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

contracts: Add interfaces #80

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 14 additions & 10 deletions contracts/src/Interfaces/IBorrowerOperations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,29 @@ interface IBorrowerOperations is ILiquityBase {
address _boldTokenAddress
) external;

function openTrove(uint _maxFee, uint256 _ETHAmount, uint _boldAmount, address _upperHint, address _lowerHint, uint256 _annualInterestRate) external;
function openTrove(address _owner, uint256 _ownerIndex, uint _maxFee, uint256 _ETHAmount, uint _boldAmount, address _upperHint, address _lowerHint, uint256 _annualInterestRate, uint256 _spDeposit) external;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know combined operations will be coming later, but there's one that's worth considering already: opening a Trove with a delegated interest rate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Definitely! Good idea.


function addColl(uint256 _ETHAmount) external;
function addColl(uint256 _troveId, uint256 _ETHAmount) external;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does _ETHAMount (and generally, the term ETH) represent WETH and LSTs in the contracts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, exactly. Technically it’s actually any ERC20 used as collateral, but in our case it will be WETH and some LSTs.


function moveETHGainToTrove(address _user, uint256 _ETHAmount) external;
function moveETHGainToTrove(uint256 _troveId, uint256 _ETHAmount) external;

function withdrawColl(uint _amount) external;
function withdrawColl(uint256 _troveId, uint _amount) external;

function withdrawBold(uint _maxFee, uint _amount) external;
function withdrawBold(uint256 _troveId, uint _maxFee, uint _amount) external;

function repayBold(uint _amount) external;
function repayBold(uint256 _troveId, uint _amount) external;

function closeTrove() external;
function closeTrove(uint256 _troveId) external;

function adjustTrove(uint _maxFee, uint _collChange, bool _isCollIncrease, uint _debtChange, bool isDebtIncrease) external;
function adjustTrove(uint256 _troveId, uint _maxFee, uint _collChange, bool _isCollIncrease, uint _debtChange, bool isDebtIncrease) external;
Copy link
Collaborator

@danielattilasimon danielattilasimon Mar 12, 2024

Choose a reason for hiding this comment

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

Is _maxFee still needed? I know there's still an upfront interest payment (1 week's worth), but it's no longer unpredictable, like the borrow fee in v1 (unless you're delegating I guess, which is not the case for normal openTrove() / adjustTrove() / withdrawBold().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. I’ll remove it.


function claimCollateral() external;
function delegateInterest(uint256 _troveId, address _delegate) external;
Copy link
Collaborator

Choose a reason for hiding this comment

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

How do you undelegate? Is the idea to reuse adjustTroveInterestRate() for that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was thinking of delegating to zero address (or to owner), but that’s an option too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought of adjustTroveInterestRate() because I expect many people to also change their interest rate at the time of undelegation, so this would save an operation.

Copy link
Collaborator

@danielattilasimon danielattilasimon Mar 20, 2024

Choose a reason for hiding this comment

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

Upon further thought, there should probably be 2 different calls for interest rate delegation:

  • delegateInterestRateToIndividualManager(troveId, manager, min, max)
  • delegateInterestRateToBatchManager(troveId, batchManager)

The first one would grant the arbitrary address "manager" the right to call adjustTroveInterestRate() on the Trove with an interest rate within range of [min, max]. The owner of the Trove can undelegate by passing a zero address (or their own address) to the same function, like you suggested.

The second form is for batch delegation (duh) and requires batchManager address to have previously registered themselves as a batch manager, providing a [min, max] range (as well as a management fee) which can't be changed later. Undelegation in this case involves removing the Trove from the batch and reinserting it into a new position in the list, most likely even if the owner continues to use the last interest rate set by the batch manager (because batches must be kept contiguous). As such, we could either reuse adjustTroveInterestRate() for undelegation (and have it recognize when a Trove is part of a batch, and perform removal), or have a dedicated function that shares some of its internals with adjustTroveInterestRate(). I tend to prefer the latter as I dislike functions that branch too much, so I would add one more function:

  • undelegateInterestRateFromBatchManager(troveId, newAnnualInterestRate, upperHint, lowerHint)

Copy link
Collaborator

@danielattilasimon danielattilasimon Mar 20, 2024

Choose a reason for hiding this comment

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

Actually, we probably have to add hints to batch delegation too, as in:

  • delegateInterestRateToBatchManager(troveId, batchManager, upperHint, lowerHint)

Most of the time, hints won't be crucial as each batch will store "pointers" to both ends of its slice of the list for the purpose of quickly skipping over the entire batch, which can be used to find the correct insertion point on-chain. However, if a batch is empty, we don't know the correct position of constituents yet, so we need a hint.

Alternatively, we could put placeholder nodes in the list for each batch manager (or just empty batches) where new Troves are to be inserted, but this could be abused (spamming the list full of useless empty batches that make traversing the list costly, e.g. when redeeming). For that reason, I prefer hints.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, your reasoning above make a lot of sense to me. Feel free to add a commit with those new function signatures so they don’t get lost in this comments.
Thanks!


function claimCollateral(uint256 _troveId) external;

// TODO: addRepayWhitelistedAddress?(see github issue #64)

function getCompositeDebt(uint _debt) external pure returns (uint);

