@agoric/inter-protocol 0.13.4-pismo-dev-0d5327f.0 → 0.14.1-dev-bf4b59f.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 (141) hide show
  1. package/CHANGELOG.md +287 -0
  2. package/README.md +26 -20
  3. package/bundles/bundle-auctioneer-js-meta.json +722 -0
  4. package/bundles/bundle-auctioneer.js +1 -0
  5. package/bundles/bundle-econCommitteeCharter-js-meta.json +514 -0
  6. package/bundles/bundle-econCommitteeCharter.js +1 -0
  7. package/bundles/bundle-feeDistributor-js-meta.json +458 -0
  8. package/bundles/bundle-feeDistributor.js +1 -1
  9. package/bundles/bundle-fluxAggregatorKit-js-meta.json +674 -0
  10. package/bundles/bundle-fluxAggregatorKit.js +1 -0
  11. package/bundles/bundle-psm-js-meta.json +666 -0
  12. package/bundles/bundle-psm.js +1 -1
  13. package/bundles/bundle-reserve-js-meta.json +662 -0
  14. package/bundles/bundle-reserve.js +1 -1
  15. package/bundles/bundle-scaledPriceAuthority-js-meta.json +542 -0
  16. package/bundles/bundle-scaledPriceAuthority.js +1 -1
  17. package/bundles/bundle-vaultFactory-js-meta.json +786 -0
  18. package/bundles/bundle-vaultFactory.js +1 -1
  19. package/exported.js +0 -2
  20. package/package.json +34 -31
  21. package/scripts/add-collateral-core.js +14 -4
  22. package/scripts/build-bundles.js +9 -2
  23. package/scripts/deploy-contracts.js +1 -4
  24. package/scripts/init-core.js +20 -38
  25. package/scripts/invite-committee-core.js +1 -1
  26. package/scripts/manual-price-feed.js +2 -2
  27. package/scripts/price-feed-core.js +7 -6
  28. package/scripts/start-local-chain.sh +84 -0
  29. package/src/auction/auctionBook.js +755 -0
  30. package/src/auction/auctioneer.js +720 -0
  31. package/src/auction/offerBook.js +221 -0
  32. package/src/auction/params.js +174 -0
  33. package/src/auction/scheduleMath.js +167 -0
  34. package/src/auction/scheduler.js +370 -0
  35. package/src/auction/sortedOffers.js +136 -0
  36. package/src/auction/util.js +55 -0
  37. package/src/clientSupport.js +324 -0
  38. package/src/collectFees.js +8 -14
  39. package/src/contractSupport.js +24 -68
  40. package/src/econCommitteeCharter.js +161 -77
  41. package/src/feeDistributor.js +60 -20
  42. package/src/index.js +2 -0
  43. package/src/interest-math.js +1 -4
  44. package/src/interest.js +20 -13
  45. package/src/price/README.md +57 -0
  46. package/src/price/fluxAggregatorContract.js +190 -0
  47. package/src/price/fluxAggregatorKit.js +375 -0
  48. package/src/price/priceOracleKit.js +127 -0
  49. package/src/price/roundsManager.js +726 -0
  50. package/src/proposals/addAssetToVault.js +89 -94
  51. package/src/proposals/committee-proposal.js +141 -40
  52. package/src/proposals/core-proposal.js +100 -167
  53. package/src/proposals/econ-behaviors.js +320 -564
  54. package/src/proposals/price-feed-proposal.js +175 -78
  55. package/src/proposals/startEconCommittee.js +25 -12
  56. package/src/proposals/startPSM.js +231 -211
  57. package/src/proposals/utils.js +31 -17
  58. package/src/psm/README.md +71 -0
  59. package/src/psm/psm.js +272 -160
  60. package/src/psm/types.js +2 -0
  61. package/src/reserve/assetReserve.js +56 -413
  62. package/src/reserve/assetReserveKit.js +303 -0
  63. package/src/reserve/doc.md +1 -3
  64. package/src/reserve/params.js +2 -5
  65. package/src/typeGuards.js +13 -0
  66. package/src/vaultFactory/Liquidation.md +100 -0
  67. package/src/vaultFactory/burn.js +2 -1
  68. package/src/vaultFactory/liquidation.js +270 -108
  69. package/src/vaultFactory/math.js +95 -0
  70. package/src/vaultFactory/orderedVaultStore.js +0 -1
  71. package/src/vaultFactory/params.js +133 -112
  72. package/src/vaultFactory/prioritizedVaults.js +36 -79
  73. package/src/vaultFactory/storeUtils.js +67 -9
  74. package/src/vaultFactory/type-imports.js +2 -0
  75. package/src/vaultFactory/types.js +22 -26
  76. package/src/vaultFactory/vault.js +772 -709
  77. package/src/vaultFactory/vaultDirector.js +480 -483
  78. package/src/vaultFactory/vaultFactory.js +99 -60
  79. package/src/vaultFactory/vaultHolder.js +121 -95
  80. package/src/vaultFactory/vaultKit.js +39 -31
  81. package/src/vaultFactory/vaultManager.js +1249 -868
  82. package/bundles/bundle-amm-meta.js +0 -618
  83. package/bundles/bundle-amm.js +0 -1
  84. package/bundles/bundle-feeDistributor-meta.js +0 -346
  85. package/bundles/bundle-interchainPool-meta.js +0 -534
  86. package/bundles/bundle-interchainPool.js +0 -1
  87. package/bundles/bundle-liquidateIncrementally-meta.js +0 -442
  88. package/bundles/bundle-liquidateIncrementally.js +0 -1
  89. package/bundles/bundle-liquidateMinimum-meta.js +0 -442
  90. package/bundles/bundle-liquidateMinimum.js +0 -1
  91. package/bundles/bundle-psm-meta.js +0 -538
  92. package/bundles/bundle-psmCharter-meta.js +0 -418
  93. package/bundles/bundle-psmCharter.js +0 -1
  94. package/bundles/bundle-reserve-meta.js +0 -542
  95. package/bundles/bundle-scaledPriceAuthority-meta.js +0 -442
  96. package/bundles/bundle-stakeFactory-meta.js +0 -574
  97. package/bundles/bundle-stakeFactory.js +0 -1
  98. package/bundles/bundle-vaultFactory-meta.js +0 -598
  99. package/scripts/add-initial-liquidity.js +0 -180
  100. package/src/collect.js +0 -13
  101. package/src/interchainPool.js +0 -135
  102. package/src/makeTracer.js +0 -36
  103. package/src/my-lien.js +0 -85
  104. package/src/proposals/demoIssuers.js +0 -685
  105. package/src/proposals/sim-behaviors.js +0 -40
  106. package/src/psm/psmCharter.js +0 -139
  107. package/src/stakeFactory/README.md +0 -62
  108. package/src/stakeFactory/attestation.js +0 -267
  109. package/src/stakeFactory/attestationTool.js +0 -66
  110. package/src/stakeFactory/constants.js +0 -16
  111. package/src/stakeFactory/params.js +0 -31
  112. package/src/stakeFactory/stakeFactory.js +0 -236
  113. package/src/stakeFactory/stakeFactoryKit.js +0 -455
  114. package/src/stakeFactory/stakeFactoryManager.js +0 -296
  115. package/src/stakeFactory/types.js +0 -42
  116. package/src/vaultFactory/liquidateIncrementally.js +0 -350
  117. package/src/vaultFactory/liquidateMinimum.js +0 -100
  118. package/src/vpool-xyk-amm/AttackersGuide.md +0 -89
  119. package/src/vpool-xyk-amm/addLiquidity.js +0 -222
  120. package/src/vpool-xyk-amm/addPool.js +0 -197
  121. package/src/vpool-xyk-amm/constantProduct/AMM-Trade.jpeg +0 -0
  122. package/src/vpool-xyk-amm/constantProduct/README.md +0 -204
  123. package/src/vpool-xyk-amm/constantProduct/calcFees.js +0 -99
  124. package/src/vpool-xyk-amm/constantProduct/calcSwapPrices.js +0 -85
  125. package/src/vpool-xyk-amm/constantProduct/core.js +0 -153
  126. package/src/vpool-xyk-amm/constantProduct/defaults.js +0 -5
  127. package/src/vpool-xyk-amm/constantProduct/getXY.js +0 -52
  128. package/src/vpool-xyk-amm/constantProduct/internal-types.js +0 -116
  129. package/src/vpool-xyk-amm/constantProduct/invariants.js +0 -43
  130. package/src/vpool-xyk-amm/constantProduct/swap.js +0 -272
  131. package/src/vpool-xyk-amm/constantProduct/types.js +0 -32
  132. package/src/vpool-xyk-amm/doublePool.js +0 -194
  133. package/src/vpool-xyk-amm/estimate.js +0 -155
  134. package/src/vpool-xyk-amm/multipoolMarketMaker.js +0 -520
  135. package/src/vpool-xyk-amm/params.js +0 -61
  136. package/src/vpool-xyk-amm/pool.js +0 -396
  137. package/src/vpool-xyk-amm/priceAuthority.js +0 -94
  138. package/src/vpool-xyk-amm/removeLiquidity.js +0 -31
  139. package/src/vpool-xyk-amm/singlePool.js +0 -73
  140. package/src/vpool-xyk-amm/swap.js +0 -69
  141. package/src/vpool-xyk-amm/types.js +0 -154
