Skip to main content

SeniorPool

SeniorPool​

Deployment on Ethereum mainnet:

https://etherscan.io/address/0x8481a6EbAf5c7DABc3F7e09e44A89531fd31F822

Main entry point for senior LPs (a.k.a. capital providers) Automatically invests across borrower pools using an adjustable strategy.

USDC_MANTISSA​

uint256 USDC_MANTISSA

FIDU_MANTISSA​

uint256 FIDU_MANTISSA

ZAPPER_ROLE​

bytes32 ZAPPER_ROLE

config​

contract GoldfinchConfig config

compoundBalance​

uint256 compoundBalance

DEPRECATED!

writedowns​

mapping(contract ITranchedPool => uint256) writedowns

DEPRECATED, DO NOT USE.

writedownsByPoolToken​

mapping(uint256 => uint256) writedownsByPoolToken

Writedowns by PoolToken id. This is used to ensure writedowns are incremental. Example: At t1, a pool is late and should be written down by 10%. At t2, the pool is even later, and should be written down by 25%. This variable helps ensure that if writedowns occur at both t1 and t2, t2's writedown is only by the delta of 15%, rather than double-counting the writedown percent from t1.

_checkpointedEpochId​

uint256 _checkpointedEpochId

_epochs​

mapping(uint256 => struct ISeniorPoolEpochWithdrawals.Epoch) _epochs

_withdrawalRequests​

mapping(uint256 => struct ISeniorPoolEpochWithdrawals.WithdrawalRequest) _withdrawalRequests

_usdcAvailable​

uint256 _usdcAvailable

Tracks usdc available for investments, zaps, withdrawal allocations etc. Due to the time based nature of epochs, if the last epoch has ended but isn't checkpointed yet then this var doesn't reflect the true usdc available at the current timestamp. To query for the up to date usdc available without having to execute a tx, use the usdcAvailable() view fn

_epochDuration​

uint256 _epochDuration

initialize​

function initialize(address owner, contract GoldfinchConfig _config) public

setEpochDuration​

function setEpochDuration(uint256 newEpochDuration) external

Update epoch duration

Triggers a checkpoint

initializeEpochs​

function initializeEpochs() external

Initialize the epoch withdrawal system. This includes writing the initial epoch and snapshotting usdcAvailable at the current usdc balance of the senior pool.

deposit​

function deposit(uint256 amount) public returns (uint256 depositShares)

Deposits amount USDC from msg.sender into the SeniorPool, and grants you the equivalent value of FIDU tokens

Parameters​

NameTypeDescription
amountuint256The amount of USDC to deposit

depositWithPermit​

