Skip to content

Commit

Permalink
Merge branch 'main' into add-creator-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
gvladika committed Nov 15, 2023
2 parents f5ac379 + 6dff4c5 commit 9fb1fe5
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 46 deletions.
27 changes: 19 additions & 8 deletions .env-sample
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
## RPC endpoint
BASECHAIN_RPC=""

## Deployer key used for deploying creator or creating token bridge
BASECHAIN_DEPLOYER_KEY=""

## WETH address on the basechain. It will be set and used in the TokenBridgeCreator
BASECHAIN_WETH=""

## Gas limit for deploying child chain factory needs to be provided to the TokenBridgeCreator when templates are set.
## If this param is not provided then gas limit will be estimated using SDK from child chain (specified by ORBIT_RPC and ROLLUP_ADDRESS)
GAS_LIMIT_FOR_L2_FACTORY_DEPLOYMENT=6000000

## Contract verification
ARBISCAN_API_KEY=""

### Vars for creating token bridge from existing TokenBridgeCreator
## Rollup on top of which token bridge will be created
ROLLUP_ADDRESS=""
ORBIT_RPC=""
ROLLUP_OWNER=""
L1_TOKEN_BRIDGE_CREATOR=""
# needed for verification
L1_RETRYABLE_SENDER=""

## RPC endpoints
BASECHAIN_RPC=""
ORBIT_RPC=""

## Deployer key used for deploying creator and creating token bridge
BASECHAIN_DEPLOYER_KEY=""
L1_RETRYABLE_SENDER=""
25 changes: 25 additions & 0 deletions .env.arb1.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## RPC endpoint
BASECHAIN_RPC="https://arb1.arbitrum.io/rpc"

## Deployer key used for deploying creator or creating token bridge
BASECHAIN_DEPLOYER_KEY=""

## WETH address on the basechain. It will be set and used in the TokenBridgeCreator
BASECHAIN_WETH="0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"

## Gas limit for deploying child chain factory needs to be provided to the TokenBridgeCreator when templates are set.
## If this param is not provided then gas limit will be estimated using SDK from child chain (specified by ORBIT_RPC and ROLLUP_ADDRESS)
GAS_LIMIT_FOR_L2_FACTORY_DEPLOYMENT=6000000

## Contract verification
ARBISCAN_API_KEY=""


