Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Redesign with registerPILTerms methods #389

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/core-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,15 @@ export type {
} from "./types/resources/ipAsset";

export type {
RegisterNonComSocialRemixingPILRequest,
RegisterCommercialUsePILRequest,
RegisterCommercialRemixPILRequest,
RegisterPILTermsRequest,
RegisterPILResponse,
AttachLicenseTermsRequest,
AttachLicenseTermsResponse,
MintLicenseTokensRequest,
MintLicenseTokensResponse,
LicenseTermsId,
LicenseTerms,
PILTerms,
PILTermsInput,
PredictMintingLicenseFeeRequest,
SetLicensingConfigRequest,
SetLicensingConfigResponse,
Expand Down
87 changes: 87 additions & 0 deletions packages/core-sdk/src/resources/PILFlavor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Address, zeroAddress } from "viem";

import { PILTerms } from "../types/resources/license";
import { getAddress } from "../utils/utils";
import { getRevenueShare } from "../utils/licenseTermsHelper";

export class PILFlavor {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets simplify the names, commercialUse, nonCommercial, commercialRemix, nonCommercialRemix. I don't think we need the PIL at the end. PILFlavor class already indicates that.

static nonComSocialRemixingPIL(): PILTerms {
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,
): PILTerms {
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,
): PILTerms {
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: "",
};
}
}
20 changes: 8 additions & 12 deletions packages/core-sdk/src/resources/ipAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { 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 @@ -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: PILTerms[] = [];
const licenseTermsData = request.args[j].licenseTermsData;
for (let i = 0; i < licenseTermsData.length; i++) {
const licenseTerm = await validateLicenseTerms(
Expand Down Expand Up @@ -1946,7 +1942,7 @@ export class IPAssetClient {
return await this.ipAssetRegistryClient.isRegistered({ id: getAddress(ipId, "ipId") });
}

private async getLicenseTermsId(licenseTerms: LicenseTerms[]): 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 @@ -2070,13 +2066,13 @@ export class IPAssetClient {
}

private async validateLicenseTermsData(
licenseTermsData: LicenseTermsData<RegisterPILTermsRequest, LicensingConfig>[],
licenseTermsData: LicenseTermsData<PILTermsInput, LicensingConfig>[],
): Promise<{
licenseTerms: LicenseTerms[];
licenseTermsData: LicenseTermsData<LicenseTerms, InnerLicensingConfig>[];
licenseTerms: PILTerms[];
licenseTermsData: LicenseTermsData<PILTerms, InnerLicensingConfig>[];
}> {
const licenseTerms: LicenseTerms[] = [];
const processedLicenseTermsData: LicenseTermsData<LicenseTerms, 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
Loading
Loading