"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const hardhat_1 = __importDefault(require("hardhat"));
const deploymentConfig_1 = require("../helpers/deploymentConfig");
const func = function ({ network, deployments, getNamedAccounts }) {
    var _a;
    return __awaiter(this, void 0, void 0, function* () {
        const networkName = network.name === "hardhat" ? "bsctestnet" : network.name;
        const { deploy } = deployments;
        const { deployer } = yield getNamedAccounts();
        const resilientOracle = yield hardhat_1.default.ethers.getContract("ResilientOracle");
        const oraclesData = yield (0, deploymentConfig_1.getOraclesData)();
        for (const asset of deploymentConfig_1.assets[networkName]) {
            const { oracle } = asset;
            console.log(`Configuring ${asset.token}`);
            yield deploy(`Mock${asset.token}`, {
                from: deployer,
                log: true,
                deterministicDeployment: false,
                args: [`Mock${asset.token}`, `Mock${asset.token}`, 18],
                autoMine: true,
                contract: "BEP20Harness",
            });
            const mock = yield hardhat_1.default.ethers.getContract(`Mock${asset.token}`);
            console.log(`Configuring resilient oracle for ${asset.token}`);
            let tx = yield resilientOracle.setTokenConfig({
                asset: mock.address,
                oracles: oraclesData[oracle].oracles,
                enableFlagsForOracles: oraclesData[oracle].enableFlagsForOracles,
            });
            yield tx.wait(1);
            console.log(`Configuring ${oracle} oracle for ${asset.token}`);
            tx = yield ((_a = oraclesData[oracle].underlyingOracle) === null || _a === void 0 ? void 0 : _a.setPrice(mock.address, asset.price));
            yield tx.wait(1);
        }
    });
};
exports.default = func;
func.tags = ["configure"];
func.skip = (env) => __awaiter(void 0, void 0, void 0, function* () { return env.network.live; });
//# sourceMappingURL=3-configure-feeds.js.map