0.7.27 +Refactor
This commit is contained in:
@@ -2,12 +2,9 @@
|
||||
|
||||
//! Meteora DAMM v1 transaction decoder.
|
||||
|
||||
/// Meteora DAMM v1 program id.
|
||||
pub const KB_METEORA_DAMM_V1_PROGRAM_ID: &str = "Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB";
|
||||
|
||||
/// Decoded Meteora DAMM v1 create-pool event.
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct KbMeteoraDammV1CreatePoolDecoded {
|
||||
pub struct MeteoraDammV1CreatePoolDecoded {
|
||||
/// Parent transaction id.
|
||||
pub transaction_id: i64,
|
||||
/// Parent instruction id.
|
||||
@@ -34,7 +31,7 @@ pub struct KbMeteoraDammV1CreatePoolDecoded {
|
||||
|
||||
/// Decoded Meteora DAMM v1 swap event.
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct KbMeteoraDammV1SwapDecoded {
|
||||
pub struct MeteoraDammV1SwapDecoded {
|
||||
/// Parent transaction id.
|
||||
pub transaction_id: i64,
|
||||
/// Parent instruction id.
|
||||
@@ -44,7 +41,7 @@ pub struct KbMeteoraDammV1SwapDecoded {
|
||||
/// Program id.
|
||||
pub program_id: std::string::String,
|
||||
/// Trade side relative to normalized base.
|
||||
pub trade_side: crate::KbSwapTradeSide,
|
||||
pub trade_side: crate::SwapTradeSide,
|
||||
/// Optional pool account.
|
||||
pub pool_account: std::option::Option<std::string::String>,
|
||||
/// Optional token A mint.
|
||||
@@ -57,26 +54,26 @@ pub struct KbMeteoraDammV1SwapDecoded {
|
||||
|
||||
/// Decoded Meteora DAMM v1 event.
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub enum KbMeteoraDammV1DecodedEvent {
|
||||
pub enum MeteoraDammV1DecodedEvent {
|
||||
/// Pool creation.
|
||||
CreatePool(KbMeteoraDammV1CreatePoolDecoded),
|
||||
CreatePool(MeteoraDammV1CreatePoolDecoded),
|
||||
/// Swap.
|
||||
Swap(KbMeteoraDammV1SwapDecoded),
|
||||
Swap(MeteoraDammV1SwapDecoded),
|
||||
}
|
||||
|
||||
/// Meteora DAMM v1 decoder.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct KbMeteoraDammV1Decoder;
|
||||
pub struct MeteoraDammV1Decoder;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum KbMeteoraDammV1InstructionKind {
|
||||
enum MeteoraDammV1InstructionKind {
|
||||
CreatePool,
|
||||
CreatePoolWithConfig,
|
||||
Swap,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl KbMeteoraDammV1Decoder {
|
||||
impl MeteoraDammV1Decoder {
|
||||
/// Creates a new decoder.
|
||||
pub fn new() -> Self {
|
||||
return Self;
|
||||
@@ -85,14 +82,14 @@ impl KbMeteoraDammV1Decoder {
|
||||
/// Decodes one projected transaction into zero or more Meteora DAMM v1 events.
|
||||
pub fn decode_transaction(
|
||||
&self,
|
||||
transaction: &crate::KbChainTransactionDto,
|
||||
instructions: &[crate::KbChainInstructionDto],
|
||||
) -> Result<std::vec::Vec<crate::KbMeteoraDammV1DecodedEvent>, crate::KbError> {
|
||||
transaction: &crate::ChainTransactionDto,
|
||||
instructions: &[crate::ChainInstructionDto],
|
||||
) -> Result<std::vec::Vec<crate::MeteoraDammV1DecodedEvent>, crate::Error> {
|
||||
let transaction_id_option = transaction.id;
|
||||
let transaction_id = match transaction_id_option {
|
||||
Some(transaction_id) => transaction_id,
|
||||
None => {
|
||||
return Err(crate::KbError::InvalidState(format!(
|
||||
return Err(crate::Error::InvalidState(format!(
|
||||
"chain transaction '{}' has no internal id",
|
||||
transaction.signature
|
||||
)));
|
||||
@@ -103,13 +100,13 @@ impl KbMeteoraDammV1Decoder {
|
||||
let transaction_json = match transaction_json_result {
|
||||
Ok(transaction_json) => transaction_json,
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Json(format!(
|
||||
return Err(crate::Error::Json(format!(
|
||||
"cannot parse transaction_json for signature '{}': {}",
|
||||
transaction.signature, error
|
||||
)));
|
||||
},
|
||||
};
|
||||
let log_messages = kb_extract_log_messages(&transaction_json);
|
||||
let log_messages = extract_log_messages(&transaction_json);
|
||||
let mut decoded_events = std::vec::Vec::new();
|
||||
for instruction in instructions {
|
||||
if instruction.parent_instruction_id.is_some() {
|
||||
@@ -120,7 +117,7 @@ impl KbMeteoraDammV1Decoder {
|
||||
Some(program_id) => program_id,
|
||||
None => continue,
|
||||
};
|
||||
if program_id.as_str() != crate::KB_METEORA_DAMM_V1_PROGRAM_ID {
|
||||
if program_id.as_str() != crate::METEORA_DAMM_V1_PROGRAM_ID {
|
||||
continue;
|
||||
}
|
||||
let instruction_id_option = instruction.id;
|
||||
@@ -128,49 +125,47 @@ impl KbMeteoraDammV1Decoder {
|
||||
Some(instruction_id) => instruction_id,
|
||||
None => continue,
|
||||
};
|
||||
let accounts_result = kb_parse_accounts_json(instruction.accounts_json.as_str());
|
||||
let accounts_result = parse_accounts_json(instruction.accounts_json.as_str());
|
||||
let accounts = match accounts_result {
|
||||
Ok(accounts) => accounts,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let parsed_json_result =
|
||||
kb_parse_optional_parsed_json(instruction.parsed_json.as_ref());
|
||||
let parsed_json_result = parse_optional_parsed_json(instruction.parsed_json.as_ref());
|
||||
let parsed_json = match parsed_json_result {
|
||||
Ok(parsed_json) => parsed_json,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let instruction_kind =
|
||||
kb_classify_instruction_kind(parsed_json.as_ref(), &log_messages);
|
||||
let pool_account = kb_extract_string_by_candidate_keys(
|
||||
let instruction_kind = classify_instruction_kind(parsed_json.as_ref(), &log_messages);
|
||||
let pool_account = extract_string_by_candidate_keys(
|
||||
parsed_json.as_ref(),
|
||||
&["pool", "poolAddress", "poolAccount", "amm", "ammPool", "poolState"],
|
||||
)
|
||||
.or_else(|| return kb_extract_account(&accounts, 0));
|
||||
let token_a_mint = kb_extract_string_by_candidate_keys(
|
||||
.or_else(|| return extract_account(&accounts, 0));
|
||||
let token_a_mint = extract_string_by_candidate_keys(
|
||||
parsed_json.as_ref(),
|
||||
&["tokenAMint", "mintA", "baseMint", "token0Mint", "mint0", "coinMint"],
|
||||
)
|
||||
.or_else(|| return kb_extract_account(&accounts, 1));
|
||||
let token_b_mint = kb_extract_string_by_candidate_keys(
|
||||
.or_else(|| return extract_account(&accounts, 1));
|
||||
let token_b_mint = extract_string_by_candidate_keys(
|
||||
parsed_json.as_ref(),
|
||||
&["tokenBMint", "mintB", "quoteMint", "token1Mint", "mint1", "pcMint"],
|
||||
)
|
||||
.or_else(|| return kb_extract_account(&accounts, 2));
|
||||
let config_account = kb_extract_string_by_candidate_keys(
|
||||
.or_else(|| return extract_account(&accounts, 2));
|
||||
let config_account = extract_string_by_candidate_keys(
|
||||
parsed_json.as_ref(),
|
||||
&["config", "poolConfig", "ammConfig", "tradeFeeConfig"],
|
||||
)
|
||||
.or_else(|| return kb_extract_account(&accounts, 3));
|
||||
let creator = kb_extract_string_by_candidate_keys(
|
||||
.or_else(|| return extract_account(&accounts, 3));
|
||||
let creator = extract_string_by_candidate_keys(
|
||||
parsed_json.as_ref(),
|
||||
&["creator", "payer", "user", "owner"],
|
||||
)
|
||||
.or_else(|| return kb_extract_account(&accounts, 4));
|
||||
if instruction_kind == KbMeteoraDammV1InstructionKind::CreatePool
|
||||
|| instruction_kind == KbMeteoraDammV1InstructionKind::CreatePoolWithConfig
|
||||
.or_else(|| return extract_account(&accounts, 4));
|
||||
if instruction_kind == MeteoraDammV1InstructionKind::CreatePool
|
||||
|| instruction_kind == MeteoraDammV1InstructionKind::CreatePoolWithConfig
|
||||
{
|
||||
let used_config =
|
||||
instruction_kind == KbMeteoraDammV1InstructionKind::CreatePoolWithConfig;
|
||||
instruction_kind == MeteoraDammV1InstructionKind::CreatePoolWithConfig;
|
||||
let payload_json = serde_json::json!({
|
||||
"decoder": "meteora_damm_v1",
|
||||
"eventKind": "create_pool",
|
||||
@@ -187,8 +182,8 @@ impl KbMeteoraDammV1Decoder {
|
||||
"configAccount": config_account,
|
||||
"creator": creator
|
||||
});
|
||||
decoded_events.push(crate::KbMeteoraDammV1DecodedEvent::CreatePool(
|
||||
crate::KbMeteoraDammV1CreatePoolDecoded {
|
||||
decoded_events.push(crate::MeteoraDammV1DecodedEvent::CreatePool(
|
||||
crate::MeteoraDammV1CreatePoolDecoded {
|
||||
transaction_id,
|
||||
instruction_id,
|
||||
signature: transaction.signature.clone(),
|
||||
@@ -204,8 +199,8 @@ impl KbMeteoraDammV1Decoder {
|
||||
));
|
||||
continue;
|
||||
}
|
||||
if instruction_kind == KbMeteoraDammV1InstructionKind::Swap {
|
||||
let trade_side = kb_infer_trade_side(&log_messages);
|
||||
if instruction_kind == MeteoraDammV1InstructionKind::Swap {
|
||||
let trade_side = infer_trade_side(&log_messages);
|
||||
let payload_json = serde_json::json!({
|
||||
"decoder": "meteora_damm_v1",
|
||||
"eventKind": "swap",
|
||||
@@ -221,8 +216,8 @@ impl KbMeteoraDammV1Decoder {
|
||||
"tokenBMint": token_b_mint,
|
||||
"tradeSide": format!("{:?}", trade_side)
|
||||
});
|
||||
decoded_events.push(crate::KbMeteoraDammV1DecodedEvent::Swap(
|
||||
crate::KbMeteoraDammV1SwapDecoded {
|
||||
decoded_events.push(crate::MeteoraDammV1DecodedEvent::Swap(
|
||||
crate::MeteoraDammV1SwapDecoded {
|
||||
transaction_id,
|
||||
instruction_id,
|
||||
signature: transaction.signature.clone(),
|
||||
@@ -240,46 +235,46 @@ impl KbMeteoraDammV1Decoder {
|
||||
}
|
||||
}
|
||||
|
||||
fn kb_classify_instruction_kind(
|
||||
fn classify_instruction_kind(
|
||||
parsed_json: std::option::Option<&serde_json::Value>,
|
||||
log_messages: &[std::string::String],
|
||||
) -> KbMeteoraDammV1InstructionKind {
|
||||
let parsed_instruction_name = kb_extract_string_by_candidate_keys(
|
||||
) -> MeteoraDammV1InstructionKind {
|
||||
let parsed_instruction_name = extract_string_by_candidate_keys(
|
||||
parsed_json,
|
||||
&["instruction", "instructionName", "type", "name"],
|
||||
);
|
||||
if let Some(parsed_instruction_name) = parsed_instruction_name {
|
||||
let normalized = kb_normalize_text(parsed_instruction_name.as_str());
|
||||
let normalized = normalize_text(parsed_instruction_name.as_str());
|
||||
if normalized.contains("initializepoolwithconfig") {
|
||||
return KbMeteoraDammV1InstructionKind::CreatePoolWithConfig;
|
||||
return MeteoraDammV1InstructionKind::CreatePoolWithConfig;
|
||||
}
|
||||
if normalized.contains("initializepool") {
|
||||
return KbMeteoraDammV1InstructionKind::CreatePool;
|
||||
return MeteoraDammV1InstructionKind::CreatePool;
|
||||
}
|
||||
if normalized == "swap" {
|
||||
return KbMeteoraDammV1InstructionKind::Swap;
|
||||
return MeteoraDammV1InstructionKind::Swap;
|
||||
}
|
||||
}
|
||||
if kb_value_contains_any_key(parsed_json, &["poolConfig", "ammConfig", "tradeFeeConfig"]) {
|
||||
return KbMeteoraDammV1InstructionKind::CreatePoolWithConfig;
|
||||
if value_contains_any_key(parsed_json, &["poolConfig", "ammConfig", "tradeFeeConfig"]) {
|
||||
return MeteoraDammV1InstructionKind::CreatePoolWithConfig;
|
||||
}
|
||||
if kb_log_messages_contain_keyword(log_messages, "initialize_pool_with_config")
|
||||
|| kb_log_messages_contain_keyword(log_messages, "initializepoolwithconfig")
|
||||
if log_messages_contain_keyword(log_messages, "initialize_pool_with_config")
|
||||
|| log_messages_contain_keyword(log_messages, "initializepoolwithconfig")
|
||||
{
|
||||
return KbMeteoraDammV1InstructionKind::CreatePoolWithConfig;
|
||||
return MeteoraDammV1InstructionKind::CreatePoolWithConfig;
|
||||
}
|
||||
if kb_log_messages_contain_keyword(log_messages, "initialize_pool")
|
||||
|| kb_log_messages_contain_keyword(log_messages, "initializepool")
|
||||
if log_messages_contain_keyword(log_messages, "initialize_pool")
|
||||
|| log_messages_contain_keyword(log_messages, "initializepool")
|
||||
{
|
||||
return KbMeteoraDammV1InstructionKind::CreatePool;
|
||||
return MeteoraDammV1InstructionKind::CreatePool;
|
||||
}
|
||||
if kb_log_messages_contain_keyword(log_messages, "swap") {
|
||||
return KbMeteoraDammV1InstructionKind::Swap;
|
||||
if log_messages_contain_keyword(log_messages, "swap") {
|
||||
return MeteoraDammV1InstructionKind::Swap;
|
||||
}
|
||||
return KbMeteoraDammV1InstructionKind::Unknown;
|
||||
return MeteoraDammV1InstructionKind::Unknown;
|
||||
}
|
||||
|
||||
fn kb_extract_log_messages(
|
||||
fn extract_log_messages(
|
||||
transaction_json: &serde_json::Value,
|
||||
) -> std::vec::Vec<std::string::String> {
|
||||
let mut messages = std::vec::Vec::new();
|
||||
@@ -307,10 +302,10 @@ fn kb_extract_log_messages(
|
||||
return messages;
|
||||
}
|
||||
|
||||
fn kb_log_messages_contain_keyword(log_messages: &[std::string::String], keyword: &str) -> bool {
|
||||
let keyword_normalized = kb_normalize_text(keyword);
|
||||
fn log_messages_contain_keyword(log_messages: &[std::string::String], keyword: &str) -> bool {
|
||||
let keyword_normalized = normalize_text(keyword);
|
||||
for log_message in log_messages {
|
||||
let log_normalized = kb_normalize_text(log_message.as_str());
|
||||
let log_normalized = normalize_text(log_message.as_str());
|
||||
if log_normalized.contains(keyword_normalized.as_str()) {
|
||||
return true;
|
||||
}
|
||||
@@ -318,7 +313,7 @@ fn kb_log_messages_contain_keyword(log_messages: &[std::string::String], keyword
|
||||
return false;
|
||||
}
|
||||
|
||||
fn kb_normalize_text(value: &str) -> std::string::String {
|
||||
fn normalize_text(value: &str) -> std::string::String {
|
||||
let mut normalized = std::string::String::new();
|
||||
for character in value.chars() {
|
||||
if character.is_ascii_alphanumeric() {
|
||||
@@ -328,14 +323,14 @@ fn kb_normalize_text(value: &str) -> std::string::String {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
fn kb_parse_accounts_json(
|
||||
fn parse_accounts_json(
|
||||
accounts_json: &str,
|
||||
) -> Result<std::vec::Vec<std::string::String>, crate::KbError> {
|
||||
) -> Result<std::vec::Vec<std::string::String>, crate::Error> {
|
||||
let values_result = serde_json::from_str::<std::vec::Vec<serde_json::Value>>(accounts_json);
|
||||
let values = match values_result {
|
||||
Ok(values) => values,
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Json(format!(
|
||||
return Err(crate::Error::Json(format!(
|
||||
"cannot parse instruction accounts_json '{}': {}",
|
||||
accounts_json, error
|
||||
)));
|
||||
@@ -351,9 +346,9 @@ fn kb_parse_accounts_json(
|
||||
return Ok(accounts);
|
||||
}
|
||||
|
||||
fn kb_parse_optional_parsed_json(
|
||||
fn parse_optional_parsed_json(
|
||||
parsed_json: std::option::Option<&std::string::String>,
|
||||
) -> Result<std::option::Option<serde_json::Value>, crate::KbError> {
|
||||
) -> Result<std::option::Option<serde_json::Value>, crate::Error> {
|
||||
let parsed_json = match parsed_json {
|
||||
Some(parsed_json) => parsed_json,
|
||||
None => return Ok(None),
|
||||
@@ -362,7 +357,7 @@ fn kb_parse_optional_parsed_json(
|
||||
match value_result {
|
||||
Ok(value) => return Ok(Some(value)),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Json(format!(
|
||||
return Err(crate::Error::Json(format!(
|
||||
"cannot parse instruction parsed_json '{}': {}",
|
||||
parsed_json, error
|
||||
)));
|
||||
@@ -370,7 +365,7 @@ fn kb_parse_optional_parsed_json(
|
||||
}
|
||||
}
|
||||
|
||||
fn kb_extract_string_by_candidate_keys(
|
||||
fn extract_string_by_candidate_keys(
|
||||
value: std::option::Option<&serde_json::Value>,
|
||||
candidate_keys: &[&str],
|
||||
) -> std::option::Option<std::string::String> {
|
||||
@@ -378,10 +373,10 @@ fn kb_extract_string_by_candidate_keys(
|
||||
Some(value) => value,
|
||||
None => return None,
|
||||
};
|
||||
return kb_extract_string_by_candidate_keys_inner(value, candidate_keys);
|
||||
return extract_string_by_candidate_keys_inner(value, candidate_keys);
|
||||
}
|
||||
|
||||
fn kb_extract_string_by_candidate_keys_inner(
|
||||
fn extract_string_by_candidate_keys_inner(
|
||||
value: &serde_json::Value,
|
||||
candidate_keys: &[&str],
|
||||
) -> std::option::Option<std::string::String> {
|
||||
@@ -397,7 +392,7 @@ fn kb_extract_string_by_candidate_keys_inner(
|
||||
}
|
||||
for nested_value in object.values() {
|
||||
let nested_result =
|
||||
kb_extract_string_by_candidate_keys_inner(nested_value, candidate_keys);
|
||||
extract_string_by_candidate_keys_inner(nested_value, candidate_keys);
|
||||
if nested_result.is_some() {
|
||||
return nested_result;
|
||||
}
|
||||
@@ -407,7 +402,7 @@ fn kb_extract_string_by_candidate_keys_inner(
|
||||
if let Some(array) = value.as_array() {
|
||||
for nested_value in array {
|
||||
let nested_result =
|
||||
kb_extract_string_by_candidate_keys_inner(nested_value, candidate_keys);
|
||||
extract_string_by_candidate_keys_inner(nested_value, candidate_keys);
|
||||
if nested_result.is_some() {
|
||||
return nested_result;
|
||||
}
|
||||
@@ -416,7 +411,7 @@ fn kb_extract_string_by_candidate_keys_inner(
|
||||
return None;
|
||||
}
|
||||
|
||||
fn kb_value_contains_any_key(
|
||||
fn value_contains_any_key(
|
||||
value: std::option::Option<&serde_json::Value>,
|
||||
candidate_keys: &[&str],
|
||||
) -> bool {
|
||||
@@ -424,10 +419,10 @@ fn kb_value_contains_any_key(
|
||||
Some(value) => value,
|
||||
None => return false,
|
||||
};
|
||||
return kb_value_contains_any_key_inner(value, candidate_keys);
|
||||
return value_contains_any_key_inner(value, candidate_keys);
|
||||
}
|
||||
|
||||
fn kb_value_contains_any_key_inner(value: &serde_json::Value, candidate_keys: &[&str]) -> bool {
|
||||
fn value_contains_any_key_inner(value: &serde_json::Value, candidate_keys: &[&str]) -> bool {
|
||||
if let Some(object) = value.as_object() {
|
||||
for candidate_key in candidate_keys {
|
||||
if object.contains_key(*candidate_key) {
|
||||
@@ -435,7 +430,7 @@ fn kb_value_contains_any_key_inner(value: &serde_json::Value, candidate_keys: &[
|
||||
}
|
||||
}
|
||||
for nested_value in object.values() {
|
||||
if kb_value_contains_any_key_inner(nested_value, candidate_keys) {
|
||||
if value_contains_any_key_inner(nested_value, candidate_keys) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -443,7 +438,7 @@ fn kb_value_contains_any_key_inner(value: &serde_json::Value, candidate_keys: &[
|
||||
}
|
||||
if let Some(array) = value.as_array() {
|
||||
for nested_value in array {
|
||||
if kb_value_contains_any_key_inner(nested_value, candidate_keys) {
|
||||
if value_contains_any_key_inner(nested_value, candidate_keys) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -451,7 +446,7 @@ fn kb_value_contains_any_key_inner(value: &serde_json::Value, candidate_keys: &[
|
||||
return false;
|
||||
}
|
||||
|
||||
fn kb_extract_account(
|
||||
fn extract_account(
|
||||
accounts: &[std::string::String],
|
||||
index: usize,
|
||||
) -> std::option::Option<std::string::String> {
|
||||
@@ -461,20 +456,20 @@ fn kb_extract_account(
|
||||
return Some(accounts[index].clone());
|
||||
}
|
||||
|
||||
fn kb_infer_trade_side(log_messages: &[std::string::String]) -> crate::KbSwapTradeSide {
|
||||
if kb_log_messages_contain_keyword(log_messages, "buy") {
|
||||
return crate::KbSwapTradeSide::BuyBase;
|
||||
fn infer_trade_side(log_messages: &[std::string::String]) -> crate::SwapTradeSide {
|
||||
if log_messages_contain_keyword(log_messages, "buy") {
|
||||
return crate::SwapTradeSide::BuyBase;
|
||||
}
|
||||
if kb_log_messages_contain_keyword(log_messages, "sell") {
|
||||
return crate::KbSwapTradeSide::SellBase;
|
||||
if log_messages_contain_keyword(log_messages, "sell") {
|
||||
return crate::SwapTradeSide::SellBase;
|
||||
}
|
||||
return crate::KbSwapTradeSide::Unknown;
|
||||
return crate::SwapTradeSide::Unknown;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
fn make_create_transaction() -> crate::KbChainTransactionDto {
|
||||
let mut dto = crate::KbChainTransactionDto::new(
|
||||
fn make_create_transaction() -> crate::ChainTransactionDto {
|
||||
let mut dto = crate::ChainTransactionDto::new(
|
||||
"sig-meteora-damm-v1-create-1".to_string(),
|
||||
Some(890001),
|
||||
Some(1779500001),
|
||||
@@ -501,19 +496,19 @@ mod tests {
|
||||
return dto;
|
||||
}
|
||||
|
||||
fn make_create_instruction() -> crate::KbChainInstructionDto {
|
||||
let mut dto = crate::KbChainInstructionDto::new(
|
||||
fn make_create_instruction() -> crate::ChainInstructionDto {
|
||||
let mut dto = crate::ChainInstructionDto::new(
|
||||
501,
|
||||
None,
|
||||
0,
|
||||
None,
|
||||
Some(crate::KB_METEORA_DAMM_V1_PROGRAM_ID.to_string()),
|
||||
Some(crate::METEORA_DAMM_V1_PROGRAM_ID.to_string()),
|
||||
Some("meteora-damm-v1".to_string()),
|
||||
Some(1),
|
||||
serde_json::json!([
|
||||
"DammV1Pool111",
|
||||
"DammV1TokenA111",
|
||||
"So11111111111111111111111111111111111111112",
|
||||
crate::WSOL_MINT_ID,
|
||||
"DammV1Config111",
|
||||
"DammV1Creator111"
|
||||
])
|
||||
@@ -526,7 +521,7 @@ mod tests {
|
||||
"instruction": "initialize_pool_with_config",
|
||||
"pool": "DammV1Pool111",
|
||||
"tokenAMint": "DammV1TokenA111",
|
||||
"tokenBMint": "So11111111111111111111111111111111111111112",
|
||||
"tokenBMint": crate::WSOL_MINT_ID,
|
||||
"config": "DammV1Config111",
|
||||
"creator": "DammV1Creator111"
|
||||
}
|
||||
@@ -538,8 +533,8 @@ mod tests {
|
||||
return dto;
|
||||
}
|
||||
|
||||
fn make_swap_transaction() -> crate::KbChainTransactionDto {
|
||||
let mut dto = crate::KbChainTransactionDto::new(
|
||||
fn make_swap_transaction() -> crate::ChainTransactionDto {
|
||||
let mut dto = crate::ChainTransactionDto::new(
|
||||
"sig-meteora-damm-v1-swap-1".to_string(),
|
||||
Some(890002),
|
||||
Some(1779500002),
|
||||
@@ -566,21 +561,17 @@ mod tests {
|
||||
return dto;
|
||||
}
|
||||
|
||||
fn make_swap_instruction() -> crate::KbChainInstructionDto {
|
||||
let mut dto = crate::KbChainInstructionDto::new(
|
||||
fn make_swap_instruction() -> crate::ChainInstructionDto {
|
||||
let mut dto = crate::ChainInstructionDto::new(
|
||||
503,
|
||||
None,
|
||||
0,
|
||||
None,
|
||||
Some(crate::KB_METEORA_DAMM_V1_PROGRAM_ID.to_string()),
|
||||
Some(crate::METEORA_DAMM_V1_PROGRAM_ID.to_string()),
|
||||
Some("meteora-damm-v1".to_string()),
|
||||
Some(1),
|
||||
serde_json::json!([
|
||||
"DammV1SwapPool111",
|
||||
"DammV1SwapTokenA111",
|
||||
"So11111111111111111111111111111111111111112"
|
||||
])
|
||||
.to_string(),
|
||||
serde_json::json!(["DammV1SwapPool111", "DammV1SwapTokenA111", crate::WSOL_MINT_ID])
|
||||
.to_string(),
|
||||
None,
|
||||
None,
|
||||
Some(
|
||||
@@ -589,7 +580,7 @@ mod tests {
|
||||
"instruction": "swap",
|
||||
"pool": "DammV1SwapPool111",
|
||||
"tokenAMint": "DammV1SwapTokenA111",
|
||||
"tokenBMint": "So11111111111111111111111111111111111111112"
|
||||
"tokenBMint": crate::WSOL_MINT_ID
|
||||
}
|
||||
})
|
||||
.to_string(),
|
||||
@@ -601,7 +592,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn meteora_damm_v1_create_pool_is_detected() {
|
||||
let decoder = crate::KbMeteoraDammV1Decoder::new();
|
||||
let decoder = crate::MeteoraDammV1Decoder::new();
|
||||
let transaction = make_create_transaction();
|
||||
let instructions = vec![make_create_instruction()];
|
||||
let decoded_result = decoder.decode_transaction(&transaction, &instructions);
|
||||
@@ -611,18 +602,15 @@ mod tests {
|
||||
};
|
||||
assert_eq!(decoded.len(), 1);
|
||||
match &decoded[0] {
|
||||
crate::KbMeteoraDammV1DecodedEvent::CreatePool(event) => {
|
||||
crate::MeteoraDammV1DecodedEvent::CreatePool(event) => {
|
||||
assert_eq!(event.transaction_id, 501);
|
||||
assert_eq!(event.instruction_id, 502);
|
||||
assert_eq!(event.pool_account, Some("DammV1Pool111".to_string()));
|
||||
assert_eq!(event.token_a_mint, Some("DammV1TokenA111".to_string()));
|
||||
assert_eq!(
|
||||
event.token_b_mint,
|
||||
Some("So11111111111111111111111111111111111111112".to_string())
|
||||
);
|
||||
assert_eq!(event.token_b_mint, Some(crate::WSOL_MINT_ID.to_string()));
|
||||
assert!(event.used_config);
|
||||
},
|
||||
crate::KbMeteoraDammV1DecodedEvent::Swap(_) => {
|
||||
crate::MeteoraDammV1DecodedEvent::Swap(_) => {
|
||||
panic!("unexpected swap event")
|
||||
},
|
||||
}
|
||||
@@ -630,7 +618,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn meteora_damm_v1_swap_is_detected() {
|
||||
let decoder = crate::KbMeteoraDammV1Decoder::new();
|
||||
let decoder = crate::MeteoraDammV1Decoder::new();
|
||||
let transaction = make_swap_transaction();
|
||||
let instructions = vec![make_swap_instruction()];
|
||||
let decoded_result = decoder.decode_transaction(&transaction, &instructions);
|
||||
@@ -640,17 +628,14 @@ mod tests {
|
||||
};
|
||||
assert_eq!(decoded.len(), 1);
|
||||
match &decoded[0] {
|
||||
crate::KbMeteoraDammV1DecodedEvent::Swap(event) => {
|
||||
crate::MeteoraDammV1DecodedEvent::Swap(event) => {
|
||||
assert_eq!(event.transaction_id, 503);
|
||||
assert_eq!(event.instruction_id, 504);
|
||||
assert_eq!(event.pool_account, Some("DammV1SwapPool111".to_string()));
|
||||
assert_eq!(event.token_a_mint, Some("DammV1SwapTokenA111".to_string()));
|
||||
assert_eq!(
|
||||
event.token_b_mint,
|
||||
Some("So11111111111111111111111111111111111111112".to_string())
|
||||
);
|
||||
assert_eq!(event.token_b_mint, Some(crate::WSOL_MINT_ID.to_string()));
|
||||
},
|
||||
crate::KbMeteoraDammV1DecodedEvent::CreatePool(_) => {
|
||||
crate::MeteoraDammV1DecodedEvent::CreatePool(_) => {
|
||||
panic!("unexpected create event")
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user