"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.ArbitrumDolomitePoolsTokenFetcher = 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 display_item_present_1 = require("../../../app-toolkit/helpers/presentation/display-item.present");
const image_present_1 = require("../../../app-toolkit/helpers/presentation/image.present");
const uniswap_v2_pool_on_chain_template_token_fetcher_1 = require("../../../apps/uniswap-v2/common/uniswap-v2.pool.on-chain.template.token-fetcher");
const utils_1 = require("../common/utils");
const contracts_1 = require("../contracts");
let ArbitrumDolomitePoolsTokenFetcher = class ArbitrumDolomitePoolsTokenFetcher extends uniswap_v2_pool_on_chain_template_token_fetcher_1.UniswapV2PoolOnChainTemplateTokenFetcher {
    constructor(appToolkit, dolomiteContractFactory) {
        super(appToolkit);
        this.appToolkit = appToolkit;
        this.dolomiteContractFactory = dolomiteContractFactory;
        this.factoryAddress = utils_1.DOLOMITE_AMM_FACTORY_ADDRESSES[this.network];
        this.isExcludedFromTvl = true;
        this.groupLabel = 'Pools';
    }
    getPoolTokenContract(address) {
        return this.dolomiteContractFactory.dolomiteAmmPair({ address, network: this.network });
    }
    getPoolFactoryContract(address) {
        return this.dolomiteContractFactory.dolomiteAmmFactory({ address, network: this.network });
    }
    getPoolsLength(contract) {
        return contract.allPairsLength();
    }
    getPoolAddress(contract, index) {
        return contract.allPairs(index);
    }
    getPoolToken0(contract) {
        return contract.token0();
    }
    getPoolToken1(contract) {
        return contract.token1();
    }
    getPoolReserves(contract) {
        return contract.getReservesWei();
    }
    getLabel({ appToken }) {
        return __awaiter(this, void 0, void 0, function* () {
            const label = appToken.tokens.map(v => (0, image_present_1.getLabelFromToken)(v)).join(' / ');
            return label.replace('WETH', 'ETH');
        });
    }
    getSecondaryLabel(_params) {
        return __awaiter(this, void 0, void 0, function* () {
            return '50% / 50%';
        });
    }
    getStatsItems({ appToken }) {
        return __awaiter(this, void 0, void 0, function* () {
            const { fee, reserves, liquidity, volume, apy } = appToken.dataProps;
            const reservesDisplay = reserves
                .map(v => {
                if (Number.isNaN(v) || v === 0) {
                    return '0';
                }
                return v < 0.01 ? '<0.01' : v.toFixed(2);
            })
                .join(' / ');
            return [
                { label: 'Fee', value: (0, display_item_present_1.buildPercentageDisplayItem)(fee) },
                { label: 'Liquidity', value: (0, display_item_present_1.buildDollarDisplayItem)(liquidity) },
                { label: 'Reserves', value: reservesDisplay },
                { label: 'Ratio', value: '50% / 50%' },
                { label: 'Volume', value: (0, display_item_present_1.buildDollarDisplayItem)(volume) },
                { label: 'APY', value: (0, display_item_present_1.buildPercentageDisplayItem)(apy) },
            ];
        });
    }
};
ArbitrumDolomitePoolsTokenFetcher = __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.DolomiteContractFactory)),
    __metadata("design:paramtypes", [Object, contracts_1.DolomiteContractFactory])
], ArbitrumDolomitePoolsTokenFetcher);
exports.ArbitrumDolomitePoolsTokenFetcher = ArbitrumDolomitePoolsTokenFetcher;
//# sourceMappingURL=dolomite.pools.token-fetcher.js.map