@agoric/smart-wallet 0.5.4-dev-6388a00.0 → 0.5.4-dev-376e47d.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/smart-wallet",
3
- "version": "0.5.4-dev-6388a00.0+6388a00",
3
+ "version": "0.5.4-dev-376e47d.0+376e47d",
4
4
  "description": "Wallet contract",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -16,8 +16,8 @@
16
16
  "lint:eslint": "eslint ."
17
17
  },
18
18
  "devDependencies": {
19
- "@agoric/cosmic-proto": "0.3.1-dev-6388a00.0+6388a00",
20
- "@agoric/swingset-vat": "0.32.3-dev-6388a00.0+6388a00",
19
+ "@agoric/cosmic-proto": "0.3.1-dev-376e47d.0+376e47d",
20
+ "@agoric/swingset-vat": "0.32.3-dev-376e47d.0+376e47d",
21
21
  "@endo/bundle-source": "^3.0.1",
22
22
  "@endo/captp": "^4.0.1",
23
23
  "@endo/init": "^1.0.1",
@@ -25,15 +25,15 @@
25
25
  "import-meta-resolve": "^2.2.1"
26
26
  },
27
27
  "dependencies": {
28
- "@agoric/assert": "0.6.1-dev-6388a00.0+6388a00",
29
- "@agoric/casting": "0.4.3-dev-6388a00.0+6388a00",
30
- "@agoric/ertp": "0.16.3-dev-6388a00.0+6388a00",
31
- "@agoric/internal": "0.3.3-dev-6388a00.0+6388a00",
32
- "@agoric/notifier": "0.6.3-dev-6388a00.0+6388a00",
33
- "@agoric/store": "0.9.3-dev-6388a00.0+6388a00",
34
- "@agoric/vat-data": "0.5.3-dev-6388a00.0+6388a00",
35
- "@agoric/vats": "0.15.2-dev-6388a00.0+6388a00",
36
- "@agoric/zoe": "0.26.3-dev-6388a00.0+6388a00",
28
+ "@agoric/assert": "0.6.1-dev-376e47d.0+376e47d",
29
+ "@agoric/casting": "0.4.3-dev-376e47d.0+376e47d",
30
+ "@agoric/ertp": "0.16.3-dev-376e47d.0+376e47d",
31
+ "@agoric/internal": "0.3.3-dev-376e47d.0+376e47d",
32
+ "@agoric/notifier": "0.6.3-dev-376e47d.0+376e47d",
33
+ "@agoric/store": "0.9.3-dev-376e47d.0+376e47d",
34
+ "@agoric/vat-data": "0.5.3-dev-376e47d.0+376e47d",
35
+ "@agoric/vats": "0.15.2-dev-376e47d.0+376e47d",
36
+ "@agoric/zoe": "0.26.3-dev-376e47d.0+376e47d",
37
37
  "@endo/eventual-send": "^1.0.1",
38
38
  "@endo/far": "^1.0.1",
39
39
  "@endo/marshal": "^1.0.1",
@@ -69,5 +69,5 @@
69
69
  "typeCoverage": {
70
70
  "atLeast": 94.07
71
71
  },
72
- "gitHead": "6388a002b53593f17a8d936d4e937efb7d065d97"
72
+ "gitHead": "376e47d1b7eba11d1e587778489d8f199d53870f"
73
73
  }
@@ -0,0 +1,31 @@
1
+ export function watchOfferOutcomes(watchers: OutcomeWatchers, seat: UserSeat): Promise<[unknown, 0 | 1, PaymentPKeywordRecord]>;
2
+ export function prepareOfferWatcher(baggage: any): (walletHelper?: any, deposit?: any, offerSpec?: any, address?: any, iAmount?: any, seatRef?: any) => import("@endo/exo/src/exo-makers.js").GuardedKit<{
3
+ helper: {
4
+ updateStatus(offerStatusUpdates: any): void;
5
+ onNewContinuingOffer(offerId: any, invitationAmount: any, invitationMakers: any, publicSubscribers: any): void;
6
+ publishResult(result: any): void;
7
+ };
8
+ /** @type {OutcomeWatchers['paymentWatcher']} */
9
+ paymentWatcher: OutcomeWatchers['paymentWatcher'];
10
+ /** @type {OutcomeWatchers['resultWatcher']} */
11
+ resultWatcher: OutcomeWatchers['resultWatcher'];
12
+ /** @type {OutcomeWatchers['numWantsWatcher']} */
13
+ numWantsWatcher: OutcomeWatchers['numWantsWatcher'];
14
+ }>;
15
+ export type OfferStatus = import('./offers.js').OfferSpec & {
16
+ error?: string;
17
+ numWantsSatisfied?: number;
18
+ result?: unknown | typeof import('./offers.js').UNPUBLISHED_RESULT;
19
+ payouts?: AmountKeywordRecord;
20
+ };
21
+ /**
22
+ * <T, [UserSeat]
23
+ */
24
+ export type OfferPromiseWatcher<T extends unknown> = import('@agoric/swingset-liveslots').PromiseWatcher<T, [UserSeat]>;
25
+ export type OutcomeWatchers = {
26
+ resultWatcher: OfferPromiseWatcher<unknown>;
27
+ numWantsWatcher: OfferPromiseWatcher<number>;
28
+ paymentWatcher: OfferPromiseWatcher<PaymentPKeywordRecord>;
29
+ };
30
+ export type MakeOfferWatcher = ReturnType<typeof prepareOfferWatcher>;
31
+ //# sourceMappingURL=offerWatcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"offerWatcher.d.ts","sourceRoot":"","sources":["offerWatcher.js"],"names":[],"mappings":"AAsEO,6CAHI,eAAe,QACf,QAAQ,oDAQlB;AA8BM;;;;;;IAwED,gDAAgD;oBAArC,eAAe,CAAC,gBAAgB,CAAC;IAyB5C,+CAA+C;mBAApC,eAAe,CAAC,eAAe,CAAC;IAkB3C,iDAAiD;qBAAtC,eAAe,CAAC,iBAAiB,CAAC;GAkBlD;0BAhOY,OAAO,aAAa,EAAE,SAAS,GAAG;IAC9C,KAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,MAAU,CAAC,EAAE,OAAO,GAAG,cAAc,aAAa,EAAE,kBAAkB,CAAC;IACvE,OAAW,CAAC,EAAE,mBAAmB,CAAC;CAC/B;;;;qDAKS,OAAO,4BAA4B,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;8BAIlE;IACZ,aAAe,EAAE,oBAAoB,OAAO,CAAC,CAAC;IAC9C,eAAiB,EAAE,oBAAoB,MAAM,CAAC,CAAC;IAC/C,cAAgB,EAAE,oBAAoB,qBAAqB,CAAC,CAAC;CAC1D;+BAiNU,WAAW,0BAA0B,CAAC"}
@@ -0,0 +1,243 @@
1
+ import { E, passStyleOf } from '@endo/far';
2
+
3
+ import { isUpgradeDisconnection } from '@agoric/internal/src/upgrade-api.js';
4
+ import { prepareExoClassKit, watchPromise } from '@agoric/vat-data';
5
+ import { M } from '@agoric/store';
6
+ import {
7
+ PaymentPKeywordRecordShape,
8
+ SeatShape,
9
+ } from '@agoric/zoe/src/typeGuards.js';
10
+ import { AmountShape } from '@agoric/ertp/src/typeGuards.js';
11
+ import { deeplyFulfilledObject, objectMap } from '@agoric/internal';
12
+
13
+ import { UNPUBLISHED_RESULT } from './offers.js';
14
+
15
+ /**
16
+ * @typedef {import('./offers.js').OfferSpec & {
17
+ * error?: string,
18
+ * numWantsSatisfied?: number
19
+ * result?: unknown | typeof import('./offers.js').UNPUBLISHED_RESULT,
20
+ * payouts?: AmountKeywordRecord,
21
+ * }} OfferStatus
22
+ */
23
+
24
+ /**
25
+ * @template {any} T
26
+ * @typedef {import('@agoric/swingset-liveslots').PromiseWatcher<T, [UserSeat]>} OfferPromiseWatcher<T, [UserSeat]
27
+ */
28
+
29
+ /**
30
+ * @typedef {{
31
+ * resultWatcher: OfferPromiseWatcher<unknown>,
32
+ * numWantsWatcher: OfferPromiseWatcher<number>,
33
+ * paymentWatcher: OfferPromiseWatcher<PaymentPKeywordRecord>,
34
+ * }} OutcomeWatchers
35
+ */
36
+
37
+ /**
38
+ * @param {OutcomeWatchers} watchers
39
+ * @param {UserSeat} seat
40
+ */
41
+ const watchForOfferResult = ({ resultWatcher }, seat) => {
42
+ const p = E(seat).getOfferResult();
43
+ watchPromise(p, resultWatcher, seat);
44
+ return p;
45
+ };
46
+
47
+ /**
48
+ * @param {OutcomeWatchers} watchers
49
+ * @param {UserSeat} seat
50
+ */
51
+ const watchForNumWants = ({ numWantsWatcher }, seat) => {
52
+ const p = E(seat).numWantsSatisfied();
53
+ watchPromise(p, numWantsWatcher, seat);
54
+ return p;
55
+ };
56
+
57
+ /**
58
+ * @param {OutcomeWatchers} watchers
59
+ * @param {UserSeat} seat
60
+ */
61
+ const watchForPayout = ({ paymentWatcher }, seat) => {
62
+ const p = E(seat).getPayouts();
63
+ watchPromise(p, paymentWatcher, seat);
64
+ return p;
65
+ };
66
+
67
+ /**
68
+ * @param {OutcomeWatchers} watchers
69
+ * @param {UserSeat} seat
70
+ */
71
+ export const watchOfferOutcomes = (watchers, seat) => {
72
+ return Promise.all([
73
+ watchForOfferResult(watchers, seat),
74
+ watchForNumWants(watchers, seat),
75
+ watchForPayout(watchers, seat),
76
+ ]);
77
+ };
78
+
79
+ const offerWatcherGuard = harden({
80
+ helper: M.interface('InstanceAdminStorage', {
81
+ updateStatus: M.call(M.any()).returns(),
82
+ onNewContinuingOffer: M.call(
83
+ M.or(M.number(), M.string()),
84
+ AmountShape,
85
+ M.any(),
86
+ )
87
+ .optional(M.record())
88
+ .returns(),
89
+ publishResult: M.call(M.any()).returns(),
90
+ }),
91
+ paymentWatcher: M.interface('paymentWatcher', {
92
+ onFulfilled: M.call(PaymentPKeywordRecordShape, SeatShape).returns(
93
+ M.promise(),
94
+ ),
95
+ onRejected: M.call(M.any(), SeatShape).returns(),
96
+ }),
97
+ resultWatcher: M.interface('resultWatcher', {
98
+ onFulfilled: M.call(M.any(), SeatShape).returns(),
99
+ onRejected: M.call(M.any(), SeatShape).returns(),
100
+ }),
101
+ numWantsWatcher: M.interface('numWantsWatcher', {
102
+ onFulfilled: M.call(M.number(), SeatShape).returns(),
103
+ onRejected: M.call(M.any(), SeatShape).returns(),
104
+ }),
105
+ });
106
+
107
+ export const prepareOfferWatcher = baggage => {
108
+ return prepareExoClassKit(
109
+ baggage,
110
+ 'OfferWatcher',
111
+ offerWatcherGuard,
112
+ (walletHelper, deposit, offerSpec, address, iAmount, seatRef) => ({
113
+ walletHelper,
114
+ deposit,
115
+ status: offerSpec,
116
+ address,
117
+ invitationAmount: iAmount,
118
+ seatRef,
119
+ }),
120
+ {
121
+ helper: {
122
+ updateStatus(offerStatusUpdates) {
123
+ const { state } = this;
124
+ state.status = harden({ ...state.status, ...offerStatusUpdates });
125
+
126
+ state.walletHelper.updateStatus(state.status);
127
+ },
128
+ onNewContinuingOffer(
129
+ offerId,
130
+ invitationAmount,
131
+ invitationMakers,
132
+ publicSubscribers,
133
+ ) {
134
+ const { state } = this;
135
+
136
+ void state.walletHelper.addContinuingOffer(
137
+ offerId,
138
+ invitationAmount,
139
+ invitationMakers,
140
+ publicSubscribers,
141
+ );
142
+ },
143
+
144
+ publishResult(result) {
145
+ const { state, facets } = this;
146
+
147
+ const passStyle = passStyleOf(result);
148
+ // someday can we get TS to type narrow based on the passStyleOf result match?
149
+ switch (passStyle) {
150
+ case 'bigint':
151
+ case 'boolean':
152
+ case 'null':
153
+ case 'number':
154
+ case 'string':
155
+ case 'symbol':
156
+ case 'undefined':
157
+ facets.helper.updateStatus({ result });
158
+ break;
159
+ case 'copyRecord':
160
+ if ('invitationMakers' in result) {
161
+ // save for continuing invitation offer
162
+
163
+ void facets.helper.onNewContinuingOffer(
164
+ String(state.status.id),
165
+ state.invitationAmount,
166
+ result.invitationMakers,
167
+ result.publicSubscribers,
168
+ );
169
+ }
170
+ facets.helper.updateStatus({ result: UNPUBLISHED_RESULT });
171
+ break;
172
+ default:
173
+ // drop the result
174
+ facets.helper.updateStatus({ result: UNPUBLISHED_RESULT });
175
+ }
176
+ },
177
+ },
178
+
179
+ /** @type {OutcomeWatchers['paymentWatcher']} */
180
+ paymentWatcher: {
181
+ async onFulfilled(payouts) {
182
+ const { state, facets } = this;
183
+
184
+ // This will block until all payouts succeed, but user will be updated
185
+ // since each payout will trigger its corresponding purse notifier.
186
+ const amountPKeywordRecord = objectMap(payouts, paymentRef =>
187
+ E.when(paymentRef, payment => state.deposit.receive(payment)),
188
+ );
189
+ const amounts = await deeplyFulfilledObject(amountPKeywordRecord);
190
+ facets.helper.updateStatus({ payouts: amounts });
191
+ },
192
+ /**
193
+ * @param {Error} err
194
+ * @param {UserSeat} seat
195
+ */
196
+ onRejected(err, seat) {
197
+ const { facets } = this;
198
+ if (isUpgradeDisconnection(err)) {
199
+ void watchForPayout(facets, seat);
200
+ }
201
+ },
202
+ },
203
+
204
+ /** @type {OutcomeWatchers['resultWatcher']} */
205
+ resultWatcher: {
206
+ onFulfilled(result) {
207
+ const { facets } = this;
208
+ facets.helper.publishResult(result);
209
+ },
210
+ /**
211
+ * @param {Error} err
212
+ * @param {UserSeat} seat
213
+ */
214
+ onRejected(err, seat) {
215
+ const { facets } = this;
216
+ if (isUpgradeDisconnection(err)) {
217
+ void watchForOfferResult(facets, seat);
218
+ }
219
+ },
220
+ },
221
+
222
+ /** @type {OutcomeWatchers['numWantsWatcher']} */
223
+ numWantsWatcher: {
224
+ onFulfilled(numSatisfied) {
225
+ const { facets } = this;
226
+
227
+ facets.helper.updateStatus({ numWantsSatisfied: numSatisfied });
228
+ },
229
+ /**
230
+ * @param {Error} err
231
+ * @param {UserSeat} seat
232
+ */
233
+ onRejected(err, seat) {
234
+ const { facets } = this;
235
+ void watchForNumWants(facets, seat);
236
+ },
237
+ },
238
+ },
239
+ );
240
+ };
241
+ harden(prepareOfferWatcher);
242
+
243
+ /** @typedef {ReturnType<typeof prepareOfferWatcher>} MakeOfferWatcher */
package/src/offers.d.ts CHANGED
@@ -11,30 +11,6 @@
11
11
  */
