Skip to content

Commit 34e23c5

Browse files
authored
Enhance the re-design register method (#630)
* fix: update error handling and documentation for IP asset registration * docs: enhance IP asset registration documentation with detailed usage examples and clarify license terms and royalty shares handling * test: update error messages and add tests for optional parameters in IP asset registration * test: refactor and enhance integration tests for IP asset registration with minted NFTs * fix: update documentation for royaltyShares in RegisterIpAssetRequest to clarify association with revenue distribution
1 parent a5ec4c0 commit 34e23c5

File tree

4 files changed

+644
-180
lines changed

4 files changed

+644
-180
lines changed

packages/core-sdk/src/resources/ipAsset.ts

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,22 +1667,64 @@ export class IPAssetClient {
16671667
}
16681668
}
16691669
/**
1670-
* Register an IP asset, supporting both minted and mint-on-demand NFTs, with optional license terms and royalty shares.
1671-
* Supports the following workflows:
1672-
* - {@link registerIPAndAttachLicenseTermsAndDistributeRoyaltyTokens}
1673-
* - {@link registerIpAndAttachPilTerms}
1674-
* - {@link register}
1675-
* - {@link mintAndRegisterIpAndAttachPilTermsAndDistributeRoyaltyTokens}
1676-
* - {@link mintAndRegisterIpAssetWithPilTerms}
1677-
* - {@link mintAndRegisterIp}
1670+
* Register an IP asset, supporting both minted and mint-on-demand NFTs, with optional `licenseTermsData` and `royaltyShares`.
16781671
*
1679-
* The method supports automatic token handling for minting fees:
1672+
* This method automatically selects and calls the appropriate workflow from 6 available methods based on your input parameters.
1673+
* Here are three common usage patterns:
1674+
*
1675+
* **1. Minted NFT with License Terms and Royalty Distribution:**
1676+
* ```typescript
1677+
* const result = await client.ipAsset.registerIpAsset({
1678+
* nft: { type: "minted", nftContract: "0x...", tokenId: 1n },
1679+
* licenseTermsData: [
1680+
* {
1681+
* terms: PILFlavor.commercialRemix({
1682+
* defaultMintingFee: 10000n,
1683+
* commercialRevShare: 100,
1684+
* currency: "0x..."
1685+
* })
1686+
* }
1687+
* ],
1688+
* royaltyShares: [
1689+
* { recipient: "0x...", percentage: 100 }
1690+
* ]
1691+
* });
1692+
* ```
1693+
*
1694+
* **2. Minted NFT with Basic License Terms:**
1695+
* ```typescript
1696+
* const result = await client.ipAsset.registerIpAsset({
1697+
* nft: { type: "minted", nftContract: "0x...", tokenId: 1n },
1698+
* licenseTermsData: [
1699+
* {
1700+
* terms: PILFlavor.nonCommercialSocialRemixing()
1701+
* }
1702+
* ]
1703+
* });
1704+
* ```
1705+
*
1706+
* **3. Mint NFT with IP Asset:**
1707+
* ```typescript
1708+
* const result = await client.ipAsset.registerIpAsset({
1709+
* nft: { type: "mint", spgNftContract: "0x...", recipient: "0x...", allowDuplicates: false },
1710+
* });
1711+
* ```
1712+
*
1713+
* **Supported Workflows (6 methods automatically selected based on parameters):**
1714+
* - {@link registerIPAndAttachLicenseTermsAndDistributeRoyaltyTokens} - Register IP with license terms and royalty distribution
1715+
* - {@link registerIpAndAttachPilTerms} - Register IP with license terms
1716+
* - {@link register} - Register basic IP asset
1717+
* - {@link mintAndRegisterIpAndAttachPilTermsAndDistributeRoyaltyTokens} - Mint NFT and register IP with license terms and royalty distribution
1718+
* - {@link mintAndRegisterIpAssetWithPilTerms} - Mint NFT and register IP with license terms
1719+
* - {@link mintAndRegisterIp} - Mint NFT and register basic IP asset
1720+
*
1721+
* **Automatic Token Handling:**
16801722
* - If the wallet's IP token balance is insufficient to cover minting fees, it automatically wraps native IP tokens into WIP tokens.
16811723
* - It checks allowances for all required spenders and automatically approves them if their current allowance is lower than needed.
16821724
* - These automatic processes can be configured through the `wipOptions` parameter to control behavior like multicall usage and approval settings.
16831725
*
16841726
* @throws {Error} If the NFT type is invalid.
1685-
* @throws {Error} If royalty shares are required when registering IP with license terms data.
1727+
* @throws {Error} If `licenseTermsData` is not provided when `royaltyShares` are specified.
16861728
*
16871729
*/
16881730
public async registerIpAsset<T extends RegisterIpAssetRequest<MintedNFT | MintNFT>>(
@@ -1693,7 +1735,7 @@ export class IPAssetClient {
16931735

16941736
// Validate royalty shares without license terms
16951737
if (royaltyShares && !licenseTermsData) {
1696-
throw new Error("Royalty shares are required when registering IP with license terms data.");
1738+
throw new Error("License terms data must be provided when royalty shares are specified.");
16971739
}
16981740

16991741
if (nft.type === "minted") {

packages/core-sdk/src/types/resources/ipAsset.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,11 +611,86 @@ export type MintedNFT = {
611611
nftContract: Address;
612612
tokenId: TokenIdInput;
613613
};
614+
/**
615+
* Request configuration for registering IP assets with flexible licensing and royalty options.
616+
*
617+
* @template T - The NFT type (MintNFT and MintedNFT)
618+
*
619+
* @example
620+
* **Basic IP Registration:**
621+
* ```typescript
622+
* const request: RegisterIpAssetRequest<MintedNFT> = {
623+
* nft: {
624+
* type: "minted",
625+
* nftContract: "0x1234567890123456789012345678901234567890",
626+
* tokenId: 1n
627+
* }
628+
* };
629+
* ```
630+
*
631+
* @example
632+
* **IP Registration with License Terms:**
633+
* ```typescript
634+
* const request: RegisterIpAssetRequest<MintedNFT> = {
635+
* nft: {
636+
* type: "minted",
637+
* nftContract: "0x1234567890123456789012345678901234567890",
638+
* tokenId: 1n
639+
* },
640+
* licenseTermsData: [
641+
* {
642+
* terms: PILFlavor.commercialUse({
643+
* defaultMintingFee: 10000n,
644+
* currency: WIP_TOKEN_ADDRESS
645+
* })
646+
* }
647+
* ]
648+
* };
649+
* ```
650+
* @example
651+
* **Mint New NFT and with License Terms and Royalty Distribution:**
652+
* ```typescript
653+
* const request: RegisterIpAssetRequest<MintNFT> = {
654+
* nft: {
655+
* type: "mint",
656+
* spgNftContract: "0x1234567890123456789012345678901234567890",
657+
* recipient: "0xRecipient...",
658+
* allowDuplicates: false
659+
* },
660+
* licenseTermsData: [
661+
* {
662+
* terms: PILFlavor.nonCommercialSocialRemixing()
663+
* }
664+
* ],
665+
* royaltyShares: [
666+
* { recipient: "0xArtist...", percentage: 70 },
667+
* { recipient: "0xCollaborator...", percentage: 30 }
668+
* ],
669+
* };
670+
* ```
671+
*/
614672
export type RegisterIpAssetRequest<T extends MintNFT | MintedNFT> = WithWipOptions &
615673
WithIpMetadata & {
674+
/** The NFT to be registered as an IP asset. */
616675
nft: T;
676+
677+
/**
678+
* License terms and configuration to be attached to the IP asset.
679+
*
680+
* @remarks
681+
* Can be specified independently or together with `royaltyShares` for revenue distribution.
682+
*/
617683
licenseTermsData?: LicenseTermsDataInput[];
684+
685+
/**
686+
* Authors of the IP and their shares of the royalty tokens.
687+
*
688+
* @remarks
689+
* Can only be specified when `licenseTermsData` is also provided, ensuring
690+
* that distribute royalty.
691+
*/
618692
royaltyShares?: RoyaltyShare[];
693+
619694
/**
620695
* The deadline for the signature in seconds.
621696
* @default 1000
@@ -624,6 +699,26 @@ export type RegisterIpAssetRequest<T extends MintNFT | MintedNFT> = WithWipOptio
624699
txOptions?: Omit<TxOptions, "encodedTxDataOnly">;
625700
};
626701

702+
/**
703+
* Response type for IP asset registration with conditional return types based on input parameters.
704+
*
705+
* @template T - The request type extending `RegisterIpAssetRequest`
706+
*
707+
* @remarks
708+
* The response structure varies based on the registration type:
709+
*
710+
* **Full Registration (with license terms + royalty shares):**
711+
* - Returns detailed response with royalty vault information
712+
* - Includes transaction hashes for both registration and royalty distribution
713+
*
714+
* **License Terms Only:**
715+
* - Returns response with license terms IDs
716+
* - Includes IP registration details
717+
*
718+
* **Basic Registration:**
719+
* - Returns minimal response with IP ID and transaction hash
720+
*
721+
*/
627722
export type RegisterIpAssetResponse<T extends RegisterIpAssetRequest<MintedNFT | MintNFT>> =
628723
T extends { licenseTermsData: LicenseTermsDataInput[]; royaltyShares: RoyaltyShare[] }
629724
? T extends { nft: { type: "minted" } }

0 commit comments

Comments
 (0)