@continuumdao/ctm-mpc-defi 0.2.19 → 0.2.20
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 +185 -56
- package/dist/agent/catalog.cjs.map +1 -1
- package/dist/agent/catalog.d.ts +696 -633
- package/dist/agent/catalog.js +183 -57
- package/dist/agent/catalog.js.map +1 -1
- package/dist/agent/skills/hyperliquid/SKILL.md +24 -20
- package/dist/chains/evm/index.cjs +1 -1
- package/dist/chains/evm/index.cjs.map +1 -1
- package/dist/chains/evm/index.js +1 -1
- package/dist/chains/evm/index.js.map +1 -1
- package/dist/core/index.cjs +70 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +35 -2
- package/dist/core/index.js +69 -2
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +69 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +69 -3
- package/dist/index.js.map +1 -1
- package/dist/protocols/evm/aave-v4/index.cjs +1 -1
- package/dist/protocols/evm/aave-v4/index.cjs.map +1 -1
- package/dist/protocols/evm/aave-v4/index.js +1 -1
- package/dist/protocols/evm/aave-v4/index.js.map +1 -1
- package/dist/protocols/evm/circle-cctp/index.cjs +1 -1
- package/dist/protocols/evm/circle-cctp/index.cjs.map +1 -1
- package/dist/protocols/evm/circle-cctp/index.js +1 -1
- package/dist/protocols/evm/circle-cctp/index.js.map +1 -1
- package/dist/protocols/evm/curve-dao/index.cjs +1 -1
- package/dist/protocols/evm/curve-dao/index.cjs.map +1 -1
- package/dist/protocols/evm/curve-dao/index.d.ts +1 -1
- package/dist/protocols/evm/curve-dao/index.js +1 -1
- package/dist/protocols/evm/curve-dao/index.js.map +1 -1
- package/dist/protocols/evm/ethena/index.cjs +1 -1
- package/dist/protocols/evm/ethena/index.cjs.map +1 -1
- package/dist/protocols/evm/ethena/index.js +1 -1
- package/dist/protocols/evm/ethena/index.js.map +1 -1
- package/dist/protocols/evm/euler-v2/index.cjs +1 -1
- package/dist/protocols/evm/euler-v2/index.cjs.map +1 -1
- package/dist/protocols/evm/euler-v2/index.js +1 -1
- package/dist/protocols/evm/euler-v2/index.js.map +1 -1
- package/dist/protocols/evm/gmx/index.cjs +49 -21
- package/dist/protocols/evm/gmx/index.cjs.map +1 -1
- package/dist/protocols/evm/gmx/index.d.ts +20 -6
- package/dist/protocols/evm/gmx/index.js +48 -22
- package/dist/protocols/evm/gmx/index.js.map +1 -1
- package/dist/protocols/evm/hyperliquid/index.cjs +461 -1
- package/dist/protocols/evm/hyperliquid/index.cjs.map +1 -1
- package/dist/protocols/evm/hyperliquid/index.d.ts +187 -1
- package/dist/protocols/evm/hyperliquid/index.js +441 -3
- package/dist/protocols/evm/hyperliquid/index.js.map +1 -1
- package/dist/protocols/evm/lido/index.cjs +1 -1
- package/dist/protocols/evm/lido/index.cjs.map +1 -1
- package/dist/protocols/evm/lido/index.js +1 -1
- package/dist/protocols/evm/lido/index.js.map +1 -1
- package/dist/protocols/evm/maple/index.cjs +1 -1
- package/dist/protocols/evm/maple/index.cjs.map +1 -1
- package/dist/protocols/evm/maple/index.js +1 -1
- package/dist/protocols/evm/maple/index.js.map +1 -1
- package/dist/protocols/evm/morpho/index.cjs +1 -1
- package/dist/protocols/evm/morpho/index.cjs.map +1 -1
- package/dist/protocols/evm/morpho/index.js +1 -1
- package/dist/protocols/evm/morpho/index.js.map +1 -1
- package/dist/protocols/evm/permit2/index.cjs +202 -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 +199 -0
- package/dist/protocols/evm/permit2/index.js.map +1 -0
- package/dist/protocols/evm/sky/index.cjs +1 -1
- package/dist/protocols/evm/sky/index.cjs.map +1 -1
- package/dist/protocols/evm/sky/index.js +1 -1
- package/dist/protocols/evm/sky/index.js.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.cjs +1 -1
- package/dist/protocols/evm/uniswap-v4/index.cjs.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.js +1 -1
- package/dist/protocols/evm/uniswap-v4/index.js.map +1 -1
- package/package.json +7 -1
|
@@ -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,
|
|
@@ -1326,6 +1330,406 @@ async function buildEvmMultisignBodyHyperliquidDelegateOnlyBatch(args) {
|
|
|
1326
1330
|
async function buildEvmMultisignBodyHyperliquidUndelegateBatch(args) {
|
|
1327
1331
|
return buildEvmMultisignBodyHyperliquidDelegateBatch({ ...args, isUndelegate: true });
|
|
1328
1332
|
}
|
|
1333
|
+
var EXCHANGE_DOMAIN = {
|
|
1334
|
+
name: "Exchange",
|
|
1335
|
+
version: "1",
|
|
1336
|
+
chainId: 1337,
|
|
1337
|
+
verifyingContract: "0x0000000000000000000000000000000000000000"
|
|
1338
|
+
};
|
|
1339
|
+
var AGENT_TYPES = {
|
|
1340
|
+
Agent: [
|
|
1341
|
+
{ name: "source", type: "string" },
|
|
1342
|
+
{ name: "connectionId", type: "bytes32" }
|
|
1343
|
+
]
|
|
1344
|
+
};
|
|
1345
|
+
function adjustMsgpackValue(value) {
|
|
1346
|
+
if (Array.isArray(value)) return value.map(adjustMsgpackValue);
|
|
1347
|
+
if (typeof value === "object" && value !== null) {
|
|
1348
|
+
const result = {};
|
|
1349
|
+
for (const key of Object.keys(value)) {
|
|
1350
|
+
const entry = value[key];
|
|
1351
|
+
if (entry !== void 0) result[key] = adjustMsgpackValue(entry);
|
|
1352
|
+
}
|
|
1353
|
+
return result;
|
|
1354
|
+
}
|
|
1355
|
+
if (typeof value === "number" && Number.isInteger(value) && (value >= 4294967296 || value < -2147483648)) {
|
|
1356
|
+
return BigInt(value);
|
|
1357
|
+
}
|
|
1358
|
+
return value;
|
|
1359
|
+
}
|
|
1360
|
+
function toUint64Bytes(n) {
|
|
1361
|
+
const bytes = new Uint8Array(8);
|
|
1362
|
+
new DataView(bytes.buffer).setBigUint64(0, BigInt(n));
|
|
1363
|
+
return bytes;
|
|
1364
|
+
}
|
|
1365
|
+
function concatBytes(...parts) {
|
|
1366
|
+
const total = parts.reduce((sum, p) => sum + p.length, 0);
|
|
1367
|
+
const out = new Uint8Array(total);
|
|
1368
|
+
let offset = 0;
|
|
1369
|
+
for (const p of parts) {
|
|
1370
|
+
out.set(p, offset);
|
|
1371
|
+
offset += p.length;
|
|
1372
|
+
}
|
|
1373
|
+
return out;
|
|
1374
|
+
}
|
|
1375
|
+
function hexToBytes(hex) {
|
|
1376
|
+
const h = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
1377
|
+
const bytes = new Uint8Array(h.length / 2);
|
|
1378
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
1379
|
+
bytes[i] = parseInt(h.slice(i * 2, i * 2 + 2), 16);
|
|
1380
|
+
}
|
|
1381
|
+
return bytes;
|
|
1382
|
+
}
|
|
1383
|
+
function createHyperliquidL1ActionHash(args) {
|
|
1384
|
+
const { action, nonce, vaultAddress, expiresAfter } = args;
|
|
1385
|
+
const actionBytes = msgpack.encode(adjustMsgpackValue(action));
|
|
1386
|
+
const nonceBytes = toUint64Bytes(nonce);
|
|
1387
|
+
const vaultMarker = vaultAddress ? new Uint8Array([1]) : new Uint8Array([0]);
|
|
1388
|
+
const vaultBytes = vaultAddress ? hexToBytes(vaultAddress) : new Uint8Array();
|
|
1389
|
+
const expiresMarker = expiresAfter !== void 0 ? new Uint8Array([0]) : new Uint8Array();
|
|
1390
|
+
const expiresBytes = expiresAfter !== void 0 ? toUint64Bytes(expiresAfter) : new Uint8Array();
|
|
1391
|
+
const bytes = concatBytes(actionBytes, nonceBytes, vaultMarker, vaultBytes, expiresMarker, expiresBytes);
|
|
1392
|
+
return viem.keccak256(bytes);
|
|
1393
|
+
}
|
|
1394
|
+
function buildHyperliquidAgentTypedData(args) {
|
|
1395
|
+
const connectionId = createHyperliquidL1ActionHash(args);
|
|
1396
|
+
const source = args.isTestnet ? "b" : "a";
|
|
1397
|
+
return {
|
|
1398
|
+
domain: EXCHANGE_DOMAIN,
|
|
1399
|
+
types: AGENT_TYPES,
|
|
1400
|
+
primaryType: "Agent",
|
|
1401
|
+
message: {
|
|
1402
|
+
source,
|
|
1403
|
+
connectionId
|
|
1404
|
+
},
|
|
1405
|
+
connectionId,
|
|
1406
|
+
nonce: args.nonce,
|
|
1407
|
+
action: args.action
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
function buildHyperliquidUpdateLeverageAction(args) {
|
|
1411
|
+
const leverage = Math.trunc(args.leverage);
|
|
1412
|
+
if (!Number.isFinite(leverage) || leverage < 1) {
|
|
1413
|
+
throw new Error("leverage must be a positive integer");
|
|
1414
|
+
}
|
|
1415
|
+
return {
|
|
1416
|
+
type: "updateLeverage",
|
|
1417
|
+
asset: args.asset,
|
|
1418
|
+
isCross: args.isCross !== false,
|
|
1419
|
+
leverage
|
|
1420
|
+
};
|
|
1421
|
+
}
|
|
1422
|
+
var EIP712_SIGN_REQUEST_KIND = "eip712";
|
|
1423
|
+
function msgHashNo0x(digest) {
|
|
1424
|
+
return digest.startsWith("0x") ? digest.slice(2) : digest;
|
|
1425
|
+
}
|
|
1426
|
+
function eip712SignatureText(domain, primaryType) {
|
|
1427
|
+
return JSON.stringify({
|
|
1428
|
+
kind: "EIP-712",
|
|
1429
|
+
...typeof domain.name === "string" ? { name: domain.name } : {},
|
|
1430
|
+
primaryType
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
function jsonStringifyForAudit(value) {
|
|
1434
|
+
return JSON.stringify(value, (_, v) => typeof v === "bigint" ? v.toString() : v);
|
|
1435
|
+
}
|
|
1436
|
+
function eip712MsgRawHex(typedData, delivery) {
|
|
1437
|
+
const envelope = {
|
|
1438
|
+
version: 1,
|
|
1439
|
+
...typedData,
|
|
1440
|
+
delivery
|
|
1441
|
+
};
|
|
1442
|
+
return viem.stringToHex(jsonStringifyForAudit(envelope));
|
|
1443
|
+
}
|
|
1444
|
+
function buildEip712MultisignBody(args) {
|
|
1445
|
+
const { typedData, delivery } = args;
|
|
1446
|
+
const digest = viem.hashTypedData({
|
|
1447
|
+
domain: typedData.domain,
|
|
1448
|
+
types: typedData.types,
|
|
1449
|
+
primaryType: typedData.primaryType,
|
|
1450
|
+
message: typedData.message
|
|
1451
|
+
});
|
|
1452
|
+
const extraJSON = {
|
|
1453
|
+
signRequestKind: EIP712_SIGN_REQUEST_KIND,
|
|
1454
|
+
eip712: {
|
|
1455
|
+
version: 1,
|
|
1456
|
+
digest,
|
|
1457
|
+
domain: typedData.domain,
|
|
1458
|
+
types: typedData.types,
|
|
1459
|
+
primaryType: typedData.primaryType,
|
|
1460
|
+
message: typedData.message
|
|
1461
|
+
},
|
|
1462
|
+
delivery
|
|
1463
|
+
};
|
|
1464
|
+
return finalizeMultisign({
|
|
1465
|
+
keyGen: args.keyGen,
|
|
1466
|
+
purposeText: args.purposeText,
|
|
1467
|
+
purposeSuffix: args.purposeSuffix,
|
|
1468
|
+
destinationChainID: args.destinationChainID,
|
|
1469
|
+
destinationAddress: args.destinationAddress,
|
|
1470
|
+
extraJSON,
|
|
1471
|
+
legs: [
|
|
1472
|
+
{
|
|
1473
|
+
msgHash: msgHashNo0x(digest),
|
|
1474
|
+
msgRaw: eip712MsgRawHex(typedData, delivery),
|
|
1475
|
+
destinationAddress: args.destinationAddress,
|
|
1476
|
+
signatureText: eip712SignatureText(typedData.domain, typedData.primaryType),
|
|
1477
|
+
audit: {
|
|
1478
|
+
kind: "EIP712",
|
|
1479
|
+
primaryType: typedData.primaryType,
|
|
1480
|
+
deliveryKind: delivery.kind,
|
|
1481
|
+
...args.audit ?? {}
|
|
1482
|
+
},
|
|
1483
|
+
feeSnapshot: {}
|
|
1484
|
+
}
|
|
1485
|
+
]
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
// src/protocols/evm/hyperliquid/exchangeMultisign.ts
|
|
1490
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
1491
|
+
async function buildHyperliquidUpdateLeverageMultisign(args) {
|
|
1492
|
+
const marketKind = args.marketKind ?? "perp";
|
|
1493
|
+
const { asset } = await hyperliquidResolveAsset({
|
|
1494
|
+
chainId: args.chainId,
|
|
1495
|
+
coin: args.coin,
|
|
1496
|
+
marketKind,
|
|
1497
|
+
dex: args.dex
|
|
1498
|
+
});
|
|
1499
|
+
const action = buildHyperliquidUpdateLeverageAction({
|
|
1500
|
+
asset,
|
|
1501
|
+
leverage: args.leverage,
|
|
1502
|
+
isCross: args.isCross
|
|
1503
|
+
});
|
|
1504
|
+
const nonce = args.nonce ?? Date.now();
|
|
1505
|
+
const isTestnet = args.chainId === 998;
|
|
1506
|
+
const typed = buildHyperliquidAgentTypedData({ action, nonce, isTestnet });
|
|
1507
|
+
return buildEip712MultisignBody({
|
|
1508
|
+
keyGen: args.keyGen,
|
|
1509
|
+
purposeText: args.purposeText,
|
|
1510
|
+
destinationChainID: String(args.chainId),
|
|
1511
|
+
destinationAddress: ZERO_ADDRESS,
|
|
1512
|
+
typedData: {
|
|
1513
|
+
domain: typed.domain,
|
|
1514
|
+
types: typed.types,
|
|
1515
|
+
primaryType: typed.primaryType,
|
|
1516
|
+
message: typed.message
|
|
1517
|
+
},
|
|
1518
|
+
delivery: {
|
|
1519
|
+
kind: "hyperliquid_exchange",
|
|
1520
|
+
chainId: args.chainId,
|
|
1521
|
+
isTestnet,
|
|
1522
|
+
action,
|
|
1523
|
+
nonce
|
|
1524
|
+
},
|
|
1525
|
+
audit: {
|
|
1526
|
+
protocol: "hyperliquid",
|
|
1527
|
+
action: "updateLeverage",
|
|
1528
|
+
coin: args.coin,
|
|
1529
|
+
marketKind,
|
|
1530
|
+
asset,
|
|
1531
|
+
leverage: action.leverage,
|
|
1532
|
+
isCross: action.isCross,
|
|
1533
|
+
nonce,
|
|
1534
|
+
connectionId: typed.connectionId
|
|
1535
|
+
}
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
var HYPERLIQUID_BRIDGE_MIN_DEPOSIT_USDC = 5;
|
|
1539
|
+
var HYPERLIQUID_BRIDGE_ARBITRUM_MAINNET_CHAIN_ID = 42161;
|
|
1540
|
+
var HYPERLIQUID_BRIDGE_ARBITRUM_TESTNET_CHAIN_ID = 421614;
|
|
1541
|
+
var BRIDGE_MAINNET = {
|
|
1542
|
+
bridge2: "0x2df1c51e09aecf9cacb7bc98cb1742757f163df7",
|
|
1543
|
+
usdc: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
1544
|
+
label: "Arbitrum One"
|
|
1545
|
+
};
|
|
1546
|
+
var BRIDGE_TESTNET = {
|
|
1547
|
+
bridge2: "0x08cfc1B6b2dCF36A1480b99353A354AA8AC56f89",
|
|
1548
|
+
usdc: "0x1baAbB04529D43a73232B713C0FE471f7c7334d5",
|
|
1549
|
+
label: "Arbitrum Sepolia"
|
|
1550
|
+
};
|
|
1551
|
+
var HYPERLIQUID_HYPEREVM_USDC_MAINNET = "0xb88339cb7199b77e23db6e890353e22632ba630f";
|
|
1552
|
+
var HYPERLIQUID_HYPEREVM_USDC_TESTNET = "0x2B3370eE501B4a559b57D449569354196457D8Ab";
|
|
1553
|
+
var HYPERLIQUID_USER_SIGNED_SIGNATURE_CHAIN_ID = "0x66eee";
|
|
1554
|
+
var HYPERLIQUID_BRIDGE_ERC20_TRANSFER_FALLBACK_GAS = 80000n;
|
|
1555
|
+
function hyperliquidBridgeArbitrumChainId(hyperEvmChainId) {
|
|
1556
|
+
if (hyperEvmChainId === 999) return HYPERLIQUID_BRIDGE_ARBITRUM_MAINNET_CHAIN_ID;
|
|
1557
|
+
if (hyperEvmChainId === 998) return HYPERLIQUID_BRIDGE_ARBITRUM_TESTNET_CHAIN_ID;
|
|
1558
|
+
return null;
|
|
1559
|
+
}
|
|
1560
|
+
function hyperliquidBridgeConfig(arbitrumChainId) {
|
|
1561
|
+
if (arbitrumChainId === HYPERLIQUID_BRIDGE_ARBITRUM_MAINNET_CHAIN_ID) {
|
|
1562
|
+
return {
|
|
1563
|
+
bridge2: viem.getAddress(BRIDGE_MAINNET.bridge2),
|
|
1564
|
+
usdc: viem.getAddress(BRIDGE_MAINNET.usdc),
|
|
1565
|
+
label: BRIDGE_MAINNET.label
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1568
|
+
if (arbitrumChainId === HYPERLIQUID_BRIDGE_ARBITRUM_TESTNET_CHAIN_ID) {
|
|
1569
|
+
return {
|
|
1570
|
+
bridge2: viem.getAddress(BRIDGE_TESTNET.bridge2),
|
|
1571
|
+
usdc: viem.getAddress(BRIDGE_TESTNET.usdc),
|
|
1572
|
+
label: BRIDGE_TESTNET.label
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1575
|
+
return null;
|
|
1576
|
+
}
|
|
1577
|
+
function isHyperliquidBridgeArbitrumChainSupported(chainId) {
|
|
1578
|
+
return hyperliquidBridgeConfig(chainId) != null;
|
|
1579
|
+
}
|
|
1580
|
+
function isHyperliquidBridgeArbitrumUsdcRow(chainId, contractAddress) {
|
|
1581
|
+
const cfg = hyperliquidBridgeConfig(chainId);
|
|
1582
|
+
if (!cfg) return false;
|
|
1583
|
+
try {
|
|
1584
|
+
return viem.getAddress(contractAddress).toLowerCase() === cfg.usdc.toLowerCase();
|
|
1585
|
+
} catch {
|
|
1586
|
+
return false;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
function isHyperliquidHyperEvmUsdcRow(hyperEvmChainId, contractAddress) {
|
|
1590
|
+
const expected = hyperEvmChainId === 999 ? HYPERLIQUID_HYPEREVM_USDC_MAINNET : hyperEvmChainId === 998 ? HYPERLIQUID_HYPEREVM_USDC_TESTNET : null;
|
|
1591
|
+
if (!expected) return false;
|
|
1592
|
+
try {
|
|
1593
|
+
return viem.getAddress(contractAddress).toLowerCase() === viem.getAddress(expected).toLowerCase();
|
|
1594
|
+
} catch {
|
|
1595
|
+
return false;
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
var HYPERLIQUID_USER_SIGNED_DOMAIN = {
|
|
1599
|
+
name: "HyperliquidSignTransaction",
|
|
1600
|
+
version: "1",
|
|
1601
|
+
verifyingContract: "0x0000000000000000000000000000000000000000"
|
|
1602
|
+
};
|
|
1603
|
+
var HYPERLIQUID_WITHDRAW_SIGN_TYPES = {
|
|
1604
|
+
"HyperliquidTransaction:Withdraw": [
|
|
1605
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
1606
|
+
{ name: "destination", type: "string" },
|
|
1607
|
+
{ name: "amount", type: "string" },
|
|
1608
|
+
{ name: "time", type: "uint64" }
|
|
1609
|
+
]
|
|
1610
|
+
};
|
|
1611
|
+
function buildHyperliquidWithdraw3Action(args) {
|
|
1612
|
+
const amount = args.amountHuman.trim();
|
|
1613
|
+
if (!amount || !/^\d+(\.\d+)?$/.test(amount.replace(/,/g, ""))) {
|
|
1614
|
+
throw new Error("amountHuman must be a positive decimal string");
|
|
1615
|
+
}
|
|
1616
|
+
if (Number(amount.replace(/,/g, "")) <= 0) {
|
|
1617
|
+
throw new Error("amountHuman must be greater than zero");
|
|
1618
|
+
}
|
|
1619
|
+
const destination = viem.getAddress(args.destination);
|
|
1620
|
+
const time = args.timeMs ?? Date.now();
|
|
1621
|
+
const hyperliquidChain = args.isTestnet ? "Testnet" : "Mainnet";
|
|
1622
|
+
const signatureChainId = "0x66eee";
|
|
1623
|
+
const action = {
|
|
1624
|
+
type: "withdraw3",
|
|
1625
|
+
signatureChainId,
|
|
1626
|
+
hyperliquidChain,
|
|
1627
|
+
destination: destination.toLowerCase(),
|
|
1628
|
+
amount,
|
|
1629
|
+
time
|
|
1630
|
+
};
|
|
1631
|
+
return { action, nonce: time };
|
|
1632
|
+
}
|
|
1633
|
+
function buildHyperliquidWithdraw3TypedData(args) {
|
|
1634
|
+
const chainId = Number.parseInt(args.action.signatureChainId, 16);
|
|
1635
|
+
return {
|
|
1636
|
+
domain: {
|
|
1637
|
+
...HYPERLIQUID_USER_SIGNED_DOMAIN,
|
|
1638
|
+
chainId
|
|
1639
|
+
},
|
|
1640
|
+
types: HYPERLIQUID_WITHDRAW_SIGN_TYPES,
|
|
1641
|
+
primaryType: "HyperliquidTransaction:Withdraw",
|
|
1642
|
+
message: {
|
|
1643
|
+
hyperliquidChain: args.action.hyperliquidChain,
|
|
1644
|
+
destination: args.action.destination,
|
|
1645
|
+
amount: args.action.amount,
|
|
1646
|
+
time: args.action.time
|
|
1647
|
+
}
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
var erc20TransferAbi = viem.parseAbi(["function transfer(address to, uint256 amount) returns (bool)"]);
|
|
1651
|
+
var ZERO_ADDRESS2 = "0x0000000000000000000000000000000000000000";
|
|
1652
|
+
function parseUsdHumanTo6(usdHuman) {
|
|
1653
|
+
const trimmed = usdHuman.trim().replace(/,/g, "");
|
|
1654
|
+
if (!trimmed || !/^\d+(\.\d+)?$/.test(trimmed)) {
|
|
1655
|
+
throw new Error("usdHuman must be a positive decimal string");
|
|
1656
|
+
}
|
|
1657
|
+
return viem.parseUnits(trimmed, 6);
|
|
1658
|
+
}
|
|
1659
|
+
async function buildEvmMultisignBodyHyperliquidBridgeDepositBatch(args) {
|
|
1660
|
+
const cfg = hyperliquidBridgeConfig(args.chainId);
|
|
1661
|
+
if (!cfg) throw new Error("chainId must be Arbitrum One (42161) or Arbitrum Sepolia (421614)");
|
|
1662
|
+
const amountWei = parseUsdHumanTo6(args.usdHuman);
|
|
1663
|
+
const minWei = viem.parseUnits(String(HYPERLIQUID_BRIDGE_MIN_DEPOSIT_USDC), 6);
|
|
1664
|
+
if (amountWei < minWei) {
|
|
1665
|
+
throw new Error(`Bridge deposit must be at least ${HYPERLIQUID_BRIDGE_MIN_DEPOSIT_USDC} USDC`);
|
|
1666
|
+
}
|
|
1667
|
+
const executor = viem.getAddress(args.executorAddress);
|
|
1668
|
+
const data = viem.encodeFunctionData({
|
|
1669
|
+
abi: erc20TransferAbi,
|
|
1670
|
+
functionName: "transfer",
|
|
1671
|
+
args: [cfg.bridge2, amountWei]
|
|
1672
|
+
});
|
|
1673
|
+
return buildEvmMultisignBatch({
|
|
1674
|
+
context: {
|
|
1675
|
+
keyGen: args.keyGen,
|
|
1676
|
+
chainCategory: "evm",
|
|
1677
|
+
chainId: args.chainId,
|
|
1678
|
+
rpcUrl: args.rpcUrl,
|
|
1679
|
+
chainDetail: args.chainDetail,
|
|
1680
|
+
useCustomGas: args.useCustomGas,
|
|
1681
|
+
customGasChainDetails: args.customGasChainDetails ?? null,
|
|
1682
|
+
executorAddress: executor,
|
|
1683
|
+
purposeText: args.purposeText
|
|
1684
|
+
},
|
|
1685
|
+
steps: [{ to: cfg.usdc, data, value: 0n, fallbackGas: HYPERLIQUID_BRIDGE_ERC20_TRANSFER_FALLBACK_GAS }],
|
|
1686
|
+
destinationAddress: cfg.usdc,
|
|
1687
|
+
buildBatchMeta: () => ({
|
|
1688
|
+
kind: "Hyperliquid",
|
|
1689
|
+
action: "bridgeDeposit",
|
|
1690
|
+
arbitrumChainId: args.chainId,
|
|
1691
|
+
usdc: cfg.usdc,
|
|
1692
|
+
bridge2: cfg.bridge2,
|
|
1693
|
+
usdHuman: args.usdHuman,
|
|
1694
|
+
evm: { type: "hyperliquid_bridge_deposit", version: 1, chainId: String(args.chainId) }
|
|
1695
|
+
})
|
|
1696
|
+
});
|
|
1697
|
+
}
|
|
1698
|
+
async function buildHyperliquidBridgeWithdrawMultisign(args) {
|
|
1699
|
+
if (!isHyperliquidChainSupported(args.chainId)) {
|
|
1700
|
+
throw new Error("chainId must be 999 or 998");
|
|
1701
|
+
}
|
|
1702
|
+
const isTestnet = args.chainId === 998;
|
|
1703
|
+
const destination = viem.getAddress(args.destination ?? args.executorAddress);
|
|
1704
|
+
const { action, nonce } = buildHyperliquidWithdraw3Action({
|
|
1705
|
+
destination,
|
|
1706
|
+
amountHuman: args.usdHuman,
|
|
1707
|
+
isTestnet
|
|
1708
|
+
});
|
|
1709
|
+
const typed = buildHyperliquidWithdraw3TypedData({ action });
|
|
1710
|
+
return buildEip712MultisignBody({
|
|
1711
|
+
keyGen: args.keyGen,
|
|
1712
|
+
purposeText: args.purposeText,
|
|
1713
|
+
destinationChainID: String(args.chainId),
|
|
1714
|
+
destinationAddress: ZERO_ADDRESS2,
|
|
1715
|
+
typedData: typed,
|
|
1716
|
+
delivery: {
|
|
1717
|
+
kind: "hyperliquid_exchange",
|
|
1718
|
+
chainId: args.chainId,
|
|
1719
|
+
isTestnet,
|
|
1720
|
+
action,
|
|
1721
|
+
nonce
|
|
1722
|
+
},
|
|
1723
|
+
audit: {
|
|
1724
|
+
protocol: "hyperliquid",
|
|
1725
|
+
action: "bridgeWithdraw",
|
|
1726
|
+
usdHuman: args.usdHuman,
|
|
1727
|
+
destination,
|
|
1728
|
+
nonce,
|
|
1729
|
+
hyperliquidChain: action.hyperliquidChain
|
|
1730
|
+
}
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1329
1733
|
|
|
1330
1734
|
// src/protocols/evm/hyperliquid/index.ts
|
|
1331
1735
|
var HYPERLIQUID_PROTOCOL_ID = "hyperliquid";
|
|
@@ -1446,6 +1850,40 @@ var hyperliquidProtocolModule = {
|
|
|
1446
1850
|
validator: { type: "string", required: true, description: "Validator address" }
|
|
1447
1851
|
}
|
|
1448
1852
|
},
|
|
1853
|
+
{
|
|
1854
|
+
id: "hyperliquid.bridgeDeposit",
|
|
1855
|
+
protocolId: HYPERLIQUID_PROTOCOL_ID,
|
|
1856
|
+
chainCategory: "evm",
|
|
1857
|
+
description: "Deposit USDC from Arbitrum to Hyperliquid via Bridge2 (ERC20 transfer)",
|
|
1858
|
+
commonParams: ["keyGen", "purposeText", "useCustomGas"],
|
|
1859
|
+
params: {
|
|
1860
|
+
usdHuman: { type: "string", required: true, description: "USDC amount (min 5)" }
|
|
1861
|
+
}
|
|
1862
|
+
},
|
|
1863
|
+
{
|
|
1864
|
+
id: "hyperliquid.bridgeWithdraw",
|
|
1865
|
+
protocolId: HYPERLIQUID_PROTOCOL_ID,
|
|
1866
|
+
chainCategory: "evm",
|
|
1867
|
+
description: "Withdraw USDC from Hyperliquid to Arbitrum via withdraw3 (EIP-712 /exchange)",
|
|
1868
|
+
commonParams: ["keyGen", "purposeText"],
|
|
1869
|
+
params: {
|
|
1870
|
+
usdHuman: { type: "string", required: true, description: "USDC amount" },
|
|
1871
|
+
destination: { type: "string", required: false, description: "Arbitrum recipient (defaults to executor)" }
|
|
1872
|
+
}
|
|
1873
|
+
},
|
|
1874
|
+
{
|
|
1875
|
+
id: "hyperliquid.updateLeverage",
|
|
1876
|
+
protocolId: HYPERLIQUID_PROTOCOL_ID,
|
|
1877
|
+
chainCategory: "evm",
|
|
1878
|
+
description: "Update per-market cross/isolated leverage via Hyperliquid L1 /exchange (EIP-712)",
|
|
1879
|
+
commonParams: ["keyGen", "purposeText"],
|
|
1880
|
+
params: {
|
|
1881
|
+
coin: { type: "string", required: true, description: "Market coin e.g. BTC" },
|
|
1882
|
+
leverage: { type: "number", required: true, description: "New leverage (1..market max)" },
|
|
1883
|
+
isCross: { type: "boolean", required: false, description: "true for cross (default), false for isolated" },
|
|
1884
|
+
marketKind: { type: "string", required: false, description: "perp (default) or spot" }
|
|
1885
|
+
}
|
|
1886
|
+
},
|
|
1449
1887
|
{
|
|
1450
1888
|
id: "hyperliquid.undelegate",
|
|
1451
1889
|
protocolId: HYPERLIQUID_PROTOCOL_ID,
|
|
@@ -1461,12 +1899,18 @@ var hyperliquidProtocolModule = {
|
|
|
1461
1899
|
};
|
|
1462
1900
|
registerProtocolModule(hyperliquidProtocolModule);
|
|
1463
1901
|
|
|
1902
|
+
exports.HYPERLIQUID_BRIDGE_ARBITRUM_MAINNET_CHAIN_ID = HYPERLIQUID_BRIDGE_ARBITRUM_MAINNET_CHAIN_ID;
|
|
1903
|
+
exports.HYPERLIQUID_BRIDGE_ARBITRUM_TESTNET_CHAIN_ID = HYPERLIQUID_BRIDGE_ARBITRUM_TESTNET_CHAIN_ID;
|
|
1904
|
+
exports.HYPERLIQUID_BRIDGE_ERC20_TRANSFER_FALLBACK_GAS = HYPERLIQUID_BRIDGE_ERC20_TRANSFER_FALLBACK_GAS;
|
|
1905
|
+
exports.HYPERLIQUID_BRIDGE_MIN_DEPOSIT_USDC = HYPERLIQUID_BRIDGE_MIN_DEPOSIT_USDC;
|
|
1464
1906
|
exports.HYPERLIQUID_CORE_WRITER_ADDRESS = HYPERLIQUID_CORE_WRITER_ADDRESS;
|
|
1465
1907
|
exports.HYPERLIQUID_CORE_WRITER_GAS_FALLBACK = HYPERLIQUID_CORE_WRITER_GAS_FALLBACK;
|
|
1466
1908
|
exports.HYPERLIQUID_DEFAULT_CANDLE_LIMIT = HYPERLIQUID_DEFAULT_CANDLE_LIMIT;
|
|
1467
1909
|
exports.HYPERLIQUID_DEFAULT_LOOKBACK_DAYS = HYPERLIQUID_DEFAULT_LOOKBACK_DAYS;
|
|
1468
1910
|
exports.HYPERLIQUID_DEFAULT_OHLCV_INTERVAL = HYPERLIQUID_DEFAULT_OHLCV_INTERVAL;
|
|
1469
1911
|
exports.HYPERLIQUID_HLP_VAULT_ADDRESS = HYPERLIQUID_HLP_VAULT_ADDRESS;
|
|
1912
|
+
exports.HYPERLIQUID_HYPEREVM_USDC_MAINNET = HYPERLIQUID_HYPEREVM_USDC_MAINNET;
|
|
1913
|
+
exports.HYPERLIQUID_HYPEREVM_USDC_TESTNET = HYPERLIQUID_HYPEREVM_USDC_TESTNET;
|
|
1470
1914
|
exports.HYPERLIQUID_INTERVAL_MS = HYPERLIQUID_INTERVAL_MS;
|
|
1471
1915
|
exports.HYPERLIQUID_MAX_CANDLE_LIMIT = HYPERLIQUID_MAX_CANDLE_LIMIT;
|
|
1472
1916
|
exports.HYPERLIQUID_MAX_LOOKBACK_DAYS = HYPERLIQUID_MAX_LOOKBACK_DAYS;
|
|
@@ -1475,6 +1919,9 @@ exports.HYPERLIQUID_PROTOCOL_ID = HYPERLIQUID_PROTOCOL_ID;
|
|
|
1475
1919
|
exports.HYPERLIQUID_SPOT_ASSET_OFFSET = HYPERLIQUID_SPOT_ASSET_OFFSET;
|
|
1476
1920
|
exports.HYPERLIQUID_SUPPORTED_CHAIN_IDS = HYPERLIQUID_SUPPORTED_CHAIN_IDS;
|
|
1477
1921
|
exports.HYPERLIQUID_TIF = HYPERLIQUID_TIF;
|
|
1922
|
+
exports.HYPERLIQUID_USER_SIGNED_DOMAIN = HYPERLIQUID_USER_SIGNED_DOMAIN;
|
|
1923
|
+
exports.HYPERLIQUID_USER_SIGNED_SIGNATURE_CHAIN_ID = HYPERLIQUID_USER_SIGNED_SIGNATURE_CHAIN_ID;
|
|
1924
|
+
exports.HYPERLIQUID_WITHDRAW_SIGN_TYPES = HYPERLIQUID_WITHDRAW_SIGN_TYPES;
|
|
1478
1925
|
exports.buildCoreWriterCancelByCloidCalldata = buildCoreWriterCancelByCloidCalldata;
|
|
1479
1926
|
exports.buildCoreWriterCancelByOidCalldata = buildCoreWriterCancelByOidCalldata;
|
|
1480
1927
|
exports.buildCoreWriterLimitOrderCalldata = buildCoreWriterLimitOrderCalldata;
|
|
@@ -1483,6 +1930,7 @@ exports.buildCoreWriterStakingWithdrawCalldata = buildCoreWriterStakingWithdrawC
|
|
|
1483
1930
|
exports.buildCoreWriterTokenDelegateCalldata = buildCoreWriterTokenDelegateCalldata;
|
|
1484
1931
|
exports.buildCoreWriterUsdClassTransferCalldata = buildCoreWriterUsdClassTransferCalldata;
|
|
1485
1932
|
exports.buildCoreWriterVaultTransferCalldata = buildCoreWriterVaultTransferCalldata;
|
|
1933
|
+
exports.buildEvmMultisignBodyHyperliquidBridgeDepositBatch = buildEvmMultisignBodyHyperliquidBridgeDepositBatch;
|
|
1486
1934
|
exports.buildEvmMultisignBodyHyperliquidCancelBatch = buildEvmMultisignBodyHyperliquidCancelBatch;
|
|
1487
1935
|
exports.buildEvmMultisignBodyHyperliquidCloseBatch = buildEvmMultisignBodyHyperliquidCloseBatch;
|
|
1488
1936
|
exports.buildEvmMultisignBodyHyperliquidDelegateBatch = buildEvmMultisignBodyHyperliquidDelegateBatch;
|
|
@@ -1494,8 +1942,17 @@ exports.buildEvmMultisignBodyHyperliquidUndelegateBatch = buildEvmMultisignBodyH
|
|
|
1494
1942
|
exports.buildEvmMultisignBodyHyperliquidUsdClassTransferBatch = buildEvmMultisignBodyHyperliquidUsdClassTransferBatch;
|
|
1495
1943
|
exports.buildEvmMultisignBodyHyperliquidVaultDepositBatch = buildEvmMultisignBodyHyperliquidVaultDepositBatch;
|
|
1496
1944
|
exports.buildEvmMultisignBodyHyperliquidVaultWithdrawBatch = buildEvmMultisignBodyHyperliquidVaultWithdrawBatch;
|
|
1945
|
+
exports.buildHyperliquidAgentTypedData = buildHyperliquidAgentTypedData;
|
|
1946
|
+
exports.buildHyperliquidBridgeWithdrawMultisign = buildHyperliquidBridgeWithdrawMultisign;
|
|
1947
|
+
exports.buildHyperliquidUpdateLeverageAction = buildHyperliquidUpdateLeverageAction;
|
|
1948
|
+
exports.buildHyperliquidUpdateLeverageMultisign = buildHyperliquidUpdateLeverageMultisign;
|
|
1949
|
+
exports.buildHyperliquidWithdraw3Action = buildHyperliquidWithdraw3Action;
|
|
1950
|
+
exports.buildHyperliquidWithdraw3TypedData = buildHyperliquidWithdraw3TypedData;
|
|
1497
1951
|
exports.coreWriterStep = coreWriterStep;
|
|
1952
|
+
exports.createHyperliquidL1ActionHash = createHyperliquidL1ActionHash;
|
|
1498
1953
|
exports.hyperliquidApiBaseUrl = hyperliquidApiBaseUrl;
|
|
1954
|
+
exports.hyperliquidBridgeArbitrumChainId = hyperliquidBridgeArbitrumChainId;
|
|
1955
|
+
exports.hyperliquidBridgeConfig = hyperliquidBridgeConfig;
|
|
1499
1956
|
exports.hyperliquidCollectAllPerpMarkets = hyperliquidCollectAllPerpMarkets;
|
|
1500
1957
|
exports.hyperliquidEncodePx8 = hyperliquidEncodePx8;
|
|
1501
1958
|
exports.hyperliquidEncodeUsd6 = hyperliquidEncodeUsd6;
|
|
@@ -1545,6 +2002,9 @@ exports.hyperliquidResolveTif = hyperliquidResolveTif;
|
|
|
1545
2002
|
exports.hyperliquidSearchMarkets = hyperliquidSearchMarkets;
|
|
1546
2003
|
exports.hyperliquidSearchMarketsSummary = hyperliquidSearchMarketsSummary;
|
|
1547
2004
|
exports.hyperliquidVaultStatsUrl = hyperliquidVaultStatsUrl;
|
|
2005
|
+
exports.isHyperliquidBridgeArbitrumChainSupported = isHyperliquidBridgeArbitrumChainSupported;
|
|
2006
|
+
exports.isHyperliquidBridgeArbitrumUsdcRow = isHyperliquidBridgeArbitrumUsdcRow;
|
|
1548
2007
|
exports.isHyperliquidChainSupported = isHyperliquidChainSupported;
|
|
2008
|
+
exports.isHyperliquidHyperEvmUsdcRow = isHyperliquidHyperEvmUsdcRow;
|
|
1549
2009
|
//# sourceMappingURL=index.cjs.map
|
|
1550
2010
|
//# sourceMappingURL=index.cjs.map
|