@agoric/inter-protocol 0.13.2-dev-70ba9b0.0 → 0.13.2-dev-ed5ee58.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 (70) hide show
  1. package/bundles/bundle-econCommitteeCharter-meta.js +78 -78
  2. package/bundles/bundle-econCommitteeCharter.js +1 -1
  3. package/bundles/bundle-feeDistributor-meta.js +61 -61
  4. package/bundles/bundle-feeDistributor.js +1 -1
  5. package/bundles/bundle-fluxAggregator-meta.js +188 -188
  6. package/bundles/bundle-fluxAggregator.js +1 -1
  7. package/bundles/bundle-psm-meta.js +112 -112
  8. package/bundles/bundle-psm.js +1 -1
  9. package/bundles/bundle-reserve-meta.js +110 -114
  10. package/bundles/bundle-reserve.js +1 -1
  11. package/bundles/bundle-scaledPriceAuthority-meta.js +78 -78
  12. package/bundles/bundle-stakeFactory-meta.js +118 -118
  13. package/bundles/bundle-stakeFactory.js +1 -1
  14. package/bundles/bundle-vaultFactory-meta.js +130 -130
  15. package/bundles/bundle-vaultFactory.js +1 -1
  16. package/exported.js +0 -1
  17. package/package.json +16 -16
  18. package/scripts/deploy-contracts.js +0 -2
  19. package/scripts/init-core.js +0 -16
  20. package/src/feeDistributor.js +1 -1
  21. package/src/proposals/addAssetToVault.js +4 -57
  22. package/src/proposals/committee-proposal.js +3 -6
  23. package/src/proposals/core-proposal.js +1 -73
  24. package/src/proposals/demoIssuers.js +1 -232
  25. package/src/proposals/econ-behaviors.js +10 -193
  26. package/src/proposals/sim-behaviors.js +1 -1
  27. package/src/reserve/assetReserve.js +9 -170
  28. package/src/reserve/params.js +1 -4
  29. package/src/vaultFactory/liquidateIncrementally.js +16 -141
  30. package/src/vaultFactory/liquidateMinimum.js +19 -21
  31. package/src/vaultFactory/params.js +0 -29
  32. package/src/vaultFactory/types.js +0 -6
  33. package/src/vaultFactory/vault.js +1 -3
  34. package/src/vaultFactory/vaultDirector.js +1 -33
  35. package/src/vaultFactory/vaultFactory.js +2 -12
  36. package/src/vaultFactory/vaultManager.js +10 -217
  37. package/bundles/bundle-amm-meta.js +0 -686
  38. package/bundles/bundle-amm.js +0 -1
  39. package/bundles/bundle-interchainPool-meta.js +0 -606
  40. package/bundles/bundle-interchainPool.js +0 -1
  41. package/bundles/bundle-liquidateIncrementally-meta.js +0 -470
  42. package/bundles/bundle-liquidateIncrementally.js +0 -1
  43. package/bundles/bundle-liquidateMinimum-meta.js +0 -470
  44. package/bundles/bundle-liquidateMinimum.js +0 -1
  45. package/scripts/add-initial-liquidity.js +0 -179
  46. package/src/interchainPool.js +0 -134
  47. package/src/vpool-xyk-amm/AttackersGuide.md +0 -89
  48. package/src/vpool-xyk-amm/addLiquidity.js +0 -221
  49. package/src/vpool-xyk-amm/addPool.js +0 -200
  50. package/src/vpool-xyk-amm/constantProduct/AMM-Trade.jpeg +0 -0
  51. package/src/vpool-xyk-amm/constantProduct/README.md +0 -204
  52. package/src/vpool-xyk-amm/constantProduct/calcFees.js +0 -93
  53. package/src/vpool-xyk-amm/constantProduct/calcSwapPrices.js +0 -83
  54. package/src/vpool-xyk-amm/constantProduct/core.js +0 -145
  55. package/src/vpool-xyk-amm/constantProduct/defaults.js +0 -3
  56. package/src/vpool-xyk-amm/constantProduct/getXY.js +0 -48
  57. package/src/vpool-xyk-amm/constantProduct/internal-types.js +0 -114
  58. package/src/vpool-xyk-amm/constantProduct/invariants.js +0 -39
  59. package/src/vpool-xyk-amm/constantProduct/swap.js +0 -270
  60. package/src/vpool-xyk-amm/constantProduct/types.js +0 -30
  61. package/src/vpool-xyk-amm/doublePool.js +0 -200
  62. package/src/vpool-xyk-amm/estimate.js +0 -175
  63. package/src/vpool-xyk-amm/multipoolMarketMaker.js +0 -530
  64. package/src/vpool-xyk-amm/params.js +0 -59
  65. package/src/vpool-xyk-amm/pool.js +0 -398
  66. package/src/vpool-xyk-amm/priceAuthority.js +0 -92
  67. package/src/vpool-xyk-amm/removeLiquidity.js +0 -29
  68. package/src/vpool-xyk-amm/singlePool.js +0 -88
  69. package/src/vpool-xyk-amm/swap.js +0 -68
  70. package/src/vpool-xyk-amm/types.js +0 -152
