diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index c82fa895..a51944f5 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -18,13 +18,15 @@ on: required: true SEPOLIA_RPC_PROVIDER_URL: required: true + TEST_SEPOLIA_RPC_PROVIDER_URL: + required: true SEPOLIA_WALLET_PRIVATE_KEY: required: true SEPOLIA_TEST_WALLET_ADDRESS: required: true - STORY_TEST_NET_RPC_PROVIDER_URL: + STORY_TEST_NET_RPC_PROVIDER_URL: required: true - STORY_TEST_NET_WALLET_PRIVATE_KEY: + STORY_TEST_NET_WALLET_PRIVATE_KEY: required: true STORY_TEST_NET_TEST_WALLET_ADDRESS: required: true @@ -41,6 +43,7 @@ jobs: WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }} TEST_WALLET_ADDRESS: ${{ secrets.TEST_WALLET_ADDRESS }} SEPOLIA_RPC_PROVIDER_URL: ${{ secrets.SEPOLIA_RPC_PROVIDER_URL }} + TEST_SEPOLIA_RPC_PROVIDER_URL: ${{ secrets.TEST_SEPOLIA_RPC_PROVIDER_URL }} SEPOLIA_WALLET_PRIVATE_KEY: ${{ secrets.SEPOLIA_WALLET_PRIVATE_KEY }} SEPOLIA_TEST_WALLET_ADDRESS: ${{ secrets.SEPOLIA_TEST_WALLET_ADDRESS }} STORY_TEST_NET_RPC_PROVIDER_URL: ${{ secrets.STORY_TEST_NET_RPC_PROVIDER_URL }} @@ -63,13 +66,27 @@ jobs: node-version: 20.0.0 cache: pnpm + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + - name: Install dependencies run: pnpm install - name: Fix run: pnpm fix + - name: Run Anvil + id: run_anvil + run: anvil --fork-url ${SEPOLIA_RPC_PROVIDER_URL} --block-time 1 --silent & + + - name: Check on Run Anvil + if: steps.run_anvil.outcome != 'success' + run: exit 1 + - name: Test + if: steps.run_anvil.outcome == 'success' run: pnpm test - name: Build diff --git a/.github/workflows/external-pr.yaml b/.github/workflows/external-pr.yaml index f01f1e66..d6324623 100644 --- a/.github/workflows/external-pr.yaml +++ b/.github/workflows/external-pr.yaml @@ -22,6 +22,7 @@ jobs: WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }} TEST_WALLET_ADDRESS: ${{ secrets.TEST_WALLET_ADDRESS }} SEPOLIA_RPC_PROVIDER_URL: ${{ secrets.SEPOLIA_RPC_PROVIDER_URL }} + TEST_SEPOLIA_RPC_PROVIDER_URL: ${{ secrets.TEST_SEPOLIA_RPC_PROVIDER_URL }} SEPOLIA_WALLET_PRIVATE_KEY: ${{ secrets.SEPOLIA_WALLET_PRIVATE_KEY }} SEPOLIA_TEST_WALLET_ADDRESS: ${{ secrets.SEPOLIA_TEST_WALLET_ADDRESS }} STORY_TEST_NET_RPC_PROVIDER_URL: ${{ secrets.STORY_TEST_NET_RPC_PROVIDER_URL }} diff --git a/.github/workflows/internal-pr.yaml b/.github/workflows/internal-pr.yaml index 9a949cbc..ea759c24 100644 --- a/.github/workflows/internal-pr.yaml +++ b/.github/workflows/internal-pr.yaml @@ -22,6 +22,7 @@ jobs: WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }} TEST_WALLET_ADDRESS: ${{ secrets.TEST_WALLET_ADDRESS }} SEPOLIA_RPC_PROVIDER_URL: ${{ secrets.SEPOLIA_RPC_PROVIDER_URL }} + TEST_SEPOLIA_RPC_PROVIDER_URL: ${{ secrets.TEST_SEPOLIA_RPC_PROVIDER_URL }} SEPOLIA_WALLET_PRIVATE_KEY: ${{ secrets.SEPOLIA_WALLET_PRIVATE_KEY }} SEPOLIA_TEST_WALLET_ADDRESS: ${{ secrets.SEPOLIA_TEST_WALLET_ADDRESS }} STORY_TEST_NET_RPC_PROVIDER_URL: ${{ secrets.STORY_TEST_NET_RPC_PROVIDER_URL }} diff --git a/.github/workflows/publish-package.yaml b/.github/workflows/publish-package.yaml index a98aabf7..07c8251a 100644 --- a/.github/workflows/publish-package.yaml +++ b/.github/workflows/publish-package.yaml @@ -54,6 +54,7 @@ jobs: WALLET_PRIVATE_KEY: ${{ secrets.WALLET_PRIVATE_KEY }} TEST_WALLET_ADDRESS: ${{ secrets.TEST_WALLET_ADDRESS }} SEPOLIA_RPC_PROVIDER_URL: ${{ secrets.SEPOLIA_RPC_PROVIDER_URL }} + TEST_SEPOLIA_RPC_PROVIDER_URL: ${{ secrets.TEST_SEPOLIA_RPC_PROVIDER_URL }} SEPOLIA_WALLET_PRIVATE_KEY: ${{ secrets.SEPOLIA_WALLET_PRIVATE_KEY }} SEPOLIA_TEST_WALLET_ADDRESS: ${{ secrets.SEPOLIA_TEST_WALLET_ADDRESS }} STORY_TEST_NET_RPC_PROVIDER_URL: ${{ secrets.STORY_TEST_NET_RPC_PROVIDER_URL }} diff --git a/.gitmodules b/.gitmodules index 8412af5a..880305e0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,8 @@ -[submodule "packages/core-sdk/protocol-contracts"] - path = packages/core-sdk/protocol-contracts +[submodule "packages/core-sdk/protocol-periphery-contracts"] + path = packages/core-sdk/protocol-periphery-contracts + url = https://github.com/storyprotocol/protocol-periphery-v1 + branch = release-v1.x.x +[submodule "packages/core-sdk/protocol-core-contracts"] + path = packages/core-sdk/protocol-core-contracts url = https://github.com/storyprotocol/protocol-core-v1 - branch = main + branch = release-v1.x.x diff --git a/Makefile b/Makefile index 69a142d1..1d5a5a85 100644 --- a/Makefile +++ b/Makefile @@ -1,32 +1,31 @@ +.PHONY: compile_contracts + compile_contracts: - git submodule add -b main --force https://github.com/storyprotocol/protocol-core-v1 packages/core-sdk/protocol-contracts + rm -rf packages/core-sdk/src/abi/json/tmp + + git submodule add -b release-v1.x.x --force https://github.com/storyprotocol/protocol-core-v1 packages/core-sdk/protocol-core-contracts + git submodule add -b release-v1.x.x --force https://github.com/storyprotocol/protocol-periphery-v1 packages/core-sdk/protocol-periphery-contracts git submodule update --remote --merge - cd packages/core-sdk/protocol-contracts && yarn install - 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/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/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/registries/IPAssetRegistry.sol -o packages/core-sdk/src/abi/json/tmp/IPAssetRegistry - 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/PILicenseTemplate.sol -o packages/core-sdk/src/abi/json/tmp/PILicenseTemplate - 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 + cd packages/core-sdk/protocol-core-contracts && yarn install + + solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-core-contracts --include-path packages/core-sdk/protocol-core-contracts/node_modules/ --abi packages/core-sdk/protocol-core-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-core-contracts --include-path packages/core-sdk/protocol-core-contracts/node_modules/ --abi packages/core-sdk/protocol-core-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-core-contracts --include-path packages/core-sdk/protocol-core-contracts/node_modules/ --abi packages/core-sdk/protocol-core-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-core-contracts --include-path packages/core-sdk/protocol-core-contracts/node_modules/ --abi packages/core-sdk/protocol-core-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-core-contracts --include-path packages/core-sdk/protocol-core-contracts/node_modules/ --abi packages/core-sdk/protocol-core-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-core-contracts --include-path packages/core-sdk/protocol-core-contracts/node_modules/ --abi packages/core-sdk/protocol-core-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-core-contracts --include-path packages/core-sdk/protocol-core-contracts/node_modules/ --abi packages/core-sdk/protocol-core-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-core-contracts --include-path packages/core-sdk/protocol-core-contracts/node_modules/ --abi packages/core-sdk/protocol-core-contracts/contracts/registries/IPAssetRegistry.sol -o packages/core-sdk/src/abi/json/tmp/IPAssetRegistry + solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-core-contracts --include-path packages/core-sdk/protocol-core-contracts/node_modules/ --abi packages/core-sdk/protocol-core-contracts/contracts/modules/licensing/PILicenseTemplate.sol -o packages/core-sdk/src/abi/json/tmp/PILicenseTemplate + solc @erc6551/=node_modules/erc6551/ --pretty-json --base-path packages/core-sdk/protocol-core-contracts --include-path packages/core-sdk/protocol-core-contracts/node_modules/ --abi packages/core-sdk/protocol-core-contracts/contracts/lib/Errors.sol -o packages/core-sdk/src/abi/json/tmp/Errors cp packages/core-sdk/src/abi/json/tmp/Errors/Errors.abi packages/core-sdk/src/abi/json/Errors.json - echo 'export default '"$$(jq '.' packages/core-sdk/src/abi/json/Errors.json)"' as const;' > packages/core-sdk/src/abi/json/Errors.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/IPAccountImpl/IPAccountImpl.abi)"' as const;' > packages/core-sdk/src/abi/json/IPAccountImpl.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/LicensingModule/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/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 - 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/PILicenseTemplate/IPILicenseTemplate.abi)"' as const;' > packages/core-sdk/src/abi/json/IPILicenseTemplate.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/LicensingModule/ILicenseToken.abi)"' as const;' > packages/core-sdk/src/abi/json/ILicenseToken.abi.ts + cd packages/core-sdk/protocol-periphery-contracts && yarn install + + solc @storyprotocol/core/=node_modules/@story-protocol/protocol-core/contracts/ --pretty-json --base-path packages/core-sdk/protocol-periphery-contracts --include-path packages/core-sdk/protocol-periphery-contracts/node_modules/ --abi packages/core-sdk/protocol-periphery-contracts/contracts/StoryProtocolGateway.sol -o packages/core-sdk/src/abi/json/tmp/StoryProtocolGateway + solc @storyprotocol/core/=node_modules/@story-protocol/protocol-core/contracts/ --pretty-json --base-path packages/core-sdk/protocol-periphery-contracts --include-path packages/core-sdk/protocol-periphery-contracts/node_modules/ --abi packages/core-sdk/protocol-periphery-contracts/contracts/SPGNFT.sol -o packages/core-sdk/src/abi/json/tmp/SPGNFT rm -rf packages/core-sdk/src/abi/json/tmp - rm -rf packages/core-sdk/protocol-contracts + rm -rf packages/core-sdk/protocol-core-contracts + rm -rf packages/core-sdk/protocol-periphery-contracts diff --git a/README.md b/README.md index 2cff776e..9c9103d1 100644 --- a/README.md +++ b/README.md @@ -98,9 +98,9 @@ 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) +## Steps to pull and compile latest Protocol Core & Periphery v1 Smart Contract ABIs (Currently pulls from the protocol-core-v1 and protocol-periphery-v1 `release-v1.x.x` branch) -Must have `solc` installed (https://docs.soliditylang.org/en/v0.8.9/installing-solidity.html) +Must have `solc` installed (https://docs.soliditylang.org/en/v0.8.23/installing-solidity.html) - run `make compile_contracts` diff --git a/packages/core-sdk/package.json b/packages/core-sdk/package.json index 1798238a..537284e8 100644 --- a/packages/core-sdk/package.json +++ b/packages/core-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@story-protocol/core-sdk", - "version": "1.0.0-rc.6", + "version": "1.0.0-rc.9", "description": "Story Protocol Core SDK", "main": "dist/story-protocol-core-sdk.cjs.js", "module": "dist/story-protocol-core-sdk.esm.js", diff --git a/packages/core-sdk/src/abi/generated.ts b/packages/core-sdk/src/abi/generated.ts index a8535d59..1bf0a91c 100644 --- a/packages/core-sdk/src/abi/generated.ts +++ b/packages/core-sdk/src/abi/generated.ts @@ -5939,373 +5939,3498 @@ export const royaltyPolicyLapConfig = { } as const; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// SDK +// SPG ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// COMMON ============================================================= +/** + * [__View Contract on Sepolia Etherscan__](https://sepolia.etherscan.io/address/0x69415CE984A79a3Cfbe3F51024C63b6C107331e3) + */ +export const spgAbi = [ + { + type: "constructor", + inputs: [ + { name: "accessController", internalType: "address", type: "address" }, + { name: "ipAssetRegistry", internalType: "address", type: "address" }, + { name: "licensingModule", internalType: "address", type: "address" }, + { name: "coreMetadataModule", internalType: "address", type: "address" }, + { name: "pilTemplate", internalType: "address", type: "address" }, + { name: "licenseToken", internalType: "address", type: "address" }, + ], + stateMutability: "nonpayable", + }, + { + type: "error", + inputs: [{ name: "authority", internalType: "address", type: "address" }], + name: "AccessManagedInvalidAuthority", + }, + { + type: "error", + inputs: [ + { name: "caller", internalType: "address", type: "address" }, + { name: "delay", internalType: "uint32", type: "uint32" }, + ], + name: "AccessManagedRequiredDelay", + }, + { + type: "error", + inputs: [{ name: "caller", internalType: "address", type: "address" }], + name: "AccessManagedUnauthorized", + }, + { + type: "error", + inputs: [{ name: "target", internalType: "address", type: "address" }], + name: "AddressEmptyCode", + }, + { + type: "error", + inputs: [{ name: "implementation", internalType: "address", type: "address" }], + name: "ERC1967InvalidImplementation", + }, + { type: "error", inputs: [], name: "ERC1967NonPayable" }, + { type: "error", inputs: [], name: "FailedInnerCall" }, + { type: "error", inputs: [], name: "InvalidInitialization" }, + { type: "error", inputs: [], name: "NotInitializing" }, + { type: "error", inputs: [], name: "SPG__CallerNotMinterRole" }, + { type: "error", inputs: [], name: "SPG__EmptyLicenseTokens" }, + { type: "error", inputs: [], name: "SPG__ZeroAddressParam" }, + { type: "error", inputs: [], name: "UUPSUnauthorizedCallContext" }, + { + type: "error", + inputs: [{ name: "slot", internalType: "bytes32", type: "bytes32" }], + name: "UUPSUnsupportedProxiableUUID", + }, + { + type: "event", + anonymous: false, + inputs: [ + { + name: "authority", + internalType: "address", + type: "address", + indexed: false, + }, + ], + name: "AuthorityUpdated", + }, + { + type: "event", + anonymous: false, + inputs: [ + { + name: "nftContract", + internalType: "address", + type: "address", + indexed: true, + }, + ], + name: "CollectionCreated", + }, + { + type: "event", + anonymous: false, + inputs: [ + { + name: "version", + internalType: "uint64", + type: "uint64", + indexed: false, + }, + ], + name: "Initialized", + }, + { + type: "event", + anonymous: false, + inputs: [ + { + name: "implementation", + internalType: "address", + type: "address", + indexed: true, + }, + ], + name: "Upgraded", + }, + { + type: "function", + inputs: [], + name: "ACCESS_CONTROLLER", + outputs: [{ name: "", internalType: "contract IAccessController", type: "address" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "CORE_METADATA_MODULE", + outputs: [ + { + name: "", + internalType: "contract ICoreMetadataModule", + type: "address", + }, + ], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "IP_ASSET_REGISTRY", + outputs: [{ name: "", internalType: "contract IIPAssetRegistry", type: "address" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "LICENSE_TOKEN", + outputs: [{ name: "", internalType: "contract ILicenseToken", type: "address" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "LICENSING_MODULE", + outputs: [{ name: "", internalType: "contract ILicensingModule", type: "address" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "PIL_TEMPLATE", + outputs: [ + { + name: "", + internalType: "contract IPILicenseTemplate", + type: "address", + }, + ], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "UPGRADE_INTERFACE_VERSION", + outputs: [{ name: "", internalType: "string", type: "string" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "authority", + outputs: [{ name: "", internalType: "address", type: "address" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [ + { name: "name", internalType: "string", type: "string" }, + { name: "symbol", internalType: "string", type: "string" }, + { name: "maxSupply", internalType: "uint32", type: "uint32" }, + { name: "mintCost", internalType: "uint256", type: "uint256" }, + { name: "mintToken", internalType: "address", type: "address" }, + { name: "owner", internalType: "address", type: "address" }, + ], + name: "createCollection", + outputs: [{ name: "nftContract", internalType: "address", type: "address" }], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [{ name: "accessManager", internalType: "address", type: "address" }], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [], + name: "isConsumingScheduledOp", + outputs: [{ name: "", internalType: "bytes4", type: "bytes4" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [ + { name: "nftContract", internalType: "address", type: "address" }, + { name: "recipient", internalType: "address", type: "address" }, + { + name: "metadata", + internalType: "struct IStoryProtocolGateway.IPMetadata", + type: "tuple", + components: [ + { name: "metadataURI", internalType: "string", type: "string" }, + { name: "metadataHash", internalType: "bytes32", type: "bytes32" }, + { name: "nftMetadataHash", internalType: "bytes32", type: "bytes32" }, + ], + }, + ], + name: "mintAndRegisterIp", + outputs: [ + { name: "ipId", internalType: "address", type: "address" }, + { name: "tokenId", internalType: "uint256", type: "uint256" }, + ], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "nftContract", internalType: "address", type: "address" }, + { name: "recipient", internalType: "address", type: "address" }, + { + name: "metadata", + internalType: "struct IStoryProtocolGateway.IPMetadata", + type: "tuple", + components: [ + { name: "metadataURI", internalType: "string", type: "string" }, + { name: "metadataHash", internalType: "bytes32", type: "bytes32" }, + { name: "nftMetadataHash", internalType: "bytes32", type: "bytes32" }, + ], + }, + { + name: "terms", + internalType: "struct PILTerms", + type: "tuple", + components: [ + { name: "transferable", internalType: "bool", type: "bool" }, + { name: "royaltyPolicy", internalType: "address", type: "address" }, + { name: "mintingFee", internalType: "uint256", type: "uint256" }, + { name: "expiration", internalType: "uint256", type: "uint256" }, + { name: "commercialUse", internalType: "bool", type: "bool" }, + { name: "commercialAttribution", internalType: "bool", type: "bool" }, + { + name: "commercializerChecker", + internalType: "address", + type: "address", + }, + { + name: "commercializerCheckerData", + internalType: "bytes", + type: "bytes", + }, + { + name: "commercialRevShare", + internalType: "uint32", + type: "uint32", + }, + { + name: "commercialRevCelling", + internalType: "uint256", + type: "uint256", + }, + { name: "derivativesAllowed", internalType: "bool", type: "bool" }, + { + name: "derivativesAttribution", + internalType: "bool", + type: "bool", + }, + { name: "derivativesApproval", internalType: "bool", type: "bool" }, + { name: "derivativesReciprocal", internalType: "bool", type: "bool" }, + { + name: "derivativeRevCelling", + internalType: "uint256", + type: "uint256", + }, + { name: "currency", internalType: "address", type: "address" }, + { name: "uri", internalType: "string", type: "string" }, + ], + }, + ], + name: "mintAndRegisterIpAndAttachPILTerms", + outputs: [ + { name: "ipId", internalType: "address", type: "address" }, + { name: "tokenId", internalType: "uint256", type: "uint256" }, + { name: "licenseTermsId", internalType: "uint256", type: "uint256" }, + ], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "nftContract", internalType: "address", type: "address" }, + { + name: "derivData", + internalType: "struct IStoryProtocolGateway.MakeDerivative", + type: "tuple", + components: [ + { name: "parentIpIds", internalType: "address[]", type: "address[]" }, + { name: "licenseTemplate", internalType: "address", type: "address" }, + { + name: "licenseTermsIds", + internalType: "uint256[]", + type: "uint256[]", + }, + { name: "royaltyContext", internalType: "bytes", type: "bytes" }, + ], + }, + { + name: "metadata", + internalType: "struct IStoryProtocolGateway.IPMetadata", + type: "tuple", + components: [ + { name: "metadataURI", internalType: "string", type: "string" }, + { name: "metadataHash", internalType: "bytes32", type: "bytes32" }, + { name: "nftMetadataHash", internalType: "bytes32", type: "bytes32" }, + ], + }, + { name: "recipient", internalType: "address", type: "address" }, + ], + name: "mintAndRegisterIpAndMakeDerivative", + outputs: [ + { name: "ipId", internalType: "address", type: "address" }, + { name: "tokenId", internalType: "uint256", type: "uint256" }, + ], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "nftContract", internalType: "address", type: "address" }, + { name: "licenseTokenIds", internalType: "uint256[]", type: "uint256[]" }, + { name: "royaltyContext", internalType: "bytes", type: "bytes" }, + { + name: "metadata", + internalType: "struct IStoryProtocolGateway.IPMetadata", + type: "tuple", + components: [ + { name: "metadataURI", internalType: "string", type: "string" }, + { name: "metadataHash", internalType: "bytes32", type: "bytes32" }, + { name: "nftMetadataHash", internalType: "bytes32", type: "bytes32" }, + ], + }, + { name: "recipient", internalType: "address", type: "address" }, + ], + name: "mintAndRegisterIpAndMakeDerivativeWithLicenseTokens", + outputs: [ + { name: "ipId", internalType: "address", type: "address" }, + { name: "tokenId", internalType: "uint256", type: "uint256" }, + ], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [], + name: "proxiableUUID", + outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [ + { name: "nftContract", internalType: "address", type: "address" }, + { name: "tokenId", internalType: "uint256", type: "uint256" }, + { + name: "metadata", + internalType: "struct IStoryProtocolGateway.IPMetadata", + type: "tuple", + components: [ + { name: "metadataURI", internalType: "string", type: "string" }, + { name: "metadataHash", internalType: "bytes32", type: "bytes32" }, + { name: "nftMetadataHash", internalType: "bytes32", type: "bytes32" }, + ], + }, + { + name: "terms", + internalType: "struct PILTerms", + type: "tuple", + components: [ + { name: "transferable", internalType: "bool", type: "bool" }, + { name: "royaltyPolicy", internalType: "address", type: "address" }, + { name: "mintingFee", internalType: "uint256", type: "uint256" }, + { name: "expiration", internalType: "uint256", type: "uint256" }, + { name: "commercialUse", internalType: "bool", type: "bool" }, + { name: "commercialAttribution", internalType: "bool", type: "bool" }, + { + name: "commercializerChecker", + internalType: "address", + type: "address", + }, + { + name: "commercializerCheckerData", + internalType: "bytes", + type: "bytes", + }, + { + name: "commercialRevShare", + internalType: "uint32", + type: "uint32", + }, + { + name: "commercialRevCelling", + internalType: "uint256", + type: "uint256", + }, + { name: "derivativesAllowed", internalType: "bool", type: "bool" }, + { + name: "derivativesAttribution", + internalType: "bool", + type: "bool", + }, + { name: "derivativesApproval", internalType: "bool", type: "bool" }, + { name: "derivativesReciprocal", internalType: "bool", type: "bool" }, + { + name: "derivativeRevCelling", + internalType: "uint256", + type: "uint256", + }, + { name: "currency", internalType: "address", type: "address" }, + { name: "uri", internalType: "string", type: "string" }, + ], + }, + { + name: "sigMetadata", + internalType: "struct IStoryProtocolGateway.SignatureData", + type: "tuple", + components: [ + { name: "signer", internalType: "address", type: "address" }, + { name: "deadline", internalType: "uint256", type: "uint256" }, + { name: "signature", internalType: "bytes", type: "bytes" }, + ], + }, + { + name: "sigAttach", + internalType: "struct IStoryProtocolGateway.SignatureData", + type: "tuple", + components: [ + { name: "signer", internalType: "address", type: "address" }, + { name: "deadline", internalType: "uint256", type: "uint256" }, + { name: "signature", internalType: "bytes", type: "bytes" }, + ], + }, + ], + name: "registerIpAndAttachPILTerms", + outputs: [ + { name: "ipId", internalType: "address", type: "address" }, + { name: "licenseTermsId", internalType: "uint256", type: "uint256" }, + ], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "nftContract", internalType: "address", type: "address" }, + { name: "tokenId", internalType: "uint256", type: "uint256" }, + { + name: "derivData", + internalType: "struct IStoryProtocolGateway.MakeDerivative", + type: "tuple", + components: [ + { name: "parentIpIds", internalType: "address[]", type: "address[]" }, + { name: "licenseTemplate", internalType: "address", type: "address" }, + { + name: "licenseTermsIds", + internalType: "uint256[]", + type: "uint256[]", + }, + { name: "royaltyContext", internalType: "bytes", type: "bytes" }, + ], + }, + { + name: "metadata", + internalType: "struct IStoryProtocolGateway.IPMetadata", + type: "tuple", + components: [ + { name: "metadataURI", internalType: "string", type: "string" }, + { name: "metadataHash", internalType: "bytes32", type: "bytes32" }, + { name: "nftMetadataHash", internalType: "bytes32", type: "bytes32" }, + ], + }, + { + name: "sigMetadata", + internalType: "struct IStoryProtocolGateway.SignatureData", + type: "tuple", + components: [ + { name: "signer", internalType: "address", type: "address" }, + { name: "deadline", internalType: "uint256", type: "uint256" }, + { name: "signature", internalType: "bytes", type: "bytes" }, + ], + }, + { + name: "sigRegister", + internalType: "struct IStoryProtocolGateway.SignatureData", + type: "tuple", + components: [ + { name: "signer", internalType: "address", type: "address" }, + { name: "deadline", internalType: "uint256", type: "uint256" }, + { name: "signature", internalType: "bytes", type: "bytes" }, + ], + }, + ], + name: "registerIpAndMakeDerivative", + outputs: [{ name: "ipId", internalType: "address", type: "address" }], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "nftContract", internalType: "address", type: "address" }, + { name: "tokenId", internalType: "uint256", type: "uint256" }, + { name: "licenseTokenIds", internalType: "uint256[]", type: "uint256[]" }, + { name: "royaltyContext", internalType: "bytes", type: "bytes" }, + { + name: "metadata", + internalType: "struct IStoryProtocolGateway.IPMetadata", + type: "tuple", + components: [ + { name: "metadataURI", internalType: "string", type: "string" }, + { name: "metadataHash", internalType: "bytes32", type: "bytes32" }, + { name: "nftMetadataHash", internalType: "bytes32", type: "bytes32" }, + ], + }, + { + name: "sigMetadata", + internalType: "struct IStoryProtocolGateway.SignatureData", + type: "tuple", + components: [ + { name: "signer", internalType: "address", type: "address" }, + { name: "deadline", internalType: "uint256", type: "uint256" }, + { name: "signature", internalType: "bytes", type: "bytes" }, + ], + }, + { + name: "sigRegister", + internalType: "struct IStoryProtocolGateway.SignatureData", + type: "tuple", + components: [ + { name: "signer", internalType: "address", type: "address" }, + { name: "deadline", internalType: "uint256", type: "uint256" }, + { name: "signature", internalType: "bytes", type: "bytes" }, + ], + }, + ], + name: "registerIpAndMakeDerivativeWithLicenseTokens", + outputs: [{ name: "ipId", internalType: "address", type: "address" }], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "ipId", internalType: "address", type: "address" }, + { + name: "terms", + internalType: "struct PILTerms", + type: "tuple", + components: [ + { name: "transferable", internalType: "bool", type: "bool" }, + { name: "royaltyPolicy", internalType: "address", type: "address" }, + { name: "mintingFee", internalType: "uint256", type: "uint256" }, + { name: "expiration", internalType: "uint256", type: "uint256" }, + { name: "commercialUse", internalType: "bool", type: "bool" }, + { name: "commercialAttribution", internalType: "bool", type: "bool" }, + { + name: "commercializerChecker", + internalType: "address", + type: "address", + }, + { + name: "commercializerCheckerData", + internalType: "bytes", + type: "bytes", + }, + { + name: "commercialRevShare", + internalType: "uint32", + type: "uint32", + }, + { + name: "commercialRevCelling", + internalType: "uint256", + type: "uint256", + }, + { name: "derivativesAllowed", internalType: "bool", type: "bool" }, + { + name: "derivativesAttribution", + internalType: "bool", + type: "bool", + }, + { name: "derivativesApproval", internalType: "bool", type: "bool" }, + { name: "derivativesReciprocal", internalType: "bool", type: "bool" }, + { + name: "derivativeRevCelling", + internalType: "uint256", + type: "uint256", + }, + { name: "currency", internalType: "address", type: "address" }, + { name: "uri", internalType: "string", type: "string" }, + ], + }, + ], + name: "registerPILTermsAndAttach", + outputs: [{ name: "licenseTermsId", internalType: "uint256", type: "uint256" }], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [{ name: "newAuthority", internalType: "address", type: "address" }], + name: "setAuthority", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { + name: "newNftContractBeacon", + internalType: "address", + type: "address", + }, + ], + name: "setNftContractBeacon", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [{ name: "newNftContract", internalType: "address", type: "address" }], + name: "upgradeCollections", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "newImplementation", internalType: "address", type: "address" }, + { name: "data", internalType: "bytes", type: "bytes" }, + ], + name: "upgradeToAndCall", + outputs: [], + stateMutability: "payable", + }, +] as const; + +/** + * [__View Contract on Sepolia Etherscan__](https://sepolia.etherscan.io/address/0x69415CE984A79a3Cfbe3F51024C63b6C107331e3) + */ +export const spgAddress = { + 11155111: "0x69415CE984A79a3Cfbe3F51024C63b6C107331e3", +} as const; + +/** + * [__View Contract on Sepolia Etherscan__](https://sepolia.etherscan.io/address/0x69415CE984A79a3Cfbe3F51024C63b6C107331e3) + */ +export const spgConfig = { address: spgAddress, abi: spgAbi } as const; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// SPGNFTBeacon +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** + * [__View Contract on Sepolia Etherscan__](https://sepolia.etherscan.io/address/0x027D258659FBdda9033f9c008AF166239EBa67c1) + */ +export const spgnftBeaconAbi = [ + { + type: "constructor", + inputs: [ + { name: "implementation_", internalType: "address", type: "address" }, + { name: "initialOwner", internalType: "address", type: "address" }, + ], + stateMutability: "nonpayable", + }, + { + type: "error", + inputs: [{ name: "implementation", internalType: "address", type: "address" }], + name: "BeaconInvalidImplementation", + }, + { + type: "error", + inputs: [{ name: "owner", internalType: "address", type: "address" }], + name: "OwnableInvalidOwner", + }, + { + type: "error", + inputs: [{ name: "account", internalType: "address", type: "address" }], + name: "OwnableUnauthorizedAccount", + }, + { + type: "event", + anonymous: false, + inputs: [ + { + name: "previousOwner", + internalType: "address", + type: "address", + indexed: true, + }, + { + name: "newOwner", + internalType: "address", + type: "address", + indexed: true, + }, + ], + name: "OwnershipTransferred", + }, + { + type: "event", + anonymous: false, + inputs: [ + { + name: "implementation", + internalType: "address", + type: "address", + indexed: true, + }, + ], + name: "Upgraded", + }, + { + type: "function", + inputs: [], + name: "implementation", + outputs: [{ name: "", internalType: "address", type: "address" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "owner", + outputs: [{ name: "", internalType: "address", type: "address" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "renounceOwnership", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [{ name: "newOwner", internalType: "address", type: "address" }], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [{ name: "newImplementation", internalType: "address", type: "address" }], + name: "upgradeTo", + outputs: [], + stateMutability: "nonpayable", + }, +] as const; + +/** + * [__View Contract on Sepolia Etherscan__](https://sepolia.etherscan.io/address/0x027D258659FBdda9033f9c008AF166239EBa67c1) + */ +export const spgnftBeaconAddress = { + 11155111: "0x027D258659FBdda9033f9c008AF166239EBa67c1", +} as const; + +/** + * [__View Contract on Sepolia Etherscan__](https://sepolia.etherscan.io/address/0x027D258659FBdda9033f9c008AF166239EBa67c1) + */ +export const spgnftBeaconConfig = { + address: spgnftBeaconAddress, + abi: spgnftBeaconAbi, +} as const; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// SPGNFTImpl +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/** + * [__View Contract on Sepolia Etherscan__](https://sepolia.etherscan.io/address/0xDb6480C00B570324A122A6B35F9CAC0F87BDb3e6) + */ +export const spgnftImplAbi = [ + { + type: "constructor", + inputs: [{ name: "spg", internalType: "address", type: "address" }], + stateMutability: "nonpayable", + }, + { type: "error", inputs: [], name: "AccessControlBadConfirmation" }, + { + type: "error", + inputs: [ + { name: "account", internalType: "address", type: "address" }, + { name: "neededRole", internalType: "bytes32", type: "bytes32" }, + ], + name: "AccessControlUnauthorizedAccount", + }, + { + type: "error", + inputs: [ + { name: "sender", internalType: "address", type: "address" }, + { name: "tokenId", internalType: "uint256", type: "uint256" }, + { name: "owner", internalType: "address", type: "address" }, + ], + name: "ERC721IncorrectOwner", + }, + { + type: "error", + inputs: [ + { name: "operator", internalType: "address", type: "address" }, + { name: "tokenId", internalType: "uint256", type: "uint256" }, + ], + name: "ERC721InsufficientApproval", + }, + { + type: "error", + inputs: [{ name: "approver", internalType: "address", type: "address" }], + name: "ERC721InvalidApprover", + }, + { + type: "error", + inputs: [{ name: "operator", internalType: "address", type: "address" }], + name: "ERC721InvalidOperator", + }, + { + type: "error", + inputs: [{ name: "owner", internalType: "address", type: "address" }], + name: "ERC721InvalidOwner", + }, + { + type: "error", + inputs: [{ name: "receiver", internalType: "address", type: "address" }], + name: "ERC721InvalidReceiver", + }, + { + type: "error", + inputs: [{ name: "sender", internalType: "address", type: "address" }], + name: "ERC721InvalidSender", + }, + { + type: "error", + inputs: [{ name: "tokenId", internalType: "uint256", type: "uint256" }], + name: "ERC721NonexistentToken", + }, + { type: "error", inputs: [], name: "InvalidInitialization" }, + { type: "error", inputs: [], name: "NotInitializing" }, + { type: "error", inputs: [], name: "SPGNFT_ZeroMaxSupply" }, + { type: "error", inputs: [], name: "SPGNFT__CallerNotSPG" }, + { type: "error", inputs: [], name: "SPGNFT__MaxSupplyReached" }, + { type: "error", inputs: [], name: "SPGNFT__ZeroAddressParam" }, + { + type: "event", + anonymous: false, + inputs: [ + { + name: "owner", + internalType: "address", + type: "address", + indexed: true, + }, + { + name: "approved", + internalType: "address", + type: "address", + indexed: true, + }, + { + name: "tokenId", + internalType: "uint256", + type: "uint256", + indexed: true, + }, + ], + name: "Approval", + }, + { + type: "event", + anonymous: false, + inputs: [ + { + name: "owner", + internalType: "address", + type: "address", + indexed: true, + }, + { + name: "operator", + internalType: "address", + type: "address", + indexed: true, + }, + { name: "approved", internalType: "bool", type: "bool", indexed: false }, + ], + name: "ApprovalForAll", + }, + { + type: "event", + anonymous: false, + inputs: [ + { + name: "version", + internalType: "uint64", + type: "uint64", + indexed: false, + }, + ], + name: "Initialized", + }, + { + type: "event", + anonymous: false, + inputs: [ + { name: "role", internalType: "bytes32", type: "bytes32", indexed: true }, + { + name: "previousAdminRole", + internalType: "bytes32", + type: "bytes32", + indexed: true, + }, + { + name: "newAdminRole", + internalType: "bytes32", + type: "bytes32", + indexed: true, + }, + ], + name: "RoleAdminChanged", + }, + { + type: "event", + anonymous: false, + inputs: [ + { name: "role", internalType: "bytes32", type: "bytes32", indexed: true }, + { + name: "account", + internalType: "address", + type: "address", + indexed: true, + }, + { + name: "sender", + internalType: "address", + type: "address", + indexed: true, + }, + ], + name: "RoleGranted", + }, + { + type: "event", + anonymous: false, + inputs: [ + { name: "role", internalType: "bytes32", type: "bytes32", indexed: true }, + { + name: "account", + internalType: "address", + type: "address", + indexed: true, + }, + { + name: "sender", + internalType: "address", + type: "address", + indexed: true, + }, + ], + name: "RoleRevoked", + }, + { + type: "event", + anonymous: false, + inputs: [ + { name: "from", internalType: "address", type: "address", indexed: true }, + { name: "to", internalType: "address", type: "address", indexed: true }, + { + name: "tokenId", + internalType: "uint256", + type: "uint256", + indexed: true, + }, + ], + name: "Transfer", + }, + { + type: "function", + inputs: [], + name: "DEFAULT_ADMIN_ROLE", + outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "SPG_ADDRESS", + outputs: [{ name: "", internalType: "address", type: "address" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [ + { name: "to", internalType: "address", type: "address" }, + { name: "tokenId", internalType: "uint256", type: "uint256" }, + ], + name: "approve", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [{ name: "owner", internalType: "address", type: "address" }], + name: "balanceOf", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [{ name: "tokenId", internalType: "uint256", type: "uint256" }], + name: "getApproved", + outputs: [{ name: "", internalType: "address", type: "address" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [{ name: "role", internalType: "bytes32", type: "bytes32" }], + name: "getRoleAdmin", + outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [ + { name: "role", internalType: "bytes32", type: "bytes32" }, + { name: "account", internalType: "address", type: "address" }, + ], + name: "grantRole", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "role", internalType: "bytes32", type: "bytes32" }, + { name: "account", internalType: "address", type: "address" }, + ], + name: "hasRole", + outputs: [{ name: "", internalType: "bool", type: "bool" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [ + { name: "name", internalType: "string", type: "string" }, + { name: "symbol", internalType: "string", type: "string" }, + { name: "maxSupply", internalType: "uint32", type: "uint32" }, + { name: "mintCost", internalType: "uint256", type: "uint256" }, + { name: "mintToken", internalType: "address", type: "address" }, + { name: "owner", internalType: "address", type: "address" }, + ], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "owner", internalType: "address", type: "address" }, + { name: "operator", internalType: "address", type: "address" }, + ], + name: "isApprovedForAll", + outputs: [{ name: "", internalType: "bool", type: "bool" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [{ name: "to", internalType: "address", type: "address" }], + name: "mint", + outputs: [{ name: "tokenId", internalType: "uint256", type: "uint256" }], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "to", internalType: "address", type: "address" }, + { name: "payer", internalType: "address", type: "address" }, + ], + name: "mintBySPG", + outputs: [{ name: "tokenId", internalType: "uint256", type: "uint256" }], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [], + name: "mintCost", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "mintToken", + outputs: [{ name: "", internalType: "address", type: "address" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "name", + outputs: [{ name: "", internalType: "string", type: "string" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [{ name: "tokenId", internalType: "uint256", type: "uint256" }], + name: "ownerOf", + outputs: [{ name: "", internalType: "address", type: "address" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [ + { name: "role", internalType: "bytes32", type: "bytes32" }, + { name: "callerConfirmation", internalType: "address", type: "address" }, + ], + name: "renounceRole", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "role", internalType: "bytes32", type: "bytes32" }, + { name: "account", internalType: "address", type: "address" }, + ], + name: "revokeRole", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "from", internalType: "address", type: "address" }, + { name: "to", internalType: "address", type: "address" }, + { name: "tokenId", internalType: "uint256", type: "uint256" }, + ], + name: "safeTransferFrom", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "from", internalType: "address", type: "address" }, + { name: "to", internalType: "address", type: "address" }, + { name: "tokenId", internalType: "uint256", type: "uint256" }, + { name: "data", internalType: "bytes", type: "bytes" }, + ], + name: "safeTransferFrom", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "operator", internalType: "address", type: "address" }, + { name: "approved", internalType: "bool", type: "bool" }, + ], + name: "setApprovalForAll", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [{ name: "cost", internalType: "uint256", type: "uint256" }], + name: "setMintCost", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [{ name: "token", internalType: "address", type: "address" }], + name: "setMintToken", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [{ name: "interfaceId", internalType: "bytes4", type: "bytes4" }], + name: "supportsInterface", + outputs: [{ name: "", internalType: "bool", type: "bool" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "symbol", + outputs: [{ name: "", internalType: "string", type: "string" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [{ name: "tokenId", internalType: "uint256", type: "uint256" }], + name: "tokenURI", + outputs: [{ name: "", internalType: "string", type: "string" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [], + name: "totalSupply", + outputs: [{ name: "", internalType: "uint256", type: "uint256" }], + stateMutability: "view", + }, + { + type: "function", + inputs: [ + { name: "from", internalType: "address", type: "address" }, + { name: "to", internalType: "address", type: "address" }, + { name: "tokenId", internalType: "uint256", type: "uint256" }, + ], + name: "transferFrom", + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + inputs: [ + { name: "token", internalType: "address", type: "address" }, + { name: "recipient", internalType: "address", type: "address" }, + ], + name: "withdrawToken", + outputs: [], + stateMutability: "nonpayable", + }, +] as const; + +/** + * [__View Contract on Sepolia Etherscan__](https://sepolia.etherscan.io/address/0xDb6480C00B570324A122A6B35F9CAC0F87BDb3e6) + */ +export const spgnftImplAddress = { + 11155111: "0xDb6480C00B570324A122A6B35F9CAC0F87BDb3e6", +} as const; + +/** + * [__View Contract on Sepolia Etherscan__](https://sepolia.etherscan.io/address/0xDb6480C00B570324A122A6B35F9CAC0F87BDb3e6) + */ +export const spgnftImplConfig = { + address: spgnftImplAddress, + abi: spgnftImplAbi, +} as const; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// SDK +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +// COMMON ============================================================= + +function getAddress(address: Record, chainId?: number): Address { + return address[chainId || 0] || "0x"; +} + +export type SimpleWalletClient< + TChain extends Chain | undefined = Chain | undefined, + TAccount extends Account | undefined = Account | undefined, +> = { + account?: TAccount; + writeContract: < + const abi extends Abi | readonly unknown[], + functionName extends ContractFunctionName, + args extends ContractFunctionArgs, + TChainOverride extends Chain | undefined = undefined, + >( + args: WriteContractParameters, + ) => Promise; +}; + +// Contract AccessController ============================================================= + +/** + * AccessControllerPermissionSetEvent + * + * @param ipAccountOwner address + * @param ipAccount address + * @param signer address + * @param to address + * @param func bytes4 + * @param permission uint8 + */ +export type AccessControllerPermissionSetEvent = { + ipAccountOwner: Address; + ipAccount: Address; + signer: Address; + to: Address; + func: Hex; + permission: number; +}; + +/** + * AccessControllerSetPermissionRequest + * + * @param ipAccount address + * @param signer address + * @param to address + * @param func bytes4 + * @param permission uint8 + */ +export type AccessControllerSetPermissionRequest = { + ipAccount: Address; + signer: Address; + to: Address; + func: Hex; + permission: number; +}; + +/** + * contract AccessController event + */ +export class AccessControllerEventClient { + protected readonly rpcClient: PublicClient; + public readonly address: Address; + + constructor(rpcClient: PublicClient, address?: Address) { + this.address = address || getAddress(accessControllerAddress, rpcClient.chain?.id); + this.rpcClient = rpcClient; + } + + /** + * event PermissionSet for contract AccessController + */ + public watchPermissionSetEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: accessControllerAbi, + address: this.address, + eventName: "PermissionSet", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event PermissionSet for contract AccessController + */ + public parseTxPermissionSetEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: accessControllerAbi, + eventName: "PermissionSet", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "PermissionSet") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } +} + +/** + * contract AccessController write method + */ +export class AccessControllerClient extends AccessControllerEventClient { + protected readonly wallet: SimpleWalletClient; + + constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { + super(rpcClient, address); + this.wallet = wallet; + } + + /** + * method setPermission for contract AccessController + * + * @param request AccessControllerSetPermissionRequest + * @return Promise + */ + public async setPermission( + request: AccessControllerSetPermissionRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: accessControllerAbi, + address: this.address, + functionName: "setPermission", + account: this.wallet.account, + args: [request.ipAccount, request.signer, request.to, request.func, request.permission], + }); + return await this.wallet.writeContract(call as WriteContractParameters); + } +} + +// Contract DisputeModule ============================================================= + +/** + * DisputeModuleDisputeCancelledEvent + * + * @param disputeId uint256 + * @param data bytes + */ +export type DisputeModuleDisputeCancelledEvent = { + disputeId: bigint; + data: Hex; +}; + +/** + * DisputeModuleDisputeRaisedEvent + * + * @param disputeId uint256 + * @param targetIpId address + * @param disputeInitiator address + * @param arbitrationPolicy address + * @param linkToDisputeEvidence bytes32 + * @param targetTag bytes32 + * @param data bytes + */ +export type DisputeModuleDisputeRaisedEvent = { + disputeId: bigint; + targetIpId: Address; + disputeInitiator: Address; + arbitrationPolicy: Address; + linkToDisputeEvidence: Hex; + targetTag: Hex; + data: Hex; +}; + +/** + * DisputeModuleDisputeResolvedEvent + * + * @param disputeId uint256 + */ +export type DisputeModuleDisputeResolvedEvent = { + disputeId: bigint; +}; + +/** + * DisputeModuleCancelDisputeRequest + * + * @param disputeId uint256 + * @param data bytes + */ +export type DisputeModuleCancelDisputeRequest = { + disputeId: bigint; + data: Hex; +}; + +/** + * DisputeModuleRaiseDisputeRequest + * + * @param targetIpId address + * @param linkToDisputeEvidence string + * @param targetTag bytes32 + * @param data bytes + */ +export type DisputeModuleRaiseDisputeRequest = { + targetIpId: Address; + linkToDisputeEvidence: string; + targetTag: Hex; + data: Hex; +}; + +/** + * DisputeModuleResolveDisputeRequest + * + * @param disputeId uint256 + * @param data bytes + */ +export type DisputeModuleResolveDisputeRequest = { + disputeId: bigint; + data: Hex; +}; + +/** + * contract DisputeModule event + */ +export class DisputeModuleEventClient { + protected readonly rpcClient: PublicClient; + public readonly address: Address; + + constructor(rpcClient: PublicClient, address?: Address) { + this.address = address || getAddress(disputeModuleAddress, rpcClient.chain?.id); + this.rpcClient = rpcClient; + } + + /** + * event DisputeCancelled for contract DisputeModule + */ + public watchDisputeCancelledEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: disputeModuleAbi, + address: this.address, + eventName: "DisputeCancelled", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event DisputeCancelled for contract DisputeModule + */ + public parseTxDisputeCancelledEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: disputeModuleAbi, + eventName: "DisputeCancelled", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "DisputeCancelled") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } + + /** + * event DisputeRaised for contract DisputeModule + */ + public watchDisputeRaisedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: disputeModuleAbi, + address: this.address, + eventName: "DisputeRaised", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event DisputeRaised for contract DisputeModule + */ + public parseTxDisputeRaisedEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: disputeModuleAbi, + eventName: "DisputeRaised", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "DisputeRaised") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } + + /** + * event DisputeResolved for contract DisputeModule + */ + public watchDisputeResolvedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: disputeModuleAbi, + address: this.address, + eventName: "DisputeResolved", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event DisputeResolved for contract DisputeModule + */ + public parseTxDisputeResolvedEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: disputeModuleAbi, + eventName: "DisputeResolved", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "DisputeResolved") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } +} + +/** + * contract DisputeModule write method + */ +export class DisputeModuleClient extends DisputeModuleEventClient { + protected readonly wallet: SimpleWalletClient; + + constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { + super(rpcClient, address); + this.wallet = wallet; + } + + /** + * method cancelDispute for contract DisputeModule + * + * @param request DisputeModuleCancelDisputeRequest + * @return Promise + */ + public async cancelDispute( + request: DisputeModuleCancelDisputeRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: disputeModuleAbi, + address: this.address, + functionName: "cancelDispute", + account: this.wallet.account, + args: [request.disputeId, request.data], + }); + return await this.wallet.writeContract(call as WriteContractParameters); + } + + /** + * method raiseDispute for contract DisputeModule + * + * @param request DisputeModuleRaiseDisputeRequest + * @return Promise + */ + public async raiseDispute( + request: DisputeModuleRaiseDisputeRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: disputeModuleAbi, + address: this.address, + functionName: "raiseDispute", + account: this.wallet.account, + args: [request.targetIpId, request.linkToDisputeEvidence, request.targetTag, request.data], + }); + return await this.wallet.writeContract(call as WriteContractParameters); + } + + /** + * method resolveDispute for contract DisputeModule + * + * @param request DisputeModuleResolveDisputeRequest + * @return Promise + */ + public async resolveDispute( + request: DisputeModuleResolveDisputeRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: disputeModuleAbi, + address: this.address, + functionName: "resolveDispute", + account: this.wallet.account, + args: [request.disputeId, request.data], + }); + return await this.wallet.writeContract(call as WriteContractParameters); + } +} + +// Contract IPAccountImpl ============================================================= + +/** + * IpAccountImplExecuteRequest + * + * @param to address + * @param value uint256 + * @param data bytes + */ +export type IpAccountImplExecuteRequest = { + to: Address; + value: bigint; + data: Hex; +}; + +/** + * IpAccountImplExecuteWithSigRequest + * + * @param to address + * @param value uint256 + * @param data bytes + * @param signer address + * @param deadline uint256 + * @param signature bytes + */ +export type IpAccountImplExecuteWithSigRequest = { + to: Address; + value: bigint; + data: Hex; + signer: Address; + deadline: bigint; + signature: Hex; +}; + +/** + * contract IPAccountImpl write method + */ +export class IpAccountImplClient { + protected readonly wallet: SimpleWalletClient; + protected readonly rpcClient: PublicClient; + public readonly address: Address; + + constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { + this.address = address || getAddress(ipAccountImplAddress, rpcClient.chain?.id); + this.rpcClient = rpcClient; + this.wallet = wallet; + } + + /** + * method execute for contract IPAccountImpl + * + * @param request IpAccountImplExecuteRequest + * @return Promise + */ + public async execute(request: IpAccountImplExecuteRequest): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: ipAccountImplAbi, + address: this.address, + functionName: "execute", + account: this.wallet.account, + args: [request.to, request.value, request.data], + }); + return await this.wallet.writeContract(call as WriteContractParameters); + } + + /** + * method executeWithSig for contract IPAccountImpl + * + * @param request IpAccountImplExecuteWithSigRequest + * @return Promise + */ + public async executeWithSig( + request: IpAccountImplExecuteWithSigRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: ipAccountImplAbi, + address: this.address, + functionName: "executeWithSig", + account: this.wallet.account, + args: [ + request.to, + request.value, + request.data, + request.signer, + request.deadline, + request.signature, + ], + }); + return await this.wallet.writeContract(call as WriteContractParameters); + } +} + +// Contract IPAssetRegistry ============================================================= + +/** + * IpAssetRegistryIpRegisteredEvent + * + * @param ipId address + * @param chainId uint256 + * @param tokenContract address + * @param tokenId uint256 + * @param name string + * @param uri string + * @param registrationDate uint256 + */ +export type IpAssetRegistryIpRegisteredEvent = { + ipId: Address; + chainId: bigint; + tokenContract: Address; + tokenId: bigint; + name: string; + uri: string; + registrationDate: bigint; +}; + +/** + * IpAssetRegistryIpIdRequest + * + * @param chainId uint256 + * @param tokenContract address + * @param tokenId uint256 + */ +export type IpAssetRegistryIpIdRequest = { + chainId: bigint; + tokenContract: Address; + tokenId: bigint; +}; + +export type IpAssetRegistryIpIdResponse = Address; + +/** + * IpAssetRegistryIsRegisteredRequest + * + * @param id address + */ +export type IpAssetRegistryIsRegisteredRequest = { + id: Address; +}; + +export type IpAssetRegistryIsRegisteredResponse = boolean; + +/** + * IpAssetRegistryRegisterRequest + * + * @param chainid uint256 + * @param tokenContract address + * @param tokenId uint256 + */ +export type IpAssetRegistryRegisterRequest = { + chainid: bigint; + tokenContract: Address; + tokenId: bigint; +}; + +/** + * contract IPAssetRegistry event + */ +export class IpAssetRegistryEventClient { + protected readonly rpcClient: PublicClient; + public readonly address: Address; + + constructor(rpcClient: PublicClient, address?: Address) { + this.address = address || getAddress(ipAssetRegistryAddress, rpcClient.chain?.id); + this.rpcClient = rpcClient; + } + + /** + * event IPRegistered for contract IPAssetRegistry + */ + public watchIpRegisteredEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: ipAssetRegistryAbi, + address: this.address, + eventName: "IPRegistered", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event IPRegistered for contract IPAssetRegistry + */ + public parseTxIpRegisteredEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: ipAssetRegistryAbi, + eventName: "IPRegistered", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "IPRegistered") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } +} + +/** + * contract IPAssetRegistry readonly method + */ +export class IpAssetRegistryReadOnlyClient extends IpAssetRegistryEventClient { + constructor(rpcClient: PublicClient, address?: Address) { + super(rpcClient, address); + } + + /** + * method ipId for contract IPAssetRegistry + * + * @param request IpAssetRegistryIpIdRequest + * @return Promise + */ + public async ipId(request: IpAssetRegistryIpIdRequest): Promise { + return await this.rpcClient.readContract({ + abi: ipAssetRegistryAbi, + address: this.address, + functionName: "ipId", + args: [request.chainId, request.tokenContract, request.tokenId], + }); + } + + /** + * method isRegistered for contract IPAssetRegistry + * + * @param request IpAssetRegistryIsRegisteredRequest + * @return Promise + */ + public async isRegistered( + request: IpAssetRegistryIsRegisteredRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: ipAssetRegistryAbi, + address: this.address, + functionName: "isRegistered", + args: [request.id], + }); + } +} + +/** + * contract IPAssetRegistry write method + */ +export class IpAssetRegistryClient extends IpAssetRegistryReadOnlyClient { + protected readonly wallet: SimpleWalletClient; + + constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { + super(rpcClient, address); + this.wallet = wallet; + } + + /** + * method register for contract IPAssetRegistry + * + * @param request IpAssetRegistryRegisterRequest + * @return Promise + */ + public async register(request: IpAssetRegistryRegisterRequest): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: ipAssetRegistryAbi, + address: this.address, + functionName: "register", + account: this.wallet.account, + args: [request.chainid, request.tokenContract, request.tokenId], + }); + return await this.wallet.writeContract(call as WriteContractParameters); + } +} + +// Contract IpRoyaltyVaultImpl ============================================================= + +/** + * IpRoyaltyVaultImplRevenueTokenClaimedEvent + * + * @param claimer address + * @param token address + * @param amount uint256 + */ +export type IpRoyaltyVaultImplRevenueTokenClaimedEvent = { + claimer: Address; + token: Address; + amount: bigint; +}; + +/** + * IpRoyaltyVaultImplRoyaltyTokensCollectedEvent + * + * @param ancestorIpId address + * @param royaltyTokensCollected uint256 + */ +export type IpRoyaltyVaultImplRoyaltyTokensCollectedEvent = { + ancestorIpId: Address; + royaltyTokensCollected: bigint; +}; + +/** + * IpRoyaltyVaultImplSnapshotCompletedEvent + * + * @param snapshotId uint256 + * @param snapshotTimestamp uint256 + * @param unclaimedTokens uint32 + */ +export type IpRoyaltyVaultImplSnapshotCompletedEvent = { + snapshotId: bigint; + snapshotTimestamp: bigint; + unclaimedTokens: number; +}; + +/** + * IpRoyaltyVaultImplClaimableRevenueRequest + * + * @param account address + * @param snapshotId uint256 + * @param token address + */ +export type IpRoyaltyVaultImplClaimableRevenueRequest = { + account: Address; + snapshotId: bigint; + token: Address; +}; + +export type IpRoyaltyVaultImplClaimableRevenueResponse = bigint; + +export type IpRoyaltyVaultImplIpIdResponse = Address; + +/** + * IpRoyaltyVaultImplClaimRevenueBySnapshotBatchRequest + * + * @param snapshotIds uint256[] + * @param token address + */ +export type IpRoyaltyVaultImplClaimRevenueBySnapshotBatchRequest = { + snapshotIds: readonly bigint[]; + token: Address; +}; + +/** + * IpRoyaltyVaultImplClaimRevenueByTokenBatchRequest + * + * @param snapshotId uint256 + * @param tokenList address[] + */ +export type IpRoyaltyVaultImplClaimRevenueByTokenBatchRequest = { + snapshotId: bigint; + tokenList: readonly Address[]; +}; + +/** + * IpRoyaltyVaultImplCollectRoyaltyTokensRequest + * + * @param ancestorIpId address + */ +export type IpRoyaltyVaultImplCollectRoyaltyTokensRequest = { + ancestorIpId: Address; +}; + +/** + * contract IpRoyaltyVaultImpl event + */ +export class IpRoyaltyVaultImplEventClient { + protected readonly rpcClient: PublicClient; + public readonly address: Address; + + constructor(rpcClient: PublicClient, address?: Address) { + this.address = address || getAddress(ipRoyaltyVaultImplAddress, rpcClient.chain?.id); + this.rpcClient = rpcClient; + } + + /** + * event RevenueTokenClaimed for contract IpRoyaltyVaultImpl + */ + public watchRevenueTokenClaimedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: ipRoyaltyVaultImplAbi, + address: this.address, + eventName: "RevenueTokenClaimed", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event RevenueTokenClaimed for contract IpRoyaltyVaultImpl + */ + public parseTxRevenueTokenClaimedEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: ipRoyaltyVaultImplAbi, + eventName: "RevenueTokenClaimed", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "RevenueTokenClaimed") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } + + /** + * event RoyaltyTokensCollected for contract IpRoyaltyVaultImpl + */ + public watchRoyaltyTokensCollectedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: ipRoyaltyVaultImplAbi, + address: this.address, + eventName: "RoyaltyTokensCollected", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event RoyaltyTokensCollected for contract IpRoyaltyVaultImpl + */ + public parseTxRoyaltyTokensCollectedEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: ipRoyaltyVaultImplAbi, + eventName: "RoyaltyTokensCollected", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "RoyaltyTokensCollected") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } + + /** + * event SnapshotCompleted for contract IpRoyaltyVaultImpl + */ + public watchSnapshotCompletedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: ipRoyaltyVaultImplAbi, + address: this.address, + eventName: "SnapshotCompleted", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event SnapshotCompleted for contract IpRoyaltyVaultImpl + */ + public parseTxSnapshotCompletedEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: ipRoyaltyVaultImplAbi, + eventName: "SnapshotCompleted", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "SnapshotCompleted") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } +} + +/** + * contract IpRoyaltyVaultImpl readonly method + */ +export class IpRoyaltyVaultImplReadOnlyClient extends IpRoyaltyVaultImplEventClient { + constructor(rpcClient: PublicClient, address?: Address) { + super(rpcClient, address); + } + + /** + * method claimableRevenue for contract IpRoyaltyVaultImpl + * + * @param request IpRoyaltyVaultImplClaimableRevenueRequest + * @return Promise + */ + public async claimableRevenue( + request: IpRoyaltyVaultImplClaimableRevenueRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: ipRoyaltyVaultImplAbi, + address: this.address, + functionName: "claimableRevenue", + args: [request.account, request.snapshotId, request.token], + }); + } + + /** + * method ipId for contract IpRoyaltyVaultImpl + * + * @param request IpRoyaltyVaultImplIpIdRequest + * @return Promise + */ + public async ipId(): Promise { + return await this.rpcClient.readContract({ + abi: ipRoyaltyVaultImplAbi, + address: this.address, + functionName: "ipId", + }); + } +} + +/** + * contract IpRoyaltyVaultImpl write method + */ +export class IpRoyaltyVaultImplClient extends IpRoyaltyVaultImplReadOnlyClient { + protected readonly wallet: SimpleWalletClient; + + constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { + super(rpcClient, address); + this.wallet = wallet; + } + + /** + * method claimRevenueBySnapshotBatch for contract IpRoyaltyVaultImpl + * + * @param request IpRoyaltyVaultImplClaimRevenueBySnapshotBatchRequest + * @return Promise + */ + public async claimRevenueBySnapshotBatch( + request: IpRoyaltyVaultImplClaimRevenueBySnapshotBatchRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: ipRoyaltyVaultImplAbi, + address: this.address, + functionName: "claimRevenueBySnapshotBatch", + account: this.wallet.account, + args: [request.snapshotIds, request.token], + }); + return await this.wallet.writeContract(call as WriteContractParameters); + } + + /** + * method claimRevenueByTokenBatch for contract IpRoyaltyVaultImpl + * + * @param request IpRoyaltyVaultImplClaimRevenueByTokenBatchRequest + * @return Promise + */ + public async claimRevenueByTokenBatch( + request: IpRoyaltyVaultImplClaimRevenueByTokenBatchRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: ipRoyaltyVaultImplAbi, + address: this.address, + functionName: "claimRevenueByTokenBatch", + account: this.wallet.account, + args: [request.snapshotId, request.tokenList], + }); + return await this.wallet.writeContract(call as WriteContractParameters); + } + + /** + * method collectRoyaltyTokens for contract IpRoyaltyVaultImpl + * + * @param request IpRoyaltyVaultImplCollectRoyaltyTokensRequest + * @return Promise + */ + public async collectRoyaltyTokens( + request: IpRoyaltyVaultImplCollectRoyaltyTokensRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: ipRoyaltyVaultImplAbi, + address: this.address, + functionName: "collectRoyaltyTokens", + account: this.wallet.account, + args: [request.ancestorIpId], + }); + return await this.wallet.writeContract(call as WriteContractParameters); + } + + /** + * method snapshot for contract IpRoyaltyVaultImpl + * + * @param request IpRoyaltyVaultImplSnapshotRequest + * @return Promise + */ + public async snapshot(): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: ipRoyaltyVaultImplAbi, + address: this.address, + functionName: "snapshot", + account: this.wallet.account, + }); + return await this.wallet.writeContract(call as WriteContractParameters); + } +} + +// Contract LicenseRegistry ============================================================= + +/** + * LicenseRegistryAuthorityUpdatedEvent + * + * @param authority address + */ +export type LicenseRegistryAuthorityUpdatedEvent = { + authority: Address; +}; + +/** + * LicenseRegistryExpirationTimeSetEvent + * + * @param ipId address + * @param expireTime uint256 + */ +export type LicenseRegistryExpirationTimeSetEvent = { + ipId: Address; + expireTime: bigint; +}; + +/** + * LicenseRegistryInitializedEvent + * + * @param version uint64 + */ +export type LicenseRegistryInitializedEvent = { + version: bigint; +}; + +/** + * LicenseRegistryLicenseTemplateRegisteredEvent + * + * @param licenseTemplate address + */ +export type LicenseRegistryLicenseTemplateRegisteredEvent = { + licenseTemplate: Address; +}; + +/** + * LicenseRegistryLicensingConfigSetForIpEvent + * + * @param ipId address + * @param licensingConfig tuple + */ +export type LicenseRegistryLicensingConfigSetForIpEvent = { + ipId: Address; + licensingConfig: { + isSet: boolean; + mintingFee: bigint; + licensingHook: Address; + hookData: Hex; + }; +}; + +/** + * LicenseRegistryLicensingConfigSetForLicenseEvent + * + * @param ipId address + * @param licenseTemplate address + * @param licenseTermsId uint256 + */ +export type LicenseRegistryLicensingConfigSetForLicenseEvent = { + ipId: Address; + licenseTemplate: Address; + licenseTermsId: bigint; +}; + +/** + * LicenseRegistryUpgradedEvent + * + * @param implementation address + */ +export type LicenseRegistryUpgradedEvent = { + implementation: Address; +}; + +export type LicenseRegistryDisputeModuleResponse = Address; + +export type LicenseRegistryExpirationTimeResponse = Hex; + +export type LicenseRegistryLicensingModuleResponse = Address; + +export type LicenseRegistryUpgradeInterfaceVersionResponse = string; + +export type LicenseRegistryAuthorityResponse = Address; + +/** + * LicenseRegistryExistsRequest + * + * @param licenseTemplate address + * @param licenseTermsId uint256 + */ +export type LicenseRegistryExistsRequest = { + licenseTemplate: Address; + licenseTermsId: bigint; +}; + +export type LicenseRegistryExistsResponse = boolean; + +/** + * LicenseRegistryGetAttachedLicenseTermsRequest + * + * @param ipId address + * @param index uint256 + */ +export type LicenseRegistryGetAttachedLicenseTermsRequest = { + ipId: Address; + index: bigint; +}; + +/** + * LicenseRegistryGetAttachedLicenseTermsResponse + * + * @param licenseTemplate address + * @param licenseTermsId uint256 + */ +export type LicenseRegistryGetAttachedLicenseTermsResponse = { + licenseTemplate: Address; + licenseTermsId: bigint; +}; + +/** + * LicenseRegistryGetAttachedLicenseTermsCountRequest + * + * @param ipId address + */ +export type LicenseRegistryGetAttachedLicenseTermsCountRequest = { + ipId: Address; +}; + +export type LicenseRegistryGetAttachedLicenseTermsCountResponse = bigint; + +/** + * LicenseRegistryGetDefaultLicenseTermsResponse + * + * @param licenseTemplate address + * @param licenseTermsId uint256 + */ +export type LicenseRegistryGetDefaultLicenseTermsResponse = { + licenseTemplate: Address; + licenseTermsId: bigint; +}; + +/** + * LicenseRegistryGetDerivativeIpRequest + * + * @param parentIpId address + * @param index uint256 + */ +export type LicenseRegistryGetDerivativeIpRequest = { + parentIpId: Address; + index: bigint; +}; + +/** + * LicenseRegistryGetDerivativeIpResponse + * + * @param childIpId address + */ +export type LicenseRegistryGetDerivativeIpResponse = { + childIpId: Address; +}; + +/** + * LicenseRegistryGetDerivativeIpCountRequest + * + * @param parentIpId address + */ +export type LicenseRegistryGetDerivativeIpCountRequest = { + parentIpId: Address; +}; + +export type LicenseRegistryGetDerivativeIpCountResponse = bigint; + +/** + * LicenseRegistryGetExpireTimeRequest + * + * @param ipId address + */ +export type LicenseRegistryGetExpireTimeRequest = { + ipId: Address; +}; + +export type LicenseRegistryGetExpireTimeResponse = bigint; + +/** + * LicenseRegistryGetLicensingConfigRequest + * + * @param ipId address + * @param licenseTemplate address + * @param licenseTermsId uint256 + */ +export type LicenseRegistryGetLicensingConfigRequest = { + ipId: Address; + licenseTemplate: Address; + licenseTermsId: bigint; +}; + +export type LicenseRegistryGetLicensingConfigResponse = { + isSet: boolean; + mintingFee: bigint; + licensingHook: Address; + hookData: Hex; +}; + +/** + * LicenseRegistryGetParentIpRequest + * + * @param childIpId address + * @param index uint256 + */ +export type LicenseRegistryGetParentIpRequest = { + childIpId: Address; + index: bigint; +}; + +/** + * LicenseRegistryGetParentIpResponse + * + * @param parentIpId address + */ +export type LicenseRegistryGetParentIpResponse = { + parentIpId: Address; +}; + +/** + * LicenseRegistryGetParentIpCountRequest + * + * @param childIpId address + */ +export type LicenseRegistryGetParentIpCountRequest = { + childIpId: Address; +}; + +export type LicenseRegistryGetParentIpCountResponse = bigint; + +/** + * LicenseRegistryHasDerivativeIpsRequest + * + * @param parentIpId address + */ +export type LicenseRegistryHasDerivativeIpsRequest = { + parentIpId: Address; +}; + +export type LicenseRegistryHasDerivativeIpsResponse = boolean; + +/** + * LicenseRegistryHasIpAttachedLicenseTermsRequest + * + * @param ipId address + * @param licenseTemplate address + * @param licenseTermsId uint256 + */ +export type LicenseRegistryHasIpAttachedLicenseTermsRequest = { + ipId: Address; + licenseTemplate: Address; + licenseTermsId: bigint; +}; + +export type LicenseRegistryHasIpAttachedLicenseTermsResponse = boolean; + +export type LicenseRegistryIsConsumingScheduledOpResponse = Hex; + +/** + * LicenseRegistryIsDerivativeIpRequest + * + * @param childIpId address + */ +export type LicenseRegistryIsDerivativeIpRequest = { + childIpId: Address; +}; + +export type LicenseRegistryIsDerivativeIpResponse = boolean; + +/** + * LicenseRegistryIsExpiredNowRequest + * + * @param ipId address + */ +export type LicenseRegistryIsExpiredNowRequest = { + ipId: Address; +}; + +export type LicenseRegistryIsExpiredNowResponse = boolean; + +/** + * LicenseRegistryIsParentIpRequest + * + * @param parentIpId address + * @param childIpId address + */ +export type LicenseRegistryIsParentIpRequest = { + parentIpId: Address; + childIpId: Address; +}; + +export type LicenseRegistryIsParentIpResponse = boolean; + +/** + * LicenseRegistryIsRegisteredLicenseTemplateRequest + * + * @param licenseTemplate address + */ +export type LicenseRegistryIsRegisteredLicenseTemplateRequest = { + licenseTemplate: Address; +}; + +export type LicenseRegistryIsRegisteredLicenseTemplateResponse = boolean; + +export type LicenseRegistryProxiableUuidResponse = Hex; + +/** + * LicenseRegistryVerifyMintLicenseTokenRequest + * + * @param licensorIpId address + * @param licenseTemplate address + * @param licenseTermsId uint256 + * @param isMintedByIpOwner bool + */ +export type LicenseRegistryVerifyMintLicenseTokenRequest = { + licensorIpId: Address; + licenseTemplate: Address; + licenseTermsId: bigint; + isMintedByIpOwner: boolean; +}; + +export type LicenseRegistryVerifyMintLicenseTokenResponse = { + isSet: boolean; + mintingFee: bigint; + licensingHook: Address; + hookData: Hex; +}; + +/** + * LicenseRegistryAttachLicenseTermsToIpRequest + * + * @param ipId address + * @param licenseTemplate address + * @param licenseTermsId uint256 + */ +export type LicenseRegistryAttachLicenseTermsToIpRequest = { + ipId: Address; + licenseTemplate: Address; + licenseTermsId: bigint; +}; + +/** + * LicenseRegistryInitializeRequest + * + * @param accessManager address + */ +export type LicenseRegistryInitializeRequest = { + accessManager: Address; +}; + +/** + * LicenseRegistryRegisterDerivativeIpRequest + * + * @param childIpId address + * @param parentIpIds address[] + * @param licenseTemplate address + * @param licenseTermsIds uint256[] + */ +export type LicenseRegistryRegisterDerivativeIpRequest = { + childIpId: Address; + parentIpIds: readonly Address[]; + licenseTemplate: Address; + licenseTermsIds: readonly bigint[]; +}; + +/** + * LicenseRegistryRegisterLicenseTemplateRequest + * + * @param licenseTemplate address + */ +export type LicenseRegistryRegisterLicenseTemplateRequest = { + licenseTemplate: Address; +}; + +/** + * LicenseRegistrySetAuthorityRequest + * + * @param newAuthority address + */ +export type LicenseRegistrySetAuthorityRequest = { + newAuthority: Address; +}; + +/** + * LicenseRegistrySetDefaultLicenseTermsRequest + * + * @param newLicenseTemplate address + * @param newLicenseTermsId uint256 + */ +export type LicenseRegistrySetDefaultLicenseTermsRequest = { + newLicenseTemplate: Address; + newLicenseTermsId: bigint; +}; + +/** + * LicenseRegistrySetExpireTimeRequest + * + * @param ipId address + * @param expireTime uint256 + */ +export type LicenseRegistrySetExpireTimeRequest = { + ipId: Address; + expireTime: bigint; +}; + +/** + * LicenseRegistrySetLicensingConfigForIpRequest + * + * @param ipId address + * @param licensingConfig tuple + */ +export type LicenseRegistrySetLicensingConfigForIpRequest = { + ipId: Address; + licensingConfig: { + isSet: boolean; + mintingFee: bigint; + licensingHook: Address; + hookData: Hex; + }; +}; + +/** + * LicenseRegistrySetLicensingConfigForLicenseRequest + * + * @param ipId address + * @param licenseTemplate address + * @param licenseTermsId uint256 + * @param licensingConfig tuple + */ +export type LicenseRegistrySetLicensingConfigForLicenseRequest = { + ipId: Address; + licenseTemplate: Address; + licenseTermsId: bigint; + licensingConfig: { + isSet: boolean; + mintingFee: bigint; + licensingHook: Address; + hookData: Hex; + }; +}; + +/** + * LicenseRegistryUpgradeToAndCallRequest + * + * @param newImplementation address + * @param data bytes + */ +export type LicenseRegistryUpgradeToAndCallRequest = { + newImplementation: Address; + data: Hex; +}; + +/** + * contract LicenseRegistry event + */ +export class LicenseRegistryEventClient { + protected readonly rpcClient: PublicClient; + public readonly address: Address; + + constructor(rpcClient: PublicClient, address?: Address) { + this.address = address || getAddress(licenseRegistryAddress, rpcClient.chain?.id); + this.rpcClient = rpcClient; + } + + /** + * event AuthorityUpdated for contract LicenseRegistry + */ + public watchAuthorityUpdatedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: licenseRegistryAbi, + address: this.address, + eventName: "AuthorityUpdated", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event AuthorityUpdated for contract LicenseRegistry + */ + public parseTxAuthorityUpdatedEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: licenseRegistryAbi, + eventName: "AuthorityUpdated", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "AuthorityUpdated") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } + + /** + * event ExpirationTimeSet for contract LicenseRegistry + */ + public watchExpirationTimeSetEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: licenseRegistryAbi, + address: this.address, + eventName: "ExpirationTimeSet", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event ExpirationTimeSet for contract LicenseRegistry + */ + public parseTxExpirationTimeSetEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: licenseRegistryAbi, + eventName: "ExpirationTimeSet", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "ExpirationTimeSet") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } + + /** + * event Initialized for contract LicenseRegistry + */ + public watchInitializedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: licenseRegistryAbi, + address: this.address, + eventName: "Initialized", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event Initialized for contract LicenseRegistry + */ + public parseTxInitializedEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: licenseRegistryAbi, + eventName: "Initialized", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "Initialized") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } + + /** + * event LicenseTemplateRegistered for contract LicenseRegistry + */ + public watchLicenseTemplateRegisteredEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: licenseRegistryAbi, + address: this.address, + eventName: "LicenseTemplateRegistered", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event LicenseTemplateRegistered for contract LicenseRegistry + */ + public parseTxLicenseTemplateRegisteredEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: licenseRegistryAbi, + eventName: "LicenseTemplateRegistered", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "LicenseTemplateRegistered") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } + + /** + * event LicensingConfigSetForIP for contract LicenseRegistry + */ + public watchLicensingConfigSetForIpEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: licenseRegistryAbi, + address: this.address, + eventName: "LicensingConfigSetForIP", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event LicensingConfigSetForIP for contract LicenseRegistry + */ + public parseTxLicensingConfigSetForIpEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: licenseRegistryAbi, + eventName: "LicensingConfigSetForIP", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "LicensingConfigSetForIP") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } + + /** + * event LicensingConfigSetForLicense for contract LicenseRegistry + */ + public watchLicensingConfigSetForLicenseEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: licenseRegistryAbi, + address: this.address, + eventName: "LicensingConfigSetForLicense", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event LicensingConfigSetForLicense for contract LicenseRegistry + */ + public parseTxLicensingConfigSetForLicenseEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: licenseRegistryAbi, + eventName: "LicensingConfigSetForLicense", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "LicensingConfigSetForLicense") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } + + /** + * event Upgraded for contract LicenseRegistry + */ + public watchUpgradedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: licenseRegistryAbi, + address: this.address, + eventName: "Upgraded", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event Upgraded for contract LicenseRegistry + */ + public parseTxUpgradedEvent(txReceipt: TransactionReceipt): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: licenseRegistryAbi, + eventName: "Upgraded", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "Upgraded") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } +} + +/** + * contract LicenseRegistry readonly method + */ +export class LicenseRegistryReadOnlyClient extends LicenseRegistryEventClient { + constructor(rpcClient: PublicClient, address?: Address) { + super(rpcClient, address); + } -function getAddress(address: Record, chainId?: number): Address { - return address[chainId || 0] || "0x"; -} + /** + * method DISPUTE_MODULE for contract LicenseRegistry + * + * @param request LicenseRegistryDisputeModuleRequest + * @return Promise + */ + public async disputeModule(): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "DISPUTE_MODULE", + }); + } -export type SimpleWalletClient< - TChain extends Chain | undefined = Chain | undefined, - TAccount extends Account | undefined = Account | undefined, -> = { - account?: TAccount; - writeContract: < - const abi extends Abi | readonly unknown[], - functionName extends ContractFunctionName, - args extends ContractFunctionArgs, - TChainOverride extends Chain | undefined = undefined, - >( - args: WriteContractParameters, - ) => Promise; -}; + /** + * method EXPIRATION_TIME for contract LicenseRegistry + * + * @param request LicenseRegistryExpirationTimeRequest + * @return Promise + */ + public async expirationTime(): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "EXPIRATION_TIME", + }); + } -// Contract AccessController ============================================================= + /** + * method LICENSING_MODULE for contract LicenseRegistry + * + * @param request LicenseRegistryLicensingModuleRequest + * @return Promise + */ + public async licensingModule(): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "LICENSING_MODULE", + }); + } -/** - * AccessControllerPermissionSetEvent - * - * @param ipAccountOwner address - * @param ipAccount address - * @param signer address - * @param to address - * @param func bytes4 - * @param permission uint8 - */ -export type AccessControllerPermissionSetEvent = { - ipAccountOwner: Address; - ipAccount: Address; - signer: Address; - to: Address; - func: Hex; - permission: number; -}; + /** + * method UPGRADE_INTERFACE_VERSION for contract LicenseRegistry + * + * @param request LicenseRegistryUpgradeInterfaceVersionRequest + * @return Promise + */ + public async upgradeInterfaceVersion(): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "UPGRADE_INTERFACE_VERSION", + }); + } -/** - * AccessControllerSetPermissionRequest - * - * @param ipAccount address - * @param signer address - * @param to address - * @param func bytes4 - * @param permission uint8 - */ -export type AccessControllerSetPermissionRequest = { - ipAccount: Address; - signer: Address; - to: Address; - func: Hex; - permission: number; -}; + /** + * method authority for contract LicenseRegistry + * + * @param request LicenseRegistryAuthorityRequest + * @return Promise + */ + public async authority(): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "authority", + }); + } -/** - * contract AccessController event - */ -export class AccessControllerEventClient { - protected readonly rpcClient: PublicClient; - public readonly address: Address; + /** + * method exists for contract LicenseRegistry + * + * @param request LicenseRegistryExistsRequest + * @return Promise + */ + public async exists( + request: LicenseRegistryExistsRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "exists", + args: [request.licenseTemplate, request.licenseTermsId], + }); + } - constructor(rpcClient: PublicClient, address?: Address) { - this.address = address || getAddress(accessControllerAddress, rpcClient.chain?.id); - this.rpcClient = rpcClient; + /** + * method getAttachedLicenseTerms for contract LicenseRegistry + * + * @param request LicenseRegistryGetAttachedLicenseTermsRequest + * @return Promise + */ + public async getAttachedLicenseTerms( + request: LicenseRegistryGetAttachedLicenseTermsRequest, + ): Promise { + const result = await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "getAttachedLicenseTerms", + args: [request.ipId, request.index], + }); + return { + licenseTemplate: result[0], + licenseTermsId: result[1], + }; + } + + /** + * method getAttachedLicenseTermsCount for contract LicenseRegistry + * + * @param request LicenseRegistryGetAttachedLicenseTermsCountRequest + * @return Promise + */ + public async getAttachedLicenseTermsCount( + request: LicenseRegistryGetAttachedLicenseTermsCountRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "getAttachedLicenseTermsCount", + args: [request.ipId], + }); + } + + /** + * method getDefaultLicenseTerms for contract LicenseRegistry + * + * @param request LicenseRegistryGetDefaultLicenseTermsRequest + * @return Promise + */ + public async getDefaultLicenseTerms(): Promise { + const result = await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "getDefaultLicenseTerms", + }); + return { + licenseTemplate: result[0], + licenseTermsId: result[1], + }; + } + + /** + * method getDerivativeIp for contract LicenseRegistry + * + * @param request LicenseRegistryGetDerivativeIpRequest + * @return Promise + */ + public async getDerivativeIp( + request: LicenseRegistryGetDerivativeIpRequest, + ): Promise { + const result = await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "getDerivativeIp", + args: [request.parentIpId, request.index], + }); + return { + childIpId: result, + }; + } + + /** + * method getDerivativeIpCount for contract LicenseRegistry + * + * @param request LicenseRegistryGetDerivativeIpCountRequest + * @return Promise + */ + public async getDerivativeIpCount( + request: LicenseRegistryGetDerivativeIpCountRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "getDerivativeIpCount", + args: [request.parentIpId], + }); } /** - * event PermissionSet for contract AccessController + * method getExpireTime for contract LicenseRegistry + * + * @param request LicenseRegistryGetExpireTimeRequest + * @return Promise */ - public watchPermissionSetEvent( - onLogs: (txHash: Hex, ev: Partial) => void, - ): WatchContractEventReturnType { - return this.rpcClient.watchContractEvent({ - abi: accessControllerAbi, + public async getExpireTime( + request: LicenseRegistryGetExpireTimeRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, address: this.address, - eventName: "PermissionSet", - onLogs: (evs) => { - evs.forEach((it) => onLogs(it.transactionHash, it.args)); - }, + functionName: "getExpireTime", + args: [request.ipId], }); } /** - * parse tx receipt event PermissionSet for contract AccessController + * method getLicensingConfig for contract LicenseRegistry + * + * @param request LicenseRegistryGetLicensingConfigRequest + * @return Promise */ - public parseTxPermissionSetEvent( - txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; - for (const log of txReceipt.logs) { - try { - const event = decodeEventLog({ - abi: accessControllerAbi, - eventName: "PermissionSet", - data: log.data, - topics: log.topics, - }); - if (event.eventName === "PermissionSet") { - targetLogs.push(event.args); - } - } catch (e) { - /* empty */ - } - } - return targetLogs; + public async getLicensingConfig( + request: LicenseRegistryGetLicensingConfigRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "getLicensingConfig", + args: [request.ipId, request.licenseTemplate, request.licenseTermsId], + }); } -} - -/** - * contract AccessController write method - */ -export class AccessControllerClient extends AccessControllerEventClient { - protected readonly wallet: SimpleWalletClient; - constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { - super(rpcClient, address); - this.wallet = wallet; + /** + * method getParentIp for contract LicenseRegistry + * + * @param request LicenseRegistryGetParentIpRequest + * @return Promise + */ + public async getParentIp( + request: LicenseRegistryGetParentIpRequest, + ): Promise { + const result = await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "getParentIp", + args: [request.childIpId, request.index], + }); + return { + parentIpId: result, + }; } /** - * method setPermission for contract AccessController + * method getParentIpCount for contract LicenseRegistry * - * @param request AccessControllerSetPermissionRequest - * @return Promise + * @param request LicenseRegistryGetParentIpCountRequest + * @return Promise */ - public async setPermission( - request: AccessControllerSetPermissionRequest, - ): Promise { - const { request: call } = await this.rpcClient.simulateContract({ - abi: accessControllerAbi, + public async getParentIpCount( + request: LicenseRegistryGetParentIpCountRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, address: this.address, - functionName: "setPermission", - account: this.wallet.account, - args: [request.ipAccount, request.signer, request.to, request.func, request.permission], + functionName: "getParentIpCount", + args: [request.childIpId], }); - return await this.wallet.writeContract(call as WriteContractParameters); } -} - -// Contract DisputeModule ============================================================= - -/** - * DisputeModuleDisputeCancelledEvent - * - * @param disputeId uint256 - * @param data bytes - */ -export type DisputeModuleDisputeCancelledEvent = { - disputeId: bigint; - data: Hex; -}; - -/** - * DisputeModuleDisputeRaisedEvent - * - * @param disputeId uint256 - * @param targetIpId address - * @param disputeInitiator address - * @param arbitrationPolicy address - * @param linkToDisputeEvidence bytes32 - * @param targetTag bytes32 - * @param data bytes - */ -export type DisputeModuleDisputeRaisedEvent = { - disputeId: bigint; - targetIpId: Address; - disputeInitiator: Address; - arbitrationPolicy: Address; - linkToDisputeEvidence: Hex; - targetTag: Hex; - data: Hex; -}; - -/** - * DisputeModuleDisputeResolvedEvent - * - * @param disputeId uint256 - */ -export type DisputeModuleDisputeResolvedEvent = { - disputeId: bigint; -}; - -/** - * DisputeModuleCancelDisputeRequest - * - * @param disputeId uint256 - * @param data bytes - */ -export type DisputeModuleCancelDisputeRequest = { - disputeId: bigint; - data: Hex; -}; - -/** - * DisputeModuleRaiseDisputeRequest - * - * @param targetIpId address - * @param linkToDisputeEvidence string - * @param targetTag bytes32 - * @param data bytes - */ -export type DisputeModuleRaiseDisputeRequest = { - targetIpId: Address; - linkToDisputeEvidence: string; - targetTag: Hex; - data: Hex; -}; -/** - * DisputeModuleResolveDisputeRequest - * - * @param disputeId uint256 - * @param data bytes - */ -export type DisputeModuleResolveDisputeRequest = { - disputeId: bigint; - data: Hex; -}; + /** + * method hasDerivativeIps for contract LicenseRegistry + * + * @param request LicenseRegistryHasDerivativeIpsRequest + * @return Promise + */ + public async hasDerivativeIps( + request: LicenseRegistryHasDerivativeIpsRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "hasDerivativeIps", + args: [request.parentIpId], + }); + } -/** - * contract DisputeModule event - */ -export class DisputeModuleEventClient { - protected readonly rpcClient: PublicClient; - public readonly address: Address; + /** + * method hasIpAttachedLicenseTerms for contract LicenseRegistry + * + * @param request LicenseRegistryHasIpAttachedLicenseTermsRequest + * @return Promise + */ + public async hasIpAttachedLicenseTerms( + request: LicenseRegistryHasIpAttachedLicenseTermsRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "hasIpAttachedLicenseTerms", + args: [request.ipId, request.licenseTemplate, request.licenseTermsId], + }); + } - constructor(rpcClient: PublicClient, address?: Address) { - this.address = address || getAddress(disputeModuleAddress, rpcClient.chain?.id); - this.rpcClient = rpcClient; + /** + * method isConsumingScheduledOp for contract LicenseRegistry + * + * @param request LicenseRegistryIsConsumingScheduledOpRequest + * @return Promise + */ + public async isConsumingScheduledOp(): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "isConsumingScheduledOp", + }); } /** - * event DisputeCancelled for contract DisputeModule + * method isDerivativeIp for contract LicenseRegistry + * + * @param request LicenseRegistryIsDerivativeIpRequest + * @return Promise */ - public watchDisputeCancelledEvent( - onLogs: (txHash: Hex, ev: Partial) => void, - ): WatchContractEventReturnType { - return this.rpcClient.watchContractEvent({ - abi: disputeModuleAbi, + public async isDerivativeIp( + request: LicenseRegistryIsDerivativeIpRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, address: this.address, - eventName: "DisputeCancelled", - onLogs: (evs) => { - evs.forEach((it) => onLogs(it.transactionHash, it.args)); - }, + functionName: "isDerivativeIp", + args: [request.childIpId], }); } /** - * parse tx receipt event DisputeCancelled for contract DisputeModule + * method isExpiredNow for contract LicenseRegistry + * + * @param request LicenseRegistryIsExpiredNowRequest + * @return Promise */ - public parseTxDisputeCancelledEvent( - txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; - for (const log of txReceipt.logs) { - try { - const event = decodeEventLog({ - abi: disputeModuleAbi, - eventName: "DisputeCancelled", - data: log.data, - topics: log.topics, - }); - if (event.eventName === "DisputeCancelled") { - targetLogs.push(event.args); - } - } catch (e) { - /* empty */ - } - } - return targetLogs; + public async isExpiredNow( + request: LicenseRegistryIsExpiredNowRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "isExpiredNow", + args: [request.ipId], + }); } /** - * event DisputeRaised for contract DisputeModule + * method isParentIp for contract LicenseRegistry + * + * @param request LicenseRegistryIsParentIpRequest + * @return Promise */ - public watchDisputeRaisedEvent( - onLogs: (txHash: Hex, ev: Partial) => void, - ): WatchContractEventReturnType { - return this.rpcClient.watchContractEvent({ - abi: disputeModuleAbi, + public async isParentIp( + request: LicenseRegistryIsParentIpRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, address: this.address, - eventName: "DisputeRaised", - onLogs: (evs) => { - evs.forEach((it) => onLogs(it.transactionHash, it.args)); - }, + functionName: "isParentIp", + args: [request.parentIpId, request.childIpId], }); } /** - * parse tx receipt event DisputeRaised for contract DisputeModule + * method isRegisteredLicenseTemplate for contract LicenseRegistry + * + * @param request LicenseRegistryIsRegisteredLicenseTemplateRequest + * @return Promise */ - public parseTxDisputeRaisedEvent( - txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; - for (const log of txReceipt.logs) { - try { - const event = decodeEventLog({ - abi: disputeModuleAbi, - eventName: "DisputeRaised", - data: log.data, - topics: log.topics, - }); - if (event.eventName === "DisputeRaised") { - targetLogs.push(event.args); - } - } catch (e) { - /* empty */ - } - } - return targetLogs; + public async isRegisteredLicenseTemplate( + request: LicenseRegistryIsRegisteredLicenseTemplateRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "isRegisteredLicenseTemplate", + args: [request.licenseTemplate], + }); } /** - * event DisputeResolved for contract DisputeModule + * method proxiableUUID for contract LicenseRegistry + * + * @param request LicenseRegistryProxiableUuidRequest + * @return Promise */ - public watchDisputeResolvedEvent( - onLogs: (txHash: Hex, ev: Partial) => void, - ): WatchContractEventReturnType { - return this.rpcClient.watchContractEvent({ - abi: disputeModuleAbi, + public async proxiableUuid(): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, address: this.address, - eventName: "DisputeResolved", - onLogs: (evs) => { - evs.forEach((it) => onLogs(it.transactionHash, it.args)); - }, + functionName: "proxiableUUID", }); } /** - * parse tx receipt event DisputeResolved for contract DisputeModule + * method verifyMintLicenseToken for contract LicenseRegistry + * + * @param request LicenseRegistryVerifyMintLicenseTokenRequest + * @return Promise */ - public parseTxDisputeResolvedEvent( - txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; - for (const log of txReceipt.logs) { - try { - const event = decodeEventLog({ - abi: disputeModuleAbi, - eventName: "DisputeResolved", - data: log.data, - topics: log.topics, - }); - if (event.eventName === "DisputeResolved") { - targetLogs.push(event.args); - } - } catch (e) { - /* empty */ - } - } - return targetLogs; + public async verifyMintLicenseToken( + request: LicenseRegistryVerifyMintLicenseTokenRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "verifyMintLicenseToken", + args: [ + request.licensorIpId, + request.licenseTemplate, + request.licenseTermsId, + request.isMintedByIpOwner, + ], + }); } } /** - * contract DisputeModule write method + * contract LicenseRegistry write method */ -export class DisputeModuleClient extends DisputeModuleEventClient { +export class LicenseRegistryClient extends LicenseRegistryReadOnlyClient { protected readonly wallet: SimpleWalletClient; constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { @@ -6314,532 +9439,354 @@ export class DisputeModuleClient extends DisputeModuleEventClient { } /** - * method cancelDispute for contract DisputeModule + * method attachLicenseTermsToIp for contract LicenseRegistry * - * @param request DisputeModuleCancelDisputeRequest + * @param request LicenseRegistryAttachLicenseTermsToIpRequest * @return Promise */ - public async cancelDispute( - request: DisputeModuleCancelDisputeRequest, + public async attachLicenseTermsToIp( + request: LicenseRegistryAttachLicenseTermsToIpRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: disputeModuleAbi, + abi: licenseRegistryAbi, address: this.address, - functionName: "cancelDispute", + functionName: "attachLicenseTermsToIp", account: this.wallet.account, - args: [request.disputeId, request.data], + args: [request.ipId, request.licenseTemplate, request.licenseTermsId], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method raiseDispute for contract DisputeModule + * method initialize for contract LicenseRegistry * - * @param request DisputeModuleRaiseDisputeRequest + * @param request LicenseRegistryInitializeRequest * @return Promise */ - public async raiseDispute( - request: DisputeModuleRaiseDisputeRequest, + public async initialize( + request: LicenseRegistryInitializeRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: disputeModuleAbi, + abi: licenseRegistryAbi, address: this.address, - functionName: "raiseDispute", + functionName: "initialize", account: this.wallet.account, - args: [request.targetIpId, request.linkToDisputeEvidence, request.targetTag, request.data], + args: [request.accessManager], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method resolveDispute for contract DisputeModule + * method registerDerivativeIp for contract LicenseRegistry * - * @param request DisputeModuleResolveDisputeRequest + * @param request LicenseRegistryRegisterDerivativeIpRequest * @return Promise */ - public async resolveDispute( - request: DisputeModuleResolveDisputeRequest, + public async registerDerivativeIp( + request: LicenseRegistryRegisterDerivativeIpRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: disputeModuleAbi, + abi: licenseRegistryAbi, address: this.address, - functionName: "resolveDispute", + functionName: "registerDerivativeIp", account: this.wallet.account, - args: [request.disputeId, request.data], + args: [ + request.childIpId, + request.parentIpIds, + request.licenseTemplate, + request.licenseTermsIds, + ], }); - return await this.wallet.writeContract(call as WriteContractParameters); - } -} - -// Contract IPAccountImpl ============================================================= - -/** - * IpAccountImplExecuteRequest - * - * @param to address - * @param value uint256 - * @param data bytes - */ -export type IpAccountImplExecuteRequest = { - to: Address; - value: bigint; - data: Hex; -}; - -/** - * IpAccountImplExecuteWithSigRequest - * - * @param to address - * @param value uint256 - * @param data bytes - * @param signer address - * @param deadline uint256 - * @param signature bytes - */ -export type IpAccountImplExecuteWithSigRequest = { - to: Address; - value: bigint; - data: Hex; - signer: Address; - deadline: bigint; - signature: Hex; -}; - -/** - * contract IPAccountImpl write method - */ -export class IpAccountImplClient { - protected readonly wallet: SimpleWalletClient; - protected readonly rpcClient: PublicClient; - public readonly address: Address; - - constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { - this.address = address || getAddress(ipAccountImplAddress, rpcClient.chain?.id); - this.rpcClient = rpcClient; - this.wallet = wallet; + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method execute for contract IPAccountImpl + * method registerLicenseTemplate for contract LicenseRegistry * - * @param request IpAccountImplExecuteRequest + * @param request LicenseRegistryRegisterLicenseTemplateRequest * @return Promise */ - public async execute(request: IpAccountImplExecuteRequest): Promise { + public async registerLicenseTemplate( + request: LicenseRegistryRegisterLicenseTemplateRequest, + ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: ipAccountImplAbi, + abi: licenseRegistryAbi, address: this.address, - functionName: "execute", + functionName: "registerLicenseTemplate", account: this.wallet.account, - args: [request.to, request.value, request.data], + args: [request.licenseTemplate], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method executeWithSig for contract IPAccountImpl + * method setAuthority for contract LicenseRegistry * - * @param request IpAccountImplExecuteWithSigRequest + * @param request LicenseRegistrySetAuthorityRequest * @return Promise */ - public async executeWithSig( - request: IpAccountImplExecuteWithSigRequest, + public async setAuthority( + request: LicenseRegistrySetAuthorityRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: ipAccountImplAbi, + abi: licenseRegistryAbi, address: this.address, - functionName: "executeWithSig", + functionName: "setAuthority", account: this.wallet.account, - args: [ - request.to, - request.value, - request.data, - request.signer, - request.deadline, - request.signature, - ], + args: [request.newAuthority], }); return await this.wallet.writeContract(call as WriteContractParameters); } -} - -// Contract IPAssetRegistry ============================================================= - -/** - * IpAssetRegistryIpRegisteredEvent - * - * @param ipId address - * @param chainId uint256 - * @param tokenContract address - * @param tokenId uint256 - * @param name string - * @param uri string - * @param registrationDate uint256 - */ -export type IpAssetRegistryIpRegisteredEvent = { - ipId: Address; - chainId: bigint; - tokenContract: Address; - tokenId: bigint; - name: string; - uri: string; - registrationDate: bigint; -}; - -/** - * IpAssetRegistryIpIdRequest - * - * @param chainId uint256 - * @param tokenContract address - * @param tokenId uint256 - */ -export type IpAssetRegistryIpIdRequest = { - chainId: bigint; - tokenContract: Address; - tokenId: bigint; -}; - -export type IpAssetRegistryIpIdResponse = Address; - -/** - * IpAssetRegistryIsRegisteredRequest - * - * @param id address - */ -export type IpAssetRegistryIsRegisteredRequest = { - id: Address; -}; - -export type IpAssetRegistryIsRegisteredResponse = boolean; - -/** - * IpAssetRegistryRegisterRequest - * - * @param chainid uint256 - * @param tokenContract address - * @param tokenId uint256 - */ -export type IpAssetRegistryRegisterRequest = { - chainid: bigint; - tokenContract: Address; - tokenId: bigint; -}; - -/** - * contract IPAssetRegistry event - */ -export class IpAssetRegistryEventClient { - protected readonly rpcClient: PublicClient; - public readonly address: Address; - - constructor(rpcClient: PublicClient, address?: Address) { - this.address = address || getAddress(ipAssetRegistryAddress, rpcClient.chain?.id); - this.rpcClient = rpcClient; - } /** - * event IPRegistered for contract IPAssetRegistry + * method setDefaultLicenseTerms for contract LicenseRegistry + * + * @param request LicenseRegistrySetDefaultLicenseTermsRequest + * @return Promise */ - public watchIpRegisteredEvent( - onLogs: (txHash: Hex, ev: Partial) => void, - ): WatchContractEventReturnType { - return this.rpcClient.watchContractEvent({ - abi: ipAssetRegistryAbi, + public async setDefaultLicenseTerms( + request: LicenseRegistrySetDefaultLicenseTermsRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: licenseRegistryAbi, address: this.address, - eventName: "IPRegistered", - onLogs: (evs) => { - evs.forEach((it) => onLogs(it.transactionHash, it.args)); - }, + functionName: "setDefaultLicenseTerms", + account: this.wallet.account, + args: [request.newLicenseTemplate, request.newLicenseTermsId], }); + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * parse tx receipt event IPRegistered for contract IPAssetRegistry + * method setExpireTime for contract LicenseRegistry + * + * @param request LicenseRegistrySetExpireTimeRequest + * @return Promise */ - public parseTxIpRegisteredEvent( - txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; - for (const log of txReceipt.logs) { - try { - const event = decodeEventLog({ - abi: ipAssetRegistryAbi, - eventName: "IPRegistered", - data: log.data, - topics: log.topics, - }); - if (event.eventName === "IPRegistered") { - targetLogs.push(event.args); - } - } catch (e) { - /* empty */ - } - } - return targetLogs; + public async setExpireTime( + request: LicenseRegistrySetExpireTimeRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "setExpireTime", + account: this.wallet.account, + args: [request.ipId, request.expireTime], + }); + return await this.wallet.writeContract(call as WriteContractParameters); } -} -/** - * contract IPAssetRegistry readonly method - */ -export class IpAssetRegistryReadOnlyClient extends IpAssetRegistryEventClient { - constructor(rpcClient: PublicClient, address?: Address) { - super(rpcClient, address); + /** + * method setLicensingConfigForIp for contract LicenseRegistry + * + * @param request LicenseRegistrySetLicensingConfigForIpRequest + * @return Promise + */ + public async setLicensingConfigForIp( + request: LicenseRegistrySetLicensingConfigForIpRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: licenseRegistryAbi, + address: this.address, + functionName: "setLicensingConfigForIp", + account: this.wallet.account, + args: [request.ipId, request.licensingConfig], + }); + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method ipId for contract IPAssetRegistry + * method setLicensingConfigForLicense for contract LicenseRegistry * - * @param request IpAssetRegistryIpIdRequest - * @return Promise + * @param request LicenseRegistrySetLicensingConfigForLicenseRequest + * @return Promise */ - public async ipId(request: IpAssetRegistryIpIdRequest): Promise { - return await this.rpcClient.readContract({ - abi: ipAssetRegistryAbi, + public async setLicensingConfigForLicense( + request: LicenseRegistrySetLicensingConfigForLicenseRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: licenseRegistryAbi, address: this.address, - functionName: "ipId", - args: [request.chainId, request.tokenContract, request.tokenId], + functionName: "setLicensingConfigForLicense", + account: this.wallet.account, + args: [ + request.ipId, + request.licenseTemplate, + request.licenseTermsId, + request.licensingConfig, + ], }); + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method isRegistered for contract IPAssetRegistry + * method upgradeToAndCall for contract LicenseRegistry * - * @param request IpAssetRegistryIsRegisteredRequest - * @return Promise + * @param request LicenseRegistryUpgradeToAndCallRequest + * @return Promise */ - public async isRegistered( - request: IpAssetRegistryIsRegisteredRequest, - ): Promise { - return await this.rpcClient.readContract({ - abi: ipAssetRegistryAbi, + public async upgradeToAndCall( + request: LicenseRegistryUpgradeToAndCallRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: licenseRegistryAbi, address: this.address, - functionName: "isRegistered", - args: [request.id], + functionName: "upgradeToAndCall", + account: this.wallet.account, + args: [request.newImplementation, request.data], }); + return await this.wallet.writeContract(call as WriteContractParameters); } } +// Contract LicenseToken ============================================================= + /** - * contract IPAssetRegistry write method + * LicenseTokenOwnerOfRequest + * + * @param tokenId uint256 + */ +export type LicenseTokenOwnerOfRequest = { + tokenId: bigint; +}; + +export type LicenseTokenOwnerOfResponse = Address; + +/** + * contract LicenseToken readonly method */ -export class IpAssetRegistryClient extends IpAssetRegistryReadOnlyClient { - protected readonly wallet: SimpleWalletClient; +export class LicenseTokenReadOnlyClient { + protected readonly rpcClient: PublicClient; + public readonly address: Address; - constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { - super(rpcClient, address); - this.wallet = wallet; + constructor(rpcClient: PublicClient, address?: Address) { + this.address = address || getAddress(licenseTokenAddress, rpcClient.chain?.id); + this.rpcClient = rpcClient; } /** - * method register for contract IPAssetRegistry + * method ownerOf for contract LicenseToken * - * @param request IpAssetRegistryRegisterRequest - * @return Promise + * @param request LicenseTokenOwnerOfRequest + * @return Promise */ - public async register(request: IpAssetRegistryRegisterRequest): Promise { - const { request: call } = await this.rpcClient.simulateContract({ - abi: ipAssetRegistryAbi, + public async ownerOf(request: LicenseTokenOwnerOfRequest): Promise { + return await this.rpcClient.readContract({ + abi: licenseTokenAbi, address: this.address, - functionName: "register", - account: this.wallet.account, - args: [request.chainid, request.tokenContract, request.tokenId], + functionName: "ownerOf", + args: [request.tokenId], }); - return await this.wallet.writeContract(call as WriteContractParameters); } } -// Contract IpRoyaltyVaultImpl ============================================================= +// Contract LicensingModule ============================================================= /** - * IpRoyaltyVaultImplRevenueTokenClaimedEvent + * LicensingModuleLicenseTokensMintedEvent * - * @param claimer address - * @param token address + * @param caller address + * @param licensorIpId address + * @param licenseTemplate address + * @param licenseTermsId uint256 * @param amount uint256 + * @param receiver address + * @param startLicenseTokenId uint256 */ -export type IpRoyaltyVaultImplRevenueTokenClaimedEvent = { - claimer: Address; - token: Address; +export type LicensingModuleLicenseTokensMintedEvent = { + caller: Address; + licensorIpId: Address; + licenseTemplate: Address; + licenseTermsId: bigint; amount: bigint; + receiver: Address; + startLicenseTokenId: bigint; }; /** - * IpRoyaltyVaultImplRoyaltyTokensCollectedEvent - * - * @param ancestorIpId address - * @param royaltyTokensCollected uint256 - */ -export type IpRoyaltyVaultImplRoyaltyTokensCollectedEvent = { - ancestorIpId: Address; - royaltyTokensCollected: bigint; -}; - -/** - * IpRoyaltyVaultImplSnapshotCompletedEvent - * - * @param snapshotId uint256 - * @param snapshotTimestamp uint256 - * @param unclaimedTokens uint32 - */ -export type IpRoyaltyVaultImplSnapshotCompletedEvent = { - snapshotId: bigint; - snapshotTimestamp: bigint; - unclaimedTokens: number; -}; - -/** - * IpRoyaltyVaultImplClaimableRevenueRequest + * LicensingModuleAttachLicenseTermsRequest * - * @param account address - * @param snapshotId uint256 - * @param token address + * @param ipId address + * @param licenseTemplate address + * @param licenseTermsId uint256 */ -export type IpRoyaltyVaultImplClaimableRevenueRequest = { - account: Address; - snapshotId: bigint; - token: Address; +export type LicensingModuleAttachLicenseTermsRequest = { + ipId: Address; + licenseTemplate: Address; + licenseTermsId: bigint; }; -export type IpRoyaltyVaultImplClaimableRevenueResponse = bigint; - -export type IpRoyaltyVaultImplIpIdResponse = Address; - /** - * IpRoyaltyVaultImplClaimRevenueBySnapshotBatchRequest + * LicensingModuleMintLicenseTokensRequest * - * @param snapshotIds uint256[] - * @param token address + * @param licensorIpId address + * @param licenseTemplate address + * @param licenseTermsId uint256 + * @param amount uint256 + * @param receiver address + * @param royaltyContext bytes */ -export type IpRoyaltyVaultImplClaimRevenueBySnapshotBatchRequest = { - snapshotIds: readonly bigint[]; - token: Address; +export type LicensingModuleMintLicenseTokensRequest = { + licensorIpId: Address; + licenseTemplate: Address; + licenseTermsId: bigint; + amount: bigint; + receiver: Address; + royaltyContext: Hex; }; /** - * IpRoyaltyVaultImplClaimRevenueByTokenBatchRequest + * LicensingModuleRegisterDerivativeRequest * - * @param snapshotId uint256 - * @param tokenList address[] + * @param childIpId address + * @param parentIpIds address[] + * @param licenseTermsIds uint256[] + * @param licenseTemplate address + * @param royaltyContext bytes */ -export type IpRoyaltyVaultImplClaimRevenueByTokenBatchRequest = { - snapshotId: bigint; - tokenList: readonly Address[]; +export type LicensingModuleRegisterDerivativeRequest = { + childIpId: Address; + parentIpIds: readonly Address[]; + licenseTermsIds: readonly bigint[]; + licenseTemplate: Address; + royaltyContext: Hex; }; /** - * IpRoyaltyVaultImplCollectRoyaltyTokensRequest + * LicensingModuleRegisterDerivativeWithLicenseTokensRequest * - * @param ancestorIpId address + * @param childIpId address + * @param licenseTokenIds uint256[] + * @param royaltyContext bytes */ -export type IpRoyaltyVaultImplCollectRoyaltyTokensRequest = { - ancestorIpId: Address; +export type LicensingModuleRegisterDerivativeWithLicenseTokensRequest = { + childIpId: Address; + licenseTokenIds: readonly bigint[]; + royaltyContext: Hex; }; /** - * contract IpRoyaltyVaultImpl event + * contract LicensingModule event */ -export class IpRoyaltyVaultImplEventClient { +export class LicensingModuleEventClient { protected readonly rpcClient: PublicClient; public readonly address: Address; constructor(rpcClient: PublicClient, address?: Address) { - this.address = address || getAddress(ipRoyaltyVaultImplAddress, rpcClient.chain?.id); + this.address = address || getAddress(licensingModuleAddress, rpcClient.chain?.id); this.rpcClient = rpcClient; } /** - * event RevenueTokenClaimed for contract IpRoyaltyVaultImpl - */ - public watchRevenueTokenClaimedEvent( - onLogs: (txHash: Hex, ev: Partial) => void, - ): WatchContractEventReturnType { - return this.rpcClient.watchContractEvent({ - abi: ipRoyaltyVaultImplAbi, - address: this.address, - eventName: "RevenueTokenClaimed", - onLogs: (evs) => { - evs.forEach((it) => onLogs(it.transactionHash, it.args)); - }, - }); - } - - /** - * parse tx receipt event RevenueTokenClaimed for contract IpRoyaltyVaultImpl - */ - public parseTxRevenueTokenClaimedEvent( - txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; - for (const log of txReceipt.logs) { - try { - const event = decodeEventLog({ - abi: ipRoyaltyVaultImplAbi, - eventName: "RevenueTokenClaimed", - data: log.data, - topics: log.topics, - }); - if (event.eventName === "RevenueTokenClaimed") { - targetLogs.push(event.args); - } - } catch (e) { - /* empty */ - } - } - return targetLogs; - } - - /** - * event RoyaltyTokensCollected for contract IpRoyaltyVaultImpl - */ - public watchRoyaltyTokensCollectedEvent( - onLogs: (txHash: Hex, ev: Partial) => void, - ): WatchContractEventReturnType { - return this.rpcClient.watchContractEvent({ - abi: ipRoyaltyVaultImplAbi, - address: this.address, - eventName: "RoyaltyTokensCollected", - onLogs: (evs) => { - evs.forEach((it) => onLogs(it.transactionHash, it.args)); - }, - }); - } - - /** - * parse tx receipt event RoyaltyTokensCollected for contract IpRoyaltyVaultImpl - */ - public parseTxRoyaltyTokensCollectedEvent( - txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; - for (const log of txReceipt.logs) { - try { - const event = decodeEventLog({ - abi: ipRoyaltyVaultImplAbi, - eventName: "RoyaltyTokensCollected", - data: log.data, - topics: log.topics, - }); - if (event.eventName === "RoyaltyTokensCollected") { - targetLogs.push(event.args); - } - } catch (e) { - /* empty */ - } - } - return targetLogs; - } - - /** - * event SnapshotCompleted for contract IpRoyaltyVaultImpl + * event LicenseTokensMinted for contract LicensingModule */ - public watchSnapshotCompletedEvent( - onLogs: (txHash: Hex, ev: Partial) => void, + public watchLicenseTokensMintedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, ): WatchContractEventReturnType { return this.rpcClient.watchContractEvent({ - abi: ipRoyaltyVaultImplAbi, + abi: licensingModuleAbi, address: this.address, - eventName: "SnapshotCompleted", + eventName: "LicenseTokensMinted", onLogs: (evs) => { evs.forEach((it) => onLogs(it.transactionHash, it.args)); }, @@ -6847,21 +9794,21 @@ export class IpRoyaltyVaultImplEventClient { } /** - * parse tx receipt event SnapshotCompleted for contract IpRoyaltyVaultImpl + * parse tx receipt event LicenseTokensMinted for contract LicensingModule */ - public parseTxSnapshotCompletedEvent( + public parseTxLicenseTokensMintedEvent( txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; + ): Array { + const targetLogs: Array = []; for (const log of txReceipt.logs) { try { const event = decodeEventLog({ - abi: ipRoyaltyVaultImplAbi, - eventName: "SnapshotCompleted", + abi: licensingModuleAbi, + eventName: "LicenseTokensMinted", data: log.data, topics: log.topics, }); - if (event.eventName === "SnapshotCompleted") { + if (event.eventName === "LicenseTokensMinted") { targetLogs.push(event.args); } } catch (e) { @@ -6873,49 +9820,9 @@ export class IpRoyaltyVaultImplEventClient { } /** - * contract IpRoyaltyVaultImpl readonly method - */ -export class IpRoyaltyVaultImplReadOnlyClient extends IpRoyaltyVaultImplEventClient { - constructor(rpcClient: PublicClient, address?: Address) { - super(rpcClient, address); - } - - /** - * method claimableRevenue for contract IpRoyaltyVaultImpl - * - * @param request IpRoyaltyVaultImplClaimableRevenueRequest - * @return Promise - */ - public async claimableRevenue( - request: IpRoyaltyVaultImplClaimableRevenueRequest, - ): Promise { - return await this.rpcClient.readContract({ - abi: ipRoyaltyVaultImplAbi, - address: this.address, - functionName: "claimableRevenue", - args: [request.account, request.snapshotId, request.token], - }); - } - - /** - * method ipId for contract IpRoyaltyVaultImpl - * - * @param request IpRoyaltyVaultImplIpIdRequest - * @return Promise - */ - public async ipId(): Promise { - return await this.rpcClient.readContract({ - abi: ipRoyaltyVaultImplAbi, - address: this.address, - functionName: "ipId", - }); - } -} - -/** - * contract IpRoyaltyVaultImpl write method + * contract LicensingModule write method */ -export class IpRoyaltyVaultImplClient extends IpRoyaltyVaultImplReadOnlyClient { +export class LicensingModuleClient extends LicensingModuleEventClient { protected readonly wallet: SimpleWalletClient; constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { @@ -6924,559 +9831,560 @@ export class IpRoyaltyVaultImplClient extends IpRoyaltyVaultImplReadOnlyClient { } /** - * method claimRevenueBySnapshotBatch for contract IpRoyaltyVaultImpl + * method attachLicenseTerms for contract LicensingModule * - * @param request IpRoyaltyVaultImplClaimRevenueBySnapshotBatchRequest + * @param request LicensingModuleAttachLicenseTermsRequest * @return Promise */ - public async claimRevenueBySnapshotBatch( - request: IpRoyaltyVaultImplClaimRevenueBySnapshotBatchRequest, + public async attachLicenseTerms( + request: LicensingModuleAttachLicenseTermsRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: ipRoyaltyVaultImplAbi, + abi: licensingModuleAbi, address: this.address, - functionName: "claimRevenueBySnapshotBatch", + functionName: "attachLicenseTerms", account: this.wallet.account, - args: [request.snapshotIds, request.token], + args: [request.ipId, request.licenseTemplate, request.licenseTermsId], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method claimRevenueByTokenBatch for contract IpRoyaltyVaultImpl + * method mintLicenseTokens for contract LicensingModule * - * @param request IpRoyaltyVaultImplClaimRevenueByTokenBatchRequest + * @param request LicensingModuleMintLicenseTokensRequest * @return Promise */ - public async claimRevenueByTokenBatch( - request: IpRoyaltyVaultImplClaimRevenueByTokenBatchRequest, + public async mintLicenseTokens( + request: LicensingModuleMintLicenseTokensRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: ipRoyaltyVaultImplAbi, + abi: licensingModuleAbi, address: this.address, - functionName: "claimRevenueByTokenBatch", + functionName: "mintLicenseTokens", account: this.wallet.account, - args: [request.snapshotId, request.tokenList], + args: [ + request.licensorIpId, + request.licenseTemplate, + request.licenseTermsId, + request.amount, + request.receiver, + request.royaltyContext, + ], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method collectRoyaltyTokens for contract IpRoyaltyVaultImpl + * method registerDerivative for contract LicensingModule * - * @param request IpRoyaltyVaultImplCollectRoyaltyTokensRequest + * @param request LicensingModuleRegisterDerivativeRequest * @return Promise */ - public async collectRoyaltyTokens( - request: IpRoyaltyVaultImplCollectRoyaltyTokensRequest, + public async registerDerivative( + request: LicensingModuleRegisterDerivativeRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: ipRoyaltyVaultImplAbi, + abi: licensingModuleAbi, address: this.address, - functionName: "collectRoyaltyTokens", + functionName: "registerDerivative", account: this.wallet.account, - args: [request.ancestorIpId], + args: [ + request.childIpId, + request.parentIpIds, + request.licenseTermsIds, + request.licenseTemplate, + request.royaltyContext, + ], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method snapshot for contract IpRoyaltyVaultImpl + * method registerDerivativeWithLicenseTokens for contract LicensingModule * - * @param request IpRoyaltyVaultImplSnapshotRequest + * @param request LicensingModuleRegisterDerivativeWithLicenseTokensRequest * @return Promise */ - public async snapshot(): Promise { + public async registerDerivativeWithLicenseTokens( + request: LicensingModuleRegisterDerivativeWithLicenseTokensRequest, + ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: ipRoyaltyVaultImplAbi, + abi: licensingModuleAbi, address: this.address, - functionName: "snapshot", + functionName: "registerDerivativeWithLicenseTokens", account: this.wallet.account, + args: [request.childIpId, request.licenseTokenIds, request.royaltyContext], }); return await this.wallet.writeContract(call as WriteContractParameters); } } -// Contract LicenseRegistry ============================================================= - -/** - * LicenseRegistryAuthorityUpdatedEvent - * - * @param authority address - */ -export type LicenseRegistryAuthorityUpdatedEvent = { - authority: Address; -}; - -/** - * LicenseRegistryExpirationTimeSetEvent - * - * @param ipId address - * @param expireTime uint256 - */ -export type LicenseRegistryExpirationTimeSetEvent = { - ipId: Address; - expireTime: bigint; -}; - -/** - * LicenseRegistryInitializedEvent - * - * @param version uint64 - */ -export type LicenseRegistryInitializedEvent = { - version: bigint; -}; - -/** - * LicenseRegistryLicenseTemplateRegisteredEvent - * - * @param licenseTemplate address - */ -export type LicenseRegistryLicenseTemplateRegisteredEvent = { - licenseTemplate: Address; -}; +// Contract ModuleRegistry ============================================================= /** - * LicenseRegistryLicensingConfigSetForIpEvent + * ModuleRegistryIsRegisteredRequest * - * @param ipId address - * @param licensingConfig tuple + * @param moduleAddress address */ -export type LicenseRegistryLicensingConfigSetForIpEvent = { - ipId: Address; - licensingConfig: { - isSet: boolean; - mintingFee: bigint; - licensingHook: Address; - hookData: Hex; - }; +export type ModuleRegistryIsRegisteredRequest = { + moduleAddress: Address; }; -/** - * LicenseRegistryLicensingConfigSetForLicenseEvent - * - * @param ipId address - * @param licenseTemplate address - * @param licenseTermsId uint256 - */ -export type LicenseRegistryLicensingConfigSetForLicenseEvent = { - ipId: Address; - licenseTemplate: Address; - licenseTermsId: bigint; -}; +export type ModuleRegistryIsRegisteredResponse = boolean; /** - * LicenseRegistryUpgradedEvent - * - * @param implementation address + * contract ModuleRegistry readonly method */ -export type LicenseRegistryUpgradedEvent = { - implementation: Address; -}; - -export type LicenseRegistryDisputeModuleResponse = Address; - -export type LicenseRegistryExpirationTimeResponse = Hex; - -export type LicenseRegistryLicensingModuleResponse = Address; - -export type LicenseRegistryUpgradeInterfaceVersionResponse = string; - -export type LicenseRegistryAuthorityResponse = Address; +export class ModuleRegistryReadOnlyClient { + protected readonly rpcClient: PublicClient; + public readonly address: Address; -/** - * LicenseRegistryExistsRequest - * - * @param licenseTemplate address - * @param licenseTermsId uint256 - */ -export type LicenseRegistryExistsRequest = { - licenseTemplate: Address; - licenseTermsId: bigint; -}; + constructor(rpcClient: PublicClient, address?: Address) { + this.address = address || getAddress(moduleRegistryAddress, rpcClient.chain?.id); + this.rpcClient = rpcClient; + } -export type LicenseRegistryExistsResponse = boolean; + /** + * method isRegistered for contract ModuleRegistry + * + * @param request ModuleRegistryIsRegisteredRequest + * @return Promise + */ + public async isRegistered( + request: ModuleRegistryIsRegisteredRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: moduleRegistryAbi, + address: this.address, + functionName: "isRegistered", + args: [request.moduleAddress], + }); + } +} -/** - * LicenseRegistryGetAttachedLicenseTermsRequest - * - * @param ipId address - * @param index uint256 - */ -export type LicenseRegistryGetAttachedLicenseTermsRequest = { - ipId: Address; - index: bigint; -}; +// Contract PILicenseTemplate ============================================================= /** - * LicenseRegistryGetAttachedLicenseTermsResponse + * PiLicenseTemplateAuthorityUpdatedEvent * - * @param licenseTemplate address - * @param licenseTermsId uint256 + * @param authority address */ -export type LicenseRegistryGetAttachedLicenseTermsResponse = { - licenseTemplate: Address; - licenseTermsId: bigint; +export type PiLicenseTemplateAuthorityUpdatedEvent = { + authority: Address; }; /** - * LicenseRegistryGetAttachedLicenseTermsCountRequest + * PiLicenseTemplateDerivativeApprovedEvent * + * @param licenseTermsId uint256 * @param ipId address + * @param caller address + * @param approved bool */ -export type LicenseRegistryGetAttachedLicenseTermsCountRequest = { +export type PiLicenseTemplateDerivativeApprovedEvent = { + licenseTermsId: bigint; ipId: Address; + caller: Address; + approved: boolean; }; -export type LicenseRegistryGetAttachedLicenseTermsCountResponse = bigint; - /** - * LicenseRegistryGetDefaultLicenseTermsResponse + * PiLicenseTemplateInitializedEvent * - * @param licenseTemplate address - * @param licenseTermsId uint256 + * @param version uint64 */ -export type LicenseRegistryGetDefaultLicenseTermsResponse = { - licenseTemplate: Address; - licenseTermsId: bigint; +export type PiLicenseTemplateInitializedEvent = { + version: bigint; }; /** - * LicenseRegistryGetDerivativeIpRequest + * PiLicenseTemplateLicenseTermsRegisteredEvent * - * @param parentIpId address - * @param index uint256 + * @param licenseTermsId uint256 + * @param licenseTemplate address + * @param licenseTerms bytes */ -export type LicenseRegistryGetDerivativeIpRequest = { - parentIpId: Address; - index: bigint; +export type PiLicenseTemplateLicenseTermsRegisteredEvent = { + licenseTermsId: bigint; + licenseTemplate: Address; + licenseTerms: Hex; }; /** - * LicenseRegistryGetDerivativeIpResponse + * PiLicenseTemplateUpgradedEvent * - * @param childIpId address + * @param implementation address */ -export type LicenseRegistryGetDerivativeIpResponse = { - childIpId: Address; +export type PiLicenseTemplateUpgradedEvent = { + implementation: Address; }; +export type PiLicenseTemplateAccessControllerResponse = Address; + +export type PiLicenseTemplateIpAccountRegistryResponse = Address; + +export type PiLicenseTemplateLicenseRegistryResponse = Address; + +export type PiLicenseTemplateRoyaltyModuleResponse = Address; + +export type PiLicenseTemplateUpgradeInterfaceVersionResponse = string; + +export type PiLicenseTemplateAuthorityResponse = Address; + /** - * LicenseRegistryGetDerivativeIpCountRequest + * PiLicenseTemplateExistsRequest * - * @param parentIpId address + * @param licenseTermsId uint256 */ -export type LicenseRegistryGetDerivativeIpCountRequest = { - parentIpId: Address; +export type PiLicenseTemplateExistsRequest = { + licenseTermsId: bigint; }; -export type LicenseRegistryGetDerivativeIpCountResponse = bigint; +export type PiLicenseTemplateExistsResponse = boolean; /** - * LicenseRegistryGetExpireTimeRequest + * PiLicenseTemplateGetEarlierExpireTimeRequest * - * @param ipId address + * @param licenseTermsIds uint256[] + * @param start uint256 */ -export type LicenseRegistryGetExpireTimeRequest = { - ipId: Address; +export type PiLicenseTemplateGetEarlierExpireTimeRequest = { + licenseTermsIds: readonly bigint[]; + start: bigint; }; -export type LicenseRegistryGetExpireTimeResponse = bigint; +export type PiLicenseTemplateGetEarlierExpireTimeResponse = bigint; /** - * LicenseRegistryGetLicensingConfigRequest + * PiLicenseTemplateGetExpireTimeRequest * - * @param ipId address - * @param licenseTemplate address * @param licenseTermsId uint256 + * @param start uint256 */ -export type LicenseRegistryGetLicensingConfigRequest = { - ipId: Address; - licenseTemplate: Address; +export type PiLicenseTemplateGetExpireTimeRequest = { licenseTermsId: bigint; + start: bigint; }; -export type LicenseRegistryGetLicensingConfigResponse = { - isSet: boolean; - mintingFee: bigint; - licensingHook: Address; - hookData: Hex; -}; +export type PiLicenseTemplateGetExpireTimeResponse = bigint; /** - * LicenseRegistryGetParentIpRequest + * PiLicenseTemplateGetLicenseTermsRequest * - * @param childIpId address - * @param index uint256 + * @param selectedLicenseTermsId uint256 */ -export type LicenseRegistryGetParentIpRequest = { - childIpId: Address; - index: bigint; +export type PiLicenseTemplateGetLicenseTermsRequest = { + selectedLicenseTermsId: bigint; }; /** - * LicenseRegistryGetParentIpResponse + * PiLicenseTemplateGetLicenseTermsResponse * - * @param parentIpId address + * @param terms tuple */ -export type LicenseRegistryGetParentIpResponse = { - parentIpId: Address; +export type PiLicenseTemplateGetLicenseTermsResponse = { + terms: { + transferable: boolean; + royaltyPolicy: Address; + mintingFee: bigint; + expiration: bigint; + commercialUse: boolean; + commercialAttribution: boolean; + commercializerChecker: Address; + commercializerCheckerData: Hex; + commercialRevShare: number; + commercialRevCelling: bigint; + derivativesAllowed: boolean; + derivativesAttribution: boolean; + derivativesApproval: boolean; + derivativesReciprocal: boolean; + derivativeRevCelling: bigint; + currency: Address; + uri: string; + }; }; /** - * LicenseRegistryGetParentIpCountRequest + * PiLicenseTemplateGetLicenseTermsIdRequest * - * @param childIpId address + * @param terms tuple */ -export type LicenseRegistryGetParentIpCountRequest = { - childIpId: Address; +export type PiLicenseTemplateGetLicenseTermsIdRequest = { + terms: { + transferable: boolean; + royaltyPolicy: Address; + mintingFee: bigint; + expiration: bigint; + commercialUse: boolean; + commercialAttribution: boolean; + commercializerChecker: Address; + commercializerCheckerData: Hex; + commercialRevShare: number; + commercialRevCelling: bigint; + derivativesAllowed: boolean; + derivativesAttribution: boolean; + derivativesApproval: boolean; + derivativesReciprocal: boolean; + derivativeRevCelling: bigint; + currency: Address; + uri: string; + }; }; -export type LicenseRegistryGetParentIpCountResponse = bigint; - /** - * LicenseRegistryHasDerivativeIpsRequest + * PiLicenseTemplateGetLicenseTermsIdResponse * - * @param parentIpId address + * @param selectedLicenseTermsId uint256 */ -export type LicenseRegistryHasDerivativeIpsRequest = { - parentIpId: Address; +export type PiLicenseTemplateGetLicenseTermsIdResponse = { + selectedLicenseTermsId: bigint; }; -export type LicenseRegistryHasDerivativeIpsResponse = boolean; - /** - * LicenseRegistryHasIpAttachedLicenseTermsRequest + * PiLicenseTemplateGetLicenseTermsUriRequest * - * @param ipId address - * @param licenseTemplate address * @param licenseTermsId uint256 */ -export type LicenseRegistryHasIpAttachedLicenseTermsRequest = { - ipId: Address; - licenseTemplate: Address; +export type PiLicenseTemplateGetLicenseTermsUriRequest = { licenseTermsId: bigint; }; -export type LicenseRegistryHasIpAttachedLicenseTermsResponse = boolean; +export type PiLicenseTemplateGetLicenseTermsUriResponse = string; -export type LicenseRegistryIsConsumingScheduledOpResponse = Hex; +export type PiLicenseTemplateGetMetadataUriResponse = string; /** - * LicenseRegistryIsDerivativeIpRequest + * PiLicenseTemplateGetRoyaltyPolicyRequest * - * @param childIpId address + * @param licenseTermsId uint256 */ -export type LicenseRegistryIsDerivativeIpRequest = { - childIpId: Address; +export type PiLicenseTemplateGetRoyaltyPolicyRequest = { + licenseTermsId: bigint; }; -export type LicenseRegistryIsDerivativeIpResponse = boolean; - /** - * LicenseRegistryIsExpiredNowRequest + * PiLicenseTemplateGetRoyaltyPolicyResponse * - * @param ipId address + * @param royaltyPolicy address + * @param royaltyData bytes + * @param mintingFee uint256 + * @param currency address */ -export type LicenseRegistryIsExpiredNowRequest = { - ipId: Address; +export type PiLicenseTemplateGetRoyaltyPolicyResponse = { + royaltyPolicy: Address; + royaltyData: Hex; + mintingFee: bigint; + currency: Address; }; -export type LicenseRegistryIsExpiredNowResponse = boolean; +export type PiLicenseTemplateIsConsumingScheduledOpResponse = Hex; /** - * LicenseRegistryIsParentIpRequest + * PiLicenseTemplateIsDerivativeApprovedRequest * * @param parentIpId address + * @param licenseTermsId uint256 * @param childIpId address */ -export type LicenseRegistryIsParentIpRequest = { +export type PiLicenseTemplateIsDerivativeApprovedRequest = { parentIpId: Address; + licenseTermsId: bigint; childIpId: Address; }; -export type LicenseRegistryIsParentIpResponse = boolean; +export type PiLicenseTemplateIsDerivativeApprovedResponse = boolean; /** - * LicenseRegistryIsRegisteredLicenseTemplateRequest + * PiLicenseTemplateIsLicenseTransferableRequest * - * @param licenseTemplate address + * @param licenseTermsId uint256 */ -export type LicenseRegistryIsRegisteredLicenseTemplateRequest = { - licenseTemplate: Address; +export type PiLicenseTemplateIsLicenseTransferableRequest = { + licenseTermsId: bigint; }; -export type LicenseRegistryIsRegisteredLicenseTemplateResponse = boolean; +export type PiLicenseTemplateIsLicenseTransferableResponse = boolean; -export type LicenseRegistryProxiableUuidResponse = Hex; +export type PiLicenseTemplateNameResponse = string; + +export type PiLicenseTemplateProxiableUuidResponse = Hex; /** - * LicenseRegistryVerifyMintLicenseTokenRequest + * PiLicenseTemplateSupportsInterfaceRequest * - * @param licensorIpId address - * @param licenseTemplate address - * @param licenseTermsId uint256 - * @param isMintedByIpOwner bool + * @param interfaceId bytes4 */ -export type LicenseRegistryVerifyMintLicenseTokenRequest = { - licensorIpId: Address; - licenseTemplate: Address; - licenseTermsId: bigint; - isMintedByIpOwner: boolean; +export type PiLicenseTemplateSupportsInterfaceRequest = { + interfaceId: Hex; }; -export type LicenseRegistryVerifyMintLicenseTokenResponse = { - isSet: boolean; - mintingFee: bigint; - licensingHook: Address; - hookData: Hex; -}; +export type PiLicenseTemplateSupportsInterfaceResponse = boolean; /** - * LicenseRegistryAttachLicenseTermsToIpRequest + * PiLicenseTemplateToJsonRequest * - * @param ipId address - * @param licenseTemplate address * @param licenseTermsId uint256 */ -export type LicenseRegistryAttachLicenseTermsToIpRequest = { - ipId: Address; - licenseTemplate: Address; +export type PiLicenseTemplateToJsonRequest = { licenseTermsId: bigint; }; +export type PiLicenseTemplateToJsonResponse = string; + +export type PiLicenseTemplateTotalRegisteredLicenseTermsResponse = bigint; + /** - * LicenseRegistryInitializeRequest + * PiLicenseTemplateVerifyCompatibleLicensesRequest * - * @param accessManager address + * @param licenseTermsIds uint256[] */ -export type LicenseRegistryInitializeRequest = { - accessManager: Address; +export type PiLicenseTemplateVerifyCompatibleLicensesRequest = { + licenseTermsIds: readonly bigint[]; }; +export type PiLicenseTemplateVerifyCompatibleLicensesResponse = boolean; + /** - * LicenseRegistryRegisterDerivativeIpRequest + * PiLicenseTemplateInitializeRequest * - * @param childIpId address - * @param parentIpIds address[] - * @param licenseTemplate address - * @param licenseTermsIds uint256[] + * @param accessManager address + * @param name string + * @param metadataURI string */ -export type LicenseRegistryRegisterDerivativeIpRequest = { - childIpId: Address; - parentIpIds: readonly Address[]; - licenseTemplate: Address; - licenseTermsIds: readonly bigint[]; +export type PiLicenseTemplateInitializeRequest = { + accessManager: Address; + name: string; + metadataURI: string; }; /** - * LicenseRegistryRegisterLicenseTemplateRequest + * PiLicenseTemplateRegisterLicenseTermsRequest * - * @param licenseTemplate address + * @param terms tuple */ -export type LicenseRegistryRegisterLicenseTemplateRequest = { - licenseTemplate: Address; +export type PiLicenseTemplateRegisterLicenseTermsRequest = { + terms: { + transferable: boolean; + royaltyPolicy: Address; + mintingFee: bigint; + expiration: bigint; + commercialUse: boolean; + commercialAttribution: boolean; + commercializerChecker: Address; + commercializerCheckerData: Hex; + commercialRevShare: number; + commercialRevCelling: bigint; + derivativesAllowed: boolean; + derivativesAttribution: boolean; + derivativesApproval: boolean; + derivativesReciprocal: boolean; + derivativeRevCelling: bigint; + currency: Address; + uri: string; + }; }; /** - * LicenseRegistrySetAuthorityRequest + * PiLicenseTemplateSetApprovalRequest * - * @param newAuthority address + * @param parentIpId address + * @param licenseTermsId uint256 + * @param childIpId address + * @param approved bool */ -export type LicenseRegistrySetAuthorityRequest = { - newAuthority: Address; +export type PiLicenseTemplateSetApprovalRequest = { + parentIpId: Address; + licenseTermsId: bigint; + childIpId: Address; + approved: boolean; }; /** - * LicenseRegistrySetDefaultLicenseTermsRequest + * PiLicenseTemplateSetAuthorityRequest * - * @param newLicenseTemplate address - * @param newLicenseTermsId uint256 + * @param newAuthority address */ -export type LicenseRegistrySetDefaultLicenseTermsRequest = { - newLicenseTemplate: Address; - newLicenseTermsId: bigint; +export type PiLicenseTemplateSetAuthorityRequest = { + newAuthority: Address; }; /** - * LicenseRegistrySetExpireTimeRequest + * PiLicenseTemplateUpgradeToAndCallRequest * - * @param ipId address - * @param expireTime uint256 + * @param newImplementation address + * @param data bytes */ -export type LicenseRegistrySetExpireTimeRequest = { - ipId: Address; - expireTime: bigint; +export type PiLicenseTemplateUpgradeToAndCallRequest = { + newImplementation: Address; + data: Hex; }; /** - * LicenseRegistrySetLicensingConfigForIpRequest + * PiLicenseTemplateVerifyMintLicenseTokenRequest * - * @param ipId address - * @param licensingConfig tuple + * @param 0 uint256 + * @param 1 address + * @param 2 address + * @param 3 uint256 */ -export type LicenseRegistrySetLicensingConfigForIpRequest = { - ipId: Address; - licensingConfig: { - isSet: boolean; - mintingFee: bigint; - licensingHook: Address; - hookData: Hex; - }; -}; +export type PiLicenseTemplateVerifyMintLicenseTokenRequest = readonly [ + bigint, + Address, + Address, + bigint, +]; /** - * LicenseRegistrySetLicensingConfigForLicenseRequest + * PiLicenseTemplateVerifyRegisterDerivativeRequest * - * @param ipId address - * @param licenseTemplate address + * @param childIpId address + * @param parentIpId address * @param licenseTermsId uint256 - * @param licensingConfig tuple + * @param licensee address */ -export type LicenseRegistrySetLicensingConfigForLicenseRequest = { - ipId: Address; - licenseTemplate: Address; +export type PiLicenseTemplateVerifyRegisterDerivativeRequest = { + childIpId: Address; + parentIpId: Address; licenseTermsId: bigint; - licensingConfig: { - isSet: boolean; - mintingFee: bigint; - licensingHook: Address; - hookData: Hex; - }; + licensee: Address; }; /** - * LicenseRegistryUpgradeToAndCallRequest + * PiLicenseTemplateVerifyRegisterDerivativeForAllParentsRequest * - * @param newImplementation address - * @param data bytes + * @param childIpId address + * @param parentIpIds address[] + * @param licenseTermsIds uint256[] + * @param childIpOwner address */ -export type LicenseRegistryUpgradeToAndCallRequest = { - newImplementation: Address; - data: Hex; +export type PiLicenseTemplateVerifyRegisterDerivativeForAllParentsRequest = { + childIpId: Address; + parentIpIds: readonly Address[]; + licenseTermsIds: readonly bigint[]; + childIpOwner: Address; }; /** - * contract LicenseRegistry event + * contract PILicenseTemplate event */ -export class LicenseRegistryEventClient { +export class PiLicenseTemplateEventClient { protected readonly rpcClient: PublicClient; public readonly address: Address; constructor(rpcClient: PublicClient, address?: Address) { - this.address = address || getAddress(licenseRegistryAddress, rpcClient.chain?.id); + this.address = address || getAddress(piLicenseTemplateAddress, rpcClient.chain?.id); this.rpcClient = rpcClient; } /** - * event AuthorityUpdated for contract LicenseRegistry + * event AuthorityUpdated for contract PILicenseTemplate */ public watchAuthorityUpdatedEvent( - onLogs: (txHash: Hex, ev: Partial) => void, + onLogs: (txHash: Hex, ev: Partial) => void, ): WatchContractEventReturnType { return this.rpcClient.watchContractEvent({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, address: this.address, eventName: "AuthorityUpdated", onLogs: (evs) => { @@ -7486,16 +10394,16 @@ export class LicenseRegistryEventClient { } /** - * parse tx receipt event AuthorityUpdated for contract LicenseRegistry + * parse tx receipt event AuthorityUpdated for contract PILicenseTemplate */ public parseTxAuthorityUpdatedEvent( txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; + ): Array { + const targetLogs: Array = []; for (const log of txReceipt.logs) { try { const event = decodeEventLog({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, eventName: "AuthorityUpdated", data: log.data, topics: log.topics, @@ -7511,97 +10419,15 @@ export class LicenseRegistryEventClient { } /** - * event ExpirationTimeSet for contract LicenseRegistry - */ - public watchExpirationTimeSetEvent( - onLogs: (txHash: Hex, ev: Partial) => void, - ): WatchContractEventReturnType { - return this.rpcClient.watchContractEvent({ - abi: licenseRegistryAbi, - address: this.address, - eventName: "ExpirationTimeSet", - onLogs: (evs) => { - evs.forEach((it) => onLogs(it.transactionHash, it.args)); - }, - }); - } - - /** - * parse tx receipt event ExpirationTimeSet for contract LicenseRegistry - */ - public parseTxExpirationTimeSetEvent( - txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; - for (const log of txReceipt.logs) { - try { - const event = decodeEventLog({ - abi: licenseRegistryAbi, - eventName: "ExpirationTimeSet", - data: log.data, - topics: log.topics, - }); - if (event.eventName === "ExpirationTimeSet") { - targetLogs.push(event.args); - } - } catch (e) { - /* empty */ - } - } - return targetLogs; - } - - /** - * event Initialized for contract LicenseRegistry - */ - public watchInitializedEvent( - onLogs: (txHash: Hex, ev: Partial) => void, - ): WatchContractEventReturnType { - return this.rpcClient.watchContractEvent({ - abi: licenseRegistryAbi, - address: this.address, - eventName: "Initialized", - onLogs: (evs) => { - evs.forEach((it) => onLogs(it.transactionHash, it.args)); - }, - }); - } - - /** - * parse tx receipt event Initialized for contract LicenseRegistry - */ - public parseTxInitializedEvent( - txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; - for (const log of txReceipt.logs) { - try { - const event = decodeEventLog({ - abi: licenseRegistryAbi, - eventName: "Initialized", - data: log.data, - topics: log.topics, - }); - if (event.eventName === "Initialized") { - targetLogs.push(event.args); - } - } catch (e) { - /* empty */ - } - } - return targetLogs; - } - - /** - * event LicenseTemplateRegistered for contract LicenseRegistry + * event DerivativeApproved for contract PILicenseTemplate */ - public watchLicenseTemplateRegisteredEvent( - onLogs: (txHash: Hex, ev: Partial) => void, + public watchDerivativeApprovedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, ): WatchContractEventReturnType { return this.rpcClient.watchContractEvent({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, address: this.address, - eventName: "LicenseTemplateRegistered", + eventName: "DerivativeApproved", onLogs: (evs) => { evs.forEach((it) => onLogs(it.transactionHash, it.args)); }, @@ -7609,21 +10435,21 @@ export class LicenseRegistryEventClient { } /** - * parse tx receipt event LicenseTemplateRegistered for contract LicenseRegistry + * parse tx receipt event DerivativeApproved for contract PILicenseTemplate */ - public parseTxLicenseTemplateRegisteredEvent( + public parseTxDerivativeApprovedEvent( txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; + ): Array { + const targetLogs: Array = []; for (const log of txReceipt.logs) { try { const event = decodeEventLog({ - abi: licenseRegistryAbi, - eventName: "LicenseTemplateRegistered", + abi: piLicenseTemplateAbi, + eventName: "DerivativeApproved", data: log.data, topics: log.topics, }); - if (event.eventName === "LicenseTemplateRegistered") { + if (event.eventName === "DerivativeApproved") { targetLogs.push(event.args); } } catch (e) { @@ -7634,15 +10460,15 @@ export class LicenseRegistryEventClient { } /** - * event LicensingConfigSetForIP for contract LicenseRegistry + * event Initialized for contract PILicenseTemplate */ - public watchLicensingConfigSetForIpEvent( - onLogs: (txHash: Hex, ev: Partial) => void, + public watchInitializedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, ): WatchContractEventReturnType { return this.rpcClient.watchContractEvent({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, address: this.address, - eventName: "LicensingConfigSetForIP", + eventName: "Initialized", onLogs: (evs) => { evs.forEach((it) => onLogs(it.transactionHash, it.args)); }, @@ -7650,21 +10476,21 @@ export class LicenseRegistryEventClient { } /** - * parse tx receipt event LicensingConfigSetForIP for contract LicenseRegistry + * parse tx receipt event Initialized for contract PILicenseTemplate */ - public parseTxLicensingConfigSetForIpEvent( + public parseTxInitializedEvent( txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; + ): Array { + const targetLogs: Array = []; for (const log of txReceipt.logs) { try { const event = decodeEventLog({ - abi: licenseRegistryAbi, - eventName: "LicensingConfigSetForIP", + abi: piLicenseTemplateAbi, + eventName: "Initialized", data: log.data, topics: log.topics, }); - if (event.eventName === "LicensingConfigSetForIP") { + if (event.eventName === "Initialized") { targetLogs.push(event.args); } } catch (e) { @@ -7675,15 +10501,15 @@ export class LicenseRegistryEventClient { } /** - * event LicensingConfigSetForLicense for contract LicenseRegistry + * event LicenseTermsRegistered for contract PILicenseTemplate */ - public watchLicensingConfigSetForLicenseEvent( - onLogs: (txHash: Hex, ev: Partial) => void, + public watchLicenseTermsRegisteredEvent( + onLogs: (txHash: Hex, ev: Partial) => void, ): WatchContractEventReturnType { return this.rpcClient.watchContractEvent({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, address: this.address, - eventName: "LicensingConfigSetForLicense", + eventName: "LicenseTermsRegistered", onLogs: (evs) => { evs.forEach((it) => onLogs(it.transactionHash, it.args)); }, @@ -7691,21 +10517,21 @@ export class LicenseRegistryEventClient { } /** - * parse tx receipt event LicensingConfigSetForLicense for contract LicenseRegistry + * parse tx receipt event LicenseTermsRegistered for contract PILicenseTemplate */ - public parseTxLicensingConfigSetForLicenseEvent( + public parseTxLicenseTermsRegisteredEvent( txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; + ): Array { + const targetLogs: Array = []; for (const log of txReceipt.logs) { try { const event = decodeEventLog({ - abi: licenseRegistryAbi, - eventName: "LicensingConfigSetForLicense", + abi: piLicenseTemplateAbi, + eventName: "LicenseTermsRegistered", data: log.data, topics: log.topics, }); - if (event.eventName === "LicensingConfigSetForLicense") { + if (event.eventName === "LicenseTermsRegistered") { targetLogs.push(event.args); } } catch (e) { @@ -7716,13 +10542,13 @@ export class LicenseRegistryEventClient { } /** - * event Upgraded for contract LicenseRegistry + * event Upgraded for contract PILicenseTemplate */ public watchUpgradedEvent( - onLogs: (txHash: Hex, ev: Partial) => void, + onLogs: (txHash: Hex, ev: Partial) => void, ): WatchContractEventReturnType { return this.rpcClient.watchContractEvent({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, address: this.address, eventName: "Upgraded", onLogs: (evs) => { @@ -7732,14 +10558,16 @@ export class LicenseRegistryEventClient { } /** - * parse tx receipt event Upgraded for contract LicenseRegistry + * parse tx receipt event Upgraded for contract PILicenseTemplate */ - public parseTxUpgradedEvent(txReceipt: TransactionReceipt): Array { - const targetLogs: Array = []; + public parseTxUpgradedEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; for (const log of txReceipt.logs) { try { const event = decodeEventLog({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, eventName: "Upgraded", data: log.data, topics: log.topics, @@ -7756,421 +10584,676 @@ export class LicenseRegistryEventClient { } /** - * contract LicenseRegistry readonly method + * contract PILicenseTemplate readonly method */ -export class LicenseRegistryReadOnlyClient extends LicenseRegistryEventClient { +export class PiLicenseTemplateReadOnlyClient extends PiLicenseTemplateEventClient { constructor(rpcClient: PublicClient, address?: Address) { super(rpcClient, address); } /** - * method DISPUTE_MODULE for contract LicenseRegistry + * method ACCESS_CONTROLLER for contract PILicenseTemplate * - * @param request LicenseRegistryDisputeModuleRequest - * @return Promise + * @param request PiLicenseTemplateAccessControllerRequest + * @return Promise */ - public async disputeModule(): Promise { + public async accessController(): Promise { return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, address: this.address, - functionName: "DISPUTE_MODULE", + functionName: "ACCESS_CONTROLLER", }); } /** - * method EXPIRATION_TIME for contract LicenseRegistry + * method IP_ACCOUNT_REGISTRY for contract PILicenseTemplate * - * @param request LicenseRegistryExpirationTimeRequest - * @return Promise + * @param request PiLicenseTemplateIpAccountRegistryRequest + * @return Promise */ - public async expirationTime(): Promise { + public async ipAccountRegistry(): Promise { return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, + address: this.address, + functionName: "IP_ACCOUNT_REGISTRY", + }); + } + + /** + * method LICENSE_REGISTRY for contract PILicenseTemplate + * + * @param request PiLicenseTemplateLicenseRegistryRequest + * @return Promise + */ + public async licenseRegistry(): Promise { + return await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, + address: this.address, + functionName: "LICENSE_REGISTRY", + }); + } + + /** + * method ROYALTY_MODULE for contract PILicenseTemplate + * + * @param request PiLicenseTemplateRoyaltyModuleRequest + * @return Promise + */ + public async royaltyModule(): Promise { + return await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, + address: this.address, + functionName: "ROYALTY_MODULE", + }); + } + + /** + * method UPGRADE_INTERFACE_VERSION for contract PILicenseTemplate + * + * @param request PiLicenseTemplateUpgradeInterfaceVersionRequest + * @return Promise + */ + public async upgradeInterfaceVersion(): Promise { + return await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, + address: this.address, + functionName: "UPGRADE_INTERFACE_VERSION", + }); + } + + /** + * method authority for contract PILicenseTemplate + * + * @param request PiLicenseTemplateAuthorityRequest + * @return Promise + */ + public async authority(): Promise { + return await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, + address: this.address, + functionName: "authority", + }); + } + + /** + * method exists for contract PILicenseTemplate + * + * @param request PiLicenseTemplateExistsRequest + * @return Promise + */ + public async exists( + request: PiLicenseTemplateExistsRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, + address: this.address, + functionName: "exists", + args: [request.licenseTermsId], + }); + } + + /** + * method getEarlierExpireTime for contract PILicenseTemplate + * + * @param request PiLicenseTemplateGetEarlierExpireTimeRequest + * @return Promise + */ + public async getEarlierExpireTime( + request: PiLicenseTemplateGetEarlierExpireTimeRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, + address: this.address, + functionName: "getEarlierExpireTime", + args: [request.licenseTermsIds, request.start], + }); + } + + /** + * method getExpireTime for contract PILicenseTemplate + * + * @param request PiLicenseTemplateGetExpireTimeRequest + * @return Promise + */ + public async getExpireTime( + request: PiLicenseTemplateGetExpireTimeRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, + address: this.address, + functionName: "getExpireTime", + args: [request.licenseTermsId, request.start], + }); + } + + /** + * method getLicenseTerms for contract PILicenseTemplate + * + * @param request PiLicenseTemplateGetLicenseTermsRequest + * @return Promise + */ + public async getLicenseTerms( + request: PiLicenseTemplateGetLicenseTermsRequest, + ): Promise { + const result = await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, + address: this.address, + functionName: "getLicenseTerms", + args: [request.selectedLicenseTermsId], + }); + return { + terms: result, + }; + } + + /** + * method getLicenseTermsId for contract PILicenseTemplate + * + * @param request PiLicenseTemplateGetLicenseTermsIdRequest + * @return Promise + */ + public async getLicenseTermsId( + request: PiLicenseTemplateGetLicenseTermsIdRequest, + ): Promise { + const result = await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "EXPIRATION_TIME", + functionName: "getLicenseTermsId", + args: [request.terms], }); + return { + selectedLicenseTermsId: result, + }; } /** - * method LICENSING_MODULE for contract LicenseRegistry + * method getLicenseTermsURI for contract PILicenseTemplate * - * @param request LicenseRegistryLicensingModuleRequest - * @return Promise + * @param request PiLicenseTemplateGetLicenseTermsUriRequest + * @return Promise */ - public async licensingModule(): Promise { + public async getLicenseTermsUri( + request: PiLicenseTemplateGetLicenseTermsUriRequest, + ): Promise { return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, address: this.address, - functionName: "LICENSING_MODULE", + functionName: "getLicenseTermsURI", + args: [request.licenseTermsId], }); } /** - * method UPGRADE_INTERFACE_VERSION for contract LicenseRegistry + * method getMetadataURI for contract PILicenseTemplate * - * @param request LicenseRegistryUpgradeInterfaceVersionRequest - * @return Promise + * @param request PiLicenseTemplateGetMetadataUriRequest + * @return Promise */ - public async upgradeInterfaceVersion(): Promise { + public async getMetadataUri(): Promise { return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, address: this.address, - functionName: "UPGRADE_INTERFACE_VERSION", + functionName: "getMetadataURI", }); } /** - * method authority for contract LicenseRegistry + * method getRoyaltyPolicy for contract PILicenseTemplate * - * @param request LicenseRegistryAuthorityRequest - * @return Promise + * @param request PiLicenseTemplateGetRoyaltyPolicyRequest + * @return Promise */ - public async authority(): Promise { - return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async getRoyaltyPolicy( + request: PiLicenseTemplateGetRoyaltyPolicyRequest, + ): Promise { + const result = await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "authority", + functionName: "getRoyaltyPolicy", + args: [request.licenseTermsId], }); + return { + royaltyPolicy: result[0], + royaltyData: result[1], + mintingFee: result[2], + currency: result[3], + }; } /** - * method exists for contract LicenseRegistry + * method isConsumingScheduledOp for contract PILicenseTemplate * - * @param request LicenseRegistryExistsRequest - * @return Promise + * @param request PiLicenseTemplateIsConsumingScheduledOpRequest + * @return Promise */ - public async exists( - request: LicenseRegistryExistsRequest, - ): Promise { + public async isConsumingScheduledOp(): Promise { return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, address: this.address, - functionName: "exists", - args: [request.licenseTemplate, request.licenseTermsId], + functionName: "isConsumingScheduledOp", }); } /** - * method getAttachedLicenseTerms for contract LicenseRegistry + * method isDerivativeApproved for contract PILicenseTemplate * - * @param request LicenseRegistryGetAttachedLicenseTermsRequest - * @return Promise + * @param request PiLicenseTemplateIsDerivativeApprovedRequest + * @return Promise */ - public async getAttachedLicenseTerms( - request: LicenseRegistryGetAttachedLicenseTermsRequest, - ): Promise { - const result = await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async isDerivativeApproved( + request: PiLicenseTemplateIsDerivativeApprovedRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "getAttachedLicenseTerms", - args: [request.ipId, request.index], + functionName: "isDerivativeApproved", + args: [request.parentIpId, request.licenseTermsId, request.childIpId], }); - return { - licenseTemplate: result[0], - licenseTermsId: result[1], - }; } /** - * method getAttachedLicenseTermsCount for contract LicenseRegistry + * method isLicenseTransferable for contract PILicenseTemplate * - * @param request LicenseRegistryGetAttachedLicenseTermsCountRequest - * @return Promise + * @param request PiLicenseTemplateIsLicenseTransferableRequest + * @return Promise */ - public async getAttachedLicenseTermsCount( - request: LicenseRegistryGetAttachedLicenseTermsCountRequest, - ): Promise { + public async isLicenseTransferable( + request: PiLicenseTemplateIsLicenseTransferableRequest, + ): Promise { return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, address: this.address, - functionName: "getAttachedLicenseTermsCount", - args: [request.ipId], + functionName: "isLicenseTransferable", + args: [request.licenseTermsId], }); } /** - * method getDefaultLicenseTerms for contract LicenseRegistry + * method name for contract PILicenseTemplate * - * @param request LicenseRegistryGetDefaultLicenseTermsRequest - * @return Promise + * @param request PiLicenseTemplateNameRequest + * @return Promise */ - public async getDefaultLicenseTerms(): Promise { - const result = await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async name(): Promise { + return await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "getDefaultLicenseTerms", + functionName: "name", }); - return { - licenseTemplate: result[0], - licenseTermsId: result[1], - }; } /** - * method getDerivativeIp for contract LicenseRegistry + * method proxiableUUID for contract PILicenseTemplate * - * @param request LicenseRegistryGetDerivativeIpRequest - * @return Promise + * @param request PiLicenseTemplateProxiableUuidRequest + * @return Promise */ - public async getDerivativeIp( - request: LicenseRegistryGetDerivativeIpRequest, - ): Promise { - const result = await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async proxiableUuid(): Promise { + return await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "getDerivativeIp", - args: [request.parentIpId, request.index], + functionName: "proxiableUUID", }); - return { - childIpId: result, - }; } /** - * method getDerivativeIpCount for contract LicenseRegistry + * method supportsInterface for contract PILicenseTemplate * - * @param request LicenseRegistryGetDerivativeIpCountRequest - * @return Promise + * @param request PiLicenseTemplateSupportsInterfaceRequest + * @return Promise */ - public async getDerivativeIpCount( - request: LicenseRegistryGetDerivativeIpCountRequest, - ): Promise { + public async supportsInterface( + request: PiLicenseTemplateSupportsInterfaceRequest, + ): Promise { return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, address: this.address, - functionName: "getDerivativeIpCount", - args: [request.parentIpId], + functionName: "supportsInterface", + args: [request.interfaceId], }); } /** - * method getExpireTime for contract LicenseRegistry + * method toJson for contract PILicenseTemplate * - * @param request LicenseRegistryGetExpireTimeRequest - * @return Promise + * @param request PiLicenseTemplateToJsonRequest + * @return Promise */ - public async getExpireTime( - request: LicenseRegistryGetExpireTimeRequest, - ): Promise { + public async toJson( + request: PiLicenseTemplateToJsonRequest, + ): Promise { return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, address: this.address, - functionName: "getExpireTime", - args: [request.ipId], + functionName: "toJson", + args: [request.licenseTermsId], }); } /** - * method getLicensingConfig for contract LicenseRegistry + * method totalRegisteredLicenseTerms for contract PILicenseTemplate * - * @param request LicenseRegistryGetLicensingConfigRequest - * @return Promise + * @param request PiLicenseTemplateTotalRegisteredLicenseTermsRequest + * @return Promise */ - public async getLicensingConfig( - request: LicenseRegistryGetLicensingConfigRequest, - ): Promise { + public async totalRegisteredLicenseTerms(): Promise { return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + abi: piLicenseTemplateAbi, address: this.address, - functionName: "getLicensingConfig", - args: [request.ipId, request.licenseTemplate, request.licenseTermsId], + functionName: "totalRegisteredLicenseTerms", }); } /** - * method getParentIp for contract LicenseRegistry + * method verifyCompatibleLicenses for contract PILicenseTemplate * - * @param request LicenseRegistryGetParentIpRequest - * @return Promise + * @param request PiLicenseTemplateVerifyCompatibleLicensesRequest + * @return Promise */ - public async getParentIp( - request: LicenseRegistryGetParentIpRequest, - ): Promise { - const result = await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async verifyCompatibleLicenses( + request: PiLicenseTemplateVerifyCompatibleLicensesRequest, + ): Promise { + return await this.rpcClient.readContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "getParentIp", - args: [request.childIpId, request.index], + functionName: "verifyCompatibleLicenses", + args: [request.licenseTermsIds], }); - return { - parentIpId: result, - }; + } +} + +/** + * contract PILicenseTemplate write method + */ +export class PiLicenseTemplateClient extends PiLicenseTemplateReadOnlyClient { + protected readonly wallet: SimpleWalletClient; + + constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { + super(rpcClient, address); + this.wallet = wallet; } /** - * method getParentIpCount for contract LicenseRegistry + * method initialize for contract PILicenseTemplate * - * @param request LicenseRegistryGetParentIpCountRequest - * @return Promise + * @param request PiLicenseTemplateInitializeRequest + * @return Promise */ - public async getParentIpCount( - request: LicenseRegistryGetParentIpCountRequest, - ): Promise { - return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async initialize( + request: PiLicenseTemplateInitializeRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "getParentIpCount", - args: [request.childIpId], + functionName: "initialize", + account: this.wallet.account, + args: [request.accessManager, request.name, request.metadataURI], }); + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method hasDerivativeIps for contract LicenseRegistry + * method registerLicenseTerms for contract PILicenseTemplate * - * @param request LicenseRegistryHasDerivativeIpsRequest - * @return Promise + * @param request PiLicenseTemplateRegisterLicenseTermsRequest + * @return Promise */ - public async hasDerivativeIps( - request: LicenseRegistryHasDerivativeIpsRequest, - ): Promise { - return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async registerLicenseTerms( + request: PiLicenseTemplateRegisterLicenseTermsRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "hasDerivativeIps", - args: [request.parentIpId], + functionName: "registerLicenseTerms", + account: this.wallet.account, + args: [request.terms], }); + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method hasIpAttachedLicenseTerms for contract LicenseRegistry + * method setApproval for contract PILicenseTemplate * - * @param request LicenseRegistryHasIpAttachedLicenseTermsRequest - * @return Promise + * @param request PiLicenseTemplateSetApprovalRequest + * @return Promise */ - public async hasIpAttachedLicenseTerms( - request: LicenseRegistryHasIpAttachedLicenseTermsRequest, - ): Promise { - return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async setApproval( + request: PiLicenseTemplateSetApprovalRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "hasIpAttachedLicenseTerms", - args: [request.ipId, request.licenseTemplate, request.licenseTermsId], + functionName: "setApproval", + account: this.wallet.account, + args: [request.parentIpId, request.licenseTermsId, request.childIpId, request.approved], }); + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method isConsumingScheduledOp for contract LicenseRegistry + * method setAuthority for contract PILicenseTemplate * - * @param request LicenseRegistryIsConsumingScheduledOpRequest - * @return Promise + * @param request PiLicenseTemplateSetAuthorityRequest + * @return Promise */ - public async isConsumingScheduledOp(): Promise { - return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async setAuthority( + request: PiLicenseTemplateSetAuthorityRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "isConsumingScheduledOp", + functionName: "setAuthority", + account: this.wallet.account, + args: [request.newAuthority], }); + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method isDerivativeIp for contract LicenseRegistry + * method upgradeToAndCall for contract PILicenseTemplate * - * @param request LicenseRegistryIsDerivativeIpRequest - * @return Promise + * @param request PiLicenseTemplateUpgradeToAndCallRequest + * @return Promise */ - public async isDerivativeIp( - request: LicenseRegistryIsDerivativeIpRequest, - ): Promise { - return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async upgradeToAndCall( + request: PiLicenseTemplateUpgradeToAndCallRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "isDerivativeIp", - args: [request.childIpId], + functionName: "upgradeToAndCall", + account: this.wallet.account, + args: [request.newImplementation, request.data], }); + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method isExpiredNow for contract LicenseRegistry + * method verifyMintLicenseToken for contract PILicenseTemplate * - * @param request LicenseRegistryIsExpiredNowRequest - * @return Promise + * @param request PiLicenseTemplateVerifyMintLicenseTokenRequest + * @return Promise */ - public async isExpiredNow( - request: LicenseRegistryIsExpiredNowRequest, - ): Promise { - return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async verifyMintLicenseToken( + request: PiLicenseTemplateVerifyMintLicenseTokenRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "isExpiredNow", - args: [request.ipId], + functionName: "verifyMintLicenseToken", + account: this.wallet.account, + args: [request[0], request[1], request[2], request[3]], }); + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method isParentIp for contract LicenseRegistry + * method verifyRegisterDerivative for contract PILicenseTemplate * - * @param request LicenseRegistryIsParentIpRequest - * @return Promise + * @param request PiLicenseTemplateVerifyRegisterDerivativeRequest + * @return Promise */ - public async isParentIp( - request: LicenseRegistryIsParentIpRequest, - ): Promise { - return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async verifyRegisterDerivative( + request: PiLicenseTemplateVerifyRegisterDerivativeRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "isParentIp", - args: [request.parentIpId, request.childIpId], + functionName: "verifyRegisterDerivative", + account: this.wallet.account, + args: [request.childIpId, request.parentIpId, request.licenseTermsId, request.licensee], }); + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method isRegisteredLicenseTemplate for contract LicenseRegistry + * method verifyRegisterDerivativeForAllParents for contract PILicenseTemplate * - * @param request LicenseRegistryIsRegisteredLicenseTemplateRequest - * @return Promise + * @param request PiLicenseTemplateVerifyRegisterDerivativeForAllParentsRequest + * @return Promise */ - public async isRegisteredLicenseTemplate( - request: LicenseRegistryIsRegisteredLicenseTemplateRequest, - ): Promise { - return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async verifyRegisterDerivativeForAllParents( + request: PiLicenseTemplateVerifyRegisterDerivativeForAllParentsRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: piLicenseTemplateAbi, address: this.address, - functionName: "isRegisteredLicenseTemplate", - args: [request.licenseTemplate], + functionName: "verifyRegisterDerivativeForAllParents", + account: this.wallet.account, + args: [request.childIpId, request.parentIpIds, request.licenseTermsIds, request.childIpOwner], }); + return await this.wallet.writeContract(call as WriteContractParameters); + } +} + +// Contract RoyaltyModule ============================================================= + +/** + * RoyaltyModulePayRoyaltyOnBehalfRequest + * + * @param receiverIpId address + * @param payerIpId address + * @param token address + * @param amount uint256 + */ +export type RoyaltyModulePayRoyaltyOnBehalfRequest = { + receiverIpId: Address; + payerIpId: Address; + token: Address; + amount: bigint; +}; + +/** + * contract RoyaltyModule write method + */ +export class RoyaltyModuleClient { + protected readonly wallet: SimpleWalletClient; + protected readonly rpcClient: PublicClient; + public readonly address: Address; + + constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { + this.address = address || getAddress(royaltyModuleAddress, rpcClient.chain?.id); + this.rpcClient = rpcClient; + this.wallet = wallet; } /** - * method proxiableUUID for contract LicenseRegistry + * method payRoyaltyOnBehalf for contract RoyaltyModule * - * @param request LicenseRegistryProxiableUuidRequest - * @return Promise + * @param request RoyaltyModulePayRoyaltyOnBehalfRequest + * @return Promise */ - public async proxiableUuid(): Promise { - return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + public async payRoyaltyOnBehalf( + request: RoyaltyModulePayRoyaltyOnBehalfRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: royaltyModuleAbi, address: this.address, - functionName: "proxiableUUID", + functionName: "payRoyaltyOnBehalf", + account: this.wallet.account, + args: [request.receiverIpId, request.payerIpId, request.token, request.amount], }); + return await this.wallet.writeContract(call as WriteContractParameters); + } +} + +// Contract RoyaltyPolicyLAP ============================================================= + +/** + * RoyaltyPolicyLapGetRoyaltyDataRequest + * + * @param ipId address + */ +export type RoyaltyPolicyLapGetRoyaltyDataRequest = { + ipId: Address; +}; + +/** + * RoyaltyPolicyLapGetRoyaltyDataResponse + * + * @param 0 bool + * @param 1 address + * @param 2 uint32 + * @param 3 address[] + * @param 4 uint32[] + */ +export type RoyaltyPolicyLapGetRoyaltyDataResponse = readonly [ + boolean, + Address, + number, + readonly Address[], + readonly number[], +]; + +/** + * RoyaltyPolicyLapOnRoyaltyPaymentRequest + * + * @param caller address + * @param ipId address + * @param token address + * @param amount uint256 + */ +export type RoyaltyPolicyLapOnRoyaltyPaymentRequest = { + caller: Address; + ipId: Address; + token: Address; + amount: bigint; +}; + +/** + * contract RoyaltyPolicyLAP readonly method + */ +export class RoyaltyPolicyLapReadOnlyClient { + protected readonly rpcClient: PublicClient; + public readonly address: Address; + + constructor(rpcClient: PublicClient, address?: Address) { + this.address = address || getAddress(royaltyPolicyLapAddress, rpcClient.chain?.id); + this.rpcClient = rpcClient; } /** - * method verifyMintLicenseToken for contract LicenseRegistry + * method getRoyaltyData for contract RoyaltyPolicyLAP * - * @param request LicenseRegistryVerifyMintLicenseTokenRequest - * @return Promise + * @param request RoyaltyPolicyLapGetRoyaltyDataRequest + * @return Promise */ - public async verifyMintLicenseToken( - request: LicenseRegistryVerifyMintLicenseTokenRequest, - ): Promise { + public async getRoyaltyData( + request: RoyaltyPolicyLapGetRoyaltyDataRequest, + ): Promise { return await this.rpcClient.readContract({ - abi: licenseRegistryAbi, + abi: royaltyPolicyLapAbi, address: this.address, - functionName: "verifyMintLicenseToken", - args: [ - request.licensorIpId, - request.licenseTemplate, - request.licenseTermsId, - request.isMintedByIpOwner, - ], + functionName: "getRoyaltyData", + args: [request.ipId], }); } } /** - * contract LicenseRegistry write method + * contract RoyaltyPolicyLAP write method */ -export class LicenseRegistryClient extends LicenseRegistryReadOnlyClient { +export class RoyaltyPolicyLapClient extends RoyaltyPolicyLapReadOnlyClient { protected readonly wallet: SimpleWalletClient; constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { @@ -8179,354 +11262,639 @@ export class LicenseRegistryClient extends LicenseRegistryReadOnlyClient { } /** - * method attachLicenseTermsToIp for contract LicenseRegistry + * method onRoyaltyPayment for contract RoyaltyPolicyLAP * - * @param request LicenseRegistryAttachLicenseTermsToIpRequest + * @param request RoyaltyPolicyLapOnRoyaltyPaymentRequest * @return Promise */ - public async attachLicenseTermsToIp( - request: LicenseRegistryAttachLicenseTermsToIpRequest, + public async onRoyaltyPayment( + request: RoyaltyPolicyLapOnRoyaltyPaymentRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: licenseRegistryAbi, + abi: royaltyPolicyLapAbi, address: this.address, - functionName: "attachLicenseTermsToIp", + functionName: "onRoyaltyPayment", account: this.wallet.account, - args: [request.ipId, request.licenseTemplate, request.licenseTermsId], + args: [request.caller, request.ipId, request.token, request.amount], }); return await this.wallet.writeContract(call as WriteContractParameters); } +} + +// Contract SPG ============================================================= + +/** + * SpgCollectionCreatedEvent + * + * @param nftContract address + */ +export type SpgCollectionCreatedEvent = { + nftContract: Address; +}; + +/** + * SpgCreateCollectionRequest + * + * @param name string + * @param symbol string + * @param maxSupply uint32 + * @param mintCost uint256 + * @param mintToken address + * @param owner address + */ +export type SpgCreateCollectionRequest = { + name: string; + symbol: string; + maxSupply: number; + mintCost: bigint; + mintToken: Address; + owner: Address; +}; + +/** + * SpgMintAndRegisterIpRequest + * + * @param nftContract address + * @param recipient address + * @param metadata tuple + */ +export type SpgMintAndRegisterIpRequest = { + nftContract: Address; + recipient: Address; + metadata: { + metadataURI: string; + metadataHash: Hex; + nftMetadataHash: Hex; + }; +}; + +/** + * SpgMintAndRegisterIpAndAttachPilTermsRequest + * + * @param nftContract address + * @param recipient address + * @param metadata tuple + * @param terms tuple + */ +export type SpgMintAndRegisterIpAndAttachPilTermsRequest = { + nftContract: Address; + recipient: Address; + metadata: { + metadataURI: string; + metadataHash: Hex; + nftMetadataHash: Hex; + }; + terms: { + transferable: boolean; + royaltyPolicy: Address; + mintingFee: bigint; + expiration: bigint; + commercialUse: boolean; + commercialAttribution: boolean; + commercializerChecker: Address; + commercializerCheckerData: Hex; + commercialRevShare: number; + commercialRevCelling: bigint; + derivativesAllowed: boolean; + derivativesAttribution: boolean; + derivativesApproval: boolean; + derivativesReciprocal: boolean; + derivativeRevCelling: bigint; + currency: Address; + uri: string; + }; +}; + +/** + * SpgMintAndRegisterIpAndMakeDerivativeRequest + * + * @param nftContract address + * @param derivData tuple + * @param metadata tuple + * @param recipient address + */ +export type SpgMintAndRegisterIpAndMakeDerivativeRequest = { + nftContract: Address; + derivData: { + parentIpIds: readonly Address[]; + licenseTemplate: Address; + licenseTermsIds: readonly bigint[]; + royaltyContext: Hex; + }; + metadata: { + metadataURI: string; + metadataHash: Hex; + nftMetadataHash: Hex; + }; + recipient: Address; +}; + +/** + * SpgMintAndRegisterIpAndMakeDerivativeWithLicenseTokensRequest + * + * @param nftContract address + * @param licenseTokenIds uint256[] + * @param royaltyContext bytes + * @param metadata tuple + * @param recipient address + */ +export type SpgMintAndRegisterIpAndMakeDerivativeWithLicenseTokensRequest = { + nftContract: Address; + licenseTokenIds: readonly bigint[]; + royaltyContext: Hex; + metadata: { + metadataURI: string; + metadataHash: Hex; + nftMetadataHash: Hex; + }; + recipient: Address; +}; + +/** + * SpgRegisterIpAndAttachPilTermsRequest + * + * @param nftContract address + * @param tokenId uint256 + * @param metadata tuple + * @param terms tuple + * @param sigMetadata tuple + * @param sigAttach tuple + */ +export type SpgRegisterIpAndAttachPilTermsRequest = { + nftContract: Address; + tokenId: bigint; + metadata: { + metadataURI: string; + metadataHash: Hex; + nftMetadataHash: Hex; + }; + terms: { + transferable: boolean; + royaltyPolicy: Address; + mintingFee: bigint; + expiration: bigint; + commercialUse: boolean; + commercialAttribution: boolean; + commercializerChecker: Address; + commercializerCheckerData: Hex; + commercialRevShare: number; + commercialRevCelling: bigint; + derivativesAllowed: boolean; + derivativesAttribution: boolean; + derivativesApproval: boolean; + derivativesReciprocal: boolean; + derivativeRevCelling: bigint; + currency: Address; + uri: string; + }; + sigMetadata: { + signer: Address; + deadline: bigint; + signature: Hex; + }; + sigAttach: { + signer: Address; + deadline: bigint; + signature: Hex; + }; +}; + +/** + * SpgRegisterIpAndMakeDerivativeRequest + * + * @param nftContract address + * @param tokenId uint256 + * @param derivData tuple + * @param metadata tuple + * @param sigMetadata tuple + * @param sigRegister tuple + */ +export type SpgRegisterIpAndMakeDerivativeRequest = { + nftContract: Address; + tokenId: bigint; + derivData: { + parentIpIds: readonly Address[]; + licenseTemplate: Address; + licenseTermsIds: readonly bigint[]; + royaltyContext: Hex; + }; + metadata: { + metadataURI: string; + metadataHash: Hex; + nftMetadataHash: Hex; + }; + sigMetadata: { + signer: Address; + deadline: bigint; + signature: Hex; + }; + sigRegister: { + signer: Address; + deadline: bigint; + signature: Hex; + }; +}; + +/** + * SpgRegisterIpAndMakeDerivativeWithLicenseTokensRequest + * + * @param nftContract address + * @param tokenId uint256 + * @param licenseTokenIds uint256[] + * @param royaltyContext bytes + * @param metadata tuple + * @param sigMetadata tuple + * @param sigRegister tuple + */ +export type SpgRegisterIpAndMakeDerivativeWithLicenseTokensRequest = { + nftContract: Address; + tokenId: bigint; + licenseTokenIds: readonly bigint[]; + royaltyContext: Hex; + metadata: { + metadataURI: string; + metadataHash: Hex; + nftMetadataHash: Hex; + }; + sigMetadata: { + signer: Address; + deadline: bigint; + signature: Hex; + }; + sigRegister: { + signer: Address; + deadline: bigint; + signature: Hex; + }; +}; + +/** + * SpgRegisterPilTermsAndAttachRequest + * + * @param ipId address + * @param terms tuple + */ +export type SpgRegisterPilTermsAndAttachRequest = { + ipId: Address; + terms: { + transferable: boolean; + royaltyPolicy: Address; + mintingFee: bigint; + expiration: bigint; + commercialUse: boolean; + commercialAttribution: boolean; + commercializerChecker: Address; + commercializerCheckerData: Hex; + commercialRevShare: number; + commercialRevCelling: bigint; + derivativesAllowed: boolean; + derivativesAttribution: boolean; + derivativesApproval: boolean; + derivativesReciprocal: boolean; + derivativeRevCelling: bigint; + currency: Address; + uri: string; + }; +}; + +/** + * contract SPG event + */ +export class SpgEventClient { + protected readonly rpcClient: PublicClient; + public readonly address: Address; + + constructor(rpcClient: PublicClient, address?: Address) { + this.address = address || getAddress(spgAddress, rpcClient.chain?.id); + this.rpcClient = rpcClient; + } /** - * method initialize for contract LicenseRegistry - * - * @param request LicenseRegistryInitializeRequest - * @return Promise + * event CollectionCreated for contract SPG */ - public async initialize( - request: LicenseRegistryInitializeRequest, - ): Promise { - const { request: call } = await this.rpcClient.simulateContract({ - abi: licenseRegistryAbi, + public watchCollectionCreatedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: spgAbi, address: this.address, - functionName: "initialize", - account: this.wallet.account, - args: [request.accessManager], + eventName: "CollectionCreated", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, }); - return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method registerDerivativeIp for contract LicenseRegistry + * parse tx receipt event CollectionCreated for contract SPG + */ + public parseTxCollectionCreatedEvent( + txReceipt: TransactionReceipt, + ): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: spgAbi, + eventName: "CollectionCreated", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "CollectionCreated") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } +} + +/** + * contract SPG write method + */ +export class SpgClient extends SpgEventClient { + protected readonly wallet: SimpleWalletClient; + + constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { + super(rpcClient, address); + this.wallet = wallet; + } + + /** + * method createCollection for contract SPG * - * @param request LicenseRegistryRegisterDerivativeIpRequest + * @param request SpgCreateCollectionRequest * @return Promise */ - public async registerDerivativeIp( - request: LicenseRegistryRegisterDerivativeIpRequest, + public async createCollection( + request: SpgCreateCollectionRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: licenseRegistryAbi, + abi: spgAbi, address: this.address, - functionName: "registerDerivativeIp", + functionName: "createCollection", account: this.wallet.account, - args: [ - request.childIpId, - request.parentIpIds, - request.licenseTemplate, - request.licenseTermsIds, + args: [ + request.name, + request.symbol, + request.maxSupply, + request.mintCost, + request.mintToken, + request.owner, ], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method registerLicenseTemplate for contract LicenseRegistry + * method mintAndRegisterIp for contract SPG * - * @param request LicenseRegistryRegisterLicenseTemplateRequest + * @param request SpgMintAndRegisterIpRequest * @return Promise */ - public async registerLicenseTemplate( - request: LicenseRegistryRegisterLicenseTemplateRequest, + public async mintAndRegisterIp( + request: SpgMintAndRegisterIpRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: licenseRegistryAbi, + abi: spgAbi, address: this.address, - functionName: "registerLicenseTemplate", + functionName: "mintAndRegisterIp", account: this.wallet.account, - args: [request.licenseTemplate], + args: [request.nftContract, request.recipient, request.metadata], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method setAuthority for contract LicenseRegistry + * method mintAndRegisterIpAndAttachPILTerms for contract SPG * - * @param request LicenseRegistrySetAuthorityRequest + * @param request SpgMintAndRegisterIpAndAttachPilTermsRequest * @return Promise */ - public async setAuthority( - request: LicenseRegistrySetAuthorityRequest, + public async mintAndRegisterIpAndAttachPilTerms( + request: SpgMintAndRegisterIpAndAttachPilTermsRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: licenseRegistryAbi, + abi: spgAbi, address: this.address, - functionName: "setAuthority", + functionName: "mintAndRegisterIpAndAttachPILTerms", account: this.wallet.account, - args: [request.newAuthority], + args: [request.nftContract, request.recipient, request.metadata, request.terms], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method setDefaultLicenseTerms for contract LicenseRegistry + * method mintAndRegisterIpAndMakeDerivative for contract SPG * - * @param request LicenseRegistrySetDefaultLicenseTermsRequest + * @param request SpgMintAndRegisterIpAndMakeDerivativeRequest * @return Promise */ - public async setDefaultLicenseTerms( - request: LicenseRegistrySetDefaultLicenseTermsRequest, + public async mintAndRegisterIpAndMakeDerivative( + request: SpgMintAndRegisterIpAndMakeDerivativeRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: licenseRegistryAbi, + abi: spgAbi, address: this.address, - functionName: "setDefaultLicenseTerms", + functionName: "mintAndRegisterIpAndMakeDerivative", account: this.wallet.account, - args: [request.newLicenseTemplate, request.newLicenseTermsId], + args: [request.nftContract, request.derivData, request.metadata, request.recipient], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method setExpireTime for contract LicenseRegistry + * method mintAndRegisterIpAndMakeDerivativeWithLicenseTokens for contract SPG * - * @param request LicenseRegistrySetExpireTimeRequest + * @param request SpgMintAndRegisterIpAndMakeDerivativeWithLicenseTokensRequest * @return Promise */ - public async setExpireTime( - request: LicenseRegistrySetExpireTimeRequest, + public async mintAndRegisterIpAndMakeDerivativeWithLicenseTokens( + request: SpgMintAndRegisterIpAndMakeDerivativeWithLicenseTokensRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: licenseRegistryAbi, + abi: spgAbi, address: this.address, - functionName: "setExpireTime", + functionName: "mintAndRegisterIpAndMakeDerivativeWithLicenseTokens", account: this.wallet.account, - args: [request.ipId, request.expireTime], + args: [ + request.nftContract, + request.licenseTokenIds, + request.royaltyContext, + request.metadata, + request.recipient, + ], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method setLicensingConfigForIp for contract LicenseRegistry + * method registerIpAndAttachPILTerms for contract SPG * - * @param request LicenseRegistrySetLicensingConfigForIpRequest + * @param request SpgRegisterIpAndAttachPilTermsRequest * @return Promise */ - public async setLicensingConfigForIp( - request: LicenseRegistrySetLicensingConfigForIpRequest, + public async registerIpAndAttachPilTerms( + request: SpgRegisterIpAndAttachPilTermsRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: licenseRegistryAbi, + abi: spgAbi, address: this.address, - functionName: "setLicensingConfigForIp", + functionName: "registerIpAndAttachPILTerms", account: this.wallet.account, - args: [request.ipId, request.licensingConfig], + args: [ + request.nftContract, + request.tokenId, + request.metadata, + request.terms, + request.sigMetadata, + request.sigAttach, + ], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method setLicensingConfigForLicense for contract LicenseRegistry + * method registerIpAndMakeDerivative for contract SPG * - * @param request LicenseRegistrySetLicensingConfigForLicenseRequest + * @param request SpgRegisterIpAndMakeDerivativeRequest * @return Promise */ - public async setLicensingConfigForLicense( - request: LicenseRegistrySetLicensingConfigForLicenseRequest, + public async registerIpAndMakeDerivative( + request: SpgRegisterIpAndMakeDerivativeRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: licenseRegistryAbi, + abi: spgAbi, address: this.address, - functionName: "setLicensingConfigForLicense", + functionName: "registerIpAndMakeDerivative", account: this.wallet.account, args: [ - request.ipId, - request.licenseTemplate, - request.licenseTermsId, - request.licensingConfig, + request.nftContract, + request.tokenId, + request.derivData, + request.metadata, + request.sigMetadata, + request.sigRegister, ], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method upgradeToAndCall for contract LicenseRegistry + * method registerIpAndMakeDerivativeWithLicenseTokens for contract SPG * - * @param request LicenseRegistryUpgradeToAndCallRequest + * @param request SpgRegisterIpAndMakeDerivativeWithLicenseTokensRequest * @return Promise */ - public async upgradeToAndCall( - request: LicenseRegistryUpgradeToAndCallRequest, + public async registerIpAndMakeDerivativeWithLicenseTokens( + request: SpgRegisterIpAndMakeDerivativeWithLicenseTokensRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: licenseRegistryAbi, + abi: spgAbi, address: this.address, - functionName: "upgradeToAndCall", + functionName: "registerIpAndMakeDerivativeWithLicenseTokens", account: this.wallet.account, - args: [request.newImplementation, request.data], + args: [ + request.nftContract, + request.tokenId, + request.licenseTokenIds, + request.royaltyContext, + request.metadata, + request.sigMetadata, + request.sigRegister, + ], }); return await this.wallet.writeContract(call as WriteContractParameters); } -} - -// Contract LicenseToken ============================================================= - -/** - * LicenseTokenOwnerOfRequest - * - * @param tokenId uint256 - */ -export type LicenseTokenOwnerOfRequest = { - tokenId: bigint; -}; - -export type LicenseTokenOwnerOfResponse = Address; - -/** - * contract LicenseToken readonly method - */ -export class LicenseTokenReadOnlyClient { - protected readonly rpcClient: PublicClient; - public readonly address: Address; - - constructor(rpcClient: PublicClient, address?: Address) { - this.address = address || getAddress(licenseTokenAddress, rpcClient.chain?.id); - this.rpcClient = rpcClient; - } /** - * method ownerOf for contract LicenseToken + * method registerPILTermsAndAttach for contract SPG * - * @param request LicenseTokenOwnerOfRequest - * @return Promise + * @param request SpgRegisterPilTermsAndAttachRequest + * @return Promise */ - public async ownerOf(request: LicenseTokenOwnerOfRequest): Promise { - return await this.rpcClient.readContract({ - abi: licenseTokenAbi, + public async registerPilTermsAndAttach( + request: SpgRegisterPilTermsAndAttachRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: spgAbi, address: this.address, - functionName: "ownerOf", - args: [request.tokenId], + functionName: "registerPILTermsAndAttach", + account: this.wallet.account, + args: [request.ipId, request.terms], }); + return await this.wallet.writeContract(call as WriteContractParameters); } } -// Contract LicensingModule ============================================================= +// Contract SPGNFTBeacon ============================================================= /** - * LicensingModuleLicenseTokensMintedEvent + * SpgnftBeaconOwnershipTransferredEvent * - * @param caller address - * @param licensorIpId address - * @param licenseTemplate address - * @param licenseTermsId uint256 - * @param amount uint256 - * @param receiver address - * @param startLicenseTokenId uint256 + * @param previousOwner address + * @param newOwner address */ -export type LicensingModuleLicenseTokensMintedEvent = { - caller: Address; - licensorIpId: Address; - licenseTemplate: Address; - licenseTermsId: bigint; - amount: bigint; - receiver: Address; - startLicenseTokenId: bigint; +export type SpgnftBeaconOwnershipTransferredEvent = { + previousOwner: Address; + newOwner: Address; }; /** - * LicensingModuleAttachLicenseTermsRequest + * SpgnftBeaconUpgradedEvent * - * @param ipId address - * @param licenseTemplate address - * @param licenseTermsId uint256 + * @param implementation address */ -export type LicensingModuleAttachLicenseTermsRequest = { - ipId: Address; - licenseTemplate: Address; - licenseTermsId: bigint; +export type SpgnftBeaconUpgradedEvent = { + implementation: Address; }; -/** - * LicensingModuleMintLicenseTokensRequest - * - * @param licensorIpId address - * @param licenseTemplate address - * @param licenseTermsId uint256 - * @param amount uint256 - * @param receiver address - * @param royaltyContext bytes - */ -export type LicensingModuleMintLicenseTokensRequest = { - licensorIpId: Address; - licenseTemplate: Address; - licenseTermsId: bigint; - amount: bigint; - receiver: Address; - royaltyContext: Hex; -}; +export type SpgnftBeaconImplementationResponse = Address; + +export type SpgnftBeaconOwnerResponse = Address; /** - * LicensingModuleRegisterDerivativeRequest + * SpgnftBeaconTransferOwnershipRequest * - * @param childIpId address - * @param parentIpIds address[] - * @param licenseTermsIds uint256[] - * @param licenseTemplate address - * @param royaltyContext bytes + * @param newOwner address */ -export type LicensingModuleRegisterDerivativeRequest = { - childIpId: Address; - parentIpIds: readonly Address[]; - licenseTermsIds: readonly bigint[]; - licenseTemplate: Address; - royaltyContext: Hex; +export type SpgnftBeaconTransferOwnershipRequest = { + newOwner: Address; }; /** - * LicensingModuleRegisterDerivativeWithLicenseTokensRequest + * SpgnftBeaconUpgradeToRequest * - * @param childIpId address - * @param licenseTokenIds uint256[] - * @param royaltyContext bytes + * @param newImplementation address */ -export type LicensingModuleRegisterDerivativeWithLicenseTokensRequest = { - childIpId: Address; - licenseTokenIds: readonly bigint[]; - royaltyContext: Hex; +export type SpgnftBeaconUpgradeToRequest = { + newImplementation: Address; }; /** - * contract LicensingModule event + * contract SPGNFTBeacon event */ -export class LicensingModuleEventClient { +export class SpgnftBeaconEventClient { protected readonly rpcClient: PublicClient; public readonly address: Address; constructor(rpcClient: PublicClient, address?: Address) { - this.address = address || getAddress(licensingModuleAddress, rpcClient.chain?.id); + this.address = address || getAddress(spgnftBeaconAddress, rpcClient.chain?.id); this.rpcClient = rpcClient; } /** - * event LicenseTokensMinted for contract LicensingModule + * event OwnershipTransferred for contract SPGNFTBeacon */ - public watchLicenseTokensMintedEvent( - onLogs: (txHash: Hex, ev: Partial) => void, + public watchOwnershipTransferredEvent( + onLogs: (txHash: Hex, ev: Partial) => void, ): WatchContractEventReturnType { return this.rpcClient.watchContractEvent({ - abi: licensingModuleAbi, + abi: spgnftBeaconAbi, address: this.address, - eventName: "LicenseTokensMinted", + eventName: "OwnershipTransferred", onLogs: (evs) => { evs.forEach((it) => onLogs(it.transactionHash, it.args)); }, @@ -8534,21 +11902,60 @@ export class LicensingModuleEventClient { } /** - * parse tx receipt event LicenseTokensMinted for contract LicensingModule + * parse tx receipt event OwnershipTransferred for contract SPGNFTBeacon */ - public parseTxLicenseTokensMintedEvent( + public parseTxOwnershipTransferredEvent( txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; + ): Array { + const targetLogs: Array = []; for (const log of txReceipt.logs) { try { const event = decodeEventLog({ - abi: licensingModuleAbi, - eventName: "LicenseTokensMinted", + abi: spgnftBeaconAbi, + eventName: "OwnershipTransferred", data: log.data, topics: log.topics, }); - if (event.eventName === "LicenseTokensMinted") { + if (event.eventName === "OwnershipTransferred") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } + + /** + * event Upgraded for contract SPGNFTBeacon + */ + public watchUpgradedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: spgnftBeaconAbi, + address: this.address, + eventName: "Upgraded", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event Upgraded for contract SPGNFTBeacon + */ + public parseTxUpgradedEvent(txReceipt: TransactionReceipt): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: spgnftBeaconAbi, + eventName: "Upgraded", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "Upgraded") { targetLogs.push(event.args); } } catch (e) { @@ -8560,573 +11967,487 @@ export class LicensingModuleEventClient { } /** - * contract LicensingModule write method + * contract SPGNFTBeacon readonly method */ -export class LicensingModuleClient extends LicensingModuleEventClient { - protected readonly wallet: SimpleWalletClient; - - constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { +export class SpgnftBeaconReadOnlyClient extends SpgnftBeaconEventClient { + constructor(rpcClient: PublicClient, address?: Address) { super(rpcClient, address); - this.wallet = wallet; } /** - * method attachLicenseTerms for contract LicensingModule + * method implementation for contract SPGNFTBeacon * - * @param request LicensingModuleAttachLicenseTermsRequest - * @return Promise + * @param request SpgnftBeaconImplementationRequest + * @return Promise */ - public async attachLicenseTerms( - request: LicensingModuleAttachLicenseTermsRequest, - ): Promise { - const { request: call } = await this.rpcClient.simulateContract({ - abi: licensingModuleAbi, + public async implementation(): Promise { + return await this.rpcClient.readContract({ + abi: spgnftBeaconAbi, address: this.address, - functionName: "attachLicenseTerms", - account: this.wallet.account, - args: [request.ipId, request.licenseTemplate, request.licenseTermsId], + functionName: "implementation", }); - return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method mintLicenseTokens for contract LicensingModule - * - * @param request LicensingModuleMintLicenseTokensRequest - * @return Promise - */ - public async mintLicenseTokens( - request: LicensingModuleMintLicenseTokensRequest, - ): Promise { - const { request: call } = await this.rpcClient.simulateContract({ - abi: licensingModuleAbi, - address: this.address, - functionName: "mintLicenseTokens", - account: this.wallet.account, - args: [ - request.licensorIpId, - request.licenseTemplate, - request.licenseTermsId, - request.amount, - request.receiver, - request.royaltyContext, - ], + * method owner for contract SPGNFTBeacon + * + * @param request SpgnftBeaconOwnerRequest + * @return Promise + */ + public async owner(): Promise { + return await this.rpcClient.readContract({ + abi: spgnftBeaconAbi, + address: this.address, + functionName: "owner", }); - return await this.wallet.writeContract(call as WriteContractParameters); + } +} + +/** + * contract SPGNFTBeacon write method + */ +export class SpgnftBeaconClient extends SpgnftBeaconReadOnlyClient { + protected readonly wallet: SimpleWalletClient; + + constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { + super(rpcClient, address); + this.wallet = wallet; } /** - * method registerDerivative for contract LicensingModule + * method renounceOwnership for contract SPGNFTBeacon * - * @param request LicensingModuleRegisterDerivativeRequest + * @param request SpgnftBeaconRenounceOwnershipRequest * @return Promise */ - public async registerDerivative( - request: LicensingModuleRegisterDerivativeRequest, - ): Promise { + public async renounceOwnership(): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: licensingModuleAbi, + abi: spgnftBeaconAbi, address: this.address, - functionName: "registerDerivative", + functionName: "renounceOwnership", account: this.wallet.account, - args: [ - request.childIpId, - request.parentIpIds, - request.licenseTermsIds, - request.licenseTemplate, - request.royaltyContext, - ], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method registerDerivativeWithLicenseTokens for contract LicensingModule + * method transferOwnership for contract SPGNFTBeacon * - * @param request LicensingModuleRegisterDerivativeWithLicenseTokensRequest + * @param request SpgnftBeaconTransferOwnershipRequest * @return Promise */ - public async registerDerivativeWithLicenseTokens( - request: LicensingModuleRegisterDerivativeWithLicenseTokensRequest, + public async transferOwnership( + request: SpgnftBeaconTransferOwnershipRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: licensingModuleAbi, + abi: spgnftBeaconAbi, address: this.address, - functionName: "registerDerivativeWithLicenseTokens", + functionName: "transferOwnership", account: this.wallet.account, - args: [request.childIpId, request.licenseTokenIds, request.royaltyContext], + args: [request.newOwner], }); return await this.wallet.writeContract(call as WriteContractParameters); } -} - -// Contract ModuleRegistry ============================================================= - -/** - * ModuleRegistryIsRegisteredRequest - * - * @param moduleAddress address - */ -export type ModuleRegistryIsRegisteredRequest = { - moduleAddress: Address; -}; - -export type ModuleRegistryIsRegisteredResponse = boolean; - -/** - * contract ModuleRegistry readonly method - */ -export class ModuleRegistryReadOnlyClient { - protected readonly rpcClient: PublicClient; - public readonly address: Address; - - constructor(rpcClient: PublicClient, address?: Address) { - this.address = address || getAddress(moduleRegistryAddress, rpcClient.chain?.id); - this.rpcClient = rpcClient; - } /** - * method isRegistered for contract ModuleRegistry + * method upgradeTo for contract SPGNFTBeacon * - * @param request ModuleRegistryIsRegisteredRequest - * @return Promise + * @param request SpgnftBeaconUpgradeToRequest + * @return Promise */ - public async isRegistered( - request: ModuleRegistryIsRegisteredRequest, - ): Promise { - return await this.rpcClient.readContract({ - abi: moduleRegistryAbi, + public async upgradeTo(request: SpgnftBeaconUpgradeToRequest): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: spgnftBeaconAbi, address: this.address, - functionName: "isRegistered", - args: [request.moduleAddress], + functionName: "upgradeTo", + account: this.wallet.account, + args: [request.newImplementation], }); + return await this.wallet.writeContract(call as WriteContractParameters); } } -// Contract PILicenseTemplate ============================================================= +// Contract SPGNFTImpl ============================================================= /** - * PiLicenseTemplateAuthorityUpdatedEvent + * SpgnftImplApprovalEvent * - * @param authority address + * @param owner address + * @param approved address + * @param tokenId uint256 */ -export type PiLicenseTemplateAuthorityUpdatedEvent = { - authority: Address; +export type SpgnftImplApprovalEvent = { + owner: Address; + approved: Address; + tokenId: bigint; }; /** - * PiLicenseTemplateDerivativeApprovedEvent + * SpgnftImplApprovalForAllEvent * - * @param licenseTermsId uint256 - * @param ipId address - * @param caller address + * @param owner address + * @param operator address * @param approved bool */ -export type PiLicenseTemplateDerivativeApprovedEvent = { - licenseTermsId: bigint; - ipId: Address; - caller: Address; +export type SpgnftImplApprovalForAllEvent = { + owner: Address; + operator: Address; approved: boolean; }; /** - * PiLicenseTemplateInitializedEvent + * SpgnftImplInitializedEvent * * @param version uint64 */ -export type PiLicenseTemplateInitializedEvent = { +export type SpgnftImplInitializedEvent = { version: bigint; }; /** - * PiLicenseTemplateLicenseTermsRegisteredEvent - * - * @param licenseTermsId uint256 - * @param licenseTemplate address - * @param licenseTerms bytes - */ -export type PiLicenseTemplateLicenseTermsRegisteredEvent = { - licenseTermsId: bigint; - licenseTemplate: Address; - licenseTerms: Hex; -}; - -/** - * PiLicenseTemplateUpgradedEvent + * SpgnftImplRoleAdminChangedEvent * - * @param implementation address - */ -export type PiLicenseTemplateUpgradedEvent = { - implementation: Address; + * @param role bytes32 + * @param previousAdminRole bytes32 + * @param newAdminRole bytes32 + */ +export type SpgnftImplRoleAdminChangedEvent = { + role: Hex; + previousAdminRole: Hex; + newAdminRole: Hex; }; -export type PiLicenseTemplateAccessControllerResponse = Address; - -export type PiLicenseTemplateIpAccountRegistryResponse = Address; - -export type PiLicenseTemplateLicenseRegistryResponse = Address; - -export type PiLicenseTemplateRoyaltyModuleResponse = Address; - -export type PiLicenseTemplateUpgradeInterfaceVersionResponse = string; - -export type PiLicenseTemplateAuthorityResponse = Address; - /** - * PiLicenseTemplateExistsRequest + * SpgnftImplRoleGrantedEvent * - * @param licenseTermsId uint256 + * @param role bytes32 + * @param account address + * @param sender address */ -export type PiLicenseTemplateExistsRequest = { - licenseTermsId: bigint; +export type SpgnftImplRoleGrantedEvent = { + role: Hex; + account: Address; + sender: Address; }; -export type PiLicenseTemplateExistsResponse = boolean; - /** - * PiLicenseTemplateGetEarlierExpireTimeRequest + * SpgnftImplRoleRevokedEvent * - * @param licenseTermsIds uint256[] - * @param start uint256 + * @param role bytes32 + * @param account address + * @param sender address */ -export type PiLicenseTemplateGetEarlierExpireTimeRequest = { - licenseTermsIds: readonly bigint[]; - start: bigint; +export type SpgnftImplRoleRevokedEvent = { + role: Hex; + account: Address; + sender: Address; }; -export type PiLicenseTemplateGetEarlierExpireTimeResponse = bigint; - /** - * PiLicenseTemplateGetExpireTimeRequest + * SpgnftImplTransferEvent * - * @param licenseTermsId uint256 - * @param start uint256 + * @param from address + * @param to address + * @param tokenId uint256 */ -export type PiLicenseTemplateGetExpireTimeRequest = { - licenseTermsId: bigint; - start: bigint; +export type SpgnftImplTransferEvent = { + from: Address; + to: Address; + tokenId: bigint; }; -export type PiLicenseTemplateGetExpireTimeResponse = bigint; - -/** - * PiLicenseTemplateGetLicenseTermsRequest - * - * @param selectedLicenseTermsId uint256 - */ -export type PiLicenseTemplateGetLicenseTermsRequest = { - selectedLicenseTermsId: bigint; -}; +export type SpgnftImplDefaultAdminRoleResponse = Hex; -/** - * PiLicenseTemplateGetLicenseTermsResponse - * - * @param terms tuple - */ -export type PiLicenseTemplateGetLicenseTermsResponse = { - terms: { - transferable: boolean; - royaltyPolicy: Address; - mintingFee: bigint; - expiration: bigint; - commercialUse: boolean; - commercialAttribution: boolean; - commercializerChecker: Address; - commercializerCheckerData: Hex; - commercialRevShare: number; - commercialRevCelling: bigint; - derivativesAllowed: boolean; - derivativesAttribution: boolean; - derivativesApproval: boolean; - derivativesReciprocal: boolean; - derivativeRevCelling: bigint; - currency: Address; - uri: string; - }; -}; +export type SpgnftImplSpgAddressResponse = Address; /** - * PiLicenseTemplateGetLicenseTermsIdRequest + * SpgnftImplBalanceOfRequest * - * @param terms tuple + * @param owner address */ -export type PiLicenseTemplateGetLicenseTermsIdRequest = { - terms: { - transferable: boolean; - royaltyPolicy: Address; - mintingFee: bigint; - expiration: bigint; - commercialUse: boolean; - commercialAttribution: boolean; - commercializerChecker: Address; - commercializerCheckerData: Hex; - commercialRevShare: number; - commercialRevCelling: bigint; - derivativesAllowed: boolean; - derivativesAttribution: boolean; - derivativesApproval: boolean; - derivativesReciprocal: boolean; - derivativeRevCelling: bigint; - currency: Address; - uri: string; - }; +export type SpgnftImplBalanceOfRequest = { + owner: Address; }; -/** - * PiLicenseTemplateGetLicenseTermsIdResponse - * - * @param selectedLicenseTermsId uint256 - */ -export type PiLicenseTemplateGetLicenseTermsIdResponse = { - selectedLicenseTermsId: bigint; -}; +export type SpgnftImplBalanceOfResponse = bigint; /** - * PiLicenseTemplateGetLicenseTermsUriRequest + * SpgnftImplGetApprovedRequest * - * @param licenseTermsId uint256 + * @param tokenId uint256 */ -export type PiLicenseTemplateGetLicenseTermsUriRequest = { - licenseTermsId: bigint; +export type SpgnftImplGetApprovedRequest = { + tokenId: bigint; }; -export type PiLicenseTemplateGetLicenseTermsUriResponse = string; - -export type PiLicenseTemplateGetMetadataUriResponse = string; - -/** - * PiLicenseTemplateGetRoyaltyPolicyRequest - * - * @param licenseTermsId uint256 - */ -export type PiLicenseTemplateGetRoyaltyPolicyRequest = { - licenseTermsId: bigint; -}; +export type SpgnftImplGetApprovedResponse = Address; /** - * PiLicenseTemplateGetRoyaltyPolicyResponse + * SpgnftImplGetRoleAdminRequest * - * @param royaltyPolicy address - * @param royaltyData bytes - * @param mintingFee uint256 - * @param currency address + * @param role bytes32 */ -export type PiLicenseTemplateGetRoyaltyPolicyResponse = { - royaltyPolicy: Address; - royaltyData: Hex; - mintingFee: bigint; - currency: Address; +export type SpgnftImplGetRoleAdminRequest = { + role: Hex; }; -export type PiLicenseTemplateIsConsumingScheduledOpResponse = Hex; +export type SpgnftImplGetRoleAdminResponse = Hex; /** - * PiLicenseTemplateIsDerivativeApprovedRequest - * - * @param parentIpId address - * @param licenseTermsId uint256 - * @param childIpId address - */ -export type PiLicenseTemplateIsDerivativeApprovedRequest = { - parentIpId: Address; - licenseTermsId: bigint; - childIpId: Address; + * SpgnftImplHasRoleRequest + * + * @param role bytes32 + * @param account address + */ +export type SpgnftImplHasRoleRequest = { + role: Hex; + account: Address; }; -export type PiLicenseTemplateIsDerivativeApprovedResponse = boolean; +export type SpgnftImplHasRoleResponse = boolean; /** - * PiLicenseTemplateIsLicenseTransferableRequest + * SpgnftImplIsApprovedForAllRequest * - * @param licenseTermsId uint256 + * @param owner address + * @param operator address */ -export type PiLicenseTemplateIsLicenseTransferableRequest = { - licenseTermsId: bigint; +export type SpgnftImplIsApprovedForAllRequest = { + owner: Address; + operator: Address; }; -export type PiLicenseTemplateIsLicenseTransferableResponse = boolean; +export type SpgnftImplIsApprovedForAllResponse = boolean; -export type PiLicenseTemplateNameResponse = string; +export type SpgnftImplMintCostResponse = bigint; -export type PiLicenseTemplateProxiableUuidResponse = Hex; +export type SpgnftImplMintTokenResponse = Address; + +export type SpgnftImplNameResponse = string; /** - * PiLicenseTemplateSupportsInterfaceRequest + * SpgnftImplOwnerOfRequest + * + * @param tokenId uint256 + */ +export type SpgnftImplOwnerOfRequest = { + tokenId: bigint; +}; + +export type SpgnftImplOwnerOfResponse = Address; + +/** + * SpgnftImplSupportsInterfaceRequest * * @param interfaceId bytes4 */ -export type PiLicenseTemplateSupportsInterfaceRequest = { +export type SpgnftImplSupportsInterfaceRequest = { interfaceId: Hex; }; -export type PiLicenseTemplateSupportsInterfaceResponse = boolean; +export type SpgnftImplSupportsInterfaceResponse = boolean; + +export type SpgnftImplSymbolResponse = string; /** - * PiLicenseTemplateToJsonRequest + * SpgnftImplTokenUriRequest * - * @param licenseTermsId uint256 + * @param tokenId uint256 */ -export type PiLicenseTemplateToJsonRequest = { - licenseTermsId: bigint; +export type SpgnftImplTokenUriRequest = { + tokenId: bigint; }; -export type PiLicenseTemplateToJsonResponse = string; +export type SpgnftImplTokenUriResponse = string; -export type PiLicenseTemplateTotalRegisteredLicenseTermsResponse = bigint; +export type SpgnftImplTotalSupplyResponse = bigint; /** - * PiLicenseTemplateVerifyCompatibleLicensesRequest + * SpgnftImplApproveRequest * - * @param licenseTermsIds uint256[] + * @param to address + * @param tokenId uint256 */ -export type PiLicenseTemplateVerifyCompatibleLicensesRequest = { - licenseTermsIds: readonly bigint[]; +export type SpgnftImplApproveRequest = { + to: Address; + tokenId: bigint; }; -export type PiLicenseTemplateVerifyCompatibleLicensesResponse = boolean; +/** + * SpgnftImplGrantRoleRequest + * + * @param role bytes32 + * @param account address + */ +export type SpgnftImplGrantRoleRequest = { + role: Hex; + account: Address; +}; /** - * PiLicenseTemplateInitializeRequest + * SpgnftImplInitializeRequest * - * @param accessManager address * @param name string - * @param metadataURI string + * @param symbol string + * @param maxSupply uint32 + * @param mintCost uint256 + * @param mintToken address + * @param owner address */ -export type PiLicenseTemplateInitializeRequest = { - accessManager: Address; +export type SpgnftImplInitializeRequest = { name: string; - metadataURI: string; + symbol: string; + maxSupply: number; + mintCost: bigint; + mintToken: Address; + owner: Address; }; /** - * PiLicenseTemplateRegisterLicenseTermsRequest + * SpgnftImplMintRequest * - * @param terms tuple + * @param to address */ -export type PiLicenseTemplateRegisterLicenseTermsRequest = { - terms: { - transferable: boolean; - royaltyPolicy: Address; - mintingFee: bigint; - expiration: bigint; - commercialUse: boolean; - commercialAttribution: boolean; - commercializerChecker: Address; - commercializerCheckerData: Hex; - commercialRevShare: number; - commercialRevCelling: bigint; - derivativesAllowed: boolean; - derivativesAttribution: boolean; - derivativesApproval: boolean; - derivativesReciprocal: boolean; - derivativeRevCelling: bigint; - currency: Address; - uri: string; - }; +export type SpgnftImplMintRequest = { + to: Address; }; /** - * PiLicenseTemplateSetApprovalRequest + * SpgnftImplMintBySpgRequest * - * @param parentIpId address - * @param licenseTermsId uint256 - * @param childIpId address - * @param approved bool + * @param to address + * @param payer address */ -export type PiLicenseTemplateSetApprovalRequest = { - parentIpId: Address; - licenseTermsId: bigint; - childIpId: Address; - approved: boolean; +export type SpgnftImplMintBySpgRequest = { + to: Address; + payer: Address; }; /** - * PiLicenseTemplateSetAuthorityRequest + * SpgnftImplRenounceRoleRequest * - * @param newAuthority address + * @param role bytes32 + * @param callerConfirmation address */ -export type PiLicenseTemplateSetAuthorityRequest = { - newAuthority: Address; +export type SpgnftImplRenounceRoleRequest = { + role: Hex; + callerConfirmation: Address; }; /** - * PiLicenseTemplateUpgradeToAndCallRequest + * SpgnftImplRevokeRoleRequest * - * @param newImplementation address + * @param role bytes32 + * @param account address + */ +export type SpgnftImplRevokeRoleRequest = { + role: Hex; + account: Address; +}; + +/** + * SpgnftImplSafeTransferFromRequest + * + * @param from address + * @param to address + * @param tokenId uint256 + */ +export type SpgnftImplSafeTransferFromRequest = { + from: Address; + to: Address; + tokenId: bigint; +}; + +/** + * SpgnftImplSafeTransferFrom2Request + * + * @param from address + * @param to address + * @param tokenId uint256 * @param data bytes */ -export type PiLicenseTemplateUpgradeToAndCallRequest = { - newImplementation: Address; +export type SpgnftImplSafeTransferFrom2Request = { + from: Address; + to: Address; + tokenId: bigint; data: Hex; }; /** - * PiLicenseTemplateVerifyMintLicenseTokenRequest + * SpgnftImplSetApprovalForAllRequest * - * @param 0 uint256 - * @param 1 address - * @param 2 address - * @param 3 uint256 + * @param operator address + * @param approved bool */ -export type PiLicenseTemplateVerifyMintLicenseTokenRequest = readonly [ - bigint, - Address, - Address, - bigint, -]; +export type SpgnftImplSetApprovalForAllRequest = { + operator: Address; + approved: boolean; +}; /** - * PiLicenseTemplateVerifyRegisterDerivativeRequest + * SpgnftImplSetMintCostRequest * - * @param childIpId address - * @param parentIpId address - * @param licenseTermsId uint256 - * @param licensee address + * @param cost uint256 */ -export type PiLicenseTemplateVerifyRegisterDerivativeRequest = { - childIpId: Address; - parentIpId: Address; - licenseTermsId: bigint; - licensee: Address; +export type SpgnftImplSetMintCostRequest = { + cost: bigint; }; /** - * PiLicenseTemplateVerifyRegisterDerivativeForAllParentsRequest + * SpgnftImplSetMintTokenRequest * - * @param childIpId address - * @param parentIpIds address[] - * @param licenseTermsIds uint256[] - * @param childIpOwner address + * @param token address */ -export type PiLicenseTemplateVerifyRegisterDerivativeForAllParentsRequest = { - childIpId: Address; - parentIpIds: readonly Address[]; - licenseTermsIds: readonly bigint[]; - childIpOwner: Address; +export type SpgnftImplSetMintTokenRequest = { + token: Address; }; /** - * contract PILicenseTemplate event + * SpgnftImplTransferFromRequest + * + * @param from address + * @param to address + * @param tokenId uint256 */ -export class PiLicenseTemplateEventClient { +export type SpgnftImplTransferFromRequest = { + from: Address; + to: Address; + tokenId: bigint; +}; + +/** + * SpgnftImplWithdrawTokenRequest + * + * @param token address + * @param recipient address + */ +export type SpgnftImplWithdrawTokenRequest = { + token: Address; + recipient: Address; +}; + +/** + * contract SPGNFTImpl event + */ +export class SpgnftImplEventClient { protected readonly rpcClient: PublicClient; public readonly address: Address; constructor(rpcClient: PublicClient, address?: Address) { - this.address = address || getAddress(piLicenseTemplateAddress, rpcClient.chain?.id); + this.address = address || getAddress(spgnftImplAddress, rpcClient.chain?.id); this.rpcClient = rpcClient; } /** - * event AuthorityUpdated for contract PILicenseTemplate + * event Approval for contract SPGNFTImpl */ - public watchAuthorityUpdatedEvent( - onLogs: (txHash: Hex, ev: Partial) => void, + public watchApprovalEvent( + onLogs: (txHash: Hex, ev: Partial) => void, ): WatchContractEventReturnType { return this.rpcClient.watchContractEvent({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - eventName: "AuthorityUpdated", + eventName: "Approval", onLogs: (evs) => { evs.forEach((it) => onLogs(it.transactionHash, it.args)); }, @@ -9134,21 +12455,60 @@ export class PiLicenseTemplateEventClient { } /** - * parse tx receipt event AuthorityUpdated for contract PILicenseTemplate + * parse tx receipt event Approval for contract SPGNFTImpl */ - public parseTxAuthorityUpdatedEvent( + public parseTxApprovalEvent(txReceipt: TransactionReceipt): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: spgnftImplAbi, + eventName: "Approval", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "Approval") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } + + /** + * event ApprovalForAll for contract SPGNFTImpl + */ + public watchApprovalForAllEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: spgnftImplAbi, + address: this.address, + eventName: "ApprovalForAll", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event ApprovalForAll for contract SPGNFTImpl + */ + public parseTxApprovalForAllEvent( txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; + ): Array { + const targetLogs: Array = []; for (const log of txReceipt.logs) { try { const event = decodeEventLog({ - abi: piLicenseTemplateAbi, - eventName: "AuthorityUpdated", + abi: spgnftImplAbi, + eventName: "ApprovalForAll", data: log.data, topics: log.topics, }); - if (event.eventName === "AuthorityUpdated") { + if (event.eventName === "ApprovalForAll") { targetLogs.push(event.args); } } catch (e) { @@ -9159,15 +12519,15 @@ export class PiLicenseTemplateEventClient { } /** - * event DerivativeApproved for contract PILicenseTemplate + * event Initialized for contract SPGNFTImpl */ - public watchDerivativeApprovedEvent( - onLogs: (txHash: Hex, ev: Partial) => void, + public watchInitializedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, ): WatchContractEventReturnType { return this.rpcClient.watchContractEvent({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - eventName: "DerivativeApproved", + eventName: "Initialized", onLogs: (evs) => { evs.forEach((it) => onLogs(it.transactionHash, it.args)); }, @@ -9175,21 +12535,60 @@ export class PiLicenseTemplateEventClient { } /** - * parse tx receipt event DerivativeApproved for contract PILicenseTemplate + * parse tx receipt event Initialized for contract SPGNFTImpl */ - public parseTxDerivativeApprovedEvent( + public parseTxInitializedEvent(txReceipt: TransactionReceipt): Array { + const targetLogs: Array = []; + for (const log of txReceipt.logs) { + try { + const event = decodeEventLog({ + abi: spgnftImplAbi, + eventName: "Initialized", + data: log.data, + topics: log.topics, + }); + if (event.eventName === "Initialized") { + targetLogs.push(event.args); + } + } catch (e) { + /* empty */ + } + } + return targetLogs; + } + + /** + * event RoleAdminChanged for contract SPGNFTImpl + */ + public watchRoleAdminChangedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, + ): WatchContractEventReturnType { + return this.rpcClient.watchContractEvent({ + abi: spgnftImplAbi, + address: this.address, + eventName: "RoleAdminChanged", + onLogs: (evs) => { + evs.forEach((it) => onLogs(it.transactionHash, it.args)); + }, + }); + } + + /** + * parse tx receipt event RoleAdminChanged for contract SPGNFTImpl + */ + public parseTxRoleAdminChangedEvent( txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; + ): Array { + const targetLogs: Array = []; for (const log of txReceipt.logs) { try { const event = decodeEventLog({ - abi: piLicenseTemplateAbi, - eventName: "DerivativeApproved", + abi: spgnftImplAbi, + eventName: "RoleAdminChanged", data: log.data, topics: log.topics, }); - if (event.eventName === "DerivativeApproved") { + if (event.eventName === "RoleAdminChanged") { targetLogs.push(event.args); } } catch (e) { @@ -9200,15 +12599,15 @@ export class PiLicenseTemplateEventClient { } /** - * event Initialized for contract PILicenseTemplate + * event RoleGranted for contract SPGNFTImpl */ - public watchInitializedEvent( - onLogs: (txHash: Hex, ev: Partial) => void, + public watchRoleGrantedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, ): WatchContractEventReturnType { return this.rpcClient.watchContractEvent({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - eventName: "Initialized", + eventName: "RoleGranted", onLogs: (evs) => { evs.forEach((it) => onLogs(it.transactionHash, it.args)); }, @@ -9216,21 +12615,19 @@ export class PiLicenseTemplateEventClient { } /** - * parse tx receipt event Initialized for contract PILicenseTemplate + * parse tx receipt event RoleGranted for contract SPGNFTImpl */ - public parseTxInitializedEvent( - txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; + public parseTxRoleGrantedEvent(txReceipt: TransactionReceipt): Array { + const targetLogs: Array = []; for (const log of txReceipt.logs) { try { const event = decodeEventLog({ - abi: piLicenseTemplateAbi, - eventName: "Initialized", + abi: spgnftImplAbi, + eventName: "RoleGranted", data: log.data, topics: log.topics, }); - if (event.eventName === "Initialized") { + if (event.eventName === "RoleGranted") { targetLogs.push(event.args); } } catch (e) { @@ -9241,15 +12638,15 @@ export class PiLicenseTemplateEventClient { } /** - * event LicenseTermsRegistered for contract PILicenseTemplate + * event RoleRevoked for contract SPGNFTImpl */ - public watchLicenseTermsRegisteredEvent( - onLogs: (txHash: Hex, ev: Partial) => void, + public watchRoleRevokedEvent( + onLogs: (txHash: Hex, ev: Partial) => void, ): WatchContractEventReturnType { return this.rpcClient.watchContractEvent({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - eventName: "LicenseTermsRegistered", + eventName: "RoleRevoked", onLogs: (evs) => { evs.forEach((it) => onLogs(it.transactionHash, it.args)); }, @@ -9257,21 +12654,19 @@ export class PiLicenseTemplateEventClient { } /** - * parse tx receipt event LicenseTermsRegistered for contract PILicenseTemplate + * parse tx receipt event RoleRevoked for contract SPGNFTImpl */ - public parseTxLicenseTermsRegisteredEvent( - txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; + public parseTxRoleRevokedEvent(txReceipt: TransactionReceipt): Array { + const targetLogs: Array = []; for (const log of txReceipt.logs) { try { const event = decodeEventLog({ - abi: piLicenseTemplateAbi, - eventName: "LicenseTermsRegistered", + abi: spgnftImplAbi, + eventName: "RoleRevoked", data: log.data, topics: log.topics, }); - if (event.eventName === "LicenseTermsRegistered") { + if (event.eventName === "RoleRevoked") { targetLogs.push(event.args); } } catch (e) { @@ -9282,15 +12677,15 @@ export class PiLicenseTemplateEventClient { } /** - * event Upgraded for contract PILicenseTemplate + * event Transfer for contract SPGNFTImpl */ - public watchUpgradedEvent( - onLogs: (txHash: Hex, ev: Partial) => void, + public watchTransferEvent( + onLogs: (txHash: Hex, ev: Partial) => void, ): WatchContractEventReturnType { return this.rpcClient.watchContractEvent({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - eventName: "Upgraded", + eventName: "Transfer", onLogs: (evs) => { evs.forEach((it) => onLogs(it.transactionHash, it.args)); }, @@ -9298,21 +12693,19 @@ export class PiLicenseTemplateEventClient { } /** - * parse tx receipt event Upgraded for contract PILicenseTemplate + * parse tx receipt event Transfer for contract SPGNFTImpl */ - public parseTxUpgradedEvent( - txReceipt: TransactionReceipt, - ): Array { - const targetLogs: Array = []; + public parseTxTransferEvent(txReceipt: TransactionReceipt): Array { + const targetLogs: Array = []; for (const log of txReceipt.logs) { try { const event = decodeEventLog({ - abi: piLicenseTemplateAbi, - eventName: "Upgraded", + abi: spgnftImplAbi, + eventName: "Transfer", data: log.data, topics: log.topics, }); - if (event.eventName === "Upgraded") { + if (event.eventName === "Transfer") { targetLogs.push(event.args); } } catch (e) { @@ -9324,329 +12717,192 @@ export class PiLicenseTemplateEventClient { } /** - * contract PILicenseTemplate readonly method + * contract SPGNFTImpl readonly method */ -export class PiLicenseTemplateReadOnlyClient extends PiLicenseTemplateEventClient { +export class SpgnftImplReadOnlyClient extends SpgnftImplEventClient { constructor(rpcClient: PublicClient, address?: Address) { super(rpcClient, address); } /** - * method ACCESS_CONTROLLER for contract PILicenseTemplate - * - * @param request PiLicenseTemplateAccessControllerRequest - * @return Promise - */ - public async accessController(): Promise { - return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, - address: this.address, - functionName: "ACCESS_CONTROLLER", - }); - } - - /** - * method IP_ACCOUNT_REGISTRY for contract PILicenseTemplate - * - * @param request PiLicenseTemplateIpAccountRegistryRequest - * @return Promise - */ - public async ipAccountRegistry(): Promise { - return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, - address: this.address, - functionName: "IP_ACCOUNT_REGISTRY", - }); - } - - /** - * method LICENSE_REGISTRY for contract PILicenseTemplate - * - * @param request PiLicenseTemplateLicenseRegistryRequest - * @return Promise - */ - public async licenseRegistry(): Promise { - return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, - address: this.address, - functionName: "LICENSE_REGISTRY", - }); - } - - /** - * method ROYALTY_MODULE for contract PILicenseTemplate - * - * @param request PiLicenseTemplateRoyaltyModuleRequest - * @return Promise - */ - public async royaltyModule(): Promise { - return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, - address: this.address, - functionName: "ROYALTY_MODULE", - }); - } - - /** - * method UPGRADE_INTERFACE_VERSION for contract PILicenseTemplate - * - * @param request PiLicenseTemplateUpgradeInterfaceVersionRequest - * @return Promise - */ - public async upgradeInterfaceVersion(): Promise { - return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, - address: this.address, - functionName: "UPGRADE_INTERFACE_VERSION", - }); - } - - /** - * method authority for contract PILicenseTemplate + * method DEFAULT_ADMIN_ROLE for contract SPGNFTImpl * - * @param request PiLicenseTemplateAuthorityRequest - * @return Promise + * @param request SpgnftImplDefaultAdminRoleRequest + * @return Promise */ - public async authority(): Promise { + public async defaultAdminRole(): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "authority", + functionName: "DEFAULT_ADMIN_ROLE", }); } /** - * method exists for contract PILicenseTemplate + * method SPG_ADDRESS for contract SPGNFTImpl * - * @param request PiLicenseTemplateExistsRequest - * @return Promise + * @param request SpgnftImplSpgAddressRequest + * @return Promise */ - public async exists( - request: PiLicenseTemplateExistsRequest, - ): Promise { + public async spgAddress(): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "exists", - args: [request.licenseTermsId], + functionName: "SPG_ADDRESS", }); } /** - * method getEarlierExpireTime for contract PILicenseTemplate + * method balanceOf for contract SPGNFTImpl * - * @param request PiLicenseTemplateGetEarlierExpireTimeRequest - * @return Promise + * @param request SpgnftImplBalanceOfRequest + * @return Promise */ - public async getEarlierExpireTime( - request: PiLicenseTemplateGetEarlierExpireTimeRequest, - ): Promise { + public async balanceOf( + request: SpgnftImplBalanceOfRequest, + ): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "getEarlierExpireTime", - args: [request.licenseTermsIds, request.start], + functionName: "balanceOf", + args: [request.owner], }); } /** - * method getExpireTime for contract PILicenseTemplate + * method getApproved for contract SPGNFTImpl * - * @param request PiLicenseTemplateGetExpireTimeRequest - * @return Promise + * @param request SpgnftImplGetApprovedRequest + * @return Promise */ - public async getExpireTime( - request: PiLicenseTemplateGetExpireTimeRequest, - ): Promise { + public async getApproved( + request: SpgnftImplGetApprovedRequest, + ): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, - address: this.address, - functionName: "getExpireTime", - args: [request.licenseTermsId, request.start], - }); - } - - /** - * method getLicenseTerms for contract PILicenseTemplate - * - * @param request PiLicenseTemplateGetLicenseTermsRequest - * @return Promise - */ - public async getLicenseTerms( - request: PiLicenseTemplateGetLicenseTermsRequest, - ): Promise { - const result = await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "getLicenseTerms", - args: [request.selectedLicenseTermsId], - }); - return { - terms: result, - }; - } - - /** - * method getLicenseTermsId for contract PILicenseTemplate - * - * @param request PiLicenseTemplateGetLicenseTermsIdRequest - * @return Promise - */ - public async getLicenseTermsId( - request: PiLicenseTemplateGetLicenseTermsIdRequest, - ): Promise { - const result = await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, - address: this.address, - functionName: "getLicenseTermsId", - args: [request.terms], + functionName: "getApproved", + args: [request.tokenId], }); - return { - selectedLicenseTermsId: result, - }; } /** - * method getLicenseTermsURI for contract PILicenseTemplate + * method getRoleAdmin for contract SPGNFTImpl * - * @param request PiLicenseTemplateGetLicenseTermsUriRequest - * @return Promise + * @param request SpgnftImplGetRoleAdminRequest + * @return Promise */ - public async getLicenseTermsUri( - request: PiLicenseTemplateGetLicenseTermsUriRequest, - ): Promise { + public async getRoleAdmin( + request: SpgnftImplGetRoleAdminRequest, + ): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "getLicenseTermsURI", - args: [request.licenseTermsId], + functionName: "getRoleAdmin", + args: [request.role], }); } /** - * method getMetadataURI for contract PILicenseTemplate + * method hasRole for contract SPGNFTImpl * - * @param request PiLicenseTemplateGetMetadataUriRequest - * @return Promise + * @param request SpgnftImplHasRoleRequest + * @return Promise */ - public async getMetadataUri(): Promise { + public async hasRole(request: SpgnftImplHasRoleRequest): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, - address: this.address, - functionName: "getMetadataURI", - }); - } - - /** - * method getRoyaltyPolicy for contract PILicenseTemplate - * - * @param request PiLicenseTemplateGetRoyaltyPolicyRequest - * @return Promise - */ - public async getRoyaltyPolicy( - request: PiLicenseTemplateGetRoyaltyPolicyRequest, - ): Promise { - const result = await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "getRoyaltyPolicy", - args: [request.licenseTermsId], + functionName: "hasRole", + args: [request.role, request.account], }); - return { - royaltyPolicy: result[0], - royaltyData: result[1], - mintingFee: result[2], - currency: result[3], - }; } /** - * method isConsumingScheduledOp for contract PILicenseTemplate + * method isApprovedForAll for contract SPGNFTImpl * - * @param request PiLicenseTemplateIsConsumingScheduledOpRequest - * @return Promise + * @param request SpgnftImplIsApprovedForAllRequest + * @return Promise */ - public async isConsumingScheduledOp(): Promise { + public async isApprovedForAll( + request: SpgnftImplIsApprovedForAllRequest, + ): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "isConsumingScheduledOp", + functionName: "isApprovedForAll", + args: [request.owner, request.operator], }); } /** - * method isDerivativeApproved for contract PILicenseTemplate + * method mintCost for contract SPGNFTImpl * - * @param request PiLicenseTemplateIsDerivativeApprovedRequest - * @return Promise + * @param request SpgnftImplMintCostRequest + * @return Promise */ - public async isDerivativeApproved( - request: PiLicenseTemplateIsDerivativeApprovedRequest, - ): Promise { + public async mintCost(): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "isDerivativeApproved", - args: [request.parentIpId, request.licenseTermsId, request.childIpId], + functionName: "mintCost", }); } /** - * method isLicenseTransferable for contract PILicenseTemplate + * method mintToken for contract SPGNFTImpl * - * @param request PiLicenseTemplateIsLicenseTransferableRequest - * @return Promise + * @param request SpgnftImplMintTokenRequest + * @return Promise */ - public async isLicenseTransferable( - request: PiLicenseTemplateIsLicenseTransferableRequest, - ): Promise { + public async mintToken(): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "isLicenseTransferable", - args: [request.licenseTermsId], + functionName: "mintToken", }); } /** - * method name for contract PILicenseTemplate + * method name for contract SPGNFTImpl * - * @param request PiLicenseTemplateNameRequest - * @return Promise + * @param request SpgnftImplNameRequest + * @return Promise */ - public async name(): Promise { + public async name(): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, functionName: "name", }); } /** - * method proxiableUUID for contract PILicenseTemplate + * method ownerOf for contract SPGNFTImpl * - * @param request PiLicenseTemplateProxiableUuidRequest - * @return Promise + * @param request SpgnftImplOwnerOfRequest + * @return Promise */ - public async proxiableUuid(): Promise { + public async ownerOf(request: SpgnftImplOwnerOfRequest): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "proxiableUUID", + functionName: "ownerOf", + args: [request.tokenId], }); } /** - * method supportsInterface for contract PILicenseTemplate + * method supportsInterface for contract SPGNFTImpl * - * @param request PiLicenseTemplateSupportsInterfaceRequest - * @return Promise + * @param request SpgnftImplSupportsInterfaceRequest + * @return Promise */ public async supportsInterface( - request: PiLicenseTemplateSupportsInterfaceRequest, - ): Promise { + request: SpgnftImplSupportsInterfaceRequest, + ): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, functionName: "supportsInterface", args: [request.interfaceId], @@ -9654,58 +12910,53 @@ export class PiLicenseTemplateReadOnlyClient extends PiLicenseTemplateEventClien } /** - * method toJson for contract PILicenseTemplate + * method symbol for contract SPGNFTImpl * - * @param request PiLicenseTemplateToJsonRequest - * @return Promise + * @param request SpgnftImplSymbolRequest + * @return Promise */ - public async toJson( - request: PiLicenseTemplateToJsonRequest, - ): Promise { + public async symbol(): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "toJson", - args: [request.licenseTermsId], + functionName: "symbol", }); } /** - * method totalRegisteredLicenseTerms for contract PILicenseTemplate + * method tokenURI for contract SPGNFTImpl * - * @param request PiLicenseTemplateTotalRegisteredLicenseTermsRequest - * @return Promise + * @param request SpgnftImplTokenUriRequest + * @return Promise */ - public async totalRegisteredLicenseTerms(): Promise { + public async tokenUri(request: SpgnftImplTokenUriRequest): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "totalRegisteredLicenseTerms", + functionName: "tokenURI", + args: [request.tokenId], }); } /** - * method verifyCompatibleLicenses for contract PILicenseTemplate + * method totalSupply for contract SPGNFTImpl * - * @param request PiLicenseTemplateVerifyCompatibleLicensesRequest - * @return Promise + * @param request SpgnftImplTotalSupplyRequest + * @return Promise */ - public async verifyCompatibleLicenses( - request: PiLicenseTemplateVerifyCompatibleLicensesRequest, - ): Promise { + public async totalSupply(): Promise { return await this.rpcClient.readContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "verifyCompatibleLicenses", - args: [request.licenseTermsIds], + functionName: "totalSupply", }); } } /** - * contract PILicenseTemplate write method + * contract SPGNFTImpl write method */ -export class PiLicenseTemplateClient extends PiLicenseTemplateReadOnlyClient { +export class SpgnftImplClient extends SpgnftImplReadOnlyClient { protected readonly wallet: SimpleWalletClient; constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { @@ -9714,308 +12965,262 @@ export class PiLicenseTemplateClient extends PiLicenseTemplateReadOnlyClient { } /** - * method initialize for contract PILicenseTemplate + * method approve for contract SPGNFTImpl * - * @param request PiLicenseTemplateInitializeRequest + * @param request SpgnftImplApproveRequest * @return Promise */ - public async initialize( - request: PiLicenseTemplateInitializeRequest, - ): Promise { + public async approve(request: SpgnftImplApproveRequest): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "initialize", + functionName: "approve", account: this.wallet.account, - args: [request.accessManager, request.name, request.metadataURI], + args: [request.to, request.tokenId], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method registerLicenseTerms for contract PILicenseTemplate + * method grantRole for contract SPGNFTImpl * - * @param request PiLicenseTemplateRegisterLicenseTermsRequest + * @param request SpgnftImplGrantRoleRequest * @return Promise */ - public async registerLicenseTerms( - request: PiLicenseTemplateRegisterLicenseTermsRequest, - ): Promise { + public async grantRole(request: SpgnftImplGrantRoleRequest): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "registerLicenseTerms", + functionName: "grantRole", account: this.wallet.account, - args: [request.terms], + args: [request.role, request.account], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method setApproval for contract PILicenseTemplate + * method initialize for contract SPGNFTImpl * - * @param request PiLicenseTemplateSetApprovalRequest + * @param request SpgnftImplInitializeRequest * @return Promise */ - public async setApproval( - request: PiLicenseTemplateSetApprovalRequest, - ): Promise { + public async initialize(request: SpgnftImplInitializeRequest): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "setApproval", + functionName: "initialize", account: this.wallet.account, - args: [request.parentIpId, request.licenseTermsId, request.childIpId, request.approved], + args: [ + request.name, + request.symbol, + request.maxSupply, + request.mintCost, + request.mintToken, + request.owner, + ], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method setAuthority for contract PILicenseTemplate + * method mint for contract SPGNFTImpl * - * @param request PiLicenseTemplateSetAuthorityRequest + * @param request SpgnftImplMintRequest * @return Promise */ - public async setAuthority( - request: PiLicenseTemplateSetAuthorityRequest, - ): Promise { + public async mint(request: SpgnftImplMintRequest): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "setAuthority", + functionName: "mint", account: this.wallet.account, - args: [request.newAuthority], + args: [request.to], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method upgradeToAndCall for contract PILicenseTemplate + * method mintBySPG for contract SPGNFTImpl * - * @param request PiLicenseTemplateUpgradeToAndCallRequest + * @param request SpgnftImplMintBySpgRequest * @return Promise */ - public async upgradeToAndCall( - request: PiLicenseTemplateUpgradeToAndCallRequest, - ): Promise { + public async mintBySpg(request: SpgnftImplMintBySpgRequest): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "upgradeToAndCall", + functionName: "mintBySPG", account: this.wallet.account, - args: [request.newImplementation, request.data], + args: [request.to, request.payer], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method verifyMintLicenseToken for contract PILicenseTemplate + * method renounceRole for contract SPGNFTImpl * - * @param request PiLicenseTemplateVerifyMintLicenseTokenRequest + * @param request SpgnftImplRenounceRoleRequest * @return Promise */ - public async verifyMintLicenseToken( - request: PiLicenseTemplateVerifyMintLicenseTokenRequest, + public async renounceRole( + request: SpgnftImplRenounceRoleRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "verifyMintLicenseToken", + functionName: "renounceRole", account: this.wallet.account, - args: [request[0], request[1], request[2], request[3]], + args: [request.role, request.callerConfirmation], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method verifyRegisterDerivative for contract PILicenseTemplate + * method revokeRole for contract SPGNFTImpl * - * @param request PiLicenseTemplateVerifyRegisterDerivativeRequest + * @param request SpgnftImplRevokeRoleRequest * @return Promise */ - public async verifyRegisterDerivative( - request: PiLicenseTemplateVerifyRegisterDerivativeRequest, - ): Promise { + public async revokeRole(request: SpgnftImplRevokeRoleRequest): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "verifyRegisterDerivative", + functionName: "revokeRole", account: this.wallet.account, - args: [request.childIpId, request.parentIpId, request.licenseTermsId, request.licensee], + args: [request.role, request.account], }); return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method verifyRegisterDerivativeForAllParents for contract PILicenseTemplate + * method safeTransferFrom for contract SPGNFTImpl * - * @param request PiLicenseTemplateVerifyRegisterDerivativeForAllParentsRequest + * @param request SpgnftImplSafeTransferFromRequest * @return Promise */ - public async verifyRegisterDerivativeForAllParents( - request: PiLicenseTemplateVerifyRegisterDerivativeForAllParentsRequest, + public async safeTransferFrom( + request: SpgnftImplSafeTransferFromRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: piLicenseTemplateAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "verifyRegisterDerivativeForAllParents", + functionName: "safeTransferFrom", account: this.wallet.account, - args: [request.childIpId, request.parentIpIds, request.licenseTermsIds, request.childIpOwner], + args: [request.from, request.to, request.tokenId], }); return await this.wallet.writeContract(call as WriteContractParameters); } -} - -// Contract RoyaltyModule ============================================================= - -/** - * RoyaltyModulePayRoyaltyOnBehalfRequest - * - * @param receiverIpId address - * @param payerIpId address - * @param token address - * @param amount uint256 - */ -export type RoyaltyModulePayRoyaltyOnBehalfRequest = { - receiverIpId: Address; - payerIpId: Address; - token: Address; - amount: bigint; -}; - -/** - * contract RoyaltyModule write method - */ -export class RoyaltyModuleClient { - protected readonly wallet: SimpleWalletClient; - protected readonly rpcClient: PublicClient; - public readonly address: Address; - constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { - this.address = address || getAddress(royaltyModuleAddress, rpcClient.chain?.id); - this.rpcClient = rpcClient; - this.wallet = wallet; + /** + * method safeTransferFrom for contract SPGNFTImpl + * + * @param request SpgnftImplSafeTransferFrom2Request + * @return Promise + */ + public async safeTransferFrom2( + request: SpgnftImplSafeTransferFrom2Request, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: spgnftImplAbi, + address: this.address, + functionName: "safeTransferFrom", + account: this.wallet.account, + args: [request.from, request.to, request.tokenId, request.data], + }); + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method payRoyaltyOnBehalf for contract RoyaltyModule + * method setApprovalForAll for contract SPGNFTImpl * - * @param request RoyaltyModulePayRoyaltyOnBehalfRequest + * @param request SpgnftImplSetApprovalForAllRequest * @return Promise */ - public async payRoyaltyOnBehalf( - request: RoyaltyModulePayRoyaltyOnBehalfRequest, + public async setApprovalForAll( + request: SpgnftImplSetApprovalForAllRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: royaltyModuleAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "payRoyaltyOnBehalf", + functionName: "setApprovalForAll", account: this.wallet.account, - args: [request.receiverIpId, request.payerIpId, request.token, request.amount], + args: [request.operator, request.approved], }); return await this.wallet.writeContract(call as WriteContractParameters); } -} - -// Contract RoyaltyPolicyLAP ============================================================= - -/** - * RoyaltyPolicyLapGetRoyaltyDataRequest - * - * @param ipId address - */ -export type RoyaltyPolicyLapGetRoyaltyDataRequest = { - ipId: Address; -}; - -/** - * RoyaltyPolicyLapGetRoyaltyDataResponse - * - * @param 0 bool - * @param 1 address - * @param 2 uint32 - * @param 3 address[] - * @param 4 uint32[] - */ -export type RoyaltyPolicyLapGetRoyaltyDataResponse = readonly [ - boolean, - Address, - number, - readonly Address[], - readonly number[], -]; - -/** - * RoyaltyPolicyLapOnRoyaltyPaymentRequest - * - * @param caller address - * @param ipId address - * @param token address - * @param amount uint256 - */ -export type RoyaltyPolicyLapOnRoyaltyPaymentRequest = { - caller: Address; - ipId: Address; - token: Address; - amount: bigint; -}; - -/** - * contract RoyaltyPolicyLAP readonly method - */ -export class RoyaltyPolicyLapReadOnlyClient { - protected readonly rpcClient: PublicClient; - public readonly address: Address; - constructor(rpcClient: PublicClient, address?: Address) { - this.address = address || getAddress(royaltyPolicyLapAddress, rpcClient.chain?.id); - this.rpcClient = rpcClient; + /** + * method setMintCost for contract SPGNFTImpl + * + * @param request SpgnftImplSetMintCostRequest + * @return Promise + */ + public async setMintCost( + request: SpgnftImplSetMintCostRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: spgnftImplAbi, + address: this.address, + functionName: "setMintCost", + account: this.wallet.account, + args: [request.cost], + }); + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method getRoyaltyData for contract RoyaltyPolicyLAP + * method setMintToken for contract SPGNFTImpl * - * @param request RoyaltyPolicyLapGetRoyaltyDataRequest - * @return Promise + * @param request SpgnftImplSetMintTokenRequest + * @return Promise */ - public async getRoyaltyData( - request: RoyaltyPolicyLapGetRoyaltyDataRequest, - ): Promise { - return await this.rpcClient.readContract({ - abi: royaltyPolicyLapAbi, + public async setMintToken( + request: SpgnftImplSetMintTokenRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: spgnftImplAbi, address: this.address, - functionName: "getRoyaltyData", - args: [request.ipId], + functionName: "setMintToken", + account: this.wallet.account, + args: [request.token], }); + return await this.wallet.writeContract(call as WriteContractParameters); } -} - -/** - * contract RoyaltyPolicyLAP write method - */ -export class RoyaltyPolicyLapClient extends RoyaltyPolicyLapReadOnlyClient { - protected readonly wallet: SimpleWalletClient; - constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, address?: Address) { - super(rpcClient, address); - this.wallet = wallet; + /** + * method transferFrom for contract SPGNFTImpl + * + * @param request SpgnftImplTransferFromRequest + * @return Promise + */ + public async transferFrom( + request: SpgnftImplTransferFromRequest, + ): Promise { + const { request: call } = await this.rpcClient.simulateContract({ + abi: spgnftImplAbi, + address: this.address, + functionName: "transferFrom", + account: this.wallet.account, + args: [request.from, request.to, request.tokenId], + }); + return await this.wallet.writeContract(call as WriteContractParameters); } /** - * method onRoyaltyPayment for contract RoyaltyPolicyLAP + * method withdrawToken for contract SPGNFTImpl * - * @param request RoyaltyPolicyLapOnRoyaltyPaymentRequest + * @param request SpgnftImplWithdrawTokenRequest * @return Promise */ - public async onRoyaltyPayment( - request: RoyaltyPolicyLapOnRoyaltyPaymentRequest, + public async withdrawToken( + request: SpgnftImplWithdrawTokenRequest, ): Promise { const { request: call } = await this.rpcClient.simulateContract({ - abi: royaltyPolicyLapAbi, + abi: spgnftImplAbi, address: this.address, - functionName: "onRoyaltyPayment", + functionName: "withdrawToken", account: this.wallet.account, - args: [request.caller, request.ipId, request.token, request.amount], + args: [request.token, request.recipient], }); return await this.wallet.writeContract(call as WriteContractParameters); } diff --git a/packages/core-sdk/src/client.ts b/packages/core-sdk/src/client.ts index 9150be6b..8a9eb010 100644 --- a/packages/core-sdk/src/client.ts +++ b/packages/core-sdk/src/client.ts @@ -14,6 +14,7 @@ import { DisputeClient } from "./resources/dispute"; import { IPAccountClient } from "./resources/ipAccount"; import { chainStringToViemChain } from "./utils/utils"; import { RoyaltyClient } from "./resources/royalty"; +import { NftClient } from "./resources/nftClient"; import { SimpleWalletClient } from "./abi/generated"; if (typeof process !== "undefined") { @@ -32,6 +33,8 @@ export class StoryClient { private _dispute: DisputeClient | null = null; private _ipAccount: IPAccountClient | null = null; private _royalty: RoyaltyClient | null = null; + private _nftClient: NftClient | null = null; + /** * @param config - the configuration for the SDK client */ @@ -171,6 +174,7 @@ export class StoryClient { return this._ipAccount; } + /** * Getter for the royalty client. The client is lazily created when * this method is called. @@ -184,4 +188,18 @@ export class StoryClient { return this._royalty; } + + /** + * Getter for the NFT client. The client is lazily created when + * this method is called. + * + * @returns the NftClient instance + */ + public get nftClient(): NftClient { + if (this._nftClient === null) { + this._nftClient = new NftClient(this.rpcClient, this.wallet); + } + + return this._nftClient; + } } diff --git a/packages/core-sdk/src/index.ts b/packages/core-sdk/src/index.ts index 3be15023..191691dc 100644 --- a/packages/core-sdk/src/index.ts +++ b/packages/core-sdk/src/index.ts @@ -5,9 +5,10 @@ export { IPAssetClient } from "./resources/ipAsset"; export { PermissionClient } from "./resources/permission"; export { LicenseClient } from "./resources/license"; export { DisputeClient } from "./resources/dispute"; +export { NftClient } from "./resources/nftClient"; export type { StoryConfig } from "./types/config"; -export type { Hex, TypedData } from "./types/common"; +export type { TypedData } from "./types/common"; export type { RegisterIpResponse, @@ -38,6 +39,7 @@ export type { SnapshotResponse, ClaimableRevenueRequest, ClaimableRevenueResponse, + RoyaltyVaultAddress, } from "./types/resources/royalty"; export type { SetPermissionsRequest, SetPermissionsResponse } from "./types/resources/permission"; @@ -60,3 +62,10 @@ export type { IPAccountExecuteWithSigRequest, IPAccountExecuteWithSigResponse, } from "./types/resources/ipAccount"; + +export type { + CreateNFTCollectionRequest, + CreateNFTCollectionResponse, +} from "./types/resources/nftClient"; + +export type { PiLicenseTemplateGetLicenseTermsResponse } from "./abi/generated"; diff --git a/packages/core-sdk/src/resources/ipAccount.ts b/packages/core-sdk/src/resources/ipAccount.ts index fc3a9430..ea56535a 100644 --- a/packages/core-sdk/src/resources/ipAccount.ts +++ b/packages/core-sdk/src/resources/ipAccount.ts @@ -23,6 +23,7 @@ export class IPAccountClient { * @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.accountAddress The ipId to send. * @param request.data The data to send along with the transaction. * @returns Tx hash for the transaction. */ @@ -75,6 +76,7 @@ export class IPAccountClient { data: request.data, signer: request.signer, deadline: parseToBigInt(request.deadline), + // 712 signature signature: request.signature, }); diff --git a/packages/core-sdk/src/resources/ipAsset.ts b/packages/core-sdk/src/resources/ipAsset.ts index 22e55098..16fdbbe9 100644 --- a/packages/core-sdk/src/resources/ipAsset.ts +++ b/packages/core-sdk/src/resources/ipAsset.ts @@ -1,13 +1,15 @@ -import { Hex, PublicClient, getAddress, zeroAddress } from "viem"; +import { Hex, PublicClient, getAddress, toHex, zeroAddress } from "viem"; import { chain } from "../utils/utils"; import { SupportedChainIds } from "../types/config"; import { handleError } from "../utils/errors"; import { + CreateIpAssetWithPilTermsRequest, RegisterDerivativeRequest, RegisterDerivativeResponse, RegisterDerivativeWithLicenseTokensRequest, RegisterDerivativeWithLicenseTokensResponse, + RegisterIpAndMakeDerivativeRequest, RegisterIpResponse, RegisterRequest, } from "../types/resources/ipAsset"; @@ -17,8 +19,14 @@ import { LicenseTokenReadOnlyClient, LicensingModuleClient, PiLicenseTemplateClient, + RoyaltyPolicyLapClient, SimpleWalletClient, + SpgClient, + SpgMintAndRegisterIpAndAttachPilTermsRequest, + SpgRegisterIpAndMakeDerivativeRequest, } from "../abi/generated"; +import { getLicenseTermByType } from "../utils/getLicenseTermsByType"; +import { PIL_TYPE } from "../types/resources/license"; export class IPAssetClient { public licensingModuleClient: LicensingModuleClient; @@ -26,7 +34,10 @@ export class IPAssetClient { public licenseTemplateClient: PiLicenseTemplateClient; public licenseRegistryReadOnlyClient: LicenseRegistryReadOnlyClient; public licenseTokenReadOnlyClient: LicenseTokenReadOnlyClient; + public royaltyPolicyLAPClient: RoyaltyPolicyLapClient; + public spgClient: SpgClient; private readonly rpcClient: PublicClient; + private readonly wallet: SimpleWalletClient; private readonly chainId: SupportedChainIds; constructor(rpcClient: PublicClient, wallet: SimpleWalletClient, chainId: SupportedChainIds) { @@ -35,7 +46,10 @@ export class IPAssetClient { this.licenseTemplateClient = new PiLicenseTemplateClient(rpcClient, wallet); this.licenseRegistryReadOnlyClient = new LicenseRegistryReadOnlyClient(rpcClient); this.licenseTokenReadOnlyClient = new LicenseTokenReadOnlyClient(rpcClient); + this.royaltyPolicyLAPClient = new RoyaltyPolicyLapClient(rpcClient, wallet); + this.spgClient = new SpgClient(rpcClient, wallet); this.rpcClient = rpcClient; + this.wallet = wallet; this.chainId = chainId; } @@ -94,7 +108,7 @@ export class IPAssetClient { throw new Error(`The child IP with id ${request.childIpId} is not registered.`); } for (const parentId of request.parentIpIds) { - const isParentIpIdRegistered = await this.isRegistered(parentId); + const isParentIpIdRegistered = await this.isRegistered(getAddress(parentId)); if (!isParentIpIdRegistered) { throw new Error(`The parent IP with id ${parentId} is not registered.`); } @@ -105,8 +119,10 @@ export class IPAssetClient { for (let i = 0; i < request.parentIpIds.length; i++) { const isAttachedLicenseTerms = await this.licenseRegistryReadOnlyClient.hasIpAttachedLicenseTerms({ - ipId: request.parentIpIds[i], - licenseTemplate: request.licenseTemplate || this.licenseTemplateClient.address, + ipId: getAddress(request.parentIpIds[i]), + licenseTemplate: + (request.licenseTemplate && getAddress(request.licenseTemplate)) || + this.licenseTemplateClient.address, licenseTermsId: BigInt(request.licenseTermsIds[i]), }); if (!isAttachedLicenseTerms) { @@ -162,7 +178,7 @@ export class IPAssetClient { } } const txHash = await this.licensingModuleClient.registerDerivativeWithLicenseTokens({ - childIpId: request.childIpId, + childIpId: getAddress(request.childIpId), licenseTokenIds: request.licenseTokenIds.map((id) => BigInt(id)), royaltyContext: zeroAddress, }); @@ -177,10 +193,167 @@ export class IPAssetClient { } } + /** + * Mint an NFT from a collection and register it as an IP. + * @param request - The request object that contains all data needed to mint and register ip. + * @param request.nftContract The address of the NFT collection. + * @param request.pilType The type of the PIL. + * @param request.metadata - The metadata for the IP. + * @param request.metadataURI The URI of the metadata for the IP. + * @param request.metadata [Optional] The metadata for the IP. + * @param request.nftMetadata The metadata for the IP NFT. + * @param request.recipient [Optional] The address of the recipient of the minted NFT. + * @param request.mintingFee [Optional] The fee to be paid when minting a license. + * @param request.commercialRevShare [Optional] Percentage of revenue that must be shared with the licensor. + * @param request.currency [Optional] The ERC20 token to be used to pay the minting fee. the token must be registered in story protocol. + * @param request.txOptions [Optional] The transaction options. + * @returns A Promise that resolves to an object containing the transaction hash. + */ + public async createIpAssetWithPilTerms(request: CreateIpAssetWithPilTermsRequest) { + try { + if (request.pilType === undefined || request.pilType === null) { + throw new Error("PIL type is required."); + } + if ( + request.pilType === PIL_TYPE.COMMERCIAL_USE && + (!request.mintingFee || !request.currency) + ) { + throw new Error("Minting fee and currency are required for commercial use PIL."); + } + if ( + request.pilType === PIL_TYPE.COMMERCIAL_REMIX && + (!request.mintingFee || !request.currency || !request.commercialRevShare) + ) { + throw new Error( + "Minting fee, currency and commercialRevShare are required for commercial remix PIL.", + ); + } + const licenseTerm = getLicenseTermByType(request.pilType, { + mintingFee: request.mintingFee, + currency: request.currency && getAddress(request.currency), + royaltyPolicyLAPAddress: this.royaltyPolicyLAPClient.address, + commercialRevShare: request.commercialRevShare, + }); + const object: SpgMintAndRegisterIpAndAttachPilTermsRequest = { + nftContract: getAddress(request.nftContract), + recipient: + (request.recipient && getAddress(request.recipient)) || this.wallet.account!.address, + + terms: licenseTerm, + metadata: { + metadataURI: "", + metadataHash: toHex("", { size: 32 }), + nftMetadataHash: toHex("", { size: 32 }), + }, + }; + if ( + request.metadata && + !request.metadata.metadataURI && + !request.metadata.metadata && + !request.metadata.nftMetadata + ) { + object.metadata = { + metadataURI: request.metadata.metadataURI, + metadataHash: toHex(request.metadata.metadata, { size: 32 }), + nftMetadataHash: toHex(request.metadata.nftMetadata, { size: 32 }), + }; + } + const txHash = await this.spgClient.mintAndRegisterIpAndAttachPilTerms(object); + return txHash; + } catch (error) { + handleError(error, "Failed to mint and register IP and attach PIL terms"); + } + } + /** + * Register the given NFT as a derivative IP with metadata without using license tokens. + * @param request - The request object that contains all data needed to register derivative IP. + * @param request.nftContract The address of the NFT collection. + * @param request.tokenId The ID of the NFT. + * @param request.derivData The derivative data to be used for registerDerivative. + * @param request.derivData.parentIpIds The IDs of the parent IPs to link the registered derivative IP. + * @param request.derivData.licenseTemplate [Optional] The address of the license template to be used for the linking. + * @param request.derivData.licenseTermsIds The IDs of the license terms to be used for the linking. + * @param request.sigRegister Signature data for registerDerivative for the IP via the Licensing Module. + * @param request.sigRegister.signer The address of the signer for execution with signature. + * @param request.sigRegister.deadline The deadline for the signature. + * @param request.sigRegister.signature The signature for the execution via IP Account. + * @param request.metadata [Optional] The desired metadata for the newly registered IP. + * @param request.metadata.metadataURI The URI of the metadata for the IP. + * @param request.metadata.metadata The metadata for the IP. + * @param request.metadata.nftMetadata The the metadata for the IP NFT. + * @param request.sigMetadata [Optional] Signature data for setAll (metadata) for the IP via the Core Metadata Module. + * @param request.sigMetadata.signer The address of the signer for execution with signature. + * @param request.sigMetadata.deadline The deadline for the signature. + * @param request.sigMetadata.signature The signature for the execution via IP Account. + * @param request.txOptions [Optional] The transaction options. + * @returns A Promise that resolves to an object containing the transaction hash. + */ + private async registerDerivativeIp(request: RegisterIpAndMakeDerivativeRequest) { + try { + const object: SpgRegisterIpAndMakeDerivativeRequest = { + nftContract: getAddress(request.nftContract), + tokenId: BigInt(request.tokenId), + derivData: { + parentIpIds: request.derivData.parentIpIds.map((id) => getAddress(id)), + licenseTermsIds: request.derivData.licenseTermsIds.map((id) => BigInt(id)), + licenseTemplate: + (request.derivData.licenseTemplate && getAddress(request.derivData.licenseTemplate)) || + this.licenseTemplateClient.address, + royaltyContext: zeroAddress, + }, + sigRegister: { + signer: getAddress(request.sigRegister.signer), + deadline: BigInt(request.sigRegister.deadline), + signature: request.sigRegister.signature, + }, + sigMetadata: { + signer: zeroAddress, + deadline: BigInt(0), + signature: zeroAddress, + }, + metadata: { + metadataURI: "", + metadataHash: toHex("", { size: 32 }), + nftMetadataHash: toHex("", { size: 32 }), + }, + }; + if ( + request.sigMetadata && + request.sigMetadata.signature && + request.sigMetadata.signature !== zeroAddress && + request.sigMetadata.signer && + request.sigMetadata.signer !== zeroAddress && + request.sigMetadata.deadline + ) { + object.sigMetadata = { + signer: getAddress(request.sigMetadata.signer), + deadline: BigInt(request.sigMetadata.deadline), + signature: request.sigMetadata.signature, + }; + } + if ( + request.metadata && + request.metadata.metadata && + request.metadata.metadataURI && + request.metadata.nftMetadata + ) { + object.metadata = { + metadataURI: request.metadata.metadataURI, + metadataHash: toHex(request.metadata.metadata, { size: 32 }), + nftMetadataHash: toHex(request.metadata.nftMetadata, { size: 32 }), + }; + } + + const txHash = await this.spgClient.registerIpAndMakeDerivative(object); + return txHash; + } catch (error) { + handleError(error, "Failed to register derivative IP"); + } + } private async isNFTRegistered(tokenAddress: Hex, tokenId: bigint): Promise { const ipId = await this.ipAssetRegistryClient.ipId({ chainId: BigInt(chain[this.chainId]), - tokenContract: tokenAddress, + tokenContract: getAddress(tokenAddress), tokenId: tokenId, }); const isRegistered = await this.ipAssetRegistryClient.isRegistered({ id: ipId }); @@ -188,6 +361,6 @@ export class IPAssetClient { } private async isRegistered(ipId: Hex): Promise { - return await this.ipAssetRegistryClient.isRegistered({ id: ipId }); + return await this.ipAssetRegistryClient.isRegistered({ id: getAddress(ipId) }); } } diff --git a/packages/core-sdk/src/resources/license.ts b/packages/core-sdk/src/resources/license.ts index 40df99f4..76843397 100644 --- a/packages/core-sdk/src/resources/license.ts +++ b/packages/core-sdk/src/resources/license.ts @@ -1,4 +1,4 @@ -import { PublicClient, zeroAddress } from "viem"; +import { PublicClient, getAddress, zeroAddress } from "viem"; import { IpAssetRegistryClient, @@ -6,6 +6,7 @@ import { LicenseRegistryReadOnlyClient, LicensingModuleClient, PiLicenseTemplateClient, + PiLicenseTemplateGetLicenseTermsResponse, PiLicenseTemplateReadOnlyClient, RoyaltyPolicyLapClient, SimpleWalletClient, @@ -20,8 +21,10 @@ import { LicenseTermsIdResponse, MintLicenseTokensRequest, MintLicenseTokensResponse, + PIL_TYPE, } from "../types/resources/license"; import { handleError } from "../utils/errors"; +import { getLicenseTermByType } from "../utils/getLicenseTermsByType"; export class LicenseClient { public licenseRegistryClient: LicenseRegistryEventClient; @@ -56,25 +59,7 @@ export class LicenseClient { request?: RegisterNonComSocialRemixingPILRequest, ): Promise { try { - const licenseTerms: LicenseTerms = { - transferable: true, - royaltyPolicy: zeroAddress, - mintingFee: BigInt(0), - expiration: BigInt(0), - commercialUse: false, - commercialAttribution: false, - commercializerChecker: zeroAddress, - commercializerCheckerData: zeroAddress, - commercialRevShare: 0, - commercialRevCelling: BigInt(0), - derivativesAllowed: true, - derivativesAttribution: true, - derivativesApproval: false, - derivativesReciprocal: true, - derivativeRevCelling: BigInt(0), - currency: zeroAddress, - uri: "", - }; + const licenseTerms = getLicenseTermByType(PIL_TYPE.NON_COMMERCIAL_REMIX); const licenseTermsId = await this.getLicenseTermsId(licenseTerms); if (licenseTermsId !== 0) { return { licenseTermsId: licenseTermsId.toString() }; @@ -96,7 +81,6 @@ export class LicenseClient { * @param request - The request object that contains all data needed to register a PIL commercial use license. * @param request.mintingFee The fee to be paid when minting a license. * @param request.currency The ERC20 token to be used to pay the minting fee and the token must be registered in story protocol. - * @param request.royaltyPolicy The address of the royalty policy contract which required to StoryProtocol in advance. * @param request.txOptions [Optional] The transaction options. * @returns A Promise that resolves to an object containing the optional transaction hash and optional license terms Id. * @emits LicenseTermsRegistered (licenseTermsId, licenseTemplate, licenseTerms); @@ -105,25 +89,11 @@ export class LicenseClient { request: RegisterCommercialUsePILRequest, ): Promise { try { - const licenseTerms: LicenseTerms = { - transferable: true, - royaltyPolicy: this.royaltyPolicyLAPClient.address, - mintingFee: BigInt(request.mintingFee), - expiration: BigInt(0), - commercialUse: true, - commercialAttribution: true, - commercializerChecker: zeroAddress, - commercializerCheckerData: zeroAddress, - commercialRevShare: 0, - commercialRevCelling: BigInt(0), - derivativesAllowed: true, - derivativesAttribution: true, - derivativesApproval: false, - derivativesReciprocal: false, - derivativeRevCelling: BigInt(0), - currency: request.currency, - uri: "", - }; + const licenseTerms = getLicenseTermByType(PIL_TYPE.COMMERCIAL_USE, { + mintingFee: request.mintingFee, + currency: request.currency && getAddress(request.currency), + royaltyPolicyLAPAddress: this.royaltyPolicyLAPClient.address, + }); const licenseTermsId = await this.getLicenseTermsId(licenseTerms); if (licenseTermsId !== 0) { return { licenseTermsId: licenseTermsId.toString() }; @@ -146,7 +116,6 @@ export class LicenseClient { * @param request.mintingFee The fee to be paid when minting a license. * @param request.commercialRevShare Percentage of revenue that must be shared with the licensor. * @param request.currency The ERC20 token to be used to pay the minting fee. the token must be registered in story protocol. - * @param request.royaltyPolicy The address of the royalty policy contract which required to StoryProtocol in advance. * @param request.txOptions [Optional] The transaction options. * @returns A Promise that resolves to an object containing the optional transaction hash and optional license terms Id. * @emits LicenseTermsRegistered (licenseTermsId, licenseTemplate, licenseTerms); @@ -155,25 +124,12 @@ export class LicenseClient { request: RegisterCommercialRemixPILRequest, ): Promise { try { - const licenseTerms: LicenseTerms = { - transferable: true, - royaltyPolicy: this.royaltyPolicyLAPClient.address, - mintingFee: BigInt(request.mintingFee), - expiration: BigInt(0), - commercialUse: true, - commercialAttribution: true, - commercializerChecker: zeroAddress, - commercializerCheckerData: zeroAddress, + const licenseTerms = getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { + mintingFee: request.mintingFee, + currency: request.currency && getAddress(request.currency), + royaltyPolicyLAPAddress: this.royaltyPolicyLAPClient.address, commercialRevShare: request.commercialRevShare, - commercialRevCelling: BigInt(0), - derivativesAllowed: true, - derivativesAttribution: true, - derivativesApproval: false, - derivativesReciprocal: true, - derivativeRevCelling: BigInt(0), - currency: request.currency, - uri: "", - }; + }); const licenseTermsId = await this.getLicenseTermsId(licenseTerms); if (licenseTermsId !== 0) { return { licenseTermsId: licenseTermsId.toString() }; @@ -202,7 +158,9 @@ export class LicenseClient { */ public async attachLicenseTerms(request: AttachLicenseTermsRequest) { try { - const isRegistered = await this.ipAssetRegistryClient.isRegistered({ id: request.ipId }); + const isRegistered = await this.ipAssetRegistryClient.isRegistered({ + id: getAddress(request.ipId), + }); if (!isRegistered) { throw new Error(`The IP with id ${request.ipId} is not registered.`); } @@ -215,7 +173,9 @@ export class LicenseClient { const isAttachedLicenseTerms = await this.licenseRegistryReadOnlyClient.hasIpAttachedLicenseTerms({ ipId: request.ipId, - licenseTemplate: request.licenseTemplate || this.licenseTemplateClient.address, + licenseTemplate: + (request.licenseTemplate && getAddress(request.licenseTemplate)) || + this.licenseTemplateClient.address, licenseTermsId: BigInt(request.licenseTermsId), }); if (isAttachedLicenseTerms) { @@ -266,7 +226,7 @@ export class LicenseClient { ): Promise { try { const isLicenseIpIdRegistered = await this.ipAssetRegistryClient.isRegistered({ - id: request.licensorIpId, + id: getAddress(request.licensorIpId), }); if (!isLicenseIpIdRegistered) { throw new Error(`The licensor IP with id ${request.licensorIpId} is not registered.`); @@ -280,7 +240,9 @@ export class LicenseClient { const isAttachedLicenseTerms = await this.licenseRegistryReadOnlyClient.hasIpAttachedLicenseTerms({ ipId: request.licensorIpId, - licenseTemplate: request.licenseTemplate || this.licenseTemplateClient.address, + licenseTemplate: + (request.licenseTemplate && getAddress(request.licenseTemplate)) || + this.licenseTemplateClient.address, licenseTermsId: BigInt(request.licenseTermsId), }); if (!isAttachedLicenseTerms) { @@ -293,7 +255,8 @@ export class LicenseClient { licenseTemplate: request.licenseTemplate || this.licenseTemplateClient.address, licenseTermsId: BigInt(request.licenseTermsId), amount: BigInt(request.amount || 1), - receiver: request.receiver || this.wallet.account!.address, + receiver: + (request.receiver && getAddress(request.receiver)) || this.wallet.account!.address, royaltyContext: zeroAddress, }); if (request.txOptions?.waitForTransaction) { @@ -312,6 +275,23 @@ export class LicenseClient { } } + /** + * Gets license terms of the given ID. + * @param selectedLicenseTermsId The ID of the license terms. + * @returns A Promise that resolves to an object containing the PILTerms associate with the given ID. + */ + public async getLicenseTerms( + selectedLicenseTermsId: string, + ): Promise { + try { + return await this.piLicenseTemplateReadOnlyClient.getLicenseTerms({ + selectedLicenseTermsId: BigInt(selectedLicenseTermsId), + }); + } catch (error) { + handleError(error, "Failed to get license terms"); + } + } + private async getLicenseTermsId(request: LicenseTerms): Promise { const licenseRes = await this.licenseTemplateClient.getLicenseTermsId({ terms: request }); return Number(licenseRes.selectedLicenseTermsId); diff --git a/packages/core-sdk/src/resources/nftClient.ts b/packages/core-sdk/src/resources/nftClient.ts new file mode 100644 index 00000000..4b34d4e7 --- /dev/null +++ b/packages/core-sdk/src/resources/nftClient.ts @@ -0,0 +1,65 @@ +import { PublicClient, getAddress, isAddress, maxUint32, zeroAddress } from "viem"; + +import { SimpleWalletClient, SpgClient } from "../abi/generated"; +import { + CreateNFTCollectionRequest, + CreateNFTCollectionResponse, +} from "../types/resources/nftClient"; +import { handleError } from "../utils/errors"; + +export class NftClient { + public spgClient: SpgClient; + private readonly rpcClient: PublicClient; + private readonly wallet: SimpleWalletClient; + + constructor(rpcClient: PublicClient, wallet: SimpleWalletClient) { + this.rpcClient = rpcClient; + this.wallet = wallet; + this.spgClient = new SpgClient(rpcClient, wallet); + } + + /** + * Creates a new SPG NFT Collection. + * @param request - The request object containing necessary data to create a SPG NFT Collection. + * @param request.name - The name of the collection. + * @param request.symbol - The symbol of the collection. + * @param request.maxSupply - The maximum supply of the collection. + * @param request.mintCost - The cost to mint a token. + * @param request.mintToken - The token to mint. + * @param request.owner - The owner of the collection. + * @param request.txOptions - Optional transaction options. + * @returns A Promise that resolves to a CreateNFTCollectionResponse containing the transaction hash and collection address. + * @emits CollectionCreated (nftContract); + */ + public async createNFTCollection< + TReq extends CreateNFTCollectionRequest, + TRes = CreateNFTCollectionResponse, + >(request: TReq): Promise { + try { + if (request.mintCost && request.mintCost > 0n && !isAddress(request.mintToken || "")) { + throw new Error("Invalid mint token address, mint cost is greater than 0."); + } + + const txHash = await this.spgClient.createCollection({ + name: request.name, + symbol: request.symbol, + maxSupply: request.maxSupply ?? Number(maxUint32), + mintCost: request.mintCost ?? 0n, + mintToken: request.mintToken ?? zeroAddress, + owner: (request.owner && getAddress(request.owner)) || this.wallet.account!.address, + }); + + if (request.txOptions?.waitForTransaction) { + const txReceipt = await this.rpcClient.waitForTransactionReceipt({ hash: txHash }); + const targetLogs = this.spgClient.parseTxCollectionCreatedEvent(txReceipt); + return { + txHash: txHash, + nftContract: targetLogs[0].nftContract, + } as TRes; + } + return { txHash: txHash } as TRes; + } catch (error) { + handleError(error, "Failed to create a SPG NFT collection"); + } + } +} diff --git a/packages/core-sdk/src/resources/royalty.ts b/packages/core-sdk/src/resources/royalty.ts index aa87ff5d..68254dac 100644 --- a/packages/core-sdk/src/resources/royalty.ts +++ b/packages/core-sdk/src/resources/royalty.ts @@ -1,4 +1,4 @@ -import { Hex, PublicClient, encodeFunctionData } from "viem"; +import { Hex, PublicClient, encodeFunctionData, getAddress } from "viem"; import { handleError } from "../utils/errors"; import { @@ -11,8 +11,8 @@ import { RoyaltyVaultAddress, SnapshotRequest, SnapshotResponse, - claimRevenueRequest, - claimRevenueResponse, + ClaimRevenueRequest, + ClaimRevenueResponse, } from "../types/resources/royalty"; import { IpAssetRegistryClient, @@ -55,12 +55,12 @@ export class RoyaltyClient { ): Promise { try { const isParentIpIdRegistered = await this.ipAssetRegistryClient.isRegistered({ - id: request.parentIpId, + id: getAddress(request.parentIpId), }); if (!isParentIpIdRegistered) { throw new Error(`The parent IP with id ${request.parentIpId} is not registered.`); } - const proxyAddress = await this.getRoyaltyVaultProxyAddress(request.royaltyVaultIpId); + const proxyAddress = await this.getRoyaltyVaultAddress(getAddress(request.royaltyVaultIpId)); const ipRoyaltyVault = new IpRoyaltyVaultImplClient( this.rpcClient, this.wallet, @@ -99,13 +99,13 @@ export class RoyaltyClient { ): Promise { try { const isReceiverRegistered = await this.ipAssetRegistryClient.isRegistered({ - id: request.receiverIpId, + id: getAddress(request.receiverIpId), }); if (!isReceiverRegistered) { throw new Error(`The receiver IP with id ${request.receiverIpId} is not registered.`); } const isPayerRegistered = await this.ipAssetRegistryClient.isRegistered({ - id: request.payerIpId, + id: getAddress(request.payerIpId), }); if (!isPayerRegistered) { throw new Error(`The payer IP with id ${request.payerIpId} is not registered.`); @@ -113,7 +113,7 @@ export class RoyaltyClient { const txHash = await this.royaltyModuleClient.payRoyaltyOnBehalf({ receiverIpId: request.receiverIpId, payerIpId: request.payerIpId, - token: request.token, + token: getAddress(request.token), amount: BigInt(request.amount), }); if (request.txOptions?.waitForTransaction) { @@ -141,16 +141,16 @@ export class RoyaltyClient { request: ClaimableRevenueRequest, ): Promise { try { - const proxyAddress = await this.getRoyaltyVaultProxyAddress(request.royaltyVaultIpId); + const proxyAddress = await this.getRoyaltyVaultAddress(getAddress(request.royaltyVaultIpId)); const ipRoyaltyVault = new IpRoyaltyVaultImplClient( this.rpcClient, this.wallet, proxyAddress, ); const amount = await ipRoyaltyVault.claimableRevenue({ - account: request.account, + account: getAddress(request.account), snapshotId: BigInt(request.snapshotId), - token: request.token, + token: getAddress(request.token), }); return amount.toString(); } catch (error) { @@ -164,32 +164,41 @@ export class RoyaltyClient { * @param request.snapshotIds The list of snapshot ids. * @param request.royaltyVaultIpId The id of the royalty vault. * @param request.token The revenue token to claim. + * @param request.account [Optional] The ipId to send. * @param request.txOptions [Optional] The transaction options. * @returns A Promise that resolves to an object containing the transaction hash and optional claimableToken if waitForTxn is set to true. * @emits RevenueTokenClaimed (claimer, token, amount). */ - public async claimRevenue(request: claimRevenueRequest): Promise { + public async claimRevenue(request: ClaimRevenueRequest): Promise { try { - const proxyAddress = await this.getRoyaltyVaultProxyAddress(request.royaltyVaultIpId); + const proxyAddress = await this.getRoyaltyVaultAddress(getAddress(request.royaltyVaultIpId)); const ipRoyaltyVault = new IpRoyaltyVaultImplClient( this.rpcClient, this.wallet, proxyAddress, ); - const iPAccountExecuteResponse = await this.ipAccountClient.execute({ - to: proxyAddress, - value: 0, - accountAddress: request.account, - txOptions: { - waitForTransaction: true, - }, - data: encodeFunctionData({ - abi: ipRoyaltyVaultImplAbi, - functionName: "claimRevenueBySnapshotBatch", - args: [request.snapshotIds.map((item) => BigInt(item)), request.token], - }), - }); - const txHash = iPAccountExecuteResponse.txHash as Hex; + let txHash: Hex; + if (request.account) { + const iPAccountExecuteResponse = await this.ipAccountClient.execute({ + to: proxyAddress, + value: 0, + accountAddress: getAddress(request.account), + txOptions: { + waitForTransaction: true, + }, + data: encodeFunctionData({ + abi: ipRoyaltyVaultImplAbi, + functionName: "claimRevenueBySnapshotBatch", + args: [request.snapshotIds.map((item) => BigInt(item)), request.token], + }), + }); + txHash = iPAccountExecuteResponse.txHash as Hex; + } else { + txHash = await ipRoyaltyVault.claimRevenueBySnapshotBatch({ + snapshotIds: request.snapshotIds.map((item) => BigInt(item)), + token: getAddress(request.token), + }); + } if (request.txOptions?.waitForTransaction) { const txReceipt = await this.rpcClient.waitForTransactionReceipt({ hash: txHash, @@ -213,7 +222,7 @@ export class RoyaltyClient { */ public async snapshot(request: SnapshotRequest): Promise { try { - const proxyAddress = await this.getRoyaltyVaultProxyAddress(request.royaltyVaultIpId); + const proxyAddress = await this.getRoyaltyVaultAddress(getAddress(request.royaltyVaultIpId)); const ipRoyaltyVault = new IpRoyaltyVaultImplClient( this.rpcClient, this.wallet, @@ -232,9 +241,14 @@ export class RoyaltyClient { } } - private async getRoyaltyVaultProxyAddress(royaltyVaultIpId: Hex): Promise { + /** + * Get the royalty vault proxy address of given royaltyVaultIpId. + * @param royaltyVaultIpId the id of the royalty vault. + * @returns A Promise that resolves to an object containing the royalty vault address. + */ + public async getRoyaltyVaultAddress(royaltyVaultIpId: Hex): Promise { const isRoyaltyVaultIpIdRegistered = await this.ipAssetRegistryClient.isRegistered({ - id: royaltyVaultIpId, + id: getAddress(royaltyVaultIpId), }); if (!isRoyaltyVaultIpIdRegistered) { throw new Error(`The royalty vault IP with id ${royaltyVaultIpId} is not registered.`); diff --git a/packages/core-sdk/src/types/common.ts b/packages/core-sdk/src/types/common.ts index e3b63fcb..2a978ac9 100644 --- a/packages/core-sdk/src/types/common.ts +++ b/packages/core-sdk/src/types/common.ts @@ -1,5 +1,3 @@ -export type Hex = `0x${string}`; - export type TypedData = { interface: string; // i.e. "(address,uint256)" data: unknown[]; diff --git a/packages/core-sdk/src/types/resources/ipAccount.ts b/packages/core-sdk/src/types/resources/ipAccount.ts index edc756a8..844ffb74 100644 --- a/packages/core-sdk/src/types/resources/ipAccount.ts +++ b/packages/core-sdk/src/types/resources/ipAccount.ts @@ -1,10 +1,12 @@ +import { Hex } from "viem"; + import { TxOptions } from "../options"; export type IPAccountExecuteRequest = { - accountAddress: `0x${string}`; - to: `0x${string}`; + accountAddress: Hex; + to: Hex; value: number; - data: `0x${string}`; + data: Hex; txOptions?: TxOptions; }; @@ -13,13 +15,13 @@ export type IPAccountExecuteResponse = { }; export type IPAccountExecuteWithSigRequest = { - accountAddress: `0x${string}`; - to: `0x${string}`; + accountAddress: Hex; + to: Hex; value: number; - data: `0x${string}`; - signer: `0x${string}`; + data: Hex; + signer: Hex; deadline: number; - signature: `0x${string}`; + signature: Hex; txOptions?: TxOptions; }; diff --git a/packages/core-sdk/src/types/resources/ipAsset.ts b/packages/core-sdk/src/types/resources/ipAsset.ts index cf78abd7..aff9e0d6 100644 --- a/packages/core-sdk/src/types/resources/ipAsset.ts +++ b/packages/core-sdk/src/types/resources/ipAsset.ts @@ -1,6 +1,7 @@ -import { Hex } from "viem"; +import { Address, Hex } from "viem"; import { TxOptions } from "../options"; +import { PIL_TYPE } from "./license"; export type RegisterIpResponse = { txHash?: string; @@ -35,3 +36,43 @@ export type RegisterDerivativeResponse = { txHash?: string; childIpId?: Hex; }; + +export type CreateIpAssetWithPilTermsRequest = { + nftContract: Address; + pilType: PIL_TYPE; + metadata?: { + metadataURI: string; + metadata: string; + nftMetadata: string; + }; + recipient?: Hex; + mintingFee?: string; + currency?: Hex; + commercialRevShare?: number; + txOptions?: TxOptions; +}; + +export type RegisterIpAndMakeDerivativeRequest = { + nftContract: Address; + tokenId: string; + derivData: { + parentIpIds: Address[]; + licenseTermsIds: string[]; + licenseTemplate?: Address; + }; + metadata?: { + metadataURI: string; + metadata: string; + nftMetadata: string; + }; + sigMetadata?: { + signer: Address; + deadline: string; + signature: Hex; + }; + sigRegister: { + signer: Address; + deadline: string; + signature: Hex; + }; +}; diff --git a/packages/core-sdk/src/types/resources/license.ts b/packages/core-sdk/src/types/resources/license.ts index 596bdf5b..14ea7781 100644 --- a/packages/core-sdk/src/types/resources/license.ts +++ b/packages/core-sdk/src/types/resources/license.ts @@ -75,3 +75,9 @@ export type MintLicenseTokensResponse = { licenseTokenId?: string; txHash?: string; }; + +export enum PIL_TYPE { + NON_COMMERCIAL_REMIX, + COMMERCIAL_USE, + COMMERCIAL_REMIX, +} diff --git a/packages/core-sdk/src/types/resources/nftClient.ts b/packages/core-sdk/src/types/resources/nftClient.ts new file mode 100644 index 00000000..4caa6a1e --- /dev/null +++ b/packages/core-sdk/src/types/resources/nftClient.ts @@ -0,0 +1,18 @@ +import { Hex } from "viem"; + +import { TxOptions } from "../options"; + +export type CreateNFTCollectionRequest = { + name: string; + symbol: string; + maxSupply?: number; + mintCost?: bigint; + mintToken?: Hex; + owner?: Hex; + txOptions?: TxOptions; +}; + +export type CreateNFTCollectionResponse = + TReq["txOptions"] extends { waitForTransaction: true } + ? { txHash: string; nftContract: Hex } + : { txHash: string; nftContract?: Hex }; diff --git a/packages/core-sdk/src/types/resources/royalty.ts b/packages/core-sdk/src/types/resources/royalty.ts index c44331e9..29233638 100644 --- a/packages/core-sdk/src/types/resources/royalty.ts +++ b/packages/core-sdk/src/types/resources/royalty.ts @@ -66,15 +66,15 @@ export type SnapshotRequest = { txOptions?: TxOptions; }; -export type claimRevenueRequest = { +export type ClaimRevenueRequest = { snapshotIds: string[]; token: Hex; - account: Hex; royaltyVaultIpId: Hex; + account?: Hex; txOptions?: TxOptions; }; -export type claimRevenueResponse = { +export type ClaimRevenueResponse = { txHash: string; claimableToken?: string; }; diff --git a/packages/core-sdk/src/utils/getLicenseTermsByType.ts b/packages/core-sdk/src/utils/getLicenseTermsByType.ts new file mode 100644 index 00000000..74d35e06 --- /dev/null +++ b/packages/core-sdk/src/utils/getLicenseTermsByType.ts @@ -0,0 +1,66 @@ +import { Hex, getAddress, zeroAddress } from "viem"; + +import { PIL_TYPE, LicenseTerms } from "../types/resources/license"; + +export function getLicenseTermByType( + type: PIL_TYPE, + term?: { + mintingFee?: string; + currency?: Hex; + royaltyPolicyLAPAddress: Hex; + commercialRevShare?: number; + }, +): LicenseTerms { + const licenseTerms: LicenseTerms = { + transferable: true, + royaltyPolicy: zeroAddress, + mintingFee: BigInt(0), + expiration: BigInt(0), + commercialUse: false, + commercialAttribution: false, + commercializerChecker: zeroAddress, + commercializerCheckerData: zeroAddress, + commercialRevShare: 0, + commercialRevCelling: BigInt(0), + derivativesAllowed: true, + derivativesAttribution: true, + derivativesApproval: false, + derivativesReciprocal: true, + derivativeRevCelling: BigInt(0), + currency: zeroAddress, + uri: "", + }; + if (type === PIL_TYPE.NON_COMMERCIAL_REMIX) { + return licenseTerms; + } else if (type === PIL_TYPE.COMMERCIAL_USE) { + if (!term || term.mintingFee === undefined || term.currency === undefined) { + throw new Error("mintingFee currency are required for commercial use PIL."); + } + licenseTerms.royaltyPolicy = getAddress(term.royaltyPolicyLAPAddress); + licenseTerms.mintingFee = BigInt(term.mintingFee); + licenseTerms.commercialUse = true; + licenseTerms.commercialAttribution = true; + licenseTerms.derivativesReciprocal = false; + licenseTerms.currency = getAddress(term.currency); + return licenseTerms; + } else { + if ( + !term || + term.mintingFee === undefined || + term.currency === undefined || + term.commercialRevShare === undefined + ) { + throw new Error( + "mintingFee, currency and commercialRevShare are required for commercial remix PIL.", + ); + } + licenseTerms.royaltyPolicy = getAddress(term.royaltyPolicyLAPAddress); + licenseTerms.mintingFee = BigInt(term.mintingFee); + licenseTerms.commercialUse = true; + licenseTerms.commercialAttribution = true; + licenseTerms.commercialRevShare = term.commercialRevShare; + licenseTerms.derivativesReciprocal = true; + licenseTerms.currency = getAddress(term.currency); + return licenseTerms; + } +} diff --git a/packages/core-sdk/src/utils/utils.ts b/packages/core-sdk/src/utils/utils.ts index 623f74cf..52c67cd5 100644 --- a/packages/core-sdk/src/utils/utils.ts +++ b/packages/core-sdk/src/utils/utils.ts @@ -8,10 +8,11 @@ import { parseAbiParameters, Chain, ContractEventName, + Hex, } from "viem"; import { sepolia } from "viem/chains"; -import { Hex, TypedData } from "../types/common"; +import { TypedData } from "../types/common"; import { SupportedChainIds } from "../types/config"; export function isIntegerString(s: string): boolean { diff --git a/packages/core-sdk/test/integration/ipAccount.test.ts b/packages/core-sdk/test/integration/ipAccount.test.ts index e0e92ad9..3328c11d 100644 --- a/packages/core-sdk/test/integration/ipAccount.test.ts +++ b/packages/core-sdk/test/integration/ipAccount.test.ts @@ -1,49 +1,99 @@ import chai from "chai"; import chaiAsPromised from "chai-as-promised"; import { StoryClient } from "../../src"; -import { getStoryClientInSepolia } from "./util"; +import { MockERC721, getStoryClientInSepolia, getTokenId } from "./util"; +import { Hex, encodeFunctionData, getAddress, zeroAddress } from "viem"; +import { accessControllerAbi, accessControllerAddress } from "../../src/abi/generated"; +import { privateKeyToAccount } from "viem/accounts"; chai.use(chaiAsPromised); const expect = chai.expect; -describe.skip("Permission Functions", () => { +const sepoliaChainId = BigInt(11155111); + +describe("Ip Account functions", () => { let client: StoryClient; + let ipId: Hex; + let data: Hex; - before(function () { + before(async function () { client = getStoryClientInSepolia(); + const tokenId = await getTokenId(); + const registerResult = await client.ipAsset.register({ + tokenContract: MockERC721, + tokenId: tokenId!, + txOptions: { + waitForTransaction: true, + }, + }); + ipId = registerResult.ipId!; + data = encodeFunctionData({ + abi: accessControllerAbi, + functionName: "setPermission", + args: [ + getAddress(ipId), + getAddress(process.env.TEST_WALLET_ADDRESS as Hex), + getAddress("0x2ac240293f12032E103458451dE8A8096c5A72E8"), + "0x00000000" as Hex, + 1, + ], + }); }); - describe("Execute Set Permission", async function () { - it("should not throw error when execute setting permission", async () => { - const waitForTransaction: boolean = true; - // const response = await expect( - - // ).to.not.be.rejected; + describe("Execute ipAccount", async function () { + it("should not throw error when execute", async () => { const response = await client.ipAccount.execute({ - accountAddress: "0x004e38104adc39cbf4cea9bd8876440a969e3d0b", + to: accessControllerAddress[11155111], value: 0, - to: "0x674d6E1f7b5e2d714DBa588e9d046965225517c8", - data: "0x7bac65fd000000000000000000000000004e38104adc39cbf4cea9bd8876440a969e3d0b0000000000000000000000009965507d1a55bcc2695c58ba16fb37d819b0a4dc0000000000000000000000002ac240293f12032e103458451de8a8096c5a72e800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", - txOptions: { - waitForTransaction: waitForTransaction, - }, + data, + accountAddress: ipId, }); - console.log("response", response); - expect(response.txHash).to.be.a("string"); - expect(response.txHash).not.empty; + expect(response.txHash).to.be.a("string").and.not.empty; }); }); - describe("Execute with sig Set Permission", async function () { + describe.skip("Execute with sig", async function () { + // collect signature and help other execute method it("should not throw error when executeWithSig setting permission", async () => { + const account = privateKeyToAccount(process.env.SEPOLIA_TEST_WALLET_PRIVATE_KEY as Hex); + + const signature = await account.signTypedData({ + types: { + EIP712Domain: [ + { name: "name", type: "string" }, + { name: "chainId", type: "uint256" }, + { name: "verifyingContract", type: "address" }, + ], + ExecuteWithSig: [ + { name: "accountAddress", type: "address" }, + { name: "value", type: "uint256" }, + { name: "to", type: "address" }, + { name: "data", type: "bytes" }, + { name: "deadline", type: "uint256" }, + ], + }, + primaryType: "ExecuteWithSig", + domain: { + name: "sepolia", + chainId: sepoliaChainId, + verifyingContract: client.ipAsset.ipAssetRegistryClient.address, + }, + message: { + accountAddress: ipId, + value: BigInt(0), + to: client.ipAsset.ipAssetRegistryClient.address, + data: data, + deadline: BigInt(111), + }, + }); const waitForTransaction: boolean = true; const response = await expect( client.ipAccount.executeWithSig({ - accountAddress: "0x004e38104adc39cbf4cea9bd8876440a969e3d0b", + accountAddress: ipId, value: 0, - to: "0x674d6E1f7b5e2d714DBa588e9d046965225517c8", - data: "0x7bac65fd000000000000000000000000004e38104adc39cbf4cea9bd8876440a969e3d0b0000000000000000000000009965507d1a55bcc2695c58ba16fb37d819b0a4dc0000000000000000000000002ac240293f12032e103458451de8a8096c5a72e800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", + to: client.ipAsset.ipAssetRegistryClient.address, + data: data, deadline: 111, - signer: "0x", - signature: "0x", + signer: process.env.SEPOLIA_TEST_WALLET_ADDRESS as Hex, + signature: signature, txOptions: { waitForTransaction: waitForTransaction, }, diff --git a/packages/core-sdk/test/integration/ipAsset.test.ts b/packages/core-sdk/test/integration/ipAsset.test.ts index 90fb2979..372d82f3 100644 --- a/packages/core-sdk/test/integration/ipAsset.test.ts +++ b/packages/core-sdk/test/integration/ipAsset.test.ts @@ -1,7 +1,9 @@ import chai from "chai"; -import { StoryClient } from "../../src"; -import { Hex } from "viem"; import chaiAsPromised from "chai-as-promised"; +import { Hex } from "viem"; + +import { StoryClient } from "../../src"; +import { PIL_TYPE } from "../../src/types/resources/license"; import { MockERC721, getStoryClientInSepolia, getTokenId } from "./util"; chai.use(chaiAsPromised); @@ -10,7 +12,7 @@ const expect = chai.expect; let parentIpId: Hex; let childIpId: Hex; let noCommercialLicenseTermsId: string; -describe.skip("IP Asset Functions ", () => { +describe("IP Asset Functions ", () => { let client: StoryClient; before(async function () { client = getStoryClientInSepolia(); @@ -102,4 +104,71 @@ describe.skip("IP Asset Functions ", () => { expect(response.txHash).to.be.a("string").not.empty; }); }); + + describe("NFT Client (SPG)", () => { + let nftContract: Hex; + + before(async () => { + // Create a NFT collection for this test-suite + const txData = await client.nftClient.createNFTCollection({ + name: "test-collection", + symbol: "TEST", + maxSupply: 100, + mintCost: 0n, + txOptions: { + waitForTransaction: true, + }, + }); + + expect(txData.nftContract).to.be.a("string").and.not.empty; + nftContract = txData.nftContract; + }); + + describe("should not throw error when mint and register ip and attach pil terms", async () => { + it("Non-Commercial Remix", async () => { + const txHash = await client.ipAsset.createIpAssetWithPilTerms({ + nftContract, + pilType: PIL_TYPE.NON_COMMERCIAL_REMIX, + metadata: { + metadataURI: "test-uri", + metadata: "test-metadata-hash", + nftMetadata: "test-nft-metadata-hash", + }, + }); + expect(txHash).to.be.a("string").and.not.empty; + }); + + it("Commercial Use", async () => { + const txHash = await client.ipAsset.createIpAssetWithPilTerms({ + nftContract, + pilType: PIL_TYPE.COMMERCIAL_USE, + commercialRevShare: 10, + mintingFee: "100", + currency: "0xB132A6B7AE652c974EE1557A3521D53d18F6739f", + metadata: { + metadataURI: "test-uri", + metadata: "test-metadata-hash", + nftMetadata: "test-nft-metadata-hash", + }, + }); + expect(txHash).to.be.a("string").and.not.empty; + }); + + it("Commercial Remix", async () => { + const txHash = await client.ipAsset.createIpAssetWithPilTerms({ + nftContract, + pilType: PIL_TYPE.COMMERCIAL_REMIX, + commercialRevShare: 10, + mintingFee: "100", + currency: "0xB132A6B7AE652c974EE1557A3521D53d18F6739f", + metadata: { + metadataURI: "test-uri", + metadata: "test-metadata-hash", + nftMetadata: "test-nft-metadata-hash", + }, + }); + expect(txHash).to.be.a("string").and.not.empty; + }); + }); + }); }); diff --git a/packages/core-sdk/test/integration/license.test.ts b/packages/core-sdk/test/integration/license.test.ts index 1e31f5a6..21ea640c 100644 --- a/packages/core-sdk/test/integration/license.test.ts +++ b/packages/core-sdk/test/integration/license.test.ts @@ -1,17 +1,14 @@ import chai from "chai"; import { StoryClient } from "../../src"; -import { createPublicClient, createWalletClient, Hex, http } from "viem"; -import { privateKeyToAccount } from "viem/accounts"; +import { Hex } from "viem"; import chaiAsPromised from "chai-as-promised"; -import { chainStringToViemChain } from "../../src/utils/utils"; -import { MockERC20, MockERC721, getStoryClientInSepolia } from "./util"; +import { MockERC20, MockERC721, getStoryClientInSepolia, getTokenId } from "./util"; chai.use(chaiAsPromised); const expect = chai.expect; -describe.skip("License Functions in storyTestnet", () => { +describe("License Functions", () => { let client: StoryClient; - const account = privateKeyToAccount(process.env.SEPOLIA_WALLET_PRIVATE_KEY as Hex); before(function () { client = getStoryClientInSepolia(); @@ -53,49 +50,12 @@ describe.skip("License Functions in storyTestnet", () => { describe("attach License Terms and mint license tokens", async function () { let ipId: Hex; let licenseId: string; - let tokenId: string; + let tokenId; before(async function () { - const baseConfig = { - chain: chainStringToViemChain("sepolia"), - transport: http(process.env.SEPOLIA_RPC_PROVIDER_URL), - } as const; - const publicClient = createPublicClient(baseConfig); - const walletClient = createWalletClient({ - ...baseConfig, - account, - }); - const { request } = await publicClient.simulateContract({ - abi: [ - { - inputs: [ - { internalType: "address", name: "to", type: "address" }, - { - internalType: "uint256", - name: "tokenId", - type: "uint256", - }, - ], - name: "mintId", - outputs: [{ internalType: "uint256", name: "tokenId", type: "uint256" }], - stateMutability: "nonpayable", - type: "function", - }, - ], - address: MockERC721, - functionName: "mintId", - args: [account.address, BigInt(Math.round(new Date().getTime() / 1000))], - }); - const hash = await walletClient.writeContract(request); - const { logs } = await publicClient.waitForTransactionReceipt({ - hash, - }); - if (logs[0].topics[3]) { - tokenId = parseInt(logs[0].topics[3], 16).toString(); - } - + tokenId = await getTokenId(); const registerResult = await client.ipAsset.register({ tokenContract: MockERC721, - tokenId: tokenId, + tokenId: tokenId!, txOptions: { waitForTransaction: true, }, @@ -132,5 +92,10 @@ describe.skip("License Functions in storyTestnet", () => { expect(result.txHash).to.be.a("string").and.not.empty; expect(result.licenseTokenId).to.be.a("string").and.not.empty; }); + + it("should not throw error when get license terms", async function () { + const result = await client.license.getLicenseTerms(licenseId); + expect(result).not.empty; + }); }); }); diff --git a/packages/core-sdk/test/integration/permission.test.ts b/packages/core-sdk/test/integration/permission.test.ts index bd2e09c7..e072c95a 100644 --- a/packages/core-sdk/test/integration/permission.test.ts +++ b/packages/core-sdk/test/integration/permission.test.ts @@ -3,7 +3,7 @@ import { StoryClient } from "../../src"; import { MockERC721, getStoryClientInSepolia, getTokenId } from "./util"; import { Hex } from "viem"; -describe.skip("Permission Functions", () => { +describe("Permission Functions", () => { let client: StoryClient; before(function () { diff --git a/packages/core-sdk/test/integration/royalty.test.ts b/packages/core-sdk/test/integration/royalty.test.ts index 3e9c202e..f7579d51 100644 --- a/packages/core-sdk/test/integration/royalty.test.ts +++ b/packages/core-sdk/test/integration/royalty.test.ts @@ -7,6 +7,8 @@ import { createWalletClient, PublicClient, WalletClient, + encodeFunctionData, + isBytes, } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import chaiAsPromised from "chai-as-promised"; @@ -16,7 +18,7 @@ import { MockERC721, MockERC20, getTokenId, getStoryClientInSepolia } from "./ut chai.use(chaiAsPromised); const expect = chai.expect; let snapshotId: string; -describe.skip("Test royalty Functions", () => { +describe("Test royalty Functions", () => { let client: StoryClient; let publicClient: PublicClient; let walletClient: WalletClient; @@ -25,7 +27,7 @@ describe.skip("Test royalty Functions", () => { client = getStoryClientInSepolia(); const baseConfig = { chain: chainStringToViemChain("sepolia"), - transport: http(process.env.SEPOLIA_RPC_PROVIDER_URL), + transport: http(process.env.TEST_SEPOLIA_RPC_PROVIDER_URL), } as const; publicClient = createPublicClient(baseConfig); walletClient = createWalletClient({ @@ -51,7 +53,7 @@ describe.skip("Test royalty Functions", () => { const response = await client.license.registerCommercialRemixPIL({ mintingFee: "1", currency: MockERC20, - commercialRevShare: 100, + commercialRevShare: 10000, txOptions: { waitForTransaction: true, }, @@ -72,9 +74,7 @@ describe.skip("Test royalty Functions", () => { before(async () => { ipId1 = await getIpId(); ipId2 = await getIpId(); - console.log("ipId1", ipId1, "ipId2", ipId2); const licenseTermsId = await getCommercialPolicyId(); - console.log("licenseTermsId", licenseTermsId); await attachLicenseTerms(ipId1, licenseTermsId); await client.ipAsset.registerDerivative({ childIpId: ipId2, @@ -86,6 +86,18 @@ describe.skip("Test royalty Functions", () => { }); }); + it("should not throw error when collect royalty tokens", async () => { + const response = await client.royalty.collectRoyaltyTokens({ + parentIpId: ipId1, + royaltyVaultIpId: ipId2, + txOptions: { + waitForTransaction: true, + }, + }); + expect(response.txHash).to.be.a("string").not.empty; + expect(response.royaltyTokensCollected).to.be.a("string").not.empty; + }); + it("should not throw error when pay royalty on behalf", async () => { //1. approve the spender const abi = [ @@ -118,7 +130,7 @@ describe.skip("Test royalty Functions", () => { abi: abi, address: MockERC20, functionName: "approve", - args: [client.royalty.royaltyPolicyLapClient.address, BigInt(100)], + args: [client.royalty.royaltyPolicyLapClient.address, BigInt(100000 * 10 ** 6)], account: walletClient.account, }); const approveHash = await walletClient.writeContract(call); @@ -148,7 +160,7 @@ describe.skip("Test royalty Functions", () => { address: MockERC20, functionName: "mint", account: walletClient.account, - args: [process.env.STORY_TEST_NET_TEST_WALLET_ADDRESS! as Hex, BigInt(1000)], + args: [process.env.SEPOLIA_TEST_WALLET_ADDRESS! as Hex, BigInt(100000 * 10 ** 6)], }); const mintHash = await walletClient.writeContract(request); await waitTx(publicClient, mintHash); @@ -166,7 +178,7 @@ describe.skip("Test royalty Functions", () => { it("should not throw error when snapshot", async () => { const response = await client.royalty.snapshot({ - royaltyVaultIpId: ipId2, + royaltyVaultIpId: ipId1, txOptions: { waitForTransaction: true, }, @@ -175,45 +187,98 @@ describe.skip("Test royalty Functions", () => { expect(response.snapshotId).to.be.a("string"); snapshotId = response.snapshotId!; }); - - it("should not throw error when collect royalty tokens", async () => { - const response = await client.royalty.collectRoyaltyTokens({ - parentIpId: ipId1, - royaltyVaultIpId: ipId2, - txOptions: { - waitForTransaction: true, - }, - }); - expect(response.txHash).to.be.a("string").not.empty; - expect(response.royaltyTokensCollected).to.be.a("string").not.empty; - }); - it("should not throw error when claimable revenue", async () => { const response = await client.royalty.claimableRevenue({ - royaltyVaultIpId: ipId2, + royaltyVaultIpId: ipId1, account: ipId1, snapshotId: snapshotId.toString(), - token: "0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAE", + token: MockERC20, }); expect(response).to.be.a("string"); }); - it("should not throw error when claim revenue", async () => { - const parentIpId = "0x66f90435a01173E727Fffd1BbB5b033a50561325"; - const childIpId = "0x286e816704883a4087e214C89983A7d84219e4cF"; - snapshotId = "1"; - console.log("snapshotId", snapshotId.toString(), "ipId1", ipId1, "ipId2", ipId2); + it("should not throw error when claim revenue by ipAccount", async () => { const response = await client.royalty.claimRevenue({ - royaltyVaultIpId: childIpId, - account: parentIpId, + royaltyVaultIpId: ipId1, snapshotIds: [snapshotId.toString()], - token: "0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAE", + account: ipId1, + token: MockERC20, txOptions: { waitForTransaction: true, }, }); - console.log("response", response); expect(response.claimableToken).to.be.a("string"); }); + + it("should not throw error when claim revenue by ipAccount by EOA", async () => { + const proxyAddress = await client.royalty.getRoyaltyVaultAddress(ipId1); + //1.transfer token to eoa + const iPAccountExecuteResponse = await client.ipAccount.execute({ + to: proxyAddress, + value: 0, + accountAddress: ipId1, + txOptions: { + waitForTransaction: true, + }, + data: encodeFunctionData({ + abi: [ + { + inputs: [ + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "transfer", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + ], + functionName: "transfer", + args: [process.env.SEPOLIA_TEST_WALLET_ADDRESS as Hex, BigInt(10 * 10 ** 6)], + }), + }); + //2. transfer token to royaltyVault,revenue token + const response2 = await client.royalty.payRoyaltyOnBehalf({ + receiverIpId: ipId1, + payerIpId: ipId2, + token: MockERC20, + amount: "10", + txOptions: { + waitForTransaction: true, + }, + }); + const snapshotId = await client.royalty.snapshot({ + royaltyVaultIpId: ipId1, + txOptions: { waitForTransaction: true }, + }); + const claimableRevenue = await client.royalty.claimableRevenue({ + royaltyVaultIpId: ipId1, + account: process.env.SEPOLIA_TEST_WALLET_ADDRESS as Hex, + snapshotId: snapshotId.snapshotId!, + token: MockERC20, + }); + const response = await client.royalty.claimRevenue({ + royaltyVaultIpId: ipId1, + snapshotIds: [snapshotId.snapshotId!], + token: MockERC20, + txOptions: { + waitForTransaction: true, + }, + }); + }); }); }); diff --git a/packages/core-sdk/test/integration/util.ts b/packages/core-sdk/test/integration/util.ts index 37194840..0be88421 100644 --- a/packages/core-sdk/test/integration/util.ts +++ b/packages/core-sdk/test/integration/util.ts @@ -6,7 +6,7 @@ import { StoryClient, StoryConfig } from "../../src"; export const getTokenId = async (): Promise => { const baseConfig = { chain: chainStringToViemChain("sepolia"), - transport: http(process.env.SEPOLIA_RPC_PROVIDER_URL), + transport: http(process.env.TEST_SEPOLIA_RPC_PROVIDER_URL), } as const; const publicClient = createPublicClient(baseConfig); const walletClient = createWalletClient({ @@ -43,7 +43,7 @@ export const MockERC721 = "0x7ee32b8B515dEE0Ba2F25f612A04a731eEc24F49"; export const getStoryClientInSepolia = (): StoryClient => { const config: StoryConfig = { chainId: "sepolia", - transport: http(process.env.SEPOLIA_RPC_PROVIDER_URL), + transport: http(process.env.TEST_SEPOLIA_RPC_PROVIDER_URL), account: privateKeyToAccount(process.env.SEPOLIA_WALLET_PRIVATE_KEY as Hex), }; return StoryClient.newClient(config); diff --git a/packages/core-sdk/test/unit/resources/license.test.ts b/packages/core-sdk/test/unit/resources/license.test.ts index adb828e3..0b5e00e5 100644 --- a/packages/core-sdk/test/unit/resources/license.test.ts +++ b/packages/core-sdk/test/unit/resources/license.test.ts @@ -2,8 +2,12 @@ import chai from "chai"; import { createMock } from "../testUtils"; import * as sinon from "sinon"; import { LicenseClient } from "../../../src"; -import { PublicClient, WalletClient, Account } from "viem"; +import { PublicClient, WalletClient, Account, zeroAddress, Hex } from "viem"; import chaiAsPromised from "chai-as-promised"; +import { + PiLicenseTemplateGetLicenseTermsResponse, + RoyaltyPolicyLapClient, +} from "../../../src/abi/generated"; chai.use(chaiAsPromised); const expect = chai.expect; const txHash = "0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997"; @@ -20,6 +24,11 @@ describe("Test LicenseClient", function () { accountMock.address = "0x73fcb515cee99e4991465ef586cfe2b072ebb512"; walletMock.account = accountMock; licenseClient = new LicenseClient(rpcMock, walletMock); + licenseClient.royaltyPolicyLAPClient = new RoyaltyPolicyLapClient( + rpcMock, + walletMock, + zeroAddress, + ); }); afterEach(function () { @@ -58,8 +67,8 @@ describe("Test LicenseClient", function () { .returns([ { licenseTermsId: BigInt(1), - licenseTemplate: "0x", - licenseTerms: "0x", + licenseTemplate: zeroAddress, + licenseTerms: zeroAddress, }, ]); @@ -102,7 +111,7 @@ describe("Test LicenseClient", function () { const result = await licenseClient.registerCommercialUsePIL({ mintingFee: "1", - currency: "0x", + currency: zeroAddress, }); expect(result.licenseTermsId).to.equal("1"); @@ -116,7 +125,7 @@ describe("Test LicenseClient", function () { const result = await licenseClient.registerCommercialUsePIL({ mintingFee: "1", - currency: "0x", + currency: zeroAddress, }); expect(result.txHash).to.equal(txHash); @@ -132,14 +141,14 @@ describe("Test LicenseClient", function () { .returns([ { licenseTermsId: BigInt(1), - licenseTemplate: "0x", - licenseTerms: "0x", + licenseTemplate: zeroAddress, + licenseTerms: zeroAddress, }, ]); const result = await licenseClient.registerCommercialUsePIL({ mintingFee: "1", - currency: "0x", + currency: zeroAddress, txOptions: { waitForTransaction: true, }, @@ -160,7 +169,7 @@ describe("Test LicenseClient", function () { try { await licenseClient.registerCommercialUsePIL({ mintingFee: "1", - currency: "0x", + currency: zeroAddress, }); } catch (error) { expect((error as Error).message).equal( @@ -179,7 +188,7 @@ describe("Test LicenseClient", function () { const result = await licenseClient.registerCommercialRemixPIL({ mintingFee: "1", commercialRevShare: 100, - currency: "0x", + currency: zeroAddress, }); expect(result.licenseTermsId).to.equal("1"); @@ -194,7 +203,7 @@ describe("Test LicenseClient", function () { const result = await licenseClient.registerCommercialRemixPIL({ mintingFee: "1", commercialRevShare: 100, - currency: "0x", + currency: zeroAddress, }); expect(result.txHash).to.equal(txHash); @@ -210,15 +219,15 @@ describe("Test LicenseClient", function () { .returns([ { licenseTermsId: BigInt(1), - licenseTemplate: "0x", - licenseTerms: "0x", + licenseTemplate: zeroAddress, + licenseTerms: zeroAddress, }, ]); const result = await licenseClient.registerCommercialRemixPIL({ mintingFee: "1", commercialRevShare: 100, - currency: "0x", + currency: zeroAddress, txOptions: { waitForTransaction: true, }, @@ -235,11 +244,12 @@ describe("Test LicenseClient", function () { sinon .stub(licenseClient.licenseTemplateClient, "registerLicenseTerms") .throws(new Error("request fail.")); + try { await licenseClient.registerCommercialRemixPIL({ mintingFee: "1", commercialRevShare: 100, - currency: "0x", + currency: zeroAddress, }); } catch (error) { expect((error as Error).message).equal( @@ -255,12 +265,12 @@ describe("Test LicenseClient", function () { try { await licenseClient.attachLicenseTerms({ - ipId: "0x", + ipId: zeroAddress, licenseTermsId: "1", }); } catch (error) { expect((error as Error).message).equal( - "Failed to attach license terms: The IP with id 0x is not registered.", + "Failed to attach license terms: The IP with id 0x0000000000000000000000000000000000000000 is not registered.", ); } }); @@ -271,7 +281,7 @@ describe("Test LicenseClient", function () { try { await licenseClient.attachLicenseTerms({ - ipId: "0x", + ipId: zeroAddress, licenseTermsId: "1", }); } catch (error) { @@ -290,12 +300,12 @@ describe("Test LicenseClient", function () { try { await licenseClient.attachLicenseTerms({ - ipId: "0x", + ipId: zeroAddress, licenseTermsId: "1", }); } catch (error) { expect((error as Error).message).equal( - "Failed to attach license terms: License terms id 1 is already attached to the IP with id 0x.", + "Failed to attach license terms: License terms id 1 is already attached to the IP with id 0x0000000000000000000000000000000000000000.", ); } }); @@ -309,13 +319,32 @@ describe("Test LicenseClient", function () { sinon.stub(licenseClient.licensingModuleClient, "attachLicenseTerms").resolves(txHash); const result = await licenseClient.attachLicenseTerms({ - ipId: "0x", + ipId: zeroAddress, licenseTermsId: "1", }); expect(result.txHash).to.equal(txHash); }); + it("should throw invalid address when call when call attachLicenseTerms given a invalid licenseTemplate address", async function () { + sinon.stub(licenseClient.ipAssetRegistryClient, "isRegistered").resolves(true); + sinon.stub(licenseClient.piLicenseTemplateReadOnlyClient, "exists").resolves(true); + sinon + .stub(licenseClient.licenseRegistryReadOnlyClient, "hasIpAttachedLicenseTerms") + .resolves(true); + + try { + await licenseClient.attachLicenseTerms({ + ipId: zeroAddress, + licenseTermsId: "1", + licenseTemplate: "invalid address" as Hex, + }); + } catch (error) { + expect((error as Error).message).contain( + `Failed to attach license terms: Address "invalid address" is invalid`, + ); + } + }); it("should return txHash when call attachLicenseTerms given args is correct and waitForTransaction of true", async function () { sinon.stub(licenseClient.ipAssetRegistryClient, "isRegistered").resolves(true); sinon.stub(licenseClient.piLicenseTemplateReadOnlyClient, "exists").resolves(true); @@ -325,7 +354,7 @@ describe("Test LicenseClient", function () { sinon.stub(licenseClient.licensingModuleClient, "attachLicenseTerms").resolves(txHash); const result = await licenseClient.attachLicenseTerms({ - ipId: "0x", + ipId: zeroAddress, licenseTermsId: "1", txOptions: { waitForTransaction: true, @@ -342,12 +371,49 @@ describe("Test LicenseClient", function () { try { await licenseClient.mintLicenseTokens({ - licensorIpId: "0x", + licensorIpId: zeroAddress, licenseTermsId: "1", }); } catch (error) { expect((error as Error).message).equal( - "Failed to mint license tokens: The licensor IP with id 0x is not registered.", + "Failed to mint license tokens: The licensor IP with id 0x0000000000000000000000000000000000000000 is not registered.", + ); + } + }); + + it("should throw invalid address when call mintLicenseTokens given invalid licenseTemplate address", async function () { + sinon.stub(licenseClient.ipAssetRegistryClient, "isRegistered").resolves(true); + sinon.stub(licenseClient.piLicenseTemplateReadOnlyClient, "exists").resolves(true); + + try { + await licenseClient.mintLicenseTokens({ + licensorIpId: zeroAddress, + licenseTermsId: "1", + licenseTemplate: "invalid address" as Hex, + }); + } catch (error) { + expect((error as Error).message).contain( + `Failed to mint license tokens: Address "invalid address" is invalid`, + ); + } + }); + + it("should throw invalid address when call mintLicenseTokens given invalid receiver address", async function () { + sinon.stub(licenseClient.ipAssetRegistryClient, "isRegistered").resolves(true); + sinon.stub(licenseClient.piLicenseTemplateReadOnlyClient, "exists").resolves(true); + sinon + .stub(licenseClient.licenseRegistryReadOnlyClient, "hasIpAttachedLicenseTerms") + .resolves(true); + + try { + await licenseClient.mintLicenseTokens({ + licensorIpId: zeroAddress, + licenseTermsId: "1", + receiver: "invalid address" as Hex, + }); + } catch (error) { + expect((error as Error).message).contain( + `Failed to mint license tokens: Address "invalid address" is invalid`, ); } }); @@ -358,7 +424,7 @@ describe("Test LicenseClient", function () { try { await licenseClient.mintLicenseTokens({ - licensorIpId: "0x", + licensorIpId: zeroAddress, licenseTermsId: "1", }); } catch (error) { @@ -377,12 +443,12 @@ describe("Test LicenseClient", function () { try { await licenseClient.mintLicenseTokens({ - licensorIpId: "0x", + licensorIpId: zeroAddress, licenseTermsId: "1", }); } catch (error) { expect((error as Error).message).equal( - "Failed to mint license tokens: License terms id 1 is not attached to the IP with id 0x.", + "Failed to mint license tokens: License terms id 1 is not attached to the IP with id 0x0000000000000000000000000000000000000000.", ); } }); @@ -396,7 +462,7 @@ describe("Test LicenseClient", function () { sinon.stub(licenseClient.licensingModuleClient, "mintLicenseTokens").resolves(txHash); const result = await licenseClient.mintLicenseTokens({ - licensorIpId: "0x", + licensorIpId: zeroAddress, licenseTermsId: "1", }); @@ -412,18 +478,18 @@ describe("Test LicenseClient", function () { sinon.stub(licenseClient.licensingModuleClient, "mintLicenseTokens").resolves(txHash); sinon.stub(licenseClient.licensingModuleClient, "parseTxLicenseTokensMintedEvent").returns([ { - caller: "0x", - licensorIpId: "0x", - licenseTemplate: "0x", + caller: zeroAddress, + licensorIpId: zeroAddress, + licenseTemplate: zeroAddress, licenseTermsId: BigInt(1), amount: BigInt(1), - receiver: "0x", + receiver: zeroAddress, startLicenseTokenId: BigInt(1), }, ]); const result = await licenseClient.mintLicenseTokens({ - licensorIpId: "0x", + licensorIpId: zeroAddress, licenseTermsId: "1", txOptions: { waitForTransaction: true, @@ -434,4 +500,51 @@ describe("Test LicenseClient", function () { expect(result.licenseTokenId).to.equal("1"); }); }); + + describe("Test licenseClient.getLicenseTerms", async function () { + it("should return license terms when call getLicenseTerms given licenseTermsId is exist", async function () { + const mockLicenseTermsResponse: PiLicenseTemplateGetLicenseTermsResponse = { + terms: { + transferable: true, + royaltyPolicy: zeroAddress, + mintingFee: BigInt(1), + expiration: BigInt(1), + commercialUse: true, + commercialAttribution: true, + commercializerChecker: zeroAddress, + commercializerCheckerData: zeroAddress, + commercialRevShare: 100, + commercialRevCelling: BigInt(1), + derivativesAllowed: true, + derivativesAttribution: true, + derivativesApproval: true, + derivativesReciprocal: true, + derivativeRevCelling: BigInt(1), + currency: zeroAddress, + uri: "string", + }, + }; + sinon + .stub(licenseClient.piLicenseTemplateReadOnlyClient, "getLicenseTerms") + .resolves(mockLicenseTermsResponse); + + const result = await licenseClient.getLicenseTerms("1"); + + expect(result).to.equal(mockLicenseTermsResponse); + }); + + it("should throw error when call getLicenseTerms given licenseTermsId is not exist", async function () { + sinon + .stub(licenseClient.piLicenseTemplateReadOnlyClient, "getLicenseTerms") + .throws(new Error("Given licenseTermsId is not exist.")); + + try { + await licenseClient.getLicenseTerms("1"); + } catch (error) { + expect((error as Error).message).equal( + "Failed to get license terms: Given licenseTermsId is not exist.", + ); + } + }); + }); }); diff --git a/packages/core-sdk/test/unit/resources/nftClient.test.ts b/packages/core-sdk/test/unit/resources/nftClient.test.ts new file mode 100644 index 00000000..516c9f25 --- /dev/null +++ b/packages/core-sdk/test/unit/resources/nftClient.test.ts @@ -0,0 +1,95 @@ +import chai, { expect } from "chai"; +import chaiAsPromised from "chai-as-promised"; +import * as sinon from "sinon"; +import { Hex, PublicClient, WalletClient } from "viem"; + +import { CreateNFTCollectionRequest, NftClient } from "../../../src"; +import { createMock } from "../testUtils"; + +chai.use(chaiAsPromised); + +describe("Test NftClient", function () { + let nftClient: NftClient; + let rpcMock: PublicClient; + let walletMock: WalletClient; + + const mock = { + txHash: "0x063834efe214f4199b1ad7181ce8c5ced3e15d271c8e866da7c89e86ee629cfb", + nftContract: "0x73fcb515cee99e4991465ef586cfe2b072ebb512", + }; + + beforeEach(function () { + rpcMock = createMock(); + walletMock = createMock(); + nftClient = new NftClient(rpcMock, walletMock); + }); + + afterEach(function () { + sinon.restore(); + }); + + describe("test for CreateNFTCollection", () => { + const reqBody: CreateNFTCollectionRequest = { + name: "test-collection", + symbol: "TEST", + maxSupply: 100, + mintCost: 0n, + owner: "0x0000000000000000000000000000000000000001" as Hex, + txOptions: { + waitForTransaction: false, + }, + }; + + it("should throw simulateContract error if simulateContract throws an error", async () => { + rpcMock.simulateContract = sinon.stub().throws(new Error("simulateContract error")); + rpcMock.waitForTransactionReceipt = sinon.stub().resolves(); + walletMock.writeContract = sinon.stub().resolves(mock.txHash); + + try { + await nftClient.createNFTCollection(reqBody); + } catch (err) { + expect((err as Error).message.includes("simulateContract error")); + } + }); + + it("should throw writeContract error if writeContract throws an error", async () => { + rpcMock.simulateContract = sinon.stub().resolves({ request: null }); + walletMock.writeContract = sinon.stub().throws(new Error("writeContract error")); + + try { + await nftClient.createNFTCollection(reqBody); + } catch (err) { + expect((err as Error).message.includes("writeContract error")); + } + }); + + it("should return txHash and nftContract if txOptions.waitForTransaction is truthy", async () => { + rpcMock.simulateContract = sinon.stub().resolves({ request: null }); + rpcMock.waitForTransactionReceipt = sinon.stub().resolves(); + walletMock.writeContract = sinon.stub().resolves(mock.txHash); + + sinon.stub(nftClient.spgClient, "parseTxCollectionCreatedEvent").returns([ + { + nftContract: "0x73fcb515cee99e4991465ef586cfe2b072ebb512", + }, + ]); + + const result = await nftClient.createNFTCollection({ + ...reqBody, + txOptions: { + waitForTransaction: true, + }, + }); + expect(result.txHash).to.equal(mock.txHash); + expect(result.nftContract).to.equal(mock.nftContract); + }); + + it("should return txHash if txOptions.waitForTransaction is falsy", async () => { + rpcMock.simulateContract = sinon.stub().resolves({ request: null }); + walletMock.writeContract = sinon.stub().resolves(mock.txHash); + + const result = await nftClient.createNFTCollection(reqBody); + expect(result.txHash).to.equal(mock.txHash); + }); + }); +}); diff --git a/packages/core-sdk/test/unit/resources/royalty.test.ts b/packages/core-sdk/test/unit/resources/royalty.test.ts index ac6a3a8b..ca62622b 100644 --- a/packages/core-sdk/test/unit/resources/royalty.test.ts +++ b/packages/core-sdk/test/unit/resources/royalty.test.ts @@ -60,7 +60,7 @@ describe("Test RoyaltyClient", function () { }); } catch (err) { expect((err as Error).message).equals( - "Failed to collect royalty tokens: The royalty vault IP with id 0x73fcb515cee99e4991465ef586cfe2b072ebb512 is not registered.", + "Failed to collect royalty tokens: The royalty vault IP with id 0x73fCB515cEE99e4991465ef586CfE2B072EbB512 is not registered.", ); } }); @@ -78,7 +78,7 @@ describe("Test RoyaltyClient", function () { }); } catch (err) { expect((err as Error).message).equals( - "Failed to collect royalty tokens: The royalty vault IP with id 0x73fcb515cee99e4991465ef586cfe2b072ebb512 address is not set.", + "Failed to collect royalty tokens: The royalty vault IP with id 0x73fCB515cEE99e4991465ef586CfE2B072EbB512 address is not set.", ); } }); @@ -96,7 +96,7 @@ describe("Test RoyaltyClient", function () { }); } catch (err) { expect((err as Error).message).equals( - "Failed to collect royalty tokens: The royalty vault IP with id 0x73fcb515cee99e4991465ef586cfe2b072ebb512 address is not set.", + "Failed to collect royalty tokens: The royalty vault IP with id 0x73fCB515cEE99e4991465ef586CfE2B072EbB512 address is not set.", ); } }); @@ -234,7 +234,7 @@ describe("Test RoyaltyClient", function () { }); } catch (err) { expect((err as Error).message).equals( - "Failed to calculate claimable revenue: The royalty vault IP with id 0x73fcb515cee99e4991465ef586cfe2b072ebb512 is not registered.", + "Failed to calculate claimable revenue: The royalty vault IP with id 0x73fCB515cEE99e4991465ef586CfE2B072EbB512 is not registered.", ); } }); @@ -254,7 +254,7 @@ describe("Test RoyaltyClient", function () { }); } catch (err) { expect((err as Error).message).equals( - "Failed to calculate claimable revenue: The royalty vault IP with id 0x73fcb515cee99e4991465ef586cfe2b072ebb512 address is not set.", + "Failed to calculate claimable revenue: The royalty vault IP with id 0x73fCB515cEE99e4991465ef586CfE2B072EbB512 address is not set.", ); } }); @@ -295,7 +295,7 @@ describe("Test RoyaltyClient", function () { }); } catch (err) { expect((err as Error).message).equals( - "Failed to claim revenue: The royalty vault IP with id 0x73fcb515cee99e4991465ef586cfe2b072ebb512 is not registered.", + "Failed to claim revenue: The royalty vault IP with id 0x73fCB515cEE99e4991465ef586CfE2B072EbB512 is not registered.", ); } }); @@ -315,7 +315,7 @@ describe("Test RoyaltyClient", function () { }); } catch (err) { expect((err as Error).message).equals( - "Failed to claim revenue: The royalty vault IP with id 0x73fcb515cee99e4991465ef586cfe2b072ebb512 address is not set.", + "Failed to claim revenue: The royalty vault IP with id 0x73fCB515cEE99e4991465ef586CfE2B072EbB512 address is not set.", ); } }); @@ -341,7 +341,7 @@ describe("Test RoyaltyClient", function () { expect(result.txHash).equals(txHash); }); - it("should return txHash when call claimRevenue given correct args and waitForTransaction is true", async function () { + it("should return txHash when call claimRevenue given correct args and waitForTransaction is true by ip account", async function () { sinon.stub(royaltyClient.ipAssetRegistryClient, "isRegistered").resolves(true); sinon .stub(royaltyClient.royaltyPolicyLapClient, "getRoyaltyData") @@ -375,6 +375,40 @@ describe("Test RoyaltyClient", function () { expect(result.txHash).equals(txHash); expect(result.claimableToken).equals("1"); }); + + it("should return txHash when call claimRevenue given correct args and waitForTransaction is true by EOA", async function () { + sinon.stub(royaltyClient.ipAssetRegistryClient, "isRegistered").resolves(true); + sinon + .stub(royaltyClient.royaltyPolicyLapClient, "getRoyaltyData") + .resolves([ + true, + "0x73fcb515cee99e4991465ef586cfe2b072ebb512", + 1, + ["0x73fcb515cee99e4991465ef586cfe2b072ebb512"], + [1], + ]); + sinon + .stub(IpRoyaltyVaultImplClient.prototype, "claimRevenueBySnapshotBatch") + .resolves(txHash); + sinon.stub(royaltyClient.ipAccountClient, "execute").resolves({ txHash }); + sinon.stub(IpRoyaltyVaultImplClient.prototype, "parseTxRevenueTokenClaimedEvent").returns([ + { + claimer: "0x73fcb515cee99e4991465ef586cfe2b072ebb512", + token: "0x73fcb515cee99e4991465ef586cfe2b072ebb512", + amount: 1, + }, + ]); + + const result = await royaltyClient.claimRevenue({ + snapshotIds: ["1"], + token: "0x73fcb515cee99e4991465ef586cfe2b072ebb512", + royaltyVaultIpId: "0x73fcb515cee99e4991465ef586cfe2b072ebb512", + txOptions: { waitForTransaction: true }, + }); + + expect(result.txHash).equals(txHash); + expect(result.claimableToken).equals("1"); + }); }); describe("Test royaltyClient.snapshot", async function () { @@ -387,7 +421,7 @@ describe("Test RoyaltyClient", function () { }); } catch (err) { expect((err as Error).message).equals( - "Failed to snapshot: The royalty vault IP with id 0x73fcb515cee99e4991465ef586cfe2b072ebb512 is not registered.", + "Failed to snapshot: The royalty vault IP with id 0x73fCB515cEE99e4991465ef586CfE2B072EbB512 is not registered.", ); } }); @@ -404,7 +438,7 @@ describe("Test RoyaltyClient", function () { }); } catch (err) { expect((err as Error).message).equals( - "Failed to snapshot: The royalty vault IP with id 0x73fcb515cee99e4991465ef586cfe2b072ebb512 address is not set.", + "Failed to snapshot: The royalty vault IP with id 0x73fCB515cEE99e4991465ef586CfE2B072EbB512 address is not set.", ); } }); diff --git a/packages/core-sdk/test/unit/utils/getLicenseTermsByType.test.ts b/packages/core-sdk/test/unit/utils/getLicenseTermsByType.test.ts new file mode 100644 index 00000000..64b0b4ce --- /dev/null +++ b/packages/core-sdk/test/unit/utils/getLicenseTermsByType.test.ts @@ -0,0 +1,175 @@ +import { Hex, zeroAddress } from "viem"; +import { PIL_TYPE } from "../../../src/types/resources/license"; +import { getLicenseTermByType } from "../../../src/utils/getLicenseTermsByType"; +import { expect } from "chai"; + +describe("Get License Terms By Type", () => { + it("it should return no commercial license terms when call getLicenseTermByType given NON_COMMERCIAL_REMIX", async () => { + const result = getLicenseTermByType(PIL_TYPE.NON_COMMERCIAL_REMIX); + expect(result).to.deep.include({ + transferable: true, + commercialAttribution: false, + commercialRevCelling: 0n, + commercialRevShare: 0, + commercialUse: false, + commercializerChecker: "0x0000000000000000000000000000000000000000", + commercializerCheckerData: "0x0000000000000000000000000000000000000000", + currency: "0x0000000000000000000000000000000000000000", + derivativeRevCelling: 0n, + derivativesAllowed: true, + derivativesApproval: false, + derivativesAttribution: true, + derivativesReciprocal: true, + expiration: 0n, + mintingFee: 0n, + royaltyPolicy: "0x0000000000000000000000000000000000000000", + uri: "", + }); + }); + + describe("Get Commercial License Terms", () => { + it("it should throw when call getLicenseTermByType given COMMERCIAL_USE without terms", async () => { + expect(() => getLicenseTermByType(PIL_TYPE.COMMERCIAL_USE)).to.throw( + "mintingFee currency are required for commercial use PIL.", + ); + }); + + it("it should throw when call getLicenseTermByType given COMMERCIAL_USE without mintFee", async () => { + expect(() => + getLicenseTermByType(PIL_TYPE.COMMERCIAL_USE, { + currency: zeroAddress, + royaltyPolicyLAPAddress: zeroAddress, + }), + ).to.throw("mintingFee currency are required for commercial use PIL."); + }); + + it("it should throw when call getLicenseTermByType given COMMERCIAL_USE without currency", async () => { + expect(() => + getLicenseTermByType(PIL_TYPE.COMMERCIAL_USE, { + royaltyPolicyLAPAddress: zeroAddress, + mintingFee: "1", + }), + ).to.throw("mintingFee currency are required for commercial use PIL."); + }); + + it("it should throw when call getLicenseTermByType given COMMERCIAL_USE and wrong royaltyAddress", async () => { + expect(() => + getLicenseTermByType(PIL_TYPE.COMMERCIAL_USE, { + royaltyPolicyLAPAddress: "wrong" as Hex, + mintingFee: "1", + currency: zeroAddress, + }), + ).to.throw(`Address "wrong" is invalid.`); + }); + + it("it should return commercial license terms when call getLicenseTermByType given COMMERCIAL_USE and correct args", async () => { + const result = getLicenseTermByType(PIL_TYPE.COMMERCIAL_USE, { + royaltyPolicyLAPAddress: zeroAddress, + mintingFee: "1", + currency: zeroAddress, + }); + expect(result).to.deep.contain({ + commercialAttribution: true, + commercialRevCelling: 0n, + commercialRevShare: 0, + commercialUse: true, + commercializerChecker: "0x0000000000000000000000000000000000000000", + commercializerCheckerData: "0x0000000000000000000000000000000000000000", + currency: "0x0000000000000000000000000000000000000000", + derivativeRevCelling: 0n, + derivativesAllowed: true, + derivativesApproval: false, + derivativesAttribution: true, + derivativesReciprocal: false, + expiration: 0n, + mintingFee: 1n, + royaltyPolicy: "0x0000000000000000000000000000000000000000", + transferable: true, + uri: "", + }); + }); + }); + + describe("Get Commercial remix License Terms", () => { + it("it should throw when call getLicenseTermByType given COMMERCIAL_REMIX without terms", async () => { + expect(() => getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX)).to.throw( + "mintingFee, currency and commercialRevShare are required for commercial remix PIL.", + ); + }); + + it("it should throw when call getLicenseTermByType given COMMERCIAL_REMIX without mintFee", async () => { + expect(() => + getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { + currency: zeroAddress, + royaltyPolicyLAPAddress: zeroAddress, + commercialRevShare: 100, + }), + ).to.throw( + "mintingFee, currency and commercialRevShare are required for commercial remix PIL.", + ); + }); + + it("it should throw when call getLicenseTermByType given COMMERCIAL_REMIX without currency", async () => { + expect(() => + getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { + royaltyPolicyLAPAddress: zeroAddress, + mintingFee: "1", + commercialRevShare: 100, + }), + ).to.throw( + "mintingFee, currency and commercialRevShare are required for commercial remix PIL.", + ); + }); + + it("it should throw when call getLicenseTermByType given COMMERCIAL_REMIX and wrong royaltyAddress", async () => { + expect(() => + getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { + royaltyPolicyLAPAddress: "wrong" as Hex, + mintingFee: "1", + currency: zeroAddress, + commercialRevShare: 100, + }), + ).to.throw(`Address "wrong" is invalid.`); + }); + + it("it should throw when call getLicenseTermByType given COMMERCIAL_REMIX without commercialRevShare ", async () => { + expect(() => + getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { + royaltyPolicyLAPAddress: "wrong" as Hex, + mintingFee: "1", + currency: zeroAddress, + }), + ).to.throw( + `mintingFee, currency and commercialRevShare are required for commercial remix PIL.`, + ); + }); + + it("it should return commercial license terms when call getLicenseTermByType given COMMERCIAL_REMIX and correct args", async () => { + const result = getLicenseTermByType(PIL_TYPE.COMMERCIAL_REMIX, { + royaltyPolicyLAPAddress: zeroAddress, + mintingFee: "1", + currency: zeroAddress, + commercialRevShare: 100, + }); + expect(result).to.deep.contain({ + commercialAttribution: true, + commercialRevCelling: 0n, + commercialRevShare: 100, + commercialUse: true, + commercializerChecker: "0x0000000000000000000000000000000000000000", + commercializerCheckerData: "0x0000000000000000000000000000000000000000", + currency: "0x0000000000000000000000000000000000000000", + derivativeRevCelling: 0n, + derivativesAllowed: true, + derivativesApproval: false, + derivativesAttribution: true, + derivativesReciprocal: true, + expiration: 0n, + mintingFee: 1n, + royaltyPolicy: "0x0000000000000000000000000000000000000000", + transferable: true, + uri: "", + }); + }); + }); +}); diff --git a/packages/core-sdk/tsconfig.json b/packages/core-sdk/tsconfig.json index b844b905..3df7de46 100644 --- a/packages/core-sdk/tsconfig.json +++ b/packages/core-sdk/tsconfig.json @@ -5,7 +5,7 @@ "module": "ESNext", "outDir": "dist", "types": ["mocha"], - "lib": ["dom"] + "lib": ["dom", "es2015"] }, "include": ["src/**/*", "test/**/*"] } diff --git a/packages/wagmi-generater/wagmi.config.ts b/packages/wagmi-generater/wagmi.config.ts index a20946d4..bf2734d7 100644 --- a/packages/wagmi-generater/wagmi.config.ts +++ b/packages/wagmi-generater/wagmi.config.ts @@ -1,166 +1,192 @@ -import {defineConfig} from '@wagmi/cli' -import {blockExplorer} from '@wagmi/cli/plugins' -import {sdk} from './sdk' -import type {Evaluate} from "@wagmi/cli/src/types"; -import type {ContractConfig} from "@wagmi/cli/src/config"; -import {resolveProxyContracts} from "./resolveProxyContracts"; +import { defineConfig } from "@wagmi/cli"; +import { blockExplorer } from "@wagmi/cli/plugins"; +import { sdk } from "./sdk"; +import type { Evaluate } from "@wagmi/cli/src/types"; +import type { ContractConfig } from "@wagmi/cli/src/config"; +import { resolveProxyContracts } from "./resolveProxyContracts"; const storyTestnetId = 1513; const sepoliaChainId = 11155111; -import 'dotenv/config'; +import "dotenv/config"; export default defineConfig(async () => { - const contracts: Evaluate>[] = [ - { - name: "AccessController", address: { - [sepoliaChainId]: "0xF9936a224b3Deb6f9A4645ccAfa66f7ECe83CF0A", - // [storyTestnetId]: "0x7e253Df9b0fC872746877Fa362b2cAf32712d770", - } + const contracts: Evaluate>[] = [ + { + name: "AccessController", + address: { + [sepoliaChainId]: "0xF9936a224b3Deb6f9A4645ccAfa66f7ECe83CF0A", + // [storyTestnetId]: "0x7e253Df9b0fC872746877Fa362b2cAf32712d770", + }, + }, + { + name: "DisputeModule", + address: { + [sepoliaChainId]: "0xEB7B1dd43B81A7be1fA427515a2b173B454A9832", + // [storyTestnetId]: "0x6d54456Ae5DCbDC0C9E2713cC8E650fE4f445c7C", + }, + }, + { + name: "IPAccountImpl", + address: { + [sepoliaChainId]: "0x36a5f0D61f6Bab3C6Dde211E5a6762Cb18a8060d", + // [storyTestnetId]: "0x38cAfD16502B1d61c6399A18d6Fa1Ea8CEca3678", + }, + }, + { + name: "IPAssetRegistry", + address: { + [sepoliaChainId]: "0xd43fE0d865cb5C26b1351d3eAf2E3064BE3276F6", + // [storyTestnetId]: "0x862de97662a1231FFc14038eC1BE93aB129D2169", + }, + }, + { + name: "IpRoyaltyVaultImpl", + address: { + [sepoliaChainId]: "0xD6c2AfB61085f1359d47159f2271BDD0EeBf19C2", + // [storyTestnetId]: "0x8Be22cc2D13ADF496a417D9C616dA4a253c68Af8", + }, + }, + { + name: "LicenseRegistry", + address: { + [sepoliaChainId]: "0x4f4b1bf7135C7ff1462826CCA81B048Ed19562ed", + // [storyTestnetId]: "0x0c3D467537FAd845a78728CEdc3D9447338c5422", + }, + }, + { + name: "LicenseToken", + address: { + [sepoliaChainId]: "0x1333c78A821c9a576209B01a16dDCEF881cAb6f2", + // [storyTestnetId]: "0xD40b7bCA204f96a346021e31c9ad54FF495226e7", + }, + }, + { + name: "LicensingModule", + address: { + [sepoliaChainId]: "0xe89b0EaA8a0949738efA80bB531a165FB3456CBe", + // [storyTestnetId]: "0xEeDDE5529122b621105798860F235c28FD3aBA40", + }, + }, + { + name: "PILicenseTemplate", + address: { + [sepoliaChainId]: "0x260B6CB6284c89dbE660c0004233f7bB99B5edE7", + // [storyTestnetId]: "0xd0Be223ae9719bBD93447ecf5289319CCf8cA227", + }, + }, + { + name: "ModuleRegistry", + address: { + [sepoliaChainId]: "0x2E0a668289D5C4Da6a2264aC8DF03cd600c7aAB8", + // [storyTestnetId]: "0xf2965E3B6251905Dd1E8671077760D07b0408cf2", + }, + }, + { + name: "RoyaltyModule", + address: { + [sepoliaChainId]: "0xFAE961dd2b87CD5818dbCDc2591e6AB0b50E96b0", + // [storyTestnetId]: "0x551AD8CD7893003cE00500aC2aCF1E327763D9f6", + }, + }, + { + name: "RoyaltyPolicyLAP", + address: { + [sepoliaChainId]: "0xAAbaf349C7a2A84564F9CC4Ac130B3f19A718E86", + // [storyTestnetId]: "0x2EcdB5bD12a037dCb9De0Ab7957f35FEeF758eA6", + }, + }, + { + name: "SPG", + address: { + [sepoliaChainId]: "0x69415CE984A79a3Cfbe3F51024C63b6C107331e3", + // [storyTestnetId]: "0x2EcdB5bD12a037dCb9De0Ab7957f35FEeF758eA6", + }, + }, + { + name: "SPGNFTBeacon", + address: { + [sepoliaChainId]: "0x027D258659FBdda9033f9c008AF166239EBa67c1", + // [storyTestnetId]: "0x2EcdB5bD12a037dCb9De0Ab7957f35FEeF758eA6", + }, + }, + { + name: "SPGNFTImpl", + address: { + [sepoliaChainId]: "0xDb6480C00B570324A122A6B35F9CAC0F87BDb3e6", + // [storyTestnetId]: "0x2EcdB5bD12a037dCb9De0Ab7957f35FEeF758eA6", + }, + }, + ]; + return { + out: "../core-sdk/src/abi/generated.ts", + contracts: [], + plugins: [ + blockExplorer({ + baseUrl: "https://api-sepolia.etherscan.io/api", + name: "Etherscan", + getAddress: await resolveProxyContracts({ + baseUrl: "https://rpc.sepolia.org", + contracts: contracts, + chainId: sepoliaChainId, + }), + contracts: contracts, + apiKey: process.env.API_KEY, + }), + sdk({ + permissionLessSDK: true, + whiteList: { + AccessController: ["PermissionSet", "setPermission"], + DisputeModule: [ + "DisputeCancelled", + "DisputeRaised", + "DisputeResolved", + "cancelDispute", + "raiseDispute", + "resolveDispute", + ], + IPAccountImpl: ["execute", "executeWithSig"], + IPAssetRegistry: ["IPRegistered", "ipId", "isRegistered", "register"], + IpRoyaltyVaultImpl: [ + "claimRevenueBySnapshotBatch", + "claimRevenueByTokenBatch", + "claimableRevenue", + "collectRoyaltyTokens", + "ipId", + "RoyaltyTokensCollected", + "snapshot", + "SnapshotCompleted", + "RevenueTokenClaimed", + ], + PiLicenseTemplate: [ + "getLicenseTermsId", + "registerLicenseTerms", + "LicenseTermsRegistered", + ], + LicensingModule: [ + "attachLicenseTerms", + "mintLicenseTokens", + "LicenseTokensMinted", + "registerDerivativeWithLicenseTokens", + "registerDerivative", + "getLicenseTerms", + ], + ModuleRegistry: ["isRegistered"], + RoyaltyModule: ["payRoyaltyOnBehalf"], + RoyaltyPolicyLAP: ["onRoyaltyPayment", "getRoyaltyData"], + LicenseToken: ["ownerOf"], + SPG: [ + "createCollection", + "CollectionCreated", + "mintAndRegisterIp", + "registerPILTermsAndAttach", + "mintAndRegisterIpAndAttachPILTerms", + "registerIpAndAttachPILTerms", + "mintAndRegisterIpAndMakeDerivative", + "registerIpAndMakeDerivative", + "mintAndRegisterIpAndMakeDerivativeWithLicenseTokens", + "registerIpAndMakeDerivativeWithLicenseTokens" + ], }, - { - name: "DisputeModule", address: { - [sepoliaChainId]: "0xEB7B1dd43B81A7be1fA427515a2b173B454A9832", - // [storyTestnetId]: "0x6d54456Ae5DCbDC0C9E2713cC8E650fE4f445c7C", - } - }, - { - name: "IPAccountImpl", address: { - [sepoliaChainId]: "0x36a5f0D61f6Bab3C6Dde211E5a6762Cb18a8060d", - // [storyTestnetId]: "0x38cAfD16502B1d61c6399A18d6Fa1Ea8CEca3678", - } - }, - { - name: "IPAssetRegistry", address: { - [sepoliaChainId]: "0xd43fE0d865cb5C26b1351d3eAf2E3064BE3276F6", - // [storyTestnetId]: "0x862de97662a1231FFc14038eC1BE93aB129D2169", - } - }, - { - name: "IpRoyaltyVaultImpl", address: { - [sepoliaChainId]: "0xD6c2AfB61085f1359d47159f2271BDD0EeBf19C2", - // [storyTestnetId]: "0x8Be22cc2D13ADF496a417D9C616dA4a253c68Af8", - } - }, - { - name: "LicenseRegistry", address: { - [sepoliaChainId]: "0x4f4b1bf7135C7ff1462826CCA81B048Ed19562ed", - // [storyTestnetId]: "0x0c3D467537FAd845a78728CEdc3D9447338c5422", - } - }, - { - name: "LicenseToken", address: { - [sepoliaChainId]: "0x1333c78A821c9a576209B01a16dDCEF881cAb6f2", - // [storyTestnetId]: "0xD40b7bCA204f96a346021e31c9ad54FF495226e7", - } - }, - { - name: "LicensingModule", address: { - [sepoliaChainId]: "0xe89b0EaA8a0949738efA80bB531a165FB3456CBe", - // [storyTestnetId]: "0xEeDDE5529122b621105798860F235c28FD3aBA40", - } - }, - { - name: "PILicenseTemplate", address: { - [sepoliaChainId]: "0x260B6CB6284c89dbE660c0004233f7bB99B5edE7", - // [storyTestnetId]: "0xd0Be223ae9719bBD93447ecf5289319CCf8cA227", - } - }, - { - name: "ModuleRegistry", address: { - [sepoliaChainId]: "0x2E0a668289D5C4Da6a2264aC8DF03cd600c7aAB8", - // [storyTestnetId]: "0xf2965E3B6251905Dd1E8671077760D07b0408cf2", - } - }, - { - name: "RoyaltyModule", address: { - [sepoliaChainId]: "0xFAE961dd2b87CD5818dbCDc2591e6AB0b50E96b0", - // [storyTestnetId]: "0x551AD8CD7893003cE00500aC2aCF1E327763D9f6", - } - }, - { - name: "RoyaltyPolicyLAP", address: { - [sepoliaChainId]: "0xAAbaf349C7a2A84564F9CC4Ac130B3f19A718E86", - // [storyTestnetId]: "0x2EcdB5bD12a037dCb9De0Ab7957f35FEeF758eA6", - } - }, - ] - return { - out: '../core-sdk/src/abi/generated.ts', - contracts: [], - plugins: [ - blockExplorer({ - baseUrl: 'https://api-sepolia.etherscan.io/api', - name: 'Etherscan', - getAddress: await resolveProxyContracts({ - baseUrl: 'https://rpc.sepolia.org', - contracts: contracts, - chainId: sepoliaChainId, - }), - contracts: contracts, - apiKey: process.env.API_KEY - }), - sdk({ - permissionLessSDK: true, - whiteList: { - "AccessController": [ - "PermissionSet", - "setPermission", - ], - "DisputeModule": [ - "DisputeCancelled", - "DisputeRaised", - "DisputeResolved", - "cancelDispute", - "raiseDispute", - "resolveDispute", - ], - "IPAccountImpl": [ - "execute", - "executeWithSig", - ], - "IPAssetRegistry": [ - "IPRegistered", - "ipId", - "isRegistered", - "register", - ], - "IpRoyaltyVaultImpl": [ - "claimRevenueBySnapshotBatch", - "claimRevenueByTokenBatch", - "claimableRevenue", - "collectRoyaltyTokens", - "ipId", - "RoyaltyTokensCollected", - "snapshot", - "SnapshotCompleted", - "RevenueTokenClaimed" - ], - "PiLicenseTemplate": [ - "getLicenseTermsId", - "registerLicenseTerms", - "LicenseTermsRegistered" - ], - "LicensingModule": [ - "attachLicenseTerms", - "mintLicenseTokens", - "LicenseTokensMinted", - "registerDerivativeWithLicenseTokens", - "registerDerivative", - ], - "ModuleRegistry": [ - "isRegistered", - ], - "RoyaltyModule": [ - "payRoyaltyOnBehalf", - ], - "RoyaltyPolicyLAP": [ - "onRoyaltyPayment", - "getRoyaltyData", - ], - "LicenseToken":[ - "ownerOf" - ] - } - }), - ], - } -}) \ No newline at end of file + }), + ], + }; +});