@agoric/orchestration 0.1.1-dev-989aa19.0 → 0.1.1-dev-9274bc7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/package.json +18 -16
  2. package/src/chain-info.js +1 -1
  3. package/src/examples/stakeBld.contract.d.ts +10 -20
  4. package/src/examples/stakeBld.contract.d.ts.map +1 -1
  5. package/src/examples/stakeBld.contract.js +4 -2
  6. package/src/examples/stakeIca.contract.d.ts +9 -9
  7. package/src/examples/stakeIca.contract.d.ts.map +1 -1
  8. package/src/examples/stakeIca.contract.js +4 -1
  9. package/src/exos/chain-account-kit.d.ts +10 -1
  10. package/src/exos/chain-account-kit.d.ts.map +1 -1
  11. package/src/exos/chain-account-kit.js +35 -13
  12. package/src/exos/chain-hub.d.ts +2392 -0
  13. package/src/{utils/chainHub.d.ts.map → exos/chain-hub.d.ts.map} +1 -1
  14. package/src/{utils/chainHub.js → exos/chain-hub.js} +69 -9
  15. package/src/exos/cosmos-orchestration-account.d.ts +50 -15
  16. package/src/exos/cosmos-orchestration-account.d.ts.map +1 -1
  17. package/src/exos/cosmos-orchestration-account.js +113 -57
  18. package/src/exos/icq-connection-kit.d.ts +10 -1
  19. package/src/exos/icq-connection-kit.d.ts.map +1 -1
  20. package/src/exos/icq-connection-kit.js +27 -11
  21. package/src/exos/local-chain-facade.d.ts +46 -9
  22. package/src/exos/local-chain-facade.d.ts.map +1 -1
  23. package/src/exos/local-chain-facade.js +1 -1
  24. package/src/exos/local-orchestration-account.d.ts +115 -2343
  25. package/src/exos/local-orchestration-account.d.ts.map +1 -1
  26. package/src/exos/local-orchestration-account.js +185 -56
  27. package/src/exos/orchestrator.d.ts +9 -2313
  28. package/src/exos/orchestrator.d.ts.map +1 -1
  29. package/src/exos/orchestrator.js +1 -1
  30. package/src/exos/remote-chain-facade.d.ts +6 -6
  31. package/src/facade.d.ts +48 -11
  32. package/src/facade.d.ts.map +1 -1
  33. package/src/facade.js +2 -2
  34. package/src/proposals/orchestration-proposal.d.ts +36 -6
  35. package/src/proposals/orchestration-proposal.js +1 -1
  36. package/src/proposals/start-stakeAtom.d.ts +9 -9
  37. package/src/proposals/start-stakeAtom.d.ts.map +1 -1
  38. package/src/proposals/start-stakeAtom.js +5 -6
  39. package/src/proposals/start-stakeBld.d.ts +10 -20
  40. package/src/proposals/start-stakeBld.d.ts.map +1 -1
  41. package/src/proposals/start-stakeOsmo.d.ts +9 -9
  42. package/src/proposals/start-stakeOsmo.d.ts.map +1 -1
  43. package/src/proposals/start-stakeOsmo.js +5 -6
  44. package/src/service.d.ts +92 -9
  45. package/src/service.d.ts.map +1 -1
  46. package/src/service.js +143 -66
  47. package/src/utils/start-helper.d.ts +8 -2320
  48. package/src/utils/start-helper.d.ts.map +1 -1
  49. package/src/utils/start-helper.js +5 -2
  50. package/src/utils/time.d.ts +2 -0
  51. package/src/utils/time.d.ts.map +1 -1
  52. package/src/utils/time.js +2 -0
  53. package/src/vat-orchestration.d.ts +36 -6
  54. package/src/vat-orchestration.d.ts.map +1 -1
  55. package/src/vat-orchestration.js +3 -0
  56. package/src/utils/chainHub.d.ts +0 -2404
