Skip to content

Commit

Permalink
Add collectRoyaltyTokens and payRoyaltyOnBehalf in royalty (#120)
Browse files Browse the repository at this point in the history
* Add royality test setup

* Update Royalty abi

* Add collectRoyaltyTokens method

* Update abi for getRoyaltyData method

* Update abi for other royalty methods

* Add collectRoyaltyTokens and payRoyaltyOnBehalfin royalty

* Update tokenId

* Export royalty types

* Upgrade version and skip storyNet tests

* Refactor code
  • Loading branch information
bonnie57 authored Apr 8, 2024
1 parent d537b05 commit 6497498
Show file tree
Hide file tree
Showing 17 changed files with 660 additions and 9 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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/access/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/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/royalty/policies/IpRoyaltyVault.sol -o packages/core-sdk/src/abi/json/tmp/Royalty
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/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
Expand All @@ -19,6 +20,9 @@ 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/AccessController/AccessController.abi)"' as const;' > packages/core-sdk/src/abi/json/AccessController.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/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/Royalty/IpRoyaltyVault.abi)"' as const;' > packages/core-sdk/src/abi/json/IpRoyaltyVault.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/Royalty/IRoyaltyPolicyLAP.abi)"' as const;' > packages/core-sdk/src/abi/json/IRoyaltyPolicyLAP.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/IRoyaltyModule.abi)"' as const;' > packages/core-sdk/src/abi/json/IRoyaltyModule.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/IPAssetRegistry/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
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.11",
"version": "0.0.1-beta-rc.12",
"description": "Story Protocol Core SDK",
"main": "dist/story-protocol-core-sdk.cjs.js",
"module": "dist/story-protocol-core-sdk.esm.js",
Expand Down
14 changes: 14 additions & 0 deletions packages/core-sdk/src/abi/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import IPAccountImplABI from "./json/IPAccountImpl.abi";
import IPAssetRegistryABI from "./json/IIPAssetRegistry.abi";
import LicensingModuleABI from "./json/LicensingModule.abi";
import PILPolicyFrameworkManagerABI from "./json/PILPolicyFrameworkManager.abi";
import IRoyaltyPolicyLAPABI from "./json/IRoyaltyPolicyLAP.abi";
import IpRoyaltyVaultABI from "./json/IpRoyaltyVault.abi";
import IRoyaltyModuleABI from "./json/IRoyaltyModule.abi";
import ErrorsABI from "./json/Errors.abi";
import { contractAddress } from "../utils/env";
import { SupportedChainIds } from "../types/config";
Expand Down Expand Up @@ -39,5 +42,16 @@ export const getPILPolicyFrameworkManagerConfig = (chain: SupportedChainIds) =>
address: getAddress(contractAddress[chain].PILPolicyFrameworkManager),
});
export const getRoyaltyPolicyLAPConfig = (chain: SupportedChainIds) => ({
abi: [...IRoyaltyPolicyLAPABI, ...ErrorsABI],
address: getAddress(contractAddress[chain].RoyaltyPolicyLAP),
});

export const getRoyaltyVaultImplConfig = (chain: SupportedChainIds) => ({
abi: [...IpRoyaltyVaultABI, ...ErrorsABI],
address: getAddress(contractAddress[chain].IpRoyaltyVaultImpl),
});

