Skip to content

Commit

Permalink
chore: update to imperative prompts, remove connection inputs from pl…
Browse files Browse the repository at this point in the history
…ugins (#93)

* Update to imperative prompts, remove connection inputs from plugins

* Add changeset

* Re-create lockfile
  • Loading branch information
0xaguspunk authored Dec 18, 2024
1 parent 5b04a13 commit 608f9f1
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 58 deletions.
15 changes: 15 additions & 0 deletions typescript/.changeset/wicked-lizards-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@goat-sdk/plugin-solana-magiceden": patch
"@goat-sdk/plugin-solana-nfts": patch
"@goat-sdk/plugin-polymarket": patch
"@goat-sdk/plugin-spl-token": patch
"goat-examples-vercel-ai-solana": patch
"@goat-sdk/plugin-jupiter": patch
"@goat-sdk/plugin-meteora": patch
"@goat-sdk/plugin-uniswap": patch
"@goat-sdk/plugin-tensor": patch
"@goat-sdk/wallet-solana": patch
"@goat-sdk/plugin-erc20": patch
---

Move to imperative prompts
2 changes: 1 addition & 1 deletion typescript/examples/vercel-ai/solana/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const keypair = Keypair.fromSecretKey(base58.decode(process.env.SOLANA_PRIVATE_K
keypair,
connection,
}),
plugins: [sendSOL(), jupiter(), splToken({ connection, network: "mainnet" })],
plugins: [sendSOL(), jupiter(), splToken()],
});

