Skip to content

Commit 8f5c55d

Browse files
authored
Merge pull request #122 from Near-One/fix/token2022-transfers
Solana: provide correct token program id for 2022-standard tokens
2 parents d96493c + d78c4b2 commit 8f5c55d

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bridge-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bridge-cli"
3-
version = "0.2.10"
3+
version = "0.2.11"
44
edition = "2021"
55
repository = "https://github.com/Near-One/bridge-sdk-rs"
66

bridge-sdk/bridge-clients/solana-bridge-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "solana-bridge-client"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
edition = "2021"
55

66
[dependencies]

bridge-sdk/bridge-clients/solana-bridge-client/src/solana_bridge_client.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,15 @@ impl SolanaBridgeClient {
305305
let (authority, _) = Pubkey::find_program_address(&[b"authority"], program_id);
306306
let (sol_vault, _) = Pubkey::find_program_address(&[b"sol_vault"], program_id);
307307

308+
let token_program_id = self.get_mint_owner(token).await?;
309+
if token_program_id != spl_token::ID && token_program_id != spl_token_2022::ID {
310+
return Err(SolanaBridgeClientError::InvalidArgument(format!("Not a Solana token: {token}")));
311+
}
312+
308313
let (from_token_account, _) = Pubkey::find_program_address(
309314
&[
310315
keypair.pubkey().as_ref(),
311-
spl_token::ID.as_ref(),
316+
token_program_id.as_ref(),
312317
token.as_ref(),
313318
],
314319
&spl_associated_token_account::ID,
@@ -358,7 +363,7 @@ impl SolanaBridgeClient {
358363
AccountMeta::new_readonly(sysvar::rent::ID, false),
359364
AccountMeta::new_readonly(*wormhole_core, false),
360365
AccountMeta::new_readonly(system_program::ID, false),
361-
AccountMeta::new_readonly(spl_token::ID, false),
366+
AccountMeta::new_readonly(token_program_id, false),
362367
],
363368
);
364369

@@ -441,10 +446,16 @@ impl SolanaBridgeClient {
441446
);
442447
let recipient = data.payload.recipient;
443448
let (authority, _) = Pubkey::find_program_address(&[b"authority"], program_id);
449+
450+
let token_program_id = self.get_mint_owner(solana_token).await?;
451+
if token_program_id != spl_token::ID && token_program_id != spl_token_2022::ID {
452+
return Err(SolanaBridgeClientError::InvalidArgument(format!("Not a Solana token: {solana_token}")));
453+
}
454+
444455
let (token_account, _) = Pubkey::find_program_address(
445456
&[
446457
recipient.as_ref(),
447-
spl_token::ID.as_ref(),
458+
token_program_id.as_ref(),
448459
solana_token.as_ref(),
449460
],
450461
&spl_associated_token_account::ID,
@@ -499,7 +510,7 @@ impl SolanaBridgeClient {
499510
AccountMeta::new_readonly(system_program::ID, false),
500511
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
501512
AccountMeta::new_readonly(system_program::ID, false),
502-
AccountMeta::new_readonly(spl_token::ID, false),
513+
AccountMeta::new_readonly(token_program_id, false),
503514
],
504515
);
505516

@@ -609,11 +620,11 @@ impl SolanaBridgeClient {
609620
&self,
610621
token: Pubkey,
611622
) -> Result<COption<Pubkey>, SolanaBridgeClientError> {
623+
const MINT_BASIC_DATA_SIZE: usize = 82;
624+
612625
let client = self.client()?;
613626

614627
let mint_account = client.get_account(&token).await?;
615-
616-
const MINT_BASIC_DATA_SIZE: usize = 82;
617628
let mint_data = Mint::unpack(&mint_account.data[..MINT_BASIC_DATA_SIZE])
618629
.map_err(|e| SolanaBridgeClientError::InvalidAccountData(e.to_string()))?;
619630

bridge-sdk/connectors/omni-connector/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "omni-connector"
3-
version = "0.2.6"
3+
version = "0.2.7"
44
edition = "2021"
55

66
[dependencies]

0 commit comments

Comments
 (0)