@agoric/inter-protocol 0.13.3 → 0.13.4-dev-d32a66a.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 (140) hide show
  1. package/README.md +26 -20
  2. package/bundles/bundle-auctioneer-js-meta.json +722 -0
  3. package/bundles/bundle-auctioneer.js +1 -0
  4. package/bundles/bundle-econCommitteeCharter-js-meta.json +514 -0
  5. package/bundles/bundle-econCommitteeCharter.js +1 -0
  6. package/bundles/bundle-feeDistributor-js-meta.json +458 -0
  7. package/bundles/bundle-feeDistributor.js +1 -1
  8. package/bundles/bundle-fluxAggregatorKit-js-meta.json +674 -0
  9. package/bundles/bundle-fluxAggregatorKit.js +1 -0
  10. package/bundles/bundle-psm-js-meta.json +666 -0
  11. package/bundles/bundle-psm.js +1 -1
  12. package/bundles/bundle-reserve-js-meta.json +662 -0
  13. package/bundles/bundle-reserve.js +1 -1
  14. package/bundles/bundle-scaledPriceAuthority-js-meta.json +542 -0
  15. package/bundles/bundle-scaledPriceAuthority.js +1 -1
  16. package/bundles/bundle-vaultFactory-js-meta.json +786 -0
  17. package/bundles/bundle-vaultFactory.js +1 -1
  18. package/exported.js +0 -2
  19. package/package.json +34 -31
  20. package/scripts/add-collateral-core.js +14 -4
  21. package/scripts/build-bundles.js +9 -2
  22. package/scripts/deploy-contracts.js +1 -4
  23. package/scripts/init-core.js +20 -38
  24. package/scripts/invite-committee-core.js +1 -1
  25. package/scripts/manual-price-feed.js +2 -2
  26. package/scripts/price-feed-core.js +7 -6
  27. package/scripts/start-local-chain.sh +84 -0
  28. package/src/auction/auctionBook.js +755 -0
  29. package/src/auction/auctioneer.js +720 -0
  30. package/src/auction/offerBook.js +221 -0
  31. package/src/auction/params.js +174 -0
  32. package/src/auction/scheduleMath.js +167 -0
  33. package/src/auction/scheduler.js +370 -0
  34. package/src/auction/sortedOffers.js +136 -0
  35. package/src/auction/util.js +55 -0
  36. package/src/clientSupport.js +324 -0
  37. package/src/collectFees.js +8 -14
  38. package/src/contractSupport.js +24 -68
  39. package/src/econCommitteeCharter.js +161 -77
  40. package/src/feeDistributor.js +60 -20
  41. package/src/index.js +2 -0
  42. package/src/interest-math.js +1 -4
  43. package/src/interest.js +20 -13
  44. package/src/price/README.md +57 -0
  45. package/src/price/fluxAggregatorContract.js +190 -0
  46. package/src/price/fluxAggregatorKit.js +375 -0
  47. package/src/price/priceOracleKit.js +127 -0
  48. package/src/price/roundsManager.js +726 -0
  49. package/src/proposals/addAssetToVault.js +89 -94
  50. package/src/proposals/committee-proposal.js +141 -40
  51. package/src/proposals/core-proposal.js +100 -167
  52. package/src/proposals/econ-behaviors.js +320 -564
  53. package/src/proposals/price-feed-proposal.js +175 -78
  54. package/src/proposals/startEconCommittee.js +25 -12
  55. package/src/proposals/startPSM.js +231 -211
  56. package/src/proposals/utils.js +31 -17
  57. package/src/psm/README.md +71 -0
  58. package/src/psm/psm.js +272 -160
  59. package/src/psm/types.js +2 -0
  60. package/src/reserve/assetReserve.js +56 -413
  61. package/src/reserve/assetReserveKit.js +303 -0
  62. package/src/reserve/doc.md +1 -3
  63. package/src/reserve/params.js +2 -5
  64. package/src/typeGuards.js +13 -0
  65. package/src/vaultFactory/Liquidation.md +100 -0
  66. package/src/vaultFactory/burn.js +2 -1
  67. package/src/vaultFactory/liquidation.js +270 -108
  68. package/src/vaultFactory/math.js +95 -0
  69. package/src/vaultFactory/orderedVaultStore.js +0 -1
  70. package/src/vaultFactory/params.js +133 -112
  71. package/src/vaultFactory/prioritizedVaults.js +36 -79
  72. package/src/vaultFactory/storeUtils.js +67 -9
  73. package/src/vaultFactory/type-imports.js +2 -0
  74. package/src/vaultFactory/types.js +22 -26
  75. package/src/vaultFactory/vault.js +772 -709
  76. package/src/vaultFactory/vaultDirector.js +480 -483
  77. package/src/vaultFactory/vaultFactory.js +99 -60
  78. package/src/vaultFactory/vaultHolder.js +121 -95
  79. package/src/vaultFactory/vaultKit.js +39 -31
  80. package/src/vaultFactory/vaultManager.js +1249 -868
  81. package/bundles/bundle-amm-meta.js +0 -618
  82. package/bundles/bundle-amm.js +0 -1
  83. package/bundles/bundle-feeDistributor-meta.js +0 -346
  84. package/bundles/bundle-interchainPool-meta.js +0 -534
  85. package/bundles/bundle-interchainPool.js +0 -1
  86. package/bundles/bundle-liquidateIncrementally-meta.js +0 -442
  87. package/bundles/bundle-liquidateIncrementally.js +0 -1
  88. package/bundles/bundle-liquidateMinimum-meta.js +0 -442
  89. package/bundles/bundle-liquidateMinimum.js +0 -1
  90. package/bundles/bundle-psm-meta.js +0 -538
  91. package/bundles/bundle-psmCharter-meta.js +0 -418
  92. package/bundles/bundle-psmCharter.js +0 -1
  93. package/bundles/bundle-reserve-meta.js +0 -542
  94. package/bundles/bundle-scaledPriceAuthority-meta.js +0 -442
  95. package/bundles/bundle-stakeFactory-meta.js +0 -574
  96. package/bundles/bundle-stakeFactory.js +0 -1
  97. package/bundles/bundle-vaultFactory-meta.js +0 -598
  98. package/scripts/add-initial-liquidity.js +0 -180
  99. package/src/collect.js +0 -13
  100. package/src/interchainPool.js +0 -135
  101. package/src/makeTracer.js +0 -36
  102. package/src/my-lien.js +0 -85
  103. package/src/proposals/demoIssuers.js +0 -685
  104. package/src/proposals/sim-behaviors.js +0 -40
  105. package/src/psm/psmCharter.js +0 -139
  106. package/src/stakeFactory/README.md +0 -62
  107. package/src/stakeFactory/attestation.js +0 -267
  108. package/src/stakeFactory/attestationTool.js +0 -66
  109. package/src/stakeFactory/constants.js +0 -16
  110. package/src/stakeFactory/params.js +0 -31
  111. package/src/stakeFactory/stakeFactory.js +0 -236
  112. package/src/stakeFactory/stakeFactoryKit.js +0 -455
  113. package/src/stakeFactory/stakeFactoryManager.js +0 -296
  114. package/src/stakeFactory/types.js +0 -42
  115. package/src/vaultFactory/liquidateIncrementally.js +0 -350
  116. package/src/vaultFactory/liquidateMinimum.js +0 -100
  117. package/src/vpool-xyk-amm/AttackersGuide.md +0 -89
  118. package/src/vpool-xyk-amm/addLiquidity.js +0 -222
  119. package/src/vpool-xyk-amm/addPool.js +0 -197
  120. package/src/vpool-xyk-amm/constantProduct/AMM-Trade.jpeg +0 -0
  121. package/src/vpool-xyk-amm/constantProduct/README.md +0 -204
  122. package/src/vpool-xyk-amm/constantProduct/calcFees.js +0 -99
  123. package/src/vpool-xyk-amm/constantProduct/calcSwapPrices.js +0 -85
  124. package/src/vpool-xyk-amm/constantProduct/core.js +0 -153
  125. package/src/vpool-xyk-amm/constantProduct/defaults.js +0 -5
  126. package/src/vpool-xyk-amm/constantProduct/getXY.js +0 -52
  127. package/src/vpool-xyk-amm/constantProduct/internal-types.js +0 -116
  128. package/src/vpool-xyk-amm/constantProduct/invariants.js +0 -43
  129. package/src/vpool-xyk-amm/constantProduct/swap.js +0 -272
  130. package/src/vpool-xyk-amm/constantProduct/types.js +0 -32
  131. package/src/vpool-xyk-amm/doublePool.js +0 -194
  132. package/src/vpool-xyk-amm/estimate.js +0 -155
  133. package/src/vpool-xyk-amm/multipoolMarketMaker.js +0 -520
  134. package/src/vpool-xyk-amm/params.js +0 -61
  135. package/src/vpool-xyk-amm/pool.js +0 -396
  136. package/src/vpool-xyk-amm/priceAuthority.js +0 -94
  137. package/src/vpool-xyk-amm/removeLiquidity.js +0 -31
  138. package/src/vpool-xyk-amm/singlePool.js +0 -73
  139. package/src/vpool-xyk-amm/swap.js +0 -69
  140. package/src/vpool-xyk-amm/types.js +0 -154
