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

feat: added step to dog for LR != CR support #200

Open
wants to merge 1 commit into
base: liq-2.0
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
4 changes: 3 additions & 1 deletion src/dog.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ contract Dog {
// --- Data ---
struct Ilk {
address clip; // Liquidator
uint256 step; // Liquidation Ratio [wad]
uint256 chop; // Liquidation Penalty [wad]
uint256 hole; // Max DAI needed to cover debt+fees of active auctions per ilk [rad]
uint256 dirt; // Amt DAI needed to cover debt+fees of active auctions per ilk [rad]
Expand Down Expand Up @@ -134,6 +135,7 @@ contract Dog {
}
function file(bytes32 ilk, bytes32 what, uint256 data) external auth {
if (what == "chop") ilks[ilk].chop = data;
else if (what == "step") ilks[ilk].step = data;
else if (what == "hole") ilks[ilk].hole = data;
else revert("Dog/file-unrecognized-param");
emit FileIlkUint256(ilk, what, data);
Expand All @@ -160,7 +162,7 @@ contract Dog {
{
uint256 spot;
(,rate, spot,, dust) = vat.ilks(ilk);
require(spot > 0 && mul(ink, spot) < mul(art, rate), "Dog/not-unsafe");
require(spot > 0 && mul(ink, spot) < mul(mul(art, milk.step) / WAD, rate), "Dog/not-unsafe");

// Get the minimum value between:
// 1) Remaining space in the general Hole
Expand Down
22 changes: 12 additions & 10 deletions src/test/clip.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ contract ClipperTest is DSTest {
clip.rely(address(dog));

dog.file(ilk, "clip", address(clip));
dog.file(ilk, "step", WAD);
dog.file(ilk, "chop", 1.1 ether); // 10% chop
dog.file(ilk, "hole", rad(1000 ether));
dog.file("Hole", rad(1000 ether));
Expand Down Expand Up @@ -350,7 +351,7 @@ contract ClipperTest is DSTest {

function test_get_chop() public {
uint256 chop = dog.chop(ilk);
(, uint256 chop2,,) = dog.ilks(ilk);
(,, uint256 chop2,,) = dog.ilks(ilk);
assertEq(chop, chop2);
}

Expand Down Expand Up @@ -646,22 +647,23 @@ contract ClipperTest is DSTest {

function test_Hole_hole() public {
assertEq(dog.Dirt(), 0);
(,,, uint256 dirt) = dog.ilks(ilk);
(,,,, uint256 dirt) = dog.ilks(ilk);
assertEq(dirt, 0);

dog.bark(ilk, me, address(this));

(, uint256 tab,,,,) = clip.sales(1);

assertEq(dog.Dirt(), tab);
(,,, dirt) = dog.ilks(ilk);
(,,,, dirt) = dog.ilks(ilk);
assertEq(dirt, tab);

bytes32 ilk2 = "silver";
Clipper clip2 = new Clipper(address(vat), address(spot), address(dog), ilk2);
clip2.rely(address(dog));

dog.file(ilk2, "clip", address(clip2));
dog.file(ilk2, "step", WAD);
dog.file(ilk2, "chop", 1.1 ether);
dog.file(ilk2, "hole", rad(1000 ether));
dog.rely(address(clip2));
Expand All @@ -687,8 +689,8 @@ contract ClipperTest is DSTest {
(, uint256 tab2,,,,) = clip2.sales(1);

assertEq(dog.Dirt(), tab + tab2);
(,,, dirt) = dog.ilks(ilk);
(,,, uint256 dirt2) = dog.ilks(ilk2);
(,,,, dirt) = dog.ilks(ilk);
(,,,, uint256 dirt2) = dog.ilks(ilk2);
assertEq(dirt, tab);
assertEq(dirt2, tab2);
}
Expand All @@ -700,7 +702,7 @@ contract ClipperTest is DSTest {
assertEq(_art(ilk, me), 100 ether);

assertEq(dog.Dirt(), 0);
(,uint256 chop,, uint256 dirt) = dog.ilks(ilk);
(,,uint256 chop,, uint256 dirt) = dog.ilks(ilk);
assertEq(dirt, 0);

dog.bark(ilk, me, address(this));
Expand All @@ -716,7 +718,7 @@ contract ClipperTest is DSTest {
assertEq(_art(ilk, me), 100 ether - tab * WAD / rate / chop);

assertEq(dog.Dirt(), tab);
(,,, dirt) = dog.ilks(ilk);
(,,,, dirt) = dog.ilks(ilk);
assertEq(dirt, tab);
}

Expand All @@ -727,7 +729,7 @@ contract ClipperTest is DSTest {
assertEq(_art(ilk, me), 100 ether);

assertEq(dog.Dirt(), 0);
(,uint256 chop,, uint256 dirt) = dog.ilks(ilk);
(,,uint256 chop,, uint256 dirt) = dog.ilks(ilk);
assertEq(dirt, 0);

dog.bark(ilk, me, address(this));
Expand All @@ -743,7 +745,7 @@ contract ClipperTest is DSTest {
assertEq(_art(ilk, me), 100 ether - tab * WAD / rate / chop);

assertEq(dog.Dirt(), tab);
(,,, dirt) = dog.ilks(ilk);
(,,,, dirt) = dog.ilks(ilk);
assertEq(dirt, tab);
}

Expand Down Expand Up @@ -1250,7 +1252,7 @@ contract ClipperTest is DSTest {

// Assert that callback to clear dirt was successful.
assertEq(dog.Dirt(), 0);
(,,, uint256 dirt) = dog.ilks(ilk);
(,,,, uint256 dirt) = dog.ilks(ilk);
assertEq(dirt, 0);

// Assert transfer of gem.
Expand Down
3 changes: 2 additions & 1 deletion src/test/dog.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ contract DogTest is DSTest {
clip = new ClipperMock();
dog = new Dog(address(vat));
vat.rely(address(dog));
dog.file(ilk, "step", WAD);
dog.file(ilk, "chop", 11 * WAD / 10);
dog.file("vow", address(vow));
dog.file(ilk, "clip", address(clip));
Expand All @@ -59,7 +60,7 @@ contract DogTest is DSTest {
function isDusty() internal returns (bool dusty) {
(, uint256 rate,,, uint256 dust) = vat.ilks(ilk);
(, uint256 art) = vat.urns(ilk, usr);
(, uint256 chop,,) = dog.ilks(ilk);
(,, uint256 chop,,) = dog.ilks(ilk);
uint256 due = art * rate;
uint256 tab = due * chop / WAD;
dusty = tab > 0 && tab < dust;
Expand Down
1 change: 1 addition & 0 deletions src/test/end.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ contract EndTest is DSTest {
clip.rely(address(dog));
dog.rely(address(clip));
dog.file(name, "clip", address(clip));
dog.file(name, "step", WAD);
dog.file(name, "chop", 1.1 ether);
dog.file(name, "hole", rad(25000 ether));
dog.file("Hole", rad((25000 ether)));
Expand Down