function adjustTroveInterestRate(uint _newAnnualInterestRate, address _upperHint, address _lowerHint) external;
function adjustTroveInterestRate(uint256 _troveId, uint _newAnnualInterestRate, address _upperHint, address _lowerHint) external;
}
17 changes: 16 additions & 1 deletion contracts/src/Interfaces/IStabilityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ interface IStabilityPool is ILiquityBase {
*/
function provideToSP(uint _amount) external;


/* withdrawFromSP():
* - Calculates depositor's ETH gain
* - Calculates the compounded deposit
Expand All @@ -81,6 +81,21 @@ interface IStabilityPool is ILiquityBase {
*/
function offset(uint _debt, uint _coll) external;

/* setETHSellIntent():
* Opt-in swap facility liquidation gains
*/
function setETHSellIntent(uint256 _ethAmount, uint256 _priceDiscount) external;

/* buyETH():
* Swap ETH to Bold using opt-in swap facility liquidation gains, from one depositor
*/
function buyETH(address _depositor, uint256 _ethAmount) external;

/* buyETHBatch():
* Swap ETH to Bold using opt-in swap facility liquidation gains, from multiple depositors
*/
function buyETHBatch(address[] calldata _depositors, uint256 _ethAmount) external;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Haven't thought this through, but shouldn't _ethAmount also be an array (of how much to buy from each depositor)? Or is the idea to move on from one depositor to the next when its intent is fully used up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, my idea was the latter. I’m assuming you would order the array from most favorable to least.


/*
* Returns the total amount of ETH held by the pool, accounted in an internal variable instead of `balance`,
* to exclude edge cases like ETH received from a self-destruct.
Expand Down
50 changes: 26 additions & 24 deletions contracts/src/Interfaces/ITroveManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ interface ITroveManager is ILiquityBase {

function getTroveFromTroveOwnersArray(uint _index) external view returns (address);

function getNominalICR(address _borrower) external view returns (uint);
function getCurrentICR(address _borrower, uint _price) external view returns (uint);
function getNominalICR(uint256 _troveId) external view returns (uint);
function getCurrentICR(uint256 _troveId, uint _price) external view returns (uint);

function liquidate(address _borrower) external;
function liquidate(uint256 _troveId) external;

function batchLiquidateTroves(address[] calldata _troveArray) external;
function batchLiquidateTroves(uint256[] calldata _troveArray) external;

function redeemCollateral(
uint _boldAmount,
Expand All @@ -49,55 +49,57 @@ interface ITroveManager is ILiquityBase {
uint _maxFee
) external;

function updateStakeAndTotalStakes(address _borrower) external returns (uint);
function updateStakeAndTotalStakes(uint256 _troveId) external returns (uint);

function addTroveOwnerToArray(address _borrower) external returns (uint index);
function addTroveOwnerToArray(uint256 _troveId) external returns (uint index);

function applyPendingRewards(address _borrower) external;
function applyPendingRewards(uint256 _troveId) external;

function getPendingETHReward(address _borrower) external view returns (uint);
function appyInterestToTroves(uint256[] calldata _troveIds) external;

function getPendingBoldDebtReward(address _borrower) external view returns (uint);
function getPendingETHReward(uint256 _troveId) external view returns (uint);

function hasPendingRewards(address _borrower) external view returns (bool);
function getPendingBoldDebtReward(uint256 _troveId) external view returns (uint);

function getEntireDebtAndColl(address _borrower) external view returns (
function hasPendingRewards(uint256 _troveId) external view returns (bool);

function getEntireDebtAndColl(uint256 _troveId) external view returns (
uint debt,
uint coll,
uint pendingBoldDebtReward,
uint pendingETHReward
);

function closeTrove(address _borrower) external;
function closeTrove(uint256 _troveId) external;

function removeStake(address _borrower) external;
function removeStake(uint256 _troveId) external;

function getRedemptionRate() external view returns (uint);
function getRedemptionRateWithDecay() external view returns (uint);

function getRedemptionFeeWithDecay(uint _ETHDrawn) external view returns (uint);

function getTroveStatus(address _borrower) external view returns (uint);
function getTroveStatus(uint256 _troveId) external view returns (uint);

function getTroveStake(address _borrower) external view returns (uint);
function getTroveStake(uint256 _troveId) external view returns (uint);

function getTroveDebt(address _borrower) external view returns (uint);
function getTroveDebt(uint256 _troveId) external view returns (uint);

function getTroveColl(address _borrower) external view returns (uint);
function getTroveColl(uint256 _troveId) external view returns (uint);

function getTroveAnnualInterestRate(address _borrower) external view returns (uint);
function getTroveAnnualInterestRate(uint256 _troveId) external view returns (uint);

function setTrovePropertiesOnOpen(address _borrower, uint256 _coll, uint256 _debt, uint256 _annualInterestRate) external returns (uint256);
function setTrovePropertiesOnOpen(uint256 _troveId, uint256 _coll, uint256 _debt, uint256 _annualInterestRate) external returns (uint256);

function increaseTroveColl(address _borrower, uint _collIncrease) external returns (uint);
function increaseTroveColl(uint256 _troveId, uint _collIncrease) external returns (uint);

function decreaseTroveColl(address _borrower, uint _collDecrease) external returns (uint);
function decreaseTroveColl(uint256 _troveId, uint _collDecrease) external returns (uint);

function increaseTroveDebt(address _borrower, uint _debtIncrease) external returns (uint);
function increaseTroveDebt(uint256 _troveId, uint _debtIncrease) external returns (uint);

function decreaseTroveDebt(address _borrower, uint _collDecrease) external returns (uint);
function decreaseTroveDebt(uint256 _troveId, uint _collDecrease) external returns (uint);

function changeAnnualInterestRate(address _borrower, uint256 _newAnnualInterestRate) external;
function changeAnnualInterestRate(uint256 _troveId, uint256 _newAnnualInterestRate) external;

function getTCR(uint _price) external view returns (uint);

Expand Down
Loading