Skip to content

Commit 01ac870

Browse files
feat(frontend): Explicitly write native Arbitrum and Base exchange rate (#12165)
# Motivation To be more explicit and consistent, we add Arbitrum and Base native tokens to the list of exchange rates, even if we use the Ethereum native token as price.
1 parent feb5082 commit 01ac870

File tree

6 files changed

+48
-8
lines changed

6 files changed

+48
-8
lines changed

src/frontend/src/lib/schema/post-message.schema.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ export const PostMessageDataResponseExchangeSchema = PostMessageDataResponseSche
173173
currentSplPrices: z.custom<CoingeckoSimpleTokenPriceResponse>(),
174174
currentErc4626Prices: z.custom<CoingeckoSimpleTokenPriceResponse>(),
175175
currentBnbPrice: z.custom<CoingeckoSimplePriceResponse>().optional(),
176-
currentPolPrice: z.custom<CoingeckoSimplePriceResponse>().optional()
176+
currentPolPrice: z.custom<CoingeckoSimplePriceResponse>().optional(),
177+
currentArbitrumEthPrice: z.custom<CoingeckoSimplePriceResponse>().optional(),
178+
currentBaseEthPrice: z.custom<CoingeckoSimplePriceResponse>().optional()
177179
});
178180

179181
export const PostMessageDataResponseExchangeErrorSchema = PostMessageDataResponseSchema.extend({

src/frontend/src/lib/services/exchange.services.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { TokenId } from '$declarations/backend/backend.did';
2+
import { ARBITRUM_MAINNET_NETWORK } from '$env/networks/networks-evm/networks.evm.arbitrum.env';
3+
import { BASE_NETWORK } from '$env/networks/networks-evm/networks.evm.base.env';
24
import { BSC_MAINNET_NETWORK } from '$env/networks/networks-evm/networks.evm.bsc.env';
35
import { POLYGON_MAINNET_NETWORK } from '$env/networks/networks-evm/networks.evm.polygon.env';
46
import { ETHEREUM_NETWORK } from '$env/networks/networks.eth.env';
@@ -244,13 +246,23 @@ const POL_NATIVE_ENTRY: NativeTokenEntry = {
244246
tokenId: { EvmNative: POLYGON_MAINNET_NETWORK.chainId },
245247
coingeckoKey: 'polygon-ecosystem-token'
246248
};
249+
const ARBITRUM_ETH_NATIVE_ENTRY: NativeTokenEntry = {
250+
tokenId: { EvmNative: ARBITRUM_MAINNET_NETWORK.chainId },
251+
coingeckoKey: 'ethereum'
252+
};
253+
const BASE_ETH_NATIVE_ENTRY: NativeTokenEntry = {
254+
tokenId: { EvmNative: BASE_NETWORK.chainId },
255+
coingeckoKey: 'ethereum'
256+
};
247257
const NATIVE_TOKEN_IDS: NativeTokenEntry[] = [
248258
ETH_NATIVE_ENTRY,
249259
BTC_NATIVE_ENTRY,
250260
ICP_NATIVE_ENTRY,
251261
SOL_NATIVE_ENTRY,
252262
BNB_NATIVE_ENTRY,
253-
POL_NATIVE_ENTRY
263+
POL_NATIVE_ENTRY,
264+
ARBITRUM_ETH_NATIVE_ENTRY,
265+
BASE_ETH_NATIVE_ENTRY
254266
];
255267

256268
const collectTokenPairs = <T>({
@@ -317,6 +329,8 @@ export const fetchAllExchangeRatesFromBackend = async ({
317329
currentSolPrice: CoingeckoSimplePriceResponse | undefined;
318330
currentBnbPrice: CoingeckoSimplePriceResponse | undefined;
319331
currentPolPrice: CoingeckoSimplePriceResponse | undefined;
332+
currentArbitrumEthPrice: CoingeckoSimplePriceResponse | undefined;
333+
currentBaseEthPrice: CoingeckoSimplePriceResponse | undefined;
320334
currentErc20Prices: CoingeckoSimpleTokenPriceResponse;
321335
currentIcrcPrices: CoingeckoSimpleTokenPriceResponse;
322336
currentSplPrices: CoingeckoSimpleTokenPriceResponse;
@@ -363,6 +377,8 @@ export const fetchAllExchangeRatesFromBackend = async ({
363377
currentSolPrice: nativePrice({ ...SOL_NATIVE_ENTRY, coingeckoRates }),
364378
currentBnbPrice: nativePrice({ ...BNB_NATIVE_ENTRY, coingeckoRates }),
365379
currentPolPrice: nativePrice({ ...POL_NATIVE_ENTRY, coingeckoRates }),
380+
currentArbitrumEthPrice: nativePrice({ ...ARBITRUM_ETH_NATIVE_ENTRY, coingeckoRates }),
381+
currentBaseEthPrice: nativePrice({ ...BASE_ETH_NATIVE_ENTRY, coingeckoRates }),
366382
currentErc20Prices: buildPriceMap({
367383
pairs: erc20.pairs,
368384
rates: coingeckoRates,
@@ -387,6 +403,8 @@ export const syncExchange = (data: PostMessageDataResponseExchange | undefined)
387403
data.currentSolPrice,
388404
data.currentBnbPrice,
389405
data.currentPolPrice,
406+
data.currentArbitrumEthPrice,
407+
data.currentBaseEthPrice,
390408
data.currentErc20Prices,
391409
data.currentIcrcPrices,
392410
data.currentSplPrices,

src/frontend/src/lib/workers/exchange.worker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ const syncExchange = async ({
222222
currentSplPrices,
223223
currentErc4626Prices,
224224
currentBnbPrice,
225-
currentPolPrice
225+
currentPolPrice,
226+
currentArbitrumEthPrice: currentEthPrice,
227+
currentBaseEthPrice: currentEthPrice
226228
}
227229
} as PostMessage<PostMessageDataResponseExchange>);
228230
} catch (err: unknown) {

src/frontend/src/tests/lib/services/exchange.services.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ describe('exchange.services', () => {
271271
{ SolNativeMainnet: null },
272272
{ EvmNative: 56n },
273273
{ EvmNative: 137n },
274+
{ EvmNative: 42161n },
275+
{ EvmNative: 8453n },
274276
{ Erc20: ['0xabc', 1n] },
275277
{ Icrc: Principal.fromText('ryjl3-tyaaa-aaaaa-aaaba-cai') },
276278
{ SplMainnet: 'SoLaddr1' }
@@ -327,6 +329,8 @@ describe('exchange.services', () => {
327329
expect(result.currentSolPrice).toBeUndefined();
328330
expect(result.currentBnbPrice).toBeUndefined();
329331
expect(result.currentPolPrice).toBeUndefined();
332+
expect(result.currentArbitrumEthPrice).toBeUndefined();
333+
expect(result.currentBaseEthPrice).toBeUndefined();
330334
expect(result.currentErc20Prices).toEqual({});
331335
expect(result.currentIcrcPrices).toEqual({});
332336
expect(result.currentSplPrices).toEqual({});
@@ -389,6 +393,8 @@ describe('exchange.services', () => {
389393
{ SolNativeMainnet: null },
390394
{ EvmNative: 56n },
391395
{ EvmNative: 137n },
396+
{ EvmNative: 42161n },
397+
{ EvmNative: 8453n },
392398
{ Erc20: ['0xabc', 999n] }
393399
]
394400
})
@@ -403,7 +409,9 @@ describe('exchange.services', () => {
403409
[{ IcpNative: null }, mockExchangeRate],
404410
[{ SolNativeMainnet: null }, mockExchangeRate],
405411
[{ EvmNative: 56n }, mockExchangeRate],
406-
[{ EvmNative: 137n }, mockExchangeRate]
412+
[{ EvmNative: 137n }, mockExchangeRate],
413+
[{ EvmNative: 42161n }, mockExchangeRate],
414+
[{ EvmNative: 8453n }, mockExchangeRate]
407415
)
408416
);
409417

@@ -422,6 +430,8 @@ describe('exchange.services', () => {
422430
expect(result.currentSolPrice).toEqual({ solana: expectedPrice });
423431
expect(result.currentBnbPrice).toEqual({ binancecoin: expectedPrice });
424432
expect(result.currentPolPrice).toEqual({ 'polygon-ecosystem-token': expectedPrice });
433+
expect(result.currentArbitrumEthPrice).toEqual({ ethereum: expectedPrice });
434+
expect(result.currentBaseEthPrice).toEqual({ ethereum: expectedPrice });
425435
});
426436

427437
it('should handle missing optional fields in BackendExchangeRate', async () => {

src/frontend/src/tests/lib/services/worker.exchange.service.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ describe('worker.exchange.services', () => {
120120
currentSplPrices: {},
121121
currentErc4626Prices: {},
122122
currentBnbPrice: { binancecoin: { usd: 400 } },
123-
currentPolPrice: {}
123+
currentPolPrice: {},
124+
currentArbitrumEthPrice: { ethereum: { usd: 1 } },
125+
currentBaseEthPrice: { ethereum: { usd: 1 } }
124126
};
125127
const payload = { msg: 'syncExchange', data: mockData };
126128
workerInstance.onmessage?.({ data: payload } as MessageEvent);

src/frontend/src/tests/lib/workers/exchange.worker.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ describe('exchange.worker', () => {
166166
currentIcrcPrices: null,
167167
currentPolPrice: { 'polygon-ecosystem-token': { usd: 1 } },
168168
currentSolPrice: { solana: { usd: 1 } },
169-
currentSplPrices: null
169+
currentSplPrices: null,
170+
currentArbitrumEthPrice: { ethereum: { usd: 1 } },
171+
currentBaseEthPrice: { ethereum: { usd: 1 } }
170172
}
171173
});
172174
});
@@ -641,7 +643,9 @@ describe('exchange.worker', () => {
641643
currentIcrcPrices: { icrc1: { usd: 1 }, icrc2: { usd: 1 } },
642644
currentPolPrice: { 'polygon-ecosystem-token': { usd: 1 } },
643645
currentSolPrice: { solana: { usd: 1 } },
644-
currentSplPrices: { spl1: { usd: 1 }, spl2: { usd: 1 } }
646+
currentSplPrices: { spl1: { usd: 1 }, spl2: { usd: 1 } },
647+
currentArbitrumEthPrice: { ethereum: { usd: 1 } },
648+
currentBaseEthPrice: { ethereum: { usd: 1 } }
645649
}
646650
});
647651
});
@@ -702,7 +706,9 @@ describe('exchange.worker', () => {
702706
currentIcrcPrices: { icrc1: { usd: 1 }, icrc2: { usd: 1 } },
703707
currentPolPrice: { 'polygon-ecosystem-token': { usd: 1, usd_24h_change: 3 } },
704708
currentSolPrice: { solana: { usd: 1, usd_24h_change: 3 } },
705-
currentSplPrices: { spl1: { usd: 1 }, spl2: { usd: 1 } }
709+
currentSplPrices: { spl1: { usd: 1 }, spl2: { usd: 1 } },
710+
currentArbitrumEthPrice: { ethereum: { usd: 1, usd_24h_change: 3 } },
711+
currentBaseEthPrice: { ethereum: { usd: 1, usd_24h_change: 3 } }
706712
}
707713
});
708714
});

0 commit comments

Comments
 (0)