@agoric/inter-protocol 0.16.2-other-dev-8f8782b.0 → 0.16.2-other-dev-fbe72e7.0.fbe72e7
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.
- package/README.md +6 -6
- package/package.json +46 -39
- package/scripts/build-bundles.js +5 -21
- package/src/auction/auctionBook.d.ts +147 -0
- package/src/auction/auctionBook.d.ts.map +1 -0
- package/src/auction/auctionBook.js +182 -151
- package/src/auction/auctionMath.d.ts +17 -0
- package/src/auction/auctionMath.d.ts.map +1 -0
- package/src/auction/auctionMath.js +81 -0
- package/src/auction/auctioneer.d.ts +70 -0
- package/src/auction/auctioneer.d.ts.map +1 -0
- package/src/auction/auctioneer.js +72 -59
- package/src/auction/offerBook.d.ts +46 -0
- package/src/auction/offerBook.d.ts.map +1 -0
- package/src/auction/offerBook.js +17 -12
- package/src/auction/params.d.ts +145 -0
- package/src/auction/params.d.ts.map +1 -0
- package/src/auction/params.js +11 -9
- package/src/auction/scheduleMath.d.ts +5 -0
- package/src/auction/scheduleMath.d.ts.map +1 -0
- package/src/auction/scheduleMath.js +18 -16
- package/src/auction/scheduler.d.ts +50 -0
- package/src/auction/scheduler.d.ts.map +1 -0
- package/src/auction/scheduler.js +53 -47
- package/src/auction/sortedOffers.d.ts +8 -0
- package/src/auction/sortedOffers.d.ts.map +1 -0
- package/src/auction/sortedOffers.js +10 -9
- package/src/auction/util.d.ts +31 -0
- package/src/auction/util.d.ts.map +1 -0
- package/src/auction/util.js +12 -6
- package/src/clientSupport.d.ts +168 -0
- package/src/clientSupport.d.ts.map +1 -0
- package/src/clientSupport.js +161 -98
- package/src/collectFees.d.ts +2 -0
- package/src/collectFees.d.ts.map +1 -0
- package/src/contractSupport.d.ts +28 -0
- package/src/contractSupport.d.ts.map +1 -0
- package/src/contractSupport.js +19 -13
- package/src/econCommitteeCharter.d.ts +43 -0
- package/src/econCommitteeCharter.d.ts.map +1 -0
- package/src/econCommitteeCharter.js +25 -20
- package/src/feeDistributor.d.ts +224 -0
- package/src/feeDistributor.d.ts.map +1 -0
- package/src/feeDistributor.js +41 -33
- package/src/index.d.ts +2 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +1 -0
- package/src/interest-math.d.ts +4 -0
- package/src/interest-math.d.ts.map +1 -0
- package/src/interest-math.js +5 -1
- package/src/interest.d.ts +30 -0
- package/src/interest.d.ts.map +1 -0
- package/src/interest.js +25 -23
- package/src/price/README.md +14 -1
- package/src/price/fluxAggregatorContract.d.ts +71 -0
- package/src/price/fluxAggregatorContract.d.ts.map +1 -0
- package/src/price/fluxAggregatorContract.js +64 -55
- package/src/price/fluxAggregatorKit.d.ts +104 -0
- package/src/price/fluxAggregatorKit.d.ts.map +1 -0
- package/src/price/fluxAggregatorKit.js +55 -42
- package/src/price/priceOracleKit.d.ts +39 -0
- package/src/price/priceOracleKit.d.ts.map +1 -0
- package/src/price/priceOracleKit.js +17 -15
- package/src/price/roundsManager.d.ts +204 -0
- package/src/price/roundsManager.d.ts.map +1 -0
- package/src/price/roundsManager.js +132 -85
- package/src/proposals/README.md +2 -3
- package/src/proposals/add-auction.js +285 -0
- package/src/proposals/addAssetToVault.js +192 -40
- package/src/proposals/committee-proposal.js +25 -31
- package/src/proposals/core-proposal.js +9 -11
- package/src/proposals/deploy-price-feeds.js +341 -0
- package/src/proposals/econ-behaviors.js +84 -49
- package/src/proposals/price-feed-proposal.js +109 -51
- package/src/proposals/replace-fee-distributor.js +198 -0
- package/src/proposals/replace-scaledPriceAuthorities.js +124 -0
- package/src/proposals/replaceElectorate.js +610 -0
- package/src/proposals/startEconCommittee.js +2 -2
- package/src/proposals/startPSM.js +44 -29
- package/src/proposals/upgrade-scaledPriceAuthorities.js +78 -0
- package/src/proposals/upgrade-vaults.js +207 -0
- package/src/proposals/utils.d.ts +21 -0
- package/src/proposals/utils.d.ts.map +1 -0
- package/src/proposals/utils.js +66 -9
- package/src/proposals/withdraw-reserve-proposal.js +63 -0
- package/src/provisionPool.d.ts +69 -0
- package/src/provisionPool.d.ts.map +1 -0
- package/src/provisionPool.js +138 -0
- package/src/provisionPoolKit.d.ts +129 -0
- package/src/provisionPoolKit.d.ts.map +1 -0
- package/src/provisionPoolKit.js +608 -0
- package/src/psm/psm.d.ts +133 -0
- package/src/psm/psm.d.ts.map +1 -0
- package/src/psm/psm.js +85 -79
- package/src/psm/types-ambient.d.ts +2 -0
- package/src/psm/types-ambient.d.ts.map +1 -0
- package/src/psm/types-ambient.js +3 -0
- package/src/reserve/assetReserve.d.ts +58 -0
- package/src/reserve/assetReserve.d.ts.map +1 -0
- package/src/reserve/assetReserve.js +42 -34
- package/src/reserve/assetReserveKit.d.ts +103 -0
- package/src/reserve/assetReserveKit.d.ts.map +1 -0
- package/src/reserve/assetReserveKit.js +134 -32
- package/src/reserve/params.d.ts +16 -0
- package/src/reserve/params.d.ts.map +1 -0
- package/src/reserve/params.js +8 -2
- package/src/tokens.d.ts +3 -0
- package/src/tokens.d.ts.map +1 -0
- package/src/tokens.js +5 -0
- package/src/vaultFactory/burn.d.ts +2 -0
- package/src/vaultFactory/burn.d.ts.map +1 -0
- package/src/vaultFactory/burn.js +1 -1
- package/src/vaultFactory/liquidation.d.ts +25 -0
- package/src/vaultFactory/liquidation.d.ts.map +1 -0
- package/src/vaultFactory/liquidation.js +37 -24
- package/src/vaultFactory/math.d.ts +11 -0
- package/src/vaultFactory/math.d.ts.map +1 -0
- package/src/vaultFactory/math.js +11 -10
- package/src/vaultFactory/orderedVaultStore.d.ts +94 -0
- package/src/vaultFactory/orderedVaultStore.d.ts.map +1 -0
- package/src/vaultFactory/orderedVaultStore.js +9 -10
- package/src/vaultFactory/params.d.ts +143 -0
- package/src/vaultFactory/params.d.ts.map +1 -0
- package/src/vaultFactory/params.js +56 -25
- package/src/vaultFactory/prioritizedVaults.d.ts +280 -0
- package/src/vaultFactory/prioritizedVaults.d.ts.map +1 -0
- package/src/vaultFactory/prioritizedVaults.js +7 -4
- package/src/vaultFactory/proceeds.d.ts +35 -0
- package/src/vaultFactory/proceeds.d.ts.map +1 -0
- package/src/vaultFactory/proceeds.js +26 -18
- package/src/vaultFactory/storeUtils.d.ts +25 -0
- package/src/vaultFactory/storeUtils.d.ts.map +1 -0
- package/src/vaultFactory/storeUtils.js +10 -12
- package/src/vaultFactory/types-ambient.d.ts +137 -0
- package/src/vaultFactory/types-ambient.d.ts.map +1 -0
- package/src/vaultFactory/{types.js → types-ambient.js} +47 -44
- package/src/vaultFactory/vault.d.ts +344 -0
- package/src/vaultFactory/vault.d.ts.map +1 -0
- package/src/vaultFactory/vault.js +107 -100
- package/src/vaultFactory/vaultDirector.d.ts +347 -0
- package/src/vaultFactory/vaultDirector.d.ts.map +1 -0
- package/src/vaultFactory/vaultDirector.js +94 -64
- package/src/vaultFactory/vaultFactory.d.ts +250 -0
- package/src/vaultFactory/vaultFactory.d.ts.map +1 -0
- package/src/vaultFactory/vaultFactory.js +56 -33
- package/src/vaultFactory/vaultHolder.d.ts +170 -0
- package/src/vaultFactory/vaultHolder.d.ts.map +1 -0
- package/src/vaultFactory/vaultHolder.js +14 -15
- package/src/vaultFactory/vaultKit.d.ts +33 -0
- package/src/vaultFactory/vaultKit.d.ts.map +1 -0
- package/src/vaultFactory/vaultKit.js +9 -4
- package/src/vaultFactory/vaultManager.d.ts +676 -0
- package/src/vaultFactory/vaultManager.d.ts.map +1 -0
- package/src/vaultFactory/vaultManager.js +286 -167
- package/CHANGELOG.md +0 -1041
- package/exported.js +0 -2
- package/scripts/add-collateral-core.js +0 -112
- package/scripts/deploy-contracts.js +0 -100
- package/scripts/init-core.js +0 -198
- package/scripts/invite-committee-core.js +0 -42
- package/scripts/manual-price-feed.js +0 -117
- package/scripts/price-feed-core.js +0 -104
- package/scripts/start-local-chain.sh +0 -84
- package/src/psm/types.js +0 -3
- package/src/typeGuards.js +0 -13
- package/src/vaultFactory/type-imports.js +0 -4
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
// @ts-nocheck -- lots of type errors. low prio b/c proposals are like scripts
|
|
2
|
-
import {
|
|
2
|
+
import { makeTracer } from '@agoric/internal';
|
|
3
3
|
import {
|
|
4
|
-
makeStorageNodeChild,
|
|
5
4
|
assertPathSegment,
|
|
5
|
+
makeStorageNodeChild,
|
|
6
6
|
} from '@agoric/internal/src/lib-chainStorage.js';
|
|
7
|
-
import {
|
|
7
|
+
import { E } from '@endo/far';
|
|
8
8
|
|
|
9
9
|
import { unitAmount } from '@agoric/zoe/src/contractSupport/priceQuote.js';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
oracleBrandFeedName,
|
|
12
|
+
reserveThenDeposit,
|
|
13
|
+
reserveThenGetNames,
|
|
14
|
+
} from './utils.js';
|
|
15
|
+
|
|
16
|
+
// backwards compatibility
|
|
17
|
+
export { oracleBrandFeedName as instanceNameFor };
|
|
11
18
|
|
|
12
19
|
const trace = makeTracer('RunPriceFeed', true);
|
|
13
20
|
|
|
@@ -20,12 +27,12 @@ const sanitizePathSegment = name => {
|
|
|
20
27
|
|
|
21
28
|
/**
|
|
22
29
|
* @typedef {{
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
30
|
+
* brandIn?: ERef<Brand<'nat'> | undefined>;
|
|
31
|
+
* brandOut?: ERef<Brand<'nat'> | undefined>;
|
|
32
|
+
* IN_BRAND_NAME: string;
|
|
33
|
+
* IN_BRAND_DECIMALS: string;
|
|
34
|
+
* OUT_BRAND_NAME: string;
|
|
35
|
+
* OUT_BRAND_DECIMALS: string;
|
|
29
36
|
* }} PriceFeedOptions
|
|
30
37
|
*/
|
|
31
38
|
|
|
@@ -33,7 +40,7 @@ const sanitizePathSegment = name => {
|
|
|
33
40
|
* Create inert brands (no mint or issuer) referred to by price oracles.
|
|
34
41
|
*
|
|
35
42
|
* @param {ChainBootstrapSpace & NamedVatPowers} space
|
|
36
|
-
* @param {{options: {priceFeedOptions: PriceFeedOptions}}} opt
|
|
43
|
+
* @param {{ options: { priceFeedOptions: PriceFeedOptions } }} opt
|
|
37
44
|
* @returns {Promise<[Brand<'nat'>, Brand<'nat'>]>}
|
|
38
45
|
*/
|
|
39
46
|
export const ensureOracleBrands = async (
|
|
@@ -56,13 +63,10 @@ export const ensureOracleBrands = async (
|
|
|
56
63
|
},
|
|
57
64
|
},
|
|
58
65
|
) => {
|
|
59
|
-
trace('ensureOracleBrands');
|
|
60
|
-
|
|
61
66
|
const updateFreshBrand = async (brand, name, decimals) => {
|
|
62
67
|
let b = await brand;
|
|
63
68
|
if (!b) {
|
|
64
69
|
// not 1st await
|
|
65
|
-
// eslint-disable-next-line @jessie.js/no-nested-await
|
|
66
70
|
b = await E(agoricNames).provideInertBrand(
|
|
67
71
|
name,
|
|
68
72
|
harden({ decimalPlaces: parseInt(decimals, 10) }),
|
|
@@ -79,7 +83,18 @@ export const ensureOracleBrands = async (
|
|
|
79
83
|
|
|
80
84
|
/**
|
|
81
85
|
* @param {ChainBootstrapSpace} powers
|
|
82
|
-
* @param {{
|
|
86
|
+
* @param {{
|
|
87
|
+
* options: {
|
|
88
|
+
* priceFeedOptions: {
|
|
89
|
+
* AGORIC_INSTANCE_NAME: string;
|
|
90
|
+
* oracleAddresses: string[];
|
|
91
|
+
* contractTerms: import('@agoric/inter-protocol/src/price/fluxAggregatorKit.js').ChainlinkConfig;
|
|
92
|
+
* IN_BRAND_NAME: string;
|
|
93
|
+
* OUT_BRAND_NAME: string;
|
|
94
|
+
* priceAggregatorRef: Installation;
|
|
95
|
+
* };
|
|
96
|
+
* };
|
|
97
|
+
* }} config
|
|
83
98
|
*/
|
|
84
99
|
export const createPriceFeed = async (
|
|
85
100
|
{
|
|
@@ -95,7 +110,9 @@ export const createPriceFeed = async (
|
|
|
95
110
|
priceAuthority,
|
|
96
111
|
priceAuthorityAdmin,
|
|
97
112
|
startGovernedUpgradable,
|
|
113
|
+
zoe,
|
|
98
114
|
},
|
|
115
|
+
instance: { produce: produceInstance },
|
|
99
116
|
},
|
|
100
117
|
{
|
|
101
118
|
options: {
|
|
@@ -105,30 +122,62 @@ export const createPriceFeed = async (
|
|
|
105
122
|
contractTerms,
|
|
106
123
|
IN_BRAND_NAME,
|
|
107
124
|
OUT_BRAND_NAME,
|
|
125
|
+
priceAggregatorRef,
|
|
108
126
|
},
|
|
109
127
|
},
|
|
110
128
|
},
|
|
111
129
|
) => {
|
|
112
|
-
trace('createPriceFeed');
|
|
130
|
+
trace('createPriceFeed', AGORIC_INSTANCE_NAME);
|
|
113
131
|
const STORAGE_PATH = 'priceFeed';
|
|
114
132
|
|
|
115
133
|
void E(client).assignBundle([_addr => ({ priceAuthority })]);
|
|
116
134
|
|
|
117
|
-
|
|
135
|
+
let installationP;
|
|
136
|
+
await null;
|
|
137
|
+
if (priceAggregatorRef) {
|
|
138
|
+
const bundleID = await E.get(priceAggregatorRef).bundleID;
|
|
139
|
+
if (bundleID) {
|
|
140
|
+
installationP = E(zoe).installBundleID(bundleID);
|
|
141
|
+
await E.when(
|
|
142
|
+
installationP,
|
|
143
|
+
installation =>
|
|
144
|
+
E(E(agoricNamesAdmin).lookupAdmin('installation')).update(
|
|
145
|
+
'priceAggregator',
|
|
146
|
+
installation,
|
|
147
|
+
),
|
|
148
|
+
err =>
|
|
149
|
+
console.error(
|
|
150
|
+
`🚨 failed to update priceAggregator installation for ${AGORIC_INSTANCE_NAME}`,
|
|
151
|
+
err,
|
|
152
|
+
),
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (!installationP) {
|
|
157
|
+
installationP = E.get(
|
|
158
|
+
reserveThenGetNames(E(agoricNamesAdmin).lookupAdmin('installation'), [
|
|
159
|
+
'priceAggregator',
|
|
160
|
+
]),
|
|
161
|
+
)[0];
|
|
162
|
+
console.error(
|
|
163
|
+
'🚨 failed to install new fluxAggregator bundle, reusing previous one.',
|
|
164
|
+
);
|
|
165
|
+
}
|
|
118
166
|
|
|
119
167
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
168
|
+
* @type {[
|
|
169
|
+
* [Brand<'nat'>, Brand<'nat'>],
|
|
170
|
+
* Installation<import('@agoric/inter-protocol/src/price/fluxAggregatorContract.js')['start]>,
|
|
171
|
+
* Timer,
|
|
172
|
+
* ]}
|
|
123
173
|
*/
|
|
124
|
-
const [[brandIn, brandOut],
|
|
174
|
+
const [[brandIn, brandOut], installation, timer] = await Promise.all([
|
|
125
175
|
reserveThenGetNames(E(agoricNamesAdmin).lookupAdmin('oracleBrand'), [
|
|
126
176
|
IN_BRAND_NAME,
|
|
127
177
|
OUT_BRAND_NAME,
|
|
128
178
|
]),
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
]),
|
|
179
|
+
installationP,
|
|
180
|
+
chainTimerService,
|
|
132
181
|
]);
|
|
133
182
|
|
|
134
183
|
const unitAmountIn = await unitAmount(brandIn);
|
|
@@ -140,14 +189,11 @@ export const createPriceFeed = async (
|
|
|
140
189
|
timer,
|
|
141
190
|
unitAmountIn,
|
|
142
191
|
});
|
|
143
|
-
trace('got terms');
|
|
144
|
-
|
|
145
192
|
const label = sanitizePathSegment(AGORIC_INSTANCE_NAME);
|
|
146
193
|
|
|
147
194
|
const storageNode = await makeStorageNodeChild(chainStorage, STORAGE_PATH);
|
|
148
195
|
const marshaller = await E(board).getReadonlyMarshaller();
|
|
149
196
|
|
|
150
|
-
trace('awaiting startInstance');
|
|
151
197
|
const faKit = await E(startGovernedUpgradable)({
|
|
152
198
|
governedParams: {},
|
|
153
199
|
privateArgs: {
|
|
@@ -158,30 +204,38 @@ export const createPriceFeed = async (
|
|
|
158
204
|
},
|
|
159
205
|
terms,
|
|
160
206
|
label,
|
|
161
|
-
installation
|
|
207
|
+
installation,
|
|
162
208
|
});
|
|
163
209
|
|
|
164
|
-
|
|
210
|
+
// Publish price feed in home.priceAuthority.
|
|
211
|
+
const forceReplace = true;
|
|
212
|
+
// Make sure this PA is registered before sharing the instance in agoricNames,
|
|
213
|
+
// which allows contracts that depend on the registry value to wait for it and
|
|
214
|
+
// prevent a race.
|
|
215
|
+
await E(priceAuthorityAdmin).registerPriceAuthority(
|
|
216
|
+
E(faKit.publicFacet).getPriceAuthority(),
|
|
217
|
+
brandIn,
|
|
218
|
+
brandOut,
|
|
219
|
+
forceReplace,
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
await E(E(agoricNamesAdmin).lookupAdmin('instance'))
|
|
165
223
|
.update(AGORIC_INSTANCE_NAME, faKit.instance)
|
|
166
224
|
.catch(err =>
|
|
167
225
|
console.error(`🚨 failed to update ${AGORIC_INSTANCE_NAME}`, err),
|
|
168
226
|
);
|
|
169
227
|
|
|
228
|
+
// being after the above awaits means that when this resolves, the consumer
|
|
229
|
+
// gets notified that the authority is in the registry and its instance is in
|
|
230
|
+
// agoricNames. reset() in case we're replacing an existing feed.
|
|
231
|
+
produceInstance[AGORIC_INSTANCE_NAME].reset();
|
|
232
|
+
produceInstance[AGORIC_INSTANCE_NAME].resolve(faKit.instance);
|
|
233
|
+
|
|
170
234
|
E(E.get(econCharterKit).creatorFacet).addInstance(
|
|
171
235
|
faKit.instance,
|
|
172
236
|
faKit.governorCreatorFacet,
|
|
173
237
|
AGORIC_INSTANCE_NAME,
|
|
174
238
|
);
|
|
175
|
-
trace('registered', AGORIC_INSTANCE_NAME, faKit.instance);
|
|
176
|
-
|
|
177
|
-
// Publish price feed in home.priceAuthority.
|
|
178
|
-
const forceReplace = true;
|
|
179
|
-
void E(priceAuthorityAdmin).registerPriceAuthority(
|
|
180
|
-
E(faKit.publicFacet).getPriceAuthority(),
|
|
181
|
-
brandIn,
|
|
182
|
-
brandOut,
|
|
183
|
-
forceReplace,
|
|
184
|
-
);
|
|
185
239
|
|
|
186
240
|
/**
|
|
187
241
|
* Initialize a new oracle and send an invitation to administer it.
|
|
@@ -190,22 +244,23 @@ export const createPriceFeed = async (
|
|
|
190
244
|
*/
|
|
191
245
|
const addOracle = async addr => {
|
|
192
246
|
const invitation = await E(faKit.creatorFacet).makeOracleInvitation(addr);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
[invitation],
|
|
198
|
-
);
|
|
247
|
+
const debugName = `${AGORIC_INSTANCE_NAME} member ${addr}`;
|
|
248
|
+
await reserveThenDeposit(debugName, namesByAddressAdmin, addr, [
|
|
249
|
+
invitation,
|
|
250
|
+
]).catch(err => console.error(`failed deposit to ${debugName}`, err));
|
|
199
251
|
};
|
|
200
252
|
|
|
201
253
|
trace('distributing invitations', oracleAddresses);
|
|
202
|
-
|
|
254
|
+
// This doesn't resolve until oracle operators create their smart wallets.
|
|
255
|
+
// Don't block bootstrap on it.
|
|
256
|
+
void Promise.all(oracleAddresses.map(addOracle));
|
|
203
257
|
trace('createPriceFeed complete');
|
|
204
258
|
};
|
|
205
259
|
|
|
206
260
|
const t = 'priceFeed';
|
|
207
261
|
/**
|
|
208
|
-
* Add a price feed to a running chain, returning the manifest, installations,
|
|
262
|
+
* Add a price feed to a running chain, returning the manifest, installations,
|
|
263
|
+
* and options.
|
|
209
264
|
*
|
|
210
265
|
* @param {object} utils
|
|
211
266
|
* @param {(ref: unknown) => Promise<unknown>} [utils.restoreRef]
|
|
@@ -223,14 +278,16 @@ export const getManifestForPriceFeed = async (
|
|
|
223
278
|
chainStorage: t,
|
|
224
279
|
chainTimerService: t,
|
|
225
280
|
client: t,
|
|
226
|
-
contractGovernor: t,
|
|
227
281
|
econCharterKit: t,
|
|
228
|
-
economicCommitteeCreatorFacet: t,
|
|
229
282
|
highPrioritySendersManager: t,
|
|
230
283
|
namesByAddressAdmin: t,
|
|
231
284
|
priceAuthority: t,
|
|
232
285
|
priceAuthorityAdmin: t,
|
|
233
286
|
startGovernedUpgradable: t,
|
|
287
|
+
zoe: t,
|
|
288
|
+
},
|
|
289
|
+
instance: {
|
|
290
|
+
produce: t,
|
|
234
291
|
},
|
|
235
292
|
},
|
|
236
293
|
[ensureOracleBrands.name]: {
|
|
@@ -243,6 +300,7 @@ export const getManifestForPriceFeed = async (
|
|
|
243
300
|
},
|
|
244
301
|
},
|
|
245
302
|
installations: {
|
|
303
|
+
// ??? will every eval of price-feed-proposal install priceAggregator ?
|
|
246
304
|
priceAggregator: restoreRef(priceFeedOptions.priceAggregatorRef),
|
|
247
305
|
},
|
|
248
306
|
options: {
|
|
@@ -258,7 +316,7 @@ export const getManifestForPriceFeed = async (
|
|
|
258
316
|
});
|
|
259
317
|
|
|
260
318
|
/**
|
|
261
|
-
* @param {import('./econ-behaviors').EconomyBootstrapPowers} powers
|
|
319
|
+
* @param {import('./econ-behaviors.js').EconomyBootstrapPowers} powers
|
|
262
320
|
* @param {object} [config]
|
|
263
321
|
* @param {object} [config.options]
|
|
264
322
|
* @param {string[]} [config.options.demoOracleAddresses]
|
|
@@ -303,7 +361,7 @@ export const startPriceFeeds = async (
|
|
|
303
361
|
{
|
|
304
362
|
options: {
|
|
305
363
|
priceFeedOptions: {
|
|
306
|
-
AGORIC_INSTANCE_NAME:
|
|
364
|
+
AGORIC_INSTANCE_NAME: oracleBrandFeedName(inBrandName, outBrandName),
|
|
307
365
|
contractTerms: {
|
|
308
366
|
minSubmissionCount: 2,
|
|
309
367
|
minSubmissionValue: 1,
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { deeplyFulfilledObject, makeTracer } from '@agoric/internal';
|
|
2
|
+
import { Stable } from '@agoric/internal/src/tokens.js';
|
|
3
|
+
import { makeScalarBigMapStore } from '@agoric/vat-data';
|
|
4
|
+
import { getInterfaceOf, E } from '@endo/far';
|
|
5
|
+
|
|
6
|
+
const trace = makeTracer('ReplaceFeeDistributer', true);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Start the reward distributor.
|
|
10
|
+
*
|
|
11
|
+
* @param {import('./econ-behaviors').EconomyBootstrapPowers} powers
|
|
12
|
+
* @param {{
|
|
13
|
+
* options: {
|
|
14
|
+
* keywordShares: Record<string, bigint>;
|
|
15
|
+
* collectionInterval: bigint;
|
|
16
|
+
* };
|
|
17
|
+
* }} options
|
|
18
|
+
*/
|
|
19
|
+
export const replaceFeeDistributor = async (
|
|
20
|
+
{
|
|
21
|
+
consume: {
|
|
22
|
+
chainTimerService,
|
|
23
|
+
bankManager,
|
|
24
|
+
vaultFactoryKit,
|
|
25
|
+
periodicFeeCollectors,
|
|
26
|
+
reserveKit,
|
|
27
|
+
zoe,
|
|
28
|
+
contractKits: contractKitsP,
|
|
29
|
+
},
|
|
30
|
+
produce: {
|
|
31
|
+
feeDistributorKit,
|
|
32
|
+
periodicFeeCollectors: periodicFeeCollectorsP,
|
|
33
|
+
},
|
|
34
|
+
instance: {
|
|
35
|
+
produce: { feeDistributor: feeDistributorP },
|
|
36
|
+
},
|
|
37
|
+
installation: {
|
|
38
|
+
consume: { feeDistributor },
|
|
39
|
+
},
|
|
40
|
+
issuer: {
|
|
41
|
+
consume: { [Stable.symbol]: centralIssuerP },
|
|
42
|
+
},
|
|
43
|
+
brand: {
|
|
44
|
+
consume: { [Stable.symbol]: centralBrandP },
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{ options },
|
|
48
|
+
) => {
|
|
49
|
+
trace('replaceFeeDistributer', options);
|
|
50
|
+
|
|
51
|
+
const { keywordShares, collectionInterval } = options;
|
|
52
|
+
|
|
53
|
+
const feeDistributorTerms = await deeplyFulfilledObject(
|
|
54
|
+
harden({
|
|
55
|
+
timerService: chainTimerService,
|
|
56
|
+
collectionInterval,
|
|
57
|
+
keywordShares,
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
trace('feeDistributorTerms', feeDistributorTerms);
|
|
61
|
+
|
|
62
|
+
const [centralIssuer, centralBrand, contractKits] = await Promise.all([
|
|
63
|
+
centralIssuerP,
|
|
64
|
+
centralBrandP,
|
|
65
|
+
contractKitsP,
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
const rewardDistributorDepositFacet = await E(bankManager)
|
|
69
|
+
.getRewardDistributorDepositFacet(Stable.denom, {
|
|
70
|
+
issuer: centralIssuer,
|
|
71
|
+
brand: centralBrand,
|
|
72
|
+
})
|
|
73
|
+
.catch(e => {
|
|
74
|
+
console.error('Cannot create fee collector deposit facet', e);
|
|
75
|
+
return undefined;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @type {StartedInstanceKit<
|
|
80
|
+
* typeof import('@agoric/inter-protocol/src/feeDistributor.js').start
|
|
81
|
+
* >}
|
|
82
|
+
*/
|
|
83
|
+
const instanceKit = await E(zoe).startInstance(
|
|
84
|
+
feeDistributor,
|
|
85
|
+
{ Fee: centralIssuer },
|
|
86
|
+
feeDistributorTerms,
|
|
87
|
+
undefined,
|
|
88
|
+
'feeDistributor',
|
|
89
|
+
);
|
|
90
|
+
await E(instanceKit.creatorFacet).setDestinations({
|
|
91
|
+
...(rewardDistributorDepositFacet && {
|
|
92
|
+
RewardDistributor: E(
|
|
93
|
+
instanceKit.creatorFacet,
|
|
94
|
+
).makeDepositFacetDestination(rewardDistributorDepositFacet),
|
|
95
|
+
}),
|
|
96
|
+
Reserve: E(instanceKit.creatorFacet).makeOfferDestination(
|
|
97
|
+
zoe,
|
|
98
|
+
'Collateral',
|
|
99
|
+
E.get(reserveKit).publicFacet,
|
|
100
|
+
'makeAddCollateralInvitation',
|
|
101
|
+
),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
trace('Clearing the old instance from bootstrap powers...');
|
|
105
|
+
feeDistributorKit.reset();
|
|
106
|
+
feeDistributorP.reset();
|
|
107
|
+
|
|
108
|
+
trace('Now introduce the new instance');
|
|
109
|
+
feeDistributorKit.resolve(
|
|
110
|
+
harden({ ...instanceKit, label: 'feeDistributor' }),
|
|
111
|
+
);
|
|
112
|
+
feeDistributorP.resolve(instanceKit.instance);
|
|
113
|
+
|
|
114
|
+
const periodicCollectors = await periodicFeeCollectors;
|
|
115
|
+
trace(
|
|
116
|
+
`Stop periodicCollectors of the old instance. Number of collectors: ${periodicCollectors.getSize()}`,
|
|
117
|
+
);
|
|
118
|
+
for await (const [key, collector] of periodicCollectors.entries()) {
|
|
119
|
+
trace('Getting debugName', key);
|
|
120
|
+
// @ts-expect-error incomplete PeriodicFeeCollector type
|
|
121
|
+
const debugName = await E(collector).getDebugName();
|
|
122
|
+
trace(`Stopping ${debugName}...`);
|
|
123
|
+
await E(collector).stop();
|
|
124
|
+
}
|
|
125
|
+
periodicFeeCollectorsP.reset();
|
|
126
|
+
|
|
127
|
+
trace('Old collectors cleared. Start creating and setting new ones.');
|
|
128
|
+
|
|
129
|
+
const collectorKit = {
|
|
130
|
+
vaultFactory: E.get(vaultFactoryKit).creatorFacet,
|
|
131
|
+
};
|
|
132
|
+
const newCollectorStore = makeScalarBigMapStore('periodicCollectors', {
|
|
133
|
+
durable: true,
|
|
134
|
+
});
|
|
135
|
+
await Promise.all(
|
|
136
|
+
Object.entries(collectorKit).map(async ([debugName, collectorFacet]) => {
|
|
137
|
+
const collector = E(instanceKit.creatorFacet).makeContractFeeCollector(
|
|
138
|
+
zoe,
|
|
139
|
+
collectorFacet,
|
|
140
|
+
);
|
|
141
|
+
const periodicCollector = await E(
|
|
142
|
+
instanceKit.creatorFacet,
|
|
143
|
+
).startPeriodicCollection(debugName, collector);
|
|
144
|
+
newCollectorStore.init(periodicCollectors.getSize(), periodicCollector);
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
trace('Write newCollectorStore in periodicFeeCollectors');
|
|
149
|
+
periodicFeeCollectorsP.resolve(newCollectorStore);
|
|
150
|
+
|
|
151
|
+
trace('Write to contractKits');
|
|
152
|
+
const label = getInterfaceOf(instanceKit.instance);
|
|
153
|
+
const kit = harden({ ...instanceKit, label });
|
|
154
|
+
contractKits.init(kit.instance, kit);
|
|
155
|
+
|
|
156
|
+
trace('Done.');
|
|
157
|
+
};
|
|
158
|
+
harden(replaceFeeDistributor);
|
|
159
|
+
|
|
160
|
+
const t = 'replaceFeeDistributor';
|
|
161
|
+
export const getManifestForReplaceFeeDistributor = async (
|
|
162
|
+
{ restoreRef },
|
|
163
|
+
{ feeDistributorRef, ...feeDistributorOptions },
|
|
164
|
+
) => ({
|
|
165
|
+
manifest: {
|
|
166
|
+
[replaceFeeDistributor.name]: {
|
|
167
|
+
consume: {
|
|
168
|
+
chainTimerService: t,
|
|
169
|
+
bankManager: t,
|
|
170
|
+
vaultFactoryKit: t,
|
|
171
|
+
periodicFeeCollectors: t,
|
|
172
|
+
reserveKit: t,
|
|
173
|
+
zoe: t,
|
|
174
|
+
contractKits: t,
|
|
175
|
+
},
|
|
176
|
+
produce: {
|
|
177
|
+
feeDistributorKit: t,
|
|
178
|
+
periodicFeeCollectors: t,
|
|
179
|
+
},
|
|
180
|
+
instance: {
|
|
181
|
+
produce: { feeDistributor: t },
|
|
182
|
+
},
|
|
183
|
+
installation: {
|
|
184
|
+
consume: { feeDistributor: t },
|
|
185
|
+
},
|
|
186
|
+
issuer: {
|
|
187
|
+
consume: { [Stable.symbol]: t },
|
|
188
|
+
},
|
|
189
|
+
brand: {
|
|
190
|
+
consume: { [Stable.symbol]: t },
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
installations: {
|
|
195
|
+
feeDistributor: restoreRef(feeDistributorRef),
|
|
196
|
+
},
|
|
197
|
+
options: { ...feeDistributorOptions },
|
|
198
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { makeTracer } from '@agoric/internal';
|
|
2
|
+
import { E } from '@endo/far';
|
|
3
|
+
|
|
4
|
+
import { startScaledPriceAuthority } from './addAssetToVault.js';
|
|
5
|
+
import { scaledPriceFeedName } from './utils.js';
|
|
6
|
+
|
|
7
|
+
const trace = makeTracer('replaceScaledPA', true);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {BootstrapPowers} powers
|
|
11
|
+
* @param {object} config
|
|
12
|
+
* @param {object} config.options
|
|
13
|
+
*/
|
|
14
|
+
export const replaceScaledPriceAuthority = async (powers, { options }) => {
|
|
15
|
+
const {
|
|
16
|
+
instance: { produce: produceInstance },
|
|
17
|
+
} = powers;
|
|
18
|
+
const { issuerName } = options.interchainAssetOptions;
|
|
19
|
+
|
|
20
|
+
const spaKit = await startScaledPriceAuthority(powers, { options });
|
|
21
|
+
|
|
22
|
+
const label = scaledPriceFeedName(issuerName);
|
|
23
|
+
produceInstance[label].reset();
|
|
24
|
+
|
|
25
|
+
// publish into agoricNames. This must stay after registerPriceAuthority,
|
|
26
|
+
// which is called by startScaledPriceAuthority()
|
|
27
|
+
produceInstance[label].resolve(spaKit.instance);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Look up the existing assets known to auctions, and replace the corresponding
|
|
32
|
+
* scaledPriceAuthorities. The existing contracts will be left behind to be
|
|
33
|
+
* cleaned up later.
|
|
34
|
+
*
|
|
35
|
+
* @param {ChainBootstrapSpace & BootstrapPowers} powers
|
|
36
|
+
* @param {{ options: { scaledPARef: { bundleID: string } } }} options
|
|
37
|
+
*/
|
|
38
|
+
export const replaceScaledPriceAuthorities = async (powers, { options }) => {
|
|
39
|
+
trace('start');
|
|
40
|
+
const {
|
|
41
|
+
consume: {
|
|
42
|
+
agoricNamesAdmin,
|
|
43
|
+
agoricNames,
|
|
44
|
+
contractKits: contractKitsP,
|
|
45
|
+
zoe,
|
|
46
|
+
},
|
|
47
|
+
} = powers;
|
|
48
|
+
|
|
49
|
+
const { scaledPARef } = options;
|
|
50
|
+
|
|
51
|
+
const installationsAdmin = E(agoricNamesAdmin).lookupAdmin('installation');
|
|
52
|
+
const [spaInstallation, contractKits] = await Promise.all([
|
|
53
|
+
E(E(installationsAdmin).readonly()).lookup('scaledPriceAuthority'),
|
|
54
|
+
contractKitsP,
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
const bundleID = scaledPARef.bundleID;
|
|
58
|
+
if (scaledPARef && bundleID) {
|
|
59
|
+
await E.when(
|
|
60
|
+
E(zoe).installBundleID(bundleID),
|
|
61
|
+
installation =>
|
|
62
|
+
E(installationsAdmin).update('scaledPriceAuthority', installation),
|
|
63
|
+
err =>
|
|
64
|
+
console.error(
|
|
65
|
+
`🚨 failed to update scaledPriceAuthority installation`,
|
|
66
|
+
err,
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
trace('installed scaledPriceAuthority bundle', bundleID);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Ask Zoe for the installation for each kit's instance, and return all the
|
|
73
|
+
// kits where that matches the given installation.
|
|
74
|
+
async function maybeSPAKit(kit) {
|
|
75
|
+
const installation = await E(zoe).getInstallationForInstance(kit.instance);
|
|
76
|
+
return spaInstallation === installation ? [kit] : [];
|
|
77
|
+
}
|
|
78
|
+
const scaledPAKits = (
|
|
79
|
+
await Promise.all([...contractKits.values()].map(maybeSPAKit))
|
|
80
|
+
).flat();
|
|
81
|
+
|
|
82
|
+
const namedBrands = await E(E(agoricNames).lookup('brand')).entries();
|
|
83
|
+
|
|
84
|
+
for (const kitEntry of scaledPAKits) {
|
|
85
|
+
const { instance } = kitEntry;
|
|
86
|
+
const terms = await E(powers.consume.zoe).getTerms(instance);
|
|
87
|
+
const { brand } = terms.scaleIn.denominator;
|
|
88
|
+
const entry = namedBrands.find(([_k, v]) => v === brand);
|
|
89
|
+
assert(entry, 'unable to find issuerName for ', brand);
|
|
90
|
+
const issuerName = entry[0];
|
|
91
|
+
await replaceScaledPriceAuthority(powers, {
|
|
92
|
+
options: { interchainAssetOptions: { issuerName } },
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const t = 'replaceScaledPriceAuthority';
|
|
98
|
+
export const getManifestForReplaceScaledPriceAuthorities = async (
|
|
99
|
+
_ign,
|
|
100
|
+
upgradeSPAOptions,
|
|
101
|
+
) => ({
|
|
102
|
+
manifest: {
|
|
103
|
+
[replaceScaledPriceAuthorities.name]: {
|
|
104
|
+
consume: {
|
|
105
|
+
// //// Widely known ////
|
|
106
|
+
agoricNames: t,
|
|
107
|
+
priceAuthority: t,
|
|
108
|
+
startUpgradable: t,
|
|
109
|
+
zoe: t,
|
|
110
|
+
|
|
111
|
+
// //// closely held, powerful ////
|
|
112
|
+
agoricNamesAdmin: t,
|
|
113
|
+
contractKits: t,
|
|
114
|
+
priceAuthorityAdmin: t,
|
|
115
|
+
},
|
|
116
|
+
instance: {
|
|
117
|
+
// This is a right to add/replace any instance. That we update only the
|
|
118
|
+
// relevant ones must be verified by inspection.
|
|
119
|
+
produce: t,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
options: { ...upgradeSPAOptions },
|
|
124
|
+
});
|