Skip to content

Commit

Permalink
Add policy comments (#72)
Browse files Browse the repository at this point in the history
Update comments and types
  • Loading branch information
DonFungible authored Feb 19, 2024
1 parent 14c2b9b commit 83857d5
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/core-sdk/src/resources/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
Expand Down
28 changes: 24 additions & 4 deletions packages/core-sdk/src/resources/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<AddPolicyToIpResponse> {
try {
const IPAccountConfig = {
Expand Down
2 changes: 1 addition & 1 deletion packages/core-sdk/src/types/resources/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type MintLicenseResponse = {

export type LinkIpToParentRequest = {
licenseIds: string[];
childIpId: string;
childIpId: `0x${string}`;
minRoyalty: number;
txOptions?: TxOptions;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/core-sdk/src/types/resources/permission.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/core-sdk/src/types/resources/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export type RegisterPILPolicyResponse = {
};

export type AddPolicyToIpRequest = {
ipId: string;
ipId: `0x${string}`;
policyId: string;
txOptions?: TxOptions;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/core-sdk/test/integration/permission.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions packages/core-sdk/test/unit/resources/permission.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -131,7 +131,7 @@ describe("Test Permission", function () {

await expect(
permissionClient.setPermission({
ipAsset: AddressZero,
ipId: AddressZero,
signer: AddressZero,
to: AddressZero,
func: AddressZero,
Expand Down

0 comments on commit 83857d5

Please sign in to comment.