76 lines
2.8 KiB
JavaScript
76 lines
2.8 KiB
JavaScript
const { Client } = require('pg');
|
|
const { Connection, PublicKey } = require('@solana/web3.js');
|
|
|
|
async function debugSpecificPayment() {
|
|
const client = new Client({ connectionString: process.env.DATABASE_URL });
|
|
await client.connect();
|
|
|
|
const targetAddress = "DZrWQ3Li3AogniRhgyGjNVmG1b3hLe7rR3tgeaKRcy63";
|
|
|
|
// Find the transaction by address
|
|
const res = await client.query(`
|
|
SELECT id, source_ref_id, amount, currency, metadata, status, created_at
|
|
FROM transactions
|
|
WHERE metadata->'wallets'->'SOLANA'->>'address' = $1
|
|
`, [targetAddress]);
|
|
|
|
if (res.rows.length === 0) {
|
|
console.log(`❌ No transaction found in DB with Solana address: ${targetAddress}`);
|
|
await client.end();
|
|
return;
|
|
}
|
|
|
|
const tx = res.rows[0];
|
|
console.log(`\n--- Transaction Found: ${tx.id} ---`);
|
|
console.log(`Source Ref: ${tx.source_ref_id}`);
|
|
console.log(`Status: ${tx.status}`);
|
|
console.log(`Created: ${tx.created_at}`);
|
|
console.log(`Fiat Amount: ${tx.amount} ${tx.currency}`);
|
|
console.log(`Intent Network/Token: ${tx.metadata?.intent_network} / ${tx.metadata?.intent_token}`);
|
|
|
|
// Check Balance on devnet
|
|
const connection = new Connection('https://api.devnet.solana.com', 'confirmed');
|
|
|
|
let actualSol = 0;
|
|
try {
|
|
const pubKey = new PublicKey(targetAddress);
|
|
const balance = await connection.getBalance(pubKey);
|
|
actualSol = balance / 1e9;
|
|
console.log(`\nActual Devnet Balance: ${actualSol} SOL`);
|
|
|
|
const signatures = await connection.getSignaturesForAddress(pubKey, { limit: 5 });
|
|
console.log(`Recent Txs: ${signatures.length}`);
|
|
} catch(e) {
|
|
console.log("Error fetching balance:", e.message);
|
|
}
|
|
|
|
// Try calculation
|
|
let expectedSolAmount = 0;
|
|
try {
|
|
const tryRes = await fetch(`https://api.binance.com/api/v3/ticker/price?symbol=USDTTRY`);
|
|
const tryData = await tryRes.json();
|
|
const usdTryPrice = parseFloat(tryData.price);
|
|
|
|
const solRes = await fetch(`https://api.binance.com/api/v3/ticker/price?symbol=SOLUSDT`);
|
|
const solData = await solRes.json();
|
|
const solUsdPrice = parseFloat(solData.price);
|
|
|
|
const priceInTry = solUsdPrice * usdTryPrice;
|
|
const rawExpected = parseFloat(tx.amount) / priceInTry;
|
|
expectedSolAmount = parseFloat((rawExpected * 0.98).toFixed(6));
|
|
console.log(`\nExpected Amount: ~${expectedSolAmount} SOL (based on current price)`);
|
|
} catch(e) {
|
|
console.log("Failed to fetch price");
|
|
}
|
|
|
|
if (actualSol >= expectedSolAmount && expectedSolAmount > 0) {
|
|
console.log("✅ Balance covers expectation");
|
|
} else {
|
|
console.log("❌ Balance is less than expected");
|
|
}
|
|
|
|
await client.end();
|
|
}
|
|
|
|
debugSpecificPayment();
|