Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SolanaTracker ¶
type SolanaTracker struct { BaseURL string // The base URL for the Solana Swap API RPC string // The URL for the Solana RPC node. Keypair solana.PrivateKey // The private key used for signing transactions. }
SolanaTracker struct is used to interact with the Solana swap API.
Fields:
- BaseURL: The base URL for the Solana swap API.
- RPC: The URL for the Solana RPC node.
- Keypair: The private key used for signing transactions.
func NewSolanaTracker ¶
func NewSolanaTracker(keypair solana.PrivateKey, rpcURL string) *SolanaTracker
NewSolanaTracker creates a new instance of SolanaTracker with the given keypair and RPC URL.
The base URL for the Solana Swap API is hardcoded as "https://swap-v2.solanatracker.io".
Parameters:
- keypair: The private key used for signing transactions.
- rpcURL: The URL for the Solana RPC node.
Returns:
- *SolanaTracker: A pointer to a new SolanaTracker struct with the provided keypair, rpcURL, and base URL.
func (*SolanaTracker) GetSwapInstructions ¶
func (st *SolanaTracker) GetSwapInstructions(fromToken string, toToken string, fromAmount float64, slippage float64, payer string, priorityFee *float64, forceLegacy bool) (*SwapResponse, error)
GetSwapInstructions fetches the swap instructions from SolanaTracker.
Parameters:
- fromToken: The address of the token to swap from.
- toToken: The address of the token to swap to.
- fromAmount: The amount of token to swap from.
- slippage: Maximum tolerated price slippage before cancelling.
- payer: The address of the payer for the swap.
- priorityFee: The priority fee for the swap transaction.
- forceLegacy: Wether to force legacy mode.
Returns:
- SwapResponse: The instructions to perform the swap.
- (Optional) Error if one occurs.
func (*SolanaTracker) PerformSwap ¶
func (st *SolanaTracker) PerformSwap(swapResponse *SwapResponse, options SwapOptions) (string, error)
PerformSwap sends and confirms a transaction.
Parameters:
- swapResponse: The swap instructions provided by SolanaTracker.
- options: The SwapOptions for the transaction
Returns:
- Signature of the transaction.
- (Optional) Error if one occurs.
type SwapOptions ¶
type SwapOptions struct { SendOptions rpc.TransactionOpts /* Number of times to retry confirming a transaction. If the transaction confirmation fails, the client will retry confirming the transaction this many times before giving up. */ ConfirmationRetries int /* Maximum amount of time to wait for transaction confirmation. If transaction confirmation takes longer than this timeout, the client will give up and return an error. */ ConfirmationRetryTimeout time.Duration /* Number of blocks to buffer when checking the last valid block height. Used to ensure that the transaction is still valid when it is confirmed. */ LastValidBlockHeightBuffer uint64 /* Determines the required commitment level the transaction must have before it is considered successful. Default: CommitmentFinalized Options: - CommitmentFinalized - CommitmentConfirmed - CommitmentProcessed Starting with solana-go@v1.5.5, commitment levels `max`, `recent`, `root`, `single` and `singleGossip` are deprecated. */ Commitment rpc.CommitmentType // Amount of time to wait between resending a transaction. ResendInterval time.Duration // Amount of time to wait between transaction confirmation status checks. ConfirmationCheckInterval time.Duration /* Whether to skip the transaction confirmation check. If true, the client will not wait for the transaction to be confirmed and will return the signature immediately after sending the transaction. */ SkipConfirmationCheck bool }
SwapOptions is a struct that contains options that can be used to customize the behavior of the transaction sending and confirmation process.
Fields:
- SendOptions: A solana-go/rpc.TransactionOpts struct. It includes the preflight commitment level, skipping preflight, and maximum retries.
- ConfirmationRetries: Number of times to retry confirming a transaction.
- ConfirmationRetryTimeout: Maximum amount of time to wait for transaction confirmation.
- LastValidBlockHeightBuffer: Number of blocks to buffer when checking the last valid block height.
- Determines the required commitment level the transaction must have before it is considered successful.
- ResendInterval: Amount of time to wait between resending a transaction.
- ConfirmationCheckInterval: Amount of time to wait between transaction confirmation status checks.
- SkipConfirmationCheck: Whether to skip the transaction confirmation check.
type SwapResponse ¶
type SwapResponse struct { Txn string `json:"txn"` // The base64-encoded transaction that needs to be sent. ForceLegacy bool `json:"forceLegacy"` // Whether to force legacy mode for the transaction. }
SwapResponse is the response from SolanaTracker.
Contains the instructions to perform the swap.
Fields:
- Txn: The base64-encoded transaction that needs to be sent.
- ForceLegacy: Whether to force legacy mode for the transaction.