thesis / solidity-contracts

MIT License
2 stars 1 forks source link

Captain hook: _beforeTokenTransfer #6

Closed pdyraga closed 3 years ago

pdyraga commented 3 years ago

Sometimes, an additional logic needs to be hooked into transfer/burn/mint. One such example is Governor Bravo's _moveDelegates function of a token that needs to be called when tokens are moved between accounts (including burning).

_beforeTokenTransfer hook will let us inject custom logic by overriding just one function instead of having to override burn, burnFrom, transfer, transferFrom, and mint separately.

The idea of beforeTokenTransfer was kindly borrowed from Open Zeppelin's ERC20 token.