Skip to content

Commit 524d234

Browse files
committed
Add default value for DerivativeData and LicenseConfig
Add default value for LicenseConfig Update the doc about multiple line Update the doc Update event with link Update zero address Modify licenseConfig logic Refactor via comments Enhance LicenseTermsData type Make licensingConfig required in the setLicensingConfig method Update default show style
1 parent 749fc32 commit 524d234

File tree

16 files changed

+286
-529
lines changed

16 files changed

+286
-529
lines changed

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

Lines changed: 11 additions & 100 deletions
Large diffs are not rendered by default.

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

Lines changed: 36 additions & 315 deletions
Large diffs are not rendered by default.

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

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ import {
4343
getRevenueShare,
4444
validateLicenseTerms,
4545
} from "../utils/licenseTermsHelper";
46-
import { chain, getAddress } from "../utils/utils";
46+
import { chain, getAddress, validateAddress } from "../utils/utils";
4747
import { ChainIds } from "../types/config";
4848
import { calculateLicenseWipMintFee, contractCallWithFees } from "../utils/feeUtils";
4949
import { Erc20Spender } from "../types/utils/wip";
50+
import { validateLicenseConfig } from "../utils/validateLicenseConfig";
5051

5152
export class LicenseClient {
5253
public licenseRegistryClient: LicenseRegistryEventClient;
@@ -538,80 +539,43 @@ export class LicenseClient {
538539

539540
/**
540541
* Sets the licensing configuration for a specific license terms of an IP. If both licenseTemplate and licenseTermsId are not specified then the licensing config apply to all licenses of given IP.
541-
* @param request - The request object that contains all data needed to set licensing config.
542-
* @param request.ipId The address of the IP for which the configuration is being set.
543-
* @param request.licenseTermsId The ID of the license terms within the license template.
544-
* @param request.licenseTemplate The address of the license template used, If not specified, the configuration applies to all licenses.
545-
* @param request.licensingConfig The licensing configuration for the license.
546-
* @param request.licensingConfig.isSet Whether the configuration is set or not.
547-
* @param request.licensingConfig.mintingFee The minting fee to be paid when minting license tokens.
548-
* @param request.licensingConfig.hookData The data to be used by the licensing hook.
549-
* @param request.licensingConfig.licensingHook The hook contract address for the licensing module, or address(0) if none.
550-
* @param request.licensingConfig.commercialRevShare The commercial revenue share percentage.
551-
* @param request.licensingConfig.disabled Whether the license is disabled or not.
552-
* @param request.licensingConfig.expectMinimumGroupRewardShare The minimum percentage of the group’s reward share (from 0 to 100%, represented as 100 * 10 ** 6) that can be allocated to the IP when it is added to the group.
553-
* If the remaining reward share in the group is less than the minimumGroupRewardShare, the IP cannot be added to the group.
554-
* @param request.licensingConfig.expectGroupRewardPool The address of the expected group reward pool. The IP can only be added to a group with this specified reward pool address,
555-
* or address(0) if the IP does not want to be added to any group.
556-
* @param request.txOptions [Optional] This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property.
557-
* @returns A Promise that resolves to a transaction hash, and if encodedTxDataOnly is true, includes encoded transaction data, and if waitForTransaction is true, includes success.
558542
*/
559543
public async setLicensingConfig(
560544
request: SetLicensingConfigRequest,
561545
): Promise<SetLicensingConfigResponse> {
562546
try {
563547
const req: LicensingModuleSetLicensingConfigRequest = {
564548
ipId: request.ipId,
565-
licenseTemplate: getAddress(request.licenseTemplate, "request.licenseTemplate"),
549+
licenseTemplate: validateAddress(request.licenseTemplate),
566550
licenseTermsId: BigInt(request.licenseTermsId),
567-
licensingConfig: {
568-
isSet: request.licensingConfig.isSet,
569-
mintingFee: BigInt(request.licensingConfig.mintingFee),
570-
hookData: request.licensingConfig.hookData,
571-
licensingHook: request.licensingConfig.licensingHook,
572-
disabled: request.licensingConfig.disabled,
573-
commercialRevShare: getRevenueShare(request.licensingConfig.commercialRevShare),
574-
expectGroupRewardPool: getAddress(
575-
request.licensingConfig.expectGroupRewardPool,
576-
"request.licensingConfig.expectGroupRewardPool",
577-
),
578-
expectMinimumGroupRewardShare: Number(
579-
request.licensingConfig.expectMinimumGroupRewardShare,
580-
),
581-
},
551+
licensingConfig: validateLicenseConfig(request.licensingConfig),
582552
};
583-
if (req.licensingConfig.mintingFee < 0) {
584-
throw new Error("The minting fee must be greater than 0.");
585-
}
586-
if (
587-
request.licenseTemplate === zeroAddress &&
588-
request.licensingConfig.commercialRevShare !== 0
589-
) {
553+
if (req.licenseTemplate === zeroAddress && req.licensingConfig.commercialRevShare !== 0) {
590554
throw new Error(
591555
"The license template cannot be zero address if commercial revenue share is not zero.",
592556
);
593557
}
594558
const isLicenseIpIdRegistered = await this.ipAssetRegistryClient.isRegistered({
595-
id: getAddress(request.ipId, "request.ipId"),
559+
id: validateAddress(req.ipId),
596560
});
597561
if (!isLicenseIpIdRegistered) {
598-
throw new Error(`The licensor IP with id ${request.ipId} is not registered.`);
562+
throw new Error(`The licensor IP with id ${req.ipId} is not registered.`);
599563
}
600564
const isExisted = await this.piLicenseTemplateReadOnlyClient.exists({
601565
licenseTermsId: req.licenseTermsId,
602566
});
603567
if (!isExisted) {
604-
throw new Error(`License terms id ${request.licenseTermsId} do not exist.`);
568+
throw new Error(`License terms id ${req.licenseTermsId} do not exist.`);
605569
}
606-
if (request.licensingConfig.licensingHook !== zeroAddress) {
570+
if (req.licensingConfig.licensingHook !== zeroAddress) {
607571
const isRegistered = await this.moduleRegistryReadOnlyClient.isRegistered({
608-
moduleAddress: request.licensingConfig.licensingHook,
572+
moduleAddress: req.licensingConfig.licensingHook,
609573
});
610574
if (!isRegistered) {
611575
throw new Error("The licensing hook is not registered.");
612576
}
613577
}
614-
if (request.licenseTemplate === zeroAddress && request.licenseTermsId !== 0n) {
578+
if (req.licenseTemplate === zeroAddress && req.licenseTermsId !== 0n) {
615579
throw new Error("The license template is zero address but license terms id is not zero.");
616580
}
617581

packages/core-sdk/src/types/common.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,33 @@ export type TypedData = {
99
};
1010

1111
export type IpMetadataAndTxOptions = WithTxOptions & {
12+
/** The desired metadata for the newly minted NFT and newly registered IP. */
1213
ipMetadata?: Partial<IpMetadataForWorkflow>;
1314
};
14-
1515
export type LicensingConfig = {
16+
/** Whether the configuration is set or not */
1617
isSet: boolean;
18+
/** The minting fee to be paid when minting license tokens. */
1719
mintingFee: bigint | string | number;
20+
/** The hook contract address for the licensing module, or zero address if none. */
1821
licensingHook: Address;
22+
/** The data to be used by the licensing hook. */
1923
hookData: Hex;
24+
/** The commercial revenue share percentage (from 0 to 100%, represented as 100_000_000). */
2025
commercialRevShare: number | string;
26+
/** Whether the licensing is disabled or not. */
2127
disabled: boolean;
28+
/** The minimum percentage of the group’s reward share (from 0 to 100%, represented as 100_000_000) that can be allocated to the IP when it is added to the group. */
2229
expectMinimumGroupRewardShare: number | string;
30+
/** The address of the expected group reward pool. The IP can only be added to a group with this specified reward pool address, or zero address if the IP does not want to be added to any group. */
2331
expectGroupRewardPool: Address;
2432
};
2533

26-
export type InnerLicensingConfig = {
34+
export type ValidatedLicensingConfig = LicensingConfig & {
2735
mintingFee: bigint;
2836
commercialRevShare: number;
2937
expectMinimumGroupRewardShare: number;
30-
} & LicensingConfig;
38+
};
3139

3240
/**
3341
* Input for token amount, can be bigint or number.

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,35 @@ import { Address } from "viem";
22

33
import { TxOptions } from "../options";
44
import { EncodedTxData } from "../../abi/generated";
5-
import { InnerLicensingConfig, IpMetadataAndTxOptions, LicensingConfig } from "../common";
5+
import { IpMetadataAndTxOptions, LicensingConfig, ValidatedLicensingConfig } from "../common";
66

77
export type LicenseData = {
88
licenseTermsId: string | bigint | number;
9-
licensingConfig: LicensingConfig;
9+
licensingConfig?: LicensingConfig;
1010
licenseTemplate?: Address;
1111
};
1212

13-
export type InnerLicenseData = {
13+
export type ValidatedLicenseData = {
1414
licenseTermsId: bigint;
15-
licensingConfig: InnerLicensingConfig;
15+
licensingConfig: ValidatedLicensingConfig;
1616
licenseTemplate: Address;
1717
};
18-
1918
export type MintAndRegisterIpAndAttachLicenseAndAddToGroupRequest = {
2019
spgNftContract: Address;
20+
/** The ID of the group IP to add the newly registered IP. */
2121
groupId: Address;
22+
/** Set to true to allow minting an NFT with a duplicate metadata hash. */
2223
allowDuplicates: boolean;
24+
/** The maximum reward share percentage that can be allocated to each member IP. */
2325
maxAllowedRewardShare: number | string;
26+
/** The data of the license and its configuration to be attached to the new group IP. */
2427
licenseData: LicenseData[];
28+
/** The address of the recipient of the minted NFT. If not provided, the function will use the user's own wallet address. */
2529
recipient?: Address;
30+
/**
31+
* The deadline for the signature in seconds.
32+
* @default 1000
33+
*/
2634
deadline?: string | number | bigint;
2735
} & IpMetadataAndTxOptions;
2836

@@ -42,13 +50,19 @@ export type RegisterGroupResponse = {
4250
encodedTxData?: EncodedTxData;
4351
groupId?: Address;
4452
};
45-
4653
export type RegisterIpAndAttachLicenseAndAddToGroupRequest = {
4754
nftContract: Address;
4855
tokenId: bigint | string | number;
56+
/** The ID of the group IP to add the newly registered IP. */
4957
groupId: Address;
58+
/**
59+
* The deadline for the signature in seconds.
60+
* @default 1000
61+
*/
5062
deadline?: bigint;
63+
/** The data of the license and its configuration to be attached to the new group IP. */
5164
licenseData: LicenseData[];
65+
/** The maximum reward share percentage that can be allocated to each member IP. */
5266
maxAllowedRewardShare: number | string;
5367
} & IpMetadataAndTxOptions;
5468

@@ -59,7 +73,9 @@ export type RegisterIpAndAttachLicenseAndAddToGroupResponse = {
5973
tokenId?: bigint;
6074
};
6175
export type RegisterGroupAndAttachLicenseRequest = {
76+
/** The address specifying how royalty will be split amongst the pool of IPs in the group. */
6277
groupPool: Address;
78+
/** The data of the license and its configuration to be attached to the new group IP. */
6379
licenseData: LicenseData;
6480
txOptions?: TxOptions;
6581
};
@@ -69,11 +85,14 @@ export type RegisterGroupAndAttachLicenseResponse = {
6985
encodedTxData?: EncodedTxData;
7086
groupId?: Address;
7187
};
72-
7388
export type RegisterGroupAndAttachLicenseAndAddIpsRequest = {
89+
/** The address specifying how royalty will be split amongst the pool of IPs in the group. */
7490
groupPool: Address;
91+
/** The IP IDs of the IPs to be added to the group. */
7592
ipIds: Address[];
93+
/** The data of the license and its configuration to be attached to the new group IP. */
7694
licenseData: LicenseData;
95+
/** The maximum reward share percentage that can be allocated to each member IP. */
7796
maxAllowedRewardShare: number | string;
7897
txOptions?: TxOptions;
7998
};

0 commit comments

Comments
 (0)