@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
package/exported.js CHANGED
@@ -1,4 +1,3 @@
1
1
  import './src/stakeFactory/types.js';
2
2
  import './src/psm/types.js';
3
3
  import './src/vaultFactory/types.js';
4
- import './src/vpool-xyk-amm/types.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/inter-protocol",
3
- "version": "0.13.2-dev-70ba9b0.0+70ba9b0",
3
+ "version": "0.13.2-dev-ed5ee58.0+ed5ee58",
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-70ba9b0.0+70ba9b0",
33
- "@agoric/ertp": "0.15.4-dev-70ba9b0.0+70ba9b0",
34
- "@agoric/governance": "0.9.2-dev-70ba9b0.0+70ba9b0",
35
- "@agoric/internal": "0.2.2-dev-70ba9b0.0+70ba9b0",
36
- "@agoric/notifier": "0.5.2-dev-70ba9b0.0+70ba9b0",
37
- "@agoric/store": "0.8.4-dev-70ba9b0.0+70ba9b0",
38
- "@agoric/time": "0.2.2-dev-70ba9b0.0+70ba9b0",
39
- "@agoric/vat-data": "0.4.4-dev-70ba9b0.0+70ba9b0",
40
- "@agoric/vats": "0.13.1-dev-70ba9b0.0+70ba9b0",
41
- "@agoric/zoe": "0.25.4-dev-70ba9b0.0+70ba9b0",
32
+ "@agoric/assert": "0.5.2-dev-ed5ee58.0+ed5ee58",
33
+ "@agoric/ertp": "0.15.4-dev-ed5ee58.0+ed5ee58",
34
+ "@agoric/governance": "0.9.2-dev-ed5ee58.0+ed5ee58",
35
+ "@agoric/internal": "0.2.2-dev-ed5ee58.0+ed5ee58",
36
+ "@agoric/notifier": "0.5.2-dev-ed5ee58.0+ed5ee58",
37
+ "@agoric/store": "0.8.4-dev-ed5ee58.0+ed5ee58",
38
+ "@agoric/time": "0.2.2-dev-ed5ee58.0+ed5ee58",
39
+ "@agoric/vat-data": "0.4.4-dev-ed5ee58.0+ed5ee58",
40
+ "@agoric/vats": "0.13.1-dev-ed5ee58.0+ed5ee58",
41
+ "@agoric/zoe": "0.25.4-dev-ed5ee58.0+ed5ee58",
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-70ba9b0.0+70ba9b0",
50
- "@agoric/smart-wallet": "0.4.3-dev-70ba9b0.0+70ba9b0",
51
- "@agoric/swingset-liveslots": "0.9.1-dev-70ba9b0.0+70ba9b0",
52
- "@agoric/swingset-vat": "0.30.3-dev-70ba9b0.0+70ba9b0",
49
+ "@agoric/deploy-script-support": "0.9.5-dev-ed5ee58.0+ed5ee58",
50
+ "@agoric/smart-wallet": "0.4.3-dev-ed5ee58.0+ed5ee58",
51
+ "@agoric/swingset-liveslots": "0.9.1-dev-ed5ee58.0+ed5ee58",
52
+ "@agoric/swingset-vat": "0.30.3-dev-ed5ee58.0+ed5ee58",
53
53
  "@endo/bundle-source": "^2.4.2",
54
54
  "@endo/init": "^0.5.52",
55
55
  "@endo/promise-kit": "^0.2.52",
@@ -78,5 +78,5 @@
78
78
  "publishConfig": {
79
79
  "access": "public"
80
80
  },
81
- "gitHead": "70ba9b0ce1bf20c815e3d63ac98cc7086a813984"
81
+ "gitHead": "ed5ee58a276fce3c55f19e4f6f662ed579896c2c"
82
82
  }
