Skip to content

tommiful/asa-recurring-withdrawal-dApp

Repository files navigation

ASA recurring withdrawal dApp

The solution architecture relies on Algorand Standard Asset (ASA), Atomic Transfers (AT) and Stateful & Stateless Smart Contracts (ASC1), whose source code is provided both in TEAL and PyTeal.

Check out the whole solution.

ASA Staking CLI

1. Setup

  1. Download the asa_staking.py script
  2. Install the following dependencies:
$ pip3 install docopt --upgrade
$ pip3 install py-algorand-sdk --upgrade
$ pip3 install pyteal --upgrade
  1. Create an account on PureStake and get your API token

2. CLI usage

Using the ASA Staking dApp from your CLI is pretty easy, just ask for help:

$ python3 asa_staking.py -h
Usage:
  asa_staking.py create <purestake-api-token> <mnemonic> <asset-id> <locking-blocks> <funding-amount> [--test]
  asa_staking.py info <purestake-api-token> <app-id> [--test]
  asa_staking.py join <purestake-api-token> <mnemonic> <app-id> [--test]
  asa_staking.py booking <purestake-api-token> <mnemonic> <app-id> <booking-amount> [--test]
  asa_staking.py status <purestake-api-token> <account> <app-id> [--test]
  asa_staking.py withdraw <purestake-api-token> <mnemonic> <app-id> [--test]
  asa_staking.py [--help]

Commands:
  create      Create new decentalized ASA staking application.
  info        Decentalized ASA staking application info.
  join        Join a decentalized ASA staking application.
  booking     Book and deposit a staking amount.
  status      Check your staking status.
  withdraw    Withdraw staked amount with rewards.

Options:
  -t --test   Use Algorand TestNet.
  -h --help

⚠️ Keep your <mnemonic> safe! Although you will only use it on you local machine, is it strongly recommended to make use of a dedicated account just to interact with the ASA Staking dApp!

Testing Mode

  1. Run the ASA Staking dApp on Algorand TestNet adding -t after commands.
  2. Run the ASA Staking dApp on Algorand Sandbox passing "" as <purestake-api-token>.

3. Create your own ASA Staking dApp

Want to provide an ASA Staking dApp for your community? Let's use the create command:

  1. Choose the <asset-id>
  2. Define the <locking-blocks>: users will lock their ASA for this period
  3. Define the <funding-amount>: as creator you will fund the ASA Staking dApp

⚠️ Note that the <funding-amount> must be expressed in ASA minimal units, taking into accunt ASA decimals positions.

⚠️ Example: if ASA Decimals = 3, then to fund the dApp with 100 ASA units you must enter <funding-amount>=100000 (as result of 100 * 10^3).

$ python3 asa_staking.py create <purestake-api-token> <mnemonic> <asset-id> <locking-blocks> <funding-amount>

⚠️ Enter the the <mnemonic> formatting it as: "word_1 word_2 word_3 ... word_25" and keep it safe!

4. ASA Staking dApp info

The given an <app-id> you can display ASA Staking dApp info:

$ python3 asa_staking.py info <purestake-api-token> <app-id>
* ======================== STAKING dAPP SUMMARY ======================== *

       APP ID:	123
       ASA ID:	4
       ESCROW:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

       LOCKING BLOCKS:	⏳ 250000
       BOOKABLE FUNDS:	💰 1000000

* ====================================================================== *

5. Join the ASA Staking dApp

As a user you can join the ASA Staking dApp identified by its <app-id>:

$ python3 asa_staking.py join <purestake-api-token> <mnemonic> <app-id>

⚠️ Enter the the <mnemonic> formatting it as: "word_1 word_2 word_3 ... word_25" and keep it safe!

6. Stake your ASA

As a user you can stake your ASA depositing a <booking-amount> of ASA in the ASA Staking dApp identified by its <app-id>, wait the locking blocks and withdraw the doubled staked amount!

⚠️ Note that the <booking-amount> must be expressed in ASA minimal units, taking into accunt ASA decimals positions.

⚠️ Example: if ASA Decimals = 3, then to stake 50 ASA units you must ener <booking-amount>=50000 (as result of 50 * 10^3).

$ python3 asa_staking.py booking <purestake-api-token> <mnemonic> <app-id> <booking-amount>

⚠️ Enter the the <mnemonic> formatting it as: "word_1 word_2 word_3 ... word_25" and keep it safe!

7. Check your staking status

Monitor the status of your <account> in the ASA Staking dApp identified by its <app-id>:

$ python3 asa_staking.py status <purestake-api-token> <account> <app-id>
* ======================= BOOKED STAKING SUMMARY ======================= *

           APP ID:	123
           ASA ID:	4

           BOOKED AMOUNT:	42
           REMANING LOCK:	Withdrawal ready! ️🔐⌛

* ====================================================================== *

8. Withdraw your staked ASA

As a user you can withdraw your staked ASA from the ASA Staking dApp identified by its <app-id> once the locking period expires:

$ python3 asa_staking.py withdraw <purestake-api-token> <mnemonic> <app-id>

⚠️ Enter the the <mnemonic> formatting it as: "word_1 word_2 word_3 ... word_25" and keep it safe!

Tip the Dev

If you find this solution useful as free and open source learning example, consider tipping the Dev:

XODGWLOMKUPTGL3ZV53H3GZZWMCTJVQ5B2BZICFD3STSLA2LPSH6V6RW3I

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages