0.7.25
This commit is contained in:
@@ -76,7 +76,7 @@ enum KbDexlabInstructionKind {
|
||||
impl KbDexlabDecoder {
|
||||
/// Creates a new decoder.
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
return Self;
|
||||
}
|
||||
|
||||
/// Decodes one projected transaction into zero or more DexLab events.
|
||||
@@ -93,7 +93,7 @@ impl KbDexlabDecoder {
|
||||
"chain transaction '{}' has no internal id",
|
||||
transaction.signature
|
||||
)));
|
||||
}
|
||||
},
|
||||
};
|
||||
let transaction_json_result =
|
||||
serde_json::from_str::<serde_json::Value>(transaction.transaction_json.as_str());
|
||||
@@ -104,7 +104,7 @@ impl KbDexlabDecoder {
|
||||
"cannot parse transaction_json for signature '{}': {}",
|
||||
transaction.signature, error
|
||||
)));
|
||||
}
|
||||
},
|
||||
};
|
||||
let log_messages = kb_extract_log_messages(&transaction_json);
|
||||
let mut decoded_events = std::vec::Vec::new();
|
||||
@@ -140,45 +140,24 @@ impl KbDexlabDecoder {
|
||||
kb_classify_instruction_kind(parsed_json.as_ref(), &log_messages);
|
||||
let pool_account = kb_extract_string_by_candidate_keys(
|
||||
parsed_json.as_ref(),
|
||||
&[
|
||||
"pool",
|
||||
"poolAddress",
|
||||
"poolAccount",
|
||||
"amm",
|
||||
"ammPool",
|
||||
"poolState",
|
||||
],
|
||||
&["pool", "poolAddress", "poolAccount", "amm", "ammPool", "poolState"],
|
||||
)
|
||||
.or_else(|| kb_extract_account(&accounts, 0));
|
||||
.or_else(|| return kb_extract_account(&accounts, 0));
|
||||
let token_a_mint = kb_extract_string_by_candidate_keys(
|
||||
parsed_json.as_ref(),
|
||||
&[
|
||||
"tokenA",
|
||||
"tokenAMint",
|
||||
"mintA",
|
||||
"baseMint",
|
||||
"token0Mint",
|
||||
"mint0",
|
||||
],
|
||||
&["tokenA", "tokenAMint", "mintA", "baseMint", "token0Mint", "mint0"],
|
||||
)
|
||||
.or_else(|| kb_extract_account(&accounts, 1));
|
||||
.or_else(|| return kb_extract_account(&accounts, 1));
|
||||
let token_b_mint = kb_extract_string_by_candidate_keys(
|
||||
parsed_json.as_ref(),
|
||||
&[
|
||||
"tokenB",
|
||||
"tokenBMint",
|
||||
"mintB",
|
||||
"quoteMint",
|
||||
"token1Mint",
|
||||
"mint1",
|
||||
],
|
||||
&["tokenB", "tokenBMint", "mintB", "quoteMint", "token1Mint", "mint1"],
|
||||
)
|
||||
.or_else(|| kb_extract_account(&accounts, 2));
|
||||
.or_else(|| return kb_extract_account(&accounts, 2));
|
||||
let creator = kb_extract_string_by_candidate_keys(
|
||||
parsed_json.as_ref(),
|
||||
&["payer", "creator", "user", "owner"],
|
||||
)
|
||||
.or_else(|| kb_extract_account(&accounts, 3));
|
||||
.or_else(|| return kb_extract_account(&accounts, 3));
|
||||
let fee_tier = kb_extract_string_by_candidate_keys(
|
||||
parsed_json.as_ref(),
|
||||
&["feeTier", "fee_tier", "tradeFeeTier", "feeRate"],
|
||||
@@ -246,7 +225,7 @@ impl KbDexlabDecoder {
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(decoded_events)
|
||||
return Ok(decoded_events);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +257,7 @@ fn kb_classify_instruction_kind(
|
||||
if kb_log_messages_contain_keyword(log_messages, "swap") {
|
||||
return KbDexlabInstructionKind::Swap;
|
||||
}
|
||||
KbDexlabInstructionKind::Unknown
|
||||
return KbDexlabInstructionKind::Unknown;
|
||||
}
|
||||
|
||||
fn kb_extract_log_messages(
|
||||
@@ -305,7 +284,7 @@ fn kb_extract_log_messages(
|
||||
messages.push(text.to_string());
|
||||
}
|
||||
}
|
||||
messages
|
||||
return messages;
|
||||
}
|
||||
|
||||
fn kb_log_messages_contain_keyword(log_messages: &[std::string::String], keyword: &str) -> bool {
|
||||
@@ -316,7 +295,7 @@ fn kb_log_messages_contain_keyword(log_messages: &[std::string::String], keyword
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
return false;
|
||||
}
|
||||
|
||||
fn kb_normalize_text(value: &str) -> std::string::String {
|
||||
@@ -326,7 +305,7 @@ fn kb_normalize_text(value: &str) -> std::string::String {
|
||||
normalized.push(character.to_ascii_lowercase());
|
||||
}
|
||||
}
|
||||
normalized
|
||||
return normalized;
|
||||
}
|
||||
|
||||
fn kb_parse_accounts_json(
|
||||
@@ -340,7 +319,7 @@ fn kb_parse_accounts_json(
|
||||
"cannot parse instruction accounts_json '{}': {}",
|
||||
accounts_json, error
|
||||
)));
|
||||
}
|
||||
},
|
||||
};
|
||||
let mut accounts = std::vec::Vec::new();
|
||||
for value in values {
|
||||
@@ -349,7 +328,7 @@ fn kb_parse_accounts_json(
|
||||
accounts.push(text.to_string());
|
||||
}
|
||||
}
|
||||
Ok(accounts)
|
||||
return Ok(accounts);
|
||||
}
|
||||
|
||||
fn kb_parse_optional_parsed_json(
|
||||
@@ -361,11 +340,13 @@ fn kb_parse_optional_parsed_json(
|
||||
};
|
||||
let value_result = serde_json::from_str::<serde_json::Value>(parsed_json.as_str());
|
||||
match value_result {
|
||||
Ok(value) => Ok(Some(value)),
|
||||
Err(error) => Err(crate::KbError::Json(format!(
|
||||
"cannot parse instruction parsed_json '{}': {}",
|
||||
parsed_json, error
|
||||
))),
|
||||
Ok(value) => return Ok(Some(value)),
|
||||
Err(error) => {
|
||||
return Err(crate::KbError::Json(format!(
|
||||
"cannot parse instruction parsed_json '{}': {}",
|
||||
parsed_json, error
|
||||
)));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,7 +358,7 @@ fn kb_extract_string_by_candidate_keys(
|
||||
Some(value) => value,
|
||||
None => return None,
|
||||
};
|
||||
kb_extract_string_by_candidate_keys_inner(value, candidate_keys)
|
||||
return kb_extract_string_by_candidate_keys_inner(value, candidate_keys);
|
||||
}
|
||||
|
||||
fn kb_extract_string_by_candidate_keys_inner(
|
||||
@@ -412,7 +393,7 @@ fn kb_extract_string_by_candidate_keys_inner(
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
return None;
|
||||
}
|
||||
|
||||
fn kb_extract_account(
|
||||
@@ -422,7 +403,7 @@ fn kb_extract_account(
|
||||
if index >= accounts.len() {
|
||||
return None;
|
||||
}
|
||||
Some(accounts[index].clone())
|
||||
return Some(accounts[index].clone());
|
||||
}
|
||||
|
||||
fn kb_infer_trade_side(log_messages: &[std::string::String]) -> crate::KbSwapTradeSide {
|
||||
@@ -432,7 +413,7 @@ fn kb_infer_trade_side(log_messages: &[std::string::String]) -> crate::KbSwapTra
|
||||
if kb_log_messages_contain_keyword(log_messages, "sell") {
|
||||
return crate::KbSwapTradeSide::SellBase;
|
||||
}
|
||||
crate::KbSwapTradeSide::Unknown
|
||||
return crate::KbSwapTradeSide::Unknown;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -462,7 +443,7 @@ mod tests {
|
||||
.to_string(),
|
||||
);
|
||||
dto.id = Some(801);
|
||||
dto
|
||||
return dto;
|
||||
}
|
||||
|
||||
fn make_create_instruction() -> crate::KbChainInstructionDto {
|
||||
@@ -498,7 +479,7 @@ mod tests {
|
||||
),
|
||||
);
|
||||
dto.id = Some(802);
|
||||
dto
|
||||
return dto;
|
||||
}
|
||||
|
||||
fn make_swap_transaction() -> crate::KbChainTransactionDto {
|
||||
@@ -526,7 +507,7 @@ mod tests {
|
||||
.to_string(),
|
||||
);
|
||||
dto.id = Some(803);
|
||||
dto
|
||||
return dto;
|
||||
}
|
||||
|
||||
fn make_swap_instruction() -> crate::KbChainInstructionDto {
|
||||
@@ -559,7 +540,7 @@ mod tests {
|
||||
),
|
||||
);
|
||||
dto.id = Some(804);
|
||||
dto
|
||||
return dto;
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -584,10 +565,10 @@ mod tests {
|
||||
Some("So11111111111111111111111111111111111111112".to_string())
|
||||
);
|
||||
assert_eq!(event.fee_tier, Some("0.3%".to_string()));
|
||||
}
|
||||
},
|
||||
crate::KbDexlabDecodedEvent::Swap(_) => {
|
||||
panic!("unexpected swap event")
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -612,10 +593,10 @@ mod tests {
|
||||
event.token_b_mint,
|
||||
Some("So11111111111111111111111111111111111111112".to_string())
|
||||
);
|
||||
}
|
||||
},
|
||||
crate::KbDexlabDecodedEvent::CreatePool(_) => {
|
||||
panic!("unexpected create event")
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user