@agoric/smart-wallet 0.5.4-upgrade-14-dev-c8f9e7b.0 → 0.5.4-upgrade-16-dev-8879538.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.
@@ -59,7 +59,7 @@ const trace = makeTracer('SmrtWlt');
59
59
  * id: OfferId,
60
60
  * invitationSpec: import('./invitations').InvitationSpec,
61
61
  * proposal: Proposal,
62
- * offerArgs?: unknown
62
+ * offerArgs?: any
63
63
  * }} OfferSpec
64
64
  */
65
65
 
@@ -147,7 +147,7 @@ const trace = makeTracer('SmrtWlt');
147
147
  * address: string,
148
148
  * bank: ERef<import('@agoric/vats/src/vat-bank.js').Bank>,
149
149
  * currentStorageNode: StorageNode,
150
- * invitationPurse: Purse<'set'>,
150
+ * invitationPurse: Purse<'set', InvitationDetails>,
151
151
  * walletStorageNode: StorageNode,
152
152
  * }} UniqueParams
153
153
  *
@@ -171,9 +171,9 @@ const trace = makeTracer('SmrtWlt');
171
171
  *
172
172
  * @typedef {Readonly<UniqueParams & {
173
173
  * paymentQueues: MapStore<Brand, Array<Payment>>,
174
- * offerToInvitationMakers: MapStore<string, import('./types').RemoteInvitationMakers>,
174
+ * offerToInvitationMakers: MapStore<string, import('./types.js').InvitationMakers>,
175
175
  * offerToPublicSubscriberPaths: MapStore<string, Record<string, string>>,
176
- * offerToUsedInvitation: MapStore<string, Amount>,
176
+ * offerToUsedInvitation: MapStore<string, Amount<'set'>>,
177
177
  * purseBalances: MapStore<Purse, Amount>,
178
178
  * updateRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<UpdateRecord>,
179
179
  * currentRecorderKit: import('@agoric/zoe/src/contractSupport/recorder.js').RecorderKit<CurrentWalletRecord>,
@@ -456,6 +456,7 @@ export const prepareSmartWallet = (baggage, shared) => {
456
456
  }),
457
457
  };
458
458
 
