Skip to content

Commit

Permalink
create ip account (#46)
Browse files Browse the repository at this point in the history
* add ipAccountRegistryABI

* ipAccount scaffold

* add ipAccount to client

* add abis

* add initial fns

* add accessControl initial scaffold

* add unit test scaffold for ipAccount and ipAccountReadOnly

* add tests

* Lint

* Add account to simulate function

* Update ci environment

* Update CI

* Skip test for now

---------

Co-authored-by: Allen Chuang <[email protected]>
  • Loading branch information
edisonz0718 and allenchuang authored Jan 25, 2024
1 parent 9ef1930 commit 30001a3
Show file tree
Hide file tree
Showing 29 changed files with 1,246 additions and 113 deletions.
62 changes: 8 additions & 54 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,17 @@ on:
secrets:
API_BASE_URL:
required: true
STORY_PROTOCOL_CONTRACT:
IP_ACCOUNT_REGISTRY:
required: true
IP_ASSET_REGISTRY_CONTRACT:
REGISTRATION_MODULE:
required: true
IP_ORG_CONTROLLER_CONTRACT:
LICENSE_REGISTRY:
required: true
RELATIONSHIP_MODULE_CONTRACT:
required: true
REGISTRATION_MODULE_CONTRACT:
required: true
LICENSE_REGISTRY_CONTRACT:
required: true
MODULE_REGISTRY_CONTRACT:
required: true
LICENSE_MODULE_CONTRACT:
ACCESS_CONTROLLER:
required: true
RPC_PROVIDER_URL:
required: true
WALLET_PRIVATE_KEY:
required: true
TEST_WALLET_ADDRESS:
required: true
TEST_IPORG_ID:
required: true
TEST_IPORG_ID_WITH_HOOK:
required: true
TEST_IPASSET_ID1:
required: true
TEST_IPASSET_ID2:
required: true
TEST_RELATIONSHIP_ID:
required: true
TEST_RELATIONSHIP_TYPE:
required: true
TEST_LICENSE_ID:
required: true
TEST_HOOK_ID:
required: true
TEST_MODULE_ID:
required: true
TEST_TRANSACTION_ID:
required: true

jobs:
build:
Expand All @@ -67,27 +36,12 @@ jobs:
# TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
# TURBO_TEAM: ${{ vars.TURBO_TEAM }}
NEXT_PUBLIC_API_BASE_URL: ${{ secrets.API_BASE_URL }}
NEXT_PUBLIC_STORY_PROTOCOL_CONTRACT: ${{ secrets.STORY_PROTOCOL_CONTRACT }}
NEXT_PUBLIC_IP_ASSET_REGISTRY_CONTRACT: ${{ secrets.IP_ASSET_REGISTRY_CONTRACT }}
NEXT_PUBLIC_IP_ORG_CONTROLLER_CONTRACT: ${{ secrets.IP_ORG_CONTROLLER_CONTRACT }}
NEXT_PUBLIC_RELATIONSHIP_MODULE_CONTRACT: ${{ secrets.RELATIONSHIP_MODULE_CONTRACT }}
NEXT_PUBLIC_REGISTRATION_MODULE_CONTRACT: ${{ secrets.REGISTRATION_MODULE_CONTRACT }}
NEXT_PUBLIC_LICENSE_REGISTRY_CONTRACT: ${{ secrets.LICENSE_REGISTRY_CONTRACT }}
NEXT_PUBLIC_MODULE_REGISTRY_CONTRACT: ${{ secrets.MODULE_REGISTRY_CONTRACT }}
NEXT_PUBLIC_LICENSE_MODULE_CONTRACT: ${{secrets.LICENSE_MODULE_CONTRACT}}
NEXT_PUBLIC_IP_ACCOUNT_REGISTRY: ${{ secrets.IP_ACCOUNT_REGISTRY }}
NEXT_PUBLIC_REGISTRATION_MODULE: ${{ secrets.REGISTRATION_MODULE }}
NEXT_PUBLIC_LICENSE_REGISTRY: ${{ secrets.LICENSE_REGISTRY }}
NEXT_PUBLIC_ACCESS_CONTROLLER: ${{ secrets.ACCESS_CONTROLLER }}
RPC_PROVIDER_URL: ${{ secrets.RPC_PROVIDER_URL }}
WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }}
TEST_WALLET_ADDRESS: ${{ secrets.TEST_WALLET_ADDRESS }}
TEST_IPORG_ID: ${{ secrets.TEST_IPORG_ID }}
TEST_IPORG_ID_WITH_HOOK: ${{ secrets.TEST_IPORG_ID_WITH_HOOK }}
TEST_IPASSET_ID1: ${{ secrets.TEST_IPASSET_ID1 }}
TEST_IPASSET_ID2: ${{ secrets.TEST_IPASSET_ID2 }}
TEST_RELATIONSHIP_ID: ${{ secrets.TEST_RELATIONSHIP_ID }}
TEST_RELATIONSHIP_TYPE: ${{ secrets.TEST_RELATIONSHIP_TYPE }}
TEST_LICENSE_ID: ${{ secrets.TEST_LICENSE_ID }}
TEST_HOOK_ID: ${{ secrets.TEST_HOOK_ID }}
TEST_MODULE_ID: ${{ secrets.TEST_MODULE_ID }}
TEST_TRANSACTION_ID: ${{ secrets.TEST_TRANSACTION_ID }}

