From 83857d5c5a0ec2c7a2b0bee1fe9b5cb6ec8e4de2 Mon Sep 17 00:00:00 2001 From: Don <100505855+DonFungible@users.noreply.github.com> Date: Sun, 18 Feb 2024 16:34:21 -0800 Subject: [PATCH] Add policy comments (#72) Update comments and types --- packages/core-sdk/src/resources/permission.ts | 4 +-- packages/core-sdk/src/resources/policy.ts | 28 ++++++++++++++++--- .../core-sdk/src/types/resources/license.ts | 2 +- .../src/types/resources/permission.ts | 2 +- .../core-sdk/src/types/resources/policy.ts | 2 +- .../test/integration/permission.test.ts | 2 +- .../test/unit/resources/permission.test.ts | 8 +++--- 7 files changed, 34 insertions(+), 14 deletions(-) diff --git a/packages/core-sdk/src/resources/permission.ts b/packages/core-sdk/src/resources/permission.ts index ab6c9d45..d47ad013 100644 --- a/packages/core-sdk/src/resources/permission.ts +++ b/packages/core-sdk/src/resources/permission.ts @@ -39,7 +39,7 @@ export class PermissionClient { try { const IPAccountConfig = { abi: this.ipAccountABI, - address: getAddress(request.ipAsset), + address: getAddress(request.ipId), }; const { request: call } = await this.rpcClient.simulateContract({ @@ -52,7 +52,7 @@ export class PermissionClient { abi: this.accessControllerConfig.abi, functionName: "setPermission", args: [ - getAddress(request.ipAsset), // 0x Address + getAddress(request.ipId), // 0x Address getAddress(request.signer), // 0x Address getAddress(request.to), // 0x Address request.func as Hex, // bytes4 diff --git a/packages/core-sdk/src/resources/policy.ts b/packages/core-sdk/src/resources/policy.ts index e78f6bbc..1a962e75 100644 --- a/packages/core-sdk/src/resources/policy.ts +++ b/packages/core-sdk/src/resources/policy.ts @@ -27,10 +27,23 @@ export class PolicyClient { } /** - * Create a policy on Story Protocol based on the specified params. - * - * @param request - the request object that contains all data needed to register a policy. - * @returns the response object that contains results from the policy creation. + * Registers a PIL policy to the registry + * Internally, this function must generate a Licensing.Policy struct and call registerPolicy. + * @param request - the licensing parameters for the Programmable IP License v1 (PIL) standard. + * @param request.transferable Whether or not the license is transferable + * @param request.attribution Whether or not attribution is required when reproducing the work + * @param request.commercialUse Whether or not the work can be used commercially + * @param request.commercialAttribution Whether or not attribution is required when reproducing the work commercially + * @param request.commercializerChecker commericializers that are allowed to commercially exploit the work. If zero address, then no restrictions is enforced. + * @param request.commercialRevShare Percentage of revenue that must be shared with the licensor + * @param request.derivativesAllowed Whether or not the licensee can create derivatives of his work + * @param request.derivativesAttribution Whether or not attribution is required for derivatives of the work + * @param request.derivativesApproval Whether or not the licensor must approve derivatives of the work before they can be linked to the licensor IP ID + * @param request.derivativesReciprocal Whether or not the licensee must license derivatives of the work under the same terms. + * @param request.territories List of territories where the license is valid. If empty, global. + * @param request.distributionChannels List of distribution channels where the license is valid. Empty if no restrictions. + * @param request.royaltyPolicy Address of a royalty policy contract (e.g. RoyaltyPolicyLS) that will handle royalty payments + * @returns the transaction hash and the policy ID if the txOptions.waitForTransaction is set to true */ public async registerPILPolicy( request: RegisterPILPolicyRequest, @@ -81,6 +94,13 @@ export class PolicyClient { } } + /** + * Adds a policy to the set of policies of an IP + * @param request The request object containing details to add a policy to an IP + * @param request.ipId The id of the IP + * @param request.polId The id of the policy + * @return the transaction hash and the index of the policy in the IP's policy set if the txOptions.waitForTransaction is set to true + */ public async addPolicyToIp(request: AddPolicyToIpRequest): Promise { try { const IPAccountConfig = { diff --git a/packages/core-sdk/src/types/resources/license.ts b/packages/core-sdk/src/types/resources/license.ts index 190ee92a..7a99fa0e 100644 --- a/packages/core-sdk/src/types/resources/license.ts +++ b/packages/core-sdk/src/types/resources/license.ts @@ -15,7 +15,7 @@ export type MintLicenseResponse = { export type LinkIpToParentRequest = { licenseIds: string[]; - childIpId: string; + childIpId: `0x${string}`; minRoyalty: number; txOptions?: TxOptions; }; diff --git a/packages/core-sdk/src/types/resources/permission.ts b/packages/core-sdk/src/types/resources/permission.ts index 6fd0c3aa..b878d485 100644 --- a/packages/core-sdk/src/types/resources/permission.ts +++ b/packages/core-sdk/src/types/resources/permission.ts @@ -1,7 +1,7 @@ import { TxOptions } from "../options"; export type setPermissionsRequest = { - ipAsset: `0x${string}`; + ipId: `0x${string}`; signer: `0x${string}`; to: `0x${string}`; func: string; diff --git a/packages/core-sdk/src/types/resources/policy.ts b/packages/core-sdk/src/types/resources/policy.ts index 41411ff9..88eb37f0 100644 --- a/packages/core-sdk/src/types/resources/policy.ts +++ b/packages/core-sdk/src/types/resources/policy.ts @@ -127,7 +127,7 @@ export type RegisterPILPolicyResponse = { }; export type AddPolicyToIpRequest = { - ipId: string; + ipId: `0x${string}`; policyId: string; txOptions?: TxOptions; }; diff --git a/packages/core-sdk/test/integration/permission.test.ts b/packages/core-sdk/test/integration/permission.test.ts index b877346f..ad214adf 100644 --- a/packages/core-sdk/test/integration/permission.test.ts +++ b/packages/core-sdk/test/integration/permission.test.ts @@ -26,7 +26,7 @@ describe("Permission Functions", () => { const waitForTransaction: boolean = true; const response = await expect( client.permission.setPermission({ - ipAsset: "0x004e38104adc39cbf4cea9bd8876440a969e3d0b", + ipId: "0x004e38104adc39cbf4cea9bd8876440a969e3d0b", signer: process.env.TEST_WALLET_ADDRESS as `0x${string}`, to: "0x2ac240293f12032E103458451dE8A8096c5A72E8", func: "0x00000000", diff --git a/packages/core-sdk/test/unit/resources/permission.test.ts b/packages/core-sdk/test/unit/resources/permission.test.ts index aba44164..e4e79a81 100644 --- a/packages/core-sdk/test/unit/resources/permission.test.ts +++ b/packages/core-sdk/test/unit/resources/permission.test.ts @@ -34,7 +34,7 @@ describe("Test Permission", function () { walletMock.writeContract = sinon.stub().resolves(txHash); const res = await permissionClient.setPermission({ - ipAsset: AddressZero, + ipId: AddressZero, signer: AddressZero, to: AddressZero, func: "0x00000000", @@ -54,7 +54,7 @@ describe("Test Permission", function () { walletMock.writeContract = sinon.stub().resolves(txHash); const res = await permissionClient.setPermission({ - ipAsset: AddressZero, + ipId: AddressZero, signer: AddressZero, to: AddressZero, func: "0x00000000", @@ -111,7 +111,7 @@ describe("Test Permission", function () { walletMock.writeContract = sinon.stub().rejects(new Error("http 500")); await expect( permissionClient.setPermission({ - ipAsset: AddressZero, + ipId: AddressZero, signer: AddressZero, to: AddressZero, func: "0x00000000", @@ -131,7 +131,7 @@ describe("Test Permission", function () { await expect( permissionClient.setPermission({ - ipAsset: AddressZero, + ipId: AddressZero, signer: AddressZero, to: AddressZero, func: AddressZero,