Skip to content

Commit

Permalink
fix: issues-53
Browse files Browse the repository at this point in the history
* takeOverDebt _addKeysAndLoansInfo fixed

* MAX_NUM_USER_POSOTION checking fixed
  • Loading branch information
fann95 committed Oct 30, 2023
1 parent 21a66a0 commit f5860c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions contracts/LiquidityBorrowingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ contract LiquidityBorrowingManager is
accLoanRatePerSeconds
);
// Add the new borrowing key and old loans to the newBorrowing
_addKeysAndLoansInfo(newBorrowing.borrowedAmount > 0, borrowingKey, oldLoans);
_addKeysAndLoansInfo(newBorrowing.borrowedAmount > 0, newBorrowingKey, oldLoans);
// Increase the borrowed amount, liquidation bonus, and fees owed of the newBorrowing based on the oldBorrowing
newBorrowing.borrowedAmount += oldBorrowing.borrowedAmount;
newBorrowing.liquidationBonus += oldBorrowing.liquidationBonus;
Expand Down Expand Up @@ -817,11 +817,11 @@ contract LiquidityBorrowingManager is
if (!update) {
// If it's a new position, ensure that the user does not have too many positions
bytes32[] storage allUserBorrowingKeys = userBorrowingKeys[msg.sender];
// Add the borrowingKey to the user's borrowing keys
allUserBorrowingKeys.push(borrowingKey);
(allUserBorrowingKeys.length > Constants.MAX_NUM_USER_POSOTION).revertError(
ErrLib.ErrorCode.TOO_MANY_USER_POSITIONS
);
// Add the borrowingKey to the user's borrowing keys
allUserBorrowingKeys.push(borrowingKey);
}
}

Expand Down
12 changes: 11 additions & 1 deletion test/WagmiLeverageTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ describe("WagmiLeverageTests", () => {
it("takeOverDebt should be correct if the collateral is depleted", async () => {
snapshot_global.restore();
const aliceBorrowingsCount = await borrowingManager.getBorrowerDebtsCount(alice.address);

const bobBorrowingsCount = await borrowingManager.getBorrowerDebtsCount(bob.address);
let debt: LiquidityBorrowingManager.BorrowingInfoExtStructOutput = (
await borrowingManager.getBorrowerDebtsInfo(bob.address)
Expand All @@ -1145,9 +1146,18 @@ describe("WagmiLeverageTests", () => {
await expect(borrowingManager.connect(alice).takeOverDebt(debt.key, collateralDebt)).to.be.reverted; //collateralAmt is not enough
await borrowingManager.connect(alice).takeOverDebt(debt.key, collateralDebt.add(5));
expect(await borrowingManager.getBorrowerDebtsCount(bob.address)).to.be.equal(bobBorrowingsCount.sub(1));
expect(await borrowingManager.getBorrowerDebtsCount(alice.address)).to.be.equal(aliceBorrowingsCount.add(1));
expect(await borrowingManager.getBorrowerDebtsCount(alice.address)).to.be.equal(aliceBorrowingsCount.add(1));//new
let loansInfo: LiquidityManager.LoanInfoStructOutput[] = await borrowingManager.getLoansInfo(debt.key);
expect(loansInfo.length).to.be.equal(0);
const borrowingsInfo = await borrowingManager.borrowingsInfo(debt.key);
expect(borrowingsInfo.borrower).to.be.equal(constants.AddressZero);
const newBorrowingKey = await borrowingManager.userBorrowingKeys(alice.address, aliceBorrowingsCount);//aliceBorrowingsCount==0
expect(newBorrowingKey).to.be.not.equal(debt.key);
loansInfo = await borrowingManager.getLoansInfo(newBorrowingKey);
expect(loansInfo.length).to.be.equal(3);
debt = (await borrowingManager.getBorrowerDebtsInfo(alice.address))[0];
expect(newBorrowingKey).to.be.equal(debt.key);
expect(alice.address).to.be.equal(debt.info.borrower);
});

it("increase the collateral balance should be correct", async () => {
Expand Down

0 comments on commit f5860c8

Please sign in to comment.