From 410971b18111c6c69351eb0e1d1edb2203af48a0 Mon Sep 17 00:00:00 2001 From: hzhu Date: Sat, 28 Sep 2024 04:19:11 -0700 Subject: [PATCH] feat: support new chain, blast --- README.md | 6 ++-- src/constants.ts | 2 ++ src/tests/index.test.ts | 61 +++++++++++++++++++++++++++++++++++++++++ src/types.ts | 2 ++ src/utils/index.ts | 4 ++- 5 files changed, 71 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b348379..24be19a 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ ## Blockchain Support -| arbitrum | avalanche | base | bnb chain | ethereum | linea | optimism | polygon | scroll | -| :----------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------: | -| Arbitrum | Avalanche | Base | BNB Chain | Ethereum | Linea | Optimism | Polygon | Scroll | +| arbitrum | avalanche | base | bnb chain | blast | ethereum | linea | optimism | polygon | scroll | +| :----------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------: | +| Arbitrum | Avalanche | Base | BNB Chain | Blast | Ethereum | Linea | Optimism | Polygon | Scroll | ## Overview diff --git a/src/constants.ts b/src/constants.ts index 212e437..a71b1c7 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,6 +1,7 @@ import { bsc, base, + blast, linea, scroll, mainnet, @@ -46,6 +47,7 @@ export const NATIVE_SYMBOL_BY_CHAIN_ID: { [key in SupportedChainId]: string } = { [bsc.id]: bsc.nativeCurrency.symbol, [base.id]: base.nativeCurrency.symbol, + [blast.id]: blast.nativeCurrency.symbol, [linea.id]: linea.nativeCurrency.symbol, [scroll.id]: scroll.nativeCurrency.symbol, [mainnet.id]: mainnet.nativeCurrency.symbol, diff --git a/src/tests/index.test.ts b/src/tests/index.test.ts index 0665a12..f556fcf 100644 --- a/src/tests/index.test.ts +++ b/src/tests/index.test.ts @@ -7,6 +7,7 @@ import { } from "viem"; import { base, + blast, linea, scroll, polygon, @@ -1020,3 +1021,63 @@ test("parse a swap on Linear (USDC for WETH) with execute", async () => { }, }); }); + +// https://blastscan.io/tx/0x2cdcf1c74ff01657a2d8540be3e820e21312fd5b929ae1dc887f1a45418a4bf4 +test("parse a swap on Blast (YOLO for USDB) with execute", async () => { + const publicClient = createPublicClient({ + chain: blast, + transport: http( + `https://blast-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}` + ), + }) as PublicClient; + + const transactionHash = `0x2cdcf1c74ff01657a2d8540be3e820e21312fd5b929ae1dc887f1a45418a4bf4`; + + const result = await parseSwap({ + publicClient, + transactionHash, + }); + + expect(result).toEqual({ + tokenIn: { + symbol: "YOLO", + amount: "10004.483202235712364987", + address: "0xf77dd21c5ce38ac08786BE35Ef1d1DeC1a6a15F3", + }, + tokenOut: { + symbol: "USDB", + amount: "22.673803957148435593", + address: "0x4300000000000000000000000000000000000003", + }, + }); +}); + +// https://blastscan.io/tx/0x62b094c45cc2506d60d44afa50bc54e699c09278be5050d8510a42ab1c8fa31f +test("parse a swap on Blast (ETH for ezETH) with execute", async () => { + const publicClient = createPublicClient({ + chain: blast, + transport: http( + `https://blast-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}` + ), + }) as PublicClient; + + const transactionHash = `0x62b094c45cc2506d60d44afa50bc54e699c09278be5050d8510a42ab1c8fa31f`; + + const result = await parseSwap({ + publicClient, + transactionHash, + }); + + expect(result).toEqual({ + tokenIn: { + symbol: "ETH", + amount: "0.0005", + address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", + }, + tokenOut: { + symbol: "ezETH", + amount: "0.000491534297265178", + address: "0x2416092f143378750bb29b79eD961ab195CcEea5", + }, + }); +}); diff --git a/src/types.ts b/src/types.ts index e875384..2bf2789 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,7 @@ import { bsc, base, + blast, linea, scroll, mainnet, @@ -23,6 +24,7 @@ import type { export type SupportedChainId = | typeof bsc.id | typeof base.id + | typeof blast.id | typeof linea.id | typeof scroll.id | typeof mainnet.id diff --git a/src/utils/index.ts b/src/utils/index.ts index a37dd0c..334fe67 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -2,13 +2,14 @@ import { fromHex, erc20Abi, getAddress, formatUnits, formatEther } from "viem"; import { bsc, base, + blast, + linea, scroll, mainnet, polygon, arbitrum, optimism, avalanche, - linea, } from "viem/chains"; import { NATIVE_SYMBOL_BY_CHAIN_ID, NATIVE_TOKEN_ADDRESS } from "../constants"; import type { Address } from "viem"; @@ -25,6 +26,7 @@ export function isChainIdSupported( const supportedChainIds: number[] = [ bsc.id, base.id, + blast.id, linea.id, scroll.id, polygon.id,