"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 api_1 = require("@polkadot/api");
const monetary_js_1 = require("@interlay/monetary-js");
const chai_1 = require("chai");
const big_js_1 = __importDefault(require("big.js"));
const factory_1 = require("../../../../src/factory");
const config_1 = require("../../../config");
const src_1 = require("../../../../src");
const fee_1 = require("../../../../src/parachain/fee");
const helpers_1 = require("../../../utils/helpers");
describe("fee", () => {
    let api;
    let oracleInterBtcAPI;
    let collateralCurrencies;
    let wrappedCurrency;
    before(function () {
        return __awaiter(this, void 0, void 0, function* () {
            api = yield factory_1.createSubstrateAPI(config_1.PARACHAIN_ENDPOINT);
            const keyring = new api_1.Keyring({ type: "sr25519" });
            const oracleAccount = keyring.addFromUri(config_1.ORACLE_URI);
            oracleInterBtcAPI = new src_1.DefaultInterBtcApi(api, "regtest", oracleAccount, config_1.ESPLORA_BASE_PATH);
            collateralCurrencies =
                src_1.getCorrespondingCollateralCurrencies(oracleInterBtcAPI.getGovernanceCurrency());
            wrappedCurrency = oracleInterBtcAPI.getWrappedCurrency();
        });
    });
    after(() => __awaiter(void 0, void 0, void 0, function* () {
        api.disconnect();
    }));
    it("should check getReplaceGriefingCollateralRate", () => __awaiter(void 0, void 0, void 0, function* () {
        const replaceGriefingCollateralRate = yield oracleInterBtcAPI.fee.getReplaceGriefingCollateralRate();
        chai_1.assert.equal(replaceGriefingCollateralRate.toString(), "0.1");
    })).timeout(2000000);
    // TODO: re-enable and use mocking (see getPremiumRedeemVaults test for example)
    it.skip("should getGriefingCollateral for issue", () => __awaiter(void 0, void 0, void 0, function* () {
        for (const collateralCurrency of collateralCurrencies) {
            const exchangeRateValue = new big_js_1.default("3855.23187");
            const exchangeRate = new monetary_js_1.ExchangeRate(monetary_js_1.Bitcoin, collateralCurrency, exchangeRateValue);
            yield helpers_1.callWithExchangeRate(oracleInterBtcAPI.oracle, exchangeRate, () => __awaiter(void 0, void 0, void 0, function* () {
                const amountBtc = src_1.newMonetaryAmount(0.001, wrappedCurrency, true);
                const griefingCollateral = yield oracleInterBtcAPI.fee.getGriefingCollateral(amountBtc, fee_1.GriefingCollateralType.Issue);
                chai_1.assert.equal(griefingCollateral.toBig(griefingCollateral.currency.base).round(5, 0).toString(), "0.00001");
            }));
        }
    })).timeout(2 * 200000);
    // TODO: re-enable and use mocking (see getPremiumRedeemVaults test for example)
    it.skip("should getGriefingCollateral for replace", () => __awaiter(void 0, void 0, void 0, function* () {
        for (const collateralCurrency of collateralCurrencies) {
            const exchangeRateValue = new big_js_1.default("3855.23187");
            const exchangeRate = new monetary_js_1.ExchangeRate(monetary_js_1.Bitcoin, collateralCurrency, exchangeRateValue);
            yield helpers_1.callWithExchangeRate(oracleInterBtcAPI.oracle, exchangeRate, () => __awaiter(void 0, void 0, void 0, function* () {
                const amountToReplace = src_1.newMonetaryAmount(0.728, wrappedCurrency, true);
                const griefingCollateral = yield oracleInterBtcAPI.fee.getGriefingCollateral(amountToReplace, fee_1.GriefingCollateralType.Replace);
                chai_1.assert.equal(griefingCollateral.toString(griefingCollateral.currency.base), "16.744");
            }));
        }
    })).timeout(2 * 200000);
});
//# sourceMappingURL=fee.test.js.map