Giter VIP home page Giter VIP logo

anchor-uniswap-v2's Introduction

Uniswap V2 AMM implemented in Anchor

  • programs/ammv2/src/draft.rs: outline of program with comments -- drafted before implementation

Supported Instructions

  • programs/ammv2/src/
    • instructions/
      • init_pool.rs: initialize a new pool
      • liqduidity.rs: add and remove liquidity
      • swap.rs: perform a token swap

Implemented Tests

  • tests/ammv2.ts:
    • intialize a new pool
    • add liquidity (x3)
    • remove liquidity
    • swap
    • remove liquidity

anchor-uniswap-v2's People

Contributors

0xnineteen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

anchor-uniswap-v2's Issues

Incorrect Exchange Rate

In the add_liquidity function in liquidity.rs, we have ->

        ...
        let exchange01 = vault_balance0.checked_div(vault_balance1).unwrap();
        let amount_deposit_1 = amount_liq0.checked_mul(exchange01).unwrap();
        ...
        deposit1 = amount_deposit_1; // update liquidity amount ! 

However, In the add_liquidity function in draft.rs, to derive the user_liq1 by using user_liq0, the following is mentioned

        ...      
        // define: depo_user_liq1 = user_liq0 * pool_balance1 / pool_balance0
        ...

I think that the exchange rate in liquidity.rs

        let exchange01 = vault_balance0.checked_div(vault_balance1).unwrap();

should be changed to

        let exchange01 = vault_balance1.checked_div(vault_balance0).unwrap();

Anchor build issues

Hi, when I trying to build the project I got this issues.
error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets
--> src/lib.rs:267:9
|
267 | / compile_error!("
268 | | target is not supported, for more information see:
269 | | https://docs.rs/getrandom/#unsupported-targets\
270 | | ");
| |__________^

Compiling ahash v0.7.6
error[E0433]: failed to resolve: use of undeclared crate or module imp
--> src/lib.rs:291:5
|
291 | imp::getrandom_inner(dest)
| ^^^ use of undeclared crate or module imp

For more information about this error, try rustc --explain E0433.
error: could not compile getrandom (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error[E0422]: cannot find struct, variant or union type LineColumn in crate proc_macro
--> /home/hcrypto/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.36/src/wrapper.rs:485:33
|
485 | let proc_macro::LineColumn { line, column } = s.start();
| ^^^^^^^^^^ not found in proc_macro
|
help: consider importing one of these items
|
1 + use crate::LineColumn;
|
1 + use crate::fallback::LineColumn;
|
help: if you import LineColumn, refer to it directly
|
485 - let proc_macro::LineColumn { line, column } = s.start();
485 + let LineColumn { line, column } = s.start();
|

error[E0422]: cannot find struct, variant or union type LineColumn in crate proc_macro
--> /home/hcrypto/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.36/src/wrapper.rs:502:33
|
502 | let proc_macro::LineColumn { line, column } = s.end();
| ^^^^^^^^^^ not found in proc_macro
|
help: consider importing one of these items
|
1 + use crate::LineColumn;
|
1 + use crate::fallback::LineColumn;
|
help: if you import LineColumn, refer to it directly
|
502 - let proc_macro::LineColumn { line, column } = s.end();
502 + let LineColumn { line, column } = s.end();
|

For more information about this error, try rustc --explain E0422.
error: could not compile proc-macro2 (lib) due to 2 previous errors

How to fix this problems?

Front end integration issue

Hi,

I have checked and run your source code it's working fine on localnet. When i am integrating with frontend on devnet i can't able to initialize the pool. I have integrating which is like in testcase.

error: failed to send transaction: Transaction simulation failed: Error processing Instruction 2: Program failed to complete.

I don't know why the issue is occurs. Please provide a solution.

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.