Reference implementation for a Transfer-controlled Algorand Standard Asset
(TC-ASA), which extends an ASA to provide custom or more granular control around
transfer, mint and burn operations.
It implements the following:
- Setting a "global freeze" flag, that prevents all token transfers.
- Individually whitelisting/locking users.
Can be extended to implement any form of control over the transfer of the token, e.g.:
- Requiring the payment of royalties when transferring the token.
- Restricting the minimum or maximum balance per user, the overall number of token holders, etc.
- Implementing vesting or minimum lock periods.
- Enabling allowance.
The TC-ASA ties together:
- An Algorand Standard Asset (ASA), created with the
defaultFrozenflag set to prevents allxferoperations. - An Algorand Smart Contract (ASC), which holds the
clawback,freeze,managerandreserveroles over the ASA.
All operations on the ASA require an application call to the ASC. For instance,
a call to the ABI method transfer(account,uint64,asset) will transfer uint64
units of the asset (the ASA) from the transaction Sender to account (the
recipient). Under the hood, the ASC creates an inner clawback transaction
(itxn) that moves the ASA.
The transfer method provides the fundamental building block for all other
operations. For instance, if implementing royalties you would extend transfer
so that it also checks for an additional payment to the royalty owner (e.g.
through a group transfer):
transfer(account,uint64,asset): Transferuint64units ofasset(must be a reference to the TC-ASA) fromSendertoaccount.
The following methods can only be invoked by the master account, which defaults
to the ASC creator:
init(asset): Initializes the TC-ASA by clawing back the total ASA supply into the account managed by this ASC (theReserve). Can only be called once.mint(account,uint64,asset): Mintsuint64units ofassetfromReservetoaccount.burn(account,uint64,asset): Burnsuint64units ofassetfromaccounttoReserve.setWhitelist(account,bool): Sets thewhitelistedflag ofaccount.whitelistedmust betrueto receive funds.setLock(account,bool): Sets thelockedflag ofaccount.lockedmust befalsetotransferfunds.setFreeze(bool): Sets the globalfrozenflag.frozenmust befalseto issuemintortransferoperations.
masteronly can update the ASC.- Anyone can
opt-into the ASC. closeout,clearanddeletewillrejectany transaction.- WARNING: Clearing the application state for a user with outstanding funds
will prevent them from calling
transfer.
- WARNING: Clearing the application state for a user with outstanding funds
will prevent them from calling
WARNING: This implementation has not been security-audited.
- The file
tc_asa.pyprovides the PyTeal implementation and, if executed, writes the TEAL contract to/tmp/tc_asa.teal. - The file
deploy.pyprovides helpers to deploy the ASA and the ASC to the network.- By default, it will run against an Algorand sandbox endpoints.
- Will print the JSON ABI specification to
/tmp/contract.json.
Use the @ABI.method(interface: dict) decorator to add new methods to the
contract. interface must be a Python dictionary encoding an ARC-4 method
description.