Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.
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
2 changes: 2 additions & 0 deletions artifacts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,10 @@ export {
LibraryMockHelper,
LiquidatorHelper,
RebalancingHelper,
RebalancingSetBidderHelper,
RebalancingSetV2Helper,
RebalancingSetV3Helper,
RebalanceTestSetup,
ValuationHelper
} from '../utils/helpers';

Expand Down
54 changes: 52 additions & 2 deletions contracts/helper/RebalancingSetCTokenBidder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";


Expand All @@ -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
Copy link
Contributor

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

* - Add bidAndWithdrawTWAP function to check that bids can only succeed for the current auction chunk
*/
contract RebalancingSetCTokenBidder is
ReentrancyGuard
Expand Down Expand Up @@ -132,8 +138,7 @@ contract RebalancingSetCTokenBidder is
uint256 _quantity,
bool _allowPartialFill
)
external
nonReentrant
public
{
// Get token flow arrays for the given bid quantity
(
Expand Down Expand Up @@ -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
*
Copy link
Contributor

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 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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "set-protocol-contracts",
"version": "1.4.12-beta",
"version": "1.4.13-beta",
"description": "Smart contracts for {Set} Protocol",
"main": "dist/artifacts/index.js",
"typings": "dist/typings/artifacts/index.d.ts",
Expand Down
Loading