Skip to content

Commit

Permalink
feat: update copy and set approval only if positive amount
Browse files Browse the repository at this point in the history
- update copy on modified contracts
- add if condition to set approval only with positive amount for gas savings on 1-sided liquidity
  • Loading branch information
gabririgo committed Sep 8, 2023
1 parent b78adfc commit 2115d2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion contracts/protocol/extensions/adapters/AUniswap.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0-or-later
/*
Copyright 2021-2022 Rigo Intl.
Copyright 2021-2023 Rigo Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
18 changes: 9 additions & 9 deletions contracts/protocol/extensions/adapters/AUniswapV3NPM.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0-or-later
/*
Copyright 2021-2022 Rigo Intl.
Copyright 2021-2023 Rigo Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,8 +44,8 @@ abstract contract AUniswapV3NPM is IAUniswapV3NPM {
address uniswapNpm = _getUniswapNpm();

// we set the allowance to the uniswap position manager
_safeApprove(params.token0, uniswapNpm, type(uint256).max);
_safeApprove(params.token1, uniswapNpm, type(uint256).max);
if (params.amount0Desired > 0) _safeApprove(params.token0, uniswapNpm, type(uint256).max);
if (params.amount1Desired > 0) _safeApprove(params.token1, uniswapNpm, type(uint256).max);

// only then do we mint the liquidity token
(tokenId, liquidity, amount0, amount1) = INonfungiblePositionManager(uniswapNpm).mint(
Expand All @@ -65,8 +65,8 @@ abstract contract AUniswapV3NPM is IAUniswapV3NPM {
);

// we make sure we do not clear storage
_safeApprove(params.token0, uniswapNpm, uint256(1));
_safeApprove(params.token1, uniswapNpm, uint256(1));
if (params.amount0Desired > 0) _safeApprove(params.token0, uniswapNpm, uint256(1));
if (params.amount1Desired > 0) _safeApprove(params.token1, uniswapNpm, uint256(1));
}

/// @inheritdoc IAUniswapV3NPM
Expand All @@ -90,8 +90,8 @@ abstract contract AUniswapV3NPM is IAUniswapV3NPM {
_assertTokenWhitelisted(token1);

// we first set the allowance to the uniswap position manager
_safeApprove(token0, uniswapNpm, type(uint256).max);
_safeApprove(token1, uniswapNpm, type(uint256).max);
if (params.amount0Desired > 0) _safeApprove(token0, uniswapNpm, type(uint256).max);
if (params.amount1Desired > 0) _safeApprove(token1, uniswapNpm, type(uint256).max);

// finally, we add to the liquidity token
(liquidity, amount0, amount1) = INonfungiblePositionManager(uniswapNpm).increaseLiquidity(
Expand All @@ -106,8 +106,8 @@ abstract contract AUniswapV3NPM is IAUniswapV3NPM {
);

// we make sure we do not clear storage
_safeApprove(token0, uniswapNpm, uint256(1));
_safeApprove(token1, uniswapNpm, uint256(1));
if (params.amount0Desired > 0) _safeApprove(token0, uniswapNpm, uint256(1));
if (params.amount1Desired > 0) _safeApprove(token1, uniswapNpm, uint256(1));
}

/// @inheritdoc IAUniswapV3NPM
Expand Down

0 comments on commit 2115d2c

Please sign in to comment.