@gblin-protocol/mcp-server 0.1.0
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/LICENSE +21 -0
- package/README.md +213 -0
- package/dist/abi.d.ts +260 -0
- package/dist/abi.d.ts.map +1 -0
- package/dist/abi.js +52 -0
- package/dist/abi.js.map +1 -0
- package/dist/client.d.ts +11247 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +26 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +26 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +36 -0
- package/dist/config.js.map +1 -0
- package/dist/helpers.d.ts +83 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +259 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/tools.d.ts +147 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +497 -0
- package/dist/tools.js.map +1 -0
- package/llms.txt +52 -0
- package/package.json +66 -0
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GBLIN MCP — Tool Implementations
|
|
3
|
+
*
|
|
4
|
+
* Five focused tools. Each returns structured JSON the LLM can parse:
|
|
5
|
+
*
|
|
6
|
+
* 1. get_treasury_state → NAV, basket, Crash Shield (snapshot)
|
|
7
|
+
* 2. quote_safe_swap → preview a buy/sell with safe minOut
|
|
8
|
+
* 3. swap_gblin_to_usdc_jit → calldata for Just-In-Time x402 payment
|
|
9
|
+
* 4. invest_usdc_to_gblin → calldata to convert USDC earnings → GBLIN
|
|
10
|
+
* 5. analyze_treasury_health → balances + gas check + runway estimate
|
|
11
|
+
*/
|
|
12
|
+
declare function toolResult(payload: unknown): {
|
|
13
|
+
content: {
|
|
14
|
+
type: "text";
|
|
15
|
+
text: string;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
declare function toolError(message: string, hint?: string): {
|
|
19
|
+
isError: boolean;
|
|
20
|
+
content: {
|
|
21
|
+
type: "text";
|
|
22
|
+
text: string;
|
|
23
|
+
}[];
|
|
24
|
+
};
|
|
25
|
+
export declare const GET_TREASURY_STATE_DEFINITION: {
|
|
26
|
+
name: string;
|
|
27
|
+
description: string;
|
|
28
|
+
inputSchema: {
|
|
29
|
+
type: "object";
|
|
30
|
+
properties: {};
|
|
31
|
+
additionalProperties: boolean;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export declare function handleGetTreasuryState(): Promise<{
|
|
35
|
+
content: {
|
|
36
|
+
type: "text";
|
|
37
|
+
text: string;
|
|
38
|
+
}[];
|
|
39
|
+
}>;
|
|
40
|
+
export declare const QUOTE_SAFE_SWAP_DEFINITION: {
|
|
41
|
+
name: string;
|
|
42
|
+
description: string;
|
|
43
|
+
inputSchema: {
|
|
44
|
+
type: "object";
|
|
45
|
+
properties: {
|
|
46
|
+
direction: {
|
|
47
|
+
type: string;
|
|
48
|
+
enum: string[];
|
|
49
|
+
};
|
|
50
|
+
amount_in: {
|
|
51
|
+
type: string;
|
|
52
|
+
description: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
required: string[];
|
|
56
|
+
additionalProperties: boolean;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export declare function handleQuoteSafeSwap(args: unknown): Promise<{
|
|
60
|
+
content: {
|
|
61
|
+
type: "text";
|
|
62
|
+
text: string;
|
|
63
|
+
}[];
|
|
64
|
+
}>;
|
|
65
|
+
export declare const JIT_SWAP_DEFINITION: {
|
|
66
|
+
name: string;
|
|
67
|
+
description: string;
|
|
68
|
+
inputSchema: {
|
|
69
|
+
type: "object";
|
|
70
|
+
properties: {
|
|
71
|
+
usdc_needed: {
|
|
72
|
+
type: string;
|
|
73
|
+
description: string;
|
|
74
|
+
};
|
|
75
|
+
wallet_address: {
|
|
76
|
+
type: string;
|
|
77
|
+
description: string;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
required: string[];
|
|
81
|
+
additionalProperties: boolean;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
export declare function handleJitSwap(args: unknown): Promise<{
|
|
85
|
+
content: {
|
|
86
|
+
type: "text";
|
|
87
|
+
text: string;
|
|
88
|
+
}[];
|
|
89
|
+
}>;
|
|
90
|
+
export declare const INVEST_DEFINITION: {
|
|
91
|
+
name: string;
|
|
92
|
+
description: string;
|
|
93
|
+
inputSchema: {
|
|
94
|
+
type: "object";
|
|
95
|
+
properties: {
|
|
96
|
+
usdc_amount: {
|
|
97
|
+
type: string;
|
|
98
|
+
description: string;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
required: string[];
|
|
102
|
+
additionalProperties: boolean;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
export declare function handleInvest(args: unknown): Promise<{
|
|
106
|
+
content: {
|
|
107
|
+
type: "text";
|
|
108
|
+
text: string;
|
|
109
|
+
}[];
|
|
110
|
+
}>;
|
|
111
|
+
export declare const ANALYZE_TREASURY_DEFINITION: {
|
|
112
|
+
name: string;
|
|
113
|
+
description: string;
|
|
114
|
+
inputSchema: {
|
|
115
|
+
type: "object";
|
|
116
|
+
properties: {
|
|
117
|
+
wallet_address: {
|
|
118
|
+
type: string;
|
|
119
|
+
description: string;
|
|
120
|
+
};
|
|
121
|
+
daily_burn_usd: {
|
|
122
|
+
type: string;
|
|
123
|
+
description: string;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
required: string[];
|
|
127
|
+
additionalProperties: boolean;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
export declare function handleAnalyzeTreasury(args: unknown): Promise<{
|
|
131
|
+
content: {
|
|
132
|
+
type: "text";
|
|
133
|
+
text: string;
|
|
134
|
+
}[];
|
|
135
|
+
}>;
|
|
136
|
+
export declare const TOOL_DEFINITIONS: {
|
|
137
|
+
name: string;
|
|
138
|
+
description: string;
|
|
139
|
+
inputSchema: {
|
|
140
|
+
type: "object";
|
|
141
|
+
properties: {};
|
|
142
|
+
additionalProperties: boolean;
|
|
143
|
+
};
|
|
144
|
+
}[];
|
|
145
|
+
export declare const TOOL_HANDLERS: Record<string, (args: unknown) => Promise<ReturnType<typeof toolResult> | ReturnType<typeof toolError>>>;
|
|
146
|
+
export {};
|
|
147
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA6CH,iBAAS,UAAU,CAAC,OAAO,EAAE,OAAO;;;;;EASnC;AAED,iBAAS,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;;;;;;EAUhD;AAWD,eAAO,MAAM,6BAA6B;;;;;;;;CASzC,CAAC;AAEF,wBAAsB,sBAAsB;;;;;GAgC3C;AAaD,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;CAgBtC,CAAC;AAEF,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,OAAO;;;;;GAoEtD;AAeD,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;CAgB/B,CAAC;AAEF,wBAAsB,aAAa,CAAC,IAAI,EAAE,OAAO;;;;;GA6DhD;AAUD,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;CAe7B,CAAC;AAEF,wBAAsB,YAAY,CAAC,IAAI,EAAE,OAAO;;;;;GA6F/C;AAeD,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;CAgBvC,CAAC;AAEF,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,OAAO;;;;;GAsGxD;AAMD,eAAO,MAAM,gBAAgB;;;;;;;;GAM5B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,MAAM,CAChC,MAAM,EACN,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAOzF,CAAC"}
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GBLIN MCP — Tool Implementations
|
|
3
|
+
*
|
|
4
|
+
* Five focused tools. Each returns structured JSON the LLM can parse:
|
|
5
|
+
*
|
|
6
|
+
* 1. get_treasury_state → NAV, basket, Crash Shield (snapshot)
|
|
7
|
+
* 2. quote_safe_swap → preview a buy/sell with safe minOut
|
|
8
|
+
* 3. swap_gblin_to_usdc_jit → calldata for Just-In-Time x402 payment
|
|
9
|
+
* 4. invest_usdc_to_gblin → calldata to convert USDC earnings → GBLIN
|
|
10
|
+
* 5. analyze_treasury_health → balances + gas check + runway estimate
|
|
11
|
+
*/
|
|
12
|
+
import { encodeFunctionData, encodePacked, formatUnits, getAddress, isAddress, parseUnits, } from "viem";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import { ERC20_ABI, GBLIN_ABI } from "./abi.js";
|
|
15
|
+
import { client } from "./client.js";
|
|
16
|
+
import { GBLIN_V5, MIN_DEPOSIT_WEI, USDC, WETH, WETH_USDC_POOL_FEE, } from "./config.js";
|
|
17
|
+
import { applySlippageBuffer, checkCooldown, getBasketState, getDynamicSlippage, getEthPriceUsd, getNavUsd, getWalletBalances, quoteGblinForUsdc, } from "./helpers.js";
|
|
18
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
19
|
+
// SHARED HELPERS
|
|
20
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
21
|
+
const AddressSchema = z
|
|
22
|
+
.string()
|
|
23
|
+
.refine((v) => isAddress(v), { message: "Invalid EVM address" })
|
|
24
|
+
.transform((v) => getAddress(v));
|
|
25
|
+
const AmountStringSchema = z
|
|
26
|
+
.string()
|
|
27
|
+
.regex(/^\d+(\.\d+)?$/, "Amount must be a positive decimal string");
|
|
28
|
+
function toolResult(payload) {
|
|
29
|
+
return {
|
|
30
|
+
content: [
|
|
31
|
+
{
|
|
32
|
+
type: "text",
|
|
33
|
+
text: JSON.stringify(payload, jsonReplacer, 2),
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function toolError(message, hint) {
|
|
39
|
+
return {
|
|
40
|
+
isError: true,
|
|
41
|
+
content: [
|
|
42
|
+
{
|
|
43
|
+
type: "text",
|
|
44
|
+
text: JSON.stringify({ error: message, hint }, null, 2),
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** JSON.stringify replacer that turns BigInt into string. */
|
|
50
|
+
function jsonReplacer(_key, value) {
|
|
51
|
+
return typeof value === "bigint" ? value.toString() : value;
|
|
52
|
+
}
|
|
53
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
54
|
+
// TOOL 1 — get_treasury_state
|
|
55
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
56
|
+
export const GET_TREASURY_STATE_DEFINITION = {
|
|
57
|
+
name: "get_treasury_state",
|
|
58
|
+
description: "Read the current GBLIN protocol state on Base mainnet: NAV in USD, basket composition with dynamic weights, and Crash Shield status. Use this BEFORE any swap to know the current price and risk regime.",
|
|
59
|
+
inputSchema: {
|
|
60
|
+
type: "object",
|
|
61
|
+
properties: {},
|
|
62
|
+
additionalProperties: false,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
export async function handleGetTreasuryState() {
|
|
66
|
+
try {
|
|
67
|
+
const [navUsd, ethPriceUsd, basket, slippage] = await Promise.all([
|
|
68
|
+
getNavUsd(),
|
|
69
|
+
getEthPriceUsd(),
|
|
70
|
+
getBasketState(),
|
|
71
|
+
getDynamicSlippage(),
|
|
72
|
+
]);
|
|
73
|
+
return toolResult({
|
|
74
|
+
nav_usd: Number(navUsd.toFixed(6)),
|
|
75
|
+
eth_price_usd: Number(ethPriceUsd.toFixed(2)),
|
|
76
|
+
crash_shield_active: basket.crashShieldActive,
|
|
77
|
+
slippage_buffer_pct: slippage.pct,
|
|
78
|
+
slippage_reason: slippage.reason,
|
|
79
|
+
basket: basket.entries.map((e) => ({
|
|
80
|
+
token: e.token,
|
|
81
|
+
is_stable: e.isStable,
|
|
82
|
+
base_weight_pct: e.baseWeightBps / 100,
|
|
83
|
+
dynamic_weight_pct: e.dynamicWeightBps / 100,
|
|
84
|
+
slashed: e.isSlashed,
|
|
85
|
+
pool_fee_bps: e.poolFee,
|
|
86
|
+
})),
|
|
87
|
+
meta: {
|
|
88
|
+
contract: GBLIN_V5,
|
|
89
|
+
chain: "base",
|
|
90
|
+
chain_id: 8453,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
return toolError(err.message, "Check RPC connectivity and oracle freshness.");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
99
|
+
// TOOL 2 — quote_safe_swap
|
|
100
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
101
|
+
const QuoteSafeSwapSchema = z.object({
|
|
102
|
+
direction: z.enum(["buy", "sell"]),
|
|
103
|
+
amount_in: AmountStringSchema.describe("For direction=buy → ETH amount (e.g. '0.01'). For direction=sell → GBLIN amount (e.g. '5.0')."),
|
|
104
|
+
});
|
|
105
|
+
export const QUOTE_SAFE_SWAP_DEFINITION = {
|
|
106
|
+
name: "quote_safe_swap",
|
|
107
|
+
description: "Preview a buy (ETH→GBLIN) or sell (GBLIN→ETH) without executing. Returns expected output, safe minOut with dynamic slippage buffer (2.5% normal / 4% during Crash Shield), and fee breakdown. Read-only.",
|
|
108
|
+
inputSchema: {
|
|
109
|
+
type: "object",
|
|
110
|
+
properties: {
|
|
111
|
+
direction: { type: "string", enum: ["buy", "sell"] },
|
|
112
|
+
amount_in: {
|
|
113
|
+
type: "string",
|
|
114
|
+
description: "Positive decimal. ETH for buy, GBLIN for sell.",
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
required: ["direction", "amount_in"],
|
|
118
|
+
additionalProperties: false,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
export async function handleQuoteSafeSwap(args) {
|
|
122
|
+
let parsed;
|
|
123
|
+
try {
|
|
124
|
+
parsed = QuoteSafeSwapSchema.parse(args);
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
return toolError(`Invalid arguments: ${e.message}`);
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
const slippage = await getDynamicSlippage();
|
|
131
|
+
const amountWei = parseUnits(parsed.amount_in, 18);
|
|
132
|
+
if (parsed.direction === "buy") {
|
|
133
|
+
if (amountWei < MIN_DEPOSIT_WEI) {
|
|
134
|
+
return toolError(`DepositTooSmall: minimum buy is ${formatUnits(MIN_DEPOSIT_WEI, 18)} ETH.`, "Increase amount_in or pool buys into batches.");
|
|
135
|
+
}
|
|
136
|
+
const [gblinOut, founderFee, stabFee] = await client.readContract({
|
|
137
|
+
address: GBLIN_V5,
|
|
138
|
+
abi: GBLIN_ABI,
|
|
139
|
+
functionName: "quoteBuyGBLIN",
|
|
140
|
+
args: [amountWei],
|
|
141
|
+
});
|
|
142
|
+
const safeMin = applySlippageBuffer(gblinOut, slippage.bps);
|
|
143
|
+
return toolResult({
|
|
144
|
+
direction: "buy",
|
|
145
|
+
amount_in_eth: parsed.amount_in,
|
|
146
|
+
expected_gblin_out: formatUnits(gblinOut, 18),
|
|
147
|
+
safe_min_gblin_out: formatUnits(safeMin, 18),
|
|
148
|
+
fees: {
|
|
149
|
+
founder_eth: formatUnits(founderFee, 18),
|
|
150
|
+
stability_eth: formatUnits(stabFee, 18),
|
|
151
|
+
total_fee_bps: 10,
|
|
152
|
+
},
|
|
153
|
+
slippage_buffer_bps: Number(slippage.bps),
|
|
154
|
+
slippage_reason: slippage.reason,
|
|
155
|
+
will_revert_with_zero_tolerance: true,
|
|
156
|
+
next_step: "Call contract.buyGBLIN(safe_min_gblin_out) with msg.value = amount_in.",
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
// sell
|
|
160
|
+
const ethOut = await client.readContract({
|
|
161
|
+
address: GBLIN_V5,
|
|
162
|
+
abi: GBLIN_ABI,
|
|
163
|
+
functionName: "quoteSellGBLIN",
|
|
164
|
+
args: [amountWei],
|
|
165
|
+
});
|
|
166
|
+
const safeMin = applySlippageBuffer(ethOut, slippage.bps);
|
|
167
|
+
return toolResult({
|
|
168
|
+
direction: "sell",
|
|
169
|
+
amount_in_gblin: parsed.amount_in,
|
|
170
|
+
expected_eth_out: formatUnits(ethOut, 18),
|
|
171
|
+
safe_min_eth_out: formatUnits(safeMin, 18),
|
|
172
|
+
slippage_buffer_bps: Number(slippage.bps),
|
|
173
|
+
slippage_reason: slippage.reason,
|
|
174
|
+
cooldown_note: "Sell reverts with CooldownActive if last buy was <2 min ago. Check via analyze_treasury_health.",
|
|
175
|
+
next_step: "Call contract.sellGBLINForEth(amount_in, safe_min_eth_out).",
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
return toolError(err.message);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
183
|
+
// TOOL 3 — swap_gblin_to_usdc_jit (THE JIT TOOL FOR x402)
|
|
184
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
185
|
+
const JitSwapSchema = z.object({
|
|
186
|
+
usdc_needed: AmountStringSchema.describe("Exact USDC required for the x402 payment (e.g. '0.50')."),
|
|
187
|
+
wallet_address: AddressSchema.describe("The agent's wallet address — used to check cooldown status."),
|
|
188
|
+
});
|
|
189
|
+
export const JIT_SWAP_DEFINITION = {
|
|
190
|
+
name: "swap_gblin_to_usdc_jit",
|
|
191
|
+
description: "Generate ready-to-broadcast calldata that converts GBLIN → USDC in a single atomic transaction via the contract's native sellGBLINForToken function. Works on any wallet (EOA, ERC-4337 smart account, EIP-7702). Use this immediately before paying an x402 invoice.",
|
|
192
|
+
inputSchema: {
|
|
193
|
+
type: "object",
|
|
194
|
+
properties: {
|
|
195
|
+
usdc_needed: { type: "string", description: "USDC amount, decimal string." },
|
|
196
|
+
wallet_address: {
|
|
197
|
+
type: "string",
|
|
198
|
+
description: "Agent's 0x address (for cooldown check).",
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
required: ["usdc_needed", "wallet_address"],
|
|
202
|
+
additionalProperties: false,
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
export async function handleJitSwap(args) {
|
|
206
|
+
let parsed;
|
|
207
|
+
try {
|
|
208
|
+
parsed = JitSwapSchema.parse(args);
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
return toolError(`Invalid arguments: ${e.message}`);
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
// 1. Cooldown check (on-chain block.timestamp, NOT Date.now)
|
|
215
|
+
const cooldown = await checkCooldown(parsed.wallet_address);
|
|
216
|
+
if (cooldown.active) {
|
|
217
|
+
return toolError(`CooldownActive: ${cooldown.secondsRemaining}s remaining until sell is unlocked.`, "The agent recently called buyGBLIN. Wait or use existing USDC reserves.");
|
|
218
|
+
}
|
|
219
|
+
// 2. Reverse quote: how much GBLIN to sell?
|
|
220
|
+
const quote = await quoteGblinForUsdc(parsed.usdc_needed);
|
|
221
|
+
// 3. Build calldata for native atomic swap
|
|
222
|
+
const calldata = encodeFunctionData({
|
|
223
|
+
abi: GBLIN_ABI,
|
|
224
|
+
functionName: "sellGBLINForToken",
|
|
225
|
+
args: [
|
|
226
|
+
quote.gblinToSell,
|
|
227
|
+
USDC,
|
|
228
|
+
WETH_USDC_POOL_FEE,
|
|
229
|
+
quote.minUsdcOut,
|
|
230
|
+
],
|
|
231
|
+
});
|
|
232
|
+
return toolResult({
|
|
233
|
+
action: "single_atomic_tx",
|
|
234
|
+
target_contract: GBLIN_V5,
|
|
235
|
+
calldata,
|
|
236
|
+
value: "0",
|
|
237
|
+
params: {
|
|
238
|
+
gblin_amount: formatUnits(quote.gblinToSell, 18),
|
|
239
|
+
target_token: USDC,
|
|
240
|
+
pool_fee: WETH_USDC_POOL_FEE,
|
|
241
|
+
min_usdc_out: formatUnits(quote.minUsdcOut, 6),
|
|
242
|
+
},
|
|
243
|
+
expected: {
|
|
244
|
+
usdc_out: formatUnits(quote.expectedUsdcOut, 6),
|
|
245
|
+
nav_used_usd: Number(quote.navUsd.toFixed(6)),
|
|
246
|
+
slippage_buffer_pct: quote.slippage.pct,
|
|
247
|
+
slippage_reason: quote.slippage.reason,
|
|
248
|
+
},
|
|
249
|
+
compatibility: {
|
|
250
|
+
eoa: true,
|
|
251
|
+
erc4337: true,
|
|
252
|
+
eip7702: true,
|
|
253
|
+
note: "Single contract call — no batching needed for atomicity.",
|
|
254
|
+
},
|
|
255
|
+
gas_hint: 600_000,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
return toolError(err.message);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
263
|
+
// TOOL 4 — invest_usdc_to_gblin (treasury accumulation)
|
|
264
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
265
|
+
const InvestSchema = z.object({
|
|
266
|
+
usdc_amount: AmountStringSchema,
|
|
267
|
+
});
|
|
268
|
+
export const INVEST_DEFINITION = {
|
|
269
|
+
name: "invest_usdc_to_gblin",
|
|
270
|
+
description: "Generate calldata to convert USDC earnings into GBLIN (treasury accumulation). Returns two sequential steps: (1) approve USDC, (2) call buyGBLINWithToken. Includes properly-quoted minOut values to prevent MEV sandwich attacks — never accepts 0 minOut.",
|
|
271
|
+
inputSchema: {
|
|
272
|
+
type: "object",
|
|
273
|
+
properties: {
|
|
274
|
+
usdc_amount: {
|
|
275
|
+
type: "string",
|
|
276
|
+
description: "USDC amount to invest (decimal string).",
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
required: ["usdc_amount"],
|
|
280
|
+
additionalProperties: false,
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
export async function handleInvest(args) {
|
|
284
|
+
let parsed;
|
|
285
|
+
try {
|
|
286
|
+
parsed = InvestSchema.parse(args);
|
|
287
|
+
}
|
|
288
|
+
catch (e) {
|
|
289
|
+
return toolError(`Invalid arguments: ${e.message}`);
|
|
290
|
+
}
|
|
291
|
+
try {
|
|
292
|
+
const usdcUnits = parseUnits(parsed.usdc_amount, 6);
|
|
293
|
+
if (usdcUnits === 0n) {
|
|
294
|
+
return toolError("usdc_amount must be > 0.");
|
|
295
|
+
}
|
|
296
|
+
const [ethPriceUsd, slippage] = await Promise.all([
|
|
297
|
+
getEthPriceUsd(),
|
|
298
|
+
getDynamicSlippage(),
|
|
299
|
+
]);
|
|
300
|
+
// Step 1: estimate WETH out from USDC via oracle price.
|
|
301
|
+
// usdc_decimal_units / ethPriceUsd ≈ ETH
|
|
302
|
+
// Convert: (usdcUnits * 1e18) / (ethPriceUsd * 1e6)
|
|
303
|
+
const ethPriceScaled = BigInt(Math.round(ethPriceUsd * 1_000_000)); // 6 decimals
|
|
304
|
+
const wethExpected = (usdcUnits * parseUnits("1", 18)) / ethPriceScaled;
|
|
305
|
+
const minWethOut = applySlippageBuffer(wethExpected, slippage.bps);
|
|
306
|
+
if (minWethOut < MIN_DEPOSIT_WEI) {
|
|
307
|
+
return toolError(`DepositTooSmall: ${parsed.usdc_amount} USDC converts to ~${formatUnits(wethExpected, 18)} WETH, below contract minimum of ${formatUnits(MIN_DEPOSIT_WEI, 18)} ETH.`, "Aggregate more USDC before investing.");
|
|
308
|
+
}
|
|
309
|
+
// Step 2: quote GBLIN out from the contract using the min WETH amount.
|
|
310
|
+
const [gblinExpected] = await client.readContract({
|
|
311
|
+
address: GBLIN_V5,
|
|
312
|
+
abi: GBLIN_ABI,
|
|
313
|
+
functionName: "quoteBuyGBLIN",
|
|
314
|
+
args: [minWethOut],
|
|
315
|
+
});
|
|
316
|
+
const minGblinOut = applySlippageBuffer(gblinExpected, slippage.bps);
|
|
317
|
+
// Uniswap V3 path encoding: USDC → (fee=500) → WETH
|
|
318
|
+
const path = encodePacked(["address", "uint24", "address"], [USDC, WETH_USDC_POOL_FEE, WETH]);
|
|
319
|
+
const approveCalldata = encodeFunctionData({
|
|
320
|
+
abi: ERC20_ABI,
|
|
321
|
+
functionName: "approve",
|
|
322
|
+
args: [GBLIN_V5, usdcUnits],
|
|
323
|
+
});
|
|
324
|
+
const buyCalldata = encodeFunctionData({
|
|
325
|
+
abi: GBLIN_ABI,
|
|
326
|
+
functionName: "buyGBLINWithToken",
|
|
327
|
+
args: [path, usdcUnits, minWethOut, minGblinOut],
|
|
328
|
+
});
|
|
329
|
+
return toolResult({
|
|
330
|
+
action: "sequential_txs",
|
|
331
|
+
steps: [
|
|
332
|
+
{
|
|
333
|
+
step: 1,
|
|
334
|
+
description: "Approve GBLIN contract to spend USDC",
|
|
335
|
+
target: USDC,
|
|
336
|
+
calldata: approveCalldata,
|
|
337
|
+
value: "0",
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
step: 2,
|
|
341
|
+
description: "Buy GBLIN with USDC via native contract function",
|
|
342
|
+
target: GBLIN_V5,
|
|
343
|
+
calldata: buyCalldata,
|
|
344
|
+
value: "0",
|
|
345
|
+
},
|
|
346
|
+
],
|
|
347
|
+
expected: {
|
|
348
|
+
usdc_in: parsed.usdc_amount,
|
|
349
|
+
weth_min: formatUnits(minWethOut, 18),
|
|
350
|
+
gblin_min: formatUnits(minGblinOut, 18),
|
|
351
|
+
slippage_buffer_pct: slippage.pct,
|
|
352
|
+
},
|
|
353
|
+
security: {
|
|
354
|
+
mev_protected: true,
|
|
355
|
+
min_outs_set: true,
|
|
356
|
+
note: "minWethOut and minGblinOut are both > 0, computed from on-chain quotes + dynamic slippage. Reverts on bad execution.",
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
catch (err) {
|
|
361
|
+
return toolError(err.message);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
365
|
+
// TOOL 5 — analyze_treasury_health
|
|
366
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
367
|
+
const AnalyzeSchema = z.object({
|
|
368
|
+
wallet_address: AddressSchema,
|
|
369
|
+
daily_burn_usd: z
|
|
370
|
+
.number()
|
|
371
|
+
.nonnegative()
|
|
372
|
+
.optional()
|
|
373
|
+
.describe("Optional: agent's average daily API spend in USD. Enables runway estimate."),
|
|
374
|
+
});
|
|
375
|
+
export const ANALYZE_TREASURY_DEFINITION = {
|
|
376
|
+
name: "analyze_treasury_health",
|
|
377
|
+
description: "Analyze an agent wallet's treasury health: GBLIN/USDC/ETH balances, gas runway, and (if daily_burn_usd provided) days of operational runway plus rebalance recommendation. Critical for autonomous decision-making.",
|
|
378
|
+
inputSchema: {
|
|
379
|
+
type: "object",
|
|
380
|
+
properties: {
|
|
381
|
+
wallet_address: { type: "string", description: "Agent's 0x address." },
|
|
382
|
+
daily_burn_usd: {
|
|
383
|
+
type: "number",
|
|
384
|
+
description: "Optional. Average daily spend in USD (e.g. 1.5).",
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
required: ["wallet_address"],
|
|
388
|
+
additionalProperties: false,
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
export async function handleAnalyzeTreasury(args) {
|
|
392
|
+
let parsed;
|
|
393
|
+
try {
|
|
394
|
+
parsed = AnalyzeSchema.parse(args);
|
|
395
|
+
}
|
|
396
|
+
catch (e) {
|
|
397
|
+
return toolError(`Invalid arguments: ${e.message}`);
|
|
398
|
+
}
|
|
399
|
+
try {
|
|
400
|
+
const [balances, cooldown] = await Promise.all([
|
|
401
|
+
getWalletBalances(parsed.wallet_address),
|
|
402
|
+
checkCooldown(parsed.wallet_address),
|
|
403
|
+
]);
|
|
404
|
+
const ethBalanceNum = Number(balances.ethFormatted);
|
|
405
|
+
const gasHealth = ethBalanceNum >= 0.001
|
|
406
|
+
? "sufficient"
|
|
407
|
+
: ethBalanceNum >= 0.0003
|
|
408
|
+
? "low"
|
|
409
|
+
: "critical";
|
|
410
|
+
const usdcNum = Number(balances.usdcFormatted);
|
|
411
|
+
const gblinPct = balances.totalUsd > 0
|
|
412
|
+
? (balances.gblinValueUsd / balances.totalUsd) * 100
|
|
413
|
+
: 0;
|
|
414
|
+
const usdcPct = balances.totalUsd > 0 ? (usdcNum / balances.totalUsd) * 100 : 0;
|
|
415
|
+
// Strategy presets:
|
|
416
|
+
// high burn (> $2/day) → conservative 70/30
|
|
417
|
+
// low burn (≤ $2/day) → aggressive 90/10
|
|
418
|
+
let recommendation = {
|
|
419
|
+
target_gblin_pct: 90,
|
|
420
|
+
target_usdc_pct: 10,
|
|
421
|
+
action: "hold",
|
|
422
|
+
runway_days: null,
|
|
423
|
+
reasoning: "No daily_burn_usd provided. Default preset is aggressive 90/10.",
|
|
424
|
+
};
|
|
425
|
+
if (parsed.daily_burn_usd !== undefined && parsed.daily_burn_usd > 0) {
|
|
426
|
+
const highBurn = parsed.daily_burn_usd > 2;
|
|
427
|
+
const targetGblin = highBurn ? 70 : 90;
|
|
428
|
+
const targetUsdc = highBurn ? 30 : 10;
|
|
429
|
+
const runwayDays = Math.floor(usdcNum / parsed.daily_burn_usd);
|
|
430
|
+
let action = "hold";
|
|
431
|
+
if (usdcPct < targetUsdc - 5)
|
|
432
|
+
action = "rebalance_to_usdc";
|
|
433
|
+
else if (usdcPct > targetUsdc + 10)
|
|
434
|
+
action = "rebalance_to_gblin";
|
|
435
|
+
recommendation = {
|
|
436
|
+
target_gblin_pct: targetGblin,
|
|
437
|
+
target_usdc_pct: targetUsdc,
|
|
438
|
+
action,
|
|
439
|
+
runway_days: runwayDays,
|
|
440
|
+
reasoning: highBurn
|
|
441
|
+
? `High burn rate ($${parsed.daily_burn_usd}/day): hold larger USDC buffer (30%) to avoid forced GBLIN liquidations during market stress.`
|
|
442
|
+
: `Low burn rate ($${parsed.daily_burn_usd}/day): maximize GBLIN exposure (90%) for treasury yield. JIT-swap on demand.`,
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
return toolResult({
|
|
446
|
+
wallet: parsed.wallet_address,
|
|
447
|
+
balances: {
|
|
448
|
+
gblin: balances.gblinFormatted,
|
|
449
|
+
gblin_value_usd: Number(balances.gblinValueUsd.toFixed(4)),
|
|
450
|
+
usdc: balances.usdcFormatted,
|
|
451
|
+
eth: balances.ethFormatted,
|
|
452
|
+
eth_value_usd: Number(balances.ethValueUsd.toFixed(4)),
|
|
453
|
+
total_usd: Number(balances.totalUsd.toFixed(4)),
|
|
454
|
+
},
|
|
455
|
+
ratios: {
|
|
456
|
+
gblin_pct: Number(gblinPct.toFixed(2)),
|
|
457
|
+
usdc_pct: Number(usdcPct.toFixed(2)),
|
|
458
|
+
},
|
|
459
|
+
gas_health: {
|
|
460
|
+
status: gasHealth,
|
|
461
|
+
eth_balance: balances.ethFormatted,
|
|
462
|
+
warning: gasHealth === "critical"
|
|
463
|
+
? "ETH below 0.0003 — JIT swaps will likely fail due to insufficient gas. Top up immediately."
|
|
464
|
+
: gasHealth === "low"
|
|
465
|
+
? "ETH between 0.0003 and 0.001 — limited gas headroom."
|
|
466
|
+
: null,
|
|
467
|
+
},
|
|
468
|
+
cooldown: {
|
|
469
|
+
active: cooldown.active,
|
|
470
|
+
seconds_remaining: cooldown.secondsRemaining,
|
|
471
|
+
last_deposit_unix: cooldown.lastDeposit,
|
|
472
|
+
},
|
|
473
|
+
recommendation,
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
catch (err) {
|
|
477
|
+
return toolError(err.message);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
481
|
+
// REGISTRY
|
|
482
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
483
|
+
export const TOOL_DEFINITIONS = [
|
|
484
|
+
GET_TREASURY_STATE_DEFINITION,
|
|
485
|
+
QUOTE_SAFE_SWAP_DEFINITION,
|
|
486
|
+
JIT_SWAP_DEFINITION,
|
|
487
|
+
INVEST_DEFINITION,
|
|
488
|
+
ANALYZE_TREASURY_DEFINITION,
|
|
489
|
+
];
|
|
490
|
+
export const TOOL_HANDLERS = {
|
|
491
|
+
get_treasury_state: handleGetTreasuryState,
|
|
492
|
+
quote_safe_swap: handleQuoteSafeSwap,
|
|
493
|
+
swap_gblin_to_usdc_jit: handleJitSwap,
|
|
494
|
+
invest_usdc_to_gblin: handleInvest,
|
|
495
|
+
analyze_treasury_health: handleAnalyzeTreasury,
|
|
496
|
+
};
|
|
497
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,UAAU,EACV,SAAS,EACT,UAAU,GACX,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,QAAQ,EACR,eAAe,EACf,IAAI,EACJ,IAAI,EACJ,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E,MAAM,aAAa,GAAG,CAAC;KACpB,MAAM,EAAE;KACR,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO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