Skip to content

Commit 0e60242

Browse files
authored
Refactor: clean string type via number type (#635)
* refactor: update type definitions to use LicenseTermsIdInput and DeadlineInput for improved consistency and clarity across IP asset and licensing methods * refactor: update LicensingConfig and related types to use RevShareInput and FeeInput for improved type consistency across SDK * refactor: update disputeId type in settleAssertion method to use DisputeId for improved type safety * refactor: update mintFee handling to use BigInt for consistency across NFT and licensing methods * refactor: remove redundant NaN checks in revenue share and license validation functions for improved clarity * refactor: update CommercialRemixRequest and CommercialUseRequest types to use FeeInput for minting fees, enhancing type consistency across SDK
1 parent 7fb0bdb commit 0e60242

30 files changed

+312
-355
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import {
4848
WrappedIpClient,
4949
} from "../abi/generated";
5050
import { MAX_ROYALTY_TOKEN } from "../constants/common";
51-
import { RevShareType } from "../types/common";
51+
import { LicenseTermsIdInput, RevShareType } from "../types/common";
5252
import { ChainIds } from "../types/config";
5353
import { TransactionResponse } from "../types/options";
5454
import {
@@ -2101,9 +2101,7 @@ export class IPAssetClient {
21012101
return licenseTermsIds;
21022102
}
21032103

2104-
private async validateLicenseTokenIds(
2105-
licenseTokenIds: string[] | bigint[] | number[],
2106-
): Promise<bigint[]> {
2104+
private async validateLicenseTokenIds(licenseTokenIds: LicenseTermsIdInput[]): Promise<bigint[]> {
21072105
if (licenseTokenIds.length === 0) {
21082106
throw new Error("License token IDs must be provided.");
21092107
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ import {
2020
TotalLicenseTokenLimitHookClient,
2121
WrappedIpClient,
2222
} from "../abi/generated";
23-
import { LicensingConfig, RevShareType } from "../types/common";
23+
import { LicenseTermsIdInput, LicensingConfig, RevShareType } from "../types/common";
2424
import { ChainIds } from "../types/config";
2525
import { TransactionResponse, TxOptions } from "../types/options";
2626
import {
2727
AttachLicenseTermsRequest,
2828
AttachLicenseTermsResponse,
2929
GetLicensingConfigRequest,
3030
LicenseTerms,
31-
LicenseTermsId,
3231
LicenseTermsIdResponse,
3332
MintLicenseTokensRequest,
3433
MintLicenseTokensResponse,
@@ -257,7 +256,7 @@ export class LicenseClient {
257256
* Gets license terms of the given ID.
258257
*/
259258
public async getLicenseTerms(
260-
selectedLicenseTermsId: LicenseTermsId,
259+
selectedLicenseTermsId: LicenseTermsIdInput,
261260
): Promise<PiLicenseTemplateGetLicenseTermsResponse> {
262261
try {
263262
return await this.piLicenseTemplateReadOnlyClient.getLicenseTerms({

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class NftClient {
5555
symbol: request.symbol,
5656
baseURI: request.baseURI ?? "",
5757
maxSupply: request.maxSupply ?? Number(maxUint32),
58-
mintFee: request.mintFee ?? 0n,
58+
mintFee: BigInt(request.mintFee ?? 0),
5959
mintFeeToken: request.mintFeeToken ?? zeroAddress,
6060
owner: validateAddress(request.owner || this.wallet.account!.address),
6161
mintFeeRecipient: validateAddress(request.mintFeeRecipient),

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type LicensingConfigInput = {
2323
/** Whether the licensing configuration is active. If false, the configuration is ignored. */
2424
isSet: boolean;
2525
/** The minting fee to be paid when minting license tokens. */
26-
mintingFee: bigint | string | number;
26+
mintingFee: FeeInput;
2727
/**
2828
* The licensingHook is an address to a smart contract that implements the `ILicensingHook` interface.
2929
* This contract's `beforeMintLicenseTokens` function is executed before a user mints a License Token,
@@ -40,21 +40,21 @@ export type LicensingConfigInput = {
4040
* Percentage of revenue that must be shared with the licensor.
4141
* Must be between 0 and 100 (where 100% represents 100_000_000).
4242
*/
43-
commercialRevShare: number | string;
43+
commercialRevShare: RevShareInput;
4444
/** Whether the licensing is disabled or not. If this is true, then no licenses can be minted and no more derivatives can be attached at all. */
4545
disabled: boolean;
4646
/**
4747
* 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.
4848
* Must be between 0 and 100 (where 100% represents 100_000_000).
4949
*/
50-
expectMinimumGroupRewardShare: number | string;
50+
expectMinimumGroupRewardShare: RevShareInput;
5151
/** 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. */
5252
expectGroupRewardPool: Address;
5353
};
5454

5555
export type LicensingConfig = LicensingConfigInput & {
5656
mintingFee: bigint;
57-
commercialRevShare: number;
57+
commercialRevShare: RevShareInput;
5858
expectMinimumGroupRewardShare: number;
5959
};
6060

@@ -80,3 +80,26 @@ export enum RevShareType {
8080
EXPECT_MINIMUM_GROUP_REWARD_SHARE = "expectMinimumGroupRewardShare",
8181
MAX_ALLOWED_REWARD_SHARE_PERCENTAGE = "maxAllowedRewardSharePercentage",
8282
}
83+
84+
/**
85+
* Input for license terms id, can be bigint or number.
86+
* Will be converted to bigint for contract calls.
87+
*/
88+
export type LicenseTermsIdInput = number | bigint;
89+
90+
/**
91+
* Input for deadline, can be bigint or number.
92+
* Will be converted to bigint for contract calls.
93+
*/
94+
export type DeadlineInput = number | bigint;
95+
96+
/**
97+
* Input for revenue share, can be number.
98+
*/
99+
export type RevShareInput = number;
100+
101+
/**
102+
* Input for fee, can be bigint or number.
103+
* Will be converted to bigint for contract calls.
104+
*/
105+
export type FeeInput = bigint | number;

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Address, Hash, Hex } from "viem";
33
import { EncodedTxData } from "../../abi/generated";
44
import { TxOptions, WipOptions, WithTxOptions } from "../options";
55

6+
export type DisputeId = number | bigint;
7+
68
export type RaiseDisputeRequest = WithTxOptions & {
79
/** The IP ID that is the target of the dispute. */
810
targetIpId: Address;
@@ -19,14 +21,14 @@ export type RaiseDisputeRequest = WithTxOptions & {
1921
*/
2022
targetTag: DisputeTargetTag;
2123
/** The liveness is the time window (in seconds) in which a counter dispute can be presented (30days). */
22-
liveness: bigint | number | string;
24+
liveness: bigint | number;
2325
/**
2426
* The amount of wrapper IP that the dispute initiator pays upfront into a pool.
2527
* To counter that dispute the opposite party of the dispute has to place a bond of the same amount.
2628
* The winner of the dispute gets the original bond back + 50% of the other party bond. The remaining 50% of the loser party bond goes to the reviewer.
2729
* The bond amount must be between the minimum and maximum bond values defined in the Optimistic Oracle V3 (OOV3) contract. If not specified, it defaults to the minimum bond value.
2830
*/
29-
bond?: bigint | number | string;
31+
bond?: bigint | number;
3032
/**
3133
* Omit {@link WipOptions.useMulticallWhenPossible} for this function due to disputeInitiator issue.
3234
* It will be executed sequentially with several transactions.
@@ -41,7 +43,7 @@ export type RaiseDisputeResponse = {
4143
};
4244

4345
export type CancelDisputeRequest = {
44-
disputeId: number | string | bigint;
46+
disputeId: DisputeId;
4547
/**
4648
* Additional data used in the cancellation process.
4749
*
@@ -57,7 +59,7 @@ export type CancelDisputeResponse = {
5759
};
5860

5961
export type ResolveDisputeRequest = {
60-
disputeId: number | string | bigint;
62+
disputeId: DisputeId;
6163
/**
6264
* Additional data used in the resolution process.
6365
*
@@ -77,7 +79,7 @@ export type TagIfRelatedIpInfringedRequest = {
7779
/** The ipId to tag */
7880
ipId: Address;
7981
/** The dispute id that tagged the related infringing ipId */
80-
disputeId: number | string | bigint;
82+
disputeId: DisputeId;
8183
}[];
8284
options?: {
8385
/**

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ import {
55
GroupingModuleClaimedRewardEvent,
66
GroupingModuleCollectedRoyaltiesToGroupPoolEvent,
77
} from "../../abi/generated";
8-
import { IpMetadataAndTxOptions, LicensingConfig, LicensingConfigInput } from "../common";
8+
import {
9+
DeadlineInput,
10+
IpMetadataAndTxOptions,
11+
LicenseTermsIdInput,
12+
LicensingConfig,
13+
LicensingConfigInput,
14+
RevShareInput,
15+
TokenIdInput,
16+
} from "../common";
917
import { TxOptions } from "../options";
1018

1119
export type LicenseDataInput = {
12-
licenseTermsId: string | bigint | number;
20+
licenseTermsId: LicenseTermsIdInput;
1321
/**
1422
* The address of the license template.
1523
* Defaults to {@link https://docs.story.foundation/docs/programmable-ip-license | PIL} address if not provided.
@@ -36,7 +44,7 @@ export type MintAndRegisterIpAndAttachLicenseAndAddToGroupRequest = {
3644
* The maximum reward share percentage that can be allocated to each member IP.
3745
* Must be between 0 and 100 (where 100% represents 100_000_000).
3846
*/
39-
maxAllowedRewardShare: number | string;
47+
maxAllowedRewardShare: RevShareInput;
4048
/** The data of the license and its configuration to be attached to the new group IP. */
4149
licenseData: LicenseDataInput[];
4250
/** The address of the recipient of the minted NFT. If not provided, the function will use the user's own wallet address. */
@@ -45,7 +53,7 @@ export type MintAndRegisterIpAndAttachLicenseAndAddToGroupRequest = {
4553
* The deadline for the signature in seconds.
4654
* @default 1000
4755
*/
48-
deadline?: string | number | bigint;
56+
deadline?: DeadlineInput;
4957
} & IpMetadataAndTxOptions;
5058

5159
export type MintAndRegisterIpAndAttachLicenseAndAddToGroupResponse = {
@@ -67,18 +75,18 @@ export type RegisterGroupResponse = {
6775
};
6876
export type RegisterIpAndAttachLicenseAndAddToGroupRequest = {
6977
nftContract: Address;
70-
tokenId: bigint | string | number;
78+
tokenId: TokenIdInput;
7179
/** The ID of the group IP to add the newly registered IP. */
7280
groupId: Address;
7381
/**
7482
* The deadline for the signature in seconds.
7583
* @default 1000
7684
*/
77-
deadline?: bigint;
85+
deadline?: DeadlineInput;
7886
/** The data of the license and its configuration to be attached to the new group IP. */
7987
licenseData: LicenseDataInput[];
8088
/** The maximum reward share percentage that can be allocated to each member IP. */
81-
maxAllowedRewardShare: number | string;
89+
maxAllowedRewardShare: RevShareInput;
8290
} & IpMetadataAndTxOptions;
8391

8492
export type RegisterIpAndAttachLicenseAndAddToGroupResponse = {
@@ -111,7 +119,7 @@ export type RegisterGroupAndAttachLicenseAndAddIpsRequest = {
111119
* The maximum reward share percentage that can be allocated to each member IP.
112120
* Must be between 0 and 100 (where 100% represents 100_000_000).
113121
*/
114-
maxAllowedRewardShare: number | string;
122+
maxAllowedRewardShare: RevShareInput;
115123
txOptions?: TxOptions;
116124
};
117125

@@ -157,7 +165,7 @@ export type AddIpRequest = {
157165
* Must be between 0 and 100 (where 100% represents 100_000_000).
158166
* @default 100
159167
*/
160-
maxAllowedRewardSharePercentage?: number;
168+
maxAllowedRewardSharePercentage?: RevShareInput;
161169
txOptions?: Omit<TxOptions, "encodedTxDataOnly">;
162170
};
163171

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Address, Hash, Hex } from "viem";
22

33
import { EncodedTxData } from "../../abi/generated";
4-
import { TokenAmountInput } from "../common";
4+
import { DeadlineInput, TokenAmountInput } from "../common";
55
import { TxOptions } from "../options";
66

77
export type IPAccountExecuteRequest = {
@@ -31,11 +31,11 @@ export type IPAccountExecuteWithSigRequest = {
3131
/** The signer of the transaction. */
3232
signer: Address;
3333
/** The deadline of the transaction signature in seconds. */
34-
deadline: number | bigint | string;
34+
deadline: DeadlineInput;
3535
/** The signature of the transaction, EIP-712 encoded. The helper method `getPermissionSignature` supports generating the signature. */
3636
signature: Address;
3737
/** The amount of IP to send. */
38-
value?: number | bigint | string;
38+
value?: number | bigint;
3939
txOptions?: TxOptions;
4040
};
4141

0 commit comments

Comments
 (0)