Skip to content

Instantly share code, notes, and snippets.

@charles-cooper
Last active December 23, 2023 11:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charles-cooper/1bc936d7e67af0d57d5df3f54276eb2b to your computer and use it in GitHub Desktop.
Save charles-cooper/1bc936d7e67af0d57d5df3f54276eb2b to your computer and use it in GitHub Desktop.
permit demo
allowances: HashMap[address, HashMap[address, uint256]]
balanceOf: HashMap[address, uint256]
totalSupply: uint256
bundle: ERC20Bundle
def __init__():
... # do things with initializing and totalSupply
@external
@bundle(ERC20Bundle, bind=True) # bind=True indicates transfer cannot be exported on its own, only as part of ERC20Bundle
def transfer(...):
... # implementation
@external
@bundle(ERC20Bundle, bind=True)
def transferFrom(...):
... # implementation
@external
@bundle(ERC20Bundle, bind=True)
def approve(...):
... # implementation
... # etc
# permit.vy
import ERC20Implementation as token
_erc20: token
nonces: HashMap[address, uint256]
export: _erc20.ERC20Bundle
def __init__():
self._erc20.__init__(...)
@external
def permit():
nonce: uint256 = self.nonces[owner]
... # do digest and verify sig
self.nonces[_owner] += 1
self._erc20.allowances[...][...] += ...
# the final token contract implemented by a user of the library
import permit
p: permit
export: p.ERC20Bundle, p.permit
def __init__():
self.p.__init__(...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment