Skip to content

Commit

Permalink
Fix the verify() step of the tx flows updating troves (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpierre authored Jan 20, 2025
1 parent f591ee5 commit 1189ab8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 79 deletions.
20 changes: 13 additions & 7 deletions frontend/app/src/tx-flows/shared.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down
35 changes: 5 additions & 30 deletions frontend/app/src/tx-flows/updateBorrowPosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,7 @@ export const updateBorrowPosition: FlowDeclaration<UpdateBorrowPositionRequest>
},

async verify({ request, wagmiConfig }, hash) {
await verifyTroveUpdate(
wagmiConfig,
hash,
request.loan.collIndex,
request.loan.updatedAt,
);
await verifyTroveUpdate(wagmiConfig, hash, request.loan);
},
},

Expand Down Expand Up @@ -299,12 +294,7 @@ export const updateBorrowPosition: FlowDeclaration<UpdateBorrowPositionRequest>
},

async verify({ request, wagmiConfig }, hash) {
await verifyTroveUpdate(
wagmiConfig,
hash,
request.loan.collIndex,
request.loan.updatedAt,
);
await verifyTroveUpdate(wagmiConfig, hash, request.loan);
},
},

Expand Down Expand Up @@ -337,12 +327,7 @@ export const updateBorrowPosition: FlowDeclaration<UpdateBorrowPositionRequest>
},

async verify({ request, wagmiConfig }, hash) {
await verifyTroveUpdate(
wagmiConfig,
hash,
request.loan.collIndex,
request.loan.updatedAt,
);
await verifyTroveUpdate(wagmiConfig, hash, request.loan);
},
},

Expand Down Expand Up @@ -374,12 +359,7 @@ export const updateBorrowPosition: FlowDeclaration<UpdateBorrowPositionRequest>
},

async verify({ request, wagmiConfig }, hash) {
await verifyTroveUpdate(
wagmiConfig,
hash,
request.loan.collIndex,
request.loan.updatedAt,
);
await verifyTroveUpdate(wagmiConfig, hash, request.loan);
},
},

Expand Down Expand Up @@ -411,12 +391,7 @@ export const updateBorrowPosition: FlowDeclaration<UpdateBorrowPositionRequest>
},

async verify({ request, wagmiConfig }, hash) {
await verifyTroveUpdate(
wagmiConfig,
hash,
request.loan.collIndex,
request.loan.updatedAt,
);
await verifyTroveUpdate(wagmiConfig, hash, request.loan);
},
},
},
Expand Down
28 changes: 4 additions & 24 deletions frontend/app/src/tx-flows/updateLeveragePosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,7 @@ export const updateLeveragePosition: FlowDeclaration<UpdateLeveragePositionReque
},

async verify({ request, wagmiConfig }, hash) {
await verifyTroveUpdate(
wagmiConfig,
hash,
request.loan.collIndex,
request.loan.updatedAt,
);
await verifyTroveUpdate(wagmiConfig, hash, request.loan);
},
},

Expand Down Expand Up @@ -303,12 +298,7 @@ export const updateLeveragePosition: FlowDeclaration<UpdateLeveragePositionReque
},

async verify({ request, wagmiConfig }, hash) {
await verifyTroveUpdate(
wagmiConfig,
hash,
request.loan.collIndex,
request.loan.updatedAt,
);
await verifyTroveUpdate(wagmiConfig, hash, request.loan);
},
},

Expand Down Expand Up @@ -361,12 +351,7 @@ export const updateLeveragePosition: FlowDeclaration<UpdateLeveragePositionReque
},

async verify({ request, wagmiConfig }, hash) {
await verifyTroveUpdate(
wagmiConfig,
hash,
request.loan.collIndex,
request.loan.updatedAt,
);
await verifyTroveUpdate(wagmiConfig, hash, request.loan);
},
},

Expand Down Expand Up @@ -416,12 +401,7 @@ export const updateLeveragePosition: FlowDeclaration<UpdateLeveragePositionReque
},

async verify({ request, wagmiConfig }, hash) {
await verifyTroveUpdate(
wagmiConfig,
hash,
request.loan.collIndex,
request.loan.updatedAt,
);
await verifyTroveUpdate(wagmiConfig, hash, request.loan);
},
},
},
Expand Down
21 changes: 3 additions & 18 deletions frontend/app/src/tx-flows/updateLoanInterestRate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,7 @@ export const updateLoanInterestRate: FlowDeclaration<UpdateLoanInterestRateReque
},

async verify({ request, wagmiConfig }, hash) {
await verifyTroveUpdate(
wagmiConfig,
hash,
request.loan.collIndex,
request.loan.updatedAt,
);
await verifyTroveUpdate(wagmiConfig, hash, request.loan);
},
},

Expand Down Expand Up @@ -241,12 +236,7 @@ export const updateLoanInterestRate: FlowDeclaration<UpdateLoanInterestRateReque
},

async verify({ request, wagmiConfig }, hash) {
await verifyTroveUpdate(
wagmiConfig,
hash,
request.loan.collIndex,
request.loan.updatedAt,
);
await verifyTroveUpdate(wagmiConfig, hash, request.loan);
},
},

Expand Down Expand Up @@ -277,12 +267,7 @@ export const updateLoanInterestRate: FlowDeclaration<UpdateLoanInterestRateReque
},

async verify({ request, wagmiConfig }, hash) {
await verifyTroveUpdate(
wagmiConfig,
hash,
request.loan.collIndex,
request.loan.updatedAt,
);
await verifyTroveUpdate(wagmiConfig, hash, request.loan);
},
},
},
Expand Down

0 comments on commit 1189ab8

Please sign in to comment.