Skip to content

Commit 8186963

Browse files
committed
feat: worldchain support
1 parent a3a0c0c commit 8186963

File tree

6 files changed

+80
-10
lines changed

6 files changed

+80
-10
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686
</td>
8787
</tr>
8888
<tr>
89+
<td style="width:100px; text-align:center;">
90+
<div align="center">
91+
<img alt="Worldchain" src="https://cdn.prod.website-files.com/6503306c491d20f69e484470/6718ce22ee5879d832765fd6_66ced64f18a10922ffcff77d_65d8bce782514cfb6c149b7a_1VQdZPHJ_400x400.webp" width="22"/>
92+
<br>Worldchain
93+
</div>
94+
</td>
8995
<td style="width:100px; text-align:center;">
9096
<div align="center">
9197
<img alt="coming soon" src="https://i.imgur.com/CexTjqF.png" width="22"/>
@@ -116,12 +122,7 @@
116122
<br>🔜
117123
</div>
118124
</td>
119-
<td style="width:100px; text-align:center;">
120-
<div align="center">
121-
<img alt="coming soon" src="https://uc0b21458bb164b77e02b55e693f.previews.dropboxusercontent.com/p/thumb/ACd46XAdDQOjnDUQFKFEF15nMyLugKxfdnezVxHzCDAGt4bVB8l6AJVJB83hl1gSLMXlMtGzODSzMu-HaX-B5fzDVqvAcLTidJitmhGWq8qUjnLMAXE7hwYZJvU9QcKmwdJD9Qb9QyXzB-eGceNuj0b_IWLWL3vrQZguOjJWdMm9rT68SpLT7nG13gnxZxoXuCV5myYxOYVQ5zBx6DchblRIzFzeEpxuI4ciaH9phUCbP_4M5cV1aqSDBtwfWgbMHzTJ5nukSPY4-1hg2irDAFYgclLXV-pw_jfKmZgqKfW7HizolfD5-Gb1EL10Os2dfsurNu0FTqLrxYJrTZ7Qhzxzr1hwI9-m1Qo--3R2AezSNYgv4YGBy33sDvWhNgy-Xn8K1MhNtG8HMInuEYkaKv6XtVDJssG8wEbW1hDOfmqpaV2SMuWwPehX0Ry4dvJ6dN7axGNBU-Xcorl52AWan5C3727K9RaifMl2TAFvunoCNxtFghRjNpYuiV3Q9IBXd--O4Cca8K07bloVSH-ectkbJIp_tT4dI_yBL32qnG26fL4a1sGzKpcrZZCQsyq0fwVWll2yzru3k71EQRoIjvnuFcyvGOScYrnJOWmFp7d2eABwlG4-T3U8ZYvjn5NY2UYo9kUeCY-Ev--2WExLqfCKga_19tA6FGk8CMhuf_gvAE0hfsgmi3PYiqTjj1mviJIc_o3Mkx6eLMIXHHaTIxqjvP_V219UiimJgNwfreCM7wkIpkGW0BuRyBzAjfgW3C2hB2cJGF8OhBn-cKnrNEU1WSC-TVKrcPwlDH3ticPQOD7hXucL110aBmxY_KacBPI2Br4HioXKYTWsTfrRnVbjB0KpE0RWtstyryG-pMq-vA/p.png" width="22"/>
122-
<br>🔜
123-
</div>
124-
</td>
125+
125126
</tr>
126127
</table>
127128

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
arbitrum,
1212
optimism,
1313
avalanche,
14+
worldchain,
1415
} from "viem/chains";
1516
import type { SupportedChainId } from "./types";
1617

@@ -59,6 +60,7 @@ export const NATIVE_SYMBOL_BY_CHAIN_ID: { [key in SupportedChainId]: string } =
5960
[optimism.id]: optimism.nativeCurrency.symbol,
6061
[arbitrum.id]: arbitrum.nativeCurrency.symbol,
6162
[avalanche.id]: avalanche.nativeCurrency.symbol,
63+
[worldchain.id]: worldchain.nativeCurrency.symbol,
6264
};
6365

