Skip to content

Commit

Permalink
Merge pull request #90 from storyprotocol/dev
Browse files Browse the repository at this point in the history
beta rc6
  • Loading branch information
edisonz0718 authored Feb 24, 2024
2 parents e819baf + 145880f commit 9546822
Show file tree
Hide file tree
Showing 32 changed files with 2,330 additions and 274 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ compile_contracts:
solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-contracts --include-path packages/core-sdk/protocol-contracts/node_modules/ --abi packages/core-sdk/protocol-contracts/contracts/IPAccountImpl.sol -o packages/core-sdk/src/abi/json/tmp/IPAccountImpl
solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-contracts --include-path packages/core-sdk/protocol-contracts/node_modules/ --abi packages/core-sdk/protocol-contracts/contracts/AccessController.sol -o packages/core-sdk/src/abi/json/tmp/AccessController
solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-contracts --include-path packages/core-sdk/protocol-contracts/node_modules/ --abi packages/core-sdk/protocol-contracts/contracts/modules/RegistrationModule.sol -o packages/core-sdk/src/abi/json/tmp/RegistrationModule
solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-contracts --include-path packages/core-sdk/protocol-contracts/node_modules/ --abi packages/core-sdk/protocol-contracts/contracts/modules/dispute-module/DisputeModule.sol -o packages/core-sdk/src/abi/json/tmp/DisputeModule
solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-contracts --include-path packages/core-sdk/protocol-contracts/node_modules/ --abi packages/core-sdk/protocol-contracts/contracts/modules/dispute/DisputeModule.sol -o packages/core-sdk/src/abi/json/tmp/DisputeModule
solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-contracts --include-path packages/core-sdk/protocol-contracts/node_modules/ --abi packages/core-sdk/protocol-contracts/contracts/modules/licensing/LicensingModule.sol -o packages/core-sdk/src/abi/json/tmp/LicensingModule
solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-contracts --include-path packages/core-sdk/protocol-contracts/node_modules/ --abi packages/core-sdk/protocol-contracts/contracts/modules/licensing/PILPolicyFrameworkManager.sol -o packages/core-sdk/src/abi/json/tmp/PILPolicyFrameworkManager
solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-contracts --include-path packages/core-sdk/protocol-contracts/node_modules/ --abi packages/core-sdk/protocol-contracts/contracts/modules/tagging/TaggingModule.sol -o packages/core-sdk/src/abi/json/tmp/TaggingModule
solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-contracts --include-path packages/core-sdk/protocol-contracts/node_modules/ --abi packages/core-sdk/protocol-contracts/contracts/interfaces/registries/IIPAssetRegistry.sol -o packages/core-sdk/src/abi/json/tmp/IIPAssetRegistry
solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-contracts --include-path packages/core-sdk/protocol-contracts/node_modules/ --abi packages/core-sdk/protocol-contracts/contracts/registries/LicenseRegistry.sol -o packages/core-sdk/src/abi/json/tmp/LicenseRegistry
solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-contracts --include-path packages/core-sdk/protocol-contracts/node_modules/ --abi packages/core-sdk/protocol-contracts/contracts/lib/Errors.sol -o packages/core-sdk/src/abi/json/tmp/Errors
Expand All @@ -22,7 +21,6 @@ compile_contracts:
echo 'export default '"$$(jq --argjson entities "$$(jq -c '.' packages/core-sdk/src/abi/sdkEntities.json)" 'map(select(.name as $$name | $$entities | if type == "array" then index($$name) else false end))' packages/core-sdk/src/abi/json/tmp/DisputeModule/DisputeModule.abi)"' as const;' > packages/core-sdk/src/abi/json/DisputeModule.abi.ts
echo 'export default '"$$(jq --argjson entities "$$(jq -c '.' packages/core-sdk/src/abi/sdkEntities.json)" 'map(select(.name as $$name | $$entities | if type == "array" then index($$name) else false end))' packages/core-sdk/src/abi/json/tmp/LicensingModule/LicensingModule.abi)"' as const;' > packages/core-sdk/src/abi/json/LicensingModule.abi.ts
echo 'export default '"$$(jq --argjson entities "$$(jq -c '.' packages/core-sdk/src/abi/sdkEntities.json)" 'map(select(.name as $$name | $$entities | if type == "array" then index($$name) else false end))' packages/core-sdk/src/abi/json/tmp/PILPolicyFrameworkManager/PILPolicyFrameworkManager.abi)"' as const;' > packages/core-sdk/src/abi/json/PILPolicyFrameworkManager.abi.ts
echo 'export default '"$$(jq --argjson entities "$$(jq -c '.' packages/core-sdk/src/abi/sdkEntities.json)" 'map(select(.name as $$name | $$entities | if type == "array" then index($$name) else false end))' packages/core-sdk/src/abi/json/tmp/TaggingModule/TaggingModule.abi)"' as const;' > packages/core-sdk/src/abi/json/TaggingModule.abi.ts
echo 'export default '"$$(jq --argjson entities "$$(jq -c '.' packages/core-sdk/src/abi/sdkEntities.json)" 'map(select(.name as $$name | $$entities | if type == "array" then index($$name) else false end))' packages/core-sdk/src/abi/json/tmp/IIPAssetRegistry/IIPAssetRegistry.abi)"' as const;' > packages/core-sdk/src/abi/json/IIPAssetRegistry.abi.ts
echo 'export default '"$$(jq --argjson entities "$$(jq -c '.' packages/core-sdk/src/abi/sdkEntities.json)" 'map(select(.name as $$name | $$entities | if type == "array" then index($$name) else false end))' packages/core-sdk/src/abi/json/tmp/LicenseRegistry/LicenseRegistry.abi)"' as const;' > packages/core-sdk/src/abi/json/LicenseRegistry.abi.ts

