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

Index Token Extensions and Fungible Tokens #214

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
25 changes: 13 additions & 12 deletions Cargo.lock

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

29 changes: 29 additions & 0 deletions blockbuster/src/programs/token_extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,42 @@ pub struct MintAccountExtensions {
pub token_group_member: Option<ShadowTokenGroupMember>,
}

impl MintAccountExtensions {
pub fn is_some(&self) -> bool {
self.default_account_state.is_some()
|| self.confidential_transfer_mint.is_some()
|| self.confidential_transfer_account.is_some()
|| self.confidential_transfer_fee_config.is_some()
|| self.interest_bearing_config.is_some()
|| self.transfer_fee_config.is_some()
|| self.mint_close_authority.is_some()
|| self.permanent_delegate.is_some()
|| self.metadata_pointer.is_some()
|| self.metadata.is_some()
|| self.transfer_hook.is_some()
|| self.group_pointer.is_some()
|| self.token_group.is_some()
|| self.group_member_pointer.is_some()
|| self.token_group_member.is_some()
}
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct TokenAccountExtensions {
pub confidential_transfer: Option<ShadowConfidentialTransferAccount>,
pub cpi_guard: Option<ShadowCpiGuard>,
pub memo_transfer: Option<ShadowMemoTransfer>,
pub transfer_fee_amount: Option<ShadowTransferFeeAmount>,
}

impl TokenAccountExtensions {
pub fn is_some(&self) -> bool {
self.confidential_transfer.is_some()
|| self.cpi_guard.is_some()
|| self.memo_transfer.is_some()
|| self.transfer_fee_amount.is_some()
}
}
#[derive(Debug, PartialEq)]
pub struct TokenAccount {
pub account: Account,
Expand Down
1 change: 1 addition & 0 deletions digital_asset_types/src/dao/extensions/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl Default for asset::Model {
owner_delegate_seq: None,
leaf_seq: None,
base_info_seq: None,
mint_extensions: None,
mpl_core_plugins: None,
mpl_core_unknown_plugins: None,
mpl_core_collection_current_size: None,
Expand Down
3 changes: 3 additions & 0 deletions digital_asset_types/src/dao/generated/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct Model {
pub owner_delegate_seq: Option<i64>,
pub leaf_seq: Option<i64>,
pub base_info_seq: Option<i64>,
pub mint_extensions: Option<Json>,
pub mpl_core_plugins: Option<Json>,
pub mpl_core_unknown_plugins: Option<Json>,
pub mpl_core_collection_num_minted: Option<i32>,
Expand Down Expand Up @@ -93,6 +94,7 @@ pub enum Column {
OwnerDelegateSeq,
LeafSeq,
BaseInfoSeq,
MintExtensions,
MplCorePlugins,
MplCoreUnknownPlugins,
MplCoreCollectionNumMinted,
Expand Down Expand Up @@ -153,6 +155,7 @@ impl ColumnTrait for Column {
Self::OwnerDelegateSeq => ColumnType::BigInteger.def().null(),
Self::LeafSeq => ColumnType::BigInteger.def().null(),
Self::BaseInfoSeq => ColumnType::BigInteger.def().null(),
Self::MintExtensions => ColumnType::JsonBinary.def().null(),
Self::MplCorePlugins => ColumnType::JsonBinary.def().null(),
Self::MplCoreUnknownPlugins => ColumnType::JsonBinary.def().null(),
Self::MplCoreCollectionNumMinted => ColumnType::Integer.def().null(),
Expand Down
3 changes: 3 additions & 0 deletions digital_asset_types/src/dao/generated/token_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct Model {
pub delegated_amount: i64,
pub slot_updated: i64,
pub token_program: Vec<u8>,
pub extensions: Option<Json>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
Expand All @@ -38,6 +39,7 @@ pub enum Column {
DelegatedAmount,
SlotUpdated,
TokenProgram,
Extensions,
}

#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
Expand Down Expand Up @@ -69,6 +71,7 @@ impl ColumnTrait for Column {
Self::DelegatedAmount => ColumnType::BigInteger.def(),
Self::SlotUpdated => ColumnType::BigInteger.def(),
Self::TokenProgram => ColumnType::Binary.def(),
Self::Extensions => ColumnType::Json.def().null(),
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions digital_asset_types/src/dao/generated/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Model {
pub close_authority: Option<Vec<u8>>,
pub extension_data: Option<Vec<u8>>,
pub slot_updated: i64,
pub extensions: Option<Json>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
Expand All @@ -36,6 +37,7 @@ pub enum Column {
CloseAuthority,
ExtensionData,
SlotUpdated,
Extensions,
}

#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
Expand Down Expand Up @@ -66,6 +68,7 @@ impl ColumnTrait for Column {
Self::CloseAuthority => ColumnType::Binary.def().null(),
Self::ExtensionData => ColumnType::Binary.def().null(),
Self::SlotUpdated => ColumnType::BigInteger.def(),
Self::Extensions => ColumnType::JsonBinary.def().null(),
}
}
}
Expand All @@ -77,3 +80,13 @@ impl RelationTrait for Relation {
}

impl ActiveModelBehavior for ActiveModel {}

pub trait IsNonFungible {
fn is_non_fungible(&self) -> bool;
}

impl IsNonFungible for Model {
fn is_non_fungible(&self) -> bool {
self.decimals == 0 && self.supply == 1.into()
}
}
6 changes: 4 additions & 2 deletions digital_asset_types/src/dapi/common/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ pub fn asset_to_rpc(asset: FullAsset, options: &Options) -> Result<RpcAsset, DbE
.unwrap_or(false);
let edition_nonce =
safe_select(chain_data_selector, "$.edition_nonce").and_then(|v| v.as_u64());

let mpl_core_info = match interface {
Interface::MplCoreAsset | Interface::MplCoreCollection => Some(MplCoreInfo {
num_minted: asset.mpl_core_collection_num_minted,
Expand Down Expand Up @@ -415,7 +416,7 @@ pub fn asset_to_rpc(asset: FullAsset, options: &Options) -> Result<RpcAsset, DbE
locked: false,
}),
creators: Some(rpc_creators),
ownership: Ownership {
ownership: Some(Ownership {
frozen: asset.frozen,
delegated: asset.delegate.is_some(),
delegate: asset.delegate.map(|s| bs58::encode(s).into_string()),
Expand All @@ -424,7 +425,7 @@ pub fn asset_to_rpc(asset: FullAsset, options: &Options) -> Result<RpcAsset, DbE
.owner
.map(|o| bs58::encode(o).into_string())
.unwrap_or("".to_string()),
},
}),
supply: match interface {
Interface::V1NFT => Some(Supply {
edition_nonce,
Expand All @@ -444,6 +445,7 @@ pub fn asset_to_rpc(asset: FullAsset, options: &Options) -> Result<RpcAsset, DbE
remaining: u.get("remaining").and_then(|t| t.as_u64()).unwrap_or(0),
}),
burnt: asset.burnt,
mint_extensions: asset.mint_extensions,
plugins: asset.mpl_core_plugins,
unknown_plugins: asset.mpl_core_unknown_plugins,
mpl_core_info,
Expand Down
29 changes: 21 additions & 8 deletions digital_asset_types/src/rpc/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ pub struct AssetProof {
pub tree_id: String,
}

#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema, Default)]
pub enum Interface {
#[serde(rename = "V1_NFT")]
V1NFT,
#[serde(rename = "V1_PRINT")]
V1PRINT,
#[serde(rename = "V2_NFT")]
Nft,
// TODO: change on version bump\
#[serde(rename = "LEGACY_NFT")]
// TODO: change on version bump
#[allow(non_camel_case_types)]
LEGACY_NFT,
#[serde(rename = "V2_NFT")]
Nft,
#[serde(rename = "FungibleAsset")]
FungibleAsset,
#[serde(rename = "Custom")]
Custom,
#[serde(rename = "FungibleToken")]
FungibleToken,
#[serde(rename = "Identity")]
Identity,
#[serde(rename = "Executable")]
Expand All @@ -47,6 +47,9 @@ pub enum Interface {
MplCoreAsset,
#[serde(rename = "MplCoreCollection")]
MplCoreCollection,
#[default]
#[serde(rename = "Custom")]
Custom,
}

impl From<(&SpecificationVersions, &SpecificationAssetClass)> for Interface {
Expand All @@ -60,6 +63,8 @@ impl From<(&SpecificationVersions, &SpecificationAssetClass)> for Interface {
}
(_, SpecificationAssetClass::MplCoreAsset) => Interface::MplCoreAsset,
(_, SpecificationAssetClass::MplCoreCollection) => Interface::MplCoreCollection,
(_, SpecificationAssetClass::FungibleAsset) => Interface::FungibleAsset,
(_, SpecificationAssetClass::FungibleToken) => Interface::FungibleToken,
_ => Interface::Custom,
}
}
Expand Down Expand Up @@ -87,6 +92,10 @@ impl From<Interface> for (SpecificationVersions, SpecificationAssetClass) {
SpecificationVersions::V1,
SpecificationAssetClass::MplCoreCollection,
),
Interface::FungibleToken => (
SpecificationVersions::V0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably doesn't matter based on its usage, but seems like it would be V1 as most other things are now V1.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will change to V1

SpecificationAssetClass::FungibleToken,
),
_ => (SpecificationVersions::V1, SpecificationAssetClass::Unknown),
}
}
Expand Down Expand Up @@ -366,7 +375,7 @@ pub struct MplCoreInfo {
pub plugins_json_version: Option<i32>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema, Default)]
pub struct Asset {
pub interface: Interface,
pub id: String,
Expand All @@ -382,13 +391,17 @@ pub struct Asset {
pub royalty: Option<Royalty>,
#[serde(skip_serializing_if = "Option::is_none")]
pub creators: Option<Vec<Creator>>,
pub ownership: Ownership,
#[serde(skip_serializing_if = "Option::is_none")]
pub ownership: Option<Ownership>,
#[serde(skip_serializing_if = "Option::is_none")]
pub uses: Option<Uses>,
#[serde(skip_serializing_if = "Option::is_none")]
pub supply: Option<Supply>,
pub mutable: bool,
pub burnt: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub mint_extensions: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub plugins: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub unknown_plugins: Option<Value>,
Expand Down
1 change: 1 addition & 0 deletions digital_asset_types/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ pub fn create_asset(
mpl_core_plugins_json_version: None,
mpl_core_external_plugins: None,
mpl_core_unknown_external_plugins: None,
mint_extensions: None,
},
)
}
Expand Down
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions integration_tests/tests/integration_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ mod common;
mod general_scenario_tests;
mod mpl_core_tests;
mod regular_nft_tests;
mod token_extensions_tests;
Loading