@agoric/inter-protocol 0.13.2-dev-bf35d83.0 → 0.13.2-dev-58d36fb.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/inter-protocol",
3
- "version": "0.13.2-dev-bf35d83.0+bf35d83",
3
+ "version": "0.13.2-dev-58d36fb.0+58d36fb",
4
4
  "description": "Core cryptoeconomy contracts",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -29,16 +29,16 @@
29
29
  },
30
30
  "homepage": "https://github.com/Agoric/agoric-sdk#readme",
31
31
  "dependencies": {
32
- "@agoric/assert": "0.5.2-dev-bf35d83.0+bf35d83",
33
- "@agoric/ertp": "0.15.4-dev-bf35d83.0+bf35d83",
34
- "@agoric/governance": "0.9.2-dev-bf35d83.0+bf35d83",
35
- "@agoric/internal": "0.2.2-dev-bf35d83.0+bf35d83",
36
- "@agoric/notifier": "0.5.2-dev-bf35d83.0+bf35d83",
37
- "@agoric/store": "0.8.4-dev-bf35d83.0+bf35d83",
38
- "@agoric/time": "0.2.2-dev-bf35d83.0+bf35d83",
39
- "@agoric/vat-data": "0.4.4-dev-bf35d83.0+bf35d83",
40
- "@agoric/vats": "0.13.1-dev-bf35d83.0+bf35d83",
41
- "@agoric/zoe": "0.25.4-dev-bf35d83.0+bf35d83",
32
+ "@agoric/assert": "0.5.2-dev-58d36fb.0+58d36fb",
33
+ "@agoric/ertp": "0.15.4-dev-58d36fb.0+58d36fb",
34
+ "@agoric/governance": "0.9.2-dev-58d36fb.0+58d36fb",
35
+ "@agoric/internal": "0.2.2-dev-58d36fb.0+58d36fb",
36
+ "@agoric/notifier": "0.5.2-dev-58d36fb.0+58d36fb",
37
+ "@agoric/store": "0.8.4-dev-58d36fb.0+58d36fb",
38
+ "@agoric/time": "0.2.2-dev-58d36fb.0+58d36fb",
39
+ "@agoric/vat-data": "0.4.4-dev-58d36fb.0+58d36fb",
40
+ "@agoric/vats": "0.13.1-dev-58d36fb.0+58d36fb",
41
+ "@agoric/zoe": "0.25.4-dev-58d36fb.0+58d36fb",
42
42
  "@endo/captp": "^2.0.18",
43
43
  "@endo/eventual-send": "^0.16.8",
44
44
  "@endo/far": "^0.2.14",
@@ -46,10 +46,10 @@
46
46
  "@endo/nat": "^4.1.23"
47
47
  },
48
48
  "devDependencies": {
49
- "@agoric/deploy-script-support": "0.9.5-dev-bf35d83.0+bf35d83",
50
- "@agoric/smart-wallet": "0.4.3-dev-bf35d83.0+bf35d83",
51
- "@agoric/swingset-liveslots": "0.9.1-dev-bf35d83.0+bf35d83",
52
- "@agoric/swingset-vat": "0.30.3-dev-bf35d83.0+bf35d83",
49
+ "@agoric/deploy-script-support": "0.9.5-dev-58d36fb.0+58d36fb",
50
+ "@agoric/smart-wallet": "0.4.3-dev-58d36fb.0+58d36fb",
51
+ "@agoric/swingset-liveslots": "0.9.1-dev-58d36fb.0+58d36fb",
52
+ "@agoric/swingset-vat": "0.30.3-dev-58d36fb.0+58d36fb",
53
53
  "@endo/bundle-source": "^2.4.2",
54
54
  "@endo/init": "^0.5.52",
55
55
  "@endo/promise-kit": "^0.2.52",
@@ -75,5 +75,5 @@
75
75
  "publishConfig": {
76
76
  "access": "public"
77
77
  },
78
- "gitHead": "bf35d8366bf5b8e69278746ecafee20d0a024756"
78
+ "gitHead": "58d36fb9dfaaad0c0a962ba2940b6fcba2ea8b25"
79
79
  }
@@ -54,10 +54,12 @@ const trace = makeTracer('AucBook', false);
54
54
  /**
55
55
  * @typedef {{
56
56
  * want: Amount<'nat'>
57
+ * } & {
58
+ * exitAfterBuy?: boolean,
57
59
  * } & ({
58
- * offerPrice: Ratio,
60
+ * offerPrice: Ratio,
59
61
  * } | {
60
- * offerBidScaling: Ratio,
62
+ * offerBidScaling: Ratio,
61
63
  * })} BidSpec
62
64
  */