@@ -10,9 +10,7 @@ const contractRefs = [
10
10
  '../../governance/bundles/bundle-committee.js',
11
11
  '../../governance/bundles/bundle-binaryVoteCounter.js',
12
12
  '../bundles/bundle-stakeFactory.js',
13
- '../bundles/bundle-amm.js',
14
13
  '../bundles/bundle-vaultFactory.js',
15
- '../bundles/bundle-liquidateMinimum.js',
16
14
  '../bundles/bundle-reserve.js',
17
15
  '../bundles/bundle-psm.js',
18
16
  '../../vats/bundles/bundle-mintHolder.js',
@@ -36,14 +36,6 @@ const installKeyGroups = {
36
36
  ],
37
37
  },
38
38
  main: {
39
- amm: [
40
- '../src/vpool-xyk-amm/multipoolMarketMaker.js',
41
- '../bundles/bundle-amm.js',
42
- ],
43
- interchainPool: [
44
- '../src/interchainPool.js',
45
- '../bundles/bundle-interchainPool.js',
46
- ],
47
39
  vaultFactory: [
48
40
  '../src/vaultFactory/vaultFactory.js',
49
41
  '../bundles/bundle-vaultFactory.js',
@@ -52,14 +44,6 @@ const installKeyGroups = {
52
44
  '../src/feeDistributor.js',
53
45
  '../bundles/bundle-feeDistributor.js',
54
46
  ],
55
- liquidateMinimum: [
56
- '../src/vaultFactory/liquidateMinimum.js',
57
- '../bundles/bundle-liquidateMinimum.js',
58
- ],
59
- liquidate: [
60
- '../src/vaultFactory/liquidateIncrementally.js',
61
- '../bundles/bundle-liquidateIncrementally.js',
62
- ],
63
47
  reserve: ['../src/reserve/assetReserve.js', '../bundles/bundle-reserve.js'],
64
48
  },
65
49
  };
@@ -41,7 +41,7 @@ export const customTermsShape = harden({
41
41
  */
42
42
 
43
43
  /**
44
- * wrapper to take the vaultFactory or AMM's creatorFacet, and make a call that
44
+ * wrapper to take the a creatorFacet (e.g. vaultFactory) and make a call that
45
45
  * will request an invitation and return a promise for a payment.
46
46
  *
47
47
  * @param {ERef<ZoeService>} zoe
@@ -44,44 +44,6 @@ export const publishInterchainAssetFromBoardId = async (
44
44
  ]);
45
45
  };
46
46
 
47
- const addPool = async (
48
- zoe,
49
- amm,
50
- issuer,
51
- keyword,
52
- brand,
53
- runBrand,
54
- runIssuer,
55
- ) => {
56
- const ammPub = E(zoe).getPublicFacet(amm);
57
- const [addPoolInvitation] = await Promise.all([
58
- E(ammPub).addPoolInvitation(),
59
- E(ammPub).addIssuer(issuer, keyword),
60
- ]);
61
- const proposal = harden({
62
- give: {
63
- Secondary: AmountMath.makeEmpty(brand),
64
- Central: AmountMath.makeEmpty(runBrand),
65
- },
66
- });
67
- const centralPurse = E(runIssuer).makeEmptyPurse();
68
- const secondaryPurse = E(issuer).makeEmptyPurse();
69
- const [emptyCentral, emptySecondary] = await Promise.all([
70
- E(centralPurse).withdraw(proposal.give.Central),
71
- E(secondaryPurse).withdraw(proposal.give.Secondary),
72
- ]);
73
- const payments = harden({
74
- Central: emptyCentral,
75
- Secondary: emptySecondary,
76
- });
77
- const addLiquiditySeat = await E(zoe).offer(
78
- addPoolInvitation,
79
- proposal,
80
- payments,
81
- );
82
- await E(addLiquiditySeat).getOfferResult();
83
- };
84
-
85
47
  /**
86
48
  * @param {EconomyBootstrapPowers} powers
87
49
  * @param {object} config
@@ -90,20 +52,11 @@ const addPool = async (
90
52
  */
91
53
  export const publishInterchainAssetFromBank = async (
92
54
  {
93
- consume: { zoe, bankManager, agoricNamesAdmin, bankMints },
55
+ consume: { zoe, bankManager, agoricNamesAdmin, bankMints, reserveKit },
94
56
  produce: { bankMints: produceBankMints },
95
57
  installation: {
96
58
  consume: { mintHolder },
97
59
  },
98
- instance: {
99
- consume: { amm },
100
- },
101
- issuer: {
102
- consume: { [Stable.symbol]: runIssuer },
103
- },
104
- brand: {
105
- consume: { [Stable.symbol]: stableBrandP },
106
- },
107
60
  },
108
61
  { options: { interchainAssetOptions } },
109
62
  ) => {
@@ -129,14 +82,10 @@ export const publishInterchainAssetFromBank = async (
129
82
  E(zoe).startInstance(mintHolder, {}, terms),
130
83
  );
131
84
 
132
- const [issuer, brand, runBrand] = await Promise.all([
133
- issuerP,
134
- E(issuerP).getBrand(),
135
- stableBrandP,
136
- ]);
85
+ const [issuer, brand] = await Promise.all([issuerP, E(issuerP).getBrand()]);
137
86
  const kit = { mint: mintP, issuer, brand };
138
87
 
139
- await addPool(zoe, amm, issuer, keyword, brand, runBrand, runIssuer);
88
+ await E(E.get(reserveKit).creatorFacet).addIssuer(issuer, keyword);
140
89
 
141
90
  // Create the mint list if it doesn't exist and wasn't already rejected.
142
91
  produceBankMints.resolve([]);
@@ -318,14 +267,12 @@ export const getManifestForAddAssetToVault = (
318
267
  bankManager: true,
319
268
  agoricNamesAdmin: true,
320
269
  bankMints: true,
270
+ reserveKit: true,
321
271
  },
322
272
  produce: { bankMints: true },
323
273
  installation: {
324
274
  consume: { mintHolder: true },
325
275
  },
326
- instance: { consume: { amm: 'amm' } },
327
- issuer: { consume: { [Stable.symbol]: 'zoe' } },
328
- brand: { consume: { [Stable.symbol]: 'zoe' } },
329
276
  },
330
277
  }),
