Repository navigation
feat(oft): deploy OFT proxies via CreateX CREATE3 for cross-chain deterministic addresses #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ocakciomursel-pixel
wants to merge
2
commits into
GoodDollar:master
from
ocakciomursel-pixel:feat/oft-createx-deploy
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { ethers } from 'hardhat'; | ||
|
|
||
| /** | ||
| * Canonical CreateX universal factory address deployed across EVM chains (Celo, XDC, Ethereum, Fuse, etc.). | ||
| * @see https://github.com/pcaversaccio/createx | ||
| */ | ||
| export const CREATEX_ADDRESS = '0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed'; | ||
|
|
||
| /** | ||
| * Keccak-256 hash of CreateX's 16-byte CREATE3 child proxy initcode (`0x67363d3d37363d34f03d5260086018f3`). | ||
| */ | ||
| export const CREATE3_PROXY_INITCODE_HASH = '0x21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f'; | ||
|
|
||
| export const CREATEX_ABI = [ | ||
| 'function deployCreate3AndInit(bytes32 salt, bytes initCode, bytes data, tuple(uint256 constructorAmount, uint256 initCallAmount) values) payable returns (address newContract)', | ||
| // Note: CreateX's on-chain computeCreate3Address(bytes32) does NOT run _guard(salt); it expects the post-guard salt | ||
| // produced by guardCreateXSalt(deployer, rawSalt), whereas deployCreate3AndInit takes the raw salt and calls _guard(salt). | ||
| 'function computeCreate3Address(bytes32 salt) view returns (address computedAddress)', | ||
| 'function computeCreate3Address(bytes32 salt, address deployer) pure returns (address computedAddress)', | ||
| ]; | ||
|
|
||
| /** | ||
| * Builds a 32-byte CreateX salt with sender-permissioned deploy protection and cross-chain address consistency: | ||
| * - bytes 0..19 (20 bytes): `deployer` address (`SenderBytes.MsgSender` — only `deployer` can produce the guarded salt) | ||
| * - byte 20 (1 byte): `0x00` (`RedeployProtectionFlag.False` — omits `block.chainid` so the address is identical across all chains) | ||
| * - bytes 21..31 (11 bytes): first 11 bytes of `keccak256(utf8(label))` | ||
| */ | ||
| export function buildCreateXSalt(deployer: string, label: string): string { | ||
| const entropy = ethers.utils.hexDataSlice(ethers.utils.id(label), 0, 11); | ||
| return ethers.utils.solidityPack(['address', 'uint8', 'bytes11'], [ethers.utils.getAddress(deployer), 0, entropy]); | ||
| } | ||
|
|
||
| /** | ||
| * Computes the post-`_guard(salt)` value that CreateX derives internally in `deployCreate3*` when | ||
| * `msg.sender == deployer` and `salt[20] == 0x00`: | ||
| * `_efficientHash(bytes32(uint256(uint160(msg.sender))), salt)` == `keccak256(abi.encode(deployer, salt))`. | ||
| * Note: CreateX's view function `computeCreate3Address(bytes32)` does NOT apply `_guard`, so callers of | ||
| * `computeCreate3Address(bytes32)` must pass this guarded salt, while `deployCreate3AndInit` takes the raw salt. | ||
| */ | ||
| export function guardCreateXSalt(deployer: string, salt: string): string { | ||
| const normalizedDeployer = ethers.utils.getAddress(deployer); | ||
| const saltPrefix = ethers.utils.getAddress(ethers.utils.hexDataSlice(salt, 0, 20)); | ||
| if (saltPrefix !== normalizedDeployer) { | ||
| throw new Error(`CreateX salt sender prefix mismatch: expected ${normalizedDeployer}, got ${saltPrefix}`); | ||
| } | ||
| const redeployFlag = ethers.utils.hexDataSlice(salt, 20, 21); | ||
| if (redeployFlag !== '0x00') { | ||
| throw new Error(`CreateX cross-chain redeploy protection must be 0x00 for cross-chain deterministic addresses, got ${redeployFlag}`); | ||
| } | ||
| return ethers.utils.keccak256( | ||
| ethers.utils.defaultAbiCoder.encode(['address', 'bytes32'], [normalizedDeployer, salt]), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Deterministically computes the CREATE3 deployment address for a sender-guarded CreateX salt. | ||
| * Depends only on `createXAddress`, `deployer`, and `salt` (independent of chain ID and contract bytecode). | ||
| */ | ||
| export function computeCreateXCreate3Address( | ||
| deployer: string, | ||
| salt: string, | ||
| createXAddress: string = CREATEX_ADDRESS, | ||
| ): string { | ||
| const guardedSalt = guardCreateXSalt(deployer, salt); | ||
| const proxyChild = ethers.utils.getCreate2Address(createXAddress, guardedSalt, CREATE3_PROXY_INITCODE_HASH); | ||
| return ethers.utils.getContractAddress({ from: proxyChild, nonce: 1 }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.