/** * Constants for vault phase. * * - ACTIVE - vault is in use and can be changed * - LIQUIDATING - vault is being liquidated by the vault manager, and cannot be * changed by the user. If liquidation fails, vaults may remain in this state. * An upgrade to the contract might be able to recover them. * - TRANSFER - vault is able to be transferred (payments and debits frozen until * it has a new owner) * - CLOSED - vault was closed by the user and all assets have been paid out * - LIQUIDATED - vault was closed by the manager, with remaining assets paid to * owner */ export type Phase = (typeof Phase)[keyof typeof Phase]; export namespace Phase { let ACTIVE: "active"; let LIQUIDATING: "liquidating"; let CLOSED: "closed"; let LIQUIDATED: "liquidated"; let TRANSFER: "transfer"; } /** * @typedef {object} VaultNotification * @property {Amount<'nat'>} locked Amount of Collateral locked * @property {{ debt: Amount<'nat'>; interest: Ratio }} debtSnapshot 'debt' at * the point the compounded interest was 'interest' * @property {Phase} vaultState */ /** * @typedef {object} VaultManager * @property {() => Subscriber} getAssetSubscriber * @property {(collateralAmount: Amount) => Amount<'nat'>} maxDebtFor * @property {() => Brand<'nat'>} getCollateralBrand * @property {(base: string) => string} scopeDescription * @property {() => Brand<'nat'>} getDebtBrand * @property {MintAndTransfer} mintAndTransfer * @property {(amount: Amount, seat: ZCFSeat) => void} burn * @property {() => Ratio} getCompoundedInterest * @property {( * oldDebt: import('./storeUtils.js').NormalizedDebt, * oldCollateral: Amount<'nat'>, * vaultId: VaultId, * vaultPhase: VaultPhase, * vault: Vault, * ) => void} handleBalanceChange * @property {() => import('./vaultManager.js').GovernedParamGetters} getGovernedParams */ /** * @typedef {Readonly<{ * idInManager: VaultId; * manager: VaultManager; * storageNode: StorageNode; * vaultSeat: ZCFSeat; * }>} ImmutableState */ /** * Snapshot is of the debt and compounded interest when the principal was last * changed. * * @typedef {{ * interestSnapshot: Ratio; * phase: VaultPhase; * debtSnapshot: Amount<'nat'>; * outerUpdater: * | import('@agoric/zoe/src/contractSupport/recorder.js').Recorder * | null; * }} MutableState */ export const VaultI: import("@endo/patterns").InterfaceGuard<{ getCollateralAmount: import("@endo/patterns").MethodGuard; getCurrentDebt: import("@endo/patterns").MethodGuard; getNormalizedDebt: import("@endo/patterns").MethodGuard; getVaultSeat: import("@endo/patterns").MethodGuard; initVaultKit: import("@endo/patterns").MethodGuard; liquidated: import("@endo/patterns").MethodGuard; liquidating: import("@endo/patterns").MethodGuard; makeAdjustBalancesInvitation: import("@endo/patterns").MethodGuard; makeCloseInvitation: import("@endo/patterns").MethodGuard; makeTransferInvitation: import("@endo/patterns").MethodGuard; abortLiquidation: import("@endo/patterns").MethodGuard; }>; export function prepareVault(baggage: import("@agoric/swingset-liveslots").Baggage, makeRecorderKit: import("@agoric/zoe/src/contractSupport/recorder.js").MakeRecorderKit, zcf: ZCF): (manager: VaultManager, idInManager: string, storageNode: globalThis.StorageNode) => import("@endo/exo").GuardedKit<{ helper: { collateralBrand(): Brand<"nat">; debtBrand(): Brand<"nat">; emptyCollateral(): import("@agoric/ertp").NatAmount; emptyDebt(): import("@agoric/ertp").NatAmount; /** * @typedef {{ * give: { Collateral: Amount<'nat'>; Minted: Amount<'nat'> }; * want: { Collateral: Amount<'nat'>; Minted: Amount<'nat'> }; * }} FullProposal */ /** * @param {ProposalRecord} partial * @returns {FullProposal} */ fullProposal(partial: ProposalRecord): { give: { Collateral: Amount<"nat">; Minted: Amount<"nat">; }; want: { Collateral: Amount<"nat">; Minted: Amount<"nat">; }; }; /** @param {VaultPhase} newPhase */ assignPhase(newPhase: VaultPhase): void; assertActive(): void; assertCloseable(): void; /** * Called whenever the debt is paid or created through a transaction, * but not for interest accrual. * * @param {Amount<'nat'>} newDebt - principal and all accrued interest */ updateDebtSnapshot(newDebt: Amount<"nat">): void; /** * Update the debt balance and propagate upwards to maintain aggregate * debt and liquidation order. * * @param {NormalizedDebt} oldDebtNormalized - prior principal and all * accrued interest, normalized to the launch of the vaultManager * @param {Amount<'nat'>} oldCollateral - actual collateral * @param {Amount<'nat'>} newDebtActual - actual principal and all * accrued interest */ updateDebtAccounting(oldDebtNormalized: NormalizedDebt, oldCollateral: Amount<"nat">, newDebtActual: Amount<"nat">): void; /** * @param {ZCFSeat} seat * @returns {Amount<'nat'>} */ getCollateralAllocated(seat: ZCFSeat): Amount<"nat">; /** * @param {ZCFSeat} seat * @returns {Amount<'nat'>} */ getMintedAllocated(seat: ZCFSeat): Amount<"nat">; assertVaultHoldsNoMinted(): void; /** * @param {Amount<'nat'>} collateralAmount * @param {Amount<'nat'>} proposedDebt */ assertSufficientCollateral(collateralAmount: Amount<"nat">, proposedDebt: Amount<"nat">): void; /** @param {Phase} newPhase */ getStateSnapshot(newPhase: Phase): { debtSnapshot: { debt: import("@agoric/ertp").NatAmount; interest: Ratio; }; locked: import("@agoric/ertp").NatAmount; vaultState: Phase; }; /** call this whenever anything changes! */ updateUiState(): void; /** @param {ZCFSeat} seat */ closeHook(seat: ZCFSeat): Promise; /** * Calculate the fee, the amount to mint and the resulting debt. The * give and the want together reflect a delta, where typically one is * zero because they come from the gave/want of an offer proposal. If * the `want` is zero, the `fee` will also be zero, so the simple math * works. * * @param {Amount<'nat'>} currentDebt * @param {Amount<'nat'>} giveAmount * @param {Amount<'nat'>} wantAmount */ debtFee(currentDebt: Amount<"nat">, giveAmount: Amount<"nat">, wantAmount: Amount<"nat">): { newDebt: import("@agoric/ertp").NatAmount; toMint: import("@agoric/ertp").NatAmount; fee: import("@agoric/ertp").NatAmount; surplus: import("@agoric/ertp").NatAmount; }; /** * Adjust principal and collateral (atomically for offer safety) * * @param {ZCFSeat} clientSeat * @returns {string} success message */ adjustBalancesHook(clientSeat: ZCFSeat): string; /** * @param {ZCFSeat} clientSeat * @param {FullProposal} fp * @param {ReturnType} costs * @param {object} accounting * @param {NormalizedDebt} accounting.normalizedDebtPre * @param {Amount<'nat'>} accounting.collateralPre * @returns {string} success message */ commitBalanceAdjustment(clientSeat: ZCFSeat, fp: { give: { Collateral: Amount<"nat">; Minted: Amount<"nat">; }; want: { Collateral: Amount<"nat">; Minted: Amount<"nat">; }; }, { newDebt, fee, surplus, toMint }: ReturnType, { normalizedDebtPre, collateralPre }: { normalizedDebtPre: NormalizedDebt; collateralPre: Amount<"nat">; }): string; /** * @param {ZCFSeat} seat * @returns {VaultKit} */ makeTransferInvitationHook(seat: ZCFSeat): VaultKit; }; self: { getVaultSeat(): globalThis.ZCFSeat; /** * @param {ZCFSeat} seat * @param {StorageNode} storageNode */ initVaultKit(seat: ZCFSeat, storageNode: StorageNode): Promise<{ publicSubscribers: { vault: { description: string; subscriber: globalThis.Subscriber; storagePath: Promise; }; }; invitationMakers: import("@endo/exo").Guarded<{ AdjustBalances(): Promise>; CloseVault(): Promise>; TransferVault(): Promise>; }>; vault: import("@endo/exo").Guarded<{ getPublicTopics(): { vault: { description: string; subscriber: globalThis.Subscriber; storagePath: Promise; }; }; makeAdjustBalancesInvitation(): Promise>; makeCloseInvitation(): Promise>; makeTransferInvitation(): Promise>; getCollateralAmount(): import("@agoric/ertp").NatAmount; getCurrentDebt(): import("@agoric/ertp").NatAmount; getNormalizedDebt(): NormalizedDebt; }>; vaultUpdater: import("@agoric/zoe/src/contractSupport/recorder.js").Recorder; }>; /** Called by manager at start of liquidation. */ liquidating(): void; /** * Called by manager at end of liquidation, at which point all debts * have been covered. */ liquidated(): void; /** * Called by vaultManager when the auction wasn't able to sell the * collateral. The liquidation fee was charged against the collateral, * but the debt will be restored and the vault will be active again. * Liquidation.md has details on the liquidation approach. */ abortLiquidation(): string; makeAdjustBalancesInvitation(): Promise>; makeCloseInvitation(): Promise>; /** @returns {Promise>} */ makeTransferInvitation(): Promise>; /** @returns {Amount<'nat'>} */ getCollateralAmount(): Amount<"nat">; /** * The actual current debt, including accrued interest. * * This looks like a simple getter but it does a lot of the heavy * lifting for interest accrual. Rather than updating all records when * interest accrues, the vault manager updates just its rolling * compounded interest. Here we calculate what the current debt is given * what's recorded in this vault and what interest has compounded since * this vault record was written. * * @returns {Amount<'nat'>} * @see getNormalizedDebt */ getCurrentDebt(): Amount<"nat">; /** * The normalization puts all debts on a common time-independent scale * since the launch of this vault manager. This allows the manager to * order vaults by their debt-to-collateral ratios without having to * mutate the debts as the interest accrues. * * @returns {import('./storeUtils.js').NormalizedDebt} as if the vault * was open at the launch of this manager, before any interest * accrued * @see getActualDebAmount */ getNormalizedDebt(): import("./storeUtils.js").NormalizedDebt; }; }>; export type VaultPhase = Exclude; export type VaultNotification = { /** * Amount of Collateral locked */ locked: Amount<"nat">; /** * 'debt' at * the point the compounded interest was 'interest' */ debtSnapshot: { debt: Amount<"nat">; interest: Ratio; }; vaultState: Phase; }; export type VaultManager = { getAssetSubscriber: () => Subscriber; maxDebtFor: (collateralAmount: Amount) => Amount<"nat">; getCollateralBrand: () => Brand<"nat">; scopeDescription: (base: string) => string; getDebtBrand: () => Brand<"nat">; mintAndTransfer: MintAndTransfer; burn: (amount: Amount, seat: ZCFSeat) => void; getCompoundedInterest: () => Ratio; handleBalanceChange: (oldDebt: import("./storeUtils.js").NormalizedDebt, oldCollateral: Amount<"nat">, vaultId: VaultId, vaultPhase: VaultPhase, vault: Vault) => void; getGovernedParams: () => import("./vaultManager.js").GovernedParamGetters; }; export type ImmutableState = Readonly<{ idInManager: VaultId; manager: VaultManager; storageNode: StorageNode; vaultSeat: ZCFSeat; }>; /** * Snapshot is of the debt and compounded interest when the principal was last * changed. */ export type MutableState = { interestSnapshot: Ratio; phase: VaultPhase; debtSnapshot: Amount<"nat">; outerUpdater: import("@agoric/zoe/src/contractSupport/recorder.js").Recorder | null; }; export type Vault = EReturn>["self"]; import type { Brand } from '@agoric/ertp/src/types.js'; import type { NormalizedDebt } from './storeUtils.js'; import { calculateDebtCosts } from './math.js'; import type { EReturn } from '@endo/far'; //# sourceMappingURL=vault.d.ts.map