Skip to content

Commit

Permalink
add l2 fee multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
KorbinianK committed Apr 10, 2024
1 parent 55426ef commit 7b975c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/bridge-ui/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ export CONFIGURED_RELAYER=
export CONFIGURED_EVENT_INDEXER=

# Show the slow L1 bridging warning
export PUBLIC_SLOW_L1_BRIDGING_WARNING=false
export PUBLIC_SLOW_L1_BRIDGING_WARNING=false

# L2 processing fee multiplier
export PUBLIC_L2_PROCESSING_FEE_MULTIPLIER=10
6 changes: 6 additions & 0 deletions packages/bridge-ui/src/libs/chain/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { Chain } from 'viem';
import { chainConfig } from '$chainConfig';
import type { ChainConfig } from '$libs/chain';

import { LayerType } from './types';

function mapChainConfigToChain(chainId: string, chainConfig: ChainConfig): Chain {
return {
id: Number(chainId),
Expand All @@ -21,6 +23,10 @@ export const chainIdToChain = (chainId: number): Chain => {
return chain;
};

export const isL2Chain = (chainId: number) => {
return chainConfig[chainId].type === LayerType.L2;
};

export const chains: [Chain, ...Chain[]] = Object.entries(chainConfig).map(([chainId, chainConfig]) =>
mapChainConfigToChain(chainId, chainConfig),
) as [Chain, ...Chain[]];
Expand Down
12 changes: 11 additions & 1 deletion packages/bridge-ui/src/libs/fee/recommendProcessingFee.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { getPublicClient } from '@wagmi/core';

import { recommendProcessingFeeConfig } from '$config';
import { PUBLIC_L2_PROCESSING_FEE_MULTIPLIER } from '$env/static/public';
import { isL2Chain } from '$libs/chain';
import { NoCanonicalInfoFoundError } from '$libs/error';
import { type Token, TokenType } from '$libs/token';
import { getTokenAddresses } from '$libs/token/getTokenAddresses';
Expand Down Expand Up @@ -40,6 +42,14 @@ export async function recommendProcessingFee({
// getGasPrice will return gasPrice as 3000000001, rather than 3000000000
const gasPrice = await destPublicClient.getGasPrice();

let multiplier = 1;

//TODO: temporary increase multiplier for L2 chains until we have a better solution via the relayer
// figure out if it is L2-L1
if (isL2Chain(srcChainId)) {
multiplier = parseInt(PUBLIC_L2_PROCESSING_FEE_MULTIPLIER);
}

// The gas limit for processMessage call for ETH is about ~800k.
// To make it enticing, we say 900k
let gasLimit = ethGasLimit;
Expand Down Expand Up @@ -82,5 +92,5 @@ export async function recommendProcessingFee({
}
}
}
return gasPrice * gasLimit;
return gasPrice * gasLimit * BigInt(multiplier);
}

0 comments on commit 7b975c6

Please sign in to comment.