Derive SplTokenMeta addresses
Change-Id: I4a988b0778c741c1405d096ea0d7aa67a2a31190
This commit is contained in:
parent
8718e31fb4
commit
f8a0184a1d
|
@ -86,3 +86,19 @@ impl<'b, const State: AccountState> Seeded<&EndpointDerivationData> for Endpoint
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type SplTokenMeta<'b> = Info<'b>;
|
||||||
|
|
||||||
|
pub struct SplTokenMetaDerivationData {
|
||||||
|
pub mint: Pubkey,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'b> Seeded<&SplTokenMetaDerivationData> for SplTokenMeta<'b> {
|
||||||
|
fn seeds(data: &SplTokenMetaDerivationData) -> Vec<Vec<u8>> {
|
||||||
|
vec![
|
||||||
|
"metadata".as_bytes().to_vec(),
|
||||||
|
spl_token_metadata::id().as_ref().to_vec(),
|
||||||
|
data.mint.as_ref().to_vec(),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ use crate::{
|
||||||
accounts::{
|
accounts::{
|
||||||
ConfigAccount,
|
ConfigAccount,
|
||||||
EmitterAccount,
|
EmitterAccount,
|
||||||
|
SplTokenMeta,
|
||||||
|
SplTokenMetaDerivationData,
|
||||||
WrappedMetaDerivationData,
|
WrappedMetaDerivationData,
|
||||||
WrappedTokenMeta,
|
WrappedTokenMeta,
|
||||||
},
|
},
|
||||||
|
@ -71,7 +73,7 @@ pub struct AttestToken<'b> {
|
||||||
pub wrapped_meta: WrappedTokenMeta<'b, { AccountState::Uninitialized }>,
|
pub wrapped_meta: WrappedTokenMeta<'b, { AccountState::Uninitialized }>,
|
||||||
|
|
||||||
/// SPL Metadata for the associated Mint
|
/// SPL Metadata for the associated Mint
|
||||||
pub spl_metadata: Info<'b>,
|
pub spl_metadata: SplTokenMeta<'b>,
|
||||||
|
|
||||||
/// CPI Context
|
/// CPI Context
|
||||||
pub bridge: Mut<Info<'b>>,
|
pub bridge: Mut<Info<'b>>,
|
||||||
|
@ -102,6 +104,14 @@ impl<'a> From<&AttestToken<'a>> for WrappedMetaDerivationData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> From<&AttestToken<'a>> for SplTokenMetaDerivationData {
|
||||||
|
fn from(accs: &AttestToken<'a>) -> Self {
|
||||||
|
SplTokenMetaDerivationData {
|
||||||
|
mint: *accs.mint.info().key,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(BorshDeserialize, BorshSerialize, Default)]
|
#[derive(BorshDeserialize, BorshSerialize, Default)]
|
||||||
pub struct AttestTokenData {
|
pub struct AttestTokenData {
|
||||||
pub nonce: u32,
|
pub nonce: u32,
|
||||||
|
@ -134,6 +144,10 @@ pub fn attest_token(
|
||||||
|
|
||||||
// Assign metadata if an SPL Metadata account exists for the SPL token in question.
|
// Assign metadata if an SPL Metadata account exists for the SPL token in question.
|
||||||
if !accs.spl_metadata.data_is_empty() {
|
if !accs.spl_metadata.data_is_empty() {
|
||||||
|
let derivation_data: SplTokenMetaDerivationData = (&*accs).into();
|
||||||
|
accs.spl_metadata
|
||||||
|
.verify_derivation(&spl_token_metadata::id(), &derivation_data)?;
|
||||||
|
|
||||||
if *accs.spl_metadata.owner != spl_token_metadata::id() {
|
if *accs.spl_metadata.owner != spl_token_metadata::id() {
|
||||||
return Err(WrongAccountOwner.into());
|
return Err(WrongAccountOwner.into());
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ use crate::{
|
||||||
Endpoint,
|
Endpoint,
|
||||||
EndpointDerivationData,
|
EndpointDerivationData,
|
||||||
MintSigner,
|
MintSigner,
|
||||||
|
SplTokenMeta,
|
||||||
|
SplTokenMetaDerivationData,
|
||||||
WrappedDerivationData,
|
WrappedDerivationData,
|
||||||
WrappedMetaDerivationData,
|
WrappedMetaDerivationData,
|
||||||
WrappedMint,
|
WrappedMint,
|
||||||
|
@ -447,24 +449,27 @@ pub fn attest(
|
||||||
message_key: Pubkey,
|
message_key: Pubkey,
|
||||||
mint: Pubkey,
|
mint: Pubkey,
|
||||||
decimals: u8,
|
decimals: u8,
|
||||||
mint_meta: Pubkey,
|
|
||||||
spl_metadata: Pubkey,
|
|
||||||
symbol: String,
|
|
||||||
name: String,
|
|
||||||
nonce: u32,
|
nonce: u32,
|
||||||
) -> solitaire::Result<Instruction> {
|
) -> solitaire::Result<Instruction> {
|
||||||
let config_key = ConfigAccount::<'_, { AccountState::Uninitialized }>::key(None, &program_id);
|
let config_key = ConfigAccount::<'_, { AccountState::Uninitialized }>::key(None, &program_id);
|
||||||
let emitter_key = EmitterAccount::key(None, &program_id);
|
let emitter_key = EmitterAccount::key(None, &program_id);
|
||||||
|
|
||||||
// Bridge keys
|
// SPL Metadata
|
||||||
|
let spl_metadata = SplTokenMeta::key(
|
||||||
|
&SplTokenMetaDerivationData { mint },
|
||||||
|
&spl_token_metadata::id(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Mint Metadata
|
||||||
|
let mint_meta = WrappedTokenMeta::<'_, { AccountState::Uninitialized }>::key(
|
||||||
|
&WrappedMetaDerivationData {
|
||||||
|
mint_key: mint,
|
||||||
|
},
|
||||||
|
&bridge_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Bridge Keys
|
||||||
let bridge_config = Bridge::<'_, { AccountState::Uninitialized }>::key(None, &bridge_id);
|
let bridge_config = Bridge::<'_, { AccountState::Uninitialized }>::key(None, &bridge_id);
|
||||||
let payload = PayloadAssetMeta {
|
|
||||||
token_address: mint.to_bytes(),
|
|
||||||
token_chain: 1,
|
|
||||||
decimals,
|
|
||||||
symbol,
|
|
||||||
name,
|
|
||||||
};
|
|
||||||
let sequence_key = Sequence::key(
|
let sequence_key = Sequence::key(
|
||||||
&SequenceDerivationData {
|
&SequenceDerivationData {
|
||||||
emitter_key: &emitter_key,
|
emitter_key: &emitter_key,
|
||||||
|
|
|
@ -19,7 +19,6 @@ use spl_token::state::{
|
||||||
Mint,
|
Mint,
|
||||||
};
|
};
|
||||||
use spl_token_metadata::state::Metadata;
|
use spl_token_metadata::state::Metadata;
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
pub type Address = [u8; 32];
|
pub type Address = [u8; 32];
|
||||||
pub type ChainID = u16;
|
pub type ChainID = u16;
|
||||||
|
|
|
@ -58,7 +58,6 @@ pub fn attest_ix(
|
||||||
message: String,
|
message: String,
|
||||||
mint: String,
|
mint: String,
|
||||||
decimals: u8,
|
decimals: u8,
|
||||||
mint_meta: String,
|
|
||||||
nonce: u32,
|
nonce: u32,
|
||||||
) -> JsValue {
|
) -> JsValue {
|
||||||
let program_id = Pubkey::from_str(program_id.as_str()).unwrap();
|
let program_id = Pubkey::from_str(program_id.as_str()).unwrap();
|
||||||
|
@ -66,10 +65,15 @@ pub fn attest_ix(
|
||||||
let payer = Pubkey::from_str(payer.as_str()).unwrap();
|
let payer = Pubkey::from_str(payer.as_str()).unwrap();
|
||||||
let message = Pubkey::from_str(message.as_str()).unwrap();
|
let message = Pubkey::from_str(message.as_str()).unwrap();
|
||||||
let mint = Pubkey::from_str(mint.as_str()).unwrap();
|
let mint = Pubkey::from_str(mint.as_str()).unwrap();
|
||||||
let mint_meta = Pubkey::from_str(mint_meta.as_str()).unwrap();
|
|
||||||
|
|
||||||
let ix = attest(
|
let ix = attest(
|
||||||
program_id, bridge_id, payer, message, mint, decimals, mint_meta, nonce,
|
program_id,
|
||||||
|
bridge_id,
|
||||||
|
payer,
|
||||||
|
message,
|
||||||
|
mint,
|
||||||
|
decimals,
|
||||||
|
nonce,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue