@agoric/orchestration 0.2.0 → 0.2.1-upgrade-23-dev-bd79330.0.bd79330

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 (234) hide show
  1. package/index.js +0 -4
  2. package/package.json +27 -27
  3. package/src/axelar-types.d.ts +2 -0
  4. package/src/axelar-types.d.ts.map +1 -1
  5. package/src/axelar-types.js +2 -0
  6. package/src/cctp-chain-info.js +4 -1
  7. package/src/chain-info.d.ts +21 -6
  8. package/src/chain-info.d.ts.map +1 -1
  9. package/src/chain-info.js +9 -8
  10. package/src/cosmos-api.d.ts +102 -29
  11. package/src/cosmos-api.d.ts.map +1 -1
  12. package/src/cosmos-api.js +585 -0
  13. package/src/{ethereum-api.ts → ethereum-api.js} +1 -1
  14. package/src/examples/auto-stake-it-tap-kit.d.ts +4 -3
  15. package/src/examples/auto-stake-it-tap-kit.d.ts.map +1 -1
  16. package/src/examples/auto-stake-it-tap-kit.js +3 -4
  17. package/src/examples/auto-stake-it.contract.d.ts +6 -4
  18. package/src/examples/auto-stake-it.contract.d.ts.map +1 -1
  19. package/src/examples/auto-stake-it.contract.js +3 -1
  20. package/src/examples/auto-stake-it.flows.d.ts +2 -1
  21. package/src/examples/auto-stake-it.flows.d.ts.map +1 -1
  22. package/src/examples/auto-stake-it.flows.js +1 -0
  23. package/src/examples/axelar-gmp-account-kit.d.ts +6 -4
  24. package/src/examples/axelar-gmp-account-kit.d.ts.map +1 -1
  25. package/src/examples/axelar-gmp-account-kit.js +4 -2
  26. package/src/examples/axelar-gmp.contract.d.ts +8 -8
  27. package/src/examples/axelar-gmp.contract.d.ts.map +1 -1
  28. package/src/examples/axelar-gmp.contract.js +2 -2
  29. package/src/examples/axelar-gmp.flows.d.ts +1 -1
  30. package/src/examples/basic-flows.contract.d.ts +7 -5
  31. package/src/examples/basic-flows.contract.d.ts.map +1 -1
  32. package/src/examples/basic-flows.contract.js +3 -1
  33. package/src/examples/basic-flows.flows.d.ts +2 -1
  34. package/src/examples/basic-flows.flows.d.ts.map +1 -1
  35. package/src/examples/basic-flows.flows.js +1 -0
  36. package/src/examples/send-anywhere.contract.d.ts +12 -6
  37. package/src/examples/send-anywhere.contract.d.ts.map +1 -1
  38. package/src/examples/send-anywhere.contract.js +4 -1
  39. package/src/examples/send-anywhere.flows.d.ts +3 -2
  40. package/src/examples/send-anywhere.flows.d.ts.map +1 -1
  41. package/src/examples/send-anywhere.flows.js +3 -6
  42. package/src/examples/stake-bld.contract.d.ts +206 -25
  43. package/src/examples/stake-bld.contract.d.ts.map +1 -1
  44. package/src/examples/stake-bld.contract.js +19 -4
  45. package/src/examples/stake-ica.contract.d.ts +434 -71
  46. package/src/examples/stake-ica.contract.d.ts.map +1 -1
  47. package/src/examples/stake-ica.contract.js +28 -6
  48. package/src/examples/staking-combinations.contract.d.ts +4 -2
  49. package/src/examples/staking-combinations.contract.d.ts.map +1 -1
  50. package/src/examples/staking-combinations.contract.js +5 -3
  51. package/src/examples/staking-combinations.flows.d.ts +3 -2
  52. package/src/examples/staking-combinations.flows.d.ts.map +1 -1
  53. package/src/examples/staking-combinations.flows.js +7 -6
  54. package/src/examples/swap-anything.contract.d.ts +14 -7
  55. package/src/examples/swap-anything.contract.d.ts.map +1 -1
  56. package/src/examples/swap-anything.contract.js +12 -8
  57. package/src/examples/swap.contract.d.ts +18 -6
  58. package/src/examples/swap.contract.d.ts.map +1 -1
  59. package/src/examples/swap.contract.js +9 -3
  60. package/src/examples/swap.flows.d.ts +2 -0
  61. package/src/examples/swap.flows.d.ts.map +1 -1
  62. package/src/examples/swap.flows.js +2 -0
  63. package/src/examples/unbond.contract.d.ts +7 -4
  64. package/src/examples/unbond.contract.d.ts.map +1 -1
  65. package/src/examples/unbond.contract.js +6 -3
  66. package/src/exos/chain-hub-admin.d.ts +1 -19
  67. package/src/exos/chain-hub-admin.d.ts.map +1 -1
  68. package/src/exos/chain-hub-admin.js +1 -1
  69. package/src/exos/chain-hub.d.ts +4 -2
  70. package/src/exos/chain-hub.d.ts.map +1 -1
  71. package/src/exos/chain-hub.js +2 -1
  72. package/src/exos/combine-invitation-makers.d.ts +2 -1
  73. package/src/exos/combine-invitation-makers.d.ts.map +1 -1
  74. package/src/exos/combine-invitation-makers.js +2 -1
  75. package/src/exos/cosmos-orchestration-account.d.ts +615 -98
  76. package/src/exos/cosmos-orchestration-account.d.ts.map +1 -1
  77. package/src/exos/cosmos-orchestration-account.js +695 -306
  78. package/src/exos/exo-interfaces.js +35 -0
  79. package/src/exos/ibc-packet.d.ts +11 -9
  80. package/src/exos/ibc-packet.d.ts.map +1 -1
  81. package/src/exos/ibc-packet.js +33 -8
  82. package/src/exos/ica-account-kit.d.ts +4 -9
  83. package/src/exos/ica-account-kit.d.ts.map +1 -1
  84. package/src/exos/ica-account-kit.js +10 -7
  85. package/src/exos/icq-connection-kit.d.ts +1 -1
  86. package/src/exos/local-chain-facade.d.ts +1542 -5
  87. package/src/exos/local-chain-facade.d.ts.map +1 -1
  88. package/src/exos/local-chain-facade.js +4 -2
  89. package/src/exos/local-orchestration-account.d.ts +201 -56
  90. package/src/exos/local-orchestration-account.d.ts.map +1 -1
  91. package/src/exos/local-orchestration-account.js +260 -51
  92. package/src/exos/orchestrator.d.ts +35813 -73
  93. package/src/exos/orchestrator.d.ts.map +1 -1
  94. package/src/exos/orchestrator.js +7 -10
  95. package/src/exos/packet-tools.d.ts +19 -8
  96. package/src/exos/packet-tools.d.ts.map +1 -1
  97. package/src/exos/packet-tools.js +92 -9
  98. package/src/exos/portfolio-holder-kit.d.ts +90 -2
  99. package/src/exos/portfolio-holder-kit.d.ts.map +1 -1
  100. package/src/exos/remote-chain-facade.d.ts +1499 -1
  101. package/src/exos/remote-chain-facade.d.ts.map +1 -1
  102. package/src/exos/remote-chain-facade.js +8 -3
  103. package/src/facade.d.ts +1 -0
  104. package/src/facade.d.ts.map +1 -1
  105. package/src/facade.js +4 -6
  106. package/src/fixtures/query-flows.contract.d.ts +8 -6
  107. package/src/fixtures/query-flows.contract.d.ts.map +1 -1
  108. package/src/fixtures/query-flows.contract.js +3 -1
  109. package/src/fixtures/query-flows.flows.d.ts +1 -0
  110. package/src/fixtures/query-flows.flows.d.ts.map +1 -1
  111. package/src/fixtures/query-flows.flows.js +1 -0
  112. package/src/orchestration-api.d.ts +46 -16
  113. package/src/orchestration-api.d.ts.map +1 -1
  114. package/src/orchestration-api.js +410 -0
  115. package/src/proposals/init-chain-info.js +10 -2
  116. package/src/proposals/orchestration-proposal.js +3 -0
  117. package/src/proposals/revise-chain-info.js +4 -1
  118. package/src/proposals/start-auto-stake-it.js +1 -0
  119. package/src/proposals/start-axelar-gmp.js +2 -2
  120. package/src/proposals/start-basic-flows.js +5 -0
  121. package/src/proposals/start-send-anywhere.js +4 -2
  122. package/src/proposals/start-stakeAtom.js +5 -4
  123. package/src/proposals/start-stakeBld.js +8 -6
  124. package/src/proposals/start-stakeOsmo.js +5 -4
  125. package/src/proposals/start-swap-anything.js +4 -2
  126. package/src/stubs/{viem-abi.d.ts → viem-typedData.js} +10 -4
  127. package/src/typeGuards.d.ts +38 -5
  128. package/src/typeGuards.d.ts.map +1 -1
  129. package/src/typeGuards.js +92 -22
  130. package/src/types.d.ts +1 -0
  131. package/src/types.d.ts.map +1 -1
  132. package/src/types.js +27 -0
  133. package/src/utils/abitype.d.ts +6 -0
  134. package/src/utils/abitype.d.ts.map +1 -0
  135. package/src/utils/abitype.js +13 -0
  136. package/src/utils/address.d.ts +3 -1
  137. package/src/utils/address.d.ts.map +1 -1
  138. package/src/utils/address.js +24 -2
  139. package/src/utils/agd-lib.d.ts +1 -51
  140. package/src/utils/agd-lib.d.ts.map +1 -1
  141. package/src/utils/agd-lib.js +1 -1
  142. package/src/utils/amounts.d.ts +1 -0
  143. package/src/utils/amounts.d.ts.map +1 -1
  144. package/src/utils/amounts.js +1 -0
  145. package/src/utils/asset.d.ts +1 -0
  146. package/src/utils/asset.d.ts.map +1 -1
  147. package/src/utils/asset.js +1 -0
  148. package/src/utils/chain-hub-helper.d.ts +1 -0
  149. package/src/utils/chain-hub-helper.d.ts.map +1 -1
  150. package/src/utils/chain-hub-helper.js +1 -0
  151. package/src/utils/codecs.d.ts +145 -0
  152. package/src/utils/codecs.d.ts.map +1 -0
  153. package/src/utils/codecs.js +206 -0
  154. package/src/utils/cosmos.d.ts +5 -4
  155. package/src/utils/cosmos.d.ts.map +1 -1
  156. package/src/utils/cosmos.js +29 -9
  157. package/src/utils/exo-helpers.d.ts +156 -0
  158. package/src/utils/exo-helpers.d.ts.map +1 -0
  159. package/src/utils/exo-helpers.js +241 -0
  160. package/src/utils/gmp.d.ts +2 -2
  161. package/src/utils/gmp.d.ts.map +1 -1
  162. package/src/utils/gmp.js +31 -15
  163. package/src/utils/orchestrationAccount.d.ts +79 -0
  164. package/src/utils/orchestrationAccount.d.ts.map +1 -1
  165. package/src/utils/orchestrationAccount.js +210 -6
  166. package/src/utils/packet.d.ts.map +1 -1
  167. package/src/utils/packet.js +5 -0
  168. package/src/utils/permit2/signatureTransfer.d.ts +221 -0
  169. package/src/utils/permit2/signatureTransfer.d.ts.map +1 -0
  170. package/src/utils/permit2/signatureTransfer.js +265 -0
  171. package/src/utils/permit2/signatureTransferHelpers.d.ts +334 -0
  172. package/src/utils/permit2/signatureTransferHelpers.d.ts.map +1 -0
  173. package/src/utils/permit2/signatureTransferHelpers.js +270 -0
  174. package/src/utils/permit2.d.ts +11 -0
  175. package/src/utils/permit2.d.ts.map +1 -0
  176. package/src/utils/permit2.js +11 -0
  177. package/src/utils/progress.d.ts +41 -0
  178. package/src/utils/progress.d.ts.map +1 -0
  179. package/src/utils/progress.js +180 -0
  180. package/src/utils/start-helper.d.ts +28 -10
  181. package/src/utils/start-helper.d.ts.map +1 -1
  182. package/src/utils/start-helper.js +30 -7
  183. package/src/utils/time.d.ts +2 -2
  184. package/src/utils/time.d.ts.map +1 -1
  185. package/src/utils/time.js +1 -1
  186. package/src/utils/viem-utils/hashTypedData.d.ts +21 -0
  187. package/src/utils/viem-utils/hashTypedData.d.ts.map +1 -0
  188. package/src/utils/viem-utils/hashTypedData.js +61 -0
  189. package/src/utils/viem-utils/types.d.ts +6 -0
  190. package/src/utils/viem-utils/types.d.ts.map +1 -0
  191. package/src/utils/viem-utils/types.js +18 -0
  192. package/src/utils/viem.d.ts +11 -0
  193. package/src/utils/viem.d.ts.map +1 -0
  194. package/src/utils/viem.js +11 -0
  195. package/src/utils/zcf-tools.d.ts +15 -1
  196. package/src/utils/zcf-tools.d.ts.map +1 -1
  197. package/src/utils/zcf-tools.js +19 -3
  198. package/src/utils/zoe-tools.d.ts +5 -2
  199. package/src/utils/zoe-tools.d.ts.map +1 -1
  200. package/src/utils/zoe-tools.js +8 -2
  201. package/src/vat-orchestration.d.ts +5 -3
  202. package/src/vat-orchestration.d.ts.map +1 -1
  203. package/src/vat-orchestration.js +4 -3
  204. package/src/vendor/viem/{_esm-YOAV66U4.js → _esm-OKAICHVC.js} +2 -2
  205. package/src/vendor/viem/{ccip-AAQDZF3N.js → ccip-34BSSMV5.js} +1 -2
  206. package/src/vendor/viem/{chunk-4EF4K2MH.js → chunk-GCI53Z2G.js} +35 -1
  207. package/src/vendor/viem/chunk-ZKSIP2AM.js +326 -0
  208. package/src/vendor/viem/viem-abi.js +2 -2
  209. package/src/vendor/viem/viem-typedData.d.ts +19 -0
  210. package/src/vendor/viem/viem-typedData.js +59 -0
  211. package/tools/contract-tests.d.ts +34 -19
  212. package/tools/contract-tests.d.ts.map +1 -1
  213. package/tools/contract-tests.ts +15 -3
  214. package/tools/ibc-mock-fixtures.d.ts +49 -0
  215. package/tools/ibc-mock-fixtures.d.ts.map +1 -0
  216. package/tools/ibc-mock-fixtures.ts +161 -0
  217. package/tools/ibc-mocks.d.ts +2 -3
  218. package/tools/ibc-mocks.d.ts.map +1 -1
  219. package/tools/ibc-mocks.ts +2 -1
  220. package/tools/make-test-address.d.ts +1 -1
  221. package/tools/make-test-address.d.ts.map +1 -1
  222. package/tools/make-test-address.js +1 -2
  223. package/tools/network-fakes.d.ts +142 -0
  224. package/tools/network-fakes.d.ts.map +1 -0
  225. package/tools/network-fakes.ts +388 -0
  226. package/tsup.config.ts +3 -1
  227. package/src/cosmos-api.ts +0 -469
  228. package/src/exos/exo-interfaces.ts +0 -35
  229. package/src/orchestration-api.ts +0 -365
  230. package/src/stubs/viem-abi.d.ts.map +0 -1
  231. package/src/types.ts +0 -26
  232. package/src/vendor/viem/chunk-XN4LUOIH.js +0 -253
  233. package/src/vendor/viem/secp256k1-WHBDSQB2.js +0 -1914
  234. /package/src/stubs/{viem-abi.ts → viem-abi.js} +0 -0
