53 lines
2.1 KiB
JavaScript
53 lines
2.1 KiB
JavaScript
|
|
const { Client } = require('pg');
|
|
const { Connection, PublicKey } = require('@solana/web3.js');
|
|
|
|
async function debugVerification() {
|
|
const client = new Client({ connectionString: process.env.DATABASE_URL });
|
|
await client.connect();
|
|
const connection = new Connection('https://api.devnet.solana.com', 'confirmed');
|
|
|
|
const res = await client.query(`
|
|
SELECT id, source_ref_id, amount, currency, metadata
|
|
FROM transactions
|
|
WHERE source_ref_id IN ('TEST_ORDER_999', 'TEST_ORDER_1000')
|
|
`);
|
|
|
|
for (const tx of res.rows) {
|
|
console.log(`\n--- Checking ${tx.source_ref_id} ---`);
|
|
const solAddr = tx.metadata?.wallets?.SOLANA?.address;
|
|
|
|
// 1. Calculate Backend's expected amount
|
|
// Simple mock of logic in sync-worker
|
|
const amountTry = parseFloat(tx.amount);
|
|
// Let's assume SOL price is around 4000 TRY for this debug
|
|
const solPriceRes = await fetch('https://api.binance.com/api/v3/ticker/price?symbol=SOLUSDT');
|
|
const solPriceData = await solPriceRes.json();
|
|
const usdtTryRes = await fetch('https://api.binance.com/api/v3/ticker/price?symbol=USDTTRY');
|
|
const usdtTryData = await usdtTryRes.json();
|
|
|
|
const priceSolTry = parseFloat(solPriceData.price) * parseFloat(usdtTryData.price);
|
|
const rawExpected = amountTry / priceSolTry;
|
|
const expectedWithTolerance = (rawExpected * 0.98).toFixed(6);
|
|
|
|
console.log(`Amount: ${amountTry} TRY`);
|
|
console.log(`Current SOL Price: ~${priceSolTry.toFixed(2)} TRY`);
|
|
console.log(`Backend Minimum Expected: ${expectedWithTolerance} SOL`);
|
|
|
|
// 2. Check Actual Balance
|
|
const pubKey = new PublicKey(solAddr);
|
|
const balance = await connection.getBalance(pubKey);
|
|
const actualSol = balance / 1e9;
|
|
console.log(`Actual Wallet Balance: ${actualSol} SOL`);
|
|
|
|
if (actualSol >= parseFloat(expectedWithTolerance)) {
|
|
console.log("✅ VERIFICATION SHOULD PASS!");
|
|
} else {
|
|
console.log("❌ VERIFICATION FAILED: Insufficient balance for tolerance.");
|
|
}
|
|
}
|
|
await client.end();
|
|
}
|
|
|
|
debugVerification();
|