Lorca-R / 4swap-sdk-go

4swap go sdk

Home Page:https://github.com/fox-one/4swap-sdk-go/blob/master/docs/api.md

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

4swap SDK go

4swap

4swap is a decentralized protocol implement for automated liquidity provision on Mixin Network

Authorization

4swap supports two kinds of access tokens:

  1. the access token that complete the OAuth flow at 4swap's webpage: https://app.4swap.org
  2. the access token that generated by your own Mixn Application. The token should sign the URL /me and the scope should be "FULL". Please read this document for more details.

Example

func TestMtgSwap(t *testing.T) {
    const (
        btc   = "c6d0c728-2624-429b-8e0d-d9d19b6592fa"
        xin   = "c94ac88f-4671-3976-b60a-09064f1811e8"
        token = "your authorization token"
    )
    
    ctx := context.Background()
    fswap.UseEndpoint(fswap.MtgEndpoint)
    
    group, err := fswap.ReadGroup(ctx)
    if err != nil {
        t.Fatal(err)
    }
    
    me, err := mixin.UserMe(ctx, token)
    if err != nil {
        t.Fatal(err)
    }
    
    followID, _ := uuid.NewV4()
    action := mtg.SwapAction(
        me.UserID,
        followID.String(),
        btc,
        "", // leave the routes field as empty to let the engine decide the route. 
        decimal.NewFromFloat(0.1),
    )
    
    memo, err := action.Encode(group.PublicKey)
    if err != nil {
        t.Fatal(err)
    }
    
    t.Log(memo)
    
    // use mixin-sdk-go or bot-api-client-go to transfer to 4swap's multisig address
    
    // query the order.
    ctx = fswap.WithToken(ctx, token)
    order, err := fswap.ReadOrder(ctx, followID.String())
    if err != nil {
        t.Fatal(err)
    }
    
    t.Log(order.State)
}

About

4swap go sdk

https://github.com/fox-one/4swap-sdk-go/blob/master/docs/api.md

License:MIT License


Languages

Language:Go 100.0%