Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions client/swaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@ func (c *Client) GetSwapByIntentID(ctx context.Context, intentID uuid.UUID) (Get

// ListSwapHistoryParams represents parameters for listing swap history.
type ListSwapHistoryParams struct {
// Limit defines the maximum number of tokens to return.
// Limit defines the maximum number of swaps to return.
Limit int64
// Offset defines the number of tokens to skip.
// Offset defines the number of swaps to skip.
Offset int64
// Active specifies whether to return only active swaps.
Active bool
// Status defines the swap status filter (optional).
Status types.UiStatus
// Network defines the swap network filter (optional).
Network int64
// From defines the swap `from` timestamp filter (optional).
From int64
// To defines the swap `to` timestamp filter (optional).
To int64
// Token defines the swap token filter (optional).
Token string
// Wallets specify addresses filter.
Wallets []string
// RetailID specifies the retail ID filter.
Expand All @@ -47,7 +55,25 @@ func (params *ListSwapHistoryParams) toQueryParams() string {
q.Set("offset", strconv.FormatInt(params.Offset, 10))
}

q.Set("active", strconv.FormatBool(params.Active))
if params.Status != "" {
q.Set("status", string(params.Status))
}

if params.Network != 0 {
q.Set("network", strconv.FormatInt(params.Network, 10))
}

if params.From != 0 {
q.Set("from", strconv.FormatInt(params.From, 10))
}

if params.To != 0 {
q.Set("to", strconv.FormatInt(params.To, 10))
}

if params.Token != "" {
q.Set("token", params.Token)
}

for _, wallet := range params.Wallets {
q.Add("wallet", wallet)
Expand Down
14 changes: 11 additions & 3 deletions examples/get-history/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ package main
import (
"context"
"log"
"time"

"github.com/BoostyLabs/hotpot-sdk-go/client"
"github.com/BoostyLabs/hotpot-sdk-go/examples"
"github.com/BoostyLabs/hotpot-sdk-go/types"
)

const OneDayInMs int64 = 86_400_000

func main() {
ctx := context.Background()

Expand All @@ -16,11 +20,11 @@ func main() {

// INFO: To specify wallet addresses and retailer ID for swap history, set one of env variables:
// - WALLET_ADDRESSES: export WALLET_ADDRESSES=0x1234567890123456789012345678901234567890,bc1pg02klrmyzfkeftcn4j3v2dyly5xh9mpcf5dunxhjst25w7ayu9uq6t2ja0
// - RETAILER_ID: export RETAILER_ID=1234567890
// - RETAIL_ID: export RETAIL_ID=1234567890
//
// NOTE: Only one of these variables should be set.
//
// LIMIT, OFFSET, ACTIVE can be set via env variables.
// LIMIT, OFFSET, NETWORK_ID, TOKEN can be set via env variables.

log.Printf("Getting swap history by addresses: %v", cfg.WalletAddresses)
log.Printf("or by retail id: %s", cfg.RetailID)
Expand All @@ -30,7 +34,11 @@ func main() {
RetailID: cfg.RetailID,
Limit: cfg.Limit,
Offset: cfg.Offset,
Active: cfg.ActiveSwaps,
Status: types.UiStatusSubmitted,
Network: cfg.NetworkID,
From: time.Now().UnixMilli() - OneDayInMs,
To: time.Now().UnixMilli() + OneDayInMs,
Token: cfg.Token,
})
if err != nil {
log.Fatalf("failed to get swap history: %v", err)
Expand Down
20 changes: 20 additions & 0 deletions types/swaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,23 @@ type SwapAdditionalInfo struct {
MinDestAmountLots *Int `json:"min_dest_amount_lots"`
MaxDestAmountLots *Int `json:"max_dest_amount_lots"`
}

// UiStatus represents a human-readable status of a swap.
type UiStatus string

const (
// UiStatusSubmitted defines the `Submitted` status.
UiStatusSubmitted UiStatus = "Submitted"
// UiStatusFailed defines the `Failed` status.
UiStatusFailed UiStatus = "Failed"
// UiStatusExecuting defines the `Executing` status.
UiStatusExecuting UiStatus = "Executing"
// UiStatusCompleted defines the `Completed` status.
UiStatusCompleted UiStatus = "Completed"
// UiStatusRefunding defines the `Refunding` status.
UiStatusRefunding UiStatus = "Refunding"
// UiStatusRefunded defines the `Refunded` status.
UiStatusRefunded UiStatus = "Refunded"
// UiStatusExpired defines the `Expired` status.
UiStatusExpired UiStatus = "Expired"
)
Loading