Skip to content

Commit

Permalink
Change to else if and return values
Browse files Browse the repository at this point in the history
  • Loading branch information
oldchili committed Nov 20, 2024
1 parent b0902e8 commit 1a6eb1c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/SupplySync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@ contract SupplySync {
sky.approve(owner, type(uint256).max);
}

function sync() external {
function sync() external returns (bool isMint, uint256 amount) {
uint256 mkrSupplyInSky = mkr.totalSupply() * rate;
uint256 skyBalance = sky.balanceOf(address(this));

unchecked {
if (mkrSupplyInSky > skyBalance) {
sky.mint(address(this), mkrSupplyInSky - skyBalance);
} else {
sky.burn(address(this), skyBalance - mkrSupplyInSky);
isMint = true;
amount = mkrSupplyInSky - skyBalance;
sky.mint(address(this), amount);
} else if (mkrSupplyInSky < skyBalance) {
amount = skyBalance - mkrSupplyInSky;
sky.burn(address(this), amount);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions test/integration/SupplySync.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ contract SupplySyncTest is DssTest {
uint256 skySupplyBefore = SKY.totalSupply();
uint256 syncBalanceBefore = SKY.balanceOf(address(sync));

sync.sync();
(bool isMint, uint256 amount) = sync.sync();

uint256 syncBalanceAfter = SKY.balanceOf(address(sync));

assertEq(syncBalanceAfter, mkrSupply * 24_000);
assertEq(isMint, isExpectedMint);
assertEq(amount, expectedChange);
if (isExpectedMint) {
assertEq(syncBalanceAfter, syncBalanceBefore + expectedChange);
assertEq(SKY.totalSupply(), skySupplyBefore + expectedChange);
Expand All @@ -102,7 +104,7 @@ contract SupplySyncTest is DssTest {

function testExactSkyInSync() public {
deal(address(SKY), address(sync), MKR.totalSupply() * 24_000);
_checkSync(true, 0);
_checkSync(false, 0);
}

function testWindDown() public {
Expand Down

0 comments on commit 1a6eb1c

Please sign in to comment.