Expand Down
84 changes: 23 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,97 +11,59 @@ Suppose you already have a node project or created a new node project. First, yo
Use `npm`:

```
npm install --save @story-protocol/core-sdk viem
npm install --save @story-protocol/core-sdk viem@1.21.4
```

Use `pnpm`:

```
pnpm install @story-protocol/core-sdk viem
pnpm install @story-protocol/core-sdk viem@1.21.4
```

Use `yarn`:

```
yarn add @story-protocol/core-sdk viem
yarn add @story-protocol/core-sdk viem@1.21.4
```

Besides the Story Protocol SDK package `@story-protocol/core-sdk`, we also require the package `viem` (https://www.npmjs.com/package/viem) to access the DeFi wallet accounts.

### Setup the `.env` file for your project
# Initiate SDK Client

The second steps is to create a file named `.env` in the root directory of the project with the following environment variables:
Next we can initiate the SDK Client by first setting up our wallet and then the client itself.

```
NEXT_PUBLIC_API_BASE_URL=
NEXT_PUBLIC_STORY_PROTOCOL_CONTRACT=
NEXT_PUBLIC_IP_ASSET_REGISTRY_CONTRACT=
NEXT_PUBLIC_IP_ORG_CONTROLLER_CONTRACT=
NEXT_PUBLIC_RELATIONSHIP_MODULE_CONTRACT=
NEXT_PUBLIC_REGISTRATION_MODULE_CONTRACT=
NEXT_PUBLIC_LICENSE_REGISTRY_CONTRACT=
NEXT_PUBLIC_MODULE_REGISTRY_CONTRACT=
# RPC Endpoint for Sepolia Testnet
RPC_URL=https://rpc.ankr.com/eth_sepolia
# Private key of the wallet to interact with Story Protocol SDK
PRIVATE_KEY="<KEEP_ME_SECRET>"
```

The above `.env` defines several variables with prefix `NEXT_PUBLIC_`that will be used by Story Protocol SDK. Because the alpha version of Story Protocol SDK works with the smart contracts deployed on Sepolia testnet, we need to provide the RPC URL for the end point.

For the latest values of the smart contract addresses, please reach out the Story Protocol team or refer to [SDK Setup Guide Document](https://docs.storyprotocol.xyz/docs/setup)
## Set up your wallet

### Create Story Protocol Client
The SDK supports using `viem` for initiating SDK client. Create a typescript file and write the following code to initiate the client with a private key:

Next, we need create a client to access Story Protocol by using private key or from the wallet app of browser.
> :information-source: Make sure to have WALLET_PRIVATE_KEY set up in your .env file.
Here is the way to create a Story Protocol client with the private key:

```typescript
```typescript index.ts
import { privateKeyToAccount } from 'viem/accounts';

const PRIVATE_KEY = process.env.PRIVATE_KEY || '0x';
const account = privateKeyToAccount(PRIVATE_KEY as `0x${string}`);

// Instantiate the Story Client for readonly operations, using default
export const realonlyClient = StoryClient.newReadOnlyClient({});

// Instantiate the Story Client, test environment required for alpha release.
// The private key is also required for written operations.
export const client = StoryClient.newClient({ account });
const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY || '0x';
const account = privateKeyToAccount(WALLET_PRIVATE_KEY as `0x${string}`);
```

Here is the way to create a Story Protocol with wallet app:
The preceding code created the `account` object for creating the SDK client.

```typescript
import { createWalletClient, custom } from 'viem';
## Set up SDK client

const walletClient = createWalletClient({
chainId: 'sepolia',
transport: custom(window.ethereum),
});
To set up the SDK client, import `StoryClient` and `StoryConfig` from `@story-protocol/core-sdk`. Write the following code, utilizing the `account` we created previously.

// Retrieve the first account for eth_requestAccounts method
const account = await walletClient.requestAddresses()[0];
> :information-source: Make sure to have RPC_PROVIDER_URL for your desired chain set up in your .env file. We recommend using the Sepolia network with `RPC_PROVIDER_URL=https://rpc.ankr.com/eth_sepolia`.
// Instantiate the Story Client for readonly operations, using default
export const realonlyClient = StoryClient.newReadOnlyClient({});
```typescript index.ts
import { StoryClient, StoryConfig } from '@story-protocol/core-sdk';

// Instantiate the Story Client, test environment required for alpha release.
// The private key is also required for written operations.
export const client = StoryClient.newClient({ account });
const config: StoryConfig = {
transport: http(process.env.RPC_PROVIDER_URL),
account: account,
};
const client = StoryClient.newClient(config);
```

### Use `Client` or `ReadOnlyClient` to access Story Protocol

Now you can use the `ReadOnlyClient` instance to perform read-only operations with Story Protocol resources, and `Client` instance to perform both read-only and write operations. `ReadOnlyClient` and `Client` are the aggregators for accessing the resources. You can refer to [SDK document](https://docs.storyprotocol.xyz/docs/overview-1) to learn how to use these clients interact with Story Protocol.

You can also refer to the [Story Protocol Example Repostory](https://github.com/storyprotocol/my-story-protocol-example/) to learn with the SDK example.

## How To Build and Test Story Protocol SDK
## How To Build and Test Story Protocol SDK for local testing

This section provides the instructions on how to build Story Protocol SDK from source code.

Expand Down
140 changes: 97 additions & 43 deletions packages/core-sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,124 @@
core-sdk is the base level sdk to interact with story protocol. It provides functions to both read and write data to the protocol.
# Story Protocol SDK

## Installation
Welcome to the documents for Story Protocol SDK. The SDK provides the APIs for developers to build applications with Story Protocol. By using the SDK, developers can create the resources like IP assets and perform actions to interact with the resource.

Install the SDK and ethers.js
## How to use Story Protocol SDK in Your Project

npm
### Install Story Protocol core SDK

```shell
npm i @story-protocol/core-sdk ethers@^5.7.2
```
Suppose you already have a node project or created a new node project. First, you need to install `@story-protocol/core-sdk` in your project. You can use one of the following command to install the package:

pnpm
Use `npm`:

```shell
pnpm i @story-protocol/core-sdk ethers@^5.7.2
```
npm install --save @story-protocol/core-sdk [email protected]
```

yarn
Use `pnpm`:

```shell
yarn add @story-protocol/core-sdk ethers@^5.7.2
```
pnpm install @story-protocol/core-sdk [email protected]
```

## Set up `.env` file

(Ask the team to provide the values)
Use `yarn`:

```
NEXT_PUBLIC_API_BASE_URL =
NEXT_PUBLIC_FRANCHISE_REGISTRY_CONTRACT =
NEXT_PUBLIC_RELATIONSHIP_MODULE_CONTRACT =
NEXT_PUBLIC_COLLECT_MODULE_CONTRACT =
NEXT_PUBLIC_LICENSING_MODULE_CONTRACT =
yarn add @story-protocol/core-sdk [email protected]
```

## Set up SDK client
Besides the Story Protocol SDK package `@story-protocol/core-sdk`, we also require the package `viem` (https://www.npmjs.com/package/viem) to access the DeFi wallet accounts.

Using browser wallet
# Initiate SDK Client

```typescript
import { StoryClient } from "@story-protocol/core-sdk";
import ethers from "ethers";
Next we can initiate the SDK Client by first setting up our wallet and then the client itself.

// Provider/Signer from browser wallet (i.e Metamask)
const provider = new ethers.providers.Web3Provider(window.ethereum);
await provider.send("eth_requestAccounts", []);
const signer = await provider.getSigner();
## Set up your wallet

// Instantiate a read-only Story Client with an optional provider
const client = StoryClient.newReadOnlyClient({ provider });
The SDK supports using `viem` for initiating SDK client. Create a typescript file and write the following code to initiate the client with a private key:

// Instatiate a read/write Story Client with a signer
const client = StoryClient.newClient({ signer });
> :information-source: Make sure to have WALLET_PRIVATE_KEY set up in your .env file.
```typescript index.ts
import { privateKeyToAccount } from "viem/accounts";

const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY || "0x";
const account = privateKeyToAccount(WALLET_PRIVATE_KEY as `0x${string}`);
```

Using private key
The preceding code created the `account` object for creating the SDK client.

## Set up SDK client

```typescript
import { StoryClient } from "@story-protocol/core-sdk"
import ethers from "ethers"
To set up the SDK client, import `StoryClient` and `StoryConfig` from `@story-protocol/core-sdk`. Write the following code, utilizing the `account` we created previously.

// Signer from private key
const provider = new ethers.providers.JsonRpcProvider(<YOUR RPC URL>)
const signer = new ethers.Wallet(<YOUR PRIVATE KEY>, provider)
> :information-source: Make sure to have RPC_PROVIDER_URL for your desired chain set up in your .env file. We recommend using the Sepolia network with `RPC_PROVIDER_URL=https://rpc.ankr.com/eth_sepolia`.
// Instantiate the Story Client
const client = StoryClient.newClient({ signer })
```typescript index.ts
import { StoryClient, StoryConfig } from "@story-protocol/core-sdk";

const config: StoryConfig = {
transport: http(process.env.RPC_PROVIDER_URL),
account: account,
};
const client = StoryClient.newClient(config);
```

## How To Build and Test Story Protocol SDK for local testing

This section provides the instructions on how to build Story Protocol SDK from source code.

### Prerequisite

- Install PNPM: Execute `npm install -g pnpm`
- Install TypeScript: Run `pnpm add typescript -D`
- Install Yalc: Use `npm install -g yalc`

### Steps for Using Yalc for Local Testing of Core-SDK

For manual testing of the core-sdk, set up a separate web project. The guide below uses `yalc` to link the `core-sdk` locally, enabling its installation and import for testing.

Under the `typescript-sdk/packages/core-sdk` directory:

- Navigate to the `core-sdk` directory.
- Execute `npm run build` to build your latest code.
- Run `yalc publish`. You should see a message like `@story-protocol/core-sdk@<version> published in store.` (Note: The version number may vary).

To set up your testing environment (e.g., a new Next.js project), use `yalc add @story-protocol/core-sdk@<version>` (ensure the version number is updated accordingly).

- Run `pnpm install`. This installs `@story-protocol/core-sdk@<version>` with your local changes.

### Steps to Refresh the Changes

Under the `typescript-sdk/packages/core-sdk` directory:

- Execute `npm run build` to build your latest code.
- Run `yalc push`.

In your testing environment:

- Run `yalc update` to pull the latest changes.

## Steps to pull and compile latest smart contract ABIs (Currently pulls from the protocol-contracts `dev` branch)

Must have `solc` installed (https://docs.soliditylang.org/en/v0.8.9/installing-solidity.html)

- run `make compile_contracts`

## Release

| Package | Description |
| :------------------------------ | :--------------------------------------------- |
| [core-sdk](./packages/core-sdk) | The core sdk for interacting with the protocol |

## Contributing

Pull requests are welcome. For major changes, please open an issue first
to discuss what you would like to change. Details see: [CONTRIBUTING](/CONTRIBUTING.md)

Please make sure to update tests as appropriate.

## License

[MIT License](/LICENSE.md)

## Contact Us
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.5",
"version": "0.0.1-beta-rc.6",
"description": "Story Protocol Core SDK",
"main": "dist/story-protocol-core-sdk.cjs.js",
"module": "dist/story-protocol-core-sdk.esm.js",
Expand Down
4 changes: 4 additions & 0 deletions packages/core-sdk/src/abi/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ export const PILPolicyFrameworkManagerConfig = {
abi: [...PILPolicyFrameworkManagerABI, ...ErrorsABI],
address: getAddress(sepolia.PILPolicyFrameworkManager),
};

export const RoyaltyPolicyLAPConfig = {
address: getAddress(sepolia.RoyaltyPolicyLAP),
};
25 changes: 0 additions & 25 deletions packages/core-sdk/src/abi/json/Errors.abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,29 +816,4 @@ export default [
name: "RoyaltyPolicyLAP__ZeroRoyaltyModule",
type: "error",
},
{
inputs: [],
name: "TaggingModule__DstIpIdDoesNotHaveDstTag",
type: "error",
},
{
inputs: [],
name: "TaggingModule__InvalidRelationTypeName",
type: "error",
},
{
inputs: [],
name: "TaggingModule__RelationTypeAlreadyExists",
type: "error",
},
{
inputs: [],
name: "TaggingModule__RelationTypeDoesNotExist",
type: "error",
},
{
inputs: [],
name: "TaggingModule__SrcIpIdDoesNotHaveSrcTag",
type: "error",
},
] as const;
25 changes: 0 additions & 25 deletions packages/core-sdk/src/abi/json/Errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -815,30 +815,5 @@
"inputs": [],
"name": "RoyaltyPolicyLAP__ZeroRoyaltyModule",
"type": "error"
},
{
"inputs": [],
"name": "TaggingModule__DstIpIdDoesNotHaveDstTag",
"type": "error"
},
{
"inputs": [],
"name": "TaggingModule__InvalidRelationTypeName",
"type": "error"
},
{
"inputs": [],
"name": "TaggingModule__RelationTypeAlreadyExists",
"type": "error"
},
{
"inputs": [],
"name": "TaggingModule__RelationTypeDoesNotExist",
"type": "error"
},
{
"inputs": [],
"name": "TaggingModule__SrcIpIdDoesNotHaveSrcTag",
"type": "error"
}
]
Loading

0 comments on commit 9546822

Please sign in to comment.