diff --git a/packages/run-protocol/src/reserve/assetReserve.js b/packages/run-protocol/src/reserve/assetReserve.js index 71340c183fa..de5a7110bbb 100644 --- a/packages/run-protocol/src/reserve/assetReserve.js +++ b/packages/run-protocol/src/reserve/assetReserve.js @@ -25,6 +25,8 @@ const nonalphanumeric = /[^A-Za-z0-9]/g; * * @property {AmountKeywordRecord} allocations * @property {Amount<'nat'>} shortfallBalance shortfall from liquiditation that + * @property {Amount<'nat'>} totalFeeMinted total RUN minted to date + * @property {Amount<'nat'>} totalFeeBurned total RUN burned to date * has not yet been compensated. */ @@ -222,6 +224,9 @@ const start = async (zcf, privateArgs) => { const { brand: runBrand } = await E(runMint).getIssuerRecord(); + let totalFeeMinted = AmountMath.makeEmpty(runBrand); + let totalFeeBurned = AmountMath.makeEmpty(runBrand); + // shortfall in Vaults due to liquidations less than debt. This value can be // reduced by various actions which burn RUN. let shortfallBalance = AmountMath.makeEmpty(runBrand); @@ -236,6 +241,8 @@ const start = async (zcf, privateArgs) => { const metrics = harden({ allocations: getAllocations(), shortfallBalance, + totalFeeMinted, + totalFeeBurned, }); metricsPublication.updateState(metrics); }; @@ -270,6 +277,8 @@ const start = async (zcf, privateArgs) => { // create the RUN const offerToSeat = runMint.mintGains(harden({ RUN: runAmount })); + totalFeeMinted = AmountMath.add(totalFeeMinted, runAmount); + offerToSeat.incrementBy( collateralSeat.decrementBy( harden({ @@ -316,6 +325,7 @@ const start = async (zcf, privateArgs) => { }), ); zcf.reallocate(offerToSeat, collateralSeat); + updateMetrics(); }; const burnRUNToReduceShortfall = reduction => { @@ -328,6 +338,8 @@ const start = async (zcf, privateArgs) => { } runMint.burnLosses(harden({ [runKeyword]: amountToBurn }), collateralSeat); + totalFeeBurned = AmountMath.add(totalFeeBurned, amountToBurn); + reduceLiquidationShortfall(amountToBurn); }; diff --git a/packages/run-protocol/test/metrics.js b/packages/run-protocol/test/metrics.js index 1e8e6eb71de..75f7262c125 100644 --- a/packages/run-protocol/test/metrics.js +++ b/packages/run-protocol/test/metrics.js @@ -102,3 +102,9 @@ export const vaultManagerMetricsTracker = async (t, publicFacet) => { assertFullyLiquidated, }); }; +export const reserveInitialState = emptyRun => ({ + allocations: {}, + shortfallBalance: emptyRun, + totalFeeBurned: emptyRun, + totalFeeMinted: emptyRun, +}); diff --git a/packages/run-protocol/test/reserve/test-reserve.js b/packages/run-protocol/test/reserve/test-reserve.js index ebdbdd35a8f..b9b77486a7f 100644 --- a/packages/run-protocol/test/reserve/test-reserve.js +++ b/packages/run-protocol/test/reserve/test-reserve.js @@ -10,7 +10,7 @@ import { eventLoopIteration } from '@agoric/zoe/tools/eventLoopIteration.js'; import { setupReserveServices } from './setup.js'; import { unsafeMakeBundleCache } from '../bundleTool.js'; -import { subscriptionTracker } from '../metrics.js'; +import { reserveInitialState, subscriptionTracker } from '../metrics.js'; import { subscriptionKey } from '../supports.js'; const addLiquidPool = async ( @@ -173,6 +173,10 @@ test('governance add Liquidity to the AMM', async t => { 'should be 80K', ); + const metricsSub = await E(reserve.reserveCreatorFacet).getMetrics(); + const m = await subscriptionTracker(t, metricsSub); + await m.assertInitial(reserveInitialState(AmountMath.makeEmpty(runBrand))); + const invitation = await E( reserve.reservePublicFacet, ).makeAddCollateralInvitation(); @@ -230,6 +234,14 @@ test('governance add Liquidity to the AMM', async t => { }), 'should be 80K', ); + + await m.assertChange({ + totalFeeMinted: { value: 80_000n }, + allocations: { + Rmoola: moola(10_000n), + RmoolaLiquidity: AmountMath.make(moolaLiquidityBrand, 85_622n), + }, + }); }); test('request more collateral than available', async t => { @@ -335,10 +347,7 @@ test('reserve track shortfall', async t => { const metricsSub = await E(reserve.reserveCreatorFacet).getMetrics(); const m = await subscriptionTracker(t, metricsSub); - await m.assertInitial({ - allocations: {}, - shortfallBalance: AmountMath.makeEmpty(runBrand), - }); + await m.assertInitial(reserveInitialState(AmountMath.makeEmpty(runBrand))); await m.assertChange({ shortfallBalance: { value: runningShortfall }, }); @@ -390,10 +399,7 @@ test('reserve burn IST', async t => { const metricsSub = await E(reserve.reserveCreatorFacet).getMetrics(); const m = await subscriptionTracker(t, metricsSub); - await m.assertInitial({ - allocations: {}, - shortfallBalance: AmountMath.makeEmpty(runBrand), - }); + await m.assertInitial(reserveInitialState(AmountMath.makeEmpty(runBrand))); await m.assertChange({ shortfallBalance: { value: runningShortfall }, }); @@ -454,6 +460,7 @@ test('reserve burn IST', async t => { value: runningShortfall, }, allocations: { RUN: AmountMath.makeEmpty(runBrand) }, + totalFeeBurned: { value: 1000n }, }); }); diff --git a/packages/run-protocol/test/vaultFactory/test-vaultFactory.js b/packages/run-protocol/test/vaultFactory/test-vaultFactory.js index 83d29e72161..7868e92d004 100644 --- a/packages/run-protocol/test/vaultFactory/test-vaultFactory.js +++ b/packages/run-protocol/test/vaultFactory/test-vaultFactory.js @@ -52,6 +52,7 @@ import { metricsTracker, vaultManagerMetricsTracker, subscriptionTracker, + reserveInitialState, } from '../metrics.js'; /** @typedef {Record & { @@ -637,10 +638,7 @@ test('price drop', async t => { const metricsSub = await E(reserveCreatorFacet).getMetrics(); const m = await subscriptionTracker(t, metricsSub); - await m.assertInitial({ - allocations: {}, - shortfallBalance: run.makeEmpty(), - }); + await m.assertInitial(reserveInitialState(run.makeEmpty())); const debtAmountAfter = await E(vault).getCurrentDebt(); const finalNotification = await E(vaultNotifier).getUpdateSince(); @@ -764,11 +762,7 @@ test('price falls precipitously', async t => { const metricsSub = await E(reserveCreatorFacet).getMetrics(); const m = await subscriptionTracker(t, metricsSub); - await m.assertInitial({ - allocations: {}, - shortfallBalance: run.makeEmpty(), - }); - + await m.assertInitial(reserveInitialState(run.makeEmpty())); await manualTimer.tick(); await assertDebtIs(debtAmount.value); @@ -1741,10 +1735,7 @@ test('mutable liquidity triggers and interest', async t => { const metricsSub = await E(reserveCreatorFacet).getMetrics(); const m = await subscriptionTracker(t, metricsSub); - await m.assertInitial({ - allocations: {}, - shortfallBalance: run.makeEmpty(), - }); + await m.assertInitial(reserveInitialState(run.makeEmpty())); let shortfallBalance = 0n; // initial loans /////////////////////////////////////