Skip to content

Commit aa47094

Browse files
Merge pull request #375 from LIT-Protocol/chore/repalce-vendor-sugar-install
Replace `sugar-sdk` vendor install, refactor use of SDK
2 parents 5ce3cac + 8db4f92 commit aa47094

File tree

10 files changed

+32
-67
lines changed

10 files changed

+32
-67
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
ability-aerodrome-swap: minor
3+
---
4+
5+
Refactor internal use of the SDK to simplify the Aerodrome Swap Ability

packages/apps/ability-aerodrome-swap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
},
77
"dependencies": {
88
"@lit-protocol/vincent-ability-sdk": "workspace:*",
9+
"sugar-sdk": "file:vendor/sugar-sdk-0.3.0-alpha.1.tgz",
910
"ethers": "^5.8.0",
10-
"sugar-sdk": "file:vendor/sugar-sdk-0.3.0.tgz",
1111
"tslib": "2.8.1",
1212
"zod": "^3.25.64"
1313
},

packages/apps/ability-aerodrome-swap/src/generated/lit-action.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"ipfsCid": "QmQpvixAaeDCw1Fkgaqf5EidTMm1PzgKwJjpjFXPmJVaxV"
2+
"ipfsCid": "QmQ92K8M45AqsgyfaKNrcrJiQgQLaCu2ip9mHehnbJfkRg"
33
}

packages/apps/ability-aerodrome-swap/src/lib/vincent-ability.ts

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
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';
66
import { ethers } from 'ethers';
77

88
import {
@@ -15,7 +15,7 @@ import {
1515
} from './schemas';
1616
import { AbilityAction, CheckNativeTokenBalanceResultSuccess } from './types';
1717
import { 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';
1919
import { findSupportedTokenOnBase } from './ability-helpers/find-supported-token-on-base';
2020
import { 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,
Binary file not shown.
-83.3 KB
Binary file not shown.

packages/libs/contracts-sdk/contracts/facets/VincentUserFacet.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ contract VincentUserFacet is VincentBase {
342342

343343
mapping(bytes32 => bytes) storage abilityPolicyParameterValues = us_.agentPkpTokenIdToAgentStorage[
344344
pkpTokenId
345-
].abilityPolicyParameterValues[appId][appVersion][hashedAbilityIpfsCid];
345+
]
346+
.abilityPolicyParameterValues[appId][appVersion][hashedAbilityIpfsCid];
346347

347348
// Step 4: Iterate through each policy associated with the ability.
348349
for (uint256 j = 0; j < policyCount; j++) {

packages/libs/contracts-sdk/script/DeployFeeDiamond.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ contract DeployFeeDiamond is Script {
9090
cuts[6] = contractToFacetCutAdd("AerodromeSwapFeeFacet", address(aerodromeSwapFeeFacet));
9191

9292
// Deploy the Diamond with the diamondCut facet and all other facets in one transaction
93-
Fee diamond = new Fee{
94-
salt: create2Salt
95-
}(cuts, FeeArgs({owner: deployerAddress, init: address(0), initCalldata: bytes("")}));
93+
Fee diamond = new Fee{salt: create2Salt}(
94+
cuts, FeeArgs({owner: deployerAddress, init: address(0), initCalldata: bytes("")})
95+
);
9696

9797
// Stop broadcasting transactions
9898
vm.stopBroadcast();

pnpm-lock.yaml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)