@@ -1,69 +0,0 @@
1
- // @ts-check
2
- import { assertProposalShape } from '@agoric/zoe/src/contractSupport/index.js';
3
-
4
- import '@agoric/zoe/exported.js';
5
- import { AmountMath } from '@agoric/ertp';
6
-
7
- /**
8
- * @param {ZCF} zcf
9
- * @param {(brandIn: Brand, brandOut: Brand) => VirtualPool} provideVPool
10
- */
11
- export const makeMakeSwapInvitation = (zcf, provideVPool) => {
12
- /**
13
- * trade with a stated amountIn.
14
- *
15
- * @param {ZCFSeat} seat
16
- * @param {{ stopAfter: Amount }} args
17
- */
18
- const swapIn = (seat, args) => {
19
- assertProposalShape(seat, {
20
- give: { In: null },
21
- want: { Out: null },
22
- });
23
- const {
24
- give: { In: amountIn },
25
- want: { Out: amountOut },
26
- } = seat.getProposal();
27
- if (args) {
28
- AmountMath.coerce(amountOut.brand, args.stopAfter);
29
- // TODO check that there are no other keys
30
- }
31
-
32
- const pool = provideVPool(amountIn.brand, amountOut.brand);
33
- let prices;
34
- const stopAfter = args && args.stopAfter;
35
- if (stopAfter) {
36
- AmountMath.coerce(amountOut.brand, stopAfter);
37
- prices = pool.getPriceForOutput(amountIn, stopAfter);
38
- }
39
- if (!prices || !AmountMath.isGTE(prices.swapperGets, stopAfter)) {
40
- // `amountIn` is not enough to sell for stopAfter so just sell it all
41
- prices = pool.getPriceForInput(amountIn, amountOut);
42
- }
43
- assert(amountIn.brand === prices.swapperGives.brand);
44
- return pool.allocateGainsAndLosses(seat, prices);
45
- };
46
-
47
- // trade with a stated amount out.
48
- const swapOut = seat => {
49
- assertProposalShape(seat, {
50
- give: { In: null },
51
- want: { Out: null },
52
- });
53
- const {
54
- give: { In: amountIn },
55
- want: { Out: amountOut },
56
- } = seat.getProposal();
57
- const pool = provideVPool(amountIn.brand, amountOut.brand);
58
- const prices = pool.getPriceForOutput(amountIn, amountOut);
59
- return pool.allocateGainsAndLosses(seat, prices);
60
- };
61
-
62
- const makeSwapInInvitation = () =>
63
- zcf.makeInvitation(swapIn, 'autoswap swapIn');
64
-
65
- const makeSwapOutInvitation = () =>
66
- zcf.makeInvitation(swapOut, 'autoswap swapOut');
67
-
68
- return { makeSwapInInvitation, makeSwapOutInvitation };
69
- };
@@ -1,154 +0,0 @@
1
- // @ts-check
2
-
3
- /**
4
- * @typedef {object} VPoolPriceQuote
5
- * @property {Amount<'nat'>} amountIn
6
- * @property {Amount<'nat'>} amountOut
7
- */
8
-
9
- /**
10
- * @typedef {object} SinglePoolSwapResult
11
- *
12
- * @property {Amount<'nat'>} xIncrement
13
- * @property {Amount<'nat'>} swapperGives
14
- * @property {Amount<'nat'>} yDecrement
15
- * @property {Amount<'nat'>} swapperGets
16
- * @property {Amount<'nat'>} protocolFee
17
- * @property {Amount<'nat'>} poolFee
18
- * @property {Amount<'nat'>} newY
19
- * @property {Amount<'nat'>} newX
20
- */
21
-
22
- /**
23
- * @typedef {import('./multipoolMarketMaker.js').MetricsNotification} MetricsNotification
24
- * @typedef {import('./pool.js').PoolMetricsNotification} PoolMetricsNotification
25
- */
26
-
27
- /**
28
- * @typedef {object} DoublePoolSwapResult
29
- * @property {Amount<'nat'>} swapperGives
30
- * @property {Amount<'nat'>} swapperGets
31
- * @property {Amount<'nat'>} inPoolIncrement
32
- * @property {Amount<'nat'>} inPoolDecrement
33
- * @property {Amount<'nat'>} outPoolIncrement
34
- * @property {Amount<'nat'>} outPoolDecrement
35
- * @property {Amount<'nat'>} protocolFee
36
- */
37
-
38
- /**
39
- * @typedef {Arity extends 'single' ? SinglePoolSwapResult
40
- * : Arity extends 'double' ? DoublePoolSwapResult
41
- * : SinglePoolSwapResult | DoublePoolSwapResult} SwapResult
42
- * @template {'single' | 'double' | unknown} Arity
43
- */
44
-
45
- /**
46
- * @typedef {object} VirtualPool - virtual pool for price quotes and trading
47
- * @property {(seat: ZCFSeat, prices: SwapResult<Arity>) => string} allocateGainsAndLosses
48
- * @property {(amountIn: Amount, amountOut: Amount) => SwapResult<Arity>} getPriceForInput
49
- * @property {(amountIn: Amount, amountOut: Amount) => SwapResult<Arity>} getPriceForOutput
50
- * @template {'single' | 'double' | unknown} [Arity=unknown]
51
- */
52
-
53
- /**
54
- * @callback AddLiquidityActual
55
- * @param {XYKPool} pool
56
- * @param {ZCFSeat} zcfSeat
57
- * @param {Amount<'nat'>} secondaryAmount
58
- * @param {Amount<'nat'>} poolCentralAmount
59
- * @param {ZCFSeat} [feeSeat]
60
- * @returns {string}
61
- */
62
-
63
- /**
64
- * @callback AddLiquidityInternal
65
- * @param {ZCFSeat} zcfSeat
66
- * @param {Amount<'nat'>} secondaryAmount
67
- * @param {Amount<'nat'>} poolCentralAmount
68
- * @param {ZCFSeat} [feeSeat]
69
- */
70
-
71
- /**
72
- * @typedef {object} XYKPool
73
- * @property {() => bigint} getLiquiditySupply
74
- * @property {() => Issuer} getLiquidityIssuer
75
- * @property {(seat: ZCFSeat) => string} addLiquidity
76
- * @property {(seat: ZCFSeat) => string} removeLiquidity
77
- * @property {() => ZCFSeat} getPoolSeat
78
- * @property {() => Amount} getSecondaryAmount
79
- * @property {() => Amount} getCentralAmount
80
- * @property {() => Subscriber<Record<string, Amount>>} getSubscriber
81
- * @property {() => void} updateState
82
- * @property {() => PriceAuthority} getToCentralPriceAuthority
83
- * @property {() => PriceAuthority} getFromCentralPriceAuthority
84
- * @property {() => VirtualPool} getVPool
85
- * @property {() => StoredSubscription<PoolMetricsNotification>} getMetrics
86
- */
87
-
88
- /**
89
- * @typedef {object} PoolFacets
90
- * @property {XYKPool} pool
91
- * @property {{addLiquidityActual: AddLiquidityActual, addLiquidityInternal: AddLiquidityInternal}} helper
92
- * @property {VirtualPool<'single'>} singlePool
93
- */
94
-
95
- /**
96
- * @typedef {object} XYKAMMCreatorFacet
97
- * @property {() => Promise<Invitation>} makeCollectFeesInvitation
98
- * @property {(facet: AssetReservePublicFacet) => void} resolveReserveFacet
99
- */
100
-
101
- /**
102
- * @typedef {object} XYKAMMPublicFacet
103
- * @property {() => Promise<Invitation>} addPoolInvitation
104
- * add a new liquidity pool
105
- * @property {(secondaryIssuer: ERef<Issuer>, keyword: Keyword) => Promise<Issuer>} addIssuer
106
- * @property {() => Promise<Invitation>} makeSwapInvitation synonym for
107
- * makeSwapInInvitation
108
- * @property {() => Promise<Invitation>} makeSwapInInvitation make an invitation
109
- * that allows one to do a swap in which the In amount is specified and the Out
110
- * amount is calculated
111
- * @property {() => Promise<Invitation>} makeSwapOutInvitation make an invitation
112
- * that allows one to do a swap in which the Out amount is specified and the In
113
- * amount is calculated
114
- * @property {() => Promise<Invitation>} makeAddLiquidityInvitation make an
115
- * invitation that allows one to add liquidity to the pool.
116
- * @property {() => Promise<Invitation>} makeAddLiquidityAtRateInvitation make
117
- * an invitation that allows one to add liquidity to the pool at an arbitrary
118
- * ratio of collateral to Central.
119
- * @property {() => Promise<Invitation>} makeRemoveLiquidityInvitation make an
120
- * invitation that allows one to remove liquidity from the pool.
121
- * @property {(brand: Brand) => Issuer} getLiquidityIssuer
122
- * @property {(brand: Brand) => bigint} getLiquiditySupply get the current value of
123
- * liquidity in the pool for brand held by investors.
124
- * @property {(brand: Brand) => Issuer} getSecondaryIssuer
125
- * @property {(amountIn: Amount, amountOut: Amount) => VPoolPriceQuote} getInputPrice
126
- * calculate the amount of brandOut that will be returned if the amountIn is
127
- * offered using makeSwapInInvitation at the current price.
128
- * @property {(amountOut: Amount, amountIn: Amount) => VPoolPriceQuote} getOutputPrice
129
- * calculate the amount of brandIn that is required in order to get amountOut
130
- * using makeSwapOutInvitation at the current price
131
- * @property {(brand: Brand) => Record<string, Amount>} getPoolAllocation get an
132
- * AmountKeywordRecord showing the current balances in the pool for brand.
133
- * @property {() => Issuer} getQuoteIssuer - get the Issuer that attests to
134
- * the prices in the priceQuotes issued by the PriceAuthorities
135
- * @property {(brand: Brand) => {toCentral: PriceAuthority, fromCentral: PriceAuthority}} getPriceAuthorities
136
- * get a pair of PriceAuthorities { toCentral, fromCentral } for requesting
137
- * Prices and notifications about changing prices.
138
- * @property {() => Brand[]} getAllPoolBrands
139
- * @property {() => Allocation} getProtocolPoolBalance
140
- * @property {() => StoredSubscription<MetricsNotification>} getMetrics
141
- * @property {(brand: Brand) => StoredSubscription<PoolMetricsNotification>} getPoolMetrics
142
- * @property {() => bigint} getProtocolFee
143
- * @property {() => bigint} getPoolFee
144
- * @property {() => bigint} getMinInitialPoolLiquidity
145
- */
146
-
147
- /**
148
- * @callback MakeAmmParamManager
149
- * @param {ERef<ZoeService>} zoe
150
- * @param {bigint} poolFeeBP
151
- * @param {bigint} protocolFeeBP
152
- * @param {Invitation} poserInvitation - invitation for the question poser
153
- * @returns {Promise<ParamManagerFull>}
154
- */