From f5cf85bdc7c414f411d1cd0afac120645239e438 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 8 Jul 2024 15:48:37 -0700 Subject: [PATCH 01/11] refactor: CosmosInterchainService --- .../bootstrapTests/vat-orchestration.test.ts | 10 ++--- packages/orchestration/index.js | 2 +- .../src/examples/sendAnywhere.contract.js | 4 +- .../src/examples/stakeIca.contract.js | 4 +- .../src/examples/swapExample.contract.js | 4 +- .../src/examples/unbondExample.contract.js | 4 +- .../cosmos-interchain-service.js} | 39 ++++++++++--------- .../src/exos/local-chain-facade.js | 4 +- .../orchestration/src/exos/orchestrator.js | 4 +- .../src/exos/remote-chain-facade.js | 4 +- packages/orchestration/src/facade.js | 4 +- .../src/proposals/orchestration-proposal.js | 4 +- packages/orchestration/src/types.ts | 2 +- .../orchestration/src/utils/start-helper.js | 4 +- .../orchestration/src/vat-orchestration.js | 12 +++--- packages/orchestration/test/supports.ts | 6 +-- packages/vats/src/core/types-ambient.d.ts | 2 +- 17 files changed, 58 insertions(+), 55 deletions(-) rename packages/orchestration/src/{service.js => exos/cosmos-interchain-service.js} (90%) diff --git a/packages/boot/test/bootstrapTests/vat-orchestration.test.ts b/packages/boot/test/bootstrapTests/vat-orchestration.test.ts index fed0336a3c9..da8ba3187a3 100644 --- a/packages/boot/test/bootstrapTests/vat-orchestration.test.ts +++ b/packages/boot/test/bootstrapTests/vat-orchestration.test.ts @@ -11,7 +11,7 @@ import { MsgDelegate, MsgDelegateResponse, } from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js'; -import type { OrchestrationService } from '@agoric/orchestration'; +import type { CosmosInterchainService } from '@agoric/orchestration'; import { decodeBase64 } from '@endo/base64'; import { M, matches } from '@endo/patterns'; import { @@ -187,7 +187,7 @@ test.skip('Query connection can be created', async t => { runUtils: { EV }, } = t.context; - type Powers = { orchestration: OrchestrationService }; + type Powers = { orchestration: CosmosInterchainService }; const contract = async ({ orchestration }) => { const connection = await EV(orchestration).provideICQConnection('connection-0'); @@ -201,7 +201,7 @@ test.skip('Query connection can be created', async t => { // core eval context { - const orchestration: OrchestrationService = + const orchestration: CosmosInterchainService = await EV.vat('bootstrap').consumeItem('orchestration'); await contract({ orchestration }); } @@ -213,7 +213,7 @@ test.skip('Query connection can send a query', async t => { runUtils: { EV }, } = t.context; - type Powers = { orchestration: OrchestrationService }; + type Powers = { orchestration: CosmosInterchainService }; const contract = async ({ orchestration }) => { const queryConnection = await EV(orchestration).provideICQConnection('connection-0'); @@ -255,7 +255,7 @@ test.skip('Query connection can send a query', async t => { // core eval context { - const orchestration: OrchestrationService = + const orchestration: CosmosInterchainService = await EV.vat('bootstrap').consumeItem('orchestration'); await contract({ orchestration }); } diff --git a/packages/orchestration/index.js b/packages/orchestration/index.js index c5ba4292ecb..09afecb813d 100644 --- a/packages/orchestration/index.js +++ b/packages/orchestration/index.js @@ -3,5 +3,5 @@ /// export * from './src/types.js'; -export * from './src/service.js'; +export * from './src/exos/cosmos-interchain-service.js'; export * from './src/typeGuards.js'; diff --git a/packages/orchestration/src/examples/sendAnywhere.contract.js b/packages/orchestration/src/examples/sendAnywhere.contract.js index ef0dfd7e6f9..42c7bdf4ed5 100644 --- a/packages/orchestration/src/examples/sendAnywhere.contract.js +++ b/packages/orchestration/src/examples/sendAnywhere.contract.js @@ -18,7 +18,7 @@ const { entries } = Object; * @import {NameHub} from '@agoric/vats'; * @import {Remote} from '@agoric/vow'; * @import {CosmosChainInfo, IBCConnectionInfo} from '../cosmos-api'; - * @import {OrchestrationService} from '../service.js'; + * @import {CosmosInterchainService} from '../exos/cosmos-interchain-service.js'; * @import {Orchestrator} from '../types.js' * @import {OrchestrationAccount} from '../orchestration-api.js' */ @@ -26,7 +26,7 @@ const { entries } = Object; /** * @typedef {{ * localchain: Remote; - * orchestrationService: Remote; + * orchestrationService: Remote; * storageNode: Remote; * timerService: Remote; * agoricNames: Remote; diff --git a/packages/orchestration/src/examples/stakeIca.contract.js b/packages/orchestration/src/examples/stakeIca.contract.js index 846326b1bae..fa8846a9a1c 100644 --- a/packages/orchestration/src/examples/stakeIca.contract.js +++ b/packages/orchestration/src/examples/stakeIca.contract.js @@ -17,7 +17,7 @@ const trace = makeTracer('StakeIca'); * @import {Baggage} from '@agoric/vat-data'; * @import {IBCConnectionID} from '@agoric/vats'; * @import {TimerService} from '@agoric/time'; - * @import {ICQConnection, OrchestrationService} from '../types.js'; + * @import {ICQConnection, CosmosInterchainService} from '../types.js'; */ /** @type {ContractMeta} */ @@ -51,7 +51,7 @@ export const privateArgsShape = meta.privateArgsShape; /** * @param {ZCF} zcf * @param {{ - * orchestration: OrchestrationService; + * orchestration: CosmosInterchainService; * storageNode: StorageNode; * marshaller: Marshaller; * timer: TimerService; diff --git a/packages/orchestration/src/examples/swapExample.contract.js b/packages/orchestration/src/examples/swapExample.contract.js index d822cece896..217bf96dce8 100644 --- a/packages/orchestration/src/examples/swapExample.contract.js +++ b/packages/orchestration/src/examples/swapExample.contract.js @@ -12,7 +12,7 @@ import { provideOrchestration } from '../utils/start-helper.js'; * @import {TimerService} from '@agoric/time'; * @import {LocalChain} from '@agoric/vats/src/localchain.js'; * @import {Remote} from '@agoric/internal'; - * @import {OrchestrationService} from '../service.js'; + * @import {CosmosInterchainService} from '../exos/cosmos-interchain-service.js'; * @import {Baggage} from '@agoric/vat-data' * @import {NameHub} from '@agoric/vats'; */ @@ -94,7 +94,7 @@ export const makeNatAmountShape = (brand, min) => * @param {{ * agoricNames: Remote; * localchain: Remote; - * orchestrationService: Remote; + * orchestrationService: Remote; * storageNode: Remote; * timerService: Remote; * marshaller: Marshaller; diff --git a/packages/orchestration/src/examples/unbondExample.contract.js b/packages/orchestration/src/examples/unbondExample.contract.js index d403b53489c..a376238ece1 100644 --- a/packages/orchestration/src/examples/unbondExample.contract.js +++ b/packages/orchestration/src/examples/unbondExample.contract.js @@ -9,7 +9,7 @@ import { provideOrchestration } from '../utils/start-helper.js'; * @import {LocalChain} from '@agoric/vats/src/localchain.js'; * @import {NameHub} from '@agoric/vats'; * @import {Remote} from '@agoric/internal'; - * @import {OrchestrationService} from '../service.js'; + * @import {CosmosInterchainService} from '../exos/cosmos-interchain-service.js'; */ /** @@ -47,7 +47,7 @@ const unbondAndLiquidStakeFn = async (orch, { zcf }, _seat, _offerArgs) => { * @param {{ * agoricNames: Remote; * localchain: Remote; - * orchestrationService: Remote; + * orchestrationService: Remote; * storageNode: Remote; * marshaller: Marshaller; * timerService: Remote; diff --git a/packages/orchestration/src/service.js b/packages/orchestration/src/exos/cosmos-interchain-service.js similarity index 90% rename from packages/orchestration/src/service.js rename to packages/orchestration/src/exos/cosmos-interchain-service.js index 93cbf1ab7ce..82acebd8f13 100644 --- a/packages/orchestration/src/service.js +++ b/packages/orchestration/src/exos/cosmos-interchain-service.js @@ -4,12 +4,12 @@ import { Fail, b } from '@endo/errors'; import { E } from '@endo/far'; import { M } from '@endo/patterns'; import { Shape as NetworkShape } from '@agoric/network'; -import { prepareChainAccountKit } from './exos/chain-account-kit.js'; -import { prepareICQConnectionKit } from './exos/icq-connection-kit.js'; +import { prepareChainAccountKit } from './chain-account-kit.js'; +import { prepareICQConnectionKit } from './icq-connection-kit.js'; import { makeICAChannelAddress, makeICQChannelAddress, -} from './utils/address.js'; +} from '../utils/address.js'; /** * @import {Zone} from '@agoric/base-zone'; @@ -18,7 +18,7 @@ import { * @import {IBCConnectionID} from '@agoric/vats'; * @import {RemoteIbcAddress} from '@agoric/vats/tools/ibc-utils.js'; * @import {Vow, VowTools} from '@agoric/vow'; - * @import {ICQConnection, IcaAccount, ICQConnectionKit, ChainAccountKit} from './types.js'; + * @import {ICQConnection, IcaAccount, ICQConnectionKit, ChainAccountKit} from '../types.js'; */ const { Vow$ } = NetworkShape; // TODO #9611 @@ -60,7 +60,7 @@ const getPower = (powers, name) => { * @param {ReturnType} makeChainAccountKit * @param {ReturnType} makeICQConnectionKit */ -const prepareOrchestrationKit = ( +const prepareCosmosOrchestrationServiceKit = ( zone, { watch }, makeChainAccountKit, @@ -92,7 +92,7 @@ const prepareOrchestrationKit = ( ) .returns(M.remotable('ConnectionKit Holder facet')), }), - public: M.interface('OrchestrationService', { + public: M.interface('CosmosInterchainService', { makeAccount: M.call(M.string(), M.string(), M.string()).returns( Vow$(M.remotable('ChainAccountKit')), ), @@ -240,20 +240,23 @@ const prepareOrchestrationKit = ( * @param {Zone} zone * @param {VowTools} vowTools */ -export const prepareOrchestrationTools = (zone, vowTools) => { +export const prepareCosmosInterchainService = (zone, vowTools) => { const makeChainAccountKit = prepareChainAccountKit(zone, vowTools); const makeICQConnectionKit = prepareICQConnectionKit(zone, vowTools); - const makeOrchestrationKit = prepareOrchestrationKit( - zone, - vowTools, - makeChainAccountKit, - makeICQConnectionKit, - ); + const makeCosmosOrchestrationServiceKit = + prepareCosmosOrchestrationServiceKit( + zone, + vowTools, + makeChainAccountKit, + makeICQConnectionKit, + ); + + const makeCosmosInterchainService = initialPowers => + makeCosmosOrchestrationServiceKit(initialPowers).public; - return harden({ makeOrchestrationKit }); + return makeCosmosInterchainService; }; -harden(prepareOrchestrationTools); +harden(prepareCosmosInterchainService); -/** @typedef {ReturnType} OrchestrationTools */ -/** @typedef {ReturnType} OrchestrationKit */ -/** @typedef {OrchestrationKit['public']} OrchestrationService */ +/** @typedef {ReturnType} MakeCosmosInterchainService */ +/** @typedef {ReturnType} CosmosInterchainService */ diff --git a/packages/orchestration/src/exos/local-chain-facade.js b/packages/orchestration/src/exos/local-chain-facade.js index 251551a7cbe..ddada8f15f4 100644 --- a/packages/orchestration/src/exos/local-chain-facade.js +++ b/packages/orchestration/src/exos/local-chain-facade.js @@ -11,7 +11,7 @@ import { ChainFacadeI } from '../typeGuards.js'; * @import {Remote} from '@agoric/internal'; * @import {LocalChain, LocalChainAccount} from '@agoric/vats/src/localchain.js'; * @import {Vow, VowTools} from '@agoric/vow'; - * @import {OrchestrationService} from '../service.js'; + * @import {CosmosInterchainService} from './cosmos-interchain-service.js'; * @import {MakeLocalOrchestrationAccountKit} from './local-orchestration-account.js'; * @import {ChainAddress, ChainInfo, CosmosChainInfo, IBCConnectionInfo, OrchestrationAccount, PromiseToVow} from '../types.js'; */ @@ -19,7 +19,7 @@ import { ChainFacadeI } from '../typeGuards.js'; /** * @typedef {{ * makeLocalOrchestrationAccountKit: MakeLocalOrchestrationAccountKit; - * orchestration: Remote; + * orchestration: Remote; * storageNode: Remote; * timer: Remote; * localchain: Remote; diff --git a/packages/orchestration/src/exos/orchestrator.js b/packages/orchestration/src/exos/orchestrator.js index 8703f6aaf04..97fca59363d 100644 --- a/packages/orchestration/src/exos/orchestrator.js +++ b/packages/orchestration/src/exos/orchestrator.js @@ -22,7 +22,7 @@ import { * @import {RecorderKit, MakeRecorderKit} from '@agoric/zoe/src/contractSupport/recorder.js'. * @import {Remote} from '@agoric/internal'; * @import {PickFacet} from '@agoric/swingset-liveslots'; - * @import {OrchestrationService} from '../service.js'; + * @import {CosmosInterchainService} from './cosmos-interchain-service.js'; * @import {MakeLocalOrchestrationAccountKit} from './local-orchestration-account.js'; * @import {MakeLocalChainFacade} from './local-chain-facade.js'; * @import {MakeRemoteChainFacade} from './remote-chain-facade.js'; @@ -50,7 +50,7 @@ export const OrchestratorI = M.interface('Orchestrator', { * makeRecorderKit: MakeRecorderKit; * makeLocalChainFacade: MakeLocalChainFacade; * makeRemoteChainFacade: MakeRemoteChainFacade; - * orchestrationService: Remote; + * orchestrationService: Remote; * storageNode: Remote; * timerService: Remote; * vowTools: VowTools; diff --git a/packages/orchestration/src/exos/remote-chain-facade.js b/packages/orchestration/src/exos/remote-chain-facade.js index a88d903d60c..3b87240c39d 100644 --- a/packages/orchestration/src/exos/remote-chain-facade.js +++ b/packages/orchestration/src/exos/remote-chain-facade.js @@ -11,7 +11,7 @@ import { ChainFacadeI } from '../typeGuards.js'; * @import {TimerService} from '@agoric/time'; * @import {Remote} from '@agoric/internal'; * @import {Vow, VowTools} from '@agoric/vow'; - * @import {OrchestrationService} from '../service.js'; + * @import {CosmosInterchainService} from './cosmos-interchain-service.js'; * @import {prepareCosmosOrchestrationAccount} from './cosmos-orchestration-account.js'; * @import {ChainInfo, CosmosChainInfo, IBCConnectionInfo, OrchestrationAccount, ChainAddress, IcaAccount, PromiseToVow, Denom} from '../types.js'; */ @@ -27,7 +27,7 @@ const anyVal = null; * makeCosmosOrchestrationAccount: ReturnType< * typeof prepareCosmosOrchestrationAccount * >; - * orchestration: Remote; + * orchestration: Remote; * storageNode: Remote; * timer: Remote; * vowTools: VowTools; diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index 53cdd699f00..f9cb821140c 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -13,7 +13,7 @@ import { prepareOrchestratorKit } from './exos/orchestrator.js'; * @import {LocalChain} from '@agoric/vats/src/localchain.js'; * @import {RecorderKit, MakeRecorderKit} from '@agoric/zoe/src/contractSupport/recorder.js'. * @import {Remote} from '@agoric/internal'; - * @import {OrchestrationService} from './service.js'; + * @import {CosmosInterchainService} from './exos/cosmos-interchain-service.js'; * @import {Chain, ChainInfo, CosmosChainInfo, IBCConnectionInfo, OrchestrationAccount, Orchestrator} from './types.js'; * @import {MakeLocalChainFacade} from './exos/local-chain-facade.js'; * @import {MakeRemoteChainFacade} from './exos/remote-chain-facade.js'; @@ -26,7 +26,7 @@ import { prepareOrchestratorKit } from './exos/orchestrator.js'; * timerService: Remote; * zcf: ZCF; * storageNode: Remote; - * orchestrationService: Remote; + * orchestrationService: Remote; * localchain: Remote; * chainHub: import('./exos/chain-hub.js').ChainHub; * makeLocalOrchestrationAccountKit: MakeLocalOrchestrationAccountKit; diff --git a/packages/orchestration/src/proposals/orchestration-proposal.js b/packages/orchestration/src/proposals/orchestration-proposal.js index 815e3bc7aad..04968ee3294 100644 --- a/packages/orchestration/src/proposals/orchestration-proposal.js +++ b/packages/orchestration/src/proposals/orchestration-proposal.js @@ -9,7 +9,7 @@ const trace = makeTracer('CoreEvalOrchestration', true); /** * @import {PortAllocator} from '@agoric/network'; - * @import {OrchestrationService} from '../service.js' + * @import {CosmosInterchainService} from '../exos/cosmos-interchain-service.js' * @import {OrchestrationVat} from '../vat-orchestration.js' */ @@ -141,7 +141,7 @@ harden(initChainInfo); /** * @param {BootstrapPowers & { * consume: { - * orchestration: OrchestrationService; + * orchestration: CosmosInterchainService; * }; * }} powers * @param {object} _options diff --git a/packages/orchestration/src/types.ts b/packages/orchestration/src/types.ts index a9a17cc8905..6ee257b930e 100644 --- a/packages/orchestration/src/types.ts +++ b/packages/orchestration/src/types.ts @@ -7,5 +7,5 @@ export type * from './exos/chain-account-kit.js'; export type * from './exos/icq-connection-kit.js'; export type * from './internal.js'; export type * from './orchestration-api.js'; -export type * from './service.js'; +export type * from './exos/cosmos-interchain-service.js'; export type * from './vat-orchestration.js'; diff --git a/packages/orchestration/src/utils/start-helper.js b/packages/orchestration/src/utils/start-helper.js index e96fedabb8f..1c4399257fa 100644 --- a/packages/orchestration/src/utils/start-helper.js +++ b/packages/orchestration/src/utils/start-helper.js @@ -16,13 +16,13 @@ import { prepareLocalChainFacade } from '../exos/local-chain-facade.js'; * @import {Baggage} from '@agoric/vat-data'; * @import {NameHub} from '@agoric/vats'; * @import {Remote} from '@agoric/vow'; - * @import {OrchestrationService} from '../service.js'; + * @import {CosmosInterchainService} from '../exos/cosmos-interchain-service.js'; */ /** * @typedef {{ * localchain: Remote; - * orchestrationService: Remote; + * orchestrationService: Remote; * storageNode: Remote; * timerService: Remote; * agoricNames: Remote; diff --git a/packages/orchestration/src/vat-orchestration.js b/packages/orchestration/src/vat-orchestration.js index 8f3de0b1cc2..b14cd0a17d9 100644 --- a/packages/orchestration/src/vat-orchestration.js +++ b/packages/orchestration/src/vat-orchestration.js @@ -1,14 +1,14 @@ import { Far } from '@endo/far'; -import { prepareVowTools } from '@agoric/vow/vat.js'; +import { prepareSwingsetVowTools } from '@agoric/vow/vat.js'; import { makeDurableZone } from '@agoric/zone/durable.js'; -import { prepareOrchestrationTools } from './service.js'; +import { prepareCosmosInterchainService } from './exos/cosmos-interchain-service.js'; -/** @import {OrchestrationPowers} from './service.js' */ +/** @import {OrchestrationPowers} from './exos/cosmos-interchain-service.js' */ export const buildRootObject = (_vatPowers, _args, baggage) => { const zone = makeDurableZone(baggage); - const vowTools = prepareVowTools(zone.subZone('VowTools')); - const { makeOrchestrationKit } = prepareOrchestrationTools( + const vowTools = prepareSwingsetVowTools(zone.subZone('VowTools')); + const makeCosmosInterchainService = prepareCosmosInterchainService( zone.subZone('orchestration'), vowTools, ); @@ -16,7 +16,7 @@ export const buildRootObject = (_vatPowers, _args, baggage) => { return Far('OrchestrationVat', { /** @param {Partial} [initialPowers] */ makeOrchestrationKit(initialPowers = {}) { - return makeOrchestrationKit(initialPowers); + return { public: makeCosmosInterchainService(initialPowers) }; }, }); }; diff --git a/packages/orchestration/test/supports.ts b/packages/orchestration/test/supports.ts index c017a3f07d2..d3e1c59f706 100644 --- a/packages/orchestration/test/supports.ts +++ b/packages/orchestration/test/supports.ts @@ -22,7 +22,7 @@ import { makeDurableZone } from '@agoric/zone/durable.js'; import { E } from '@endo/far'; import type { ExecutionContext } from 'ava'; import { registerChainNamespace } from '../src/chain-info.js'; -import { prepareOrchestrationTools } from '../src/service.js'; +import { prepareCosmosInterchainService } from '../src/exos/cosmos-interchain-service.js'; import { setupFakeNetwork } from './network-fakes.js'; export { @@ -113,11 +113,11 @@ export const commonSetup = async (t: ExecutionContext) => { ); await setupIBCProtocol(); - const { makeOrchestrationKit } = prepareOrchestrationTools( + const makeOrchestrationKit = prepareCosmosInterchainService( rootZone.subZone('orchestration'), vowTools, ); - const { public: orchestration } = makeOrchestrationKit({ portAllocator }); + const orchestration = makeOrchestrationKit({ portAllocator }); await registerChainNamespace(agoricNamesAdmin, () => {}); diff --git a/packages/vats/src/core/types-ambient.d.ts b/packages/vats/src/core/types-ambient.d.ts index 74359b00ac7..c78ef92ca54 100644 --- a/packages/vats/src/core/types-ambient.d.ts +++ b/packages/vats/src/core/types-ambient.d.ts @@ -368,7 +368,7 @@ type ChainBootstrapSpaceT = { namesByAddress: import('../types.js').NameHub; namesByAddressAdmin: import('../types.js').NamesByAddressAdmin; networkVat: NetworkVat; - orchestration: import('@agoric/orchestration/src/service.js').OrchestrationService; + orchestration: import('@agoric/orchestration/src/service.js').CosmosInterchainService; pegasusConnections: import('@agoric/vats').NameHubKit; pegasusConnectionsAdmin: import('@agoric/vats').NameAdmin; priceAuthorityVat: Awaited; From 5c96c9a9ca837efd2ef580411ce276750c565d67 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 8 Jul 2024 15:55:40 -0700 Subject: [PATCH 02/11] chore: rm unused orchestrationKit --- .../src/proposals/orchestration-proposal.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/orchestration/src/proposals/orchestration-proposal.js b/packages/orchestration/src/proposals/orchestration-proposal.js index 04968ee3294..e9dc0d64ddd 100644 --- a/packages/orchestration/src/proposals/orchestration-proposal.js +++ b/packages/orchestration/src/proposals/orchestration-proposal.js @@ -20,7 +20,6 @@ const trace = makeTracer('CoreEvalOrchestration', true); * }; * produce: { * orchestration: Producer; - * orchestrationKit: Producer; * orchestrationVat: Producer; * }; * }} powers @@ -29,11 +28,7 @@ const trace = makeTracer('CoreEvalOrchestration', true); export const setupOrchestrationVat = async ( { consume: { loadCriticalVat, portAllocator: portAllocatorP }, - produce: { - orchestrationVat, - orchestration, - orchestrationKit: orchestrationKitP, - }, + produce: { orchestrationVat, orchestration }, }, options, ) => { @@ -55,8 +50,6 @@ export const setupOrchestrationVat = async ( orchestration.reset(); orchestration.resolve(newOrchestrationKit.public); - orchestrationKitP.reset(); - orchestrationKitP.resolve(newOrchestrationKit); }; /** @@ -162,7 +155,6 @@ export const getManifestForOrchestration = (_powers, { orchestrationRef }) => ({ }, produce: { orchestration: 'orchestration', - orchestrationKit: 'orchestrationKit', orchestrationVat: 'orchestrationVat', }, }, From caa88a1110b1988923ae377bb59262958413a873 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 8 Jul 2024 15:58:45 -0700 Subject: [PATCH 03/11] feat: makeCosmosInterchainService --- .../orchestration/src/proposals/orchestration-proposal.js | 7 ++++--- packages/orchestration/src/vat-orchestration.js | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/orchestration/src/proposals/orchestration-proposal.js b/packages/orchestration/src/proposals/orchestration-proposal.js index e9dc0d64ddd..321ad4c3a6d 100644 --- a/packages/orchestration/src/proposals/orchestration-proposal.js +++ b/packages/orchestration/src/proposals/orchestration-proposal.js @@ -10,7 +10,6 @@ const trace = makeTracer('CoreEvalOrchestration', true); /** * @import {PortAllocator} from '@agoric/network'; * @import {CosmosInterchainService} from '../exos/cosmos-interchain-service.js' - * @import {OrchestrationVat} from '../vat-orchestration.js' */ /** @@ -44,12 +43,14 @@ export const setupOrchestrationVat = async ( const portAllocator = await portAllocatorP; - const newOrchestrationKit = await E(vats.orchestration).makeOrchestrationKit({ + const cosmosInterchainService = await E( + vats.orchestration, + ).makeCosmosInterchainService({ portAllocator, }); orchestration.reset(); - orchestration.resolve(newOrchestrationKit.public); + orchestration.resolve(cosmosInterchainService); }; /** diff --git a/packages/orchestration/src/vat-orchestration.js b/packages/orchestration/src/vat-orchestration.js index b14cd0a17d9..357ecb24eb4 100644 --- a/packages/orchestration/src/vat-orchestration.js +++ b/packages/orchestration/src/vat-orchestration.js @@ -15,8 +15,8 @@ export const buildRootObject = (_vatPowers, _args, baggage) => { return Far('OrchestrationVat', { /** @param {Partial} [initialPowers] */ - makeOrchestrationKit(initialPowers = {}) { - return { public: makeCosmosInterchainService(initialPowers) }; + makeCosmosInterchainService(initialPowers = {}) { + return makeCosmosInterchainService(initialPowers); }, }); }; From f5772bda2338d705112187a83f1c34ed3eefd2fa Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 8 Jul 2024 14:27:35 -0700 Subject: [PATCH 04/11] refactor: consolidate subzones --- .../orchestration/src/utils/start-helper.js | 30 +++++++++----- .../snapshots/sendAnywhere.test.ts.md | 38 ++++++++++-------- .../snapshots/sendAnywhere.test.ts.snap | Bin 871 -> 922 bytes .../snapshots/unbondExample.test.ts.md | 22 ++++++---- .../snapshots/unbondExample.test.ts.snap | Bin 697 -> 779 bytes 5 files changed, 55 insertions(+), 35 deletions(-) diff --git a/packages/orchestration/src/utils/start-helper.js b/packages/orchestration/src/utils/start-helper.js index 1c4399257fa..959709e732d 100644 --- a/packages/orchestration/src/utils/start-helper.js +++ b/packages/orchestration/src/utils/start-helper.js @@ -48,16 +48,27 @@ export const provideOrchestration = ( baggage, })); - const zone = makeDurableZone(baggage); + // separate zones + const zones = (() => { + const zone = makeDurableZone(baggage); + return { + asyncFlow: zone.subZone('asyncFlow'), + /** for contract-provided names */ + contract: zone.subZone('contract'), + orchestration: zone.subZone('orchestration'), + vows: zone.subZone('vows'), + }; + })(); + const { agoricNames, timerService } = remotePowers; - const vowTools = prepareVowTools(zone.subZone('vows')); + const vowTools = prepareVowTools(zones.vows); const chainHub = makeChainHub(agoricNames, vowTools); const { makeRecorderKit } = prepareRecorderKitMakers(baggage, marshaller); const makeLocalOrchestrationAccountKit = prepareLocalOrchestrationAccountKit( - zone, + zones.orchestration, makeRecorderKit, zcf, timerService, @@ -65,19 +76,18 @@ export const provideOrchestration = ( chainHub, ); - const asyncFlowTools = prepareAsyncFlowTools(zone.subZone('asyncFlow'), { + const asyncFlowTools = prepareAsyncFlowTools(zones.asyncFlow, { vowTools, }); const makeCosmosOrchestrationAccount = prepareCosmosOrchestrationAccount( - // FIXME what zone? - zone, + zones.orchestration, makeRecorderKit, vowTools, zcf, ); - const makeRemoteChainFacade = prepareRemoteChainFacade(zone, { + const makeRemoteChainFacade = prepareRemoteChainFacade(zones.orchestration, { makeCosmosOrchestrationAccount, orchestration: remotePowers.orchestrationService, storageNode: remotePowers.storageNode, @@ -85,7 +95,7 @@ export const provideOrchestration = ( vowTools, }); - const makeLocalChainFacade = prepareLocalChainFacade(zone, { + const makeLocalChainFacade = prepareLocalChainFacade(zones.orchestration, { makeLocalOrchestrationAccountKit, localchain: remotePowers.localchain, // FIXME what path? @@ -97,7 +107,7 @@ export const provideOrchestration = ( const facade = makeOrchestrationFacade({ zcf, - zone, + zone: zones.orchestration, chainHub, makeLocalOrchestrationAccountKit, makeRecorderKit, @@ -108,6 +118,6 @@ export const provideOrchestration = ( vowTools, ...remotePowers, }); - return { ...facade, chainHub, vowTools, zone }; + return { ...facade, chainHub, vowTools, zone: zones.contract }; }; harden(provideOrchestration); diff --git a/packages/orchestration/test/examples/snapshots/sendAnywhere.test.ts.md b/packages/orchestration/test/examples/snapshots/sendAnywhere.test.ts.md index 5bee6c1c222..b26f76cdb5a 100644 --- a/packages/orchestration/test/examples/snapshots/sendAnywhere.test.ts.md +++ b/packages/orchestration/test/examples/snapshots/sendAnywhere.test.ts.md @@ -10,17 +10,7 @@ Generated by [AVA](https://avajs.dev). { 'Durable Publish Kit_kindHandle': 'Alleged: kind', - 'Local Orchestration Account Kit_kindHandle': 'Alleged: kind', - LocalChainFacade_kindHandle: 'Alleged: kind', - Orchestrator_kindHandle: 'Alleged: kind', Recorder_kindHandle: 'Alleged: kind', - RemoteChainFacade_kindHandle: 'Alleged: kind', - ResumableAgoricNamesHack_kindHandle: 'Alleged: kind', - 'Send CF_kindHandle': 'Alleged: kind', - 'Send CF_singleton': 'Alleged: Send CF', - 'Send PF_kindHandle': 'Alleged: kind', - 'Send PF_singleton': 'Alleged: Send PF', - 'Staking Account Holder_kindHandle': 'Alleged: kind', asyncFlow: { AdminAsyncFlow_kindHandle: 'Alleged: kind', AdminAsyncFlow_singleton: 'Alleged: AdminAsyncFlow', @@ -34,16 +24,30 @@ Generated by [AVA](https://avajs.dev). flowForOutcomeVow: {}, unwrapMap: 'Alleged: weakMapStore', }, - sendIt: { - asyncFlow_kindHandle: 'Alleged: kind', - endowments: { - 1: { - contractState_kindHandle: 'Alleged: kind', - contractState_singleton: 'Alleged: contractState', + contract: { + ResumableAgoricNamesHack_kindHandle: 'Alleged: kind', + 'Send CF_kindHandle': 'Alleged: kind', + 'Send CF_singleton': 'Alleged: Send CF', + 'Send PF_kindHandle': 'Alleged: kind', + 'Send PF_singleton': 'Alleged: Send PF', + vbankAssetsByBrand: {}, + }, + orchestration: { + 'Local Orchestration Account Kit_kindHandle': 'Alleged: kind', + LocalChainFacade_kindHandle: 'Alleged: kind', + Orchestrator_kindHandle: 'Alleged: kind', + RemoteChainFacade_kindHandle: 'Alleged: kind', + 'Staking Account Holder_kindHandle': 'Alleged: kind', + sendIt: { + asyncFlow_kindHandle: 'Alleged: kind', + endowments: { + 1: { + contractState_kindHandle: 'Alleged: kind', + contractState_singleton: 'Alleged: contractState', + }, }, }, }, - vbankAssetsByBrand: {}, vows: { PromiseWatcher_kindHandle: 'Alleged: kind', VowInternalsKit_kindHandle: 'Alleged: kind', diff --git a/packages/orchestration/test/examples/snapshots/sendAnywhere.test.ts.snap b/packages/orchestration/test/examples/snapshots/sendAnywhere.test.ts.snap index ca1ec68d67d53991ac332fc3a7d9d5b740e54e12..68b8203f347ce15d9607a8fbfed72c1e1789732e 100644 GIT binary patch literal 922 zcmV;L17-X{RzVJo5K`H5fu`G3Q;eVh&6o@LKqC&UMuJ?8=;x${X z_WQm!Z{C}E-+p^Ih^0T$Po8oUnV5$I3PTEcqyYD0r&^NCIi-3W0f^_2Oo0ZFqXfrtgL`7f;GUFvBs=*W`nt_?E1TjqCw2P zelmz7J@oEG=Fun;!8VB?<{53V6URK{!CT%8E5%sb2 zPE+WU0@U)QFp7MWB0m<8MXCHD*G7?vq)6ev3$XK8PW7x#7jIg?s}?Y{fbT8fPYZb6 z20pfdA8g>c4Qx2T+Ya#1Db>!JuU(5ZzjA2c*m8jb7x=;jp1CDyqayvw1)jS= zw*h?G0Dfu!RukB1mZYt+)S)I2Hi7S&z#nD$#Y%%Ol$x{I3C5A=WM!_~+l`W3M2p$<_1BQk?Z}G|MuQqHYFTy+owK`(mnSGC9*Rn~QL*8lkd{t9gJ5xqRC1%5dLE z#p|ZAxo^nuI=fh6>_+S4V6PuvmPGisDdg$_jkwY&>zx8?HD~oGiW9|;DIXLmhq0XY zq}ol4FUS0#(yexqW_gb$*_X?CYEw?5do)Q)aOz08xyN-fo(+{wC{^UYM`NzH$sg4% z*rk0g0`FF@u5LBcRl2;A%U)1UU9o@875gt=vENIZaa3r=rN;vjqmI_x=Chwv5m0L0=ad(9m22J0>lCL!|pQA^Y({=Bg zDAs3?wvN5Q?I=Y@%+B7HmzQ%a^9`qDGxMnXpJ=meQTER*;8_c>+9i8xSM13u`vTQ) zrX|L%w@(_kz(pXZV=hc;_txz;aHpKYLL~*326|Ws#NJG|@mU-AvJL!Nj&b3o+t|o{ wR?-Hq)$ literal 871 zcmV-t1DO0lRzVq2=Kp=E6P+GsSu zj)6767O})i%gh6-G})I|QcYdKgHGBNiRlH`6Z=CykKIEew zJBRex`EQRM*W*{4mimc|r=7N@#HUqlfw5N}FfrH3?8>k$)F?B3Q$8^HhRf)h&Cb7@ zIX}MBCE0Ho!>w7}UDdQNyEB6+@2HU(kM+^t%fKIH;7u90Pys{*cv1o0SAcJQ!1};% zKJeTJUi;1nm*z*f#=Mm(@I@8asya~LfzDg&u29)jf!!*wR|WoZ#g61w$7fCfPPL*z zB3qN>6|MY9hn{PIl_`53>F6x4CgUg*B?}L1JCzynwj6014vUZcnY=>oGfqzha$tA! z+)(kRRl4xrIJIfX@*-ccz}UswL9Z@<7=cuVS1IOti~3xf47EOkYEDsYN<^yp2gqO+ zvMto8t@L_oLp9)ca@DG*S(G+eDa8pze=$rKL6PGH>#> zxVV@b`|`gog^IfrN>6LRUd>qs)!Z^*S%P2AB$%Dgw$r;B@V*9IsyiCBoQ7N8lcADU xQ)shxE_~_FvvYI!`II~d?k24?;y7oK-f$2KR$@<*~0{bbQfV zp`yuIOv_a{XD!yeTNz+RjKU`Kq-ruXfpCV9+XRT=EDa8YSL3oDK}QKF<4K_v^>l=M zN+3C@yfzE8qS}`tf`298)Jxe926ehzuz->UJhg!L7VzBy$~LfX10QYRrwwFMz^xSU zBxTgj8m(Q1*soK-n-uWPq`D?Goppe`1KeH>D! zpl8P#ddX-;soL!Nq8gWV+Fo8Ym;FJOz7*4DP_Bg{5^jsW zqP^ZkV>J?CX*|N%F&2jb#>nP$ugX?kOU0&5qg2;avuRE-L&&}K`5+h1E=MT5hqT4i zF6}TCM6Blt*4&U)qdpH6JEI&VDSKS@Yf`O;+LK+jGuEwa7-hLed-0q3VQPIwJ8QHT zl^~ip%Mf4b4XnefQIAb+9rH=;Sd)rFX@VBp*bE`>5@&Q*>swnsHR9h~l^*4l^`v1` zs-7o9p)X=}OHsW0ZR(2}^=NbIp;$OiMNU1~ge9;=#U`6uDj5~(` zFgoBHN_PE#?NaTvr@y9)JF@>sXr=_^!3BCTAMLxXeI868&72vjQ&ox{5<6by^Z6kb zn{3MP)*^&{m7KScUFsrYg}-!#`YE JC1Xnn0061zZC?NY literal 697 zcmV;q0!IBoRzVgXeIy|yj+I1^htN{OC(s!ZD~Lo6aUMVu#bQ|Lcrn#}G2cmm)Yz$XAM0X7NnngE{(@S6Y| zCE&OOEE2y${Ce{RXO@ucxUjGQG6!-Eq>M#US|SdJS0T4H5<{Dk2fImAintX#685+) zRJcV|DER<3SCx`SJiHh5V<7W{Bqd-F_O~1R`-0}Q?`~^GWl%S)#baxz6ybv@Yv76r^b9taxGfQDx07yb0D)h{z^6M z2vsd0GD5$ZqsKx;l3T4Z>t*awWWJ31qF<%Zs<6vyiAsqFs%L1oTimB>;|gPCtY!jZ z;QYF5>!@M1DQxzYhNYGlsbZdxH~y8A|5_nYY?DUZ9MLv6af;?r6^ z)V+twa-*n>|KVf0oZfq2g^VYlPG9b$S2c#75_fPam&;jfu&Z8fwMV1=aFk2h Date: Mon, 8 Jul 2024 14:43:05 -0700 Subject: [PATCH 05/11] feat: withOrchestration helper --- .../src/examples/sendAnywhere.contract.js | 35 ++++++++++-------- .../src/examples/swapExample.contract.js | 36 ++++++------------- .../src/examples/unbondExample.contract.js | 35 ++++++------------ .../orchestration/src/utils/start-helper.js | 33 +++++++++++++++++ 4 files changed, 73 insertions(+), 66 deletions(-) diff --git a/packages/orchestration/src/examples/sendAnywhere.contract.js b/packages/orchestration/src/examples/sendAnywhere.contract.js index 42c7bdf4ed5..ac8cde3b6f0 100644 --- a/packages/orchestration/src/examples/sendAnywhere.contract.js +++ b/packages/orchestration/src/examples/sendAnywhere.contract.js @@ -1,25 +1,26 @@ +import { makeStateRecord } from '@agoric/async-flow'; +import { AmountShape } from '@agoric/ertp'; +import { heapVowE } from '@agoric/vow/vat.js'; import { withdrawFromSeat } from '@agoric/zoe/src/contractSupport/zoeHelpers.js'; import { InvitationShape } from '@agoric/zoe/src/typeGuards.js'; -import { M, mustMatch } from '@endo/patterns'; import { E } from '@endo/far'; -import { heapVowE } from '@agoric/vow/vat.js'; -import { makeStateRecord } from '@agoric/async-flow'; -import { AmountShape } from '@agoric/ertp'; -import { CosmosChainInfoShape } from '../typeGuards.js'; -import { provideOrchestration } from '../utils/start-helper.js'; +import { M, mustMatch } from '@endo/patterns'; import { makeResumableAgoricNamesHack } from '../exos/agoric-names-tools.js'; +import { CosmosChainInfoShape } from '../typeGuards.js'; +import { withOrchestration } from '../utils/start-helper.js'; const { entries } = Object; /** - * @import {Baggage} from '@agoric/vat-data'; * @import {TimerService} from '@agoric/time'; * @import {LocalChain} from '@agoric/vats/src/localchain.js'; * @import {NameHub} from '@agoric/vats'; * @import {Remote} from '@agoric/vow'; + * @import {Zone} from '@agoric/zone'; * @import {CosmosChainInfo, IBCConnectionInfo} from '../cosmos-api'; * @import {CosmosInterchainService} from '../exos/cosmos-interchain-service.js'; * @import {Orchestrator} from '../types.js' + * @import {OrchestrationTools} from '../utils/start-helper.js'; * @import {OrchestrationAccount} from '../orchestration-api.js' */ @@ -89,19 +90,21 @@ export const SingleAmountRecord = M.and( ); /** + * Orchestration contract to be wrapped by withOrchestration for Zoe + * * @param {ZCF} zcf * @param {OrchestrationPowers & { * marshaller: Marshaller; * }} privateArgs - * @param {Baggage} baggage + * @param {Zone} zone + * @param {OrchestrationTools} tools */ -export const start = async (zcf, privateArgs, baggage) => { - const { chainHub, orchestrate, vowTools, zone } = provideOrchestration( - zcf, - baggage, - privateArgs, - privateArgs.marshaller, - ); +const contract = async ( + zcf, + privateArgs, + zone, + { chainHub, orchestrate, vowTools }, +) => { const agoricNamesTools = makeResumableAgoricNamesHack(zone, { agoricNames: privateArgs.agoricNames, vowTools, @@ -171,3 +174,5 @@ export const start = async (zcf, privateArgs, baggage) => { return { publicFacet, creatorFacet }; }; + +export const start = withOrchestration(contract); diff --git a/packages/orchestration/src/examples/swapExample.contract.js b/packages/orchestration/src/examples/swapExample.contract.js index 217bf96dce8..b4079fcc1d5 100644 --- a/packages/orchestration/src/examples/swapExample.contract.js +++ b/packages/orchestration/src/examples/swapExample.contract.js @@ -5,7 +5,7 @@ import { Far } from '@endo/far'; import { deeplyFulfilled } from '@endo/marshal'; import { M, objectMap } from '@endo/patterns'; import { orcUtils } from '../utils/orc.js'; -import { provideOrchestration } from '../utils/start-helper.js'; +import { withOrchestration } from '../utils/start-helper.js'; /** * @import {Orchestrator, IcaAccount, CosmosValidatorAddress} from '../types.js' @@ -13,8 +13,9 @@ import { provideOrchestration } from '../utils/start-helper.js'; * @import {LocalChain} from '@agoric/vats/src/localchain.js'; * @import {Remote} from '@agoric/internal'; * @import {CosmosInterchainService} from '../exos/cosmos-interchain-service.js'; - * @import {Baggage} from '@agoric/vat-data' * @import {NameHub} from '@agoric/vats'; + * @import {Zone} from '@agoric/zone'; + * @import {OrchestrationTools} from '../utils/start-helper.js'; */ /** @@ -90,6 +91,8 @@ export const makeNatAmountShape = (brand, min) => harden({ brand, value: min ? M.gte(min) : M.nat() }); /** + * Orchestration contract to be wrapped by withOrchestration for Zoe + * * @param {ZCF} zcf * @param {{ * agoricNames: Remote; @@ -99,31 +102,10 @@ export const makeNatAmountShape = (brand, min) => * timerService: Remote; * marshaller: Marshaller; * }} privateArgs - * @param {Baggage} baggage + * @param {Zone} zone + * @param {OrchestrationTools} tools */ -export const start = async (zcf, privateArgs, baggage) => { - const { - agoricNames, - localchain, - orchestrationService, - storageNode, - timerService, - marshaller, - } = privateArgs; - - const { orchestrate } = provideOrchestration( - zcf, - baggage, - { - agoricNames, - localchain, - orchestrationService, - storageNode, - timerService, - }, - marshaller, - ); - +const contract = async (zcf, privateArgs, zone, { orchestrate }) => { const { brands } = zcf.getTerms(); /** deprecated historical example */ @@ -153,3 +135,5 @@ export const start = async (zcf, privateArgs, baggage) => { return harden({ publicFacet }); }; + +export const start = withOrchestration(contract); diff --git a/packages/orchestration/src/examples/unbondExample.contract.js b/packages/orchestration/src/examples/unbondExample.contract.js index a376238ece1..83f92afd233 100644 --- a/packages/orchestration/src/examples/unbondExample.contract.js +++ b/packages/orchestration/src/examples/unbondExample.contract.js @@ -1,6 +1,6 @@ import { Far } from '@endo/far'; import { M } from '@endo/patterns'; -import { provideOrchestration } from '../utils/start-helper.js'; +import { withOrchestration } from '../utils/start-helper.js'; /** * @import {Orchestrator, IcaAccount, CosmosValidatorAddress} from '../types.js' @@ -9,7 +9,9 @@ import { provideOrchestration } from '../utils/start-helper.js'; * @import {LocalChain} from '@agoric/vats/src/localchain.js'; * @import {NameHub} from '@agoric/vats'; * @import {Remote} from '@agoric/internal'; + * @import {Zone} from '@agoric/zone'; * @import {CosmosInterchainService} from '../exos/cosmos-interchain-service.js'; + * @import {OrchestrationTools} from '../utils/start-helper.js'; */ /** @@ -43,6 +45,8 @@ const unbondAndLiquidStakeFn = async (orch, { zcf }, _seat, _offerArgs) => { }; /** + * Orchestration contract to be wrapped by withOrchestration for Zoe + * * @param {ZCF} zcf * @param {{ * agoricNames: Remote; @@ -52,31 +56,10 @@ const unbondAndLiquidStakeFn = async (orch, { zcf }, _seat, _offerArgs) => { * marshaller: Marshaller; * timerService: Remote; * }} privateArgs - * @param {Baggage} baggage + * @param {Zone} zone + * @param {OrchestrationTools} tools */ -export const start = async (zcf, privateArgs, baggage) => { - const { - agoricNames, - localchain, - orchestrationService, - storageNode, - marshaller, - timerService, - } = privateArgs; - - const { orchestrate } = provideOrchestration( - zcf, - baggage, - { - agoricNames, - localchain, - orchestrationService, - storageNode, - timerService, - }, - marshaller, - ); - +const contract = async (zcf, privateArgs, zone, { orchestrate }) => { /** @type {OfferHandler} */ const unbondAndLiquidStake = orchestrate( 'LSTTia', @@ -103,3 +86,5 @@ export const start = async (zcf, privateArgs, baggage) => { return harden({ publicFacet }); }; + +export const start = withOrchestration(contract); diff --git a/packages/orchestration/src/utils/start-helper.js b/packages/orchestration/src/utils/start-helper.js index 959709e732d..a25de447666 100644 --- a/packages/orchestration/src/utils/start-helper.js +++ b/packages/orchestration/src/utils/start-helper.js @@ -16,6 +16,7 @@ import { prepareLocalChainFacade } from '../exos/local-chain-facade.js'; * @import {Baggage} from '@agoric/vat-data'; * @import {NameHub} from '@agoric/vats'; * @import {Remote} from '@agoric/vow'; + * @import {Zone} from '@agoric/zone'; * @import {CosmosInterchainService} from '../exos/cosmos-interchain-service.js'; */ @@ -121,3 +122,35 @@ export const provideOrchestration = ( return { ...facade, chainHub, vowTools, zone: zones.contract }; }; harden(provideOrchestration); + +/** @typedef {Omit, 'zone'>} OrchestrationTools */ + +/** + * Simplifies contract functions for Orchestration by wrapping a simpler + * function with all the tools it needs in order to use Orchestration. + * + * @template {Record} CT + * @template {OrchestrationPowers & { + * marshaller: Marshaller; + * }} PA + * @template R + * @param {( + * zcf: ZCF, + * privateArgs: PA, + * zone: Zone, + * tools: OrchestrationTools, + * ) => Promise} contractFn + * @returns {(zcf: ZCF, privateArgs: PA, baggage: Baggage) => Promise} a + * Zoe start function + */ +export const withOrchestration = + contractFn => async (zcf, privateArgs, baggage) => { + const { zone, ...tools } = provideOrchestration( + zcf, + baggage, + privateArgs, + privateArgs.marshaller, + ); + return contractFn(zcf, privateArgs, zone, tools); + }; +harden(withOrchestration); From 595ec5be654e35b7f8387e0c770a4c8d6b48f9b7 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 9 Jul 2024 08:04:54 -0700 Subject: [PATCH 06/11] fix(examples): exos for upgradability --- .../src/examples/swapExample.contract.js | 28 ++++++++--------- .../src/examples/unbondExample.contract.js | 30 +++++++++---------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/packages/orchestration/src/examples/swapExample.contract.js b/packages/orchestration/src/examples/swapExample.contract.js index b4079fcc1d5..eb3a93da608 100644 --- a/packages/orchestration/src/examples/swapExample.contract.js +++ b/packages/orchestration/src/examples/swapExample.contract.js @@ -1,7 +1,6 @@ import { StorageNodeShape } from '@agoric/internal'; import { TimerServiceShape } from '@agoric/time'; import { withdrawFromSeat } from '@agoric/zoe/src/contractSupport/zoeHelpers.js'; -import { Far } from '@endo/far'; import { deeplyFulfilled } from '@endo/marshal'; import { M, objectMap } from '@endo/patterns'; import { orcUtils } from '../utils/orc.js'; @@ -117,20 +116,19 @@ const contract = async (zcf, privateArgs, zone, { orchestrate }) => { */ const swapAndStakeHandler = orchestrate('LSTTia', { zcf }, stackAndSwapFn); - const makeSwapAndStakeInvitation = () => - zcf.makeInvitation( - swapAndStakeHandler, - 'Swap for TIA and stake', - undefined, - harden({ - give: { Stable: makeNatAmountShape(brands.Stable, 1n) }, - want: {}, // XXX ChainAccount Ownable? - exit: M.any(), - }), - ); - - const publicFacet = Far('SwapAndStake Public Facet', { - makeSwapAndStakeInvitation, + const publicFacet = zone.exo('publicFacet', undefined, { + makeSwapAndStakeInvitation() { + return zcf.makeInvitation( + swapAndStakeHandler, + 'Swap for TIA and stake', + undefined, + harden({ + give: { Stable: makeNatAmountShape(brands.Stable, 1n) }, + want: {}, // XXX ChainAccount Ownable? + exit: M.any(), + }), + ); + }, }); return harden({ publicFacet }); diff --git a/packages/orchestration/src/examples/unbondExample.contract.js b/packages/orchestration/src/examples/unbondExample.contract.js index 83f92afd233..0b0beac9bf3 100644 --- a/packages/orchestration/src/examples/unbondExample.contract.js +++ b/packages/orchestration/src/examples/unbondExample.contract.js @@ -1,4 +1,3 @@ -import { Far } from '@endo/far'; import { M } from '@endo/patterns'; import { withOrchestration } from '../utils/start-helper.js'; @@ -67,21 +66,20 @@ const contract = async (zcf, privateArgs, zone, { orchestrate }) => { unbondAndLiquidStakeFn, ); - const makeUnbondAndLiquidStakeInvitation = () => - zcf.makeInvitation( - unbondAndLiquidStake, - 'Unbond and liquid stake', - undefined, - harden({ - // Nothing to give; the funds come from undelegating - give: {}, - want: {}, // XXX ChainAccount Ownable? - exit: M.any(), - }), - ); - - const publicFacet = Far('SwapAndStake Public Facet', { - makeUnbondAndLiquidStakeInvitation, + const publicFacet = zone.exo('publicFacet', undefined, { + makeUnbondAndLiquidStakeInvitation() { + return zcf.makeInvitation( + unbondAndLiquidStake, + 'Unbond and liquid stake', + undefined, + harden({ + // Nothing to give; the funds come from undelegating + give: {}, + want: {}, // XXX ChainAccount Ownable? + exit: M.any(), + }), + ); + }, }); return harden({ publicFacet }); From 5c9aeacabfdaec5cc904c5c8459048e0e1fbb5b8 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 9 Jul 2024 10:29:37 -0700 Subject: [PATCH 07/11] chore(types): fix VatLoader index --- packages/vats/src/core/types-ambient.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/vats/src/core/types-ambient.d.ts b/packages/vats/src/core/types-ambient.d.ts index c78ef92ca54..910b096cc70 100644 --- a/packages/vats/src/core/types-ambient.d.ts +++ b/packages/vats/src/core/types-ambient.d.ts @@ -109,7 +109,9 @@ type Producer = { }; type VatSourceRef = { bundleName?: string; bundleID?: string }; -type VatLoader = ( +type VatLoader = < + N extends Names, +>( name: N, sourceRef?: VatSourceRef, ) => Promise>; From 59d05499fca3de36f52a0d9a6afbc7706af254f4 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 9 Jul 2024 10:38:19 -0700 Subject: [PATCH 08/11] chore: remove addOrchestrationToClient --- .../src/proposals/orchestration-proposal.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/packages/orchestration/src/proposals/orchestration-proposal.js b/packages/orchestration/src/proposals/orchestration-proposal.js index 321ad4c3a6d..a7f4fa5f439 100644 --- a/packages/orchestration/src/proposals/orchestration-proposal.js +++ b/packages/orchestration/src/proposals/orchestration-proposal.js @@ -132,21 +132,6 @@ export const initChainInfo = async ({ }; harden(initChainInfo); -/** - * @param {BootstrapPowers & { - * consume: { - * orchestration: CosmosInterchainService; - * }; - * }} powers - * @param {object} _options - */ -export const addOrchestrationToClient = async ( - { consume: { client, orchestration } }, - _options, -) => { - return E(client).assignBundle([_a => ({ orchestration })]); -}; - export const getManifestForOrchestration = (_powers, { orchestrationRef }) => ({ manifest: { [setupOrchestrationVat.name]: { From 504490958a1c5cd1861e3afa02427071ee0d7c46 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 9 Jul 2024 09:53:34 -0700 Subject: [PATCH 09/11] refactor: bootstrap cosmosInterchainService --- .../src/proposals/orchestration-proposal.js | 9 ++++----- packages/orchestration/src/proposals/start-stakeAtom.js | 6 +++--- packages/orchestration/src/proposals/start-stakeOsmo.js | 6 +++--- packages/vats/src/core/types-ambient.d.ts | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/orchestration/src/proposals/orchestration-proposal.js b/packages/orchestration/src/proposals/orchestration-proposal.js index a7f4fa5f439..8094b830ddb 100644 --- a/packages/orchestration/src/proposals/orchestration-proposal.js +++ b/packages/orchestration/src/proposals/orchestration-proposal.js @@ -18,7 +18,6 @@ const trace = makeTracer('CoreEvalOrchestration', true); * portAllocator: PortAllocator; * }; * produce: { - * orchestration: Producer; * orchestrationVat: Producer; * }; * }} powers @@ -27,7 +26,7 @@ const trace = makeTracer('CoreEvalOrchestration', true); export const setupOrchestrationVat = async ( { consume: { loadCriticalVat, portAllocator: portAllocatorP }, - produce: { orchestrationVat, orchestration }, + produce: { orchestrationVat, ...produce }, }, options, ) => { @@ -49,8 +48,8 @@ export const setupOrchestrationVat = async ( portAllocator, }); - orchestration.reset(); - orchestration.resolve(cosmosInterchainService); + produce.cosmosInterchainService.reset(); + produce.cosmosInterchainService.resolve(cosmosInterchainService); }; /** @@ -140,7 +139,7 @@ export const getManifestForOrchestration = (_powers, { orchestrationRef }) => ({ portAllocator: 'portAllocator', }, produce: { - orchestration: 'orchestration', + cosmosInterchainService: 'cosmosInterchainService', orchestrationVat: 'orchestrationVat', }, }, diff --git a/packages/orchestration/src/proposals/start-stakeAtom.js b/packages/orchestration/src/proposals/start-stakeAtom.js index ee63de7c612..c64cc7e2445 100644 --- a/packages/orchestration/src/proposals/start-stakeAtom.js +++ b/packages/orchestration/src/proposals/start-stakeAtom.js @@ -29,7 +29,7 @@ export const startStakeAtom = async ({ board, chainStorage, chainTimerService, - orchestration, + cosmosInterchainService, startUpgradable, }, installation: { @@ -65,7 +65,7 @@ export const startStakeAtom = async ({ icqEnabled: cosmoshub.icqEnabled, }, privateArgs: { - orchestration: await orchestration, + orchestration: await cosmosInterchainService, storageNode, marshaller, timer: await chainTimerService, @@ -89,7 +89,7 @@ export const getManifestForStakeAtom = ( board: true, chainStorage: true, chainTimerService: true, - orchestration: true, + cosmosInterchainService: true, startUpgradable: true, }, installation: { diff --git a/packages/orchestration/src/proposals/start-stakeOsmo.js b/packages/orchestration/src/proposals/start-stakeOsmo.js index fc3b3118096..8f8cf1849eb 100644 --- a/packages/orchestration/src/proposals/start-stakeOsmo.js +++ b/packages/orchestration/src/proposals/start-stakeOsmo.js @@ -29,7 +29,7 @@ export const startStakeOsmo = async ({ board, chainStorage, chainTimerService, - orchestration, + cosmosInterchainService, startUpgradable, }, installation: { @@ -66,7 +66,7 @@ export const startStakeOsmo = async ({ icqEnabled: osmosis.icqEnabled, }, privateArgs: { - orchestration: await orchestration, + orchestration: await cosmosInterchainService, storageNode, marshaller, timer: await chainTimerService, @@ -90,7 +90,7 @@ export const getManifestForStakeOsmo = ( board: true, chainStorage: true, chainTimerService: true, - orchestration: true, + cosmosInterchainService: true, startUpgradable: true, }, installation: { diff --git a/packages/vats/src/core/types-ambient.d.ts b/packages/vats/src/core/types-ambient.d.ts index 910b096cc70..ee27e97924b 100644 --- a/packages/vats/src/core/types-ambient.d.ts +++ b/packages/vats/src/core/types-ambient.d.ts @@ -344,6 +344,7 @@ type ChainBootstrapSpaceT = { client: ClientManager; clientCreator: any; coreEvalBridgeHandler: import('../types.js').BridgeHandler; + cosmosInterchainService: import('@agoric/orchestration').CosmosInterchainService; /** Utilities to support debugging */ diagnostics: { /** @@ -370,7 +371,6 @@ type ChainBootstrapSpaceT = { namesByAddress: import('../types.js').NameHub; namesByAddressAdmin: import('../types.js').NamesByAddressAdmin; networkVat: NetworkVat; - orchestration: import('@agoric/orchestration/src/service.js').CosmosInterchainService; pegasusConnections: import('@agoric/vats').NameHubKit; pegasusConnectionsAdmin: import('@agoric/vats').NameAdmin; priceAuthorityVat: Awaited; From c2f422f768884d4df7edbc1f3cb021f5faf25292 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 9 Jul 2024 10:37:14 -0700 Subject: [PATCH 10/11] refactor: privateArgs cosmosInterchainService --- .../orchestration/src/examples/stakeIca.contract.js | 11 ++++++++--- .../orchestration/src/proposals/start-stakeAtom.js | 2 +- .../orchestration/src/proposals/start-stakeOsmo.js | 2 +- .../test/examples/stake-ica.contract.test.ts | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/orchestration/src/examples/stakeIca.contract.js b/packages/orchestration/src/examples/stakeIca.contract.js index fa8846a9a1c..e40485d93ae 100644 --- a/packages/orchestration/src/examples/stakeIca.contract.js +++ b/packages/orchestration/src/examples/stakeIca.contract.js @@ -30,7 +30,7 @@ export const meta = harden({ icqEnabled: M.boolean(), }, privateArgsShape: { - orchestration: M.remotable('orchestration'), + cosmosInterchainService: M.remotable('cosmosInterchainService'), storageNode: StorageNodeShape, marshaller: M.remotable('marshaller'), timer: TimerServiceShape, @@ -51,7 +51,7 @@ export const privateArgsShape = meta.privateArgsShape; /** * @param {ZCF} zcf * @param {{ - * orchestration: CosmosInterchainService; + * cosmosInterchainService: CosmosInterchainService; * storageNode: StorageNode; * marshaller: Marshaller; * timer: TimerService; @@ -66,7 +66,12 @@ export const start = async (zcf, privateArgs, baggage) => { bondDenom, icqEnabled, } = zcf.getTerms(); - const { orchestration, marshaller, storageNode, timer } = privateArgs; + const { + cosmosInterchainService: orchestration, + marshaller, + storageNode, + timer, + } = privateArgs; const zone = makeDurableZone(baggage); diff --git a/packages/orchestration/src/proposals/start-stakeAtom.js b/packages/orchestration/src/proposals/start-stakeAtom.js index c64cc7e2445..96bc316e5c5 100644 --- a/packages/orchestration/src/proposals/start-stakeAtom.js +++ b/packages/orchestration/src/proposals/start-stakeAtom.js @@ -65,7 +65,7 @@ export const startStakeAtom = async ({ icqEnabled: cosmoshub.icqEnabled, }, privateArgs: { - orchestration: await cosmosInterchainService, + cosmosInterchainService: await cosmosInterchainService, storageNode, marshaller, timer: await chainTimerService, diff --git a/packages/orchestration/src/proposals/start-stakeOsmo.js b/packages/orchestration/src/proposals/start-stakeOsmo.js index 8f8cf1849eb..6fcfde82d5a 100644 --- a/packages/orchestration/src/proposals/start-stakeOsmo.js +++ b/packages/orchestration/src/proposals/start-stakeOsmo.js @@ -66,7 +66,7 @@ export const startStakeOsmo = async ({ icqEnabled: osmosis.icqEnabled, }, privateArgs: { - orchestration: await cosmosInterchainService, + cosmosInterchainService: await cosmosInterchainService, storageNode, marshaller, timer: await chainTimerService, diff --git a/packages/orchestration/test/examples/stake-ica.contract.test.ts b/packages/orchestration/test/examples/stake-ica.contract.test.ts index a3448d45487..f879a856204 100644 --- a/packages/orchestration/test/examples/stake-ica.contract.test.ts +++ b/packages/orchestration/test/examples/stake-ica.contract.test.ts @@ -69,7 +69,7 @@ const startContract = async ({ terms, { marshaller, - orchestration, + cosmosInterchainService: orchestration, storageNode: storage.rootNode.makeChildNode(storagePath), timer, }, From 1c1560a7a3562e8c92d005630b2a9f78753cb65f Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 9 Jul 2024 12:52:28 -0700 Subject: [PATCH 11/11] test: match cosmosInterchainService bootstrap --- .../test/examples/stake-ica.contract.test.ts | 4 ++-- packages/orchestration/test/service.test.ts | 10 +++++----- packages/orchestration/test/supports.ts | 12 +++++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/orchestration/test/examples/stake-ica.contract.test.ts b/packages/orchestration/test/examples/stake-ica.contract.test.ts index f879a856204..4ce9cf04df5 100644 --- a/packages/orchestration/test/examples/stake-ica.contract.test.ts +++ b/packages/orchestration/test/examples/stake-ica.contract.test.ts @@ -51,7 +51,7 @@ const getChainTerms = ( }; const startContract = async ({ - orchestration, + cosmosInterchainService, timer, marshaller, storage, @@ -69,7 +69,7 @@ const startContract = async ({ terms, { marshaller, - cosmosInterchainService: orchestration, + cosmosInterchainService, storageNode: storage.rootNode.makeChildNode(storagePath), timer, }, diff --git a/packages/orchestration/test/service.test.ts b/packages/orchestration/test/service.test.ts index 5d27a08e1b8..20996a83ae8 100644 --- a/packages/orchestration/test/service.test.ts +++ b/packages/orchestration/test/service.test.ts @@ -18,12 +18,12 @@ import { tryDecodeResponse } from '../src/utils/cosmos.js'; test('makeICQConnection returns an ICQConnection', async t => { const { - bootstrap: { orchestration }, + bootstrap: { cosmosInterchainService }, } = await commonSetup(t); const CONTROLLER_CONNECTION_ID = 'connection-0'; - const icqConnection = await E(orchestration).provideICQConnection( + const icqConnection = await E(cosmosInterchainService).provideICQConnection( CONTROLLER_CONNECTION_ID, ); const [localAddr, remoteAddr] = await Promise.all([ @@ -46,7 +46,7 @@ test('makeICQConnection returns an ICQConnection', async t => { 'remote address contains icqhost port, unordered ordering, and icq-1 version string', ); - const icqConnection2 = await E(orchestration).provideICQConnection( + const icqConnection2 = await E(cosmosInterchainService).provideICQConnection( CONTROLLER_CONNECTION_ID, ); const localAddr2 = await E(icqConnection2).getLocalAddress(); @@ -68,14 +68,14 @@ test('makeICQConnection returns an ICQConnection', async t => { test('makeAccount returns a ChainAccount', async t => { const { - bootstrap: { orchestration }, + bootstrap: { cosmosInterchainService }, } = await commonSetup(t); const CHAIN_ID = 'cosmoshub-99'; const HOST_CONNECTION_ID = 'connection-0'; const CONTROLLER_CONNECTION_ID = 'connection-1'; - const account = await E(orchestration).makeAccount( + const account = await E(cosmosInterchainService).makeAccount( CHAIN_ID, HOST_CONNECTION_ID, CONTROLLER_CONNECTION_ID, diff --git a/packages/orchestration/test/supports.ts b/packages/orchestration/test/supports.ts index d3e1c59f706..9755d221f0e 100644 --- a/packages/orchestration/test/supports.ts +++ b/packages/orchestration/test/supports.ts @@ -113,11 +113,13 @@ export const commonSetup = async (t: ExecutionContext) => { ); await setupIBCProtocol(); - const makeOrchestrationKit = prepareCosmosInterchainService( + const makeCosmosInterchainService = prepareCosmosInterchainService( rootZone.subZone('orchestration'), vowTools, ); - const orchestration = makeOrchestrationKit({ portAllocator }); + const cosmosInterchainService = makeCosmosInterchainService({ + portAllocator, + }); await registerChainNamespace(agoricNamesAdmin, () => {}); @@ -129,7 +131,7 @@ export const commonSetup = async (t: ExecutionContext) => { timer, localchain, marshaller, - orchestration, + cosmosInterchainService, // TODO remove; bootstrap doesn't have a zone rootZone: rootZone.subZone('contract'), storage, @@ -143,7 +145,7 @@ export const commonSetup = async (t: ExecutionContext) => { commonPrivateArgs: { agoricNames, localchain, - orchestrationService: orchestration, + orchestrationService: cosmosInterchainService, storageNode: storage.rootNode, marshaller, timerService: timer, @@ -151,7 +153,7 @@ export const commonSetup = async (t: ExecutionContext) => { facadeServices: { agoricNames, localchain, - orchestrationService: orchestration, + orchestrationService: cosmosInterchainService, timerService: timer, }, utils: {