"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.PoolTogetherV3LogProvider = exports.PoolWithMultipleWinnersBuilderCreatedType = void 0;
const common_1 = require("@nestjs/common");
const moment_1 = __importDefault(require("moment"));
const cache_decorator_1 = require("../../../cache/cache.decorator");
const contracts_1 = require("../contracts");
var PoolWithMultipleWinnersBuilderCreatedType;
(function (PoolWithMultipleWinnersBuilderCreatedType) {
    PoolWithMultipleWinnersBuilderCreatedType["STAKE"] = "stake";
    PoolWithMultipleWinnersBuilderCreatedType["YIELD"] = "yield";
    PoolWithMultipleWinnersBuilderCreatedType["COMPOUND"] = "compound";
})(PoolWithMultipleWinnersBuilderCreatedType = exports.PoolWithMultipleWinnersBuilderCreatedType || (exports.PoolWithMultipleWinnersBuilderCreatedType = {}));
let PoolTogetherV3LogProvider = class PoolTogetherV3LogProvider {
    constructor(contractFactory) {
        this.contractFactory = contractFactory;
    }
    getPoolWithMultipleWinnersBuilderLogs({ fromBlock, network, address, }) {
        return __awaiter(this, void 0, void 0, function* () {
            const contract = this.contractFactory.poolTogetherV3PoolWithMultipleWinnersBuilder({ network, address });
            const mapper = ({ address, event, args }) => {
                var _a;
                return ({
                    args: Array.from((_a = args === null || args === void 0 ? void 0 : args.values()) !== null && _a !== void 0 ? _a : []),
                    address,
                    event,
                });
            };
            const [stakeLogs, compoundLogs, yieldLogs] = yield Promise.all([
                contract
                    .queryFilter(contract.filters.StakePrizePoolWithMultipleWinnersCreated(), fromBlock)
                    .then(logs => logs.map(mapper)),
                contract
                    .queryFilter(contract.filters.CompoundPrizePoolWithMultipleWinnersCreated(), fromBlock)
                    .then(logs => logs.map(mapper)),
                contract
                    .queryFilter(contract.filters.YieldSourcePrizePoolWithMultipleWinnersCreated(), fromBlock)
                    .then(logs => logs.map(mapper)),
            ]);
            return {
                [PoolWithMultipleWinnersBuilderCreatedType.STAKE]: stakeLogs,
                [PoolWithMultipleWinnersBuilderCreatedType.COMPOUND]: compoundLogs,
                [PoolWithMultipleWinnersBuilderCreatedType.YIELD]: yieldLogs,
            };
        });
    }
};
__decorate([
    (0, cache_decorator_1.Cache)({
        key: ({ network, address, fromBlock }) => `pool-together-v3:${network}:community-pool-builder-logs:${address}:${fromBlock}`,
        ttl: moment_1.default.duration(1, 'hour').asSeconds(),
    }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], PoolTogetherV3LogProvider.prototype, "getPoolWithMultipleWinnersBuilderLogs", null);
PoolTogetherV3LogProvider = __decorate([
    (0, common_1.Injectable)(),
    __param(0, (0, common_1.Inject)(contracts_1.PoolTogetherV3ContractFactory)),
    __metadata("design:paramtypes", [contracts_1.PoolTogetherV3ContractFactory])
], PoolTogetherV3LogProvider);
exports.PoolTogetherV3LogProvider = PoolTogetherV3LogProvider;
//# sourceMappingURL=pool-together-v3.log-provider.js.map