"use strict";
/**
 * @file Sumer
 * @desc This file defines the constructor of the `Sumer` class.
 * @hidden
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
const ethers_1 = require("ethers");
const eth = __importStar(require("./eth"));
const util = __importStar(require("./util"));
const comptroller = __importStar(require("./comptroller"));
const cToken = __importStar(require("./cToken"));
const errorABIs_1 = require("./errorABIs");
// import * as comp from './comp'
// import * as gov from './gov'
const abi_1 = require("./abi");
const constants_1 = require("./constants");
// Turn off Ethers.js warnings
// ethers.utils.Logger.setLogLevel(ethers.utils.Logger.levels.ERROR)
/**
 * Creates an instance of the Sumer.js SDK.
 *
 * @param {Provider | string} [provider] Optional Ethereum network provider.
 *     Defaults to Ethers.js fallback mainnet provider.
 * @param {object} [options] Optional provider options.
 *
 * @example
 * ```
 * var sumer = new Sumer(window.ethereum); // web browser
 *
 * var sumer = new Sumer('http://127.0.0.1:8545'); // HTTP provider
 *
 * var sumer = new Sumer(); // Uses Ethers.js fallback mainnet (for testing only)
 *
 * var sumer = new Sumer('ropsten'); // Uses Ethers.js fallback (for testing only)
 *
 * // Init with private key (server side)
 * var sumer = new Sumer('https://mainnet.infura.io/v3/_your_project_id_', {
 *   privateKey: '0x_your_private_key_', // preferably with environment variable
 * });
 *
 * // Init with HD mnemonic (server side)
 * var sumer = new Sumer('mainnet' {
 *   mnemonic: 'clutch captain shoe...', // preferably with environment variable
 * });
 * ```
 *
 * @returns {object} Returns an instance of the Sumer.js SDK.
 */
const Sumer = function (provider = 'mainnet', options = {}) {
    const originalProvider = provider;
    options.provider = provider || options.provider;
    provider = eth._createProvider(options);
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const instance = Object.assign(Object.assign(Object.assign({ _originalProvider: originalProvider, _provider: provider }, comptroller), cToken), { 
        // ...gov,
        // claimComp: comp.claimComp,
        // delegate: comp.delegate,
        // delegateBySig: comp.delegateBySig,
        // createDelegateSignature: comp.createDelegateSignature,
        _network: {
            id: options.networkId,
            name: options.networkName,
        }, getTokenPairBySymbol: (symbol) => {
            return (0, constants_1.getTokenPairBySymbol)(options.networkName, symbol);
        }, getTokenPairByAddress: (tokenAddress) => {
            return (0, constants_1.getTokenPairBySymbol)(options.networkName, tokenAddress);
        }, getTokenPairsByGroupId: (assetGroupId) => {
            return (0, constants_1.getTokenPairsByGroupId)(options.networkName, assetGroupId);
        } });
    // Instance needs to know which network the provider connects to, so it can
    //     use the correct contract addresses.
    // instance._networkPromise = eth.getProviderNetwork(provider).then((network) => {
    //   delete instance._networkPromise
    //   instance._network = network
    // })
    return instance;
};
Sumer.eth = eth;
Sumer.util = util;
Sumer._ethers = ethers_1.ethers;
Sumer.abi = abi_1.abi;
Sumer.errorABIs = errorABIs_1.errorABIs;
Sumer.getDecimals = constants_1.getDecimals;
Sumer.getAddress = constants_1.getAddress;
Sumer.getName = constants_1.getName;
Sumer.getTokenPairs = constants_1.getTokenPairs;
Sumer.getNetworkBlocksPerYear = constants_1.getNetworkBlocksPerYear;
Sumer.getRateModals = constants_1.getRateModals;
Sumer.getTokenPairByAddress = constants_1.getTokenPairByAddress;
Sumer.getTokenPairBySymbol = constants_1.getTokenPairBySymbol;
Sumer.getTokenPairsByGroupId = constants_1.getTokenPairsByGroupId;
Sumer.isUnderlyAllowed = constants_1.isUnderlyAllowed;
Sumer.isCTokenAllowed = constants_1.isCTokenAllowed;
Sumer.isEther = constants_1.isEther;
// Sumer.comp = {
//   getCompBalance: comp.getCompBalance,
//   getCompAccrued: comp.getCompAccrued,
// }
Object.assign(Sumer, constants_1.constants);
module.exports = Sumer;
//# sourceMappingURL=index.js.map