UNPKG

@lidofinance/lido-ethereum-sdk

Version:

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

87 lines 3.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LidoSDKVaultViewer = void 0; const bus_module_js_1 = require("./bus-module.js"); const index_js_1 = require("../common/index.js"); const index_js_2 = require("./consts/index.js"); class LidoSDKVaultViewer extends bus_module_js_1.BusModule { async fetchConnectedVaults(props) { const vaultViewer = await this.bus.contracts.getContractVaultViewer(); const offset = BigInt(props.perPage * (props.page - 1)); const limit = BigInt(props.perPage); const totalVaults = await vaultViewer.read.vaultsCount(); const vaultAddresses = await vaultViewer.read.vaultAddressesBatch([ offset, limit, ]); return { data: vaultAddresses, totals: totalVaults }; } async fetchVaultsByOwner(props) { if (!props.address) { throw this.bus.core.error({ code: index_js_1.ERROR_CODE.INVALID_ARGUMENT, message: `Address is required argument`, }); } const vaultViewer = await this.bus.contracts.getContractVaultViewer(); const scanLimit = props.scanLimit ?? index_js_2.SCAN_LIMIT; const totalVaults = await vaultViewer.read.vaultsCount(); let vaults = []; for (let i = 0n; i < totalVaults; i += scanLimit) { const vaultsBatch = await vaultViewer.read.vaultsByOwnerBatch([ props.address, i, scanLimit, ]); vaults = vaults.concat(vaultsBatch); } return { data: vaults, totals: vaults.length, }; } async fetchVaultsByOwnerEntities(props) { const result = await this.fetchVaultsByOwner(props); return { data: result.data.map((v) => this.bus.vaultFromAddress(v)), totals: result.totals, }; } async fetchConnectedVaultEntities(props) { const result = await this.fetchConnectedVaults(props); return { data: result.data.map((v) => this.bus.vaultFromAddress(v)), totals: result.totals, }; } async _validateRoles(roles) { const ROLES = await this.bus.constants.ROLES(); for (const role of roles) { if (!Object.values(ROLES).includes(role)) { throw this.bus.core.error({ code: index_js_1.ERROR_CODE.TRANSACTION_ERROR, message: `Invalid role "${role}" found.`, }); } } } async getRoleMembers(props) { await this._validateRoles(props.roles); const vaultViewer = await this.bus.contracts.getContractVaultViewer(); return vaultViewer.read.roleMembers([props.vaultAddress, props.roles]); } async getRoleMembersBatch(props) { await this._validateRoles(props.roles); const vaultViewer = await this.bus.contracts.getContractVaultViewer(); return vaultViewer.read.roleMembersBatch([ props.vaultAddresses, props.roles, ]); } async getVaultData(props) { const vaultViewer = await this.bus.contracts.getContractVaultViewer(); return vaultViewer.read.vaultData([props.vaultAddress]); } } exports.LidoSDKVaultViewer = LidoSDKVaultViewer; //# sourceMappingURL=vault-viewer.js.map