@@ -1,530 +0,0 @@
1
- import '@agoric/zoe/exported.js';
2
-
3
- import { AssetKind, makeIssuerKit } from '@agoric/ertp';
4
- import { handleParamGovernance, ParamTypes } from '@agoric/governance';
5
- import { makeAtomicProvider } from '@agoric/store/src/stores/store-utils.js';
6
- import {
7
- assertIssuerKeywords,
8
- offerTo,
9
- } from '@agoric/zoe/src/contractSupport/index.js';
10
- import { E } from '@endo/far';
11
- import { Far } from '@endo/marshal';
12
- import { initEmpty } from '@agoric/store';
13
- import {
14
- provideDurableMapStore,
15
- provideDurableWeakMapStore,
16
- provide,
17
- prepareKindMulti,
18
- } from '@agoric/vat-data';
19
- import { makeTracer } from '@agoric/internal';
20
- import { makeMakeCollectFeesInvitation } from '../collectFees.js';
21
- import { makeMetricsPublisherKit } from '../contractSupport.js';
22
- import {
23
- makeMakeAddLiquidityAtRateInvitation,
24
- makeMakeAddLiquidityInvitation,
25
- } from './addLiquidity.js';
26
- import { makeAddIssuer, makeAddPoolInvitation } from './addPool.js';
27
- import { makeDoublePool } from './doublePool.js';
28
- import {
29
- MIN_INITIAL_POOL_LIQUIDITY_KEY,
30
- POOL_FEE_KEY,
31
- PROTOCOL_FEE_KEY,
32
- } from './params.js';
33
- import { publicPrices } from './pool.js';
34
- import { makeMakeRemoveLiquidityInvitation } from './removeLiquidity.js';
35
- import { makeMakeSwapInvitation } from './swap.js';
36
-
37
- import '@agoric/governance/exported.js';
38
-
39
- const { quote: q, details: X } = assert;
40
-
41
- const trace = makeTracer('XykAmm', false);
42
-
43
- /**
44
- * @typedef {object} MetricsNotification
45
- * @property {Brand[]} XYK brands of pools that use an X*Y=K pricing policy
46
- */
47
-
48
- /** @typedef {GovernanceTerms< {MinInitialPoolLiquidity: 'amount'} & {ProtocolFee: 'amount'} & {PoolFee: 'amount'}>} AmmGovernanceParams */
49
-
50
- /** @typedef {{brands:BrandKeywordRecord,timer:import('@agoric/time/src/types').TimerService}} AmmTerms */
51
-
52
- /**
53
- * @typedef {Readonly<{
54
- * zcf: ZCF<AmmTerms>,
55
- * secondaryBrandToPool: WeakMapStore<Brand,PoolFacets>,
56
- * secondaryBrandToLiquidityMint: WeakMapStore<Brand,ZCFMint<'nat'>>,
57
- * centralBrand: Brand<'nat'>,
58
- * timer: import('@agoric/time/src/types').TimerService,
59
- * quoteIssuerKit: IssuerKit<'set'>,
60
- * params: import('@agoric/governance/src/contractGovernance/typedParamManager').Getters<import('./params.js').AmmParams>,
61
- * protocolSeat: ZCFSeat,
62
- * }>} AmmPowers
63
- */
64
-
65
- // All the state at the AMM level is shared lexically. Some functions here have
66
- // to ignore their first parameter since they have other parameters and are
67
- // included in virtual/durable facets.
68
- /** @typedef {{}} MethodContext */
69
-
70
- /** @typedef {import('@agoric/vat-data').Baggage} Baggage */
71
-
72
- /**
73
- * Multipool AMM is a rewrite of Uniswap that supports multiple liquidity pools,
74
- * and direct exchanges across pools. Please see the documentation for more:
75
- * https://agoric.com/documentation/zoe/guide/contracts/multipoolAMM.html It
76
- * also uses a unique approach to charging fees. Each pool grows on every trade,
77
- * and a protocolFee is extracted.
78
- *
79
- * We expect that this contract will have tens to hundreds of issuers. Each
80
- * liquidity pool is between the central token and a secondary token. Secondary
81
- * tokens can be exchanged with each other, but only through the central
82
- * token. For example, if X and Y are two token types and C is the central
83
- * token, a swap giving X and wanting Y would first use the pool (X, C) then the
84
- * pool (Y, C). There are no liquidity pools directly between two secondary
85
- * tokens.
86
- *
87
- * There should only need to be one instance of this contract, so liquidity can
88
- * be shared as much as possible.
89
- *
90
- * When the contract is instantiated, the central token is specified in the
91
- * terms. Separate invitations are available by calling methods on the
92
- * publicFacet for adding and removing liquidity and for making trades. Other
93
- * publicFacet operations support querying prices and the sizes of pools. New
94
- * Pools can be created by first calling addIssuer() and then exercising an
95
- * invitation from addPoolInvitation().
96
- *
97
- * When making trades or requesting prices, the caller must specify either a
98
- * maximum input amount (swapIn, getInputPrice) or a minimum output amount
99
- * (swapOut, getOutPutPrice) or both. For swaps, the required keywords are `In`
100
- * for the trader's `give` amount, and `Out` for the trader's `want` amount.
101
- * getInputPrice and getOutputPrice each take two Amounts. The price functions
102
- * return both amountIn (which may be lower than the original amount) and
103
- * amountOut (which may be higher). When both prices are specified, no swap will
104
- * be made (and no price provided) if both restrictions can't be honored.
105
- *
106
- * When adding and removing liquidity, the keywords are Central, Secondary, and
107
- * Liquidity. adding liquidity has Central and Secondary in the `give` section,
108
- * while removing liquidity has `want` and `give` swapped.
109
- *
110
- * Transactions that don't require an invitation include addPool and the
111
- * queries: getInputPrice, getOutputPrice, getPoolAllocation,
112
- * getLiquidityIssuer, and getLiquiditySupply.
113
- *
114
- * This contract has two parameters (poolFee and protocolFee) that are
115
- * managed by governance. The contract calls `handleParamGovernance()` at
116
- * startup, which allows a contractManager to call for votes that would change
117
- * the parameter values in a transparent way. When correctly set up, customers
118
- * with access to this contract's publicFacet can verify the connectivity, and
119
- * see which Electorate has the ability to vote on changes, and which votes are
120
- * ongoing or have taken place. If not correctly set up, the validation checks
121
- * will fail visibly.
122
- *
123
- * The initial values of the parameters are provided as poolFeeBP and
124
- * protocolFeeBP in terms. The poolFee is charged in {Central} and each collateral, so
125
- * it is provided as a bigint. The protocolFee is always charged in {Fee}, but the
126
- * initial value is specified as a bigint for consistency.
127
- *
128
- * The contract gets the initial values for those parameters from its terms, and
129
- * thereafter can be seen to only use the values provided by the
130
- * getter method returned by the paramManager.
131
- *
132
- * `handleParamGovernance()` adds several methods to the publicFacet of the
133
- * contract, and bundles the privateFacet to ensure that governance
134
- * functionality is only accessible to the contractGovernor.
135
- *
136
- * The creatorFacet has one method (makeCollectFeesInvitation, which returns
137
- * collected fees to the creator). `handleParamGovernance()` adds internal
138
- * methods used by the contractGovernor. The contractGovernor then has access to
139
- * those internal methods, and reveals the original AMM creatorFacet to its own
140
- * creator.
141
- *
142
- * @param {ZCF<AMMTerms>} zcf
143
- * @param {{
144
- * initialPoserInvitation: Invitation,
145
- * storageNode: ERef<StorageNode>,
146
- * marshaller: ERef<Marshaller>,
147
- * }} privateArgs
148
- * @param {Baggage} baggage
149
- */
150
- const start = async (zcf, privateArgs, baggage) => {
151
- /**
152
- * This contract must have a "Central" keyword and issuer in the
153
- * IssuerKeywordRecord.
154
- */
155
- const { brands, timer } = zcf.getTerms();
156
- assertIssuerKeywords(zcf, ['Central']);
157
- const centralBrand = /** @type {Brand<'nat'>} */ (brands.Central);
158
- assert(centralBrand !== undefined, 'centralBrand must be present');
159
-
160
- const [
161
- { augmentVirtualPublicFacet, makeVirtualGovernorFacet, params },
162
- centralDisplayInfo,
163
- ] = await Promise.all([
164
- handleParamGovernance(
165
- zcf,
166
- privateArgs.initialPoserInvitation,
167
- {
168
- [POOL_FEE_KEY]: ParamTypes.NAT,
169
- [PROTOCOL_FEE_KEY]: ParamTypes.NAT,
170
- [MIN_INITIAL_POOL_LIQUIDITY_KEY]: ParamTypes.AMOUNT,
171
- },
172
- privateArgs.storageNode,
173
- privateArgs.marshaller,
174
- ),
175
- E(centralBrand).getDisplayInfo(),
176
- privateArgs.storageNode,
177
- privateArgs.marshaller,
178
- ]);
179
-
180
- assert.equal(
181
- centralDisplayInfo.assetKind,
182
- AssetKind.NAT,
183
- X`Central must be of kind ${q(AssetKind.NAT)}, not ${q(
184
- centralDisplayInfo.assetKind,
185
- )}`,
186
- );
187
-
188
- /** @type {MapStore<Brand,PoolFacets>} */
189
- const secondaryBrandToPool = provideDurableMapStore(
190
- baggage,
191
- 'secondaryBrandToPool',
192
- );
193
- const getPool = brand => {
194
- // TODO: https://github.com/Agoric/agoric-sdk/issues/5776
195
- assert(
196
- secondaryBrandToPool.has(brand),
197
- `"secondaryBrandToPool" not found: ${q(brand)}`,
198
- );
199
- return secondaryBrandToPool.get(brand).pool;
200
- };
201
- const getPoolHelper = brand => secondaryBrandToPool.get(brand).helper;
202
- // XXX a brand can be in secondaryBrandToLiquidityMint and return false for this check
203
- // if it's called between addIssuer and addPool
204
- const isSecondary = secondaryBrandToPool.has;
205
-
206
- // The liquidityBrand has to exist to allow the addPool Offer to specify want
207
- /** @type {WeakMapStore<Brand<'nat'>, ZCFMint<'nat'>>} */
208
- const secondaryBrandToLiquidityMint = provideDurableWeakMapStore(
209
- baggage,
210
- 'secondaryBrandToLiquidityMint',
211
- );
212
- const secondaryBrandToLiquidityMintProvider = makeAtomicProvider(
213
- secondaryBrandToLiquidityMint,
214
- );
215
-
216
- const quoteIssuerKit = provide(baggage, 'quoteIssuerKit', () =>
217
- makeIssuerKit('Quote', AssetKind.SET),
218
- );
219
-
220
- const { metricsPublication, metricsSubscription } = makeMetricsPublisherKit(
221
- privateArgs.storageNode,
222
- privateArgs.marshaller,
223
- );
224
- const updateMetrics = () => {
225
- metricsPublication.updateState(
226
- harden({ XYK: Array.from(secondaryBrandToPool.keys()) }),
227
- );
228
- };
229
- updateMetrics();
230
-
231
- // For now, this seat collects protocol fees. It needs to be connected to
232
- // something that will extract the fees.
233
- const protocolSeat = provide(
234
- baggage,
235
- 'protocolSeat',
236
- () => zcf.makeEmptySeatKit().zcfSeat,
237
- );
238
-
239
- /** @type {AssetReservePublicFacet | undefined} */
240
- let reserveFacet = baggage.has('reserveFacet')
241
- ? baggage.get('reserveFacet')
242
- : undefined;
243
-
244
- /**
245
- * @param {Brand<'nat'>} secondaryBrand
246
- * @param {ZCFSeat} reserveLiquidityTokenSeat
247
- * @param {Keyword} liquidityKeyword
248
- * @returns {Promise<void>} up to caller whether to await or handle rejections
249
- */
250
- const handlePoolAdded = async (
251
- secondaryBrand,
252
- reserveLiquidityTokenSeat,
253
- liquidityKeyword,
254
- ) => {
255
- trace('handlePoolAdded', { secondaryBrand, liquidityKeyword });
256
- updateMetrics();
257
-
258
- assert(reserveFacet, 'Missing reserveFacet');
259
- assert(reserveLiquidityTokenSeat, 'Missing reserveLiquidityTokenSeat');
260
-
261
- const secondaryIssuer = await zcf.getIssuerForBrand(secondaryBrand);
262
- trace('ensuring reserve has the liquidity issuer', {
263
- secondaryBrand,
264
- secondaryIssuer,
265
- });
266
- await E(reserveFacet).addLiquidityIssuer(secondaryIssuer);
267
-
268
- trace(
269
- `move ${liquidityKeyword} to the reserve`,
270
- reserveLiquidityTokenSeat.getCurrentAllocation(),
271
- );
272
- const addCollateral = await E(reserveFacet).makeAddCollateralInvitation();
273
- const proposal = harden({
274
- give: {
275
- Collateral:
276
- reserveLiquidityTokenSeat.getCurrentAllocation()[liquidityKeyword],
277
- },
278
- });
279
- const { deposited, userSeatPromise } = await offerTo(
280
- zcf,
281
- addCollateral,
282
- harden({ [liquidityKeyword]: 'Collateral' }),
283
- proposal,
284
- reserveLiquidityTokenSeat,
285
- );
286
- const deposits = await deposited;
287
- trace('handlePoolAdded deposited', deposits);
288
- await E(userSeatPromise).getOfferResult();
289
- reserveLiquidityTokenSeat.exit();
290
- trace('handlePoolAdded done');
291
- };
292
-
293
- /**
294
- * @param {MethodContext} _context
295
- * @param {Brand<'nat'>} brand
296
- */
297
- const getLiquidityIssuer = (_context, brand) =>
298
- secondaryBrandToLiquidityMint.get(brand).getIssuerRecord().issuer;
299
- /**
300
- * @param {MethodContext} _context
301
- * @param {Brand} brand
302
- */
303
- const getLiquiditySupply = (_context, brand) =>
304
- getPool(brand).getLiquiditySupply();
305
-
306
- /**
307
- * @param {MethodContext} _context
308
- * @param {Brand<'nat'>} brand
309
- */
310
- const getSecondaryIssuer = (_context, brand) => {
311
- assert(
312
- secondaryBrandToLiquidityMint.has(brand),
313
- 'Brand not a secondary of the AMM',
314
- );
315
- return zcf.getIssuerForBrand(brand);
316
- };
317
- const poolStorageNode = await (privateArgs.storageNode &&
318
- E(privateArgs.storageNode).makeChildNode(
319
- // NB: the set of pools grows monotonically
320
- `pool${secondaryBrandToPool.getSize()}`,
321
- ));
322
-
323
- // shared AMM state that will be lexically accessible to all pools
324
- /** @type {AmmPowers} */
325
- const ammPowers = harden({
326
- zcf,
327
- secondaryBrandToPool,
328
- secondaryBrandToLiquidityMint,
329
- centralBrand,
330
- timer,
331
- quoteIssuerKit,
332
- params,
333
- protocolSeat,
334
- });
335
- const addPoolInvitation = makeAddPoolInvitation(
336
- baggage,
337
- ammPowers,
338
- handlePoolAdded,
339
- poolStorageNode,
340
- privateArgs.marshaller,
341
- );
342
- const addIssuer = makeAddIssuer(
343
- zcf,
344
- isSecondary,
345
- secondaryBrandToLiquidityMintProvider,
346
- () => {
347
- assert(reserveFacet, 'Must first resolveReserveFacet');
348
- return secondaryBrand =>
349
- E(
350
- /** @type {AssetReservePublicFacet} */ (reserveFacet),
351
- ).addIssuerFromAmm(secondaryBrand);
352
- },
353
- );
354
-
355
- /**
356
- * @param {unknown} _context
357
- * @param {Brand} brand
358
- */
359
- const getPoolAllocation = (_context, brand) =>
360
- getPool(brand).getPoolSeat().getCurrentAllocation();
361
-
362
- /**
363
- * @param {*} _context xxx
364
- * @param {Brand} brand
365
- */
366
- const getPriceAuthorities = (_context, brand) => {
367
- const pool = getPool(brand);
368
- return {
369
- toCentral: pool.getToCentralPriceAuthority(),
370
- fromCentral: pool.getFromCentralPriceAuthority(),
371
- };
372
- };
373
-
374
- /**
375
- * @param {MethodContext} _context
376
- * @param {Brand} brand
377
- */
378
- const getPoolMetrics = (_context, brand) => getPool(brand).getMetrics();
379
-
380
- /**
381
- * @param {Brand} brandIn
382
- * @param {Brand} [brandOut]
383
- * @returns {VirtualPool}
384
- */
385
- const provideVPool = (brandIn, brandOut) => {
386
- if (!brandOut) {
387
- return getPool(brandIn).getVPool();
388
- }
389
-
390
- if (isSecondary(brandIn) && isSecondary(brandOut)) {
391
- return makeDoublePool(
392
- zcf,
393
- getPool(brandIn),
394
- getPool(brandOut),
395
- params.getProtocolFee,
396
- params.getPoolFee,
397
- protocolSeat,
398
- );
399
- }
400
-
401
- const pool = isSecondary(brandOut) ? getPool(brandOut) : getPool(brandIn);
402
- return pool.getVPool();
403
- };
404
-
405
- /**
406
- * @param {*} _context xxx
407
- * @param {Amount<'nat'>} amountIn
408
- * @param {Amount<'nat'>} amountOut
409
- */
410
- const getInputPrice = (_context, amountIn, amountOut) => {
411
- const pool = provideVPool(amountIn.brand, amountOut.brand);
412
- return publicPrices(pool.getPriceForInput(amountIn, amountOut));
413
- };
414
-
415
- /**
416
- * @param {*} _context xxx
417
- * @param {Amount<'nat'>} amountIn
418
- * @param {Amount<'nat'>} amountOut
419
- */
420
- const getOutputPrice = (_context, amountIn, amountOut) => {
421
- const pool = provideVPool(amountIn.brand, amountOut.brand);
422
- return publicPrices(pool.getPriceForOutput(amountIn, amountOut));
423
- };
424
-
425
- const { makeSwapInInvitation, makeSwapOutInvitation } =
426
- makeMakeSwapInvitation(zcf, provideVPool);
427
- const makeAddLiquidityInvitation = makeMakeAddLiquidityInvitation(
428
- zcf,
429
- getPool,
430
- );
431
- const makeAddLiquidityAtRateInvitation = makeMakeAddLiquidityAtRateInvitation(
432
- zcf,
433
- getPool,
434
- provideVPool,
435
- protocolSeat,
436
- getPoolHelper,
437
- );
438
-
439
- const makeRemoveLiquidityInvitation = makeMakeRemoveLiquidityInvitation(
440
- zcf,
441
- getPool,
442
- );
443
-
444
- const { makeCollectFeesInvitation } = makeMakeCollectFeesInvitation(
445
- zcf,
446
- protocolSeat,
447
- centralBrand,
448
- 'Fee',
449
- );
450
-
451
- const publicFacet = augmentVirtualPublicFacet(
452
- Far('AMM public facet', {
453
- addPoolInvitation,
454
- addIssuer,
455
- getPoolAllocation,
456
- getLiquidityIssuer,
457
- getLiquiditySupply,
458
- getInputPrice,
459
- getOutputPrice,
460
- getSecondaryIssuer,
461
- makeSwapInvitation: makeSwapInInvitation,
462
- makeSwapInInvitation,
463
- makeSwapOutInvitation,
464
- makeAddLiquidityInvitation,
465
- makeAddLiquidityAtRateInvitation,
466
- makeRemoveLiquidityInvitation,
467
- getQuoteIssuer: () => quoteIssuerKit.issuer,
468
- getPriceAuthorities,
469
- getAllPoolBrands: () =>
470
- Object.values(zcf.getTerms().brands).filter(isSecondary),
471
- getProtocolPoolBalance: () => protocolSeat.getCurrentAllocation(),
472
- getMetrics: () => metricsSubscription,
473
- getPoolMetrics,
474
- ...params,
475
- }),
476
- );
477
-
478
- const { governorFacet, limitedCreatorFacet } = makeVirtualGovernorFacet(
479
- harden({
480
- makeCollectFeesInvitation,
481
- /**
482
- * Must be called before adding pools. Not provided at contract start time
483
- * due to cyclic dependency.
484
- *
485
- * @param {MethodContext} _context
486
- * @param {AssetReservePublicFacet} facet
487
- */
488
- resolveReserveFacet: (_context, facet) => {
489
- assert(!reserveFacet, 'reserveFacet already resolved');
490
- reserveFacet = facet;
491
- baggage.init('reserveFacet', facet);
492
- },
493
- }),
494
- );
495
-
496
- const makeAMM = prepareKindMulti(baggage, 'AMM', initEmpty, {
497
- publicFacet,
498
- creatorFacet: governorFacet,
499
- limitedCreatorFacet,
500
- });
501
- const { creatorFacet, publicFacet: pFacet } = makeAMM();
502
- return { creatorFacet, publicFacet: pFacet };
503
- };
504
-
505
- harden(start);
506
- export { start };
507
-
508
- /**
509
- * @typedef {object} AMMParamGetters
510
- * @property {() => NatValue} getPoolFee
511
- * @property {() => NatValue} getProtocolFee
512
- * @property {() => Amount<'nat'>} getMinInitialPoolLiquidity
513
- * @property {() => Amount} getElectorate
514
- */
515
-
516
- /**
517
- * @typedef { bigint } BasisPoints -- hundredths of a percent
518
- *
519
- * @typedef {GovernanceTerms<{
520
- * PoolFee: 'nat',
521
- * ProtocolFee: 'nat',
522
- * MinInitialPoolLiquidity: 'amount',
523
- * }> & {
524
- * brands: { Central: Brand },
525
- * issuers: {},
526
- * timer: import('@agoric/time/src/types').TimerService,
527
- * poolFeeBP: BasisPoints, // portion of the fees that go into the pool
528
- * protocolFeeBP: BasisPoints, // portion of the fees that are shared with validators
529
- * }} AMMTerms
530
- */
@@ -1,59 +0,0 @@
1
- import { CONTRACT_ELECTORATE, ParamTypes } from '@agoric/governance';
2
-
3
- export const POOL_FEE_KEY = 'PoolFee';
4
- export const PROTOCOL_FEE_KEY = 'ProtocolFee';
5
- export const MIN_INITIAL_POOL_LIQUIDITY_KEY = 'MinInitialPoolLiquidity';
6
-
7
- const DEFAULT_POOL_FEE_BP = 24n;
8
- const DEFAULT_PROTOCOL_FEE_BP = 6n;
9
-
10
- /**
11
- * @param {Invitation} electorateInvitation - invitation for the question poser
12
- * @param {bigint} protocolFeeBP
13
- * @param {bigint} poolFeeBP
14
- * @param {Amount<'nat'>} minInitialLiquidity
15
- */
16
- const makeAmmParams = (
17
- electorateInvitation,
18
- protocolFeeBP,
19
- poolFeeBP,
20
- minInitialLiquidity,
21
- ) => {
22
- return harden({
23
- [POOL_FEE_KEY]: { type: ParamTypes.NAT, value: poolFeeBP },
24
- [PROTOCOL_FEE_KEY]: { type: ParamTypes.NAT, value: protocolFeeBP },
25
- [MIN_INITIAL_POOL_LIQUIDITY_KEY]: {
26
- type: ParamTypes.AMOUNT,
27
- value: minInitialLiquidity,
28
- },
29
- [CONTRACT_ELECTORATE]: {
30
- type: ParamTypes.INVITATION,
31
- value: electorateInvitation,
32
- },
33
- });
34
- };
35
-
36
- /** @typedef {import('@agoric/governance/src/contractGovernance/typedParamManager').ParamTypesMapFromRecord<ReturnType<typeof makeAmmParams>>} AmmParams */
37
-
38
- const makeAmmTerms = (
39
- timer,
40
- poserInvitationAmount,
41
- minInitialLiquidity,
42
- protocolFeeBP = DEFAULT_PROTOCOL_FEE_BP,
43
- poolFeeBP = DEFAULT_POOL_FEE_BP,
44
- ) => ({
45
- timer,
46
- poolFeeBP,
47
- protocolFeeBP,
48
- governedParams: makeAmmParams(
49
- poserInvitationAmount,
50
- protocolFeeBP,
51
- poolFeeBP,
52
- minInitialLiquidity,
53
- ),
54
- });
55
-
56
- harden(makeAmmTerms);
57
- harden(makeAmmParams);
58
-
59
- export { makeAmmTerms, makeAmmParams };