@lidofinance/lido-ethereum-sdk
Version:
<div style="display: flex;" align="center"> <h1 align="center">Lido Ethereum SDK</h1> </div>
178 lines • 13.1 kB
JavaScript
"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.LidoSDKWithdrawViews = 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");
let LidoSDKWithdrawViews = (() => {
var _a;
let _classSuper = bus_module_js_1.BusModule;
let _instanceExtraInitializers = [];
let _getWithdrawalRequestsIds_decorators;
let _getLastCheckpointIndex_decorators;
let _getWithdrawalStatus_decorators;
let _findCheckpointHints_decorators;
let _getClaimableEther_decorators;
let _getUnfinalizedStETH_decorators;
let _minStethWithdrawalAmount_decorators;
let _minWStethWithdrawalAmount_decorators;
let _maxStethWithdrawalAmount_decorators;
let _maxWStethWithdrawalAmount_decorators;
let _isPaused_decorators;
let _isBunkerModeActive_decorators;
let _isTurboModeActive_decorators;
return _a = class LidoSDKWithdrawViews extends _classSuper {
async getWithdrawalRequestsIds(props) {
const contract = await this.bus.contract.getContractWithdrawalQueue();
const parsedAccount = await this.bus.core.useAccount(props.account);
return contract.read.getWithdrawalRequests([parsedAccount.address]);
}
async getLastCheckpointIndex() {
const contract = await this.bus.contract.getContractWithdrawalQueue();
return contract.read.getLastCheckpointIndex();
}
async getWithdrawalStatus(props) {
const { requestsIds } = props;
const contract = await this.bus.contract.getContractWithdrawalQueue();
const requests = await contract.read.getWithdrawalStatus([requestsIds]);
(0, index_js_2.invariantArgument)(requests.length === requestsIds.length, 'Invalid requests ids');
return requests.map((request, i) => ({
...request,
id: requestsIds[i] || BigInt(0),
stringId: requestsIds[i]?.toString() || '0',
}));
}
async findCheckpointHints(props) {
const { sortedIds, firstIndex = 1n, lastIndex: _lastIndex } = props;
const contract = await this.bus.contract.getContractWithdrawalQueue();
const lastFinalizedRequestId = await contract.read.getLastFinalizedRequestId();
for (let index = sortedIds.length - 1; index >= 0; index--) {
const id = sortedIds[index];
(0, index_js_2.invariantArgument)(id && id <= lastFinalizedRequestId, `Cannot find hints for unfinalized request ${id?.toString()}`);
}
const lastIndex = _lastIndex ?? (await this.getLastCheckpointIndex());
return contract.read.findCheckpointHints([
sortedIds,
firstIndex,
lastIndex,
]);
}
async getClaimableEther(props) {
const { sortedIds, hints } = props;
const contract = await this.bus.contract.getContractWithdrawalQueue();
return contract.read.getClaimableEther([sortedIds, hints]);
}
async getUnfinalizedStETH() {
const contract = await this.bus.contract.getContractWithdrawalQueue();
return contract.read.unfinalizedStETH();
}
async minStethWithdrawalAmount() {
const contract = await this.bus.contract.getContractWithdrawalQueue();
return contract.read.MIN_STETH_WITHDRAWAL_AMOUNT();
}
async minWStethWithdrawalAmount() {
const [amount, contract] = await Promise.all([
this.minStethWithdrawalAmount(),
this.bus.contract.getContractWstETH(),
]);
return contract.read.getWstETHByStETH([amount]);
}
async maxStethWithdrawalAmount() {
const contract = await this.bus.contract.getContractWithdrawalQueue();
return contract.read.MAX_STETH_WITHDRAWAL_AMOUNT();
}
async maxWStethWithdrawalAmount() {
const [amount, contract] = await Promise.all([
this.maxStethWithdrawalAmount(),
this.bus.contract.getContractWstETH(),
]);
return contract.read.getWstETHByStETH([amount]);
}
async isPaused() {
const contract = await this.bus.contract.getContractWithdrawalQueue();
return contract.read.isPaused();
}
async isBunkerModeActive() {
const contract = await this.bus.contract.getContractWithdrawalQueue();
return contract.read.isBunkerModeActive();
}
async isTurboModeActive() {
const [isBunkerMode, isPaused] = await Promise.all([
this.isBunkerModeActive(),
await this.isPaused(),
]);
return !isPaused && !isBunkerMode;
}
constructor() {
super(...arguments);
__runInitializers(this, _instanceExtraInitializers);
}
},
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_getWithdrawalRequestsIds_decorators = [(0, index_js_1.Logger)('Views:')];
_getLastCheckpointIndex_decorators = [(0, index_js_1.Logger)('Views:')];
_getWithdrawalStatus_decorators = [(0, index_js_1.Logger)('Views:')];
_findCheckpointHints_decorators = [(0, index_js_1.Logger)('Views:')];
_getClaimableEther_decorators = [(0, index_js_1.Logger)('Views:')];
_getUnfinalizedStETH_decorators = [(0, index_js_1.Logger)('Views:')];
_minStethWithdrawalAmount_decorators = [(0, index_js_1.Logger)('Views:'), (0, index_js_1.Cache)(30 * 60 * 1000, ['bus.core.chain.id'])];
_minWStethWithdrawalAmount_decorators = [(0, index_js_1.Logger)('Views:')];
_maxStethWithdrawalAmount_decorators = [(0, index_js_1.Logger)('Views:'), (0, index_js_1.Cache)(30 * 60 * 1000, ['bus.core.chain.id'])];
_maxWStethWithdrawalAmount_decorators = [(0, index_js_1.Logger)('Views:')];
_isPaused_decorators = [(0, index_js_1.Logger)('Views:')];
_isBunkerModeActive_decorators = [(0, index_js_1.Logger)('Views:')];
_isTurboModeActive_decorators = [(0, index_js_1.Logger)('Views:')];
__esDecorate(_a, null, _getWithdrawalRequestsIds_decorators, { kind: "method", name: "getWithdrawalRequestsIds", static: false, private: false, access: { has: obj => "getWithdrawalRequestsIds" in obj, get: obj => obj.getWithdrawalRequestsIds }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getLastCheckpointIndex_decorators, { kind: "method", name: "getLastCheckpointIndex", static: false, private: false, access: { has: obj => "getLastCheckpointIndex" in obj, get: obj => obj.getLastCheckpointIndex }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getWithdrawalStatus_decorators, { kind: "method", name: "getWithdrawalStatus", static: false, private: false, access: { has: obj => "getWithdrawalStatus" in obj, get: obj => obj.getWithdrawalStatus }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _findCheckpointHints_decorators, { kind: "method", name: "findCheckpointHints", static: false, private: false, access: { has: obj => "findCheckpointHints" in obj, get: obj => obj.findCheckpointHints }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getClaimableEther_decorators, { kind: "method", name: "getClaimableEther", static: false, private: false, access: { has: obj => "getClaimableEther" in obj, get: obj => obj.getClaimableEther }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getUnfinalizedStETH_decorators, { kind: "method", name: "getUnfinalizedStETH", static: false, private: false, access: { has: obj => "getUnfinalizedStETH" in obj, get: obj => obj.getUnfinalizedStETH }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _minStethWithdrawalAmount_decorators, { kind: "method", name: "minStethWithdrawalAmount", static: false, private: false, access: { has: obj => "minStethWithdrawalAmount" in obj, get: obj => obj.minStethWithdrawalAmount }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _minWStethWithdrawalAmount_decorators, { kind: "method", name: "minWStethWithdrawalAmount", static: false, private: false, access: { has: obj => "minWStethWithdrawalAmount" in obj, get: obj => obj.minWStethWithdrawalAmount }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _maxStethWithdrawalAmount_decorators, { kind: "method", name: "maxStethWithdrawalAmount", static: false, private: false, access: { has: obj => "maxStethWithdrawalAmount" in obj, get: obj => obj.maxStethWithdrawalAmount }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _maxWStethWithdrawalAmount_decorators, { kind: "method", name: "maxWStethWithdrawalAmount", static: false, private: false, access: { has: obj => "maxWStethWithdrawalAmount" in obj, get: obj => obj.maxWStethWithdrawalAmount }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _isPaused_decorators, { kind: "method", name: "isPaused", static: false, private: false, access: { has: obj => "isPaused" in obj, get: obj => obj.isPaused }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _isBunkerModeActive_decorators, { kind: "method", name: "isBunkerModeActive", static: false, private: false, access: { has: obj => "isBunkerModeActive" in obj, get: obj => obj.isBunkerModeActive }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _isTurboModeActive_decorators, { kind: "method", name: "isTurboModeActive", static: false, private: false, access: { has: obj => "isTurboModeActive" in obj, get: obj => obj.isTurboModeActive }, metadata: _metadata }, null, _instanceExtraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
_a;
})();
exports.LidoSDKWithdrawViews = LidoSDKWithdrawViews;
//# sourceMappingURL=withdraw-views.js.map