feat: add get asset config to sdk

This commit is contained in:
Francisco Bezzecchi
2025-04-18 17:52:09 -03:00
parent 360b97b445
commit f31db31c3f
3 changed files with 48 additions and 0 deletions

View File

@@ -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<AssetConfig> {
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.

View File

@@ -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);
}
}

View File

@@ -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<void>;
@@ -46,6 +53,7 @@ export interface ContractInteractions {
getScope(privacyPoolAddress: Address): Promise<bigint>;
getStateRoot(privacyPoolAddress: Address): Promise<bigint>;
getStateSize(privacyPoolAddress: Address): Promise<bigint>;
getAssetConfig(assetAddress: Address): Promise<AssetConfig>;
getScopeData(
scope: bigint,
): Promise<{ poolAddress: Address | null; assetAddress: Address | null }>;