@@ -2,6 +2,7 @@ package swapkit
22
33import "encoding/json"
44
5+ // QuoteRequest represents a request to swapkit for a swap quote.
56type QuoteRequest struct {
67 SellAsset string `json:"sellAsset"`
78 BuyAsset string `json:"buyAsset"`
@@ -13,6 +14,7 @@ type QuoteRequest struct {
1314 MaxExecutionTime * int `json:"maxExecutionTime,omitempty"`
1415}
1516
17+ // SwapRequest represents a request to swakip to execute a swap.
1618type SwapRequest struct {
1719 RouteID string `json:"routeId"`
1820 SourceAddress string `json:"sourceAddress"`
@@ -25,13 +27,15 @@ type SwapRequest struct {
2527 OverrideSlippage * bool `json:"overrideSlippage,omitempty"`
2628}
2729
30+ // QuoteResponse contains info about swaps' quotes.
2831type QuoteResponse struct {
29- QuoteID string `json:"quoteId"`
30- Routes []QuoteRoute `json:"routes"`
31- ProviderErrors []QuoteError `json:"providerErrors,omitempty"`
32- Error string `json:"error,omitempty"`
32+ QuoteID string `json:"quoteId"`
33+ Routes []QuoteRoute `json:"routes"`
34+ ProviderErrors []ProviderError `json:"providerErrors,omitempty"`
35+ Error string `json:"error,omitempty"`
3336}
3437
38+ // SwapResponse is the answer provided by swapkit when asking to execute a swap.
3539type SwapResponse struct {
3640 RouteID string `json:"routeId"`
3741 Providers []string `json:"providers"`
@@ -53,6 +57,8 @@ type SwapResponse struct {
5357 NextActions []NextAction `json:"nextActions,omitempty"`
5458}
5559
60+ // QuoteRoute represent a single route to swap coins from
61+ // SellAsset to BuyAsset.
5662type QuoteRoute struct {
5763 RouteID string `json:"routeId"`
5864 Providers []string `json:"providers"`
@@ -81,6 +87,7 @@ type QuoteRoute struct {
8187 NextActions []NextAction `json:"nextActions,omitempty"`
8288}
8389
90+ // Fee represents one of the possible fees for executing a swap.
8491type Fee struct {
8592 Type string `json:"type"`
8693 Amount string `json:"amount"`
@@ -89,14 +96,64 @@ type Fee struct {
8996 Protocol string `json:"protocol"`
9097}
9198
99+ // NextAction is provided by swap as a convenience field to suggest what
100+ // the next step in a swap workflow could be.
92101type NextAction struct {
93102 Method string `json:"method"`
94103 URL string `json:"url"`
95104 Payload json.RawMessage `json:"payload,omitempty"`
96105}
97106
98- type QuoteError struct {
107+ // ProviderError contains errors specific to a Provider
108+ // (e.g. some provided will only provide quotes for sell amounts
109+ // higher than a certain treshold).
110+ type ProviderError struct {
99111 Provider string `json:"provider"`
100112 ErrorCode string `json:"errorCode"`
101113 Message string `json:"message"`
102114}
115+
116+ // TrackRequest is used to query swapkit fo track the status of a swap.
117+ type TrackRequest struct {
118+ Hash string `json:"hash"`
119+ ChainID string `json:"chainId"`
120+ }
121+
122+ // TrackResponse represents SwapKit's response for a tracked transaction
123+ type TrackResponse struct {
124+ ChainID string `json:"chainId"`
125+ Hash string `json:"hash"`
126+ Block int64 `json:"block"`
127+ Type string `json:"type"` // swap, token_transfer, etc.
128+ Status string `json:"status"` // not_started, pending, swapping, completed, refunded, failed, unknown
129+ TrackingStatus string `json:"trackingStatus"` // deprecated, status is enough
130+ FromAsset string `json:"fromAsset"`
131+ FromAmount string `json:"fromAmount"`
132+ FromAddress string `json:"fromAddress"`
133+ ToAsset string `json:"toAsset"`
134+ ToAmount string `json:"toAmount"`
135+ ToAddress string `json:"toAddress"`
136+ FinalisedAt int64 `json:"finalisedAt"` // UNIX timestamp
137+ Meta json.RawMessage `json:"meta,omitempty"` // provider, images, etc.
138+ Payload json.RawMessage `json:"payload,omitempty"` // transaction-specific info
139+ Legs []TrackLeg `json:"legs,omitempty"` // individual steps in transaction
140+ }
141+
142+ // TrackLeg represents a step of the transaction
143+ type TrackLeg struct {
144+ ChainID string `json:"chainId"`
145+ Hash string `json:"hash"`
146+ Block int64 `json:"block"`
147+ Type string `json:"type"`
148+ Status string `json:"status"`
149+ TrackingStatus string `json:"trackingStatus"`
150+ FromAsset string `json:"fromAsset"`
151+ FromAmount string `json:"fromAmount"`
152+ FromAddress string `json:"fromAddress"`
153+ ToAsset string `json:"toAsset"`
154+ ToAmount string `json:"toAmount"`
155+ ToAddress string `json:"toAddress"`
156+ FinalisedAt int64 `json:"finalisedAt"`
157+ Meta json.RawMessage `json:"meta,omitempty"`
158+ Payload json.RawMessage `json:"payload,omitempty"`
159+ }
0 commit comments