Skip to content

Commit

Permalink
feat: constructed persistent account keys from instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
frolvanya committed Jan 15, 2025
1 parent 4bd6867 commit b51fb3b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
18 changes: 9 additions & 9 deletions omni-relayer/example-mainnet-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
14 changes: 7 additions & 7 deletions omni-relayer/example-testnet-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
34 changes: 27 additions & 7 deletions omni-relayer/src/utils/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();

if let Err(err) = decode_instruction(
redis_connection,
solana,
signature,
transaction,
&instruction.data,
&message.account_keys,
account_keys,
)
.await
{
Expand All @@ -48,7 +54,7 @@ async fn decode_instruction(
signature: Signature,
transaction: &EncodedTransactionWithStatusMeta,
data: &str,
account_keys: &[String],
account_keys: Vec<Option<String>>,
) -> Result<()> {
let decoded_data = bs58::decode(data).into_vec()?;

Expand Down Expand Up @@ -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)
};

Expand Down Expand Up @@ -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)) =
Expand Down

0 comments on commit b51fb3b

Please sign in to comment.