"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BinanceSmartChainMidasMarketTokenFetcher = void 0;
const common_1 = require("@nestjs/common");
const app_toolkit_interface_1 = require("../../../app-toolkit/app-toolkit.interface");
const position_template_decorator_1 = require("../../../app-toolkit/decorators/position-template.decorator");
const midas_market_token_fetcher_1 = require("../common/midas.market.token-fetcher");
const contracts_1 = require("../contracts");
let BinanceSmartChainMidasMarketTokenFetcher = class BinanceSmartChainMidasMarketTokenFetcher extends midas_market_token_fetcher_1.MidasMarketTokenFetcher {
    constructor(appToolkit, midasContractFactory) {
        super(appToolkit);
        this.appToolkit = appToolkit;
        this.midasContractFactory = midasContractFactory;
        this.groupLabel = 'Lending';
        this.poolDirectoryAddress = '0x295d7347606f4bd810c8296bb8d75d657001fcf7';
        this.poolLensAddress = '0x6f4e0b5405f3751f7327cf8095004c34fc307f55';
    }
    getPoolDirectoryContract(address) {
        return this.midasContractFactory.midasPoolDirectory({ address, network: this.network });
    }
    getCTokenContract(address) {
        return this.midasContractFactory.midasCErc20Token({ address, network: this.network });
    }
    getPoolLensContract(address) {
        return this.midasContractFactory.midasPoolLens({ address, network: this.network });
    }
    getPools(contract) {
        return contract.callStatic.getActivePools();
    }
    getPool(contract, poolId) {
        return contract.callStatic.pools(poolId);
    }
    getMarketTokenAddresses(contract, poolAddress) {
        return __awaiter(this, void 0, void 0, function* () {
            const assets = yield contract.callStatic.getPoolAssetsWithData(poolAddress);
            return assets.map(asset => asset.cToken);
        });
    }
    getUnderlyingTokenAddress(contract) {
        return contract.underlying();
    }
    getExchangeRateCurrent(contract) {
        return contract.callStatic.exchangeRateCurrent();
    }
    getSupplyRateRaw(contract) {
        return contract.supplyRatePerBlock();
    }
};
BinanceSmartChainMidasMarketTokenFetcher = __decorate([
    (0, position_template_decorator_1.PositionTemplate)(),
    __param(0, (0, common_1.Inject)(app_toolkit_interface_1.APP_TOOLKIT)),
    __param(1, (0, common_1.Inject)(contracts_1.MidasContractFactory)),
    __metadata("design:paramtypes", [Object, contracts_1.MidasContractFactory])
], BinanceSmartChainMidasMarketTokenFetcher);
exports.BinanceSmartChainMidasMarketTokenFetcher = BinanceSmartChainMidasMarketTokenFetcher;
//# sourceMappingURL=midas.market.token-fetcher.js.map