Skip to content

Commit

Permalink
chore: revert to working managerParamValues
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Mar 27, 2024
1 parent 792f66f commit 8354228
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 41 deletions.
65 changes: 30 additions & 35 deletions packages/inter-protocol/src/proposals/upgrade-vaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ import { makeNotifierFromAsyncIterable } from '@agoric/notifier';
import { AmountMath } from '@agoric/ertp/src/index.js';
import { makeScalarMapStore } from '@agoric/store/src/index.js';

Check failure on line 4 in packages/inter-protocol/src/proposals/upgrade-vaults.js

View workflow job for this annotation

GitHub Actions / lint-primary

'makeScalarMapStore' is defined but never used. Allowed unused vars must match /^_/u

// // stand-in for Promise.any which isn't available to this version.
// // Not in use yet, because it seemed to cause a crash (?)
// const any = promises =>
// new Promise((resolve, reject) => {
// for (const promise of promises) {
// promise.then(resolve);
// }
// Promise.allSettled(promises).then(results => {
// const rejects = results.filter(({ status }) => status === 'rejected');
// if (rejects.length === results.length) {
// const messages = rejects.map(({ message }) => message);
// const aggregate = new Error(messages.join(';'));
// aggregate.errors = rejects.map(({ reason }) => reason);
// reject(aggregate);
// }
// });
// });
// stand-in for Promise.any() which isn't available at this point.
const any = promises =>
new Promise((resolve, reject) => {
for (const promise of promises) {
promise.then(resolve);
}
void Promise.allSettled(promises).then(results => {
const rejects = results.filter(({ status }) => status === 'rejected');
if (rejects.length === results.length) {
// @ts-expect-error TypeScript doesn't know enough
const messages = rejects.map(({ message }) => message);
const aggregate = new Error(messages.join(';'));
// @ts-expect-error TypeScript doesn't know enough
aggregate.errors = rejects.map(({ reason }) => reason);
reject(aggregate);
}
});
});

/**
* @param {import('../../src/proposals/econ-behaviors').EconomyBootstrapPowers} powers
Expand Down Expand Up @@ -59,8 +60,7 @@ export const upgradeVaults = async (powers, { options }) => {
installationP,
installation =>
E(E(agoricNamesAdmin).lookupAdmin('installation')).update(
// TODO(cth) fix!
'aultFact',
'vaultFactory',
installation,
),
err =>
Expand All @@ -74,25 +74,23 @@ export const upgradeVaults = async (powers, { options }) => {

await null;

const params = makeScalarMapStore('brand');
const params = {};
for (const kwd of Object.keys(vaultBrands)) {
const b = vaultBrands[kwd];
const subscription = E(directorPF).getSubscription({
collateralBrand: b,
});
const notifier = makeNotifierFromAsyncIterable(subscription);
const { value } = await notifier.getUpdateSince();
params.init(
b,
harden({
debtLimit: value.current.DebtLimit.value,
interestRate: value.current.InterestRate.value,
liquidationMargin: value.current.LiquidationMargin.value,
liquidationPadding: value.current.LiquidationPadding.value,
liquidationPenalty: value.current.LiquidationPenalty.value,
mintFee: value.current.MintFee.value,
}),
);
params[kwd] = harden({
brand: b,
debtLimit: value.current.DebtLimit.value,
interestRate: value.current.InterestRate.value,
liquidationMargin: value.current.LiquidationMargin.value,
liquidationPadding: value.current.LiquidationPadding.value,
liquidationPenalty: value.current.LiquidationPenalty.value,
mintFee: value.current.MintFee.value,
});
}
return params;
};
Expand Down Expand Up @@ -129,10 +127,7 @@ export const upgradeVaults = async (powers, { options }) => {

// Wait for at least one new price feed to be ready before upgrading Vaults
void E.when(
// XXX use any(). We're not expecting failures, but if they happened we'd
// prefer to ignore them. Promise.any() isn't available yet, so we use
// race(), which isn't quite right, but it isn't expected to matter.
Promise.race(
any(
Object.values(vaultBrands).map(brand =>
E(priceAuthority).quoteGiven(AmountMath.make(brand, 10n), istBrand),
),
Expand Down
27 changes: 23 additions & 4 deletions packages/inter-protocol/src/vaultFactory/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ export const makeGovernedTerms = ({
};
harden(makeGovernedTerms);

// XXX Better to declare this as VaultManagerParamValues + brand. How?
/**
* @typedef {object} VaultManagerParams
* @property {Brand} brand
* @property {Ratio} liquidationMargin
* @property {Ratio} liquidationPenalty
* @property {Ratio} interestRate
* @property {Ratio} mintFee
* @property {Amount<'nat'>} debtLimit
* @property {Ratio} [liquidationPadding]
*/

/**
* Stop-gap which restores initial param values UNTIL
* https://github.com/Agoric/agoric-sdk/issues/5200
Expand All @@ -172,8 +184,8 @@ harden(makeGovernedTerms);
*
* @param {import('@agoric/vat-data').Baggage} baggage
* @param {ERef<Marshaller>} marshaller
* @param {MapStore<Brand, VaultManagerParamValues>} managerParamValues - sets
* of parameters keyed by Brand. override stored initial values
* @param {Record<string, VaultManagerParams>} managerParamValues - sets of
* parameters (plus brand:) keyed by Keyword. override stored initial values
*/
export const provideVaultParamManagers = (
baggage,
Expand Down Expand Up @@ -206,8 +218,15 @@ export const provideVaultParamManagers = (

// restore from baggage, unless `managerParamValues` overrides.
for (const [brand, args] of managerArgs.entries()) {
if (managerParamValues.has(brand)) {
const values = managerParamValues.get(brand);
let values;
for (const key of Object.keys(managerParamValues)) {
if (managerParamValues[+key].brand === brand) {
values = managerParamValues[+key];
break;
}
}

if (values) {
makeManager(brand, { ...args, initialParamValues: values });
} else {
makeManager(brand, args);
Expand Down
2 changes: 0 additions & 2 deletions packages/inter-protocol/src/vaultFactory/vaultDirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,10 @@ const prepareVaultDirector = (
const oldInvitation = baggage.has(shortfallInvitationKey)
? baggage.get(shortfallInvitationKey)
: undefined;
console.log('@@@@@ Old Invitation', oldInvitation);

const newInvitation = await directorParamManager.getInternalParamValue(
SHORTFALL_INVITATION_KEY,
);
console.log('@@@@@ New Invitation', newInvitation);

if (newInvitation === oldInvitation) {
shortfallReporter ||
Expand Down
1 change: 1 addition & 0 deletions packages/inter-protocol/src/vaultFactory/vaultFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ harden(meta);
* storageNode: ERef<StorageNode>;
* marshaller: ERef<Marshaller>;
* auctioneerInstance: Instance;
* managerParams: Record<string, import('./params.js').VaultManagerParams>;
* }} privateArgs
* @param {import('@agoric/ertp').Baggage} baggage
*/
Expand Down

0 comments on commit 8354228

Please sign in to comment.