Skip to content

Commit

Permalink
feat: support new chain, blast
Browse files Browse the repository at this point in the history
  • Loading branch information
hzhu committed Sep 28, 2024
1 parent 9c4f2b1 commit 410971b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

## Blockchain Support

| <img alt="arbitrum" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/arbitrum/info/logo.png" width="23"/> | <img alt="avalanche" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/avalanchec/info/logo.png" width="20"/> | <img alt="base" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/base/info/logo.png" width="20"/> | <img alt="bnb chain" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/binance/info/logo.png" width="21"/> | <img alt="ethereum" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/ethereum/info/logo.png" width="21"/> | <img alt="linea" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/linea/info/logo.png" width="22"/> | <img alt="optimism" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/optimism/info/logo.png" width="22"/> | <img alt="polygon" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/polygon/info/logo.png" width="22"/> | <img alt="scroll" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/scroll/info/logo.png" width="22"/> |
| :----------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------: |
| Arbitrum | Avalanche | Base | BNB Chain | Ethereum | Linea | Optimism | Polygon | Scroll |
| <img alt="arbitrum" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/arbitrum/info/logo.png" width="23"/> | <img alt="avalanche" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/avalanchec/info/logo.png" width="20"/> | <img alt="base" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/base/info/logo.png" width="20"/> | <img alt="bnb chain" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/binance/info/logo.png" width="21"/> | <img alt="blast" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/blast/info/logo.png" width="22"/> | <img alt="ethereum" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/ethereum/info/logo.png" width="21"/> | <img alt="linea" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/linea/info/logo.png" width="22"/> | <img alt="optimism" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/optimism/info/logo.png" width="22"/> | <img alt="polygon" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/polygon/info/logo.png" width="22"/> | <img alt="scroll" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/scroll/info/logo.png" width="22"/> |
| :----------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------: |
| Arbitrum | Avalanche | Base | BNB Chain | Blast | Ethereum | Linea | Optimism | Polygon | Scroll |

## Overview

Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
bsc,
base,
blast,
linea,
scroll,
mainnet,
Expand Down Expand Up @@ -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,
Expand Down
61 changes: 61 additions & 0 deletions src/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "viem";
import {
base,
blast,
linea,
scroll,
polygon,
Expand Down Expand Up @@ -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<Transport, Chain>;

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<Transport, Chain>;

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",
},
});
});
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
bsc,
base,
blast,
linea,
scroll,
mainnet,
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -25,6 +26,7 @@ export function isChainIdSupported(
const supportedChainIds: number[] = [
bsc.id,
base.id,
blast.id,
linea.id,
scroll.id,
polygon.id,
Expand Down

0 comments on commit 410971b

Please sign in to comment.