The createMusdClient surface: live reads, preview math, hints, lifecycle writes, and the redemption/keeper functions, all bound to one chain + clients.

interface MusdClient {
    addresses: MusdAddresses;
    chainId: number;
    contracts: MusdContracts;
    fixed: {
        CCR: 1500000000000000000n;
        DECIMAL_PRECISION: 1000000000000000000n;
        MCR: 1100000000000000000n;
        MIN_NET_DEBT_MIN: 50000000000000000000n;
        MUSD_GAS_COMPENSATION: 200000000000000000000n;
        ONE_HUNDRED_PCT: 1000000000000000000n;
        PERCENT_DIVISOR: 200n;
    };
    addCollateral(params: { amount: bigint }): Promise<WriteResult>;
    adjustTrove(params: AdjustTroveParams): Promise<WriteResult>;
    balanceOf(address: `0x${string}`): Promise<bigint>;
    batchLiquidate(borrowers: readonly `0x${string}`[]): Promise<WriteResult>;
    borrow(params: BorrowParams): Promise<WriteResult>;
    claim(): Promise<ClaimResult>;
    close(): Promise<WriteResult>;
    computeEntireDebt(params: ComputeEntireDebtParams): bigint;
    computeHints(params: ComputeHintsParams): Promise<Hints>;
    computeICR(params: ComputeICRParams): bigint;
    computeLiquidationPrice(params: ComputeLiquidationPriceParams): bigint;
    computeNICR(params: ComputeNICRParams): bigint;
    drawForMargin(params: DrawForMarginParams): Promise<MarginDraw>;
    getBorrowingCapacity(owner: `0x${string}`): Promise<BorrowingCapacity>;
    getBorrowingFee(debt: bigint): Promise<bigint>;
    getBorrowingPower(params: GetBorrowingPowerParams): Promise<BorrowingPower>;
    getClaimableCollateral(address: `0x${string}`): Promise<bigint>;
    getConstants(): Promise<MusdConstants>;
    getHealthFactor(params: { icr: bigint }): number;
    getOraclePrice(): Promise<bigint>;
    getSystemState(): Promise<SystemState>;
    getTrove(address: `0x${string}`): Promise<Trove>;
    invalidateConstants(): void;
    isLiquidatable(address: `0x${string}`): Promise<boolean>;
    liquidate(borrower: `0x${string}`): Promise<WriteResult>;
    maxWithdrawableCollateral(owner: `0x${string}`): Promise<MaxWithdrawable>;
    openTrove(params: OpenTroveParams): Promise<WriteResult>;
    previewAdjustTrove(params: PreviewAdjustParams): Promise<AdjustPreview>;
    previewBorrow(params: PreviewBorrowParams): Promise<BorrowPreview>;
    previewClose(owner: `0x${string}`): Promise<ClosePreview>;
    previewOpen(params: PreviewOpenParams): Promise<OpenPreview>;
    previewRedeem(params: PreviewRedeemParams): Promise<RedemptionPreview>;
    previewRefinance(owner: `0x${string}`): Promise<RefinancePreview>;
    previewWithdrawCollateral(
        params: { amount: bigint; owner: `0x${string}` },
    ): Promise<AdjustPreview>;
    redeem(params: RedeemParams): Promise<RedeemResult>;
    refinance(): Promise<WriteResult>;
    repay(params: { amount: bigint }): Promise<WriteResult>;
    verifyDeployment(): Promise<void>;
    withdrawCollateral(params: { amount: bigint }): Promise<WriteResult>;
}

Properties

addresses: MusdAddresses
chainId: number
contracts: MusdContracts
fixed: {
    CCR: 1500000000000000000n;
    DECIMAL_PRECISION: 1000000000000000000n;
    MCR: 1100000000000000000n;
    MIN_NET_DEBT_MIN: 50000000000000000000n;
    MUSD_GAS_COMPENSATION: 200000000000000000000n;
    ONE_HUNDRED_PCT: 1000000000000000000n;
    PERCENT_DIVISOR: 200n;
}

The bundled fixed constants (synchronous, no network).

Methods

  • The largest open draw that survives a price fall and a holding horizon the CALLER chooses (MK-240). Both inputs are required and have no default; how long a position is held and how far the price may fall are the holder's choices, not the library's. Returns the ceiling beside it and the margin it was solved with. The price history for choosing the inputs is on drawForMargin in math/getBorrowingPower.ts and in docs/03-core-api.md.

    Parameters

    Returns Promise<MarginDraw>

  • The contract's ceiling for an open at this collateral (MK-100, MK-240): the largest draw accepted right now with NO margin, which in normal mode opens at exactly the 110% liquidation threshold. A limit to display, never an amount to borrow, and there is no amount to borrow on this result. For a draw sized to a margin, call drawForMargin. An open time calculator only; for an existing Trove use previewBorrow.

    Parameters

    Returns Promise<BorrowingPower>

  • BTC surplus claimable by address (CollSurplusPool), pair with claim().

    Parameters

    • address: `0x${string}`

    Returns Promise<bigint>

  • Drop the cached governable constants, so the next getConstants re-reads them (MK-012).

    For when you know something changed and do not want to wait out the TTL: a governance event observed in a log subscription, or a test that wants a deterministic re-read. It does NOT clear the deployment verification, which is memoized for the client's lifetime on purpose: a wiring pointer changing is a redeployment, not a governance action.

    Returns void

  • Whether liquidate(address) would liquidate the Trove now: getCurrentICR < MCR in BOTH modes, and not the last Trove in the system (MK-001, MK-074). The protocol has no Recovery Mode widening (TroveManager.sol:1146-1148).

    Parameters

    • address: `0x${string}`

    Returns Promise<boolean>

  • Assert the contracts at the resolved addresses really are a consistent MUSD deployment (MK-008): code present at all seven bundled addresses, all fourteen cross wiring pointers resolving to that same map, HintHelpers.priceFeed() still unset, and MCR/CCR equal to the bundled fixed constants. One multicall, memoized after the first success, and awaited automatically before the first write.

    Calling it yourself is only necessary if you want the check to happen at a moment you choose, for example right after constructing a client against an overridden address map.

    Returns Promise<void>

    a bundled constant disagrees with the chain.

    missing code, or wiring that does not resolve.