NOTE: This code is not audited and should not be used in production environment.
Algo AMM allows you to trade on the outcomes of events, and follow the odds to garner accurate insights about the future.
Liquidity Providers supply stable coins in return for the liquidity shares.
The liquidity lets users to buy or sell Voting Shares, which are redeemed for 1 unit of the stable asset if the outcome is resolved as correct, and become worthless if it’s incorrect.
The core feature of the app is that we protect the owners of Voting shares by keeping the reserves of stable assets, primarily in case of liquidity drain.
The goal is, by harnessing the power of free markets to aggregate collective knowledge and provide the general public with an unbiased source of truth in regards to the likelihood of certain significant events happening in the future.
We wrote contract for Prediction Market Constant Function Automated Market Maker with the help of PyTeal and Py-algorand-sdk.
The front end application is written with react and vite. The repository for the Front-End is avalaible here: https://github.com/dspytdao/algo-amm-frontend
Constant Function Automated Market Maker (AMM) contract provides configuration options and creates a market for an event that has a binary outcome.
Liquidity Pool provides a foundation for users to purchase and redeem spawned tokens once the event has been resolved. The Liquidity Pool supports a constant reserve ratio for stable price discovery and protection from liquidity drain. The liquidity provided allows to spawn two tokens in equal amount in 25%/25% proportion of the liquidity supplied.
The purchase price for each token is determined by equation: x + y = k. Where x is the amount of A tokens in the AMM, y is the amount of B tokens in the AMM.
Once the event has occured the price for one token should resolve to 1, while 0 for another.
Liquidity Shares and Voting Shares can only be released after the creator of the contract moderated the outcome.
- Vscode or another IDE
- Python 3
- PIP Package Manager
- Py-algorand-sdk
- PyTEAL
- Algorand Purestake node api key
PyTeal contracts are written in Python using any editor of your choice. compileProgram
method produces the TEAL code which is then compiled into bytecode and deployed to the blockchain.
The PyTeal smart contract consists of two programs. These are called the approval program and the clear programs. In PyTeal both of these programs are generally created in the same Python file.
The approval_program
is responsible for processing all application calls to the contract, with the exception of the clear call. The program is responsible for implementing most of the logic of an application.
The clear_program
is used to handle accounts using the clear call to remove the smart contract from their balance record.
In amm.py
we keep the high-level logic of the contract, helpers.py
contains lower level methods and config.py
keeps track of global variable and key configuration variables.
Alogrand: Smart contract details
Creating Stateful Algorand Smart Contracts in Python with PyTeal