diff --git a/packages/sdk/src/core/contracts.service.ts b/packages/sdk/src/core/contracts.service.ts index 35f5504..1776b23 100644 --- a/packages/sdk/src/core/contracts.service.ts +++ b/packages/sdk/src/core/contracts.service.ts @@ -13,6 +13,7 @@ import { } from "viem"; import { Withdrawal, WithdrawalProof } from "../types/withdrawal.js"; import { + AssetConfig, ContractInteractions, TransactionResponse, } from "../interfaces/contracts.interface.js"; @@ -283,6 +284,40 @@ export class ContractInteractionsService implements ContractInteractions { return BigInt(stateSize as string); } + + /** + * Retrieves data from the corresponding asset + * + * @param assetAddress - The asset contract address. + * @returns AssetConfig - An object containing the privacy pool address, minimum deposit amount, vetting fee and maximum relaying fee. + * @throws ContractError if the asset does not exist in the pool. + */ + async getAssetConfig(assetAddress: Address): Promise { + const assetConfig = await this.publicClient.readContract({ + address: this.entrypointAddress, + abi: IEntrypointABI as Abi, + account: this.account, + args: [assetAddress], + functionName: "assetConfig", + }); + const [pool, minimumDepositAmount, vettingFeeBPS, maxRelayFeeBPS] = assetConfig as [string, bigint, bigint, bigint]; + + // if no pool throw error + if ( + !pool || + pool === "0x0000000000000000000000000000000000000000" + ) { + throw ContractError.assetNotFound(assetAddress); + } + + return { + pool: getAddress(pool), + minimumDepositAmount, + vettingFeeBPS, + maxRelayFeeBPS + } + } + /** * Retrieves data about a specific scope, including the associated privacy pool * and the asset used in that pool. diff --git a/packages/sdk/src/errors/base.error.ts b/packages/sdk/src/errors/base.error.ts index fed91eb..03c4dfa 100644 --- a/packages/sdk/src/errors/base.error.ts +++ b/packages/sdk/src/errors/base.error.ts @@ -117,4 +117,9 @@ export class ContractError extends SDKError { public static scopeNotFound(scope: bigint): ContractError { return new ContractError(`No pool found for scope ${scope.toString()}`, ErrorCode.CONTRACT_ERROR); } + + public static assetNotFound(address: string): ContractError { + return new ContractError(`Asset ${address} has no pool`, ErrorCode.CONTRACT_ERROR); + } + } diff --git a/packages/sdk/src/interfaces/contracts.interface.ts b/packages/sdk/src/interfaces/contracts.interface.ts index 9d409ea..fbc54b9 100644 --- a/packages/sdk/src/interfaces/contracts.interface.ts +++ b/packages/sdk/src/interfaces/contracts.interface.ts @@ -9,6 +9,13 @@ export interface SolidityGroth16Proof { pubSignals: bigint[]; } +export interface AssetConfig { + pool: Address, + minimumDepositAmount: bigint, + vettingFeeBPS: bigint, + maxRelayFeeBPS: bigint +} + export interface TransactionResponse { hash: string; wait: () => Promise; @@ -46,6 +53,7 @@ export interface ContractInteractions { getScope(privacyPoolAddress: Address): Promise; getStateRoot(privacyPoolAddress: Address): Promise; getStateSize(privacyPoolAddress: Address): Promise; + getAssetConfig(assetAddress: Address): Promise; getScopeData( scope: bigint, ): Promise<{ poolAddress: Address | null; assetAddress: Address | null }>;