Skip to content

Commit

Permalink
solana: add tbtc metadata creation
Browse files Browse the repository at this point in the history
  • Loading branch information
a5-pickle committed Aug 4, 2023
1 parent 2900c63 commit c59d7c1
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 5 deletions.
135 changes: 135 additions & 0 deletions cross-chain/solana/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions cross-chain/solana/programs/tbtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ cpi = ["no-entrypoint"]

[dependencies]
anchor-lang = { version = "=0.28.0", features = ["derive", "init-if-needed"] }
anchor-spl = "=0.28.0"
solana-program = "=1.14.20"
anchor-spl = { version = "=0.28.0", features = ["metadata"] }

solana-program = "1.14.20"

mpl-token-metadata = "1.13.1"
42 changes: 40 additions & 2 deletions cross-chain/solana/programs/tbtc/src/processor/admin/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
state::{Config, Guardians, Minters},
};
use anchor_lang::prelude::*;
use anchor_spl::token;
use anchor_spl::{metadata, token};

#[derive(Accounts)]
pub struct Initialize<'info> {
Expand Down Expand Up @@ -49,11 +49,20 @@ pub struct Initialize<'info> {
#[account(mut)]
authority: Signer<'info>,

/// CHECK: This account is needed for the MPL Token Metadata program.
#[account(mut)]
tbtc_metadata: UncheckedAccount<'info>,

/// CHECK: This account is needed for the MPL Token Metadata program.
rent: UncheckedAccount<'info>,

mpl_token_metadata_program: Program<'info, metadata::Metadata>,
token_program: Program<'info, token::Token>,
system_program: Program<'info, System>,
}

pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
// Set Config account data.
ctx.accounts.config.set_inner(Config {
bump: ctx.bumps["config"],
authority: ctx.accounts.authority.key(),
Expand All @@ -65,15 +74,44 @@ pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
paused: false,
});

// Set Guardians account data with empty vec.
ctx.accounts.guardians.set_inner(Guardians {
bump: ctx.bumps["guardians"],
keys: Vec::new(),
});

// Set Guardians account data with empty vec.
ctx.accounts.minters.set_inner(Minters {
bump: ctx.bumps["minters"],
keys: Vec::new(),
});

Ok(())
// Create metadata for tBTC.
metadata::create_metadata_accounts_v3(
CpiContext::new_with_signer(
ctx.accounts.mpl_token_metadata_program.to_account_info(),
metadata::CreateMetadataAccountsV3 {
metadata: ctx.accounts.tbtc_metadata.to_account_info(),
mint: ctx.accounts.mint.to_account_info(),
mint_authority: ctx.accounts.config.to_account_info(),
payer: ctx.accounts.authority.to_account_info(),
update_authority: ctx.accounts.config.to_account_info(),
system_program: ctx.accounts.system_program.to_account_info(),
rent: ctx.accounts.rent.to_account_info(),
},
&[&[Config::SEED_PREFIX, &[ctx.bumps["config"]]]],
),
mpl_token_metadata::state::DataV2 {
symbol: "tBTC".to_string(),
name: "tBTC v2".to_string(),
uri: "".to_string(),
seller_fee_basis_points: 0,
creators: None,
collection: None,
uses: None,
},
true,
true,
None,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pub fn send_tbtc_gateway(ctx: Context<SendTbtcGateway>, args: SendTbtcGatewayArg
wormhole_program: ctx.accounts.core_bridge_program.to_account_info(),
},
&[
&[Custodian::SEED_PREFIX, &[custodian.bump]],
&[
token_bridge::SEED_PREFIX_SENDER,
&[ctx.accounts.custodian.token_bridge_sender_bump],
Expand All @@ -184,7 +185,6 @@ pub fn send_tbtc_gateway(ctx: Context<SendTbtcGateway>, args: SendTbtcGatewayArg
&ctx.accounts.core_emitter_sequence.value().to_le_bytes(),
&[ctx.bumps["core_message"]],
],
&[Custodian::SEED_PREFIX, &[custodian.bump]],
],
),
nonce,
Expand Down

0 comments on commit c59d7c1

Please sign in to comment.