Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIP-41: send pol directly to StakeManager #61

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions script/1.3.0/UpgradeEmissionManager.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

import {Script, stdJson, console2 as console} from "forge-std/Script.sol";

import {
ProxyAdmin,
TransparentUpgradeableProxy,
ITransparentUpgradeableProxy
} from "openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol";
import {DefaultEmissionManager} from "../../src/DefaultEmissionManager.sol";

contract UpgradeEmissionManager is Script {
using stdJson for string;

function run() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");

string memory input = vm.readFile("script/1.2.0/input.json");
string memory chainIdSlug = string(abi.encodePacked('["', vm.toString(block.chainid), '"]'));
address emProxyAddress = input.readAddress(string.concat(chainIdSlug, ".emissionManagerProxy"));
address emProxyAdmin = input.readAddress(string.concat(chainIdSlug, ".emProxyAdmin"));

vm.startBroadcast(deployerPrivateKey);

DefaultEmissionManager emProxy = DefaultEmissionManager(emProxyAddress);

address migration = address(emProxy.migration());
address stakeManager = emProxy.stakeManager();
address treasury = emProxy.treasury();

DefaultEmissionManager newEmImpl = new DefaultEmissionManager(migration, stakeManager, treasury);

vm.stopBroadcast();

bytes memory payload = abi.encodeWithSelector(
ProxyAdmin.upgrade.selector,
ITransparentUpgradeableProxy(address(emProxy)),
address(newEmImpl)
);

console.log("Send this payload to: ", emProxyAdmin);
console.logBytes(payload);
}
}
10 changes: 10 additions & 0 deletions script/1.3.0/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"1": {
"emissionManagerProxy": "0xbC9f74b3b14f460a6c47dCdDFd17411cBc7b6c53",
"emProxyAdmin": "0xEBea33f2c92D03556b417F4F572B2FbbE62C39c3"
},
"11155111": {
"emissionManagerProxy": "0x20393fF3B3C38b72a16eB7d7A474cd38ABD8Ff27",
"emProxyAdmin": "0x28cDCE6FfE44D03da1F7b15b474a0e72243873F2"
}
}
7 changes: 4 additions & 3 deletions src/DefaultEmissionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ contract DefaultEmissionManager is Ownable2StepUpgradeable, IDefaultEmissionMana

IPolygonEcosystemToken _token = token;
_token.mint(address(this), amountToMint);

_token.safeTransfer(treasury, treasuryAmt);
// backconvert POL to MATIC before sending to StakeManager
migration.unmigrateTo(stakeManager, stakeManagerAmt);

_token.safeTransfer(stakeManager, stakeManagerAmt);
}

/// @inheritdoc IDefaultEmissionManager
Expand All @@ -91,7 +92,7 @@ contract DefaultEmissionManager is Ownable2StepUpgradeable, IDefaultEmissionMana

/// @inheritdoc IDefaultEmissionManager
function version() external pure returns (string memory) {
return "1.2.0";
return "1.3.0";
}

uint256[47] private __gap;
Expand Down
14 changes: 7 additions & 7 deletions test/DefaultEmissionManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ contract DefaultEmissionManagerTest is Test {
assertApproxEqAbs(newSupply, polygon.totalSupply(), _MAX_PRECISION_DELTA);
uint256 totalAmtMinted = polygon.totalSupply() - initialTotalSupply;
uint256 totalAmtMintedTwoFifth = totalAmtMinted * 2 / 5;
assertEq(matic.balanceOf(stakeManager), totalAmtMinted - totalAmtMintedTwoFifth);
assertEq(polygon.balanceOf(stakeManager), totalAmtMinted - totalAmtMintedTwoFifth);
assertEq(polygon.balanceOf(treasury), totalAmtMintedTwoFifth);
}

