@continuumdao/ctm-mpc-defi 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/catalog.cjs +878 -141
- package/dist/agent/catalog.cjs.map +1 -1
- package/dist/agent/catalog.d.cts +756 -12
- package/dist/agent/catalog.d.ts +756 -12
- package/dist/agent/catalog.js +829 -142
- package/dist/agent/catalog.js.map +1 -1
- package/dist/chains/evm/index.cjs +13 -0
- package/dist/chains/evm/index.cjs.map +1 -1
- package/dist/chains/evm/index.d.cts +3 -1
- package/dist/chains/evm/index.d.ts +3 -1
- package/dist/chains/evm/index.js +13 -1
- package/dist/chains/evm/index.js.map +1 -1
- package/dist/index.cjs +825 -141
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +825 -142
- package/dist/index.js.map +1 -1
- package/dist/protocols/evm/aave-v4/index.cjs +1987 -0
- package/dist/protocols/evm/aave-v4/index.cjs.map +1 -0
- package/dist/protocols/evm/aave-v4/index.d.cts +500 -0
- package/dist/protocols/evm/aave-v4/index.d.ts +500 -0
- package/dist/protocols/evm/aave-v4/index.js +1943 -0
- package/dist/protocols/evm/aave-v4/index.js.map +1 -0
- package/dist/protocols/evm/ethena/index.cjs +965 -0
- package/dist/protocols/evm/ethena/index.cjs.map +1 -0
- package/dist/protocols/evm/ethena/index.d.cts +161 -0
- package/dist/protocols/evm/ethena/index.d.ts +161 -0
- package/dist/protocols/evm/ethena/index.js +943 -0
- package/dist/protocols/evm/ethena/index.js.map +1 -0
- package/dist/protocols/evm/euler-v2/index.cjs +2263 -0
- package/dist/protocols/evm/euler-v2/index.cjs.map +1 -0
- package/dist/protocols/evm/euler-v2/index.d.cts +317 -0
- package/dist/protocols/evm/euler-v2/index.d.ts +317 -0
- package/dist/protocols/evm/euler-v2/index.js +2238 -0
- package/dist/protocols/evm/euler-v2/index.js.map +1 -0
- package/dist/protocols/evm/lido/index.cjs +834 -0
- package/dist/protocols/evm/lido/index.cjs.map +1 -0
- package/dist/protocols/evm/lido/index.d.cts +120 -0
- package/dist/protocols/evm/lido/index.d.ts +120 -0
- package/dist/protocols/evm/lido/index.js +809 -0
- package/dist/protocols/evm/lido/index.js.map +1 -0
- package/dist/protocols/evm/maple/index.cjs +707 -0
- package/dist/protocols/evm/maple/index.cjs.map +1 -0
- package/dist/protocols/evm/maple/index.d.cts +109 -0
- package/dist/protocols/evm/maple/index.d.ts +109 -0
- package/dist/protocols/evm/maple/index.js +693 -0
- package/dist/protocols/evm/maple/index.js.map +1 -0
- package/dist/protocols/evm/sky/index.cjs +1254 -0
- package/dist/protocols/evm/sky/index.cjs.map +1 -0
- package/dist/protocols/evm/sky/index.d.cts +218 -0
- package/dist/protocols/evm/sky/index.d.ts +218 -0
- package/dist/protocols/evm/sky/index.js +1229 -0
- package/dist/protocols/evm/sky/index.js.map +1 -0
- package/package.json +37 -3
|
@@ -0,0 +1,834 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var viem = require('viem');
|
|
4
|
+
|
|
5
|
+
// src/core/registry.ts
|
|
6
|
+
var modules = [];
|
|
7
|
+
function registerProtocolModule(mod) {
|
|
8
|
+
const existing = modules.findIndex((m) => m.id === mod.id);
|
|
9
|
+
if (existing >= 0) {
|
|
10
|
+
modules[existing] = mod;
|
|
11
|
+
} else {
|
|
12
|
+
modules.push(mod);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
var LIDO_STETH_CONTRACT_MAINNET = viem.getAddress(
|
|
16
|
+
"0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"
|
|
17
|
+
);
|
|
18
|
+
var LIDO_WSTETH_CONTRACT_MAINNET = viem.getAddress(
|
|
19
|
+
"0x7f39C581F595B853cBbF37C12FfeeA971C5a5bEa"
|
|
20
|
+
);
|
|
21
|
+
var LIDO_WITHDRAWAL_QUEUE_MAINNET = viem.getAddress("0x889edC2eDab5f40e902b864aD4d7AdE8E412F9B1");
|
|
22
|
+
var LIDO_ETHEREUM_MAINNET_CHAIN_ID = 1;
|
|
23
|
+
var LIDO_SUBMIT_REFERRAL_MAINNET = viem.zeroAddress;
|
|
24
|
+
function isEthereumMainnetChainId(chainIdStr) {
|
|
25
|
+
return String(chainIdStr ?? "").trim() === String(LIDO_ETHEREUM_MAINNET_CHAIN_ID);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/core/keygen.ts
|
|
29
|
+
function firstClientIdFromKeyGen(data) {
|
|
30
|
+
const map = data?.ClientKeys;
|
|
31
|
+
if (!map || typeof map !== "object") return null;
|
|
32
|
+
for (const v of Object.values(map)) {
|
|
33
|
+
if (typeof v === "string" && v.trim()) return v.trim();
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/chains/evm/txParams.ts
|
|
39
|
+
function gasLimitFromEstimateAndChainConfig(estimatedGas, chainGasLimit) {
|
|
40
|
+
if (chainGasLimit == null || !Number.isFinite(chainGasLimit) || chainGasLimit <= 0) {
|
|
41
|
+
return estimatedGas;
|
|
42
|
+
}
|
|
43
|
+
const cfg = BigInt(Math.floor(chainGasLimit));
|
|
44
|
+
return cfg > estimatedGas ? cfg : estimatedGas;
|
|
45
|
+
}
|
|
46
|
+
async function fetchChainFeeParams(rpcUrl, chainId) {
|
|
47
|
+
const url = rpcUrl.trim();
|
|
48
|
+
if (!url) return { isEip1559: false };
|
|
49
|
+
const chainIdNum = chainId;
|
|
50
|
+
if (Number.isNaN(chainIdNum)) return { isEip1559: false };
|
|
51
|
+
const chain = viem.defineChain({
|
|
52
|
+
id: chainIdNum,
|
|
53
|
+
name: "Discovery",
|
|
54
|
+
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
|
|
55
|
+
rpcUrls: { default: { http: [url] } }
|
|
56
|
+
});
|
|
57
|
+
const publicClient = viem.createPublicClient({
|
|
58
|
+
chain,
|
|
59
|
+
transport: viem.http(url)
|
|
60
|
+
});
|
|
61
|
+
const getGasPriceGwei = async () => {
|
|
62
|
+
const gasPriceWei = await publicClient.getGasPrice();
|
|
63
|
+
return parseFloat(viem.formatUnits(gasPriceWei, 9));
|
|
64
|
+
};
|
|
65
|
+
try {
|
|
66
|
+
const block = await publicClient.getBlock({ blockTag: "latest" });
|
|
67
|
+
const baseFeePerGas = block?.baseFeePerGas;
|
|
68
|
+
if (baseFeePerGas == null || baseFeePerGas === void 0) {
|
|
69
|
+
const gasPriceGwei2 = await getGasPriceGwei();
|
|
70
|
+
return { isEip1559: false, gasPriceGwei: gasPriceGwei2 };
|
|
71
|
+
}
|
|
72
|
+
const baseFeeGwei = parseFloat(viem.formatUnits(baseFeePerGas, 9));
|
|
73
|
+
let priorityFeeGwei;
|
|
74
|
+
try {
|
|
75
|
+
const priorityWei = await publicClient.estimateMaxPriorityFeePerGas();
|
|
76
|
+
priorityFeeGwei = parseFloat(viem.formatUnits(priorityWei, 9));
|
|
77
|
+
} catch {
|
|
78
|
+
}
|
|
79
|
+
const gasPriceGwei = await getGasPriceGwei();
|
|
80
|
+
return {
|
|
81
|
+
isEip1559: true,
|
|
82
|
+
baseFeeGwei,
|
|
83
|
+
priorityFeeGwei,
|
|
84
|
+
gasPriceGwei
|
|
85
|
+
};
|
|
86
|
+
} catch {
|
|
87
|
+
try {
|
|
88
|
+
const gasPriceWei = await publicClient.getGasPrice();
|
|
89
|
+
const gasPriceGwei = parseFloat(viem.formatUnits(gasPriceWei, 9));
|
|
90
|
+
return { isEip1559: false, gasPriceGwei };
|
|
91
|
+
} catch {
|
|
92
|
+
return { isEip1559: false };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function finalizeEip1559Fees(maxFeePerGas, maxPriorityFeePerGas, floor, baseWei) {
|
|
97
|
+
let maxP = maxPriorityFeePerGas;
|
|
98
|
+
let maxF = maxFeePerGas;
|
|
99
|
+
if (baseWei > 0n && maxF < baseWei + maxP) {
|
|
100
|
+
maxF = baseWei + maxP + viem.parseGwei("0.001");
|
|
101
|
+
}
|
|
102
|
+
if (maxF < maxP) {
|
|
103
|
+
maxF = baseWei > 0n ? baseWei + maxP + viem.parseGwei("0.001") : maxP * 2n;
|
|
104
|
+
}
|
|
105
|
+
return { maxFeePerGas: maxF, maxPriorityFeePerGas: maxP };
|
|
106
|
+
}
|
|
107
|
+
function alignEip1559FeesWithLatestBase(maxFeePerGas, maxPriorityFeePerGas, latestBlockBaseFeeWei) {
|
|
108
|
+
return finalizeEip1559Fees(maxFeePerGas, maxPriorityFeePerGas, null, latestBlockBaseFeeWei);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/protocols/evm/lido/multisign.ts
|
|
112
|
+
var LIDO_SUBMIT_FALLBACK_GAS_UNITS = 450000n;
|
|
113
|
+
var LIDO_APPROVE_FALLBACK = 110000n;
|
|
114
|
+
var LIDO_REQUEST_WITHDRAWALS_FALLBACK_GAS_UNITS = 1350000n;
|
|
115
|
+
var LIDO_CLAIM_WITHDRAWAL_FALLBACK_GAS_UNITS = 900000n;
|
|
116
|
+
var LIDO_WSTETH_WRAP_FALLBACK_GAS_UNITS = 520000n;
|
|
117
|
+
var LIDO_WSTETH_UNWRAP_FALLBACK_GAS_UNITS = 600000n;
|
|
118
|
+
var MIN_LIDO_EXECUTE_GAS = 260000n;
|
|
119
|
+
var erc20Abi = viem.parseAbi([
|
|
120
|
+
"function allowance(address owner, address spender) view returns (uint256)",
|
|
121
|
+
"function approve(address spender, uint256 amount) returns (bool)"
|
|
122
|
+
]);
|
|
123
|
+
var lidoAbi = viem.parseAbi([
|
|
124
|
+
"function submit(address referral) payable returns (uint256)",
|
|
125
|
+
"function getSharesByPooledEth(uint256 ethAmount) view returns (uint256)"
|
|
126
|
+
]);
|
|
127
|
+
var wqAbi = viem.parseAbi([
|
|
128
|
+
"function MIN_STETH_WITHDRAWAL_AMOUNT() view returns (uint256)",
|
|
129
|
+
"function MAX_STETH_WITHDRAWAL_AMOUNT() view returns (uint256)",
|
|
130
|
+
"function requestWithdrawals(uint256[] amounts, address owner) returns (uint256[] requestIds)",
|
|
131
|
+
"function claimWithdrawal(uint256 requestId)"
|
|
132
|
+
]);
|
|
133
|
+
var wstethAbi = viem.parseAbi([
|
|
134
|
+
"function wrap(uint256 stETHAmount) returns (uint256)",
|
|
135
|
+
"function unwrap(uint256 wstETHAmount) returns (uint256)"
|
|
136
|
+
]);
|
|
137
|
+
function gweiToDecimalString(n) {
|
|
138
|
+
if (!Number.isFinite(n)) return "0";
|
|
139
|
+
if (n === 0) return "0";
|
|
140
|
+
const s = String(n);
|
|
141
|
+
if (s.indexOf("e") !== -1 || s.indexOf("E") !== -1) return n.toFixed(9).replace(/\.?0+$/, "") || "0";
|
|
142
|
+
return s;
|
|
143
|
+
}
|
|
144
|
+
function parseExtraJsonObject(detail) {
|
|
145
|
+
const raw = detail?.ExtraJSON ?? detail?.extraJSON;
|
|
146
|
+
if (raw == null) return null;
|
|
147
|
+
if (typeof raw === "object" && !Array.isArray(raw)) return raw;
|
|
148
|
+
if (typeof raw === "string" && raw.trim()) {
|
|
149
|
+
try {
|
|
150
|
+
const p = JSON.parse(raw);
|
|
151
|
+
if (p && typeof p === "object" && !Array.isArray(p)) return p;
|
|
152
|
+
} catch {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
function parseOptionalGasLimitString(raw) {
|
|
159
|
+
if (raw == null) return null;
|
|
160
|
+
const s = String(raw).trim();
|
|
161
|
+
if (!s) return null;
|
|
162
|
+
try {
|
|
163
|
+
if (/^0x[0-9a-fA-F]+$/.test(s)) return BigInt(s);
|
|
164
|
+
return BigInt(s);
|
|
165
|
+
} catch {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
var LIDO_EVM_TYPES = /* @__PURE__ */ new Set([
|
|
170
|
+
"lido_submit",
|
|
171
|
+
"lido_steth_approve",
|
|
172
|
+
"lido_request_withdrawals",
|
|
173
|
+
"lido_claim_withdrawal",
|
|
174
|
+
"lido_wsteth_wrap",
|
|
175
|
+
"lido_wsteth_unwrap"
|
|
176
|
+
]);
|
|
177
|
+
function lidoRequestWithdrawalsBatchIndices(detail) {
|
|
178
|
+
const ex = parseExtraJsonObject(detail);
|
|
179
|
+
if (!ex) return [];
|
|
180
|
+
const bm = ex.batchMeta;
|
|
181
|
+
if (!Array.isArray(bm)) return [];
|
|
182
|
+
const out = [];
|
|
183
|
+
bm.forEach((entry, idx) => {
|
|
184
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) return;
|
|
185
|
+
const evm = entry.evm;
|
|
186
|
+
if (!evm || typeof evm !== "object" || Array.isArray(evm)) return;
|
|
187
|
+
const t = String(evm.type ?? "").trim();
|
|
188
|
+
if (t === "lido_request_withdrawals") out.push(idx);
|
|
189
|
+
});
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
function isLidoBatchStepEvmSignRequest(detail, batchIndex) {
|
|
193
|
+
const ex = parseExtraJsonObject(detail);
|
|
194
|
+
if (!ex) return false;
|
|
195
|
+
const idx = batchIndex >= 0 ? batchIndex : 0;
|
|
196
|
+
const bm = ex.batchMeta;
|
|
197
|
+
if (Array.isArray(bm) && bm[idx] && typeof bm[idx] === "object" && !Array.isArray(bm[idx])) {
|
|
198
|
+
const evm0 = bm[idx].evm;
|
|
199
|
+
if (evm0 && typeof evm0 === "object" && !Array.isArray(evm0)) {
|
|
200
|
+
const t = String(evm0.type ?? "");
|
|
201
|
+
if (LIDO_EVM_TYPES.has(t)) return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
function resolveLidoBatchStepGasFromSignRequest(detail, batchIndex) {
|
|
207
|
+
if (!detail) return null;
|
|
208
|
+
const idx = batchIndex >= 0 ? batchIndex : 0;
|
|
209
|
+
const propBatch = detail.proposal_tx_params ?? detail.proposalTxParams ?? detail.ProposalTxParams;
|
|
210
|
+
if (Array.isArray(propBatch) && propBatch.length > idx) {
|
|
211
|
+
const row = propBatch[idx];
|
|
212
|
+
if (row && typeof row === "object" && !Array.isArray(row)) {
|
|
213
|
+
const r = row;
|
|
214
|
+
const gl = parseOptionalGasLimitString(
|
|
215
|
+
r.gas_limit ?? r.gasLimit ?? r.GasLimit
|
|
216
|
+
);
|
|
217
|
+
if (gl != null && gl > 0n) return gl;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const ex = parseExtraJsonObject(detail);
|
|
221
|
+
const bm = ex?.batchMeta;
|
|
222
|
+
if (Array.isArray(bm) && bm[idx] && typeof bm[idx] === "object" && !Array.isArray(bm[idx])) {
|
|
223
|
+
const l = bm[idx].lido;
|
|
224
|
+
const gs = l?.gasSubmit ?? l?.gasApprove ?? l?.gasRequestWithdrawals ?? l?.gasClaimWithdrawal ?? l?.gasWstethWrap ?? l?.gasWstethUnwrap;
|
|
225
|
+
const base = parseOptionalGasLimitString(gs?.baseGasUnits);
|
|
226
|
+
if (base != null && base > 0n) return base;
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
async function finalizeLidoMultipart(steps, args) {
|
|
231
|
+
const ph = (args.keyGen.pubkeyhex ?? "").trim();
|
|
232
|
+
if (!ph) throw new Error("keyGen pubKey (pubkeyhex) is required");
|
|
233
|
+
const keyList = args.keyGen.keylist ?? [];
|
|
234
|
+
const clientId = firstClientIdFromKeyGen(args.keyGen);
|
|
235
|
+
const ch = viem.defineChain({
|
|
236
|
+
id: LIDO_ETHEREUM_MAINNET_CHAIN_ID,
|
|
237
|
+
name: "Ethereum",
|
|
238
|
+
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
|
|
239
|
+
rpcUrls: { default: { http: [args.rpcUrl.trim()] } }
|
|
240
|
+
});
|
|
241
|
+
const publicClient = viem.createPublicClient({ chain: ch, transport: viem.http(args.rpcUrl.trim()) });
|
|
242
|
+
const feeParams = await fetchChainFeeParams(args.rpcUrl.trim(), LIDO_ETHEREUM_MAINNET_CHAIN_ID);
|
|
243
|
+
const legacy = Boolean(args.chainDetail?.legacy) || !feeParams.isEip1559;
|
|
244
|
+
const latestBaseFeeWei = !legacy ? (await publicClient.getBlock({ blockTag: "latest" })).baseFeePerGas ?? 0n : 0n;
|
|
245
|
+
const useCustomGas = args.useCustomGas;
|
|
246
|
+
const gasLimitConfig = useCustomGas && args.chainDetail?.gasLimit != null ? Number(args.chainDetail.gasLimit) : void 0;
|
|
247
|
+
const gasFeeMultiplier = useCustomGas && args.chainDetail?.gasMultiplier != null ? Number(args.chainDetail.gasMultiplier) : void 0;
|
|
248
|
+
const executor = viem.getAddress(args.executorAddress);
|
|
249
|
+
const baseNonce = await publicClient.getTransactionCount({ address: executor, blockTag: "pending" });
|
|
250
|
+
const messageHashes = [];
|
|
251
|
+
const messageRawBatch = [];
|
|
252
|
+
const proposalTxParamsBatch = [];
|
|
253
|
+
let firstTxFeePayload = {};
|
|
254
|
+
let firstDataNo0x = "";
|
|
255
|
+
const batchMeta = [];
|
|
256
|
+
for (let i = 0; i < steps.length; i++) {
|
|
257
|
+
const s = steps[i];
|
|
258
|
+
const v = viem.getAddress(s.to);
|
|
259
|
+
const data = s.data;
|
|
260
|
+
const currentNonce = baseNonce + i;
|
|
261
|
+
let estimatedGas;
|
|
262
|
+
try {
|
|
263
|
+
estimatedGas = await publicClient.estimateGas({
|
|
264
|
+
to: v,
|
|
265
|
+
data,
|
|
266
|
+
value: s.value,
|
|
267
|
+
account: executor
|
|
268
|
+
});
|
|
269
|
+
} catch {
|
|
270
|
+
estimatedGas = s.fallbackGas;
|
|
271
|
+
}
|
|
272
|
+
const gasLimitI = useCustomGas ? gasLimitFromEstimateAndChainConfig(estimatedGas, gasLimitConfig) : estimatedGas;
|
|
273
|
+
if (legacy) {
|
|
274
|
+
let gasPriceWei = await publicClient.getGasPrice();
|
|
275
|
+
if (useCustomGas && gasFeeMultiplier != null && gasFeeMultiplier > 0) {
|
|
276
|
+
gasPriceWei = gasPriceWei * BigInt(100 + gasFeeMultiplier) / 100n;
|
|
277
|
+
}
|
|
278
|
+
if (useCustomGas && args.chainDetail?.gasPrice != null && args.chainDetail.gasPrice > 0) {
|
|
279
|
+
const configured = viem.parseGwei(gweiToDecimalString(Number(args.chainDetail.gasPrice)));
|
|
280
|
+
if (configured > gasPriceWei) gasPriceWei = configured;
|
|
281
|
+
}
|
|
282
|
+
const ser = viem.serializeTransaction({
|
|
283
|
+
type: "legacy",
|
|
284
|
+
to: v,
|
|
285
|
+
data,
|
|
286
|
+
value: s.value,
|
|
287
|
+
gas: gasLimitI,
|
|
288
|
+
gasPrice: gasPriceWei,
|
|
289
|
+
nonce: currentNonce,
|
|
290
|
+
chainId: LIDO_ETHEREUM_MAINNET_CHAIN_ID
|
|
291
|
+
});
|
|
292
|
+
const h = viem.keccak256(ser);
|
|
293
|
+
messageHashes.push(h.startsWith("0x") ? h.slice(2) : h);
|
|
294
|
+
messageRawBatch.push(ser);
|
|
295
|
+
proposalTxParamsBatch.push({
|
|
296
|
+
nonce: currentNonce,
|
|
297
|
+
gasLimit: gasLimitI.toString(),
|
|
298
|
+
txType: "legacy",
|
|
299
|
+
gasPrice: gasPriceWei.toString()
|
|
300
|
+
});
|
|
301
|
+
if (i === 0) {
|
|
302
|
+
firstTxFeePayload = { txNonce: currentNonce, txGasLimit: gasLimitI.toString(), txGasPrice: gasPriceWei.toString() };
|
|
303
|
+
firstDataNo0x = data.startsWith("0x") ? data.slice(2) : data;
|
|
304
|
+
}
|
|
305
|
+
} else {
|
|
306
|
+
const fetchedBase = feeParams.baseFeeGwei ?? 0;
|
|
307
|
+
const fetchedPriority = feeParams.priorityFeeGwei ?? 0;
|
|
308
|
+
const configuredBase = useCustomGas && args.chainDetail?.baseFee != null ? Number(args.chainDetail.baseFee) : 0;
|
|
309
|
+
const configuredPriority = useCustomGas && args.chainDetail?.priorityFee != null ? Number(args.chainDetail.priorityFee) : 0;
|
|
310
|
+
const effectiveBaseFeeGwei = Math.max(fetchedBase, configuredBase);
|
|
311
|
+
const effectivePriorityFeeGwei = Math.max(fetchedPriority, configuredPriority);
|
|
312
|
+
const baseFeeMultiplierPct = useCustomGas && args.chainDetail?.baseFeeMultiplier != null ? Math.max(100, Number(args.chainDetail.baseFeeMultiplier)) : 100;
|
|
313
|
+
const baseComponentGwei = effectiveBaseFeeGwei * baseFeeMultiplierPct / 100;
|
|
314
|
+
const maxFeePerGasGwei = baseComponentGwei + effectivePriorityFeeGwei;
|
|
315
|
+
let maxPriorityFeePerGas = effectivePriorityFeeGwei > 0 ? viem.parseGwei(gweiToDecimalString(effectivePriorityFeeGwei)) : viem.parseGwei("1");
|
|
316
|
+
let maxFeePerGas = viem.parseGwei(gweiToDecimalString(maxFeePerGasGwei));
|
|
317
|
+
if (useCustomGas && gasFeeMultiplier != null && gasFeeMultiplier > 0) {
|
|
318
|
+
maxPriorityFeePerGas = maxPriorityFeePerGas * BigInt(100 + gasFeeMultiplier) / 100n;
|
|
319
|
+
maxFeePerGas = maxFeePerGas * BigInt(100 + gasFeeMultiplier) / 100n;
|
|
320
|
+
}
|
|
321
|
+
({ maxFeePerGas, maxPriorityFeePerGas } = alignEip1559FeesWithLatestBase(
|
|
322
|
+
maxFeePerGas,
|
|
323
|
+
maxPriorityFeePerGas,
|
|
324
|
+
latestBaseFeeWei
|
|
325
|
+
));
|
|
326
|
+
const ser = viem.serializeTransaction({
|
|
327
|
+
type: "eip1559",
|
|
328
|
+
to: v,
|
|
329
|
+
data,
|
|
330
|
+
value: s.value,
|
|
331
|
+
gas: gasLimitI,
|
|
332
|
+
maxFeePerGas,
|
|
333
|
+
maxPriorityFeePerGas,
|
|
334
|
+
nonce: currentNonce,
|
|
335
|
+
chainId: LIDO_ETHEREUM_MAINNET_CHAIN_ID
|
|
336
|
+
});
|
|
337
|
+
const h = viem.keccak256(ser);
|
|
338
|
+
messageHashes.push(h.startsWith("0x") ? h.slice(2) : h);
|
|
339
|
+
messageRawBatch.push(ser);
|
|
340
|
+
proposalTxParamsBatch.push({
|
|
341
|
+
nonce: currentNonce,
|
|
342
|
+
gasLimit: gasLimitI.toString(),
|
|
343
|
+
txType: "eip1559",
|
|
344
|
+
maxFeePerGas: maxFeePerGas.toString(),
|
|
345
|
+
maxPriorityFeePerGas: maxPriorityFeePerGas.toString()
|
|
346
|
+
});
|
|
347
|
+
if (i === 0) {
|
|
348
|
+
firstTxFeePayload = {
|
|
349
|
+
txNonce: currentNonce,
|
|
350
|
+
txGasLimit: gasLimitI.toString(),
|
|
351
|
+
txMaxFeePerGas: maxFeePerGas.toString(),
|
|
352
|
+
txMaxPriorityFeePerGas: maxPriorityFeePerGas.toString()
|
|
353
|
+
};
|
|
354
|
+
firstDataNo0x = data.startsWith("0x") ? data.slice(2) : data;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
batchMeta.push(s.buildBatchMeta({ gasLimit: gasLimitI }));
|
|
358
|
+
}
|
|
359
|
+
const extraPayload = { batchMeta };
|
|
360
|
+
if (useCustomGas && args.customGasChainDetails && Object.keys(args.customGasChainDetails).length > 0) {
|
|
361
|
+
extraPayload.customGasChainDetails = args.customGasChainDetails;
|
|
362
|
+
}
|
|
363
|
+
const extraJSON = JSON.stringify(extraPayload);
|
|
364
|
+
const firstSigText = batchMeta[0].signatureText;
|
|
365
|
+
const firstValue = steps[0].value;
|
|
366
|
+
const bodyForSign = {
|
|
367
|
+
keyList,
|
|
368
|
+
pubKey: ph,
|
|
369
|
+
msgHash: messageHashes[0],
|
|
370
|
+
msgRaw: firstDataNo0x,
|
|
371
|
+
messageHashes,
|
|
372
|
+
messageRawBatch,
|
|
373
|
+
destinationChainID: String(LIDO_ETHEREUM_MAINNET_CHAIN_ID),
|
|
374
|
+
destinationAddress: steps[0].to,
|
|
375
|
+
extraJSON,
|
|
376
|
+
signatureText: firstSigText,
|
|
377
|
+
purpose: (() => {
|
|
378
|
+
const t = args.purposeText.trim();
|
|
379
|
+
const suffix = args.purposeSuffix.trim();
|
|
380
|
+
return (t ? `${t}
|
|
381
|
+
|
|
382
|
+
` : "") + suffix;
|
|
383
|
+
})(),
|
|
384
|
+
...firstTxFeePayload,
|
|
385
|
+
proposalTxParams: proposalTxParamsBatch
|
|
386
|
+
};
|
|
387
|
+
if (firstValue > 0n) {
|
|
388
|
+
bodyForSign.value = firstValue.toString();
|
|
389
|
+
}
|
|
390
|
+
if (clientId) bodyForSign.clientId = clientId;
|
|
391
|
+
return { bodyForSign, messageToSign: JSON.stringify(bodyForSign) };
|
|
392
|
+
}
|
|
393
|
+
async function buildEvmMultisignBodyLidoSubmit(args) {
|
|
394
|
+
if (args.chainId !== LIDO_ETHEREUM_MAINNET_CHAIN_ID) {
|
|
395
|
+
throw new Error("Lido stake is supported on Ethereum mainnet (chain id 1) only.");
|
|
396
|
+
}
|
|
397
|
+
const lido = LIDO_STETH_CONTRACT_MAINNET;
|
|
398
|
+
const amt = viem.parseUnits(args.ethAmountHuman, 18);
|
|
399
|
+
if (amt === 0n) throw new Error("ETH amount must be greater than zero.");
|
|
400
|
+
const referral = viem.getAddress(LIDO_SUBMIT_REFERRAL_MAINNET);
|
|
401
|
+
const data = viem.encodeFunctionData({
|
|
402
|
+
abi: lidoAbi,
|
|
403
|
+
functionName: "submit",
|
|
404
|
+
args: [referral]
|
|
405
|
+
});
|
|
406
|
+
const step = {
|
|
407
|
+
to: lido,
|
|
408
|
+
data,
|
|
409
|
+
value: amt,
|
|
410
|
+
fallbackGas: LIDO_SUBMIT_FALLBACK_GAS_UNITS,
|
|
411
|
+
buildBatchMeta: ({ gasLimit }) => ({
|
|
412
|
+
destinationAddress: lido,
|
|
413
|
+
signatureText: JSON.stringify({
|
|
414
|
+
kind: "Lido",
|
|
415
|
+
name: "Lido.submit",
|
|
416
|
+
referral,
|
|
417
|
+
valueWei: amt.toString(),
|
|
418
|
+
ethAmountHuman: args.ethAmountHuman,
|
|
419
|
+
chainId: LIDO_ETHEREUM_MAINNET_CHAIN_ID
|
|
420
|
+
}),
|
|
421
|
+
evm: { type: "lido_submit", version: 1, chainId: String(LIDO_ETHEREUM_MAINNET_CHAIN_ID) },
|
|
422
|
+
lido: { step: "submit", ethAmountHuman: args.ethAmountHuman, gasSubmit: { baseGasUnits: gasLimit.toString() } }
|
|
423
|
+
})
|
|
424
|
+
};
|
|
425
|
+
const purposeSuffix = `Lido: stake ${args.ethAmountHuman} ETH \u2192 stETH (submit) on Ethereum.`;
|
|
426
|
+
return finalizeLidoMultipart([step], {
|
|
427
|
+
keyGen: args.keyGen,
|
|
428
|
+
rpcUrl: args.rpcUrl,
|
|
429
|
+
chainDetail: args.chainDetail,
|
|
430
|
+
useCustomGas: args.useCustomGas,
|
|
431
|
+
customGasChainDetails: args.customGasChainDetails,
|
|
432
|
+
purposeText: args.purposeText,
|
|
433
|
+
purposeSuffix,
|
|
434
|
+
executorAddress: args.executorAddress
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
async function buildEvmMultisignBodyLidoRequestWithdrawals(args) {
|
|
438
|
+
if (args.chainId !== LIDO_ETHEREUM_MAINNET_CHAIN_ID) {
|
|
439
|
+
throw new Error("Lido withdrawals are supported on Ethereum mainnet (chain id 1) only.");
|
|
440
|
+
}
|
|
441
|
+
const steth = LIDO_STETH_CONTRACT_MAINNET;
|
|
442
|
+
const wq = LIDO_WITHDRAWAL_QUEUE_MAINNET;
|
|
443
|
+
const ch = viem.defineChain({
|
|
444
|
+
id: LIDO_ETHEREUM_MAINNET_CHAIN_ID,
|
|
445
|
+
name: "Ethereum",
|
|
446
|
+
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
|
|
447
|
+
rpcUrls: { default: { http: [args.rpcUrl.trim()] } }
|
|
448
|
+
});
|
|
449
|
+
const publicClient = viem.createPublicClient({ chain: ch, transport: viem.http(args.rpcUrl.trim()) });
|
|
450
|
+
const amountWei = viem.parseUnits(args.stEthAmountHuman, 18);
|
|
451
|
+
if (amountWei === 0n) throw new Error("stETH amount must be greater than zero.");
|
|
452
|
+
const minW = await publicClient.readContract({
|
|
453
|
+
address: wq,
|
|
454
|
+
abi: wqAbi,
|
|
455
|
+
functionName: "MIN_STETH_WITHDRAWAL_AMOUNT"
|
|
456
|
+
});
|
|
457
|
+
const maxW = await publicClient.readContract({
|
|
458
|
+
address: wq,
|
|
459
|
+
abi: wqAbi,
|
|
460
|
+
functionName: "MAX_STETH_WITHDRAWAL_AMOUNT"
|
|
461
|
+
});
|
|
462
|
+
if (amountWei < minW) {
|
|
463
|
+
throw new Error(
|
|
464
|
+
`Withdrawal amount is below the queue minimum (${minW.toString()} wei of stETH; check decimals / protocol constants).`
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
if (amountWei > maxW) {
|
|
468
|
+
throw new Error(
|
|
469
|
+
`This flow sends a single request; amount exceeds the queue maximum (${maxW.toString()} wei). Split across multiple requests.`
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
const executor = viem.getAddress(args.executorAddress);
|
|
473
|
+
const ownerAddr = viem.getAddress(args.owner);
|
|
474
|
+
const steps = [];
|
|
475
|
+
let approvalNeeded = false;
|
|
476
|
+
const allowance = await publicClient.readContract({
|
|
477
|
+
address: steth,
|
|
478
|
+
abi: erc20Abi,
|
|
479
|
+
functionName: "allowance",
|
|
480
|
+
args: [executor, wq]
|
|
481
|
+
});
|
|
482
|
+
if (allowance < amountWei) {
|
|
483
|
+
approvalNeeded = true;
|
|
484
|
+
if (allowance > 0n) {
|
|
485
|
+
const dataReset = viem.encodeFunctionData({
|
|
486
|
+
abi: erc20Abi,
|
|
487
|
+
functionName: "approve",
|
|
488
|
+
args: [wq, 0n]
|
|
489
|
+
});
|
|
490
|
+
steps.push({
|
|
491
|
+
to: steth,
|
|
492
|
+
data: dataReset,
|
|
493
|
+
value: 0n,
|
|
494
|
+
fallbackGas: LIDO_APPROVE_FALLBACK,
|
|
495
|
+
buildBatchMeta: ({ gasLimit }) => ({
|
|
496
|
+
destinationAddress: steth,
|
|
497
|
+
signatureText: JSON.stringify({
|
|
498
|
+
kind: "Lido",
|
|
499
|
+
name: "stETH.approve (reset allowance before new amount)",
|
|
500
|
+
spender: wq,
|
|
501
|
+
chainId: LIDO_ETHEREUM_MAINNET_CHAIN_ID
|
|
502
|
+
}),
|
|
503
|
+
evm: { type: "lido_steth_approve", version: 1, chainId: String(LIDO_ETHEREUM_MAINNET_CHAIN_ID) },
|
|
504
|
+
lido: { step: "approve_reset", gasApprove: { baseGasUnits: gasLimit.toString() } }
|
|
505
|
+
})
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
const dataApprove = viem.encodeFunctionData({
|
|
509
|
+
abi: erc20Abi,
|
|
510
|
+
functionName: "approve",
|
|
511
|
+
args: [wq, amountWei]
|
|
512
|
+
});
|
|
513
|
+
steps.push({
|
|
514
|
+
to: steth,
|
|
515
|
+
data: dataApprove,
|
|
516
|
+
value: 0n,
|
|
517
|
+
fallbackGas: LIDO_APPROVE_FALLBACK,
|
|
518
|
+
buildBatchMeta: ({ gasLimit }) => ({
|
|
519
|
+
destinationAddress: steth,
|
|
520
|
+
signatureText: JSON.stringify({
|
|
521
|
+
kind: "Lido",
|
|
522
|
+
name: "stETH.approve",
|
|
523
|
+
spender: wq,
|
|
524
|
+
amountWei: amountWei.toString(),
|
|
525
|
+
chainId: LIDO_ETHEREUM_MAINNET_CHAIN_ID
|
|
526
|
+
}),
|
|
527
|
+
evm: { type: "lido_steth_approve", version: 1, chainId: String(LIDO_ETHEREUM_MAINNET_CHAIN_ID) },
|
|
528
|
+
lido: {
|
|
529
|
+
step: "approve_exact",
|
|
530
|
+
stEthAmountHuman: args.stEthAmountHuman,
|
|
531
|
+
gasApprove: { baseGasUnits: gasLimit.toString() }
|
|
532
|
+
}
|
|
533
|
+
})
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
const dataReq = viem.encodeFunctionData({
|
|
537
|
+
abi: wqAbi,
|
|
538
|
+
functionName: "requestWithdrawals",
|
|
539
|
+
args: [[amountWei], ownerAddr]
|
|
540
|
+
});
|
|
541
|
+
steps.push({
|
|
542
|
+
to: wq,
|
|
543
|
+
data: dataReq,
|
|
544
|
+
value: 0n,
|
|
545
|
+
fallbackGas: LIDO_REQUEST_WITHDRAWALS_FALLBACK_GAS_UNITS,
|
|
546
|
+
buildBatchMeta: ({ gasLimit }) => ({
|
|
547
|
+
destinationAddress: wq,
|
|
548
|
+
signatureText: JSON.stringify({
|
|
549
|
+
kind: "Lido",
|
|
550
|
+
name: "WithdrawalQueue.requestWithdrawals",
|
|
551
|
+
amountsWei: [amountWei.toString()],
|
|
552
|
+
owner: ownerAddr,
|
|
553
|
+
chainId: LIDO_ETHEREUM_MAINNET_CHAIN_ID
|
|
554
|
+
}),
|
|
555
|
+
evm: { type: "lido_request_withdrawals", version: 1, chainId: String(LIDO_ETHEREUM_MAINNET_CHAIN_ID) },
|
|
556
|
+
lido: {
|
|
557
|
+
step: "requestWithdrawals",
|
|
558
|
+
stEthAmountHuman: args.stEthAmountHuman,
|
|
559
|
+
owner: ownerAddr,
|
|
560
|
+
approvalNeeded,
|
|
561
|
+
gasRequestWithdrawals: { baseGasUnits: gasLimit.toString() }
|
|
562
|
+
}
|
|
563
|
+
})
|
|
564
|
+
});
|
|
565
|
+
const purposeSuffix = `Lido: withdrawal queue \u2014 approve (if needed) + requestWithdrawals (${args.stEthAmountHuman} stETH) on Ethereum (claim ETH in a follow-up tx when finalized).`;
|
|
566
|
+
return finalizeLidoMultipart(steps, {
|
|
567
|
+
keyGen: args.keyGen,
|
|
568
|
+
rpcUrl: args.rpcUrl,
|
|
569
|
+
chainDetail: args.chainDetail,
|
|
570
|
+
useCustomGas: args.useCustomGas,
|
|
571
|
+
customGasChainDetails: args.customGasChainDetails,
|
|
572
|
+
purposeText: args.purposeText,
|
|
573
|
+
purposeSuffix,
|
|
574
|
+
executorAddress: executor
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
async function buildEvmMultisignBodyLidoClaimWithdrawal(args) {
|
|
578
|
+
if (args.chainId !== LIDO_ETHEREUM_MAINNET_CHAIN_ID) {
|
|
579
|
+
throw new Error("Lido withdrawals are supported on Ethereum mainnet (chain id 1) only.");
|
|
580
|
+
}
|
|
581
|
+
if (args.requestId <= 0n) throw new Error("Withdrawal request id must be greater than zero.");
|
|
582
|
+
const wq = LIDO_WITHDRAWAL_QUEUE_MAINNET;
|
|
583
|
+
const data = viem.encodeFunctionData({
|
|
584
|
+
abi: wqAbi,
|
|
585
|
+
functionName: "claimWithdrawal",
|
|
586
|
+
args: [args.requestId]
|
|
587
|
+
});
|
|
588
|
+
const step = {
|
|
589
|
+
to: wq,
|
|
590
|
+
data,
|
|
591
|
+
value: 0n,
|
|
592
|
+
fallbackGas: LIDO_CLAIM_WITHDRAWAL_FALLBACK_GAS_UNITS,
|
|
593
|
+
buildBatchMeta: ({ gasLimit }) => ({
|
|
594
|
+
destinationAddress: wq,
|
|
595
|
+
signatureText: JSON.stringify({
|
|
596
|
+
kind: "Lido",
|
|
597
|
+
name: "WithdrawalQueue.claimWithdrawal",
|
|
598
|
+
requestId: args.requestId.toString(),
|
|
599
|
+
chainId: LIDO_ETHEREUM_MAINNET_CHAIN_ID
|
|
600
|
+
}),
|
|
601
|
+
evm: { type: "lido_claim_withdrawal", version: 1, chainId: String(LIDO_ETHEREUM_MAINNET_CHAIN_ID) },
|
|
602
|
+
lido: {
|
|
603
|
+
step: "claimWithdrawal",
|
|
604
|
+
requestId: args.requestId.toString(),
|
|
605
|
+
gasClaimWithdrawal: { baseGasUnits: gasLimit.toString() }
|
|
606
|
+
}
|
|
607
|
+
})
|
|
608
|
+
};
|
|
609
|
+
const purposeSuffix = `Lido: claim ETH for finalized withdrawal request #${args.requestId.toString()} on Ethereum (separate tx from requesting).`;
|
|
610
|
+
return finalizeLidoMultipart([step], {
|
|
611
|
+
keyGen: args.keyGen,
|
|
612
|
+
rpcUrl: args.rpcUrl,
|
|
613
|
+
chainDetail: args.chainDetail,
|
|
614
|
+
useCustomGas: args.useCustomGas,
|
|
615
|
+
customGasChainDetails: args.customGasChainDetails,
|
|
616
|
+
purposeText: args.purposeText,
|
|
617
|
+
purposeSuffix,
|
|
618
|
+
executorAddress: args.executorAddress
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
async function buildEvmMultisignBodyLidoWrapStEth(args) {
|
|
622
|
+
if (args.chainId !== LIDO_ETHEREUM_MAINNET_CHAIN_ID) {
|
|
623
|
+
throw new Error("Lido wrap is supported on Ethereum mainnet (chain id 1) only.");
|
|
624
|
+
}
|
|
625
|
+
const steth = LIDO_STETH_CONTRACT_MAINNET;
|
|
626
|
+
const wsteth = LIDO_WSTETH_CONTRACT_MAINNET;
|
|
627
|
+
const ch = viem.defineChain({
|
|
628
|
+
id: LIDO_ETHEREUM_MAINNET_CHAIN_ID,
|
|
629
|
+
name: "Ethereum",
|
|
630
|
+
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
|
|
631
|
+
rpcUrls: { default: { http: [args.rpcUrl.trim()] } }
|
|
632
|
+
});
|
|
633
|
+
const publicClient = viem.createPublicClient({ chain: ch, transport: viem.http(args.rpcUrl.trim()) });
|
|
634
|
+
const amountWei = viem.parseUnits(args.stEthAmountHuman, 18);
|
|
635
|
+
if (amountWei === 0n) throw new Error("stETH amount must be greater than zero.");
|
|
636
|
+
const executor = viem.getAddress(args.executorAddress);
|
|
637
|
+
const steps = [];
|
|
638
|
+
let approvalNeeded = false;
|
|
639
|
+
const allowance = await publicClient.readContract({
|
|
640
|
+
address: steth,
|
|
641
|
+
abi: erc20Abi,
|
|
642
|
+
functionName: "allowance",
|
|
643
|
+
args: [executor, wsteth]
|
|
644
|
+
});
|
|
645
|
+
if (allowance < amountWei) {
|
|
646
|
+
approvalNeeded = true;
|
|
647
|
+
if (allowance > 0n) {
|
|
648
|
+
const dataReset = viem.encodeFunctionData({
|
|
649
|
+
abi: erc20Abi,
|
|
650
|
+
functionName: "approve",
|
|
651
|
+
args: [wsteth, 0n]
|
|
652
|
+
});
|
|
653
|
+
steps.push({
|
|
654
|
+
to: steth,
|
|
655
|
+
data: dataReset,
|
|
656
|
+
value: 0n,
|
|
657
|
+
fallbackGas: LIDO_APPROVE_FALLBACK,
|
|
658
|
+
buildBatchMeta: ({ gasLimit }) => ({
|
|
659
|
+
destinationAddress: steth,
|
|
660
|
+
signatureText: JSON.stringify({
|
|
661
|
+
kind: "Lido",
|
|
662
|
+
name: "stETH.approve (reset for wstETH wrap)",
|
|
663
|
+
spender: wsteth,
|
|
664
|
+
chainId: LIDO_ETHEREUM_MAINNET_CHAIN_ID
|
|
665
|
+
}),
|
|
666
|
+
evm: { type: "lido_steth_approve", version: 1, chainId: String(LIDO_ETHEREUM_MAINNET_CHAIN_ID) },
|
|
667
|
+
lido: { step: "approve_wrap_reset", spender: "wstETH", gasApprove: { baseGasUnits: gasLimit.toString() } }
|
|
668
|
+
})
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
const dataApprove = viem.encodeFunctionData({
|
|
672
|
+
abi: erc20Abi,
|
|
673
|
+
functionName: "approve",
|
|
674
|
+
args: [wsteth, amountWei]
|
|
675
|
+
});
|
|
676
|
+
steps.push({
|
|
677
|
+
to: steth,
|
|
678
|
+
data: dataApprove,
|
|
679
|
+
value: 0n,
|
|
680
|
+
fallbackGas: LIDO_APPROVE_FALLBACK,
|
|
681
|
+
buildBatchMeta: ({ gasLimit }) => ({
|
|
682
|
+
destinationAddress: steth,
|
|
683
|
+
signatureText: JSON.stringify({
|
|
684
|
+
kind: "Lido",
|
|
685
|
+
name: "stETH.approve",
|
|
686
|
+
spender: wsteth,
|
|
687
|
+
amountWei: amountWei.toString(),
|
|
688
|
+
chainId: LIDO_ETHEREUM_MAINNET_CHAIN_ID
|
|
689
|
+
}),
|
|
690
|
+
evm: { type: "lido_steth_approve", version: 1, chainId: String(LIDO_ETHEREUM_MAINNET_CHAIN_ID) },
|
|
691
|
+
lido: {
|
|
692
|
+
step: "approve_wrap_exact",
|
|
693
|
+
stEthAmountHuman: args.stEthAmountHuman,
|
|
694
|
+
gasApprove: { baseGasUnits: gasLimit.toString() }
|
|
695
|
+
}
|
|
696
|
+
})
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
const dataWrap = viem.encodeFunctionData({
|
|
700
|
+
abi: wstethAbi,
|
|
701
|
+
functionName: "wrap",
|
|
702
|
+
args: [amountWei]
|
|
703
|
+
});
|
|
704
|
+
steps.push({
|
|
705
|
+
to: wsteth,
|
|
706
|
+
data: dataWrap,
|
|
707
|
+
value: 0n,
|
|
708
|
+
fallbackGas: LIDO_WSTETH_WRAP_FALLBACK_GAS_UNITS,
|
|
709
|
+
buildBatchMeta: ({ gasLimit }) => ({
|
|
710
|
+
destinationAddress: wsteth,
|
|
711
|
+
signatureText: JSON.stringify({
|
|
712
|
+
kind: "Lido",
|
|
713
|
+
name: "WstETH.wrap",
|
|
714
|
+
stEthAmountWei: amountWei.toString(),
|
|
715
|
+
chainId: LIDO_ETHEREUM_MAINNET_CHAIN_ID
|
|
716
|
+
}),
|
|
717
|
+
evm: { type: "lido_wsteth_wrap", version: 1, chainId: String(LIDO_ETHEREUM_MAINNET_CHAIN_ID) },
|
|
718
|
+
lido: {
|
|
719
|
+
step: "wrap",
|
|
720
|
+
stEthAmountHuman: args.stEthAmountHuman,
|
|
721
|
+
approvalNeeded,
|
|
722
|
+
gasWstethWrap: { baseGasUnits: gasLimit.toString() }
|
|
723
|
+
}
|
|
724
|
+
})
|
|
725
|
+
});
|
|
726
|
+
const purposeSuffix = `Lido: approve (if needed) + wrap (${args.stEthAmountHuman} stETH \u2192 wstETH) on Ethereum.`;
|
|
727
|
+
return finalizeLidoMultipart(steps, {
|
|
728
|
+
keyGen: args.keyGen,
|
|
729
|
+
rpcUrl: args.rpcUrl,
|
|
730
|
+
chainDetail: args.chainDetail,
|
|
731
|
+
useCustomGas: args.useCustomGas,
|
|
732
|
+
customGasChainDetails: args.customGasChainDetails,
|
|
733
|
+
purposeText: args.purposeText,
|
|
734
|
+
purposeSuffix,
|
|
735
|
+
executorAddress: executor
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
async function buildEvmMultisignBodyLidoUnwrapWstEth(args) {
|
|
739
|
+
if (args.chainId !== LIDO_ETHEREUM_MAINNET_CHAIN_ID) {
|
|
740
|
+
throw new Error("Lido unwrap is supported on Ethereum mainnet (chain id 1) only.");
|
|
741
|
+
}
|
|
742
|
+
const wsteth = LIDO_WSTETH_CONTRACT_MAINNET;
|
|
743
|
+
const amt = viem.parseUnits(args.wstEthAmountHuman, 18);
|
|
744
|
+
if (amt === 0n) throw new Error("wstETH amount must be greater than zero.");
|
|
745
|
+
const data = viem.encodeFunctionData({
|
|
746
|
+
abi: wstethAbi,
|
|
747
|
+
functionName: "unwrap",
|
|
748
|
+
args: [amt]
|
|
749
|
+
});
|
|
750
|
+
const step = {
|
|
751
|
+
to: wsteth,
|
|
752
|
+
data,
|
|
753
|
+
value: 0n,
|
|
754
|
+
fallbackGas: LIDO_WSTETH_UNWRAP_FALLBACK_GAS_UNITS,
|
|
755
|
+
buildBatchMeta: ({ gasLimit }) => ({
|
|
756
|
+
destinationAddress: wsteth,
|
|
757
|
+
signatureText: JSON.stringify({
|
|
758
|
+
kind: "Lido",
|
|
759
|
+
name: "WstETH.unwrap",
|
|
760
|
+
wstEthAmountWei: amt.toString(),
|
|
761
|
+
chainId: LIDO_ETHEREUM_MAINNET_CHAIN_ID
|
|
762
|
+
}),
|
|
763
|
+
evm: { type: "lido_wsteth_unwrap", version: 1, chainId: String(LIDO_ETHEREUM_MAINNET_CHAIN_ID) },
|
|
764
|
+
lido: {
|
|
765
|
+
step: "unwrap",
|
|
766
|
+
wstEthAmountHuman: args.wstEthAmountHuman,
|
|
767
|
+
gasWstethUnwrap: { baseGasUnits: gasLimit.toString() }
|
|
768
|
+
}
|
|
769
|
+
})
|
|
770
|
+
};
|
|
771
|
+
const purposeSuffix = `Lido: unwrap (${args.wstEthAmountHuman} wstETH \u2192 stETH) on Ethereum.`;
|
|
772
|
+
return finalizeLidoMultipart([step], {
|
|
773
|
+
keyGen: args.keyGen,
|
|
774
|
+
rpcUrl: args.rpcUrl,
|
|
775
|
+
chainDetail: args.chainDetail,
|
|
776
|
+
useCustomGas: args.useCustomGas,
|
|
777
|
+
customGasChainDetails: args.customGasChainDetails,
|
|
778
|
+
purposeText: args.purposeText,
|
|
779
|
+
purposeSuffix,
|
|
780
|
+
executorAddress: args.executorAddress
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
function isLidoEvmSignRequestForEstimateWorkaround(detail, batchIndex) {
|
|
784
|
+
return isLidoBatchStepEvmSignRequest(detail, batchIndex ?? 0);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// src/protocols/evm/lido/index.ts
|
|
788
|
+
var LIDO_PROTOCOL_ID = "lido";
|
|
789
|
+
var lidoProtocolModule = {
|
|
790
|
+
id: LIDO_PROTOCOL_ID,
|
|
791
|
+
chainCategory: "evm",
|
|
792
|
+
isChainSupported(ctx) {
|
|
793
|
+
if (ctx.chainCategory !== "evm") return false;
|
|
794
|
+
return Number(ctx.chainId) === LIDO_ETHEREUM_MAINNET_CHAIN_ID;
|
|
795
|
+
},
|
|
796
|
+
isTokenSupported(token) {
|
|
797
|
+
return token.category === "evm" && (token.kind === "native" || token.kind === "erc20");
|
|
798
|
+
},
|
|
799
|
+
actions: [
|
|
800
|
+
{ id: "lido.submit", protocolId: LIDO_PROTOCOL_ID, chainCategory: "evm", description: "Stake ETH via Lido submit()", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: { valueWei: { type: "string", required: true, description: "ETH to stake (wei string)" } } },
|
|
801
|
+
{ id: "lido.request-withdrawals", protocolId: LIDO_PROTOCOL_ID, chainCategory: "evm", description: "Queue stETH withdrawal", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} },
|
|
802
|
+
{ id: "lido.claim-withdrawal", protocolId: LIDO_PROTOCOL_ID, chainCategory: "evm", description: "Claim finalized withdrawal", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} },
|
|
803
|
+
{ id: "lido.wrap-steth", protocolId: LIDO_PROTOCOL_ID, chainCategory: "evm", description: "Wrap stETH to wstETH", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} },
|
|
804
|
+
{ id: "lido.unwrap-wsteth", protocolId: LIDO_PROTOCOL_ID, chainCategory: "evm", description: "Unwrap wstETH to stETH", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} }
|
|
805
|
+
]
|
|
806
|
+
};
|
|
807
|
+
registerProtocolModule(lidoProtocolModule);
|
|
808
|
+
|
|
809
|
+
exports.LIDO_CLAIM_WITHDRAWAL_FALLBACK_GAS_UNITS = LIDO_CLAIM_WITHDRAWAL_FALLBACK_GAS_UNITS;
|
|
810
|
+
exports.LIDO_ETHEREUM_MAINNET_CHAIN_ID = LIDO_ETHEREUM_MAINNET_CHAIN_ID;
|
|
811
|
+
exports.LIDO_EVM_TYPES = LIDO_EVM_TYPES;
|
|
812
|
+
exports.LIDO_PROTOCOL_ID = LIDO_PROTOCOL_ID;
|
|
813
|
+
exports.LIDO_REQUEST_WITHDRAWALS_FALLBACK_GAS_UNITS = LIDO_REQUEST_WITHDRAWALS_FALLBACK_GAS_UNITS;
|
|
814
|
+
exports.LIDO_STETH_CONTRACT_MAINNET = LIDO_STETH_CONTRACT_MAINNET;
|
|
815
|
+
exports.LIDO_SUBMIT_FALLBACK_GAS_UNITS = LIDO_SUBMIT_FALLBACK_GAS_UNITS;
|
|
816
|
+
exports.LIDO_SUBMIT_REFERRAL_MAINNET = LIDO_SUBMIT_REFERRAL_MAINNET;
|
|
817
|
+
exports.LIDO_WITHDRAWAL_QUEUE_MAINNET = LIDO_WITHDRAWAL_QUEUE_MAINNET;
|
|
818
|
+
exports.LIDO_WSTETH_CONTRACT_MAINNET = LIDO_WSTETH_CONTRACT_MAINNET;
|
|
819
|
+
exports.LIDO_WSTETH_UNWRAP_FALLBACK_GAS_UNITS = LIDO_WSTETH_UNWRAP_FALLBACK_GAS_UNITS;
|
|
820
|
+
exports.LIDO_WSTETH_WRAP_FALLBACK_GAS_UNITS = LIDO_WSTETH_WRAP_FALLBACK_GAS_UNITS;
|
|
821
|
+
exports.MIN_LIDO_EXECUTE_GAS = MIN_LIDO_EXECUTE_GAS;
|
|
822
|
+
exports.buildEvmMultisignBodyLidoClaimWithdrawal = buildEvmMultisignBodyLidoClaimWithdrawal;
|
|
823
|
+
exports.buildEvmMultisignBodyLidoRequestWithdrawals = buildEvmMultisignBodyLidoRequestWithdrawals;
|
|
824
|
+
exports.buildEvmMultisignBodyLidoSubmit = buildEvmMultisignBodyLidoSubmit;
|
|
825
|
+
exports.buildEvmMultisignBodyLidoUnwrapWstEth = buildEvmMultisignBodyLidoUnwrapWstEth;
|
|
826
|
+
exports.buildEvmMultisignBodyLidoWrapStEth = buildEvmMultisignBodyLidoWrapStEth;
|
|
827
|
+
exports.isEthereumMainnetChainId = isEthereumMainnetChainId;
|
|
828
|
+
exports.isLidoBatchStepEvmSignRequest = isLidoBatchStepEvmSignRequest;
|
|
829
|
+
exports.isLidoEvmSignRequestForEstimateWorkaround = isLidoEvmSignRequestForEstimateWorkaround;
|
|
830
|
+
exports.lidoProtocolModule = lidoProtocolModule;
|
|
831
|
+
exports.lidoRequestWithdrawalsBatchIndices = lidoRequestWithdrawalsBatchIndices;
|
|
832
|
+
exports.resolveLidoBatchStepGasFromSignRequest = resolveLidoBatchStepGasFromSignRequest;
|
|
833
|
+
//# sourceMappingURL=index.cjs.map
|
|
834
|
+
//# sourceMappingURL=index.cjs.map
|