@agoric/inter-protocol 0.16.2-dev-b9f5667.0 → 0.16.2-dev-74a89a7.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.16.2-dev-b9f5667.0+b9f5667",
3
+ "version": "0.16.2-dev-74a89a7.0+74a89a7",
4
4
  "description": "Core cryptoeconomy contracts",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -31,15 +31,15 @@
31
31
  },
32
32
  "homepage": "https://github.com/Agoric/agoric-sdk#readme",
33
33
  "dependencies": {
34
- "@agoric/ertp": "0.16.3-dev-b9f5667.0+b9f5667",
35
- "@agoric/governance": "0.10.4-dev-b9f5667.0+b9f5667",
36
- "@agoric/internal": "0.3.3-dev-b9f5667.0+b9f5667",
37
- "@agoric/notifier": "0.6.3-dev-b9f5667.0+b9f5667",
38
- "@agoric/store": "0.9.3-dev-b9f5667.0+b9f5667",
39
- "@agoric/time": "0.3.3-dev-b9f5667.0+b9f5667",
40
- "@agoric/vat-data": "0.5.3-dev-b9f5667.0+b9f5667",
41
- "@agoric/vats": "0.15.2-dev-b9f5667.0+b9f5667",
42
- "@agoric/zoe": "0.26.3-dev-b9f5667.0+b9f5667",
34
+ "@agoric/ertp": "0.16.3-dev-74a89a7.0+74a89a7",
35
+ "@agoric/governance": "0.10.4-dev-74a89a7.0+74a89a7",
36
+ "@agoric/internal": "0.3.3-dev-74a89a7.0+74a89a7",
37
+ "@agoric/notifier": "0.6.3-dev-74a89a7.0+74a89a7",
38
+ "@agoric/store": "0.9.3-dev-74a89a7.0+74a89a7",
39
+ "@agoric/time": "0.3.3-dev-74a89a7.0+74a89a7",
40
+ "@agoric/vat-data": "0.5.3-dev-74a89a7.0+74a89a7",
41
+ "@agoric/vats": "0.15.2-dev-74a89a7.0+74a89a7",
42
+ "@agoric/zoe": "0.26.3-dev-74a89a7.0+74a89a7",
43
43
  "@endo/captp": "^4.2.2",
44
44
  "@endo/errors": "^1.2.4",
45
45
  "@endo/eventual-send": "^1.2.4",
@@ -50,10 +50,10 @@
50
50
  "jessie.js": "^0.3.4"
51
51
  },
52
52
  "devDependencies": {
53
- "@agoric/smart-wallet": "0.5.4-dev-b9f5667.0+b9f5667",
54
- "@agoric/swingset-liveslots": "0.10.3-dev-b9f5667.0+b9f5667",
55
- "@agoric/swingset-vat": "0.32.3-dev-b9f5667.0+b9f5667",
56
- "@agoric/zone": "0.2.3-dev-b9f5667.0+b9f5667",
53
+ "@agoric/smart-wallet": "0.5.4-dev-74a89a7.0+74a89a7",
54
+ "@agoric/swingset-liveslots": "0.10.3-dev-74a89a7.0+74a89a7",
55
+ "@agoric/swingset-vat": "0.32.3-dev-74a89a7.0+74a89a7",
56
+ "@agoric/zone": "0.2.3-dev-74a89a7.0+74a89a7",
57
57
  "@endo/bundle-source": "^3.3.0",
58
58
  "@endo/init": "^1.1.3",
59
59
  "@endo/promise-kit": "^1.1.4",
@@ -84,5 +84,5 @@
84
84
  "typeCoverage": {
85
85
  "atLeast": 95.81
86
86
  },
87
- "gitHead": "b9f5667ddb39267445c232e24e62cde12685a42a"
87
+ "gitHead": "74a89a7af2190b538bd8221486566e02e29dfe20"
88
88
  }
