Skip to content

Commit

Permalink
feat(connect): allow different fees per EVM chain
Browse files Browse the repository at this point in the history
  • Loading branch information
adderpositive authored and tomasklim committed Dec 27, 2024
1 parent 9925781 commit 235294d
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 15 deletions.
78 changes: 78 additions & 0 deletions packages/connect/src/data/__tests__/defaultFeeLevels.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { getEthereumFeeLevels } from '../defaultFeeLevels';

describe('getEthereumFeeLevels', () => {
const fixtures = {
eth: {
expected: {
blockTime: -1,
defaultFees: [
{
label: 'normal',
feePerUnit: '15',
feeLimit: '21000',
blocks: -1,
},
],
minFee: 1,
maxFee: 10000,
dustLimit: -1,
},
},
pol: {
expected: {
blockTime: -1,
defaultFees: [
{
label: 'normal',
feePerUnit: '200',
feeLimit: '21000',
blocks: -1,
},
],
minFee: 1,
maxFee: 10000000,
dustLimit: -1,
},
},
base: {
expected: {
blockTime: -1,
defaultFees: [
{
label: 'normal',
feePerUnit: '0.01',
feeLimit: '21000',
blocks: -1,
},
],
minFee: 0.000000001,
maxFee: 100,
dustLimit: -1,
},
},
unknown: {
expected: {
blockTime: -1,
defaultFees: [
{
label: 'normal',
feePerUnit: '5',
feeLimit: '21000',
blocks: -1,
},
],
minFee: 0.000000001,
maxFee: 10000,
dustLimit: -1,
},
},
};

Object.entries(fixtures).forEach(([chain, { expected }]) => {
it(`should return correct fee levels for ${chain}`, () => {
const result = getEthereumFeeLevels(chain);

expect(result).toEqual(expected);
});
});
});
2 changes: 1 addition & 1 deletion packages/connect/src/data/coinInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ const parseEthereumNetworksJson = (json: any) => {

ethereumNetworks.push({
...ethereumNetworkInfoBase,
...getEthereumFeeLevels(),
...getEthereumFeeLevels(network.chain),
blockchainLink: network.blockchain_link,
chainId: network.chain_id,
label: network.label,
Expand Down
48 changes: 34 additions & 14 deletions packages/connect/src/data/defaultFeeLevels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ const getDefaultBlocksForFeeLevel = (shortcut: string, label: string) =>
? BLOCKS_FOR_FEE_LEVEL[shortcut][label]
: -1; // -1 for unknown

const EVM_GAS_PRICE_PER_CHAIN: Record<string, { min: number; max: number; defaultGas: number }> = {
eth: { min: 1, max: 10000, defaultGas: 15 },
pol: { min: 1, max: 10000000, defaultGas: 200 },
bsc: { min: 1, max: 100000, defaultGas: 3 },
base: { min: 0.000000001, max: 100, defaultGas: 0.01 },
arb: { min: 0.000000001, max: 100, defaultGas: 0.01 },
op: { min: 0.000000001, max: 100, defaultGas: 0.01 },
};

const getEvmChainGasPrice = (chain: string) =>
EVM_GAS_PRICE_PER_CHAIN[chain] ?? {
min: 0.000000001,
max: 10000,
defaultGas: 5,
};

// partial data from coins.jon
interface CoinsJsonData {
shortcut: string; // uppercase shortcut
Expand Down Expand Up @@ -58,20 +74,24 @@ export const getBitcoinFeeLevels = (coin: CoinsJsonData): FeeInfoWithLevels => {
};
};

export const getEthereumFeeLevels = (): FeeInfoWithLevels => ({
blockTime: -1, // unknown
defaultFees: [
{
label: 'normal' as const,
feePerUnit: '5000000000',
feeLimit: '21000', // unlike the other networks ethereum have additional value "feeLimit" (Gas limit)
blocks: -1, // unknown
},
],
minFee: 1,
maxFee: 10000,
dustLimit: -1, // unknown/unused
});
export const getEthereumFeeLevels = (chain: string): FeeInfoWithLevels => {
const { min, max, defaultGas } = getEvmChainGasPrice(chain);

return {
blockTime: -1, // unknown
defaultFees: [
{
label: 'normal' as const,
feePerUnit: defaultGas.toString(),
feeLimit: '21000', // default transfer gas limit
blocks: -1, // unknown
},
],
minFee: min,
maxFee: max,
dustLimit: -1, // unknown/unused
};
};

const RIPPLE_FEE_INFO: FeeInfoWithLevels = {
blockTime: -1, // unknown
Expand Down

0 comments on commit 235294d

Please sign in to comment.