Skip to content

Commit

Permalink
Merge pull request #41 from 0xPolygon/feat/deployment-scripts
Browse files Browse the repository at this point in the history
Deployment scripts
  • Loading branch information
gretzke authored Oct 17, 2023
2 parents 0e2dbd2 + a47821b commit 7a1dec2
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 36 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ A default implementation is included and this contract will be proxy upgradable

### Deployment

Forge scripts are used to deploy or upgrade contracts and an additional extract.js script can be used to generate a JSON and Markdown file with coalesced deployment information. (see [deployments](./deployments/))

1. Ensure .env file is set, `cp .env.example`
2. Populate Enviornment variables: `source .env`
3. We use a forge script to deploy the contracts, and have an additional extract.js script to store a JSON file with coalesced deployment information. (see [deployments](./deployments/))
2. `source .env`

3. Deploy using foundry

- (mainnet): `forge script scripts/Deploy.s.sol --broadcast --verify --rpc-url $RPC_URL --private-key $PRIVATE_KEY --etherscan-api-key $ETHERSCAN_API_KEY`
- (testnet, goerli for example): `forge script scripts/Deploy.s.sol --broadcast --verify --rpc-url $RPC_URL --private-key $PRIVATE_KEY --verifier-url https://api-goerli.etherscan.io/api --chain-id 5`
- (mainnet): `forge script scripts/Deploy.s.sol --broadcast --verify --rpc-url $RPC_URL --etherscan-api-key $ETHERSCAN_API_KEY`
- (testnet, goerli for example): `forge script scripts/Deploy.s.sol --broadcast --verify --rpc-url $RPC_URL --verifier-url https://api-goerli.etherscan.io/api --chain-id 5`

4. Run `node scripts/util/extract.js <chainId> [version = 1.0.0] [scriptName = Deploy.s.sol]` to extract deployment information from forge broadcast output (broadcast/latest-run.json).

Expand Down
61 changes: 61 additions & 0 deletions scripts/1.0.0/Deploy.goerli.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

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

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

