Skip to content

Commit

Permalink
Supply sync implemenation
Browse files Browse the repository at this point in the history
  • Loading branch information
oldchili committed Nov 19, 2024
1 parent 72905f4 commit 936569d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ It is a converter between `Mkr` and `Sky` (both ways). Using the `mint` and `bur
**Note:** if one of the tokens removes `mint` capabilities to this contract, it means that the path which gives that token to the user won't be available.

**Note 2:** In the MKR -> SKY conversion, if the user passes a `wad` amount not multiple of `rate`, it causes that a dusty value will be lost.

### SupplySync

A contract with permissionless functionality that syncs the SKY supply to include also the MKR supply (thus MKR acts as wrapper of SKY).
9 changes: 9 additions & 0 deletions deploy/SkyDeploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ScriptTools } from "dss-test/ScriptTools.sol";

import { Sky } from "src/Sky.sol";
import { MkrSky } from "src/MkrSky.sol";
import { SupplySync } from "src/SupplySync.sol";

import { SkyInstance } from "./SkyInstance.sol";

Expand All @@ -46,4 +47,12 @@ library SkyDeploy {
sky = address(new Sky());
ScriptTools.switchOwner(sky, deployer, owner);
}

function deploySupplySync(
address mkr,
address sky,
address owner
) internal returns (address supplySync) {
supplySync = address(new SupplySync(mkr, sky, owner));
}
}
20 changes: 20 additions & 0 deletions deploy/SkyInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { SkyInstance } from "./SkyInstance.sol";

interface SkyLike {
function rely(address) external;
function allowance(address, address) external view returns (uint256);
}

interface MkrSkyLike {
Expand All @@ -29,6 +30,11 @@ interface MkrSkyLike {
function rate() external view returns (uint256);
}

interface SupplySyncLike {
function mkr() external view returns (address);
function sky() external view returns (address);
}

interface MkrLike {
function authority() external view returns (address);
}
Expand All @@ -54,4 +60,18 @@ library SkyInit {
dss.chainlog.setAddress("SKY", instance.sky);
dss.chainlog.setAddress("MKR_SKY", instance.mkrSky);
}

function initSupplySync(
DssInstance memory dss,
address supplySync
) 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(sky.allowance(supplySync, dss.chainlog.getAddress("MCD_PAUSE_PROXY")) == type(uint256).max, "SkyInit/allowance-not-set");

sky.rely(supplySync);
dss.chainlog.setAddress("SKY_SUPPLY_SYNC", supplySync);
}
}
54 changes: 54 additions & 0 deletions src/SupplySync.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

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

// Copyright (C) 2023 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
// 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;

interface GemLike {
function totalSupply() external view returns (uint256);
function balanceOf(address) external view returns (uint256);
function approve(address, uint256) external;
function mint(address, uint256) external;
function burn(address, uint256) external;
}

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

constructor(address mkr_, address sky_, address owner) {
mkr = GemLike(mkr_);
sky = GemLike(sky_);

// 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 skyBalance = sky.balanceOf(address(this));

unchecked {
if (mkrSupplyInSky > skyBalance) {
sky.mint(address(this), mkrSupplyInSky - skyBalance);
} else {
sky.burn(address(this), skyBalance - mkrSupplyInSky);
}
}
}
}

0 comments on commit 936569d

Please sign in to comment.