Skip to content

Commit dd788be

Browse files
authored
feat: Adding lerp support (#60)
1 parent 07f630e commit dd788be

File tree

6 files changed

+102
-5
lines changed

6 files changed

+102
-5
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@
4141
[submodule "lib/univ2-lp-oracle"]
4242
path = lib/univ2-lp-oracle
4343
url = https://github.com/makerdao/univ2-lp-oracle
44+
[submodule "lib/dss-lerp"]
45+
path = lib/dss-lerp
46+
url = https://github.com/makerdao/dss-lerp

lib/dss-interfaces

lib/dss-lerp

Submodule dss-lerp added at 98841ed

src/DssExecLib.sol

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ interface IAMLike {
116116
function exec(bytes32) external returns (uint256);
117117
}
118118

119+
interface LerpFactoryLike {
120+
function newLerp(bytes32 name_, address target_, bytes32 what_, uint256 startTime_, uint256 start_, uint256 end_, uint256 duration_) external returns (address);
121+
function newIlkLerp(bytes32 name_, address target_, bytes32 ilk_, bytes32 what_, uint256 startTime_, uint256 start_, uint256 end_, uint256 duration_) external returns (address);
122+
}
123+
124+
interface LerpLike {
125+
function tick() external;
126+
}
127+
119128

120129
library DssExecLib {
121130

@@ -183,6 +192,7 @@ library DssExecLib {
183192
function pauseProxy() public view returns (address) { return getChangelogAddress("MCD_PAUSE_PROXY"); }
184193
function autoLine() public view returns (address) { return getChangelogAddress("MCD_IAM_AUTO_LINE"); }
185194
function daiJoin() public view returns (address) { return getChangelogAddress("MCD_JOIN_DAI"); }
195+
function lerpFab() public view returns (address) { return getChangelogAddress("LERP_FAB"); }
186196

187197
function clip(bytes32 _ilk) public view returns (address _clip) {
188198
_clip = RegistryLike(reg()).xlip(_ilk);
@@ -1063,4 +1073,41 @@ library DssExecLib {
10631073
DssVat(vat()).suck(vow(), address(this), _amount * RAD);
10641074
JoinLike(daiJoin()).exit(_target, _amount * WAD);
10651075
}
1076+
1077+
/************/
1078+
/*** Misc ***/
1079+
/************/
1080+
/**
1081+
@dev Initiate linear interpolation on an administrative value over time.
1082+
@param _name The label for this lerp instance
1083+
@param _target The target contract
1084+
@param _what The target parameter to adjust
1085+
@param _startTime The time for this lerp
1086+
@param _start The start value for the target parameter
1087+
@param _end The end value for the target parameter
1088+
@param _duration The duration of the interpolation
1089+
*/
1090+
function linearInterpolation(bytes32 _name, address _target, bytes32 _what, uint256 _startTime, uint256 _start, uint256 _end, uint256 _duration) public returns (address) {
1091+
address lerp = LerpFactoryLike(lerpFab()).newLerp(_name, _target, _what, _startTime, _start, _end, _duration);
1092+
Authorizable(_target).rely(lerp);
1093+
LerpLike(lerp).tick();
1094+
return lerp;
1095+
}
1096+
/**
1097+
@dev Initiate linear interpolation on an administrative value over time.
1098+
@param _name The label for this lerp instance
1099+
@param _target The target contract
1100+
@param _ilk The ilk to target
1101+
@param _what The target parameter to adjust
1102+
@param _startTime The time for this lerp
1103+
@param _start The start value for the target parameter
1104+
@param _end The end value for the target parameter
1105+
@param _duration The duration of the interpolation
1106+
*/
1107+
function linearInterpolation(bytes32 _name, address _target, bytes32 _ilk, bytes32 _what, uint256 _startTime, uint256 _start, uint256 _end, uint256 _duration) public returns (address) {
1108+
address lerp = LerpFactoryLike(lerpFab()).newIlkLerp(_name, _target, _ilk, _what, _startTime, _start, _end, _duration);
1109+
Authorizable(_target).rely(lerp);
1110+
LerpLike(lerp).tick();
1111+
return lerp;
1112+
}
10661113
}

src/test/DssAction.t.sol

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ import {MkrAuthority} from "mkr-authority/MkrAuthority.sol";
3030
import {IlkRegistry} from "ilk-registry/IlkRegistry.sol";
3131
import {ClipperMom} from "clipper-mom/ClipperMom.sol";
3232
import {Median} from "median/median.sol";
33-
import {OSM} from "osm/osm.sol";
33+
import {OSM} from 'osm/osm.sol';
34+
import {OsmAbstract,
35+
LerpAbstract} from "dss-interfaces/Interfaces.sol";
3436
import {UNIV2LPOracle} from "univ2-lp-oracle/UNIV2LPOracle.sol";
35-
import {OsmAbstract} from "dss-interfaces/Interfaces.sol";
3637
import {DSProxyFactory,
3738
DSProxy} from "ds-proxy/proxy.sol";
3839
import {DssAutoLine} from "dss-auto-line/DssAutoLine.sol";
40+
import {LerpFactory} from "dss-lerp/LerpFactory.sol";
3941

4042
import {Vat} from "dss/vat.sol";
4143
import {Dog} from "dss/dog.sol";
@@ -95,6 +97,7 @@ contract ActionTest is DSTest {
9597
ClipperMom clipperMom;
9698
MkrAuthority govGuard;
9799
DssAutoLine autoLine;
100+
LerpFactory lerpFab;
98101

99102
ChainLog clog;
100103

@@ -272,6 +275,8 @@ contract ActionTest is DSTest {
272275
autoLine = new DssAutoLine(address(vat));
273276
vat.rely(address(autoLine));
274277

278+
lerpFab = new LerpFactory();
279+
275280
median = new Median();
276281

277282
hevm.store(
@@ -297,6 +302,7 @@ contract ActionTest is DSTest {
297302
clog.setAddress("GOV_GUARD", address(govGuard));
298303
clog.setAddress("CLIPPER_MOM", address(clipperMom));
299304
clog.setAddress("MCD_IAM_AUTO_LINE", address(autoLine));
305+
clog.setAddress("LERP_FAB", address(lerpFab));
300306

301307
action = new DssTestAction();
302308

@@ -315,6 +321,7 @@ contract ActionTest is DSTest {
315321
median.rely(address(action));
316322
clog.rely(address(action));
317323
autoLine.rely(address(action));
324+
lerpFab.rely(address(action));
318325

319326
clipperMom.setOwner(address(action));
320327
osmMom.setOwner(address(action));
@@ -1038,14 +1045,12 @@ contract ActionTest is DSTest {
10381045
function test_addNewCollateral_case6() public {
10391046
collateralOnboardingTest(false, false, false); // Liquidations: OFF, PIP != OSM, osmSrc != median
10401047
}
1041-
10421048
function test_officeHoursCanOverrideInAction() public {
10431049
DssTestNoOfficeHoursAction actionNoOfficeHours = new DssTestNoOfficeHoursAction();
10441050
actionNoOfficeHours.execute();
10451051
assertTrue(!actionNoOfficeHours.officeHours());
10461052
}
10471053

1048-
10491054
/***************/
10501055
/*** Payment ***/
10511056
/***************/
@@ -1067,4 +1072,35 @@ contract ActionTest is DSTest {
10671072
assertEq(vat.dai(address(vow)), 0);
10681073
assertEq(vat.sin(address(vow)), 100 * RAD);
10691074
}
1075+
1076+
/************/
1077+
/*** Misc ***/
1078+
/************/
1079+
1080+
function test_lerp_Line() public {
1081+
LerpAbstract lerp = LerpAbstract(action.linearInterpolation_test("myLerp001", address(vat), "Line", block.timestamp, rad(2400 ether), rad(0 ether), 1 days));
1082+
assertEq(lerp.what(), "Line");
1083+
assertEq(lerp.start(), rad(2400 ether));
1084+
assertEq(lerp.end(), rad(0 ether));
1085+
assertEq(lerp.duration(), 1 days);
1086+
assertTrue(!lerp.done());
1087+
assertEq(lerp.startTime(), block.timestamp);
1088+
assertEq(vat.Line(), rad(2400 ether));
1089+
hevm.warp(now + 1 hours);
1090+
assertEq(vat.Line(), rad(2400 ether));
1091+
lerp.tick();
1092+
assertEq(vat.Line(), rad(2300 ether + 1600)); // Small amount at the end is rounding errors
1093+
hevm.warp(now + 1 hours);
1094+
lerp.tick();
1095+
assertEq(vat.Line(), rad(2200 ether + 800));
1096+
hevm.warp(now + 6 hours);
1097+
lerp.tick();
1098+
assertEq(vat.Line(), rad(1600 ether + 800));
1099+
hevm.warp(now + 1 days);
1100+
assertEq(vat.Line(), rad(1600 ether + 800));
1101+
lerp.tick();
1102+
assertEq(vat.Line(), rad(0 ether));
1103+
assertTrue(lerp.done());
1104+
assertEq(vat.wards(address(lerp)), 0);
1105+
}
10701106
}

src/test/DssTestAction.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,14 @@ contract DssTestAction is DssAction {
351351
DssExecLib.sendPaymentFromSurplusBuffer(target, amount);
352352
}
353353

354+
/************/
355+
/*** Misc ***/
356+
/************/
357+
function linearInterpolation_test(bytes32 _name, address _target, bytes32 _what, uint256 _startTime, uint256 _start, uint256 _end, uint256 _duration) public returns (address) {
358+
return DssExecLib.linearInterpolation(_name, _target, _what, _startTime, _start, _end, _duration);
359+
}
360+
function linearInterpolation_test(bytes32 _name, address _target, bytes32 _ilk, bytes32 _what, uint256 _startTime, uint256 _start, uint256 _end, uint256 _duration) public returns (address) {
361+
return DssExecLib.linearInterpolation(_name, _target, _ilk, _what, _startTime, _start, _end, _duration);
362+
}
363+
354364
}

0 commit comments

Comments
 (0)