Add command to add MPL Core Assets to Collections#107
Conversation
…ction Uses mpl-core's updateV2 instruction to set an asset's update authority to a collection, enabling post-creation collection assignment. https://claude.ai/code/session_01QjTrbKjMEQZoKDSzdmM7vV
Summary by CodeRabbit
WalkthroughAdds a new Oclif command Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/commands/core/collection/add.ts`:
- Around line 30-32: The code calls fetchCollection before checking whether the
asset is already collection-bound, causing an unnecessary RPC; change the order
in the add command so you first fetch the asset with
fetchAsset(publicKey(args.asset)) and check its collection membership (e.g.,
asset.collection or equivalent) and only call
fetchCollection(publicKey(args.collection)) if the asset is not already in a
collection; ensure you still use publicKey(args.collection) when needed and keep
existing error/validation logic but move it after the early
collection-membership check to avoid unnecessary network calls.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: d8de3723-376b-4d73-aade-4349bc815e24
📒 Files selected for processing (1)
src/commands/core/collection/add.ts
| const asset = await fetchAsset(umi, publicKey(args.asset)) | ||
| const collection = await fetchCollection(umi, publicKey(args.collection)) | ||
|
|
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Avoid unnecessary RPC on the early-reject path.
At Line 31, fetchCollection is called before checking whether the asset is already collection-bound (Line 33). If the asset is already in a collection, this does extra network work and latency for no benefit.
♻️ Proposed refactor
- const asset = await fetchAsset(umi, publicKey(args.asset))
- const collection = await fetchCollection(umi, publicKey(args.collection))
+ const asset = await fetchAsset(umi, publicKey(args.asset))
if (asset.updateAuthority.type === 'Collection') {
spinner.fail('Asset is already in a collection')
this.error(`Asset ${args.asset} already belongs to collection ${asset.updateAuthority.address}`)
}
+
+ const collection = await fetchCollection(umi, publicKey(args.collection))Also applies to: 33-36
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/commands/core/collection/add.ts` around lines 30 - 32, The code calls
fetchCollection before checking whether the asset is already collection-bound,
causing an unnecessary RPC; change the order in the add command so you first
fetch the asset with fetchAsset(publicKey(args.asset)) and check its collection
membership (e.g., asset.collection or equivalent) and only call
fetchCollection(publicKey(args.collection)) if the asset is not already in a
collection; ensure you still use publicKey(args.collection) when needed and keep
existing error/validation logic but move it after the early
collection-membership check to avoid unnecessary network calls.
Summary
This PR adds a new CLI command that allows users to add existing MPL Core Assets to Collections. The command updates an asset's update authority to point to a collection, effectively associating the asset with that collection.
Key Changes
CollectionAddcommand class insrc/commands/core/collection/add.tscollectionIdandassetIdImplementation Details
updatefunction from@metaplex-foundation/mpl-coreto modify the asset's update authorityhttps://claude.ai/code/session_01QjTrbKjMEQZoKDSzdmM7vV