Skip to content

Commit

Permalink
Update Token Metadata program (#487)
Browse files Browse the repository at this point in the history
* Update Token Metadata program

* Fix build

* Add optional token account to metadata authority
  • Loading branch information
lorisleiva authored Feb 28, 2023
1 parent 2c6980d commit b6d9571
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-swans-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@metaplex-foundation/js': patch
---

Update Token Metadata program
2 changes: 1 addition & 1 deletion packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@metaplex-foundation/mpl-candy-guard": "^0.3.0",
"@metaplex-foundation/mpl-candy-machine": "^5.0.0",
"@metaplex-foundation/mpl-candy-machine-core": "^0.1.2",
"@metaplex-foundation/mpl-token-metadata": "^2.7.0",
"@metaplex-foundation/mpl-token-metadata": "^2.8.6",
"@noble/ed25519": "^1.7.1",
"@noble/hashes": "^1.1.3",
"@solana/spl-token": "^0.3.5",
Expand Down
8 changes: 5 additions & 3 deletions packages/js/src/plugins/nftModule/Authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type TokenMetadataAuthority =
export type TokenMetadataAuthorityMetadata = {
__kind: 'metadata';
updateAuthority: Signer;
token?: PublicKey;
};

/** An approved delegate authority of the metadata account for a given action. */
Expand Down Expand Up @@ -79,7 +80,7 @@ export type ParsedTokenMetadataAuthorization = {
approver?: PublicKey;
/**
* If "delegate" authority, the address of the token record
* or the metdata delegate record PDA depending on the type.
* or the metadata delegate record PDA depending on the type.
*/
delegateRecord?: PublicKey;
/** If any auth rules are provided, the address of the auth rule account. */
Expand Down Expand Up @@ -109,6 +110,7 @@ export const parseTokenMetadataAuthorization = (

if (input.authority.__kind === 'metadata') {
auth.accounts.authority = input.authority.updateAuthority.publicKey;
auth.accounts.token = input.authority.token;
auth.signers.push(input.authority.updateAuthority);
auth.data.authorityType = AuthorityType.Metadata;
} else if (input.authority.__kind === 'metadataDelegate') {
Expand All @@ -122,7 +124,7 @@ export const parseTokenMetadataAuthorization = (
auth.accounts.delegateRecord = delegateRecord;
auth.accounts.approver = approver;
auth.signers.push(input.authority.delegate);
auth.data.authorityType = AuthorityType.Delegate;
auth.data.authorityType = AuthorityType.MetadataDelegate;
} else if (input.authority.__kind === 'tokenDelegate') {
const { delegateRecord, approver, tokenAccount } =
parseTokenMetadataDelegateInput(
Expand All @@ -136,7 +138,7 @@ export const parseTokenMetadataAuthorization = (
auth.accounts.delegateRecord = delegateRecord;
auth.accounts.approver = approver;
auth.signers.push(input.authority.delegate);
auth.data.authorityType = AuthorityType.Delegate;
auth.data.authorityType = AuthorityType.TokenDelegate;
} else if (input.authority.__kind === 'holder') {
auth.accounts.authority = input.authority.owner.publicKey;
auth.accounts.token = input.authority.token;
Expand Down
9 changes: 8 additions & 1 deletion packages/js/src/plugins/nftModule/DelegateType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ import { UnreachableCaseError } from '@/errors';
export type TokenDelegateType =
| 'StandardV1'
| 'TransferV1'
| 'LockedTransferV1'
| 'SaleV1'
| 'UtilityV1'
| 'StakingV1';
export type MetadataDelegateType =
// | 'AuthorityV1'
| 'CollectionV1'
// | 'UseV1'
| 'UpdateV1';
| 'UpdateV1'
| 'ProgrammableConfigV1';

const tokenDelegateRoleMap: Record<TokenDelegateType, TokenDelegateRole> = {
StandardV1: TokenDelegateRole.Standard,
TransferV1: TokenDelegateRole.Transfer,
LockedTransferV1: TokenDelegateRole.LockedTransfer,
SaleV1: TokenDelegateRole.Sale,
UtilityV1: TokenDelegateRole.Utility,
StakingV1: TokenDelegateRole.Staking,
Expand All @@ -34,13 +37,15 @@ const metadataDelegateRoleMap: Record<
CollectionV1: MetadataDelegateRole.Collection,
// UseV1: MetadataDelegateRole.Use,
UpdateV1: MetadataDelegateRole.Update,
ProgrammableConfigV1: MetadataDelegateRole.ProgrammableConfig,
};

const metadataDelegateSeedMap: Record<MetadataDelegateRole, string> = {
[MetadataDelegateRole.Authority]: 'authority_delegate',
[MetadataDelegateRole.Collection]: 'collection_delegate',
[MetadataDelegateRole.Use]: 'use_delegate',
[MetadataDelegateRole.Update]: 'update_delegate',
[MetadataDelegateRole.ProgrammableConfig]: 'programmable_config_delegate',
};

const delegateCustomDataMap: Record<
Expand All @@ -52,12 +57,14 @@ const delegateCustomDataMap: Record<
CollectionV1: false,
// UseV1: false,
UpdateV1: false,
ProgrammableConfigV1: false,
// Token
StandardV1: true,
TransferV1: true,
SaleV1: true,
UtilityV1: true,
StakingV1: true,
LockedTransferV1: true,
};

export const getTokenDelegateRole = (
Expand Down
5 changes: 5 additions & 0 deletions packages/js/test/plugins/nftModule/updateNft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ test('[nftModule] it can add rulesets to programmable NFTs', async (t: Test) =>
await mx.nfts().update({
nftOrSft: nft,
ruleSet: ruleSet.publicKey,
authority: {
__kind: 'metadata',
updateAuthority: mx.identity(),
token: nft.token.address,
},
});

// Then the updated NFT has a new programmable configs containing that ruleset.
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

Binary file modified programs/mpl_token_metadata.so
Binary file not shown.

0 comments on commit b6d9571

Please sign in to comment.