Skip to content

Commit 46041b0

Browse files
committed
chore: update token amounts to base unit
1 parent 3764a9f commit 46041b0

File tree

5 files changed

+45
-77
lines changed

5 files changed

+45
-77
lines changed

packages/apps/abilities-e2e/test-e2e/swap-aerodrome.spec.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,14 @@ const ALCHEMY_GAS_SPONSOR_API_KEY = getEnv('ALCHEMY_GAS_SPONSOR_API_KEY');
4545
const ALCHEMY_GAS_SPONSOR_POLICY_ID = getEnv('ALCHEMY_GAS_SPONSOR_POLICY_ID');
4646
const EXPECTED_AERODROME_UNIVERSAL_ROUTER_ADDRESS = '0x01D40099fCD87C018969B0e8D4aB1633Fb34763C';
4747

48-
// const SWAP_AMOUNT = 0.0003;
48+
// const SWAP_AMOUNT = '300000000000000'; // 0.0003 WETH (18 decimals)
4949
// const SWAP_TOKEN_IN_ADDRESS = '0x4200000000000000000000000000000000000006'; // WETH
5050
// const SWAP_TOKEN_IN_DECIMALS = 18;
5151

52-
const SWAP_AMOUNT = 0.1;
52+
const SWAP_AMOUNT = '10000'; // 0.01 USDC (6 decimals)
5353
const SWAP_TOKEN_IN_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; // USDC
5454
const SWAP_TOKEN_IN_DECIMALS = 6;
5555

56-
const EXPECTED_SWAP_AMOUNT = ethers.utils.formatUnits(
57-
ethers.utils.parseUnits(SWAP_AMOUNT.toString(), SWAP_TOKEN_IN_DECIMALS),
58-
SWAP_TOKEN_IN_DECIMALS,
59-
);
60-
6156
// const SWAP_TOKEN_OUT_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; // USDC
6257
// const SWAP_TOKEN_OUT_DECIMALS = 6;
6358
const SWAP_TOKEN_OUT_ADDRESS = '0x4200000000000000000000000000000000000006'; // WETH
@@ -268,8 +263,8 @@ describe('Aerodrome Swap Ability E2E Tests', () => {
268263
);
269264
expect(innerResult.spenderAddress).toBe(EXPECTED_AERODROME_UNIVERSAL_ROUTER_ADDRESS);
270265
expect(innerResult.tokenAddress).toBe(SWAP_TOKEN_IN_ADDRESS.toLowerCase());
271-
expect(innerResult.requiredAllowance).toBe(EXPECTED_SWAP_AMOUNT);
272-
expect(innerResult.currentAllowance).toBe('0.0');
266+
expect(innerResult.requiredAllowance).toBe(SWAP_AMOUNT.toString());
267+
expect(innerResult.currentAllowance).toBe('0');
273268
});
274269

