Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish Reserve econ data: mint & burn #5753

Merged
merged 3 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/run-protocol/src/reserve/assetReserve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'>} mintedRUN total RUN minted to date
* @property {Amount<'nat'>} burnedRUN total RUN burned to date
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use Fee instead of RUN per #4800

and per

// Metrics naming scheme: nouns are present values; past-participles are accumulative.
minted should be second.

"total" helps convey that this is "minted ever" not any other time window.

Suggested change
* @property {Amount<'nat'>} mintedRUN total RUN minted to date
* @property {Amount<'nat'>} burnedRUN total RUN burned to date
* @property {Amount<'nat'>} totalFeeMinted total Fee minted to date
* @property {Amount<'nat'>} totalFeeBurned total Fee burned to date

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* has not yet been compensated.
*/

Expand Down Expand Up @@ -222,6 +224,9 @@ const start = async (zcf, privateArgs) => {

const { brand: runBrand } = await E(runMint).getIssuerRecord();

let mintedRUN = AmountMath.makeEmpty(runBrand);
let burnedRUN = AmountMath.makeEmpty(runBrand);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noting the variable names should continue to match the metric names

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


// 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);
Expand All @@ -236,6 +241,8 @@ const start = async (zcf, privateArgs) => {
const metrics = harden({
allocations: getAllocations(),
shortfallBalance,
mintedRUN,
burnedRUN,
});
metricsPublication.updateState(metrics);
};
Expand Down Expand Up @@ -270,6 +277,8 @@ const start = async (zcf, privateArgs) => {

// create the RUN
const offerToSeat = runMint.mintGains(harden({ RUN: runAmount }));
mintedRUN = AmountMath.add(mintedRUN, runAmount);

offerToSeat.incrementBy(
collateralSeat.decrementBy(
harden({
Expand Down Expand Up @@ -316,6 +325,7 @@ const start = async (zcf, privateArgs) => {
}),
);
zcf.reallocate(offerToSeat, collateralSeat);
updateMetrics();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed here but not after burnedRUN change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already called in burnRUNToReduceShortfall, because that calls increaseLiquidationShortfall. addLiquiditytoAmmPool mints, but doesn't adjust the shortfall. The shortfall is increased by other contracts that get a shortfallReportingInvitation.

};

const burnRUNToReduceShortfall = reduction => {
Expand All @@ -328,6 +338,8 @@ const start = async (zcf, privateArgs) => {
}

runMint.burnLosses(harden({ [runKeyword]: amountToBurn }), collateralSeat);
burnedRUN = AmountMath.add(burnedRUN, amountToBurn);

reduceLiquidationShortfall(amountToBurn);
};

Expand Down
6 changes: 6 additions & 0 deletions packages/run-protocol/test/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ export const vaultManagerMetricsTracker = async (t, publicFacet) => {
assertFullyLiquidated,
});
};
export const reserveInitialState = emptyRun => ({
allocations: {},
shortfallBalance: emptyRun,
burnedRUN: emptyRun,
mintedRUN: emptyRun,
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is valid only for test-reserve.js so please keep it there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hoisted it when the vault test needed it as well. I didn't want the vault test to have to be updated if we add more to the record. I didn't see a better place to put it, and metrics.js is at least under test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, my mistake that it's used only in test-reserve.js.

25 changes: 16 additions & 9 deletions packages/run-protocol/test/reserve/test-reserve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -230,6 +234,14 @@ test('governance add Liquidity to the AMM', async t => {
}),
'should be 80K',
);

await m.assertChange({
mintedRUN: { value: 80_000n },
allocations: {
Rmoola: moola(10_000n),
RmoolaLiquidity: AmountMath.make(moolaLiquidityBrand, 85_622n),
},
});
});

test('request more collateral than available', async t => {
Expand Down Expand Up @@ -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 },
});
Expand Down Expand Up @@ -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 },
});
Expand Down Expand Up @@ -454,6 +460,7 @@ test('reserve burn IST', async t => {
value: runningShortfall,
},
allocations: { RUN: AmountMath.makeEmpty(runBrand) },
burnedRUN: { value: 1000n },
});
});

Expand Down
17 changes: 4 additions & 13 deletions packages/run-protocol/test/vaultFactory/test-vaultFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
metricsTracker,
vaultManagerMetricsTracker,
subscriptionTracker,
reserveInitialState,
} from '../metrics.js';

/** @typedef {Record<string, any> & {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 /////////////////////////////////////
Expand Down