From 8e31159d12c050886f2d6d534d3ea03393296771 Mon Sep 17 00:00:00 2001 From: penemue698 Date: Thu, 15 Jun 2023 16:19:11 +0000 Subject: [PATCH] change order of operations for sol deposit --- scripts/eth_sol/sol_deposit.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/scripts/eth_sol/sol_deposit.js b/scripts/eth_sol/sol_deposit.js index d950e52..d2c8e50 100644 --- a/scripts/eth_sol/sol_deposit.js +++ b/scripts/eth_sol/sol_deposit.js @@ -47,16 +47,19 @@ async function updateDeposits () { const newDeposits = bridgesToInsert.filter(tx => !txidsOfAlreadyProcessedDeposits.includes(tx[3])) for (let deposit of newDeposits) { - console.log(`inserting deposit: ${deposit[3]} - ${deposit[2]} SOL`) - await db.query(`UPDATE sol_deposits SET completed = true WHERE id=$1`, [request.id]) - await db.query( - `INSERT INTO bridges (deposit_currency, deposit_address, deposit_amount, deposit_txid, deposit_timestamp, outgoing_currency, outgoing_address) - VALUES ($1,$2,$3,$4,NOW(),$5,$6) - ON CONFLICT (deposit_txid) DO NOTHING`, - deposit - ); - - transferFromDepositAddressToLiquidityPool(request.id) + try { + await transferFromDepositAddressToLiquidityPool(request.id) + console.log(`inserting deposit: ${deposit[3]} - ${deposit[2]} SOL`) + await db.query(`UPDATE sol_deposits SET completed = true WHERE id=$1`, [request.id]) + await db.query( + `INSERT INTO bridges (deposit_currency, deposit_address, deposit_amount, deposit_txid, deposit_timestamp, outgoing_currency, outgoing_address) + VALUES ($1,$2,$3,$4,NOW(),$5,$6) + ON CONFLICT (deposit_txid) DO NOTHING`, + deposit + ); + } catch (error) { + console.log(`error sending sol back to liquidity pool: `, JSON.stringify(error)) + } } } }