Skip to content

Commit 580c138

Browse files
committed
feat: support parsing transactions on berachain
1 parent 0f49539 commit 580c138

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@
100100
</td>
101101
<td style="width:100px; text-align:center;">
102102
<div align="center">
103-
<img alt="coming soon" src="https://i.imgur.com/CexTjqF.png" width="22"/>
104-
<br>🔜
103+
<img alt="coming soon" src="https://www.berachain.com/icon.svg" width="24"/>
104+
<br>Berachain
105105
</div>
106106
</td>
107107
<td style="width:100px; text-align:center;">
108108
<div align="center">
109-
<img alt="coming soon" src="https://i.imgur.com/c5GLXZm.png" width="22"/>
109+
<img alt="coming soon" src="https://i.imgur.com/CexTjqF.png" width="22"/>
110110
<br>🔜
111111
</div>
112112
</td>

src/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
unichain,
1313
optimism,
1414
avalanche,
15+
berachain,
1516
worldchain,
1617
} from "viem/chains";
1718
import type { SupportedChainId } from "./types";
@@ -62,6 +63,7 @@ export const NATIVE_SYMBOL_BY_CHAIN_ID: { [key in SupportedChainId]: string } =
6263
[optimism.id]: optimism.nativeCurrency.symbol,
6364
[arbitrum.id]: arbitrum.nativeCurrency.symbol,
6465
[avalanche.id]: avalanche.nativeCurrency.symbol,
66+
[berachain.id]: berachain.nativeCurrency.symbol,
6567
[worldchain.id]: worldchain.nativeCurrency.symbol,
6668
};
6769

src/tests/index.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
optimism,
1818
mantle,
1919
worldchain,
20+
berachain,
2021
} from "viem/chains";
2122
import { test, expect } from "vitest";
2223
import { parseSwap } from "../index";
@@ -1353,3 +1354,33 @@ test("parse a swap on Unichain (WETH for USDC) with AllowanceHolder", async () =
13531354
},
13541355
});
13551356
});
1357+
1358+
// https://berascan.com/tx/0xaf644cef00ca79ee0365218d02cf238c2b4a5e9a1b1e7cfccaee1542fb19211b
1359+
test("parse a swap on Berachain (WETH for WBERA) with AllowanceHolder", async () => {
1360+
const publicClient = createPublicClient({
1361+
chain: berachain,
1362+
transport: http(
1363+
`https://berachain-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
1364+
),
1365+
}) as PublicClient<Transport, Chain>;
1366+
1367+
const transactionHash = `0xaf644cef00ca79ee0365218d02cf238c2b4a5e9a1b1e7cfccaee1542fb19211b`;
1368+
1369+
const result = await parseSwap({
1370+
publicClient,
1371+
transactionHash,
1372+
});
1373+
1374+
expect(result).toEqual({
1375+
tokenIn: {
1376+
symbol: "WETH",
1377+
amount: "0.0025",
1378+
address: "0x2F6F07CDcf3588944Bf4C42aC74ff24bF56e7590",
1379+
},
1380+
tokenOut: {
1381+
symbol: "WBERA",
1382+
amount: "1.116831193710334426",
1383+
address: "0x6969696969696969696969696969696969696969",
1384+
},
1385+
});
1386+
});

src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
optimism,
1313
avalanche,
1414
worldchain,
15+
berachain,
1516
unichain,
1617
} from "viem/chains";
1718

@@ -39,6 +40,7 @@ export type SupportedChainId =
3940
| typeof unichain.id
4041
| typeof optimism.id
4142
| typeof avalanche.id
43+
| typeof berachain.id
4244
| typeof worldchain.id;
4345

4446
export interface EnrichLogsArgs {

src/utils/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
optimism,
1414
unichain,
1515
avalanche,
16+
berachain,
1617
worldchain,
1718
} from "viem/chains";
1819
import { NATIVE_SYMBOL_BY_CHAIN_ID, NATIVE_TOKEN_ADDRESS } from "../constants";
@@ -41,6 +42,7 @@ export function isChainIdSupported(
4142
optimism.id,
4243
unichain.id,
4344
avalanche.id,
45+
berachain.id,
4446
worldchain.id,
4547
];
4648
return supportedChainIds.includes(chainId);

0 commit comments

Comments
 (0)