Skip to main content

BaseDepositFacility

Git Source

Inherits: Policy, PolicyEnabler, IDepositFacility, ReentrancyGuard

Title: Base Deposit Facility

Abstract base contract for deposit facilities with shared functionality

Constants​

ONE_HUNDRED_PERCENT​

The number representing 100%

uint16 public constant ONE_HUNDRED_PERCENT = 100e2;

DEPOSIT_MANAGER​

The deposit manager

IDepositManager public immutable DEPOSIT_MANAGER;

State Variables​

_authorizedOperators​

Set of authorized operators

EnumerableSet.AddressSet private _authorizedOperators;

_assetCommittedDeposits​

The amount of assets committed, excluding the assets that have been lent out

mapping(IERC20 asset => uint256 committedDeposits) private _assetCommittedDeposits;

_assetOperatorCommittedDeposits​

The amount of assets committed per operator, excluding the assets that have been lent out

mapping(bytes32 assetOperatorKey => uint256 committedDeposits)
private _assetOperatorCommittedDeposits;

TRSRY​

The TRSRY module

Must be populated by the inheriting contract in configureDependencies()

TRSRYv1 public TRSRY;

DEPOS​

The DEPOS module.

Must be populated by the inheriting contract in configureDependencies()

DEPOSv1 public DEPOS;

_assetPeriodReclaimRates​

Maps asset-period key to reclaim rate

The key is the keccak256 of the asset address and the deposit period

mapping(bytes32 key => uint16 reclaimRate) private _assetPeriodReclaimRates;

Functions​

_onlyAuthorizedOperator​

function _onlyAuthorizedOperator() internal view;

onlyAuthorizedOperator​

Reverts if the caller is not an authorized operator

modifier onlyAuthorizedOperator();

constructor​

constructor(address kernel_, address depositManager_) Policy(Kernel(kernel_));

Parameters

NameTypeDescription
kernel_address
depositManager_address

authorizeOperator​

Authorize an operator (e.g., a redemption vault) to handle actions through this facility

function authorizeOperator(address operator_) external onlyEnabled onlyAdminRole;

Parameters

NameTypeDescription
operator_addressThe address of the operator to authorize

deauthorizeOperator​

Deauthorize an operator

function deauthorizeOperator(address operator_) external onlyEnabled onlyEmergencyOrAdminRole;

Parameters

NameTypeDescription
operator_addressThe address of the operator to deauthorize

isAuthorizedOperator​

Check if an operator is authorized

function isAuthorizedOperator(address operator_) external view returns (bool);

Parameters

NameTypeDescription
operator_addressThe address of the operator to check

Returns

NameTypeDescription
<none>boolTrue if the operator is authorized

getOperators​

Get the list of operators authorized to handle actions through this facility

function getOperators() external view returns (address[] memory operators);

Returns

NameTypeDescription
operatorsaddress[]The list of operators

_getCommittedDepositsKey​

function _getCommittedDepositsKey(
IERC20 depositToken_,
address operator_
) internal pure returns (bytes32);

Parameters

NameTypeDescription
depositToken_IERC20
operator_address

Returns

NameTypeDescription
<none>bytes32

_getAssetPeriodKey​

Helper function to generate the key for asset period reclaim rates

function _getAssetPeriodKey(
IERC20 asset_,
uint8 depositPeriod_
) internal pure returns (bytes32);

Parameters

NameTypeDescription
asset_IERC20The asset address
depositPeriod_uint8The deposit period in months

Returns

NameTypeDescription
<none>bytes32The keccak256 hash of the asset and deposit period

handleCommit​

Allows an operator to commit funds. This will ensure that enough funds are available to honour the commitments.

This function will revert if:

  • This contract is not enabled
  • The caller is not an authorized operator
  • The deposit token or period are not supported for this facility in the DepositManager
  • There are not enough available deposits in the DepositManager
function handleCommit(
IERC20 depositToken_,
uint8 depositPeriod_,
uint256 amount_
) external nonReentrant onlyEnabled onlyAuthorizedOperator;

Parameters

NameTypeDescription
depositToken_IERC20The deposit token committed
depositPeriod_uint8The deposit period in months
amount_uint256The amount to commit

handleCommitCancel​

Allows an operator to cancel committed funds.

This function will revert if:

  • This contract is not enabled
  • The caller is not an authorized operator
  • The amount is greater than the committed deposits for the operator
function handleCommitCancel(
IERC20 depositToken_,
uint8,
uint256 amount_
) external nonReentrant onlyEnabled onlyAuthorizedOperator;

Parameters

