@continuumdao/ctm-mpc-defi 0.2.22 → 0.2.24
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 +142 -13
- package/dist/agent/catalog.cjs.map +1 -1
- package/dist/agent/catalog.d.ts +282 -43
- package/dist/agent/catalog.js +138 -14
- package/dist/agent/catalog.js.map +1 -1
- package/dist/agent/skills/gmx/SKILL.md +30 -0
- package/dist/agent/skills/hyperliquid/SKILL.md +32 -0
- package/dist/agent/skills/uniswap-v4/SKILL.md +26 -1
- package/dist/core/index.d.ts +4 -36
- package/dist/eip712Multisign-xhXpUYp3.d.ts +36 -0
- package/dist/index.cjs +344 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +344 -12
- package/dist/index.js.map +1 -1
- package/dist/protocols/evm/gmx/index.cjs +39 -0
- package/dist/protocols/evm/gmx/index.cjs.map +1 -1
- package/dist/protocols/evm/gmx/index.d.ts +21 -1
- package/dist/protocols/evm/gmx/index.js +38 -1
- package/dist/protocols/evm/gmx/index.js.map +1 -1
- package/dist/protocols/evm/hyperliquid/index.cjs +478 -208
- package/dist/protocols/evm/hyperliquid/index.cjs.map +1 -1
- package/dist/protocols/evm/hyperliquid/index.d.ts +166 -51
- package/dist/protocols/evm/hyperliquid/index.js +467 -210
- package/dist/protocols/evm/hyperliquid/index.js.map +1 -1
- package/dist/protocols/evm/permit2/index.cjs.map +1 -1
- package/dist/protocols/evm/permit2/index.js.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.cjs +734 -15
- package/dist/protocols/evm/uniswap-v4/index.cjs.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.d.ts +189 -17
- package/dist/protocols/evm/uniswap-v4/index.js +698 -16
- package/dist/protocols/evm/uniswap-v4/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { C as ChainCategory, a as ChainSupportContext, E as EvmTokenKind, K as KeyGenSubset, b as KeyGenSubsetForPermit, M as MultisignBuildResult, c as MultisignCommonArgs, N as NearTokenKind, P as ParamDoc, d as ProtocolActionDescriptor, e as ProtocolModule, S as SolanaTokenKind, T as TokenRef } from './types-PZrvtjv8.js';
|
|
2
2
|
export { getClientIdFromKeyGenResult as firstClientIdFromKeyGen } from '@continuumdao/continuum-node-sdk';
|
|
3
|
-
export {
|
|
3
|
+
export { DEFAULT_DEFI_MULTISIGN_EXPIRY_SECONDS, DEFI_PROTOCOLS_WITH_30MIN_EXPIRY, defiMultisignExpiryUnixSeconds, getAaveGraphqlProxyUrl, getCoingeckoProxyUrl, getEulerGraphqlProxyUrl, getMapleGraphqlProxyUrl, getMorphoGraphqlProxyUrl, mergePurposeText, postJsonViaOptionalProxy, setAaveGraphqlProxyUrl, setCoingeckoProxyUrl, setEulerGraphqlProxyUrl, setMapleGraphqlProxyUrl, setMorphoGraphqlProxyUrl } from './core/index.js';
|
|
4
4
|
export { C as ChainCategoryBuildInput, a as ChainCategoryModule, M as MultisignLeg, c as coreChainCategoryModule, f as finalizeMultisign } from './envelope-C_bfuKab.js';
|
|
5
5
|
export { g as getActionsByChainCategory, a as getProtocolModule, b as getProtocolModules, r as registerProtocolModule } from './registry-DxDSPQ-p.js';
|
|
6
|
+
export { B as BuildEip712MultisignBodyArgs, E as EIP712_SIGN_REQUEST_KIND, a as Eip712MultisignDelivery, b as Eip712TypedDataField, c as Eip712TypedDataPayload, d as buildEip712MultisignBody } from './eip712Multisign-xhXpUYp3.js';
|
|
6
7
|
export { E as EvmChainDetail, a as EvmProtocolContext, b as EvmTxStep, i as isEvmNativeToken, m as matchEvmTokenKind } from './types-RZWOTm8c.js';
|
|
7
8
|
export { COINGECKO_PLATFORM_BY_CHAIN_ID, ConditionalApproveStep, EvmBatchMetaBuilder, EvmBuildBatchArgs, approveStepsToEvmTxSteps, buildConditionalErc20ApproveSteps, buildEvmMultisignBatch, coingeckoPlatformForChainId, evmChainCategoryModule, normalizeCurveRouterAmountString, normalizeHumanDecimalAmount, parseEvmChainIdToNumber, publicClientForRpc, resolveErc20Decimals, routerSwapGasLimitFromEstimate } from './chains/evm/index.js';
|
|
8
9
|
export { SOLANA_CHAIN_CATEGORY, solanaChainCategoryModule } from './chains/solana/index.js';
|
package/dist/index.js
CHANGED
|
@@ -615,8 +615,18 @@ var UNIVERSAL_ROUTER_SPENDER = {
|
|
|
615
615
|
143: "0x0d97dc33264bfc1c226207428a79b26757fb9dc3",
|
|
616
616
|
59144: "0x661e93cca42afacb172121ef892830ca3b70f08d",
|
|
617
617
|
4217: "0x1febb76be10aaf3a1402f04e8e835f2c382f7914",
|
|
618
|
-
196: "0x5507749f2c558bb3e162c6e90c314c092e7372ff"
|
|
618
|
+
196: "0x5507749f2c558bb3e162c6e90c314c092e7372ff",
|
|
619
|
+
/** Robinhood Chain mainnet — Universal Router v2.1.1 (Trade API / interface) */
|
|
620
|
+
4663: "0x8876789976decbfcbbbe364623c63652db8c0904"
|
|
619
621
|
};
|
|
622
|
+
var UNIVERSAL_ROUTER_VERSION_BY_CHAIN = {
|
|
623
|
+
/** Robinhood has UR 2.1.1 only in the supported-chains table (no 2.0 Trade API column). */
|
|
624
|
+
4663: "2.1.1"
|
|
625
|
+
};
|
|
626
|
+
function getUniswapUniversalRouterVersion(chainId) {
|
|
627
|
+
const v = UNIVERSAL_ROUTER_VERSION_BY_CHAIN[chainId];
|
|
628
|
+
return typeof v === "string" && v.trim() ? v.trim() : UNISWAP_UNIVERSAL_ROUTER_VERSION_DEFAULT;
|
|
629
|
+
}
|
|
620
630
|
function isUniswapV4ChainSupported(chainId) {
|
|
621
631
|
if (chainId == null) return false;
|
|
622
632
|
const n = parseEvmChainIdToNumber(chainId);
|
|
@@ -651,7 +661,9 @@ var POSITION_MANAGER_BY_CHAIN = {
|
|
|
651
661
|
11155111: "0x4B2C77d209D3405F41a037Ec6c77F7F5b8e2ca80",
|
|
652
662
|
130: "0x0d97dc33264bfc1c226207428a79b26757fb9dc3",
|
|
653
663
|
1868: "0x0e2850543f69f678257266e0907ff9a58b3f13de",
|
|
654
|
-
59144: "0x661e93cca42afacb172121ef892830ca3b70f08d"
|
|
664
|
+
59144: "0x661e93cca42afacb172121ef892830ca3b70f08d",
|
|
665
|
+
/** Robinhood Chain mainnet */
|
|
666
|
+
4663: "0x58daec3116aae6D93017bAAea7749052E8a04fA7"
|
|
655
667
|
};
|
|
656
668
|
function getUniswapV4PositionManagerOrThrow(chainId) {
|
|
657
669
|
const raw = POSITION_MANAGER_BY_CHAIN[chainId];
|
|
@@ -698,8 +710,8 @@ function parseUniswapChainId(value) {
|
|
|
698
710
|
function trimAddr(a) {
|
|
699
711
|
return a.trim();
|
|
700
712
|
}
|
|
701
|
-
function
|
|
702
|
-
const t = (
|
|
713
|
+
function isUniswapNativeTokenAddress(token) {
|
|
714
|
+
const t = (token ?? "").toString().trim();
|
|
703
715
|
if (!t) return false;
|
|
704
716
|
try {
|
|
705
717
|
return getAddress(t) === zeroAddress;
|
|
@@ -714,7 +726,16 @@ function isUniswapFullQuoteResponseNativeIn(stored) {
|
|
|
714
726
|
const input = q.input;
|
|
715
727
|
if (!input) return false;
|
|
716
728
|
const raw = (input.address ?? input.token ?? "").toString().trim();
|
|
717
|
-
return
|
|
729
|
+
return isUniswapNativeTokenAddress(raw);
|
|
730
|
+
}
|
|
731
|
+
function isUniswapFullQuoteResponseNativeOut(stored) {
|
|
732
|
+
if (!stored) return false;
|
|
733
|
+
const q = stored.quote;
|
|
734
|
+
if (!q || typeof q !== "object" || Array.isArray(q)) return false;
|
|
735
|
+
const output = q.output;
|
|
736
|
+
if (!output) return false;
|
|
737
|
+
const raw = (output.address ?? output.token ?? "").toString().trim();
|
|
738
|
+
return isUniswapNativeTokenAddress(raw);
|
|
718
739
|
}
|
|
719
740
|
async function fetchEthereumAddressForKeyGen(managementNodeUrl, keyGenId, readAuth = { bearerOnGet: true, jwt: null }, init) {
|
|
720
741
|
const base = managementNodeUrl.trim().replace(/\/$/, "");
|
|
@@ -776,6 +797,31 @@ function buildUniswapQuoteRequestBody(args) {
|
|
|
776
797
|
}
|
|
777
798
|
return body;
|
|
778
799
|
}
|
|
800
|
+
function resolveChainIdFromStoredUniswapQuote(stored) {
|
|
801
|
+
if (!stored) return 0;
|
|
802
|
+
const top = stored;
|
|
803
|
+
for (const key of ["tokenInChainId", "chainId"]) {
|
|
804
|
+
const raw = top[key];
|
|
805
|
+
if (raw != null && String(raw).trim() !== "") {
|
|
806
|
+
try {
|
|
807
|
+
return parseUniswapChainId(raw);
|
|
808
|
+
} catch {
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
const q = top.quote;
|
|
813
|
+
if (q && typeof q === "object" && !Array.isArray(q)) {
|
|
814
|
+
const input = q.input;
|
|
815
|
+
const chain = input?.chainId;
|
|
816
|
+
if (chain != null && String(chain).trim() !== "") {
|
|
817
|
+
try {
|
|
818
|
+
return parseUniswapChainId(chain);
|
|
819
|
+
} catch {
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
return 0;
|
|
824
|
+
}
|
|
779
825
|
function errorMessageFromUniswapJsonBody(value) {
|
|
780
826
|
if (value == null) return null;
|
|
781
827
|
if (typeof value === "string") {
|
|
@@ -888,16 +934,18 @@ async function uniswapTradeQuote(args) {
|
|
|
888
934
|
}
|
|
889
935
|
const base = args.baseUrl && args.baseUrl.trim() ? args.baseUrl.trim().replace(/\/$/, "") : DEFAULT_TRADE_BASE;
|
|
890
936
|
const quoteUrl = `${base}/quote`;
|
|
891
|
-
const
|
|
937
|
+
const chainIdForRouter = parseUniswapChainId(resolveInputChainId(args));
|
|
938
|
+
const urv = args.universalRouterVersion && args.universalRouterVersion.trim() || getUniswapUniversalRouterVersion(chainIdForRouter);
|
|
892
939
|
const body = buildUniswapQuoteRequestBody({ ...args, swapper });
|
|
893
|
-
const nativeIn =
|
|
940
|
+
const nativeIn = isUniswapNativeTokenAddress(args.tokenIn);
|
|
941
|
+
const nativeOut = isUniswapNativeTokenAddress(args.tokenOut);
|
|
894
942
|
const headers = {
|
|
895
943
|
...UNISWAP_QUOTE_HEADERS_BASE,
|
|
896
944
|
"x-api-key": apiKey,
|
|
897
945
|
"x-universal-router-version": urv,
|
|
898
946
|
"x-permit2-disabled": args.permit2Disabled === true ? "true" : "false",
|
|
899
|
-
/** Native (0x0)
|
|
900
|
-
"x-erc20eth-enabled": nativeIn ? "true" : "false"
|
|
947
|
+
/** Native (0x0) in or out: enables ERC20↔ETH routes (incl. UniswapX on Robinhood). */
|
|
948
|
+
"x-erc20eth-enabled": nativeIn || nativeOut ? "true" : "false"
|
|
901
949
|
};
|
|
902
950
|
const fetchFn = args.fetchImpl ?? globalThis.fetch;
|
|
903
951
|
const res = await fetchFn(quoteUrl, {
|
|
@@ -908,7 +956,11 @@ async function uniswapTradeQuote(args) {
|
|
|
908
956
|
});
|
|
909
957
|
const text = await res.text();
|
|
910
958
|
if (!res.ok) {
|
|
911
|
-
|
|
959
|
+
let msg = messageFromUniswapHttpResponseBody(text, res.status, res.statusText);
|
|
960
|
+
if (res.status === 404 && chainIdForRouter === 4663) {
|
|
961
|
+
msg += " On Robinhood Chain, confirm USDG is 0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168, use Native ETH or WETH (0x0Bd7\u2026) as output, and try at least ~$300 notional (UniswapX minimum).";
|
|
962
|
+
}
|
|
963
|
+
throw new Error(msg);
|
|
912
964
|
}
|
|
913
965
|
const forParse = text.replace(/^\uFEFF/, "");
|
|
914
966
|
try {
|
|
@@ -1015,16 +1067,17 @@ async function uniswapCreateSwap(args) {
|
|
|
1015
1067
|
quote: classic,
|
|
1016
1068
|
deadline
|
|
1017
1069
|
};
|
|
1018
|
-
const urv = (args.universalRouterVersion ??
|
|
1070
|
+
const urv = (args.universalRouterVersion ?? "").trim() || getUniswapUniversalRouterVersion(resolveChainIdFromStoredUniswapQuote(args.fullQuoteFromPermit));
|
|
1019
1071
|
const fn = args.fetchImpl ?? globalThis.fetch;
|
|
1020
1072
|
const nativeIn = isUniswapFullQuoteResponseNativeIn(args.fullQuoteFromPermit);
|
|
1073
|
+
const nativeOut = isUniswapFullQuoteResponseNativeOut(args.fullQuoteFromPermit);
|
|
1021
1074
|
const res = await fn(url, {
|
|
1022
1075
|
method: "POST",
|
|
1023
1076
|
headers: {
|
|
1024
1077
|
"Content-Type": "application/json",
|
|
1025
1078
|
"x-api-key": args.uniswapApiKey.trim(),
|
|
1026
1079
|
"x-universal-router-version": urv,
|
|
1027
|
-
"x-erc20eth-enabled": nativeIn ? "true" : "false",
|
|
1080
|
+
"x-erc20eth-enabled": nativeIn || nativeOut ? "true" : "false",
|
|
1028
1081
|
"x-permit2-disabled": "true"
|
|
1029
1082
|
},
|
|
1030
1083
|
body: JSON.stringify(body)
|
|
@@ -2224,6 +2277,270 @@ async function swapExactInput(args) {
|
|
|
2224
2277
|
return swapFromQuote({ ...args, swap });
|
|
2225
2278
|
}
|
|
2226
2279
|
|
|
2280
|
+
// src/protocols/evm/uniswap-v4/limitOrder.ts
|
|
2281
|
+
function trimAddr3(a) {
|
|
2282
|
+
return a.trim();
|
|
2283
|
+
}
|
|
2284
|
+
var UNISWAP_LIMIT_ORDER_CHAIN_ID = 1;
|
|
2285
|
+
var DEFAULT_UNISWAPX_ORDER_BASE = "https://api.uniswap.org/v2";
|
|
2286
|
+
var DEFAULT_LIMIT_ORDER_QUOTE_PATH = "/limit_order_quote";
|
|
2287
|
+
var UNISWAP_QUOTE_HEADERS_BASE2 = {
|
|
2288
|
+
"Content-Type": "application/json",
|
|
2289
|
+
"User-Agent": "ctm-mpc-defi uniswapLimitOrderQuote/1.0 (TS)"
|
|
2290
|
+
};
|
|
2291
|
+
function isUniswapLimitOrderChainSupported(chainId) {
|
|
2292
|
+
return parseUniswapChainId(chainId) === UNISWAP_LIMIT_ORDER_CHAIN_ID;
|
|
2293
|
+
}
|
|
2294
|
+
function assertUniswapLimitOrderChain(chainId) {
|
|
2295
|
+
if (!isUniswapLimitOrderChainSupported(chainId)) {
|
|
2296
|
+
throw new Error(
|
|
2297
|
+
`UniswapX limit orders are only supported on Ethereum mainnet (chainId ${UNISWAP_LIMIT_ORDER_CHAIN_ID}). Got ${chainId}. Use market swap on this chain or wait for UniswapX limit support.`
|
|
2298
|
+
);
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
function inferPrimaryTypeFromPermitTypes(types) {
|
|
2302
|
+
for (const key of Object.keys(types)) {
|
|
2303
|
+
if (key !== "EIP712Domain") {
|
|
2304
|
+
return key;
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
throw new Error("permitData.types missing primaryType (no non-EIP712Domain entry)");
|
|
2308
|
+
}
|
|
2309
|
+
function permitDataToEip712Payload(permitData) {
|
|
2310
|
+
const domain = permitData.domain;
|
|
2311
|
+
const types = permitData.types;
|
|
2312
|
+
const message = permitData.values ?? permitData.message;
|
|
2313
|
+
if (domain == null || typeof domain !== "object" || Array.isArray(domain)) {
|
|
2314
|
+
throw new Error("limit order quote: permitData.domain missing");
|
|
2315
|
+
}
|
|
2316
|
+
if (types == null || typeof types !== "object" || Array.isArray(types)) {
|
|
2317
|
+
throw new Error("limit order quote: permitData.types missing");
|
|
2318
|
+
}
|
|
2319
|
+
if (message == null || typeof message !== "object" || Array.isArray(message)) {
|
|
2320
|
+
throw new Error("limit order quote: permitData.values (message) missing");
|
|
2321
|
+
}
|
|
2322
|
+
const primaryType = typeof permitData.primaryType === "string" && permitData.primaryType.trim() ? permitData.primaryType.trim() : inferPrimaryTypeFromPermitTypes(
|
|
2323
|
+
types
|
|
2324
|
+
);
|
|
2325
|
+
return {
|
|
2326
|
+
domain,
|
|
2327
|
+
types,
|
|
2328
|
+
primaryType,
|
|
2329
|
+
message
|
|
2330
|
+
};
|
|
2331
|
+
}
|
|
2332
|
+
function extractPermitDataFromLimitQuote(quoteResponse) {
|
|
2333
|
+
const permitData = quoteResponse.permitData;
|
|
2334
|
+
if (permitData == null) return null;
|
|
2335
|
+
if (typeof permitData !== "object" || Array.isArray(permitData)) {
|
|
2336
|
+
throw new Error("limit order quote: permitData is not an object");
|
|
2337
|
+
}
|
|
2338
|
+
return permitData;
|
|
2339
|
+
}
|
|
2340
|
+
function buildLimitOrderQuoteRequestBody(args) {
|
|
2341
|
+
const base = buildUniswapQuoteRequestBody({
|
|
2342
|
+
type: args.type,
|
|
2343
|
+
amount: args.amount,
|
|
2344
|
+
tokenIn: args.tokenIn,
|
|
2345
|
+
tokenOut: args.tokenOut,
|
|
2346
|
+
chainId: args.chainId,
|
|
2347
|
+
tokenInChainId: args.tokenInChainId,
|
|
2348
|
+
tokenOutChainId: args.tokenOutChainId,
|
|
2349
|
+
swapper: args.swapper
|
|
2350
|
+
});
|
|
2351
|
+
assertUniswapLimitOrderChain(base.tokenInChainId);
|
|
2352
|
+
return {
|
|
2353
|
+
...base,
|
|
2354
|
+
limitPrice: String(args.limitPrice).trim(),
|
|
2355
|
+
orderDeadline: args.orderDeadline
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2358
|
+
async function uniswapLimitOrderQuote(args) {
|
|
2359
|
+
const apiKey = (args.uniswapApiKey || "").trim();
|
|
2360
|
+
if (!apiKey) {
|
|
2361
|
+
throw new Error("uniswapApiKey (x-api-key) is required");
|
|
2362
|
+
}
|
|
2363
|
+
let swapper;
|
|
2364
|
+
if ((args.swapper || "").trim()) {
|
|
2365
|
+
swapper = trimAddr3(args.swapper);
|
|
2366
|
+
} else {
|
|
2367
|
+
const keyGen = (args.keyGen || "").trim();
|
|
2368
|
+
if (!keyGen) {
|
|
2369
|
+
throw new Error("keyGen is required when swapper is not provided");
|
|
2370
|
+
}
|
|
2371
|
+
const mpc = (args.managementNodeUrl || "").trim();
|
|
2372
|
+
if (!mpc) {
|
|
2373
|
+
throw new Error("managementNodeUrl is required when swapper is not provided (to resolve keyGen)");
|
|
2374
|
+
}
|
|
2375
|
+
swapper = await fetchEthereumAddressForKeyGen(
|
|
2376
|
+
mpc,
|
|
2377
|
+
keyGen,
|
|
2378
|
+
args.nodeReadAuth ?? { bearerOnGet: true, jwt: null }
|
|
2379
|
+
);
|
|
2380
|
+
}
|
|
2381
|
+
const chainIdForGuard = parseUniswapChainId(resolveInputChainId(args));
|
|
2382
|
+
assertUniswapLimitOrderChain(chainIdForGuard);
|
|
2383
|
+
const base = args.baseUrl && args.baseUrl.trim() ? args.baseUrl.trim().replace(/\/$/, "") : "https://trade-api.gateway.uniswap.org/v1";
|
|
2384
|
+
const quoteUrl = `${base}${DEFAULT_LIMIT_ORDER_QUOTE_PATH}`;
|
|
2385
|
+
const body = buildLimitOrderQuoteRequestBody({ ...args, swapper });
|
|
2386
|
+
const headers = {
|
|
2387
|
+
...UNISWAP_QUOTE_HEADERS_BASE2,
|
|
2388
|
+
"x-api-key": apiKey
|
|
2389
|
+
};
|
|
2390
|
+
const fetchFn = args.fetchImpl ?? globalThis.fetch;
|
|
2391
|
+
const res = await fetchFn(quoteUrl, {
|
|
2392
|
+
method: "POST",
|
|
2393
|
+
headers,
|
|
2394
|
+
body: JSON.stringify(body),
|
|
2395
|
+
signal: args.signal
|
|
2396
|
+
});
|
|
2397
|
+
const text = await res.text();
|
|
2398
|
+
if (!res.ok) {
|
|
2399
|
+
throw new Error(messageFromUniswapHttpResponseBody(text, res.status, res.statusText));
|
|
2400
|
+
}
|
|
2401
|
+
const forParse = text.replace(/^\uFEFF/, "");
|
|
2402
|
+
try {
|
|
2403
|
+
return JSON.parse(forParse);
|
|
2404
|
+
} catch {
|
|
2405
|
+
throw new Error(
|
|
2406
|
+
`Limit order quote: ${messageFromUniswapHttpResponseBody(text, res.status, res.statusText)}`
|
|
2407
|
+
);
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
function buildUniswapXLimitOrderSubmitBody(args) {
|
|
2411
|
+
const quote = args.quoteResponse.quote;
|
|
2412
|
+
if (quote == null || typeof quote !== "object" || Array.isArray(quote)) {
|
|
2413
|
+
throw new Error("limit order submit: quoteResponse.quote missing");
|
|
2414
|
+
}
|
|
2415
|
+
const routing = typeof args.quoteResponse.routing === "string" && args.quoteResponse.routing.trim() ? args.quoteResponse.routing.trim() : "LIMIT_ORDER";
|
|
2416
|
+
const chainId = args.quoteResponse.chainId ?? quote.chainId ?? UNISWAP_LIMIT_ORDER_CHAIN_ID;
|
|
2417
|
+
const quoteId = typeof args.quoteResponse.quoteId === "string" ? args.quoteResponse.quoteId : void 0;
|
|
2418
|
+
const requestId = typeof args.quoteResponse.requestId === "string" ? args.quoteResponse.requestId : void 0;
|
|
2419
|
+
return {
|
|
2420
|
+
signature: args.signatureHex.startsWith("0x") ? args.signatureHex : `0x${args.signatureHex}`,
|
|
2421
|
+
quote,
|
|
2422
|
+
chainId: parseUniswapChainId(chainId),
|
|
2423
|
+
orderType: "Limit",
|
|
2424
|
+
routing,
|
|
2425
|
+
...quoteId ? { quoteId } : {},
|
|
2426
|
+
...requestId ? { requestId } : {}
|
|
2427
|
+
};
|
|
2428
|
+
}
|
|
2429
|
+
async function fetchUniswapXLimitOrders(args) {
|
|
2430
|
+
const chainId = args.chainId ?? UNISWAP_LIMIT_ORDER_CHAIN_ID;
|
|
2431
|
+
assertUniswapLimitOrderChain(chainId);
|
|
2432
|
+
const base = args.baseUrl && args.baseUrl.trim() ? args.baseUrl.trim().replace(/\/$/, "") : DEFAULT_UNISWAPX_ORDER_BASE;
|
|
2433
|
+
const params = new URLSearchParams({
|
|
2434
|
+
chainId: String(chainId),
|
|
2435
|
+
swapper: trimAddr3(args.swapper)
|
|
2436
|
+
});
|
|
2437
|
+
if (args.limit != null && args.limit > 0) {
|
|
2438
|
+
params.set("limit", String(Math.floor(args.limit)));
|
|
2439
|
+
}
|
|
2440
|
+
const url = `${base}/limit-orders?${params.toString()}`;
|
|
2441
|
+
const headers = {
|
|
2442
|
+
Accept: "application/json",
|
|
2443
|
+
"User-Agent": "ctm-mpc-defi uniswapLimitOrdersList/1.0 (TS)"
|
|
2444
|
+
};
|
|
2445
|
+
const apiKey = (args.uniswapApiKey || "").trim();
|
|
2446
|
+
if (apiKey) {
|
|
2447
|
+
headers["x-api-key"] = apiKey;
|
|
2448
|
+
}
|
|
2449
|
+
const fetchFn = args.fetchImpl ?? globalThis.fetch;
|
|
2450
|
+
const res = await fetchFn(url, { method: "GET", headers });
|
|
2451
|
+
const text = await res.text();
|
|
2452
|
+
if (!res.ok) {
|
|
2453
|
+
const parsed = (() => {
|
|
2454
|
+
try {
|
|
2455
|
+
return JSON.parse(text);
|
|
2456
|
+
} catch {
|
|
2457
|
+
return null;
|
|
2458
|
+
}
|
|
2459
|
+
})();
|
|
2460
|
+
const msg = errorMessageFromUniswapJsonBody(parsed) ?? (text.trim() || res.statusText);
|
|
2461
|
+
throw new Error(`List limit orders HTTP ${res.status}: ${msg}`);
|
|
2462
|
+
}
|
|
2463
|
+
return JSON.parse(text.replace(/^\uFEFF/, ""));
|
|
2464
|
+
}
|
|
2465
|
+
async function uniswapFetchLimitOrdersMcp(args) {
|
|
2466
|
+
let swapper;
|
|
2467
|
+
if ((args.swapper || "").trim()) {
|
|
2468
|
+
swapper = trimAddr3(args.swapper);
|
|
2469
|
+
} else {
|
|
2470
|
+
const keyGen = (args.keyGen || "").trim();
|
|
2471
|
+
if (!keyGen) {
|
|
2472
|
+
throw new Error("swapper or keyGen is required");
|
|
2473
|
+
}
|
|
2474
|
+
const mpc = (args.managementNodeUrl || "").trim();
|
|
2475
|
+
if (!mpc) {
|
|
2476
|
+
throw new Error("managementNodeUrl is required when swapper is not provided");
|
|
2477
|
+
}
|
|
2478
|
+
swapper = await fetchEthereumAddressForKeyGen(
|
|
2479
|
+
mpc,
|
|
2480
|
+
keyGen,
|
|
2481
|
+
args.nodeReadAuth ?? { bearerOnGet: true, jwt: null }
|
|
2482
|
+
);
|
|
2483
|
+
}
|
|
2484
|
+
return fetchUniswapXLimitOrders({
|
|
2485
|
+
swapper,
|
|
2486
|
+
chainId: args.chainId,
|
|
2487
|
+
uniswapApiKey: args.uniswapApiKey,
|
|
2488
|
+
limit: args.limit,
|
|
2489
|
+
baseUrl: args.baseUrl,
|
|
2490
|
+
fetchImpl: args.fetchImpl
|
|
2491
|
+
});
|
|
2492
|
+
}
|
|
2493
|
+
async function buildEvmMultisignBodyUniswapV4LimitOrderBatch(args) {
|
|
2494
|
+
assertUniswapLimitOrderChain(args.chainId);
|
|
2495
|
+
const permitRaw = extractPermitDataFromLimitQuote(args.fullLimitQuote);
|
|
2496
|
+
if (!permitRaw) {
|
|
2497
|
+
throw new Error(
|
|
2498
|
+
"Limit order quote has no permitData \u2014 cannot build EIP-712 sign request. Re-quote or confirm mainnet limit order support for this pair."
|
|
2499
|
+
);
|
|
2500
|
+
}
|
|
2501
|
+
const typedData = permitDataToEip712Payload(permitRaw);
|
|
2502
|
+
const submitTemplate = buildUniswapXLimitOrderSubmitBody({
|
|
2503
|
+
quoteResponse: args.fullLimitQuote,
|
|
2504
|
+
signatureHex: "0x"
|
|
2505
|
+
});
|
|
2506
|
+
return buildEip712MultisignBody({
|
|
2507
|
+
keyGen: args.keyGen,
|
|
2508
|
+
purposeText: args.purposeText,
|
|
2509
|
+
destinationChainID: String(UNISWAP_LIMIT_ORDER_CHAIN_ID),
|
|
2510
|
+
destinationAddress: PERMIT2_ADDRESS,
|
|
2511
|
+
typedData,
|
|
2512
|
+
delivery: {
|
|
2513
|
+
kind: "uniswapx_limit_order",
|
|
2514
|
+
chainId: UNISWAP_LIMIT_ORDER_CHAIN_ID,
|
|
2515
|
+
swapper: getAddress(args.swapper),
|
|
2516
|
+
submitBodyTemplate: submitTemplate,
|
|
2517
|
+
quoteResponse: args.fullLimitQuote,
|
|
2518
|
+
uniswapApiKey: args.uniswapApiKey,
|
|
2519
|
+
tradeApiBaseUrl: args.tradeApiBaseUrl ?? "https://trade-api.gateway.uniswap.org/v1"
|
|
2520
|
+
},
|
|
2521
|
+
audit: {
|
|
2522
|
+
protocol: "uniswap-v4",
|
|
2523
|
+
action: "limitOrder",
|
|
2524
|
+
routing: args.fullLimitQuote.routing ?? "LIMIT_ORDER",
|
|
2525
|
+
orderType: "Limit",
|
|
2526
|
+
primaryType: typedData.primaryType
|
|
2527
|
+
},
|
|
2528
|
+
expiryDate: args.expiryDate
|
|
2529
|
+
});
|
|
2530
|
+
}
|
|
2531
|
+
async function buildEvmMultisignBodyUniswapV4LimitOrderBatchFromMcp(args) {
|
|
2532
|
+
return buildEvmMultisignBodyUniswapV4LimitOrderBatch({
|
|
2533
|
+
keyGen: args.keyGen,
|
|
2534
|
+
chainId: args.chainId,
|
|
2535
|
+
purposeText: args.purposeText,
|
|
2536
|
+
fullLimitQuote: args.fullLimitQuote,
|
|
2537
|
+
swapper: getAddress(args.executorAddress),
|
|
2538
|
+
uniswapApiKey: args.uniswapApiKey,
|
|
2539
|
+
tradeApiBaseUrl: args.tradeApiBaseUrl,
|
|
2540
|
+
expiryDate: args.expiryDate
|
|
2541
|
+
});
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2227
2544
|
// src/protocols/evm/uniswap-v4/index.ts
|
|
2228
2545
|
var UNISWAP_V4_PROTOCOL_ID = "uniswap-v4";
|
|
2229
2546
|
var uniswapV4ProtocolModule = {
|
|
@@ -2270,6 +2587,17 @@ var uniswapV4ProtocolModule = {
|
|
|
2270
2587
|
type: { type: "EXACT_INPUT | EXACT_OUTPUT", required: true, description: "Trade type" }
|
|
2271
2588
|
}
|
|
2272
2589
|
},
|
|
2590
|
+
{
|
|
2591
|
+
id: "uniswap-v4.limit-order",
|
|
2592
|
+
protocolId: UNISWAP_V4_PROTOCOL_ID,
|
|
2593
|
+
chainCategory: "evm",
|
|
2594
|
+
description: "Place UniswapX limit order via EIP-712 sign + POST /order (Ethereum mainnet only)",
|
|
2595
|
+
commonParams: ["keyGen", "purposeText"],
|
|
2596
|
+
params: {
|
|
2597
|
+
fullLimitQuote: { type: "object", required: true, description: "Full limit order quote from Trade API" },
|
|
2598
|
+
uniswapApiKey: { type: "string", required: true, description: "Uniswap Trade API key" }
|
|
2599
|
+
}
|
|
2600
|
+
},
|
|
2273
2601
|
{
|
|
2274
2602
|
id: "uniswap-v4.mint-liquidity",
|
|
2275
2603
|
protocolId: UNISWAP_V4_PROTOCOL_ID,
|
|
@@ -2325,6 +2653,10 @@ var uniswapV4 = {
|
|
|
2325
2653
|
swapExactInput,
|
|
2326
2654
|
swapFromQuote,
|
|
2327
2655
|
buildSwapMultisignBody: buildEvmMultisignBodyUniswapV4SkipPermit2Batch,
|
|
2656
|
+
limitOrderQuote: uniswapLimitOrderQuote,
|
|
2657
|
+
buildLimitOrderMultisignBody: buildEvmMultisignBodyUniswapV4LimitOrderBatchFromMcp,
|
|
2658
|
+
fetchLimitOrders: fetchUniswapXLimitOrders,
|
|
2659
|
+
fetchLimitOrdersMcp: uniswapFetchLimitOrdersMcp,
|
|
2328
2660
|
quote: uniswapTradeQuote,
|
|
2329
2661
|
createLiquidityPosition: uniswapLpCreatePosition,
|
|
2330
2662
|
increaseLiquidityPosition: uniswapLpIncreasePosition,
|