Skip to content
Merged
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
17 changes: 17 additions & 0 deletions packages/core-sdk/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Run Test File",
"outputCapture": "std",
"program": "${workspaceRoot}/node_modules/mocha/bin/mocha.js",
"args": ["-r", "ts-node/register", "${relativeFile}"],
"console": "integratedTerminal",
"env": {
"TS_NODE_PROJECT": "./tsconfig.test.json"
}
}
]
}
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": "1.3.0-beta.1",
"version": "1.3.0-beta.2",
"description": "Story Protocol Core SDK",
"main": "dist/story-protocol-core-sdk.cjs.js",
"module": "dist/story-protocol-core-sdk.esm.js",
Expand Down
8 changes: 8 additions & 0 deletions packages/core-sdk/src/abi/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20672,6 +20672,14 @@ export class IpAccountImplReadOnlyClient {
functionName: "token",
});
}

public async owner(): Promise<Address> {
return await this.rpcClient.readContract({
abi: ipAccountImplAbi,
address: this.address,
functionName: "owner",
});
}
}

/**
Expand Down
27 changes: 25 additions & 2 deletions packages/core-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import { PermissionClient } from "./resources/permission";
import { LicenseClient } from "./resources/license";
import { DisputeClient } from "./resources/dispute";
import { IPAccountClient } from "./resources/ipAccount";
import { chain, chainStringToViemChain } from "./utils/utils";
import { chain, chainStringToViemChain, validateAddress } from "./utils/utils";
import { RoyaltyClient } from "./resources/royalty";
import { NftClient } from "./resources/nftClient";
import { GroupClient } from "./resources/group";
import { SimpleWalletClient } from "./abi/generated";
import { WipClient } from "./resources/wip";

if (typeof process !== "undefined") {
dotenv.config();
Expand All @@ -36,14 +37,15 @@ export class StoryClient {
private _royalty: RoyaltyClient | null = null;
private _nftClient: NftClient | null = null;
private _group: GroupClient | null = null;
private _wip: WipClient | null = null;

/**
* @param config - the configuration for the SDK client
*/
private constructor(config: StoryConfig) {
this.config = {
...config,
chainId: chain[config.chainId || "homer"],
chainId: chain[config.chainId || "aeneid"],
};
if (!this.config.transport) {
throw new Error(
Expand Down Expand Up @@ -218,4 +220,25 @@ export class StoryClient {

return this._group;
}

public get wipClient(): WipClient {
if (this._wip === null) {
this._wip = new WipClient(this.rpcClient, this.wallet);
}
return this._wip;
}

public async getWalletBalance(): Promise<bigint> {
if (!this.wallet.account) {
throw new Error("No account found in wallet");
}
return await this.getBalance(this.wallet.account.address);
}

public async getBalance(address: string): Promise<bigint> {
const validAddress = validateAddress(address);
return await this.rpcClient.getBalance({
address: validAddress,
});
}
}
7 changes: 5 additions & 2 deletions packages/core-sdk/src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ import { Hex } from "viem";
export const AddressZero = "0x0000000000000000000000000000000000000000";
export const HashZero = "0x0000000000000000000000000000000000000000000000000000000000000000";
export const defaultFunctionSelector: Hex = "0x00000000";
export const royaltySharesTotalSupply: number = 100000000;
export const MAX_ROYALTY_TOKEN = 100000000;
export const royaltySharesTotalSupply: number = 100_000_000;
export const MAX_ROYALTY_TOKEN = 100_000_000;

/** Address for the WIP contract. This address is fixed */
export const WIP_TOKEN_ADDRESS = "0x1514000000000000000000000000000000000000";
2 changes: 1 addition & 1 deletion packages/core-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { StoryClient } from "./client";
export { AddressZero, HashZero } from "./constants/common";
export { homer } from "./utils/chain";
export { aeneid } from "./utils/chain";
export { IPAssetClient } from "./resources/ipAsset";
export { PermissionClient } from "./resources/permission";
export { LicenseClient } from "./resources/license";
Expand Down
Loading