Code Monkey home page Code Monkey logo

solana-pool-amm's Introduction

Solana Coding Camp AMM

  • refactor structure

Backend

  • AMM program x.y=k
  • typescript lib & test
  • npm publish

Notes

  • mỗi pool cung cấp 1 seed

  • các pool nên có tresurer khác nhau

  • x_treasury, y_treasury: luu x, y token

  • để dùng init_if_needed: bật flag trong cargo.toml của anchor-lang

  • chuyển tiền trước khi ghi data: transfer -> ghi pool

Swap logic

  • dst_y_account: account trả token swap cho người dùng, sử dụng init_if_needed: khởi tạo nếu cần

  • transfer lượng a từ ví người dùng vào treasury

  • chuyển ngược lại token swap vào ví người dùng (dst_y_account) với lượng b. authority phải ký giao dịch nên tái tạo seed và sign bằng seed và bump -> call CpiContext:new_with_seed

  • update lại pool

  • tránh overflow - dùng lib num-trails khai báo trong cargo.toml

  • dùng hàm checked_add().ok_or(err), checked_sub().ok_or(err)

  • sử dụng event tăng ux lên

  • khai báo struct event #[event]

  • post event:

emit(CreatePoolEvent { data })
  • tinh toan sử dụng u128 tránh overflow -> cast về lại u64 -> return
  • thực hiện nhân trước chia sau

Testing

  • pre-test

Front-end

  • use IDL

solana-pool-amm's People

Contributors

hongthaipham avatar

Watchers

James Cloos avatar  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.