Skip to content

Commit

Permalink
fix: erc-20 transfers with SettlerMetaTxn
Browse files Browse the repository at this point in the history
  • Loading branch information
hzhu committed Jul 10, 2024
1 parent 3c72e68 commit 9bc6995
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/parseSwapV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,15 @@ export async function parseSwapV2({

const nativeTransferAmount = extractNativeTransfer(trace, taker);

output = {
symbol: NATIVE_SYMBOL_BY_CHAIN_ID[chainId],
amount: nativeTransferAmount,
address: NATIVE_TOKEN_ADDRESS,
};
if (nativeTransferAmount === "0") {
output = logs[logs.length - 1];
} else {
output = {
symbol: NATIVE_SYMBOL_BY_CHAIN_ID[chainId],
amount: nativeTransferAmount,
address: NATIVE_TOKEN_ADDRESS,
};
}
}

if (isNativeSell) {
Expand Down
31 changes: 31 additions & 0 deletions src/tests/parseSwapV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,37 @@ test("parse a gasless swap on Base (USDC for ETH) for SettlerMetaTxn", async ()
});
});

// https://basescan.org/tx/0xe595dec22a7e2c2c5bdb0c1a7e59b2302ede72e5d2210c6cd7071222ea6dc2b2
test("parse a gasless swap on Base (DEGEN for USDC) for SettlerMetaTxn", async () => {
const publicClient = createPublicClient({
chain: base,
transport: http(
`https://base-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
),
}) as PublicClient<Transport, Chain>;

const transactionHash =
"0xe595dec22a7e2c2c5bdb0c1a7e59b2302ede72e5d2210c6cd7071222ea6dc2b2";

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

expect(result).toEqual({
tokenIn: {
symbol: "DEGEN",
amount: "1392.424785087824779911",
address: "0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed",
},
tokenOut: {
symbol: "USDC",
amount: "9.915288",
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
},
});
});

// https://arbiscan.io/tx/0xb2c05194e4ec9ae0f82098ec82a606df544e87c8d6b7726bbb4b1dcc023cb9d7
test("parse a gasless swap on on Arbitrum (ARB for ETH)", async () => {
const publicClient = createPublicClient({
Expand Down

0 comments on commit 9bc6995

Please sign in to comment.