@lidofinance/lido-ethereum-sdk
Version:
<div style="display: flex;" align="center"> <h1 align="center">Lido Ethereum SDK</h1> </div>
268 lines • 21.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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LidoSDKDualGovernance = void 0;
const viem_1 = require("viem");
const index_js_1 = require("../common/index.js");
const sdk_module_js_1 = require("../common/class-primitives/sdk-module.js");
const index_js_2 = require("../common/decorators/index.js");
const DualGovernance_js_1 = require("./abi/DualGovernance.js");
const Escrow_js_1 = require("./abi/Escrow.js");
const EmergencyProtectedTimelock_js_1 = require("./abi/EmergencyProtectedTimelock.js");
const DGConfigProvider_js_1 = require("./abi/DGConfigProvider.js");
const types_js_1 = require("./types.js");
let LidoSDKDualGovernance = (() => {
var _a;
let _classSuper = sdk_module_js_1.LidoSDKModule;
let _instanceExtraInitializers = [];
let _getContractEmergencyProtectedTimelockAddress_decorators;
let _getContractEmergencyProtectedTimelock_decorators;
let _getContractDualGovernance_decorators;
let _getContractVetoSignallingEscrow_decorators;
let _getContractStETH_decorators;
let _getContractDualGovernanceConfigProvider_decorators;
let _getGovernanceAddress_decorators;
let _getVetoSignallingEscrowAddress_decorators;
let _getStETHAddress_decorators;
let _getDualGovernanceConfigProviderAddress_decorators;
let _getVetoSignallingEscrowLockedAssets_decorators;
let _getTotalStEthInEscrow_decorators;
let _getDualGovernanceConfig_decorators;
let _getTotalStETHSupply_decorators;
let _calculateCurrentVetoSignallingThresholdProgress_decorators;
let _getDualGovernanceState_decorators;
let _getGovernanceWarningStatus_decorators;
return _a = class LidoSDKDualGovernance extends _classSuper {
getContractEmergencyProtectedTimelockAddress() {
return this.core.getDualGovernanceContractAddress(index_js_1.DUAL_GOVERNANCE_CONTRACT_NAMES.EPT);
}
async getContractEmergencyProtectedTimelock() {
const address = this.getContractEmergencyProtectedTimelockAddress();
(0, index_js_1.invariant)(address, `EmergencyProtectedTimelock is not supported on ${this.core.chain.name}`, index_js_1.ERROR_CODE.NOT_SUPPORTED);
return (0, index_js_1.getEncodableContract)((0, viem_1.getContract)({
address,
abi: EmergencyProtectedTimelock_js_1.emergencyProtectedTimelockAbi,
client: this.core.keyedClient,
}));
}
async getContractDualGovernance() {
const address = await this.getGovernanceAddress();
(0, index_js_1.invariant)(address, `Couldn't fetch DualGovernance address on chain ${this.core.chain.name}`, index_js_1.ERROR_CODE.READ_ERROR);
return (0, index_js_1.getEncodableContract)((0, viem_1.getContract)({
address,
abi: DualGovernance_js_1.dualGovernanceAbi,
client: this.core.keyedClient,
}));
}
async getContractVetoSignallingEscrow() {
const address = await this.getVetoSignallingEscrowAddress();
(0, index_js_1.invariant)(address, `Couldn't fetch VetoSignallingEscrow address on chain ${this.core.chain.name}`, index_js_1.ERROR_CODE.READ_ERROR);
return (0, index_js_1.getEncodableContract)((0, viem_1.getContract)({
address,
abi: Escrow_js_1.escrowAbi,
client: this.core.keyedClient,
}));
}
async getContractStETH() {
return this.core.getLidoContract();
}
async getContractDualGovernanceConfigProvider() {
const address = await this.getDualGovernanceConfigProviderAddress();
(0, index_js_1.invariant)(address, `Couldn't fetch DualGovernanceConfigProvider address on chain ${this.core.chain.name}`, index_js_1.ERROR_CODE.READ_ERROR);
return (0, index_js_1.getEncodableContract)((0, viem_1.getContract)({
address,
abi: DGConfigProvider_js_1.dgConfigProviderAbi,
client: this.core.keyedClient,
}));
}
async getGovernanceAddress() {
const emergencyProtectedTimelockContract = await this.getContractEmergencyProtectedTimelock();
return await emergencyProtectedTimelockContract.read.getGovernance();
}
async getVetoSignallingEscrowAddress() {
const dualGovernanceContract = await this.getContractDualGovernance();
return await dualGovernanceContract.read.getVetoSignallingEscrow();
}
async getStETHAddress() {
const vetoSignallingContract = await this.getContractVetoSignallingEscrow();
return await vetoSignallingContract.read.ST_ETH();
}
async getDualGovernanceConfigProviderAddress() {
const dualGovernanceContract = await this.getContractDualGovernance();
return await dualGovernanceContract.read.getConfigProvider();
}
async getVetoSignallingEscrowLockedAssets() {
const vetoSignallingContract = await this.getContractVetoSignallingEscrow();
return await vetoSignallingContract.read.getSignallingEscrowDetails();
}
async getTotalStEthInEscrow() {
const stETHContract = await this.getContractStETH();
const vetoSignallingEscrowLockedAssets = await this.getVetoSignallingEscrowLockedAssets();
const unfinalizedShares = vetoSignallingEscrowLockedAssets.totalStETHLockedShares +
vetoSignallingEscrowLockedAssets.totalUnstETHUnfinalizedShares;
const pooledEthByShares = await stETHContract.read.getPooledEthByShares([
unfinalizedShares,
]);
return (pooledEthByShares +
vetoSignallingEscrowLockedAssets.totalUnstETHFinalizedETH);
}
async getDualGovernanceConfig() {
const dualGovernanceConfigProvider = await this.getContractDualGovernanceConfigProvider();
return await dualGovernanceConfigProvider.read.getDualGovernanceConfig();
}
async getTotalStETHSupply() {
const stETHContract = await this.getContractStETH();
return await stETHContract.read.totalSupply();
}
async calculateCurrentVetoSignallingThresholdProgress() {
const [totalStETHSupply, dualGovernanceConfig, totalStEthInEscrow] = await Promise.all([
this.getTotalStETHSupply(),
this.getDualGovernanceConfig(),
this.getTotalStEthInEscrow(),
]);
const targetPercent = Number((0, viem_1.formatUnits)(dualGovernanceConfig.firstSealRageQuitSupport, 16));
const currentSupport = totalStEthInEscrow;
if (targetPercent < 0 || currentSupport < 0n || totalStETHSupply < 0n) {
return { currentSupportPercent: 0 };
}
if (totalStETHSupply === 0n) {
const percent = currentSupport > 0n ? 100 : 0;
return { currentSupportPercent: percent };
}
const targetValue = (totalStETHSupply * BigInt(targetPercent)) / 100n;
if (targetValue === 0n) {
const percent = currentSupport > 0n ? 100 : 0;
return { currentSupportPercent: percent };
}
const thresholdSupportPercentBigInt = (currentSupport * 100n) / targetValue;
let thresholdSupportPercentNumber = Number(thresholdSupportPercentBigInt);
if (thresholdSupportPercentNumber > 100)
thresholdSupportPercentNumber = 100;
if (thresholdSupportPercentNumber < 0)
thresholdSupportPercentNumber = 0;
return {
currentSupportPercent: thresholdSupportPercentNumber,
};
}
async getDualGovernanceState() {
const dualGovernanceContract = await this.getContractDualGovernance();
const { persistedState } = await dualGovernanceContract.read.getStateDetails();
return persistedState;
}
async getGovernanceWarningStatus({ triggerPercent, }) {
const currentGovernanceState = await this.getDualGovernanceState();
const { currentSupportPercent } = await this.calculateCurrentVetoSignallingThresholdProgress();
const NORMAL_STATES = [
types_js_1.GovernanceState.Normal,
types_js_1.GovernanceState.VetoCooldown,
];
const BLOCKED_STATES = [
types_js_1.GovernanceState.VetoSignalling,
types_js_1.GovernanceState.VetoSignallingDeactivation,
types_js_1.GovernanceState.RageQuit,
];
if (BLOCKED_STATES.includes(currentGovernanceState)) {
return {
state: 'Blocked',
currentVetoSupportPercent: currentSupportPercent,
};
}
if (NORMAL_STATES.includes(currentGovernanceState)) {
if (currentSupportPercent > triggerPercent) {
return {
state: 'Warning',
currentVetoSupportPercent: currentSupportPercent,
};
}
else {
return {
state: 'Normal',
currentVetoSupportPercent: currentSupportPercent,
};
}
}
return {
state: 'Unknown',
currentVetoSupportPercent: null,
};
}
constructor() {
super(...arguments);
__runInitializers(this, _instanceExtraInitializers);
}
},
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_getContractEmergencyProtectedTimelockAddress_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getContractEmergencyProtectedTimelock_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getContractDualGovernance_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getContractVetoSignallingEscrow_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getContractStETH_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getContractDualGovernanceConfigProvider_decorators = [(0, index_js_2.Logger)('Contracts:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getGovernanceAddress_decorators = [(0, index_js_2.Logger)('Views:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getVetoSignallingEscrowAddress_decorators = [(0, index_js_2.Logger)('Views:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getStETHAddress_decorators = [(0, index_js_2.Logger)('Views:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getDualGovernanceConfigProviderAddress_decorators = [(0, index_js_2.Logger)('Views:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getVetoSignallingEscrowLockedAssets_decorators = [(0, index_js_2.Logger)('Views:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getTotalStEthInEscrow_decorators = [(0, index_js_2.Logger)('Views:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getDualGovernanceConfig_decorators = [(0, index_js_2.Logger)('Views:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getTotalStETHSupply_decorators = [(0, index_js_2.Logger)('Views:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_calculateCurrentVetoSignallingThresholdProgress_decorators = [(0, index_js_2.Logger)('Views:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getDualGovernanceState_decorators = [(0, index_js_2.Logger)('Views:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id'])];
_getGovernanceWarningStatus_decorators = [(0, index_js_2.Logger)('Views:'), (0, index_js_2.Cache)(30 * 60 * 1000, ['core.chain.id', 'triggerPercent'])];
__esDecorate(_a, null, _getContractEmergencyProtectedTimelockAddress_decorators, { kind: "method", name: "getContractEmergencyProtectedTimelockAddress", static: false, private: false, access: { has: obj => "getContractEmergencyProtectedTimelockAddress" in obj, get: obj => obj.getContractEmergencyProtectedTimelockAddress }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getContractEmergencyProtectedTimelock_decorators, { kind: "method", name: "getContractEmergencyProtectedTimelock", static: false, private: false, access: { has: obj => "getContractEmergencyProtectedTimelock" in obj, get: obj => obj.getContractEmergencyProtectedTimelock }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getContractDualGovernance_decorators, { kind: "method", name: "getContractDualGovernance", static: false, private: false, access: { has: obj => "getContractDualGovernance" in obj, get: obj => obj.getContractDualGovernance }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getContractVetoSignallingEscrow_decorators, { kind: "method", name: "getContractVetoSignallingEscrow", static: false, private: false, access: { has: obj => "getContractVetoSignallingEscrow" in obj, get: obj => obj.getContractVetoSignallingEscrow }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getContractStETH_decorators, { kind: "method", name: "getContractStETH", static: false, private: false, access: { has: obj => "getContractStETH" in obj, get: obj => obj.getContractStETH }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getContractDualGovernanceConfigProvider_decorators, { kind: "method", name: "getContractDualGovernanceConfigProvider", static: false, private: false, access: { has: obj => "getContractDualGovernanceConfigProvider" in obj, get: obj => obj.getContractDualGovernanceConfigProvider }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getGovernanceAddress_decorators, { kind: "method", name: "getGovernanceAddress", static: false, private: false, access: { has: obj => "getGovernanceAddress" in obj, get: obj => obj.getGovernanceAddress }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getVetoSignallingEscrowAddress_decorators, { kind: "method", name: "getVetoSignallingEscrowAddress", static: false, private: false, access: { has: obj => "getVetoSignallingEscrowAddress" in obj, get: obj => obj.getVetoSignallingEscrowAddress }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getStETHAddress_decorators, { kind: "method", name: "getStETHAddress", static: false, private: false, access: { has: obj => "getStETHAddress" in obj, get: obj => obj.getStETHAddress }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getDualGovernanceConfigProviderAddress_decorators, { kind: "method", name: "getDualGovernanceConfigProviderAddress", static: false, private: false, access: { has: obj => "getDualGovernanceConfigProviderAddress" in obj, get: obj => obj.getDualGovernanceConfigProviderAddress }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getVetoSignallingEscrowLockedAssets_decorators, { kind: "method", name: "getVetoSignallingEscrowLockedAssets", static: false, private: false, access: { has: obj => "getVetoSignallingEscrowLockedAssets" in obj, get: obj => obj.getVetoSignallingEscrowLockedAssets }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getTotalStEthInEscrow_decorators, { kind: "method", name: "getTotalStEthInEscrow", static: false, private: false, access: { has: obj => "getTotalStEthInEscrow" in obj, get: obj => obj.getTotalStEthInEscrow }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getDualGovernanceConfig_decorators, { kind: "method", name: "getDualGovernanceConfig", static: false, private: false, access: { has: obj => "getDualGovernanceConfig" in obj, get: obj => obj.getDualGovernanceConfig }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getTotalStETHSupply_decorators, { kind: "method", name: "getTotalStETHSupply", static: false, private: false, access: { has: obj => "getTotalStETHSupply" in obj, get: obj => obj.getTotalStETHSupply }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _calculateCurrentVetoSignallingThresholdProgress_decorators, { kind: "method", name: "calculateCurrentVetoSignallingThresholdProgress", static: false, private: false, access: { has: obj => "calculateCurrentVetoSignallingThresholdProgress" in obj, get: obj => obj.calculateCurrentVetoSignallingThresholdProgress }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getDualGovernanceState_decorators, { kind: "method", name: "getDualGovernanceState", static: false, private: false, access: { has: obj => "getDualGovernanceState" in obj, get: obj => obj.getDualGovernanceState }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(_a, null, _getGovernanceWarningStatus_decorators, { kind: "method", name: "getGovernanceWarningStatus", static: false, private: false, access: { has: obj => "getGovernanceWarningStatus" in obj, get: obj => obj.getGovernanceWarningStatus }, metadata: _metadata }, null, _instanceExtraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
_a;
})();
exports.LidoSDKDualGovernance = LidoSDKDualGovernance;
//# sourceMappingURL=dual-governance.js.map