import type { Address } from "viem"; import type { LucidlyClient } from "./client.js"; import type { TxResult } from "./types.js"; import { AccountantWithRateProviders } from "./artifacts.js"; /** Resolve the Accountant address for a vault. The vault address alone isn't the accountant, * so callers pass the accountant address (from deploy) or set it as the active vault's accountant. * For convenience the read methods accept an explicit accountant address. */ export class AccountantModule { constructor(private readonly c: LucidlyClient) {} /** Current exchange rate (base-asset units per share). Pass the accountant address. */ async getRate(accountant?: Address): Promise { const a = this.c.requireAccountant("accountant.getRate", accountant); return this.c.read({ address: a, abi: AccountantWithRateProviders.abi, functionName: "getRate" }); } /** Share price expressed in `quote` asset units. */ async getRateInQuote(quote: Address | string, accountant?: Address): Promise { const a = this.c.requireAccountant("accountant.getRateInQuote", accountant); const q = this.c.resolveToken(quote); return this.c.read({ address: a, abi: AccountantWithRateProviders.abi, functionName: "getRateInQuote", args: [q], }); } /** Push a new exchange rate (requires UPDATE_EXCHANGE_RATE role and within bounds/delay). */ async updateRate(newRate: bigint, accountant?: Address): Promise { const a = this.c.requireAccountant("accountant.updateRate", accountant); const hash = await this.c.send({ address: a, abi: AccountantWithRateProviders.abi, functionName: "updateExchangeRate", args: [newRate], }); return this.c.wrapTx(hash); } }