Skip to content

Commit

Permalink
Rename InnerPILTerms and PILTerms
Browse files Browse the repository at this point in the history
  • Loading branch information
bonnie57 committed Jan 23, 2025
1 parent f447b49 commit 32c5f5b
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 41 deletions.
1 change: 1 addition & 0 deletions packages/core-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export type {
MintLicenseTokensResponse,
LicenseTermsId,
PILTerms,
PILTermsInput,
PredictMintingLicenseFeeRequest,
SetLicensingConfigRequest,
SetLicensingConfigResponse,
Expand Down
8 changes: 4 additions & 4 deletions packages/core-sdk/src/resources/PILFlavor.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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.",
Expand Down Expand Up @@ -63,7 +63,7 @@ export class PILFlavor {
royaltyPolicy: Address,
currency: Address,
commercialRevShare: number | string,
): InnerPILTerms {
): PILTerms {
return {
transferable: true,
royaltyPolicy: getAddress(royaltyPolicy, "royaltyPolicyLAPAddress"),
Expand Down
16 changes: 8 additions & 8 deletions packages/core-sdk/src/resources/ipAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -1942,7 +1942,7 @@ export class IPAssetClient {
return await this.ipAssetRegistryClient.isRegistered({ id: getAddress(ipId, "ipId") });
}

private async getLicenseTermsId(licenseTerms: InnerPILTerms[]): Promise<bigint[]> {
private async getLicenseTermsId(licenseTerms: PILTerms[]): Promise<bigint[]> {
const licenseTermsIds: bigint[] = [];
for (const licenseTerm of licenseTerms) {
const licenseRes = await this.licenseTemplateClient.getLicenseTermsId({
Expand Down Expand Up @@ -2066,13 +2066,13 @@ export class IPAssetClient {
}

private async validateLicenseTermsData(
licenseTermsData: LicenseTermsData<PILTerms, LicensingConfig>[],
licenseTermsData: LicenseTermsData<PILTermsInput, LicensingConfig>[],
): Promise<{
licenseTerms: InnerPILTerms[];
licenseTermsData: LicenseTermsData<InnerPILTerms, InnerLicensingConfig>[];
licenseTerms: PILTerms[];
licenseTermsData: LicenseTermsData<PILTerms, InnerLicensingConfig>[];
}> {
const licenseTerms: InnerPILTerms[] = [];
const processedLicenseTermsData: LicenseTermsData<InnerPILTerms, InnerLicensingConfig>[] = [];
const licenseTerms: PILTerms[] = [];
const processedLicenseTermsData: LicenseTermsData<PILTerms, InnerLicensingConfig>[] = [];
for (let i = 0; i < licenseTermsData.length; i++) {
const licenseTerm = await validateLicenseTerms(licenseTermsData[i].terms, this.rpcClient);
licenseTerms.push(licenseTerm);
Expand Down
14 changes: 7 additions & 7 deletions packages/core-sdk/src/resources/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -73,13 +73,13 @@ export class LicenseClient {
request: RegisterPILTermsRequest<PILType>,
): Promise<RegisterPILResponse> {
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) {
Expand Down Expand Up @@ -432,15 +432,15 @@ export class LicenseClient {
handleError(error, "Failed to set licensing config");
}
}
private async getLicenseTermsId(request: InnerPILTerms): Promise<LicenseTermsIdResponse> {
private async getLicenseTermsId(request: PILTerms): Promise<LicenseTermsIdResponse> {
const licenseRes = await this.licenseTemplateClient.getLicenseTermsId({ terms: request });
return licenseRes.selectedLicenseTermsId;
}
private createTerms(
PILType: PIL_TYPE,
terms: RegisterPILTermsRequest<PIL_TYPE>["terms"],
): InnerPILTerms {
let innerTerms: InnerPILTerms;
): PILTerms {
let innerTerms: PILTerms;
switch (PILType) {
case PIL_TYPE.NON_COMMERCIAL_REMIX:
innerTerms = PILFlavor.nonComSocialRemixingPIL();
Expand Down
12 changes: 6 additions & 6 deletions packages/core-sdk/src/types/resources/ipAsset.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -64,7 +64,7 @@ export type LicenseTermsData<T, U> = {
export type MintAndRegisterIpAssetWithPilTermsRequest = {
spgNftContract: Address;
allowDuplicates: boolean;
licenseTermsData: LicenseTermsData<PILTerms, LicensingConfig>[];
licenseTermsData: LicenseTermsData<PILTermsInput, LicensingConfig>[];
recipient?: Address;
royaltyPolicyAddress?: Address;
} & IpMetadataAndTxOption;
Expand Down Expand Up @@ -99,7 +99,7 @@ export type RegisterIpAndMakeDerivativeResponse = {
export type RegisterIpAndAttachPilTermsRequest = {
nftContract: Address;
tokenId: bigint | string | number;
licenseTermsData: LicenseTermsData<PILTerms, LicensingConfig>[];
licenseTermsData: LicenseTermsData<PILTermsInput, LicensingConfig>[];
deadline?: bigint | number | string;
} & IpMetadataAndTxOption;

Expand Down Expand Up @@ -224,7 +224,7 @@ export type MintAndRegisterIpRequest = {

export type RegisterPilTermsAndAttachRequest = {
ipId: Address;
licenseTermsData: LicenseTermsData<PILTerms, LicensingConfig>[];
licenseTermsData: LicenseTermsData<PILTermsInput, LicensingConfig>[];
deadline?: string | number | bigint;
txOptions?: TxOptions;
};
Expand Down Expand Up @@ -297,7 +297,7 @@ export type BatchRegisterResponse = {
export type RegisterIPAndAttachLicenseTermsAndDistributeRoyaltyTokensRequest = {
nftContract: Address;
tokenId: bigint | string | number;
licenseTermsData: LicenseTermsData<PILTerms, LicensingConfig>[];
licenseTermsData: LicenseTermsData<PILTermsInput, LicensingConfig>[];
deadline?: string | number | bigint;
royaltyShares: RoyaltyShare[];
txOptions?: Omit<TxOptions, "encodedTxDataOnly">;
Expand Down Expand Up @@ -347,7 +347,7 @@ export type MintAndRegisterIpAndAttachPILTermsAndDistributeRoyaltyTokensRequest
spgNftContract: Address;
allowDuplicates: boolean;
licenseTermsData: {
terms: PILTerms;
terms: PILTermsInput;
licensingConfig: LicensingConfig;
}[];
royaltyShares: RoyaltyShare[];
Expand Down
9 changes: 4 additions & 5 deletions packages/core-sdk/src/types/resources/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.*/
Expand Down Expand Up @@ -58,7 +57,7 @@ export type RegisterPILTermsRequest<PILType extends PIL_TYPE> = {
| (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. */
Expand All @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions packages/core-sdk/src/utils/licenseTermsHelper.ts
Original file line number Diff line number Diff line change
@@ -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<InnerPILTerms> {
): Promise<PILTerms> {
const { royaltyPolicy, currency } = params;
const royaltyModuleReadOnlyClient = new RoyaltyModuleReadOnlyClient(rpcClient);
if (getAddress(royaltyPolicy, "params.royaltyPolicy") !== zeroAddress) {
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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.");
Expand Down
4 changes: 2 additions & 2 deletions packages/core-sdk/test/unit/resources/ipAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions packages/core-sdk/test/unit/resources/license.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/core-sdk/test/unit/utils/licenseTermsHelper.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -13,7 +13,7 @@ describe("License Terms Helper", () => {
beforeEach(() => {
rpcMock = createMock<PublicClient>();
});
const licenseTerms: PILTerms = {
const licenseTerms: PILTermsInput = {
defaultMintingFee: 1513n,
currency: MockERC20.address,
royaltyPolicy: zeroAddress,
Expand Down

0 comments on commit 32c5f5b

Please sign in to comment.