Skip to content

Commit

Permalink
feat(plugins): add edition plugins data conversion (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
shotgunofdeath authored May 16, 2024
1 parent 07b7452 commit b87ec5e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/file-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ js_client: &js_client
- ".github/test-js-client.yml"
- ".github/file-filters.yml"
- ".github/.env"
- "/**"
- "**/"
19 changes: 18 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import {
DasApiAssetInterface,
} from '@metaplex-foundation/digital-asset-standard-api';
import {
AddBlocker,
AssetV1,
Attributes,
BaseUpdateAuthority,
BurnDelegate,
CollectionV1,
Edition,
FreezeDelegate,
getPluginSerializer,
ImmutableMetadata,
Key,
mapPlugin,
MasterEdition,
MPL_CORE_PROGRAM_ID,
PermanentBurnDelegate,
PermanentFreezeDelegate,
Expand Down Expand Up @@ -123,14 +127,23 @@ function dasPluginDataToCorePluginData(
| PermanentFreezeDelegate
| Attributes
| PermanentTransferDelegate
| PermanentBurnDelegate {
| PermanentBurnDelegate
| Edition
| MasterEdition
| AddBlocker
| ImmutableMetadata {
// TODO: Refactor when DAS types are defined
return (({
basis_points,
creators,
rule_set,
attribute_list,
frozen,
additional_delegates,
number,
max_supply,
name,
uri,
}) => ({
...(basis_points !== undefined ? { basisPoints: basis_points } : {}),
...(creators !== undefined
Expand All @@ -147,6 +160,10 @@ function dasPluginDataToCorePluginData(
...(additional_delegates !== undefined
? { additionalDelegates: additional_delegates }
: {}),
...(number !== undefined ? { number } : {}),
...(max_supply !== undefined ? { maxSupply: max_supply } : {}),
...(name !== undefined ? { name } : {}),
...(uri !== undefined ? { uri } : {}),
}))(dasPluginData);
}

Expand Down
58 changes: 35 additions & 23 deletions test/_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
PluginAuthorityPairArgs,
fetchCollectionV1,
createCollectionV1,
updatePluginAuthority,
} from '@metaplex-foundation/mpl-core';
import { dasApi } from '@metaplex-foundation/digital-asset-standard-api';
import { testPlugins } from '@metaplex-foundation/umi-bundle-tests';
Expand Down Expand Up @@ -104,25 +105,11 @@ const createCollection = async (
return fetchCollectionV1(umi, publicKey(collection));
};

function getPluginsForCreation(
transferDelegateAuthority: PublicKey,
payer: PublicKey
) {
function getPluginsForCreation(payer: PublicKey) {
return [
pluginAuthorityPair({
authority: addressPluginAuthority(transferDelegateAuthority),
type: 'TransferDelegate',
}),
pluginAuthorityPair({
type: 'BurnDelegate',
}),
pluginAuthorityPair({
type: 'UpdateDelegate',
}),
pluginAuthorityPair({
type: 'FreezeDelegate',
data: { frozen: false },
}),
pluginAuthorityPair({
type: 'Attributes',
data: { attributeList: [{ key: 'some key', value: 'some value' }] },
Expand Down Expand Up @@ -176,10 +163,18 @@ export async function createDasTestAssetOrCollection({
updateAuthority,
collection: assetAddress,
payer,
plugins: getPluginsForCreation(
transferDelegateAuthority.publicKey,
payer.publicKey
),
plugins: [
...getPluginsForCreation(payer.publicKey),
pluginAuthorityPair({
type: 'MasterEdition',
data: {
maxSupply: 100,
name: 'Test Master Edition Name',
uri: 'https://example.com/das-collection-master-edition',
},
authority: updatePluginAuthority(),
}),
],
});
} else {
asset = await createAsset(umi, {
Expand All @@ -188,10 +183,27 @@ export async function createDasTestAssetOrCollection({
asset: assetAddress,
payer,
collection,
plugins: getPluginsForCreation(
transferDelegateAuthority.publicKey,
payer.publicKey
),
plugins: [
...getPluginsForCreation(payer.publicKey),
pluginAuthorityPair({
authority: addressPluginAuthority(
transferDelegateAuthority.publicKey
),
type: 'TransferDelegate',
}),
pluginAuthorityPair({
type: 'BurnDelegate',
authority: updatePluginAuthority(),
}),
pluginAuthorityPair({
type: 'FreezeDelegate',
data: { frozen: false },
}),
pluginAuthorityPair({
type: 'Edition',
data: { number: 2 },
}),
],
});
}

Expand Down
40 changes: 40 additions & 0 deletions test/das.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
dasTestAssetInCollectionPubKey,
dasTestCollection2PubKey,
} from './_expectedData';
import { fetchAssetV1, fetchCollectionV1 } from '@metaplex-foundation/mpl-core';

test('das: it can search assets', async (t) => {
// Given an Umi instance with DAS API
Expand Down Expand Up @@ -123,3 +124,42 @@ test('das: it can fetch collections by update authority if update authority is n
);
t.like(collection, dasTestCollection2);
});

test('das: it can convert a DAS asset with the edition plugin to the MPL Core asset structure', async (t) => {
// Given an Umi instance with DAS API and an asset with the edition plugin
const umi = createUmiWithDas(DAS_API_ENDPOINT);
const assetPb = publicKey('94tbAopaajgjRndvvK31TBqNTkNbJdzifwW4ec7iqpYh');

// Then the asset data parsed from DAS
const assets = await das.fetchAssetsByOwner(umi, {
owner: publicKey('EBgC18R6zKNic1CLYKYEy3SMSz4zweymeqrMHkXeqpag'),
});
const assetDas = assets.find((a) => a.publicKey === assetPb) ?? {};

// Then the asset data fetched via fetchAssetV1
const assetMplCore = await fetchAssetV1(umi, assetPb);

// Assets data structure is the same from both sources
t.like(assetMplCore, assetDas);
});

test('das: it can convert a DAS collection with the master edition plugin to the MPL Core collection structure', async (t) => {
// Given an Umi instance with DAS API and a collection with the master edition plugin
const umi = createUmiWithDas(DAS_API_ENDPOINT);
const collectionPubKey = publicKey(
'D6kHt7XgMLtqBWSSf7QNc6YijQn8vqBwHb2ZF3GHnv7P'
);

// Then the collection data parsed from DAS
const collections = await das.fetchCollectionsByUpdateAuthority(umi, {
updateAuthority: publicKey('EBgC18R6zKNic1CLYKYEy3SMSz4zweymeqrMHkXeqpag'),
});
const collectionDas =
collections.find((a) => a.publicKey === collectionPubKey) ?? {};

// Then the collection data fetched via fetchCollectionV1
const collectionMplCore = await fetchCollectionV1(umi, collectionPubKey);

// Collections data structure is the same from both sources
t.like(collectionMplCore, collectionDas);
});

0 comments on commit b87ec5e

Please sign in to comment.