"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseEscrowLockedBalance = exports.parseOrmlTokensAccountData = exports.ChainBalance = exports.parseEscrowPoint = exports.VotingCurrency = exports.GovernanceCurrency = exports.WrappedAmount = exports.WrappedCurrency = exports.CurrencyIdLiteral = void 0;
const monetary_js_1 = require("@interlay/monetary-js");
const utils_1 = require("../utils");
var CurrencyIdLiteral;
(function (CurrencyIdLiteral) {
    CurrencyIdLiteral["DOT"] = "DOT";
    CurrencyIdLiteral["INTERBTC"] = "IBTC";
    CurrencyIdLiteral["INTR"] = "INTR";
    CurrencyIdLiteral["KSM"] = "KSM";
    CurrencyIdLiteral["KBTC"] = "KBTC";
    CurrencyIdLiteral["KINT"] = "KINT";
})(CurrencyIdLiteral = exports.CurrencyIdLiteral || (exports.CurrencyIdLiteral = {}));
const CollateralCurrency = [monetary_js_1.Polkadot, monetary_js_1.Kusama, monetary_js_1.Interlay, monetary_js_1.Kintsugi];
exports.WrappedCurrency = [monetary_js_1.InterBtc, monetary_js_1.KBtc];
exports.WrappedAmount = [monetary_js_1.InterBtcAmount, monetary_js_1.KBtcAmount];
exports.GovernanceCurrency = [monetary_js_1.Interlay, monetary_js_1.Kintsugi];
exports.VotingCurrency = [monetary_js_1.VoteInterlay, monetary_js_1.VoteKintsugi];
function parseEscrowPoint(e) {
    return {
        bias: e.bias.toBn(),
        slope: e.slope.toBn(),
        ts: e.ts.toBn(),
    };
}
exports.parseEscrowPoint = parseEscrowPoint;
class ChainBalance {
    constructor(currency, free, transferable, reserved) {
        this.currency = currency;
        this.free = utils_1.newMonetaryAmount(free || 0, currency);
        this.transferable = utils_1.newMonetaryAmount(transferable || 0, currency);
        this.reserved = utils_1.newMonetaryAmount(reserved || 0, currency);
    }
    /*
        First stringifies the `MonetaryAmount`s, then the entire object.
        Allows for simple comparison in tests.
    */
    toString() {
        const stringifiedChainBalance = Object.fromEntries(Object.entries(this).map(([k, v]) => [k, v.toString()]));
        return JSON.stringify(stringifiedChainBalance);
    }
}
exports.ChainBalance = ChainBalance;
function parseOrmlTokensAccountData(data, currency) {
    return new ChainBalance(currency, data.free.toString(), data.free.sub(data.frozen).toString(), data.reserved.toString());
}
exports.parseOrmlTokensAccountData = parseOrmlTokensAccountData;
function parseEscrowLockedBalance(governanceCurrency, escrowLockedBalance) {
    return {
        amount: utils_1.newMonetaryAmount(escrowLockedBalance.amount.toString(), governanceCurrency),
        endBlock: escrowLockedBalance.end.toNumber(),
    };
}
exports.parseEscrowLockedBalance = parseEscrowLockedBalance;
//# sourceMappingURL=currency.js.map