@@ -7,12 +7,14 @@ import {
77} from "viem" ;
88import {
99 SUPPORTED_CHAINS ,
10- MULTICALL3_ADDRESS ,
10+ FORWARDING_MULTICALL_ABI ,
1111 FUNCTION_SELECTORS ,
1212 ERC_4337_ENTRY_POINT ,
1313 NATIVE_TOKEN_ADDRESS ,
1414 SETTLER_META_TXN_ABI ,
1515 NATIVE_SYMBOL_BY_CHAIN_ID ,
16+ FORWARDING_MULTICALL_ADDRESS ,
17+ MULTICALL3_ADDRESS ,
1618} from "./constants" ;
1719import {
1820 transferLogs ,
@@ -112,7 +114,40 @@ export async function parseSwap({
112114 amount : nativeAmountToTaker ,
113115 address : NATIVE_TOKEN_ADDRESS ,
114116 } ;
117+ if ( to ?. toLowerCase ( ) === FORWARDING_MULTICALL_ADDRESS . toLowerCase ( ) ) {
118+ const { args : multicallArgs } = decodeFunctionData ( {
119+ abi : FORWARDING_MULTICALL_ABI ,
120+ data : transaction . input ,
121+ } ) ;
115122
123+ if ( multicallArgs && Array . isArray ( multicallArgs ) && multicallArgs [ 0 ] && Array . isArray ( multicallArgs [ 0 ] ) ) {
124+ const { args : settlerArgs } = decodeFunctionData ( {
125+ abi : SETTLER_META_TXN_ABI ,
126+ data : multicallArgs [ 0 ] [ 1 ] ?. data ,
127+ } ) ;
128+
129+ const recipient =
130+ settlerArgs [ 0 ] . recipient . toLowerCase ( ) as Address ;
131+
132+ const msgSender = settlerArgs [ 3 ] ;
133+
134+ const nativeAmountToTaker = calculateNativeTransfer ( trace , {
135+ recipient,
136+ } ) ;
137+
138+ if ( nativeAmountToTaker === "0" ) {
139+ [ output ] = logs . filter (
140+ ( log ) => log . to . toLowerCase ( ) === msgSender . toLowerCase ( )
141+ ) ;
142+ } else {
143+ output = {
144+ symbol : NATIVE_SYMBOL_BY_CHAIN_ID [ chainId ] ,
145+ amount : nativeAmountToTaker ,
146+ address : NATIVE_TOKEN_ADDRESS ,
147+ } ;
148+ }
149+ }
150+ }
116151 if ( to ?. toLowerCase ( ) === MULTICALL3_ADDRESS . toLowerCase ( ) ) {
117152 const { args : multicallArgs } = decodeFunctionData ( {
118153 abi : multicall3Abi ,
@@ -122,7 +157,7 @@ export async function parseSwap({
122157 if ( multicallArgs [ 0 ] ) {
123158 const { args : settlerArgs } = decodeFunctionData ( {
124159 abi : SETTLER_META_TXN_ABI ,
125- data : multicallArgs [ 0 ] [ 1 ] . callData ,
160+ data : multicallArgs [ 0 ] [ 1 ] ? .callData ,
126161 } ) ;
127162
128163 const takerForGaslessApprovalSwap =
@@ -245,4 +280,4 @@ export async function parseSwap({
245280 address : output . address ,
246281 } ,
247282 } ;
248- }
283+ }
0 commit comments