0.5.3 • Published 1 year ago

yulerc20 v0.5.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Yul ERC20

NOT MEANT FOR PRODUCTION - UNAUDITED - USE AT OWN RISK

ERC20 implementations using only inline assembly YUL. Basically, hyper gas optimized ERC20 base implementations for solidity developers. It improves on gas consupmtion for every public / external method over the leading ERC20.sol implementations (OpenZeppelin, Solmate). Optimizing view/pure calls can matter too, as many ERC20 view methods get used inside of state changing methods. See below for full gas comparison.

Note that there are two separate slightly differing implementations ERC20.sol and ERC20External.sol in this repository. Use ERC20External.sol for additional gas savings if your ERC20 doesn't need internal (i.e. same contract including inheritors) access to any of these functions: transfer(), transferFrom(), approve(), allowance(), balanceOf(), nonces(), totalSupply(), name(), symbol(), decimals(). All the basic getter functions can still be accessed easily via internal state variables and so are not needed, and the remaining functions are usually not needed as an internal subroutine; thus most ERC20s, especially simple ones, should benefit from the ERC20External.sol implementation gas savings. For those that want to utilize any of the listed functions in thier contracts that inherit and extend the base implementation, they can use ERC20.sol instead (gas usage only increases by 0-100 gas in most functions).

This is also useful as a reference implementation to learn the basics of inline assembly if you are already familiar with canonical solidity ERC20 implementations. There are comments with solidity translations for lines in yul.

Usage

install with

npm install yulerc20

then you could import this as your base ERC20 contract implementation:

import {ERC20} from "yulerc20/contracts/ERC20.sol";

or

import {ERC20External} from "yulerc20/contracts/ERC20External.sol";

STILL HIGHLY EXPERIMENTAL - NOT YET MEANT FOR PRODUCTION

Test

fill in ALCHEMY_ID in a .env (see .env.example for all environment vars)

yarn

yarn compile

yarn test

Gas Comparison

  • Solc version: 0.8.13
  • Optimizer enabled: true
  • Runs: 999999

approve

ContractGas Cost
OpenZeppelinERC2046232
SolmateERC2046153
YulERC2046080
YulERC20External46008

permit

ContractGas Cost
SolmateERC2074172
YulERC2073774
YulERC20External73762

transfer

ContractGas Cost
OpenZeppelinERC2051496
SolmateERC2051251
YulERC2051167
YulERC20External51073

transferFrom

ContractGas Cost
OpenZeppelinERC2033697
SolmateERC2031995
YulERC2031748
YulERC20External31688

allowance

ContractGas Cost
OpenZeppelinERC2024578
SolmateERC2024557
YulERC2024557
YulERC20External24503

balanceOf

ContractGas Cost
OpenZeppelinERC2023993
SolmateERC2023984
YulERC2023987
YulERC20External23939

burn

ContractGas Cost
OpenZeppelinERC2028900
SolmateERC2028768
YulERC2028646
YulERC20External28646

decimals

ContractGas Cost
OpenZeppelinERC2021286
SolmateERC2021313
YulERC2021286
YulERC20External21262

mint

ContractGas Cost
OpenZeppelinERC2051317
SolmateERC2051194
YulERC2051118
YulERC20External51118

name

ContractGas Cost
OpenZeppelinERC2024284
SolmateERC2024276
YulERC2021571
YulERC20External21281

symbol

ContractGas Cost
OpenZeppelinERC2024282
SolmateERC2024274
YulERC2021580
YulERC20External21279

totalSupply

ContractGas Cost
OpenZeppelinERC2023413
SolmateERC2023427
YulERC2023413
YulERC20External23385
0.5.3

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.2

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago