Created
July 24, 2022 00:45
-
-
Save devtooligan/5eb1eb5094af8b77da9b547b7b1dfef9 to your computer and use it in GitHub Desktop.
Huff -- Inheritance pattern for CONSTRUCTOR() / MAIN()
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 is the main file that will be compiled | |
/* Imports */ | |
#include "./ERC20.huff" | |
#include "./utils/Ownable.huff" | |
#define macro CONSTRUCTOR() = takes (0) returns (0) { | |
OWNABLE_CONSTRUCTOR() | |
ERC20_CONSTRUCTOR() | |
} | |
#define macro MAIN() = takes (0) returns (0) { | |
ERC20_MAIN() | |
OWNABLE_MAIN() | |
0x00 0x00 revert | |
} |
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 is a partial file, only relevant fns are shown, constructor() and main() | |
#define macro ERC20_CONSTRUCTOR() = takes(0) returns (0) { | |
chainid [INITIAL_CHAIN_ID] sstore // [] | |
COMPUTE_DOMAIN_SEPARATOR() // [DOMAIN SEPARATOR] | |
[INITIAL_DOMAIN_SEPARATOR] sstore // [] | |
} | |
#define macro ERC20_MAIN() = takes(0) returns (0) { | |
NON_PAYABLE() | |
// Identify which function is being called. | |
0x00 calldataload 0xE0 shr // [fn sig] | |
dup1 __FUNC_SIG(transfer) eq transferJump jumpi | |
dup1 __FUNC_SIG(transferFrom) eq transferFromJump jumpi | |
dup1 __FUNC_SIG(mint) eq mintJump jumpi | |
dup1 __FUNC_SIG(balanceOf) eq balanceOfJump jumpi | |
done jump | |
transferJump: | |
TRANSFER() | |
transferFromJump: | |
TRANSFER_FROM() | |
mintJump: | |
MINT() | |
balanceOfJump: | |
BALANCE_OF() | |
done: | |
} |
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 is a partial file, only relevant fns are shown, constructor() and main() | |
#define macro OWNABLE_CONSTRUCTOR() = takes (0) returns (0) { | |
caller [OWNER_POINTER] sstore | |
} | |
#define macro OWNABLE_MAIN() = takes(0) returns (0) { | |
// Identify which function is being called. | |
0x00 calldataload 0xE0 shr | |
dup1 0xa9059cbb eq onlyOwner jumpi | |
dup1 0x40c10f19 eq setOwner jumpi | |
done jump // NOTE: Does not revert if not found | |
ownlyOwner: | |
OWNLYOWNER() | |
setOwner: | |
SETOWNER() | |
done: | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment