"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const token_math_1 = require("@melonproject/token-math");
const initTestEnvironment_1 = require("../utils/initTestEnvironment");
const deployKyberEnvironment_1 = require("../../contracts/exchanges/transactions/deployKyberEnvironment");
const getContract_1 = require("../../utils/solidity/getContract");
const getToken_1 = require("../../contracts/dependencies/token/calls/getToken");
const deploy_1 = require("../../contracts/dependencies/token/transactions/deploy");
const deployKyberPriceFeed_1 = require("../../contracts/prices/transactions/deployKyberPriceFeed");
const isAddress_1 = require("../../utils/checks/isAddress");
const hasValidPrice_1 = require("../../contracts/prices/calls/hasValidPrice");
const getPrice_1 = require("../../contracts/prices/calls/getPrice");
const updateKyber_1 = require("../../contracts/prices/transactions/updateKyber");
const Contracts_1 = require("../../Contracts");
const deployContract_1 = require("../../utils/solidity/deployContract");
describe('kyber-price-feed', () => {
    const shared = {};
    beforeAll(() => __awaiter(this, void 0, void 0, function* () {
        shared.env = yield initTestEnvironment_1.initTestEnvironment();
        shared.tokens = {
            eur: yield getToken_1.getToken(shared.env, yield deploy_1.deployToken(shared.env, 'EUR')),
            mln: yield getToken_1.getToken(shared.env, yield deploy_1.deployToken(shared.env, 'MLN')),
            weth: yield getToken_1.getToken(shared.env, yield deploy_1.deployToken(shared.env, 'WETH')),
        };
        shared.kyberDeploy = yield deployKyberEnvironment_1.deployKyberEnvironment(shared.env, [
            shared.tokens.mln,
            shared.tokens.eur,
        ]);
        shared.mockRegistryAddress = yield deployContract_1.deployContract(shared.env, Contracts_1.Contracts.MockRegistry);
        shared.mockRegistry = yield getContract_1.getContract(shared.env, Contracts_1.Contracts.MockRegistry, `${shared.mockRegistryAddress}`);
        yield shared.mockRegistry.methods
            .setNativeAsset(shared.tokens.weth.address.toString())
            .send({ from: `${shared.env.wallet.address}` });
        for (const token of Object.values(shared.tokens)) {
            yield shared.mockRegistry.methods
                .register(`${token['address']}`)
                .send({ from: `${shared.env.wallet.address}` });
        }
    }));
    it('Deploy kyber pricefeed', () => __awaiter(this, void 0, void 0, function* () {
        shared.kyberPriceFeed = yield deployKyberPriceFeed_1.deployKyberPriceFeed(shared.env, {
            kyberNetworkProxy: shared.kyberDeploy.kyberNetworkProxy,
            quoteToken: shared.tokens.weth,
            registry: shared.mockRegistryAddress,
        });
        expect(isAddress_1.isAddress(shared.kyberPriceFeed));
    }));
    // it('Update kyber feed', async () => {
    //   expect();
    // });
    it('Get price', () => __awaiter(this, void 0, void 0, function* () {
        yield updateKyber_1.updateKyber(shared.env, shared.kyberPriceFeed);
        const hasValidMlnPrice = yield hasValidPrice_1.hasValidPrice(shared.env, shared.kyberPriceFeed, shared.tokens.mln);
        expect(hasValidMlnPrice).toBe(true);
        const mlnPrice = yield getPrice_1.getPrice(shared.env, shared.kyberPriceFeed, shared.tokens.mln);
        expect(token_math_1.toFixed(mlnPrice)).toBe('1.000000');
    }));
});
