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

token provider #24

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ ANTHROPIC_API_KEY=
WALLET_SECRET_KEY=2eETRBeJFNfxAmPzTxfRynebRjTYK9WBLeAE5JhfxdzAxjJG8ZCbmHX1WadTRdcEpE7HRELVp6cbCfZFY6Qw9BgR
WALLET_PUBLIC_KEY=DM1fSD9KfdJ2jaSmR9NGpPPVcDzBwsYg1STttYc5Bvay


BIRDEYE_API_KEY=

SOL_ADDRESS=So11111111111111111111111111111111111111112
SLIPPAGE=1
RPC_URL=https://api.mainnet-beta.solana.com
RPC_URL=https://api.mainnet-beta.solana.com
HELIUS_API_KEY=
22 changes: 22 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"kuromoji": "^0.1.2",
"libsodium-wrappers": "^0.7.13",
"multer": "^1.4.5-lts.1",
"node-cache": "^5.1.2",
"node-llama-cpp": "^3.0.0-beta.44",
"node-wav": "^0.0.2",
"nodejs-whisper": "^0.1.18",
Expand Down
71 changes: 71 additions & 0 deletions src/providers/token.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { TokenProvider } from "./token";
import NodeCache from "node-cache";

// Mock the dependencies
jest.mock("cross-fetch");
jest.mock("fs");
jest.mock("node-cache");

describe("TokenProvider Tests", () => {
// let connection: Connection;
let tokenProvider: TokenProvider;

beforeEach(() => {
// Initialize the connection and token provider before each test
// connection = new Connection("https://api.mainnet-beta.solana.com");
tokenProvider = new TokenProvider(
"2weMjPLLybRMMva1fM3U31goWWrCpF59CHWNhnCJ9Vyh"
);
});

test("should fetch token security data", async () => {
// Mock the response for the fetchTokenSecurity call
const mockFetchResponse = {
success: true,
data: {
ownerBalance: "100",
creatorBalance: "50",
ownerPercentage: 10,
creatorPercentage: 5,
top10HolderBalance: "200",
top10HolderPercent: 20,
},
};

// Mock fetchWithRetry function
const fetchSpy = jest
.spyOn(tokenProvider as any, "fetchWithRetry")
.mockResolvedValue(mockFetchResponse);

// Run the fetchTokenSecurity method
// const securityData = await tokenProvider.fetchTokenSecurity();

// Check if the data returned is correct
// expect(securityData).toEqual({
// ownerBalance: "100",
// creatorBalance: "50",
// ownerPercentage: 10,
// creatorPercentage: 5,
// top10HolderBalance: "200",
// top10HolderPercent: 20,
// });
//console.log the securityData
// console.log({ securityData });

// const holderList = await tokenProvider.fetchHolderList();

// console.log({ holderList });

// const tradeData = await tokenProvider.fetchTokenTradeData();
// console.log({ tradeData });

// const dexScreenerData = await tokenProvider.fetchDexScreenerData();
// console.log({ dexScreenerData });

const tokenReport = await tokenProvider.getFormattedTokenReport();
console.log({ tokenReport });

// Ensure the mock was called
expect(fetchSpy).toHaveBeenCalled();
});
});
Loading