@@ -33,17 +33,19 @@ export default function main(): void {
3333 // Get the token and the amount from the event emitted by the task that triggered this one
3434 const tokenStr = evm . decode ( new EvmDecodeParam ( 'address' , event . data . toHexString ( ) ) )
3535 const token = Address . fromString ( tokenStr )
36- const output = evm . decode ( new EvmDecodeParam ( 'uint256[]' , event . output . toHexString ( ) ) )
37- const amountsOut = JSON . parse < string [ ] > ( output )
38- const amount = BigInt . fromString ( amountsOut [ 0 ] )
36+
37+ const amountsStr = evm . decode ( new EvmDecodeParam ( 'uint256[]' , event . output . toHexString ( ) ) )
38+ const amounts = JSON . parse < string [ ] > ( amountsStr )
39+ if ( amounts . length == 0 ) throw new Error ( 'Empty amounts array' )
40+ const amount = BigInt . fromString ( amounts [ 0 ] )
3941
4042 const feeToken = new ERC20Token ( inputs . feeToken , chainId )
4143 const maxFee = TokenAmount . fromStringDecimal ( feeToken , inputs . maxFee )
4244
4345 const approveData = ERC20Utils . encodeApprove ( aaveV3Pool , amount )
4446 const supplyData = AavePoolUtils . encodeSupply ( token , amount , smartAccount , 0 )
4547
46- // Deposit USDC owned by the smart account
48+ // Give approval and deposit the tokens, owned by the smart account
4749 EvmCallBuilder . forChain ( chainId )
4850 . addCall ( token , approveData )
4951 . addCall ( aaveV3Pool , supplyData )
0 commit comments