From 7ac5293bc9e2696f4244311371867cb3c5dfbe31 Mon Sep 17 00:00:00 2001 From: Bonnie Date: Mon, 20 Jan 2025 15:00:32 +0800 Subject: [PATCH 1/3] Refactor LicenseTerms and InnerLicenseTerms --- packages/core-sdk/src/resources/ipAsset.ts | 21 ++++++++--------- packages/core-sdk/src/resources/license.ts | 6 ++--- .../core-sdk/src/types/resources/ipAsset.ts | 12 +++++----- .../core-sdk/src/types/resources/license.ts | 23 +++++++++++-------- .../core-sdk/src/utils/licenseTermsHelper.ts | 14 +++++------ .../test/unit/resources/ipAsset.test.ts | 5 ++-- 6 files changed, 41 insertions(+), 40 deletions(-) diff --git a/packages/core-sdk/src/resources/ipAsset.ts b/packages/core-sdk/src/resources/ipAsset.ts index 843584c3..962252b9 100644 --- a/packages/core-sdk/src/resources/ipAsset.ts +++ b/packages/core-sdk/src/resources/ipAsset.ts @@ -97,11 +97,7 @@ import { import { getRevenueShare, validateLicenseTerms } from "../utils/licenseTermsHelper"; import { getDeadline, getPermissionSignature, getSignature } from "../utils/sign"; import { AccessPermission } from "../types/resources/permission"; -import { - InnerLicensingConfig, - LicenseTerms, - RegisterPILTermsRequest, -} from "../types/resources/license"; +import { InnerLicensingConfig, InnerLicenseTerms } from "../types/resources/license"; import { MAX_ROYALTY_TOKEN, royaltySharesTotalSupply } from "../constants/common"; import { getFunctionSignature } from "../utils/getFunctionSignature"; import { LicensingConfig } from "../types/common"; @@ -773,7 +769,7 @@ export class IPAssetClient { })); // Due to emit event log by sequence, we need to get license terms id from request.args for (let j = 0; j < request.args.length; j++) { - const licenseTerms: LicenseTerms[] = []; + const licenseTerms: InnerLicenseTerms[] = []; const licenseTermsData = request.args[j].licenseTermsData; for (let i = 0; i < licenseTermsData.length; i++) { const licenseTerm = await validateLicenseTerms( @@ -1946,7 +1942,7 @@ export class IPAssetClient { return await this.ipAssetRegistryClient.isRegistered({ id: getAddress(ipId, "ipId") }); } - private async getLicenseTermsId(licenseTerms: LicenseTerms[]): Promise { + private async getLicenseTermsId(licenseTerms: InnerLicenseTerms[]): Promise { const licenseTermsIds: bigint[] = []; for (const licenseTerm of licenseTerms) { const licenseRes = await this.licenseTemplateClient.getLicenseTermsId({ @@ -2070,13 +2066,14 @@ export class IPAssetClient { } private async validateLicenseTermsData( - licenseTermsData: LicenseTermsData[], + licenseTermsData: LicenseTermsData[], ): Promise<{ - licenseTerms: LicenseTerms[]; - licenseTermsData: LicenseTermsData[]; + licenseTerms: InnerLicenseTerms[]; + licenseTermsData: LicenseTermsData[]; }> { - const licenseTerms: LicenseTerms[] = []; - const processedLicenseTermsData: LicenseTermsData[] = []; + const licenseTerms: InnerLicenseTerms[] = []; + const processedLicenseTermsData: LicenseTermsData[] = + []; for (let i = 0; i < licenseTermsData.length; i++) { const licenseTerm = await validateLicenseTerms(licenseTermsData[i].terms, this.rpcClient); licenseTerms.push(licenseTerm); diff --git a/packages/core-sdk/src/resources/license.ts b/packages/core-sdk/src/resources/license.ts index f34972c1..933df9b9 100644 --- a/packages/core-sdk/src/resources/license.ts +++ b/packages/core-sdk/src/resources/license.ts @@ -17,7 +17,6 @@ import { royaltyPolicyLapAddress, } from "../abi/generated"; import { - LicenseTerms, RegisterNonComSocialRemixingPILRequest, RegisterPILResponse, RegisterCommercialUsePILRequest, @@ -29,10 +28,11 @@ import { PIL_TYPE, AttachLicenseTermsResponse, LicenseTermsId, - RegisterPILTermsRequest, + InnerLicenseTerms, PredictMintingLicenseFeeRequest, SetLicensingConfigRequest, SetLicensingConfigResponse, + RegisterPILTermsRequest, } from "../types/resources/license"; import { handleError } from "../utils/errors"; import { @@ -593,7 +593,7 @@ export class LicenseClient { handleError(error, "Failed to set licensing config"); } } - private async getLicenseTermsId(request: LicenseTerms): Promise { + private async getLicenseTermsId(request: InnerLicenseTerms): Promise { const licenseRes = await this.licenseTemplateClient.getLicenseTermsId({ terms: request }); return licenseRes.selectedLicenseTermsId; } diff --git a/packages/core-sdk/src/types/resources/ipAsset.ts b/packages/core-sdk/src/types/resources/ipAsset.ts index ab9ea4c7..f8e6ed3b 100644 --- a/packages/core-sdk/src/types/resources/ipAsset.ts +++ b/packages/core-sdk/src/types/resources/ipAsset.ts @@ -1,7 +1,7 @@ import { Address, Hex } from "viem"; import { TxOptions } from "../options"; -import { RegisterPILTermsRequest } from "./license"; +import { LicenseTerms } from "./license"; import { EncodedTxData } from "../../abi/generated"; import { IpMetadataAndTxOption, LicensingConfig } from "../common"; import { IpMetadataForWorkflow } from "../../utils/getIpMetadataForWorkflow"; @@ -64,7 +64,7 @@ export type LicenseTermsData = { export type MintAndRegisterIpAssetWithPilTermsRequest = { spgNftContract: Address; allowDuplicates: boolean; - licenseTermsData: LicenseTermsData[]; + licenseTermsData: LicenseTermsData[]; recipient?: Address; royaltyPolicyAddress?: Address; } & IpMetadataAndTxOption; @@ -99,7 +99,7 @@ export type RegisterIpAndMakeDerivativeResponse = { export type RegisterIpAndAttachPilTermsRequest = { nftContract: Address; tokenId: bigint | string | number; - licenseTermsData: LicenseTermsData[]; + licenseTermsData: LicenseTermsData[]; deadline?: bigint | number | string; } & IpMetadataAndTxOption; @@ -224,7 +224,7 @@ export type MintAndRegisterIpRequest = { export type RegisterPilTermsAndAttachRequest = { ipId: Address; - licenseTermsData: LicenseTermsData[]; + licenseTermsData: LicenseTermsData[]; deadline?: string | number | bigint; txOptions?: TxOptions; }; @@ -297,7 +297,7 @@ export type BatchRegisterResponse = { export type RegisterIPAndAttachLicenseTermsAndDistributeRoyaltyTokensRequest = { nftContract: Address; tokenId: bigint | string | number; - licenseTermsData: LicenseTermsData[]; + licenseTermsData: LicenseTermsData[]; deadline?: string | number | bigint; royaltyShares: RoyaltyShare[]; txOptions?: Omit; @@ -347,7 +347,7 @@ export type MintAndRegisterIpAndAttachPILTermsAndDistributeRoyaltyTokensRequest spgNftContract: Address; allowDuplicates: boolean; licenseTermsData: { - terms: RegisterPILTermsRequest; + terms: LicenseTerms; licensingConfig: LicensingConfig; }[]; royaltyShares: RoyaltyShare[]; diff --git a/packages/core-sdk/src/types/resources/license.ts b/packages/core-sdk/src/types/resources/license.ts index 0fa3e880..3eaa2178 100644 --- a/packages/core-sdk/src/types/resources/license.ts +++ b/packages/core-sdk/src/types/resources/license.ts @@ -28,9 +28,9 @@ export type LicenseTerms = { /*The address of the royalty policy contract which required to StoryProtocol in advance.*/ royaltyPolicy: Address; /*The default minting fee to be paid when minting a license.*/ - defaultMintingFee: bigint; + defaultMintingFee: bigint | string | number; /*The expiration period of the license.*/ - expiration: bigint; + expiration: bigint | string | number; /*Indicates whether the work can be used commercially or not.*/ commercialUse: boolean; /*Whether attribution is required when reproducing the work commercially or not.*/ @@ -42,7 +42,7 @@ export type LicenseTerms = { /*Percentage of revenue that must be shared with the licensor.*/ commercialRevShare: number; /*The maximum revenue that can be generated from the commercial use of the work.*/ - commercialRevCeiling: bigint; + commercialRevCeiling: bigint | string | number; /*Indicates whether the licensee can create derivatives of his work or not.*/ derivativesAllowed: boolean; /*Indicates whether attribution is required for derivatives of the work or not.*/ @@ -52,21 +52,24 @@ export type LicenseTerms = { /*Indicates whether the licensee must license derivatives of the work under the same terms or not.*/ derivativesReciprocal: boolean; /*The maximum revenue that can be generated from the derivative use of the work.*/ - derivativeRevCeiling: bigint; + derivativeRevCeiling: bigint | string | number; /*The ERC20 token to be used to pay the minting fee. the token must be registered in story protocol.*/ currency: Address; /*The URI of the license terms, which can be used to fetch the offchain license terms.*/ uri: string; }; -export type RegisterPILTermsRequest = Omit< +export type RegisterPILTermsRequest = LicenseTerms & { + txOptions?: TxOptions; +}; + +export type InnerLicenseTerms = Omit< LicenseTerms, "defaultMintingFee" | "expiration" | "commercialRevCeiling" | "derivativeRevCeiling" > & { - defaultMintingFee: bigint | string | number; - expiration: bigint | string | number; - commercialRevCeiling: bigint | string | number; - derivativeRevCeiling: bigint | string | number; - txOptions?: TxOptions; + defaultMintingFee: bigint; + expiration: bigint; + commercialRevCeiling: bigint; + derivativeRevCeiling: bigint; }; export type LicenseTermsIdResponse = bigint; diff --git a/packages/core-sdk/src/utils/licenseTermsHelper.ts b/packages/core-sdk/src/utils/licenseTermsHelper.ts index b5c496fb..71845967 100644 --- a/packages/core-sdk/src/utils/licenseTermsHelper.ts +++ b/packages/core-sdk/src/utils/licenseTermsHelper.ts @@ -1,6 +1,6 @@ import { Address, PublicClient, zeroAddress } from "viem"; -import { PIL_TYPE, LicenseTerms, RegisterPILTermsRequest } from "../types/resources/license"; +import { PIL_TYPE, InnerLicenseTerms, LicenseTerms } from "../types/resources/license"; import { getAddress } from "./utils"; import { RoyaltyModuleReadOnlyClient } from "../abi/generated"; import { MAX_ROYALTY_TOKEN } from "../constants/common"; @@ -13,8 +13,8 @@ export function getLicenseTermByType( royaltyPolicyAddress: Address; commercialRevShare?: number; }, -): LicenseTerms { - const licenseTerms: LicenseTerms = { +): InnerLicenseTerms { + const licenseTerms: InnerLicenseTerms = { transferable: true, royaltyPolicy: zeroAddress, defaultMintingFee: BigInt(0), @@ -77,9 +77,9 @@ export function getLicenseTermByType( } export async function validateLicenseTerms( - params: RegisterPILTermsRequest, + params: LicenseTerms, rpcClient: PublicClient, -): Promise { +): Promise { const { royaltyPolicy, currency } = params; const royaltyModuleReadOnlyClient = new RoyaltyModuleReadOnlyClient(rpcClient); if (getAddress(royaltyPolicy, "params.royaltyPolicy") !== zeroAddress) { @@ -117,7 +117,7 @@ export async function validateLicenseTerms( return object; } -const verifyCommercialUse = (terms: LicenseTerms) => { +const verifyCommercialUse = (terms: InnerLicenseTerms) => { if (!terms.commercialUse) { if (terms.commercialAttribution) { throw new Error("Cannot add commercial attribution when commercial use is disabled."); @@ -146,7 +146,7 @@ const verifyCommercialUse = (terms: LicenseTerms) => { } }; -const verifyDerivatives = (terms: LicenseTerms) => { +const verifyDerivatives = (terms: InnerLicenseTerms) => { if (!terms.derivativesAllowed) { if (terms.derivativesAttribution) { throw new Error("Cannot add derivative attribution when derivative use is disabled."); diff --git a/packages/core-sdk/test/unit/resources/ipAsset.test.ts b/packages/core-sdk/test/unit/resources/ipAsset.test.ts index 86f33d91..845f0578 100644 --- a/packages/core-sdk/test/unit/resources/ipAsset.test.ts +++ b/packages/core-sdk/test/unit/resources/ipAsset.test.ts @@ -1,7 +1,7 @@ import chai from "chai"; import { createMock } from "../testUtils"; import * as sinon from "sinon"; -import { IPAssetClient, LicenseTerms } from "../../../src"; +import { IPAssetClient } from "../../../src"; import { PublicClient, WalletClient, @@ -18,6 +18,7 @@ import { LicenseRegistryReadOnlyClient } from "../../../src/abi/generated"; import { MAX_ROYALTY_TOKEN, royaltySharesTotalSupply } from "../../../src/constants/common"; import { LicensingConfig } from "../../../src/types/common"; import { DerivativeData } from "../../../src/types/resources/ipAsset"; +import { InnerLicenseTerms } from "../../../src/types/resources/license"; const { RoyaltyModuleReadOnlyClient, IpRoyaltyVaultImplReadOnlyClient, @@ -26,7 +27,7 @@ const { const txHash = "0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997"; chai.use(chaiAsPromised); const expect = chai.expect; -const licenseTerms: LicenseTerms = { +const licenseTerms: InnerLicenseTerms = { transferable: true, royaltyPolicy: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c", defaultMintingFee: BigInt(1), From f447b496d77343a055dfd66665c8f1e424c75cee Mon Sep 17 00:00:00 2001 From: Bonnie Date: Tue, 21 Jan 2025 11:10:37 +0800 Subject: [PATCH 2/3] Refactor the license module --- packages/core-sdk/src/index.ts | 5 +- packages/core-sdk/src/resources/PILFlavor.ts | 87 +++++ packages/core-sdk/src/resources/ipAsset.ts | 17 +- packages/core-sdk/src/resources/license.ts | 240 +++--------- .../core-sdk/src/types/resources/ipAsset.ts | 12 +- .../core-sdk/src/types/resources/license.ts | 129 +++---- .../core-sdk/src/utils/licenseTermsHelper.ts | 91 +---- .../core-sdk/test/integration/ipAsset.test.ts | 5 +- .../core-sdk/test/integration/license.test.ts | 68 +--- .../core-sdk/test/integration/royalty.test.ts | 13 +- .../test/unit/resources/ipAsset.test.ts | 4 +- .../test/unit/resources/license.test.ts | 362 ++++-------------- .../unit/utils/licenseTermsHelper.test.ts | 220 +---------- 13 files changed, 343 insertions(+), 910 deletions(-) create mode 100644 packages/core-sdk/src/resources/PILFlavor.ts diff --git a/packages/core-sdk/src/index.ts b/packages/core-sdk/src/index.ts index a1ee2ef0..da7d519d 100644 --- a/packages/core-sdk/src/index.ts +++ b/packages/core-sdk/src/index.ts @@ -62,9 +62,6 @@ export type { } from "./types/resources/ipAsset"; export type { - RegisterNonComSocialRemixingPILRequest, - RegisterCommercialUsePILRequest, - RegisterCommercialRemixPILRequest, RegisterPILTermsRequest, RegisterPILResponse, AttachLicenseTermsRequest, @@ -72,7 +69,7 @@ export type { MintLicenseTokensRequest, MintLicenseTokensResponse, LicenseTermsId, - LicenseTerms, + PILTerms, PredictMintingLicenseFeeRequest, SetLicensingConfigRequest, SetLicensingConfigResponse, diff --git a/packages/core-sdk/src/resources/PILFlavor.ts b/packages/core-sdk/src/resources/PILFlavor.ts new file mode 100644 index 00000000..e96870cc --- /dev/null +++ b/packages/core-sdk/src/resources/PILFlavor.ts @@ -0,0 +1,87 @@ +import { Address, zeroAddress } from "viem"; + +import { InnerPILTerms } from "../types/resources/license"; +import { getAddress } from "../utils/utils"; +import { getRevenueShare } from "../utils/licenseTermsHelper"; + +export class PILFlavor { + static nonComSocialRemixingPIL(): InnerPILTerms { + return { + transferable: true, + royaltyPolicy: zeroAddress, + defaultMintingFee: 0n, + expiration: 0n, + commercialUse: false, + commercialAttribution: false, + commercializerChecker: zeroAddress, + commercializerCheckerData: "0x", + commercialRevShare: 0, + commercialRevCeiling: 0n, + derivativesAllowed: true, + derivativesAttribution: true, + derivativesApproval: false, + derivativesReciprocal: true, + derivativeRevCeiling: 0n, + currency: zeroAddress, + uri: "", + }; + } + + static commercialUsePIL( + defaultMintingFee: bigint | number | string, + royaltyPolicy: Address, + currency: Address, + ): InnerPILTerms { + if (defaultMintingFee === undefined || currency === undefined || royaltyPolicy === undefined) { + throw new Error( + "DefaultMintingFee, currency and royaltyPolicy are required for commercial use PIL.", + ); + } + return { + transferable: true, + royaltyPolicy: getAddress(royaltyPolicy, "royaltyPolicyLAPAddress"), + defaultMintingFee: BigInt(defaultMintingFee), + expiration: 0n, + commercialUse: true, + commercialAttribution: true, + commercializerChecker: zeroAddress, + commercializerCheckerData: "0x", + commercialRevShare: 0, + commercialRevCeiling: 0n, + derivativesAllowed: true, + derivativesAttribution: true, + derivativesApproval: false, + derivativesReciprocal: false, + derivativeRevCeiling: 0n, + currency: getAddress(currency, "currency"), + uri: "", + }; + } + + static commercialRemixPIL( + defaultMintingFee: bigint | number | string, + royaltyPolicy: Address, + currency: Address, + commercialRevShare: number | string, + ): InnerPILTerms { + return { + transferable: true, + royaltyPolicy: getAddress(royaltyPolicy, "royaltyPolicyLAPAddress"), + defaultMintingFee: BigInt(defaultMintingFee), + expiration: 0n, + commercialUse: true, + commercialAttribution: true, + commercializerChecker: zeroAddress, + commercializerCheckerData: "0x", + commercialRevShare: getRevenueShare(commercialRevShare), + commercialRevCeiling: 0n, + derivativesAllowed: true, + derivativesAttribution: true, + derivativesApproval: false, + derivativesReciprocal: true, + derivativeRevCeiling: 0n, + currency: getAddress(currency, "currency"), + uri: "", + }; + } +} diff --git a/packages/core-sdk/src/resources/ipAsset.ts b/packages/core-sdk/src/resources/ipAsset.ts index 962252b9..78293aa8 100644 --- a/packages/core-sdk/src/resources/ipAsset.ts +++ b/packages/core-sdk/src/resources/ipAsset.ts @@ -97,7 +97,7 @@ import { import { getRevenueShare, validateLicenseTerms } from "../utils/licenseTermsHelper"; import { getDeadline, getPermissionSignature, getSignature } from "../utils/sign"; import { AccessPermission } from "../types/resources/permission"; -import { InnerLicensingConfig, InnerLicenseTerms } from "../types/resources/license"; +import { InnerPILTerms, InnerLicensingConfig, PILTerms } from "../types/resources/license"; import { MAX_ROYALTY_TOKEN, royaltySharesTotalSupply } from "../constants/common"; import { getFunctionSignature } from "../utils/getFunctionSignature"; import { LicensingConfig } from "../types/common"; @@ -769,7 +769,7 @@ export class IPAssetClient { })); // Due to emit event log by sequence, we need to get license terms id from request.args for (let j = 0; j < request.args.length; j++) { - const licenseTerms: InnerLicenseTerms[] = []; + const licenseTerms: InnerPILTerms[] = []; const licenseTermsData = request.args[j].licenseTermsData; for (let i = 0; i < licenseTermsData.length; i++) { const licenseTerm = await validateLicenseTerms( @@ -1942,7 +1942,7 @@ export class IPAssetClient { return await this.ipAssetRegistryClient.isRegistered({ id: getAddress(ipId, "ipId") }); } - private async getLicenseTermsId(licenseTerms: InnerLicenseTerms[]): Promise { + private async getLicenseTermsId(licenseTerms: InnerPILTerms[]): Promise { const licenseTermsIds: bigint[] = []; for (const licenseTerm of licenseTerms) { const licenseRes = await this.licenseTemplateClient.getLicenseTermsId({ @@ -2066,14 +2066,13 @@ export class IPAssetClient { } private async validateLicenseTermsData( - licenseTermsData: LicenseTermsData[], + licenseTermsData: LicenseTermsData[], ): Promise<{ - licenseTerms: InnerLicenseTerms[]; - licenseTermsData: LicenseTermsData[]; + licenseTerms: InnerPILTerms[]; + licenseTermsData: LicenseTermsData[]; }> { - const licenseTerms: InnerLicenseTerms[] = []; - const processedLicenseTermsData: LicenseTermsData[] = - []; + const licenseTerms: InnerPILTerms[] = []; + const processedLicenseTermsData: LicenseTermsData[] = []; for (let i = 0; i < licenseTermsData.length; i++) { const licenseTerm = await validateLicenseTerms(licenseTermsData[i].terms, this.rpcClient); licenseTerms.push(licenseTerm); diff --git a/packages/core-sdk/src/resources/license.ts b/packages/core-sdk/src/resources/license.ts index 933df9b9..d9811167 100644 --- a/packages/core-sdk/src/resources/license.ts +++ b/packages/core-sdk/src/resources/license.ts @@ -14,13 +14,9 @@ import { PiLicenseTemplateGetLicenseTermsResponse, PiLicenseTemplateReadOnlyClient, SimpleWalletClient, - royaltyPolicyLapAddress, } from "../abi/generated"; import { - RegisterNonComSocialRemixingPILRequest, RegisterPILResponse, - RegisterCommercialUsePILRequest, - RegisterCommercialRemixPILRequest, AttachLicenseTermsRequest, LicenseTermsIdResponse, MintLicenseTokensRequest, @@ -28,20 +24,20 @@ import { PIL_TYPE, AttachLicenseTermsResponse, LicenseTermsId, - InnerLicenseTerms, + InnerPILTerms, PredictMintingLicenseFeeRequest, SetLicensingConfigRequest, SetLicensingConfigResponse, RegisterPILTermsRequest, + CommercialLicenseTerms, + CommercialRemixLicenseTerms, + PILTerms, } from "../types/resources/license"; import { handleError } from "../utils/errors"; -import { - getLicenseTermByType, - getRevenueShare, - validateLicenseTerms, -} from "../utils/licenseTermsHelper"; -import { chain, getAddress } from "../utils/utils"; +import { getRevenueShare, validateLicenseTerms } from "../utils/licenseTermsHelper"; +import { getAddress } from "../utils/utils"; import { SupportedChainIds } from "../types/config"; +import { PILFlavor } from "./PILFlavor"; export class LicenseClient { public licenseRegistryClient: LicenseRegistryEventClient; @@ -69,207 +65,50 @@ export class LicenseClient { } /** * Registers new license terms and return the ID of the newly registered license terms. - * @param request - The request object that contains all data needed to register a license term. - * @param request.transferable Indicates whether the license is transferable or not. - * @param request.royaltyPolicy The address of the royalty policy contract which required to StoryProtocol in advance. - * @param request.mintingFee The fee to be paid when minting a license. - * @param request.expiration The expiration period of the license. - * @param request.commercialUse Indicates whether the work can be used commercially or not. - * @param request.commercialAttribution Whether attribution is required when reproducing the work commercially or not. - * @param request.commercializerChecker Commercializers that are allowed to commercially exploit the work. If zero address, then no restrictions is enforced. - * @param request.commercializerCheckerData The data to be passed to the commercializer checker contract. - * @param request.commercialRevShare Percentage of revenue that must be shared with the licensor. - * @param request.commercialRevCeiling The maximum revenue that can be generated from the commercial use of the work. - * @param request.derivativesAllowed Indicates whether the licensee can create derivatives of his work or not. - * @param request.derivativesAttribution Indicates whether attribution is required for derivatives of the work or not. - * @param request.derivativesApproval Indicates whether the licensor must approve derivatives of the work before they can be linked to the licensor IP ID or not. - * @param request.derivativesReciprocal Indicates whether the licensee must license derivatives of the work under the same terms or not. - * @param request.derivativeRevCeiling The maximum revenue that can be generated from the derivative use of the work. - * @param request.currency The ERC20 token to be used to pay the minting fee. the token must be registered in story protocol. - * @param request.uri The URI of the license terms, which can be used to fetch the offchain license terms. - * @param request.txOptions - [Optional] transaction. This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property. - * @returns A Promise that resolves to a transaction hash, and if encodedTxDataOnly is true, includes encoded transaction data, and if waitForTransaction is true, includes license terms Id. - * @emits LicenseTermsRegistered (licenseTermsId, licenseTemplate, licenseTerms); - */ - public async registerPILTerms(request: RegisterPILTermsRequest): Promise { - try { - const object = await validateLicenseTerms(request, this.rpcClient); - const licenseTermsId = await this.getLicenseTermsId(object); - if (licenseTermsId !== 0n) { - return { licenseTermsId: licenseTermsId }; - } - if (request?.txOptions?.encodedTxDataOnly) { - return { - encodedTxData: this.licenseTemplateClient.registerLicenseTermsEncode({ - terms: object, - }), - }; - } else { - const txHash = await this.licenseTemplateClient.registerLicenseTerms({ - terms: object, - }); - if (request?.txOptions?.waitForTransaction) { - const txReceipt = await this.rpcClient.waitForTransactionReceipt({ - ...request.txOptions, - hash: txHash, - }); - const targetLogs = - this.licenseTemplateClient.parseTxLicenseTermsRegisteredEvent(txReceipt); - return { txHash: txHash, licenseTermsId: targetLogs[0].licenseTermsId }; - } else { - return { txHash: txHash }; - } - } - } catch (error) { - handleError(error, "Failed to register license terms"); - } - } - /** - * Convenient function to register a PIL non commercial social remix license to the registry - * @param request - [Optional] The request object that contains all data needed to register a PIL non commercial social remix license. - * @param request.txOptions - [Optional] transaction. This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property. - * @returns A Promise that resolves to a transaction hash, and if encodedTxDataOnly is true, includes encoded transaction data, and if waitForTransaction is true, includes license terms Id. - * @emits LicenseTermsRegistered (licenseTermsId, licenseTemplate, licenseTerms); - */ - public async registerNonComSocialRemixingPIL( - request?: RegisterNonComSocialRemixingPILRequest, - ): Promise { - try { - const licenseTerms = getLicenseTermByType(PIL_TYPE.NON_COMMERCIAL_REMIX); - const licenseTermsId = await this.getLicenseTermsId(licenseTerms); - if (licenseTermsId !== 0n) { - return { licenseTermsId: licenseTermsId }; - } - if (request?.txOptions?.encodedTxDataOnly) { - return { - encodedTxData: this.licenseTemplateClient.registerLicenseTermsEncode({ - terms: licenseTerms, - }), - }; - } else { - const txHash = await this.licenseTemplateClient.registerLicenseTerms({ - terms: licenseTerms, - }); - if (request?.txOptions?.waitForTransaction) { - const txReceipt = await this.rpcClient.waitForTransactionReceipt({ - ...request.txOptions, - hash: txHash, - }); - const targetLogs = - this.licenseTemplateClient.parseTxLicenseTermsRegisteredEvent(txReceipt); - return { txHash: txHash, licenseTermsId: targetLogs[0].licenseTermsId }; - } else { - return { txHash: txHash }; - } - } - } catch (error) { - handleError(error, "Failed to register non commercial social remixing PIL"); - } - } - /** - * Convenient function to register a PIL commercial use license to the registry. - * @param request - The request object that contains all data needed to register a PIL commercial use license. - * @param request.defaultMintingFee The fee to be paid when minting a license. - * @param request.currency The ERC20 token to be used to pay the minting fee and the token must be registered in story protocol. - * @param request.royaltyPolicyAddress [Optional] The address of the royalty policy contract, default value is LAP. - * @param request.txOptions - [Optional] transaction. This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property. + * If terms and type are both not provided, it will return the license terms ID of the no commercial license terms. + * It will emit LicenseTermsRegistered (licenseTermsId, licenseTemplate, licenseTerms). * @returns A Promise that resolves to a transaction hash, and if encodedTxDataOnly is true, includes encoded transaction data, and if waitForTransaction is true, includes license terms Id. - * @emits LicenseTermsRegistered (licenseTermsId, licenseTemplate, licenseTerms); */ - public async registerCommercialUsePIL( - request: RegisterCommercialUsePILRequest, + public async registerPILTerms( + request: RegisterPILTermsRequest, ): Promise { try { - const licenseTerms = getLicenseTermByType(PIL_TYPE.COMMERCIAL_USE, { - defaultMintingFee: request.defaultMintingFee, - currency: request.currency, - royaltyPolicyAddress: - (request.royaltyPolicyAddress && - getAddress(request.royaltyPolicyAddress, "request.royaltyPolicyAddress")) || - royaltyPolicyLapAddress[chain[this.chainId]], - }); - const licenseTermsId = await this.getLicenseTermsId(licenseTerms); - if (licenseTermsId !== 0n) { - return { licenseTermsId: licenseTermsId }; - } - if (request.txOptions?.encodedTxDataOnly) { - return { - encodedTxData: this.licenseTemplateClient.registerLicenseTermsEncode({ - terms: licenseTerms, - }), - }; + let terms: InnerPILTerms; + if (!request.terms && !request.PILType) { + terms = PILFlavor.nonComSocialRemixingPIL(); + } else if (request.PILType !== undefined) { + terms = this.createTerms(request.PILType, request.terms); } else { - const txHash = await this.licenseTemplateClient.registerLicenseTerms({ - terms: licenseTerms, - }); - if (request.txOptions?.waitForTransaction) { - const txReceipt = await this.rpcClient.waitForTransactionReceipt({ - ...request.txOptions, - hash: txHash, - }); - const targetLogs = - this.licenseTemplateClient.parseTxLicenseTermsRegisteredEvent(txReceipt); - return { txHash: txHash, licenseTermsId: targetLogs[0].licenseTermsId }; - } else { - return { txHash: txHash }; - } + terms = await validateLicenseTerms(request.terms as PILTerms, this.rpcClient); } - } catch (error) { - handleError(error, "Failed to register commercial use PIL"); - } - } - /** - * Convenient function to register a PIL commercial Remix license to the registry. - * @param request - The request object that contains all data needed to register license. - * @param request.defaultMintingFee The fee to be paid when minting a license. - * @param request.commercialRevShare Percentage of revenue that must be shared with the licensor. - * @param request.currency The ERC20 token to be used to pay the minting fee. the token must be registered in story protocol. - * @param request.royaltyPolicyAddress [Optional] The address of the royalty policy contract, default value is LAP. - * @param request.txOptions - [Optional] transaction. This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property. - * @returns A Promise that resolves to a transaction hash, and if encodedTxDataOnly is true, includes encoded transaction data, and if waitForTransaction is true, includes license terms Id. - * @emits LicenseTermsRegistered (licenseTermsId, licenseTemplate, licenseTerms); - */ - public async registerCommercialRemixPIL( - request: RegisterCommercialRemixPILRequest, - ): Promise { - try { - const licenseTerms = getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { - defaultMintingFee: request.defaultMintingFee, - currency: request.currency, - royaltyPolicyAddress: - (request.royaltyPolicyAddress && - getAddress(request.royaltyPolicyAddress, "request.royaltyPolicyAddress")) || - royaltyPolicyLapAddress[chain[this.chainId]], - commercialRevShare: request.commercialRevShare, - }); - const licenseTermsId = await this.getLicenseTermsId(licenseTerms); + const licenseTermsId = await this.getLicenseTermsId(terms); if (licenseTermsId !== 0n) { return { licenseTermsId: licenseTermsId }; } - if (request.txOptions?.encodedTxDataOnly) { + if (request?.txOptions?.encodedTxDataOnly === true) { return { encodedTxData: this.licenseTemplateClient.registerLicenseTermsEncode({ - terms: licenseTerms, + terms: terms, }), }; } else { const txHash = await this.licenseTemplateClient.registerLicenseTerms({ - terms: licenseTerms, + terms: terms, }); - if (request.txOptions?.waitForTransaction) { + if (request?.txOptions?.waitForTransaction) { const txReceipt = await this.rpcClient.waitForTransactionReceipt({ ...request.txOptions, hash: txHash, }); const targetLogs = this.licenseTemplateClient.parseTxLicenseTermsRegisteredEvent(txReceipt); - return { txHash: txHash, licenseTermsId: targetLogs[0].licenseTermsId }; + return { txHash, licenseTermsId: targetLogs[0].licenseTermsId }; } else { - return { txHash: txHash }; + return { txHash }; } } } catch (error) { - handleError(error, "Failed to register commercial remix PIL"); + handleError(error, "Failed to register license terms"); } } @@ -593,8 +432,35 @@ export class LicenseClient { handleError(error, "Failed to set licensing config"); } } - private async getLicenseTermsId(request: InnerLicenseTerms): Promise { + private async getLicenseTermsId(request: InnerPILTerms): Promise { const licenseRes = await this.licenseTemplateClient.getLicenseTermsId({ terms: request }); return licenseRes.selectedLicenseTermsId; } + private createTerms( + PILType: PIL_TYPE, + terms: RegisterPILTermsRequest["terms"], + ): InnerPILTerms { + let innerTerms: InnerPILTerms; + switch (PILType) { + case PIL_TYPE.NON_COMMERCIAL_REMIX: + innerTerms = PILFlavor.nonComSocialRemixingPIL(); + break; + case PIL_TYPE.COMMERCIAL_USE: + innerTerms = PILFlavor.commercialUsePIL( + (terms as CommercialLicenseTerms).defaultMintingFee, + (terms as CommercialLicenseTerms).currency, + (terms as CommercialLicenseTerms).royaltyPolicy, + ); + break; + case PIL_TYPE.COMMERCIAL_REMIX: + innerTerms = PILFlavor.commercialRemixPIL( + (terms as CommercialRemixLicenseTerms).defaultMintingFee, + (terms as CommercialRemixLicenseTerms).royaltyPolicy, + (terms as CommercialRemixLicenseTerms).currency, + (terms as CommercialRemixLicenseTerms).commercialRevShare, + ); + break; + } + return innerTerms; + } } diff --git a/packages/core-sdk/src/types/resources/ipAsset.ts b/packages/core-sdk/src/types/resources/ipAsset.ts index f8e6ed3b..73b7603b 100644 --- a/packages/core-sdk/src/types/resources/ipAsset.ts +++ b/packages/core-sdk/src/types/resources/ipAsset.ts @@ -1,7 +1,7 @@ import { Address, Hex } from "viem"; import { TxOptions } from "../options"; -import { LicenseTerms } from "./license"; +import { PILTerms } from "./license"; import { EncodedTxData } from "../../abi/generated"; import { IpMetadataAndTxOption, LicensingConfig } from "../common"; import { IpMetadataForWorkflow } from "../../utils/getIpMetadataForWorkflow"; @@ -64,7 +64,7 @@ export type LicenseTermsData = { export type MintAndRegisterIpAssetWithPilTermsRequest = { spgNftContract: Address; allowDuplicates: boolean; - licenseTermsData: LicenseTermsData[]; + licenseTermsData: LicenseTermsData[]; recipient?: Address; royaltyPolicyAddress?: Address; } & IpMetadataAndTxOption; @@ -99,7 +99,7 @@ export type RegisterIpAndMakeDerivativeResponse = { export type RegisterIpAndAttachPilTermsRequest = { nftContract: Address; tokenId: bigint | string | number; - licenseTermsData: LicenseTermsData[]; + licenseTermsData: LicenseTermsData[]; deadline?: bigint | number | string; } & IpMetadataAndTxOption; @@ -224,7 +224,7 @@ export type MintAndRegisterIpRequest = { export type RegisterPilTermsAndAttachRequest = { ipId: Address; - licenseTermsData: LicenseTermsData[]; + licenseTermsData: LicenseTermsData[]; deadline?: string | number | bigint; txOptions?: TxOptions; }; @@ -297,7 +297,7 @@ export type BatchRegisterResponse = { export type RegisterIPAndAttachLicenseTermsAndDistributeRoyaltyTokensRequest = { nftContract: Address; tokenId: bigint | string | number; - licenseTermsData: LicenseTermsData[]; + licenseTermsData: LicenseTermsData[]; deadline?: string | number | bigint; royaltyShares: RoyaltyShare[]; txOptions?: Omit; @@ -347,7 +347,7 @@ export type MintAndRegisterIpAndAttachPILTermsAndDistributeRoyaltyTokensRequest spgNftContract: Address; allowDuplicates: boolean; licenseTermsData: { - terms: LicenseTerms; + terms: PILTerms; licensingConfig: LicensingConfig; }[]; royaltyShares: RoyaltyShare[]; diff --git a/packages/core-sdk/src/types/resources/license.ts b/packages/core-sdk/src/types/resources/license.ts index 3eaa2178..273a4fee 100644 --- a/packages/core-sdk/src/types/resources/license.ts +++ b/packages/core-sdk/src/types/resources/license.ts @@ -4,95 +4,89 @@ import { TxOptions } from "../options"; import { EncodedTxData } from "../../abi/generated"; import { LicensingConfig } from "../common"; -export type LicenseApiResponse = { - data: License; -}; - -export type License = { - id: string; - policyId: string; - licensorIpId: Address; -}; - -export type RegisterNonComSocialRemixingPILRequest = { - txOptions?: TxOptions; -}; +export interface CommercialLicenseTerms { + /** The default minting fee to be paid when minting a license.*/ + defaultMintingFee: bigint | string | number; + /** The ERC20 token to be used to pay the minting fee. The token must be registered in story protocol.*/ + currency: Address; + /** The address of the royalty policy contract which required to StoryProtocol in advance.*/ + royaltyPolicy: Address; +} +export interface CommercialRemixLicenseTerms extends CommercialLicenseTerms { + /** Percentage of revenue that must be shared with the licensor.*/ + commercialRevShare: number | string; +} /** * This structure defines the terms for a Programmable IP License (PIL). These terms can be attached to IP Assets. The legal document of the PIL can be found in this repository. - * @type LicenseTerms + * @type PILTerms **/ -export type LicenseTerms = { - /*Indicates whether the license is transferable or not.*/ +export interface PILTerms extends CommercialLicenseTerms, CommercialRemixLicenseTerms { + /** Indicates whether the license is transferable or not.*/ transferable: boolean; - /*The address of the royalty policy contract which required to StoryProtocol in advance.*/ - royaltyPolicy: Address; - /*The default minting fee to be paid when minting a license.*/ - defaultMintingFee: bigint | string | number; - /*The expiration period of the license.*/ + /** The expiration period of the license.*/ expiration: bigint | string | number; - /*Indicates whether the work can be used commercially or not.*/ + /** Indicates whether the work can be used commercially or not.*/ commercialUse: boolean; - /*Whether attribution is required when reproducing the work commercially or not.*/ + /** Whether attribution is required when reproducing the work commercially or not.*/ commercialAttribution: boolean; - /*Commercializers that are allowed to commercially exploit the work. If zero address, then no restrictions is enforced.*/ + /** Commercializers that are allowed to commercially exploit the work. If zero address, then no restrictions is enforced.*/ commercializerChecker: Address; - /*The data to be passed to the commercializer checker contract.*/ + /** The data to be passed to the commercializer checker contract.*/ commercializerCheckerData: Address; - /*Percentage of revenue that must be shared with the licensor.*/ - commercialRevShare: number; - /*The maximum revenue that can be generated from the commercial use of the work.*/ + /** The maximum revenue that can be generated from the commercial use of the work.*/ commercialRevCeiling: bigint | string | number; - /*Indicates whether the licensee can create derivatives of his work or not.*/ + /** Indicates whether the licensee can create derivatives of his work or not.*/ derivativesAllowed: boolean; - /*Indicates whether attribution is required for derivatives of the work or not.*/ + /** Indicates whether attribution is required for derivatives of the work or not.*/ derivativesAttribution: boolean; - /*Indicates whether the licensor must approve derivatives of the work before they can be linked to the licensor IP ID or not.*/ + /** Indicates whether the licensor must approve derivatives of the work before they can be linked to the licensor IP ID or not.*/ derivativesApproval: boolean; - /*Indicates whether the licensee must license derivatives of the work under the same terms or not.*/ + /** Indicates whether the licensee must license derivatives of the work under the same terms or not.*/ derivativesReciprocal: boolean; - /*The maximum revenue that can be generated from the derivative use of the work.*/ + /** The maximum revenue that can be generated from the derivative use of the work.*/ derivativeRevCeiling: bigint | string | number; - /*The ERC20 token to be used to pay the minting fee. the token must be registered in story protocol.*/ - currency: Address; - /*The URI of the license terms, which can be used to fetch the offchain license terms.*/ + /** The URI of the license terms, which can be used to fetch the offchain license terms.*/ uri: string; -}; -export type RegisterPILTermsRequest = LicenseTerms & { +} +/** + * The request object that contains all data needed to register a license term. + */ +export type RegisterPILTermsRequest = { + /** The license terms to be registered. */ + terms: + | (PILType extends PIL_TYPE.COMMERCIAL_USE ? CommercialLicenseTerms : never) + | (PILType extends PIL_TYPE.COMMERCIAL_REMIX ? CommercialRemixLicenseTerms : never) + | (PILType extends PIL_TYPE.NON_COMMERCIAL_REMIX ? undefined : never) + | PILTerms; + /** The type of the license terms to be registered, including no-commercial, commercial,commercial remix. */ + PILType?: PILType; + /** This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property. */ txOptions?: TxOptions; }; - -export type InnerLicenseTerms = Omit< - LicenseTerms, - "defaultMintingFee" | "expiration" | "commercialRevCeiling" | "derivativeRevCeiling" -> & { - defaultMintingFee: bigint; - expiration: bigint; - commercialRevCeiling: bigint; - derivativeRevCeiling: bigint; -}; -export type LicenseTermsIdResponse = bigint; - export type RegisterPILResponse = { + /** The ID of the registered license terms. */ licenseTermsId?: bigint; + /** The transaction hash of the register PIL terms. */ txHash?: string; + /** The encoded transaction data of the register PIL terms. */ encodedTxData?: EncodedTxData; }; - -export type RegisterCommercialUsePILRequest = { - defaultMintingFee: string | number | bigint; - currency: Address; - royaltyPolicyAddress?: Address; - txOptions?: TxOptions; -}; - -export type RegisterCommercialRemixPILRequest = { - defaultMintingFee: string | number | bigint; +export type InnerPILTerms = Omit< + PILTerms, + | "defaultMintingFee" + | "expiration" + | "commercialRevCeiling" + | "derivativeRevCeiling" + | "commercialRevShare" +> & { + defaultMintingFee: bigint; + expiration: bigint; + commercialRevCeiling: bigint; + derivativeRevCeiling: bigint; commercialRevShare: number; - currency: Address; - royaltyPolicyAddress?: Address; - txOptions?: TxOptions; }; +export type LicenseTermsIdResponse = bigint; export type AttachLicenseTermsRequest = { ipId: Address; @@ -123,10 +117,17 @@ export type MintLicenseTokensResponse = { txHash?: string; encodedTxData?: EncodedTxData; }; - +/** + * The type of the Programmable IP License (PIL). + * @enum {number} + * @readonly + */ export enum PIL_TYPE { + /*Non commercial remix*/ NON_COMMERCIAL_REMIX, + /** Commercial use*/ COMMERCIAL_USE, + /** Commercial remix*/ COMMERCIAL_REMIX, } diff --git a/packages/core-sdk/src/utils/licenseTermsHelper.ts b/packages/core-sdk/src/utils/licenseTermsHelper.ts index 71845967..1c832d8f 100644 --- a/packages/core-sdk/src/utils/licenseTermsHelper.ts +++ b/packages/core-sdk/src/utils/licenseTermsHelper.ts @@ -1,85 +1,14 @@ -import { Address, PublicClient, zeroAddress } from "viem"; +import { PublicClient, zeroAddress } from "viem"; -import { PIL_TYPE, InnerLicenseTerms, LicenseTerms } from "../types/resources/license"; +import { InnerPILTerms, PILTerms } from "../types/resources/license"; import { getAddress } from "./utils"; import { RoyaltyModuleReadOnlyClient } from "../abi/generated"; import { MAX_ROYALTY_TOKEN } from "../constants/common"; -export function getLicenseTermByType( - type: PIL_TYPE, - term?: { - defaultMintingFee?: string | number | bigint; - currency?: Address; - royaltyPolicyAddress: Address; - commercialRevShare?: number; - }, -): InnerLicenseTerms { - const licenseTerms: InnerLicenseTerms = { - transferable: true, - royaltyPolicy: zeroAddress, - defaultMintingFee: BigInt(0), - expiration: BigInt(0), - commercialUse: false, - commercialAttribution: false, - commercializerChecker: zeroAddress, - commercializerCheckerData: zeroAddress, - commercialRevShare: 0, - commercialRevCeiling: BigInt(0), - derivativesAllowed: true, - derivativesAttribution: true, - derivativesApproval: false, - derivativesReciprocal: true, - derivativeRevCeiling: BigInt(0), - currency: zeroAddress, - uri: "", - }; - if (type === PIL_TYPE.NON_COMMERCIAL_REMIX) { - licenseTerms.commercializerCheckerData = "0x"; - return licenseTerms; - } else if (type === PIL_TYPE.COMMERCIAL_USE) { - if (!term || term.defaultMintingFee === undefined || term.currency === undefined) { - throw new Error("DefaultMintingFee, currency are required for commercial use PIL."); - } - licenseTerms.royaltyPolicy = getAddress( - term.royaltyPolicyAddress, - "term.royaltyPolicyLAPAddress", - ); - licenseTerms.defaultMintingFee = BigInt(term.defaultMintingFee); - licenseTerms.commercialUse = true; - licenseTerms.commercialAttribution = true; - licenseTerms.derivativesReciprocal = false; - licenseTerms.currency = getAddress(term.currency, "term.currency"); - return licenseTerms; - } else { - if ( - !term || - term.defaultMintingFee === undefined || - term.currency === undefined || - term.commercialRevShare === undefined - ) { - throw new Error( - "DefaultMintingFee, currency and commercialRevShare are required for commercial remix PIL.", - ); - } - licenseTerms.royaltyPolicy = getAddress( - term.royaltyPolicyAddress, - "term.royaltyPolicyLAPAddress", - ); - licenseTerms.defaultMintingFee = BigInt(term.defaultMintingFee); - licenseTerms.commercialUse = true; - licenseTerms.commercialAttribution = true; - - licenseTerms.commercialRevShare = getRevenueShare(term.commercialRevShare); - licenseTerms.derivativesReciprocal = true; - licenseTerms.currency = getAddress(term.currency, "term.currency"); - return licenseTerms; - } -} - export async function validateLicenseTerms( - params: LicenseTerms, + params: PILTerms, rpcClient: PublicClient, -): Promise { +): Promise { const { royaltyPolicy, currency } = params; const royaltyModuleReadOnlyClient = new RoyaltyModuleReadOnlyClient(rpcClient); if (getAddress(royaltyPolicy, "params.royaltyPolicy") !== zeroAddress) { @@ -106,18 +35,14 @@ export async function validateLicenseTerms( expiration: BigInt(params.expiration), commercialRevCeiling: BigInt(params.commercialRevCeiling), derivativeRevCeiling: BigInt(params.derivativeRevCeiling), - }; + commercialRevShare: getRevenueShare(params.commercialRevShare), + } as const; verifyCommercialUse(object); verifyDerivatives(object); - if (object.commercialRevShare < 0 || object.commercialRevShare > 100) { - throw new Error("CommercialRevShare should be between 0 and 100."); - } else { - object.commercialRevShare = (object.commercialRevShare / 100) * 100000000; - } return object; } -const verifyCommercialUse = (terms: InnerLicenseTerms) => { +const verifyCommercialUse = (terms: InnerPILTerms) => { if (!terms.commercialUse) { if (terms.commercialAttribution) { throw new Error("Cannot add commercial attribution when commercial use is disabled."); @@ -146,7 +71,7 @@ const verifyCommercialUse = (terms: InnerLicenseTerms) => { } }; -const verifyDerivatives = (terms: InnerLicenseTerms) => { +const verifyDerivatives = (terms: InnerPILTerms) => { if (!terms.derivativesAllowed) { if (terms.derivativesAttribution) { throw new Error("Cannot add derivative attribution when derivative use is disabled."); diff --git a/packages/core-sdk/test/integration/ipAsset.test.ts b/packages/core-sdk/test/integration/ipAsset.test.ts index 3a624d57..5f944ea4 100644 --- a/packages/core-sdk/test/integration/ipAsset.test.ts +++ b/packages/core-sdk/test/integration/ipAsset.test.ts @@ -1,5 +1,5 @@ import chai from "chai"; -import { StoryClient } from "../../src"; +import { PIL_TYPE, StoryClient } from "../../src"; import { Address, Hex, toHex, zeroAddress } from "viem"; import chaiAsPromised from "chai-as-promised"; import { @@ -28,7 +28,8 @@ describe("IP Asset Functions ", () => { let parentIpId: Hex; before(async () => { client = getStoryClient(); - const res = await client.license.registerNonComSocialRemixingPIL({ + const res = await client.license.registerPILTerms({ + terms: undefined, txOptions: { waitForTransaction: true, }, diff --git a/packages/core-sdk/test/integration/license.test.ts b/packages/core-sdk/test/integration/license.test.ts index 89b9c4b8..a27849a2 100644 --- a/packages/core-sdk/test/integration/license.test.ts +++ b/packages/core-sdk/test/integration/license.test.ts @@ -1,28 +1,30 @@ import chai from "chai"; -import { StoryClient } from "../../src"; +import { PIL_TYPE, StoryClient } from "../../src"; import { Hex, zeroAddress } from "viem"; import chaiAsPromised from "chai-as-promised"; import { mockERC721, getStoryClient, getTokenId, odyssey } from "./utils/util"; import { MockERC20 } from "./utils/mockERC20"; -import { licensingModuleAddress } from "../../src/abi/generated"; +import { licensingModuleAddress, royaltyPolicyLapAddress } from "../../src/abi/generated"; chai.use(chaiAsPromised); const expect = chai.expect; describe("License Functions", () => { let client: StoryClient; + let licenseId: bigint; before(() => { client = getStoryClient(); }); - describe("register license with different types", async () => { - it("should not throw error when register license ", async () => { - const result = await client.license.registerPILTerms({ + + it("should not throw error when register license ", async () => { + const result = await client.license.registerPILTerms({ + terms: { defaultMintingFee: "1", currency: MockERC20.address, transferable: false, - royaltyPolicy: zeroAddress, - commercialUse: false, + royaltyPolicy: royaltyPolicyLapAddress[odyssey], + commercialUse: true, commercialAttribution: false, commercializerChecker: zeroAddress, commercializerCheckerData: "0x", @@ -35,47 +37,16 @@ describe("License Functions", () => { expiration: "", commercialRevCeiling: "", derivativeRevCeiling: "", - txOptions: { - waitForTransaction: true, - }, - }); - expect(result.licenseTermsId).to.be.a("bigint"); - }); - it("should not throw error when register license with non commercial social remixing PIL", async () => { - const result = await client.license.registerNonComSocialRemixingPIL({ - txOptions: { - waitForTransaction: true, - }, - }); - expect(result.licenseTermsId).to.be.a("bigint"); - }); - it("should not throw error when register license with commercial use", async () => { - const result = await client.license.registerCommercialUsePIL({ - defaultMintingFee: "1", - currency: MockERC20.address, - txOptions: { - waitForTransaction: true, - }, - }); - expect(result.licenseTermsId).to.be.a("bigint"); - }); - - it("should not throw error when register license with commercial Remix use", async () => { - const result = await client.license.registerCommercialRemixPIL({ - defaultMintingFee: "1", - commercialRevShare: 100, - currency: MockERC20.address, - txOptions: { - waitForTransaction: true, - }, - }); - expect(result.licenseTermsId).to.be.a("bigint"); + }, + txOptions: { + waitForTransaction: true, + }, }); + expect(result.licenseTermsId).to.be.a("bigint"); + licenseId = result.licenseTermsId!; }); - describe("attach License Terms and mint license tokens", async () => { let ipId: Hex; - let licenseId: bigint; let tokenId; before(async () => { tokenId = await getTokenId(); @@ -89,15 +60,6 @@ describe("License Functions", () => { const mockERC20 = new MockERC20(); await mockERC20.approve(licensingModuleAddress[odyssey]); ipId = registerResult.ipId!; - const registerLicenseResult = await client.license.registerCommercialRemixPIL({ - defaultMintingFee: "1", - commercialRevShare: 100, - currency: MockERC20.address, - txOptions: { - waitForTransaction: true, - }, - }); - licenseId = registerLicenseResult.licenseTermsId!; }); it("should not throw error when attach License Terms", async () => { diff --git a/packages/core-sdk/test/integration/royalty.test.ts b/packages/core-sdk/test/integration/royalty.test.ts index f1ad0996..a3c3ade4 100644 --- a/packages/core-sdk/test/integration/royalty.test.ts +++ b/packages/core-sdk/test/integration/royalty.test.ts @@ -1,5 +1,5 @@ import chai from "chai"; -import { StoryClient } from "../../src"; +import { PIL_TYPE, StoryClient } from "../../src"; import { Address, Hex, encodeFunctionData } from "viem"; import chaiAsPromised from "chai-as-promised"; import { mockERC721, getTokenId, getStoryClient } from "./utils/util"; @@ -30,10 +30,13 @@ describe("Test royalty Functions", () => { return response.ipId! as Hex; }; const getCommercialPolicyId = async (): Promise => { - const response = await client.license.registerCommercialRemixPIL({ - defaultMintingFee: "100000", - currency: MockERC20.address, - commercialRevShare: 10, + const response = await client.license.registerPILTerms({ + terms: { + defaultMintingFee: "100000", + currency: MockERC20.address, + royaltyPolicy: "0x", + }, + PILType: PIL_TYPE.COMMERCIAL_USE, txOptions: { waitForTransaction: true, }, diff --git a/packages/core-sdk/test/unit/resources/ipAsset.test.ts b/packages/core-sdk/test/unit/resources/ipAsset.test.ts index 845f0578..be2e2e56 100644 --- a/packages/core-sdk/test/unit/resources/ipAsset.test.ts +++ b/packages/core-sdk/test/unit/resources/ipAsset.test.ts @@ -18,7 +18,7 @@ import { LicenseRegistryReadOnlyClient } from "../../../src/abi/generated"; import { MAX_ROYALTY_TOKEN, royaltySharesTotalSupply } from "../../../src/constants/common"; import { LicensingConfig } from "../../../src/types/common"; import { DerivativeData } from "../../../src/types/resources/ipAsset"; -import { InnerLicenseTerms } from "../../../src/types/resources/license"; +import { InnerPILTerms } from "../../../src/types/resources/license"; const { RoyaltyModuleReadOnlyClient, IpRoyaltyVaultImplReadOnlyClient, @@ -27,7 +27,7 @@ const { const txHash = "0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997"; chai.use(chaiAsPromised); const expect = chai.expect; -const licenseTerms: InnerLicenseTerms = { +const licenseTerms: InnerPILTerms = { transferable: true, royaltyPolicy: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c", defaultMintingFee: BigInt(1), diff --git a/packages/core-sdk/test/unit/resources/license.test.ts b/packages/core-sdk/test/unit/resources/license.test.ts index d05291c3..8522c104 100644 --- a/packages/core-sdk/test/unit/resources/license.test.ts +++ b/packages/core-sdk/test/unit/resources/license.test.ts @@ -5,7 +5,7 @@ import { LicenseClient } from "../../../src"; import { PublicClient, WalletClient, Account, zeroAddress, Hex } from "viem"; import chaiAsPromised from "chai-as-promised"; import { PiLicenseTemplateGetLicenseTermsResponse } from "../../../src/abi/generated"; -import { LicenseTerms } from "../../../src/types/resources/license"; +import { PILTerms, PIL_TYPE } from "../../../src/types/resources/license"; import { MockERC20 } from "../../integration/utils/mockERC20"; const { RoyaltyModuleReadOnlyClient } = require("../../../src/abi/generated"); @@ -38,8 +38,8 @@ describe("Test LicenseClient", () => { .resolves(true); RoyaltyModuleReadOnlyClient.prototype.isWhitelistedRoyaltyToken = sinon.stub().resolves(true); }); - const licenseTerms: LicenseTerms = { - defaultMintingFee: 1513n, + const licenseTerms: PILTerms = { + defaultMintingFee: 3n, currency: MockERC20.address, royaltyPolicy: zeroAddress, transferable: false, @@ -62,7 +62,9 @@ describe("Test LicenseClient", () => { .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") .resolves({ selectedLicenseTermsId: BigInt(1) }); - const result = await licenseClient.registerPILTerms(licenseTerms); + const result = await licenseClient.registerPILTerms({ + terms: licenseTerms, + }); expect(result.licenseTermsId).to.equal(1n); expect(result.txHash).to.equal(undefined); @@ -74,12 +76,14 @@ describe("Test LicenseClient", () => { .resolves({ selectedLicenseTermsId: BigInt(0) }); await expect( licenseClient.registerPILTerms({ - ...licenseTerms, - commercialUse: true, - defaultMintingFee: 1, - currency: MockERC20.address, - commercialRevShare: 101, - royaltyPolicy: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c", + terms: { + ...licenseTerms, + commercialUse: true, + defaultMintingFee: 1, + currency: MockERC20.address, + commercialRevShare: 101, + royaltyPolicy: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c", + }, }), ).to.be.rejectedWith( "Failed to register license terms: CommercialRevShare should be between 0 and 100.", @@ -91,17 +95,20 @@ describe("Test LicenseClient", () => { .resolves({ selectedLicenseTermsId: BigInt(0) }); await expect( licenseClient.registerPILTerms({ - ...licenseTerms, - commercialUse: true, - defaultMintingFee: 1, - currency: MockERC20.address, - commercialRevShare: -1, - royaltyPolicy: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c", + terms: { + ...licenseTerms, + commercialUse: true, + defaultMintingFee: 1, + currency: MockERC20.address, + commercialRevShare: -1, + royaltyPolicy: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c", + }, }), ).to.be.rejectedWith( "Failed to register license terms: CommercialRevShare should be between 0 and 100.", ); }); + it("should return encodedTxData when call registerPILTerms given txOptions.encodedTxDataOnly of true and args is correct", async () => { sinon .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") @@ -111,7 +118,7 @@ describe("Test LicenseClient", () => { .returns({ to: zeroAddress, data: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c" }); const result = await licenseClient.registerPILTerms({ - ...licenseTerms, + terms: licenseTerms, txOptions: { encodedTxDataOnly: true, }, @@ -122,7 +129,7 @@ describe("Test LicenseClient", () => { }); }); - it("should return txHash when call registerPILTerms given args is correct", async () => { + it("should return none commercial license terms when call registerPILTerms given terms and type is empty", async () => { sinon .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") .resolves({ selectedLicenseTermsId: BigInt(0) }); @@ -138,34 +145,7 @@ describe("Test LicenseClient", () => { ]); const result = await licenseClient.registerPILTerms({ - ...licenseTerms, - }); - - expect(result.txHash).to.equal(txHash); - }); - - it("should return txHash when call registerPILTerms given args is correct and waitForTransaction of true", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(0) }); - sinon.stub(licenseClient.licenseTemplateClient, "registerLicenseTerms").resolves(txHash); - sinon - .stub(licenseClient.licenseTemplateClient, "parseTxLicenseTermsRegisteredEvent") - .returns([ - { - licenseTermsId: BigInt(1), - licenseTemplate: zeroAddress, - licenseTerms: zeroAddress, - }, - ]); - - const result = await licenseClient.registerPILTerms({ - ...licenseTerms, - commercialUse: true, - defaultMintingFee: 1, - currency: MockERC20.address, - commercialRevShare: 90, - royaltyPolicy: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c", + terms: undefined, txOptions: { waitForTransaction: true, }, @@ -174,29 +154,7 @@ describe("Test LicenseClient", () => { expect(result.txHash).to.equal(txHash); expect(result.licenseTermsId).to.equal(1n); }); - }); - describe("Test licenseClient.registerNonComSocialRemixingPIL", async () => { - it("should return licenseTermsId when call registerNonComSocialRemixingPIL given licenseTermsId is registered", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(1) }); - - const result = await licenseClient.registerNonComSocialRemixingPIL(); - - expect(result.licenseTermsId).to.equal(1n); - }); - - it("should return txhash when call registerNonComSocialRemixingPIL given licenseTermsId is not registered", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(0) }); - sinon.stub(licenseClient.licenseTemplateClient, "registerLicenseTerms").resolves(txHash); - - const result = await licenseClient.registerNonComSocialRemixingPIL(); - - expect(result.txHash).to.equal(txHash); - }); - it("should return txhash when call registerNonComSocialRemixingPIL given licenseTermsId is not registered and waitForTransaction of true", async () => { + it("should return txHash when call registerPILTerms given terms", async () => { sinon .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") .resolves({ selectedLicenseTermsId: BigInt(0) }); @@ -211,186 +169,78 @@ describe("Test LicenseClient", () => { }, ]); - const result = await licenseClient.registerNonComSocialRemixingPIL({ - txOptions: { - waitForTransaction: true, - }, + const result = await licenseClient.registerPILTerms({ + terms: licenseTerms, }); expect(result.txHash).to.equal(txHash); - expect(result.licenseTermsId).to.equal(1n); }); - it("should return throw error when call registerNonComSocialRemixingPIL given request fail", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(0) }); - sinon - .stub(licenseClient.licenseTemplateClient, "registerLicenseTerms") - .throws(new Error("request fail.")); - try { - await licenseClient.registerNonComSocialRemixingPIL({ + describe("Test licenseClient.registerPILTerms with different PIL_Type", async () => { + beforeEach(() => { + sinon + .stub(licenseClient.licenseTemplateClient, "parseTxLicenseTermsRegisteredEvent") + .returns([ + { + licenseTermsId: BigInt(1), + licenseTemplate: zeroAddress, + licenseTerms: zeroAddress, + }, + ]); + sinon + .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") + .resolves({ selectedLicenseTermsId: BigInt(0) }); + sinon.stub(licenseClient.licenseTemplateClient, "registerLicenseTerms").resolves(txHash); + }); + it("should return txHash when call registerPILTerms given PILType of COMMERCIAL_USE", async () => { + const result = await licenseClient.registerPILTerms({ + PILType: PIL_TYPE.COMMERCIAL_USE, + terms: { + defaultMintingFee: 1, + currency: MockERC20.address, + royaltyPolicy: zeroAddress, + }, txOptions: { waitForTransaction: true, }, }); - } catch (error) { - expect((error as Error).message).equal( - "Failed to register non commercial social remixing PIL: request fail.", - ); - } - }); - - it("should return encodedTxData when call registerNonComSocialRemixingPIL given txOptions.encodedTxDataOnly of true and args is correct", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(0) }); - sinon - .stub(licenseClient.licenseTemplateClient, "registerLicenseTermsEncode") - .returns({ to: zeroAddress, data: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c" }); - const result = await licenseClient.registerNonComSocialRemixingPIL({ - txOptions: { - encodedTxDataOnly: true, - }, + expect(result.txHash).to.equal(txHash); + expect(result.licenseTermsId).to.equal(1n); }); - expect(result.encodedTxData).to.deep.equal({ - to: zeroAddress, - data: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c", - }); - }); - }); - - describe("Test licenseClient.registerCommercialUsePIL", async () => { - it("should return licenseTermsId when call registerCommercialUsePIL given licenseTermsId is registered", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(1) }); - - const result = await licenseClient.registerCommercialUsePIL({ - defaultMintingFee: 1, - currency: zeroAddress, - }); - - expect(result.licenseTermsId).to.equal(1n); - }); - - it("should return txhash when call registerCommercialUsePIL given licenseTermsId is not registered", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(0) }); - sinon.stub(licenseClient.licenseTemplateClient, "registerLicenseTerms").resolves(txHash); - - const result = await licenseClient.registerCommercialUsePIL({ - defaultMintingFee: "1", - currency: zeroAddress, - }); - - expect(result.txHash).to.equal(txHash); - }); - - it("should return txhash when call registerCommercialUsePIL given licenseTermsId is not registered and waitForTransaction of true", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(0) }); - sinon.stub(licenseClient.licenseTemplateClient, "registerLicenseTerms").resolves(txHash); - sinon - .stub(licenseClient.licenseTemplateClient, "parseTxLicenseTermsRegisteredEvent") - .returns([ - { - licenseTermsId: BigInt(1), - licenseTemplate: zeroAddress, - licenseTerms: zeroAddress, + it("should return txHash when call registerPILTerms given PILType of COMMERCIAL_REMIX", async () => { + const result = await licenseClient.registerPILTerms({ + PILType: PIL_TYPE.COMMERCIAL_REMIX, + terms: { + defaultMintingFee: 1, + currency: MockERC20.address, + royaltyPolicy: zeroAddress, + commercialRevShare: 100, + }, + txOptions: { + waitForTransaction: true, }, - ]); - - const result = await licenseClient.registerCommercialUsePIL({ - defaultMintingFee: "1", - currency: zeroAddress, - txOptions: { - waitForTransaction: true, - }, - }); - - expect(result.txHash).to.equal(txHash); - expect(result.licenseTermsId).to.equal(1n); - }); - - it("should return throw error when call registerCommercialUsePIL given request fail", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(0) }); - sinon - .stub(licenseClient.licenseTemplateClient, "registerLicenseTerms") - .throws(new Error("request fail.")); - - try { - await licenseClient.registerCommercialUsePIL({ - defaultMintingFee: "1", - currency: zeroAddress, }); - } catch (error) { - expect((error as Error).message).equal( - "Failed to register commercial use PIL: request fail.", - ); - } - }); - - it("should return encodedTxData when call registerCommercialUsePIL given txOptions.encodedTxDataOnly of true and args is correct", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(0) }); - sinon - .stub(licenseClient.licenseTemplateClient, "registerLicenseTermsEncode") - .returns({ to: zeroAddress, data: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c" }); - - const result = await licenseClient.registerCommercialUsePIL({ - defaultMintingFee: "1", - currency: zeroAddress, - royaltyPolicyAddress: zeroAddress, - txOptions: { - encodedTxDataOnly: true, - }, - }); - - expect(result.encodedTxData).to.deep.equal({ - to: zeroAddress, - data: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c", - }); - }); - }); - - describe("Test licenseClient.registerCommercialRemixPIL", async () => { - it("should return licenseTermsId when call registerCommercialRemixPIL given licenseTermsId is registered", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(1) }); - const result = await licenseClient.registerCommercialRemixPIL({ - defaultMintingFee: "1", - commercialRevShare: 100, - currency: zeroAddress, + expect(result.txHash).to.equal(txHash); + expect(result.licenseTermsId).to.equal(1n); }); - expect(result.licenseTermsId).to.equal(1n); - }); - - it("should return txhash when call registerCommercialRemixPIL given licenseTermsId is not registered", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(0) }); - sinon.stub(licenseClient.licenseTemplateClient, "registerLicenseTerms").resolves(txHash); + it("should return txHash when call registerPILTerms given PILType of NON_COMMERCIAL_REMIX", async () => { + const result = await licenseClient.registerPILTerms({ + PILType: PIL_TYPE.NON_COMMERCIAL_REMIX, + //TODO: Need to find a way to improve it, or more flexible terms type by union type + terms: undefined, + txOptions: { + waitForTransaction: true, + }, + }); - const result = await licenseClient.registerCommercialRemixPIL({ - defaultMintingFee: "1", - commercialRevShare: 100, - currency: zeroAddress, + expect(result.txHash).to.equal(txHash); + expect(result.licenseTermsId).to.equal(1n); }); - - expect(result.txHash).to.equal(txHash); }); - - it("should return txhash when call registerCommercialRemixPIL given licenseTermsId is not registered and waitForTransaction of true", async () => { + it("should return txHash when call registerPILTerms given args type and waitForTransaction of true", async () => { sinon .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") .resolves({ selectedLicenseTermsId: BigInt(0) }); @@ -405,10 +255,9 @@ describe("Test LicenseClient", () => { }, ]); - const result = await licenseClient.registerCommercialRemixPIL({ - defaultMintingFee: "1", - commercialRevShare: 100, - currency: zeroAddress, + const result = await licenseClient.registerPILTerms({ + PILType: PIL_TYPE.NON_COMMERCIAL_REMIX, + terms: licenseTerms, txOptions: { waitForTransaction: true, }, @@ -417,51 +266,6 @@ describe("Test LicenseClient", () => { expect(result.txHash).to.equal(txHash); expect(result.licenseTermsId).to.equal(1n); }); - - it("should return throw error when call registerCommercialRemixPIL given request fail", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(0) }); - sinon - .stub(licenseClient.licenseTemplateClient, "registerLicenseTerms") - .throws(new Error("request fail.")); - - try { - await licenseClient.registerCommercialRemixPIL({ - defaultMintingFee: "1", - commercialRevShare: 100, - currency: zeroAddress, - }); - } catch (error) { - expect((error as Error).message).equal( - "Failed to register commercial remix PIL: request fail.", - ); - } - }); - - it("should return encodedTxData when call registerCommercialRemixPIL given txOptions.encodedTxDataOnly of true and args is correct", async () => { - sinon - .stub(licenseClient.licenseTemplateClient, "getLicenseTermsId") - .resolves({ selectedLicenseTermsId: BigInt(0) }); - sinon - .stub(licenseClient.licenseTemplateClient, "registerLicenseTermsEncode") - .returns({ to: zeroAddress, data: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c" }); - - const result = await licenseClient.registerCommercialRemixPIL({ - defaultMintingFee: "1", - commercialRevShare: 100, - currency: zeroAddress, - royaltyPolicyAddress: zeroAddress, - txOptions: { - encodedTxDataOnly: true, - }, - }); - - expect(result.encodedTxData).to.deep.equal({ - to: zeroAddress, - data: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c", - }); - }); }); describe("Test licenseClient.attachLicenseTerms", async () => { diff --git a/packages/core-sdk/test/unit/utils/licenseTermsHelper.test.ts b/packages/core-sdk/test/unit/utils/licenseTermsHelper.test.ts index 7f34601a..c8276c74 100644 --- a/packages/core-sdk/test/unit/utils/licenseTermsHelper.test.ts +++ b/packages/core-sdk/test/unit/utils/licenseTermsHelper.test.ts @@ -1,10 +1,6 @@ -import { Hex, PublicClient, zeroAddress } from "viem"; -import { LicenseTerms, PIL_TYPE } from "../../../src/types/resources/license"; -import { - getLicenseTermByType, - getRevenueShare, - validateLicenseTerms, -} from "../../../src/utils/licenseTermsHelper"; +import { PublicClient, zeroAddress } from "viem"; +import { PILTerms } from "../../../src/types/resources/license"; +import { getRevenueShare, validateLicenseTerms } from "../../../src/utils/licenseTermsHelper"; import { expect } from "chai"; import { MockERC20 } from "../../integration/utils/mockERC20"; import sinon from "sinon"; @@ -12,220 +8,12 @@ import { createMock } from "../testUtils"; const { RoyaltyModuleReadOnlyClient } = require("../../../src/abi/generated"); describe("License Terms Helper", () => { - describe("getLicenseTermByType", () => { - it("it should return no commercial license terms when call getLicenseTermByType given NON_COMMERCIAL_REMIX", async () => { - const result = getLicenseTermByType(PIL_TYPE.NON_COMMERCIAL_REMIX); - expect(result).to.deep.include({ - transferable: true, - commercialAttribution: false, - commercialRevCeiling: 0n, - commercialRevShare: 0, - commercialUse: false, - commercializerChecker: "0x0000000000000000000000000000000000000000", - commercializerCheckerData: "0x", - currency: "0x0000000000000000000000000000000000000000", - derivativeRevCeiling: 0n, - derivativesAllowed: true, - derivativesApproval: false, - derivativesAttribution: true, - derivativesReciprocal: true, - expiration: 0n, - defaultMintingFee: 0n, - royaltyPolicy: "0x0000000000000000000000000000000000000000", - uri: "", - }); - }); - - describe("Get Commercial License Terms", () => { - it("it should throw when call getLicenseTermByType given COMMERCIAL_USE without terms", async () => { - expect(() => getLicenseTermByType(PIL_TYPE.COMMERCIAL_USE)).to.throw( - "DefaultMintingFee, currency are required for commercial use PIL.", - ); - }); - - it("it should throw when call getLicenseTermByType given COMMERCIAL_USE without mintFee", async () => { - expect(() => - getLicenseTermByType(PIL_TYPE.COMMERCIAL_USE, { - currency: zeroAddress, - royaltyPolicyAddress: zeroAddress, - }), - ).to.throw("DefaultMintingFee, currency are required for commercial use PIL."); - }); - - it("it should throw when call getLicenseTermByType given COMMERCIAL_USE without currency", async () => { - expect(() => - getLicenseTermByType(PIL_TYPE.COMMERCIAL_USE, { - royaltyPolicyAddress: zeroAddress, - defaultMintingFee: "1", - }), - ).to.throw("DefaultMintingFee, currency are required for commercial use PIL."); - }); - - it("it should throw when call getLicenseTermByType given COMMERCIAL_USE and wrong royaltyAddress", async () => { - expect(() => - getLicenseTermByType(PIL_TYPE.COMMERCIAL_USE, { - royaltyPolicyAddress: "wrong" as Hex, - defaultMintingFee: "1", - currency: zeroAddress, - }), - ).to.throw( - `term.royaltyPolicyLAPAddress address is invalid: wrong, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`, - ); - }); - - it("it should return commercial license terms when call getLicenseTermByType given COMMERCIAL_USE and correct args", async () => { - const result = getLicenseTermByType(PIL_TYPE.COMMERCIAL_USE, { - royaltyPolicyAddress: zeroAddress, - defaultMintingFee: "1", - currency: zeroAddress, - }); - expect(result).to.deep.contain({ - commercialAttribution: true, - commercialRevCeiling: 0n, - commercialRevShare: 0, - commercialUse: true, - commercializerChecker: "0x0000000000000000000000000000000000000000", - commercializerCheckerData: "0x0000000000000000000000000000000000000000", - currency: "0x0000000000000000000000000000000000000000", - derivativeRevCeiling: 0n, - derivativesAllowed: true, - derivativesApproval: false, - derivativesAttribution: true, - derivativesReciprocal: false, - expiration: 0n, - defaultMintingFee: 1n, - royaltyPolicy: "0x0000000000000000000000000000000000000000", - transferable: true, - uri: "", - }); - }); - }); - - describe("Get Commercial remix License Terms", () => { - it("it should throw when call getLicenseTermByType given COMMERCIAL_REMIX without terms", async () => { - expect(() => getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX)).to.throw( - "MintingFee, currency and commercialRevShare are required for commercial remix PIL.", - ); - }); - - it("it should throw when call getLicenseTermByType given COMMERCIAL_REMIX without mintFee", async () => { - expect(() => - getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { - currency: zeroAddress, - royaltyPolicyAddress: zeroAddress, - commercialRevShare: 100, - }), - ).to.throw( - "MintingFee, currency and commercialRevShare are required for commercial remix PIL.", - ); - }); - - it("it should throw when call getLicenseTermByType given COMMERCIAL_REMIX without currency", async () => { - expect(() => - getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { - royaltyPolicyAddress: zeroAddress, - defaultMintingFee: "1", - commercialRevShare: 100, - }), - ).to.throw( - "MintingFee, currency and commercialRevShare are required for commercial remix PIL.", - ); - }); - - it("it should throw when call getLicenseTermByType given COMMERCIAL_REMIX and wrong royaltyAddress", async () => { - expect(() => - getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { - royaltyPolicyAddress: "wrong" as Hex, - defaultMintingFee: "1", - currency: zeroAddress, - commercialRevShare: 100, - }), - ).to.throw( - `term.royaltyPolicyLAPAddress address is invalid: wrong, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`, - ); - }); - - it("it should throw when call getLicenseTermByType given COMMERCIAL_REMIX without commercialRevShare ", async () => { - expect(() => - getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { - royaltyPolicyAddress: "wrong" as Hex, - defaultMintingFee: "1", - currency: zeroAddress, - }), - ).to.throw( - `MintingFee, currency and commercialRevShare are required for commercial remix PIL.`, - ); - }); - - it("it should return commercial license terms when call getLicenseTermByType given COMMERCIAL_REMIX and correct args", async () => { - const result = getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { - royaltyPolicyAddress: zeroAddress, - defaultMintingFee: "1", - currency: zeroAddress, - commercialRevShare: 100, - }); - expect(result).to.deep.contain({ - commercialAttribution: true, - commercialRevCeiling: 0n, - commercialRevShare: 100000000, - commercialUse: true, - commercializerChecker: "0x0000000000000000000000000000000000000000", - commercializerCheckerData: "0x0000000000000000000000000000000000000000", - currency: "0x0000000000000000000000000000000000000000", - derivativeRevCeiling: 0n, - derivativesAllowed: true, - derivativesApproval: false, - derivativesAttribution: true, - derivativesReciprocal: true, - expiration: 0n, - defaultMintingFee: 1n, - royaltyPolicy: "0x0000000000000000000000000000000000000000", - transferable: true, - uri: "", - }); - }); - it("it throw commercialRevShare error when call getLicenseTermByType given COMMERCIAL_REMIX and commercialRevShare is less than 0 ", async () => { - expect(() => - getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { - royaltyPolicyAddress: zeroAddress, - defaultMintingFee: "1", - currency: zeroAddress, - commercialRevShare: -8, - }), - ).to.throw(`CommercialRevShare should be between 0 and 100.`); - }); - - it("it throw commercialRevShare error when call getLicenseTermByType given COMMERCIAL_REMIX and commercialRevShare is greater than 100", async () => { - expect(() => - getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { - royaltyPolicyAddress: zeroAddress, - defaultMintingFee: "1", - currency: zeroAddress, - commercialRevShare: 105, - }), - ).to.throw(`CommercialRevShare should be between 0 and 100.`); - }); - - it("it get commercialRevShare correct value when call getLicenseTermByType given COMMERCIAL_REMIX and commercialRevShare is 10", async () => { - const result = getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { - royaltyPolicyAddress: zeroAddress, - defaultMintingFee: "1", - currency: zeroAddress, - commercialRevShare: 10, - }); - expect(result).to.contains({ - commercialRevShare: 10000000, - }); - }); - }); - }); - describe("validateLicenseTerms", () => { let rpcMock: PublicClient; beforeEach(() => { rpcMock = createMock(); }); - const licenseTerms: LicenseTerms = { + const licenseTerms: PILTerms = { defaultMintingFee: 1513n, currency: MockERC20.address, royaltyPolicy: zeroAddress, From 32c5f5b32faed94ae21474a2768728b7ecd14e04 Mon Sep 17 00:00:00 2001 From: Bonnie Date: Thu, 23 Jan 2025 10:17:12 +0800 Subject: [PATCH 3/3] Rename InnerPILTerms and PILTerms --- packages/core-sdk/src/index.ts | 1 + packages/core-sdk/src/resources/PILFlavor.ts | 8 ++++---- packages/core-sdk/src/resources/ipAsset.ts | 16 ++++++++-------- packages/core-sdk/src/resources/license.ts | 14 +++++++------- packages/core-sdk/src/types/resources/ipAsset.ts | 12 ++++++------ packages/core-sdk/src/types/resources/license.ts | 9 ++++----- .../core-sdk/src/utils/licenseTermsHelper.ts | 10 +++++----- .../core-sdk/test/unit/resources/ipAsset.test.ts | 4 ++-- .../core-sdk/test/unit/resources/license.test.ts | 4 ++-- .../test/unit/utils/licenseTermsHelper.test.ts | 4 ++-- 10 files changed, 41 insertions(+), 41 deletions(-) diff --git a/packages/core-sdk/src/index.ts b/packages/core-sdk/src/index.ts index da7d519d..17919ca4 100644 --- a/packages/core-sdk/src/index.ts +++ b/packages/core-sdk/src/index.ts @@ -70,6 +70,7 @@ export type { MintLicenseTokensResponse, LicenseTermsId, PILTerms, + PILTermsInput, PredictMintingLicenseFeeRequest, SetLicensingConfigRequest, SetLicensingConfigResponse, diff --git a/packages/core-sdk/src/resources/PILFlavor.ts b/packages/core-sdk/src/resources/PILFlavor.ts index e96870cc..cad545bf 100644 --- a/packages/core-sdk/src/resources/PILFlavor.ts +++ b/packages/core-sdk/src/resources/PILFlavor.ts @@ -1,11 +1,11 @@ import { Address, zeroAddress } from "viem"; -import { InnerPILTerms } from "../types/resources/license"; +import { PILTerms } from "../types/resources/license"; import { getAddress } from "../utils/utils"; import { getRevenueShare } from "../utils/licenseTermsHelper"; export class PILFlavor { - static nonComSocialRemixingPIL(): InnerPILTerms { + static nonComSocialRemixingPIL(): PILTerms { return { transferable: true, royaltyPolicy: zeroAddress, @@ -31,7 +31,7 @@ export class PILFlavor { defaultMintingFee: bigint | number | string, royaltyPolicy: Address, currency: Address, - ): InnerPILTerms { + ): PILTerms { if (defaultMintingFee === undefined || currency === undefined || royaltyPolicy === undefined) { throw new Error( "DefaultMintingFee, currency and royaltyPolicy are required for commercial use PIL.", @@ -63,7 +63,7 @@ export class PILFlavor { royaltyPolicy: Address, currency: Address, commercialRevShare: number | string, - ): InnerPILTerms { + ): PILTerms { return { transferable: true, royaltyPolicy: getAddress(royaltyPolicy, "royaltyPolicyLAPAddress"), diff --git a/packages/core-sdk/src/resources/ipAsset.ts b/packages/core-sdk/src/resources/ipAsset.ts index 78293aa8..c4c17652 100644 --- a/packages/core-sdk/src/resources/ipAsset.ts +++ b/packages/core-sdk/src/resources/ipAsset.ts @@ -97,7 +97,7 @@ import { import { getRevenueShare, validateLicenseTerms } from "../utils/licenseTermsHelper"; import { getDeadline, getPermissionSignature, getSignature } from "../utils/sign"; import { AccessPermission } from "../types/resources/permission"; -import { InnerPILTerms, InnerLicensingConfig, PILTerms } from "../types/resources/license"; +import { PILTerms, InnerLicensingConfig, PILTermsInput } from "../types/resources/license"; import { MAX_ROYALTY_TOKEN, royaltySharesTotalSupply } from "../constants/common"; import { getFunctionSignature } from "../utils/getFunctionSignature"; import { LicensingConfig } from "../types/common"; @@ -769,7 +769,7 @@ export class IPAssetClient { })); // Due to emit event log by sequence, we need to get license terms id from request.args for (let j = 0; j < request.args.length; j++) { - const licenseTerms: InnerPILTerms[] = []; + const licenseTerms: PILTerms[] = []; const licenseTermsData = request.args[j].licenseTermsData; for (let i = 0; i < licenseTermsData.length; i++) { const licenseTerm = await validateLicenseTerms( @@ -1942,7 +1942,7 @@ export class IPAssetClient { return await this.ipAssetRegistryClient.isRegistered({ id: getAddress(ipId, "ipId") }); } - private async getLicenseTermsId(licenseTerms: InnerPILTerms[]): Promise { + private async getLicenseTermsId(licenseTerms: PILTerms[]): Promise { const licenseTermsIds: bigint[] = []; for (const licenseTerm of licenseTerms) { const licenseRes = await this.licenseTemplateClient.getLicenseTermsId({ @@ -2066,13 +2066,13 @@ export class IPAssetClient { } private async validateLicenseTermsData( - licenseTermsData: LicenseTermsData[], + licenseTermsData: LicenseTermsData[], ): Promise<{ - licenseTerms: InnerPILTerms[]; - licenseTermsData: LicenseTermsData[]; + licenseTerms: PILTerms[]; + licenseTermsData: LicenseTermsData[]; }> { - const licenseTerms: InnerPILTerms[] = []; - const processedLicenseTermsData: LicenseTermsData[] = []; + const licenseTerms: PILTerms[] = []; + const processedLicenseTermsData: LicenseTermsData[] = []; for (let i = 0; i < licenseTermsData.length; i++) { const licenseTerm = await validateLicenseTerms(licenseTermsData[i].terms, this.rpcClient); licenseTerms.push(licenseTerm); diff --git a/packages/core-sdk/src/resources/license.ts b/packages/core-sdk/src/resources/license.ts index d9811167..62cd7049 100644 --- a/packages/core-sdk/src/resources/license.ts +++ b/packages/core-sdk/src/resources/license.ts @@ -24,14 +24,14 @@ import { PIL_TYPE, AttachLicenseTermsResponse, LicenseTermsId, - InnerPILTerms, + PILTerms, PredictMintingLicenseFeeRequest, SetLicensingConfigRequest, SetLicensingConfigResponse, RegisterPILTermsRequest, CommercialLicenseTerms, CommercialRemixLicenseTerms, - PILTerms, + PILTermsInput, } from "../types/resources/license"; import { handleError } from "../utils/errors"; import { getRevenueShare, validateLicenseTerms } from "../utils/licenseTermsHelper"; @@ -73,13 +73,13 @@ export class LicenseClient { request: RegisterPILTermsRequest, ): Promise { try { - let terms: InnerPILTerms; + let terms: PILTerms; if (!request.terms && !request.PILType) { terms = PILFlavor.nonComSocialRemixingPIL(); } else if (request.PILType !== undefined) { terms = this.createTerms(request.PILType, request.terms); } else { - terms = await validateLicenseTerms(request.terms as PILTerms, this.rpcClient); + terms = await validateLicenseTerms(request.terms as PILTermsInput, this.rpcClient); } const licenseTermsId = await this.getLicenseTermsId(terms); if (licenseTermsId !== 0n) { @@ -432,15 +432,15 @@ export class LicenseClient { handleError(error, "Failed to set licensing config"); } } - private async getLicenseTermsId(request: InnerPILTerms): Promise { + private async getLicenseTermsId(request: PILTerms): Promise { const licenseRes = await this.licenseTemplateClient.getLicenseTermsId({ terms: request }); return licenseRes.selectedLicenseTermsId; } private createTerms( PILType: PIL_TYPE, terms: RegisterPILTermsRequest["terms"], - ): InnerPILTerms { - let innerTerms: InnerPILTerms; + ): PILTerms { + let innerTerms: PILTerms; switch (PILType) { case PIL_TYPE.NON_COMMERCIAL_REMIX: innerTerms = PILFlavor.nonComSocialRemixingPIL(); diff --git a/packages/core-sdk/src/types/resources/ipAsset.ts b/packages/core-sdk/src/types/resources/ipAsset.ts index 73b7603b..e5d2c05e 100644 --- a/packages/core-sdk/src/types/resources/ipAsset.ts +++ b/packages/core-sdk/src/types/resources/ipAsset.ts @@ -1,7 +1,7 @@ import { Address, Hex } from "viem"; import { TxOptions } from "../options"; -import { PILTerms } from "./license"; +import { PILTermsInput } from "./license"; import { EncodedTxData } from "../../abi/generated"; import { IpMetadataAndTxOption, LicensingConfig } from "../common"; import { IpMetadataForWorkflow } from "../../utils/getIpMetadataForWorkflow"; @@ -64,7 +64,7 @@ export type LicenseTermsData = { export type MintAndRegisterIpAssetWithPilTermsRequest = { spgNftContract: Address; allowDuplicates: boolean; - licenseTermsData: LicenseTermsData[]; + licenseTermsData: LicenseTermsData[]; recipient?: Address; royaltyPolicyAddress?: Address; } & IpMetadataAndTxOption; @@ -99,7 +99,7 @@ export type RegisterIpAndMakeDerivativeResponse = { export type RegisterIpAndAttachPilTermsRequest = { nftContract: Address; tokenId: bigint | string | number; - licenseTermsData: LicenseTermsData[]; + licenseTermsData: LicenseTermsData[]; deadline?: bigint | number | string; } & IpMetadataAndTxOption; @@ -224,7 +224,7 @@ export type MintAndRegisterIpRequest = { export type RegisterPilTermsAndAttachRequest = { ipId: Address; - licenseTermsData: LicenseTermsData[]; + licenseTermsData: LicenseTermsData[]; deadline?: string | number | bigint; txOptions?: TxOptions; }; @@ -297,7 +297,7 @@ export type BatchRegisterResponse = { export type RegisterIPAndAttachLicenseTermsAndDistributeRoyaltyTokensRequest = { nftContract: Address; tokenId: bigint | string | number; - licenseTermsData: LicenseTermsData[]; + licenseTermsData: LicenseTermsData[]; deadline?: string | number | bigint; royaltyShares: RoyaltyShare[]; txOptions?: Omit; @@ -347,7 +347,7 @@ export type MintAndRegisterIpAndAttachPILTermsAndDistributeRoyaltyTokensRequest spgNftContract: Address; allowDuplicates: boolean; licenseTermsData: { - terms: PILTerms; + terms: PILTermsInput; licensingConfig: LicensingConfig; }[]; royaltyShares: RoyaltyShare[]; diff --git a/packages/core-sdk/src/types/resources/license.ts b/packages/core-sdk/src/types/resources/license.ts index 273a4fee..7a68deca 100644 --- a/packages/core-sdk/src/types/resources/license.ts +++ b/packages/core-sdk/src/types/resources/license.ts @@ -19,9 +19,8 @@ export interface CommercialRemixLicenseTerms extends CommercialLicenseTerms { /** * This structure defines the terms for a Programmable IP License (PIL). These terms can be attached to IP Assets. The legal document of the PIL can be found in this repository. - * @type PILTerms **/ -export interface PILTerms extends CommercialLicenseTerms, CommercialRemixLicenseTerms { +export interface PILTermsInput extends CommercialLicenseTerms, CommercialRemixLicenseTerms { /** Indicates whether the license is transferable or not.*/ transferable: boolean; /** The expiration period of the license.*/ @@ -58,7 +57,7 @@ export type RegisterPILTermsRequest = { | (PILType extends PIL_TYPE.COMMERCIAL_USE ? CommercialLicenseTerms : never) | (PILType extends PIL_TYPE.COMMERCIAL_REMIX ? CommercialRemixLicenseTerms : never) | (PILType extends PIL_TYPE.NON_COMMERCIAL_REMIX ? undefined : never) - | PILTerms; + | PILTermsInput; /** The type of the license terms to be registered, including no-commercial, commercial,commercial remix. */ PILType?: PILType; /** This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property. */ @@ -72,8 +71,8 @@ export type RegisterPILResponse = { /** The encoded transaction data of the register PIL terms. */ encodedTxData?: EncodedTxData; }; -export type InnerPILTerms = Omit< - PILTerms, +export type PILTerms = Omit< + PILTermsInput, | "defaultMintingFee" | "expiration" | "commercialRevCeiling" diff --git a/packages/core-sdk/src/utils/licenseTermsHelper.ts b/packages/core-sdk/src/utils/licenseTermsHelper.ts index 1c832d8f..adb5d41e 100644 --- a/packages/core-sdk/src/utils/licenseTermsHelper.ts +++ b/packages/core-sdk/src/utils/licenseTermsHelper.ts @@ -1,14 +1,14 @@ import { PublicClient, zeroAddress } from "viem"; -import { InnerPILTerms, PILTerms } from "../types/resources/license"; +import { PILTerms, PILTermsInput } from "../types/resources/license"; import { getAddress } from "./utils"; import { RoyaltyModuleReadOnlyClient } from "../abi/generated"; import { MAX_ROYALTY_TOKEN } from "../constants/common"; export async function validateLicenseTerms( - params: PILTerms, + params: PILTermsInput, rpcClient: PublicClient, -): Promise { +): Promise { const { royaltyPolicy, currency } = params; const royaltyModuleReadOnlyClient = new RoyaltyModuleReadOnlyClient(rpcClient); if (getAddress(royaltyPolicy, "params.royaltyPolicy") !== zeroAddress) { @@ -42,7 +42,7 @@ export async function validateLicenseTerms( return object; } -const verifyCommercialUse = (terms: InnerPILTerms) => { +const verifyCommercialUse = (terms: PILTerms) => { if (!terms.commercialUse) { if (terms.commercialAttribution) { throw new Error("Cannot add commercial attribution when commercial use is disabled."); @@ -71,7 +71,7 @@ const verifyCommercialUse = (terms: InnerPILTerms) => { } }; -const verifyDerivatives = (terms: InnerPILTerms) => { +const verifyDerivatives = (terms: PILTerms) => { if (!terms.derivativesAllowed) { if (terms.derivativesAttribution) { throw new Error("Cannot add derivative attribution when derivative use is disabled."); diff --git a/packages/core-sdk/test/unit/resources/ipAsset.test.ts b/packages/core-sdk/test/unit/resources/ipAsset.test.ts index be2e2e56..5be5dcda 100644 --- a/packages/core-sdk/test/unit/resources/ipAsset.test.ts +++ b/packages/core-sdk/test/unit/resources/ipAsset.test.ts @@ -18,7 +18,7 @@ import { LicenseRegistryReadOnlyClient } from "../../../src/abi/generated"; import { MAX_ROYALTY_TOKEN, royaltySharesTotalSupply } from "../../../src/constants/common"; import { LicensingConfig } from "../../../src/types/common"; import { DerivativeData } from "../../../src/types/resources/ipAsset"; -import { InnerPILTerms } from "../../../src/types/resources/license"; +import { PILTerms } from "../../../src/types/resources/license"; const { RoyaltyModuleReadOnlyClient, IpRoyaltyVaultImplReadOnlyClient, @@ -27,7 +27,7 @@ const { const txHash = "0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997"; chai.use(chaiAsPromised); const expect = chai.expect; -const licenseTerms: InnerPILTerms = { +const licenseTerms: PILTerms = { transferable: true, royaltyPolicy: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c", defaultMintingFee: BigInt(1), diff --git a/packages/core-sdk/test/unit/resources/license.test.ts b/packages/core-sdk/test/unit/resources/license.test.ts index 8522c104..ac77a449 100644 --- a/packages/core-sdk/test/unit/resources/license.test.ts +++ b/packages/core-sdk/test/unit/resources/license.test.ts @@ -5,7 +5,7 @@ import { LicenseClient } from "../../../src"; import { PublicClient, WalletClient, Account, zeroAddress, Hex } from "viem"; import chaiAsPromised from "chai-as-promised"; import { PiLicenseTemplateGetLicenseTermsResponse } from "../../../src/abi/generated"; -import { PILTerms, PIL_TYPE } from "../../../src/types/resources/license"; +import { PILTermsInput, PIL_TYPE } from "../../../src/types/resources/license"; import { MockERC20 } from "../../integration/utils/mockERC20"; const { RoyaltyModuleReadOnlyClient } = require("../../../src/abi/generated"); @@ -38,7 +38,7 @@ describe("Test LicenseClient", () => { .resolves(true); RoyaltyModuleReadOnlyClient.prototype.isWhitelistedRoyaltyToken = sinon.stub().resolves(true); }); - const licenseTerms: PILTerms = { + const licenseTerms: PILTermsInput = { defaultMintingFee: 3n, currency: MockERC20.address, royaltyPolicy: zeroAddress, diff --git a/packages/core-sdk/test/unit/utils/licenseTermsHelper.test.ts b/packages/core-sdk/test/unit/utils/licenseTermsHelper.test.ts index c8276c74..9bd1a95a 100644 --- a/packages/core-sdk/test/unit/utils/licenseTermsHelper.test.ts +++ b/packages/core-sdk/test/unit/utils/licenseTermsHelper.test.ts @@ -1,5 +1,5 @@ import { PublicClient, zeroAddress } from "viem"; -import { PILTerms } from "../../../src/types/resources/license"; +import { PILTermsInput } from "../../../src/types/resources/license"; import { getRevenueShare, validateLicenseTerms } from "../../../src/utils/licenseTermsHelper"; import { expect } from "chai"; import { MockERC20 } from "../../integration/utils/mockERC20"; @@ -13,7 +13,7 @@ describe("License Terms Helper", () => { beforeEach(() => { rpcMock = createMock(); }); - const licenseTerms: PILTerms = { + const licenseTerms: PILTermsInput = { defaultMintingFee: 1513n, currency: MockERC20.address, royaltyPolicy: zeroAddress,