From 5ab7a8dd543c5cd20f1686c06e66521a8bc9fbbb Mon Sep 17 00:00:00 2001 From: Hrik Bhowal Date: Wed, 6 Mar 2024 19:51:03 -0500 Subject: [PATCH 1/2] refactor: separate lst and lrt contracts into folders --- script/__TestFlashLeverage.s.sol | 6 +- script/deploy-test/08_DeployHandlers.t.sol | 2 +- ...5_DeployInitialReserveAndSpotOracles.s.sol | 4 +- script/deploy/08_DeployHandlers.s.sol | 4 +- .../BalancerFlashloanDirectMintHandler.sol | 2 +- .../{handlers/base => }/IonHandlerBase.sol | 12 +- .../UniswapFlashloanBalancerSwapHandler.sol | 4 +- .../UniswapFlashswapDirectMintHandler.sol | 2 +- .../base => }/UniswapFlashswapHandler.sol | 2 +- src/flash/{handlers => lrt}/RsEthHandler.sol | 6 +- src/flash/{handlers => lrt}/WeEthHandler.sol | 6 +- src/flash/{handlers => lst}/EthXHandler.sol | 10 +- src/flash/{handlers => lst}/SwEthHandler.sol | 8 +- src/flash/{handlers => lst}/WstEthHandler.sol | 8 +- src/libraries/{ => lrt}/EtherFiLibrary.sol | 4 +- src/libraries/{ => lrt}/KelpDaoLibrary.sol | 7 +- src/libraries/{ => lst}/LidoLibrary.sol | 6 +- src/libraries/{ => lst}/StaderLibrary.sol | 2 +- src/libraries/{ => lst}/SwellLibrary.sol | 4 +- .../{ => lrt}/RsEthWstEthReserveOracle.sol | 8 +- .../{ => lrt}/WeEthWstEthReserveOracle.sol | 8 +- .../reserve/{ => lst}/EthXReserveOracle.sol | 4 +- .../reserve/{ => lst}/SwEthReserveOracle.sol | 4 +- .../reserve/{ => lst}/WstEthReserveOracle.sol | 4 +- .../spot/{ => lrt}/RsEthWstEthSpotOracle.sol | 8 +- .../spot/{ => lrt}/WeEthWstEthSpotOracle.sol | 8 +- src/oracles/spot/{ => lst}/EthXSpotOracle.sol | 6 +- .../spot/{ => lst}/SwEthSpotOracle.sol | 8 +- .../spot/{ => lst}/WstEthSpotOracle.sol | 6 +- test/differential/IonPoolFrobBoolean.t.sol | 1 + test/fork/concrete/ReserveOracleFork.t.sol | 151 --------- .../WeEthWstEthReserveOracleFork.t.sol | 223 ------------- ...ieldOracleFork.t.sol => YieldOracle.t.sol} | 0 .../BalancerFlashloanDirectMintHandler.t.sol | 5 +- .../UniswapFlashloanBalancerSwapHandler.t.sol | 5 +- .../UniswapFlashswapDirectMintHandler.t.sol | 3 +- .../UniswapFlashswapHandler.t.sol | 4 +- test/fork/concrete/lrt/ReserveOracle.t.sol | 297 ++++++++++++++++++ .../RsEthHandler.t.sol} | 18 +- .../SpotOracle.t.sol} | 29 +- .../WeEthHandler.t.sol} | 18 +- .../EthXHandler.t.sol} | 18 +- .../EthXReserveOracle.t.sol} | 12 +- test/fork/concrete/{ => lst}/SpotOracle.t.sol | 108 +------ .../SwEthHandler.t.sol} | 18 +- .../SwEthReserveOracle.t.sol} | 12 +- .../WstEthHandler.t.sol} | 22 +- .../WstEthReserveOracle.t.sol} | 12 +- .../BalancerFlashloanDirectMintHandler.t.sol | 3 +- .../UniswapFlashloanBalancerSwapHandler.t.sol | 3 +- .../UniswapFlashswapDirectMintHandler.t.sol | 3 +- .../UniswapFlashswapHandler.t.sol | 2 +- test/fork/fuzz/{ => lrt}/EtherFiLibrary.t.sol | 6 +- test/fork/fuzz/{ => lrt}/KelpDaoLibrary.t.sol | 6 +- .../RsEthHandler.t.sol} | 8 +- .../WeEthHandler.t.sol} | 8 +- .../EthXHandler.t.sol} | 16 +- test/fork/fuzz/{ => lst}/LidoLibrary.t.sol | 6 +- test/fork/fuzz/{ => lst}/StaderLibrary.t.sol | 4 +- .../SwEthHandler.t.sol} | 12 +- test/fork/fuzz/{ => lst}/SwellLibrary.t.sol | 4 +- .../WstEthHandler.t.sol} | 14 +- test/helpers/handlers/LrtHandlerForkBase.sol | 2 +- test/integration/concrete/WeEthIonPool.t.sol | 8 +- test/unit/concrete/SwEthHandler.t.sol | 2 +- test/unit/concrete/WstEthHandler.t.sol | 2 +- 66 files changed, 535 insertions(+), 693 deletions(-) rename src/flash/{handlers/base => }/BalancerFlashloanDirectMintHandler.sol (99%) rename src/flash/{handlers/base => }/IonHandlerBase.sol (96%) rename src/flash/{handlers/base => }/UniswapFlashloanBalancerSwapHandler.sol (99%) rename src/flash/{handlers/base => }/UniswapFlashswapDirectMintHandler.sol (99%) rename src/flash/{handlers/base => }/UniswapFlashswapHandler.sol (99%) rename src/flash/{handlers => lrt}/RsEthHandler.sol (88%) rename src/flash/{handlers => lrt}/WeEthHandler.sol (89%) rename src/flash/{handlers => lst}/EthXHandler.sol (87%) rename src/flash/{handlers => lst}/SwEthHandler.sol (88%) rename src/flash/{handlers => lst}/WstEthHandler.sol (94%) rename src/libraries/{ => lrt}/EtherFiLibrary.sol (97%) rename src/libraries/{ => lrt}/KelpDaoLibrary.sol (90%) rename src/libraries/{ => lst}/LidoLibrary.sol (89%) rename src/libraries/{ => lst}/StaderLibrary.sol (95%) rename src/libraries/{ => lst}/SwellLibrary.sol (91%) rename src/oracles/reserve/{ => lrt}/RsEthWstEthReserveOracle.sol (83%) rename src/oracles/reserve/{ => lrt}/WeEthWstEthReserveOracle.sol (85%) rename src/oracles/reserve/{ => lst}/EthXReserveOracle.sol (90%) rename src/oracles/reserve/{ => lst}/SwEthReserveOracle.sol (91%) rename src/oracles/reserve/{ => lst}/WstEthReserveOracle.sol (92%) rename src/oracles/spot/{ => lrt}/RsEthWstEthSpotOracle.sol (91%) rename src/oracles/spot/{ => lrt}/WeEthWstEthSpotOracle.sol (91%) rename src/oracles/spot/{ => lst}/EthXSpotOracle.sol (92%) rename src/oracles/spot/{ => lst}/SwEthSpotOracle.sol (88%) rename src/oracles/spot/{ => lst}/WstEthSpotOracle.sol (91%) delete mode 100644 test/fork/concrete/ReserveOracleFork.t.sol delete mode 100644 test/fork/concrete/WeEthWstEthReserveOracleFork.t.sol rename test/fork/concrete/{YieldOracleFork.t.sol => YieldOracle.t.sol} (100%) create mode 100644 test/fork/concrete/lrt/ReserveOracle.t.sol rename test/fork/concrete/{RsEthHandlerFork.t.sol => lrt/RsEthHandler.t.sol} (84%) rename test/fork/concrete/{SpotOracleFork.t.sol => lrt/SpotOracle.t.sol} (69%) rename test/fork/concrete/{WeEthHandlerFork.t.sol => lrt/WeEthHandler.t.sol} (85%) rename test/fork/concrete/{EthXHandlerFork.t.sol => lst/EthXHandler.t.sol} (84%) rename test/fork/concrete/{EthXReserveOracleFork.t.sol => lst/EthXReserveOracle.t.sol} (93%) rename test/fork/concrete/{ => lst}/SpotOracle.t.sol (61%) rename test/fork/concrete/{SwEthHandlerFork.t.sol => lst/SwEthHandler.t.sol} (84%) rename test/fork/concrete/{SwEthReserveOracleFork.t.sol => lst/SwEthReserveOracle.t.sol} (94%) rename test/fork/concrete/{WstEthHandlerFork.t.sol => lst/WstEthHandler.t.sol} (96%) rename test/fork/concrete/{WstEthReserveOracleFork.t.sol => lst/WstEthReserveOracle.t.sol} (93%) rename test/fork/fuzz/{ => lrt}/EtherFiLibrary.t.sol (85%) rename test/fork/fuzz/{ => lrt}/KelpDaoLibrary.t.sol (89%) rename test/fork/fuzz/{RsEthHandlerForkFuzz.t.sol => lrt/RsEthHandler.t.sol} (79%) rename test/fork/fuzz/{WeEthHandlerForkFuzz.t.sol => lrt/WeEthHandler.t.sol} (80%) rename test/fork/fuzz/{EthXHandlerForkFuzz.t.sol => lst/EthXHandler.t.sol} (71%) rename test/fork/fuzz/{ => lst}/LidoLibrary.t.sol (87%) rename test/fork/fuzz/{ => lst}/StaderLibrary.t.sol (94%) rename test/fork/fuzz/{SwEthHandlerForkFuzz.t.sol => lst/SwEthHandler.t.sol} (69%) rename test/fork/fuzz/{ => lst}/SwellLibrary.t.sol (90%) rename test/fork/fuzz/{WstEthHandlerForkFuzz.t.sol => lst/WstEthHandler.t.sol} (95%) diff --git a/script/__TestFlashLeverage.s.sol b/script/__TestFlashLeverage.s.sol index 30426080..55f0276d 100644 --- a/script/__TestFlashLeverage.s.sol +++ b/script/__TestFlashLeverage.s.sol @@ -2,12 +2,12 @@ pragma solidity 0.8.21; import { IonPool } from "../src/IonPool.sol"; -import { RsEthHandler } from "../src/flash/handlers/RsEthHandler.sol"; +import { RsEthHandler } from "../src/flash/lrt/RsEthHandler.sol"; import { Whitelist } from "../src/Whitelist.sol"; import { IWstEth, IRsEth } from "../src/interfaces/ProviderInterfaces.sol"; import { WSTETH_ADDRESS, RSETH } from "../src/Constants.sol"; -import { LidoLibrary } from "../src/libraries/LidoLibrary.sol"; -import { KelpDaoLibrary } from "./../src/libraries/KelpDaoLibrary.sol"; +import { LidoLibrary } from "../src/libraries/lst/LidoLibrary.sol"; +import { KelpDaoLibrary } from "../src/libraries/lrt/KelpDaoLibrary.sol"; import { BaseScript } from "./Base.s.sol"; diff --git a/script/deploy-test/08_DeployHandlers.t.sol b/script/deploy-test/08_DeployHandlers.t.sol index f4f3697c..ad251071 100644 --- a/script/deploy-test/08_DeployHandlers.t.sol +++ b/script/deploy-test/08_DeployHandlers.t.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.21; import { DeployTestBase } from "./00_DeployTestBase.t.sol"; import { DeployHandlersScript } from "../deploy/08_DeployHandlers.s.sol"; -import { IonHandlerBase } from "../../src/flash/handlers/base/IonHandlerBase.sol"; +import { IonHandlerBase } from "../../src/flash/IonHandlerBase.sol"; contract DeployHandlersTest is DeployTestBase, DeployHandlersScript { function checkState(IonHandlerBase handler) public { diff --git a/script/deploy/05_DeployInitialReserveAndSpotOracles.s.sol b/script/deploy/05_DeployInitialReserveAndSpotOracles.s.sol index 5c238db1..6af54b31 100644 --- a/script/deploy/05_DeployInitialReserveAndSpotOracles.s.sol +++ b/script/deploy/05_DeployInitialReserveAndSpotOracles.s.sol @@ -3,8 +3,8 @@ pragma solidity 0.8.21; import { DeployScript } from "../Deploy.s.sol"; import { RAY } from "../../src/libraries/math/WadRayMath.sol"; -import { RsEthWstEthReserveOracle } from "../../src/oracles/reserve/RsEthWstEthReserveOracle.sol"; -import { RsEthWstEthSpotOracle } from "../../src/oracles/spot/RsEthWstEthSpotOracle.sol"; +import { RsEthWstEthReserveOracle } from "../../src/oracles/reserve/lrt/RsEthWstEthReserveOracle.sol"; +import { RsEthWstEthSpotOracle } from "../../src/oracles/spot/lrt/RsEthWstEthSpotOracle.sol"; import { stdJson as StdJson } from "forge-std/StdJson.sol"; diff --git a/script/deploy/08_DeployHandlers.s.sol b/script/deploy/08_DeployHandlers.s.sol index 92f4cae8..7ab9c51b 100644 --- a/script/deploy/08_DeployHandlers.s.sol +++ b/script/deploy/08_DeployHandlers.s.sol @@ -6,8 +6,8 @@ import { DeployScript } from "../Deploy.s.sol"; import { IonPool } from "../../src/IonPool.sol"; import { GemJoin } from "../../src/join/GemJoin.sol"; import { Whitelist } from "../../src/Whitelist.sol"; -import { IonHandlerBase } from "../../src/flash/handlers/base/IonHandlerBase.sol"; -import { RsEthHandler } from "../../src/flash/handlers/RsEthHandler.sol"; +import { IonHandlerBase } from "../../src/flash/IonHandlerBase.sol"; +import { RsEthHandler } from "../../src/flash/lrt/RsEthHandler.sol"; import { stdJson as StdJson } from "forge-std/StdJson.sol"; diff --git a/src/flash/handlers/base/BalancerFlashloanDirectMintHandler.sol b/src/flash/BalancerFlashloanDirectMintHandler.sol similarity index 99% rename from src/flash/handlers/base/BalancerFlashloanDirectMintHandler.sol rename to src/flash/BalancerFlashloanDirectMintHandler.sol index 639bdf76..19d3e5e0 100644 --- a/src/flash/handlers/base/BalancerFlashloanDirectMintHandler.sol +++ b/src/flash/BalancerFlashloanDirectMintHandler.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.21; import { IonHandlerBase } from "./IonHandlerBase.sol"; -import { IWETH9 } from "../../../interfaces/IWETH9.sol"; +import { IWETH9 } from "../interfaces/IWETH9.sol"; import { IVault, IERC20 as IERC20Balancer } from "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol"; import { IFlashLoanRecipient } from "@balancer-labs/v2-interfaces/contracts/vault/IFlashLoanRecipient.sol"; diff --git a/src/flash/handlers/base/IonHandlerBase.sol b/src/flash/IonHandlerBase.sol similarity index 96% rename from src/flash/handlers/base/IonHandlerBase.sol rename to src/flash/IonHandlerBase.sol index b4c9d005..b1312f14 100644 --- a/src/flash/handlers/base/IonHandlerBase.sol +++ b/src/flash/IonHandlerBase.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.21; -import { IonPool } from "../../../IonPool.sol"; -import { IWETH9 } from "../../../interfaces/IWETH9.sol"; -import { GemJoin } from "../../../join/GemJoin.sol"; -import { WadRayMath, RAY } from "../../../libraries/math/WadRayMath.sol"; -import { Whitelist } from "../../../Whitelist.sol"; -import { WETH_ADDRESS } from "../../../Constants.sol"; +import { IonPool } from "../IonPool.sol"; +import { IWETH9 } from "../interfaces/IWETH9.sol"; +import { GemJoin } from "../join/GemJoin.sol"; +import { WadRayMath, RAY } from "../libraries/math/WadRayMath.sol"; +import { Whitelist } from "../Whitelist.sol"; +import { WETH_ADDRESS } from "../Constants.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; diff --git a/src/flash/handlers/base/UniswapFlashloanBalancerSwapHandler.sol b/src/flash/UniswapFlashloanBalancerSwapHandler.sol similarity index 99% rename from src/flash/handlers/base/UniswapFlashloanBalancerSwapHandler.sol rename to src/flash/UniswapFlashloanBalancerSwapHandler.sol index c7f8d77f..8d2f82d5 100644 --- a/src/flash/handlers/base/UniswapFlashloanBalancerSwapHandler.sol +++ b/src/flash/UniswapFlashloanBalancerSwapHandler.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.21; -import { IWETH9 } from "../../../interfaces/IWETH9.sol"; +import { IWETH9 } from "../interfaces/IWETH9.sol"; import { IonHandlerBase } from "./IonHandlerBase.sol"; -import { IWETH9 } from "../../../interfaces/IWETH9.sol"; +import { IWETH9 } from "../interfaces/IWETH9.sol"; import { IUniswapV3Pool } from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; import { IUniswapV3FlashCallback } from "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3FlashCallback.sol"; diff --git a/src/flash/handlers/base/UniswapFlashswapDirectMintHandler.sol b/src/flash/UniswapFlashswapDirectMintHandler.sol similarity index 99% rename from src/flash/handlers/base/UniswapFlashswapDirectMintHandler.sol rename to src/flash/UniswapFlashswapDirectMintHandler.sol index 0d50af12..1634ac5a 100644 --- a/src/flash/handlers/base/UniswapFlashswapDirectMintHandler.sol +++ b/src/flash/UniswapFlashswapDirectMintHandler.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.21; import { IonHandlerBase } from "./IonHandlerBase.sol"; -import { IWETH9 } from "../../../interfaces/IWETH9.sol"; +import { IWETH9 } from "../interfaces/IWETH9.sol"; import { IUniswapV3Pool } from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; import { IUniswapV3SwapCallback } from "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol"; diff --git a/src/flash/handlers/base/UniswapFlashswapHandler.sol b/src/flash/UniswapFlashswapHandler.sol similarity index 99% rename from src/flash/handlers/base/UniswapFlashswapHandler.sol rename to src/flash/UniswapFlashswapHandler.sol index f28309ac..94d4cfc3 100644 --- a/src/flash/handlers/base/UniswapFlashswapHandler.sol +++ b/src/flash/UniswapFlashswapHandler.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.21; import { IonHandlerBase } from "./IonHandlerBase.sol"; -import { WadRayMath } from "../../../libraries/math/WadRayMath.sol"; +import { WadRayMath } from "../libraries/math/WadRayMath.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; diff --git a/src/flash/handlers/RsEthHandler.sol b/src/flash/lrt/RsEthHandler.sol similarity index 88% rename from src/flash/handlers/RsEthHandler.sol rename to src/flash/lrt/RsEthHandler.sol index 21b1b76b..9c556b46 100644 --- a/src/flash/handlers/RsEthHandler.sol +++ b/src/flash/lrt/RsEthHandler.sol @@ -5,10 +5,10 @@ import { IonPool } from "../../IonPool.sol"; import { GemJoin } from "../../join/GemJoin.sol"; import { IRsEth } from "../../interfaces/ProviderInterfaces.sol"; import { Whitelist } from "../../Whitelist.sol"; -import { UniswapFlashswapDirectMintHandler } from "./base/UniswapFlashswapDirectMintHandler.sol"; -import { IonHandlerBase } from "./base/IonHandlerBase.sol"; +import { UniswapFlashswapDirectMintHandler } from "../UniswapFlashswapDirectMintHandler.sol"; +import { IonHandlerBase } from "../IonHandlerBase.sol"; import { RSETH, WETH_ADDRESS } from "../../Constants.sol"; -import { KelpDaoLibrary } from "./../../libraries/KelpDaoLibrary.sol"; +import { KelpDaoLibrary } from "../../libraries/lrt/KelpDaoLibrary.sol"; import { IUniswapV3Pool } from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; diff --git a/src/flash/handlers/WeEthHandler.sol b/src/flash/lrt/WeEthHandler.sol similarity index 89% rename from src/flash/handlers/WeEthHandler.sol rename to src/flash/lrt/WeEthHandler.sol index d3fdc768..5972c6f4 100644 --- a/src/flash/handlers/WeEthHandler.sol +++ b/src/flash/lrt/WeEthHandler.sol @@ -5,9 +5,9 @@ import { IonPool } from "../../IonPool.sol"; import { GemJoin } from "../../join/GemJoin.sol"; import { IWeEth } from "../../interfaces/ProviderInterfaces.sol"; import { Whitelist } from "../../Whitelist.sol"; -import { UniswapFlashswapDirectMintHandler } from "./base/UniswapFlashswapDirectMintHandler.sol"; -import { IonHandlerBase } from "./base/IonHandlerBase.sol"; -import { EtherFiLibrary } from "../../libraries/EtherFiLibrary.sol"; +import { UniswapFlashswapDirectMintHandler } from "../UniswapFlashswapDirectMintHandler.sol"; +import { IonHandlerBase } from "../IonHandlerBase.sol"; +import { EtherFiLibrary } from "../../libraries/lrt/EtherFiLibrary.sol"; import { WEETH_ADDRESS, WETH_ADDRESS, EETH_ADDRESS } from "../../Constants.sol"; import { IUniswapV3Pool } from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; diff --git a/src/flash/handlers/EthXHandler.sol b/src/flash/lst/EthXHandler.sol similarity index 87% rename from src/flash/handlers/EthXHandler.sol rename to src/flash/lst/EthXHandler.sol index 11493265..8218ae43 100644 --- a/src/flash/handlers/EthXHandler.sol +++ b/src/flash/lst/EthXHandler.sol @@ -4,12 +4,12 @@ pragma solidity 0.8.21; import { IonPool } from "../../IonPool.sol"; import { GemJoin } from "../../join/GemJoin.sol"; import { Whitelist } from "../../Whitelist.sol"; -import { StaderLibrary } from "../../libraries/StaderLibrary.sol"; +import { StaderLibrary } from "../../libraries/lst/StaderLibrary.sol"; import { IStaderStakePoolsManager } from "../../interfaces/ProviderInterfaces.sol"; -import { IonHandlerBase } from "./base/IonHandlerBase.sol"; -import { UniswapFlashloanBalancerSwapHandler } from "./base/UniswapFlashloanBalancerSwapHandler.sol"; -import { BalancerFlashloanDirectMintHandler } from "./base/BalancerFlashloanDirectMintHandler.sol"; -import { UniswapFlashswapHandler } from "./base/UniswapFlashswapHandler.sol"; +import { IonHandlerBase } from "../IonHandlerBase.sol"; +import { UniswapFlashloanBalancerSwapHandler } from "../UniswapFlashloanBalancerSwapHandler.sol"; +import { BalancerFlashloanDirectMintHandler } from "../BalancerFlashloanDirectMintHandler.sol"; +import { UniswapFlashswapHandler } from "../UniswapFlashswapHandler.sol"; import { IUniswapV3Pool } from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; diff --git a/src/flash/handlers/SwEthHandler.sol b/src/flash/lst/SwEthHandler.sol similarity index 88% rename from src/flash/handlers/SwEthHandler.sol rename to src/flash/lst/SwEthHandler.sol index 458e81cc..7fab6a37 100644 --- a/src/flash/handlers/SwEthHandler.sol +++ b/src/flash/lst/SwEthHandler.sol @@ -3,11 +3,11 @@ pragma solidity 0.8.21; import { IonPool } from "../../IonPool.sol"; import { GemJoin } from "../../join/GemJoin.sol"; -import { IonHandlerBase } from "./base/IonHandlerBase.sol"; -import { UniswapFlashswapHandler } from "./base/UniswapFlashswapHandler.sol"; -import { BalancerFlashloanDirectMintHandler } from "./base/BalancerFlashloanDirectMintHandler.sol"; +import { IonHandlerBase } from "../IonHandlerBase.sol"; +import { UniswapFlashswapHandler } from "../UniswapFlashswapHandler.sol"; +import { BalancerFlashloanDirectMintHandler } from "../BalancerFlashloanDirectMintHandler.sol"; import { ISwEth } from "../../interfaces/ProviderInterfaces.sol"; -import { SwellLibrary } from "../../libraries/SwellLibrary.sol"; +import { SwellLibrary } from "../../libraries/lst/SwellLibrary.sol"; import { WadRayMath } from "../../libraries/math/WadRayMath.sol"; import { Whitelist } from "../../Whitelist.sol"; diff --git a/src/flash/handlers/WstEthHandler.sol b/src/flash/lst/WstEthHandler.sol similarity index 94% rename from src/flash/handlers/WstEthHandler.sol rename to src/flash/lst/WstEthHandler.sol index 792771a7..9d62677e 100644 --- a/src/flash/handlers/WstEthHandler.sol +++ b/src/flash/lst/WstEthHandler.sol @@ -2,12 +2,12 @@ pragma solidity 0.8.21; import { IonPool } from "../../IonPool.sol"; -import { IonHandlerBase } from "./base/IonHandlerBase.sol"; +import { IonHandlerBase } from "../IonHandlerBase.sol"; import { GemJoin } from "../../join/GemJoin.sol"; -import { UniswapFlashswapHandler } from "./base/UniswapFlashswapHandler.sol"; -import { BalancerFlashloanDirectMintHandler } from "./base/BalancerFlashloanDirectMintHandler.sol"; +import { UniswapFlashswapHandler } from "../UniswapFlashswapHandler.sol"; +import { BalancerFlashloanDirectMintHandler } from "../BalancerFlashloanDirectMintHandler.sol"; import { IWstEth } from "../../interfaces/ProviderInterfaces.sol"; -import { LidoLibrary } from "../../libraries/LidoLibrary.sol"; +import { LidoLibrary } from "../../libraries/lst/LidoLibrary.sol"; import { Whitelist } from "../../Whitelist.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/src/libraries/EtherFiLibrary.sol b/src/libraries/lrt/EtherFiLibrary.sol similarity index 97% rename from src/libraries/EtherFiLibrary.sol rename to src/libraries/lrt/EtherFiLibrary.sol index 81590c72..6a372a76 100644 --- a/src/libraries/EtherFiLibrary.sol +++ b/src/libraries/lrt/EtherFiLibrary.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { IWeEth, IEEth, IEtherFiLiquidityPool } from "../interfaces/ProviderInterfaces.sol"; +import { IWeEth, IEEth, IEtherFiLiquidityPool } from "../../interfaces/ProviderInterfaces.sol"; +import { WadRayMath } from "../math/WadRayMath.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; -import { WadRayMath } from "./math/WadRayMath.sol"; using Math for uint256; using WadRayMath for uint256; diff --git a/src/libraries/KelpDaoLibrary.sol b/src/libraries/lrt/KelpDaoLibrary.sol similarity index 90% rename from src/libraries/KelpDaoLibrary.sol rename to src/libraries/lrt/KelpDaoLibrary.sol index 5d145e9e..1852d11e 100644 --- a/src/libraries/KelpDaoLibrary.sol +++ b/src/libraries/lrt/KelpDaoLibrary.sol @@ -1,10 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { IRsEth } from "../interfaces/ProviderInterfaces.sol"; -import { RSETH_LRT_DEPOSIT_POOL, RSETH_LRT_ORACLE, ETH_ADDRESS } from "../Constants.sol"; +import { IRsEth } from "../../interfaces/ProviderInterfaces.sol"; +import { RSETH_LRT_DEPOSIT_POOL, RSETH_LRT_ORACLE, ETH_ADDRESS } from "../../Constants.sol"; +import { WadRayMath, WAD } from "../math/WadRayMath.sol"; + import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; -import { WadRayMath, WAD } from "./math/WadRayMath.sol"; using WadRayMath for uint256; using Math for uint256; diff --git a/src/libraries/LidoLibrary.sol b/src/libraries/lst/LidoLibrary.sol similarity index 89% rename from src/libraries/LidoLibrary.sol rename to src/libraries/lst/LidoLibrary.sol index c392a0a6..21798717 100644 --- a/src/libraries/LidoLibrary.sol +++ b/src/libraries/lst/LidoLibrary.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { IStEth } from "../interfaces/ProviderInterfaces.sol"; -import { IWstEth } from "../interfaces/ProviderInterfaces.sol"; -import { WadRayMath } from "../libraries/math/WadRayMath.sol"; +import { IStEth } from "../../interfaces/ProviderInterfaces.sol"; +import { IWstEth } from "../../interfaces/ProviderInterfaces.sol"; +import { WadRayMath } from "../../libraries/math/WadRayMath.sol"; /** * @title LidoLibrary diff --git a/src/libraries/StaderLibrary.sol b/src/libraries/lst/StaderLibrary.sol similarity index 95% rename from src/libraries/StaderLibrary.sol rename to src/libraries/lst/StaderLibrary.sol index 5e53fd92..ed9ea80f 100644 --- a/src/libraries/StaderLibrary.sol +++ b/src/libraries/lst/StaderLibrary.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { IStaderStakePoolsManager, IStaderOracle } from "../interfaces/ProviderInterfaces.sol"; +import { IStaderStakePoolsManager, IStaderOracle } from "../../interfaces/ProviderInterfaces.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; diff --git a/src/libraries/SwellLibrary.sol b/src/libraries/lst/SwellLibrary.sol similarity index 91% rename from src/libraries/SwellLibrary.sol rename to src/libraries/lst/SwellLibrary.sol index d332ba04..b481ae27 100644 --- a/src/libraries/SwellLibrary.sol +++ b/src/libraries/lst/SwellLibrary.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { WadRayMath } from "../libraries/math/WadRayMath.sol"; -import { ISwEth } from "../interfaces/ProviderInterfaces.sol"; +import { WadRayMath } from "../../libraries/math/WadRayMath.sol"; +import { ISwEth } from "../../interfaces/ProviderInterfaces.sol"; /** * @title SwellLibrary diff --git a/src/oracles/reserve/RsEthWstEthReserveOracle.sol b/src/oracles/reserve/lrt/RsEthWstEthReserveOracle.sol similarity index 83% rename from src/oracles/reserve/RsEthWstEthReserveOracle.sol rename to src/oracles/reserve/lrt/RsEthWstEthReserveOracle.sol index 773060d7..4e40e419 100644 --- a/src/oracles/reserve/RsEthWstEthReserveOracle.sol +++ b/src/oracles/reserve/lrt/RsEthWstEthReserveOracle.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { IWstEth } from "../../interfaces/ProviderInterfaces.sol"; -import { ReserveOracle } from "./ReserveOracle.sol"; -import { WSTETH_ADDRESS, RSETH_LRT_ORACLE } from "../../Constants.sol"; -import { WadRayMath } from "../../libraries/math/WadRayMath.sol"; +import { IWstEth } from "../../../interfaces/ProviderInterfaces.sol"; +import { ReserveOracle } from "../ReserveOracle.sol"; +import { WSTETH_ADDRESS, RSETH_LRT_ORACLE } from "../../../Constants.sol"; +import { WadRayMath } from "../../../libraries/math/WadRayMath.sol"; /** * @notice Reserve oracle for rsETH. diff --git a/src/oracles/reserve/WeEthWstEthReserveOracle.sol b/src/oracles/reserve/lrt/WeEthWstEthReserveOracle.sol similarity index 85% rename from src/oracles/reserve/WeEthWstEthReserveOracle.sol rename to src/oracles/reserve/lrt/WeEthWstEthReserveOracle.sol index 7cbd2ea7..c747eab2 100644 --- a/src/oracles/reserve/WeEthWstEthReserveOracle.sol +++ b/src/oracles/reserve/lrt/WeEthWstEthReserveOracle.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { IWeEth, IWstEth } from "../../interfaces/ProviderInterfaces.sol"; -import { ReserveOracle } from "./ReserveOracle.sol"; -import { WEETH_ADDRESS, WSTETH_ADDRESS } from "../../Constants.sol"; -import { WadRayMath } from "../../libraries/math/WadRayMath.sol"; +import { IWeEth, IWstEth } from "../../../interfaces/ProviderInterfaces.sol"; +import { ReserveOracle } from "../ReserveOracle.sol"; +import { WEETH_ADDRESS, WSTETH_ADDRESS } from "../../../Constants.sol"; +import { WadRayMath } from "../../../libraries/math/WadRayMath.sol"; /** * @notice Reserve oracle for weETH. diff --git a/src/oracles/reserve/EthXReserveOracle.sol b/src/oracles/reserve/lst/EthXReserveOracle.sol similarity index 90% rename from src/oracles/reserve/EthXReserveOracle.sol rename to src/oracles/reserve/lst/EthXReserveOracle.sol index 1e01726f..e4484b3a 100644 --- a/src/oracles/reserve/EthXReserveOracle.sol +++ b/src/oracles/reserve/lst/EthXReserveOracle.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { IStaderStakePoolsManager } from "../../interfaces/ProviderInterfaces.sol"; -import { ReserveOracle } from "./ReserveOracle.sol"; +import { IStaderStakePoolsManager } from "../../../interfaces/ProviderInterfaces.sol"; +import { ReserveOracle } from "../ReserveOracle.sol"; /** * @notice Reserve oracle for ETHx. diff --git a/src/oracles/reserve/SwEthReserveOracle.sol b/src/oracles/reserve/lst/SwEthReserveOracle.sol similarity index 91% rename from src/oracles/reserve/SwEthReserveOracle.sol rename to src/oracles/reserve/lst/SwEthReserveOracle.sol index cd4ba8a7..84b4fb5f 100644 --- a/src/oracles/reserve/SwEthReserveOracle.sol +++ b/src/oracles/reserve/lst/SwEthReserveOracle.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { ISwEth } from "../../interfaces/ProviderInterfaces.sol"; -import { ReserveOracle } from "./ReserveOracle.sol"; +import { ISwEth } from "../../../interfaces/ProviderInterfaces.sol"; +import { ReserveOracle } from "../ReserveOracle.sol"; /** * @notice Reserve oracle for swETH. diff --git a/src/oracles/reserve/WstEthReserveOracle.sol b/src/oracles/reserve/lst/WstEthReserveOracle.sol similarity index 92% rename from src/oracles/reserve/WstEthReserveOracle.sol rename to src/oracles/reserve/lst/WstEthReserveOracle.sol index 6bae2995..b1e0ab89 100644 --- a/src/oracles/reserve/WstEthReserveOracle.sol +++ b/src/oracles/reserve/lst/WstEthReserveOracle.sol @@ -2,8 +2,8 @@ pragma solidity 0.8.21; -import { IWstEth } from "../../interfaces/ProviderInterfaces.sol"; -import { ReserveOracle } from "./ReserveOracle.sol"; +import { IWstEth } from "../../../interfaces/ProviderInterfaces.sol"; +import { ReserveOracle } from "../ReserveOracle.sol"; /** * @notice Reserve oracle for wstETH. diff --git a/src/oracles/spot/RsEthWstEthSpotOracle.sol b/src/oracles/spot/lrt/RsEthWstEthSpotOracle.sol similarity index 91% rename from src/oracles/spot/RsEthWstEthSpotOracle.sol rename to src/oracles/spot/lrt/RsEthWstEthSpotOracle.sol index 3b93406a..b781f71d 100644 --- a/src/oracles/spot/RsEthWstEthSpotOracle.sol +++ b/src/oracles/spot/lrt/RsEthWstEthSpotOracle.sol @@ -2,15 +2,15 @@ pragma solidity 0.8.21; -import { SpotOracle } from "../../oracles/spot/SpotOracle.sol"; -import { WadRayMath } from "../../libraries/math/WadRayMath.sol"; +import { SpotOracle } from "../../../oracles/spot/SpotOracle.sol"; +import { WadRayMath } from "../../../libraries/math/WadRayMath.sol"; import { WSTETH_ADDRESS, REDSTONE_RSETH_ETH_PRICE_FEED, ETH_PER_STETH_CHAINLINK, REDSTONE_DECIMALS -} from "../../Constants.sol"; -import { IWstEth } from "../../interfaces/ProviderInterfaces.sol"; +} from "../../../Constants.sol"; +import { IWstEth } from "../../../interfaces/ProviderInterfaces.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; diff --git a/src/oracles/spot/WeEthWstEthSpotOracle.sol b/src/oracles/spot/lrt/WeEthWstEthSpotOracle.sol similarity index 91% rename from src/oracles/spot/WeEthWstEthSpotOracle.sol rename to src/oracles/spot/lrt/WeEthWstEthSpotOracle.sol index 5109b436..0244f4e1 100644 --- a/src/oracles/spot/WeEthWstEthSpotOracle.sol +++ b/src/oracles/spot/lrt/WeEthWstEthSpotOracle.sol @@ -2,15 +2,15 @@ pragma solidity 0.8.21; -import { SpotOracle } from "../../oracles/spot/SpotOracle.sol"; -import { WadRayMath } from "../../libraries/math/WadRayMath.sol"; +import { SpotOracle } from "../../../oracles/spot/SpotOracle.sol"; +import { WadRayMath } from "../../../libraries/math/WadRayMath.sol"; import { WSTETH_ADDRESS, REDSTONE_WEETH_ETH_PRICE_FEED, ETH_PER_STETH_CHAINLINK, REDSTONE_DECIMALS -} from "../../Constants.sol"; -import { IWstEth } from "../../interfaces/ProviderInterfaces.sol"; +} from "../../../Constants.sol"; +import { IWstEth } from "../../../interfaces/ProviderInterfaces.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; diff --git a/src/oracles/spot/EthXSpotOracle.sol b/src/oracles/spot/lst/EthXSpotOracle.sol similarity index 92% rename from src/oracles/spot/EthXSpotOracle.sol rename to src/oracles/spot/lst/EthXSpotOracle.sol index 71831b2e..b3ee33c9 100644 --- a/src/oracles/spot/EthXSpotOracle.sol +++ b/src/oracles/spot/lst/EthXSpotOracle.sol @@ -2,9 +2,9 @@ pragma solidity 0.8.21; -import { SpotOracle } from "../../oracles/spot/SpotOracle.sol"; -import { IChainlink } from "../../interfaces/IChainlink.sol"; -import { WadRayMath } from "../../libraries/math/WadRayMath.sol"; +import { SpotOracle } from "../SpotOracle.sol"; +import { IChainlink } from "../../../interfaces/IChainlink.sol"; +import { WadRayMath } from "../../../libraries/math/WadRayMath.sol"; interface IRedstonePriceFeed { function latestRoundData() diff --git a/src/oracles/spot/SwEthSpotOracle.sol b/src/oracles/spot/lst/SwEthSpotOracle.sol similarity index 88% rename from src/oracles/spot/SwEthSpotOracle.sol rename to src/oracles/spot/lst/SwEthSpotOracle.sol index 1a062c95..b405730e 100644 --- a/src/oracles/spot/SwEthSpotOracle.sol +++ b/src/oracles/spot/lst/SwEthSpotOracle.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { TickMath } from "../../libraries/uniswap/TickMath.sol"; -import { UniswapOracleLibrary } from "../../libraries/uniswap/UniswapOracleLibrary.sol"; -import { WAD } from "../../libraries/math/WadRayMath.sol"; -import { SpotOracle } from "./SpotOracle.sol"; +import { TickMath } from "../../../libraries/uniswap/TickMath.sol"; +import { UniswapOracleLibrary } from "../../../libraries/uniswap/UniswapOracleLibrary.sol"; +import { WAD } from "../../../libraries/math/WadRayMath.sol"; +import { SpotOracle } from "../SpotOracle.sol"; import { IUniswapV3Pool } from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; diff --git a/src/oracles/spot/WstEthSpotOracle.sol b/src/oracles/spot/lst/WstEthSpotOracle.sol similarity index 91% rename from src/oracles/spot/WstEthSpotOracle.sol rename to src/oracles/spot/lst/WstEthSpotOracle.sol index bee7e59b..47ece5c3 100644 --- a/src/oracles/spot/WstEthSpotOracle.sol +++ b/src/oracles/spot/lst/WstEthSpotOracle.sol @@ -2,9 +2,9 @@ pragma solidity 0.8.21; -import { SpotOracle } from "../../oracles/spot/SpotOracle.sol"; -import { IChainlink } from "../../interfaces/IChainlink.sol"; -import { IWstEth } from "../../interfaces/ProviderInterfaces.sol"; +import { SpotOracle } from "../SpotOracle.sol"; +import { IChainlink } from "../../../interfaces/IChainlink.sol"; +import { IWstEth } from "../../../interfaces/ProviderInterfaces.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; diff --git a/test/differential/IonPoolFrobBoolean.t.sol b/test/differential/IonPoolFrobBoolean.t.sol index e9047734..4ca03ed9 100644 --- a/test/differential/IonPoolFrobBoolean.t.sol +++ b/test/differential/IonPoolFrobBoolean.t.sol @@ -2,6 +2,7 @@ pragma solidity 0.8.21; import { Test } from "forge-std/Test.sol"; + import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; contract IonPool_FrobBooleanTest is Test { diff --git a/test/fork/concrete/ReserveOracleFork.t.sol b/test/fork/concrete/ReserveOracleFork.t.sol deleted file mode 100644 index f6f3f9b4..00000000 --- a/test/fork/concrete/ReserveOracleFork.t.sol +++ /dev/null @@ -1,151 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity 0.8.21; - -import { ReserveOracle } from "./../../../src/oracles/reserve/ReserveOracle.sol"; -import { RsEthWstEthReserveOracle } from "./../../../src/oracles/reserve/RsEthWstEthReserveOracle.sol"; -import { WadRayMath } from "./../../../src/libraries/math/WadRayMath.sol"; -import { UPDATE_COOLDOWN } from "./../../../src/oracles/reserve/ReserveOracle.sol"; -import { - RSETH_LRT_ORACLE, RSETH_LRT_DEPOSIT_POOL, WSTETH_ADDRESS, RSETH, ETHX_ADDRESS -} from "../../../src/Constants.sol"; -import { ReserveOracleSharedSetup } from "../../helpers/ReserveOracleSharedSetup.sol"; -import { StdStorage, stdStorage } from "./../../../lib/forge-safe/lib/forge-std/src/StdStorage.sol"; -import { IERC20 } from "./../../../lib/forge-safe/lib/forge-std/src/interfaces/IERC20.sol"; - -uint256 constant LTV = 0.9e27; -uint256 constant MAX_CHANGE = 0.03e27; - -abstract contract ReserveOracle_ForkTest is ReserveOracleSharedSetup { - using stdStorage for StdStorage; - using WadRayMath for uint256; - - ReserveOracle reserveOracle; - StdStorage stdstore1; - - function testFork_CurrentExchangeRate() public { - uint256 expectedExchangeRate = getProtocolExchangeRate(); - uint256 currentExchangeRate = reserveOracle.currentExchangeRate(); - assertEq(currentExchangeRate, expectedExchangeRate, "current exchange rate"); - - uint256 exchangeRateInEth = convertToEth(currentExchangeRate); - assertGt(exchangeRateInEth, 1 ether, "within reasonable exchange rate minimum bound"); - assertLt(exchangeRateInEth, 1.2 ether, "within reasonable exchange rate upper bound"); - } - - function testFork_GetProtocolExchangeRate() public { - uint256 exchangeRateInEth = convertToEth(reserveOracle.getProtocolExchangeRate()); - assertGt(exchangeRateInEth, 1 ether, "within reasonable exchange rate minimum bound"); - assertLt(exchangeRateInEth, 1.2 ether, "within reasonable exchange rate minimum bound"); - } - - function testFork_UpdateExchangeRate() public { - uint256 expectedExchangeRate = getProtocolExchangeRate(); - reserveOracle.updateExchangeRate(); - assertEq(reserveOracle.currentExchangeRate(), expectedExchangeRate, "update without bound"); - } - - function testFork_RevertWhen_UpdateIsOnCooldown() public { - reserveOracle.updateExchangeRate(); - vm.expectRevert(abi.encodeWithSelector(ReserveOracle.UpdateCooldown.selector, block.timestamp)); - reserveOracle.updateExchangeRate(); - uint256 lastUpdated = block.timestamp; - - vm.warp(block.timestamp + UPDATE_COOLDOWN - 1); - vm.expectRevert(abi.encodeWithSelector(ReserveOracle.UpdateCooldown.selector, lastUpdated)); - reserveOracle.updateExchangeRate(); - lastUpdated = block.timestamp; - - vm.warp(block.timestamp + UPDATE_COOLDOWN); - reserveOracle.updateExchangeRate(); - } - - function testFork_UpdateExchangeRateMaxBounded() public { - uint256 expectedMaxBound = getMaxBound(); - increaseExchangeRate(); - reserveOracle.updateExchangeRate(); - assertEq(reserveOracle.currentExchangeRate(), expectedMaxBound, "exchange rate max bounded"); - } - - function testFork_UpdateExchangeRateMinBounded() public { - uint256 expectedMinBound = getMinBound(); - decreaseExchangeRate(); - reserveOracle.updateExchangeRate(); - assertEq(reserveOracle.currentExchangeRate(), expectedMinBound, "exchange rate min bounded"); - } - - // --- Helper Functions --- - - function getMaxBound() public view returns (uint256) { - uint256 currentExchangeRate = reserveOracle.currentExchangeRate(); - uint256 diff = currentExchangeRate.rayMulDown(MAX_CHANGE); - return currentExchangeRate + diff; - } - - function getMinBound() public view returns (uint256) { - uint256 currentExchangeRate = reserveOracle.currentExchangeRate(); - uint256 diff = currentExchangeRate.rayMulDown(MAX_CHANGE); - return currentExchangeRate - diff; - } - - function setERC20Balance(address token, address usr, uint256 amt) public { - stdstore1.target(token).sig(IERC20(token).balanceOf.selector).with_key(usr).checked_write(amt); - require(IERC20(token).balanceOf(usr) == amt, "balance not set"); - } - - function increaseExchangeRate() public virtual returns (uint256) { } - - function decreaseExchangeRate() public virtual returns (uint256) { } - - // converts lending asset denomination to ETH - function convertToEth(uint256 amt) public virtual returns (uint256) { } - - function getProtocolExchangeRate() public virtual returns (uint256) { } -} - -contract RsEthWstEthReserveOracle_ForkTest is ReserveOracle_ForkTest { - using WadRayMath for uint256; - - bytes32 constant RSETH_TOTAL_SUPPLY_SLOT = 0x0000000000000000000000000000000000000000000000000000000000000035; - - function setUp() public override { - super.setUp(); - reserveOracle = new RsEthWstEthReserveOracle(ILK_INDEX, emptyFeeds, QUORUM, MAX_CHANGE); - } - - function increaseExchangeRate() public override returns (uint256 newPrice) { - // effectively doubles the exchange rate by giving ETHx amount equal to - // rsETH total supply to the deposit pool. - uint256 prevPrice = RSETH_LRT_ORACLE.rsETHPrice(); - - uint256 totalSupply = RSETH.totalSupply(); - setERC20Balance(address(ETHX_ADDRESS), address(RSETH_LRT_DEPOSIT_POOL), totalSupply); - - RSETH_LRT_ORACLE.updateRSETHPrice(); - - newPrice = RSETH_LRT_ORACLE.rsETHPrice(); - require(newPrice > prevPrice, "price should increase"); - } - - function decreaseExchangeRate() public override returns (uint256 newPrice) { - uint256 prevPrice = RSETH_LRT_ORACLE.rsETHPrice(); - - // effectively halves the exchange rate by doubling the rsETH total supply - uint256 newTotalSupply = RSETH.totalSupply() * 2; - vm.store(address(RSETH), RSETH_TOTAL_SUPPLY_SLOT, bytes32(newTotalSupply)); - - RSETH_LRT_ORACLE.updateRSETHPrice(); - - newPrice = RSETH_LRT_ORACLE.rsETHPrice(); - require(newPrice < prevPrice, "price should decrease"); - } - - function convertToEth(uint256 amt) public view override returns (uint256) { - // wstETH * ETH / wstETH - return WSTETH_ADDRESS.getStETHByWstETH(amt); - } - - function getProtocolExchangeRate() public view override returns (uint256) { - return RSETH_LRT_ORACLE.rsETHPrice().wadMulDown(WSTETH_ADDRESS.tokensPerStEth()); - } -} diff --git a/test/fork/concrete/WeEthWstEthReserveOracleFork.t.sol b/test/fork/concrete/WeEthWstEthReserveOracleFork.t.sol deleted file mode 100644 index 0834f16c..00000000 --- a/test/fork/concrete/WeEthWstEthReserveOracleFork.t.sol +++ /dev/null @@ -1,223 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.21; - -import { RAY } from "../../../src/libraries/math/WadRayMath.sol"; -import { WeEthWstEthReserveOracle } from "../../../src/oracles/reserve/WeEthWstEthReserveOracle.sol"; -import { ReserveFeed } from "../../../src/oracles/reserve/ReserveFeed.sol"; -import { ReserveOracle } from "../../../src/oracles/reserve/ReserveOracle.sol"; -import { IWeEth, IEEth } from "../../../src/interfaces/ProviderInterfaces.sol"; - -import { ReserveOracleSharedSetup } from "../../helpers/ReserveOracleSharedSetup.sol"; - -import { ETHER_FI_LIQUIDITY_POOL_ADDRESS, WEETH_ADDRESS, EETH_ADDRESS } from "src/Constants.sol"; - -// fork tests for integrating with external contracts -contract WeEthWstEthReserveOracleForkTest is ReserveOracleSharedSetup { - function setUp() public override { - blockNumber = 19_079_925; - super.setUp(); - } - - // --- weETH Reserve Oracle Test --- - - function test_RevertWhen_UpdateIsOnCooldown() public { - uint256 maxChange = 3e25; // 0.03 3% - address[] memory feeds = new address[](3); - uint8 quorum = 0; - WeEthWstEthReserveOracle weEthWstEthReserveOracle = - new WeEthWstEthReserveOracle(STETH_ILK_INDEX, feeds, quorum, maxChange); - - weEthWstEthReserveOracle.updateExchangeRate(); - - vm.expectRevert(abi.encodeWithSelector(ReserveOracle.UpdateCooldown.selector, block.timestamp)); - weEthWstEthReserveOracle.updateExchangeRate(); - } - - function test_WeEthWstEthReserveOracleGetProtocolExchangeRate() public { - uint256 maxChange = 3e25; // 0.03 3% - address[] memory feeds = new address[](3); - uint8 quorum = 0; - WeEthWstEthReserveOracle weEthWstEthReserveOracle = - new WeEthWstEthReserveOracle(STETH_ILK_INDEX, feeds, quorum, maxChange); - - uint256 protocolExchangeRate = weEthWstEthReserveOracle.getProtocolExchangeRate(); - assertEq(protocolExchangeRate, 891_594_478_806_748_333, "protocol exchange rate"); - } - - // --- Errors --- - function test_RevertWhen_WeEthWstEthInvalidInitialization() public { - ReserveFeed reserveFeed1 = new ReserveFeed(address(this)); - ReserveFeed reserveFeed2 = new ReserveFeed(address(this)); - ReserveFeed reserveFeed3 = new ReserveFeed(address(this)); - - uint256 maxChange = 3e25; // 0.03 3% - address[] memory feeds = new address[](3); - feeds[0] = address(reserveFeed1); - feeds[1] = address(reserveFeed2); - feeds[2] = address(reserveFeed3); - uint8 quorum = 3; - - vm.expectRevert(abi.encodeWithSelector(ReserveOracle.InvalidInitialization.selector, 0)); - new WeEthWstEthReserveOracle(STETH_ILK_INDEX, feeds, quorum, maxChange); - } - - // --- Slashing Scenario --- - - function test_UnpackEtherFiTotalValue() public { - uint256 totalValueOutOfLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueOutOfLp(); - - uint256 totalValueInLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueInLp(); - - // 0x00000000000001287956cfe67f3b5ffe0000000000001e3b21b7e61ce9aac681 - // [totalValueInLp, totalValueOutOfLp] - bytes32 totalValue = vm.load(address(ETHER_FI_LIQUIDITY_POOL_ADDRESS), EETH_LIQUIDITY_POOL_TOTAL_VALUE_SLOT); - - uint256 unpackedTotalValueInLp = uint256(totalValue >> 128); - - uint256 unpackedTotalValueOutOfLp = uint256(totalValue & EETH_TOTAL_VALUE_MASK); - - assertEq(unpackedTotalValueOutOfLp, totalValueOutOfLp, "totalValueOutOfLp"); - assertEq(unpackedTotalValueInLp, totalValueInLp, "totalValueInLp"); - } - - function test_WeEthExchangeRatePostSlashing() public { - uint256 totalValueOutOfLpDiff = 10_000 ether; - - uint256 totalValueOutOfLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueOutOfLp(); - uint256 totalValueInLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueInLp(); - - bytes32 newTotalValueInLp = bytes32(totalValueInLp) << 128; - - bytes32 newTotalValueOutOfLp = bytes32(uint256(totalValueOutOfLp - totalValueOutOfLpDiff)); - - bytes32 newTotalValue = newTotalValueInLp | newTotalValueOutOfLp; - - // reduce rebase share values in EtherFi - vm.store(address(ETHER_FI_LIQUIDITY_POOL_ADDRESS), EETH_LIQUIDITY_POOL_TOTAL_VALUE_SLOT, bytes32(newTotalValue)); - - // _share * getTotalPooledEther() / totalShares - // _share * (totalValueOutOfLp + totalValueInLp) / totalShares - - uint256 expectedEEthPerWeEthExchangeRate = - 1 ether * (totalValueInLp + uint256(newTotalValueOutOfLp)) / IEEth(EETH_ADDRESS).totalShares(); - uint256 eEthPerWeEthExchangeRate = IWeEth(WEETH_ADDRESS).getEETHByWeETH(1 ether); - - assertEq(eEthPerWeEthExchangeRate, expectedEEthPerWeEthExchangeRate, "new exchange rate"); - } - - // --- Bounding Scenario --- - - // wstETH gets slashed, weETH per stETH goes up - function test_WstEthExchangeRateGoesDownOutputsMax() public { - uint256 maxChange = 3e25; - uint256 newClBalance = 0.5 ether; - - address[] memory feeds = new address[](3); - uint8 quorum = 0; - - WeEthWstEthReserveOracle weEthWstEthReserveOracle = - new WeEthWstEthReserveOracle(STETH_ILK_INDEX, feeds, quorum, maxChange); - - uint256 exchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); - - vm.store(LIDO, LIDO_CL_BALANCE_SLOT, bytes32(newClBalance)); - - weEthWstEthReserveOracle.updateExchangeRate(); - uint256 newExchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); - - uint256 maxExchangeRate = exchangeRate + ((exchangeRate * maxChange) / RAY); - assertEq(newExchangeRate, maxExchangeRate, "max exchange rate bound"); - } - - // weETH gets slashed, weETH per stETH goes down - function test_WeEthExchangeRateGoesDownOutputsMin() public { - uint256 maxChange = 5e25; - - address[] memory feeds = new address[](3); - uint8 quorum = 0; - - // sets currentExchange rate to be the current exchangeRate in constructor - WeEthWstEthReserveOracle weEthWstEthReserveOracle = - new WeEthWstEthReserveOracle(STETH_ILK_INDEX, feeds, quorum, maxChange); - - uint256 exchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); - - uint256 totalValueInLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueInLp(); - - bytes32 newTotalValueInLp = bytes32(totalValueInLp) << 128; - - bytes32 newTotalValueOutOfLp = bytes32(uint256(100 ether)); - - bytes32 newTotalValue = newTotalValueInLp | newTotalValueOutOfLp; - - vm.store(address(ETHER_FI_LIQUIDITY_POOL_ADDRESS), EETH_LIQUIDITY_POOL_TOTAL_VALUE_SLOT, bytes32(newTotalValue)); - - weEthWstEthReserveOracle.updateExchangeRate(); - uint256 newExchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); - - uint256 minExchangeRate = exchangeRate - ((exchangeRate * maxChange) / RAY); - assertEq(newExchangeRate, minExchangeRate, "minimum exchange rate bound"); - } - - // Exchange Rate Change But Not Bounded - - function test_WstEthExchangeRateGoesDownNotMaxBounded() public { - uint256 maxChange = 3e25; - uint256 clBalanceDiff = 1 ether; - - address[] memory feeds = new address[](3); - uint8 quorum = 0; - - WeEthWstEthReserveOracle weEthWstEthReserveOracle = - new WeEthWstEthReserveOracle(STETH_ILK_INDEX, feeds, quorum, maxChange); - - uint256 exchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); - - bytes32 currClBalance = vm.load(LIDO, LIDO_CL_BALANCE_SLOT); - uint256 newClBalance = uint256(currClBalance) - clBalanceDiff; - - vm.store(LIDO, LIDO_CL_BALANCE_SLOT, bytes32(newClBalance)); - - weEthWstEthReserveOracle.updateExchangeRate(); - uint256 newExchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); - - uint256 maxExchangeRate = exchangeRate + ((exchangeRate * maxChange) / RAY); - - assertLt(newExchangeRate, maxExchangeRate, "below max bound"); - assertGt(newExchangeRate, exchangeRate, "above min bound"); - } - - function test_WeEthExchangeRateGoesDownNotMinBounded() public { - uint256 maxChange = 5e25; - uint256 totalValueOutOfLpDiff = 1 ether; - - address[] memory feeds = new address[](3); - uint8 quorum = 0; - - // sets currentExchange rate to be the current exchangeRate in constructor - WeEthWstEthReserveOracle weEthWstEthReserveOracle = - new WeEthWstEthReserveOracle(STETH_ILK_INDEX, feeds, quorum, maxChange); - - uint256 exchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); - - uint256 totalValueOutOfLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueOutOfLp(); - - uint256 totalValueInLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueInLp(); - - bytes32 newTotalValueInLp = bytes32(totalValueInLp) << 128; - - bytes32 newTotalValueOutOfLp = bytes32(totalValueOutOfLp - totalValueOutOfLpDiff); - - bytes32 newTotalValue = newTotalValueInLp | newTotalValueOutOfLp; - - vm.store(address(ETHER_FI_LIQUIDITY_POOL_ADDRESS), EETH_LIQUIDITY_POOL_TOTAL_VALUE_SLOT, bytes32(newTotalValue)); - - weEthWstEthReserveOracle.updateExchangeRate(); - uint256 newExchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); - - uint256 minExchangeRate = exchangeRate - ((exchangeRate * maxChange) / RAY); - - assertLt(newExchangeRate, exchangeRate, "below previous exchange rate"); - assertGt(newExchangeRate, minExchangeRate, "above minimum exchange rate bound"); - } -} diff --git a/test/fork/concrete/YieldOracleFork.t.sol b/test/fork/concrete/YieldOracle.t.sol similarity index 100% rename from test/fork/concrete/YieldOracleFork.t.sol rename to test/fork/concrete/YieldOracle.t.sol diff --git a/test/fork/concrete/handlers-base/BalancerFlashloanDirectMintHandler.t.sol b/test/fork/concrete/handlers-base/BalancerFlashloanDirectMintHandler.t.sol index bf069769..afabb063 100644 --- a/test/fork/concrete/handlers-base/BalancerFlashloanDirectMintHandler.t.sol +++ b/test/fork/concrete/handlers-base/BalancerFlashloanDirectMintHandler.t.sol @@ -3,10 +3,7 @@ pragma solidity 0.8.21; import { LstHandler_ForkBase } from "../../../helpers/handlers/LstHandlerForkBase.sol"; import { WadRayMath, RAY } from "../../../../src/libraries/math/WadRayMath.sol"; -import { - BalancerFlashloanDirectMintHandler, - VAULT -} from "../../../../src/flash/handlers/base/BalancerFlashloanDirectMintHandler.sol"; +import { BalancerFlashloanDirectMintHandler, VAULT } from "../../../../src/flash/BalancerFlashloanDirectMintHandler.sol"; import { Whitelist } from "../../../../src/Whitelist.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; diff --git a/test/fork/concrete/handlers-base/UniswapFlashloanBalancerSwapHandler.t.sol b/test/fork/concrete/handlers-base/UniswapFlashloanBalancerSwapHandler.t.sol index 4c6513d8..8cb75604 100644 --- a/test/fork/concrete/handlers-base/UniswapFlashloanBalancerSwapHandler.t.sol +++ b/test/fork/concrete/handlers-base/UniswapFlashloanBalancerSwapHandler.t.sol @@ -3,9 +3,8 @@ pragma solidity 0.8.21; import { LstHandler_ForkBase } from "../../../helpers/handlers/LstHandlerForkBase.sol"; import { WadRayMath, RAY, WAD } from "../../../../src/libraries/math/WadRayMath.sol"; -import { UniswapFlashloanBalancerSwapHandler } from - "../../../../src/flash/handlers/base/UniswapFlashloanBalancerSwapHandler.sol"; -import { IonHandlerBase } from "../../../../src/flash/handlers/base/IonHandlerBase.sol"; +import { UniswapFlashloanBalancerSwapHandler } from "../../../../src/flash/UniswapFlashloanBalancerSwapHandler.sol"; +import { IonHandlerBase } from "../../../../src/flash/IonHandlerBase.sol"; import { Whitelist } from "../../../../src/Whitelist.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; diff --git a/test/fork/concrete/handlers-base/UniswapFlashswapDirectMintHandler.t.sol b/test/fork/concrete/handlers-base/UniswapFlashswapDirectMintHandler.t.sol index d32c0fa2..0f5ece4c 100644 --- a/test/fork/concrete/handlers-base/UniswapFlashswapDirectMintHandler.t.sol +++ b/test/fork/concrete/handlers-base/UniswapFlashswapDirectMintHandler.t.sol @@ -1,8 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { UniswapFlashswapDirectMintHandler } from - "../../../../src/flash/handlers/base/UniswapFlashswapDirectMintHandler.sol"; +import { UniswapFlashswapDirectMintHandler } from "../../../../src/flash/UniswapFlashswapDirectMintHandler.sol"; import { Whitelist } from "../../../../src/Whitelist.sol"; import { LrtHandler_ForkBase } from "../../../helpers/handlers/LrtHandlerForkBase.sol"; import { WadRayMath, RAY } from "../../../../src/libraries/math/WadRayMath.sol"; diff --git a/test/fork/concrete/handlers-base/UniswapFlashswapHandler.t.sol b/test/fork/concrete/handlers-base/UniswapFlashswapHandler.t.sol index d088f87d..b9872ab3 100644 --- a/test/fork/concrete/handlers-base/UniswapFlashswapHandler.t.sol +++ b/test/fork/concrete/handlers-base/UniswapFlashswapHandler.t.sol @@ -3,8 +3,8 @@ pragma solidity 0.8.21; import { LstHandler_ForkBase } from "../../../helpers/handlers/LstHandlerForkBase.sol"; import { WadRayMath, RAY, WAD } from "../../../../src/libraries/math/WadRayMath.sol"; -import { UniswapFlashswapHandler } from "../../../../src/flash/handlers/base/UniswapFlashswapHandler.sol"; -import { IonHandlerBase } from "../../../../src/flash/handlers/base/IonHandlerBase.sol"; +import { UniswapFlashswapHandler } from "../../../../src/flash/UniswapFlashswapHandler.sol"; +import { IonHandlerBase } from "../../../../src/flash/IonHandlerBase.sol"; import { Whitelist } from "../../../../src/Whitelist.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; diff --git a/test/fork/concrete/lrt/ReserveOracle.t.sol b/test/fork/concrete/lrt/ReserveOracle.t.sol new file mode 100644 index 00000000..e361d956 --- /dev/null +++ b/test/fork/concrete/lrt/ReserveOracle.t.sol @@ -0,0 +1,297 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.21; + +import { ReserveOracle } from "../../../../src/oracles/reserve/ReserveOracle.sol"; +import { RsEthWstEthReserveOracle } from "../../../../src/oracles/reserve/lrt/RsEthWstEthReserveOracle.sol"; +import { WadRayMath } from "../../../../src/libraries/math/WadRayMath.sol"; +import { UPDATE_COOLDOWN } from "../../../../src/oracles/reserve/ReserveOracle.sol"; +import { + RSETH_LRT_ORACLE, + RSETH_LRT_DEPOSIT_POOL, + WSTETH_ADDRESS, + RSETH, + ETHX_ADDRESS +} from "../../../../src/Constants.sol"; +import { ReserveOracleSharedSetup } from "../../../helpers/ReserveOracleSharedSetup.sol"; +import { StdStorage, stdStorage } from "../../../../lib/forge-safe/lib/forge-std/src/StdStorage.sol"; +import { IERC20 } from "../../../../lib/forge-safe/lib/forge-std/src/interfaces/IERC20.sol"; +import { RAY } from "../../../../src/libraries/math/WadRayMath.sol"; +import { WeEthWstEthReserveOracle } from "../../../../src/oracles/reserve/lrt/WeEthWstEthReserveOracle.sol"; +import { ReserveFeed } from "../../../../src/oracles/reserve/ReserveFeed.sol"; +import { ReserveOracle } from "../../../../src/oracles/reserve/ReserveOracle.sol"; +import { IWeEth, IEEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; + +import { ReserveOracleSharedSetup } from "../../../helpers/ReserveOracleSharedSetup.sol"; + +import { ETHER_FI_LIQUIDITY_POOL_ADDRESS, WEETH_ADDRESS, EETH_ADDRESS } from "../../../../src/Constants.sol"; + +uint256 constant LTV = 0.9e27; +uint256 constant MAX_CHANGE = 0.03e27; + +using WadRayMath for uint256; + +abstract contract ReserveOracle_ForkTest is ReserveOracleSharedSetup { + using stdStorage for StdStorage; + + ReserveOracle reserveOracle; + StdStorage stdstore1; + + function testFork_CurrentExchangeRate() public { + uint256 expectedExchangeRate = _getProtocolExchangeRate(); + uint256 currentExchangeRate = reserveOracle.currentExchangeRate(); + assertEq(currentExchangeRate, expectedExchangeRate, "current exchange rate"); + + uint256 exchangeRateInEth = _convertToEth(currentExchangeRate); + assertGt(exchangeRateInEth, 1 ether, "within reasonable exchange rate minimum bound"); + assertLt(exchangeRateInEth, 1.2 ether, "within reasonable exchange rate upper bound"); + } + + function testFork_GetProtocolExchangeRate() public { + uint256 exchangeRateInEth = _convertToEth(reserveOracle.getProtocolExchangeRate()); + assertGt(exchangeRateInEth, 1 ether, "within reasonable exchange rate minimum bound"); + assertLt(exchangeRateInEth, 1.2 ether, "within reasonable exchange rate minimum bound"); + } + + function testFork_UpdateExchangeRate() public { + uint256 expectedExchangeRate = _getProtocolExchangeRate(); + reserveOracle.updateExchangeRate(); + assertEq(reserveOracle.currentExchangeRate(), expectedExchangeRate, "update without bound"); + } + + function testFork_RevertWhen_UpdateIsOnCooldown() public { + reserveOracle.updateExchangeRate(); + vm.expectRevert(abi.encodeWithSelector(ReserveOracle.UpdateCooldown.selector, block.timestamp)); + reserveOracle.updateExchangeRate(); + uint256 lastUpdated = block.timestamp; + + vm.warp(block.timestamp + UPDATE_COOLDOWN - 1); + vm.expectRevert(abi.encodeWithSelector(ReserveOracle.UpdateCooldown.selector, lastUpdated)); + reserveOracle.updateExchangeRate(); + lastUpdated = block.timestamp; + + vm.warp(block.timestamp + UPDATE_COOLDOWN); + reserveOracle.updateExchangeRate(); + } + + function testFork_UpdateExchangeRateMaxBounded() public { + uint256 expectedMaxBound = getMaxBound(); + _increaseExchangeRate(); + reserveOracle.updateExchangeRate(); + assertEq(reserveOracle.currentExchangeRate(), expectedMaxBound, "exchange rate max bounded"); + } + + function testFork_UpdateExchangeRateMinBounded() public { + uint256 expectedMinBound = getMinBound(); + _decreaseExchangeRate(); + reserveOracle.updateExchangeRate(); + assertEq(reserveOracle.currentExchangeRate(), expectedMinBound, "exchange rate min bounded"); + } + + // --- Helper Functions --- + + function getMaxBound() public view returns (uint256) { + uint256 currentExchangeRate = reserveOracle.currentExchangeRate(); + uint256 diff = currentExchangeRate.rayMulDown(MAX_CHANGE); + return currentExchangeRate + diff; + } + + function getMinBound() public view returns (uint256) { + uint256 currentExchangeRate = reserveOracle.currentExchangeRate(); + uint256 diff = currentExchangeRate.rayMulDown(MAX_CHANGE); + return currentExchangeRate - diff; + } + + function setERC20Balance(address token, address usr, uint256 amt) public { + stdstore1.target(token).sig(IERC20(token).balanceOf.selector).with_key(usr).checked_write(amt); + require(IERC20(token).balanceOf(usr) == amt, "balance not set"); + } + + function _increaseExchangeRate() internal virtual returns (uint256); + + function _decreaseExchangeRate() internal virtual returns (uint256); + + /** + * @dev converts lending asset denomination to ETH + * @param amt amount of lending asset + */ + function _convertToEth(uint256 amt) internal virtual returns (uint256); + + function _getProtocolExchangeRate() internal virtual returns (uint256); +} + +contract RsEthWstEthReserveOracle_ForkTest is ReserveOracle_ForkTest { + using WadRayMath for uint256; + + bytes32 constant RSETH_TOTAL_SUPPLY_SLOT = 0x0000000000000000000000000000000000000000000000000000000000000035; + + function setUp() public override { + super.setUp(); + reserveOracle = new RsEthWstEthReserveOracle(ILK_INDEX, emptyFeeds, QUORUM, MAX_CHANGE); + } + + function _increaseExchangeRate() internal override returns (uint256 newPrice) { + // effectively doubles the exchange rate by giving ETHx amount equal to + // rsETH total supply to the deposit pool. + uint256 prevPrice = RSETH_LRT_ORACLE.rsETHPrice(); + + uint256 totalSupply = RSETH.totalSupply(); + setERC20Balance(address(ETHX_ADDRESS), address(RSETH_LRT_DEPOSIT_POOL), totalSupply); + + RSETH_LRT_ORACLE.updateRSETHPrice(); + + newPrice = RSETH_LRT_ORACLE.rsETHPrice(); + require(newPrice > prevPrice, "price should increase"); + } + + function _decreaseExchangeRate() internal override returns (uint256 newPrice) { + uint256 prevPrice = RSETH_LRT_ORACLE.rsETHPrice(); + + // effectively halves the exchange rate by doubling the rsETH total supply + uint256 newTotalSupply = RSETH.totalSupply() * 2; + vm.store(address(RSETH), RSETH_TOTAL_SUPPLY_SLOT, bytes32(newTotalSupply)); + + RSETH_LRT_ORACLE.updateRSETHPrice(); + + newPrice = RSETH_LRT_ORACLE.rsETHPrice(); + require(newPrice < prevPrice, "price should decrease"); + } + + function _convertToEth(uint256 amt) internal view override returns (uint256) { + // wstETH * ETH / wstETH + return WSTETH_ADDRESS.getStETHByWstETH(amt); + } + + function _getProtocolExchangeRate() internal view override returns (uint256) { + return RSETH_LRT_ORACLE.rsETHPrice().wadMulDown(WSTETH_ADDRESS.tokensPerStEth()); + } +} + +contract WeEthWstEthReserveOracleForkTest is ReserveOracle_ForkTest { + function setUp() public override { + // blockNumber = 19_079_925; + super.setUp(); + reserveOracle = new WeEthWstEthReserveOracle(ILK_INDEX, emptyFeeds, QUORUM, MAX_CHANGE); + } + + // --- Slashing Scenario --- + function test_UnpackEtherFiTotalValue() public { + uint256 totalValueOutOfLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueOutOfLp(); + + uint256 totalValueInLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueInLp(); + + // 0x00000000000001287956cfe67f3b5ffe0000000000001e3b21b7e61ce9aac681 + // [totalValueInLp, totalValueOutOfLp] + bytes32 totalValue = vm.load(address(ETHER_FI_LIQUIDITY_POOL_ADDRESS), EETH_LIQUIDITY_POOL_TOTAL_VALUE_SLOT); + + uint256 unpackedTotalValueInLp = uint256(totalValue >> 128); + + uint256 unpackedTotalValueOutOfLp = uint256(totalValue & EETH_TOTAL_VALUE_MASK); + + assertEq(unpackedTotalValueOutOfLp, totalValueOutOfLp, "totalValueOutOfLp"); + assertEq(unpackedTotalValueInLp, totalValueInLp, "totalValueInLp"); + } + + function test_WstEthExchangeRateGoesDownNotMaxBounded() public { + uint256 maxChange = 3e25; + uint256 clBalanceDiff = 1 ether; + + address[] memory feeds = new address[](3); + uint8 quorum = 0; + + WeEthWstEthReserveOracle weEthWstEthReserveOracle = + new WeEthWstEthReserveOracle(STETH_ILK_INDEX, feeds, quorum, maxChange); + + uint256 exchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); + + bytes32 currClBalance = vm.load(LIDO, LIDO_CL_BALANCE_SLOT); + uint256 newClBalance = uint256(currClBalance) - clBalanceDiff; + + vm.store(LIDO, LIDO_CL_BALANCE_SLOT, bytes32(newClBalance)); + + weEthWstEthReserveOracle.updateExchangeRate(); + uint256 newExchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); + + uint256 maxExchangeRate = exchangeRate + ((exchangeRate * maxChange) / RAY); + + assertLt(newExchangeRate, maxExchangeRate, "below max bound"); + assertGt(newExchangeRate, exchangeRate, "above min bound"); + } + + function test_WeEthExchangeRateGoesDownNotMinBounded() public { + uint256 maxChange = 5e25; + uint256 totalValueOutOfLpDiff = 1 ether; + + address[] memory feeds = new address[](3); + uint8 quorum = 0; + + // sets currentExchange rate to be the current exchangeRate in constructor + WeEthWstEthReserveOracle weEthWstEthReserveOracle = + new WeEthWstEthReserveOracle(STETH_ILK_INDEX, feeds, quorum, maxChange); + + uint256 exchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); + + uint256 totalValueOutOfLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueOutOfLp(); + + uint256 totalValueInLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueInLp(); + + bytes32 newTotalValueInLp = bytes32(totalValueInLp) << 128; + + bytes32 newTotalValueOutOfLp = bytes32(totalValueOutOfLp - totalValueOutOfLpDiff); + + bytes32 newTotalValue = newTotalValueInLp | newTotalValueOutOfLp; + + vm.store(address(ETHER_FI_LIQUIDITY_POOL_ADDRESS), EETH_LIQUIDITY_POOL_TOTAL_VALUE_SLOT, bytes32(newTotalValue)); + + weEthWstEthReserveOracle.updateExchangeRate(); + uint256 newExchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); + + uint256 minExchangeRate = exchangeRate - ((exchangeRate * maxChange) / RAY); + + assertLt(newExchangeRate, exchangeRate, "below previous exchange rate"); + assertGt(newExchangeRate, minExchangeRate, "above minimum exchange rate bound"); + } + + function _increaseExchangeRate() internal override returns (uint256 newPrice) { + uint256 prevPrice = WEETH_ADDRESS.getRate(); + + // effectively doubles the exchange rate by giving ETHx amount equal to + // rsETH total supply to the deposit pool. + uint256 totalValueOutOfLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueOutOfLp(); + uint256 totalValueInLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueInLp(); + + uint256 currTotalValue = totalValueInLp + totalValueOutOfLp; + uint256 newTotalValue = currTotalValue * 2; + + vm.store(address(ETHER_FI_LIQUIDITY_POOL_ADDRESS), EETH_LIQUIDITY_POOL_TOTAL_VALUE_SLOT, bytes32(newTotalValue)); + + newPrice = WEETH_ADDRESS.getRate(); + require(newPrice > prevPrice, "price should increase"); + } + + function _decreaseExchangeRate() internal override returns (uint256 newPrice) { + uint256 prevPrice = WEETH_ADDRESS.getRate(); + + // effectively doubles the exchange rate by giving ETHx amount equal to + // rsETH total supply to the deposit pool. + uint256 totalValueOutOfLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueOutOfLp(); + uint256 totalValueInLp = ETHER_FI_LIQUIDITY_POOL_ADDRESS.totalValueInLp(); + + uint256 currTotalValue = totalValueInLp + totalValueOutOfLp; + uint256 newTotalValue = currTotalValue / 2; + + vm.store(address(ETHER_FI_LIQUIDITY_POOL_ADDRESS), EETH_LIQUIDITY_POOL_TOTAL_VALUE_SLOT, bytes32(newTotalValue)); + + newPrice = WEETH_ADDRESS.getRate(); + require(newPrice < prevPrice, "price should decrease"); + } + + function _convertToEth(uint256 amt) internal view override returns (uint256) { + // wstETH * ETH / wstETH + return WSTETH_ADDRESS.getStETHByWstETH(amt); + } + + function _getProtocolExchangeRate() internal view override returns (uint256) { + return WEETH_ADDRESS.getRate().wadMulDown(WSTETH_ADDRESS.tokensPerStEth()); + } +} diff --git a/test/fork/concrete/RsEthHandlerFork.t.sol b/test/fork/concrete/lrt/RsEthHandler.t.sol similarity index 84% rename from test/fork/concrete/RsEthHandlerFork.t.sol rename to test/fork/concrete/lrt/RsEthHandler.t.sol index 03eb3358..07da7114 100644 --- a/test/fork/concrete/RsEthHandlerFork.t.sol +++ b/test/fork/concrete/lrt/RsEthHandler.t.sol @@ -1,15 +1,15 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { IRsEth } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { KelpDaoLibrary } from "../../../src/libraries/KelpDaoLibrary.sol"; -import { RsEthHandler } from "../../../src/flash/handlers/RsEthHandler.sol"; -import { Whitelist } from "../../../src/Whitelist.sol"; -import { RSETH, RSETH_LRT_DEPOSIT_POOL } from "../../../src/Constants.sol"; -import { LrtHandler_ForkBase } from "../../helpers/handlers/LrtHandlerForkBase.sol"; - -import { IProviderLibraryExposed } from "../../helpers/IProviderLibraryExposed.sol"; -import { UniswapFlashswapDirectMintHandler_Test } from "./handlers-base/UniswapFlashswapDirectMintHandler.t.sol"; +import { IRsEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; +import { KelpDaoLibrary } from "../../../../src/libraries/lrt/KelpDaoLibrary.sol"; +import { RsEthHandler } from "../../../../src/flash/lrt/RsEthHandler.sol"; +import { Whitelist } from "../../../../src/Whitelist.sol"; +import { RSETH, RSETH_LRT_DEPOSIT_POOL } from "../../../../src/Constants.sol"; +import { LrtHandler_ForkBase } from "../../../helpers/handlers/LrtHandlerForkBase.sol"; + +import { IProviderLibraryExposed } from "../../../helpers/IProviderLibraryExposed.sol"; +import { UniswapFlashswapDirectMintHandler_Test } from "../handlers-base/UniswapFlashswapDirectMintHandler.t.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/test/fork/concrete/SpotOracleFork.t.sol b/test/fork/concrete/lrt/SpotOracle.t.sol similarity index 69% rename from test/fork/concrete/SpotOracleFork.t.sol rename to test/fork/concrete/lrt/SpotOracle.t.sol index b841385c..f1c542fe 100644 --- a/test/fork/concrete/SpotOracleFork.t.sol +++ b/test/fork/concrete/lrt/SpotOracle.t.sol @@ -2,13 +2,15 @@ pragma solidity 0.8.21; -import { ReserveOracleSharedSetup } from "../../helpers/ReserveOracleSharedSetup.sol"; -import { RsEthWstEthSpotOracle } from "./../../../src/oracles/spot/rsEthWstEthSpotOracle.sol"; -import { ReserveOracle } from "./../../../src/oracles/reserve/ReserveOracle.sol"; -import { SpotOracle } from "./../../../src/oracles/spot/SpotOracle.sol"; -import { RsEthWstEthReserveOracle } from "./../../../src/oracles/reserve/RsEthWstEthReserveOracle.sol"; -import { WadRayMath } from "./../../../src/libraries/math/WadRayMath.sol"; -import { console2 } from "forge-std/console2.sol"; +import { ReserveOracle } from "../../../../src/oracles/reserve/ReserveOracle.sol"; +import { SpotOracle } from "../../../../src/oracles/spot/SpotOracle.sol"; +import { RsEthWstEthReserveOracle } from "../../../../src/oracles/reserve/lrt/RsEthWstEthReserveOracle.sol"; +import { RsEthWstEthSpotOracle } from "../../../../src/oracles/spot/lrt/rsEthWstEthSpotOracle.sol"; +import { WeEthWstEthReserveOracle } from "../../../../src/oracles/reserve/lrt/WeEthWstEthReserveOracle.sol"; +import { WeEthWstEthSpotOracle } from "../../../../src/oracles/spot/lrt/weEthWstEthSpotOracle.sol"; +import { WadRayMath } from "../../../../src/libraries/math/WadRayMath.sol"; + +import { ReserveOracleSharedSetup } from "../../../helpers/ReserveOracleSharedSetup.sol"; abstract contract SpotOracle_ForkTest is ReserveOracleSharedSetup { using WadRayMath for uint256; @@ -20,7 +22,6 @@ abstract contract SpotOracle_ForkTest is ReserveOracleSharedSetup { function testFork_ViewPrice() public { uint256 price = spotOracle.getPrice(); - console2.log("price", price); assertGt(price, 0, "price greater than zero"); } @@ -29,7 +30,6 @@ abstract contract SpotOracle_ForkTest is ReserveOracleSharedSetup { uint256 ltv = spotOracle.LTV(); uint256 expectedSpot = ltv.wadMulDown(price); uint256 spot = spotOracle.getSpot(); - console2.log("spot", spot); assertEq(spot, expectedSpot, "spot"); } @@ -69,6 +69,17 @@ abstract contract SpotOracle_ForkTest is ReserveOracleSharedSetup { } } +contract WeEthWstEthSpotOracle_ForkTest is SpotOracle_ForkTest { + uint256 constant MAX_TIME_FROM_LAST_UPDATE = 87_000; + uint256 constant MAX_LTV = 0.8e27; + + function setUp() public override { + super.setUp(); + reserveOracle = new WeEthWstEthReserveOracle(ILK_INDEX, emptyFeeds, QUORUM, DEFAULT_MAX_CHANGE); + spotOracle = new WeEthWstEthSpotOracle(MAX_LTV, address(reserveOracle), MAX_TIME_FROM_LAST_UPDATE); + } +} + contract RsEthWstEthSpotOracle_ForkTest is SpotOracle_ForkTest { uint256 constant MAX_TIME_FROM_LAST_UPDATE = 87_000; uint256 constant MAX_LTV = 0.8e27; diff --git a/test/fork/concrete/WeEthHandlerFork.t.sol b/test/fork/concrete/lrt/WeEthHandler.t.sol similarity index 85% rename from test/fork/concrete/WeEthHandlerFork.t.sol rename to test/fork/concrete/lrt/WeEthHandler.t.sol index 45055f14..f541df0e 100644 --- a/test/fork/concrete/WeEthHandlerFork.t.sol +++ b/test/fork/concrete/lrt/WeEthHandler.t.sol @@ -1,15 +1,15 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { IWeEth } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { EtherFiLibrary } from "../../../src/libraries/EtherFiLibrary.sol"; -import { LrtHandler_ForkBase } from "../../helpers/handlers/LrtHandlerForkBase.sol"; -import { WeEthHandler } from "../../../src/flash/handlers/WeEthHandler.sol"; -import { Whitelist } from "../../../src/Whitelist.sol"; -import { WEETH_ADDRESS, EETH_ADDRESS } from "../../../src/Constants.sol"; - -import { IProviderLibraryExposed } from "../../helpers/IProviderLibraryExposed.sol"; -import { UniswapFlashswapDirectMintHandler_Test } from "./handlers-base/UniswapFlashswapDirectMintHandler.t.sol"; +import { IWeEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; +import { EtherFiLibrary } from "../../../../src/libraries/lrt/EtherFiLibrary.sol"; +import { LrtHandler_ForkBase } from "../../../helpers/handlers/LrtHandlerForkBase.sol"; +import { WeEthHandler } from "../../../../src/flash/lrt/WeEthHandler.sol"; +import { Whitelist } from "../../../../src/Whitelist.sol"; +import { WEETH_ADDRESS, EETH_ADDRESS } from "../../../../src/Constants.sol"; + +import { IProviderLibraryExposed } from "../../../helpers/IProviderLibraryExposed.sol"; +import { UniswapFlashswapDirectMintHandler_Test } from "../handlers-base/UniswapFlashswapDirectMintHandler.t.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/test/fork/concrete/EthXHandlerFork.t.sol b/test/fork/concrete/lst/EthXHandler.t.sol similarity index 84% rename from test/fork/concrete/EthXHandlerFork.t.sol rename to test/fork/concrete/lst/EthXHandler.t.sol index d44b105f..1b5d0c0b 100644 --- a/test/fork/concrete/EthXHandlerFork.t.sol +++ b/test/fork/concrete/lst/EthXHandler.t.sol @@ -1,15 +1,15 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { IStaderStakePoolsManager } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { EthXHandler } from "../../../src/flash/handlers/EthXHandler.sol"; -import { StaderLibrary } from "../../../src/libraries/StaderLibrary.sol"; -import { Whitelist } from "../../../src/Whitelist.sol"; - -import { BalancerFlashloanDirectMintHandler_Test } from "./handlers-base/BalancerFlashloanDirectMintHandler.t.sol"; -import { UniswapFlashloanBalancerSwapHandler_Test } from "./handlers-base/UniswapFlashloanBalancerSwapHandler.t.sol"; -import { LstHandler_ForkBase } from "../../helpers/handlers/LstHandlerForkBase.sol"; -import { IProviderLibraryExposed } from "../../helpers/IProviderLibraryExposed.sol"; +import { IStaderStakePoolsManager } from "../../../../src/interfaces/ProviderInterfaces.sol"; +import { EthXHandler } from "../../../../src/flash/lst/EthXHandler.sol"; +import { StaderLibrary } from "../../../../src/libraries/lst/StaderLibrary.sol"; +import { Whitelist } from "../../../../src/Whitelist.sol"; + +import { BalancerFlashloanDirectMintHandler_Test } from "../handlers-base/BalancerFlashloanDirectMintHandler.t.sol"; +import { UniswapFlashloanBalancerSwapHandler_Test } from "../handlers-base/UniswapFlashloanBalancerSwapHandler.t.sol"; +import { LstHandler_ForkBase } from "../../../helpers/handlers/LstHandlerForkBase.sol"; +import { IProviderLibraryExposed } from "../../../helpers/IProviderLibraryExposed.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; diff --git a/test/fork/concrete/EthXReserveOracleFork.t.sol b/test/fork/concrete/lst/EthXReserveOracle.t.sol similarity index 93% rename from test/fork/concrete/EthXReserveOracleFork.t.sol rename to test/fork/concrete/lst/EthXReserveOracle.t.sol index 0e842826..d06a98b3 100644 --- a/test/fork/concrete/EthXReserveOracleFork.t.sol +++ b/test/fork/concrete/lst/EthXReserveOracle.t.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { EthXReserveOracle } from "../../../src/oracles/reserve/EthXReserveOracle.sol"; -import { ReserveFeed } from "../../../src/oracles/reserve/ReserveFeed.sol"; -import { IStaderStakePoolsManager } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { WadRayMath, RAY } from "../../../src/libraries/math/WadRayMath.sol"; -import { ReserveOracle } from "../../../src/oracles/reserve/ReserveOracle.sol"; -import { ReserveOracleSharedSetup } from "../../helpers/ReserveOracleSharedSetup.sol"; +import { EthXReserveOracle } from "../../../../src/oracles/reserve/lst/EthXReserveOracle.sol"; +import { ReserveFeed } from "../../../../src/oracles/reserve/ReserveFeed.sol"; +import { IStaderStakePoolsManager } from "../../../../src/interfaces/ProviderInterfaces.sol"; +import { WadRayMath, RAY } from "../../../../src/libraries/math/WadRayMath.sol"; +import { ReserveOracle } from "../../../../src/oracles/reserve/ReserveOracle.sol"; +import { ReserveOracleSharedSetup } from "../../../helpers/ReserveOracleSharedSetup.sol"; contract EthXReserveOracleForkTest is ReserveOracleSharedSetup { using WadRayMath for *; diff --git a/test/fork/concrete/SpotOracle.t.sol b/test/fork/concrete/lst/SpotOracle.t.sol similarity index 61% rename from test/fork/concrete/SpotOracle.t.sol rename to test/fork/concrete/lst/SpotOracle.t.sol index 07999af8..d17cd5d0 100644 --- a/test/fork/concrete/SpotOracle.t.sol +++ b/test/fork/concrete/lst/SpotOracle.t.sol @@ -2,19 +2,17 @@ pragma solidity 0.8.21; -import { SpotOracle } from "../../../src/oracles/spot/SpotOracle.sol"; -import { SwEthSpotOracle } from "../../../src/oracles/spot/SwEthSpotOracle.sol"; -import { WstEthSpotOracle } from "../../../src/oracles/spot/WstEthSpotOracle.sol"; -import { EthXSpotOracle } from "../../../src/oracles/spot/EthXSpotOracle.sol"; -import { WeEthWstEthSpotOracle } from "../../../src/oracles/spot/WeEthWstEthSpotOracle.sol"; -import { ReserveOracle } from "../../../src/oracles/reserve/ReserveOracle.sol"; -import { SwEthReserveOracle } from "../../../src/oracles/reserve/SwEthReserveOracle.sol"; -import { WstEthReserveOracle } from "../../../src/oracles/reserve/WstEthReserveOracle.sol"; -import { EthXReserveOracle } from "../../../src/oracles/reserve/EthXReserveOracle.sol"; -import { WeEthWstEthReserveOracle } from "../../../src/oracles/reserve/WeEthWstEthReserveOracle.sol"; -import { WadRayMath } from "../../../src/libraries/math/WadRayMath.sol"; - -import { ReserveOracleSharedSetup } from "../../helpers/ReserveOracleSharedSetup.sol"; +import { SpotOracle } from "../../../../src/oracles/spot/SpotOracle.sol"; +import { SwEthSpotOracle } from "../../../../src/oracles/spot/lst/SwEthSpotOracle.sol"; +import { WstEthSpotOracle } from "../../../../src/oracles/spot/lst/WstEthSpotOracle.sol"; +import { EthXSpotOracle } from "../../../../src/oracles/spot/lst/EthXSpotOracle.sol"; +import { ReserveOracle } from "../../../../src/oracles/reserve/ReserveOracle.sol"; +import { SwEthReserveOracle } from "../../../../src/oracles/reserve/lst/SwEthReserveOracle.sol"; +import { WstEthReserveOracle } from "../../../../src/oracles/reserve/lst/WstEthReserveOracle.sol"; +import { EthXReserveOracle } from "../../../../src/oracles/reserve/lst/EthXReserveOracle.sol"; +import { WadRayMath } from "../../../../src/libraries/math/WadRayMath.sol"; + +import { ReserveOracleSharedSetup } from "../../../helpers/ReserveOracleSharedSetup.sol"; // fork tests for integrating with external contracts contract SpotOracleForkTest is ReserveOracleSharedSetup { @@ -200,87 +198,3 @@ contract SpotOracleForkTest is ReserveOracleSharedSetup { assertEq(ethXSpotOracle.getSpot(), expectedSpot, "spot"); } } - -contract WeEthWstEthSpotOracleForkTest is ReserveOracleSharedSetup { - using WadRayMath for uint256; - - WeEthWstEthSpotOracle weEthWstEthSpotOracle; - WeEthWstEthReserveOracle weEthWstEthReserveOracle; - - function setUp() public override { - // fork test - blockNumber = 19_084_676; // after ETH per weETH Redstone deployment - super.setUp(); - - // instantiate reserve oracles - address[] memory feeds = new address[](3); - weEthWstEthReserveOracle = new WeEthWstEthReserveOracle(ILK_INDEX, feeds, QUORUM, DEFAULT_MAX_CHANGE); - } - - function test_WeEthWstEthSpotOracleViewPrice() public { - uint256 ltv = 0.5e27; - uint256 maxTimeFromLastUpdate = 2 days; - - weEthWstEthSpotOracle = new WeEthWstEthSpotOracle(ltv, address(weEthWstEthReserveOracle), maxTimeFromLastUpdate); - - uint256 price = weEthWstEthSpotOracle.getPrice(); - - assertEq(price, 891_763_339_537_677_809, "wstETH per weETH price"); - } - - function test_WeEthWstEthSpotOracleSpotPriceGoesUpUsesExchangeRateAsMin() public { - uint256 ltv = 0.5e27; - uint256 maxTimeFromLastUpdate = 2 days; - weEthWstEthSpotOracle = new WeEthWstEthSpotOracle(ltv, address(weEthWstEthReserveOracle), maxTimeFromLastUpdate); - uint256 spot = weEthWstEthSpotOracle.getSpot(); - - weEthWstEthReserveOracle.updateExchangeRate(); - uint256 newExchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); - uint256 expectedSpot = ltv.wadMulDown(newExchangeRate); - - assertEq(spot, expectedSpot, "wstETH per weETH spot"); - } - - function test_WeEthWstEthOracleExchangeRateGoesDownUsesExchangeRateAsMin() public { - uint256 ltv = 0.7e27; - uint256 maxTimeFromLastUpdate = 2 days; - weEthWstEthSpotOracle = new WeEthWstEthSpotOracle(ltv, address(weEthWstEthReserveOracle), maxTimeFromLastUpdate); - - uint256 weEthLpDiff = 1000 ether; - changeWeEthLpBalance(weEthLpDiff); - - weEthWstEthReserveOracle.updateExchangeRate(); - - uint256 newExchangeRate = weEthWstEthReserveOracle.currentExchangeRate(); - - uint256 expectedPrice = 891_763_339_537_677_809; - uint256 expectedSpot = ltv.wadMulDown(newExchangeRate); - - assertEq(weEthWstEthSpotOracle.getPrice(), expectedPrice, "price"); - assertEq(weEthWstEthSpotOracle.getSpot(), expectedSpot, "spot"); - } - - function test_WeEthWstEthOracleMaxTimeFromLastUpdateExceeded() public { - uint256 ltv = 0.7e27; - uint256 maxTimeFromLastUpdate = 2 days; - weEthWstEthSpotOracle = new WeEthWstEthSpotOracle(ltv, address(weEthWstEthReserveOracle), maxTimeFromLastUpdate); - - vm.warp(block.timestamp + 2 days); - - uint256 expectedPrice = 0; - uint256 expectedSpot = 0; - assertEq(weEthWstEthSpotOracle.getPrice(), expectedPrice, "price"); - assertEq(weEthWstEthSpotOracle.getSpot(), expectedSpot, "spot"); - } - - function test_WeEthWstEthOracleMaxTimeFromLastUpdateNotExceeded() public { - uint256 ltv = 0.7e27; - uint256 maxTimeFromLastUpdate = 2 days; - weEthWstEthSpotOracle = new WeEthWstEthSpotOracle(ltv, address(weEthWstEthReserveOracle), maxTimeFromLastUpdate); - - vm.warp(block.timestamp + 1 days); - - assertNotEq(weEthWstEthSpotOracle.getPrice(), 0, "price"); - assertNotEq(weEthWstEthSpotOracle.getSpot(), 0, "spot"); - } -} diff --git a/test/fork/concrete/SwEthHandlerFork.t.sol b/test/fork/concrete/lst/SwEthHandler.t.sol similarity index 84% rename from test/fork/concrete/SwEthHandlerFork.t.sol rename to test/fork/concrete/lst/SwEthHandler.t.sol index 95e8bd7f..6f7be9c3 100644 --- a/test/fork/concrete/SwEthHandlerFork.t.sol +++ b/test/fork/concrete/lst/SwEthHandler.t.sol @@ -1,15 +1,15 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { ISwEth } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { SwEthHandler } from "../../../src/flash/handlers/SwEthHandler.sol"; -import { SwellLibrary } from "../../../src/libraries/SwellLibrary.sol"; -import { Whitelist } from "../../../src/Whitelist.sol"; - -import { LstHandler_ForkBase } from "../../helpers/handlers/LstHandlerForkBase.sol"; -import { IProviderLibraryExposed } from "../../helpers/IProviderLibraryExposed.sol"; -import { BalancerFlashloanDirectMintHandler_Test } from "./handlers-base/BalancerFlashloanDirectMintHandler.t.sol"; -import { UniswapFlashswapHandler_Test } from "./handlers-base/UniswapFlashswapHandler.t.sol"; +import { ISwEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; +import { SwEthHandler } from "../../../../src/flash//lst/SwEthHandler.sol"; +import { SwellLibrary } from "../../../../src/libraries/lst/SwellLibrary.sol"; +import { Whitelist } from "../../../../src/Whitelist.sol"; + +import { LstHandler_ForkBase } from "../../../helpers/handlers/LstHandlerForkBase.sol"; +import { IProviderLibraryExposed } from "../../../helpers/IProviderLibraryExposed.sol"; +import { BalancerFlashloanDirectMintHandler_Test } from "../handlers-base/BalancerFlashloanDirectMintHandler.t.sol"; +import { UniswapFlashswapHandler_Test } from "../handlers-base/UniswapFlashswapHandler.t.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; diff --git a/test/fork/concrete/SwEthReserveOracleFork.t.sol b/test/fork/concrete/lst/SwEthReserveOracle.t.sol similarity index 94% rename from test/fork/concrete/SwEthReserveOracleFork.t.sol rename to test/fork/concrete/lst/SwEthReserveOracle.t.sol index 726d935b..210d7019 100644 --- a/test/fork/concrete/SwEthReserveOracleFork.t.sol +++ b/test/fork/concrete/lst/SwEthReserveOracle.t.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { SwEthReserveOracle } from "../../../src/oracles/reserve/SwEthReserveOracle.sol"; -import { ReserveFeed } from "../../../src/oracles/reserve/ReserveFeed.sol"; -import { ISwEth } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { RAY } from "../../../src/libraries/math/WadRayMath.sol"; -import { ReserveOracle } from "../../../src/oracles/reserve/ReserveOracle.sol"; -import { ReserveOracleSharedSetup } from "../../helpers/ReserveOracleSharedSetup.sol"; +import { SwEthReserveOracle } from "../../../../src/oracles/reserve/lst/SwEthReserveOracle.sol"; +import { ReserveFeed } from "../../../../src/oracles/reserve/ReserveFeed.sol"; +import { ISwEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; +import { RAY } from "../../../../src/libraries/math/WadRayMath.sol"; +import { ReserveOracle } from "../../../../src/oracles/reserve/ReserveOracle.sol"; +import { ReserveOracleSharedSetup } from "../../../helpers/ReserveOracleSharedSetup.sol"; contract SwEthReserveOracleForkTest is ReserveOracleSharedSetup { // --- swETH Reserve Oracle Test --- diff --git a/test/fork/concrete/WstEthHandlerFork.t.sol b/test/fork/concrete/lst/WstEthHandler.t.sol similarity index 96% rename from test/fork/concrete/WstEthHandlerFork.t.sol rename to test/fork/concrete/lst/WstEthHandler.t.sol index 60a1dfcb..ff9af81d 100644 --- a/test/fork/concrete/WstEthHandlerFork.t.sol +++ b/test/fork/concrete/lst/WstEthHandler.t.sol @@ -1,17 +1,17 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { IWstEth } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { WstEthHandler } from "../../../src/flash/handlers/WstEthHandler.sol"; -import { WadRayMath, RAY } from "../../../src/libraries/math/WadRayMath.sol"; -import { LidoLibrary } from "../../../src/libraries/LidoLibrary.sol"; -import { Whitelist } from "../../../src/Whitelist.sol"; -import { IonHandlerBase } from "../../../src/flash/handlers/base/IonHandlerBase.sol"; - -import { BalancerFlashloanDirectMintHandler_Test } from "./handlers-base/BalancerFlashloanDirectMintHandler.t.sol"; -import { UniswapFlashswapHandler_Test } from "./handlers-base/UniswapFlashswapHandler.t.sol"; -import { LstHandler_ForkBase } from "../../helpers/handlers/LstHandlerForkBase.sol"; -import { IProviderLibraryExposed } from "../../helpers/IProviderLibraryExposed.sol"; +import { IWstEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; +import { WstEthHandler } from "../../../../src/flash/lst/WstEthHandler.sol"; +import { WadRayMath, RAY } from "../../../../src/libraries/math/WadRayMath.sol"; +import { LidoLibrary } from "../../../../src/libraries/lst/LidoLibrary.sol"; +import { Whitelist } from "../../../../src/Whitelist.sol"; +import { IonHandlerBase } from "../../../../src/flash/IonHandlerBase.sol"; + +import { BalancerFlashloanDirectMintHandler_Test } from "../handlers-base/BalancerFlashloanDirectMintHandler.t.sol"; +import { UniswapFlashswapHandler_Test } from "../handlers-base/UniswapFlashswapHandler.t.sol"; +import { LstHandler_ForkBase } from "../../../helpers/handlers/LstHandlerForkBase.sol"; +import { IProviderLibraryExposed } from "../../../helpers/IProviderLibraryExposed.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; diff --git a/test/fork/concrete/WstEthReserveOracleFork.t.sol b/test/fork/concrete/lst/WstEthReserveOracle.t.sol similarity index 93% rename from test/fork/concrete/WstEthReserveOracleFork.t.sol rename to test/fork/concrete/lst/WstEthReserveOracle.t.sol index 257a123e..b035863a 100644 --- a/test/fork/concrete/WstEthReserveOracleFork.t.sol +++ b/test/fork/concrete/lst/WstEthReserveOracle.t.sol @@ -1,13 +1,13 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { WAD, RAY } from "../../../src/libraries/math/WadRayMath.sol"; -import { WstEthReserveOracle } from "../../../src/oracles/reserve/WstEthReserveOracle.sol"; -import { ReserveFeed } from "../../../src/oracles/reserve/ReserveFeed.sol"; -import { ReserveOracle } from "../../../src/oracles/reserve/ReserveOracle.sol"; -import { IStEth, IWstEth } from "../../../src/interfaces/ProviderInterfaces.sol"; +import { WAD, RAY } from "../../../../src/libraries/math/WadRayMath.sol"; +import { WstEthReserveOracle } from "../../../../src/oracles/reserve/lst/WstEthReserveOracle.sol"; +import { ReserveFeed } from "../../../../src/oracles/reserve/ReserveFeed.sol"; +import { ReserveOracle } from "../../../../src/oracles/reserve/ReserveOracle.sol"; +import { IStEth, IWstEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; -import { ReserveOracleSharedSetup } from "../../helpers/ReserveOracleSharedSetup.sol"; +import { ReserveOracleSharedSetup } from "../../../helpers/ReserveOracleSharedSetup.sol"; // fork tests for integrating with external contracts contract WstEthReserveOracleForkTest is ReserveOracleSharedSetup { diff --git a/test/fork/fuzz/handlers-base/BalancerFlashloanDirectMintHandler.t.sol b/test/fork/fuzz/handlers-base/BalancerFlashloanDirectMintHandler.t.sol index 2c1941d7..1575782c 100644 --- a/test/fork/fuzz/handlers-base/BalancerFlashloanDirectMintHandler.t.sol +++ b/test/fork/fuzz/handlers-base/BalancerFlashloanDirectMintHandler.t.sol @@ -3,8 +3,7 @@ pragma solidity 0.8.21; import { LstHandler_ForkBase } from "../../../helpers/handlers/LstHandlerForkBase.sol"; import { WadRayMath, RAY } from "../../../../src/libraries/math/WadRayMath.sol"; -import { BalancerFlashloanDirectMintHandler } from - "../../../../src/flash/handlers/base/BalancerFlashloanDirectMintHandler.sol"; +import { BalancerFlashloanDirectMintHandler } from "../../../../src/flash/BalancerFlashloanDirectMintHandler.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; diff --git a/test/fork/fuzz/handlers-base/UniswapFlashloanBalancerSwapHandler.t.sol b/test/fork/fuzz/handlers-base/UniswapFlashloanBalancerSwapHandler.t.sol index effc6fe0..b84b2a61 100644 --- a/test/fork/fuzz/handlers-base/UniswapFlashloanBalancerSwapHandler.t.sol +++ b/test/fork/fuzz/handlers-base/UniswapFlashloanBalancerSwapHandler.t.sol @@ -3,8 +3,7 @@ pragma solidity 0.8.21; import { LstHandler_ForkBase } from "../../../helpers/handlers/LstHandlerForkBase.sol"; import { WadRayMath, RAY, WAD } from "../../../../src/libraries/math/WadRayMath.sol"; -import { UniswapFlashloanBalancerSwapHandler } from - "../../../../src/flash/handlers/base/UniswapFlashloanBalancerSwapHandler.sol"; +import { UniswapFlashloanBalancerSwapHandler } from "../../../../src/flash/UniswapFlashloanBalancerSwapHandler.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; diff --git a/test/fork/fuzz/handlers-base/UniswapFlashswapDirectMintHandler.t.sol b/test/fork/fuzz/handlers-base/UniswapFlashswapDirectMintHandler.t.sol index 37d7cbb5..6f62ba30 100644 --- a/test/fork/fuzz/handlers-base/UniswapFlashswapDirectMintHandler.t.sol +++ b/test/fork/fuzz/handlers-base/UniswapFlashswapDirectMintHandler.t.sol @@ -2,8 +2,7 @@ pragma solidity 0.8.21; import { LrtHandler_ForkBase } from "../../../helpers/handlers/LrtHandlerForkBase.sol"; -import { UniswapFlashswapDirectMintHandler } from - "../../../../src/flash/handlers/base/UniswapFlashswapDirectMintHandler.sol"; +import { UniswapFlashswapDirectMintHandler } from "../../../../src/flash/UniswapFlashswapDirectMintHandler.sol"; import { WadRayMath, RAY } from "../../../../src/libraries/math/WadRayMath.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/test/fork/fuzz/handlers-base/UniswapFlashswapHandler.t.sol b/test/fork/fuzz/handlers-base/UniswapFlashswapHandler.t.sol index df1f13ad..868d9846 100644 --- a/test/fork/fuzz/handlers-base/UniswapFlashswapHandler.t.sol +++ b/test/fork/fuzz/handlers-base/UniswapFlashswapHandler.t.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.21; import { LstHandler_ForkBase } from "../../../helpers/handlers/LstHandlerForkBase.sol"; import { WadRayMath, RAY, WAD } from "../../../../src/libraries/math/WadRayMath.sol"; -import { UniswapFlashswapHandler } from "../../../../src/flash/handlers/base/UniswapFlashswapHandler.sol"; +import { UniswapFlashswapHandler } from "../../../../src/flash/UniswapFlashswapHandler.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; diff --git a/test/fork/fuzz/EtherFiLibrary.t.sol b/test/fork/fuzz/lrt/EtherFiLibrary.t.sol similarity index 85% rename from test/fork/fuzz/EtherFiLibrary.t.sol rename to test/fork/fuzz/lrt/EtherFiLibrary.t.sol index cb8e01b5..ce74d121 100644 --- a/test/fork/fuzz/EtherFiLibrary.t.sol +++ b/test/fork/fuzz/lrt/EtherFiLibrary.t.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.21; -import { EtherFiLibrary } from "../../../src/libraries/EtherFiLibrary.sol"; -import { IWeEth } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { WEETH_ADDRESS, EETH_ADDRESS } from "../../../src/Constants.sol"; +import { EtherFiLibrary } from "../../../../src/libraries/lrt/EtherFiLibrary.sol"; +import { IWeEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; +import { WEETH_ADDRESS, EETH_ADDRESS } from "../../../../src/Constants.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/test/fork/fuzz/KelpDaoLibrary.t.sol b/test/fork/fuzz/lrt/KelpDaoLibrary.t.sol similarity index 89% rename from test/fork/fuzz/KelpDaoLibrary.t.sol rename to test/fork/fuzz/lrt/KelpDaoLibrary.t.sol index 5a44b62a..ea21d7fb 100644 --- a/test/fork/fuzz/KelpDaoLibrary.t.sol +++ b/test/fork/fuzz/lrt/KelpDaoLibrary.t.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.21; -import { KelpDaoLibrary } from "../../../src/libraries/KelpDaoLibrary.sol"; -import { IRsEth } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { RSETH, RSETH_LRT_DEPOSIT_POOL, ETH_ADDRESS } from "../../../src/Constants.sol"; +import { KelpDaoLibrary } from "../../../../src/libraries/lrt/KelpDaoLibrary.sol"; +import { IRsEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; +import { RSETH, RSETH_LRT_DEPOSIT_POOL, ETH_ADDRESS } from "../../../../src/Constants.sol"; import { Test } from "forge-std/Test.sol"; diff --git a/test/fork/fuzz/RsEthHandlerForkFuzz.t.sol b/test/fork/fuzz/lrt/RsEthHandler.t.sol similarity index 79% rename from test/fork/fuzz/RsEthHandlerForkFuzz.t.sol rename to test/fork/fuzz/lrt/RsEthHandler.t.sol index 52721ddd..915b3732 100644 --- a/test/fork/fuzz/RsEthHandlerForkFuzz.t.sol +++ b/test/fork/fuzz/lrt/RsEthHandler.t.sol @@ -1,13 +1,13 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { RsEthHandler_ForkBase } from "../concrete/RsEthHandlerFork.t.sol"; -import { LrtHandler_ForkBase } from "../../helpers/handlers/LrtHandlerForkBase.sol"; +import { RsEthHandler_ForkBase } from "../../concrete/lrt/RsEthHandler.t.sol"; +import { LrtHandler_ForkBase } from "../../../helpers/handlers/LrtHandlerForkBase.sol"; import { UniswapFlashswapDirectMintHandler_FuzzTest, UniswapFlashswapDirectMintHandler_WithRateChange_FuzzTest -} from "./handlers-base/UniswapFlashswapDirectMintHandler.t.sol"; -import { RSETH, RSETH_LRT_DEPOSIT_POOL } from "../../../src/Constants.sol"; +} from "../handlers-base/UniswapFlashswapDirectMintHandler.t.sol"; +import { RSETH, RSETH_LRT_DEPOSIT_POOL } from "../../../../src/Constants.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; diff --git a/test/fork/fuzz/WeEthHandlerForkFuzz.t.sol b/test/fork/fuzz/lrt/WeEthHandler.t.sol similarity index 80% rename from test/fork/fuzz/WeEthHandlerForkFuzz.t.sol rename to test/fork/fuzz/lrt/WeEthHandler.t.sol index c7fcaf7b..7baa15d3 100644 --- a/test/fork/fuzz/WeEthHandlerForkFuzz.t.sol +++ b/test/fork/fuzz/lrt/WeEthHandler.t.sol @@ -1,13 +1,13 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { WeEthHandler_ForkBase } from "../concrete/WeEthHandlerFork.t.sol"; -import { LrtHandler_ForkBase } from "../../helpers/handlers/LrtHandlerForkBase.sol"; +import { WeEthHandler_ForkBase } from "../../concrete/lrt/WeEthHandler.t.sol"; +import { LrtHandler_ForkBase } from "../../../helpers/handlers/LrtHandlerForkBase.sol"; import { UniswapFlashswapDirectMintHandler_FuzzTest, UniswapFlashswapDirectMintHandler_WithRateChange_FuzzTest -} from "./handlers-base/UniswapFlashswapDirectMintHandler.t.sol"; -import { WEETH_ADDRESS } from "../../../src/Constants.sol"; +} from "../handlers-base/UniswapFlashswapDirectMintHandler.t.sol"; +import { WEETH_ADDRESS } from "../../../../src/Constants.sol"; import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol"; diff --git a/test/fork/fuzz/EthXHandlerForkFuzz.t.sol b/test/fork/fuzz/lst/EthXHandler.t.sol similarity index 71% rename from test/fork/fuzz/EthXHandlerForkFuzz.t.sol rename to test/fork/fuzz/lst/EthXHandler.t.sol index 798e56f5..9c1af4a6 100644 --- a/test/fork/fuzz/EthXHandlerForkFuzz.t.sol +++ b/test/fork/fuzz/lst/EthXHandler.t.sol @@ -1,23 +1,23 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { EthXHandler_ForkBase } from "../../fork/concrete/EthXHandlerFork.t.sol"; -import { LstHandler_ForkBase } from "../../helpers/handlers/LstHandlerForkBase.sol"; -import { WadRayMath } from "../../../src/libraries/math/WadRayMath.sol"; -import { IStaderStakePoolsManager } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { StaderLibrary } from "../../../src/libraries/StaderLibrary.sol"; +import { EthXHandler_ForkBase } from "../../../fork/concrete/lst/EthXHandler.t.sol"; +import { LstHandler_ForkBase } from "../../../helpers/handlers/LstHandlerForkBase.sol"; +import { WadRayMath } from "../../../../src/libraries/math/WadRayMath.sol"; +import { IStaderStakePoolsManager } from "../../../../src/interfaces/ProviderInterfaces.sol"; +import { StaderLibrary } from "../../../../src/libraries/lst/StaderLibrary.sol"; import { BalancerFlashloanDirectMintHandler_FuzzTest, BalancerFlashloanDirectMintHandler_WithRateChange_FuzzTest -} from "./handlers-base/BalancerFlashloanDirectMintHandler.t.sol"; +} from "../handlers-base/BalancerFlashloanDirectMintHandler.t.sol"; import { UniswapFlashswapHandler_FuzzTest, UniswapFlashswapHandler_WithRateChange_FuzzTest -} from "./handlers-base/UniswapFlashswapHandler.t.sol"; +} from "../handlers-base/UniswapFlashswapHandler.t.sol"; import { UniswapFlashloanBalancerSwapHandler_FuzzTest, UniswapFlashloanBalancerSwapHandler_WithRateChange_FuzzTest -} from "./handlers-base/UniswapFlashloanBalancerSwapHandler.t.sol"; +} from "../handlers-base/UniswapFlashloanBalancerSwapHandler.t.sol"; using StaderLibrary for IStaderStakePoolsManager; diff --git a/test/fork/fuzz/LidoLibrary.t.sol b/test/fork/fuzz/lst/LidoLibrary.t.sol similarity index 87% rename from test/fork/fuzz/LidoLibrary.t.sol rename to test/fork/fuzz/lst/LidoLibrary.t.sol index 06487bf9..8d429956 100644 --- a/test/fork/fuzz/LidoLibrary.t.sol +++ b/test/fork/fuzz/lst/LidoLibrary.t.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.21; -import { LidoLibrary } from "../../../src/libraries/LidoLibrary.sol"; -import { IWstEth } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { IStEth } from "../../../src/interfaces/ProviderInterfaces.sol"; +import { LidoLibrary } from "../../../../src/libraries/lst/LidoLibrary.sol"; +import { IWstEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; +import { IStEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/test/fork/fuzz/StaderLibrary.t.sol b/test/fork/fuzz/lst/StaderLibrary.t.sol similarity index 94% rename from test/fork/fuzz/StaderLibrary.t.sol rename to test/fork/fuzz/lst/StaderLibrary.t.sol index bd149b92..8d750902 100644 --- a/test/fork/fuzz/StaderLibrary.t.sol +++ b/test/fork/fuzz/lst/StaderLibrary.t.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { StaderLibrary } from "../../../src/libraries/StaderLibrary.sol"; -import { IStaderStakePoolsManager, IStaderConfig } from "../../../src/interfaces/ProviderInterfaces.sol"; +import { StaderLibrary } from "../../../../src/libraries/lst/StaderLibrary.sol"; +import { IStaderStakePoolsManager, IStaderConfig } from "../../../../src/interfaces/ProviderInterfaces.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/test/fork/fuzz/SwEthHandlerForkFuzz.t.sol b/test/fork/fuzz/lst/SwEthHandler.t.sol similarity index 69% rename from test/fork/fuzz/SwEthHandlerForkFuzz.t.sol rename to test/fork/fuzz/lst/SwEthHandler.t.sol index 6f8ba7d5..81b52da6 100644 --- a/test/fork/fuzz/SwEthHandlerForkFuzz.t.sol +++ b/test/fork/fuzz/lst/SwEthHandler.t.sol @@ -1,20 +1,20 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { SwEthHandler_ForkBase } from "../../fork/concrete/SwEthHandlerFork.t.sol"; +import { SwEthHandler_ForkBase } from "../../../fork/concrete/lst/SwEthHandler.t.sol"; -import { LstHandler_ForkBase } from "../../helpers/handlers/LstHandlerForkBase.sol"; +import { LstHandler_ForkBase } from "../../../helpers/handlers/LstHandlerForkBase.sol"; -import { ISwEth } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { SwellLibrary } from "../../../src/libraries/SwellLibrary.sol"; +import { ISwEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; +import { SwellLibrary } from "../../../../src/libraries/lst/SwellLibrary.sol"; import { BalancerFlashloanDirectMintHandler_FuzzTest, BalancerFlashloanDirectMintHandler_WithRateChange_FuzzTest -} from "./handlers-base/BalancerFlashloanDirectMintHandler.t.sol"; +} from "../handlers-base/BalancerFlashloanDirectMintHandler.t.sol"; import { UniswapFlashswapHandler_FuzzTest, UniswapFlashswapHandler_WithRateChange_FuzzTest -} from "./handlers-base/UniswapFlashswapHandler.t.sol"; +} from "../handlers-base/UniswapFlashswapHandler.t.sol"; using SwellLibrary for ISwEth; diff --git a/test/fork/fuzz/SwellLibrary.t.sol b/test/fork/fuzz/lst/SwellLibrary.t.sol similarity index 90% rename from test/fork/fuzz/SwellLibrary.t.sol rename to test/fork/fuzz/lst/SwellLibrary.t.sol index 81d618f7..1ed431dd 100644 --- a/test/fork/fuzz/SwellLibrary.t.sol +++ b/test/fork/fuzz/lst/SwellLibrary.t.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { SwellLibrary } from "../../../src/libraries/SwellLibrary.sol"; -import { ISwEth } from "../../../src/interfaces/ProviderInterfaces.sol"; +import { SwellLibrary } from "../../../../src/libraries/lst/SwellLibrary.sol"; +import { ISwEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/test/fork/fuzz/WstEthHandlerForkFuzz.t.sol b/test/fork/fuzz/lst/WstEthHandler.t.sol similarity index 95% rename from test/fork/fuzz/WstEthHandlerForkFuzz.t.sol rename to test/fork/fuzz/lst/WstEthHandler.t.sol index 97ad636a..d69022f6 100644 --- a/test/fork/fuzz/WstEthHandlerForkFuzz.t.sol +++ b/test/fork/fuzz/lst/WstEthHandler.t.sol @@ -1,22 +1,22 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { WstEthHandler_ForkBase } from "../../fork/concrete/WstEthHandlerFork.t.sol"; +import { WstEthHandler_ForkBase } from "../../../fork/concrete/lst/WstEthHandler.t.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import { LstHandler_ForkBase } from "../../helpers/handlers/LstHandlerForkBase.sol"; -import { WadRayMath, RAY } from "../../../src/libraries/math/WadRayMath.sol"; -import { IWstEth } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { LidoLibrary } from "../../../src/libraries/LidoLibrary.sol"; +import { LstHandler_ForkBase } from "../../../helpers/handlers/LstHandlerForkBase.sol"; +import { WadRayMath, RAY } from "../../../../src/libraries/math/WadRayMath.sol"; +import { IWstEth } from "../../../../src/interfaces/ProviderInterfaces.sol"; +import { LidoLibrary } from "../../../../src/libraries/lst/LidoLibrary.sol"; import { BalancerFlashloanDirectMintHandler_FuzzTest, BalancerFlashloanDirectMintHandler_WithRateChange_FuzzTest -} from "./handlers-base/BalancerFlashloanDirectMintHandler.t.sol"; +} from "../handlers-base/BalancerFlashloanDirectMintHandler.t.sol"; import { UniswapFlashswapHandler_FuzzTest, UniswapFlashswapHandler_WithRateChange_FuzzTest -} from "./handlers-base/UniswapFlashswapHandler.t.sol"; +} from "../handlers-base/UniswapFlashswapHandler.t.sol"; using LidoLibrary for IWstEth; diff --git a/test/helpers/handlers/LrtHandlerForkBase.sol b/test/helpers/handlers/LrtHandlerForkBase.sol index da91d681..94f8ae47 100644 --- a/test/helpers/handlers/LrtHandlerForkBase.sol +++ b/test/helpers/handlers/LrtHandlerForkBase.sol @@ -5,7 +5,7 @@ import { IonHandler_ForkBase } from "./IonHandlerForkBase.sol"; import { WSTETH_ADDRESS, REDSTONE_WEETH_ETH_PRICE_FEED, WSTETH_ADDRESS } from "../../../src/Constants.sol"; import { IonPoolSharedSetup } from "../IonPoolSharedSetup.sol"; import { WadRayMath } from "../../../src/libraries/math/WadRayMath.sol"; -import { LidoLibrary } from "../../../src/libraries/LidoLibrary.sol"; +import { LidoLibrary } from "../../../src/libraries/lst/LidoLibrary.sol"; import { IWstEth } from "../../../src/interfaces/ProviderInterfaces.sol"; using LidoLibrary for IWstEth; diff --git a/test/integration/concrete/WeEthIonPool.t.sol b/test/integration/concrete/WeEthIonPool.t.sol index dcd600c4..f99f1c66 100644 --- a/test/integration/concrete/WeEthIonPool.t.sol +++ b/test/integration/concrete/WeEthIonPool.t.sol @@ -7,11 +7,11 @@ import { WeEthIonPoolSharedSetup } from "../../helpers/weETH/WeEthIonPoolSharedS import { Whitelist } from "../../../src/Whitelist.sol"; import { WSTETH_ADDRESS, WEETH_ADDRESS, EETH_ADDRESS } from "../../../src/Constants.sol"; import { IWstEth, IWeEth } from "../../../src/interfaces/ProviderInterfaces.sol"; -import { LidoLibrary } from "../../../src/libraries/LidoLibrary.sol"; -import { EtherFiLibrary } from "../../../src/libraries/EtherFiLibrary.sol"; +import { LidoLibrary } from "../../../src/libraries/lst/LidoLibrary.sol"; +import { EtherFiLibrary } from "../../../src/libraries/lrt/EtherFiLibrary.sol"; import { SpotOracle } from "../../../src/oracles/spot/SpotOracle.sol"; -import { WeEthWstEthReserveOracle } from "../../../src/oracles/reserve/WeEthWstEthReserveOracle.sol"; -import { WeEthWstEthSpotOracle } from "../../../src/oracles/spot/WeEthWstEthSpotOracle.sol"; +import { WeEthWstEthReserveOracle } from "../../../src/oracles/reserve/lrt/WeEthWstEthReserveOracle.sol"; +import { WeEthWstEthSpotOracle } from "../../../src/oracles/spot/lrt/WeEthWstEthSpotOracle.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; diff --git a/test/unit/concrete/SwEthHandler.t.sol b/test/unit/concrete/SwEthHandler.t.sol index 86c47ba5..d9a0ef08 100644 --- a/test/unit/concrete/SwEthHandler.t.sol +++ b/test/unit/concrete/SwEthHandler.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { SwEthHandler } from "../../../src/flash/handlers/SwEthHandler.sol"; +import { SwEthHandler } from "../../../src/flash/lst/SwEthHandler.sol"; import { Whitelist } from "../../../src/Whitelist.sol"; import { IonPoolSharedSetup } from "../../helpers/IonPoolSharedSetup.sol"; diff --git a/test/unit/concrete/WstEthHandler.t.sol b/test/unit/concrete/WstEthHandler.t.sol index f8381b67..079c63cb 100644 --- a/test/unit/concrete/WstEthHandler.t.sol +++ b/test/unit/concrete/WstEthHandler.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.21; -import { WstEthHandler } from "../../../src/flash/handlers/WstEthHandler.sol"; +import { WstEthHandler } from "../../../src/flash/lst/WstEthHandler.sol"; import { Whitelist } from "../../../src/Whitelist.sol"; import { IonPoolSharedSetup } from "../../helpers/IonPoolSharedSetup.sol"; From 3aeb7de2ffdb31d13e15227129a075fc8406dd42 Mon Sep 17 00:00:00 2001 From: Hrik Bhowal Date: Thu, 7 Mar 2024 12:47:43 -0500 Subject: [PATCH 2/2] test: test leverage on live pool --- script/__TestFlashLeverage.s.sol | 48 ------------------------- test/live/TestFlashLeverage.t.sol | 59 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 48 deletions(-) delete mode 100644 script/__TestFlashLeverage.s.sol create mode 100644 test/live/TestFlashLeverage.t.sol diff --git a/script/__TestFlashLeverage.s.sol b/script/__TestFlashLeverage.s.sol deleted file mode 100644 index 55f0276d..00000000 --- a/script/__TestFlashLeverage.s.sol +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity 0.8.21; - -import { IonPool } from "../src/IonPool.sol"; -import { RsEthHandler } from "../src/flash/lrt/RsEthHandler.sol"; -import { Whitelist } from "../src/Whitelist.sol"; -import { IWstEth, IRsEth } from "../src/interfaces/ProviderInterfaces.sol"; -import { WSTETH_ADDRESS, RSETH } from "../src/Constants.sol"; -import { LidoLibrary } from "../src/libraries/lst/LidoLibrary.sol"; -import { KelpDaoLibrary } from "../src/libraries/lrt/KelpDaoLibrary.sol"; - -import { BaseScript } from "./Base.s.sol"; - -using LidoLibrary for IWstEth; -using KelpDaoLibrary for IRsEth; - -contract FlashLeverageScript is BaseScript { - string configPath = "./deployment-config/DeployedAddresses.json"; - string config = vm.readFile(configPath); - - function run() public broadcast { - IonPool pool = IonPool(vm.parseJsonAddress(config, ".ionPool")); - RsEthHandler rsEthHandler = RsEthHandler(payable(vm.parseJsonAddress(config, ".handler"))); - - pool.updateSupplyCap(1000 ether); - WSTETH_ADDRESS.depositForLst(500 ether); - WSTETH_ADDRESS.approve(address(pool), type(uint256).max); - pool.supply(address(this), WSTETH_ADDRESS.balanceOf(broadcaster), new bytes32[](0)); - - pool.addOperator(address(rsEthHandler)); - - uint256 initialDeposit = 2 ether; // in collateral terms - uint256 resultingAdditionalCollateral = 8 ether; // in collateral terms - uint256 maxResultingDebt = 15 ether; - - RSETH.approve(address(rsEthHandler), type(uint256).max); - // EETH_ADDRESS.approve(address(WEETH_ADDRESS), type(uint256).max); - RSETH.depositForLrt(initialDeposit * 2); - - rsEthHandler.flashswapAndMint( - initialDeposit, - resultingAdditionalCollateral, - maxResultingDebt, - block.timestamp + 1_000_000_000_000, - new bytes32[](0) - ); - } -} diff --git a/test/live/TestFlashLeverage.t.sol b/test/live/TestFlashLeverage.t.sol new file mode 100644 index 00000000..cf2136be --- /dev/null +++ b/test/live/TestFlashLeverage.t.sol @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.21; + +import { IonPool } from "../../src/IonPool.sol"; +import { WSTETH_ADDRESS, RSETH, WEETH_ADDRESS, EETH_ADDRESS } from "../../src/Constants.sol"; +import { LidoLibrary } from "../../src/libraries/lst/LidoLibrary.sol"; +import { EtherFiLibrary } from "../../src/libraries/lrt/EtherFiLibrary.sol"; +import { WeEthHandler } from "../../src/flash/lrt/WeEthHandler.sol"; +import { IWstEth, IWeEth } from "../../src/interfaces/ProviderInterfaces.sol"; +import { Whitelist } from "../../src/Whitelist.sol"; + +import { Test } from "forge-std/Test.sol"; + +using LidoLibrary for IWstEth; +using EtherFiLibrary for IWeEth; + +contract TestFlashLeverage is Test { + IonPool pool; + WeEthHandler weEthHandler; + Whitelist whitelist; + + uint256 initialDeposit = 4 ether; // in collateral terms + uint256 resultingAdditionalCollateral = 10 ether; // in collateral terms + uint256 maxResultingDebt = 15 ether; + + function setUp() public { + vm.createSelectFork(vm.envString("MAINNET_RPC_URL")); + pool = IonPool(0x0000000000eaEbd95dAfcA37A39fd09745739b78); + weEthHandler = WeEthHandler(payable(0xAB3c6236327FF77159B37f18EF85e8AC58034479)); + whitelist = Whitelist(0x7E317f99aA313669AaCDd8dB3927ff3aCB562dAD); + + vm.startPrank(whitelist.owner()); + whitelist.updateBorrowersRoot(0, bytes32(0)); + whitelist.updateLendersRoot(bytes32(0)); + vm.stopPrank(); + + vm.prank(pool.owner()); + pool.updateSupplyCap(1_000_000 ether); + WSTETH_ADDRESS.depositForLst(500 ether); + WSTETH_ADDRESS.approve(address(pool), type(uint256).max); + pool.supply(address(this), WSTETH_ADDRESS.balanceOf(address(this)), new bytes32[](0)); + } + + function testWeEthHandler() public { + pool.addOperator(address(weEthHandler)); + + WEETH_ADDRESS.approve(address(weEthHandler), type(uint256).max); + EETH_ADDRESS.approve(address(WEETH_ADDRESS), type(uint256).max); + WEETH_ADDRESS.depositForLrt(initialDeposit * 2); + + weEthHandler.flashswapAndMint( + initialDeposit, + resultingAdditionalCollateral, + maxResultingDebt, + block.timestamp + 1_000_000_000_000, + new bytes32[](0) + ); + } +}