Lifinity AMM v2 decoder
Decode Lifinity AMM v2 instructions and accounts in Rust with carbon-lifinity-amm-v2-decoder 2.0.0. Program ID 2wT8Yq49kHgDzXuPxZSaeLaH1qbmGXtEyPy64bL7aD3c.
On this page
carbon-lifinity-amm-v2-decoder decodes the instructions and accounts of the Lifinity AMM v2 program (2wT8Yq49kHgDzXuPxZSaeLaH1qbmGXtEyPy64bL7aD3c): 3 instructions, 1 account type. It is generated with Codama from the program's IDL; see decoders for how decoders plug into a pipeline.
| Crate | carbon-lifinity-amm-v2-decoder 2.0.0 |
| Install | cargo add carbon-lifinity-amm-v2-decoder@2. |
| Program ID | 2wT8Yq49kHgDzXuPxZSaeLaH1qbmGXtEyPy64bL7aD3c (carbon_) |
| Category | DEX & AMM |
| Decoder | carbon_ |
| Instruction enum | instructions:: |
| Account enum | accounts:: |
| Features | serde, postgres, graphql (none enabled by default) |
| API docs | docs.rs/carbon-lifinity-amm-v2-decoder/2.0.0 |
| Source | decoders/lifinity-amm-v2-decoder |
Other DEX and AMM decoders: BonkSwap, FluxBeam, Gavel, Heaven, Jupiter Limit Order, Jupiter Limit Order v2, Kamino Limit Order, Meteora DAMM v2, Meteora DLMM, Meteora Pools, OpenBook v2, Orca Whirlpools, PancakeSwap, Phoenix v1, PumpSwap, Raydium AMM v4, Raydium CLMM, Raydium CPMM, Raydium Stable Swap, Stabble Stable Swap, Stabble Weighted Swap. To decode several in one pipeline, see dEX and AMM decoders.
The serde feature derives Serialize/Deserialize on every type, postgres adds tables and processors for Postgres, and graphql adds a schema for the GraphQL server.
Usage#
This program crawls recent Lifinity AMM v2 transactions from the public RPC and prints every decoded Swap instruction. Add the dependencies:
cargo add carbon-core@2.0.0 carbon-lifinity-amm-v2-decoder@2.0.0 carbon-rpc-transaction-crawler-datasource@2.0.0 carbon-log-metrics@2.0.0 env_logger tokio --features tokio/fulluse {
carbon_core::{
error::CarbonResult, instruction::InstructionProcessorInputType, pipeline::Pipeline,
processor::Processor,
},
carbon_log_metrics::LogMetrics,
carbon_lifinity_amm_v2_decoder::{
instructions::LifinityAmmV2Instruction, LifinityAmmV2Decoder, PROGRAM_ID,
},
carbon_rpc_transaction_crawler_datasource::{ConnectionConfig, Filters, RpcTransactionCrawler},
std::sync::Arc,
};
#[tokio::main]
async fn main() -> CarbonResult<()> {
env_logger::init();
// Fetches the program's recent transactions over JSON-RPC, newest first.
let datasource = RpcTransactionCrawler::new(
"https://api.mainnet-beta.solana.com".to_string(),
PROGRAM_ID,
ConnectionConfig::default(),
Filters::new(None, None, None),
None,
);
Pipeline::builder()
.datasource(datasource)
.metrics(Arc::new(LogMetrics::new()))
.instruction(LifinityAmmV2Decoder, InstructionLogger)
.build()?
.run()
.await
}
struct InstructionLogger;
impl Processor<InstructionProcessorInputType<'_, LifinityAmmV2Instruction>> for InstructionLogger {
async fn process(
&mut self,
input: &InstructionProcessorInputType<'_, LifinityAmmV2Instruction>,
) -> CarbonResult<()> {
let signature = input.metadata.transaction_metadata.signature;
if let LifinityAmmV2Instruction::Swap { data, accounts, .. } = input.decoded_instruction {
println!("swap {signature}: {data:?} authority={}", accounts.authority);
}
Ok(())
}
}RUST_LOG=info cargo runEach Swap instruction prints one line with the transaction signature and the decoded Swap data. The public endpoint rate-limits requests, so the first lines can take a while; use your own RPC URL for anything beyond a test. See stream with RPC for the crawler options.
Decode accounts#
The transaction crawler emits transactions only. To decode accounts, use a datasource that emits account updates. This program subscribes to the program's accounts with programSubscribe on the public WebSocket endpoint and prints every decoded Amm account as it changes. Add the datasource and the Solana RPC types it takes:
cargo add carbon-rpc-program-subscribe-datasource@2.0.0 solana-client@4.2.2use {
carbon_core::{
account::AccountProcessorInputType, error::CarbonResult, pipeline::Pipeline,
processor::Processor,
},
carbon_log_metrics::LogMetrics,
carbon_lifinity_amm_v2_decoder::{
accounts::LifinityAmmV2Account, LifinityAmmV2Decoder, PROGRAM_ID,
},
carbon_rpc_program_subscribe_datasource::{Filters, RpcProgramSubscribe},
solana_client::rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig, UiAccountEncoding},
std::sync::Arc,
};
#[tokio::main]
async fn main() -> CarbonResult<()> {
env_logger::init();
// Streams every change to an account owned by the program (programSubscribe).
let config = RpcProgramAccountsConfig {
account_config: RpcAccountInfoConfig {
encoding: Some(UiAccountEncoding::Base64),
..Default::default()
},
..Default::default()
};
let datasource = RpcProgramSubscribe::new(
"wss://api.mainnet-beta.solana.com".to_string(),
Filters::new(PROGRAM_ID, Some(config)),
);
Pipeline::builder()
.datasource(datasource)
.metrics(Arc::new(LogMetrics::new()))
.account(LifinityAmmV2Decoder, AccountLogger)
.build()?
.run()
.await
}
struct AccountLogger;
impl Processor<AccountProcessorInputType<'_, LifinityAmmV2Account>> for AccountLogger {
async fn process(
&mut self,
input: &AccountProcessorInputType<'_, LifinityAmmV2Account>,
) -> CarbonResult<()> {
let LifinityAmmV2Account::Amm(amm) = &input.decoded_account.data;
println!("amm {}: {amm:?}", input.metadata.pubkey);
Ok(())
}
}RUST_LOG=info cargo runEach update to a Amm account prints its address and decoded fields; the program runs until you stop it. Cargo resolves solana-client to 4.2.2, the exact version the datasource pins, so both use the same RpcProgramAccountsConfig type. To load every existing account once instead of streaming changes, see load account state.
Instructions#
Variants of LifinityAmmV2Instruction. Each is LifinityAmmV2Instruction::, where data and accounts are the types listed under the variant, exported from carbon_. Discriminators are the leading bytes of the instruction data, in hex.
How an instruction decodes. The decoder returns a variant only when all of these hold; otherwise the instruction is skipped and no processor is called:
- The instruction's program ID is
2wT8Yq49kHgDzXuPxZSaeLaH1qbmGXtEyPy64bL7aD3c. - The data starts with the variant's discriminator, and the rest deserializes into its data type.
- The instruction has at least as many accounts as the variant requires (the "Required accounts" count under each variant).
Accounts. They are matched by position, in the order listed. An account marked optional is None only when the instruction ends before it; Anchor programs pass the program ID as a placeholder for an omitted optional account, so check for Some(PROGRAM_ too. Accounts after the listed ones are in accounts. as AccountMetas. The decoder doesn't record whether an account signed or was writable: read that from input. and ., which follow the same order. It doesn't check signer, writable, owner or PDA constraints either; the program enforced those when the transaction executed, so a decoded instruction from a successful transaction already satisfied them.
DepositAllTokenTypes#
Discriminator 205f453c4b4fcdee · data DepositAllTokenTypes · accounts DepositAllTokenTypesInstructionAccounts.
| Field | Type |
|---|---|
pool_ | u64 |
maximum_ | u64 |
maximum_ | u64 |
Required accounts: 10; extras go to remaining.
Fields of DepositAllTokenTypesInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | amm | Pubkey |
| 1 | authority | Pubkey |
| 2 | user_ | Pubkey |
| 3 | source_ | Pubkey |
| 4 | source_ | Pubkey |
| 5 | token_a | Pubkey |
| 6 | token_b | Pubkey |
| 7 | pool_mint | Pubkey |
| 8 | destination | Pubkey |
| 9 | token_ | Pubkey |
| 10… | remaining | Vec< |
Swap#
Discriminator f8c69e91e17587c8 · data Swap · accounts SwapInstructionAccounts.
| Field | Type |
|---|---|
amount_in | u64 |
minimum_ | u64 |
Required accounts: 13; extras go to remaining.
Fields of SwapInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | authority | Pubkey |
| 1 | amm | Pubkey |
| 2 | user_ | Pubkey |
| 3 | source_info | Pubkey |
| 4 | destination_ | Pubkey |
| 5 | swap_source | Pubkey |
| 6 | swap_ | Pubkey |
| 7 | pool_mint | Pubkey |
| 8 | fee_account | Pubkey |
| 9 | token_ | Pubkey |
| 10 | oracle_ | Pubkey |
| 11 | oracle_ | Pubkey |
| 12 | oracle_ | Pubkey |
| 13… | remaining | Vec< |
WithdrawAllTokenTypes#
Discriminator bdfe9caed209a4d8 · data WithdrawAllTokenTypes · accounts WithdrawAllTokenTypesInstructionAccounts.
| Field | Type |
|---|---|
pool_ | u64 |
minimum_ | u64 |
minimum_ | u64 |
Required accounts: 10; extras go to remaining.
Fields of WithdrawAllTokenTypesInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | amm | Pubkey |
| 1 | authority | Pubkey |
| 2 | user_ | Pubkey |
| 3 | source_info | Pubkey |
| 4 | token_a | Pubkey |
| 5 | token_b | Pubkey |
| 6 | pool_mint | Pubkey |
| 7 | dest_ | Pubkey |
| 8 | dest_ | Pubkey |
| 9 | token_ | Pubkey |
| 10… | remaining | Vec< |
Accounts#
Variants of LifinityAmmV2Account. Each wraps a boxed struct from carbon_. decode_ only considers accounts owned by PROGRAM_ID and returns the first variant that matches.
Amm#
Discriminator 8ff5c8114ad6c487 · accounts::.
| Field | Type | Description |
|---|---|---|
initializer_ | Pubkey | |
initializer_ | Pubkey | |
initializer_ | Pubkey | |
initializer_ | u64 | |
taker_ | u64 | |
is_ | bool | Is the swap initialized, with data written to it |
bump_seed | u8 | Bump seed used to generate the program address / authority |
freeze_ | u8 | Freeze swap |
freeze_ | u8 | Freeze deposit |
freeze_ | u8 | Freeze withdraw |
base_ | u8 | Base decimals account |
token_ | Pubkey | Token program ID associated with the swap |
token_ | Pubkey | Address of token A liquidity account |
token_ | Pubkey | Address of token B liquidity account |
pool_mint | Pubkey | Address of pool token mint |
token_ | Pubkey | Address of token A mint |
token_ | Pubkey | Address of token B mint |
fee_account | Pubkey | Address of pool fee account |
oracle_ | Pubkey | Oracle Main account |
oracle_ | Pubkey | Oracle Sub account |
oracle_ | Pubkey | oracle Pc account |
fees | AmmFees | Fees associated with swap |
curve | AmmCurve | Curve associated with swap |
config | AmmConfig | Curve associated with swap |
amm_p_temp1 | Pubkey | Temp area |
amm_p_temp2 | Pubkey | Temp area |
amm_p_temp3 | Pubkey | Temp area |
amm_p_temp4 | Pubkey | Temp area |
amm_p_temp5 | Pubkey | Temp area |
Types#
Types used by the instructions, accounts and events above, exported from carbon_.
AmmConfig#
Struct types::.
| Field | Type |
|---|---|
last_price | u64 |
last_ | u64 |
config_ | u64 |
volume_x | u64 |
volume_y | u64 |
volume_ | u64 |
deposit_cap | u64 |
regression_ | u64 |
oracle_type | u64 |
oracle_ | u64 |
oracle_ | u64 |
oracle_ | u64 |
oracle_ | u64 |
oracle_ | u64 |
oracle_ | u64 |
std_spread | u64 |
std_ | u64 |
spread_ | u64 |
price_ | i64 |
price_ | i64 |
rebalance_ | u64 |
fee_trade | u64 |
fee_ | u64 |
oracle_ | u64 |
config_ | u64 |
config_ | u64 |
config_ | u64 |
config_ | u64 |
config_ | u64 |
AmmCurve#
Struct types::.
| Field | Type |
|---|---|
curve_type | u8 |
curve_ | u64 |
AmmFees#
From the program's IDL:
Encapsulates all fee information and calculations for swap operations
Struct types::.
| Field | Type |
|---|---|
trade_ | u64 |
trade_ | u64 |
owner_ | u64 |
owner_ | u64 |
owner_ | u64 |
owner_ | u64 |
host_ | u64 |
host_ | u64 |
CurveType#
From the program's IDL:
Curve types supported by the token-swap program.
Enum types::.
| Variant |
|---|
Standard |
ConstantProduct |