@agoric/smart-wallet 0.5.4-mainnet1B-dev-b0c1f78.0 → 0.5.4-orchestration-dev-096c4e8.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,44 +1,44 @@
1
1
  {
2
2
  "name": "@agoric/smart-wallet",
3
- "version": "0.5.4-mainnet1B-dev-b0c1f78.0+b0c1f78",
3
+ "version": "0.5.4-orchestration-dev-096c4e8.0+096c4e8",
4
4
  "description": "Wallet contract",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "yarn build:bundles",
8
8
  "build:bundles": "node ./scripts/build-bundles.js",
9
- "prepack": "tsc --build jsconfig.build.json",
9
+ "prepack": "tsc --build tsconfig.build.json",
10
10
  "postpack": "git clean -f '*.d.ts*'",
11
11
  "test": "ava",
12
12
  "test:xs": "exit 0",
13
13
  "lint": "run-s --continue-on-error lint:*",
14
14
  "lint-fix": "yarn lint:eslint --fix",
15
- "lint:types": "tsc -p jsconfig.json",
15
+ "lint:types": "tsc",
16
16
  "lint:eslint": "eslint ."
17
17
  },
18
18
  "devDependencies": {
19
- "@agoric/cosmic-proto": "0.3.1-mainnet1B-dev-b0c1f78.0+b0c1f78",
20
- "@endo/bundle-source": "2.5.2-upstream-rollup",
21
- "@endo/captp": "3.1.1",
22
- "@endo/init": "0.5.56",
23
- "ava": "^5.2.0",
19
+ "@agoric/cosmic-proto": "0.4.1-orchestration-dev-096c4e8.0+096c4e8",
20
+ "@agoric/swingset-vat": "0.32.3-orchestration-dev-096c4e8.0+096c4e8",
21
+ "@endo/bundle-source": "^3.1.0",
22
+ "@endo/captp": "^4.0.4",
23
+ "@endo/init": "^1.0.4",
24
+ "ava": "^5.3.0",
24
25
  "import-meta-resolve": "^2.2.1"
25
26
  },
26
27
  "dependencies": {
27
- "@agoric/assert": "0.6.1-mainnet1B-dev-b0c1f78.0+b0c1f78",
28
- "@agoric/casting": "0.4.3-mainnet1B-dev-b0c1f78.0+b0c1f78",
29
- "@agoric/ertp": "0.16.3-mainnet1B-dev-b0c1f78.0+b0c1f78",
30
- "@agoric/internal": "0.4.0-mainnet1B-dev-b0c1f78.0+b0c1f78",
31
- "@agoric/notifier": "0.6.3-mainnet1B-dev-b0c1f78.0+b0c1f78",
32
- "@agoric/store": "0.9.3-mainnet1B-dev-b0c1f78.0+b0c1f78",
33
- "@agoric/swingset-vat": "0.32.3-mainnet1B-dev-b0c1f78.0+b0c1f78",
34
- "@agoric/vat-data": "0.5.3-mainnet1B-dev-b0c1f78.0+b0c1f78",
35
- "@agoric/vats": "0.15.2-mainnet1B-dev-b0c1f78.0+b0c1f78",
36
- "@agoric/zoe": "0.26.3-mainnet1B-dev-b0c1f78.0+b0c1f78",
37
- "@endo/eventual-send": "0.17.2",
38
- "@endo/far": "0.2.18",
39
- "@endo/marshal": "0.8.5",
40
- "@endo/nat": "4.1.27",
41
- "@endo/promise-kit": "0.2.56"
28
+ "@agoric/assert": "0.6.1-orchestration-dev-096c4e8.0+096c4e8",
29
+ "@agoric/casting": "0.4.3-orchestration-dev-096c4e8.0+096c4e8",
30
+ "@agoric/ertp": "0.16.3-orchestration-dev-096c4e8.0+096c4e8",
31
+ "@agoric/internal": "0.3.3-orchestration-dev-096c4e8.0+096c4e8",
32
+ "@agoric/notifier": "0.6.3-orchestration-dev-096c4e8.0+096c4e8",
33
+ "@agoric/store": "0.9.3-orchestration-dev-096c4e8.0+096c4e8",
34
+ "@agoric/vat-data": "0.5.3-orchestration-dev-096c4e8.0+096c4e8",
35
+ "@agoric/vats": "0.15.2-orchestration-dev-096c4e8.0+096c4e8",
36
+ "@agoric/zoe": "0.26.3-orchestration-dev-096c4e8.0+096c4e8",
37
+ "@endo/eventual-send": "^1.1.2",
38
+ "@endo/far": "^1.0.4",
39
+ "@endo/marshal": "^1.3.0",
40
+ "@endo/nat": "^5.0.4",
41
+ "@endo/promise-kit": "^1.0.4"
42
42
  },
