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

add cm authority as additional delegate #12

Merged
merged 3 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
108 changes: 80 additions & 28 deletions programs/candy-guard/Cargo.lock

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

2 changes: 1 addition & 1 deletion programs/candy-guard/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test-bpf = []
[dependencies]
anchor-lang = "0.28.0"
arrayref = "0.3.6"
mpl-core = { version = "0.6.1" }
mpl-core = { version = "0.8.0" }
mpl-core-candy-guard-derive = { path = "../macro", version = "0.2.1" }
mpl-core-candy-machine-core = { path = "../../candy-machine-core/program", version = "0.2.0", features = [
"cpi",
Expand Down
4 changes: 2 additions & 2 deletions programs/candy-guard/program/src/guards/asset_burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ impl Condition for AssetBurn {
assert_keys_equal(&collection_info.key(), &self.required_collection)
.map_err(|_| CandyGuardError::InvalidNftCollection)?;

let asset = Asset::try_from(asset_info)?;
assert_keys_equal(&asset.base.owner, ctx.accounts.minter.key)
let asset = BaseAssetV1::try_from(asset_info)?;
assert_keys_equal(&asset.owner, ctx.accounts.minter.key)
.map_err(|_| CandyGuardError::IncorrectOwner)?;

ctx.indices.insert("asset_burn_index", index);
Expand Down
6 changes: 3 additions & 3 deletions programs/candy-guard/program/src/guards/asset_burn_multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ impl Condition for AssetBurnMulti {
while i < usize::from(self.num) {
asset_account = try_get_account_info(ctx.accounts.remaining, index + i + 1)?;

asset = Asset::try_from(asset_account)?;
asset = BaseAssetV1::try_from(asset_account)?;

match asset.base.update_authority {
match asset.update_authority {
UpdateAuthority::Collection(pubkey) => {
assert_keys_equal(&pubkey, collection_account.key)
.map_err(|_| CandyGuardError::InvalidNftCollection)?;
Expand All @@ -57,7 +57,7 @@ impl Condition for AssetBurnMulti {

assert_keys_equal(collection_account.key, &self.required_collection)
.map_err(|_| CandyGuardError::InvalidNftCollection)?;
assert_keys_equal(&asset.base.owner, ctx.accounts.minter.key)
assert_keys_equal(&asset.owner, ctx.accounts.minter.key)
.map_err(|_| CandyGuardError::IncorrectOwner)?;

i += 1;
Expand Down
4 changes: 2 additions & 2 deletions programs/candy-guard/program/src/guards/asset_mint_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ impl Condition for AssetMintLimit {
// verifies that we got the correct Core Asset
verify_core_collection(asset_account, &self.required_collection)?;

let asset = Asset::try_from(asset_account)?;
if assert_keys_equal(&asset.base.owner, ctx.accounts.minter.key).is_err() {
let asset = BaseAssetV1::try_from(asset_account)?;
if assert_keys_equal(&asset.owner, ctx.accounts.minter.key).is_err() {
return err!(CandyGuardError::IncorrectOwner);
}

Expand Down
4 changes: 2 additions & 2 deletions programs/candy-guard/program/src/guards/asset_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ impl Condition for AssetPayment {
assert_keys_equal(&collection_info.key(), &self.required_collection)
.map_err(|_| CandyGuardError::InvalidNftCollection)?;

let asset = Asset::try_from(asset_info)?;
assert_keys_equal(&asset.base.owner, ctx.accounts.minter.key)
let asset = BaseAssetV1::try_from(asset_info)?;
assert_keys_equal(&asset.owner, ctx.accounts.minter.key)
.map_err(|_| CandyGuardError::IncorrectOwner)?;

ctx.indices.insert("asset_payment_index", index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ impl Condition for AssetPaymentMulti {
while i < usize::from(self.num) {
asset_account = try_get_account_info(ctx.accounts.remaining, index + i + 2)?;

asset = Asset::try_from(asset_account)?;
match asset.base.update_authority {
asset = BaseAssetV1::try_from(asset_account)?;
match asset.update_authority {
UpdateAuthority::Collection(pubkey) => {
assert_keys_equal(&pubkey, collection_account.key)
.map_err(|_| CandyGuardError::InvalidNftCollection)?;
Expand All @@ -62,7 +62,7 @@ impl Condition for AssetPaymentMulti {

assert_keys_equal(collection_account.key, &self.required_collection)
.map_err(|_| CandyGuardError::InvalidNftCollection)?;
assert_keys_equal(&asset.base.owner, ctx.accounts.minter.key)
assert_keys_equal(&asset.owner, ctx.accounts.minter.key)
.map_err(|_| CandyGuardError::IncorrectOwner)?;

i += 1;
Expand Down
6 changes: 3 additions & 3 deletions programs/candy-guard/program/src/guards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::collections::BTreeMap;

pub use anchor_lang::prelude::*;
use mpl_core::{
accounts::BaseAssetV1,
types::{PluginAuthorityPair, UpdateAuthority},
Asset,
};

pub use crate::{errors::CandyGuardError, state::GuardSet};
Expand Down Expand Up @@ -221,9 +221,9 @@ pub fn get_account_info<T>(remaining_accounts: &[T], index: usize) -> Option<&T>
}

pub fn verify_core_collection(asset: &AccountInfo, collection: &Pubkey) -> Result<()> {
let asset = Asset::try_from(asset)?;
let asset = BaseAssetV1::try_from(asset)?;

match asset.base.update_authority {
match asset.update_authority {
UpdateAuthority::Collection(pubkey) => {
assert_keys_equal(&pubkey, collection)
.map_err(|_| CandyGuardError::InvalidNftCollection)?;
Expand Down
Loading
Loading