6466
export const NATIVE_TOKEN_ADDRESS = `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`;

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export async function parseSwap({
189189
{ symbol: "", amount: "", address: "" }
190190
);
191191

192+
console.log("B");
192193
return {
193194
tokenIn: {
194195
symbol: NATIVE_SYMBOL_BY_CHAIN_ID[chainId],
@@ -208,6 +209,7 @@ export async function parseSwap({
208209
}
209210
/* v8 ignore stop */
210211

212+
console.log("A");
211213
return {
212214
tokenIn: {
213215
symbol: input.symbol,

src/tests/index.test.ts

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
arbitrum,
1717
optimism,
1818
mantle,
19+
worldchain,
1920
} from "viem/chains";
2021
import { test, expect } from "vitest";
2122
import { parseSwap } from "../index";
@@ -642,9 +643,7 @@ test("parse a gasless swap on Optimism (USDC for OP) for execute", async () => {
642643
});
643644
});
644645

645-
// TODO: remove skip or test different tx hash, RPC provider cannot fetch this transaction hash.
646-
// https://bscscan.com/tx/0xdda12da1e32c3320082355c985d6f2c6559169989de51e3cc83123395516c057
647-
test.skip("parse a swap on BNB Chain (ETH for USDC) for execute", async () => {
646+
test("parse a swap on BNB Chain (ETH for USDC) for execute", async () => {
648647
const publicClient = createPublicClient({
649648
chain: optimism,
650649
transport: http(
@@ -1233,3 +1232,65 @@ test("parse a swap on Mode (ezETH for MODE) with SettlerMetaTxn", async () => {
12331232
},
12341233
});
12351234
});
1235+
1236+
// https://worldscan.org/tx/0xc6b6a747910ff6ff6262f3a7067db5d48fb83d774f3556bee7654b020f0e875d
1237+
test("parse a swap on Worldchain (USDC.e for WLD) with Settler", async () => {
1238+
const publicClient = createPublicClient({
1239+
chain: worldchain,
1240+
transport: http(
1241+
`https://worldchain-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
1242+
),
1243+
}) as PublicClient<Transport, Chain>;
1244+
1245+
const transactionHash = `0xc6b6a747910ff6ff6262f3a7067db5d48fb83d774f3556bee7654b020f0e875d`;
1246+
1247+
const result = await parseSwap({
1248+
publicClient,
1249+
transactionHash,
1250+
});
1251+
1252+
expect(result).toEqual({
1253+
tokenIn: {
1254+
symbol: "USDC.e",
1255+
amount: "0.8",
1256+
address: "0x79A02482A880bCE3F13e09Da970dC34db4CD24d1",
1257+
},
1258+
tokenOut: {
1259+
symbol: "WLD",
1260+
amount: "0.382406307673532742",
1261+
address: "0x2cFc85d8E48F8EAB294be644d9E25C3030863003",
1262+
},
1263+
});
1264+
});
1265+
1266+
// https://worldscan.org/tx/0x4c095630a5b87cd2c04fcc2cf08940ed8251f6d451efc61e1e90b42775d4f051
1267+
test("parse a swap on Worldchain (ETH for USDC.e) with Settler", async () => {
1268+
const publicClient = createPublicClient({
1269+
chain: worldchain,
1270+
transport: http(
1271+
`https://worldchain-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
1272+
),
1273+
}) as PublicClient<Transport, Chain>;
1274+
1275+
const transactionHash = `0x4c095630a5b87cd2c04fcc2cf08940ed8251f6d451efc61e1e90b42775d4f051`;
1276+
1277+
const result = await parseSwap({
1278+
publicClient,
1279+
transactionHash,
1280+
});
1281+
1282+
console.log(result, "<--result");
1283+
1284+
expect(result).toEqual({
1285+
tokenIn: {
1286+
symbol: "ETH",
1287+
amount: "0.001",
1288+
address: NATIVE_TOKEN_ADDRESS,
1289+
},
1290+
tokenOut: {
1291+
symbol: "USDC.e",
1292+
amount: "3.332454",
1293+
address: "0x79A02482A880bCE3F13e09Da970dC34db4CD24d1",
1294+
},
1295+
});
1296+
});

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
arbitrum,
1212
optimism,
1313
avalanche,
14+
worldchain,
1415
} from "viem/chains";
1516

1617
import type {
@@ -35,7 +36,8 @@ export type SupportedChainId =
3536
| typeof polygon.id
3637
| typeof arbitrum.id
3738
| typeof optimism.id
38-
| typeof avalanche.id;
39+
| typeof avalanche.id
40+
| typeof worldchain.id;
3941

4042
export interface EnrichLogsArgs {
4143
transactionReceipt: TransactionReceipt;

src/utils/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
arbitrum,
1313
optimism,
1414
avalanche,
15+
worldchain,
1516
} from "viem/chains";
1617
import { NATIVE_SYMBOL_BY_CHAIN_ID, NATIVE_TOKEN_ADDRESS } from "../constants";
1718
import type { Address } from "viem";
@@ -38,6 +39,7 @@ export function isChainIdSupported(
3839
arbitrum.id,
3940
optimism.id,
4041
avalanche.id,
42+
worldchain.id,
4143
];
4244
return supportedChainIds.includes(chainId);
4345
}

0 commit comments

Comments
 (0)