Skip to content

Commit

Permalink
Fixing self-revoke (#157)
Browse files Browse the repository at this point in the history
* Adding resizing of metadata and edition accounts.

* Integrating close of ownerless accounts.

* Adding auth to fungibles.

* Updating based on first round of feedback.

* Minor tweaks and adding more thorough tests.

* Finishing resize tests.

* Fix formatting.

* Fixing bad test function.

* Minor fixes.

* Adding ignores.

* TS Ignore

* Ignoring DeadlineExceeded tests.

* Updating based on audit.

* Update clients.

* Add couple last tests

* Fixing self revoke for metadata delegates.

---------

Co-authored-by: Michael Danenberg <[email protected]>
  • Loading branch information
blockiosaurus and danenbm authored Dec 22, 2024
1 parent 703a448 commit 3469dd9
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 28 deletions.
24 changes: 12 additions & 12 deletions clients/js/test/close/fungible.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ test.skip('it can close ownerless metadata for a fungible with zero supply and n

t.deepEqual(await umi.rpc.getAccount(asset.metadata.publicKey), <
MaybeRpcAccount
>{
publicKey: asset.metadata.publicKey,
exists: false,
});
>{
publicKey: asset.metadata.publicKey,
exists: false,
});
t.deepEqual(await umi.rpc.getBalance(asset.metadata.publicKey), lamports(0));

const lamportsAfter = await umi.rpc.getBalance(closeDestination);
Expand Down Expand Up @@ -139,10 +139,10 @@ test.skip('it can close ownerless metadata for a fungible with zero supply and m

t.deepEqual(await umi.rpc.getAccount(asset.metadata.publicKey), <
MaybeRpcAccount
>{
publicKey: asset.metadata.publicKey,
exists: false,
});
>{
publicKey: asset.metadata.publicKey,
exists: false,
});
t.deepEqual(await umi.rpc.getBalance(asset.metadata.publicKey), lamports(0));

const lamportsAfter = await umi.rpc.getBalance(closeDestination);
Expand Down Expand Up @@ -201,10 +201,10 @@ test.skip('it can close ownerless metadata for a fungible asset with zero supply

t.deepEqual(await umi.rpc.getAccount(asset.metadata.publicKey), <
MaybeRpcAccount
>{
publicKey: asset.metadata.publicKey,
exists: false,
});
>{
publicKey: asset.metadata.publicKey,
exists: false,
});
t.deepEqual(await umi.rpc.getBalance(asset.metadata.publicKey), lamports(0));

const lamportsAfter = await umi.rpc.getBalance(closeDestination);
Expand Down
16 changes: 8 additions & 8 deletions clients/js/test/close/nonFungible.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ test.skip('it can close ownerless metadata for a non-fungible with zero supply',

t.deepEqual(await umi.rpc.getAccount(asset.metadata.publicKey), <
MaybeRpcAccount
>{
publicKey: asset.metadata.publicKey,
exists: false,
});
>{
publicKey: asset.metadata.publicKey,
exists: false,
});
t.deepEqual(await umi.rpc.getBalance(asset.metadata.publicKey), lamports(0));

const lamportsAfter = await umi.rpc.getBalance(closeDestination);
Expand Down Expand Up @@ -268,10 +268,10 @@ test.skip('it can close ownerless metadata for a non-fungible edition with zero

t.deepEqual(await umi.rpc.getAccount(asset.metadata.publicKey), <
MaybeRpcAccount
>{
publicKey: asset.metadata.publicKey,
exists: false,
});
>{
publicKey: asset.metadata.publicKey,
exists: false,
});
t.deepEqual(await umi.rpc.getBalance(asset.metadata.publicKey), lamports(0));

const lamportsAfter = await umi.rpc.getBalance(closeDestination);
Expand Down
38 changes: 38 additions & 0 deletions clients/js/test/revokeCollectionV1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,41 @@ NON_EDITION_TOKEN_STANDARDS.forEach((tokenStandard) => {
t.false(await umi.rpc.accountExists(metadataDelegateRecord));
});
});

