Coder Social home page Coder Social logo

go-aptos-liquidswap's Introduction

go-aptos-liquidswap

Go Go Report Card License: MIT

A go sdk for liquidswap on aptos.

Install

go get github.com/omnibtc/go-aptos-liquidswap

Usage

Get amount out:

amountOut := GetAmountOut(
    Coin{Symbol: "USDT", Decimal: 6},
    Coin{Symbol: "BTC", Decimal: 8},
    big.NewInt(1000000),
    PoolResource{
        CoinXReserve: big.NewInt(10415880990),
        CoinYReserve: big.NewInt(3004784231600),
        CurveType: Uncorellated,
    },
)

Calc amount min out:

amountMinOut := AmountMinOut(amountOut, decimal.NewFromFloat(0.005))

Get amount in:

amountIn := GetAmountIn(
    Coin{Symbol: "USDT", Decimal: 6},
    Coin{Symbol: "BTC", Decimal: 8},
    big.NewInt(1000000),
    PoolResource{
        CoinXReserve: big.NewInt(10415880990),
        CoinYReserve: big.NewInt(3004784231600),
    },
)

Get amount max in:

amountMaxOut := AmountMaxIn(amountIn, decimal.NewFromFloat(0.005))

Use StableCurve

liquidswap pool type can be StableCurve for stable coins swap.

amountIn := GetAmountIn(
    Coin{Symbol: "USDT", Decimal: 6},
    Coin{Symbol: "USDC", Decimal: 6},
    big.NewInt(1000000),
    PoolResource{
        CoinXReserve: big.NewInt(81442051331),
        CoinYReserve: big.NewInt(136352475461),
        CurveType:    StableCurve,    // USDT-USDC pool is StableCurve
    },
)

Create payload info:

params := &SwapParams{
        Script:           "0x123::scripts",
        FromCoin:         "0x123::BTC",
        ToCoin:           "0x123::APT",
        FromAmount:       big.NewInt(1),
        ToAmount:         big.NewInt(266607),
        InteractiveToken: "from",  // from|to, from - exactIn  to - exactOut
        Slippage:         decimal.NewFromFloat(0.005),
        Pool: Pool{
            LpToken:       "0x123::lp<0x123::APT,0x123::BTC>",
            ModuleAddress: "0x1234",
            Address:       "0x12345",
        },
    }
payload, err := CreateSwapPayload(params)

go-aptos-liquidswap's People

Contributors

xiang-xx 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.