Skip to content

Commit

Permalink
Marketdata Checker
Browse files Browse the repository at this point in the history
  • Loading branch information
kryptobrah committed Jun 14, 2024
1 parent a6cf265 commit 620640e
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/marketdata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@degenfrends/solana-rugchecker': patch
---

## @degenfrends/solana-rugchecker: Initial version
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ from https://api.raydium.io/v2/sdk/liquidity/mainnet.json and set the path of th
```typescript
const rugCheckConfig = {
solanaRpcEndpoint: 'https://api.devnet.solana.com'
poolFilePath: './mainnet.json'
poolFilePath: './mainnet.json' //optional
poolAddress: '12345pooladdress' //optional, can't be set with environment variable, since it most likely changes on every check
heliusApiKey: 'your-api-key' //optional
};
const rugChecker = new SPLRugchecker(rugCheckConfig);
```
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const WebsiteChecker = require('./dist/index.js').WebsiteChecker;
async function main() {
const rugCheckConfig = {
solanaRpcEndpoint: 'https://solana-mainnet.rpc.extrnode.com/036e028d-7094-4f3d-876e-956d6e56f0ff',
heliusApiKey: '123456'
heliusApiKey: '123456-your-api-key'
//poolFilePath: './all_pools.json'
};
const rugChecker = new SPLRugchecker(rugCheckConfig);
Expand Down
2 changes: 1 addition & 1 deletion src/checker/holders-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class HoldersChecker {
holdersCheckResult.topHolders = topHolders;
holdersCheckResult.topHoldersPercentage = topHoldersPercentage;
holdersCheckResult.raydiumPercentage = raydiumPercentage;

holdersCheckResult.address = tokenAddress;
return holdersCheckResult;
}
}
2 changes: 1 addition & 1 deletion src/checker/liquidity-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class LiquidityChecker {
liquidityCheckResult.isLiquidityLocked = burnPct > 95;
liquidityCheckResult.burnt = burnPct;
liquidityCheckResult.liquidityPoolAddress = poolAddress;

liquidityCheckResult.address = tokenAddress;
return liquidityCheckResult;
}

Expand Down
45 changes: 45 additions & 0 deletions src/checker/marketdata-checker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { config } from 'dotenv';
import axios from 'axios';
import MarketdataCheckConfig from '../model/config/marketdata-check';
import MarketdataCheckResult from '../model/result/marketdata-check';

config();

export default class MarketdataChecker {
constructor({}: MarketdataCheckConfig) {}

async check(tokenAddress: string): Promise<MarketdataCheckResult> {
const marketdataResponse = await axios.get('https://api.dexscreener.com/latest/dex/tokens/' + tokenAddress, {
timeout: 300000,
responseType: 'json'
});
let marketdataResult = this.createMarketdataCheckResult(marketdataResponse.data.pairs[0]);
marketdataResult.address = tokenAddress;
return marketdataResult;
}

private createMarketdataCheckResult(marketdata: any): MarketdataCheckResult {
const metadataCheckResult = new MarketdataCheckResult();
metadataCheckResult.priceSol = marketdata.priceNative;
metadataCheckResult.priceUsd = marketdata.priceUsd;
metadataCheckResult.liquidityUsd = marketdata.liquidity.usd;
metadataCheckResult.fdv = marketdata.fdv;
metadataCheckResult.volume24h = marketdata.volume.h24;
metadataCheckResult.volume6h = marketdata.volume.h6;
metadataCheckResult.volume1h = marketdata.volume.h1;
metadataCheckResult.volume5m = marketdata.volume.m5;
metadataCheckResult.priceChange24h = marketdata.priceChange.h24;
metadataCheckResult.priceChange6h = marketdata.priceChange.h6;
metadataCheckResult.priceChange1h = marketdata.priceChange.h1;
metadataCheckResult.priceChange5m = marketdata.priceChange.m5;
metadataCheckResult.buys24h = marketdata.txns.h24.buys;
metadataCheckResult.buys6h = marketdata.txns.h6.buys;
metadataCheckResult.buys1h = marketdata.txns.h1.buys;
metadataCheckResult.buys5m = marketdata.txns.m5.buys;
metadataCheckResult.sells24h = marketdata.txns.h24.sells;
metadataCheckResult.sells6h = marketdata.txns.h6.sells;
metadataCheckResult.sells1h = marketdata.txns.h1.sells;
metadataCheckResult.sells5m = marketdata.txns.m5.sells;
return metadataCheckResult;
}
}
3 changes: 2 additions & 1 deletion src/checker/metadata-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class MetadataChecker {
}
this.connection = connection;
if (!metaplex) {
metaplex = Metaplex.make(connection);
metaplex = Metaplex.make(this.connection);
}
this.metaplex = metaplex;
if (heliusApiKey) {
Expand All @@ -45,6 +45,7 @@ export default class MetadataChecker {
) {
metadataCheckResult = await this.getHeliusMetadata(tokenAddress, metadataCheckResult);
}
metadataCheckResult.address = tokenAddress;
return metadataCheckResult;
}

