UNPKG

@lidofinance/lido-ethereum-sdk

Version:

<div style="display: flex;" align="center"> <h1 align="center">Lido Ethereum SDK</h1> </div>

131 lines 7.52 kB
"use strict"; var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { var useValue = arguments.length > 2; for (var i = 0; i < initializers.length; i++) { value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); } return useValue ? value : void 0; }; var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); var _, done = false; for (var i = decorators.length - 1; i >= 0; i--) { var context = {}; for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; for (var p in contextIn.access) context.access[p] = contextIn.access[p]; context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); if (kind === "accessor") { if (result === void 0) continue; if (result === null || typeof result !== "object") throw new TypeError("Object expected"); if (_ = accept(result.get)) descriptor.get = _; if (_ = accept(result.set)) descriptor.set = _; if (_ = accept(result.init)) initializers.unshift(_); } else if (_ = accept(result)) { if (kind === "field") initializers.unshift(_); else descriptor[key] = _; } } if (target) Object.defineProperty(target, contextIn.name, descriptor); done = true; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LidoSDKWithdrawWaitingTime = void 0; const index_js_1 = require("../common/decorators/index.js"); const bus_module_js_1 = require("./bus-module.js"); const index_js_2 = require("../common/index.js"); const viem_1 = require("viem"); const endpoints = { calculateByAmount: '/v2/request-time/calculate', calculateByRequestId: '/v2/request-time', }; let LidoSDKWithdrawWaitingTime = (() => { var _a; let _classSuper = bus_module_js_1.BusModule; let _instanceExtraInitializers = []; let _getWithdrawalWaitingTimeByAmount_decorators; let _getWithdrawalWaitingTimeByRequestIds_decorators; return _a = class LidoSDKWithdrawWaitingTime extends _classSuper { async getWithdrawalWaitingTimeByAmount(props) { const getCustomApiUrl = props?.getCustomApiUrl; const query = new URLSearchParams(); if (props.amount) { query.set('amount', (0, viem_1.formatEther)(props.amount)); } const baseUrl = this.getBaseUrl(getCustomApiUrl); const url = `${baseUrl}${endpoints.calculateByAmount}?${query.toString()}`; const response = await fetch(url, { headers: { 'WQ-Request-Source': 'sdk', }, }); return response.json(); } async getWithdrawalWaitingTimeByRequestIds(props) { const requestDelay = props?.requestDelay ?? 1000; const getCustomApiUrl = props?.getCustomApiUrl; if (!Array.isArray(props.ids) || props.ids.length === 0) { throw this.bus.core.error({ code: index_js_2.ERROR_CODE.INVALID_ARGUMENT, message: 'expected not empty array ids', }); } const idsPages = []; const pageSize = 20; const baseUrl = this.getBaseUrl(getCustomApiUrl); const path = `${baseUrl}${endpoints.calculateByRequestId}`; for (let i = 0; i < props.ids.length; i += pageSize) { idsPages.push(props.ids.slice(i, i + pageSize)); } const result = []; for (const page of idsPages) { const query = new URLSearchParams(); query.set('ids', page.toString()); const url = `${path}?${query.toString()}`; const response = await fetch(url, { headers: { 'WQ-Request-Source': 'sdk', }, }); const requests = await response.json(); result.push(...requests); if (idsPages.length > 1) { await new Promise((resolve) => setTimeout(resolve, requestDelay)); } } return result; } getBaseUrl(getCustomApiUrl) { const defaultUrl = index_js_2.WQ_API_URLS[this.bus.core.chainId]; const baseUrl = getCustomApiUrl && typeof getCustomApiUrl === 'function' ? getCustomApiUrl(defaultUrl ?? null, this.bus.core.chainId) : defaultUrl; if (!baseUrl) { throw this.bus.core.error({ code: index_js_2.ERROR_CODE.INVALID_ARGUMENT, message: `wq-api URL is not found for chain ${this.bus.core.chainId}, use getCustomApiUrl prop to setup custom URL`, }); } return baseUrl; } constructor() { super(...arguments); __runInitializers(this, _instanceExtraInitializers); } }, (() => { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0; _getWithdrawalWaitingTimeByAmount_decorators = [(0, index_js_1.Logger)('API:'), (0, index_js_1.ErrorHandler)()]; _getWithdrawalWaitingTimeByRequestIds_decorators = [(0, index_js_1.Logger)('API:'), (0, index_js_1.ErrorHandler)()]; __esDecorate(_a, null, _getWithdrawalWaitingTimeByAmount_decorators, { kind: "method", name: "getWithdrawalWaitingTimeByAmount", static: false, private: false, access: { has: obj => "getWithdrawalWaitingTimeByAmount" in obj, get: obj => obj.getWithdrawalWaitingTimeByAmount }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getWithdrawalWaitingTimeByRequestIds_decorators, { kind: "method", name: "getWithdrawalWaitingTimeByRequestIds", static: false, private: false, access: { has: obj => "getWithdrawalWaitingTimeByRequestIds" in obj, get: obj => obj.getWithdrawalWaitingTimeByRequestIds }, metadata: _metadata }, null, _instanceExtraInitializers); if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); })(), _a; })(); exports.LidoSDKWithdrawWaitingTime = LidoSDKWithdrawWaitingTime; //# sourceMappingURL=withdraw-waiting-time.js.map