From a0561992efe1e33f6203f6a551168ded9a00eac4 Mon Sep 17 00:00:00 2001 From: aryan Date: Sun, 17 Nov 2024 23:55:25 +0700 Subject: [PATCH] feat: langchain --- docs/assets/navigation.js | 2 +- docs/assets/search.js | 2 +- docs/classes/SolanaAgentKit.html | 11 +- docs/functions/createSolanaTools.html | 1 + docs/interfaces/CollectionDeployment.html | 3 + docs/interfaces/CollectionOptions.html | 5 + docs/interfaces/Creator.html | 3 + .../interfaces/MintCollectionNFTResponse.html | 3 + docs/modules.html | 5 + package.json | 9 +- pnpm-lock.yaml | 338 ++++++++++++++++++ src/agent/index.ts | 83 +++++ src/index.ts | 81 +---- src/langchain/index.ts | 181 ++++++++++ 14 files changed, 641 insertions(+), 86 deletions(-) create mode 100644 docs/functions/createSolanaTools.html create mode 100644 docs/interfaces/CollectionDeployment.html create mode 100644 docs/interfaces/CollectionOptions.html create mode 100644 docs/interfaces/Creator.html create mode 100644 docs/interfaces/MintCollectionNFTResponse.html create mode 100644 src/agent/index.ts create mode 100644 src/langchain/index.ts diff --git a/docs/assets/navigation.js b/docs/assets/navigation.js index e2b7968..a5b7798 100644 --- a/docs/assets/navigation.js +++ b/docs/assets/navigation.js @@ -1 +1 @@ -window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAAE4uuVipJrShRslIKzs9JzEt0TE/NK/HOLFHSUSpILMlQslJKzkksLk4t1keV18soyc1R0lHKzsxLUbIyNLKojQUAkMWD6UsAAAA=" \ No newline at end of file +window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAAE4XQwQrCMAwG4HfJeTgcOmQ3UbyICrqbeCg1c8UuLWsERfbuMie6YZ2XXPL3S9L9HRivDAnsjBYkpickXiqGAKzgHBKQWjiHLuz2BzkXGgI4KzpCMowmVfCWZkZrlKwMzdFqcyuQWp4ixjITEl3oC3bhaBx74Y2tq/ujvlK9ZImCTemHml7f85Ui/sxbL9ItOmvIoRf8me4bIestsPn91BjdOjq70FNy4VeoK8aj6vAA1ZERvOoBAAA=" \ No newline at end of file diff --git a/docs/assets/search.js b/docs/assets/search.js index 0a99505..4097043 100644 --- a/docs/assets/search.js +++ b/docs/assets/search.js @@ -1 +1 @@ -window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAAE6WWTYvbMBBA/8vsVWQtf9u3thAohV669CLCotpKaqLIqS3vthj/92I7jqRaUAXfgjXvzRCNRuqhqd9byEkP50qUkGM/RSDohUEO32pOBf1wYkJ+qSQg6BoOORScti1rn83l3U954YCWVcgBBrRYI+zfrUUtWtl0hawbF+WTGa/pEVxpw4RcV6oSY88P9cyCFbKqhWtiFb4l7zvlnDn9f0/30O35XmlZNqxtH8irIQ/m971Q9U3DfnWslXvaFUzuO1G61WDFttRRsiuv/7zUZ+a24Wb89syfas4f6DcLtKWGE5MfKaeiYE7ZjfAteS+VkF/3L05JVeyWjLKhoj0yt3GiBW/MWbr9sUukW7YDgkqU7DfkPbyxph37IAd/F+wyQHCsGC/HcT2XgaCoL5dRhKCsi276ebiFfWfjyByD5+hnDxDxkI93URYdDogs8LQwfVgc6ssEYkAE20C8ArEB+oCIbwP9FegbYACIBDYwWIGBAYaASGgDwxUYGmAEiEQ2MFqBkQHGgEhsA+MVGBtgAogkNjBZgYkBpoBIagPTFZgaYAaIZDYwW4GZ2QBjP2Br7+B18+B/umdqH3v/WBpo/jQdgzfWSFZ+no8DIcb93cPr7ZzcXxY9+JD3w6BORd4P2sEY1+bs2oNCebDyYCfPPK8LbV4rWaJkyQMyOd89yhMrT+zkOTH5YxnjSpMqTeqkGQezOErdkSlH5uS43efH6T4/zve50kVKFznp2mlS0nFSniujMk+pPCfVbSRre69vvtvuq3tE02iVYLdSlgefkgTKETygUG83pQqVKvy/6oDgWl0ZrwSDnByG4S8bdGcRHQwAAA=="; \ No newline at end of file +window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAAE6WZ227jNhCG34W+FRLP+Ky7PSBAUXRbtEFvBGPBlWhXiEy5Er3bwPC7F9TBHJp0Qq2udmHN/8+Q/DQUmTOryh81i5Mze8llxmLAdcQkPwgWs7/Kgkv+YS+k+jVXLGKnqmAxSwte16J+tB8//KMOBYv6pyxm7BL1rgvAq2taylpVp1SVVYjlxI4n9hE78kpI5VZqEsMU5zSzFKnKSxma2ISPyfuDF4UImr/JNXR8vq88yypR1wPyEsnA/DidG24q8e9J1OqJn1Khnk4yC6vBKxtTRyaORfn6XL6IsAW348dn/lQWxQDePKIxNeyF+sgLLlMRlN0KH5P3kEv15ek5KKmJHZNRVVzWOxHWTkjwOMb3ea1E9bk88DxsfR3JyDFnYQvbRw7MtiR9sxJciTbyuSwL8zrvTrJBtX50Yt7cD3CxvLp/0kqyF+RSiWrHU1E/do/etLI6323Lu+M1ea/P9TXdSXMUVSqk4nvxbiYrNDSZNT3XfvD7sZlqb8rboPApa/4Jtpx04XdG4tR6J+mpygfkbKNHpqzKV16o14+8zus/ylyqARM58YpHFpS2yz6kDCIZntwP1edm0zlo+Zt1mLhwtNKr+sMb7+W9FBOf/L1hk+HcKarO95KrU/UO9LfFUNlPFUGn/7dcKhP+5en5T1EfS1l7a7obHL4Qepsdbj3pZP7h3h/DvSKE4hlX/GcKMdLBxWwjlstM/MfiM/suqlp/WMUMH2YPGxaxXS6KTJ9/+j6YlofuZcjK9NT8d9uF/S3S5uWLkzb6ccqiZBrh5mEJ6+02Snpx86D5ofcwvzRCYFECPiE4QrCEyKIEfUJ0hGgJZyxKZj7hzBHOLOGcRcncJ5w7wrklXLAoWfiEC0e4sIRLFiVLn3DpCJeWcMWiZOUTrhzhyhKuWZSsfcK1I1xbwg2Lko1PuHGEGxsAzQN42QEXHrihp8HHz48HIJsg0FyAlyFwIQKbItBsgJcjcEECmyTQfICXJXBhApsm0IyAlydwgQKbKNCcgJcpcKECmyrQrICXK3DBApss0LyAly1w4QKbLtDMgJcvcAEDmzDUzKCXMHQJQ5sw1MyglzB0CcObHtU0KX+X8rQpmzDUzKCXMHQJQ5sw1MyglzB0CUObMNTMoJcwdAlDmzDUzKCXMHQJQ5sw1MyglzB0Cet+ara176JSIvul3d6SxBx/zuxrt+nBot+AzwwWLD5fLmaTi88Xss/pZ23yfiP1+OHM+OFsoF9GPjaJJRJLHGhZ9ociMuQVGfIq0M9c9ZHCSF2hNuaqkhRE6gnzaQ7TdXOYVu2Bm7iRFYDAFeiP2MRlTlzmQ1xsHMjYMGxwLQQpueYydmTlwhauNVPtlZ3xWRqfZZDPXqhv/e2XsVkbm3WQjflQJVNEBoVho2o/vIkFGQ+GDUhbmDmWO1VdjxjElzQHDGsO2lfurOo2xmQT5NF+ahMWyTxD2ETTaxViROYJwuapv5TLuks5YkZf2zC0uxvsXXODvWtvsI0hmeywue5uHb7pW4djd+tAFm9KFm8aZEgOscSHdAIM6wRtZ+L60vAlt1ggNYWV1N1OkmknXRfC2q650iU2pBIIK6W5ZiIOhGsIA7v/640xIb06rFXf/iHGWJFlClilbcSO+VEUuRQsTraXy/+LDwbE6hsAAA=="; \ No newline at end of file diff --git a/docs/classes/SolanaAgentKit.html b/docs/classes/SolanaAgentKit.html index 8c278db..7e06b3d 100644 --- a/docs/classes/SolanaAgentKit.html +++ b/docs/classes/SolanaAgentKit.html @@ -1,7 +1,7 @@ SolanaAgentKit | solana-agent-kit

