client

package
v0.0.0-...-038b677 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 30 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReplacePathVariable

func ReplacePathVariable(path, pathVarName string, value interface{}) (string, error)

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

func NewClient(config Config) (*Client, error)

NewClient creates and initializes a new Client instance based on the provided Config.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*http.Response, error)

func (*Client) GetEthClient

func (c *Client) GetEthClient(chainId int) (*ethclient.Client, error)

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body []byte) (*http.Request, error)

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

CreateOrder creates an order in the Limit Order Protocol

func (*OrderbookService) GetActiveOrdersWithPermit

GetActiveOrdersWithPermit returns all orders in the Limit Order Protocol that are active and have a valid permit

func (*OrderbookService) GetAllOrders

GetAllOrders returns all orders in the Limit Order Protocol

func (*OrderbookService) GetCount

GetCount returns the number of orders in the Limit Order Protocol

func (*OrderbookService) GetEvent

GetEvent returns an event in the Limit Order Protocol by order hash

func (*OrderbookService) GetEvents

GetEvents returns all events in the Limit Order Protocol

func (*OrderbookService) GetOrdersByCreatorAddress

GetOrdersByCreatorAddress returns all orders created by a given address in the Limit Order Protocol

type SwapService

type SwapService service

func (*SwapService) ApproveAllowance

ApproveAllowance returns the allowance the 1inch router has to spend a token on behalf of a wallet

func (*SwapService) ApproveSpender

ApproveSpender returns the address of the 1inch router contract

func (*SwapService) ApproveTransaction

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

GetLiquiditySources returns all liquidity sources tracked by the 1inch Aggregation Protocol for a given chain

func (*SwapService) GetQuote

GetQuote returns the quote for a potential swap through the Aggregation Protocol

func (*SwapService) GetSwapData

GetSwapData returns a swap quote with transaction data that can be used to execute a swap through the Aggregation Protocol

func (*SwapService) GetTokens

GetTokens returns all tokens officially tracked by the 1inch Aggregation Protocol for a given chain

type Web3ProviderConfig

type Web3ProviderConfig struct {
	ChainId int
	Url     string
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL