diff --git a/contracts/BorrowController.sol b/contracts/BorrowController.sol index 4a51607..9293eb0 100644 --- a/contracts/BorrowController.sol +++ b/contracts/BorrowController.sol @@ -55,10 +55,9 @@ contract BorrowController is IBorrowController, Controller, IPositionLocker { } LoanPosition memory position = _loanPositionManager.getPosition(positionId); - uint256 maxPayInterest; - uint256 minEarnInterest; - (position.collateralAmount, position.debtAmount, position.expiredWith, maxPayInterest, minEarnInterest) = - abi.decode(data, (uint256, uint256, Epoch, uint256, uint256)); + int256 interestThreshold; + (position.collateralAmount, position.debtAmount, position.expiredWith, interestThreshold) = + abi.decode(data, (uint256, uint256, Epoch, int256)); (Coupon[] memory couponsToMint, Coupon[] memory couponsToBurn, int256 collateralDelta, int256 debtDelta) = _loanPositionManager.adjustPosition( @@ -73,9 +72,9 @@ contract BorrowController is IBorrowController, Controller, IPositionLocker { _wrapCoupons(couponsToMint); } - if (swapParams.inToken == position.collateralToken) { + if (swapParams.inSubstitute == position.collateralToken) { _swap(position.collateralToken, position.debtToken, swapParams.amount, swapParams.data); - } else if (swapParams.inToken == position.debtToken) { + } else if (swapParams.inSubstitute == position.debtToken) { _swap(position.debtToken, position.collateralToken, swapParams.amount, swapParams.data); } @@ -85,8 +84,7 @@ contract BorrowController is IBorrowController, Controller, IPositionLocker { couponsToMint, couponsToBurn, debtDelta < 0 ? uint256(-debtDelta) : 0, - maxPayInterest, - minEarnInterest + interestThreshold ); if (collateralDelta > 0) { @@ -110,15 +108,15 @@ contract BorrowController is IBorrowController, Controller, IPositionLocker { address collateralToken, address debtToken, uint256 collateralAmount, - uint256 borrowAmount, - uint256 maxPayInterest, + uint256 debtAmount, + int256 maxPayInterest, Epoch expiredWith, SwapParams calldata swapParams, ERC20PermitParams calldata collateralPermitParams ) external payable nonReentrant wrapETH { collateralPermitParams.tryPermit(_getUnderlyingToken(collateralToken), msg.sender, address(this)); - bytes memory lockData = abi.encode(collateralAmount, borrowAmount, expiredWith, maxPayInterest, 0); + bytes memory lockData = abi.encode(collateralAmount, debtAmount, expiredWith, maxPayInterest); lockData = abi.encode(0, msg.sender, swapParams, abi.encode(collateralToken, debtToken, lockData)); bytes memory result = _loanPositionManager.lock(lockData); uint256 positionId = abi.decode(result, (uint256)); @@ -131,9 +129,8 @@ contract BorrowController is IBorrowController, Controller, IPositionLocker { function adjustPosition( uint256 positionId, uint256 collateralAmount, - uint256 borrowAmount, - uint256 maxPayInterest, - uint256 minEarnInterest, + uint256 debtAmount, + int256 interestThreshold, Epoch expiredWith, SwapParams calldata swapParams, PermitSignature calldata positionPermitParams, @@ -146,10 +143,10 @@ contract BorrowController is IBorrowController, Controller, IPositionLocker { debtPermitParams.tryPermit(_getUnderlyingToken(position.debtToken), msg.sender, address(this)); position.collateralAmount = collateralAmount; - position.debtAmount = borrowAmount; + position.debtAmount = debtAmount; position.expiredWith = expiredWith; - _loanPositionManager.lock(_encodeAdjustData(positionId, position, maxPayInterest, minEarnInterest, swapParams)); + _loanPositionManager.lock(_encodeAdjustData(positionId, position, interestThreshold, swapParams)); _burnAllSubstitute(position.collateralToken, msg.sender); _burnAllSubstitute(position.debtToken, msg.sender); @@ -178,11 +175,10 @@ contract BorrowController is IBorrowController, Controller, IPositionLocker { function _encodeAdjustData( uint256 id, LoanPosition memory p, - uint256 maxPay, - uint256 minEarn, + int256 interestThreshold, SwapParams memory swapParams ) internal view returns (bytes memory) { - bytes memory data = abi.encode(p.collateralAmount, p.debtAmount, p.expiredWith, maxPay, minEarn); + bytes memory data = abi.encode(p.collateralAmount, p.debtAmount, p.expiredWith, interestThreshold); return abi.encode(id, msg.sender, swapParams, data); } } diff --git a/contracts/DepositController.sol b/contracts/DepositController.sol index 559adb3..52f0265 100644 --- a/contracts/DepositController.sol +++ b/contracts/DepositController.sol @@ -50,10 +50,8 @@ contract DepositController is IDepositController, Controller, IPositionLocker { } BondPosition memory position = _bondPositionManager.getPosition(positionId); - uint256 maxPayInterest; - uint256 minEarnInterest; - (position.amount, position.expiredWith, maxPayInterest, minEarnInterest) = - abi.decode(data, (uint256, Epoch, uint256, uint256)); + int256 interestThreshold; + (position.amount, position.expiredWith, interestThreshold) = abi.decode(data, (uint256, Epoch, int256)); (Coupon[] memory couponsToMint, Coupon[] memory couponsToBurn, int256 amountDelta) = _bondPositionManager.adjustPosition(positionId, position.amount, position.expiredWith); if (amountDelta < 0) _bondPositionManager.withdrawToken(position.asset, address(this), uint256(-amountDelta)); @@ -68,8 +66,7 @@ contract DepositController is IDepositController, Controller, IPositionLocker { couponsToMint, couponsToBurn, amountDelta > 0 ? uint256(amountDelta) : 0, - maxPayInterest, - minEarnInterest + interestThreshold ); if (amountDelta > 0) { @@ -88,11 +85,11 @@ contract DepositController is IDepositController, Controller, IPositionLocker { address asset, uint256 amount, uint16 lockEpochs, - uint256 minEarnInterest, + int256 minEarnInterest, ERC20PermitParams calldata tokenPermitParams ) external payable nonReentrant wrapETH { tokenPermitParams.tryPermit(_getUnderlyingToken(asset), msg.sender, address(this)); - bytes memory lockData = abi.encode(amount, EpochLibrary.current().add(lockEpochs - 1), 0, minEarnInterest); + bytes memory lockData = abi.encode(amount, EpochLibrary.current().add(lockEpochs - 1), -minEarnInterest); bytes memory result = _bondPositionManager.lock(abi.encode(0, msg.sender, abi.encode(asset, lockData))); uint256 id = abi.decode(result, (uint256)); @@ -104,13 +101,13 @@ contract DepositController is IDepositController, Controller, IPositionLocker { function withdraw( uint256 positionId, uint256 withdrawAmount, - uint256 maxPayInterest, + int256 maxPayInterest, PermitSignature calldata positionPermitParams ) external nonReentrant onlyPositionOwner(positionId) { positionPermitParams.tryPermit(_bondPositionManager, positionId, address(this)); BondPosition memory position = _bondPositionManager.getPosition(positionId); - bytes memory lockData = abi.encode(position.amount - withdrawAmount, position.expiredWith, maxPayInterest, 0); + bytes memory lockData = abi.encode(position.amount - withdrawAmount, position.expiredWith, maxPayInterest); _bondPositionManager.lock(abi.encode(positionId, msg.sender, lockData)); _burnAllSubstitute(position.asset, msg.sender); diff --git a/contracts/interfaces/IBorrowController.sol b/contracts/interfaces/IBorrowController.sol index ad95301..c9cc37a 100644 --- a/contracts/interfaces/IBorrowController.sol +++ b/contracts/interfaces/IBorrowController.sol @@ -8,7 +8,7 @@ import {Epoch} from "../libraries/Epoch.sol"; interface IBorrowController is IController { struct SwapParams { - address inToken; + address inSubstitute; uint256 amount; bytes data; } @@ -20,8 +20,8 @@ interface IBorrowController is IController { address collateralToken, address debtToken, uint256 collateralAmount, - uint256 borrowAmount, - uint256 maxPayInterest, + uint256 debtAmount, + int256 maxPayInterest, Epoch expiredWith, SwapParams calldata swapParams, ERC20PermitParams calldata collateralPermitParams @@ -30,9 +30,8 @@ interface IBorrowController is IController { function adjustPosition( uint256 positionId, uint256 collateralAmount, - uint256 borrowAmount, - uint256 maxPayInterest, - uint256 minEarnInterest, + uint256 debtAmount, + int256 interestThreshold, Epoch expiredWith, SwapParams calldata swapParams, PermitSignature calldata positionPermitParams, diff --git a/contracts/interfaces/IDepositController.sol b/contracts/interfaces/IDepositController.sol index 457f63c..71704ed 100644 --- a/contracts/interfaces/IDepositController.sol +++ b/contracts/interfaces/IDepositController.sol @@ -12,14 +12,14 @@ interface IDepositController is IController { address token, uint256 amount, uint16 lockEpochs, - uint256 minEarnInterest, + int256 minEarnInterest, ERC20PermitParams calldata tokenPermitParams ) external payable; function withdraw( uint256 positionId, uint256 withdrawAmount, - uint256 maxPayInterest, + int256 maxPayInterest, PermitSignature calldata positionPermitParams ) external; diff --git a/contracts/libraries/Controller.sol b/contracts/libraries/Controller.sol index cc14198..9808e0b 100644 --- a/contracts/libraries/Controller.sol +++ b/contracts/libraries/Controller.sol @@ -9,6 +9,7 @@ import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC2 import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol"; import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; +import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {CloberMarketSwapCallbackReceiver} from "../external/clober/CloberMarketSwapCallbackReceiver.sol"; import {CloberMarketFactory} from "../external/clober/CloberMarketFactory.sol"; @@ -33,6 +34,7 @@ abstract contract Controller is Ownable2Step, ReentrancyGuard { + using SafeCast for uint256; using SafeERC20 for IERC20; using CouponKeyLibrary for CouponKey; using CouponLibrary for Coupon; @@ -64,17 +66,15 @@ abstract contract Controller is Coupon[] memory couponsToMint, Coupon[] memory couponsToBurn, uint256 amountToPay, - uint256 maxPayInterest, - uint256 leftRequiredInterest + int256 remainingInterest ) internal { if (couponsToBurn.length > 0) { Coupon memory lastCoupon = couponsToBurn[couponsToBurn.length - 1]; assembly { mstore(couponsToBurn, sub(mload(couponsToBurn), 1)) } - bytes memory data = abi.encode( - user, lastCoupon, couponsToMint, couponsToBurn, amountToPay, maxPayInterest, leftRequiredInterest - ); + bytes memory data = + abi.encode(user, lastCoupon, couponsToMint, couponsToBurn, amountToPay, remainingInterest); assembly { mstore(couponsToBurn, add(mload(couponsToBurn), 1)) } @@ -87,9 +87,8 @@ abstract contract Controller is assembly { mstore(couponsToMint, sub(mload(couponsToMint), 1)) } - bytes memory data = abi.encode( - user, lastCoupon, couponsToMint, couponsToBurn, amountToPay, maxPayInterest, leftRequiredInterest - ); + bytes memory data = + abi.encode(user, lastCoupon, couponsToMint, couponsToBurn, amountToPay, remainingInterest); assembly { mstore(couponsToMint, add(mload(couponsToMint), 1)) } @@ -97,7 +96,7 @@ abstract contract Controller is CloberOrderBook market = CloberOrderBook(_couponMarkets[lastCoupon.id()]); market.marketOrder(address(this), 0, 0, lastCoupon.amount, 2, data); } else { - if (leftRequiredInterest > 0) revert ControllerSlippage(); + if (remainingInterest < 0) revert ControllerSlippage(); _ensureBalance(token, user, amountToPay); } } @@ -115,32 +114,22 @@ abstract contract Controller is address asset = CloberOrderBook(msg.sender).quoteToken(); address user; Coupon memory lastCoupon; - unchecked { - Coupon[] memory couponsToMint; - Coupon[] memory couponsToBurn; - uint256 amountToPay; - uint256 maxPayInterest; - uint256 leftRequiredInterest; - (user, lastCoupon, couponsToMint, couponsToBurn, amountToPay, maxPayInterest, leftRequiredInterest) = - abi.decode(data, (address, Coupon, Coupon[], Coupon[], uint256, uint256, uint256)); - - if (asset == inputToken) { - if (maxPayInterest < inputAmount) revert ControllerSlippage(); - maxPayInterest -= inputAmount; - amountToPay += inputAmount; - } else { - if (leftRequiredInterest > outputAmount) { - leftRequiredInterest -= outputAmount; - } else { - leftRequiredInterest = 0; - } - } - - _executeCouponTrade( - user, asset, couponsToMint, couponsToBurn, amountToPay, maxPayInterest, leftRequiredInterest - ); + Coupon[] memory couponsToMint; + Coupon[] memory couponsToBurn; + uint256 amountToPay; + int256 remainingInterest; + (user, lastCoupon, couponsToMint, couponsToBurn, amountToPay, remainingInterest) = + abi.decode(data, (address, Coupon, Coupon[], Coupon[], uint256, int256)); + + if (asset == inputToken) { + remainingInterest -= inputAmount.toInt256(); + amountToPay += inputAmount; + } else { + remainingInterest += outputAmount.toInt256(); } + _executeCouponTrade(user, asset, couponsToMint, couponsToBurn, amountToPay, remainingInterest); + // transfer input tokens if (inputAmount > 0) IERC20(inputToken).safeTransfer(msg.sender, inputAmount); uint256 couponBalance = IERC20(inputToken).balanceOf(address(this)); diff --git a/test/foundry/integration/BorrowController.t.sol b/test/foundry/integration/BorrowController.t.sol index 925c3e8..7d496b2 100644 --- a/test/foundry/integration/BorrowController.t.sol +++ b/test/foundry/integration/BorrowController.t.sol @@ -178,7 +178,7 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv address collateralToken, address borrowToken, uint256 collateralAmount, - uint256 borrowAmount, + uint256 debtAmount, uint16 loanEpochs ) internal returns (uint256 positionId) { positionId = loanPositionManager.nextId(); @@ -194,8 +194,8 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv collateralToken, borrowToken, collateralAmount, - borrowAmount, - type(uint256).max, + debtAmount, + type(int256).max, EpochLibrary.current().add(loanEpochs - 1), swapParams, permitParams @@ -204,23 +204,23 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv function testBorrow() public { uint256 collateralAmount = usdc.amount(10000); - uint256 borrowAmount = 1 ether; + uint256 debtAmount = 1 ether; uint256 beforeUSDCBalance = usdc.balanceOf(user); uint256 beforeETHBalance = user.balance; - uint256 positionId = _initialBorrow(user, wausdc, waweth, collateralAmount, borrowAmount, 2); + uint256 positionId = _initialBorrow(user, wausdc, waweth, collateralAmount, debtAmount, 2); LoanPosition memory loanPosition = loanPositionManager.getPosition(positionId); uint256 couponAmount = 0.08 ether; assertEq(loanPositionManager.ownerOf(positionId), user, "POSITION_OWNER"); assertEq(usdc.balanceOf(user), beforeUSDCBalance - collateralAmount, "USDC_BALANCE"); - assertGe(user.balance, beforeETHBalance + borrowAmount - couponAmount, "NATIVE_BALANCE_GE"); - assertLe(user.balance, beforeETHBalance + borrowAmount - couponAmount + 0.001 ether, "NATIVE_BALANCE_LE"); + assertGe(user.balance, beforeETHBalance + debtAmount - couponAmount, "NATIVE_BALANCE_GE"); + assertLe(user.balance, beforeETHBalance + debtAmount - couponAmount + 0.001 ether, "NATIVE_BALANCE_LE"); assertEq(loanPosition.expiredWith, EpochLibrary.current().add(1), "POSITION_EXPIRE_EPOCH"); assertEq(loanPosition.collateralAmount, collateralAmount, "POSITION_COLLATERAL_AMOUNT"); - assertEq(loanPosition.debtAmount, borrowAmount, "POSITION_DEBT_AMOUNT"); + assertEq(loanPosition.debtAmount, debtAmount, "POSITION_DEBT_AMOUNT"); assertEq(loanPosition.collateralToken, wausdc, "POSITION_COLLATERAL_TOKEN"); assertEq(loanPosition.debtToken, waweth, "POSITION_DEBT_TOKEN"); } @@ -239,8 +239,7 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv positionId, beforeLoanPosition.collateralAmount, beforeLoanPosition.debtAmount + 0.5 ether, - type(uint256).max, - 0, + type(int256).max, beforeLoanPosition.expiredWith, swapParams, permit721Params, @@ -280,7 +279,6 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv positionId, beforeLoanPosition.collateralAmount + collateralAmount, beforeLoanPosition.debtAmount, - type(uint256).max, 0, beforeLoanPosition.expiredWith, swapParams, @@ -319,7 +317,6 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv positionId, beforeLoanPosition.collateralAmount - collateralAmount, beforeLoanPosition.debtAmount, - type(uint256).max, 0, beforeLoanPosition.expiredWith, swapParams, @@ -360,8 +357,7 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv positionId, beforeLoanPosition.collateralAmount, beforeLoanPosition.debtAmount, - maxPayInterest, - 0, + int256(maxPayInterest), beforeLoanPosition.expiredWith.add(epochs), swapParams, permit721Params, @@ -398,7 +394,6 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv positionId, beforeLoanPosition.collateralAmount, beforeLoanPosition.debtAmount, - type(uint256).max, 0, beforeLoanPosition.expiredWith.sub(epochs), swapParams, @@ -437,7 +432,6 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv positionId, beforeLoanPosition.collateralAmount, beforeLoanPosition.debtAmount - repayAmount, - type(uint256).max, 0, beforeLoanPosition.expiredWith, swapParams, @@ -476,7 +470,6 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv positionId, beforeLoanPosition.collateralAmount, beforeLoanPosition.debtAmount - repayAmount, - type(uint256).max, 0, beforeLoanPosition.expiredWith, swapParams, @@ -491,7 +484,7 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv function testLeverage() public { uint256 collateralAmount = 0.4 ether; - uint256 borrowAmount = usdc.amount(550); + uint256 debtAmount = usdc.amount(550); uint256 beforeUSDCBalance = usdc.balanceOf(user); uint256 beforeWETHBalance = weth.balanceOf(user); @@ -514,15 +507,15 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv ) ); swapParams.amount = usdc.amount(500); - swapParams.inToken = address(wausdc); + swapParams.inSubstitute = address(wausdc); vm.prank(user); borrowController.borrow{value: 0.16 ether}( waweth, wausdc, collateralAmount, - borrowAmount, - type(uint256).max, + debtAmount, + type(int256).max, EpochLibrary.current().add(1), swapParams, permitParams @@ -536,7 +529,7 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv assertEq(beforeWETHBalance, weth.balanceOf(user), "WETH_BALANCE"); assertEq(loanPosition.expiredWith, EpochLibrary.current().add(1), "POSITION_EXPIRE_EPOCH"); assertEq(loanPosition.collateralAmount, collateralAmount, "POSITION_COLLATERAL_AMOUNT"); - assertEq(loanPosition.debtAmount, borrowAmount, "POSITION_DEBT_AMOUNT"); + assertEq(loanPosition.debtAmount, debtAmount, "POSITION_DEBT_AMOUNT"); assertEq(loanPosition.collateralToken, waweth, "POSITION_COLLATERAL_TOKEN"); assertEq(loanPosition.debtToken, wausdc, "POSITION_DEBT_TOKEN"); } @@ -554,7 +547,7 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv uint256 beforePositionDebtAmount = loanPosition.debtAmount; uint256 collateralAmount = 0.4 ether; - uint256 borrowAmount = usdc.amount(550); + uint256 debtAmount = usdc.amount(550); ERC20PermitParams memory permitParams = vm.signPermit( 1, @@ -575,15 +568,14 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv ) ); swapParams.amount = usdc.amount(500); - swapParams.inToken = address(wausdc); + swapParams.inSubstitute = address(wausdc); vm.prank(user); borrowController.adjustPosition{value: 0.16 ether}( positionId, loanPosition.collateralAmount + collateralAmount, - loanPosition.debtAmount + borrowAmount, - type(uint256).max, - 0, + loanPosition.debtAmount + debtAmount, + type(int256).max, loanPosition.expiredWith, swapParams, permit721Params, @@ -603,7 +595,7 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv collateralAmount + beforePositionCollateralAmount, "POSITION_COLLATERAL_AMOUNT" ); - assertEq(loanPosition.debtAmount, borrowAmount + beforePositionDebtAmount, "POSITION_DEBT_AMOUNT"); + assertEq(loanPosition.debtAmount, debtAmount + beforePositionDebtAmount, "POSITION_DEBT_AMOUNT"); assertEq(loanPosition.collateralToken, waweth, "POSITION_COLLATERAL_TOKEN"); assertEq(loanPosition.debtToken, wausdc, "POSITION_DEBT_TOKEN"); } @@ -626,7 +618,7 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv ) ); swapParams.amount = usdc.amount(500); - swapParams.inToken = address(wausdc); + swapParams.inSubstitute = address(wausdc); PermitSignature memory permit721Params = vm.signPermit(1, loanPositionManager, address(borrowController), positionId); @@ -636,7 +628,6 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv positionId, beforeLoanPosition.collateralAmount - collateralAmount, debtAmount, - type(uint256).max, 0, beforeLoanPosition.expiredWith, swapParams, @@ -678,7 +669,7 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv ) ); swapParams.amount = usdc.amount(500); - swapParams.inToken = address(wausdc); + swapParams.inSubstitute = address(wausdc); PermitSignature memory permit721Params = vm.signPermit(1, loanPositionManager, address(borrowController), positionId); @@ -688,7 +679,6 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv positionId, beforeLoanPosition.collateralAmount - collateralAmount, 0, - type(uint256).max, 0, beforeLoanPosition.expiredWith, swapParams, @@ -730,7 +720,7 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv ) ); swapParams.amount = usdc.amount(500); - swapParams.inToken = address(wausdc); + swapParams.inSubstitute = address(wausdc); PermitSignature memory permit721Params = vm.signPermit(1, loanPositionManager, address(borrowController), positionId); @@ -740,7 +730,6 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv positionId, beforeLoanPosition.collateralAmount - collateralAmount, maxDebtAmount, - type(uint256).max, 0, beforeLoanPosition.expiredWith, swapParams, @@ -780,8 +769,7 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv positionId, beforeLoanPosition.collateralAmount, beforeLoanPosition.debtAmount + 0.5 ether, - type(uint256).max, - 0, + type(int256).max, beforeLoanPosition.expiredWith, swapParams, permit721Params, @@ -806,7 +794,6 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv positionId, beforeLoanPosition.collateralAmount - collateralAmount, beforeLoanPosition.debtAmount, - type(uint256).max, 0, beforeLoanPosition.expiredWith, swapParams, @@ -830,8 +817,7 @@ contract BorrowControllerIntegrationTest is Test, CloberMarketSwapCallbackReceiv positionId, beforeLoanPosition.collateralAmount - collateralAmount, beforeLoanPosition.debtAmount, - type(uint256).max, - 0, + type(int256).max, beforeLoanPosition.expiredWith, swapParams, permit721Params, diff --git a/test/foundry/integration/CouponLiquidator.t.sol b/test/foundry/integration/CouponLiquidator.t.sol index 27d76e7..9515d2e 100644 --- a/test/foundry/integration/CouponLiquidator.t.sol +++ b/test/foundry/integration/CouponLiquidator.t.sol @@ -188,7 +188,7 @@ contract CouponLiquidatorIntegrationTest is Test, CloberMarketSwapCallbackReceiv address collateralToken, address borrowToken, uint256 collateralAmount, - uint256 borrowAmount, + uint256 debtAmount, uint8 loanEpochs ) internal returns (uint256 positionId) { positionId = loanPositionManager.nextId(); @@ -205,8 +205,8 @@ contract CouponLiquidatorIntegrationTest is Test, CloberMarketSwapCallbackReceiv collateralToken, borrowToken, collateralAmount, - borrowAmount, - type(uint256).max, + debtAmount, + type(int256).max, EpochLibrary.current().add(loanEpochs - 1), swapParams, permitParams diff --git a/test/foundry/integration/DepositController.t.sol b/test/foundry/integration/DepositController.t.sol index 5e6ebbb..5a6825b 100644 --- a/test/foundry/integration/DepositController.t.sol +++ b/test/foundry/integration/DepositController.t.sol @@ -208,7 +208,7 @@ contract DepositControllerIntegrationTest is Test, CloberMarketSwapCallbackRecei vm.signPermit(1, IERC20Permit(Constants.USDC), address(depositController), amount); vm.expectRevert(abi.encodeWithSelector(IController.ControllerSlippage.selector)); vm.prank(user); - depositController.deposit(wausdc, amount, 2, amount * 4 / 100, permitParams); + depositController.deposit(wausdc, amount, 2, int256(amount * 4 / 100), permitParams); } function testDepositOverCloberMarket() public { @@ -260,7 +260,7 @@ contract DepositControllerIntegrationTest is Test, CloberMarketSwapCallbackRecei depositController.withdraw( tokenId, amount / 2, - type(uint256).max, + type(int256).max, vm.signPermit(1, bondPositionManager, address(depositController), tokenId) ); @@ -277,7 +277,7 @@ contract DepositControllerIntegrationTest is Test, CloberMarketSwapCallbackRecei beforeBalance = usdc.balanceOf(user); beforePosition = afterPosition; - depositController.withdraw(tokenId, beforePosition.amount, type(uint256).max, emptyERC721PermitParams); + depositController.withdraw(tokenId, beforePosition.amount, type(int256).max, emptyERC721PermitParams); afterPosition = bondPositionManager.getPosition(tokenId); @@ -308,7 +308,7 @@ contract DepositControllerIntegrationTest is Test, CloberMarketSwapCallbackRecei depositController.withdraw( tokenId, amount - 1, - type(uint256).max, + type(int256).max, vm.signPermit(1, bondPositionManager, address(depositController), tokenId) ); @@ -336,7 +336,7 @@ contract DepositControllerIntegrationTest is Test, CloberMarketSwapCallbackRecei depositController.withdraw( tokenId, amount / 2, - type(uint256).max, + type(int256).max, vm.signPermit(1, bondPositionManager, address(depositController), tokenId) ); @@ -353,7 +353,7 @@ contract DepositControllerIntegrationTest is Test, CloberMarketSwapCallbackRecei beforeBalance = user.balance; beforePosition = afterPosition; - depositController.withdraw(tokenId, beforePosition.amount, type(uint256).max, emptyERC721PermitParams); + depositController.withdraw(tokenId, beforePosition.amount, type(int256).max, emptyERC721PermitParams); afterPosition = bondPositionManager.getPosition(tokenId);