Skip to content

Commit

Permalink
Use treasuryDeposit to do initial transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
wcgcyx committed Nov 22, 2023
1 parent 7806a5c commit 91c5909
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 196 deletions.
2 changes: 0 additions & 2 deletions scripts/bootstrap/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ CHILD_BRIDGE_PAUSER=
CHILD_BRIDGE_UNPAUSER=
## The address to be assigned with ADAPTOR_MANAGER_ROLE in child bridge.
CHILD_BRIDGE_ADAPTOR_MANAGER=
## The address to be assigned with TREASURY_MANAGER_ROLE in child bridge.
CHILD_BRIDGE_TREASURY_MANAGER=
## The address to be assigned with DEFAULT_ADMIN_ROLE in child adaptor.
CHILD_ADAPTOR_DEFAULT_ADMIN=
## The address to be assigned with BRIDGE_MANAGER_ROLE in child adaptor.
Expand Down
8 changes: 5 additions & 3 deletions scripts/bootstrap/6_imx_burning.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ async function run() {
console.log("Burn IMX in...");
await helper.waitForConfirmation();

let childBridgeObj = JSON.parse(fs.readFileSync('../../out/ChildERC20Bridge.sol/ChildERC20Bridge.json', 'utf8'));
let childBridge = new ethers.Contract(childBridgeAddr, childBridgeObj.abi, childProvider);

console.log("Transfer " + imxDepositLimit + " IMX to child bridge...");
let [priorityFee, maxFee] = await helper.getFee(adminWallet);
let resp = await adminWallet.sendTransaction({
to: childBridgeAddr,
let resp = await childBridge.connect(adminWallet).treasuryDeposit({
value: ethers.utils.parseEther(imxDepositLimit),
maxPriorityFeePerGas: priorityFee,
maxFeePerGas: maxFee,
});
})
await helper.waitForReceipt(resp.hash, childProvider);
adminBal = await childProvider.getBalance(adminAddr);
bridgeBal = await childProvider.getBalance(childBridgeAddr);
Expand Down
2 changes: 0 additions & 2 deletions scripts/bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ CHILD_BRIDGE_PAUSER=
CHILD_BRIDGE_UNPAUSER=
## The address to be assigned with ADAPTOR_MANAGER_ROLE in child bridge.
CHILD_BRIDGE_ADAPTOR_MANAGER=
## The address to be assigned with TREASURY_MANAGER_ROLE in child bridge.
CHILD_BRIDGE_TREASURY_MANAGER=
## The address to be assigned with DEFAULT_ADMIN_ROLE in child adaptor.
CHILD_ADAPTOR_DEFAULT_ADMIN=
## The address to be assigned with BRIDGE_MANAGER_ROLE in child adaptor.
Expand Down
2 changes: 0 additions & 2 deletions scripts/deploy/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ CHILD_BRIDGE_PAUSER=
CHILD_BRIDGE_UNPAUSER=
## The address to be assigned with ADAPTOR_MANAGER_ROLE in child bridge.
CHILD_BRIDGE_ADAPTOR_MANAGER=
## The address to be assigned with TREASURY_MANAGER_ROLE in child bridge.
CHILD_BRIDGE_TREASURY_MANAGER=
## The address to be assigned with DEFAULT_ADMIN_ROLE in child adaptor.
CHILD_ADAPTOR_DEFAULT_ADMIN=
## The address to be assigned with BRIDGE_MANAGER_ROLE in child adaptor.
Expand Down
6 changes: 2 additions & 4 deletions scripts/deploy/child_initialisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ exports.initialiseChildContracts = async () => {
let childBridgePauser = helper.requireEnv("CHILD_BRIDGE_PAUSER");
let childBridgeUnpauser = helper.requireEnv("CHILD_BRIDGE_UNPAUSER");
let childBridgeAdaptorManager = helper.requireEnv("CHILD_BRIDGE_ADAPTOR_MANAGER");
let childBridgeTreasuryManager = helper.requireEnv("CHILD_BRIDGE_TREASURY_MANAGER");
let childAdaptorDefaultAdmin = helper.requireEnv("CHILD_ADAPTOR_DEFAULT_ADMIN");
let childAdaptorBridgeManager = helper.requireEnv("CHILD_ADAPTOR_BRIDGE_MANAGER");
let childAdaptorGasServiceManager = helper.requireEnv("CHILD_ADAPTOR_GAS_SERVICE_MANAGER");
Expand Down Expand Up @@ -62,16 +61,15 @@ exports.initialiseChildContracts = async () => {
pauser: childBridgePauser,
unpauser: childBridgeUnpauser,
adaptorManager: childBridgeAdaptorManager,
treasuryManager: childBridgeTreasuryManager,
initialDepositor: adminEOAAddr,
treasuryManager: multisigAddr,
},
childAdaptorAddr,
ethers.utils.getAddress(rootAdaptorAddr),
childTemplateAddr,
rootChainName,
rootIMXAddr,
childWIMXAddr,
multisigAddr,
adminEOAAddr,
{
maxPriorityFeePerGas: priorityFee,
maxFeePerGas: maxFee,
Expand Down
2 changes: 0 additions & 2 deletions scripts/localdev/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ CHILD_BRIDGE_PAUSER=0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc
CHILD_BRIDGE_UNPAUSER=0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc
## The address to be assigned with ADAPTOR_MANAGER_ROLE in child bridge.
CHILD_BRIDGE_ADAPTOR_MANAGER=0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc
## The address to be assigned with TREASURY_MANAGER_ROLE in child bridge.
CHILD_BRIDGE_TREASURY_MANAGER=0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc
## The address to be assigned with DEFAULT_ADMIN_ROLE in child adaptor.
CHILD_ADAPTOR_DEFAULT_ADMIN=0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc
## The address to be assigned with BRIDGE_MANAGER_ROLE in child adaptor.
Expand Down
15 changes: 4 additions & 11 deletions src/child/ChildERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ contract ChildERC20Bridge is BridgeRoles, IChildERC20BridgeErrors, IChildERC20Br
address public childETHToken;
/// @dev The address of the wrapped IMX token on L2.
address public wIMXToken;
/// @dev The address of the multisig contract on L2.
address public multisigContract;
/// @dev The address that will perform the initial depositing of IMX on L2.
address public initialDepositor;

/**
* @notice Initialization function for ChildERC20Bridge.
Expand All @@ -90,15 +86,13 @@ contract ChildERC20Bridge is BridgeRoles, IChildERC20BridgeErrors, IChildERC20Br
address newChildTokenTemplate,
string memory newRootChain,
address newRootIMXToken,
address newWIMXToken,
address newMultisigContract,
address newInitialDepositor
address newWIMXToken
) public initializer {
if (
newBridgeAdaptor == address(0) || newChildTokenTemplate == address(0) || newRootIMXToken == address(0)
|| newRoles.defaultAdmin == address(0) || newRoles.pauser == address(0) || newRoles.unpauser == address(0)
|| newRoles.adaptorManager == address(0) || newRoles.treasuryManager == address(0)
|| newWIMXToken == address(0) || newMultisigContract == address(0) || newInitialDepositor == address(0)
|| newWIMXToken == address(0)
) {
revert ZeroAddress();
}
Expand All @@ -118,6 +112,7 @@ contract ChildERC20Bridge is BridgeRoles, IChildERC20BridgeErrors, IChildERC20Br
_grantRole(PAUSER_ROLE, newRoles.pauser);
_grantRole(UNPAUSER_ROLE, newRoles.unpauser);
_grantRole(ADAPTOR_MANAGER_ROLE, newRoles.adaptorManager);
_grantRole(TREASURY_MANAGER_ROLE, newRoles.initialDepositor);
_grantRole(TREASURY_MANAGER_ROLE, newRoles.treasuryManager);

rootERC20BridgeAdaptor = newRootERC20BridgeAdaptor;
Expand All @@ -126,8 +121,6 @@ contract ChildERC20Bridge is BridgeRoles, IChildERC20BridgeErrors, IChildERC20Br
rootChain = newRootChain;
rootIMXToken = newRootIMXToken;
wIMXToken = newWIMXToken;
multisigContract = newMultisigContract;
initialDepositor = newInitialDepositor;

// NOTE: how will this behave in an updgrade scenario?
// e.g. this clone may already be deployed and we could deploy to the same address if the salt is the same.
Expand All @@ -148,7 +141,7 @@ contract ChildERC20Bridge is BridgeRoles, IChildERC20BridgeErrors, IChildERC20Br
*/
receive() external payable whenNotPaused {
// Revert if sender is not the WIMX token address
if (_msgSender() != wIMXToken && _msgSender() != multisigContract && _msgSender() != initialDepositor) {
if (msg.sender != wIMXToken) {
revert NonPermittedNativeTransfer();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/child/IChildERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface IChildERC20Bridge {
address pauser; // The address which will inherit `PAUSER_ROLE`.
address unpauser; // The address which will inherit `UNPAUSER_ROLE`.
address adaptorManager; // The address which will inherit `ADAPTOR_MANAGER_ROLE`.
address initialDepositor; // The address which will inherit `TREASURY_MANAGER_ROLE`.
address treasuryManager; // The address which will inherit `TREASURY_MANAGER_ROLE`.
}

Expand Down
7 changes: 2 additions & 5 deletions test/integration/child/ChildAxelarBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ contract ChildERC20BridgeIntegrationTest is Test, IChildERC20BridgeEvents, IChil
address constant IMX_TOKEN_ADDRESS = address(0xccc);
address constant WIMX_TOKEN_ADDRESS = address(0xabc);
address constant NATIVE_ETH = address(0xeee);
address constant MULTISIG_ADDRESS = address(0xbbbb);
address constant INITIAL_DEPOSITOR = address(0xcccc);

ChildERC20Bridge public childERC20Bridge;
ChildERC20 public childERC20;
Expand All @@ -46,6 +44,7 @@ contract ChildERC20BridgeIntegrationTest is Test, IChildERC20BridgeEvents, IChil
pauser: address(this),
unpauser: address(this),
adaptorManager: address(this),
initialDepositor: address(this),
treasuryManager: address(this)
});
childERC20Bridge.initialize(
Expand All @@ -55,9 +54,7 @@ contract ChildERC20BridgeIntegrationTest is Test, IChildERC20BridgeEvents, IChil
address(childERC20),
ROOT_CHAIN_NAME,
IMX_TOKEN_ADDRESS,
WIMX_TOKEN_ADDRESS,
MULTISIG_ADDRESS,
INITIAL_DEPOSITOR
WIMX_TOKEN_ADDRESS
);

IChildAxelarBridgeAdaptor.InitializationRoles memory adaptorRoles = IChildAxelarBridgeAdaptor
Expand Down
128 changes: 14 additions & 114 deletions test/unit/child/ChildERC20Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B
address constant ROOT_IMX_TOKEN = address(0xccc);
address constant CHILD_WIMX_TOKEN = address(0xabc);
address constant NATIVE_ETH = address(0xeee);
address constant MULTISIG_ADDRESS = address(0xbbbb);
address constant INITIAL_DEPOSITOR = address(0xcccc);
ChildERC20 public childTokenTemplate;
ChildERC20 public rootToken;
address public childETHToken;
ChildERC20Bridge public childBridge;

address treasuryManager = makeAddr("treasuryManager");
address initialDepositor = makeAddr("initialDepositor");

IChildERC20Bridge.InitializationRoles roles = IChildERC20Bridge.InitializationRoles({
defaultAdmin: address(this),
pauser: pauser,
unpauser: unpauser,
adaptorManager: address(this),
initialDepositor: initialDepositor,
treasuryManager: treasuryManager
});

Expand All @@ -54,9 +54,7 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B
address(childTokenTemplate),
ROOT_CHAIN_NAME,
ROOT_IMX_TOKEN,
CHILD_WIMX_TOKEN,
MULTISIG_ADDRESS,
INITIAL_DEPOSITOR
CHILD_WIMX_TOKEN
);
}

Expand Down Expand Up @@ -170,127 +168,55 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B
address(childTokenTemplate),
ROOT_CHAIN_NAME,
ROOT_IMX_TOKEN,
CHILD_WIMX_TOKEN,
MULTISIG_ADDRESS,
INITIAL_DEPOSITOR
CHILD_WIMX_TOKEN
);
}

