diff --git a/packages/orchestration/src/chain-info.js b/packages/orchestration/src/chain-info.js index fe7352ca004..5629e52633a 100644 --- a/packages/orchestration/src/chain-info.js +++ b/packages/orchestration/src/chain-info.js @@ -19,8 +19,6 @@ export const wellKnownChainInfo = icqEnabled: true, pfmEnabled: true, ibcHooksEnabled: true, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'ustride' }], }, cosmos: { @@ -30,8 +28,6 @@ export const wellKnownChainInfo = icqEnabled: true, pfmEnabled: true, ibcHooksEnabled: true, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'uatom' }], }, celestia: { @@ -41,8 +37,6 @@ export const wellKnownChainInfo = icqEnabled: true, pfmEnabled: true, ibcHooksEnabled: true, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'utia' }], }, osmosis: { @@ -52,8 +46,6 @@ export const wellKnownChainInfo = icqEnabled: true, pfmEnabled: true, ibcHooksEnabled: true, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'uosmo' }], }, }) diff --git a/packages/orchestration/src/cosmos-api.ts b/packages/orchestration/src/cosmos-api.ts index 04cebb79777..5306de19b60 100644 --- a/packages/orchestration/src/cosmos-api.ts +++ b/packages/orchestration/src/cosmos-api.ts @@ -72,11 +72,6 @@ export type CosmosChainInfo = { icqEnabled: boolean; pfmEnabled: boolean; ibcHooksEnabled: boolean; - /** - * - */ - allowedMessages: TypeUrl[]; - allowedQueries: TypeUrl[]; /** * cf https://github.com/cosmos/chain-registry/blob/master/chain.schema.json#L117 diff --git a/packages/orchestration/src/examples/swapExample.contract.js b/packages/orchestration/src/examples/swapExample.contract.js index 8fdb4ac49de..448663f7eb1 100644 --- a/packages/orchestration/src/examples/swapExample.contract.js +++ b/packages/orchestration/src/examples/swapExample.contract.js @@ -15,12 +15,13 @@ import { orcUtils } from '../utils/orc.js'; * @import {Remote} from '@agoric/internal'; * @import {OrchestrationService} from '../service.js'; * @import {Baggage} from '@agoric/vat-data' - * @import {Zone} from '@agoric/zone'; + * @import {NameHub} from '@agoric/vats'; */ /** @type {ContractMeta} */ export const meta = { privateArgsShape: { + agoricNames: M.remotable('agoricNames'), localchain: M.remotable('localchain'), orchestrationService: M.or(M.remotable('orchestration'), null), storageNode: StorageNodeShape, @@ -42,6 +43,7 @@ export const makeNatAmountShape = (brand, min) => /** * @param {ZCF} zcf * @param {{ + * agoricNames: Remote; * localchain: Remote; * orchestrationService: Remote; * storageNode: Remote; @@ -54,16 +56,22 @@ export const start = async (zcf, privateArgs, baggage) => { const zone = makeDurableZone(baggage); - const { localchain, orchestrationService, storageNode, timerService } = - privateArgs; + const { + agoricNames, + localchain, + orchestrationService, + storageNode, + timerService, + } = privateArgs; const { orchestrate } = makeOrchestrationFacade({ - zone, - timerService, - zcf, + agoricNames, localchain, - storageNode, orchestrationService, + storageNode, + timerService, + zcf, + zone, }); /** deprecated historical example */ diff --git a/packages/orchestration/src/examples/unbondExample.contract.js b/packages/orchestration/src/examples/unbondExample.contract.js index 48a2a1979d5..70ae1696114 100644 --- a/packages/orchestration/src/examples/unbondExample.contract.js +++ b/packages/orchestration/src/examples/unbondExample.contract.js @@ -8,6 +8,7 @@ import { makeOrchestrationFacade } from '../facade.js'; * @import {TimerService} from '@agoric/time'; * @import {Baggage} from '@agoric/vat-data'; * @import {LocalChain} from '@agoric/vats/src/localchain.js'; + * @import {NameHub} from '@agoric/vats'; * @import {Remote} from '@agoric/internal'; * @import {OrchestrationService} from '../service.js'; */ @@ -15,6 +16,7 @@ import { makeOrchestrationFacade } from '../facade.js'; /** * @param {ZCF} zcf * @param {{ + * agoricNames: Remote; * localchain: Remote; * orchestrationService: Remote; * storageNode: Remote; @@ -23,17 +25,23 @@ import { makeOrchestrationFacade } from '../facade.js'; * @param {Baggage} baggage */ export const start = async (zcf, privateArgs, baggage) => { - const { localchain, orchestrationService, storageNode, timerService } = - privateArgs; + const { + agoricNames, + localchain, + orchestrationService, + storageNode, + timerService, + } = privateArgs; const zone = makeDurableZone(baggage); const { orchestrate } = makeOrchestrationFacade({ + agoricNames, localchain, - zone, + orchestrationService, + storageNode, timerService, zcf, - storageNode, - orchestrationService, + zone, }); /** @type {OfferHandler} */ diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index b9ea70bfeea..1f73ae93120 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -3,11 +3,11 @@ import { makeScalarBigMapStore } from '@agoric/vat-data'; import { E } from '@endo/far'; import { M } from '@endo/patterns'; -import { wellKnownChainInfo } from './chain-info.js'; import { prepareCosmosOrchestrationAccount } from './exos/cosmosOrchestrationAccount.js'; import { CosmosChainInfoShape } from './typeGuards.js'; /** + * @import {NameHub} from '@agoric/vats'; * @import {Zone} from '@agoric/zone'; * @import {TimerService} from '@agoric/time'; * @import {LocalChain} from '@agoric/vats/src/localchain.js'; @@ -19,12 +19,14 @@ import { CosmosChainInfoShape } from './typeGuards.js'; /** @type {any} */ const anyVal = null; +// TODO define key hierarchy in shared constants +/** agoricNames key for ChainInfo hub */ +export const CHAIN_KEY = 'chain'; + // FIXME look up real values // UNTIL https://github.com/Agoric/agoric-sdk/issues/9063 const mockLocalChainInfo = { allegedName: 'agoric', - allowedMessages: [], - allowedQueries: [], chainId: 'agoriclocal', connections: anyVal, ibcHooksEnabled: true, @@ -155,6 +157,7 @@ const makeRemoteChainFacade = ( * storageNode: Remote; * orchestrationService: Remote; * localchain: Remote; + * agoricNames: Remote; * }} powers */ export const makeOrchestrationFacade = ({ @@ -164,6 +167,7 @@ export const makeOrchestrationFacade = ({ storageNode, orchestrationService, localchain, + agoricNames, }) => { console.log('makeOrchestrationFacade got', { zone, @@ -178,6 +182,22 @@ export const makeOrchestrationFacade = ({ valueShape: CosmosChainInfoShape, }); + /** + * @param {string} name + * @returns {Promise} + */ + const getChainInfo = async name => { + // Either from registerChain or memoized remote lookup() + if (chainInfos.has(name)) { + return chainInfos.get(name); + } + + const chainInfo = await E(agoricNames).lookup(CHAIN_KEY, name); + assert(chainInfo, `unknown chain ${name}`); + chainInfos.init(name, chainInfo); + return chainInfo; + }; + return { /** * Register a new chain in a heap store. The name will override a name in @@ -211,12 +231,7 @@ export const makeOrchestrationFacade = ({ return makeLocalChainFacade(localchain); } - // TODO look up well known realistically https://github.com/Agoric/agoric-sdk/issues/9063 - const chainInfo = chainInfos.has(name) - ? chainInfos.get(name) - : // @ts-expect-error may be undefined - wellKnownChainInfo[name]; - assert(chainInfo, `unknown chain ${name}`); + const chainInfo = await getChainInfo(name); return makeRemoteChainFacade(chainInfo, { orchestration: orchestrationService, diff --git a/packages/orchestration/src/typeGuards.js b/packages/orchestration/src/typeGuards.js index 9ba142f57ec..c67b08fba39 100644 --- a/packages/orchestration/src/typeGuards.js +++ b/packages/orchestration/src/typeGuards.js @@ -53,7 +53,5 @@ export const CosmosChainInfoShape = M.splitRecord( icqEnabled: M.boolean(), pfmEnabled: M.boolean(), ibcHooksEnabled: M.boolean(), - allowedMessages: M.arrayOf(M.string()), - allowedQueries: M.arrayOf(M.string()), }, ); diff --git a/packages/orchestration/src/utils/mockChainInfo.js b/packages/orchestration/src/utils/mockChainInfo.js index d7fb12cea0e..42cfcca688f 100644 --- a/packages/orchestration/src/utils/mockChainInfo.js +++ b/packages/orchestration/src/utils/mockChainInfo.js @@ -1,5 +1,10 @@ /** - * @file Mocked Chain Info object until #8879 + * @file Mocked Chain Info object + * + * Until https://github.com/Agoric/agoric-sdk/issues/8879 + * + * Generated using + * https://github.com/Agoric/agoric-sdk/compare/pc/ibc-chain-info */ import { Order, @@ -67,9 +72,7 @@ const connectionEntries = harden({ }, }); -/** - * @returns {Pick} - */ +/** @returns {Pick} */ export const prepareMockChainInfo = () => { return harden({ chainId: 'agoriclocal', diff --git a/packages/orchestration/test/examples/swapExample.test.ts b/packages/orchestration/test/examples/swapExample.test.ts index ca1a8852fe5..c10c4b2a994 100644 --- a/packages/orchestration/test/examples/swapExample.test.ts +++ b/packages/orchestration/test/examples/swapExample.test.ts @@ -16,6 +16,7 @@ test('start', async t => { const { bootstrap, brands: { ist }, + commonPrivateArgs, utils, } = await commonSetup(t); @@ -27,12 +28,7 @@ test('start', async t => { installation, { Stable: ist.issuer }, {}, - { - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, - storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, - }, + commonPrivateArgs, ); const inv = E(publicFacet).makeSwapAndStakeInvitation(); diff --git a/packages/orchestration/test/examples/unbondExample.test.ts b/packages/orchestration/test/examples/unbondExample.test.ts index b78e606fdf0..7b23042977a 100644 --- a/packages/orchestration/test/examples/unbondExample.test.ts +++ b/packages/orchestration/test/examples/unbondExample.test.ts @@ -13,8 +13,8 @@ type StartFn = test('start', async t => { const { - bootstrap, brands: { ist }, + commonPrivateArgs, } = await commonSetup(t); const { zoe, bundleAndInstall } = await setUpZoeForTest(); @@ -25,12 +25,7 @@ test('start', async t => { installation, { Stable: ist.issuer }, {}, - { - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, - storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, - }, + commonPrivateArgs, ); const inv = E(publicFacet).makeUnbondAndLiquidStakeInvitation(); diff --git a/packages/orchestration/test/facade.test.ts b/packages/orchestration/test/facade.test.ts index 10fdfa1c162..0057a932502 100644 --- a/packages/orchestration/test/facade.test.ts +++ b/packages/orchestration/test/facade.test.ts @@ -15,23 +15,19 @@ export const mockChainInfo: CosmosChainInfo = harden({ icqEnabled: false, pfmEnabled: false, ibcHooksEnabled: false, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'umock' }], }); test('chain info', async t => { - const { bootstrap } = await commonSetup(t); + const { bootstrap, facadeServices } = await commonSetup(t); const zone = bootstrap.rootZone; const { zcf } = await setupZCFTest(); const { registerChain, orchestrate } = makeOrchestrationFacade({ - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, + ...facadeServices, storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, zcf, zone, }); @@ -47,7 +43,7 @@ test('chain info', async t => { }); test('contract upgrade', async t => { - const { bootstrap } = await commonSetup(t); + const { bootstrap, facadeServices } = await commonSetup(t); const zone = bootstrap.rootZone; @@ -56,10 +52,8 @@ test('contract upgrade', async t => { // Register once { const { registerChain } = makeOrchestrationFacade({ - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, + ...facadeServices, storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, zcf, zone, }); @@ -74,10 +68,8 @@ test('contract upgrade', async t => { // Simulate running again in a new incarnation with the same zone { const { registerChain } = makeOrchestrationFacade({ - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, + ...facadeServices, storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, zcf, zone, }); diff --git a/packages/orchestration/test/supports.ts b/packages/orchestration/test/supports.ts index d13338b260b..b87f4678bb7 100644 --- a/packages/orchestration/test/supports.ts +++ b/packages/orchestration/test/supports.ts @@ -9,8 +9,13 @@ import { buildZoeManualTimer } from '@agoric/zoe/tools/manualTimer.js'; import { withAmountUtils } from '@agoric/zoe/tools/test-utils.js'; import { makeHeapZone } from '@agoric/zone'; import { E } from '@endo/far'; +import { makeNameHubKit } from '@agoric/vats'; +import { makeWellKnownSpaces } from '@agoric/vats/src/core/utils.js'; import { fakeNetworkEchoStuff } from './network-fakes.js'; import { prepareOrchestrationTools } from '../src/service.js'; +import { CHAIN_KEY } from '../src/facade.js'; +import type { CosmosChainInfo } from '../src/cosmos-api.js'; +import { wellKnownChainInfo } from '../src/chain-info.js'; export { makeFakeLocalchainBridge } from '@agoric/vats/tools/fake-bridge.js'; @@ -53,8 +58,21 @@ export const commonSetup = async t => { const { portAllocator } = fakeNetworkEchoStuff(rootZone.subZone('network')); const { public: orchestration } = makeOrchestrationKit({ portAllocator }); + const { nameHub: agoricNames, nameAdmin: agoricNamesAdmin } = + makeNameHubKit(); + const spaces = await makeWellKnownSpaces(agoricNamesAdmin, t.log, [ + CHAIN_KEY, + ]); + + // Simulate what BLD stakers would have configured + for (const [name, info] of Object.entries(wellKnownChainInfo)) { + // @ts-expect-error FIXME types + spaces.chain.produce[name].resolve(info); + } + return { bootstrap: { + agoricNames, bankManager, timer, localchain, @@ -68,6 +86,19 @@ export const commonSetup = async t => { bld, ist, }, + commonPrivateArgs: { + agoricNames, + localchain, + orchestrationService: orchestration, + storageNode: storage.rootNode, + timerService: timer, + }, + facadeServices: { + agoricNames, + localchain, + orchestrationService: orchestration, + timerService: timer, + }, utils: { pourPayment, },