459
+ // TODO move to top level so its type can be exported
459
460
  /**
460
461
  * Make the durable object to return, but taking some parameters that are awaited by a wrapping function.
461
462
  * This is necessary because the class kit construction helpers, `initState` and `finish` run synchronously
@@ -547,13 +548,11 @@ export const prepareSmartWallet = (baggage, shared) => {
547
548
  // publish purse's balance and changes
548
549
  const notifier = await E(purse).getCurrentAmountNotifier();
549
550
  const startP = E(notifier).getUpdateSince(undefined);
550
- // @ts-expect-error import watchPromise's type is unknown
551
551
  watchPromise(startP, handler, notifier);
552
552
  },
553
553
 
554
554
  watchNextBalance(handler, notifier, updateCount) {
555
555
  const nextP = E(notifier).getUpdateSince(updateCount);
556
- // @ts-expect-error import watchPromise's type is unknown
557
556
  watchPromise(nextP, handler, notifier);
558
557
  },
559
558
 
@@ -645,24 +644,47 @@ export const prepareSmartWallet = (baggage, shared) => {
645
644
  const offerSpec = liveOffers.get(seatId);
646
645
  const seat = liveOfferSeats.get(seatId);
647
646
 
648
- const invitation = invitationFromSpec(offerSpec.invitationSpec);
649
- watcherPromises.push(
650
- E.when(
651
- E(invitationIssuer).getAmountOf(invitation),
652
- invitationAmount => {
653
- const watcher = makeOfferWatcher(
654
- facets.helper,
655
- facets.deposit,
656
- offerSpec,
657
- address,
658
- invitationAmount,
659
- seat,
660
- );
661
- return watchOfferOutcomes(watcher, seat);
662
- },
663
- ),
664
- );
647
+ const watchOutcome = (async () => {
648
+ await null;
649
+ let invitationAmount = state.offerToUsedInvitation.has(
650
+ // @ts-expect-error older type allowed number
651
+ offerSpec.id,
652
+ )
653
+ ? state.offerToUsedInvitation.get(
654
+ // @ts-expect-error older type allowed number
655
+ offerSpec.id,
656
+ )
657
+ : undefined;
658
+ if (invitationAmount) {
659
+ facets.helper.logWalletInfo(
660
+ 'recovered invitation amount for offer',
661
+ offerSpec.id,
662
+ );
663
+ } else {
664
+ facets.helper.logWalletInfo(
665
+ 'inferring invitation amount for offer',
666
+ offerSpec.id,
667
+ );
668
+ const tempInvitation = invitationFromSpec(
669
+ offerSpec.invitationSpec,
670
+ );
671
+ invitationAmount =
672
+ await E(invitationIssuer).getAmountOf(tempInvitation);
673
+ void E(invitationIssuer).burn(tempInvitation);
674
+ }
675
+
676
+ const watcher = makeOfferWatcher(
677
+ facets.helper,
678
+ facets.deposit,
679
+ offerSpec,
680
+ address,
681
+ invitationAmount,
682
+ seat,
683
+ );
684
+ return watchOfferOutcomes(watcher, seat);
685
+ })();
665
686
  trace(`Repaired seat ${seatId} for wallet ${address}`);
687
+ watcherPromises.push(watchOutcome);
666
688
  }
667
689
 
668
690
  await Promise.all(watcherPromises);
@@ -711,6 +733,13 @@ export const prepareSmartWallet = (baggage, shared) => {
711
733
  }
712
734
  }
713
735
  },
736
+
737
+ /**
738
+ * @param {string} offerId
739
+ * @param {Amount<"set">} invitationAmount
740
+ * @param {import("./types.js").InvitationMakers} invitationMakers
741
+ * @param {import("./types.js").PublicSubscribers} publicSubscribers
742
+ */
714
743
  async addContinuingOffer(
715
744
  offerId,
716
745
  invitationAmount,
@@ -738,7 +767,6 @@ export const prepareSmartWallet = (baggage, shared) => {
738
767
  const { registry, invitationBrand } = shared;
739
768
 
740
769
  if (registry.has(brand)) {
741
- // @ts-expect-error virtual purse
742
770
  return E(state.bank).getPurse(brand);
743
771
  } else if (invitationBrand === brand) {
744
772
  return state.invitationPurse;
@@ -809,6 +837,7 @@ export const prepareSmartWallet = (baggage, shared) => {
809
837
  // When there is a purse deposit into it
810
838
  if (registry.has(brand)) {
811
839
  const purse = E(bank).getPurse(brand);
840
+ // @ts-expect-error narrow assetKind to 'nat'
812
841
  return E(purse).deposit(payment);
813
842
  } else if (invitationBrand === brand) {
814
843
  // @ts-expect-error narrow assetKind to 'set'
@@ -832,6 +861,10 @@ export const prepareSmartWallet = (baggage, shared) => {
832
861
 
833
862
  payments: {
834
863
  /**
864
+ * Withdraw the offered amount from the appropriate purse of this wallet.
865
+ *
866
+ * Save its amount in liveOfferPayments in case we need to reclaim the payment.
867
+ *
835
868
  * @param {AmountKeywordRecord} give
836
869
  * @param {OfferId} offerId
837
870
  * @returns {PaymentPKeywordRecord}
@@ -847,8 +880,8 @@ export const prepareSmartWallet = (baggage, shared) => {
847
880
  .getLiveOfferPayments()
848
881
  .init(offerId, brandPaymentRecord);
849
882
 
850
- // Add each payment to liveOfferPayments as it is withdrawn. If
851
- // there's an error partway through, we can recover the withdrawals.
883
+ // Add each payment amount to brandPaymentRecord as it is withdrawn. If
884
+ // there's an error later, we can use it to redeposit the correct amount.
852
885
  return objectMap(give, amount => {
853
886
  /** @type {Promise<Purse>} */
854
887
  const purseP = facets.helper.purseForBrand(amount.brand);
@@ -869,28 +902,43 @@ export const prepareSmartWallet = (baggage, shared) => {
869
902
  });
870
903
  },
871
904
 
905
+ /**
906
+ * Find the live payments for the offer and deposit them back in the appropriate purses.
907
+ *
908
+ * @param {OfferId} offerId
909
+ * @returns {Promise<Amount[]>}
910
+ */
872
911
  async tryReclaimingWithdrawnPayments(offerId) {
873
912
  const { facets } = this;
874
913
 
914
+ await null;
915
+
875
916
  const liveOfferPayments = facets.helper.getLiveOfferPayments();
876
917
  if (liveOfferPayments.has(offerId)) {
877
918
  const brandPaymentRecord = liveOfferPayments.get(offerId);
878
919
  if (!brandPaymentRecord) {
879
- return Promise.resolve(undefined);
920
+ return [];
880
921
  }
922
+ const out = [];
881
923
  // Use allSettled to ensure we attempt all the deposits, regardless of
882
924
  // individual rejections.
883
- return Promise.allSettled(
884
- Array.from(brandPaymentRecord.entries()).map(async ([b, p]) => {
925
+ await Promise.allSettled(
926
+ Array.from(brandPaymentRecord.entries()).map(([b, p]) => {
885
927
  // Wait for the withdrawal to complete. This protects against a
886
928
  // race when updating paymentToPurse.
887
929
  const purseP = facets.helper.purseForBrand(b);
888
930
 
889
931
  // Now send it back to the purse.
890
- return E(purseP).deposit(p);
932
+ return E(purseP)
933
+ .deposit(p)
934
+ .then(amt => {
935
+ out.push(amt);
936
+ });
891
937
  }),
892
938
  );
939
+ return harden(out);
893
940
  }
941
+ return [];
894
942
  },
895
943
  },
896
944
 
@@ -912,6 +960,7 @@ export const prepareSmartWallet = (baggage, shared) => {
912
960
 
913
961
  await null;
914
962
 
963
+ /** @type {UserSeat} */
915
964
  let seatRef;
916
965
  let watcher;
917
966
  try {
@@ -930,23 +979,23 @@ export const prepareSmartWallet = (baggage, shared) => {
930
979
 
931
980
  const invitation = invitationFromSpec(offerSpec.invitationSpec);
932
981
 
933
- const [paymentKeywordRecord, invitationAmount] = await Promise.all([
934
- proposal?.give &&
935
- deeplyFulfilledObject(
936
- facets.payments.withdrawGive(proposal.give, offerSpec.id),
937
- ),
938
- E(invitationIssuer).getAmountOf(invitation),
939
- ]);
982
+ const invitationAmount =
983
+ await E(invitationIssuer).getAmountOf(invitation);
940
984
 
941
985
  // 2. Begin executing offer
942
986
  // No explicit signal to user that we reached here but if anything above
943
987
  // failed they'd get an 'error' status update.
944
988
 
945
- /** @type {UserSeat} */
989
+ const withdrawnPayments =
990
+ proposal?.give &&
991
+ (await deeplyFulfilledObject(
992
+ facets.payments.withdrawGive(proposal.give, offerSpec.id),
993
+ ));
994
+
946
995
  seatRef = await E(zoe).offer(
947
996
  invitation,
948
997
  proposal,
949
- paymentKeywordRecord,
998
+ withdrawnPayments,
950
999
  offerSpec.offerArgs,
951
1000
  );
952
1001
  facets.helper.logWalletInfo(offerSpec.id, 'seated');
@@ -968,22 +1017,24 @@ export const prepareSmartWallet = (baggage, shared) => {
968
1017
 
969
1018
  // await so that any errors are caught and handled below
970
1019
  await watchOfferOutcomes(watcher, seatRef);
971
- } catch (err) {
972
- facets.helper.logWalletError('OFFER ERROR:', err);
1020
+ } catch (reason) {
1021
+ // This block only runs if the block above fails during one vat incarnation.
1022
+ facets.helper.logWalletError('IMMEDIATE OFFER ERROR:', reason);
973
1023
 
974
- // Notify the user
975
- if (err.upgradeMessage === 'vat upgraded') {
1024
+ // Update status to observers
1025
+ if (isUpgradeDisconnection(reason)) {
976
1026
  // The offer watchers will reconnect. Don't reclaim or exit
977
1027
  return;
978
1028
  } else if (watcher) {
979
- watcher.helper.updateStatus({ error: err.toString() });
1029
+ // The watcher's onRejected will updateStatus()
980
1030
  } else {
981
1031
  facets.helper.updateStatus({
982
- error: err.toString(),
1032
+ error: reason.toString(),
983
1033
  ...offerSpec,
984
1034
  });
985
1035
  }
986
1036
 
1037
+ // Backstop recovery, in case something very basic fails.
987
1038
  if (offerSpec?.proposal?.give) {
988
1039
  facets.payments
989
1040
  .tryReclaimingWithdrawnPayments(offerSpec.id)
@@ -995,15 +1046,9 @@ export const prepareSmartWallet = (baggage, shared) => {
995
1046
  );
996
1047
  }
997
1048
 
998
- if (seatRef) {
999
- void E.when(E(seatRef).hasExited(), hasExited => {
1000
- if (!hasExited) {
1001
- void E(seatRef).tryExit();
1002
- }
1003
- });
1004
- }
1005
-
1006
- throw err;
1049
+ // XXX tests rely on throwing immediate errors, not covering the
1050
+ // error handling in the event the failure is after an upgrade
1051
+ throw reason;
1007
1052
  }
1008
1053
  },
1009
1054
  /**
@@ -1014,6 +1059,19 @@ export const prepareSmartWallet = (baggage, shared) => {
1014
1059
  * @throws if the seat can't be found or E(seatRef).tryExit() fails.
1015
1060
  */
1016
1061
  async tryExitOffer(offerId) {
1062
+ const { facets } = this;
1063
+ const amts = await facets.payments
1064
+ .tryReclaimingWithdrawnPayments(offerId)
1065
+ .catch(e => {
1066
+ facets.helper.logWalletError(
1067
+ 'recovery failed reclaiming payments',
1068
+ e,
1069
+ );
1070
+ return [];
1071
+ });
1072
+ if (amts.length > 0) {
1073
+ facets.helper.logWalletInfo('reclaimed', amts, 'from', offerId);
1074
+ }
1017
1075
  const seatRef = this.state.liveOfferSeats.get(offerId);
1018
1076
  await E(seatRef).tryExit();
1019
1077
  },
@@ -1022,7 +1080,7 @@ export const prepareSmartWallet = (baggage, shared) => {
1022
1080
  /**
1023
1081
  * Umarshals the actionCapData and delegates to the appropriate action handler.
1024
1082
  *
1025
- * @param {import('@endo/marshal').CapData<string>} actionCapData of type BridgeAction
1083
+ * @param {import('@endo/marshal').CapData<string | null>} actionCapData of type BridgeAction
1026
1084
  * @param {boolean} [canSpend]
1027
1085
  * @returns {Promise<void>}
1028
1086
  */
@@ -1104,9 +1162,9 @@ export const prepareSmartWallet = (baggage, shared) => {
1104
1162
  },
1105
1163
  });
1106
1164
  },
1165
+ // TODO remove this and repairUnwatchedSeats once the repair has taken place.
1107
1166
  /**
1108
- * one-time use function. Remove this and repairUnwatchedSeats once the
1109
- * repair has taken place.
1167
+ * To be called once ever per wallet.
1110
1168
  *
1111
1169
  * @param {object} key
1112
1170
  */
@@ -1117,8 +1175,12 @@ export const prepareSmartWallet = (baggage, shared) => {
1117
1175
  return;
1118
1176
  }
1119
1177
 
1120
- void facets.helper.repairUnwatchedSeats();
1121
- void facets.helper.repairUnwatchedPurses();
1178
+ facets.helper.repairUnwatchedSeats().catch(e => {
1179
+ console.error('repairUnwatchedSeats rejection', e);
1180
+ });
1181
+ facets.helper.repairUnwatchedPurses().catch(e => {
1182
+ console.error('repairUnwatchedPurses rejection', e);
1183
+ });
1122
1184
  trace(`repaired wallet ${state.address}`);
1123
1185
  },
1124
1186
  },
@@ -1,4 +1,4 @@
1
1
  export namespace shape {
2
- const WalletBridgeMsg: import("@endo/patterns").Matcher;
2
+ let WalletBridgeMsg: import("@endo/patterns").Matcher;
3
3
  }
4
4
  //# sourceMappingURL=typeGuards.d.ts.map
package/src/types.d.ts CHANGED
@@ -5,10 +5,11 @@
5
5
  * Downside is it can't reference any ambient types, which most of agoric-sdk type are presently.
6
6
  */
7
7
 
8
- import type { ERef, FarRef } from '@endo/far';
8
+ import type { ERef } from '@endo/far';
9
9
  import type { CapData } from '@endo/marshal';
10
- import type { MsgWalletSpendAction } from '@agoric/cosmic-proto/swingset/msgs';
10
+ import type { agoric } from '@agoric/cosmic-proto';
11
11
  import type { AgoricNamesRemotes } from '@agoric/vats/tools/board-utils.js';
12
+ import type { StoredFacet } from '@agoric/internal/src/lib-chainStorage.js';
12
13
  import type { OfferSpec } from './offers.js';
13
14
 
14
15
  declare const CapDataShape: unique symbol;
@@ -21,10 +22,9 @@ declare const CapDataShape: unique symbol;
21
22
  */
22
23
  export type Petname = string | string[];
23
24
 
24
- export type RemotePurse<T = unknown> = FarRef<Purse<T>>;
25
-
26
- export type RemoteInvitationMakers = FarRef<
27
- Record<string, (...args: any[]) => Promise<Invitation>>
25
+ export type InvitationMakers = Record<
26
+ string,
27
+ (...args: any[]) => Promise<Invitation>
28
28
  >;
29
29
 
30
30
  export type PublicSubscribers = Record<string, ERef<StoredFacet>>;
@@ -34,20 +34,16 @@ export type Cell<T> = {
34
34
  set(val: T): void;
35
35
  };
36
36
 
37
- export type BridgeActionCapData = WalletCapData<
38
- import('./smartWallet.js').BridgeAction
39
- >;
40
-
41
37
  /**
42
38
  * Defined by walletAction struct in msg_server.go
43
39
  *
44
- * @see {MsgWalletSpendAction} and walletSpendAction in msg_server.go
40
+ * @see {agoric.swingset.MsgWalletAction} and walletSpendAction in msg_server.go
45
41
  */
46
42
  export type WalletActionMsg = {
47
43
  type: 'WALLET_ACTION';
48
44
  /** base64 of Uint8Array of bech32 data */
49
45
  owner: string;
50
- /** JSON of BridgeActionCapData */
46
+ /** JSON of marshalled BridgeAction */
51
47
  action: string;
52
48
  blockHeight: unknown; // int64
53
49
  blockTime: unknown; // int64
@@ -56,7 +52,7 @@ export type WalletActionMsg = {
56
52
  /**
57
53
  * Defined by walletSpendAction struct in msg_server.go
58
54
  *
59
- * @see {MsgWalletSpendAction} and walletSpendAction in msg_server.go
55
+ * @see {agoric.swingset.MsgWalletSpendAction} and walletSpendAction in msg_server.go
60
56
  */
61
57
  export type WalletSpendActionMsg = {
62
58
  type: 'WALLET_SPEND_ACTION';
package/src/utils.d.ts CHANGED
@@ -1,26 +1,26 @@
1
1
  export const NO_SMART_WALLET_ERROR: "no smart wallet";
2
- export function makeWalletStateCoalescer(invitationBrand?: Brand<"set"> | undefined): {
2
+ export function makeWalletStateCoalescer(invitationBrand?: globalThis.Brand<"set"> | undefined): {
3
3
  state: {
4
- invitationsReceived: Map<import("./offers").OfferId, {
5
- acceptedIn: import('./offers').OfferId;
4
+ invitationsReceived: Map<import("./offers.js").OfferId, {
5
+ acceptedIn: import("./offers.js").OfferId;
6
6
  description: string;
7
7
  instance: Instance;
8
8
  }>;
9
- offerStatuses: Map<import("./offers").OfferId, import("./offers").OfferStatus>;
10
- balances: Map<Brand<AssetKind>, Amount<AssetKind>>;
9
+ offerStatuses: Map<import("./offers.js").OfferId, import("./offers.js").OfferStatus>;
10
+ balances: Map<globalThis.Brand, globalThis.Amount>;
11
11
  };
12
- update: (updateRecord: import('./smartWallet').UpdateRecord | {}) => void;
12
+ update: (updateRecord: import("./smartWallet.js").UpdateRecord | {}) => void;
13
13
  };
14
- export function coalesceUpdates(updates: ERef<Subscriber<import('./smartWallet').UpdateRecord>>, invitationBrand?: Brand<"set"> | undefined): {
15
- invitationsReceived: Map<import("./offers").OfferId, {
16
- acceptedIn: import('./offers').OfferId;
14
+ export function coalesceUpdates(updates: ERef<Subscriber<import("./smartWallet.js").UpdateRecord>>, invitationBrand?: globalThis.Brand<"set"> | undefined): {
15
+ invitationsReceived: Map<import("./offers.js").OfferId, {
16
+ acceptedIn: import("./offers.js").OfferId;
17
17
  description: string;
18
18
  instance: Instance;
19
19
  }>;
20
- offerStatuses: Map<import("./offers").OfferId, import("./offers").OfferStatus>;
21
- balances: Map<Brand<AssetKind>, Amount<AssetKind>>;
20
+ offerStatuses: Map<import("./offers.js").OfferId, import("./offers.js").OfferStatus>;
21
+ balances: Map<globalThis.Brand, globalThis.Amount>;
22
22
  };
23
- export function assertHasData(follower: import('@agoric/casting').Follower<any>): Promise<void>;
24
- export function objectMapStoragePath(subscribers?: import("@agoric/zoe/src/contractSupport").TopicsRecord | import("./types.js").PublicSubscribers | undefined): ERef<Record<string, string>> | null;
25
- export type CoalescedWalletState = ReturnType<typeof makeWalletStateCoalescer>['state'];
23
+ export function assertHasData(follower: import("@agoric/casting").Follower<any>): Promise<void>;
24
+ export function objectMapStoragePath(subscribers?: import("@agoric/zoe/src/contractSupport/topics.js").TopicsRecord | import("./types.js").PublicSubscribers | undefined): ERef<Record<string, string>> | null;
25
+ export type CoalescedWalletState = ReturnType<typeof makeWalletStateCoalescer>["state"];
26
26
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAKA,sDAAuD;AAKhD;;;wBASmD,OAAO,UAAU,EAAE,OAAO;yBAAe,MAAM;sBAAY,QAAQ;;;;;2BAI/G,OAAO,eAAe,EAAE,YAAY,GAAG,EAAE;EA8DtD;AAaM,yCAHI,KAAK,WAAW,OAAO,eAAe,EAAE,YAAY,CAAC,CAAC;;oBA5EP,OAAO,UAAU,EAAE,OAAO;qBAAe,MAAM;kBAAY,QAAQ;;;;EAwF5H;AAMM,wCAHI,OAAO,iBAAiB,EAAE,QAAQ,CAAC,GAAG,CAAC,iBAYjD;AAQM,iKAFM,KAAK,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,IAAI,CAW/C;mCArDa,WAAW,+BAA+B,CAAC,CAAC,OAAO,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAIA,sDAAuD;AAKhD;;;wBASsD,OAAO,aAAa,EAAE,OAAO;yBAAe,MAAM;sBAAY,QAAQ;;;;;2BAIrH,OAAO,kBAAkB,EAAE,YAAY,GAAG,EAAE;EA8DzD;AAaM,yCAHI,IAAI,CAAC,UAAU,CAAC,OAAO,kBAAkB,EAAE,YAAY,CAAC,CAAC;;oBA5EP,OAAO,aAAa,EAAE,OAAO;qBAAe,MAAM;kBAAY,QAAQ;;;;EAwFlI;AAMM,wCAHI,OAAO,iBAAiB,EAAE,QAAQ,CAAC,GAAG,CAAC,iBAYjD;AAQM,2KAFM,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,IAAI,CAW/C;mCArDa,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC,OAAO,CAAC"}
package/src/utils.js CHANGED
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-undef-init */
2
1
  import { deeplyFulfilledObject, objectMap, makeTracer } from '@agoric/internal';
3
2
  import { observeIteration, subscribeEach } from '@agoric/notifier';
4
3
  import { E } from '@endo/far';
@@ -9,7 +8,7 @@ const trace = makeTracer('WUTIL', false);
9
8
 
10
9
  /** @param {Brand<'set'>} [invitationBrand] */
11
10
  export const makeWalletStateCoalescer = (invitationBrand = undefined) => {
12
- /** @type {Map<import('./offers').OfferId, import('./offers').OfferStatus>} */
11
+ /** @type {Map<import('./offers.js').OfferId, import('./offers.js').OfferStatus>} */
13
12
  const offerStatuses = new Map();
14
13
  /** @type {Map<Brand, Amount>} */
15
14
  const balances = new Map();
@@ -17,11 +16,11 @@ export const makeWalletStateCoalescer = (invitationBrand = undefined) => {
17
16
  /**
18
17
  * keyed by description; xxx assumes unique
19
18
  *
20
- * @type {Map<import('./offers').OfferId, { acceptedIn: import('./offers').OfferId, description: string, instance: Instance }>}
19
+ * @type {Map<import('./offers.js').OfferId, { acceptedIn: import('./offers.js').OfferId, description: string, instance: Instance }>}
21
20
  */
22
21
  const invitationsReceived = new Map();
23
22
 
24
- /** @param {import('./smartWallet').UpdateRecord | {}} updateRecord newer than previous */
23
+ /** @param {import('./smartWallet.js').UpdateRecord | {}} updateRecord newer than previous */
25
24
  const update = updateRecord => {
26
25
  if (!('updated' in updateRecord)) {
27
26
  return;
@@ -93,7 +92,7 @@ export const makeWalletStateCoalescer = (invitationBrand = undefined) => {
93
92
  * If this proves to be a problem we can add an option to this or a related
94
93
  * utility to reset state from RPC.
95
94
  *
96
- * @param {ERef<Subscriber<import('./smartWallet').UpdateRecord>>} updates
95
+ * @param {ERef<Subscriber<import('./smartWallet.js').UpdateRecord>>} updates
97
96
  * @param {Brand<'set'>} [invitationBrand]
98
97
  */
99
98
  export const coalesceUpdates = (updates, invitationBrand) => {
@@ -125,7 +124,7 @@ export const assertHasData = async follower => {
125
124
  /**
126
125
  * Handles the case of falsy argument so the caller can consistently await.
127
126
  *
128
- * @param {import('./types.js').PublicSubscribers | import('@agoric/zoe/src/contractSupport').TopicsRecord} [subscribers]
127
+ * @param {import('./types.js').PublicSubscribers | import('@agoric/zoe/src/contractSupport/index.js').TopicsRecord} [subscribers]
129
128
  * @returns {ERef<Record<string, string>> | null}
130
129
  */
131
130
  export const objectMapStoragePath = subscribers => {
@@ -1,10 +1,10 @@
1
1
  export namespace customTermsShape {
2
- const agoricNames: any;
3
- const board: any;
4
- const assetPublisher: any;
2
+ let agoricNames: globalThis.Pattern;
3
+ let board: globalThis.Pattern;
4
+ let assetPublisher: globalThis.Pattern;
5
5
  }
6
6
  export const privateArgsShape: import("@endo/patterns").Matcher;
7
- export function publishDepositFacet(address: string, wallet: import('./smartWallet.js').SmartWallet, namesByAddressAdmin: ERef<import('@agoric/vats').NameAdmin>): Promise<unknown>;
7
+ export function publishDepositFacet(address: string, wallet: import("./smartWallet.js").SmartWallet, namesByAddressAdmin: ERef<import("@agoric/vats").NameAdmin>): Promise<unknown>;
8
8
  export function makeAssetRegistry(assetPublisher: AssetPublisher): {
9
9
  /** @param {Brand} brand */
10
10
  has: (brand: Brand) => boolean;
@@ -13,103 +13,45 @@ export function makeAssetRegistry(assetPublisher: AssetPublisher): {
13
13
  brand: Brand;
14
14
  displayInfo: DisplayInfo;
15
15
  issuer: Issuer;
16
- petname: import('./types').Petname;
16
+ petname: import("./types.js").Petname;
17
17
  };
18
18
  values: () => Iterable<{
19
19
  brand: Brand;
20
20
  displayInfo: DisplayInfo;
21
21
  issuer: Issuer;
22
- petname: import('./types').Petname;
22
+ petname: import("./types.js").Petname;
23
23
  }>;
24
24
  };
25
25
  export function prepare(zcf: ZCF<SmartWalletContractTerms>, privateArgs: {
26
26
  storageNode: ERef<StorageNode>;
27
- walletBridgeManager?: ERef<import("@agoric/vats").ScopedBridgeManager> | undefined;
28
- walletReviver?: ERef<WalletReviver> | undefined;
29
- }, baggage: MapStore<string, unknown>): Promise<{
30
- creatorFacet: {
27
+ walletBridgeManager?: ERef<import("@agoric/vats").ScopedBridgeManager<"wallet">>;
28
+ walletReviver?: ERef<WalletReviver>;
29
+ }, baggage: import("@agoric/vat-data").Baggage): Promise<{
30
+ creatorFacet: import("@endo/exo").Guarded<{
31
31
  /**
32
32
  * @param {string} address
33
- * @param {ERef<import('@agoric/vats/src/vat-bank').Bank>} bank
34
- * @param {ERef<import('@agoric/vats/').NameAdmin>} namesByAddressAdmin
35
- * @returns {Promise<[wallet: import('./smartWallet').SmartWallet, isNew: boolean]>} wallet
33
+ * @param {ERef<import('@agoric/vats/src/vat-bank.js').Bank>} bank
34
+ * @param {ERef<import('@agoric/vats/src/types.js').NameAdmin>} namesByAddressAdmin
35
+ * @returns {Promise<[wallet: import('./smartWallet.js').SmartWallet, isNew: boolean]>} wallet
36
36
  * along with a flag to distinguish between looking up an existing wallet
37
37
  * and creating a new one.
38
38
  */
39
- provideSmartWallet(address: string, bank: ERef<import('@agoric/vats/src/vat-bank').Bank>, namesByAddressAdmin: ERef<import('@agoric/vats/').NameAdmin>): Promise<[wallet: {
40
- handleBridgeAction(actionCapData: import("@endo/marshal").CapData<string>, canSpend?: boolean | undefined): Promise<void>;
41
- getDepositFacet(): {
42
- receive(payment: Payment<AssetKind>): Promise<Amount<AssetKind>>;
43
- };
44
- getOffersFacet(): {
45
- executeOffer(offerSpec: import("./smartWallet.js").OfferSpec): Promise<void>;
46
- tryExitOffer(offerId: import("./smartWallet.js").OfferId): Promise<void>;
47
- };
48
- getCurrentSubscriber(): Subscriber<import("./smartWallet.js").CurrentWalletRecord>;
49
- getUpdatesSubscriber(): Subscriber<import("./smartWallet.js").UpdateRecord>;
50
- getPublicTopics(): {
51
- current: {
52
- description: string;
53
- subscriber: Subscriber<import("./smartWallet.js").CurrentWalletRecord>;
54
- storagePath: Promise<string>;
55
- };
56
- updates: {
57
- description: string;
58
- subscriber: Subscriber<import("./smartWallet.js").UpdateRecord>;
59
- storagePath: Promise<string>;
60
- };
61
- };
62
- repairWalletForIncarnation2(key: any): void;
63
- }, isNew: boolean]>;
64
- } & import("@endo/eventual-send").RemotableBrand<{}, {
65
- /**
66
- * @param {string} address
67
- * @param {ERef<import('@agoric/vats/src/vat-bank').Bank>} bank
68
- * @param {ERef<import('@agoric/vats/').NameAdmin>} namesByAddressAdmin
69
- * @returns {Promise<[wallet: import('./smartWallet').SmartWallet, isNew: boolean]>} wallet
70
- * along with a flag to distinguish between looking up an existing wallet
71
- * and creating a new one.
72
- */
73
- provideSmartWallet(address: string, bank: ERef<import('@agoric/vats/src/vat-bank').Bank>, namesByAddressAdmin: ERef<import('@agoric/vats/').NameAdmin>): Promise<[wallet: {
74
- handleBridgeAction(actionCapData: import("@endo/marshal").CapData<string>, canSpend?: boolean | undefined): Promise<void>;
75
- getDepositFacet(): {
76
- receive(payment: Payment<AssetKind>): Promise<Amount<AssetKind>>;
77
- };
78
- getOffersFacet(): {
79
- executeOffer(offerSpec: import("./smartWallet.js").OfferSpec): Promise<void>;
80
- tryExitOffer(offerId: import("./smartWallet.js").OfferId): Promise<void>;
81
- };
82
- getCurrentSubscriber(): Subscriber<import("./smartWallet.js").CurrentWalletRecord>;
83
- getUpdatesSubscriber(): Subscriber<import("./smartWallet.js").UpdateRecord>;
84
- getPublicTopics(): {
85
- current: {
86
- description: string;
87
- subscriber: Subscriber<import("./smartWallet.js").CurrentWalletRecord>;
88
- storagePath: Promise<string>;
89
- };
90
- updates: {
91
- description: string;
92
- subscriber: Subscriber<import("./smartWallet.js").UpdateRecord>;
93
- storagePath: Promise<string>;
94
- };
95
- };
96
- repairWalletForIncarnation2(key: any): void;
97
- }, isNew: boolean]>;
39
+ provideSmartWallet(address: string, bank: ERef<import("@agoric/vats/src/vat-bank.js").Bank>, namesByAddressAdmin: ERef<import("@agoric/vats/src/types.js").NameAdmin>): Promise<[wallet: import("./smartWallet.js").SmartWallet, isNew: boolean]>;
98
40
  }>;
99
41
  }>;
100
42
  export type SmartWalletContractTerms = {
101
- agoricNames: ERef<NameHub>;
102
- board: ERef<import('@agoric/vats').Board>;
43
+ agoricNames: globalThis.ERef<NameHub>;
44
+ board: ERef<import("@agoric/vats").Board>;
103
45
  assetPublisher: AssetPublisher;
104
46
  };
105
- export type NameHub = import('@agoric/vats').NameHub;
106
47
  export type AssetPublisher = {
107
- getAssetSubscription: () => ERef<IterableEachTopic<import('@agoric/vats/src/vat-bank').AssetDescriptor>>;
48
+ getAssetSubscription: () => ERef<IterableEachTopic<import("@agoric/vats/src/vat-bank.js").AssetDescriptor>>;
108
49
  };
109
50
  export type isRevive = boolean;
110
51
  export type WalletReviver = {
111
- reviveWallet: (address: string) => Promise<import('./smartWallet').SmartWallet>;
52
+ reviveWallet: (address: string) => Promise<import("./smartWallet.js").SmartWallet>;
112
53
  ackWallet: (address: string) => isRevive;
113
54
  };
114
55
  export type start = typeof prepare;
56
+ import type { NameHub } from '@agoric/vats';
115
57
  //# sourceMappingURL=walletFactory.d.ts.map