-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Make
CreateAddress
Module-Friendly (#224)
### 🕓 Changelog This PR refactors the `CreateAddress` contract to make it module-friendly and ready for the breaking `0.4.0` release. --------- Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
- Loading branch information
1 parent
b26a9f3
commit 7207431
Showing
6 changed files
with
118 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,59 @@ | ||
# pragma version ~=0.4.0b5 | ||
""" | ||
@title CreateAddress Module Reference Implementation | ||
@custom:contract-name CreateAddressMock | ||
@license GNU Affero General Public License v3.0 only | ||
@author pcaversaccio | ||
""" | ||
|
||
|
||
# @dev We import and initialise the `CreateAddress` module. | ||
from .. import CreateAddress as ca | ||
initializes: ca | ||
|
||
|
||
@deploy | ||
@payable | ||
def __init__(): | ||
""" | ||
@dev To omit the opcodes for checking the `msg.value` | ||
in the creation-time EVM bytecode, the constructor | ||
is declared as `payable`. | ||
""" | ||
ca.__init__() | ||
|
||
|
||
@external | ||
@view | ||
def compute_address_rlp_self(nonce: uint256) -> address: | ||
""" | ||
@dev Returns the address where a contract will be stored if | ||
deployed via this contract using the `CREATE` opcode. | ||
@param nonce The 32-byte account nonce of this contract. | ||
@return address The 20-byte address where a contract will be stored. | ||
""" | ||
return ca._compute_address_rlp_self(nonce) | ||
|
||
|
||
@external | ||
@pure | ||
def compute_address_rlp(deployer: address, nonce: uint256) -> address: | ||
""" | ||
@dev Returns the address where a contract will be stored | ||
if deployed via `deployer` using the `CREATE` opcode. | ||
For the specification of the Recursive Length Prefix (RLP) | ||
encoding scheme, please refer to p. 19 of the Ethereum | ||
Yellow Paper (https://ethereum.github.io/yellowpaper/paper.pdf) | ||
and the Ethereum Wiki (https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp). | ||
For further insights also, see the following issue: | ||
https://github.com/transmissions11/solmate/issues/207. | ||
Based on the EIP-161 (https://github.com/ethereum/EIPs/blob/master/EIPS/eip-161.md) | ||
specification, all contract accounts on the Ethereum mainnet | ||
are initiated with `nonce = 1`. Thus, the first contract address | ||
created by another contract is calculated with a non-zero nonce. | ||
@param deployer The 20-byte deployer address. | ||
@param nonce The 32-byte account nonce of the deployer address. | ||
@return address The 20-byte address where a contract will be stored. | ||
""" | ||
return ca._compute_address_rlp(deployer, nonce) |
This file contains 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