Expand Down
14 changes: 11 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import WebsiteChecker from './checker/website-checker';
import MetadataCheckConfig from './model/config/metadata-check';
import HoldersCheckConfig from './model/config/holders-check';
import LiquidityCheckConfig from './model/config/liquidity-check';
import MarketdataChecker from './checker/marketdata-checker';
import MarketdataCheckConfig from './model/config/marketdata-check';
export default class SPLRugchecker {
private holdersChecker: HoldersChecker;
private liquidityChecker: LiquidityChecker;
private metadataChecker: MetadataChecker;
private marketdataChecker: MarketdataChecker;

public constructor({ solanaRpcEndpoint, poolFilePath, poolAddress, heliusApiKey }: RugCheckConfig) {
const metadataCheckConfig = { solanaRpcEndpoint: solanaRpcEndpoint, heliusApiKey: heliusApiKey };
Expand All @@ -19,20 +22,23 @@ export default class SPLRugchecker {
this.holdersChecker = new HoldersChecker(holdersCheckConfig);
const liquidityCheckConfig = { solanaRpcEndpoint: solanaRpcEndpoint, poolFilePath: poolFilePath, poolAddress: poolAddress };
this.liquidityChecker = new LiquidityChecker(liquidityCheckConfig);
const marketdataCheckConfig = {};
this.marketdataChecker = new MarketdataChecker(marketdataCheckConfig);
}

async check(tokenAddress: string): Promise<RugCheckResult> {
const [metadataCheckResult, holdersCheckResult, liquidityCheckResult] = await Promise.all([
const [metadataCheckResult, holdersCheckResult, liquidityCheckResult, marketdataCheckResult] = await Promise.all([
this.metadataChecker.check(tokenAddress),
this.holdersChecker.check(tokenAddress),
this.liquidityChecker.check(tokenAddress)
this.liquidityChecker.check(tokenAddress),
this.marketdataChecker.check(tokenAddress)
]);

const rugCheckResult = new RugCheckResult();
rugCheckResult.metadata = metadataCheckResult;
rugCheckResult.holders = holdersCheckResult;
rugCheckResult.liquidity = liquidityCheckResult;

rugCheckResult.marketdata = marketdataCheckResult;
return rugCheckResult;
}

Expand Down Expand Up @@ -89,8 +95,10 @@ export { WebsiteChecker };
export { MetadataChecker };
export { HoldersChecker };
export { LiquidityChecker };
export { MarketdataChecker };

export { RugCheckConfig };
export { MetadataCheckConfig };
export { LiquidityCheckConfig };
export { HoldersCheckConfig };
export { MarketdataCheckConfig };
1 change: 1 addition & 0 deletions src/model/config/marketdata-check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default class MarketdataCheckConfig {}
1 change: 1 addition & 0 deletions src/model/result/holders-check.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import HolderCheckResult from './holder-check';

export default class HoldersCheckResult {
address: string;
topHolders: HolderCheckResult[];
topHoldersPercentage: number;
raydiumPercentage: number;
Expand Down
1 change: 1 addition & 0 deletions src/model/result/liquidity-check.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default class LiquidityCheckResult {
address: string;
isLiquidityLocked: boolean;
burnt: number;
liquidityPoolAddress: string;
Expand Down
23 changes: 23 additions & 0 deletions src/model/result/marketdata-check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default class MarketdataCheckResult {
address: string;
priceSol: number;
priceUsd: number;
liquidityUsd: number;
fdv: number;
volume24h: number;
volume6h: number;
volume1h: number;
volume5m: number;
priceChange24h: number;
priceChange6h: number;
priceChange1h: number;
priceChange5m: number;
buys24h: number;
buys6h: number;
buys1h: number;
buys5m: number;
sells24h: number;
sells6h: number;
sells1h: number;
sells5m: number;
}
3 changes: 3 additions & 0 deletions src/model/result/rug-check.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import HoldersCheckResult from './holders-check';
import LiquidityCheckResult from './liquidity-check';
import MarketdataCheckResult from './marketdata-check';
import MetadataCheckResult from './metadata-check';

export default class RugCheckResult {
address: string;
metadata: MetadataCheckResult;
holders: HoldersCheckResult;
liquidity: LiquidityCheckResult;
marketdata: MarketdataCheckResult;
}

0 comments on commit 620640e

Please sign in to comment.