diff --git a/package.json b/package.json index 126272b0..1ee3da7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "solana-agent-kit", - "version": "1.3.3", + "version": "1.3.4", "description": "connect any ai agents to solana protocols", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/actions/balance.ts b/src/actions/balance.ts index 107b7095..381b2a5d 100644 --- a/src/actions/balance.ts +++ b/src/actions/balance.ts @@ -5,7 +5,7 @@ import { z } from "zod"; import { get_balance } from "../tools"; const balanceAction: Action = { - name: "solana_balance", + name: "BALANCE_ACTION", similes: [ "check balance", "get wallet balance", diff --git a/src/actions/compressedAirdrop.ts b/src/actions/compressedAirdrop.ts index 4be2fb43..107d3523 100644 --- a/src/actions/compressedAirdrop.ts +++ b/src/actions/compressedAirdrop.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { sendCompressedAirdrop } from "../tools"; const compressedAirdropAction: Action = { - name: "solana_compressed_airdrop", + name: "COMPRESSED_AIRDROP", similes: [ "ZK Compressed airdrop", "Airdrop tokens with compression", diff --git a/src/actions/createGibworkTask.ts b/src/actions/createGibworkTask.ts index 3ff8b12c..12aa809b 100644 --- a/src/actions/createGibworkTask.ts +++ b/src/actions/createGibworkTask.ts @@ -5,7 +5,7 @@ import { PublicKey } from "@solana/web3.js"; import { create_gibwork_task } from "../tools"; const createGibworkTaskAction: Action = { - name: "solana_create_gibwork_task", + name: "CREATE_GIBWORK_TASK", similes: [ "create task", "post job", diff --git a/src/actions/createImage.ts b/src/actions/createImage.ts index 895fefb7..adbf55cf 100644 --- a/src/actions/createImage.ts +++ b/src/actions/createImage.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { create_image } from "../tools/create_image"; const createImageAction: Action = { - name: "solana_create_image", + name: "CREATE_IMAGE", similes: [ "generate image", "create artwork", diff --git a/src/actions/createOpenbookMarket.ts b/src/actions/createOpenbookMarket.ts index dafb5092..ae765594 100644 --- a/src/actions/createOpenbookMarket.ts +++ b/src/actions/createOpenbookMarket.ts @@ -5,7 +5,7 @@ import { PublicKey } from "@solana/web3.js"; import { openbookCreateMarket } from "../tools"; const createOpenbookMarketAction: Action = { - name: "solana_create_openbook_market", + name: "CREATE_OPENBOOK_MARKET", similes: [ "create openbook market", "setup trading market", diff --git a/src/actions/createOrcaSingleSidedWhirlpool.ts b/src/actions/createOrcaSingleSidedWhirlpool.ts index 9b95cdfd..affc445b 100644 --- a/src/actions/createOrcaSingleSidedWhirlpool.ts +++ b/src/actions/createOrcaSingleSidedWhirlpool.ts @@ -20,7 +20,7 @@ const FEE_TIERS = { } as const; const createOrcaSingleSidedWhirlpoolAction: Action = { - name: "solana_create_orca_single_sided_whirlpool", + name: "CREATE_ORCA_SINGLE_SIDED_WHIRLPOOL", similes: [ "create orca whirlpool", "setup orca single sided pool", diff --git a/src/actions/deployCollection.ts b/src/actions/deployCollection.ts index 0ac8e6cf..1ca5e140 100644 --- a/src/actions/deployCollection.ts +++ b/src/actions/deployCollection.ts @@ -10,7 +10,7 @@ interface CollectionOptions { } const deployCollectionAction: Action = { - name: "solana_deploy_collection", + name: "DEPLOY_COLLECTION", similes: [ "create collection", "launch collection", diff --git a/src/actions/deployToken.ts b/src/actions/deployToken.ts index d3650542..3a3f25da 100644 --- a/src/actions/deployToken.ts +++ b/src/actions/deployToken.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { deploy_token } from "../tools"; const deployTokenAction: Action = { - name: "deploy_token", + name: "DEPLOY_TOKEN", similes: [ "create token", "launch token", diff --git a/src/actions/fetchPrice.ts b/src/actions/fetchPrice.ts index 0c453919..b2326718 100644 --- a/src/actions/fetchPrice.ts +++ b/src/actions/fetchPrice.ts @@ -5,7 +5,7 @@ import { PublicKey } from "@solana/web3.js"; import { fetchPrice } from "../tools"; const fetchPriceAction: Action = { - name: "solana_fetch_price", + name: "FETCH_PRICE", similes: [ "get token price", "check price", diff --git a/src/actions/getAllDomainsTLDs.ts b/src/actions/getAllDomainsTLDs.ts index 1eae1aa9..d8d2b642 100644 --- a/src/actions/getAllDomainsTLDs.ts +++ b/src/actions/getAllDomainsTLDs.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { getAllDomainsTLDs } from "../tools"; const getAllDomainsTLDsAction: Action = { - name: "solana_get_all_tlds", + name: "GET_ALL_TLDS", similes: [ "list domain tlds", "get domain extensions", diff --git a/src/actions/getAllRegisteredAllDomains.ts b/src/actions/getAllRegisteredAllDomains.ts index 6ed91406..a4d5688a 100644 --- a/src/actions/getAllRegisteredAllDomains.ts +++ b/src/actions/getAllRegisteredAllDomains.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { getAllRegisteredAllDomains } from "../tools"; const getAllRegisteredAllDomainsAction: Action = { - name: "solana_get_all_registered_all_domains", + name: "GET_ALL_REGISTERED_ALL_DOMAINS", similes: [ "list registered domains", "get all domains", diff --git a/src/actions/getMainAllDomainsDomain.ts b/src/actions/getMainAllDomainsDomain.ts index de35ee22..1071050b 100644 --- a/src/actions/getMainAllDomainsDomain.ts +++ b/src/actions/getMainAllDomainsDomain.ts @@ -5,7 +5,7 @@ import { PublicKey } from "@solana/web3.js"; import { getMainAllDomainsDomain } from "../tools"; const getMainAllDomainsDomainAction: Action = { - name: "solana_get_main_domain", + name: "GET_MAIN_ALL_DOMAINS_DOMAIN", similes: [ "get main domain", "fetch primary domain", diff --git a/src/actions/getOwnedAllDomains.ts b/src/actions/getOwnedAllDomains.ts index 359bf389..e9f294ac 100644 --- a/src/actions/getOwnedAllDomains.ts +++ b/src/actions/getOwnedAllDomains.ts @@ -5,7 +5,7 @@ import { PublicKey } from "@solana/web3.js"; import { getOwnedAllDomains } from "../tools"; const getOwnedAllDomainsAction: Action = { - name: "solana_get_owned_all_domains", + name: "GET_OWNED_ALL_DOMAINS", similes: [ "list owned domains", "get my domains", diff --git a/src/actions/getOwnedDomainsForTLD.ts b/src/actions/getOwnedDomainsForTLD.ts index 1c0b4be9..4343488e 100644 --- a/src/actions/getOwnedDomainsForTLD.ts +++ b/src/actions/getOwnedDomainsForTLD.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { getOwnedDomainsForTLD } from "../tools"; const getOwnedDomainsForTLDAction: Action = { - name: "solana_get_owned_tld_domains", + name: "GET_OWNED_DOMAINS_FOR_TLD", similes: [ "list owned domains for tld", "get my domains for extension", diff --git a/src/actions/getPrimaryDomain.ts b/src/actions/getPrimaryDomain.ts index f678a31d..2655dae4 100644 --- a/src/actions/getPrimaryDomain.ts +++ b/src/actions/getPrimaryDomain.ts @@ -5,7 +5,7 @@ import { PublicKey } from "@solana/web3.js"; import { getPrimaryDomain } from "../tools"; const getPrimaryDomainAction: Action = { - name: "solana_get_domain", + name: "GET_PRIMARY_DOMAIN", similes: [ "get primary domain", "lookup primary domain", diff --git a/src/actions/getTPS.ts b/src/actions/getTPS.ts index b5c09791..490bfb4f 100644 --- a/src/actions/getTPS.ts +++ b/src/actions/getTPS.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { getTPS } from "../tools"; const getTPSAction: Action = { - name: "solana_get_tps", + name: "GET_TPS", similes: [ "get transactions per second", "check network speed", diff --git a/src/actions/getTokenData.ts b/src/actions/getTokenData.ts index f416a0c0..bf820dcf 100644 --- a/src/actions/getTokenData.ts +++ b/src/actions/getTokenData.ts @@ -6,7 +6,7 @@ import { JupiterTokenData } from "../types"; import { getTokenAddressFromTicker, getTokenDataByAddress } from "../tools"; const getTokenDataAction: Action = { - name: "solana_token_data", + name: "GET_TOKEN_DATA", similes: [ "get token info", "token details", diff --git a/src/actions/index.ts b/src/actions/index.ts index cb81ce1c..b66c89e2 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -27,35 +27,35 @@ import raydiumCreateAmmV4Action from "./raydiumCreateAmmV4"; import createOrcaSingleSidedWhirlpoolAction from "./createOrcaSingleSidedWhirlpool"; import launchPumpfunTokenAction from "./launchPumpfunToken"; -export const actions = [ - deployTokenAction, - balanceAction, - transferAction, - deployCollectionAction, - mintNFTAction, - tradeAction, - requestFundsAction, - resolveDomainAction, - getTokenDataAction, - getTPSAction, - fetchPriceAction, - stakeWithJupAction, - registerDomainAction, - lendAssetAction, - createGibworkTaskAction, - resolveSolDomainAction, - pythFetchPriceAction, - getOwnedDomainsForTLDAction, - getPrimaryDomainAction, - getAllDomainsTLDsAction, - getOwnedAllDomainsAction, - createImageAction, - getMainAllDomainsDomainAction, - getAllRegisteredAllDomainsAction, - raydiumCreateCpmmAction, - raydiumCreateAmmV4Action, - createOrcaSingleSidedWhirlpoolAction, - launchPumpfunTokenAction, -]; +export const ACTIONS = { + "DEPLOY_TOKEN_ACTION" : deployTokenAction, + "BALANCE_ACTION" : balanceAction, + "TRANSFER_ACTION" : transferAction, + "DEPLOY_COLLECTION_ACTION" : deployCollectionAction, + "MINT_NFT_ACTION" : mintNFTAction, + "TRADE_ACTION" : tradeAction, + "REQUEST_FUNDS_ACTION" : requestFundsAction, + "RESOLVE_DOMAIN_ACTION" : resolveDomainAction, + "GET_TOKEN_DATA_ACTION" : getTokenDataAction, + "GET_TPS_ACTION" : getTPSAction, + "FETCH_PRICE_ACTION" : fetchPriceAction, + "STAKE_WITH_JUP_ACTION" : stakeWithJupAction, + "REGISTER_DOMAIN_ACTION" : registerDomainAction, + "LEND_ASSET_ACTION" : lendAssetAction, + "CREATE_GIBWORK_TASK_ACTION" : createGibworkTaskAction, + "RESOLVE_SOL_DOMAIN_ACTION" : resolveSolDomainAction, + "PYTH_FETCH_PRICE_ACTION" : pythFetchPriceAction, + "GET_OWNED_DOMAINS_FOR_TLD_ACTION" : getOwnedDomainsForTLDAction, + "GET_PRIMARY_DOMAIN_ACTION" : getPrimaryDomainAction, + "GET_ALL_DOMAINS_TLDS_ACTION" : getAllDomainsTLDsAction, + "GET_OWNED_ALL_DOMAINS_ACTION" : getOwnedAllDomainsAction, + "CREATE_IMAGE_ACTION" : createImageAction, + "GET_MAIN_ALL_DOMAINS_DOMAIN_ACTION" : getMainAllDomainsDomainAction, + "GET_ALL_REGISTERED_ALL_DOMAINS_ACTION" : getAllRegisteredAllDomainsAction, + "RAYDIUM_CREATE_CPMM_ACTION" : raydiumCreateCpmmAction, + "RAYDIUM_CREATE_AMM_V4_ACTION" : raydiumCreateAmmV4Action, + "CREATE_ORCA_SINGLE_SIDED_WHIRLPOOL_ACTION" : createOrcaSingleSidedWhirlpoolAction, + "LAUNCH_PUMPFUN_TOKEN_ACTION" : launchPumpfunTokenAction, +}; export type { Action, ActionExample, Handler } from "../types/action"; diff --git a/src/actions/launchPumpfunToken.ts b/src/actions/launchPumpfunToken.ts index 601bb47f..3c23394e 100644 --- a/src/actions/launchPumpfunToken.ts +++ b/src/actions/launchPumpfunToken.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { launchPumpFunToken } from "../tools"; const launchPumpfunTokenAction: Action = { - name: "solana_launch_pumpfun_token", + name: "LAUNCH_PUMPFUN_TOKEN", similes: [ "create pumpfun token", "launch token on pumpfun", diff --git a/src/actions/lendAsset.ts b/src/actions/lendAsset.ts index 1072acec..9ceb20ee 100644 --- a/src/actions/lendAsset.ts +++ b/src/actions/lendAsset.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { lendAsset } from "../tools"; const lendAssetAction: Action = { - name: "solana_lend_asset", + name: "LEND_ASSET", similes: [ "lend usdc", "deposit for yield", diff --git a/src/actions/mintNFT.ts b/src/actions/mintNFT.ts index 5c3d691b..f04cfb73 100644 --- a/src/actions/mintNFT.ts +++ b/src/actions/mintNFT.ts @@ -5,7 +5,7 @@ import { z } from "zod"; import { mintCollectionNFT } from "../tools"; const mintNFTAction: Action = { - name: "solana_mint_nft", + name: "MINT_NFT", similes: [ "mint nft", "create nft", diff --git a/src/actions/pythFetchPrice.ts b/src/actions/pythFetchPrice.ts index ed3d5be4..8dc11f60 100644 --- a/src/actions/pythFetchPrice.ts +++ b/src/actions/pythFetchPrice.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { pythFetchPrice } from "../tools"; const pythFetchPriceAction: Action = { - name: "solana_pyth_fetch_price", + name: "PYTH_FETCH_PRICE", similes: [ "get pyth price", "check pyth price", diff --git a/src/actions/raydiumCreateAmmV4.ts b/src/actions/raydiumCreateAmmV4.ts index 7d4e37b0..8ad228db 100644 --- a/src/actions/raydiumCreateAmmV4.ts +++ b/src/actions/raydiumCreateAmmV4.ts @@ -6,7 +6,7 @@ import BN from "bn.js"; import { raydiumCreateAmmV4 } from "../tools"; const raydiumCreateAmmV4Action: Action = { - name: "raydium_create_ammV4", + name: "RAYDIUM_CREATE_AMM_V4", similes: [ "create raydium v4 pool", "setup raydium v4 liquidity pool", diff --git a/src/actions/raydiumCreateClmm.ts b/src/actions/raydiumCreateClmm.ts index 277cc06b..dd243227 100644 --- a/src/actions/raydiumCreateClmm.ts +++ b/src/actions/raydiumCreateClmm.ts @@ -7,7 +7,7 @@ import Decimal from "decimal.js"; import { raydiumCreateClmm } from "../tools"; const raydiumCreateClmmAction: Action = { - name: "raydium_create_clmm", + name: "RAYDIUM_CREATE_CLMM", similes: [ "create clmm pool", "create concentrated liquidity pool", diff --git a/src/actions/raydiumCreateCpmm.ts b/src/actions/raydiumCreateCpmm.ts index 28fe82a3..b2159b56 100644 --- a/src/actions/raydiumCreateCpmm.ts +++ b/src/actions/raydiumCreateCpmm.ts @@ -6,7 +6,7 @@ import BN from "bn.js"; import { raydiumCreateCpmm } from "../tools"; const raydiumCreateCpmmAction: Action = { - name: "solana_raydium_create_cpmm", + name: "RAYDIUM_CREATE_CPMM", similes: [ "create raydium pool", "setup raydium liquidity pool", diff --git a/src/actions/registerDomain.ts b/src/actions/registerDomain.ts index b4a6d8d9..55f9354b 100644 --- a/src/actions/registerDomain.ts +++ b/src/actions/registerDomain.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { registerDomain } from "../tools"; const registerDomainAction: Action = { - name: "solana_register_domain", + name: "REGISTER_DOMAIN", similes: [ "register domain", "buy domain", diff --git a/src/actions/requestFunds.ts b/src/actions/requestFunds.ts index 116c15e7..a4a95c2b 100644 --- a/src/actions/requestFunds.ts +++ b/src/actions/requestFunds.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { request_faucet_funds } from "../tools"; const requestFundsAction: Action = { - name: "solana_request_funds", + name: "REQUEST_FUNDS", similes: [ "request sol", "get test sol", diff --git a/src/actions/resolveDomain.ts b/src/actions/resolveDomain.ts index d159141c..e54adea5 100644 --- a/src/actions/resolveDomain.ts +++ b/src/actions/resolveDomain.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { resolveAllDomains } from "../tools"; const resolveDomainAction: Action = { - name: "solana_resolve_all_domains", + name: "RESOLVE_ALL_DOMAINS", similes: [ "resolve domain", "lookup domain", diff --git a/src/actions/resolveSolDomain.ts b/src/actions/resolveSolDomain.ts index 26ebae04..60281e20 100644 --- a/src/actions/resolveSolDomain.ts +++ b/src/actions/resolveSolDomain.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { resolveSolDomain } from "../tools"; const resolveSolDomainAction: Action = { - name: "solana_resolve_sol_domain", + name: "RESOLVE_SOL_DOMAIN", similes: [ "resolve sol domain", "lookup sol domain", diff --git a/src/actions/stakeWithJup.ts b/src/actions/stakeWithJup.ts index 630f0249..7f7680f0 100644 --- a/src/actions/stakeWithJup.ts +++ b/src/actions/stakeWithJup.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { stakeWithJup } from "../tools"; const stakeWithJupAction: Action = { - name: "solana_stake_with_jup", + name: "STAKE_WITH_JUPITER", similes: [ "stake sol", "stake with jupiter", diff --git a/src/actions/tokenDataByTicker.ts b/src/actions/tokenDataByTicker.ts index 3ab3f127..28995a53 100644 --- a/src/actions/tokenDataByTicker.ts +++ b/src/actions/tokenDataByTicker.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { getTokenDataByTicker } from "../tools"; const tokenDataByTickerAction: Action = { - name: "solana_token_data_by_ticker", + name: "GET_TOKEN_DATA_BY_TICKER", similes: [ "token data by ticker", "fetch token info by ticker", diff --git a/src/actions/trade.ts b/src/actions/trade.ts index 397f0ca9..a4c9e480 100644 --- a/src/actions/trade.ts +++ b/src/actions/trade.ts @@ -5,7 +5,7 @@ import { z } from "zod"; import { trade } from "../tools"; const tradeAction: Action = { - name: "solana_trade", + name: "TRADE", similes: [ "swap tokens", "exchange tokens", diff --git a/src/actions/transfer.ts b/src/actions/transfer.ts index cc8a6480..f4206aae 100644 --- a/src/actions/transfer.ts +++ b/src/actions/transfer.ts @@ -5,7 +5,7 @@ import { z } from "zod"; import { transfer } from "../tools"; const transferAction: Action = { - name: "solana_transfer", + name: "TRANSFER", similes: [ "send tokens", "transfer funds", diff --git a/src/index.ts b/src/index.ts index 4ae9056b..8a796621 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,5 @@ export { SolanaAgentKit, createSolanaTools }; export * from "./types"; // Export action system -export * from "./actions"; -export * from "./types/action"; +export { ACTIONS } from "./actions"; export * from "./utils/actionExecutor"; diff --git a/src/types/index.ts b/src/types/index.ts index 5c7786cb..6d31949c 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,4 +1,6 @@ import { PublicKey } from "@solana/web3.js"; +import { SolanaAgentKit } from "../agent"; +import { z } from "zod"; export interface Config { OPENAI_API_KEY?: string; @@ -98,3 +100,56 @@ export interface GibworkCreateTaskReponse { signature?: string | undefined; } +/** + * Example of an action with input and output + */ +export interface ActionExample { + input: Record; + output: Record; + explanation: string; +} + +/** + * Handler function type for executing the action + */ +export type Handler = ( + agent: SolanaAgentKit, + input: Record, +) => Promise>; + +/** + * Main Action interface inspired by ELIZA + * This interface makes it easier to implement actions across different frameworks + */ +export interface Action { + /** + * Unique name of the action + */ + name: string; + + /** + * Alternative names/phrases that can trigger this action + */ + similes: string[]; + + /** + * Detailed description of what the action does + */ + description: string; + + /** + * Array of example inputs and outputs for the action + * Each inner array represents a group of related examples + */ + examples: ActionExample[][]; + + /** + * Zod schema for input validation + */ + schema: z.ZodType; + + /** + * Function that executes the action + */ + handler: Handler; +} diff --git a/src/utils/actionExecutor.ts b/src/utils/actionExecutor.ts index e152ecbe..ed2bd901 100644 --- a/src/utils/actionExecutor.ts +++ b/src/utils/actionExecutor.ts @@ -1,13 +1,13 @@ import { Action } from "../types/action"; import { SolanaAgentKit } from "../agent"; -import { actions } from "../actions"; +import { ACTIONS } from "../actions"; /** * Find an action by its name or one of its similes */ export function findAction(query: string): Action | undefined { const normalizedQuery = query.toLowerCase().trim(); - return actions.find( + return Object.values(ACTIONS).find( (action) => action.name.toLowerCase() === normalizedQuery || action.similes.some((simile) => simile.toLowerCase() === normalizedQuery), diff --git a/test/index.ts b/test/index.ts index a9b115f6..2a3312b7 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1,4 +1,4 @@ -import { SolanaAgentKit } from "../src"; +import { SolanaAgentKit , ACTIONS} from "../src"; import { createSolanaTools } from "../src/langchain"; import { HumanMessage } from "@langchain/core/messages"; import { MemorySaver } from "@langchain/langgraph";