import { Contract } from "ethers";
import AuthoritiesRegistryABI from "../../abis/AuthoritiesRegistry";
import CompoundMarketERC4626ABI from "../../abis/CompoundMarketERC4626";
import FlywheelStaticRewardsABI from "../../abis/FlywheelStaticRewards";
import ICErc20ABI from "../../abis/ICErc20";
import ICErc20PluginRewardsABI from "../../abis/ICErc20PluginRewards";
import ILeveredPositionFactoryABI from "../../abis/ILeveredPositionFactory";
import ILiquidatorsRegistryABI from "../../abis/ILiquidatorsRegistry";
import IonicComptrollerABI from "../../abis/IonicComptroller";
import IonicFlywheelABI from "../../abis/IonicFlywheel";
import IonicFlywheelLensRouterABI from "../../abis/IonicFlywheelLensRouter";
import JumpRateModelABI from "../../abis/JumpRateModel";
import LeveredPositionABI from "../../abis/LeveredPosition";
import LeveredPositionsLensABI from "../../abis/LeveredPositionsLens";
import MasterPriceOracleABI from "../../abis/MasterPriceOracle";
import OptimizedAPRVaultFirstExtensionABI from "../../abis/OptimizedAPRVaultFirstExtension";
import OptimizedAPRVaultSecondExtensionABI from "../../abis/OptimizedAPRVaultSecondExtension";
import OptimizedVaultsRegistryABI from "../../abis/OptimizedVaultsRegistry";
import PoolLensSecondaryABI from "../../abis/PoolLensSecondary";
import PoolRolesAuthorityABI from "../../abis/PoolRolesAuthority";
import UnitrollerABI from "../../abis/Unitroller";
export function withCreateContracts(Base) {
    return class CreateContracts extends Base {
        constructor() {
            super(...arguments);
            this.createUnitroller = this.createContractInstance(UnitrollerABI);
            this.createIonicFlywheel = this.createContractInstance(IonicFlywheelABI);
            this.createFlywheelStaticRewards = this.createContractInstance(FlywheelStaticRewardsABI);
            this.createJumpRateModel = this.createContractInstance(JumpRateModelABI);
        }
        createContractInstance(abi) {
            return (address, signerOrProvider = this.signer) => new Contract(address, abi, signerOrProvider);
        }
        createComptroller(comptrollerAddress, signerOrProvider = this.provider) {
            if (this.chainDeployment.ComptrollerFirstExtension) {
                return new Contract(comptrollerAddress, [...IonicComptrollerABI], signerOrProvider);
            }
            return new Contract(comptrollerAddress, IonicComptrollerABI, signerOrProvider);
        }
        createICErc20(address, signerOrProvider = this.provider) {
            return new Contract(address, ICErc20ABI, signerOrProvider);
        }
        createICErc20PluginRewards(cTokenAddress, signerOrProvider = this.provider) {
            return new Contract(cTokenAddress, ICErc20PluginRewardsABI, signerOrProvider);
        }
        createMasterPriceOracle(signerOrProvider = this.provider) {
            return new Contract(this.chainDeployment.MasterPriceOracle.address, MasterPriceOracleABI, signerOrProvider);
        }
        createCompoundMarketERC4626(address, signerOrProvider = this.provider) {
            return new Contract(address, CompoundMarketERC4626ABI, signerOrProvider);
        }
        createOptimizedAPRVault(address, signerOrProvider = this.provider) {
            return new Contract(address, [...OptimizedAPRVaultFirstExtensionABI, ...OptimizedAPRVaultSecondExtensionABI], signerOrProvider);
        }
        createOptimizedVaultsRegistry(signerOrProvider = this.provider) {
            return new Contract(this.chainDeployment.OptimizedVaultsRegistry.address, OptimizedVaultsRegistryABI, signerOrProvider);
        }
        createIonicFlywheelLensRouter(signerOrProvider = this.provider) {
            return new Contract(this.chainDeployment.IonicFlywheelLensRouter.address, IonicFlywheelLensRouterABI, signerOrProvider);
        }
        createLeveredPositionFactory(signerOrProvider = this.provider) {
            return new Contract(this.chainDeployment.LeveredPositionFactory.address, ILeveredPositionFactoryABI, signerOrProvider);
        }
        createLeveredPosition(address, signerOrProvider = this.provider) {
            return new Contract(address, LeveredPositionABI, signerOrProvider);
        }
        createLeveredPositionLens(signerOrProvider = this.provider) {
            return new Contract(this.chainDeployment.LeveredPositionsLens.address, LeveredPositionsLensABI, signerOrProvider);
        }
        createPoolLensSecondary(signerOrProvider = this.provider) {
            return new Contract(this.chainDeployment.PoolLensSecondary.address, PoolLensSecondaryABI, signerOrProvider);
        }
        createILiquidatorsRegistry(signerOrProvider = this.provider) {
            return new Contract(this.chainDeployment.LiquidatorsRegistry.address, ILiquidatorsRegistryABI, signerOrProvider);
        }
        createAuthoritiesRegistry(signerOrProvider = this.provider) {
            return new Contract(this.chainDeployment.AuthoritiesRegistry.address, AuthoritiesRegistryABI, signerOrProvider);
        }
        createPoolRolesAuthority(poolAuthAddress, signerOrProvider = this.provider) {
            return new Contract(poolAuthAddress, PoolRolesAuthorityABI, signerOrProvider);
        }
    };
}
