-
Notifications
You must be signed in to change notification settings - Fork 4
/
auction.go
148 lines (141 loc) · 6.27 KB
/
auction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package go_cowswap
import (
"context"
"fmt"
"time"
)
// GetAuction - The current batch auction that solvers should be solving right now. Includes the list of solvable orders, the block on which the batch was created, as well as prices for all tokens being traded (used for objective value computation)
func (c *Client) GetAuction(ctx context.Context) (*AuctionResponse, int, error) {
endpoint := "/auction"
var dataRes AuctionResponse
statusCode, err := c.doRequest(ctx, endpoint, "GET", &dataRes, nil)
if err != nil {
return nil, statusCode, &ErrorCowResponse{Code: statusCode, ErrorType: "do_request_error", Description: err.Error()}
}
return &dataRes, statusCode, nil
}
type AuctionResponse struct {
ID int `json:"id"`
Block int `json:"block"`
LatestSettlementBlock int `json:"latestSettlementBlock"`
Orders []struct {
SellToken string `json:"sellToken"`
BuyToken string `json:"buyToken"`
Receiver string `json:"receiver"`
SellAmount string `json:"sellAmount"`
BuyAmount string `json:"buyAmount"`
ValidTo int `json:"validTo"`
AppData string `json:"appData"`
FeeAmount string `json:"feeAmount"`
Kind string `json:"kind"`
PartiallyFillable bool `json:"partiallyFillable"`
SellTokenBalance string `json:"sellTokenBalance"`
BuyTokenBalance string `json:"buyTokenBalance"`
SigningScheme string `json:"signingScheme"`
Signature string `json:"signature"`
From string `json:"from"`
QuoteID int `json:"quoteId"`
CreationTime time.Time `json:"creationTime"`
Owner string `json:"owner"`
UID string `json:"UID"`
AvailableBalance string `json:"availableBalance"`
ExecutedSellAmount string `json:"executedSellAmount"`
ExecutedSellAmountBeforeFees string `json:"executedSellAmountBeforeFees"`
ExecutedBuyAmount string `json:"executedBuyAmount"`
ExecutedFeeAmount string `json:"executedFeeAmount"`
Invalidated bool `json:"invalidated"`
Status string `json:"status"`
FullFeeAmount string `json:"fullFeeAmount"`
IsLiquidityOrder bool `json:"isLiquidityOrder"`
EthflowData struct {
IsRefunded bool `json:"isRefunded"`
UserValidTo int `json:"userValidTo"`
} `json:"ethflowData"`
OnchainUser string `json:"onchainUser"`
} `json:"orders"`
Prices struct {
AdditionalProp1 string `json:"additionalProp1"`
AdditionalProp2 string `json:"additionalProp2"`
AdditionalProp3 string `json:"additionalProp3"`
} `json:"prices"`
}
// GetSolverAuctionById - The competition information by auction id
func (c *Client) GetSolverAuctionById(ctx context.Context, auctionId int) (*SolverAuctionByIdResponse, int, error) {
if auctionId < 0 {
return nil, 404, &ErrorCowResponse{Code: 404, ErrorType: "invalid_auction_id", Description: "invalid auction id"}
}
endpoint := fmt.Sprintf("/solver_competition/%v", auctionId)
var dataRes SolverAuctionByIdResponse
statusCode, err := c.doRequest(ctx, endpoint, "GET", &dataRes, nil)
if err != nil {
return nil, statusCode, &ErrorCowResponse{Code: statusCode, ErrorType: "do_request_error", Description: err.Error()}
}
return &dataRes, statusCode, nil
}
type SolverAuctionByIdResponse struct {
AuctionId int `json:"auctionId"`
TransactionHash string `json:"transactionHash"`
GasPrice float64 `json:"gasPrice"`
LiquidityCollectedBlock int `json:"liquidityCollectedBlock"`
CompetitionSimulationBlock int `json:"competitionSimulationBlock"`
Solutions []struct {
Solver string `json:"solver"`
Objective struct {
Total float64 `json:"total"`
Surplus float64 `json:"surplus"`
Fees float64 `json:"fees"`
Cost float64 `json:"cost"`
Gas int `json:"gas"`
} `json:"objective"`
Prices struct {
AdditionalProp1 string `json:"additionalProp1"`
AdditionalProp2 string `json:"additionalProp2"`
AdditionalProp3 string `json:"additionalProp3"`
} `json:"prices"`
Orders []struct {
Id string `json:"id"`
ExecutedAmount string `json:"executedAmount"`
} `json:"orders"`
CallData string `json:"callData"`
} `json:"solutions"`
}
// GetSolverAuctionByTxHash - The competition information by transaction hash
func (c *Client) GetSolverAuctionByTxHash(ctx context.Context, txHash string) (*SolverAuctionByTxHashResponse, int, error) {
if txHash == "" {
return nil, 404, &ErrorCowResponse{Code: 404, ErrorType: "invalid_tx_hash", Description: "invalid tx hash"}
}
endpoint := fmt.Sprintf("/solver_competition/by_tx_hash/%s", txHash)
var dataRes SolverAuctionByTxHashResponse
statusCode, err := c.doRequest(ctx, endpoint, "GET", &dataRes, nil)
if err != nil {
return nil, statusCode, &ErrorCowResponse{Code: statusCode, ErrorType: "do_request_error", Description: err.Error()}
}
return &dataRes, statusCode, nil
}
type SolverAuctionByTxHashResponse struct {
AuctionId int `json:"auctionId"`
TransactionHash string `json:"transactionHash"`
GasPrice float64 `json:"gasPrice"`
LiquidityCollectedBlock int `json:"liquidityCollectedBlock"`
CompetitionSimulationBlock int `json:"competitionSimulationBlock"`
Solutions []struct {
Solver string `json:"solver"`
Objective struct {
Total float64 `json:"total"`
Surplus float64 `json:"surplus"`
Fees float64 `json:"fees"`
Cost float64 `json:"cost"`
Gas int `json:"gas"`
} `json:"objective"`
Prices struct {
AdditionalProp1 string `json:"additionalProp1"`
AdditionalProp2 string `json:"additionalProp2"`
AdditionalProp3 string `json:"additionalProp3"`
} `json:"prices"`
Orders []struct {
Id string `json:"id"`
ExecutedAmount string `json:"executedAmount"`
} `json:"orders"`
CallData string `json:"callData"`
} `json:"solutions"`
}