Skip to content

Commit

Permalink
Add a proxy admin contract
Browse files Browse the repository at this point in the history
  • Loading branch information
gretzke committed Sep 1, 2023
1 parent 4e8eb8a commit b759292
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
9 changes: 6 additions & 3 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.21;

import {Script} from "forge-std/Script.sol";

import {TransparentUpgradeableProxy} from "openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {ProxyAdmin, TransparentUpgradeableProxy} from "openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol";
import {Polygon} from "../src/Polygon.sol";
import {DefaultInflationManager} from "../src/DefaultInflationManager.sol";
import {PolygonMigration} from "../src/PolygonMigration.sol";
Expand All @@ -18,19 +18,22 @@ contract Deploy is Script {
function run(address matic, address governance, address treasury, address stakeManager) public {
vm.startBroadcast(deployerPrivateKey);

ProxyAdmin admin = new ProxyAdmin();
admin.transferOwnership(governance);

address migrationImplementation = address(new PolygonMigration());

address migrationProxy = address(
new TransparentUpgradeableProxy(
migrationImplementation,
governance,
address(admin),
abi.encodeCall(PolygonMigration.initialize, matic)
)
);

address inflationManagerImplementation = address(new DefaultInflationManager());
address inflationManagerProxy = address(
new TransparentUpgradeableProxy(address(inflationManagerImplementation), governance, "")
new TransparentUpgradeableProxy(address(inflationManagerImplementation), address(admin), "")
);

Polygon polygonToken = new Polygon(migrationProxy, inflationManagerProxy);
Expand Down
7 changes: 4 additions & 3 deletions test/DefaultInflationManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Polygon} from "src/Polygon.sol";
import {DefaultInflationManager} from "src/DefaultInflationManager.sol";
import {PolygonMigration} from "src/PolygonMigration.sol";
import {ERC20PresetMinterPauser} from "openzeppelin-contracts/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";
import {TransparentUpgradeableProxy} from "openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {ProxyAdmin, TransparentUpgradeableProxy} from "openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol";
import {Test} from "forge-std/Test.sol";

contract DefaultInflationManagerTest is Test {
Expand All @@ -30,12 +30,13 @@ contract DefaultInflationManagerTest is Test {
stakeManager = makeAddr("stakeManager");
governance = makeAddr("governance");
inflationManagerImplementation = new DefaultInflationManager();
ProxyAdmin admin = new ProxyAdmin();
inflationManager = DefaultInflationManager(
address(new TransparentUpgradeableProxy(address(inflationManagerImplementation), msg.sender, ""))
address(new TransparentUpgradeableProxy(address(inflationManagerImplementation), address(admin), ""))
);
matic = new ERC20PresetMinterPauser("Matic Token", "MATIC");
migration = PolygonMigration(
address(new TransparentUpgradeableProxy(address(new PolygonMigration()), msg.sender, ""))
address(new TransparentUpgradeableProxy(address(new PolygonMigration()), address(admin), ""))
);
migration.initialize(address(matic));
polygon = new Polygon(address(migration), address(inflationManager));
Expand Down
5 changes: 3 additions & 2 deletions test/Polygon.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.21;
import {Polygon} from "src/Polygon.sol";
import {IPolygon} from "src/interfaces/IPolygon.sol";
import {DefaultInflationManager} from "src/DefaultInflationManager.sol";
import {TransparentUpgradeableProxy} from "openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {TransparentUpgradeableProxy, ProxyAdmin} from "openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol";
import {Test} from "forge-std/Test.sol";

contract PolygonTest is Test {
Expand All @@ -21,8 +21,9 @@ contract PolygonTest is Test {
treasury = makeAddr("treasury");
stakeManager = makeAddr("stakeManager");
matic = makeAddr("matic");
ProxyAdmin admin = new ProxyAdmin();
inflationManager = DefaultInflationManager(
address(new TransparentUpgradeableProxy(address(new DefaultInflationManager()), msg.sender, ""))
address(new TransparentUpgradeableProxy(address(new DefaultInflationManager()), address(admin), ""))
);
polygon = new Polygon(migration, address(inflationManager));
inflationManager.initialize(address(polygon), migration, stakeManager, treasury, msg.sender);
Expand Down
7 changes: 5 additions & 2 deletions test/PolygonMigration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Polygon} from "src/Polygon.sol";
import {PolygonMigration} from "src/PolygonMigration.sol";
import {IPolygonMigration} from "src/interfaces/IPolygonMigration.sol";
import {ERC20PresetMinterPauser} from "openzeppelin-contracts/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";
import {TransparentUpgradeableProxy} from "openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {TransparentUpgradeableProxy, ProxyAdmin} from "openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol";
import {SigUtils} from "test/SigUtils.t.sol";
import {Test} from "forge-std/Test.sol";

Expand All @@ -14,6 +14,7 @@ contract PolygonMigrationTest is Test {
Polygon public polygon;
PolygonMigration public migration;
SigUtils public sigUtils;
ProxyAdmin public admin;
address public treasury;
address public stakeManager;
address public inflationManager;
Expand All @@ -25,11 +26,12 @@ contract PolygonMigrationTest is Test {
inflationManager = makeAddr("inflationManager");
governance = makeAddr("governance");
matic = new ERC20PresetMinterPauser("Matic Token", "MATIC");
admin = new ProxyAdmin();
migration = PolygonMigration(
address(
new TransparentUpgradeableProxy(
address(new PolygonMigration()),
msg.sender,
address(admin),
abi.encodeCall(PolygonMigration.initialize, address(matic))
)
)
Expand Down Expand Up @@ -115,6 +117,7 @@ contract PolygonMigrationTest is Test {
}

function testRevert_Unmigrate(address user, uint256 amount) external {
vm.assume(user != address(admin));
bool unmigrationLock = true;
vm.assume(
amount <= 10000000000 * 10 ** 18 && user != address(0) && user != address(migration) && user != governance
Expand Down

0 comments on commit b759292

Please sign in to comment.