-
Notifications
You must be signed in to change notification settings - Fork 52
[rolling fallback] incentive dutch auction #1127
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
Changes from all commits
f62e8fc
35cc852
1b64093
1fc4234
7d193bb
0e54c34
239362e
57b3171
13104de
af8b852
5e962c3
d89c3dd
db338dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,46 +27,61 @@ contract BlueFallbackRolling is IBlueFallbackRolling { | |
| BLUE = _blue; | ||
| } | ||
|
|
||
| /// @param start The start time of the rolling period. | ||
| /// @param incentive The caller incentive as a WAD-scaled percentage of the debt rolled. | ||
| /// @dev The LLTV of the Blue market must be greater than or equal to the LLTV of the Midnight market. | ||
| function setConfig(bytes32 midnightId, bytes32 blueId, uint64 start, uint64 incentive, bool enabled) | ||
| external | ||
| override | ||
| { | ||
| require(incentive <= WAD, IncentiveTooHigh()); | ||
| function setConfig( | ||
| bytes32 midnightId, | ||
| bytes32 blueId, | ||
| uint64 start, | ||
| uint64 end, | ||
| uint64 incentiveAtStart, | ||
| uint64 incentiveAtEnd, | ||
| bool enabled | ||
| ) external override { | ||
| require(start < end, EndNotAfterStart()); | ||
| require(incentiveAtStart <= WAD, IncentiveTooHigh()); | ||
| require(incentiveAtEnd <= WAD, IncentiveTooHigh()); | ||
|
|
||
| isConfig[msg.sender][keccak256(abi.encode(midnightId, blueId, start, incentive))] = enabled; | ||
| isConfig[msg.sender][keccak256(abi.encode(midnightId, blueId, start, end, incentiveAtStart, incentiveAtEnd))] = | ||
| enabled; | ||
|
|
||
| emit SetConfig(msg.sender, midnightId, blueId, start, incentive, enabled); | ||
| emit SetConfig(msg.sender, midnightId, blueId, start, end, incentiveAtStart, incentiveAtEnd, enabled); | ||
| } | ||
|
|
||
| function roll( | ||
| Market memory midnightMarket, | ||
| MarketParams memory blueMarketParams, | ||
| address user, | ||
| uint64 start, | ||
| uint64 incentive, | ||
| uint64 end, | ||
| uint64 incentiveAtStart, | ||
| uint64 incentiveAtEnd, | ||
| uint256 assets | ||
| ) external override { | ||
| bytes32 midnightId = IdLib.toId(midnightMarket); | ||
| bytes32 blueId = Id.unwrap(blueMarketParams.id()); | ||
| require(isConfig[user][keccak256(abi.encode(midnightId, blueId, start, incentive))], NotConfigured()); | ||
| require( | ||
| isConfig[user][keccak256(abi.encode(midnightId, blueId, start, end, incentiveAtStart, incentiveAtEnd))], | ||
| NotConfigured() | ||
| ); | ||
| require(blueMarketParams.loanToken == midnightMarket.loanToken, InconsistentLoanToken()); | ||
| require(block.timestamp >= start, NotStarted()); | ||
| require(block.timestamp <= end, Ended()); | ||
| uint128 collateralBitmap = IMidnight(MIDNIGHT).collateralBitmap(midnightId, user); | ||
| require(UtilsLib.countBits(collateralBitmap) == 1, IncorrectActivatedCollateral()); | ||
| uint256 collateralIndex = UtilsLib.msb(collateralBitmap); | ||
| require( | ||
| blueMarketParams.collateralToken == midnightMarket.collateralParams[collateralIndex].token, | ||
| InconsistentCollateralToken() | ||
| ); | ||
| require(midnightMarket.collateralParams[collateralIndex].lltv <= blueMarketParams.lltv, BlueLltvTooLow()); | ||
|
Comment on lines
72
to
+76
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these checks (as well as the loan token check) are not perfect because the users could set non-valid configs
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. potential solution, check these in
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not too bad that one can set an invalid config, but IMO we should do either all checks in setConfig (meaning you can't enable an invalid config) or all checks in roll There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Imho it's better to do all check in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there are currently 4 checks on a given config: start <= end, incentives <= WAD, loan token match and collateral token match. We can't really check the collateral tokens because the config might be set before the user supply any collateral into midnight. It's also more expensive in gas to check the loan token in
peyha marked this conversation as resolved.
|
||
|
|
||
| // Round in favor of the Midnight position. | ||
|
MathisGD marked this conversation as resolved.
|
||
| uint256 collateralAssets = IMidnight(MIDNIGHT).collateral(midnightId, user, collateralIndex) | ||
| .mulDivDown(assets, IMidnight(MIDNIGHT).debt(midnightId, user)); | ||
| // Round in favor of the borrower. | ||
| uint256 incentiveAssets = UtilsLib.mulDivDown(assets, incentive, WAD); | ||
| // Round against the roller. | ||
| uint256 incentiveFactor = incentiveAtStart | ||
| + UtilsLib.mulDivDown(incentiveAtEnd - incentiveAtStart, block.timestamp - start, end - start); | ||
| uint256 incentiveAssets = UtilsLib.mulDivDown(assets, incentiveFactor, WAD); | ||
|
|
||
| emit Roll(msg.sender, user, midnightId, blueId, assets, collateralAssets, incentiveAssets); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.