"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultInterBtcApi = exports.getBitcoinNetwork = void 0;
const electrs_1 = require("./external/electrs");
const nomination_1 = require("./parachain/nomination");
const issue_1 = require("./parachain/issue");
const oracle_1 = require("./parachain/oracle");
const redeem_1 = require("./parachain/redeem");
const fee_1 = require("./parachain/fee");
const vaults_1 = require("./parachain/vaults");
const system_1 = require("./parachain/system");
const tokens_1 = require("./parachain/tokens");
const clients_1 = require("./clients");
const btc_relay_1 = require("./parachain/btc-relay");
const replace_1 = require("./parachain/replace");
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
const rewards_1 = require("./parachain/rewards");
const transaction_1 = require("./parachain/transaction");
const _1 = require(".");
__exportStar(require("./factory"), exports);
__exportStar(require("./parachain/transaction"), exports);
function getBitcoinNetwork(network = "mainnet") {
    switch (network) {
        case "mainnet":
            return bitcoinjs_lib_1.networks.bitcoin;
        case "testnet":
            return bitcoinjs_lib_1.networks.testnet;
        default:
            return bitcoinjs_lib_1.networks.regtest;
    }
}
exports.getBitcoinNetwork = getBitcoinNetwork;
/**
 * @category BTC Bridge
 */
class DefaultInterBtcApi {
    constructor(api, bitcoinNetwork = "mainnet", _account, esploraNetwork) {
        this.api = api;
        const wrappedCurrency = this.getWrappedCurrency();
        const governanceCurrency = this.getGovernanceCurrency();
        const btcNetwork = getBitcoinNetwork(bitcoinNetwork);
        this.electrsAPI = new electrs_1.DefaultElectrsAPI(esploraNetwork || bitcoinNetwork);
        this.transactionAPI = new transaction_1.DefaultTransactionAPI(api, _account);
        this.assetRegistry = new _1.DefaultAssetRegistryAPI(api);
        this.tokens = new tokens_1.DefaultTokensAPI(api, this.transactionAPI);
        this.system = new system_1.DefaultSystemAPI(api, this.transactionAPI);
        this.oracle = new oracle_1.DefaultOracleAPI(api, wrappedCurrency, this.transactionAPI);
        this.fee = new fee_1.DefaultFeeAPI(api, this.oracle, this.assetRegistry);
        this.rewards = new rewards_1.DefaultRewardsAPI(api, wrappedCurrency, this.transactionAPI, this.assetRegistry);
        this.escrow = new _1.DefaultEscrowAPI(api, governanceCurrency, this.system, this.transactionAPI);
        this.vaults = new vaults_1.DefaultVaultsAPI(api, this.electrsAPI, wrappedCurrency, governanceCurrency, this.tokens, this.oracle, this.fee, this.rewards, this.system, this.transactionAPI, this.assetRegistry);
        this.faucet = new clients_1.FaucetClient(api, "");
        this.btcRelay = new btc_relay_1.DefaultBTCRelayAPI(api, this.electrsAPI);
        this.replace = new replace_1.DefaultReplaceAPI(api, btcNetwork, this.electrsAPI, wrappedCurrency, this.fee, this.transactionAPI, this.assetRegistry);
        this.issue = new issue_1.DefaultIssueAPI(api, btcNetwork, this.electrsAPI, wrappedCurrency, this.fee, this.vaults, this.transactionAPI, this.assetRegistry);
        this.redeem = new redeem_1.DefaultRedeemAPI(api, btcNetwork, this.electrsAPI, wrappedCurrency, this.vaults, this.oracle, this.transactionAPI, this.assetRegistry, this.system);
        this.nomination = new nomination_1.DefaultNominationAPI(api, wrappedCurrency, this.vaults, this.rewards, this.transactionAPI, this.assetRegistry);
    }
    setAccount(account, signer) {
        if (!account.sign && !signer) {
            throw new Error("signer must be passed if account is not a Keypair");
        }
        if (signer) {
            this.api.setSigner(signer);
        }
        this.transactionAPI.setAccount(account);
    }
    removeAccount() {
        this.transactionAPI.removeAccount();
    }
    get account() {
        return this.transactionAPI.getAccount();
    }
    getGovernanceCurrency() {
        const currencyId = this.api.consts.escrowRewards.getNativeCurrencyId;
        // beware: this call will throw if the native currency is not a token!
        return _1.tokenSymbolToCurrency(currencyId.asToken);
    }
    getWrappedCurrency() {
        const currencyId = this.api.consts.escrowRewards.getWrappedCurrencyId;
        // beware: this call will throw if the wrapped currency is not a token!
        return _1.tokenSymbolToCurrency(currencyId.asToken);
    }
}
exports.DefaultInterBtcApi = DefaultInterBtcApi;
//# sourceMappingURL=interbtc-api.js.map