项目作者: fox-one

项目描述 :
4swap go sdk
高级语言: Go
项目地址: git://github.com/fox-one/4swap-sdk-go.git
创建时间: 2020-09-14T02:42:24Z
项目社区:https://github.com/fox-one/4swap-sdk-go

开源协议:MIT License

下载


4swap SDK go

4swap

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

Install

  1. go get github.com/fox-one/4swap-sdk-go/v2

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

  1. func TestPreOrder(t *testing.T) {
  2. ctx := context.Background()
  3. c := New()
  4. c.UseToken("your auth token")
  5. pairs, err := c.ListPairs(ctx)
  6. if err != nil {
  7. t.Fatal(err)
  8. }
  9. req := &PreOrderReq{
  10. PayAssetID: "4d8c508b-91c5-375b-92b0-ee702ed2dac5",
  11. FillAssetID: "31d2ea9c-95eb-3355-b65b-ba096853bc18",
  12. PayAmount: decimal.NewFromFloat(0.1),
  13. }
  14. preOrder, err := PreOrderWithPairs(pairs, req)
  15. if err != nil {
  16. t.Fatal(err)
  17. }
  18. t.Logf("fill amount: %s", preOrder.FillAmount)
  19. followID := uuid.NewString()
  20. minAmount := preOrder.FillAmount.Mul(decimal.NewFromFloat(0.99)).Truncate(8)
  21. memo := BuildSwap(followID, req.FillAssetID, preOrder.Paths, minAmount)
  22. t.Logf("memo: %s", memo)
  23. group, err := c.ReadGroup(ctx)
  24. if err != nil {
  25. t.Fatal(err)
  26. }
  27. t.Logf("target mix address: %s", group.MixAddress)
  28. transfer := &mixin.TransferInput{
  29. AssetID: req.PayAssetID,
  30. OpponentID: group.MixAddress,
  31. Amount: req.PayAmount,
  32. TraceID: followID,
  33. Memo: memo,
  34. }
  35. t.Log(mixin.URL.SafePay(transfer))
  36. // transfer pay asset to mix address
  37. // view order detail
  38. order, err := c.ReadOrder(ctx, followID)
  39. if err != nil {
  40. assert.True(t, IsErrorCode(err, 401))
  41. } else {
  42. t.Logf("order state: %s", order.State)
  43. }
  44. }