@abstract-foundation/agw-mcp 0.1.0-beta.7 → 0.1.0-beta.8
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/index.mjs +31 -11
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -439,11 +439,22 @@ function normalizeRouteFills(value) {
|
|
|
439
439
|
}
|
|
440
440
|
return fills;
|
|
441
441
|
}
|
|
442
|
+
function normalizeTransaction(payload) {
|
|
443
|
+
const transaction = isRecord$5(payload.transaction) ? payload.transaction : {};
|
|
444
|
+
return {
|
|
445
|
+
to: requireString(transaction.to ?? payload.to, "to"),
|
|
446
|
+
data: requireString(transaction.data ?? payload.data, "data"),
|
|
447
|
+
value: asString(transaction.value ?? payload.value) ?? "0",
|
|
448
|
+
gasLimit: asString(transaction.gas ?? payload.gas),
|
|
449
|
+
gasPrice: asString(transaction.gasPrice ?? payload.gasPrice)
|
|
450
|
+
};
|
|
451
|
+
}
|
|
442
452
|
function normalizeQuotePayload(payload, request) {
|
|
443
453
|
if (!isRecord$5(payload)) throw new Error("response payload must be an object");
|
|
444
454
|
const issues = isRecord$5(payload.issues) ? payload.issues : {};
|
|
445
455
|
const route = isRecord$5(payload.route) ? payload.route : {};
|
|
446
456
|
const fees = isRecord$5(payload.fees) ? payload.fees : {};
|
|
457
|
+
const transaction = normalizeTransaction(payload);
|
|
447
458
|
return {
|
|
448
459
|
quoteId: asString(payload.zid),
|
|
449
460
|
chainId: normalizePositiveInteger(payload.chainId ?? request.chainId, "chainId"),
|
|
@@ -457,14 +468,14 @@ function normalizeQuotePayload(payload, request) {
|
|
|
457
468
|
estimatedPriceImpact: asString(payload.estimatedPriceImpact),
|
|
458
469
|
allowanceTarget: asString(payload.allowanceTarget),
|
|
459
470
|
gas: {
|
|
460
|
-
limit:
|
|
461
|
-
price:
|
|
471
|
+
limit: transaction.gasLimit,
|
|
472
|
+
price: transaction.gasPrice,
|
|
462
473
|
estimatedFee: asString(payload.totalNetworkFee)
|
|
463
474
|
},
|
|
464
475
|
transaction: {
|
|
465
|
-
to:
|
|
466
|
-
data:
|
|
467
|
-
value:
|
|
476
|
+
to: transaction.to,
|
|
477
|
+
data: transaction.data,
|
|
478
|
+
value: transaction.value
|
|
468
479
|
},
|
|
469
480
|
fees: {
|
|
470
481
|
integratorFee: normalizeFee(fees.integratorFee),
|
|
@@ -2910,6 +2921,7 @@ const signTransactionTool = {
|
|
|
2910
2921
|
|
|
2911
2922
|
//#endregion
|
|
2912
2923
|
//#region src/tools/swap-tokens.ts
|
|
2924
|
+
const ZEROEX_NATIVE_ETH_SENTINEL = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
2913
2925
|
function parseExecute$1(value) {
|
|
2914
2926
|
if (value === void 0) return false;
|
|
2915
2927
|
if (typeof value !== "boolean") throw new Error("execute must be a boolean");
|
|
@@ -2925,6 +2937,11 @@ function parseOptionalString(value, field) {
|
|
|
2925
2937
|
if (typeof value !== "string" || value.trim() === "") throw new Error(`${field} must be a non-empty string when provided`);
|
|
2926
2938
|
return value.trim();
|
|
2927
2939
|
}
|
|
2940
|
+
function normalizeSwapToken(value, nativeSymbol) {
|
|
2941
|
+
const normalized = value.trim();
|
|
2942
|
+
if (normalized.toUpperCase() === nativeSymbol.toUpperCase()) return ZEROEX_NATIVE_ETH_SENTINEL;
|
|
2943
|
+
return normalized;
|
|
2944
|
+
}
|
|
2928
2945
|
function createSwapTokensTool(dependencies = {}) {
|
|
2929
2946
|
const createQuoteAdapter = dependencies.createQuoteAdapter ?? (() => {
|
|
2930
2947
|
return createZeroExQuoteAdapter({ apiKey: resolveZeroExConfig().apiKey });
|
|
@@ -2937,11 +2954,11 @@ function createSwapTokensTool(dependencies = {}) {
|
|
|
2937
2954
|
properties: {
|
|
2938
2955
|
sellToken: {
|
|
2939
2956
|
type: "string",
|
|
2940
|
-
description: "Token address
|
|
2957
|
+
description: "Token address to sell, or native symbol (for example ETH)"
|
|
2941
2958
|
},
|
|
2942
2959
|
buyToken: {
|
|
2943
2960
|
type: "string",
|
|
2944
|
-
description: "Token address
|
|
2961
|
+
description: "Token address to buy, or native symbol (for example ETH)"
|
|
2945
2962
|
},
|
|
2946
2963
|
sellAmount: {
|
|
2947
2964
|
type: "string",
|
|
@@ -2971,11 +2988,15 @@ function createSwapTokensTool(dependencies = {}) {
|
|
|
2971
2988
|
const session = context.sessionManager.getSession();
|
|
2972
2989
|
if (!session) throw new Error("session is missing");
|
|
2973
2990
|
const execute = parseExecute$1(params.execute);
|
|
2974
|
-
const
|
|
2991
|
+
const quoteAdapter = dependencies.quoteAdapter ?? createQuoteAdapter();
|
|
2992
|
+
const networkConfig = resolveToolNetworkConfig(context, session.chainId);
|
|
2993
|
+
const sellToken = normalizeSwapToken(params.sellToken, networkConfig.chain.nativeCurrency.symbol);
|
|
2994
|
+
const buyToken = normalizeSwapToken(params.buyToken, networkConfig.chain.nativeCurrency.symbol);
|
|
2995
|
+
const quote = await quoteAdapter.getQuote({
|
|
2975
2996
|
chainId: session.chainId,
|
|
2976
2997
|
taker: session.accountAddress,
|
|
2977
|
-
sellToken
|
|
2978
|
-
buyToken
|
|
2998
|
+
sellToken,
|
|
2999
|
+
buyToken,
|
|
2979
3000
|
sellAmount: parseOptionalString(params.sellAmount, "sellAmount"),
|
|
2980
3001
|
buyAmount: parseOptionalString(params.buyAmount, "buyAmount"),
|
|
2981
3002
|
slippageBps: parseOptionalInteger(params.slippageBps, "slippageBps")
|
|
@@ -2996,7 +3017,6 @@ function createSwapTokensTool(dependencies = {}) {
|
|
|
2996
3017
|
spender: quote.issues.allowance?.spender ?? null
|
|
2997
3018
|
}
|
|
2998
3019
|
};
|
|
2999
|
-
const networkConfig = resolveToolNetworkConfig(context, session.chainId);
|
|
3000
3020
|
await assertMainnetPolicyRegistryPreflight({
|
|
3001
3021
|
chainId: session.chainId,
|
|
3002
3022
|
to: txTarget,
|