CREATE3
should have a way of call getDeployed
with an address?
#678
Answered
by
eugenioclrc
eugenioclrc
asked this question in
Q&A
-
What if i want to predict a create3 deployed contract from an specific address and a salt? |
Beta Was this translation helpful? Give feedback.
Answered by
eugenioclrc
Oct 25, 2023
Replies: 2 comments 4 replies
-
Something like this: /// @dev Returns the deterministic address for `salt` and a `deployer` address.
function getDeployed(bytes32 salt, address deployer) internal pure returns (address deployed) {
/// @solidity memory-safe-assembly
assembly {
// Cache the free memory pointer.
let m := mload(0x40)
// Store `deployer`.
mstore(0x00, deployer)
// Store the prefix.
mstore8(0x0b, 0xff)
// Store the salt.
mstore(0x20, salt)
// Store the bytecode hash.
mstore(0x40, _PROXY_BYTECODE_HASH)
// Store the proxy's address.
mstore(0x14, keccak256(0x0b, 0x55))
// Restore the free memory pointer.
mstore(0x40, m)
// 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x01).
// 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex).
mstore(0x00, 0xd694)
// Nonce of the proxy contract (1).
mstore8(0x34, 0x01)
deployed := keccak256(0x1e, 0x17)
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Vectorized
-
Nice heads up. Gonna add it. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something like this: