diff --git a/packages/react-sdk/package.json b/packages/react-sdk/package.json index c7caa12b..31a93930 100644 --- a/packages/react-sdk/package.json +++ b/packages/react-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@story-protocol/react-sdk", - "version": "0.0.2", + "version": "1.1.0-stable", "description": "The Story Protocol React SDK", "main": "dist/story-protocol-react-sdk.cjs.js", "module": "dist/story-protocol-react-sdk.esm.js", @@ -14,6 +14,7 @@ "scripts": { "generate": "node ./generator/index.js", "build": "pnpm run fix && preconstruct build", + "test:integration": "jest -i", "fix": "pnpm run format:fix && pnpm run lint:fix", "format": "prettier --check .", "format:fix": "prettier --write .", @@ -62,7 +63,7 @@ }, "license": "MIT", "dependencies": { - "@story-protocol/core-sdk": "1.0.0-rc.22", + "@story-protocol/core-sdk": "1.1.0-stable", "react": "^18.3.1", "viem": "^2.8.12" }, diff --git a/packages/react-sdk/src/index.ts b/packages/react-sdk/src/index.ts index ecdb3cbc..44f5d909 100644 --- a/packages/react-sdk/src/index.ts +++ b/packages/react-sdk/src/index.ts @@ -24,6 +24,7 @@ export type { IPAccountExecuteWithSigRequest, IPAccountExecuteWithSigResponse, IpAccountStateResponse, + TokenResponse, GenerateCreatorMetadataParam, IpCreator, GenerateIpMetadataParam, @@ -41,8 +42,9 @@ export type { RegisterIpAndMakeDerivativeRequest, RegisterIpAndMakeDerivativeResponse, MintAndRegisterIpAndMakeDerivativeRequest, - RegisterNonComSocialRemixingPILRequest, + RegisterPILTermsRequest, RegisterPILResponse, + RegisterNonComSocialRemixingPILRequest, RegisterCommercialUsePILRequest, RegisterCommercialRemixPILRequest, AttachLicenseTermsRequest, diff --git a/packages/react-sdk/src/resources/useIpAccount.ts b/packages/react-sdk/src/resources/useIpAccount.ts index 9c9a1d66..2f45afec 100644 --- a/packages/react-sdk/src/resources/useIpAccount.ts +++ b/packages/react-sdk/src/resources/useIpAccount.ts @@ -4,7 +4,9 @@ import { IPAccountExecuteWithSigRequest, IPAccountExecuteWithSigResponse, IpAccountStateResponse, + TokenResponse, } from "@story-protocol/core-sdk"; +import { Address } from "viem"; import { useState } from "react"; import { useStoryContext } from "../StoryProtocolContext"; @@ -16,11 +18,13 @@ const useIpAccount = () => { execute: false, executeWithSig: false, getIpAccountNonce: false, + getToken: false, }); const [errors, setErrors] = useState>({ execute: null, executeWithSig: null, getIpAccountNonce: null, + getToken: null, }); /** Executes a transaction from the IP Account. @@ -67,10 +71,10 @@ const useIpAccount = () => { /** Returns the IPAccount's internal nonce for transaction ordering. * @param ipId The IP ID - * @returns The nonce for transaction ordering. + * @returns A Promise that resolves to the IP Account's nonce. */ const getIpAccountNonce = withLoadingErrorHandling< - string, + Address, IpAccountStateResponse >( "getIpAccountNonce", @@ -79,12 +83,24 @@ const useIpAccount = () => { setErrors ); + /** + * Returns the identifier of the non-fungible token which owns the account + * @returns A Promise that resolves to an object containing the chain ID, token contract address, and token ID. + */ + const getToken = withLoadingErrorHandling( + "getToken", + client.ipAccount.getToken.bind(client.ipAccount), + setLoadings, + setErrors + ); + return { loadings, errors, execute, executeWithSig, getIpAccountNonce, + getToken, }; }; export default useIpAccount; diff --git a/packages/react-sdk/src/resources/useLicense.ts b/packages/react-sdk/src/resources/useLicense.ts index 8fa06201..8f19620f 100644 --- a/packages/react-sdk/src/resources/useLicense.ts +++ b/packages/react-sdk/src/resources/useLicense.ts @@ -1,6 +1,7 @@ import { - RegisterNonComSocialRemixingPILRequest, + RegisterPILTermsRequest, RegisterPILResponse, + RegisterNonComSocialRemixingPILRequest, RegisterCommercialUsePILRequest, RegisterCommercialRemixPILRequest, AttachLicenseTermsRequest, @@ -18,6 +19,7 @@ import { withLoadingErrorHandling } from "../withLoadingErrorHandling"; const useLicense = () => { const client = useStoryContext(); const [loadings, setLoadings] = useState>({ + registerPILTerms: false, registerNonComSocialRemixingPIL: false, registerCommercialUsePIL: false, registerCommercialRemixPIL: false, @@ -26,6 +28,7 @@ const useLicense = () => { getLicenseTerms: false, }); const [errors, setErrors] = useState>({ + registerPILTerms: null, registerNonComSocialRemixingPIL: null, registerCommercialUsePIL: null, registerCommercialRemixPIL: null, @@ -34,6 +37,40 @@ const useLicense = () => { getLicenseTerms: null, }); + /** + * Registers new license terms and return the ID of the newly registered license terms. + * @param request - The request object that contains all data needed to register a license term. + * @param request.transferable Indicates whether the license is transferable or not. + * @param request.royaltyPolicy The address of the royalty policy contract which required to StoryProtocol in advance. + * @param request.mintingFee The fee to be paid when minting a license. + * @param request.expiration The expiration period of the license. + * @param request.commercialUse Indicates whether the work can be used commercially or not. + * @param request.commercialAttribution Whether attribution is required when reproducing the work commercially or not. + * @param request.commercializerChecker Commercializers that are allowed to commercially exploit the work. If zero address, then no restrictions is enforced. + * @param request.commercializerCheckerData The data to be passed to the commercializer checker contract. + * @param request.commercialRevShare Percentage of revenue that must be shared with the licensor. + * @param request.commercialRevCeiling The maximum revenue that can be generated from the commercial use of the work. + * @param request.derivativesAllowed Indicates whether the licensee can create derivatives of his work or not. + * @param request.derivativesAttribution Indicates whether attribution is required for derivatives of the work or not. + * @param request.derivativesApproval Indicates whether the licensor must approve derivatives of the work before they can be linked to the licensor IP ID or not. + * @param request.derivativesReciprocal Indicates whether the licensee must license derivatives of the work under the same terms or not. + * @param request.derivativeRevCeiling The maximum revenue that can be generated from the derivative use of the work. + * @param request.currency The ERC20 token to be used to pay the minting fee. the token must be registered in story protocol. + * @param request.uri The URI of the license terms, which can be used to fetch the offchain license terms. + * @param request.txOptions - [Optional] transaction. This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property. + * @returns A Promise that resolves to an object containing the optional transaction hash, optional transaction encodedTxData and optional license terms Id. + * @emits LicenseTermsRegistered (licenseTermsId, licenseTemplate, licenseTerms); + */ + const registerPILTerms = withLoadingErrorHandling< + RegisterPILTermsRequest, + RegisterPILResponse + >( + "registerPILTerms", + client.license.registerPILTerms.bind(client.license), + setLoadings, + setErrors + ); + /** * Convenient function to register a PIL non commercial social remix license to the registry * @param request - [Optional] The request object that contains all data needed to register a PIL non commercial social remix license. @@ -54,7 +91,7 @@ const useLicense = () => { /** * Convenient function to register a PIL commercial use license to the registry. * @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.defaultMintingFee 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.txOptions - [Optional] transaction. This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property. * @returns A Promise that resolves to an object containing the optional transaction hash and optional license terms Id. @@ -73,7 +110,7 @@ const useLicense = () => { /** * Convenient function to register a PIL commercial Remix license to the registry. * @param request - The request object that contains all data needed to register license. - * @param request.mintingFee The fee to be paid when minting a license. + * @param request.defaultMintingFee 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.txOptions - [Optional] transaction. This extends `WaitForTransactionReceiptParameters` from the Viem library, excluding the `hash` property. @@ -159,6 +196,7 @@ const useLicense = () => { return { loadings, errors, + registerPILTerms, registerNonComSocialRemixingPIL, registerCommercialUsePIL, registerCommercialRemixPIL, diff --git a/packages/react-sdk/test/integration/useLicense.test.ts b/packages/react-sdk/test/integration/useLicense.test.ts index 4e165561..b2620b9d 100644 --- a/packages/react-sdk/test/integration/useLicense.test.ts +++ b/packages/react-sdk/test/integration/useLicense.test.ts @@ -34,7 +34,7 @@ describe("useLicense Functions", () => { await act(async () => { await expect( licenseHook.registerCommercialUsePIL({ - mintingFee: "1", + defaultMintingFee: "1", currency: mockERC20Address, txOptions: { waitForTransaction: true, @@ -52,7 +52,7 @@ describe("useLicense Functions", () => { await act(async () => { await expect( licenseHook.registerCommercialRemixPIL({ - mintingFee: "1", + defaultMintingFee: "1", commercialRevShare: 100, currency: mockERC20Address, txOptions: { diff --git a/packages/react-sdk/test/integration/useRoyalty.test.ts b/packages/react-sdk/test/integration/useRoyalty.test.ts index f7831f58..e50056fc 100644 --- a/packages/react-sdk/test/integration/useRoyalty.test.ts +++ b/packages/react-sdk/test/integration/useRoyalty.test.ts @@ -39,7 +39,7 @@ describe("useRoyalty Functions", () => { return await act(async () => { return ( await licenseHook.registerCommercialUsePIL({ - mintingFee: "1", + defaultMintingFee: "1", currency: mockERC20Address, txOptions: { waitForTransaction: true, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c7d8e8c8..2b5ab821 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -140,8 +140,8 @@ importers: packages/react-sdk: dependencies: '@story-protocol/core-sdk': - specifier: 1.0.0-rc.22 - version: 1.0.0-rc.22(typescript@5.4.5) + specifier: 1.1.0-stable + version: 1.1.0-stable(typescript@5.4.5) react: specifier: ^18.3.1 version: 18.3.1 @@ -3942,8 +3942,8 @@ packages: '@stablelib/wipe': 1.0.1 dev: true - /@story-protocol/core-sdk@1.0.0-rc.22(typescript@5.4.5): - resolution: {integrity: sha512-l+i7lzUGTdpBNfoMeFSRztFPuP9uTzAEA9PZ0wDviWg5pA22D+QmnbkF1HrBd5Mctxtv5tivdFSLARizBEjWEA==} + /@story-protocol/core-sdk@1.1.0-stable(typescript@5.4.5): + resolution: {integrity: sha512-gS7nk7UsRcOazd9rKUyKANF97GowGCt4OauEDPtb/az1szjsavfEbC8+wR7D+bO7lde9e1/yoIeWcoN0Fj4vQw==} dependencies: abitype: 0.10.3(typescript@5.4.5) axios: 1.6.8