-
Notifications
You must be signed in to change notification settings - Fork 413
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
basic rate-limited hole #218
Draft
kmbarry1
wants to merge
1
commit into
liq-2.0
Choose a base branch
from
decaying-dirt
base: liq-2.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,11 @@ contract Dog { | |
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] | ||
uint256 trid; // Amt of dirt dug by auctions. [rad] | ||
// Packed in to a single slot to minimze gas costs. | ||
uint224 clod; // Amount of dirt to remove per time quantum [rad] | ||
uint32 qntm; // Time between removal of clods [seconds] | ||
uint256 last; // Timstamp of most recent dirt reduction [Unix epoch] | ||
} | ||
|
||
VatLike immutable public vat; // CDP Engine | ||
|
@@ -112,6 +117,10 @@ contract Dog { | |
function min(uint256 x, uint256 y) internal pure returns (uint256 z) { | ||
z = x <= y ? x : y; | ||
} | ||
function min(uint256 x, uint256 y, uint256 z) internal pure returns (uint256 w) { | ||
w = x <= y ? x : y; | ||
if (z < w) w = z; | ||
} | ||
function add(uint256 x, uint256 y) internal pure returns (uint256 z) { | ||
require((z = x + y) >= x); | ||
} | ||
|
@@ -195,15 +204,36 @@ contract Dog { | |
uint256 rate; | ||
uint256 dust; | ||
{ | ||
uint256 spot; | ||
(,rate, spot,, dust) = vat.ilks(ilk); | ||
require(spot > 0 && mul(ink, spot) < mul(art, rate), "Dog/not-unsafe"); | ||
{ | ||
uint256 spot; | ||
(,rate, spot,, dust) = vat.ilks(ilk); | ||
require(spot > 0 && mul(ink, spot) < mul(art, rate), "Dog/not-unsafe"); | ||
} | ||
|
||
uint256 _Dirt = Dirt; | ||
{ | ||
// Risk of overflow should be extremely small, even if milk.last = 0; | ||
// can anyway be made less likely to overflow with a little more work. | ||
uint256 pile = mul(sub(block.timestamp, milk.last) / milk.qntm, milk.clod); | ||
pile = min(milk.dirt, milk.trid, pile); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. given |
||
if (pile > 0) { | ||
milk.trid = sub(milk.trid, pile); | ||
milk.dirt = sub(milk.dirt, pile); // In principle safe if trid <= dirt can be formally verified. | ||
_Dirt = sub(_Dirt, pile); // In principle safe is dirt <= Dirt can be formally verified. | ||
} | ||
} | ||
|
||
// Get the minimum value between: | ||
// 1) Remaining space in the general Hole | ||
// 2) Remaining space in the collateral hole | ||
require(Hole > Dirt && milk.hole > milk.dirt, "Dog/liquidation-limit-hit"); | ||
uint256 room = min(Hole - Dirt, milk.hole - milk.dirt); | ||
require(Hole > _Dirt && milk.hole > milk.dirt, "Dog/liquidation-limit-hit"); | ||
uint256 room = min(Hole - _Dirt, milk.hole - milk.dirt); | ||
|
||
// Commit trid, dirt, Dirt, and last updates to storage. | ||
ilks[ilk].trid = milk.trid; | ||
ilks[ilk].dirt = milk.dirt; | ||
Dirt = _Dirt; | ||
ilks[ilk].last = block.timestamp; | ||
|
||
// uint256.max()/(RAD*WAD) = 115,792,089,237,316 | ||
dart = min(art, mul(room, WAD) / rate / milk.chop); | ||
|
@@ -256,8 +286,7 @@ contract Dog { | |
} | ||
|
||
function digs(bytes32 ilk, uint256 rad) external auth { | ||
Dirt = sub(Dirt, rad); | ||
ilks[ilk].dirt = sub(ilks[ilk].dirt, rad); | ||
ilks[ilk].trid = add(ilks[ilk].trid, rad); | ||
emit Digs(ilk, rad); | ||
} | ||
|
||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about removing this and setting
clod
in a per-second basis to save some gas?