Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
mPaella committed Dec 9, 2024
1 parent 12bd01f commit 7c4be36
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 0 deletions.
33 changes: 33 additions & 0 deletions typescript/packages/plugins/jupiter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@goat-sdk/plugin-jupiter",
"version": "0.0.1",
"files": ["dist/**/*", "README.md", "package.json"],
"scripts": {
"build": "tsup",
"clean": "rm -rf dist",
"test": "vitest run --passWithNoTests"
},
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"dependencies": {
"@jup-ag/api": "6.0.31",
"@goat-sdk/core": "workspace:*",
"zod": "catalog:"
},
"peerDependencies": {
"@jup-ag/api": "6.0.31",
"@goat-sdk/core": "workspace:*"
},
"homepage": "https://ohmygoat.dev",
"repository": {
"type": "git",
"url": "git+https://github.com/goat-sdk/goat.git"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/goat-sdk/goat/issues"
},
"keywords": ["ai", "agents", "web3"]
}
1 change: 1 addition & 0 deletions typescript/packages/plugins/jupiter/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./plugin";
161 changes: 161 additions & 0 deletions typescript/packages/plugins/jupiter/src/parameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import {
QuoteGetSwapModeEnum,
type QuoteResponse,
type SwapInfo,
type SwapPostRequest,
type QuoteGetRequest,
} from "@jup-ag/api";
import { z } from "zod";

export const getQuoteParametersSchema: z.ZodType<QuoteGetRequest> = z.object({
inputMint: z.string().describe("The token to swap from"),
outputMint: z.string().describe("The token to swap to"),
amount: z.number().describe("The amount of tokens to swap"),
slippageBps: z.number().optional().describe("The slippage in bps"),
autoSlippage: z.boolean().optional().describe("Whether to use auto slippage"),
autoSlippageCollisionUsdValue: z.number().optional().describe("The collision USD value for auto slippage"),
computeAutoSlippage: z.boolean().optional().describe("Whether to compute auto slippage"),
maxAutoSlippageBps: z.number().optional().describe("The maximum auto slippage in bps"),
swapMode: z.nativeEnum(QuoteGetSwapModeEnum).optional().describe("The swap mode"),
dexes: z.array(z.string()).optional().describe("The dexes to use"),
excludeDexes: z.array(z.string()).optional().describe("The dexes to exclude"),
restrictIntermediateTokens: z.boolean().optional().describe("Whether to restrict intermediate tokens"),
onlyDirectRoutes: z.boolean().optional().describe("Whether to only use direct routes"),
asLegacyTransaction: z.boolean().optional().describe("Whether to return the transaction as a legacy transaction"),
platformFeeBps: z.number().optional().describe("The platform fee in bps"),
maxAccounts: z.number().optional().describe("The maximum number of accounts"),
minimizeSlippage: z.boolean().optional().describe("Whether to minimize slippage"),
preferLiquidDexes: z.boolean().optional().describe("Whether to prefer liquid dexes"),
tokenCategoryBasedIntermediateTokens: z
.boolean()
.optional()
.describe("Whether to use token category based intermediate tokens"),
});

export const swapInfoSchema: z.ZodType<SwapInfo> = z.object({
ammKey: z.string().describe("The AMM key"),
label: z.string().optional().describe("The label"),
inputMint: z.string().describe("The token to swap from"),
outputMint: z.string().describe("The token to swap to"),
inAmount: z.string().describe("The amount of tokens to swap"),
outAmount: z.string().describe("The amount of tokens to swap"),
feeAmount: z.string().describe("The fee amount"),
feeMint: z.string().describe("The fee mint"),
});

