diff --git a/typescript/packages/plugins/nansen/package.json b/typescript/packages/plugins/nansen/package.json index 93fb9c24..c2f216aa 100644 --- a/typescript/packages/plugins/nansen/package.json +++ b/typescript/packages/plugins/nansen/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "@goat-sdk/core": "workspace:*", - "zod": "^3.22.4" + "zod": "catalog:" }, "devDependencies": { "tsup": "^8.0.1", diff --git a/typescript/packages/plugins/nansen/src/nansen.service.ts b/typescript/packages/plugins/nansen/src/nansen.service.ts index 37f7d010..e7b30285 100644 --- a/typescript/packages/plugins/nansen/src/nansen.service.ts +++ b/typescript/packages/plugins/nansen/src/nansen.service.ts @@ -1,4 +1,5 @@ import { Tool } from "@goat-sdk/core"; +import type { z } from "zod"; import { GetAddressDetailsParams, GetEntityDetailsParams, @@ -28,7 +29,7 @@ export class NansenService { @Tool({ description: "Get details for a specific address from Nansen", }) - async getAddressDetails(parameters: GetAddressDetailsParams) { + async getAddressDetails(parameters: z.infer) { const { address } = parameters; return this.fetchNansen(`/address/${address}`); } @@ -36,7 +37,7 @@ export class NansenService { @Tool({ description: "Get transactions for a specific address from Nansen", }) - async getAddressTransactions(parameters: GetAddressDetailsParams) { + async getAddressTransactions(parameters: z.infer) { const { address } = parameters; return this.fetchNansen(`/address/${address}/transactions`); } @@ -44,7 +45,7 @@ export class NansenService { @Tool({ description: "Get details for a specific token from Nansen", }) - async getTokenDetails(parameters: GetTokenDetailsParams) { + async getTokenDetails(parameters: z.infer) { const { address, chain } = parameters; return this.fetchNansen(`/token/${chain}/${address}`); } @@ -52,7 +53,7 @@ export class NansenService { @Tool({ description: "Get details for a specific NFT collection or token from Nansen", }) - async getNFTDetails(parameters: GetNFTDetailsParams) { + async getNFTDetails(parameters: z.infer) { const { address, chain, tokenId } = parameters; const endpoint = tokenId ? `/nft/${chain}/${address}/${tokenId}` : `/nft/${chain}/${address}`; return this.fetchNansen(endpoint); @@ -61,7 +62,7 @@ export class NansenService { @Tool({ description: "Check if an address is considered 'smart money' by Nansen", }) - async getSmartMoneyStatus(parameters: GetSmartMoneyParams) { + async getSmartMoneyStatus(parameters: z.infer) { const { address, chain } = parameters; return this.fetchNansen(`/smart-money/${chain}/${address}`); } @@ -69,7 +70,7 @@ export class NansenService { @Tool({ description: "Get details for a specific entity from Nansen", }) - async getEntityDetails(parameters: GetEntityDetailsParams) { + async getEntityDetails(parameters: z.infer) { const { entityId } = parameters; return this.fetchNansen(`/entity/${entityId}`); } @@ -77,7 +78,7 @@ export class NansenService { @Tool({ description: "Get token flow data for a specific exchange", }) - async getExchangeFlows(parameters: GetExchangeFlowsParams) { + async getExchangeFlows(parameters: z.infer) { const { exchange, token, timeframe } = parameters; const tokenParam = token ? `&token=${token}` : ""; return this.fetchNansen(`/exchange/${exchange}/flows?timeframe=${timeframe}${tokenParam}`); @@ -86,7 +87,7 @@ export class NansenService { @Tool({ description: "Get data for a specific Nansen signal", }) - async getSignal(parameters: GetSignalParams) { + async getSignal(parameters: z.infer) { const { signalId, parameters: signalParams } = parameters; const queryParams = signalParams ? `?${new URLSearchParams(signalParams as Record)}` : ""; return this.fetchNansen(`/signal/${signalId}${queryParams}`); diff --git a/typescript/packages/plugins/nansen/src/parameters.ts b/typescript/packages/plugins/nansen/src/parameters.ts index 87139775..a7dad4a7 100644 --- a/typescript/packages/plugins/nansen/src/parameters.ts +++ b/typescript/packages/plugins/nansen/src/parameters.ts @@ -1,65 +1,51 @@ -import { createToolParameters, type ToolParametersStatic } from "@goat-sdk/core"; +import { createToolParameters } from "@goat-sdk/core"; import { z } from "zod"; -const AddressDetailsSchema = z.object({ - address: z.string().describe("Ethereum address to get details for"), -}); -export class GetAddressDetailsParams implements ToolParametersStatic { - static schema = AddressDetailsSchema; - constructor() {} -} +export class GetAddressDetailsParams extends createToolParameters( + z.object({ + address: z.string().describe("Ethereum address to get details for"), + }), +) {} -const TokenDetailsSchema = z.object({ - address: z.string().describe("Token contract address"), - chain: z.enum(["ethereum", "polygon", "bsc"]).describe("Blockchain network"), -}); -export class GetTokenDetailsParams implements ToolParametersStatic { - static schema = TokenDetailsSchema; - constructor() {} -} +export class GetTokenDetailsParams extends createToolParameters( + z.object({ + address: z.string().describe("Token contract address"), + chain: z.enum(["ethereum", "polygon", "bsc"]).describe("Blockchain network"), + }), +) {} -const NFTDetailsSchema = z.object({ - address: z.string().describe("NFT contract address"), - chain: z.enum(["ethereum", "polygon", "bsc"]).describe("Blockchain network"), - tokenId: z.string().optional().describe("Specific NFT token ID"), -}); -export class GetNFTDetailsParams implements ToolParametersStatic { - static schema = NFTDetailsSchema; - constructor() {} -} +export class GetNFTDetailsParams extends createToolParameters( + z.object({ + address: z.string().describe("NFT contract address"), + chain: z.enum(["ethereum", "polygon", "bsc"]).describe("Blockchain network"), + tokenId: z.string().optional().describe("Specific NFT token ID"), + }), +) {} -const SmartMoneySchema = z.object({ - address: z.string().describe("Address to check smart money status"), - chain: z.enum(["ethereum", "polygon", "bsc"]).describe("Blockchain network"), -}); -export class GetSmartMoneyParams implements ToolParametersStatic { - static schema = SmartMoneySchema; - constructor() {} -} +export class GetSmartMoneyParams extends createToolParameters( + z.object({ + address: z.string().describe("Address to check smart money status"), + chain: z.enum(["ethereum", "polygon", "bsc"]).describe("Blockchain network"), + }), +) {} -const EntityDetailsSchema = z.object({ - entityId: z.string().describe("Nansen entity ID"), -}); -export class GetEntityDetailsParams implements ToolParametersStatic { - static schema = EntityDetailsSchema; - constructor() {} -} +export class GetEntityDetailsParams extends createToolParameters( + z.object({ + entityId: z.string().describe("Nansen entity ID"), + }), +) {} -const ExchangeFlowsSchema = z.object({ - exchange: z.string().describe("Exchange name or address"), - token: z.string().optional().describe("Specific token address to filter by"), - timeframe: z.enum(["1h", "24h", "7d", "30d"]).default("24h").describe("Time period for flow data"), -}); -export class GetExchangeFlowsParams implements ToolParametersStatic { - static schema = ExchangeFlowsSchema; - constructor() {} -} +export class GetExchangeFlowsParams extends createToolParameters( + z.object({ + exchange: z.string().describe("Exchange name or address"), + token: z.string().optional().describe("Specific token address to filter by"), + timeframe: z.enum(["1h", "24h", "7d", "30d"]).default("24h").describe("Time period for flow data"), + }), +) {} -const SignalSchema = z.object({ - signalId: z.string().describe("Nansen signal ID"), - parameters: z.record(z.any()).optional().describe("Additional parameters required by the signal"), -}); -export class GetSignalParams implements ToolParametersStatic { - static schema = SignalSchema; - constructor() {} -} +export class GetSignalParams extends createToolParameters( + z.object({ + signalId: z.string().describe("Nansen signal ID"), + parameters: z.record(z.any()).optional().describe("Additional parameters required by the signal"), + }), +) {} diff --git a/typescript/pnpm-lock.yaml b/typescript/pnpm-lock.yaml index fa58859f..4b798324 100644 --- a/typescript/pnpm-lock.yaml +++ b/typescript/pnpm-lock.yaml @@ -1098,8 +1098,8 @@ importers: specifier: workspace:* version: link:../../core zod: - specifier: ^3.22.4 - version: 3.24.1 + specifier: 'catalog:' + version: 3.23.8 devDependencies: tsup: specifier: ^8.0.1