-
Notifications
You must be signed in to change notification settings - Fork 5
/
curve.js
59 lines (46 loc) · 1.42 KB
/
curve.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
"use strict";
const eventBus = require('ocore/event_bus.js');
const conf = require('ocore/conf.js');
const dag = require('aabot/dag.js');
const aa_state = require('aabot/aa_state.js');
const light_data_feeds = conf.bLight ? require('aabot/light_data_feeds.js') : null;
const ORACLE_UPDATE_INTERVAL = 2 * 60 * 1000;
let curves = {};
class CurveAA {
#curve_aa;
#params;
#oracles;
constructor(curve_aa, params, oracles) {
this.#curve_aa = curve_aa;
this.#params = params;
this.#oracles = oracles;
setInterval(() => this.updateDataFeeds(), ORACLE_UPDATE_INTERVAL);
}
static async create(curve_aa) {
if (curves[curve_aa])
return curves[curve_aa];
const params = await dag.readAAParams(curve_aa);
const oracles = await dag.executeGetter(curve_aa, 'get_oracles');
if (conf.bLight)
for (let oracle of oracles)
await light_data_feeds.updateDataFeed(oracle.oracle, oracle.feed_name);
await aa_state.followAA(curve_aa);
const curve = new CurveAA(curve_aa, params, oracles);
curves[curve_aa] = curve;
return curve;
}
static get(curve_aa) {
return curves[curve_aa];
}
async updateDataFeeds(bForce, bQuiet) {
if (!conf.bLight)
return;
let bUpdated = false;
for (let oracle of this.#oracles)
if (await light_data_feeds.updateDataFeed(oracle.oracle, oracle.feed_name, bForce))
bUpdated = true;
if (bUpdated && !bQuiet)
eventBus.emit('data_feeds_updated');
}
}
module.exports = CurveAA;