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.
- Download the
asa_staking.py
script - Install the following dependencies:
$ pip3 install docopt --upgrade
$ pip3 install py-algorand-sdk --upgrade
$ pip3 install pyteal --upgrade
- Create an account on PureStake and get your API token
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
<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!
- Run the ASA Staking dApp on Algorand TestNet adding
-t
after commands. - Run the ASA Staking dApp on Algorand Sandbox passing
""
as<purestake-api-token>
.
Want to provide an ASA Staking dApp for your community? Let's use the create
command:
- Choose the
<asset-id>
- Define the
<locking-blocks>
: users will lock their ASA for this period - Define the
<funding-amount>
: as creator you will fund the ASA Staking dApp
<funding-amount>
must be expressed in ASA minimal units,
taking into accunt ASA decimals positions.
<funding-amount>=100000
(as result of 100 * 10^3).
$ python3 asa_staking.py create <purestake-api-token> <mnemonic> <asset-id> <locking-blocks> <funding-amount>
<mnemonic>
formatting it as: "word_1 word_2 word_3 ... word_25"
and keep it safe!
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
* ====================================================================== *
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>
<mnemonic>
formatting it as: "word_1 word_2 word_3 ... word_25"
and keep it safe!
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!
<booking-amount>
must be expressed in ASA minimal units,
taking into accunt ASA decimals positions.
<booking-amount>=50000
(as result of 50 * 10^3).
$ python3 asa_staking.py booking <purestake-api-token> <mnemonic> <app-id> <booking-amount>
<mnemonic>
formatting it as: "word_1 word_2 word_3 ... word_25"
and keep it safe!
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! ️🔐⌛
* ====================================================================== *
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>
<mnemonic>
formatting it as: "word_1 word_2 word_3 ... word_25"
and keep it safe!
If you find this solution useful as free and open source learning example, consider tipping the Dev:
XODGWLOMKUPTGL3ZV53H3GZZWMCTJVQ5B2BZICFD3STSLA2LPSH6V6RW3I