NON_EDITION_TOKEN_STANDARDS.forEach((tokenStandard) => {
test(`it can self-revoke a collection delegate for a ${tokenStandard}`, async (t) => {
// Given an asset with an approved collection delegate.
const umi = await createUmi();
const updateAuthority = generateSigner(umi);
const { publicKey: mint } = await createDigitalAssetWithToken(umi, {
authority: updateAuthority,
tokenStandard: TokenStandard[tokenStandard],
});
const collectionDelegate = generateSigner(umi);
await delegateCollectionV1(umi, {
mint,
authority: updateAuthority,
delegate: collectionDelegate.publicKey,
tokenStandard: TokenStandard[tokenStandard],
}).sendAndConfirm(umi);
const [metadataDelegateRecord] = findMetadataDelegateRecordPda(umi, {
mint,
delegateRole: MetadataDelegateRole.Collection,
delegate: collectionDelegate.publicKey,
updateAuthority: updateAuthority.publicKey,
});
t.true(await umi.rpc.accountExists(metadataDelegateRecord));

// When we revoke the collection delegate.
await revokeCollectionV1(umi, {
mint,
authority: collectionDelegate,
updateAuthority: updateAuthority.publicKey,
delegate: collectionDelegate.publicKey,
tokenStandard: TokenStandard[tokenStandard],
}).sendAndConfirm(umi);

// Then the metadata delegate record was deleted.
t.false(await umi.rpc.accountExists(metadataDelegateRecord));
});
});
16 changes: 8 additions & 8 deletions programs/token-metadata/program/src/processor/delegate/revoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,21 @@ fn get_delegate_record_update_authority(
delegate_record_info: &AccountInfo,
authority: &Pubkey,
) -> Result<Pubkey, ProgramError> {
let delegate_record_update_authority = match delegate_scenario {
let (delegate, delegate_record_update_authority) = match delegate_scenario {
DelegateScenario::Metadata(_) => {
MetadataDelegateRecord::from_account_info(delegate_record_info)
.map_err(|_| MetadataError::DelegateNotFound)?
.update_authority
let record = MetadataDelegateRecord::from_account_info(delegate_record_info)
.map_err(|_| MetadataError::DelegateNotFound)?;
(record.delegate, record.update_authority)
}
DelegateScenario::Holder(_) => {
HolderDelegateRecord::from_account_info(delegate_record_info)
.map_err(|_| MetadataError::DelegateNotFound)?
.update_authority
let record = HolderDelegateRecord::from_account_info(delegate_record_info)
.map_err(|_| MetadataError::DelegateNotFound)?;
(record.delegate, record.update_authority)
}
_ => return Err(MetadataError::InvalidDelegateRole.into()),
};

if cmp_pubkeys(&delegate_record_update_authority, authority) {
if cmp_pubkeys(&delegate, authority) {
Ok(delegate_record_update_authority)
} else {
Err(MetadataError::InvalidDelegate.into())
Expand Down
48 changes: 48 additions & 0 deletions programs/token-metadata/program/tests/utils/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,30 @@ impl Metadata {
#[cfg(feature = "padded")]
upsize_metadata(context, &self.pubkey).await;

#[cfg(feature = "resize")]
{
let tx = Transaction::new_signed_with_payer(
&[ResizeBuilder::new()
.metadata(self.pubkey)
.edition(find_master_edition_account(&self.mint.pubkey()).0)
.mint(self.mint.pubkey())
.payer(context.payer.pubkey())
.authority(context.payer.pubkey())
.token(self.token.pubkey())
.system_program(solana_program::system_program::ID)
.build()
.unwrap()
.instruction()],
Some(&context.payer.pubkey()),
&[&context.payer],
context.last_blockhash,
);

assert_before_metadata(context, self.pubkey).await;
context.banks_client.process_transaction(tx).await?;
assert_after_metadata(context, self.pubkey).await;
}

Ok(())
}

Expand Down Expand Up @@ -316,6 +340,30 @@ impl Metadata {
#[cfg(feature = "padded")]
upsize_metadata(context, &self.pubkey).await;

#[cfg(feature = "resize")]
{
let tx = Transaction::new_signed_with_payer(
&[ResizeBuilder::new()
.metadata(self.pubkey)
.edition(find_master_edition_account(&self.mint.pubkey()).0)
.mint(self.mint.pubkey())
.payer(context.payer.pubkey())
.authority(context.payer.pubkey())
.token(self.token.pubkey())
.system_program(solana_program::system_program::ID)
.build()
.unwrap()
.instruction()],
Some(&context.payer.pubkey()),
&[&context.payer],
context.last_blockhash,
);

assert_before_metadata(context, self.pubkey).await;
context.banks_client.process_transaction(tx).await?;
assert_after_metadata(context, self.pubkey).await;
}

Ok(())
}

Expand Down

0 comments on commit 3469dd9

Please sign in to comment.