function test_RevertIf_InitializeWithAZeroAddressDefaultAdmin() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
roles.defaultAdmin = address(0);
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(
roles,
address(1),
ROOT_BRIDGE_ADAPTOR,
address(1),
ROOT_CHAIN_NAME,
address(1),
address(1),
address(1),
address(1)
);
bridge.initialize(roles, address(1), ROOT_BRIDGE_ADAPTOR, address(1), ROOT_CHAIN_NAME, address(1), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressPauser() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
roles.pauser = address(0);
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(
roles,
address(1),
ROOT_BRIDGE_ADAPTOR,
address(1),
ROOT_CHAIN_NAME,
address(1),
address(1),
address(1),
address(1)
);
bridge.initialize(roles, address(1), ROOT_BRIDGE_ADAPTOR, address(1), ROOT_CHAIN_NAME, address(1), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressUnpauser() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
roles.unpauser = address(0);
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(
roles,
address(1),
ROOT_BRIDGE_ADAPTOR,
address(1),
ROOT_CHAIN_NAME,
address(1),
address(1),
address(1),
address(1)
);
bridge.initialize(roles, address(1), ROOT_BRIDGE_ADAPTOR, address(1), ROOT_CHAIN_NAME, address(1), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressAdapter() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
roles.adaptorManager = address(0);
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(
roles,
address(0),
ROOT_BRIDGE_ADAPTOR,
address(1),
ROOT_CHAIN_NAME,
address(1),
address(1),
address(1),
address(1)
);
bridge.initialize(roles, address(0), ROOT_BRIDGE_ADAPTOR, address(1), ROOT_CHAIN_NAME, address(1), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressTreasuryManager() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
roles.treasuryManager = address(0);
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(
roles,
address(1),
ROOT_BRIDGE_ADAPTOR,
address(1),
ROOT_CHAIN_NAME,
address(1),
address(1),
address(1),
address(1)
);
bridge.initialize(roles, address(1), ROOT_BRIDGE_ADAPTOR, address(1), ROOT_CHAIN_NAME, address(1), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressChildTemplate() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(
roles,
address(1),
ROOT_BRIDGE_ADAPTOR,
address(0),
ROOT_CHAIN_NAME,
address(1),
address(1),
address(1),
address(1)
);
bridge.initialize(roles, address(1), ROOT_BRIDGE_ADAPTOR, address(0), ROOT_CHAIN_NAME, address(1), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressIMXToken() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
vm.expectRevert(ZeroAddress.selector);
bridge.initialize(
roles,
address(1),
ROOT_BRIDGE_ADAPTOR,
address(1),
ROOT_CHAIN_NAME,
address(0),
address(1),
address(1),
address(1)
);
bridge.initialize(roles, address(1), ROOT_BRIDGE_ADAPTOR, address(1), ROOT_CHAIN_NAME, address(0), address(1));
}

function test_RevertIf_InitializeWithAZeroAddressAll() public {
Expand All @@ -301,48 +227,22 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B
roles.unpauser = address(0);
roles.adaptorManager = address(0);
roles.treasuryManager = address(0);
bridge.initialize(
roles,
address(0),
ROOT_BRIDGE_ADAPTOR,
address(0),
ROOT_CHAIN_NAME,
address(0),
address(0),
address(0),
address(0)
);
bridge.initialize(roles, address(0), ROOT_BRIDGE_ADAPTOR, address(0), ROOT_CHAIN_NAME, address(0), address(0));
}

function test_RevertIf_InitializeWithAnEmptyBridgeAdaptorString() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
vm.expectRevert(InvalidRootERC20BridgeAdaptor.selector);
bridge.initialize(
roles,
address(this),
"",
address(childTokenTemplate),
ROOT_CHAIN_NAME,
ROOT_IMX_TOKEN,
CHILD_WIMX_TOKEN,
MULTISIG_ADDRESS,
INITIAL_DEPOSITOR
roles, address(this), "", address(childTokenTemplate), ROOT_CHAIN_NAME, ROOT_IMX_TOKEN, CHILD_WIMX_TOKEN
);
}

function test_RevertIf_InitializeWithAnEmptyChainNameString() public {
ChildERC20Bridge bridge = new ChildERC20Bridge();
vm.expectRevert(InvalidRootChain.selector);
bridge.initialize(
roles,
address(this),
ROOT_BRIDGE_ADAPTOR,
address(childTokenTemplate),
"",
ROOT_IMX_TOKEN,
CHILD_WIMX_TOKEN,
MULTISIG_ADDRESS,
INITIAL_DEPOSITOR
roles, address(this), ROOT_BRIDGE_ADAPTOR, address(childTokenTemplate), "", ROOT_IMX_TOKEN, CHILD_WIMX_TOKEN
);
}

Expand Down
Loading

0 comments on commit 91c5909

Please sign in to comment.