Skip to content

Commit

Permalink
fix(plugin-nansen): update parameter types to use z.infer for better …
Browse files Browse the repository at this point in the history
…type safety

Co-Authored-By: Alfonso Gomez Jordana Manas <[email protected]>
  • Loading branch information
1 parent e28f35d commit 5f28ddc
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 68 deletions.
2 changes: 1 addition & 1 deletion typescript/packages/plugins/nansen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@goat-sdk/core": "workspace:*",
"zod": "^3.22.4"
"zod": "catalog:"
},
"devDependencies": {
"tsup": "^8.0.1",
Expand Down
17 changes: 9 additions & 8 deletions typescript/packages/plugins/nansen/src/nansen.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Tool } from "@goat-sdk/core";
import type { z } from "zod";
import {
GetAddressDetailsParams,
GetEntityDetailsParams,
Expand Down Expand Up @@ -28,31 +29,31 @@ export class NansenService {
@Tool({
description: "Get details for a specific address from Nansen",
})
async getAddressDetails(parameters: GetAddressDetailsParams) {
async getAddressDetails(parameters: z.infer<typeof GetAddressDetailsParams.schema>) {
const { address } = parameters;
return this.fetchNansen(`/address/${address}`);
}

@Tool({
description: "Get transactions for a specific address from Nansen",
})
async getAddressTransactions(parameters: GetAddressDetailsParams) {
async getAddressTransactions(parameters: z.infer<typeof GetAddressDetailsParams.schema>) {
const { address } = parameters;
return this.fetchNansen(`/address/${address}/transactions`);
}

@Tool({
description: "Get details for a specific token from Nansen",
})
async getTokenDetails(parameters: GetTokenDetailsParams) {
async getTokenDetails(parameters: z.infer<typeof GetTokenDetailsParams.schema>) {
const { address, chain } = parameters;
return this.fetchNansen(`/token/${chain}/${address}`);
}

@Tool({
description: "Get details for a specific NFT collection or token from Nansen",
})
async getNFTDetails(parameters: GetNFTDetailsParams) {
async getNFTDetails(parameters: z.infer<typeof GetNFTDetailsParams.schema>) {
const { address, chain, tokenId } = parameters;
const endpoint = tokenId ? `/nft/${chain}/${address}/${tokenId}` : `/nft/${chain}/${address}`;
return this.fetchNansen(endpoint);
Expand All @@ -61,23 +62,23 @@ export class NansenService {
@Tool({
description: "Check if an address is considered 'smart money' by Nansen",
})
async getSmartMoneyStatus(parameters: GetSmartMoneyParams) {
async getSmartMoneyStatus(parameters: z.infer<typeof GetSmartMoneyParams.schema>) {
const { address, chain } = parameters;
return this.fetchNansen(`/smart-money/${chain}/${address}`);
}

@Tool({
description: "Get details for a specific entity from Nansen",
})
async getEntityDetails(parameters: GetEntityDetailsParams) {
async getEntityDetails(parameters: z.infer<typeof GetEntityDetailsParams.schema>) {
const { entityId } = parameters;
return this.fetchNansen(`/entity/${entityId}`);
}

@Tool({
description: "Get token flow data for a specific exchange",
})
async getExchangeFlows(parameters: GetExchangeFlowsParams) {
async getExchangeFlows(parameters: z.infer<typeof GetExchangeFlowsParams.schema>) {
const { exchange, token, timeframe } = parameters;
const tokenParam = token ? `&token=${token}` : "";
return this.fetchNansen(`/exchange/${exchange}/flows?timeframe=${timeframe}${tokenParam}`);
Expand All @@ -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<typeof GetSignalParams.schema>) {
const { signalId, parameters: signalParams } = parameters;
const queryParams = signalParams ? `?${new URLSearchParams(signalParams as Record<string, string>)}` : "";
return this.fetchNansen(`/signal/${signalId}${queryParams}`);
Expand Down
100 changes: 43 additions & 57 deletions typescript/packages/plugins/nansen/src/parameters.ts
Original file line number Diff line number Diff line change
@@ -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<typeof AddressDetailsSchema> {
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<typeof TokenDetailsSchema> {
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<typeof NFTDetailsSchema> {
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<typeof SmartMoneySchema> {
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<typeof EntityDetailsSchema> {
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<typeof ExchangeFlowsSchema> {
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<typeof SignalSchema> {
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"),
}),
) {}
4 changes: 2 additions & 2 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 5f28ddc

Please sign in to comment.