@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
252 lines • 12.5 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.CoreSDK = void 0;
const lido_ethereum_sdk_1 = require("@lidofinance/lido-ethereum-sdk");
const viem_1 = require("viem");
const index_js_1 = require("../abi/index.js");
const csm_sdk_cacheable_js_1 = require("../common/class-primitives/csm-sdk-cacheable.js");
const index_js_2 = require("../common/decorators/index.js");
const index_js_3 = require("../common/index.js");
const index_js_4 = require("../common/utils/index.js");
let CoreSDK = (() => {
var _a;
let _classSuper = csm_sdk_cacheable_js_1.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 ?? index_js_3.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];
(0, lido_ethereum_sdk_1.invariant)(address, `Contract [${contract}] not configured`, lido_ethereum_sdk_1.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 (0, viem_1.getContract)({
address: this.getContractAddress(contractName),
abi,
client: {
public: this.publicClient,
wallet: this.core.web3Provider,
},
});
}
getContract(contractName) {
const abi = index_js_3.CONTRACT_BASE_ABI[contractName];
return this.getContractWithAbi(contractName, abi);
}
get contractBaseModule() {
return this.getContractWithAbi(this.moduleName, index_js_1.BaseModuleAbi);
}
get contractAccounting() {
return this.getContract(index_js_3.CONTRACT_NAMES.accounting);
}
get contractEjector() {
return this.getContract(index_js_3.CONTRACT_NAMES.ejector);
}
get contractFeeDistributor() {
return this.getContract(index_js_3.CONTRACT_NAMES.feeDistributor);
}
get contractFeeOracle() {
return this.getContract(index_js_3.CONTRACT_NAMES.feeOracle);
}
get contractCSModule() {
return this.getContract(index_js_3.CONTRACT_NAMES.csModule);
}
get contractParametersRegistry() {
return this.getContract(index_js_3.CONTRACT_NAMES.parametersRegistry);
}
get contractHashConsensus() {
return this.getContract(index_js_3.CONTRACT_NAMES.hashConsensus);
}
get contractStakingRouter() {
return this.getContract(index_js_3.CONTRACT_NAMES.stakingRouter);
}
get contractValidatorsExitBusOracle() {
return this.getContract(index_js_3.CONTRACT_NAMES.validatorsExitBusOracle);
}
get contractWithdrawalVault() {
return this.getContract(index_js_3.CONTRACT_NAMES.withdrawalVault);
}
get contractSMDiscovery() {
return this.getContract(index_js_3.CONTRACT_NAMES.SMDiscovery);
}
get contractCuratedModule() {
return this.getContract(index_js_3.CONTRACT_NAMES.curatedModule);
}
get supportedVersions() {
return this.moduleName === index_js_3.CONTRACT_NAMES.curatedModule
? index_js_3.SUPPORTED_CM_VERSIONS
: index_js_3.SUPPORTED_CSM_VERSIONS;
}
get externalLinks() {
return index_js_3.EXTERNAL_LINKS[this.chainId];
}
getExternalLink(type) {
return this.externalLinks[type];
}
get keysApiLink() {
return this.keysApiUrl ?? this.getExternalLink(index_js_3.LINK_TYPE.keysApi);
}
get rewardsTreeLink() {
return this.getExternalLink(index_js_3.LINK_TYPE.rewardsTree);
}
get icsTreeLink() {
return this.getExternalLink(index_js_3.LINK_TYPE.icsTree);
}
get curatedGateTreeLink() {
return this.getExternalLink(index_js_3.LINK_TYPE.curatedGateTree);
}
get feesMonitoringApiLink() {
return (this.feesMonitoringApiUrl ??
this.getExternalLink(index_js_3.LINK_TYPE.feesMonitoringApi));
}
getIpfsUrls(cid) {
if (!(0, index_js_4.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 = [(0, index_js_2.Logger)('Utils:'), (0, index_js_2.Cache)(index_js_3.CACHE_LONG)];
_getContractNameByAddress_decorators = [(0, index_js_2.Logger)('Utils:')];
_getContractWithAbi_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(index_js_3.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;
})();
exports.CoreSDK = CoreSDK;
//# sourceMappingURL=core-sdk.js.map