@@ -46,24 +46,29 @@ import {
4646const ALCHEMY_GAS_SPONSOR_API_KEY = getEnv ( 'ALCHEMY_GAS_SPONSOR_API_KEY' ) ;
4747const ALCHEMY_GAS_SPONSOR_POLICY_ID = getEnv ( 'ALCHEMY_GAS_SPONSOR_POLICY_ID' ) ;
4848
49- // const SWAP_AMOUNT = 80;
50- // const SWAP_TOKEN_IN_ADDRESS = '0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed'; // DEGEN
51- // const SWAP_TOKEN_IN_DECIMALS = 18;
49+ const SWAP_AMOUNT = 80 ;
50+ const SWAP_TOKEN_IN_ADDRESS = '0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed' ; // DEGEN
51+ const SWAP_TOKEN_IN_DECIMALS = 18 ;
5252
5353// const SWAP_AMOUNT = 0.0003;
5454// const SWAP_TOKEN_IN_ADDRESS = '0x4200000000000000000000000000000000000006'; // WETH
5555// const SWAP_TOKEN_IN_DECIMALS = 18;
5656
57- const SWAP_AMOUNT = 0.1 ;
58- const SWAP_TOKEN_IN_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' ; // USDC
59- const SWAP_TOKEN_IN_DECIMALS = 6 ;
57+ // const SWAP_AMOUNT = 0.1;
58+ // const SWAP_TOKEN_IN_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; // USDC
59+ // const SWAP_TOKEN_IN_DECIMALS = 6;
60+
61+ const EXPECTED_SWAP_AMOUNT = ethers . utils . formatUnits (
62+ ethers . utils . parseUnits ( SWAP_AMOUNT . toString ( ) , SWAP_TOKEN_IN_DECIMALS ) ,
63+ SWAP_TOKEN_IN_DECIMALS ,
64+ ) ;
6065
61- // const SWAP_TOKEN_OUT_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; // USDC
62- // const SWAP_TOKEN_OUT_DECIMALS = 6;
66+ const SWAP_TOKEN_OUT_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' ; // USDC
67+ const SWAP_TOKEN_OUT_DECIMALS = 6 ;
6368// const SWAP_TOKEN_OUT_ADDRESS = '0x4200000000000000000000000000000000000006'; // WETH
6469// const SWAP_TOKEN_OUT_DECIMALS = 18;
65- const SWAP_TOKEN_OUT_ADDRESS = '0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed' ; // DEGEN
66- const SWAP_TOKEN_OUT_DECIMALS = 18 ;
70+ // const SWAP_TOKEN_OUT_ADDRESS = '0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed'; // DEGEN
71+ // const SWAP_TOKEN_OUT_DECIMALS = 18;
6772
6873const RPC_URL = BASE_RPC_URL ;
6974const CHAIN_ID = 8453 ;
@@ -429,10 +434,8 @@ describe('Uniswap Swap Ability E2E Tests', () => {
429434 ) ;
430435 expect ( innerResult . spenderAddress ) . toBe ( signedUniswapQuote . quote . to ) ;
431436 expect ( innerResult . tokenAddress ) . toBe ( SWAP_TOKEN_IN_ADDRESS ) ;
432- expect ( innerResult . requiredAllowance ) . toBe (
433- ethers . utils . parseUnits ( SWAP_AMOUNT . toString ( ) , SWAP_TOKEN_IN_DECIMALS ) . toString ( ) ,
434- ) ;
435- expect ( innerResult . currentAllowance ) . toBe ( '0' ) ;
437+ expect ( innerResult . requiredAllowance ) . toBe ( EXPECTED_SWAP_AMOUNT ) ;
438+ expect ( innerResult . currentAllowance ) . toBe ( '0.0' ) ;
436439 } ) ;
437440
438441 it ( 'should fail execute because of invalid ability action' , async ( ) => {
@@ -531,10 +534,8 @@ describe('Uniswap Swap Ability E2E Tests', () => {
531534
532535 expect ( executeResult . result ) . toBeDefined ( ) ;
533536 expect ( executeResult . result . approvalTxHash ) . toBeUndefined ( ) ;
534- expect ( executeResult . result . currentAllowance ) . toBeDefined ( ) ;
535- expect ( BigInt ( executeResult . result . currentAllowance ! ) ) . toBeGreaterThanOrEqual (
536- BigInt ( ethers . utils . parseUnits ( SWAP_AMOUNT . toString ( ) , SWAP_TOKEN_IN_DECIMALS ) . toString ( ) ) ,
537- ) ;
537+ expect ( executeResult . result . currentAllowance ! ) . toBe ( EXPECTED_SWAP_AMOUNT ) ;
538+ expect ( executeResult . result . requiredAllowance ! ) . toBe ( EXPECTED_SWAP_AMOUNT ) ;
538539 } ) ;
539540
540541 it ( 'should successfully run precheck on the Uniswap Swap Ability' , async ( ) => {
@@ -581,12 +582,23 @@ describe('Uniswap Swap Ability E2E Tests', () => {
581582 // Verify the result is properly populated
582583 expect ( precheckResult . result ) . toBeDefined ( ) ;
583584 expect ( precheckResult . result ! . nativeTokenBalance ) . toBeDefined ( ) ;
584- expect ( BigInt ( precheckResult . result ! . nativeTokenBalance as string ) ) . toBeGreaterThan ( 0n ) ;
585+ expect (
586+ ethers . utils . parseEther ( precheckResult . result ! . nativeTokenBalance as string ) . toBigInt ( ) ,
587+ ) . toBeGreaterThan ( 0n ) ;
588+
585589 expect ( precheckResult . result ! . tokenInAddress ) . toBe ( SWAP_TOKEN_IN_ADDRESS ) ;
586590 expect ( precheckResult . result ! . tokenInBalance ) . toBeDefined ( ) ;
587- expect ( BigInt ( precheckResult . result ! . tokenInBalance as string ) ) . toBeGreaterThan ( 0n ) ;
588- expect ( BigInt ( precheckResult . result ! . currentTokenInAllowanceForSpender ) ) . toBeGreaterThan ( 0n ) ;
591+ expect (
592+ ethers . utils
593+ . parseUnits ( precheckResult . result ! . tokenInBalance as string , SWAP_TOKEN_IN_DECIMALS )
594+ . toBigInt ( ) ,
595+ ) . toBeGreaterThan ( 0n ) ;
596+
597+ expect ( precheckResult . result ! . currentTokenInAllowanceForSpender as string ) . toBe (
598+ EXPECTED_SWAP_AMOUNT ,
599+ ) ;
589600 expect ( precheckResult . result ! . spenderAddress ) . toBe ( signedUniswapQuote . quote . to ) ;
601+ expect ( precheckResult . result ! . requiredTokenInAllowance ! ) . toBe ( EXPECTED_SWAP_AMOUNT ) ;
590602 } ) ;
591603
592604 it ( 'should execute the Uniswap Swap Ability with the Agent Wallet PKP' , async ( ) => {
@@ -684,10 +696,8 @@ describe('Uniswap Swap Ability E2E Tests', () => {
684696 ) ;
685697 expect ( innerResult . spenderAddress ) . toBe ( signedUniswapQuote . quote . to ) ;
686698 expect ( innerResult . tokenAddress ) . toBe ( SWAP_TOKEN_IN_ADDRESS ) ;
687- expect ( innerResult . requiredAllowance ) . toBe (
688- ethers . utils . parseUnits ( SWAP_AMOUNT . toString ( ) , SWAP_TOKEN_IN_DECIMALS ) . toString ( ) ,
689- ) ;
690- expect ( innerResult . currentAllowance ) . toBe ( '0' ) ;
699+ expect ( innerResult . requiredAllowance ) . toBe ( EXPECTED_SWAP_AMOUNT ) ;
700+ expect ( innerResult . currentAllowance ) . toBe ( '0.0' ) ;
691701 } ) ;
692702
693703 it ( 'should make a new ERC20 approval transaction for the Uniswap router' , async ( ) => {
@@ -769,10 +779,8 @@ describe('Uniswap Swap Ability E2E Tests', () => {
769779
770780 expect ( executeResult . result ) . toBeDefined ( ) ;
771781 expect ( executeResult . result . approvalTxHash ) . toBeUndefined ( ) ;
772- expect ( executeResult . result . currentAllowance ) . toBeDefined ( ) ;
773- expect ( BigInt ( executeResult . result . currentAllowance ! ) ) . toBeGreaterThanOrEqual (
774- BigInt ( ethers . utils . parseUnits ( SWAP_AMOUNT . toString ( ) , SWAP_TOKEN_IN_DECIMALS ) . toString ( ) ) ,
775- ) ;
782+ expect ( executeResult . result . currentAllowance ! ) . toBe ( EXPECTED_SWAP_AMOUNT ) ;
783+ expect ( executeResult . result . requiredAllowance ! ) . toBe ( EXPECTED_SWAP_AMOUNT ) ;
776784 } ) ;
777785
778786 it ( 'should successfully run precheck on the Uniswap Swap Ability' , async ( ) => {
@@ -822,10 +830,16 @@ describe('Uniswap Swap Ability E2E Tests', () => {
822830 expect ( precheckResult . result ) . toBeDefined ( ) ;
823831 expect ( precheckResult . result ! . nativeTokenBalance ) . toBeUndefined ( ) ;
824832 expect ( precheckResult . result ! . tokenInAddress ) . toBe ( SWAP_TOKEN_IN_ADDRESS ) ;
825- expect ( precheckResult . result ! . tokenInBalance ) . toBeDefined ( ) ;
826- expect ( BigInt ( precheckResult . result ! . tokenInBalance as string ) ) . toBeGreaterThan ( 0n ) ;
827- expect ( BigInt ( precheckResult . result ! . currentTokenInAllowanceForSpender ) ) . toBeGreaterThan ( 0n ) ;
833+ expect (
834+ ethers . utils
835+ . parseUnits ( precheckResult . result ! . tokenInBalance as string , SWAP_TOKEN_IN_DECIMALS )
836+ . toBigInt ( ) ,
837+ ) . toBeGreaterThan ( 0n ) ;
838+ expect ( precheckResult . result ! . currentTokenInAllowanceForSpender as string ) . toBe (
839+ EXPECTED_SWAP_AMOUNT ,
840+ ) ;
828841 expect ( precheckResult . result ! . spenderAddress ) . toBe ( signedUniswapQuote . quote . to ) ;
842+ expect ( precheckResult . result ! . requiredTokenInAllowance ! ) . toBe ( EXPECTED_SWAP_AMOUNT ) ;
829843 } ) ;
830844
831845 it ( 'should execute the Uniswap Swap Ability with the Agent Wallet PKP' , async ( ) => {
0 commit comments