Class SolanaAgentKit

Main class for interacting with Solana blockchain Provides a unified interface for token operations, NFT management, and trading

SolanaAgentKit

-

Constructors

Constructors

Properties

connection wallet wallet_address @@ -9,10 +9,11 @@ Provides a unified interface for token operations, NFT management, and tradingdeployToken getBalance mintNFT +registerDomain requestFaucetFunds trade transfer -

Constructors

Properties

connection: Connection

Solana RPC connection

-
wallet: Keypair

Wallet keypair for signing transactions

-
wallet_address: PublicKey

Public key of the wallet

-

Methods

  • Parameters

    • options: CollectionOptions

    Returns Promise<CollectionDeployment>

  • Parameters

    • decimals: number = DEFAULT_OPTIONS.TOKEN_DECIMALS
    • OptionalinitialSupply: number

    Returns Promise<{
        mint: PublicKey;
        tokenAccount: undefined | PublicKey;
    }>

  • Parameters

    • Optionaltoken_address: PublicKey

    Returns Promise<null | number>

  • Parameters

    • collectionMint: PublicKey
    • metadata: {
          creators?: {
              address: string;
              share: number;
          }[];
          name: string;
          sellerFeeBasisPoints?: number;
          symbol: string;
          uri: string;
      }
      • Optionalcreators?: {
            address: string;
            share: number;
        }[]
      • name: string
      • OptionalsellerFeeBasisPoints?: number
      • symbol: string
      • uri: string
    • Optionalrecipient: PublicKey

    Returns Promise<MintCollectionNFTResponse>

  • Returns Promise<void>

  • Parameters

    • outputMint: PublicKey
    • inputAmount: number
    • OptionalinputMint: PublicKey
    • slippageBps: number = DEFAULT_OPTIONS.SLIPPAGE_BPS

    Returns Promise<string>

  • Parameters

    • to: PublicKey
    • amount: number
    • Optionalmint: PublicKey

    Returns Promise<string>

+

Constructors

  • Parameters

    • private_key: string
    • rpc_url: string = "https://api.mainnet-beta.solana.com"

    Returns SolanaAgentKit

Properties

connection: Connection

Solana RPC connection

+
wallet: Keypair

Wallet keypair for signing transactions

+
wallet_address: PublicKey

Public key of the wallet

+

Methods

  • Parameters

    • decimals: number = DEFAULT_OPTIONS.TOKEN_DECIMALS
    • OptionalinitialSupply: number

    Returns Promise<{
        mint: PublicKey;
        tokenAccount: undefined | PublicKey;
    }>

  • Parameters

    • Optionaltoken_address: PublicKey

    Returns Promise<null | number>

  • Parameters

    • collectionMint: PublicKey
    • metadata: {
          creators?: {
              address: string;
              share: number;
          }[];
          name: string;
          sellerFeeBasisPoints?: number;
          symbol: string;
          uri: string;
      }
      • Optionalcreators?: {
            address: string;
            share: number;
        }[]
      • name: string
      • OptionalsellerFeeBasisPoints?: number
      • symbol: string
      • uri: string
    • Optionalrecipient: PublicKey

    Returns Promise<MintCollectionNFTResponse>

  • Parameters

    • name: string
    • OptionalspaceKB: number

    Returns Promise<string>

  • Returns Promise<void>

  • Parameters

    • outputMint: PublicKey
    • inputAmount: number
    • OptionalinputMint: PublicKey
    • slippageBps: number = DEFAULT_OPTIONS.SLIPPAGE_BPS

    Returns Promise<string>

  • Parameters

    • to: PublicKey
    • amount: number
    • Optionalmint: PublicKey

    Returns Promise<string>

