Developers
Search…
πŸš™
FunctionUtils - Utils Across the Module
Modifiers and functions used in multiple places in the code

1. Introduction

The FunctionUtils contract is an abstract contract that can is used across many other contracts of the protocol through inheritance. It contains utility functions, constants and modifiers.

2. Contract Details

Interfaces

No interface, this contract is used through inheritance.

Parameters

  • BASE_TOKENS: Base used for floating numbers across all contracts of the protocol that import FunctionUtils. It is equal to 10^18
  • BASE_PARAMS: Base that is used to define parameters that need to have a floating value (for instance parameters that are defined as ratios). It is equal to 10^9

3. Key Mechanisms & Concepts

Utility Function

_piecewiseLinear

1
function _piecewiseLinear(
2
uint64 x,
3
uint64[] memory xArray,
4
uint64[] memory yArray
5
) internal pure returns (uint64 y);
Copied!
Computes the value of a linear by part function at a given point following a set of breaking points and of values at these breaking points. The evolution of the linear by part function between two breaking points is linear. Before the first breaking point and after the last one, the function is constant with a value equal to the first or last value of the yArray.
Parameters:
  • x: Point of the function we want to compute
  • xArray: List of breaking points (in ascending order) that define the linear by part function
  • yArray: List of values at breaking points (not necessarily in ascending order)

Modifiers

onlyCompatibleInputArrays

1
modifier onlyCompatibleInputArrays(
2
uint64[] memory xArray,
3
uint64[] memory yArray
4
);
Copied!
Checks if the input arrays given by governance to update the fee structure of a parameter is valid. This function is a way to avoid some governance attacks or errors where governance passes parameters that are going to cause errors at the level of the protocol. The modifier checks if the arrays have a non null length, if their length if the same, if the values in the xArray are in ascending order, and if the values in the xArray and in the yArray are not superior to BASE_PARAMS
Parameters:
  • xArray: List of breaking points (in ascending order) that define the linear by part function
  • yArray: List of values at breaking points (not necessarily in ascending order)

onlyCompatibleFees

1
modifier onlyCompatibleFees(uint64 fees);
Copied!
Checks if the new value given for a fee parameter is consistent: in Angle's protocol, in most cases, fees should be inferior to BASE_PARAMS.
Parameters:
  • fees: Value of the new parameter to check

zeroCheck

1
modifier zeroCheck(address newAddress);
Copied!
Checks if an address given is not null: it is a way to avoid some errors and attacks when passing address parameters
Parameters:
  • newAddress: Address to check