63
65
  /**
@@ -71,6 +73,7 @@ export const makeBidSpecShape = (currencyBrand, collateralBrand) => {
71
73
  return M.splitRecord(
72
74
  { want: collateralAmountShape },
73
75
  {
76
+ exitAfterBuy: M.boolean(),
74
77
  // xxx should have exactly one of these properties
75
78
  offerPrice: makeBrandedRatioPattern(
76
79
  currencyAmountShape,
@@ -266,9 +269,16 @@ export const prepareAuctionBook = (baggage, zcf) => {
266
269
  * @param {ZCFSeat} seat
267
270
  * @param {Ratio} price
268
271
  * @param {Amount<'nat'>} want
269
- * @param {boolean} trySettle
272
+ * @param {object} opts
273
+ * @param {boolean} opts.trySettle
274
+ * @param {boolean} [opts.exitAfterBuy]
270
275
  */
271
- acceptPriceOffer(seat, price, want, trySettle) {
276
+ acceptPriceOffer(
277
+ seat,
278
+ price,
279
+ want,
280
+ { trySettle, exitAfterBuy = false },
281
+ ) {
272
282
  const { priceBook, curAuctionPrice } = this.state;
273
283
  const { helper } = this.facets;
274
284
  trace('acceptPrice');
@@ -281,13 +291,14 @@ export const prepareAuctionBook = (baggage, zcf) => {
281
291
 
282
292
  const stillWant = AmountMath.subtract(want, collateralSold);
283
293
  if (
294
+ (exitAfterBuy && !AmountMath.isEmpty(collateralSold)) ||
284
295
  AmountMath.isEmpty(stillWant) ||
285
296
  AmountMath.isEmpty(seat.getCurrentAllocation().Currency)
286
297
  ) {
287
298
  seat.exit();
288
299
  } else {
289
300
  trace('added Offer ', price, stillWant.value);
290
- priceBook.add(seat, price, stillWant);
301
+ priceBook.add(seat, price, stillWant, exitAfterBuy);
291
302
  }
292
303
  },
293
304
 
@@ -299,9 +310,16 @@ export const prepareAuctionBook = (baggage, zcf) => {
299
310
  * @param {ZCFSeat} seat
300
311
  * @param {Ratio} bidScaling
301
312
  * @param {Amount<'nat'>} want
302
- * @param {boolean} trySettle
313
+ * @param {object} opts
314
+ * @param {boolean} opts.trySettle
315
+ * @param {boolean} [opts.exitAfterBuy]
303
316
  */
304
- acceptScaledBidOffer(seat, bidScaling, want, trySettle) {
317
+ acceptScaledBidOffer(
318
+ seat,
319
+ bidScaling,
320
+ want,
321
+ { trySettle, exitAfterBuy = false },
322
+ ) {
305
323
  trace('accept scaled bid offer');
306
324
  const { curAuctionPrice, lockedPriceForRound, scaledBidBook } =
307
325
  this.state;
@@ -318,12 +336,13 @@ export const prepareAuctionBook = (baggage, zcf) => {
318
336
 
319
337
  const stillWant = AmountMath.subtract(want, collateralSold);
320
338
  if (
339
+ (exitAfterBuy && !AmountMath.isEmpty(collateralSold)) ||
321
340
  AmountMath.isEmpty(stillWant) ||
322
341
  AmountMath.isEmpty(seat.getCurrentAllocation().Currency)
323
342
  ) {
324
343
  seat.exit();
325
344
  } else {
326
- scaledBidBook.add(seat, bidScaling, stillWant);
345
+ scaledBidBook.add(seat, bidScaling, stillWant, exitAfterBuy);
327
346
  }
328
347
  },
329
348
  },
@@ -418,7 +437,8 @@ export const prepareAuctionBook = (baggage, zcf) => {
418
437
 
419
438
  const { totalProceedsGoal } = this.state;
420
439
  const { helper } = this.facets;
421
- for (const [key, { seat, price: p, wanted }] of prioritizedOffers) {
440
+ for (const [key, seatRecord] of prioritizedOffers) {
441
+ const { seat, price: p, wanted, exitAfterBuy } = seatRecord;
422
442
  if (totalProceedsGoal && AmountMath.isEmpty(totalProceedsGoal)) {
423
443
  break;
424
444
  } else if (seat.hasExited()) {
@@ -428,6 +448,7 @@ export const prepareAuctionBook = (baggage, zcf) => {
428
448
 
429
449
  const alloc = seat.getCurrentAllocation();
430
450
  if (
451
+ (exitAfterBuy && !AmountMath.isEmpty(collateralSold)) ||
431
452
  AmountMath.isEmpty(alloc.Currency) ||
432
453
  ('Collateral' in alloc &&
433
454
  AmountMath.isGTE(alloc.Collateral, wanted))
@@ -462,32 +483,17 @@ export const prepareAuctionBook = (baggage, zcf) => {
462
483
  );
463
484
  },
464
485
  /**
465
- *
466
486
  * @param {BidSpec} bidSpec
467
487
  * @param {ZCFSeat} seat
468
488
  * @param {boolean} trySettle
469
489
  */
470
490
  addOffer(bidSpec, seat, trySettle) {
471
- const { collateralAmountShape, currencyAmountShape } = this.state;
472
- const BidSpecShape = M.or(
473
- {
474
- want: collateralAmountShape,
475
- offerPrice: makeBrandedRatioPattern(
476
- currencyAmountShape,
477
- collateralAmountShape,
478
- ),
479
- },
480
- {
481
- want: collateralAmountShape,
482
- offerBidScaling: makeBrandedRatioPattern(
483
- currencyAmountShape,
484
- currencyAmountShape,
485
- ),
486
- },
487
- );
491
+ const { currencyBrand, collateralBrand } = this.state;
492
+ const BidSpecShape = makeBidSpecShape(currencyBrand, collateralBrand);
488
493
 
489
494
  mustMatch(bidSpec, BidSpecShape);
490
495
  const { give } = seat.getProposal();
496
+ const { currencyAmountShape } = this.state;
491
497
  mustMatch(
492
498
  give.Currency,
493
499
  currencyAmountShape,
@@ -495,19 +501,26 @@ export const prepareAuctionBook = (baggage, zcf) => {
495
501
  );
496
502
 
497
503
  const { helper } = this.facets;
504
+ const { exitAfterBuy } = bidSpec;
498
505
  if ('offerPrice' in bidSpec) {
499
506
  return helper.acceptPriceOffer(
500
507
  seat,
501
508
  bidSpec.offerPrice,
502
509
  bidSpec.want,
503
- trySettle,
510
+ {
511
+ trySettle,
512
+ exitAfterBuy,
513
+ },
504
514
  );
505
515
  } else if ('offerBidScaling' in bidSpec) {
506
516
  return helper.acceptScaledBidOffer(
507
517
  seat,
508
518
  bidSpec.offerBidScaling,
509
519
  bidSpec.want,
510
- trySettle,
520
+ {
521
+ trySettle,
522
+ exitAfterBuy,
523
+ },
511
524
  );
512
525
  } else {
513
526
  throw Fail`Offer was neither a price nor a scaled bid`;
@@ -420,7 +420,9 @@ export const start = async (zcf, privateArgs, baggage) => {
420
420
  deposits.set(brand, []);
421
421
  } else if (depositsForBrand.length > 1) {
422
422
  const collProceeds = collateralSeat.getCurrentAllocation().Collateral;
423
- const currProceeds = currencySeat.getCurrentAllocation().Currency;
423
+ const currProceeds =
424
+ currencySeat.getCurrentAllocation().Currency ||
425
+ AmountMath.makeEmpty(brands.Currency);
424
426
  const transfers = distributeProportionalSharesWithLimits(
425
427
  collProceeds,
426
428
  currProceeds,
@@ -29,7 +29,7 @@ const nextSequenceNumber = () => {
29
29
  * wanted: Amount<'nat'>,
30
30
  * seqNum: NatValue,
31
31
  * received: Amount<'nat'>,
32
- * } & ({ bidScaling: Pattern, price: undefined } | { bidScaling: undefined, price: Ratio})
32
+ * } & {exitAfterBuy: boolean} & ({ bidScaling: Pattern, price: undefined } | { bidScaling: undefined, price: Ratio})
33
33
  * } BidderRecord
34
34
  */
35
35
 
@@ -60,8 +60,9 @@ export const prepareScaledBidBook = baggage =>
60
60
  * @param {ZCFSeat} seat
61
61
  * @param {Ratio} bidScaling
62
62
  * @param {Amount<'nat'>} wanted
63
+ * @param {boolean} exitAfterBuy
63
64
  */
64
- add(seat, bidScaling, wanted) {
65
+ add(seat, bidScaling, wanted, exitAfterBuy) {
65
66
  const { bidScalingPattern, collateralBrand, records } = this.state;
66
67
  mustMatch(bidScaling, bidScalingPattern);
67
68
 
@@ -76,6 +77,7 @@ export const prepareScaledBidBook = baggage =>
76
77
  seat,
77
78
  seqNum,
78
79
  wanted,
80
+ exitAfterBuy,
79
81
  };
80
82
  records.init(key, harden(bidderRecord));
81
83
  return key;
@@ -139,7 +141,13 @@ export const preparePriceBook = baggage =>
139
141
  records: makeScalarBigMapStore('scaledBidRecords', { durable: true }),
140
142
  }),
141
143
  {
142
- add(seat, price, wanted) {
144
+ /**
145
+ * @param {ZCFSeat} seat
146
+ * @param {Ratio} price
147
+ * @param {Amount<'nat'>} wanted
148
+ * @param {boolean} exitAfterBuy
149
+ */
150
+ add(seat, price, wanted, exitAfterBuy) {
143
151
  const { priceRatioPattern, collateralBrand, records } = this.state;
144
152
  mustMatch(price, priceRatioPattern);
145
153
 
@@ -154,6 +162,7 @@ export const preparePriceBook = baggage =>
154
162
  seat,
155
163
  seqNum,
156
164
  wanted,
165
+ exitAfterBuy,
157
166
  };
158
167
  records.init(key, harden(bidderRecord));
159
168
  return key;