@agoric/orchestration 0.1.1-dev-6bf6362.0.6bf6362 → 0.1.1-dev-01b8bed.0.01b8bed

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 (34) hide show
  1. package/package.json +16 -16
  2. package/src/cosmos-api.d.ts +19 -1
  3. package/src/cosmos-api.d.ts.map +1 -1
  4. package/src/cosmos-api.ts +21 -0
  5. package/src/examples/auto-stake-it-tap-kit.d.ts +2 -2
  6. package/src/examples/auto-stake-it-tap-kit.d.ts.map +1 -1
  7. package/src/examples/auto-stake-it-tap-kit.js +2 -4
  8. package/src/examples/stake-bld.contract.d.ts +10 -2
  9. package/src/examples/stake-bld.contract.d.ts.map +1 -1
  10. package/src/examples/stake-ica.contract.d.ts +11 -1
  11. package/src/examples/stake-ica.contract.d.ts.map +1 -1
  12. package/src/exos/cosmos-orchestration-account.d.ts +78 -5
  13. package/src/exos/cosmos-orchestration-account.d.ts.map +1 -1
  14. package/src/exos/cosmos-orchestration-account.js +265 -39
  15. package/src/exos/ibc-packet.d.ts +19 -6
  16. package/src/exos/ibc-packet.d.ts.map +1 -1
  17. package/src/exos/ibc-packet.js +25 -5
  18. package/src/exos/local-orchestration-account.d.ts +41 -17
  19. package/src/exos/local-orchestration-account.d.ts.map +1 -1
  20. package/src/exos/local-orchestration-account.js +160 -24
  21. package/src/exos/packet-tools.d.ts +8 -2
  22. package/src/exos/packet-tools.d.ts.map +1 -1
  23. package/src/exos/packet-tools.js +61 -12
  24. package/src/orchestration-api.d.ts +18 -2
  25. package/src/orchestration-api.d.ts.map +1 -1
  26. package/src/orchestration-api.ts +21 -3
  27. package/src/utils/address.d.ts.map +1 -1
  28. package/src/utils/address.js +13 -2
  29. package/src/utils/cosmos.d.ts +5 -4
  30. package/src/utils/cosmos.d.ts.map +1 -1
  31. package/src/utils/cosmos.js +22 -9
  32. package/src/utils/orchestrationAccount.d.ts +16 -0
  33. package/src/utils/orchestrationAccount.d.ts.map +1 -1
  34. package/src/utils/orchestrationAccount.js +22 -2
@@ -40,9 +40,13 @@ import {
40
40
  MsgUndelegateResponse as MsgUndelegateResponseType,
41
41
  } from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js';
42
42
  import { Any as AnyType } from '@agoric/cosmic-proto/google/protobuf/any.js';
43
- import { MsgTransfer as MsgTransferType } from '@agoric/cosmic-proto/ibc/applications/transfer/v1/tx.js';
43
+ import {
44
+ MsgTransferResponse as MsgTransferResponseType,
45
+ MsgTransfer as MsgTransferType,
46
+ } from '@agoric/cosmic-proto/ibc/applications/transfer/v1/tx.js';
44
47
  import { makeTracer } from '@agoric/internal';
45
48
  import { Shape as NetworkShape } from '@agoric/network';
49
+ import { decodeIbcEndpoint } from '@agoric/vats/tools/ibc-utils.js';
46
50
  import { M } from '@agoric/vat-data';
47
51
  import { VowShape } from '@agoric/vow';
48
52
  import { decodeBase64 } from '@endo/base64';
@@ -66,7 +70,10 @@ import {
66
70
  toTruncatedDenomAmount,
67
71
  tryDecodeResponse,
68
72
  } from '../utils/cosmos.js';
69
- import { orchestrationAccountMethods } from '../utils/orchestrationAccount.js';
73
+ import {
74
+ orchestrationAccountMethods,
75
+ pickData,
76
+ } from '../utils/orchestrationAccount.js';
70
77
  import { makeTimestampHelper } from '../utils/time.js';
71
78
  import { accountIdTo32Bytes, parseAccountId } from '../utils/address.js';
72
79
 
@@ -123,10 +130,11 @@ const MsgUndelegate = CodecHelper(MsgUndelegateType);
123
130
  const MsgUndelegateResponse = CodecHelper(MsgUndelegateResponseType);
