Skip to content

Commit 20439b5

Browse files
add test case for optimism
1 parent 1e29254 commit 20439b5

File tree

5 files changed

+35
-51
lines changed

5 files changed

+35
-51
lines changed

.env.example

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# This is an `.env.example` file. You must rename it to `.env` and fill in the values.
2-
3-
# Required: Alchemy API key for Ethereum mainnet and various chain tests
2+
# An Ethereum RPC node is required to run the tests. You can use an Alchemy RPC node or a local node:
43
# Create an Alchemy API key: https://docs.alchemy.com/docs/alchemy-quickstart-guide
4+
# Or even better, run a local node: https://ethereum.org/en/run-a-node and use it's RPC URL.
5+
ETH_MAINNET_RPC="https://eth-mainnet.g.alchemy.com/v2/<your-api-key>"
56
ALCHEMY_API_KEY="your-alchemy-api-key-here"
67

7-
# Required: Ethereum mainnet RPC
8-
ETH_MAINNET_RPC="https://eth-mainnet.g.alchemy.com/v2/<your-api-key>"
98

109
# Required: QuickNode API keys for specific chain tests
1110
# Sign up at https://quicknode.com for free trial with debug method support

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
QUICKNODE_MANTLE_API_KEY: ${{ secrets.QUICKNODE_MANTLE_API_KEY }}
1919
QUICKNODE_BNB_CHAIN_API_KEY: ${{ secrets.QUICKNODE_BNB_CHAIN_API_KEY }}
2020
QUICKNODE_MODE_API_KEY: ${{ secrets.QUICKNODE_MODE_API_KEY }}
21-
BASE_MAINNET_RPC: ${{ secrets.BASE_MAINNET_RPC }}
2221
- uses: codecov/codecov-action@v3
2322
with:
2423
token: ${{ secrets.CODECOV_TOKEN }}

src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ import {
1919
isChainIdSupported,
2020
calculateNativeTransfer,
2121
parseSmartContractWalletTx,
22-
calculateNetTransfers,
23-
findLargestInflow,
24-
findLargestOutflow,
2522
} from "./utils";
2623
import type { Hash, Chain, Address, Transport, PublicClient } from "viem";
2724
import type { TraceTransactionSchema } from "./types";

src/tests/index.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,7 @@ test("logs a warning for reverted transactions)", async () => {
14561456
warnSpy.mockRestore();
14571457
});
14581458

1459+
//https://etherscan.io/tx/0x7eea91c5c715ef4bb1e39ddf4c7832113693e87c18392740353d5ae669406a46
14591460
test("parse a swap on Ethereum (USDC for WMON) with SettlerIntent", async () => {
14601461
const transactionHash = "0x7eea91c5c715ef4bb1e39ddf4c7832113693e87c18392740353d5ae669406a46";
14611462

@@ -1476,4 +1477,35 @@ test("parse a swap on Ethereum (USDC for WMON) with SettlerIntent", async () =>
14761477
address: "0x6917037f8944201b2648198a89906edf863b9517",
14771478
},
14781479
});
1480+
});
1481+
1482+
// https://optimistic.etherscan.io/tx/0xdee6f4fea0250f297ed9663c4ca4479e8a253c62e16faa60759e25832cd1f34f
1483+
test("parse a swap on Optimism (wstETH for ETH) via Balancer pool", async () => {
1484+
const publicClient = createPublicClient({
1485+
chain: optimism,
1486+
transport: http(
1487+
`https://opt-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
1488+
),
1489+
}) as PublicClient<Transport, Chain>;
1490+
1491+
const transactionHash =
1492+
"0xdee6f4fea0250f297ed9663c4ca4479e8a253c62e16faa60759e25832cd1f34f";
1493+
1494+
const result = await parseSwap({
1495+
publicClient,
1496+
transactionHash,
1497+
});
1498+
1499+
expect(result).toEqual({
1500+
tokenIn: {
1501+
symbol: "wstETH",
1502+
amount: "0.008868",
1503+
address: "0x1f32b1c2345538c0c6f582fcb022739c4a194ebb",
1504+
},
1505+
tokenOut: {
1506+
symbol: "WETH",
1507+
amount: "0.010698199301849867",
1508+
address: "0x4200000000000000000000000000000000000006",
1509+
},
1510+
});
14791511
});

src/utils/index.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -223,46 +223,3 @@ export function parseSmartContractWalletTx({
223223

224224
return null;
225225
}
226-
227-
export interface NetTransfer {
228-
tokenAddress: `0x${string}`;
229-
netAmount: bigint;
230-
symbol?: string;
231-
}
232-
233-
export function calculateNetTransfers(
234-
logs: any[],
235-
userAddress: `0x${string}`
236-
): NetTransfer[] {
237-
const netByToken = new Map<string, bigint>();
238-
239-
for (const log of logs) {
240-
const tokenAddress = log.address.toLowerCase();
241-
const amount = log.amountRaw;
242-
243-
if (log.from.toLowerCase() === userAddress.toLowerCase()) {
244-
netByToken.set(tokenAddress, (netByToken.get(tokenAddress) || 0n) - amount);
245-
}
246-
247-
if (log.to.toLowerCase() === userAddress.toLowerCase()) {
248-
netByToken.set(tokenAddress, (netByToken.get(tokenAddress) || 0n) + amount);
249-
}
250-
}
251-
252-
return Array.from(netByToken.entries()).map(([address, amount]) => ({
253-
tokenAddress: address as `0x${string}`,
254-
netAmount: amount
255-
}));
256-
}
257-
258-
export function findLargestOutflow(netTransfers: NetTransfer[]): NetTransfer | null {
259-
return netTransfers
260-
.filter(t => t.netAmount < 0n)
261-
.sort((a, b) => Number(a.netAmount - b.netAmount))[0] || null;
262-
}
263-
264-
export function findLargestInflow(netTransfers: NetTransfer[]): NetTransfer | null {
265-
return netTransfers
266-
.filter(t => t.netAmount > 0n)
267-
.sort((a, b) => Number(b.netAmount - a.netAmount))[0] || null;
268-
}

0 commit comments

Comments
 (0)