@continuumdao/ctm-mpc-defi 0.2.19 → 0.2.22
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 +303 -93
- package/dist/agent/catalog.cjs.map +1 -1
- package/dist/agent/catalog.d.ts +985 -709
- package/dist/agent/catalog.js +299 -94
- package/dist/agent/catalog.js.map +1 -1
- package/dist/agent/skills/hyperliquid/SKILL.md +24 -20
- package/dist/agent/skills/uniswap-v4/SKILL.md +58 -0
- package/dist/chains/evm/index.cjs +6 -2
- package/dist/chains/evm/index.cjs.map +1 -1
- package/dist/chains/evm/index.d.ts +4 -4
- package/dist/chains/evm/index.js +6 -2
- 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 +95 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +44 -4
- package/dist/core/index.js +91 -2
- package/dist/core/index.js.map +1 -1
- package/dist/{envelope-CpBUh9eP.d.ts → envelope-C_bfuKab.d.ts} +3 -1
- package/dist/index.cjs +96 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +93 -4
- package/dist/index.js.map +1 -1
- package/dist/protocols/evm/aave-v4/index.cjs +6 -2
- package/dist/protocols/evm/aave-v4/index.cjs.map +1 -1
- package/dist/protocols/evm/aave-v4/index.d.ts +1 -1
- package/dist/protocols/evm/aave-v4/index.js +6 -2
- package/dist/protocols/evm/aave-v4/index.js.map +1 -1
- package/dist/protocols/evm/circle-cctp/index.cjs +6 -2
- package/dist/protocols/evm/circle-cctp/index.cjs.map +1 -1
- package/dist/protocols/evm/circle-cctp/index.d.ts +2 -2
- package/dist/protocols/evm/circle-cctp/index.js +6 -2
- package/dist/protocols/evm/circle-cctp/index.js.map +1 -1
- package/dist/protocols/evm/curve-dao/index.cjs +6 -2
- package/dist/protocols/evm/curve-dao/index.cjs.map +1 -1
- package/dist/protocols/evm/curve-dao/index.d.ts +2 -2
- package/dist/protocols/evm/curve-dao/index.js +6 -2
- package/dist/protocols/evm/curve-dao/index.js.map +1 -1
- package/dist/protocols/evm/ethena/index.cjs +6 -2
- package/dist/protocols/evm/ethena/index.cjs.map +1 -1
- package/dist/protocols/evm/ethena/index.d.ts +1 -1
- package/dist/protocols/evm/ethena/index.js +6 -2
- package/dist/protocols/evm/ethena/index.js.map +1 -1
- package/dist/protocols/evm/euler-v2/index.cjs +6 -2
- package/dist/protocols/evm/euler-v2/index.cjs.map +1 -1
- package/dist/protocols/evm/euler-v2/index.d.ts +1 -1
- package/dist/protocols/evm/euler-v2/index.js +6 -2
- package/dist/protocols/evm/euler-v2/index.js.map +1 -1
- package/dist/protocols/evm/gmx/index.cjs +54 -22
- package/dist/protocols/evm/gmx/index.cjs.map +1 -1
- package/dist/protocols/evm/gmx/index.d.ts +22 -8
- package/dist/protocols/evm/gmx/index.js +53 -23
- package/dist/protocols/evm/gmx/index.js.map +1 -1
- package/dist/protocols/evm/hyperliquid/index.cjs +467 -2
- package/dist/protocols/evm/hyperliquid/index.cjs.map +1 -1
- package/dist/protocols/evm/hyperliquid/index.d.ts +189 -3
- package/dist/protocols/evm/hyperliquid/index.js +447 -4
- package/dist/protocols/evm/hyperliquid/index.js.map +1 -1
- package/dist/protocols/evm/lido/index.cjs +6 -2
- package/dist/protocols/evm/lido/index.cjs.map +1 -1
- package/dist/protocols/evm/lido/index.d.ts +1 -1
- package/dist/protocols/evm/lido/index.js +6 -2
- package/dist/protocols/evm/lido/index.js.map +1 -1
- package/dist/protocols/evm/maple/index.cjs +6 -2
- package/dist/protocols/evm/maple/index.cjs.map +1 -1
- package/dist/protocols/evm/maple/index.d.ts +1 -1
- package/dist/protocols/evm/maple/index.js +6 -2
- package/dist/protocols/evm/maple/index.js.map +1 -1
- package/dist/protocols/evm/morpho/index.cjs +6 -2
- package/dist/protocols/evm/morpho/index.cjs.map +1 -1
- package/dist/protocols/evm/morpho/index.d.ts +1 -1
- package/dist/protocols/evm/morpho/index.js +6 -2
- package/dist/protocols/evm/morpho/index.js.map +1 -1
- package/dist/protocols/evm/permit2/index.cjs +206 -0
- package/dist/protocols/evm/permit2/index.cjs.map +1 -0
- package/dist/protocols/evm/permit2/index.d.ts +43 -0
- package/dist/protocols/evm/permit2/index.js +203 -0
- package/dist/protocols/evm/permit2/index.js.map +1 -0
- package/dist/protocols/evm/sky/index.cjs +6 -2
- package/dist/protocols/evm/sky/index.cjs.map +1 -1
- package/dist/protocols/evm/sky/index.d.ts +1 -1
- package/dist/protocols/evm/sky/index.js +6 -2
- package/dist/protocols/evm/sky/index.js.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.cjs +685 -2
- package/dist/protocols/evm/uniswap-v4/index.cjs.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.d.ts +180 -3
- package/dist/protocols/evm/uniswap-v4/index.js +663 -3
- package/dist/protocols/evm/uniswap-v4/index.js.map +1 -1
- package/dist/{registry-Bv5o37_w.d.ts → registry-DxDSPQ-p.d.ts} +1 -1
- package/dist/{types-BfjWdw1j.d.ts → types-PZrvtjv8.d.ts} +2 -0
- package/dist/{types-DUeNJLr9.d.ts → types-RZWOTm8c.d.ts} +1 -1
- package/package.json +8 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { parseAbi, encodeAbiParameters, getAddress, encodeFunctionData, defineChain, createPublicClient, http, parseGwei, serializeTransaction,
|
|
1
|
+
import { parseAbi, encodeAbiParameters, getAddress, keccak256, parseUnits, encodeFunctionData, hashTypedData, defineChain, createPublicClient, http, parseGwei, serializeTransaction, stringToHex } from 'viem';
|
|
2
2
|
import { fetchChainFeeParams, gasLimitFromEstimateAndChainConfig, gweiToDecimalString, proposalTxParamsToFeeSnapshot, alignEip1559FeesWithLatestBase, getClientIdFromKeyGenResult } from '@continuumdao/continuum-node-sdk';
|
|
3
|
+
import { encode } from '@msgpack/msgpack';
|
|
3
4
|
|
|
4
5
|
// src/core/registry.ts
|
|
5
6
|
var modules = [];
|
|
@@ -202,6 +203,7 @@ async function hyperliquidFetchOhlcvRange(args) {
|
|
|
202
203
|
);
|
|
203
204
|
}
|
|
204
205
|
const latestCandle = candles.length > 0 ? candles[candles.length - 1] : null;
|
|
206
|
+
const effectiveLookbackDays = args.lookbackDays ?? (args.lookbackHours == null && args.startTimeMs == null ? HYPERLIQUID_DEFAULT_LOOKBACK_DAYS : void 0);
|
|
205
207
|
return {
|
|
206
208
|
coin,
|
|
207
209
|
dex,
|
|
@@ -210,6 +212,8 @@ async function hyperliquidFetchOhlcvRange(args) {
|
|
|
210
212
|
endTimeMs,
|
|
211
213
|
expectedBars,
|
|
212
214
|
candleCount: candles.length,
|
|
215
|
+
...effectiveLookbackDays != null ? { lookbackDays: effectiveLookbackDays } : {},
|
|
216
|
+
...args.lookbackHours != null ? { lookbackHours: args.lookbackHours } : {},
|
|
213
217
|
latestCandle,
|
|
214
218
|
candles,
|
|
215
219
|
fetchedAtMs: Date.now()
|
|
@@ -953,7 +957,7 @@ function finalizeMultisign(input) {
|
|
|
953
957
|
batchMeta,
|
|
954
958
|
...input.extraJSON ?? {}
|
|
955
959
|
};
|
|
956
|
-
const extraJSON = JSON.stringify(extraPayload);
|
|
960
|
+
const extraJSON = JSON.stringify(extraPayload, (_, v) => typeof v === "bigint" ? v.toString() : v);
|
|
957
961
|
const bodyForSign = {
|
|
958
962
|
keyList,
|
|
959
963
|
pubKey: ph,
|
|
@@ -978,6 +982,9 @@ function finalizeMultisign(input) {
|
|
|
978
982
|
bodyForSign.value = valueWei.toString();
|
|
979
983
|
}
|
|
980
984
|
if (clientId) bodyForSign.clientId = clientId;
|
|
985
|
+
if (input.expiryDate != null && input.expiryDate > 0) {
|
|
986
|
+
bodyForSign.expiryDate = Math.floor(input.expiryDate);
|
|
987
|
+
}
|
|
981
988
|
return { bodyForSign, messageToSign: JSON.stringify(bodyForSign) };
|
|
982
989
|
}
|
|
983
990
|
function routerSwapGasLimitFromEstimate(estimatedGas, chainGasLimit) {
|
|
@@ -1141,7 +1148,8 @@ async function buildEvmMultisignBatch(args) {
|
|
|
1141
1148
|
destinationChainID: String(chainId),
|
|
1142
1149
|
destinationAddress: args.destinationAddress ?? steps[0].to,
|
|
1143
1150
|
legs,
|
|
1144
|
-
extraJSON: Object.keys(extraJSON).length > 0 ? extraJSON : void 0
|
|
1151
|
+
extraJSON: Object.keys(extraJSON).length > 0 ? extraJSON : void 0,
|
|
1152
|
+
expiryDate: context.expiryDate
|
|
1145
1153
|
});
|
|
1146
1154
|
const pv = args.payableValueWei;
|
|
1147
1155
|
if (pv != null && pv > 0n) {
|
|
@@ -1324,6 +1332,407 @@ async function buildEvmMultisignBodyHyperliquidDelegateOnlyBatch(args) {
|
|
|
1324
1332
|
async function buildEvmMultisignBodyHyperliquidUndelegateBatch(args) {
|
|
1325
1333
|
return buildEvmMultisignBodyHyperliquidDelegateBatch({ ...args, isUndelegate: true });
|
|
1326
1334
|
}
|
|
1335
|
+
var EXCHANGE_DOMAIN = {
|
|
1336
|
+
name: "Exchange",
|
|
1337
|
+
version: "1",
|
|
1338
|
+
chainId: 1337,
|
|
1339
|
+
verifyingContract: "0x0000000000000000000000000000000000000000"
|
|
1340
|
+
};
|
|
1341
|
+
var AGENT_TYPES = {
|
|
1342
|
+
Agent: [
|
|
1343
|
+
{ name: "source", type: "string" },
|
|
1344
|
+
{ name: "connectionId", type: "bytes32" }
|
|
1345
|
+
]
|
|
1346
|
+
};
|
|
1347
|
+
function adjustMsgpackValue(value) {
|
|
1348
|
+
if (Array.isArray(value)) return value.map(adjustMsgpackValue);
|
|
1349
|
+
if (typeof value === "object" && value !== null) {
|
|
1350
|
+
const result = {};
|
|
1351
|
+
for (const key of Object.keys(value)) {
|
|
1352
|
+
const entry = value[key];
|
|
1353
|
+
if (entry !== void 0) result[key] = adjustMsgpackValue(entry);
|
|
1354
|
+
}
|
|
1355
|
+
return result;
|
|
1356
|
+
}
|
|
1357
|
+
if (typeof value === "number" && Number.isInteger(value) && (value >= 4294967296 || value < -2147483648)) {
|
|
1358
|
+
return BigInt(value);
|
|
1359
|
+
}
|
|
1360
|
+
return value;
|
|
1361
|
+
}
|
|
1362
|
+
function toUint64Bytes(n) {
|
|
1363
|
+
const bytes = new Uint8Array(8);
|
|
1364
|
+
new DataView(bytes.buffer).setBigUint64(0, BigInt(n));
|
|
1365
|
+
return bytes;
|
|
1366
|
+
}
|
|
1367
|
+
function concatBytes(...parts) {
|
|
1368
|
+
const total = parts.reduce((sum, p) => sum + p.length, 0);
|
|
1369
|
+
const out = new Uint8Array(total);
|
|
1370
|
+
let offset = 0;
|
|
1371
|
+
for (const p of parts) {
|
|
1372
|
+
out.set(p, offset);
|
|
1373
|
+
offset += p.length;
|
|
1374
|
+
}
|
|
1375
|
+
return out;
|
|
1376
|
+
}
|
|
1377
|
+
function hexToBytes(hex) {
|
|
1378
|
+
const h = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
1379
|
+
const bytes = new Uint8Array(h.length / 2);
|
|
1380
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
1381
|
+
bytes[i] = parseInt(h.slice(i * 2, i * 2 + 2), 16);
|
|
1382
|
+
}
|
|
1383
|
+
return bytes;
|
|
1384
|
+
}
|
|
1385
|
+
function createHyperliquidL1ActionHash(args) {
|
|
1386
|
+
const { action, nonce, vaultAddress, expiresAfter } = args;
|
|
1387
|
+
const actionBytes = encode(adjustMsgpackValue(action));
|
|
1388
|
+
const nonceBytes = toUint64Bytes(nonce);
|
|
1389
|
+
const vaultMarker = vaultAddress ? new Uint8Array([1]) : new Uint8Array([0]);
|
|
1390
|
+
const vaultBytes = vaultAddress ? hexToBytes(vaultAddress) : new Uint8Array();
|
|
1391
|
+
const expiresMarker = expiresAfter !== void 0 ? new Uint8Array([0]) : new Uint8Array();
|
|
1392
|
+
const expiresBytes = expiresAfter !== void 0 ? toUint64Bytes(expiresAfter) : new Uint8Array();
|
|
1393
|
+
const bytes = concatBytes(actionBytes, nonceBytes, vaultMarker, vaultBytes, expiresMarker, expiresBytes);
|
|
1394
|
+
return keccak256(bytes);
|
|
1395
|
+
}
|
|
1396
|
+
function buildHyperliquidAgentTypedData(args) {
|
|
1397
|
+
const connectionId = createHyperliquidL1ActionHash(args);
|
|
1398
|
+
const source = args.isTestnet ? "b" : "a";
|
|
1399
|
+
return {
|
|
1400
|
+
domain: EXCHANGE_DOMAIN,
|
|
1401
|
+
types: AGENT_TYPES,
|
|
1402
|
+
primaryType: "Agent",
|
|
1403
|
+
message: {
|
|
1404
|
+
source,
|
|
1405
|
+
connectionId
|
|
1406
|
+
},
|
|
1407
|
+
connectionId,
|
|
1408
|
+
nonce: args.nonce,
|
|
1409
|
+
action: args.action
|
|
1410
|
+
};
|
|
1411
|
+
}
|
|
1412
|
+
function buildHyperliquidUpdateLeverageAction(args) {
|
|
1413
|
+
const leverage = Math.trunc(args.leverage);
|
|
1414
|
+
if (!Number.isFinite(leverage) || leverage < 1) {
|
|
1415
|
+
throw new Error("leverage must be a positive integer");
|
|
1416
|
+
}
|
|
1417
|
+
return {
|
|
1418
|
+
type: "updateLeverage",
|
|
1419
|
+
asset: args.asset,
|
|
1420
|
+
isCross: args.isCross !== false,
|
|
1421
|
+
leverage
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
var EIP712_SIGN_REQUEST_KIND = "eip712";
|
|
1425
|
+
function msgHashNo0x(digest) {
|
|
1426
|
+
return digest.startsWith("0x") ? digest.slice(2) : digest;
|
|
1427
|
+
}
|
|
1428
|
+
function eip712SignatureText(domain, primaryType) {
|
|
1429
|
+
return JSON.stringify({
|
|
1430
|
+
kind: "EIP-712",
|
|
1431
|
+
...typeof domain.name === "string" ? { name: domain.name } : {},
|
|
1432
|
+
primaryType
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
function jsonStringifyForAudit(value) {
|
|
1436
|
+
return JSON.stringify(value, (_, v) => typeof v === "bigint" ? v.toString() : v);
|
|
1437
|
+
}
|
|
1438
|
+
function eip712MsgRawHex(typedData, delivery) {
|
|
1439
|
+
const envelope = {
|
|
1440
|
+
version: 1,
|
|
1441
|
+
...typedData,
|
|
1442
|
+
delivery
|
|
1443
|
+
};
|
|
1444
|
+
return stringToHex(jsonStringifyForAudit(envelope));
|
|
1445
|
+
}
|
|
1446
|
+
function buildEip712MultisignBody(args) {
|
|
1447
|
+
const { typedData, delivery } = args;
|
|
1448
|
+
const digest = hashTypedData({
|
|
1449
|
+
domain: typedData.domain,
|
|
1450
|
+
types: typedData.types,
|
|
1451
|
+
primaryType: typedData.primaryType,
|
|
1452
|
+
message: typedData.message
|
|
1453
|
+
});
|
|
1454
|
+
const extraJSON = {
|
|
1455
|
+
signRequestKind: EIP712_SIGN_REQUEST_KIND,
|
|
1456
|
+
eip712: {
|
|
1457
|
+
version: 1,
|
|
1458
|
+
digest,
|
|
1459
|
+
domain: typedData.domain,
|
|
1460
|
+
types: typedData.types,
|
|
1461
|
+
primaryType: typedData.primaryType,
|
|
1462
|
+
message: typedData.message
|
|
1463
|
+
},
|
|
1464
|
+
delivery
|
|
1465
|
+
};
|
|
1466
|
+
return finalizeMultisign({
|
|
1467
|
+
keyGen: args.keyGen,
|
|
1468
|
+
purposeText: args.purposeText,
|
|
1469
|
+
purposeSuffix: args.purposeSuffix,
|
|
1470
|
+
destinationChainID: args.destinationChainID,
|
|
1471
|
+
destinationAddress: args.destinationAddress,
|
|
1472
|
+
extraJSON,
|
|
1473
|
+
expiryDate: args.expiryDate,
|
|
1474
|
+
legs: [
|
|
1475
|
+
{
|
|
1476
|
+
msgHash: msgHashNo0x(digest),
|
|
1477
|
+
msgRaw: eip712MsgRawHex(typedData, delivery),
|
|
1478
|
+
destinationAddress: args.destinationAddress,
|
|
1479
|
+
signatureText: eip712SignatureText(typedData.domain, typedData.primaryType),
|
|
1480
|
+
audit: {
|
|
1481
|
+
kind: "EIP712",
|
|
1482
|
+
primaryType: typedData.primaryType,
|
|
1483
|
+
deliveryKind: delivery.kind,
|
|
1484
|
+
...args.audit ?? {}
|
|
1485
|
+
},
|
|
1486
|
+
feeSnapshot: {}
|
|
1487
|
+
}
|
|
1488
|
+
]
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
// src/protocols/evm/hyperliquid/exchangeMultisign.ts
|
|
1493
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
1494
|
+
async function buildHyperliquidUpdateLeverageMultisign(args) {
|
|
1495
|
+
const marketKind = args.marketKind ?? "perp";
|
|
1496
|
+
const { asset } = await hyperliquidResolveAsset({
|
|
1497
|
+
chainId: args.chainId,
|
|
1498
|
+
coin: args.coin,
|
|
1499
|
+
marketKind,
|
|
1500
|
+
dex: args.dex
|
|
1501
|
+
});
|
|
1502
|
+
const action = buildHyperliquidUpdateLeverageAction({
|
|
1503
|
+
asset,
|
|
1504
|
+
leverage: args.leverage,
|
|
1505
|
+
isCross: args.isCross
|
|
1506
|
+
});
|
|
1507
|
+
const nonce = args.nonce ?? Date.now();
|
|
1508
|
+
const isTestnet = args.chainId === 998;
|
|
1509
|
+
const typed = buildHyperliquidAgentTypedData({ action, nonce, isTestnet });
|
|
1510
|
+
return buildEip712MultisignBody({
|
|
1511
|
+
keyGen: args.keyGen,
|
|
1512
|
+
purposeText: args.purposeText,
|
|
1513
|
+
destinationChainID: String(args.chainId),
|
|
1514
|
+
destinationAddress: ZERO_ADDRESS,
|
|
1515
|
+
typedData: {
|
|
1516
|
+
domain: typed.domain,
|
|
1517
|
+
types: typed.types,
|
|
1518
|
+
primaryType: typed.primaryType,
|
|
1519
|
+
message: typed.message
|
|
1520
|
+
},
|
|
1521
|
+
delivery: {
|
|
1522
|
+
kind: "hyperliquid_exchange",
|
|
1523
|
+
chainId: args.chainId,
|
|
1524
|
+
isTestnet,
|
|
1525
|
+
action,
|
|
1526
|
+
nonce
|
|
1527
|
+
},
|
|
1528
|
+
audit: {
|
|
1529
|
+
protocol: "hyperliquid",
|
|
1530
|
+
action: "updateLeverage",
|
|
1531
|
+
coin: args.coin,
|
|
1532
|
+
marketKind,
|
|
1533
|
+
asset,
|
|
1534
|
+
leverage: action.leverage,
|
|
1535
|
+
isCross: action.isCross,
|
|
1536
|
+
nonce,
|
|
1537
|
+
connectionId: typed.connectionId
|
|
1538
|
+
}
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
var HYPERLIQUID_BRIDGE_MIN_DEPOSIT_USDC = 5;
|
|
1542
|
+
var HYPERLIQUID_BRIDGE_ARBITRUM_MAINNET_CHAIN_ID = 42161;
|
|
1543
|
+
var HYPERLIQUID_BRIDGE_ARBITRUM_TESTNET_CHAIN_ID = 421614;
|
|
1544
|
+
var BRIDGE_MAINNET = {
|
|
1545
|
+
bridge2: "0x2df1c51e09aecf9cacb7bc98cb1742757f163df7",
|
|
1546
|
+
usdc: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
1547
|
+
label: "Arbitrum One"
|
|
1548
|
+
};
|
|
1549
|
+
var BRIDGE_TESTNET = {
|
|
1550
|
+
bridge2: "0x08cfc1B6b2dCF36A1480b99353A354AA8AC56f89",
|
|
1551
|
+
usdc: "0x1baAbB04529D43a73232B713C0FE471f7c7334d5",
|
|
1552
|
+
label: "Arbitrum Sepolia"
|
|
1553
|
+
};
|
|
1554
|
+
var HYPERLIQUID_HYPEREVM_USDC_MAINNET = "0xb88339cb7199b77e23db6e890353e22632ba630f";
|
|
1555
|
+
var HYPERLIQUID_HYPEREVM_USDC_TESTNET = "0x2B3370eE501B4a559b57D449569354196457D8Ab";
|
|
1556
|
+
var HYPERLIQUID_USER_SIGNED_SIGNATURE_CHAIN_ID = "0x66eee";
|
|
1557
|
+
var HYPERLIQUID_BRIDGE_ERC20_TRANSFER_FALLBACK_GAS = 80000n;
|
|
1558
|
+
function hyperliquidBridgeArbitrumChainId(hyperEvmChainId) {
|
|
1559
|
+
if (hyperEvmChainId === 999) return HYPERLIQUID_BRIDGE_ARBITRUM_MAINNET_CHAIN_ID;
|
|
1560
|
+
if (hyperEvmChainId === 998) return HYPERLIQUID_BRIDGE_ARBITRUM_TESTNET_CHAIN_ID;
|
|
1561
|
+
return null;
|
|
1562
|
+
}
|
|
1563
|
+
function hyperliquidBridgeConfig(arbitrumChainId) {
|
|
1564
|
+
if (arbitrumChainId === HYPERLIQUID_BRIDGE_ARBITRUM_MAINNET_CHAIN_ID) {
|
|
1565
|
+
return {
|
|
1566
|
+
bridge2: getAddress(BRIDGE_MAINNET.bridge2),
|
|
1567
|
+
usdc: getAddress(BRIDGE_MAINNET.usdc),
|
|
1568
|
+
label: BRIDGE_MAINNET.label
|
|
1569
|
+
};
|
|
1570
|
+
}
|
|
1571
|
+
if (arbitrumChainId === HYPERLIQUID_BRIDGE_ARBITRUM_TESTNET_CHAIN_ID) {
|
|
1572
|
+
return {
|
|
1573
|
+
bridge2: getAddress(BRIDGE_TESTNET.bridge2),
|
|
1574
|
+
usdc: getAddress(BRIDGE_TESTNET.usdc),
|
|
1575
|
+
label: BRIDGE_TESTNET.label
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
return null;
|
|
1579
|
+
}
|
|
1580
|
+
function isHyperliquidBridgeArbitrumChainSupported(chainId) {
|
|
1581
|
+
return hyperliquidBridgeConfig(chainId) != null;
|
|
1582
|
+
}
|
|
1583
|
+
function isHyperliquidBridgeArbitrumUsdcRow(chainId, contractAddress) {
|
|
1584
|
+
const cfg = hyperliquidBridgeConfig(chainId);
|
|
1585
|
+
if (!cfg) return false;
|
|
1586
|
+
try {
|
|
1587
|
+
return getAddress(contractAddress).toLowerCase() === cfg.usdc.toLowerCase();
|
|
1588
|
+
} catch {
|
|
1589
|
+
return false;
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
function isHyperliquidHyperEvmUsdcRow(hyperEvmChainId, contractAddress) {
|
|
1593
|
+
const expected = hyperEvmChainId === 999 ? HYPERLIQUID_HYPEREVM_USDC_MAINNET : hyperEvmChainId === 998 ? HYPERLIQUID_HYPEREVM_USDC_TESTNET : null;
|
|
1594
|
+
if (!expected) return false;
|
|
1595
|
+
try {
|
|
1596
|
+
return getAddress(contractAddress).toLowerCase() === getAddress(expected).toLowerCase();
|
|
1597
|
+
} catch {
|
|
1598
|
+
return false;
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
var HYPERLIQUID_USER_SIGNED_DOMAIN = {
|
|
1602
|
+
name: "HyperliquidSignTransaction",
|
|
1603
|
+
version: "1",
|
|
1604
|
+
verifyingContract: "0x0000000000000000000000000000000000000000"
|
|
1605
|
+
};
|
|
1606
|
+
var HYPERLIQUID_WITHDRAW_SIGN_TYPES = {
|
|
1607
|
+
"HyperliquidTransaction:Withdraw": [
|
|
1608
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
1609
|
+
{ name: "destination", type: "string" },
|
|
1610
|
+
{ name: "amount", type: "string" },
|
|
1611
|
+
{ name: "time", type: "uint64" }
|
|
1612
|
+
]
|
|
1613
|
+
};
|
|
1614
|
+
function buildHyperliquidWithdraw3Action(args) {
|
|
1615
|
+
const amount = args.amountHuman.trim();
|
|
1616
|
+
if (!amount || !/^\d+(\.\d+)?$/.test(amount.replace(/,/g, ""))) {
|
|
1617
|
+
throw new Error("amountHuman must be a positive decimal string");
|
|
1618
|
+
}
|
|
1619
|
+
if (Number(amount.replace(/,/g, "")) <= 0) {
|
|
1620
|
+
throw new Error("amountHuman must be greater than zero");
|
|
1621
|
+
}
|
|
1622
|
+
const destination = getAddress(args.destination);
|
|
1623
|
+
const time = args.timeMs ?? Date.now();
|
|
1624
|
+
const hyperliquidChain = args.isTestnet ? "Testnet" : "Mainnet";
|
|
1625
|
+
const signatureChainId = "0x66eee";
|
|
1626
|
+
const action = {
|
|
1627
|
+
type: "withdraw3",
|
|
1628
|
+
signatureChainId,
|
|
1629
|
+
hyperliquidChain,
|
|
1630
|
+
destination: destination.toLowerCase(),
|
|
1631
|
+
amount,
|
|
1632
|
+
time
|
|
1633
|
+
};
|
|
1634
|
+
return { action, nonce: time };
|
|
1635
|
+
}
|
|
1636
|
+
function buildHyperliquidWithdraw3TypedData(args) {
|
|
1637
|
+
const chainId = Number.parseInt(args.action.signatureChainId, 16);
|
|
1638
|
+
return {
|
|
1639
|
+
domain: {
|
|
1640
|
+
...HYPERLIQUID_USER_SIGNED_DOMAIN,
|
|
1641
|
+
chainId
|
|
1642
|
+
},
|
|
1643
|
+
types: HYPERLIQUID_WITHDRAW_SIGN_TYPES,
|
|
1644
|
+
primaryType: "HyperliquidTransaction:Withdraw",
|
|
1645
|
+
message: {
|
|
1646
|
+
hyperliquidChain: args.action.hyperliquidChain,
|
|
1647
|
+
destination: args.action.destination,
|
|
1648
|
+
amount: args.action.amount,
|
|
1649
|
+
time: args.action.time
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
var erc20TransferAbi = parseAbi(["function transfer(address to, uint256 amount) returns (bool)"]);
|
|
1654
|
+
var ZERO_ADDRESS2 = "0x0000000000000000000000000000000000000000";
|
|
1655
|
+
function parseUsdHumanTo6(usdHuman) {
|
|
1656
|
+
const trimmed = usdHuman.trim().replace(/,/g, "");
|
|
1657
|
+
if (!trimmed || !/^\d+(\.\d+)?$/.test(trimmed)) {
|
|
1658
|
+
throw new Error("usdHuman must be a positive decimal string");
|
|
1659
|
+
}
|
|
1660
|
+
return parseUnits(trimmed, 6);
|
|
1661
|
+
}
|
|
1662
|
+
async function buildEvmMultisignBodyHyperliquidBridgeDepositBatch(args) {
|
|
1663
|
+
const cfg = hyperliquidBridgeConfig(args.chainId);
|
|
1664
|
+
if (!cfg) throw new Error("chainId must be Arbitrum One (42161) or Arbitrum Sepolia (421614)");
|
|
1665
|
+
const amountWei = parseUsdHumanTo6(args.usdHuman);
|
|
1666
|
+
const minWei = parseUnits(String(HYPERLIQUID_BRIDGE_MIN_DEPOSIT_USDC), 6);
|
|
1667
|
+
if (amountWei < minWei) {
|
|
1668
|
+
throw new Error(`Bridge deposit must be at least ${HYPERLIQUID_BRIDGE_MIN_DEPOSIT_USDC} USDC`);
|
|
1669
|
+
}
|
|
1670
|
+
const executor = getAddress(args.executorAddress);
|
|
1671
|
+
const data = encodeFunctionData({
|
|
1672
|
+
abi: erc20TransferAbi,
|
|
1673
|
+
functionName: "transfer",
|
|
1674
|
+
args: [cfg.bridge2, amountWei]
|
|
1675
|
+
});
|
|
1676
|
+
return buildEvmMultisignBatch({
|
|
1677
|
+
context: {
|
|
1678
|
+
keyGen: args.keyGen,
|
|
1679
|
+
chainCategory: "evm",
|
|
1680
|
+
chainId: args.chainId,
|
|
1681
|
+
rpcUrl: args.rpcUrl,
|
|
1682
|
+
chainDetail: args.chainDetail,
|
|
1683
|
+
useCustomGas: args.useCustomGas,
|
|
1684
|
+
customGasChainDetails: args.customGasChainDetails ?? null,
|
|
1685
|
+
executorAddress: executor,
|
|
1686
|
+
purposeText: args.purposeText
|
|
1687
|
+
},
|
|
1688
|
+
steps: [{ to: cfg.usdc, data, value: 0n, fallbackGas: HYPERLIQUID_BRIDGE_ERC20_TRANSFER_FALLBACK_GAS }],
|
|
1689
|
+
destinationAddress: cfg.usdc,
|
|
1690
|
+
buildBatchMeta: () => ({
|
|
1691
|
+
kind: "Hyperliquid",
|
|
1692
|
+
action: "bridgeDeposit",
|
|
1693
|
+
arbitrumChainId: args.chainId,
|
|
1694
|
+
usdc: cfg.usdc,
|
|
1695
|
+
bridge2: cfg.bridge2,
|
|
1696
|
+
usdHuman: args.usdHuman,
|
|
1697
|
+
evm: { type: "hyperliquid_bridge_deposit", version: 1, chainId: String(args.chainId) }
|
|
1698
|
+
})
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1701
|
+
async function buildHyperliquidBridgeWithdrawMultisign(args) {
|
|
1702
|
+
if (!isHyperliquidChainSupported(args.chainId)) {
|
|
1703
|
+
throw new Error("chainId must be 999 or 998");
|
|
1704
|
+
}
|
|
1705
|
+
const isTestnet = args.chainId === 998;
|
|
1706
|
+
const destination = getAddress(args.destination ?? args.executorAddress);
|
|
1707
|
+
const { action, nonce } = buildHyperliquidWithdraw3Action({
|
|
1708
|
+
destination,
|
|
1709
|
+
amountHuman: args.usdHuman,
|
|
1710
|
+
isTestnet
|
|
1711
|
+
});
|
|
1712
|
+
const typed = buildHyperliquidWithdraw3TypedData({ action });
|
|
1713
|
+
return buildEip712MultisignBody({
|
|
1714
|
+
keyGen: args.keyGen,
|
|
1715
|
+
purposeText: args.purposeText,
|
|
1716
|
+
destinationChainID: String(args.chainId),
|
|
1717
|
+
destinationAddress: ZERO_ADDRESS2,
|
|
1718
|
+
typedData: typed,
|
|
1719
|
+
delivery: {
|
|
1720
|
+
kind: "hyperliquid_exchange",
|
|
1721
|
+
chainId: args.chainId,
|
|
1722
|
+
isTestnet,
|
|
1723
|
+
action,
|
|
1724
|
+
nonce
|
|
1725
|
+
},
|
|
1726
|
+
audit: {
|
|
1727
|
+
protocol: "hyperliquid",
|
|
1728
|
+
action: "bridgeWithdraw",
|
|
1729
|
+
usdHuman: args.usdHuman,
|
|
1730
|
+
destination,
|
|
1731
|
+
nonce,
|
|
1732
|
+
hyperliquidChain: action.hyperliquidChain
|
|
1733
|
+
}
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1327
1736
|
|
|
1328
1737
|
// src/protocols/evm/hyperliquid/index.ts
|
|
1329
1738
|
var HYPERLIQUID_PROTOCOL_ID = "hyperliquid";
|
|
@@ -1444,6 +1853,40 @@ var hyperliquidProtocolModule = {
|
|
|
1444
1853
|
validator: { type: "string", required: true, description: "Validator address" }
|
|
1445
1854
|
}
|
|
1446
1855
|
},
|
|
1856
|
+
{
|
|
1857
|
+
id: "hyperliquid.bridgeDeposit",
|
|
1858
|
+
protocolId: HYPERLIQUID_PROTOCOL_ID,
|
|
1859
|
+
chainCategory: "evm",
|
|
1860
|
+
description: "Deposit USDC from Arbitrum to Hyperliquid via Bridge2 (ERC20 transfer)",
|
|
1861
|
+
commonParams: ["keyGen", "purposeText", "useCustomGas"],
|
|
1862
|
+
params: {
|
|
1863
|
+
usdHuman: { type: "string", required: true, description: "USDC amount (min 5)" }
|
|
1864
|
+
}
|
|
1865
|
+
},
|
|
1866
|
+
{
|
|
1867
|
+
id: "hyperliquid.bridgeWithdraw",
|
|
1868
|
+
protocolId: HYPERLIQUID_PROTOCOL_ID,
|
|
1869
|
+
chainCategory: "evm",
|
|
1870
|
+
description: "Withdraw USDC from Hyperliquid to Arbitrum via withdraw3 (EIP-712 /exchange)",
|
|
1871
|
+
commonParams: ["keyGen", "purposeText"],
|
|
1872
|
+
params: {
|
|
1873
|
+
usdHuman: { type: "string", required: true, description: "USDC amount" },
|
|
1874
|
+
destination: { type: "string", required: false, description: "Arbitrum recipient (defaults to executor)" }
|
|
1875
|
+
}
|
|
1876
|
+
},
|
|
1877
|
+
{
|
|
1878
|
+
id: "hyperliquid.updateLeverage",
|
|
1879
|
+
protocolId: HYPERLIQUID_PROTOCOL_ID,
|
|
1880
|
+
chainCategory: "evm",
|
|
1881
|
+
description: "Update per-market cross/isolated leverage via Hyperliquid L1 /exchange (EIP-712)",
|
|
1882
|
+
commonParams: ["keyGen", "purposeText"],
|
|
1883
|
+
params: {
|
|
1884
|
+
coin: { type: "string", required: true, description: "Market coin e.g. BTC" },
|
|
1885
|
+
leverage: { type: "number", required: true, description: "New leverage (1..market max)" },
|
|
1886
|
+
isCross: { type: "boolean", required: false, description: "true for cross (default), false for isolated" },
|
|
1887
|
+
marketKind: { type: "string", required: false, description: "perp (default) or spot" }
|
|
1888
|
+
}
|
|
1889
|
+
},
|
|
1447
1890
|
{
|
|
1448
1891
|
id: "hyperliquid.undelegate",
|
|
1449
1892
|
protocolId: HYPERLIQUID_PROTOCOL_ID,
|
|
@@ -1459,6 +1902,6 @@ var hyperliquidProtocolModule = {
|
|
|
1459
1902
|
};
|
|
1460
1903
|
registerProtocolModule(hyperliquidProtocolModule);
|
|
1461
1904
|
|
|
1462
|
-
export { HYPERLIQUID_CORE_WRITER_ADDRESS, HYPERLIQUID_CORE_WRITER_GAS_FALLBACK, HYPERLIQUID_DEFAULT_CANDLE_LIMIT, HYPERLIQUID_DEFAULT_LOOKBACK_DAYS, HYPERLIQUID_DEFAULT_OHLCV_INTERVAL, HYPERLIQUID_HLP_VAULT_ADDRESS, HYPERLIQUID_INTERVAL_MS, HYPERLIQUID_MAX_CANDLE_LIMIT, HYPERLIQUID_MAX_LOOKBACK_DAYS, HYPERLIQUID_MAX_OHLCV_BARS, HYPERLIQUID_PROTOCOL_ID, HYPERLIQUID_SPOT_ASSET_OFFSET, HYPERLIQUID_SUPPORTED_CHAIN_IDS, HYPERLIQUID_TIF, buildCoreWriterCancelByCloidCalldata, buildCoreWriterCancelByOidCalldata, buildCoreWriterLimitOrderCalldata, buildCoreWriterStakingDepositCalldata, buildCoreWriterStakingWithdrawCalldata, buildCoreWriterTokenDelegateCalldata, buildCoreWriterUsdClassTransferCalldata, buildCoreWriterVaultTransferCalldata, buildEvmMultisignBodyHyperliquidCancelBatch, buildEvmMultisignBodyHyperliquidCloseBatch, buildEvmMultisignBodyHyperliquidDelegateBatch, buildEvmMultisignBodyHyperliquidDelegateOnlyBatch, buildEvmMultisignBodyHyperliquidLimitOrderBatch, buildEvmMultisignBodyHyperliquidStakeDepositBatch, buildEvmMultisignBodyHyperliquidStakeWithdrawBatch, buildEvmMultisignBodyHyperliquidUndelegateBatch, buildEvmMultisignBodyHyperliquidUsdClassTransferBatch, buildEvmMultisignBodyHyperliquidVaultDepositBatch, buildEvmMultisignBodyHyperliquidVaultWithdrawBatch, coreWriterStep, hyperliquidApiBaseUrl, hyperliquidCollectAllPerpMarkets, hyperliquidEncodePx8, hyperliquidEncodeUsd6, hyperliquidEncodeWei8, hyperliquidFetchActiveAssetData, hyperliquidFetchAllMids, hyperliquidFetchCandles, hyperliquidFetchClearinghouseState, hyperliquidFetchDelegations, hyperliquidFetchDelegationsForExecutor, hyperliquidFetchDexList, hyperliquidFetchMarketSnapshot, hyperliquidFetchMarketSnapshotSummary, hyperliquidFetchMarketsSummary, hyperliquidFetchOhlcvRange, hyperliquidFetchOhlcvSummary, hyperliquidFetchOpenContextSummary, hyperliquidFetchOpenMarketContext, hyperliquidFetchOpenOrders, hyperliquidFetchOpenOrdersSummary, hyperliquidFetchOrdersForExecutor, hyperliquidFetchPerpAssetContext, hyperliquidFetchPerpConciseAnnotations, hyperliquidFetchPerpMeta, hyperliquidFetchPositionDisplayRows, hyperliquidFetchPositionsForExecutor, hyperliquidFetchSpotClearinghouseState, hyperliquidFetchSpotMeta, hyperliquidFetchStakingSummary, hyperliquidFetchStakingSummaryForExecutor, hyperliquidFetchUsdClassBalances, hyperliquidFetchUsdClassBalancesSummary, hyperliquidFetchUserVaultEquities, hyperliquidFetchUserVaultEquitiesSummary, hyperliquidFetchVaultCatalogSummary, hyperliquidFetchVaultSummaries, hyperliquidInferDexFromCoin, hyperliquidIsSpotAssetId, hyperliquidMarketSymbol, hyperliquidProtocolModule, hyperliquidResolveAsset, hyperliquidResolveOhlcvWindow, hyperliquidResolvePerpAsset, hyperliquidResolvePerpMarket, hyperliquidResolveSpotAsset, hyperliquidResolveTif, hyperliquidSearchMarkets, hyperliquidSearchMarketsSummary, hyperliquidVaultStatsUrl, isHyperliquidChainSupported };
|
|
1905
|
+
export { HYPERLIQUID_BRIDGE_ARBITRUM_MAINNET_CHAIN_ID, HYPERLIQUID_BRIDGE_ARBITRUM_TESTNET_CHAIN_ID, HYPERLIQUID_BRIDGE_ERC20_TRANSFER_FALLBACK_GAS, HYPERLIQUID_BRIDGE_MIN_DEPOSIT_USDC, HYPERLIQUID_CORE_WRITER_ADDRESS, HYPERLIQUID_CORE_WRITER_GAS_FALLBACK, HYPERLIQUID_DEFAULT_CANDLE_LIMIT, HYPERLIQUID_DEFAULT_LOOKBACK_DAYS, HYPERLIQUID_DEFAULT_OHLCV_INTERVAL, HYPERLIQUID_HLP_VAULT_ADDRESS, HYPERLIQUID_HYPEREVM_USDC_MAINNET, HYPERLIQUID_HYPEREVM_USDC_TESTNET, HYPERLIQUID_INTERVAL_MS, HYPERLIQUID_MAX_CANDLE_LIMIT, HYPERLIQUID_MAX_LOOKBACK_DAYS, HYPERLIQUID_MAX_OHLCV_BARS, HYPERLIQUID_PROTOCOL_ID, HYPERLIQUID_SPOT_ASSET_OFFSET, HYPERLIQUID_SUPPORTED_CHAIN_IDS, HYPERLIQUID_TIF, HYPERLIQUID_USER_SIGNED_DOMAIN, HYPERLIQUID_USER_SIGNED_SIGNATURE_CHAIN_ID, HYPERLIQUID_WITHDRAW_SIGN_TYPES, buildCoreWriterCancelByCloidCalldata, buildCoreWriterCancelByOidCalldata, buildCoreWriterLimitOrderCalldata, buildCoreWriterStakingDepositCalldata, buildCoreWriterStakingWithdrawCalldata, buildCoreWriterTokenDelegateCalldata, buildCoreWriterUsdClassTransferCalldata, buildCoreWriterVaultTransferCalldata, buildEvmMultisignBodyHyperliquidBridgeDepositBatch, buildEvmMultisignBodyHyperliquidCancelBatch, buildEvmMultisignBodyHyperliquidCloseBatch, buildEvmMultisignBodyHyperliquidDelegateBatch, buildEvmMultisignBodyHyperliquidDelegateOnlyBatch, buildEvmMultisignBodyHyperliquidLimitOrderBatch, buildEvmMultisignBodyHyperliquidStakeDepositBatch, buildEvmMultisignBodyHyperliquidStakeWithdrawBatch, buildEvmMultisignBodyHyperliquidUndelegateBatch, buildEvmMultisignBodyHyperliquidUsdClassTransferBatch, buildEvmMultisignBodyHyperliquidVaultDepositBatch, buildEvmMultisignBodyHyperliquidVaultWithdrawBatch, buildHyperliquidAgentTypedData, buildHyperliquidBridgeWithdrawMultisign, buildHyperliquidUpdateLeverageAction, buildHyperliquidUpdateLeverageMultisign, buildHyperliquidWithdraw3Action, buildHyperliquidWithdraw3TypedData, coreWriterStep, createHyperliquidL1ActionHash, hyperliquidApiBaseUrl, hyperliquidBridgeArbitrumChainId, hyperliquidBridgeConfig, hyperliquidCollectAllPerpMarkets, hyperliquidEncodePx8, hyperliquidEncodeUsd6, hyperliquidEncodeWei8, hyperliquidFetchActiveAssetData, hyperliquidFetchAllMids, hyperliquidFetchCandles, hyperliquidFetchClearinghouseState, hyperliquidFetchDelegations, hyperliquidFetchDelegationsForExecutor, hyperliquidFetchDexList, hyperliquidFetchMarketSnapshot, hyperliquidFetchMarketSnapshotSummary, hyperliquidFetchMarketsSummary, hyperliquidFetchOhlcvRange, hyperliquidFetchOhlcvSummary, hyperliquidFetchOpenContextSummary, hyperliquidFetchOpenMarketContext, hyperliquidFetchOpenOrders, hyperliquidFetchOpenOrdersSummary, hyperliquidFetchOrdersForExecutor, hyperliquidFetchPerpAssetContext, hyperliquidFetchPerpConciseAnnotations, hyperliquidFetchPerpMeta, hyperliquidFetchPositionDisplayRows, hyperliquidFetchPositionsForExecutor, hyperliquidFetchSpotClearinghouseState, hyperliquidFetchSpotMeta, hyperliquidFetchStakingSummary, hyperliquidFetchStakingSummaryForExecutor, hyperliquidFetchUsdClassBalances, hyperliquidFetchUsdClassBalancesSummary, hyperliquidFetchUserVaultEquities, hyperliquidFetchUserVaultEquitiesSummary, hyperliquidFetchVaultCatalogSummary, hyperliquidFetchVaultSummaries, hyperliquidInferDexFromCoin, hyperliquidIsSpotAssetId, hyperliquidMarketSymbol, hyperliquidProtocolModule, hyperliquidResolveAsset, hyperliquidResolveOhlcvWindow, hyperliquidResolvePerpAsset, hyperliquidResolvePerpMarket, hyperliquidResolveSpotAsset, hyperliquidResolveTif, hyperliquidSearchMarkets, hyperliquidSearchMarketsSummary, hyperliquidVaultStatsUrl, isHyperliquidBridgeArbitrumChainSupported, isHyperliquidBridgeArbitrumUsdcRow, isHyperliquidChainSupported, isHyperliquidHyperEvmUsdcRow };
|
|
1463
1906
|
//# sourceMappingURL=index.js.map
|
|
1464
1907
|
//# sourceMappingURL=index.js.map
|