From b0902e893d0192d0a50c16e1c6283e06584fadba Mon Sep 17 00:00:00 2001 From: oldchili <130549691+oldchili@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:37:21 +0200 Subject: [PATCH] Handle review comments --- deploy/SkyDeploy.sol | 5 ++--- deploy/SkyInit.sol | 6 ++++-- src/SupplySync.sol | 18 +++++++++++++----- test/integration/SupplySync.t.sol | 20 +++++++++++++++++--- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/deploy/SkyDeploy.sol b/deploy/SkyDeploy.sol index e08f751..bc60fe8 100644 --- a/deploy/SkyDeploy.sol +++ b/deploy/SkyDeploy.sol @@ -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)); } } diff --git a/deploy/SkyInit.sol b/deploy/SkyInit.sol index 3207ba0..3cfadb5 100644 --- a/deploy/SkyInit.sol +++ b/deploy/SkyInit.sol @@ -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 { @@ -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); diff --git a/src/SupplySync.sol b/src/SupplySync.sol index 5d93a35..4ba5466 100644 --- a/src/SupplySync.sol +++ b/src/SupplySync.sol @@ -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 @@ -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 { diff --git a/test/integration/SupplySync.t.sol b/test/integration/SupplySync.t.sol index b30273a..675c6c1 100644 --- a/test/integration/SupplySync.t.sol +++ b/test/integration/SupplySync.t.sol @@ -1,4 +1,18 @@ +// SPDX-FileCopyrightText: © 2024 Dai Foundation // 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 . pragma solidity ^0.8.21; @@ -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; } @@ -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(); @@ -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)); @@ -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); }