feat: Helius primary + Alchemy fallback for trade execution
- Helius HTTPS: Primary RPC for Drift SDK initialization and subscriptions - Alchemy HTTPS (10K CU/s): Fallback RPC for transaction confirmations - Added getFallbackConnection() method to DriftService - openPosition() and closePosition() now use Alchemy for tx confirmations - accountSubscribe errors are non-fatal warnings (SDK falls back gracefully) - System fully operational: Drift initialized, Position Manager ready - Trade execution will use high-throughput Alchemy for confirmations
This commit is contained in:
@@ -470,6 +470,13 @@ export class DriftService {
|
||||
return this.connection
|
||||
}
|
||||
|
||||
/**
|
||||
* Get fallback connection (Alchemy for trade execution)
|
||||
*/
|
||||
getFallbackConnection(): Connection | null {
|
||||
return this.fallbackConnection || null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user instance
|
||||
*/
|
||||
|
||||
@@ -146,8 +146,16 @@ export async function openPosition(
|
||||
console.log(`📝 Transaction submitted: ${txSig}`)
|
||||
|
||||
// CRITICAL: Confirm transaction actually executed on-chain
|
||||
console.log('⏳ Confirming transaction on-chain...')
|
||||
const connection = driftService.getConnection()
|
||||
// Use Alchemy (fallback RPC) for confirmation - higher throughput
|
||||
console.log('⏳ Confirming transaction on-chain (using Alchemy for high throughput)...')
|
||||
const alchemyConnection = driftService.getFallbackConnection()
|
||||
const connection = alchemyConnection || driftService.getConnection()
|
||||
|
||||
if (alchemyConnection) {
|
||||
console.log('✅ Using Alchemy RPC for transaction confirmation')
|
||||
} else {
|
||||
console.log('⚠️ No fallback RPC available, using primary RPC')
|
||||
}
|
||||
|
||||
try {
|
||||
const confirmation = await connection.confirmTransaction(txSig, 'confirmed')
|
||||
@@ -557,9 +565,16 @@ export async function closePosition(
|
||||
console.log(`✅ Close order placed! Transaction: ${txSig}`)
|
||||
|
||||
// CRITICAL: Confirm transaction on-chain to prevent phantom closes
|
||||
// BUT: Use timeout to prevent API hangs during network congestion
|
||||
console.log('⏳ Confirming transaction on-chain (30s timeout)...')
|
||||
const connection = driftService.getConnection()
|
||||
// Use Alchemy (fallback RPC) for confirmation - higher throughput
|
||||
console.log('⏳ Confirming transaction on-chain (using Alchemy, 30s timeout)...')
|
||||
const alchemyConnection = driftService.getFallbackConnection()
|
||||
const connection = alchemyConnection || driftService.getConnection()
|
||||
|
||||
if (alchemyConnection) {
|
||||
console.log('✅ Using Alchemy RPC for transaction confirmation')
|
||||
} else {
|
||||
console.log('⚠️ No fallback RPC available, using primary RPC')
|
||||
}
|
||||
|
||||
try {
|
||||
const confirmationPromise = connection.confirmTransaction(txSig, 'confirmed')
|
||||
|
||||
Reference in New Issue
Block a user