@@ -149,6 +149,56 @@ describe("StashDexProcessor", function () {
149149 } ) ;
150150 } ) ;
151151
152+ describe ( "forwardAmount" , function ( ) {
153+ it ( "calls repay on StashDex after forwarding TARGET_ASSET" , async function ( ) {
154+ const { caller, usdc, pool, stashDex, stashDexProcessor} = await loadFixture ( deployAll ) ;
155+
156+ await usdc . mint ( stashDexProcessor , debtAmount ) ;
157+
158+ const tx = await stashDexProcessor . connect ( caller ) . forwardAmount ( usdc , debtAmount - 1n ) ;
159+ await expect ( tx ) . to . emit ( stashDexProcessor , "Forwarded" ) ;
160+ await expect ( tx ) . to . emit ( stashDex , "Repaid" ) . withArgs ( usdc . target , debtAmount - 1n ) ;
161+
162+ expect ( await stashDex . getTotalBorrowed ( usdc ) ) . to . equal ( 1n ) ;
163+ expect ( await usdc . balanceOf ( stashDexProcessor ) ) . to . equal ( 1n ) ;
164+ expect ( await usdc . balanceOf ( stashDex ) ) . to . equal ( 0n ) ;
165+ expect ( await usdc . balanceOf ( pool ) ) . to . equal ( debtAmount - 1n ) ;
166+ } ) ;
167+
168+ it ( "repays tokenA debt when forwarding tokenA" , async function ( ) {
169+ const { deployer, admin, configAdmin, caller, user, swapProcessor, usdc, tokenA, stashDex, stashDexProcessor} =
170+ await loadFixture ( deployAll ) ;
171+
172+ // Create tokenA debt: set up a pool for tokenA and a swap route usdc→tokenA
173+ const tokenADebt = 100_000000n ;
174+ const tokenAPool = (
175+ await deploy ( "TestLiquidityPool" , deployer , { } , tokenA , admin , ZERO_ADDRESS )
176+ ) as TestLiquidityPool ;
177+ await tokenA . mint ( tokenAPool , tokenADebt ) ;
178+ await stashDex . connect ( configAdmin ) . setPool ( tokenA , tokenAPool ) ;
179+ await stashDex . connect ( configAdmin ) . setRoute ( {
180+ tokenIn : usdc , tokenOut : tokenA , feeBps : 0 , processor : swapProcessor
181+ } ) ;
182+ await usdc . mint ( user , tokenADebt ) ;
183+ await usdc . connect ( user ) . approve ( stashDex , tokenADebt ) ;
184+ await stashDex . connect ( user ) . swap ( usdc , tokenA , tokenADebt , tokenADebt , user ) ;
185+
186+ const mintAmount = 60_000000n ;
187+ const forwardAmount = 55_000000n ;
188+ await tokenA . mint ( stashDexProcessor , mintAmount ) ;
189+
190+ const tx = await stashDexProcessor . connect ( caller ) . forwardAmount ( tokenA , forwardAmount ) ;
191+ await expect ( tx ) . to . emit ( stashDexProcessor , "Forwarded" ) ;
192+ await expect ( tx ) . to . emit ( stashDex , "Repaid" ) . withArgs ( tokenA . target , forwardAmount ) ;
193+
194+ expect ( await stashDex . getTotalBorrowed ( tokenA ) ) . to . equal ( tokenADebt - forwardAmount ) ;
195+ expect ( await tokenA . balanceOf ( stashDexProcessor ) ) . to . equal ( mintAmount - forwardAmount ) ;
196+ expect ( await tokenA . balanceOf ( stashDex ) ) . to . equal ( 0n ) ;
197+ expect ( await tokenA . balanceOf ( tokenAPool ) ) . to . equal ( forwardAmount ) ;
198+ expect ( await stashDex . getTotalBorrowed ( usdc ) ) . to . equal ( debtAmount ) ; // usdc debt unaffected
199+ } ) ;
200+ } ) ;
201+
152202 describe ( "process4626" , function ( ) {
153203 it ( "calls repay on StashDex after processing 4626 shares" , async function ( ) {
154204 const { deployer, caller, usdc, pool, stashDex, stashDexProcessor, test4626} = await loadFixture ( deployAll ) ;
0 commit comments