contract Deploy is Script {
using stdJson for string;

function run() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
string memory input = vm.readFile("scripts/1.0.0/input.json");
string memory chainIdSlug = string(abi.encodePacked('["', vm.toString(block.chainid), '"]'));
address matic = input.readAddress(string.concat(chainIdSlug, ".matic"));
address governance = input.readAddress(string.concat(chainIdSlug, ".governance"));
address treasury = input.readAddress(string.concat(chainIdSlug, ".treasury"));
address stakeManager = input.readAddress(string.concat(chainIdSlug, ".stakeManager"));
address permit2revoker = input.readAddress(string.concat(chainIdSlug, ".permit2revoker"));

vm.startBroadcast(deployerPrivateKey);

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

address migrationImplementation = address(new PolygonMigration(matic));

address migrationProxy = address(
new TransparentUpgradeableProxy(
migrationImplementation,
address(admin),
abi.encodeWithSelector(PolygonMigration.initialize.selector)
)
);

address emissionManagerImplementation = address(
new DefaultEmissionManager(migrationProxy, stakeManager, treasury)
);
address emissionManagerProxy = address(
new TransparentUpgradeableProxy(address(emissionManagerImplementation), address(admin), "")
);

PolygonEcosystemToken polygonToken = new PolygonEcosystemToken(
migrationProxy,
emissionManagerProxy,
governance,
permit2revoker
);

DefaultEmissionManager(emissionManagerProxy).initialize(address(polygonToken), governance);

PolygonMigration(migrationProxy).setPolygonToken(address(polygonToken));

PolygonMigration(migrationProxy).transferOwnership(governance); // governance needs to accept the ownership transfer

vm.stopBroadcast();
}
}
13 changes: 2 additions & 11 deletions scripts/1.0.0/Deploy.s.sol → scripts/1.1.0/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,9 @@ import {PolygonMigration} from "../../src/PolygonMigration.sol";
contract Deploy is Script {
using stdJson for string;

string internal constant TEST_MNEMONIC = "test test test test test test test test test test test junk";
uint256 public deployerPrivateKey;

constructor() {
deployerPrivateKey = vm.envOr({name: "PRIVATE_KEY", defaultValue: uint256(0)});
if (deployerPrivateKey == 0) {
(, deployerPrivateKey) = deriveRememberKey({mnemonic: TEST_MNEMONIC, index: 0});
}
}

function run() public {
string memory input = vm.readFile("scripts/1.0.0/input.json");
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
string memory input = vm.readFile("scripts/1.1.0/input.json");
string memory chainIdSlug = string(abi.encodePacked('["', vm.toString(block.chainid), '"]'));
address matic = input.readAddress(string.concat(chainIdSlug, ".matic"));
address governance = input.readAddress(string.concat(chainIdSlug, ".governance"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,16 @@ import {DefaultEmissionManager} from "../../src/DefaultEmissionManager.sol";
contract Deploy is Script {
using stdJson for string;

string internal constant TEST_MNEMONIC = "test test test test test test test test test test test junk";
uint256 public deployerPrivateKey;

constructor() {
deployerPrivateKey = vm.envOr({name: "PRIVATE_KEY", defaultValue: uint256(0)});
if (deployerPrivateKey == 0) {
(, deployerPrivateKey) = deriveRememberKey({mnemonic: TEST_MNEMONIC, index: 0});
}
}

function run() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
string memory input = vm.readFile("scripts/1.1.0/input.json");
string memory chainIdSlug = string(abi.encodePacked('["', vm.toString(block.chainid), '"]'));
ITransparentUpgradeableProxy emissionProxy = ITransparentUpgradeableProxy(
input.readAddress(string.concat(chainIdSlug, ".emissionProxy"))
);
address proxyAdmin = input.readAddress(string.concat(chainIdSlug, ".proxyAdmin"));
address migrationProxy = input.readAddress(string.concat(chainIdSlug, ".migrationProxy"));
address stakeManager = input.readAddress(string.concat(chainIdSlug, ".stakeManager"));
address treasury = input.readAddress(string.concat(chainIdSlug, ".treasury"));
vm.startBroadcast(deployerPrivateKey);
ProxyAdmin admin = ProxyAdmin(proxyAdmin);

address emissionManagerImplementationUpgrade = address(
new DefaultEmissionManager(migrationProxy, stakeManager, treasury)
);

admin.upgrade(emissionProxy, emissionManagerImplementationUpgrade);
new DefaultEmissionManager(migrationProxy, stakeManager, treasury);

vm.stopBroadcast();
}
Expand Down
13 changes: 12 additions & 1 deletion scripts/1.1.0/input.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
{
"1": {
"matic": "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
"governance": "0x6e7a5820baD6cebA8Ef5ea69c0C92EbbDAc9CE48",
"treasury": "0x2ff25495d77f380d5F65B95F103181aE8b1cf898",
"stakeManager": "0x5e3Ef299fDDf15eAa0432E6e66473ace8c13D908",
"permit2revoker": "0x6e7a5820baD6cebA8Ef5ea69c0C92EbbDAc9CE48"
},
"5": {
"migrationProxy": "0x5c5589fca76237Ed00BA024e19b6C077a108f687",
"stakeManager": "0x00200eA4Ee292E253E6Ca07dBA5EdC07c8Aa37A3",
"treasury": "0x531c7Befe78B6496e5753815ab3d3Cc024c1E842"
},
"31337": {
"treasury": "0x0000000000000000000000000000000000000001",
"stakeManager": "0x0000000000000000000000000000000000000001",
"proxyAdmin": "0x4ed7c70F96B99c776995fB64377f0d4aB3B0e1C1",
"migrationProxy": "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
"emissionProxy": "0x09635F643e140090A9A8Dcd712eD6285858ceBef"
}
Expand Down

0 comments on commit 7a1dec2

Please sign in to comment.