GithubHelp home page GithubHelp logo

amm_pool's Introduction

AMM Pool - Smart Contract for Automated Market Making

This repository contains the smart contract code for an Automated Market Making (AMM) pool. The AMM pool facilitates decentralized token exchange between supported tokens.

The smart contract relies on PSP22 implementation.

This contract is based on Balancer multi asset LP design and all formulas are taken from the Balancer's whitepaper

Features:

  • Swap functionality to exchange tokens within the pool.
  • Liquidity provisioning for users to contribute to the pool and earn rewards. (Can be added later)
  • Fee collection on swaps to incentivize liquidity providers. (Can be added later)
  • Permissioned withdrawal for authorized accounts to remove liquidity.

Getting Started

Prerequisites

- Rust programming language with tools installed ([Rust compiler, Cargo package manager](https://doc.rust-lang.org/cargo/getting-started/installation.html))
- Cargo contract (https://github.com/paritytech/cargo-contract)
- Familiarity with smart contract development principles

Clone the Repository

git clone https://github.com/inkdevhub/amm_pool.git

Build

cd amm_pool
cargo contract build --release

Test

cargo test

Usage

Swapping Tokens:

Use the swap(token_in, token_out, amount_token_in, min_amount_token_out) function to exchange tokens within the pool, where:

  • token_in: The token type being provided for the swap (PSP22 token address).
  • token_out: The token type desired in return for the swap (PSP22 token address).
  • amount_token_in: The amount of token_in the user is willing to spend (U128 integer representing the amount).
  • min_amount_token_out: The minimum amount of token_out the user expects to receive (U128 integer representing the amount).

Liquidity Management (For Authorized Accounts):

Currently, the provided code doesn't include functionality for liquidity provisioning. However, you can implement features like:

  • A function to deposit tokens into the pool to become a liquidity provider.
  • A function for liquidity providers to withdraw their share of the pool's reserves.
  • Permissions and Configuration (For Authorized Accounts):

The is_authorized(account) function can be used internally to verify if an account has permission to perform specific actions (like withdrawals). The set_swap_fee_percentage(swap_fee_percentage) function allows authorized accounts to adjust the swap fee percentage (if implemented).

Important Notes:

  • Ensure the calling account has granted sufficient allowance to the AMM contract to transfer the specified amount_token_in before calling the swap function.
  • Only authorized accounts (typically the contract owner) can perform actions like withdrawals and fee adjustments.

Disclaimer:

This code example is for educational purposes only and should not be used in production environments without proper testing, security audits, and legal considerations.

amm_pool's People

Contributors

uladaleph avatar

Watchers

Saša Pul avatar Hoon Kim avatar

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.