Skip to content

Commit e9060f8

Browse files
authored
Add default values (#638)
* refactor: update default value formatting for maxRts in IP asset types for improved readability * fix: update maxMintingFee handling to default to 0 in license request types and improve related tests * fix: standardize maxRevenueShare and maxMintingFee default handling across IP asset and license request types * Use ?? instead of || to check undefine * fix: update maxAllowedRewardShare handling to be optional with a default value of 100 across group-related requests * fix: streamline expectMinimumGroupRewardShare validation and update error messages for clarity * fix: update maxAllowedRewardShare to be optional with a default of 100 and enhance related tests for clarity * fix: update maxMintingFee, maxRts, and maxRevenueShare to default to 0 in IP asset requests and enhance related tests for clarity * fix: update maxAllowedRewardShare, maxRts, maxMintingFee, and maxRevenueShare values in group and IP asset tests for improved accuracy and consistency * fix: adjust maxAllowedRewardShare and maxRevenueShare values in group and license tests for consistency * fix: update maxRevenueShare value in license tests for consistency with other configurations
1 parent fe1ac61 commit e9060f8

File tree

15 files changed

+258
-185
lines changed

15 files changed

+258
-185
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ export class GroupClient {
163163
spgNftContract: validateAddress(spgNftContract),
164164
recipient: validateAddress(recipient || this.wallet.account!.address),
165165
maxAllowedRewardShare: BigInt(
166-
getRevenueShare(request.maxAllowedRewardShare, RevShareType.MAX_ALLOWED_REWARD_SHARE),
166+
getRevenueShare(
167+
request.maxAllowedRewardShare ?? 100,
168+
RevShareType.MAX_ALLOWED_REWARD_SHARE,
169+
),
167170
),
168171
licensesData: this.getLicenseData(request.licenseData),
169172
ipMetadata: getIpMetadataForWorkflow(request.ipMetadata),
@@ -275,7 +278,10 @@ export class GroupClient {
275278
ipMetadata: getIpMetadataForWorkflow(request.ipMetadata),
276279
tokenId: BigInt(request.tokenId),
277280
maxAllowedRewardShare: BigInt(
278-
getRevenueShare(request.maxAllowedRewardShare, RevShareType.MAX_ALLOWED_REWARD_SHARE),
281+
getRevenueShare(
282+
request.maxAllowedRewardShare ?? 100,
283+
RevShareType.MAX_ALLOWED_REWARD_SHARE,
284+
),
279285
),
280286
sigAddToGroup: {
281287
signer: validateAddress(this.wallet.account!.address),
@@ -350,7 +356,12 @@ export class GroupClient {
350356
groupPool: validateAddress(request.groupPool),
351357
ipIds: request.ipIds,
352358
licenseData: this.getLicenseData(request.licenseData)[0],
353-
maxAllowedRewardShare: BigInt(getRevenueShare(request.maxAllowedRewardShare)),
359+
maxAllowedRewardShare: BigInt(
360+
getRevenueShare(
361+
request.maxAllowedRewardShare ?? 100,
362+
RevShareType.MAX_ALLOWED_REWARD_SHARE,
363+
),
364+
),
354365
};
355366
for (let i = 0; i < request.ipIds.length; i++) {
356367
const isRegistered = await this.ipAssetRegistryClient.isRegistered({
@@ -491,7 +502,7 @@ export class GroupClient {
491502
ipIds: validateAddresses(ipIds),
492503
maxAllowedRewardShare: BigInt(
493504
getRevenueShare(
494-
maxAllowedRewardSharePercentage === undefined ? 100 : maxAllowedRewardSharePercentage,
505+
maxAllowedRewardSharePercentage ?? 100,
495506
RevShareType.MAX_ALLOWED_REWARD_SHARE_PERCENTAGE,
496507
),
497508
),

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

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import {
4646
TotalLicenseTokenLimitHookClient,
4747
WrappedIpClient,
4848
} from "../abi/generated";
49-
import { MAX_ROYALTY_TOKEN } from "../constants/common";
5049
import { LicenseTermsIdInput, RevShareType } from "../types/common";
5150
import { ChainIds } from "../types/config";
5251
import { TransactionResponse } from "../types/options";
@@ -433,12 +432,9 @@ export class IPAssetClient {
433432
arg.licenseTermsIds.map((id) => BigInt(id)),
434433
arg.licenseTemplate || this.licenseTemplateAddress,
435434
zeroAddress,
436-
BigInt(arg.maxMintingFee || 0),
437-
Number(arg.maxRts === undefined ? MAX_ROYALTY_TOKEN : arg.maxRts),
438-
getRevenueShare(
439-
arg.maxRevenueShare === undefined ? 100 : arg.maxRevenueShare,
440-
RevShareType.MAX_REVENUE_SHARE,
441-
),
435+
BigInt(arg.maxMintingFee ?? 0),
436+
validateMaxRts(arg.maxRts),
437+
getRevenueShare(arg.maxRevenueShare ?? 100, RevShareType.MAX_REVENUE_SHARE),
442438
],
443439
});
444440
const { result: state } = await ipAccount.state();
@@ -492,9 +488,8 @@ export class IPAssetClient {
492488
childIpId: validateAddress(request.childIpId),
493489
licenseTokenIds: request.licenseTokenIds.map((id) => BigInt(id)),
494490
royaltyContext: zeroAddress,
495-
maxRts: Number(request.maxRts),
491+
maxRts: validateMaxRts(request.maxRts),
496492
};
497-
validateMaxRts(req.maxRts);
498493
const isChildIpIdRegistered = await this.isRegistered(request.childIpId);
499494
if (!isChildIpIdRegistered) {
500495
throw new Error(`The child IP with id ${request.childIpId} is not registered.`);
@@ -1049,11 +1044,9 @@ export class IPAssetClient {
10491044
ipMetadata: getIpMetadataForWorkflow(request.ipMetadata),
10501045
licenseTokenIds: licenseTokenIds,
10511046
royaltyContext: zeroAddress,
1052-
maxRts: Number(request.maxRts),
1047+
maxRts: validateMaxRts(request.maxRts),
10531048
allowDuplicates: request.allowDuplicates || true,
10541049
};
1055-
validateMaxRts(object.maxRts);
1056-
10571050
const encodedTxData =
10581051
this.derivativeWorkflowsClient.mintAndRegisterIpAndMakeDerivativeWithLicenseTokensEncode(
10591052
object,
@@ -1130,9 +1123,8 @@ export class IPAssetClient {
11301123
deadline: calculatedDeadline,
11311124
signature,
11321125
},
1133-
maxRts: Number(request.maxRts),
1126+
maxRts: validateMaxRts(request.maxRts),
11341127
};
1135-
validateMaxRts(object.maxRts);
11361128
if (request.txOptions?.encodedTxDataOnly) {
11371129
return {
11381130
encodedTxData:
@@ -1694,7 +1686,7 @@ export class IPAssetClient {
16941686
}
16951687
}
16961688
/**
1697-
* Register a derivative IP asset, supporting both minted and mint-on-demand NFTs, with optional `derivData`, `royaltyShares` and `licenseTokenIds`, `maxRts`.
1689+
* Register a derivative IP asset, supporting both minted and mint-on-demand NFTs, with optional `derivData`, `royaltyShares` and `licenseTokenIds`.
16981690
*
16991691
* This method automatically selects and calls the appropriate workflow from 6 available methods based on your input parameters.
17001692
* Here are three common usage patterns:
@@ -1707,7 +1699,6 @@ export class IPAssetClient {
17071699
* parentIpIds: ["0x..."],
17081700
* licenseTermsIds: [1n],
17091701
* maxMintingFee: 10000n,
1710-
* maxRts: 100,
17111702
* maxRevenueShare: 100
17121703
* },
17131704
* royaltyShares: [
@@ -1724,18 +1715,16 @@ export class IPAssetClient {
17241715
* parentIpIds: ["0x..."],
17251716
* licenseTermsIds: [1n],
17261717
* maxMintingFee: 10000n,
1727-
* maxRts: 100,
17281718
* maxRevenueShare: 100
17291719
* }
17301720
* });
17311721
* ```
17321722
*
1733-
* **3. Mint NFT with License Token IDs and maxRts:**
1723+
* **3. Mint NFT with License Token IDs:**
17341724
* ```typescript
17351725
* const result = await client.ipAsset.registerDerivativeIpAsset({
17361726
* nft: { type: "mint", spgNftContract: "0x...", recipient: "0x...", allowDuplicates: false },
17371727
* licenseTokenIds: [1, 2, 3],
1738-
* maxRts: 100
17391728
* });
17401729
* ```
17411730
*
@@ -1752,37 +1741,25 @@ export class IPAssetClient {
17521741
* - It checks allowances for all required spenders and automatically approves them if their current allowance is lower than needed.
17531742
* - These automatic processes can be configured through the `wipOptions` parameter to control behavior like multicall usage and approval settings.
17541743
*
1755-
* @throws {Error} If `licenseTokenIds` and `maxRts` are not provided together.
17561744
* @throws {Error} If `derivData` is not provided when `royaltyShares` are provided.
1757-
* @throws {Error} If neither `derivData` nor (`licenseTokenIds` and `maxRts`) are provided.
1745+
* @throws {Error} If neither `derivData` nor `licenseTokenIds` are provided.
17581746
* @throws {Error} If the NFT type is invalid.
17591747
*/
17601748
public async registerDerivativeIpAsset<
17611749
T extends RegisterDerivativeIpAssetRequest<MintedNFT | MintNFT>,
17621750
>(request: T): Promise<RegisterDerivativeIpAssetResponse<T>> {
17631751
try {
1764-
const { nft, licenseTokenIds, maxRts, royaltyShares, derivData } = request;
1765-
if (
1766-
(licenseTokenIds && licenseTokenIds.length > 0 && maxRts === undefined) ||
1767-
(maxRts !== undefined && (!licenseTokenIds || licenseTokenIds.length === 0))
1768-
) {
1769-
throw new Error("licenseTokenIds and maxRts must be provided together.");
1770-
}
1771-
1752+
const { nft, licenseTokenIds, royaltyShares, derivData } = request;
17721753
if (royaltyShares && !derivData) {
17731754
throw new Error("derivData must be provided when royaltyShares are provided.");
17741755
}
17751756

17761757
// Validate that at least one valid combination is provided
17771758
const hasDerivData = !!derivData;
1778-
const hasLicenseTokens = !!(
1779-
licenseTokenIds &&
1780-
licenseTokenIds.length > 0 &&
1781-
maxRts !== undefined
1782-
);
1759+
const hasLicenseTokens = !!(licenseTokenIds && licenseTokenIds.length > 0);
17831760

17841761
if (!hasDerivData && !hasLicenseTokens) {
1785-
throw new Error("Either derivData or (licenseTokenIds and maxRts) must be provided.");
1762+
throw new Error("Either derivData or licenseTokenIds must be provided.");
17861763
}
17871764

17881765
if (nft.type === "minted") {
@@ -1802,7 +1779,7 @@ export class IPAssetClient {
18021779
}
18031780

18041781
/**
1805-
* Handles derivative registration for already minted NFTs with optional `derivData`, `royaltyShares` and `licenseTokenIds`, `maxRts`.
1782+
* Handles derivative registration for already minted NFTs with optional `derivData`, `royaltyShares` and `licenseTokenIds`.
18061783
*
18071784
* Supports the following workflows:
18081785
* - {@link registerDerivativeIpAndAttachLicenseTermsAndDistributeRoyaltyTokens}
@@ -1849,12 +1826,12 @@ export class IPAssetClient {
18491826
return this.registerIpAndMakeDerivativeWithLicenseTokens({
18501827
...baseParams,
18511828
licenseTokenIds: licenseTokenIds!,
1852-
maxRts: maxRts!,
1829+
maxRts,
18531830
});
18541831
}
18551832

18561833
/**
1857-
* Handles derivative registration for minted NFTs with optional `derivData`, `royaltyShares` and `licenseTokenIds`, `maxRts`.
1834+
* Handles derivative registration for minted NFTs with optional `derivData`, `royaltyShares` and `licenseTokenIds`.
18581835
*
18591836
* Supports the following workflows:
18601837
* - {@link mintAndRegisterIpAndMakeDerivativeAndDistributeRoyaltyTokens}
@@ -1901,7 +1878,7 @@ export class IPAssetClient {
19011878
return this.mintAndRegisterIpAndMakeDerivativeWithLicenseTokens({
19021879
...baseParams,
19031880
licenseTokenIds: licenseTokenIds!,
1904-
maxRts: maxRts!,
1881+
maxRts,
19051882
});
19061883
}
19071884

@@ -1916,7 +1893,6 @@ export class IPAssetClient {
19161893
* ```typescript
19171894
* const result = await client.ipAsset.linkDerivative({
19181895
* licenseTokenIds: [1, 2, 3],
1919-
* maxRts: 100,
19201896
* childIpId: "0x...",
19211897
* });
19221898
* ```
@@ -1926,7 +1902,6 @@ export class IPAssetClient {
19261902
* const result = await client.ipAsset.linkDerivative({
19271903
* parentIpIds: ["0x..."],
19281904
* licenseTermsIds: [1],
1929-
* maxRts: 100,
19301905
* childIpId: "0x...",
19311906
* });
19321907
* ```

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,11 @@ export class LicenseClient {
190190
amount: BigInt(request.amount === undefined ? 1 : request.amount),
191191
receiver,
192192
royaltyContext: zeroAddress,
193-
maxMintingFee: BigInt(request.maxMintingFee),
194-
maxRevenueShare: getRevenueShare(request.maxRevenueShare, RevShareType.MAX_REVENUE_SHARE),
193+
maxMintingFee: BigInt(request.maxMintingFee ?? 0),
194+
maxRevenueShare: getRevenueShare(
195+
request.maxRevenueShare ?? 100,
196+
RevShareType.MAX_REVENUE_SHARE,
197+
),
195198
} as const;
196199
if (req.maxMintingFee < 0) {
197200
throw new Error(`The maxMintingFee must be greater than 0.`);

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ export type MintAndRegisterIpAndAttachLicenseAndAddToGroupRequest = {
4343
/**
4444
* The maximum reward share percentage that can be allocated to each member IP.
4545
* Must be between 0 and 100 (where 100% represents 100_000_000).
46+
*
47+
* @default 100
4648
*/
47-
maxAllowedRewardShare: RevShareInput;
49+
maxAllowedRewardShare?: RevShareInput;
4850
/** The data of the license and its configuration to be attached to the new group IP. */
4951
licenseData: LicenseDataInput[];
5052
/** The address of the recipient of the minted NFT. If not provided, the function will use the user's own wallet address. */
@@ -85,8 +87,13 @@ export type RegisterIpAndAttachLicenseAndAddToGroupRequest = {
8587
deadline?: DeadlineInput;
8688
/** The data of the license and its configuration to be attached to the new group IP. */
8789
licenseData: LicenseDataInput[];
88-
/** The maximum reward share percentage that can be allocated to each member IP. */
89-
maxAllowedRewardShare: RevShareInput;
90+
/**
91+
* The maximum reward share percentage that can be allocated to each member IP.
92+
* Must be between 0 and 100 (where 100% represents 100_000_000).
93+
*
94+
* @default 100
95+
*/
96+
maxAllowedRewardShare?: RevShareInput;
9097
} & IpMetadataAndTxOptions;
9198

9299
export type RegisterIpAndAttachLicenseAndAddToGroupResponse = {
@@ -118,8 +125,10 @@ export type RegisterGroupAndAttachLicenseAndAddIpsRequest = {
118125
/**
119126
* The maximum reward share percentage that can be allocated to each member IP.
120127
* Must be between 0 and 100 (where 100% represents 100_000_000).
128+
*
129+
* @default 100
121130
*/
122-
maxAllowedRewardShare: RevShareInput;
131+
maxAllowedRewardShare?: RevShareInput;
123132
txOptions?: TxOptions;
124133
};
125134

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ export type RegisterDerivativeWithLicenseTokensRequest = {
8585
childIpId: Address;
8686
/** The IDs of the license tokens. */
8787
licenseTokenIds: LicenseTermsIdInput[];
88-
/** The maximum number of royalty tokens that can be distributed to the external royalty policies (max: 100,000,000). */
89-
maxRts: MaxRtsInput;
88+
/**
89+
* The maximum number of royalty tokens that can be distributed to the external royalty policies (max: 100,000,000).
90+
* @default 100_000_000
91+
*/
92+
maxRts?: MaxRtsInput;
9093
txOptions?: TxOptions;
9194
};
9295

@@ -213,8 +216,11 @@ export type MintAndRegisterIpAndMakeDerivativeWithLicenseTokensRequest = {
213216
licenseTokenIds: LicenseTermsIdInput[];
214217
/** The address of the recipient of the minted NFT. If not provided, the client's own wallet address will be used. */
215218
recipient?: Address;
216-
/** The maximum number of royalty tokens that can be distributed to the external royalty policies (max: 100,000,000). */
217-
maxRts: MaxRtsInput;
219+
/**
220+
* The maximum number of royalty tokens that can be distributed to the external royalty policies (max: 100,000,000).
221+
* @default 100_000_000
222+
*/
223+
maxRts?: MaxRtsInput;
218224
/**
219225
* Set to true to allow minting an NFT with a duplicate metadata hash.
220226
* @default true
@@ -228,8 +234,11 @@ export type RegisterIpAndMakeDerivativeWithLicenseTokensRequest = {
228234
tokenId: TokenIdInput;
229235
/** The IDs of the license tokens to be burned for linking the IP to parent IPs. */
230236
licenseTokenIds: LicenseTermsIdInput[];
231-
/** The maximum number of royalty tokens that can be distributed to the external royalty policies (max: 100,000,000). */
232-
maxRts: MaxRtsInput;
237+
/**
238+
* The maximum number of royalty tokens that can be distributed to the external royalty policies (max: 100,000,000).
239+
* @default 100_000_000
240+
*/
241+
maxRts?: MaxRtsInput;
233242
/**
234243
* The deadline for the signature in seconds.
235244
* @default 1000
@@ -256,7 +265,8 @@ export type BatchMintAndRegisterIpAssetWithPilTermsResponse = {
256265

257266
export type BatchRegisterDerivativeRequest = {
258267
args: RegisterDerivativeRequest[];
259-
/** The deadline for the signature in seconds.
268+
/**
269+
* The deadline for the signature in seconds.
260270
* @default 1000
261271
*/
262272
deadline?: DeadlineInput;
@@ -773,12 +783,10 @@ export type RegisterDerivativeIpAssetRequest<T extends MintedNFT | MintNFT> = Wi
773783
derivData?: DerivativeDataInput;
774784
/**
775785
* The maximum number of royalty tokens that can be distributed to the external royalty policies (max: 100,000,000).
776-
* Must be provided together with `licenseTokenIds`.
786+
* @default 100_000_000
777787
*/
778788
maxRts?: MaxRtsInput;
779-
/** The IDs of the license tokens to be burned for linking the IP to parent IPs.
780-
* Must be provided together with `maxRts`.
781-
*/
789+
/** The IDs of the license tokens to be burned for linking the IP to parent IPs. */
782790
licenseTokenIds?: LicenseTermsIdInput[];
783791
/**
784792
* The deadline for the signature in seconds.

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,18 @@ export type MintLicenseTokensRequest = {
121121
* Defaults to {@link https://docs.story.foundation/docs/programmable-ip-license | PIL} address if not provided.
122122
*/
123123
licenseTemplate?: Address;
124-
/** The maximum minting fee that the caller is willing to pay. if set to 0 then no limit. */
125-
maxMintingFee: FeeInput;
126-
/** The maximum revenue share percentage allowed for minting the License Tokens. Must be between 0 and 100,000,000 (where 100,000,000 represents 100%). */
127-
maxRevenueShare: RevShareInput;
124+
/**
125+
* The maximum minting fee that the caller is willing to pay.if set to 0 then no limit.
126+
*
127+
* @default 0
128+
*/
129+
maxMintingFee?: FeeInput;
130+
/**
131+
* The maximum revenue share percentage allowed for minting the License Tokens. Must be between 0 and 100,000,000 (where 100,000,000 represents 100%).
132+
*
133+
* @default 100
134+
*/
135+
maxRevenueShare?: RevShareInput;
128136
/**
129137
* The amount of license tokens to mint.
130138
* @default 1

0 commit comments

Comments
 (0)