From 728d30f43c4de7624d0313fdd19d6876c827fa26 Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:28:50 +0100 Subject: [PATCH 1/5] fix: standardize formatting --- .prettierrc | 15 -- foundry.toml | 12 +- src/_global/swapUtils.sol | 4 +- src/aave-v2/AaveV2ERC4626Reinvest.sol | 28 ++- src/aave-v2/AaveV2ERC4626ReinvestFactory.sol | 10 +- .../AaveV2ERC4626ReinvestIncentive.sol | 31 ++- .../AaveV2ERC4626ReinvestIncentiveFactory.sol | 10 +- src/aave-v2/test/AaveV2ERC4626Reinvest.t.sol | 22 +- src/aave-v3/AaveV3ERC4626Reinvest.sol | 28 ++- src/aave-v3/AaveV3ERC4626ReinvestFactory.sol | 16 +- .../AaveV3ERC4626ReinvestIncentive.sol | 28 ++- .../AaveV3ERC4626ReinvestIncentiveFactory.sol | 16 +- src/aave-v3/AaveV3ERC4626ReinvestUni.sol | 30 ++- .../AaveV3ERC4626ReinvestUniFactory.sol | 16 +- src/aave-v3/external/IRewardsController.sol | 13 +- src/aave-v3/test/AaveV3ERC4626Reinvest.t.sol | 18 +- .../test/AaveV3ERC4626ReinvestIncentive.t.sol | 18 +- .../test/AaveV3ERC4626ReinvestUni.t.sol | 18 +- src/alpaca/AlpacaERC4626Reinvest.sol | 21 +- src/alpaca/test/AlpacaERC4626Reinvest.t.sol | 16 +- src/arrakis/Arrakis_Factory.sol | 13 +- src/arrakis/Arrakis_Non_Native_LP_Vault.sol | 48 ++-- src/arrakis/interfaces/IArrakisRouter.sol | 6 +- .../test/Arrakis_Non_Native_LP_Vault.t.sol | 235 ++++++------------ src/arrakis/utils/FullMath.sol | 24 +- src/arrakis/utils/IGUniPool.sol | 46 ++-- src/arrakis/utils/LiquidityAmounts.sol | 135 +++++----- src/arrakis/utils/TickMath.sol | 114 ++++----- src/arrakis/utils/Utilities.sol | 11 +- src/benqi/BenqiERC4626Reinvest.sol | 31 ++- src/benqi/BenqiERC4626Staking.sol | 32 ++- src/benqi/BenqiNativeERC4626Reinvest.sol | 43 ++-- src/benqi/external/IBERC20.sol | 4 +- src/benqi/external/IBEther.sol | 2 +- src/benqi/external/LibBCompound.sol | 7 +- src/benqi/test/BenqiERC4626Reinvest.t.sol | 16 +- src/benqi/test/BenqiERC4626Staking.t.sol | 12 +- .../test/BenqiNativeERC4626Reinvest.t.sol | 18 +- src/compound/CompoundV2ERC4626Wrapper.sol | 25 +- src/compound/CompoundV3ERC4626Wrapper.sol | 22 +- src/compound/external/ICERC20.sol | 4 +- src/compound/external/IComet.sol | 8 +- src/compound/external/IComptroller.sol | 2 +- src/compound/external/LibCompound.sol | 7 +- .../test/CompoundV2ERC4626Wrapper.t.sol | 8 +- .../test/CompoundV3ERC4626Wrapper.t.sol | 8 +- src/geist/GeistERC4626Reinvest.sol | 28 ++- src/geist/test/GeistERC4626Reinvest.t.sol | 24 +- src/interfaces/IERC4626TimelockVault.sol | 8 +- src/kycdao-4626/kycdao4626.sol | 22 +- src/kycdao-4626/test/kycdao4626.t.sol | 16 +- src/lido/stETH.sol | 19 +- src/lido/stETH_swap.sol | 32 ++- src/lido/stMATIC.sol | 19 +- src/lido/test/stETH.t.sol | 14 +- src/lido/test/stETH_swap.t.sol | 12 +- src/lido/test/stMatic.t.sol | 10 +- src/rocketPool/rEth.sol | 42 ++-- src/rocketPool/test/rEth.t.sol | 12 +- src/uniswap-v2/interfaces/IUniswapV2ERC20.sol | 10 +- src/uniswap-v2/interfaces/IUniswapV2Pair.sol | 10 +- .../interfaces/IUniswapV2Router.sol | 16 +- .../no-swap/UniswapV2WrapperERC4626.sol | 52 ++-- .../UniswapV2ERC4626PoolFactory.sol | 22 +- .../swap-built-in/UniswapV2ERC4626Swap.sol | 103 +++++--- src/uniswap-v2/test/UniswapV2.t.sol | 16 +- src/uniswap-v2/test/UniswapV2Swap.t.sol | 18 +- src/uniswap-v2/test/UniswapV2SwapLocal.t.sol | 37 +-- src/uniswap-v2/utils/UniswapV2Library.sol | 34 ++- src/venus/VenusERC4626Reinvest.sol | 24 +- src/venus/external/IVComptroller.sol | 2 +- src/venus/external/IVERC20.sol | 4 +- src/venus/external/LibVCompound.sol | 7 +- src/venus/test/VenusERC4626Harvest.t.sol | 16 +- src/venus/test/VenusERC4626Wrapper.t.sol | 16 +- 75 files changed, 1019 insertions(+), 877 deletions(-) delete mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index e368cfe..0000000 --- a/.prettierrc +++ /dev/null @@ -1,15 +0,0 @@ -{ - "overrides": [ - { - "files": "*.sol", - "options": { - "printWidth": 80, - "tabWidth": 4, - "useTabs": false, - "singleQuote": false, - "bracketSpacing": false, - "explicitTypes": "always" - } - } - ] -} diff --git a/foundry.toml b/foundry.toml index 6e08247..b3bea11 100644 --- a/foundry.toml +++ b/foundry.toml @@ -15,4 +15,14 @@ remappings = [ 'v2-periphery/=lib/v2-periphery/contracts/' ] -fs_permissions = [{ access = "read-write", path = "./"}] \ No newline at end of file +fs_permissions = [{ access = "read-write", path = "./"}] + +[fmt] +bracket_spacing = true +int_types = "long" +line_length = 120 +multiline_func_header = "all" +number_underscore = "thousands" +quote_style = "double" +tab_width = 4 +wrap_comments = true diff --git a/src/_global/swapUtils.sol b/src/_global/swapUtils.sol index ffdef6d..1528181 100644 --- a/src/_global/swapUtils.sol +++ b/src/_global/swapUtils.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; interface IPair { function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); diff --git a/src/aave-v2/AaveV2ERC4626Reinvest.sol b/src/aave-v2/AaveV2ERC4626Reinvest.sol index 5970eeb..9141516 100644 --- a/src/aave-v2/AaveV2ERC4626Reinvest.sol +++ b/src/aave-v2/AaveV2ERC4626Reinvest.sol @@ -1,14 +1,14 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; -import {ILendingPool} from "./aave/ILendingPool.sol"; -import {IAaveMining} from "./aave/IAaveMining.sol"; +import { ILendingPool } from "./aave/ILendingPool.sol"; +import { IAaveMining } from "./aave/IAaveMining.sol"; -import {DexSwap} from "../_global/swapUtils.sol"; +import { DexSwap } from "../_global/swapUtils.sol"; /// @title AaveV2ERC4626Reinvest /// @notice Extended implementation of yield-daddy's ERC4626 @@ -89,7 +89,9 @@ contract AaveV2ERC4626Reinvest is ERC4626 { ILendingPool lendingPool_, address rewardToken_, address manager_ - ) ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) { + ) + ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) + { aToken = aToken_; rewards = rewards_; lendingPool = lendingPool_; @@ -186,7 +188,11 @@ contract AaveV2ERC4626Reinvest is ERC4626 { ///@param assets_ Amount of assets to withdraw ///@param receiver_ Address to send withdrawn assets to ///@param owner_ Address to burn shares from - function withdraw(uint256 assets_, address receiver_, address owner_) + function withdraw( + uint256 assets_, + address receiver_, + address owner_ + ) public virtual override @@ -216,7 +222,11 @@ contract AaveV2ERC4626Reinvest is ERC4626 { ///@param shares_ Amount of shares to redeem ///@param receiver_ Address to send redeemed assets to ///@param owner_ Address to burn shares from - function redeem(uint256 shares_, address receiver_, address owner_) + function redeem( + uint256 shares_, + address receiver_, + address owner_ + ) public virtual override diff --git a/src/aave-v2/AaveV2ERC4626ReinvestFactory.sol b/src/aave-v2/AaveV2ERC4626ReinvestFactory.sol index 97e741e..5a10489 100644 --- a/src/aave-v2/AaveV2ERC4626ReinvestFactory.sol +++ b/src/aave-v2/AaveV2ERC4626ReinvestFactory.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; -import {AaveV2ERC4626Reinvest} from "./AaveV2ERC4626Reinvest.sol"; -import {IAaveMining} from "./aave/IAaveMining.sol"; -import {ILendingPool} from "./aave/ILendingPool.sol"; +import { AaveV2ERC4626Reinvest } from "./AaveV2ERC4626Reinvest.sol"; +import { IAaveMining } from "./aave/IAaveMining.sol"; +import { ILendingPool } from "./aave/ILendingPool.sol"; /// @title AaveV2ERC4626ReinvestFactory /// @notice Factory for creating AaveV2ERC4626 contracts diff --git a/src/aave-v2/AaveV2ERC4626ReinvestIncentive.sol b/src/aave-v2/AaveV2ERC4626ReinvestIncentive.sol index 69fe41d..ea85b8b 100644 --- a/src/aave-v2/AaveV2ERC4626ReinvestIncentive.sol +++ b/src/aave-v2/AaveV2ERC4626ReinvestIncentive.sol @@ -1,17 +1,18 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; -import {ILendingPool} from "./aave/ILendingPool.sol"; -import {IAaveMining} from "./aave/IAaveMining.sol"; +import { ILendingPool } from "./aave/ILendingPool.sol"; +import { IAaveMining } from "./aave/IAaveMining.sol"; -import {DexSwap} from "../_global/swapUtils.sol"; +import { DexSwap } from "../_global/swapUtils.sol"; /// @title AaveV2ERC4626ReinvestIncentive -/// @notice Extended implementation of yield-daddy AaveV2 wrapper with reinvesting logic - with incentives to call harvest() built-in +/// @notice Extended implementation of yield-daddy AaveV2 wrapper with reinvesting logic - with incentives to call +/// harvest() built-in /// @notice Reinvests rewards accrued for higher APY /// @author ZeroPoint Labs contract AaveV2ERC4626ReinvestIncentive is ERC4626 { @@ -95,7 +96,9 @@ contract AaveV2ERC4626ReinvestIncentive is ERC4626 { ILendingPool lendingPool_, address rewardToken_, address manager_ - ) ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) { + ) + ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) + { aToken = aToken_; rewards = rewards_; lendingPool = lendingPool_; @@ -162,7 +165,11 @@ contract AaveV2ERC4626ReinvestIncentive is ERC4626 { ERC4626 OVERRIDE FUNCTIONS //////////////////////////////////////////////////////////////*/ - function withdraw(uint256 assets_, address receiver_, address owner_) + function withdraw( + uint256 assets_, + address receiver_, + address owner_ + ) public virtual override @@ -188,7 +195,11 @@ contract AaveV2ERC4626ReinvestIncentive is ERC4626 { lendingPool.withdraw(address(asset), assets_, receiver_); } - function redeem(uint256 shares_, address receiver_, address owner_) + function redeem( + uint256 shares_, + address receiver_, + address owner_ + ) public virtual override diff --git a/src/aave-v2/AaveV2ERC4626ReinvestIncentiveFactory.sol b/src/aave-v2/AaveV2ERC4626ReinvestIncentiveFactory.sol index 4d6c3f4..171b9c2 100644 --- a/src/aave-v2/AaveV2ERC4626ReinvestIncentiveFactory.sol +++ b/src/aave-v2/AaveV2ERC4626ReinvestIncentiveFactory.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; -import {AaveV2ERC4626ReinvestIncentive} from "./AaveV2ERC4626ReinvestIncentive.sol"; -import {IAaveMining} from "./aave/IAaveMining.sol"; -import {ILendingPool} from "./aave/ILendingPool.sol"; +import { AaveV2ERC4626ReinvestIncentive } from "./AaveV2ERC4626ReinvestIncentive.sol"; +import { IAaveMining } from "./aave/IAaveMining.sol"; +import { ILendingPool } from "./aave/ILendingPool.sol"; /// @title AaveV2ERC4626ReinvestFactory /// @notice Factory for creating AaveV2ERC4626Reinvest contracts diff --git a/src/aave-v2/test/AaveV2ERC4626Reinvest.t.sol b/src/aave-v2/test/AaveV2ERC4626Reinvest.t.sol index 20500e6..8ecc59e 100644 --- a/src/aave-v2/test/AaveV2ERC4626Reinvest.t.sol +++ b/src/aave-v2/test/AaveV2ERC4626Reinvest.t.sol @@ -2,15 +2,15 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; -import {AaveV2ERC4626Reinvest} from "../AaveV2ERC4626Reinvest.sol"; -import {AaveV2ERC4626ReinvestFactory} from "../AaveV2ERC4626ReinvestFactory.sol"; +import { AaveV2ERC4626Reinvest } from "../AaveV2ERC4626Reinvest.sol"; +import { AaveV2ERC4626ReinvestFactory } from "../AaveV2ERC4626ReinvestFactory.sol"; -import {ILendingPool} from "../aave/ILendingPool.sol"; -import {IAaveMining} from "../aave/IAaveMining.sol"; -import {DexSwap} from "../../_global/swapUtils.sol"; +import { ILendingPool } from "../aave/ILendingPool.sol"; +import { IAaveMining } from "../aave/IAaveMining.sol"; +import { DexSwap } from "../../_global/swapUtils.sol"; contract AaveV2ERC4626ReinvestTest is Test { //////////////////////////////////////// @@ -54,7 +54,7 @@ contract AaveV2ERC4626ReinvestTest is Test { manager = msg.sender; vm.selectFork(polyFork); - vm.rollFork(39700000); + vm.rollFork(39_700_000); /// @dev Original AAVE v2 reward mining is disabled on each network /// @dev We can leave this set to whatever on V2, harvest() is just not used @@ -92,8 +92,8 @@ contract AaveV2ERC4626ReinvestTest is Test { function setUp() public { alice = address(0x1); bob = address(0x2); - deal(address(asset), alice, 10000 ether); - deal(address(asset), bob, 10000 ether); + deal(address(asset), alice, 10_000 ether); + deal(address(asset), bob, 10_000 ether); } function testFactoryDeploy() public { @@ -112,7 +112,7 @@ contract AaveV2ERC4626ReinvestTest is Test { /// @dev Just check if we can deposit uint256 amount = 100 ether; - deal(address(vaultAsset), alice, 10000 ether); + deal(address(vaultAsset), alice, 10_000 ether); uint256 aliceUnderlyingAmount = amount; vaultAsset.approve(address(vault_), aliceUnderlyingAmount); vault_.deposit(aliceUnderlyingAmount, alice); diff --git a/src/aave-v3/AaveV3ERC4626Reinvest.sol b/src/aave-v3/AaveV3ERC4626Reinvest.sol index 0a852de..b1a4978 100644 --- a/src/aave-v3/AaveV3ERC4626Reinvest.sol +++ b/src/aave-v3/AaveV3ERC4626Reinvest.sol @@ -1,14 +1,14 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; -import {IPool} from "./external/IPool.sol"; -import {IRewardsController} from "./external/IRewardsController.sol"; +import { IPool } from "./external/IPool.sol"; +import { IRewardsController } from "./external/IRewardsController.sol"; -import {DexSwap} from "../_global/swapUtils.sol"; +import { DexSwap } from "../_global/swapUtils.sol"; /// @title AaveV3ERC4626Reinvest /// @notice Extended implementation of yield-daddy's ERC4626 for Aave V3 with rewards reinvesting @@ -101,7 +101,9 @@ contract AaveV3ERC4626Reinvest is ERC4626 { IPool lendingPool_, IRewardsController rewardsController_, address manager_ - ) ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) { + ) + ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) + { aToken = aToken_; lendingPool = lendingPool_; rewardsController = rewardsController_; @@ -252,7 +254,11 @@ contract AaveV3ERC4626Reinvest is ERC4626 { ERC4626 OVERRIDES //////////////////////////////////////////////////////////////*/ - function withdraw(uint256 assets_, address receiver_, address owner_) + function withdraw( + uint256 assets_, + address receiver_, + address owner_ + ) public virtual override @@ -280,7 +286,11 @@ contract AaveV3ERC4626Reinvest is ERC4626 { lendingPool.withdraw(address(asset), assets_, receiver_); } - function redeem(uint256 shares_, address receiver_, address owner_) + function redeem( + uint256 shares_, + address receiver_, + address owner_ + ) public virtual override diff --git a/src/aave-v3/AaveV3ERC4626ReinvestFactory.sol b/src/aave-v3/AaveV3ERC4626ReinvestFactory.sol index d62241b..a52520f 100644 --- a/src/aave-v3/AaveV3ERC4626ReinvestFactory.sol +++ b/src/aave-v3/AaveV3ERC4626ReinvestFactory.sol @@ -1,13 +1,13 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; -import {IPool} from "./external/IPool.sol"; -import {AaveV3ERC4626Reinvest} from "./AaveV3ERC4626Reinvest.sol"; -import {IRewardsController} from "./external/IRewardsController.sol"; -import {Bytes32AddressLib} from "solmate/utils/Bytes32AddressLib.sol"; +import { IPool } from "./external/IPool.sol"; +import { AaveV3ERC4626Reinvest } from "./AaveV3ERC4626Reinvest.sol"; +import { IRewardsController } from "./external/IRewardsController.sol"; +import { Bytes32AddressLib } from "solmate/utils/Bytes32AddressLib.sol"; /// @title AaveV3ERC4626ReinvestFactory /// @notice Factory for creating AaveV3ERC4626 contracts @@ -129,7 +129,9 @@ contract AaveV3ERC4626ReinvestFactory { address token_, address pair1_, address pair2_ - ) external { + ) + external + { if (msg.sender != manager) revert INVALID_ACCESS(); vault_.setRoutes(rewardToken_, token_, pair1_, pair2_); diff --git a/src/aave-v3/AaveV3ERC4626ReinvestIncentive.sol b/src/aave-v3/AaveV3ERC4626ReinvestIncentive.sol index 68d3aed..8a85e32 100644 --- a/src/aave-v3/AaveV3ERC4626ReinvestIncentive.sol +++ b/src/aave-v3/AaveV3ERC4626ReinvestIncentive.sol @@ -1,14 +1,14 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; -import {IPool} from "./external/IPool.sol"; -import {IRewardsController} from "./external/IRewardsController.sol"; +import { IPool } from "./external/IPool.sol"; +import { IRewardsController } from "./external/IRewardsController.sol"; -import {DexSwap} from "../_global/swapUtils.sol"; +import { DexSwap } from "../_global/swapUtils.sol"; /// @title AaveV3ERC4626ReinvestIncentive /// @notice Extended implementation of yield-daddy AaveV3 wrapper for Aave V3 with rewards reinvesting @@ -103,7 +103,9 @@ contract AaveV3ERC4626ReinvestIncentive is ERC4626 { IPool lendingPool_, IRewardsController rewardsController_, address manager_ - ) ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) { + ) + ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) + { aToken = aToken_; lendingPool = lendingPool_; rewardsController = rewardsController_; @@ -260,7 +262,11 @@ contract AaveV3ERC4626ReinvestIncentive is ERC4626 { ERC4626 OVERRIDES //////////////////////////////////////////////////////////////*/ - function withdraw(uint256 assets_, address receiver_, address owner_) + function withdraw( + uint256 assets_, + address receiver_, + address owner_ + ) public virtual override @@ -286,7 +292,11 @@ contract AaveV3ERC4626ReinvestIncentive is ERC4626 { lendingPool.withdraw(address(asset), assets_, receiver_); } - function redeem(uint256 shares_, address receiver_, address owner_) + function redeem( + uint256 shares_, + address receiver_, + address owner_ + ) public virtual override diff --git a/src/aave-v3/AaveV3ERC4626ReinvestIncentiveFactory.sol b/src/aave-v3/AaveV3ERC4626ReinvestIncentiveFactory.sol index 61d0509..b17bca4 100644 --- a/src/aave-v3/AaveV3ERC4626ReinvestIncentiveFactory.sol +++ b/src/aave-v3/AaveV3ERC4626ReinvestIncentiveFactory.sol @@ -1,13 +1,13 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; -import {IPool} from "./external/IPool.sol"; -import {AaveV3ERC4626ReinvestIncentive} from "./AaveV3ERC4626ReinvestIncentive.sol"; -import {IRewardsController} from "./external/IRewardsController.sol"; -import {Bytes32AddressLib} from "solmate/utils/Bytes32AddressLib.sol"; +import { IPool } from "./external/IPool.sol"; +import { AaveV3ERC4626ReinvestIncentive } from "./AaveV3ERC4626ReinvestIncentive.sol"; +import { IRewardsController } from "./external/IRewardsController.sol"; +import { Bytes32AddressLib } from "solmate/utils/Bytes32AddressLib.sol"; /// @title AaveV3ERC4626ReinvestIncentiveFactory /// @notice Factory for creating AaveV3ERC4626 contracts @@ -144,7 +144,9 @@ contract AaveV3ERC4626ReinvestIncentiveFactory { address token_, address pair1_, address pair2_ - ) external { + ) + external + { if (msg.sender != manager) revert INVALID_ACCESS(); vault_.setRoutes(rewardToken_, token_, pair1_, pair2_); diff --git a/src/aave-v3/AaveV3ERC4626ReinvestUni.sol b/src/aave-v3/AaveV3ERC4626ReinvestUni.sol index 3e38d6a..3b679ff 100644 --- a/src/aave-v3/AaveV3ERC4626ReinvestUni.sol +++ b/src/aave-v3/AaveV3ERC4626ReinvestUni.sol @@ -1,15 +1,15 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; -import {IPool} from "./external/IPool.sol"; -import {IRewardsController} from "./external/IRewardsController.sol"; +import { IPool } from "./external/IPool.sol"; +import { IRewardsController } from "./external/IRewardsController.sol"; -import {DexSwap} from "../_global/swapUtils.sol"; -import {ISwapRouter} from "../aave-v2/utils/ISwapRouter.sol"; +import { DexSwap } from "../_global/swapUtils.sol"; +import { ISwapRouter } from "../aave-v2/utils/ISwapRouter.sol"; /// @title AaveV3ERC4626ReinvestUni - /// @notice xtended implementation of yield-daddy ERC4626 wrapper for Aave V3 with rewards reinvesting @@ -91,7 +91,9 @@ contract AaveV3ERC4626ReinvestUni is ERC4626 { IPool lendingPool_, IRewardsController rewardsController_, address manager_ - ) ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) { + ) + ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) + { aToken = aToken_; lendingPool = lendingPool_; rewardsController = rewardsController_; @@ -204,7 +206,11 @@ contract AaveV3ERC4626ReinvestUni is ERC4626 { ERC4626 OVERRIDES //////////////////////////////////////////////////////////////*/ - function withdraw(uint256 assets_, address receiver_, address owner_) + function withdraw( + uint256 assets_, + address receiver_, + address owner_ + ) public virtual override @@ -230,7 +236,11 @@ contract AaveV3ERC4626ReinvestUni is ERC4626 { lendingPool.withdraw(address(asset), assets_, receiver_); } - function redeem(uint256 shares_, address receiver_, address owner_) + function redeem( + uint256 shares_, + address receiver_, + address owner_ + ) public virtual override diff --git a/src/aave-v3/AaveV3ERC4626ReinvestUniFactory.sol b/src/aave-v3/AaveV3ERC4626ReinvestUniFactory.sol index aeaf1ac..2adefc2 100644 --- a/src/aave-v3/AaveV3ERC4626ReinvestUniFactory.sol +++ b/src/aave-v3/AaveV3ERC4626ReinvestUniFactory.sol @@ -1,13 +1,13 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; -import {IPool} from "./external/IPool.sol"; -import {AaveV3ERC4626ReinvestUni} from "./AaveV3ERC4626ReinvestUni.sol"; -import {IRewardsController} from "./external/IRewardsController.sol"; -import {Bytes32AddressLib} from "solmate/utils/Bytes32AddressLib.sol"; +import { IPool } from "./external/IPool.sol"; +import { AaveV3ERC4626ReinvestUni } from "./AaveV3ERC4626ReinvestUni.sol"; +import { IRewardsController } from "./external/IRewardsController.sol"; +import { Bytes32AddressLib } from "solmate/utils/Bytes32AddressLib.sol"; /// @title AaveV3ERC4626ReinvestUniFactory /// @notice Forked from yield-daddy AaveV3ERC4626Factory for creating AaveV3ERC4626 contracts @@ -136,7 +136,9 @@ contract AaveV3ERC4626ReinvestUniFactory { uint24 poolFee1_, address tokenMid_, uint24 poolFee2_ - ) external { + ) + external + { if (msg.sender != manager) revert INVALID_ACCESS(); vault_.setRoutes(rewardToken_, poolFee1_, tokenMid_, poolFee2_); diff --git a/src/aave-v3/external/IRewardsController.sol b/src/aave-v3/external/IRewardsController.sol index 12fb793..d6bc44e 100644 --- a/src/aave-v3/external/IRewardsController.sol +++ b/src/aave-v3/external/IRewardsController.sol @@ -7,7 +7,10 @@ pragma solidity 0.8.21; * @notice Defines the basic interface for a Rewards Controller. */ interface IRewardsController { - function getAllUserRewards(address[] calldata assets, address user) + function getAllUserRewards( + address[] calldata assets, + address user + ) external view returns (address[] memory rewardsList, uint256[] memory unclaimedAmounts); @@ -22,14 +25,18 @@ interface IRewardsController { function getRewardsByAsset(address asset) external view returns (address[] memory); /** - * @dev Claims all rewards for a user to the desired address, on all the assets of the pool, accumulating the pending rewards + * @dev Claims all rewards for a user to the desired address, on all the assets of the pool, accumulating the + * pending rewards * @param assets The list of assets to check eligible distributions before claiming rewards * @param to The address that will be receiving the rewards * @return rewardsList List of addresses of the reward tokens * @return claimedAmounts List that contains the claimed amount per reward, following same order as "rewardList" * */ - function claimAllRewards(address[] calldata assets, address to) + function claimAllRewards( + address[] calldata assets, + address to + ) external returns (address[] memory rewardsList, uint256[] memory claimedAmounts); } diff --git a/src/aave-v3/test/AaveV3ERC4626Reinvest.t.sol b/src/aave-v3/test/AaveV3ERC4626Reinvest.t.sol index 2f73a7c..39b3210 100644 --- a/src/aave-v3/test/AaveV3ERC4626Reinvest.t.sol +++ b/src/aave-v3/test/AaveV3ERC4626Reinvest.t.sol @@ -2,14 +2,14 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; -import {AaveV3ERC4626Reinvest} from "../AaveV3ERC4626Reinvest.sol"; -import {AaveV3ERC4626ReinvestFactory} from "../AaveV3ERC4626ReinvestFactory.sol"; +import { AaveV3ERC4626Reinvest } from "../AaveV3ERC4626Reinvest.sol"; +import { AaveV3ERC4626ReinvestFactory } from "../AaveV3ERC4626ReinvestFactory.sol"; -import {IRewardsController} from "../../aave-v3/external/IRewardsController.sol"; -import {IPool} from "../external/IPool.sol"; +import { IRewardsController } from "../../aave-v3/external/IRewardsController.sol"; +import { IPool } from "../external/IPool.sol"; contract AaveV3ERC4626ReinvestTest is Test { //////////////////////////////////////// @@ -47,7 +47,7 @@ contract AaveV3ERC4626ReinvestTest is Test { manager = msg.sender; vm.selectFork(avaxFork); - vm.rollFork(26800000); + vm.rollFork(26_800_000); rewards = IRewardsController(vm.envAddress("AAVEV3_AVAX_REWARDS")); lendingPool = IPool(vm.envAddress("AAVEV3_AVAX_LENDINGPOOL")); @@ -88,8 +88,8 @@ contract AaveV3ERC4626ReinvestTest is Test { alice = address(0x1); bob = address(0x2); /// TODO: Should be e18 by default - deal(address(asset), alice, 10000e6); - deal(address(asset), bob, 10000e6); + deal(address(asset), alice, 10_000e6); + deal(address(asset), bob, 10_000e6); } function testFactoryDeployDAIAndDeposit() public { diff --git a/src/aave-v3/test/AaveV3ERC4626ReinvestIncentive.t.sol b/src/aave-v3/test/AaveV3ERC4626ReinvestIncentive.t.sol index acd98b7..bcd69af 100644 --- a/src/aave-v3/test/AaveV3ERC4626ReinvestIncentive.t.sol +++ b/src/aave-v3/test/AaveV3ERC4626ReinvestIncentive.t.sol @@ -2,14 +2,14 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; -import {AaveV3ERC4626ReinvestIncentive} from "../AaveV3ERC4626ReinvestIncentive.sol"; -import {AaveV3ERC4626ReinvestIncentiveFactory} from "../AaveV3ERC4626ReinvestIncentiveFactory.sol"; +import { AaveV3ERC4626ReinvestIncentive } from "../AaveV3ERC4626ReinvestIncentive.sol"; +import { AaveV3ERC4626ReinvestIncentiveFactory } from "../AaveV3ERC4626ReinvestIncentiveFactory.sol"; -import {IRewardsController} from "../../aave-v3/external/IRewardsController.sol"; -import {IPool} from "../external/IPool.sol"; +import { IRewardsController } from "../../aave-v3/external/IRewardsController.sol"; +import { IPool } from "../external/IPool.sol"; contract AaveV3ERC4626ReinvestIncentiveTest is Test { //////////////////////////////////////// @@ -48,7 +48,7 @@ contract AaveV3ERC4626ReinvestIncentiveTest is Test { manager = msg.sender; vm.selectFork(avaxFork); - vm.rollFork(26800000); + vm.rollFork(26_800_000); rewards = IRewardsController(vm.envAddress("AAVEV3_AVAX_REWARDS")); lendingPool = IPool(vm.envAddress("AAVEV3_AVAX_LENDINGPOOL")); @@ -89,8 +89,8 @@ contract AaveV3ERC4626ReinvestIncentiveTest is Test { bob = address(0x2); harvestCaller = address(0x3); /// TODO: Should be e18 by default - deal(address(asset), alice, 10000e6); - deal(address(asset), bob, 10000e6); + deal(address(asset), alice, 10_000e6); + deal(address(asset), bob, 10_000e6); } function testFactoryDeployDAIAndDeposit() public { diff --git a/src/aave-v3/test/AaveV3ERC4626ReinvestUni.t.sol b/src/aave-v3/test/AaveV3ERC4626ReinvestUni.t.sol index 87a48c8..86ec3b0 100644 --- a/src/aave-v3/test/AaveV3ERC4626ReinvestUni.t.sol +++ b/src/aave-v3/test/AaveV3ERC4626ReinvestUni.t.sol @@ -2,14 +2,14 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; -import {AaveV3ERC4626ReinvestUni} from "../AaveV3ERC4626ReinvestUni.sol"; -import {AaveV3ERC4626ReinvestUniFactory} from "../AaveV3ERC4626ReinvestUniFactory.sol"; +import { AaveV3ERC4626ReinvestUni } from "../AaveV3ERC4626ReinvestUni.sol"; +import { AaveV3ERC4626ReinvestUniFactory } from "../AaveV3ERC4626ReinvestUniFactory.sol"; -import {IRewardsController} from "../../aave-v3/external/IRewardsController.sol"; -import {IPool} from "../external/IPool.sol"; +import { IRewardsController } from "../../aave-v3/external/IRewardsController.sol"; +import { IPool } from "../external/IPool.sol"; contract AaveV3ERC4626ReinvestUniTest is Test { //////////////////////////////////////// @@ -48,7 +48,7 @@ contract AaveV3ERC4626ReinvestUniTest is Test { manager = msg.sender; vm.selectFork(optiFork); - vm.rollFork(24518058); + vm.rollFork(24_518_058); rewards = IRewardsController(vm.envAddress("AAVEV3_OPTIMISM_REWARDS")); lendingPool = IPool(vm.envAddress("AAVEV3_OPTIMISM_LENDINGPOOL")); @@ -86,8 +86,8 @@ contract AaveV3ERC4626ReinvestUniTest is Test { alice = address(0x1); bob = address(0x2); /// TODO: Should be e18 by default - deal(address(asset), alice, 10000e6); - deal(address(asset), bob, 10000e6); + deal(address(asset), alice, 10_000e6); + deal(address(asset), bob, 10_000e6); } function testFailManagerCreateERC4626() public { diff --git a/src/alpaca/AlpacaERC4626Reinvest.sol b/src/alpaca/AlpacaERC4626Reinvest.sol index 2b4bace..f9901ec 100644 --- a/src/alpaca/AlpacaERC4626Reinvest.sol +++ b/src/alpaca/AlpacaERC4626Reinvest.sol @@ -1,16 +1,16 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {IBToken} from "./interfaces/IBToken.sol"; -import {IFairLaunch} from "./interfaces/IFairLaunch.sol"; -import {IVaultConfig} from "./interfaces/IVaultConfig.sol"; -import {DexSwap} from "../_global/swapUtils.sol"; +import { IBToken } from "./interfaces/IBToken.sol"; +import { IFairLaunch } from "./interfaces/IFairLaunch.sol"; +import { IVaultConfig } from "./interfaces/IVaultConfig.sol"; +import { DexSwap } from "../_global/swapUtils.sol"; /// @title Alpaca ERC4626 Wrapper /// @notice Extended AAVE-V2 logic using FairLaunch (and not AaveMining) for rewards distribution @@ -126,7 +126,8 @@ contract AlpacaERC4626Reinvest is ERC4626 { /// @notice Harvest AlpacaToken rewards for all of the shares held by this vault /// @notice Amount gets reinvested into the vault after swap to the underlying /// @notice This implementation is sub-optimal for fair distribution of APY among shareholders - /// @notice Ie. Shareholder may request to withdraw his share before harvest accrued value, forfeiting his rewards boosted APY + /// @notice Ie. Shareholder may request to withdraw his share before harvest accrued value, forfeiting his rewards + /// boosted APY function harvest(uint256 minAmountOut_) external { staking.harvest(poolId); @@ -246,7 +247,7 @@ contract AlpacaERC4626Reinvest is ERC4626 { uint256 vaultDebtVal = ibToken.vaultDebtVal(); if (block.timestamp > ibToken.lastAccrueTime()) { uint256 interest = ibToken.pendingInterest(0); - uint256 toReserve = interest.mulDivDown(IVaultConfig(ibToken.config()).getReservePoolBps(), 10000); + uint256 toReserve = interest.mulDivDown(IVaultConfig(ibToken.config()).getReservePoolBps(), 10_000); reservePool = reservePool + (toReserve); vaultDebtVal = vaultDebtVal + (interest); } diff --git a/src/alpaca/test/AlpacaERC4626Reinvest.t.sol b/src/alpaca/test/AlpacaERC4626Reinvest.t.sol index 5e94aba..d6db2e0 100644 --- a/src/alpaca/test/AlpacaERC4626Reinvest.t.sol +++ b/src/alpaca/test/AlpacaERC4626Reinvest.t.sol @@ -2,11 +2,11 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {AlpacaERC4626Reinvest} from "../AlpacaERC4626Reinvest.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { AlpacaERC4626Reinvest } from "../AlpacaERC4626Reinvest.sol"; -import {IBToken} from "../interfaces/IBToken.sol"; -import {IFairLaunch} from "../interfaces/IFairLaunch.sol"; +import { IBToken } from "../interfaces/IBToken.sol"; +import { IFairLaunch } from "../interfaces/IFairLaunch.sol"; /// Deployment addresses: https://github.com/alpaca-finance/bsc-alpaca-contract/blob/main/.mainnet.json contract AlpacaERC4626ReinvestTest is Test { @@ -50,7 +50,7 @@ contract AlpacaERC4626ReinvestTest is Test { vm.prank(manager); vault.setRoute(address(asset), swapPair1, swapPair1); - deal(address(asset), alice, 100000000 ether); + deal(address(asset), alice, 100_000_000 ether); } function setVault(IBToken asset_, uint256 poolId_) public { @@ -66,7 +66,7 @@ contract AlpacaERC4626ReinvestTest is Test { } function testDepositWithdraw() public { - uint256 amount = 10000 ether; + uint256 amount = 10_000 ether; vm.startPrank(alice); @@ -86,7 +86,7 @@ contract AlpacaERC4626ReinvestTest is Test { } function testHarvest() public { - uint256 amount = 10000 ether; + uint256 amount = 10_000 ether; vm.startPrank(alice); @@ -102,7 +102,7 @@ contract AlpacaERC4626ReinvestTest is Test { assertEq(vault.balanceOf(alice), aliceShareAmount); /// @dev temp hack to get ALPACA, impl should be tested more anyways - deal(address(alpacaToken), address(vault), 100000 ether); + deal(address(alpacaToken), address(vault), 100_000 ether); vault.harvest(1); } } diff --git a/src/arrakis/Arrakis_Factory.sol b/src/arrakis/Arrakis_Factory.sol index 7bb2bfe..82a8de3 100644 --- a/src/arrakis/Arrakis_Factory.sol +++ b/src/arrakis/Arrakis_Factory.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {ArrakisNonNativeVault, IArrakisRouter, IGUniPool} from "./Arrakis_Non_Native_LP_Vault.sol"; -import {IStakePool} from "./interfaces/IStakePool.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { ArrakisNonNativeVault, IArrakisRouter, IGUniPool } from "./Arrakis_Non_Native_LP_Vault.sol"; +import { IStakePool } from "./interfaces/IStakePool.sol"; /// @title ArrakisFactory /// @notice Factory for creating ArrakisERC4626 contracts @@ -67,7 +67,10 @@ contract ArrakisFactory { string memory symbol_, address gauge_, uint160 slippage_ - ) external returns (ArrakisNonNativeVault vaultA, ArrakisNonNativeVault vaultB) { + ) + external + returns (ArrakisNonNativeVault vaultA, ArrakisNonNativeVault vaultB) + { IGUniPool pool = IGUniPool(gUniPool_); ERC20 token0 = pool.token0(); ERC20 token1 = pool.token1(); diff --git a/src/arrakis/Arrakis_Non_Native_LP_Vault.sol b/src/arrakis/Arrakis_Non_Native_LP_Vault.sol index 5c7405f..f68d58c 100644 --- a/src/arrakis/Arrakis_Non_Native_LP_Vault.sol +++ b/src/arrakis/Arrakis_Non_Native_LP_Vault.sol @@ -1,17 +1,17 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; - -import {IGUniPool} from "./utils/IGUniPool.sol"; -import {IUniswapV3Pool} from "v3-core/interfaces/IUniswapV3Pool.sol"; -import {TickMath} from "./utils/TickMath.sol"; -import {LiquidityAmounts, FullMath} from "./utils/LiquidityAmounts.sol"; -import {IArrakisRouter} from "./interfaces/IArrakisRouter.sol"; -import {IGauge} from "./interfaces/IGauge.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; + +import { IGUniPool } from "./utils/IGUniPool.sol"; +import { IUniswapV3Pool } from "v3-core/interfaces/IUniswapV3Pool.sol"; +import { TickMath } from "./utils/TickMath.sol"; +import { LiquidityAmounts, FullMath } from "./utils/LiquidityAmounts.sol"; +import { IArrakisRouter } from "./interfaces/IArrakisRouter.sol"; +import { IGauge } from "./interfaces/IGauge.sol"; /// @title ArrakisNonNativeVault /// @notice A vault for wrapping arrakis vault LP tokens and depositing them to the vault. @@ -135,7 +135,8 @@ contract ArrakisNonNativeVault is ERC4626 { uint256 priceDecimals; uint256 liquidity; uint256 grossLiquidity; - /// @dev calculating non_asset price in terms on asset price to find virtual total assets in terms of deposit asset + /// @dev calculating non_asset price in terms on asset price to find virtual total assets in terms of deposit + /// asset if (zeroForOne) { /// @dev using sqrtPriceX96 * sqrtPriceX96 to calculate the price of non_asset in terms of asset priceDecimals = (((10 ** non_asset.decimals()) * X96) / ((sqrtRatioX96 * sqrtRatioX96) / X96)); @@ -161,7 +162,8 @@ contract ArrakisNonNativeVault is ERC4626 { (uint160 sqrtRatioX96,,,,,,) = arrakisVault.pool().slot0(); uint256 priceDecimals = (1 ether * ((sqrtRatioX96 * sqrtRatioX96) / X96)) / X96; - /// @dev multiplying the price decimals by 1e12 as the price you get from sqrtRationX96 is 6 decimals but need 18 decimal value for this method + /// @dev multiplying the price decimals by 1e12 as the price you get from sqrtRationX96 is 6 decimals but need + /// 18 decimal value for this method (bool _direction, uint256 swapAmount) = getRebalanceParams( arrakisVault, zeroForOne ? underlyingAmount_ : 0, !zeroForOne ? underlyingAmount_ : 0, priceDecimals * 1e12 ); @@ -180,7 +182,8 @@ contract ArrakisNonNativeVault is ERC4626 { _swap(params); - /// @notice we need a final swap to put the remaining amount of tokens into liquidity as before swap might have moved the liquidity positions needed. + /// @notice we need a final swap to put the remaining amount of tokens into liquidity as before swap might have + /// moved the liquidity positions needed. uint256 token0Bal = arrakisVault.token0().balanceOf(address(this)); uint256 token1Bal = arrakisVault.token1().balanceOf(address(this)); (uint256 amount0Used, uint256 amount1Used,) = arrakisVault.getMintAmounts(token0Bal, token1Bal); @@ -270,30 +273,30 @@ contract ArrakisNonNativeVault is ERC4626 { /// @notice maximum amount of assets that can be deposited. function maxDeposit(address) public view override returns (uint256) { - if (arrakisVault.restrictedMintToggle() == 11111) return 0; + if (arrakisVault.restrictedMintToggle() == 11_111) return 0; return type(uint256).max; } /// @notice maximum amount of shares that can be minted. function maxMint(address) public view override returns (uint256) { - if (arrakisVault.restrictedMintToggle() == 11111) return 0; + if (arrakisVault.restrictedMintToggle() == 11_111) return 0; return type(uint256).max; } /// @notice Maximum amount of liquidity of the pool that can be withdrawn. function maxWithdraw(address owner) public view override returns (uint256) { - if (arrakisVault.restrictedMintToggle() == 11111) return 0; + if (arrakisVault.restrictedMintToggle() == 11_111) return 0; uint256 liquidityBalance = convertToAssets(balanceOf[owner]); return liquidityBalance; } /// @notice Maximum amount of shares that can be redeemed. function maxRedeem(address owner) public view override returns (uint256) { - if (arrakisVault.restrictedMintToggle() == 11111) return 0; + if (arrakisVault.restrictedMintToggle() == 11_111) return 0; return ERC20(address(this)).balanceOf(owner); } - receive() external payable {} + receive() external payable { } /*////////////////////////////////////////////////////////////// UTILITIES METHODS @@ -329,7 +332,12 @@ contract ArrakisNonNativeVault is ERC4626 { SWAP LOGIC HELPERS //////////////////////////////////////////////////////////////*/ - function getRebalanceParams(IGUniPool pool_, uint256 amount0In_, uint256 amount1In_, uint256 price18Decimals_) + function getRebalanceParams( + IGUniPool pool_, + uint256 amount0In_, + uint256 amount1In_, + uint256 price18Decimals_ + ) public view returns (bool direction, uint256 swapAmount) diff --git a/src/arrakis/interfaces/IArrakisRouter.sol b/src/arrakis/interfaces/IArrakisRouter.sol index 8e3db1a..03aaf1e 100644 --- a/src/arrakis/interfaces/IArrakisRouter.sol +++ b/src/arrakis/interfaces/IArrakisRouter.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {IGauge} from "./IGauge.sol"; +import { IGauge } from "./IGauge.sol"; interface IArrakisRouter { function addLiquidityAndStake( @@ -11,5 +11,7 @@ interface IArrakisRouter { uint256 amount0Min, uint256 amount1Min, address receiver - ) external returns (uint256 amount0, uint256 amount1, uint256 mintAmount); + ) + external + returns (uint256 amount0, uint256 amount1, uint256 mintAmount); } diff --git a/src/arrakis/test/Arrakis_Non_Native_LP_Vault.t.sol b/src/arrakis/test/Arrakis_Non_Native_LP_Vault.t.sol index 5bfd782..f6eba4a 100644 --- a/src/arrakis/test/Arrakis_Non_Native_LP_Vault.t.sol +++ b/src/arrakis/test/Arrakis_Non_Native_LP_Vault.t.sol @@ -1,13 +1,21 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.10; -import {Utilities} from "../utils/Utilities.sol"; +import { Utilities } from "../utils/Utilities.sol"; import "forge-std/Vm.sol"; import "forge-std/Test.sol"; -import {ArrakisNonNativeVault, IArrakisRouter, IUniswapV3Pool, LiquidityAmounts, IGUniPool, TickMath, SafeTransferLib} from "../Arrakis_Non_Native_LP_Vault.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {IWETH} from "../utils/IWETH.sol"; -import {ArrakisFactory} from "../Arrakis_Factory.sol"; +import { + ArrakisNonNativeVault, + IArrakisRouter, + IUniswapV3Pool, + LiquidityAmounts, + IGUniPool, + TickMath, + SafeTransferLib +} from "../Arrakis_Non_Native_LP_Vault.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { IWETH } from "../utils/IWETH.sol"; +import { ArrakisFactory } from "../Arrakis_Factory.sol"; interface UniRouter { function factory() external view returns (address); @@ -18,12 +26,15 @@ interface UniRouter { address[] calldata path, address to, uint256 deadline - ) external returns (uint256[] memory amounts); + ) + external + returns (uint256[] memory amounts); } contract Arrakis_LP_Test is Test { using TickMath for int24; using SafeTransferLib for ERC20; + uint256 public maticFork; string POLYGON_RPC_URL = vm.envString("POLYGON_RPC_URL"); ERC20 public arrakisVault; @@ -35,8 +46,7 @@ contract Arrakis_LP_Test is Test { IWETH public WMATIC = IWETH(0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270); address public USDC = 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174; /// @notice TraderJoe router - UniRouter private joeRouter = - UniRouter(0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff); + UniRouter private joeRouter = UniRouter(0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff); function setUp() public { maticFork = vm.createFork(POLYGON_RPC_URL); @@ -50,69 +60,51 @@ contract Arrakis_LP_Test is Test { 0xbc91a120cCD8F80b819EAF32F0996daC3Fa76a6C ); - (arrakisNonNativeVault, arrakisToken1AsAssetVault) = arrakisFactory - .createArrakisVaults( - address(arrakisVault), - "Arrakis WMATIC/USDC LP Vault", - "aLP4626", - 0x9941C03D31BC8B3aA26E363f7DD908725e1a21bb, - 50 - ); + (arrakisNonNativeVault, arrakisToken1AsAssetVault) = arrakisFactory.createArrakisVaults( + address(arrakisVault), + "Arrakis WMATIC/USDC LP Vault", + "aLP4626", + 0x9941C03D31BC8B3aA26E363f7DD908725e1a21bb, + 50 + ); } function getWMATIC(uint256 amt) internal { deal(address(this), amt); deal(USDC, address(this), amt); - WMATIC.deposit{value: amt}(); + WMATIC.deposit{ value: amt }(); } function paramswap() external { uint256 amount; - amount = - ERC20(blah ? address(vault.non_asset()) : address(vault.asset())) - .balanceOf(address(msg.sender)) / - 2; + amount = ERC20(blah ? address(vault.non_asset()) : address(vault.asset())).balanceOf(address(msg.sender)) / 2; IUniswapV3Pool uniPool = vault.arrakisVault().pool(); - (uint160 sqrtPriceX96, , , , , , ) = uniPool.slot0(); + (uint160 sqrtPriceX96,,,,,,) = uniPool.slot0(); uint160 twoPercentSqrtPrice = sqrtPriceX96 / 100; uniPool.swap( address(this), blah, int256(amount), - blah - ? sqrtPriceX96 - (twoPercentSqrtPrice) - : sqrtPriceX96 + (twoPercentSqrtPrice), + blah ? sqrtPriceX96 - (twoPercentSqrtPrice) : sqrtPriceX96 + (twoPercentSqrtPrice), "" ); blah = !blah; } function computeFeesAccrued() external view { - (, int24 tick, , , , , ) = vault.arrakisVault().pool().slot0(); + (, int24 tick,,,,,) = vault.arrakisVault().pool().slot0(); ( uint128 liquidity, uint256 feeGrowthInside0Last, uint256 feeGrowthInside1Last, uint128 tokensOwed0, uint128 tokensOwed1 - ) = vault.arrakisVault().pool().positions( - vault.arrakisVault().getPositionID() - ); + ) = vault.arrakisVault().pool().positions(vault.arrakisVault().getPositionID()); // compute current fees earned - uint256 fee0 = _computeFeesEarned( - true, - feeGrowthInside0Last, - tick, - liquidity - ) + uint256(tokensOwed0); - uint256 fee1 = _computeFeesEarned( - false, - feeGrowthInside1Last, - tick, - liquidity - ) + uint256(tokensOwed1); + uint256 fee0 = _computeFeesEarned(true, feeGrowthInside0Last, tick, liquidity) + uint256(tokensOwed0); + uint256 fee1 = _computeFeesEarned(false, feeGrowthInside1Last, tick, liquidity) + uint256(tokensOwed1); console.log("computed fees", fee0, fee1); } @@ -121,7 +113,11 @@ contract Arrakis_LP_Test is Test { uint256 feeGrowthInsideLast, int24 tick, uint128 liquidity - ) private view returns (uint256 fee) { + ) + private + view + returns (uint256 fee) + { uint256 feeGrowthOutsideLower; uint256 feeGrowthOutsideUpper; uint256 feeGrowthGlobal; @@ -129,20 +125,12 @@ contract Arrakis_LP_Test is Test { IGUniPool gUniPool = vault.arrakisVault(); if (isZero) { feeGrowthGlobal = pool.feeGrowthGlobal0X128(); - (, , feeGrowthOutsideLower, , , , , ) = pool.ticks( - gUniPool.lowerTick() - ); - (, , feeGrowthOutsideUpper, , , , , ) = pool.ticks( - gUniPool.upperTick() - ); + (,, feeGrowthOutsideLower,,,,,) = pool.ticks(gUniPool.lowerTick()); + (,, feeGrowthOutsideUpper,,,,,) = pool.ticks(gUniPool.upperTick()); } else { feeGrowthGlobal = pool.feeGrowthGlobal1X128(); - (, , , feeGrowthOutsideLower, , , , ) = pool.ticks( - gUniPool.lowerTick() - ); - (, , , feeGrowthOutsideUpper, , , , ) = pool.ticks( - gUniPool.upperTick() - ); + (,,, feeGrowthOutsideLower,,,,) = pool.ticks(gUniPool.lowerTick()); + (,,, feeGrowthOutsideUpper,,,,) = pool.ticks(gUniPool.upperTick()); } unchecked { @@ -162,75 +150,46 @@ contract Arrakis_LP_Test is Test { feeGrowthAbove = feeGrowthGlobal - feeGrowthOutsideUpper; } - uint256 feeGrowthInside = feeGrowthGlobal - - feeGrowthBelow - - feeGrowthAbove; - fee = - (liquidity * (feeGrowthInside - feeGrowthInsideLast)) / - 0x100000000000000000000000000000000; + uint256 feeGrowthInside = feeGrowthGlobal - feeGrowthBelow - feeGrowthAbove; + fee = (liquidity * (feeGrowthInside - feeGrowthInsideLast)) / 0x100000000000000000000000000000000; } } - function getUnderlyingBalances() - external - view - returns (uint256 amount0Current, uint256 amount1Current) - { + function getUnderlyingBalances() external view returns (uint256 amount0Current, uint256 amount1Current) { IGUniPool gUniPool = vault.arrakisVault(); - (uint160 sqrtRatioX96, , , , , , ) = gUniPool.pool().slot0(); - (uint128 liquidity, , , , ) = gUniPool.pool().positions( - gUniPool.getPositionID() - ); + (uint160 sqrtRatioX96,,,,,,) = gUniPool.pool().slot0(); + (uint128 liquidity,,,,) = gUniPool.pool().positions(gUniPool.getPositionID()); // compute current holdings from liquidity - (amount0Current, amount1Current) = LiquidityAmounts - .getAmountsForLiquidity( - sqrtRatioX96, - gUniPool.lowerTick().getSqrtRatioAtTick(), - gUniPool.upperTick().getSqrtRatioAtTick(), - liquidity - ); + (amount0Current, amount1Current) = LiquidityAmounts.getAmountsForLiquidity( + sqrtRatioX96, + gUniPool.lowerTick().getSqrtRatioAtTick(), + gUniPool.upperTick().getSqrtRatioAtTick(), + liquidity + ); } - function uniswapV3SwapCallback( - int256 amount0Delta, - int256 amount1Delta, - bytes calldata /*data*/ - ) external { + function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata /*data*/ ) external { IGUniPool gUniPool = vault.arrakisVault(); require(msg.sender == address(gUniPool.pool()), "callback caller"); - if (amount0Delta > 0) - ERC20(address(gUniPool.token0())).safeTransfer( - msg.sender, - uint256(amount0Delta) - ); - else if (amount1Delta > 0) - ERC20(address(gUniPool.token1())).safeTransfer( - msg.sender, - uint256(amount1Delta) - ); + if (amount0Delta > 0) { + ERC20(address(gUniPool.token0())).safeTransfer(msg.sender, uint256(amount0Delta)); + } else if (amount1Delta > 0) { + ERC20(address(gUniPool.token1())).safeTransfer(msg.sender, uint256(amount1Delta)); + } } - function swap(uint256 amtIn, address[] memory path) - internal - returns (uint256) - { + function swap(uint256 amtIn, address[] memory path) internal returns (uint256) { ERC20(path[0]).approve(address(joeRouter), amtIn); - uint256[] memory amts = joeRouter.swapExactTokensForTokens( - amtIn, - 0, - path, - address(this), - block.timestamp + 1 - ); + uint256[] memory amts = joeRouter.swapExactTokensForTokens(amtIn, 0, path, address(this), block.timestamp + 1); return amts[amts.length - 1]; } function testDepositWithToken0AsAssetSuccess() public { vault = arrakisNonNativeVault; blah = true; - uint256 amt = 300000e18; + uint256 amt = 300_000e18; getWMATIC(amt); amt = 2000e18; @@ -238,15 +197,13 @@ contract Arrakis_LP_Test is Test { this.computeFeesAccrued(); emit log_named_uint("deposited amount:", 2000e18); - uint256 sharesReceived = arrakisNonNativeVault.deposit( - amt, - address(this) - ); + uint256 sharesReceived = arrakisNonNativeVault.deposit(amt, address(this)); console.log("Underlying balance :", vault.totalAssets()); - /// @dev we simulate the swaps on the same pool we are adding liquidity to, so we can get the fees accrued and test the reinvest. + /// @dev we simulate the swaps on the same pool we are adding liquidity to, so we can get the fees accrued and + /// test the reinvest. console.log("Starting swap simulation on uniswap...."); uint256 countLoop = 2; - ERC20(address(WMATIC)).transfer(address(this), 298000e18); + ERC20(address(WMATIC)).transfer(address(this), 298_000e18); while (countLoop > 0) { this.paramswap(); countLoop--; @@ -254,30 +211,21 @@ contract Arrakis_LP_Test is Test { console.log("swap simulation on uniswap stopped!"); this.computeFeesAccrued(); - uint256 returnAssets = arrakisNonNativeVault.redeem( - sharesReceived, - address(this), - address(this) - ); + uint256 returnAssets = arrakisNonNativeVault.redeem(sharesReceived, address(this), address(this)); console.log("Underlying balance :", vault.totalAssets()); emit log_named_decimal_uint( - "amount gained through out the duration in the form of deposited Asset", - returnAssets, - 18 + "amount gained through out the duration in the form of deposited Asset", returnAssets, 18 ); } function testMintWithToken0AsAssetSuccess() public { vault = arrakisNonNativeVault; blah = true; - uint256 amt = 300000e18; + uint256 amt = 300_000e18; getWMATIC(amt); amt = 2000e18; - ERC20(address(WMATIC)).approve( - address(arrakisNonNativeVault), - type(uint256).max - ); + ERC20(address(WMATIC)).approve(address(arrakisNonNativeVault), type(uint256).max); this.computeFeesAccrued(); emit log_named_uint("deposited amount:", 2000e18); @@ -286,7 +234,7 @@ contract Arrakis_LP_Test is Test { console.log("Underlying balance :", vault.totalAssets()); console.log("Starting swap simulation on uniswap...."); uint256 countLoop = 2; - ERC20(address(WMATIC)).transfer(address(this), 298000e18); + ERC20(address(WMATIC)).transfer(address(this), 298_000e18); while (countLoop > 0) { this.paramswap(); countLoop--; @@ -294,23 +242,17 @@ contract Arrakis_LP_Test is Test { console.log("swap simulation on uniswap stopped!"); this.computeFeesAccrued(); - uint256 returnAssets = arrakisNonNativeVault.withdraw( - vault.totalAssets() - 1e19, - address(this), - address(this) - ); + uint256 returnAssets = arrakisNonNativeVault.withdraw(vault.totalAssets() - 1e19, address(this), address(this)); console.log("Underlying balance :", vault.totalAssets()); emit log_named_decimal_uint( - "amount gained through out the duration in the form of deposited Asset", - returnAssets, - 18 + "amount gained through out the duration in the form of deposited Asset", returnAssets, 18 ); } function testDepositWithToken1AsAssetSuccess() public { vault = arrakisToken1AsAssetVault; blah = false; - uint256 amt = 300000e18; + uint256 amt = 300_000e18; // get 2000 WMATIC to user getWMATIC(amt); // swap for WBTC @@ -318,25 +260,16 @@ contract Arrakis_LP_Test is Test { path[0] = address(WMATIC); path[1] = USDC; uint256 amountUSDC = swap(amt, path); - ERC20(address(USDC)).approve( - address(arrakisToken1AsAssetVault), - amountUSDC - ); + ERC20(address(USDC)).approve(address(arrakisToken1AsAssetVault), amountUSDC); this.computeFeesAccrued(); - emit log_named_uint("deposited amount:", 2000 * (10**6)); + emit log_named_uint("deposited amount:", 2000 * (10 ** 6)); - uint256 sharesReceived = arrakisToken1AsAssetVault.deposit( - 2000 * (10**6), - address(this) - ); + uint256 sharesReceived = arrakisToken1AsAssetVault.deposit(2000 * (10 ** 6), address(this)); console.log("Underlying balance :", vault.totalAssets()); console.log("Shares received:", sharesReceived); console.log("Starting swap simulation on uniswap...."); uint256 countLoop = 2; - ERC20(address(USDC)).transfer( - address(this), - ERC20(address(USDC)).balanceOf(address(this)) - ); + ERC20(address(USDC)).transfer(address(this), ERC20(address(USDC)).balanceOf(address(this))); while (countLoop > 0) { this.paramswap(); countLoop--; @@ -344,18 +277,12 @@ contract Arrakis_LP_Test is Test { console.log("swap simulation on uniswap stopped!"); this.computeFeesAccrued(); - uint256 returnAssets = arrakisToken1AsAssetVault.redeem( - sharesReceived, - address(this), - address(this) - ); + uint256 returnAssets = arrakisToken1AsAssetVault.redeem(sharesReceived, address(this), address(this)); console.log("Underlying balance :", vault.totalAssets()); emit log_named_decimal_uint( - "amount gained through out the duration in the form of deposited Asset", - returnAssets, - 6 + "amount gained through out the duration in the form of deposited Asset", returnAssets, 6 ); } - receive() external payable {} + receive() external payable { } } diff --git a/src/arrakis/utils/FullMath.sol b/src/arrakis/utils/FullMath.sol index 969f8aa..5446c12 100644 --- a/src/arrakis/utils/FullMath.sol +++ b/src/arrakis/utils/FullMath.sol @@ -2,20 +2,19 @@ pragma solidity >=0.8.10; /// @title Contains 512-bit math functions -/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision -/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits +/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of +/// precision +/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 +/// bits library FullMath { - /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 + /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or + /// denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv - function mulDiv( - uint256 a, - uint256 b, - uint256 denominator - ) internal pure returns (uint256 result) { + function mulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = a * b // Compute the product mod 2**256 and mod 2**256 - 1 @@ -110,16 +109,13 @@ library FullMath { } } - /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 + /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or + /// denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result - function mulDivRoundingUp( - uint256 a, - uint256 b, - uint256 denominator - ) internal pure returns (uint256 result) { + function mulDivRoundingUp(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) { result = mulDiv(a, b, denominator); if (mulmod(a, b, denominator) > 0) { require(result < type(uint256).max); diff --git a/src/arrakis/utils/IGUniPool.sol b/src/arrakis/utils/IGUniPool.sol index 245abb5..040ab65 100644 --- a/src/arrakis/utils/IGUniPool.sol +++ b/src/arrakis/utils/IGUniPool.sol @@ -1,42 +1,34 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.8.10; -import {ERC20} from "solmate/tokens/ERC20.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; -import { - IUniswapV3Pool -} from "v3-core/interfaces/IUniswapV3Pool.sol"; +import { IUniswapV3Pool } from "v3-core/interfaces/IUniswapV3Pool.sol"; interface IGUniPool { - function mint(uint256 mintAmount, address receiver) + function mint( + uint256 mintAmount, + address receiver + ) external - returns ( - uint256 amount0, - uint256 amount1, - uint128 liquidityMinted - ); + returns (uint256 amount0, uint256 amount1, uint128 liquidityMinted); - function burn(uint256 burnAmount, address receiver) + function burn( + uint256 burnAmount, + address receiver + ) external - returns ( - uint256 amount0, - uint256 amount1, - uint128 liquidityBurned - ); + returns (uint256 amount0, uint256 amount1, uint128 liquidityBurned); - function getMintAmounts(uint256 amount0Max, uint256 amount1Max) + function getMintAmounts( + uint256 amount0Max, + uint256 amount1Max + ) external view - returns ( - uint256 amount0, - uint256 amount1, - uint256 mintAmount - ); + returns (uint256 amount0, uint256 amount1, uint256 mintAmount); - function getUnderlyingBalances() - external - view - returns (uint256 amount0, uint256 amount1); + function getUnderlyingBalances() external view returns (uint256 amount0, uint256 amount1); function getPositionID() external view returns (bytes32 positionID); @@ -54,5 +46,5 @@ interface IGUniPool { function balanceOf(address account) external view returns (uint256); - function restrictedMintToggle() external view returns(uint16); + function restrictedMintToggle() external view returns (uint16); } diff --git a/src/arrakis/utils/LiquidityAmounts.sol b/src/arrakis/utils/LiquidityAmounts.sol index ae019e2..51de716 100644 --- a/src/arrakis/utils/LiquidityAmounts.sol +++ b/src/arrakis/utils/LiquidityAmounts.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.5.0; -import {FullMath} from "./FullMath.sol"; +import { FullMath } from "./FullMath.sol"; import "v3-core/libraries/FixedPoint96.sol"; /// @title Liquidity amount functions @@ -21,19 +21,16 @@ library LiquidityAmounts { uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0 - ) internal pure returns (uint128 liquidity) { - if (sqrtRatioAX96 > sqrtRatioBX96) + ) + internal + pure + returns (uint128 liquidity) + { + if (sqrtRatioAX96 > sqrtRatioBX96) { (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); - uint256 intermediate = - FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96); - return - toUint128( - FullMath.mulDiv( - amount0, - intermediate, - sqrtRatioBX96 - sqrtRatioAX96 - ) - ); + } + uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96); + return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96)); } /// @notice Computes the amount of liquidity received for a given amount of token1 and price range @@ -46,17 +43,15 @@ library LiquidityAmounts { uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount1 - ) internal pure returns (uint128 liquidity) { - if (sqrtRatioAX96 > sqrtRatioBX96) + ) + internal + pure + returns (uint128 liquidity) + { + if (sqrtRatioAX96 > sqrtRatioBX96) { (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); - return - toUint128( - FullMath.mulDiv( - amount1, - FixedPoint96.Q96, - sqrtRatioBX96 - sqrtRatioAX96 - ) - ); + } + return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96)); } /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current @@ -67,29 +62,24 @@ library LiquidityAmounts { uint160 sqrtRatioBX96, uint256 amount0, uint256 amount1 - ) internal pure returns (uint128 liquidity) { - if (sqrtRatioAX96 > sqrtRatioBX96) + ) + internal + pure + returns (uint128 liquidity) + { + if (sqrtRatioAX96 > sqrtRatioBX96) { (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); + } if (sqrtRatioX96 <= sqrtRatioAX96) { - liquidity = getLiquidityForAmount0( - sqrtRatioAX96, - sqrtRatioBX96, - amount0 - ); + liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0); } else if (sqrtRatioX96 < sqrtRatioBX96) { - uint128 liquidity0 = - getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0); - uint128 liquidity1 = - getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1); + uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0); + uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1); liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1; } else { - liquidity = getLiquidityForAmount1( - sqrtRatioAX96, - sqrtRatioBX96, - amount1 - ); + liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1); } } @@ -102,16 +92,18 @@ library LiquidityAmounts { uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity - ) internal pure returns (uint256 amount0) { - if (sqrtRatioAX96 > sqrtRatioBX96) + ) + internal + pure + returns (uint256 amount0) + { + if (sqrtRatioAX96 > sqrtRatioBX96) { (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); + } - return - FullMath.mulDiv( - uint256(liquidity) << FixedPoint96.RESOLUTION, - sqrtRatioBX96 - sqrtRatioAX96, - sqrtRatioBX96 - ) / sqrtRatioAX96; + return FullMath.mulDiv( + uint256(liquidity) << FixedPoint96.RESOLUTION, sqrtRatioBX96 - sqrtRatioAX96, sqrtRatioBX96 + ) / sqrtRatioAX96; } /// @notice Computes the amount of token1 for a given amount of liquidity and a price range @@ -123,16 +115,16 @@ library LiquidityAmounts { uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity - ) internal pure returns (uint256 amount1) { - if (sqrtRatioAX96 > sqrtRatioBX96) + ) + internal + pure + returns (uint256 amount1) + { + if (sqrtRatioAX96 > sqrtRatioBX96) { (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); + } - return - FullMath.mulDiv( - liquidity, - sqrtRatioBX96 - sqrtRatioAX96, - FixedPoint96.Q96 - ); + return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96); } /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current @@ -142,33 +134,22 @@ library LiquidityAmounts { uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity - ) internal pure returns (uint256 amount0, uint256 amount1) { - if (sqrtRatioAX96 > sqrtRatioBX96) + ) + internal + pure + returns (uint256 amount0, uint256 amount1) + { + if (sqrtRatioAX96 > sqrtRatioBX96) { (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); + } if (sqrtRatioX96 <= sqrtRatioAX96) { - amount0 = getAmount0ForLiquidity( - sqrtRatioAX96, - sqrtRatioBX96, - liquidity - ); + amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } else if (sqrtRatioX96 < sqrtRatioBX96) { - amount0 = getAmount0ForLiquidity( - sqrtRatioX96, - sqrtRatioBX96, - liquidity - ); - amount1 = getAmount1ForLiquidity( - sqrtRatioAX96, - sqrtRatioX96, - liquidity - ); + amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity); + amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity); } else { - amount1 = getAmount1ForLiquidity( - sqrtRatioAX96, - sqrtRatioBX96, - liquidity - ); + amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } } } diff --git a/src/arrakis/utils/TickMath.sol b/src/arrakis/utils/TickMath.sol index 320f241..a14e4d0 100644 --- a/src/arrakis/utils/TickMath.sol +++ b/src/arrakis/utils/TickMath.sol @@ -6,83 +6,92 @@ pragma solidity >=0.8.10; /// prices between 2**-128 and 2**128 library TickMath { /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128 - int24 internal constant MIN_TICK = -887272; + int24 internal constant MIN_TICK = -887_272; /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128 int24 internal constant MAX_TICK = -MIN_TICK; /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK) - uint160 internal constant MIN_SQRT_RATIO = 4295128739; + uint160 internal constant MIN_SQRT_RATIO = 4_295_128_739; /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK) - uint160 internal constant MAX_SQRT_RATIO = - 1461446703485210103287273052203988822378723970342; + uint160 internal constant MAX_SQRT_RATIO = 1_461_446_703_485_210_103_287_273_052_203_988_822_378_723_970_342; /// @notice Calculates sqrt(1.0001^tick) * 2^96 /// @dev Throws if |tick| > max tick /// @param tick The input tick for the above formula - /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0) + /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets + /// (token1/token0) /// at the given tick - function getSqrtRatioAtTick(int24 tick) - internal - pure - returns (uint160 sqrtPriceX96) - { - uint256 absTick = - tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick)); + function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) { + uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick)); // EDIT: 0.8 compatibility require(absTick <= uint256(int256(MAX_TICK)), "T"); - uint256 ratio = - absTick & 0x1 != 0 - ? 0xfffcb933bd6fad37aa2d162d1a594001 - : 0x100000000000000000000000000000000; - if (absTick & 0x2 != 0) + uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000; + if (absTick & 0x2 != 0) { ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128; - if (absTick & 0x4 != 0) + } + if (absTick & 0x4 != 0) { ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128; - if (absTick & 0x8 != 0) + } + if (absTick & 0x8 != 0) { ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128; - if (absTick & 0x10 != 0) + } + if (absTick & 0x10 != 0) { ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128; - if (absTick & 0x20 != 0) + } + if (absTick & 0x20 != 0) { ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128; - if (absTick & 0x40 != 0) + } + if (absTick & 0x40 != 0) { ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128; - if (absTick & 0x80 != 0) + } + if (absTick & 0x80 != 0) { ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128; - if (absTick & 0x100 != 0) + } + if (absTick & 0x100 != 0) { ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128; - if (absTick & 0x200 != 0) + } + if (absTick & 0x200 != 0) { ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128; - if (absTick & 0x400 != 0) + } + if (absTick & 0x400 != 0) { ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128; - if (absTick & 0x800 != 0) + } + if (absTick & 0x800 != 0) { ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128; - if (absTick & 0x1000 != 0) + } + if (absTick & 0x1000 != 0) { ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128; - if (absTick & 0x2000 != 0) + } + if (absTick & 0x2000 != 0) { ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128; - if (absTick & 0x4000 != 0) + } + if (absTick & 0x4000 != 0) { ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128; - if (absTick & 0x8000 != 0) + } + if (absTick & 0x8000 != 0) { ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128; - if (absTick & 0x10000 != 0) + } + if (absTick & 0x10000 != 0) { ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128; - if (absTick & 0x20000 != 0) + } + if (absTick & 0x20000 != 0) { ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128; - if (absTick & 0x40000 != 0) + } + if (absTick & 0x40000 != 0) { ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128; - if (absTick & 0x80000 != 0) + } + if (absTick & 0x80000 != 0) { ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128; + } if (tick > 0) ratio = type(uint256).max / ratio; // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96. // we then downcast because we know the result always fits within 160 bits due to our tick input constraint // we round up in the division so getTickAtSqrtRatio of the output price is always consistent - sqrtPriceX96 = uint160( - (ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1) - ); + sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1)); } /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio @@ -90,16 +99,9 @@ library TickMath { /// ever return. /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96 /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio - function getTickAtSqrtRatio(uint160 sqrtPriceX96) - internal - pure - returns (int24 tick) - { + function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) { // second inequality must be < because the price can never reach the price at the max tick - require( - sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, - "R" - ); + require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, "R"); uint256 ratio = uint256(sqrtPriceX96) << 32; uint256 r = ratio; @@ -234,21 +236,11 @@ library TickMath { log_2 := or(log_2, shl(50, f)) } - int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number + int256 log_sqrt10001 = log_2 * 255_738_958_999_603_826_347_141; // 128.128 number - int24 tickLow = - int24( - (log_sqrt10001 - 3402992956809132418596140100660247210) >> 128 - ); - int24 tickHi = - int24( - (log_sqrt10001 + 291339464771989622907027621153398088495) >> 128 - ); + int24 tickLow = int24((log_sqrt10001 - 3_402_992_956_809_132_418_596_140_100_660_247_210) >> 128); + int24 tickHi = int24((log_sqrt10001 + 291_339_464_771_989_622_907_027_621_153_398_088_495) >> 128); - tick = tickLow == tickHi - ? tickLow - : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 - ? tickHi - : tickLow; + tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow; } } diff --git a/src/arrakis/utils/Utilities.sol b/src/arrakis/utils/Utilities.sol index 18c0ed9..75b3e32 100644 --- a/src/arrakis/utils/Utilities.sol +++ b/src/arrakis/utils/Utilities.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: Unlicense pragma solidity >=0.8.0; -import {DSTest} from "ds-test/test.sol"; -import {Vm} from "forge-std/Vm.sol"; +import { DSTest } from "ds-test/test.sol"; +import { Vm } from "forge-std/Vm.sol"; //common utilities for forge tests contract Utilities is DSTest { @@ -17,10 +17,7 @@ contract Utilities is DSTest { } //create users with 100 ether balance - function createUsers(uint256 userNum) - external - returns (address payable[] memory) - { + function createUsers(uint256 userNum) external returns (address payable[] memory) { address payable[] memory users = new address payable[](userNum); for (uint256 i = 0; i < userNum; i++) { address payable user = this.getNextUserAddress(); @@ -35,4 +32,4 @@ contract Utilities is DSTest { uint256 targetBlock = block.number + numBlocks; vm.roll(targetBlock); } -} \ No newline at end of file +} diff --git a/src/benqi/BenqiERC4626Reinvest.sol b/src/benqi/BenqiERC4626Reinvest.sol index 1d326d4..b14a535 100644 --- a/src/benqi/BenqiERC4626Reinvest.sol +++ b/src/benqi/BenqiERC4626Reinvest.sol @@ -1,16 +1,16 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {IBERC20} from "./external/IBERC20.sol"; -import {LibBCompound} from "./external/LibBCompound.sol"; -import {IBComptroller} from "./external/IBComptroller.sol"; +import { IBERC20 } from "./external/IBERC20.sol"; +import { LibBCompound } from "./external/LibBCompound.sol"; +import { IBComptroller } from "./external/IBComptroller.sol"; -import {DexSwap} from "../_global/swapUtils.sol"; +import { DexSwap } from "../_global/swapUtils.sol"; /// @title BenqiERC4626Reinvest /// @notice Custom implementation of yield-daddy Compound wrapper with flexible reinvesting logic @@ -86,7 +86,12 @@ contract BenqiERC4626Reinvest is ERC4626 { /// @dev cToken_ is the Compound cToken contract /// @dev comptroller_ is the Compound comptroller contract /// @dev manager_ is the address that can set swap routes - constructor(ERC20 asset_, IBERC20 cToken_, IBComptroller comptroller_, address manager_) + constructor( + ERC20 asset_, + IBERC20 cToken_, + IBComptroller comptroller_, + address manager_ + ) ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) { cToken = cToken_; @@ -102,7 +107,13 @@ contract BenqiERC4626Reinvest is ERC4626 { /// @notice Set type of reward we are harvesting and selling /// @dev 0 = BenqiToken, 1 = AVAX /// @dev Setting wrong addresses here will revert harvest() calls - function setRoute(uint8 rewardType_, address rewardToken_, address token_, address pair1_, address pair2_) + function setRoute( + uint8 rewardType_, + address rewardToken_, + address token_, + address pair1_, + address pair2_ + ) external { if (msg.sender != manager) revert INVALID_ACCESS(); diff --git a/src/benqi/BenqiERC4626Staking.sol b/src/benqi/BenqiERC4626Staking.sol index 3bd2af3..ffd1574 100644 --- a/src/benqi/BenqiERC4626Staking.sol +++ b/src/benqi/BenqiERC4626Staking.sol @@ -1,19 +1,21 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; -import {IPair, DexSwap} from "../_global/swapUtils.sol"; -import {IStakedAvax} from "./interfaces/IStakedAvax.sol"; -import {IWETH} from "../lido/interfaces/IWETH.sol"; +import { IPair, DexSwap } from "../_global/swapUtils.sol"; +import { IStakedAvax } from "./interfaces/IStakedAvax.sol"; +import { IWETH } from "../lido/interfaces/IWETH.sol"; /// @title BenqiERC4626Staking /// @notice Accepts WAVAX to deposit into Benqi's staking contract - sAVAX, provides ERC4626 interface over token -/// @notice Withdraw/Redeem to AVAX is not a part of this base contract. Withdraw/Redeem is only possible to sAVAX token. -/// @notice Two possible ways of extending this contract: https://docs.benqi.fi/benqi-liquid-staking/staking-and-unstaking +/// @notice Withdraw/Redeem to AVAX is not a part of this base contract. Withdraw/Redeem is only possible to sAVAX +/// token. +/// @notice Two possible ways of extending this contract: +/// https://docs.benqi.fi/benqi-liquid-staking/staking-and-unstaking /// @notice In contrast to Lido's stETH, sAVAX can be Unstaked with 15d cooldown period. /// @author ZeroPoint Labs contract BenqiERC4626Staking is ERC4626 { @@ -47,7 +49,10 @@ contract BenqiERC4626Staking is ERC4626 { /// @param wavax_ wavax address (Vault's underlying / deposit token) /// @param sAvax_ sAVAX (Benqi staking contract) address - constructor(address wavax_, address sAvax_) + constructor( + address wavax_, + address sAvax_ + ) // address tradeJoePool_ ERC4626(ERC20(wavax_), "ERC4626-Wrapped sAVAX", "wLsAVAX") { @@ -56,14 +61,14 @@ contract BenqiERC4626Staking is ERC4626 { wavax = IWETH(wavax_); } - receive() external payable {} + receive() external payable { } /*////////////////////////////////////////////////////////////// INTERNAL HOOKS LOGIC //////////////////////////////////////////////////////////////*/ function _addLiquidity(uint256 wAvaxAmt_, uint256) internal returns (uint256 sAvaxAmt) { - sAvaxAmt = sAVAX.submit{value: wAvaxAmt_}(); + sAvaxAmt = sAVAX.submit{ value: wAvaxAmt_ }(); } /*////////////////////////////////////////////////////////////// @@ -115,7 +120,8 @@ contract BenqiERC4626Staking is ERC4626 { /// @notice Withdraw amount of ETH represented by stEth / ERC4626-stEth. Output token is stEth. function withdraw(uint256 assets_, address receiver_, address owner_) public override returns (uint256 shares) { - /// @dev In base implementation, previeWithdraw allows to get sAvax amount to withdraw for virtual amount from convertToAssets + /// @dev In base implementation, previeWithdraw allows to get sAvax amount to withdraw for virtual amount from + /// convertToAssets shares = previewWithdraw(assets_); if (msg.sender != owner_) { diff --git a/src/benqi/BenqiNativeERC4626Reinvest.sol b/src/benqi/BenqiNativeERC4626Reinvest.sol index 868783f..6e3360c 100644 --- a/src/benqi/BenqiNativeERC4626Reinvest.sol +++ b/src/benqi/BenqiNativeERC4626Reinvest.sol @@ -1,17 +1,17 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {IBEther} from "./external/IBEther.sol"; -import {LibBCompound} from "./external/LibBCompound.sol"; -import {IBComptroller} from "./external/IBComptroller.sol"; +import { IBEther } from "./external/IBEther.sol"; +import { LibBCompound } from "./external/LibBCompound.sol"; +import { IBComptroller } from "./external/IBComptroller.sol"; -import {DexSwap} from "../_global/swapUtils.sol"; -import {WrappedNative} from "./utils/wrappedNative.sol"; +import { DexSwap } from "../_global/swapUtils.sol"; +import { WrappedNative } from "./utils/wrappedNative.sol"; /// @title BenqiNativeERC4626Reinvest /// @notice Custom implementation of yield-daddy Compound wrapper with flexible reinvesting logic @@ -98,7 +98,12 @@ contract BenqiNativeERC4626Reinvest is ERC4626 { /// @dev reward_ is the COMP-like token /// @dev cEther_ is the Compound concept of a share /// @dev manager_ is the address that can set swap routes - constructor(ERC20 asset_, ERC20 reward_, IBEther cEther_, address manager_) + constructor( + ERC20 asset_, + ERC20 reward_, + IBEther cEther_, + address manager_ + ) ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) { reward = reward_; @@ -116,7 +121,13 @@ contract BenqiNativeERC4626Reinvest is ERC4626 { /// @notice Set type of reward we are harvesting and selling /// @dev 0 = BenqiToken, 1 = AVAX /// @dev Setting wrong addresses here will revert harvest() calls - function setRoute(uint8 rewardType_, address rewardToken_, address token_, address pair1_, address pair2_) + function setRoute( + uint8 rewardType_, + address rewardToken_, + address token_, + address pair1_, + address pair2_ + ) external { if (msg.sender != manager) revert INVALID_ACCESS(); @@ -202,12 +213,12 @@ contract BenqiNativeERC4626Reinvest is ERC4626 { /// @notice "Regular" ERC20 deposit for WAVAX function afterDeposit(uint256 assets_, uint256) internal override { wavax.withdraw(assets_); - cEther.mint{value: assets_}(); + cEther.mint{ value: assets_ }(); } /// @notice "Payable" afterDeposit for special case when we deposit native token function afterDeposit(uint256 avaxAmt_) internal { - cEther.mint{value: avaxAmt_}(); + cEther.mint{ value: avaxAmt_ }(); } /// @notice Accept native token (AVAX) for deposit. Non-ERC4626 function. @@ -297,7 +308,7 @@ contract BenqiNativeERC4626Reinvest is ERC4626 { emit Withdraw(msg.sender, receiver_, owner_, assets_, shares); /// @dev Output token is WAVAX, same as input token (consitency vs gas cost) - wavax.deposit{value: assets_}(); + wavax.deposit{ value: assets_ }(); asset.safeTransfer(receiver_, assets_); } @@ -321,12 +332,12 @@ contract BenqiNativeERC4626Reinvest is ERC4626 { emit Withdraw(msg.sender, receiver_, owner_, assets, shares_); /// @dev Output token is WAVAX, same as input token (consitency vs gas cost) - wavax.deposit{value: assets}(); + wavax.deposit{ value: assets }(); asset.safeTransfer(receiver_, assets); } - receive() external payable {} + receive() external payable { } /*////////////////////////////////////////////////////////////// ERC20 METADATA diff --git a/src/benqi/external/IBERC20.sol b/src/benqi/external/IBERC20.sol index 5742953..7044643 100644 --- a/src/benqi/external/IBERC20.sol +++ b/src/benqi/external/IBERC20.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; -import {IBInterestRateModel} from "./IBInterestRateModel.sol"; +import { IBInterestRateModel } from "./IBInterestRateModel.sol"; abstract contract IBERC20 is ERC20 { function mint(uint256 underlyingAmount) external virtual returns (uint256); diff --git a/src/benqi/external/IBEther.sol b/src/benqi/external/IBEther.sol index ae651db..ee567fb 100644 --- a/src/benqi/external/IBEther.sol +++ b/src/benqi/external/IBEther.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; abstract contract IBEther is ERC20 { function comptroller() external view virtual returns (address); diff --git a/src/benqi/external/LibBCompound.sol b/src/benqi/external/LibBCompound.sol index ff8189f..59ffe43 100644 --- a/src/benqi/external/LibBCompound.sol +++ b/src/benqi/external/LibBCompound.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {IBERC20} from "./IBERC20.sol"; +import { IBERC20 } from "./IBERC20.sol"; /// @notice Get up to date cToken data without mutating state. /// @notice Forked from Transmissions11 (https://github.com/transmissions11/libcompound) to upgrade version @@ -30,7 +30,8 @@ library LibBCompound { uint256 borrowRateMantissa = cToken.interestRateModel().getBorrowRate(totalCash, borrowsPrior, reservesPrior); - if (borrowRateMantissa > 0.0005e16) revert RATE_TOO_HIGH(); // Same as borrowRateMaxMantissa in CTokenInterfaces.sol + if (borrowRateMantissa > 0.0005e16) revert RATE_TOO_HIGH(); // Same as borrowRateMaxMantissa in + // CTokenInterfaces.sol uint256 interestAccumulated = (borrowRateMantissa * (block.number - accrualBlockNumberPrior)).mulWadDown(borrowsPrior); diff --git a/src/benqi/test/BenqiERC4626Reinvest.t.sol b/src/benqi/test/BenqiERC4626Reinvest.t.sol index d7cf11d..212a415 100644 --- a/src/benqi/test/BenqiERC4626Reinvest.t.sol +++ b/src/benqi/test/BenqiERC4626Reinvest.t.sol @@ -2,12 +2,12 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; -import {BenqiERC4626Reinvest} from "../BenqiERC4626Reinvest.sol"; +import { BenqiERC4626Reinvest } from "../BenqiERC4626Reinvest.sol"; -import {IBERC20} from "../external/IBERC20.sol"; -import {IBComptroller} from "../external/IBComptroller.sol"; +import { IBERC20 } from "../external/IBERC20.sol"; +import { IBComptroller } from "../external/IBComptroller.sol"; contract BenqiERC4626ReinvestTest is Test { address public manager; @@ -55,8 +55,8 @@ contract BenqiERC4626ReinvestTest is Test { alice = address(0x1); bob = address(0x2); - deal(address(asset), alice, 100000000 ether); - deal(address(asset), bob, 100000000 ether); + deal(address(asset), alice, 100_000_000 ether); + deal(address(asset), bob, 100_000_000 ether); /// @dev Making contracts persistent vm.makePersistent(address(comptroller)); @@ -90,7 +90,7 @@ contract BenqiERC4626ReinvestTest is Test { } function testDepositWithdraw() public { - uint256 amount = 1000000 ether; + uint256 amount = 1_000_000 ether; vm.startPrank(alice); uint256 aliceUnderlyingAmount = amount; @@ -115,7 +115,7 @@ contract BenqiERC4626ReinvestTest is Test { /// @dev Contracts require a careful selection of blocks to roll function testHarvest() public { - uint256 amount = 10000 ether; + uint256 amount = 10_000 ether; ////////////////////////////////////////////////////////////// diff --git a/src/benqi/test/BenqiERC4626Staking.t.sol b/src/benqi/test/BenqiERC4626Staking.t.sol index 26b04a4..5b5754d 100644 --- a/src/benqi/test/BenqiERC4626Staking.t.sol +++ b/src/benqi/test/BenqiERC4626Staking.t.sol @@ -3,12 +3,12 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; import "forge-std/console.sol"; -import {BenqiERC4626Staking} from "../BenqiERC4626Staking.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { BenqiERC4626Staking } from "../BenqiERC4626Staking.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {IPair, DexSwap} from "../../_global/swapUtils.sol"; -import {IStETH} from "../../lido/interfaces/IStETH.sol"; -import {IWETH} from "../../lido/interfaces/IWETH.sol"; +import { IPair, DexSwap } from "../../_global/swapUtils.sol"; +import { IStETH } from "../../lido/interfaces/IStETH.sol"; +import { IWETH } from "../../lido/interfaces/IWETH.sol"; contract BenqiERC4626StakingTest is Test { uint256 public ethFork; @@ -139,7 +139,7 @@ contract BenqiERC4626StakingTest is Test { startHoax(alice, aliceEth + 1 ether); uint256 expectedSharesFromAsset = vault.convertToShares(aliceEth); - uint256 aliceShareAmount = vault.deposit{value: aliceEth}(alice); + uint256 aliceShareAmount = vault.deposit{ value: aliceEth }(alice); assertEq(expectedSharesFromAsset, aliceShareAmount); } } diff --git a/src/benqi/test/BenqiNativeERC4626Reinvest.t.sol b/src/benqi/test/BenqiNativeERC4626Reinvest.t.sol index 4c16346..4e57bdc 100644 --- a/src/benqi/test/BenqiNativeERC4626Reinvest.t.sol +++ b/src/benqi/test/BenqiNativeERC4626Reinvest.t.sol @@ -2,12 +2,12 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; -import {BenqiNativeERC4626Reinvest} from "../BenqiNativeERC4626Reinvest.sol"; +import { BenqiNativeERC4626Reinvest } from "../BenqiNativeERC4626Reinvest.sol"; -import {IBEther} from "../external/IBEther.sol"; -import {IBComptroller} from "../external/IBComptroller.sol"; +import { IBEther } from "../external/IBEther.sol"; +import { IBComptroller } from "../external/IBComptroller.sol"; contract BenqiNativeERC4626ReinvestTest is Test { address public manager; @@ -30,7 +30,7 @@ contract BenqiNativeERC4626ReinvestTest is Test { constructor() { avaxFork = vm.createFork(AVAX_RPC_URL); vm.selectFork(avaxFork); - vm.roll(12649496); + vm.roll(12_649_496); manager = msg.sender; comptroller = IBComptroller(vm.envAddress("BENQI_COMPTROLLER")); @@ -50,8 +50,8 @@ contract BenqiNativeERC4626ReinvestTest is Test { alice = address(0x1); bob = address(0x2); hoax(alice, 1000 ether); - deal(address(asset), alice, 100000000 ether); - deal(address(asset), bob, 100000000 ether); + deal(address(asset), alice, 100_000_000 ether); + deal(address(asset), bob, 100_000_000 ether); } function setVault(ERC20 underylyingAsset, ERC20 reward_, IBEther cToken_) public { @@ -72,7 +72,7 @@ contract BenqiNativeERC4626ReinvestTest is Test { } function testDepositWithdraw() public { - uint256 amount = 1000000 ether; + uint256 amount = 1_000_000 ether; vm.startPrank(alice); uint256 aliceUnderlyingAmount = amount; @@ -101,7 +101,7 @@ contract BenqiNativeERC4626ReinvestTest is Test { vm.prank(alice); uint256 aliceUnderlyingAmount = amount; - uint256 aliceShareAmount = vault.deposit{value: aliceUnderlyingAmount}(alice); + uint256 aliceShareAmount = vault.deposit{ value: aliceUnderlyingAmount }(alice); uint256 aliceAssetsToWithdraw = vault.convertToAssets(aliceShareAmount); assertEq(aliceUnderlyingAmount, aliceShareAmount); diff --git a/src/compound/CompoundV2ERC4626Wrapper.sol b/src/compound/CompoundV2ERC4626Wrapper.sol index 91ee4b2..76e8a5a 100644 --- a/src/compound/CompoundV2ERC4626Wrapper.sol +++ b/src/compound/CompoundV2ERC4626Wrapper.sol @@ -1,16 +1,16 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {ICERC20} from "./external/ICERC20.sol"; -import {LibCompound} from "./external/LibCompound.sol"; -import {IComptroller} from "./external/IComptroller.sol"; -import {ISwapRouter} from "../aave-v2/utils/ISwapRouter.sol"; -import {DexSwap} from "../_global/swapUtils.sol"; +import { ICERC20 } from "./external/ICERC20.sol"; +import { LibCompound } from "./external/LibCompound.sol"; +import { IComptroller } from "./external/IComptroller.sol"; +import { ISwapRouter } from "../aave-v2/utils/ISwapRouter.sol"; +import { DexSwap } from "../_global/swapUtils.sol"; /// @title CompoundV2ERC4626Wrapper /// @notice Custom implementation of yield-daddy wrappers with flexible reinvesting logic @@ -90,7 +90,9 @@ contract CompoundV2ERC4626Wrapper is ERC4626 { ICERC20 cToken_, // compound concept of a share IComptroller comptroller_, address manager_ - ) ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) { + ) + ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) + { reward = reward_; cToken = cToken_; comptroller = comptroller_; @@ -122,7 +124,8 @@ contract CompoundV2ERC4626Wrapper is ERC4626 { /// @notice Claims liquidity mining rewards from Compound and performs low-lvl swap with instant reinvesting /// Calling harvest() claims COMP-Fork token through direct Pair swap for best control and lowest cost - /// harvest() can be called by anybody. ideally this function should be adjusted per needs (e.g add fee for harvesting) + /// harvest() can be called by anybody. ideally this function should be adjusted per needs (e.g add fee for + /// harvesting) function harvest(uint256 minAmountOut_) external { ICERC20[] memory cTokens = new ICERC20[](1); cTokens[0] = cToken; diff --git a/src/compound/CompoundV3ERC4626Wrapper.sol b/src/compound/CompoundV3ERC4626Wrapper.sol index b58a30d..1a859fb 100644 --- a/src/compound/CompoundV3ERC4626Wrapper.sol +++ b/src/compound/CompoundV3ERC4626Wrapper.sol @@ -1,16 +1,16 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {CometMainInterface} from "./external/IComet.sol"; -import {LibCompound} from "./external/LibCompound.sol"; -import {ICometRewards} from "./external/ICometRewards.sol"; -import {ISwapRouter} from "../aave-v2/utils/ISwapRouter.sol"; -import {DexSwap} from "../_global/swapUtils.sol"; +import { CometMainInterface } from "./external/IComet.sol"; +import { LibCompound } from "./external/LibCompound.sol"; +import { ICometRewards } from "./external/ICometRewards.sol"; +import { ISwapRouter } from "../aave-v2/utils/ISwapRouter.sol"; +import { DexSwap } from "../_global/swapUtils.sol"; /// @title CompoundV3ERC4626Wrapper /// @notice Custom implementation with flexible reinvesting logic @@ -75,7 +75,9 @@ contract CompoundV3ERC4626Wrapper is ERC4626 { CometMainInterface cToken_, // compound concept of a share ICometRewards rewardsManager_, address manager_ - ) ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) { + ) + ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) + { cToken = cToken_; rewardsManager = rewardsManager_; manager = manager_; diff --git a/src/compound/external/ICERC20.sol b/src/compound/external/ICERC20.sol index 15edd01..4ae5433 100644 --- a/src/compound/external/ICERC20.sol +++ b/src/compound/external/ICERC20.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; -import {IInterestRateModel} from "./IInterestRateModel.sol"; +import { IInterestRateModel } from "./IInterestRateModel.sol"; abstract contract ICERC20 is ERC20 { function mint(uint256 underlyingAmount) external virtual returns (uint256); diff --git a/src/compound/external/IComet.sol b/src/compound/external/IComet.sol index 87b9327..ded24a0 100644 --- a/src/compound/external/IComet.sol +++ b/src/compound/external/IComet.sol @@ -106,7 +106,13 @@ abstract contract CometMainInterface { function balanceOf(address owner) public view virtual returns (uint256); function borrowBalanceOf(address account) public view virtual returns (uint256); - function pause(bool supplyPaused, bool transferPaused, bool withdrawPaused, bool absorbPaused, bool buyPaused) + function pause( + bool supplyPaused, + bool transferPaused, + bool withdrawPaused, + bool absorbPaused, + bool buyPaused + ) external virtual; function isSupplyPaused() public view virtual returns (bool); diff --git a/src/compound/external/IComptroller.sol b/src/compound/external/IComptroller.sol index cadff14..940b41e 100644 --- a/src/compound/external/IComptroller.sol +++ b/src/compound/external/IComptroller.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ICERC20} from "./ICERC20.sol"; +import { ICERC20 } from "./ICERC20.sol"; interface IComptroller { function getAllMarkets() external view returns (ICERC20[] memory); diff --git a/src/compound/external/LibCompound.sol b/src/compound/external/LibCompound.sol index 19b6045..4b97384 100644 --- a/src/compound/external/LibCompound.sol +++ b/src/compound/external/LibCompound.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {ICERC20} from "./ICERC20.sol"; +import { ICERC20 } from "./ICERC20.sol"; /// @notice Get up to date cToken data without mutating state. /// @notice Forked from Transmissions11 (https://github.com/transmissions11/libcompound) to upgrade version @@ -30,7 +30,8 @@ library LibCompound { uint256 borrowRateMantissa = cToken.interestRateModel().getBorrowRate(totalCash, borrowsPrior, reservesPrior); - if (borrowRateMantissa > 0.0005e16) revert RATE_TOO_HIGH(); // Same as borrowRateMaxMantissa in CTokenInterfaces.sol + if (borrowRateMantissa > 0.0005e16) revert RATE_TOO_HIGH(); // Same as borrowRateMaxMantissa in + // CTokenInterfaces.sol uint256 interestAccumulated = borrowRateMantissa * block.number - accrualBlockNumberPrior.mulWadDown(borrowsPrior); diff --git a/src/compound/test/CompoundV2ERC4626Wrapper.t.sol b/src/compound/test/CompoundV2ERC4626Wrapper.t.sol index b87b63b..8f6d9f5 100644 --- a/src/compound/test/CompoundV2ERC4626Wrapper.t.sol +++ b/src/compound/test/CompoundV2ERC4626Wrapper.t.sol @@ -2,10 +2,10 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {CompoundV2ERC4626Wrapper} from "../CompoundV2ERC4626Wrapper.sol"; -import {ICERC20} from "../external/ICERC20.sol"; -import {IComptroller} from "../external/IComptroller.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { CompoundV2ERC4626Wrapper } from "../CompoundV2ERC4626Wrapper.sol"; +import { ICERC20 } from "../external/ICERC20.sol"; +import { IComptroller } from "../external/IComptroller.sol"; contract CompoundV2ERC4626Test is Test { uint256 public ethFork; diff --git a/src/compound/test/CompoundV3ERC4626Wrapper.t.sol b/src/compound/test/CompoundV3ERC4626Wrapper.t.sol index 0d8ea44..ac88ae0 100644 --- a/src/compound/test/CompoundV3ERC4626Wrapper.t.sol +++ b/src/compound/test/CompoundV3ERC4626Wrapper.t.sol @@ -2,10 +2,10 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {CompoundV3ERC4626Wrapper} from "../CompoundV3ERC4626Wrapper.sol"; -import {CometMainInterface} from "../external/IComet.sol"; -import {ICometRewards} from "../external/ICometRewards.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { CompoundV3ERC4626Wrapper } from "../CompoundV3ERC4626Wrapper.sol"; +import { CometMainInterface } from "../external/IComet.sol"; +import { ICometRewards } from "../external/ICometRewards.sol"; contract CompoundV3ERC4626Test is Test { uint256 public ethFork; diff --git a/src/geist/GeistERC4626Reinvest.sol b/src/geist/GeistERC4626Reinvest.sol index fcbac5e..14cb056 100644 --- a/src/geist/GeistERC4626Reinvest.sol +++ b/src/geist/GeistERC4626Reinvest.sol @@ -1,13 +1,13 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; -import {IMultiFeeDistribution} from "./external/IMultiFeeDistribution.sol"; -import {IGLendingPool} from "./external/IGLendingPool.sol"; -import {DexSwap} from "../_global/swapUtils.sol"; +import { IMultiFeeDistribution } from "./external/IMultiFeeDistribution.sol"; +import { IGLendingPool } from "./external/IGLendingPool.sol"; +import { DexSwap } from "../_global/swapUtils.sol"; /// @title GeistERC4626Reinvest /// @notice AAVE-V2 Forked protocol with Curve-like rewards distribution in place of IAaveMining. @@ -89,7 +89,9 @@ contract GeistERC4626Reinvest is ERC4626 { IGLendingPool lendingPool_, ERC20 rewardToken_, address manager_ - ) ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) { + ) + ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) + { aToken = aToken_; rewards = rewards_; lendingPool = lendingPool_; @@ -165,7 +167,11 @@ contract GeistERC4626Reinvest is ERC4626 { ERC4626 OVERRIDES //////////////////////////////////////////////////////////////*/ - function withdraw(uint256 assets_, address receiver_, address owner_) + function withdraw( + uint256 assets_, + address receiver_, + address owner_ + ) public virtual override @@ -191,7 +197,11 @@ contract GeistERC4626Reinvest is ERC4626 { lendingPool.withdraw(address(asset), assets_, receiver_); } - function redeem(uint256 shares_, address receiver_, address owner_) + function redeem( + uint256 shares_, + address receiver_, + address owner_ + ) public virtual override diff --git a/src/geist/test/GeistERC4626Reinvest.t.sol b/src/geist/test/GeistERC4626Reinvest.t.sol index 3dde14d..49340d5 100644 --- a/src/geist/test/GeistERC4626Reinvest.t.sol +++ b/src/geist/test/GeistERC4626Reinvest.t.sol @@ -2,14 +2,14 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; -import {GeistERC4626Reinvest} from "../GeistERC4626Reinvest.sol"; +import { GeistERC4626Reinvest } from "../GeistERC4626Reinvest.sol"; -import {IGLendingPool} from "../external/IGLendingPool.sol"; -import {IMultiFeeDistribution} from "../external/IMultiFeeDistribution.sol"; -import {DexSwap} from "../../_global/swapUtils.sol"; +import { IGLendingPool } from "../external/IGLendingPool.sol"; +import { IMultiFeeDistribution } from "../external/IMultiFeeDistribution.sol"; +import { DexSwap } from "../../_global/swapUtils.sol"; contract GeistERC4626ReinvestTest is Test { //////////////////////////////////////// @@ -57,8 +57,8 @@ contract GeistERC4626ReinvestTest is Test { alice = address(0x1); bob = address(0x2); - deal(address(asset), alice, 10000 ether); - deal(address(asset), bob, 10000 ether); + deal(address(asset), alice, 10_000 ether); + deal(address(asset), bob, 10_000 ether); } function testSingleDepositWithdraw() public { @@ -142,16 +142,16 @@ contract GeistERC4626ReinvestTest is Test { asset.approve(address(vault), amount); uint256 aliceShareAmount = vault.deposit(amount, alice); - vm.roll(block.number + 1000000); + vm.roll(block.number + 1_000_000); /// @dev Deal 10000 GEIST reward tokens to the vault - deal(address(rewardToken), address(vault), 10000 ether); + deal(address(rewardToken), address(vault), 10_000 ether); assertEq(vault.totalSupply(), aliceShareAmount); assertEq(vault.totalAssets(), 100 ether); console.log("totalAssets before harvest", vault.totalAssets()); - assertEq(ERC20(rewardToken).balanceOf(address(vault)), 10000 ether); + assertEq(ERC20(rewardToken).balanceOf(address(vault)), 10_000 ether); - vm.roll(block.number + 6492849); + vm.roll(block.number + 6_492_849); IMultiFeeDistribution.RewardData[] memory rewardData = vault.getRewardsAccrued(); for (uint256 i = 0; i < rewardData.length; i++) { diff --git a/src/interfaces/IERC4626TimelockVault.sol b/src/interfaces/IERC4626TimelockVault.sol index 38a3d6c..c157665 100644 --- a/src/interfaces/IERC4626TimelockVault.sol +++ b/src/interfaces/IERC4626TimelockVault.sol @@ -1,7 +1,7 @@ ///SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {IERC4626} from "openzeppelin-contracts/contracts/interfaces/IERC4626.sol"; +import { IERC4626 } from "openzeppelin-contracts/contracts/interfaces/IERC4626.sol"; /// @title IERC4626TimelockVault /// @author Zeropoint Labs @@ -21,11 +21,13 @@ interface IERC4626TimelockVault is IERC4626 { uint256 shareAmount; } - /// @notice Abstract function, demonstrating a need for two separate calls to withdraw from IERC4626TimelockVault target vault + /// @notice Abstract function, demonstrating a need for two separate calls to withdraw from IERC4626TimelockVault + /// target vault /// @dev Owner first submits request for unlock and only after specified cooldown passes, can withdraw function requestUnlock(uint256 shareAmount, address owner) external; - /// @notice Abstract function, demonstrating a need for two separate calls to withdraw from IERC4626TimelockVault target vault + /// @notice Abstract function, demonstrating a need for two separate calls to withdraw from IERC4626TimelockVault + /// target vault /// @dev Owner can resign from unlock request. In production vaults have differing mechanism for this function cancelUnlock(address owner) external; diff --git a/src/kycdao-4626/kycdao4626.sol b/src/kycdao-4626/kycdao4626.sol index 0266a2a..e737447 100644 --- a/src/kycdao-4626/kycdao4626.sol +++ b/src/kycdao-4626/kycdao4626.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; -import {IKycValidity} from "./interfaces/IKycValidity.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; +import { IKycValidity } from "./interfaces/IKycValidity.sol"; /// @title kycDAO4626 /// @notice NFT-gated ERC-4626 using KYCDAO https://docs.kycdao.xyz/smartcontracts/evm/ @@ -87,7 +87,11 @@ contract kycDAO4626 is ERC4626 { afterDeposit(assets, shares_); } - function withdraw(uint256 assets_, address receiver_, address owner_) + function withdraw( + uint256 assets_, + address receiver_, + address owner_ + ) public virtual override @@ -113,7 +117,11 @@ contract kycDAO4626 is ERC4626 { asset.safeTransfer(receiver_, assets_); } - function redeem(uint256 shares_, address receiver_, address owner_) + function redeem( + uint256 shares_, + address receiver_, + address owner_ + ) public virtual override diff --git a/src/kycdao-4626/test/kycdao4626.t.sol b/src/kycdao-4626/test/kycdao4626.t.sol index db427f8..f6d1e22 100644 --- a/src/kycdao-4626/test/kycdao4626.t.sol +++ b/src/kycdao-4626/test/kycdao4626.t.sol @@ -4,11 +4,11 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; import "forge-std/console.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {kycDAO4626} from "../kycdao4626.sol"; -import {IKycValidity} from "../interfaces/IKycValidity.sol"; +import { kycDAO4626 } from "../kycdao4626.sol"; +import { IKycValidity } from "../interfaces/IKycValidity.sol"; contract kycDAO4626Test is Test { uint256 public polygonFork; @@ -44,7 +44,7 @@ contract kycDAO4626Test is Test { } function testDepositWithdraw() public { - uint256 underlyingAmount = 10000000000000000; + uint256 underlyingAmount = 10_000_000_000_000_000; vm.startPrank(kycNFTHolder); @@ -61,7 +61,7 @@ contract kycDAO4626Test is Test { } function testMintRedeem() public { - uint256 sharesMint = 10000000000000000; + uint256 sharesMint = 10_000_000_000_000_000; vm.startPrank(kycNFTHolder); @@ -79,7 +79,7 @@ contract kycDAO4626Test is Test { } function testRevertDeposit() public { - uint256 underlyingAmount = 10000000000000000; + uint256 underlyingAmount = 10_000_000_000_000_000; vm.startPrank(alice); @@ -91,7 +91,7 @@ contract kycDAO4626Test is Test { } function testRevertMint() public { - uint256 sharesMint = 10000000000000000; + uint256 sharesMint = 10_000_000_000_000_000; vm.startPrank(alice); diff --git a/src/lido/stETH.sol b/src/lido/stETH.sol index 818fde2..6cc8679 100644 --- a/src/lido/stETH.sol +++ b/src/lido/stETH.sol @@ -1,17 +1,18 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; -import {IStETH} from "./interfaces/IStETH.sol"; -import {IWETH} from "./interfaces/IWETH.sol"; +import { IStETH } from "./interfaces/IStETH.sol"; +import { IWETH } from "./interfaces/IWETH.sol"; /// @title StETHERC4626 /// @notice WIP: Lido's stETH ERC4626 Wrapper - stEth as Vault's underlying token (and token received after withdraw). -/// @notice Accepts WETH through ERC4626 interface, but can also accept ETH directly through different deposit() function signature. +/// @notice Accepts WETH through ERC4626 interface, but can also accept ETH directly through different deposit() +/// function signature. /// @notice Vault balance holds stEth. Value is updated for each accounting call. /// @notice Assets Under Managment (totalAssets()) operates on rebasing balance. /// @dev This Wrapper is a base implementation, providing ERC4626 interface over stEth without any additional strategy. @@ -55,14 +56,14 @@ contract StETHERC4626 is ERC4626 { weth = IWETH(weth_); } - receive() external payable {} + receive() external payable { } /*////////////////////////////////////////////////////////////// INTERNAL HOOKS LOGIC //////////////////////////////////////////////////////////////*/ function _addLiquidity(uint256 ethAmount_, uint256) internal returns (uint256 stEthAmount) { - stEthAmount = stEth.submit{value: ethAmount_}(address(this)); + stEthAmount = stEth.submit{ value: ethAmount_ }(address(this)); } /*////////////////////////////////////////////////////////////// diff --git a/src/lido/stETH_swap.sol b/src/lido/stETH_swap.sol index bb62295..4dc4ecb 100644 --- a/src/lido/stETH_swap.sol +++ b/src/lido/stETH_swap.sol @@ -1,19 +1,20 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; -import {ICurve} from "./interfaces/ICurve.sol"; -import {IStETH} from "./interfaces/IStETH.sol"; -import {IWETH} from "./interfaces/IWETH.sol"; +import { ICurve } from "./interfaces/ICurve.sol"; +import { IStETH } from "./interfaces/IStETH.sol"; +import { IWETH } from "./interfaces/IWETH.sol"; /// @title Lido's stETH ERC4626 Wrapper /// @notice Accepts WETH through ERC4626 interface, but can also accept ETH directly through other deposit() function. /// @notice Returns assets as ETH for brevity (community-version should return stEth) -/// @notice Assets Under Managment (totalAssets()) operates on rebasing balance, re-calculated to the current value in ETH. +/// @notice Assets Under Managment (totalAssets()) operates on rebasing balance, re-calculated to the current value in +/// ETH. /// @notice Uses ETH/stETH CurvePool for a fast-exit with 1% slippage hardcoded. /// @author ZeroPoint Labs contract StETHERC4626Swap is ERC4626 { @@ -54,7 +55,7 @@ contract StETHERC4626Swap is ERC4626 { ICurve public curvePool; uint256 public slippage; - uint256 public immutable slippageFloat = 10000; + uint256 public immutable slippageFloat = 10_000; int128 public immutable index_eth = 0; @@ -70,7 +71,12 @@ contract StETHERC4626Swap is ERC4626 { /// @param stEth_ stETH (Lido contract) address /// @param curvePool_ CurvePool address /// @param manager_ manager address - constructor(address weth_, address stEth_, address curvePool_, address manager_) + constructor( + address weth_, + address stEth_, + address curvePool_, + address manager_ + ) ERC4626(ERC20(weth_), "ERC4626-Wrapped stETH", "wLstETH") { stEth = IStETH(stEth_); @@ -82,7 +88,7 @@ contract StETHERC4626Swap is ERC4626 { slippage = 9900; } - receive() external payable {} + receive() external payable { } /*////////////////////////////////////////////////////////////// ERC4626 OVERRIDES @@ -94,7 +100,7 @@ contract StETHERC4626Swap is ERC4626 { } function afterDeposit(uint256 ethAmount, uint256) internal override { - stEth.submit{value: ethAmount}(address(this)); + stEth.submit{ value: ethAmount }(address(this)); /// Lido's submit() accepts only native ETH } @@ -212,7 +218,7 @@ contract StETHERC4626Swap is ERC4626 { function setSlippage(uint256 amount_) external { if (msg.sender != manager) revert INVALID_ACCESS(); - if (amount_ > 10000 || amount_ < 9000) revert INVALID_SLIPPAGE(); + if (amount_ > 10_000 || amount_ < 9000) revert INVALID_SLIPPAGE(); slippage = amount_; } diff --git a/src/lido/stMATIC.sol b/src/lido/stMATIC.sol index 5917d9a..a0e3290 100644 --- a/src/lido/stMATIC.sol +++ b/src/lido/stMATIC.sol @@ -1,13 +1,13 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; -import {IStMATIC} from "./interfaces/IStMATIC.sol"; -import {IMATIC} from "./interfaces/IMatic.sol"; +import { IStMATIC } from "./interfaces/IStMATIC.sol"; +import { IMATIC } from "./interfaces/IMatic.sol"; /// @title StMATIC4626 /// @notice Lido's stMATIC ERC4626 Wrapper - stMatic as Vault's underlying token (and token received after withdraw) @@ -43,14 +43,17 @@ contract StMATIC4626 is ERC4626 { /// @param matic_ matic address (Vault's underlying / deposit token) /// @param stMatic_ stMatic (Lido contract) address - constructor(address matic_, address stMatic_) + constructor( + address matic_, + address stMatic_ + ) ERC4626(ERC20(matic_), "ERC4626-Wrapped stMatic", "ERC4626-stMatic") { stMatic = IStMATIC(stMatic_); stMaticAsset = ERC20(stMatic_); } - receive() external payable {} + receive() external payable { } /*////////////////////////////////////////////////////////////// INTERNAL HOOKS LOGIC diff --git a/src/lido/test/stETH.t.sol b/src/lido/test/stETH.t.sol index bb96fce..1a4d2b4 100644 --- a/src/lido/test/stETH.t.sol +++ b/src/lido/test/stETH.t.sol @@ -3,13 +3,13 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; import "forge-std/console.sol"; -import {StETHERC4626} from "../stETH.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { StETHERC4626 } from "../stETH.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {ICurve} from "../interfaces/ICurve.sol"; -import {IStETH} from "../interfaces/IStETH.sol"; -import {IWETH} from "../interfaces/IWETH.sol"; -import {wstETH} from "../interfaces/wstETH.sol"; +import { ICurve } from "../interfaces/ICurve.sol"; +import { IStETH } from "../interfaces/IStETH.sol"; +import { IWETH } from "../interfaces/IWETH.sol"; +import { wstETH } from "../interfaces/wstETH.sol"; contract stEthTest is Test { uint256 public ethFork; @@ -91,7 +91,7 @@ contract stEthTest is Test { startHoax(alice, aliceEth + 1 ether); uint256 expectedSharesFromAsset = vault.convertToShares(aliceEth); - uint256 aliceShareAmount = vault.deposit{value: aliceEth}(alice); + uint256 aliceShareAmount = vault.deposit{ value: aliceEth }(alice); assertEq(expectedSharesFromAsset, aliceShareAmount); } } diff --git a/src/lido/test/stETH_swap.t.sol b/src/lido/test/stETH_swap.t.sol index bc48d9b..6856d20 100644 --- a/src/lido/test/stETH_swap.t.sol +++ b/src/lido/test/stETH_swap.t.sol @@ -3,13 +3,13 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; import "forge-std/console.sol"; -import {StETHERC4626Swap} from "../stETH_swap.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { StETHERC4626Swap } from "../stETH_swap.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {ICurve} from "../interfaces/ICurve.sol"; -import {IStETH} from "../interfaces/IStETH.sol"; -import {IWETH} from "../interfaces/IWETH.sol"; -import {wstETH} from "../interfaces/wstETH.sol"; +import { ICurve } from "../interfaces/ICurve.sol"; +import { IStETH } from "../interfaces/IStETH.sol"; +import { IWETH } from "../interfaces/IWETH.sol"; +import { wstETH } from "../interfaces/wstETH.sol"; contract stEthSwapTest is Test { uint256 public ethFork; diff --git a/src/lido/test/stMatic.t.sol b/src/lido/test/stMatic.t.sol index b818f50..0a687b9 100644 --- a/src/lido/test/stMatic.t.sol +++ b/src/lido/test/stMatic.t.sol @@ -4,11 +4,11 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; import "forge-std/console.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {StMATIC4626} from "../stMATIC.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; -import {IStMATIC} from "../interfaces/IStMATIC.sol"; -import {IWETH} from "../interfaces/IWETH.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { StMATIC4626 } from "../stMATIC.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; +import { IStMATIC } from "../interfaces/IStMATIC.sol"; +import { IWETH } from "../interfaces/IWETH.sol"; contract stMaticTest is Test { uint256 public ethFork; diff --git a/src/rocketPool/rEth.sol b/src/rocketPool/rEth.sol index 0766c11..22a6c7d 100644 --- a/src/rocketPool/rEth.sol +++ b/src/rocketPool/rEth.sol @@ -1,23 +1,25 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; -import {IWETH} from "./interfaces/IWETH.sol"; -import {IRETH} from "./interfaces/IReth.sol"; -import {IRSTORAGE} from "./interfaces/IRstorage.sol"; -import {IRPROTOCOL} from "./interfaces/IRProtocol.sol"; -import {IRETHTOKEN} from "./interfaces/IRethToken.sol"; +import { IWETH } from "./interfaces/IWETH.sol"; +import { IRETH } from "./interfaces/IReth.sol"; +import { IRSTORAGE } from "./interfaces/IRstorage.sol"; +import { IRPROTOCOL } from "./interfaces/IRProtocol.sol"; +import { IRETHTOKEN } from "./interfaces/IRethToken.sol"; /// @title rEthERC4626 /// @notice Experimental RocketPool's rETH ERC4626 Wrapper /// @notice Preview functions allow to check current value of held rETH tokens denominated as ETH /// @notice Redemption is denominated in rETH as RocketPool doesn't allow to redeem ETH directly -/// @notice Adapter can be used as a good base for building rETH oriented strategy (requires changes to shares calculation) -/// @notice deposit & mint are "entry" functions to RocketPool - caller gives weth, caller receives wrEth, vault holds rEth +/// @notice Adapter can be used as a good base for building rETH oriented strategy (requires changes to shares +/// calculation) +/// @notice deposit & mint are "entry" functions to RocketPool - caller gives weth, caller receives wrEth, vault holds +/// rEth /// @notice withdraw & redeem are "exit" functions from rEthERC4626 - caller gives wrEth, caller receives rEth /// @author ZeroPoint Labs contract rEthERC4626 is ERC4626 { @@ -92,7 +94,7 @@ contract rEthERC4626 is ERC4626 { rEthAsset = ERC20(rocketTokenRETHAddress); } - receive() external payable {} + receive() external payable { } /*////////////////////////////////////////////////////////////// ERC4626 OVERRIDES @@ -123,7 +125,7 @@ contract rEthERC4626 is ERC4626 { uint256 startBalance = rEthAsset.balanceOf(address(this)); /// @dev Deposit eth to rocket pool - rEth.deposit{value: assets_}(); + rEth.deposit{ value: assets_ }(); /// @dev How much rEth are we receiving after deposit to the rocket pool /// NOTE: Prone to inflation attack on balance of this contract!!! @@ -163,7 +165,7 @@ contract rEthERC4626 is ERC4626 { uint256 startBalance = rEthAsset.balanceOf(address(this)); /// @dev Deposit eth to rocket pool - rEth.deposit{value: assets}(); + rEth.deposit{ value: assets }(); /// @dev How much rEth are we receiving after deposit to the rocket pool /// NOTE: Prone to inflation attack on balance of this contract!!! @@ -175,11 +177,13 @@ contract rEthERC4626 is ERC4626 { emit Deposit(msg.sender, receiver_, assets, rEthReceived); } - /// @notice Withdraw in this implementation allows to receive rEth from wrEth, not redeem directly to ETH (from rEth) + /// @notice Withdraw in this implementation allows to receive rEth from wrEth, not redeem directly to ETH (from + /// rEth) /// @notice caller is asking for asset rETH/wrEth to withdraw, where asset is virtually equal to ETH-backing /// @notice rocket pool has no redeem-to-eth function /// @dev To allow withdrawing "assets" as ETH, directly from rEth, would require an exchange of rEth to ETH on a DEX - /// @dev That is considered an extension to the following implementation, which is strict ERC4626 wrapper over rEth token interface + /// @dev That is considered an extension to the following implementation, which is strict ERC4626 wrapper over rEth + /// token interface function withdraw(uint256 assets_, address receiver_, address owner_) public override returns (uint256 shares) { /// @dev Returns shares = previewWithdraw(assets_); @@ -206,7 +210,8 @@ contract rEthERC4626 is ERC4626 { /// @notice Redeem rETH for burning wrEth shares (of this vault) /// @notice caller is asking to redeem wrEth shares to rEth, exit asset is rEth /// @dev To allow redeeming "assets" as ETH, directly from rEth, would require an exchange of rEth to ETH on a DEX - /// @dev That is considered an extension to the following implementation, which is strict ERC4626 wrapper over rEth token interface + /// @dev That is considered an extension to the following implementation, which is strict ERC4626 wrapper over rEth + /// token interface function redeem(uint256 shares_, address receiver_, address owner_) public override returns (uint256 assets) { if (msg.sender != owner_) { uint256 allowed = allowance[owner_][msg.sender]; @@ -225,7 +230,8 @@ contract rEthERC4626 is ERC4626 { emit Withdraw(msg.sender, receiver_, owner_, assets, shares_); - /// @dev Transfers amount of the requested rEth shares. We can transfer "shares" in this impl because of 1:1 ratio rEth:wrEth + /// @dev Transfers amount of the requested rEth shares. We can transfer "shares" in this impl because of 1:1 + /// ratio rEth:wrEth rEthAsset.safeTransfer(receiver_, shares_); } diff --git a/src/rocketPool/test/rEth.t.sol b/src/rocketPool/test/rEth.t.sol index c9ed2bc..1381cf1 100644 --- a/src/rocketPool/test/rEth.t.sol +++ b/src/rocketPool/test/rEth.t.sol @@ -4,13 +4,13 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; import "forge-std/console.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {rEthERC4626} from "../rEth.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { rEthERC4626 } from "../rEth.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {IRETH} from "../interfaces/IReth.sol"; -import {IRSTORAGE} from "../interfaces/IRstorage.sol"; -import {IWETH} from "../interfaces/IWETH.sol"; +import { IRETH } from "../interfaces/IReth.sol"; +import { IRSTORAGE } from "../interfaces/IRstorage.sol"; +import { IWETH } from "../interfaces/IWETH.sol"; contract rEthTest is Test { uint256 public ethFork; diff --git a/src/uniswap-v2/interfaces/IUniswapV2ERC20.sol b/src/uniswap-v2/interfaces/IUniswapV2ERC20.sol index 17545ee..ba2c05f 100644 --- a/src/uniswap-v2/interfaces/IUniswapV2ERC20.sol +++ b/src/uniswap-v2/interfaces/IUniswapV2ERC20.sol @@ -29,6 +29,14 @@ interface IUniswapV2ERC20 { function nonces(address owner) external view returns (uint256); - function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) + function permit( + address owner, + address spender, + uint256 value, + uint256 deadline, + uint8 v, + bytes32 r, + bytes32 s + ) external; } diff --git a/src/uniswap-v2/interfaces/IUniswapV2Pair.sol b/src/uniswap-v2/interfaces/IUniswapV2Pair.sol index 0f0d09e..694138d 100644 --- a/src/uniswap-v2/interfaces/IUniswapV2Pair.sol +++ b/src/uniswap-v2/interfaces/IUniswapV2Pair.sol @@ -20,7 +20,15 @@ interface IUniswapV2Pair { function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint256); - function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) + function permit( + address owner, + address spender, + uint256 value, + uint256 deadline, + uint8 v, + bytes32 r, + bytes32 s + ) external; event Mint(address indexed sender, uint256 amount0, uint256 amount1); diff --git a/src/uniswap-v2/interfaces/IUniswapV2Router.sol b/src/uniswap-v2/interfaces/IUniswapV2Router.sol index a1f5316..250eb6f 100644 --- a/src/uniswap-v2/interfaces/IUniswapV2Router.sol +++ b/src/uniswap-v2/interfaces/IUniswapV2Router.sol @@ -10,7 +10,9 @@ interface IUniswapV2Router { uint256 amountBMin, address to, uint256 deadline - ) external returns (uint256 amountA, uint256 amountB); + ) + external + returns (uint256 amountA, uint256 amountB); function addLiquidity( address tokenA, @@ -21,7 +23,9 @@ interface IUniswapV2Router { uint256 amountBMin, address to, uint256 deadline - ) external returns (uint256 amountA, uint256 amountB, uint256 liquidity); + ) + external + returns (uint256 amountA, uint256 amountB, uint256 liquidity); function swapTokensForExactTokens( uint256 amountOut, @@ -29,7 +33,9 @@ interface IUniswapV2Router { address[] calldata path, address to, uint256 deadline - ) external returns (uint256[] memory amounts); + ) + external + returns (uint256[] memory amounts); function swapExactTokensForTokens( uint256 amountIn, @@ -37,5 +43,7 @@ interface IUniswapV2Router { address[] calldata path, address to, uint256 deadline - ) external returns (uint256[] memory amounts); + ) + external + returns (uint256[] memory amounts); } diff --git a/src/uniswap-v2/no-swap/UniswapV2WrapperERC4626.sol b/src/uniswap-v2/no-swap/UniswapV2WrapperERC4626.sol index 41ab4bb..5a47e70 100644 --- a/src/uniswap-v2/no-swap/UniswapV2WrapperERC4626.sol +++ b/src/uniswap-v2/no-swap/UniswapV2WrapperERC4626.sol @@ -1,14 +1,14 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {IUniswapV2Pair} from "../interfaces/IUniswapV2Pair.sol"; -import {IUniswapV2Router} from "../interfaces/IUniswapV2Router.sol"; -import {UniswapV2Library} from "../utils/UniswapV2Library.sol"; +import { IUniswapV2Pair } from "../interfaces/IUniswapV2Pair.sol"; +import { IUniswapV2Router } from "../interfaces/IUniswapV2Router.sol"; +import { UniswapV2Library } from "../utils/UniswapV2Library.sol"; /// @title UniswapV2WrapperERC4626 /// @notice Custom ERC4626 Wrapper for UniV2 Pools without swapping, accepting token0/token1 transfers @@ -16,10 +16,12 @@ import {UniswapV2Library} from "../utils/UniswapV2Library.sol"; /// @notice Basic flow description: /// @notice Vault (ERC4626) - totalAssets() == lpToken of Uniswap Pool /// @notice deposit(assets) -> assets == lpToken amount to receive -/// @notice - user needs to approve both A,B tokens in X,Y amounts (see getLiquidityAmounts / getAssetsAmounts functions) +/// @notice - user needs to approve both A,B tokens in X,Y amounts (see getLiquidityAmounts / getAssetsAmounts +/// functions) /// @notice - check is run if A,B covers requested Z amount of UniLP /// @notice - deposit() safeTransfersFrom A,B to _min Z amount of UniLP -/// @notice withdraw() -> withdraws both A,B in accrued X+n,Y+n amounts, burns Z amount of UniLP (or Vault's LP, those are 1:1) +/// @notice withdraw() -> withdraws both A,B in accrued X+n,Y+n amounts, burns Z amount of UniLP (or Vault's LP, those +/// are 1:1) /// @dev https://v2.info.uniswap.org/pair/0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5 (DAI-USDC LP/PAIR on ETH) /// @author ZeroPoint Labs contract UniswapV2WrapperERC4626 is ERC4626 { @@ -36,7 +38,7 @@ contract UniswapV2WrapperERC4626 is ERC4626 { address public immutable manager; uint256 public slippage; - uint256 public immutable slippageFloat = 10000; + uint256 public immutable slippageFloat = 10_000; IUniswapV2Pair public immutable pair; IUniswapV2Router public immutable router; @@ -67,7 +69,9 @@ contract UniswapV2WrapperERC4626 is ERC4626 { IUniswapV2Pair pair_, /// Pair address (to opti) uint256 slippage_ - ) ERC4626(asset_, name_, symbol_) { + ) + ERC4626(asset_, name_, symbol_) + { manager = msg.sender; pair = pair_; router = router_; @@ -80,7 +84,7 @@ contract UniswapV2WrapperERC4626 is ERC4626 { /// @param amount_ amount of slippage function setSlippage(uint256 amount_) external { require(msg.sender == manager, "owner"); - require(amount_ < 10000 && amount_ > 9000); + require(amount_ < 10_000 && amount_ > 9000); /// 10% max slippage slippage = amount_; } @@ -136,8 +140,10 @@ contract UniswapV2WrapperERC4626 is ERC4626 { //////////////////////////////////////////////////////////////*/ /// @notice Deposit pre-calculated amount of token0/1 to get amount of UniLP (assets/getUniLpFromAssets_) - /// @notice REQUIREMENT: Calculate amount of assets and have enough of assets0/1 to cover this amount for LP requested (slippage!) - /// @param getUniLpFromAssets_ Assume caller called getAssetsAmounts() first to know amount of assets to approve to this contract + /// @notice REQUIREMENT: Calculate amount of assets and have enough of assets0/1 to cover this amount for LP + /// requested (slippage!) + /// @param getUniLpFromAssets_ Assume caller called getAssetsAmounts() first to know amount of assets to approve to + /// this contract /// @param receiver_ - Who will receive shares (Standard ERC4626) /// @return shares - Of this Vault (Standard ERC4626) function deposit(uint256 getUniLpFromAssets_, address receiver_) public override returns (uint256 shares) { @@ -160,8 +166,10 @@ contract UniswapV2WrapperERC4626 is ERC4626 { afterDeposit(getUniLpFromAssets_, shares); } - /// @notice Mint amount of shares of this Vault (1:1 with UniLP). Requires precalculating amount of assets to approve to this contract. - /// @param sharesOfThisVault_ shares value == amount of Vault token (shares) to mint from requested lpToken. (1:1 with lpToken). + /// @notice Mint amount of shares of this Vault (1:1 with UniLP). Requires precalculating amount of assets to + /// approve to this contract. + /// @param sharesOfThisVault_ shares value == amount of Vault token (shares) to mint from requested lpToken. (1:1 + /// with lpToken). /// @param receiver_ == receiver of shares (Vault token) /// @return assets == amount of LPTOKEN minted (1:1 with sharesOfThisVault_ input) function mint(uint256 sharesOfThisVault_, address receiver_) public override returns (uint256 assets) { @@ -181,7 +189,8 @@ contract UniswapV2WrapperERC4626 is ERC4626 { afterDeposit(assets, sharesOfThisVault_); } - /// @notice Withdraw amount of token0/1 from burning Vault shares (1:1 with UniLP). Ie. User wants to burn 100 UniLP (underlying) for N worth of token0/1 + /// @notice Withdraw amount of token0/1 from burning Vault shares (1:1 with UniLP). Ie. User wants to burn 100 UniLP + /// (underlying) for N worth of token0/1 /// @param assets_ - amount of UniLP to burn (calculate amount of expected token0/1 from helper functions) /// @param receiver_ - Who will receive shares (Standard ERC4626) /// @param owner_ - Who owns shares (Standard ERC4626) @@ -189,7 +198,11 @@ contract UniswapV2WrapperERC4626 is ERC4626 { uint256 assets_, // amount of underlying asset (pool Lp) to withdraw address receiver_, address owner_ - ) public override returns (uint256 shares) { + ) + public + override + returns (uint256 shares) + { shares = previewWithdraw(assets_); (uint256 assets0, uint256 assets1) = getAssetsAmounts(assets_); @@ -214,7 +227,8 @@ contract UniswapV2WrapperERC4626 is ERC4626 { token1.safeTransfer(receiver_, assets1); } - /// @notice Redeem amount of Vault shares (1:1 with UniLP) for arbitrary amount of token0/1. Calculate amount of expected token0/1 from helper functions. + /// @notice Redeem amount of Vault shares (1:1 with UniLP) for arbitrary amount of token0/1. Calculate amount of + /// expected token0/1 from helper functions. /// @param shares_ - amount of UniLP to burn /// @param receiver_ - Who will receive shares (Standard ERC4626) /// @param owner_ - Who owns shares (Standard ERC4626) diff --git a/src/uniswap-v2/swap-built-in/UniswapV2ERC4626PoolFactory.sol b/src/uniswap-v2/swap-built-in/UniswapV2ERC4626PoolFactory.sol index 56bb757..8a1447c 100644 --- a/src/uniswap-v2/swap-built-in/UniswapV2ERC4626PoolFactory.sol +++ b/src/uniswap-v2/swap-built-in/UniswapV2ERC4626PoolFactory.sol @@ -1,19 +1,20 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; -import {IUniswapV2Pair} from "../interfaces/IUniswapV2Pair.sol"; -import {IUniswapV2Router} from "../interfaces/IUniswapV2Router.sol"; -import {UniswapV2ERC4626Swap} from "./UniswapV2ERC4626Swap.sol"; +import { IUniswapV2Pair } from "../interfaces/IUniswapV2Pair.sol"; +import { IUniswapV2Router } from "../interfaces/IUniswapV2Router.sol"; +import { UniswapV2ERC4626Swap } from "./UniswapV2ERC4626Swap.sol"; -import {IUniswapV3Factory} from "../interfaces/IUniswapV3.sol"; -import {IUniswapV3Pool} from "../interfaces/IUniswapV3.sol"; +import { IUniswapV3Factory } from "../interfaces/IUniswapV3.sol"; +import { IUniswapV3Pool } from "../interfaces/IUniswapV3.sol"; /// @title UniswapV2ERC4626PoolFactory /// @notice Uniswap V2 ERC4626 Pool Factory for instant deployment of adapter for two tokens of the Pair. -/// @notice Use for stress-free deployment of an adapter for a single uniswap V2 pair. Oracle functionality is currently disabled. +/// @notice Use for stress-free deployment of an adapter for a single uniswap V2 pair. Oracle functionality is currently +/// disabled. /// @author ZeroPoint Labs contract UniswapV2ERC4626PoolFactory { /*////////////////////////////////////////////////////////////// @@ -38,7 +39,10 @@ contract UniswapV2ERC4626PoolFactory { oracleFactory = oracleFactory_; } - function create(IUniswapV2Pair pair_, uint24 fee_) + function create( + IUniswapV2Pair pair_, + uint24 fee_ + ) external returns (UniswapV2ERC4626Swap v0, UniswapV2ERC4626Swap v1, address oracle) { diff --git a/src/uniswap-v2/swap-built-in/UniswapV2ERC4626Swap.sol b/src/uniswap-v2/swap-built-in/UniswapV2ERC4626Swap.sol index 0b4c4af..37f6078 100644 --- a/src/uniswap-v2/swap-built-in/UniswapV2ERC4626Swap.sol +++ b/src/uniswap-v2/swap-built-in/UniswapV2ERC4626Swap.sol @@ -1,26 +1,30 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {IUniswapV2Pair} from "../interfaces/IUniswapV2Pair.sol"; -import {IUniswapV2Router} from "../interfaces/IUniswapV2Router.sol"; -import {UniswapV2Library} from "../utils/UniswapV2Library.sol"; +import { IUniswapV2Pair } from "../interfaces/IUniswapV2Pair.sol"; +import { IUniswapV2Router } from "../interfaces/IUniswapV2Router.sol"; +import { UniswapV2Library } from "../utils/UniswapV2Library.sol"; -import {IUniswapV3Pool} from "../interfaces/IUniswapV3.sol"; +import { IUniswapV3Pool } from "../interfaces/IUniswapV3.sol"; -import {DexSwap} from "../../_global/swapUtils.sol"; +import { DexSwap } from "../../_global/swapUtils.sol"; /// @title UniswapV2ERC4626Swap -/// @notice ERC4626 UniswapV2 Adapter - Allows exit & join to UniswapV2 LP Pools from ERC4626 interface. Single sided liquidity adapter. -/// @notice Provides a set of helpful functions to calculate different aspects of liquidity providing to the UniswapV2-style pools. +/// @notice ERC4626 UniswapV2 Adapter - Allows exit & join to UniswapV2 LP Pools from ERC4626 interface. Single sided +/// liquidity adapter. +/// @notice Provides a set of helpful functions to calculate different aspects of liquidity providing to the +/// UniswapV2-style pools. /// @notice Accept tokenX || tokenY as ASSET. Uses UniswapV2Pair LP-TOKEN as AUM (totalAssets()). -/// @notice BASIC FLOW: Deposit tokenX > tokenX swap to tokenX && tokenY optimal amount > tokenX/Y deposited into UniswapV2 +/// @notice BASIC FLOW: Deposit tokenX > tokenX swap to tokenX && tokenY optimal amount > tokenX/Y deposited into +/// UniswapV2 /// @notice > shares minted to the Vault from the Uniswap Pool > shares minted to the user from the Vault -/// @dev Example Pool: https://v2.info.uniswap.org/pair/0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5 (DAI-USDC LP/PAIR on ETH). +/// @dev Example Pool: https://v2.info.uniswap.org/pair/0xae461ca67b15dc8dc81ce7615e0320da1a9ab8d5 (DAI-USDC LP/PAIR on +/// ETH). /// @author ZeroPoint Labs contract UniswapV2ERC4626Swap is ERC4626 { /*////////////////////////////////////////////////////////////// @@ -51,7 +55,7 @@ contract UniswapV2ERC4626Swap is ERC4626 { /// NOTE: Hardcoded workaround to ensure execution within changing pair reserves - 0.4% (4000/1000000) uint256 public fee = 4000; - uint256 public immutable slippageFloat = 1000000; + uint256 public immutable slippageFloat = 1_000_000; IUniswapV2Pair public immutable pair; IUniswapV2Router public immutable router; @@ -78,7 +82,9 @@ contract UniswapV2ERC4626Swap is ERC4626 { IUniswapV2Router router_, IUniswapV2Pair pair_, IUniswapV3Pool oracle_ - ) ERC4626(asset_, name_, symbol_) { + ) + ERC4626(asset_, name_, symbol_) + { manager = msg.sender; pair = pair_; @@ -151,7 +157,8 @@ contract UniswapV2ERC4626Swap is ERC4626 { shares = _liquidityAdd(a0, a1); - /// @dev caller calculates minSharesOut off-chain, this contracts functions can be used to retrive reserves over the past blocks + /// @dev caller calculates minSharesOut off-chain, this contracts functions can be used to retrive reserves over + /// the past blocks if (shares < minSharesOut_) revert NOT_MIN_SHARES_OUT(); /// @dev we just pass uniswap lp-token amount to user @@ -179,12 +186,14 @@ contract UniswapV2ERC4626Swap is ERC4626 { (uint256 a0, uint256 a1) = _swapJoin(assets_); /// NOTE: Pool reserve could be manipulated - /// NOTE: reserve manipulation, leading to inflation of shares is meaningless, because redemption happens against UniV2Pair not this Vault balance + /// NOTE: reserve manipulation, leading to inflation of shares is meaningless, because redemption happens + /// against UniV2Pair not this Vault balance uint256 uniShares = _liquidityAdd(a0, a1); /// @dev totalAssets holds sum of all UniLP, /// NOTE: UniLP is non-rebasing, yield accrues on Uniswap pool (you can redeem more t0/t1 for same amount of LP) - /// NOTE: If we want it as Strategy, e.g do something with this LP, then we need to calculate shares, 1:1 won't work + /// NOTE: If we want it as Strategy, e.g do something with this LP, then we need to calculate shares, 1:1 won't + /// work /// NOTE: Caller needs to trust previewDeposit return value which can be manipulated for 1 block if (uniShares < shares) revert NOT_MIN_SHARES_OUT(); @@ -219,7 +228,8 @@ contract UniswapV2ERC4626Swap is ERC4626 { } /// @notice mint exact amount of this Vault shares and effectivley UniswapV2Pair shares (1:1 relation) - /// @dev Requires caller to have a prior knowledge of what amount of `assets` to approve (use this contract helper functions) + /// @dev Requires caller to have a prior knowledge of what amount of `assets` to approve (use this contract helper + /// functions) function mint(uint256 shares_, address receiver_) public override returns (uint256 assets) { assets = previewMint(shares_); @@ -238,8 +248,14 @@ contract UniswapV2ERC4626Swap is ERC4626 { } /// @notice Non-ERC4626 withdraw function taking additional protection parameters for execution - /// @dev Caller specifies minAmountOut_ of this Vault's underlying to receive for burning Vault's shares (and UniswapV2Pair shares) - function withdraw(uint256 assets_, address receiver_, address owner_, uint256 minAmountOut_) + /// @dev Caller specifies minAmountOut_ of this Vault's underlying to receive for burning Vault's shares (and + /// UniswapV2Pair shares) + function withdraw( + uint256 assets_, + address receiver_, + address owner_, + uint256 minAmountOut_ + ) /// @dev calculated off-chain, "secure" withdraw function. public returns (uint256 shares) @@ -268,7 +284,8 @@ contract UniswapV2ERC4626Swap is ERC4626 { emit Withdraw(msg.sender, receiver_, owner_, amount, shares); } - /// @notice Receive amount of `assets` of underlying token of this Vault (token0 or token1 of underlying UniswapV2Pair) + /// @notice Receive amount of `assets` of underlying token of this Vault (token0 or token1 of underlying + /// UniswapV2Pair) function withdraw(uint256 assets_, address receiver_, address owner_) public override returns (uint256 shares) { shares = previewWithdraw(assets_); @@ -284,11 +301,13 @@ contract UniswapV2ERC4626Swap is ERC4626 { _burn(owner_, shares); - /// @dev ideally contract for token0/1 should know what assets amount to use without conditional checks, gas overhead + /// @dev ideally contract for token0/1 should know what assets amount to use without conditional checks, gas + /// overhead uint256 amount = asset == token0 ? _swapExit(assets1) + assets0 : _swapExit(assets0) + assets1; /// NOTE: This is a weak check anyways. previews can be manipulated. - /// NOTE: If enabled, withdraws() which didn't accrue enough of the yield to cover deposit's _swapJoin() will fail + /// NOTE: If enabled, withdraws() which didn't accrue enough of the yield to cover deposit's _swapJoin() will + /// fail /// NOTE: For secure execution user should use protected functions /// require(amount >= assets, "ASSETS_AMOUNT_OUT"); @@ -299,7 +318,12 @@ contract UniswapV2ERC4626Swap is ERC4626 { /// @notice Non-ERC4626 redeem function taking additional protection parameters for execution /// @dev Caller needs to know the amount of minAmountOut to receive for burning amount of shares beforehand - function redeem(uint256 shares_, address receiver_, address owner_, uint256 minAmountOut_) + function redeem( + uint256 shares_, + address receiver_, + address owner_, + uint256 minAmountOut_ + ) /// @dev calculated off-chain, "secure" withdraw function. public returns (uint256 assets) @@ -328,7 +352,8 @@ contract UniswapV2ERC4626Swap is ERC4626 { emit Withdraw(msg.sender, receiver_, owner_, amount, shares_); } - /// @notice Burn amount of 'shares' of this Vault (and UniswapV2Pair shares) to receive some amount of underlying token of this vault + /// @notice Burn amount of 'shares' of this Vault (and UniswapV2Pair shares) to receive some amount of underlying + /// token of this vault function redeem(uint256 shares_, address receiver_, address owner) public override returns (uint256 assets) { if (msg.sender != owner) { uint256 allowed = allowance[owner][msg.sender]; // Saves gas for limited approvals. @@ -345,7 +370,8 @@ contract UniswapV2ERC4626Swap is ERC4626 { _burn(owner, shares_); - /// @dev ideally contract for token0/1 should know what assets amount to use without conditional checks, gas overhead + /// @dev ideally contract for token0/1 should know what assets amount to use without conditional checks, gas + /// overhead uint256 amount = asset == token0 ? _swapExit(assets1) + assets0 : _swapExit(assets0) + assets1; /// NOTE: See note in withdraw() @@ -371,7 +397,8 @@ contract UniswapV2ERC4626Swap is ERC4626 { } /// @notice for this many shares/uniLp we need to pay at least this many assets - /// @dev adds slippage for over-approving asset to cover possible reserves fluctuation. value is returned to the user in full + /// @dev adds slippage for over-approving asset to cover possible reserves fluctuation. value is returned to the + /// user in full function previewMint(uint256 shares_) public view override returns (uint256 assets) { /// NOTE: Ensure this covers liquidity requested for a block! assets = mintAssets(shares_); @@ -392,7 +419,8 @@ contract UniswapV2ERC4626Swap is ERC4626 { assets = redeemAssets(shares_); } - /// @notice calculate value of shares of this vault as the sum of t0/t1 of UniV2 pair simulated as t0 or t1 total amount after swap + /// @notice calculate value of shares of this vault as the sum of t0/t1 of UniV2 pair simulated as t0 or t1 total + /// amount after swap /// @notice This is vulnerable to manipulation of getReserves! function mintAssets(uint256 shares_) public view returns (uint256 assets) { (uint256 reserveA, uint256 reserveB) = @@ -416,7 +444,8 @@ contract UniswapV2ERC4626Swap is ERC4626 { return a0 + UniswapV2Library.getAmountOut(a1, reserveB, reserveA); } - /// @notice separate from mintAssets virtual assets calculation from shares, but with omitted slippage to stop overwithdraw from Vault's balance + /// @notice separate from mintAssets virtual assets calculation from shares, but with omitted slippage to stop + /// overwithdraw from Vault's balance function redeemAssets(uint256 shares_) public view returns (uint256 assets) { (uint256 a0, uint256 a1) = getAssetsAmounts(shares_); @@ -434,7 +463,10 @@ contract UniswapV2ERC4626Swap is ERC4626 { //////////////////////////////////////////////////////////////*/ /// @dev NOTE: Unused now, useful for on-chain oracle implemented inside of deposit/mint standard ERC4626 functions - function _swapJoinProtected(uint256 assets_, uint256 minAmountOut_) + function _swapJoinProtected( + uint256 assets_, + uint256 minAmountOut_ + ) internal returns (uint256 amount0, uint256 amount1) { @@ -442,14 +474,16 @@ contract UniswapV2ERC4626Swap is ERC4626 { if (amount1 < minAmountOut_) revert NOT_MIN_AMOUNT_OUT(); } - /// @dev NOTE: Unused now, useful for on-chain oracle implemented inside of withdraw/redeem standard ERC4626 functions + /// @dev NOTE: Unused now, useful for on-chain oracle implemented inside of withdraw/redeem standard ERC4626 + /// functions function _swapExitProtected(uint256 assets_, uint256 minAmountOut_) internal returns (uint256 amounts) { (amounts) = _swapExit(assets_); if (amounts < minAmountOut_) revert NOT_MIN_AMOUNT_OUT(); } /// @notice directional swap from asset to opposite token (asset != tokenX) - /// @notice calculates optimal (for the current block) amount of token0/token1 to deposit into UniswapV2Pair and splits provided assets according to the formula + /// @notice calculates optimal (for the current block) amount of token0/token1 to deposit into UniswapV2Pair and + /// splits provided assets according to the formula function _swapJoin(uint256 assets_) internal returns (uint256 amount0, uint256 amount1) { uint256 reserve = _getReserves(); /// NOTE: @@ -474,7 +508,8 @@ contract UniswapV2ERC4626Swap is ERC4626 { } /// @notice directional swap from asset to opposite token (asset != tokenX) - /// @notice exit is in opposite direction to Join but we don't need to calculate splitting, just swap provided assets, check happens in withdraw/redeem + /// @notice exit is in opposite direction to Join but we don't need to calculate splitting, just swap provided + /// assets, check happens in withdraw/redeem function _swapExit(uint256 assets_) internal returns (uint256 amounts) { (address fromToken, address toToken) = _getExitToken(); amounts = DexSwap.swap( diff --git a/src/uniswap-v2/test/UniswapV2.t.sol b/src/uniswap-v2/test/UniswapV2.t.sol index 77d7830..b65b811 100644 --- a/src/uniswap-v2/test/UniswapV2.t.sol +++ b/src/uniswap-v2/test/UniswapV2.t.sol @@ -3,12 +3,12 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; import "forge-std/console.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {UniswapV2WrapperERC4626} from "../no-swap/UniswapV2WrapperERC4626.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { UniswapV2WrapperERC4626 } from "../no-swap/UniswapV2WrapperERC4626.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {IUniswapV2Pair} from "../interfaces/IUniswapV2Pair.sol"; -import {IUniswapV2Router} from "../interfaces/IUniswapV2Router.sol"; +import { IUniswapV2Pair } from "../interfaces/IUniswapV2Pair.sol"; +import { IUniswapV2Router } from "../interfaces/IUniswapV2Router.sol"; contract UniswapV2Test is Test { uint256 public ethFork; @@ -60,7 +60,7 @@ contract UniswapV2Test is Test { function testDepositMath() public { /// We use this odd number because UniLP amounts are oddly-small too - uint256 uniLpRequest = 887226683879712; + uint256 uniLpRequest = 887_226_683_879_712; vm.startPrank(alice); @@ -76,7 +76,7 @@ contract UniswapV2Test is Test { /// DepositWithdraw flow where user is using LP amount to calculate assets0/assets1 function testDepositWithdraw0() public { /// We use this odd number because UniLP amounts are oddly-small too - uint256 uniLpRequest = 887226683879712; + uint256 uniLpRequest = 887_226_683_879_712; vm.startPrank(alice); @@ -144,7 +144,7 @@ contract UniswapV2Test is Test { function testMintRedeem() public { /// We use this odd number because UniLP amounts are oddly-small too - uint256 uniLpRequest = 887226683879712; + uint256 uniLpRequest = 887_226_683_879_712; vm.startPrank(alice); diff --git a/src/uniswap-v2/test/UniswapV2Swap.t.sol b/src/uniswap-v2/test/UniswapV2Swap.t.sol index 74adacc..cb7e976 100644 --- a/src/uniswap-v2/test/UniswapV2Swap.t.sol +++ b/src/uniswap-v2/test/UniswapV2Swap.t.sol @@ -3,16 +3,16 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; import "forge-std/console.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {UniswapV2ERC4626Swap} from "../swap-built-in/UniswapV2ERC4626Swap.sol"; -import {UniswapV2ERC4626PoolFactory} from "../swap-built-in/UniswapV2ERC4626PoolFactory.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { UniswapV2ERC4626Swap } from "../swap-built-in/UniswapV2ERC4626Swap.sol"; +import { UniswapV2ERC4626PoolFactory } from "../swap-built-in/UniswapV2ERC4626PoolFactory.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {IUniswapV2Pair} from "../interfaces/IUniswapV2Pair.sol"; -import {IUniswapV2Router} from "../interfaces/IUniswapV2Router.sol"; +import { IUniswapV2Pair } from "../interfaces/IUniswapV2Pair.sol"; +import { IUniswapV2Router } from "../interfaces/IUniswapV2Router.sol"; -import {IUniswapV3Factory} from "../interfaces/IUniswapV3.sol"; -import {IUniswapV3Pool} from "../interfaces/IUniswapV3.sol"; +import { IUniswapV3Factory } from "../interfaces/IUniswapV3.sol"; +import { IUniswapV3Pool } from "../interfaces/IUniswapV3.sol"; contract UniswapV2TestSwap is Test { uint256 public ethFork; @@ -154,7 +154,7 @@ contract UniswapV2TestSwap is Test { /// as MINIMAL amount of shares. where function differs is that if user was to run calculations /// himself, directly against UniswapV2 Pair, calculations would output smaller number of assets /// required for that amountOfSharesToMint, that is because UniV2 Pair doesn't need to swapJoin() - uint256 amountOfSharesToMint = 44323816369031; + uint256 amountOfSharesToMint = 44_323_816_369_031; console.log("amountOfSharesToMint", amountOfSharesToMint); vm.startPrank(alice); diff --git a/src/uniswap-v2/test/UniswapV2SwapLocal.t.sol b/src/uniswap-v2/test/UniswapV2SwapLocal.t.sol index b1713ea..9863869 100644 --- a/src/uniswap-v2/test/UniswapV2SwapLocal.t.sol +++ b/src/uniswap-v2/test/UniswapV2SwapLocal.t.sol @@ -4,22 +4,22 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; import "forge-std/console.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {WETH} from "solmate/tokens/WETH.sol"; -import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { WETH } from "solmate/tokens/WETH.sol"; +import { MockERC20 } from "solmate/test/utils/mocks/MockERC20.sol"; -import {UniswapV2ERC4626Swap} from "../swap-built-in/UniswapV2ERC4626Swap.sol"; -import {UniswapV2ERC4626PoolFactory} from "../swap-built-in/UniswapV2ERC4626PoolFactory.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { UniswapV2ERC4626Swap } from "../swap-built-in/UniswapV2ERC4626Swap.sol"; +import { UniswapV2ERC4626PoolFactory } from "../swap-built-in/UniswapV2ERC4626PoolFactory.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {IUniswapV2Pair} from "../interfaces/IUniswapV2Pair.sol"; -import {IUniswapV2Router} from "../interfaces/IUniswapV2Router.sol"; +import { IUniswapV2Pair } from "../interfaces/IUniswapV2Pair.sol"; +import { IUniswapV2Router } from "../interfaces/IUniswapV2Router.sol"; /// @dev Deploying localhost UniswapV2 contracts -import {IUniswapV2Factory} from "../interfaces/IUniswapV2Factory.sol"; +import { IUniswapV2Factory } from "../interfaces/IUniswapV2Factory.sol"; -import {IUniswapV3Factory} from "../interfaces/IUniswapV3.sol"; -import {IUniswapV3Pool} from "../interfaces/IUniswapV3.sol"; +import { IUniswapV3Factory } from "../interfaces/IUniswapV3.sol"; +import { IUniswapV3Pool } from "../interfaces/IUniswapV3.sol"; contract UniswapV2TestSwapLocalHost is Test { using FixedPointMathLib for uint256; @@ -101,7 +101,7 @@ contract UniswapV2TestSwapLocalHost is Test { function seedLiquidity() public { for (uint256 i = 0; i < 100; i++) { - uint256 amount = 10000e18; + uint256 amount = 10_000e18; /// @dev generate pseudo random address for 100 deposits into pool address poolUser = address(uint160(uint256(keccak256(abi.encodePacked(i, blockhash(block.number)))))); @@ -228,7 +228,7 @@ contract UniswapV2TestSwapLocalHost is Test { /// as MINIMAL amount of shares. where function differs is that if user was to run calculations /// himself, directly against UniswapV2 Pair, calculations would output smaller number of assets /// required for that amountOfSharesToMint, that is because UniV2 Pair doesn't need to swapJoin() - uint256 amountOfSharesToMint = 44323816369031; + uint256 amountOfSharesToMint = 44_323_816_369_031; console.log("amountOfSharesToMint", amountOfSharesToMint); vm.startPrank(alice); @@ -362,7 +362,8 @@ contract UniswapV2TestSwapLocalHost is Test { /// alice should be able to withdraw more assets than she deposited assertGe(aliceAssetsToWithdraw, amount); - /// @dev Here, caller assumes trust in previewRedeem, under normal circumstances it should be queried few times or calculated fully off-chain + /// @dev Here, caller assumes trust in previewRedeem, under normal circumstances it should be queried few times + /// or calculated fully off-chain uint256 minAmountOut = vault.previewRedeem(aliceShareBalance); /// TODO: Investiage why here we need to give higher slippage? minAmountOut = (minAmountOut * 995) / 1000; @@ -386,7 +387,7 @@ contract UniswapV2TestSwapLocalHost is Test { } function testProtectedMintRedeem() public { - uint256 amountOfSharesToMint = 44323816369031; + uint256 amountOfSharesToMint = 44_323_816_369_031; console.log("amountOfSharesToMint", amountOfSharesToMint); vm.startPrank(alice); @@ -399,7 +400,8 @@ contract UniswapV2TestSwapLocalHost is Test { asset.approve(address(vault), assetsToApprove); - /// @dev Caller assumes trust in previewMint, under normal circumstances it should be queried few times or calculated fully off-chain + /// @dev Caller assumes trust in previewMint, under normal circumstances it should be queried few times or + /// calculated fully off-chain uint256 minSharesOut = (amountOfSharesToMint * 997) / 1000; uint256 aliceAssetsMinted = vault.mint(amountOfSharesToMint, alice, minSharesOut); @@ -423,7 +425,8 @@ contract UniswapV2TestSwapLocalHost is Test { uint256 aliceSharesToBurn = vault.previewWithdraw(aliceAssetsToWithdraw); console.log("aliceSharesToBurn", aliceSharesToBurn); - /// @dev Caller assumes trust in previewMint, under normal circumstances it should be queried few times or calculated fully off-chain + /// @dev Caller assumes trust in previewMint, under normal circumstances it should be queried few times or + /// calculated fully off-chain uint256 minAmountOut = (aliceAssetsToWithdraw * 30) / 1000; uint256 assetsReceived = vault.redeem(aliceBalanceOfShares, alice, alice, minAmountOut); diff --git a/src/uniswap-v2/utils/UniswapV2Library.sol b/src/uniswap-v2/utils/UniswapV2Library.sol index de1607b..6d5d290 100644 --- a/src/uniswap-v2/utils/UniswapV2Library.sol +++ b/src/uniswap-v2/utils/UniswapV2Library.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {IUniswapV2Pair} from "../interfaces/IUniswapV2Pair.sol"; +import { IUniswapV2Pair } from "../interfaces/IUniswapV2Pair.sol"; library SafeMath { function add(uint256 x, uint256 y) internal pure returns (uint256 z) { @@ -22,7 +22,7 @@ library UniswapV2Library { /// @dev implementation details: https://blog.alphaventuredao.io/onesideduniswap/ function getSwapAmount(uint256 resA, uint256 amt) internal pure returns (uint256) { - return (sqrt(resA.mul(resA.mul(3988009) + amt.mul(3988000))).sub(resA.mul(1997))) / 1994; + return (sqrt(resA.mul(resA.mul(3_988_009) + amt.mul(3_988_000))).sub(resA.mul(1997))) / 1994; } // returns sorted token addresses, used to handle return values from pairs sorted in this order @@ -34,7 +34,11 @@ library UniswapV2Library { // fetches and sorts the reserves for a pair /// NOTE: Original lib implementation changed to accept pair address directly - function getReserves(address pair, address tokenA, address tokenB) + function getReserves( + address pair, + address tokenA, + address tokenB + ) internal view returns (uint256 reserveA, uint256 reserveB) @@ -52,7 +56,11 @@ library UniswapV2Library { } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset - function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut) + function getAmountOut( + uint256 amountIn, + uint256 reserveIn, + uint256 reserveOut + ) internal pure returns (uint256 amountOut) @@ -66,7 +74,11 @@ library UniswapV2Library { } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset - function getAmountIn(uint256 amountOut, uint256 reserveIn, uint256 reserveOut) + function getAmountIn( + uint256 amountOut, + uint256 reserveIn, + uint256 reserveOut + ) internal pure returns (uint256 amountIn) @@ -79,7 +91,11 @@ library UniswapV2Library { } // performs chained getAmountOut calculations on any number of pairs - function getAmountsOut(address factory, uint256 amountIn, address[] memory path) + function getAmountsOut( + address factory, + uint256 amountIn, + address[] memory path + ) internal view returns (uint256[] memory amounts) @@ -94,7 +110,11 @@ library UniswapV2Library { } // performs chained getAmountIn calculations on any number of pairs - function getAmountsIn(address factory, uint256 amountOut, address[] memory path) + function getAmountsIn( + address factory, + uint256 amountOut, + address[] memory path + ) internal view returns (uint256[] memory amounts) diff --git a/src/venus/VenusERC4626Reinvest.sol b/src/venus/VenusERC4626Reinvest.sol index 92429b4..6193b12 100644 --- a/src/venus/VenusERC4626Reinvest.sol +++ b/src/venus/VenusERC4626Reinvest.sol @@ -1,16 +1,16 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {ERC4626} from "solmate/mixins/ERC4626.sol"; -import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { ERC4626 } from "solmate/mixins/ERC4626.sol"; +import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {IVERC20} from "./external/IVERC20.sol"; -import {LibVCompound} from "./external/LibVCompound.sol"; -import {IVComptroller} from "./external/IVComptroller.sol"; +import { IVERC20 } from "./external/IVERC20.sol"; +import { LibVCompound } from "./external/LibVCompound.sol"; +import { IVComptroller } from "./external/IVComptroller.sol"; -import {DexSwap} from "../_global/swapUtils.sol"; +import { DexSwap } from "../_global/swapUtils.sol"; /// @title VenusERC4626Reinvest /// @notice Extended implementation of yield-daddy CompoundV2 wrapper @@ -82,7 +82,13 @@ contract VenusERC4626Reinvest is ERC4626 { /// @param cToken_ The address of the cToken contract /// @param comptroller_ The address of the comptroller contract /// @param manager_ The address of the manager - constructor(ERC20 asset_, ERC20 reward_, IVERC20 cToken_, IVComptroller comptroller_, address manager_) + constructor( + ERC20 asset_, + ERC20 reward_, + IVERC20 cToken_, + IVComptroller comptroller_, + address manager_ + ) ERC4626(asset_, _vaultName(asset_), _vaultSymbol(asset_)) { reward = reward_; diff --git a/src/venus/external/IVComptroller.sol b/src/venus/external/IVComptroller.sol index dbc782a..ac3ff80 100644 --- a/src/venus/external/IVComptroller.sol +++ b/src/venus/external/IVComptroller.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {IVERC20} from "./IVERC20.sol"; +import { IVERC20 } from "./IVERC20.sol"; interface IVComptroller { struct VenusMarketState { diff --git a/src/venus/external/IVERC20.sol b/src/venus/external/IVERC20.sol index ac84013..c3c4c73 100644 --- a/src/venus/external/IVERC20.sol +++ b/src/venus/external/IVERC20.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {ERC20} from "solmate/tokens/ERC20.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; -import {IVInterestRateModel} from "./IVInterestRateModel.sol"; +import { IVInterestRateModel } from "./IVInterestRateModel.sol"; abstract contract IVERC20 is ERC20 { function mint(uint256 underlyingAmount) external virtual returns (uint256); diff --git a/src/venus/external/LibVCompound.sol b/src/venus/external/LibVCompound.sol index f484e0d..934a61e 100644 --- a/src/venus/external/LibVCompound.sol +++ b/src/venus/external/LibVCompound.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.21; -import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol"; +import { FixedPointMathLib } from "solmate/utils/FixedPointMathLib.sol"; -import {IVERC20} from "./IVERC20.sol"; +import { IVERC20 } from "./IVERC20.sol"; /// @notice Get up to date cToken data without mutating state. /// @notice Forked from Transmissions11 (https://github.com/transmissions11/libcompound) to upgrade version @@ -30,7 +30,8 @@ library LibVCompound { uint256 borrowRateMantissa = cToken.interestRateModel().getBorrowRate(totalCash, borrowsPrior, reservesPrior); - if (borrowRateMantissa > 0.0005e16) revert RATE_TOO_HIGH(); // Same as borrowRateMaxMantissa in CTokenInterfaces.sol + if (borrowRateMantissa > 0.0005e16) revert RATE_TOO_HIGH(); // Same as borrowRateMaxMantissa in + // CTokenInterfaces.sol uint256 interestAccumulated = (borrowRateMantissa * (block.number - accrualBlockNumberPrior)).mulWadDown(borrowsPrior); diff --git a/src/venus/test/VenusERC4626Harvest.t.sol b/src/venus/test/VenusERC4626Harvest.t.sol index 9497ccf..e12d82c 100644 --- a/src/venus/test/VenusERC4626Harvest.t.sol +++ b/src/venus/test/VenusERC4626Harvest.t.sol @@ -2,12 +2,12 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {VenusERC4626Reinvest} from "../VenusERC4626Reinvest.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { VenusERC4626Reinvest } from "../VenusERC4626Reinvest.sol"; -import {IVERC20} from "../external/IVERC20.sol"; -import {LibVCompound} from "../external/LibVCompound.sol"; -import {IVComptroller} from "../external/IVComptroller.sol"; +import { IVERC20 } from "../external/IVERC20.sol"; +import { LibVCompound } from "../external/LibVCompound.sol"; +import { IVComptroller } from "../external/IVComptroller.sol"; contract VenusERC4626HarvestTest is Test { uint256 public fork; @@ -76,8 +76,8 @@ contract VenusERC4626HarvestTest is Test { alice = address(0x1); bob = address(0x2); - deal(address(asset), alice, 100000 ether); - deal(address(asset), bob, 100000 ether); + deal(address(asset), alice, 100_000 ether); + deal(address(asset), bob, 100_000 ether); /// @dev Making contracts persistent vm.makePersistent(address(comptroller)); @@ -89,7 +89,7 @@ contract VenusERC4626HarvestTest is Test { } function testHarvestUSDC() public { - uint256 amount = 100000 ether; + uint256 amount = 100_000 ether; /// @dev split for more deposits to calculate delta correctly uint256 halfAmount = amount / 2; diff --git a/src/venus/test/VenusERC4626Wrapper.t.sol b/src/venus/test/VenusERC4626Wrapper.t.sol index 5370386..fc46b3b 100644 --- a/src/venus/test/VenusERC4626Wrapper.t.sol +++ b/src/venus/test/VenusERC4626Wrapper.t.sol @@ -2,12 +2,12 @@ pragma solidity 0.8.21; import "forge-std/Test.sol"; -import {ERC20} from "solmate/tokens/ERC20.sol"; -import {VenusERC4626Reinvest} from "../VenusERC4626Reinvest.sol"; +import { ERC20 } from "solmate/tokens/ERC20.sol"; +import { VenusERC4626Reinvest } from "../VenusERC4626Reinvest.sol"; -import {IVERC20} from "../external/IVERC20.sol"; -import {LibVCompound} from "../external/LibVCompound.sol"; -import {IVComptroller} from "../external/IVComptroller.sol"; +import { IVERC20 } from "../external/IVERC20.sol"; +import { LibVCompound } from "../external/LibVCompound.sol"; +import { IVComptroller } from "../external/IVComptroller.sol"; contract VenusERC4626WrapperTest is Test { uint256 public fork; @@ -78,8 +78,8 @@ contract VenusERC4626WrapperTest is Test { function setUp() public { alice = address(0x1); bob = address(0x2); - deal(address(asset), alice, 100000 ether); - deal(address(asset), bob, 100000 ether); + deal(address(asset), alice, 100_000 ether); + deal(address(asset), bob, 100_000 ether); } function testDepositWithdrawUSDC() public { @@ -146,7 +146,7 @@ contract VenusERC4626WrapperTest is Test { } function testHarvest() public { - uint256 amount = 10000 ether; + uint256 amount = 10_000 ether; fork = vm.createFork(BSC_RPC_URL); From 84b98a86c1fff0f8573dde4161f1ae85195b59bf Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:29:25 +0100 Subject: [PATCH 2/5] fix: remove oz --- .gitmodules | 3 --- lib/openzeppelin-contracts | 1 - 2 files changed, 4 deletions(-) delete mode 160000 lib/openzeppelin-contracts diff --git a/.gitmodules b/.gitmodules index 6f2fbb7..633f51b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "lib/ds-test"] path = lib/ds-test url = https://github.com/dapphub/ds-test -[submodule "lib/openzeppelin-contracts"] - path = lib/openzeppelin-contracts - url = https://github.com/OpenZeppelin/openzeppelin-contracts [submodule "lib/solmate"] path = lib/solmate url = https://github.com/Rari-Capital/solmate diff --git a/lib/openzeppelin-contracts b/lib/openzeppelin-contracts deleted file mode 160000 index 60e3ffe..0000000 --- a/lib/openzeppelin-contracts +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 60e3ffe6a3cc38ab94cae995bc1de081eed79335 From 526df92682b0ba2d90dba22a47df87e1499a59a4 Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:33:32 +0100 Subject: [PATCH 3/5] fix: --- lib/openzeppelin-contracts | 1 + 1 file changed, 1 insertion(+) create mode 160000 lib/openzeppelin-contracts diff --git a/lib/openzeppelin-contracts b/lib/openzeppelin-contracts new file mode 160000 index 0000000..60e3ffe --- /dev/null +++ b/lib/openzeppelin-contracts @@ -0,0 +1 @@ +Subproject commit 60e3ffe6a3cc38ab94cae995bc1de081eed79335 From 6b47ab7cf327698409552a8ff1aeda65b5f9b719 Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:33:49 +0100 Subject: [PATCH 4/5] fix: --- lib/openzeppelin-contracts | 1 - 1 file changed, 1 deletion(-) delete mode 160000 lib/openzeppelin-contracts diff --git a/lib/openzeppelin-contracts b/lib/openzeppelin-contracts deleted file mode 160000 index 60e3ffe..0000000 --- a/lib/openzeppelin-contracts +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 60e3ffe6a3cc38ab94cae995bc1de081eed79335 From 313e8c3d06bab1e7c49efdc02754891f74b1f00e Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:33:54 +0100 Subject: [PATCH 5/5] forge install: openzeppelin-contracts v4.9.3 --- .gitmodules | 3 +++ lib/openzeppelin-contracts | 1 + 2 files changed, 4 insertions(+) create mode 160000 lib/openzeppelin-contracts diff --git a/.gitmodules b/.gitmodules index 633f51b..53b7a1f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -17,3 +17,6 @@ [submodule "lib/v2-periphery"] path = lib/v2-periphery url = https://github.com/Uniswap/v2-periphery +[submodule "lib/openzeppelin-contracts"] + path = lib/openzeppelin-contracts + url = https://github.com/OpenZeppelin/openzeppelin-contracts diff --git a/lib/openzeppelin-contracts b/lib/openzeppelin-contracts new file mode 160000 index 0000000..fd81a96 --- /dev/null +++ b/lib/openzeppelin-contracts @@ -0,0 +1 @@ +Subproject commit fd81a96f01cc42ef1c9a5399364968d0e07e9e90