Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/philogy/huff-stuff
https://github.com/philogy/huff-stuff
Last synced: 11 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/philogy/huff-stuff
- Owner: Philogy
- Created: 2022-08-02T09:15:29.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-08-09T20:05:56.000Z (over 2 years ago)
- Last Synced: 2023-03-10T19:18:31.129Z (over 1 year ago)
- Language: Solidity
- Size: 24.4 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Huff Stuff
A collection of heavily optimized Huff contrats.
## ERC20
Source: `ERC20.huff`Example use: `src/test/contracts/MockERC20.huff`
**Basic Macros:**
The `_ERC20_SELECTOR_SWITCH` macro inserts the ERC20 selector switch into your
code. It takes 1 stack argument, the selector and returns it, meaning the macro
can seamlessly be added to an existing selector switch. Example:```huff
GET_SELECTOR()
dup1 __FUNC_SIG(mint) eq mint jumpi
dup1 _ERC20_SELECTOR_SWITCH(decimals, symbol, name)
__FUNC_SIG(burn) eq burn jumpi
```The `_ERC20_SELECTOR_SWITCH` macro takes the token's decimals and 2 jump labels
as macro arguments. The first jump label being the logic returning the token's
symbol and the second the name.**Minting / Burning:**
In order to mint / burn tokens in the constructor or elsewhere use the
`ERC20_SAFE_BURN` and `ERC20_SAFE_MINT` macros. They take 2 stack arguments:
\[amount, account\]. They're called "safe" because they do overflow / underflow
checking, meaning that if only these methods are used to adjust the supply,
balances and the total supply cannot not overflow / underflow.The two macros also take 2 macro arguments `mem1` and `mem2`. These are meant
to be free memory pointers whereby `mem2 = 0x20 + mem1`, `mem2` is passed as a
macro argument to avoid having to calculate it via `mem1 0x20 add` at runtime.**Other Macros:**
The `ERC20.huff` library currently has no other macros for retrieving
balance / allowance / total supply internally. They may however be added in the
future.**Storage layout:**
Variable|Slot
------|------
totalSupply|`SLOT_TOTAL_SUPPLY`
balanceOf(account)|`keccak256(SLOT_BALANCE_OF . account)`
allowance(owner, spender)|`keccak256(SLOT_ALLOWANCE . spender . owner)`