diff --git a/docs/functions/createSolanaTools.html b/docs/functions/createSolanaTools.html new file mode 100644 index 0000000..c98ea81 --- /dev/null +++ b/docs/functions/createSolanaTools.html @@ -0,0 +1 @@ +createSolanaTools | solana-agent-kit

Function createSolanaTools

  • Parameters

    Returns (
        | SolanaBalanceTool
        | SolanaTransferTool
        | SolanaDeployTokenTool
        | SolanaDeployCollectionTool
        | SolanaMintNFTTool
        | SolanaTradeTool
        | SolanaRequestFundsTool
        | SolanaRegisterDomainTool)[]

diff --git a/docs/interfaces/CollectionDeployment.html b/docs/interfaces/CollectionDeployment.html new file mode 100644 index 0000000..c36da7b --- /dev/null +++ b/docs/interfaces/CollectionDeployment.html @@ -0,0 +1,3 @@ +CollectionDeployment | solana-agent-kit

Interface CollectionDeployment

interface CollectionDeployment {
    collectionAddress: PublicKey;
    signature: Uint8Array;
}

Properties

collectionAddress: PublicKey
signature: Uint8Array
diff --git a/docs/interfaces/CollectionOptions.html b/docs/interfaces/CollectionOptions.html new file mode 100644 index 0000000..7c99c76 --- /dev/null +++ b/docs/interfaces/CollectionOptions.html @@ -0,0 +1,5 @@ +CollectionOptions | solana-agent-kit

Interface CollectionOptions

interface CollectionOptions {
    creators?: Creator[];
    name: string;
    royaltyBasisPoints?: number;
    uri: string;
}

Properties

creators?: Creator[]
name: string
royaltyBasisPoints?: number
uri: string
diff --git a/docs/interfaces/Creator.html b/docs/interfaces/Creator.html new file mode 100644 index 0000000..e40897c --- /dev/null +++ b/docs/interfaces/Creator.html @@ -0,0 +1,3 @@ +Creator | solana-agent-kit

Interface Creator

interface Creator {
    address: string;
    percentage: number;
}

Properties

Properties

address: string
percentage: number
diff --git a/docs/interfaces/MintCollectionNFTResponse.html b/docs/interfaces/MintCollectionNFTResponse.html new file mode 100644 index 0000000..9eae721 --- /dev/null +++ b/docs/interfaces/MintCollectionNFTResponse.html @@ -0,0 +1,3 @@ +MintCollectionNFTResponse | solana-agent-kit

Interface MintCollectionNFTResponse

interface MintCollectionNFTResponse {
    metadata: PublicKey;
    mint: PublicKey;
}

Properties

Properties

