diff --git a/src/app/lib/transaction.ts b/src/app/lib/transaction.ts index e36f09fbda..ffcd556102 100644 --- a/src/app/lib/transaction.ts +++ b/src/app/lib/transaction.ts @@ -5,7 +5,7 @@ import { ContextSigner, Signer } from '@oasisprotocol/client/dist/signature' import { WalletError, WalletErrors } from 'types/errors' import { getEvmBech32Address } from 'app/lib/eth-helpers' import { isValidEthAddress } from 'app/lib/eth-helpers' -import { ParaTimeTransaction, TransactionTypes } from 'app/state/paratimes/types' +import { ParaTimeTransaction, Runtime, TransactionTypes } from 'app/state/paratimes/types' import { addressToPublicKey, parseRoseStringToBigNumber, shortPublicKey } from './helpers' import { consensusDecimals } from '../../config' @@ -25,9 +25,6 @@ export type TW = oasis.consensus.TransactionWrapper /** Runtime Transaction Wrapper */ type RTW = oasisRT.wrapper.TransactionWrapper -// A wild guess: the minimum gas price on Emerald (100 nano ROSE) times the default loose -// overestimate of the gas (15k). -const defaultWithdrawFeeAmount = '1500000' const defaultDepositFeeAmount = '0' export class OasisTransaction { @@ -130,12 +127,11 @@ export class OasisTransaction { signer: Signer, transaction: ParaTimeTransaction, fromAddress: string, - runtimeId: string, - runtimeDecimals: number, + runtime: Runtime, ): Promise> { const { amount, recipient: targetAddress, type } = transaction const isDepositing = type === TransactionTypes.Deposit - const consensusRuntimeId = oasis.misc.fromHex(runtimeId) + const consensusRuntimeId = oasis.misc.fromHex(runtime.id) const txWrapper = new oasisRT.consensusAccounts.Wrapper(consensusRuntimeId)[ isDepositing ? 'callDeposit' : 'callWithdraw' ]() @@ -150,13 +146,15 @@ export class OasisTransaction { ? transaction.feeAmount : isDepositing ? defaultDepositFeeAmount - : defaultWithdrawFeeAmount, + : // A wild guess: the minimum gas price times the default loose + // overestimate of the gas. + (runtime.gasPrice * runtime.feeGas).toString(), ) - .shiftedBy(runtimeDecimals) + .shiftedBy(runtime.decimals) .shiftedBy(-consensusDecimals) .toFixed(0), ) - const feeGas = transaction.feeGas ? BigInt(transaction.feeGas) : 15000n + const feeGas = transaction.feeGas ? BigInt(transaction.feeGas) : runtime.feeGas const signerInfo = { address_spec: { signature: { [transaction.ethPrivateKey ? 'secp256k1eth' : 'ed25519']: signer.public() }, @@ -167,7 +165,7 @@ export class OasisTransaction { txWrapper .setBody({ amount: [ - oasis.quantity.fromBigInt(BigInt(parseRoseStringToBigNumber(amount, runtimeDecimals).toFixed(0))), + oasis.quantity.fromBigInt(BigInt(parseRoseStringToBigNumber(amount, runtime.decimals).toFixed(0))), oasisRT.token.NATIVE_DENOMINATION, ], to: oasis.staking.addressFromBech32( diff --git a/src/app/state/paratimes/saga.ts b/src/app/state/paratimes/saga.ts index 40f7990d22..f478dc2de6 100644 --- a/src/app/state/paratimes/saga.ts +++ b/src/app/state/paratimes/saga.ts @@ -76,6 +76,8 @@ export function* submitTransaction() { address: paraTimeConfig[selectedNetwork].address!, id: paraTimeConfig[selectedNetwork].runtimeId!, decimals: paraTimeConfig.decimals, + gasPrice: paraTimeConfig.gasPrice, + feeGas: paraTimeConfig.feeGas, } yield* call(submitParaTimeTransaction, runtime, { diff --git a/src/app/state/paratimes/types.ts b/src/app/state/paratimes/types.ts index 384eb0292e..b6657a34e2 100644 --- a/src/app/state/paratimes/types.ts +++ b/src/app/state/paratimes/types.ts @@ -42,6 +42,8 @@ export type Runtime = { address: string id: string decimals: number + gasPrice: bigint + feeGas: bigint } export type ParaTimeTransaction = Pick< diff --git a/src/app/state/transaction/saga.ts b/src/app/state/transaction/saga.ts index 1049bf26a1..e06a462902 100644 --- a/src/app/state/transaction/saga.ts +++ b/src/app/state/transaction/saga.ts @@ -106,15 +106,7 @@ function* prepareParatimeTransfer( yield* call(assertSufficientBalance, BigInt(parseRoseStringToBaseUnitString(transaction.amount))) } - return yield* call( - OasisTransaction.buildParaTimeTransfer, - nic, - signer, - transaction, - from, - runtime.id, - runtime.decimals, - ) + return yield* call(OasisTransaction.buildParaTimeTransfer, nic, signer, transaction, from, runtime) } function* prepareAddEscrow(signer: Signer, amount: bigint, validator: string) { diff --git a/src/config.ts b/src/config.ts index f34754b175..460964bb73 100644 --- a/src/config.ts +++ b/src/config.ts @@ -77,6 +77,8 @@ type ParaTimeConfig = { mainnet: ParaTimeNetwork testnet: ParaTimeNetwork local: ParaTimeNetwork + gasPrice: bigint + feeGas: bigint decimals: number type: RuntimeTypes } @@ -99,6 +101,8 @@ const emeraldConfig: ParaTimeConfig = { address: undefined, runtimeId: undefined, }, + gasPrice: 100n, + feeGas: 15_000n, decimals: 18, type: RuntimeTypes.Evm, } @@ -116,6 +120,8 @@ const cipherConfig: ParaTimeConfig = { address: undefined, runtimeId: undefined, }, + gasPrice: 5n, + feeGas: 500_000n, decimals: 9, type: RuntimeTypes.Oasis, } @@ -133,7 +139,8 @@ const sapphireConfig: ParaTimeConfig = { address: undefined, runtimeId: undefined, }, - + gasPrice: 100n, + feeGas: 15_000n, decimals: 18, type: RuntimeTypes.Evm, }