Skip to content

Commit

Permalink
Estimate gas limit
Browse files Browse the repository at this point in the history
  • Loading branch information
0xp3gasus committed Oct 8, 2024
1 parent da2d89f commit d2877b3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/angry-roses-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-wallet': minor
---

Estimate gas limit for EVM clients
3 changes: 2 additions & 1 deletion packages/xchain-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"@xchainjs/xchain-radix": "workspace:*",
"@xchainjs/xchain-thorchain": "workspace:*",
"@xchainjs/xchain-util": "workspace:*",
"@xchainjs/xchain-utxo": "workspace:*"
"@xchainjs/xchain-utxo": "workspace:*",
"ethers": "5.7.2"
},
"devDependencies": {
"@xchainjs/xchain-bitcoin": "workspace:*",
Expand Down
29 changes: 29 additions & 0 deletions packages/xchain-wallet/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
getContractAddressFromAsset,
} from '@xchainjs/xchain-util'
import { Client as UtxoClient } from '@xchainjs/xchain-utxo'
import { BigNumber } from 'ethers'

import { ChainBalances, CosmosTxParams, EvmTxParams, RadixTxParams, UtxoTxParams } from './types'

Expand Down Expand Up @@ -373,6 +374,34 @@ export class Wallet {
return client.getFees()
}

/**
* Estimates gas limit for a transaction.
*
* @param {TxParams} params The transaction and fees options.
* @returns {BigNumber} The estimated gas limit.
*/
public async estimateGasLimit({
asset,
recipient,
amount,
memo,
from,
isMemoEncoded,
}: EvmTxParams & { from?: Address }): Promise<BigNumber> {
const client = this.getClient(asset.chain)
if (!this.isEvmClient(client)) {
throw Error(`estimateGasLimit method not supported in ${asset.chain} chain`)
}
return client.estimateGasLimit({
asset,
recipient,
amount,
memo,
from,
isMemoEncoded,
})
}

/**
* Make a transaction
* @param {UtxoTxParams | EvmTxParams | CosmosTxParams} params txParams - The parameters to make the transfer
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4836,6 +4836,7 @@ __metadata:
"@xchainjs/xchain-thorchain": "workspace:*"
"@xchainjs/xchain-util": "workspace:*"
"@xchainjs/xchain-utxo": "workspace:*"
ethers: "npm:5.7.2"
languageName: unknown
linkType: soft

Expand Down

0 comments on commit d2877b3

Please sign in to comment.