function depositWithPermit(uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external returns (uint256 depositShares)

Identical to deposit, except it allows for a passed up signature to permit the Senior Pool to move funds on behalf of the user, all within one transaction.

Parameters​

NameTypeDescription
amountuint256The amount of USDC to deposit
deadlineuint256
vuint8secp256k1 signature component
rbytes32secp256k1 signature component
sbytes32secp256k1 signature component

addToWithdrawalRequest​

function addToWithdrawalRequest(uint256 fiduAmount, uint256 tokenId) external

Add fiduAmount FIDU to a withdrawal request for tokenId. Caller must own tokenId

Reverts if a withdrawal with the given tokenId does not exist Reverts if the caller is not the owner of the given token Triggers a checkpoint

requestWithdrawal​

function requestWithdrawal(uint256 fiduAmount) external returns (uint256)

Submit a request to withdraw fiduAmount of FIDU. Request is rejected if caller already owns a request token. A non-transferrable request token is minted to the caller

triggers a checkpoint

Return Values​

NameTypeDescription
[0]uint256

cancelWithdrawalRequest​

function cancelWithdrawalRequest(uint256 tokenId) external returns (uint256)

Cancel request for tokenId. The fiduRequested (minus a fee) is returned to the caller. Caller must own tokenId.

triggers a checkpoint

Return Values​

NameTypeDescription
[0]uint256

claimWithdrawalRequest​

function claimWithdrawalRequest(uint256 tokenId) external returns (uint256)

Transfer the usdcWithdrawable of request for tokenId to the caller. Caller must own tokenId

triggers a checkpoint

epochDuration​

function epochDuration() external view returns (uint256)

Current duration of withdrawal epochs, in seconds

withdrawalRequest​

function withdrawalRequest(uint256 tokenId) external view returns (struct ISeniorPoolEpochWithdrawals.WithdrawalRequest)

Get request by tokenId. A request is considered active if epochCursor > 0.

_previewEpochCheckpoint​

function _previewEpochCheckpoint(struct ISeniorPoolEpochWithdrawals.Epoch epoch) internal view returns (struct ISeniorPoolEpochWithdrawals.Epoch, enum SeniorPool.EpochCheckpointStatus)

Preview the effects of attempting to checkpoint a given epoch. If the epoch doesn't need to be checkpointed then the same epoch will be return along with a bool indicated it didn't need to be checkpointed.

Parameters​

NameTypeDescription
epochstruct ISeniorPoolEpochWithdrawals.Epochepoch to checkpoint

Return Values​

NameTypeDescription
[0]struct ISeniorPoolEpochWithdrawals.EpochmaybeCheckpointedEpoch the checkpointed epoch if the epoch was able to be checkpointed, otherwise the same epoch
[1]enum SeniorPool.EpochCheckpointStatusepochStatus If the epoch can't be finalized, returns Unapplied. If the Epoch is after the end time of the epoch the epoch will be extended. An extended epoch will have its endTime set to the next endtime but won't have any usdc allocated to it. If the epoch can be finalized and its after the end time, it will have usdc allocated to it.

_headEpoch​

function _headEpoch() internal view returns (struct ISeniorPoolEpochWithdrawals.Epoch)

Returns the most recent, uncheckpointed epoch

_previewWithdrawRequestCheckpoint​

function _previewWithdrawRequestCheckpoint(struct ISeniorPoolEpochWithdrawals.WithdrawalRequest wr) internal view returns (struct ISeniorPoolEpochWithdrawals.WithdrawalRequest)

Returns the state of a withdraw request after checkpointing

_mostRecentEndsAtAfter​

function _mostRecentEndsAtAfter(uint256 endsAt) internal view returns (uint256)

Returns the most recent time an epoch would end assuming the current epoch duration and the starting point of endsAt.

Parameters​

NameTypeDescription
endsAtuint256basis for calculating the most recent endsAt time

Return Values​

NameTypeDescription
[0]uint256mostRecentEndsAt The most recent endsAt

_sendToReserve​

function _sendToReserve(uint256 amount, address userForEvent) internal

_applyInitializeNextEpochFrom​

function _applyInitializeNextEpochFrom(struct ISeniorPoolEpochWithdrawals.Epoch previousEpoch) internal returns (struct ISeniorPoolEpochWithdrawals.Epoch)

Initialize the next epoch using a given epoch by carrying forward its oustanding fidu

_initializeNextEpochFrom​

function _initializeNextEpochFrom(struct ISeniorPoolEpochWithdrawals.Epoch previousEpoch) internal view returns (struct ISeniorPoolEpochWithdrawals.Epoch)

_applyEpochCheckpoints​

function _applyEpochCheckpoints() private returns (struct ISeniorPoolEpochWithdrawals.Epoch)

Increment _checkpointedEpochId cursor up to the current epoch

_applyWithdrawalRequestCheckpoint​

function _applyWithdrawalRequestCheckpoint(uint256 tokenId) internal returns (struct ISeniorPoolEpochWithdrawals.WithdrawalRequest)

_applyEpochAndRequestCheckpoints​

function _applyEpochAndRequestCheckpoints(uint256 tokenId) internal returns (struct ISeniorPoolEpochWithdrawals.Epoch, struct ISeniorPoolEpochWithdrawals.WithdrawalRequest)

_applyEpochCheckpoint​

function _applyEpochCheckpoint(struct ISeniorPoolEpochWithdrawals.Epoch epoch) internal returns (struct ISeniorPoolEpochWithdrawals.Epoch)

Checkpoint an epoch, returning the same epoch if it doesn't need to be checkpointed or a newly initialized epoch if the given epoch was successfully checkpointed. In other words, return the most current epoch

_To decrease storage writes we have introduced optimizations based on two observations

 1. If block.timestamp < endsAt, then the epoch is unchanged and we can return
the unmodified epoch (checkpointStatus == Unappled).
2. If the epoch has ended but its fiduRequested is 0 OR the senior pool's usdcAvailable
is 0, then the next epoch will have the SAME fiduRequested, and the only variable we have to update
is endsAt (chekpointStatus == Extended)._

Parameters​

NameTypeDescription
epochstruct ISeniorPoolEpochWithdrawals.Epochepoch to checkpoint

Return Values​

NameTypeDescription
[0]struct ISeniorPoolEpochWithdrawals.EpochcurrentEpoch current epoch

_burnWithdrawRequest​

function _burnWithdrawRequest(uint256 tokenId) internal

withdraw​

function withdraw(uint256 usdcAmount) external returns (uint256 amount)

Withdraws USDC from the SeniorPool to msg.sender, and burns the equivalent value of FIDU tokens

Parameters​

NameTypeDescription
usdcAmountuint256The amount of USDC to withdraw

withdrawInFidu​

function withdrawInFidu(uint256 fiduAmount) external returns (uint256 amount)

Withdraws USDC (denominated in FIDU terms) from the SeniorPool to msg.sender

Parameters​

NameTypeDescription
fiduAmountuint256The amount of USDC to withdraw in terms of FIDU shares

_withdraw​

function _withdraw(uint256 usdcAmount, uint256 withdrawShares) internal returns (uint256 userAmount)

invest​

function invest(contract ITranchedPool pool) external returns (uint256)

Invest in an ITranchedPool's senior tranche using the senior pool's strategy

Parameters​

NameTypeDescription
poolcontract ITranchedPoolAn ITranchedPool whose senior tranche should be considered for investment

redeem​

function redeem(uint256 tokenId) external

Redeem interest and/or principal from an ITranchedPool investment

triggers a checkpoint

Parameters​

NameTypeDescription
tokenIduint256the ID of an IPoolTokens token to be redeemed

writedown​

function writedown(uint256 tokenId) external

Write down an ITranchedPool investment. This will adjust the senior pool's share price down if we're considering the investment a loss, or up if the borrower has subsequently made repayments that restore confidence that the full loan will be repaid.

triggers a checkpoint

Parameters​

NameTypeDescription
tokenIduint256the ID of an IPoolTokens token to be considered for writedown

usdcAvailable​

function usdcAvailable() public view returns (uint256)

Returns the amount of unallocated usdc in the senior pool, taking into account usdc that will be allocated to withdrawals when a checkpoint happens

currentEpoch​

function currentEpoch() external view returns (struct ISeniorPoolEpochWithdrawals.Epoch)

The current withdrawal epoch

assets​

function assets() external view returns (uint256)

Returns the net assests controlled by and owed to the pool

sharesOutstanding​

function sharesOutstanding() external view returns (uint256)

Returns the number of shares outstanding, accounting for shares that will be burned when an epoch checkpoint happens

getNumShares​

function getNumShares(uint256 usdcAmount) public view returns (uint256)

estimateInvestment​

function estimateInvestment(contract ITranchedPool pool) external view returns (uint256)

calculateWritedown​

function calculateWritedown(uint256 tokenId) external view returns (uint256)

Calculates the writedown amount for a particular pool position

Parameters​

NameTypeDescription
tokenIduint256The token reprsenting the position

Return Values​

NameTypeDescription
[0]uint256The amount in dollars the principal should be written down by

_getNumShares​

function _getNumShares(uint256 _usdcAmount, uint256 _sharePrice) internal pure returns (uint256)

_calculateWritedown​

function _calculateWritedown(contract ITranchedPool pool, uint256 principal) internal view returns (uint256 writedownPercent, uint256 writedownAmount)

_distributeLosses​

function _distributeLosses(int256 writedownDelta) internal

_collectInterestAndPrincipal​

function _collectInterestAndPrincipal(address from, uint256 interest, uint256 principal) internal

_isValidPool​

function _isValidPool(contract ITranchedPool pool) internal view returns (bool)

_approvePool​

function _approvePool(contract ITranchedPool pool, uint256 allowance) internal

_usdcToFidu​

function _usdcToFidu(uint256 amount) internal pure returns (uint256)

_fiduToUsdc​

function _fiduToUsdc(uint256 amount) internal pure returns (uint256)

_getUSDCAmountFromShares​

function _getUSDCAmountFromShares(uint256 fiduAmount) internal view returns (uint256)

_getUSDCAmountFromShares​

function _getUSDCAmountFromShares(uint256 _fiduAmount, uint256 _sharePrice) internal pure returns (uint256)

_usdcToSharePrice​

function _usdcToSharePrice(uint256 usdcAmount) internal view returns (uint256)

_totalShares​

function _totalShares() internal view returns (uint256)

_sliceIndexToSeniorTrancheId​

function _sliceIndexToSeniorTrancheId(uint256 index) internal pure returns (uint256)

Returns the senion tranche id for the given slice index

Parameters​

NameTypeDescription
indexuint256slice index

Return Values​

NameTypeDescription
[0]uint256senior tranche id of given slice index

onlyZapper​

modifier onlyZapper()

EpochCheckpointStatus​

enum EpochCheckpointStatus {
Unapplied,
Extended,
Finalized
}