safehands-pharos 1.0.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/.agents/skill/safehands/SKILL.md +169 -0
- package/LICENSE +21 -0
- package/README.md +382 -0
- package/contracts/RiskRegistry.json +149 -0
- package/contracts/RiskRegistry.sol +30 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +98 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/constants.d.ts +173 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +151 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/dodoApi.d.ts +57 -0
- package/dist/lib/dodoApi.d.ts.map +1 -0
- package/dist/lib/dodoApi.js +123 -0
- package/dist/lib/dodoApi.js.map +1 -0
- package/dist/lib/pharosClient.d.ts +58 -0
- package/dist/lib/pharosClient.d.ts.map +1 -0
- package/dist/lib/pharosClient.js +51 -0
- package/dist/lib/pharosClient.js.map +1 -0
- package/dist/lib/riskEngine.d.ts +27 -0
- package/dist/lib/riskEngine.d.ts.map +1 -0
- package/dist/lib/riskEngine.js +284 -0
- package/dist/lib/riskEngine.js.map +1 -0
- package/dist/lib/testRpc.d.ts +2 -0
- package/dist/lib/testRpc.d.ts.map +1 -0
- package/dist/lib/testRpc.js +30 -0
- package/dist/lib/testRpc.js.map +1 -0
- package/dist/lib/testTools.d.ts +2 -0
- package/dist/lib/testTools.d.ts.map +1 -0
- package/dist/lib/testTools.js +263 -0
- package/dist/lib/testTools.js.map +1 -0
- package/dist/scripts/checkDeploy.d.ts +2 -0
- package/dist/scripts/checkDeploy.d.ts.map +1 -0
- package/dist/scripts/checkDeploy.js +25 -0
- package/dist/scripts/checkDeploy.js.map +1 -0
- package/dist/scripts/deployRegistry.d.ts +2 -0
- package/dist/scripts/deployRegistry.d.ts.map +1 -0
- package/dist/scripts/deployRegistry.js +101 -0
- package/dist/scripts/deployRegistry.js.map +1 -0
- package/dist/scripts/testRegistry.d.ts +2 -0
- package/dist/scripts/testRegistry.d.ts.map +1 -0
- package/dist/scripts/testRegistry.js +44 -0
- package/dist/scripts/testRegistry.js.map +1 -0
- package/dist/tools/approveToken.d.ts +60 -0
- package/dist/tools/approveToken.d.ts.map +1 -0
- package/dist/tools/approveToken.js +59 -0
- package/dist/tools/approveToken.js.map +1 -0
- package/dist/tools/assessRisk.d.ts +67 -0
- package/dist/tools/assessRisk.d.ts.map +1 -0
- package/dist/tools/assessRisk.js +71 -0
- package/dist/tools/assessRisk.js.map +1 -0
- package/dist/tools/checkAllowance.d.ts +37 -0
- package/dist/tools/checkAllowance.d.ts.map +1 -0
- package/dist/tools/checkAllowance.js +43 -0
- package/dist/tools/checkAllowance.js.map +1 -0
- package/dist/tools/estimateGas.d.ts +70 -0
- package/dist/tools/estimateGas.d.ts.map +1 -0
- package/dist/tools/estimateGas.js +129 -0
- package/dist/tools/estimateGas.js.map +1 -0
- package/dist/tools/executeSwap.d.ts +94 -0
- package/dist/tools/executeSwap.d.ts.map +1 -0
- package/dist/tools/executeSwap.js +107 -0
- package/dist/tools/executeSwap.js.map +1 -0
- package/dist/tools/getExecutionHistory.d.ts +52 -0
- package/dist/tools/getExecutionHistory.d.ts.map +1 -0
- package/dist/tools/getExecutionHistory.js +94 -0
- package/dist/tools/getExecutionHistory.js.map +1 -0
- package/dist/tools/getGasPrice.d.ts +26 -0
- package/dist/tools/getGasPrice.d.ts.map +1 -0
- package/dist/tools/getGasPrice.js +52 -0
- package/dist/tools/getGasPrice.js.map +1 -0
- package/dist/tools/getPoolInfo.d.ts +88 -0
- package/dist/tools/getPoolInfo.d.ts.map +1 -0
- package/dist/tools/getPoolInfo.js +99 -0
- package/dist/tools/getPoolInfo.js.map +1 -0
- package/dist/tools/getTokenPrice.d.ts +28 -0
- package/dist/tools/getTokenPrice.d.ts.map +1 -0
- package/dist/tools/getTokenPrice.js +79 -0
- package/dist/tools/getTokenPrice.js.map +1 -0
- package/dist/tools/getTransactionStatus.d.ts +58 -0
- package/dist/tools/getTransactionStatus.d.ts.map +1 -0
- package/dist/tools/getTransactionStatus.js +68 -0
- package/dist/tools/getTransactionStatus.js.map +1 -0
- package/dist/tools/getWalletBalance.d.ts +40 -0
- package/dist/tools/getWalletBalance.d.ts.map +1 -0
- package/dist/tools/getWalletBalance.js +71 -0
- package/dist/tools/getWalletBalance.js.map +1 -0
- package/dist/tools/publishRiskScore.d.ts +74 -0
- package/dist/tools/publishRiskScore.d.ts.map +1 -0
- package/dist/tools/publishRiskScore.js +70 -0
- package/dist/tools/publishRiskScore.js.map +1 -0
- package/dist/tools/queryRiskRegistry.d.ts +49 -0
- package/dist/tools/queryRiskRegistry.d.ts.map +1 -0
- package/dist/tools/queryRiskRegistry.js +61 -0
- package/dist/tools/queryRiskRegistry.js.map +1 -0
- package/dist/tools/sendPayment.d.ts +70 -0
- package/dist/tools/sendPayment.d.ts.map +1 -0
- package/dist/tools/sendPayment.js +68 -0
- package/dist/tools/sendPayment.js.map +1 -0
- package/dist/tools/simulateTransaction.d.ts +82 -0
- package/dist/tools/simulateTransaction.d.ts.map +1 -0
- package/dist/tools/simulateTransaction.js +89 -0
- package/dist/tools/simulateTransaction.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// ─── Tool: approve_token ───────────────────────────────────────────────
|
|
2
|
+
// Approves ERC-20 token spending for DODO swap router.
|
|
3
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { publicClient, createPharosWalletClient, getExplorerUrl } from "../lib/pharosClient.js";
|
|
6
|
+
import { DODO_APPROVE_ADDRESS, USDC_ADDRESS, USDT_ADDRESS, ERC20_ABI } from "../lib/constants.js";
|
|
7
|
+
import { resolveTokenDecimals, toWei } from "../lib/dodoApi.js";
|
|
8
|
+
export const approveTokenSchema = z.object({
|
|
9
|
+
walletAddress: z.string().describe("Wallet address granting the approval"),
|
|
10
|
+
token: z.enum(["USDC", "USDT"]).describe("ERC-20 token to approve"),
|
|
11
|
+
amount: z.string().describe("Human-readable amount to approve, or 'max' for unlimited"),
|
|
12
|
+
privateKey: z.string().describe("Private key to sign the approval transaction"),
|
|
13
|
+
});
|
|
14
|
+
export const approveTokenTool = {
|
|
15
|
+
name: "approve_token",
|
|
16
|
+
description: "Approve ERC-20 token spending for FaroSwap (DODO) router. Required before swapping non-native tokens.",
|
|
17
|
+
inputSchema: approveTokenSchema,
|
|
18
|
+
};
|
|
19
|
+
export async function handleApproveToken(raw) {
|
|
20
|
+
const input = approveTokenSchema.parse(raw);
|
|
21
|
+
const tokenAddress = input.token === "USDC" ? USDC_ADDRESS : USDT_ADDRESS;
|
|
22
|
+
const decimals = resolveTokenDecimals(input.token);
|
|
23
|
+
const approveAmount = input.amount === "max"
|
|
24
|
+
? 2n ** 256n - 1n // type(uint256).max
|
|
25
|
+
: BigInt(toWei(input.amount, decimals));
|
|
26
|
+
try {
|
|
27
|
+
const wallet = createPharosWalletClient(input.privateKey);
|
|
28
|
+
const txHash = await wallet.writeContract({
|
|
29
|
+
address: tokenAddress,
|
|
30
|
+
abi: ERC20_ABI,
|
|
31
|
+
functionName: "approve",
|
|
32
|
+
args: [DODO_APPROVE_ADDRESS, approveAmount],
|
|
33
|
+
});
|
|
34
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash });
|
|
35
|
+
return {
|
|
36
|
+
success: receipt.status === "success",
|
|
37
|
+
txHash,
|
|
38
|
+
explorerUrl: getExplorerUrl(txHash),
|
|
39
|
+
token: input.token,
|
|
40
|
+
tokenAddress,
|
|
41
|
+
approvedAmount: input.amount === "max" ? "unlimited" : input.amount,
|
|
42
|
+
spender: DODO_APPROVE_ADDRESS,
|
|
43
|
+
gasUsed: receipt.gasUsed.toString(),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
txHash: null,
|
|
50
|
+
explorerUrl: null,
|
|
51
|
+
token: input.token,
|
|
52
|
+
tokenAddress,
|
|
53
|
+
approvedAmount: null,
|
|
54
|
+
spender: DODO_APPROVE_ADDRESS,
|
|
55
|
+
error: `Approval failed: ${err.message}`,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=approveToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approveToken.js","sourceRoot":"","sources":["../../src/tools/approveToken.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,uDAAuD;AACvD,2EAA2E;AAE3E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAClG,OAAO,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEhE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sCAAsC,CAAC;IAC1E,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,yBAAyB,CAAC;IACnE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,0DAA0D,CAAC;IACvF,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8CAA8C,CAAC;CAChF,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,eAAe;IACrB,WAAW,EACT,uGAAuG;IACzG,WAAW,EAAE,kBAAkB;CAChC,CAAC;AAEF,MAAM,CAAC,KAAK,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C;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,IAAI;YACZ,WAAW,EAAE,IAAI;YACjB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,YAAY;YACZ,cAAc,EAAE,IAAI;YACpB,OAAO,EAAE,oBAAoB;YAC7B,KAAK,EAAE,oBAAqB,GAAa,CAAC,OAAO,EAAE;SACpD,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type RiskAssessment } from "../lib/riskEngine.js";
|
|
3
|
+
export declare const assessRiskSchema: z.ZodObject<{
|
|
4
|
+
action: z.ZodEnum<["swap", "transfer"]>;
|
|
5
|
+
tokenIn: z.ZodOptional<z.ZodString>;
|
|
6
|
+
tokenOut: z.ZodOptional<z.ZodString>;
|
|
7
|
+
amount: z.ZodString;
|
|
8
|
+
toAddress: z.ZodOptional<z.ZodString>;
|
|
9
|
+
walletAddress: z.ZodString;
|
|
10
|
+
privateKey: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
amount: string;
|
|
13
|
+
action: "transfer" | "swap";
|
|
14
|
+
walletAddress: string;
|
|
15
|
+
privateKey?: string | undefined;
|
|
16
|
+
tokenIn?: string | undefined;
|
|
17
|
+
tokenOut?: string | undefined;
|
|
18
|
+
toAddress?: string | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
amount: string;
|
|
21
|
+
action: "transfer" | "swap";
|
|
22
|
+
walletAddress: string;
|
|
23
|
+
privateKey?: string | undefined;
|
|
24
|
+
tokenIn?: string | undefined;
|
|
25
|
+
tokenOut?: string | undefined;
|
|
26
|
+
toAddress?: string | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
export type AssessRiskInput = z.input<typeof assessRiskSchema>;
|
|
29
|
+
export interface AssessRiskResult extends RiskAssessment {
|
|
30
|
+
registryPublish?: {
|
|
31
|
+
published: boolean;
|
|
32
|
+
txHash?: string;
|
|
33
|
+
explorerUrl?: string;
|
|
34
|
+
error?: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export declare const assessRiskTool: {
|
|
38
|
+
name: string;
|
|
39
|
+
description: string;
|
|
40
|
+
inputSchema: z.ZodObject<{
|
|
41
|
+
action: z.ZodEnum<["swap", "transfer"]>;
|
|
42
|
+
tokenIn: z.ZodOptional<z.ZodString>;
|
|
43
|
+
tokenOut: z.ZodOptional<z.ZodString>;
|
|
44
|
+
amount: z.ZodString;
|
|
45
|
+
toAddress: z.ZodOptional<z.ZodString>;
|
|
46
|
+
walletAddress: z.ZodString;
|
|
47
|
+
privateKey: z.ZodOptional<z.ZodString>;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
amount: string;
|
|
50
|
+
action: "transfer" | "swap";
|
|
51
|
+
walletAddress: string;
|
|
52
|
+
privateKey?: string | undefined;
|
|
53
|
+
tokenIn?: string | undefined;
|
|
54
|
+
tokenOut?: string | undefined;
|
|
55
|
+
toAddress?: string | undefined;
|
|
56
|
+
}, {
|
|
57
|
+
amount: string;
|
|
58
|
+
action: "transfer" | "swap";
|
|
59
|
+
walletAddress: string;
|
|
60
|
+
privateKey?: string | undefined;
|
|
61
|
+
tokenIn?: string | undefined;
|
|
62
|
+
tokenOut?: string | undefined;
|
|
63
|
+
toAddress?: string | undefined;
|
|
64
|
+
}>;
|
|
65
|
+
};
|
|
66
|
+
export declare function handleAssessRisk(input: AssessRiskInput): Promise<AssessRiskResult>;
|
|
67
|
+
//# sourceMappingURL=assessRisk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assessRisk.d.ts","sourceRoot":"","sources":["../../src/tools/assessRisk.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAIvE,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;EAU3B,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE/D,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD,eAAe,CAAC,EAAE;QAChB,SAAS,EAAE,OAAO,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAM1B,CAAC;AAEF,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAoDxF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// ─── Tool: assess_risk ─────────────────────────────────────────────────
|
|
2
|
+
// Core risk assessment tool. When privateKey is provided, auto-publishes
|
|
3
|
+
// the result to the on-chain RiskRegistry.
|
|
4
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { assessRisk } from "../lib/riskEngine.js";
|
|
7
|
+
import { createPharosWalletClient, publicClient, getExplorerUrl } from "../lib/pharosClient.js";
|
|
8
|
+
import { RISK_REGISTRY_ADDRESS, RISK_REGISTRY_ABI } from "../lib/constants.js";
|
|
9
|
+
export const assessRiskSchema = z.object({
|
|
10
|
+
action: z.enum(["swap", "transfer"]),
|
|
11
|
+
tokenIn: z.string().optional(),
|
|
12
|
+
tokenOut: z.string().optional(),
|
|
13
|
+
amount: z.string(),
|
|
14
|
+
toAddress: z.string().optional(),
|
|
15
|
+
walletAddress: z.string(),
|
|
16
|
+
privateKey: z.string().optional().describe("If provided, auto-publishes the risk score to the on-chain RiskRegistry"),
|
|
17
|
+
});
|
|
18
|
+
export const assessRiskTool = {
|
|
19
|
+
name: "assess_risk",
|
|
20
|
+
description: "Evaluate risk of a planned on-chain action (swap or transfer). Returns 0-100 risk score with 5-dimension breakdown. " +
|
|
21
|
+
"Optionally auto-publishes to on-chain RiskRegistry when privateKey is provided.",
|
|
22
|
+
inputSchema: assessRiskSchema,
|
|
23
|
+
};
|
|
24
|
+
export async function handleAssessRisk(input) {
|
|
25
|
+
if (input.action === "swap" && (!input.tokenIn || !input.tokenOut)) {
|
|
26
|
+
throw new Error("Swap action requires both tokenIn and tokenOut");
|
|
27
|
+
}
|
|
28
|
+
if (input.action === "transfer" && !input.toAddress) {
|
|
29
|
+
throw new Error("Transfer action requires toAddress");
|
|
30
|
+
}
|
|
31
|
+
const assessment = await assessRisk({
|
|
32
|
+
action: input.action,
|
|
33
|
+
tokenIn: input.tokenIn,
|
|
34
|
+
tokenOut: input.tokenOut,
|
|
35
|
+
amount: input.amount,
|
|
36
|
+
toAddress: input.toAddress,
|
|
37
|
+
walletAddress: input.walletAddress,
|
|
38
|
+
});
|
|
39
|
+
const result = { ...assessment };
|
|
40
|
+
// Auto-publish to on-chain registry if privateKey is provided
|
|
41
|
+
if (input.privateKey) {
|
|
42
|
+
try {
|
|
43
|
+
const wallet = createPharosWalletClient(input.privateKey);
|
|
44
|
+
const txHash = await wallet.writeContract({
|
|
45
|
+
address: RISK_REGISTRY_ADDRESS,
|
|
46
|
+
abi: RISK_REGISTRY_ABI,
|
|
47
|
+
functionName: "publish",
|
|
48
|
+
args: [
|
|
49
|
+
input.walletAddress,
|
|
50
|
+
BigInt(assessment.riskScore),
|
|
51
|
+
assessment.riskLevel,
|
|
52
|
+
assessment.recommendation,
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
await publicClient.waitForTransactionReceipt({ hash: txHash });
|
|
56
|
+
result.registryPublish = {
|
|
57
|
+
published: true,
|
|
58
|
+
txHash,
|
|
59
|
+
explorerUrl: getExplorerUrl(txHash),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
result.registryPublish = {
|
|
64
|
+
published: false,
|
|
65
|
+
error: `Registry publish failed: ${err.message}`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=assessRisk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assessRisk.js","sourceRoot":"","sources":["../../src/tools/assessRisk.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,yEAAyE;AACzE,2CAA2C;AAC3C,2EAA2E;AAE3E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAuB,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACpC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;IACzB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CACxC,yEAAyE,CAC1E;CACF,CAAC,CAAC;AAaH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,aAAa;IACnB,WAAW,EACT,sHAAsH;QACt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M,YAAY,CAAC,yBAAyB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;YAE/D,MAAM,CAAC,eAAe,GAAG;gBACvB,SAAS,EAAE,IAAI;gBACf,MAAM;gBACN,WAAW,EAAE,cAAc,CAAC,MAAM,CAAC;aACpC,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,eAAe,GAAG;gBACvB,SAAS,EAAE,KAAK;gBAChB,KAAK,EAAE,4BAA6B,GAAa,CAAC,OAAO,EAAE;aAC5D,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const checkAllowanceSchema: z.ZodObject<{
|
|
3
|
+
walletAddress: z.ZodString;
|
|
4
|
+
token: z.ZodEnum<["USDC", "USDT"]>;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
walletAddress: string;
|
|
7
|
+
token: "USDT" | "USDC";
|
|
8
|
+
}, {
|
|
9
|
+
walletAddress: string;
|
|
10
|
+
token: "USDT" | "USDC";
|
|
11
|
+
}>;
|
|
12
|
+
export type CheckAllowanceInput = z.input<typeof checkAllowanceSchema>;
|
|
13
|
+
export declare const checkAllowanceTool: {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
inputSchema: z.ZodObject<{
|
|
17
|
+
walletAddress: z.ZodString;
|
|
18
|
+
token: z.ZodEnum<["USDC", "USDT"]>;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
walletAddress: string;
|
|
21
|
+
token: "USDT" | "USDC";
|
|
22
|
+
}, {
|
|
23
|
+
walletAddress: string;
|
|
24
|
+
token: "USDT" | "USDC";
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
export declare function handleCheckAllowance(raw: CheckAllowanceInput): Promise<{
|
|
28
|
+
token: "USDT" | "USDC";
|
|
29
|
+
tokenAddress: "0xE7E84B8B4f39C507499c40B4ac199B050e2882d5" | "0xE0BE08c77f415F577A1B3A9aD7a1Df1479564ec8";
|
|
30
|
+
walletAddress: string;
|
|
31
|
+
spender: "0x4Cf317b8918FbE8A890c01eDAb7d548555Ac2cE9";
|
|
32
|
+
allowance: string;
|
|
33
|
+
allowanceRaw: string;
|
|
34
|
+
isApproved: boolean;
|
|
35
|
+
needsApproval: boolean;
|
|
36
|
+
}>;
|
|
37
|
+
//# sourceMappingURL=checkAllowance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkAllowance.d.ts","sourceRoot":"","sources":["../../src/tools/checkAllowance.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,eAAO,MAAM,oBAAoB;;;;;;;;;EAG/B,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEvE,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;CAK9B,CAAC;AAEF,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,mBAAmB;;;;;;;;;GA6BlE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// ─── Tool: check_allowance ─────────────────────────────────────────────
|
|
2
|
+
// Checks ERC-20 token allowance for DODO_APPROVE_ADDRESS.
|
|
3
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { publicClient } from "../lib/pharosClient.js";
|
|
6
|
+
import { DODO_APPROVE_ADDRESS, USDC_ADDRESS, USDT_ADDRESS, ERC20_ABI, } from "../lib/constants.js";
|
|
7
|
+
import { formatUnits } from "viem";
|
|
8
|
+
export const checkAllowanceSchema = z.object({
|
|
9
|
+
walletAddress: z.string().describe("Wallet address to check allowance for"),
|
|
10
|
+
token: z.enum(["USDC", "USDT"]).describe("ERC-20 token to check"),
|
|
11
|
+
});
|
|
12
|
+
export const checkAllowanceTool = {
|
|
13
|
+
name: "check_allowance",
|
|
14
|
+
description: "Check ERC-20 token allowance granted to DODO_APPROVE_ADDRESS for swaps. Returns current allowance and whether approval is needed.",
|
|
15
|
+
inputSchema: checkAllowanceSchema,
|
|
16
|
+
};
|
|
17
|
+
export async function handleCheckAllowance(raw) {
|
|
18
|
+
const input = checkAllowanceSchema.parse(raw);
|
|
19
|
+
const walletAddr = input.walletAddress;
|
|
20
|
+
const tokenAddress = input.token === "USDC" ? USDC_ADDRESS : USDT_ADDRESS;
|
|
21
|
+
const decimals = 6;
|
|
22
|
+
const allowanceRaw = (await publicClient.readContract({
|
|
23
|
+
address: tokenAddress,
|
|
24
|
+
abi: ERC20_ABI,
|
|
25
|
+
functionName: "allowance",
|
|
26
|
+
args: [walletAddr, DODO_APPROVE_ADDRESS],
|
|
27
|
+
}));
|
|
28
|
+
const allowanceFormatted = formatUnits(allowanceRaw, decimals);
|
|
29
|
+
// Consider "approved" if allowance is at least 1,000,000 tokens (typical max approval)
|
|
30
|
+
const isApproved = allowanceRaw > 0n;
|
|
31
|
+
const needsApproval = !isApproved;
|
|
32
|
+
return {
|
|
33
|
+
token: input.token,
|
|
34
|
+
tokenAddress,
|
|
35
|
+
walletAddress: input.walletAddress,
|
|
36
|
+
spender: DODO_APPROVE_ADDRESS,
|
|
37
|
+
allowance: allowanceFormatted,
|
|
38
|
+
allowanceRaw: allowanceRaw.toString(),
|
|
39
|
+
isApproved,
|
|
40
|
+
needsApproval,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=checkAllowance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkAllowance.js","sourceRoot":"","sources":["../../src/tools/checkAllowance.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,0DAA0D;AAC1D,2EAA2E;AAE3E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,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,CAAC;IACrC,MAAM,aAAa,GAAG,CAAC,UAAU,CAAC;IAElC,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,YAAY;QACZ,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,OAAO,EAAE,oBAAoB;QAC7B,SAAS,EAAE,kBAAkB;QAC7B,YAAY,EAAE,YAAY,CAAC,QAAQ,EAAE;QACrC,UAAU;QACV,aAAa;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const estimateGasSchema: z.ZodObject<{
|
|
3
|
+
action: z.ZodEnum<["swap", "transfer"]>;
|
|
4
|
+
tokenIn: z.ZodOptional<z.ZodString>;
|
|
5
|
+
tokenOut: z.ZodOptional<z.ZodString>;
|
|
6
|
+
amount: z.ZodString;
|
|
7
|
+
walletAddress: z.ZodString;
|
|
8
|
+
toAddress: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
amount: string;
|
|
11
|
+
action: "transfer" | "swap";
|
|
12
|
+
walletAddress: string;
|
|
13
|
+
tokenIn?: string | undefined;
|
|
14
|
+
tokenOut?: string | undefined;
|
|
15
|
+
toAddress?: string | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
amount: string;
|
|
18
|
+
action: "transfer" | "swap";
|
|
19
|
+
walletAddress: string;
|
|
20
|
+
tokenIn?: string | undefined;
|
|
21
|
+
tokenOut?: string | undefined;
|
|
22
|
+
toAddress?: string | undefined;
|
|
23
|
+
}>;
|
|
24
|
+
export type EstimateGasInput = z.input<typeof estimateGasSchema>;
|
|
25
|
+
export declare const estimateGasTool: {
|
|
26
|
+
name: string;
|
|
27
|
+
description: string;
|
|
28
|
+
inputSchema: z.ZodObject<{
|
|
29
|
+
action: z.ZodEnum<["swap", "transfer"]>;
|
|
30
|
+
tokenIn: z.ZodOptional<z.ZodString>;
|
|
31
|
+
tokenOut: z.ZodOptional<z.ZodString>;
|
|
32
|
+
amount: z.ZodString;
|
|
33
|
+
walletAddress: z.ZodString;
|
|
34
|
+
toAddress: z.ZodOptional<z.ZodString>;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
amount: string;
|
|
37
|
+
action: "transfer" | "swap";
|
|
38
|
+
walletAddress: string;
|
|
39
|
+
tokenIn?: string | undefined;
|
|
40
|
+
tokenOut?: string | undefined;
|
|
41
|
+
toAddress?: string | undefined;
|
|
42
|
+
}, {
|
|
43
|
+
amount: string;
|
|
44
|
+
action: "transfer" | "swap";
|
|
45
|
+
walletAddress: string;
|
|
46
|
+
tokenIn?: string | undefined;
|
|
47
|
+
tokenOut?: string | undefined;
|
|
48
|
+
toAddress?: string | undefined;
|
|
49
|
+
}>;
|
|
50
|
+
};
|
|
51
|
+
export declare function handleEstimateGas(raw: EstimateGasInput): Promise<{
|
|
52
|
+
error: string;
|
|
53
|
+
gasEstimate: null;
|
|
54
|
+
gasCostPHRS: null;
|
|
55
|
+
gasCostUsd: null;
|
|
56
|
+
isSufficient: boolean;
|
|
57
|
+
action?: undefined;
|
|
58
|
+
gasPrice?: undefined;
|
|
59
|
+
walletBalance?: undefined;
|
|
60
|
+
} | {
|
|
61
|
+
action: "transfer" | "swap";
|
|
62
|
+
gasEstimate: string;
|
|
63
|
+
gasPrice: string;
|
|
64
|
+
gasCostPHRS: string;
|
|
65
|
+
gasCostUsd: string;
|
|
66
|
+
walletBalance: string;
|
|
67
|
+
isSufficient: boolean;
|
|
68
|
+
error?: undefined;
|
|
69
|
+
}>;
|
|
70
|
+
//# sourceMappingURL=estimateGas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimateGas.d.ts","sourceRoot":"","sources":["../../src/tools/estimateGas.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;EAO5B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEjE,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;CAK3B,CAAC;AAKF,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;GAiH5D"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// ─── Tool: estimate_gas ────────────────────────────────────────────────
|
|
2
|
+
// Estimates gas cost for a swap or transfer before executing.
|
|
3
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { publicClient } from "../lib/pharosClient.js";
|
|
6
|
+
import { getDodoRoute, isNativeToken } from "../lib/dodoApi.js";
|
|
7
|
+
import { formatEther, parseEther } from "viem";
|
|
8
|
+
export const estimateGasSchema = z.object({
|
|
9
|
+
action: z.enum(["swap", "transfer"]).describe("Type of action to estimate gas for"),
|
|
10
|
+
tokenIn: z.string().optional().describe("Token to swap from (for swaps)"),
|
|
11
|
+
tokenOut: z.string().optional().describe("Token to swap to (for swaps)"),
|
|
12
|
+
amount: z.string().describe("Human-readable amount"),
|
|
13
|
+
walletAddress: z.string().describe("Sender wallet address"),
|
|
14
|
+
toAddress: z.string().optional().describe("Recipient address (for transfers)"),
|
|
15
|
+
});
|
|
16
|
+
export const estimateGasTool = {
|
|
17
|
+
name: "estimate_gas",
|
|
18
|
+
description: "Estimate gas cost for a swap or transfer before executing. Returns gas units, cost in PHRS, cost in USD, and whether the wallet has sufficient gas.",
|
|
19
|
+
inputSchema: estimateGasSchema,
|
|
20
|
+
};
|
|
21
|
+
// Read-only address for price quotes (never signs transactions)
|
|
22
|
+
const QUOTE_WALLET = "0x0000000000000000000000000000000000000001";
|
|
23
|
+
export async function handleEstimateGas(raw) {
|
|
24
|
+
const input = estimateGasSchema.parse(raw);
|
|
25
|
+
const walletAddr = input.walletAddress;
|
|
26
|
+
// Get current gas price
|
|
27
|
+
const gasPrice = await publicClient.getGasPrice();
|
|
28
|
+
const gasPriceGwei = Number(gasPrice) / 1e9;
|
|
29
|
+
// Get wallet balance to check sufficiency
|
|
30
|
+
const balance = await publicClient.getBalance({ address: walletAddr });
|
|
31
|
+
let gasEstimate;
|
|
32
|
+
if (input.action === "transfer") {
|
|
33
|
+
if (!input.toAddress) {
|
|
34
|
+
return {
|
|
35
|
+
error: "toAddress required for transfer gas estimation",
|
|
36
|
+
gasEstimate: null,
|
|
37
|
+
gasCostPHRS: null,
|
|
38
|
+
gasCostUsd: null,
|
|
39
|
+
isSufficient: false,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// Native transfer is always 21,000 gas
|
|
43
|
+
try {
|
|
44
|
+
gasEstimate = await publicClient.estimateGas({
|
|
45
|
+
to: input.toAddress,
|
|
46
|
+
value: parseEther(input.amount),
|
|
47
|
+
account: walletAddr,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
gasEstimate = 21000n;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// Swap — get gas estimate from DODO route
|
|
56
|
+
if (!input.tokenIn || !input.tokenOut) {
|
|
57
|
+
return {
|
|
58
|
+
error: "tokenIn and tokenOut required for swap gas estimation",
|
|
59
|
+
gasEstimate: null,
|
|
60
|
+
gasCostPHRS: null,
|
|
61
|
+
gasCostUsd: null,
|
|
62
|
+
isSufficient: false,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const quote = await getDodoRoute({
|
|
67
|
+
fromToken: input.tokenIn,
|
|
68
|
+
toToken: input.tokenOut,
|
|
69
|
+
amountHuman: input.amount,
|
|
70
|
+
walletAddress: input.walletAddress,
|
|
71
|
+
});
|
|
72
|
+
if (!quote.routeAvailable) {
|
|
73
|
+
return {
|
|
74
|
+
error: "No swap route available — cannot estimate gas",
|
|
75
|
+
gasEstimate: null,
|
|
76
|
+
gasCostPHRS: null,
|
|
77
|
+
gasCostUsd: null,
|
|
78
|
+
isSufficient: false,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
gasEstimate = BigInt(quote.gasLimit);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
return {
|
|
85
|
+
error: `Gas estimation failed: ${err.message}`,
|
|
86
|
+
gasEstimate: null,
|
|
87
|
+
gasCostPHRS: null,
|
|
88
|
+
gasCostUsd: null,
|
|
89
|
+
isSufficient: false,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Calculate cost
|
|
94
|
+
const gasCostWei = gasEstimate * gasPrice;
|
|
95
|
+
const gasCostPHRS = formatEther(gasCostWei);
|
|
96
|
+
// Get PHRS price for USD conversion
|
|
97
|
+
let gasCostUsd = "unavailable";
|
|
98
|
+
try {
|
|
99
|
+
const priceQuote = await getDodoRoute({
|
|
100
|
+
fromToken: "PHRS",
|
|
101
|
+
toToken: "USDC",
|
|
102
|
+
amountHuman: "1",
|
|
103
|
+
walletAddress: QUOTE_WALLET,
|
|
104
|
+
});
|
|
105
|
+
if (priceQuote.routeAvailable) {
|
|
106
|
+
const phrsUsd = parseFloat(priceQuote.amountOut);
|
|
107
|
+
gasCostUsd = (parseFloat(gasCostPHRS) * phrsUsd).toFixed(6);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// USD price unavailable
|
|
112
|
+
}
|
|
113
|
+
// Check if wallet has enough for gas (and value if native transfer/swap)
|
|
114
|
+
let totalNeeded = gasCostWei;
|
|
115
|
+
if (input.action === "transfer" || (input.action === "swap" && isNativeToken(input.tokenIn || ""))) {
|
|
116
|
+
totalNeeded += parseEther(input.amount);
|
|
117
|
+
}
|
|
118
|
+
const isSufficient = balance >= totalNeeded;
|
|
119
|
+
return {
|
|
120
|
+
action: input.action,
|
|
121
|
+
gasEstimate: gasEstimate.toString(),
|
|
122
|
+
gasPrice: gasPriceGwei.toFixed(2) + " Gwei",
|
|
123
|
+
gasCostPHRS,
|
|
124
|
+
gasCostUsd,
|
|
125
|
+
walletBalance: formatEther(balance) + " PHRS",
|
|
126
|
+
isSufficient,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=estimateGas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"estimateGas.js","sourceRoot":"","sources":["../../src/tools/estimateGas.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8DAA8D;AAC9D,2EAA2E;AAE3E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAE/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,oCAAoC,CAAC;IACnF,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gCAAgC,CAAC;IACzE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;IACxE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC;IACpD,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC;IAC3D,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;CAC/E,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,eA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;YACf,WAAW,EAAE,GAAG;YAChB,aAAa,EAAE,YAAY;SAC5B,CAAC,CAAC;QACH,IAAI,UAAU,CAAC,cAAc,EAAE,CAAC;YAC9B,MAAM,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;YACjD,UAAU,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,wBAAwB;IAC1B,CAAC;IAED,yEAAyE;IACzE,IAAI,WAAW,GAAG,UAAU,CAAC;IAC7B,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,IAAI,aAAa,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;QACnG,WAAW,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;IACD,MAAM,YAAY,GAAG,OAAO,IAAI,WAAW,CAAC;IAE5C,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,WAAW,EAAE,WAAW,CAAC,QAAQ,EAAE;QACnC,QAAQ,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO;QAC3C,WAAW;QACX,UAAU;QACV,aAAa,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO;QAC7C,YAAY;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const executeSwapSchema: z.ZodObject<{
|
|
3
|
+
tokenIn: z.ZodString;
|
|
4
|
+
tokenOut: z.ZodString;
|
|
5
|
+
amountIn: z.ZodString;
|
|
6
|
+
slippageTolerance: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
7
|
+
walletAddress: z.ZodString;
|
|
8
|
+
privateKey: z.ZodString;
|
|
9
|
+
bypassRiskCheck: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
privateKey: string;
|
|
12
|
+
tokenIn: string;
|
|
13
|
+
tokenOut: string;
|
|
14
|
+
walletAddress: string;
|
|
15
|
+
amountIn: string;
|
|
16
|
+
slippageTolerance: number;
|
|
17
|
+
bypassRiskCheck: boolean;
|
|
18
|
+
}, {
|
|
19
|
+
privateKey: string;
|
|
20
|
+
tokenIn: string;
|
|
21
|
+
tokenOut: string;
|
|
22
|
+
walletAddress: string;
|
|
23
|
+
amountIn: string;
|
|
24
|
+
slippageTolerance?: number | undefined;
|
|
25
|
+
bypassRiskCheck?: boolean | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
export type ExecuteSwapInput = z.input<typeof executeSwapSchema>;
|
|
28
|
+
export declare const executeSwapTool: {
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
inputSchema: z.ZodObject<{
|
|
32
|
+
tokenIn: z.ZodString;
|
|
33
|
+
tokenOut: z.ZodString;
|
|
34
|
+
amountIn: z.ZodString;
|
|
35
|
+
slippageTolerance: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
36
|
+
walletAddress: z.ZodString;
|
|
37
|
+
privateKey: z.ZodString;
|
|
38
|
+
bypassRiskCheck: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
privateKey: string;
|
|
41
|
+
tokenIn: string;
|
|
42
|
+
tokenOut: string;
|
|
43
|
+
walletAddress: string;
|
|
44
|
+
amountIn: string;
|
|
45
|
+
slippageTolerance: number;
|
|
46
|
+
bypassRiskCheck: boolean;
|
|
47
|
+
}, {
|
|
48
|
+
privateKey: string;
|
|
49
|
+
tokenIn: string;
|
|
50
|
+
tokenOut: string;
|
|
51
|
+
walletAddress: string;
|
|
52
|
+
amountIn: string;
|
|
53
|
+
slippageTolerance?: number | undefined;
|
|
54
|
+
bypassRiskCheck?: boolean | undefined;
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
export declare function handleExecuteSwap(raw: ExecuteSwapInput): Promise<{
|
|
58
|
+
success: boolean;
|
|
59
|
+
riskAssessment: {
|
|
60
|
+
riskScore: number;
|
|
61
|
+
wasBlocked: boolean;
|
|
62
|
+
blockReason: string;
|
|
63
|
+
};
|
|
64
|
+
error: string;
|
|
65
|
+
txHash?: undefined;
|
|
66
|
+
explorerUrl?: undefined;
|
|
67
|
+
amountOut?: undefined;
|
|
68
|
+
gasUsed?: undefined;
|
|
69
|
+
} | {
|
|
70
|
+
success: boolean;
|
|
71
|
+
riskAssessment: {
|
|
72
|
+
riskScore: number;
|
|
73
|
+
wasBlocked: boolean;
|
|
74
|
+
blockReason?: undefined;
|
|
75
|
+
};
|
|
76
|
+
error: string;
|
|
77
|
+
txHash?: undefined;
|
|
78
|
+
explorerUrl?: undefined;
|
|
79
|
+
amountOut?: undefined;
|
|
80
|
+
gasUsed?: undefined;
|
|
81
|
+
} | {
|
|
82
|
+
success: boolean;
|
|
83
|
+
txHash: `0x${string}`;
|
|
84
|
+
explorerUrl: string;
|
|
85
|
+
amountOut: string;
|
|
86
|
+
gasUsed: string;
|
|
87
|
+
riskAssessment: {
|
|
88
|
+
riskScore: number;
|
|
89
|
+
wasBlocked: boolean;
|
|
90
|
+
blockReason?: undefined;
|
|
91
|
+
};
|
|
92
|
+
error?: undefined;
|
|
93
|
+
}>;
|
|
94
|
+
//# sourceMappingURL=executeSwap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executeSwap.d.ts","sourceRoot":"","sources":["../../src/tools/executeSwap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;EAQ5B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEjE,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAI3B,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+F5D"}
|