diff --git a/packages/inter-protocol/test/liquidationVisibility/assertions.js b/packages/inter-protocol/test/liquidationVisibility/assertions.js index 81ff3c7434e..82a29889c55 100644 --- a/packages/inter-protocol/test/liquidationVisibility/assertions.js +++ b/packages/inter-protocol/test/liquidationVisibility/assertions.js @@ -33,25 +33,21 @@ export const assertBidderPayout = async ( )); }; -export const assertReserveState = async (t, metricsTopic, method, expected) => { - const m = await subscriptionTracker(t, metricsTopic); - +export const assertReserveState = async (metricTracker, method, expected) => { switch (method) { case 'initial': - await m.assertInitial(expected); + await metricTracker.assertInitial(expected); break; case 'like': - await m.assertLike(expected); + await metricTracker.assertLike(expected); break; case 'state': - await m.assertState(expected); + await metricTracker.assertState(expected); break; default: console.log('Default'); break; } - - return m; }; export const assertVaultCurrentDebt = async (t, vault, debt) => { diff --git a/packages/inter-protocol/test/liquidationVisibility/test-liquidationVisibility.js b/packages/inter-protocol/test/liquidationVisibility/test-liquidationVisibility.js index 4152d36b06a..720893167d8 100644 --- a/packages/inter-protocol/test/liquidationVisibility/test-liquidationVisibility.js +++ b/packages/inter-protocol/test/liquidationVisibility/test-liquidationVisibility.js @@ -35,7 +35,8 @@ import { startAuctionClock, getDataFromVstorage, openVault, -} from './tools.js'; + getMetricTrackers, adjustVault +} from "./tools.js"; import { assertBidderPayout, assertCollateralProceeds, @@ -235,21 +236,20 @@ test('Auction sells all collateral w/shortfall', async t => { } = services; await E(reserveCreatorFacet).addIssuer(aeth.issuer, 'Aeth'); - const metricsTopic = await E.get(E(reservePublicFacet).getPublicTopics()) - .metrics; - const m = await assertReserveState( + const { reserveTracker, collateralManagerTracker } = await getMetricTrackers({ t, - metricsTopic, + collateralManager: aethCollateralManager, + reservePublicFacet, + }); + + await assertReserveState( + reserveTracker, 'initial', reserveInitialState(run.makeEmpty()), ); let shortfallBalance = 0n; - const aethVaultMetrics = await vaultManagerMetricsTracker( - t, - aethCollateralManager, - ); - await aethVaultMetrics.assertInitial({ + await collateralManagerTracker.assertInitial({ // present numActiveVaults: 0, numLiquidatingVaults: 0, @@ -293,7 +293,7 @@ test('Auction sells all collateral w/shortfall', async t => { await assertVaultDebtSnapshot(t, aliceNotifier, aliceWantMinted); let totalDebt = 5250n; - await aethVaultMetrics.assertChange({ + await collateralManagerTracker.assertChange({ numActiveVaults: 1, totalCollateral: { value: 1000n }, totalDebt: { value: totalDebt }, @@ -306,12 +306,13 @@ test('Auction sells all collateral w/shortfall', async t => { // Alice reduce collateral by 300. That leaves her at 700 * 10 > 1.05 * 5000. // Prices will drop from 10 to 7, she'll be liquidated: 700 * 7 < 1.05 * 5000. const collateralDecrement = aeth.make(300n); - const aliceReduceCollateralSeat = await E(zoe).offer( - E(aliceVault).makeAdjustBalancesInvitation(), - harden({ + const aliceReduceCollateralSeat = await adjustVault({ + t, + vault: aliceVault, + proposal: { want: { Collateral: collateralDecrement }, - }), - ); + }, + }); await E(aliceReduceCollateralSeat).getOfferResult(); trace('alice '); @@ -319,7 +320,7 @@ test('Auction sells all collateral w/shortfall', async t => { await assertVaultDebtSnapshot(t, aliceNotifier, aliceWantMinted); trace(t, 'alice reduce collateral'); - await aethVaultMetrics.assertChange({ + await collateralManagerTracker.assertChange({ totalCollateral: { value: 700n }, }); @@ -339,7 +340,7 @@ test('Auction sells all collateral w/shortfall', async t => { ); let currentTime = now1; - await aethVaultMetrics.assertChange({ + await collateralManagerTracker.assertChange({ lockedQuote: makeRatioFromAmounts( aeth.make(1_000_000n), run.make(7_000_000n), @@ -353,8 +354,7 @@ test('Auction sells all collateral w/shortfall', async t => { await assertVaultState(t, aliceNotifier, Phase.LIQUIDATED); trace(t, 'alice liquidated', currentTime); - totalDebt += 30n; - await aethVaultMetrics.assertChange({ + await collateralManagerTracker.assertChange({ numActiveVaults: 0, numLiquidatingVaults: 1, liquidatingCollateral: { value: 700n }, @@ -363,11 +363,11 @@ test('Auction sells all collateral w/shortfall', async t => { }); shortfallBalance += 2065n; - await m.assertChange({ + await reserveTracker.assertChange({ shortfallBalance: { value: shortfallBalance }, }); - await aethVaultMetrics.assertChange({ + await collateralManagerTracker.assertChange({ liquidatingDebt: { value: 0n }, liquidatingCollateral: { value: 0n }, totalCollateral: { value: 0n }, diff --git a/packages/inter-protocol/test/liquidationVisibility/tools.js b/packages/inter-protocol/test/liquidationVisibility/tools.js index 905dd5ecdb8..0fed62186ad 100644 --- a/packages/inter-protocol/test/liquidationVisibility/tools.js +++ b/packages/inter-protocol/test/liquidationVisibility/tools.js @@ -8,6 +8,7 @@ import { eventLoopIteration } from '@agoric/internal/src/testing-utils.js'; import { TimeMath } from '@agoric/time'; import { subscribeEach } from '@agoric/notifier'; import '../../src/vaultFactory/types.js'; +import exp from 'constants'; import { withAmountUtils } from '../supports.js'; import { getRunFromFaucet, @@ -285,6 +286,52 @@ export const openVault = async ({ ); }; +/** + * @typedef {object} AdjustVaultParams + * @property {object} t + * @property {Vault} vault + * @property {{ + * want: [ + * { + * Collateral: Amount<'nat'>; + * Minted: Amount<'nat'>; + * }, + * ]; + * give: [ + * { + * Collateral: Amount<'nat'>; + * Minted: Amount<'nat'>; + * }, + * ]; + * }} proposal + * @property {{ + * want: [ + * { + * Collateral: Payment; + * Minted: Payment; + * }, + * ]; + * give: [ + * { + * Collateral: Payment; + * Minted: Payment; + * }, + * ]; + * }} [payment] + */ + +/** + * @param {AdjustVaultParams} adjustVaultParams + * @returns {Promise} + */ +export const adjustVault = async ({ t, vault, proposal, payment }) => { + return E(t.context.zoe).offer( + E(vault).makeAdjustBalancesInvitation(), + harden(proposal), + payment, + ); +}; + /** * @typedef {object} GetTrackerParams * @property {any} t @@ -294,8 +341,8 @@ export const openVault = async ({ /** * @typedef {object} Trackers - * @property {object | undefined} reserveTracker - * @property {object | undefined} collateralManagerTracker + * @property {object} [reserveTracker] + * @property {object} [collateralManagerTracker] */ /** @@ -308,7 +355,7 @@ export const getMetricTrackers = async ({ reservePublicFacet, }) => { /** @type {Trackers} */ - const trackers = harden({}); + const trackers = {}; if (reservePublicFacet) { const metricsTopic = await E.get(E(reservePublicFacet).getPublicTopics()) .metrics; @@ -322,7 +369,7 @@ export const getMetricTrackers = async ({ ); } - return trackers; + return harden(trackers); }; export const getBookDataTracker = async (t, auctioneerPublicFacet, brand) => {