Skip to content

Commit

Permalink
wip: update core client interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nhanphan committed Mar 12, 2024
1 parent 670c159 commit 5d1574b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
3 changes: 1 addition & 2 deletions clients/js/test/_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Asset,
fetchAsset,
createCollection as baseCreateCollection,
AssetWithPlugins
} from '@metaplex-foundation/mpl-core'
import {
createAssociatedToken,
Expand Down Expand Up @@ -373,4 +372,4 @@ export const yesterday = (): DateTime => now() - 3600n * 24n;
export const tomorrow = (): DateTime => now() + 3600n * 24n;

// TODO move to mpl-core
export const isFrozen = (asset: AssetWithPlugins): boolean => asset.freeze?.frozen || false;
export const isFrozen = (asset: Asset): boolean => asset.freeze?.frozen || false;
18 changes: 9 additions & 9 deletions clients/js/test/defaultGuards/freezeSolPayment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@metaplex-foundation/umi';
import { generateSignerWithSol } from '@metaplex-foundation/umi-bundle-tests';
import test, { Assertions } from 'ava';
import { AssetWithPlugins, fetchAssetWithPlugins } from '@metaplex-foundation/mpl-core';
import { Asset, fetchAsset } from '@metaplex-foundation/mpl-core';
import {
fetchFreezeEscrow,
findCandyGuardPda,
Expand Down Expand Up @@ -89,7 +89,7 @@ test('it transfers SOL to an escrow account and freezes the NFT', async (t) => {
await assertSuccessfulMint(t, umi, { mint, owner: umi.identity });

// And the NFT is frozen.
const asset = await fetchAssetWithPlugins(umi, mint.publicKey);
const asset = await fetchAsset(umi, mint.publicKey);
t.is(isFrozen(asset), true, 'NFT is frozen');

// And cannot be thawed since not all NFTs have been minted.
Expand Down Expand Up @@ -183,14 +183,14 @@ test('it can thaw an NFT once all NFTs are minted', async (t) => {

// And given we minted the only frozen NFT from that candy machine.
const mint = await mintNft(umi, candyMachine, destination, collection);
let asset = await fetchAssetWithPlugins(umi, mint.publicKey);
let asset = await fetchAsset(umi, mint.publicKey);
t.is(isFrozen(asset), true, 'NFT is frozen');

// When we thaw the NFT.
await thawNft(umi, candyMachine, destination, mint.publicKey, collection);

// Then the NFT is thawed.
asset = await fetchAssetWithPlugins(umi, mint.publicKey);
asset = await fetchAsset(umi, mint.publicKey);
t.is(isFrozen(asset), false, 'NFT is thawed');
});

Expand Down Expand Up @@ -379,8 +379,8 @@ test('it can have multiple freeze escrow and reuse the same ones', async (t) =>
// Then all NFTs except for group D have been frozen.
const [tokenA, tokenB, tokenC, tokenD] = await Promise.all(
[mintA, mintB, mintC, mintD].map(
({ publicKey: mint }): Promise<AssetWithPlugins> =>
fetchAssetWithPlugins(umi, mint)
({ publicKey: mint }): Promise<Asset> =>
fetchAsset(umi, mint)
)
);

Expand Down Expand Up @@ -624,7 +624,7 @@ test('it transfers SOL to an escrow account and locks the Programmable NFT', asy
await assertSuccessfulMint(t, umi, { mint, owner: umi.identity });

// And the pNFT is frozen.
const asset = await fetchAssetWithPlugins(umi, mint.publicKey);
const asset = await fetchAsset(umi, mint.publicKey);
t.is(isFrozen(asset), true);

// And cannot be thawed since not all NFTs have been minted.
Expand Down Expand Up @@ -696,7 +696,7 @@ test('it can thaw a Programmable NFT once all NFTs are minted', async (t) => {
)
.sendAndConfirm(umi);

let asset = await fetchAssetWithPlugins(umi, mint.publicKey);
let asset = await fetchAsset(umi, mint.publicKey);
t.is(isFrozen(asset), true, 'asset is frozen');

// When we thaw the locked asset.
Expand All @@ -716,7 +716,7 @@ test('it can thaw a Programmable NFT once all NFTs are minted', async (t) => {
.sendAndConfirm(umi);

// Then the asset is unlocked.
asset = await fetchAssetWithPlugins(umi, mint.publicKey);
asset = await fetchAsset(umi, mint.publicKey);
t.is(isFrozen(asset), false, 'asset is frozen');

// And the freeze escrow ATA account is closed.
Expand Down
18 changes: 9 additions & 9 deletions clients/js/test/defaultGuards/freezeTokenPayment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
Umi,
} from '@metaplex-foundation/umi';
import test, { Assertions } from 'ava';
import { AssetWithPlugins, fetchAssetWithPlugins } from '@metaplex-foundation/mpl-core';
import { Asset, fetchAsset } from '@metaplex-foundation/mpl-core';
import {
addConfigLines,
fetchFreezeEscrow,
Expand Down Expand Up @@ -106,7 +106,7 @@ test('it transfers tokens to an escrow account and freezes the NFT', async (t) =
// Then minting was successful.
await assertSuccessfulMint(t, umi, { mint, owner: umi.identity });

const asset = await fetchAssetWithPlugins(umi, mint.publicKey);
const asset = await fetchAsset(umi, mint.publicKey);
t.is(isFrozen(asset), true);

// And cannot be thawed since not all NFTs have been minted.
Expand Down Expand Up @@ -227,14 +227,14 @@ test('it can thaw an NFT once all NFTs are minted', async (t) => {
destinationAta,
collection
);
let asset = await fetchAssetWithPlugins(umi, mint.publicKey);
let asset = await fetchAsset(umi, mint.publicKey);
t.is(isFrozen(asset), true);

// When we thaw the NFT.
await thawNft(umi, candyMachine, tokenMint, destinationAta, mint.publicKey, collection);

// Then the NFT is thawed.
asset = await fetchAssetWithPlugins(umi, mint.publicKey);
asset = await fetchAsset(umi, mint.publicKey);
t.is(isFrozen(asset), false);
});

Expand Down Expand Up @@ -493,8 +493,8 @@ test('it can have multiple freeze escrow and reuse the same ones', async (t) =>
// Then all NFTs except for group D have been frozen.
const [tokenA, tokenB, tokenC, tokenD] = await Promise.all(
[nftA, nftB, nftC, nftD].map(
({ publicKey: mint }): Promise<AssetWithPlugins> =>
fetchAssetWithPlugins(umi, mint)
({ publicKey: mint }): Promise<Asset> =>
fetchAsset(umi, mint)
)
);

Expand Down Expand Up @@ -791,7 +791,7 @@ test('it transfers tokens to an escrow account and locks the Programmable NFT',
// Then minting was successful.
await assertSuccessfulMint(t, umi, { mint, owner: umi.identity });

const asset = await fetchAssetWithPlugins(umi, mint.publicKey);
const asset = await fetchAsset(umi, mint.publicKey);
t.is(isFrozen(asset), true);

// And cannot be thawed since not all NFTs have been minted.
Expand Down Expand Up @@ -874,7 +874,7 @@ test('it can thaw a Programmable NFT once all NFTs are minted', async (t) => {
)
.sendAndConfirm(umi);

let asset = await fetchAssetWithPlugins(umi, mint.publicKey);
let asset = await fetchAsset(umi, mint.publicKey);
t.is(isFrozen(asset), true);

// When we thaw the locked PNFT.
Expand All @@ -894,7 +894,7 @@ test('it can thaw a Programmable NFT once all NFTs are minted', async (t) => {
)
.sendAndConfirm(umi);

asset = await fetchAssetWithPlugins(umi, mint.publicKey);
asset = await fetchAsset(umi, mint.publicKey);
t.is(isFrozen(asset), false);

// And the freeze escrow ATA account is closed.
Expand Down
4 changes: 2 additions & 2 deletions programs/candy-guard/program/src/guards/freeze_sol_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::*;
use anchor_lang::AccountsClose;
use mpl_candy_machine_core_asset::CandyMachine;
use mpl_core::{
accounts::Asset,
accounts::BaseAsset,
instructions::{
ApprovePluginAuthorityCpiBuilder, AddPluginCpiBuilder, RevokePluginAuthorityCpiBuilder,
UpdatePluginCpiBuilder,
Expand Down Expand Up @@ -510,7 +510,7 @@ pub fn thaw_nft<'info>(
&[bump],
];

let maybe_freeze_plugin = mpl_core::fetch_plugin::<Asset, Freeze>(&asset, PluginType::Freeze);
let maybe_freeze_plugin = mpl_core::fetch_plugin::<BaseAsset, Freeze>(&asset, PluginType::Freeze);

let is_frozen = match maybe_freeze_plugin {
Ok((_, freeze_plugin, _)) => freeze_plugin.frozen,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anchor_lang::prelude::*;
use arrayref::array_ref;
use mpl_core::{self, accounts::Collection, fetch_plugin, instructions::CreateCpiBuilder, types::{PluginType, UpdateDelegate}};
use mpl_core::{self, accounts::BaseCollection, fetch_plugin, instructions::CreateCpiBuilder, types::{PluginType, UpdateDelegate}};
use solana_program::sysvar;

use crate::{
Expand Down Expand Up @@ -71,7 +71,7 @@ pub(crate) fn process_mint_asset(
return err!(CandyError::IncorrectOwner);
}

let (auth, _, _) = fetch_plugin::<Collection, UpdateDelegate>(&accounts.collection, PluginType::UpdateDelegate)?;
let (auth, _, _) = fetch_plugin::<BaseCollection, UpdateDelegate>(&accounts.collection, PluginType::UpdateDelegate)?;

assert_plugin_pubkey_authority(&auth, &accounts.authority_pda.key())?;

Expand Down
8 changes: 4 additions & 4 deletions programs/candy-machine-core/program/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anchor_lang::prelude::*;
use arrayref::array_ref;
use mpl_core::{accounts::Collection, fetch_plugin, instructions::{ApproveCollectionPluginAuthorityCpiBuilder, AddCollectionPluginCpiBuilder, RevokeCollectionPluginAuthorityCpiBuilder }, types::{Authority, Plugin, PluginType, UpdateDelegate}};
use mpl_core::{accounts::BaseCollection, fetch_plugin, instructions::{ApproveCollectionPluginAuthorityCpiBuilder, AddCollectionPluginCpiBuilder, RevokeCollectionPluginAuthorityCpiBuilder }, types::{Authority, Plugin, PluginType, UpdateDelegate}};
use mpl_token_metadata::{
accounts::Metadata,
instructions::{
Expand Down Expand Up @@ -289,7 +289,7 @@ pub fn assert_plugin_pubkey_authority(

pub fn approve_asset_collection_delegate(accounts: ApproveAssetDelegateHelperAccounts) -> Result<()> {
// add UpdateDelegate plugin if it does not exist on the Collection
let maybe_update_plugin = fetch_plugin::<Collection, UpdateDelegate>(&accounts.collection, PluginType::UpdateDelegate);
let maybe_update_plugin = fetch_plugin::<BaseCollection, UpdateDelegate>(&accounts.collection, PluginType::UpdateDelegate);
if maybe_update_plugin.is_err() {
AddCollectionPluginCpiBuilder::new(&accounts.mpl_core_program)
.collection(&accounts.collection)
Expand All @@ -301,7 +301,7 @@ pub fn approve_asset_collection_delegate(accounts: ApproveAssetDelegateHelperAcc
}

// add CM authority to collection if it doesn't exist
let (auth, _, _) = fetch_plugin::<Collection, UpdateDelegate>(&accounts.collection, PluginType::UpdateDelegate)?;
let (auth, _, _) = fetch_plugin::<BaseCollection, UpdateDelegate>(&accounts.collection, PluginType::UpdateDelegate)?;
let auth_to_add = Authority::Pubkey {
address: accounts.authority_pda.key()
};
Expand All @@ -327,7 +327,7 @@ pub fn revoke_asset_collection_delegate(
candy_machine: Pubkey,
signer_bump: u8,
) -> Result<()> {
let maybe_update_delegate_plugin = mpl_core::fetch_plugin::<Collection, UpdateDelegate>(&accounts.collection, PluginType::UpdateDelegate);
let maybe_update_delegate_plugin = mpl_core::fetch_plugin::<BaseCollection, UpdateDelegate>(&accounts.collection, PluginType::UpdateDelegate);

let has_auth = match maybe_update_delegate_plugin {
Ok((auth, _, _)) => auth == Authority::Pubkey {
Expand Down

0 comments on commit 5d1574b

Please sign in to comment.