Skip to content

Commit

Permalink
Handle review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oldchili committed Nov 20, 2024
1 parent 6b6a887 commit b0902e8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
5 changes: 2 additions & 3 deletions deploy/SkyDeploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ library SkyDeploy {
}

function deploySupplySync(
address mkr,
address sky,
address mkrSky,
address owner
) internal returns (address supplySync) {
supplySync = address(new SupplySync(mkr, sky, owner));
supplySync = address(new SupplySync(mkrSky, owner));
}
}
6 changes: 4 additions & 2 deletions deploy/SkyInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface MkrSkyLike {
interface SupplySyncLike {
function mkr() external view returns (address);
function sky() external view returns (address);
function rate() external view returns (uint256);
}

interface MkrLike {
Expand Down Expand Up @@ -67,8 +68,9 @@ library SkyInit {
) internal {
SkyLike sky = SkyLike(dss.chainlog.getAddress("SKY"));

require(SupplySyncLike(supplySync).mkr() == dss.chainlog.getAddress("MCD_GOV"), "SkyInit/mkr-does-not-match");
require(SupplySyncLike(supplySync).sky() == address(sky), "SkyInit/sky-does-not-match");
require(SupplySyncLike(supplySync).mkr() == dss.chainlog.getAddress("MCD_GOV"), "SkyInit/mkr-does-not-match");
require(SupplySyncLike(supplySync).sky() == address(sky), "SkyInit/sky-does-not-match");
require(SupplySyncLike(supplySync).rate() == 24_000, "SkyInit/rate-does-not-match");
require(sky.allowance(supplySync, dss.chainlog.getAddress("MCD_PAUSE_PROXY")) == type(uint256).max, "SkyInit/allowance-not-set");

sky.rely(supplySync);
Expand Down
18 changes: 13 additions & 5 deletions src/SupplySync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/// MkrSky.sol -- Mkr/Sky Exchanger

// Copyright (C) 2023 Dai Foundation
// Copyright (C) 2024 Dai Foundation
//
// 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
Expand All @@ -27,20 +27,28 @@ interface GemLike {
function burn(address, uint256) external;
}

interface MkrSkyLike {
function mkr() external view returns (address);
function sky() external view returns (address);
function rate() external view returns (uint256);
}

contract SupplySync {
GemLike public immutable mkr;
GemLike public immutable sky;
uint256 public immutable rate;

constructor(address mkr_, address sky_, address owner) {
mkr = GemLike(mkr_);
sky = GemLike(sky_);
constructor(address mkrSky, address owner) {
mkr = GemLike(MkrSkyLike(mkrSky).mkr());
sky = GemLike(MkrSkyLike(mkrSky).sky());
rate = MkrSkyLike(mkrSky).rate();

// Allow owner (pause proxy) to burn the sky in this contract, if ever needed to wind down
sky.approve(owner, type(uint256).max);
}

function sync() external {
uint256 mkrSupplyInSky = mkr.totalSupply() * 24_000;
uint256 mkrSupplyInSky = mkr.totalSupply() * rate;
uint256 skyBalance = sky.balanceOf(address(this));

unchecked {
Expand Down
20 changes: 17 additions & 3 deletions test/integration/SupplySync.t.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
// SPDX-FileCopyrightText: © 2024 Dai Foundation <www.daifoundation.org>
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// 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.8.21;

Expand All @@ -16,7 +30,6 @@ interface GemLike {

interface SkyLike is GemLike {
function wards(address) external view returns (uint256);
function rely(address) external;
function deny(address) external;
}

Expand All @@ -38,7 +51,7 @@ contract SupplySyncTest is DssTest {
MKR = GemLike(dss.chainlog.getAddress("MCD_GOV"));
SKY = SkyLike(dss.chainlog.getAddress("SKY"));

sync = SupplySync(SkyDeploy.deploySupplySync(address(MKR), address(SKY), PAUSE_PROXY));
sync = SupplySync(SkyDeploy.deploySupplySync(dss.chainlog.getAddress("MKR_SKY"), PAUSE_PROXY));
vm.startPrank(PAUSE_PROXY);
SkyInit.initSupplySync(dss, address(sync));
vm.stopPrank();
Expand All @@ -47,6 +60,7 @@ contract SupplySyncTest is DssTest {
function testDeployAndInit() public {
assertEq(address(sync.mkr()), address(MKR));
assertEq(address(sync.sky()), address(SKY));
assertEq(sync.rate(), 24_000);
assertEq(SKY.allowance(address(sync), PAUSE_PROXY), type(uint256).max);
assertEq(SKY.wards(address(sync)), 1);
assertEq(dss.chainlog.getAddress("SKY_SUPPLY_SYNC"), address(sync));
Expand All @@ -71,7 +85,7 @@ contract SupplySyncTest is DssTest {
}
}

function testSZeroSkyInSync() public {
function testZeroSkyInSync() public {
deal(address(SKY), address(sync), 0);
_checkSync(true, MKR.totalSupply() * 24_000);
}
Expand Down

0 comments on commit b0902e8

Please sign in to comment.