JumpRateModelV3
Overview
License: MIT
contract JumpRateModelV3 is Initializable, InterestRateModel, AccessControlUpgradeable
V3 interest rate Model.
Structs info
BlendingTokenInfo
struct BlendingTokenInfo {
uint256 gainPerBlock;
uint256 jumGainPerBlock;
uint256 targetUtil;
}
RateInfo
struct RateInfo {
uint256 lastInterestRate;
uint256 lastAccrualBlockNumber;
uint256 maxBorrowRate;
}
Events info
NewInterestParams
event NewInterestParams(uint256 gainPerBlock, uint256 jumGainPerBlock, uint256 targetUtil)
Emitted when the owner of the interest rate model is updated.
Parameters:
gainPerBlock
uint256
The new gainPerBlock.
jumGainPerBlock
uint256
The new jumGainPerBlock.
targetUtil
uint256
The new targetUtil.
NewOwner
event NewOwner(address newOwner)
Emitted when the owner of the contract is updated.
Parameters:
newOwner
address
The address of the new owner.
NewInterest
event NewInterest(uint256 appliedBlock, uint256 interestRate)
Emitted when a new interest rate is set.
Parameters:
appliedBlock
uint256
The block number at which the interest rate was applied.
interestRate
uint256
The new interest rate.
Constants info
MODERATOR_ROLE (0x797669c9)
bytes32 constant MODERATOR_ROLE = keccak256("MODERATOR_ROLE")
State variables info
blocksPerYear (0xa385fb96)
uint256 blocksPerYear
The approximate number of blocks per year that is assumed by the interest rate model.
blendingTokenInfo (0x582d785a)
mapping(address => struct JumpRateModelV3.BlendingTokenInfo) blendingTokenInfo
rateInfo (0x3a86fb41)
mapping(address => struct JumpRateModelV3.RateInfo) rateInfo
isBlendingTokenSupport (0xb7979487)
mapping(address => bool) isBlendingTokenSupport
Modifiers info
onlyBlendingToken
modifier onlyBlendingToken()
Modifier to restrict access to only the blending token contract.
onlyAdmin
modifier onlyAdmin()
Modifier to check if the caller is the default admin role.
onlyModerator
modifier onlyModerator()
Modifier to check if the caller has the moderator role.
Functions info
initialize (0xfe4b84df)
function initialize(uint256 blocksPerYear_) public initializer
Constructs an interest rate model.
Parameters:
blocksPerYear_
uint256
Number of blocks in a year for compounding.
grantModerator (0x6981c7ae)
function grantModerator(address newModerator) public onlyAdmin
Grants the MODERATOR_ROLE
to a new address. The caller must have the ADMIN_ROLE
.
Parameters:
newModerator
address
The address to grant the role to.
revokeModerator (0x36445636)
function revokeModerator(address moderator) public onlyAdmin
Revokes the moderator role from the specified address. The caller must have the admin role.
Parameters:
moderator
address
The address of the moderator to revoke the role from.
updateJumpRateModel (0x10b86276)
function updateJumpRateModel(
uint256 gainPerYear,
uint256 jumGainPerYear,
uint256 targetUtil_,
address blendingToken
) external onlyModerator
Updates the parameters of the interest rate model (only callable by owner, i.e. Timelock). Only the contract moderator can call this function.
Parameters:
gainPerYear
uint256
The rate of increase in interest rate wrt utilization (scaled by 1e18).
jumGainPerYear
uint256
The jumGainPerBlock after hitting a specified utilization point.
targetUtil_
uint256
The utilization point at which the jump multiplier is applied.
setBlockPerYear (0x03700d6b)
function setBlockPerYear(uint256 blocksPerYear_) external onlyModerator
Sets the number of blocks per year for the JumpRateModelV3 contract. Only the contract moderator can call this function.
Parameters:
blocksPerYear_
uint256
The new number of blocks per year.
addBLendingTokenSupport (0xf9828944)
function addBLendingTokenSupport(
address blendingToken,
uint256 gainPerYear,
uint256 jumGainPerYear,
uint256 targetUtil_,
uint256 newMaxBorrow
) external onlyModerator
Adds support for a new blending token to the JumpRateModelV3 contract.
Requirements:
blendingToken
cannot be the zero address.Only the contract moderator can call this function.
Parameters:
blendingToken
address
The address of the blending token to add support for.
gainPerYear
uint256
The gain per year for the blending token.
jumGainPerYear
uint256
The jump gain per year for the blending token.
targetUtil_
uint256
The target utilization rate for the blending token.
newMaxBorrow
uint256
The new maximum borrow rate for the blending token.
removeBLendingTokenSupport (0xff60fb68)
function removeBLendingTokenSupport(address _blending) external onlyModerator
Removes blending token support for the specified blending token address.
Requirements:
_blending
cannot be the zero address._blending
must be a supported blending token.
Parameters:
_blending
address
The address of the blending token to remove support for.
setMaxBorrowRate (0xa8801029)
function setMaxBorrowRate(
address blendingToken,
uint256 newMaxBorrow
) external onlyModerator
Sets the maximum borrow rate for a blending token.
Requirements:
The caller must have the
onlyModerator
modifier.The blending token must be supported by the contract.
Parameters:
blendingToken
address
The address of the blending token.
newMaxBorrow
uint256
The new maximum borrow rate to be set.
updateBlockNumber (0x938c9cf6)
function updateBlockNumber(address blendingToken) public onlyModerator
Updates the block number for a given blending token.
Requirements:
The caller must have the
onlyModerator
modifier.The blending token must be supported.
Parameters:
blendingToken
address
The address of the blending token to update.
utilizationRate (0x6e71e2d8)
function utilizationRate(
uint256 cash,
uint256 borrows,
uint256 reserves
) public pure returns (uint256)
Calculates the utilization rate of the market: borrows / (cash + borrows - reserves)
.
Parameters:
cash
uint256
The amount of cash in the market.
borrows
uint256
The amount of borrows in the market.
reserves
uint256
The amount of reserves in the market (currently unused).
Return values:
[0]
uint256
The utilization rate as a mantissa between [0, 1e18].
getInterestRateChange (0x86959d81)
function getInterestRateChange(
uint256 cash,
uint256 borrows,
uint256 reserves,
address blendingToken
) public view returns (int256)
Calculates the change in the interest rate per block per block.
Parameters:
cash
uint256
The amount of cash in the market.
borrows
uint256
The amount of borrows in the market.
reserves
uint256
The amount of reserves in the market.
Return values:
[0]
int256
The change in the interest rate per block per block as a mantissa (scaled by 1e18).
getBlockNumber (0x42cbb15c)
function getBlockNumber() public view returns (uint256)
Function to simply retrieve block number. This exists mainly for inheriting test contracts to stub this result.
storeBorrowRate (0x5eeaafea)
function storeBorrowRate(
uint256 cash,
uint256 borrows,
uint256 reserves
) public override onlyBlendingToken returns (uint256)
Calculates and stores the current borrow interest rate per block for the specified blending token.
Parameters:
cash
uint256
The total amount of cash the market has.
borrows
uint256
The total amount of borrows the market has outstanding.
reserves
uint256
The total amount of reserves the market has.
Return values:
[0]
uint256
The calculated borrow rate per block, represented as a percentage and scaled by 1e18.
getSupplyRate (0x32dc9b1c)
function getSupplyRate(
uint256 cash,
uint256 borrows,
uint256 reserves,
uint256 reserveFactorMantissa,
address blendingToken
) public view override returns (uint256)
Calculates the current supply rate per block.
Parameters:
cash
uint256
The amount of cash in the market.
borrows
uint256
The amount of borrows in the market.
reserves
uint256
The amount of reserves in the market.
reserveFactorMantissa
uint256
The current reserve factor for the market.
Return values:
[0]
uint256
The supply rate percentage per block as a mantissa (scaled by 1e18).
getBorrowRate (0x89469df9)
function getBorrowRate(
uint256 cash,
uint256 borrows,
uint256 reserves,
address blendingToken
) external view override returns (uint256)
Calculates the current borrow rate per block.
Parameters:
cash
uint256
The amount of cash in the market.
borrows
uint256
The amount of borrows in the market.
reserves
uint256
The amount of reserves in the market.
Return values:
[0]
uint256
The borrow rate percentage per block as a mantissa (scaled by 1e18).
Last updated