@kasarlabs/avnu-mcp 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 +27 -0
- package/bin/avnu-mcp.js +2 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +49 -0
- package/build/index.js.map +1 -0
- package/build/interfaces/index.d.ts +7 -0
- package/build/interfaces/index.js +2 -0
- package/build/interfaces/index.js.map +1 -0
- package/build/lib/abis/erc20Abi.d.ts +92 -0
- package/build/lib/abis/erc20Abi.js +676 -0
- package/build/lib/abis/erc20Abi.js.map +1 -0
- package/build/lib/constants/index.d.ts +2 -0
- package/build/lib/constants/index.js +3 -0
- package/build/lib/constants/index.js.map +1 -0
- package/build/lib/dependances/types.d.ts +85 -0
- package/build/lib/dependances/types.js +51 -0
- package/build/lib/dependances/types.js.map +1 -0
- package/build/lib/types/index.d.ts +51 -0
- package/build/lib/types/index.js +2 -0
- package/build/lib/types/index.js.map +1 -0
- package/build/lib/utils/contractInteractor.d.ts +16 -0
- package/build/lib/utils/contractInteractor.js +114 -0
- package/build/lib/utils/contractInteractor.js.map +1 -0
- package/build/lib/utils/transactionMonitor.d.ts +11 -0
- package/build/lib/utils/transactionMonitor.js +82 -0
- package/build/lib/utils/transactionMonitor.js.map +1 -0
- package/build/lib/utils/utils.d.ts +6 -0
- package/build/lib/utils/utils.js +9 -0
- package/build/lib/utils/utils.js.map +1 -0
- package/build/schemas/index.d.ts +28 -0
- package/build/schemas/index.js +20 -0
- package/build/schemas/index.js.map +1 -0
- package/build/tools/approval.d.ts +8 -0
- package/build/tools/approval.js +46 -0
- package/build/tools/approval.js.map +1 -0
- package/build/tools/fetchRoute.d.ts +13 -0
- package/build/tools/fetchRoute.js +67 -0
- package/build/tools/fetchRoute.js.map +1 -0
- package/build/tools/fetchTokens.d.ts +10 -0
- package/build/tools/fetchTokens.js +30 -0
- package/build/tools/fetchTokens.js.map +1 -0
- package/build/tools/swap.d.ts +17 -0
- package/build/tools/swap.js +92 -0
- package/build/tools/swap.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { RpcProvider } from 'starknet';
|
|
2
|
+
import { SystemMessage } from '@langchain/core/messages';
|
|
3
|
+
import { z as Zod } from 'zod';
|
|
4
|
+
export interface StarknetTool<P = unknown> {
|
|
5
|
+
name: string;
|
|
6
|
+
plugins: string;
|
|
7
|
+
description: string;
|
|
8
|
+
schema?: Zod.AnyZodObject;
|
|
9
|
+
responseFormat?: string;
|
|
10
|
+
execute: (agent: SnakAgentInterface, params: P, plugins_manager?: any) => Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface SignatureTool<P = any> {
|
|
13
|
+
name: string;
|
|
14
|
+
categorie?: string;
|
|
15
|
+
description: string;
|
|
16
|
+
schema?: object;
|
|
17
|
+
execute: (params: P) => Promise<unknown>;
|
|
18
|
+
}
|
|
19
|
+
export declare enum AgentMode {
|
|
20
|
+
INTERACTIVE = "interactive",
|
|
21
|
+
AUTONOMOUS = "autonomous",
|
|
22
|
+
HYBRID = "hybrid"
|
|
23
|
+
}
|
|
24
|
+
export interface RawAgentConfig {
|
|
25
|
+
name: string;
|
|
26
|
+
group: string;
|
|
27
|
+
description: string;
|
|
28
|
+
lore: string[];
|
|
29
|
+
objectives: string[];
|
|
30
|
+
knowledge: string[];
|
|
31
|
+
interval: number;
|
|
32
|
+
plugins: string[];
|
|
33
|
+
memory: MemoryConfig;
|
|
34
|
+
rag?: RagConfig;
|
|
35
|
+
mcpServers?: Record<string, any>;
|
|
36
|
+
mode: AgentMode;
|
|
37
|
+
}
|
|
38
|
+
export interface MemoryConfig {
|
|
39
|
+
enabled?: boolean;
|
|
40
|
+
shortTermMemorySize?: number;
|
|
41
|
+
memorySize?: number;
|
|
42
|
+
maxIterations?: number;
|
|
43
|
+
embeddingModel?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface RagConfig {
|
|
46
|
+
enabled?: boolean;
|
|
47
|
+
topK?: number;
|
|
48
|
+
embeddingModel?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface AgentConfig {
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
group: string;
|
|
54
|
+
description: string;
|
|
55
|
+
interval: number;
|
|
56
|
+
chatId: string;
|
|
57
|
+
plugins: string[];
|
|
58
|
+
memory: MemoryConfig;
|
|
59
|
+
rag?: RagConfig;
|
|
60
|
+
mcpServers?: Record<string, any>;
|
|
61
|
+
mode: AgentMode;
|
|
62
|
+
maxIterations: number;
|
|
63
|
+
prompt: SystemMessage;
|
|
64
|
+
}
|
|
65
|
+
export interface DatabaseCredentials {
|
|
66
|
+
host: string;
|
|
67
|
+
port: number;
|
|
68
|
+
user: string;
|
|
69
|
+
password: string;
|
|
70
|
+
database: string;
|
|
71
|
+
}
|
|
72
|
+
export interface SnakAgentInterface {
|
|
73
|
+
getAccountCredentials: () => {
|
|
74
|
+
accountPublicKey: string;
|
|
75
|
+
accountPrivateKey: string;
|
|
76
|
+
};
|
|
77
|
+
getDatabaseCredentials: () => DatabaseCredentials;
|
|
78
|
+
getSignature: () => {
|
|
79
|
+
signature: string;
|
|
80
|
+
};
|
|
81
|
+
getProvider: () => RpcProvider;
|
|
82
|
+
getAgentConfig: () => AgentConfig;
|
|
83
|
+
}
|
|
84
|
+
import winston from 'winston';
|
|
85
|
+
export declare const logger: winston.Logger;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export var AgentMode;
|
|
2
|
+
(function (AgentMode) {
|
|
3
|
+
AgentMode["INTERACTIVE"] = "interactive";
|
|
4
|
+
AgentMode["AUTONOMOUS"] = "autonomous";
|
|
5
|
+
AgentMode["HYBRID"] = "hybrid";
|
|
6
|
+
})(AgentMode || (AgentMode = {}));
|
|
7
|
+
import winston from 'winston';
|
|
8
|
+
const levels = {
|
|
9
|
+
error: 0,
|
|
10
|
+
warn: 1,
|
|
11
|
+
info: 2,
|
|
12
|
+
http: 3,
|
|
13
|
+
debug: 4,
|
|
14
|
+
};
|
|
15
|
+
const colors = {
|
|
16
|
+
error: 'red',
|
|
17
|
+
warn: 'yellow',
|
|
18
|
+
info: 'green',
|
|
19
|
+
http: 'magenta',
|
|
20
|
+
debug: 'blue',
|
|
21
|
+
};
|
|
22
|
+
winston.addColors(colors);
|
|
23
|
+
const level = () => {
|
|
24
|
+
if (process.env.LOG_LEVEL) {
|
|
25
|
+
return process.env.LOG_LEVEL.toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
const env = process.env.NODE_ENV || 'production';
|
|
28
|
+
return env === 'development' ? 'debug' : 'info';
|
|
29
|
+
};
|
|
30
|
+
const format = winston.format.combine(winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston.format.colorize({ all: true }), winston.format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`));
|
|
31
|
+
let transports;
|
|
32
|
+
try {
|
|
33
|
+
transports = [
|
|
34
|
+
new winston.transports.Console(),
|
|
35
|
+
new winston.transports.File({
|
|
36
|
+
filename: 'logs/error.log',
|
|
37
|
+
level: 'error',
|
|
38
|
+
}),
|
|
39
|
+
new winston.transports.File({ filename: 'logs/combined.log' }),
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
transports = [new winston.transports.Console()];
|
|
44
|
+
}
|
|
45
|
+
export const logger = winston.createLogger({
|
|
46
|
+
level: level(),
|
|
47
|
+
levels,
|
|
48
|
+
format,
|
|
49
|
+
transports,
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/dependances/types.ts"],"names":[],"mappings":"AAqCA,MAAM,CAAN,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,sCAAyB,CAAA;IACzB,8BAAiB,CAAA;AACnB,CAAC,EAJW,SAAS,KAAT,SAAS,QAIpB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IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC;YAC1B,QAAQ,EAAE,gBAAgB;YAC1B,KAAK,EAAE,OAAO;SACf,CAAC;QAEF,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,mBAAmB,EAAE,CAAC;KAC/D,CAAC;AACJ,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,UAAU,GAAG,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IACzC,KAAK,EAAE,KAAK,EAAE;IACd,MAAM;IACN,MAAM;IACN,UAAU;CACX,CAAC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Token as AvnuToken } from '@avnu/avnu-sdk';
|
|
2
|
+
import { ProviderInterface } from 'starknet';
|
|
3
|
+
export interface SwapParams {
|
|
4
|
+
sellTokenSymbol: string;
|
|
5
|
+
buyTokenSymbol: string;
|
|
6
|
+
sellAmount: number;
|
|
7
|
+
}
|
|
8
|
+
export interface Token {
|
|
9
|
+
name: string;
|
|
10
|
+
address: string;
|
|
11
|
+
symbol: string;
|
|
12
|
+
decimals: number;
|
|
13
|
+
logoUri: string | null;
|
|
14
|
+
lastDailyVolumeUsd: number;
|
|
15
|
+
extensions: {
|
|
16
|
+
[key: string]: string;
|
|
17
|
+
};
|
|
18
|
+
tags: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface TokenResponse {
|
|
21
|
+
content: AvnuToken[];
|
|
22
|
+
size: number;
|
|
23
|
+
number: number;
|
|
24
|
+
totalElements: number;
|
|
25
|
+
totalPages: number;
|
|
26
|
+
}
|
|
27
|
+
export interface SwapResult {
|
|
28
|
+
status: 'success' | 'failure';
|
|
29
|
+
message?: string;
|
|
30
|
+
error?: string;
|
|
31
|
+
transactionHash?: string;
|
|
32
|
+
sellAmount?: number;
|
|
33
|
+
sellToken?: string;
|
|
34
|
+
buyToken?: string;
|
|
35
|
+
amountReceived?: string;
|
|
36
|
+
receipt?: any;
|
|
37
|
+
events?: any[];
|
|
38
|
+
}
|
|
39
|
+
export interface BaseUtilityClass {
|
|
40
|
+
provider: ProviderInterface;
|
|
41
|
+
}
|
|
42
|
+
export interface ContractDeployResult {
|
|
43
|
+
transactionHash: string;
|
|
44
|
+
contractAddress: string | string[];
|
|
45
|
+
}
|
|
46
|
+
export interface TransactionResult {
|
|
47
|
+
status: 'success' | 'failure';
|
|
48
|
+
transactionHash?: string;
|
|
49
|
+
contractAddress?: string;
|
|
50
|
+
error?: string;
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Account, Contract, Call, EstimateFee } from 'starknet';
|
|
2
|
+
import { BaseUtilityClass, ContractDeployResult, TransactionResult } from '../types/index.js';
|
|
3
|
+
export declare class ContractInteractor implements BaseUtilityClass {
|
|
4
|
+
provider: any;
|
|
5
|
+
constructor(provider: any);
|
|
6
|
+
deployContract(account: Account, classHash: string, constructorCalldata?: any[], salt?: string): Promise<ContractDeployResult>;
|
|
7
|
+
estimateContractDeploy(account: Account, classHash: string, constructorCalldata?: any[], salt?: string): Promise<EstimateFee>;
|
|
8
|
+
multicall(account: Account, calls: Call[]): Promise<TransactionResult>;
|
|
9
|
+
estimateMulticall(account: Account, calls: Call[]): Promise<EstimateFee>;
|
|
10
|
+
createContract(abi: any[], address: string, account?: Account): Contract;
|
|
11
|
+
readContract(contract: Contract, method: string, args?: any[]): Promise<any>;
|
|
12
|
+
writeContract(contract: Contract, method: string, args?: any[]): Promise<TransactionResult>;
|
|
13
|
+
estimateContractWrite(contract: Contract, method: string, args?: any[]): Promise<EstimateFee>;
|
|
14
|
+
formatTokenAmount(amount: string | number, decimals?: number): string;
|
|
15
|
+
parseTokenAmount(amount: string, decimals?: number): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Contract, CallData, hash } from 'starknet';
|
|
2
|
+
export class ContractInteractor {
|
|
3
|
+
constructor(provider) {
|
|
4
|
+
this.provider = provider;
|
|
5
|
+
}
|
|
6
|
+
async deployContract(account, classHash, constructorCalldata = [], salt) {
|
|
7
|
+
try {
|
|
8
|
+
const deployPayload = {
|
|
9
|
+
classHash,
|
|
10
|
+
constructorCalldata: CallData.compile(constructorCalldata),
|
|
11
|
+
salt: salt || hash.getSelectorFromName(Math.random().toString()),
|
|
12
|
+
};
|
|
13
|
+
const { transaction_hash, contract_address } = await account.deploy(deployPayload);
|
|
14
|
+
await this.provider.waitForTransaction(transaction_hash);
|
|
15
|
+
return {
|
|
16
|
+
transactionHash: transaction_hash,
|
|
17
|
+
contractAddress: contract_address,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
throw new Error(`Failed to deploy contract: ${error.message}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async estimateContractDeploy(account, classHash, constructorCalldata = [], salt) {
|
|
25
|
+
try {
|
|
26
|
+
const deployPayload = {
|
|
27
|
+
classHash,
|
|
28
|
+
constructorCalldata: CallData.compile(constructorCalldata),
|
|
29
|
+
salt: salt || hash.getSelectorFromName(Math.random().toString()),
|
|
30
|
+
};
|
|
31
|
+
return account.estimateDeployFee(deployPayload);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new Error(`Failed to estimate contract deploy: ${error.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async multicall(account, calls) {
|
|
38
|
+
try {
|
|
39
|
+
const { transaction_hash } = await account.execute(calls);
|
|
40
|
+
await this.provider.waitForTransaction(transaction_hash);
|
|
41
|
+
return {
|
|
42
|
+
status: 'success',
|
|
43
|
+
transactionHash: transaction_hash,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return {
|
|
48
|
+
status: 'failure',
|
|
49
|
+
error: error.message,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async estimateMulticall(account, calls) {
|
|
54
|
+
try {
|
|
55
|
+
return account.estimateInvokeFee(calls);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
throw new Error(`Failed to estimate multicall: ${error.message}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
createContract(abi, address, account) {
|
|
62
|
+
return new Contract(abi, address, account || this.provider);
|
|
63
|
+
}
|
|
64
|
+
async readContract(contract, method, args = []) {
|
|
65
|
+
try {
|
|
66
|
+
return await contract.call(method, args);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
throw new Error(`Failed to read contract: ${error.message}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async writeContract(contract, method, args = []) {
|
|
73
|
+
try {
|
|
74
|
+
const { transaction_hash } = await contract.invoke(method, args);
|
|
75
|
+
await this.provider.waitForTransaction(transaction_hash);
|
|
76
|
+
return {
|
|
77
|
+
status: 'success',
|
|
78
|
+
transactionHash: transaction_hash,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return {
|
|
83
|
+
status: 'failure',
|
|
84
|
+
error: error.message,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async estimateContractWrite(contract, method, args = []) {
|
|
89
|
+
if (!contract.account) {
|
|
90
|
+
throw new Error('Contract must be connected to an account to estimate fees');
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
return await contract.estimate(method, args);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
throw new Error(`Failed to estimate contract write: ${error.message}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
formatTokenAmount(amount, decimals = 18) {
|
|
100
|
+
const value = typeof amount === 'string' ? amount : amount.toString();
|
|
101
|
+
const [whole, fraction = ''] = value.split('.');
|
|
102
|
+
const paddedFraction = fraction.padEnd(decimals, '0');
|
|
103
|
+
return whole + paddedFraction;
|
|
104
|
+
}
|
|
105
|
+
parseTokenAmount(amount, decimals = 18) {
|
|
106
|
+
const amountBigInt = BigInt(amount);
|
|
107
|
+
const divisor = BigInt(10) ** BigInt(decimals);
|
|
108
|
+
const wholePart = amountBigInt / divisor;
|
|
109
|
+
const fractionPart = amountBigInt % divisor;
|
|
110
|
+
const paddedFraction = fractionPart.toString().padStart(decimals, '0');
|
|
111
|
+
return `${wholePart}.${paddedFraction}`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=contractInteractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contractInteractor.js","sourceRoot":"","sources":["../../../src/lib/utils/contractInteractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,QAAQ,EAAQ,QAAQ,EAAE,IAAI,EAAe,MAAM,UAAU,CAAC;AAOhF,MAAM,OAAO,kBAAkB;IAC7B,YAAmB,QAAa;QAAb,aAAQ,GAAR,QAAQ,CAAK;IAAG,CAAC;IAEpC,KAAK,CAAC,cAAc,CAClB,OAAgB,EAChB,SAAiB,EACjB,sBAA6B,EAAE,EAC/B,IAAa;QAEb,IAAI,CAAC;YACH,MAAM,aAAa,GAAG;gBACpB,SAAS;gBACT,mBAAmB,EAAE,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC;gBAC1D,IAAI,EAAE,IAAI,IAAI,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;aACjE,CAAC;YAEF,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAC1C,MAAM,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YACtC,MAAM,IAAI,CAAC,QAAQ,CAAC,k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-0,0 +1,11 @@
|
|
|
1
|
+
import { BaseUtilityClass } from '../types/index.js';
|
|
2
|
+
import { TransactionStatus, TransactionReceipt } from 'starknet';
|
|
3
|
+
export declare class TransactionMonitor implements BaseUtilityClass {
|
|
4
|
+
provider: any;
|
|
5
|
+
private readonly pollingInterval;
|
|
6
|
+
constructor(provider: any, pollingInterval?: number);
|
|
7
|
+
waitForTransaction(txHash: string, callback?: (status: TransactionStatus) => void): Promise<TransactionReceipt>;
|
|
8
|
+
getTransactionEvents(txHash: string): Promise<Event[]>;
|
|
9
|
+
watchEvents(fromBlock: number, toBlock: number | "latest" | undefined, callback: (events: Event[]) => void): Promise<void>;
|
|
10
|
+
getTransactionStatus(txHash: string): Promise<TransactionStatus>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export class TransactionMonitor {
|
|
2
|
+
constructor(provider, pollingInterval = 5000) {
|
|
3
|
+
this.provider = provider;
|
|
4
|
+
this.pollingInterval = pollingInterval;
|
|
5
|
+
}
|
|
6
|
+
async waitForTransaction(txHash, callback) {
|
|
7
|
+
let receipt;
|
|
8
|
+
while (true) {
|
|
9
|
+
try {
|
|
10
|
+
receipt = await this.provider.getTransactionReceipt(txHash);
|
|
11
|
+
if (callback) {
|
|
12
|
+
const status = await this.provider.getTransactionStatus(txHash);
|
|
13
|
+
callback(status);
|
|
14
|
+
}
|
|
15
|
+
if (receipt.finality_status === 'ACCEPTED_ON_L2' ||
|
|
16
|
+
receipt.finality_status === 'ACCEPTED_ON_L1') {
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
if (receipt.execution_status === 'REVERTED') {
|
|
20
|
+
throw new Error(`Transaction ${txHash} was reverted`);
|
|
21
|
+
}
|
|
22
|
+
await new Promise((resolve) => setTimeout(resolve, this.pollingInterval));
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (error.message.includes('Transaction hash not found')) {
|
|
26
|
+
await new Promise((resolve) => setTimeout(resolve, this.pollingInterval));
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return receipt;
|
|
33
|
+
}
|
|
34
|
+
async getTransactionEvents(txHash) {
|
|
35
|
+
try {
|
|
36
|
+
const receipt = await this.provider.getTransactionReceipt(txHash);
|
|
37
|
+
return receipt.events || [];
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new Error(`Failed to get transaction events: ${error.message}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async watchEvents(fromBlock, toBlock = 'latest', callback) {
|
|
44
|
+
let currentBlock = fromBlock;
|
|
45
|
+
while (true) {
|
|
46
|
+
try {
|
|
47
|
+
const latestBlock = toBlock === 'latest' ? await this.provider.getBlockNumber() : toBlock;
|
|
48
|
+
if (currentBlock > latestBlock) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
const block = await this.provider.getBlockWithTxs(currentBlock);
|
|
52
|
+
const events = [];
|
|
53
|
+
for (const tx of block.transactions) {
|
|
54
|
+
if (tx.transaction_hash) {
|
|
55
|
+
const receipt = await this.provider.getTransactionReceipt(tx.transaction_hash);
|
|
56
|
+
if (receipt.events) {
|
|
57
|
+
events.push(...receipt.events);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (events.length > 0) {
|
|
62
|
+
callback(events);
|
|
63
|
+
}
|
|
64
|
+
currentBlock++;
|
|
65
|
+
await new Promise((resolve) => setTimeout(resolve, this.pollingInterval));
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error('Error watching events:', error);
|
|
69
|
+
await new Promise((resolve) => setTimeout(resolve, this.pollingInterval));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async getTransactionStatus(txHash) {
|
|
74
|
+
try {
|
|
75
|
+
return await this.provider.getTransactionStatus(txHash);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
throw new Error(`Failed to get transaction status: ${error.message}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=transactionMonitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactionMonitor.js","sourceRoot":"","sources":["../../../src/lib/utils/transactionMonitor.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,kBAAkB;IAC7B,YACS,QAAa,EACH,kBAA0B,IAAI;QADxC,aAAQ,GAAR,QAAQ,CAAK;QACH,oBAAe,GAAf,eAAe,CAAe;IAC9C,CAAC;IAEJ,KAAK,CAAC,kBAAkB,CACtB,MAAc,EACd,QAA8C;QAE9C,IAAI,OAA2B,CAAC;QAEhC,OAAO,IAAI,EAAE,CAAC;YACZ,IAAI,CAAC;gBACH,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;gBAE5D,IAAI,QAAQ,EAAE,CAAC;oBACb,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;oBAChE,QAAQ,CAAC,MAAM,CAAC,CAAC;gBACnB,CAAC;gBAED,IACE,OAAO,CAAC,eAAe,KAAK,gBAAgB;oBAC5C,OAAO,CAAC,eAAe,KAAK,gBAAgB,EAC5C,CAAC;oBACD,MAAM;gBACR,CAAC;gBAED,IAAI,OAAO,CAAC,gBAAgB,KAAK,UAAU,EAAE,CAAC;oBAC5C,MAAM,IAAI,KAAK,CAAC,eAAe,MAAM,eAAe,CAAC,CAAC;gBACxD,CAAC;gBAED,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAC5B,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,CAAC,CAC1C,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,CAAC,OAAO,CAAC,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AAQ,CAAC,qBAAqB,CACvD,EAAE,CAAC,gBAAgB,CACpB,CAAC;wBACF,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;4BACnB,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;wBACjC,CAAC;oBACH,CAAC;gBACH,CAAC;gBAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBACtB,QAAQ,CAAC,MAAM,CAAC,CAAC;gBACnB,CAAC;gBAED,YAAY,EAAE,CAAC;gBACf,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAC5B,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,CAAC,CAC1C,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;gBAC/C,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAC5B,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,CAAC,CAC1C,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,MAAc;QACvC,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;QAC1D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,qCAAqC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const executeV3Transaction = async ({ call, account, }) => {
|
|
2
|
+
const { transaction_hash } = await account.execute(call);
|
|
3
|
+
const receipt = await account.waitForTransaction(transaction_hash);
|
|
4
|
+
if (!receipt.isSuccess()) {
|
|
5
|
+
throw new Error('Transaction confirmed but failed');
|
|
6
|
+
}
|
|
7
|
+
return transaction_hash;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/lib/utils/utils.ts"],"names":[],"mappings":"AA6BA,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,EACzC,IAAI,EACJ,OAAO,GACO,EAAmB,EAAE;IACnC,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;IACnE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
export declare const swapSchema: z.ZodObject<{
|
|
3
|
+
sellTokenSymbol: z.ZodString;
|
|
4
|
+
buyTokenSymbol: z.ZodString;
|
|
5
|
+
sellAmount: z.ZodNumber;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
sellTokenSymbol: string;
|
|
8
|
+
buyTokenSymbol: string;
|
|
9
|
+
sellAmount: number;
|
|
10
|
+
}, {
|
|
11
|
+
sellTokenSymbol: string;
|
|
12
|
+
buyTokenSymbol: string;
|
|
13
|
+
sellAmount: number;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const routeSchema: z.ZodObject<{
|
|
16
|
+
sellTokenSymbol: z.ZodString;
|
|
17
|
+
buyTokenSymbol: z.ZodString;
|
|
18
|
+
sellAmount: z.ZodNumber;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
sellTokenSymbol: string;
|
|
21
|
+
buyTokenSymbol: string;
|
|
22
|
+
sellAmount: number;
|
|
23
|
+
}, {
|
|
24
|
+
sellTokenSymbol: string;
|
|
25
|
+
buyTokenSymbol: string;
|
|
26
|
+
sellAmount: number;
|
|
27
|
+
}>;
|
|
28
|
+
export type RouteSchemaType = z.infer<typeof routeSchema>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
export const swapSchema = z.object({
|
|
3
|
+
sellTokenSymbol: z
|
|
4
|
+
.string()
|
|
5
|
+
.describe("Symbol of the token to sell (e.g., 'ETH', 'USDC')"),
|
|
6
|
+
buyTokenSymbol: z
|
|
7
|
+
.string()
|
|
8
|
+
.describe("Symbol of the token to buy (e.g., 'ETH', 'USDC')"),
|
|
9
|
+
sellAmount: z.number().positive().describe('Amount of tokens to sell'),
|
|
10
|
+
});
|
|
11
|
+
export const routeSchema = z.object({
|
|
12
|
+
sellTokenSymbol: z
|
|
13
|
+
.string()
|
|
14
|
+
.describe("Symbol of the token to sell (e.g., 'ETH', 'USDC')"),
|
|
15
|
+
buyTokenSymbol: z
|
|
16
|
+
.string()
|
|
17
|
+
.describe("Symbol of the token to buy (e.g., 'ETH', 'USDC')"),
|
|
18
|
+
sellAmount: z.number().positive().describe('Amount of tokens to sell'),
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schemas/index.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,eAAe,EAAE,CAAC;SACf,MAAM,EAAE;SACR,QAAQ,CAAC,mDAAmD,CAAC;IAChE,cAAc,EAAE,CAAC;SACd,MAAM,EAAE;SACR,QAAQ,CAAC,kDAAkD,CAAC;IAC/D,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,0BAA0B,CAAC;CACvE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,eAAe,EAAE,CAAC;SACf,MAAM,EAAE;SACR,QAAQ,CAAC,mDAAmD,CAAC;IAChE,cAAc,EAAE,CAAC;SACd,MAAM,EAAE;SACR,QAAQ,CAAC,kDAAkD,CAAC;IAC/D,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,0BAA0B,CAAC;CACvE,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Account } from 'starknet';
|
|
2
|
+
import { onchainWrite } from '@kasarlabs/ask-starknet-core';
|
|
3
|
+
export declare class ApprovalService {
|
|
4
|
+
private env;
|
|
5
|
+
constructor(env: onchainWrite);
|
|
6
|
+
private safeStringify;
|
|
7
|
+
checkAndApproveToken(account: Account, tokenAddress: string, spenderAddress: string, amount: string): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { uint256 } from 'starknet';
|
|
2
|
+
import { ERC20_ABI } from '../lib/abis/erc20Abi.js';
|
|
3
|
+
import { ContractInteractor } from '../lib/utils/contractInteractor.js';
|
|
4
|
+
import { TransactionMonitor } from '../lib/utils/transactionMonitor.js';
|
|
5
|
+
export class ApprovalService {
|
|
6
|
+
constructor(env) {
|
|
7
|
+
this.env = env;
|
|
8
|
+
}
|
|
9
|
+
safeStringify(obj) {
|
|
10
|
+
return JSON.stringify(obj, (_, value) => (typeof value === 'bigint' ? value.toString() : value), 2);
|
|
11
|
+
}
|
|
12
|
+
async checkAndApproveToken(account, tokenAddress, spenderAddress, amount) {
|
|
13
|
+
try {
|
|
14
|
+
const contractInteractor = new ContractInteractor(this.env.provider);
|
|
15
|
+
const transactionMonitor = new TransactionMonitor(this.env.provider);
|
|
16
|
+
const contract = contractInteractor.createContract(ERC20_ABI, tokenAddress, account);
|
|
17
|
+
const allowanceResult = await contract.allowance(account.address, spenderAddress);
|
|
18
|
+
let currentAllowance;
|
|
19
|
+
if (Array.isArray(allowanceResult)) {
|
|
20
|
+
currentAllowance = BigInt(allowanceResult[0].toString());
|
|
21
|
+
}
|
|
22
|
+
else if (typeof allowanceResult === 'object' &&
|
|
23
|
+
allowanceResult !== null) {
|
|
24
|
+
const value = Object.values(allowanceResult)[0];
|
|
25
|
+
currentAllowance = BigInt(value.toString());
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
currentAllowance = BigInt(allowanceResult.toString());
|
|
29
|
+
}
|
|
30
|
+
const requiredAmount = BigInt(amount);
|
|
31
|
+
if (currentAllowance < requiredAmount) {
|
|
32
|
+
contract.connect(account);
|
|
33
|
+
const approveCall = await contract.approve(spenderAddress, uint256.bnToUint256(amount));
|
|
34
|
+
console.error('Approve transaction sent:', this.safeStringify(approveCall));
|
|
35
|
+
if (!approveCall?.transaction_hash) {
|
|
36
|
+
throw new Error('No transaction hash in approve result');
|
|
37
|
+
}
|
|
38
|
+
await transactionMonitor.waitForTransaction(approveCall.transaction_hash, (status) => console.error('Approve status:', status));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw new Error(`Failed to approve token: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=approval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/tools/approval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,OAAO,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAMxE,MAAM,OAAO,eAAe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BACN,gBAAgB,GAAG,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,CAAC;YACxD,CAAC;YAED,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;YAEtC,IAAI,gBAAgB,GAAG,cAAc,EAAE,CAAC;gBACtC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC1B,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,OAAO,CACxC,cAAc,EACd,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAC5B,CAAC;gBAEF,OAAO,CAAC,KAAK,CACX,2BAA2B,EAC3B,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,CAChC,CAAC;gBAEF,IAAI,CAAC,WAAW,EAAE,gBAAgB,EAAE,CAAC;oBACnC,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;gBAC3D,CAAC;gBAED,MAAM,kBAAkB,CAAC,kBAAkB,CACzC,WAAW,CAAC,gBAAgB,EAC5B,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,iBAAiB,EAAE,MAAM,CAAC,CACrD,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,4BAA4B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CACvF,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { onchainRead, onchainWrite } from '@kasarlabs/ask-starknet-core';
|
|
2
|
+
import { RouteSchemaType } from '../schemas/index.js';
|
|
3
|
+
import { RouteResult } from '../interfaces/index.js';
|
|
4
|
+
export declare class RouteFetchService {
|
|
5
|
+
private tokenService;
|
|
6
|
+
constructor();
|
|
7
|
+
initialize(): Promise<void>;
|
|
8
|
+
fetchRoute(params: RouteSchemaType, env: onchainRead, accountAddress: string): Promise<RouteResult>;
|
|
9
|
+
}
|
|
10
|
+
export declare const getRoute: (env: onchainWrite, params: RouteSchemaType) => Promise<string | {
|
|
11
|
+
status: string;
|
|
12
|
+
error: string;
|
|
13
|
+
}>;
|