diff --git a/src/SupplySync.sol b/src/SupplySync.sol index 4ba5466..df56a1e 100644 --- a/src/SupplySync.sol +++ b/src/SupplySync.sol @@ -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); } } } diff --git a/test/integration/SupplySync.t.sol b/test/integration/SupplySync.t.sol index 675c6c1..06448fa 100644 --- a/test/integration/SupplySync.t.sol +++ b/test/integration/SupplySync.t.sol @@ -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); @@ -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 {