Skip to content

Commit

Permalink
Merge branch 'SMR-1816-ETH-Withdraw' into NOJIRA_AUTOMATE_BOOTSTRAP
Browse files Browse the repository at this point in the history
  • Loading branch information
wcgcyx committed Nov 9, 2023
2 parents 9e47066 + 56d9e06 commit 93a54fc
Show file tree
Hide file tree
Showing 47 changed files with 4,023 additions and 147 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ROOT_GAS_SERVICE_ADDRESS=
CHILD_GAS_SERVICE_ADDRESS=
ROOT_CHAIN_NAME=
CHILD_CHAIN_NAME=
CHILD_WIMX_ADDRESS=
ROOT_IMX_ADDRESS=
ROOT_WETH_ADDRESS=
ENVIRONMENT=
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ CHILD_GAS_SERVICE_ADDRESS=
ROOT_CHAIN_NAME="ROOT"
CHILD_CHAIN_NAME="CHILD"
ROOT_IMX_ADDRESS=
INITIAL_IMX_CUMULATIVE_DEPOSIT_LIMIT="0"
```
where `{ROOT,CHILD}_{GATEWAY,GAS_SERVICE}_ADDRESS` refers to the gateway and gas service addresses used by Axelar.

`INITIAL_IMX_CUMULATIVE_DEPOSIT_LIMIT` refers to the cumulative amount of IMX that can be deposited. A value of `0` indicated unlimited.

We can just use dummy gateway/gas service addresses if we only want to test the deployment, and not bridging functionality. If wanting to use dummy addresses, any valid Ethereum address can be used here.

4. Run the deploy script.
Expand Down Expand Up @@ -138,6 +141,7 @@ ROOT_GATEWAY_ADDRESS="0x013459EC3E8Aeced878C5C4bFfe126A366cd19E9"
CHILD_GATEWAY_ADDRESS="0xc7B788E88BAaB770A6d4936cdcCcd5250E1bbAd8"
ROOT_GAS_SERVICE_ADDRESS="0x28f8B50E1Be6152da35e923602a2641491E71Ed8"
CHILD_GAS_SERVICE_ADDRESS="0xC573c722e21eD7fadD38A8f189818433e01Ae466"
INITIAL_IMX_CUMULATIVE_DEPOSIT_LIMIT="0"
ENVIRONMENT="local"
```
(Note that `{ROOT,CHILD}_PRIVATE_KEY` can be any of the standard localhost private keys that get funded)
Expand Down
8 changes: 5 additions & 3 deletions script/DeployChildContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ contract DeployChildContracts is Script {
vm.createSelectFork(childRpcUrl);
vm.startBroadcast(deployerPrivateKey);

WIMX wrappedIMX = new WIMX();

ProxyAdmin proxyAdmin = new ProxyAdmin();

ChildERC20 childTokenTemplate = new ChildERC20();
childTokenTemplate.initialize(address(123), "TEMPLATE", "TPT", 18);

ChildERC20Bridge childERC20BridgeImplementation = new ChildERC20Bridge();
childERC20BridgeImplementation.initialize(address(1), "0x123", address(1), "root", address(1));
childERC20BridgeImplementation.initialize(
address(1), "0x123", address(1), "root", address(1), address(wrappedIMX)
);

TransparentUpgradeableProxy childERC20BridgeProxy = new TransparentUpgradeableProxy(
address(childERC20BridgeImplementation),
Expand All @@ -46,8 +50,6 @@ contract DeployChildContracts is Script {
""
);

WIMX wrappedIMX = new WIMX();

vm.stopBroadcast();

console2.log("====CHILD ADDRESSES====");
Expand Down
12 changes: 6 additions & 6 deletions script/DeployRootContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ contract DeployRootContracts is Script {
uint256 rootPrivateKey = vm.envUint("ROOT_PRIVATE_KEY");
string memory rootRpcUrl = vm.envString("ROOT_RPC_URL");
string memory deployEnvironment = vm.envString("ENVIRONMENT");
address rootGateway = vm.envAddress("ROOT_GATEWAY_ADDRESS");

/**
* DEPLOY ROOT CHAIN CONTRACTS
Expand All @@ -35,19 +36,18 @@ contract DeployRootContracts is Script {
rootChainChildTokenTemplate.initialize(address(123), "TEMPLATE", "TPT", 18);

RootERC20Bridge rootERC20BridgeImplementation = new RootERC20Bridge();
rootERC20BridgeImplementation.initialize(address(1), address(1), "filler", address(1), address(1), address(1));
rootERC20BridgeImplementation.initialize(
address(1), address(1), "filler", address(1), address(1), address(1), "filler_child_name", 1
);
TransparentUpgradeableProxy rootERC20BridgeProxy = new TransparentUpgradeableProxy(
address(rootERC20BridgeImplementation),
address(proxyAdmin),
""
);

// TODO add dummy initialize of implementation contracts!
RootAxelarBridgeAdaptor rootBridgeAdaptorImplementation = new RootAxelarBridgeAdaptor(rootGateway);
rootBridgeAdaptorImplementation.initialize(address(rootERC20BridgeImplementation), "Filler", address(1));

RootAxelarBridgeAdaptor rootBridgeAdaptorImplementation = new RootAxelarBridgeAdaptor();
rootBridgeAdaptorImplementation.initialize(
address(rootERC20BridgeImplementation), "Filler", address(1), address(1)
);
TransparentUpgradeableProxy rootBridgeAdaptorProxy = new TransparentUpgradeableProxy(
address(rootBridgeAdaptorImplementation),
address(proxyAdmin),
Expand Down
11 changes: 9 additions & 2 deletions script/InitializeChildContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ contract InitializeChildContracts is Script {
string memory childRpcUrl = vm.envString("CHILD_RPC_URL");
string memory rootChainName = vm.envString("ROOT_CHAIN_NAME");
address rootIMXToken = vm.envAddress("ROOT_IMX_ADDRESS");
address wIMXToken = vm.envAddress("CHILD_WIMX_ADDRESS");
address childGasService = vm.envAddress("CHILD_GAS_SERVICE_ADDRESS"); // Not yet used.

/**
* INITIALIZE CHILD CONTRACTS
Expand All @@ -32,10 +34,15 @@ contract InitializeChildContracts is Script {
vm.startBroadcast(deployerPrivateKey);

childERC20Bridge.initialize(
address(childAxelarBridgeAdaptor), rootBridgeAdaptorString, childTokenTemplate, rootChainName, rootIMXToken
address(childAxelarBridgeAdaptor),
rootBridgeAdaptorString,
childTokenTemplate,
rootChainName,
rootIMXToken,
wIMXToken
);

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

vm.stopBroadcast();
}
Expand Down
11 changes: 6 additions & 5 deletions script/InitializeRootContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ struct InitializeRootContractsParams {
address rootIMXToken;
address rootWETHToken;
string childChainName;
address rootGateway;
address rootGasService;
uint256 initialIMXCumulativeDepositLimit;
}

contract InitializeRootContracts is Script {
Expand All @@ -41,8 +41,8 @@ contract InitializeRootContracts is Script {
rootIMXToken: vm.envAddress("ROOT_IMX_ADDRESS"),
rootWETHToken: vm.envAddress("ROOT_WETH_ADDRESS"),
childChainName: vm.envString("CHILD_CHAIN_NAME"),
rootGateway: vm.envAddress("ROOT_GATEWAY_ADDRESS"),
rootGasService: vm.envAddress("ROOT_GAS_SERVICE_ADDRESS")
rootGasService: vm.envAddress("ROOT_GAS_SERVICE_ADDRESS"),
initialIMXCumulativeDepositLimit: vm.envUint("INITIAL_IMX_CUMULATIVE_DEPOSIT_LIMIT")
});

string[] memory checksumInputs = Utils.getChecksumInputs(params.childBridgeAdaptor);
Expand All @@ -60,13 +60,14 @@ contract InitializeRootContracts is Script {
childBridgeAdaptorChecksum,
params.rootChainChildTokenTemplate,
params.rootIMXToken,
params.rootWETHToken
params.rootWETHToken,
params.childChainName,
params.initialIMXCumulativeDepositLimit
);

params.rootBridgeAdaptor.initialize(
address(params.rootERC20Bridge), // root bridge
params.childChainName, // child chain name
params.rootGateway, // axelar gateway
params.rootGasService // axelar gas service
);

Expand Down
46 changes: 43 additions & 3 deletions src/child/ChildAxelarBridgeAdaptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,65 @@
pragma solidity ^0.8.21;

import {AxelarExecutable} from "@axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol";
import {IAxelarGasService} from "@axelar-cgp-solidity/contracts/interfaces/IAxelarGasService.sol";
import {IAxelarGateway} from "@axelar-cgp-solidity/contracts/interfaces/IAxelarGateway.sol";
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import {IChildERC20Bridge} from "../interfaces/child/IChildERC20Bridge.sol";
import {IChildAxelarBridgeAdaptorErrors} from "../interfaces/child/IChildAxelarBridgeAdaptor.sol";
import {
IChildAxelarBridgeAdaptorErrors,
IChildAxelarBridgeAdaptorEvents
} from "../interfaces/child/IChildAxelarBridgeAdaptor.sol";
import {IChildERC20BridgeAdaptor} from "../interfaces/child/IChildERC20BridgeAdaptor.sol";

contract ChildAxelarBridgeAdaptor is AxelarExecutable, Initializable, IChildAxelarBridgeAdaptorErrors {
contract ChildAxelarBridgeAdaptor is
AxelarExecutable,
IChildERC20BridgeAdaptor,
Initializable,
IChildAxelarBridgeAdaptorErrors,
IChildAxelarBridgeAdaptorEvents
{
/// @notice Address of bridge to relay messages to.
IChildERC20Bridge public childBridge;
IAxelarGasService public gasService;
string public rootChain;

constructor(address _gateway) AxelarExecutable(_gateway) {}

/**
* @notice Initializes the contract.
* @param _childBridge Address of the child bridge contract.
*/
function initialize(address _childBridge) external initializer {
function initialize(string memory _rootChain, address _childBridge, address _gasService) external initializer {
if (_childBridge == address(0)) {
revert ZeroAddress();
}

childBridge = IChildERC20Bridge(_childBridge);
rootChain = _rootChain;
gasService = IAxelarGasService(_gasService);
}

/**
* TODO
*/
function sendMessage(bytes calldata payload, address refundRecipient) external payable override {
if (msg.value == 0) {
revert NoGas();
}
if (msg.sender != address(childBridge)) {
revert CallerNotBridge();
}

// Load from storage.
string memory _rootBridgeAdaptor = childBridge.rootERC20BridgeAdaptor();
string memory _rootChain = rootChain;

gasService.payNativeGasForContractCall{value: msg.value}(
address(this), _rootChain, _rootBridgeAdaptor, payload, refundRecipient
);

gateway.callContract(_rootChain, _rootBridgeAdaptor, payload);
emit AxelarMessageSent(_rootChain, _rootBridgeAdaptor, payload);
}

/**
Expand All @@ -32,6 +71,7 @@ contract ChildAxelarBridgeAdaptor is AxelarExecutable, Initializable, IChildAxel
internal
override
{
emit AdaptorExecute(sourceChain_, sourceAddress_, payload_);
childBridge.onMessageReceive(sourceChain_, sourceAddress_, payload_);
}
}
Loading

0 comments on commit 93a54fc

Please sign in to comment.