Solana.SPL.TokenSwap (Solana v0.1.0)

View Source

Functions for interacting with Solana's Token Swap Program.

Summary

Functions

The size of a serialized token swap account.

Creates the instructions to deposit A or B tokens into the pool.

Creates the instructions to deposit both A and B tokens into the pool.

Translates the result of a Solana.RPC.Request.get_account_info/2 into token swap account information.

The Token Swap Program's ID.

Creates the instructions to initialize a new token swap account.

Creates the instructions to swap token A for token B or vice versa.

Creates the instructions to withdraw A or B tokens from the pool.

Creates the instructions to withdraw both A and B tokens from the pool.

Functions

byte_size()

@spec byte_size() :: pos_integer()

The size of a serialized token swap account.

deposit(opts)

Creates the instructions to deposit A or B tokens into the pool.

Options

  • :swap - Required. The token swap to use.

  • :authority - Required. the swap account's swap authority.

  • :user_token - Required. The user's account for token A or B.

  • :swap_a - Required. The swap account for token A.

  • :swap_b - Required. The swap account for token B.

  • :user_pool - Required. The user's account for the pool token. Pool tokens will be deposited here.

  • :pool_mint - Required. The swap pool token's mint.

  • :user_authority - Required. Account delegated to transfer the user's tokens.

  • :amount (pos_integer/0) - Required. Amount of token A or B to deposit.

  • :amount_pool (pos_integer/0) - Required. Minimum amount of pool tokens to mint.

deposit_all(opts)

Creates the instructions to deposit both A and B tokens into the pool.

Options

  • :swap - Required. The token swap to use.

  • :authority - Required. the swap account's swap authority.

  • :user_a - Required. The user's account for token A.

  • :user_b - Required. The user's account for token B.

  • :swap_a - Required. The swap account for token A.

  • :swap_b - Required. The swap account for token B.

  • :user_pool - Required. The user's account for the pool token. Pool tokens will be deposited here.

  • :pool_mint - Required. The swap pool token's mint.

  • :user_authority - Required. Account delegated to transfer the user's tokens.

  • :amount_a (pos_integer/0) - Required. Maximum amount of token A to deposit.

  • :amount_b (pos_integer/0) - Required. Maximum amount of token B to deposit.

  • :amount_pool (pos_integer/0) - Required. Amount of pool tokens to mint.

from_account_info(info)

@spec from_account_info(info :: map()) :: map() | :error

Translates the result of a Solana.RPC.Request.get_account_info/2 into token swap account information.

id()

@spec id() :: binary()

The Token Swap Program's ID.

init(opts)

Creates the instructions to initialize a new token swap account.

Options

  • :payer - Required. The account that will pay for the token swap account creation.

  • :balance (non_neg_integer/0) - Required. The lamport balance the token swap account should have.

  • :authority - Required. The token swap account's swap authority

  • :new - Required. The public key of the newly-created token swap account.

  • :token_a - Required. The A token account in token swaps. Must be owned by authority.

  • :token_b - Required. The B token account in token swaps. Must be owned by authority.

  • :pool - Required. The token account which holds outside liquidity and enables A/B trades.

  • :pool_mint - Required. The mint of the pool.

  • :fee_account - Required. The token account which receives all trading and withdrawal fees.

  • :trade_fee - The new swap account's trading fee. Trade fees are extra token amounts that are held inside the token accounts during a trade, making the value of liquidity tokens rise. The default value is {0, 1}.

  • :owner_trade_fee - The new swap account's owner trading fee. Owner trading fees are extra token amounts that are held inside the token accounts during a trade, with the equivalent in pool tokens minted to the owner of the program. The default value is {0, 1}.

  • :owner_withdraw_fee - The new swap account's owner withdraw fee. Owner withdraw fees are extra liquidity pool token amounts that are sent to the owner on every withdrawal. The default value is {0, 1}.

  • :host_fee - The new swap account's host fee. Host fees are a proportion of the owner trading fees, sent to an extra account provided during the trade. The default value is {0, 1}.

  • :curve - Required. The automated market maker (AMM) curve to use for the new token swap account. Should take the form {type, params}. See the docs on which curves are available.

swap(opts)

Creates the instructions to swap token A for token B or vice versa.

Options

  • :swap - Required. The token swap to use.

  • :authority - Required. the swap account's swap authority.

  • :user_source - Required. User's source token account. Must have the same mint as swap_source.

  • :swap_source - Required. swap source token account. Must have the same mint as user_source.

  • :user_destination - Required. User's destination token account. Must have the same mint as swap_destination.

  • :swap_destination - Required. swap destination token account. Must have the same mint as user_destination.

  • :pool_mint - Required. The swap pool token's mint.

  • :fee_account - Required. The token account which receives all trading and withdrawal fees.

  • :host_fee_account - Host account to gather fees.

  • :user_authority - Required. Account delegated to transfer the user's tokens.

  • :amount (pos_integer/0) - Required. Amount to transfer from the source account.

  • :minimum_return (pos_integer/0) - Required. Minimum number of tokens the user will receive.

withdraw(opts)

Creates the instructions to withdraw A or B tokens from the pool.

Options

  • :swap - Required. The token swap to use.

  • :authority - Required. the swap account's swap authority.

  • :user_token - Required. The user's account for token A or B.

  • :swap_a - Required. The swap account for token A.

  • :swap_b - Required. The swap account for token B.

  • :user_pool - Required. The user's account for the pool token. Pool tokens with be withdrawn from here.

  • :pool_mint - Required. The swap pool token's mint.

  • :user_authority - Required. Account delegated to transfer the user's tokens.

  • :fee_account - Required. The token account which receives all trading and withdrawal fees.

  • :amount (pos_integer/0) - Required. Amount of token A or B to withdraw.

  • :amount_pool (pos_integer/0) - Required. Maximum amount of pool tokens to burn.

withdraw_all(opts)

Creates the instructions to withdraw both A and B tokens from the pool.

Options

  • :swap - Required. The token swap to use.

  • :authority - Required. the swap account's swap authority.

  • :user_a - Required. The user's account for token A.

  • :user_b - Required. The user's account for token B.

  • :swap_a - Required. The swap account for token A.

  • :swap_b - Required. The swap account for token B.

  • :user_pool - Required. The user's account for the pool token. Pool tokens with be withdrawn from here.

  • :pool_mint - Required. The swap pool token's mint.

  • :user_authority - Required. Account delegated to transfer the user's tokens.

  • :fee_account - Required. The token account which receives all trading and withdrawal fees.

  • :amount_a (pos_integer/0) - Required. Minimum amount of token A to withdraw.

  • :amount_b (pos_integer/0) - Required. Minimum amount of token B to withdraw.

  • :amount_pool (pos_integer/0) - Required. Amount of pool tokens to burn.