Skip to content

Commit

Permalink
Merge pull request #8717 from Agoric/ta/move-priceAuthorityRegistry
Browse files Browse the repository at this point in the history
move priceAuthorityRegistry with its vat
  • Loading branch information
mergify[bot] authored Jan 11, 2024
2 parents ba2f0d9 + a92cf55 commit 53ec11c
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 30 deletions.
13 changes: 12 additions & 1 deletion packages/SwingSet/src/kernel/state/storageHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export function* enumeratePrefixedKeys(kvStore, prefix, exclusiveEnd) {
}
}

// NOTE: awkward naming: the thing that returns a stream of keys is named
/**
* @param {KVStore} kvStore
* @param {string} prefix
*/ // NOTE: awkward naming: the thing that returns a stream of keys is named
// "enumerate..." while the thing that returns a stream of values is named
// "get..."
function* enumerateNumericPrefixedKeys(kvStore, prefix) {
Expand All @@ -43,12 +46,20 @@ function* enumerateNumericPrefixedKeys(kvStore, prefix) {
}
}

/**
* @param {KVStore} kvStore
* @param {string} prefix
*/
export function* getPrefixedValues(kvStore, prefix) {
for (const key of enumerateNumericPrefixedKeys(kvStore, prefix)) {
yield kvStore.get(key) || Fail`enumerate ensures get`;
}
}

/**
* @param {KVStore} kvStore
* @param {string} prefix
*/
export function deletePrefixedKeys(kvStore, prefix) {
// this is kind of like a deleteRange() would be, but can be implemented
// efficiently without backend DB support because it only looks at numeric
Expand Down
2 changes: 1 addition & 1 deletion packages/boot/test/upgrading/test-upgrade-vats.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ test('upgrade vat-priceAuthority', async t => {
priceAuthorityVatConfig,
);

/** @type {import('@agoric/zoe/tools/priceAuthorityRegistry.js').PriceAuthorityRegistry} */
/** @type {import('@agoric/vats/src/priceAuthorityRegistry.js').PriceAuthorityRegistry} */
const registry = await EV(priceAuthorityRoot).getRegistry();

// Ideally we'd also test registering a PA and verifying the same one comes out the def end.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@agoric/zoe/src/contractSupport/index.js';
import { assertPayoutAmount } from '@agoric/zoe/test/zoeTestHelpers.js';
import { makeManualPriceAuthority } from '@agoric/zoe/tools/manualPriceAuthority.js';
import { providePriceAuthorityRegistry } from '@agoric/zoe/tools/priceAuthorityRegistry.js';
import { providePriceAuthorityRegistry } from '@agoric/vats/src/priceAuthorityRegistry.js';
import { E } from '@endo/eventual-send';
import { NonNullish } from '@agoric/assert';

Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/test/vaultFactory/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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 { providePriceAuthorityRegistry } from '@agoric/vats/src/priceAuthorityRegistry.js';
import { makeScalarBigMapStore } from '@agoric/vat-data/src/index.js';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { buildManualTimer } from '@agoric/swingset-vat/tools/manual-timer.js';
import { E } from '@endo/eventual-send';
import { deeplyFulfilled } from '@endo/marshal';
import { TimeMath } from '@agoric/time';
import { providePriceAuthorityRegistry } from '@agoric/zoe/tools/priceAuthorityRegistry.js';
import { providePriceAuthorityRegistry } from '@agoric/vats/src/priceAuthorityRegistry.js';
import { makeScalarMapStore } from '@agoric/vat-data/src/index.js';
import { makeManualPriceAuthority } from '@agoric/zoe/tools/manualPriceAuthority.js';
import { makeNotifierFromAsyncIterable, subscribeEach } from '@agoric/notifier';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { makeNotifierFromSubscriber } from '@agoric/notifier';
import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js';
import { makeManualPriceAuthority } from '@agoric/zoe/tools/manualPriceAuthority.js';
import { makeScalarBigMapStore } from '@agoric/vat-data/src/index.js';
import { providePriceAuthorityRegistry } from '@agoric/zoe/tools/priceAuthorityRegistry.js';
import { providePriceAuthorityRegistry } from '@agoric/vats/src/priceAuthorityRegistry.js';

import { makeScriptedPriceAuthority } from '@agoric/zoe/tools/scriptedPriceAuthority.js';
import { E } from '@endo/eventual-send';
Expand Down
2 changes: 1 addition & 1 deletion packages/vats/src/core/types-ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ type ChainBootstrapSpaceT = {
pegasusConnectionsAdmin: import('@agoric/vats').NameAdmin;
priceAuthorityVat: Awaited<PriceAuthorityVat>;
priceAuthority: PriceAuthority;
priceAuthorityAdmin: import('@agoric/zoe/tools/priceAuthorityRegistry').PriceAuthorityRegistryAdmin;
priceAuthorityAdmin: import('@agoric/vats/src/priceAuthorityRegistry').PriceAuthorityRegistryAdmin;
provisioning: Awaited<ProvisioningVat> | undefined;
provisionBridgeManager: import('../types.js').ScopedBridgeManager | undefined;
provisionWalletBridgeManager:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
provideDurableMapStore,
} from '@agoric/vat-data';
import { provideLazy } from '@agoric/store';
import { E } from '@endo/eventual-send';
import { E } from '@endo/far';
import { Far } from '@endo/marshal';
import { PriceAuthorityI } from '../src/contractSupport/priceAuthority.js';
import { PriceAuthorityI } from '@agoric/zoe/src/contractSupport/priceAuthority.js';

const { Fail } = assert;

Expand All @@ -19,17 +19,19 @@ const { Fail } = assert;

/**
* @typedef {object} PriceAuthorityRegistryAdmin
* @property {(pa: ERef<PriceAuthority>,
* brandIn: Brand,
* brandOut: Brand,
* force?: boolean) => Promise<Deleter>} registerPriceAuthority
* Add a unique price authority for a given pair
* @property {(
* pa: ERef<PriceAuthority>,
* brandIn: Brand,
* brandOut: Brand,
* force?: boolean,
* ) => Promise<Deleter>} registerPriceAuthority
* Add a unique price authority for a given pair
*/

/**
* @typedef {object} PriceAuthorityRegistry A price authority that is a facade
* for other backing price authorities registered for a given asset and price
* brand
* for other backing price authorities registered for a given asset and price
* brand
* @property {PriceAuthority} priceAuthority
* @property {PriceAuthorityRegistryAdmin} adminFacet
*/
Expand All @@ -43,10 +45,10 @@ const { Fail } = assert;
export const providePriceAuthorityRegistry = baggage => {
/**
* @typedef {object} PriceAuthorityRecord A record indicating a registered
* price authority. We put a box around the priceAuthority to ensure the
* deleter doesn't delete the wrong thing.
* price authority. We put a box around the priceAuthority to ensure the
* deleter doesn't delete the wrong thing.
* @property {ERef<PriceAuthority>} priceAuthority the sub-authority for a
* given input and output brand pair
* given input and output brand pair
*/

/** @type {MapStore<Brand, MapStore<Brand, PriceAuthorityRecord>>} */
Expand Down Expand Up @@ -74,10 +76,12 @@ export const providePriceAuthorityRegistry = baggage => {
/**
* Return a quote when relation is true of the arguments.
*
* @param {Amount<'nat'>} amountIn monitor the amountOut corresponding to this amountIn
* @param {Amount<'nat'>} amountOutLimit the value to compare with the monitored amountOut
* @param {Amount<'nat'>} amountIn monitor the amountOut corresponding to
* this amountIn
* @param {Amount<'nat'>} amountOutLimit the value to compare with the
* monitored amountOut
* @returns {Promise<PriceQuote>} resolve with a quote when `amountOut
* relation amountOutLimit` is true
* relation amountOutLimit` is true
*/
async (amountIn, amountOutLimit) => {
const pa = paFor(amountIn.brand, amountOutLimit.brand);
Expand All @@ -94,10 +98,12 @@ export const providePriceAuthorityRegistry = baggage => {
/**
* Return a mutable quote when relation is true of the arguments.
*
* @param {Amount} amountIn monitor the amountOut corresponding to this amountIn
* @param {Amount} amountOutLimit the value to compare with the monitored amountOut
* @param {Amount} amountIn monitor the amountOut corresponding to this
* amountIn
* @param {Amount} amountOutLimit the value to compare with the monitored
* amountOut
* @returns {Promise<MutableQuote>} resolve with a quote when `amountOut
* relation amountOutLimit` is true
* relation amountOutLimit` is true
*/
async (amountIn, amountOutLimit) => {
const pa = paFor(amountIn.brand, amountOutLimit.brand);
Expand Down
2 changes: 1 addition & 1 deletion packages/vats/src/vat-priceAuthority.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { providePriceAuthorityRegistry } from '@agoric/zoe/tools/priceAuthorityRegistry.js';
import { Far } from '@endo/marshal';
import { providePriceAuthorityRegistry } from './priceAuthorityRegistry.js';

/**
* Vat holding the canonical PriceAuthorityRegistry for looking up prices on any
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js';
import { makeScalarBigMapStore } from '@agoric/vat-data';

import { AmountMath, makeIssuerKit } from '@agoric/ertp';
import { buildManualTimer } from '@agoric/swingset-vat/tools/manual-timer.js';
import { E } from '@endo/eventual-send';
import { providePriceAuthorityRegistry } from '../../../tools/priceAuthorityRegistry.js';
import { makeFakePriceAuthority } from '../../../tools/fakePriceAuthority.js';
import { makeScalarBigMapStore } from '@agoric/vat-data';
import { makeFakePriceAuthority } from '@agoric/zoe/tools/fakePriceAuthority.js';
import { E } from '@endo/far';
import { providePriceAuthorityRegistry } from '../src/priceAuthorityRegistry.js';

test('price authority confused stores', async t => {
const baggage = makeScalarBigMapStore('test baggage');
Expand Down

0 comments on commit 53ec11c

Please sign in to comment.