v0.1.0-pre.011
This commit is contained in:
@@ -7,12 +7,12 @@ use base64::Engine; // rust-rules: trait-import
|
||||
use sha2::Digest; // rust-rules: trait-import
|
||||
|
||||
/// Current canonical transaction document version.
|
||||
pub const CANONICAL_TRANSACTION_FORMAT_VERSION: u32 = 1;
|
||||
pub const MD_CANONICAL_TRANSACTION_FORMAT_VERSION: u32 = 1;
|
||||
|
||||
/// Source-independent canonical Solana transaction.
|
||||
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CanonicalTransaction {
|
||||
pub struct MdCanonicalTransaction {
|
||||
/// Canonical contract version included in the hashed document.
|
||||
pub format_version: u32,
|
||||
/// Primary transaction signature as base58 text.
|
||||
@@ -22,19 +22,19 @@ pub struct CanonicalTransaction {
|
||||
/// Optional block timestamp as Unix seconds.
|
||||
pub block_time: std::option::Option<i64>,
|
||||
/// Transaction message version.
|
||||
pub version: CanonicalTransactionVersion,
|
||||
pub version: MdCanonicalTransactionVersion,
|
||||
/// All transaction signatures in message order.
|
||||
pub signatures: std::vec::Vec<std::string::String>,
|
||||
/// Canonical transaction message.
|
||||
pub message: CanonicalTransactionMessage,
|
||||
pub message: MdCanonicalTransactionMessage,
|
||||
/// Optional execution metadata.
|
||||
pub metadata: std::option::Option<CanonicalTransactionMetadata>,
|
||||
pub metadata: std::option::Option<MdCanonicalTransactionMetadata>,
|
||||
}
|
||||
|
||||
impl CanonicalTransaction {
|
||||
impl MdCanonicalTransaction {
|
||||
/// Validates the canonical transaction invariants.
|
||||
pub fn validate(&self) -> kb_core::Result<()> {
|
||||
if self.format_version != crate::CANONICAL_TRANSACTION_FORMAT_VERSION {
|
||||
if self.format_version != crate::MD_CANONICAL_TRANSACTION_FORMAT_VERSION {
|
||||
return std::result::Result::Err(kb_core::Error::invalid_state(format!(
|
||||
"unsupported canonical transaction format version: {}",
|
||||
self.format_version
|
||||
@@ -73,7 +73,7 @@ impl CanonicalTransaction {
|
||||
if let std::result::Result::Err(error) = message_result {
|
||||
return std::result::Result::Err(error);
|
||||
}
|
||||
if self.version == CanonicalTransactionVersion::Legacy
|
||||
if self.version == MdCanonicalTransactionVersion::Legacy
|
||||
&& (!self.message.address_table_lookups.is_empty()
|
||||
|| !self.message.loaded_addresses.writable.is_empty()
|
||||
|| !self.message.loaded_addresses.readonly.is_empty())
|
||||
@@ -146,7 +146,7 @@ impl CanonicalTransaction {
|
||||
/// Canonical Solana transaction version.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(tag = "kind", content = "number", rename_all = "snake_case")]
|
||||
pub enum CanonicalTransactionVersion {
|
||||
pub enum MdCanonicalTransactionVersion {
|
||||
/// Legacy transaction message.
|
||||
Legacy,
|
||||
/// Numbered versioned transaction message.
|
||||
@@ -156,7 +156,7 @@ pub enum CanonicalTransactionVersion {
|
||||
/// Canonical Solana message header.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CanonicalMessageHeader {
|
||||
pub struct MdCanonicalMessageHeader {
|
||||
/// Number of required transaction signatures.
|
||||
pub num_required_signatures: u8,
|
||||
/// Number of readonly signed accounts.
|
||||
@@ -168,22 +168,22 @@ pub struct CanonicalMessageHeader {
|
||||
/// Canonical Solana transaction message.
|
||||
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CanonicalTransactionMessage {
|
||||
pub struct MdCanonicalTransactionMessage {
|
||||
/// Message header.
|
||||
pub header: CanonicalMessageHeader,
|
||||
pub header: MdCanonicalMessageHeader,
|
||||
/// Static account keys in message order.
|
||||
pub static_account_keys: std::vec::Vec<std::string::String>,
|
||||
/// Recent blockhash as base58 text.
|
||||
pub recent_blockhash: std::string::String,
|
||||
/// Top-level compiled instructions.
|
||||
pub instructions: std::vec::Vec<CanonicalCompiledInstruction>,
|
||||
pub instructions: std::vec::Vec<MdCanonicalCompiledInstruction>,
|
||||
/// Address lookup table references for versioned messages.
|
||||
pub address_table_lookups: std::vec::Vec<CanonicalAddressTableLookup>,
|
||||
pub address_table_lookups: std::vec::Vec<MdCanonicalAddressTableLookup>,
|
||||
/// Loaded writable and readonly addresses resolved by the runtime.
|
||||
pub loaded_addresses: CanonicalLoadedAddresses,
|
||||
pub loaded_addresses: MdCanonicalLoadedAddresses,
|
||||
}
|
||||
|
||||
impl CanonicalTransactionMessage {
|
||||
impl MdCanonicalTransactionMessage {
|
||||
/// Returns the resolved account count including loaded addresses.
|
||||
pub fn resolved_account_count(&self) -> usize {
|
||||
return self.static_account_keys.len()
|
||||
@@ -262,7 +262,7 @@ impl CanonicalTransactionMessage {
|
||||
/// Canonical compiled Solana instruction.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CanonicalCompiledInstruction {
|
||||
pub struct MdCanonicalCompiledInstruction {
|
||||
/// Resolved account index of the invoked program.
|
||||
pub program_id_index: u16,
|
||||
/// Resolved account indexes consumed by the instruction.
|
||||
@@ -273,7 +273,7 @@ pub struct CanonicalCompiledInstruction {
|
||||
pub stack_height: std::option::Option<u32>,
|
||||
}
|
||||
|
||||
impl CanonicalCompiledInstruction {
|
||||
impl MdCanonicalCompiledInstruction {
|
||||
fn validate(&self, resolved_account_count: usize) -> kb_core::Result<()> {
|
||||
if usize::from(self.program_id_index) >= resolved_account_count {
|
||||
return std::result::Result::Err(kb_core::Error::invalid_state(
|
||||
@@ -301,7 +301,7 @@ impl CanonicalCompiledInstruction {
|
||||
/// Canonical address lookup table reference.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CanonicalAddressTableLookup {
|
||||
pub struct MdCanonicalAddressTableLookup {
|
||||
/// Lookup table account key as base58 text.
|
||||
pub account_key: std::string::String,
|
||||
/// Writable lookup indexes.
|
||||
@@ -313,7 +313,7 @@ pub struct CanonicalAddressTableLookup {
|
||||
/// Runtime-loaded addresses for a versioned transaction.
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CanonicalLoadedAddresses {
|
||||
pub struct MdCanonicalLoadedAddresses {
|
||||
/// Writable loaded addresses in runtime order.
|
||||
pub writable: std::vec::Vec<std::string::String>,
|
||||
/// Readonly loaded addresses in runtime order.
|
||||
@@ -323,7 +323,7 @@ pub struct CanonicalLoadedAddresses {
|
||||
/// Canonical transaction execution status.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum CanonicalTransactionStatus {
|
||||
pub enum MdCanonicalTransactionStatus {
|
||||
/// Transaction execution succeeded.
|
||||
Success,
|
||||
/// Transaction execution failed.
|
||||
@@ -333,9 +333,9 @@ pub enum CanonicalTransactionStatus {
|
||||
/// Canonical transaction execution metadata.
|
||||
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CanonicalTransactionMetadata {
|
||||
pub struct MdCanonicalTransactionMetadata {
|
||||
/// Canonical execution status.
|
||||
pub status: CanonicalTransactionStatus,
|
||||
pub status: MdCanonicalTransactionStatus,
|
||||
/// Optional source-independent transaction error document.
|
||||
pub error: std::option::Option<serde_json::Value>,
|
||||
/// Transaction fee in lamports.
|
||||
@@ -345,24 +345,24 @@ pub struct CanonicalTransactionMetadata {
|
||||
/// Account balances after execution in lamports.
|
||||
pub post_balances: std::vec::Vec<u64>,
|
||||
/// Inner instruction groups indexed by parent top-level instruction.
|
||||
pub inner_instructions: std::vec::Vec<CanonicalInnerInstructionGroup>,
|
||||
pub inner_instructions: std::vec::Vec<MdCanonicalInnerInstructionGroup>,
|
||||
/// Runtime log messages in execution order.
|
||||
pub log_messages: std::vec::Vec<std::string::String>,
|
||||
/// Token balances before execution.
|
||||
pub pre_token_balances: std::vec::Vec<CanonicalTokenBalance>,
|
||||
pub pre_token_balances: std::vec::Vec<MdCanonicalTokenBalance>,
|
||||
/// Token balances after execution.
|
||||
pub post_token_balances: std::vec::Vec<CanonicalTokenBalance>,
|
||||
pub post_token_balances: std::vec::Vec<MdCanonicalTokenBalance>,
|
||||
/// Transaction rewards.
|
||||
pub rewards: std::vec::Vec<CanonicalReward>,
|
||||
pub rewards: std::vec::Vec<MdCanonicalReward>,
|
||||
/// Optional transaction return data.
|
||||
pub return_data: std::option::Option<CanonicalReturnData>,
|
||||
pub return_data: std::option::Option<MdCanonicalReturnData>,
|
||||
/// Optional consumed compute units.
|
||||
pub compute_units_consumed: std::option::Option<u64>,
|
||||
/// Optional runtime cost units.
|
||||
pub cost_units: std::option::Option<u64>,
|
||||
}
|
||||
|
||||
impl CanonicalTransactionMetadata {
|
||||
impl MdCanonicalTransactionMetadata {
|
||||
fn validate(
|
||||
&self,
|
||||
resolved_account_count: usize,
|
||||
@@ -379,14 +379,14 @@ impl CanonicalTransactionMetadata {
|
||||
));
|
||||
}
|
||||
match self.status {
|
||||
CanonicalTransactionStatus::Success => {
|
||||
MdCanonicalTransactionStatus::Success => {
|
||||
if self.error.is_some() {
|
||||
return std::result::Result::Err(kb_core::Error::invalid_state(
|
||||
"successful canonical transaction must not contain an error",
|
||||
));
|
||||
}
|
||||
},
|
||||
CanonicalTransactionStatus::Failed => {
|
||||
MdCanonicalTransactionStatus::Failed => {
|
||||
if self.error.is_none() {
|
||||
return std::result::Result::Err(kb_core::Error::invalid_state(
|
||||
"failed canonical transaction must contain an error",
|
||||
@@ -453,17 +453,17 @@ impl CanonicalTransactionMetadata {
|
||||
/// Group of inner instructions attached to one top-level instruction.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CanonicalInnerInstructionGroup {
|
||||
pub struct MdCanonicalInnerInstructionGroup {
|
||||
/// Parent top-level instruction index.
|
||||
pub parent_instruction_index: u16,
|
||||
/// Inner instructions in runtime order.
|
||||
pub instructions: std::vec::Vec<CanonicalCompiledInstruction>,
|
||||
pub instructions: std::vec::Vec<MdCanonicalCompiledInstruction>,
|
||||
}
|
||||
|
||||
/// Exact SPL token balance representation.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CanonicalTokenBalance {
|
||||
pub struct MdCanonicalTokenBalance {
|
||||
/// Resolved account index.
|
||||
pub account_index: u16,
|
||||
/// Token mint public key.
|
||||
@@ -480,7 +480,7 @@ pub struct CanonicalTokenBalance {
|
||||
pub decimal_amount: std::string::String,
|
||||
}
|
||||
|
||||
impl CanonicalTokenBalance {
|
||||
impl MdCanonicalTokenBalance {
|
||||
/// Creates an exact canonical token balance without provider-specific UI formatting.
|
||||
pub fn new(
|
||||
account_index: u16,
|
||||
@@ -552,7 +552,7 @@ impl CanonicalTokenBalance {
|
||||
/// Canonical transaction reward.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CanonicalReward {
|
||||
pub struct MdCanonicalReward {
|
||||
/// Reward account public key.
|
||||
pub pubkey: std::string::String,
|
||||
/// Signed lamport delta.
|
||||
@@ -568,7 +568,7 @@ pub struct CanonicalReward {
|
||||
/// Canonical transaction return data.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CanonicalReturnData {
|
||||
pub struct MdCanonicalReturnData {
|
||||
/// Program that returned the data.
|
||||
pub program_id: std::string::String,
|
||||
/// Return bytes encoded as standard base64.
|
||||
@@ -671,18 +671,18 @@ fn validate_base58_length(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
fn sample_transaction() -> crate::CanonicalTransaction {
|
||||
return crate::CanonicalTransaction {
|
||||
format_version: crate::CANONICAL_TRANSACTION_FORMAT_VERSION,
|
||||
fn sample_transaction() -> crate::MdCanonicalTransaction {
|
||||
return crate::MdCanonicalTransaction {
|
||||
format_version: crate::MD_CANONICAL_TRANSACTION_FORMAT_VERSION,
|
||||
primary_signature: "2Ana1pUpv2ZbMVkwF5FXapYeBEjdxDatLn7nvJkhgTSXbs59SyZSx866bXirPgj8QQVB57uxHJBG1YFvkRbFj4T".to_string(),
|
||||
slot: 42,
|
||||
block_time: std::option::Option::Some(1_700_000_000),
|
||||
version: crate::CanonicalTransactionVersion::Legacy,
|
||||
version: crate::MdCanonicalTransactionVersion::Legacy,
|
||||
signatures: std::vec![
|
||||
"2Ana1pUpv2ZbMVkwF5FXapYeBEjdxDatLn7nvJkhgTSXbs59SyZSx866bXirPgj8QQVB57uxHJBG1YFvkRbFj4T".to_string(),
|
||||
],
|
||||
message: crate::CanonicalTransactionMessage {
|
||||
header: crate::CanonicalMessageHeader {
|
||||
message: crate::MdCanonicalTransactionMessage {
|
||||
header: crate::MdCanonicalMessageHeader {
|
||||
num_required_signatures: 1,
|
||||
num_readonly_signed_accounts: 0,
|
||||
num_readonly_unsigned_accounts: 1,
|
||||
@@ -692,17 +692,17 @@ mod tests {
|
||||
"SysvarC1ock11111111111111111111111111111111".to_string(),
|
||||
],
|
||||
recent_blockhash: "11111111111111111111111111111111".to_string(),
|
||||
instructions: std::vec![crate::CanonicalCompiledInstruction {
|
||||
instructions: std::vec![crate::MdCanonicalCompiledInstruction {
|
||||
program_id_index: 0,
|
||||
account_indexes: std::vec![1],
|
||||
data_base64: "AQ==".to_string(),
|
||||
stack_height: std::option::Option::Some(1),
|
||||
}],
|
||||
address_table_lookups: std::vec::Vec::new(),
|
||||
loaded_addresses: crate::CanonicalLoadedAddresses::default(),
|
||||
loaded_addresses: crate::MdCanonicalLoadedAddresses::default(),
|
||||
},
|
||||
metadata: std::option::Option::Some(crate::CanonicalTransactionMetadata {
|
||||
status: crate::CanonicalTransactionStatus::Success,
|
||||
metadata: std::option::Option::Some(crate::MdCanonicalTransactionMetadata {
|
||||
status: crate::MdCanonicalTransactionStatus::Success,
|
||||
error: std::option::Option::None,
|
||||
fee: 5000,
|
||||
pre_balances: std::vec![10_000, 1],
|
||||
@@ -740,14 +740,14 @@ mod tests {
|
||||
let mut first = sample_transaction();
|
||||
let mut second = sample_transaction();
|
||||
if let std::option::Option::Some(metadata) = &mut first.metadata {
|
||||
metadata.status = crate::CanonicalTransactionStatus::Failed;
|
||||
metadata.status = crate::MdCanonicalTransactionStatus::Failed;
|
||||
metadata.error = std::option::Option::Some(serde_json::json!({
|
||||
"z": 3,
|
||||
"nested": {"b": 2, "a": 1}
|
||||
}));
|
||||
}
|
||||
if let std::option::Option::Some(metadata) = &mut second.metadata {
|
||||
metadata.status = crate::CanonicalTransactionStatus::Failed;
|
||||
metadata.status = crate::MdCanonicalTransactionStatus::Failed;
|
||||
let parse_result =
|
||||
serde_json::from_str::<serde_json::Value>(r#"{"nested":{"a":1,"b":2},"z":3}"#);
|
||||
metadata.error = match parse_result {
|
||||
@@ -777,7 +777,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn token_decimal_amount_is_derived_without_source_ui_formatting() {
|
||||
let result = crate::CanonicalTokenBalance::new(
|
||||
let result = crate::MdCanonicalTokenBalance::new(
|
||||
0,
|
||||
"So11111111111111111111111111111111111111112",
|
||||
std::option::Option::None,
|
||||
@@ -811,7 +811,7 @@ mod tests {
|
||||
fn validation_rejects_inconsistent_status_and_error() {
|
||||
let mut transaction = sample_transaction();
|
||||
if let std::option::Option::Some(metadata) = &mut transaction.metadata {
|
||||
metadata.status = crate::CanonicalTransactionStatus::Failed;
|
||||
metadata.status = crate::MdCanonicalTransactionStatus::Failed;
|
||||
}
|
||||
let result = transaction.validate();
|
||||
assert!(result.is_err());
|
||||
|
||||
@@ -11,7 +11,7 @@ use ts_rs::TS; // rust-rules: derive-import
|
||||
export,
|
||||
export_to = "../frontend/ts/bindings/kb_model/decoded/EventSourceKind.ts"
|
||||
)]
|
||||
pub enum EventSourceKind {
|
||||
pub enum MdEventSourceKind {
|
||||
/// Top-level instruction.
|
||||
Instruction,
|
||||
/// Inner instruction.
|
||||
@@ -38,7 +38,7 @@ pub enum EventSourceKind {
|
||||
export,
|
||||
export_to = "../frontend/ts/bindings/kb_model/decoded/DecoderConfidence.ts"
|
||||
)]
|
||||
pub enum DecoderConfidence {
|
||||
pub enum MdDecoderConfidence {
|
||||
/// Exact manual decode.
|
||||
Exact,
|
||||
/// Exact IDL-based decode.
|
||||
@@ -61,27 +61,27 @@ pub enum DecoderConfidence {
|
||||
export,
|
||||
export_to = "../frontend/ts/bindings/kb_model/decoded/DecodedProtocolEvent.ts"
|
||||
)]
|
||||
pub struct DecodedProtocolEvent {
|
||||
pub struct MdDecodedProtocolEvent {
|
||||
/// Transaction signature.
|
||||
pub signature: crate::Signature,
|
||||
pub signature: crate::MdSignature,
|
||||
/// Transaction slot.
|
||||
pub slot: crate::Slot,
|
||||
pub slot: crate::MdSlot,
|
||||
/// Instruction path.
|
||||
pub instruction_path: crate::InstructionPath,
|
||||
pub instruction_path: crate::MdInstructionPath,
|
||||
/// Program id.
|
||||
pub program_id: crate::ProgramId,
|
||||
pub program_id: crate::MdProgramId,
|
||||
/// Protocol family.
|
||||
pub protocol_code: crate::ProtocolCode,
|
||||
pub protocol_code: crate::MdProtocolCode,
|
||||
/// Protocol surface.
|
||||
pub surface_code: crate::SurfaceCode,
|
||||
pub surface_code: crate::MdSurfaceCode,
|
||||
/// Canonical event code.
|
||||
pub event_code: crate::EventCode,
|
||||
pub event_code: crate::MdEventCode,
|
||||
/// Short event name.
|
||||
pub event_name: crate::EventName,
|
||||
pub event_name: crate::MdEventName,
|
||||
/// Event family.
|
||||
pub event_family: crate::EventFamily,
|
||||
pub event_family: crate::MdEventFamily,
|
||||
/// Event source kind.
|
||||
pub source_kind: crate::EventSourceKind,
|
||||
pub source_kind: crate::MdEventSourceKind,
|
||||
/// Decoder confidence.
|
||||
pub confidence: crate::DecoderConfidence,
|
||||
pub confidence: crate::MdDecoderConfidence,
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use ts_rs::TS; // rust-rules: derive-import
|
||||
export,
|
||||
export_to = "../frontend/ts/bindings/kb_model/materialized/MaterializedEventFamily.ts"
|
||||
)]
|
||||
pub enum MaterializedEventFamily {
|
||||
pub enum MdMaterializedEventFamily {
|
||||
/// Trade materialization.
|
||||
Trade,
|
||||
/// Liquidity materialization.
|
||||
@@ -68,13 +68,13 @@ pub enum MaterializedEventFamily {
|
||||
export,
|
||||
export_to = "../frontend/ts/bindings/kb_model/materialized/MaterializedEvent.ts"
|
||||
)]
|
||||
pub struct MaterializedEvent {
|
||||
pub struct MdMaterializedEvent {
|
||||
/// Source transaction signature.
|
||||
pub signature: crate::Signature,
|
||||
pub signature: crate::MdSignature,
|
||||
/// Source transaction slot.
|
||||
pub slot: crate::Slot,
|
||||
pub slot: crate::MdSlot,
|
||||
/// Source decoded family.
|
||||
pub decoded_family: crate::EventFamily,
|
||||
pub decoded_family: crate::MdEventFamily,
|
||||
/// Materialized family.
|
||||
pub materialized_family: crate::MaterializedEventFamily,
|
||||
pub materialized_family: crate::MdMaterializedEventFamily,
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use ts_rs::TS; // rust-rules: derive-import
|
||||
export,
|
||||
export_to = "../frontend/ts/bindings/kb_model/nomenclature/ProgramCode.ts"
|
||||
)]
|
||||
pub struct ProgramCode(pub std::string::String);
|
||||
pub struct MdProgramCode(pub std::string::String);
|
||||
|
||||
/// Protocol family code, for example `raydium` or `meteora`.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, serde::Deserialize, serde::Serialize, TS)]
|
||||
@@ -19,7 +19,7 @@ pub struct ProgramCode(pub std::string::String);
|
||||
export,
|
||||
export_to = "../frontend/ts/bindings/kb_model/nomenclature/ProtocolCode.ts"
|
||||
)]
|
||||
pub struct ProtocolCode(pub std::string::String);
|
||||
pub struct MdProtocolCode(pub std::string::String);
|
||||
|
||||
/// Concrete protocol surface code, for example `raydium_amm_v4`.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, serde::Deserialize, serde::Serialize, TS)]
|
||||
@@ -27,17 +27,17 @@ pub struct ProtocolCode(pub std::string::String);
|
||||
export,
|
||||
export_to = "../frontend/ts/bindings/kb_model/nomenclature/SurfaceCode.ts"
|
||||
)]
|
||||
pub struct SurfaceCode(pub std::string::String);
|
||||
pub struct MdSurfaceCode(pub std::string::String);
|
||||
|
||||
/// Event name without surface prefix.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, serde::Deserialize, serde::Serialize, TS)]
|
||||
#[ts(export, export_to = "../frontend/ts/bindings/kb_model/nomenclature/EventName.ts")]
|
||||
pub struct EventName(pub std::string::String);
|
||||
pub struct MdEventName(pub std::string::String);
|
||||
|
||||
/// Canonical event code in `<surface_code>.<event_name>` format.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, serde::Deserialize, serde::Serialize, TS)]
|
||||
#[ts(export, export_to = "../frontend/ts/bindings/kb_model/nomenclature/EventCode.ts")]
|
||||
pub struct EventCode(pub std::string::String);
|
||||
pub struct MdEventCode(pub std::string::String);
|
||||
|
||||
/// High-level event family.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, serde::Deserialize, serde::Serialize, TS)]
|
||||
@@ -45,7 +45,7 @@ pub struct EventCode(pub std::string::String);
|
||||
export,
|
||||
export_to = "../frontend/ts/bindings/kb_model/nomenclature/EventFamily.ts"
|
||||
)]
|
||||
pub enum EventFamily {
|
||||
pub enum MdEventFamily {
|
||||
/// Swap or buy/sell event.
|
||||
Trade,
|
||||
/// Liquidity deposit/withdraw or equivalent.
|
||||
|
||||
@@ -11,15 +11,15 @@ use ts_rs::TS; // rust-rules: derive-import
|
||||
export,
|
||||
export_to = "../frontend/ts/bindings/kb_model/observation/ProgramObservation.ts"
|
||||
)]
|
||||
pub struct ProgramObservation {
|
||||
pub struct MdProgramObservation {
|
||||
/// Transaction signature.
|
||||
pub signature: crate::Signature,
|
||||
pub signature: crate::MdSignature,
|
||||
/// Transaction slot.
|
||||
pub slot: crate::Slot,
|
||||
pub slot: crate::MdSlot,
|
||||
/// Instruction path.
|
||||
pub instruction_path: crate::InstructionPath,
|
||||
pub instruction_path: crate::MdInstructionPath,
|
||||
/// Program id.
|
||||
pub program_id: crate::ProgramId,
|
||||
pub program_id: crate::MdProgramId,
|
||||
/// Optional 8-byte discriminator in hexadecimal.
|
||||
pub discriminator_8: std::option::Option<std::string::String>,
|
||||
/// Raw instruction data length.
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
//! Source-neutral instruction replay input shared by decoders and stores.
|
||||
|
||||
/// Version of the normalized core replay contract.
|
||||
pub const CORE_REPLAY_INPUT_CONTRACT_VERSION: u32 = 2;
|
||||
pub const MD_CORE_REPLAY_INPUT_CONTRACT_VERSION: u32 = 2;
|
||||
|
||||
/// Decoder replay input containing one instruction plus extracted transaction context.
|
||||
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
pub struct CoreInstructionReplayInput {
|
||||
pub struct MdCoreInstructionReplayInput {
|
||||
/// Version of the normalized core replay contract.
|
||||
pub core_contract_version: u32,
|
||||
/// Stable deduplication key for this replay input.
|
||||
@@ -45,7 +45,7 @@ pub struct CoreInstructionReplayInput {
|
||||
pub balance_changes_json: serde_json::Value,
|
||||
}
|
||||
|
||||
impl CoreInstructionReplayInput {
|
||||
impl MdCoreInstructionReplayInput {
|
||||
/// Builds a decoder replay input after validating its stable identity and array context.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
@@ -71,7 +71,7 @@ impl CoreInstructionReplayInput {
|
||||
));
|
||||
}
|
||||
let value = Self {
|
||||
core_contract_version: crate::CORE_REPLAY_INPUT_CONTRACT_VERSION,
|
||||
core_contract_version: crate::MD_CORE_REPLAY_INPUT_CONTRACT_VERSION,
|
||||
replay_input_key: replay_input_key.into(),
|
||||
signature: signature.into(),
|
||||
slot,
|
||||
@@ -98,7 +98,7 @@ impl CoreInstructionReplayInput {
|
||||
|
||||
/// Validates the stable replay identity and contract version.
|
||||
pub fn validate(&self) -> kb_core::Result<()> {
|
||||
if self.core_contract_version != crate::CORE_REPLAY_INPUT_CONTRACT_VERSION {
|
||||
if self.core_contract_version != crate::MD_CORE_REPLAY_INPUT_CONTRACT_VERSION {
|
||||
return std::result::Result::Err(kb_core::Error::invalid_state(
|
||||
"unsupported core replay input contract version",
|
||||
));
|
||||
|
||||
@@ -8,7 +8,7 @@ use ts_rs::TS; // rust-rules: derive-import
|
||||
/// Solana transaction signature.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, serde::Deserialize, serde::Serialize, TS)]
|
||||
#[ts(export, export_to = "../frontend/ts/bindings/kb_model/solana/Signature.ts")]
|
||||
pub struct Signature(pub std::string::String);
|
||||
pub struct MdSignature(pub std::string::String);
|
||||
|
||||
/// Solana slot.
|
||||
#[derive(
|
||||
@@ -25,19 +25,19 @@ pub struct Signature(pub std::string::String);
|
||||
TS,
|
||||
)]
|
||||
#[ts(export, export_to = "../frontend/ts/bindings/kb_model/solana/Slot.ts")]
|
||||
pub struct Slot(pub u64);
|
||||
pub struct MdSlot(pub u64);
|
||||
|
||||
/// Solana program id.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, serde::Deserialize, serde::Serialize, TS)]
|
||||
#[ts(export, export_to = "../frontend/ts/bindings/kb_model/solana/ProgramId.ts")]
|
||||
pub struct ProgramId(pub std::string::String);
|
||||
pub struct MdProgramId(pub std::string::String);
|
||||
|
||||
/// Solana public key.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, serde::Deserialize, serde::Serialize, TS)]
|
||||
#[ts(export, export_to = "../frontend/ts/bindings/kb_model/solana/Pubkey.ts")]
|
||||
pub struct Pubkey(pub std::string::String);
|
||||
pub struct MdPubkey(pub std::string::String);
|
||||
|
||||
/// Stable top-level or inner instruction path.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, serde::Deserialize, serde::Serialize, TS)]
|
||||
#[ts(export, export_to = "../frontend/ts/bindings/kb_model/solana/InstructionPath.ts")]
|
||||
pub struct InstructionPath(pub std::string::String);
|
||||
pub struct MdInstructionPath(pub std::string::String);
|
||||
|
||||
Reference in New Issue
Block a user