Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use Token Metadata (and latest Bubblegum) Rust clients #168

Merged
merged 6 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
354 changes: 45 additions & 309 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ anyhow = "1.0.75"
async-std = "1.0.0"
async-trait = "0.1.60"
base64 = "0.21.0"
blockbuster = "=0.9.0-beta.5"
blockbuster = { version = "0.9.0-beta.5", git = "https://github.com/metaplex-foundation/blockbuster.git", rev = "421272e062461c054691e8bb587caa6e7a15fe71" }
borsh = "~0.10.3"
borsh-derive = "~0.10.3"
bs58 = "0.4.0"
Expand All @@ -54,10 +54,8 @@ lazy_static = "1.4.0"
log = "0.4.17"
metrics = "0.20.1"
mime_guess = "2.0.4"
mpl-bubblegum = "=1.0.1-beta.4"
mpl-candy-guard = "2.0.0"
mpl-candy-machine-core = "2.0.1"
mpl-token-metadata = "=2.0.0-beta.1"
mpl-bubblegum = "1.2.0"
mpl-token-metadata = "4.0.1"
nft_ingester = { path = "nft_ingester" }
num-derive = "0.3.3"
num-integer = { version = "0.1.44", default_features = false }
Expand Down
4 changes: 1 addition & 3 deletions das_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ jsonrpsee-core = { workspace = true, features =["server"]}
log = { workspace = true }
metrics = { workspace = true }
mpl-bubblegum = { workspace = true }
mpl-candy-guard = { workspace = true, features = ["no-entrypoint"] }
mpl-candy-machine-core = { workspace = true, features = ["no-entrypoint"] }
mpl-token-metadata = { workspace = true, features = ["serde-feature"] }
mpl-token-metadata = { workspace = true, features = ["serde"] }
open-rpc-derive = { workspace = true }
open-rpc-schema = { workspace = true }
schemars = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions digital_asset_types/src/dao/generated/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3

#![allow(unused_imports)]

pub use super::asset::Entity as Asset;
pub use super::asset_authority::Entity as AssetAuthority;
pub use super::asset_creators::Entity as AssetCreators;
Expand Down
2 changes: 1 addition & 1 deletion digital_asset_types/src/json/chain_data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use blockbuster::token_metadata::state::{TokenStandard, Uses};
use blockbuster::token_metadata::types::{TokenStandard, Uses};
use serde::{Deserialize, Serialize};

pub enum ChainData {
Expand Down
2 changes: 1 addition & 1 deletion digital_asset_types/tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use blockbuster::token_metadata::state::*;
use blockbuster::token_metadata::types::{Collection, Creator, TokenStandard, Uses};
use digital_asset_types::dao::sea_orm_active_enums::{
SpecificationAssetClass, SpecificationVersions,
};
Expand Down
2 changes: 1 addition & 1 deletion digital_asset_types/tests/get_asset_by_id.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(test)]
mod common;

