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

Adding assets to a collection as another different authority #208

Open
meditatingsloth opened this issue Jan 3, 2025 · 0 comments
Open

Comments

@meditatingsloth
Copy link

meditatingsloth commented Jan 3, 2025

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,
    },
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant