@agoric/orchestration 0.1.1-calypso-dev-84eb287.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 (120) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +5 -0
  3. package/index.d.ts +4 -0
  4. package/index.js +7 -0
  5. package/package.json +95 -0
  6. package/src/chain-info.d.ts +2318 -0
  7. package/src/chain-info.d.ts.map +1 -0
  8. package/src/chain-info.js +114 -0
  9. package/src/cosmos-api.d.ts +174 -0
  10. package/src/cosmos-api.d.ts.map +1 -0
  11. package/src/cosmos-api.ts +231 -0
  12. package/src/ethereum-api.d.ts +8 -0
  13. package/src/ethereum-api.d.ts.map +1 -0
  14. package/src/ethereum-api.ts +7 -0
  15. package/src/examples/sendAnywhere.contract.d.ts +31 -0
  16. package/src/examples/sendAnywhere.contract.d.ts.map +1 -0
  17. package/src/examples/sendAnywhere.contract.js +171 -0
  18. package/src/examples/stakeBld.contract.d.ts +121 -0
  19. package/src/examples/stakeBld.contract.d.ts.map +1 -0
  20. package/src/examples/stakeBld.contract.js +133 -0
  21. package/src/examples/stakeIca.contract.d.ts +93 -0
  22. package/src/examples/stakeIca.contract.d.ts.map +1 -0
  23. package/src/examples/stakeIca.contract.js +143 -0
  24. package/src/examples/swapExample.contract.d.ts +34 -0
  25. package/src/examples/swapExample.contract.d.ts.map +1 -0
  26. package/src/examples/swapExample.contract.js +155 -0
  27. package/src/examples/unbondExample.contract.d.ts +21 -0
  28. package/src/examples/unbondExample.contract.d.ts.map +1 -0
  29. package/src/examples/unbondExample.contract.js +105 -0
  30. package/src/exos/README.md +56 -0
  31. package/src/exos/agoric-names-tools.d.ts +27 -0
  32. package/src/exos/agoric-names-tools.d.ts.map +1 -0
  33. package/src/exos/agoric-names-tools.js +109 -0
  34. package/src/exos/chain-account-kit.d.ts +88 -0
  35. package/src/exos/chain-account-kit.d.ts.map +1 -0
  36. package/src/exos/chain-account-kit.js +210 -0
  37. package/src/exos/chain-hub.d.ts +77 -0
  38. package/src/exos/chain-hub.d.ts.map +1 -0
  39. package/src/exos/chain-hub.js +214 -0
  40. package/src/exos/cosmos-orchestration-account.d.ts +207 -0
  41. package/src/exos/cosmos-orchestration-account.d.ts.map +1 -0
  42. package/src/exos/cosmos-orchestration-account.js +536 -0
  43. package/src/exos/icq-connection-kit.d.ts +50 -0
  44. package/src/exos/icq-connection-kit.d.ts.map +1 -0
  45. package/src/exos/icq-connection-kit.js +135 -0
  46. package/src/exos/local-chain-facade.d.ts +81 -0
  47. package/src/exos/local-chain-facade.d.ts.map +1 -0
  48. package/src/exos/local-chain-facade.js +113 -0
  49. package/src/exos/local-orchestration-account.d.ts +176 -0
  50. package/src/exos/local-orchestration-account.d.ts.map +1 -0
  51. package/src/exos/local-orchestration-account.js +446 -0
  52. package/src/exos/orchestrator.d.ts +91 -0
  53. package/src/exos/orchestrator.d.ts.map +1 -0
  54. package/src/exos/orchestrator.js +141 -0
  55. package/src/exos/remote-chain-facade.d.ts +144 -0
  56. package/src/exos/remote-chain-facade.d.ts.map +1 -0
  57. package/src/exos/remote-chain-facade.js +145 -0
  58. package/src/facade.d.ts +57 -0
  59. package/src/facade.d.ts.map +1 -0
  60. package/src/facade.js +132 -0
  61. package/src/fetched-chain-info.d.ts +2311 -0
  62. package/src/fetched-chain-info.d.ts.map +1 -0
  63. package/src/fetched-chain-info.js +2288 -0
  64. package/src/internal.d.ts +13 -0
  65. package/src/internal.d.ts.map +1 -0
  66. package/src/internal.ts +20 -0
  67. package/src/orchestration-api.d.ts +158 -0
  68. package/src/orchestration-api.d.ts.map +1 -0
  69. package/src/orchestration-api.ts +201 -0
  70. package/src/proposals/orchestration-proposal.d.ts +53 -0
  71. package/src/proposals/orchestration-proposal.d.ts.map +1 -0
  72. package/src/proposals/orchestration-proposal.js +179 -0
  73. package/src/proposals/revise-chain-info.d.ts +21 -0
  74. package/src/proposals/revise-chain-info.d.ts.map +1 -0
  75. package/src/proposals/revise-chain-info.js +44 -0
  76. package/src/proposals/start-stakeAtom.d.ts +109 -0
  77. package/src/proposals/start-stakeAtom.d.ts.map +1 -0
  78. package/src/proposals/start-stakeAtom.js +105 -0
  79. package/src/proposals/start-stakeBld.d.ts +154 -0
  80. package/src/proposals/start-stakeBld.d.ts.map +1 -0
  81. package/src/proposals/start-stakeBld.js +103 -0
  82. package/src/proposals/start-stakeOsmo.d.ts +108 -0
  83. package/src/proposals/start-stakeOsmo.d.ts.map +1 -0
  84. package/src/proposals/start-stakeOsmo.js +106 -0
  85. package/src/service.d.ts +97 -0
  86. package/src/service.d.ts.map +1 -0
  87. package/src/service.js +259 -0
  88. package/src/typeGuards.d.ts +55 -0
  89. package/src/typeGuards.d.ts.map +1 -0
  90. package/src/typeGuards.js +104 -0
  91. package/src/types.d.ts +11 -0
  92. package/src/types.d.ts.map +1 -0
  93. package/src/types.ts +11 -0
  94. package/src/utils/address.d.ts +14 -0
  95. package/src/utils/address.d.ts.map +1 -0
  96. package/src/utils/address.js +79 -0
  97. package/src/utils/cosmos.d.ts +9 -0
  98. package/src/utils/cosmos.d.ts.map +1 -0
  99. package/src/utils/cosmos.js +36 -0
  100. package/src/utils/orc.d.ts +17 -0
  101. package/src/utils/orc.d.ts.map +1 -0
  102. package/src/utils/orc.js +38 -0
  103. package/src/utils/orchestrationAccount.d.ts +10 -0
  104. package/src/utils/orchestrationAccount.d.ts.map +1 -0
  105. package/src/utils/orchestrationAccount.js +22 -0
  106. package/src/utils/packet.d.ts +57 -0
  107. package/src/utils/packet.d.ts.map +1 -0
  108. package/src/utils/packet.js +112 -0
  109. package/src/utils/registry.d.ts +13 -0
  110. package/src/utils/registry.d.ts.map +1 -0
  111. package/src/utils/registry.js +131 -0
  112. package/src/utils/start-helper.d.ts +51 -0
  113. package/src/utils/start-helper.d.ts.map +1 -0
  114. package/src/utils/start-helper.js +109 -0
  115. package/src/utils/time.d.ts +31 -0
  116. package/src/utils/time.d.ts.map +1 -0
  117. package/src/utils/time.js +63 -0
  118. package/src/vat-orchestration.d.ts +58 -0
  119. package/src/vat-orchestration.d.ts.map +1 -0
  120. package/src/vat-orchestration.js +24 -0
@@ -0,0 +1,446 @@
1
+ /** @file Use-object for the owner of a localchain account */
2
+ import { typedJson } from '@agoric/cosmic-proto/vatsafe';
3
+ import { AmountShape, PaymentShape } from '@agoric/ertp';
4
+ import { makeTracer } from '@agoric/internal';
5
+ import { Shape as NetworkShape } from '@agoric/network';
6
+ import { M } from '@agoric/vat-data';
7
+ import { VowShape } from '@agoric/vow';
8
+ import { TopicsRecordShape } from '@agoric/zoe/src/contractSupport/index.js';
9
+ import { E } from '@endo/far';
10
+ import {
11
+ ChainAddressShape,
12
+ ChainAmountShape,
13
+ DenomAmountShape,
14
+ DenomShape,
15
+ IBCTransferOptionsShape,
16
+ } from '../typeGuards.js';
17
+ import { maxClockSkew } from '../utils/cosmos.js';
18
+ import { orchestrationAccountMethods } from '../utils/orchestrationAccount.js';
19
+ import { dateInSeconds, makeTimestampHelper } from '../utils/time.js';
20
+
21
+ /**
22
+ * @import {LocalChainAccount} from '@agoric/vats/src/localchain.js';
23
+ * @import {AmountArg, ChainAddress, DenomAmount, IBCMsgTransferOptions, OrchestrationAccount, ChainInfo, IBCConnectionInfo, PromiseToVow} from '@agoric/orchestration';
24
+ * @import {RecorderKit, MakeRecorderKit} from '@agoric/zoe/src/contractSupport/recorder.js'.
25
+ * @import {Zone} from '@agoric/zone';
26
+ * @import {Remote} from '@agoric/internal';
27
+ * @import {TimerService, TimerBrand, TimestampRecord} from '@agoric/time';
28
+ * @import {PromiseVow, Vow, VowTools} from '@agoric/vow';
29
+ * @import {TypedJson, JsonSafe} from '@agoric/cosmic-proto';
30
+ * @import {ChainHub} from './chain-hub.js';
31
+ */
32
+
33
+ const trace = makeTracer('LOA');
34
+
35
+ const { Fail } = assert;
36
+ const { Vow$ } = NetworkShape; // TODO #9611
37
+
38
+ /**
39
+ * @typedef {object} LocalChainAccountNotification
40
+ * @property {string} address
41
+ */
42
+
43
+ /**
44
+ * @typedef {{
45
+ * topicKit: RecorderKit<LocalChainAccountNotification>;
46
+ * account: LocalChainAccount;
47
+ * address: ChainAddress;
48
+ * }} State
49
+ */
50
+
51
+ const HolderI = M.interface('holder', {
52
+ ...orchestrationAccountMethods,
53
+ getPublicTopics: M.call().returns(TopicsRecordShape),
54
+ delegate: M.call(M.string(), AmountShape).returns(VowShape),
55
+ undelegate: M.call(M.string(), AmountShape).returns(VowShape),
56
+ withdraw: M.call(AmountShape).returns(Vow$(PaymentShape)),
57
+ executeTx: M.call(M.arrayOf(M.record())).returns(Vow$(M.record())),
58
+ });
59
+
60
+ /** @type {{ [name: string]: [description: string, valueShape: Pattern] }} */
61
+ const PUBLIC_TOPICS = {
62
+ account: ['Account holder status', M.any()],
63
+ };
64
+
65
+ /**
66
+ * @param {Zone} zone
67
+ * @param {MakeRecorderKit} makeRecorderKit
68
+ * @param {ZCF} zcf
69
+ * @param {Remote<TimerService>} timerService
70
+ * @param {VowTools} vowTools
71
+ * @param {ChainHub} chainHub
72
+ */
73
+ export const prepareLocalOrchestrationAccountKit = (
74
+ zone,
75
+ makeRecorderKit,
76
+ zcf,
77
+ timerService,
78
+ { watch, allVows, asVow },
79
+ chainHub,
80
+ ) => {
81
+ const timestampHelper = makeTimestampHelper(timerService);
82
+
83
+ /** Make an object wrapping an LCA with Zoe interfaces. */
84
+ const makeLocalOrchestrationAccountKit = zone.exoClassKit(
85
+ 'Local Orchestration Account Kit',
86
+ {
87
+ holder: HolderI,
88
+ undelegateWatcher: M.interface('undelegateWatcher', {
89
+ onFulfilled: M.call([M.splitRecord({ completionTime: M.string() })])
90
+ .optional(M.arrayOf(M.undefined())) // empty context
91
+ .returns(VowShape),
92
+ }),
93
+ getChainInfoWatcher: M.interface('getChainInfoWatcher', {
94
+ onFulfilled: M.call(M.record()) // agoric chain info
95
+ .optional(ChainAddressShape)
96
+ .returns(Vow$(M.record())), // connection info
97
+ }),
98
+ transferWatcher: M.interface('transferWatcher', {
99
+ onFulfilled: M.call([M.record(), M.nat()])
100
+ .optional({
101
+ destination: ChainAddressShape,
102
+ opts: M.or(M.undefined(), IBCTransferOptionsShape),
103
+ amount: ChainAmountShape,
104
+ })
105
+ .returns(Vow$(M.record())),
106
+ }),
107
+ extractFirstResultWatcher: M.interface('extractFirstResultWatcher', {
108
+ onFulfilled: M.call([M.record()])
109
+ .optional(M.arrayOf(M.undefined()))
110
+ .returns(M.any()),
111
+ }),
112
+ returnVoidWatcher: M.interface('returnVoidWatcher', {
113
+ onFulfilled: M.call(M.any())
114
+ .optional(M.arrayOf(M.undefined()))
115
+ .returns(M.undefined()),
116
+ }),
117
+ getBalanceWatcher: M.interface('getBalanceWatcher', {
118
+ onFulfilled: M.call(AmountShape)
119
+ .optional(DenomShape)
120
+ .returns(DenomAmountShape),
121
+ }),
122
+ invitationMakers: M.interface('invitationMakers', {
123
+ Delegate: M.call(M.string(), AmountShape).returns(M.promise()),
124
+ Undelegate: M.call(M.string(), AmountShape).returns(M.promise()),
125
+ CloseAccount: M.call().returns(M.promise()),
126
+ }),
127
+ },
128
+ /**
129
+ * @param {object} initState
130
+ * @param {LocalChainAccount} initState.account
131
+ * @param {ChainAddress} initState.address
132
+ * @param {Remote<StorageNode>} initState.storageNode
133
+ * @returns {State}
134
+ */
135
+ ({ account, address, storageNode }) => {
136
+ // must be the fully synchronous maker because the kit is held in durable state
137
+ // @ts-expect-error XXX Patterns
138
+ const topicKit = makeRecorderKit(storageNode, PUBLIC_TOPICS.account[1]);
139
+
140
+ return { account, address, topicKit };
141
+ },
142
+ {
143
+ invitationMakers: {
144
+ /**
145
+ * @param {string} validatorAddress
146
+ * @param {Amount<'nat'>} ertpAmount
147
+ */
148
+ Delegate(validatorAddress, ertpAmount) {
149
+ trace('Delegate', validatorAddress, ertpAmount);
150
+
151
+ return zcf.makeInvitation(seat => {
152
+ seat.exit();
153
+ return watch(
154
+ this.facets.holder.delegate(validatorAddress, ertpAmount),
155
+ );
156
+ }, 'Delegate');
157
+ },
158
+ /**
159
+ * @param {string} validatorAddress
160
+ * @param {Amount<'nat'>} ertpAmount
161
+ */
162
+ Undelegate(validatorAddress, ertpAmount) {
163
+ trace('Undelegate', validatorAddress, ertpAmount);
164
+
165
+ return zcf.makeInvitation(seat => {
166
+ seat.exit();
167
+ return watch(
168
+ this.facets.holder.undelegate(validatorAddress, ertpAmount),
169
+ );
170
+ }, 'Undelegate');
171
+ },
172
+ CloseAccount() {
173
+ throw Error('not yet implemented');
174
+ },
175
+ },
176
+ undelegateWatcher: {
177
+ /**
178
+ * @param {[
179
+ * JsonSafe<
180
+ * TypedJson<'/cosmos.staking.v1beta1.MsgUndelegateResponse'>
181
+ * >,
182
+ * ]} response
183
+ */
184
+ onFulfilled(response) {
185
+ const { completionTime } = response[0];
186
+ return watch(
187
+ E(timerService).wakeAt(
188
+ // TODO clean up date handling once we have real data
189
+ dateInSeconds(new Date(completionTime)) + maxClockSkew,
190
+ ),
191
+ );
192
+ },
193
+ },
194
+ getChainInfoWatcher: {
195
+ /**
196
+ * @param {ChainInfo} agoricChainInfo
197
+ * @param {ChainAddress} destination
198
+ */
199
+ onFulfilled(agoricChainInfo, destination) {
200
+ return chainHub.getConnectionInfo(
201
+ agoricChainInfo.chainId,
202
+ destination.chainId,
203
+ );
204
+ },
205
+ },
206
+ transferWatcher: {
207
+ /**
208
+ * @param {[
209
+ * { transferChannel: IBCConnectionInfo['transferChannel'] },
210
+ * bigint,
211
+ * ]} results
212
+ * @param {{
213
+ * destination: ChainAddress;
214
+ * opts: IBCMsgTransferOptions;
215
+ * amount: DenomAmount;
216
+ * }} ctx
217
+ */
218
+ onFulfilled(
219
+ [{ transferChannel }, timeoutTimestamp],
220
+ { opts, amount, destination },
221
+ ) {
222
+ return watch(
223
+ E(this.state.account).executeTx([
224
+ typedJson('/ibc.applications.transfer.v1.MsgTransfer', {
225
+ sourcePort: transferChannel.portId,
226
+ sourceChannel: transferChannel.channelId,
227
+ token: {
228
+ amount: String(amount.value),
229
+ denom: amount.denom,
230
+ },
231
+ sender: this.state.address.address,
232
+ receiver: destination.address,
233
+ timeoutHeight: opts?.timeoutHeight ?? {
234
+ revisionHeight: 0n,
235
+ revisionNumber: 0n,
236
+ },
237
+ timeoutTimestamp,
238
+ memo: opts?.memo ?? '',
239
+ }),
240
+ ]),
241
+ );
242
+ },
243
+ },
244
+ /**
245
+ * takes an array of results (from `executeEncodedTx`) and returns the
246
+ * first result
247
+ */
248
+ extractFirstResultWatcher: {
249
+ /**
250
+ * @param {Record<unknown, unknown>[]} results
251
+ */
252
+ onFulfilled(results) {
253
+ results.length === 1 ||
254
+ Fail`expected exactly one result; got ${results}`;
255
+ return results[0];
256
+ },
257
+ },
258
+ /**
259
+ * takes an array of results (from `executeEncodedTx`) and returns void
260
+ * since we are not interested in the result
261
+ */
262
+ returnVoidWatcher: {
263
+ /**
264
+ * @param {unknown} _result
265
+ */
266
+ onFulfilled(_result) {
267
+ return undefined;
268
+ },
269
+ },
270
+ /**
271
+ * handles a request for balance from a bank purse and returns the balance
272
+ * as a Chain Amount
273
+ */
274
+ getBalanceWatcher: {
275
+ /**
276
+ * @param {Amount<'nat'>} natAmount
277
+ * @param {DenomAmount['denom']} denom
278
+ * @returns {DenomAmount}
279
+ */
280
+ onFulfilled(natAmount, denom) {
281
+ return harden({ denom, value: natAmount.value });
282
+ },
283
+ },
284
+ holder: {
285
+ /**
286
+ * TODO: balance lookups for non-vbank assets
287
+ *
288
+ * @type {PromiseToVow<OrchestrationAccount<any>['getBalance']>}
289
+ */
290
+ getBalance(denomArg) {
291
+ // FIXME look up real values
292
+ // UNTIL https://github.com/Agoric/agoric-sdk/issues/9211
293
+ const [brand, denom] =
294
+ typeof denomArg === 'string'
295
+ ? [/** @type {any} */ (null), denomArg]
296
+ : [denomArg, 'FIXME'];
297
+
298
+ return watch(
299
+ E(this.state.account).getBalance(brand),
300
+ this.facets.getBalanceWatcher,
301
+ denom,
302
+ );
303
+ },
304
+ getBalances() {
305
+ // TODO https://github.com/Agoric/agoric-sdk/issues/9610
306
+ return asVow(() => Fail`not yet implemented`);
307
+ },
308
+
309
+ getPublicTopics() {
310
+ const { topicKit } = this.state;
311
+ return harden({
312
+ account: {
313
+ description: PUBLIC_TOPICS.account[0],
314
+ subscriber: topicKit.subscriber,
315
+ storagePath: topicKit.recorder.getStoragePath(),
316
+ },
317
+ });
318
+ },
319
+ /**
320
+ * @param {string} validatorAddress
321
+ * @param {Amount<'nat'>} ertpAmount
322
+ */
323
+ delegate(validatorAddress, ertpAmount) {
324
+ // TODO #9211 lookup denom from brand
325
+ const amount = {
326
+ amount: String(ertpAmount.value),
327
+ denom: 'ubld',
328
+ };
329
+ const { account: lca } = this.state;
330
+
331
+ return watch(
332
+ E(lca).executeTx([
333
+ typedJson('/cosmos.staking.v1beta1.MsgDelegate', {
334
+ amount,
335
+ validatorAddress,
336
+ delegatorAddress: this.state.address.address,
337
+ }),
338
+ ]),
339
+ this.facets.extractFirstResultWatcher,
340
+ );
341
+ },
342
+ /**
343
+ * @param {string} validatorAddress
344
+ * @param {Amount<'nat'>} ertpAmount
345
+ * @returns {Vow<void | TimestampRecord>}
346
+ */
347
+ undelegate(validatorAddress, ertpAmount) {
348
+ // TODO #9211 lookup denom from brand
349
+ const amount = {
350
+ amount: String(ertpAmount.value),
351
+ denom: 'ubld',
352
+ };
353
+ const { account: lca } = this.state;
354
+ return watch(
355
+ E(lca).executeTx([
356
+ typedJson('/cosmos.staking.v1beta1.MsgUndelegate', {
357
+ amount,
358
+ validatorAddress,
359
+ delegatorAddress: this.state.address.address,
360
+ }),
361
+ ]),
362
+ this.facets.undelegateWatcher,
363
+ );
364
+ },
365
+ /**
366
+ * Starting a transfer revokes the account holder. The associated
367
+ * updater will get a special notification that the account is being
368
+ * transferred.
369
+ */
370
+ /** @type {PromiseToVow<OrchestrationAccount<any>['deposit']>} */
371
+ deposit(payment) {
372
+ return watch(
373
+ E(this.state.account).deposit(payment),
374
+ this.facets.returnVoidWatcher,
375
+ );
376
+ },
377
+ /** @type {PromiseToVow<LocalChainAccount['withdraw']>} */
378
+ withdraw(amount) {
379
+ return watch(E(this.state.account).withdraw(amount));
380
+ },
381
+ /** @type {PromiseToVow<LocalChainAccount['executeTx']>} */
382
+ executeTx(messages) {
383
+ return watch(E(this.state.account).executeTx(messages));
384
+ },
385
+ /** @type {OrchestrationAccount<any>['getAddress']} */
386
+ getAddress() {
387
+ return this.state.address;
388
+ },
389
+ send(toAccount, amount) {
390
+ return asVow(() => {
391
+ // FIXME implement
392
+ console.log('send got', toAccount, amount);
393
+ throw Fail`send not yet implemented`;
394
+ });
395
+ },
396
+ /**
397
+ * @param {AmountArg} amount an ERTP {@link Amount} or a
398
+ * {@link DenomAmount}
399
+ * @param {ChainAddress} destination
400
+ * @param {IBCMsgTransferOptions} [opts] if either timeoutHeight or
401
+ * timeoutTimestamp are not supplied, a default timeoutTimestamp will
402
+ * be set for 5 minutes in the future
403
+ * @returns {Vow<void>}
404
+ */
405
+ transfer(amount, destination, opts) {
406
+ return asVow(() => {
407
+ trace('Transferring funds from LCA over IBC');
408
+ // TODO #9211 lookup denom from brand
409
+ if ('brand' in amount) throw Fail`ERTP Amounts not yet supported`;
410
+
411
+ const connectionInfoV = watch(
412
+ chainHub.getChainInfo('agoric'),
413
+ this.facets.getChainInfoWatcher,
414
+ destination,
415
+ );
416
+
417
+ // set a `timeoutTimestamp` if caller does not supply either `timeoutHeight` or `timeoutTimestamp`
418
+ // TODO #9324 what's a reasonable default? currently 5 minutes
419
+ const timeoutTimestampVowOrValue =
420
+ opts?.timeoutTimestamp ??
421
+ (opts?.timeoutHeight
422
+ ? 0n
423
+ : E(timestampHelper).getTimeoutTimestampNS());
424
+
425
+ const transferV = watch(
426
+ allVows([connectionInfoV, timeoutTimestampVowOrValue]),
427
+ this.facets.transferWatcher,
428
+ { opts, amount, destination },
429
+ );
430
+ return watch(transferV, this.facets.returnVoidWatcher);
431
+ });
432
+ },
433
+ /** @type {PromiseToVow<OrchestrationAccount<any>['transferSteps']>} */
434
+ transferSteps(amount, msg) {
435
+ return asVow(() => {
436
+ console.log('transferSteps got', amount, msg);
437
+ throw Fail`not yet implemented`;
438
+ });
439
+ },
440
+ },
441
+ },
442
+ );
443
+ return makeLocalOrchestrationAccountKit;
444
+ };
445
+ /** @typedef {ReturnType<typeof prepareLocalOrchestrationAccountKit>} MakeLocalOrchestrationAccountKit */
446
+ /** @typedef {ReturnType<MakeLocalOrchestrationAccountKit>} LocalOrchestrationAccountKit */
@@ -0,0 +1,91 @@
1
+ /** @see {Orchestrator} */
2
+ export const OrchestratorI: import("@endo/patterns").InterfaceGuard<{
3
+ getChain: import("@endo/patterns").MethodGuard;
4
+ makeLocalAccount: import("@endo/patterns").MethodGuard;
5
+ getBrandInfo: import("@endo/patterns").MethodGuard;
6
+ asAmount: import("@endo/patterns").MethodGuard;
7
+ }>;
8
+ export function prepareOrchestratorKit(zone: Zone, { chainHub, localchain, makeLocalChainFacade, makeRemoteChainFacade, vowTools: { watch }, }: {
9
+ asyncFlowTools: AsyncFlowTools;
10
+ chainHub: ChainHub;
11
+ localchain: Remote<LocalChain>;
12
+ makeRecorderKit: MakeRecorderKit;
13
+ makeLocalChainFacade: MakeLocalChainFacade;
14
+ makeRemoteChainFacade: MakeRemoteChainFacade;
15
+ orchestrationService: Remote<OrchestrationService>;
16
+ storageNode: Remote<StorageNode>;
17
+ timerService: Remote<TimerService>;
18
+ vowTools: VowTools;
19
+ zcf: ZCF;
20
+ }): () => import("@endo/exo").GuardedKit<{
21
+ /** Waits for `chainInfo` and returns a LocalChainFacade */
22
+ makeLocalChainFacadeWatcher: {
23
+ /** @param {ChainInfo} agoricChainInfo */
24
+ onFulfilled(agoricChainInfo: ChainInfo): import("@endo/exo").Guarded<{
25
+ getChainInfo(): Vow<Readonly<{
26
+ chainId: string;
27
+ connections?: Record<string, IBCConnectionInfo>;
28
+ icqEnabled?: boolean;
29
+ stakingTokens?: Readonly<Array<{
30
+ denom: string;
31
+ }>>;
32
+ }>>;
33
+ makeAccount(): Vow<PromiseToVow<OrchestrationAccount<ChainInfo>>>;
34
+ }>;
35
+ };
36
+ /**
37
+ * Waits for `chainInfo` for `agoric` and a remote chain and returns a
38
+ * RemoteChainFacade
39
+ */
40
+ makeRemoteChainFacadeWatcher: {
41
+ /**
42
+ * Waits for `chainInfo` for `agoric` and a remote chain and returns a
43
+ * RemoteChainFacade
44
+ *
45
+ * @param {[ChainInfo, ChainInfo, IBCConnectionInfo]} chainsAndConnection
46
+ */
47
+ onFulfilled([_agoricChainInfo, remoteChainInfo, connectionInfo]: [ChainInfo, ChainInfo, IBCConnectionInfo]): import("@endo/exo").Guarded<{
48
+ getChainInfo(): Vow<Readonly<{
49
+ chainId: string;
50
+ connections?: Record<string, IBCConnectionInfo>;
51
+ icqEnabled?: boolean;
52
+ stakingTokens?: Readonly<Array<{
53
+ denom: string;
54
+ }>>;
55
+ }>>;
56
+ makeAccount(): Vow<PromiseToVow<OrchestrationAccount<ChainInfo>>>;
57
+ }>;
58
+ };
59
+ orchestrator: {
60
+ /** @type {PromiseToVow<Orchestrator['getChain']>} */
61
+ getChain(chainName: string): Vow<Chain<any>>;
62
+ makeLocalAccount(): Vow<import("@endo/exo").Guarded<{
63
+ getAddress(): string;
64
+ getBalance(brand: Brand<"nat">): import("@agoric/vow").PromiseVow<Amount<"nat">>;
65
+ deposit(payment: Payment<"nat">, optAmountShape?: Pattern): import("@agoric/vow").PromiseVow<Amount<"nat">>;
66
+ withdraw(amount: Amount<"nat">): import("@agoric/vow").PromiseVow<Payment<"nat">>;
67
+ executeTx<MT extends import("@agoric/cosmic-proto").TypedJson[]>(messages: MT): PromiseVowOfTupleMappedToGenerics<{ [K in keyof MT]: import("@agoric/cosmic-proto").JsonSafe<import("@agoric/cosmic-proto").ResponseTo<MT[K]>>; }>;
68
+ monitorTransfers(tap: import("@agoric/vats/src/bridge-target.js").TargetApp): import("@agoric/vow").PromiseVow<import("@agoric/vats/src/bridge-target.js").TargetRegistration>;
69
+ }>>;
70
+ getBrandInfo: () => never;
71
+ asAmount: () => never;
72
+ };
73
+ }>;
74
+ import type { Zone } from '@agoric/base-zone';
75
+ import type { AsyncFlowTools } from '@agoric/async-flow';
76
+ import type { ChainHub } from './chain-hub.js';
77
+ import type { LocalChain } from '@agoric/vats/src/localchain.js';
78
+ import type { Remote } from '@agoric/internal';
79
+ import type { MakeRecorderKit } from '@agoric/zoe/src/contractSupport/recorder.js';
80
+ import type { MakeLocalChainFacade } from './local-chain-facade.js';
81
+ import type { MakeRemoteChainFacade } from './remote-chain-facade.js';
82
+ import type { OrchestrationService } from '../service.js';
83
+ import type { TimerService } from '@agoric/time';
84
+ import type { VowTools } from '@agoric/vow';
85
+ import type { ChainInfo } from '../types.js';
86
+ import type { IBCConnectionInfo } from '../types.js';
87
+ import type { Vow } from '@agoric/vow';
88
+ import type { OrchestrationAccount } from '../types.js';
89
+ import type { PromiseToVow } from '../types.js';
90
+ import type { Chain } from '../types.js';
91
+ //# sourceMappingURL=orchestrator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["orchestrator.js"],"names":[],"mappings":"AAmCA,0BAA0B;AAC1B;;;;;GAKG;AAkBI,6CAfI,IAAI,+FACJ;IACV,cAAkB,EAAE,cAAc,CAAC;IACnC,QAAY,EAAE,QAAQ,CAAC;IACvB,UAAc,EAAE,OAAO,UAAU,CAAC,CAAC;IACnC,eAAmB,EAAE,eAAe,CAAC;IACrC,oBAAwB,EAAE,oBAAoB,CAAC;IAC/C,qBAAyB,EAAE,qBAAqB,CAAC;IACjD,oBAAwB,EAAE,OAAO,oBAAoB,CAAC,CAAC;IACvD,WAAe,EAAE,OAAO,WAAW,CAAC,CAAC;IACrC,YAAgB,EAAE,OAAO,YAAY,CAAC,CAAC;IACvC,QAAY,EAAE,QAAQ,CAAC;IACvB,GAAO,EAAE,GAAG,CAAC;CACV;IAmCE,2DAA2D;;QAEzD,yCAAyC;;;;;;;;;;;;;IAK3C;;;OAGG;;QAED;;;;;WAKG;;;;;;;;;;;;;;QAMH,qDAAqD;;;;;;;;;;;;;GAwB1D;0BA5HoB,mBAAmB;oCAET,oBAAoB;8BAD1B,gBAAgB;gCAId,gCAAgC;4BAEpC,kBAAkB;qCADI,6CAA6C;0CAKrD,yBAAyB;2CACxB,0BAA0B;0CAH3B,eAAe;kCALvB,cAAc;8BADb,aAAa;+BAU4E,aAAa;uCAAb,aAAa;yBAVtG,aAAa;0CAU4E,aAAa;kCAAb,aAAa;2BAAb,aAAa"}
@@ -0,0 +1,141 @@
1
+ /** @file ChainAccount exo */
2
+ import { AmountShape } from '@agoric/ertp';
3
+ import { makeTracer } from '@agoric/internal';
4
+ import { Shape as NetworkShape } from '@agoric/network';
5
+ import { E } from '@endo/far';
6
+ import { M } from '@endo/patterns';
7
+ import {
8
+ BrandInfoShape,
9
+ ChainInfoShape,
10
+ DenomAmountShape,
11
+ DenomShape,
12
+ LocalChainAccountShape,
13
+ } from '../typeGuards.js';
14
+
15
+ /**
16
+ * @import {Zone} from '@agoric/base-zone';
17
+ * @import {ChainHub} from './chain-hub.js';
18
+ * @import {AsyncFlowTools} from '@agoric/async-flow';
19
+ * @import {Vow, VowTools} from '@agoric/vow';
20
+ * @import {TimerService} from '@agoric/time';
21
+ * @import {LocalChain} from '@agoric/vats/src/localchain.js';
22
+ * @import {RecorderKit, MakeRecorderKit} from '@agoric/zoe/src/contractSupport/recorder.js'.
23
+ * @import {Remote} from '@agoric/internal';
24
+ * @import {PickFacet} from '@agoric/swingset-liveslots';
25
+ * @import {OrchestrationService} from '../service.js';
26
+ * @import {MakeLocalOrchestrationAccountKit} from './local-orchestration-account.js';
27
+ * @import {MakeLocalChainFacade} from './local-chain-facade.js';
28
+ * @import {MakeRemoteChainFacade} from './remote-chain-facade.js';
29
+ * @import {Chain, ChainInfo, CosmosChainInfo, IBCConnectionInfo, OrchestrationAccount, Orchestrator, PromiseToVow} from '../types.js';
30
+ */
31
+
32
+ const { Fail } = assert;
33
+ const { Vow$ } = NetworkShape; // TODO #9611
34
+ const trace = makeTracer('Orchestrator');
35
+
36
+ /** @see {Orchestrator} */
37
+ export const OrchestratorI = M.interface('Orchestrator', {
38
+ getChain: M.call(M.string()).returns(Vow$(ChainInfoShape)),
39
+ makeLocalAccount: M.call().returns(Vow$(LocalChainAccountShape)),
40
+ getBrandInfo: M.call(DenomShape).returns(BrandInfoShape),
41
+ asAmount: M.call(DenomAmountShape).returns(AmountShape),
42
+ });
43
+
44
+ /**
45
+ * @param {Zone} zone
46
+ * @param {{
47
+ * asyncFlowTools: AsyncFlowTools;
48
+ * chainHub: ChainHub;
49
+ * localchain: Remote<LocalChain>;
50
+ * makeRecorderKit: MakeRecorderKit;
51
+ * makeLocalChainFacade: MakeLocalChainFacade;
52
+ * makeRemoteChainFacade: MakeRemoteChainFacade;
53
+ * orchestrationService: Remote<OrchestrationService>;
54
+ * storageNode: Remote<StorageNode>;
55
+ * timerService: Remote<TimerService>;
56
+ * vowTools: VowTools;
57
+ * zcf: ZCF;
58
+ * }} powers
59
+ */
60
+ export const prepareOrchestratorKit = (
61
+ zone,
62
+ {
63
+ chainHub,
64
+ localchain,
65
+ makeLocalChainFacade,
66
+ makeRemoteChainFacade,
67
+ vowTools: { watch },
68
+ },
69
+ ) =>
70
+ zone.exoClassKit(
71
+ 'Orchestrator',
72
+ {
73
+ orchestrator: OrchestratorI,
74
+ makeLocalChainFacadeWatcher: M.interface('makeLocalChainFacadeWatcher', {
75
+ onFulfilled: M.call(M.record())
76
+ .optional(M.arrayOf(M.undefined()))
77
+ .returns(M.any()), // FIXME narrow
78
+ }),
79
+ makeRemoteChainFacadeWatcher: M.interface(
80
+ 'makeRemoteChainFacadeWatcher',
81
+ {
82
+ onFulfilled: M.call(M.any())
83
+ .optional(M.arrayOf(M.undefined()))
84
+ .returns(M.any()), // FIXME narrow
85
+ },
86
+ ),
87
+ },
88
+ () => {
89
+ trace('making an Orchestrator');
90
+ return {};
91
+ },
92
+ {
93
+ /** Waits for `chainInfo` and returns a LocalChainFacade */
94
+ makeLocalChainFacadeWatcher: {
95
+ /** @param {ChainInfo} agoricChainInfo */
96
+ onFulfilled(agoricChainInfo) {
97
+ return makeLocalChainFacade(agoricChainInfo);
98
+ },
99
+ },
100
+ /**
101
+ * Waits for `chainInfo` for `agoric` and a remote chain and returns a
102
+ * RemoteChainFacade
103
+ */
104
+ makeRemoteChainFacadeWatcher: {
105
+ /**
106
+ * Waits for `chainInfo` for `agoric` and a remote chain and returns a
107
+ * RemoteChainFacade
108
+ *
109
+ * @param {[ChainInfo, ChainInfo, IBCConnectionInfo]} chainsAndConnection
110
+ */
111
+ onFulfilled([_agoricChainInfo, remoteChainInfo, connectionInfo]) {
112
+ return makeRemoteChainFacade(remoteChainInfo, connectionInfo);
113
+ },
114
+ },
115
+ orchestrator: {
116
+ /** @type {PromiseToVow<Orchestrator['getChain']>} */
117
+ getChain(name) {
118
+ if (name === 'agoric') {
119
+ // TODO #9449 fix types
120
+ // @ts-expect-error Type 'Vow<Voidless>' is not assignable to type 'Vow<Chain<any>>'.
121
+ return watch(
122
+ chainHub.getChainInfo('agoric'),
123
+ this.facets.makeLocalChainFacadeWatcher,
124
+ );
125
+ }
126
+ // TODO #9449 fix types
127
+ // @ts-expect-error Type 'Vow<Voidless>' is not assignable to type 'Vow<Chain<any>>'.
128
+ return watch(
129
+ chainHub.getChainsAndConnection('agoric', name),
130
+ this.facets.makeRemoteChainFacadeWatcher,
131
+ );
132
+ },
133
+ makeLocalAccount() {
134
+ return watch(E(localchain).makeAccount());
135
+ },
136
+ getBrandInfo: () => Fail`not yet implemented`,
137
+ asAmount: () => Fail`not yet implemented`,
138
+ },
139
+ },
140
+ );
141
+ harden(prepareOrchestratorKit);