Skip to content

Commit 9020b47

Browse files
committed
fix: use log that has taker from transfer for meta txn
1 parent 65e6b95 commit 9020b47

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
QUICKNODE_API_KEY: ${{ secrets.QUICKNODE_API_KEY }}
1818
QUICKNODE_MANTLE_API_KEY: ${{ secrets.QUICKNODE_MANTLE_API_KEY }}
1919
QUICKNODE_BNB_CHAIN_API_KEY: ${{ secrets.QUICKNODE_BNB_CHAIN_API_KEY }}
20+
QUICKNODE_MODE_API_KEY: ${{ secrets.QUICKNODE_MODE_API_KEY }}
2021
- uses: codecov/codecov-action@v3
2122
with:
2223
token: ${{ secrets.CODECOV_TOKEN }}

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,16 @@ export async function parseSwap({
150150

151151
const { 3: msgSender } = args;
152152

153+
const logsFromTaker = logs.filter((log) => log.from === msgSender);
154+
153155
const nativeAmountToTaker = calculateNativeTransfer(trace, {
154156
recipient: msgSender,
155157
});
156158

159+
if (logsFromTaker.length) {
160+
input = logsFromTaker[0];
161+
}
162+
157163
if (nativeAmountToTaker === "0") {
158164
output = logs[logs.length - 1];
159165
const takerReceived = logs.filter(

src/tests/index.test.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ test("parses swapped amounts case 1 (default)", async () => {
8686
});
8787
});
8888

89+
// https://etherscan.io/tx/0x761521a243ca56338b8bcbcf0d4bfc230ff349bb36e31472ac1d850977bdc484
90+
test("parses swapped amounts for meta transaction", async () => {
91+
const transactionHash =
92+
"0x761521a243ca56338b8bcbcf0d4bfc230ff349bb36e31472ac1d850977bdc484";
93+
94+
const result = await parseSwap({
95+
publicClient,
96+
transactionHash,
97+
});
98+
99+
expect(result).toEqual({
100+
tokenIn: {
101+
symbol: "ZRX",
102+
amount: "833.3332",
103+
address: "0xE41d2489571d322189246DaFA5ebDe1F4699F498",
104+
},
105+
tokenOut: {
106+
symbol: "ETH",
107+
amount: "0.08832649392868776",
108+
address: NATIVE_TOKEN_ADDRESS,
109+
},
110+
});
111+
});
112+
89113
// https://etherscan.io/tx/0x76b744ab42b05b30624bd5027b4f7da841cdc357bb1d6ee74e3d9e049dd8a126
90114
test("parses swapped amounts case 2 (default)", async () => {
91115
const transactionHash =
@@ -1182,7 +1206,7 @@ test("parse a swap on Mode (ETH for BEAST) with Settler", async () => {
11821206
const publicClient = createPublicClient({
11831207
chain: mode,
11841208
transport: http(
1185-
`https://fluent-boldest-water.mode-mainnet.quiknode.pro/${process.env.QUICKNODE_API_KEY}`
1209+
`https://nameless-still-sound.mode-mainnet.quiknode.pro/${process.env.QUICKNODE_MODE_API_KEY}`
11861210
),
11871211
}) as PublicClient<Transport, Chain>;
11881212

@@ -1212,7 +1236,7 @@ test("parse a swap on Mode (BEAST for ezETH) with Settler", async () => {
12121236
const publicClient = createPublicClient({
12131237
chain: mode,
12141238
transport: http(
1215-
`https://fluent-boldest-water.mode-mainnet.quiknode.pro/${process.env.QUICKNODE_API_KEY}`
1239+
`https://nameless-still-sound.mode-mainnet.quiknode.pro/${process.env.QUICKNODE_MODE_API_KEY}`
12161240
),
12171241
}) as PublicClient<Transport, Chain>;
12181242

@@ -1242,7 +1266,7 @@ test("parse a swap on Mode (ezETH for MODE) with SettlerMetaTxn", async () => {
12421266
const publicClient = createPublicClient({
12431267
chain: mode,
12441268
transport: http(
1245-
`https://fluent-boldest-water.mode-mainnet.quiknode.pro/${process.env.QUICKNODE_API_KEY}`
1269+
`https://nameless-still-sound.mode-mainnet.quiknode.pro/${process.env.QUICKNODE_MODE_API_KEY}`
12461270
),
12471271
}) as PublicClient<Transport, Chain>;
12481272

0 commit comments

Comments
 (0)