Is there an example of how to use permission policies and hook permission behaviour with regards to FA2 implementation? https://gitlab.com/tzip/tzip/-/blob/master/proposals/tzip-12/tzip-12.md I am having a hard time wrapping my head around this idea. Does hook require a secondary contract for it to execute? Is there a standard for me to use approvals like in FA1.2 where we can state the amount to transfer instead of giving operator permissions in FA2?
1 Answer
- If you choose a permission policy that supports sender/receiver hooks, token owner contracts (addresses that hold token balances) should implement corresponding entry points (
%tokens_sent
and/or%tokens_received
). Those entry points will be called by the FA2 contract during transfer. There is an example of a simple receiver hook: https://gitlab.com/tzip/tzip/-/blob/fa2-editing/proposals/tzip-12/examples/fa2_custom_receiver.mligo
There is also an example of the FA2 implementation that supports sender/receiver hooks and usage of the receiver hook: https://github.com/tqtezos/smart-contracts/tree/master/fa2_hooks
- Instead of FA1.2 allowances, FA2 uses operators. Operators can transfer ANY token and ANY amount on behalf of the token owner. We analyzed the actual usage of the allowances for both ERC-20 and FA1.2 and found that virtually nobody use them for the granular control. The most frequent use case is to give maximum allowance to the trusted address (operator). ERC-1155 standard also specifies operators instead of allowances.
Although it is possible to create allowance wrapper contract for the FA2 or extend FA2 with the custom permission policy to support allowances.
-
Thanks! The Token Owner Contracts in this case does it mean the FA2 contract that holds the storage of the balance or a tz1 implicit account?– VinnysonCommented Sep 25, 2020 at 21:16
-
How do we use transfer hook if the sender/receiver is a tz1 account? There won't be any %tokens_sent and/or %tokens_received entry points to call– VinnysonCommented Sep 25, 2020 at 21:22
-
Token Owner is either an implicit address or a contract address which has some token balance inside the ledger of the FA2 contract. Commented Sep 27, 2020 at 3:44
-
You are right, you cannot have sender/receiver hooks for the implicit accounts. It is very similar to Ethereum ERC-1155 standard. ERC-1155 allows tokens transfer to contract accounts only if they implement receiver hooks or to any implicit account (EOA - Externally Owned Account in Ethereum terminology) Commented Sep 27, 2020 at 3:50