FeeManager - Parameters Setting
Computing transaction fees according to the specified logic
FeeManagercontract is responsible for updating fees within relevant contracts of the protocol for HAs, for users minting and burning and for SLPs slippage. There is one such contract per collateral/stablecoin pair.
It relies on external functions that keepers shoud be able to call to update parameters in the corresponding contract.
The reason for having such a contract is that it may be expensive to compute collateral ratio in terms of gas fees. If the structure of some of the fees depend on the collateral ratio, computing it all the time could make some transactions really inefficient: from a user perspective it is better to have a parameter which stores the fees and that can be updated by trusted functions which take into account the actual collateral ratio.
AccessControl. This contract is not upgradeable.
The reference to a
FeeManagercontract in another contract (like a
StableMastercontract) can always be modified.
Note that although it has setters to define fees, the
FeeManagerdoes not inherit from the
FunctionUtilsbecause the parameters for the fees are stored as
uint256rather than as
uint64and a different
_piecewiseLinearfunction is hence needed. The reason for this different structure is that there is otherwise a risk of overflow in the
_piecewiseLinearfunction used in other contracts.
stableMaster: Reference to the
StableMastercontract associated to the stablecoin
perpetualManager: Address of the
PerpetualManagercontract corresponding to this keeper contract
Bonus - Malus Fee, means that if the
fee > BASE_PARAMSthen /// agents incur a malus and will have larger fees, while
fee < BASE_PARAMSthey incur a smaller fee than what they would have if fees just consisted in what was obtained using coverage.
xBonusMalusMint, xBonusMalusBurn: Values of the collateral ratio where mint or burn transaction fees will change for users. It should be ranked in ascending order.
yFeeMint, yFeeBurn: Values of the mint or burn fees at the points of collateral ratio in the x array. The evolution of the fees when collateral ratio is between two threshold values is linear
xSlippage: Values of the collateral ratio where the slippage factor for SLPs exiting will evolve
ySlippage: Slippage factor at the values of collateral ratio above
xSlippageFee: Values of the collateral ratio where the slippage fee, that is the portion of the fees that does not come to SLPs although changes
ySlippageFee: Slippage fee value at the values of collateral ratio above
haFeeDeposit, haFeeWithdraw: Extra deposit or withdraw bonus/malus for HAs fees,
BASE_PARAMSmeans that there are no fees
POOLMANAGER_ROLE: this role is admin of all roles here. Although there is no function that requires this role, this role is here as it allows the corresponding
PoolManagerto directly update the roles in this contract without having to define functions in it.
GUARDIAN_ROLE: there is no
GOVERNOR_ROLEin this contract
The following functions are the function that keepers need to call if they want to update the way fees are computed for users, SLPs and HAs. The fees that are computed here are not the real fees that are going to be taken, they are just going to change the total fees previously computed using HA coverage. For instance if with the hedge curve 10% transaction fees should be taken from the user and if with the fees depending on collateral ratio it is said that the output factor is 90%, then users will end up getting 10% * 90% = 9% meaning collateral ratio helped to give a bonus to users by reducing fees.
What's computed here is hence more a correction of the fees.
function updateUsersSLP() external;
Updates the SLP and Users fees associated to the pair stablecoin/collateral in the
StableMastercontract based on the collateral ratio.
This function updates:
bonusMalusMint: part of the fee induced by a user minting depending on the collateral ratio. In normal times, no fees are taken for that, and so this fee should be equal to
bonusMalusBurn: part of the fee induced by a user burning depending on the collateral ratio
slippage: what's given to SLPs compared with their claim when they exit
slippageFee: that is the portion of fees that is put aside because the protocol is not well collateralized
bonusMalusBurnallow governance to add penalties or bonuses for users minting and burning in some situations of collateral ratio. These parameters are multiplied to the fee amount depending on coverage by Hedging Agents to get the exact fee induced to the users.
This function uses its own version of the
_piecewiseLinearfunction defined in
FunctionUtils. The reason for having a different function is that here the values in the
xArraycan be greater than
BASE_PARAMSmeaning that if we used the same version of
FunctionUtils, there would be a non negligeable risk of overflow.
function updateHA() external;
Updates HA fees associated to the pair stablecoin/collateral in the
PerpetualManagercontract. This function updates:
- The part of the fee taken from HAs when they create a perpetual or add collateral in it. This allows governance to add penalties or bonuses in some occasions to HAs opening their perpetuals
- The part of the fee taken from the HA when they withdraw collateral from a perpetual. This allows governance to add penalty or bonuses in some occasions to HAs closing their perpetuals
Penalties or bonuses for HAs should almost never be used. In the
PerpetualManagercontract, these parameters are multiplied to the fee amount depending on the HA coverage to get the exact fee amount for HAs. For the moment, these parameters do not depend on the collateral ratio, and they are just an extra element that governance can play on to correct fees taken for HAs.
function setFees(uint256 xArray, uint64 yArray, uint8 typeChange) external;
Sets the x (ie thresholds of collateral ratio) array / y (ie value of fees at threshold)-array for users minting, burning, for SLPs withdrawal slippage or for the slippage fee when updating the exchange rate between sanTokens and collateral.
xArray: New collateral ratio thresholds (in ascending order)
yArray: New fees or ratio at thresholds
typeChange: Type of parameter to change
typeChange = 1, minting fees are updated. For
typeChange = 2, burning fees are updated. For
typeChange = 3, slippage values are updated. For other values of
typeChange, slippage fee values are updated.
function setHAFees(uint64 _haFeeDeposit, uint64 _haFeeWithdraw) external;
Sets the extra parameters that can be multiplied to the fees when HAs mint and burn
_haFeeDeposit: New deposit fee for HAs
_haFeeWithdraw: New withdraw fee for HAs