124
131
  const Any = CodecHelper(AnyType);
125
132
  const MsgTransfer = CodecHelper(MsgTransferType);
133
+ const MsgTransferResponse = CodecHelper(MsgTransferResponseType);
126
134
 
127
135
  /**
128
136
  * @import {HostOf} from '@agoric/async-flow';
129
- * @import {AmountArg, IcaAccount, CosmosChainAddress, CosmosValidatorAddress, ICQConnection, StakingAccountActions, StakingAccountQueries, NobleMethods, OrchestrationAccountCommon, CosmosRewardsResponse, IBCConnectionInfo, IBCMsgTransferOptions, ChainHub, CosmosDelegationResponse, CaipChainId, AccountIdArg} from '../types.js';
137
+ * @import {AmountArg, IcaAccount, CosmosChainAddress, CosmosValidatorAddress, ICQConnection, StakingAccountActions, StakingAccountQueries, NobleMethods, OrchestrationAccountCommon, CosmosRewardsResponse, IBCConnectionInfo, IBCMsgTransferOptions, ChainHub, CosmosDelegationResponse, CaipChainId, AccountIdArg, ChainInfo, MetaTrafficEntry} from '../types.js';
130
138
  * @import {ContractMeta, Invitation, OfferHandler, ZCF, ZCFSeat} from '@agoric/zoe';
131
139
  * @import {RecorderKit, MakeRecorderKit} from '@agoric/zoe/src/contractSupport/recorder.js';
132
140
  * @import {Coin} from '@agoric/cosmic-proto/cosmos/base/v1beta1/coin.js';
@@ -134,18 +142,22 @@ const MsgTransfer = CodecHelper(MsgTransferType);
134
142
  * @import {DelegationResponse} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/staking.js';
135
143
  * @import {InvitationMakers} from '@agoric/smart-wallet/src/types.js';
136
144
  * @import {TimerService} from '@agoric/time';
137
- * @import {Vow, VowTools} from '@agoric/vow';
145
+ * @import {Vow, VowTools, PromiseVow} from '@agoric/vow';
138
146
  * @import {Zone} from '@agoric/zone';
139
147
  * @import {ResponseQuery} from '@agoric/cosmic-proto/tendermint/abci/types.js';
140
- * @import {JsonSafe} from '@agoric/cosmic-proto';
148
+ * @import {AnyJson, JsonSafe} from '@agoric/cosmic-proto';
149
+ * @import {TxBody} from '@agoric/cosmic-proto/cosmos/tx/v1beta1/tx.js';
141
150
  * @import {Matcher} from '@endo/patterns';
142
151
  * @import {LocalIbcAddress, RemoteIbcAddress} from '@agoric/vats/tools/ibc-utils.js';
152
+ * @import {SendOptions} from '@agoric/network';
143
153
  */
144
154
 
145
155
  const trace = makeTracer('CosmosOrchAccount');
146
156
 
147
157
  const { Vow$ } = NetworkShape; // TODO #9611
148
158
 
159
+ const EVow$ = shape => M.or(Vow$(shape), M.promise(/* shape */));
160
+
149
161
  /**
150
162
  * @typedef {object} CosmosOrchestrationAccountNotification
151
163
  * @property {CosmosChainAddress} chainAddress
@@ -241,6 +253,9 @@ export const IcaAccountHolderI = M.interface('IcaAccountHolder', {
241
253
  executeEncodedTx: M.call(M.arrayOf(Proto3Shape))
242
254
  .optional(ExecuteICATxOptsShape)
243
255
  .returns(VowShape),
256
+ executeEncodedTxWithMeta: M.call(M.arrayOf(Proto3Shape))
257
+ .optional(ExecuteICATxOptsShape)
258
+ .returns(EVow$({ result: EVow$(M.any()), meta: M.record({}) })),
244
259
  });
245
260
 
246
261
  /** @type {{ [name: string]: [description: string, valueShape: Matcher] }} */
@@ -290,6 +305,21 @@ export const prepareCosmosOrchestrationAccountKit = (
290
305
  zcf,
291
306
  },
