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

remove Pool.active and clean up #63

Merged
merged 21 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ef91e0d
add wild() to pools and plans and allow permissionless caging
iamchrissmith Jun 6, 2022
01fc0c1
add hub tests for wild caging and fix auth
iamchrissmith Jun 6, 2022
eeef142
make wild pure
iamchrissmith Jun 6, 2022
899504e
Merge branch 'v2' into add-pause-update-active
iamchrissmith Jun 7, 2022
9b6c96e
add paused check on pools and plans to prevent any exec action
iamchrissmith Jun 7, 2022
031b7f8
add ability to pause pool and ensure exec doesn't change
iamchrissmith Jun 7, 2022
3340b57
add ability to pause plan and ensure exec doesn't change
iamchrissmith Jun 7, 2022
3a02ee1
add ability to unpause pool and resume exec
iamchrissmith Jun 7, 2022
8754cd0
add ability to unpause plan and resume exec
iamchrissmith Jun 7, 2022
284bb0e
add pause to Mom
iamchrissmith Jun 7, 2022
e3d58df
remove active from pools
iamchrissmith Jun 7, 2022
384e5f6
Merge branch 'v2' into add-pause-update-active
iamchrissmith Jun 7, 2022
4db7c45
remove pause and wild
iamchrissmith Jun 8, 2022
cf1b646
clean up variables
iamchrissmith Jun 8, 2022
b4997db
remove unneeded events
iamchrissmith Jun 8, 2022
4d654ef
remove spacing
iamchrissmith Jun 8, 2022
71597c8
Merge branch 'v2' into add-pause-update-active
iamchrissmith Jun 8, 2022
b9a3793
Merge branch 'v2' into add-pause-update-active
iamchrissmith Jun 8, 2022
35fbc1e
Merge branch 'v2' into add-pause-update-active
iamchrissmith Jun 9, 2022
d99eabc
Merge branch 'v2' into add-pause-update-active
iamchrissmith Jun 9, 2022
ae618a4
align &s
iamchrissmith Jun 9, 2022
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
5 changes: 2 additions & 3 deletions src/D3MHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ contract D3MHub {
Mode.MCD_CAGED,
currentAssets
);
} else if (ilks[ilk].tic != 0 || !_pool.active() || !ilks[ilk].plan.active()) {
} else if (ilks[ilk].tic != 0 || !ilks[ilk].plan.active()) {
// pool caged
_unwind(
ilk,
Expand Down Expand Up @@ -486,8 +486,7 @@ contract D3MHub {
ID3MPool _pool = ilks[ilk].pool;

require(vat.live() == 1, "D3MHub/no-reap-during-shutdown");
require(ilks[ilk].tic == 0, "D3MHub/d3m-not-live");
require(_pool.active(), "D3MHub/pool-not-active");
require(ilks[ilk].tic == 0, "D3MHub/pool-not-live");
require(ilks[ilk].plan.active(), "D3MHub/plan-not-active");

_pool.preDebtChange("reap");
Expand Down
68 changes: 21 additions & 47 deletions src/D3MHub.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ contract D3MHubTest is DSTest {
vat.fold(ilk, vow, int(2 * RAY));
d3mHub.exec(ilk);
}

function test_wind_limited_ilk_line() public {
d3mTestPlan.file("bar", 10);
d3mTestPlan.file("targetAssets", 50 * WAD);
Expand Down Expand Up @@ -397,22 +397,6 @@ contract D3MHubTest is DSTest {
assertTrue(d3mTestPool.postDebt());
}

function test_unwind_pool_not_active() public {
_windSystem();

// Temporarily disable the module
d3mTestPool.file("active_", false);
d3mHub.exec(ilk);

// Ensure we unwound our position
(uint256 ink, uint256 art) = vat.urns(ilk, address(d3mTestPool));
assertEq(ink, 0);
assertEq(art, 0);
// Make sure pre/post functions get called
assertTrue(d3mTestPool.preDebt());
assertTrue(d3mTestPool.postDebt());
}

function test_unwind_plan_not_active() public {
_windSystem();

Expand Down Expand Up @@ -701,19 +685,6 @@ contract D3MHubTest is DSTest {
d3mHub.reap(ilk);
}

function testFail_no_reap_pool_inactive() public {
_windSystem();
// interest is determined by the difference in gem balance to dai debt
// by giving extra gems to the Join we simulate interest
_giveTokens(TokenLike(address(testGem)), 10 * WAD);
testGem.transfer(address(d3mTestPool), 10 * WAD);

// pool inactive
d3mTestPool.file("active_", false);

d3mHub.reap(ilk);
}

function testFail_no_reap_plan_inactive() public {
_windSystem();
// interest is determined by the difference in gem balance to dai debt
Expand Down Expand Up @@ -749,7 +720,7 @@ contract D3MHubTest is DSTest {
assertEq(testGem.balanceOf(address(this)), prevBalance + 50 * WAD);
}

function test_cage_pool() public {
function test_cage_d3m_with_auth() public {
(, , uint256 tau, , uint256 tic) = d3mHub.ilks(ilk);
assertEq(tic, 0);

Expand All @@ -759,17 +730,17 @@ contract D3MHubTest is DSTest {
assertEq(tic, block.timestamp + tau);
}

function testFail_cage_pool_mcd_caged() public {
function testFail_cage_d3m_mcd_caged() public {
vat.cage();
d3mHub.cage(ilk);
}
function testFail_cage_pool_no_auth() public {

function testFail_cage_d3m_no_auth() public {
d3mHub.deny(address(this));
d3mHub.cage(ilk);
}

function testFail_cage_pool_already_caged() public {
function testFail_cage_d3m_already_caged() public {
d3mHub.cage(ilk);
d3mHub.cage(ilk);
}
Expand Down Expand Up @@ -1020,9 +991,9 @@ contract D3MHubTest is DSTest {
assertTrue(newPool.preDebt() == false);
assertTrue(newPool.postDebt() == false);

// Pool Inactive
d3mTestPool.file("active_", false);
assertTrue(d3mTestPool.active() == false);
// Plan Inactive
d3mTestPlan.file("active_", false);
assertTrue(d3mTestPlan.active() == false);

d3mHub.exec(ilk);

Expand All @@ -1037,14 +1008,17 @@ contract D3MHubTest is DSTest {
d3mTestPool.file("postDebt", false); // reset postDebt

d3mHub.file(ilk, "pool", address(newPool));
// Reactivate Plan
d3mTestPlan.file("active_", true);
assertTrue(d3mTestPlan.active());
d3mHub.exec(ilk);

// New Pool should get wound up to the original amount because plan didn't change
(npink, npart) = vat.urns(ilk, address(newPool));
assertEq(npink, 50 * WAD);
assertEq(npart, 50 * WAD);
assertTrue(newPool.preDebt() == true);
assertTrue(newPool.postDebt() == true);
assertTrue(newPool.preDebt());
assertTrue(newPool.postDebt());

(opink, opart) = vat.urns(ilk, address(d3mTestPool));
assertEq(opink, 0);
Expand Down Expand Up @@ -1141,7 +1115,7 @@ contract D3MHubTest is DSTest {

(, ID3MPlan plan, , , ) = d3mHub.ilks(ilk);
assertEq(address(plan), address(newPlan));

d3mHub.exec(ilk);

// New Plan should determine the pool position
Expand Down Expand Up @@ -1169,7 +1143,7 @@ contract D3MHubTest is DSTest {
d3mTestPool.deny(address(d3mHub));
d3mTestPool.hope(address(newHub));
d3mTestPool.nope(address(d3mHub));

// Update Permissions in Vat
vat.deny(address(d3mHub));
vat.rely(address(newHub));
Expand Down Expand Up @@ -1208,7 +1182,7 @@ contract D3MHubTest is DSTest {
d3mTestPool.deny(address(d3mHub));
d3mTestPool.hope(address(newHub));
d3mTestPool.nope(address(d3mHub));

// Update Permissions in Vat
vat.deny(address(d3mHub));
vat.rely(address(newHub));
Expand Down Expand Up @@ -1286,7 +1260,7 @@ contract D3MHubTest is DSTest {
assertEq(npart, 50 * WAD);
assertTrue(newPool.preDebt() == false);
assertTrue(newPool.postDebt() == false);

// Clean up after transition
d3mHub.cage(ilk);
d3mTestPool.deny(address(d3mHub));
Expand All @@ -1310,7 +1284,7 @@ contract D3MHubTest is DSTest {
}

function test_exec_lock_protection() public {
// Store memory slot 0x4
// Store memory slot 0x3
hevm.store(address(d3mHub), bytes32(uint256(3)), bytes32(uint256(1)));
assertEq(d3mHub.locked(), 1);

Expand All @@ -1323,7 +1297,7 @@ contract D3MHubTest is DSTest {
}

function test_reap_lock_protection() public {
// Store memory slot 0x4
// Store memory slot 0x3
hevm.store(address(d3mHub), bytes32(uint256(3)), bytes32(uint256(1)));
assertEq(d3mHub.locked(), 1);

Expand All @@ -1336,7 +1310,7 @@ contract D3MHubTest is DSTest {
}

function test_exit_lock_protection() public {
// Store memory slot 0x4
// Store memory slot 0x3
hevm.store(address(d3mHub), bytes32(uint256(3)), bytes32(uint256(1)));
assertEq(d3mHub.locked(), 1);

Expand Down
20 changes: 12 additions & 8 deletions src/plans/D3MAavePlan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract D3MAavePlan is ID3MPlan {

mapping (address => uint256) public wards;
InterestRateStrategyLike public tack;
uint256 public bar; // Target Interest Rate [ray]
uint256 public bar; // Target Interest Rate [ray]

LendingPoolLike public immutable pool;
TokenLike public immutable stableDebt;
Expand Down Expand Up @@ -113,9 +113,8 @@ contract D3MAavePlan is ID3MPlan {
}

function file(bytes32 what, uint256 data) external auth {
if (what == "bar") {
bar = data;
} else revert("D3MAavePlan/file-unrecognized-param");
if (what == "bar") bar = data;
else revert("D3MAavePlan/file-unrecognized-param");
emit File(what, data);
}

Expand Down Expand Up @@ -157,9 +156,9 @@ contract D3MAavePlan is ID3MPlan {
unchecked {
targetUtil = _rdiv(
_rmul(
targetInterestRate - base,
targetInterestRate - base,
tack.OPTIMAL_UTILIZATION_RATE()
),
),
variableRateSlope1
);
}
Expand Down Expand Up @@ -194,8 +193,13 @@ contract D3MAavePlan is ID3MPlan {

function active() public view override returns (bool) {
if (bar == 0) return false;
(,,,,,,,,,, address strategy,) = pool.getReserveData(address(dai));
return strategy == address(tack);
(,,,,,,, address adai_, address stableDebt_, address variableDebt_, address strategy,) = pool.getReserveData(address(dai));
return (
strategy == address(tack) &&
adai_ == address(adai) &&
stableDebt_ == address(stableDebt) &&
variableDebt_ == address(variableDebt)
);
}

function disable() external override {
Expand Down
4 changes: 1 addition & 3 deletions src/plans/D3MPlanBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ contract D3MPlanBase is ID3MPlan {
return true;
}

function disable() external override {

}
function disable() external override {}
}

contract D3MPlanBaseTest is DSTest {
Expand Down
1 change: 0 additions & 1 deletion src/plans/ID3MPlan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ interface ID3MPlan {
function active() external view returns (bool);

/**

@notice Disables the plan so that it would instruct the Hub to unwind
its entire position.
@dev Implementation should be permissioned.
Expand Down
4 changes: 0 additions & 4 deletions src/pools/D3MAavePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,6 @@ contract D3MAavePool is ID3MPool {
return _min(asset.balanceOf(address(adai)), assetBalance());
}

function active() external pure override returns (bool) {
return true;
}

function redeemable() external view override returns (address) {
return address(adai);
}
Expand Down
8 changes: 0 additions & 8 deletions src/pools/D3MPoolBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ contract D3MPoolBase is ID3MPool {

function maxWithdraw() external view override returns (uint256) {}

function active() external override pure returns(bool) {
return true;
}

function redeemable() external override pure returns(address) {
return address(0);
}
Expand Down Expand Up @@ -234,8 +230,4 @@ contract D3MPoolBaseTest is DSTest {
function test_implements_postDebtChange() public {
D3MPoolBase(d3mTestPool).postDebtChange("test");
}

function test_implements_active() public view {
D3MPoolBase(d3mTestPool).active();
}
}
3 changes: 0 additions & 3 deletions src/pools/ID3MPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ interface ID3MPool {
*/
function maxWithdraw() external view returns (uint256);

/// @notice Reports whether the plan is active
function active() external view returns (bool);

/// @notice returns address of redeemable tokens (if any)
function redeemable() external view returns (address);
}
16 changes: 6 additions & 10 deletions src/tests/stubs/D3MTestPlan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,19 @@ contract D3MTestPlan is ID3MPlan {
}

function file(bytes32 what, uint256 data) external auth {
if (what == "maxBar_") {
maxBar_ = data;
} else if (what == "targetAssets") {
targetAssets = data;
} else if (what == "currentRate") {
currentRate = data;
} else if (what == "bar") {
if (what == "maxBar_") maxBar_ = data;
else if (what == "targetAssets") targetAssets = data;
else if (what == "currentRate") currentRate = data;
else if (what == "bar") {
require(data <= maxBar(), "D3MTestPlan/above-max-interest");

bar = data;
} else revert("D3MTestPlan/file-unrecognized-param");
}

function file(bytes32 what, bool data) external auth {
if (what == "active_") {
active_ = data;
} else revert("D3MTestPlan/file-unrecognized-param");
if (what == "active_") active_ = data;
else revert("D3MTestPlan/file-unrecognized-param");
}

function maxBar() public view returns (uint256) {
Expand Down
12 changes: 3 additions & 9 deletions src/tests/stubs/D3MTestPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ contract D3MTestPool is ID3MPool {
mapping (address => uint256) public wards;

RewardsClaimerLike public immutable rewardsClaimer;
address public immutable share; // Token representing a share of the asset pool
TokenLike public immutable asset; // Dai
address public king; // Who gets the rewards
address public immutable share; // Token representing a share of the asset pool
TokenLike public immutable asset; // Dai
address public king; // Who gets the rewards

// test helper variables
uint256 maxDepositAmount = type(uint256).max;
bool public preDebt = false;
bool public postDebt = false;
bool public active_ = true;

// --- Events ---
event Rely(address indexed usr);
Expand Down Expand Up @@ -66,7 +65,6 @@ contract D3MTestPool is ID3MPool {
function file(bytes32 what, bool data) external auth {
if (what == "preDebt") preDebt = data;
else if (what == "postDebt") postDebt = data;
else if (what == "active_") active_ = data;
else revert("D3MTestPool/file-unrecognized-param");
}
function file(bytes32 what, uint256 data) external auth {
Expand Down Expand Up @@ -145,10 +143,6 @@ contract D3MTestPool is ID3MPool {
return shares;
}

function active() external view override returns (bool) {
return active_;
}

function redeemable() external view override returns (address) {
return address(share);
}
Expand Down