Skip to content

Commit

Permalink
Add env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjimmutable committed Nov 7, 2023
1 parent e09c8f8 commit c4b61a2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 34 deletions.
7 changes: 6 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ROOT_ADMIN_ADDRESS=
ROOT_PAUSER_ADDRESS=
ROOT_UNPAUSER_ADDRESS=
ROOT_RPC_URL=
ROOT_CHAIN_ID=
ROOT_PRIVATE_KEY=
Expand All @@ -7,8 +9,11 @@ ROOT_GAS_SERVICE_ADDRESS=
ROOT_CHAIN_NAME=
ROOT_IMX_ADDRESS=
ROOT_WETH_ADDRESS=
INITIAL_IMX_CUMULATIVE_DEPOSIT_LIMIT= # 0 for unlimited

ROOT_ADMIN_ADDRESS=
CHILD_ADMIN_ADDRESS=
CHILD_PAUSER_ADDRESS=
CHILD_UNPAUSER_ADDRESS=
CHILD_RPC_URL=
CHILD_CHAIN_ID=
CHILD_PRIVATE_KEY=
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ yarn run execute evm/call-contract local Ethereum Polygon map
5. (OPTIONAL) Check the token mapping has been populated using `cast`
```shell
source .env
cast call --rpc-url $CHILD_RPC_URL "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" "rootTokenToChildToken(address)(address)" "0x38Aa1Cb12E5263eC0c6e9febC25B01116D346CD4"
cast call --rpc-url $CHILD_RPC_URL "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707" "rootTokenToChildToken(address)(address)" "0x38Aa1Cb12E5263eC0c6e9febC25B01116D346CD4"
```

6. Run the script that will send a `DEPOSIT` message
Expand All @@ -172,6 +172,6 @@ yarn run execute evm/call-contract local Ethereum Polygon deposit
7. (OPTIONAL) Check the tokens have been deposited using `cast`
```shell
source .env
cast call --rpc-url $CHILD_RPC_URL "0x3b39f73D7De57Ed2Fe85C0F30374D839dc625b93" "balanceOf(address)(uint256)" "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
cast call --rpc-url $CHILD_RPC_URL "0xa03647137120b00cae83751A82280A67df027F04" "balanceOf(address)(uint256)" "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
```
(Note: This assumes your address is the one associated with the above-specified private key)
67 changes: 43 additions & 24 deletions script/InitializeChildContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,66 @@ import {Utils} from "./Utils.sol";

// TODO update private key usage to be more secure: https://book.getfoundry.sh/reference/forge/forge-script#wallet-options---raw

struct InitializeChildContractsParams {
address childAdminAddress;
address childPauserAddress;
address childUnpauserAddress;
ChildERC20Bridge childERC20Bridge;
ChildAxelarBridgeAdaptor childAxelarBridgeAdaptor;
address childTokenTemplate;
address rootERC20BridgeAdaptor;
string rootChainName;
address rootIMXToken;
string childRpcUrl;
uint256 deployerPrivateKey;
address childGasService;
}

