Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable rate OnChain Tests #540

Open
wants to merge 2 commits into
base: feature/variable-rate
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions cache/solidity-files-cache.json
Original file line number Diff line number Diff line change
Expand Up @@ -5285,7 +5285,7 @@
}
},
"src/oracles/chainlink/ChainlinkMultiOracle.sol": {
"lastModificationDate": 1677499641263,
"lastModificationDate": 1678452737622,
"contentHash": "a22b18e9ca40e7135457b337d8c3fd38",
"sourceName": "src/oracles/chainlink/ChainlinkMultiOracle.sol",
"solcConfig": {
Expand Down Expand Up @@ -8614,7 +8614,7 @@
}
},
"src/test/oracles/ChainlinkMultiOracle.t.sol": {
"lastModificationDate": 1677499641253,
"lastModificationDate": 1678444665979,
"contentHash": "55fbea7071b38f2f3fa3ef4575a80a0c",
"sourceName": "src/test/oracles/ChainlinkMultiOracle.t.sol",
"solcConfig": {
Expand Down Expand Up @@ -8767,7 +8767,7 @@
}
},
"src/test/oracles/CompositeMultiOracle.t.sol": {
"lastModificationDate": 1677499641252,
"lastModificationDate": 1678444665979,
"contentHash": "18568dad409a49eb28f92db83eb4d627",
"sourceName": "src/test/oracles/CompositeMultiOracle.t.sol",
"solcConfig": {
Expand Down Expand Up @@ -8917,7 +8917,7 @@
}
},
"src/test/oracles/ConvexOracle.t.sol": {
"lastModificationDate": 1677499641252,
"lastModificationDate": 1678444665980,
"contentHash": "c513d51dd4cb2b35182e954712254e66",
"sourceName": "src/test/oracles/ConvexOracle.t.sol",
"solcConfig": {
Expand Down Expand Up @@ -9219,7 +9219,7 @@
}
},
"src/test/oracles/LidoOracle.t.sol": {
"lastModificationDate": 1677499641251,
"lastModificationDate": 1678444665980,
"contentHash": "c7d1f36325a705467a6f7e1db92e5881",
"sourceName": "src/test/oracles/LidoOracle.t.sol",
"solcConfig": {
Expand Down Expand Up @@ -10573,8 +10573,8 @@
}
},
"src/test/variable/Fixture.sol": {
"lastModificationDate": 1678446385283,
"contentHash": "fc4956ce6e38d66239547bbb17631b0f",
"lastModificationDate": 1678454873938,
"contentHash": "5b8aed38036c584b6681df1962824cf9",
"sourceName": "src/test/variable/Fixture.sol",
"solcConfig": {
"settings": {
Expand Down Expand Up @@ -10687,8 +10687,8 @@
}
},
"src/test/variable/FixtureStates.sol": {
"lastModificationDate": 1678446363485,
"contentHash": "c7ec7e0e8c8b25aaacd6eac651325e8e",
"lastModificationDate": 1678454156111,
"contentHash": "4c64fb46fb3db86f5143cee7ea92d160",
"sourceName": "src/test/variable/FixtureStates.sol",
"solcConfig": {
"settings": {
Expand Down Expand Up @@ -10842,8 +10842,8 @@
}
},
"src/test/variable/VRCauldron.t.sol": {
"lastModificationDate": 1678446537965,
"contentHash": "575777a72a96316834adcc827cdadcdd",
"lastModificationDate": 1678454824036,
"contentHash": "ba4292ec5ce982ff5c98e6a794e866d5",
"sourceName": "src/test/variable/VRCauldron.t.sol",
"solcConfig": {
"settings": {
Expand Down Expand Up @@ -10992,8 +10992,8 @@
}
},
"src/test/variable/VRLadle.t.sol": {
"lastModificationDate": 1678446550925,
"contentHash": "b32a5c3338fdab98e570a7d63456dbee",
"lastModificationDate": 1678447926085,
"contentHash": "fc74b6ea9350274fe7c8e183e65c7645",
"sourceName": "src/test/variable/VRLadle.t.sol",
"solcConfig": {
"settings": {
Expand Down Expand Up @@ -11240,8 +11240,8 @@
}
},
"src/test/variable/VYToken.t.sol": {
"lastModificationDate": 1678445284186,
"contentHash": "e4cb4fbcb2f75c31dad3aef846d887ae",
"lastModificationDate": 1678447569385,
"contentHash": "cb00187c5c2c0c5e40c53886f9c1e6a5",
"sourceName": "src/test/variable/VYToken.t.sol",
"solcConfig": {
"settings": {
Expand Down Expand Up @@ -11409,7 +11409,7 @@
}
},
"src/variable/VRCauldron.sol": {
"lastModificationDate": 1678447057859,
"lastModificationDate": 1678452731223,
"contentHash": "ba4c7748a2efd3576c60afc6ed4d6831",
"sourceName": "src/variable/VRCauldron.sol",
"solcConfig": {
Expand Down Expand Up @@ -11461,7 +11461,7 @@
}
},
"src/variable/VRLadle.sol": {
"lastModificationDate": 1678446439706,
"lastModificationDate": 1678454862108,
"contentHash": "5ba14c8e5bb475b7b7179227836f247a",
"sourceName": "src/variable/VRLadle.sol",
"solcConfig": {
Expand Down
128 changes: 77 additions & 51 deletions src/test/variable/Fixture.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ import "@yield-protocol/utils-v2/src/utils/Math.sol";
using Cast for uint256;
using Cast for uint256;
using Math for uint256;

abstract contract Fixture is Test, TestConstants, TestExtensions {
address public admin = makeAddr("admin");
address public user = makeAddr("user");
address public immutable timelock;
VRCauldron public cauldron;
VRLadle public ladle;
Witch public witch;
Expand All @@ -64,8 +66,6 @@ abstract contract Fixture is Test, TestConstants, TestExtensions {
AccumulatorMultiOracle public chiRateOracle;
ChainlinkMultiOracle public spotOracle;
ChainlinkAggregatorV3Mock public ethAggregator;
ChainlinkAggregatorV3Mock public daiAggregator;
ChainlinkAggregatorV3Mock public usdcAggregator;
ChainlinkAggregatorV3Mock public baseAggregator;

bytes12 public vaultId = 0x000000000000000000000001;
Expand All @@ -80,10 +80,21 @@ abstract contract Fixture is Test, TestConstants, TestExtensions {
uint256 public ART = WAD;
uint256 public FEE = 1000;
uint128 public unit;

address USDC_JOIN = address(0x0d9A1A773be5a83eEbda23bf98efB8585C3ae4f4);
address DAI_JOIN = address(0x4fE92119CDf873Cf8826F4E6EcfD4E578E3D44Dc);
address WETH_JOIN = address(0x3bDb887Dc46ec0E964Df89fFE2980db0121f0fD0);

constructor() {
timelock = addresses[MAINNET][TIMELOCK];
}

function setUp() public virtual {
usdc = new USDCMock();
weth = new WETH9Mock();
dai = new DAIMock();
vm.createSelectFork(MAINNET, 16668354);

usdc = USDCMock(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
weth = WETH9Mock(payable(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2));
dai = DAIMock(0x6B175474E89094C44Da98b954EedeAC495271d0F);
base = new ERC20Mock("Base", "BASE");
otherERC20 = new ERC20Mock("Other ERC20", "OTHERERC20");

Expand All @@ -94,16 +105,35 @@ abstract contract Fixture is Test, TestConstants, TestExtensions {
);
witch = new Witch(ICauldron(address(cauldron)), ILadle(address(ladle)));


restrictedERC20Mock = new RestrictedERC20Mock("Restricted", "RESTRICTED");
restrictedERC20Mock = new RestrictedERC20Mock(
"Restricted",
"RESTRICTED"
);

usdcJoin = FlashJoin(USDC_JOIN);
wethJoin = FlashJoin(WETH_JOIN);
daiJoin = FlashJoin(DAI_JOIN);

bytes4 role = 0x00000000;
vm.startPrank(timelock);
AccessControl access = AccessControl(address(usdcJoin));
access.grantRole(role, address(this));
access = AccessControl(address(wethJoin));
access.grantRole(role, address(this));
access = AccessControl(address(daiJoin));
access.grantRole(role, address(this));
vm.stopPrank();

usdcJoin = new FlashJoin(address(usdc));
wethJoin = new FlashJoin(address(weth));
daiJoin = new FlashJoin(address(dai));
baseJoin = new FlashJoin(address(base));

setUpOracles();
vyToken = new VYToken(baseId, IOracle(address(chiRateOracle)), IJoin(baseJoin),base.name(), base.symbol());
vyToken = new VYToken(
daiId,
IOracle(address(chiRateOracle)),
IJoin(daiJoin),
dai.name(),
dai.symbol()
);
// Setting permissions
ladleGovAuth();
cauldronGovAuth(address(ladle));
Expand All @@ -115,12 +145,16 @@ abstract contract Fixture is Test, TestConstants, TestExtensions {
bytes4[] memory roles = new bytes4[](2);
roles[0] = Join.join.selector;
roles[1] = Join.exit.selector;
baseJoin.grantRoles(roles, address(vyToken));
vm.prank(timelock);
daiJoin.grantRoles(roles, address(vyToken));
}

function setUpOracles() internal {
chiRateOracle = new AccumulatorMultiOracle();
chiRateOracle = AccumulatorMultiOracle(
0x95750d6F5fba4ed1cc4Dc42D2c01dFD3DB9a11eC
);

vm.startPrank(timelock);
chiRateOracle.grantRole(
AccumulatorMultiOracle.setSource.selector,
address(this)
Expand All @@ -129,48 +163,34 @@ abstract contract Fixture is Test, TestConstants, TestExtensions {
AccumulatorMultiOracle.updatePerSecondRate.selector,
address(this)
);
vm.stopPrank();
chiRateOracle.setSource(baseId, RATE, WAD, WAD * 2);
chiRateOracle.setSource(baseId, CHI, WAD, WAD * 2);

ethAggregator = new ChainlinkAggregatorV3Mock();
ethAggregator.set(1e18 / 2);

daiAggregator = new ChainlinkAggregatorV3Mock();
daiAggregator.set(1e18 / 2);

usdcAggregator = new ChainlinkAggregatorV3Mock();
usdcAggregator.set(1e18 / 2);

baseAggregator = new ChainlinkAggregatorV3Mock();
baseAggregator.set(1e18 / 2);

spotOracle = new ChainlinkMultiOracle();
spotOracle = ChainlinkMultiOracle(
0xcDCe5C87f691058B61f3A65913f1a3cBCbAd9F52
);

bytes4 role = 0x00000000;
AccessControl access = AccessControl(address(spotOracle));
vm.prank(timelock);
spotOracle.grantRole(
ChainlinkMultiOracle.setSource.selector,
address(this)
);

spotOracle.setSource(
ETH,
IERC20Metadata(address(weth)),
usdcId,
IERC20Metadata(address(usdc)),
address(usdcAggregator)
);
spotOracle.setSource(
ETH,
IERC20Metadata(address(weth)),
baseId,
IERC20Metadata(address(base)),
address(ethAggregator)
);
spotOracle.setSource(
ETH,
IERC20Metadata(address(weth)),
daiId,
IERC20Metadata(address(dai)),
address(daiAggregator)
);
}

// ----------------- Permissions ----------------- //
Expand Down Expand Up @@ -225,11 +245,15 @@ abstract contract Fixture is Test, TestConstants, TestExtensions {
address chirateoracle,
uint8 salt
) internal {

cauldron.setRateOracle(assetId, IOracle(chirateoracle));
cauldron.addBase(assetId);

cauldron.setSpotOracle(assetId, assetId, IOracle(chirateoracle), 1000000);
cauldron.setSpotOracle(
assetId,
assetId,
IOracle(chirateoracle),
1000000
);
bytes6[] memory ilk = new bytes6[](1);
ilk[0] = assetId;
cauldron.addIlks(assetId, ilk);
Expand All @@ -240,31 +264,33 @@ abstract contract Fixture is Test, TestConstants, TestExtensions {
uint24(1e6),
18
);
(bytes12 vaultId_,) = ladle.build(assetId, assetId, salt);
// cauldron.build(address(this), vaultId_, assetId, assetId);
IERC20(assetAddress).approve(address(join),INK * 10);
(bytes12 vaultId_, ) = ladle.build(assetId, assetId, salt);

IERC20(assetAddress).approve(address(join), INK * 10);
deal(assetAddress, address(this), INK * 10);
ladle.pour(vaultId_, address(this), (INK * 10).i128(), 0);
}

function getAbove(int128 ink,int128 art, bytes12 vault) internal returns(bool){
function getAbove(
int128 ink,
int128 art,
bytes12 vault
) internal returns (bool) {
(, bytes6 baseId, bytes6 ilkId) = cauldron.vaults(vault);

(IOracle oracle, uint32 ratio1) = cauldron.spotOracles(baseId, ilkId);
uint256 ratio = uint256(ratio1) * 1e12; // Normalized to 18 decimals
(uint256 inkValue, ) = oracle.get(
ilkId,
baseId,
uint256(int(ink))
); // ink * spot
(uint256 inkValue, ) = oracle.get(ilkId, baseId, uint256(int(ink))); // ink * spot
uint256 baseValue = cauldron.debtToBase(baseId, uint128(art));
return inkValue.i256() - baseValue.wmul(ratio).i256() >=0;
return inkValue.i256() - baseValue.wmul(ratio).i256() >= 0;
}

function giveMeDustAndLine(bytes12 vault) internal returns (uint128 dust, uint128 line) {
function giveMeDustAndLine(
bytes12 vault
) internal returns (uint128 dust, uint128 line) {
(, bytes6 baseId, bytes6 ilkId) = cauldron.vaults(vault);
(uint96 max, uint24 min, uint8 dec,) = cauldron.debt(baseId,ilkId);
dust = min * uint128(10)**dec;
line = max * uint128(10)**dec;
(uint96 max, uint24 min, uint8 dec, ) = cauldron.debt(baseId, ilkId);
dust = min * uint128(10) ** dec;
line = max * uint128(10) ** dec;
}
}
Loading