Expand All @@ -167,8 +167,8 @@ contract DefaultEmissionManagerTest is Test {
assertApproxEqAbs(newSupply, polygon.totalSupply(), _MAX_PRECISION_DELTA);
uint256 balance = (polygon.totalSupply() - initialTotalSupply) * 2 / 5;
uint256 stakeManagerBalance = (polygon.totalSupply() - initialTotalSupply) - balance;
assertEq(matic.balanceOf(stakeManager), stakeManagerBalance);
assertEq(polygon.balanceOf(stakeManager), 0);
assertEq(polygon.balanceOf(stakeManager), stakeManagerBalance);
assertEq(matic.balanceOf(stakeManager), 0);
assertEq(polygon.balanceOf(treasury), balance);

skip(delay);
Expand All @@ -185,8 +185,8 @@ contract DefaultEmissionManagerTest is Test {
balance = totalAmtMintedTwoFifth;
stakeManagerBalance = totalAmtMinted - totalAmtMintedTwoFifth;

assertEq(matic.balanceOf(stakeManager), stakeManagerBalance);
assertEq(polygon.balanceOf(stakeManager), 0);
assertEq(polygon.balanceOf(stakeManager), stakeManagerBalance);
assertEq(matic.balanceOf(stakeManager), 0);
assertEq(polygon.balanceOf(treasury), balance);
}

Expand All @@ -213,8 +213,8 @@ contract DefaultEmissionManagerTest is Test {
balance = totalAmtMintedTwoFifth;
stakeManagerBalance = totalAmtMinted - totalAmtMintedTwoFifth;

assertEq(matic.balanceOf(stakeManager), stakeManagerBalance);
assertEq(polygon.balanceOf(stakeManager), 0);
assertEq(polygon.balanceOf(stakeManager), stakeManagerBalance);
assertEq(matic.balanceOf(stakeManager), 0);
assertEq(polygon.balanceOf(treasury), balance);
}
}
Expand Down
79 changes: 0 additions & 79 deletions test/upgrade/DefaultEmissionManager.1.2.0.sepolia.t.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract DefaultEmissionManagerTestMainnet is Test {

address POLYGON_PROTOCOL_COUNCIL = 0x37D085ca4a24f6b29214204E8A8666f12cf19516;
address EM_PROXY = 0xbC9f74b3b14f460a6c47dCdDFd17411cBc7b6c53;
address COMMUNITY_TREASURY = 0x2ff25495d77f380d5F65B95F103181aE8b1cf898;
address COMMUNITY_TREASURY = 0x86380e136A3AaD5677A210Ad02713694c4E6a5b9;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we rename it as DAO @simonDos ?

address EM_PROXY_ADMIN = 0xEBea33f2c92D03556b417F4F572B2FbbE62C39c3;
PolygonEcosystemToken pol = PolygonEcosystemToken(0x455e53CBB86018Ac2B8092FdCd39d8444aFFC3F6);

Expand All @@ -34,46 +34,23 @@ contract DefaultEmissionManagerTestMainnet is Test {
function testUpgrade() external {
vm.selectFork(mainnetFork);

address newTreasury = makeAddr("newTreasury");

DefaultEmissionManager emProxy = DefaultEmissionManager(EM_PROXY);

assertEq(emProxy.treasury(), COMMUNITY_TREASURY);

address migration = address(emProxy.migration());
address stakeManager = emProxy.stakeManager();
address treasury = emProxy.treasury();

DefaultEmissionManager newEmImpl = new DefaultEmissionManager(migration, stakeManager, newTreasury);
DefaultEmissionManager newEmImpl = new DefaultEmissionManager(migration, stakeManager, treasury);

ProxyAdmin admin = ProxyAdmin(EM_PROXY_ADMIN);

vm.prank(POLYGON_PROTOCOL_COUNCIL);

admin.upgradeAndCall(
admin.upgrade(
ITransparentUpgradeableProxy(address(emProxy)),
address(newEmImpl),
abi.encodeWithSelector(DefaultEmissionManager.reinitialize.selector)
address(newEmImpl)
);

// initialize can still not be called
vm.expectRevert("Initializable: contract is already initialized");
emProxy.initialize(makeAddr("token"), msg.sender);

assertEq(pol.totalSupply(), emProxy.START_SUPPLY_1_2_0());
assertEq(block.timestamp, emProxy.startTimestamp());

// emission is now 2.5%
inputs[0] = "node";
inputs[1] = "test/util/calc.js";
inputs[2] = vm.toString(uint256(365 days));
inputs[3] = vm.toString(pol.totalSupply());
// vm.ffi executes the js script which contains the new emission rate
uint256 newSupply = abi.decode(vm.ffi(inputs), (uint256));
assertApproxEqAbs(newSupply, emProxy.inflatedSupplyAfter(365 days), 1e20);

// treasury has been updated
assertEq(emProxy.treasury(), newTreasury);
// emission has been updated
assertEq(emProxy.INTEREST_PER_YEAR_LOG2(), NEW_INTEREST_PER_YEAR_LOG2);
}
}
Loading