Skip to content
Permalink
master
Switch branches/tags
Go to file
@gbalabasquer
Latest commit c8d4c80 Apr 2, 2021 History
* Initial commit

* dapp init DutchOven

* dapp install ds-test

* paste in code from gist

* make it build

* tweak README

* add license blurb

* First draft for flash loan + removing loaf if lot is 0 + minor changes (#1)

* cmooney-20200725: various bug fixes

* done TODO checks and fixed trailing whitespace

* ONE to RAY, removed slices, bakes public

* chore: add TODO for max/min/pay variables

* SC-4072: limit amount of Dai out for liquidation (#5)

* SC-4072: limit amount of Dai out for liquidation

* remove changes for another PR

* added BLN

* fix comment

* change MILLION to MIl

* fixed up the formula

* fixed bug in MIL va. MLN

* forgot rdiv()

* missing closing )

* add comments on types

* typo, needed param to be data

* fix: update dog to fix stack to deep, compiles

* feat: update dog to use LIQ-1.2 logic

* fix: update comments, remove dunk, change bone to digs

* fix: gas optimize dink > 0 require

* fix: update comments, add spot to brace block, add cost var

* fix: change cost to due

* fix: formatting

Co-authored-by: Lucas Manuel <lucas@makerdao.com>

* fix dust check

* feat: Add Auction Reset Functionality (SC-4635) (#7)

* feat: add auction reset functionality

* fix: add storage vars, fix compilation issues

* feat: add require to warm, change to external

* fix: update comments

* fix: use safe sub, add dead auction check in warm and take

* Price decrease function interface and sample implementations (#8)

* define price decrease function interface and some trial implementations

* commit sample price decrease functions

* dapp install https://github.com/makerdao/dss.git

* feat: add testing for linear/exp price dec functions

* feat: add unit tests to stairstep, linear price decrease functions

* fix: add comments about precision

* fix: update exp test tolerance to 1e-22

* feat: tests working consistently with precision tolerance

* fix: fix wrong comments

* dapp uninstall dss

* fix: update variables, comments

Co-authored-by: Lucas Manuel <lucas@makerdao.com>

* rely on oven in Dog.file (#11)

* rename files (#13)

* Add on-chain tracking of live auctions (#3)

* Add on-chain tracking of live auctions

* rename last to move for clarity

* Add splice and count funtions for array management

* Fix index shifting

* Change _stopBaking to _remove

* Clean up and fixes

* remove list(uint256,uint256)(uint256[]) and replace with getId(uint256)(uint256)

* Replace .length-- with .pop() for forward compatibility

* Remove comment

* fix: update memes, comments

Co-authored-by: Lucas <lucas@makerdao.com>

* feat: Add Unit Testing (SC-4636) (#9)

* feat: start bake test

* dapp install ds-value

* feat: add take tests for over/under/at tab

* feat: add take test for multiple bids, tests pass

* fix: delete notes file

* fix: remove empty lib/dss

* dapp install dss

* feat: add more testing, setup

* feat: all tests pass except exp decrease

* fix: fix exp decrease step and cut values

* fix: remove rpow, change max/pay to pay/val, update dirt require

* Fix import file and rename uint to uin256

* fix: update room require

* fix: update val to price

* fix: remove vat.flux(), grab straight to oven

* fix: remove rely/deny/hope/nope from oven file in dog

* fix: update imports

* fix: update dog.digs() comment

* fix: update vat helpers, hevm.warping, address(this)

* fix: use defined CHEAT_CODE

* feat: add pos to testing

* fix: remove unused MLN, BLN vars in test

* uint to uint256

* Compile with solc 0.5 and 0.6

Co-authored-by: Gonzalo Balabasquer <gbalabasquer@gmail.com>

* re-meme and minor cleanup (#15)

* dapp uninstall ds-test

* dapp uninstall ds-value

* dapp uninstall dss

* Remove stuff that will not be transferred

* Minor changes to make clipper tests to work

* Preliminary Circuit Breaker

Added logic to `stop` and `start` the clipper. All major functions are frozen when `stopped == true`.

* use current price, not bidder maximum

* hole per ilk (#141)

* Bit simpler tests

* Implement hole per collateral

* Fixing minor things

* fix: update hole comment

Co-authored-by: Lucas <lucas@makerdao.com>

* Clipper cleanup (#146)

* improve take arg comments

* remove comment about returning collateral incrementally

* rename warm to redo

* rename resetting event

* add Take event

* fix: format Take event, comments

Co-authored-by: Lucas <lucas@makerdao.com>

* feat: Add Auction Reset Tests (SC-6413) (#148)

* feat: add auction reset testing, tests pass

* fix: move repeated setup code to function

* feat: add try_redo() to clip tests

* fix: update to camelcase, fix comment

* Add license identifier to clip.sol

* change to levels

* Revert "Merge branch 'SC-4636' into liq-2.0"

This reverts commit 1906a89, reversing
changes made to 12d3254.

* Add license identifier to dog.sol

* Add tests

* No breaker for yank

* remove yank breaker tests

* Add tests

* No breaker for yank

* remove yank breaker tests

* fixing rebase issues

* remove `which`

* fix: read dust from vat (#151)

* feat: add chop getter API

* feat: Add Dusty `bite` Check (SC-6351) (#154)

* feat: add dusty bite check

* fix: use rate in dust revert calc

* feat: add rate to dusty check test

* fix: remove math import

* fix: update comments

* fix: get rid of jug

* feat: Add LibNote events to dog.sol, clip.sol (SC-4645) (#156)

* feat: add LibNote to dog, clip

* feat: index ids, add top to Kick and Redo, add max/price/owe to Take

* fix: remove note from functions with custom events in dog and clip

* minor gas optimizations in Clipper (#152)

* minor gas optimizations in Clipper

* fix: add dust call back, resolve conflicts

Co-authored-by: Lucas <lucas@makerdao.com>

* feat: Use custom events (#157)

* feat: add custom events across functions in dog and clip

* fix: update public to external for rely/deny in clip

* feat: update File events to differentiate types

* fix: add rely events to constructors, index id in Bark

* fix: change tab to due in Bark event

* feat: Add Keeper Liquidation Incentive (SC-6597) (#153)

* feat: add keeper liquidation incentive and testing, tests pass

* fix: use ali to bark()

* feat: add tip and chip as per ilk params for incentives

* fix: fix test failures from rebase

* fix: update wmul

* feat: update tests to assert bob balance

* fix: update comments

* feat: add custom events for rely/deny in abaci.sol (#163)

* change price API to accept seconds elapsed since auction start (#162)

* change price API to accept seconds elapsed since auction start

* reinstate 0.5.12 compatibility

* fix: add Rely event to abaci constructors

* fix: update liq incentive to use due (#164)

* feat: Upgrade dog, clip to 0.6.7, Update CI (SC-7268) (#165)

* feat: upgrade dog, clip to 0.6.7, update CI

* fix: format immutable vars, use interface in abaci.sol

* fix: update chip comment (#166)

* feat: End Integration and `yank()` (SC-6352 + SC-6353) (#161)

* draft, dog is in end w/ cat, and auction cancellation

* committing from laptop so i can pull to desktop

* committing latest changes to share

* fix: fix interace and formatting

* feat: add tests for yank and end integration

feix: formatting

* fix: use _remove in yank, remove vat.hope() in halt()

* fix: update halt to skip

* fix: update tests to use real rate, remove unnecessary testing

* fix: use vat.fold in snip test for rate

* feat: add clipper assertions from yank call

* fix: update scope of tab and lot

Co-authored-by: wilbarnes <wbarnesf@gmail.com>

* separate price decrease function tests into their own file (#168)

* feat: Add `needsRedo` Function (SC-7445) (#169)

* feat: add view function for auction reset

* feat: test for both tail and cusp

* feat: add ripe function

* fix: update ripe to done

* fix: remove sale.tab check from done function

* fix: update return bool

* feat: minor gas optimization for dink calculation (#167)

* fix: Input and state validation (#170)

* add input validation to Clipper.kick w/tests

* regularize checks for non-running auctions

* more tests

* Slither findings (#172)

* make public funcs external in Dog

* simplify cut param of StairstepExponentialDecrease

* fix revert message in StairstepExponentialDecrease

* gas optimization and test for Clipper.yank (#175)

* Compile with solc 0.6.11

* Make LinearDecrease.tau public

* fix: whitespace and BIL (#178)

* LIQ-2.0 20210114 updates (#181)

* some small changes and TODO notes

* verbose testing

* Add id to yank

* rm max TODO

Co-authored-by: Brian McMichael <brian@brianmcmichael.com>

* Add extra function to pay rewards to external address (#180)

* Add remaining art to dart to prevent unliquidatable vaults (#179)

* Add remaining art to dart to prevent unliquidatable vaults

* rm extra require

* Reuse mart

* Simplify dust check

* Modify unit test in order to work with the dust behaviour change

* rename test for clarity

* Add test TODO

Co-authored-by: Gonzalo Balabasquer <gbalabasquer@gmail.com>

* Liq 2.0 gas improvements (#184)

* Optimize gas usage in some functions

* Optimize take function and change done to status (which returns also the price)

* Fix require message

* Fix in needsRedo

* now => block.timestamp

* Add comment

* Use id as in other functions

* Fix shadow variable warning

* Add missing SPDX License Identifier for some files

* Liq 2.0: add tests for external calls (#185)

* tests for external calls

* add test for reentrancy

* test redo reentrancy

* more realistic flashsale test

* avoid third-party names

* Prevent take impersonation. (#189)

Co-authored-by: Emilio Silva Schlenker <e18r@disroot.org>

* Instead of ending auction if tab < dust, recalculate amounts (#190)

* Instead of ending auction if tab < dust, recalculate amounts

* Instead of ending auction if tab < dust, recalculate amounts

* Some changes

* Avoid if block if tab == owe

Co-authored-by: Emilio Silva Schlenker <e18r@disroot.org>
Co-authored-by: Brian McMichael <brian@brianmcmichael.com>

* fix: move incentive to kick() in redo() (SC-8390) (#188)

* fix: move incentive to kick() in redo() (SC-8390)

* removed comment

* prevent vat.suck() and move SLOAD

* pedantic security

* adding TODO comments

* LIQ-2.0: dusty test cases around dog.bark() (#186)

* create test file for dog

* dog set up

* add isDusty() function and a few tests

- test_bark_basic()
- testFail_bark_not_unsafe()
- test_bark_unliquidatable_vault()
- test_bark_dust_over_ilk_hole()
- test_bark_dust_over_Hole()
- test_bark_exactly_dust_over_Hole()

* update code to recent changes

* add some tests

- test_bark_over_ilk_hole
- test_bark_over_Hole
- test_bark_dust_under_ilk_hole
- test_bark_dust_under_Hole

* remove duplicate lines

* Redo some tests

Co-authored-by: Gonzalo Balabasquer <gbalabasquer@gmail.com>

* Add lock modifier to redo just as extra safety measure (#192)

* Change needsRedo function to getStatus which also includes the price (#193)

* Change needsRedo function to getStatus which also includes the price

* Fix comment

* Clean up warnings (#195)

* Make dog immutable and spotter manageable + check dog is not used as who in flash loan call

* Not paying incentive in redo if the auction is dusty

* Make chip and tip public + more tests (#196)

* Test for not partial purchase when tab == dust

* Make chip and tip public + adding a test to check redo incentives logic

* Addressing comments

* Fix spacing

* Avoid extra SLOAD when using chip and tip (#2)

* In case Hole < Dirt or milk.hole < milk.dirt also show revert message

* Save SLOAD in kick

* Save SLOAD in kick

* move top

* Clearer parameter name

* Yank param uint256

* Tweak breaker docs

* Custom events + int/uint with 256 + now -> block.timestamp

* Custom events + int/uint with 256 + now -> block.timestamp

* Add indexed to usr in Skip and Snip

* Move math constant to the top

* Rename all File events to just plain File name

* getPrice function

This function:

* avoids replicated code
* avoids stack-too-deep brackets

* Fix comment take param

* Add snip to End code documentation

* Add snip to End code documentation

* Text changes

* Liq 2.0 formulas

* Add formulas for `take`

* add brief `top` formula for kick and redo

* formulas for `bark`

* made formulas for bark clearer

* general equation for bark

* added the case when `dart` creates a dusty vault

* corrected typos

* adding formulas for abaci linear and exponential decrease for price

* Updating explanation of cut

* New formulas for bark and take (#199)

* New formulas for bark

* New formulas for take

* Fix bark formula

* Format some text

* Minor fixes

Co-authored-by: Emilio Silva Schlenker <e18r@disroot.org>
Co-authored-by: tannr <tannr@makerdao.com>

* Optimize deletion: don't shift if element is last

* Optimize deletion: don't shift if element is last

* Add test of element removal

* Add more assertions and a test of out-of-range failure

* document test

* unused var

* dig entire tab when full lot is purchased

* Address PwC finding 6.6

* revamp dog partial liquidation logic

* add tests for not creating dusty auctions

* Update src/test/dog.t.sol

Co-authored-by: Gonzalo Balabasquer <gbalabasquer@gmail.com>

* Update src/test/dog.t.sol

Co-authored-by: Gonzalo Balabasquer <gbalabasquer@gmail.com>

* fix try_bark

* improve clarity of dusty vault & dusty room test

Co-authored-by: Gonzalo Balabasquer <gbalabasquer@gmail.com>

* Add lock modifier to every auth function + make SetBreaker part of th…

* Add lock modifier to every auth function + make SetBreaker part of the file function

* Update src/clip.sol

Co-authored-by: Kurt Barry <kurt@makerdao.com>

Co-authored-by: Kurt Barry <kurt@makerdao.com>

* Make dog can be changed on the clipper

* Save extra SLOAD calling kicks

* Addp kpr to Kick and Redo events

* Addp kpr to Kick and Redo events

* Log amount is being paid to kpr

* Rename kprAmt to coin

* Use one storage slot for chip and tip

* Use one storage slot for chip and tip

* Fix for Kurt and Brian

* Remove LibNote in order to be able to compile with solc 0.6 optimized

* Remove LibNote in order to be able to compile with solc 0.6 optimized

* Add runs to the Makefile

* Require top > 0 for kicking and resetting (#205)

* Don't set unstable default values in stairstep constructor (#204)

* Update to 0.6.12 (#206)

* changing wards uint to uint256

* Remove list(), use active() (#207)

* validation for chop (#209)

* Fix state mutability warning in one test contract (#210)

* Add list(), remove getId() (#212)

* add continuous exponential decrease (#211)

* add continuous exponential decrease

* Update src/test/abaci.t.sol

Co-authored-by: Gonzalo Balabasquer <gbalabasquer@gmail.com>

* harmonize comments

Co-authored-by: Gonzalo Balabasquer <gbalabasquer@gmail.com>

* Gas Optimization: Cache the dust value and allow public modification. (#214)

* More efficient lock in case tx reverts or if in future there are not … (#213)

* More efficient lock in case tx reverts or if in future there are not refunds

* Fix spacing

Co-authored-by: Brian McMichael <brian@brianmcmichael.com>

* validate Clipper ilk when filing in Dog (#216)

* Revert "More efficient lock in case tx reverts or if in future there are not … (#213)" (#217)

This reverts commit 628d6f9.

* Return lot size with getStatus (#215)

* Return lot size with getStatus

* Add tab to getStatus

* Add a breaker level that prevents kick and redo but not take (#220)

* add a breaker level to disable kick and redo but not take

* test re-enabling taking

Co-authored-by: Gonzalo Balabasquer <gbalabasquer@gmail.com>

* fix tests

* fix tests post-rebase

Co-authored-by: Gonzalo Balabasquer <gbalabasquer@gmail.com>

* Dog and Clipper comment updates (#221)

* update Dog comment

* typos and phrasing

* improve kick param comments

* change kpr comments for kick and redo

* rename getPrice() to getFeedPrice() and price to feedPrice (#224)

* rename getPrice to getFeedPrice

Note that this is inconsistent with daiwanese practices

* rename the return value of getFeedPrice()

* gas tests and don't use optimizations (#226)

* gas tests and don't use optimizations

* update shell.nix to not compile w/optimizations

* properly account for chop in dust checks in the Clipper (#222)

* properly account for chop in dust checks in the Clipper

* cached chost, uniform checks, tests

* update take comment

* Cache chost

* Remove unused variable

* Change _ position

* don't set upchost in constructor

* cache ilk, fix comment

* actually don't cache, ilk is immutable

* remove underscore

* remove extra comma

Co-authored-by: Gonzalo Balabasquer <gbalabasquer@gmail.com>

* Rename abaci file event (#229)

* remove extra newline

Co-authored-by: Kurt Barry <kurt.m.barry@gmail.com>
Co-authored-by: Christopher Mooney <chris@dod.net>
Co-authored-by: Lucas Manuel <lucas@makerdao.com>
Co-authored-by: Kurt Barry <kurt@makerdao.com>
Co-authored-by: Brian L. McMichael <brian@brianmcmichael.com>
Co-authored-by: andy8052 <andychorlian@gmail.com>
Co-authored-by: wilbarnes <wbarnesf@gmail.com>
Co-authored-by: Emilio Silva Schlenker <e18r@disroot.org>
Co-authored-by: tannr <tannr@makerdao.com>
10 contributors

Users who have contributed to this file

Loading
@gbalabasquer @MrChico @rainbreak @godsflaw @brianmcmichael @kmbarry1 @wilbarnes @k06a @e18r @andy8052
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2017, 2018, 2019 dbrock, rain, mrchico
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pragma solidity >=0.5.12;
// FIXME: This contract was altered compared to the production version.
// It doesn't use LibNote anymore.
// New deployments of this contract will need to include custom events (TO DO).
contract Dai {
// --- Auth ---
mapping (address => uint) public wards;
function rely(address guy) external auth { wards[guy] = 1; }
function deny(address guy) external auth { wards[guy] = 0; }
modifier auth {
require(wards[msg.sender] == 1, "Dai/not-authorized");
_;
}
// --- ERC20 Data ---
string public constant name = "Dai Stablecoin";
string public constant symbol = "DAI";
string public constant version = "1";
uint8 public constant decimals = 18;
uint256 public totalSupply;
mapping (address => uint) public balanceOf;
mapping (address => mapping (address => uint)) public allowance;
mapping (address => uint) public nonces;
event Approval(address indexed src, address indexed guy, uint wad);
event Transfer(address indexed src, address indexed dst, uint wad);
// --- Math ---
function add(uint x, uint y) internal pure returns (uint z) {
require((z = x + y) >= x);
}
function sub(uint x, uint y) internal pure returns (uint z) {
require((z = x - y) <= x);
}
// --- EIP712 niceties ---
bytes32 public DOMAIN_SEPARATOR;
// bytes32 public constant PERMIT_TYPEHASH = keccak256("Permit(address holder,address spender,uint256 nonce,uint256 expiry,bool allowed)");
bytes32 public constant PERMIT_TYPEHASH = 0xea2aa0a1be11a07ed86d755c93467f4f82362b452371d1ba94d1715123511acb;
constructor(uint256 chainId_) public {
wards[msg.sender] = 1;
DOMAIN_SEPARATOR = keccak256(abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256(bytes(version)),
chainId_,
address(this)
));
}
// --- Token ---
function transfer(address dst, uint wad) external returns (bool) {
return transferFrom(msg.sender, dst, wad);
}
function transferFrom(address src, address dst, uint wad)
public returns (bool)
{
require(balanceOf[src] >= wad, "Dai/insufficient-balance");
if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) {
require(allowance[src][msg.sender] >= wad, "Dai/insufficient-allowance");
allowance[src][msg.sender] = sub(allowance[src][msg.sender], wad);
}
balanceOf[src] = sub(balanceOf[src], wad);
balanceOf[dst] = add(balanceOf[dst], wad);
emit Transfer(src, dst, wad);
return true;
}
function mint(address usr, uint wad) external auth {
balanceOf[usr] = add(balanceOf[usr], wad);
totalSupply = add(totalSupply, wad);
emit Transfer(address(0), usr, wad);
}
function burn(address usr, uint wad) external {
require(balanceOf[usr] >= wad, "Dai/insufficient-balance");
if (usr != msg.sender && allowance[usr][msg.sender] != uint(-1)) {
require(allowance[usr][msg.sender] >= wad, "Dai/insufficient-allowance");
allowance[usr][msg.sender] = sub(allowance[usr][msg.sender], wad);
}
balanceOf[usr] = sub(balanceOf[usr], wad);
totalSupply = sub(totalSupply, wad);
emit Transfer(usr, address(0), wad);
}
function approve(address usr, uint wad) external returns (bool) {
allowance[msg.sender][usr] = wad;
emit Approval(msg.sender, usr, wad);
return true;
}
// --- Alias ---
function push(address usr, uint wad) external {
transferFrom(msg.sender, usr, wad);
}
function pull(address usr, uint wad) external {
transferFrom(usr, msg.sender, wad);
}
function move(address src, address dst, uint wad) external {
transferFrom(src, dst, wad);
}
// --- Approve by signature ---
function permit(address holder, address spender, uint256 nonce, uint256 expiry,
bool allowed, uint8 v, bytes32 r, bytes32 s) external
{
bytes32 digest =
keccak256(abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
keccak256(abi.encode(PERMIT_TYPEHASH,
holder,
spender,
nonce,
expiry,
allowed))
));
require(holder != address(0), "Dai/invalid-address-0");
require(holder == ecrecover(digest, v, r, s), "Dai/invalid-permit");
require(expiry == 0 || now <= expiry, "Dai/permit-expired");
require(nonce == nonces[holder]++, "Dai/invalid-nonce");
uint wad = allowed ? uint(-1) : 0;
allowance[holder][spender] = wad;
emit Approval(holder, spender, wad);
}
}