NameTypeDescription
depositToken_IERC20The deposit token committed
_uint8The deposit period in months
amount_uint256The amount to reduce the commitment by

handleCommitWithdraw​

Allows an operator to withdraw committed funds. This will withdraw deposit tokens to the recipient.

This function will revert if:

  • This contract is not enabled
  • The caller is not an authorized operator
  • The amount is greater than the committed deposits for the operator
function handleCommitWithdraw(
IERC20 depositToken_,
uint8 depositPeriod_,
uint256 amount_,
address recipient_
) external nonReentrant onlyEnabled onlyAuthorizedOperator returns (uint256);

Parameters

NameTypeDescription
depositToken_IERC20The deposit token to withdraw
depositPeriod_uint8The deposit period in months
amount_uint256The amount to withdraw
recipient_addressThe address to receive the deposit tokens

Returns

NameTypeDescription
<none>uint256The amount of tokens transferred

handleBorrow​

Allows an operator to borrow against this facility's committed funds.

This function will revert if:

  • This contract is not enabled
  • The caller is not an authorized operator
  • The amount is greater than the committed deposits for the operator
  • The amount withdrawn from the vault would be zero
function handleBorrow(
IERC20 depositToken_,
uint8,
uint256 amount_,
address recipient_
) external nonReentrant onlyEnabled onlyAuthorizedOperator returns (uint256);

Parameters

NameTypeDescription
depositToken_IERC20The deposit token to borrow against
_uint8The deposit period in months
amount_uint256The amount to borrow
recipient_addressThe address to receive the borrowed tokens

Returns

NameTypeDescription
<none>uint256The amount of tokens borrowed

handleLoanRepay​

This function performs the following:

  • Updates the committed deposits

Notes:

  • This function is only callable by authorized operators
  • This function does not check for over-payment. It is expected to be handled by the calling contract.

This function will revert if:

  • This contract is not enabled
  • The caller is not an authorized operator
function handleLoanRepay(
IERC20 depositToken_,
uint8,
uint256 amount_,
uint256 maxAmount_,
address payer_
) external nonReentrant onlyEnabled onlyAuthorizedOperator returns (uint256);

Parameters

NameTypeDescription
depositToken_IERC20The deposit token being repaid
_uint8The deposit period in months
amount_uint256The amount of principal being repaid
maxAmount_uint256The maximum amount of principal that can be repaid
payer_addressThe address making the repayment

Returns

NameTypeDescription
<none>uint256The amount of tokens repaid

handleLoanDefault​

Allows an operator to default on a loan

This function will revert if:

  • This contract is not enabled
  • The caller is not an authorized operator
function handleLoanDefault(
IERC20 depositToken_,
uint8 depositPeriod_,
uint256 amount_,
address payer_
) external nonReentrant onlyEnabled onlyAuthorizedOperator;

Parameters

NameTypeDescription
depositToken_IERC20The deposit token being defaulted
depositPeriod_uint8The deposit period in months
amount_uint256The amount being defaulted
payer_addressThe address making the default

handlePositionRedemption​

Allows an operator to handle position-based redemptions by updating the position's remainingDeposit

function handlePositionRedemption(
uint256 positionId_,
uint256 amount_
) external nonReentrant onlyEnabled onlyAuthorizedOperator;

Parameters

NameTypeDescription
positionId_uint256The position ID to update
amount_uint256The amount being redeemed from the position

handlePositionCancelRedemption​

Allows an operator to handle the cancellation of position-based redemptions by updating the position's remainingDeposit

function handlePositionCancelRedemption(
uint256 positionId_,
uint256 amount_
) external nonReentrant onlyEnabled onlyAuthorizedOperator;

Parameters

NameTypeDescription
positionId_uint256The position ID to update
amount_uint256The redemption amount to be cancelled

getAvailableDeposits​

Get the available deposit balance for a specific token. This excludes any committed funds.

function getAvailableDeposits(IERC20 depositToken_) public view returns (uint256);

Parameters

NameTypeDescription
depositToken_IERC20The deposit token to query

Returns

NameTypeDescription
<none>uint256The available deposit balance

getCommittedDeposits​

Get the committed deposits for a specific token and operator. The committed deposits value represents the amount of the deposit token that this contract ensures will be available for the specific operator to use.

The amount is calculated as:

  • The amount of deposits that have been committed (via handleCommit()) for the deposit token and operator
  • Minus: the amount of loan principal currently outstanding for the operator
function getCommittedDeposits(
IERC20 depositToken_,
address operator_
) public view returns (uint256);

Parameters

NameTypeDescription
depositToken_IERC20The deposit token to query
operator_addressThe operator

Returns

