Skip to main content

ConvertibleDepositFacility

Git Source

Inherits: BaseDepositFacility, IConvertibleDepositFacility, IPeriodicTask

Title: Convertible Deposit Facility

forge-lint: disable-start(mixed-case-function, mixed-case-variable)

Implementation of the {IConvertibleDepositFacility} interface It is a general-purpose contract that can be used to create, mint, convert, redeem, and reclaim receipt tokens

State Variables

ROLE_AUCTIONEER

bytes32 public constant ROLE_AUCTIONEER = "cd_auctioneer"

MINTR

The MINTR module.

MINTRv1 public MINTR

_OHM_SCALE

uint256 internal constant _OHM_SCALE = 1e9

Functions

constructor

constructor(address kernel_, address depositManager_) BaseDepositFacility(kernel_, depositManager_);

configureDependencies

Define module dependencies for this policy.

function configureDependencies() external override returns (Keycode[] memory dependencies);

Returns

NameTypeDescription
dependenciesKeycode[]- Keycode array of module dependencies.

requestPermissions

Function called by kernel to set module function permissions.

function requestPermissions() external view override returns (Permissions[] memory permissions);

Returns

NameTypeDescription
permissionsPermissions[]requests - Array of keycodes and function selectors for requested permissions.

VERSION

function VERSION() external pure returns (uint8 major, uint8 minor);

createPosition

Creates a convertible deposit position

This function reverts if:

  • The caller does not have the ROLE_AUCTIONEER role
  • The contract is not enabled
  • The asset and period are not supported
function createPosition(CreatePositionParams calldata params_)
external
onlyRole(ROLE_AUCTIONEER)
nonReentrant
onlyEnabled
returns (uint256 positionId, uint256 receiptTokenId, uint256 actualAmount);

Parameters

NameTypeDescription
params_CreatePositionParamsThe parameters for the position creation

Returns

NameTypeDescription
positionIduint256The ID of the new position
receiptTokenIduint256
actualAmountuint256

deposit

Deposits the given amount of the underlying asset in exchange for a receipt token. This function can be used to mint additional receipt tokens on a 1:1 basis, without creating a new position.

function deposit(IERC20 asset_, uint8 periodMonths_, uint256 amount_, bool wrapReceipt_)
external
nonReentrant
onlyEnabled
returns (uint256 receiptTokenId, uint256 actualAmount);

Parameters

NameTypeDescription
asset_IERC20The address of the asset
periodMonths_uint8The period of the deposit
amount_uint256The amount of asset to deposit
wrapReceipt_boolWhether the receipt token should be wrapped

Returns

NameTypeDescription
receiptTokenIduint256The ID of the receipt token
actualAmountuint256The quantity of receipt tokens minted to the depositor

_previewConvert

Determines the conversion output

function _previewConvert(
address depositor_,
uint256 positionId_,
uint256 amount_,
address previousAsset_,
uint8 previousPeriodMonths_
) internal view returns (uint256 convertedTokenOut, address currentAsset, uint8 currentPeriodMonths);

Parameters

NameTypeDescription
depositor_addressThe depositor of the position
positionId_uint256The ID of the position
amount_uint256The amount of receipt tokens to convert
previousAsset_addressUsed to validate that the asset is the same across positions (zero if the first position)
previousPeriodMonths_uint8Used to validate that the period is the same across positions (0 if the first position)

Returns

NameTypeDescription
convertedTokenOutuint256The amount of converted tokens
currentAssetaddressThe asset of the current position
currentPeriodMonthsuint8The period of the current position

previewConvert

Preview the amount of receipt tokens and OHM that would be converted

This function reverts if:

  • The contract is not enabled
  • The length of the positionIdsarray does not match the length of the amounts array
  • depositor_ is not the owner of all of the positions
  • Any position is not valid
  • Any position is not a supported asset
  • Any position has a different asset or deposit period
  • Any position has reached the conversion expiry
  • Any conversion amount is greater than the remaining deposit
  • The amount of deposits to convert is 0
  • The converted amount is 0
function previewConvert(address depositor_, uint256[] memory positionIds_, uint256[] memory amounts_)
external
view
onlyEnabled
returns (uint256 receiptTokenIn, uint256 convertedTokenOut);

Parameters

NameTypeDescription
depositor_address
positionIds_uint256[]An array of position ids that will be converted
amounts_uint256[]An array of amounts of receipt tokens to convert

Returns

NameTypeDescription
receiptTokenInuint256The total amount of receipt tokens converted
convertedTokenOutuint256The amount of OHM minted during conversion

convert

Converts receipt tokens to OHM before conversion expiry

This function reverts if:

  • The contract is not enabled
  • No positions are provided
  • The length of the positionIdsarray does not match the length of the amounts array
  • The caller is not the owner of all of the positions
  • Any position is not valid
  • Any position is not a supported asset
  • Any position has a different asset or deposit period
  • Any position has reached the conversion expiry
  • Any position has a conversion amount greater than the remaining deposit
  • The amount of deposits to convert is 0
  • The converted amount is 0
function convert(uint256[] memory positionIds_, uint256[] memory amounts_, bool wrappedReceipt_)
external
nonReentrant
onlyEnabled
returns (uint256 receiptTokenIn, uint256 convertedTokenOut);

Parameters

NameTypeDescription
positionIds_uint256[]An array of position ids that will be converted
amounts_uint256[]An array of amounts of receipt tokens to convert
wrappedReceipt_boolWhether the receipt tokens to use are wrapped as ERC20s

Returns

NameTypeDescription
receiptTokenInuint256The total amount of receipt tokens converted
convertedTokenOutuint256The amount of OHM minted during conversion

previewClaimYield

Preview the amount of yield that would be claimed for the given asset

This returns the value from DepositManager.maxClaimYield(), which is a theoretical value.

function previewClaimYield(IERC20 asset_) public view returns (uint256 yieldAssets);

Parameters

NameTypeDescription
asset_IERC20The address of the asset

Returns

NameTypeDescription
yieldAssetsuint256assets The amount of assets that would be claimed

claimYield

Claim the yield accrued for the given asset

function claimYield(IERC20 asset_) public returns (uint256);

Parameters

NameTypeDescription
asset_IERC20The address of the asset

Returns

NameTypeDescription
<none>uint256assets The amount of assets that were claimed

claimYield

Claim the yield accrued for the given asset

This function mainly serves as a backup for claiming protocol yield, in case the max yield cannot be claimed.

function claimYield(IERC20 asset_, uint256 amount_) public returns (uint256);

Parameters

NameTypeDescription
asset_IERC20The address of the asset
amount_uint256The amount to claim

Returns

NameTypeDescription
<none>uint256assets The amount of assets that were claimed

claimAllYield

Claim the yield accrued for all assets and deposit periods

function claimAllYield() external;

convertedToken

The address of the token that is converted to by the facility

function convertedToken() external view returns (address);

execute

Executes the periodic task

This function reverts if:

  • The caller is not authorized Notes:
  • If disabled, nothing is done
  • This will attempt to claim yield for all configured assets
  • If the claimAllYield function fails for any asset, an event will be emitted instead of reverting
function execute() external onlyRole(HEART_ROLE);

supportsInterface

function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(BaseDepositFacility, IPeriodicTask)
returns (bool);