package/src/service.d.ts CHANGED
@@ -1,12 +1,55 @@
1
- export const OrchestrationI: import("@endo/patterns").InterfaceGuard<{
2
- makeAccount: import("@endo/patterns").MethodGuard;
3
- provideICQConnection: import("@endo/patterns").MethodGuard;
4
- }>;
5
- export function prepareOrchestrationTools(zone: Zone): {
1
+ export function prepareOrchestrationTools(zone: Zone, vowTools: {
2
+ when: <T, TResult1 = import("@agoric/vow").EUnwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow").EUnwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
3
+ watch: <T_1 = any, TResult1_1 = T_1, TResult2_1 = never, C = any>(specimenP: import("@agoric/vow").ERef<T_1 | import("@agoric/vow").Vow<T_1>>, watcher?: import("@agoric/vow").Watcher<T_1, TResult1_1, TResult2_1> | undefined, watcherContext?: C | undefined) => import("@agoric/vow").Vow<Exclude<TResult1_1, void> | Exclude<TResult2_1, void> extends never ? TResult1_1 : Exclude<TResult1_1, void> | Exclude<TResult2_1, void>>;
4
+ makeVowKit: <T_2>() => import("@agoric/vow").VowKit<T_2>;
5
+ allVows: (vows: unknown[]) => import("@agoric/vow").Vow<any[]>;
6
+ }): {
6
7
  makeOrchestrationKit: (initialPowers?: Partial<OrchestrationPowers> | undefined) => import("@endo/exo").GuardedKit<{
7
- self: {
8
- allocateICAControllerPort(): Promise<Port>;
9
- allocateICQControllerPort(): Promise<Port>;
8
+ requestICAChannelWatcher: {
9
+ /**
10
+ * @param {Port} port
11
+ * @param {{
12
+ * chainId: string;
13
+ * remoteConnAddr: RemoteIbcAddress;
14
+ * }} watchContext
15
+ */
16
+ onFulfilled(port: Port, { chainId, remoteConnAddr }: {
17
+ chainId: string;
18
+ remoteConnAddr: `/${string}ibc-port/${string}/ordered/${string}` | `/${string}ibc-port/${string}/unordered/${string}`;
19
+ }): import("@agoric/vow").Vow<any>;
20
+ };
21
+ requestICQChannelWatcher: {
22
+ /**
23
+ * @param {Port} port
24
+ * @param {{
25
+ * remoteConnAddr: RemoteIbcAddress;
26
+ * controllerConnectionId: IBCConnectionID;
27
+ * }} watchContext
28
+ */
29
+ onFulfilled(port: Port, { remoteConnAddr, controllerConnectionId }: {
30
+ remoteConnAddr: `/${string}ibc-port/${string}/ordered/${string}` | `/${string}ibc-port/${string}/unordered/${string}`;
31
+ controllerConnectionId: `connection-${number}`;
32
+ }): import("@agoric/vow").Vow<any>;
33
+ };
34
+ /**
35
+ * Waits for a channel (ICA, ICQ) to open and returns the consumer-facing
36
+ * facet of the ConnectionKit, specified by `returnFacet`. Saves the
37
+ * ConnectionKit if `saveICQConnection` is provided.
38
+ */
39
+ channelOpenWatcher: {
40
+ /**
41
+ * @param {Connection} _connection
42
+ * @param {{
43
+ * connectionKit: ConnectionKit;
44
+ * returnFacet: string;
45
+ * saveICQConnection?: IBCConnectionID;
46
+ * }} watchContext
47
+ */
48
+ onFulfilled(_connection: Connection, { connectionKit, returnFacet, saveICQConnection }: {
49
+ connectionKit: ConnectionKit;
50
+ returnFacet: string;
51
+ saveICQConnection?: `connection-${number}` | undefined;
52
+ }): any;
10
53
  };
11
54
  public: {
12
55
  /**
@@ -49,12 +92,51 @@ export type ICQConnectionStore = import("@endo/pass-style").RemotableObject & im
49
92
  getRemoteAddress(): `/${string}ibc-port/${string}/ordered/${string}` | `/${string}ibc-port/${string}/unordered/${string}`;
50
93
  query(msgs: import("@agoric/cosmic-proto").JsonSafe<import("@agoric/cosmic-proto/tendermint/abci/types.js").RequestQuery>[]): Promise<import("@agoric/cosmic-proto").JsonSafe<import("@agoric/cosmic-proto/tendermint/abci/types.js").ResponseQuery>[]>;
51
94
  };
95
+ parseQueryPacketWatcher: {
96
+ onFulfilled(ack: string): import("@agoric/cosmic-proto").JsonSafe<import("@agoric/cosmic-proto/tendermint/abci/types.js").ResponseQuery>[];
97
+ };
52
98
  connectionHandler: {
53
- onOpen(connection: Remote<import("@agoric/network").Connection>, localAddr: `/ibc-port/${string}`, remoteAddr: `/${string}ibc-port/${string}/ordered/${string}` | `/${string}ibc-port/${string}/unordered/${string}`): Promise<void>;
99
+ onOpen(connection: Remote<Connection>, localAddr: `/ibc-port/${string}`, remoteAddr: `/${string}ibc-port/${string}/ordered/${string}` | `/${string}ibc-port/${string}/unordered/${string}`): Promise<void>;
54
100
  onClose(_connection: any, reason: any): Promise<void>;
55
101
  onReceive(connection: any, bytes: any): Promise<string>;
56
102
  };
57
103
  }>>;
104
+ export type ConnectionKit = import("@endo/exo").GuardedKit<{
105
+ connection: {
106
+ getLocalAddress(): `/ibc-port/${string}`;
107
+ getRemoteAddress(): `/${string}ibc-port/${string}/ordered/${string}` | `/${string}ibc-port/${string}/unordered/${string}`;
108
+ query(msgs: import("@agoric/cosmic-proto").JsonSafe<import("@agoric/cosmic-proto/tendermint/abci/types.js").RequestQuery>[]): Promise<import("@agoric/cosmic-proto").JsonSafe<import("@agoric/cosmic-proto/tendermint/abci/types.js").ResponseQuery>[]>;
109
+ };
110
+ parseQueryPacketWatcher: {
111
+ onFulfilled(ack: string): import("@agoric/cosmic-proto").JsonSafe<import("@agoric/cosmic-proto/tendermint/abci/types.js").ResponseQuery>[];
112
+ };
113
+ connectionHandler: {
114
+ onOpen(connection: Remote<Connection>, localAddr: `/ibc-port/${string}`, remoteAddr: `/${string}ibc-port/${string}/ordered/${string}` | `/${string}ibc-port/${string}/unordered/${string}`): Promise<void>;
115
+ onClose(_connection: any, reason: any): Promise<void>;
116
+ onReceive(connection: any, bytes: any): Promise<string>;
117
+ };
118
+ }> | import("@endo/exo").GuardedKit<{
119
+ parseTxPacketWatcher: {
120
+ onFulfilled(ack: string): string;
121
+ };
122
+ account: {
123
+ getAddress(): import("./orchestration-api.js").ChainAddress;
124
+ getBalance(_denom: any): never;
125
+ getBalances(): never;
126
+ getLocalAddress(): `/ibc-port/${string}`;
127
+ getRemoteAddress(): `/${string}ibc-port/${string}/ordered/${string}` | `/${string}ibc-port/${string}/unordered/${string}`;
128
+ getPort(): Port;
129
+ executeTx(): never;
130
+ executeEncodedTx(msgs: import("@agoric/cosmic-proto").JsonSafe<import("@agoric/cosmic-proto/google/protobuf/any.js").Any>[], opts?: Omit<import("@agoric/cosmic-proto/cosmos/tx/v1beta1/tx.js").TxBody, "messages"> | undefined): Promise<string>;
131
+ close(): Promise<void>;
132
+ getPurse(brand: Brand): Promise<never>;
133
+ };
134
+ connectionHandler: {
135
+ onOpen(connection: Remote<Connection>, localAddr: `/ibc-port/${string}`, remoteAddr: `/${string}ibc-port/${string}/ordered/${string}` | `/${string}ibc-port/${string}/unordered/${string}`): Promise<void>;
136
+ onClose(_connection: any, reason: any): Promise<void>;
137
+ onReceive(connection: any, bytes: any): Promise<string>;
138
+ };
139
+ }>;
58
140
  export type OrchestrationState = {
59
141
  powers: PowerStore;
60
142
  icqConnections: ICQConnectionStore;
@@ -64,6 +146,7 @@ export type OrchestrationKit = ReturnType<OrchestrationTools["makeOrchestrationK
64
146
  export type OrchestrationService = OrchestrationKit["public"];
65
147
  import type { Zone } from '@agoric/base-zone';
66
148
  import type { Port } from '@agoric/network';
149
+ import type { Connection } from '@agoric/network';
67
150
  import type { IcaAccount } from './types.js';
68
151
  import type { Remote } from '@agoric/internal';
69
152
  //# sourceMappingURL=service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["service.js"],"names":[],"mappings":"AAoDA;;;GAOG;AAgHI;;;;;;;YA7DC;;;;;;eAMG;iCALQ,MAAM;YA2BjB;;;eAGG;;;;;;;;EAwCV;;;;;;;;;;;;;;yBArJY,QAAQ,CACpB,MAAU,mBAAmB,EAC7B,mBAAuB,CAAC,MAAM,mBAAmB,CAAC,CAC/C;;;;;;;;;;;;;iCA0BU;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,cAAc,EAAE,kBAAkB,CAAA;CAAE;iCA2H1D,UAAU,CAAC,OAAO,yBAAyB,CAAC;+BAC5C,UAAU,CAAC,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;mCACtD,gBAAgB,CAAC,QAAQ,CAAC;0BA7KjB,mBAAmB;0BAEJ,iBAAiB;gCAEO,YAAY;4BAHjD,kBAAkB"}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["service.js"],"names":[],"mappings":"AAuPO;wFAzOkB,CAAC;;;oBAYzB,SAAS;;;;YA2FF;;;;;;eAMG;;yBAHW,MAAM;;;;;YAkBpB;;;;;;eAMG;;;;;;QAeL;;;;WAIG;;YAED;;;;;;;eAOG;;+BAJiB,aAAa;6BACf,MAAM;;;;;YAoBxB;;;;;;eAMG;iCALQ,MAAM;YAuBjB;;;eAGG;;;;;;;;EA0CV;;;;;;;;;;;;;;yBAhOY,QAAQ,CACpB,MAAU,mBAAmB,EAC7B,mBAAuB,CAAC,MAAM,mBAAmB,CAAC,CAC/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkIU,KAAK;;;;;;;;iCAjHL;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,cAAc,EAAE,kBAAkB,CAAA;CAAE;iCA+M1D,UAAU,CAAC,OAAO,yBAAyB,CAAC;+BAC5C,UAAU,CAAC,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;mCACtD,gBAAgB,CAAC,QAAQ,CAAC;0BA1PjB,mBAAmB;0BAEQ,iBAAiB;gCAAjB,iBAAiB;gCAIY,YAAY;4BALlE,kBAAkB"}
package/src/service.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /** @file Orchestration service */
2
2
 
3
- import { V as E } from '@agoric/vow/vat.js';
3
+ import { E } from '@endo/far';
4
4
  import { M } from '@endo/patterns';
5
5
  import { Shape as NetworkShape } from '@agoric/network';
6
6
  import { prepareChainAccountKit } from './exos/chain-account-kit.js';
@@ -13,9 +13,11 @@ import {
13
13
  /**
14
14
  * @import {Zone} from '@agoric/base-zone';
15
15
  * @import {Remote} from '@agoric/internal';
16
- * @import {Port, PortAllocator} from '@agoric/network';
16
+ * @import {Connection, Port, PortAllocator} from '@agoric/network';
17
17
  * @import {IBCConnectionID} from '@agoric/vats';
18
- * @import {ICQConnection, IcaAccount, ICQConnectionKit} from './types.js';
18
+ * @import {RemoteIbcAddress} from '@agoric/vats/tools/ibc-utils.js';
19
+ * @import {VowTools} from '@agoric/vow';
20
+ * @import {ICQConnection, IcaAccount, ICQConnectionKit, ChainAccountKit} from './types.js';
19
21
  */
20
22
 
21
23
  const { Fail, bare } = assert;
@@ -36,9 +38,9 @@ const { Fail, bare } = assert;
36
38
  * >} PowerStore
37
39
  */
38
40
 
39
- /**
40
- * @typedef {MapStore<IBCConnectionID, ICQConnectionKit>} ICQConnectionStore
41
- */
41
+ /** @typedef {MapStore<IBCConnectionID, ICQConnectionKit>} ICQConnectionStore */
42
+
43
+ /** @typedef {ChainAccountKit | ICQConnectionKit} ConnectionKit */
42
44
 
43
45
  /**
44
46
  * @template {keyof OrchestrationPowers} K
@@ -50,39 +52,54 @@ const getPower = (powers, name) => {
50
52
  return /** @type {OrchestrationPowers[K]} */ (powers.get(name));
51
53
  };
52
54
 
53
- export const OrchestrationI = M.interface('Orchestration', {
54
- makeAccount: M.callWhen(M.string(), M.string(), M.string()).returns(
55
- M.remotable('ChainAccount'),
56
- ),
57
- provideICQConnection: M.callWhen(M.string()).returns(
58
- M.remotable('Connection'),
59
- ),
60
- });
61
-
62
55
  /** @typedef {{ powers: PowerStore; icqConnections: ICQConnectionStore }} OrchestrationState */
63
56
 
64
57
  /**
65
58
  * @param {Zone} zone
59
+ * @param {VowTools} vowTools
66
60
  * @param {ReturnType<typeof prepareChainAccountKit>} makeChainAccountKit
67
61
  * @param {ReturnType<typeof prepareICQConnectionKit>} makeICQConnectionKit
68
62
  */
69
63
  const prepareOrchestrationKit = (
70
64
  zone,
65
+ { when, watch },
71
66
  makeChainAccountKit,
72
67
  makeICQConnectionKit,
73
68
  ) =>
74
69
  zone.exoClassKit(
75
70
  'Orchestration',
76
71
  {
77
- self: M.interface('OrchestrationSelf', {
78
- allocateICAControllerPort: M.callWhen().returns(
79
- NetworkShape.Vow$(NetworkShape.Port),
72
+ requestICAChannelWatcher: M.interface('RequestICAChannelWatcher', {
73
+ onFulfilled: M.call(M.remotable('Port'))
74
+ .optional({ chainId: M.string(), remoteConnAddr: M.string() })
75
+ .returns(NetworkShape.Vow$(NetworkShape.Connection)),
76
+ }),
77
+ requestICQChannelWatcher: M.interface('RequestICQChannelWatcher', {
78
+ onFulfilled: M.call(M.remotable('Port'))
79
+ .optional({
80
+ remoteConnAddr: M.string(),
81
+ controllerConnectionId: M.string(),
82
+ })
83
+ .returns(NetworkShape.Vow$(NetworkShape.Connection)),
84
+ }),
85
+ channelOpenWatcher: M.interface('ChannelOpenWatcher', {
86
+ onFulfilled: M.call(M.remotable('Connection'))
87
+ .optional(
88
+ M.splitRecord(
89
+ { connectionKit: M.record(), returnFacet: M.string() },
90
+ { saveICQConnection: M.string() },
91
+ ),
92
+ )
93
+ .returns(M.remotable('ConnectionKit Holder facet')),
94
+ }),
95
+ public: M.interface('OrchestrationService', {
96
+ makeAccount: M.callWhen(M.string(), M.string(), M.string()).returns(
97
+ M.remotable('ChainAccountKit'),
80
98
  ),
81
- allocateICQControllerPort: M.callWhen().returns(
82
- NetworkShape.Vow$(NetworkShape.Port),
99
+ provideICQConnection: M.callWhen(M.string()).returns(
100
+ M.remotable('ICQConnection'),
83
101
  ),
84
102
  }),
85
- public: OrchestrationI,
86
103
  },
87
104
  /** @param {Partial<OrchestrationPowers>} [initialPowers] */
88
105
  initialPowers => {
@@ -97,16 +114,78 @@ const prepareOrchestrationKit = (
97
114
  return /** @type {OrchestrationState} */ ({ powers, icqConnections });
98
115
  },
99
116
  {
100
- self: {
101
- async allocateICAControllerPort() {
102
- const portAllocator = getPower(this.state.powers, 'portAllocator');
103
- return E(portAllocator).allocateICAControllerPort();
117
+ requestICAChannelWatcher: {
118
+ /**
119
+ * @param {Port} port
120
+ * @param {{
121
+ * chainId: string;
122
+ * remoteConnAddr: RemoteIbcAddress;
123
+ * }} watchContext
124
+ */
125
+ onFulfilled(port, { chainId, remoteConnAddr }) {
126
+ const chainAccountKit = makeChainAccountKit(
127
+ chainId,
128
+ port,
129
+ remoteConnAddr,
130
+ );
131
+ return watch(
132
+ E(port).connect(remoteConnAddr, chainAccountKit.connectionHandler),
133
+ this.facets.channelOpenWatcher,
134
+ { returnFacet: 'account', connectionKit: chainAccountKit },
135
+ );
104
136
  },
105
- async allocateICQControllerPort() {
106
- const portAllocator = getPower(this.state.powers, 'portAllocator');
107
- return E(portAllocator).allocateICAControllerPort();
137
+ },
138
+ requestICQChannelWatcher: {
139
+ /**
140
+ * @param {Port} port
141
+ * @param {{
142
+ * remoteConnAddr: RemoteIbcAddress;
143
+ * controllerConnectionId: IBCConnectionID;
144
+ * }} watchContext
145
+ */
146
+ onFulfilled(port, { remoteConnAddr, controllerConnectionId }) {
147
+ const connectionKit = makeICQConnectionKit(port);
148
+ /** @param {ICQConnectionKit} kit */
149
+ return watch(
150
+ E(port).connect(remoteConnAddr, connectionKit.connectionHandler),
151
+ this.facets.channelOpenWatcher,
152
+ {
153
+ connectionKit,
154
+ returnFacet: 'connection',
155
+ saveICQConnection: controllerConnectionId,
156
+ },
157
+ );
108
158
  },
109
159
  },
160
+ /**
161
+ * Waits for a channel (ICA, ICQ) to open and returns the consumer-facing
162
+ * facet of the ConnectionKit, specified by `returnFacet`. Saves the
163
+ * ConnectionKit if `saveICQConnection` is provided.
164
+ */
165
+ channelOpenWatcher: {
166
+ /**
167
+ * @param {Connection} _connection
168
+ * @param {{
169
+ * connectionKit: ConnectionKit;
170
+ * returnFacet: string;
171
+ * saveICQConnection?: IBCConnectionID;
172
+ * }} watchContext
173
+ */
174
+ onFulfilled(
175
+ _connection,
176
+ { connectionKit, returnFacet, saveICQConnection },
177
+ ) {
178
+ if (saveICQConnection) {
179
+ this.state.icqConnections.init(
180
+ saveICQConnection,
181
+ /** @type {ICQConnectionKit} */ (connectionKit),
182
+ );
183
+ }
184
+ return connectionKit[returnFacet];
185
+ },
186
+ // TODO #9317 if we fail, should we revoke the port (if it was created in this flow)?
187
+ // onRejected() {}
188
+ },
110
189
  public: {
111
190
  /**
112
191
  * @param {string} chainId
@@ -115,65 +194,63 @@ const prepareOrchestrationKit = (
115
194
  * @param {IBCConnectionID} controllerConnectionId self connection_id
116
195
  * @returns {Promise<IcaAccount>}
117
196
  */
118
- async makeAccount(chainId, hostConnectionId, controllerConnectionId) {
119
- const port = await this.facets.self.allocateICAControllerPort();
120
-
197
+ makeAccount(chainId, hostConnectionId, controllerConnectionId) {
121
198
  const remoteConnAddr = makeICAChannelAddress(
122
199
  hostConnectionId,
123
200
  controllerConnectionId,
124
201
  );
125
- const chainAccountKit = makeChainAccountKit(
126
- chainId,
127
- port,
128
- remoteConnAddr,
129
- );
130
-
131
- // await so we do not return a ChainAccount before it successfully instantiates
132
- await E(port).connect(
133
- remoteConnAddr,
134
- chainAccountKit.connectionHandler,
202
+ const portAllocator = getPower(this.state.powers, 'portAllocator');
203
+ return when(
204
+ watch(
205
+ E(portAllocator).allocateICAControllerPort(),
206
+ this.facets.requestICAChannelWatcher,
207
+ {
208
+ chainId,
209
+ remoteConnAddr,
210
+ },
211
+ ),
135
212
  );
136
- // FIXME if we fail, should we close the port (if it was created in this flow)?
137
- return chainAccountKit.account;
138
213
  },
139
214
  /**
140
215
  * @param {IBCConnectionID} controllerConnectionId
141
216
  * @returns {Promise<ICQConnection>}
142
217
  */
143
- async provideICQConnection(controllerConnectionId) {
218
+ provideICQConnection(controllerConnectionId) {
144
219
  if (this.state.icqConnections.has(controllerConnectionId)) {
145
- return this.state.icqConnections.get(controllerConnectionId)
146
- .connection;
220
+ // TODO #9281 do not return synchronously. see https://github.com/Agoric/agoric-sdk/pull/9454#discussion_r1626898694
221
+ return when(
222
+ this.state.icqConnections.get(controllerConnectionId).connection,
223
+ );
147
224
  }
148
- // allocate a new Port for every Connection
149
- // TODO #9317 optimize ICQ port allocation
150
- const port = await this.facets.self.allocateICQControllerPort();
151
225
  const remoteConnAddr = makeICQChannelAddress(controllerConnectionId);
152
- const icqConnectionKit = makeICQConnectionKit(port);
153
-
154
- // await so we do not return/save a ICQConnection before it successfully instantiates
155
- await E(port).connect(
156
- remoteConnAddr,
157
- icqConnectionKit.connectionHandler,
158
- );
159
-
160
- this.state.icqConnections.init(
161
- controllerConnectionId,
162
- icqConnectionKit,
226
+ const portAllocator = getPower(this.state.powers, 'portAllocator');
227
+ return when(
228
+ watch(
229
+ // allocate a new Port for every Connection
230
+ // TODO #9317 optimize ICQ port allocation
231
+ E(portAllocator).allocateICQControllerPort(),
232
+ this.facets.requestICQChannelWatcher,
233
+ {
234
+ remoteConnAddr,
235
+ controllerConnectionId,
236
+ },
237
+ ),
163
238
  );
164
-
165
- return icqConnectionKit.connection;
166
239
  },
167
240
  },
168
241
  },
169
242
  );
170
243
 
171
- /** @param {Zone} zone */
172
- export const prepareOrchestrationTools = zone => {
173
- const makeChainAccountKit = prepareChainAccountKit(zone);
174
- const makeICQConnectionKit = prepareICQConnectionKit(zone);
244
+ /**
245
+ * @param {Zone} zone
246
+ * @param {VowTools} vowTools
247
+ */
248
+ export const prepareOrchestrationTools = (zone, vowTools) => {
249
+ const makeChainAccountKit = prepareChainAccountKit(zone, vowTools);
250
+ const makeICQConnectionKit = prepareICQConnectionKit(zone, vowTools);
175
251
  const makeOrchestrationKit = prepareOrchestrationKit(
176
252
  zone,
253
+ vowTools,
177
254
  makeChainAccountKit,
178
255
  makeICQConnectionKit,
179
256
  );