diff --git a/README.md b/README.md index 45bddd76..2dd01d81 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ const signature = await trade( ### Lend Tokens ```typescript -import { lend } from 'solana-agent-kit'; +import { lendAsset } from 'solana-agent-kit'; import { PublicKey } from '@solana/web3.js'; const signature = await lendAsset( diff --git a/package.json b/package.json index db76bcbe..08ce54a9 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "typedoc": "^0.26.11" }, "devDependencies": { - "@types/node": "^22.9.0" + "@types/node": "^22.9.0", + "ts-node": "^10.9.2" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a79d19ce..47f3516f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -54,6 +54,9 @@ importers: '@types/node': specifier: ^22.9.0 version: 22.9.0 + ts-node: + specifier: ^10.9.2 + version: 10.9.2(@types/node@22.9.0)(typescript@5.6.3) packages: @@ -71,6 +74,20 @@ packages: peerDependencies: '@solana/web3.js': ^1.87.3 + '@cspotcode/source-map-support@0.8.1': + resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} + engines: {node: '>=12'} + + '@jridgewell/resolve-uri@3.1.2': + resolution: {integrity: sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==} + engines: {node: '>=6.0.0'} + + '@jridgewell/sourcemap-codec@1.5.0': + resolution: {integrity: sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==} + + '@jridgewell/trace-mapping@0.3.9': + resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==} + '@langchain/core@0.3.18': resolution: {integrity: sha512-IEZCrFs1Xd0J2FTH1D3Lnm3/Yk2r8LSpwDeLYwcCom3rNAK5k4mKQ2rwIpNq3YuqBdrTNMKRO+PopjkP1SB17A==} engines: {node: '>=18'} @@ -318,6 +335,18 @@ packages: '@swc/helpers@0.5.15': resolution: {integrity: sha512-JQ5TuMi45Owi4/BIMAJBoSQoOJu12oOk/gADqlcUL9JEdHB8vyjUSsxqeNXnmXHjYKMi2WcYtezGEEhqUI/E2g==} + '@tsconfig/node10@1.0.11': + resolution: {integrity: sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==} + + '@tsconfig/node12@1.0.11': + resolution: {integrity: sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==} + + '@tsconfig/node14@1.0.3': + resolution: {integrity: sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==} + + '@tsconfig/node16@1.0.4': + resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==} + '@types/connect@3.4.38': resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==} @@ -368,6 +397,15 @@ packages: resolution: {integrity: sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==} engines: {node: '>=6.5'} + acorn-walk@8.3.4: + resolution: {integrity: sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==} + engines: {node: '>=0.4.0'} + + acorn@8.14.0: + resolution: {integrity: sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==} + engines: {node: '>=0.4.0'} + hasBin: true + agentkeepalive@4.5.0: resolution: {integrity: sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==} engines: {node: '>= 8.0.0'} @@ -376,6 +414,9 @@ packages: resolution: {integrity: sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==} engines: {node: '>=10'} + arg@4.1.3: + resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} + argparse@2.0.1: resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} @@ -476,6 +517,9 @@ packages: commander@2.20.3: resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} + create-require@1.1.1: + resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} + decamelize@1.2.0: resolution: {integrity: sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==} engines: {node: '>=0.10.0'} @@ -495,6 +539,10 @@ packages: devlop@1.1.0: resolution: {integrity: sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==} + diff@4.0.2: + resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} + engines: {node: '>=0.3.1'} + dotenv@16.4.5: resolution: {integrity: sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==} engines: {node: '>=12'} @@ -668,6 +716,9 @@ packages: lunr@2.3.9: resolution: {integrity: sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==} + make-error@1.3.6: + resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} + markdown-it@14.1.0: resolution: {integrity: sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==} hasBin: true @@ -832,6 +883,20 @@ packages: trim-lines@3.0.1: resolution: {integrity: sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==} + ts-node@10.9.2: + resolution: {integrity: sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==} + hasBin: true + peerDependencies: + '@swc/core': '>=1.2.50' + '@swc/wasm': '>=1.2.50' + '@types/node': '*' + typescript: '>=2.7' + peerDependenciesMeta: + '@swc/core': + optional: true + '@swc/wasm': + optional: true + tslib@2.8.1: resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} @@ -886,6 +951,9 @@ packages: resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==} hasBin: true + v8-compile-cache-lib@3.0.1: + resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} + vfile-message@4.0.2: resolution: {integrity: sha512-jRDZ1IMLttGj41KcZvlrYAaI3CfqpLpfpf+Mfig13viT6NKvRzWZ+lXz0Y5D60w6uJIBAOGq9mSHf0gktF0duw==} @@ -931,6 +999,10 @@ packages: engines: {node: '>= 14'} hasBin: true + yn@3.1.1: + resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==} + engines: {node: '>=6'} + zod-to-json-schema@3.23.5: resolution: {integrity: sha512-5wlSS0bXfF/BrL4jPAbz9da5hDlDptdEppYfe+x4eIJ7jioqKG9uUxOwPzqof09u/XeVdrgFu29lZi+8XNDJtA==} peerDependencies: @@ -974,6 +1046,19 @@ snapshots: - typescript - utf-8-validate + '@cspotcode/source-map-support@0.8.1': + dependencies: + '@jridgewell/trace-mapping': 0.3.9 + + '@jridgewell/resolve-uri@3.1.2': {} + + '@jridgewell/sourcemap-codec@1.5.0': {} + + '@jridgewell/trace-mapping@0.3.9': + dependencies: + '@jridgewell/resolve-uri': 3.1.2 + '@jridgewell/sourcemap-codec': 1.5.0 + '@langchain/core@0.3.18(openai@4.72.0(zod@3.23.8))': dependencies: ansi-styles: 5.2.0 @@ -1345,6 +1430,14 @@ snapshots: dependencies: tslib: 2.8.1 + '@tsconfig/node10@1.0.11': {} + + '@tsconfig/node12@1.0.11': {} + + '@tsconfig/node14@1.0.3': {} + + '@tsconfig/node16@1.0.4': {} + '@types/connect@3.4.38': dependencies: '@types/node': 22.9.0 @@ -1399,12 +1492,20 @@ snapshots: dependencies: event-target-shim: 5.0.1 + acorn-walk@8.3.4: + dependencies: + acorn: 8.14.0 + + acorn@8.14.0: {} + agentkeepalive@4.5.0: dependencies: humanize-ms: 1.2.1 ansi-styles@5.2.0: {} + arg@4.1.3: {} + argparse@2.0.1: {} asynckit@0.4.0: {} @@ -1500,6 +1601,8 @@ snapshots: commander@2.20.3: {} + create-require@1.1.1: {} + decamelize@1.2.0: {} delay@5.0.0: {} @@ -1512,6 +1615,8 @@ snapshots: dependencies: dequal: 2.0.3 + diff@4.0.2: {} + dotenv@16.4.5: {} emoji-regex-xs@1.0.0: {} @@ -1663,6 +1768,8 @@ snapshots: lunr@2.3.9: {} + make-error@1.3.6: {} + markdown-it@14.1.0: dependencies: argparse: 2.0.1 @@ -1832,6 +1939,24 @@ snapshots: trim-lines@3.0.1: {} + ts-node@10.9.2(@types/node@22.9.0)(typescript@5.6.3): + dependencies: + '@cspotcode/source-map-support': 0.8.1 + '@tsconfig/node10': 1.0.11 + '@tsconfig/node12': 1.0.11 + '@tsconfig/node14': 1.0.3 + '@tsconfig/node16': 1.0.4 + '@types/node': 22.9.0 + acorn: 8.14.0 + acorn-walk: 8.3.4 + arg: 4.1.3 + create-require: 1.1.1 + diff: 4.0.2 + make-error: 1.3.6 + typescript: 5.6.3 + v8-compile-cache-lib: 3.0.1 + yn: 3.1.1 + tslib@2.8.1: {} typedoc@0.26.11(typescript@5.6.3): @@ -1888,6 +2013,8 @@ snapshots: uuid@8.3.2: {} + v8-compile-cache-lib@3.0.1: {} + vfile-message@4.0.2: dependencies: '@types/unist': 3.0.3 @@ -1919,6 +2046,8 @@ snapshots: yaml@2.6.0: {} + yn@3.1.1: {} + zod-to-json-schema@3.23.5(zod@3.23.8): dependencies: zod: 3.23.8 diff --git a/src/tools/lend.ts b/src/tools/lend.ts index 05f7dbe4..5fd85b70 100644 --- a/src/tools/lend.ts +++ b/src/tools/lend.ts @@ -25,18 +25,18 @@ export async function lendAsset( const request = { owner: agent.wallet.publicKey.toBase58(), - mintAddress: asset, - depositAmount: amount, + mintAddress: asset.toBase58(), + depositAmount: amount.toString(), }; - const priority = `?priorityFee=${getPriorityFees(agent.connection)}`; + const priorityFees = await getPriorityFees(agent.connection); + const priority = `?priorityFee=${priorityFees.median}`; const response = await fetch( `${LULO_API}/generate/account/deposit${priority}`, { method: "POST", headers: { - Accept: "application/json", "Content-Type": "application/json", "x-wallet-pubkey": agent.wallet.publicKey.toBase58(), "x-api-key": LULO_API_KEY, diff --git a/src/utils/send_tx.ts b/src/utils/send_tx.ts index 36489e81..593cbc83 100644 --- a/src/utils/send_tx.ts +++ b/src/utils/send_tx.ts @@ -1,5 +1,5 @@ import { SolanaAgentKit } from "../agent"; -import { Transaction, Keypair } from "@solana/web3.js"; +import { Transaction, Keypair, TransactionInstruction } from "@solana/web3.js"; import { Connection, ComputeBudgetProgram } from "@solana/web3.js"; /** @@ -7,7 +7,16 @@ import { Connection, ComputeBudgetProgram } from "@solana/web3.js"; * @param connection - Solana RPC connection * @returns Priority fees statistics and instructions for different fee levels */ -export async function getPriorityFees(connection: Connection) { +export async function getPriorityFees(connection: Connection): Promise<{ + min: number; + median: number; + max: number; + instructions?: { + low: TransactionInstruction; + medium: TransactionInstruction; + high: TransactionInstruction; + }; +}> { try { // Get recent prioritization fees const priorityFees = await connection.getRecentPrioritizationFees(); diff --git a/test/index.ts b/test/index.ts index 72374970..d86324db 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1,48 +1,42 @@ -import { SolanaAgentKit } from "../src"; -import { createSolanaTools } from "../src/langchain"; -import { OpenAI } from "@langchain/openai"; -import { AgentExecutor } from "langchain/agents"; -import { PromptTemplate } from "@langchain/core/prompts"; -import { pull } from "langchain/hub"; -import { createReactAgent } from "langchain/agents"; - -// Initialize SolanaAgentKit -const solanaKit = new SolanaAgentKit( - "", - "https://mainnet.helius-rpc.com/?api-key=" -); - -solanaKit.connection.getRecentPrioritizationFees - -// Create Solana-specific tools -const tools = createSolanaTools(solanaKit); - -(async () => { - // Define a Prompt Template for the Agent - const prompt = await pull("hwchase17/react"); - - // Create an LLM Chain - const llm = new OpenAI({ - modelName: "gpt-4o-mini", - temperature: 0, - }); - - const agent = await createReactAgent({ - llm, - tools, - prompt, - }); - - const agentExecutor = new AgentExecutor({ - agent, - tools, - maxIterations: 50, - }); - - const result = await agentExecutor.invoke({ - input: - "Deploy a token with 6 decimals ", - }); - - console.log(result); -})(); +// import { SolanaAgentKit } from "../src"; +// import { createSolanaTools } from "../src/langchain"; +// import { OpenAI } from "@langchain/openai"; +// import { AgentExecutor } from "langchain/agents"; +// import { PromptTemplate } from "@langchain/core/prompts"; +// import { pull } from "langchain/hub"; +// import { createReactAgent } from "langchain/agents"; + +// // Initialize SolanaAgentKit +// const solanaKit = new SolanaAgentKit(undefined, "rpc-url"); + +// // Create Solana-specific tools +// const tools = createSolanaTools(solanaKit); + +// (async () => { +// // Define a Prompt Template for the Agent +// const prompt = await pull("hwchase17/react"); + +// // Create an LLM Chain +// const llm = new OpenAI({ +// modelName: "gpt-4o-mini", +// temperature: 0, +// }); + +// const agent = await createReactAgent({ +// llm, +// tools, +// prompt, +// }); + +// const agentExecutor = new AgentExecutor({ +// agent, +// tools, +// maxIterations: 50, +// }); + +// const result = await agentExecutor.invoke({ +// input: "Deploy a token with 6 decimals ", +// }); + +// console.log(result); +// })();