metadata: PublicKey
mint: PublicKey
diff --git a/docs/modules.html b/docs/modules.html index 86ac98c..41f90bb 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -1,2 +1,7 @@ solana-agent-kit
diff --git a/package.json b/package.json index 0dbd123..5cd5592 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,13 @@ { "name": "solana-agent-kit", "version": "1.0.0", - "description": "", - "main": "index.js", + "description": "A toolkit for interacting with the Solana blockchain using LangChain", + "main": "dist/index.js", + "types": "dist/index.d.ts", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "build": "tsc" + "build": "tsc", + "docs": "typedoc src --out docs" }, "keywords": [], "author": "", @@ -21,6 +23,7 @@ "@solana/spl-token": "^0.4.9", "@solana/web3.js": "^1.95.4", "bs58": "^6.0.0", + "langchain": "^0.3.6", "typedoc": "^0.26.11" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4e16071..ce7fb64 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -38,6 +38,9 @@ importers: bs58: specifier: ^6.0.0 version: 6.0.0 + langchain: + specifier: ^0.3.6 + version: 0.3.6(@langchain/core@0.3.18(openai@4.72.0(zod@3.23.8)))(axios@1.7.7)(openai@4.72.0(zod@3.23.8)) typedoc: specifier: ^0.26.11 version: 0.26.11(typescript@5.6.3) @@ -168,6 +171,22 @@ packages: deprecated: 'Arweave support is deprecated - We recommend migrating to the Irys datachain: https://migrate-to.irys.xyz/' hasBin: true + '@langchain/core@0.3.18': + resolution: {integrity: sha512-IEZCrFs1Xd0J2FTH1D3Lnm3/Yk2r8LSpwDeLYwcCom3rNAK5k4mKQ2rwIpNq3YuqBdrTNMKRO+PopjkP1SB17A==} + engines: {node: '>=18'} + + '@langchain/openai@0.3.13': + resolution: {integrity: sha512-lfiauYttb1Vv1GVGDNZlse8475RUsKm9JJ7X9kMVtYoOQnK8xxzMVSrpW7HYLmJokrtVgF6STwRzNJI2gZ3uBw==} + engines: {node: '>=18'} + peerDependencies: + '@langchain/core': '>=0.2.26 <0.4.0' + + '@langchain/textsplitters@0.1.0': + resolution: {integrity: sha512-djI4uw9rlkAb5iMhtLED+xJebDdAG935AdP4eRTB02R7OB/act55Bj9wsskhZsvuyQRpO4O1wQOp85s6T6GWmw==} + engines: {node: '>=18'} + peerDependencies: + '@langchain/core': '>=0.2.21 <0.4.0' + '@metaplex-foundation/beet-solana@0.3.1': resolution: {integrity: sha512-tgyEl6dvtLln8XX81JyBvWjIiEcjTkUwZbrM5dIobTmoqMuGewSyk9CClno8qsMsFdB5T3jC91Rjeqmu/6xk2g==} @@ -541,18 +560,30 @@ packages: '@types/mdast@4.0.4': resolution: {integrity: sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA==} + '@types/node-fetch@2.6.12': + resolution: {integrity: sha512-8nneRWKCg3rMtF69nLQJnOYUcbafYeFSjqkw3jCRLsqkWFlHaoQrr5mXmofFGOx3DKn7UfmBMyov8ySvLRVldA==} + '@types/node@11.11.6': resolution: {integrity: sha512-Exw4yUWMBXM3X+8oqzJNRqZSwUAaS4+7NdvHqQuFi/d+synz++xmX3QIf+BFqneW8N31R8Ky+sikfZUXq07ggQ==} '@types/node@12.20.55': resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} + '@types/node@18.19.64': + resolution: {integrity: sha512-955mDqvO2vFf/oL7V3WiUtiz+BugyX8uVbaT2H8oj3+8dRyH2FLiNdowe7eNqRM7IOIZvzDH76EoAT+gwm6aIQ==} + '@types/node@22.9.0': resolution: {integrity: sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==} + '@types/retry@0.12.0': + resolution: {integrity: sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==} + '@types/unist@3.0.3': resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==} + '@types/uuid@10.0.0': + resolution: {integrity: sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==} + '@types/uuid@8.3.4': resolution: {integrity: sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==} @@ -569,6 +600,10 @@ packages: resolution: {integrity: sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ==} hasBin: true + abort-controller@3.0.0: + resolution: {integrity: sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==} + engines: {node: '>=6.5'} + aes-js@3.0.0: resolution: {integrity: sha512-H7wUZRn8WpTq9jocdxQ2c8x2sKo9ZVmzfRE13GiNJXfp7NcKYEdvl3vspKjXox6RIG2VtaRe4JFvxG4rqp2Zuw==} @@ -596,6 +631,10 @@ packages: resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} engines: {node: '>=8'} + ansi-styles@5.2.0: + resolution: {integrity: sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==} + engines: {node: '>=10'} + ansicolors@0.3.2: resolution: {integrity: sha512-QXu7BPrP29VllRxH8GwB7x5iX5qWKAAMLqKQGWTeLWVlNHNOpVMJ91dsxQAIWXpjuW5wqvxu3Jd/nRjrJ+0pqg==} @@ -727,6 +766,10 @@ packages: resolution: {integrity: sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw==} engines: {node: '>=6.14.2'} + camelcase@6.3.0: + resolution: {integrity: sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==} + engines: {node: '>=10'} + ccount@2.0.1: resolution: {integrity: sha512-eyrF0jiFpY+3drT6383f1qhkbGsLSifNAjA61IUjZjmLCWjItY6LB9ft9YhoDgwfmclB2zhu51Lc7+95b8NRAg==} @@ -780,6 +823,10 @@ packages: comma-separated-tokens@2.0.3: resolution: {integrity: sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg==} + commander@10.0.1: + resolution: {integrity: sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==} + engines: {node: '>=14'} + commander@12.1.0: resolution: {integrity: sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==} engines: {node: '>=18'} @@ -825,6 +872,10 @@ packages: supports-color: optional: true + decamelize@1.2.0: + resolution: {integrity: sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==} + engines: {node: '>=0.10.0'} + defaults@1.0.4: resolution: {integrity: sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==} @@ -891,6 +942,10 @@ packages: resolution: {integrity: sha512-/Sn9Y0oKl0uqQuvgFk/zQgR7aw1g36qX/jzSQ5lSwlO0GigPymk4eGQfeNTD03w1dPOqfz8V77Cy43jH56pagw==} engines: {node: '>=6.5.0', npm: '>=3'} + event-target-shim@5.0.1: + resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==} + engines: {node: '>=6'} + eventemitter3@4.0.7: resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==} @@ -930,6 +985,9 @@ packages: debug: optional: true + form-data-encoder@1.7.2: + resolution: {integrity: sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A==} + form-data@4.0.0: resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==} engines: {node: '>= 6'} @@ -938,6 +996,10 @@ packages: resolution: {integrity: sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==} engines: {node: '>= 6'} + formdata-node@4.4.1: + resolution: {integrity: sha512-0iirZp3uVDjVGt9p49aTaqjk84TrglENEDuqfdlZQ1roC9CWlPk6Avf8EEnZNcAqPonwkG35x4n3ww/1THYAeQ==} + engines: {node: '>= 12.20'} + graphemesplit@2.4.4: resolution: {integrity: sha512-lKrpp1mk1NH26USxC/Asw4OHbhSQf5XfrWZ+CDv/dFVvd1j17kFgMotdJvOesmHkbFX9P9sBfpH8VogxOWLg8w==} @@ -1030,6 +1092,13 @@ packages: js-sha512@0.8.0: resolution: {integrity: sha512-PWsmefG6Jkodqt+ePTvBZCSMFgN7Clckjd0O7su3I0+BW2QWUTJNzjktHsztGLhncP2h8mcF9V9Y2Ha59pAViQ==} + js-tiktoken@1.0.15: + resolution: {integrity: sha512-65ruOWWXDEZHHbAo7EjOcNxOGasQKbL4Fq3jEr2xsCqSsoOo6VVSqzWQb6PRIqypFSDcma4jO90YP0w5X8qVXQ==} + + js-yaml@4.1.0: + resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==} + hasBin: true + json-bigint@1.0.0: resolution: {integrity: sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==} @@ -1040,10 +1109,68 @@ packages: resolution: {integrity: sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==} engines: {'0': node >= 0.2.0} + jsonpointer@5.0.1: + resolution: {integrity: sha512-p/nXbhSEcu3pZRdkW1OfJhpsVtW1gd4Wa1fnQc9YLiTfAjn0312eMKimbdIQzuZl9aa9xUGaRlP9T/CJE/ditQ==} + engines: {node: '>=0.10.0'} + keccak@3.0.4: resolution: {integrity: sha512-3vKuW0jV8J3XNTzvfyicFR5qvxrSAGl7KIhvgOu5cmWwM7tZRj3fMbj/pfIf4be7aznbc+prBWGjywox/g2Y6Q==} engines: {node: '>=10.0.0'} + langchain@0.3.6: + resolution: {integrity: sha512-erZOIKXzwCOrQHqY9AyjkQmaX62zUap1Sigw1KrwMUOnVoLKkVNRmAyxFlNZDZ9jLs/58MaQcaT9ReJtbj3x6w==} + engines: {node: '>=18'} + peerDependencies: + '@langchain/anthropic': '*' + '@langchain/aws': '*' + '@langchain/cohere': '*' + '@langchain/core': '>=0.2.21 <0.4.0' + '@langchain/google-genai': '*' + '@langchain/google-vertexai': '*' + '@langchain/groq': '*' + '@langchain/mistralai': '*' + '@langchain/ollama': '*' + axios: '*' + cheerio: '*' + handlebars: ^4.7.8 + peggy: ^3.0.2 + typeorm: '*' + peerDependenciesMeta: + '@langchain/anthropic': + optional: true + '@langchain/aws': + optional: true + '@langchain/cohere': + optional: true + '@langchain/google-genai': + optional: true + '@langchain/google-vertexai': + optional: true + '@langchain/groq': + optional: true + '@langchain/mistralai': + optional: true + '@langchain/ollama': + optional: true + axios: + optional: true + cheerio: + optional: true + handlebars: + optional: true + peggy: + optional: true + typeorm: + optional: true + + langsmith@0.2.5: + resolution: {integrity: sha512-dA+l7ZEh1Q9Q9FcE39PUSSEMfsFo73R2V81fRo5KSlGNcypOEhoQvv6lbjyZP7MHmt3/9pPcfpuRd5Y4RbFYqQ==} + peerDependencies: + openai: '*' + peerDependenciesMeta: + openai: + optional: true + linkify-it@5.0.0: resolution: {integrity: sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==} @@ -1154,6 +1281,10 @@ packages: node-addon-api@5.1.0: resolution: {integrity: sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA==} + node-domexception@1.0.0: + resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==} + engines: {node: '>=10.5.0'} + node-fetch@2.7.0: resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==} engines: {node: 4.x || >=6.0.0} @@ -1181,6 +1312,18 @@ packages: oniguruma-to-es@0.1.2: resolution: {integrity: sha512-sBYKVJlIMB0WPO+tSu/NNB1ytSFeHyyJZ3Ayxfx3f/QUuXu0lvZk0VB4K7npmdlHSC0ldqanzh/sUSlAbgCTfw==} + openai@4.72.0: + resolution: {integrity: sha512-hFqG9BWCs7L7ifrhJXw7mJXmUBr7d9N6If3J9563o0jfwVA4wFANFDDaOIWFdgDdwgCXg5emf0Q+LoLCGszQYA==} + hasBin: true + peerDependencies: + zod: ^3.23.8 + peerDependenciesMeta: + zod: + optional: true + + openapi-types@12.1.3: + resolution: {integrity: sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw==} + ora@5.4.1: resolution: {integrity: sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ==} engines: {node: '>=10'} @@ -1189,6 +1332,22 @@ packages: resolution: {integrity: sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==} engines: {node: '>=0.10.0'} + p-finally@1.0.0: + resolution: {integrity: sha512-LICb2p9CB7FS+0eR1oqWnHhp0FljGLZCWBE9aix0Uye9W8LTQPwMTYVGWQWIw9RdQiDg4+epXQODwIYJtSJaow==} + engines: {node: '>=4'} + + p-queue@6.6.2: + resolution: {integrity: sha512-RwFpb72c/BhQLEXIZ5K2e+AhgNVmIejGlTgiB9MzZ0e93GRvqZ7uSi0dvRF7/XIXDeNkra2fNHBxTyPDGySpjQ==} + engines: {node: '>=8'} + + p-retry@4.6.2: + resolution: {integrity: sha512-312Id396EbJdvRONlngUx0NydfrIQ5lsYu0znKVUzVvArzEIt08V1qhtyESbGVd1FGX7UKtiFp5uwKZdM8wIuQ==} + engines: {node: '>=8'} + + p-timeout@3.2.0: + resolution: {integrity: sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==} + engines: {node: '>=8'} + pako@0.2.9: resolution: {integrity: sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA==} @@ -1263,6 +1422,11 @@ packages: resolution: {integrity: sha512-lDFs9AAIaWP9UCdtWrotXWWF9t8PWgQDcxqgAnpM9rMqxb3Oaq2J0thzPVSxBwdJgyQtkU/sYtFtbM1RSt/iYA==} engines: {node: '>=18.0.0'} + semver@7.6.3: + resolution: {integrity: sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==} + engines: {node: '>=10'} + hasBin: true + setprototypeof@1.2.0: resolution: {integrity: sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==} @@ -1374,6 +1538,9 @@ packages: uc.micro@2.1.0: resolution: {integrity: sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==} + undici-types@5.26.5: + resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + undici-types@6.19.8: resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==} @@ -1405,6 +1572,10 @@ packages: util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} + uuid@10.0.0: + resolution: {integrity: sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==} + hasBin: true + uuid@8.3.2: resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==} hasBin: true @@ -1421,6 +1592,10 @@ packages: wcwidth@1.0.1: resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==} + web-streams-polyfill@4.0.0-beta.3: + resolution: {integrity: sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==} + engines: {node: '>= 14'} + web3-utils@1.10.4: resolution: {integrity: sha512-tsu8FiKJLk2PzhDl9fXbGUWTkkVXYhtTA+SmEFkKft+9BgwLxfCRpU96sWv7ICC8zixBNd3JURVoiR3dUXgP8A==} engines: {node: '>=8.0.0'} @@ -1479,6 +1654,14 @@ packages: engines: {node: '>= 14'} hasBin: true + zod-to-json-schema@3.23.5: + resolution: {integrity: sha512-5wlSS0bXfF/BrL4jPAbz9da5hDlDptdEppYfe+x4eIJ7jioqKG9uUxOwPzqof09u/XeVdrgFu29lZi+8XNDJtA==} + peerDependencies: + zod: ^3.23.3 + + zod@3.23.8: + resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==} + zwitch@2.0.4: resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} @@ -1813,6 +1996,37 @@ snapshots: - encoding - utf-8-validate + '@langchain/core@0.3.18(openai@4.72.0(zod@3.23.8))': + dependencies: + ansi-styles: 5.2.0 + camelcase: 6.3.0 + decamelize: 1.2.0 + js-tiktoken: 1.0.15 + langsmith: 0.2.5(openai@4.72.0(zod@3.23.8)) + mustache: 4.2.0 + p-queue: 6.6.2 + p-retry: 4.6.2 + uuid: 10.0.0 + zod: 3.23.8 + zod-to-json-schema: 3.23.5(zod@3.23.8) + transitivePeerDependencies: + - openai + + '@langchain/openai@0.3.13(@langchain/core@0.3.18(openai@4.72.0(zod@3.23.8)))': + dependencies: + '@langchain/core': 0.3.18(openai@4.72.0(zod@3.23.8)) + js-tiktoken: 1.0.15 + openai: 4.72.0(zod@3.23.8) + zod: 3.23.8 + zod-to-json-schema: 3.23.5(zod@3.23.8) + transitivePeerDependencies: + - encoding + + '@langchain/textsplitters@0.1.0(@langchain/core@0.3.18(openai@4.72.0(zod@3.23.8)))': + dependencies: + '@langchain/core': 0.3.18(openai@4.72.0(zod@3.23.8)) + js-tiktoken: 1.0.15 + '@metaplex-foundation/beet-solana@0.3.1(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: '@metaplex-foundation/beet': 0.7.1 @@ -2529,16 +2743,29 @@ snapshots: dependencies: '@types/unist': 3.0.3 + '@types/node-fetch@2.6.12': + dependencies: + '@types/node': 22.9.0 + form-data: 4.0.1 + '@types/node@11.11.6': {} '@types/node@12.20.55': {} + '@types/node@18.19.64': + dependencies: + undici-types: 5.26.5 + '@types/node@22.9.0': dependencies: undici-types: 6.19.8 + '@types/retry@0.12.0': {} + '@types/unist@3.0.3': {} + '@types/uuid@10.0.0': {} + '@types/uuid@8.3.4': {} '@types/ws@7.4.7': @@ -2556,6 +2783,10 @@ snapshots: jsonparse: 1.3.1 through: 2.3.8 + abort-controller@3.0.0: + dependencies: + event-target-shim: 5.0.1 + aes-js@3.0.0: {} agentkeepalive@4.5.0: @@ -2589,6 +2820,8 @@ snapshots: dependencies: color-convert: 2.0.1 + ansi-styles@5.2.0: {} + ansicolors@0.3.2: {} aptos@1.8.5(debug@4.3.7): @@ -2774,6 +3007,8 @@ snapshots: node-gyp-build: 4.8.3 optional: true + camelcase@6.3.0: {} + ccount@2.0.1: {} chalk@4.1.2: @@ -2816,6 +3051,8 @@ snapshots: comma-separated-tokens@2.0.3: {} + commander@10.0.1: {} + commander@12.1.0: {} commander@2.20.3: {} @@ -2864,6 +3101,8 @@ snapshots: dependencies: ms: 2.1.3 + decamelize@1.2.0: {} + defaults@1.0.4: dependencies: clone: 1.0.4 @@ -2934,6 +3173,8 @@ snapshots: bn.js: 4.11.6 number-to-bn: 1.7.0 + event-target-shim@5.0.1: {} + eventemitter3@4.0.7: {} eventemitter3@5.0.1: {} @@ -2963,6 +3204,8 @@ snapshots: optionalDependencies: debug: 4.3.7 + form-data-encoder@1.7.2: {} + form-data@4.0.0: dependencies: asynckit: 0.4.0 @@ -2975,6 +3218,11 @@ snapshots: combined-stream: 1.0.8 mime-types: 2.1.35 + formdata-node@4.4.1: + dependencies: + node-domexception: 1.0.0 + web-streams-polyfill: 4.0.0-beta.3 + graphemesplit@2.4.4: dependencies: js-base64: 3.7.7 @@ -3099,6 +3347,14 @@ snapshots: js-sha512@0.8.0: {} + js-tiktoken@1.0.15: + dependencies: + base64-js: 1.5.1 + + js-yaml@4.1.0: + dependencies: + argparse: 2.0.1 + json-bigint@1.0.0: dependencies: bignumber.js: 9.1.2 @@ -3107,12 +3363,46 @@ snapshots: jsonparse@1.3.1: {} + jsonpointer@5.0.1: {} + keccak@3.0.4: dependencies: node-addon-api: 2.0.2 node-gyp-build: 4.8.3 readable-stream: 3.6.2 + langchain@0.3.6(@langchain/core@0.3.18(openai@4.72.0(zod@3.23.8)))(axios@1.7.7)(openai@4.72.0(zod@3.23.8)): + dependencies: + '@langchain/core': 0.3.18(openai@4.72.0(zod@3.23.8)) + '@langchain/openai': 0.3.13(@langchain/core@0.3.18(openai@4.72.0(zod@3.23.8))) + '@langchain/textsplitters': 0.1.0(@langchain/core@0.3.18(openai@4.72.0(zod@3.23.8))) + js-tiktoken: 1.0.15 + js-yaml: 4.1.0 + jsonpointer: 5.0.1 + langsmith: 0.2.5(openai@4.72.0(zod@3.23.8)) + openapi-types: 12.1.3 + p-retry: 4.6.2 + uuid: 10.0.0 + yaml: 2.6.0 + zod: 3.23.8 + zod-to-json-schema: 3.23.5(zod@3.23.8) + optionalDependencies: + axios: 1.7.7(debug@4.3.7) + transitivePeerDependencies: + - encoding + - openai + + langsmith@0.2.5(openai@4.72.0(zod@3.23.8)): + dependencies: + '@types/uuid': 10.0.0 + commander: 10.0.1 + p-queue: 6.6.2 + p-retry: 4.6.2 + semver: 7.6.3 + uuid: 10.0.0 + optionalDependencies: + openai: 4.72.0(zod@3.23.8) + linkify-it@5.0.0: dependencies: uc.micro: 2.1.0 @@ -3235,6 +3525,8 @@ snapshots: node-addon-api@5.1.0: {} + node-domexception@1.0.0: {} + node-fetch@2.7.0: dependencies: whatwg-url: 5.0.0 @@ -3261,6 +3553,22 @@ snapshots: regex: 4.4.0 regex-recursion: 4.2.1 + openai@4.72.0(zod@3.23.8): + dependencies: + '@types/node': 18.19.64 + '@types/node-fetch': 2.6.12 + abort-controller: 3.0.0 + agentkeepalive: 4.5.0 + form-data-encoder: 1.7.2 + formdata-node: 4.4.1 + node-fetch: 2.7.0 + optionalDependencies: + zod: 3.23.8 + transitivePeerDependencies: + - encoding + + openapi-types@12.1.3: {} + ora@5.4.1: dependencies: bl: 4.1.0 @@ -3275,6 +3583,22 @@ snapshots: os-tmpdir@1.0.2: {} + p-finally@1.0.0: {} + + p-queue@6.6.2: + dependencies: + eventemitter3: 4.0.7 + p-timeout: 3.2.0 + + p-retry@4.6.2: + dependencies: + '@types/retry': 0.12.0 + retry: 0.13.1 + + p-timeout@3.2.0: + dependencies: + p-finally: 1.0.0 + pako@0.2.9: {} pbkdf2@3.1.2: @@ -3356,6 +3680,8 @@ snapshots: node-addon-api: 5.1.0 node-gyp-build: 4.8.3 + semver@7.6.3: {} + setprototypeof@1.2.0: {} sha.js@2.4.11: @@ -3458,6 +3784,8 @@ snapshots: uc.micro@2.1.0: {} + undici-types@5.26.5: {} + undici-types@6.19.8: {} unicode-trie@2.0.0: @@ -3497,6 +3825,8 @@ snapshots: util-deprecate@1.0.2: {} + uuid@10.0.0: {} + uuid@8.3.2: {} vfile-message@4.0.2: @@ -3515,6 +3845,8 @@ snapshots: dependencies: defaults: 1.0.4 + web-streams-polyfill@4.0.0-beta.3: {} + web3-utils@1.10.4: dependencies: '@ethereumjs/util': 8.1.0 @@ -3559,4 +3891,10 @@ snapshots: yaml@2.6.0: {} + zod-to-json-schema@3.23.5(zod@3.23.8): + dependencies: + zod: 3.23.8 + + zod@3.23.8: {} + zwitch@2.0.4: {} diff --git a/src/agent/index.ts b/src/agent/index.ts new file mode 100644 index 0000000..543e10c --- /dev/null +++ b/src/agent/index.ts @@ -0,0 +1,83 @@ +import { Connection, Keypair, PublicKey } from "@solana/web3.js"; +import bs58 from "bs58"; +import { + request_faucet_funds, + deploy_token, + deploy_collection, + get_balance, + mintCollectionNFT, + transfer, + trade, + registerDomain +} from "../tools"; +import { CollectionOptions } from "../types"; +import { DEFAULT_OPTIONS } from "../constants"; + +/** + * Main class for interacting with Solana blockchain + * Provides a unified interface for token operations, NFT management, and trading + * + * @class SolanaAgentKit + * @property {Connection} connection - Solana RPC connection + * @property {Keypair} wallet - Wallet keypair for signing transactions + * @property {PublicKey} wallet_address - Public key of the wallet + */ +export class SolanaAgentKit { + public connection: Connection; + public wallet: Keypair; + public wallet_address: PublicKey; + + constructor( + private_key: string, + rpc_url = "https://api.mainnet-beta.solana.com" + ) { + this.connection = new Connection(rpc_url); + this.wallet = Keypair.fromSecretKey(bs58.decode(private_key)); + this.wallet_address = this.wallet.publicKey; + } + + // Tool methods + async requestFaucetFunds() { + return request_faucet_funds(this); + } + + async deployToken( + decimals: number = DEFAULT_OPTIONS.TOKEN_DECIMALS, + initialSupply?: number + ) { + return deploy_token(this, decimals, initialSupply); + } + + async deployCollection(options: CollectionOptions) { + return deploy_collection(this, options); + } + + async getBalance(token_address?: PublicKey) { + return get_balance(this, token_address); + } + + async mintNFT( + collectionMint: PublicKey, + metadata: Parameters[2], + recipient?: PublicKey + ) { + return mintCollectionNFT(this, collectionMint, metadata, recipient); + } + + async transfer(to: PublicKey, amount: number, mint?: PublicKey) { + return transfer(this, to, amount, mint); + } + + async registerDomain(name: string, spaceKB?: number) { + return registerDomain(this, name, spaceKB); + } + + async trade( + outputMint: PublicKey, + inputAmount: number, + inputMint?: PublicKey, + slippageBps: number = DEFAULT_OPTIONS.SLIPPAGE_BPS + ) { + return trade(this, outputMint, inputAmount, inputMint, slippageBps); + } +} diff --git a/src/index.ts b/src/index.ts index d7047a2..a1fd258 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,78 +1,7 @@ -import { Connection, Keypair, PublicKey } from "@solana/web3.js"; -import bs58 from "bs58"; -import { - request_faucet_funds, - deploy_token, - deploy_collection, - get_balance, - mintCollectionNFT, - transfer, - trade, -} from "./tools"; -import { CollectionOptions } from "./types"; -import { DEFAULT_OPTIONS } from "./constants"; +import { SolanaAgentKit } from './agent'; // Move the SolanaAgentKit class to src/agent.ts +import { createSolanaTools } from './langchain'; -/** - * Main class for interacting with Solana blockchain - * Provides a unified interface for token operations, NFT management, and trading - * - * @class SolanaAgentKit - * @property {Connection} connection - Solana RPC connection - * @property {Keypair} wallet - Wallet keypair for signing transactions - * @property {PublicKey} wallet_address - Public key of the wallet - */ -export class SolanaAgentKit { - public connection: Connection; - public wallet: Keypair; - public wallet_address: PublicKey; +export { SolanaAgentKit, createSolanaTools }; - constructor( - private_key: string, - rpc_url = "https://api.mainnet-beta.solana.com" - ) { - this.connection = new Connection(rpc_url); - this.wallet = Keypair.fromSecretKey(bs58.decode(private_key)); - this.wallet_address = this.wallet.publicKey; - } - - // Tool methods - async requestFaucetFunds() { - return request_faucet_funds(this); - } - - async deployToken( - decimals: number = DEFAULT_OPTIONS.TOKEN_DECIMALS, - initialSupply?: number - ) { - return deploy_token(this, decimals, initialSupply); - } - - async deployCollection(options: CollectionOptions) { - return deploy_collection(this, options); - } - - async getBalance(token_address?: PublicKey) { - return get_balance(this, token_address); - } - - async mintNFT( - collectionMint: PublicKey, - metadata: Parameters[2], - recipient?: PublicKey - ) { - return mintCollectionNFT(this, collectionMint, metadata, recipient); - } - - async transfer(to: PublicKey, amount: number, mint?: PublicKey) { - return transfer(this, to, amount, mint); - } - - async trade( - outputMint: PublicKey, - inputAmount: number, - inputMint?: PublicKey, - slippageBps: number = DEFAULT_OPTIONS.SLIPPAGE_BPS - ) { - return trade(this, outputMint, inputAmount, inputMint, slippageBps); - } -} +// Optional: Export types that users might need +export * from './types'; \ No newline at end of file diff --git a/src/langchain/index.ts b/src/langchain/index.ts new file mode 100644 index 0000000..aa098ed --- /dev/null +++ b/src/langchain/index.ts @@ -0,0 +1,181 @@ +import { Tool } from "langchain/tools"; +import { SolanaAgentKit } from "../index"; +import { PublicKey } from "@solana/web3.js"; + +export class SolanaBalanceTool extends Tool { + name = "solana_balance"; + description = "Get the balance of a Solana wallet or token account. Input can be a token address or empty for SOL balance."; + + constructor(private solanaKit: SolanaAgentKit) { + super(); + } + + async _call(input: string): Promise { + try { + const tokenAddress = input ? new PublicKey(input) : undefined; + const balance = await this.solanaKit.getBalance(tokenAddress); + return `Balance: ${balance}`; + } catch (error: any) { + return `Error getting balance: ${error.message}`; + } + } +} + +export class SolanaTransferTool extends Tool { + name = "solana_transfer"; + description = "Transfer tokens or SOL to another address. Input should be JSON string with: {to: string, amount: number, mint?: string}"; + + constructor(private solanaKit: SolanaAgentKit) { + super(); + } + + async _call(input: string): Promise { + try { + const { to, amount, mint } = JSON.parse(input); + const recipient = new PublicKey(to); + const mintAddress = mint ? new PublicKey(mint) : undefined; + + await this.solanaKit.transfer(recipient, amount, mintAddress); + return `Successfully transferred ${amount} to ${to}`; + } catch (error: any) { + return `Error making transfer: ${error.message}`; + } + } +} + +export class SolanaDeployTokenTool extends Tool { + name = "solana_deploy_token"; + description = "Deploy a new SPL token. Input should be JSON string with: {decimals?: number, initialSupply?: number}"; + + constructor(private solanaKit: SolanaAgentKit) { + super(); + } + + async _call(input: string): Promise { + try { + const { decimals = 9, initialSupply } = JSON.parse(input); + const result = await this.solanaKit.deployToken(decimals, initialSupply); + return `Token deployed successfully. Mint address: ${result.mint.toString()}`; + } catch (error: any) { + return `Error deploying token: ${error.message}`; + } + } +} + +export class SolanaDeployCollectionTool extends Tool { + name = "solana_deploy_collection"; + description = "Deploy a new NFT collection. Input should be JSON with: {name: string, uri: string, royaltyBasisPoints?: number, creators?: Array<{address: string, percentage: number}>}"; + + constructor(private solanaKit: SolanaAgentKit) { + super(); + } + + async _call(input: string): Promise { + try { + const options = JSON.parse(input); + const result = await this.solanaKit.deployCollection(options); + return `Collection deployed successfully. Address: ${result.collectionAddress.toString()}`; + } catch (error: any) { + return `Error deploying collection: ${error.message}`; + } + } +} + +export class SolanaMintNFTTool extends Tool { + name = "solana_mint_nft"; + description = "Mint a new NFT in a collection. Input should be JSON with: {collectionMint: string, metadata: {name: string, symbol: string, uri: string}, recipient?: string}"; + + constructor(private solanaKit: SolanaAgentKit) { + super(); + } + + async _call(input: string): Promise { + try { + const { collectionMint, metadata, recipient } = JSON.parse(input); + const recipientPubkey = recipient ? new PublicKey(recipient) : undefined; + const result = await this.solanaKit.mintNFT( + new PublicKey(collectionMint), + metadata, + recipientPubkey + ); + return `NFT minted successfully. Mint address: ${result.mint.toString()}`; + } catch (error: any) { + return `Error minting NFT: ${error.message}`; + } + } +} + +export class SolanaTradeTool extends Tool { + name = "solana_trade"; + description = "Swap tokens using Jupiter Exchange. Input should be JSON with: {outputMint: string, inputAmount: number, inputMint?: string, slippageBps?: number}"; + + constructor(private solanaKit: SolanaAgentKit) { + super(); + } + + async _call(input: string): Promise { + try { + const { outputMint, inputAmount, inputMint, slippageBps } = JSON.parse(input); + const tx = await this.solanaKit.trade( + new PublicKey(outputMint), + inputAmount, + inputMint ? new PublicKey(inputMint) : undefined, + slippageBps + ); + return `Trade executed successfully. Transaction: ${tx}`; + } catch (error: any) { + return `Error executing trade: ${error.message}`; + } + } +} + +export class SolanaRequestFundsTool extends Tool { + name = "solana_request_funds"; + description = "Request SOL from Solana faucet (devnet/testnet only)"; + + constructor(private solanaKit: SolanaAgentKit) { + super(); + } + + async _call(_input: string): Promise { + try { + await this.solanaKit.requestFaucetFunds(); + return "Successfully requested faucet funds"; + } catch (error: any) { + return `Error requesting funds: ${error.message}`; + } + } +} + +export class SolanaRegisterDomainTool extends Tool { + name = "solana_register_domain"; + description = "Register a .sol domain name. Input should be JSON with: {name: string, spaceKB?: number}"; + + constructor(private solanaKit: SolanaAgentKit) { + super(); + } + + async _call(input: string): Promise { + try { + const { name, spaceKB = 1 } = JSON.parse(input); + const tx = await this.solanaKit.registerDomain(name, spaceKB); + return `Domain registered successfully. Transaction: ${tx}`; + } catch (error: any) { + return `Error registering domain: ${error.message}`; + } + } +} + +// Updated createSolanaTools function +export function createSolanaTools(solanaKit: SolanaAgentKit) { + return [ + new SolanaBalanceTool(solanaKit), + new SolanaTransferTool(solanaKit), + new SolanaDeployTokenTool(solanaKit), + new SolanaDeployCollectionTool(solanaKit), + new SolanaMintNFTTool(solanaKit), + new SolanaTradeTool(solanaKit), + new SolanaRequestFundsTool(solanaKit), + new SolanaRegisterDomainTool(solanaKit), + ]; +} \ No newline at end of file