"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PriceFeed = void 0;
var tslib_1 = require("tslib");
var priceClient_1 = require("../priceClient");
var baseAdapter_1 = require("./baseAdapter");
var PriceFeed = (function (_super) {
    tslib_1.__extends(PriceFeed, _super);
    function PriceFeed(_a) {
        var _b = _a === void 0 ? {} : _a, _c = _b.name, name = _c === void 0 ? "Across API" : _c, _d = _b.host, host = _d === void 0 ? "across.to" : _d, _e = _b.timeout, timeout = _e === void 0 ? 5000 : _e, _f = _b.retries, retries = _f === void 0 ? 3 : _f;
        return _super.call(this, name, host, { timeout: timeout, retries: retries }) || this;
    }
    PriceFeed.prototype.getPriceByAddress = function (address_1) {
        return tslib_1.__awaiter(this, arguments, void 0, function (address, currency) {
            var queryArgs, now, response;
            if (currency === void 0) { currency = "usd"; }
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        queryArgs = {
                            l1Token: address,
                            baseCurrency: currency,
                        };
                        now = (0, priceClient_1.msToS)(Date.now()) - 60;
                        return [4, this.query("api/coingecko", queryArgs)];
                    case 1:
                        response = _a.sent();
                        if (!this.validateResponse(response))
                            throw new Error("Unexpected ".concat(this.name, " response: ").concat(JSON.stringify(response)));
                        return [2, { address: address, price: response.price, timestamp: now }];
                }
            });
        });
    };
    PriceFeed.prototype.getPricesByAddress = function (addresses, currency) {
        var _this = this;
        if (currency === void 0) { currency = "usd"; }
        return Promise.all(addresses.map(function (address) { return _this.getPriceByAddress(address, currency); }));
    };
    PriceFeed.prototype.validateResponse = function (response) {
        if (typeof response !== "object")
            return false;
        return response !== null && typeof response.price === "number";
    };
    return PriceFeed;
}(baseAdapter_1.BaseHTTPAdapter));
exports.PriceFeed = PriceFeed;
//# sourceMappingURL=acrossApi.js.map