mirror of
https://github.com/0xbow-io/privacy-pools-core.git
synced 2026-01-09 01:17:58 -05:00
feat: add get asset config to sdk (#70)
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 }>;
|
||||
|
||||
Reference in New Issue
Block a user