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

Add basic dev test setup #59

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 0 additions & 1 deletion contracts/src/BorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe
checkContract(_priceFeedAddress);
checkContract(_sortedTrovesAddress);
checkContract(_boldTokenAddress);
checkContract(_lqtyStakingAddress);

troveManager = ITroveManager(_troveManagerAddress);
activePool = IActivePool(_activePoolAddress);
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/GasPool.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import './Interfaces/IGasPool.sol';

/**
* The purpose of this contract is to hold Bold tokens for gas compensation:
Expand All @@ -13,6 +13,6 @@ pragma solidity 0.8.18;
* 50 Bold debt on the trove is cancelled.
* See this issue for more context: https://github.com/liquity/dev/issues/186
*/
contract GasPool {
contract GasPool is IGasPool {
// do nothing, as the core contracts have permission to send to and burn from this address
}
10 changes: 10 additions & 0 deletions contracts/src/Interfaces/IActivePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,15 @@ import "./IPool.sol";


interface IActivePool is IPool {
function stabilityPoolAddress() external view returns (address);
function defaultPoolAddress() external view returns (address);
function borrowerOperationsAddress() external view returns (address);
function troveManagerAddress() external view returns (address);
function sendETH(address _account, uint _amount) external;
function setAddresses(
address _borrowerOperationsAddress,
address _troveManagerAddress,
address _stabilityPoolAddress,
address _defaultPoolAddress
) external;
}
10 changes: 9 additions & 1 deletion contracts/src/Interfaces/IBorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

pragma solidity 0.8.18;

import "./ILiquityBase.sol";
import "./ITroveManager.sol";
import "./IPriceFeed.sol";
import "./ISortedTroves.sol";

// Common interface for the Trove Manager.
interface IBorrowerOperations {
interface IBorrowerOperations is ILiquityBase {
function troveManager() external view returns (ITroveManager);
function sortedTroves() external view returns (ISortedTroves);

function setAddresses(
address _troveManagerAddress,
address _activePoolAddress,
Expand Down
3 changes: 3 additions & 0 deletions contracts/src/Interfaces/IDefaultPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import "./IPool.sol";


interface IDefaultPool is IPool {
function troveManagerAddress() external view returns (address);
function activePoolAddress() external view returns (address);
// --- Functions ---
function sendETHToActivePool(uint _amount) external;
function setAddresses(address _troveManagerAddress, address _activePoolAddress) external;
}
7 changes: 7 additions & 0 deletions contracts/src/Interfaces/IGasPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

interface IGasPool {
// empty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious: why is this needed?

Copy link
Collaborator Author

@RickGriff RickGriff Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm that was to be consistent with declaring interfaces in BaseTest then deploying in DevTestSetup. I've changed this so we just declare the contract GasPool in BaseTest rather than the interface (and deleted the interface). An empty interface is awkward.

}
5 changes: 4 additions & 1 deletion contracts/src/Interfaces/ILiquityBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

pragma solidity 0.8.18;

import "./IActivePool.sol";
import "./IDefaultPool.sol";
import "./IPriceFeed.sol";


interface ILiquityBase {
function activePool() external view returns (IActivePool);
function defaultPool() external view returns (IDefaultPool);
function priceFeed() external view returns (IPriceFeed);
}
5 changes: 5 additions & 0 deletions contracts/src/Interfaces/ISortedTroves.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

pragma solidity 0.8.18;

import "./ITroveManager.sol";

// Common interface for the SortedTroves Doubly Linked List.
interface ISortedTroves {
function borrowerOperationsAddress() external view returns (address);
function troveManager() external view returns (ITroveManager);

function setParams(uint256 _size, address _TroveManagerAddress, address _borrowerOperationsAddress) external;

function insert(address _id, uint256 _ICR, address _prevId, address _nextId) external;
Expand Down
12 changes: 11 additions & 1 deletion contracts/src/Interfaces/IStabilityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

pragma solidity 0.8.18;

import "./IActivePool.sol";
import "./ILiquityBase.sol";
import "./IBorrowerOperations.sol";
import "./IBoldToken.sol";
import "./ITroveManager.sol";

/*
* The Stability Pool holds Bold tokens deposited by Stability Pool depositors.
*
Expand Down Expand Up @@ -33,7 +39,11 @@ pragma solidity 0.8.18;
* Please see the system Readme for an overview:
* https://github.com/liquity/dev/blob/main/README.md#lqty-issuance-to-stability-providers
*/
interface IStabilityPool {
interface IStabilityPool is ILiquityBase {
function borrowerOperations() external view returns (IBorrowerOperations);
function boldToken() external view returns (IBoldToken);
function troveManager() external view returns (ITroveManager);

/*
* Called only once on init, to set addresses of other Liquity contracts
* Callable only by owner, renounces ownership at the end
Expand Down
3 changes: 3 additions & 0 deletions contracts/src/Interfaces/ITroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity 0.8.18;
import "./ILiquityBase.sol";
import "./IStabilityPool.sol";
import "./IBoldToken.sol";
import "./ISortedTroves.sol";
import "./ILQTYToken.sol";
import "./ILQTYStaking.sol";

Expand All @@ -29,6 +30,8 @@ interface ITroveManager is ILiquityBase {
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);

function getTroveOwnersCount() external view returns (uint);

Expand Down
16 changes: 16 additions & 0 deletions contracts/src/OldTestContracts/ActivePoolTester.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import "../ActivePool.sol";

contract ActivePoolTester is ActivePool {

function unprotectedIncreaseBoldDebt(uint _amount) external {
boldDebt = boldDebt + _amount;
}

function unprotectedPayable() external payable {
ETH = ETH + msg.value;
}
}
29 changes: 29 additions & 0 deletions contracts/src/OldTestContracts/BoldTokenCaller.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import "../Interfaces/IBoldToken.sol";

contract BoldTokenCaller {
IBoldToken Bold;

function setBold(IBoldToken _bold) external {
Bold = _bold;
}

function boldMint(address _account, uint _amount) external {
Bold.mint(_account, _amount);
}

function boldBurn(address _account, uint _amount) external {
Bold.burn(_account, _amount);
}

function boldSendToPool(address _sender, address _poolAddress, uint256 _amount) external {
Bold.sendToPool(_sender, _poolAddress, _amount);
}

function boldReturnFromPool(address _poolAddress, address _receiver, uint256 _amount ) external {
Bold.returnFromPool(_poolAddress, _receiver, _amount);
}
}
66 changes: 66 additions & 0 deletions contracts/src/OldTestContracts/BoldTokenTester.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import "../BoldToken.sol";

contract BoldTokenTester is BoldToken {

bytes32 private immutable _PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;

constructor(
address _troveManagerAddress,
address _stabilityPoolAddress,
address _borrowerOperationsAddress
) public BoldToken(_troveManagerAddress,
_stabilityPoolAddress,
_borrowerOperationsAddress) {}

function unprotectedMint(address _account, uint256 _amount) external {
// No check on caller here

_mint(_account, _amount);
}

function unprotectedBurn(address _account, uint _amount) external {
// No check on caller here

_burn(_account, _amount);
}

function unprotectedSendToPool(address _sender, address _poolAddress, uint256 _amount) external {
// No check on caller here

_transfer(_sender, _poolAddress, _amount);
}

function unprotectedReturnFromPool(address _poolAddress, address _receiver, uint256 _amount ) external {
// No check on caller here

_transfer(_poolAddress, _receiver, _amount);
}

function callInternalApprove(address owner, address spender, uint256 amount) external returns (bool) {
_approve(owner, spender, amount);
}

function getChainId() external view returns (uint256 chainID) {
//return _chainID(); // it’s private
assembly {
chainID := chainid()
}
}

function getDigest(address owner, address spender, uint amount, uint nonce, uint deadline) external view returns (bytes32) {
return keccak256(abi.encodePacked(
uint16(0x1901),
domainSeparator(),
keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, amount, nonce, deadline))
)
);
}

function recoverAddress(bytes32 digest, uint8 v, bytes32 r, bytes32 s) external pure returns (address) {
return ecrecover(digest, v, r, s);
}
}
63 changes: 63 additions & 0 deletions contracts/src/OldTestContracts/BorrowerOperationsTester.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import "../BorrowerOperations.sol";

/* Tester contract inherits from BorrowerOperations, and provides external functions
for testing the parent's internal functions. */
contract BorrowerOperationsTester is BorrowerOperations {

function getNewICRFromTroveChange
(
uint _coll,
uint _debt,
uint _collChange,
bool isCollIncrease,
uint _debtChange,
bool isDebtIncrease,
uint _price
)
external
pure
returns (uint)
{
return _getNewICRFromTroveChange(_coll, _debt, _collChange, isCollIncrease, _debtChange, isDebtIncrease, _price);
}

function getNewTCRFromTroveChange
(
uint _collChange,
bool isCollIncrease,
uint _debtChange,
bool isDebtIncrease,
uint _price
)
external
view
returns (uint)
{
return _getNewTCRFromTroveChange(_collChange, isCollIncrease, _debtChange, isDebtIncrease, _price);
}

function getUSDValue(uint _coll, uint _price) external pure returns (uint) {
return _getUSDValue(_coll, _price);
}

function callInternalAdjustLoan
(
address _borrower,
uint _collWithdrawal,
uint _debtChange,
bool _isDebtIncrease,
address _upperHint,
address _lowerHint)
external
{
_adjustTrove(_borrower, _collWithdrawal, _debtChange, _isDebtIncrease, _upperHint, _lowerHint, 0);
}


// Payable fallback function
receive() external payable { }
}
60 changes: 60 additions & 0 deletions contracts/src/OldTestContracts/CDPManagerTester.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import "../TroveManager.sol";

/* Tester contract inherits from TroveManager, and provides external functions
for testing the parent's internal functions. */

contract TroveManagerTester is TroveManager {

function computeICR(uint _coll, uint _debt, uint _price) external pure returns (uint) {
return LiquityMath._computeCR(_coll, _debt, _price);
}

function getCollGasCompensation(uint _coll) external pure returns (uint) {
return _getCollGasCompensation(_coll);
}

function getBoldGasCompensation() external pure returns (uint) {
return BOLD_GAS_COMPENSATION;
}

function getCompositeDebt(uint _debt) external pure returns (uint) {
return _getCompositeDebt(_debt);
}

function unprotectedDecayBaseRateFromBorrowing() external returns (uint) {
baseRate = _calcDecayedBaseRate();
assert(baseRate >= 0 && baseRate <= DECIMAL_PRECISION);

_updateLastFeeOpTime();
return baseRate;
}

function minutesPassedSinceLastFeeOp() external view returns (uint) {
return _minutesPassedSinceLastFeeOp();
}

function setLastFeeOpTimeToNow() external {
lastFeeOperationTime = block.timestamp;
}

function setBaseRate(uint _baseRate) external {
baseRate = _baseRate;
}

function callGetRedemptionFee(uint _ETHDrawn) external view returns (uint) {
_getRedemptionFee(_ETHDrawn);
}

function getActualDebtFromComposite(uint _debtVal) external pure returns (uint) {
return _getNetDebt(_debtVal);
}

function callInternalRemoveTroveOwner(address _troveOwner) external {
uint troveOwnersArrayLength = TroveOwners.length;
_removeTroveOwner(_troveOwner, troveOwnersArrayLength);
}
}
Loading
Loading