export const getRoyaltyModuleConfig = (chain: SupportedChainIds) => ({
abi: [...IRoyaltyModuleABI, ...ErrorsABI],
address: getAddress(contractAddress[chain].RoyaltyModule),
});
2 changes: 0 additions & 2 deletions packages/core-sdk/src/abi/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
WriteContractReturnType,
Hex,
} from "viem";
import { AbiTypeToPrimitiveType, AbiParameterToPrimitiveType } from "abitype";

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// AccessController
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
30 changes: 30 additions & 0 deletions packages/core-sdk/src/abi/json/IRoyaltyModule.abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default [
{
inputs: [
{
internalType: "address",
name: "receiverIpId",
type: "address",
},
{
internalType: "address",
name: "payerIpId",
type: "address",
},
{
internalType: "address",
name: "token",
type: "address",
},
{
internalType: "uint256",
name: "amount",
type: "uint256",
},
],
name: "payRoyaltyOnBehalf",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
] as const;
69 changes: 69 additions & 0 deletions packages/core-sdk/src/abi/json/IRoyaltyPolicyLAP.abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
export default [
{
inputs: [
{
internalType: "address",
name: "ipId",
type: "address",
},
],
name: "getRoyaltyData",
outputs: [
{
internalType: "bool",
name: "",
type: "bool",
},
{
internalType: "address",
name: "",
type: "address",
},
{
internalType: "uint32",
name: "",
type: "uint32",
},
{
internalType: "address[]",
name: "",
type: "address[]",
},
{
internalType: "uint32[]",
name: "",
type: "uint32[]",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "caller",
type: "address",
},
{
internalType: "address",
name: "ipId",
type: "address",
},
{
internalType: "address",
name: "token",
type: "address",
},
{
internalType: "uint256",
name: "amount",
type: "uint256",
},
],
name: "onRoyaltyPayment",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
] as const;
93 changes: 93 additions & 0 deletions packages/core-sdk/src/abi/json/IpRoyaltyVault.abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
export default [
{
inputs: [
{
internalType: "uint256[]",
name: "snapshotIds",
type: "uint256[]",
},
{
internalType: "address",
name: "token",
type: "address",
},
],
name: "claimRevenueBySnapshotBatch",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "uint256",
name: "snapshotId",
type: "uint256",
},
{
internalType: "address[]",
name: "tokens",
type: "address[]",
},
],
name: "claimRevenueByTokenBatch",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "account",
type: "address",
},
{
internalType: "uint256",
name: "snapshotId",
type: "uint256",
},
{
internalType: "address",
name: "token",
type: "address",
},
],
name: "claimableRevenue",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "ancestorIpId",
type: "address",
},
],
name: "collectRoyaltyTokens",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [],
name: "ipId",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
stateMutability: "view",
type: "function",
},
] as const;
12 changes: 11 additions & 1 deletion packages/core-sdk/src/abi/sdkEntities.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,15 @@
"resolveDispute",
"DisputeCancelled",
"DisputeResolved",
"DisputeRaised"
"DisputeRaised",

"collectRoyaltyTokens",
"claimRevenueBySnapshotBatch",
"claimRevenueByTokenBatch",
"claimableRevenue",

"getRoyaltyData",
"onRoyaltyPayment",
"claimableRevenue",
"payRoyaltyOnBehalf"
]
16 changes: 15 additions & 1 deletion packages/core-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DisputeClient } from "./resources/dispute";
import { IPAccountClient } from "./resources/ipAccount";
import { chainStringToViemChain } from "./utils/utils";
import { StoryAPIClient } from "./clients/storyAPI";
import { RoyaltyClient } from "./resources/royalty";

if (typeof process !== "undefined") {
dotenv.config();
Expand All @@ -28,7 +29,7 @@ export class StoryClient {
private _policy: PolicyClient | null = null;
private _dispute: DisputeClient | null = null;
private _ipAccount: IPAccountClient | null = null;

private _royalty: RoyaltyClient | null = null;
/**
* @param config - the configuration for the SDK client
*/
Expand Down Expand Up @@ -159,4 +160,17 @@ export class StoryClient {

return this._ipAccount;
}
/**
* Getter for the royalty client. The client is lazily created when
* this method is called.
*
* @returns the RoyaltyClient instance
*/
public get royalty(): RoyaltyClient {
if (this._royalty === null) {
this._royalty = new RoyaltyClient(this.rpcClient, this.wallet, this.config.chainId);
}

return this._royalty;
}
}
7 changes: 7 additions & 0 deletions packages/core-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export type {
AddPolicyToIpResponse,
} from "./types/resources/policy";

export type {
CollectRoyaltyTokensRequest,
CollectRoyaltyTokensResponse,
PayRoyaltyOnBehalfRequest,
PayRoyaltyOnBehalfResponse,
} from "./types/resources/royalty";

export type { SetPermissionsRequest, SetPermissionsResponse } from "./types/resources/permission";

export type {
Expand Down
1 change: 0 additions & 1 deletion packages/core-sdk/src/resources/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export class PolicyClient {
account: this.wallet.account,
});
const txHash = await this.wallet.writeContract(call);

if (request.txOptions?.waitForTransaction) {
const targetLogs = await waitTxAndFilterLog(this.rpcClient, txHash, {
...this.licensingModuleConfig,
Expand Down
Loading

0 comments on commit 6497498

Please sign in to comment.