forked from cmadh/wax-delphioracle
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
25 lines (20 loc) · 915 Bytes
/
index.ts
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
import { CronJob } from "cron"
import { get_price } from "./plugins/price"
import { Quote, write } from "./plugins/delphioracle"
import { transact } from "./src/utils";
import { api, CRON_INTERVAL, ACCOUNT, AUTHORIZATION } from "./src/config";
console.log(`Starting cron job with interval ${CRON_INTERVAL}`);
new CronJob(CRON_INTERVAL, async () => {
const usd = await get_price("WAXP-USD");
const usdcusd = await get_price("USDC-USD");
const usdtusd = await get_price("USDT-USD");
const quotes: Quote[] = [
{ pair: "waxpusd", value: to_uint(usd, 4)},
{ pair: "usdcusd", value: to_uint(usdcusd, 4)},
{ pair: "usdtusd", value: to_uint(usdtusd, 4)}
]
await transact( api, [ write( ACCOUNT, quotes, [ AUTHORIZATION ] )]);
}, null, true).fireOnTick();
function to_uint( num: string | number, exp: number ) {
return Number((Number(num) * 10 ** exp).toFixed(0));
}