275270
it('should make a new ERC20 approval transaction for the Aerodrome Universal Router', async () => {
@@ -340,8 +335,8 @@ describe('Aerodrome Swap Ability E2E Tests', () => {
340335

341336
expect(executeResult.result).toBeDefined();
342337
expect(executeResult.result.approvalTxHash).toBeUndefined();
343-
expect(executeResult.result.currentAllowance!).toBe(EXPECTED_SWAP_AMOUNT);
344-
expect(executeResult.result.requiredAllowance!).toBe(EXPECTED_SWAP_AMOUNT);
338+
expect(executeResult.result.currentAllowance!).toBe(SWAP_AMOUNT.toString());
339+
expect(executeResult.result.requiredAllowance!).toBe(SWAP_AMOUNT.toString());
345340
});
346341

347342
it('should successfully run precheck on the Aerodrome Swap Ability', async () => {
@@ -469,8 +464,8 @@ describe('Aerodrome Swap Ability E2E Tests', () => {
469464
);
470465
expect(innerResult.spenderAddress).toBe(EXPECTED_AERODROME_UNIVERSAL_ROUTER_ADDRESS);
471466
expect(innerResult.tokenAddress).toBe(SWAP_TOKEN_IN_ADDRESS.toLowerCase());
472-
expect(innerResult.requiredAllowance).toBe(EXPECTED_SWAP_AMOUNT);
473-
expect(innerResult.currentAllowance).toBe('0.0');
467+
expect(innerResult.requiredAllowance).toBe(SWAP_AMOUNT.toString());
468+
expect(innerResult.currentAllowance).toBe('0');
474469
});
475470

476471
it('should make a new ERC20 approval transaction for the Aerodrome Universal Router', async () => {
@@ -554,8 +549,8 @@ describe('Aerodrome Swap Ability E2E Tests', () => {
554549

555550
expect(executeResult.result).toBeDefined();
556551
expect(executeResult.result.approvalTxHash).toBeUndefined();
557-
expect(executeResult.result.currentAllowance!).toBe(EXPECTED_SWAP_AMOUNT);
558-
expect(executeResult.result.requiredAllowance!).toBe(EXPECTED_SWAP_AMOUNT);
552+
expect(executeResult.result.currentAllowance!).toBe(SWAP_AMOUNT.toString());
553+
expect(executeResult.result.requiredAllowance!).toBe(SWAP_AMOUNT.toString());
559554
});
560555

561556
it('should successfully run precheck on the Aerodrome Swap Ability', async () => {
@@ -609,12 +604,12 @@ describe('Aerodrome Swap Ability E2E Tests', () => {
609604
.toBigInt(),
610605
).toBeGreaterThan(0n);
611606
expect(precheckResult.result!.currentTokenInAllowanceForSpender as string).toBe(
612-
EXPECTED_SWAP_AMOUNT,
607+
SWAP_AMOUNT.toString(),
613608
);
614609
expect(precheckResult.result!.spenderAddress).toBe(
615610
EXPECTED_AERODROME_UNIVERSAL_ROUTER_ADDRESS,
616611
);
617-
expect(precheckResult.result!.requiredTokenInAllowance!).toBe(EXPECTED_SWAP_AMOUNT);
612+
expect(precheckResult.result!.requiredTokenInAllowance!).toBe(SWAP_AMOUNT.toString());
618613
});
619614

620615
it('should execute the Aerodrome Swap Ability with the Agent Wallet PKP', async () => {

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": "QmQJVEXsBhZgXYKWPsYkrqQu7nb6VsDG4Uns7Hv64ipUPL"
2+
"ipfsCid": "QmW6KRZajykBJUeQ22kbqs45Wh9nFEoy5omZDfeaYu8qiU"
33
}

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const abilityParamsSchema = z.object({
1616
amountIn: z
1717
.string()
1818
.describe(
19-
'The amount to swap in decimal string (Example: 2.123456 for 2.123456 USDC (6 decimals), or .000001 for 0.000001 WETH (18 decimals))',
19+
'The amount to swap in the smallest unit (Example: 2123456 for 2.123456 USDC (6 decimals), or 10000000000000000 for 0.01 WETH (18 decimals))',
2020
),
2121
slippage: z
2222
.number()
@@ -52,7 +52,7 @@ export const precheckSuccessSchema = z.object({
5252
nativeTokenBalance: z
5353
.string()
5454
.describe(
55-
"The balance of the Vincent delegator's native token used for gas fees if alchemyGasSponsor is not enabled",
55+
"The balance of the Vincent delegator's native token in the smallest unit used for gas fees if alchemyGasSponsor is not enabled",
5656
)
5757
.optional(),
5858
tokenInAddress: z
@@ -61,18 +61,22 @@ export const precheckSuccessSchema = z.object({
6161
.optional(),
6262
tokenInBalance: z
6363
.string()
64-
.describe("The balance of the Vincent delegator's input token used for the swap")
64+
.describe(
65+
"The balance of the Vincent delegator's input token in the smallest unit used for the swap",
66+
)
6567
.optional(),
6668
currentTokenInAllowanceForSpender: z
6769
.string()
68-
.describe("The current allowance of the Vincent delegator's input token used for the swap"),
70+
.describe(
71+
"The current allowance of the Vincent delegator's input token in the smallest unit used for the swap",
72+
),
6973
spenderAddress: z
7074
.string()
7175
.describe('The Aerodrome Universal Router address that will be used for the swap'),
7276
requiredTokenInAllowance: z
7377
.string()
7478
.describe(
75-
"The required allowance of the Vincent delegator's input token for the swap for the ERC20 spender (Aerodrome Universal Router address)",
79+
"The required allowance of the Vincent delegator's input token in the smallest unit for the swap for the ERC20 spender (Aerodrome Universal Router address)",
7680
)
7781
.optional(),
7882
quote: z
@@ -93,22 +97,24 @@ export const precheckFailSchema = z.object({
9397
tokenAddress: z.string().describe('The address of the input token for the swap').optional(),
9498
requiredTokenAmount: z
9599
.string()
96-
.describe('The required amount of the input token for the swap')
100+
.describe('The required amount of the input token in the smallest unit for the swap')
97101
.optional(),
98102
tokenBalance: z
99103
.string()
100-
.describe("The balance of the Vincent delegator's input token used for the swap")
104+
.describe(
105+
"The balance of the Vincent delegator's input token in the smallest unit used for the swap",
106+
)
101107
.optional(),
102108
currentAllowance: z
103109
.string()
104110
.describe(
105-
"The current allowance of the Vincent delegator's input token used for the swap for the ERC20 spender (Aerodrome Universal Router address)",
111+
"The current allowance of the Vincent delegator's input token in the smallest unit used for the swap for the ERC20 spender (Aerodrome Universal Router address)",
106112
)
107113
.optional(),
108114
requiredAllowance: z
109115
.string()
110116
.describe(
111-
"The required allowance of the Vincent delegator's input token used for the swap for the ERC20 spender (Aerodrome Universal Router address)",
117+
"The required allowance of the Vincent delegator's input token in the smallest unit used for the swap for the ERC20 spender (Aerodrome Universal Router address)",
112118
)
113119
.optional(),
114120
});
@@ -136,13 +142,13 @@ export const executeSuccessSchema = z.object({
136142
currentAllowance: z
137143
.string()
138144
.describe(
139-
"The current allowance of the Vincent delegator's input token used for the swap for the ERC20 spender (Aerodrome Universal Router address)",
145+
"The current allowance of the Vincent delegator's input token in the smallest unit used for the swap for the ERC20 spender (Aerodrome Universal Router address)",
140146
)
141147
.optional(),
142148
requiredAllowance: z
143149
.string()
144150
.describe(
145-
"The required allowance of the Vincent delegator's input token used for the swap for the ERC20 spender (Aerodrome Universal Router address)",
151+
"The required allowance of the Vincent delegator's input token in the smallest unit used for the swap for the ERC20 spender (Aerodrome Universal Router address)",
146152
)
147153
.optional(),
148154
});

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

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const vincentAbility = createVincentAbility({
7777
});
7878
}
7979

80-
const requiredTokenInAmount = ethers.utils.parseUnits(amountIn, sugarTokenIn.decimals);
80+
const requiredTokenInAmount = ethers.BigNumber.from(amountIn);
8181

8282
// 3. We retrieve the current allowance of the input token for the spender from the delegator
8383
const checkErc20AllowanceResult = await checkErc20Allowance({
@@ -96,14 +96,8 @@ export const vincentAbility = createVincentAbility({
9696
if (action === AbilityAction.Approve) {
9797
return succeed({
9898
nativeTokenBalance: checkNativeTokenBalanceResultSuccess?.ethBalance.toString(),
99-
currentTokenInAllowanceForSpender: ethers.utils.formatUnits(
100-
checkErc20AllowanceResult.currentAllowance,
101-
sugarTokenIn.decimals,
102-
),
103-
requiredTokenInAllowance: ethers.utils.formatUnits(
104-
checkErc20AllowanceResult.requiredAllowance,
105-
sugarTokenIn.decimals,
106-
),
99+
currentTokenInAllowanceForSpender: checkErc20AllowanceResult.currentAllowance.toString(),
100+
requiredTokenInAllowance: checkErc20AllowanceResult.requiredAllowance.toString(),
107101
spenderAddress: sugarChainConfigBaseMainnet.UNIVERSAL_ROUTER_ADDRESS,
108102
});
109103
}
@@ -115,14 +109,8 @@ export const vincentAbility = createVincentAbility({
115109
reason: checkErc20AllowanceResult.reason,
116110
spenderAddress: checkErc20AllowanceResult.spenderAddress,
117111
tokenAddress: checkErc20AllowanceResult.tokenAddress,
118-
requiredAllowance: ethers.utils.formatUnits(
119-
checkErc20AllowanceResult.requiredAllowance,
120-
sugarTokenIn.decimals,
121-
),
122-
currentAllowance: ethers.utils.formatUnits(
123-
checkErc20AllowanceResult.currentAllowance,
124-
sugarTokenIn.decimals,
125-
),
112+
requiredAllowance: checkErc20AllowanceResult.requiredAllowance.toString(),
113+
currentAllowance: checkErc20AllowanceResult.currentAllowance.toString(),
126114
});
127115
}
128116

@@ -138,14 +126,8 @@ export const vincentAbility = createVincentAbility({
138126
return fail({
139127
reason: checkErc20BalanceResult.reason,
140128
tokenAddress: checkErc20BalanceResult.tokenAddress,
141-
requiredTokenAmount: ethers.utils.formatUnits(
142-
checkErc20BalanceResult.requiredTokenAmount,
143-
sugarTokenIn.decimals,
144-
),
145-
tokenBalance: ethers.utils.formatUnits(
146-
checkErc20BalanceResult.tokenBalance,
147-
sugarTokenIn.decimals,
148-
),
129+
requiredTokenAmount: checkErc20BalanceResult.requiredTokenAmount.toString(),
130+
tokenBalance: checkErc20BalanceResult.tokenBalance.toString(),
149131
});
150132
}
151133

@@ -184,18 +166,9 @@ export const vincentAbility = createVincentAbility({
184166
return succeed({
185167
nativeTokenBalance: checkNativeTokenBalanceResultSuccess?.ethBalance.toString(),
186168
tokenInAddress: sugarTokenIn.address,
187-
tokenInBalance: ethers.utils.formatUnits(
188-
checkErc20BalanceResult.tokenBalance,
189-
sugarTokenIn.decimals,
190-
),
191-
currentTokenInAllowanceForSpender: ethers.utils.formatUnits(
192-
checkErc20AllowanceResult.currentAllowance,
193-
sugarTokenIn.decimals,
194-
),
195-
requiredTokenInAllowance: ethers.utils.formatUnits(
196-
checkErc20AllowanceResult.requiredAllowance,
197-
sugarTokenIn.decimals,
198-
),
169+
tokenInBalance: checkErc20BalanceResult.tokenBalance.toString(),
170+
currentTokenInAllowanceForSpender: checkErc20AllowanceResult.currentAllowance.toString(),
171+
requiredTokenInAllowance: checkErc20AllowanceResult.requiredAllowance.toString(),
199172
spenderAddress: sugarChainConfigBaseMainnet.UNIVERSAL_ROUTER_ADDRESS,
200173
quote: {
201174
tokenInAmount: ethers.utils.formatUnits(quote.amount, sugarTokenIn.decimals),
@@ -242,7 +215,7 @@ export const vincentAbility = createVincentAbility({
242215
});
243216
}
244217

245-
const requiredTokenInAmount = ethers.utils.parseUnits(amountIn, sugarTokenIn.decimals);
218+
const requiredTokenInAmount = ethers.BigNumber.from(amountIn);
246219

247220
// 2. If the ability action is approve, we return success if allowance is sufficient, otherwise we send a new approval transaction
248221
let approvalTxHash: string | undefined;
@@ -273,14 +246,8 @@ export const vincentAbility = createVincentAbility({
273246
'[@lit-protocol/vincent-ability-aerodrome-swap execute] Allowance is sufficient, returning success',
274247
);
275248
return succeed({
276-
currentAllowance: ethers.utils.formatUnits(
277-
checkErc20AllowanceResult.currentAllowance,
278-
sugarTokenIn.decimals,
279-
),
280-
requiredAllowance: ethers.utils.formatUnits(
281-
checkErc20AllowanceResult.requiredAllowance,
282-
sugarTokenIn.decimals,
283-
),
249+
currentAllowance: checkErc20AllowanceResult.currentAllowance.toString(),
250+
requiredAllowance: checkErc20AllowanceResult.requiredAllowance.toString(),
284251
});
285252
} else {
286253
if (checkErc20AllowanceResult.reason.includes('insufficient ERC20 allowance for spender')) {

0 commit comments

Comments
 (0)