-
Notifications
You must be signed in to change notification settings - Fork 3
/
add-stATOM-oracles.js
190 lines (178 loc) · 5.7 KB
/
add-stATOM-oracles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// This is generated by writeCoreProposal; please edit!
/* eslint-disable */
const manifestBundleRef = {bundleID:"b1-0571491fc026ed1e3ed4346c0a8f6b2d818e5614b8bfe6b4ed6ce9caa5eb9729d21cd7f10f4638c9f3b07ebe8d077678afe023a9e6e4f762dd6159b076310e63"};
const getManifestCall = harden([
"getManifestForPriceFeed",
{
AGORIC_INSTANCE_NAME: "STATOM-USD price feed",
IN_BRAND_DECIMALS: 6,
IN_BRAND_LOOKUP: [
"agoricNames",
"oracleBrand",
"STATOM",
],
IN_BRAND_NAME: "STATOM",
OUT_BRAND_DECIMALS: 4,
OUT_BRAND_LOOKUP: [
"agoricNames",
"oracleBrand",
"USD",
],
OUT_BRAND_NAME: "USD",
brandInRef: undefined,
brandOutRef: undefined,
contractTerms: {
POLL_INTERVAL: 30n,
maxSubmissionCount: 1000,
maxSubmissionValue: 115792089237316195423570985008687907853269984665640564039457584007913129639936n,
minSubmissionCount: 2,
minSubmissionValue: 1n,
restartDelay: 1,
timeout: 10,
},
oracleAddresses: [
"agoric1krunjcqfrf7la48zrvdfeeqtls5r00ep68mzkr",
"agoric19uscwxdac6cf6z7d5e26e0jm0lgwstc47cpll8",
"agoric144rrhh4m09mh7aaffhm6xy223ym76gve2x7y78",
"agoric19d6gnr9fyp6hev4tlrg87zjrzsd5gzr5qlfq2p",
"agoric1n4fcxsnkxe4gj6e24naec99hzmc4pjfdccy5nj",
],
priceAggregatorRef: {
bundleID: "b1-5e23d485ee30dadc1cc78c4df6009466e710bf53d63204f99da96decc50a2997d6afc25df3c0a479e41c7ff46aaa806eb0aaf94c9509c9f4860640ce8b271774",
},
},
]);
const overrideManifest = {
createPriceFeed: {
consume: {
agoricNamesAdmin: "priceFeed",
board: "priceFeed",
chainStorage: "priceFeed",
chainTimerService: "priceFeed",
client: "priceFeed",
contractGovernor: "priceFeed",
econCharterKit: "priceFeed",
economicCommitteeCreatorFacet: "priceFeed",
highPrioritySendersManager: "priceFeed",
namesByAddressAdmin: "priceFeed",
priceAuthority: "priceFeed",
priceAuthorityAdmin: "priceFeed",
startGovernedUpgradable: "priceFeed",
},
instance: {
produce: "priceFeed",
},
},
ensureOracleBrands: {
namedVat: {
consume: {
agoricNames: "agoricNames",
},
},
oracleBrand: {
produce: "priceFeed",
},
},
};
// Make the behavior the completion value.
(({
manifestBundleRef,
getManifestCall,
overrideManifest,
E,
log = console.info,
restoreRef: overrideRestoreRef,
}) => {
const { entries, fromEntries } = Object;
// deeplyFulfilled is a bit overkill for what we need.
const shallowlyFulfilled = async obj => {
if (!obj) {
return obj;
}
const ents = await Promise.all(
entries(obj).map(async ([key, valueP]) => {
const value = await valueP;
return [key, value];
}),
);
return fromEntries(ents);
};
/** @param {ChainBootstrapSpace & BootstrapPowers & { evaluateBundleCap: any }} allPowers */
const behavior = async allPowers => {
// NOTE: If updating any of these names extracted from `allPowers`, you must
// change `permits` above to reflect their accessibility.
const {
consume: { vatAdminSvc, zoe, agoricNamesAdmin },
evaluateBundleCap,
installation: { produce: produceInstallations },
modules: {
utils: { runModuleBehaviors },
},
} = allPowers;
const [exportedGetManifest, ...manifestArgs] = getManifestCall;
/** @type {(ref: import\('./externalTypes.js').ManifestBundleRef) => Promise<Installation<unknown>>} */
const defaultRestoreRef = async ref => {
// extract-proposal.js creates these records, and bundleName is
// the name under which the bundle was installed into
// config.bundles
const p =
'bundleName' in ref
? E(vatAdminSvc).getBundleIDByName(ref.bundleName)
: ref.bundleID;
const bundleID = await p;
const label = bundleID.slice(0, 8);
return E(zoe).installBundleID(bundleID, label);
};
const restoreRef = overrideRestoreRef || defaultRestoreRef;
// Get the on-chain installation containing the manifest and behaviors.
console.info('evaluateBundleCap', {
manifestBundleRef,
exportedGetManifest,
vatAdminSvc,
});
let bcapP;
if ('bundleName' in manifestBundleRef) {
bcapP = E(vatAdminSvc).getNamedBundleCap(manifestBundleRef.bundleName);
} else {
bcapP = E(vatAdminSvc).getBundleCap(manifestBundleRef.bundleID);
}
const bundleCap = await bcapP;
const manifestNS = await evaluateBundleCap(bundleCap);
console.error('execute', {
exportedGetManifest,
behaviors: Object.keys(manifestNS),
});
const {
manifest,
options: rawOptions,
installations: rawInstallations,
} = await manifestNS[exportedGetManifest](
harden({ restoreRef }),
...manifestArgs,
);
// Await references in the options or installations.
const [options, installations] = await Promise.all(
[rawOptions, rawInstallations].map(shallowlyFulfilled),
);
// Publish the installations for behavior dependencies.
const installAdmin = E(agoricNamesAdmin).lookupAdmin('installation');
await Promise.all(
entries(installations || {}).map(([key, value]) => {
produceInstallations[key].resolve(value);
return E(installAdmin).update(key, value);
}),
);
// Evaluate the manifest for our behaviors.
return runModuleBehaviors({
allPowers,
behaviors: manifestNS,
manifest: overrideManifest || manifest,
makeConfig: (name, _permit) => {
log('coreProposal:', name);
return { options };
},
});
};
// Make the behavior the completion value.
return behavior;
})({ manifestBundleRef, getManifestCall, overrideManifest, E });