Last active
December 23, 2023 11:46
-
-
Save charles-cooper/1bc936d7e67af0d57d5df3f54276eb2b to your computer and use it in GitHub Desktop.
permit demo
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
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 |
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
# 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[...][...] += ... |
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
# 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