Git Product home page Git Product logo

tc-asa's Introduction

Transfer-controlled Algorand Standard Asset (TC-ASA)

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.

Design

The TC-ASA ties together:

  • An Algorand Standard Asset (ASA), created with the defaultFrozen flag set to prevents all xfer operations.
  • An Algorand Smart Contract (ASC), which holds the clawback, freeze, manager and reserve roles 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.

ABI methods and calls

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): Transfer uint64 units of asset (must be a reference to the TC-ASA) from Sender to account.

master only

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 (the Reserve). Can only be called once.
  • mint(account,uint64,asset): Mints uint64 units of asset from Reserve to account.
  • burn(account,uint64,asset): Burns uint64 units of asset from account to Reserve.
  • setWhitelist(account,bool): Sets the whitelisted flag of account. whitelisted must be true to receive funds.
  • setLock(account,bool): Sets the locked flag of account. locked must be false to transfer funds.
  • setFreeze(bool): Sets the global frozen flag. frozen must be false to issue mint or transfer operations.

ASC life cycle

  • master only can update the ASC.
  • Anyone can opt-in to the ASC.
  • closeout, clear and delete will reject any transaction.
    • WARNING: Clearing the application state for a user with outstanding funds will prevent them from calling transfer.

Usage

WARNING: This implementation has not been security-audited.

Reference Implementation

  • The file tc_asa.py provides the PyTeal implementation and, if executed, writes the TEAL contract to /tmp/tc_asa.teal.
  • The file deploy.py provides 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.

Customization

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.

Authors

tc-asa's People

Contributors

aldur avatar cusma avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

cusma

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.