Skip to content

Commit

Permalink
Enhance method to accept array of terms
Browse files Browse the repository at this point in the history
  • Loading branch information
bonnie57 committed Dec 16, 2024
1 parent 56c2c9c commit 319810d
Show file tree
Hide file tree
Showing 6 changed files with 6,283 additions and 7,970 deletions.
20 changes: 10 additions & 10 deletions packages/core-sdk/src/abi/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10946,8 +10946,8 @@ export const royaltyTokenDistributionWorkflowsAbi = [
},
{
name: "terms",
internalType: "struct PILTerms",
type: "tuple",
internalType: "struct PILTerms[]",
type: "tuple[]",
components: [
{ name: "transferable", internalType: "bool", type: "bool" },
{ name: "royaltyPolicy", internalType: "address", type: "address" },
Expand Down Expand Up @@ -11010,7 +11010,7 @@ export const royaltyTokenDistributionWorkflowsAbi = [
outputs: [
{ name: "ipId", internalType: "address", type: "address" },
{ name: "tokenId", internalType: "uint256", type: "uint256" },
{ name: "licenseTermsId", internalType: "uint256", type: "uint256" },
{ name: "licenseTermsIds", internalType: "uint256[]", type: "uint256[]" },
],
stateMutability: "nonpayable",
},
Expand Down Expand Up @@ -11094,8 +11094,8 @@ export const royaltyTokenDistributionWorkflowsAbi = [
},
{
name: "terms",
internalType: "struct PILTerms",
type: "tuple",
internalType: "struct PILTerms[]",
type: "tuple[]",
components: [
{ name: "transferable", internalType: "bool", type: "bool" },
{ name: "royaltyPolicy", internalType: "address", type: "address" },
Expand Down Expand Up @@ -11168,7 +11168,7 @@ export const royaltyTokenDistributionWorkflowsAbi = [
name: "registerIpAndAttachPILTermsAndDeployRoyaltyVault",
outputs: [
{ name: "ipId", internalType: "address", type: "address" },
{ name: "licenseTermsId", internalType: "uint256", type: "uint256" },
{ name: "licenseTermsIds", internalType: "uint256[]", type: "uint256[]" },
{ name: "ipRoyaltyVault", internalType: "address", type: "address" },
],
stateMutability: "nonpayable",
Expand Down Expand Up @@ -23809,7 +23809,7 @@ export type RoyaltyTokenDistributionWorkflowsDistributeRoyaltyTokensRequest = {
* @param spgNftContract address
* @param recipient address
* @param ipMetadata tuple
* @param terms tuple
* @param terms tuple[]
* @param royaltyShares tuple[]
*/
export type RoyaltyTokenDistributionWorkflowsMintAndRegisterIpAndAttachPilTermsAndDistributeRoyaltyTokensRequest =
Expand Down Expand Up @@ -23840,7 +23840,7 @@ export type RoyaltyTokenDistributionWorkflowsMintAndRegisterIpAndAttachPilTermsA
derivativeRevCeiling: bigint;
currency: Address;
uri: string;
};
}[];
royaltyShares: {
author: Address;
percentage: number;
Expand Down Expand Up @@ -23884,7 +23884,7 @@ export type RoyaltyTokenDistributionWorkflowsMintAndRegisterIpAndMakeDerivativeA
* @param nftContract address
* @param tokenId uint256
* @param ipMetadata tuple
* @param terms tuple
* @param terms tuple[]
* @param sigMetadata tuple
* @param sigAttach tuple
*/
Expand Down Expand Up @@ -23916,7 +23916,7 @@ export type RoyaltyTokenDistributionWorkflowsRegisterIpAndAttachPilTermsAndDeplo
derivativeRevCeiling: bigint;
currency: Address;
uri: string;
};
}[];
sigMetadata: {
signer: Address;
deadline: bigint;
Expand Down
45 changes: 28 additions & 17 deletions packages/core-sdk/src/resources/ipAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ export class IPAssetClient {
* @param request - The request object that contains all data needed to register ip and attach license terms and distribute royalty tokens.
* @param request.nftContract The address of the NFT collection.
* @param request.tokenId The ID of the NFT.
* @param request.terms The array of license terms to be attached.
* @param {Array} request.terms The array of license terms to be attached.
* @param request.terms.transferable Indicates whether the license is transferable or not.
* @param request.terms.royaltyPolicy The address of the royalty policy contract which required to StoryProtocol in advance.
* @param request.terms.mintingFee The fee to be paid when minting a license.
Expand Down Expand Up @@ -1557,19 +1557,24 @@ export class IPAssetClient {
* @param request.royaltyShares.percentage The percentage of the royalty share, 10 represents 10%.
* @param request.deadline [Optional] The deadline for the signature in seconds, default is 1000s.
* @param request.txOptions [Optional] This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property, without encodedTxData option.
* @returns A Promise that resolves to a transaction hashes, IP ID, License terms ID, and IP royalty vault.
* @returns A Promise that resolves to a transaction hashes, IP ID, IP royalty vault and an array containing the license terms ID.
* @emits IPRegistered (ipId, chainId, tokenContract, tokenId, name, uri, registrationDate)
* @emits IpRoyaltyVaultDeployed (ipId, ipRoyaltyVault)
*/
public async registerIPAndAttachLicenseTermsAndDistributeRoyaltyTokens(
request: RegisterIPAndAttachLicenseTermsAndDistributeRoyaltyTokensRequest,
): Promise<RegisterIPAndAttachLicenseTermsAndDistributeRoyaltyTokensResponse> {
try {
if (!request.terms.commercialUse) {
throw new Error("Commercial use is required to deploy a royalty vault.");
}
const { royaltyShares, totalAmount } = this.getRoyaltyShares(request.royaltyShares);
const licenseTerm = await validateLicenseTerms(request.terms, this.rpcClient);
const licenseTerms: LicenseTerms[] = [];
for (let i = 0; i < request.terms.length; i++) {
const term = request.terms[i];
if (!term.commercialUse) {
throw new Error("Commercial use is required to deploy a royalty vault.");
}
const licenseTerm = await validateLicenseTerms(term, this.rpcClient);
licenseTerms.push(licenseTerm);
}
const blockTimestamp = (await this.rpcClient.getBlock()).timestamp;
const calculatedDeadline = getDeadline(blockTimestamp, request.deadline);
const ipIdAddress = await this.getIpIdAddress(
Expand Down Expand Up @@ -1629,7 +1634,7 @@ export class IPAssetClient {
nftMetadataURI: request.ipMetadata?.nftMetadataURI || "",
nftMetadataHash: request.ipMetadata?.nftMetadataHash || zeroHash,
},
terms: licenseTerm,
terms: licenseTerms,
sigMetadata: {
signer: this.wallet.account!.address,
deadline: calculatedDeadline,
Expand All @@ -1647,7 +1652,7 @@ export class IPAssetClient {
hash: registerIpAndAttachPilTermsAndDeployRoyaltyVaultTxHash,
});
const { ipId } = this.getIpIdAndTokenIdsFromEvent(txReceipt)[0];
const licenseTermsId = await this.getLicenseTermsId([licenseTerm]);
const licenseTermsIds = await this.getLicenseTermsId(licenseTerms);
const { ipRoyaltyVault } =
this.royaltyModuleEventClient.parseTxIpRoyaltyVaultDeployedEvent(txReceipt)[0];
const distributeRoyaltyTokensTxHash = await this.distributeRoyaltyTokens({
Expand All @@ -1669,7 +1674,7 @@ export class IPAssetClient {
registerIpAndAttachPilTermsAndDeployRoyaltyVaultTxHash,
distributeRoyaltyTokensTxHash,
ipId,
licenseTermsId: licenseTermsId[0],
licenseTermsIds,
ipRoyaltyVault,
};
} catch (error) {
Expand Down Expand Up @@ -1825,7 +1830,7 @@ export class IPAssetClient {
* a commercial license.
* @param request - The request object that contains all data needed to mint an NFT and register the IP, attach PIL terms, and distribute royalty tokens.
* @param request.spgNftContract The address of the SPG NFT contract.
* @param request.terms The array of license terms to be attached.
* @param {Array} request.terms The array of license terms to be attached.
* @param request.terms.transferable Indicates whether the license is transferable or not.
* @param request.terms.royaltyPolicy The address of the royalty policy contract which required to StoryProtocol in advance.
* @param request.terms.mintingFee The fee to be paid when minting a license.
Expand Down Expand Up @@ -1853,17 +1858,23 @@ export class IPAssetClient {
* @param request.royaltyShares.percentage The percentage of the royalty share, 10 represents 10%.
* @param request.recipient - [Optional] The address to receive the minted NFT,default value is your wallet address.
* @param request.txOptions [Optional] This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property, without encodedTxData option.
* @returns A Promise that resolves to a transaction hash, IP ID, License terms ID, and IP royalty vault, Token ID.
* @returns A Promise that resolves to a transaction hash, IP ID, IP royalty vault, Token ID, and an array containing the license terms ID.
* @emits IPRegistered (ipId, chainId, tokenContract, tokenId, name, uri, registrationDate)
* @emits IpRoyaltyVaultDeployed (ipId, ipRoyaltyVault)
*/
public async mintAndRegisterIpAndAttachPilTermsAndDistributeRoyaltyTokens(
request: MintAndRegisterIpAndAttachPILTermsAndDistributeRoyaltyTokensRequest,
): Promise<MintAndRegisterIpAndAttachPILTermsAndDistributeRoyaltyTokensResponse> {
try {
if (!request.terms.commercialUse) {
throw new Error("Commercial use is required to deploy a royalty vault.");
const licenseTerms: LicenseTerms[] = [];
for (let i = 0; i < request.terms.length; i++) {
const term = request.terms[i];
if (!term.commercialUse) {
throw new Error("Commercial use is required to deploy a royalty vault.");
}
const licenseTerm = await validateLicenseTerms(term, this.rpcClient);
licenseTerms.push(licenseTerm);
}
const licenseTerm = await validateLicenseTerms(request.terms, this.rpcClient);
const { royaltyShares } = this.getRoyaltyShares(request.royaltyShares);
const txHash =
await this.royaltyTokenDistributionWorkflowsClient.mintAndRegisterIpAndAttachPilTermsAndDistributeRoyaltyTokens(
Expand All @@ -1878,7 +1889,7 @@ export class IPAssetClient {
nftMetadataURI: request.ipMetadata?.nftMetadataURI || "",
nftMetadataHash: request.ipMetadata?.nftMetadataHash || zeroHash,
},
terms: licenseTerm,
terms: licenseTerms,
royaltyShares,
},
);
Expand All @@ -1888,13 +1899,13 @@ export class IPAssetClient {
hash: txHash,
});
const { ipId, tokenId } = this.getIpIdAndTokenIdsFromEvent(txReceipt)[0];
const licenseTermsId = await this.getLicenseTermsId([licenseTerm]);
const licenseTermsIds = await this.getLicenseTermsId(licenseTerms);
const { ipRoyaltyVault } =
this.royaltyModuleEventClient.parseTxIpRoyaltyVaultDeployedEvent(txReceipt)[0];
return {
txHash,
ipId,
licenseTermsId: licenseTermsId[0],
licenseTermsIds,
ipRoyaltyVault,
tokenId,
};
Expand Down
8 changes: 4 additions & 4 deletions packages/core-sdk/src/types/resources/ipAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export type BatchRegisterResponse = {
export type RegisterIPAndAttachLicenseTermsAndDistributeRoyaltyTokensRequest = {
nftContract: Address;
tokenId: bigint | string | number;
terms: RegisterPILTermsRequest;
terms: RegisterPILTermsRequest[];
deadline?: string | number | bigint;
royaltyShares: RoyaltyShare[];
txOptions?: Omit<TxOptions, "encodedTxDataOnly">;
Expand All @@ -284,7 +284,7 @@ export type RegisterIPAndAttachLicenseTermsAndDistributeRoyaltyTokensResponse =
registerIpAndAttachPilTermsAndDeployRoyaltyVaultTxHash: Hex;
distributeRoyaltyTokensTxHash: Hex;
ipId: Address;
licenseTermsId: bigint;
licenseTermsIds: bigint[];
ipRoyaltyVault: Address;
};
export type DistributeRoyaltyTokens = {
Expand Down Expand Up @@ -327,7 +327,7 @@ export type RegisterDerivativeAndAttachLicenseTermsAndDistributeRoyaltyTokensRes

export type MintAndRegisterIpAndAttachPILTermsAndDistributeRoyaltyTokensRequest = {
spgNftContract: Address;
terms: RegisterPILTermsRequest;
terms: RegisterPILTermsRequest[];
royaltyShares: {
author: Address;
percentage: number;
Expand All @@ -339,7 +339,7 @@ export type MintAndRegisterIpAndAttachPILTermsAndDistributeRoyaltyTokensRequest
export type MintAndRegisterIpAndAttachPILTermsAndDistributeRoyaltyTokensResponse = {
txHash: Hex;
ipId?: Address;
licenseTermsId?: bigint;
licenseTermsIds?: bigint[];
ipRoyaltyVault?: Address;
tokenId?: bigint;
};
Expand Down
84 changes: 44 additions & 40 deletions packages/core-sdk/test/integration/ipAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,25 +428,27 @@ describe("IP Asset Functions ", () => {
{
nftContract: nftContract,
tokenId: tokenId!,
terms: {
transferable: true,
royaltyPolicy: royaltyPolicyLapAddress[odyssey],
defaultMintingFee: BigInt(10000),
expiration: BigInt(1000),
commercialUse: true,
commercialAttribution: false,
commercializerChecker: zeroAddress,
commercializerCheckerData: zeroAddress,
commercialRevShare: 0,
commercialRevCeiling: BigInt(0),
derivativesAllowed: true,
derivativesAttribution: true,
derivativesApproval: false,
derivativesReciprocal: true,
derivativeRevCeiling: BigInt(0),
currency: MockERC20.address,
uri: "test case",
},
terms: [
{
transferable: true,
royaltyPolicy: royaltyPolicyLapAddress[odyssey],
defaultMintingFee: BigInt(10000),
expiration: BigInt(1000),
commercialUse: true,
commercialAttribution: false,
commercializerChecker: zeroAddress,
commercializerCheckerData: zeroAddress,
commercialRevShare: 0,
commercialRevCeiling: BigInt(0),
derivativesAllowed: true,
derivativesAttribution: true,
derivativesApproval: false,
derivativesReciprocal: true,
derivativeRevCeiling: BigInt(0),
currency: MockERC20.address,
uri: "test case",
},
],
ipMetadata: {
ipMetadataURI: "test-uri",
ipMetadataHash: toHex("test-metadata-hash", { size: 32 }),
Expand All @@ -467,7 +469,7 @@ describe("IP Asset Functions ", () => {
.not.empty;
expect(result.distributeRoyaltyTokensTxHash).to.be.a("string").and.not.empty;
expect(result.ipId).to.be.a("string").and.not.empty;
expect(result.licenseTermsId).to.be.a("bigint");
expect(result.licenseTermsIds).to.be.an("array").and.not.empty;
});

it("should not throw error when call register derivative and attach license terms and distribute royalty tokens", async () => {
Expand Down Expand Up @@ -499,25 +501,27 @@ describe("IP Asset Functions ", () => {
const result =
await client.ipAsset.mintAndRegisterIpAndAttachPilTermsAndDistributeRoyaltyTokens({
spgNftContract: nftContract,
terms: {
transferable: true,
royaltyPolicy: royaltyPolicyLapAddress[odyssey],
defaultMintingFee: BigInt(10000),
expiration: BigInt(1000),
commercialUse: true,
commercialAttribution: false,
commercializerChecker: zeroAddress,
commercializerCheckerData: zeroAddress,
commercialRevShare: 0,
commercialRevCeiling: BigInt(0),
derivativesAllowed: true,
derivativesAttribution: true,
derivativesApproval: false,
derivativesReciprocal: true,
derivativeRevCeiling: BigInt(0),
currency: MockERC20.address,
uri: "test case",
},
terms: [
{
transferable: true,
royaltyPolicy: royaltyPolicyLapAddress[odyssey],
defaultMintingFee: BigInt(10000),
expiration: BigInt(1000),
commercialUse: true,
commercialAttribution: false,
commercializerChecker: zeroAddress,
commercializerCheckerData: zeroAddress,
commercialRevShare: 0,
commercialRevCeiling: BigInt(0),
derivativesAllowed: true,
derivativesAttribution: true,
derivativesApproval: false,
derivativesReciprocal: true,
derivativeRevCeiling: BigInt(0),
currency: MockERC20.address,
uri: "test case",
},
],
ipMetadata: {
ipMetadataURI: "test-uri",
ipMetadataHash: toHex("test-metadata-hash", { size: 32 }),
Expand All @@ -535,7 +539,7 @@ describe("IP Asset Functions ", () => {
});
expect(result.txHash).to.be.a("string");
expect(result.ipId).to.be.a("string");
expect(result.licenseTermsId).to.be.a("bigint");
expect(result.licenseTermsIds).to.be.an("array").and.not.empty;
expect(result.tokenId).to.be.a("bigint");
});
it("should not throw error when call mint and register ip and make derivative and distribute royalty tokens", async () => {
Expand Down
Loading

0 comments on commit 319810d

Please sign in to comment.