"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.AppToolkit = void 0;
const common_1 = require("@nestjs/common");
const bignumber_js_1 = require("bignumber.js");
const ethers_1 = require("ethers");
const app_service_1 = require("../app/app.service");
const _contract_1 = require("../contract");
const multicall_service_1 = require("../multicall/multicall.service");
const network_provider_service_1 = require("../network-provider/network-provider.service");
const position_key_service_1 = require("../position/position-key.service");
const position_service_1 = require("../position/position.service");
const token_dependency_selector_service_1 = require("../position/selectors/token-dependency-selector.service");
const token_price_selector_service_1 = require("../token/selectors/token-price-selector.service");
let AppToolkit = class AppToolkit {
    constructor(appService, networkProviderService, positionService, positionKeyService, priceSelectorService, tokenDependencySelectorService, multicallService, cacheManager) {
        this.appService = appService;
        this.networkProviderService = networkProviderService;
        this.positionService = positionService;
        this.positionKeyService = positionKeyService;
        this.priceSelectorService = priceSelectorService;
        this.tokenDependencySelectorService = tokenDependencySelectorService;
        this.multicallService = multicallService;
        this.cacheManager = cacheManager;
        this.contractFactory = new _contract_1.ContractFactory((network) => this.networkProviderService.getProvider(network));
    }
    get globalContracts() {
        return this.contractFactory;
    }
    getNetworkProvider(network) {
        return this.networkProviderService.getProvider(network);
    }
    getMulticall(network) {
        return this.multicallService.getMulticall(network);
    }
    getBaseTokenPrices(network) {
        return this.priceSelectorService.create().getAll({ network });
    }
    getBaseTokenPrice(opts) {
        return this.priceSelectorService.create().getOne(opts);
    }
    getAppTokenPositions(...appTokenDefinitions) {
        return this.positionService.getAppTokenPositions(...appTokenDefinitions);
    }
    getAppTokenPositionsFromDatabase(...appTokenDefinitions) {
        return this.positionService.getAppTokenPositions(...appTokenDefinitions);
    }
    getAppContractPositions(...appTokenDefinitions) {
        return this.positionService.getAppContractPositions(...appTokenDefinitions);
    }
    getTokenDependencySelector(opts = {}) {
        return this.tokenDependencySelectorService.create(opts);
    }
    getPositionKey(position) {
        return this.positionKeyService.getPositionKey(position);
    }
    getFromCache(key) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.cacheManager.get(key);
        });
    }
    setManyToCache(entries, ttl = 60) {
        return __awaiter(this, void 0, void 0, function* () {
            yield Promise.all(entries.map(([key, value]) => this.cacheManager.set(key, value, { ttl })));
        });
    }
    getBigNumber(source) {
        if (source instanceof ethers_1.ethers.BigNumber)
            return new bignumber_js_1.BigNumber(source.toString());
        return new bignumber_js_1.BigNumber(source);
    }
};
AppToolkit = __decorate([
    (0, common_1.Injectable)(),
    __param(0, (0, common_1.Inject)(app_service_1.AppService)),
    __param(1, (0, common_1.Inject)(network_provider_service_1.NetworkProviderService)),
    __param(2, (0, common_1.Inject)(position_service_1.PositionService)),
    __param(3, (0, common_1.Inject)(position_key_service_1.PositionKeyService)),
    __param(4, (0, common_1.Inject)(token_price_selector_service_1.PriceSelectorService)),
    __param(5, (0, common_1.Inject)(token_dependency_selector_service_1.TokenDependencySelectorService)),
    __param(6, (0, common_1.Inject)(multicall_service_1.MulticallService)),
    __param(7, (0, common_1.Inject)(common_1.CACHE_MANAGER)),
    __metadata("design:paramtypes", [app_service_1.AppService,
        network_provider_service_1.NetworkProviderService,
        position_service_1.PositionService,
        position_key_service_1.PositionKeyService,
        token_price_selector_service_1.PriceSelectorService,
        token_dependency_selector_service_1.TokenDependencySelectorService,
        multicall_service_1.MulticallService, Object])
], AppToolkit);
exports.AppToolkit = AppToolkit;
//# sourceMappingURL=app-toolkit.service.js.map