Skip to content

Commit ed4835c

Browse files
Merge pull request #8292 from BitGo/CECHO-354
feat: add support for L1 fee buffers in gas calculations for multiple coin families
2 parents 7b0c091 + 40a89e7 commit ed4835c

6 files changed

Lines changed: 24 additions & 10 deletions

File tree

.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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import { AbstractEthLikeCoin } from './abstractEthLikeCoin';
7272
import { EthLikeToken } from './ethLikeToken';
7373
import {
7474
calculateForwarderV1Address,
75+
coinFamiliesWithL1Fees,
7576
decodeTransferData,
7677
ERC1155TransferBuilder,
7778
ERC721TransferBuilder,
@@ -1516,10 +1517,9 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
15161517
const backupKeyBalance = await this.queryAddressBalance(backupKeyAddress, params.apiKey);
15171518
let totalGasNeeded = gasPrice.mul(gasLimit);
15181519

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));
1520+
// On L2 chains with L1 data fees, add buffer for L1 fees
1521+
if (this.staticsCoin?.family !== undefined && coinFamiliesWithL1Fees.includes(this.staticsCoin.family)) {
1522+
totalGasNeeded = totalGasNeeded.add(new optionalDeps.ethUtil.BN(ethGasConfigs.l1GasFeeBuffer));
15231523
}
15241524

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

25162516
async validateBalanceAndGetTxAmount(baseAddress: string, gasPrice: BN, gasLimit: BN, apiKey?: string) {
25172517
const baseAddressBalance = await this.queryAddressBalance(baseAddress, apiKey);
2518-
const totalGasNeeded = gasPrice.mul(gasLimit);
2518+
let totalGasNeeded = gasPrice.mul(gasLimit);
2519+
// On L2 chains with L1 data fees, add buffer for L1 fees
2520+
if (this.staticsCoin?.family !== undefined && coinFamiliesWithL1Fees.includes(this.staticsCoin.family)) {
2521+
totalGasNeeded = totalGasNeeded.add(new optionalDeps.ethUtil.BN(ethGasConfigs.l1GasFeeBuffer));
2522+
}
25192523
const weiToGwei = new BN(10 ** 9);
25202524
if (baseAddressBalance.lt(totalGasNeeded)) {
25212525
throw new Error(

modules/abstract-eth/src/ethLikeToken.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { BigNumber } from 'bignumber.js';
88

99
import { BitGoBase, CoinConstructor, NamedCoinConstructor, getIsUnsignedSweep, Util } from '@bitgo/sdk-core';
1010
import {
11+
coinFamiliesWithL1Fees,
1112
TransactionBuilder as EthLikeTransactionBuilder,
1213
TransferBuilder as EthLikeTransferBuilder,
1314
KeyPair as KeyPairLib,
@@ -276,10 +277,9 @@ export class EthLikeToken extends AbstractEthLikeNewCoins {
276277

277278
let totalGasNeeded = gasPrice.mul(gasLimit);
278279

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));
280+
// On L2 chains with L1 data fees, add buffer for L1 fees
281+
if (this.staticsCoin?.family !== undefined && coinFamiliesWithL1Fees.includes(this.staticsCoin.family)) {
282+
totalGasNeeded = totalGasNeeded.add(new optionalDeps.ethUtil.BN(ethGasConfigs.l1GasFeeBuffer));
283283
}
284284

285285
const weiToGwei = 10 ** 9;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { CoinFamily } from '@bitgo/statics';
2+
3+
/** L2 coin families that incur L1 data fees during recovery transactions */
4+
export const coinFamiliesWithL1Fees: ReadonlyArray<CoinFamily> = [
5+
CoinFamily.OPETH,
6+
CoinFamily.DOGEOS,
7+
CoinFamily.MORPHETH,
8+
];

modules/abstract-eth/src/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './constants';
12
export * from './contractCall';
23
export * from './iface';
34
export * from './keyPair';

modules/statics/src/tokenConfig.ts

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

351351
function getStellarTokenConfig(coin: StellarCoin): StellarTokenConfig {

0 commit comments

Comments
 (0)