From 1189ab80cd76acc6e1464b4828814e0246eb2357 Mon Sep 17 00:00:00 2001 From: Pierre Bertet Date: Mon, 20 Jan 2025 18:45:17 +0000 Subject: [PATCH] Fix the verify() step of the tx flows updating troves (#724) --- frontend/app/src/tx-flows/shared.ts | 20 +++++++---- .../app/src/tx-flows/updateBorrowPosition.tsx | 35 +++---------------- .../src/tx-flows/updateLeveragePosition.tsx | 28 +++------------ .../src/tx-flows/updateLoanInterestRate.tsx | 21 ++--------- 4 files changed, 25 insertions(+), 79 deletions(-) diff --git a/frontend/app/src/tx-flows/shared.ts b/frontend/app/src/tx-flows/shared.ts index 4e2b8a5dc..861e2dedd 100644 --- a/frontend/app/src/tx-flows/shared.ts +++ b/frontend/app/src/tx-flows/shared.ts @@ -1,4 +1,4 @@ -import type { CollIndex } from "@/src/types"; +import type { CollIndex, TroveId } from "@/src/types"; import type { Config as WagmiConfig } from "wagmi"; import { getPrefixedTroveId } from "@/src/liquity-utils"; @@ -54,17 +54,23 @@ export async function verifyTransaction( export async function verifyTroveUpdate( wagmiConfig: WagmiConfig, hash: string, - collIndex: CollIndex, - lastUpdate: number, + loan: { + collIndex: CollIndex; + troveId: TroveId; + updatedAt: number; + }, ) { - const receipt = await waitForTransactionReceipt(wagmiConfig, { + await waitForTransactionReceipt(wagmiConfig, { hash: hash as `0x${string}`, }); - const prefixedTroveId = getPrefixedTroveId(collIndex, receipt.transactionHash); + const prefixedTroveId = getPrefixedTroveId(loan.collIndex, loan.troveId); while (true) { // wait for the trove to be updated in the subgraph - const { trove } = await graphQuery(TroveByIdQuery, { id: prefixedTroveId }); - if (trove && Number(trove.updatedAt) * 1000 !== lastUpdate) { + const { trove } = await graphQuery( + TroveByIdQuery, + { id: prefixedTroveId }, + ); + if (trove && Number(trove.updatedAt) * 1000 !== loan.updatedAt) { break; } await sleep(1000); diff --git a/frontend/app/src/tx-flows/updateBorrowPosition.tsx b/frontend/app/src/tx-flows/updateBorrowPosition.tsx index ad1b64219..9274d93df 100644 --- a/frontend/app/src/tx-flows/updateBorrowPosition.tsx +++ b/frontend/app/src/tx-flows/updateBorrowPosition.tsx @@ -262,12 +262,7 @@ export const updateBorrowPosition: FlowDeclaration }, async verify({ request, wagmiConfig }, hash) { - await verifyTroveUpdate( - wagmiConfig, - hash, - request.loan.collIndex, - request.loan.updatedAt, - ); + await verifyTroveUpdate(wagmiConfig, hash, request.loan); }, }, @@ -299,12 +294,7 @@ export const updateBorrowPosition: FlowDeclaration }, async verify({ request, wagmiConfig }, hash) { - await verifyTroveUpdate( - wagmiConfig, - hash, - request.loan.collIndex, - request.loan.updatedAt, - ); + await verifyTroveUpdate(wagmiConfig, hash, request.loan); }, }, @@ -337,12 +327,7 @@ export const updateBorrowPosition: FlowDeclaration }, async verify({ request, wagmiConfig }, hash) { - await verifyTroveUpdate( - wagmiConfig, - hash, - request.loan.collIndex, - request.loan.updatedAt, - ); + await verifyTroveUpdate(wagmiConfig, hash, request.loan); }, }, @@ -374,12 +359,7 @@ export const updateBorrowPosition: FlowDeclaration }, async verify({ request, wagmiConfig }, hash) { - await verifyTroveUpdate( - wagmiConfig, - hash, - request.loan.collIndex, - request.loan.updatedAt, - ); + await verifyTroveUpdate(wagmiConfig, hash, request.loan); }, }, @@ -411,12 +391,7 @@ export const updateBorrowPosition: FlowDeclaration }, async verify({ request, wagmiConfig }, hash) { - await verifyTroveUpdate( - wagmiConfig, - hash, - request.loan.collIndex, - request.loan.updatedAt, - ); + await verifyTroveUpdate(wagmiConfig, hash, request.loan); }, }, }, diff --git a/frontend/app/src/tx-flows/updateLeveragePosition.tsx b/frontend/app/src/tx-flows/updateLeveragePosition.tsx index a017fc4aa..7530d1c25 100644 --- a/frontend/app/src/tx-flows/updateLeveragePosition.tsx +++ b/frontend/app/src/tx-flows/updateLeveragePosition.tsx @@ -260,12 +260,7 @@ export const updateLeveragePosition: FlowDeclaration