Skip to content

Commit

Permalink
Merge pull request #262 from luxfi/dev/newProd
Browse files Browse the repository at this point in the history
added: deposit checker
  • Loading branch information
venuswhispers authored Nov 30, 2024
2 parents 58d8c42 + 466116b commit 5a9dd34
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
57 changes: 57 additions & 0 deletions app/server/src/lib/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,63 @@ export async function handlerDepositAction(
}
console.log(`>> Successfully Created Deposit Action for Swap [${swap.id}]`)
}
/**
*
* @param state
* @param hash
* @param amount
* @param asset
* @param sourceAddress
* @param destinationAddress
* @returns
*/
export async function handlerCheckDeposit(
swapId: string
) {
const swap = await prisma.swap.findFirst({
where: {
id: swapId
},
include: {
deposit_actions: true,
source_network: true,
source_asset: true
}
})

if (!swap) {
throw new Error("There is No swap for this transaction")
}
const utilaNetwork = UTILA_NETWORKS[swap.source_network.internal_name as string]
if (!utilaNetwork) {
throw new Error(`Unrecognized Utila Network [${swap.source_network.internal_name}]`)
}
// checking network and asset match
const _wallet = swap.deposit_address?.split('###')?.[0] as string
const _asset = utilaNetwork.assets[swap.source_asset.asset as string]

const unconfirmedActions = swap.deposit_actions.filter((d: any) => d.status !== 'CONFIRMED')
if (unconfirmedActions.length > 0) {
throw new Error(`Some transactions still not confirmed yet`)
}
// if confirmed, check whether deposit is
const confirmed = await checkDepositAction ({
asset: _asset,
wallet: _wallet,
requestedAmount: Number(swap.requested_amount)
})

if (confirmed) {
await prisma.swap.update({
where: { id: swap.id },
data: {
status: SwapStatus.BridgeTransferPending
}
})
console.log(`>> Deposit Completed for swap [${swap.id}]`)
}
console.log(`>> Successfully Created Deposit Action for Swap [${swap.id}]`)
}
/**
* handler after deposit is checked
*/
Expand Down
11 changes: 11 additions & 0 deletions app/server/src/routes/utila.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ router.get("/payout/:swapId", async (req: Request, res: Response) => {
}
})

router.get("/deposit/check/:swapId", async (req: Request, res: Response) => {
try {
const swapId = req.params.swapId
const data = await handlerUtilaPayoutAction (swapId)
res.status(200).json(data)
} catch (err: any) {
res.status(500).send({
error: err?.message
})
}
})
/**
* Webhook route to handle events
* Handles POST requests to /v1/utila/webhook (or /webhook via alias/rewrite)
Expand Down

0 comments on commit 5a9dd34

Please sign in to comment.