Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial fixes for old tests (deployment setup, ripping out fees, "LUSD" -> "Bold", etc) (2) #68

Merged
merged 22 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions contracts/src/BorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import "./Interfaces/ITroveManager.sol";
import "./Interfaces/IBoldToken.sol";
import "./Interfaces/ICollSurplusPool.sol";
import "./Interfaces/ISortedTroves.sol";
import "./Interfaces/ILQTYStaking.sol";
import "./Dependencies/LiquityBase.sol";
import "./Dependencies/Ownable.sol";
import "./Dependencies/CheckContract.sol";

//import "forge-std/console.sol";
// import "forge-std/console.sol";


contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOperations {
Expand All @@ -28,9 +27,6 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe

ICollSurplusPool collSurplusPool;

ILQTYStaking public lqtyStaking;
address public lqtyStakingAddress;

IBoldToken public boldToken;

// A doubly linked list of Troves, sorted by their collateral ratios
Expand Down Expand Up @@ -89,7 +85,6 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe
event PriceFeedAddressChanged(address _newPriceFeedAddress);
event SortedTrovesAddressChanged(address _sortedTrovesAddress);
event BoldTokenAddressChanged(address _boldTokenAddress);
event LQTYStakingAddressChanged(address _lqtyStakingAddress);

event TroveCreated(address indexed _borrower, uint arrayIndex);
event TroveUpdated(address indexed _borrower, uint _debt, uint _coll, uint stake, BorrowerOperation operation);
Expand All @@ -106,8 +101,7 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe
address _collSurplusPoolAddress,
address _priceFeedAddress,
address _sortedTrovesAddress,
address _boldTokenAddress,
address _lqtyStakingAddress
address _boldTokenAddress
)
external
override
Expand Down Expand Up @@ -135,9 +129,7 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe
priceFeed = IPriceFeed(_priceFeedAddress);
sortedTroves = ISortedTroves(_sortedTrovesAddress);
boldToken = IBoldToken(_boldTokenAddress);
lqtyStakingAddress = _lqtyStakingAddress;
lqtyStaking = ILQTYStaking(_lqtyStakingAddress);


emit TroveManagerAddressChanged(_troveManagerAddress);
emit ActivePoolAddressChanged(_activePoolAddress);
emit DefaultPoolAddressChanged(_defaultPoolAddress);
Expand All @@ -147,7 +139,6 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe
emit PriceFeedAddressChanged(_priceFeedAddress);
emit SortedTrovesAddressChanged(_sortedTrovesAddress);
emit BoldTokenAddressChanged(_boldTokenAddress);
emit LQTYStakingAddressChanged(_lqtyStakingAddress);

_renounceOwnership();
}
Expand Down
3 changes: 1 addition & 2 deletions contracts/src/Interfaces/IBorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ interface IBorrowerOperations is ILiquityBase {
address _collSurplusPoolAddress,
address _priceFeedAddress,
address _sortedTrovesAddress,
address _boldTokenAddress,
address _lqtyStakingAddress
address _boldTokenAddress
) external;

function openTrove(uint _maxFee, uint _boldAmount, address _upperHint, address _lowerHint) external payable;
Expand Down
9 changes: 1 addition & 8 deletions contracts/src/Interfaces/ITroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import "./ILiquityBase.sol";
import "./IStabilityPool.sol";
import "./IBoldToken.sol";
import "./ISortedTroves.sol";
import "./ILQTYToken.sol";
import "./ILQTYStaking.sol";


