File tree 2 files changed +37
-0
lines changed
2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,12 @@ export async function parseSwap({
173
173
} ;
174
174
}
175
175
176
+ if ( ! output && input . from ) {
177
+ output = logs . find (
178
+ ( log ) => log . to . toLowerCase ( ) === input . from . toLowerCase ( )
179
+ ) ;
180
+ }
181
+
176
182
/* v8 ignore start */
177
183
if ( ! output ) {
178
184
console . error (
Original file line number Diff line number Diff line change @@ -259,6 +259,37 @@ test("throws an error for unsupported chains)", async () => {
259
259
} ) . rejects . toThrowError ( "chainId 42220 is unsupported…" ) ;
260
260
} ) ;
261
261
262
+ // https://basescan.org/tx/0x314ea35ef3120934ee4714f4815dc3b08dc2ab0e32e0662bfba3cdbcff14d79b
263
+ test ( "parse a gasless swap on Base (DAI for USDC)" , async ( ) => {
264
+ const publicClient = createPublicClient ( {
265
+ chain : base ,
266
+ transport : http (
267
+ `https://base-mainnet.g.alchemy.com/v2/${ process . env . ALCHEMY_API_KEY } `
268
+ ) ,
269
+ } ) as PublicClient < Transport , Chain > ;
270
+
271
+ const transactionHash =
272
+ "0x314ea35ef3120934ee4714f4815dc3b08dc2ab0e32e0662bfba3cdbcff14d79b" ;
273
+
274
+ const result = await parseSwap ( {
275
+ publicClient,
276
+ transactionHash,
277
+ } ) ;
278
+
279
+ expect ( result ) . toEqual ( {
280
+ tokenIn : {
281
+ symbol : "DAI" ,
282
+ amount : "1.998484821908329022" ,
283
+ address : "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb" ,
284
+ } ,
285
+ tokenOut : {
286
+ symbol : "USDC" ,
287
+ amount : "1.982641" ,
288
+ address : "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" ,
289
+ } ,
290
+ } ) ;
291
+ } ) ;
292
+
262
293
// https://basescan.org/tx/0xa09cb1606e30c3aed8a842723fd6c23cecd838a59f750ab3dbc5ef2c7486e696
263
294
test ( "parse a swap on Base (USDC for DAI)" , async ( ) => {
264
295
const publicClient = createPublicClient ( {
You can’t perform that action at this time.
0 commit comments