Skip to content

Commit

Permalink
D3M version 2.0 (#46)
Browse files Browse the repository at this point in the history
* Modularize (#31)

* initial separate into d3m target and d3m join contracts

* initial update of tests and file reorg/rename

* add approval for the join to allow the target to move gems and update the target withdraw to pull the adai first

* update interfaces and require successful transferFrom"

* update tests and fix reward claimer

* allow filing a new target

* minor clean up

* remove unneeded interface

* update interface and add validTarget helper

* add missing arg

* initial Test Target contract

* update test forge path to accept new match arguments

* add new line

* update Target to not need wat parameter

* add test gem for Join testing

* allow for bar = 0 case in tests

* add give allowance to test token and transfers to target

* update Join to fix target cage bug

* we don't need internal balance tracking for the test target

* add a test rewards contract

* add join specific tests for covering the interactions with the Vat

* make targets joins and have them hold balance

Co-authored-by: Julien <[email protected]>

* update testing and d3m Join so that the Target holds the balances in ERC and Vat

* rename Join to Hub

* rename Target to Join

* make Hub compatible with multiple d3m joins:

* add balance check to join

* update test for hub+joins model

* update helper for Hub approach

* update copyrights

* update tests and require d3m be live for admin actions

* use ilks instead

* organize files and change Join->Pool

* switch to pool internally on hub

* update test to use Pool naming

* initial update for separation of Plans from Pools

* minor test updates

* initial breakdown of pool into base

* add Plan base

* clean up

* Update to Eip 4626 (#34)

* initial update of tests and file reorg/rename

* update tests and fix reward claimer

* organize files and change Join->Pool

* switch to pool internally on hub

* initial update for separation of Plans from Pools

* update language for EIP-4626

* fix tests after rename

* maxWithdraw and asset balances - PR comments from @hexonaut

* fix share transfer amounts

* fix tests

* remove helper function

* remove helper function tests

* fix unwind balance

* fix asset balance in test pool

* move bar to plan

* use plan base

* Fix tests

* Modularize upd 325 (#37)

* Clean up vars and add Cage event

* Upd revert names

* Upd revert names in Pool Base

* emit Hope and Nope events on Pool Base

* Add Quit event

* Add emit for clarity

* Add Exit event

* uint => uint256

* rm math

* wards ocd

* start updating aave to use base

* shorten names

* remove chainlog from d3m hub

* remove dai daiJoin from hub

* make common interfaces to use in tests

* remove ds-value submodule

* update aave tests for no ds-value

* add todos

* do daiJoin work in hub @gbalabasquer

* PR comments to clean up hub

* clean up add TODO

* join directly to vow

* PR feedback @talbaneth and @gbalabasquer

* Apply suggestions from code review

Co-authored-by: talbaneth <[email protected]>

* remove collect and move plan to Hub from pool

* abstract bar to individual plan implementations

* read and assign end on when necessary

* don't read the plan

* adjust unwind daiJoin interaction to match wind

* fix aave tests - WIP

* Apply suggestions from code review

Co-authored-by: talbaneth <[email protected]>

* PR clean up comments

* add recover tokens function to pool

* remove convertToAssets from base

* PR comments: remove bar and pool from bases and gas efficiency

* change aave assetBalance calc

* fix mom bar filing

* update test for Aave share balance transfer in exit

* revert convert to shares in exit since we should already be dealing with shares in wad

* fix permissionless repay aave test

* fix remaining aave test

* reorganize interfaces into tests

* move constant

* remove unused interface functions

* remove maxBar from base

* remove events

* Apply suggestions from code review

Co-authored-by: talbaneth <[email protected]>

* fix silly variable setting

Co-authored-by: talbaneth <[email protected]>

* move plans to separate folder

* PR comments - update auths

* move share to pools out of base

* initial switch to returning target assets

* WIP change to return targetAsset

* accrued if needed before getting balance

* integrate @hexonaut 's Aave calc fix

* Delete empty file

* plan base unit tests

* add pool base tests

* re-order accrueIfNeeded and maxWithdraw

Co-authored-by: talbaneth <[email protected]>

* remove unneeded math

Co-authored-by: talbaneth <[email protected]>

* consistent filing for ilks

* better documentations of Ilk in Hub

Co-authored-by: talbaneth <[email protected]>

* remove unneeded safe math

* don't store culled

* unused return variable

Co-authored-by: talbaneth <[email protected]>

* update getTargetAssets

* pr feedback

* update share balance for aave to be scaled

* Mom can disable plans

* make files external

* initial AaveDai plan tests

* more AaveDaiPlan unit tests

* add disable to plan base

* fix missing override

* check dai balance in wind

* denominate shares in hub in dai/gems and add transferAllShares function

* add approxEq for checking dai depositing

* AaveDaiPool tests

* move deposit check to pool

* clean up remaining hub tests

* add Mom tests

* update base and share calculations

* update aaave deposit checking

* remove named return

Co-authored-by: talbaneth <[email protected]>

* remove debugging

* update comments and errors

* fix rounding error

* fix possible bug with debt > debt ceiling

* pr comments and clean up

* add file events

* pr comments on events and requires

* add missing auth and test coverage

* consolidate debt usage to totalDebt instead of adding it multiple times

* update unwind comment

Co-authored-by: talbaneth <[email protected]>

* fix adai pool comment

Co-authored-by: talbaneth <[email protected]>

* update comment

* remove hub cage

* take global line into account and unwind if needed

* Apply suggestions from code review

Co-authored-by: talbaneth <[email protected]>

* fix indentation

* add fees to unwind event

* Some changes to exec (bit simplication and check vat.Line) (#40)

* Some changes to exec (bit simplication and check vat.Line)

* Add comments

* Update src/DssDirectDepositHub.sol

Co-authored-by: talbaneth <[email protected]>

* Update src/DssDirectDepositHub.sol

Co-authored-by: talbaneth <[email protected]>

* Add tests

Co-authored-by: talbaneth <[email protected]>

* Add invalid target check to exec() normal path

* add cull rebalancing

* remove hub rely from pool

* remove duplicate rely

* remove live/cage from pool

* ShareTokenLike -> ATokenLike

* don't call internal transfer

* type pool and adai

* remove hub from pool base

* remove params from collect

* change plan base to interface

* update errors and contract name for plan interface change

* convert Pool Base to Interface

* add maxDeposit to pools

* account for maxDeposit in Hub.exec by either unwinding or limiting wind

* remove extra space

* revert hub interface integration

* maxDeposit is per deposit call

* remove validTarget add condition to disable for aave

* add smaller maxDeposit test

* update plan interface

* update Pool Interface

* remove extra cast

* change from seth check to cast check for forge test

* code clean up

Co-authored-by: talbaneth <[email protected]>

* pr comments clean up

* inline amount for collect

* catch up Test pool

* update maxBar to be used where it should and be internal

* add active() to plans

* add active to Pools

* add check in hub that pool and plan are active or unwind

* allow filing interestStrategy

Co-authored-by: Julien <[email protected]>
Co-authored-by: Brian McMichael <[email protected]>
Co-authored-by: talbaneth <[email protected]>
Co-authored-by: Gonzalo Balabasquer <[email protected]>

* add space

* update spacing, visibility and location of RAY

* add Natspec comments to base Pool, Plan and Hub contracts (#43)

* add docs for Hub

* add comments to plan interface

* fix ilk cage docs

* add pool docs

* comment clean up

* fix grammar

Co-authored-by: talbaneth <[email protected]>

* spelling

Co-authored-by: talbaneth <[email protected]>

* unify wrapping point and punctuation

* clarify plan doc

* pr comments

* contract -> interface

* update comments

Co-authored-by: talbaneth <[email protected]>

Co-authored-by: talbaneth <[email protected]>

* Extract test_sets_dai_value from base tests.

This is since `asset` is not part of the interface for plan/pool.
For example in Compound I just call it `dai` (and not asset).

* Remove redundant rely

* grammar

Co-authored-by: Kurt Barry <[email protected]>

* fix if condition for block number (#48)

* remove space

* fix end address

Co-authored-by: Nazzareno Massari <[email protected]>

* update end in aave tests

Co-authored-by: Nazzareno Massari <[email protected]>

* improve skaave failure test

* update pragma to be more flexible

* add hope/nope to the pool to be able to update the hub

* use interfaces in Hub

* add nope to hub

* add comments for hub.nope()

* fix storage ordering and move auth functions

* add tests for pool quit and unwind/wind upgrade paths

* add test for plan swap

* add hub upgrade tests

* reorder events

* remove unneeded cage event

* add getter functions for d3m ilks

* add ink/art to cull event

* add wad to uncull event

* add bar == 0 sets not active

* add exec fail test for non-existant ilk

* add pre and post hooks for exec and reap

* Forge ci (#49)

* try forge ci

* add ETH_RPC_URL and rpc flags

* remove check gas

* remove nix

* combine workflow commands

* remove pull_request trigger

* fix blocks

* update step names

Co-authored-by: Nazzareno Massari <[email protected]>

Co-authored-by: Nazzareno Massari <[email protected]>

* fix ordering of internal functions in hub

* remove unneeded calculateTargetSupply public function

* move aave integration test out of pool folder

* fix comment typo

Co-authored-by: Kurt Barry <[email protected]>

* fix integration test relative paths

* fix file function consistency

* remove unneeded param from unwind

* add rate == 1 require to exec

* fix spacing

* check active on pool/plan in reap

* fix cull comment

* store tic as timestamp + tau

* remove tau cage test fail

* fix requires in reap

* add bool return to deposit and withdraw

* add withdraw require to reap

* remove unneeded approval for pool to aave pool for adai

* change from recoverTokens to recoverDai for Pools

* prevent dup caging of pool

* use wad in pool functions

* pin solc in ci

* add test showing left over ink after cage if debt repaid

* Solc upgrade (#47)

* initial 0.8.13 upgrade changes

* clear warnings

* remove safe math from Hub

* remove safe math from Test Gem

* remove safe math from Dai Pool

* remove safe math from dai plan

* update ci nix

* update dappPkg

* update dapp tests for 0.8.13

* add quotes

Co-authored-by: Nazzareno Massari <[email protected]>

* update nix dapp version

* change to 0.6.12 or greater

* clean up

Co-authored-by: talbaneth <[email protected]>
Co-authored-by: Gonzalo Balabasquer <[email protected]>

* lock pragma to ^0.8.14

* add unchecked to hub

* add unchecked to Aave Plan

* remove math functions

* fix solc version in scripts

Co-authored-by: Gonzalo Balabasquer <[email protected]>

* update int overflow check

* fix merge problems

* fix makefile

Co-authored-by: Nazzareno Massari <[email protected]>

* add safe math comment back

* pin solc in ci to 0.8.14

* fix order of operations

Co-authored-by: Nazzareno Massari <[email protected]>

* fix fake address

Co-authored-by: Nazzareno Massari <[email protected]>

* revert fake address change

Co-authored-by: Nazzareno Massari <[email protected]>
Co-authored-by: talbaneth <[email protected]>
Co-authored-by: Gonzalo Balabasquer <[email protected]>

* add test for wind/unwind token with less than 18 decimals

* move unwind int overflow check to min from require

* move int overflow for wind to min checks

* refactor toWind to one assignment

* make unwind params easier to read

* add reentrancy protection in hub

* add test that cull fails with no ilk

* update mom events

* rename intrestStrategy to tack

* remove require in file and limit target rate to max bar

* set rate to max of base or target rate

* unwind if bar is out of bounds

* remove make deploy

* don't check adai address in constructor

* emit gift for king

* fix spacing

Co-authored-by: talbaneth <[email protected]>

* fix spacing

Co-authored-by: talbaneth <[email protected]>

* reorder pool plan variables

* DssDirectDepositHub => D3MHub and D3MAaveDai => D3MAave (#61)

* `MAXINT256` (#57)

Co-authored-by: Gonzalo Balabasquer <[email protected]>

* Fix error message

* replace tack filing what

* add higher level unchecked for aave plan math

* add what param for pre/post debt changes

* reorder hub immutables

* add comments with links to aave contracts

* get rewards claimer from adai

* remove recoverDai function

* add loss test by @hexonaut

* remove hub.nope()

* Add FileCopyRightText (#62)

* Remove quit (#64)

* remove unused var

Co-authored-by: talbaneth <[email protected]>

* update comment for transfer

* add redeemable function for pools

* clean up aave plan active

* update comments in hub for multiple d3ms

Co-authored-by: Julien <[email protected]>

* RAY == 1

Co-authored-by: Gonzalo Balabasquer <[email protected]>

* add require to prevent winding over MAXINT256

* replace divup with best practice version

* remove return on deposit/withdraw

* add mode protection

* rename getter functions and clear shadow warnings (#65)

* rename getter functions and clear shadow warnings

* switch _ location

* keep vow and end consistent with _ before in functions

* fix overflow wind check

* remove returns from transfers

* remove Pool.active and clean up (#63)

* add wild() to pools and plans and allow permissionless caging

* add hub tests for wild caging and fix auth

* make wild pure

* add paused check on pools and plans to prevent any exec action

* add ability to pause pool and ensure exec doesn't change

* add ability to pause plan and ensure exec doesn't change

* add ability to unpause pool and resume exec

* add ability to unpause plan and resume exec

* add pause to Mom

* remove active from pools

* remove pause and wild

* clean up variables

* remove unneeded events

* remove spacing

* align &s

* Update README (#67)

* update readme to v2 and add more detail

* Update README.md

Co-authored-by: Chris Smith <[email protected]>

* Update README.md

Co-authored-by: Chris Smith <[email protected]>

* Update README.md

Co-authored-by: Chris Smith <[email protected]>

* Update README.md

Co-authored-by: Chris Smith <[email protected]>

* update image

* add holds lp token

Co-authored-by: Chris Smith <[email protected]>

* fix imgur link to ipfs

Co-authored-by: Nazzareno Massari <[email protected]>

* fix spacing in aave plan

* No governance after cage (#60)

* Remove governance access from pool after shutdown

* New modifier onlyHub

* Remove spacing

* Add more tests

* Move some tests from AavePool to Base one

* Update src/tests/stubs/D3MTestPool.sol

Co-authored-by: Chris Smith <[email protected]>

* Update src/pools/D3MAavePool.sol

Co-authored-by: talbaneth <[email protected]>

* Update src/pools/D3MAavePool.sol

Co-authored-by: talbaneth <[email protected]>

* No need vat.live check on deny

* Fix interface message

* Remove unnecessary local variable

* transferAll => quit

* Move more tests to base

Co-authored-by: Chris Smith <[email protected]>
Co-authored-by: talbaneth <[email protected]>

* Add D3MOracle (#59)

* Add D3MOracle

* peek and read with same behaviour + better tests

* Update src/D3MOracle.sol

Co-authored-by: talbaneth <[email protected]>

* Update src/D3MOracle.sol

Co-authored-by: talbaneth <[email protected]>

* Update src/D3MOracle.sol

Co-authored-by: talbaneth <[email protected]>

* Fix message

* Add comment

* Minor change

Co-authored-by: talbaneth <[email protected]>

* Assert revert (#72)

* Implement AssertRevert

* Use assertRevert in all the other test files

* Add newline

* No more special function

* dapp uninstall ds-test

* dapp install makerdao/dss-test

* Use dss-test dependency

* Move test files

* rename asset to dai in aave pool

* clean up items

* enforce spot == RAY

* add clarity comment for bar = 0

Co-authored-by: talbaneth <[email protected]>

* Fix what filing

* uint256 standard

Co-authored-by: Gonzalo Balabasquer <[email protected]>

* change enum name

* do not pass vat to hub

* minor clean up items in hub

* dapp upgrade dss-test

* Introduce _fix function and add tests (#70)

* add initial debt repay tests

* add test where we wind first

* Introduce new function fix

* Working on tests

* Finish test

* Fix reap test

* Fix remaining tests and do some clean up in others

* clean up hub tests

* add test for fix during shutdown

* show end fail case where we get bad gems

* No fix after shutdown

* add test for module cage with debt paid back and fix

* More checks and fix some others

* fix as internal function

* Remove require

* Update src/tests/interfaces/interfaces.sol

Co-authored-by: talbaneth <[email protected]>

* Update src/tests/D3MHub.t.sol

Co-authored-by: talbaneth <[email protected]>

* Add more checks

* Improve test

* Remove rebalance in cull as it isn't actually the most correct thing

* fix comment

* add to gitignore

* Remove file

* Replace min to require for MAXINT256 check

* Fixes

Co-authored-by: Gonzalo Balabasquer <[email protected]>
Co-authored-by: talbaneth <[email protected]>

* Fix FileCopyRightText + Cleanups (#75)

* Align pool and plan code style to Compound

* more alignemnts

* Minor alignment changes and return comment

* Move && a bit

* return back from interface alignment

* Update src/pools/D3MAavePool.sol

Co-authored-by: Nazzareno Massari <[email protected]>

* Compound (#51)

* initial separate into d3m target and d3m join contracts

* initial update of tests and file reorg/rename

* add approval for the join to allow the target to move gems and update the target withdraw to pull the adai first

* update interfaces and require successful transferFrom"

* update tests and fix reward claimer

* allow filing a new target

* minor clean up

* remove unneeded interface

* update interface and add validTarget helper

* add missing arg

* initial Test Target contract

* update test forge path to accept new match arguments

* add new line

* update Target to not need wat parameter

* add test gem for Join testing

* allow for bar = 0 case in tests

* add give allowance to test token and transfers to target

* update Join to fix target cage bug

* we don't need internal balance tracking for the test target

* add a test rewards contract

* add join specific tests for covering the interactions with the Vat

* make targets joins and have them hold balance

Co-authored-by: Julien <[email protected]>

* update testing and d3m Join so that the Target holds the balances in ERC and Vat

* rename Join to Hub

* rename Target to Join

* make Hub compatible with multiple d3m joins:

* add balance check to join

* update test for hub+joins model

* update helper for Hub approach

* update copyrights

* update tests and require d3m be live for admin actions

* use ilks instead

* organize files and change Join->Pool

* switch to pool internally on hub

* update test to use Pool naming

* initial update for separation of Plans from Pools

* minor test updates

* initial breakdown of pool into base

* add Plan base

* clean up

* Update to Eip 4626 (#34)

* initial update of tests and file reorg/rename

* update tests and fix reward claimer

* organize files and change Join->Pool

* switch to pool internally on hub

* initial update for separation of Plans from Pools

* update language for EIP-4626

* fix tests after rename

* maxWithdraw and asset balances - PR comments from @hexonaut

* fix share transfer amounts

* fix tests

* remove helper function

* remove helper function tests

* fix unwind balance

* fix asset balance in test pool

* move bar to plan

* use plan base

* Fix tests

* Modularize upd 325 (#37)

* Clean up vars and add Cage event

* Upd revert names

* Upd revert names in Pool Base

* emit Hope and Nope events on Pool Base

* Add Quit event

* Add emit for clarity

* Add Exit event

* uint => uint256

* rm math

* wards ocd

* start updating aave to use base

* shorten names

* remove chainlog from d3m hub

* remove dai daiJoin from hub

* make common interfaces to use in tests

* remove ds-value submodule

* update aave tests for no ds-value

* add todos

* do daiJoin work in hub @gbalabasquer

* PR comments to clean up hub

* clean up add TODO

* join directly to vow

* PR feedback @talbaneth and @gbalabasquer

* Apply suggestions from code review

Co-authored-by: talbaneth <[email protected]>

* remove collect and move plan to Hub from pool

* abstract bar to individual plan implementations

* read and assign end on when necessary

* don't read the plan

* adjust unwind daiJoin interaction to match wind

* fix aave tests - WIP

* Apply suggestions from code review

Co-authored-by: talbaneth <[email protected]>

* PR clean up comments

* add recover tokens function to pool

* remove convertToAssets from base

* PR comments: remove bar and pool from bases and gas efficiency

* change aave assetBalance calc

* fix mom bar filing

* update test for Aave share balance transfer in exit

* revert convert to shares in exit since we should already be dealing with shares in wad

* fix permissionless repay aave test

* fix remaining aave test

* reorganize interfaces into tests

* move constant

* remove unused interface functions

* remove maxBar from base

* remove events

* Apply suggestions from code review

Co-authored-by: talbaneth <[email protected]>

* fix silly variable setting

Co-authored-by: talbaneth <[email protected]>

* move plans to separate folder

* PR comments - update auths

* move share to pools out of base

* initial switch to returning target assets

* WIP change to return targetAsset

* accrued if needed before getting balance

* integrate @hexonaut 's Aave calc fix

* Delete empty file

* plan base unit tests

* add pool base tests

* re-order accrueIfNeeded and maxWithdraw

Co-authored-by: talbaneth <[email protected]>

* remove unneeded math

Co-authored-by: talbaneth <[email protected]>

* consistent filing for ilks

* better documentations of Ilk in Hub

Co-authored-by: talbaneth <[email protected]>

* remove unneeded safe math

* don't store culled

* unused return variable

Co-authored-by: talbaneth <[email protected]>

* update getTargetAssets

* pr feedback

* update share balance for aave to be scaled

* Mom can disable plans

* make files external

* initial AaveDai plan tests

* more AaveDaiPlan unit tests

* add disable to plan base

* fix missing override

* check dai balance in wind

* denominate shares in hub in dai/gems and add transferAllShares function

* add approxEq for checking dai depositing

* AaveDaiPool tests

* move deposit check to pool

* clean up remaining hub tests

* add Mom tests

* update base and share calculations

* update aaave deposit checking

* remove named return

Co-authored-by: talbaneth <[email protected]>

* remove debugging

* update comments and errors

* fix rounding error

* fix possible bug with debt > debt ceiling

* pr comments and clean up

* add file events

* pr comments on events and requires

* add missing auth and test coverage

* consolidate debt usage to totalDebt instead of adding it multiple times

* update unwind comment

Co-authored-by: talbaneth <[email protected]>

* fix adai pool comment

Co-authored-by: talbaneth <[email protected]>

* update comment

* D3MCompoundDaiPlan - initial implementation, untested

* Neat

* Add initial version of D3MCompoundDaiPool, missing logic and tests

* More ppol work, actually add D3MCompoundDaiPool.sol

* Test supply for current rate

* D3MCompoundDaiPlan testing

* Add test for calculating supplies

* Align to latest modularize branch

* Add accrueIfNeeded to compound pool

* D3MCompoundDai.t.sol - WIP

* Align to latest modularize changes

* Remove auth modifier from compound's collect()

* Support also 0 jump multiplier

* Neat

* Unify return values

* Neat - fix indentation

* Add plan test from hub

* During test cleanup

* Align to modularize latest changes

* Support explicit disable() from mom

* Make disable overriding on Compound Plan

* Align to transferShares changes in hub

* Align to modularize - validaion in deposit

* Add underlying() validation also in plan ctr

* Remove unused function in pool and add overrride

* Align to modularize pool changes

* Add Compound plan events

* Add Compound pool auth and events

* Align to compound-cd-audit fixes, commit fa793a3

This is the commit with the response to CS audit for Plan.
The base plan and compound plan code are now identical to there.

* Align to v2, wip

* Align to v2, tests pass

* Port test from cs-audit-fixes

* Fix merge mistake with filing rate model

* Finish porting all new plan tests

* Add D3MCompoundDaiPool.t.sol

* Align Compound plan test to run base plan tests

* Cleare comparisons in D3MCompoundDai.t.sol

* Simplify to use just _setRelBorrowTarget in D3MCompoundDai.t.sol

* Align to use Like suffix for interfaces

* Linter run - break require, remove test comment

* Add clarification for Compound APY

* Slightly improve plan comment + small neats

* Add comp amount comparison to test

* Refactors based on AAVE comments

-Move administration parts to the top so wards will be in first slot.
-Move internal functions to after external related ones.

* Add amt to Compund's Collect() event

* Fix merge of D3MAaveDaiPool.t.sol

* Use compSupplySpeeds in comp claiming tests

* Align line break style to rest of the file

* Use internal constant, Add TODOs

* add 2021 Nov Aave D3M Audit (#52)

* fix end address

Co-authored-by: Nazzareno Massari <[email protected]>

* update end in aave tests

Co-authored-by: Nazzareno Massari <[email protected]>

* Update End address in D3MCompoundDai.t.sol

* Fix typo

* Tighten underlying dai comparisons, check deposit cdai

* Add nope to compound pool, support hope/nope base tests

* align to use >= in solidity pragma

* Group storage together for Compound pool and plan

* Flip expected and ectual in assertEqAbsolute

* Align to V2 branch

* Align layout of events/ctr/auth/math/admin to aave

* Revert if getAccountSnapshot returns an error

* Add TODOs

* Add Compound links and explanation for using exchangeRateStored

* Algin to V2 changes

* Renamings and avoiding unused warning on hooks

* Add SPDX-FileCopyrightText to Compound files

* Align to V2

* deactivate if cdai implementation changes

* Add boundary for barb

* Make comp immutable, get dai from cdai

* Support collect without claim.

 Since COMP can be claimed to the pool directly through Compound by
 a 3rd party make sure it can be recovered later even if comptroller
 would revert for some reason.

* Improve interface links

* align to v2 - wip

* Finish aliging to asserRevert change

* Align to V2

* Add Compound to README

* Update to permanent links

* Fix failures due to rounding

* Validate delegate is not address(0)

* Use address instead of token in cDai etherscan link

Co-authored-by: Nazzareno Massari <[email protected]>

* Move tau to general place in the Readme

* Move _calculateTargetSupply up

* Add comment about normal rate

* Use _hub in pool ctr

* Reorder cdai assignment and Avoid casting in plan

* Support utilization > 100%

* Comment why multiplierPerBlock != 0 and can de divided by

* dapp upgrade dss-test (reverting un-intentional downgrade)

* _assertEqApprox => assertEq

Co-authored-by: Gonzalo Balabasquer <[email protected]>

* Remove safe math in tests

* Fix copyrights

Co-authored-by: Nazzareno Massari <[email protected]>

* Handle several review comments in tests

* Fix copyrights also in Compound tests

* Substract before addition

* Neat - better spacings

Co-authored-by: Chris Smith <[email protected]>
Co-authored-by: Julien <[email protected]>
Co-authored-by: Brian McMichael <[email protected]>
Co-authored-by: Nazzareno Massari <[email protected]>
Co-authored-by: Gonzalo Balabasquer <[email protected]>

* Handle minor suggestions (#78)

* Destroy Compound interface alignments to match aave

* Use storage vars in ctr

* Fix aave random failures (#77)

* Fix aave random failures

* Tighten error in test_unwind_culled_then_mcd_cage

* Add reentrancy warning commnets for getTargetAssets (#80)

* Add reentrancy warning commnets for getTargetAssets

* false => zero

* remove unneeded check in getTargetAssets tests

* add withdraw DAI balance checks to Aave and Compound - CS Audit Question 7.1

* remove unneeded casting

* add check on ATOKEN_REVISION for active

* Remove reap, simplify _unwind and rebalance

* Add missing frob in _fix

* Fix README

* Fix Hub tests

* Fix Aave integration tests

* Fix compound tests and minor changes to aave ones

* No need of assetsBalance in unwind

* New structure for exec + removing _fix and creating new _normal function

* Limit amount of fixIlk

* No more modes

* cmooney-20220805: Fixes for CS 5.4 Inconsistencies (#84)

* cmooney-20220805: Fixes for CS 5.4 Inconsistencies

* bound bar in AAVE plan to MAX_BORROW_RATE

* Revert "bound bar in AAVE plan to MAX_BORROW_RATE"

This reverts commit e2bf302.

* Call getTargetAssets once

* Remove comment

* Remove param in preDebtChange and postDebtChange

* Change <= to < in one condition

* only call getTargetAssets if plan is active

* Minor changes art/Art with extra check

* Use overloaded unwind

* Move vat.slip

* Remove comment

* Fix tests

* Fix tests failing on block 15308334

* Fix 15308526

* Add comment for rounding that may affect twice

* Minor changes _normal structure

* Improve readability and comments for fixInk

* Use standard assertRevert for lock checks

* Add Hub tests for checking art != Art

* Add fixInk tests

* Treat all the variables the same in normal path

* Fix comments

* Bit of restructure of normal function

* Change order

* Better use maxWithdraw for checks in tests

* Add test and minor renaming

* Add certora (#85)

* Add Certora

* Add DISPATCHER(true)

* Add checks

* Fix

* Minor changes

* less restrictive spec

* Use real Vat, DaiJoin and Dai code with solc 0.5.12

* Use D3MTestPool and D3MTestPlan

* More checks and CI setup

* Move certora.yml to correct place

* Fix some asserts

* Add exec_exec rule and some minor changes in exec_normal

* More checks

* multi assert flag via conditional

* Improve checks and add comments

* Use staging and old certora-cli version until production gets fixed

* More checks

* Add exec_ilk_culled

* check dai in vow for normal path

* Add exec_vat_caged

* Add cage and cull

* Add uncull

* Add exit

* Add exit_revert

* Add cage_revert

* Remove unnecessary stuff of cage_revert

* Add cull_revert

* Add uncull_revert + some variables renaming

* Add rely, rely_revert, deny and deny_revert

* Add file_ilk_uint256 and file_ilk_uint256_revert

* Add file_ilk_address and file_ilk_address_revert

* Add ilk_getters

* Add exec_vat_caged_revert + minor changes

* Add exec_ilk_culled_revert and minor chanegs to exec_vat_caged_revert

* Use main staging + split CI runs in several

* Use matrix for running all the rules in CI

* Fix CI config file

* Certora CI only on pushes (for now)

* Add to ignore

* Add timeout flag

* Add exec_normal_revert (without checking if all the revert cases are covered)

* Stick to specific certora-cli-alpha-master version

* Verify inkAfter can't be higher than max_int256

* Add missing end lines

* Add unchecked

* Removing some internal functions are renaming other

* Move getters to the bottom

* Some minor changes

* art = ink outside of unchecked

* Restrict all operation to maxint256 / RAY to avoid overflows

* Bit better structure for _exec

* Minor changes to _wipe and uncull

* Tidy up

* Use NoOp event also in _wipe

* Minor renaming

* Fix exec_exec

* Add comment explaining the system cage path of exec

* Fix D3MAavePool comment

* More precise pool shares (#87)

* More precise account for pools shares after shutdown + force unwinding if assets < ink

* No more dapp

* Minor changes

* Rename test

* Add exit tests

* Fix exit and exit_revert specs

* Fix exec_normal_revert expect with the new changes

* Improve exit tests

* Improving exec_normal spec

* Fix comment

* Enforce solc 0.8.14 in make test and use it for CI

* Fix test rounding error

* Remove unnecessary tests

* 1e18 to wad and aave rounding (#88)

* switch compound tests from 1e18 to WAD

* fix aave test rounding issues

* gonza fixing my assertEq dyslexia

Co-authored-by: Gonzalo Balabasquer <[email protected]>

Co-authored-by: Gonzalo Balabasquer <[email protected]>

Co-authored-by: Chris Smith <[email protected]>

* Fix spacing in Makefile

* Fix for new version of solc-select which puts artifacts inside individual directories

* Add test_borrow_apy (#91)

* Add test_borrow_apy

* hevm => vm

* Make comment about Compound UI a bit clearer

* Add back a test that was falsely removed

Co-authored-by: rockyfour <[email protected]>

* Certora: Use solc optimizations where corresponds

* Be explicit about optimization options in test script

* add final v2 audit

* fix rounding expectation

Co-authored-by: Julien <[email protected]>
Co-authored-by: Brian McMichael <[email protected]>
Co-authored-by: talbaneth <[email protected]>
Co-authored-by: Gonzalo Balabasquer <[email protected]>
Co-authored-by: Kurt Barry <[email protected]>
Co-authored-by: Nazzareno Massari <[email protected]>
Co-authored-by: Sam MacPherson <[email protected]>
Co-authored-by: Christopher Mooney <[email protected]>
Co-authored-by: rockyfour <[email protected]>
Co-authored-by: rockyfour <[email protected]>
  • Loading branch information
11 people authored Dec 2, 2022
1 parent 160f695 commit c10c6d5
Show file tree
Hide file tree
Showing 44 changed files with 10,193 additions and 994 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/certora.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Certora

on: [push]

jobs:
certora:
name: Certora
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: Hub admin & getters
rules: rely rely_revert deny deny_revert file_ilk_uint256 file_ilk_uint256_revert file_ilk_address file_ilk_address_revert ilk_getters
- name: Hub exit, cage, cull, uncull and their reverts
rules: exit exit_revert cage cage_revert cull cull_revert uncull uncull_revert
- name: Hub exec non revert
rules: exec_normal exec_ilk_culled exec_vat_caged
- name: Hub exec normal revert
rules: exec_normal_revert
- name: Hub exec ilk culled and vat caged revert
rules: exec_ilk_culled_revert exec_vat_caged_revert
- name: Hub double exec
rules: exec_exec

steps:
- name: Checkout
uses: actions/checkout@v3

- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
java-package: jre

- name: Set up Python 3.8
uses: actions/setup-python@v3
with:
python-version: 3.8

- name: Install solc-select
run: pip3 install solc-select

- name: Solc Select 0.5.12
run: solc-select install 0.5.12

- name: Solc Select 0.8.14
run: solc-select install 0.8.14

- name: Install Certora
run: pip3 install certora-cli-alpha-master==20220824.13.29

- name: Certora ${{ matrix.name }}
run: make certora-hub short=1 rule="${{ matrix.rules }}"
env:
CERTORAKEY: ${{ secrets.CERTORAKEY }}
29 changes: 12 additions & 17 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
on: [push, pull_request]
on: [push]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository and submodules
uses: actions/checkout@v2
with:
submodules: recursive
- uses: actions/checkout@v3

- name: Install nix 2.3.6
uses: cachix/install-nix-action@v13
with:
install_url: https://releases.nixos.org/nix/nix-2.3.6/install
nix_path: nixpkgs=channel:nixos-unstable
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Use maker and dapp cachix
uses: cachix/cachix-action@v10
with:
name: maker
extraPullNames: dapp
- name: Install Dependencies
run: forge install

- name: Run tests
run: nix-shell --pure --argstr url ${{ secrets.ETH_RPC_URL }} --run 'dapp test -v --rpc'
- name: Run tests
run: make test
env:
ETH_RPC_URL: ${{ secrets.ETH_RPC_URL }}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
/out
/cache
resource_errors.json

# certora
*autoFinder_*
.*certora*
.last_confs/
*.zip
.zip-output-url.txt
certora_debug_log.txt
9 changes: 3 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "lib/ds-test"]
path = lib/ds-test
url = https://github.com/dapphub/ds-test
[submodule "lib/ds-value"]
path = lib/ds-value
url = https://github.com/dapphub/ds-value
[submodule "lib/dss-test"]
path = lib/dss-test
url = https://github.com/makerdao/dss-test
11 changes: 5 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
all :; DAPP_BUILD_OPTIMIZE=1 DAPP_BUILD_OPTIMIZE_RUNS=200 dapp --use solc:0.6.12 build
clean :; dapp clean
test :; ./test.sh match=$(match) optimizer=1
test-dev :; ./test.sh match=$(match) optimizer=0
test-forge :; ./test-forge.sh match=$(match) block=$(block)
deploy :; make && dapp create DssDirectDepositAaveDai 0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F 0x4449524543542d4141564556322d444149000000000000000000000000000000 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9 0xd784927Ff2f95ba542BfC824c8a8a98F3495f6b5
all :; DAPP_BUILD_OPTIMIZE=1 DAPP_BUILD_OPTIMIZE_RUNS=200 dapp --use solc:0.8.14 build
clean :; dapp clean
test :; ./test.sh solc="0.8.14" match="$(match)" block="$(block)" match-test="$(match-test)" match-contract="$(match-contract)"
test-forge :; make test
certora-hub :; PATH=~/.solc-select/artifacts/solc-0.8.14:~/.solc-select/artifacts/solc-0.5.12:~/.solc-select/artifacts:${PATH} certoraRun --solc_map D3MHub=solc-0.8.14,Vat=solc-0.5.12,DaiJoin=solc-0.5.12,Dai=solc-0.5.12,End=solc-0.5.12,D3MTestPlan=solc-0.8.14,D3MTestPool=solc-0.8.14,D3MTestGem=solc-0.8.14 --optimize_map D3MHub=200,Vat=0,DaiJoin=0,Dai=0,End=0,D3MTestPlan=200,D3MTestPool=200,D3MTestGem=200 --rule_sanity basic src/D3MHub.sol certora/dss/Vat.sol certora/dss/DaiJoin.sol certora/dss/Dai.sol certora/dss/End.sol src/tests/stubs/D3MTestPlan.sol src/tests/stubs/D3MTestPool.sol src/tests/stubs/D3MTestGem.sol --link D3MHub:vat=Vat D3MHub:daiJoin=DaiJoin D3MHub:end=End DaiJoin:vat=Vat DaiJoin:dai=Dai End:vat=Vat D3MTestPlan:dai=Dai D3MTestPool:hub=D3MHub D3MTestPool:vat=Vat D3MTestPool:dai=Dai D3MTestPool:share=D3MTestGem --verify D3MHub:certora/D3MHub.spec --settings -mediumTimeout=180 --staging$(if $(short), --short_output,)$(if $(rule), --rule $(rule),)$(if $(multi), --multi_assert_check,)
47 changes: 40 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
# Direct Deposit Module for Maker
![Build Status](https://github.com/makerdao/dss-direct-deposit/actions/workflows/.github/workflows/tests.yaml/badge.svg?branch=master)

The Direct Deposit Module interfaces with third party lending protocols to enable a maximum variable borrow rate for selected assets. Maker Governance is able to pick a target variable borrow rate, and the module will automatically deposit/remove liquidity to ensure that target rate is hit.
The Dai Direct Deposit Module (D3M) is a tool for directly injecting DAI into third party protocols.

## DssDirectDepositAaveDai
![D3M](https://ipfs.io/ipfs/QmfAPBsAQbPoAiMB7vypuBwC41X5yrzYKNMUia4nGyoN23)

### Configuration
As seen in the image above, external protocols are viewed under the simplified ERC-4626-like interface. Pool adapters are used to convert protocol complexity into simplified concepts of Excess Capacity + DAI liquidity + DAI outstanding. How DAI is converted between these states is completely protocol-specific and mostly irrelevant to the D3M.

The D3M is made of 3 components on the Maker side:

### D3MHub

The primary manager contract responsible for collecting all information and determining which action to take (if any). Each D3M instance is regsitered on the Hub using relevant `file(ilk, ...)` admin functions.

A permissionless `exec(ilk)` function exists which will perform all necessary steps to update the provided liquidity within the debt ceiling and external protocol constraints. `exec(ilk)` will need to be called on a somewhat regular basis to keep the system running properly. During each call to this function, interest will automatically be collected.

### D3MPool

A "dumb" adapter which is responsible for depositing or withdrawing DAI from the target protocol based on instructions from the Hub. Also contains functions which provide information such as `maxDeposit()` and `maxWithdraw()`. These inform the hub the maximum room to deposit or withdraw respectively. Abstractly we view this `maxWithdraw()` value as the available DAI liquidity that can be immediately withdrawn. Different protocols have different mechanisms for making DAI liquidity available. For example, some protocols raise interest rates to encourage more 3rd party deposits (or repays from borrowers). In the other cases, there could be a function such as `intendToWithdraw()` which signals to the pool operator that they should begin liquidating some positions to free up DAI.

### D3MPlan

The D3MPlan can be viewed as the targeting logic for D3M instances. The plan is responsible for reading all relevant information from its state (i.e. the target rate) and possibly from the external protocol (i.e. current balance of supply and borrowing in the market) and condensing this down to a debt target. This desired target debt is forwarded to the Hub to take action to reach this target debt level asap.

### General Configuration

Below are the configurable parameters for the Aave DAI D3M:
The below parameter exists for each D3M implementation:

- `tau` [seconds] - The expiry for when bad debt is sent to the vow debt queue. This must be set during initialization to enforce a deadline for when this module is considered to be in a failure mode where no more liquidity is available in the pool to unwind. Unwinding can still occur after this period elapses.

# Specific Implementations

## Aave D3M

### Configuration

Below is a configurable parameter for the Aave DAI D3M:

- `bar` [ray] - The target borrow rate on Aave for the DAI market. This module will aim to enforce that borrow limit.

### Operation
Any stkAave that is accured can be permissionlessly collected into the pause proxy by calling `collect()`.

## Compound D3M

### Configuration

Below is a configurable parameter for the Compound DAI D3M:

A permissionless `exec()` function exists which will perform all necessary steps to enforce the maximum borrow rate to within the available liquidity and debt ceiling constraints. `exec()` will need to be called on a somewhat regular basis to keep the system running properly. Upon unwinding interest will automatically be collected, but you can also permissionlessly call `reap()` to pull in all collected interest as well.
- `barb` [wad] - The target borrow rate per block on Compound for the DAI market. This module will aim to enforce that borrow limit.

Any stkAave that is accured can be permissionlessly collected into the pause proxy by calling `collect(address[], uint256)`.
Any Comp that is accured can be permissionlessly collected into the pause proxy by calling `collect()`.
Binary file not shown.
Loading

0 comments on commit c10c6d5

Please sign in to comment.