From cee148de869a309c01a4f9bdbff3749a05834f75 Mon Sep 17 00:00:00 2001 From: bitbeckers Date: Fri, 5 Jul 2024 17:54:09 +0200 Subject: [PATCH] feat(client): updated method signatures --- sdk/package.json | 2 +- sdk/src/client.ts | 298 ++++++++++++++------------------ sdk/src/types/client.ts | 130 ++++++++++++-- sdk/test/client/burn.test.ts | 2 +- sdk/test/client/minting.test.ts | 4 +- 5 files changed, 258 insertions(+), 178 deletions(-) diff --git a/sdk/package.json b/sdk/package.json index 2862970a..a72517aa 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@hypercerts-org/sdk", - "version": "2.0.0-alpha.27", + "version": "2.0.0-alpha.28", "description": "SDK for hypercerts protocol", "repository": "git@github.com:hypercerts-org/hypercerts.git", "author": "Hypercerts team", diff --git a/sdk/src/client.ts b/sdk/src/client.ts index 89e89a33..83efe6c3 100644 --- a/sdk/src/client.ts +++ b/sdk/src/client.ts @@ -3,14 +3,22 @@ import { Account, ByteArray, Hex, PublicClient, WalletClient, getAddress, getCon import { getStorage } from "./storage"; import { AllowlistEntry, + BatchClaimFractionsFromAllowlistsParams, + BatchTransferParams, + BurnFractionParams, + ClaimFractionFromAllowlistParams, ClientError, Environment, HypercertClientConfig, HypercertClientInterface, HypercertMetadata, InvalidOrMissingError, + MergeFractionsParams, + MintParams, + SplitFractionParams, SupportedChainIds, SupportedOverrides, + TransferParams, TransferRestrictions, } from "./types"; import { getConfig, getDeploymentsForChainId, getDeploymentsForEnvironment } from "./utils/config"; @@ -60,11 +68,15 @@ export class HypercertClient implements HypercertClientInterface { this.readOnly = this._config.readOnly; } - isClaimOrFractionOnConnectedChain = (claimOrFractionId: string) => { + isHypercertsOrFractionOnConnectedChain = (claimOrFractionId: string) => { const connectedChain = this._walletClient?.chain?.id; return isClaimOnChain(claimOrFractionId, connectedChain); }; + isClaimOrFractionOnConnectedChain = (claimOrFractionId: string) => { + return this.isHypercertsOrFractionOnConnectedChain(claimOrFractionId); + }; + /** * Gets the config for the client. * @returns The client config. @@ -93,31 +105,50 @@ export class HypercertClient implements HypercertClientInterface { return getDeploymentsForEnvironment(this._config.environment); }; - /** - * Mints a new claim. - * - * This method first validates the provided metadata using the `validateMetaData` function. If the metadata is invalid, it throws a `MalformedDataError`. - * It then stores the metadata on IPFS using the `storeMetadata` method of the storage client. - * After that, it simulates a contract call to the `mintClaim` function with the provided parameters and the stored metadata CID to validate the transaction. - * Finally, it submits the request using the `submitRequest` method. - * - * @param {HypercertMetadata} metaData - The metadata for the claim. - * @param {bigint} totalUnits - The total units for the claim. - * @param {TransferRestrictions} transferRestriction - The transfer restrictions for the claim. - * @param {SupportedOverrides} [overrides] - Optional overrides for the contract call. - * @returns {Promise<`0x${string}` | undefined>} A promise that resolves to the transaction hash. - * @throws {MalformedDataError} Will throw a `MalformedDataError` if the provided metadata is invalid. - */ mintClaim = async ( metaData: HypercertMetadata, totalUnits: bigint, transferRestriction: TransferRestrictions, + allowList?: AllowlistEntry[], overrides?: SupportedOverrides, - ): Promise<`0x${string}` | undefined> => { + ) => { + return await this.mintHypercert({ metaData, totalUnits, transferRestriction, allowList, overrides }); + }; + + mintHypercert = async ({ + metaData, + totalUnits, + transferRestriction, + allowList, + overrides, + }: MintParams): Promise<`0x${string}` | undefined> => { const { account } = this.getConnected(); + let allowListCid; + let root; + + if (allowList) { + const tree = parseAllowListEntriesToMerkleTree(allowList); + + // store allowlist on IPFS + const allowlistStoreRes = await this.storage.storeAllowlist( + { allowList: JSON.stringify(tree.dump()), totalUnits: totalUnits.toString() }, + { timeout: overrides?.timeout }, + ); + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + if (!allowlistStoreRes.data || !allowlistStoreRes.data.data) + throw new ClientError("No CID found", { allowlistStoreRes }); + + const { cid } = allowlistStoreRes.data.data as StoreAllowList201AnyOfTwoData; + allowListCid = cid; + root = tree.root; + } + + const metadataToStore = allowListCid ? { ...metaData, allowList: allowListCid } : metaData; + // validate and store metadata - const metadataRes = await this.storage.storeMetadata(metaData, { timeout: overrides?.timeout }); + const metadataRes = await this.storage.storeMetadata(metadataToStore, { timeout: overrides?.timeout }); if (!metadataRes || !metadataRes.data) { throw new ClientError("No CID found", { metadataRes }); @@ -125,12 +156,23 @@ export class HypercertClient implements HypercertClientInterface { const data = metadataRes.data as StoreMetadata201AnyOf; - const request = await this.simulateRequest( - account, - "mintClaim", - [account?.address, totalUnits, data.cid, transferRestriction], - overrides, - ); + let request; + + if (allowList && allowListCid) { + request = await this.simulateRequest( + account, + "createAllowlist", + [account?.address, totalUnits, root, data.cid, transferRestriction], + overrides, + ); + } else { + request = await this.simulateRequest( + account, + "mintClaim", + [account?.address, totalUnits, data.cid, transferRestriction], + overrides, + ); + } return this.submitRequest(request); }; @@ -149,22 +191,7 @@ export class HypercertClient implements HypercertClientInterface { return await readContract.read.readTransferRestriction([fractionId]).then((res) => res as TransferRestrictions); }; - /** - * Transfers a claim fraction to a new owner. - * - * This method first retrieves the wallet client and account using the `getWallet` method. - * It then simulates a contract call to the `safeTransferFrom` function with the provided parameters and the account, and submits the request using the `submitRequest` method. - * - * @param fractionId - * @param to - * @param overrides - * @returns {Promise<`0x${string}` | undefined>} A promise that resolves to the transaction hash. - */ - transferFraction = async ( - fractionId: bigint, - to: string, - overrides?: SupportedOverrides | undefined, - ): Promise<`0x${string}` | undefined> => { + transferFraction = async ({ fractionId, to, overrides }: TransferParams): Promise<`0x${string}` | undefined> => { const { account } = this.getConnected(); const request = await this.simulateRequest( @@ -177,22 +204,11 @@ export class HypercertClient implements HypercertClientInterface { return this.submitRequest(request); }; - /** - * Transfers multiple claim fractions to a new owner. - * - * This method first retrieves the wallet client and account using the `getWallet` method. - * It then simulates a contract call to the `safeBatchTransferFrom` function with the provided parameters and the account, and submits the request using the `submitRequest` method. - * - * @param fractionIds - * @param to - * @param overrides - * @returns {Promise<`0x${string}` | undefined>} A promise that resolves to the transaction hash. - */ - batchTransferFractions = async ( - fractionIds: bigint[], - to: `0x${string}`, - overrides?: SupportedOverrides | undefined, - ): Promise<`0x${string}` | undefined> => { + batchTransferFractions = async ({ + fractionIds, + to, + overrides, + }: BatchTransferParams): Promise<`0x${string}` | undefined> => { const { account } = this.getConnected(); const request = await this.simulateRequest( @@ -205,22 +221,6 @@ export class HypercertClient implements HypercertClientInterface { return this.submitRequest(request); }; - /** - * Creates an allowlist. - * - * This method first validates the provided allowlist and metadata using the `validateAllowlist` and `validateMetaData` functions respectively. If either is invalid, it throws a `MalformedDataError`. - * It then creates an allowlist from the provided entries and stores it on IPFS using the `storeData` method of the storage client. - * After that, it stores the metadata (including the CID of the allowlist) on IPFS using the `storeMetadata` method of the storage client. - * Finally, it simulates a contract call to the `createAllowlist` function with the provided parameters and the stored metadata CID, and submits the request using the `submitRequest` method. - * - * @param {AllowlistEntry[]} allowList - The entries for the allowlist. - * @param {HypercertMetadata} metaData - The metadata for the claim. - * @param {bigint} totalUnits - The total units for the claim. - * @param {TransferRestrictions} transferRestriction - The transfer restrictions for the claim. - * @param {SupportedOverrides} [overrides] - Optional overrides for the contract call. - * @returns {Promise<`0x${string}` | undefined>} A promise that resolves to the transaction hash. - * @throws {MalformedDataError} Will throw a `MalformedDataError` if the provided allowlist or metadata is invalid. - */ createAllowlist = async ( allowList: AllowlistEntry[], metaData: HypercertMetadata, @@ -263,25 +263,11 @@ export class HypercertClient implements HypercertClientInterface { return this.submitRequest(request); }; - /** - * Splits a fraction into multiple fractions. - * - * This method first retrieves the wallet client and account using the `getWallet` method. It then retrieves the owner and total units of the fraction using the `ownerOf` and `unitsOf` methods of the read contract. - * If the fraction is not owned by the account, it throws a `ClientError`. - * It then checks if the sum of the provided fractions is equal to the total units of the fraction. If not, it throws a `ClientError`. - * Finally, it simulates a contract call to the `splitFraction` function with the provided parameters and the account, and submits the request using the `submitRequest` method. - * - * @param {bigint} fractionId - The ID of the fraction to split. - * @param {bigint[]} fractions - The fractions to split the fraction into. - * @param {SupportedOverrides} [overrides] - Optional overrides for the contract call. - * @returns {Promise<`0x${string}` | undefined>} A promise that resolves to the transaction hash. - * @throws {ClientError} Will throw a `ClientError` if the fraction is not owned by the account or if the sum of the fractions is not equal to the total units of the fraction. - */ - splitFractionUnits = async ( - fractionId: bigint, - fractions: bigint[], - overrides?: SupportedOverrides, - ): Promise<`0x${string}` | undefined> => { + splitFraction = async ({ + fractionId, + fractions, + overrides, + }: SplitFractionParams): Promise<`0x${string}` | undefined> => { const { account } = this.getConnected(); const readContract = this._getContract(); @@ -307,22 +293,15 @@ export class HypercertClient implements HypercertClientInterface { return this.submitRequest(request); }; - /** - * Merges multiple fractions into a single fraction. - * - * This method first retrieves the wallet client and account using the `getWallet` method. It then retrieves the owner of each fraction using the `ownerOf` method of the read contract. - * If any of the fractions are not owned by the account, it throws a `ClientError`. - * It then simulates a contract call to the `mergeFractions` function with the provided parameters and the account, and submits the request using the `submitRequest` method. - * - * @param {bigint[]} fractionIds - The IDs of the fractions to merge. - * @param {SupportedOverrides} [overrides] - Optional overrides for the contract call. - * @returns {Promise<`0x${string}` | undefined>} A promise that resolves to the transaction hash. - * @throws {ClientError} Will throw a `ClientError` if any of the fractions are not owned by the account. - */ - mergeFractionUnits = async ( - fractionIds: bigint[], + splitFractionUnits = async ( + fractionId: bigint, + fractions: bigint[], overrides?: SupportedOverrides, ): Promise<`0x${string}` | undefined> => { + return this.splitFraction({ fractionId, fractions, overrides }); + }; + + mergeFractions = async ({ fractionIds, overrides }: MergeFractionsParams): Promise<`0x${string}` | undefined> => { const { account } = this.getConnected(); const readContract = this._getContract(); @@ -345,55 +324,40 @@ export class HypercertClient implements HypercertClientInterface { return this.submitRequest(request); }; - /** - * Burns a claim fraction. - * - * This method first retrieves the wallet client and account using the `getWallet` method. It then retrieves the owner of the claim using the `ownerOf` method of the read contract. - * If the claim is not owned by the account, it throws a `ClientError`. - * It then simulates a contract call to the `burnFraction` function with the provided parameters and the account, and submits the request using the `submitRequest` method. - * - * @param {bigint} claimId - The ID of the claim to burn. - * @param {SupportedOverrides} [overrides] - Optional overrides for the contract call. - * @returns {Promise<`0x${string}` | undefined>} A promise that resolves to the transaction hash. - * @throws {ClientError} Will throw a `ClientError` if the claim is not owned by the account. - */ - burnClaimFraction = async (claimId: bigint, overrides?: SupportedOverrides): Promise<`0x${string}` | undefined> => { + mergeFractionUnits = async ( + fractionIds: bigint[], + overrides?: SupportedOverrides, + ): Promise<`0x${string}` | undefined> => { + return this.mergeFractions({ fractionIds, overrides }); + }; + + burnFraction = async ({ fractionId, overrides }: BurnFractionParams): Promise<`0x${string}` | undefined> => { const { account } = this.getConnected(); const readContract = this._getContract(); - const claimOwner = (await readContract.read.ownerOf([claimId])) as `0x${string}`; + const hypercertOwner = (await readContract.read.ownerOf([fractionId])) as `0x${string}`; - if (claimOwner.toLowerCase() !== account?.address.toLowerCase()) { - throw new ClientError("Claim is not owned by the signer", { signer: account?.address, claimOwner }); + if (hypercertOwner.toLowerCase() !== account?.address.toLowerCase()) { + throw new ClientError("Hypercert is not owned by the signer", { signer: account?.address, hypercertOwner }); } - const request = await this.simulateRequest(account, "burnFraction", [account?.address, claimId], overrides); + const request = await this.simulateRequest(account, "burnFraction", [account?.address, fractionId], overrides); return this.submitRequest(request); }; - /** - * Mints a claim fraction from an allowlist. - * - * This method first retrieves the wallet client and account using the `getWallet` method. It then verifies the provided proof using the `verifyMerkleProof` function. If the proof is invalid, it throws an `InvalidOrMissingError`. - * It then simulates a contract call to the `mintClaimFromAllowlist` function with the provided parameters and the account, and submits the request using the `submitRequest` method. - * - * @param {bigint} claimId - The ID of the claim to mint. - * @param {bigint} units - The units of the claim to mint. - * @param {(Hex | ByteArray)[]} proof - The proof for the claim. - * @param {Hex | ByteArray} [root] - The root of the proof. If provided, it is used to verify the proof. - * @param {SupportedOverrides} [overrides] - Optional overrides for the contract call. - * @returns {Promise<`0x${string}` | undefined>} A promise that resolves to the transaction hash. - * @throws {InvalidOrMissingError} Will throw an `InvalidOrMissingError` if the proof is invalid. - */ - mintClaimFractionFromAllowlist = async ( - claimId: bigint, - units: bigint, - proof: (Hex | ByteArray)[], - root?: Hex | ByteArray, - overrides?: SupportedOverrides, - ): Promise<`0x${string}` | undefined> => { + burnClaimFraction = async (claimId: bigint, overrides?: SupportedOverrides): Promise<`0x${string}` | undefined> => { + return this.burnFraction({ fractionId: claimId, overrides }); + }; + + claimFractionFromAllowlist = async ({ + hypercertTokenId, + units, + proof, + root, + overrides, + }: ClaimFractionFromAllowlistParams): Promise<`0x${string}` | undefined> => { const { account } = this.getConnected(); //verify the proof using the OZ merkle tree library @@ -410,34 +374,30 @@ export class HypercertClient implements HypercertClientInterface { const request = await this.simulateRequest( account, "mintClaimFromAllowlist", - [account?.address, proof, claimId, units], + [account?.address, proof, hypercertTokenId, units], overrides, ); return this.submitRequest(request); }; - /** - * Mints multiple claim fractions from allowlists in a batch. - * - * This method first retrieves the wallet client and account using the `getWallet` method. If the roots are provided, it verifies each proof using the `verifyMerkleProofs` function. If any of the proofs are invalid, it throws an `InvalidOrMissingError`. - * It then simulates a contract call to the `batchMintClaimsFromAllowlists` function with the provided parameters and the account, and submits the request using the `submitRequest` method. - * - * @param {bigint[]} claimIds - The IDs of the claims to mint. - * @param {bigint[]} units - The units of each claim to mint. - * @param {(Hex | ByteArray)[][]} proofs - The proofs for each claim. - * @param {(Hex | ByteArray)[]} [roots] - The roots of each proof. If provided, they are used to verify the proofs. - * @param {SupportedOverrides} [overrides] - Optional overrides for the contract call. - * @returns {Promise<`0x${string}` | undefined>} A promise that resolves to the transaction hash. - * @throws {InvalidOrMissingError} Will throw an `InvalidOrMissingError` if any of the proofs are invalid. - */ - batchMintClaimFractionsFromAllowlists = async ( - claimIds: bigint[], - units: bigint[], - proofs: (Hex | ByteArray)[][], - roots?: (Hex | ByteArray)[], + mintClaimFractionFromAllowlist = async ( + claimId: bigint, + units: bigint, + proof: (Hex | ByteArray)[], + root?: Hex | ByteArray, overrides?: SupportedOverrides, ): Promise<`0x${string}` | undefined> => { + return this.claimFractionFromAllowlist({ hypercertTokenId: claimId, units, proof, root, overrides }); + }; + + batchClaimFractionsFromAllowlists = async ({ + hypercertTokenIds, + units, + proofs, + roots, + overrides, + }: BatchClaimFractionsFromAllowlistsParams): Promise<`0x${string}` | undefined> => { const { account } = this.getConnected(); //verify the proof using the OZ merkle tree library @@ -455,13 +415,23 @@ export class HypercertClient implements HypercertClientInterface { const request = await this.simulateRequest( account, "batchMintClaimsFromAllowlists", - [account?.address, proofs, claimIds, units], + [account?.address, proofs, hypercertTokenIds, units], overrides, ); return this.submitRequest(request); }; + batchMintClaimFractionsFromAllowlists = async ( + claimIds: bigint[], + units: bigint[], + proofs: (Hex | ByteArray)[][], + roots?: (Hex | ByteArray)[], + overrides?: SupportedOverrides, + ): Promise<`0x${string}` | undefined> => { + return this.batchClaimFractionsFromAllowlists({ hypercertTokenIds: claimIds, units, proofs, roots, overrides }); + }; + getClaimStoredDataFromTxHash = async (hash: `0x${string}`): Promise => { const { publicClient } = this.getConnected(); diff --git a/sdk/src/types/client.ts b/sdk/src/types/client.ts index ccfabb00..1f3cd02a 100644 --- a/sdk/src/types/client.ts +++ b/sdk/src/types/client.ts @@ -92,6 +92,54 @@ export interface HypercertClientState { readOnly: boolean; } +export interface TransactionParams { + overrides?: SupportedOverrides; +} + +export interface MintParams extends TransactionParams { + metaData: HypercertMetadata; + totalUnits: bigint; + transferRestriction: TransferRestrictions; + allowList?: AllowlistEntry[]; +} + +export interface TransferParams extends TransactionParams { + fractionId: bigint; + to: `0x${string}`; +} + +export interface BatchTransferParams extends TransactionParams { + fractionIds: bigint[]; + to: `0x${string}`; +} + +export interface SplitFractionParams extends TransactionParams { + fractionId: bigint; + fractions: bigint[]; +} + +export interface MergeFractionsParams extends TransactionParams { + fractionIds: bigint[]; +} + +export interface BurnFractionParams extends TransactionParams { + fractionId: bigint; +} + +export interface ClaimFractionFromAllowlistParams extends TransactionParams { + hypercertTokenId: bigint; + units: bigint; + proof: (Hex | ByteArray)[]; + root?: Hex | ByteArray; +} + +export interface BatchClaimFractionsFromAllowlistsParams extends TransactionParams { + hypercertTokenIds: bigint[]; + units: bigint[]; + proofs: (Hex | ByteArray)[][]; + roots?: (Hex | ByteArray)[]; +} + /** * The methods for the Hypercert client. */ @@ -110,13 +158,24 @@ export interface HypercertClientMethods { * @param totalUnits The total number of units for the claim. * @param transferRestriction The transfer restriction for the claim. * @returns A Promise that resolves to the transaction hash + * @deprecated use `mintClaim` with optional `allowList` parameter instead */ mintClaim: ( metaData: HypercertMetadata, totalUnits: bigint, transferRestriction: TransferRestrictions, + allowList?: AllowlistEntry[], ) => Promise<`0x${string}` | undefined>; + /** + * Mints a new hypercert. + * @param metaData The metadata for the hypercert. + * @param totalUnits The total number of units for the hypercert. + * @param transferRestriction The transfer restriction for the hypercert. + * @returns A Promise that resolves to the transaction hash + */ + mintHypercert: (params: MintParams) => Promise<`0x${string}` | undefined>; + /** * Retrieves the TransferRestrictions for a claim. * @param fractionId The ID of the claim to retrieve. @@ -131,11 +190,7 @@ export interface HypercertClientMethods { * @param overrides * @returns A Promise that resolves to the transaction hash */ - transferFraction: ( - fractionId: bigint, - to: `0x${string}`, - overrides?: SupportedOverrides, - ) => Promise<`0x${string}` | undefined>; + transferFraction: (params: TransferParams) => Promise<`0x${string}` | undefined>; /** * Transfers multiple claim fractions to a new owner. @@ -144,11 +199,7 @@ export interface HypercertClientMethods { * @param overrides * @returns A Promise that resolves to the transaction hash */ - batchTransferFractions: ( - fractionIds: bigint[], - to: `0x${string}`, - overrides?: SupportedOverrides, - ) => Promise<`0x${string}` | undefined>; + batchTransferFractions: (params: BatchTransferParams) => Promise<`0x${string}` | undefined>; /** * Creates a new allowlist and mints a new claim with the allowlist. @@ -157,6 +208,7 @@ export interface HypercertClientMethods { * @param totalUnits The total number of units for the claim. * @param transferRestriction The transfer restriction for the claim. * @returns A Promise that resolves to the transaction hash + * @deprecated use `mintHypercert` with optional `allowList` parameter instead */ createAllowlist: ( allowList: AllowlistEntry[], @@ -170,29 +222,55 @@ export interface HypercertClientMethods { * @param fractionId The ID of the claim to split. * @param newFractions The number of units for each fraction. * @returns A Promise that resolves to the transaction hash + * @deprecated use `splitFraction` instead */ splitFractionUnits: (fractionId: bigint, fractions: bigint[]) => Promise<`0x${string}` | undefined>; + /** + * Splits a claim into multiple fractions. + * @param fractionId The ID of the claim to split. + * @param newFractions The number of units for each fraction. + * @returns A Promise that resolves to the transaction hash + */ + splitFraction: (params: SplitFractionParams) => Promise<`0x${string}` | undefined>; + /** * Merges multiple claim fractions into a single claim. * @param fractionIds The IDs of the claim fractions to merge. * @returns A Promise that resolves to the transaction hash + * @deprecated use `mergeFractions` instead */ mergeFractionUnits: (fractionIds: bigint[]) => Promise<`0x${string}` | undefined>; + /** + * Merges multiple claim fractions into a single claim. + * @param fractionIds The IDs of the claim fractions to merge. + * @returns A Promise that resolves to the transaction hash + */ + mergeFractions: (params: MergeFractionsParams) => Promise<`0x${string}` | undefined>; + /** * Burns a claim fraction. * @param fractionId The ID of the claim fraction to burn. * @returns A Promise that resolves to the transaction hash + * @deprecated use `burnFraction` instead */ burnClaimFraction: (fractionId: bigint) => Promise<`0x${string}` | undefined>; + /** + * Burns a claim fraction. + * @param fractionId The ID of the claim fraction to burn. + * @returns A Promise that resolves to the transaction hash + */ + burnFraction: (params: BurnFractionParams) => Promise<`0x${string}` | undefined>; + /** * Mints a claim fraction from an allowlist. * @param claimId The ID of the claim to mint a fraction for. * @param units The number of units for the fraction. * @param proof The Merkle proof for the allowlist. * @returns A Promise that resolves to the transaction hash + * @deprecated use `claimFractionFromAllowlist` instead */ mintClaimFractionFromAllowlist: ( claimId: bigint, @@ -200,6 +278,15 @@ export interface HypercertClientMethods { proof: (Hex | ByteArray)[], ) => Promise<`0x${string}` | undefined>; + /** + * Mints a claim fraction from an allowlist. + * @param claimId The ID of the claim to mint a fraction for. + * @param units The number of units for the fraction. + * @param proof The Merkle proof for the allowlist. + * @returns A Promise that resolves to the transaction hash + */ + claimFractionFromAllowlist: (params: ClaimFractionFromAllowlistParams) => Promise<`0x${string}` | undefined>; + /** * Batch mints a claim fraction from an allowlist * @param claimIds Array of the IDs of the claims to mint fractions for. @@ -209,6 +296,7 @@ export interface HypercertClientMethods { * @note The length of the arrays must be equal. * @note The order of the arrays must be equal. * @returns A Promise that resolves to the transaction hash + * @deprecated use `batchClaimFractionsFromAllowlists` instead */ batchMintClaimFractionsFromAllowlists: ( claimIds: bigint[], @@ -216,10 +304,32 @@ export interface HypercertClientMethods { proofs: (Hex | ByteArray)[][], ) => Promise<`0x${string}` | undefined>; + /** + * Batch mints a claim fraction from an allowlist + * @param claimIds Array of the IDs of the claims to mint fractions for. + * @param units Array of the number of units for each fraction. + * @param proofs Array of Merkle proofs for the allowlists. + * @returns A Promise that resolves to the transaction receipt + * @note The length of the arrays must be equal. + * @note The order of the arrays must be equal. + * @returns A Promise that resolves to the transaction hash + */ + batchClaimFractionsFromAllowlists: ( + params: BatchClaimFractionsFromAllowlistsParams, + ) => Promise<`0x${string}` | undefined>; + /** * Check if a claim or fraction is on the chain that the Hypercertclient * is currently connected to * @param claimOrFractionId The ID of the claim or fraction to check. + * @deprecated use `isHypercertsOrFractionOnConnectedChain` instead */ isClaimOrFractionOnConnectedChain: (claimOrFractionId: string) => boolean; + + /** + * Check if a claim or fraction is on the chain that the Hypercertclient + * is currently connected to + * @param claimOrFractionId The ID of the claim or fraction to check. + */ + isHypercertsOrFractionOnConnectedChain: (claimOrFractionId: string) => boolean; } diff --git a/sdk/test/client/burn.test.ts b/sdk/test/client/burn.test.ts index 8f5316c9..96e52a18 100644 --- a/sdk/test/client/burn.test.ts +++ b/sdk/test/client/burn.test.ts @@ -69,7 +69,7 @@ describe("burn fraction tokens in HypercertClient", () => { expect(e).to.be.instanceOf(ClientError); const error = e as ClientError; - expect(error.message).to.eq("Claim is not owned by the signer"); + expect(error.message).to.eq("Hypercert is not owned by the signer"); } //TODO determine underlying calls and mock those out. Some are provider simulation calls diff --git a/sdk/test/client/minting.test.ts b/sdk/test/client/minting.test.ts index 78492157..128990cd 100644 --- a/sdk/test/client/minting.test.ts +++ b/sdk/test/client/minting.test.ts @@ -107,7 +107,7 @@ describe("mintClaim in HypercertClient", () => { try { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - hash = await client.mintClaim(formattedData!, 1000n, TransferRestrictions.AllowAll, { + hash = await client.mintClaim(formattedData!, 1000n, TransferRestrictions.AllowAll, undefined, { gasPrice: "FALSE_VALUE" as unknown as bigint, }); expect.fail("Should throw Error"); @@ -118,7 +118,7 @@ describe("mintClaim in HypercertClient", () => { } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - hash = await client.mintClaim(formattedData!, 1000n, TransferRestrictions.AllowAll, { gasPrice: 100n }); + hash = await client.mintClaim(formattedData!, 1000n, TransferRestrictions.AllowAll, undefined, { gasPrice: 100n }); expect(isHex(hash)).to.be.true; expect(readSpy.callCount).to.equal(0);