Documentation ¶
Index ¶
- Constants
- Variables
- type BestSwapParams
- type Client
- func (c *Client) BestSwap(params BestSwapParams) (string, error)
- func (c *Client) ExchangeRate(params ExchangeRateParams) (Rate, error)
- func (c *Client) Price(params PriceParams) (PriceMap, error)
- func (c *Client) Quote(params QuoteParams) (QuoteResponse, error)
- func (c *Client) RoutesMap(onlyDirectRoutes bool) (IndexedRoutesMap, error)
- func (c *Client) Swap(params SwapParams) (string, error)
- type ClientOption
- func WithAPIURL(apiURL string) ClientOption
- func WithEndpointPrice(endpointPrice string) ClientOption
- func WithEndpointQuote(endpointQuote string) ClientOption
- func WithEndpointRoutesMap(endpointRoutesMap string) ClientOption
- func WithEndpointSwap(endpointSwap string) ClientOption
- func WithHTTPClient(client *http.Client) ClientOption
- type ExchangeRateParams
- type Fee
- type IndexedRoutesMap
- type MarketInfo
- type Price
- type PriceMap
- type PriceParams
- type QuoteParams
- type QuoteResponse
- type Rate
- type Response
- type Route
- type SwapParams
- type SwapResponse
Constants ¶
const ( SwapModeExactIn = "ExactIn" SwapModeExactOut = "ExactOut" )
Predefined swap modes.
const (
// ContentTypeJSON is the content type for JSON.
ContentTypeJSON = "application/json"
)
Variables ¶
var ErrNoRoute = errors.New("no route found")
Functions ¶
This section is empty.
Types ¶
type BestSwapParams ¶
type BestSwapParams struct { UserPublicKey string // user base58 encoded public key DestinationPublicKey string // destination base58 encoded public key (optional) FeeAmount uint64 // fee amount in token basis points (optional) FeeAccount string // fee token account for the platform fee (only pass in if you set a FeeAmount). InputMint string // input mint OutputMint string // output mint Amount uint64 // amount of output token SwapMode string // swap mode, default: ExactIn (Available: ExactIn, ExactOut) }
BestSwapParams contains the parameters for the best swap route.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Jupiter client that can be used to make requests to the Jupiter API.
func NewClient ¶
func NewClient(opts ...ClientOption) *Client
NewClient returns a new Jupiter client.
func (*Client) BestSwap ¶
func (c *Client) BestSwap(params BestSwapParams) (string, error)
BestSwap returns the ebase64 encoded transaction for the best swap route for a given input mint, output mint and amount. Default swap mode: ExactOut, so the amount is the amount of output token. Default wrap unwrap sol: true
func (*Client) ExchangeRate ¶
func (c *Client) ExchangeRate(params ExchangeRateParams) (Rate, error)
ExchangeRate returns the exchange rate for a given input mint, output mint and amount. Default swap mode: ExactOut, so the amount is the amount of output token.
func (*Client) Price ¶
func (c *Client) Price(params PriceParams) (PriceMap, error)
Price returns simple price for a given input mint, output mint and amount.
func (*Client) Quote ¶
func (c *Client) Quote(params QuoteParams) (QuoteResponse, error)
Quote returns a quote for a given input mint, output mint and amount
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is a function that can be used to configure a Jupiter client.
func WithAPIURL ¶
func WithAPIURL(apiURL string) ClientOption
WithAPIURL returns a ClientOption that configures the API URL used by the Jupiter client.
func WithEndpointPrice ¶
func WithEndpointPrice(endpointPrice string) ClientOption
WithEndpointPrice returns a ClientOption that configures the price endpoint used by the Jupiter client.
func WithEndpointQuote ¶
func WithEndpointQuote(endpointQuote string) ClientOption
WithEndpointQuote returns a ClientOption that configures the quote endpoint used by the Jupiter client.
func WithEndpointRoutesMap ¶
func WithEndpointRoutesMap(endpointRoutesMap string) ClientOption
WithEndpointRoutesMap returns a ClientOption that configures the routes map endpoint used by the Jupiter client.
func WithEndpointSwap ¶
func WithEndpointSwap(endpointSwap string) ClientOption
WithEndpointSwap returns a ClientOption that configures the swap endpoint used by the Jupiter client.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
WithHTTPClient returns a ClientOption that configures the HTTP client used by the Jupiter client.
type ExchangeRateParams ¶
type ExchangeRateParams struct { InputMint string // input token mint OutputMint string // output token mint Amount uint64 // amount of token, depending on the swap mode SwapMode string // swap mode, default: ExactOut (Available: ExactIn, ExactOut) }
ExchangeRateParams contains the parameters for the exchange rate request.
type Fee ¶
type Fee struct { Amount string `json:"amount"` Mint string `json:"mint"` Pct float64 `json:"pct"` }
Fee is a fee object structure.
type IndexedRoutesMap ¶
type IndexedRoutesMap struct { MintKeys []string `json:"mintKeys"` // All the mints that are indexed to match in indexedRouteMap. IndexedRouteMap map[string][]int `json:"indexedRouteMap"` // All the possible route and their corresponding output mints. }
IndexedRoutesMap is a map of routes indexed by the route ID.
func (*IndexedRoutesMap) GetRoutesForMint ¶
func (r *IndexedRoutesMap) GetRoutesForMint(mint string) []string
GetRoutesForMint returns the routes for a given mint.
type MarketInfo ¶
type MarketInfo struct { ID string `json:"id"` Label string `json:"label"` InputMint string `json:"inputMint"` OutputMint string `json:"outputMint"` NotEnoughLiquidity bool `json:"notEnoughLiquidity"` InAmount string `json:"inAmount"` OutAmount string `json:"outAmount"` MinInAmount string `json:"minInAmount,omitempty"` MinOutAmount string `json:"minOutAmount,omitempty"` PriceImpactPct float64 `json:"priceImpactPct"` LpFee *Fee `json:"lpFee"` PlatformFee *Fee `json:"platformFee"` }
MarketInfo is a market info object structure.
type Price ¶
type Price struct { ID string `json:"id"` // Address of the token MintSymbol string `json:"mintSymbol"` // Symbol of the token VsToken string `json:"vsToken"` // Address of the token to compare against VsTokenSymbol string `json:"vsTokenSymbol"` // Symbol of the token to compare against Price float64 `json:"price"` // Price of the token in relation to the vsToken. Default to 1 unit of the token worth in USDC if vsToken is not specified. }
Price is a price object structure.
type PriceParams ¶
type PriceParams struct { IDs string `url:"ids"` // required; Symbol or address of a token, (e.g. SOL or EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v). Use `,` to query multiple tokens, e.g. (sol,btc,mer,...) VsToken string `url:"vsToken,omitempty"` // optional; Default to USDC. Symbol or address of a token, (e.g. SOL or EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v). VsAmount float64 `url:"vsAmount,omitempty"` // optional; Unit amount of specified input token. Default to 1. }
PriceParams are the parameters for a price request.
type QuoteParams ¶
type QuoteParams struct { InputMint string `url:"inputMint"` // required OutputMint string `url:"outputMint"` // required Amount uint64 `url:"amount"` // required SwapMode string `url:"swapMode,omitempty"` // Swap mode, default is ExactIn; Available values : ExactIn, ExactOut. SlippageBps uint64 `url:"slippageBps,omitempty"` FeeBps uint64 `url:"feeBps,omitempty"` // Fee BPS (only pass in if you want to charge a fee on this swap) OnlyDirectRoutes bool `url:"onlyDirectRoutes,omitempty"` // Only return direct routes (no hoppings and split trade) AsLegacyTransaction bool `url:"asLegacyTransaction,omitempty"` // Only return routes that can be done in a single legacy transaction. (Routes might be limited) UserPublicKey string `url:"userPublicKey,omitempty"` // Public key of the user (only pass in if you want deposit and fee being returned, might slow down query) }
QuoteParams are the parameters for a quote request.
type QuoteResponse ¶
type QuoteResponse []Route
QuoteResponse is the response from a quote request.
func (QuoteResponse) GetBestRoute ¶
func (q QuoteResponse) GetBestRoute() (Route, error)
GetBestRoute returns the best route from a quote response.
type Rate ¶
type Rate struct { InputMint string `json:"inputMint"` // input token mint OutputMint string `json:"outputMint"` // output token mint InAmount uint64 `json:"inAmount"` // amount of input token OutAmount uint64 `json:"outAmount"` // amount of output token }
ExchangeRate returns the exchange rate for a given input mint, output mint and amount.
type Response ¶
type Response struct { Data json.RawMessage `json:"data"` TimeTaken float64 `json:"timeTaken"` ContextSlot int64 `json:"contextSlot"` }
Response is a generic response structure.
type Route ¶
type Route struct { InAmount string `json:"inAmount"` OutAmount string `json:"outAmount"` PriceImpactPct float64 `json:"priceImpactPct"` MarketInfos []MarketInfo `json:"marketInfos"` Amount string `json:"amount"` SlippageBps int64 `json:"slippageBps"` // minimum: 0, maximum: 10000 OtherAmountThreshold string `json:"otherAmountThreshold"` // The threshold for the swap based on the provided slippage: when swapMode is ExactIn the minimum out amount, when swapMode is ExactOut the maximum in amount SwapMode string `json:"swapMode"` Fees *struct { SignatureFee int64 `json:"signatureFee"` // This inidicate the total amount needed for signing transaction(s). Value in lamports. OpenOrdersDeposits []int64 `json:"openOrdersDeposits"` // This inidicate the total amount needed for deposit of serum order account(s). Value in lamports. AtaDeposits []int64 `json:"ataDeposits"` // This inidicate the total amount needed for deposit of associative token account(s). Value in lamports. TotalFeeAndDeposits int64 `json:"totalFeeAndDeposits"` // This indicate the total lamports needed for fees and deposits above. MinimumSolForTransaction int64 `json:"minimumSOLForTransaction"` // This inidicate the minimum lamports needed for transaction(s). Might be used to create wrapped SOL and will be returned when the wrapped SOL is closed. Also ensures rent exemption of the wallet. } `json:"fees,omitempty"` }
Route is a route object structure.
type SwapParams ¶
type SwapParams struct { Route Route `json:"route"` // required UserPublicKey string `json:"userPublicKey,omitempty"` // required WrapUnwrapSol *bool `json:"wrapUnwrapSOL,omitempty"` FeeAccount string `json:"feeAccount,omitempty"` // Fee token account for the platform fee (only pass in if you set a feeBps), the mint is outputMint for the default swapMode.ExactOut and inputMint for swapMode.ExactIn. AsLegacyTransaction *bool `json:"asLegacyTransaction,omitempty"` // Request a legacy transaction rather than the default versioned transaction, needs to be paired with a quote using asLegacyTransaction otherwise the transaction might be too large. ComputeUnitPriceMicroLamports *int64 `json:"computeUnitPriceMicroLamports,omitempty"` // Compute unit price to prioritize the transaction, the additional fee will be compute unit consumed * computeUnitPriceMicroLamports. DestinationWallet string `json:"destinationWallet,omitempty"` // Public key of the wallet that will receive the output of the swap, this assumes the associated token account exists, currently adds a token transfer. }
SwapParams are the parameters for a swap request.
type SwapResponse ¶
type SwapResponse struct {
SwapTransaction string `json:"swapTransaction"` // base64 encoded transaction string
}
SwapResponse is the response from a swap request.