Skip to content

Commit 6d6296e

Browse files
committed
updates for the backend
Signed-off-by: MarcoMandar <malicemandar@gmail.com>
1 parent e240a18 commit 6d6296e

File tree

3 files changed

+59
-15
lines changed

3 files changed

+59
-15
lines changed

packages/plugin-solana/src/providers/simulationSellingService.ts

+16-14
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ export class simulationSellingService {
211211
const process = await this.startProcessInTheSonarBackend(
212212
tokenAddress,
213213
balance,
214-
sell_recommender_id
214+
sell_recommender_id,
215+
tokenPerformance.initial_mc
215216
);
216217
if (process) {
217218
this.runningProcesses.add(tokenAddress);
@@ -223,21 +224,23 @@ export class simulationSellingService {
223224
private async startProcessInTheSonarBackend(
224225
tokenAddress: string,
225226
balance: number,
226-
sell_recommender_id: string
227+
isSimulation: boolean,
228+
initial_mc: number
227229
) {
228230
try {
229231
const message = JSON.stringify({
230232
tokenAddress,
231233
balance,
232-
sell_recommender_id,
234+
isSimulation,
235+
initial_mc,
233236
});
234237
const response = await fetch(
235-
`${this.sonarBe}/api/simulation/sell`,
238+
`${this.sonarBe}/ai16z-sol/startProcess`,
236239
{
237240
method: "POST",
238241
headers: {
239242
"Content-Type": "application/json",
240-
Authorization: `Bearer ${this.sonarBeToken}`,
243+
"x-api-key": `${this.sonarBeToken}`,
241244
},
242245
body: message,
243246
}
@@ -266,15 +269,14 @@ export class simulationSellingService {
266269

267270
private stopProcessInTheSonarBackend(tokenAddress: string) {
268271
try {
269-
return fetch(
270-
`${this.sonarBe}/api/simulation/sell/${tokenAddress}`,
271-
{
272-
method: "GET",
273-
headers: {
274-
Authorization: `Bearer ${this.sonarBeToken}`,
275-
},
276-
}
277-
);
272+
return fetch(`${this.sonarBe}/ai16z-sol/stopProcess`, {
273+
method: "POST",
274+
headers: {
275+
"Content-Type": "application/json",
276+
"x-api-key": `${this.sonarBeToken}`,
277+
},
278+
body: JSON.stringify({ tokenAddress }),
279+
});
278280
} catch (error) {
279281
console.error(
280282
`Error stopping process for token ${tokenAddress}:`,

packages/plugin-solana/src/providers/trustScoreProvider.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,31 @@ export class TrustScoreManager {
399399
processedData.dexScreenerData.pairs[0]?.liquidity || 0,
400400
initialPrice: processedData.tradeData.price,
401401
};
402-
403402
this.trustScoreDb.addTokenRecommendation(tokenRecommendation);
404403

404+
this.trustScoreDb.upsertTokenPerformance({
405+
tokenAddress: tokenAddress,
406+
priceChange24h: processedData.tradeData.price_change_24h_percent,
407+
volumeChange24h: processedData.tradeData.volume_24h,
408+
trade_24h_change: processedData.tradeData.trade_24h_change_percent,
409+
liquidity:
410+
processedData.dexScreenerData.pairs[0]?.liquidity.usd || 0,
411+
liquidityChange24h: 0,
412+
holderChange24h:
413+
processedData.tradeData.unique_wallet_24h_change_percent,
414+
rugPull: false,
415+
isScam: false,
416+
marketCapChange24h: 0,
417+
sustainedGrowth: false,
418+
rapidDump: false,
419+
suspiciousVolume: false,
420+
validationTrust: 0,
421+
balance: tokensBalance,
422+
initialMarketCap:
423+
processedData.dexScreenerData.pairs[0]?.marketCap || 0,
424+
lastUpdated: new Date(),
425+
});
426+
405427
if (data.is_simulation) {
406428
// If the trade is a simulation update the balance
407429
this.trustScoreDb.updateTokenBalance(tokenAddress, tokensBalance);

packages/plugin-trustdb/src/adapters/trustScoreDatabase.ts

+20
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface TokenPerformance {
4141
suspiciousVolume: boolean;
4242
validationTrust: number;
4343
balance: number;
44+
initialMarketCap: number;
4445
lastUpdated: Date;
4546
}
4647

@@ -122,6 +123,7 @@ interface TokenPerformanceRow {
122123
suspicious_volume: number;
123124
validation_trust: number;
124125
balance: number;
126+
initial_market_cap: number;
125127
last_updated: string;
126128
}
127129

@@ -205,6 +207,7 @@ export class TrustScoreDatabase {
205207
suspicious_volume BOOLEAN DEFAULT FALSE,
206208
validation_trust REAL DEFAULT 0,
207209
balance REAL DEFAULT 0,
210+
initial_market_cap REAL DEFAULT 0,
208211
last_updated DATETIME DEFAULT CURRENT_TIMESTAMP
209212
);
210213
`);
@@ -731,6 +734,8 @@ export class TrustScoreDatabase {
731734
rapid_dump,
732735
suspicious_volume,
733736
validation_trust,
737+
balance,
738+
initial_market_cap,
734739
last_updated
735740
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
736741
ON CONFLICT(token_address) DO UPDATE SET
@@ -747,6 +752,8 @@ export class TrustScoreDatabase {
747752
rapid_dump = excluded.rapid_dump,
748753
suspicious_volume = excluded.suspicious_volume,
749754
validation_trust = excluded.validation_trust,
755+
balance = excluded.balance,
756+
initial_market_cap = excluded.initial_market_cap,
750757
last_updated = CURRENT_TIMESTAMP;
751758
`;
752759
try {
@@ -764,6 +771,8 @@ export class TrustScoreDatabase {
764771
performance.sustainedGrowth ? 1 : 0,
765772
performance.rapidDump ? 1 : 0,
766773
performance.suspiciousVolume ? 1 : 0,
774+
performance.balance,
775+
performance.initialMarketCap,
767776
validationTrust
768777
);
769778
console.log(
@@ -823,10 +832,20 @@ export class TrustScoreDatabase {
823832
suspiciousVolume: row.suspicious_volume === 1,
824833
validationTrust: row.validation_trust,
825834
balance: row.balance,
835+
initialMarketCap: row.initial_market_cap,
826836
lastUpdated: new Date(row.last_updated),
827837
};
828838
}
829839

840+
//getTokenBalance
841+
getTokenBalance(tokenAddress: string): number {
842+
const sql = `SELECT balance FROM token_performance WHERE token_address = ?;`;
843+
const row = this.db.prepare(sql).get(tokenAddress) as {
844+
balance: number;
845+
};
846+
return row.balance;
847+
}
848+
830849
getAllTokenPerformancesWithBalance(): TokenPerformance[] {
831850
const sql = `SELECT * FROM token_performance WHERE balance > 0;`;
832851
const rows = this.db.prepare(sql).all() as TokenPerformanceRow[];
@@ -847,6 +866,7 @@ export class TrustScoreDatabase {
847866
suspiciousVolume: row.suspicious_volume === 1,
848867
validationTrust: row.validation_trust,
849868
balance: row.balance,
869+
initialMarketCap: row.initial_market_cap,
850870
lastUpdated: new Date(row.last_updated),
851871
}));
852872
}

0 commit comments

Comments
 (0)