"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PriceFeed = void 0;
const priceClient_1 = require("../priceClient");
const baseAdapter_1 = require("./baseAdapter");
class PriceFeed extends baseAdapter_1.BaseHTTPAdapter {
    constructor({ name = "Across API", host = "across.to", timeout = 5000, retries = 3, } = {}) {
        super(name, host, { timeout, retries });
    }
    async getPriceByAddress(address, currency = "usd") {
        const queryArgs = {
            l1Token: address,
            baseCurrency: currency,
        };
        const now = (0, priceClient_1.msToS)(Date.now()) - 60;
        const response = await this.query("api/coingecko", queryArgs);
        if (!this.validateResponse(response))
            throw new Error(`Unexpected ${this.name} response: ${JSON.stringify(response)}`);
        return { address: address, price: response.price, timestamp: now };
    }
    getPricesByAddress(addresses, currency = "usd") {
        return Promise.all(addresses.map((address) => this.getPriceByAddress(address, currency)));
    }
    validateResponse(response) {
        if (typeof response !== "object")
            return false;
        return response !== null && typeof response.price === "number";
    }
}
exports.PriceFeed = PriceFeed;
//# sourceMappingURL=acrossApi.js.map