Skip to content

Commit dcc4002

Browse files
feat: add support for L1 fee buffers in gas calculations for multiple coin families
CECHO-354 TICKET: CECHO-354
1 parent 860cef6 commit dcc4002

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
2+
.worktrees/
23
.idea/
34
*.iml
45
lerna-debug.log

modules/abstract-eth/src/abstractEthLikeNewCoins.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,11 @@ export const optionalDeps = {
492492
export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
493493
static hopTransactionSalt = 'bitgoHopAddressRequestSalt';
494494
protected readonly sendMethodName: 'sendMultiSig' | 'sendMultiSigToken';
495+
protected readonly coinFamiliesWithL1Fees: ReadonlyArray<'opeth' | 'dogeos' | 'morpheth'> = [
496+
'opeth',
497+
'dogeos',
498+
'morpheth',
499+
];
495500

496501
readonly staticsCoin?: Readonly<StaticsBaseCoin>;
497502

@@ -1516,10 +1521,9 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
15161521
const backupKeyBalance = await this.queryAddressBalance(backupKeyAddress, params.apiKey);
15171522
let totalGasNeeded = gasPrice.mul(gasLimit);
15181523

1519-
// On optimism chain, L1 fees is to be paid as well apart from L2 fees
1520-
// So we are adding the amount that can be used up as l1 fees
1521-
if (this.staticsCoin?.family === 'opeth') {
1522-
totalGasNeeded = totalGasNeeded.add(new optionalDeps.ethUtil.BN(ethGasConfigs.opethGasL1Fees));
1524+
// On L2 chains with L1 data fees, add buffer for L1 fees
1525+
if (this.staticsCoin?.family !== undefined && this.coinFamiliesWithL1Fees.includes(this.staticsCoin.family)) {
1526+
totalGasNeeded = totalGasNeeded.add(new optionalDeps.ethUtil.BN(ethGasConfigs.l1GasFeeBuffer));
15231527
}
15241528

15251529
const weiToGwei = 10 ** 9;
@@ -2515,7 +2519,11 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
25152519

25162520
async validateBalanceAndGetTxAmount(baseAddress: string, gasPrice: BN, gasLimit: BN, apiKey?: string) {
25172521
const baseAddressBalance = await this.queryAddressBalance(baseAddress, apiKey);
2518-
const totalGasNeeded = gasPrice.mul(gasLimit);
2522+
let totalGasNeeded = gasPrice.mul(gasLimit);
2523+
// On L2 chains with L1 data fees, add buffer for L1 fees
2524+
if (this.staticsCoin?.family !== undefined && this.coinFamiliesWithL1Fees.includes(this.staticsCoin.family)) {
2525+
totalGasNeeded = totalGasNeeded.add(new optionalDeps.ethUtil.BN(ethGasConfigs.l1GasFeeBuffer));
2526+
}
25192527
const weiToGwei = new BN(10 ** 9);
25202528
if (baseAddressBalance.lt(totalGasNeeded)) {
25212529
throw new Error(

modules/abstract-eth/src/ethLikeToken.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,9 @@ export class EthLikeToken extends AbstractEthLikeNewCoins {
276276

277277
let totalGasNeeded = gasPrice.mul(gasLimit);
278278

279-
// On optimism chain, L1 fees is to be paid as well apart from L2 fees
280-
// So we are adding the amount that can be used up as l1 fees
281-
if (this.staticsCoin?.family === 'opeth') {
282-
totalGasNeeded = totalGasNeeded.add(new optionalDeps.ethUtil.BN(ethGasConfigs.opethGasL1Fees));
279+
// On L2 chains with L1 data fees (opeth, morpheth, dogeos), add buffer for L1 fees
280+
if (['opeth', 'morpheth', 'dogeos'].includes(this.staticsCoin?.family ?? '')) {
281+
totalGasNeeded = totalGasNeeded.add(new optionalDeps.ethUtil.BN(ethGasConfigs.l1GasFeeBuffer));
283282
}
284283

285284
const weiToGwei = 10 ** 9;

modules/statics/src/tokenConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export const ethGasConfigs = {
344344
minimumGasLimit: 30000, // minimum gas limit a user can set for a send
345345
maximumGasLimit: 20000000, // Customers cannot set gas limits beyond this amount
346346
newEthLikeCoinsMinGasLimit: 400000, // minimum gas limit a user can set for a send for eth like coins like arbitrum, optimism, etc
347-
opethGasL1Fees: 1000000000000000, // Buffer for opeth L1 gas fees
347+
l1GasFeeBuffer: 1000000000000000, // Buffer for L1 data fees
348348
};
349349

350350
function getStellarTokenConfig(coin: StellarCoin): StellarTokenConfig {

0 commit comments

Comments
 (0)