@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
324 lines • 20.5 kB
JavaScript
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, NOOP, withSDKError, } from '@lidofinance/lido-ethereum-sdk';
import { getContract, } from 'viem';
import { CSAccountingAbi, CSEjectorAbi, CSExitPenaltiesAbi, CSFeeDistributorAbi, CSFeeOracleAbi, CSModuleAbi, CSParametersRegistryAbi, CSStrikesAbi, CSMSatelliteAbi, HashConsensusAbi, PermissionlessGateAbi, StakingRouterAbi, ValidatorsExitBusOracleAbi, VettedGateAbi, WithdrawalVaultAbi, } from '../abi/index.js';
import { CsmSDKCacheable } from '../common/class-primitives/csm-sdk-cacheable.js';
import { Cache, Logger } from '../common/decorators/index.js';
import { CSM_CONTRACT_ADDRESSES, CSM_CONTRACT_NAMES, DEPLOYMENT_BLOCK_NUMBER_BY_CHAIN, EXTERNAL_LINKS, LINK_TYPE, MODULE_ID_BY_CHAIN, } from '../common/index.js';
import { TransactionCallbackStage, } from './types.js';
let CoreSDK = (() => {
var _a;
let _classSuper = 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] ??
CSM_CONTRACT_ADDRESSES[this.chainId]?.[contract];
invariant(address, `CSM contract [${contract}] are not supported for ${this.core.chain.name}(${this.core.chain.id})`, ERROR_CODE.NOT_SUPPORTED);
return address;
}
getContract(contractName, abi) {
return getContract({
address: this.getContractAddress(contractName),
abi,
client: {
public: this.core.rpcProvider,
wallet: this.core.web3Provider,
},
});
}
get contractCSAccounting() {
return this.getContract(CSM_CONTRACT_NAMES.csAccounting, CSAccountingAbi);
}
get contractCSEjector() {
return this.getContract(CSM_CONTRACT_NAMES.csEjector, CSEjectorAbi);
}
get contractCSFeeDistributor() {
return this.getContract(CSM_CONTRACT_NAMES.csFeeDistributor, CSFeeDistributorAbi);
}
get contractCSFeeOracle() {
return this.getContract(CSM_CONTRACT_NAMES.csFeeOracle, CSFeeOracleAbi);
}
get contractCSModule() {
return this.getContract(CSM_CONTRACT_NAMES.csModule, CSModuleAbi);
}
get contractCSParametersRegistry() {
return this.getContract(CSM_CONTRACT_NAMES.csParametersRegistry, CSParametersRegistryAbi);
}
get contractCSStrikes() {
return this.getContract(CSM_CONTRACT_NAMES.csStrikes, CSStrikesAbi);
}
get contractCSExitPenalties() {
return this.getContract(CSM_CONTRACT_NAMES.csExitPenalties, CSExitPenaltiesAbi);
}
get contractHashConsensus() {
return this.getContract(CSM_CONTRACT_NAMES.hashConsensus, HashConsensusAbi);
}
get contractPermissionlessGate() {
return this.getContract(CSM_CONTRACT_NAMES.permissionlessGate, PermissionlessGateAbi);
}
get contractVettedGate() {
return this.getContract(CSM_CONTRACT_NAMES.vettedGate, VettedGateAbi);
}
get contractStakingRouter() {
return this.getContract(CSM_CONTRACT_NAMES.stakingRouter, StakingRouterAbi);
}
get contractValidatorsExitBusOracle() {
return this.getContract(CSM_CONTRACT_NAMES.validatorsExitBusOracle, ValidatorsExitBusOracleAbi);
}
get contractWithdrawalVault() {
return this.getContract(CSM_CONTRACT_NAMES.withdrawalVault, WithdrawalVaultAbi);
}
get contractCSMSatellite() {
return this.getContract(CSM_CONTRACT_NAMES.CSMSatellite, CSMSatelliteAbi);
}
get moduleId() {
return MODULE_ID_BY_CHAIN[this.chainId];
}
get deploymentBlockNumber() {
return DEPLOYMENT_BLOCK_NUMBER_BY_CHAIN[this.chainId];
}
get externalLinks() {
return EXTERNAL_LINKS[this.chainId];
}
getExternalLink(type) {
return this.externalLinks[type];
}
get keysApiLink() {
return this.getExternalLink(LINK_TYPE.keysApi);
}
get rewardsTreeLink() {
return this.getExternalLink(LINK_TYPE.rewardsTree);
}
get icsTreeLink() {
return this.getExternalLink(LINK_TYPE.icsTree);
}
getIpfsUrls(cid) {
return [
`https://ipfs.io/ipfs/${cid}`,
`https://gateway.pinata.cloud/ipfs/${cid}`,
];
}
async performTransaction(props) {
// this guards against not having web3Provider
this.core.useWeb3Provider();
const { callback = 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) {
// passing these stub params prevent unnecessary possibly errorish RPC calls
overrides = {
...overrides,
gas: 21000n,
maxFeePerGas: 1n,
maxPriorityFeePerGas: 1n,
nonce: 1,
};
}
else {
await callback({ stage: TransactionCallbackStage.GAS_LIMIT });
const feeData = await this.core.getFeeData();
overrides.maxFeePerGas = feeData.maxFeePerGas;
overrides.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
try {
overrides.gas = await getGasLimit({ ...overrides });
}
catch {
// we retry without fees to see if tx will go trough
await withSDKError(getGasLimit({
...overrides,
maxFeePerGas: undefined,
maxPriorityFeePerGas: undefined,
}), ERROR_CODE.TRANSACTION_ERROR);
throw this.core.error({
code: ERROR_CODE.TRANSACTION_ERROR,
message: 'Not enough ether for gas',
});
}
}
const customGas = await callback({
stage: TransactionCallbackStage.SIGN,
payload: { gas: overrides.gas },
});
if (typeof customGas === 'bigint')
overrides.gas = customGas;
const hash = await withSDKError(sendTransaction({
...overrides,
}), ERROR_CODE.TRANSACTION_ERROR);
if (isContract) {
await callback({ stage: TransactionCallbackStage.MULTISIG_DONE });
return { hash };
}
await callback({
stage: TransactionCallbackStage.RECEIPT,
payload: { hash },
});
const receipt = await withSDKError(this.core.rpcProvider.waitForTransactionReceipt({
hash,
timeout: 120_000,
...waitForTransactionReceiptParameters,
}), ERROR_CODE.TRANSACTION_ERROR);
await callback({
stage: TransactionCallbackStage.CONFIRMATION,
payload: { receipt, hash },
});
const confirmations = await this.core.rpcProvider.getTransactionConfirmations({
hash: receipt.transactionHash,
});
const result = await decodeResult?.(receipt);
await callback({
stage: 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 = [Logger('Utils:'), Cache(30 * 60 * 1000)];
_get_contractCSAccounting_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractCSEjector_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractCSFeeDistributor_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractCSFeeOracle_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractCSModule_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractCSParametersRegistry_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractCSStrikes_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractCSExitPenalties_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractHashConsensus_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractPermissionlessGate_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractVettedGate_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractStakingRouter_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractValidatorsExitBusOracle_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractWithdrawalVault_decorators = [Logger('Contracts:'), Cache(30 * 60 * 1000)];
_get_contractCSMSatellite_decorators = [Logger('Contracts:'), 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;
})();
export { CoreSDK };
//# sourceMappingURL=core-sdk.js.map