UNPKG

@agoric/zoe

Version:

Zoe: the Smart Contract Framework for Offer Enforcement

31 lines (27 loc) 1.01 kB
import { AmountMath } from '@agoric/ertp'; import { makeRatio } from '../src/contractSupport/index.js'; /** * @import {Amount, Brand, DepositFacet, Issuer, IssuerKit, NatValue} from '@agoric/ertp'; */ /** @param {Pick<IssuerKit<'nat', any>, 'brand' | 'issuer' | 'mint'>} kit */ export const withAmountUtils = kit => { const decimalPlaces = kit.issuer.getDisplayInfo?.()?.decimalPlaces ?? 6; return { ...kit, /** @param {NatValue} v */ make: v => AmountMath.make(kit.brand, v), makeEmpty: () => AmountMath.makeEmpty(kit.brand), /** * @param {NatValue} n * @param {NatValue} [d] */ makeRatio: (n, d) => makeRatio(n, kit.brand, d), /** @param {number} n */ units: n => AmountMath.make(kit.brand, BigInt(Math.round(n * 10 ** decimalPlaces))), /** The intact Exo remotable */ issuerKit: kit, }; }; /** @typedef {ReturnType<typeof withAmountUtils>} AmountUtils */ export { makeFakeStorageKit } from '@agoric/internal/src/storage-test-utils.js';