AccountantWithRateProviders

Git Source

Inherits: Auth, IRateProvider

State Variables

accountantState

Store the accountant state in 3 packed slots.

AccountantState public accountantState;

rateProviderData

Maps ERC20s to their RateProviderData.

mapping(ERC20 => RateProviderData) public rateProviderData;

base

The base asset rates are provided in.

ERC20 public immutable base;

decimals

The decimals rates are provided in.

uint8 public immutable decimals;

vault

The BoringVault this accountant is working with. Used to determine share supply for fee calculation.

BoringVault public immutable vault;

ONE_SHARE

One share of the BoringVault.

uint256 internal immutable ONE_SHARE;

Functions

constructor

constructor(
    address _owner,
    address _vault,
    address payoutAddress,
    uint96 startingExchangeRate,
    address _base,
    uint16 allowedExchangeRateChangeUpper,
    uint16 allowedExchangeRateChangeLower,
    uint32 minimumUpdateDelayInSeconds,
    uint16 managementFee
)
    Auth(_owner, Authority(address(0)));

pause

Pause this contract, which prevents future calls to updateExchangeRate, and any safe rate calls will revert.

Callable by MULTISIG_ROLE.

function pause() external requiresAuth;

unpause

Unpause this contract, which allows future calls to updateExchangeRate, and any safe rate calls will stop reverting.

Callable by MULTISIG_ROLE.

function unpause() external requiresAuth;

updateDelay

Update the minimum time delay between updateExchangeRate calls.

There are no input requirements, as it is possible the admin would want the exchange rate updated as frequently as needed.

Callable by OWNER_ROLE.

function updateDelay(uint32 minimumUpdateDelayInSeconds) external requiresAuth;

updateUpper

Update the allowed upper bound change of exchange rate between updateExchangeRateCalls.

Callable by OWNER_ROLE.

function updateUpper(uint16 allowedExchangeRateChangeUpper) external requiresAuth;

updateLower

Update the allowed lower bound change of exchange rate between updateExchangeRateCalls.

Callable by OWNER_ROLE.

function updateLower(uint16 allowedExchangeRateChangeLower) external requiresAuth;

updateManagementFee

Update the management fee to a new value.

Callable by OWNER_ROLE.

function updateManagementFee(uint16 managementFee) external requiresAuth;

updatePayoutAddress

Update the payout address fees are sent to.

Callable by OWNER_ROLE.

function updatePayoutAddress(address payoutAddress) external requiresAuth;

setRateProviderData

Update the rate provider data for a specific asset.

Rate providers must return rates in terms of base or an asset pegged to base and they must use the same decimals as asset.

Callable by OWNER_ROLE.

function setRateProviderData(ERC20 asset, bool isPeggedToBase, address rateProvider) external requiresAuth;

updateExchangeRate

Updates this contract exchangeRate.

If new exchange rate is outside of accepted bounds, or if not enough time has passed, this will pause the contract, and this function will NOT calculate fees owed.

Callable by UPDATE_EXCHANGE_RATE_ROLE.

function updateExchangeRate(uint96 newExchangeRate) external requiresAuth;

claimFees

Claim pending fees.

This function must be called by the BoringVault.

This function will lose precision if the exchange rate decimals is greater than the feeAsset's decimals.

function claimFees(ERC20 feeAsset) external;

getRate

Get this BoringVault's current rate in the base.

function getRate() public view returns (uint256 rate);

getRateSafe

Get this BoringVault's current rate in the base.

Revert if paused.

function getRateSafe() external view returns (uint256 rate);

getRateInQuote

Get this BoringVault's current rate in the provided quote.

quote must have its RateProviderData set, else this will revert.

This function will lose precision if the exchange rate decimals is greater than the quote's decimals.

function getRateInQuote(ERC20 quote) public view returns (uint256 rateInQuote);

getRateInQuoteSafe

Get this BoringVault's current rate in the provided quote.

quote must have its RateProviderData set, else this will revert.

Revert if paused.

function getRateInQuoteSafe(ERC20 quote) external view returns (uint256 rateInQuote);

changeDecimals

Used to change the decimals of precision used for an amount.

function changeDecimals(uint256 amount, uint8 fromDecimals, uint8 toDecimals) internal pure returns (uint256);

Events

Paused

event Paused();

Unpaused

event Unpaused();

DelayInSecondsUpdated

event DelayInSecondsUpdated(uint32 oldDelay, uint32 newDelay);

UpperBoundUpdated

event UpperBoundUpdated(uint16 oldBound, uint16 newBound);

LowerBoundUpdated

event LowerBoundUpdated(uint16 oldBound, uint16 newBound);

ManagementFeeUpdated

event ManagementFeeUpdated(uint16 oldFee, uint16 newFee);

PayoutAddressUpdated

event PayoutAddressUpdated(address oldPayout, address newPayout);

RateProviderUpdated

event RateProviderUpdated(address asset, bool isPegged, address rateProvider);

ExchangeRateUpdated

event ExchangeRateUpdated(uint96 oldRate, uint96 newRate, uint64 currentTime);

FeesClaimed

event FeesClaimed(address indexed feeAsset, uint256 amount);

Errors

AccountantWithRateProviders__UpperBoundTooSmall

error AccountantWithRateProviders__UpperBoundTooSmall();

AccountantWithRateProviders__LowerBoundTooLarge

error AccountantWithRateProviders__LowerBoundTooLarge();

AccountantWithRateProviders__ManagementFeeTooLarge

error AccountantWithRateProviders__ManagementFeeTooLarge();

AccountantWithRateProviders__Paused

error AccountantWithRateProviders__Paused();

AccountantWithRateProviders__ZeroFeesOwed

error AccountantWithRateProviders__ZeroFeesOwed();

AccountantWithRateProviders__OnlyCallableByBoringVault

error AccountantWithRateProviders__OnlyCallableByBoringVault();

AccountantWithRateProviders__UpdateDelayTooLarge

error AccountantWithRateProviders__UpdateDelayTooLarge();

Structs

AccountantState

struct AccountantState {
    address payoutAddress;
    uint128 feesOwedInBase;
    uint128 totalSharesLastUpdate;
    uint96 exchangeRate;
    uint16 allowedExchangeRateChangeUpper;
    uint16 allowedExchangeRateChangeLower;
    uint64 lastUpdateTimestamp;
    bool isPaused;
    uint32 minimumUpdateDelayInSeconds;
    uint16 managementFee;
}

Properties

NameTypeDescription

payoutAddress

address

the address claimFees sends fees to

feesOwedInBase

uint128

total pending fees owed in terms of base

totalSharesLastUpdate

uint128

total amount of shares the last exchange rate update

exchangeRate

uint96

the current exchange rate in terms of base

allowedExchangeRateChangeUpper

uint16

the max allowed change to exchange rate from an update

allowedExchangeRateChangeLower

uint16

the min allowed change to exchange rate from an update

lastUpdateTimestamp

uint64

the block timestamp of the last exchange rate update

isPaused

bool

whether or not this contract is paused

minimumUpdateDelayInSeconds

uint32

the minimum amount of time that must pass between exchange rate updates, such that the update won't trigger the contract to be paused

managementFee

uint16

the management fee

RateProviderData

struct RateProviderData {
    bool isPeggedToBase;
    IRateProvider rateProvider;
}

Properties

NameTypeDescription

isPeggedToBase

bool

whether or not the asset is 1:1 with the base asset

rateProvider

IRateProvider

the rate provider for this asset if isPeggedToBase is false