Skip to content

Commit

Permalink
Increase default gas and fee amount to fix Cipher withdrawals
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Mar 17, 2023
1 parent 4efbca2 commit e180b58
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
20 changes: 9 additions & 11 deletions src/app/lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -25,9 +25,6 @@ export type TW<T> = oasis.consensus.TransactionWrapper<T>
/** Runtime Transaction Wrapper */
type RTW<T> = oasisRT.wrapper.TransactionWrapper<T, void>

// 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 {
Expand Down Expand Up @@ -130,12 +127,11 @@ export class OasisTransaction {
signer: Signer,
transaction: ParaTimeTransaction,
fromAddress: string,
runtimeId: string,
runtimeDecimals: number,
runtime: Runtime,
): Promise<RTW<oasisRT.types.ConsensusDeposit | oasisRT.types.ConsensusWithdraw>> {
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'
]()
Expand All @@ -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() },
Expand All @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions src/app/state/paratimes/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
2 changes: 2 additions & 0 deletions src/app/state/paratimes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export type Runtime = {
address: string
id: string
decimals: number
gasPrice: bigint
feeGas: bigint
}

export type ParaTimeTransaction = Pick<
Expand Down
10 changes: 1 addition & 9 deletions src/app/state/transaction/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ type ParaTimeConfig = {
mainnet: ParaTimeNetwork
testnet: ParaTimeNetwork
local: ParaTimeNetwork
gasPrice: bigint
feeGas: bigint
decimals: number
type: RuntimeTypes
}
Expand All @@ -99,6 +101,8 @@ const emeraldConfig: ParaTimeConfig = {
address: undefined,
runtimeId: undefined,
},
gasPrice: 100n,
feeGas: 15_000n,
decimals: 18,
type: RuntimeTypes.Evm,
}
Expand All @@ -116,6 +120,8 @@ const cipherConfig: ParaTimeConfig = {
address: undefined,
runtimeId: undefined,
},
gasPrice: 5n,
feeGas: 500_000n,
decimals: 9,
type: RuntimeTypes.Oasis,
}
Expand All @@ -133,7 +139,8 @@ const sapphireConfig: ParaTimeConfig = {
address: undefined,
runtimeId: undefined,
},

gasPrice: 100n,
feeGas: 15_000n,
decimals: 18,
type: RuntimeTypes.Evm,
}
Expand Down

0 comments on commit e180b58

Please sign in to comment.