jupag

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: MIT Imports: 12 Imported by: 0

README

go-jup-ag

Documentation

Index

Constants

View Source
const (
	SwapModeExactIn  = "ExactIn"
	SwapModeExactOut = "ExactOut"
)

Variables

This section is empty.

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 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 Jupag

type Jupag interface {
	Quote(params QuoteParams) (QuoteResponse, error)
	Swap(params SwapParams) (string, error)
	Price(params PriceParams) (PriceMap, error)
	RoutesMap(onlyDirectRoutes bool) (IndexedRoutesMap, error)
	BestSwap(params BestSwapParams) (string, error)
	ExchangeRate(params ExchangeRateParams) (Rate, error)
	// contains filtered or unexported methods
}

func NewJupag

func NewJupag() Jupag

type JupagImpl

type JupagImpl struct {
	// contains filtered or unexported fields
}

func (*JupagImpl) BestSwap added in v0.1.2

func (c *JupagImpl) 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 (*JupagImpl) ExchangeRate added in v0.1.2

func (c *JupagImpl) 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 (*JupagImpl) Price

func (c *JupagImpl) Price(params PriceParams) (PriceMap, error)

Price returns simple price for a given input mint, output mint and amount.

func (*JupagImpl) Quote

func (c *JupagImpl) Quote(params QuoteParams) (QuoteResponse, error)

Quote returns a quote for a given input mint, output mint and amount

func (*JupagImpl) RoutesMap

func (c *JupagImpl) RoutesMap(onlyDirectRoutes bool) (IndexedRoutesMap, error)

RoutesMap returns a hash map, input mint as key and an array of valid output mint as values, token mints are indexed to reduce the file size.

func (*JupagImpl) Swap

func (c *JupagImpl) Swap(params SwapParams) (string, error)

Swap returns swap base64 serialized transaction for a route. The caller is responsible for signing the transactions.

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         string `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.
	Type          string `json:"type"`          // Type of price
}

Price is a price object structure.

type PriceMap

type PriceMap map[string]Price

PriceMap is a price map objects 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 added in v0.1.2

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"`
}

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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