@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
174 lines • 10.3 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, SDKError } from '@lidofinance/lido-ethereum-sdk';
import { zeroAddress } from 'viem';
import { CsmSDKModule } from '../common/class-primitives/csm-sdk-module.js';
import { ErrorHandler, Logger } from '../common/decorators/index.js';
import { EJECT_FEE_MIN_LIMIT, EJECT_FEE_MULTIPLIEER, TOKENS, } from '../common/index.js';
import { prepCall } from '../tx-sdk/index.js';
import { parseAddKeysProps } from './parse-add-keys-props.js';
let KeysSDK = (() => {
var _a;
let _classSuper = CsmSDKModule;
let _instanceExtraInitializers = [];
let _addKeysETH_decorators;
let _addKeysStETH_decorators;
let _addKeysWstETH_decorators;
let _removeKeys_decorators;
let _ejectKeys_decorators;
let _ejectKeysByArray_decorators;
let _getEjectFeePerKey_decorators;
return _a = class KeysSDK extends _classSuper {
get moduleContract() {
return this.core.contractBaseModule;
}
get ejectorContract() {
return this.core.contractEjector;
}
async addKeysETH(props) {
const { nodeOperatorId, amount, keysCount, publicKeys, signatures, permit, ...rest } = await parseAddKeysProps(props);
return this.bus.tx.perform({
...rest,
call: ({ from }) => prepCall(this.moduleContract, 'addValidatorKeysETH', [from, nodeOperatorId, keysCount, publicKeys, signatures], amount),
});
}
async addKeysStETH(props) {
const { nodeOperatorId, amount, keysCount, publicKeys, signatures, permit, ...rest } = await parseAddKeysProps(props);
return this.bus.tx.perform({
...rest,
spend: { token: TOKENS.steth, amount, permit },
call: ({ from, permit }) => prepCall(this.moduleContract, 'addValidatorKeysStETH', [
from,
nodeOperatorId,
keysCount,
publicKeys,
signatures,
permit,
]),
});
}
async addKeysWstETH(props) {
const { nodeOperatorId, amount, keysCount, publicKeys, signatures, permit, ...rest } = await parseAddKeysProps(props);
return this.bus.tx.perform({
...rest,
spend: { token: TOKENS.wsteth, amount, permit },
call: ({ from, permit }) => prepCall(this.moduleContract, 'addValidatorKeysWstETH', [
from,
nodeOperatorId,
keysCount,
publicKeys,
signatures,
permit,
]),
});
}
async addKeys(props) {
const { token } = props;
if (props.amount === 0n) {
return this.addKeysStETH(props);
}
switch (token) {
case TOKENS.eth:
return this.addKeysETH(props);
case TOKENS.steth:
return this.addKeysStETH(props);
case TOKENS.wsteth:
return this.addKeysWstETH(props);
default:
throw new SDKError({
message: 'unsupported token',
code: ERROR_CODE.INVALID_ARGUMENT,
});
}
}
async removeKeys(props) {
const { nodeOperatorId, startIndex, keysCount, ...rest } = props;
return this.bus.tx.perform({
...rest,
call: () => prepCall(this.moduleContract, 'removeKeys', [
nodeOperatorId,
startIndex,
keysCount,
]),
});
}
async ejectKeys(props) {
const { nodeOperatorId, startIndex, keysCount, amount, refundRecipient = zeroAddress, ...rest } = props;
return this.bus.tx.perform({
...rest,
call: () => prepCall(this.ejectorContract, 'voluntaryEject', [nodeOperatorId, startIndex, keysCount, refundRecipient], amount),
});
}
async ejectKeysByArray(props) {
const { nodeOperatorId, keyIndices, amount, refundRecipient = zeroAddress, ...rest } = props;
return this.bus.tx.perform({
...rest,
call: () => prepCall(this.ejectorContract, 'voluntaryEjectByArray', [nodeOperatorId, keyIndices, refundRecipient], amount),
});
}
async getEjectFeePerKey() {
const fee = await this.core.contractWithdrawalVault.read.getWithdrawalRequestFee();
const correctedFee = fee * EJECT_FEE_MULTIPLIEER;
return correctedFee < EJECT_FEE_MIN_LIMIT
? EJECT_FEE_MIN_LIMIT
: correctedFee;
}
constructor() {
super(...arguments);
__runInitializers(this, _instanceExtraInitializers);
}
},
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_addKeysETH_decorators = [Logger('Call:'), ErrorHandler()];
_addKeysStETH_decorators = [Logger('Call:'), ErrorHandler()];
_addKeysWstETH_decorators = [Logger('Call:'), ErrorHandler()];
_removeKeys_decorators = [Logger('Call:'), ErrorHandler()];
_ejectKeys_decorators = [Logger('Call:'), ErrorHandler()];
_ejectKeysByArray_decorators = [Logger('Call:'), ErrorHandler()];
_getEjectFeePerKey_decorators = [Logger('Views:'), ErrorHandler()];
__esDecorate(_a, null, _addKeysETH_decorators, { kind: "method", name: "addKeysETH", static: false, private: false, access: { has: obj => "addKeysETH" in obj, get: obj => obj.addKeysETH }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _addKeysStETH_decorators, { kind: "method", name: "addKeysStETH", static: false, private: false, access: { has: obj => "addKeysStETH" in obj, get: obj => obj.addKeysStETH }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _addKeysWstETH_decorators, { kind: "method", name: "addKeysWstETH", static: false, private: false, access: { has: obj => "addKeysWstETH" in obj, get: obj => obj.addKeysWstETH }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _removeKeys_decorators, { kind: "method", name: "removeKeys", static: false, private: false, access: { has: obj => "removeKeys" in obj, get: obj => obj.removeKeys }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _ejectKeys_decorators, { kind: "method", name: "ejectKeys", static: false, private: false, access: { has: obj => "ejectKeys" in obj, get: obj => obj.ejectKeys }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _ejectKeysByArray_decorators, { kind: "method", name: "ejectKeysByArray", static: false, private: false, access: { has: obj => "ejectKeysByArray" in obj, get: obj => obj.ejectKeysByArray }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getEjectFeePerKey_decorators, { kind: "method", name: "getEjectFeePerKey", static: false, private: false, access: { has: obj => "getEjectFeePerKey" in obj, get: obj => obj.getEjectFeePerKey }, metadata: _metadata }, null, _instanceExtraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
_a;
})();
export { KeysSDK };
//# sourceMappingURL=keys-sdk.js.map