瀏覽代碼

Create token meta for Solana devnet tokens

Change-Id: Ic7e2bd4a808640e10b646ee85abf963f9c6c586d
Hendrik Hofstadt 4 年之前
父節點
當前提交
56d8aa5e39

+ 3 - 0
solana/devnet_setup.sh

@@ -43,6 +43,9 @@ echo "Created token account $account"
 # Mint new tokens owned by our CLI account
 spl-token mint "$token" 10000000000 "$account"
 
+# Create meta for token
+token-bridge-client create-meta "$token" "Solana Test Token" "SOLT"
+
 # Create the bridge contract at a known address
 # OK to fail on subsequent attempts (already created).
 retry client create-bridge "$bridge_address" "$initial_guardian" 86400 100

+ 1 - 0
solana/modules/token_bridge/Cargo.lock

@@ -403,6 +403,7 @@ dependencies = [
  "solana-sdk",
  "solitaire",
  "solitaire-client",
+ "spl-token-metadata",
  "token-bridge",
 ]
 

+ 2 - 1
solana/modules/token_bridge/client/Cargo.toml

@@ -17,4 +17,5 @@ solana-cli-config = "=1.7.0"
 solitaire = { path = "../../../solitaire/program" }
 solitaire-client = { path = "../../../solitaire/client" }
 solana-clap-utils = "=1.7.0"
-hex = "0.4.3"
+hex = "0.4.3"
+spl-token-metadata = { path = "../token-metadata" }

+ 79 - 0
solana/modules/token_bridge/client/src/main.rs

@@ -89,6 +89,46 @@ fn command_init_bridge(config: &Config, bridge: &Pubkey, core_bridge: &Pubkey) -
     Ok(Some(transaction))
 }
 
+fn command_create_meta(
+    config: &Config,
+    mint: &Pubkey,
+    name: String,
+    symbol: String,
+) -> CommmandResult {
+    println!("Creating meta for mint {}", mint);
+
+    let meta_acc = Pubkey::find_program_address(
+        &[
+            "metadata".as_bytes(),
+            spl_token_metadata::id().as_ref(),
+            mint.as_ref(),
+        ],
+        &spl_token_metadata::id(),
+    )
+    .0;
+    println!("Meta account: {}", meta_acc);
+    let ix = spl_token_metadata::instruction::create_metadata_accounts(
+        spl_token_metadata::id(),
+        meta_acc,
+        *mint,
+        config.owner.pubkey(),
+        config.owner.pubkey(),
+        config.owner.pubkey(),
+        name,
+        symbol,
+        String::from(""),
+        None,
+        0,
+        false,
+        false,
+    );
+    let mut transaction = Transaction::new_with_payer(&[ix], Some(&config.fee_payer.pubkey()));
+
+    let (recent_blockhash, _) = config.rpc_client.get_recent_blockhash()?;
+    transaction.sign(&[&config.fee_payer, &config.owner], recent_blockhash);
+    Ok(Some(transaction))
+}
+
 fn main() {
     let matches = App::new(crate_name!())
         .about(crate_description!())
@@ -163,6 +203,38 @@ fn main() {
                         .help("Address of the Wormhole core bridge program"),
                 ),
         )
+        .subcommand(
+            SubCommand::with_name("create-meta")
+                .about("Create token metadata")
+                .arg(
+                    Arg::with_name("mint")
+                        .long("mint")
+                        .value_name("MINT")
+                        .validator(is_pubkey_or_keypair)
+                        .takes_value(true)
+                        .index(1)
+                        .required(true)
+                        .help("Specify the mint address"),
+                )
+                .arg(
+                    Arg::with_name("name")
+                        .long("name")
+                        .value_name("NAME")
+                        .takes_value(true)
+                        .index(2)
+                        .required(true)
+                        .help("Name of the token"),
+                )
+                .arg(
+                    Arg::with_name("symbol")
+                        .long("symbol")
+                        .value_name("SYMBOL")
+                        .takes_value(true)
+                        .index(3)
+                        .required(true)
+                        .help("Symbol of the token"),
+                ),
+        )
         .get_matches();
 
     let config = {
@@ -199,6 +271,13 @@ fn main() {
 
             command_init_bridge(&config, &bridge, &core_bridge)
         }
+        ("create-meta", Some(arg_matches)) => {
+            let mint = pubkey_of(arg_matches, "mint").unwrap();
+            let name: String = value_of(arg_matches, "name").unwrap();
+            let symbol: String = value_of(arg_matches, "symbol").unwrap();
+
+            command_create_meta(&config, &mint, name, symbol)
+        }
 
         _ => unreachable!(),
     }