@continuumdao/ctm-mpc-defi 0.2.0 → 0.2.2
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/README.md +20 -78
- package/dist/agent/catalog.cjs +563 -5
- package/dist/agent/catalog.cjs.map +1 -1
- package/dist/agent/catalog.d.ts +166 -20
- package/dist/agent/catalog.js +551 -7
- package/dist/agent/catalog.js.map +1 -1
- package/dist/agent/skills/aave-v4/SKILL.md +43 -0
- package/dist/agent/skills/curve-dao/SKILL.md +13 -0
- package/dist/agent/skills/ethena/SKILL.md +10 -0
- package/dist/agent/skills/euler-v2/SKILL.md +10 -0
- package/dist/agent/skills/lido/SKILL.md +22 -0
- package/dist/agent/skills/maple-syrup/SKILL.md +10 -0
- package/dist/agent/skills/sky/SKILL.md +10 -0
- package/dist/agent/skills/uniswap-v4/SKILL.md +22 -0
- package/dist/chains/evm/index.cjs +79 -224
- package/dist/chains/evm/index.cjs.map +1 -1
- package/dist/chains/evm/index.d.ts +26 -26
- package/dist/chains/evm/index.js +69 -209
- package/dist/chains/evm/index.js.map +1 -1
- package/dist/chains/near/index.d.ts +1 -1
- package/dist/chains/solana/index.d.ts +1 -1
- package/dist/core/index.cjs +68 -106
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +21 -36
- package/dist/core/index.js +57 -96
- package/dist/core/index.js.map +1 -1
- package/dist/{envelope-CcE5Cz_q.d.ts → envelope-CpBUh9eP.d.ts} +1 -1
- package/dist/index.cjs +356 -1855
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -11
- package/dist/index.js +332 -1826
- package/dist/index.js.map +1 -1
- package/dist/protocols/evm/aave-v4/index.cjs +1152 -669
- package/dist/protocols/evm/aave-v4/index.cjs.map +1 -1
- package/dist/protocols/evm/aave-v4/index.d.ts +418 -3
- package/dist/protocols/evm/aave-v4/index.js +1126 -670
- package/dist/protocols/evm/aave-v4/index.js.map +1 -1
- package/dist/protocols/evm/curve-dao/index.cjs +257 -131
- package/dist/protocols/evm/curve-dao/index.cjs.map +1 -1
- package/dist/protocols/evm/curve-dao/index.d.ts +69 -5
- package/dist/protocols/evm/curve-dao/index.js +242 -124
- package/dist/protocols/evm/curve-dao/index.js.map +1 -1
- package/dist/protocols/evm/ethena/index.cjs +394 -402
- package/dist/protocols/evm/ethena/index.cjs.map +1 -1
- package/dist/protocols/evm/ethena/index.d.ts +47 -3
- package/dist/protocols/evm/ethena/index.js +390 -404
- package/dist/protocols/evm/ethena/index.js.map +1 -1
- package/dist/protocols/evm/euler-v2/index.cjs +2810 -1191
- package/dist/protocols/evm/euler-v2/index.cjs.map +1 -1
- package/dist/protocols/evm/euler-v2/index.d.ts +465 -3
- package/dist/protocols/evm/euler-v2/index.js +2761 -1192
- package/dist/protocols/evm/euler-v2/index.js.map +1 -1
- package/dist/protocols/evm/lido/index.cjs +351 -236
- package/dist/protocols/evm/lido/index.cjs.map +1 -1
- package/dist/protocols/evm/lido/index.d.ts +34 -4
- package/dist/protocols/evm/lido/index.js +348 -238
- package/dist/protocols/evm/lido/index.js.map +1 -1
- package/dist/protocols/evm/maple/index.cjs +390 -395
- package/dist/protocols/evm/maple/index.cjs.map +1 -1
- package/dist/protocols/evm/maple/index.d.ts +23 -3
- package/dist/protocols/evm/maple/index.js +390 -397
- package/dist/protocols/evm/maple/index.js.map +1 -1
- package/dist/protocols/evm/sky/index.cjs +454 -232
- package/dist/protocols/evm/sky/index.cjs.map +1 -1
- package/dist/protocols/evm/sky/index.d.ts +57 -3
- package/dist/protocols/evm/sky/index.js +444 -231
- package/dist/protocols/evm/sky/index.js.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.cjs +423 -658
- package/dist/protocols/evm/uniswap-v4/index.cjs.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.d.ts +3 -4
- package/dist/protocols/evm/uniswap-v4/index.js +422 -657
- package/dist/protocols/evm/uniswap-v4/index.js.map +1 -1
- package/dist/{registry-oMKlO_5z.d.ts → registry-Bv5o37_w.d.ts} +1 -1
- package/dist/{types-Ce2qNHai.d.cts → types-BfjWdw1j.d.ts} +3 -1
- package/dist/{types-5u863Fd9.d.ts → types-DUeNJLr9.d.ts} +1 -1
- package/package.json +7 -6
- package/dist/agent/catalog.d.cts +0 -939
- package/dist/chains/evm/index.d.cts +0 -64
- package/dist/chains/near/index.d.cts +0 -37
- package/dist/chains/solana/index.d.cts +0 -40
- package/dist/core/index.d.cts +0 -43
- package/dist/envelope-DYDPnrHZ.d.cts +0 -35
- package/dist/index.d.cts +0 -16
- package/dist/keygen-CfNp8yKJ.d.cts +0 -9
- package/dist/keygen-DsINazx8.d.ts +0 -9
- package/dist/nodeRead-BnmSaMGO.d.cts +0 -8
- package/dist/nodeRead-BnmSaMGO.d.ts +0 -8
- package/dist/protocols/evm/aave-v4/index.d.cts +0 -500
- package/dist/protocols/evm/curve-dao/index.d.cts +0 -147
- package/dist/protocols/evm/ethena/index.d.cts +0 -161
- package/dist/protocols/evm/euler-v2/index.d.cts +0 -317
- package/dist/protocols/evm/lido/index.d.cts +0 -120
- package/dist/protocols/evm/maple/index.d.cts +0 -109
- package/dist/protocols/evm/sky/index.d.cts +0 -218
- package/dist/protocols/evm/uniswap-v4/index.d.cts +0 -324
- package/dist/registry-BwZoE668.d.cts +0 -8
- package/dist/txParams-BC7ogvdR.d.cts +0 -19
- package/dist/txParams-BC7ogvdR.d.ts +0 -19
- package/dist/types-B8idm_gu.d.cts +0 -34
- package/dist/types-Ce2qNHai.d.ts +0 -57
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { parseAbi, getAddress, defineChain, createPublicClient, http, parseUnits, encodeFunctionData, parseGwei, serializeTransaction, keccak256
|
|
1
|
+
import { parseAbi, getAddress, defineChain, createPublicClient, http, parseUnits, encodeFunctionData, parseGwei, serializeTransaction, keccak256 } from 'viem';
|
|
2
|
+
import { fetchChainFeeParams, gasLimitFromEstimateAndChainConfig, gweiToDecimalString, proposalTxParamsToFeeSnapshot, alignEip1559FeesWithLatestBase, getClientIdFromKeyGenResult } from '@continuumdao/continuum-node-sdk';
|
|
3
|
+
import { mainnet } from 'viem/chains';
|
|
2
4
|
|
|
3
5
|
// src/core/registry.ts
|
|
4
6
|
var modules = [];
|
|
@@ -142,101 +144,239 @@ function isEvmChainInEthenaUsdeList(chainId) {
|
|
|
142
144
|
return usdeTokenAddressOnEvmChain(chainId) != null;
|
|
143
145
|
}
|
|
144
146
|
|
|
145
|
-
// src/core/
|
|
146
|
-
function
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
147
|
+
// src/core/purpose.ts
|
|
148
|
+
function mergePurposeText(purposeText, purposeSuffix) {
|
|
149
|
+
const t = purposeText.trim();
|
|
150
|
+
const suffix = (purposeSuffix ?? "").trim();
|
|
151
|
+
if (!suffix) return t;
|
|
152
|
+
return t ? `${t}
|
|
153
|
+
|
|
154
|
+
${suffix}` : suffix;
|
|
153
155
|
}
|
|
154
156
|
|
|
155
|
-
// src/
|
|
156
|
-
function
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
// src/core/envelope.ts
|
|
158
|
+
function finalizeMultisign(input) {
|
|
159
|
+
const { keyGen, destinationChainID, legs } = input;
|
|
160
|
+
if (legs.length === 0) {
|
|
161
|
+
throw new Error("finalizeMultisign requires at least one leg");
|
|
162
|
+
}
|
|
163
|
+
const ph = (keyGen.pubkeyhex ?? "").trim();
|
|
164
|
+
if (!ph) throw new Error("keyGen pubKey (pubkeyhex) is required");
|
|
165
|
+
const keyList = keyGen.keylist ?? [];
|
|
166
|
+
const clientId = getClientIdFromKeyGenResult(keyGen);
|
|
167
|
+
const first = legs[0];
|
|
168
|
+
const messageHashes = legs.map((l) => l.msgHash);
|
|
169
|
+
const messageRawBatch = legs.map((l) => l.msgRaw);
|
|
170
|
+
const batchMeta = legs.map((l) => ({
|
|
171
|
+
destinationAddress: l.destinationAddress,
|
|
172
|
+
signatureText: l.signatureText,
|
|
173
|
+
...l.audit
|
|
174
|
+
}));
|
|
175
|
+
const proposalTxParams = legs.map((l) => l.proposalTxParams).filter((p) => p != null && typeof p === "object");
|
|
176
|
+
const extraPayload = {
|
|
177
|
+
batchMeta,
|
|
178
|
+
...input.extraJSON ?? {}
|
|
179
|
+
};
|
|
180
|
+
const extraJSON = JSON.stringify(extraPayload);
|
|
181
|
+
const bodyForSign = {
|
|
182
|
+
keyList,
|
|
183
|
+
pubKey: ph,
|
|
184
|
+
msgHash: messageHashes[0],
|
|
185
|
+
msgRaw: first.msgRaw,
|
|
186
|
+
destinationChainID,
|
|
187
|
+
destinationAddress: input.destinationAddress ?? first.destinationAddress,
|
|
188
|
+
extraJSON,
|
|
189
|
+
signatureText: first.signatureText,
|
|
190
|
+
purpose: mergePurposeText(input.purposeText, input.purposeSuffix),
|
|
191
|
+
...first.feeSnapshot
|
|
192
|
+
};
|
|
193
|
+
if (legs.length > 1) {
|
|
194
|
+
bodyForSign.messageHashes = messageHashes;
|
|
195
|
+
bodyForSign.messageRawBatch = messageRawBatch;
|
|
196
|
+
}
|
|
197
|
+
if (proposalTxParams.length > 0) {
|
|
198
|
+
bodyForSign.proposalTxParams = proposalTxParams;
|
|
199
|
+
}
|
|
200
|
+
const valueWei = first.valueWei;
|
|
201
|
+
if (valueWei != null && valueWei > 0n) {
|
|
202
|
+
bodyForSign.value = valueWei.toString();
|
|
203
|
+
}
|
|
204
|
+
if (clientId) bodyForSign.clientId = clientId;
|
|
205
|
+
return { bodyForSign, messageToSign: JSON.stringify(bodyForSign) };
|
|
206
|
+
}
|
|
207
|
+
function routerSwapGasLimitFromEstimate(estimatedGas, chainGasLimit) {
|
|
208
|
+
if (chainGasLimit != null && Number.isFinite(chainGasLimit) && chainGasLimit > 0) {
|
|
209
|
+
return gasLimitFromEstimateAndChainConfig(estimatedGas, chainGasLimit);
|
|
159
210
|
}
|
|
160
|
-
|
|
161
|
-
return cfg > estimatedGas ? cfg : estimatedGas;
|
|
211
|
+
return (estimatedGas * 12n + 9n) / 10n;
|
|
162
212
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
213
|
+
|
|
214
|
+
// src/chains/evm/buildBatch.ts
|
|
215
|
+
async function buildEvmMultisignBatch(args) {
|
|
216
|
+
const { context, steps } = args;
|
|
217
|
+
const {
|
|
218
|
+
chainId,
|
|
219
|
+
rpcUrl,
|
|
220
|
+
executorAddress,
|
|
221
|
+
chainDetail,
|
|
222
|
+
useCustomGas,
|
|
223
|
+
customGasChainDetails,
|
|
224
|
+
keyGen,
|
|
225
|
+
purposeText
|
|
226
|
+
} = context;
|
|
227
|
+
if (steps.length === 0) throw new Error("buildEvmMultisignBatch requires at least one step");
|
|
228
|
+
const ch = defineChain({
|
|
229
|
+
id: chainId,
|
|
230
|
+
name: "Destination",
|
|
171
231
|
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
|
|
172
|
-
rpcUrls: { default: { http: [
|
|
232
|
+
rpcUrls: { default: { http: [rpcUrl] } }
|
|
173
233
|
});
|
|
174
|
-
const publicClient = createPublicClient({
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
});
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
234
|
+
const publicClient = createPublicClient({ chain: ch, transport: http(rpcUrl) });
|
|
235
|
+
const feeParams = await fetchChainFeeParams(rpcUrl, chainId);
|
|
236
|
+
const legacy = Boolean(chainDetail?.legacy) || !feeParams.isEip1559;
|
|
237
|
+
const latestBaseFeeWei = !legacy ? (await publicClient.getBlock({ blockTag: "latest" })).baseFeePerGas ?? 0n : 0n;
|
|
238
|
+
const gasLimitConfig = useCustomGas && chainDetail?.gasLimit != null ? Number(chainDetail.gasLimit) : void 0;
|
|
239
|
+
const chainGasLimitRouter = chainDetail?.gasLimit != null && Number.isFinite(Number(chainDetail.gasLimit)) && Number(chainDetail.gasLimit) > 0 ? Number(chainDetail.gasLimit) : void 0;
|
|
240
|
+
const gasFeeMultiplier = useCustomGas && chainDetail?.gasMultiplier != null ? Number(chainDetail.gasMultiplier) : void 0;
|
|
241
|
+
const executor = getAddress(executorAddress);
|
|
242
|
+
const baseNonce = await publicClient.getTransactionCount({ address: executor, blockTag: "pending" });
|
|
243
|
+
const legs = [];
|
|
244
|
+
for (let i = 0; i < steps.length; i++) {
|
|
245
|
+
const step = steps[i];
|
|
246
|
+
const currentNonce = baseNonce + i;
|
|
247
|
+
let estimatedGas;
|
|
248
|
+
if (args.estimateGasForStep) {
|
|
249
|
+
estimatedGas = await args.estimateGasForStep({ step, index: i, publicClient, executor });
|
|
250
|
+
} else {
|
|
251
|
+
try {
|
|
252
|
+
estimatedGas = await publicClient.estimateGas({
|
|
253
|
+
to: step.to,
|
|
254
|
+
data: step.data,
|
|
255
|
+
value: step.value,
|
|
256
|
+
account: executor
|
|
257
|
+
});
|
|
258
|
+
} catch {
|
|
259
|
+
estimatedGas = step.fallbackGas ?? 100000n;
|
|
260
|
+
}
|
|
188
261
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
262
|
+
let gasLimitI;
|
|
263
|
+
if (args.resolveGasLimit) {
|
|
264
|
+
gasLimitI = await args.resolveGasLimit({ step, index: i, estimatedGas, publicClient });
|
|
265
|
+
} else if (step.routerSwap) {
|
|
266
|
+
gasLimitI = routerSwapGasLimitFromEstimate(estimatedGas, chainGasLimitRouter);
|
|
267
|
+
} else {
|
|
268
|
+
gasLimitI = useCustomGas ? gasLimitFromEstimateAndChainConfig(estimatedGas, gasLimitConfig) : estimatedGas;
|
|
195
269
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
270
|
+
let proposalTxParams;
|
|
271
|
+
let feeSnapshot;
|
|
272
|
+
let serialized;
|
|
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 && chainDetail?.gasPrice != null && chainDetail.gasPrice > 0) {
|
|
279
|
+
const configured = parseGwei(gweiToDecimalString(Number(chainDetail.gasPrice)));
|
|
280
|
+
if (configured > gasPriceWei) gasPriceWei = configured;
|
|
281
|
+
}
|
|
282
|
+
serialized = serializeTransaction({
|
|
283
|
+
type: "legacy",
|
|
284
|
+
to: step.to,
|
|
285
|
+
data: step.data,
|
|
286
|
+
value: step.value,
|
|
287
|
+
gas: gasLimitI,
|
|
288
|
+
gasPrice: gasPriceWei,
|
|
289
|
+
nonce: currentNonce,
|
|
290
|
+
chainId
|
|
291
|
+
});
|
|
292
|
+
proposalTxParams = {
|
|
293
|
+
nonce: currentNonce,
|
|
294
|
+
gasLimit: gasLimitI.toString(),
|
|
295
|
+
txType: "legacy",
|
|
296
|
+
gasPrice: gasPriceWei.toString()
|
|
297
|
+
};
|
|
298
|
+
feeSnapshot = proposalTxParamsToFeeSnapshot(proposalTxParams);
|
|
299
|
+
} else {
|
|
300
|
+
const fetchedBase = feeParams.baseFeeGwei ?? 0;
|
|
301
|
+
const fetchedPriority = feeParams.priorityFeeGwei ?? 0;
|
|
302
|
+
const configuredBase = useCustomGas && chainDetail?.baseFee != null ? Number(chainDetail.baseFee) : 0;
|
|
303
|
+
const configuredPriority = useCustomGas && chainDetail?.priorityFee != null ? Number(chainDetail.priorityFee) : 0;
|
|
304
|
+
const effectiveBaseFeeGwei = Math.max(fetchedBase, configuredBase);
|
|
305
|
+
const effectivePriorityFeeGwei = Math.max(fetchedPriority, configuredPriority);
|
|
306
|
+
const baseFeeMultiplierPct = useCustomGas && chainDetail?.baseFeeMultiplier != null ? Math.max(100, Number(chainDetail.baseFeeMultiplier)) : 100;
|
|
307
|
+
const baseComponentGwei = effectiveBaseFeeGwei * baseFeeMultiplierPct / 100;
|
|
308
|
+
const maxFeePerGasGwei = baseComponentGwei + effectivePriorityFeeGwei;
|
|
309
|
+
let maxPriorityFeePerGas = effectivePriorityFeeGwei > 0 ? parseGwei(gweiToDecimalString(effectivePriorityFeeGwei)) : parseGwei("1");
|
|
310
|
+
let maxFeePerGas = parseGwei(gweiToDecimalString(maxFeePerGasGwei));
|
|
311
|
+
if (useCustomGas && gasFeeMultiplier != null && gasFeeMultiplier > 0) {
|
|
312
|
+
maxPriorityFeePerGas = maxPriorityFeePerGas * BigInt(100 + gasFeeMultiplier) / 100n;
|
|
313
|
+
maxFeePerGas = maxFeePerGas * BigInt(100 + gasFeeMultiplier) / 100n;
|
|
314
|
+
}
|
|
315
|
+
({ maxFeePerGas, maxPriorityFeePerGas } = alignEip1559FeesWithLatestBase(
|
|
316
|
+
maxFeePerGas,
|
|
317
|
+
maxPriorityFeePerGas,
|
|
318
|
+
latestBaseFeeWei
|
|
319
|
+
));
|
|
320
|
+
serialized = serializeTransaction({
|
|
321
|
+
type: "eip1559",
|
|
322
|
+
to: step.to,
|
|
323
|
+
data: step.data,
|
|
324
|
+
value: step.value,
|
|
325
|
+
gas: gasLimitI,
|
|
326
|
+
maxFeePerGas,
|
|
327
|
+
maxPriorityFeePerGas,
|
|
328
|
+
nonce: currentNonce,
|
|
329
|
+
chainId
|
|
330
|
+
});
|
|
331
|
+
proposalTxParams = {
|
|
332
|
+
nonce: currentNonce,
|
|
333
|
+
gasLimit: gasLimitI.toString(),
|
|
334
|
+
txType: "eip1559",
|
|
335
|
+
maxFeePerGas: maxFeePerGas.toString(),
|
|
336
|
+
maxPriorityFeePerGas: maxPriorityFeePerGas.toString()
|
|
337
|
+
};
|
|
338
|
+
feeSnapshot = i === 0 ? proposalTxParamsToFeeSnapshot(proposalTxParams) : {};
|
|
339
|
+
}
|
|
340
|
+
const h = keccak256(serialized);
|
|
341
|
+
const msgHash = h.startsWith("0x") ? h.slice(2) : h;
|
|
342
|
+
const batchMetaExtra = args.buildBatchMeta({ step, index: i, gasLimit: gasLimitI });
|
|
343
|
+
legs.push({
|
|
344
|
+
msgHash,
|
|
345
|
+
msgRaw: i === 0 && args.firstMsgRawNo0x != null ? args.firstMsgRawNo0x : serialized,
|
|
346
|
+
destinationAddress: step.to,
|
|
347
|
+
signatureText: typeof batchMetaExtra.signatureText === "string" ? batchMetaExtra.signatureText : JSON.stringify(batchMetaExtra.signatureText ?? {}),
|
|
348
|
+
audit: batchMetaExtra,
|
|
349
|
+
feeSnapshot: i === 0 ? feeSnapshot : {},
|
|
350
|
+
proposalTxParams,
|
|
351
|
+
valueWei: i === 0 ? step.value : void 0
|
|
352
|
+
});
|
|
353
|
+
if (i === 0 && args.firstMsgRawNo0x != null) {
|
|
354
|
+
legs[0].msgRaw = args.firstMsgRawNo0x;
|
|
210
355
|
}
|
|
211
356
|
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
357
|
+
const extraJSON = {};
|
|
358
|
+
if (useCustomGas && customGasChainDetails && Object.keys(customGasChainDetails).length > 0) {
|
|
359
|
+
extraJSON.customGasChainDetails = customGasChainDetails;
|
|
360
|
+
}
|
|
361
|
+
const result = finalizeMultisign({
|
|
362
|
+
keyGen,
|
|
363
|
+
purposeText,
|
|
364
|
+
purposeSuffix: args.purposeSuffix,
|
|
365
|
+
destinationChainID: String(chainId),
|
|
366
|
+
destinationAddress: args.destinationAddress ?? steps[0].to,
|
|
367
|
+
legs,
|
|
368
|
+
extraJSON: Object.keys(extraJSON).length > 0 ? extraJSON : void 0
|
|
369
|
+
});
|
|
370
|
+
const pv = args.payableValueWei;
|
|
371
|
+
if (pv != null && pv > 0n) {
|
|
372
|
+
result.bodyForSign.value = pv.toString();
|
|
221
373
|
}
|
|
222
|
-
return
|
|
374
|
+
return result;
|
|
223
375
|
}
|
|
224
|
-
function alignEip1559FeesWithLatestBase(maxFeePerGas, maxPriorityFeePerGas, latestBlockBaseFeeWei) {
|
|
225
|
-
return finalizeEip1559Fees(maxFeePerGas, maxPriorityFeePerGas, null, latestBlockBaseFeeWei);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// src/protocols/evm/ethena/multisign.ts
|
|
229
376
|
var AAVE_ERC20_APPROVE_FALLBACK = 100000n;
|
|
230
377
|
var ETHENA_SUSDE_DEPOSIT_GET_SIG_GAS_FALLBACK = 1200000n;
|
|
231
378
|
var ETHENA_SUSDE_DEPOSIT_FALLBACK = ETHENA_SUSDE_DEPOSIT_GET_SIG_GAS_FALLBACK;
|
|
232
379
|
var ETHENA_SUSDE_REDEEM_FALLBACK = 1200000n;
|
|
233
|
-
function gweiToDecimalString(n) {
|
|
234
|
-
if (!Number.isFinite(n)) return "0";
|
|
235
|
-
if (n === 0) return "0";
|
|
236
|
-
const s = String(n);
|
|
237
|
-
if (s.indexOf("e") !== -1 || s.indexOf("E") !== -1) return n.toFixed(9).replace(/\.?0+$/, "") || "0";
|
|
238
|
-
return s;
|
|
239
|
-
}
|
|
240
380
|
var erc20AllowanceAbi = parseAbi([
|
|
241
381
|
"function allowance(address owner, address spender) view returns (uint256)",
|
|
242
382
|
"function decimals() view returns (uint8)"
|
|
@@ -293,10 +433,6 @@ async function buildEvmMultisignBodyEthenaUsdeStakeToSusde(args) {
|
|
|
293
433
|
if (args.chainId !== 1) {
|
|
294
434
|
throw new Error("Ethena USDe \u2192 sUSDe stake is only supported on Ethereum mainnet (chain id 1).");
|
|
295
435
|
}
|
|
296
|
-
const ph = (args.keyGen.pubkeyhex ?? "").trim();
|
|
297
|
-
if (!ph) throw new Error("keyGen pubKey (pubkeyhex) is required");
|
|
298
|
-
const keyList = args.keyGen.keylist ?? [];
|
|
299
|
-
const clientId = firstClientIdFromKeyGen(args.keyGen);
|
|
300
436
|
const usde = getAddress(args.usde);
|
|
301
437
|
const mainnetUsde = getAddress(USDE_ETHEREUM_MAINNET);
|
|
302
438
|
if (usde.toLowerCase() !== mainnetUsde.toLowerCase()) {
|
|
@@ -351,141 +487,58 @@ async function buildEvmMultisignBodyEthenaUsdeStakeToSusde(args) {
|
|
|
351
487
|
args: [amountWei, receiver]
|
|
352
488
|
});
|
|
353
489
|
steps.push({ kind: "deposit", to: susde, data: depositData, value: 0n });
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
const
|
|
361
|
-
const
|
|
362
|
-
const
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
const gasLimitI = useCustomGas ? gasLimitFromEstimateAndChainConfig(estimatedGas, gasLimitConfig) : estimatedGas;
|
|
387
|
-
if (legacy) {
|
|
388
|
-
let gasPriceWei = await publicClient.getGasPrice();
|
|
389
|
-
if (useCustomGas && gasFeeMultiplier != null && gasFeeMultiplier > 0) {
|
|
390
|
-
gasPriceWei = gasPriceWei * BigInt(100 + gasFeeMultiplier) / 100n;
|
|
391
|
-
}
|
|
392
|
-
if (useCustomGas && args.chainDetail?.gasPrice != null && args.chainDetail.gasPrice > 0) {
|
|
393
|
-
const configured = parseGwei(gweiToDecimalString(Number(args.chainDetail.gasPrice)));
|
|
394
|
-
if (configured > gasPriceWei) gasPriceWei = configured;
|
|
395
|
-
}
|
|
396
|
-
const ser = serializeTransaction({
|
|
397
|
-
type: "legacy",
|
|
398
|
-
to: s.to,
|
|
399
|
-
data: s.data,
|
|
400
|
-
value: s.value,
|
|
401
|
-
gas: gasLimitI,
|
|
402
|
-
gasPrice: gasPriceWei,
|
|
403
|
-
nonce: currentNonce,
|
|
404
|
-
chainId: 1
|
|
405
|
-
});
|
|
406
|
-
const h = keccak256(ser);
|
|
407
|
-
messageHashes.push(h.startsWith("0x") ? h.slice(2) : h);
|
|
408
|
-
messageRawBatch.push(ser);
|
|
409
|
-
proposalTxParamsBatch.push({
|
|
410
|
-
nonce: currentNonce,
|
|
411
|
-
gasLimit: gasLimitI.toString(),
|
|
412
|
-
txType: "legacy",
|
|
413
|
-
gasPrice: gasPriceWei.toString()
|
|
414
|
-
});
|
|
415
|
-
if (i === 0) {
|
|
416
|
-
firstTxFeePayload = { txNonce: currentNonce, txGasLimit: gasLimitI.toString(), txGasPrice: gasPriceWei.toString() };
|
|
417
|
-
firstDataNo0x = s.data.startsWith("0x") ? s.data.slice(2) : s.data;
|
|
418
|
-
}
|
|
419
|
-
} else {
|
|
420
|
-
const fetchedBase = feeParams.baseFeeGwei ?? 0;
|
|
421
|
-
const fetchedPriority = feeParams.priorityFeeGwei ?? 0;
|
|
422
|
-
const configuredBase = useCustomGas && args.chainDetail?.baseFee != null ? Number(args.chainDetail.baseFee) : 0;
|
|
423
|
-
const configuredPriority = useCustomGas && args.chainDetail?.priorityFee != null ? Number(args.chainDetail.priorityFee) : 0;
|
|
424
|
-
const effectiveBaseFeeGwei = Math.max(fetchedBase, configuredBase);
|
|
425
|
-
const effectivePriorityFeeGwei = Math.max(fetchedPriority, configuredPriority);
|
|
426
|
-
const baseFeeMultiplierPct = useCustomGas && args.chainDetail?.baseFeeMultiplier != null ? Math.max(100, Number(args.chainDetail.baseFeeMultiplier)) : 100;
|
|
427
|
-
const baseComponentGwei = effectiveBaseFeeGwei * baseFeeMultiplierPct / 100;
|
|
428
|
-
const maxFeePerGasGwei = baseComponentGwei + effectivePriorityFeeGwei;
|
|
429
|
-
let maxPriorityFeePerGas = effectivePriorityFeeGwei > 0 ? parseGwei(gweiToDecimalString(effectivePriorityFeeGwei)) : parseGwei("1");
|
|
430
|
-
let maxFeePerGas = parseGwei(gweiToDecimalString(maxFeePerGasGwei));
|
|
431
|
-
if (useCustomGas && gasFeeMultiplier != null && gasFeeMultiplier > 0) {
|
|
432
|
-
maxPriorityFeePerGas = maxPriorityFeePerGas * BigInt(100 + gasFeeMultiplier) / 100n;
|
|
433
|
-
maxFeePerGas = maxFeePerGas * BigInt(100 + gasFeeMultiplier) / 100n;
|
|
490
|
+
const evmSteps = steps.map((s) => ({
|
|
491
|
+
to: s.to,
|
|
492
|
+
data: s.data,
|
|
493
|
+
value: s.value,
|
|
494
|
+
fallbackGas: s.kind === "approve" ? AAVE_ERC20_APPROVE_FALLBACK : ETHENA_SUSDE_DEPOSIT_FALLBACK
|
|
495
|
+
}));
|
|
496
|
+
const n = steps.length;
|
|
497
|
+
const purposeSuffix = n === 1 ? "Ethena: 1-tx \u2014 deposit USDe to sUSDe (allowance already set)." : `Ethena: ${n}-tx batch \u2014 approve USDe to sUSDe vault, then deposit.`;
|
|
498
|
+
const firstDataNo0x = evmSteps[0].data.startsWith("0x") ? evmSteps[0].data.slice(2) : evmSteps[0].data;
|
|
499
|
+
const gasLimitConfig = args.useCustomGas && args.chainDetail?.gasLimit != null ? Number(args.chainDetail.gasLimit) : void 0;
|
|
500
|
+
return buildEvmMultisignBatch({
|
|
501
|
+
context: {
|
|
502
|
+
chainCategory: "evm",
|
|
503
|
+
keyGen: args.keyGen,
|
|
504
|
+
purposeText: args.purposeText,
|
|
505
|
+
chainId: 1,
|
|
506
|
+
rpcUrl: args.rpcUrl.trim(),
|
|
507
|
+
executorAddress: executor,
|
|
508
|
+
chainDetail: args.chainDetail,
|
|
509
|
+
useCustomGas: args.useCustomGas,
|
|
510
|
+
customGasChainDetails: args.customGasChainDetails
|
|
511
|
+
},
|
|
512
|
+
steps: evmSteps,
|
|
513
|
+
purposeSuffix,
|
|
514
|
+
firstMsgRawNo0x: firstDataNo0x,
|
|
515
|
+
destinationAddress: steps[0].to,
|
|
516
|
+
resolveGasLimit: ({ index, estimatedGas }) => {
|
|
517
|
+
const s = steps[index];
|
|
518
|
+
if (s.kind === "deposit" && index > 0) {
|
|
519
|
+
const gas = ETHENA_SUSDE_DEPOSIT_FALLBACK;
|
|
520
|
+
return args.useCustomGas ? gasLimitFromEstimateAndChainConfig(gas, gasLimitConfig) : gas;
|
|
434
521
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
)
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
messageHashes.push(h.startsWith("0x") ? h.slice(2) : h);
|
|
453
|
-
messageRawBatch.push(ser);
|
|
454
|
-
proposalTxParamsBatch.push({
|
|
455
|
-
nonce: currentNonce,
|
|
456
|
-
gasLimit: gasLimitI.toString(),
|
|
457
|
-
txType: "eip1559",
|
|
458
|
-
maxFeePerGas: maxFeePerGas.toString(),
|
|
459
|
-
maxPriorityFeePerGas: maxPriorityFeePerGas.toString()
|
|
460
|
-
});
|
|
461
|
-
if (i === 0) {
|
|
462
|
-
firstTxFeePayload = {
|
|
463
|
-
txNonce: currentNonce,
|
|
464
|
-
txGasLimit: gasLimitI.toString(),
|
|
465
|
-
txMaxFeePerGas: maxFeePerGas.toString(),
|
|
466
|
-
txMaxPriorityFeePerGas: maxPriorityFeePerGas.toString()
|
|
522
|
+
return estimatedGas;
|
|
523
|
+
},
|
|
524
|
+
buildBatchMeta: ({ index, gasLimit }) => {
|
|
525
|
+
const s = steps[index];
|
|
526
|
+
if (s.kind === "approve") {
|
|
527
|
+
return {
|
|
528
|
+
signatureText: JSON.stringify({
|
|
529
|
+
kind: "Ethena",
|
|
530
|
+
name: "ERC20.approve",
|
|
531
|
+
to: "sUSDe vault",
|
|
532
|
+
function: "approve(address spender, uint256 amount)",
|
|
533
|
+
spender: susde,
|
|
534
|
+
amountHuman: args.amountHuman,
|
|
535
|
+
note: "Allowance to stake this USDe amount (not unlimited)."
|
|
536
|
+
}),
|
|
537
|
+
evm: { type: "ethena_erc20_approve", version: 1, chainId: "1" },
|
|
538
|
+
ethena: { step: "approve_usde", susde }
|
|
467
539
|
};
|
|
468
|
-
firstDataNo0x = s.data.startsWith("0x") ? s.data.slice(2) : s.data;
|
|
469
540
|
}
|
|
470
|
-
|
|
471
|
-
if (s.kind === "approve") {
|
|
472
|
-
batchMeta.push({
|
|
473
|
-
destinationAddress: usde,
|
|
474
|
-
signatureText: JSON.stringify({
|
|
475
|
-
kind: "Ethena",
|
|
476
|
-
name: "ERC20.approve",
|
|
477
|
-
to: "sUSDe vault",
|
|
478
|
-
function: "approve(address spender, uint256 amount)",
|
|
479
|
-
spender: susde,
|
|
480
|
-
amountHuman: args.amountHuman,
|
|
481
|
-
note: "Allowance to stake this USDe amount (not unlimited)."
|
|
482
|
-
}),
|
|
483
|
-
evm: { type: "ethena_erc20_approve", version: 1, chainId: "1" },
|
|
484
|
-
ethena: { step: "approve_usde", susde }
|
|
485
|
-
});
|
|
486
|
-
} else {
|
|
487
|
-
batchMeta.push({
|
|
488
|
-
destinationAddress: susde,
|
|
541
|
+
return {
|
|
489
542
|
signatureText: JSON.stringify({
|
|
490
543
|
kind: "Ethena",
|
|
491
544
|
name: "StakedUSDe (ERC-4626).deposit",
|
|
@@ -495,40 +548,10 @@ async function buildEvmMultisignBodyEthenaUsdeStakeToSusde(args) {
|
|
|
495
548
|
amountHuman: args.amountHuman
|
|
496
549
|
}),
|
|
497
550
|
evm: { type: "ethena_susde_deposit", version: 1, chainId: "1" },
|
|
498
|
-
ethena: { step: "deposit", vault: susde, gasBuildDeposit: { baseGasUnits:
|
|
499
|
-
}
|
|
551
|
+
ethena: { step: "deposit", vault: susde, gasBuildDeposit: { baseGasUnits: gasLimit.toString() } }
|
|
552
|
+
};
|
|
500
553
|
}
|
|
501
|
-
}
|
|
502
|
-
const extraPayload = { batchMeta };
|
|
503
|
-
if (useCustomGas && args.customGasChainDetails && Object.keys(args.customGasChainDetails).length > 0) {
|
|
504
|
-
extraPayload.customGasChainDetails = args.customGasChainDetails;
|
|
505
|
-
}
|
|
506
|
-
const extraJSON = JSON.stringify(extraPayload);
|
|
507
|
-
const firstSigText = batchMeta[0].signatureText;
|
|
508
|
-
const n = steps.length;
|
|
509
|
-
const purposeSuffix = n === 1 ? "Ethena: 1-tx \u2014 deposit USDe to sUSDe (allowance already set)." : `Ethena: ${n}-tx batch \u2014 approve USDe to sUSDe vault, then deposit.`;
|
|
510
|
-
const bodyForSign = {
|
|
511
|
-
keyList,
|
|
512
|
-
pubKey: ph,
|
|
513
|
-
msgHash: messageHashes[0],
|
|
514
|
-
msgRaw: firstDataNo0x,
|
|
515
|
-
messageHashes,
|
|
516
|
-
messageRawBatch,
|
|
517
|
-
destinationChainID: "1",
|
|
518
|
-
destinationAddress: steps[0].to,
|
|
519
|
-
extraJSON,
|
|
520
|
-
signatureText: firstSigText,
|
|
521
|
-
purpose: (() => {
|
|
522
|
-
const t = args.purposeText.trim();
|
|
523
|
-
return (t ? `${t}
|
|
524
|
-
|
|
525
|
-
` : "") + purposeSuffix;
|
|
526
|
-
})(),
|
|
527
|
-
...firstTxFeePayload,
|
|
528
|
-
proposalTxParams: proposalTxParamsBatch
|
|
529
|
-
};
|
|
530
|
-
if (clientId) bodyForSign.clientId = clientId;
|
|
531
|
-
return { bodyForSign, messageToSign: JSON.stringify(bodyForSign) };
|
|
554
|
+
});
|
|
532
555
|
}
|
|
533
556
|
var ETHENA_SUSDE_COOLDOWN_SHARES_FALLBACK = 1200000n;
|
|
534
557
|
var ETHENA_SUSDE_UNSTAKE_CLAIM_FALLBACK = 500000n;
|
|
@@ -536,161 +559,27 @@ async function buildEthenaStakedUsdeOneTxMultisignBody(args) {
|
|
|
536
559
|
if (args.chainId !== 1) {
|
|
537
560
|
throw new Error("Ethena sUSDe exit is only supported on Ethereum mainnet (chain id 1).");
|
|
538
561
|
}
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
562
|
+
const step = args.step;
|
|
563
|
+
const evmSteps = [{ to: step.to, data: step.data, value: step.value, fallbackGas: args.gasFallback }];
|
|
564
|
+
const firstDataNo0x = step.data.startsWith("0x") ? step.data.slice(2) : step.data;
|
|
565
|
+
return buildEvmMultisignBatch({
|
|
566
|
+
context: {
|
|
567
|
+
chainCategory: "evm",
|
|
568
|
+
keyGen: args.keyGen,
|
|
569
|
+
purposeText: args.purposeText,
|
|
570
|
+
chainId: 1,
|
|
571
|
+
rpcUrl: args.rpcUrl.trim(),
|
|
572
|
+
executorAddress: args.executor,
|
|
573
|
+
chainDetail: args.chainDetail,
|
|
574
|
+
useCustomGas: args.useCustomGas,
|
|
575
|
+
customGasChainDetails: args.customGasChainDetails
|
|
576
|
+
},
|
|
577
|
+
steps: evmSteps,
|
|
578
|
+
purposeSuffix: args.purposeSuffix,
|
|
579
|
+
firstMsgRawNo0x: firstDataNo0x,
|
|
580
|
+
destinationAddress: step.to,
|
|
581
|
+
buildBatchMeta: ({ gasLimit }) => args.makeBatchMeta({ gasLimitI: gasLimit })
|
|
555
582
|
});
|
|
556
|
-
const publicClient = createPublicClient({ chain: ch, transport: http(args.rpcUrl.trim()) });
|
|
557
|
-
const latestBaseFeeWei = !legacy ? (await publicClient.getBlock({ blockTag: "latest" })).baseFeePerGas ?? 0n : 0n;
|
|
558
|
-
const baseNonce = await publicClient.getTransactionCount({ address: executor, blockTag: "pending" });
|
|
559
|
-
const messageHashes = [];
|
|
560
|
-
const messageRawBatch = [];
|
|
561
|
-
const proposalTxParamsBatch = [];
|
|
562
|
-
const batchMeta = [];
|
|
563
|
-
let firstTxFeePayload = {};
|
|
564
|
-
let firstDataNo0x = "";
|
|
565
|
-
for (let i = 0; i < steps.length; i++) {
|
|
566
|
-
const s = steps[i];
|
|
567
|
-
const currentNonce = baseNonce + i;
|
|
568
|
-
let estimatedGas;
|
|
569
|
-
try {
|
|
570
|
-
estimatedGas = await publicClient.estimateGas({
|
|
571
|
-
to: s.to,
|
|
572
|
-
data: s.data,
|
|
573
|
-
value: s.value,
|
|
574
|
-
account: executor
|
|
575
|
-
});
|
|
576
|
-
} catch {
|
|
577
|
-
estimatedGas = args.gasFallback;
|
|
578
|
-
}
|
|
579
|
-
const gasLimitI = useCustomGas ? gasLimitFromEstimateAndChainConfig(estimatedGas, gasLimitConfig) : estimatedGas;
|
|
580
|
-
if (legacy) {
|
|
581
|
-
let gasPriceWei = await publicClient.getGasPrice();
|
|
582
|
-
if (useCustomGas && gasFeeMultiplier != null && gasFeeMultiplier > 0) {
|
|
583
|
-
gasPriceWei = gasPriceWei * BigInt(100 + gasFeeMultiplier) / 100n;
|
|
584
|
-
}
|
|
585
|
-
if (useCustomGas && args.chainDetail?.gasPrice != null && args.chainDetail.gasPrice > 0) {
|
|
586
|
-
const configured = parseGwei(gweiToDecimalString(Number(args.chainDetail.gasPrice)));
|
|
587
|
-
if (configured > gasPriceWei) gasPriceWei = configured;
|
|
588
|
-
}
|
|
589
|
-
const ser = serializeTransaction({
|
|
590
|
-
type: "legacy",
|
|
591
|
-
to: s.to,
|
|
592
|
-
data: s.data,
|
|
593
|
-
value: s.value,
|
|
594
|
-
gas: gasLimitI,
|
|
595
|
-
gasPrice: gasPriceWei,
|
|
596
|
-
nonce: currentNonce,
|
|
597
|
-
chainId: 1
|
|
598
|
-
});
|
|
599
|
-
const h = keccak256(ser);
|
|
600
|
-
messageHashes.push(h.startsWith("0x") ? h.slice(2) : h);
|
|
601
|
-
messageRawBatch.push(ser);
|
|
602
|
-
proposalTxParamsBatch.push({
|
|
603
|
-
nonce: currentNonce,
|
|
604
|
-
gasLimit: gasLimitI.toString(),
|
|
605
|
-
txType: "legacy",
|
|
606
|
-
gasPrice: gasPriceWei.toString()
|
|
607
|
-
});
|
|
608
|
-
if (i === 0) {
|
|
609
|
-
firstTxFeePayload = { txNonce: currentNonce, txGasLimit: gasLimitI.toString(), txGasPrice: gasPriceWei.toString() };
|
|
610
|
-
firstDataNo0x = s.data.startsWith("0x") ? s.data.slice(2) : s.data;
|
|
611
|
-
}
|
|
612
|
-
} else {
|
|
613
|
-
const fetchedBase = feeParams.baseFeeGwei ?? 0;
|
|
614
|
-
const fetchedPriority = feeParams.priorityFeeGwei ?? 0;
|
|
615
|
-
const configuredBase = useCustomGas && args.chainDetail?.baseFee != null ? Number(args.chainDetail.baseFee) : 0;
|
|
616
|
-
const configuredPriority = useCustomGas && args.chainDetail?.priorityFee != null ? Number(args.chainDetail.priorityFee) : 0;
|
|
617
|
-
const effectiveBaseFeeGwei = Math.max(fetchedBase, configuredBase);
|
|
618
|
-
const effectivePriorityFeeGwei = Math.max(fetchedPriority, configuredPriority);
|
|
619
|
-
const baseFeeMultiplierPct = useCustomGas && args.chainDetail?.baseFeeMultiplier != null ? Math.max(100, Number(args.chainDetail.baseFeeMultiplier)) : 100;
|
|
620
|
-
const baseComponentGwei = effectiveBaseFeeGwei * baseFeeMultiplierPct / 100;
|
|
621
|
-
const maxFeePerGasGwei = baseComponentGwei + effectivePriorityFeeGwei;
|
|
622
|
-
let maxPriorityFeePerGas = effectivePriorityFeeGwei > 0 ? parseGwei(gweiToDecimalString(effectivePriorityFeeGwei)) : parseGwei("1");
|
|
623
|
-
let maxFeePerGas = parseGwei(gweiToDecimalString(maxFeePerGasGwei));
|
|
624
|
-
if (useCustomGas && gasFeeMultiplier != null && gasFeeMultiplier > 0) {
|
|
625
|
-
maxPriorityFeePerGas = maxPriorityFeePerGas * BigInt(100 + gasFeeMultiplier) / 100n;
|
|
626
|
-
maxFeePerGas = maxFeePerGas * BigInt(100 + gasFeeMultiplier) / 100n;
|
|
627
|
-
}
|
|
628
|
-
({ maxFeePerGas, maxPriorityFeePerGas } = alignEip1559FeesWithLatestBase(
|
|
629
|
-
maxFeePerGas,
|
|
630
|
-
maxPriorityFeePerGas,
|
|
631
|
-
latestBaseFeeWei
|
|
632
|
-
));
|
|
633
|
-
const ser = serializeTransaction({
|
|
634
|
-
type: "eip1559",
|
|
635
|
-
to: s.to,
|
|
636
|
-
data: s.data,
|
|
637
|
-
value: s.value,
|
|
638
|
-
gas: gasLimitI,
|
|
639
|
-
maxFeePerGas,
|
|
640
|
-
maxPriorityFeePerGas,
|
|
641
|
-
nonce: currentNonce,
|
|
642
|
-
chainId: 1
|
|
643
|
-
});
|
|
644
|
-
const h = keccak256(ser);
|
|
645
|
-
messageHashes.push(h.startsWith("0x") ? h.slice(2) : h);
|
|
646
|
-
messageRawBatch.push(ser);
|
|
647
|
-
proposalTxParamsBatch.push({
|
|
648
|
-
nonce: currentNonce,
|
|
649
|
-
gasLimit: gasLimitI.toString(),
|
|
650
|
-
txType: "eip1559",
|
|
651
|
-
maxFeePerGas: maxFeePerGas.toString(),
|
|
652
|
-
maxPriorityFeePerGas: maxPriorityFeePerGas.toString()
|
|
653
|
-
});
|
|
654
|
-
if (i === 0) {
|
|
655
|
-
firstTxFeePayload = {
|
|
656
|
-
txNonce: currentNonce,
|
|
657
|
-
txGasLimit: gasLimitI.toString(),
|
|
658
|
-
txMaxFeePerGas: maxFeePerGas.toString(),
|
|
659
|
-
txMaxPriorityFeePerGas: maxPriorityFeePerGas.toString()
|
|
660
|
-
};
|
|
661
|
-
firstDataNo0x = s.data.startsWith("0x") ? s.data.slice(2) : s.data;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
batchMeta.push(args.makeBatchMeta({ gasLimitI }));
|
|
665
|
-
}
|
|
666
|
-
const extraPayload = { batchMeta };
|
|
667
|
-
if (useCustomGas && args.customGasChainDetails && Object.keys(args.customGasChainDetails).length > 0) {
|
|
668
|
-
extraPayload.customGasChainDetails = args.customGasChainDetails;
|
|
669
|
-
}
|
|
670
|
-
const extraJSON = JSON.stringify(extraPayload);
|
|
671
|
-
const firstSigText = batchMeta[0].signatureText;
|
|
672
|
-
const bodyForSign = {
|
|
673
|
-
keyList,
|
|
674
|
-
pubKey: ph,
|
|
675
|
-
msgHash: messageHashes[0],
|
|
676
|
-
msgRaw: firstDataNo0x,
|
|
677
|
-
messageHashes,
|
|
678
|
-
messageRawBatch,
|
|
679
|
-
destinationChainID: "1",
|
|
680
|
-
destinationAddress: steps[0].to,
|
|
681
|
-
extraJSON,
|
|
682
|
-
signatureText: firstSigText,
|
|
683
|
-
purpose: (() => {
|
|
684
|
-
const t = args.purposeText.trim();
|
|
685
|
-
return (t ? `${t}
|
|
686
|
-
|
|
687
|
-
` : "") + args.purposeSuffix;
|
|
688
|
-
})(),
|
|
689
|
-
...firstTxFeePayload,
|
|
690
|
-
proposalTxParams: proposalTxParamsBatch
|
|
691
|
-
};
|
|
692
|
-
if (clientId) bodyForSign.clientId = clientId;
|
|
693
|
-
return { bodyForSign, messageToSign: JSON.stringify(bodyForSign) };
|
|
694
583
|
}
|
|
695
584
|
async function buildEvmMultisignBodyEthenaSusdeRedeemToUsde(args) {
|
|
696
585
|
if (args.chainId !== 1) {
|
|
@@ -915,6 +804,103 @@ function resolveEthenaBatchStepGasFromSignRequest(detail, batchIndex) {
|
|
|
915
804
|
}
|
|
916
805
|
return null;
|
|
917
806
|
}
|
|
807
|
+
var ETHENA_MINTING_V2_MAINNET = "0xe3490297a08d6fC8Da46Edb7B6142E4F461b62D3";
|
|
808
|
+
var ETHENA_MINTING_READ_ABI = parseAbi([
|
|
809
|
+
"function isSupportedAsset(address asset) view returns (bool)"
|
|
810
|
+
]);
|
|
811
|
+
var cachedClient = null;
|
|
812
|
+
function publicClientForMainnetRpc(rpcUrl) {
|
|
813
|
+
if (cachedClient && cachedClient.rpc === rpcUrl) return cachedClient.client;
|
|
814
|
+
const c = createPublicClient({ chain: mainnet, transport: http(rpcUrl.trim(), { batch: { batchSize: 64 } }) });
|
|
815
|
+
cachedClient = { rpc: rpcUrl, client: c };
|
|
816
|
+
return c;
|
|
817
|
+
}
|
|
818
|
+
async function fetchEthenaMintingIsSupportedMap(rpcUrl, contractAddresses) {
|
|
819
|
+
const out = /* @__PURE__ */ new Map();
|
|
820
|
+
if (!rpcUrl.trim()) return out;
|
|
821
|
+
const unique = [];
|
|
822
|
+
const seen = /* @__PURE__ */ new Set();
|
|
823
|
+
for (const raw of contractAddresses) {
|
|
824
|
+
try {
|
|
825
|
+
const a = getAddress(raw);
|
|
826
|
+
const k = a.toLowerCase();
|
|
827
|
+
if (seen.has(k)) continue;
|
|
828
|
+
seen.add(k);
|
|
829
|
+
unique.push(a);
|
|
830
|
+
} catch {
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
if (unique.length === 0) return out;
|
|
834
|
+
const client = publicClientForMainnetRpc(rpcUrl);
|
|
835
|
+
const res = await client.multicall({
|
|
836
|
+
contracts: unique.map((asset) => ({
|
|
837
|
+
address: ETHENA_MINTING_V2_MAINNET,
|
|
838
|
+
abi: ETHENA_MINTING_READ_ABI,
|
|
839
|
+
functionName: "isSupportedAsset",
|
|
840
|
+
args: [asset]
|
|
841
|
+
})),
|
|
842
|
+
allowFailure: true
|
|
843
|
+
});
|
|
844
|
+
for (let i = 0; i < unique.length; i++) {
|
|
845
|
+
const row = res[i];
|
|
846
|
+
if (row.status !== "success") continue;
|
|
847
|
+
if (row.result === true) out.set(unique[i], true);
|
|
848
|
+
}
|
|
849
|
+
return out;
|
|
850
|
+
}
|
|
851
|
+
var STAKED_USDE_V2_VIEWS_ABI = parseAbi([
|
|
852
|
+
"function cooldownDuration() view returns (uint24)",
|
|
853
|
+
"function cooldowns(address account) view returns (uint104 cooldownEnd, uint152 underlyingAmount)"
|
|
854
|
+
]);
|
|
855
|
+
function publicClientForMainnet(rpcUrl) {
|
|
856
|
+
return createPublicClient({
|
|
857
|
+
chain: { id: 1, name: "Ethereum", nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 }, rpcUrls: { default: { http: [rpcUrl.trim()] } } },
|
|
858
|
+
transport: http(rpcUrl.trim())
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
async function readEthenaStakedUsdeCooldownDuration(args) {
|
|
862
|
+
const v = getAddress(args.vault ?? SUSDE_ETHEREUM_MAINNET);
|
|
863
|
+
const c = publicClientForMainnet(args.rpcUrl);
|
|
864
|
+
const d = await c.readContract({
|
|
865
|
+
address: v,
|
|
866
|
+
abi: STAKED_USDE_V2_VIEWS_ABI,
|
|
867
|
+
functionName: "cooldownDuration"
|
|
868
|
+
});
|
|
869
|
+
return BigInt(d);
|
|
870
|
+
}
|
|
871
|
+
async function readEthenaStakedUsdeUserCooldown(args) {
|
|
872
|
+
const v = getAddress(args.vault ?? SUSDE_ETHEREUM_MAINNET);
|
|
873
|
+
const c = publicClientForMainnet(args.rpcUrl);
|
|
874
|
+
const r = await c.readContract({
|
|
875
|
+
address: v,
|
|
876
|
+
abi: STAKED_USDE_V2_VIEWS_ABI,
|
|
877
|
+
functionName: "cooldowns",
|
|
878
|
+
args: [getAddress(args.account)]
|
|
879
|
+
});
|
|
880
|
+
const tuple = r;
|
|
881
|
+
return {
|
|
882
|
+
cooldownEnd: BigInt(tuple[0]),
|
|
883
|
+
underlyingAmount: BigInt(tuple[1])
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
async function readEthenaMainnetBlockTimestamp(rpcUrl) {
|
|
887
|
+
const c = publicClientForMainnet(rpcUrl);
|
|
888
|
+
const b = await c.getBlock({ blockTag: "latest" });
|
|
889
|
+
return b.timestamp;
|
|
890
|
+
}
|
|
891
|
+
function formatEthenaCooldownDurationLabel(totalSec) {
|
|
892
|
+
if (totalSec <= 0n) return "0 seconds";
|
|
893
|
+
const d = totalSec / 86400n;
|
|
894
|
+
const h = totalSec % 86400n / 3600n;
|
|
895
|
+
const m = totalSec % 3600n / 60n;
|
|
896
|
+
const s = totalSec % 60n;
|
|
897
|
+
const parts = [];
|
|
898
|
+
if (d > 0n) parts.push(`${d} day${d === 1n ? "" : "s"}`);
|
|
899
|
+
if (h > 0n) parts.push(`${h} hour${h === 1n ? "" : "s"}`);
|
|
900
|
+
if (m > 0n) parts.push(`${m} min`);
|
|
901
|
+
if (s > 0n) parts.push(`${s} sec`);
|
|
902
|
+
return parts.join(", ");
|
|
903
|
+
}
|
|
918
904
|
|
|
919
905
|
// src/protocols/evm/ethena/index.ts
|
|
920
906
|
var ETHENA_PROTOCOL_ID = "ethena";
|
|
@@ -938,6 +924,6 @@ var ethenaProtocolModule = {
|
|
|
938
924
|
};
|
|
939
925
|
registerProtocolModule(ethenaProtocolModule);
|
|
940
926
|
|
|
941
|
-
export { ETHENA_KEY_ADDRESSES_DOC, ETHENA_LABS_GITHUB, ETHENA_PROTOCOL_ID, ETHENA_SUSDE_DEPOSIT_GET_SIG_GAS_FALLBACK, SUSDE_ETHEREUM_MAINNET, USDE_ETHEREUM_MAINNET, USDE_MOST_L2S, USDE_ZKSYNC_ERA, buildEvmMultisignBodyEthenaSusdeCooldownShares, buildEvmMultisignBodyEthenaSusdeRedeemToUsde, buildEvmMultisignBodyEthenaUnstakeClaim, buildEvmMultisignBodyEthenaUsdeStakeToSusde, ethenaProtocolModule, isEthenaSusdeDepositBatchStep, isEthenaUsdeOnAssetsChain, isEvmChainInEthenaUsdeList, listEthenaUsdeEvmNetworkRows, readEthenaStakePreviewShares, readEthenaUnstakePreviewUsde, resolveEthenaBatchStepGasFromSignRequest, usdeTokenAddressOnEvmChain };
|
|
927
|
+
export { ETHENA_KEY_ADDRESSES_DOC, ETHENA_LABS_GITHUB, ETHENA_MINTING_V2_MAINNET, ETHENA_PROTOCOL_ID, ETHENA_SUSDE_DEPOSIT_GET_SIG_GAS_FALLBACK, SUSDE_ETHEREUM_MAINNET, USDE_ETHEREUM_MAINNET, USDE_MOST_L2S, USDE_ZKSYNC_ERA, buildEvmMultisignBodyEthenaSusdeCooldownShares, buildEvmMultisignBodyEthenaSusdeRedeemToUsde, buildEvmMultisignBodyEthenaUnstakeClaim, buildEvmMultisignBodyEthenaUsdeStakeToSusde, ethenaProtocolModule, fetchEthenaMintingIsSupportedMap, formatEthenaCooldownDurationLabel, isEthenaSusdeDepositBatchStep, isEthenaUsdeOnAssetsChain, isEvmChainInEthenaUsdeList, listEthenaUsdeEvmNetworkRows, readEthenaMainnetBlockTimestamp, readEthenaStakePreviewShares, readEthenaStakedUsdeCooldownDuration, readEthenaStakedUsdeUserCooldown, readEthenaUnstakePreviewUsde, resolveEthenaBatchStepGasFromSignRequest, usdeTokenAddressOnEvmChain };
|
|
942
928
|
//# sourceMappingURL=index.js.map
|
|
943
929
|
//# sourceMappingURL=index.js.map
|