@@ -9,7 +9,10 @@ import { E } from '@endo/far';
9
9
  import { Fail, q } from '@endo/errors';
10
10
 
11
11
  import { MsgTransfer as MsgTransferType } from '@agoric/cosmic-proto/ibc/applications/transfer/v1/tx.js';
12
- import { QueryDenomHashRequest as QueryDenomHashRequestType } from '@agoric/cosmic-proto/ibc/applications/transfer/v1/query.js';
12
+ import {
13
+ QueryDenomHashRequest as QueryDenomHashRequestType,
14
+ QueryDenomHashResponse as QueryDenomHashResponseType,
15
+ } from '@agoric/cosmic-proto/ibc/applications/transfer/v1/query.js';
13
16
  import {
14
17
  QueryAllBalancesRequest as QueryAllBalancesRequestType,
15
18
  QueryBalanceRequest as QueryBalanceRequestType,
@@ -29,15 +32,24 @@ import {
29
32
  TypedJsonShape,
30
33
  } from '../typeGuards.js';
31
34
  import { maxClockSkew, toDenomAmount } from '../utils/cosmos.js';
32
- import { orchestrationAccountMethods } from '../utils/orchestrationAccount.js';
35
+ import {
36
+ addTrafficEntries,
37
+ orchestrationAccountMethods,
38
+ trafficTransforms,
39
+ } from '../utils/orchestrationAccount.js';
40
+ import { makeVowExoHelpers } from '../utils/exo-helpers.js';
33
41
  import { makeTimestampHelper } from '../utils/time.js';
34
42
  import { preparePacketTools } from './packet-tools.js';
35
43
  import { prepareIBCTools } from './ibc-packet.js';
36
44
  import { coerceCoin, coerceDenomAmount } from '../utils/amounts.js';
37
45
  import { TransferRouteShape } from './chain-hub.js';
46
+ import { chainOfAccount } from '../utils/address.js';
47
+
48
+ const { details: X } = assert;
38
49
 
39
50
  const MsgTransfer = CodecHelper(MsgTransferType);
40
51
  const QueryDenomHashRequest = CodecHelper(QueryDenomHashRequestType);
52
+ const QueryDenomHashResponse = CodecHelper(QueryDenomHashResponseType);
41
53
  const QueryAllBalancesRequest = CodecHelper(QueryAllBalancesRequestType);
42
54
  const QueryBalanceRequest = CodecHelper(QueryBalanceRequestType);
43
55
  const MsgDelegate = CodecHelper(MsgDelegateType);
@@ -45,9 +57,11 @@ const MsgUndelegate = CodecHelper(MsgUndelegateType);
45
57
  const MsgSend = CodecHelper(MsgSendType);
46
58
 
47
59
  /**
48
- * @import {HostOf} from '@agoric/async-flow';
60
+ * @import {HostInterface, HostOf} from '@agoric/async-flow';
49
61
  * @import {LocalChain, LocalChainAccount} from '@agoric/vats/src/localchain.js';
50
- * @import {AmountArg, CosmosChainAddress, DenomAmount, IBCMsgTransferOptions, OrchestrationAccountCommon, LocalAccountMethods, TransferRoute, AccountIdArg, Denom, Bech32Address} from '@agoric/orchestration';
62
+ * @import {AmountArg, CosmosChainAddress, DenomAmount, IBCMsgTransferOptions,
63
+ * OrchestrationAccountCommon, LocalAccountMethods, TransferRoute,
64
+ * AccountIdArg, Denom, IBCConnectionInfo, ChainInfo, CosmosChainInfo} from '@agoric/orchestration';
51
65
  * @import {OfferHandler, ZCF, ZCFSeat} from '@agoric/zoe';
52
66
  * @import {IBCEvent} from '@agoric/vats';
53
67
  * @import {QueryDenomHashResponse} from '@agoric/cosmic-proto/ibc/applications/transfer/v1/query.js';
@@ -63,8 +77,26 @@ const MsgSend = CodecHelper(MsgSendType);
63
77
  * @import {Matcher} from '@endo/patterns';
64
78
  * @import {ChainHub} from './chain-hub.js';
65
79
  * @import {PacketTools} from './packet-tools.js';
80
+ * @import {SliceDescriptor} from '../utils/orchestrationAccount.js';
66
81
  * @import {ZoeTools} from '../utils/zoe-tools.js';
82
+ * @import {MakeProgressTracker} from '../utils/progress.js';
83
+ * @import {Amount} from '@agoric/ertp';
84
+ * @import {StorageNode} from '@agoric/internal/src/lib-chainStorage.js';
85
+ */
86
+
87
+ /**
88
+ * Watcher facets of the exoClassKit that have been removed from service, but
89
+ * need to leave behind a dummy facet to allow older contracts that use
90
+ * orchestration to be upgraded.
91
+ *
92
+ * Add new watchers here as they are removed from service. Maybe someday
93
+ * contract upgrade will allow us to prune this list.
67
94
  */
95
+ const TOMBSTONED_WATCHERS = /** @type {const} */ (
96
+ [
97
+ // 'transferWithMetaWatcher', // deprecated but not yet tombstoned
98
+ ]
99
+ );
68
100
 
69
101
  const trace = makeTracer('LocalOrchAccount');
70
102
 
@@ -72,6 +104,22 @@ const { Vow$ } = NetworkShape; // TODO #9611
72
104
 
73
105
  const EVow$ = shape => M.or(Vow$(shape), M.promise(/* shape */));
74
106
 
107
+ /**
108
+ * @template {string} TU
109
+ * @param {{ error?: string; reply: TypedJson<TU> }[] | TypedJson<TU>} result
110
+ * @returns {{ error?: string; reply: TypedJson<TU> }}
111
+ */
112
+ const extractFirstQueryResult = result => {
113
+ if (Array.isArray(result)) {
114
+ assert(
115
+ result.length > 0,
116
+ X`Expected result to be a nonempty array, got ${result}`,
117
+ );
118
+ return result[0];
119
+ }
120
+ return { reply: result };
121
+ };
122
+
75
123
  /**
76
124
  * @typedef {object} LocalChainAccountNotification
77
125
  * @property {string} address
@@ -97,7 +145,7 @@ const HolderI = M.interface('holder', {
97
145
  executeTx: M.call(M.arrayOf(M.record())).returns(Vow$(M.record())),
98
146
  sendThenWaitForAck: M.call(EVow$(M.remotable('PacketSender')))
99
147
  .optional(M.any())
100
- .returns(EVow$(M.string())),
148
+ .returns(EVow$(M.any())),
101
149
  matchFirstPacket: M.call(M.any()).returns(EVow$(M.any())),
102
150
  monitorTransfers: M.call(M.remotable('TargetApp')).returns(EVow$(M.any())),
103
151
  parseInboundTransfer: M.call(M.recordOf(M.string(), M.any())).returns(
@@ -115,6 +163,12 @@ const PUBLIC_TOPICS = {
115
163
  account: ['Account holder status', M.any()],
116
164
  };
117
165
 
166
+ /**
167
+ * @see {@link https://github.com/cosmos/ibc-go/blob/a24a6c6/modules/apps/transfer/types/errors.go#L13}
168
+ * a24a6c6 Feb 27, 2023
169
+ */
170
+ const ErrTraceNotFound = 'denomination trace not found';
171
+
118
172
  /**
119
173
  * @param {Zone} zone
120
174
  * @param {object} powers
@@ -125,11 +179,13 @@ const PUBLIC_TOPICS = {
125
179
  * @param {ChainHub} powers.chainHub
126
180
  * @param {Remote<LocalChain>} powers.localchain
127
181
  * @param {ZoeTools} powers.zoeTools
182
+ * @param {MakeProgressTracker} powers.makeProgressTracker
128
183
  */
129
184
  export const prepareLocalOrchestrationAccountKit = (
130
185
  zone,
131
186
  {
132
187
  makeRecorderKit,
188
+ makeProgressTracker,
133
189
  zcf,
134
190
  timerService,
135
191
  vowTools,
@@ -139,6 +195,7 @@ export const prepareLocalOrchestrationAccountKit = (
139
195
  },
140
196
  ) => {
141
197
  const { watch, asVow, when } = vowTools;
198
+ const vowExo = makeVowExoHelpers({ watch });
142
199
  const { makeIBCTransferSender } = prepareIBCTools(
143
200
  zone.subZone('ibcTools'),
144
201
  vowTools,
@@ -153,7 +210,20 @@ export const prepareLocalOrchestrationAccountKit = (
153
210
  const makeLocalOrchestrationAccountKit = zone.exoClassKit(
154
211
  'Local Orchestration Account Kit',
155
212
  {
213
+ /** @deprecated replaced by transferWatcher */
214
+ transferWithMetaWatcher: M.interface('transferWatcher', {
215
+ onFulfilled: M.call([M.record(), M.record(), M.record(), M.nat()])
216
+ .optional({
217
+ opts: M.opt(IBCTransferOptionsShape),
218
+ route: TransferRouteShape,
219
+ })
220
+ .returns(Vow$(M.record())),
221
+ }),
222
+ /** Facets above this line are deprecated. */
223
+ ...vowExo.makeTombstonedWatcherShapes(TOMBSTONED_WATCHERS),
224
+ ...vowExo.watcherShapes,
156
225
  helper: M.interface('helper', {
226
+ ...vowExo.helperShapes,
157
227
  amountToCoin: M.call(AmountArgShape).returns(M.record()),
158
228
  }),
159
229
  holder: HolderI,
@@ -165,9 +235,17 @@ export const prepareLocalOrchestrationAccountKit = (
165
235
  .returns(VowShape),
166
236
  }),
167
237
  transferWatcher: M.interface('transferWatcher', {
168
- onFulfilled: M.call(M.nat())
238
+ onFulfilled: M.call(M.array())
169
239
  .optional({
170
- opts: M.or(M.undefined(), IBCTransferOptionsShape),
240
+ opts: M.opt(IBCTransferOptionsShape),
241
+ route: TransferRouteShape,
242
+ })
243
+ .returns(Vow$(M.record())),
244
+ }),
245
+ transferConnectionWatcher: M.interface('transferConnectionWatcher', {
246
+ onFulfilled: M.call([M.record(), M.record(), M.nat()])
247
+ .optional({
248
+ opts: M.opt(IBCTransferOptionsShape),
171
249
  route: TransferRouteShape,
172
250
  })
173
251
  .returns(Vow$(M.record())),
@@ -198,7 +276,7 @@ export const prepareLocalOrchestrationAccountKit = (
198
276
  ),
199
277
  }),
200
278
  parseInboundTransferWatcher: M.interface('parseInboundTransferWatcher', {
201
- onFulfilled: M.call(M.record(), M.record()).returns(M.record()),
279
+ onFulfilled: M.call(M.any(), M.record()).returns(M.record()),
202
280
  onRejected: M.call(M.any(), M.record()).returns(M.record()),
203
281
  }),
204
282
  invitationMakers: M.interface('invitationMakers', {
@@ -234,7 +312,30 @@ export const prepareLocalOrchestrationAccountKit = (
234
312
  return { account, address, packetTools, topicKit };
235
313
  },
236
314
  {
315
+ /** @deprecated replaced by transferWatcher */
316
+ transferWithMetaWatcher: {
317
+ /**
318
+ * @param {readonly [
319
+ * ChainInfo,
320
+ * ChainInfo,
321
+ * Pick<IBCConnectionInfo, 'transferChannel'>,
322
+ * bigint,
323
+ * ]} details
324
+ * @param {{
325
+ * opts?: Omit<IBCMsgTransferOptions, 'forwardOpts'>;
326
+ * route: TransferRoute;
327
+ * }} ctx
328
+ */
329
+ onFulfilled(details, ctx) {
330
+ const result = this.facets.transferWatcher.onFulfilled(details, ctx);
331
+ return harden({ result, meta: {} });
332
+ },
333
+ },
334
+ /** Facets above this line are deprecated. */
335
+ ...vowExo.makeTombstonedWatcherShapes(TOMBSTONED_WATCHERS),
336
+ ...vowExo.watchers,
237
337
  helper: {
338
+ ...vowExo.helper,
238
339
  /**
239
340
  * @param {AmountArg} amount
240
341
  * @returns {Coin}
@@ -382,34 +483,83 @@ export const prepareLocalOrchestrationAccountKit = (
382
483
  );
383
484
  },
384
485
  },
486
+ transferConnectionWatcher: {
487
+ /**
488
+ * @param {readonly [CosmosChainInfo, CosmosChainInfo, bigint]} all
489
+ * @param {Record<string, any>} ctx
490
+ */
491
+ onFulfilled([srcChainInfo, nextChainInfo, timeout], ctx) {
492
+ return watch(
493
+ vowTools.allVows(
494
+ /** @type {const} */ ([
495
+ srcChainInfo,
496
+ nextChainInfo,
497
+ chainHub.getConnectionInfo(srcChainInfo, nextChainInfo),
498
+ timeout,
499
+ ]),
500
+ ),
501
+ this.facets.transferWatcher,
502
+ ctx,
503
+ );
504
+ },
505
+ },
385
506
  transferWatcher: {
386
507
  /**
387
- * @param {bigint} timeoutTimestamp
508
+ * @param {readonly [
509
+ * ChainInfo,
510
+ * ChainInfo,
511
+ * Pick<IBCConnectionInfo, 'transferChannel'>,
512
+ * bigint,
513
+ * ]} details
388
514
  * @param {{
389
515
  * opts?: Omit<IBCMsgTransferOptions, 'forwardOpts'>;
390
516
  * route: TransferRoute;
391
517
  * }} ctx
392
518
  */
393
- onFulfilled(timeoutTimestamp, { opts, route }) {
519
+ onFulfilled(
520
+ [srcChainInfo, dstChainInfo, { transferChannel }, timeoutTimestamp],
521
+ { opts, route },
522
+ ) {
394
523
  const { forwardInfo, ...transferDetails } = route;
524
+
525
+ assert.equal(
526
+ transferDetails.sourcePort,
527
+ transferChannel.portId,
528
+ X`sourcePort ${q(
529
+ transferDetails.sourcePort,
530
+ )} must match the portId ${q(transferChannel.portId)}`,
531
+ );
532
+ assert.equal(
533
+ transferDetails.sourceChannel,
534
+ transferChannel.channelId,
535
+ X`sourceChannel ${q(
536
+ transferDetails.sourceChannel,
537
+ )} must match the channelId ${q(transferChannel.channelId)}`,
538
+ );
539
+
540
+ const {
541
+ // Strip out the fields that are already included in MsgTransfer.ß
542
+ timeoutHeight,
543
+ timeoutTimestamp: _,
544
+ memo: optsMemo,
545
+ ...packetOpts
546
+ } = opts || {};
547
+
395
548
  /** @type {string | undefined} */
396
- let memo;
397
- if (opts && 'memo' in opts) {
398
- memo = opts.memo;
399
- }
549
+ let memo = optsMemo;
400
550
  if (forwardInfo) {
401
551
  // pass opts.memo as forward.next, if present
402
552
  memo = JSON.stringify({
403
553
  forward: {
404
554
  ...forwardInfo.forward,
405
- next: memo,
555
+ ...(memo === undefined ? {} : { next: memo }),
406
556
  },
407
557
  });
408
558
  }
409
559
  const transferMsg = MsgTransfer.typedJson({
410
560
  ...transferDetails,
411
561
  sender: this.state.address.value,
412
- timeoutHeight: opts?.timeoutHeight,
562
+ timeoutHeight,
413
563
  timeoutTimestamp,
414
564
  memo,
415
565
  });
@@ -419,18 +569,51 @@ export const prepareLocalOrchestrationAccountKit = (
419
569
  /** @type {any} */ (holder),
420
570
  transferMsg,
421
571
  );
572
+
573
+ /** @type {SliceDescriptor | undefined} */
574
+ let trafficSlice;
575
+ const progressTracker = opts?.progressTracker;
576
+ if (progressTracker) {
577
+ const priorReport = progressTracker.getCurrentProgressReport();
578
+
579
+ const { traffic, slice } = addTrafficEntries(
580
+ priorReport.traffic,
581
+ // Sequence number is not known at this stage; it will be
582
+ // populated by IBCTransferSenderKit['responseWatcher'] once the
583
+ // transfer packet is sent and the sequence number is assigned.
584
+ trafficTransforms.IbcTransfer.start(
585
+ `${srcChainInfo.namespace}:${srcChainInfo.reference}`,
586
+ `${dstChainInfo.namespace}:${dstChainInfo.reference}`,
587
+ transferChannel,
588
+ ),
589
+ );
590
+ trafficSlice = slice;
591
+
592
+ const newMeta = {
593
+ ...priorReport,
594
+ traffic,
595
+ };
596
+
597
+ progressTracker.update(newMeta);
598
+ }
599
+
422
600
  // Begin capturing packets, send the transfer packet, then return a
423
601
  // vow that rejects unless the packet acknowledgment comes back and is
424
602
  // verified.
425
- return holder.sendThenWaitForAck(sender);
603
+ return holder.sendThenWaitForAck(sender, {
604
+ ...packetOpts,
605
+ trafficSlice,
606
+ });
426
607
  },
427
608
  },
428
- /**
429
- * takes an array of results (from `executeEncodedTx`) and returns the
430
- * first result
431
- */
432
609
  extractFirstResultWatcher: {
433
- /** @param {Record<unknown, unknown>[]} results */
610
+ /**
611
+ * Takes an array of results (from `executeTx`) and returns the first
612
+ * result element.
613
+ *
614
+ * @param {Record<PropertyKey, unknown>[]} results
615
+ * @returns {Record<PropertyKey, unknown>}
616
+ */
434
617
  onFulfilled(results) {
435
618
  results.length === 1 ||
436
619
  Fail`expected exactly one result; got ${results}`;
@@ -516,12 +699,25 @@ export const prepareLocalOrchestrationAccountKit = (
516
699
  },
517
700
  parseInboundTransferWatcher: {
518
701
  /**
519
- * @param {QueryDenomHashResponse} localDenomHash
702
+ * @param {{ error?: string; reply: TypedJson<string> }[]
703
+ * | TypedJson<string>} result
520
704
  * @param {Awaited<
521
705
  * ReturnType<LocalAccountMethods['parseInboundTransfer']>
522
706
  * >} naiveResult
523
707
  */
524
- onFulfilled(localDenomHash, naiveResult) {
708
+ onFulfilled(result, naiveResult) {
709
+ const { error, reply } = extractFirstQueryResult(result);
710
+
711
+ // For the success case, error could be undefined or ''.
712
+ if (error) {
713
+ if (error.includes(ErrTraceNotFound)) {
714
+ // Looks like the trace was not found; The naive result is good enough.
715
+ return naiveResult;
716
+ }
717
+ throw Error(`IBC denom trace query failed: ${error}`);
718
+ }
719
+
720
+ const localDenomHash = QueryDenomHashResponse.fromTyped(reply);
525
721
  const localDenom = `ibc/${localDenomHash.hash}`;
526
722
  const { amount, ...rest } = naiveResult;
527
723
  const { denom: _, ...amountRest } = amount;
@@ -539,7 +735,7 @@ export const prepareLocalOrchestrationAccountKit = (
539
735
  onRejected(reason, naiveResult) {
540
736
  if (
541
737
  reason instanceof Error &&
542
- String(reason.message).includes('denomination trace not found')
738
+ String(reason.message).includes(ErrTraceNotFound)
543
739
  ) {
544
740
  // Looks like the trace was not found; The naive result is good enough.
545
741
  return naiveResult;
@@ -549,18 +745,21 @@ export const prepareLocalOrchestrationAccountKit = (
549
745
  },
550
746
  },
551
747
  holder: {
748
+ /** @type {OrchestrationAccountCommon['makeProgressTracker']} */
749
+ makeProgressTracker() {
750
+ return makeProgressTracker();
751
+ },
752
+
552
753
  /** @type {HostOf<OrchestrationAccountCommon['asContinuingOffer']>} */
553
754
  asContinuingOffer() {
554
- // @ts-expect-error XXX invitationMakers
555
755
  // getPublicTopics resolves promptly (same run), so we don't need a watcher
556
756
  // eslint-disable-next-line no-restricted-syntax
557
757
  return asVow(async () => {
558
758
  await null;
559
759
  const { holder, invitationMakers: im } = this.facets;
560
760
  // XXX cast to a type that has string index signature
561
- const invitationMakers = /** @type {InvitationMakers} */ (
562
- /** @type {unknown} */ (im)
563
- );
761
+ const invitationMakers =
762
+ /** @type {HostInterface<InvitationMakers> & typeof im} */ (im);
564
763
 
565
764
  return harden({
566
765
  // getPublicTopics returns a vow, for membrane compatibility.
@@ -679,10 +878,7 @@ export const prepareLocalOrchestrationAccountKit = (
679
878
  */
680
879
  /** @type {HostOf<LocalAccountMethods['deposit']>} */
681
880
  deposit(payment) {
682
- return watch(
683
- E(this.state.account).deposit(payment),
684
- this.facets.returnVoidWatcher,
685
- );
881
+ return watch(E(this.state.account).deposit(payment));
686
882
  },
687
883
  /** @type {HostOf<LocalAccountMethods['withdraw']>} */
688
884
  withdraw(amount) {
@@ -701,7 +897,7 @@ export const prepareLocalOrchestrationAccountKit = (
701
897
  *
702
898
  * @type {HostOf<OrchestrationAccountCommon['send']>}
703
899
  */
704
- send(toAccount, amount) {
900
+ send(toAccount, amount, _opts = {}) {
705
901
  return asVow(() => {
706
902
  trace('send', toAccount, amount);
707
903
  const cosmosDest = chainHub.coerceCosmosAddress(toAccount);
@@ -741,18 +937,7 @@ export const prepareLocalOrchestrationAccountKit = (
741
937
  );
742
938
  });
743
939
  },
744
- /**
745
- * @param {AccountIdArg} destination
746
- * @param {AmountArg} amount an ERTP {@link Amount} or a
747
- * {@link DenomAmount}
748
- * @param {IBCMsgTransferOptions} [opts] if either timeoutHeight or
749
- * timeoutTimestamp are not supplied, a default timeoutTimestamp will
750
- * be set for 5 minutes in the future
751
- * @returns {Vow<any>}
752
- * @throws {Error} if route is not determinable, asset is not
753
- * recognized, or the transfer is rejected (insufficient funds,
754
- * timeout)
755
- */
940
+ /** @type {HostOf<OrchestrationAccountCommon['transfer']>} */
756
941
  transfer(destination, amount, opts) {
757
942
  return asVow(() => {
758
943
  trace('Transferring funds over IBC');
@@ -762,19 +947,43 @@ export const prepareLocalOrchestrationAccountKit = (
762
947
  const { forwardOpts, ...rest } = opts ?? {};
763
948
 
764
949
  // throws if route is not determinable
950
+ const srcChainName = 'agoric';
765
951
  const route = chainHub.makeTransferRoute(
766
952
  destination,
767
953
  denomAmount,
768
- 'agoric',
954
+ srcChainName,
769
955
  forwardOpts,
770
956
  );
771
957
  trace('got transfer route', route);
772
958
 
959
+ const denomDetail = chainHub.getAsset(
960
+ denomAmount.denom,
961
+ srcChainName,
962
+ );
963
+ assert(denomDetail);
964
+
965
+ const { baseName: denomBaseName } = denomDetail;
966
+
967
+ const srcChainInfo = chainHub.getChainInfoByChainId(
968
+ chainOfAccount(this.state.address),
969
+ );
970
+
971
+ const nextChainInfo =
972
+ srcChainName === denomBaseName
973
+ ? chainHub.getChainInfoByChainId(chainOfAccount(destination))
974
+ : chainHub.getChainInfo(denomBaseName);
975
+
773
976
  // don't resolve the vow until the transfer is confirmed on remote
774
977
  // and reject vow if the transfer fails for any reason
775
978
  const resultV = watch(
776
- timestampHelper.vowOrValueFromOpts(opts),
777
- this.facets.transferWatcher,
979
+ vowTools.allVows(
980
+ /** @type {const} */ ([
981
+ srcChainInfo,
982
+ nextChainInfo,
983
+ timestampHelper.vowOrValueFromOpts(opts),
984
+ ]),
985
+ ),
986
+ this.facets.transferConnectionWatcher,
778
987
  {
779
988
  opts: rest,
780
989
  route,
@@ -836,11 +1045,11 @@ export const prepareLocalOrchestrationAccountKit = (
836
1045
 
837
1046
  // Find the local denom hash for the transferDenom, if there is one.
838
1047
  return watch(
839
- E(localchain).query(
1048
+ E(localchain).queryMany([
840
1049
  QueryDenomHashRequest.typedJson({
841
1050
  trace: denomOrTrace,
842
1051
  }),
843
- ),
1052
+ ]),
844
1053
  this.facets.parseInboundTransferWatcher,
845
1054
  buildReturnValue(denomOrTrace),
846
1055
  );