Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

D3m bar #89

Merged
merged 12 commits into from
Dec 1, 2021
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@
[submodule "lib/dss-lerp"]
path = lib/dss-lerp
url = https://github.com/makerdao/dss-lerp
[submodule "lib/dss-direct-deposit"]
path = lib/dss-direct-deposit
url = https://github.com/makerdao/dss-direct-deposit
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ Below is an outline of all functions used in the library.
- `setMedianWritersQuorum(address _median, uint256 _minQuorum)`: Sets the minimum number of valid messages from whitelisted oracle feeds needed to update median price.
- `allowOSMFreeze(address _osm, bytes32 _ilk)`: Add OSM address to OSM mom, allowing it to be frozen by governance.

### Direct Deposit Module
- `setD3MTargetInterestRate(address _d3m, uint256 _pct_bps)`: Set the target rate (`bar`) for a D3M module.

### Collateral Onboarding
In order to onboard new collateral to the Maker protocol, the following must be done before the spell is prepared:
- Deploy a GemJoin contract
Expand Down
1 change: 1 addition & 0 deletions lib/dss-direct-deposit
Submodule dss-direct-deposit added at 773069
14 changes: 14 additions & 0 deletions src/DssExecLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,20 @@ library DssExecLib {
MomLike(osmMom()).setOsm(_ilk, _osm);
}

/*****************************/
/*** Direct Deposit Module ***/
/*****************************/

/**
@dev Sets the target rate threshold for a dai direct deposit module (d3m)
@dev Aave: Targets the variable borrow rate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Let's leave this generic to both Aave/Compound and whoever else in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a line for Compound later. This is to specifically point out that for Aave, we're targeting the borrow rate (and not the lending rate). Every protocol is going to be different.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it will be the same. Really we could pick either in every lending market, but we are interested in the borrow rate as that is what is competitive with Maker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay if you want to add a comment for every D3M type though.

@param _d3m The address of the D3M contract
@param _pct_bps Target rate in basis points. (ex. 4% == 400)
*/
function setD3MTargetInterestRate(address _d3m, uint256 _pct_bps) public {
require(_pct_bps < BPS_ONE_HUNDRED_PCT); // DssExecLib/bar-too-high
setValue(_d3m, "bar", rdiv(_pct_bps, BPS_ONE_HUNDRED_PCT));
}

/*****************************/
/*** Collateral Onboarding ***/
Expand Down
35 changes: 35 additions & 0 deletions src/test/DssAction.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import {DSProxyFactory,
DSProxy} from "ds-proxy/proxy.sol";
import {DssAutoLine} from "dss-auto-line/DssAutoLine.sol";
import {LerpFactory} from "dss-lerp/LerpFactory.sol";
import {DssDirectDepositAaveDai}
from "dss-direct-deposit/DssDirectDepositAaveDai.sol";

import {Vat} from "dss/vat.sol";
import {Dog} from "dss/dog.sol";
Expand Down Expand Up @@ -76,6 +78,20 @@ contract UniPairMock {
}
}

contract AaveMock {
// https://docs.aave.com/developers/the-core-protocol/lendingpool
function getReserveData(address dai) public view returns (
uint256, uint128, uint128, uint128, uint128, uint128, uint40, address, address, address, address, uint8
) {
address _dai = dai; // avoid stack too deep
return (0,0,0,0,0,0,0, _dai, _dai, _dai, address(this), 0);
}

function getMaxVariableBorrowRate() public pure returns (uint256) {
return type(uint256).max;
}
}

contract ActionTest is DSTest {
Hevm hevm;

Expand Down Expand Up @@ -860,6 +876,25 @@ contract ActionTest is DSTest {
assertEq(osmMom.osms("gold"), address(osm));
}

/*****************************/
/*** Direct Deposit Module ***/
/*****************************/

function test_setD3MTargetInterestRate() public {
AaveMock aave = new AaveMock();
DssDirectDepositAaveDai d3m = new DssDirectDepositAaveDai(address(clog), "tungsten", address(aave), address(0));
d3m.rely(address(action));

action.setD3MTargetInterestRate_test(address(d3m), 500); // set to 5%
assertEq(d3m.bar(), 5 * RAY / 100);

action.setD3MTargetInterestRate_test(address(d3m), 0); // set to 0%
assertEq(d3m.bar(), 0);

action.setD3MTargetInterestRate_test(address(d3m), 9900); // set to 99%
assertEq(d3m.bar(), 99 * RAY / 100);
}

/*****************************/
/*** Collateral Onboarding ***/
/*****************************/
Expand Down
4 changes: 2 additions & 2 deletions src/test/DssExec.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ contract DssLibExecTest is DSTest, DSMath {
uint256 constant RAD = 10 ** 45;

// not provided in DSMath
function rpow(uint x, uint n, uint b) internal pure returns (uint z) {
function _rpow(uint x, uint n, uint b) internal pure returns (uint z) {
assembly {
switch x case 0 {switch n case 0 {z := b} default {z := 0}}
default {
Expand All @@ -218,7 +218,7 @@ contract DssLibExecTest is DSTest, DSMath {
uint256 TOLERANCE = 10 ** 22;

function yearlyYield(uint256 duty) public pure returns (uint256) {
return rpow(duty, (365 * 24 * 60 * 60), RAY);
return _rpow(duty, (365 * 24 * 60 * 60), RAY);
}

function expectedRate(uint256 percentValue) public pure returns (uint256) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/DssTestAction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ contract DssTestAction is DssAction {
DssExecLib.allowOSMFreeze(osm, ilk);
}

/*****************************/
/*** Direct Deposit Module ***/
/*****************************/

function setD3MTargetInterestRate_test(address d3m, uint256 pct_bps) public {
DssExecLib.setD3MTargetInterestRate(d3m, pct_bps);
}

/*****************************/
/*** Collateral Onboarding ***/
Expand Down