"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());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EthereumRookClaimableContractPositionFetcher = void 0;
const common_1 = require("@nestjs/common");
const axios_1 = __importDefault(require("axios"));
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const app_toolkit_interface_1 = require("../../../app-toolkit/app-toolkit.interface");
const position_template_decorator_1 = require("../../../app-toolkit/decorators/position-template.decorator");
const image_present_1 = require("../../../app-toolkit/helpers/presentation/image.present");
const position_interface_1 = require("../../../position/position.interface");
const contract_position_template_position_fetcher_1 = require("../../../position/template/contract-position.template.position-fetcher");
const contracts_1 = require("../contracts");
const REWARD_DEFINITIONS = [
    {
        address: '0xaef38e99b9db5e96cab3ce5cbc29a3a1dfeffe71',
        url: `https://indibo-lp-pre.herokuapp.com/reward_of_liquidity_provider`,
        name: 'LP-PRE',
    },
    {
        address: '0xcadf6735144d1d7f1a875a5561555cba5df2f75c',
        url: `https://indibo-lp.herokuapp.com/reward_of_liquidity_provider`,
        name: 'LP',
    },
    {
        address: '0x2777b798fdfb906d42b89cf8f9de541db05dd6a1',
        url: `https://indibo-lpq2.herokuapp.com/reward_of_liquidity_provider`,
        name: 'LP-Q2',
    },
    {
        address: '0xf55a73a366f1f9f03cef4cc10d3cd21e5c6a9026',
        url: `https://indibo-keeper.herokuapp.com/reward_of_keeper`,
        name: 'LP-KEEPER',
    },
    {
        address: '0xd81e97075dbda444ef65db3a96706c679b5311fd',
        url: `https://indibo-hiding.herokuapp.com/reward_of_hiding_game`,
        name: 'LP-HIDING-GAME',
    },
];
let EthereumRookClaimableContractPositionFetcher = class EthereumRookClaimableContractPositionFetcher extends contract_position_template_position_fetcher_1.ContractPositionTemplatePositionFetcher {
    constructor(appToolkit, contractFactory) {
        super(appToolkit);
        this.appToolkit = appToolkit;
        this.contractFactory = contractFactory;
        this.groupLabel = 'Claimable';
    }
    getContract(address) {
        return this.contractFactory.rookLiquidityPoolDistributor({ address, network: this.network });
    }
    getDefinitions() {
        return __awaiter(this, void 0, void 0, function* () {
            return REWARD_DEFINITIONS;
        });
    }
    getTokenDefinitions() {
        return __awaiter(this, void 0, void 0, function* () {
            return [
                {
                    metaType: position_interface_1.MetaType.CLAIMABLE,
                    address: '0xfa5047c9c78b8877af97bdcb85db743fd7313d4a',
                    network: this.network,
                },
            ];
        });
    }
    getLabel({ contractPosition }) {
        return __awaiter(this, void 0, void 0, function* () {
            return `Claimable ${(0, image_present_1.getLabelFromToken)(contractPosition.tokens[0])}`;
        });
    }
    getTokenBalancesPerPosition({ address, contractPosition, contract, }) {
        return __awaiter(this, void 0, void 0, function* () {
            try {
                const definition = REWARD_DEFINITIONS.find(t => t.address === contractPosition.address);
                if (!definition)
                    return [];
                const { data } = yield axios_1.default.get(`${definition.url}/${address}`);
                const earnedRaw = data.earnings_to_date;
                const earned = new bignumber_js_1.default(earnedRaw, 16);
                if (earned.eq(0))
                    return [];
                const claimedRaw = yield contract.claimedAmount(address);
                const claimed = new bignumber_js_1.default(claimedRaw.toString());
                const claimableBalanceRaw = earned.minus(claimed).toFixed(0);
                return [claimableBalanceRaw];
            }
            catch (err) {
                return [];
            }
        });
    }
};
EthereumRookClaimableContractPositionFetcher = __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.RookContractFactory)),
    __metadata("design:paramtypes", [Object, contracts_1.RookContractFactory])
], EthereumRookClaimableContractPositionFetcher);
exports.EthereumRookClaimableContractPositionFetcher = EthereumRookClaimableContractPositionFetcher;
//# sourceMappingURL=rook.claimable.contract-position-fetcher.js.map