Skip to content

Commit

Permalink
Extract L2 proxy address calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
gvladika committed Aug 31, 2023
1 parent b157eb9 commit a93fef9
Showing 1 changed file with 28 additions and 79 deletions.
107 changes: 28 additions & 79 deletions contracts/tokenbridge/ethereum/L1AtomicTokenBridgeCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -355,98 +355,26 @@ contract L1AtomicTokenBridgeCreator is Initializable, OwnableUpgradeable {
}

function getCanonicalL2RouterAddress() public view returns (address) {
address logicSeedAddress = Create2.computeAddress(
_getL2Salt(OrbitSalts.L2_ROUTER_LOGIC),
keccak256(type(CanonicalAddressSeed).creationCode),
canonicalL2FactoryAddress
);

return Create2.computeAddress(
_getL2Salt(OrbitSalts.L2_ROUTER),
keccak256(
abi.encodePacked(
type(TransparentUpgradeableProxy).creationCode,
abi.encode(logicSeedAddress, canonicalL2ProxyAdminAddress, bytes(""))
)
),
canonicalL2FactoryAddress
);
return _getProxyAddress(_getL2Salt(OrbitSalts.L2_ROUTER_LOGIC), _getL2Salt(OrbitSalts.L2_ROUTER));
}

function getCanonicalL2StandardGatewayAddress() public view returns (address) {
address logicSeedAddress = Create2.computeAddress(
_getL2Salt(OrbitSalts.L2_STANDARD_GATEWAY_LOGIC),
keccak256(type(CanonicalAddressSeed).creationCode),
canonicalL2FactoryAddress
);

return Create2.computeAddress(
_getL2Salt(OrbitSalts.L2_STANDARD_GATEWAY),
keccak256(
abi.encodePacked(
type(TransparentUpgradeableProxy).creationCode,
abi.encode(logicSeedAddress, canonicalL2ProxyAdminAddress, bytes(""))
)
),
canonicalL2FactoryAddress
return _getProxyAddress(
_getL2Salt(OrbitSalts.L2_STANDARD_GATEWAY_LOGIC), _getL2Salt(OrbitSalts.L2_STANDARD_GATEWAY)
);
}

function getCanonicalL2CustomGatewayAddress() public view returns (address) {
address logicSeedAddress = Create2.computeAddress(
_getL2Salt(OrbitSalts.L2_CUSTOM_GATEWAY_LOGIC),
keccak256(type(CanonicalAddressSeed).creationCode),
canonicalL2FactoryAddress
);

return Create2.computeAddress(
_getL2Salt(OrbitSalts.L2_CUSTOM_GATEWAY),
keccak256(
abi.encodePacked(
type(TransparentUpgradeableProxy).creationCode,
abi.encode(logicSeedAddress, canonicalL2ProxyAdminAddress, bytes(""))
)
),
canonicalL2FactoryAddress
);
return
_getProxyAddress(_getL2Salt(OrbitSalts.L2_CUSTOM_GATEWAY_LOGIC), _getL2Salt(OrbitSalts.L2_CUSTOM_GATEWAY));
}

function getCanonicalL2WethGatewayAddress() public view returns (address) {
address logicSeedAddress = Create2.computeAddress(
_getL2Salt(OrbitSalts.L2_WETH_GATEWAY_LOGIC),
keccak256(type(CanonicalAddressSeed).creationCode),
canonicalL2FactoryAddress
);

return Create2.computeAddress(
_getL2Salt(OrbitSalts.L2_WETH_GATEWAY),
keccak256(
abi.encodePacked(
type(TransparentUpgradeableProxy).creationCode,
abi.encode(logicSeedAddress, canonicalL2ProxyAdminAddress, bytes(""))
)
),
canonicalL2FactoryAddress
);
return _getProxyAddress(_getL2Salt(OrbitSalts.L2_WETH_GATEWAY_LOGIC), _getL2Salt(OrbitSalts.L2_WETH_GATEWAY));
}

function getCanonicalL2WethAddress() public view returns (address) {
address logicSeedAddress = Create2.computeAddress(
_getL2Salt(OrbitSalts.L2_WETH_LOGIC),
keccak256(type(CanonicalAddressSeed).creationCode),
canonicalL2FactoryAddress
);

return Create2.computeAddress(
_getL2Salt(OrbitSalts.L2_WETH),
keccak256(
abi.encodePacked(
type(TransparentUpgradeableProxy).creationCode,
abi.encode(logicSeedAddress, canonicalL2ProxyAdminAddress, bytes(""))
)
),
canonicalL2FactoryAddress
);
return _getProxyAddress(_getL2Salt(OrbitSalts.L2_WETH_LOGIC), _getL2Salt(OrbitSalts.L2_WETH));
}

/**
Expand Down Expand Up @@ -496,6 +424,27 @@ contract L1AtomicTokenBridgeCreator is Initializable, OwnableUpgradeable {
return IInbox(inbox).bridge().rollup().owner();
}

/**
* L2 contracts are deployed as proxy with dummy seed logic contracts using CREATE2. That enables
* us to upfront calculate the expected canonical addresses.
*/
function _getProxyAddress(bytes32 logicSalt, bytes32 proxySalt) internal view returns (address) {
address logicSeedAddress = Create2.computeAddress(
logicSalt, keccak256(type(CanonicalAddressSeed).creationCode), canonicalL2FactoryAddress
);

return Create2.computeAddress(
proxySalt,
keccak256(
abi.encodePacked(
type(TransparentUpgradeableProxy).creationCode,
abi.encode(logicSeedAddress, canonicalL2ProxyAdminAddress, bytes(""))
)
),
canonicalL2FactoryAddress
);
}

/**
* We want to have exactly one set of canonical token bridge contracts for every rollup. For that
* reason we make rollup's inbox address part of the salt. It prevents deploying more than one
Expand Down

0 comments on commit a93fef9

Please sign in to comment.