12
12
  /** Value for "result" field when the result can't be published */
13
13
  export const UNPUBLISHED_RESULT: "UNPUBLISHED";
14
- export function makeOfferExecutor({ zoe, depositFacet, invitationIssuer, powers, onStatusChange, onNewContinuingOffer, }: {
15
- zoe: ERef<ZoeService>;
16
- depositFacet: {
17
- receive: (payment: any) => Promise<Amount>;
18
- };
19
- invitationIssuer: ERef<Issuer<'set'>>;
20
- powers: {
21
- logger: Pick<Console, 'info' | 'error'>;
22
- invitationFromSpec: (spec: import('./invitations.js').InvitationSpec) => ERef<Invitation>;
23
- purseForBrand: (brand: Brand) => Promise<Purse>;
24
- };
25
- onStatusChange: (status: OfferStatus) => void;
26
- onNewContinuingOffer: (offerId: string, invitationAmount: Amount<'set'>, invitationMakers: import('./types.js').InvitationMakers, publicSubscribers: import('./types.js').PublicSubscribers | import('@agoric/zoe/src/contractSupport/index.js').TopicsRecord) => Promise<void>;
27
- }): {
28
- /**
29
- * Take an offer description provided in capData, augment it with payments and call zoe.offer()
30
- *
31
- * @param {OfferSpec} offerSpec
32
- * @param {(seatRef: UserSeat) => void} onSeatCreated
33
- * @returns {Promise<void>} when the offer has been sent to Zoe; payouts go into this wallet's purses
34
- * @throws if any parts of the offer are determined to be invalid before calling Zoe's `offer()`
35
- */
36
- executeOffer(offerSpec: OfferSpec, onSeatCreated: (seatRef: UserSeat) => void): Promise<void>;
37
- };
38
14
  export type OfferId = number | string;