contract InitializeChildContracts is Script {
function run() public {
uint256 deployerPrivateKey = vm.envUint("CHILD_PRIVATE_KEY");
ChildERC20Bridge childERC20Bridge = ChildERC20Bridge(vm.envAddress("CHILD_ERC20_BRIDGE"));
ChildAxelarBridgeAdaptor childAxelarBridgeAdaptor =
ChildAxelarBridgeAdaptor(vm.envAddress("CHILD_BRIDGE_ADAPTOR"));
address childTokenTemplate = vm.envAddress("CHILDCHAIN_CHILD_TOKEN_TEMPLATE");
address rootERC20BridgeAdaptor = vm.envAddress("ROOT_BRIDGE_ADAPTOR");
string memory childRpcUrl = vm.envString("CHILD_RPC_URL");
string memory rootChainName = vm.envString("ROOT_CHAIN_NAME");
address rootIMXToken = vm.envAddress("ROOT_IMX_ADDRESS");
address childGasService = vm.envAddress("CHILD_GAS_SERVICE_ADDRESS"); // Not yet used.
InitializeChildContractsParams memory params = InitializeChildContractsParams({
childAdminAddress: vm.envAddress("CHILD_ADMIN_ADDRESS"),
childPauserAddress: vm.envAddress("CHILD_PAUSER_ADDRESS"),
childUnpauserAddress: vm.envAddress("CHILD_UNPAUSER_ADDRESS"),
childERC20Bridge: ChildERC20Bridge(vm.envAddress("CHILD_ERC20_BRIDGE")),
childAxelarBridgeAdaptor: ChildAxelarBridgeAdaptor(vm.envAddress("CHILD_BRIDGE_ADAPTOR")),
childTokenTemplate: vm.envAddress("CHILDCHAIN_CHILD_TOKEN_TEMPLATE"),
rootERC20BridgeAdaptor: vm.envAddress("ROOT_BRIDGE_ADAPTOR"),
rootChainName: vm.envString("ROOT_CHAIN_NAME"),
rootIMXToken: vm.envAddress("ROOT_IMX_ADDRESS"),
childRpcUrl: vm.envString("CHILD_RPC_URL"),
deployerPrivateKey: vm.envUint("CHILD_PRIVATE_KEY"),
childGasService: vm.envAddress("CHILD_GAS_SERVICE_ADDRESS")
});

/**
* INITIALIZE CHILD CONTRACTS
*/
string[] memory checksumInputs = Utils.getChecksumInputs(rootERC20BridgeAdaptor);
string[] memory checksumInputs = Utils.getChecksumInputs(params.rootERC20BridgeAdaptor);
bytes memory checksumOutput = vm.ffi(checksumInputs);
string memory rootBridgeAdaptorString = string(Utils.removeZeroByteValues(checksumOutput));

vm.createSelectFork(childRpcUrl);
vm.startBroadcast(deployerPrivateKey);
vm.createSelectFork(params.childRpcUrl);
vm.startBroadcast(params.deployerPrivateKey);

// TODO update
IChildERC20Bridge.InitializationRoles memory roles = IChildERC20Bridge.InitializationRoles({
defaultAdmin: address(1),
pauser: address(2),
unpauser: address(3),
variableManager: address(4),
adaptorManager: address(5)
defaultAdmin: params.childAdminAddress,
pauser: params.childPauserAddress,
unpauser: params.childUnpauserAddress,
variableManager: params.childAdminAddress,
adaptorManager: params.childAdminAddress
});
childERC20Bridge.initialize(
params.childERC20Bridge.initialize(
roles,
address(childAxelarBridgeAdaptor),
address(params.childAxelarBridgeAdaptor),
rootBridgeAdaptorString,
childTokenTemplate,
rootChainName,
rootIMXToken
params.childTokenTemplate,
params.rootChainName,
params.rootIMXToken
);

childAxelarBridgeAdaptor.initialize(rootChainName, address(childERC20Bridge), childGasService);
params.childAxelarBridgeAdaptor.initialize(params.rootChainName, address(params.childERC20Bridge), params.childGasService);

vm.stopBroadcast();
}
Expand Down
18 changes: 11 additions & 7 deletions script/InitializeRootContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {Utils} from "./Utils.sol";

struct InitializeRootContractsParams {
address rootAdminAddress;
address rootPauserAddress;
address rootUnpauserAddress;
RootERC20Bridge rootERC20Bridge;
RootAxelarBridgeAdaptor rootBridgeAdaptor;
address rootChainChildTokenTemplate;
Expand All @@ -33,6 +35,8 @@ contract InitializeRootContracts is Script {
function run() public {
InitializeRootContractsParams memory params = InitializeRootContractsParams({
rootAdminAddress: vm.envAddress("ROOT_ADMIN_ADDRESS"),
rootPauserAddress: vm.envAddress("ROOT_PAUSER_ADDRESS"),
rootUnpauserAddress: vm.envAddress("ROOT_UNPAUSER_ADDRESS"),
rootERC20Bridge: RootERC20Bridge(payable(vm.envAddress("ROOT_ERC20_BRIDGE"))),
rootBridgeAdaptor: RootAxelarBridgeAdaptor(vm.envAddress("ROOT_BRIDGE_ADAPTOR")),
rootChainChildTokenTemplate: vm.envAddress("ROOTCHAIN_CHILD_TOKEN_TEMPLATE"),
Expand All @@ -58,13 +62,13 @@ contract InitializeRootContracts is Script {

// TODO add pauser, unpauser roles. variable manager and Adaptor manager will be privileged transaction multisg

IRootERC20Bridge.InitializationRoles memory roles = IRootERC20Bridge.InitializationRoles(
address(params.rootAdminAddress),
address(params.rootAdminAddress),
address(params.rootAdminAddress),
address(params.rootAdminAddress),
address(params.rootAdminAddress)
);
IRootERC20Bridge.InitializationRoles memory roles = IRootERC20Bridge.InitializationRoles({
defaultAdmin: params.rootAdminAddress,
pauser: params.rootPauserAddress,
unpauser: params.rootUnpauserAddress,
variableManager: params.rootAdminAddress,
adaptorManager: params.rootAdminAddress
});

params.rootERC20Bridge.initialize(
roles,
Expand Down

0 comments on commit c4b61a2

Please sign in to comment.