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