22 createVincentAbility ,
33 supportedPoliciesForAbility ,
44} from '@lit-protocol/vincent-ability-sdk' ;
5- import { base , getCallDataForSwap , getDefaultConfig , getQuoteForSwap } from 'sugar-sdk' ;
5+ import { base , getDefaultConfig , getQuoteForSwap , swap } from 'sugar-sdk' ;
66import { ethers } from 'ethers' ;
77
88import {
@@ -15,7 +15,7 @@ import {
1515} from './schemas' ;
1616import { AbilityAction , CheckNativeTokenBalanceResultSuccess } from './types' ;
1717import { checkErc20Allowance , checkErc20Balance , checkNativeTokenBalance } from './ability-checks' ;
18- import { executeSwapParams , getChainConfig , getSwapVars , type Quote } from 'sugar-sdk/primitives' ;
18+ import { getChainConfig , type Quote } from 'sugar-sdk/primitives' ;
1919import { findSupportedTokenOnBase } from './ability-helpers/find-supported-token-on-base' ;
2020import { sendAerodromeSwapTx , sendErc20ApprovalTx } from './ability-helpers' ;
2121
@@ -364,69 +364,28 @@ export const vincentAbility = createVincentAbility({
364364 }
365365 const { quote } : { quote : Quote } = parsedQuoteResponse ;
366366
367- // 3.3 Get the Sugar calldata for the swap quote
368- console . log (
369- '[@lit-protocol/vincent-ability-aerodrome-swap execute] Getting Sugar calldata for swap quote' ,
370- ) ;
371- const sugarCallDataForSwap = await getCallDataForSwap ( {
367+ // 3.3 Get the swap calldata
368+ console . log ( '[@lit-protocol/vincent-ability-aerodrome-swap execute] Getting swap calldata' ) ;
369+ const swapData = await swap ( {
372370 config : sugarConfigBaseMainnet ,
373- fromToken : quote . fromToken ,
374- toToken : quote . toToken ,
375- amountIn : requiredTokenInAmount . toBigInt ( ) ,
371+ quote,
376372 account : delegatorPkpInfo . ethAddress as `0x${string } `,
377373 slippage : SLIPPAGE ,
378- } ) ;
379- if ( sugarCallDataForSwap === null ) {
380- return fail ( {
381- reason : 'Unable to generate call data for the Aerodrome swap quote' ,
382- } ) ;
383- }
384-
385- // 3.4 Get the Sugar swap vars for the swap quote
386- console . log (
387- '[@lit-protocol/vincent-ability-aerodrome-swap execute] Getting Sugar swap vars for swap quote' ,
388- ) ;
389- const { chainId, planner, amount } = getSwapVars (
390- sugarConfigBaseMainnet . sugarConfig ,
391- quote ,
392- `${ Math . ceil ( SLIPPAGE * 100 ) } ` ,
393- delegatorPkpInfo . ethAddress as `0x${string } `,
394- ) ;
395-
396- // 3.5 Get the Sugar execute swap params for the swap quote
397- console . log (
398- '[@lit-protocol/vincent-ability-aerodrome-swap execute] Getting Sugar execute swap params for swap quote' ,
399- ) ;
400- const sugarExecuteSwapParams = executeSwapParams ( {
401- config : sugarConfigBaseMainnet . sugarConfig ,
402- chainId,
403- commands : planner . commands as `0x${string } `,
404- inputs : planner . inputs ,
405- value : amount ,
374+ unsignedTransactionOnly : true ,
406375 } ) ;
407376
408- // 3.6 ABI encode the swap params for ethers calldata
409- console . log (
410- '[@lit-protocol/vincent-ability-aerodrome-swap execute] ABI encoding swap params for ethers calldata' ,
411- ) ;
412- const executeInterface = new ethers . utils . Interface ( sugarExecuteSwapParams . abi ) ;
413- const encodedCalldataForEthers = executeInterface . encodeFunctionData (
414- 'execute(bytes,bytes[])' ,
415- [ planner . commands , planner . inputs ] ,
416- ) ;
417-
418- // 3.7 Send the swap transaction
377+ // 3.4 Send the swap transaction
419378 console . log (
420379 '[@lit-protocol/vincent-ability-aerodrome-swap execute] Sending swap transaction' ,
421380 ) ;
422381 const txHash = await sendAerodromeSwapTx ( {
423382 rpcUrl,
424- chainId : base . id ,
383+ chainId : swapData . chainId ,
425384 pkpEthAddress : delegatorPkpInfo . ethAddress ,
426385 pkpPublicKey : delegatorPkpInfo . publicKey ,
427- to : sugarChainConfigBaseMainnet . UNIVERSAL_ROUTER_ADDRESS ,
428- value : amount . toString ( ) ,
429- calldata : encodedCalldataForEthers ,
386+ to : swapData . to ,
387+ value : swapData . value . toString ( ) ,
388+ calldata : swapData . data ,
430389 gasBufferPercentage,
431390 baseFeePerGasBufferPercentage,
432391 alchemyGasSponsor,
0 commit comments