@agoric/inter-protocol 0.13.2-dev-65d3f14.0 → 0.13.2-pismo-dev-12e97f1.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.
Files changed (103) hide show
  1. package/bundles/bundle-amm-meta.js +168 -188
  2. package/bundles/bundle-amm.js +1 -1
  3. package/bundles/bundle-feeDistributor-meta.js +92 -92
  4. package/bundles/bundle-feeDistributor.js +1 -1
  5. package/bundles/bundle-interchainPool-meta.js +174 -190
  6. package/bundles/bundle-interchainPool.js +1 -1
  7. package/bundles/bundle-liquidateIncrementally-meta.js +149 -109
  8. package/bundles/bundle-liquidateIncrementally.js +1 -1
  9. package/bundles/bundle-liquidateMinimum-meta.js +149 -109
  10. package/bundles/bundle-liquidateMinimum.js +1 -1
  11. package/bundles/bundle-psm-meta.js +148 -168
  12. package/bundles/bundle-psm.js +1 -1
  13. package/bundles/bundle-psmCharter-meta.js +418 -0
  14. package/bundles/bundle-psmCharter.js +1 -0
  15. package/bundles/bundle-reserve-meta.js +176 -192
  16. package/bundles/bundle-reserve.js +1 -1
  17. package/bundles/bundle-scaledPriceAuthority-meta.js +173 -133
  18. package/bundles/bundle-scaledPriceAuthority.js +1 -1
  19. package/bundles/bundle-stakeFactory-meta.js +186 -206
  20. package/bundles/bundle-stakeFactory.js +1 -1
  21. package/bundles/bundle-vaultFactory-meta.js +197 -217
  22. package/bundles/bundle-vaultFactory.js +1 -1
  23. package/package.json +23 -25
  24. package/scripts/add-collateral-core.js +3 -52
  25. package/scripts/add-initial-liquidity.js +1 -0
  26. package/scripts/build-bundles.js +1 -4
  27. package/scripts/deploy-contracts.js +1 -0
  28. package/scripts/init-core.js +9 -11
  29. package/scripts/invite-committee-core.js +1 -0
  30. package/scripts/manual-price-feed.js +1 -1
  31. package/scripts/price-feed-core.js +2 -2
  32. package/src/collect.js +2 -0
  33. package/src/collectFees.js +4 -3
  34. package/src/contractSupport.js +27 -13
  35. package/src/econCommitteeCharter.js +80 -110
  36. package/src/feeDistributor.js +8 -6
  37. package/src/interchainPool.js +8 -7
  38. package/src/interest-math.js +2 -0
  39. package/src/interest.js +10 -6
  40. package/src/makeTracer.js +0 -5
  41. package/src/my-lien.js +7 -3
  42. package/src/proposals/addAssetToVault.js +5 -3
  43. package/src/proposals/committee-proposal.js +42 -112
  44. package/src/proposals/core-proposal.js +30 -17
  45. package/src/proposals/demoIssuers.js +16 -17
  46. package/src/proposals/econ-behaviors.js +115 -156
  47. package/src/proposals/price-feed-proposal.js +6 -118
  48. package/src/proposals/sim-behaviors.js +1 -0
  49. package/src/proposals/startEconCommittee.js +2 -1
  50. package/src/proposals/startPSM.js +117 -77
  51. package/src/proposals/utils.js +12 -23
  52. package/src/psm/psm.js +55 -37
  53. package/src/psm/psmCharter.js +139 -0
  54. package/src/reserve/assetReserve.js +35 -28
  55. package/src/reserve/params.js +2 -0
  56. package/src/stakeFactory/attestation.js +9 -4
  57. package/src/stakeFactory/attestationTool.js +1 -0
  58. package/src/stakeFactory/params.js +1 -0
  59. package/src/stakeFactory/stakeFactory.js +1 -1
  60. package/src/stakeFactory/stakeFactoryKit.js +20 -13
  61. package/src/stakeFactory/stakeFactoryManager.js +3 -2
  62. package/src/vaultFactory/burn.js +1 -0
  63. package/src/vaultFactory/liquidateIncrementally.js +8 -5
  64. package/src/vaultFactory/liquidateMinimum.js +6 -2
  65. package/src/vaultFactory/liquidation.js +2 -2
  66. package/src/vaultFactory/orderedVaultStore.js +1 -0
  67. package/src/vaultFactory/params.js +12 -7
  68. package/src/vaultFactory/prioritizedVaults.js +1 -0
  69. package/src/vaultFactory/storeUtils.js +1 -0
  70. package/src/vaultFactory/types.js +2 -0
  71. package/src/vaultFactory/vault.js +40 -26
  72. package/src/vaultFactory/vaultDirector.js +18 -15
  73. package/src/vaultFactory/vaultFactory.js +20 -19
  74. package/src/vaultFactory/vaultHolder.js +3 -4
  75. package/src/vaultFactory/vaultKit.js +1 -0
  76. package/src/vaultFactory/vaultManager.js +10 -7
  77. package/src/vpool-xyk-amm/addLiquidity.js +4 -3
  78. package/src/vpool-xyk-amm/addPool.js +20 -23
  79. package/src/vpool-xyk-amm/constantProduct/calcFees.js +12 -6
  80. package/src/vpool-xyk-amm/constantProduct/calcSwapPrices.js +2 -0
  81. package/src/vpool-xyk-amm/constantProduct/core.js +24 -16
  82. package/src/vpool-xyk-amm/constantProduct/defaults.js +2 -0
  83. package/src/vpool-xyk-amm/constantProduct/getXY.js +6 -2
  84. package/src/vpool-xyk-amm/constantProduct/internal-types.js +14 -12
  85. package/src/vpool-xyk-amm/constantProduct/invariants.js +8 -4
  86. package/src/vpool-xyk-amm/constantProduct/swap.js +19 -17
  87. package/src/vpool-xyk-amm/constantProduct/types.js +2 -0
  88. package/src/vpool-xyk-amm/doublePool.js +14 -20
  89. package/src/vpool-xyk-amm/estimate.js +2 -0
  90. package/src/vpool-xyk-amm/multipoolMarketMaker.js +5 -3
  91. package/src/vpool-xyk-amm/params.js +2 -0
  92. package/src/vpool-xyk-amm/pool.js +14 -16
  93. package/src/vpool-xyk-amm/priceAuthority.js +3 -1
  94. package/src/vpool-xyk-amm/removeLiquidity.js +2 -0
  95. package/src/vpool-xyk-amm/singlePool.js +14 -29
  96. package/src/vpool-xyk-amm/swap.js +1 -0
  97. package/src/vpool-xyk-amm/types.js +12 -10
  98. package/bundles/bundle-econCommitteeCharter-meta.js +0 -418
  99. package/bundles/bundle-econCommitteeCharter.js +0 -1
  100. package/scripts/start-local-chain-boot.js +0 -96
  101. package/scripts/start-local-chain-config.json +0 -83
  102. package/scripts/start-local-chain.sh +0 -69
  103. package/src/psm/README.md +0 -71