steps:
- name: Check out code
Expand Down
25 changes: 5 additions & 20 deletions .github/workflows/internal-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,12 @@ jobs:
uses: ./.github/workflows/build-and-test.yaml
with:
sha: ${{ github.event.pull_request.head.sha }}
ENVIRONMENT: 'alpha-sepolia'
ENVIRONMENT: 'beta-sepolia'
secrets:
IP_ACCOUNT_REGISTRY: ${{ secrets.IP_ACCOUNT_REGISTRY }}
REGISTRATION_MODULE: ${{ secrets.REGISTRATION_MODULE }}
LICENSE_REGISTRY: ${{ secrets.LICENSE_REGISTRY }}
ACCESS_CONTROLLER: ${{ secrets.ACCESS_CONTROLLER }}
API_BASE_URL: ${{ secrets.API_BASE_URL }}
STORY_PROTOCOL_CONTRACT: ${{ secrets.STORY_PROTOCOL_CONTRACT }}
IP_ASSET_REGISTRY_CONTRACT: ${{ secrets.IP_ASSET_REGISTRY_CONTRACT }}
IP_ORG_CONTROLLER_CONTRACT: ${{ secrets.IP_ORG_CONTROLLER_CONTRACT }}
RELATIONSHIP_MODULE_CONTRACT: ${{ secrets.RELATIONSHIP_MODULE_CONTRACT }}
REGISTRATION_MODULE_CONTRACT: ${{ secrets.REGISTRATION_MODULE_CONTRACT }}
LICENSE_REGISTRY_CONTRACT: ${{ secrets.LICENSE_REGISTRY_CONTRACT }}
MODULE_REGISTRY_CONTRACT: ${{ secrets.MODULE_REGISTRY_CONTRACT }}
LICENSE_MODULE_CONTRACT: ${{ secrets.LICENSE_MODULE_CONTRACT }}
RPC_PROVIDER_URL: ${{ secrets.RPC_PROVIDER_URL }}
WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }}
TEST_WALLET_ADDRESS: ${{ secrets.TEST_WALLET_ADDRESS }}
TEST_IPORG_ID: ${{ secrets.TEST_IPORG_ID }}
TEST_IPORG_ID_WITH_HOOK: ${{ secrets.TEST_IPORG_ID_WITH_HOOK }}
TEST_IPASSET_ID1: ${{ secrets.TEST_IPASSET_ID1 }}
TEST_IPASSET_ID2: ${{ secrets.TEST_IPASSET_ID2 }}
TEST_RELATIONSHIP_ID: ${{ secrets.TEST_RELATIONSHIP_ID }}
TEST_RELATIONSHIP_TYPE: ${{ secrets.TEST_RELATIONSHIP_TYPE }}
TEST_LICENSE_ID: ${{ secrets.TEST_LICENSE_ID }}
TEST_HOOK_ID: ${{ secrets.TEST_HOOK_ID }}
TEST_MODULE_ID: ${{ secrets.TEST_MODULE_ID }}
TEST_TRANSACTION_ID: ${{ secrets.TEST_TRANSACTION_ID }}
1 change: 1 addition & 0 deletions packages/core-sdk/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ FRANCHISE_REGISTRY_CONTRACT =
RELATIONSHIP_MODULE_CONTRACT =
COLLECT_MODULE_CONTRACT =
LICENSING_MODULE_CONTRACT =
IP_ACCOUNT_REGISTRY =

