-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: optimize script, reset fork state at each iteration, support sha…
…ngai for morpho tranches
- Loading branch information
Showing
2 changed files
with
25 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,51 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import "forge-std/console.sol"; | ||
import {Script} from "forge-std/Script.sol"; | ||
import {IIdleToken} from "../src/IIdleToken.sol"; | ||
|
||
contract SimulateAllocations is Script { | ||
address public constant REBALANCER = 0xB3C8e5534F0063545CBbb7Ce86854Bf42dB8872B; | ||
address public constant IDLE_USDC = 0x5274891bEC421B39D23760c04A6755eCB444797C; | ||
address public constant IDLE_DAI = 0x3fE7940616e5Bc47b0775a0dccf6237893353bB4; | ||
address public constant IDLE_USDT = 0xF34842d05A1c888Ca02769A633DF37177415C2f8; | ||
// @notice run with | ||
// forge script ./script/SimulateAllocations.s.sol:SimulateAllocations --fork-url $TENDERLY_RPC_URL_2 -v --sig "testIdleDAI(uint256[][])" "[[100000,0,0],[0,100000,0]]" | ||
// forge script ./script/SimulateAllocations.s.sol:SimulateAllocations -v --sig "testIdleDAI(uint256,uint256[][])" "[[100000,0,0],[0,100000,0]]" | ||
function testNextRates( | ||
uint256 blockNumber, | ||
address _idleToken, | ||
uint256[][] memory allocations | ||
) public returns (uint256[] memory aprs) { | ||
aprs = new uint256[](allocations.length); | ||
for (uint256 i = 0; i < allocations.length; i++) { | ||
// logArray("allocations", allocations[i]); | ||
) internal returns (uint256[] memory aprs) { | ||
uint256 len = allocations.length; | ||
aprs = new uint256[](len); | ||
for (uint256 i = 0; i < len;) { | ||
// we need to reset the forked state after each rebalance | ||
vm.createSelectFork("mainnet", blockNumber); | ||
aprs[i] = getAprForAllocations(_idleToken, allocations[i]); | ||
// console.log("apr", aprs[i]); | ||
// console.log('---'); | ||
unchecked { | ||
++i; | ||
} | ||
} | ||
} | ||
|
||
function getAprForAllocations( | ||
address _idleToken, | ||
uint256[] memory allocations | ||
) public returns (uint256) { | ||
) internal returns (uint256) { | ||
IIdleToken it = IIdleToken(_idleToken); | ||
|
||
vm.prank(REBALANCER); | ||
it.setAllocations(allocations); | ||
it.rebalance(); | ||
return it.getAvgAPR(); | ||
} | ||
|
||
function testIdleUSDC(uint256[][] memory allocations) public returns (uint256[] memory aprs) { | ||
return testNextRates(0x5274891bEC421B39D23760c04A6755eCB444797C, allocations); | ||
} | ||
function testIdleDAI(uint256[][] memory allocations) public returns (uint256[] memory aprs) { | ||
return testNextRates(0x3fE7940616e5Bc47b0775a0dccf6237893353bB4, allocations); | ||
function testIdleUSDC(uint256 blockNumber, uint256[][] memory allocations) external returns (uint256[] memory) { | ||
return testNextRates(blockNumber, IDLE_USDC, allocations); | ||
} | ||
function testIdleUSDT(uint256[][] memory allocations) public returns (uint256[] memory aprs) { | ||
return testNextRates(0xF34842d05A1c888Ca02769A633DF37177415C2f8, allocations); | ||
function testIdleDAI(uint256 blockNumber, uint256[][] memory allocations) external returns (uint256[] memory) { | ||
return testNextRates(blockNumber, IDLE_DAI, allocations); | ||
} | ||
|
||
function logArray(string memory label, uint256[] memory arr) internal view { | ||
for (uint256 i = 0; i < arr.length; i++) { | ||
console.log(label, i, arr[i]); | ||
} | ||
function testIdleUSDT(uint256 blockNumber, uint256[][] memory allocations) external returns (uint256[] memory) { | ||
return testNextRates(blockNumber, IDLE_USDT, allocations); | ||
} | ||
} |