diff --git a/periphery/src/Router.sol b/periphery/src/Router.sol index ec4e71c..0859802 100644 --- a/periphery/src/Router.sol +++ b/periphery/src/Router.sol @@ -35,18 +35,19 @@ contract Router { uint8 v, bytes32 r, bytes32 s - ) external returns (uint256 shares) { + ) external payable returns (uint256 shares) { lender.permit(msg.sender, address(this), type(uint256).max, deadline, v, r, s); if (lender.balanceOf(msg.sender) > 0) { lender.redeem(type(uint256).max, msg.sender, msg.sender); } + ERC20 asset = lender.asset(); // Transfer tokens from the caller to the lender. PERMIT2.permitTransferFrom( // The permit message. IPermit2.PermitTransferFrom({ - permitted: IPermit2.TokenPermissions({token: lender.asset(), amount: amount}), + permitted: IPermit2.TokenPermissions({token: asset, amount: amount}), nonce: nonce, deadline: deadline }), @@ -61,6 +62,12 @@ contract Router { signature ); + if (msg.value > 0) { + address(asset).call{value: msg.value}(abi.encodeWithSignature("deposit()")); + asset.safeTransfer(address(lender), msg.value); + amount += msg.value; + } + shares = lender.deposit(amount, msg.sender, courierId); unchecked { require(lender.convertToAssets(shares) > (amount * transmittance) / 10_000, "bad rounding"); @@ -74,12 +81,13 @@ contract Router { uint256 nonce, uint256 deadline, bytes calldata signature - ) external returns (uint256 shares) { + ) external payable returns (uint256 shares) { + ERC20 asset = lender.asset(); // Transfer tokens from the caller to the lender. PERMIT2.permitTransferFrom( // The permit message. IPermit2.PermitTransferFrom({ - permitted: IPermit2.TokenPermissions({token: lender.asset(), amount: amount}), + permitted: IPermit2.TokenPermissions({token: asset, amount: amount}), nonce: nonce, deadline: deadline }), @@ -94,6 +102,12 @@ contract Router { signature ); + if (msg.value > 0) { + address(asset).call{value: msg.value}(abi.encodeWithSignature("deposit()")); + asset.safeTransfer(address(lender), msg.value); + amount += msg.value; + } + shares = lender.deposit(amount, msg.sender); unchecked { require(lender.convertToAssets(shares) > (amount * transmittance) / 10_000, "bad rounding"); diff --git a/periphery/src/managers/BoostManager.sol b/periphery/src/managers/BoostManager.sol index 7b6a10d..f9498b9 100644 --- a/periphery/src/managers/BoostManager.sol +++ b/periphery/src/managers/BoostManager.sol @@ -97,8 +97,8 @@ contract BoostManager is IManager, IUniswapV3SwapCallback { TickMath.getSqrtRatioAtTick(upper), liquidity ); - amount0 = (needs0 + 1) > amount0 ? (needs0 + 1 - amount0) : 0; - amount1 = (needs1 + 1) > amount1 ? (needs1 + 1 - amount1) : 0; + amount0 = needs0 > 0 && needs0 > amount0 ? (needs0 + 1 - amount0) : 0; + amount1 = needs1 > 0 && needs1 > amount1 ? (needs1 + 1 - amount1) : 0; } require(amount0 < uint112(maxBorrows) && amount1 < (maxBorrows >> 112), "slippage"); diff --git a/periphery/src/managers/UniswapNFTManager.sol b/periphery/src/managers/UniswapNFTManager.sol index 63fc60f..8c5dc97 100644 --- a/periphery/src/managers/UniswapNFTManager.sol +++ b/periphery/src/managers/UniswapNFTManager.sol @@ -64,8 +64,8 @@ contract UniswapNFTManager is IManager { address(this) ); - token0.safeApprove(address(UNISWAP_NFT), burned0); - token1.safeApprove(address(UNISWAP_NFT), burned1); + token0.safeApprove(address(UNISWAP_NFT), burned0 + 1); + token1.safeApprove(address(UNISWAP_NFT), burned1 + 1); UNISWAP_NFT.increaseLiquidity( IUniswapPositionNFT.IncreaseLiquidityParams({ tokenId: tokenId,