// Common interface for the Trove Manager.
interface ITroveManager is ILiquityBase {
Expand All @@ -21,15 +18,11 @@ interface ITroveManager is ILiquityBase {
address _collSurplusPoolAddress,
address _priceFeedAddress,
address _boldTokenAddress,
address _sortedTrovesAddress,
address _lqtyTokenAddress,
address _lqtyStakingAddress
address _sortedTrovesAddress
) external;

function stabilityPool() external view returns (IStabilityPool);
function boldToken() external view returns (IBoldToken);
function lqtyToken() external view returns (ILQTYToken);
function lqtyStaking() external view returns (ILQTYStaking);
function sortedTroves() external view returns(ISortedTroves);
function borrowerOperationsAddress() external view returns (address);

Expand Down
48 changes: 17 additions & 31 deletions contracts/src/TroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import "./Interfaces/IStabilityPool.sol";
import "./Interfaces/ICollSurplusPool.sol";
import "./Interfaces/IBoldToken.sol";
import "./Interfaces/ISortedTroves.sol";
import "./Interfaces/ILQTYToken.sol";
import "./Interfaces/ILQTYStaking.sol";
import "./Dependencies/LiquityBase.sol";
import "./Dependencies/Ownable.sol";
import "./Dependencies/CheckContract.sol";
Expand All @@ -30,10 +28,6 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {

IBoldToken public override boldToken;

ILQTYToken public override lqtyToken;

ILQTYStaking public override lqtyStaking;

// A doubly linked list of Troves, sorted by their sorted by their collateral ratios
ISortedTroves public sortedTroves;

Expand Down Expand Up @@ -172,7 +166,6 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {
IActivePool activePool;
IDefaultPool defaultPool;
IBoldToken boldToken;
ILQTYStaking lqtyStaking;
ISortedTroves sortedTroves;
ICollSurplusPool collSurplusPool;
address gasPoolAddress;
Expand Down Expand Up @@ -207,8 +200,6 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {
event GasPoolAddressChanged(address _gasPoolAddress);
event CollSurplusPoolAddressChanged(address _collSurplusPoolAddress);
event SortedTrovesAddressChanged(address _sortedTrovesAddress);
event LQTYTokenAddressChanged(address _lqtyTokenAddress);
event LQTYStakingAddressChanged(address _lqtyStakingAddress);

event Liquidation(uint _liquidatedDebt, uint _liquidatedColl, uint _collGasCompensation, uint _boldGasCompensation);
event Redemption(uint _attemptedBoldAmount, uint _actualBoldAmount, uint _ETHSent, uint _ETHFee);
Expand Down Expand Up @@ -241,9 +232,7 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {
address _collSurplusPoolAddress,
address _priceFeedAddress,
address _boldTokenAddress,
address _sortedTrovesAddress,
address _lqtyTokenAddress,
address _lqtyStakingAddress
address _sortedTrovesAddress
)
external
override
Expand All @@ -268,8 +257,6 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {
priceFeed = IPriceFeed(_priceFeedAddress);
boldToken = IBoldToken(_boldTokenAddress);
sortedTroves = ISortedTroves(_sortedTrovesAddress);
lqtyToken = ILQTYToken(_lqtyTokenAddress);
lqtyStaking = ILQTYStaking(_lqtyStakingAddress);

emit BorrowerOperationsAddressChanged(_borrowerOperationsAddress);
emit ActivePoolAddressChanged(_activePoolAddress);
Expand All @@ -280,8 +267,6 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {
emit PriceFeedAddressChanged(_priceFeedAddress);
emit BoldTokenAddressChanged(_boldTokenAddress);
emit SortedTrovesAddressChanged(_sortedTrovesAddress);
emit LQTYTokenAddressChanged(_lqtyTokenAddress);
emit LQTYStakingAddressChanged(_lqtyStakingAddress);

_renounceOwnership();
}
Expand Down Expand Up @@ -496,7 +481,6 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {
activePool,
defaultPool,
IBoldToken(address(0)),
ILQTYStaking(address(0)),
sortedTroves,
ICollSurplusPool(address(0)),
address(0)
Expand Down Expand Up @@ -937,7 +921,6 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {
activePool,
defaultPool,
boldToken,
lqtyStaking,
sortedTroves,
collSurplusPool,
gasPoolAddress
Expand Down Expand Up @@ -1377,14 +1360,16 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {
}

function getRedemptionRateWithDecay() public view override returns (uint) {
return _calcRedemptionRate(_calcDecayedBaseRate());
return 0;
// return _calcRedemptionRate(_calcDecayedBaseRate());
}

function _calcRedemptionRate(uint _baseRate) internal pure returns (uint) {
return LiquityMath._min(
REDEMPTION_FEE_FLOOR + _baseRate,
DECIMAL_PRECISION // cap at a maximum of 100%
);
return 0;
// return LiquityMath._min(
// REDEMPTION_FEE_FLOOR + _baseRate,
// DECIMAL_PRECISION // cap at a maximum of 100%
// );
}

function _getRedemptionFee(uint _ETHDrawn) internal view returns (uint) {
Expand All @@ -1396,9 +1381,10 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {
}

function _calcRedemptionFee(uint _redemptionRate, uint _ETHDrawn) internal pure returns (uint) {
uint redemptionFee = _redemptionRate * _ETHDrawn / DECIMAL_PRECISION;
require(redemptionFee < _ETHDrawn, "TroveManager: Fee would eat up all returned collateral");
return redemptionFee;
return 0;
// uint redemptionFee = _redemptionRate * _ETHDrawn / DECIMAL_PRECISION;
// require(redemptionFee < _ETHDrawn, "TroveManager: Fee would eat up all returned collateral");
// return redemptionFee;
}

// --- Borrowing fee functions ---
Expand All @@ -1412,10 +1398,11 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {
}

function _calcBorrowingRate(uint _baseRate) internal pure returns (uint) {
return LiquityMath._min(
BORROWING_FEE_FLOOR + _baseRate,
MAX_BORROWING_FEE
);
return 0;
// return LiquityMath._min(
// BORROWING_FEE_FLOOR + _baseRate,
// MAX_BORROWING_FEE
// );
}

function getBorrowingFee(uint _boldDebt) external view override returns (uint) {
Expand All @@ -1430,7 +1417,6 @@ contract TroveManager is LiquityBase, Ownable, CheckContract, ITroveManager {
return _borrowingRate * _boldDebt / DECIMAL_PRECISION;
}


// Updates the baseRate state variable based on time elapsed since the last redemption or Bold borrowing operation.
function decayBaseRateFromBorrowing() external override {
_requireCallerIsBorrowerOperations();
Expand Down
7 changes: 2 additions & 5 deletions contracts/src/test/TestContracts/DevTestSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ contract DevTestSetup is BaseTest {
address(collSurplusPool),
address(priceFeed),
address(boldToken),
address(sortedTroves),
ZERO_ADDRESS, // No LQTY token
ZERO_ADDRESS // No LQTY staking
address(sortedTroves)
);

// set contracts in BorrowerOperations
Expand All @@ -96,8 +94,7 @@ contract DevTestSetup is BaseTest {
address(collSurplusPool),
address(priceFeed),
address(sortedTroves),
address(boldToken),
ZERO_ADDRESS // No LQTY staking
address(boldToken)
);

// set contracts in the Pools
Expand Down
81 changes: 9 additions & 72 deletions contracts/test/AccessControlTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,11 @@ contract(
let functionCaller;
let borrowerOperations;

let lqtyStaking;
let lqtyToken;

before(async () => {
coreContracts = await deploymentHelper.deployLiquityCore();
coreContracts.troveManager = await TroveManagerTester.new();
// TODO: coreContracts = await deploymentHelper.deployBoldTokenTester(coreContracts)
const LQTYContracts =
await deploymentHelper.deployLQTYTesterContractsHardhat(
bountyAddress,
lpRewardsAddress,
multisig
);


priceFeed = coreContracts.priceFeed;
boldToken = coreContracts.boldToken;
sortedTroves = coreContracts.sortedTroves;
Expand All @@ -60,14 +51,7 @@ contract(
functionCaller = coreContracts.functionCaller;
borrowerOperations = coreContracts.borrowerOperations;

lqtyStaking = LQTYContracts.lqtyStaking;
lqtyToken = LQTYContracts.lqtyToken;

await deploymentHelper.connectCoreContracts(coreContracts, LQTYContracts);
await deploymentHelper.connectLQTYContractsToCore(
LQTYContracts,
coreContracts
);
await deploymentHelper.connectCoreContracts(coreContracts);

for (account of accounts.slice(0, 10)) {
await th.openTrove(coreContracts, {
Expand Down Expand Up @@ -252,10 +236,10 @@ contract(
});

// increaseLUSD
it("increaseLUSDDebt(): reverts when called by an account that is not BO nor TroveM", async () => {
it("increaseBoldDebt(): reverts when called by an account that is not BO nor TroveM", async () => {
// Attempt call from alice
try {
const txAlice = await activePool.increaseLUSDDebt(100, {
const txAlice = await activePool.increaseBoldDebt(100, {
from: alice,
});
} catch (err) {
Expand All @@ -268,10 +252,10 @@ contract(
});

// decreaseLUSD
it("decreaseLUSDDebt(): reverts when called by an account that is not BO nor TroveM nor SP", async () => {
it("decreaseBoldDebt(): reverts when called by an account that is not BO nor TroveM nor SP", async () => {
// Attempt call from alice
try {
const txAlice = await activePool.decreaseLUSDDebt(100, {
const txAlice = await activePool.decreaseBoldDebt(100, {
from: alice,
});
} catch (err) {
Expand Down Expand Up @@ -317,10 +301,10 @@ contract(
});

// increaseLUSD
it("increaseLUSDDebt(): reverts when called by an account that is not TroveManager", async () => {
it("increaseBoldDebt(): reverts when called by an account that is not TroveManager", async () => {
// Attempt call from alice
try {
const txAlice = await defaultPool.increaseLUSDDebt(100, {
const txAlice = await defaultPool.increaseBoldDebt(100, {
from: alice,
});
} catch (err) {
Expand All @@ -333,7 +317,7 @@ contract(
it("decreaseLUSD(): reverts when called by an account that is not TroveManager", async () => {
// Attempt call from alice
try {
const txAlice = await defaultPool.decreaseLUSDDebt(100, {
const txAlice = await defaultPool.decreaseBoldDebt(100, {
from: alice,
});
} catch (err) {
Expand Down Expand Up @@ -498,52 +482,5 @@ contract(
}
});
});

describe("LQTYStaking", async (accounts) => {
it("increaseF_LUSD(): reverts when caller is not TroveManager", async () => {
try {
const txAlice = await lqtyStaking.increaseF_LUSD(dec(1, 18), {
from: alice,
});
} catch (err) {
assert.include(err.message, "revert");
}
});
});

describe("LQTYToken", async (accounts) => {
it("sendToLQTYStaking(): reverts when caller is not the LQTYSstaking", async () => {
// Check multisig has some LQTY
assert.isTrue((await lqtyToken.balanceOf(multisig)).gt(toBN("0")));

// multisig tries to call it
try {
const tx = await lqtyToken.sendToLQTYStaking(multisig, 1, {
from: multisig,
});
} catch (err) {
assert.include(err.message, "revert");
}

// FF >> time one year
await th.fastForwardTime(
timeValues.SECONDS_IN_ONE_YEAR,
web3.currentProvider
);

// Owner transfers 1 LQTY to bob
await lqtyToken.transfer(bob, dec(1, 18), { from: multisig });
assert.equal(await lqtyToken.balanceOf(bob), dec(1, 18));

// Bob tries to call it
try {
const tx = await lqtyToken.sendToLQTYStaking(bob, dec(1, 18), {
from: bob,
});
} catch (err) {
assert.include(err.message, "revert");
}
});
});
}
);
Loading
Loading