Skip to content

Commit

Permalink
Finetune Uniswap NFT managers and enable ETH deposits in Router
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed Apr 9, 2024
1 parent 1d1aa87 commit e6fadab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
22 changes: 18 additions & 4 deletions periphery/src/Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
}),
Expand All @@ -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");
Expand All @@ -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
}),
Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions periphery/src/managers/BoostManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions periphery/src/managers/UniswapNFTManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e6fadab

Please sign in to comment.