Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
[RBSetV2] Add ability to change entry fee (#554)
Browse files Browse the repository at this point in the history
Change entry fee. Add backward compatibility
  • Loading branch information
felix2feng authored and bweick committed Dec 30, 2019
1 parent e0e8124 commit 32162d5
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 62 deletions.
17 changes: 4 additions & 13 deletions contracts/core/fee-calculators/FixedFeeCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { CommonMath } from "../../lib/CommonMath.sol";
import { ICore } from "../interfaces/ICore.sol";
import { IFeeCalculator } from "../interfaces/IFeeCalculator.sol";
import { SetTokenLibrary } from "../lib/SetTokenLibrary.sol";
import { ScaleValidations } from "../../lib/ScaleValidations.sol";


/**
Expand All @@ -34,10 +35,6 @@ import { SetTokenLibrary } from "../lib/SetTokenLibrary.sol";
contract FixedFeeCalculator is IFeeCalculator {
using SafeMath for uint256;

/* ============ Constants ============ */

uint256 public constant ONE_BASIS_POINT = 10 ** 14;

/* ============ State Variables ============ */

// Mapping between an address and its initialization state
Expand Down Expand Up @@ -95,15 +92,9 @@ contract FixedFeeCalculator is IFeeCalculator {
private
view
{
require(
_fee <= CommonMath.scaleFactor(),
"Fee must be equal or less than 100%"
);

require(
_fee.mod(ONE_BASIS_POINT) == 0,
"Fee must be multiple of 0.01%"
);
ScaleValidations.validateLessThanEqualOneHundredPercent(_fee);

ScaleValidations.validateMultipleOfBasisPoint(_fee);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions contracts/core/interfaces/IRebalancingSetTokenV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ interface IRebalancingSetTokenV2 {
)
external;

/*
* Set new fee entry fee.
*/
function setEntryFee(
uint256 _newEntryFee
)
external;

/*
* Initiates the rebalance in coordination with the Liquidator contract.
* In this step, we redeem the currentSet and pass relevant information
Expand Down
11 changes: 11 additions & 0 deletions contracts/core/tokens/rebalancing-v2/BackwardCompatibility.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ import { RebalancingSetState } from "./RebalancingSetState.sol";
contract BackwardCompatibility is
RebalancingSetState
{
/* ============ Empty Variables ============ */

// Deprecated auctionLibrary. Returns 0x00 to prevent reverts
address public auctionLibrary;

// Deprecated proposal period. Returns 0 to prevent reverts
uint256 public proposalPeriod;

// Deprecated proposal start time. Returns 0 to prevent reverts
uint256 public proposalStartTime;

/* ============ Getters ============ */

function getAuctionPriceParameters() external view returns (uint256[] memory) {
Expand Down
27 changes: 6 additions & 21 deletions contracts/core/tokens/rebalancing-v2/Issuance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,9 @@ contract Issuance is
internal
view
{
require(
msg.sender == address(core),
"Not from Core"
);

require(
rebalanceState == RebalancingLibrary.State.Default,
"Invalid state"
);
validateCallerIsCore();

validateRebalanceStateIs(RebalancingLibrary.State.Default);
}

/*
Expand All @@ -73,24 +67,15 @@ contract Issuance is
internal
view
{
require(
rebalanceState != RebalancingLibrary.State.Rebalance,
"Invalid state"
);
validateRebalanceStateIsNot(RebalancingLibrary.State.Rebalance);

if (rebalanceState == RebalancingLibrary.State.Drawdown) {
// In Drawdown Sets can only be burned as part of the withdrawal process
require(
core.validModules(msg.sender),
"Cant be Drawdown"
);
validateCallerIsModule();
} else {
// When in non-Rebalance or Drawdown state, check that function caller is Core
// so that Sets can be redeemed
require(
msg.sender == address(core),
"Not from core"
);
validateCallerIsCore();
}
}
/*
Expand Down
10 changes: 2 additions & 8 deletions contracts/core/tokens/rebalancing-v2/RebalancingBid.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ contract RebalancingBid is
internal
view
{
require(
rebalanceState == RebalancingLibrary.State.Rebalance,
"State must be Rebalance"
);
validateRebalanceStateIs(RebalancingLibrary.State.Rebalance);

require(
_quantity > 0,
Expand All @@ -75,10 +72,7 @@ contract RebalancingBid is
internal
view
{
require(
core.validModules(msg.sender),
"Not approved module"
);
validateCallerIsModule();

validateGetBidPrice(_quantity);
}
Expand Down
5 changes: 1 addition & 4 deletions contracts/core/tokens/rebalancing-v2/RebalancingFailure.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ contract RebalancingFailure is
view
{
// Token must be in Rebalance State
require(
rebalanceState == RebalancingLibrary.State.Rebalance,
"Invalid state"
);
validateRebalanceStateIs(RebalancingLibrary.State.Rebalance);

// Failure triggers must be met
require(
Expand Down
61 changes: 57 additions & 4 deletions contracts/core/tokens/rebalancing-v2/RebalancingSetState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ISetToken } from "../../interfaces/ISetToken.sol";
import { IVault } from "../../interfaces/IVault.sol";
import { IWhiteList } from "../../interfaces/IWhiteList.sol";
import { RebalancingLibrary } from "../../lib/RebalancingLibrary.sol";
import { ScaleValidations } from "../../../lib/ScaleValidations.sol";


/**
Expand Down Expand Up @@ -127,10 +128,7 @@ contract RebalancingSetState {
/* ============ Modifier ============ */

modifier onlyManager() {
require(
msg.sender == manager,
"Must be manager"
);
validateManager();
_;
}

Expand All @@ -146,6 +144,11 @@ contract RebalancingSetState {
address oldLiquidator
);

event NewEntryFee(
uint256 newEntryFee,
uint256 oldEntryFee
);

event NewFeeRecipient(
address newFeeRecipient,
address oldFeeRecipient
Expand Down Expand Up @@ -187,6 +190,20 @@ contract RebalancingSetState {
manager = _newManager;
}

function setEntryFee(
uint256 _newEntryFee
)
external
onlyManager
{
ScaleValidations.validateLessThanEqualOneHundredPercent(_newEntryFee);

ScaleValidations.validateMultipleOfBasisPoint(_newEntryFee);

emit NewEntryFee(_newEntryFee, entryFee);
entryFee = _newEntryFee;
}

/*
* Set new liquidator address. Only whitelisted addresses are valid.
*/
Expand Down Expand Up @@ -273,4 +290,40 @@ contract RebalancingSetState {
{
return _tokenAddress == address(currentSet);
}

/* ============ Validations ============ */
function validateManager() internal view {
require(
msg.sender == manager,
"Not manager"
);
}

function validateCallerIsCore() internal view {
require(
msg.sender == address(core),
"Not Core"
);
}

function validateCallerIsModule() internal view {
require(
core.validModules(msg.sender),
"Not approved module"
);
}

function validateRebalanceStateIs(RebalancingLibrary.State _requiredState) internal view {
require(
rebalanceState == _requiredState,
"Invalid state"
);
}

function validateRebalanceStateIsNot(RebalancingLibrary.State _requiredState) internal view {
require(
rebalanceState != _requiredState,
"Invalid state"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ contract RebalancingSettlement is
internal
view
{
require(
rebalanceState == RebalancingLibrary.State.Rebalance,
"State must be Rebalance"
);
validateRebalanceStateIs(RebalancingLibrary.State.Rebalance);
}

/*
Expand Down
5 changes: 1 addition & 4 deletions contracts/core/tokens/rebalancing-v2/RebalancingStart.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ contract RebalancingStart is
internal
view
{
require(
rebalanceState == RebalancingLibrary.State.Default,
"Invalid state"
);
validateRebalanceStateIs(RebalancingLibrary.State.Default);

// Enough time must have passed from last rebalance to start a new proposal
require(
Expand Down
39 changes: 39 additions & 0 deletions contracts/lib/ScaleValidations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2019 Set Labs Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity 0.5.7;

import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol";


library ScaleValidations {
using SafeMath for uint256;

uint256 private constant ONE_HUNDRED_PERCENT = 1e18;
uint256 private constant ONE_BASIS_POINT = 1e14;

function validateLessThanEqualOneHundredPercent(uint256 _value) internal view {
require(_value <= ONE_HUNDRED_PERCENT, "Must be <= 100%");
}

function validateMultipleOfBasisPoint(uint256 _value) internal view {
require(
_value.mod(ONE_BASIS_POINT) == 0,
"Must be multiple of 0.01%"
);
}
}

8 changes: 8 additions & 0 deletions contracts/mocks/lib/CommonMathMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ contract CommonMathMock {
return CommonMath.safePower(a, pow);
}

function testScaleFactor()
external
pure
returns (uint256 result)
{
return CommonMath.scaleFactor();
}

function testScale(
uint256 a
)
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.3.12-beta",
"version": "1.3.13-beta",
"description": "Smart contracts for {Set} Protocol",
"main": "dist/artifacts/index.js",
"typings": "dist/typings/artifacts/index.d.ts",
Expand Down

0 comments on commit 32162d5

Please sign in to comment.