Skip to content

Commit

Permalink
Solana: fix finalize transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
kiseln committed Dec 17, 2024
1 parent a98ba59 commit 6660cb2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ use borsh::{BorshDeserialize, BorshSerialize};
use derive_builder::Builder;
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
signature::{Keypair, Signature},
signer::Signer,
system_program, sysvar,
transaction::Transaction,
instruction::{AccountMeta, Instruction}, program_option::COption, program_pack::Pack, pubkey::Pubkey, signature::{Keypair, Signature}, signer::Signer, system_program, sysvar, transaction::Transaction
};
use spl_token::state::Mint;

mod error;
mod instructions;
Expand Down Expand Up @@ -38,7 +34,6 @@ pub struct TransferId {
pub struct DepositPayload {
pub destination_nonce: u64,
pub transfer_id: TransferId,
pub token: String,
pub amount: u128,
pub recipient: Pubkey,
pub fee_recipient: Option<String>,
Expand Down Expand Up @@ -242,12 +237,14 @@ impl SolanaBridgeClient {
],
&spl_associated_token_account::ID,
);
let (vault, _) = Pubkey::find_program_address(&[b"vault", token.as_ref()], program_id);

let (wormhole_bridge, wormhole_fee_collector, wormhole_sequence) =
self.get_wormhole_accounts().await?;
let wormhole_message = Keypair::new();

let token_owner = self.get_token_owner(token).await?;
let is_solana_native = token_owner.is_some() && token_owner.unwrap() == authority;

let instruction_data = InitTransfer {
amount,
recipient,
Expand All @@ -262,7 +259,12 @@ impl SolanaBridgeClient {
AccountMeta::new_readonly(authority, false),
AccountMeta::new(token, false),
AccountMeta::new(from_token_account, false),
AccountMeta::new(vault, false), // Optional
if is_solana_native {
let (vault, _) = Pubkey::find_program_address(&[b"vault", token.as_ref()], program_id);
AccountMeta::new(vault, false)
} else {
AccountMeta::new(*program_id, false) // Vault is not present for non-native tokens
},
AccountMeta::new(sol_vault, false),
AccountMeta::new(keypair.pubkey(), true),
AccountMeta::new_readonly(config, false),
Expand Down Expand Up @@ -511,6 +513,17 @@ impl SolanaBridgeClient {
Ok(signature)
}

async fn get_token_owner(&self, token: Pubkey) -> Result<COption<Pubkey>, SolanaClientError> {
let client = self.client()?;

let mint_account = client.get_account(&token).await?;

let mint_data = Mint::unpack(&mint_account.data)
.map_err(|e| SolanaClientError::InvalidAccountData(e.to_string()))?;

Ok(mint_data.mint_authority)
}

pub fn client(&self) -> Result<&RpcClient, SolanaClientError> {
self.client.as_ref().ok_or(SolanaClientError::ConfigError(
"Client not initialized".to_string(),
Expand Down
1 change: 0 additions & 1 deletion bridge-sdk/connectors/omni-connector/src/omni_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ impl OmniConnector {
origin_chain: 1,
origin_nonce: message_payload.transfer_id.origin_nonce,
},
token: "wrap.testnet".to_string(),
amount: message_payload.amount.into(),
recipient: match message_payload.recipient {
OmniAddress::Sol(addr) => Pubkey::new_from_array(addr.0),
Expand Down

0 comments on commit 6660cb2

Please sign in to comment.