@andrewkimjoseph/celina-sdk 0.4.12 → 0.5.1
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/README.md +4 -0
- package/build/tools/catalog.d.ts +9 -0
- package/build/tools/catalog.js +36 -0
- package/build/tools/catalog.js.map +1 -0
- package/build/tools/domains/aave.d.ts +2 -0
- package/build/tools/domains/aave.js +89 -0
- package/build/tools/domains/aave.js.map +1 -0
- package/build/tools/domains/blockchain.d.ts +2 -0
- package/build/tools/domains/blockchain.js +85 -0
- package/build/tools/domains/blockchain.js.map +1 -0
- package/build/tools/domains/carbon.d.ts +2 -0
- package/build/tools/domains/carbon.js +187 -0
- package/build/tools/domains/carbon.js.map +1 -0
- package/build/tools/domains/celeste.d.ts +2 -0
- package/build/tools/domains/celeste.js +42 -0
- package/build/tools/domains/celeste.js.map +1 -0
- package/build/tools/domains/contract.d.ts +2 -0
- package/build/tools/domains/contract.js +67 -0
- package/build/tools/domains/contract.js.map +1 -0
- package/build/tools/domains/ens.d.ts +2 -0
- package/build/tools/domains/ens.js +16 -0
- package/build/tools/domains/ens.js.map +1 -0
- package/build/tools/domains/gooddollar.d.ts +2 -0
- package/build/tools/domains/gooddollar.js +73 -0
- package/build/tools/domains/gooddollar.js.map +1 -0
- package/build/tools/domains/governance.d.ts +2 -0
- package/build/tools/domains/governance.js +41 -0
- package/build/tools/domains/governance.js.map +1 -0
- package/build/tools/domains/index.d.ts +1 -0
- package/build/tools/domains/index.js +33 -0
- package/build/tools/domains/index.js.map +1 -0
- package/build/tools/domains/mento-fx.d.ts +2 -0
- package/build/tools/domains/mento-fx.js +72 -0
- package/build/tools/domains/mento-fx.js.map +1 -0
- package/build/tools/domains/nft.d.ts +2 -0
- package/build/tools/domains/nft.js +38 -0
- package/build/tools/domains/nft.js.map +1 -0
- package/build/tools/domains/self.d.ts +2 -0
- package/build/tools/domains/self.js +194 -0
- package/build/tools/domains/self.js.map +1 -0
- package/build/tools/domains/staking.d.ts +2 -0
- package/build/tools/domains/staking.js +74 -0
- package/build/tools/domains/staking.js.map +1 -0
- package/build/tools/domains/token.d.ts +2 -0
- package/build/tools/domains/token.js +73 -0
- package/build/tools/domains/token.js.map +1 -0
- package/build/tools/domains/transaction.d.ts +2 -0
- package/build/tools/domains/transaction.js +117 -0
- package/build/tools/domains/transaction.js.map +1 -0
- package/build/tools/domains/uniswap.d.ts +2 -0
- package/build/tools/domains/uniswap.js +72 -0
- package/build/tools/domains/uniswap.js.map +1 -0
- package/build/tools/filter.d.ts +2 -0
- package/build/tools/filter.js +28 -0
- package/build/tools/filter.js.map +1 -0
- package/build/tools/index.d.ts +7 -0
- package/build/tools/index.js +7 -0
- package/build/tools/index.js.map +1 -0
- package/build/tools/schemas/common.d.ts +110 -0
- package/build/tools/schemas/common.js +81 -0
- package/build/tools/schemas/common.js.map +1 -0
- package/build/tools/swap-routing.d.ts +24 -0
- package/build/tools/swap-routing.js +105 -0
- package/build/tools/swap-routing.js.map +1 -0
- package/build/tools/types.d.ts +134 -0
- package/build/tools/types.js +2 -0
- package/build/tools/types.js.map +1 -0
- package/build/tools/utils/carbon-prepare-handler.d.ts +6 -0
- package/build/tools/utils/carbon-prepare-handler.js +17 -0
- package/build/tools/utils/carbon-prepare-handler.js.map +1 -0
- package/build/tools/utils/normalize-token.d.ts +2 -0
- package/build/tools/utils/normalize-token.js +12 -0
- package/build/tools/utils/normalize-token.js.map +1 -0
- package/build/tools/utils/wallet.d.ts +2 -0
- package/build/tools/utils/wallet.js +4 -0
- package/build/tools/utils/wallet.js.map +1 -0
- package/package.json +7 -1
- package/tests/README.md +4 -0
- package/tests/catalog/operations.ts +11 -1
- package/tests/testing-entry.ts +5 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
function parseExpectedOut(value) {
|
|
2
|
+
const n = Number(value.replace(/,/g, ""));
|
|
3
|
+
return Number.isFinite(n) ? n : 0;
|
|
4
|
+
}
|
|
5
|
+
function isMentoRouteError(message) {
|
|
6
|
+
return /no mento fx route|mento fx market is currently closed/i.test(message);
|
|
7
|
+
}
|
|
8
|
+
function isUniswapRouteError(message) {
|
|
9
|
+
return /no uniswap v4 route|insufficient liquidity in uniswap v4/i.test(message);
|
|
10
|
+
}
|
|
11
|
+
function isInsufficientBalanceError(message) {
|
|
12
|
+
return /insufficient .+ balance/i.test(message);
|
|
13
|
+
}
|
|
14
|
+
function rejectionMessage(reason) {
|
|
15
|
+
return reason instanceof Error ? reason.message : String(reason);
|
|
16
|
+
}
|
|
17
|
+
async function tryMentoQuote(celina, tokenIn, tokenOut, amount, from) {
|
|
18
|
+
const quote = await celina.mentoFx.getFxQuote(tokenIn, tokenOut, amount, from);
|
|
19
|
+
return {
|
|
20
|
+
protocol: "mento_fx",
|
|
21
|
+
tokenIn: quote.tokenIn,
|
|
22
|
+
tokenOut: quote.tokenOut,
|
|
23
|
+
amountIn: quote.amountIn,
|
|
24
|
+
expectedOut: quote.expectedOut,
|
|
25
|
+
routeHops: quote.routeHops,
|
|
26
|
+
network: quote.network,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async function tryUniswapQuote(celina, tokenIn, tokenOut, amount, from) {
|
|
30
|
+
const quote = await celina.uniswap.getSwapQuote(tokenIn, tokenOut, amount, from);
|
|
31
|
+
return {
|
|
32
|
+
protocol: "uniswap_v4",
|
|
33
|
+
tokenIn: quote.tokenIn,
|
|
34
|
+
tokenOut: quote.tokenOut,
|
|
35
|
+
amountIn: quote.amountIn,
|
|
36
|
+
expectedOut: quote.expectedOut,
|
|
37
|
+
routeHops: quote.routeHops,
|
|
38
|
+
network: quote.network,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Quote a swap across Mento FX and Uniswap v4; returns the best available route. */
|
|
42
|
+
export async function getSwapQuoteWithFallback(celina, tokenIn, tokenOut, amount, from) {
|
|
43
|
+
const [mentoResult, uniswapResult] = await Promise.allSettled([
|
|
44
|
+
tryMentoQuote(celina, tokenIn, tokenOut, amount, from),
|
|
45
|
+
tryUniswapQuote(celina, tokenIn, tokenOut, amount, from),
|
|
46
|
+
]);
|
|
47
|
+
const successes = [];
|
|
48
|
+
const alternatives = [];
|
|
49
|
+
if (mentoResult.status === "fulfilled") {
|
|
50
|
+
successes.push(mentoResult.value);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const message = rejectionMessage(mentoResult.reason);
|
|
54
|
+
if (!isMentoRouteError(message)) {
|
|
55
|
+
alternatives.push({ protocol: "mento_fx", expectedOut: "0", error: message });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (uniswapResult.status === "fulfilled") {
|
|
59
|
+
successes.push(uniswapResult.value);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const message = rejectionMessage(uniswapResult.reason);
|
|
63
|
+
if (!isUniswapRouteError(message)) {
|
|
64
|
+
alternatives.push({ protocol: "uniswap_v4", expectedOut: "0", error: message });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (successes.length === 0) {
|
|
68
|
+
const failures = [mentoResult, uniswapResult]
|
|
69
|
+
.filter((result) => result.status === "rejected")
|
|
70
|
+
.map((result) => rejectionMessage(result.reason));
|
|
71
|
+
const balanceError = failures.find(isInsufficientBalanceError);
|
|
72
|
+
if (balanceError) {
|
|
73
|
+
throw new Error(balanceError);
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`No swap route for ${tokenIn} → ${tokenOut} via Mento FX or Uniswap v4.`);
|
|
76
|
+
}
|
|
77
|
+
successes.sort((a, b) => parseExpectedOut(b.expectedOut) - parseExpectedOut(a.expectedOut));
|
|
78
|
+
const best = successes[0];
|
|
79
|
+
const otherProtocols = successes.slice(1).map((q) => ({
|
|
80
|
+
protocol: q.protocol,
|
|
81
|
+
expectedOut: q.expectedOut,
|
|
82
|
+
}));
|
|
83
|
+
return {
|
|
84
|
+
...best,
|
|
85
|
+
alternatives: otherProtocols.length > 0 ? otherProtocols : alternatives,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export async function prepareSwapWithFallback(celina, from, tokenIn, tokenOut, amount, params, protocol) {
|
|
89
|
+
const chosen = protocol ??
|
|
90
|
+
(await getSwapQuoteWithFallback(celina, tokenIn, tokenOut, amount, from))
|
|
91
|
+
.protocol;
|
|
92
|
+
if (chosen === "mento_fx") {
|
|
93
|
+
return celina.mentoFx.prepareFx(from, tokenIn, tokenOut, amount, {
|
|
94
|
+
recipient: params?.recipient,
|
|
95
|
+
slippageTolerance: params?.slippageTolerance,
|
|
96
|
+
deadlineMinutes: params?.deadlineMinutes,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return celina.uniswap.prepareSwap(from, tokenIn, tokenOut, amount, {
|
|
100
|
+
recipient: params?.recipient,
|
|
101
|
+
slippageTolerance: params?.slippageTolerance,
|
|
102
|
+
deadlineMinutes: params?.deadlineMinutes,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=swap-routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap-routing.js","sourceRoot":"","sources":["../../src/tools/swap-routing.ts"],"names":[],"mappings":"AAyBA,SAAS,gBAAgB,CAAC,KAAa;IACrC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAe;IACxC,OAAO,wDAAwD,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAe;IAC1C,OAAO,2DAA2D,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACnF,CAAC;AAED,SAAS,0BAA0B,CAAC,OAAe;IACjD,OAAO,0BAA0B,CAAC,IAAI,CAAC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IAEvB,MAAM,MAAM,GACV,QAAQ;QACR,CAAC,MAAM,wBAAwB,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;aACtE,QAAQ,CAAC;IAEd,IAAI,MAAM,KAAK,UAAU,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE;YAC/D,SAAS,EAAE,MAAM,EAAE,SAAS;YAC5B,iBAAiB,EAAE,MAAM,EAAE,iBAAiB;YAC5C,eAAe,EAAE,MAAM,EAAE,eAAe;SACzC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE;QACjE,SAAS,EAAE,MAAM,EAAE,SAAS;QAC5B,iBAAiB,EAAE,MAAM,EAAE,iBAAiB;QAC5C,eAAe,EAAE,MAAM,EAAE,eAAe;KACzC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { CelinaClient } from "../index.js";
|
|
3
|
+
import type { CarbonWriteBody } from "../services/carbon.service.js";
|
|
4
|
+
export type ToolSurface = "mcp" | "celeste";
|
|
5
|
+
export type ToolFamily = "read" | "prepare" | "execute";
|
|
6
|
+
export type WalletInput = {
|
|
7
|
+
address?: string;
|
|
8
|
+
wallet_address?: string;
|
|
9
|
+
from?: string;
|
|
10
|
+
};
|
|
11
|
+
export type McpToolAnnotations = {
|
|
12
|
+
readOnlyHint?: boolean;
|
|
13
|
+
idempotentHint?: boolean;
|
|
14
|
+
destructiveHint?: boolean;
|
|
15
|
+
openWorldHint?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type McpToolMeta = {
|
|
18
|
+
title?: string;
|
|
19
|
+
annotations?: McpToolAnnotations;
|
|
20
|
+
/** MCP adapter uses okSelfSession for QR registration flows. */
|
|
21
|
+
responseKind?: "default" | "self_session";
|
|
22
|
+
};
|
|
23
|
+
export type ToolRuntimeHooks = {
|
|
24
|
+
beforePrepareSend?: (params: {
|
|
25
|
+
sender: `0x${string}`;
|
|
26
|
+
token: string;
|
|
27
|
+
amount: string;
|
|
28
|
+
}) => Promise<void>;
|
|
29
|
+
carbon?: {
|
|
30
|
+
validateBody?: (toolName: string, body: CarbonWriteBody) => void;
|
|
31
|
+
prepare?: (toolName: string, sender: `0x${string}`, prepareFn: (body: CarbonWriteBody) => Promise<unknown>, body: CarbonWriteBody, options?: {
|
|
32
|
+
marketPriceFallback?: boolean;
|
|
33
|
+
concentrated?: boolean;
|
|
34
|
+
}) => Promise<unknown>;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export type TransactionExecutors = {
|
|
38
|
+
estimateSend: (to: `0x${string}`, token: string, amount: string) => Promise<unknown>;
|
|
39
|
+
sendToken: (to: `0x${string}`, token: string, amount: string) => Promise<unknown>;
|
|
40
|
+
};
|
|
41
|
+
export type MentoFxExecutors = {
|
|
42
|
+
estimate: (tokenIn: string, tokenOut: string, amount: string, options?: {
|
|
43
|
+
recipient?: `0x${string}`;
|
|
44
|
+
slippageTolerance?: number;
|
|
45
|
+
deadlineMinutes?: number;
|
|
46
|
+
}) => Promise<unknown>;
|
|
47
|
+
execute: (tokenIn: string, tokenOut: string, amount: string, options?: {
|
|
48
|
+
recipient?: `0x${string}`;
|
|
49
|
+
slippageTolerance?: number;
|
|
50
|
+
deadlineMinutes?: number;
|
|
51
|
+
}) => Promise<unknown>;
|
|
52
|
+
};
|
|
53
|
+
export type UniswapExecutors = {
|
|
54
|
+
estimate: (tokenIn: string, tokenOut: string, amount: string, options?: {
|
|
55
|
+
recipient?: `0x${string}`;
|
|
56
|
+
slippageTolerance?: number;
|
|
57
|
+
deadlineMinutes?: number;
|
|
58
|
+
}) => Promise<unknown>;
|
|
59
|
+
execute: (tokenIn: string, tokenOut: string, amount: string, options?: {
|
|
60
|
+
recipient?: `0x${string}`;
|
|
61
|
+
slippageTolerance?: number;
|
|
62
|
+
deadlineMinutes?: number;
|
|
63
|
+
}) => Promise<unknown>;
|
|
64
|
+
};
|
|
65
|
+
export type AaveExecutors = {
|
|
66
|
+
supply: (token: string, amount: string) => Promise<unknown>;
|
|
67
|
+
withdraw: (token: string, amount?: string, withdrawMax?: boolean) => Promise<unknown>;
|
|
68
|
+
};
|
|
69
|
+
export type CarbonWriteExecutors = {
|
|
70
|
+
executeLimitOrder: (body: Record<string, unknown>) => Promise<unknown>;
|
|
71
|
+
executeRangeOrder: (body: Record<string, unknown>) => Promise<unknown>;
|
|
72
|
+
executeRecurringStrategy: (body: Record<string, unknown>) => Promise<unknown>;
|
|
73
|
+
executeConcentratedStrategy: (body: Record<string, unknown>) => Promise<unknown>;
|
|
74
|
+
executeFullRangeStrategy: (body: Record<string, unknown>) => Promise<unknown>;
|
|
75
|
+
executeRepriceStrategy: (body: Record<string, unknown>) => Promise<unknown>;
|
|
76
|
+
executeEditStrategy: (body: Record<string, unknown>) => Promise<unknown>;
|
|
77
|
+
executeDepositBudget: (body: Record<string, unknown>) => Promise<unknown>;
|
|
78
|
+
executeWithdrawBudget: (body: Record<string, unknown>) => Promise<unknown>;
|
|
79
|
+
executePauseStrategy: (body: Record<string, unknown>) => Promise<unknown>;
|
|
80
|
+
executeResumeStrategy: (body: Record<string, unknown>) => Promise<unknown>;
|
|
81
|
+
executeDeleteStrategy: (body: Record<string, unknown>) => Promise<unknown>;
|
|
82
|
+
executeTrade: (body: Record<string, unknown>) => Promise<unknown>;
|
|
83
|
+
};
|
|
84
|
+
export type GoodDollarWriteExecutors = {
|
|
85
|
+
claimDailyUbi: () => Promise<unknown>;
|
|
86
|
+
};
|
|
87
|
+
export type SelfExecutors = {
|
|
88
|
+
verifyAgent: (args: Record<string, unknown>) => Promise<unknown>;
|
|
89
|
+
lookupAgent: (agentId: number) => Promise<unknown>;
|
|
90
|
+
verifyRequest: (args: Record<string, unknown>) => Promise<unknown>;
|
|
91
|
+
registerAgent: (args: Record<string, unknown>) => Promise<unknown>;
|
|
92
|
+
checkRegistration: (sessionId: string) => Promise<unknown>;
|
|
93
|
+
getIdentity: () => Promise<unknown>;
|
|
94
|
+
refreshProof: (args: Record<string, unknown>) => Promise<unknown>;
|
|
95
|
+
deregisterAgent: () => Promise<unknown>;
|
|
96
|
+
signRequest: (args: Record<string, unknown>) => Promise<unknown>;
|
|
97
|
+
authenticatedFetch: (args: Record<string, unknown>) => Promise<unknown>;
|
|
98
|
+
};
|
|
99
|
+
export type ToolRuntimeExecutors = {
|
|
100
|
+
transaction?: TransactionExecutors;
|
|
101
|
+
mentoFx?: MentoFxExecutors;
|
|
102
|
+
uniswap?: UniswapExecutors;
|
|
103
|
+
aave?: AaveExecutors;
|
|
104
|
+
carbonWrite?: CarbonWriteExecutors;
|
|
105
|
+
gooddollarWrite?: GoodDollarWriteExecutors;
|
|
106
|
+
self?: SelfExecutors;
|
|
107
|
+
};
|
|
108
|
+
export interface ToolRuntime {
|
|
109
|
+
celina: CelinaClient;
|
|
110
|
+
resolveWallet: (input?: WalletInput) => `0x${string}`;
|
|
111
|
+
hooks?: ToolRuntimeHooks;
|
|
112
|
+
executors?: ToolRuntimeExecutors;
|
|
113
|
+
/** MCP session wallet metadata for get_wallet_address. */
|
|
114
|
+
mcpWallet?: {
|
|
115
|
+
address: `0x${string}`;
|
|
116
|
+
hasWallet: boolean;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
export interface ToolDefinition {
|
|
120
|
+
name: string;
|
|
121
|
+
description: string;
|
|
122
|
+
inputSchema: z.ZodTypeAny;
|
|
123
|
+
families: ToolFamily[];
|
|
124
|
+
surfaces?: ToolSurface[];
|
|
125
|
+
mcp?: McpToolMeta;
|
|
126
|
+
handler: (runtime: ToolRuntime, input: Record<string, unknown>) => Promise<unknown>;
|
|
127
|
+
}
|
|
128
|
+
export type FilterToolsOptions = {
|
|
129
|
+
surface?: ToolSurface;
|
|
130
|
+
families?: ToolFamily[];
|
|
131
|
+
names?: string[];
|
|
132
|
+
carbonPrepareEnabled?: boolean;
|
|
133
|
+
carbonExecuteEnabled?: boolean;
|
|
134
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CarbonWriteBody } from "../../services/carbon.service.js";
|
|
2
|
+
import type { ToolRuntime } from "../types.js";
|
|
3
|
+
export declare function runCarbonPrepare(runtime: ToolRuntime, toolName: string, prepareFn: (body: CarbonWriteBody) => Promise<unknown>, input: Record<string, unknown>, options?: {
|
|
4
|
+
marketPriceFallback?: boolean;
|
|
5
|
+
concentrated?: boolean;
|
|
6
|
+
}): Promise<unknown>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { finalizeCarbonPrepare } from "../../utils/finalize-carbon-prepare.js";
|
|
2
|
+
import { resolveWalletFromRuntime } from "./wallet.js";
|
|
3
|
+
export async function runCarbonPrepare(runtime, toolName, prepareFn, input, options) {
|
|
4
|
+
const sender = resolveWalletFromRuntime(runtime, {
|
|
5
|
+
wallet_address: input.wallet_address,
|
|
6
|
+
from: input.from,
|
|
7
|
+
});
|
|
8
|
+
const body = { ...input, wallet_address: sender };
|
|
9
|
+
if (runtime.hooks?.carbon?.prepare) {
|
|
10
|
+
return runtime.hooks.carbon.prepare(toolName, sender, prepareFn, body, options);
|
|
11
|
+
}
|
|
12
|
+
runtime.hooks?.carbon?.validateBody?.(toolName, body);
|
|
13
|
+
const prepared = await prepareFn(body);
|
|
14
|
+
const preparedFlow = await finalizeCarbonPrepare(runtime.celina.carbon, sender, prepared, body);
|
|
15
|
+
return { ...prepared, preparedFlow };
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=carbon-prepare-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carbon-prepare-handler.js","sourceRoot":"","sources":["../../../src/tools/utils/carbon-prepare-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAoB,EACpB,QAAgB,EAChB,SAAsD,EACtD,KAA8B,EAC9B,OAAmE;IAEnE,MAAM,MAAM,GAAG,wBAAwB,CAAC,OAAO,EAAE;QAC/C,cAAc,EAAE,KAAK,CAAC,cAAoC;QAC1D,IAAI,EAAE,KAAK,CAAC,IAA0B;KACvC,CAAC,CAAC;IACH,MAAM,IAAI,GAAG,EAAE,GAAG,KAAK,EAAE,cAAc,EAAE,MAAM,EAAqB,CAAC;IAErE,IAAI,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;QACnC,OAAO,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAClF,CAAC;IAED,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACtD,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,YAAY,GAAG,MAAM,qBAAqB,CAC9C,OAAO,CAAC,MAAM,CAAC,MAAM,EACrB,MAAM,EACN,QAAuD,EACvD,IAAI,CACL,CAAC;IACF,OAAO,EAAE,GAAI,QAAmB,EAAE,YAAY,EAAE,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const REGISTRY_ALIASES = {
|
|
2
|
+
GD: "GoodDollar",
|
|
3
|
+
"G$": "GoodDollar",
|
|
4
|
+
GOODDOLLAR: "GoodDollar",
|
|
5
|
+
};
|
|
6
|
+
/** Normalize common LLM token shorthands before registry lookup. */
|
|
7
|
+
export function normalizeRegistryTokenInput(token) {
|
|
8
|
+
const trimmed = token.trim();
|
|
9
|
+
const upper = trimmed.toUpperCase();
|
|
10
|
+
return REGISTRY_ALIASES[upper] ?? REGISTRY_ALIASES[trimmed] ?? trimmed;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=normalize-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-token.js","sourceRoot":"","sources":["../../../src/tools/utils/normalize-token.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAA2B;IAC/C,EAAE,EAAE,YAAY;IAChB,IAAI,EAAE,YAAY;IAClB,UAAU,EAAE,YAAY;CACzB,CAAC;AAEF,oEAAoE;AACpE,MAAM,UAAU,2BAA2B,CAAC,KAAa;IACvD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IACpC,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../../src/tools/utils/wallet.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,wBAAwB,CACtC,OAAoB,EACpB,KAAmB;IAEnB,OAAO,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrewkimjoseph/celina-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Celina SDK — Celo mainnet reads and unsigned transaction preparation for frontend apps.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
"types": "./tests/testing-entry.ts",
|
|
17
17
|
"import": "./tests/testing-entry.ts",
|
|
18
18
|
"default": "./tests/testing-entry.ts"
|
|
19
|
+
},
|
|
20
|
+
"./tools": {
|
|
21
|
+
"types": "./build/tools/index.d.ts",
|
|
22
|
+
"import": "./build/tools/index.js",
|
|
23
|
+
"default": "./build/tools/index.js"
|
|
19
24
|
}
|
|
20
25
|
},
|
|
21
26
|
"files": [
|
|
@@ -69,6 +74,7 @@
|
|
|
69
74
|
},
|
|
70
75
|
"homepage": "https://andrewkimjoseph.gitbook.io/celina-sdk",
|
|
71
76
|
"dependencies": {
|
|
77
|
+
"zod": "^3.24.3",
|
|
72
78
|
"@amplitude/analytics-node": "^1.5.21",
|
|
73
79
|
"@noble/ed25519": "^3.1.0",
|
|
74
80
|
"@bancor/carbon-sdk": "0.0.130-DEV",
|
package/tests/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="../assets/celina-banner.png" alt="Celina — Give your LLM a wallet on Celo">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# Celina operations test framework
|
|
2
6
|
|
|
3
7
|
Live Celo mainnet smoke tests driven by a single operation catalog in `tests/catalog/operations.ts`. Add one `OperationSpec` when you ship a new SDK method or MCP tool.
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from "./domains/chain-ext.js";
|
|
17
17
|
import { selfOperations } from "./domains/self.js";
|
|
18
18
|
import { carbonOperations } from "./domains/carbon.js";
|
|
19
|
+
import { getMcpToolNames } from "../../src/tools/catalog.js";
|
|
19
20
|
import type { OperationSpec } from "./types.js";
|
|
20
21
|
|
|
21
22
|
export const OPERATIONS: OperationSpec[] = [
|
|
@@ -45,4 +46,13 @@ export const SDK_OPERATIONS = OPERATIONS.filter(
|
|
|
45
46
|
Boolean(spec.sdk),
|
|
46
47
|
);
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
/** MCP tool names from the SDK tools catalog (stdio: prepare + execute Carbon). */
|
|
50
|
+
export const MCP_TOOL_NAMES = getMcpToolNames({
|
|
51
|
+
carbonPrepareEnabled: true,
|
|
52
|
+
carbonExecuteEnabled: true,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/** @deprecated Use MCP_TOOL_NAMES — kept for tests that import the operations-derived list. */
|
|
56
|
+
export const MCP_TOOL_NAMES_FROM_OPERATIONS = MCP_OPERATIONS.map(
|
|
57
|
+
(spec) => spec.mcp.tool,
|
|
58
|
+
);
|
package/tests/testing-entry.ts
CHANGED
|
@@ -9,6 +9,11 @@ export {
|
|
|
9
9
|
OPERATIONS,
|
|
10
10
|
SDK_OPERATIONS,
|
|
11
11
|
} from "./catalog/operations.js";
|
|
12
|
+
export {
|
|
13
|
+
ALL_TOOL_DEFINITIONS,
|
|
14
|
+
getMcpToolNames,
|
|
15
|
+
getCelesteToolNames,
|
|
16
|
+
} from "../src/tools/catalog.js";
|
|
12
17
|
export { getMainnetFixtures, type MainnetFixtures } from "./fixtures/mainnet.js";
|
|
13
18
|
export {
|
|
14
19
|
allowsDestructiveTests,
|