"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getVariableDebtToken = exports.getWETHGateway = exports.getIncentivesController = exports.getLendingPoolAddressesProvider = exports.getLendingPoolConfiguratorProxy = exports.getIErc20 = exports.getAToken = exports.getAaveProtocolDataProvider = exports.getMintableERC20 = exports.getLendingPool = exports.getIErc20Detailed = exports.getProvider = void 0;
const ethers_1 = require("ethers");
const constants_1 = require("./constants");
const AaveProtocolDataProvider_json_1 = __importDefault(require("./artifacts/contracts/misc/AaveProtocolDataProvider.sol/AaveProtocolDataProvider.json"));
const IERC20_json_1 = __importDefault(require("./artifacts/contracts/dependencies/openzeppelin/contracts/IERC20.sol/IERC20.json"));
const IAToken_json_1 = __importDefault(require("./artifacts/contracts/interfaces/IAToken.sol/IAToken.json"));
const ILendingPool_json_1 = __importDefault(require("./artifacts/contracts/interfaces/ILendingPool.sol/ILendingPool.json"));
const LendingPoolConfigurator_json_1 = __importDefault(require("./artifacts/contracts/protocol/lendingpool/LendingPoolConfigurator.sol/LendingPoolConfigurator.json"));
const ILendingPoolAddressesProvider_json_1 = __importDefault(require("./artifacts/contracts/interfaces/ILendingPoolAddressesProvider.sol/ILendingPoolAddressesProvider.json"));
const WETHGateway_json_1 = __importDefault(require("./artifacts/contracts/misc/WETHGateway.sol/WETHGateway.json"));
const IncentivesController_json_1 = __importDefault(require("./artifacts/contracts/protocol/incentives/IncentivesController.sol/IncentivesController.json"));
const IERC20Detailed_json_1 = __importDefault(require("./artifacts/contracts/dependencies/openzeppelin/contracts/IERC20Detailed.sol/IERC20Detailed.json"));
const MintableERC20_json_1 = __importDefault(require("./artifacts/contracts/mocks/tokens/MintableERC20.sol/MintableERC20.json"));
const VariableDebtToken_json_1 = __importDefault(require("./artifacts/contracts/protocol/tokenization/VariableDebtToken.sol/VariableDebtToken.json"));
function getProvider(providerRpc, test) {
    return providerRpc
        ? ethers_1.ethers.getDefaultProvider(providerRpc)
        : test || test === undefined
            ? ethers_1.ethers.getDefaultProvider("http://0.0.0.0:8545") : null;
}
exports.getProvider = getProvider;
exports.getIErc20Detailed = async (address, providerRpc, test) => new ethers_1.ethers.Contract(address, IERC20Detailed_json_1.default.abi, getProvider(providerRpc, test));
/**
 * getLendingPool
 * Gets the lending pool contract, connect a signer if given one
 */
async function getLendingPool(params) {
    let lendingPool = new ethers_1.ethers.Contract(constants_1.deployments.LendingPool[`${params && params.network ? params.network : "mainnet"}`].address, ILendingPool_json_1.default.abi, getProvider(params.providerRpc, params.test));
    if (params.signer)
        return lendingPool.connect(params.signer);
    return lendingPool;
}
exports.getLendingPool = getLendingPool;
async function getMintableERC20(params) {
    let token = new ethers_1.ethers.Contract(constants_1.deployments[params.tokenSymbol.toUpperCase()][`${params && params.network ? params.network : "mainnet"}`].address, MintableERC20_json_1.default.abi, getProvider(params.providerRpc, params.test));
    if (params.signer)
        return token.connect(params.signer);
    return token;
}
exports.getMintableERC20 = getMintableERC20;
async function getAaveProtocolDataProvider(params) {
    let helperContract = new ethers_1.ethers.Contract(constants_1.deployments.AaveProtocolDataProvider[`${params.network || "mainnet"}`].address, AaveProtocolDataProvider_json_1.default.abi, getProvider(params.providerRpc, params.test));
    if (params.signer)
        return helperContract.connect(params.signer);
    return helperContract;
}
exports.getAaveProtocolDataProvider = getAaveProtocolDataProvider;
async function getAToken(params) {
    let aToken = new ethers_1.ethers.Contract(params.address, IAToken_json_1.default.abi, getProvider(params.providerRpc, params.test));
    if (params.signer)
        return aToken.connect(params.signer);
    return aToken;
}
exports.getAToken = getAToken;
async function getIErc20(params) {
    let ercToken = new ethers_1.ethers.Contract(params.address, IERC20_json_1.default.abi, getProvider(params.providerRpc, params.test));
    if (params.signer)
        return ercToken.connect(params.signer);
    return ercToken;
}
exports.getIErc20 = getIErc20;
async function getLendingPoolConfiguratorProxy(params) {
    let configurator = new ethers_1.ethers.Contract(constants_1.deployments.LendingPoolConfigurator[`${params && params.network ? params.network : "mainnet"}`].address, LendingPoolConfigurator_json_1.default.abi, getProvider(params.providerRpc, params.test));
    if (params.signer)
        return configurator.connect(params.signer);
    return configurator;
}
exports.getLendingPoolConfiguratorProxy = getLendingPoolConfiguratorProxy;
async function getLendingPoolAddressesProvider(params) {
    let addressProvider = new ethers_1.ethers.Contract(constants_1.deployments.LendingPoolAddressesProvider[`${params.network || "mainnet"}`].address, ILendingPoolAddressesProvider_json_1.default.abi, getProvider(params.providerRpc, params.test));
    if (params.signer)
        return addressProvider.connect(params.signer);
    return addressProvider;
}
exports.getLendingPoolAddressesProvider = getLendingPoolAddressesProvider;
async function getIncentivesController(params) {
    let incentivesController = new ethers_1.ethers.Contract(constants_1.deployments.IncentivesControllerProxy[`${params.network || "mainnet"}`].address, IncentivesController_json_1.default.abi, getProvider(params.providerRpc, params.test));
    if (params.signer)
        return incentivesController.connect(params.signer);
    return incentivesController;
}
exports.getIncentivesController = getIncentivesController;
/**
 * getWETHGateway
 * Gets the weth gateway contract, connect a signer if given one
 */
async function getWETHGateway(params) {
    let gateway = new ethers_1.ethers.Contract(constants_1.deployments.WETHGateway[`${params && params.network ? params.network : "mainnet"}`].address, WETHGateway_json_1.default.abi, getProvider(params.providerRpc, params.test));
    if (params.signer)
        return gateway.connect(params.signer);
    return gateway;
}
exports.getWETHGateway = getWETHGateway;
async function getVariableDebtToken(params) {
    let token = new ethers_1.ethers.Contract(params.address || constants_1.deployments.VariableDebtToken[`${params && params.network ? params.network : "mainnet"}`].address, VariableDebtToken_json_1.default.abi, getProvider(params.providerRpc, params.test));
    if (params.signer)
        return token.connect(params.signer);
    return token;
}
exports.getVariableDebtToken = getVariableDebtToken;
//# sourceMappingURL=contract-getters.js.map