Documentation ¶
Index ¶
- Constants
- Variables
- type ApproveAllowance
- type AuctionResponse
- type CancelOrderReq
- type Client
- func (c *Client) CancelOrder(ctx context.Context, uid string) (*string, int, error)
- func (c *Client) CancelOrders(ctx context.Context, uids []string) (*string, int, error)
- func (c *Client) CreateOrder(ctx context.Context, signedOrder *CounterOrder) (*string, int, error)
- func (c *Client) GetAllowance(ctx context.Context, ownerAddress, tokenAddress string) (*big.Int, error)
- func (c *Client) GetAuction(ctx context.Context) (*AuctionResponse, int, error)
- func (c *Client) GetNativePrice(ctx context.Context, tokenAddress string) (*NativePriceResponse, int, error)
- func (c *Client) GetOrdersBySettlementTxHash(ctx context.Context, txHash string) (*OrdersByTxHashResponse, int, error)
- func (c *Client) GetOrdersByUid(ctx context.Context, uid string) (*OrderByUidResponse, int, error)
- func (c *Client) GetOrdersByUser(ctx context.Context, userAddress string, opts *OrdersPaginated) (*OrdersByUserResponse, int, error)
- func (c *Client) GetSolverAuctionById(ctx context.Context, auctionId int) (*SolverAuctionByIdResponse, int, error)
- func (c *Client) GetSolverAuctionByTxHash(ctx context.Context, txHash string) (*SolverAuctionByTxHashResponse, int, error)
- func (c *Client) GetTrades(ctx context.Context, opts *GetTrades) (*TradesResponse, int, error)
- func (c *Client) GetVersion(ctx context.Context) (*VersionResponse, int, error)
- func (c *Client) Quote(ctx context.Context, o *QuoteReq) (*QuoteResponse, int, error)
- func (c *Client) SetAllowance(ctx context.Context, tokenAddress, tokenAmount string) (*types.Transaction, error)
- func (c *Client) SignCancelOrder(uid string) (string, *apitypes.TypedData, error)
- func (c *Client) SignCancelOrders(uid []string) (string, *apitypes.TypedData, error)
- func (c *Client) SignOrder(o *CounterOrder) (*CounterOrder, error)
- type ConfigOpts
- type CounterOrder
- type ErrorCowResponse
- type GetTrades
- type NativePriceResponse
- type OrderByUidResponse
- type OrdersByTxHashResponse
- type OrdersByUserResponse
- type OrdersPaginated
- type QuoteReq
- type QuoteResponse
- type SignOrderFunc
- type SolverAuctionByIdResponse
- type SolverAuctionByTxHashResponse
- type TradesResponse
- type TransactionSigner
- type VersionResponse
Constants ¶
const ( MAINNET_API = "https://api.cow.fi/mainnet/api/v1" GOERLI_API = "https://api.cow.fi/goerli/api/v1" GNOSIS_CHAIN_API = "https://api.cow.fi/xdai/api/v1" GPv2Settlement = "0x9008D19f58AAbD9eD0D60971565AA8510560ab41" GPv2_Vault_Relayer = "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110" )
const ( RPC_MAINNET = "https://api.securerpc.com/v1" RPC_GOERLI = "https://eth-goerli-rpc.gateway.pokt.network" RPC_XDAI = "https://xdai-rpc.gateway.pokt.network" )
const ( SUBGRAPH_MAINNET = "https://api.thegraph.com/subgraphs/name/cowprotocol/cow" SUBGRAPH_GOERLI = "https://api.thegraph.com/subgraphs/name/cowprotocol/cow-goerli" SUBGRAPH_GNOSIS_CHAIN = "https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc" )
Variables ¶
var ChainIds = map[string]int{
"mainnet": 1,
"goerli": 5,
"xdai": 100,
}
var Domain = apitypes.TypedDataDomain{ Name: "Gnosis Protocol", Version: "v2", ChainId: math.NewHexOrDecimal256(1), VerifyingContract: GPv2Settlement, }
Default chainId is mainnet
var ETHEREUM_TOKEN_LIST = map[string]string{
"WETH": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"USDC": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"COW": "0xdef1ca1fb7fbcdc777520aa7f396b4e015f497ab",
"GNO": "0x6810e776880c02933d47db1b9fc05908e5386b96",
}
var Eip712OrderTypes = apitypes.Types{
"EIP712Domain": {
{
Name: "name",
Type: "string",
},
{
Name: "version",
Type: "string",
},
{
Name: "chainId",
Type: "uint256",
},
{
Name: "verifyingContract",
Type: "address",
},
},
"Order": {
{
Name: "sellToken",
Type: "address",
},
{
Name: "buyToken",
Type: "address",
},
{
Name: "receiver",
Type: "address",
},
{
Name: "sellAmount",
Type: "uint256",
},
{
Name: "buyAmount",
Type: "uint256",
},
{
Name: "validTo",
Type: "uint32",
},
{
Name: "appData",
Type: "bytes32",
},
{
Name: "feeAmount",
Type: "uint256",
},
{
Name: "kind",
Type: "string",
},
{
Name: "partiallyFillable",
Type: "bool",
},
{
Name: "sellTokenBalance",
Type: "string",
},
{
Name: "buyTokenBalance",
Type: "string",
},
},
"OrderCancellations": {
{
Name: "orderUids",
Type: "bytes[]",
},
},
}
var GNOSIS_SCAN_TOKEN_LIST = map[string]string{
"GNO": "",
}
var GOERLI_TOKEN_LIST = map[string]string{
"COW": "0x91056D4A53E1faa1A84306D4deAEc71085394bC8",
"GNO": "0x02ABBDbAaa7b1BB64B5c878f7ac17f8DDa169532",
"BAT": "0x70cBa46d2e933030E2f274AE58c951C800548AeF",
"DAI": "0xdc31Ee1784292379Fbb2964b3B9C4124D8F89C60",
"POLY": "0x9e32c0EfF886B6Ccae99350Fd5e7002dCED55F15",
"UNI": "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
"USDC": "0xD87Ba7A50B2E7E660f678A895E4B72E7CB4CCd9C",
"WETH": "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",
"ZRX": "0xe4E81Fa6B16327D4B78CFEB83AAdE04bA7075165",
}
var HostConfig = map[string]string{ "mainnet": MAINNET_API, "goerli": GOERLI_API, "xdai": GNOSIS_CHAIN_API, }
var Options = ConfigOpts{ Network: "goerli", Host: HostConfig["goerli"], RpcUrl: RpcConfig["goerli"], EthAddress: os.Getenv("ETH_ADDRESS"), PrivateKey: os.Getenv("PRIVATE_KEY"), }
var RpcConfig = map[string]string{ "mainnet": RPC_MAINNET, "goerli": RPC_GOERLI, "xdai": RPC_XDAI, }
var SubgraphConfig = map[string]string{ "mainnet": SUBGRAPH_MAINNET, "goerli": SUBGRAPH_GOERLI, "xdai": SUBGRAPH_GNOSIS_CHAIN, }
var TOKEN_ADDRESSES = map[string]map[string]string{ "mainnet": ETHEREUM_TOKEN_LIST, "goerli": GOERLI_TOKEN_LIST, "xdai": GNOSIS_SCAN_TOKEN_LIST, }
var TypedData = apitypes.TypedData{ Types: Eip712OrderTypes, PrimaryType: "Order", Domain: Domain, Message: map[string]interface{}{}, }
Functions ¶
This section is empty.
Types ¶
type ApproveAllowance ¶
type AuctionResponse ¶
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"` }
type CancelOrderReq ¶
type Client ¶
type Client struct { Options ConfigOpts Network string Host string Http *http.Client Eip712OrderTypes apitypes.Types TypedDataDomain apitypes.TypedDataDomain RpcUrl string EthClient *ethclient.Client ChainId *big.Int ChainIdInt int TransactionSigner *TransactionSigner Subgraph *subgraph.Client }
func NewClient ¶
func NewClient(options ConfigOpts) (*Client, error)
NewClient - Client to interact with CowSwap
func (*Client) CancelOrder ¶
CancelOrder - Cancel orders
func (*Client) CancelOrders ¶ added in v1.0.6
CancelOrders - Cancel multiple orders
func (*Client) CreateOrder ¶
func (*Client) GetAllowance ¶
func (c *Client) GetAllowance(ctx context.Context, ownerAddress, tokenAddress string) (*big.Int, error)
GetAllowance - Token allowance for owner
func (*Client) GetAuction ¶
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 (*Client) GetNativePrice ¶
func (c *Client) GetNativePrice(ctx context.Context, tokenAddress string) (*NativePriceResponse, int, error)
GetNativePrice - Get native price for given token
func (*Client) GetOrdersBySettlementTxHash ¶ added in v1.0.8
func (c *Client) GetOrdersBySettlementTxHash(ctx context.Context, txHash string) (*OrdersByTxHashResponse, int, error)
GetOrdersBySettlementTxHash - Get orders by settlement transaction hash
func (*Client) GetOrdersByUid ¶
GetOrdersByUid - Get existing order from UID
func (*Client) GetOrdersByUser ¶
func (c *Client) GetOrdersByUser(ctx context.Context, userAddress string, opts *OrdersPaginated) (*OrdersByUserResponse, int, error)
GetOrdersByUser - Get orders of a user paginated
func (*Client) GetSolverAuctionById ¶
func (c *Client) GetSolverAuctionById(ctx context.Context, auctionId int) (*SolverAuctionByIdResponse, int, error)
GetSolverAuctionById - The competition information by auction id
func (*Client) GetSolverAuctionByTxHash ¶
func (c *Client) GetSolverAuctionByTxHash(ctx context.Context, txHash string) (*SolverAuctionByTxHashResponse, int, error)
GetSolverAuctionByTxHash - The competition information by transaction hash
func (*Client) GetVersion ¶ added in v1.0.3
GetVersion - Information about the current deployed version of the API
func (*Client) SetAllowance ¶
func (c *Client) SetAllowance(ctx context.Context, tokenAddress, tokenAmount string) (*types.Transaction, error)
SetAllowance - Set token allowance for owner on CowSwap GPv2 Vault Relayer contract
func (*Client) SignCancelOrder ¶
SignCancelOrder - Sign a single order for cancellation & generate the order signature
func (*Client) SignCancelOrders ¶ added in v1.0.6
SignCancelOrders - Sign multiple orders for cancellation & generate the order signature
func (*Client) SignOrder ¶
func (c *Client) SignOrder(o *CounterOrder) (*CounterOrder, error)
type ConfigOpts ¶ added in v1.0.3
type CounterOrder ¶
type CounterOrder struct { SellToken string `json:"sellToken,omitempty"` BuyToken string `json:"buyToken,omitempty"` Receiver string `json:"receiver,omitempty"` SellAmount string `json:"sellAmount"` BuyAmount string `json:"buyAmount"` ValidTo uint32 `json:"validTo,omitempty"` AppData string `json:"appData,omitempty"` FeeAmount string `json:"feeAmount"` Kind string `json:"kind,omitempty"` PartiallyFillable bool `json:"partiallyFillable"` Signature string `json:"signature,omitempty"` SigningScheme string `json:"signingScheme,omitempty"` SellTokenBalance string `json:"sellTokenBalance,omitempty"` BuyTokenBalance string `json:"buyTokenBalance,omitempty"` From string `json:"from,omitempty"` }
CounterOrder represents a Gnosis CounterOrder.
func SignEip712Order ¶ added in v1.0.5
func SignEip712Order(c *Client, o *CounterOrder) (*CounterOrder, error)
SignEip712Order Signs order with EIP712 signing scheme
func SignEthSignOrder ¶ added in v1.0.5
func SignEthSignOrder(c *Client, o *CounterOrder) (*CounterOrder, error)
SignEthSignOrder Signs order with eth_sign signing scheme
type ErrorCowResponse ¶
type ErrorCowResponse struct { Code int `json:"code"` ErrorType string `json:"errorType"` Description string `json:"description"` }
func (*ErrorCowResponse) Error ¶
func (e *ErrorCowResponse) Error() string
type NativePriceResponse ¶
type NativePriceResponse struct {
Price float64 `json:"price"`
}
type OrderByUidResponse ¶
type OrderByUidResponse 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"` }
type OrdersByTxHashResponse ¶
type OrdersByTxHashResponse []struct { CreationDate time.Time `json:"creationDate"` Owner string `json:"owner"` UID string `json:"uid"` AvailableBalance interface{} `json:"availableBalance"` ExecutedBuyAmount string `json:"executedBuyAmount"` ExecutedSellAmount string `json:"executedSellAmount"` ExecutedSellAmountBeforeFees string `json:"executedSellAmountBeforeFees"` ExecutedFeeAmount string `json:"executedFeeAmount"` Invalidated bool `json:"invalidated"` Status string `json:"status"` Class string `json:"class"` SettlementContract string `json:"settlementContract"` FullFeeAmount string `json:"fullFeeAmount"` IsLiquidityOrder bool `json:"isLiquidityOrder"` 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"` Interactions struct { Pre []interface{} `json:"pre"` } `json:"interactions"` }
type OrdersByUserResponse ¶
type OrdersByUserResponse []struct { CreationDate time.Time `json:"creationDate"` Owner string `json:"owner"` UID string `json:"uid"` AvailableBalance interface{} `json:"availableBalance"` ExecutedBuyAmount string `json:"executedBuyAmount"` ExecutedSellAmount string `json:"executedSellAmount"` ExecutedSellAmountBeforeFees string `json:"executedSellAmountBeforeFees"` ExecutedFeeAmount string `json:"executedFeeAmount"` Invalidated bool `json:"invalidated"` Status string `json:"status"` Class string `json:"class"` SettlementContract string `json:"settlementContract"` FullFeeAmount string `json:"fullFeeAmount"` IsLiquidityOrder bool `json:"isLiquidityOrder"` 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"` Interactions struct { Pre []interface{} `json:"pre"` } `json:"interactions"` }
type OrdersPaginated ¶
type QuoteReq ¶
type QuoteReq struct { SellToken string `json:"sellToken"` BuyToken string `json:"buyToken"` Receiver string `json:"receiver"` AppData string `json:"appData"` PartiallyFillable bool `json:"partiallyFillable"` SellTokenBalance string `json:"sellTokenBalance"` BuyTokenBalance string `json:"buyTokenBalance"` PriceQuality string `json:"priceQuality"` SigningScheme string `json:"signingScheme"` OnchainOrder bool `json:"onchainOrder"` Kind string `json:"kind"` SellAmountBeforeFee string `json:"sellAmountBeforeFee"` From string `json:"from"` }
type QuoteResponse ¶
type QuoteResponse struct { Quote 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"` } `json:"quote"` From string `json:"from"` Expiration time.Time `json:"expiration"` ID int `json:"id"` }
type SignOrderFunc ¶ added in v1.0.5
type SignOrderFunc func(*Client, *CounterOrder) (*CounterOrder, error)
type SolverAuctionByIdResponse ¶
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"` }
type SolverAuctionByTxHashResponse ¶
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"` }
type TradesResponse ¶
type TradesResponse []struct { BlockNumber int `json:"blockNumber"` LogIndex int `json:"logIndex"` OrderUID string `json:"orderUid"` BuyAmount string `json:"buyAmount"` SellAmount string `json:"sellAmount"` SellAmountBeforeFees string `json:"sellAmountBeforeFees"` Owner string `json:"owner"` BuyToken string `json:"buyToken"` SellToken string `json:"sellToken"` TxHash string `json:"txHash"` }
type TransactionSigner ¶
type TransactionSigner struct { PrivateKey *ecdsa.PrivateKey SignerPubKey common.Address Auth *bind.TransactOpts }