use blockbuster::token_metadata::state::*;
use blockbuster::token_metadata::types::{Creator, TokenStandard};
use common::*;
use digital_asset_types::dao::sea_orm_active_enums::*;
use digital_asset_types::dao::{
Expand Down
2 changes: 1 addition & 1 deletion digital_asset_types/tests/get_assets_by_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod common;
use sea_orm::{entity::prelude::*, DatabaseBackend, MockDatabase};
use solana_sdk::{signature::Keypair, signer::Signer};

use blockbuster::token_metadata::state::*;
use blockbuster::token_metadata::types::{Creator, TokenStandard};
use common::*;
use digital_asset_types::dao::sea_orm_active_enums::*;
use digital_asset_types::dao::{
Expand Down
2 changes: 1 addition & 1 deletion digital_asset_types/tests/get_assets_by_creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sea_orm::{
};
use solana_sdk::{signature::Keypair, signer::Signer};

use blockbuster::token_metadata::state::*;
use blockbuster::token_metadata::types::{Creator, TokenStandard};
use common::*;
use digital_asset_types::dao::sea_orm_active_enums::*;
use digital_asset_types::dao::{
Expand Down
2 changes: 1 addition & 1 deletion digital_asset_types/tests/get_assets_by_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sea_orm::{
};
use solana_sdk::{signature::Keypair, signer::Signer};

use blockbuster::token_metadata::state::*;
use blockbuster::token_metadata::types::{Creator, TokenStandard};
use common::*;
use digital_asset_types::dao::sea_orm_active_enums::*;
use digital_asset_types::dao::{
Expand Down
2 changes: 1 addition & 1 deletion digital_asset_types/tests/get_assets_by_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod common;
use sea_orm::{entity::prelude::*, DatabaseBackend, MockDatabase};
use solana_sdk::{signature::Keypair, signer::Signer};

use blockbuster::token_metadata::state::*;
use blockbuster::token_metadata::types::{Creator, TokenStandard};
use common::*;
use digital_asset_types::dao::sea_orm_active_enums::*;
use digital_asset_types::dao::{
Expand Down
2 changes: 1 addition & 1 deletion digital_asset_types/tests/json_parsing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(test)]
use blockbuster::token_metadata::state::TokenStandard as TSBlockbuster;
use blockbuster::token_metadata::types::TokenStandard as TSBlockbuster;
use digital_asset_types::dao::asset_data;
use digital_asset_types::dao::sea_orm_active_enums::{ChainMutability, Mutability};
use digital_asset_types::dapi::common::v1_content_from_json;
Expand Down
2 changes: 0 additions & 2 deletions nft_ingester/src/program_transformers/bubblegum/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::error::IngesterError;
use digital_asset_types::dao::{
asset, asset_authority, asset_creators, asset_data, asset_grouping, backfill_items,
cl_audits_v2, cl_items,
extensions::instruction::PascalCase,
sea_orm_active_enums::{
ChainMutability, Instruction, Mutability, OwnerType, RoyaltyTargetType,
SpecificationAssetClass, SpecificationVersions,
Expand All @@ -14,7 +13,6 @@ use sea_orm::{
query::*, sea_query::OnConflict, ActiveValue::Set, ColumnTrait, DbBackend, EntityTrait,
};
use spl_account_compression::events::ChangeLogEventV1;
use std::collections::HashSet;

pub async fn save_changelog_event<'c, T>(
change_log_event: &ChangeLogEventV1,
Expand Down
13 changes: 6 additions & 7 deletions nft_ingester/src/program_transformers/bubblegum/mint_v1.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::{
error::IngesterError,
program_transformers::bubblegum::{
save_changelog_event, upsert_asset_authority, upsert_asset_base_info,
upsert_asset_creators, upsert_asset_data, upsert_asset_with_compression_info,
upsert_asset_with_leaf_info, upsert_asset_with_owner_and_delegate_info,
upsert_asset_with_seq, upsert_collection_info,
bgum_use_method_to_token_metadata_use_method, save_changelog_event, upsert_asset_authority,
upsert_asset_base_info, upsert_asset_creators, upsert_asset_data,
upsert_asset_with_compression_info, upsert_asset_with_leaf_info,
upsert_asset_with_owner_and_delegate_info, upsert_asset_with_seq, upsert_collection_info,
},
tasks::{DownloadMetadata, IntoTaskData, TaskData},
};
use blockbuster::{
instruction::InstructionBundle,
programs::bubblegum::{BubblegumInstruction, LeafSchema, Payload},
token_metadata::state::{TokenStandard, UseMethod, Uses},
token_metadata::types::{TokenStandard, Uses},
};
use chrono::Utc;
use digital_asset_types::{
Expand All @@ -22,7 +22,6 @@ use digital_asset_types::{
json::ChainDataV1,
};
use log::warn;
use num_traits::FromPrimitive;
use sea_orm::{query::*, ConnectionTrait, JsonValue};

pub async fn mint_v1<'c, T>(
Expand Down Expand Up @@ -72,7 +71,7 @@ where
primary_sale_happened: metadata.primary_sale_happened,
token_standard: Some(TokenStandard::NonFungible),
uses: metadata.uses.clone().map(|u| Uses {
use_method: UseMethod::from_u8(u.use_method as u8).unwrap(),
use_method: bgum_use_method_to_token_metadata_use_method(u.use_method),
remaining: u.remaining,
total: u.total,
}),
Expand Down
13 changes: 12 additions & 1 deletion nft_ingester/src/program_transformers/bubblegum/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use blockbuster::{
self,
instruction::InstructionBundle,
programs::bubblegum::{BubblegumInstruction, InstructionName},
programs::bubblegum::{BubblegumInstruction, InstructionName, UseMethod as BubblegumUseMethod},
token_metadata::types::UseMethod as TokenMetadataUseMethod,
};
use log::{debug, info};
use sea_orm::{ConnectionTrait, TransactionTrait};
Expand Down Expand Up @@ -115,3 +116,13 @@ fn u32_to_u8_array(value: u32) -> [u8; 8] {
result[..4].copy_from_slice(&bytes);
result
}

const fn bgum_use_method_to_token_metadata_use_method(
bubblegum_use_method: BubblegumUseMethod,
) -> TokenMetadataUseMethod {
match bubblegum_use_method {
BubblegumUseMethod::Burn => TokenMetadataUseMethod::Burn,
BubblegumUseMethod::Multiple => TokenMetadataUseMethod::Multiple,
BubblegumUseMethod::Single => TokenMetadataUseMethod::Single,
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use crate::{
error::IngesterError,
program_transformers::bubblegum::{
save_changelog_event, upsert_asset_base_info, upsert_asset_creators, upsert_asset_data,
upsert_asset_with_leaf_info, upsert_asset_with_seq,
bgum_use_method_to_token_metadata_use_method, save_changelog_event, upsert_asset_base_info,
upsert_asset_creators, upsert_asset_data, upsert_asset_with_leaf_info,
upsert_asset_with_seq,
},
tasks::{DownloadMetadata, IntoTaskData, TaskData},
};
use blockbuster::{
instruction::InstructionBundle,
programs::bubblegum::{BubblegumInstruction, LeafSchema, Payload},
token_metadata::state::{TokenStandard, UseMethod, Uses},
token_metadata::types::{TokenStandard, Uses},
};
use chrono::Utc;
use digital_asset_types::{
Expand All @@ -20,7 +21,6 @@ use digital_asset_types::{
json::ChainDataV1,
};
use log::warn;
use num_traits::FromPrimitive;
use sea_orm::{query::*, ConnectionTrait, JsonValue};

pub async fn update_metadata<'c, T>(
Expand Down Expand Up @@ -87,7 +87,7 @@ where
primary_sale_happened,
token_standard: Some(TokenStandard::NonFungible),
uses: current_metadata.uses.clone().map(|u| Uses {
use_method: UseMethod::from_u8(u.use_method as u8).unwrap(),
use_method: bgum_use_method_to_token_metadata_use_method(u.use_method),
remaining: u.remaining,
total: u.total,
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::error::IngesterError;
use blockbuster::token_metadata::state::{Key, MasterEditionV1, MasterEditionV2};
use blockbuster::token_metadata::{
accounts::{DeprecatedMasterEditionV1, MasterEdition},
types::Key,
};
use digital_asset_types::dao::{
asset, asset_v1_account_attachments, extensions,
sea_orm_active_enums::{SpecificationAssetClass, V1AccountAttachments},
Expand All @@ -13,7 +16,7 @@ use sea_orm::{
pub async fn save_v2_master_edition(
id: FBPubkey,
slot: u64,
me_data: &MasterEditionV2,
me_data: &MasterEdition,
txn: &DatabaseTransaction,
) -> Result<(), IngesterError> {
save_master_edition(
Expand All @@ -29,13 +32,15 @@ pub async fn save_v2_master_edition(
pub async fn save_v1_master_edition(
id: FBPubkey,
slot: u64,
me_data: &MasterEditionV1,
me_data: &DeprecatedMasterEditionV1,
txn: &DatabaseTransaction,
) -> Result<(), IngesterError> {
let bridge = MasterEditionV2 {
// This discards the deprecated `MasterEditionV1` fields
// but sets the `Key`` as `MasterEditionV1`.
let bridge = MasterEdition {
supply: me_data.supply,
max_supply: me_data.max_supply,
key: Key::MasterEditionV1, // is this weird?
key: Key::MasterEditionV1,
};
save_master_edition(
V1AccountAttachments::MasterEditionV1,
Expand All @@ -47,10 +52,10 @@ pub async fn save_v1_master_edition(
.await
}
pub async fn save_master_edition(
_version: V1AccountAttachments,
version: V1AccountAttachments,
id: FBPubkey,
slot: u64,
me_data: &MasterEditionV2,
me_data: &MasterEdition,
txn: &DatabaseTransaction,
) -> Result<(), IngesterError> {
let id_bytes = id.0.to_vec();
Expand All @@ -68,7 +73,7 @@ pub async fn save_master_edition(

let model = asset_v1_account_attachments::ActiveModel {
id: Set(id_bytes),
attachment_type: Set(V1AccountAttachments::MasterEditionV1),
attachment_type: Set(version),
data: Set(Some(ser)),
slot_updated: Set(slot as i64),
..Default::default()
Expand Down
29 changes: 11 additions & 18 deletions nft_ingester/src/program_transformers/token_metadata/v1_asset.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::tasks::{DownloadMetadata, IntoTaskData};
use crate::{error::IngesterError, metric, tasks::TaskData};
use blockbuster::token_metadata::{
pda::find_master_edition_account,
state::{Metadata, TokenStandard, UseMethod, Uses},
accounts::{MasterEdition, Metadata},
types::TokenStandard,
};
use cadence_macros::{is_global_default_set, statsd_count};
use chrono::Utc;
Expand All @@ -20,14 +20,12 @@ use digital_asset_types::{
};
use lazy_static::lazy_static;
use log::warn;
use num_traits::FromPrimitive;
use plerkle_serialization::Pubkey as FBPubkey;
use sea_orm::{
entity::*, query::*, sea_query::OnConflict, ActiveValue::Set, ConnectionTrait, DbBackend,
DbErr, EntityTrait, JsonValue,
};
use solana_sdk::pubkey::Pubkey;
use std::collections::HashSet;
use std::str::FromStr;
use std::time::Duration;
use tokio::time::sleep;
Expand Down Expand Up @@ -73,16 +71,15 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
slot: u64,
) -> Result<Option<TaskData>, IngesterError> {
let metadata = metadata.clone();
let data = metadata.data;
let mint_pubkey = metadata.mint;
let mint_pubkey_array = mint_pubkey.to_bytes();
let mint_pubkey_vec = mint_pubkey_array.to_vec();

let (edition_attachment_address, _) = find_master_edition_account(&mint_pubkey);
let (edition_attachment_address, _) = MasterEdition::find_pda(&mint_pubkey);

let authority = metadata.update_authority.to_bytes().to_vec();
let slot_i = slot as i64;
let uri = data.uri.trim().replace('\0', "");
let uri = metadata.uri.trim().replace('\0', "");
let _spec = SpecificationVersions::V1;
let mut class = match metadata.token_standard {
Some(TokenStandard::NonFungible) => SpecificationAssetClass::Nft,
Expand Down Expand Up @@ -179,19 +176,15 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
}
};

let name = data.name.clone().into_bytes();
let symbol = data.symbol.clone().into_bytes();
let name = metadata.name.clone().into_bytes();
let symbol = metadata.symbol.clone().into_bytes();
let mut chain_data = ChainDataV1 {
name: data.name.clone(),
symbol: data.symbol.clone(),
name: metadata.name.clone(),
symbol: metadata.symbol.clone(),
edition_nonce: metadata.edition_nonce,
primary_sale_happened: metadata.primary_sale_happened,
token_standard: metadata.token_standard,
uses: metadata.uses.map(|u| Uses {
use_method: UseMethod::from_u8(u.use_method as u8).unwrap(),
remaining: u.remaining,
total: u.total,
}),
uses: metadata.uses,
};
chain_data.sanitize();
let chain_data_json = serde_json::to_value(chain_data)
Expand Down Expand Up @@ -259,7 +252,7 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
compressible: Set(false),
royalty_target_type: Set(RoyaltyTargetType::Creators),
royalty_target: Set(None),
royalty_amount: Set(data.seller_fee_basis_points as i32), //basis points
royalty_amount: Set(metadata.seller_fee_basis_points as i32), //basis points
asset_data: Set(Some(mint_pubkey_vec.clone())),
slot_updated: Set(Some(slot_i)),
burnt: Set(false),
Expand Down Expand Up @@ -380,7 +373,7 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
.map_err(|db_err| IngesterError::AssetIndexError(db_err.to_string()))?;
}

let creators = data
let creators = metadata
.creators
.unwrap_or_default()
.iter()
Expand Down
4 changes: 2 additions & 2 deletions tools/acc_forwarder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
figment::{map, value::Value},
futures::{future::try_join_all, stream::StreamExt},
log::{info, warn},
mpl_token_metadata::{pda::find_metadata_account, state::Metadata},
mpl_token_metadata::accounts::Metadata,
plerkle_messenger::{MessengerConfig, ACCOUNT_BACKFILL_STREAM},
plerkle_serialization::{
serializer::serialize_account, solana_geyser_plugin_interface_shims::ReplicaAccountInfoV2,
Expand Down Expand Up @@ -150,7 +150,7 @@ async fn main() -> anyhow::Result<()> {
Action::Mint { mint } => {
let mint =
Pubkey::from_str(&mint).with_context(|| format!("failed to parse mint {mint}"))?;
let metadata_account = find_metadata_account(&mint).0;
let metadata_account = Metadata::find_pda(&mint).0;
let token_account = get_token_largest_account(&client, mint).await;

match token_account {
Expand Down
Loading
Loading