export const quoteResponseSchema: z.ZodType<QuoteResponse> = z.object({
inputMint: z.string().describe("The token to swap from"),
inAmount: z.string().describe("The amount of tokens to swap"),
outputMint: z.string().describe("The token to swap to"),
outAmount: z.string().describe("The amount of tokens to swap"),
otherAmountThreshold: z.string().describe("The amount of tokens to swap"),
swapMode: z.enum(["ExactIn", "ExactOut"]).describe("The swap mode"),
slippageBps: z.number().describe("The slippage in bps"),
computedAutoSlippage: z.number().optional().describe("The computed auto slippage"),
platformFee: z
.object({
amount: z.string().describe("The amount of tokens to swap"),
feeBps: z.number().describe("The platform fee in bps"),
})
.optional()
.describe("The platform fee"),
priceImpactPct: z.string().describe("The price impact in percentage"),
routePlan: z
.array(
z.object({
swapInfo: swapInfoSchema.describe("The swap info"),
percent: z.number().describe("The percent of the route plan step"),
}),
)
.describe("The route plan"),
contextSlot: z.number().optional().describe("The context slot"),
timeTaken: z.number().optional().describe("The time taken"),
});

export const swapParametersSchema: z.ZodType<SwapPostRequest> = z.object({
swapRequest: z.object({
userPublicKey: z.string().describe("The user public key"),
quoteResponse: quoteResponseSchema.describe("The quote response"),
}),
});

// interface QuoteResponse {
// /**
// *
// * @type {string}
// * @memberof QuoteResponse
// */
// inputMint: string;
// /**
// *
// * @type {string}
// * @memberof QuoteResponse
// */
// inAmount: string;
// /**
// *
// * @type {string}
// * @memberof QuoteResponse
// */
// outputMint: string;
// /**
// *
// * @type {string}
// * @memberof QuoteResponse
// */
// outAmount: string;
// /**
// *
// * @type {string}
// * @memberof QuoteResponse
// */
// otherAmountThreshold: string;
// /**
// *
// * @type {SwapMode}
// * @memberof QuoteResponse
// */
// swapMode: SwapMode;
// /**
// *
// * @type {number}
// * @memberof QuoteResponse
// */
// slippageBps: number;
// /**
// *
// * @type {number}
// * @memberof QuoteResponse
// */
// computedAutoSlippage?: number;
// /**
// *
// * @type {PlatformFee}
// * @memberof QuoteResponse
// */
// platformFee?: PlatformFee;
// /**
// *
// * @type {string}
// * @memberof QuoteResponse
// */
// priceImpactPct: string;
// /**
// *
// * @type {Array<RoutePlanStep>}
// * @memberof QuoteResponse
// */
// routePlan: Array<RoutePlanStep>;
// /**
// *
// * @type {number}
// * @memberof QuoteResponse
// */
// contextSlot?: number;
// /**
// *
// * @type {number}
// * @memberof QuoteResponse
// */
// timeTaken?: number;
// }
35 changes: 35 additions & 0 deletions typescript/packages/plugins/jupiter/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Plugin, SolanaWalletClient } from "@goat-sdk/core";
import type { z } from "zod";
import { getQuoteParametersSchema, quoteResponseSchema } from "./parameters";
import { createJupiterApiClient } from "@jup-ag/api";

export function jupiter(): Plugin<SolanaWalletClient> {
return {
name: "jupiter",
supportsSmartWallets: () => false,
supportsChain: (chain) => chain.type === "solana",
getTools: async () => {
return [
{
name: "get_quote",
description: "This {{tool}} gets a quote for a swap on the Jupiter DEX.",
parameters: getQuoteParametersSchema,
method: (walletClient, parameters: z.infer<typeof getQuoteParametersSchema>) =>
createJupiterApiClient().quoteGet(parameters),
},
{
name: "get_swap_transaction",
description: "This {{tool}} returns a transaction to swap tokens on the Jupiter DEX.",
parameters: quoteResponseSchema,
method: (walletClient, parameters: z.infer<typeof quoteResponseSchema>) =>
createJupiterApiClient().swapPost({
swapRequest: {
userPublicKey: walletClient.getAddress(),
quoteResponse: parameters,
},
}),
},
];
},
};
}
6 changes: 6 additions & 0 deletions typescript/packages/plugins/jupiter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../../../tsconfig.base.json",
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
6 changes: 6 additions & 0 deletions typescript/packages/plugins/jupiter/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from "tsup";
import { treeShakableConfig } from "../../../tsup.config.base";

export default defineConfig({
...treeShakableConfig,
});
17 changes: 17 additions & 0 deletions typescript/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7c4be36

Please sign in to comment.