Skip to content

Commit

Permalink
Estimate gas limit before router contract call
Browse files Browse the repository at this point in the history
  • Loading branch information
0xp3gasus committed Oct 8, 2024
1 parent d2877b3 commit 5a23369
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-starfishes-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-mayachain-amm': patch
---

Estimate gas limit before calling Router contract in MayachainAction
12 changes: 9 additions & 3 deletions packages/xchain-mayachain-amm/src/mayachain-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getContractAddressFromAsset,
isSynthAsset,
} from '@xchainjs/xchain-util'
import { Wallet } from '@xchainjs/xchain-wallet'
import { EvmTxParams, Wallet } from '@xchainjs/xchain-wallet'
import { ethers } from 'ethers'

import { TxSubmitted } from './types'
Expand Down Expand Up @@ -144,14 +144,20 @@ export class MayachainAction {

const nativeAsset = wallet.getAssetInfo(assetAmount.asset.chain)

const hash = await wallet.transfer({
const tx: EvmTxParams = {
asset: nativeAsset.asset,
amount: isERC20 ? baseAmount(0, nativeAsset.decimal) : assetAmount.baseAmount,
memo: unsignedTx.data,
recipient: inboundDetails.router,
gasPrice: gasPrices.fast,
isMemoEncoded: true,
gasLimit: ethers.BigNumber.from(160000),
}

const gasLimit = await wallet.estimateGasLimit(tx)

const hash = await wallet.transfer({
...tx,
gasLimit,
})

return {
Expand Down

0 comments on commit 5a23369

Please sign in to comment.