@@ -484,24 +484,25 @@ describe("StashDex", function () {
484484 it ( "reverts InvalidIndex when indexIn has bits above position 159" , async function ( ) {
485485 const { stashDex, user, tokenB, USDC } = await loadFixture ( deployAll ) ;
486486 const badIndex = ( 1n << 160n ) | BigInt ( await tokenB . getAddress ( ) ) ;
487- await expect (
488- stashDex . connect ( user ) . exchange ( badIndex , BigInt ( await tokenB . getAddress ( ) ) , 1n * USDC , 1n * USDC , user )
489- ) . to . be . revertedWithCustomError ( stashDex , "InvalidIndex" ) ;
487+ await expect ( stashDex . connect ( user ) [ "exchange(uint256,uint256,uint256,uint256,address)" ] (
488+ badIndex , BigInt ( await tokenB . getAddress ( ) ) , 1n * USDC , 1n * USDC , user
489+ ) ) . to . be . revertedWithCustomError ( stashDex , "InvalidIndex" ) ;
490490 } ) ;
491491
492492 it ( "reverts InvalidIndex when indexOut has bits above position 159" , async function ( ) {
493493 const { stashDex, user, tokenA, USDC } = await loadFixture ( deployAll ) ;
494494 const badIndex = ( 1n << 160n ) | BigInt ( await tokenA . getAddress ( ) ) ;
495- await expect (
496- stashDex . connect ( user ) . exchange ( BigInt ( await tokenA . getAddress ( ) ) , badIndex , 1n * USDC , 1n * USDC , user )
497- ) . to . be . revertedWithCustomError ( stashDex , "InvalidIndex" ) ;
495+ await expect ( stashDex . connect ( user ) [ "exchange(uint256,uint256,uint256,uint256,address)" ] (
496+ BigInt ( await tokenA . getAddress ( ) ) , badIndex , 1n * USDC , 1n * USDC , user
497+ ) ) . to . be . revertedWithCustomError ( stashDex , "InvalidIndex" ) ;
498498 } ) ;
499499
500500 it ( "accepts type(uint160).max as a valid index for both in and out" , async function ( ) {
501501 const { stashDex, user} = await loadFixture ( deployAll ) ;
502502 const maxAddr = 2n ** 160n - 1n ;
503- await expect ( stashDex . connect ( user ) . exchange ( maxAddr , maxAddr , 1n , 1n , user ) )
504- . to . be . revertedWithCustomError ( stashDex , "RouteNotAllowed" ) ;
503+ await expect ( stashDex . connect ( user ) [ "exchange(uint256,uint256,uint256,uint256,address)" ] (
504+ maxAddr , maxAddr , 1n , 1n , user
505+ ) ) . to . be . revertedWithCustomError ( stashDex , "RouteNotAllowed" ) ;
505506 } ) ;
506507
507508 it ( "delegates to swap and transfers tokens correctly" , async function ( ) {
@@ -512,7 +513,7 @@ describe("StashDex", function () {
512513 await tokenA . connect ( user ) . approve ( stashDex , 10_000n * USDC ) ;
513514 await tokenB . mint ( pool , 9_997n * USDC ) ;
514515
515- const tx = await stashDex . connect ( user ) . exchange (
516+ const tx = await stashDex . connect ( user ) [ " exchange(uint256,uint256,uint256,uint256,address)" ] (
516517 BigInt ( await tokenA . getAddress ( ) ) , BigInt ( await tokenB . getAddress ( ) ) , 10_000n * USDC , 9_997n * USDC , user2
517518 ) ;
518519 await expect ( tx ) . to . emit ( stashDex , "Swapped" )
@@ -521,6 +522,24 @@ describe("StashDex", function () {
521522 expect ( await tokenA . balanceOf ( processor ) ) . to . equal ( 10_000n * USDC ) ;
522523 expect ( await tokenB . balanceOf ( user2 ) ) . to . equal ( 9_997n * USDC ) ;
523524 } ) ;
525+
526+ it ( "delegates without recipient to swap and transfers tokens correctly" , async function ( ) {
527+ const { stashDex, configAdmin, user, tokenA, tokenB, pool, processor, USDC } = await loadFixture ( deployAll ) ;
528+ await stashDex . connect ( configAdmin ) . setPool ( tokenB , pool ) ;
529+ await stashDex . connect ( configAdmin ) . setRoute ( { tokenIn : tokenA , tokenOut : tokenB , feeBps : 3 , processor} ) ;
530+ await tokenA . mint ( user , 10_000n * USDC ) ;
531+ await tokenA . connect ( user ) . approve ( stashDex , 10_000n * USDC ) ;
532+ await tokenB . mint ( pool , 9_997n * USDC ) ;
533+
534+ const tx = await stashDex . connect ( user ) [ "exchange(uint256,uint256,uint256,uint256)" ] (
535+ BigInt ( await tokenA . getAddress ( ) ) , BigInt ( await tokenB . getAddress ( ) ) , 10_000n * USDC , 9_997n * USDC
536+ ) ;
537+ await expect ( tx ) . to . emit ( stashDex , "Swapped" )
538+ . withArgs ( tokenA . target , tokenB . target , 10_000n * USDC , 9_997n * USDC , user . address ) ;
539+
540+ expect ( await tokenA . balanceOf ( processor ) ) . to . equal ( 10_000n * USDC ) ;
541+ expect ( await tokenB . balanceOf ( user ) ) . to . equal ( 9_997n * USDC ) ;
542+ } ) ;
524543 } ) ;
525544
526545 describe ( "repay" , function ( ) {
@@ -751,7 +770,7 @@ describe("StashDex", function () {
751770 await tokenA . mint ( user , 10_000n * USDC ) ;
752771 await tokenA . connect ( user ) . approve ( stashDex , 10_000n * USDC ) ;
753772 await tokenB . mint ( pool , 9_997n * USDC ) ;
754- await stashDex . connect ( user ) . exchange (
773+ await stashDex . connect ( user ) [ " exchange(uint256,uint256,uint256,uint256,address)" ] (
755774 BigInt ( await tokenA . getAddress ( ) ) , BigInt ( await tokenB . getAddress ( ) ) ,
756775 10_000n * USDC , 9_997n * USDC , user
757776 ) ;
0 commit comments