Skip to content

Commit c51a61c

Browse files
authored
feat: add support for Abstract chain (#97)
1 parent 9070f56 commit c51a61c

File tree

5 files changed

+61
-9
lines changed

5 files changed

+61
-9
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,20 @@
116116
<br>Plasma
117117
</div>
118118
</td>
119+
<td style="width:100px; text-align:center;">
120+
<div align="center">
121+
<img alt="Abstract" src="https://www.abs.xyz/favicon.ico" width="24"/>
122+
<br>Abstract
123+
</div>
124+
</td>
125+
</tr>
126+
<tr>
119127
<td style="width:100px; text-align:center;">
120128
<div align="center">
121129
<img alt="coming soon" src="https://i.imgur.com/CexTjqF.png" width="22"/>
122130
<br>🔜
123131
</div>
124132
</td>
125-
</tr>
126-
<tr>
127133
<td style="width:100px; text-align:center;">
128134
<div align="center">
129135
<img alt="coming soon" src="https://cdn.prod.website-files.com/63692bf32544bee8b1836ea6/637b01428c7bd8e16af26756_favicon-32.png" width="22"/>

src/constants.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
avalanche,
1616
berachain,
1717
worldchain,
18-
monad
18+
monad,
19+
abstract,
1920
} from "viem/chains";
2021
import type { SupportedChainId } from "./types";
2122

@@ -132,6 +133,7 @@ export const SUPPORTED_CHAINS = [
132133
berachain,
133134
worldchain,
134135
monad,
136+
abstract,
135137
];
136138

137139
export const NATIVE_SYMBOL_BY_CHAIN_ID: { [key in SupportedChainId]: string } =
@@ -153,6 +155,7 @@ export const NATIVE_SYMBOL_BY_CHAIN_ID: { [key in SupportedChainId]: string } =
153155
[avalanche.id]: avalanche.nativeCurrency.symbol,
154156
[berachain.id]: berachain.nativeCurrency.symbol,
155157
[worldchain.id]: worldchain.nativeCurrency.symbol,
158+
[abstract.id]: abstract.nativeCurrency.symbol,
156159
};
157160

158161
export const NATIVE_TOKEN_ADDRESS = `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`;

src/tests/index.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
berachain,
2121
bsc,
2222
celo,
23+
abstract,
2324
} from "viem/chains";
2425
import { vi, test, expect } from "vitest";
2526
import { parseSwap } from "../index";
@@ -1533,3 +1534,34 @@ test("parse a swap on Mainnet (TRG for SHITCOIN)", async () => {
15331534
},
15341535
});
15351536
});
1537+
1538+
// https://abscan.org/tx/0x89d0b2806d53d06a9b7f8105c041ec2d114f6b75ce3ea85a8c7bdb4ce8ae3d5a
1539+
test("parse a swap on Abstract (PENGU for USDC.e)", async () => {
1540+
const publicClient = createPublicClient({
1541+
chain: abstract,
1542+
transport: http(
1543+
`https://abstract-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
1544+
),
1545+
}) as PublicClient<Transport, Chain>;
1546+
1547+
const transactionHash =
1548+
"0x89d0b2806d53d06a9b7f8105c041ec2d114f6b75ce3ea85a8c7bdb4ce8ae3d5a";
1549+
1550+
const result = await parseSwap({
1551+
publicClient,
1552+
transactionHash,
1553+
});
1554+
1555+
expect(result).toEqual({
1556+
tokenIn: {
1557+
symbol: "PENGU",
1558+
amount: "313.635629165192342644",
1559+
address: "0x9eBe3A824Ca958e4b3Da772D2065518F009CBa62",
1560+
},
1561+
tokenOut: {
1562+
symbol: "USDC.e",
1563+
amount: "2.98552",
1564+
address: "0x84A71ccD554Cc1b02749b35d22F684CC8ec987e1",
1565+
},
1566+
});
1567+
});

src/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import {
1515
worldchain,
1616
berachain,
1717
unichain,
18-
monad
18+
monad,
19+
abstract,
1920
} from "viem/chains";
2021

2122
import type {
@@ -45,7 +46,8 @@ export type SupportedChainId =
4546
| typeof optimism.id
4647
| typeof avalanche.id
4748
| typeof berachain.id
48-
| typeof worldchain.id;
49+
| typeof worldchain.id
50+
| typeof abstract.id;
4951

5052
export interface EnrichLogsArgs {
5153
transactionReceipt: TransactionReceipt;

src/utils/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
avalanche,
1717
berachain,
1818
worldchain,
19-
monad
19+
monad,
20+
abstract,
2021
} from "viem/chains";
2122
import { NATIVE_SYMBOL_BY_CHAIN_ID, NATIVE_TOKEN_ADDRESS } from "../constants";
2223
import type { Address } from "viem";
@@ -48,6 +49,7 @@ export function isChainIdSupported(
4849
avalanche.id,
4950
berachain.id,
5051
worldchain.id,
52+
abstract.id,
5153
];
5254
return supportedChainIds.includes(chainId);
5355
}
@@ -111,8 +113,15 @@ export async function transferLogs({
111113
const midpoint = Math.floor(results.length / 2);
112114
const enrichedLogs = transferLogsAddresses
113115
.map((log, index) => {
114-
const symbol = results[index].result as string;
115-
const decimals = results[midpoint + index].result as number;
116+
const symbol = results[index].result;
117+
const decimals = results[midpoint + index].result;
118+
119+
// zkSync-style system contracts can emit Transfer-like logs for native accounting,
120+
// but those addresses do not implement ERC20 metadata, so skip them here.
121+
if (symbol == null || decimals == null || typeof decimals !== "number") {
122+
return null;
123+
}
124+
116125
const amount =
117126
log.data === "0x" ? "0" : formatUnits(BigInt(log.data), decimals);
118127
const amountRaw = log.data === "0x" ? 0n : BigInt(log.data);
@@ -123,7 +132,7 @@ export async function transferLogs({
123132

124133
return { to, from, symbol, amount, amountRaw, address, decimals };
125134
})
126-
.filter((log) => log.amount !== "0");
135+
.filter((log): log is EnrichedLog => log != null && log.amount !== "0")
127136

128137
return enrichedLogs;
129138
}

0 commit comments

Comments
 (0)