Skip to content

Commit

Permalink
Merge pull request #85 from storyprotocol/dev
Browse files Browse the repository at this point in the history
beta rc.5
  • Loading branch information
edisonz0718 authored Feb 23, 2024
2 parents 1489d63 + a460718 commit e819baf
Show file tree
Hide file tree
Showing 22 changed files with 249 additions and 337 deletions.
2 changes: 1 addition & 1 deletion packages/core-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@story-protocol/core-sdk",
"version": "0.0.1-beta-rc.4",
"version": "0.0.1-beta-rc.5",
"description": "Story Protocol Core SDK",
"main": "dist/story-protocol-core-sdk.cjs.js",
"module": "dist/story-protocol-core-sdk.esm.js",
Expand Down
6 changes: 0 additions & 6 deletions packages/core-sdk/src/abi/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import IPAssetRegistryABI from "./json/IIPAssetRegistry.abi";
import LicensingModuleABI from "./json/LicensingModule.abi";
import PILPolicyFrameworkManagerABI from "./json/PILPolicyFrameworkManager.abi";
import RegistrationModuleABI from "./json/RegistrationModule.abi";
import TaggingModuleABI from "./json/TaggingModule.abi";
import ErrorsABI from "./json/Errors.abi";
import { sepolia } from "../utils/env";

Expand Down Expand Up @@ -44,11 +43,6 @@ export const RegistrationModuleConfig = {
address: getAddress(sepolia.RegistrationModule),
};

export const TaggingModuleConfig = {
abi: [...TaggingModuleABI, ...ErrorsABI],
address: getAddress(sepolia.TaggingModule),
};

export const PILPolicyFrameworkManagerConfig = {
abi: [...PILPolicyFrameworkManagerABI, ...ErrorsABI],
address: getAddress(sepolia.PILPolicyFrameworkManager),
Expand Down
50 changes: 0 additions & 50 deletions packages/core-sdk/src/abi/json/TaggingModule.abi.ts

This file was deleted.

5 changes: 1 addition & 4 deletions packages/core-sdk/src/abi/sdkEntities.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,5 @@
"resolveDispute",
"DisputeCancelled",
"DisputeResolved",
"DisputeRaised",

"setTag",
"removeTag"
"DisputeRaised"
]
60 changes: 42 additions & 18 deletions packages/core-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { createPublicClient, createWalletClient, PublicClient, WalletClient } fr
import * as dotenv from "dotenv";

import { StoryConfig } from "./types/config";
import { TaggingClient } from "./resources/tagging";
import { IPAssetClient } from "./resources/ipAsset";
import { PermissionClient } from "./resources/permission";
import { LicenseClient } from "./resources/license";
import { PolicyClient } from "./resources/policy";
import { DisputeClient } from "./resources/dispute";
import { IPAccountClient } from "./resources/ipAccount";
import { chainStringToViemChain } from "./utils/utils";
import { StoryAPIClient } from "./clients/storyAPI";

