mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Merge pull request #5 from liquity/fix-repayments
Handle repayments in adjust() and update tests
This commit is contained in:
commit
51c8462965
|
@ -29,8 +29,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
uint maxFeePercentage;
|
uint maxFeePercentage;
|
||||||
uint withdrawAmount;
|
uint withdrawAmount;
|
||||||
uint depositAmount;
|
uint depositAmount;
|
||||||
uint borrowAmount;
|
uint lusdChange;
|
||||||
uint repayAmount;
|
|
||||||
bool isBorrow;
|
bool isBorrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,7 +226,7 @@ abstract contract LiquityResolver is Events, Helpers {
|
||||||
withdrawAmount = getUint(getIds[1], withdrawAmount);
|
withdrawAmount = getUint(getIds[1], withdrawAmount);
|
||||||
adjustTrove.withdrawAmount = withdrawAmount == uint(-1) ? troveManager.getTroveColl(address(this)) : withdrawAmount;
|
adjustTrove.withdrawAmount = withdrawAmount == uint(-1) ? troveManager.getTroveColl(address(this)) : withdrawAmount;
|
||||||
|
|
||||||
adjustTrove.borrowAmount = getUint(getIds[2], borrowAmount);
|
borrowAmount = getUint(getIds[2], borrowAmount);
|
||||||
|
|
||||||
repayAmount = getUint(getIds[3], repayAmount);
|
repayAmount = getUint(getIds[3], repayAmount);
|
||||||
if (repayAmount == uint(-1)) {
|
if (repayAmount == uint(-1)) {
|
||||||
|
@ -234,14 +234,14 @@ abstract contract LiquityResolver is Events, Helpers {
|
||||||
uint _totalDebt = troveManager.getTroveDebt(address(this));
|
uint _totalDebt = troveManager.getTroveDebt(address(this));
|
||||||
repayAmount = _lusdBal > _totalDebt ? _totalDebt : _lusdBal;
|
repayAmount = _lusdBal > _totalDebt ? _totalDebt : _lusdBal;
|
||||||
}
|
}
|
||||||
adjustTrove.repayAmount = repayAmount;
|
|
||||||
|
|
||||||
adjustTrove.isBorrow = borrowAmount > 0;
|
adjustTrove.isBorrow = borrowAmount > 0;
|
||||||
|
adjustTrove.lusdChange = adjustTrove.isBorrow ? borrowAmount : repayAmount;
|
||||||
|
|
||||||
borrowerOperations.adjustTrove{value: adjustTrove.depositAmount}(
|
borrowerOperations.adjustTrove{value: adjustTrove.depositAmount}(
|
||||||
adjustTrove.maxFeePercentage,
|
adjustTrove.maxFeePercentage,
|
||||||
adjustTrove.withdrawAmount,
|
adjustTrove.withdrawAmount,
|
||||||
adjustTrove.borrowAmount,
|
adjustTrove.lusdChange,
|
||||||
adjustTrove.isBorrow,
|
adjustTrove.isBorrow,
|
||||||
upperHint,
|
upperHint,
|
||||||
lowerHint
|
lowerHint
|
||||||
|
@ -249,11 +249,11 @@ abstract contract LiquityResolver is Events, Helpers {
|
||||||
|
|
||||||
setUint(setIds[0], adjustTrove.depositAmount);
|
setUint(setIds[0], adjustTrove.depositAmount);
|
||||||
setUint(setIds[1], adjustTrove.withdrawAmount);
|
setUint(setIds[1], adjustTrove.withdrawAmount);
|
||||||
setUint(setIds[2], adjustTrove.borrowAmount);
|
setUint(setIds[2], borrowAmount);
|
||||||
setUint(setIds[3], adjustTrove.repayAmount);
|
setUint(setIds[3], repayAmount);
|
||||||
|
|
||||||
_eventName = "LogAdjust(address,uint256,uint256,uint256,uint256,uint256,uint256[],uint256[])";
|
_eventName = "LogAdjust(address,uint256,uint256,uint256,uint256,uint256,uint256[],uint256[])";
|
||||||
_eventParam = abi.encode(address(this), maxFeePercentage, adjustTrove.depositAmount, adjustTrove.withdrawAmount, adjustTrove.borrowAmount, adjustTrove.repayAmount, getIds, setIds);
|
_eventParam = abi.encode(address(this), maxFeePercentage, adjustTrove.depositAmount, adjustTrove.withdrawAmount, borrowAmount, repayAmount, getIds, setIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1208,7 +1208,7 @@ describe("Liquity", () => {
|
||||||
const depositAmount = 0;
|
const depositAmount = 0;
|
||||||
const borrowAmount = 0;
|
const borrowAmount = 0;
|
||||||
const withdrawAmount = ethers.utils.parseEther("1"); // 1 ETH;
|
const withdrawAmount = ethers.utils.parseEther("1"); // 1 ETH;
|
||||||
const repayAmount = ethers.utils.parseUnits("500", 18); // 500 LUSD;
|
const repayAmount = ethers.utils.parseUnits("10", 18); // 10 LUSD;
|
||||||
const { upperHint, lowerHint } = await helpers.getTroveInsertionHints(
|
const { upperHint, lowerHint } = await helpers.getTroveInsertionHints(
|
||||||
troveCollateralBefore.sub(withdrawAmount),
|
troveCollateralBefore.sub(withdrawAmount),
|
||||||
troveDebtBefore.sub(repayAmount),
|
troveDebtBefore.sub(repayAmount),
|
||||||
|
@ -1256,7 +1256,7 @@ describe("Liquity", () => {
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
troveDebt,
|
troveDebt,
|
||||||
`Trove debt should have increased by at least ${borrowAmount} ETH`
|
`Trove debt should have decreased by at least ${repayAmount} LUSD`
|
||||||
).to.gte(expectedTroveDebt);
|
).to.gte(expectedTroveDebt);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1273,7 +1273,7 @@ describe("Liquity", () => {
|
||||||
const depositAmount = ethers.utils.parseEther("1"); // 1 ETH
|
const depositAmount = ethers.utils.parseEther("1"); // 1 ETH
|
||||||
const borrowAmount = 0;
|
const borrowAmount = 0;
|
||||||
const withdrawAmount = 0;
|
const withdrawAmount = 0;
|
||||||
const repayAmount = ethers.utils.parseUnits("100", 18); // 100 lUSD
|
const repayAmount = ethers.utils.parseUnits("10", 18); // 10 lUSD
|
||||||
const upperHint = ethers.constants.AddressZero;
|
const upperHint = ethers.constants.AddressZero;
|
||||||
const lowerHint = ethers.constants.AddressZero;
|
const lowerHint = ethers.constants.AddressZero;
|
||||||
const maxFeePercentage = ethers.utils.parseUnits("0.5", 18); // 0.5% max fee
|
const maxFeePercentage = ethers.utils.parseUnits("0.5", 18); // 0.5% max fee
|
||||||
|
@ -1304,7 +1304,7 @@ describe("Liquity", () => {
|
||||||
0, // Repay amount comes from a previous spell's storage slot
|
0, // Repay amount comes from a previous spell's storage slot
|
||||||
upperHint,
|
upperHint,
|
||||||
lowerHint,
|
lowerHint,
|
||||||
[ethDepositId, 0, 0, 0],
|
[ethDepositId, 0, 0, lusdRepayId],
|
||||||
[0, 0, 0, 0],
|
[0, 0, 0, 0],
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -1323,7 +1323,7 @@ describe("Liquity", () => {
|
||||||
.connect(userWallet)
|
.connect(userWallet)
|
||||||
.approve(dsa.address, repayAmount);
|
.approve(dsa.address, repayAmount);
|
||||||
|
|
||||||
// Adjust Trove by depositing ETH and borrowing LUSD
|
// Adjust Trove by depositing ETH and repaying LUSD
|
||||||
await dsa
|
await dsa
|
||||||
.connect(userWallet)
|
.connect(userWallet)
|
||||||
.cast(...encodeSpells(spells), userWallet.address, {
|
.cast(...encodeSpells(spells), userWallet.address, {
|
||||||
|
@ -1338,7 +1338,7 @@ describe("Liquity", () => {
|
||||||
dsa.address
|
dsa.address
|
||||||
);
|
);
|
||||||
const expectedTroveColl = troveCollateralBefore.add(depositAmount);
|
const expectedTroveColl = troveCollateralBefore.add(depositAmount);
|
||||||
const expectedTroveDebt = troveDebtBefore.add(borrowAmount);
|
const expectedTroveDebt = troveDebtBefore.sub(repayAmount);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
troveCollateral,
|
troveCollateral,
|
||||||
|
@ -1347,7 +1347,7 @@ describe("Liquity", () => {
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
troveDebt,
|
troveDebt,
|
||||||
`Trove debt should have increased by at least ${borrowAmount} ETH`
|
`Trove debt (${troveDebtBefore}) should have decreased by at least ${repayAmount} LUSD`
|
||||||
).to.eq(expectedTroveDebt);
|
).to.eq(expectedTroveDebt);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user