43
43
  "files": [
44
44
  "src/"
@@ -58,10 +58,16 @@
58
58
  "files": [
59
59
  "test/**/test-*.js"
60
60
  ],
61
+ "require": [
62
+ "@endo/init/debug.js"
63
+ ],
61
64
  "timeout": "2m"
62
65
  },
63
66
  "publishConfig": {
64
67
  "access": "public"
65
68
  },
66
- "gitHead": "b0c1f788a06e8593426319de068acd64a390d349"
69
+ "typeCoverage": {
70
+ "atLeast": 93.75
71
+ },
72
+ "gitHead": "096c4e8fce80e9a509b0e1a30fda11736c4570e1"
67
73
  }
@@ -1,4 +1,4 @@
1
- export function makeInvitationsHelper(zoe: ERef<ZoeService>, agoricNames: ERef<NameHub>, invitationBrand: Brand<'set'>, invitationsPurse: Purse<'set'>, getInvitationContinuation: (fromOfferId: string) => import('./types').RemoteInvitationMakers): (spec: InvitationSpec) => ERef<Invitation>;
1
+ export function makeInvitationsHelper(zoe: ERef<ZoeService>, agoricNames: ERef<import('@agoric/vats').NameHub>, invitationBrand: Brand<'set'>, invitationsPurse: Purse<'set'>, getInvitationContinuation: (fromOfferId: string) => import('./types.js').InvitationMakers): (spec: InvitationSpec) => ERef<Invitation>;
2
2
  /**
3
3
  * Specify how to produce an invitation. See each type in the union for details.
4
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"invitations.d.ts","sourceRoot":"","sources":["invitations.js"],"names":[],"mappings":"AAkEO,2CANI,KAAK,UAAU,CAAC,eAChB,KAAK,OAAO,CAAC,mBACb,MAAM,KAAK,CAAC,oBACZ,MAAM,KAAK,CAAC,2CACE,MAAM,KAAK,OAAO,SAAS,EAAE,sBAAsB,UAsFxD,cAAc,KAAK,KAAK,UAAU,CAAC,CAgBtD;;;;6BAvJY,4BAA4B,GAAG,sBAAsB,GAAG,mBAAmB,GAAG,wBAAwB;;;;;;;2CAKtG;IACZ,MAAQ,EAAE,gBAAgB,CAAC;IAC3B,YAAc,EAAE,MAAM,EAAE,CAAC;IACzB,QAAU,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,GAAG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IACZ,MAAQ,EAAE,OAAO,CAAC;IAClB,QAAU,EAAE,QAAQ,CAAC;IACrB,WAAa,EAAE,MAAM,CAAC;CACnB;;;;uCAIS;IACZ,MAAQ,EAAE,YAAY,CAAC;IACvB,aAAe,EAAE,OAAO,aAAa,EAAE,OAAO,CAAC;IAC/C,mBAAqB,EAAE,MAAM,CAAC;IAC9B,cAAgB,CAAC,EAAE,GAAG,EAAE,CAAC;CACtB;oCAKS,KAAK,iBAAiB,EAAE,aAAa,GAAG,UAAU,CAAC"}
@@ -59,10 +59,10 @@ const MAX_PIPE_LENGTH = 2;
59
59
 
60
60
  /**
61
61
  * @param {ERef<ZoeService>} zoe
62
- * @param {ERef<NameHub>} agoricNames
62
+ * @param {ERef<import('@agoric/vats').NameHub>} agoricNames
63
63
  * @param {Brand<'set'>} invitationBrand
64
64
  * @param {Purse<'set'>} invitationsPurse
65
- * @param {(fromOfferId: string) => import('./types').RemoteInvitationMakers} getInvitationContinuation
65
+ * @param {(fromOfferId: string) => import('./types.js').InvitationMakers} getInvitationContinuation
66
66
  */