const result = await generateText({
Expand Down
12 changes: 6 additions & 6 deletions typescript/packages/plugins/erc20/src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function getTools(walletClient: EVMWalletClient, tokenList: ChainSpecific
const balanceTool = createTool(
{
name: `get_${token.symbol}_balance`,
description: `This {{tool}} gets the balance of ${token.symbol}`,
description: `Get the balance of ${token.symbol}`,
parameters: getBalanceParametersSchema,
},
(parameters: z.infer<typeof getBalanceParametersSchema>) => balanceOf(walletClient, token, parameters),
Expand All @@ -29,7 +29,7 @@ export function getTools(walletClient: EVMWalletClient, tokenList: ChainSpecific
const transferTool = createTool(
{
name: `transfer_${token.symbol}`,
description: `This {{tool}} transfers ${token.symbol} to the specified address`,
description: `Transfer ${token.symbol} to the specified address`,
parameters: transferParametersSchema,
},
(parameters: z.infer<typeof transferParametersSchema>) => transfer(walletClient, token, parameters),
Expand All @@ -38,7 +38,7 @@ export function getTools(walletClient: EVMWalletClient, tokenList: ChainSpecific
const totalSupplyTool = createTool(
{
name: `get_${token.symbol}_total_supply`,
description: `This {{tool}} gets the total supply of ${token.symbol}`,
description: `Get the total supply of ${token.symbol}`,
parameters: totalSupplyParametersSchema,
},
(parameters: z.infer<typeof totalSupplyParametersSchema>) => totalSupply(walletClient, token),
Expand All @@ -47,7 +47,7 @@ export function getTools(walletClient: EVMWalletClient, tokenList: ChainSpecific
const allowanceTool = createTool(
{
name: `get_${token.symbol}_allowance`,
description: `This {{tool}} gets the allowance of ${token.symbol}`,
description: `Get the allowance of ${token.symbol}`,
parameters: allowanceParametersSchema,
},
(parameters: z.infer<typeof allowanceParametersSchema>) => allowance(walletClient, token, parameters),
Expand All @@ -56,7 +56,7 @@ export function getTools(walletClient: EVMWalletClient, tokenList: ChainSpecific
const approveTool = createTool(
{
name: `approve_${token.symbol}`,
description: `This {{tool}} approves the allowance of ${token.symbol}`,
description: `Approve the allowance of ${token.symbol}`,
parameters: approveParametersSchema,
},
(parameters: z.infer<typeof approveParametersSchema>) => approve(walletClient, token, parameters),
Expand All @@ -65,7 +65,7 @@ export function getTools(walletClient: EVMWalletClient, tokenList: ChainSpecific
const transferFromTool = createTool(
{
name: `transfer_${token.symbol}_from`,
description: `This {{tool}} transfers ${token.symbol} from the specified address`,
description: `Transfer ${token.symbol} from the specified address`,
parameters: transferFromParametersSchema,
},
(parameters: z.infer<typeof transferFromParametersSchema>) => transferFrom(walletClient, token, parameters),
Expand Down
4 changes: 2 additions & 2 deletions typescript/packages/plugins/jupiter/src/jupiter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class JupiterService {
}

@Tool({
description: "Gets a quote for a swap on the Jupiter DEX.",
description: "Get a quote for a swap on the Jupiter DEX",
})
async getQuote(parameters: GetQuoteParameters) {
try {
Expand All @@ -31,7 +31,7 @@ export class JupiterService {
}

@Tool({
description: "Swap an SPL token for another token on the Jupiter DEX.",
description: "Swap an SPL token for another token on the Jupiter DEX",
})
async swapTokens(walletClient: SolanaWalletClient, parameters: GetQuoteParameters) {
const quoteResponse = await this.getQuote(parameters);
Expand Down
2 changes: 1 addition & 1 deletion typescript/packages/plugins/meteora/src/meteora.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CreateDLMMPositionParameters } from "./parameters";

export class MeteoraService {
@Tool({
description: "Creates a position on the Meteora DEX.",
description: "Create a position on the Meteora DEX",
})
async createDLMMPosition(walletClient: SolanaWalletClient, parameters: CreateDLMMPositionParameters) {
const newPosition = new Keypair();
Expand Down
12 changes: 6 additions & 6 deletions typescript/packages/plugins/polymarket/src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,47 @@ export function getTools(walletClient: EVMWalletClient, { credentials }: Polymar
createTool(
{
name: "get_polymarket_events",
description: "This {{tool}} gets the events on Polymarket including their markets",
description: "Get the events on Polymarket including their markets",
parameters: getEventsParametersSchema,
},
(parameters) => getEvents(parameters),
),
createTool(
{
name: "get_polymarket_market_info",
description: "This {{tool}} gets the info of a specific market on Polymarket",
description: "Get the info of a specific market on Polymarket",
parameters: getMarketInfoParametersSchema,
},
(parameters) => getMarketInfo(walletClient, parameters),
),
createTool(
{
name: "create_order_on_polymarket",
description: "This {{tool}} creates an order on Polymarket",
description: "Create an order on Polymarket",
parameters: createOrderParametersSchema,
},
(parameters) => createOrder(walletClient, credentials, parameters),
),
createTool(
{
name: "get_active_polymarket_orders",
description: "This {{tool}} gets the active orders on Polymarket",
description: "Get the active orders on Polymarket",
parameters: getOpenOrdersParametersSchema,
},
(parameters) => getOpenOrders(walletClient, credentials, parameters),
),
createTool(
{
name: "cancel_polymarket_order",
description: "This {{tool}} cancels an order on Polymarket",
description: "Cancel an order on Polymarket",
parameters: cancelOrderParametersSchema,
},
(parameters) => cancelOrder(walletClient, credentials, parameters),
),
createTool(
{
name: "cancel_all_polymarket_orders",
description: "This {{tool}} cancels all orders on Polymarket",
description: "Cancel all orders on Polymarket",
parameters: cancelAllOrdersParametersSchema,
},
(_parameters) => cancelAllOrders(walletClient, credentials),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class MagicEdenService {
constructor(private readonly apiKey?: string) {}

@Tool({
description: "Get information about a Solana NFT from the Magic Eden API",
description: "Get information about an NFT from the Magic Eden API",
})
async getNftListings(parameters: GetNftInfoParametersSchema) {
let nftInfo: z.infer<typeof getNftInfoResponseSchema>;
Expand All @@ -38,7 +38,7 @@ export class MagicEdenService {
}

@Tool({
description: "Gets a transaction to buy a Solana NFT from a listing from the Magic Eden API",
description: "Get a transaction to buy an NFT from a listing from the Magic Eden API",
})
async getBuyListingTransaction(walletClient: SolanaWalletClient, parameters: GetNftInfoParametersSchema) {
const nftInfo = await this.getNftListings(parameters);
Expand Down Expand Up @@ -71,7 +71,7 @@ export class MagicEdenService {

const versionedTransaction = VersionedTransaction.deserialize(Buffer.from(data.v0.tx.data));
const instructions = await decompileVersionedTransactionToInstructions(
walletClient.connection,
walletClient.getConnection(),
versionedTransaction,
);
const lookupTableAddresses = versionedTransaction.message.addressTableLookups.map(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { type Chain, PluginBase } from "@goat-sdk/core";
import type { Connection } from "@solana/web3.js";
import { SolanaNftsService } from "./solana-nfts.service";

export class SolanaNftsPlugin extends PluginBase {
constructor(connection: Connection) {
super("solana-nfts", [new SolanaNftsService(connection)]);
constructor() {
super("solana-nfts", [new SolanaNftsService()]);
}

supportsChain = (chain: Chain) => chain.type === "solana";
}

export const nfts = (connection: Connection) => new SolanaNftsPlugin(connection);
export const nfts = () => new SolanaNftsPlugin();
17 changes: 6 additions & 11 deletions typescript/packages/plugins/solana-nfts/src/solana-nfts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,24 @@ import { SolanaWalletClient } from "@goat-sdk/wallet-solana";
import { transfer } from "@metaplex-foundation/mpl-bubblegum";
import { getAssetWithProof } from "@metaplex-foundation/mpl-bubblegum";
import { mplBubblegum } from "@metaplex-foundation/mpl-bubblegum";
import { type Umi, publicKey } from "@metaplex-foundation/umi";
import { publicKey } from "@metaplex-foundation/umi";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { toWeb3JsInstruction } from "@metaplex-foundation/umi-web3js-adapters";
import type { Connection } from "@solana/web3.js";
import { TransferNftParameters } from "./parameters";

export class SolanaNftsService {
umi: Umi;
constructor(private readonly connection: Connection) {
this.umi = createUmi(connection);
}

@Tool({
description: "Sends an NFT from your wallet to an address on a Solana chain.",
description: "Send an NFT from your wallet to another address",
})
async transferNFT(walletClient: SolanaWalletClient, parameters: TransferNftParameters) {
const { recipientAddress, assetId } = parameters;
const umi = this.umi.use(mplBubblegum());
const umi = createUmi(walletClient.getConnection());
const bubbleGumUni = umi.use(mplBubblegum());

const assetWithProof = await getAssetWithProof(this.umi, publicKey(assetId), {
const assetWithProof = await getAssetWithProof(umi, publicKey(assetId), {
truncateCanopy: true,
});
const instructions = transfer(umi, {
const instructions = transfer(bubbleGumUni, {
...assetWithProof,
leafOwner: publicKey(walletClient.getAddress()),
newLeafOwner: publicKey(recipientAddress),
Expand Down
4 changes: 2 additions & 2 deletions typescript/packages/plugins/spl-token/src/spl-token.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { SplTokenService } from "./spl-token.service";
import type { SplTokenPluginCtorParams } from "./types/SplTokenPluginCtorParams";

export class SplTokenPlugin extends PluginBase {
constructor(params: SplTokenPluginCtorParams) {
constructor(params?: SplTokenPluginCtorParams) {
super("splToken", [new SplTokenService(params)]);
}

supportsChain = (chain: Chain) => chain.type === "solana";
}

export const splToken = (params: SplTokenPluginCtorParams) => new SplTokenPlugin(params);
export const splToken = (params?: SplTokenPluginCtorParams) => new SplTokenPlugin(params);
25 changes: 13 additions & 12 deletions typescript/packages/plugins/spl-token/src/spl-token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
createTransferCheckedInstruction,
getAssociatedTokenAddressSync,
} from "@solana/spl-token";
import { type Connection, PublicKey, type TransactionInstruction } from "@solana/web3.js";
import { PublicKey, type TransactionInstruction } from "@solana/web3.js";
import {
ConvertToBaseUnitParameters,
GetTokenBalanceByMintAddressParameters,
Expand All @@ -18,18 +18,16 @@ import { doesAccountExist } from "./utils/doesAccountExist";
import { getTokenByMintAddress } from "./utils/getTokenByMintAddress";

export class SplTokenService {
private connection: Connection;
private network: SolanaNetwork;
private tokens: Token[];

constructor({ network, tokens = SPL_TOKENS, connection }: SplTokenPluginCtorParams) {
constructor({ network = "mainnet", tokens = SPL_TOKENS }: SplTokenPluginCtorParams = {}) {
this.network = network;
this.tokens = tokens;
this.connection = connection;
}

@Tool({
description: "Gets the SPL token info by its symbol, including the mint address, decimals, and name",
description: "Get the SPL token info by its symbol, including the mint address, decimals, and name",
})
async getTokenInfoBySymbol(parameters: GetTokenMintAddressBySymbolParameters) {
const token = this.tokens.find((token) =>
Expand All @@ -44,17 +42,20 @@ export class SplTokenService {
}

@Tool({
description: "Gets the balance of an SPL token by its mint address",
description: "Get the balance of an SPL token by its mint address",
})
async getTokenBalanceByMintAddress(parameters: GetTokenBalanceByMintAddressParameters) {
async getTokenBalanceByMintAddress(
walletClient: SolanaWalletClient,
parameters: GetTokenBalanceByMintAddressParameters,
) {
const { walletAddress, mintAddress } = parameters;
const tokenAccount = getAssociatedTokenAddressSync(new PublicKey(mintAddress), new PublicKey(walletAddress));
const balance = await this.connection.getTokenAccountBalance(tokenAccount);
const balance = walletClient.getConnection().getTokenAccountBalance(tokenAccount);
return balance;
}

@Tool({
description: "Transfers an SPL token by its mint address.",
description: "Transfer an SPL token by its mint address",
})
async transferTokenByMintAddress(
walletClient: SolanaWalletClient,
Expand All @@ -74,8 +75,8 @@ export class SplTokenService {
const fromTokenAccount = getAssociatedTokenAddressSync(tokenMintPublicKey, fromPublicKey);
const toTokenAccount = getAssociatedTokenAddressSync(tokenMintPublicKey, toPublicKey);

const fromAccountExists = await doesAccountExist(this.connection, fromTokenAccount);
const toAccountExists = await doesAccountExist(this.connection, toTokenAccount);
const fromAccountExists = await doesAccountExist(walletClient.getConnection(), fromTokenAccount);
const toAccountExists = await doesAccountExist(walletClient.getConnection(), toTokenAccount);

if (!fromAccountExists) {
throw new Error(`From account ${fromTokenAccount.toBase58()} does not exist`);
Expand Down Expand Up @@ -103,7 +104,7 @@ export class SplTokenService {
}

@Tool({
description: "Converts an amount of an SPL token to its base unit",
description: "Convert an amount of an SPL token to its base unit",
})
async convertToBaseUnit(parameters: ConvertToBaseUnitParameters) {
const { amount, decimals } = parameters;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Connection } from "@solana/web3.js";
import { SolanaNetwork, Token } from "../tokens";

export interface SplTokenPluginCtorParams {
connection: Connection;
network: SolanaNetwork;
network?: SolanaNetwork;
tokens?: Token[];
}
6 changes: 3 additions & 3 deletions typescript/packages/plugins/tensor/src/tensor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class TensorService {
constructor(private readonly apiKey: string) {}

@Tool({
description: "Gets information about a Solana NFT, from the Tensor API",
description: "Get information about an NFT from the Tensor API",
})
async getNftInfo(parameters: GetNftInfoParameters) {
let nftInfo: z.infer<typeof getNftInfoResponseSchema>;
Expand All @@ -29,7 +29,7 @@ export class TensorService {
}

@Tool({
description: "Gets a transaction to buy an NFT from a listing from the Tensor API",
description: "Get a transaction to buy an NFT from a listing from the Tensor API",
})
async getBuyListingTransaction(walletClient: SolanaWalletClient, parameters: GetNftInfoParameters) {
const nftInfo = await this.getNftInfo(parameters);
Expand Down Expand Up @@ -65,7 +65,7 @@ export class TensorService {
}

const { versionedTransaction, instructions } = await deserializeTxResponseToInstructions(
walletClient.connection,
walletClient.getConnection(),
data,
);
const lookupTableAddresses = versionedTransaction.message.addressTableLookups.map(
Expand Down
6 changes: 3 additions & 3 deletions typescript/packages/plugins/uniswap/src/uniswap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class UniswapService {

@Tool({
description:
"Checks if the wallet has enough approval for a token and returns the transaction to approve the token. The approval must takes place before the swap transaction.",
"Check if the wallet has enough approval for a token and return the transaction to approve the token. The approval must takes place before the swap transaction.",
})
async checkApproval(parameters: CheckApprovalBodySchema) {
const url = new URL(`${this.params.baseUrl}/check_approval`);
Expand All @@ -28,7 +28,7 @@ export class UniswapService {

@Tool({
description:
"Gets the quote for a swap. If permitData is returned, it needs to be signed using the signedTypedData tool.",
"Get the quote for a swap. If permitData is returned, it needs to be signed using the signedTypedData tool.",
})
async getQuote(parameters: GetQuoteBodySchema) {
const url = new URL(`${this.params.baseUrl}/quote`);
Expand All @@ -49,7 +49,7 @@ export class UniswapService {

@Tool({
description:
"Gets the swap transaction for a swap. If permitData was returned from the get_quote tool, it needs to be signed using the signedTypedData tool before calling this function.",
"Get the swap transaction for a swap. If permitData was returned from the get_quote tool, it needs to be signed using the signedTypedData tool before calling this function.",
})
async getSwapTransaction(parameters: GetSwapBodySchema) {
const url = new URL(`${this.params.baseUrl}/swap`);
Expand Down
Loading

0 comments on commit 608f9f1

Please sign in to comment.