Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DexScreener API #386

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add latest token profiles action in DexScreener
omaliszewska committed Feb 8, 2025
commit 4373427b1b0e2bc529ff7595a89265b70a27492c
18 changes: 17 additions & 1 deletion typescript/agentkit/src/action-providers/dexscreener/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# CDP (Coinbase Developer Platform) Action Provider
# DexScreener Action Provider

This action provider integrates with the DexScreener API to fetch market data for decentralized exchanges (DEXs). It enables users to retrieve the latest boosted token listings.

## Features

- Fetches the latest boosted tokens from DexScreener.
- Provides token addresses along with their respective network identifiers.

## Future enhancements

- Support for additional DexScreener data





Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { ActionProvider } from "../actionProvider";
import { CreateAction } from "../actionDecorator";
import { Network } from "../../network";
import { DexScreenerSchemas } from "./schemas";
import { fetchLatestBoosts } from "./services";
import { fetchLatestBoosts, fetchLatestTokenProfiles } from "./services";

/**
* DexScreenerActionProvider is an action provider for fetching DEX market data.
@@ -43,6 +43,28 @@ export class DexScreenerActionProvider extends ActionProvider<any> {
}
}

@CreateAction({
name: "get_latest_token_profiles_dexscreener",
description: "This tool allows getting the latest token profiles from DexScreener.",
schema: DexScreenerSchemas.GetLatestTokenProfiles,
})
async getLatestTokenProfiles(
_: any,
args: z.infer<typeof DexScreenerSchemas.GetLatestTokenProfiles>,
): Promise<string> {
try {
const data = await fetchLatestTokenProfiles();

const tokenProfiles = data.map(
token =>
`${token.name} (${token.symbol}) - ${token.tokenAddress} [network: ${token.chainId}]`,
);
return tokenProfiles.join(", ");
} catch (error) {
return this.handleError(error, "latest token profiles from dexscreener");
}
}

/**
* Handles errors uniformly across actions.
*
Original file line number Diff line number Diff line change
@@ -9,6 +9,16 @@ export interface DexScreenerBoostedTokensResponse {
links: Link[];
}

export interface DexScreenerTokenProfileResponse {
url: string;
chainId: string;
tokenAddress: string;
symbol: string;
name: string;
decimals: number;
logoURI?: string;
}

export interface Link {
label?: string; // Some links use "label", while others use "type"
type?: string;
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { z } from "zod";

export const GetLatestBoostedTokens = z.null().describe("This tools does not require input");
export const GetLatestTokenProfiles = z.null().describe("This tool does not require input");

/**
* Exporting schemas as an object.
*/
export const DexScreenerSchemas = {
GetLatestBoostedTokens,
GetLatestTokenProfiles,
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DEXSCREENER_BASE_URL } from "./constants";
import { DexScreenerBoostedTokensResponse } from "./interfaces";
import { DexScreenerTokenProfileResponse } from "./interfaces";

// https://docs.dexscreener.com/api/reference#token-boosts-latest-v1
export const fetchLatestBoosts = async () => {
@@ -18,6 +19,22 @@ export const fetchLatestBoosts = async () => {
return data;
};

export const fetchLatestTokenProfiles = async () => {
const response = await fetch(`${DEXSCREENER_BASE_URL}/token-profiles/latest/v1`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}

const data = (await response.json()) as DexScreenerTokenProfileResponse[];
return data;
};

// Fetch Token Pairs
// export const fetchTokenPairs = async (chainId: string, tokenAddress: string): Promise<any> => {
// try {