UNPKG

@exromany/lido-csm-sdk

Version:

[![GitHub license](https://img.shields.io/github/license/lidofinance/lido-csm-sdk?color=limegreen)](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [![Version npm](https://img.shields.io/npm/v/@lidofinance/lido-csm-sdk?label=version)](h

249 lines 12.1 kB
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; }; import { ERROR_CODE, invariant, } from '@lidofinance/lido-ethereum-sdk'; import { getContract } from 'viem'; import { BaseModuleAbi, } from '../abi/index.js'; import { CsmSDKCacheable } from '../common/class-primitives/csm-sdk-cacheable.js'; import { Cache, Logger } from '../common/decorators/index.js'; import { CACHE_LONG, CONTRACT_BASE_ABI, CONTRACT_NAMES, EXTERNAL_LINKS, LINK_TYPE, SUPPORTED_CM_VERSIONS, SUPPORTED_CSM_VERSIONS, } from '../common/index.js'; import { isValidIpfsCid } from '../common/utils/index.js'; let CoreSDK = (() => { var _a; let _classSuper = CsmSDKCacheable; let _instanceExtraInitializers = []; let _getContractAddress_decorators; let _getContractNameByAddress_decorators; let _getContractWithAbi_decorators; return _a = class CoreSDK extends _classSuper { constructor(props) { super(); Object.defineProperty(this, "core", { enumerable: true, configurable: true, writable: true, value: __runInitializers(this, _instanceExtraInitializers) }); Object.defineProperty(this, "contractAddresses", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "moduleId", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "deploymentBlockNumber", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "clApiUrl", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "keysApiUrl", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "feesMonitoringApiUrl", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "maxEventBlocksRange", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "skipHistoricalCalls", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "moduleName", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.core = props.core; this.contractAddresses = props.contractAddresses; this.moduleId = props.moduleId; this.deploymentBlockNumber = props.deploymentBlockNumber ?? 0n; this.clApiUrl = props.clApiUrl; this.keysApiUrl = props.keysApiUrl; this.feesMonitoringApiUrl = props.feesMonitoringApiUrl; this.maxEventBlocksRange = props.maxEventBlocksRange; this.skipHistoricalCalls = props.skipHistoricalCalls ?? false; this.moduleName = props.moduleName ?? CONTRACT_NAMES.csModule; } get chainId() { return this.core.chain.id; } get chain() { return this.core.chain; } get logMode() { return this.core.logMode; } get publicClient() { return this.core.rpcProvider; } get walletClient() { return this.core.useWeb3Provider(); } getContractAddress(contract) { const address = this.contractAddresses[contract]; invariant(address, `Contract [${contract}] not configured`, ERROR_CODE.NOT_SUPPORTED); return address; } getContractNameByAddress(address) { const normalizedAddress = address.toLowerCase(); return Object.entries(this.contractAddresses).find(([_, addr]) => addr?.toLowerCase() === normalizedAddress)?.[0]; } getContractWithAbi(contractName, abi) { return getContract({ address: this.getContractAddress(contractName), abi, client: { public: this.publicClient, wallet: this.core.web3Provider, }, }); } getContract(contractName) { const abi = CONTRACT_BASE_ABI[contractName]; return this.getContractWithAbi(contractName, abi); } get contractBaseModule() { return this.getContractWithAbi(this.moduleName, BaseModuleAbi); } get contractAccounting() { return this.getContract(CONTRACT_NAMES.accounting); } get contractEjector() { return this.getContract(CONTRACT_NAMES.ejector); } get contractFeeDistributor() { return this.getContract(CONTRACT_NAMES.feeDistributor); } get contractFeeOracle() { return this.getContract(CONTRACT_NAMES.feeOracle); } get contractCSModule() { return this.getContract(CONTRACT_NAMES.csModule); } get contractParametersRegistry() { return this.getContract(CONTRACT_NAMES.parametersRegistry); } get contractHashConsensus() { return this.getContract(CONTRACT_NAMES.hashConsensus); } get contractStakingRouter() { return this.getContract(CONTRACT_NAMES.stakingRouter); } get contractValidatorsExitBusOracle() { return this.getContract(CONTRACT_NAMES.validatorsExitBusOracle); } get contractWithdrawalVault() { return this.getContract(CONTRACT_NAMES.withdrawalVault); } get contractSMDiscovery() { return this.getContract(CONTRACT_NAMES.SMDiscovery); } get contractCuratedModule() { return this.getContract(CONTRACT_NAMES.curatedModule); } get supportedVersions() { return this.moduleName === CONTRACT_NAMES.curatedModule ? SUPPORTED_CM_VERSIONS : SUPPORTED_CSM_VERSIONS; } get externalLinks() { return EXTERNAL_LINKS[this.chainId]; } getExternalLink(type) { return this.externalLinks[type]; } get keysApiLink() { return this.keysApiUrl ?? this.getExternalLink(LINK_TYPE.keysApi); } get rewardsTreeLink() { return this.getExternalLink(LINK_TYPE.rewardsTree); } get icsTreeLink() { return this.getExternalLink(LINK_TYPE.icsTree); } get curatedGateTreeLink() { return this.getExternalLink(LINK_TYPE.curatedGateTree); } get feesMonitoringApiLink() { return (this.feesMonitoringApiUrl ?? this.getExternalLink(LINK_TYPE.feesMonitoringApi)); } getIpfsUrls(cid) { if (!isValidIpfsCid(cid)) return []; return [ `https://ipfs.io/ipfs/${cid}`, `https://gateway.pinata.cloud/ipfs/${cid}`, ]; } }, (() => { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0; _getContractAddress_decorators = [Logger('Utils:'), Cache(CACHE_LONG)]; _getContractNameByAddress_decorators = [Logger('Utils:')]; _getContractWithAbi_decorators = [Logger('Contracts:'), Cache(CACHE_LONG)]; __esDecorate(_a, null, _getContractAddress_decorators, { kind: "method", name: "getContractAddress", static: false, private: false, access: { has: obj => "getContractAddress" in obj, get: obj => obj.getContractAddress }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getContractNameByAddress_decorators, { kind: "method", name: "getContractNameByAddress", static: false, private: false, access: { has: obj => "getContractNameByAddress" in obj, get: obj => obj.getContractNameByAddress }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _getContractWithAbi_decorators, { kind: "method", name: "getContractWithAbi", static: false, private: false, access: { has: obj => "getContractWithAbi" in obj, get: obj => obj.getContractWithAbi }, metadata: _metadata }, null, _instanceExtraInitializers); if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); })(), _a; })(); export { CoreSDK }; //# sourceMappingURL=core-sdk.js.map