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

Remove fees (borrow and redeem) and SP logic for LQTY and front ends #61

Merged
merged 6 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions contracts/src/BoldToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ contract BoldToken is CheckContract, IBoldToken {

mapping (address => uint256) private _nonces;

uint256 public deploymentStartTime;

// User data for Bold token
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
Expand Down Expand Up @@ -88,6 +90,8 @@ contract BoldToken is CheckContract, IBoldToken {
_HASHED_VERSION = hashedVersion;
_CACHED_CHAIN_ID = _chainID();
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(_TYPE_HASH, hashedName, hashedVersion);

deploymentStartTime = block.timestamp;
}

// --- Functions for intra-Liquity calls ---
Expand Down
19 changes: 2 additions & 17 deletions contracts/src/BorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe
vars.netDebt = _boldAmount;

if (!isRecoveryMode) {
vars.BoldFee = _triggerBorrowingFee(contractsCache.troveManager, contractsCache.boldToken, _boldAmount, _maxFeePercentage);
vars.netDebt = vars.netDebt + vars.BoldFee;
// TODO: implement interest rate charges
}
_requireAtLeastMinNetDebt(vars.netDebt);

Expand Down Expand Up @@ -271,8 +270,7 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe

// If the adjustment incorporates a debt increase and system is in Normal Mode, then trigger a borrowing fee
if (_isDebtIncrease && !isRecoveryMode) {
vars.BoldFee = _triggerBorrowingFee(contractsCache.troveManager, contractsCache.boldToken, _boldChange, _maxFeePercentage);
vars.netDebtChange = vars.netDebtChange + vars.BoldFee; // The raw debt change includes the fee
// TODO: implement interest rate charges
}

vars.debt = contractsCache.troveManager.getTroveDebt(_borrower);
Expand Down Expand Up @@ -358,19 +356,6 @@ contract BorrowerOperations is LiquityBase, Ownable, CheckContract, IBorrowerOpe

// --- Helper functions ---

function _triggerBorrowingFee(ITroveManager _troveManager, IBoldToken _boldToken, uint _boldAmount, uint _maxFeePercentage) internal returns (uint) {
_troveManager.decayBaseRateFromBorrowing(); // decay the baseRate state variable
uint BoldFee = _troveManager.getBorrowingFee(_boldAmount);

_requireUserAcceptsFee(BoldFee, _boldAmount, _maxFeePercentage);

// Send fee to LQTY staking contract
lqtyStaking.increaseF_bold(BoldFee);
_boldToken.mint(lqtyStakingAddress, BoldFee);

return BoldFee;
}

function _getUSDValue(uint _coll, uint _price) internal pure returns (uint) {
uint usdValue = _price * _coll / DECIMAL_PRECISION;

Expand Down
2 changes: 2 additions & 0 deletions contracts/src/Interfaces/IBoldToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "../Dependencies/IERC20.sol";
import "../Dependencies/IERC2612.sol";

interface IBoldToken is IERC20, IERC2612 {
function deploymentStartTime() external view returns (uint256);

function mint(address _account, uint256 _amount) external;

function burn(address _account, uint256 _amount) external;
Expand Down
109 changes: 24 additions & 85 deletions contracts/src/Interfaces/IStabilityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,7 @@ import "./ITroveManager.sol";
* Please see the implementation spec in the proof document, which closely follows on from the compounded deposit / ETH gain derivations:
* https://github.com/liquity/liquity/blob/master/papers/Scalable_Reward_Distribution_with_Compounding_Stakes.pdf
*
* --- LQTY ISSUANCE TO STABILITY POOL DEPOSITORS ---
*
* An LQTY issuance event occurs at every deposit operation, and every liquidation.
*
* Each deposit is tagged with the address of the front end through which it was made.
*
* All deposits earn a share of the issued LQTY in proportion to the deposit as a share of total deposits. The LQTY earned
* by a given deposit, is split between the depositor and the front end through which the deposit was made, based on the front end's kickbackRate.
*
* Please see the system Readme for an overview:
* https://github.com/liquity/dev/blob/main/README.md#lqty-issuance-to-stability-providers
*/
*/
interface IStabilityPool is ILiquityBase {
function borrowerOperations() external view returns (IBorrowerOperations);
function boldToken() external view returns (IBoldToken);
Expand All @@ -54,64 +43,34 @@ interface IStabilityPool is ILiquityBase {
address _activePoolAddress,
address _boldTokenAddress,
address _sortedTrovesAddress,
address _priceFeedAddress,
address _communityIssuanceAddress
address _priceFeedAddress
) external;

/*
* Initial checks:
* - Frontend is registered or zero address
* - Sender is not a registered frontend
* - _amount is not zero
* ---
* - Triggers a LQTY issuance, based on time passed since the last issuance. The LQTY issuance is shared between *all* depositors and front ends
* - Tags the deposit with the provided front end tag param, if it's a new deposit
* - Sends depositor's accumulated gains (LQTY, ETH) to depositor
* - Sends the tagged front end's accumulated LQTY gains to the tagged front end
* - Increases deposit and tagged front end's stake, and takes new snapshots for each.
*/
function provideToSP(uint _amount, address _frontEndTag) external;

/*
* Initial checks:
* - _amount is zero or there are no under collateralized troves left in the system
* - User has a non zero deposit
* ---
* - Triggers a LQTY issuance, based on time passed since the last issuance. The LQTY issuance is shared between *all* depositors and front ends
* - Removes the deposit's front end tag if it is a full withdrawal
* - Sends all depositor's accumulated gains (LQTY, ETH) to depositor
* - Sends the tagged front end's accumulated LQTY gains to the tagged front end
* - Decreases deposit and tagged front end's stake, and takes new snapshots for each.
*
* If _amount > userDeposit, the user withdraws all of their compounded deposit.
*/

/* provideToSP():
* - Calculates depositor's ETH gain
* - Calculates the compounded deposit
* - Increases deposit, and takes new snapshots of accumulators P and S
* - Sends depositor's accumulated ETH gains to depositor
*/
function provideToSP(uint _amount) external;


/* withdrawFromSP():
* - Calculates depositor's ETH gain
* - Calculates the compounded deposit
* - Sends the requested BOLD withdrawal to depositor
* - (If _amount > userDeposit, the user withdraws all of their compounded deposit)
* - Decreases deposit by withdrawn amount and takes new snapshots of accumulators P and S
*/
function withdrawFromSP(uint _amount) external;

/*
* Initial checks:
* - User has a non zero deposit
* - User has an open trove
* - User has some ETH gain
* ---
* - Triggers a LQTY issuance, based on time passed since the last issuance. The LQTY issuance is shared between *all* depositors and front ends
* - Sends all depositor's LQTY gain to depositor
* - Sends all tagged front end's LQTY gain to the tagged front end
* - Transfers the depositor's entire ETH gain from the Stability Pool to the caller's trove
* - Leaves their compounded deposit in the Stability Pool
* - Updates snapshots for deposit and tagged front end stake
*/
/* withdrawETHGainToTrove():
* - Transfers the depositor's entire ETH gain from the Stability Pool to the caller's trove
* - Leaves their compounded deposit in the Stability Pool
* - Takes new snapshots of accumulators P and S
*/
function withdrawETHGainToTrove(address _upperHint, address _lowerHint) external;

/*
* Initial checks:
* - Frontend (sender) not already registered
* - User (sender) has no deposit
* - _kickbackRate is in the range [0, 100%]
* ---
* Front end makes a one-time selection of kickback rate upon registering
*/
function registerFrontEnd(uint _kickbackRate) external;

/*
* Initial checks:
* - Caller is TroveManager
Expand All @@ -138,31 +97,11 @@ interface IStabilityPool is ILiquityBase {
*/
function getDepositorETHGain(address _depositor) external view returns (uint);

/*
* Calculate the LQTY gain earned by a deposit since its last snapshots were taken.
* If not tagged with a front end, the depositor gets a 100% cut of what their deposit earned.
* Otherwise, their cut of the deposit's earnings is equal to the kickbackRate, set by the front end through
* which they made their deposit.
*/
function getDepositorLQTYGain(address _depositor) external view returns (uint);

/*
* Return the LQTY gain earned by the front end.
*/
function getFrontEndLQTYGain(address _frontEnd) external view returns (uint);

/*
* Return the user's compounded deposit.
*/
function getCompoundedBoldDeposit(address _depositor) external view returns (uint);

/*
* Return the front end's compounded stake.
*
* The front end's compounded stake is equal to the sum of its depositors' compounded deposits.
*/
function getCompoundedFrontEndStake(address _frontEnd) external view returns (uint);

/*
* Fallback function
* Only callable by Active Pool, it just accounts for ETH received
Expand Down
2 changes: 2 additions & 0 deletions contracts/src/Interfaces/ITroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ interface ITroveManager is ILiquityBase {
function sortedTroves() external view returns(ISortedTroves);
function borrowerOperationsAddress() external view returns (address);

function BOOTSTRAP_PERIOD() external view returns (uint256);

function getTroveOwnersCount() external view returns (uint);

function getTroveFromTroveOwnersArray(uint _index) external view returns (address);
Expand Down
16 changes: 0 additions & 16 deletions contracts/src/OldTestContracts/ActivePoolTester.sol

This file was deleted.

29 changes: 0 additions & 29 deletions contracts/src/OldTestContracts/BoldTokenCaller.sol

This file was deleted.

66 changes: 0 additions & 66 deletions contracts/src/OldTestContracts/BoldTokenTester.sol

This file was deleted.

63 changes: 0 additions & 63 deletions contracts/src/OldTestContracts/BorrowerOperationsTester.sol

This file was deleted.

Loading
Loading