Expand All @@ -23,12 +23,12 @@ export class StoryClient {
private readonly wallet: WalletClient;
private readonly storyClient: StoryAPIClient;

private _ipAccount: IPAssetClient | null = null;
private _ipAsset: IPAssetClient | null = null;
private _permission: PermissionClient | null = null;
private _license: LicenseClient | null = null;
private _policy: PolicyClient | null = null;
private _tagging: TaggingClient | null = null;
private _dispute: DisputeClient | null = null;
private _ipAccount: IPAccountClient | null = null;

/**
* @param config - the configuration for the SDK client
Expand Down Expand Up @@ -69,14 +69,26 @@ export class StoryClient {
return new StoryClient(config);
}

/**
* Getter for the ip asset client. The client is lazily created when
* this method is called.
*
* @returns the IPAssetClient instance
*/
public get ipAsset(): IPAssetClient {
if (this._ipAccount === null) {
this._ipAccount = new IPAssetClient(this.rpcClient, this.wallet, this.storyClient);
if (this._ipAsset === null) {
this._ipAsset = new IPAssetClient(this.rpcClient, this.wallet, this.storyClient);
}

return this._ipAccount;
return this._ipAsset;
}

/**
* Getter for the permission client. The client is lazily created when
* this method is called.
*
* @returns the PermissionClient instance
*/
public get permission(): PermissionClient {
if (this._permission === null) {
this._permission = new PermissionClient(this.rpcClient, this.wallet);
Expand All @@ -85,6 +97,12 @@ export class StoryClient {
return this._permission;
}

/**
* Getter for the license client. The client is lazily created when
* this method is called.
*
* @returns the LicenseClient instance
*/
public get license(): LicenseClient {
if (this._license === null) {
this._license = new LicenseClient(this.rpcClient, this.wallet, this.storyClient);
Expand All @@ -93,6 +111,12 @@ export class StoryClient {
return this._license;
}

/**
* Getter for the policy client. The client is lazily created when
* this method is called.
*
* @returns the PolicyClient instance
*/
public get policy(): PolicyClient {
if (this._policy === null) {
this._policy = new PolicyClient(this.rpcClient, this.wallet);
Expand All @@ -102,30 +126,30 @@ export class StoryClient {
}

/**
* Getter for the tagging client. The client is lazily created when
* Getter for the dispute client. The client is lazily created when
* this method is called.
*
* @returns the TaggingClient instance
* @returns the DisputeClient instance
*/
public get tagging(): TaggingClient {
if (this._tagging === null) {
this._tagging = new TaggingClient(this.rpcClient, this.wallet);
public get dispute(): DisputeClient {
if (this._dispute === null) {
this._dispute = new DisputeClient(this.rpcClient, this.wallet);
}

return this._tagging;
return this._dispute;
}

/**
* Getter for the dispute client. The client is lazily created when
* Getter for the ip account client. The client is lazily created when
* this method is called.
*
* @returns the DisputeClient instance
* @returns the IPAccountClient instance
*/
public get dispute(): DisputeClient {
if (this._dispute === null) {
this._dispute = new DisputeClient(this.rpcClient, this.wallet);
public get ipAccount(): IPAccountClient {
if (this._ipAccount === null) {
this._ipAccount = new IPAccountClient(this.rpcClient, this.wallet);
}

return this._dispute;
return this._ipAccount;
}
}
2 changes: 1 addition & 1 deletion packages/core-sdk/src/clients/storyAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class StoryAPIClient {
}

public async getRoyaltyPolicy(ipId: string): Promise<RoyaltyPolicy> {
const royaltyPolicyResp = await this.httpClient.get(`/api/v1/royaltypolicies/${ipId}`);
const royaltyPolicyResp = await this.httpClient.get(`/api/v1/royalties/policies/${ipId}`);
return (royaltyPolicyResp.data as RoyaltyPolicyApiResponse).data;
}

Expand Down
17 changes: 8 additions & 9 deletions packages/core-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export { IPAssetClient } from "./resources/ipAsset";
export { PermissionClient } from "./resources/permission";
export { LicenseClient } from "./resources/license";
export { PolicyClient } from "./resources/policy";
export { TaggingClient } from "./resources/tagging";
export { DisputeClient } from "./resources/dispute";

export type { StoryConfig } from "./types/config";
Expand All @@ -32,14 +31,7 @@ export type {
AddPolicyToIpResponse,
} from "./types/resources/policy";

export type { setPermissionsRequest, setPermissionsResponse } from "./types/resources/permission";

export type {
SetTagRequest,
SetTagResponse,
RemoveTagRequest,
RemoveTagResponse,
} from "./types/resources/tagging";
export type { SetPermissionsRequest, SetPermissionsResponse } from "./types/resources/permission";

export type {
Dispute,
Expand All @@ -52,3 +44,10 @@ export type {
ResolveDisputeRequest,
ResolveDisputeResponse,
} from "./types/resources/dispute";

export type {
IPAccountExecuteRequest,
IPAccountExecuteResponse,
IPAccountExecuteWithSigRequest,
IPAccountExecuteWithSigResponse,
} from "./types/resources/ipAccount";
96 changes: 96 additions & 0 deletions packages/core-sdk/src/resources/ipAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { PublicClient, WalletClient, getAddress } from "viem";

import {
IPAccountExecuteRequest,
IPAccountExecuteResponse,
IPAccountExecuteWithSigRequest,
IPAccountExecuteWithSigResponse,
} from "../types/resources/ipAccount";
import { handleError } from "../utils/errors";
import { IPAccountABI } from "../abi/config";
import { parseToBigInt, waitTx } from "../utils/utils";

export class IPAccountClient {
private readonly wallet: WalletClient;
private readonly rpcClient: PublicClient;
public ipAccountABI = IPAccountABI;

constructor(rpcClient: PublicClient, wallet: WalletClient) {
this.wallet = wallet;
this.rpcClient = rpcClient;
}

/** Executes a transaction from the IP Account.
* @param request The request object containing necessary data to execute IP Account a transaction.
* @param request.to The recipient of the transaction.
* @param request.value The amount of Ether to send.
* @param request.data The data to send along with the transaction.
* @returns Tx hash for the transaction.
*/
public async execute(request: IPAccountExecuteRequest): Promise<IPAccountExecuteResponse> {
try {
const IPAccountConfig = {
abi: this.ipAccountABI,
address: getAddress(request.accountAddress),
};

const { request: call } = await this.rpcClient.simulateContract({
...IPAccountConfig,
functionName: "execute",
args: [request.to, parseToBigInt(0), request.data],
account: this.wallet.account,
});
const txHash = await this.wallet.writeContract(call);

if (request.txOptions?.waitForTransaction) {
await waitTx(this.rpcClient, txHash);
}
return { txHash: txHash };
} catch (error) {
handleError(error, "Failed to execute the IP Account transaction");
}
}

/** Executes a transaction from the IP Account.
* @param request The request object containing necessary data to execute IP Account a transaction.
* @param request.to The recipient of the transaction.
* @param request.value The amount of Ether to send.
* @param request.data The data to send along with the transaction.
* @param request.signer The signer of the transaction.
* @param request.deadline The deadline of the transaction signature.
* @param request.signature The signature of the transaction, EIP-712 encoded.
* @returns Tx hash for the transaction.
*/
public async executeWithSig(
request: IPAccountExecuteWithSigRequest,
): Promise<IPAccountExecuteWithSigResponse> {
try {
const IPAccountConfig = {
abi: this.ipAccountABI,
address: getAddress(request.accountAddress),
};

const { request: call } = await this.rpcClient.simulateContract({
...IPAccountConfig,
functionName: "executeWithSig",
args: [
request.to,
parseToBigInt(0),
request.data,
request.signer,
parseToBigInt(request.deadline),
request.signature,
],
account: this.wallet.account,
});
const txHash = await this.wallet.writeContract(call);

if (request.txOptions?.waitForTransaction) {
await waitTx(this.rpcClient, txHash);
}
return { txHash: txHash };
} catch (error) {
handleError(error, "Failed to execute with signature for the IP Account transaction");
}
}
}
2 changes: 1 addition & 1 deletion packages/core-sdk/src/resources/ipAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class IPAssetClient {
...this.registrationModuleConfig,
functionName: "registerRootIp",
args: [
parseToBigInt(request.policyId),
parseToBigInt(request.policyId || "0"),
getAddress(request.tokenContractAddress), // 0x Address
parseToBigInt(request.tokenId),
request.ipName || "",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-sdk/src/resources/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class LicenseClient {
* @param request.licensorIpId_ The ID of the IP granting the license (ie. licensor)
* @param request.mintAmount Number of licenses to mint. License NFT is fungible for same policy and same licensors
* @param request.receiver Receiver address of the minted license NFT(s).
* @return licenseId The ID of the minted license NFT(s).
* @returns licenseId The ID of the minted license NFT(s).
*/
public async mintLicense(request: MintLicenseRequest): Promise<MintLicenseResponse> {
try {
Expand Down
4 changes: 2 additions & 2 deletions packages/core-sdk/src/resources/permission.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PublicClient, WalletClient, getAddress, Hex, encodeFunctionData } from "viem";

import { handleError } from "../utils/errors";
import { setPermissionsRequest, setPermissionsResponse } from "../types/resources/permission";
import { SetPermissionsRequest, SetPermissionsResponse } from "../types/resources/permission";
import { IPAccountABI, AccessControllerConfig } from "../abi/config";
import { parseToBigInt, waitTxAndFilterLog } from "../utils/utils";

Expand Down Expand Up @@ -35,7 +35,7 @@ export class PermissionClient {
* @returns A Promise that resolves to an object containing the transaction hash
* @emits PermissionSet (ipAccountOwner, ipAccount, signer, to, func, permission)
*/
public async setPermission(request: setPermissionsRequest): Promise<setPermissionsResponse> {
public async setPermission(request: SetPermissionsRequest): Promise<SetPermissionsResponse> {
try {
const IPAccountConfig = {
abi: this.ipAccountABI,
Expand Down
Loading

0 comments on commit e819baf

Please sign in to comment.