Skip to content

Commit

Permalink
feat: support mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hzhu committed Oct 27, 2024
1 parent de8bfe3 commit 3ad4ea3
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<td style="width:100px; text-align:center;">
<div align="center">
<img alt="coming soon" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/mode/info/logo.png" width="22"/>
<br>Coming Soon
<br>Mode
</div>
</td>
</tr>
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,
mode,
blast,
linea,
scroll,
Expand Down Expand Up @@ -48,6 +49,7 @@ export const NATIVE_SYMBOL_BY_CHAIN_ID: { [key in SupportedChainId]: string } =
{
[bsc.id]: bsc.nativeCurrency.symbol,
[base.id]: base.nativeCurrency.symbol,
[mode.id]: mode.nativeCurrency.symbol,
[blast.id]: blast.nativeCurrency.symbol,
[linea.id]: linea.nativeCurrency.symbol,
[scroll.id]: scroll.nativeCurrency.symbol,
Expand Down
70 changes: 68 additions & 2 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,
mode,
blast,
linea,
scroll,
Expand Down Expand Up @@ -962,7 +963,7 @@ test("gracefully handles a revert in a erc-4337 transaction", async () => {
});

// https://scrollscan.com/tx/0x84b07445a1a868b4338df8aed67c9ea330e771596bf603dbef8c12b3cb9970e5
test("parse a swap on Scroll(USDC for USDT) with execute", async () => {
test("parse a swap on Scroll (USDC for USDT) with execute", async () => {
const publicClient = createPublicClient({
chain: scroll,
transport: http(
Expand Down Expand Up @@ -993,7 +994,7 @@ test("parse a swap on Scroll(USDC for USDT) with execute", async () => {
});

// https://lineascan.build/tx/0x3506d4cd4b434ec3e6fb2ec5473069471257a9436c4e8e576e0eca2a02816a75
test("parse a swap on Linear (USDC for WETH) with execute", async () => {
test("parse a swap on Linea (USDC for WETH) with execute", async () => {
const publicClient = createPublicClient({
chain: linea,
transport: http(
Expand Down Expand Up @@ -1111,3 +1112,68 @@ test("parse a swap on Mantle (WETH for mETH) with execute", async () => {
},
});
});

// https://explorer.mode.network/tx/0xd84a08f6d48b5c34cde908452602088cdb42beceef29074b8a8d5c7e45f2a3dc
test("parse a swap on Mode (ETH for BEAST) with Settler", async () => {
const publicClient = createPublicClient({
chain: mode,
transport: http(
`https://fluent-boldest-water.mode-mainnet.quiknode.pro/${process.env.QUICKNODE_API_KEY}`
),
}) as PublicClient<Transport, Chain>;

const transactionHash = `0xd84a08f6d48b5c34cde908452602088cdb42beceef29074b8a8d5c7e45f2a3dc`;

const result = await parseSwap({
publicClient,
transactionHash,
});

expect(result).toEqual({
tokenIn: {
symbol: "ETH",
amount: "0.001",
address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
},
tokenOut: {
symbol: "BEAST",
amount: "273191.79887332631998981",
address: "0x6a660e56FA3b630A786CC4Ae98859f8532D03dE9",
},
});
});

// https://explorer.mode.network/tx/0xd10163ac93593667d3922a05c09580856b1b4c1dc015738c67968912a42c46dc
test("parse a swap on Mode (BEAST for ezETH) with Settler", async () => {
const publicClient = createPublicClient({
chain: mode,
transport: http(
`https://fluent-boldest-water.mode-mainnet.quiknode.pro/${process.env.QUICKNODE_API_KEY}`
),
}) as PublicClient<Transport, Chain>;

const transactionHash = `0xd10163ac93593667d3922a05c09580856b1b4c1dc015738c67968912a42c46dc`;

const result = await parseSwap({
publicClient,
transactionHash,
});

expect(result).toEqual({
tokenIn: {
symbol: "BEAST",
amount: "238973",
address: "0x6a660e56FA3b630A786CC4Ae98859f8532D03dE9",
},
tokenOut: {
symbol: "ezETH",
amount: "0.000846925725410518",
address: "0x2416092f143378750bb29b79eD961ab195CcEea5",
},
});
});

test.todo(
"parse a swap on Mode (ezETH for BEAST) with SettlerMetaTxn",
async () => {}
);
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,
mode,
blast,
linea,
scroll,
Expand All @@ -25,6 +26,7 @@ import type {
export type SupportedChainId =
| typeof bsc.id
| typeof base.id
| typeof mode.id
| typeof blast.id
| typeof linea.id
| typeof scroll.id
Expand Down
2 changes: 2 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { fromHex, erc20Abi, getAddress, formatUnits, formatEther } from "viem";
import {
bsc,
base,
mode,
blast,
linea,
scroll,
Expand All @@ -27,6 +28,7 @@ export function isChainIdSupported(
const supportedChainIds: number[] = [
bsc.id,
base.id,
mode.id,
blast.id,
linea.id,
scroll.id,
Expand Down

0 comments on commit 3ad4ea3

Please sign in to comment.