-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from helius-labs/dev
[Merge] Dev -> Main
- Loading branch information
Showing
25 changed files
with
822 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
use helius::error::Result; | ||
use helius::types::Cluster; | ||
use helius::utils::collection_authority::{get_collection_authority_record, get_collection_metadata_account}; | ||
use helius::Helius; | ||
use mpl_token_metadata::instructions::CreateMetadataAccountV3; | ||
use mpl_token_metadata::instructions::CreateMetadataAccountV3InstructionArgs; | ||
use mpl_token_metadata::types::DataV2; | ||
use solana_program::system_instruction::create_account; | ||
use solana_program::system_program; | ||
use solana_sdk::{ | ||
signature::{Keypair, Signer}, | ||
transaction::Transaction, | ||
}; | ||
use spl_token::solana_program::program_pack::Pack; | ||
use spl_token::{instruction::initialize_mint, state::Mint}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let api_key = ""; | ||
let payer = Keypair::from_base58_string(""); | ||
let cluster = Cluster::MainnetBeta; | ||
let helius = Helius::new_with_async_solana(api_key, cluster)?; | ||
let rpc_client = helius.async_connection()?; | ||
|
||
let collection_mint_keypair = Keypair::new(); | ||
let rent = rpc_client | ||
.get_minimum_balance_for_rent_exemption(Mint::LEN) | ||
.await | ||
.expect("Failed to get rent exemption amount"); | ||
let create_mint_account_ix = create_account( | ||
&payer.pubkey(), | ||
&collection_mint_keypair.pubkey(), | ||
rent, | ||
Mint::LEN as u64, | ||
&spl_token::id(), | ||
); | ||
let collection_authority_keypair = Keypair::new(); | ||
let initialize_mint_ix = initialize_mint( | ||
&spl_token::id(), | ||
&collection_mint_keypair.pubkey(), | ||
&collection_authority_keypair.pubkey(), | ||
None, | ||
9, | ||
) | ||
.expect("Failed to create initialize mint instruction"); | ||
let recent_blockhash = rpc_client.get_latest_blockhash().await?; | ||
let transaction = Transaction::new_signed_with_payer( | ||
&[create_mint_account_ix, initialize_mint_ix], | ||
Some(&payer.pubkey()), | ||
&[&payer, &collection_mint_keypair], | ||
recent_blockhash, | ||
); | ||
rpc_client | ||
.send_and_confirm_transaction(&transaction) | ||
.await | ||
.expect("Failed to create and initialize mint"); | ||
println!( | ||
"Collection mint created and initialized: {}", | ||
collection_mint_keypair.pubkey() | ||
); | ||
|
||
let metadata_pubkey = get_collection_metadata_account(&collection_mint_keypair.pubkey()); | ||
let create_metadata_accounts_ix = CreateMetadataAccountV3 { | ||
metadata: metadata_pubkey, | ||
mint: collection_mint_keypair.pubkey(), | ||
mint_authority: collection_authority_keypair.pubkey(), | ||
payer: payer.pubkey(), | ||
update_authority: (collection_authority_keypair.pubkey(), true), | ||
system_program: system_program::ID, | ||
rent: None, | ||
} | ||
.instruction(CreateMetadataAccountV3InstructionArgs { | ||
data: DataV2 { | ||
name: "".to_string(), | ||
symbol: "".to_string(), | ||
uri: "".to_string(), | ||
seller_fee_basis_points: 0, | ||
creators: None, | ||
collection: None, | ||
uses: None, | ||
}, | ||
is_mutable: true, | ||
collection_details: None, | ||
}); | ||
let recent_blockhash = rpc_client.get_latest_blockhash().await?; | ||
let transaction = Transaction::new_signed_with_payer( | ||
&[create_metadata_accounts_ix], | ||
Some(&payer.pubkey()), | ||
&[&payer, &collection_authority_keypair], | ||
recent_blockhash, | ||
); | ||
rpc_client.send_and_confirm_transaction(&transaction).await?; | ||
println!("Metadata account created: {}", metadata_pubkey.to_string()); | ||
|
||
let delegated_authority_keypair = Keypair::new(); | ||
let result = helius | ||
.delegate_collection_authority( | ||
collection_mint_keypair.pubkey(), | ||
delegated_authority_keypair.pubkey(), | ||
&collection_authority_keypair, | ||
Some(&payer), | ||
) | ||
.await; | ||
assert!( | ||
result.is_ok(), | ||
"Failed to delegate collection authority to {}", | ||
delegated_authority_keypair.pubkey() | ||
); | ||
println!( | ||
"Delegate collection authority to {} transaction signature: {}", | ||
delegated_authority_keypair.pubkey(), | ||
result? | ||
); | ||
|
||
let collection_authority_record = | ||
get_collection_authority_record(&collection_mint_keypair.pubkey(), &delegated_authority_keypair.pubkey()); | ||
let account = rpc_client.get_account(&collection_authority_record).await; | ||
assert!(account.is_ok(), "Collection authority record account should exist"); | ||
|
||
let result = helius | ||
.revoke_collection_authority( | ||
collection_mint_keypair.pubkey(), | ||
Some(delegated_authority_keypair.pubkey()), | ||
&collection_authority_keypair, | ||
Some(&payer), | ||
) | ||
.await; | ||
assert!(result.is_ok(), "Failed to revoke collection authority"); | ||
println!( | ||
"Revoke collection authority from {} transaction signature: {}", | ||
delegated_authority_keypair.pubkey(), | ||
result? | ||
); | ||
|
||
let account = rpc_client.get_account(&collection_authority_record).await; | ||
assert!(account.is_err(), "Collection authority record account should be closed"); | ||
|
||
println!("Delegated collection authority successfully revoked"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.