-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetOraclePrice.js
More file actions
53 lines (43 loc) · 1.68 KB
/
setOraclePrice.js
File metadata and controls
53 lines (43 loc) · 1.68 KB
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
const { PriceOracle__factory } = require("@firefly-exchange/library/dist/src/contracts/exchange");
const { ethers, toBigNumberStr, BigNumber } = require("@firefly-exchange/library");
const environment = require("./environments.json");
require('dotenv').config();
env = environment[process.env.env]
market = process.env.market;
console.log("Env:", process.env.env);
console.log("Market:", market);
const providerURL = env["URL"];
const operatorKey = env["ORACLE_OPERATOR"]
const priceOracleAddress = env[market]["PriceOracle"]
const provider = new ethers.providers.JsonRpcProvider(providerURL);
const operatorWallet = new ethers.Wallet(operatorKey, provider);
async function main(price){
const contract = PriceOracle__factory.connect(priceOracleAddress, operatorWallet);
const data = await contract.getPrice(market);
console.log(`Current price: (${BigNumber(data[0].toHexString()).shiftedBy(-18).toFixed(6)},${BigNumber(data[0].toHexString()).toFixed(0)}) set at timestamp: ${+data[1]}`);
console.log(`Setting Price: ${price}, - ${toBigNumberStr(price)}`);
let i = 1;
while(true){
console.log("Try #", i++)
try{
await (await contract.setPrice(
market,
toBigNumberStr(price),
Math.ceil(Date.now()/1000),
// { gasLimit: 1_000_000 }
)
).wait();
break;
} catch(e){
console.log(e);
continue;
}
}
}
if(require.main === module){
if(process.argv.length != 3){
console.error(`Provide price to be set e.g. "yarn setPrice <price>" e.g yarn setPrice 20000`);
process.exit(1);
};
main(Number(process.argv[2]));
}