Skip to main content

FundingRateApplier

FundingRateApplier#

Provides funding rate payment functionality for the Perpetual contract.

Functions#

constructor(bytes32 _fundingRateIdentifier, address _collateralAddress, address _finderAddress, address _configStoreAddress, struct FixedPoint.Unsigned _tokenScaling, address _timerAddress) (internal)

Constructs the FundingRateApplier contract. Called by child contracts.

Parameters:#

  • _fundingRateIdentifier: identifier that tracks the funding rate of this contract.
  • _collateralAddress: address of the collateral token.
  • _finderAddress: Finder used to discover financial-product-related contracts.
  • _configStoreAddress: address of the remote configuration store managed by an external owner.
  • _tokenScaling: initial scaling to apply to the token value (i.e. scales the tracking index).
  • _timerAddress: address of the timer contract in test envs, otherwise 0x0.
applyFundingRate() (public)

This method takes 3 distinct actions:

  1. Pays out regular fees.
  2. If possible, resolves the outstanding funding rate proposal, pulling the result in and paying out the rewards.
  3. Applies the prevailing funding rate over the most recent period.
proposeFundingRate(struct FixedPoint.Signed rate, uint256 timestamp) โ†’ struct FixedPoint.Unsigned totalBond (external)

Proposes a new funding rate. Proposer receives a reward if correct.

Parameters:#

  • rate: funding rate being proposed.
  • timestamp: time at which the funding rate was computed.
_getFundingRateAppliedTokenDebt(struct FixedPoint.Unsigned rawTokenDebt) โ†’ struct FixedPoint.Unsigned tokenDebt (internal)
_getOptimisticOracle() โ†’ contract OptimisticOracleInterface (internal)
_getConfig() โ†’ struct ConfigStoreInterface.ConfigSettings (internal)
_updateFundingRate() (internal)
_validateFundingRate(struct FixedPoint.Signed rate) (internal)
_applyEffectiveFundingRate() (internal)
_calculateEffectiveFundingRate(uint256 paymentPeriodSeconds, struct FixedPoint.Signed fundingRatePerSecond, struct FixedPoint.Unsigned currentCumulativeFundingRateMultiplier) โ†’ struct FixedPoint.Unsigned newCumulativeFundingRateMultiplier (internal)
_getAncillaryData() โ†’ bytes (internal)

We do not need to check that the ancillary data length is less than the hardcoded max length in the OptimisticOracle because the length of the ancillary data is fixed in this function.

_getTokenAddress() โ†’ address (internal)
payRegularFees() โ†’ struct FixedPoint.Unsigned (public)

Pays UMA DVM regular fees (as a % of the collateral pool) to the Store contract.

These must be paid periodically for the life of the contract. If the contract has not paid its regular fee in a week or more then a late penalty is applied which is sent to the caller. If the amount of fees owed are greater than the pfc, then this will pay as much as possible from the available collateral. An event is only fired if the fees charged are greater than 0.

getOutstandingRegularFees(uint256 time) โ†’ struct FixedPoint.Unsigned regularFee, struct FixedPoint.Unsigned latePenalty, struct FixedPoint.Unsigned totalPaid (public)

Fetch any regular fees that the contract has pending but has not yet paid. If the fees to be paid are more than the total collateral within the contract then the totalPaid returned is full contract collateral amount.

This returns 0 and exit early if there is no pfc, fees were already paid during the current block, or the fee rate is 0.

pfc() โ†’ struct FixedPoint.Unsigned (external)

Gets the current profit from corruption for this contract in terms of the collateral currency.

This is equivalent to the collateral pool available from which to pay fees. Therefore, derived contracts are expected to implement this so that pay-fee methods can correctly compute the owed fees as a % of PfC.

gulp() (external)

Removes excess collateral balance not counted in the PfC by distributing it out pro-rata to all sponsors.

Multiplying the cumulativeFeeMultiplier by the ratio of non-PfC-collateral :: PfC-collateral effectively pays all sponsors a pro-rata portion of the excess collateral. This will revert if PfC is 0 and this contract's collateral balance > 0.

_payFinalFees(address payer, struct FixedPoint.Unsigned amount) (internal)
_gulp() (internal)
_pfc() โ†’ struct FixedPoint.Unsigned (internal)
_getStore() โ†’ contract StoreInterface (internal)
_computeFinalFees() โ†’ struct FixedPoint.Unsigned finalFees (internal)
_getFeeAdjustedCollateral(struct FixedPoint.Unsigned rawCollateral) โ†’ struct FixedPoint.Unsigned collateral (internal)
_getPendingRegularFeeAdjustedCollateral(struct FixedPoint.Unsigned rawCollateral) โ†’ struct FixedPoint.Unsigned (internal)
_convertToRawCollateral(struct FixedPoint.Unsigned collateral) โ†’ struct FixedPoint.Unsigned rawCollateral (internal)
_removeCollateral(struct FixedPoint.Unsigned rawCollateral, struct FixedPoint.Unsigned collateralToRemove) โ†’ struct FixedPoint.Unsigned removedCollateral (internal)
_addCollateral(struct FixedPoint.Unsigned rawCollateral, struct FixedPoint.Unsigned collateralToAdd) โ†’ struct FixedPoint.Unsigned addedCollateral (internal)
_adjustCumulativeFeeMultiplier(struct FixedPoint.Unsigned amount, struct FixedPoint.Unsigned currentPfc) (internal)
_preEntranceCheck() (internal)
_preEntranceSet() (internal)
_postEntranceReset() (internal)
setCurrentTime(uint256 time) (external)

Sets the current time.

Will revert if not running in test mode.

Parameters:#

  • time: timestamp to set current Testable time to.
getCurrentTime() โ†’ uint256 (public)

Gets the current time. Will return the last time set in setCurrentTime if running in test mode. Otherwise, it will return the block timestamp.

emergencyShutdown() (external)

Initiates the shutdown process, in case of an emergency.

remargin() (external)

A core contract method called independently or as a part of other financial contract transactions.

It pays fees and moves money between margin accounts to make sure they reflect the NAV of the contract.

_notEmergencyShutdown() (internal)
_isEmergencyShutdown() (internal)

Events#

FundingRateUpdated(int256 newFundingRate, uint256 updateTime, uint256 reward)
RegularFeesPaid(uint256 regularFee, uint256 lateFee)
FinalFeesPaid(uint256 amount)

Modifiers#

fees()
paysRegularFees()
nonReentrant()

Prevents a contract from calling itself, directly or indirectly. Calling a nonReentrant function from another nonReentrant function is not supported. It is possible to prevent this from happening by making the nonReentrant function external, and making it call a private function that does the actual state modification.

nonReentrantView()

Designed to prevent a view-only method from being re-entered during a call to a nonReentrant() state-changing method.

onlyIfTest()

Reverts if not running in test mode.

notEmergencyShutdown()
isEmergencyShutdown()