Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fox-one/4swap-sdk-go
4swap go sdk
https://github.com/fox-one/4swap-sdk-go
go mixin swap uniswap
Last synced: about 2 months ago
JSON representation
4swap go sdk
- Host: GitHub
- URL: https://github.com/fox-one/4swap-sdk-go
- Owner: fox-one
- License: mit
- Created: 2020-09-14T02:42:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-15T14:34:21.000Z (3 months ago)
- Last Synced: 2024-11-01T09:42:40.382Z (2 months ago)
- Topics: go, mixin, swap, uniswap
- Language: Go
- Homepage: https://github.com/fox-one/4swap-sdk-go/blob/master/docs/api.md
- Size: 209 KB
- Stars: 17
- Watchers: 6
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-mixin - 4swap SDK - A SDK designed to help you make your dApps that interact with 4swap. You can get market information, place order, add or remove liquidity from 4swap with it. (SDK / Related Libraries)
README
# 4swap SDK go
## 4swap
[4swap](https://4swap.org) is a decentralized protocol implement for automated liquidity provision on [Mixin Network](https://mixin.one)
## Install
```bash
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](https://developers.mixin.one/docs/dapp/guide/generate-jwt-token) for more details.### Example
```golang
func TestPreOrder(t *testing.T) {
ctx := context.Background()c := New()
c.UseToken("your auth token")
pairs, err := c.ListPairs(ctx)
if err != nil {
t.Fatal(err)
}
req := &PreOrderReq{
PayAssetID: "4d8c508b-91c5-375b-92b0-ee702ed2dac5",
FillAssetID: "31d2ea9c-95eb-3355-b65b-ba096853bc18",
PayAmount: decimal.NewFromFloat(0.1),
}
preOrder, err := PreOrderWithPairs(pairs, req)
if err != nil {
t.Fatal(err)
}
t.Logf("fill amount: %s", preOrder.FillAmount)
followID := uuid.NewString()
minAmount := preOrder.FillAmount.Mul(decimal.NewFromFloat(0.99)).Truncate(8)
memo := BuildSwap(followID, req.FillAssetID, preOrder.Paths, minAmount)
t.Logf("memo: %s", memo)
group, err := c.ReadGroup(ctx)
if err != nil {
t.Fatal(err)
}
t.Logf("target mix address: %s", group.MixAddress)
transfer := &mixin.TransferInput{
AssetID: req.PayAssetID,
OpponentID: group.MixAddress,
Amount: req.PayAmount,
TraceID: followID,
Memo: memo,
}
t.Log(mixin.URL.SafePay(transfer))
// transfer pay asset to mix address
// view order detail
order, err := c.ReadOrder(ctx, followID)
if err != nil {
assert.True(t, IsErrorCode(err, 401))
} else {
t.Logf("order state: %s", order.State)
}
}
```