@@ -1,19 +1,17 @@
1
+ import { WalletName } from '@agoric/internal';
1
2
  import { getCopyMapEntries, makeCopyMap } from '@agoric/store';
2
3
  import { E } from '@endo/far';
3
4
 
4
- // must match packages/wallet/api/src/lib-wallet.js
5
- export const DEPOSIT_FACET = 'depositFacet';
6
-
7
- const { details: X } = assert;
5
+ const { Fail } = assert;
8
6
 
9
7
  /**
10
- * @param {ERef<NameAdmin>} nameAdmin
8
+ * @param {ERef<import('@agoric/vats').NameAdmin>} nameAdmin
11
9
  * @param {string[][]} paths
12
10
  */
13
11
  export const reserveThenGetNamePaths = async (nameAdmin, paths) => {
14
12
  /**
15
13
  *
16
- * @param {ERef<NameAdmin>} nextAdmin
14
+ * @param {ERef<import('@agoric/vats').NameAdmin>} nextAdmin
17
15
  * @param {string[]} path
18
16
  */
19
17
  const nextPath = async (nextAdmin, path) => {
@@ -36,14 +34,14 @@ export const reserveThenGetNamePaths = async (nameAdmin, paths) => {
36
34
 
37
35
  return Promise.all(
38
36
  paths.map(async path => {
39
- assert(Array.isArray(path), X`path ${path} is not an array`);
37
+ Array.isArray(path) || Fail`path ${path} is not an array`;
40
38
  return nextPath(nameAdmin, path);
41
39
  }),
42
40
  );
43
41
  };
44
42
 
45
43
  /**
46
- * @param {ERef<NameAdmin>} nameAdmin
44
+ * @param {ERef<import('@agoric/vats').NameAdmin>} nameAdmin
47
45
  * @param {string[]} names
48
46
  */
49
47
  export const reserveThenGetNames = async (nameAdmin, names) =>
@@ -52,22 +50,36 @@ export const reserveThenGetNames = async (nameAdmin, names) =>
52
50
  names.map(name => [name]),
53
51
  );
54
52
 
53
+ /**
54
+ * @param {string} debugName
55
+ * @param {ERef<import('@agoric/vats').NameAdmin>} namesByAddressAdmin
56
+ * @param {string} addr
57
+ * @param {Array<ERef<Payment>>} payments
58
+ */
55
59
  export const reserveThenDeposit = async (
56
60
  debugName,
57
61
  namesByAddressAdmin,
58
62
  addr,
59
63
  payments,
60
64
  ) => {
61
- console.info('waiting for', debugName);
65
+ console.info('awaiting depositFacet for', debugName);
62
66
  const [depositFacet] = await reserveThenGetNamePaths(namesByAddressAdmin, [
63
- [addr, DEPOSIT_FACET],
67
+ [addr, WalletName.depositFacet],
64
68
  ]);
65
69
  console.info('depositing to', debugName);
66
- await Promise.all(payments.map(payment => E(depositFacet).receive(payment)));
67
- console.info('confirmed deposit for', debugName);
70
+ await Promise.allSettled(
71
+ payments.map(async (paymentP, i) => {
72
+ const payment = await paymentP;
73
+ await E(depositFacet).receive(payment);
74
+ console.info(
75
+ `confirmed deposit ${i + 1}/${payments.length} for`,
76
+ debugName,
77
+ );
78
+ }),
79
+ );
68
80
  };
69
81
 
70
- /** @type {<T>(store: ERef<MapStore>, key: string, make: () => T) => Promise<T>} */
82
+ /** @type {<T>(store: ERef<Map<string, T> | import('@agoric/internal/src/scratch.js').ScratchPad>, key: string, make: () => T) => Promise<T>} */
71
83
  const provideWhen = async (store, key, make) => {
72
84
  const found = await E(store).get(key);
73
85
  if (found) {
@@ -79,8 +91,7 @@ const provideWhen = async (store, key, make) => {
79
91
  };
80
92
 
81
93
  /**
82
- *
83
- * @param {{ scratch: ERef<MapStore<string, unknown>> }} homeP
94
+ * @param {{ scratch: ERef<import('@agoric/internal/src/scratch.js').ScratchPad> }} homeP
84
95
  * @param {object} opts
85
96
  * @param {(specifier: string) => Promise<{default: Bundle}>} opts.loadBundle
86
97
  * @param {string} [opts.installCacheKey]
@@ -108,9 +119,12 @@ export const makeInstallCache = async (
108
119
  };
109
120
 
110
121
  const wrapInstall = install => async (mPath, bPath, opts) => {
111
- const { endoZipBase64Sha512: sha512 } = await loadBundle(bPath).then(
112
- m => m.default,
122
+ const bundle = await loadBundle(bPath).then(m => m.default);
123
+ assert(
124
+ 'endoZipBase64Sha512' in bundle,
125
+ 'bundle must be EndoZipBase64Bundle',
113
126
  );
127
+ const { endoZipBase64Sha512: sha512 } = bundle;
114
128
  const detail = await provideWhen(working, sha512, () =>
115
129
  install(mPath, bPath, opts).then(installation => ({
116
130
  installation,
@@ -0,0 +1,71 @@
1
+ # Parity Stability Module
2
+
3
+ The Parity Stability Module supports efficiently minting/burning a stable token
4
+ at a specified fixed ratio to a reference stable token, which thereby acts as an
5
+ anchor to provide additional stability. For flexible economic policies, the fee
6
+ percentage for trading into and out of the stable token are specified
7
+ separately.
8
+
9
+
10
+ ## Usage
11
+
12
+ See the [Smart Wallet integration test](/packages/inter-protocol/test/smartWallet/test-psm-integration.js) for how it's used.
13
+
14
+ End users can make swap offers in the CLI or GUI.
15
+
16
+ ### CLI
17
+
18
+ See [psm.js command file](/packages/agoric-cli/src/commands/psm.js) and its [integration test script](/packages/agoric-cli/scripts/).
19
+
20
+ ```mermaid
21
+ sequenceDiagram
22
+
23
+ actor user
24
+
25
+ participant cli as Dapp PSM
26
+ participant disk
27
+ participant B as Cosmos / Swingset <br/> bridge
28
+ participant C as smart-wallet<br/>contract
29
+ participant PSM as PSM<br/>contract
30
+
31
+ user ->> cli: create a swap offer
32
+ user -->> disk: write offer data
33
+ user ->> cli: sign and send swap offer
34
+ disk -->> cli: read offer data
35
+ cli ->> B: spending transaction
36
+ B ->> C: unpack ocap data
37
+ C ->> PSM: route offer
38
+ ```
39
+
40
+
41
+ ### GUI
42
+
43
+ The GUI is in https://github.com/Agoric/dapp-psm
44
+
45
+ It introduces another layer of communication (between the dapp and Wallet UI):
46
+
47
+ ```mermaid
48
+ sequenceDiagram
49
+
50
+ actor user
51
+
52
+ participant dapp as Dapp PSM
53
+ participant ls as localStorage
54
+ participant ui as Wallet UI
55
+ participant Keplr
56
+ participant B as Cosmos / Swingset <br/> bridge
57
+ participant C as smart-wallet<br/>contract
58
+ participant PSM as PSM<br/>contract
59
+
60
+ user ->> dapp: configure offer and click
61
+ dapp ->> ls: write offer record
62
+ ls ->> ui: notify offer record
63
+ ui ->> user: display offer for signing
64
+ user ->> ui: click Approve
65
+ ui ->> Keplr: request signing
66
+ Keplr ->> user: pop-up transaction
67
+ user ->> Keplr: click to sign
68
+ Keplr ->> B: spending transaction
69
+ B ->> C: unpack ocap data
70
+ C ->> PSM: route offer
71
+ ```