@@ -1,14 +1,18 @@
1
+ // @ts-check
2
+
1
3
  import { AmountMath } from '@agoric/ertp';
2
4
 
3
5
  import { natSafeMath } from '@agoric/zoe/src/contractSupport/index.js';
4
6
  import { makeRatioFromAmounts } from '@agoric/zoe/src/contractSupport/ratio.js';
5
7
  import { getXY } from './getXY.js';
6
8
 
7
- const { Fail } = assert;
9
+ const { details: X } = assert;
8
10
 
9
11
  const assertSingleBrand = ratio => {
10
12
  ratio.numerator.brand === ratio.denominator.brand ||
11
- Fail`Ratio was expected to have same brand in numerator ${ratio.numerator.brand} and denominator ${ratio.denominator.brand}`;
13
+ assert.fail(
14
+ X`Ratio was expected to have same brand in numerator ${ratio.numerator.brand} and denominator ${ratio.denominator.brand}`,
15
+ );
12
16
  };
13
17
 
14
18
  /**
@@ -16,9 +20,9 @@ const assertSingleBrand = ratio => {
16
20
  * in favor of the amount brand. This is necessary because the ratio is produced
17
21
  * by dividing assets of the opposite brand.
18
22
  *
19
- * @param {Amount<'nat'>} amount
23
+ * @param {Amount} amount
20
24
  * @param {Ratio} ratio
21
- * @returns {Amount<'nat'>}
25
+ * @returns {Amount}
22
26
  */