# TEST CONFIGs
RPC_PROVIDER_URL =
Expand Down
14 changes: 14 additions & 0 deletions packages/core-sdk/src/abi/accessController.abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { formatAbi } from "abitype";
import { getAddress } from "viem";

import AccessControllerABI from "./json/AccessController.abi";

export const AccessControllerRaw = AccessControllerABI;
export const AccessControllerReadable = formatAbi(AccessControllerRaw);

export const AccessControllerConfig = {
abi: AccessControllerRaw,
address: getAddress(
process.env.ACCESS_CONTROLLER || process.env.NEXT_PUBLIC_ACCESS_CONTROLLER || "",
),
};
19 changes: 19 additions & 0 deletions packages/core-sdk/src/abi/ipAccountRegistry.abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { formatAbi } from "abitype";
import { getAddress } from "viem";
import * as dotenv from "dotenv";

import IPAccountRegistryABI from "./json/IIPAccountRegistry.abi";

if (typeof process !== "undefined") {
dotenv.config();
}

export const IPAccountRegistryRaw = IPAccountRegistryABI;
export const IPAccountRegistryReadable = formatAbi(IPAccountRegistryRaw);

export const IPAccountRegistryConfig = {
abi: IPAccountRegistryRaw,
address: getAddress(
process.env.IP_ACCOUNT_REGISTRY || process.env.NEXT_PUBLIC_IP_ACCOUNT_REGISTRY || "",
),
};
58 changes: 29 additions & 29 deletions packages/core-sdk/src/abi/json/IIPAccountRegistry.abi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
export default [
{
inputs: [
{
internalType: "uint256",
name: "chainId_",
type: "uint256",
},
{
internalType: "address",
name: "tokenContract_",
type: "address",
},
{
internalType: "uint256",
name: "tokenId_",
type: "uint256",
},
],
name: "ipAccount",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
{
anonymous: false,
inputs: [
Expand Down Expand Up @@ -36,33 +65,4 @@ export default [
name: "IPAccountRegistered",
type: "event",
},
{
inputs: [
{
internalType: "uint256",
name: "chainId_",
type: "uint256",
},
{
internalType: "address",
name: "tokenContract_",
type: "address",
},
{
internalType: "uint256",
name: "tokenId_",
type: "uint256",
},
],
name: "ipAccount",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
] as const;
68 changes: 68 additions & 0 deletions packages/core-sdk/src/abi/json/IPAccountRegistry.abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
export default [
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "account",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "implementation",
type: "address",
},
{
indexed: true,
internalType: "uint256",
name: "chainId",
type: "uint256",
},
{
indexed: false,
internalType: "address",
name: "tokenContract",
type: "address",
},
{
indexed: false,
internalType: "uint256",
name: "tokenId",
type: "uint256",
},
],
name: "IPAccountRegistered",
type: "event",
},
{
inputs: [
{
internalType: "uint256",
name: "chainId_",
type: "uint256",
},
{
internalType: "address",
name: "tokenContract_",
type: "address",
},
{
internalType: "uint256",
name: "tokenId_",
type: "uint256",
},
],
name: "ipAccount",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
] as const;
14 changes: 14 additions & 0 deletions packages/core-sdk/src/abi/licenseRegistry.abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { formatAbi } from "abitype";
import { getAddress } from "viem";

import LicenseRegistryABI from "./json/LicenseRegistry.abi";

export const LicenseRegistryRaw = LicenseRegistryABI;
export const LicenseRegistryReadable = formatAbi(LicenseRegistryRaw);

export const LicenseRegistryConfig = {
abi: LicenseRegistryRaw,
address: getAddress(
process.env.LICENSE_REGISTRY || process.env.NEXT_PUBLIC_LICENSE_REGISTRY || "",
),
};
12 changes: 12 additions & 0 deletions packages/core-sdk/src/abi/moduleRegistry.abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { formatAbi } from "abitype";
import { getAddress } from "viem";

import ModuleRegistryABI from "./json/ModuleRegistry.abi";

export const ModuleRegistryRaw = ModuleRegistryABI;
export const ModuleRegistryReadable = formatAbi(ModuleRegistryRaw);

export const ModuleRegistryConfig = {
abi: ModuleRegistryRaw,
address: getAddress(process.env.MODULE_REGISTRY || process.env.NEXT_PUBLIC_MODULE_REGISTRY || ""),
};
15 changes: 15 additions & 0 deletions packages/core-sdk/src/abi/registrationModule.abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getAddress } from "viem";

import RegistrationModuleABI from "./json/RegistrationModule.abi";
import errorsJson from "./json/Errors.json";

export const ErrorsAbi = errorsJson;

const storyProtocolMerged = [...RegistrationModuleABI, ...ErrorsAbi];

export const RegistrationModuleConfig = {
abi: storyProtocolMerged,
address: getAddress(
process.env.REGISTRATION_MODULE || process.env.NEXT_PUBLIC_REGISTRATION_MODULE || "",
),
};
12 changes: 12 additions & 0 deletions packages/core-sdk/src/abi/taggingModule.abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { formatAbi } from "abitype";
import { getAddress } from "viem";

import TaggingModuleABI from "./json/TaggingModule.abi";

export const TaggingModuleRaw = TaggingModuleABI;
export const TaggingModuleReadable = formatAbi(TaggingModuleRaw);

export const TaggingModuleConfig = {
abi: TaggingModuleRaw,
address: getAddress(process.env.TAGGING_MODULE || process.env.NEXT_PUBLIC_TAGGING_MODULE || ""),
};
13 changes: 13 additions & 0 deletions packages/core-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { TransactionReadOnlyClient } from "./resources/transactionReadOnly";
import { HTTP_TIMEOUT } from "./constants/http";
import { Client, ReadOnlyClient } from "./types/client";
import { PlatformClient } from "./utils/platform";
import { IPAccountClient } from "./resources/ipAccount";
import { IPAccountReadOnlyClient } from "./resources/ipAccountReadOnly";

if (typeof process !== "undefined") {
dotenv.config();
Expand All @@ -23,6 +25,7 @@ export class StoryClient {
private readonly rpcClient: PublicClient;
private readonly wallet?: WalletClient;

private _ipAccount: IPAccountClient | IPAccountReadOnlyClient | null = null;
private _transaction: TransactionClient | TransactionReadOnlyClient | null = null;
private _platform: PlatformClient | null = null;

Expand Down Expand Up @@ -80,6 +83,16 @@ export class StoryClient {
return new StoryClient(config, false) as Client;
}

public get ipAccount(): IPAccountClient | IPAccountReadOnlyClient {
if (this._ipAccount === null) {
this._ipAccount = this.isReadOnly
? new IPAccountReadOnlyClient(this.httpClient, this.rpcClient)
: new IPAccountClient(this.httpClient, this.rpcClient, this.wallet!);
}

return this._ipAccount;
}

/**
* Getter for the transaction client. The client is lazily created when
* this method is called.
Expand Down
Loading

0 comments on commit 30001a3

Please sign in to comment.