67
67
  export const makeInvitationsHelper = (
68
68
  zoe,
@@ -0,0 +1,42 @@
1
+ export function watchOfferOutcomes(watchers: OutcomeWatchers, seat: UserSeat): Promise<[unknown, 0 | 1, PaymentPKeywordRecord]>;
2
+ export function prepareOfferWatcher(baggage: import('@agoric/vat-data').Baggage): (walletHelper: any, deposit: any, offerSpec: import("./offers.js").OfferSpec, address: string, invitationAmount: Amount<"set">, seatRef: UserSeat<unknown>) => import("@endo/exo/src/exo-makers.js").GuardedKit<{
3
+ helper: {
4
+ /**
5
+ * @param {Record<string, unknown>} offerStatusUpdates
6
+ */
7
+ updateStatus(offerStatusUpdates: Record<string, unknown>): void;
8
+ onNewContinuingOffer(offerId: any, invitationAmount: any, invitationMakers: any, publicSubscribers: any): void;
9
+ /** @param {unknown} result */
10
+ publishResult(result: unknown): void;
11
+ /**
12
+ * Called when the offer result promise rejects. The other two watchers
13
+ * are waiting for particular values out of Zoe but they settle at the same time
14
+ * and don't need their own error handling.
15
+ * @param {Error} err
16
+ */
17
+ handleError(err: Error): void;
18
+ };
19
+ /** @type {OutcomeWatchers['paymentWatcher']} */
20
+ paymentWatcher: OutcomeWatchers['paymentWatcher'];
21
+ /** @type {OutcomeWatchers['resultWatcher']} */
22
+ resultWatcher: OutcomeWatchers['resultWatcher'];
23
+ /** @type {OutcomeWatchers['numWantsWatcher']} */
24
+ numWantsWatcher: OutcomeWatchers['numWantsWatcher'];
25
+ }>;
26
+ export type OfferStatus = import('./offers.js').OfferSpec & {
27
+ error?: string;
28
+ numWantsSatisfied?: number;
29
+ result?: unknown | typeof import('./offers.js').UNPUBLISHED_RESULT;
30
+ payouts?: AmountKeywordRecord;
31
+ };
32
+ /**
33
+ * <T, [UserSeat]
34
+ */
35
+ export type OfferPromiseWatcher<T extends unknown> = import('@agoric/swingset-liveslots').PromiseWatcher<T, [UserSeat]>;
36
+ export type OutcomeWatchers = {
37
+ resultWatcher: OfferPromiseWatcher<unknown>;
38
+ numWantsWatcher: OfferPromiseWatcher<number>;
39
+ paymentWatcher: OfferPromiseWatcher<PaymentPKeywordRecord>;
40
+ };
41
+ export type MakeOfferWatcher = ReturnType<typeof prepareOfferWatcher>;
42
+ //# 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;AAkCM,6CAFI,OAAO,kBAAkB,EAAE,OAAO;;QA0BrC;;WAEG;yCADQ,OAAO,MAAM,EAAE,OAAO,CAAC;;QAwBlC,8BAA8B;8BAAlB,OAAO;QAoCnB;;;;;WAKG;yBADQ,KAAK;;IAclB,gDAAgD;oBAArC,eAAe,CAAC,gBAAgB,CAAC;IA6B5C,+CAA+C;mBAApC,eAAe,CAAC,eAAe,CAAC;IAsB3C,iDAAiD;qBAAtC,eAAe,CAAC,iBAAiB,CAAC;GA0BlD;0BAnRY,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;+BAoQU,WAAW,0BAA0B,CAAC"}
@@ -0,0 +1,294 @@
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
+ handleError: M.call(M.error()).returns(),
91
+ }),
92
+ paymentWatcher: M.interface('paymentWatcher', {
93
+ onFulfilled: M.call(PaymentPKeywordRecordShape, SeatShape).returns(
94
+ M.promise(),
95
+ ),
96
+ onRejected: M.call(M.any(), SeatShape).returns(),
97
+ }),
98
+ resultWatcher: M.interface('resultWatcher', {
99
+ onFulfilled: M.call(M.any(), SeatShape).returns(),
100
+ onRejected: M.call(M.any(), SeatShape).returns(),
101
+ }),
102
+ numWantsWatcher: M.interface('numWantsWatcher', {
103
+ onFulfilled: M.call(M.number(), SeatShape).returns(),
104
+ onRejected: M.call(M.any(), SeatShape).returns(),
105
+ }),
106
+ });
107
+
108
+ /**
109
+ * @param {import('@agoric/vat-data').Baggage} baggage
110
+ */
111
+ export const prepareOfferWatcher = baggage => {
112
+ return prepareExoClassKit(
113
+ baggage,
114
+ 'OfferWatcher',
115
+ offerWatcherGuard,
116
+ /**
117
+ *
118
+ * @param {*} walletHelper
119
+ * @param {*} deposit
120
+ * @param {import('./offers.js').OfferSpec} offerSpec
121
+ * @param {string} address
122
+ * @param {Amount<'set'>} invitationAmount
123
+ * @param {UserSeat} seatRef
124
+ */
125
+ (walletHelper, deposit, offerSpec, address, invitationAmount, seatRef) => ({
126
+ walletHelper,
127
+ deposit,
128
+ status: offerSpec,
129
+ address,
130
+ invitationAmount,
131
+ seatRef,
132
+ }),
133
+ {
134
+ helper: {
135
+ /**
136
+ * @param {Record<string, unknown>} offerStatusUpdates
137
+ */
138
+ updateStatus(offerStatusUpdates) {
139
+ const { state } = this;
140
+ state.status = harden({ ...state.status, ...offerStatusUpdates });
141
+
142
+ state.walletHelper.updateStatus(state.status);
143
+ },
144
+ onNewContinuingOffer(
145
+ offerId,
146
+ invitationAmount,
147
+ invitationMakers,
148
+ publicSubscribers,
149
+ ) {
150
+ const { state } = this;
151
+
152
+ void state.walletHelper.addContinuingOffer(
153
+ offerId,
154
+ invitationAmount,
155
+ invitationMakers,
156
+ publicSubscribers,
157
+ );
158
+ },
159
+
160
+ /** @param {unknown} result */
161
+ publishResult(result) {
162
+ const { state, facets } = this;
163
+
164
+ const passStyle = passStyleOf(result);
165
+ // someday can we get TS to type narrow based on the passStyleOf result match?
166
+ switch (passStyle) {
167
+ case 'bigint':
168
+ case 'boolean':
169
+ case 'null':
170
+ case 'number':
171
+ case 'string':
172
+ case 'symbol':
173
+ case 'undefined':
174
+ facets.helper.updateStatus({ result });
175
+ break;
176
+ case 'copyRecord':
177
+ // @ts-expect-error narrowed by passStyle
178
+ if ('invitationMakers' in result) {
179
+ // save for continuing invitation offer
180
+
181
+ void facets.helper.onNewContinuingOffer(
182
+ String(state.status.id),
183
+ state.invitationAmount,
184
+ result.invitationMakers,
185
+ // @ts-expect-error narrowed by passStyle
186
+ result.publicSubscribers,
187
+ );
188
+ }
189
+ facets.helper.updateStatus({ result: UNPUBLISHED_RESULT });
190
+ break;
191
+ default:
192
+ // drop the result
193
+ facets.helper.updateStatus({ result: UNPUBLISHED_RESULT });
194
+ }
195
+ },
196
+ /**
197
+ * Called when the offer result promise rejects. The other two watchers
198
+ * are waiting for particular values out of Zoe but they settle at the same time
199
+ * and don't need their own error handling.
200
+ * @param {Error} err
201
+ */
202
+ handleError(err) {
203
+ const { facets } = this;
204
+ facets.helper.updateStatus({ error: err.toString() });
205
+ const { seatRef } = this.state;
206
+ void E.when(E(seatRef).hasExited(), hasExited => {
207
+ if (!hasExited) {
208
+ void E(seatRef).tryExit();
209
+ }
210
+ });
211
+ },
212
+ },
213
+
214
+ /** @type {OutcomeWatchers['paymentWatcher']} */
215
+ paymentWatcher: {
216
+ async onFulfilled(payouts) {
217
+ const { state, facets } = this;
218
+
219
+ // This will block until all payouts succeed, but user will be updated
220
+ // since each payout will trigger its corresponding purse notifier.
221
+ const amountPKeywordRecord = objectMap(payouts, paymentRef =>
222
+ E.when(paymentRef, payment => state.deposit.receive(payment)),
223
+ );
224
+ const amounts = await deeplyFulfilledObject(amountPKeywordRecord);
225
+ facets.helper.updateStatus({ payouts: amounts });
226
+ },
227
+ /**
228
+ * If promise disconnected, watch again. Or if there's an Error, handle it.
229
+ *
230
+ * @param {Error | import('@agoric/internal/src/upgrade-api.js').UpgradeDisconnection} reason
231
+ * @param {UserSeat} seat
232
+ */
233
+ onRejected(reason, seat) {
234
+ const { facets } = this;
235
+ if (isUpgradeDisconnection(reason)) {
236
+ void watchForPayout(facets, seat);
237
+ } else {
238
+ facets.helper.handleError(reason);
239
+ }
240
+ },
241
+ },
242
+
243
+ /** @type {OutcomeWatchers['resultWatcher']} */
244
+ resultWatcher: {
245
+ onFulfilled(result) {
246
+ const { facets } = this;
247
+ facets.helper.publishResult(result);
248
+ },
249
+ /**
250
+ * If promise disconnected, watch again. Or if there's an Error, handle it.
251
+ *
252
+ * @param {Error | import('@agoric/internal/src/upgrade-api.js').UpgradeDisconnection} reason
253
+ * @param {UserSeat} seat
254
+ */
255
+ onRejected(reason, seat) {
256
+ const { facets } = this;
257
+ if (isUpgradeDisconnection(reason)) {
258
+ void watchForOfferResult(facets, seat);
259
+ } else {
260
+ facets.helper.handleError(reason);
261
+ }
262
+ },
263
+ },
264
+
265
+ /** @type {OutcomeWatchers['numWantsWatcher']} */
266
+ numWantsWatcher: {
267
+ onFulfilled(numSatisfied) {
268
+ const { facets } = this;
269
+
270
+ facets.helper.updateStatus({ numWantsSatisfied: numSatisfied });
271
+ },
272
+ /**
273
+ * If promise disconnected, watch again.
274
+ *
275
+ * Errors are handled by the paymentWatcher because numWantsSatisfied()
276
+ * and getPayouts() settle the same (they await the same promise and
277
+ * then synchronously return a local value).
278
+ *
279
+ * @param {Error | import('@agoric/internal/src/upgrade-api.js').UpgradeDisconnection} reason
280
+ * @param {UserSeat} seat
281
+ */
282
+ onRejected(reason, seat) {
283
+ const { facets } = this;
284
+ if (isUpgradeDisconnection(reason)) {
285
+ void watchForNumWants(facets, seat);
286
+ }
287
+ },
288
+ },
289
+ },
290
+ );
291
+ };
292
+ harden(prepareOfferWatcher);
293
+
294
+ /** @typedef {ReturnType<typeof prepareOfferWatcher>} MakeOfferWatcher */
package/src/offers.d.ts CHANGED
@@ -4,41 +4,17 @@
4
4
  /**
5
5
  * @typedef {{
6
6
  * id: OfferId,
7
- * invitationSpec: import('./invitations').InvitationSpec,
7
+ * invitationSpec: import('./invitations.js').InvitationSpec,
8
8
  * proposal: Proposal,
9
9
  * offerArgs?: unknown
10
10
  * }} OfferSpec
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').InvitationSpec) => ERef<Invitation>;
23
- purseForBrand: (brand: Brand) => Promise<import('./types').RemotePurse>;
24
- };
25
- onStatusChange: (status: OfferStatus) => void;
26
- onNewContinuingOffer: (offerId: string, invitationAmount: Amount<'set'>, invitationMakers: import('./types').RemoteInvitationMakers, publicSubscribers: import('./types').PublicSubscribers | import('@agoric/zoe/src/contractSupport').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;
41
- invitationSpec: import('./invitations').InvitationSpec;
17
+ invitationSpec: import('./invitations.js').InvitationSpec;
42
18
  proposal: Proposal;
43
19
  offerArgs?: unknown;
44
20
  };
@@ -1 +1 @@
1
- {"version":3,"file":"offers.d.ts","sourceRoot":"","sources":["offers.js"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;;;;;GAOG;AAEH,kEA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