23
27
  const floorMultiplyKeepBrand = (amount, ratio) => {
24
28
  assertSingleBrand(ratio);
@@ -34,9 +38,9 @@ const floorMultiplyKeepBrand = (amount, ratio) => {
34
38
  * in favor of the amount brand. This is necessary because the ratio is produced
35
39
  * by dividing assets of the opposite brand.
36
40
  *
37
- * @param {Amount<'nat'>} amount
41
+ * @param {Amount} amount
38
42
  * @param {Ratio} ratio
39
- * @returns {Amount<'nat'>}
43
+ * @returns {Amount}
40
44
  */
41
45
  const ceilMultiplyKeepBrand = (amount, ratio) => {
42
46
  assertSingleBrand(ratio);
@@ -57,10 +61,10 @@ const ceilMultiplyKeepBrand = (amount, ratio) => {
57
61
  * deltaY = (deltaXOverX/(1 + deltaXOverX))*y
58
62
  * Equivalently: (deltaX / (deltaX + x)) * y
59
63
  *
60
- * @param {Amount<'nat'>} x - the amount of Brand X in pool
61
- * @param {Amount<'nat'>} y - the amount of Brand Y the pool
62
- * @param {Amount<'nat'>} deltaX - the amount of Brand X to be added
63
- * @returns {Amount<'nat'>} deltaY - the amount of Brand Y to be taken out
64
+ * @param {Amount} x - the amount of Brand X in pool
65
+ * @param {Amount} y - the amount of Brand Y the pool
66
+ * @param {Amount} deltaX - the amount of Brand X to be added
67
+ * @returns {Amount} deltaY - the amount of Brand Y to be taken out
64
68
  */
65
69
  export const calcDeltaYSellingX = (x, y, deltaX) => {
66
70
  const deltaXPlusX = AmountMath.add(deltaX, x);
@@ -79,10 +83,10 @@ export const calcDeltaYSellingX = (x, y, deltaX) => {
79
83
  * deltaX = (deltaYOverY/(1 - deltaYOverY))*x
80
84
  * Equivalently: (deltaY / (Y - deltaY )) * x
81
85
  *
82
- * @param {Amount<'nat'>} x - the amount of Brand X in the pool
83
- * @param {Amount<'nat'>} y - the amount of Brand Y in the pool
84
- * @param {Amount<'nat'>} deltaY - the amount of Brand Y to be taken out
85
- * @returns {Amount<'nat'>} deltaX - the amount of Brand X to be added
86
+ * @param {Amount} x - the amount of Brand X in the pool
87
+ * @param {Amount} y - the amount of Brand Y in the pool
88
+ * @param {Amount} deltaY - the amount of Brand Y to be taken out
89
+ * @returns {Amount} deltaX - the amount of Brand X to be added
86
90
  */
87
91
  export const calcDeltaXSellingX = (x, y, deltaY) => {
88
92
  const yMinusDeltaY = AmountMath.subtract(y, deltaY);
@@ -104,7 +108,9 @@ const swapInReduced = ({ x, y, deltaX: offeredAmountIn }) => {
104
108
  const amountOut = calcDeltaYSellingX(x, y, offeredAmountIn);
105
109
  const reducedAmountIn = calcDeltaXSellingX(x, y, amountOut);
106
110
  AmountMath.isGTE(offeredAmountIn, reducedAmountIn) ||
107
- Fail`The trade would have required ${reducedAmountIn} more than was offered ${offeredAmountIn}`;
111
+ assert.fail(
112
+ X`The trade would have required ${reducedAmountIn} more than was offered ${offeredAmountIn}`,
113
+ );
108
114
 
109
115
  return harden({
110
116
  amountIn: reducedAmountIn,
@@ -124,7 +130,9 @@ const swapOutImproved = ({ x, y, deltaY: wantedAmountOut }) => {
124
130
  const amountIn = calcDeltaXSellingX(x, y, wantedAmountOut);
125
131
  const improvedAmountOut = calcDeltaYSellingX(x, y, amountIn);
126
132
  AmountMath.isGTE(improvedAmountOut, wantedAmountOut) ||
127
- Fail`The trade would have returned ${improvedAmountOut} less than was wanted ${wantedAmountOut}`;
133
+ assert.fail(
134
+ X`The trade would have returned ${improvedAmountOut} less than was wanted ${wantedAmountOut}`,
135
+ );
128
136
 
129
137
  return harden({
130
138
  amountIn,
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  export const BASIS_POINTS = 10000n;
2
4
  export const DEFAULT_POOL_FEE = 24n; // 0.0024 or .24%
3
5
  export const DEFAULT_PROTOCOL_FEE = 6n; // .0006 or .06%
@@ -1,7 +1,9 @@
1
+ // @ts-check
2
+
1
3
  // This does not support secondary to secondary. That has to happen at
2
4
  // a higher abstraction
3
5
 
4
- const { Fail } = assert;
6
+ const { details: X } = assert;
5
7
  /**
6
8
  * The caller provides poolAllocation, which has balances for both Central and
7
9
  * Secondary, and at least one of amountGiven and amountWanted. getXY treats
@@ -21,7 +23,9 @@ export const getXY = ({ amountGiven, poolAllocation, amountWanted }) => {
21
23
  const centralBrand = poolAllocation.Central.brand;
22
24
  amountGiven ||
23
25
  amountWanted ||
24
- Fail`At least one of ${amountGiven} and ${amountWanted} must be specified`;
26
+ assert.fail(
27
+ X`At least one of ${amountGiven} and ${amountWanted} must be specified`,
28
+ );
25
29
 
26
30
  const deltas = {
27
31
  deltaX: amountGiven,
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  /**
2
4
  * @typedef {object} ImprovedNoFeeSwapResult
3
5
  * @property {Amount<'nat'>} amountIn
@@ -41,9 +43,9 @@
41
43
 
42
44
  /**
43
45
  * @callback CalculateFees
44
- * @param {Amount<'nat'>} amountGiven
46
+ * @param {Amount} amountGiven
45
47
  * @param {PoolAllocation} poolAllocation
46
- * @param {Amount<'nat'>} amountWanted
48
+ * @param {Amount} amountWanted
47
49
  * @param {Ratio} protocolFeeRatio
48
50
  * @param {Ratio} poolFeeRatio
49
51
  * @param {NoFeeSwapFn} swapFn
@@ -52,9 +54,9 @@
52
54
 
53
55
  /**
54
56
  * @callback InternalSwap
55
- * @param {Amount<'nat'>} amountGiven
57
+ * @param {Amount} amountGiven
56
58
  * @param {PoolAllocation} poolAllocation
57
- * @param {Amount<'nat'>} amountWanted
59
+ * @param {Amount} amountWanted
58
60
  * @param {Ratio} protocolFeeRatio
59
61
  * @param {Ratio} poolFeeRatio
60
62
  * @param {NoFeeSwapFn} swapFn
@@ -89,18 +91,18 @@
89
91
 
90
92
  /**
91
93
  * @typedef {object} GetXYResultDeltaX
92
- * @property {Amount<'nat'>} x
93
- * @property {Amount<'nat'>} y
94
- * @property {Amount<'nat'>} deltaX
95
- * @property {Amount<'nat'>|undefined} deltaY
94
+ * @property {Amount} x
95
+ * @property {Amount} y
96
+ * @property {Amount} deltaX
97
+ * @property {Amount|undefined} deltaY
96
98
  */
97
99
 
98
100
  /**
99
101
  * @typedef {object} GetXYResultDeltaY
100
- * @property {Amount<'nat'>} x
101
- * @property {Amount<'nat'>} y
102
- * @property {Amount<'nat'>} deltaY
103
- * @property {Amount<'nat'>|undefined} deltaX
102
+ * @property {Amount} x
103
+ * @property {Amount} y
104
+ * @property {Amount} deltaY
105
+ * @property {Amount|undefined} deltaX
104
106
  */
105
107
 
106
108
  /**
@@ -1,4 +1,6 @@
1
- import { Fail } from '@agoric/assert';
1
+ // @ts-check
2
+
3
+ import { assert, details as X } from '@agoric/assert';
2
4
  import { AmountMath } from '@agoric/ertp';
3
5
 
4
6
  import { natSafeMath } from '@agoric/zoe/src/contractSupport/index.js';
@@ -28,12 +30,14 @@ export const checkKInvariantSellingX = (x, y, deltaX, deltaY) => {
28
30
  * @param {Amount} deltaY - the amount of Brand Y to be taken out
29
31
  */
30
32
  export const assertKInvariantSellingX = (x, y, deltaX, deltaY) => {
31
- checkKInvariantSellingX(x, y, deltaX, deltaY) ||
32
- Fail`the constant product invariant was violated, with x=${x}, y=${y}, deltaX=${deltaX}, deltaY=${deltaY}, oldK=${natSafeMath.multiply(
33
+ assert(
34
+ checkKInvariantSellingX(x, y, deltaX, deltaY),
35
+ X`the constant product invariant was violated, with x=${x}, y=${y}, deltaX=${deltaX}, deltaY=${deltaY}, oldK=${natSafeMath.multiply(
33
36
  x.value,
34
37
  y.value,
35
38
  )}, newK=${natSafeMath.multiply(
36
39
  AmountMath.add(x, deltaX).value,
37
40
  AmountMath.subtract(y, deltaY).value,
38
- )}`;
41
+ )}`,
42
+ );
39
43
  };
@@ -1,7 +1,9 @@
1
+ // @ts-check
2
+
1
3
  import { AmountMath } from '@agoric/ertp';
2
4
  import { calculateFees, amountGT } from './calcFees.js';
3
5
 
4
- const { Fail } = assert;
6
+ const { details: X } = assert;
5
7
 
6
8
  /**
7
9
  * The fee might not be in the same brand as the amount. If they are the same,
@@ -10,9 +12,9 @@ const { Fail } = assert;
10
12
  * We return empty if the fee is larger because an empty amount indicates that
11
13
  * the trader didn't place a limit on the inputAmount.
12
14
  *
13
- * @param {Amount<'nat'>} amount
14
- * @param {Amount<'nat'>} fee
15
- * @returns {Amount<'nat'>}
15
+ * @param {Amount} amount
16
+ * @param {Amount} fee
17
+ * @returns {Amount}
16
18
  */
17
19
  const subtractRelevantFees = (amount, fee) => {
18
20
  if (amount.brand === fee.brand) {
@@ -29,9 +31,9 @@ const subtractRelevantFees = (amount, fee) => {
29
31
  * PoolFee and ProtocolFee each identify their brand. If either (or both) match
30
32
  * the brand of the Amount, subtract it/them from the amount.
31
33
  *
32
- * @param {Amount<'nat'>} amount
34
+ * @param {Amount} amount
33
35
  * @param {FeePair} fee
34
- * @returns {Amount<'nat'>}
36
+ * @returns {Amount}
35
37
  */
36
38
  const subtractFees = (amount, { poolFee, protocolFee }) => {
37
39
  return subtractRelevantFees(
@@ -44,9 +46,9 @@ const subtractFees = (amount, { poolFee, protocolFee }) => {
44
46
  * The fee might not be in the same brand as the amount. If they are the same,
45
47
  * add the fee to the amount. Otherwise return the unadjusted amount.
46
48
  *
47
- * @param {Amount<'nat'>} amount
48
- * @param {Amount<'nat'>} fee
49
- * @returns {Amount<'nat'>}
49
+ * @param {Amount} amount
50
+ * @param {Amount} fee
51
+ * @returns {Amount}
50
52
  */
51
53
  const addRelevantFees = (amount, fee) => {
52
54
  if (amount.brand === fee.brand) {
@@ -59,9 +61,9 @@ const addRelevantFees = (amount, fee) => {
59
61
  * PoolFee and ProtocolFee each identify their brand. If either (or both) match
60
62
  * the brand of the Amount, add it/them to the amount.
61
63
  *
62
- * @param {Amount<'nat'>} amount
64
+ * @param {Amount} amount
63
65
  * @param {FeePair} fee
64
- * @returns {Amount<'nat'>}
66
+ * @returns {Amount}
65
67
  */
66
68
  const addFees = (amount, { poolFee, protocolFee }) => {
67
69
  return addRelevantFees(addRelevantFees(amount, protocolFee), poolFee);
@@ -75,10 +77,10 @@ const addFees = (amount, { poolFee, protocolFee }) => {
75
77
  *
76
78
  * The first parameter specifies whether we're incrementing or decrementing from the pool
77
79
  *
78
- * @param {(amountLeft: Amount<any>, amountRight: Amount<any>, brand?: Brand) => Amount<any>} addOrSub
80
+ * @param {(amountLeft: Amount, amountRight: Amount, brand?: Brand) => Amount} addOrSub
79
81
  * @param {PoolAllocation} poolAllocation
80
- * @param {Amount<'nat'>} amount
81
- * @returns {Amount<'nat'>}
82
+ * @param {Amount} amount
83
+ * @returns {Amount}
82
84
  */
83
85
  const addOrSubtractFromPool = (addOrSub, poolAllocation, amount) => {
84
86
  if (poolAllocation.Central.brand === amount.brand) {
@@ -94,7 +96,7 @@ const isGreaterThanZero = amount => {
94
96
 
95
97
  const assertGreaterThanZero = (amount, name) => {
96
98
  (amount && isGreaterThanZero(amount)) ||
97
- Fail`${name} must be greater than 0: ${amount}`;
99
+ assert.fail(X`${name} must be greater than 0: ${amount}`);
98
100
  };
99
101
 
100
102
  const isWantedAvailable = (poolAllocation, amountWanted) => {
@@ -111,8 +113,8 @@ const isWantedAvailable = (poolAllocation, amountWanted) => {
111
113
  * requested, the proceeds would be empty, etc.) Return a result that says no
112
114
  * trade will take place and the pool balances won't change.
113
115
  *
114
- * @param {Amount<'nat'>} amountGiven
115
- * @param {Amount<'nat'>} amountWanted
116
+ * @param {Amount} amountGiven
117
+ * @param {Amount} amountWanted
116
118
  * @param {PoolAllocation} poolAllocation
117
119
  * @param {Ratio} poolFee
118
120
  */
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  /**
2
4
  * @callback Maximum
3
5
  * @param {Amount} left
@@ -1,9 +1,6 @@
1
+ // @ts-check
2
+
1
3
  import { AmountMath } from '@agoric/ertp';
2
- import {
3
- atomicRearrange,
4
- fromOnly,
5
- toOnly,
6
- } from '@agoric/zoe/src/contractSupport/index.js';
7
4
  import { Far } from '@endo/marshal';
8
5
  import { makeFeeRatio } from './constantProduct/calcFees.js';
9
6
  import {
@@ -11,7 +8,7 @@ import {
11
8
  pricesForStatedOutput,
12
9
  } from './constantProduct/calcSwapPrices.js';
13
10
 
14
- const { Fail } = assert;
11
+ const { details: X } = assert;
15
12
 
16
13
  // Price calculations and swap using a pair of pools. Both pools map between RUN
17
14
  // and some collateral. We arrange the trades so collateralInPool will have
@@ -54,26 +51,23 @@ export const makeDoublePool = (
54
51
  const centralBrand = inCentral.brand;
55
52
  const emptyCentralAmount = AmountMath.makeEmpty(centralBrand);
56
53
  centralBrand === outCentral.brand ||
57
- Fail`The central brands on the two pools must match: ${centralBrand}, ${outCentral.brand}`;
54
+ assert.fail(
55
+ X`The central brands on the two pools must match: ${centralBrand}, ${outCentral.brand}`,
56
+ );
58
57
 
59
58
  const allocateGainsAndLosses = (seat, prices) => {
60
59
  const inPoolSeat = collateralInPool.getPoolSeat();
61
60
  const outPoolSeat = collateralOutPool.getPoolSeat();
62
61
 
63
- atomicRearrange(
64
- zcf,
65
- harden([
66
- fromOnly(seat, { In: prices.swapperGives }),
67
- fromOnly(inPoolSeat, { Central: prices.inPoolDecrement }),
68
- fromOnly(outPoolSeat, { Secondary: prices.outPoolDecrement }),
69
-
70
- toOnly(seat, { Out: prices.swapperGets }),
71
- toOnly(inPoolSeat, { Secondary: prices.inPoolIncrement }),
72
- toOnly(outPoolSeat, { Central: prices.outPoolIncrement }),
73
- toOnly(feeSeat, { Fee: prices.protocolFee }),
74
- ]),
75
- );
62
+ seat.decrementBy(harden({ In: prices.swapperGives }));
63
+ inPoolSeat.decrementBy(harden({ Central: prices.inPoolDecrement }));
64
+ outPoolSeat.decrementBy(harden({ Secondary: prices.outPoolDecrement }));
65
+ seat.incrementBy(harden({ Out: prices.swapperGets }));
66
+ inPoolSeat.incrementBy(harden({ Secondary: prices.inPoolIncrement }));
67
+ outPoolSeat.incrementBy(harden({ Central: prices.outPoolIncrement }));
68
+ feeSeat.incrementBy(harden({ Fee: prices.protocolFee }));
76
69
 
70
+ zcf.reallocate(outPoolSeat, inPoolSeat, feeSeat, seat);
77
71
  seat.exit();
78
72
  collateralInPool.updateState();
79
73
  collateralOutPool.updateState();
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  import { natSafeMath } from '@agoric/zoe/src/contractSupport/index.js';
2
4
  import { AmountMath } from '@agoric/ertp';
3
5
  import { BASIS_POINTS } from './constantProduct/defaults.js';
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  import '@agoric/zoe/exported.js';
2
4
 
3
5
  import { AssetKind, makeIssuerKit } from '@agoric/ertp';
@@ -34,7 +36,7 @@ import { publicPrices } from './pool.js';
34
36
  import { makeMakeRemoveLiquidityInvitation } from './removeLiquidity.js';
35
37
  import { makeMakeSwapInvitation } from './swap.js';
36
38
 
37
- import '@agoric/governance/exported.js';
39
+ import '@agoric/governance/src/exported.js';
38
40
 
39
41
  const { quote: q, details: X } = assert;
40
42
 
@@ -56,7 +58,7 @@ const trace = makeTracer('XykAmm', false);
56
58
  * secondaryBrandToLiquidityMint: WeakMapStore<Brand,ZCFMint<'nat'>>,
57
59
  * centralBrand: Brand,
58
60
  * timer: TimerService,
59
- * quoteIssuerKit: IssuerKit<'set'>,
61
+ * quoteIssuerKit: IssuerKit,
60
62
  * params: import('@agoric/governance/src/contractGovernance/typedParamManager').Getters<import('./params.js').AmmParams>,
61
63
  * protocolSeat: ZCFSeat,
62
64
  * }>} AmmPowers
@@ -244,7 +246,7 @@ const start = async (zcf, privateArgs, baggage) => {
244
246
  : undefined;
245
247
 
246
248
  /**
247
- * @param {Brand<'nat'>} secondaryBrand
249
+ * @param {Brand} secondaryBrand
248
250
  * @param {ZCFSeat} reserveLiquidityTokenSeat
249
251
  * @param {Keyword} liquidityKeyword
250
252
  * @returns {Promise<void>} up to caller whether to await or handle rejections
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  import { CONTRACT_ELECTORATE, ParamTypes } from '@agoric/governance';
2
4
 
3
5
  export const POOL_FEE_KEY = 'PoolFee';
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  import '@agoric/zoe/exported.js';
2
4
 
3
5
  import { AmountMath, isNatValue } from '@agoric/ertp';
@@ -7,7 +9,6 @@ import {
7
9
  calcLiqValueToMint,
8
10
  calcSecondaryRequired,
9
11
  calcValueToRemove,
10
- atomicRearrange,
11
12
  } from '@agoric/zoe/src/contractSupport/index.js';
12
13
 
13
14
  import { E } from '@endo/eventual-send';
@@ -85,7 +86,7 @@ export const definePoolKind = (baggage, ammPowers, storageNode, marshaller) => {
85
86
  /**
86
87
  * @param {ZCFMint<'nat'>} liquidityZcfMint
87
88
  * @param {ZCFSeat} poolSeat
88
- * @param {Brand<'nat'>} secondaryBrand
89
+ * @param {Brand} secondaryBrand
89
90
  * @returns {ImmutableState & MutableState}
90
91
  */
91
92
  const poolInit = (liquidityZcfMint, poolSeat, secondaryBrand) => {
@@ -253,21 +254,18 @@ export const definePoolKind = (baggage, ammPowers, storageNode, marshaller) => {
253
254
  ),
254
255
  );
255
256
 
256
- atomicRearrange(
257
- ammPowers.zcf,
258
- harden([
259
- [userSeat, poolSeat, { Liquidity: liquidityIn }],
260
- [
261
- poolSeat,
262
- userSeat,
263
- {
264
- Central: centralTokenAmountOut,
265
- Secondary: tokenKeywordAmountOut,
266
- },
267
- ],
268
- ]),
257
+ poolSeat.incrementBy(
258
+ userSeat.decrementBy(harden({ Liquidity: liquidityIn })),
269
259
  );
270
-
260
+ userSeat.incrementBy(
261
+ poolSeat.decrementBy(
262
+ harden({
263
+ Central: centralTokenAmountOut,
264
+ Secondary: tokenKeywordAmountOut,
265
+ }),
266
+ ),
267
+ );
268
+ ammPowers.zcf.reallocate(userSeat, poolSeat);
271
269
  state.liqTokenSupply -= liquidityValueIn;
272
270
 
273
271
  userSeat.exit();
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  import { AmountMath } from '@agoric/ertp';
2
4
  import {
3
5
  makeNotifierFromSubscriber,
@@ -17,7 +19,7 @@ import { makeOnewayPriceAuthorityKit } from '@agoric/zoe/src/contractSupport/ind
17
19
  * @param {Brand} actualBrandOut
18
20
  * @param {TimerService} timer
19
21
  * @param {Subscriber<import('./pool').NotificationState>} subscriber
20
- * @param {IssuerKit<'set'>} quoteIssuerKit
22
+ * @param {IssuerKit} quoteIssuerKit
21
23
  * @returns {PriceAuthority}
22
24
  */
23
25
  export const makePriceAuthority = (
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  import { assertProposalShape } from '@agoric/zoe/src/contractSupport/index.js';
2
4
 
3
5
  import '@agoric/zoe/exported.js';
@@ -1,8 +1,5 @@
1
- import {
2
- atomicRearrange,
3
- fromOnly,
4
- toOnly,
5
- } from '@agoric/zoe/src/contractSupport/index.js';
1
+ // @ts-check
2
+
6
3
  import { makeFeeRatio } from './constantProduct/calcFees.js';
7
4
  import {
8
5
  pricesForStatedInput,
@@ -22,32 +19,20 @@ export const makeSinglePool = ammPowers => ({
22
19
  const { pool } = context.facets;
23
20
  const { poolSeat } = context.state;
24
21
  const { zcf, protocolSeat } = ammPowers;
25
- const inBrand = prices.swapperGives.brand;
26
-
27
- /** @type {import('@agoric/zoe/src/contractSupport/atomicTransfer.js').TransferPart[]} */
28
- const xfer = harden(
29
- inBrand === getSecondaryBrand(pool)
30
- ? [
31
- fromOnly(poolSeat, { Central: prices.yDecrement }),
32
- toOnly(poolSeat, { Secondary: prices.xIncrement }),
33
- ]
34
- : [
35
- fromOnly(poolSeat, { Secondary: prices.yDecrement }),
36
- toOnly(poolSeat, { Central: prices.xIncrement }),
37
- ],
38
- );
39
-
40
- atomicRearrange(
41
- zcf,
42
- harden([
43
- fromOnly(seat, { In: prices.swapperGives }),
22
+ seat.decrementBy(harden({ In: prices.swapperGives }));
23
+ seat.incrementBy(harden({ Out: prices.swapperGets }));
24
+ protocolSeat.incrementBy(harden({ Fee: prices.protocolFee }));
44
25
 
45
- toOnly(seat, { Out: prices.swapperGets }),
46
- toOnly(protocolSeat, { Fee: prices.protocolFee }),
26
+ const inBrand = prices.swapperGives.brand;
27
+ if (inBrand === getSecondaryBrand(pool)) {
28
+ poolSeat.decrementBy(harden({ Central: prices.yDecrement }));
29
+ poolSeat.incrementBy(harden({ Secondary: prices.xIncrement }));
30
+ } else {
31
+ poolSeat.decrementBy(harden({ Secondary: prices.yDecrement }));
32
+ poolSeat.incrementBy(harden({ Central: prices.xIncrement }));
33
+ }
47
34
 
48
- ...xfer,
49
- ]),
50
- );
35
+ zcf.reallocate(poolSeat, seat, protocolSeat);
51
36
  seat.exit();
52
37
  pool.updateState();
53
38
  return `Swap successfully completed.`;
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  import { assertProposalShape } from '@agoric/zoe/src/contractSupport/index.js';
2
3
 
3
4
  import '@agoric/zoe/exported.js';
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  /**
2
4
  * @typedef {object} VPoolPriceQuote
3
5
  * @property {Amount<'nat'>} amountIn
@@ -69,12 +71,12 @@
69
71
  /**
70
72
  * @typedef {object} XYKPool
71
73
  * @property {() => bigint} getLiquiditySupply
72
- * @property {() => Issuer<'nat'>} getLiquidityIssuer
74
+ * @property {() => Issuer} getLiquidityIssuer
73
75
  * @property {(seat: ZCFSeat) => string} addLiquidity
74
76
  * @property {(seat: ZCFSeat) => string} removeLiquidity
75
77
  * @property {() => ZCFSeat} getPoolSeat
76
- * @property {() => Amount<'nat'>} getSecondaryAmount
77
- * @property {() => Amount<'nat'>} getCentralAmount
78
+ * @property {() => Amount} getSecondaryAmount
79
+ * @property {() => Amount} getCentralAmount
78
80
  * @property {() => Subscriber<Record<string, Amount>>} getSubscriber
79
81
  * @property {() => void} updateState
80
82
  * @property {() => PriceAuthority} getToCentralPriceAuthority
@@ -100,7 +102,7 @@
100
102
  * @typedef {object} XYKAMMPublicFacet
101
103
  * @property {() => Promise<Invitation>} addPoolInvitation
102
104
  * add a new liquidity pool
103
- * @property {(secondaryIssuer: ERef<Issuer>, keyword: Keyword) => Promise<Issuer<'nat'>>} addIssuer
105
+ * @property {(secondaryIssuer: ERef<Issuer>, keyword: Keyword) => Promise<Issuer>} addIssuer
104
106
  * @property {() => Promise<Invitation>} makeSwapInvitation synonym for
105
107
  * makeSwapInInvitation
106
108
  * @property {() => Promise<Invitation>} makeSwapInInvitation make an invitation
@@ -116,24 +118,24 @@
116
118
  * ratio of collateral to Central.
117
119
  * @property {() => Promise<Invitation>} makeRemoveLiquidityInvitation make an
118
120
  * invitation that allows one to remove liquidity from the pool.
119
- * @property {(brand: Brand<'nat'>) => Issuer<'nat'>} getLiquidityIssuer
120
- * @property {(brand: Brand<'nat'>) => bigint} getLiquiditySupply get the current value of
121
+ * @property {(brand: Brand) => Issuer} getLiquidityIssuer
122
+ * @property {(brand: Brand) => bigint} getLiquiditySupply get the current value of
121
123
  * liquidity in the pool for brand held by investors.
122
- * @property {(brand: Brand<'nat'>) => Issuer<'nat'>} getSecondaryIssuer
124
+ * @property {(brand: Brand) => Issuer} getSecondaryIssuer
123
125
  * @property {(amountIn: Amount, amountOut: Amount) => VPoolPriceQuote} getInputPrice
124
126
  * calculate the amount of brandOut that will be returned if the amountIn is
125
127
  * offered using makeSwapInInvitation at the current price.
126
128
  * @property {(amountOut: Amount, amountIn: Amount) => VPoolPriceQuote} getOutputPrice
127
129
  * calculate the amount of brandIn that is required in order to get amountOut
128
130
  * using makeSwapOutInvitation at the current price
129
- * @property {(brand: Brand) => Record<string, Amount<'nat'>>} getPoolAllocation get an
131
+ * @property {(brand: Brand) => Record<string, Amount>} getPoolAllocation get an
130
132
  * AmountKeywordRecord showing the current balances in the pool for brand.
131
- * @property {() => Issuer<'nat'>} getQuoteIssuer - get the Issuer that attests to
133
+ * @property {() => Issuer} getQuoteIssuer - get the Issuer that attests to
132
134
  * the prices in the priceQuotes issued by the PriceAuthorities
133
135
  * @property {(brand: Brand) => {toCentral: PriceAuthority, fromCentral: PriceAuthority}} getPriceAuthorities
134
136
  * get a pair of PriceAuthorities { toCentral, fromCentral } for requesting
135
137
  * Prices and notifications about changing prices.
136
- * @property {() => Brand<'nat'>[]} getAllPoolBrands
138
+ * @property {() => Brand[]} getAllPoolBrands
137
139
  * @property {() => Allocation} getProtocolPoolBalance
138
140
  * @property {() => StoredSubscription<MetricsNotification>} getMetrics
139
141
  * @property {(brand: Brand) => StoredSubscription<PoolMetricsNotification>} getPoolMetrics