Documentation ¶
Index ¶
- func ReplacePathVariable(path, pathVarName string, value interface{}) (string, error)
- type ActionService
- type Client
- type Config
- type Environment
- type ErrorResponse
- type LimitOrderErrorResponse
- type OrderbookService
- func (s *OrderbookService) CreateOrder(ctx context.Context, params orderbook.CreateOrderParams) (*orderbook.CreateOrderResponse, *http.Response, error)
- func (s *OrderbookService) GetActiveOrdersWithPermit(ctx context.Context, params orderbook.GetActiveOrdersWithPermitParams) ([]orderbook.OrderResponse, *http.Response, error)
- func (s *OrderbookService) GetAllOrders(ctx context.Context, params orderbook.GetAllOrdersParams) ([]orderbook.OrderResponse, *http.Response, error)
- func (s *OrderbookService) GetCount(ctx context.Context, params orderbook.GetCountParams) (*orderbook.CountResponse, *http.Response, error)
- func (s *OrderbookService) GetEvent(ctx context.Context, params orderbook.GetEventParams) (*orderbook.EventResponse, *http.Response, error)
- func (s *OrderbookService) GetEvents(ctx context.Context, params orderbook.GetEventsParams) ([]orderbook.EventResponse, *http.Response, error)
- func (s *OrderbookService) GetOrdersByCreatorAddress(ctx context.Context, params orderbook.GetOrdersByCreatorAddressParams) ([]orderbook.OrderResponse, *http.Response, error)
- type SwapService
- func (s *SwapService) ApproveAllowance(ctx context.Context, params swap.ApproveAllowanceParams) (*swap.AllowanceResponse, *http.Response, error)
- func (s *SwapService) ApproveSpender(ctx context.Context, params swap.ApproveSpenderParams) (*swap.SpenderResponse, *http.Response, error)
- func (s *SwapService) ApproveTransaction(ctx context.Context, params swap.ApproveTransactionParams) (*swap.ApproveCallDataResponse, *http.Response, error)
- func (s *SwapService) ExecuteSwap(ctx context.Context, config *swap.ExecuteSwapConfig) error
- func (s *SwapService) GetLiquiditySources(ctx context.Context, params swap.GetLiquiditySourcesParams) (*swap.ProtocolsResponse, *http.Response, error)
- func (s *SwapService) GetQuote(ctx context.Context, params swap.GetQuoteParams) (*swap.QuoteResponse, *http.Response, error)
- func (s *SwapService) GetSwapData(ctx context.Context, params swap.GetSwapDataParams) (*swap.SwapResponse, *http.Response, error)
- func (s *SwapService) GetTokens(ctx context.Context, params swap.GetTokensParams) (*swap.TokensResponse, *http.Response, error)
- type Web3ProviderConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReplacePathVariable ¶
ReplacePathVariable replaces the path variable in the given URL with the specified value.
Types ¶
type ActionService ¶
type ActionService service
func (*ActionService) SwapTokens ¶
func (s *ActionService) SwapTokens(ctx context.Context, params swap.SwapTokensParams) error
SwapTokens executes a token swap operation using the 1inch Swap API.
The helper function takes a client, swap parameters, and a flag to skip warnings. It executes the proposed swap onchain, using Permit if available.
Parameters:
- c: A pointer to the client.Client instance. This client should be initialized and connected to the Ethereum network.
- swapParams: The parameters for the swap operation, of type swap.AggregationControllerGetSwapParams. It should contain details such as the source and destination tokens, the amount to swap, and the slippage tolerance.
- skipWarnings: A boolean flag indicating whether to skip warning prompts. If true, warning prompts will be suppressed; otherwise, they will be displayed.
The function performs several key operations:
- Sets a 10-minute Permit1 deadline for the swap operation.
- Checks if the source token supports Permit1. If Permit1 is supported, it tries to use that instead of the traditional `Approve` swap.
- Executes the swap request onchain
Note:
- The function currently has a hardcoded 10-minute deadline. Future versions will make this configurable.
- The Permit feature is used if the token typehash matches a known Permit typehash.
Returns nil on successful execution of the swap. Any error during the process is returned as a non-nil error.
type Client ¶
type Client struct { // Ethereum client map EthClientMap map[int]*ethclient.Client // The URL of the 1inch API ApiBaseURL *url.URL // The API key to use for authentication ApiKey string // When present, tests will simulate swaps on Tenderly NonceCache map[string]uint64 // Isolated namespaces for each API Actions *ActionService Swap *SwapService Orderbook *OrderbookService // contains filtered or unexported fields }
func NewClient ¶
NewClient creates and initializes a new Client instance based on the provided Config.
type Config ¶
type Config struct { DevPortalApiKey string Web3HttpProviders []Web3ProviderConfig }
type Environment ¶
type Environment string
type ErrorResponse ¶
type ErrorResponse struct { Response *http.Response `json:"-"` ErrorMessage string `json:"error"` Description string `json:"description"` StatusCode int `json:"statusCode"` RequestId string `json:"requestId"` Meta []struct { Value string `json:"value"` Type string `json:"type"` } `json:"meta"` }
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type LimitOrderErrorResponse ¶
type LimitOrderErrorResponse struct { Response *http.Response `json:"-"` StatusCode int `json:"statusCode"` Message string `json:"message"` ErrorType string `json:"error"` }
func (*LimitOrderErrorResponse) Error ¶
func (r *LimitOrderErrorResponse) Error() string
type OrderbookService ¶
type OrderbookService service
func (*OrderbookService) CreateOrder ¶
func (s *OrderbookService) CreateOrder(ctx context.Context, params orderbook.CreateOrderParams) (*orderbook.CreateOrderResponse, *http.Response, error)
CreateOrder creates an order in the Limit Order Protocol
func (*OrderbookService) GetActiveOrdersWithPermit ¶
func (s *OrderbookService) GetActiveOrdersWithPermit(ctx context.Context, params orderbook.GetActiveOrdersWithPermitParams) ([]orderbook.OrderResponse, *http.Response, error)
GetActiveOrdersWithPermit returns all orders in the Limit Order Protocol that are active and have a valid permit
func (*OrderbookService) GetAllOrders ¶
func (s *OrderbookService) GetAllOrders(ctx context.Context, params orderbook.GetAllOrdersParams) ([]orderbook.OrderResponse, *http.Response, error)
GetAllOrders returns all orders in the Limit Order Protocol
func (*OrderbookService) GetCount ¶
func (s *OrderbookService) GetCount(ctx context.Context, params orderbook.GetCountParams) (*orderbook.CountResponse, *http.Response, error)
GetCount returns the number of orders in the Limit Order Protocol
func (*OrderbookService) GetEvent ¶
func (s *OrderbookService) GetEvent(ctx context.Context, params orderbook.GetEventParams) (*orderbook.EventResponse, *http.Response, error)
GetEvent returns an event in the Limit Order Protocol by order hash
func (*OrderbookService) GetEvents ¶
func (s *OrderbookService) GetEvents(ctx context.Context, params orderbook.GetEventsParams) ([]orderbook.EventResponse, *http.Response, error)
GetEvents returns all events in the Limit Order Protocol
func (*OrderbookService) GetOrdersByCreatorAddress ¶
func (s *OrderbookService) GetOrdersByCreatorAddress(ctx context.Context, params orderbook.GetOrdersByCreatorAddressParams) ([]orderbook.OrderResponse, *http.Response, error)
GetOrdersByCreatorAddress returns all orders created by a given address in the Limit Order Protocol
type SwapService ¶
type SwapService service
func (*SwapService) ApproveAllowance ¶
func (s *SwapService) ApproveAllowance(ctx context.Context, params swap.ApproveAllowanceParams) (*swap.AllowanceResponse, *http.Response, error)
ApproveAllowance returns the allowance the 1inch router has to spend a token on behalf of a wallet
func (*SwapService) ApproveSpender ¶
func (s *SwapService) ApproveSpender(ctx context.Context, params swap.ApproveSpenderParams) (*swap.SpenderResponse, *http.Response, error)
ApproveSpender returns the address of the 1inch router contract
func (*SwapService) ApproveTransaction ¶
func (s *SwapService) ApproveTransaction(ctx context.Context, params swap.ApproveTransactionParams) (*swap.ApproveCallDataResponse, *http.Response, error)
ApproveTransaction returns the transaction data for approving the 1inch router to spend a token on behalf of a wallet
func (*SwapService) ExecuteSwap ¶
func (s *SwapService) ExecuteSwap(ctx context.Context, config *swap.ExecuteSwapConfig) error
ExecuteSwap executes a swap on the Ethereum blockchain using swap data generated by GetSwapData
func (*SwapService) GetLiquiditySources ¶
func (s *SwapService) GetLiquiditySources(ctx context.Context, params swap.GetLiquiditySourcesParams) (*swap.ProtocolsResponse, *http.Response, error)
GetLiquiditySources returns all liquidity sources tracked by the 1inch Aggregation Protocol for a given chain
func (*SwapService) GetQuote ¶
func (s *SwapService) GetQuote(ctx context.Context, params swap.GetQuoteParams) (*swap.QuoteResponse, *http.Response, error)
GetQuote returns the quote for a potential swap through the Aggregation Protocol
func (*SwapService) GetSwapData ¶
func (s *SwapService) GetSwapData(ctx context.Context, params swap.GetSwapDataParams) (*swap.SwapResponse, *http.Response, error)
GetSwapData returns a swap quote with transaction data that can be used to execute a swap through the Aggregation Protocol
func (*SwapService) GetTokens ¶
func (s *SwapService) GetTokens(ctx context.Context, params swap.GetTokensParams) (*swap.TokensResponse, *http.Response, error)
GetTokens returns all tokens officially tracked by the 1inch Aggregation Protocol for a given chain
type Web3ProviderConfig ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package orderbook provides primitives to interact with the openapi HTTP API.
|
Package orderbook provides primitives to interact with the openapi HTTP API. |
Package swap provides primitives to interact with the openapi HTTP API.
|
Package swap provides primitives to interact with the openapi HTTP API. |