Skip to content

Commit

Permalink
Fix the amount to approve when closing a batched trove (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpierre authored Nov 26, 2024
1 parent 1020a78 commit f880637
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions frontend/app/src/tx-flows/closeLoanPosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ export const closeLoanPosition: FlowDeclaration<Request, Step> = {
throw new Error("Account address is required");
}

const [debt] = await readContract(wagmiConfig, {
const { entireDebt } = await readContract(wagmiConfig, {
...coll.contracts.TroveManager,
functionName: "Troves",
functionName: "getLatestTroveData",
args: [BigInt(loan.troveId)],
});

const isBoldApproved = request.repayWithCollateral || !dn.gt(debt, [
const isBoldApproved = request.repayWithCollateral || !dn.gt(entireDebt, [
await readContract(wagmiConfig, {
...contracts.BoldToken,
functionName: "allowance",
Expand Down Expand Up @@ -179,9 +179,9 @@ export const closeLoanPosition: FlowDeclaration<Request, Step> = {
const coll = contracts.collaterals[loan.collIndex];

if (stepId === "approveBold") {
const [debt] = await readContract(wagmiConfig, {
const { entireDebt } = await readContract(wagmiConfig, {
...coll.contracts.TroveManager,
functionName: "Troves",
functionName: "getLatestTroveData",
args: [BigInt(loan.troveId)],
});

Expand All @@ -192,7 +192,7 @@ export const closeLoanPosition: FlowDeclaration<Request, Step> = {
return {
...contracts.BoldToken,
functionName: "approve",
args: [Zapper.address, dn.mul([debt, 18], 1.1)[0]], // TODO: calculate the amount to approve in a more precise way
args: [Zapper.address, dn.mul([entireDebt, 18], 1.1)[0]], // TODO: calculate the amount to approve in a more precise way
};
}

Expand Down

0 comments on commit f880637

Please sign in to comment.