Skip to content

Commit

Permalink
refactor: workaround bad initial update for vault params
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Mar 29, 2024
1 parent ef96d51 commit 9c83369
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
19 changes: 14 additions & 5 deletions packages/inter-protocol/src/proposals/upgrade-vaults.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { E } from '@endo/far';
import { makeNotifierFromAsyncIterable } from '@agoric/notifier';
import { AmountMath } from '@agoric/ertp/src/index.js';
import { makeScalarMapStore } from '@agoric/store/src/index.js';
import { makeTracer } from '@agoric/internal/src/index.js';

const trace = makeTracer('upgrade Vaults proposal');

// stand-in for Promise.any() which isn't available at this point.
const any = promises =>
Expand Down Expand Up @@ -76,14 +78,20 @@ export const upgradeVaults = async (powers, { options }) => {

const params = {};
for (const kwd of Object.keys(vaultBrands)) {
const b = vaultBrands[kwd];
const collateralBrand = vaultBrands[kwd];
const subscription = E(directorPF).getSubscription({
collateralBrand: b,
collateralBrand,
});
const notifier = makeNotifierFromAsyncIterable(subscription);
const { value } = await notifier.getUpdateSince();
let { value, updateCount } = await notifier.getUpdateSince(0n);
// @ts-expect-error It's an amount.
while (AmountMath.isEmpty(value.current.DebtLimit.value)) {
({ value, updateCount } = await notifier.getUpdateSince(updateCount));
trace(`debtLimit was empty, retried`, value.current.DebtLimit.value);
}
trace(kwd, 'params at', updateCount, 'are', value.current);
params[kwd] = harden({
brand: b,
brand: collateralBrand,
debtLimit: value.current.DebtLimit.value,
interestRate: value.current.InterestRate.value,
liquidationMargin: value.current.LiquidationMargin.value,
Expand Down Expand Up @@ -133,6 +141,7 @@ export const upgradeVaults = async (powers, { options }) => {
),
),
async () => {
trace(`upgrading after delay`);
await upgradeVaultFactory();
auctioneerKitProducer.reset();
auctioneerKitProducer.resolve(auctioneerKit);
Expand Down
14 changes: 7 additions & 7 deletions packages/inter-protocol/src/vaultFactory/params.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @jessie-check

/// <reference path="./types.js" />

import {
Expand All @@ -12,6 +10,7 @@ import { M, makeScalarMapStore } from '@agoric/store';
import { TimeMath } from '@agoric/time';
import { provideDurableMapStore } from '@agoric/vat-data';
import { subtractRatios } from '@agoric/zoe/src/contractSupport/ratio.js';
import { makeTracer } from '@agoric/internal/src/index.js';
import { amountPattern, ratioPattern } from '../contractSupport.js';

export const CHARGING_PERIOD_KEY = 'ChargingPeriod';
Expand All @@ -35,6 +34,8 @@ export const vaultDirectorParamTypes = {
};
harden(vaultDirectorParamTypes);

const trace = makeTracer('Vault Params');

/**
* @param {Amount<'set'>} electorateInvitationAmount
* @param {Amount<'nat'>} minInitialDebt
Expand Down Expand Up @@ -220,18 +221,17 @@ export const provideVaultParamManagers = (
for (const [brand, args] of managerArgs.entries()) {
let values;
for (const key of Object.keys(managerParamValues)) {
// For a couple of runs, changing to managerParamValues[+key] worked,
// but then that stopped working. Dunno why
// eslint-disable-next-line no-restricted-syntax
if (managerParamValues[key].brand === brand) {
values = managerParamValues[+key];
if (managerParamValues[key]?.brand === brand) {
values = managerParamValues[key];
break;
}
}

if (values) {
trace(`reviving params, override`, brand, values);
makeManager(brand, { ...args, initialParamValues: values });
} else {
trace(`reviving params, keeping`, brand, args.initialParamValues);
makeManager(brand, args);
}
}
Expand Down

0 comments on commit 9c83369

Please sign in to comment.