Skip to content

Adding assets to a collection as another different authority #208

@meditatingsloth

Description

@meditatingsloth

My goal is to allow many users to add assets to a collection, or allow the collection authority to add assets from other users with their permission.

This would be fine if we just wanted one other user to be able to add assets to the collection

// Works
test('it can add asset to collection as collection update delegate', async (t) => {
  const umi = await createUmi();
  const assetOwner = umi.identity;
  const collectionUmi = await createUmi();

  const assetSigner = generateSigner(umi);
  const assetAddress = assetSigner.publicKey;
  await createV2(umi, {
    asset: assetSigner,
    name: 'My Asset',
    uri: 'https://example.com/my-asset.json',
  }).sendAndConfirm(umi);

  const collectionSigner = generateSigner(collectionUmi);
  const collectionAddress = collectionSigner.publicKey;
  await createCollection(collectionUmi, {
    collection: collectionSigner,
    name: 'My Collection',
    uri: 'https://example.com/my-collection.json',
  }).sendAndConfirm(collectionUmi);

  await addCollectionPlugin(collectionUmi, {
    collection: collectionAddress,
    plugin: {
      type: 'UpdateDelegate',
      authority: { type: 'Address', address: assetOwner.publicKey },
      additionalDelegates: [],
    },
  }).sendAndConfirm(collectionUmi);

  await updateV2(umi, {
    asset: assetAddress,
    newCollection: collectionAddress,
    newUpdateAuthority: updateAuthority('Collection', [collectionAddress]),
  }).sendAndConfirm(umi);

  const asset = await fetchAssetV1(umi, assetAddress);
  t.like(asset, <Partial<AssetV1>>{
    owner: assetOwner.publicKey,
    updateAuthority: {
      type: 'Collection',
      address: collectionAddress,
    },
  });
});

The additionalDelegates array seems to be broken, as addresses within cannot add assets to the collection

// Does not work with additionalDelegates
test('it can add asset to collection as collection additional delegate', async (t) => {
  const umi = await createUmi();
  const assetOwner = umi.identity;
  const collectionUmi = await createUmi();

  const assetSigner = generateSigner(umi);
  const assetAddress = assetSigner.publicKey;
  await createV2(umi, {
    asset: assetSigner,
    name: 'My Asset',
    uri: 'https://example.com/my-asset.json',
  }).sendAndConfirm(umi);

  const collectionSigner = generateSigner(collectionUmi);
  const collectionAddress = collectionSigner.publicKey;
  await createCollection(collectionUmi, {
    collection: collectionSigner,
    name: 'My Collection',
    uri: 'https://example.com/my-collection.json',
  }).sendAndConfirm(collectionUmi);

  await addCollectionPlugin(collectionUmi, {
    collection: collectionAddress,
    plugin: {
      type: 'UpdateDelegate',
      // Some other address
      authority: { type: 'Address', address: generateSigner(umi).publicKey },
      // Who we want to be able to add collection assets
      additionalDelegates: [assetOwner.publicKey],
    },
  }).sendAndConfirm(collectionUmi);

  await updateV2(umi, {
    asset: assetAddress,
    newCollection: collectionAddress,
    newUpdateAuthority: updateAuthority('Collection', [collectionAddress]),
  }).sendAndConfirm(umi);

  const asset = await fetchAssetV1(umi, assetAddress);
  t.like(asset, <Partial<AssetV1>>{
    owner: assetOwner.publicKey,
    updateAuthority: {
      type: 'Collection',
      address: collectionAddress,
    },
  });
});

It appears that assets do not allow an asset delegate to add it to a collection, so we can't add assets as the collection owner.

// Does not work
test('it can add asset to collection as collection owner', async (t) => {
  const umi = await createUmi();
  const assetOwner = umi.identity;
  const collectionUmi = await createUmi();
  const collectionOwner = collectionUmi.identity;

  const assetSigner = generateSigner(umi);
  await createV2(umi, {
    asset: assetSigner,
    name: 'My Asset',
    uri: 'https://example.com/my-asset.json',
  }).sendAndConfirm(umi);

  const collectionSigner = generateSigner(collectionUmi);
  const collectionAddress = collectionSigner.publicKey;
  await createCollection(collectionUmi, {
    collection: collectionSigner,
    name: 'My Collection',
    uri: 'https://example.com/my-collection.json',
  }).sendAndConfirm(collectionUmi);

  await addPlugin(umi, {
    asset: assetSigner.publicKey,
    plugin: {
      type: 'UpdateDelegate',
      authority: { type: 'Address', address: collectionOwner.publicKey },
      additionalDelegates: [],
    },
  }).sendAndConfirm(umi);

  await updateV2(collectionUmi, {
    asset: assetSigner.publicKey,
    authority: collectionOwner,
    newCollection: collectionAddress,
    newUpdateAuthority: updateAuthority('Collection', [collectionAddress]),
  }).sendAndConfirm(collectionUmi);

  const asset = await fetchAssetV1(umi, assetSigner.publicKey);
  t.like(asset, <Partial<AssetV1>>{
    owner: assetOwner.publicKey,
    updateAuthority: {
      type: 'Collection',
      address: collectionAddress,
    },
  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions