From 97d8b1432c8f2dd3e9071913ea6722eddfa2596f Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 12 Dec 2023 10:51:36 -0800 Subject: [PATCH 1/2] chore(types): storageHelper params --- packages/SwingSet/src/kernel/state/storageHelper.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/SwingSet/src/kernel/state/storageHelper.js b/packages/SwingSet/src/kernel/state/storageHelper.js index 835153c785e..86b2b0d4dfa 100644 --- a/packages/SwingSet/src/kernel/state/storageHelper.js +++ b/packages/SwingSet/src/kernel/state/storageHelper.js @@ -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) { @@ -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 From a92cf556a0c806df293027458883f2a81a2bfade Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 8 Jan 2024 09:29:36 -0800 Subject: [PATCH 2/2] refactor: mv priceAuthorityRegistry to vats Somewhat of a breaking change but it's moving from tools which is not part of the package API --- .../boot/test/upgrading/test-upgrade-vats.js | 2 +- .../test/auction/test-auctionContract.js | 2 +- .../test/vaultFactory/driver.js | 2 +- .../test-replacePriceAuthority.js | 2 +- .../test/vaultFactory/vaultFactoryUtils.js | 2 +- packages/vats/src/core/types-ambient.d.ts | 2 +- .../src}/priceAuthorityRegistry.js | 42 +++++++++++-------- packages/vats/src/vat-priceAuthority.js | 2 +- .../test}/test-priceAuthorityRegistry.js | 9 ++-- 9 files changed, 36 insertions(+), 29 deletions(-) rename packages/{zoe/tools => vats/src}/priceAuthorityRegistry.js (87%) rename packages/{zoe/test/unitTests/tools => vats/test}/test-priceAuthorityRegistry.js (88%) diff --git a/packages/boot/test/upgrading/test-upgrade-vats.js b/packages/boot/test/upgrading/test-upgrade-vats.js index 3f6838b5f8c..df80d8996c0 100644 --- a/packages/boot/test/upgrading/test-upgrade-vats.js +++ b/packages/boot/test/upgrading/test-upgrade-vats.js @@ -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. diff --git a/packages/inter-protocol/test/auction/test-auctionContract.js b/packages/inter-protocol/test/auction/test-auctionContract.js index 08c74be5eb1..912f803a132 100644 --- a/packages/inter-protocol/test/auction/test-auctionContract.js +++ b/packages/inter-protocol/test/auction/test-auctionContract.js @@ -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'; diff --git a/packages/inter-protocol/test/vaultFactory/driver.js b/packages/inter-protocol/test/vaultFactory/driver.js index 89485787db7..e3a84aee0b6 100644 --- a/packages/inter-protocol/test/vaultFactory/driver.js +++ b/packages/inter-protocol/test/vaultFactory/driver.js @@ -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 { diff --git a/packages/inter-protocol/test/vaultFactory/test-replacePriceAuthority.js b/packages/inter-protocol/test/vaultFactory/test-replacePriceAuthority.js index bd731ec655b..66e212477c7 100644 --- a/packages/inter-protocol/test/vaultFactory/test-replacePriceAuthority.js +++ b/packages/inter-protocol/test/vaultFactory/test-replacePriceAuthority.js @@ -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'; diff --git a/packages/inter-protocol/test/vaultFactory/vaultFactoryUtils.js b/packages/inter-protocol/test/vaultFactory/vaultFactoryUtils.js index c3ef7e5de69..3ab679218b4 100644 --- a/packages/inter-protocol/test/vaultFactory/vaultFactoryUtils.js +++ b/packages/inter-protocol/test/vaultFactory/vaultFactoryUtils.js @@ -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'; diff --git a/packages/vats/src/core/types-ambient.d.ts b/packages/vats/src/core/types-ambient.d.ts index 309c820c7bd..dad4d4d9b3b 100644 --- a/packages/vats/src/core/types-ambient.d.ts +++ b/packages/vats/src/core/types-ambient.d.ts @@ -348,7 +348,7 @@ type ChainBootstrapSpaceT = { pegasusConnectionsAdmin: import('@agoric/vats').NameAdmin; priceAuthorityVat: Awaited; priceAuthority: PriceAuthority; - priceAuthorityAdmin: import('@agoric/zoe/tools/priceAuthorityRegistry').PriceAuthorityRegistryAdmin; + priceAuthorityAdmin: import('@agoric/vats/src/priceAuthorityRegistry').PriceAuthorityRegistryAdmin; provisioning: Awaited | undefined; provisionBridgeManager: import('../types.js').ScopedBridgeManager | undefined; provisionWalletBridgeManager: diff --git a/packages/zoe/tools/priceAuthorityRegistry.js b/packages/vats/src/priceAuthorityRegistry.js similarity index 87% rename from packages/zoe/tools/priceAuthorityRegistry.js rename to packages/vats/src/priceAuthorityRegistry.js index cb7473c7bb6..85b8570f73d 100644 --- a/packages/zoe/tools/priceAuthorityRegistry.js +++ b/packages/vats/src/priceAuthorityRegistry.js @@ -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; @@ -19,17 +19,19 @@ const { Fail } = assert; /** * @typedef {object} PriceAuthorityRegistryAdmin - * @property {(pa: ERef, - * brandIn: Brand, - * brandOut: Brand, - * force?: boolean) => Promise} registerPriceAuthority - * Add a unique price authority for a given pair + * @property {( + * pa: ERef, + * brandIn: Brand, + * brandOut: Brand, + * force?: boolean, + * ) => Promise} 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 */ @@ -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 the sub-authority for a - * given input and output brand pair + * given input and output brand pair */ /** @type {MapStore>} */ @@ -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} resolve with a quote when `amountOut - * relation amountOutLimit` is true + * relation amountOutLimit` is true */ async (amountIn, amountOutLimit) => { const pa = paFor(amountIn.brand, amountOutLimit.brand); @@ -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} resolve with a quote when `amountOut - * relation amountOutLimit` is true + * relation amountOutLimit` is true */ async (amountIn, amountOutLimit) => { const pa = paFor(amountIn.brand, amountOutLimit.brand); diff --git a/packages/vats/src/vat-priceAuthority.js b/packages/vats/src/vat-priceAuthority.js index 5e2b4168b31..86cc49eb790 100644 --- a/packages/vats/src/vat-priceAuthority.js +++ b/packages/vats/src/vat-priceAuthority.js @@ -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 diff --git a/packages/zoe/test/unitTests/tools/test-priceAuthorityRegistry.js b/packages/vats/test/test-priceAuthorityRegistry.js similarity index 88% rename from packages/zoe/test/unitTests/tools/test-priceAuthorityRegistry.js rename to packages/vats/test/test-priceAuthorityRegistry.js index 50d5439504f..dd27478c865 100644 --- a/packages/zoe/test/unitTests/tools/test-priceAuthorityRegistry.js +++ b/packages/vats/test/test-priceAuthorityRegistry.js @@ -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');