331
278
  [registerScaledPriceAuthority.name]: {
@@ -75,9 +75,9 @@ harden(startEconCharter);
75
75
  * @param {import('./econ-behaviors').EconomyBootstrapPowers} powers
76
76
  */
77
77
  export const addGovernorsToEconCharter = async ({
78
- consume: { reserveKit, ammKit, vaultFactoryKit, econCharterKit },
78
+ consume: { reserveKit, vaultFactoryKit, econCharterKit },
79
79
  instance: {
80
- consume: { amm, reserve, VaultFactory },
80
+ consume: { reserve, VaultFactory },
81
81
  },
82
82
  }) => {
83
83
  const { creatorFacet } = E.get(econCharterKit);
@@ -85,7 +85,6 @@ export const addGovernorsToEconCharter = async ({
85
85
  // Introduce charter to governed creator facets.
86
86
  await Promise.all(
87
87
  [
88
- { instanceP: amm, facetP: E.get(ammKit).governorCreatorFacet },
89
88
  { instanceP: reserve, facetP: E.get(reserveKit).governorCreatorFacet },
90
89
  {
91
90
  instanceP: VaultFactory,
@@ -148,7 +147,6 @@ export const getManifestForInviteCommittee = async (
148
147
  [addGovernorsToEconCharter.name]: {
149
148
  consume: {
150
149
  reserveGovernorCreatorFacet: t,
151
- ammGovernorCreatorFacet: t,
152
150
  vaultFactoryGovernorCreator: t,
153
151
  econCharterKit: t,
154
152
  zoe: t,
@@ -156,14 +154,13 @@ export const getManifestForInviteCommittee = async (
156
154
  namesByAddressAdmin: t,
157
155
  economicCommitteeCreatorFacet: t,
158
156
  reserveKit: t,
159
- ammKit: t,
160
157
  vaultFactoryKit: t,
161
158
  },
162
159
  installation: {
163
160
  consume: { binaryVoteCounter: t },
164
161
  },
165
162
  instance: {
166
- consume: { amm: t, reserve: t, VaultFactory: t },
163
+ consume: { reserve: t, VaultFactory: t },
167
164
  },
168
165
  },
169
166
  [inviteToEconCharter.name]: {
@@ -1,7 +1,6 @@
1
1
  import { Stable } from '@agoric/vats/src/tokens.js';
2
2
  import * as econBehaviors from './econ-behaviors.js';
3
3
  import { ECON_COMMITTEE_MANIFEST } from './startEconCommittee.js';
4
- import * as simBehaviors from './sim-behaviors.js';
5
4
 
6
5
  export * from './econ-behaviors.js';
7
6
  export * from './sim-behaviors.js';
@@ -13,40 +12,6 @@ export * from './startEconCommittee.js'; // eslint-disable-line import/export
13
12
  /** @type {import('@agoric/vats/src/core/manifest.js').BootstrapManifest} */
14
13
  const SHARED_MAIN_MANIFEST = harden({
15
14
  /** @type {import('@agoric/vats/src/core/manifest.js').BootstrapManifestPermit} */
16
- [econBehaviors.setupAmm.name]: {
17
- consume: {
18
- board: 'board',
19
- chainStorage: true,
20
- chainTimerService: 'timer',
21
- zoe: 'zoe',
22
- economicCommitteeCreatorFacet: 'economicCommittee',
23
- },
24
- produce: { ammKit: 'amm' },
25
- issuer: { consume: { [Stable.symbol]: 'zoe' } },
26
- brand: { consume: { [Stable.symbol]: 'zoe' } },
27
- installation: {
28
- consume: { contractGovernor: 'zoe', amm: 'zoe' },
29
- },
30
- instance: {
31
- produce: { ammGovernor: 'ammGovernor' },
32
- },
33
- },
34
- [econBehaviors.startInterchainPool.name]: {
35
- consume: { bankManager: 'bank', zoe: 'zoe', agoricNamesAdmin: true },
36
- installation: {
37
- consume: { interchainPool: 'zoe' },
38
- },
39
- brand: {
40
- consume: { [Stable.symbol]: 'zoe' },
41
- },
42
- issuer: {
43
- consume: { [Stable.symbol]: 'zoe' },
44
- },
45
- instance: {
46
- consume: { amm: 'amm' },
47
- produce: { interchainPool: 'interchainPool' },
48
- },
49
- },
50
15
  [econBehaviors.startVaultFactory.name]: {
51
16
  consume: {
52
17
  board: 'board',
@@ -65,12 +30,10 @@ const SHARED_MAIN_MANIFEST = harden({
65
30
  consume: {
66
31
  contractGovernor: 'zoe',
67
32
  VaultFactory: 'zoe',
68
- liquidate: 'zoe',
69
33
  },
70
34
  },
71
35
  instance: {
72
36
  consume: {
73
- amm: 'amm',
74
37
  reserve: 'reserve',
75
38
  },
76
39
  produce: {
@@ -90,7 +53,6 @@ const SHARED_MAIN_MANIFEST = harden({
90
53
 
91
54
  [econBehaviors.setupReserve.name]: {
92
55
  consume: {
93
- ammKit: 'amm',
94
56
  board: 'board',
95
57
  chainStorage: true,
96
58
  feeMintAccess: 'zoe',
@@ -105,9 +67,7 @@ const SHARED_MAIN_MANIFEST = harden({
105
67
  consume: { contractGovernor: 'zoe', reserve: 'zoe' },
106
68
  },
107
69
  instance: {
108
- consume: { amm: 'amm' },
109
70
  produce: {
110
- amm: 'amm',
111
71
  reserve: 'reserve',
112
72
  reserveGovernor: 'ReserveGovernor',
113
73
  },
@@ -122,7 +82,6 @@ const REWARD_MANIFEST = harden({
122
82
  bankManager: true,
123
83
  vaultFactoryKit: true,
124
84
  periodicFeeCollectors: true,
125
- ammKit: true,
126
85
  stakeFactoryKit: true,
127
86
  reserveKit: true,
128
87
  zoe: true,
@@ -174,35 +133,7 @@ const STAKE_FACTORY_MANIFEST = harden({
174
133
  },
175
134
  });
176
135
 
177
- export const SIM_CHAIN_MANIFEST = harden({
178
- [simBehaviors.fundAMM.name]: {
179
- consume: {
180
- centralSupplyBundle: true,
181
- mintHolderBundle: true,
182
- chainTimerService: 'timer',
183
- bldIssuerKit: true,
184
- feeMintAccess: true,
185
- loadVat: true,
186
- mints: 'mints',
187
- priceAuthorityVat: 'priceAuthority',
188
- priceAuthorityAdmin: 'priceAuthority',
189
- vaultFactoryKit: 'VaultFactory',
190
- zoe: true,
191
- },
192
- installation: {
193
- consume: { centralSupply: 'zoe' },
194
- },
195
- issuer: {
196
- consume: { [Stable.symbol]: 'zoe' },
197
- },
198
- brand: {
199
- consume: { [Stable.symbol]: 'zoe' },
200
- },
201
- instance: {
202
- consume: { amm: 'amm' },
203
- },
204
- },
205
- });
136
+ export const SIM_CHAIN_MANIFEST = harden({});
206
137
 
207
138
  export const getManifestForEconCommittee = (
208
139
  { restoreRef },
@@ -233,12 +164,9 @@ export const getManifestForMain = (
233
164
  return {
234
165
  manifest: SHARED_MAIN_MANIFEST,
235
166
  installations: {
236
- amm: restoreRef(installKeys.amm),
237
167
  VaultFactory: restoreRef(installKeys.vaultFactory),
238
168
  feeDistributor: restoreRef(installKeys.feeDistributor),
239
- liquidate: restoreRef(installKeys.liquidate),
240
169
  reserve: restoreRef(installKeys.reserve),
241
- interchainPool: restoreRef(installKeys.interchainPool),
242
170
  },
243
171
  options: {
244
172
  vaultFactoryControllerAddress,
@@ -1,6 +1,5 @@
1
1
  /* eslint-disable @jessie.js/no-nested-await -- demo file */
2
2
  import { AmountMath, AssetKind } from '@agoric/ertp';
3
- import { allValues, objectMap } from '@agoric/internal';
4
3
  import {
5
4
  makeRatio,
6
5
  natSafeMath,
@@ -13,8 +12,6 @@ const { Fail, quote: q } = assert;
13
12
  const { multiply, floorDivide } = natSafeMath;
14
13
  const { entries, fromEntries, keys, values } = Object;
15
14
 
16
- const QUOTE_INTERVAL = 5n * 60n;
17
-
18
15
  /** @type {Record<string, number>} */
19
16
  export const DecimalPlaces = {
20
17
  [Stake.symbol]: Stake.displayInfo.decimalPlaces,
@@ -346,7 +343,7 @@ export const connectFaucet = async ({
346
343
  harden(connectFaucet);
347
344
 
348
345
  /**
349
- * Calculate how much RUN we need to fund the AMM pools
346
+ * Calculate how much RUN we need to fund the pools
350
347
  *
351
348
  * @param {typeof AMMDemoState} issuers
352
349
  */
@@ -461,231 +458,3 @@ export const poolRates = (issuerName, record, kits, central) => {
461
458
  * consume: { mints }
462
459
  * }} powers
463
460
  */
464
- export const fundAMM = async ({
465
- consume: {
466
- bldIssuerKit,
467
- chainTimerService,
468
- feeMintAccess,
469
- mints,
470
- priceAuthorityVat,
471
- priceAuthorityAdmin,
472
- vaultFactoryKit,
473
- zoe,
474
- },
475
- installation: {
476
- consume: { centralSupply: centralSupplyInstall },
477
- },
478
- issuer: {
479
- consume: { IST: centralIssuer },
480
- },
481
- brand: {
482
- consume: { IST: centralBrand },
483
- },
484
- instance: {
485
- consume: { amm: ammInstance },
486
- },
487
- }) => {
488
- const { ammTotal: ammDepositValue, balances } =
489
- ammPoolRunDeposits(AMMDemoState);
490
-
491
- const vats = { mints, priceAuthority: priceAuthorityVat };
492
-
493
- const kits = await allValues(
494
- objectMap(
495
- fromEntries([Stable.symbol, ...keys(AMMDemoState)].map(n => [n, n])),
496
- async issuerName => {
497
- switch (issuerName) {
498
- case Stable.symbol: {
499
- const [issuer, brand] = await Promise.all([
500
- centralIssuer,
501
- centralBrand,
502
- ]);
503
- return { mint: undefined, issuer, brand };
504
- }
505
- case 'BLD':
506
- return bldIssuerKit;
507
- default:
508
- return provideCoin(issuerName, vats.mints);
509
- }
510
- },
511
- ),
512
- );
513
-
514
- const central = /** @type {Pick<IssuerKit<'nat'>, 'issuer' | 'brand'>} */ (
515
- kits[Stable.symbol]
516
- );
517
-
518
- /** @type {[ XYKAMMPublicFacet, import('@agoric/time/src/types').TimerService]} */
519
- const [ammPublicFacet, timer] = await Promise.all([
520
- E(zoe).getPublicFacet(ammInstance),
521
- chainTimerService,
522
- ]);
523
-
524
- const ammBootstrapPayment = await mintRunPayment(ammDepositValue, {
525
- centralSupplyInstall,
526
- feeMintAccess,
527
- zoe,
528
- });
529
-
530
- async function addAllCollateral() {
531
- const issuerMap = await splitAllCentralPayments(
532
- ammBootstrapPayment,
533
- balances,
534
- central,
535
- );
536
-
537
- return Promise.all(
538
- entries(AMMDemoState).map(async ([issuerName, record]) => {
539
- if (!record.config) {
540
- return undefined;
541
- }
542
- const { rates, initialValue } = poolRates(
543
- issuerName,
544
- record,
545
- kits,
546
- central,
547
- );
548
-
549
- const kit = kits[issuerName];
550
- if (!kit.mint) {
551
- throw Fail`no mint for ${q(issuerName)}`;
552
- }
553
- // @@ doesn't work for BLD?
554
- const secondaryPayment = await E(kit.mint).mintPayment(
555
- AmountMath.make(kit.brand, initialValue),
556
- );
557
- secondaryPayment || Fail`no payment for ${q(issuerName)}`;
558
- kit.issuer || Fail`No issuer for ${q(issuerName)}`;
559
- const liquidityIssuer = /** @type {Promise<Issuer<'nat'>>} */ (
560
- E(ammPublicFacet).addIssuer(kit.issuer, issuerName)
561
- );
562
- const [secondaryAmount, liquidityBrand] = await Promise.all([
563
- // Error: (an undefined) was not a live payment for brand
564
- // at (.../vats/src/demoIssuers.js:591)
565
- E(kit.issuer).getAmountOf(secondaryPayment),
566
- E(liquidityIssuer).getBrand(),
567
- ]);
568
- const centralAmount = issuerMap[issuerName].amount;
569
- const proposal = harden({
570
- want: { Liquidity: AmountMath.makeEmpty(liquidityBrand) },
571
- give: { Secondary: secondaryAmount, Central: centralAmount },
572
- });
573
-
574
- await E(zoe).offer(
575
- E(ammPublicFacet).addPoolInvitation(),
576
- proposal,
577
- harden({
578
- Secondary: secondaryPayment,
579
- Central: issuerMap[issuerName].payment,
580
- }),
581
- );
582
-
583
- const issuerPresence = await kit.issuer;
584
- return E(E.get(vaultFactoryKit).creatorFacet).addVaultType(
585
- issuerPresence,
586
- issuerName,
587
- rates,
588
- );
589
- }),
590
- );
591
- }
592
-
593
- /**
594
- * @param {ERef<Brand>} brandIn
595
- * @param {ERef<Brand>} brandOut
596
- * @param {Array<[bigint | number, bigint | number]>} tradeList
597
- */
598
- const makeFakePriceAuthority = (brandIn, brandOut, tradeList) =>
599
- E(vats.priceAuthority).makeFakePriceAuthority({
600
- actualBrandIn: brandIn,
601
- actualBrandOut: brandOut,
602
- tradeList,
603
- timer,
604
- quoteInterval: QUOTE_INTERVAL,
605
- });
606
-
607
- await addAllCollateral();
608
-
609
- const brandsWithPriceAuthorities = await E(ammPublicFacet).getAllPoolBrands();
610
-
611
- await Promise.all(
612
- // TODO: exactly what is the list of things to iterate here?
613
- entries(AMMDemoState).map(async ([issuerName, record]) => {
614
- // Create priceAuthority pairs for centralIssuer based on the
615
- // AMM or FakePriceAuthority.
616
- console.debug(`Creating ${issuerName}-${Stable.symbol}`);
617
- const issuer = kits[issuerName].issuer;
618
- const { trades } = record;
619
- /** @param {bigint} n */
620
- const inCollateral = n => n * 10n ** BigInt(DecimalPlaces[issuerName]);
621
- const tradesGivenCentral = trades.map(
622
- ({ central: num, collateral: unit }) =>
623
- /** @type {[bigint, bigint]} */ ([
624
- run2places(num),
625
- inCollateral(unit),
626
- ]),
627
- );
628
- assert(issuer);
629
- const brand = await E(issuer).getBrand();
630
- let toCentral;
631
- let fromCentral;
632
-
633
- if (brandsWithPriceAuthorities.includes(brand)) {
634
- ({ toCentral, fromCentral } = await E(ammPublicFacet)
635
- .getPriceAuthorities(brand)
636
- .catch(_e => {
637
- // console.warn('could not get AMM priceAuthorities', _e);
638
- return { toCentral: undefined, fromCentral: undefined };
639
- }));
640
- }
641
-
642
- if (!fromCentral && tradesGivenCentral) {
643
- // We have no amm from-central price authority, make one from trades.
644
- if (issuerName !== Stable.symbol) {
645
- console.log(
646
- `Making fake price authority for ${Stable.symbol}-${issuerName}`,
647
- );
648
- }
649
- fromCentral = makeFakePriceAuthority(
650
- central.brand,
651
- brand,
652
- tradesGivenCentral,
653
- );
654
- }
655
-
656
- if (!toCentral && central.issuer !== issuer && tradesGivenCentral) {
657
- // We have no amm to-central price authority, make one from trades.
658
- console.log(
659
- `Making fake price authority for ${issuerName}-${Stable.symbol}`,
660
- );
661
- /** @type {Array<[bigint | number, bigint | number]>} */
662
- const tradesGivenOther = tradesGivenCentral.map(
663
- ([valueCentral, valueOther]) => [valueOther, valueCentral],
664
- );
665
- toCentral = makeFakePriceAuthority(
666
- brand,
667
- central.brand,
668
- tradesGivenOther,
669
- );
670
- }
671
-
672
- // Register the price pairs.
673
- await Promise.all(
674
- [
675
- { pa: fromCentral, fromBrand: central.brand, toBrand: brand },
676
- { pa: toCentral, fromBrand: brand, toBrand: central.brand },
677
- ].map(async ({ pa, fromBrand, toBrand }) => {
678
- const paPresence = await pa;
679
- if (!paPresence) {
680
- return;
681
- }
682
- await E(priceAuthorityAdmin).registerPriceAuthority(
683
- paPresence,
684
- fromBrand,
685
- toBrand,
686
- );
687
- }),
688
- );
689
- }),
690
- );
691
- };