SPL Token Swap IDL
SPL Token Swap is the reference AMM implementation on Solana. Provides constant product, constant price, and offset curve swapping for any SPL token pair with configurable fees.
Program address
SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8- Instructions
- 6
- Accounts
- 6
- Events
- 0
- Types
- 1
What the program exposes
Instructions 6
- initialize
- swap
- depositAllTokenTypes
- withdrawAllTokenTypes
- depositSingleTokenTypeExactAmountIn
- withdrawSingleTokenTypeExactAmountOut
Accounts 6
- Fees
- SwapCurve
- SwapV1
- OffsetCurve
- ConstantProductCurve
- ConstantPriceCurve
Use it in your code
Load the SPL Token Swap IDL with Anchor in TypeScript, Rust or Python.
import { Connection, PublicKey } from "@solana/web3.js";
import { Program, AnchorProvider, Idl } from "@coral-xyz/anchor";
// Load the SPL Token Swap IDL
import idl from "./spl token swap.json";
const PROGRAM_ID = new PublicKey("SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8");
// Set up the provider and program
const connection = new Connection("https://api.mainnet-beta.solana.com");
const provider = new AnchorProvider(connection, wallet, {
commitment: "confirmed",
});
const program = new Program(idl as Idl, provider);
// Fetch and decode an account
const accountData = await program.account.sPL_Token_Swap
.fetch(accountPublicKey);
console.log("Account data:", accountData);
// Build and send an instruction
const tx = await program.methods
.initialize(/* ...args */)
.accounts({
/* ...required accounts */
})
.rpc();
console.log("Transaction signature:", tx);use anchor_client::solana_sdk::pubkey::Pubkey;
use anchor_client::solana_sdk::signature::Keypair;
use anchor_client::{Client, Cluster};
use std::str::FromStr;
// SPL Token Swap program ID
const PROGRAM_ID: &str = "SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8";
fn main() -> anyhow::Result<()> {
let payer = Keypair::new();
let client = Client::new(Cluster::Mainnet, &payer);
let program_id = Pubkey::from_str(PROGRAM_ID)?;
let program = client.program(program_id)?;
// Fetch and deserialize an account
let account: SPL_Token_SwapAccount = program.account(account_pubkey)?;
println!("Account data: {:?}", account);
// Build and send a transaction
let tx = program
.request()
.accounts(s_p_l__token__swap::accounts::Initialize {
// ...required accounts
})
.args(s_p_l__token__swap::instruction::Initialize {
// ...instruction args
})
.send()?;
println!("Transaction signature: {}", tx);
Ok(())
}from solana.rpc.api import Client
from solders.pubkey import Pubkey
from anchorpy import Program, Provider, Wallet
import json
# Load the SPL Token Swap IDL
with open("spl token swap.json") as f:
idl_data = json.load(f)
PROGRAM_ID = Pubkey.from_string("SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8")
# Set up the provider and program
client = Client("https://api.mainnet-beta.solana.com")
provider = Provider(client, Wallet.local())
program = Program(idl_data, PROGRAM_ID, provider)
# Fetch and decode an account
account = await program.account["SPL_Token_Swap"].fetch(account_pubkey)
print(f"Account data: {account}")
# Build and send an instruction
tx = await program.rpc["initialize"](
# ...instruction args
ctx=program.context(
accounts={
# ...required accounts
}
)
)
print(f"Transaction signature: {tx}")The JSON
The first 30 lines of spl token swap.json.
{
"version": "3.0.0",
"name": "spl_token_swap",
"instructions": [
{
"name": "initialize",
"accounts": [
{
"name": "swap",
"isMut": true,
"isSigner": true
},
{
"name": "authority",
"isMut": false,
"isSigner": false
},
{
"name": "tokenA",
"isMut": false,
"isSigner": false
},
{
"name": "tokenB",
"isMut": false,
"isSigner": false
},
{
"name": "pool",
"isMut": true,
...Frequently asked questions
What is the SPL Token Swap IDL?
The SPL Token Swap IDL (Interface Definition Language) is a JSON schema that describes the on-chain program interface for the SPL Token Swap smart contract on Solana. It defines all available instructions, account structures, events, and types needed to interact with the program. This one has 6 instructions, 6 account types, 0 events and 1 type definitions.
How do I use the SPL Token Swap IDL in my project?
You can use the SPL Token Swap IDL with Anchor framework clients in TypeScript (@coral-xyz/anchor), Rust (anchor-client), or Python (anchorpy). Download the JSON file, import it in your project, and use it to create a Program instance that can call instructions and decode accounts.
What is the SPL Token Swap program address on Solana?
The SPL Token Swap program is deployed at address SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8 on Solana mainnet.
What version of the SPL Token Swap IDL is this?
This is version 3.0.0 of the SPL Token Swap IDL. IDL versions follow program deployments and change as the protocol evolves, so check it against the program on-chain before you integrate.
Build on SPL Token Swap with AllenHark
Stream the program's accounts and transactions with Yellowstone gRPC, read its state over Solana RPC, or see its transactions before the block is built with ShredStream. To trade against it, try the trading bots or the PumpFun sniper.
Browse all Solana IDLs