Skip to content

Commit

Permalink
add script
Browse files Browse the repository at this point in the history
  • Loading branch information
thurendous committed Nov 11, 2024
1 parent 16ee710 commit 580d919
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 18 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ make coverage
make deploy ARGS="--network basesepolia"
```

8. Deploy the nft contract on the base sepolia network by running
```shell
make deploy ARGS="--network basemainnet"
```

1. Deploy the nft contract on the base sepolia network by running

```shell
make deploy-nft ARGS="--network basesepolia"
Expand Down
110 changes: 93 additions & 17 deletions script/DeployContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ contract DeployContracts is Script {
address public exchanger;
address public upgrader;
address public defender;
address public minter2;
address public burner2;
address public constant ZERO_ADDRESS = address(0);

function run() public returns (DeploymentResult memory) {
// local netwrok
if (block.chainid == 31337) {
console.log("Deploying contracts on the local testnet");

result = deploymentsOnLocalNetwork();
} else if (block.chainid == 84532) {
console.log("Deploying contracts on the base testnet");
Expand All @@ -59,19 +62,7 @@ contract DeployContracts is Script {
} else if (block.chainid == 8453) {
console.log("Deploying contracts on the base mainnet");

result = DeploymentResult({
utilityToken: ZERO_ADDRESS,
govToken: ZERO_ADDRESS,
exchange: ZERO_ADDRESS,
admin: vm.addr(vm.envUint("PRIVATE_KEY")),
pauser: ZERO_ADDRESS,
minter: ZERO_ADDRESS,
burner: ZERO_ADDRESS,
manager: ZERO_ADDRESS,
exchanger: ZERO_ADDRESS,
deployerKey: vm.envUint("PRIVATE_KEY"),
participant: 0
});
result = deploymentsOnBaseMainnet();
}

return result;
Expand Down Expand Up @@ -177,9 +168,9 @@ contract DeployContracts is Script {
govToken.grantRole(govToken.VOTING_POWER_EXCHANGE_ROLE(), address(votingPowerExchange));

// give exchange the minter role of govToken
govToken.grantRole(govToken.MINTER_ROLE(), address(votingPowerExchange));
// govToken.grantRole(govToken.MINTER_ROLE(), address(votingPowerExchange));
// give exchange the burner role of utilityToken
utilityToken.grantRole(utilityToken.BURNER_ROLE(), address(votingPowerExchange));
// utilityToken.grantRole(utilityToken.BURNER_ROLE(), address(votingPowerExchange));
// give defender the exchanger role
votingPowerExchange.grantRole(votingPowerExchange.EXCHANGER_ROLE(), defender);

Expand All @@ -189,9 +180,94 @@ contract DeployContracts is Script {
// here exchanger is deployer so we do this directly
// change this method when exchanger is not deployer
// utilityToken.approve(address(votingPowerExchange), 10_000 * 1e18);
// TODO: should let the outside exchanger to approve the exchange token.
// TODO: And the exchanger address should hold some utility token for calling exchange function.
// NOTE: should let the outside exchanger to approve the exchange token.
// NOTE: And the exchanger address should hold some utility token for calling exchange function. (not needed anymore)
// NOTE: the defender is now holding the utility token
vm.stopBroadcast();

return DeploymentResult({
utilityToken: address(utilityToken),
govToken: address(govToken),
exchange: address(votingPowerExchange),
admin: admin,
pauser: pauser,
minter: minter,
burner: burner,
manager: manager,
exchanger: exchanger,
deployerKey: uint256(0), // this is for outputing the type
participant: uint256(0) // this is for outputing the type
});
}

// deploy the contracts on the base mainnet for testing
function deploymentsOnBaseMainnet() public returns (DeploymentResult memory) {
uint256 PK = vm.envUint("MAINNET_DEPLOYER_PK");
address deployer = vm.addr(PK);
// check the deployer address is right
require(deployer == vm.envAddress("MAINNET_DEPLOYER_ADDR"), "Deployer address is not correct");

// set the roles
admin = deployer;
pauser = vm.envAddress("MAINNET_ADMIN_ADDR");
minter = vm.envAddress("MAINNET_ADMIN_ADDR");
burner = vm.envAddress("MAINNET_ADMIN_ADDR");
manager = vm.envAddress("MAINNET_ADMIN_ADDR");
exchanger = vm.envAddress("MAINNET_ADMIN_ADDR");
upgrader = vm.envAddress("MAINNET_ADMIN_ADDR");
defender = vm.envAddress("MAINNET_OPENZEPPELIN_DEFENDER_ADDR");

minter2 = deployer;
burner2 = deployer;

vm.startBroadcast(PK);
// deploy the utility token using the OpenZeppelin Upgrades library
address proxy = Upgrades.deployUUPSProxy(
"ERC20UpgradeableTokenV1.sol",
abi.encodeCall(
ERC20UpgradeableTokenV1.initialize, ("AMA coin", "AMA", admin, pauser, minter, burner, upgrader)
)
);

utilityToken = ERC20UpgradeableTokenV1(proxy);

// deploy the gov token
govToken = new GovToken("Governance Token", "GOV", admin, minter, burner, exchanger);

// deploy the voting power exchange
votingPowerExchange =
new VotingPowerExchange(address(govToken), address(utilityToken), admin, manager, exchanger);

// give exchange the minter role of govToken
govToken.grantRole(govToken.MINTER_ROLE(), address(votingPowerExchange));
// give exchange the burner role of utilityToken
utilityToken.grantRole(utilityToken.BURNER_ROLE(), address(votingPowerExchange));
// give exchange the voting power exchange role of govToken
govToken.grantRole(govToken.VOTING_POWER_EXCHANGE_ROLE(), address(votingPowerExchange));

// give defender the exchanger role of votingPowerExchange
votingPowerExchange.grantRole(votingPowerExchange.EXCHANGER_ROLE(), defender);

// give additional roles for testing
utilityToken.grantRole(utilityToken.MINTER_ROLE(), minter2);
utilityToken.grantRole(utilityToken.BURNER_ROLE(), burner2);
// mint some utility token to the defender initially
utilityToken.mint(defender, 100_000 * 1e18);

// give admin role to the mainnet admin address
utilityToken.grantRole(utilityToken.DEFAULT_ADMIN_ROLE(), vm.envAddress("MAINNET_ADMIN_ADDR"));
govToken.grantRole(govToken.DEFAULT_ADMIN_ROLE(), vm.envAddress("MAINNET_ADMIN_ADDR"));
votingPowerExchange.grantRole(votingPowerExchange.DEFAULT_ADMIN_ROLE(), vm.envAddress("MAINNET_ADMIN_ADDR"));

// revoke the admin role from the deployer
utilityToken.revokeRole(utilityToken.DEFAULT_ADMIN_ROLE(), deployer);
govToken.revokeRole(govToken.DEFAULT_ADMIN_ROLE(), deployer);
votingPowerExchange.revokeRole(votingPowerExchange.DEFAULT_ADMIN_ROLE(), deployer);

vm.stopBroadcast();
// NOTE: should let the outside exchanger to approve the exchange token.
// NOTE: And the exchanger address should hold some utility token for calling exchange function. (not needed anymore)
// NOTE: the defender is now holding the utility token

return DeploymentResult({
utilityToken: address(utilityToken),
Expand Down

0 comments on commit 580d919

Please sign in to comment.