import { __awaiter, __extends, __generator } from "tslib";
import axios from "axios";
import AbstractApiClient from "./abstractClient";
import { BigNumber, parseEther } from "../utils";
/**
 * An implementation of AbstractApiClient that uses the production API.
 * @class
 * @extends AbstractApiClient
 * @note This implementation makes API calls to RESTful services.
 */
var ProductionApiClient = /** @class */ (function (_super) {
    __extends(ProductionApiClient, _super);
    function ProductionApiClient(serverlessApiUrl, scraperApiUrl) {
        return _super.call(this, serverlessApiUrl, scraperApiUrl) || this;
    }
    ProductionApiClient.prototype.getCoinGeckoData = function (l1Token, baseCurrency) {
        return __awaiter(this, void 0, void 0, function () {
            var response, result, price;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, axios.get("".concat(this.getServerlessApiUrl(), "/api/coingecko"), {
                            params: {
                                l1Token: l1Token,
                                baseCurrency: baseCurrency,
                            },
                        })];
                    case 1:
                        response = _a.sent();
                        result = response.data;
                        price = baseCurrency === "usd" ? parseEther(String(result.price)) : BigNumber.from(result.price);
                        return [2 /*return*/, {
                                price: price,
                            }];
                }
            });
        });
    };
    ProductionApiClient.prototype.getSuggestedFees = function (amount, originToken, toChainid, fromChainid) {
        return __awaiter(this, void 0, void 0, function () {
            var response, result, relayFeePct, relayFeeTotal, capitalFeePct, capitalFeeTotal, relayGasFeePct, relayGasFeeTotal, isAmountTooLow, quoteTimestamp, quoteBlock;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, axios.get("".concat(this.getServerlessApiUrl(), "/api/suggested-fees"), {
                            params: {
                                token: originToken,
                                destinationChainId: toChainid,
                                originChainId: fromChainid,
                                amount: amount.toString(),
                                skipAmountLimit: true,
                            },
                        })];
                    case 1:
                        response = _a.sent();
                        result = response.data;
                        relayFeePct = BigNumber.from(result["relayFeePct"]);
                        relayFeeTotal = BigNumber.from(result["relayFeeTotal"]);
                        capitalFeePct = BigNumber.from(result["capitalFeePct"]);
                        capitalFeeTotal = BigNumber.from(result["capitalFeeTotal"]);
                        relayGasFeePct = BigNumber.from(result["relayGasFeePct"]);
                        relayGasFeeTotal = BigNumber.from(result["relayGasFeeTotal"]);
                        isAmountTooLow = result["isAmountTooLow"];
                        quoteTimestamp = BigNumber.from(result["timestamp"]);
                        quoteBlock = BigNumber.from(result["quoteBlock"]);
                        return [2 /*return*/, {
                                relayerFee: {
                                    pct: relayFeePct,
                                    total: relayFeeTotal,
                                },
                                relayerCapitalFee: {
                                    pct: capitalFeePct,
                                    total: capitalFeeTotal,
                                },
                                relayerGasFee: {
                                    pct: relayGasFeePct,
                                    total: relayGasFeeTotal,
                                },
                                isAmountTooLow: isAmountTooLow,
                                quoteTimestamp: quoteTimestamp,
                                quoteBlock: quoteBlock,
                            }];
                }
            });
        });
    };
    ProductionApiClient.prototype.getBridgeLimits = function (token, fromChainId, toChainId) {
        return __awaiter(this, void 0, void 0, function () {
            var data;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, axios.get("".concat(this.getServerlessApiUrl(), "/api/limits?token=").concat(token, "&originChainId=").concat(fromChainId, "&destinationChainId=").concat(toChainId))];
                    case 1:
                        data = (_a.sent()).data;
                        return [2 /*return*/, data];
                }
            });
        });
    };
    ProductionApiClient.prototype.getAcrossStats = function () {
        return __awaiter(this, void 0, void 0, function () {
            var axiosResponse;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, axios.get("".concat(this.getScraperApiUrl(), "/deposits/stats"))];
                    case 1:
                        axiosResponse = _a.sent();
                        return [2 /*return*/, axiosResponse.data];
                }
            });
        });
    };
    return ProductionApiClient;
}(AbstractApiClient));
export default ProductionApiClient;
//# sourceMappingURL=productionClient.js.map