Skip to content

Commit

Permalink
Merge pull request #41 from makerdao/sc-2091-offboarded-collateral
Browse files Browse the repository at this point in the history
Offboard collateral
  • Loading branch information
jar-o authored May 2, 2023
2 parents 3be06fc + 9f50b10 commit b9881a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 63 deletions.
23 changes: 4 additions & 19 deletions src/MegaPoker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ contract PokingAddresses {
// OSMs and Spotter addresses
address constant eth = 0x81FE72B5A8d1A857d176C3E7d5Bd2679A9B85763;
address constant btc = 0xf185d0682d50819263941e5f4EacC763CC5C6C42;
address constant mana = 0x8067259EA630601f319FccE477977E55C6078C13;
address constant link = 0x9B0C694C6939b5EA9584e9b61C7815E8d97D9cC7;
address constant yfi = 0x5F122465bCf86F45922036970Be6DD7F58820214;
address constant univ2usdceth = 0xf751f24DD9cfAd885984D1bA68860F558D21E52A;
address constant univ2daiusdc = 0x25D03C2C928ADE19ff9f4FFECc07d991d0df054B;
address constant matic = 0x8874964279302e6d4e523Fb1789981C39a1034Ba;
address constant wsteth = 0xFe7a2aC0B945f12089aEEB6eCebf4F384D9f043F;
address constant crvv1ethsteth = 0xEa508F82728927454bd3ce853171b0e2705880D4;
address constant guniv3daiusdc1 = 0x7F6d78CC0040c87943a0e0c140De3F77a273bd58;
Expand All @@ -47,12 +42,6 @@ contract MegaPoker is PokingAddresses {
// poke() = 0x18178358
(ok,) = eth.call(abi.encodeWithSelector(0x18178358));
(ok,) = btc.call(abi.encodeWithSelector(0x18178358));
(ok,) = mana.call(abi.encodeWithSelector(0x18178358));
(ok,) = link.call(abi.encodeWithSelector(0x18178358));
(ok,) = yfi.call(abi.encodeWithSelector(0x18178358));
(ok,) = univ2usdceth.call(abi.encodeWithSelector(0x18178358));
(ok,) = univ2daiusdc.call(abi.encodeWithSelector(0x18178358));
(ok,) = matic.call(abi.encodeWithSelector(0x18178358));
(ok,) = wsteth.call(abi.encodeWithSelector(0x18178358));
(ok,) = crvv1ethsteth.call(abi.encodeWithSelector(0x18178358));
(ok,) = reth.call(abi.encodeWithSelector(0x18178358));
Expand All @@ -62,15 +51,8 @@ contract MegaPoker is PokingAddresses {
// poke(bytes32) = 0x1504460f
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("ETH-A")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("WBTC-A")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("MANA-A")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("LINK-A")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("ETH-B")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("YFI-A")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("RENBTC-A")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("UNIV2USDCETH-A")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("UNIV2DAIUSDC-A")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("ETH-C")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("MATIC-A")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("WSTETH-A")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("WSTETH-B")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("CRVV1ETHSTETH-A")));
Expand All @@ -83,15 +65,18 @@ contract MegaPoker is PokingAddresses {
// Daily pokes
// Reduced cost pokes
if (last <= block.timestamp - 1 days) {

// poke
// The GUINIV3DAIUSDCX Oracles are very expensive to poke, and the price should not
// change frequently, so they are getting poked only once a day.
(ok,) = guniv3daiusdc1.call(abi.encodeWithSelector(0x18178358));
(ok,) = guniv3daiusdc2.call(abi.encodeWithSelector(0x18178358));

(ok,) = univ2daiusdc.call(abi.encodeWithSelector(0x18178358));

// spotter.poke
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("GUNIV3DAIUSDC1-A")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("GUNIV3DAIUSDC2-A")));
(ok,) = spotter.call(abi.encodeWithSelector(0x1504460f, bytes32("UNIV2DAIUSDC-A")));

last = block.timestamp;
}
Expand Down
49 changes: 5 additions & 44 deletions src/MegaPoker.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,7 @@ contract MegaPokerTest is DSTest, PokingAddresses {
bytes32 hackedValue = 0x0000000000000000000000000000000100000000000000000000000000000123;
hevm.store(eth, bytes32(uint256(4)), hackedValue);
hevm.store(btc, bytes32(uint256(4)), hackedValue);
hevm.store(mana, bytes32(uint256(4)), hackedValue);
hevm.store(link, bytes32(uint256(4)), hackedValue);
hevm.store(yfi, bytes32(uint256(4)), hackedValue);
hevm.store(univ2usdceth, bytes32(uint256(4)), hackedValue);
hevm.store(univ2daiusdc, bytes32(uint256(4)), hackedValue);
hevm.store(matic, bytes32(uint256(4)), hackedValue);
hevm.store(wsteth, bytes32(uint256(4)), hackedValue);
hevm.store(crvv1ethsteth, bytes32(uint256(4)), hackedValue);
hevm.store(guniv3daiusdc1, bytes32(uint256(4)), hackedValue);
Expand All @@ -184,12 +179,7 @@ contract MegaPokerTest is DSTest, PokingAddresses {
// Whitelisting tester address
hevm.store(eth, keccak256(abi.encode(address(this), uint256(5))), bytes32(uint256(1)));
hevm.store(btc, keccak256(abi.encode(address(this), uint256(5))), bytes32(uint256(1)));
hevm.store(mana, keccak256(abi.encode(address(this), uint256(5))), bytes32(uint256(1)));
hevm.store(link, keccak256(abi.encode(address(this), uint256(5))), bytes32(uint256(1)));
hevm.store(yfi, keccak256(abi.encode(address(this), uint256(5))), bytes32(uint256(1)));
hevm.store(univ2usdceth, keccak256(abi.encode(address(this), uint256(2))), bytes32(uint256(1)));
hevm.store(univ2daiusdc, keccak256(abi.encode(address(this), uint256(2))), bytes32(uint256(1)));
hevm.store(matic, keccak256(abi.encode(address(this), uint256(5))), bytes32(uint256(1)));
hevm.store(wsteth, keccak256(abi.encode(address(this), uint256(5))), bytes32(uint256(1)));
hevm.store(reth, keccak256(abi.encode(address(this), uint256(5))), bytes32(uint256(1)));
hevm.store(gno, keccak256(abi.encode(address(this), uint256(5))), bytes32(uint256(1)));
Expand All @@ -202,31 +192,20 @@ contract MegaPokerTest is DSTest, PokingAddresses {

assertTrue(OsmLike(eth).read() != hackedValue);
assertTrue(OsmLike(btc).read() != hackedValue);
assertTrue(OsmLike(mana).read() != hackedValue);
assertTrue(OsmLike(link).read() != hackedValue);
assertTrue(OsmLike(yfi).read() != hackedValue);
assertTrue(OsmLike(univ2usdceth).read() != hackedValue);
assertTrue(OsmLike(univ2daiusdc).read() != hackedValue);
assertTrue(OsmLike(matic).read() != hackedValue);
assertTrue(OsmLike(wsteth).read() != hackedValue);
assertTrue(OsmLike(crvv1ethsteth).read() != hackedValue);
assertTrue(OsmLike(reth).read() != hackedValue);
assertTrue(OsmLike(gno).read() != hackedValue);

assertTrue(OsmLike(guniv3daiusdc1).read() != hackedValue);
assertTrue(OsmLike(guniv3daiusdc2).read() != hackedValue);
assertTrue(OsmLike(univ2daiusdc).read() != hackedValue);

hevm.warp(block.timestamp + 1 hours);
megaPoker.poke();

assertEq(OsmLike(eth).read(), hackedValue);
assertEq(OsmLike(btc).read(), hackedValue);
assertEq(OsmLike(mana).read(), hackedValue);
assertEq(OsmLike(link).read(), hackedValue);
assertEq(OsmLike(yfi).read(), hackedValue);
assertEq(OsmLike(univ2usdceth).read(), hackedValue);
assertEq(OsmLike(univ2daiusdc).read(), hackedValue);
assertEq(OsmLike(matic).read(), hackedValue);
assertEq(OsmLike(wsteth).read(), hackedValue);
assertEq(OsmLike(crvv1ethsteth).read(), hackedValue);
assertEq(OsmLike(reth).read(), hackedValue);
Expand All @@ -235,6 +214,7 @@ contract MegaPokerTest is DSTest, PokingAddresses {
// Daily OSM's are not updated after one hour
assertTrue(OsmLike(guniv3daiusdc1).read() != hackedValue);
assertTrue(OsmLike(guniv3daiusdc2).read() != hackedValue);
assertTrue(OsmLike(univ2daiusdc).read() != hackedValue);

uint256 mat;
uint256 spot;
Expand All @@ -247,33 +227,12 @@ contract MegaPokerTest is DSTest, PokingAddresses {
(, mat) = SpotLike(spotter).ilks("WBTC-A");
(,, spot,,) = VatLike(vat).ilks("WBTC-A");
assertEq(spot, _rdiv(value, mat));
(, mat) = SpotLike(spotter).ilks("MANA-A");
(,, spot,,) = VatLike(vat).ilks("MANA-A");
assertEq(spot, _rdiv(value, mat));
(, mat) = SpotLike(spotter).ilks("LINK-A");
(,, spot,,) = VatLike(vat).ilks("LINK-A");
assertEq(spot, _rdiv(value, mat));
(, mat) = SpotLike(spotter).ilks("ETH-B");
(,, spot,,) = VatLike(vat).ilks("ETH-B");
assertEq(spot, _rdiv(value, mat));
(, mat) = SpotLike(spotter).ilks("YFI-A");
(,, spot,,) = VatLike(vat).ilks("YFI-A");
assertEq(spot, _rdiv(value, mat));
(, mat) = SpotLike(spotter).ilks("RENBTC-A");
(,, spot,,) = VatLike(vat).ilks("RENBTC-A");
assertEq(spot, _rdiv(value, mat));
(, mat) = SpotLike(spotter).ilks("UNIV2USDCETH-A");
(,, spot,,) = VatLike(vat).ilks("UNIV2USDCETH-A");
assertEq(spot, _rdiv(value, mat));
(, mat) = SpotLike(spotter).ilks("UNIV2DAIUSDC-A");
(,, spot,,) = VatLike(vat).ilks("UNIV2DAIUSDC-A");
assertEq(spot, _rdiv(value, mat));
(, mat) = SpotLike(spotter).ilks("ETH-C");
(,, spot,,) = VatLike(vat).ilks("ETH-C");
assertEq(spot, _rdiv(value, mat));
(, mat) = SpotLike(spotter).ilks("MATIC-A");
(,, spot,,) = VatLike(vat).ilks("MATIC-A");
assertEq(spot, _rdiv(value, mat));
(, mat) = SpotLike(spotter).ilks("WSTETH-A");
(,, spot,,) = VatLike(vat).ilks("WSTETH-A");
assertEq(spot, _rdiv(value, mat));
Expand Down Expand Up @@ -303,7 +262,9 @@ contract MegaPokerTest is DSTest, PokingAddresses {
(, mat) = SpotLike(spotter).ilks("GUNIV3DAIUSDC2-A");
(,, spot,,) = VatLike(vat).ilks("GUNIV3DAIUSDC2-A");
assertTrue(spot != _rdiv(value, mat));

(, mat) = SpotLike(spotter).ilks("UNIV2DAIUSDC-A");
(,, spot,,) = VatLike(vat).ilks("UNIV2DAIUSDC-A");
assertTrue(spot != _rdiv(value, mat));

// Daily OSM's are eligible 24 hours after first poked
hevm.warp(megaPoker.last() + 24 hours);
Expand Down

0 comments on commit b9881a8

Please sign in to comment.