-
Notifications
You must be signed in to change notification settings - Fork 58
cToken bidder changes #647
Changes from all commits
dfbcbfc
edbba4c
ea3c08c
2f254bb
a3d11a8
c04f99b
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 |
---|---|---|
|
@@ -26,7 +26,9 @@ import { ERC20Wrapper } from "../lib/ERC20Wrapper.sol"; | |
import { ICToken } from "../core/interfaces/ICToken.sol"; | ||
import { IRebalanceAuctionModule } from "../core/interfaces/IRebalanceAuctionModule.sol"; | ||
import { IRebalancingSetToken } from "../core/interfaces/IRebalancingSetToken.sol"; | ||
import { IRebalancingSetTokenV3 } from "../core/interfaces/IRebalancingSetTokenV3.sol"; | ||
import { ITransferProxy } from "../core/interfaces/ITransferProxy.sol"; | ||
import { ITWAPAuctionGetters } from "../core/interfaces/ITWAPAuctionGetters.sol"; | ||
import { Rebalance } from "../core/lib/Rebalance.sol"; | ||
|
||
|
||
|
@@ -36,6 +38,10 @@ import { Rebalance } from "../core/lib/Rebalance.sol"; | |
* | ||
* A helper contract that mints a cToken from its underlying or redeems a cToken into | ||
* its underlying used for bidding in the RebalanceAuctionModule. | ||
* | ||
* CHANGELOG 6/8/2020: | ||
* - Remove reentrant modifier on bidAndWithdraw. This modifier is already used in RebalanceAuctionModule | ||
* - Add bidAndWithdrawTWAP function to check that bids can only succeed for the current auction chunk | ||
*/ | ||
contract RebalancingSetCTokenBidder is | ||
ReentrancyGuard | ||
|
@@ -132,8 +138,7 @@ contract RebalancingSetCTokenBidder is | |
uint256 _quantity, | ||
bool _allowPartialFill | ||
) | ||
external | ||
nonReentrant | ||
public | ||
{ | ||
// Get token flow arrays for the given bid quantity | ||
( | ||
|
@@ -168,6 +173,51 @@ contract RebalancingSetCTokenBidder is | |
); | ||
} | ||
|
||
/** | ||
* Bid on rebalancing a given quantity of sets held by a rebalancing token wrapping or unwrapping | ||
* a target cToken involved. The tokens are returned to the user. This function is only compatible with | ||
* Rebalancing Set Tokens that use TWAP liquidators | ||
* | ||
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. Would be good to add some language like here to note the exact problem this function is trying to solve. “During a TWAP chunk auction, there is an adverse scenario where a bidder submits a chunk auction bid with a low gas price and iterateChunkAuction is called before that transaction is mined. When the bidder’s transaction gets mined, it may execute at an unintended price. To combat this, the BidAndWithdrawTWAP function checks that a new chunk auction has not been initiated from the point of bidding. The intended use case is that the bidder would retrieve the Rebalancing SetToken’s lastChunkAuctionEnd variable off-chain and submit it as part of the bid.” |
||
* During a TWAP chunk auction, there is an adverse scenario where a bidder submits a chunk auction bid | ||
* with a low gas price and iterateChunkAuction is called before that transaction is mined. When the bidder’s | ||
* transaction gets mined, it may execute at an unintended price. To combat this, he BidAndWithdrawTWAP | ||
* function checks that a new chunk auction has not been initiated from the point of bidding. | ||
* The intended use case is that the bidder would retrieve the Rebalancing SetToken’s lastChunkAuctionEnd | ||
* variable off-chain and submit it as part of the bid. | ||
* | ||
* @param _rebalancingSetToken Instance of the rebalancing token being bid on | ||
* @param _quantity Number of currentSets to rebalance | ||
* @param _lastChunkTimestamp Timestamp of end of previous chunk auction used to identify which | ||
chunk the bidder wants to bid on | ||
* @param _allowPartialFill Set to true if want to partially fill bid when quantity | ||
is greater than currentRemainingSets | ||
*/ | ||
|
||
function bidAndWithdrawTWAP( | ||
IRebalancingSetTokenV3 _rebalancingSetToken, | ||
uint256 _quantity, | ||
uint256 _lastChunkTimestamp, | ||
bool _allowPartialFill | ||
) | ||
external | ||
{ | ||
address liquidatorAddress = address(_rebalancingSetToken.liquidator()); | ||
address rebalancingSetTokenAddress = address(_rebalancingSetToken); | ||
|
||
uint256 lastChunkAuctionEnd = ITWAPAuctionGetters(liquidatorAddress).getLastChunkAuctionEnd(rebalancingSetTokenAddress); | ||
|
||
require( | ||
lastChunkAuctionEnd == _lastChunkTimestamp, | ||
"RebalancingSetCTokenBidder.bidAndWithdrawTWAP: Bid must be for intended chunk" | ||
); | ||
|
||
bidAndWithdraw( | ||
IRebalancingSetToken(rebalancingSetTokenAddress), | ||
_quantity, | ||
_allowPartialFill | ||
); | ||
} | ||
|
||
/* | ||
* Get token inflows and outflows and combined token array denominated in underlying required | ||
* for bid for a given rebalancing Set token. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to add month/date/year of change