-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0fee29
commit 96d1cca
Showing
3 changed files
with
190 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
// SPDX-License-Identifier: CAL | ||
pragma solidity =0.8.25; | ||
import {console2, Test} from "forge-std/Test.sol"; | ||
|
||
import { | ||
IOrderBookV3, | ||
IO, | ||
OrderV2, | ||
OrderConfigV2, | ||
TakeOrderConfigV2, | ||
TakeOrdersConfigV2 | ||
} from "rain.orderbook.interface/interface/IOrderBookV3.sol"; | ||
import {IOrderBookV3ArbOrderTaker} from "rain.orderbook.interface/interface/IOrderBookV3ArbOrderTaker.sol"; | ||
import {IParserV1} from "rain.interpreter.interface/interface/IParserV1.sol"; | ||
import {IExpressionDeployerV3} from "rain.interpreter.interface/interface/IExpressionDeployerV3.sol"; | ||
import { EvaluableConfigV3, SignedContextV1} from "rain.interpreter.interface/interface/IInterpreterCallerV2.sol"; | ||
import {IInterpreterV2,SourceIndexV2} from "rain.interpreter.interface/interface/IInterpreterV2.sol"; | ||
import {IInterpreterStoreV2} from "rain.interpreter.interface/interface/IInterpreterStoreV2.sol"; | ||
import {StrategyTests, IRouteProcessor, LibStrategyDeployment, LibComposeOrders} from "h20.test-std/StrategyTests.sol"; | ||
import {LibEncodedDispatch} from "rain.interpreter.interface/lib/caller/LibEncodedDispatch.sol"; | ||
import {StateNamespace, LibNamespace, FullyQualifiedNamespace} from "rain.interpreter.interface/lib/ns/LibNamespace.sol"; | ||
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol"; | ||
import {SafeERC20, IERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import "h20.test-std/lib/LibProcessStream.sol"; | ||
|
||
uint256 constant VAULT_ID = uint256(keccak256("vault")); | ||
|
||
/// @dev https://basescan.org/address/0x99b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D | ||
IERC20 constant BASE_WLTH= IERC20(0x99b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D); | ||
|
||
/// @dev https://basescan.org/address/0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 | ||
IERC20 constant BASE_USDC = IERC20(0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913); | ||
|
||
function baseWlthIo() pure returns (IO memory) { | ||
return IO(address(BASE_WLTH), 18, VAULT_ID); | ||
} | ||
|
||
function baseUsdcIo() pure returns (IO memory) { | ||
return IO(address(BASE_USDC), 6, VAULT_ID); | ||
} | ||
|
||
contract WlthDcaOracleUniv3Test is StrategyTests { | ||
|
||
using SafeERC20 for IERC20; | ||
using Strings for address; | ||
|
||
uint256 constant FORK_BLOCK_NUMBER = 16825797; | ||
|
||
function selectFork() internal { | ||
uint256 fork = vm.createFork(vm.envString("RPC_URL_BASE")); | ||
vm.selectFork(fork); | ||
vm.rollFork(FORK_BLOCK_NUMBER); | ||
} | ||
|
||
function getNamespace() public view returns (FullyQualifiedNamespace) { | ||
return LibNamespace.qualifyNamespace(StateNamespace.wrap(0), address(this)); | ||
} | ||
|
||
function setUp() public { | ||
selectFork(); | ||
|
||
PARSER = IParserV1(0xF836f2746B407136a5bCB515495949B1edB75184); | ||
STORE = IInterpreterStoreV2(0x6E4b01603edBDa617002A077420E98C86595748E); | ||
INTERPRETER = IInterpreterV2(0x379b966DC6B117dD47b5Fc5308534256a4Ab1BCC); | ||
EXPRESSION_DEPLOYER = IExpressionDeployerV3(0x56394785a22b3BE25470a0e03eD9E0a939C47b9b); | ||
ORDERBOOK = IOrderBookV3(0x2AeE87D75CD000583DAEC7A28db103B1c0c18b76); | ||
ARB_INSTANCE = IOrderBookV3ArbOrderTaker(0x199b22ce0c9fD88476cCaA2d2aB253Af38BAE3Ae); | ||
ROUTE_PROCESSOR = IRouteProcessor(address(0x83eC81Ae54dD8dca17C3Dd4703141599090751D1)); | ||
EXTERNAL_EOA = address(0x654FEf5Fb8A1C91ad47Ba192F7AA81dd3C821427); | ||
APPROVED_EOA = address(0x669845c29D9B1A64FFF66a55aA13EB4adB889a88); | ||
ORDER_OWNER = address(0x19f95a84aa1C48A2c6a7B2d5de164331c86D030C); | ||
|
||
EXTERNAL_EOA = address(0x654FEf5Fb8A1C91ad47Ba192F7AA81dd3C821427); | ||
APPROVED_EOA = address(0x669845c29D9B1A64FFF66a55aA13EB4adB889a88); | ||
ORDER_OWNER = address(0x19f95a84aa1C48A2c6a7B2d5de164331c86D030C); | ||
} | ||
|
||
function testWlthDcaOracleUniV3Buy() public { | ||
// Input vaults | ||
IO[] memory inputVaults = new IO[](1); | ||
inputVaults[0] = baseWlthIo(); | ||
|
||
// Output vaults | ||
IO[] memory outputVaults = new IO[](1); | ||
outputVaults[0] = baseUsdcIo(); | ||
|
||
uint256 expectedRatio = 39.505651241666644068e18; | ||
uint256 expectedAmountOutputMax = 10.853037074011243840e18; | ||
|
||
LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment( | ||
getEncodedSellWlthRoute(address(ARB_INSTANCE)), | ||
getEncodedBuyWlthRoute(address(ARB_INSTANCE)), | ||
0, | ||
0, | ||
1e18, | ||
10000e6, | ||
expectedRatio, | ||
expectedAmountOutputMax, | ||
"strategies/wlth/wlth-dca-oracle-univ3.rain", | ||
"base-wlth-dca-univ3.buy.deviation.prod", | ||
"./lib/h20.test-std/lib/rain.orderbook", | ||
"./lib/h20.test-std/lib/rain.orderbook/Cargo.toml", | ||
inputVaults, | ||
outputVaults | ||
); | ||
|
||
// OrderBook 'takeOrder' | ||
checkStrategyCalculationsArbOrder(strategy); | ||
} | ||
|
||
function testWlthDcaOracleUniV3Sell() public { | ||
// Input vaults | ||
IO[] memory inputVaults = new IO[](1); | ||
inputVaults[0] = baseUsdcIo(); | ||
|
||
// Output vaults | ||
IO[] memory outputVaults = new IO[](1); | ||
outputVaults[0] = baseWlthIo(); | ||
|
||
uint256 expectedRatio = 0.023566726830084264e18; | ||
uint256 expectedAmountOutputMax = 2713.259268502810960000e18; | ||
|
||
LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment( | ||
getEncodedBuyWlthRoute(address(ARB_INSTANCE)), | ||
getEncodedSellWlthRoute(address(ARB_INSTANCE)), | ||
0, | ||
0, | ||
1e6, | ||
10000e18, | ||
expectedRatio, | ||
expectedAmountOutputMax, | ||
"strategies/wlth/wlth-dca-oracle-univ3.rain", | ||
"base-wlth-dca-univ3.sell.deviation.prod", | ||
"./lib/h20.test-std/lib/rain.orderbook", | ||
"./lib/h20.test-std/lib/rain.orderbook/Cargo.toml", | ||
inputVaults, | ||
outputVaults | ||
); | ||
|
||
// OrderBook 'takeOrder' | ||
checkStrategyCalculationsArbOrder(strategy); | ||
} | ||
|
||
function getEncodedBuyWlthRoute(address toAddress) internal pure returns (bytes memory) { | ||
bytes memory ROUTE_PRELUDE = | ||
hex"02833589fCD6eDb6E08f4c7C32D4f71b54bdA0291301ffff011536EE1506e24e5A36Be99C73136cD82907A902E01"; | ||
|
||
return abi.encode(bytes.concat(ROUTE_PRELUDE, abi.encodePacked(address(toAddress)))); | ||
} | ||
|
||
function getEncodedSellWlthRoute(address toAddress) internal pure returns (bytes memory) { | ||
bytes memory ROUTE_PRELUDE = | ||
hex"0299b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D01ffff011536EE1506e24e5A36Be99C73136cD82907A902E00"; | ||
|
||
return abi.encode(bytes.concat(ROUTE_PRELUDE, abi.encodePacked(address(toAddress)))); | ||
} | ||
|
||
|
||
|
||
} |