39
15
  export type OfferSpec = {
40
16
  id: OfferId;
@@ -1 +1 @@
1
- {"version":3,"file":"offers.d.ts","sourceRoot":"","sources":["offers.js"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;;;GAOG;AAEH,kEAAkE;AAClE,+CAAgD;AAwBzC;SAVI,KAAK,UAAU,CAAC;;mCACW,QAAQ,MAAM,CAAC;;sBAC1C,KAAK,OAAO,KAAK,CAAC,CAAC;;gBAEnB,KAAK,OAAO,EAAE,MAAM,GAAE,OAAO,CAAC;mCACvB,OAAO,kBAAkB,EAAE,cAAc,KAAK,KAAK,UAAU,CAAC;+BAC7D,KAAK,KAAK,QAAQ,KAAK,CAAC;;6BACvB,WAAW,KAAK,IAAI;oCACnB,MAAM,oBAAoB,OAAO,KAAK,CAAC,oBAAoB,OAAO,YAAY,EAAE,gBAAgB,qBAAqB,OAAO,YAAY,EAAE,iBAAiB,GAAG,OAAO,0CAA0C,EAAE,YAAY,KAAM,QAAQ,IAAI,CAAC;;IAajQ;;;;;;;OAOG;4BAJQ,SAAS,2BACC,QAAQ,KAAK,IAAI,GACzB,QAAQ,IAAI,CAAC;EAwI7B;sBA7LY,MAAM,GAAG,MAAM;wBAIf;IACZ,EAAM,EAAE,OAAO,CAAC;IAChB,cAAkB,EAAE,OAAO,kBAAkB,EAAE,cAAc,CAAC;IAC9D,QAAY,EAAE,QAAQ,CAAC;IACvB,SAAa,CAAC,EAAE,OAAO,CAAA;CACpB;0BAOS,OAAO,aAAa,EAAE,SAAS,GAAG;IAC9C,KAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,MAAQ,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC;IAC/C,OAAS,CAAC,EAAE,mBAAmB,CAAC;CAC7B"}
1
+ {"version":3,"file":"offers.d.ts","sourceRoot":"","sources":["offers.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;GAOG;AAEH,kEAAkE;AAClE,+CAAgD;sBAbnC,MAAM,GAAG,MAAM;wBAIf;IACZ,EAAM,EAAE,OAAO,CAAC;IAChB,cAAkB,EAAE,OAAO,kBAAkB,EAAE,cAAc,CAAC;IAC9D,QAAY,EAAE,QAAQ,CAAC;IACvB,SAAa,CAAC,EAAE,OAAO,CAAA;CACpB;0BAOS,OAAO,aAAa,EAAE,SAAS,GAAG;IAC9C,KAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,MAAQ,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC;IAC/C,OAAS,CAAC,EAAE,mBAAmB,CAAC;CAC7B"}
package/src/offers.js CHANGED
@@ -1,7 +1,3 @@
1
- import { E, passStyleOf } from '@endo/far';
2
- import { deeplyFulfilledObject } from '@agoric/internal';
3
- import { makePaymentsHelper } from './payments.js';
4
-
5
1
  /**
6
2
  * @typedef {number | string} OfferId
7
3
  */
@@ -26,171 +22,3 @@ export const UNPUBLISHED_RESULT = 'UNPUBLISHED';
26
22
  * payouts?: AmountKeywordRecord,
27
23
  * }} OfferStatus
28
24
  */
29
-
30
- /* eslint-disable jsdoc/check-param-names -- bug(?) with nested objects */
31
- /**
32
- * @param {object} opts
33
- * @param {ERef<ZoeService>} opts.zoe
34
- * @param {{ receive: (payment: *) => Promise<Amount> }} opts.depositFacet
35
- * @param {ERef<Issuer<'set'>>} opts.invitationIssuer
36
- * @param {object} opts.powers
37
- * @param {Pick<Console, 'info'| 'error'>} opts.powers.logger
38
- * @param {(spec: import('./invitations.js').InvitationSpec) => ERef<Invitation>} opts.powers.invitationFromSpec
39
- * @param {(brand: Brand) => Promise<Purse>} opts.powers.purseForBrand
40
- * @param {(status: OfferStatus) => void} opts.onStatusChange
41
- * @param {(offerId: string, invitationAmount: Amount<'set'>, invitationMakers: import('./types.js').InvitationMakers, publicSubscribers: import('./types.js').PublicSubscribers | import('@agoric/zoe/src/contractSupport/index.js').TopicsRecord ) => Promise<void>} opts.onNewContinuingOffer
42
- */
43
- export const makeOfferExecutor = ({
44
- zoe,
45
- depositFacet,
46
- invitationIssuer,
47
- powers,
48
- onStatusChange,
49
- onNewContinuingOffer,
50
- }) => {
51
- const { invitationFromSpec, logger, purseForBrand } = powers;
52
-
53
- return {
54
- /**
55
- * Take an offer description provided in capData, augment it with payments and call zoe.offer()
56
- *
57
- * @param {OfferSpec} offerSpec
58
- * @param {(seatRef: UserSeat) => void} onSeatCreated
59
- * @returns {Promise<void>} when the offer has been sent to Zoe; payouts go into this wallet's purses
60
- * @throws if any parts of the offer are determined to be invalid before calling Zoe's `offer()`
61
- */
62
- async executeOffer(offerSpec, onSeatCreated) {
63
- logger.info('starting executeOffer', offerSpec.id);
64
-
65
- const paymentsManager = makePaymentsHelper(purseForBrand, depositFacet);
66
-
67
- /** @type {OfferStatus} */
68
- let status = {
69
- ...offerSpec,
70
- };
71
- /** @param {Partial<OfferStatus>} changes */
72
- const updateStatus = changes => {
73
- status = { ...status, ...changes };
74
- onStatusChange(status);
75
- };
76
-
77
- /** @type {UserSeat} */
78
- let seatRef;
79
-
80
- const tryBody = async () => {
81
- // 1. Prepare values and validate synchronously.
82
- const { id, invitationSpec, proposal, offerArgs } = offerSpec;
83
-
84
- /** @type {PaymentKeywordRecord | undefined} */
85
- const paymentKeywordRecord = await (proposal?.give &&
86
- deeplyFulfilledObject(paymentsManager.withdrawGive(proposal.give)));
87
-
88
- const invitation = invitationFromSpec(invitationSpec);
89
- const invitationAmount =
90
- await E(invitationIssuer).getAmountOf(invitation);
91
-
92
- // 2. Begin executing offer
93
- // No explicit signal to user that we reached here but if anything above
94
- // failed they'd get an 'error' status update.
95
-
96
- seatRef = await E(zoe).offer(
97
- invitation,
98
- proposal,
99
- paymentKeywordRecord,
100
- offerArgs,
101
- );
102
- logger.info(id, 'seated');
103
- onSeatCreated(seatRef);
104
-
105
- const publishResult = E.when(E(seatRef).getOfferResult(), result => {
106
- const passStyle = passStyleOf(result);
107
- logger.info(id, 'offerResult', passStyle, result);
108
- // someday can we get TS to type narrow based on the passStyleOf result match?
109
- switch (passStyle) {
110
- case 'bigint':
111
- case 'boolean':
112
- case 'null':
113
- case 'number':
114
- case 'string':
115
- case 'symbol':
116
- case 'undefined':
117
- updateStatus({ result });
118
- break;
119
- case 'copyRecord':
120
- // @ts-expect-error result narrowed by passStyle
121
- if ('invitationMakers' in result) {
122
- // save for continuing invitation offer
123
- void onNewContinuingOffer(
124
- String(id),
125
- invitationAmount,
126
- // @ts-expect-error result narrowed by passStyle
127
- result.invitationMakers,
128
- // @ts-expect-error result narrowed by passStyle
129
- result.publicSubscribers,
130
- );
131
- }
132
- // copyRecord is valid to publish but not safe as it may have private info
133
- updateStatus({ result: UNPUBLISHED_RESULT });
134
- break;
135
- default:
136
- // drop the result
137
- updateStatus({ result: UNPUBLISHED_RESULT });
138
- }
139
- });
140
-
141
- const publishWantsSatisfied = E.when(
142
- E(seatRef).numWantsSatisfied(),
143
- numSatisfied => {
144
- logger.info(id, 'numSatisfied', numSatisfied);
145
- if (numSatisfied === 0) {
146
- updateStatus({ numWantsSatisfied: 0 });
147
- }
148
- updateStatus({
149
- numWantsSatisfied: numSatisfied,
150
- });
151
- },
152
- );
153
-
154
- // This will block until all payouts succeed, but user will be updated
155
- // as each payout will trigger its corresponding purse notifier.
156
- const publishPayouts = E.when(E(seatRef).getPayouts(), payouts =>
157
- paymentsManager.depositPayouts(payouts).then(amountsOrDeferred => {
158
- updateStatus({ payouts: amountsOrDeferred });
159
- }),
160
- );
161
-
162
- // The offer is complete when these promises are resolved.
163
- // If any reject then executeOffer rejects and that must be handled.
164
- return Promise.all([
165
- publishResult,
166
- publishWantsSatisfied,
167
- publishPayouts,
168
- ]);
169
- };
170
-
171
- await tryBody().catch(err => {
172
- logger.error('OFFER ERROR:', err);
173
- // Notify the user
174
- updateStatus({ error: err.toString() });
175
- // Attempt to recover payments
176
- void paymentsManager.tryReclaimingWithdrawnPayments().then(result => {
177
- if (result) {
178
- updateStatus({ result });
179
- }
180
- });
181
- if (seatRef) {
182
- void E(seatRef)
183
- .hasExited()
184
- .then(hasExited => {
185
- if (!hasExited) {
186
- void E(seatRef).tryExit();
187
- }
188
- });
189
- }
190
- // propagate to caller
191
- throw err;
192
- });
193
- },
194
- };
195
- };
196
- harden(makeOfferExecutor);
@@ -0,0 +1,23 @@
1
+ export function upgradeWalletFactory({ consume: { walletFactoryStartResult, provisionPoolStartResult, chainStorage, walletBridgeManager: walletBridgeManagerP, }, }: BootstrapPowers & ChainBootstrapSpace, options: {
2
+ options: {
3
+ walletRef: VatSourceRef;
4
+ };
5
+ }): Promise<void>;
6
+ export function getManifestForUpgradeWallet(_powers: any, { walletRef }: {
7
+ walletRef: any;
8
+ }): {
9
+ manifest: {
10
+ [x: string]: {
11
+ consume: {
12
+ walletFactoryStartResult: string;
13
+ provisionPoolStartResult: string;
14
+ chainStorage: string;
15
+ walletBridgeManager: string;
16
+ };
17
+ };
18
+ };
19
+ options: {
20
+ walletRef: any;
21
+ };
22
+ };
23
+ //# sourceMappingURL=upgrade-wallet-factory2-proposal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade-wallet-factory2-proposal.d.ts","sourceRoot":"","sources":["upgrade-wallet-factory2-proposal.js"],"names":[],"mappings":"AASO,qKAJI,eAAe,GAAG,mBAAmB;;mBAExB,YAAY;;kBAoCnC;AAEM;;;;;;;;;;;;;;;;EAYL"}
@@ -0,0 +1,58 @@
1
+ // @ts-check
2
+ import { E } from '@endo/far';
3
+ import { makeStorageNodeChild } from '@agoric/internal/src/lib-chainStorage.js';
4
+
5
+ /**
6
+ * @param {BootstrapPowers & ChainBootstrapSpace} powers
7
+ * @param {object} options
8
+ * @param {{ walletRef: VatSourceRef }} options.options
9
+ */
10
+ export const upgradeWalletFactory = async (
11
+ {
12
+ consume: {
13
+ walletFactoryStartResult,
14
+ provisionPoolStartResult,
15
+ chainStorage,
16
+ walletBridgeManager: walletBridgeManagerP,
17
+ },
18
+ },
19
+ options,
20
+ ) => {
21
+ const WALLET_STORAGE_PATH_SEGMENT = 'wallet';
22
+
23
+ const { walletRef } = options.options;
24
+
25
+ const [walletBridgeManager, walletStorageNode, ppFacets] = await Promise.all([
26
+ walletBridgeManagerP,
27
+ makeStorageNodeChild(chainStorage, WALLET_STORAGE_PATH_SEGMENT),
28
+ provisionPoolStartResult,
29
+ ]);
30
+ const walletReviver = await E(ppFacets.creatorFacet).getWalletReviver();
31
+
32
+ const privateArgs = {
33
+ storageNode: walletStorageNode,
34
+ walletBridgeManager,
35
+ walletReviver,
36
+ };
37
+
38
+ const { adminFacet } = await walletFactoryStartResult;
39
+
40
+ assert(walletRef.bundleID);
41
+ await E(adminFacet).upgradeContract(walletRef.bundleID, privateArgs);
42
+
43
+ console.log(`Successfully upgraded WalletFactory`);
44
+ };
45
+
46
+ export const getManifestForUpgradeWallet = (_powers, { walletRef }) => ({
47
+ manifest: {
48
+ [upgradeWalletFactory.name]: {
49
+ consume: {
50
+ walletFactoryStartResult: 'walletFactoryStartResult',
51
+ provisionPoolStartResult: 'provisionPoolStartResult',
52
+ chainStorage: 'chainStorage',
53
+ walletBridgeManager: 'walletBridgeManager',
54
+ },
55
+ },
56
+ },
57
+ options: { walletRef },
58
+ });