@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
324 lines • 21.2 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 types_js_1 = require("./types.js");
let CoreSDK = (() => {
var _a;
let _classSuper = csm_sdk_cacheable_js_1.CsmSDKCacheable;
let _instanceExtraInitializers = [];
let _getContractAddress_decorators;
let _get_contractCSAccounting_decorators;
let _get_contractCSEjector_decorators;
let _get_contractCSFeeDistributor_decorators;
let _get_contractCSFeeOracle_decorators;
let _get_contractCSModule_decorators;
let _get_contractCSParametersRegistry_decorators;
let _get_contractCSStrikes_decorators;
let _get_contractCSExitPenalties_decorators;
let _get_contractHashConsensus_decorators;
let _get_contractPermissionlessGate_decorators;
let _get_contractVettedGate_decorators;
let _get_contractStakingRouter_decorators;
let _get_contractValidatorsExitBusOracle_decorators;
let _get_contractWithdrawalVault_decorators;
let _get_contractCSMSatellite_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, "overridedAddresses", {
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, "maxEventBlocksRange", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.core = props.core;
this.overridedAddresses = props.overridedAddresses;
this.clApiUrl = props.clApiUrl;
this.maxEventBlocksRange = props.maxEventBlocksRange;
}
get chainId() {
return this.core.chain.id;
}
get chain() {
return this.core.chain;
}
get logMode() {
return this.core.logMode;
}
get client() {
return this.core.rpcProvider;
}
getContractAddress(contract) {
const address = this.overridedAddresses?.[contract] ??
index_js_3.CSM_CONTRACT_ADDRESSES[this.chainId]?.[contract];
(0, lido_ethereum_sdk_1.invariant)(address, `CSM contract [${contract}] are not supported for ${this.core.chain.name}(${this.core.chain.id})`, lido_ethereum_sdk_1.ERROR_CODE.NOT_SUPPORTED);
return address;
}
getContract(contractName, abi) {
return (0, viem_1.getContract)({
address: this.getContractAddress(contractName),
abi,
client: {
public: this.core.rpcProvider,
wallet: this.core.web3Provider,
},
});
}
get contractCSAccounting() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.csAccounting, index_js_1.CSAccountingAbi);
}
get contractCSEjector() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.csEjector, index_js_1.CSEjectorAbi);
}
get contractCSFeeDistributor() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.csFeeDistributor, index_js_1.CSFeeDistributorAbi);
}
get contractCSFeeOracle() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.csFeeOracle, index_js_1.CSFeeOracleAbi);
}
get contractCSModule() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.csModule, index_js_1.CSModuleAbi);
}
get contractCSParametersRegistry() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.csParametersRegistry, index_js_1.CSParametersRegistryAbi);
}
get contractCSStrikes() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.csStrikes, index_js_1.CSStrikesAbi);
}
get contractCSExitPenalties() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.csExitPenalties, index_js_1.CSExitPenaltiesAbi);
}
get contractHashConsensus() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.hashConsensus, index_js_1.HashConsensusAbi);
}
get contractPermissionlessGate() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.permissionlessGate, index_js_1.PermissionlessGateAbi);
}
get contractVettedGate() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.vettedGate, index_js_1.VettedGateAbi);
}
get contractStakingRouter() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.stakingRouter, index_js_1.StakingRouterAbi);
}
get contractValidatorsExitBusOracle() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.validatorsExitBusOracle, index_js_1.ValidatorsExitBusOracleAbi);
}
get contractWithdrawalVault() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.withdrawalVault, index_js_1.WithdrawalVaultAbi);
}
get contractCSMSatellite() {
return this.getContract(index_js_3.CSM_CONTRACT_NAMES.CSMSatellite, index_js_1.CSMSatelliteAbi);
}
get moduleId() {
return index_js_3.MODULE_ID_BY_CHAIN[this.chainId];
}
get deploymentBlockNumber() {
return index_js_3.DEPLOYMENT_BLOCK_NUMBER_BY_CHAIN[this.chainId];
}
get externalLinks() {
return index_js_3.EXTERNAL_LINKS[this.chainId];
}
getExternalLink(type) {
return this.externalLinks[type];
}
get keysApiLink() {
return 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);
}
getIpfsUrls(cid) {
return [
`https://ipfs.io/ipfs/${cid}`,
`https://gateway.pinata.cloud/ipfs/${cid}`,
];
}
async performTransaction(props) {
this.core.useWeb3Provider();
const { callback = lido_ethereum_sdk_1.NOOP, getGasLimit, sendTransaction, decodeResult, waitForTransactionReceiptParameters = {}, } = props;
const account = await this.core.useAccount(props.account);
const isContract = await this.core.isContract(account.address);
let overrides = {
account,
chain: this.core.chain,
gas: undefined,
maxFeePerGas: undefined,
maxPriorityFeePerGas: undefined,
};
if (isContract) {
overrides = {
...overrides,
gas: 21000n,
maxFeePerGas: 1n,
maxPriorityFeePerGas: 1n,
nonce: 1,
};
}
else {
await callback({ stage: types_js_1.TransactionCallbackStage.GAS_LIMIT });
const feeData = await this.core.getFeeData();
overrides.maxFeePerGas = feeData.maxFeePerGas;
overrides.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
try {
overrides.gas = await getGasLimit({ ...overrides });
}
catch {
await (0, lido_ethereum_sdk_1.withSDKError)(getGasLimit({
...overrides,
maxFeePerGas: undefined,
maxPriorityFeePerGas: undefined,
}), lido_ethereum_sdk_1.ERROR_CODE.TRANSACTION_ERROR);
throw this.core.error({
code: lido_ethereum_sdk_1.ERROR_CODE.TRANSACTION_ERROR,
message: 'Not enough ether for gas',
});
}
}
const customGas = await callback({
stage: types_js_1.TransactionCallbackStage.SIGN,
payload: { gas: overrides.gas },
});
if (typeof customGas === 'bigint')
overrides.gas = customGas;
const hash = await (0, lido_ethereum_sdk_1.withSDKError)(sendTransaction({
...overrides,
}), lido_ethereum_sdk_1.ERROR_CODE.TRANSACTION_ERROR);
if (isContract) {
await callback({ stage: types_js_1.TransactionCallbackStage.MULTISIG_DONE });
return { hash };
}
await callback({
stage: types_js_1.TransactionCallbackStage.RECEIPT,
payload: { hash },
});
const receipt = await (0, lido_ethereum_sdk_1.withSDKError)(this.core.rpcProvider.waitForTransactionReceipt({
hash,
timeout: 120_000,
...waitForTransactionReceiptParameters,
}), lido_ethereum_sdk_1.ERROR_CODE.TRANSACTION_ERROR);
await callback({
stage: types_js_1.TransactionCallbackStage.CONFIRMATION,
payload: { receipt, hash },
});
const confirmations = await this.core.rpcProvider.getTransactionConfirmations({
hash: receipt.transactionHash,
});
const result = await decodeResult?.(receipt);
await callback({
stage: types_js_1.TransactionCallbackStage.DONE,
payload: {
result: result,
confirmations,
receipt,
hash,
},
});
return {
hash,
receipt,
result,
confirmations,
};
}
},
(() => {
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)(30 * 60 * 1000)];
_get_contractCSAccounting_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractCSEjector_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractCSFeeDistributor_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractCSFeeOracle_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractCSModule_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractCSParametersRegistry_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractCSStrikes_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractCSExitPenalties_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractHashConsensus_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractPermissionlessGate_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractVettedGate_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractStakingRouter_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractValidatorsExitBusOracle_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractWithdrawalVault_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
_get_contractCSMSatellite_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000)];
__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, _get_contractCSAccounting_decorators, { kind: "getter", name: "contractCSAccounting", static: false, private: false, access: { has: obj => "contractCSAccounting" in obj, get: obj => obj.contractCSAccounting }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractCSEjector_decorators, { kind: "getter", name: "contractCSEjector", static: false, private: false, access: { has: obj => "contractCSEjector" in obj, get: obj => obj.contractCSEjector }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractCSFeeDistributor_decorators, { kind: "getter", name: "contractCSFeeDistributor", static: false, private: false, access: { has: obj => "contractCSFeeDistributor" in obj, get: obj => obj.contractCSFeeDistributor }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractCSFeeOracle_decorators, { kind: "getter", name: "contractCSFeeOracle", static: false, private: false, access: { has: obj => "contractCSFeeOracle" in obj, get: obj => obj.contractCSFeeOracle }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractCSModule_decorators, { kind: "getter", name: "contractCSModule", static: false, private: false, access: { has: obj => "contractCSModule" in obj, get: obj => obj.contractCSModule }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractCSParametersRegistry_decorators, { kind: "getter", name: "contractCSParametersRegistry", static: false, private: false, access: { has: obj => "contractCSParametersRegistry" in obj, get: obj => obj.contractCSParametersRegistry }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractCSStrikes_decorators, { kind: "getter", name: "contractCSStrikes", static: false, private: false, access: { has: obj => "contractCSStrikes" in obj, get: obj => obj.contractCSStrikes }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractCSExitPenalties_decorators, { kind: "getter", name: "contractCSExitPenalties", static: false, private: false, access: { has: obj => "contractCSExitPenalties" in obj, get: obj => obj.contractCSExitPenalties }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractHashConsensus_decorators, { kind: "getter", name: "contractHashConsensus", static: false, private: false, access: { has: obj => "contractHashConsensus" in obj, get: obj => obj.contractHashConsensus }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractPermissionlessGate_decorators, { kind: "getter", name: "contractPermissionlessGate", static: false, private: false, access: { has: obj => "contractPermissionlessGate" in obj, get: obj => obj.contractPermissionlessGate }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractVettedGate_decorators, { kind: "getter", name: "contractVettedGate", static: false, private: false, access: { has: obj => "contractVettedGate" in obj, get: obj => obj.contractVettedGate }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractStakingRouter_decorators, { kind: "getter", name: "contractStakingRouter", static: false, private: false, access: { has: obj => "contractStakingRouter" in obj, get: obj => obj.contractStakingRouter }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractValidatorsExitBusOracle_decorators, { kind: "getter", name: "contractValidatorsExitBusOracle", static: false, private: false, access: { has: obj => "contractValidatorsExitBusOracle" in obj, get: obj => obj.contractValidatorsExitBusOracle }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractWithdrawalVault_decorators, { kind: "getter", name: "contractWithdrawalVault", static: false, private: false, access: { has: obj => "contractWithdrawalVault" in obj, get: obj => obj.contractWithdrawalVault }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _get_contractCSMSatellite_decorators, { kind: "getter", name: "contractCSMSatellite", static: false, private: false, access: { has: obj => "contractCSMSatellite" in obj, get: obj => obj.contractCSMSatellite }, 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