Skip to content

OmniBTC/go-aptos-liquidswap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

A go sdk for liquidswap on aptos.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages