Skip to content

Commit

Permalink
test: add priceAuthority to many vaults tests the right way
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Dec 28, 2023
1 parent b767831 commit d419cc7
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 89 deletions.
48 changes: 42 additions & 6 deletions packages/inter-protocol/test/vaultFactory/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { makeNotifierFromSubscriber } from '@agoric/notifier';
import { unsafeMakeBundleCache } from '@agoric/swingset-vat/tools/bundleTool.js';
import {
ceilMultiplyBy,
makeRatio,
makeRatioFromAmounts,
} from '@agoric/zoe/src/contractSupport/index.js';
import { makeManualPriceAuthority } from '@agoric/zoe/tools/manualPriceAuthority.js';
Expand All @@ -15,6 +16,9 @@ import { deeplyFulfilled } from '@endo/marshal';

import { NonNullish } from '@agoric/assert';
import { eventLoopIteration } from '@agoric/notifier/tools/testSupports.js';
import { providePriceAuthorityRegistry } from '@agoric/zoe/tools/priceAuthorityRegistry.js';
import { makeScalarBigMapStore } from '@agoric/vat-data/src/index.js';

import {
setupReserve,
startAuctioneer,
Expand Down Expand Up @@ -215,15 +219,27 @@ const setupServices = async (t, initialPrice, priceBase) => {
const { consume, produce } = space;
t.context.consume = consume;

// Cheesy hack for easy use of manual price authority
const priceAuthority = makeManualPriceAuthority({
// priceAuthorityReg is the registry, which contains and multiplexes multiple
// individual priceAuthorities, including aethPriceAuthority.
// priceAuthorityAdmin supports registering more individual priceAuthorities
// with the registry.
const aethPriceAuthority = makeManualPriceAuthority({
actualBrandIn: aeth.brand,
actualBrandOut: run.brand,
initialPrice: makeRatioFromAmounts(initialPrice, priceBase),
timer,
quoteIssuerKit: makeIssuerKit('quote', AssetKind.SET),
});
produce.priceAuthority.resolve(priceAuthority);
const baggage = makeScalarBigMapStore('baggage');
const { priceAuthority: priceAuthorityReg, adminFacet: priceAuthorityAdmin } =
providePriceAuthorityRegistry(baggage);
await E(priceAuthorityAdmin).registerPriceAuthority(
aethPriceAuthority,
aeth.brand,
run.brand,
);

produce.priceAuthority.resolve(priceAuthorityReg);

const {
installation: { produce: iProduce },
Expand Down Expand Up @@ -276,6 +292,7 @@ const setupServices = async (t, initialPrice, priceBase) => {

return {
zoe,
timer,
governor: {
governorInstance,
governorPublicFacet: E(zoe).getPublicFacet(governorInstance),
Expand All @@ -288,7 +305,9 @@ const setupServices = async (t, initialPrice, priceBase) => {
vfPublic,
aethVaultManager,
},
priceAuthority,
priceAuthority: priceAuthorityReg,
priceAuthorityAdmin,
aethPriceAuthority,
};
};

Expand All @@ -307,7 +326,7 @@ export const makeManagerDriver = async (
const { zoe, aeth, run } = t.context;
const {
vaultFactory: { lender, vaultFactory, vfPublic },
priceAuthority,
aethPriceAuthority,
timer,
} = services;
const publicTopics = await E(lender).getPublicTopics();
Expand Down Expand Up @@ -450,6 +469,22 @@ export const makeManagerDriver = async (
addVaultType: async keyword => {
/** @type {IssuerKit<'nat'>} */
const kit = makeIssuerKit(keyword.toLowerCase());

// for now, this priceAuthority never reports prices, but having one is
// sufficient to get a vaultManager running.
const pa = makeManualPriceAuthority({
actualBrandIn: kit.brand,
actualBrandOut: run.brand,
timer,
initialPrice: makeRatio(100n, run.brand, 100n, kit.brand),
});

await services.priceAuthorityAdmin.registerPriceAuthority(
pa,
kit.brand,
run.brand,
);

const manager = await E(vaultFactory).addVaultType(
kit.issuer,
keyword,
Expand Down Expand Up @@ -477,7 +512,8 @@ export const makeManagerDriver = async (
});
},
/** @param {Amount<'nat'>} p */
setPrice: p => priceAuthority.setPrice(makeRatioFromAmounts(p, priceBase)),
setPrice: p =>
aethPriceAuthority.setPrice(makeRatioFromAmounts(p, priceBase)),
// XXX the paramPath should be implied by the object `setGovernedParam` is being called on.
// e.g. the manager driver should know the paramPath is `{ key: { collateralBrand: aeth.brand } }`
// and the director driver should `{ key: 'governedParams }`
Expand Down
77 changes: 42 additions & 35 deletions packages/inter-protocol/test/vaultFactory/test-vaultFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { makeManualPriceAuthority } from '@agoric/zoe/tools/manualPriceAuthority

import { documentStorageSchema } from '@agoric/governance/tools/storageDoc.js';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { makeScriptedPriceAuthority } from '@agoric/zoe/tools/scriptedPriceAuthority.js';
import { E } from '@endo/eventual-send';
import { deeplyFulfilled } from '@endo/marshal';
import { calculateCurrentDebt } from '../../src/interest-math.js';
Expand Down Expand Up @@ -156,44 +155,25 @@ const setupServices = async (
const runPayment = await getRunFromFaucet(t, stableInitialLiquidity);
trace(t, 'faucet', { stableInitialLiquidity, runPayment });

const { space } = await setupElectorateReserveAndAuction(
t,
// @ts-expect-error inconsistent types with withAmountUtils
run,
aeth,
priceOrList,
quoteInterval,
unitAmountIn,
{ StartFrequency: startFrequency },
);

const { consume, produce } = space;

const quoteIssuerKit = makeIssuerKit('quote', AssetKind.SET);
// Cheesy hack for easy use of manual price authority
const pa = Array.isArray(priceOrList)
? makeScriptedPriceAuthority({
actualBrandIn: aeth.brand,
actualBrandOut: run.brand,
priceList: priceOrList,
timer,
quoteMint: quoteIssuerKit.mint,
unitAmountIn,
quoteInterval,
})
: makeManualPriceAuthority({
actualBrandIn: aeth.brand,
actualBrandOut: run.brand,
initialPrice: priceOrList,
timer,
quoteIssuerKit,
});
produce.priceAuthority.resolve(pa);
const { space, priceAuthorityAdmin, aethPriceAuthority } =
await setupElectorateReserveAndAuction(
t,
// @ts-expect-error inconsistent types with withAmountUtils
run,
aeth,
priceOrList,
quoteInterval,
unitAmountIn,
{ StartFrequency: startFrequency },
);

const { consume } = space;

const {
installation: { produce: iProduce },
} = space;
iProduce.VaultFactory.resolve(t.context.installation.VaultFactory);

iProduce.liquidate.resolve(t.context.installation.liquidate);
await startVaultFactory(
space,
Expand Down Expand Up @@ -267,15 +247,38 @@ const setupServices = async (

return {
zoe,
timer,
governor: g,
vaultFactory: v,
runKit: { issuer: run.issuer, brand: run.brand },
priceAuthority,
reserveKit,
space,
priceAuthorityAdmin,
aethPriceAuthority,
};
};

const addPriceAuthority = async (collateralIssuerKit, services) => {
const { priceAuthorityAdmin, timer, runKit } = services;

const pa = makeManualPriceAuthority({
actualBrandIn: collateralIssuerKit.brand,
actualBrandOut: runKit.brand,
timer,
initialPrice: makeRatio(
100n,
runKit.brand,
100n,
collateralIssuerKit.brand,
),
});
await E(priceAuthorityAdmin).registerPriceAuthority(
pa,
collateralIssuerKit.brand,
runKit.brand,
);
};

test('first', async t => {
const { aeth, run, zoe, rates } = t.context;
t.context.interestTiming = {
Expand Down Expand Up @@ -1574,6 +1577,7 @@ test('addVaultType: invalid args do not modify state', async t => {
);

const { vaultFactory } = services.vaultFactory;
await addPriceAuthority(chit, services);

const failsForSameReason = async p =>
p
Expand Down Expand Up @@ -1607,6 +1611,7 @@ test('addVaultType: extra, unexpected params', async t => {
);

const { vaultFactory } = services.vaultFactory;
await addPriceAuthority(chit, services);

const params = { ...defaultParamValues(aeth.brand), shoeSize: 10 };
const extraParams = { ...params, shoeSize: 10 };
Expand Down Expand Up @@ -1654,6 +1659,8 @@ test('director notifiers', async t => {

// add a vault type
const chit = makeIssuerKit('chit');
await addPriceAuthority(chit, services);

await E(vaultFactory).addVaultType(
chit.issuer,
'Chit',
Expand Down
Loading

0 comments on commit d419cc7

Please sign in to comment.