292
307
  ) => {
308
+ /**
309
+ * Use a WeakMapStore to memoize some additional details about the ICA
310
+ * Account.
311
+ *
312
+ * @type {import('@agoric/store').WeakMapStore<
313
+ * IcaAccount,
314
+ * {
315
+ * agoric: ChainInfo<'cosmos'>;
316
+ * la: LocalIbcAddress;
317
+ * counterparty: CaipChainId;
318
+ * ra: RemoteIbcAddress;
319
+ * }
320
+ * >}
321
+ */
322
+ const icaAccountToDetails = zone.weakMapStore('icaAccountToDetails');
293
323
  const timestampHelper = makeTimestampHelper(timerService);
294
324
  const makeCosmosOrchestrationAccountKit = zone.exoClassKit(
295
325
  'Cosmos Orchestration Account Holder',
@@ -299,6 +329,14 @@ export const prepareCosmosOrchestrationAccountKit = (
299
329
  getUpdater: M.call().returns(M.remotable()),
300
330
  amountToCoin: M.call(AmountArgShape).returns(M.record()),
301
331
  }),
332
+ attachTxMetaWatcher: M.interface('attachTxMetaWatcher', {
333
+ onFulfilled: M.call(
334
+ M.arrayOf(M.any()),
335
+ EVow$(M.splitRecord({ result: EVow$(M.any()), meta: M.record() })),
336
+ M.string(),
337
+ ).returns(EVow$(M.any())),
338
+ }),
339
+ pickDataWatcher: pickData.shape,
302
340
  returnVoidWatcher: M.interface('returnVoidWatcher', {
303
341
  onFulfilled: M.call(M.any())
304
342
  .optional(M.arrayOf(M.undefined()))
@@ -325,6 +363,18 @@ export const prepareCosmosOrchestrationAccountKit = (
325
363
  .returns(M.arrayOf(DenomAmountShape)),
326
364
  }),
327
365
  transferWatcher: M.interface('transferWatcher', {
366
+ onFulfilled: M.call(M.nat())
367
+ .optional({
368
+ destination: CosmosChainAddressShape,
369
+ opts: M.or(M.undefined(), IBCTransferOptionsShape),
370
+ token: {
371
+ denom: M.string(),
372
+ amount: M.string(),
373
+ },
374
+ })
375
+ .returns(Vow$(M.any())),
376
+ }),
377
+ transferWithMetaWatcher: M.interface('transferWithMetaWatcher', {
328
378
  onFulfilled: M.call([M.record(), M.nat()])
329
379
  .optional({
330
380
  destination: CosmosChainAddressShape,
@@ -334,7 +384,12 @@ export const prepareCosmosOrchestrationAccountKit = (
334
384
  amount: M.string(),
335
385
  },
336
386
  })
337
- .returns(Vow$(M.record())),
387
+ .returns(Vow$({ result: Vow$(M.any()), meta: M.record() })),
388
+ }),
389
+ parseTransferWatcher: M.interface('parseTransferWatcher', {
390
+ onFulfilled: M.call([M.string(), M.record()], M.record()).returns(
391
+ Vow$(M.record()),
392
+ ),
338
393
  }),
339
394
  delegationQueryWatcher: M.interface('delegationQueryWatcher', {
340
395
  onFulfilled: M.call(M.arrayOf(M.record())).returns(M.record()),
@@ -449,6 +504,62 @@ export const prepareCosmosOrchestrationAccountKit = (
449
504
  return coerceCoin(chainHub, amount);
450
505
  },
451
506
  },
507
+ attachTxMetaWatcher: {
508
+ /**
509
+ * TODO(#1994): Subsume with IcaAccount.executeEncodedTxWithMeta().
510
+ *
511
+ * @param {[
512
+ * agoric: ChainInfo<'cosmos'>,
513
+ * la: LocalIbcAddress,
514
+ * counterparty: CaipChainId,
515
+ * ra: RemoteIbcAddress,
516
+ * ]} param0
517
+ * @param {{ result: Vow<any>; meta: Record<string, any> }} param1
518
+ * @param {string} protocol
519
+ */
520
+ onFulfilled(
521
+ [agoric, la, counterparty, ra],
522
+ { result, meta: origMeta },
523
+ protocol,
524
+ ) {
525
+ const { helper } = this.facets;
526
+ const acct = helper.owned();
527
+ if (!icaAccountToDetails.has(acct)) {
528
+ // Memoize the details for next time.
529
+ icaAccountToDetails.init(
530
+ acct,
531
+ harden({ agoric, la, counterparty, ra }),
532
+ );
533
+ }
534
+
535
+ const cp = counterparty.split(':', 2);
536
+ const lad = decodeIbcEndpoint(la);
537
+ const rad = decodeIbcEndpoint(ra);
538
+
539
+ const meta = {
540
+ ...origMeta,
541
+ traffic: [
542
+ ...(origMeta.traffic || []),
543
+ /** @type {MetaTrafficEntry} */ ({
544
+ op: 'ICA',
545
+ src: [
546
+ protocol,
547
+ agoric.namespace,
548
+ agoric.reference,
549
+ lad.portID,
550
+ lad.channelID,
551
+ ],
552
+ dst: [protocol, cp[0], cp[1], rad.portID, rad.channelID],
553
+ // TODO(#11994): Need to expose from Network API `conn.sendWithMeta(...)`
554
+ // Unknown for now, so set it to null.
555
+ seq: null,
556
+ }),
557
+ ],
558
+ };
559
+ return harden({ result, meta });
560
+ },
561
+ },
562
+ pickDataWatcher: pickData.watcher,
452
563
  balanceQueryWatcher: {
453
564
  /**
454
565
  * @param {JsonSafe<ResponseQuery>[]} results
@@ -605,10 +716,7 @@ export const prepareCosmosOrchestrationAccountKit = (
605
716
  * @param {string} result
606
717
  */
607
718
  onFulfilled(result) {
608
- const response = tryDecodeResponse(
609
- result,
610
- MsgUndelegateResponse.fromProtoMsg,
611
- );
719
+ const response = tryDecodeResponse(result, MsgUndelegateResponse);
612
720
  trace('undelegate response', response);
613
721
  const { completionTime } = response;
614
722
  completionTime || Fail`No completion time result ${result}`;
@@ -634,7 +742,7 @@ export const prepareCosmosOrchestrationAccountKit = (
634
742
  onFulfilled(result) {
635
743
  const response = tryDecodeResponse(
636
744
  result,
637
- MsgWithdrawDelegatorRewardResponse.fromProtoMsg,
745
+ MsgWithdrawDelegatorRewardResponse,
638
746
  );
639
747
  trace('withdrawReward response', response);
640
748
  const { amount: coins } = response;
@@ -642,6 +750,11 @@ export const prepareCosmosOrchestrationAccountKit = (
642
750
  },
643
751
  },
644
752
  transferWatcher: {
753
+ onFulfilled(...args) {
754
+ throw Fail`obsolete transferWatcher(${args}); please retry`;
755
+ },
756
+ },
757
+ transferWithMetaWatcher: {
645
758
  /**
646
759
  * @param {[
647
760
  * { transferChannel: IBCConnectionInfo['transferChannel'] },
@@ -657,7 +770,8 @@ export const prepareCosmosOrchestrationAccountKit = (
657
770
  [{ transferChannel }, timeoutTimestamp],
658
771
  { opts, token, destination },
659
772
  ) {
660
- const results = E(this.facets.helper.owned()).executeEncodedTx([
773
+ const { chainAddress } = this.state;
774
+ const resultMeta = this.facets.holder.executeEncodedTxWithMeta([
661
775
  Any.toJSON(
662
776
  MsgTransfer.toProtoMsg({
663
777
  sourcePort: transferChannel.portId,
@@ -671,7 +785,68 @@ export const prepareCosmosOrchestrationAccountKit = (
671
785
  }),
672
786
  ),
673
787
  ]);
674
- return watch(results, this.facets.returnVoidWatcher);
788
+ const result = watch(
789
+ resultMeta,
790
+ this.facets.pickDataWatcher,
791
+ 'result',
792
+ );
793
+ const meta = watch(resultMeta, this.facets.pickDataWatcher, 'meta');
794
+ const transferTraffic = /** @type {MetaTrafficEntry} */ ({
795
+ op: 'transfer',
796
+ src: [
797
+ 'ibc',
798
+ 'cosmos',
799
+ chainAddress.chainId,
800
+ transferChannel.portId,
801
+ transferChannel.channelId,
802
+ ],
803
+ dst: [
804
+ 'ibc',
805
+ 'cosmos',
806
+ destination.chainId,
807
+ transferChannel.counterPartyPortId,
808
+ transferChannel.counterPartyChannelId,
809
+ ],
810
+ });
811
+ return watch(
812
+ allVows([result, meta]),
813
+ this.facets.parseTransferWatcher,
814
+ transferTraffic,
815
+ );
816
+ },
817
+ },
818
+ parseTransferWatcher: {
819
+ onFulfilled([transferResp, baseMeta], transferTraffic) {
820
+ trace('parseTransferWatcher', {
821
+ submitted: transferResp,
822
+ baseMeta,
823
+ transferTraffic,
824
+ });
825
+ const { sequence } = tryDecodeResponse(
826
+ transferResp,
827
+ MsgTransferResponse,
828
+ );
829
+ const baseSequence = transferTraffic?.seq;
830
+ baseSequence == null ||
831
+ Fail`expected traffic?.seq ${baseSequence} to be nullish`;
832
+ sequence != null ||
833
+ Fail`expected MsgTransferResponse.sequence ${sequence} to be non-nullish`;
834
+
835
+ /** @type {Record<string, any>} */
836
+ const meta = {
837
+ ...baseMeta,
838
+ traffic: [
839
+ ...(baseMeta.traffic || []),
840
+ { ...transferTraffic, seq: sequence },
841
+ ],
842
+ };
843
+ // Result is unknown, so return Vow<undefined>, even though our meta is good.
844
+ // XXX would be good to use a resolver promise to indicate acknowledgement.
845
+ const resMeta = harden({
846
+ result: watch(null),
847
+ meta,
848
+ });
849
+ return resMeta;
675
850
  },
676
851
  },
677
852
  invitationMakers: {
@@ -772,7 +947,7 @@ export const prepareCosmosOrchestrationAccountKit = (
772
947
  Transfer() {
773
948
  /**
774
949
  * @type {OfferHandler<
775
- * Vow<void>,
950
+ * Vow<any>,
776
951
  * {
777
952
  * amount: AmountArg;
778
953
  * destination: AccountIdArg;
@@ -843,16 +1018,18 @@ export const prepareCosmosOrchestrationAccountKit = (
843
1018
 
844
1019
  const amountAsCoin = helper.amountToCoin(amount);
845
1020
 
846
- const results = E(helper.owned()).executeEncodedTx([
847
- Any.toJSON(
848
- MsgDelegate.toProtoMsg({
849
- delegatorAddress: chainAddress.value,
850
- validatorAddress: validator.value,
851
- amount: amountAsCoin,
852
- }),
853
- ),
854
- ]);
855
- return watch(results, this.facets.returnVoidWatcher);
1021
+ return watch(
1022
+ E(helper.owned()).executeEncodedTx([
1023
+ Any.toJSON(
1024
+ MsgDelegate.toProtoMsg({
1025
+ delegatorAddress: chainAddress.value,
1026
+ validatorAddress: validator.value,
1027
+ amount: amountAsCoin,
1028
+ }),
1029
+ ),
1030
+ ]),
1031
+ this.facets.returnVoidWatcher,
1032
+ );
856
1033
  });
857
1034
  },
858
1035
 
@@ -981,34 +1158,31 @@ export const prepareCosmosOrchestrationAccountKit = (
981
1158
 
982
1159
  /** @type {HostOf<OrchestrationAccountCommon['transfer']>} */
983
1160
  transfer(destination, amount, opts) {
984
- trace('transfer', destination, amount, opts);
1161
+ const resultMeta = this.facets.holder.transferWithMeta(
1162
+ destination,
1163
+ amount,
1164
+ opts,
1165
+ );
1166
+ return watch(resultMeta, this.facets.pickDataWatcher, 'result');
1167
+ },
1168
+ /** @type {HostOf<OrchestrationAccountCommon['transferWithMeta']>} */
1169
+ transferWithMeta(destination, amount, opts) {
1170
+ trace('transferWithMeta', destination, amount, opts);
985
1171
  return asVow(() => {
986
- // `destination` arg can be non-Cosmos per the common `.transfer` method signature
987
- // but this implementation only supports transferring to another Cosmos chain.
988
- // It relies on `coerceCosmosChainAddress` to throw if `destination` has another namespace.
989
-
990
1172
  const cosmosDest = chainHub.coerceCosmosAddress(destination);
991
-
992
1173
  const { helper } = this.facets;
993
1174
  const token = helper.amountToCoin(amount);
994
1175
 
995
1176
  const connectionInfoV = watch(
996
- chainHub.getConnectionInfo(
997
- this.state.chainAddress.chainId,
998
- cosmosDest.chainId,
999
- ),
1177
+ chainHub.getConnectionInfo(this.state.chainAddress, cosmosDest),
1000
1178
  );
1001
1179
 
1002
- // Resolves when host chain successfully submits, but not when
1003
- // the receiving chain acknowledges.
1004
- // See https://github.com/Agoric/agoric-sdk/issues/9784 for a
1005
- // solution that tracks the acknowledgement on the receiving chain.
1006
1180
  return watch(
1007
1181
  allVows([
1008
1182
  connectionInfoV,
1009
1183
  timestampHelper.vowOrValueFromOpts(opts),
1010
1184
  ]),
1011
- this.facets.transferWatcher,
1185
+ this.facets.transferWithMetaWatcher,
1012
1186
  { opts, token, destination: cosmosDest },
1013
1187
  );
1014
1188
  });
@@ -1202,6 +1376,58 @@ export const prepareCosmosOrchestrationAccountKit = (
1202
1376
  watch(E(this.facets.helper.owned()).executeEncodedTx(msgs, opts)),
1203
1377
  );
1204
1378
  },
1379
+ // TODO(#11944): When IcaAccount is upgraded to provide this method directly, use it.
1380
+ // /** @type {HostOf<IcaAccount['executeEncodedTxWithMeta']>} */
1381
+ // executeEncodedTxWithMeta(msgs, opts = {}) {
1382
+ // return asVow(() =>
1383
+ // E(this.facets.helper.owned()).executeEncodedTxWithMeta(msgs, opts),
1384
+ // );
1385
+ // },
1386
+ /**
1387
+ * Submit a transaction on behalf of the remote account for execution on
1388
+ * the remote chain.
1389
+ *
1390
+ * Set `relativeTimeoutNs` to provide a timeout for the IBC packet.
1391
+ *
1392
+ * `TxBody` fields like `timeoutHeight` and `memo` can be set, but these
1393
+ * typically do not affect IBC app protocols like PFM, ICA.
1394
+ *
1395
+ * @param {AnyJson[]} msgs
1396
+ * @param {Partial<Omit<TxBody, 'messages'>> & {
1397
+ * sendOpts?: SendOptions;
1398
+ * }} [opts]
1399
+ * @returns {Vow<{ result: Vow<string>; meta: Record<string, any> }>}
1400
+ * .result is a vow for a base64 encoded bytes string. Can be decoded
1401
+ * using `tryDecodeResponses`.
1402
+ * @throws {Error} if packet fails to send or an error is returned
1403
+ */
1404
+ executeEncodedTxWithMeta(msgs, opts = {}) {
1405
+ return asVow(() => {
1406
+ const { chainAddress } = this.state;
1407
+ const { helper } = this.facets;
1408
+ const acct = helper.owned();
1409
+ const result = watch(E(acct).executeEncodedTx(msgs, opts));
1410
+ const all = [];
1411
+ if (icaAccountToDetails.has(acct)) {
1412
+ const { agoric, la, counterparty, ra } =
1413
+ icaAccountToDetails.get(acct);
1414
+ all.push(agoric, la, counterparty, ra);
1415
+ } else {
1416
+ const agoric = chainHub.getChainInfo('agoric');
1417
+ const la = E(acct).getLocalAddress();
1418
+ const counterparty = `cosmos:${chainAddress.chainId}`;
1419
+ const ra = E(acct).getRemoteAddress();
1420
+
1421
+ all.push(agoric, la, counterparty, ra);
1422
+ }
1423
+ return watch(
1424
+ allVows(all),
1425
+ this.facets.attachTxMetaWatcher,
1426
+ { result, meta: {} },
1427
+ 'ibc',
1428
+ );
1429
+ });
1430
+ },
1205
1431
  /**
1206
1432
  * @type {HostOf<NobleMethods['depositForBurn']>}
1207
1433
  */
@@ -1,4 +1,5 @@
1
- export const ICS20_TRANSFER_SUCCESS_RESULT: "AQ==";
1
+ export const ICS20_TRANSFER_SUCCESS_BYTES: "\u0001";
2
+ export const ICS20_TRANSFER_SUCCESS_RESULT: string;
2
3
  export function createSequencePattern(sequence: any): Pattern;
3
4
  export function prepareIBCTransferSender(zone: import("@agoric/base-zone").Zone, { watch, makeIBCReplyKit }: VowTools & {
4
5
  makeIBCReplyKit: MakeIBCReplyKit;
@@ -15,8 +16,11 @@ export function prepareIBCTransferSender(zone: import("@agoric/base-zone").Zone,
15
16
  * @param {PacketOptions} opts
16
17
  */
17
18
  sendPacket(match: Vow<IBCEvent<"acknowledgementPacket"> | IBCEvent<"timeoutPacket">>, opts: PacketOptions): Vow<{
19
+ meta: {
20
+ traffic: any[];
21
+ };
18
22
  eventPattern: import("@endo/patterns").Matcher;
19
- resultV: Vow<void>;
23
+ resultV: Vow<string>;
20
24
  }>;
21
25
  };
22
26
  responseWatcher: {
@@ -41,12 +45,15 @@ export function prepareIBCTransferSender(zone: import("@agoric/base-zone").Zone,
41
45
  opts: PacketOptions;
42
46
  match: Vow<IBCEvent<"acknowledgementPacket"> | IBCEvent<"timeoutPacket">>;
43
47
  }): {
48
+ meta: {
49
+ traffic: any[];
50
+ };
44
51
  eventPattern: import("@endo/patterns").Matcher;
45
- resultV: Vow<void>;
52
+ resultV: Vow<string>;
46
53
  };
47
54
  };
48
55
  verifyTransferSuccess: {
49
- onFulfilled(ackData: any): void;
56
+ onFulfilled(ackData: any): string;
50
57
  };
51
58
  }>>) => import("@endo/exo").Guarded<{
52
59
  /**
@@ -56,8 +63,11 @@ export function prepareIBCTransferSender(zone: import("@agoric/base-zone").Zone,
56
63
  * @param {PacketOptions} opts
57
64
  */
58
65
  sendPacket(match: Vow<IBCEvent<"acknowledgementPacket"> | IBCEvent<"timeoutPacket">>, opts: PacketOptions): Vow<{
66
+ meta: {
67
+ traffic: any[];
68
+ };
59
69
  eventPattern: import("@endo/patterns").Matcher;
60
- resultV: Vow<void>;
70
+ resultV: Vow<string>;
61
71
  }>;
62
72
  }>;
63
73
  export function prepareIBCReplyKit(zone: import("@agoric/base-zone").Zone, vowTools: VowTools): <E extends IBCEvent<"acknowledgementPacket"> | IBCEvent<"timeoutPacket"> = IBCEvent<"acknowledgementPacket"> | IBCEvent<"timeoutPacket">>(replyPacketPattern: Pattern, matchV: Vow<E>, opts: PacketOptions) => {
@@ -77,8 +87,11 @@ export function prepareIBCTools(zone: import("@agoric/base-zone").Zone, vowTools
77
87
  * @param {PacketOptions} opts
78
88
  */
79
89
  sendPacket(match: Vow<IBCEvent<"acknowledgementPacket"> | IBCEvent<"timeoutPacket">>, opts: PacketOptions): Vow<{
90
+ meta: {
91
+ traffic: any[];
92
+ };
80
93
  eventPattern: import("@endo/patterns").Matcher;
81
- resultV: Vow<void>;
94
+ resultV: Vow<string>;
82
95
  }>;
83
96
  }>;
84
97
  makeIBCReplyKit: <E extends IBCEvent<"acknowledgementPacket"> | IBCEvent<"timeoutPacket"> = IBCEvent<"acknowledgementPacket"> | IBCEvent<"timeoutPacket">>(replyPacketPattern: Pattern, matchV: Vow<E>, opts: PacketOptions) => {
@@ -1 +1 @@
1
- {"version":3,"file":"ibc-packet.d.ts","sourceRoot":"","sources":["ibc-packet.js"],"names":[],"mappings":"AAMA,4CAA6C,MAAM,CAAC;AAsB7C,gDAHI,GAAG,GACD,OAAO,CAgCnB;AAOM,+CAHI,OAAO,mBAAmB,EAAE,IAAI,8BAChC,QAAQ,GAAG;IAAE,eAAe,EAAE,eAAe,CAAA;CAAE,IA2HhD,GAAG,MAFA,UAAU;eAvGH,iBAAiB,CAAC,WAAW,CAAC;;;;;QAU1C;;;;;WAKG;0BAJQ,IACV,SAAa,uBAAuB,CAAC,GAAG,SAAS,eAAe,CAAC,CAC9D,QACO,aAAa;;;;;;QAYxB;;;;;;;;;;;;;;;;WAgBG;oCAb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
5
 
6
6
  // As specified in ICS20, the success result is a base64-encoded '\0x1' byte.
7
- export const ICS20_TRANSFER_SUCCESS_RESULT = 'AQ==';
7
+ export const ICS20_TRANSFER_SUCCESS_BYTES = '\x01';
8
+ export const ICS20_TRANSFER_SUCCESS_RESULT = btoa(ICS20_TRANSFER_SUCCESS_BYTES);
8
9
 
9
10
  const trace = makeTracer('IBCP');
10
11
 
11
12
  /**
12
13
  * @import {Key, Pattern} from '@endo/patterns';
13
14
  * @import {JsonSafe, TypedJson, ResponseTo} from '@agoric/cosmic-proto';
15
+ * @import {Bytes} from '@agoric/network';
14
16
  * @import {Vow, VowTools} from '@agoric/vow';
15
17
  * @import {IBCEvent, IBCPacket} from '@agoric/vats';
16
18
  * @import {LocalChainAccount} from '@agoric/vats/src/localchain.js';
@@ -68,13 +70,13 @@ export const prepareIBCTransferSender = (zone, { watch, makeIBCReplyKit }) => {
68
70
  'IBCTransferSenderKit',
69
71
  {
70
72
  public: M.interface('IBCTransferSender', {
71
- sendPacket: M.call(Vow$(M.any()), M.any()).returns(Vow$(M.record())),
73
+ sendPacket: M.call(Vow$(M.any()), M.record()).returns(Vow$(M.record())),
72
74
  }),
73
75
  responseWatcher: M.interface('responseWatcher', {
74
76
  onFulfilled: M.call([M.record()], M.record()).returns(M.any()),
75
77
  }),
76
78
  verifyTransferSuccess: M.interface('verifyTransferSuccess', {
77
- onFulfilled: M.call(M.any()).returns(),
79
+ onFulfilled: M.call(M.any()).returns(M.string()),
78
80
  }),
79
81
  },
80
82
  /**
@@ -143,7 +145,24 @@ export const prepareIBCTransferSender = (zone, { watch, makeIBCReplyKit }) => {
143
145
  { opName: 'transfer', ...opts },
144
146
  );
145
147
  const resultV = watch(ackDataV, this.facets.verifyTransferSuccess);
146
- return harden({ resultV, ...rest });
148
+
149
+ const baseMeta = opts?.meta ?? {};
150
+ const traffic = baseMeta.traffic ?? [];
151
+ const priorTraffic = traffic.slice(0, -1);
152
+ const thisTraffic = traffic.at(-1);
153
+
154
+ const meta = {
155
+ ...baseMeta,
156
+ traffic: [
157
+ ...priorTraffic,
158
+ {
159
+ ...thisTraffic,
160
+ seq: sequence,
161
+ },
162
+ ],
163
+ };
164
+
165
+ return harden({ resultV, ...rest, meta });
147
166
  },
148
167
  },
149
168
  verifyTransferSuccess: {
@@ -158,7 +177,7 @@ export const prepareIBCTransferSender = (zone, { watch, makeIBCReplyKit }) => {
158
177
  error === undefined || Fail`ICS20-1 transfer error ${error}`;
159
178
  result ?? Fail`Missing result in ICS20-1 transfer ack ${obj}`;
160
179
  if (result === ICS20_TRANSFER_SUCCESS_RESULT) {
161
- return; // OK, transfer was successful, nothing to do
180
+ return ICS20_TRANSFER_SUCCESS_RESULT; // OK, transfer was successful, return the result.
162
181
  }
163
182
 
164
183
  // Function to safely base64-decode and parse JSON
@@ -176,6 +195,7 @@ export const prepareIBCTransferSender = (zone, { watch, makeIBCReplyKit }) => {
176
195
 
177
196
  ibcAck?.result === ICS20_TRANSFER_SUCCESS_RESULT ||
178
197
  Fail`ICS20-1 transfer unsuccessful with ack result: ${outerDecoded}`;
198
+ return ICS20_TRANSFER_SUCCESS_RESULT;
179
199
  },
180
200
  },
181
201
  },