### Vars for creating token bridge from existing TokenBridgeCreator
## Rollup on top of which token bridge will be created
# ROLLUP_ADDRESS=""
# ORBIT_RPC=""
# ROLLUP_OWNER=""
# L1_TOKEN_BRIDGE_CREATOR=""
# # needed for verification
# L1_RETRYABLE_SENDER=""
30 changes: 27 additions & 3 deletions contracts/tokenbridge/arbitrum/L2AtomicTokenBridgeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
contract L2AtomicTokenBridgeFactory {
error L2AtomicTokenBridgeFactory_AlreadyExists();

// In order to avoid having uninitialized logic contracts, `initialize` function will be called
// on all logic contracts which don't have initializers disabled. This dummy non-zero address
// will be provided to those initializers, as values written to the logic contract's storage
// are not used.
address private constant ADDRESS_DEAD = address(0x000000000000000000000000000000000000dEaD);

function deployL2Contracts(
L2RuntimeCode calldata l2Code,
address l1Router,
Expand Down Expand Up @@ -86,7 +92,8 @@ contract L2AtomicTokenBridgeFactory {
proxyAdmin, _getL2Salt(OrbitSalts.L2_EXECUTOR), _getL2Salt(OrbitSalts.L2_EXECUTOR_LOGIC)
);

// create UpgradeExecutor logic and upgrade to it
// Create UpgradeExecutor logic and upgrade to it.
// Note: UpgradeExecutor logic has initializer disabled so no need to call it.
address upExecutorLogic = Create2.deploy(
0, _getL2Salt(OrbitSalts.L2_EXECUTOR_LOGIC), _creationCodeFor(runtimeCode)
);
Expand Down Expand Up @@ -119,6 +126,9 @@ contract L2AtomicTokenBridgeFactory {
Create2.deploy(0, _getL2Salt(OrbitSalts.L2_ROUTER_LOGIC), _creationCodeFor(runtimeCode));
ProxyAdmin(proxyAdmin).upgrade(ITransparentUpgradeableProxy(canonicalRouter), routerLogic);

// init logic contract with dummy values.
L2GatewayRouter(routerLogic).initialize(ADDRESS_DEAD, ADDRESS_DEAD);

// init
L2GatewayRouter(canonicalRouter).initialize(l1Router, l2StandardGatewayCanonicalAddress);

Expand Down Expand Up @@ -147,6 +157,9 @@ contract L2AtomicTokenBridgeFactory {
ITransparentUpgradeableProxy(canonicalStdGateway), stdGatewayLogic
);

// init logic contract with dummy values
L2ERC20Gateway(stdGatewayLogic).initialize(ADDRESS_DEAD, ADDRESS_DEAD, ADDRESS_DEAD);

// create beacon
StandardArbERC20 standardArbERC20 = new StandardArbERC20{
salt: _getL2Salt(OrbitSalts.L2_STANDARD_ERC20)
Expand Down Expand Up @@ -189,8 +202,11 @@ contract L2AtomicTokenBridgeFactory {
ITransparentUpgradeableProxy(canonicalCustomGateway), customGatewayLogicAddress
);

// init logic contract with dummy values
L2CustomGateway(customGatewayLogicAddress).initialize(ADDRESS_DEAD, ADDRESS_DEAD);

// init
L2GatewayRouter(canonicalCustomGateway).initialize(l1CustomGateway, router);
L2CustomGateway(canonicalCustomGateway).initialize(l1CustomGateway, router);
}

function _deployWethGateway(
Expand All @@ -206,7 +222,7 @@ contract L2AtomicTokenBridgeFactory {
proxyAdmin, _getL2Salt(OrbitSalts.L2_WETH), _getL2Salt(OrbitSalts.L2_WETH_LOGIC)
);

// create L2WETH logic and upgrade
// Create L2WETH logic and upgrade
address l2WethLogic = Create2.deploy(
0, _getL2Salt(OrbitSalts.L2_WETH_LOGIC), _creationCodeFor(aeWethRuntimeCode)
);
Expand All @@ -229,11 +245,19 @@ contract L2AtomicTokenBridgeFactory {
ITransparentUpgradeableProxy(canonicalL2WethGateway), l2WethGatewayLogic
);

// init logic contract with dummy values
L2WethGateway(payable(l2WethGatewayLogic)).initialize(
ADDRESS_DEAD, ADDRESS_DEAD, ADDRESS_DEAD, ADDRESS_DEAD
);

// init gateway
L2WethGateway(payable(canonicalL2WethGateway)).initialize(
l1WethGateway, router, l1Weth, address(canonicalL2Weth)
);

// init logic contract with dummy values
aeWETH(payable(l2WethLogic)).initialize("", "", 0, ADDRESS_DEAD, ADDRESS_DEAD);

// init L2Weth
aeWETH(payable(canonicalL2Weth)).initialize(
"WETH", "WETH", 18, canonicalL2WethGateway, l1Weth
Expand Down
74 changes: 74 additions & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# How to deploy RollupCreator and TokenBridgeCreator?

## RollupCreator
RollupCreator is in nitro-contracts repo
```
cd nitro-contracts
```

Checkout target code, ie.
```
git checkout v1.1.0
```

Install dependencies and build
```
yarn install
yarn build
```

Populate .env
```
DEVNET_PRIVKEY or MAINNET_PRIVKEY
ARBISCAN_API_KEY
```

Finally deploy it, using `--network` flag to specify network.

Ie. to deploy to Arbitrum Sepolia
```
yarn run deploy-factory --network arbSepolia
```

To deploy to Arbitrum One
```
yarn run deploy-factory --network arb1
```

Script output will contain all deployed addresses.


## TokenBridgeCreator
Checkout target code, install dependencies and build
```
cd token-bridge-contracts
yarn install
yarn build
```


Populate .env
```
BASECHAIN_RPC
BASECHAIN_DEPLOYER_KEY
BASECHAIN_WETH
GAS_LIMIT_FOR_L2_FACTORY_DEPLOYMENT
ARBISCAN_API_KEY
```

Note: Gas limit for deploying child chain factory via retryable needs to be provided to the TokenBridgeCreator when templates are set. This value can be obtained in 2 ways - 1st is to provide `ORBIT_RPC` and `ROLLUP_ADDRESS` env vars, and script will then use Arbitrum SDK to estimate gas needed for deploying L2 factory. Other way to do it is much simpler - provide hardcoded value by setting the `GAS_LIMIT_FOR_L2_FACTORY_DEPLOYMENT`. Previous deployments showed that gas needed is ~5140000. Adding a bit of buffer on top, we can set this value to `GAS_LIMIT_FOR_L2_FACTORY_DEPLOYMENT=6000000`.


Finally, deploy token bridge creator. Target chain is defined by `BASECHAIN_RPC` env var (no need to provide `--network` flag).
```
yarn run deploy:token-bridge-creator
```

Script outputs `L1TokenBridgeCreator` and `L1TokenBridgeRetryableSender` addresses. All deployed addresses can be obtained through `L1TokenBridgeCreator` contract.


## Ownership
These contracts will be owned by deployer:
- RollupCreator (owner can set templates)
- L1AtomicTokenBridgeCreator (owner can set templates)
- ProxyAdmin of L1AtomicTokenBridgeCreator and L1TokenBridgeRetryableSender (owner can do upgrades)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"test:e2e:local-env": "yarn hardhat test test-e2e/*",
"test:storage": "./scripts/storage_layout_test.bash",
"deploy:local:token-bridge": "ts-node ./scripts/local-deployment/deployCreatorAndCreateTokenBridge.ts",
"deploy:goerli:token-bridge-creator": "ts-node ./scripts/goerli-deployment/deployTokenBridgeCreator.ts",
"create:goerli:token-bridge": "ts-node ./scripts/goerli-deployment/createTokenBridge.ts",
"deploy:token-bridge-creator": "ts-node ./scripts/deployment/deployTokenBridgeCreator.ts",
"create:token-bridge": "ts-node ./scripts/deployment/createTokenBridge.ts",
"test:tokenbridge:deployment": "hardhat test test-e2e/tokenBridgeDeploymentTest.ts",
"typechain": "hardhat typechain",
"deploy:tokenbridge": "hardhat run scripts/deploy_token_bridge_l1.ts --network mainnet",
Expand Down
Loading

0 comments on commit 9fb1fe5

Please sign in to comment.