@@ -1 +1 @@
1
- {"version":3,"file":"auctionBook.d.ts","sourceRoot":"","sources":["auctionBook.js"],"names":[],"mappings":"AA+EO,6CAHI,KAAK,CAAC,KAAK,CAAC,mBACZ,KAAK,CAAC,KAAK,CAAC,oCAiBtB;AAwBM,4CAJI,OAAO,OACP,GAAG,mBACH,OAAO,6CAA6C,EAAE,eAAe,8IA8pBtE,UAAU,mJA5jBZ,WAAQ;;QAqBR;;;;;;WAMG;+BAFQ,MAAM,SACN,KAAK,GAAG,SAAS;QAW5B;;;;;;;WAOG;2BAHQ,MAAM,kBACN,MAAM,SACN,KAAK,GAAG,SAAS;QAW5B;;;;;;WAMG;qBAFQ,OAA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AM,CAAC,KAAK,CAAC;;;;;yBAEb,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI;;0BA6pBpB,UAAU,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;6BA3uBrC,kBAAkB;oCACiD,4BAA4B"}
@@ -12,7 +12,6 @@ import { assertAllDefined, makeTracer } from '@agoric/internal';
12
12
  import {
13
13
  atomicRearrange,
14
14
  ceilMultiplyBy,
15
- floorDivideBy,
16
15
  makeRatioFromAmounts,
17
16
  makeRecorderTopic,
18
17
  multiplyRatios,
@@ -21,6 +20,7 @@ import {
21
20
  import { observeNotifier } from '@agoric/notifier';
22
21
 
23
22
  import { makeNatAmountShape } from '../contractSupport.js';
23
+ import { amountsToSettle } from './auctionMath.js';
24
24
  import { preparePriceBook, prepareScaledBidBook } from './offerBook.js';
25
25
  import {
26
26
  isScaledBidPriceHigher,
@@ -282,39 +282,30 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
282
282
  return makeEmpty(collateralBrand);
283
283
  }
284
284
 
285
- /** @type {Amount<'nat'>} */
286
- const initialCollateralTarget = AmountMath.min(
287
- collateralWanted,
288
- collateralAvailable,
289
- );
290
-
291
285
  const { curAuctionPrice, bidHoldingSeat, remainingProceedsGoal } =
292
286
  this.state;
293
287
  curAuctionPrice !== null ||
294
288
  Fail`auctionPrice must be set before each round`;
295
289
  assert(curAuctionPrice);
296
290
 
297
- const proceedsNeeded = ceilMultiplyBy(
298
- initialCollateralTarget,
299
- curAuctionPrice,
300
- );
301
- if (AmountMath.isEmpty(proceedsNeeded)) {
291
+ const { proceedsExpected, proceedsTarget, collateralTarget } =
292
+ amountsToSettle(
293
+ {
294
+ bidAlloc,
295
+ collateralWanted,
296
+ collateralAvailable,
297
+ curAuctionPrice,
298
+ remainingProceedsGoal,
299
+ },
300
+ trace,
301
+ );
302
+
303
+ if (proceedsExpected === null) {
302
304
  seat.fail(Error('price fell to zero'));
303
305
  return makeEmpty(collateralBrand);
304
306
  }
305
307
 
306
- const minProceedsTarget = AmountMath.min(proceedsNeeded, bidAlloc);
307
- const proceedsLimit = remainingProceedsGoal
308
- ? AmountMath.min(remainingProceedsGoal, minProceedsTarget)
309
- : minProceedsTarget;
310
- const isRaiseLimited =
311
- remainingProceedsGoal ||
312
- !AmountMath.isGTE(proceedsLimit, proceedsNeeded);
313
-
314
- const [proceedsTarget, collateralTarget] = isRaiseLimited
315
- ? [proceedsLimit, floorDivideBy(proceedsLimit, curAuctionPrice)]
316
- : [minProceedsTarget, initialCollateralTarget];
317
-
308
+ // check that the requested amount could be satisfied
318
309
  const { Collateral } = seat.getProposal().want;
319
310
  if (Collateral && AmountMath.isGTE(Collateral, collateralTarget)) {
320
311
  seat.exit('unable to satisfy want');
@@ -335,7 +326,7 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
335
326
  );
336
327
  }
337
328
 
338
- trace('settle', {
329
+ trace('settled', {
339
330
  collateralTarget,
340
331
  proceedsTarget,
341
332
  remainingProceedsGoal: this.state.remainingProceedsGoal,
@@ -611,20 +602,14 @@ export const prepareAuctionBook = (baggage, zcf, makeRecorderKit) => {
611
602
  const pricedOffers = priceBook.offersAbove(curAuctionPrice);
612
603
  const scaledBidOffers = scaledBidBook.offersAbove(reduction);
613
604
 
614
- const compareValues = (v1, v2) => {
615
- if (v1 < v2) {
616
- return -1;
617
- } else if (v1 === v2) {
618
- return 0;
619
- } else {
620
- return 1;
621
- }
622
- };
623
- trace(`settling`, pricedOffers.length, scaledBidOffers.length);
624
605
  // requested price or BidScaling gives no priority beyond specifying which
625
606
  // round the order will be serviced in.
626
607
  const prioritizedOffers = [...pricedOffers, ...scaledBidOffers].sort(
627
- (a, b) => compareValues(a[1].seqNum, b[1].seqNum),
608
+ (a, b) => Number(a[1].seqNum - b[1].seqNum),
609
+ );
610
+
611
+ trace(
612
+ `settling ${prioritizedOffers.length} offers at ${curAuctionPrice} (priced ${pricedOffers.length}, scaled ${scaledBidOffers.length}) `,
628
613
  );
629
614
 
630
615
  const { remainingProceedsGoal } = state;
@@ -0,0 +1,17 @@
1
+ export function amountsToSettle({ bidAlloc, collateralWanted, collateralAvailable, curAuctionPrice, remainingProceedsGoal, }: {
2
+ bidAlloc: Amount<"nat">;
3
+ collateralWanted: Amount<"nat">;
4
+ collateralAvailable: Amount<"nat">;
5
+ curAuctionPrice: Ratio;
6
+ remainingProceedsGoal: Amount<"nat"> | null;
7
+ }, log?: ((...msgs: any[]) => void) | undefined): {
8
+ proceedsExpected: null;
9
+ proceedsTarget?: undefined;
10
+ collateralTarget?: undefined;
11
+ } | {
12
+ proceedsExpected: import("@agoric/ertp/src/types.js").NatAmount;
13
+ proceedsTarget: import("@agoric/ertp/src/types.js").NatAmount;
14
+ collateralTarget: import("@agoric/ertp/src/types.js").NatAmount;
15
+ };
16
+ import type { Amount } from '@agoric/ertp/src/types.js';
17
+ //# sourceMappingURL=auctionMath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auctionMath.d.ts","sourceRoot":"","sources":["auctionMath.js"],"names":[],"mappings":"AAoBO,8HARJ;IAAyB,QAAQ,EAAzB,OAAO,KAAK,CAAC;IACI,gBAAgB,EAAjC,OAAO,KAAK,CAAC;IACI,mBAAmB,EAApC,OAAO,KAAK,CAAC;IACJ,eAAe,EAAxB,KAAK;IACmB,qBAAqB,EAA7C,OAAO,KAAK,CAAC,GAAG,IAAI;CAE5B,mBAAkB,GAAG,EAAE,KAAK,IAAI;;;;;;;;EA6DlC;4BAxEwB,2BAA2B"}
@@ -0,0 +1,81 @@
1
+ import { AmountMath } from '@agoric/ertp';
2
+ import {
3
+ ceilMultiplyBy,
4
+ floorDivideBy,
5
+ } from '@agoric/zoe/src/contractSupport/index.js';
6
+
7
+ /**
8
+ * @import {Amount} from '@agoric/ertp/src/types.js';
9
+ */
10
+
11
+ /**
12
+ * @param {object} p
13
+ * @param {Amount<'nat'>} p.bidAlloc current allocation of the bidding seat
14
+ * @param {Amount<'nat'>} p.collateralWanted want of the offer
15
+ * @param {Amount<'nat'>} p.collateralAvailable available to auction
16
+ * @param {Ratio} p.curAuctionPrice current auction price
17
+ * @param {Amount<'nat'> | null} p.remainingProceedsGoal amount still needing
18
+ * liquidating over multiple rounds; null indicates no limit
19
+ * @param {(...msgs: any[]) => void} [log]
20
+ */
21
+ export const amountsToSettle = (
22
+ {
23
+ bidAlloc,
24
+ collateralWanted,
25
+ collateralAvailable,
26
+ curAuctionPrice,
27
+ remainingProceedsGoal,
28
+ },
29
+ log = () => {},
30
+ ) => {
31
+ log('amountsToSettle', {
32
+ bidAlloc,
33
+ collateralWanted,
34
+ collateralAvailable,
35
+ curAuctionPrice,
36
+ remainingProceedsGoal,
37
+ });
38
+ const initialCollateralTarget = AmountMath.min(
39
+ collateralWanted,
40
+ collateralAvailable,
41
+ );
42
+
43
+ const proceedsExpected = ceilMultiplyBy(
44
+ initialCollateralTarget,
45
+ curAuctionPrice,
46
+ );
47
+ if (AmountMath.isEmpty(proceedsExpected)) {
48
+ return { proceedsExpected: null };
49
+ }
50
+
51
+ const targetByProceeds = proceedsLimit =>
52
+ AmountMath.min(
53
+ collateralAvailable,
54
+ floorDivideBy(proceedsLimit, curAuctionPrice),
55
+ );
56
+
57
+ const [proceedsTarget, collateralTarget] = (() => {
58
+ // proceeds cannot exceed what is needed or being offered
59
+ const proceedsBidded = AmountMath.min(proceedsExpected, bidAlloc);
60
+ if (remainingProceedsGoal) {
61
+ const goalProceeds = AmountMath.min(
62
+ remainingProceedsGoal,
63
+ proceedsBidded,
64
+ );
65
+ return [goalProceeds, targetByProceeds(goalProceeds)];
66
+ } else if (AmountMath.isGTE(proceedsBidded, proceedsExpected)) {
67
+ // initial collateral suffices
68
+ return [proceedsBidded, initialCollateralTarget];
69
+ } else {
70
+ return [proceedsBidded, targetByProceeds(proceedsBidded)];
71
+ }
72
+ })();
73
+
74
+ assert(
75
+ AmountMath.isGTE(collateralAvailable, collateralTarget),
76
+ 'target cannot exceed available',
77
+ );
78
+
79
+ return { proceedsExpected, proceedsTarget, collateralTarget };
80
+ };
81
+ harden(amountsToSettle);