NameTypeDescription
<none>uint256The committed deposits for the operator

getCommittedDeposits​

Get the committed deposits for a specific token. The committed deposits value represents the amount of the deposit token that this contract ensures will be available for all operators to use.

The amount returned is calculated as:

  • The amount of deposits that have been committed (via handleCommit()) for the deposit token
  • Minus: the amount of loan principal currently outstanding
function getCommittedDeposits(IERC20 depositToken_) public view returns (uint256);

Parameters

NameTypeDescription
depositToken_IERC20The deposit token to query

Returns

NameTypeDescription
<none>uint256The total committed deposits

_validateAvailableDeposits​

function _validateAvailableDeposits(IERC20 depositToken_, uint256 amount_) internal view;

Parameters

NameTypeDescription
depositToken_IERC20
amount_uint256

_previewReclaim​

function _previewReclaim(
IERC20 depositToken_,
uint8 depositPeriod_,
uint256 amount_
) internal view returns (uint256 reclaimed);

Parameters

NameTypeDescription
depositToken_IERC20
depositPeriod_uint8
amount_uint256

Returns

NameTypeDescription
reclaimeduint256

previewReclaim​

Preview the amount of deposit token that would be reclaimed

The implementing contract is expected to handle the following:

  • Returning the total amount of deposit tokens that would be reclaimed
function previewReclaim(
IERC20 depositToken_,
uint8 depositPeriod_,
uint256 amount_
) public view onlyEnabled returns (uint256 reclaimed);

Parameters

NameTypeDescription
depositToken_IERC20The address of the deposit token
depositPeriod_uint8The period of the deposit in months
amount_uint256The amount of deposit tokens to reclaim

Returns

NameTypeDescription
reclaimeduint256The amount of deposit token returned to the caller

reclaim​

Reclaims deposit tokens, after applying a discount Deposit tokens can be reclaimed at any time. The caller is not required to have a position in the facility.

This function reverts if:

  • The contract is not active
  • Deposits are not enabled for the asset/period
  • The depositor has not approved the DepositManager to spend the receipt token
  • The depositor has an insufficient balance of the receipt token
function reclaim(
IERC20 depositToken_,
uint8 depositPeriod_,
uint256 amount_
) external nonReentrant onlyEnabled returns (uint256 reclaimed);

Parameters

NameTypeDescription
depositToken_IERC20The address of the deposit token
depositPeriod_uint8The period of the deposit in months
amount_uint256The amount of deposit tokens to reclaim

Returns

NameTypeDescription
reclaimeduint256The amount of deposit token returned to the caller

split​

Splits the specified amount of the position into a new position

This function reverts if:

  • The position does not exist
  • The position was not created by this facility
  • The caller is not the owner of the position
function split(
uint256 positionId_,
uint256 amount_,
address to_,
bool wrap_
) external nonReentrant onlyEnabled returns (uint256);

Parameters

NameTypeDescription
positionId_uint256The ID of the position to split
amount_uint256The amount to split from the position
to_addressThe address to receive the new position
wrap_boolWhether to wrap the new position

Returns

NameTypeDescription
<none>uint256The ID of the newly created position

_split​

Internal function to handle the splitting of a position

Inheriting contracts can implement this function to perform custom actions when a position is split. This function is called before the position is split in the underlying DEPOS module.

function _split(uint256 oldPositionId_, uint256 amount_) internal virtual;

Parameters

NameTypeDescription
oldPositionId_uint256
amount_uint256

setAssetPeriodReclaimRate​

Sets the reclaim rate for an asset period

This function reverts if:

  • The contract is not enabled
  • The caller does not have the manager or admin role
  • The reclaim rate exceeds 100%
function setAssetPeriodReclaimRate(
IERC20 asset_,
uint8 depositPeriod_,
uint16 reclaimRate_
) external onlyEnabled onlyManagerOrAdminRole;

Parameters

NameTypeDescription
asset_IERC20The address of the underlying asset
depositPeriod_uint8The deposit period, in months
reclaimRate_uint16The reclaim rate to set (in basis points, where 100e2 = 100%)

getAssetPeriodReclaimRate​

Returns the reclaim rate for an asset period

function getAssetPeriodReclaimRate(
IERC20 asset_,
uint8 depositPeriod_
) external view returns (uint16 reclaimRate);

Parameters

NameTypeDescription
asset_IERC20The address of the underlying asset
depositPeriod_uint8The deposit period, in months

Returns

NameTypeDescription
reclaimRateuint16The reclaim rate for the asset period

supportsInterface​

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

Parameters

NameTypeDescription
interfaceIdbytes4

Returns

NameTypeDescription
<none>bool