@continuumdao/ctm-mpc-defi 0.2.22 → 0.2.25
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 +806 -18
- package/dist/agent/catalog.cjs.map +1 -1
- package/dist/agent/catalog.d.ts +2400 -43
- package/dist/agent/catalog.js +772 -19
- package/dist/agent/catalog.js.map +1 -1
- package/dist/agent/skills/arcus/SKILL.md +72 -0
- package/dist/agent/skills/gmx/SKILL.md +32 -0
- package/dist/agent/skills/hyperliquid/SKILL.md +44 -3
- package/dist/agent/skills/uniswap-v4/SKILL.md +31 -1
- package/dist/core/index.cjs +55 -0
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +15 -21
- package/dist/core/index.js +54 -1
- package/dist/core/index.js.map +1 -1
- package/dist/eip712Multisign-xhXpUYp3.d.ts +36 -0
- package/dist/index.cjs +399 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +398 -13
- package/dist/index.js.map +1 -1
- package/dist/protocols/evm/arcus/index.cjs +2061 -0
- package/dist/protocols/evm/arcus/index.cjs.map +1 -0
- package/dist/protocols/evm/arcus/index.d.ts +726 -0
- package/dist/protocols/evm/arcus/index.js +1964 -0
- package/dist/protocols/evm/arcus/index.js.map +1 -0
- 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 +6 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseAbi, parseAbiParameters, parseAbiItem, getAddress, zeroAddress, formatUnits, parseUnits, createPublicClient, http, defineChain, encodeFunctionData, keccak256, encodeAbiParameters, decodeEventLog, decodeFunctionData, parseGwei, serializeTransaction, erc20Abi } from 'viem';
|
|
1
|
+
import { parseAbi, parseAbiParameters, parseAbiItem, getAddress, zeroAddress, formatUnits, parseUnits, createPublicClient, http, defineChain, encodeFunctionData, keccak256, encodeAbiParameters, decodeEventLog, decodeFunctionData, parseGwei, serializeTransaction, erc20Abi, hashTypedData, stringToHex } from 'viem';
|
|
2
2
|
import { nodeFetchWithReadAuth, fetchChainFeeParams, gasLimitFromEstimateAndChainConfig, gweiToDecimalString, proposalTxParamsToFeeSnapshot, alignEip1559FeesWithLatestBase, getClientIdFromKeyGenResult } from '@continuumdao/continuum-node-sdk';
|
|
3
3
|
|
|
4
4
|
// src/core/registry.ts
|
|
@@ -66,8 +66,18 @@ var UNIVERSAL_ROUTER_SPENDER = {
|
|
|
66
66
|
143: "0x0d97dc33264bfc1c226207428a79b26757fb9dc3",
|
|
67
67
|
59144: "0x661e93cca42afacb172121ef892830ca3b70f08d",
|
|
68
68
|
4217: "0x1febb76be10aaf3a1402f04e8e835f2c382f7914",
|
|
69
|
-
196: "0x5507749f2c558bb3e162c6e90c314c092e7372ff"
|
|
69
|
+
196: "0x5507749f2c558bb3e162c6e90c314c092e7372ff",
|
|
70
|
+
/** Robinhood Chain mainnet — Universal Router v2.1.1 (Trade API / interface) */
|
|
71
|
+
4663: "0x8876789976decbfcbbbe364623c63652db8c0904"
|
|
70
72
|
};
|
|
73
|
+
var UNIVERSAL_ROUTER_VERSION_BY_CHAIN = {
|
|
74
|
+
/** Robinhood has UR 2.1.1 only in the supported-chains table (no 2.0 Trade API column). */
|
|
75
|
+
4663: "2.1.1"
|
|
76
|
+
};
|
|
77
|
+
function getUniswapUniversalRouterVersion(chainId) {
|
|
78
|
+
const v = UNIVERSAL_ROUTER_VERSION_BY_CHAIN[chainId];
|
|
79
|
+
return typeof v === "string" && v.trim() ? v.trim() : UNISWAP_UNIVERSAL_ROUTER_VERSION_DEFAULT;
|
|
80
|
+
}
|
|
71
81
|
function isUniswapV4ChainSupported(chainId) {
|
|
72
82
|
if (chainId == null) return false;
|
|
73
83
|
const n = parseEvmChainIdToNumber(chainId);
|
|
@@ -104,8 +114,12 @@ var POSITION_MANAGER_BY_CHAIN = {
|
|
|
104
114
|
11155111: "0x4B2C77d209D3405F41a037Ec6c77F7F5b8e2ca80",
|
|
105
115
|
130: "0x0d97dc33264bfc1c226207428a79b26757fb9dc3",
|
|
106
116
|
1868: "0x0e2850543f69f678257266e0907ff9a58b3f13de",
|
|
107
|
-
59144: "0x661e93cca42afacb172121ef892830ca3b70f08d"
|
|
117
|
+
59144: "0x661e93cca42afacb172121ef892830ca3b70f08d",
|
|
118
|
+
/** Robinhood Chain mainnet */
|
|
119
|
+
4663: "0x58daec3116aae6D93017bAAea7749052E8a04fA7"
|
|
108
120
|
};
|
|
121
|
+
var ROBINHOOD_CHAIN_ID = 4663;
|
|
122
|
+
var ROBINHOOD_WETH_ADDRESS = "0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73";
|
|
109
123
|
function getUniswapV4PositionManagerOrThrow(chainId) {
|
|
110
124
|
const raw = POSITION_MANAGER_BY_CHAIN[chainId];
|
|
111
125
|
if (!raw || !raw.startsWith("0x") || raw.length !== 42) {
|
|
@@ -158,8 +172,8 @@ function parseUniswapChainId(value) {
|
|
|
158
172
|
function trimAddr(a) {
|
|
159
173
|
return a.trim();
|
|
160
174
|
}
|
|
161
|
-
function
|
|
162
|
-
const t = (
|
|
175
|
+
function isUniswapNativeTokenAddress(token) {
|
|
176
|
+
const t = (token ?? "").toString().trim();
|
|
163
177
|
if (!t) return false;
|
|
164
178
|
try {
|
|
165
179
|
return getAddress(t) === zeroAddress;
|
|
@@ -167,6 +181,9 @@ function isUniswapTokenInAddressNative(tokenIn) {
|
|
|
167
181
|
return t.toLowerCase() === "0x0000000000000000000000000000000000000000";
|
|
168
182
|
}
|
|
169
183
|
}
|
|
184
|
+
function isUniswapTokenInAddressNative(tokenIn) {
|
|
185
|
+
return isUniswapNativeTokenAddress(tokenIn);
|
|
186
|
+
}
|
|
170
187
|
function isUniswapFullQuoteResponseNativeIn(stored) {
|
|
171
188
|
if (!stored) return false;
|
|
172
189
|
const q = stored.quote;
|
|
@@ -174,7 +191,16 @@ function isUniswapFullQuoteResponseNativeIn(stored) {
|
|
|
174
191
|
const input = q.input;
|
|
175
192
|
if (!input) return false;
|
|
176
193
|
const raw = (input.address ?? input.token ?? "").toString().trim();
|
|
177
|
-
return
|
|
194
|
+
return isUniswapNativeTokenAddress(raw);
|
|
195
|
+
}
|
|
196
|
+
function isUniswapFullQuoteResponseNativeOut(stored) {
|
|
197
|
+
if (!stored) return false;
|
|
198
|
+
const q = stored.quote;
|
|
199
|
+
if (!q || typeof q !== "object" || Array.isArray(q)) return false;
|
|
200
|
+
const output = q.output;
|
|
201
|
+
if (!output) return false;
|
|
202
|
+
const raw = (output.address ?? output.token ?? "").toString().trim();
|
|
203
|
+
return isUniswapNativeTokenAddress(raw);
|
|
178
204
|
}
|
|
179
205
|
async function fetchEthereumAddressForKeyGen(managementNodeUrl, keyGenId, readAuth = { bearerOnGet: true, jwt: null }, init) {
|
|
180
206
|
const base = managementNodeUrl.trim().replace(/\/$/, "");
|
|
@@ -236,6 +262,31 @@ function buildUniswapQuoteRequestBody(args) {
|
|
|
236
262
|
}
|
|
237
263
|
return body;
|
|
238
264
|
}
|
|
265
|
+
function resolveChainIdFromStoredUniswapQuote(stored) {
|
|
266
|
+
if (!stored) return 0;
|
|
267
|
+
const top = stored;
|
|
268
|
+
for (const key of ["tokenInChainId", "chainId"]) {
|
|
269
|
+
const raw = top[key];
|
|
270
|
+
if (raw != null && String(raw).trim() !== "") {
|
|
271
|
+
try {
|
|
272
|
+
return parseUniswapChainId(raw);
|
|
273
|
+
} catch {
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const q = top.quote;
|
|
278
|
+
if (q && typeof q === "object" && !Array.isArray(q)) {
|
|
279
|
+
const input = q.input;
|
|
280
|
+
const chain = input?.chainId;
|
|
281
|
+
if (chain != null && String(chain).trim() !== "") {
|
|
282
|
+
try {
|
|
283
|
+
return parseUniswapChainId(chain);
|
|
284
|
+
} catch {
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return 0;
|
|
289
|
+
}
|
|
239
290
|
function errorMessageFromUniswapJsonBody(value) {
|
|
240
291
|
if (value == null) return null;
|
|
241
292
|
if (typeof value === "string") {
|
|
@@ -348,16 +399,18 @@ async function uniswapTradeQuote(args) {
|
|
|
348
399
|
}
|
|
349
400
|
const base = args.baseUrl && args.baseUrl.trim() ? args.baseUrl.trim().replace(/\/$/, "") : DEFAULT_TRADE_BASE;
|
|
350
401
|
const quoteUrl = `${base}/quote`;
|
|
351
|
-
const
|
|
402
|
+
const chainIdForRouter = parseUniswapChainId(resolveInputChainId(args));
|
|
403
|
+
const urv = args.universalRouterVersion && args.universalRouterVersion.trim() || getUniswapUniversalRouterVersion(chainIdForRouter);
|
|
352
404
|
const body = buildUniswapQuoteRequestBody({ ...args, swapper });
|
|
353
|
-
const nativeIn =
|
|
405
|
+
const nativeIn = isUniswapNativeTokenAddress(args.tokenIn);
|
|
406
|
+
const nativeOut = isUniswapNativeTokenAddress(args.tokenOut);
|
|
354
407
|
const headers = {
|
|
355
408
|
...UNISWAP_QUOTE_HEADERS_BASE,
|
|
356
409
|
"x-api-key": apiKey,
|
|
357
410
|
"x-universal-router-version": urv,
|
|
358
411
|
"x-permit2-disabled": args.permit2Disabled === true ? "true" : "false",
|
|
359
|
-
/** Native (0x0)
|
|
360
|
-
"x-erc20eth-enabled": nativeIn ? "true" : "false"
|
|
412
|
+
/** Native (0x0) in or out: enables ERC20↔ETH routes (incl. UniswapX on Robinhood). */
|
|
413
|
+
"x-erc20eth-enabled": nativeIn || nativeOut ? "true" : "false"
|
|
361
414
|
};
|
|
362
415
|
const fetchFn = args.fetchImpl ?? globalThis.fetch;
|
|
363
416
|
const res = await fetchFn(quoteUrl, {
|
|
@@ -368,7 +421,11 @@ async function uniswapTradeQuote(args) {
|
|
|
368
421
|
});
|
|
369
422
|
const text = await res.text();
|
|
370
423
|
if (!res.ok) {
|
|
371
|
-
|
|
424
|
+
let msg = messageFromUniswapHttpResponseBody(text, res.status, res.statusText);
|
|
425
|
+
if (res.status === 404 && chainIdForRouter === 4663) {
|
|
426
|
+
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).";
|
|
427
|
+
}
|
|
428
|
+
throw new Error(msg);
|
|
372
429
|
}
|
|
373
430
|
const forParse = text.replace(/^\uFEFF/, "");
|
|
374
431
|
try {
|
|
@@ -932,16 +989,17 @@ async function uniswapCreateSwap(args) {
|
|
|
932
989
|
quote: classic,
|
|
933
990
|
deadline
|
|
934
991
|
};
|
|
935
|
-
const urv = (args.universalRouterVersion ??
|
|
992
|
+
const urv = (args.universalRouterVersion ?? "").trim() || getUniswapUniversalRouterVersion(resolveChainIdFromStoredUniswapQuote(args.fullQuoteFromPermit));
|
|
936
993
|
const fn = args.fetchImpl ?? globalThis.fetch;
|
|
937
994
|
const nativeIn = isUniswapFullQuoteResponseNativeIn(args.fullQuoteFromPermit);
|
|
995
|
+
const nativeOut = isUniswapFullQuoteResponseNativeOut(args.fullQuoteFromPermit);
|
|
938
996
|
const res = await fn(url, {
|
|
939
997
|
method: "POST",
|
|
940
998
|
headers: {
|
|
941
999
|
"Content-Type": "application/json",
|
|
942
1000
|
"x-api-key": args.uniswapApiKey.trim(),
|
|
943
1001
|
"x-universal-router-version": urv,
|
|
944
|
-
"x-erc20eth-enabled": nativeIn ? "true" : "false",
|
|
1002
|
+
"x-erc20eth-enabled": nativeIn || nativeOut ? "true" : "false",
|
|
945
1003
|
"x-permit2-disabled": "true"
|
|
946
1004
|
},
|
|
947
1005
|
body: JSON.stringify(body)
|
|
@@ -2655,6 +2713,11 @@ function uniswapV4SubgraphIdForChain(chainId) {
|
|
|
2655
2713
|
function uniswapV4SubgraphSupportedChainIds() {
|
|
2656
2714
|
return Object.keys(UNISWAP_V4_SUBGRAPH_ID_BY_CHAIN_ID).map(Number).sort((a, b) => a - b);
|
|
2657
2715
|
}
|
|
2716
|
+
function uniswapV4OhlcvSupportedChainIds() {
|
|
2717
|
+
const ids = new Set(uniswapV4SubgraphSupportedChainIds());
|
|
2718
|
+
ids.add(4663);
|
|
2719
|
+
return [...ids].sort((a, b) => a - b);
|
|
2720
|
+
}
|
|
2658
2721
|
function uniswapV4SubgraphUrlForChain(chainId, apiKey) {
|
|
2659
2722
|
const id = uniswapV4SubgraphIdForChain(chainId);
|
|
2660
2723
|
if (!id) {
|
|
@@ -2826,6 +2889,44 @@ async function fetchUniswapV4PoolMeta(args) {
|
|
|
2826
2889
|
return data.pool ?? null;
|
|
2827
2890
|
}
|
|
2828
2891
|
|
|
2892
|
+
// src/protocols/evm/uniswap-v4/bitqueryApiKey.ts
|
|
2893
|
+
var BITQUERY_API_KEY_ENV = "BITQUERY_API_KEY";
|
|
2894
|
+
var BITQUERY_API_KEY_SIGNUP_URL = "https://account.bitquery.io/";
|
|
2895
|
+
var BITQUERY_API_KEY_DOCS_URL = "https://bitquery.io/blockchains/robinhood-chain-api";
|
|
2896
|
+
var BITQUERY_GRAPHQL_URL = "https://graphql.bitquery.io";
|
|
2897
|
+
function resolveBitqueryApiKey(override) {
|
|
2898
|
+
const fromOverride = override?.trim();
|
|
2899
|
+
if (fromOverride) return fromOverride;
|
|
2900
|
+
const raw = process.env[BITQUERY_API_KEY_ENV]?.trim();
|
|
2901
|
+
return raw || void 0;
|
|
2902
|
+
}
|
|
2903
|
+
function isBitqueryAuthOrRateLimitError(message) {
|
|
2904
|
+
const m = message.toLowerCase();
|
|
2905
|
+
const mentionsBitquery = m.includes("bitquery") || m.includes("bitquery_api_key") || m.includes("robinhood chain ohlcv");
|
|
2906
|
+
if (!mentionsBitquery) return false;
|
|
2907
|
+
return m.includes("429") || m.includes("rate limit") || m.includes("too many requests") || m.includes("auth") || m.includes("unauthorized") || m.includes("forbidden") || m.includes("api key") || m.includes("access token") || m.includes("required");
|
|
2908
|
+
}
|
|
2909
|
+
function bitqueryApiKeyVariablesHint() {
|
|
2910
|
+
return [
|
|
2911
|
+
`Set \`${BITQUERY_API_KEY_ENV}\` in Node \u2192 AI Agent \u2192 Variables (+ Add: paste the key as the value).`,
|
|
2912
|
+
`Get an API key at ${BITQUERY_API_KEY_SIGNUP_URL}`
|
|
2913
|
+
].join(" ");
|
|
2914
|
+
}
|
|
2915
|
+
function bitqueryAuthErrorMessage(baseError) {
|
|
2916
|
+
return `${baseError}
|
|
2917
|
+
|
|
2918
|
+
Bitquery auth or rate limit \u2014 ${bitqueryApiKeyVariablesHint()}`;
|
|
2919
|
+
}
|
|
2920
|
+
function requireBitqueryApiKey(override) {
|
|
2921
|
+
const key = resolveBitqueryApiKey(override);
|
|
2922
|
+
if (!key) {
|
|
2923
|
+
throw new Error(
|
|
2924
|
+
`Bitquery API key is required for Robinhood Chain OHLCV. ${bitqueryApiKeyVariablesHint()}`
|
|
2925
|
+
);
|
|
2926
|
+
}
|
|
2927
|
+
return key;
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2829
2930
|
// src/protocols/evm/uniswap-v4/ohlcvInterval.ts
|
|
2830
2931
|
var UNISWAP_V4_OHLCV_INTERVALS = [
|
|
2831
2932
|
"1m",
|
|
@@ -2896,6 +2997,179 @@ function resolveUniswapV4OhlcvDataTier(intervalRaw) {
|
|
|
2896
2997
|
);
|
|
2897
2998
|
}
|
|
2898
2999
|
|
|
3000
|
+
// src/protocols/evm/uniswap-v4/bitqueryOhlcv.ts
|
|
3001
|
+
function intervalToBitquerySpec(interval) {
|
|
3002
|
+
const bucketSec = uniswapV4OhlcvIntervalToBucketSec(interval);
|
|
3003
|
+
if (bucketSec < 3600) {
|
|
3004
|
+
return { count: Math.max(1, Math.floor(bucketSec / 60)), in: "minutes" };
|
|
3005
|
+
}
|
|
3006
|
+
if (bucketSec < 86400) {
|
|
3007
|
+
return { count: Math.max(1, Math.floor(bucketSec / 3600)), in: "hours" };
|
|
3008
|
+
}
|
|
3009
|
+
return { count: Math.max(1, Math.floor(bucketSec / 86400)), in: "days" };
|
|
3010
|
+
}
|
|
3011
|
+
function parseIsoOrUnixToMs(raw) {
|
|
3012
|
+
if (raw == null) return null;
|
|
3013
|
+
if (typeof raw === "number" && Number.isFinite(raw)) {
|
|
3014
|
+
return raw > 1e12 ? raw : raw * 1e3;
|
|
3015
|
+
}
|
|
3016
|
+
const s = String(raw).trim();
|
|
3017
|
+
if (!s) return null;
|
|
3018
|
+
if (/^\d+$/.test(s)) {
|
|
3019
|
+
const n = Number(s);
|
|
3020
|
+
return n > 1e12 ? n : n * 1e3;
|
|
3021
|
+
}
|
|
3022
|
+
const ms = Date.parse(s);
|
|
3023
|
+
return Number.isFinite(ms) ? ms : null;
|
|
3024
|
+
}
|
|
3025
|
+
function numToString(raw) {
|
|
3026
|
+
if (raw == null) return null;
|
|
3027
|
+
const n = typeof raw === "number" ? raw : Number(String(raw).trim());
|
|
3028
|
+
if (!Number.isFinite(n)) return null;
|
|
3029
|
+
return String(n);
|
|
3030
|
+
}
|
|
3031
|
+
function mapBitqueryOhlcvRowsToCandles(rows) {
|
|
3032
|
+
const out = [];
|
|
3033
|
+
for (const row of rows) {
|
|
3034
|
+
const timestampMs = parseIsoOrUnixToMs(row.Block?.Time);
|
|
3035
|
+
if (timestampMs == null) continue;
|
|
3036
|
+
const open = numToString(row.Trade?.open);
|
|
3037
|
+
const high = numToString(row.Trade?.high);
|
|
3038
|
+
const low = numToString(row.Trade?.low);
|
|
3039
|
+
const close = numToString(row.Trade?.close);
|
|
3040
|
+
if (open == null || high == null || low == null || close == null) continue;
|
|
3041
|
+
const volume = numToString(row.volumeUsd) ?? numToString(row.volume) ?? void 0;
|
|
3042
|
+
out.push({
|
|
3043
|
+
timestampMs,
|
|
3044
|
+
open,
|
|
3045
|
+
high,
|
|
3046
|
+
low,
|
|
3047
|
+
close,
|
|
3048
|
+
...volume != null ? { volume } : {}
|
|
3049
|
+
});
|
|
3050
|
+
}
|
|
3051
|
+
return out.sort((a, b) => a.timestampMs - b.timestampMs);
|
|
3052
|
+
}
|
|
3053
|
+
function buildCurrencyWhere(filter) {
|
|
3054
|
+
if (filter.kind === "symbol") {
|
|
3055
|
+
const symbol = filter.symbol.trim().replace(/"/g, "");
|
|
3056
|
+
return `Currency: { Symbol: { is: "${symbol}" } }`;
|
|
3057
|
+
}
|
|
3058
|
+
const address = getAddress(filter.address).toLowerCase();
|
|
3059
|
+
return `Currency: { SmartContract: { is: "${address}" } }`;
|
|
3060
|
+
}
|
|
3061
|
+
function buildBitqueryOhlcvQuery(args) {
|
|
3062
|
+
const spec = intervalToBitquerySpec(args.interval);
|
|
3063
|
+
const currencyWhere = buildCurrencyWhere(args.filter);
|
|
3064
|
+
return `query RobinhoodUniswapOhlcv {
|
|
3065
|
+
EVM(network: robinhood) {
|
|
3066
|
+
DEXTradeByTokens(
|
|
3067
|
+
limit: { count: ${args.limit} }
|
|
3068
|
+
orderBy: { ascendingByField: "Block_Time" }
|
|
3069
|
+
where: {
|
|
3070
|
+
TransactionStatus: { Success: true }
|
|
3071
|
+
Trade: {
|
|
3072
|
+
Dex: { ProtocolName: { is: "uniswap_v4" } }
|
|
3073
|
+
${currencyWhere}
|
|
3074
|
+
}
|
|
3075
|
+
Block: { Time: { since: "${args.sinceIso}", till: "${args.tillIso}" } }
|
|
3076
|
+
}
|
|
3077
|
+
) {
|
|
3078
|
+
Block { Time(interval: { count: ${spec.count}, in: ${spec.in} }) }
|
|
3079
|
+
Trade {
|
|
3080
|
+
open: PriceInUSD(minimum: Block_Number)
|
|
3081
|
+
high: PriceInUSD(maximum: Trade_PriceInUSD)
|
|
3082
|
+
low: PriceInUSD(minimum: Trade_PriceInUSD)
|
|
3083
|
+
close: PriceInUSD(maximum: Block_Number)
|
|
3084
|
+
}
|
|
3085
|
+
volumeUsd: sum(of: Trade_Side_AmountInUSD)
|
|
3086
|
+
}
|
|
3087
|
+
}
|
|
3088
|
+
}`;
|
|
3089
|
+
}
|
|
3090
|
+
function isRobinhoodOhlcvChain(chainId) {
|
|
3091
|
+
return chainId === ROBINHOOD_CHAIN_ID;
|
|
3092
|
+
}
|
|
3093
|
+
function resolveRobinhoodChartCurrency(args) {
|
|
3094
|
+
const symbol = args.currencySymbol?.trim();
|
|
3095
|
+
if (symbol) return { kind: "symbol", symbol };
|
|
3096
|
+
const direct = args.currencyAddress?.trim();
|
|
3097
|
+
if (direct && direct.startsWith("0x")) {
|
|
3098
|
+
return { kind: "address", address: getAddress(direct) };
|
|
3099
|
+
}
|
|
3100
|
+
const weth = ROBINHOOD_WETH_ADDRESS.toLowerCase();
|
|
3101
|
+
const zero = zeroAddress.toLowerCase();
|
|
3102
|
+
const candidates = [args.tokenOut, args.tokenIn].map((a) => a?.trim()).filter((a) => Boolean(a && a.startsWith("0x"))).map((a) => getAddress(a));
|
|
3103
|
+
const nonWeth = candidates.find((a) => {
|
|
3104
|
+
const lower = a.toLowerCase();
|
|
3105
|
+
return lower !== weth && lower !== zero;
|
|
3106
|
+
});
|
|
3107
|
+
if (nonWeth) return { kind: "address", address: nonWeth };
|
|
3108
|
+
if (candidates[0]) return { kind: "address", address: candidates[0] };
|
|
3109
|
+
throw new Error(
|
|
3110
|
+
"Robinhood OHLCV requires currencyAddress, currencySymbol, or tokenIn/tokenOut (existingPool)."
|
|
3111
|
+
);
|
|
3112
|
+
}
|
|
3113
|
+
function currencyFilterLabel(filter) {
|
|
3114
|
+
if (filter.kind === "symbol") return filter.symbol.toUpperCase();
|
|
3115
|
+
return `${filter.address.slice(0, 6)}\u2026${filter.address.slice(-4)}`;
|
|
3116
|
+
}
|
|
3117
|
+
async function fetchRobinhoodBitqueryOhlcv(args) {
|
|
3118
|
+
const interval = assertUniswapV4OhlcvInterval(args.interval);
|
|
3119
|
+
const apiKey = requireBitqueryApiKey(args.apiKey);
|
|
3120
|
+
const limit = Math.max(1, Math.min(1e3, Math.floor(args.limit ?? 500)));
|
|
3121
|
+
const sinceIso = new Date(args.startTimeMs).toISOString();
|
|
3122
|
+
const tillIso = new Date(args.endTimeMs).toISOString();
|
|
3123
|
+
const query = buildBitqueryOhlcvQuery({
|
|
3124
|
+
filter: args.filter,
|
|
3125
|
+
interval,
|
|
3126
|
+
sinceIso,
|
|
3127
|
+
tillIso,
|
|
3128
|
+
limit
|
|
3129
|
+
});
|
|
3130
|
+
let json;
|
|
3131
|
+
try {
|
|
3132
|
+
const res = await fetch(BITQUERY_GRAPHQL_URL, {
|
|
3133
|
+
method: "POST",
|
|
3134
|
+
headers: {
|
|
3135
|
+
"content-type": "application/json",
|
|
3136
|
+
Authorization: `Bearer ${apiKey}`
|
|
3137
|
+
},
|
|
3138
|
+
body: JSON.stringify({ query })
|
|
3139
|
+
});
|
|
3140
|
+
const text = await res.text();
|
|
3141
|
+
if (!res.ok) {
|
|
3142
|
+
const msg = text ? `Bitquery HTTP ${res.status}: ${text.slice(0, 300)}` : `Bitquery HTTP ${res.status}`;
|
|
3143
|
+
throw new Error(
|
|
3144
|
+
isBitqueryAuthOrRateLimitError(msg) ? bitqueryAuthErrorMessage(msg) : msg
|
|
3145
|
+
);
|
|
3146
|
+
}
|
|
3147
|
+
json = JSON.parse(text);
|
|
3148
|
+
} catch (e) {
|
|
3149
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
3150
|
+
if (isBitqueryAuthOrRateLimitError(msg) && !msg.includes(BITQUERY_GRAPHQL_URL)) {
|
|
3151
|
+
throw new Error(bitqueryAuthErrorMessage(msg));
|
|
3152
|
+
}
|
|
3153
|
+
throw e instanceof Error ? e : new Error(msg);
|
|
3154
|
+
}
|
|
3155
|
+
if (json.errors?.length) {
|
|
3156
|
+
const msg = json.errors.map((e) => e.message ?? "GraphQL error").join("; ");
|
|
3157
|
+
throw new Error(
|
|
3158
|
+
isBitqueryAuthOrRateLimitError(msg) ? bitqueryAuthErrorMessage(msg) : `Bitquery GraphQL: ${msg}`
|
|
3159
|
+
);
|
|
3160
|
+
}
|
|
3161
|
+
const rows = json.data?.EVM?.DEXTradeByTokens ?? [];
|
|
3162
|
+
const candles = mapBitqueryOhlcvRowsToCandles(rows);
|
|
3163
|
+
const warnings = [];
|
|
3164
|
+
if (candles.length === 0) {
|
|
3165
|
+
warnings.push("No Bitquery Uniswap v4 candles for this token and window on Robinhood Chain.");
|
|
3166
|
+
}
|
|
3167
|
+
if (rows.length >= limit) {
|
|
3168
|
+
warnings.push("Bitquery row limit reached; history may be truncated. Shorten lookback or coarsen interval.");
|
|
3169
|
+
}
|
|
3170
|
+
return { candles, warnings };
|
|
3171
|
+
}
|
|
3172
|
+
|
|
2899
3173
|
// src/protocols/evm/uniswap-v4/swapCandles.ts
|
|
2900
3174
|
function parseDecimal(raw) {
|
|
2901
3175
|
if (raw == null) return null;
|
|
@@ -3171,11 +3445,40 @@ async function fetchFromSwapsTier(args) {
|
|
|
3171
3445
|
async function uniswapV4FetchOhlcv(args) {
|
|
3172
3446
|
const chainId = parseUniswapChainId(args.chainId);
|
|
3173
3447
|
const interval = assertUniswapV4OhlcvInterval(args.interval ?? "1h");
|
|
3174
|
-
const tier = resolveUniswapV4OhlcvDataTier(interval);
|
|
3175
|
-
const pool = await resolveUniswapV4OhlcvPool(args);
|
|
3176
3448
|
const { startTimeMs, endTimeMs } = windowFromArgs(args);
|
|
3177
3449
|
const fromSec = Math.floor(startTimeMs / 1e3);
|
|
3178
3450
|
const toSec = Math.ceil(endTimeMs / 1e3);
|
|
3451
|
+
if (isRobinhoodOhlcvChain(chainId)) {
|
|
3452
|
+
const filter = resolveRobinhoodChartCurrency({
|
|
3453
|
+
currencyAddress: args.currencyAddress,
|
|
3454
|
+
currencySymbol: args.currencySymbol,
|
|
3455
|
+
tokenIn: args.existingPool?.token0Address,
|
|
3456
|
+
tokenOut: args.existingPool?.token1Address
|
|
3457
|
+
});
|
|
3458
|
+
const { candles: candles2, warnings: warnings2 } = await fetchRobinhoodBitqueryOhlcv({
|
|
3459
|
+
filter,
|
|
3460
|
+
interval,
|
|
3461
|
+
startTimeMs,
|
|
3462
|
+
endTimeMs
|
|
3463
|
+
});
|
|
3464
|
+
const label = currencyFilterLabel(filter);
|
|
3465
|
+
const window2 = candleWindowFromRows(candles2);
|
|
3466
|
+
return {
|
|
3467
|
+
symbol: label,
|
|
3468
|
+
timeframe: interval,
|
|
3469
|
+
chainId,
|
|
3470
|
+
poolReference: filter.kind === "address" ? filter.address.toLowerCase() : `symbol:${filter.symbol}`,
|
|
3471
|
+
dataSource: "bitquery",
|
|
3472
|
+
priceQuote: "token0PerToken1",
|
|
3473
|
+
...window2,
|
|
3474
|
+
candleCount: candles2.length,
|
|
3475
|
+
candles: candles2,
|
|
3476
|
+
fetchedAtMs: Date.now(),
|
|
3477
|
+
...warnings2.length > 0 ? { warnings: warnings2 } : {}
|
|
3478
|
+
};
|
|
3479
|
+
}
|
|
3480
|
+
const tier = resolveUniswapV4OhlcvDataTier(interval);
|
|
3481
|
+
const pool = await resolveUniswapV4OhlcvPool(args);
|
|
3179
3482
|
const expectedBars = Math.ceil((toSec - fromSec) / tier.bucketSec);
|
|
3180
3483
|
if (expectedBars > MAX_CANDLES) {
|
|
3181
3484
|
throw new Error(
|
|
@@ -3236,6 +3539,370 @@ async function uniswapV4FetchOhlcv(args) {
|
|
|
3236
3539
|
};
|
|
3237
3540
|
}
|
|
3238
3541
|
|
|
3542
|
+
// src/protocols/evm/uniswap-v4/limitOrder.ts
|
|
3543
|
+
function trimAddr3(a) {
|
|
3544
|
+
return a.trim();
|
|
3545
|
+
}
|
|
3546
|
+
var UNISWAP_LIMIT_ORDER_CHAIN_ID = 1;
|
|
3547
|
+
var DEFAULT_UNISWAPX_ORDER_BASE = "https://api.uniswap.org/v2";
|
|
3548
|
+
var DEFAULT_LIMIT_ORDER_QUOTE_PATH = "/limit_order_quote";
|
|
3549
|
+
var DEFAULT_ORDER_SUBMIT_PATH = "/order";
|
|
3550
|
+
var UNISWAP_QUOTE_HEADERS_BASE2 = {
|
|
3551
|
+
"Content-Type": "application/json",
|
|
3552
|
+
"User-Agent": "ctm-mpc-defi uniswapLimitOrderQuote/1.0 (TS)"
|
|
3553
|
+
};
|
|
3554
|
+
function isUniswapLimitOrderChainSupported(chainId) {
|
|
3555
|
+
return parseUniswapChainId(chainId) === UNISWAP_LIMIT_ORDER_CHAIN_ID;
|
|
3556
|
+
}
|
|
3557
|
+
function assertUniswapLimitOrderChain(chainId) {
|
|
3558
|
+
if (!isUniswapLimitOrderChainSupported(chainId)) {
|
|
3559
|
+
throw new Error(
|
|
3560
|
+
`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.`
|
|
3561
|
+
);
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
function inferPrimaryTypeFromPermitTypes(types) {
|
|
3565
|
+
for (const key of Object.keys(types)) {
|
|
3566
|
+
if (key !== "EIP712Domain") {
|
|
3567
|
+
return key;
|
|
3568
|
+
}
|
|
3569
|
+
}
|
|
3570
|
+
throw new Error("permitData.types missing primaryType (no non-EIP712Domain entry)");
|
|
3571
|
+
}
|
|
3572
|
+
function permitDataToEip712Payload(permitData) {
|
|
3573
|
+
const domain = permitData.domain;
|
|
3574
|
+
const types = permitData.types;
|
|
3575
|
+
const message = permitData.values ?? permitData.message;
|
|
3576
|
+
if (domain == null || typeof domain !== "object" || Array.isArray(domain)) {
|
|
3577
|
+
throw new Error("limit order quote: permitData.domain missing");
|
|
3578
|
+
}
|
|
3579
|
+
if (types == null || typeof types !== "object" || Array.isArray(types)) {
|
|
3580
|
+
throw new Error("limit order quote: permitData.types missing");
|
|
3581
|
+
}
|
|
3582
|
+
if (message == null || typeof message !== "object" || Array.isArray(message)) {
|
|
3583
|
+
throw new Error("limit order quote: permitData.values (message) missing");
|
|
3584
|
+
}
|
|
3585
|
+
const primaryType = typeof permitData.primaryType === "string" && permitData.primaryType.trim() ? permitData.primaryType.trim() : inferPrimaryTypeFromPermitTypes(
|
|
3586
|
+
types
|
|
3587
|
+
);
|
|
3588
|
+
return {
|
|
3589
|
+
domain,
|
|
3590
|
+
types,
|
|
3591
|
+
primaryType,
|
|
3592
|
+
message
|
|
3593
|
+
};
|
|
3594
|
+
}
|
|
3595
|
+
function extractPermitDataFromLimitQuote(quoteResponse) {
|
|
3596
|
+
const permitData = quoteResponse.permitData;
|
|
3597
|
+
if (permitData == null) return null;
|
|
3598
|
+
if (typeof permitData !== "object" || Array.isArray(permitData)) {
|
|
3599
|
+
throw new Error("limit order quote: permitData is not an object");
|
|
3600
|
+
}
|
|
3601
|
+
return permitData;
|
|
3602
|
+
}
|
|
3603
|
+
function buildLimitOrderQuoteRequestBody(args) {
|
|
3604
|
+
const base = buildUniswapQuoteRequestBody({
|
|
3605
|
+
type: args.type,
|
|
3606
|
+
amount: args.amount,
|
|
3607
|
+
tokenIn: args.tokenIn,
|
|
3608
|
+
tokenOut: args.tokenOut,
|
|
3609
|
+
chainId: args.chainId,
|
|
3610
|
+
tokenInChainId: args.tokenInChainId,
|
|
3611
|
+
tokenOutChainId: args.tokenOutChainId,
|
|
3612
|
+
swapper: args.swapper
|
|
3613
|
+
});
|
|
3614
|
+
assertUniswapLimitOrderChain(base.tokenInChainId);
|
|
3615
|
+
return {
|
|
3616
|
+
...base,
|
|
3617
|
+
limitPrice: String(args.limitPrice).trim(),
|
|
3618
|
+
orderDeadline: args.orderDeadline
|
|
3619
|
+
};
|
|
3620
|
+
}
|
|
3621
|
+
async function uniswapLimitOrderQuote(args) {
|
|
3622
|
+
const apiKey = (args.uniswapApiKey || "").trim();
|
|
3623
|
+
if (!apiKey) {
|
|
3624
|
+
throw new Error("uniswapApiKey (x-api-key) is required");
|
|
3625
|
+
}
|
|
3626
|
+
let swapper;
|
|
3627
|
+
if ((args.swapper || "").trim()) {
|
|
3628
|
+
swapper = trimAddr3(args.swapper);
|
|
3629
|
+
} else {
|
|
3630
|
+
const keyGen = (args.keyGen || "").trim();
|
|
3631
|
+
if (!keyGen) {
|
|
3632
|
+
throw new Error("keyGen is required when swapper is not provided");
|
|
3633
|
+
}
|
|
3634
|
+
const mpc = (args.managementNodeUrl || "").trim();
|
|
3635
|
+
if (!mpc) {
|
|
3636
|
+
throw new Error("managementNodeUrl is required when swapper is not provided (to resolve keyGen)");
|
|
3637
|
+
}
|
|
3638
|
+
swapper = await fetchEthereumAddressForKeyGen(
|
|
3639
|
+
mpc,
|
|
3640
|
+
keyGen,
|
|
3641
|
+
args.nodeReadAuth ?? { bearerOnGet: true, jwt: null }
|
|
3642
|
+
);
|
|
3643
|
+
}
|
|
3644
|
+
const chainIdForGuard = parseUniswapChainId(resolveInputChainId(args));
|
|
3645
|
+
assertUniswapLimitOrderChain(chainIdForGuard);
|
|
3646
|
+
const base = args.baseUrl && args.baseUrl.trim() ? args.baseUrl.trim().replace(/\/$/, "") : "https://trade-api.gateway.uniswap.org/v1";
|
|
3647
|
+
const quoteUrl = `${base}${DEFAULT_LIMIT_ORDER_QUOTE_PATH}`;
|
|
3648
|
+
const body = buildLimitOrderQuoteRequestBody({ ...args, swapper });
|
|
3649
|
+
const headers = {
|
|
3650
|
+
...UNISWAP_QUOTE_HEADERS_BASE2,
|
|
3651
|
+
"x-api-key": apiKey
|
|
3652
|
+
};
|
|
3653
|
+
const fetchFn = args.fetchImpl ?? globalThis.fetch;
|
|
3654
|
+
const res = await fetchFn(quoteUrl, {
|
|
3655
|
+
method: "POST",
|
|
3656
|
+
headers,
|
|
3657
|
+
body: JSON.stringify(body),
|
|
3658
|
+
signal: args.signal
|
|
3659
|
+
});
|
|
3660
|
+
const text = await res.text();
|
|
3661
|
+
if (!res.ok) {
|
|
3662
|
+
throw new Error(messageFromUniswapHttpResponseBody(text, res.status, res.statusText));
|
|
3663
|
+
}
|
|
3664
|
+
const forParse = text.replace(/^\uFEFF/, "");
|
|
3665
|
+
try {
|
|
3666
|
+
return JSON.parse(forParse);
|
|
3667
|
+
} catch {
|
|
3668
|
+
throw new Error(
|
|
3669
|
+
`Limit order quote: ${messageFromUniswapHttpResponseBody(text, res.status, res.statusText)}`
|
|
3670
|
+
);
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
function buildUniswapXLimitOrderSubmitBody(args) {
|
|
3674
|
+
const quote = args.quoteResponse.quote;
|
|
3675
|
+
if (quote == null || typeof quote !== "object" || Array.isArray(quote)) {
|
|
3676
|
+
throw new Error("limit order submit: quoteResponse.quote missing");
|
|
3677
|
+
}
|
|
3678
|
+
const routing = typeof args.quoteResponse.routing === "string" && args.quoteResponse.routing.trim() ? args.quoteResponse.routing.trim() : "LIMIT_ORDER";
|
|
3679
|
+
const chainId = args.quoteResponse.chainId ?? quote.chainId ?? UNISWAP_LIMIT_ORDER_CHAIN_ID;
|
|
3680
|
+
const quoteId = typeof args.quoteResponse.quoteId === "string" ? args.quoteResponse.quoteId : void 0;
|
|
3681
|
+
const requestId = typeof args.quoteResponse.requestId === "string" ? args.quoteResponse.requestId : void 0;
|
|
3682
|
+
return {
|
|
3683
|
+
signature: args.signatureHex.startsWith("0x") ? args.signatureHex : `0x${args.signatureHex}`,
|
|
3684
|
+
quote,
|
|
3685
|
+
chainId: parseUniswapChainId(chainId),
|
|
3686
|
+
orderType: "Limit",
|
|
3687
|
+
routing,
|
|
3688
|
+
...quoteId ? { quoteId } : {},
|
|
3689
|
+
...requestId ? { requestId } : {}
|
|
3690
|
+
};
|
|
3691
|
+
}
|
|
3692
|
+
async function submitUniswapXLimitOrder(args) {
|
|
3693
|
+
const apiKey = (args.uniswapApiKey || "").trim();
|
|
3694
|
+
if (!apiKey) {
|
|
3695
|
+
throw new Error("uniswapApiKey (x-api-key) is required");
|
|
3696
|
+
}
|
|
3697
|
+
const base = args.baseUrl && args.baseUrl.trim() ? args.baseUrl.trim().replace(/\/$/, "") : "https://trade-api.gateway.uniswap.org/v1";
|
|
3698
|
+
const orderUrl = `${base}${DEFAULT_ORDER_SUBMIT_PATH}`;
|
|
3699
|
+
const fetchFn = args.fetchImpl ?? globalThis.fetch;
|
|
3700
|
+
const res = await fetchFn(orderUrl, {
|
|
3701
|
+
method: "POST",
|
|
3702
|
+
headers: {
|
|
3703
|
+
"Content-Type": "application/json",
|
|
3704
|
+
"x-api-key": apiKey,
|
|
3705
|
+
"User-Agent": "ctm-mpc-defi uniswapLimitOrderSubmit/1.0 (TS)"
|
|
3706
|
+
},
|
|
3707
|
+
body: JSON.stringify(args.submitBody)
|
|
3708
|
+
});
|
|
3709
|
+
const text = await res.text();
|
|
3710
|
+
if (!res.ok) {
|
|
3711
|
+
throw new Error(messageFromUniswapHttpResponseBody(text, res.status, res.statusText));
|
|
3712
|
+
}
|
|
3713
|
+
const forParse = text.replace(/^\uFEFF/, "");
|
|
3714
|
+
try {
|
|
3715
|
+
return JSON.parse(forParse);
|
|
3716
|
+
} catch {
|
|
3717
|
+
throw new Error(
|
|
3718
|
+
`Limit order submit: ${messageFromUniswapHttpResponseBody(text, res.status, res.statusText)}`
|
|
3719
|
+
);
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
async function fetchUniswapXLimitOrders(args) {
|
|
3723
|
+
const chainId = args.chainId ?? UNISWAP_LIMIT_ORDER_CHAIN_ID;
|
|
3724
|
+
assertUniswapLimitOrderChain(chainId);
|
|
3725
|
+
const base = args.baseUrl && args.baseUrl.trim() ? args.baseUrl.trim().replace(/\/$/, "") : DEFAULT_UNISWAPX_ORDER_BASE;
|
|
3726
|
+
const params = new URLSearchParams({
|
|
3727
|
+
chainId: String(chainId),
|
|
3728
|
+
swapper: trimAddr3(args.swapper)
|
|
3729
|
+
});
|
|
3730
|
+
if (args.limit != null && args.limit > 0) {
|
|
3731
|
+
params.set("limit", String(Math.floor(args.limit)));
|
|
3732
|
+
}
|
|
3733
|
+
const url = `${base}/limit-orders?${params.toString()}`;
|
|
3734
|
+
const headers = {
|
|
3735
|
+
Accept: "application/json",
|
|
3736
|
+
"User-Agent": "ctm-mpc-defi uniswapLimitOrdersList/1.0 (TS)"
|
|
3737
|
+
};
|
|
3738
|
+
const apiKey = (args.uniswapApiKey || "").trim();
|
|
3739
|
+
if (apiKey) {
|
|
3740
|
+
headers["x-api-key"] = apiKey;
|
|
3741
|
+
}
|
|
3742
|
+
const fetchFn = args.fetchImpl ?? globalThis.fetch;
|
|
3743
|
+
const res = await fetchFn(url, { method: "GET", headers });
|
|
3744
|
+
const text = await res.text();
|
|
3745
|
+
if (!res.ok) {
|
|
3746
|
+
const parsed = (() => {
|
|
3747
|
+
try {
|
|
3748
|
+
return JSON.parse(text);
|
|
3749
|
+
} catch {
|
|
3750
|
+
return null;
|
|
3751
|
+
}
|
|
3752
|
+
})();
|
|
3753
|
+
const msg = errorMessageFromUniswapJsonBody(parsed) ?? (text.trim() || res.statusText);
|
|
3754
|
+
throw new Error(`List limit orders HTTP ${res.status}: ${msg}`);
|
|
3755
|
+
}
|
|
3756
|
+
return JSON.parse(text.replace(/^\uFEFF/, ""));
|
|
3757
|
+
}
|
|
3758
|
+
async function uniswapFetchLimitOrdersMcp(args) {
|
|
3759
|
+
let swapper;
|
|
3760
|
+
if ((args.swapper || "").trim()) {
|
|
3761
|
+
swapper = trimAddr3(args.swapper);
|
|
3762
|
+
} else {
|
|
3763
|
+
const keyGen = (args.keyGen || "").trim();
|
|
3764
|
+
if (!keyGen) {
|
|
3765
|
+
throw new Error("swapper or keyGen is required");
|
|
3766
|
+
}
|
|
3767
|
+
const mpc = (args.managementNodeUrl || "").trim();
|
|
3768
|
+
if (!mpc) {
|
|
3769
|
+
throw new Error("managementNodeUrl is required when swapper is not provided");
|
|
3770
|
+
}
|
|
3771
|
+
swapper = await fetchEthereumAddressForKeyGen(
|
|
3772
|
+
mpc,
|
|
3773
|
+
keyGen,
|
|
3774
|
+
args.nodeReadAuth ?? { bearerOnGet: true, jwt: null }
|
|
3775
|
+
);
|
|
3776
|
+
}
|
|
3777
|
+
return fetchUniswapXLimitOrders({
|
|
3778
|
+
swapper,
|
|
3779
|
+
chainId: args.chainId,
|
|
3780
|
+
uniswapApiKey: args.uniswapApiKey,
|
|
3781
|
+
limit: args.limit,
|
|
3782
|
+
baseUrl: args.baseUrl,
|
|
3783
|
+
fetchImpl: args.fetchImpl
|
|
3784
|
+
});
|
|
3785
|
+
}
|
|
3786
|
+
var EIP712_SIGN_REQUEST_KIND = "eip712";
|
|
3787
|
+
function msgHashNo0x(digest) {
|
|
3788
|
+
return digest.startsWith("0x") ? digest.slice(2) : digest;
|
|
3789
|
+
}
|
|
3790
|
+
function eip712SignatureText(domain, primaryType) {
|
|
3791
|
+
return JSON.stringify({
|
|
3792
|
+
kind: "EIP-712",
|
|
3793
|
+
...typeof domain.name === "string" ? { name: domain.name } : {},
|
|
3794
|
+
primaryType
|
|
3795
|
+
});
|
|
3796
|
+
}
|
|
3797
|
+
function jsonStringifyForAudit(value) {
|
|
3798
|
+
return JSON.stringify(value, (_, v) => typeof v === "bigint" ? v.toString() : v);
|
|
3799
|
+
}
|
|
3800
|
+
function eip712MsgRawHex(typedData, delivery) {
|
|
3801
|
+
const envelope = {
|
|
3802
|
+
version: 1,
|
|
3803
|
+
...typedData,
|
|
3804
|
+
delivery
|
|
3805
|
+
};
|
|
3806
|
+
return stringToHex(jsonStringifyForAudit(envelope));
|
|
3807
|
+
}
|
|
3808
|
+
function buildEip712MultisignBody(args) {
|
|
3809
|
+
const { typedData, delivery } = args;
|
|
3810
|
+
const digest = hashTypedData({
|
|
3811
|
+
domain: typedData.domain,
|
|
3812
|
+
types: typedData.types,
|
|
3813
|
+
primaryType: typedData.primaryType,
|
|
3814
|
+
message: typedData.message
|
|
3815
|
+
});
|
|
3816
|
+
const extraJSON = {
|
|
3817
|
+
signRequestKind: EIP712_SIGN_REQUEST_KIND,
|
|
3818
|
+
eip712: {
|
|
3819
|
+
version: 1,
|
|
3820
|
+
digest,
|
|
3821
|
+
domain: typedData.domain,
|
|
3822
|
+
types: typedData.types,
|
|
3823
|
+
primaryType: typedData.primaryType,
|
|
3824
|
+
message: typedData.message
|
|
3825
|
+
},
|
|
3826
|
+
delivery
|
|
3827
|
+
};
|
|
3828
|
+
return finalizeMultisign({
|
|
3829
|
+
keyGen: args.keyGen,
|
|
3830
|
+
purposeText: args.purposeText,
|
|
3831
|
+
purposeSuffix: args.purposeSuffix,
|
|
3832
|
+
destinationChainID: args.destinationChainID,
|
|
3833
|
+
destinationAddress: args.destinationAddress,
|
|
3834
|
+
extraJSON,
|
|
3835
|
+
expiryDate: args.expiryDate,
|
|
3836
|
+
legs: [
|
|
3837
|
+
{
|
|
3838
|
+
msgHash: msgHashNo0x(digest),
|
|
3839
|
+
msgRaw: eip712MsgRawHex(typedData, delivery),
|
|
3840
|
+
destinationAddress: args.destinationAddress,
|
|
3841
|
+
signatureText: eip712SignatureText(typedData.domain, typedData.primaryType),
|
|
3842
|
+
audit: {
|
|
3843
|
+
kind: "EIP712",
|
|
3844
|
+
primaryType: typedData.primaryType,
|
|
3845
|
+
deliveryKind: delivery.kind,
|
|
3846
|
+
...args.audit ?? {}
|
|
3847
|
+
},
|
|
3848
|
+
feeSnapshot: {}
|
|
3849
|
+
}
|
|
3850
|
+
]
|
|
3851
|
+
});
|
|
3852
|
+
}
|
|
3853
|
+
|
|
3854
|
+
// src/protocols/evm/uniswap-v4/limitOrderMultisign.ts
|
|
3855
|
+
async function buildEvmMultisignBodyUniswapV4LimitOrderBatch(args) {
|
|
3856
|
+
assertUniswapLimitOrderChain(args.chainId);
|
|
3857
|
+
const permitRaw = extractPermitDataFromLimitQuote(args.fullLimitQuote);
|
|
3858
|
+
if (!permitRaw) {
|
|
3859
|
+
throw new Error(
|
|
3860
|
+
"Limit order quote has no permitData \u2014 cannot build EIP-712 sign request. Re-quote or confirm mainnet limit order support for this pair."
|
|
3861
|
+
);
|
|
3862
|
+
}
|
|
3863
|
+
const typedData = permitDataToEip712Payload(permitRaw);
|
|
3864
|
+
const submitTemplate = buildUniswapXLimitOrderSubmitBody({
|
|
3865
|
+
quoteResponse: args.fullLimitQuote,
|
|
3866
|
+
signatureHex: "0x"
|
|
3867
|
+
});
|
|
3868
|
+
return buildEip712MultisignBody({
|
|
3869
|
+
keyGen: args.keyGen,
|
|
3870
|
+
purposeText: args.purposeText,
|
|
3871
|
+
destinationChainID: String(UNISWAP_LIMIT_ORDER_CHAIN_ID),
|
|
3872
|
+
destinationAddress: PERMIT2_ADDRESS,
|
|
3873
|
+
typedData,
|
|
3874
|
+
delivery: {
|
|
3875
|
+
kind: "uniswapx_limit_order",
|
|
3876
|
+
chainId: UNISWAP_LIMIT_ORDER_CHAIN_ID,
|
|
3877
|
+
swapper: getAddress(args.swapper),
|
|
3878
|
+
submitBodyTemplate: submitTemplate,
|
|
3879
|
+
quoteResponse: args.fullLimitQuote,
|
|
3880
|
+
uniswapApiKey: args.uniswapApiKey,
|
|
3881
|
+
tradeApiBaseUrl: args.tradeApiBaseUrl ?? "https://trade-api.gateway.uniswap.org/v1"
|
|
3882
|
+
},
|
|
3883
|
+
audit: {
|
|
3884
|
+
protocol: "uniswap-v4",
|
|
3885
|
+
action: "limitOrder",
|
|
3886
|
+
routing: args.fullLimitQuote.routing ?? "LIMIT_ORDER",
|
|
3887
|
+
orderType: "Limit",
|
|
3888
|
+
primaryType: typedData.primaryType
|
|
3889
|
+
},
|
|
3890
|
+
expiryDate: args.expiryDate
|
|
3891
|
+
});
|
|
3892
|
+
}
|
|
3893
|
+
async function buildEvmMultisignBodyUniswapV4LimitOrderBatchFromMcp(args) {
|
|
3894
|
+
return buildEvmMultisignBodyUniswapV4LimitOrderBatch({
|
|
3895
|
+
keyGen: args.keyGen,
|
|
3896
|
+
chainId: args.chainId,
|
|
3897
|
+
purposeText: args.purposeText,
|
|
3898
|
+
fullLimitQuote: args.fullLimitQuote,
|
|
3899
|
+
swapper: getAddress(args.executorAddress),
|
|
3900
|
+
uniswapApiKey: args.uniswapApiKey,
|
|
3901
|
+
tradeApiBaseUrl: args.tradeApiBaseUrl,
|
|
3902
|
+
expiryDate: args.expiryDate
|
|
3903
|
+
});
|
|
3904
|
+
}
|
|
3905
|
+
|
|
3239
3906
|
// src/protocols/evm/uniswap-v4/index.ts
|
|
3240
3907
|
var UNISWAP_V4_PROTOCOL_ID = "uniswap-v4";
|
|
3241
3908
|
var uniswapV4ProtocolModule = {
|
|
@@ -3282,6 +3949,17 @@ var uniswapV4ProtocolModule = {
|
|
|
3282
3949
|
type: { type: "EXACT_INPUT | EXACT_OUTPUT", required: true, description: "Trade type" }
|
|
3283
3950
|
}
|
|
3284
3951
|
},
|
|
3952
|
+
{
|
|
3953
|
+
id: "uniswap-v4.limit-order",
|
|
3954
|
+
protocolId: UNISWAP_V4_PROTOCOL_ID,
|
|
3955
|
+
chainCategory: "evm",
|
|
3956
|
+
description: "Place UniswapX limit order via EIP-712 sign + POST /order (Ethereum mainnet only)",
|
|
3957
|
+
commonParams: ["keyGen", "purposeText"],
|
|
3958
|
+
params: {
|
|
3959
|
+
fullLimitQuote: { type: "object", required: true, description: "Full limit order quote from Trade API" },
|
|
3960
|
+
uniswapApiKey: { type: "string", required: true, description: "Uniswap Trade API key" }
|
|
3961
|
+
}
|
|
3962
|
+
},
|
|
3285
3963
|
{
|
|
3286
3964
|
id: "uniswap-v4.mint-liquidity",
|
|
3287
3965
|
protocolId: UNISWAP_V4_PROTOCOL_ID,
|
|
@@ -3337,6 +4015,10 @@ var uniswapV4 = {
|
|
|
3337
4015
|
swapExactInput,
|
|
3338
4016
|
swapFromQuote,
|
|
3339
4017
|
buildSwapMultisignBody: buildEvmMultisignBodyUniswapV4SkipPermit2Batch,
|
|
4018
|
+
limitOrderQuote: uniswapLimitOrderQuote,
|
|
4019
|
+
buildLimitOrderMultisignBody: buildEvmMultisignBodyUniswapV4LimitOrderBatchFromMcp,
|
|
4020
|
+
fetchLimitOrders: fetchUniswapXLimitOrders,
|
|
4021
|
+
fetchLimitOrdersMcp: uniswapFetchLimitOrdersMcp,
|
|
3340
4022
|
quote: uniswapTradeQuote,
|
|
3341
4023
|
createLiquidityPosition: uniswapLpCreatePosition,
|
|
3342
4024
|
increaseLiquidityPosition: uniswapLpIncreasePosition,
|
|
@@ -3350,6 +4032,6 @@ var uniswapV4 = {
|
|
|
3350
4032
|
isChainSupported: isUniswapV4ChainSupported
|
|
3351
4033
|
};
|
|
3352
4034
|
|
|
3353
|
-
export { MAX_UINT160, MAX_UINT48, PERMIT2_ADDRESS, THE_GRAPH_API_KEY_DOCS_URL, THE_GRAPH_API_KEY_ENV, THE_GRAPH_API_KEY_SIGNUP_URL, UNISWAP_LP_API_BASE_DEFAULT, UNISWAP_LP_DEFAULT_DEADLINE_SEC_OFFSET, UNISWAP_LP_DEFAULT_EXPIRY_MINUTES, UNISWAP_LP_DEFAULT_SLIPPAGE_PERCENT, UNISWAP_SWAP_DEFAULT_DEADLINE_SEC_OFFSET, UNISWAP_SWAP_DEFAULT_EXPIRY_MINUTES, UNISWAP_TRADE_BASE_DEFAULT, UNISWAP_UNIVERSAL_ROUTER_DEFAULT_GAS_UNITS, UNISWAP_UNIVERSAL_ROUTER_VERSION_DEFAULT, UNISWAP_V4_LP_COLLECT_DEFAULT_GAS_UNITS, UNISWAP_V4_LP_DECREASE_DEFAULT_GAS_UNITS, UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK, UNISWAP_V4_LP_INCREASE_DEFAULT_GAS_UNITS, UNISWAP_V4_LP_LOG_CHUNK_SIZE_DEFAULT, UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN, UNISWAP_V4_LP_MINT_DEFAULT_GAS_UNITS, UNISWAP_V4_LP_POOL_LOOKUP_HINT, UNISWAP_V4_LP_POSITION_REGISTRY_HINT, UNISWAP_V4_LP_WETH_DEPOSIT_FALLBACK, UNISWAP_V4_OHLCV_INTERVALS, UNISWAP_V4_PROTOCOL_ID, UNISWAP_V4_SUBGRAPH_ID_BY_CHAIN_ID, aggregateOhlcvCandles, applySlippagePercentToApproveWei, assertUniswapV4OhlcvInterval,
|
|
4035
|
+
export { BITQUERY_API_KEY_DOCS_URL, BITQUERY_API_KEY_ENV, BITQUERY_API_KEY_SIGNUP_URL, BITQUERY_GRAPHQL_URL, DEFAULT_LIMIT_ORDER_QUOTE_PATH, DEFAULT_ORDER_SUBMIT_PATH, DEFAULT_UNISWAPX_ORDER_BASE, MAX_UINT160, MAX_UINT48, PERMIT2_ADDRESS, ROBINHOOD_CHAIN_ID, ROBINHOOD_WETH_ADDRESS, THE_GRAPH_API_KEY_DOCS_URL, THE_GRAPH_API_KEY_ENV, THE_GRAPH_API_KEY_SIGNUP_URL, UNISWAP_LIMIT_ORDER_CHAIN_ID, UNISWAP_LP_API_BASE_DEFAULT, UNISWAP_LP_DEFAULT_DEADLINE_SEC_OFFSET, UNISWAP_LP_DEFAULT_EXPIRY_MINUTES, UNISWAP_LP_DEFAULT_SLIPPAGE_PERCENT, UNISWAP_SWAP_DEFAULT_DEADLINE_SEC_OFFSET, UNISWAP_SWAP_DEFAULT_EXPIRY_MINUTES, UNISWAP_TRADE_BASE_DEFAULT, UNISWAP_UNIVERSAL_ROUTER_DEFAULT_GAS_UNITS, UNISWAP_UNIVERSAL_ROUTER_VERSION_DEFAULT, UNISWAP_V4_LP_COLLECT_DEFAULT_GAS_UNITS, UNISWAP_V4_LP_DECREASE_DEFAULT_GAS_UNITS, UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK, UNISWAP_V4_LP_INCREASE_DEFAULT_GAS_UNITS, UNISWAP_V4_LP_LOG_CHUNK_SIZE_DEFAULT, UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN, UNISWAP_V4_LP_MINT_DEFAULT_GAS_UNITS, UNISWAP_V4_LP_POOL_LOOKUP_HINT, UNISWAP_V4_LP_POSITION_REGISTRY_HINT, UNISWAP_V4_LP_WETH_DEPOSIT_FALLBACK, UNISWAP_V4_OHLCV_INTERVALS, UNISWAP_V4_PROTOCOL_ID, UNISWAP_V4_SUBGRAPH_ID_BY_CHAIN_ID, aggregateOhlcvCandles, applySlippagePercentToApproveWei, assertUniswapLimitOrderChain, assertUniswapV4OhlcvInterval, bitqueryApiKeyVariablesHint, bitqueryAuthErrorMessage, buildEvmMultisignBodyUniswapV4CollectFeesBatch, buildEvmMultisignBodyUniswapV4DecreaseLiquidityBatch, buildEvmMultisignBodyUniswapV4IncreaseLiquidityBatch, buildEvmMultisignBodyUniswapV4LimitOrderBatch, buildEvmMultisignBodyUniswapV4LimitOrderBatchFromMcp, buildEvmMultisignBodyUniswapV4MintLiquidityBatch, buildEvmMultisignBodyUniswapV4SkipPermit2Batch, buildLimitOrderQuoteRequestBody, buildUniswapQuoteRequestBody, buildUniswapV4PurposePrefill, buildUniswapXLimitOrderSubmitBody, computeUniswapV4PoolReference, computeUniswapV4Session, createSwap, currencyFilterLabel, errorMessageFromUniswapJsonBody, extractPermitDataFromLimitQuote, extractUniswapLpTokenAmounts, extractUniswapLpTransaction, fetchEthereumAddressForKeyGen, fetchRobinhoodBitqueryOhlcv, fetchUniswapV4PoolDayDatas, fetchUniswapV4PoolHourDatas, fetchUniswapV4PoolMeta, fetchUniswapV4Swaps, fetchUniswapXLimitOrders, formatUniswapAmountFieldFromWei, formatUniswapLpAmountHuman, formatUniswapPercentForUi, formatUniswapQuoteForDisplay, formatUniswapV4PositionNotFoundError, getClassicQuoteFromStoredUniswapResponse, getUniswapUniversalRouterSpenderOrThrow, getUniswapUniversalRouterVersion, getUniswapV4PositionManagerDeployBlock, getUniswapV4PositionManagerOrThrow, isBitqueryAuthOrRateLimitError, isEthGetLogsBlockRangeTooLargeError, isNativeUniswapLpTokenAddress, isRobinhoodOhlcvChain, isTheGraphRateLimitOrAuthError, isUniswapFullQuoteResponseNativeIn, isUniswapFullQuoteResponseNativeOut, isUniswapLimitOrderChainSupported, isUniswapNativeTokenAddress, isUniswapTokenInAddressNative, isUniswapV4ChainSupported, isUniswapV4LiquidityEvmSignRequest, isUniswapV4SwapEvmSignRequest, listUniswapV4PositionsForWallet, listUniswapV4StandardLpPools, mapBitqueryOhlcvRowsToCandles, messageFromUniswapHttpResponseBody, parseUniswapChainId, parseUniswapLpApiSnapshot, parseUniswapQuoteClassicInOut, parseUniswapQuoteSlippageInfo, parseUniswapV4ScanFromDateYmd, permitDataToEip712Payload, quoteSwap, readUniswapV4PositionInfoRaw, requireBitqueryApiKey, resolveBitqueryApiKey, resolveBlockAtOrAfterUnixTime, resolveChainIdFromStoredUniswapQuote, resolveInputChainId, resolveRobinhoodChartCurrency, resolveRouterSwapGasUnitsFromSignRequest, resolveTheGraphApiKey, resolveUniswapV4LpExistingPoolFromKey, resolveUniswapV4LpPoolPreset, resolveUniswapV4OhlcvDataTier, resolveUniswapV4OhlcvPool, resolveUniswapV4PositionScanFromDate, sortUniswapV4PoolCurrencies, submitUniswapXLimitOrder, swapExactInput, swapFromQuote, swapTransactionDeadlineUnixFromExpiryMinutes, theGraphApiKeyVariablesHint, theGraphRateLimitErrorMessage, tryGetUniswapV4PositionManager, uniswapCreateSwap, uniswapFetchLimitOrdersMcp, uniswapLimitOrderQuote, uniswapLpClaimFees, uniswapLpCreatePosition, uniswapLpDecreasePosition, uniswapLpIncreasePosition, uniswapLpTxFieldForAction, uniswapQuoteToJsonQuoteOneLine, uniswapTradeQuote, uniswapV4, uniswapV4FetchOhlcv, uniswapV4ListPositionsForMcp, uniswapV4ListPositionsFromRegistryForMcp, uniswapV4ListPositionsRegistryMcpPlaceholder, uniswapV4ListStandardLpPools, uniswapV4OhlcvIntervalToBucketSec, uniswapV4OhlcvSupportedChainIds, uniswapV4PositionMintedTokenIdsFromReceipt, uniswapV4ProtocolModule, uniswapV4RegisterPositionFromMintTxPlaceholder, uniswapV4RegisterPositionNftPlaceholder, uniswapV4SubgraphIdForChain, uniswapV4SubgraphSupportedChainIds, uniswapV4SubgraphUrlForChain };
|
|
3354
4036
|
//# sourceMappingURL=index.js.map
|
|
3355
4037
|
//# sourceMappingURL=index.js.map
|