From b51fb3ba189d39b2cab2010272b715274a401cbd Mon Sep 17 00:00:00 2001 From: Ivan Frolov Date: Wed, 15 Jan 2025 00:27:13 -0500 Subject: [PATCH] feat: constructed persistent account keys from instruction --- omni-relayer/example-mainnet-config.toml | 18 ++++++------- omni-relayer/example-testnet-config.toml | 14 +++++----- omni-relayer/src/utils/solana.rs | 34 +++++++++++++++++++----- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/omni-relayer/example-mainnet-config.toml b/omni-relayer/example-mainnet-config.toml index 0563b050..d321cce5 100644 --- a/omni-relayer/example-mainnet-config.toml +++ b/omni-relayer/example-mainnet-config.toml @@ -38,20 +38,20 @@ expected_finalization_time = 1066 rpc_http_url = "https://api.mainnet-beta.solana.com" rpc_ws_url = "wss://api.mainnet-beta.solana.com" # Program ID on Solana is an account ID whitch the bridge contract (basically bridge_token_factory_address on Solana) -program_id = "" +program_id = "dahPEoZGXfyV58JqqH85okdHmpN8U2q8owgPUXSCPxe" # This is the wormhole contract ID on Solana (can be found here https://wormhole.com/docs/build/reference/contract-addresses/#__tabbed_1_2) -wormhole_id = "" +wormhole_id = "worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth" # There's a list of account keys and they are store in a strict order. We need indexes to get the right key -init_transfer_sender_index = 0 -init_transfer_token_index = 6 -init_transfer_emitter_index = 15 -init_transfer_sol_sender_index = 0 -init_transfer_sol_emitter_index = 11 +init_transfer_sender_index = 5 +init_transfer_token_index = 1 +init_transfer_emitter_index = 6 +init_transfer_sol_sender_index = 1 +init_transfer_sol_emitter_index = 3 # Discriminators are used to identify the type of the event (can be found during the building process of solana's contract) init_transfer_discriminator = [174, 50, 134, 99, 122, 243, 243, 224] init_transfer_sol_discriminator = [124, 167, 164, 191, 81, 140, 108, 30] -finalize_transfer_emitter_index = 9 -finalize_transfer_sol_emitter_index = 8 +finalize_transfer_emitter_index = 6 +finalize_transfer_sol_emitter_index = 5 finalize_transfer_discriminator = [124, 126, 103, 188, 144, 65, 135, 51] finalize_transfer_sol_discriminator = [104, 27, 121, 69, 3, 70, 217, 66] diff --git a/omni-relayer/example-testnet-config.toml b/omni-relayer/example-testnet-config.toml index 801f2b65..2bf74cb1 100644 --- a/omni-relayer/example-testnet-config.toml +++ b/omni-relayer/example-testnet-config.toml @@ -45,16 +45,16 @@ program_id = "Gy1XPwYZURfBzHiGAxnw3SYC33SfqsEpGSS5zeBge28p" # This is the wormhole contract ID on Solana (can be found here https://wormhole.com/docs/build/reference/contract-addresses/#__tabbed_1_2) wormhole_id = "3u8hJUVTA4jH1wYAyUur7FFZVQ8H635K3tSHHF4ssjQ5" # There's a list of account keys and they are store in a strict order. We need indexes to get the right key -init_transfer_sender_index = 0 -init_transfer_token_index = 6 -init_transfer_emitter_index = 15 -init_transfer_sol_sender_index = 0 -init_transfer_sol_emitter_index = 11 +init_transfer_sender_index = 5 +init_transfer_token_index = 1 +init_transfer_emitter_index = 6 +init_transfer_sol_sender_index = 1 +init_transfer_sol_emitter_index = 3 # Discriminators are used to identify the type of the event (can be found during the building process of solana's contract) init_transfer_discriminator = [174, 50, 134, 99, 122, 243, 243, 224] init_transfer_sol_discriminator = [124, 167, 164, 191, 81, 140, 108, 30] -finalize_transfer_emitter_index = 9 -finalize_transfer_sol_emitter_index = 8 +finalize_transfer_emitter_index = 6 +finalize_transfer_sol_emitter_index = 5 finalize_transfer_discriminator = [124, 126, 103, 188, 144, 65, 135, 51] finalize_transfer_sol_discriminator = [104, 27, 121, 69, 3, 70, 217, 66] diff --git a/omni-relayer/src/utils/solana.rs b/omni-relayer/src/utils/solana.rs index edfb3ba0..275680ba 100644 --- a/omni-relayer/src/utils/solana.rs +++ b/omni-relayer/src/utils/solana.rs @@ -27,13 +27,19 @@ pub async fn process_message( signature: Signature, ) { for instruction in message.instructions.clone() { + let account_keys = instruction + .accounts + .into_iter() + .map(|i| message.account_keys.get(i as usize).cloned()) + .collect::>(); + if let Err(err) = decode_instruction( redis_connection, solana, signature, transaction, &instruction.data, - &message.account_keys, + account_keys, ) .await { @@ -48,7 +54,7 @@ async fn decode_instruction( signature: Signature, transaction: &EncodedTransactionWithStatusMeta, data: &str, - account_keys: &[String], + account_keys: Vec>, ) -> Result<()> { let decoded_data = bs58::decode(data).into_vec()?; @@ -78,21 +84,31 @@ async fn decode_instruction( let (sender, token, emitter) = if discriminator == &solana.init_transfer_discriminator { let sender = account_keys .get(solana.init_transfer_sender_index) - .context("Missing sender account key")?; + .context("Missing sender account key")? + .as_ref() + .context("Sender account key is None")?; let token = account_keys .get(solana.init_transfer_token_index) - .context("Missing token account key")?; + .context("Missing token account key")? + .as_ref() + .context("Sender account key is None")?; let emitter = account_keys .get(solana.init_transfer_emitter_index) - .context("Missing emitter account key")?; + .context("Missing emitter account key")? + .as_ref() + .context("Emitter key is None")?; (sender, token, emitter) } else { let sender = account_keys .get(solana.init_transfer_sol_sender_index) - .context("Missing SOL sender account key")?; + .context("Missing SOL sender account key")? + .as_ref() + .context("SOL sender account key is None")?; let emitter = account_keys .get(solana.init_transfer_sol_emitter_index) - .context("Missing SOL emitter account key")?; + .context("Missing SOL emitter account key")? + .as_ref() + .context("Sol emitter key is None")?; (sender, &Pubkey::default().to_string(), emitter) }; @@ -150,10 +166,14 @@ async fn decode_instruction( account_keys .get(solana.finalize_transfer_emitter_index) .context("Missing emitter account key")? + .as_ref() + .context("Emitter account key is None")? } else { account_keys .get(solana.finalize_transfer_sol_emitter_index) .context("Missing SOL emitter account key")? + .as_ref() + .context("SOL emitter account key is None")? }; if let Some(OptionSerializer::Some(logs)) =