Skip to content

Commit 6dc852f

Browse files
authored
Merge pull request #6351 from BitGo/WIN-5989
feat(sdk-coin-soneium): add gas limit validation in setGasLimit method
2 parents 8f1e2e3 + 3d57bce commit 6dc852f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

modules/sdk-coin-soneium/src/soneium.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import { BaseCoin, BitGoBase, common, MPCAlgorithm, MultisigType, multisigTypes } from '@bitgo/sdk-core';
11-
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics';
11+
import { BaseCoin as StaticsBaseCoin, coins, ethGasConfigs } from '@bitgo/statics';
1212
import {
1313
AbstractEthLikeNewCoins,
1414
recoveryBlockchainExplorerQuery,
@@ -55,4 +55,22 @@ export class Soneium extends AbstractEthLikeNewCoins {
5555
const explorerUrl = common.Environments[this.bitgo.getEnv()].soneiumExplorerBaseUrl;
5656
return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken);
5757
}
58+
59+
/**
60+
* Check whether gas limit passed in by user are within our max and min bounds
61+
* If they are not set, set them to the defaults
62+
* @param {number} userGasLimit user defined gas limit
63+
* @returns {number} the gas limit to use for this transaction
64+
*/
65+
setGasLimit(userGasLimit?: number): number {
66+
if (!userGasLimit) {
67+
return ethGasConfigs.defaultGasLimit;
68+
}
69+
const gasLimitMax = ethGasConfigs.maximumGasLimit;
70+
const gasLimitMin = ethGasConfigs.newEthLikeCoinsMinGasLimit;
71+
if (userGasLimit < gasLimitMin || userGasLimit > gasLimitMax) {
72+
throw new Error(`Gas limit must be between ${gasLimitMin} and ${gasLimitMax}`);
73+
}
74+
return userGasLimit;
75+
}
5876
}

0 commit comments

Comments
 (0)