diff --git a/packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js b/packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js index bbc91bd8f20..4c91e143b5f 100644 --- a/packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js +++ b/packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js @@ -84,7 +84,11 @@ export function buildRootObject(vatPowers, vatParameters) { issuerArgs: [undefined, { decimalPlaces: 6 }], mintValue: 7 * 10 ** 6, pursePetname: 'Oracle fee', - tradesGivenCentral: [[1000, 3000000], [1000, 2500000], [1000, 2750000]], + tradesGivenCentral: [ + [1000, 3000000], + [1000, 2500000], + [1000, 2750000], + ], }, ], [ @@ -92,7 +96,13 @@ export function buildRootObject(vatPowers, vatParameters) { { mintValue: 1900, pursePetname: 'Fun budget', - tradesGivenCentral: [[10, 1], [13, 1], [12, 1], [18, 1], [15, 1]], + tradesGivenCentral: [ + [10, 1], + [13, 1], + [12, 1], + [18, 1], + [15, 1], + ], }, ], [ @@ -100,13 +110,19 @@ export function buildRootObject(vatPowers, vatParameters) { { mintValue: 1900, pursePetname: 'Nest egg', - tradesGivenCentral: [[2135, 50], [2172, 50], [2124, 50]], + tradesGivenCentral: [ + [2135, 50], + [2172, 50], + [2124, 50], + ], }, ], ]), ); const issuerNames = [...issuerNameToRecord.keys()]; - const centralIssuerIndex = issuerNames.findIndex(issuerName => issuerName === CENTRAL_ISSUER_NAME); + const centralIssuerIndex = issuerNames.findIndex( + issuerName => issuerName === CENTRAL_ISSUER_NAME, + ); if (centralIssuerIndex < 0) { throw Error(`Cannot find issuer ${CENTRAL_ISSUER_NAME}`); } @@ -120,10 +136,10 @@ export function buildRootObject(vatPowers, vatParameters) { ); const centralIssuer = issuers[centralIssuerIndex]; - + /** - * @param {ERef} issuerIn - * @param {ERef} issuerOut + * @param {ERef} issuerIn + * @param {ERef} issuerOut * @param {Array<[number, number]>} tradeList */ const makeFakePriceAuthority = async (issuerIn, issuerOut, tradeList) => { @@ -138,25 +154,25 @@ export function buildRootObject(vatPowers, vatParameters) { quoteInterval: QUOTE_INTERVAL, }), ]); - return E(priceAuthorityAdmin).registerPriceAuthority(pa, brandIn, brandOut); + return E(priceAuthorityAdmin).registerPriceAuthority( + pa, + brandIn, + brandOut, + ); }; - await Promise.all(issuers.map(async (issuer, i) => { - // Create priceAuthority pairs for centralIssuerIndex based on the - // FakePriceAuthority. - if (issuer === centralIssuer) { - return; - } - console.error(`Creating ${issuerNames[i]}-${issuerNames[centralIssuerIndex]}`); - const { tradesGivenCentral } = issuerNameToRecord.get(issuerNames[i]); - const tradesGivenThis = tradesGivenCentral.map(([a, b]) => [b, a]); - return Promise.all([ - makeFakePriceAuthority(centralIssuer, issuer, tradesGivenCentral), - makeFakePriceAuthority(issuer, centralIssuer, tradesGivenThis), - ]); - })); - - for (const issuerpetname of issuerNameToRecord) - + await Promise.all( + issuers.map(async (issuer, i) => { + // Create priceAuthority pairs for centralIssuerIndex based on the + // FakePriceAuthority. + console.error(`Creating ${issuerNames[i]}-${CENTRAL_ISSUER_NAME}`); + const { tradesGivenCentral } = issuerNameToRecord.get(issuerNames[i]); + const tradesGivenThis = tradesGivenCentral.map(([a, b]) => [b, a]); + return Promise.all([ + makeFakePriceAuthority(centralIssuer, issuer, tradesGivenCentral), + makeFakePriceAuthority(issuer, centralIssuer, tradesGivenThis), + ]); + }), + ); return harden({ async createUserBundle(_nickname, powerFlags = []) { diff --git a/packages/zoe/tools/priceAuthorityRegistry.js b/packages/zoe/tools/priceAuthorityRegistry.js index 4cbffec339c..113f3a019eb 100644 --- a/packages/zoe/tools/priceAuthorityRegistry.js +++ b/packages/zoe/tools/priceAuthorityRegistry.js @@ -13,7 +13,7 @@ import '../exported'; /** * @typedef {Object} PriceAuthorityRegistryAdmin - * @property {(pa: ERef, brandIn: Brand, brandOut: Brand) + * @property {(pa: ERef, brandIn: Brand, brandOut: Brand, force?: boolean) * => Deleter} registerPriceAuthority Add a unique price authority for a given * pair */ @@ -109,7 +109,7 @@ export const makePriceAuthorityRegistry = () => { /** @type {PriceAuthorityRegistryAdmin} */ const adminFacet = { - registerPriceAuthority(pa, brandIn, brandOut) { + registerPriceAuthority(pa, brandIn, brandOut, force = false) { /** @type {Store} */ let priceStore; if (assetToPriceStore.has(brandIn)) { @@ -126,7 +126,11 @@ export const makePriceAuthorityRegistry = () => { }; // Set up the record. - priceStore.init(brandOut, harden(record)); + if (force && priceStore.has(brandOut)) { + priceStore.set(brandOut, harden(record)); + } else { + priceStore.init(brandOut, harden(record)); + } return harden({ delete() {