Skip to content

Commit

Permalink
update from core changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nhanphan committed Mar 18, 2024
1 parent 5d1574b commit 61a3bb1
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 104 deletions.
12 changes: 6 additions & 6 deletions clients/js/test/_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
verifyCollectionV1,
} from '@metaplex-foundation/mpl-token-metadata';
import {
Asset,
fetchAsset,
createCollection as baseCreateCollection,
AssetV1,
fetchAssetV1,
createCollectionV1 as baseCreateCollection,
} from '@metaplex-foundation/mpl-core'
import {
createAssociatedToken,
Expand Down Expand Up @@ -310,9 +310,9 @@ export const assertSuccessfulMint = async (

// Nft.

const nft = await fetchAsset(umi, mint)
const nft = await fetchAssetV1(umi, mint)

t.like(nft, <Asset>{
t.like(nft, <AssetV1>{
publicKey: publicKey(mint),
owner
});
Expand Down Expand Up @@ -372,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: Asset): boolean => asset.freeze?.frozen || false;
export const isFrozen = (asset: AssetV1): boolean => asset.freezeDelegate?.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 { Asset, fetchAsset } from '@metaplex-foundation/mpl-core';
import { AssetV1, fetchAssetV1 } 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 fetchAsset(umi, mint.publicKey);
const asset = await fetchAssetV1(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 fetchAsset(umi, mint.publicKey);
let asset = await fetchAssetV1(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 fetchAsset(umi, mint.publicKey);
asset = await fetchAssetV1(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<Asset> =>
fetchAsset(umi, mint)
({ publicKey: mint }): Promise<AssetV1> =>
fetchAssetV1(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 fetchAsset(umi, mint.publicKey);
const asset = await fetchAssetV1(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 fetchAsset(umi, mint.publicKey);
let asset = await fetchAssetV1(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 fetchAsset(umi, mint.publicKey);
asset = await fetchAssetV1(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 { Asset, fetchAsset } from '@metaplex-foundation/mpl-core';
import { AssetV1, fetchAssetV1 } 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 fetchAsset(umi, mint.publicKey);
const asset = await fetchAssetV1(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 fetchAsset(umi, mint.publicKey);
let asset = await fetchAssetV1(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 fetchAsset(umi, mint.publicKey);
asset = await fetchAssetV1(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<Asset> =>
fetchAsset(umi, mint)
({ publicKey: mint }): Promise<AssetV1> =>
fetchAssetV1(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 fetchAsset(umi, mint.publicKey);
const asset = await fetchAssetV1(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 fetchAsset(umi, mint.publicKey);
let asset = await fetchAssetV1(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 fetchAsset(umi, mint.publicKey);
asset = await fetchAssetV1(umi, mint.publicKey);
t.is(isFrozen(asset), false);

// And the freeze escrow ATA account is closed.
Expand Down
4 changes: 2 additions & 2 deletions clients/js/test/mintV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@metaplex-foundation/umi';
import { generateSignerWithSol } from '@metaplex-foundation/umi-bundle-tests';
import test from 'ava';
import { fetchAsset } from '@metaplex-foundation/mpl-core';
import { fetchAssetV1 } from '@metaplex-foundation/mpl-core';
import {
CandyMachine,
fetchCandyMachine,
Expand Down Expand Up @@ -566,7 +566,7 @@ const drain = async (
)
.sendAndConfirm(umi);

const asset = await fetchAsset(umi, mint.publicKey);
const asset = await fetchAssetV1(umi, mint.publicKey);
indices.push(parseInt(asset.name, 10));
}

Expand Down
4 changes: 2 additions & 2 deletions clients/js/test/setCollectionV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import test from 'ava';

import { setComputeUnitLimit } from '@metaplex-foundation/mpl-toolbox';
import { PluginType, revokeCollectionPluginAuthority } from '@metaplex-foundation/mpl-core';
import { PluginType, revokeCollectionPluginAuthorityV1 } from '@metaplex-foundation/mpl-core';
import {
CandyMachine,
fetchCandyMachine,
Expand Down Expand Up @@ -133,7 +133,7 @@ test.only('it can set the same collection of a candy machine when mint is in pro

// And we remove delegate authority from the collection.

await revokeCollectionPluginAuthority(umi, {
await revokeCollectionPluginAuthorityV1(umi, {
collection: collectionA.publicKey,
authority: collectionUpdateAuthorityA,
pluginType: PluginType.UpdateDelegate,
Expand Down
46 changes: 18 additions & 28 deletions programs/candy-guard/program/src/guards/freeze_sol_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use super::*;
use anchor_lang::AccountsClose;
use mpl_candy_machine_core_asset::CandyMachine;
use mpl_core::{
accounts::BaseAsset,
accounts::BaseAssetV1,
instructions::{
ApprovePluginAuthorityCpiBuilder, AddPluginCpiBuilder, RevokePluginAuthorityCpiBuilder,
UpdatePluginCpiBuilder,
ApprovePluginAuthorityV1CpiBuilder, AddPluginV1CpiBuilder, RevokePluginAuthorityV1CpiBuilder,
UpdatePluginV1CpiBuilder,
},
types::{Authority, Freeze, Plugin, PluginType},
types::{PluginAuthority, FreezeDelegate, Plugin, PluginType},
};

use solana_program::{
Expand Down Expand Up @@ -336,28 +336,18 @@ pub fn freeze_nft(
];

// approves a delegate to lock and transfer the token
AddPluginCpiBuilder::new(&ctx.accounts.mpl_core_program)
AddPluginV1CpiBuilder::new(&ctx.accounts.mpl_core_program)
.asset(&ctx.accounts.asset)
.collection(Some(&ctx.accounts.collection))
.authority(&ctx.accounts.minter)
.payer(Some(&ctx.accounts.payer))
.authority(Some(&ctx.accounts.minter))
.payer(&ctx.accounts.payer)
.system_program(&ctx.accounts.system_program)
.plugin(Plugin::Freeze(Freeze { frozen: true }))
.invoke()?;

ApprovePluginAuthorityCpiBuilder::new(&ctx.accounts.mpl_core_program)
.authority(&ctx.accounts.minter)
.asset(&ctx.accounts.asset)
.collection(Some(&ctx.accounts.collection))
.new_authority(Authority::Pubkey {
.plugin(Plugin::FreezeDelegate(FreezeDelegate { frozen: true }))
.init_authority(PluginAuthority::Pubkey {
address: freeze_pda.key(),
})
.plugin_type(PluginType::Freeze)
.payer(Some(&ctx.accounts.payer))
.system_program(&ctx.accounts.system_program)
.invoke()
.map_err(|error| error.into())

}

/// Helper function to initialize the freeze pda.
Expand Down Expand Up @@ -510,29 +500,29 @@ pub fn thaw_nft<'info>(
&[bump],
];

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

let is_frozen = match maybe_freeze_plugin {
Ok((_, freeze_plugin, _)) => freeze_plugin.frozen,
_ => false,
};

if is_frozen {
UpdatePluginCpiBuilder::new(mpl_core_program)
.authority(freeze_pda)
UpdatePluginV1CpiBuilder::new(mpl_core_program)
.authority(Some(freeze_pda))
.collection(Some(collection))
.payer(Some(&ctx.accounts.payer))
.payer(&ctx.accounts.payer)
.asset(asset)
.plugin(Plugin::Freeze(Freeze { frozen: false }))
.plugin(Plugin::FreezeDelegate(FreezeDelegate { frozen: false }))
.system_program(system_program)
.invoke_signed(&[&signer])?;

RevokePluginAuthorityCpiBuilder::new(mpl_core_program)
.authority(freeze_pda)
RevokePluginAuthorityV1CpiBuilder::new(mpl_core_program)
.authority(Some(freeze_pda))
.collection(Some(collection))
.asset(asset)
.plugin_type(PluginType::Freeze)
.payer(Some(&ctx.accounts.payer))
.plugin_type(PluginType::FreezeDelegate)
.payer(&ctx.accounts.payer)
.system_program(system_program)
.invoke_signed(&[&signer])?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use mpl_token_metadata::MAX_SYMBOL_LENGTH;
use crate::{
approve_asset_collection_delegate, constants::{
AUTHORITY_SEED, HIDDEN_SECTION,
}, state::{CandyMachine, CandyMachineData}, utils::fixed_length_string, AccountVersion, ApproveAssetDelegateHelperAccounts, ApproveMetadataDelegateHelperAccounts
}, state::{CandyMachine, CandyMachineData}, utils::fixed_length_string, AccountVersion, ApproveAssetDelegateHelperAccounts
};

pub fn initialize_v2(
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::BaseCollection, fetch_plugin, instructions::CreateCpiBuilder, types::{PluginType, UpdateDelegate}};
use mpl_core::{self, accounts::BaseCollectionV1, fetch_plugin, instructions::CreateV1CpiBuilder, 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::<BaseCollection, UpdateDelegate>(&accounts.collection, PluginType::UpdateDelegate)?;
let (auth, _, _) = fetch_plugin::<BaseCollectionV1, UpdateDelegate>(&accounts.collection, PluginType::UpdateDelegate)?;

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

Expand Down Expand Up @@ -213,7 +213,7 @@ fn create_and_mint(
.as_ref()
.ok_or(CandyError::MissingInstructionsSysvar)?;

CreateCpiBuilder::new(&accounts.mpl_core_program)
CreateV1CpiBuilder::new(&accounts.mpl_core_program)
.payer(&accounts.payer)
.asset(&accounts.asset)
.owner(Some(&accounts.asset_owner))
Expand Down
Loading

0 comments on commit 61a3bb1

Please sign in to comment.