Skip to main content

BackerRewards

BackerRewards

Deployment on Ethereum mainnet:

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

config

contract GoldfinchConfig config

GFI_MANTISSA

uint256 GFI_MANTISSA

FIDU_MANTISSA

uint256 FIDU_MANTISSA

USDC_MANTISSA

uint256 USDC_MANTISSA

NUM_TRANCHES_PER_SLICE

uint256 NUM_TRANCHES_PER_SLICE

BackerRewardsInfo

struct BackerRewardsInfo {
uint256 accRewardsPerPrincipalDollar;
}

BackerRewardsTokenInfo

struct BackerRewardsTokenInfo {
uint256 rewardsClaimed;
uint256 accRewardsPerPrincipalDollarAtMint;
}

StakingRewardsPoolInfo

struct StakingRewardsPoolInfo {
uint256 accumulatedRewardsPerTokenAtLastCheckpoint;
uint256 lastUpdateTime;
struct BackerRewards.StakingRewardsSliceInfo[] slicesInfo;
}

StakingRewardsSliceInfo

struct StakingRewardsSliceInfo {
uint256 fiduSharePriceAtDrawdown;
uint256 principalDeployedAtLastCheckpoint;
uint256 accumulatedRewardsPerTokenAtDrawdown;
uint256 accumulatedRewardsPerTokenAtLastCheckpoint;
uint256 unrealizedAccumulatedRewardsPerTokenAtLastCheckpoint;
}

StakingRewardsTokenInfo

struct StakingRewardsTokenInfo {
uint256 accumulatedRewardsPerTokenAtLastWithdraw;
}

totalRewards

uint256 totalRewards

total amount of GFI rewards available, times 1e18

maxInterestDollarsEligible

uint256 maxInterestDollarsEligible

interest $ eligible for gfi rewards, times 1e18

totalInterestReceived

uint256 totalInterestReceived

counter of total interest repayments, times 1e6

totalRewardPercentOfTotalGFI

uint256 totalRewardPercentOfTotalGFI

totalRewards/totalGFISupply * 100, times 1e18

tokens

mapping(uint256 => struct BackerRewards.BackerRewardsTokenInfo) tokens

poolTokenId -> BackerRewardsTokenInfo

pools

mapping(address => struct BackerRewards.BackerRewardsInfo) pools

pool.address -> BackerRewardsInfo

poolStakingRewards

mapping(contract ITranchedPool => struct BackerRewards.StakingRewardsPoolInfo) poolStakingRewards

Staking rewards info for each pool

tokenStakingRewards

mapping(uint256 => struct BackerRewards.StakingRewardsTokenInfo) tokenStakingRewards

Staking rewards info for each pool token

initialize

function __initialize__(address owner, contract GoldfinchConfig _config) public

forceInitializeStakingRewardsPoolInfo

function forceInitializeStakingRewardsPoolInfo(contract ITranchedPool pool, uint256 fiduSharePriceAtDrawdown, uint256 principalDeployedAtDrawdown, uint256 rewardsAccumulatorAtDrawdown) external

intialize the first slice of a StakingRewardsPoolInfo

this is _only meant to be called on pools that didnt qualify for the backer rewards airdrop but were deployed before this contract._

allocateRewards

function allocateRewards(uint256 _interestPaymentAmount) external

Calculates the accRewardsPerPrincipalDollar for a given pool, when a interest payment is received by the protocol

NameTypeDescription
_interestPaymentAmountuint256The amount of total dollars the interest payment, expects 10^6 value

setTotalRewards

function setTotalRewards(uint256 _totalRewards) public

Set the total gfi rewards and the % of total GFI

NameTypeDescription
_totalRewardsuint256The amount of GFI rewards available, expects 10^18 value

setTotalInterestReceived

function setTotalInterestReceived(uint256 _totalInterestReceived) public

Set the total interest received to date. This should only be called once on contract deploy.

NameTypeDescription
_totalInterestReceiveduint256The amount of interest the protocol has received to date, expects 10^6 value

setMaxInterestDollarsEligible

function setMaxInterestDollarsEligible(uint256 _maxInterestDollarsEligible) public

Set the max dollars across the entire protocol that are eligible for GFI rewards

NameTypeDescription
_maxInterestDollarsEligibleuint256The amount of interest dollars eligible for GFI rewards, expects 10^18 value

setPoolTokenAccRewardsPerPrincipalDollarAtMint

function setPoolTokenAccRewardsPerPrincipalDollarAtMint(address poolAddress, uint256 tokenId) external

When a pool token is minted for multiple drawdowns, set accRewardsPerPrincipalDollarAtMint to the current accRewardsPerPrincipalDollar price

NameTypeDescription
poolAddressaddress
tokenIduint256Pool token id

onTranchedPoolDrawdown

function onTranchedPoolDrawdown(uint256 sliceIndex) external

callback for TranchedPools when they drawdown

initializes rewards info for the calling TranchedPool

poolTokenClaimableRewards

function poolTokenClaimableRewards(uint256 tokenId) public view returns (uint256)

Calculate the gross available gfi rewards for a PoolToken

NameTypeDescription
tokenIduint256Pool token id
NameTypeDescription
[0]uint256The amount of GFI claimable

stakingRewardsClaimed

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

Calculates the amount of staking rewards already claimed for a PoolToken. This function is provided for the sake of external (e.g. frontend client) consumption; it is not necessary as an input to the mutative calculations in this contract.

NameTypeDescription
tokenIduint256Pool token id
NameTypeDescription
[0]uint256The amount of GFI claimed

withdrawMultiple

function withdrawMultiple(uint256[] tokenIds) public

PoolToken request to withdraw multiple PoolTokens allocated rewards

NameTypeDescription
tokenIdsuint256[]Array of pool token id

withdraw

function withdraw(uint256 tokenId) public

PoolToken request to withdraw all allocated rewards

NameTypeDescription
tokenIduint256Pool token id

stakingRewardsEarnedSinceLastWithdraw

function stakingRewardsEarnedSinceLastWithdraw(uint256 tokenId) public view returns (uint256)

Returns the amount of staking rewards earned by a given token since the last time its staking rewards were withdrawn.

NameTypeDescription
tokenIduint256token id to get rewards
NameTypeDescription
[0]uint256amount of rewards

_allocateRewards

function _allocateRewards(uint256 _interestPaymentAmount) internal

_allocateStakingRewards

function _allocateStakingRewards() internal

_checkpointPoolStakingRewards

function _checkpointPoolStakingRewards(contract ITranchedPool pool, bool publish) internal

Checkpoints staking reward accounting for a given pool.

NameTypeDescription
poolcontract ITranchedPoolpool to checkpoint
publishboolif true, the updated rewards values will be immediately available for backers to withdraw. otherwise, the accounting will be updated but backers will not be able to withdraw

_checkpointSliceStakingRewards

function _checkpointSliceStakingRewards(contract ITranchedPool pool, uint256 sliceIndex, bool publish) internal

checkpoint the staking rewards accounting for a single tranched pool slice

NameTypeDescription
poolcontract ITranchedPoolpool that the slice belongs to
sliceIndexuint256index of slice to checkpoint rewards accounting for
publishboolif true, the updated rewards values will be immediately available for backers to withdraw. otherwise, the accounting will be updated but backers will not be able to withdraw

_checkpointTokenStakingRewards

function _checkpointTokenStakingRewards(uint256 tokenId) internal

Updates the staking rewards accounting for for a given tokenId

NameTypeDescription
tokenIduint256token id to checkpoint

_calculateNewGrossGFIRewardsForInterestAmount

function _calculateNewGrossGFIRewardsForInterestAmount(uint256 _interestPaymentAmount) internal view returns (uint256)

Calculate the rewards earned for a given interest payment

NameTypeDescription
_interestPaymentAmountuint256interest payment amount times 1e6

_isSeniorTrancheToken

function _isSeniorTrancheToken(struct IPoolTokens.TokenInfo tokenInfo) internal pure returns (bool)
NameTypeDescription
[0]boolWhether the provided `tokenInfo` is a token corresponding to a senior tranche.

_usdcToAtomic

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

Returns an amount with the base of usdc (1e6) as an 1e18 number

_atomicToUsdc

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

Returns an amount with the base 1e18 as a usdc amount (1e6)

_fiduToUsdc

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

Returns the equivalent amount of USDC given an amount of fidu and a share price

NameTypeDescription
amountuint256amount of FIDU
sharePriceuint256share price of FIDU
NameTypeDescription
[0]uint256equivalent amount of USDC

_sliceIndexToJuniorTrancheId

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

Returns the junior tranche id for the given slice index

NameTypeDescription
indexuint256slice index
NameTypeDescription
[0]uint256junior tranche id of given slice index

_juniorTrancheIdToSliceIndex

function _juniorTrancheIdToSliceIndex(uint256 trancheId) internal pure returns (uint256)

Returns the slice index for the given junior tranche id

NameTypeDescription
trancheIduint256tranche id
NameTypeDescription
[0]uint256slice index that the given tranche id belongs to

_getUpdatedStakingRewards

function _getUpdatedStakingRewards() internal returns (contract IStakingRewards)

get the StakingRewards contract after checkpoint the rewards values

NameTypeDescription
[0]contract IStakingRewardsStakingRewards with updated rewards values

_poolRewardsHaveBeenInitialized

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

Returns true if a TranchedPool's rewards parameters have been initialized, otherwise false

NameTypeDescription
poolcontract ITranchedPoolpool to check rewards info

_poolStakingRewardsInfoHaveBeenInitialized

function _poolStakingRewardsInfoHaveBeenInitialized(struct BackerRewards.StakingRewardsPoolInfo poolInfo) internal pure returns (bool)

Returns true if a given pool's staking rewards parameters have been initialized

_sliceRewardsHaveBeenInitialized

function _sliceRewardsHaveBeenInitialized(contract ITranchedPool pool, uint256 sliceIndex) internal view returns (bool)

Returns true if a TranchedPool's slice's rewards parameters have been initialized, otherwise false

_getSliceAccumulatorAtLastCheckpoint

function _getSliceAccumulatorAtLastCheckpoint(struct BackerRewards.StakingRewardsSliceInfo sliceInfo, struct BackerRewards.StakingRewardsPoolInfo poolInfo) internal pure returns (uint256)

Return a slice's rewards accumulator if it has been intialized, otherwise return the TranchedPool's accumulator

_getTokenAccumulatorAtLastWithdraw

function _getTokenAccumulatorAtLastWithdraw(struct BackerRewards.StakingRewardsTokenInfo tokenInfo, struct BackerRewards.StakingRewardsSliceInfo sliceInfo) internal pure returns (uint256)

Return a tokenss rewards accumulator if its been initialized, otherwise return the slice's accumulator

_getJuniorTrancheForTranchedPoolSlice

function _getJuniorTrancheForTranchedPoolSlice(contract ITranchedPool pool, uint256 sliceIndex) internal view returns (struct ITranchedPool.TrancheInfo)

Returns the junior tranche of a pool given a slice index

NameTypeDescription
poolcontract ITranchedPoolpool to retreive tranche from
sliceIndexuint256slice index
NameTypeDescription
[0]struct ITranchedPool.TrancheInfotranche in specified slice and pool

_getPrincipalDeployedForTranche

function _getPrincipalDeployedForTranche(struct ITranchedPool.TrancheInfo tranche) internal pure returns (uint256)

Return the amount of principal currently deployed in a given slice

NameTypeDescription
tranchestruct ITranchedPool.TrancheInfotranche to get principal outstanding of

_initializeStakingRewardsSliceInfo

function _initializeStakingRewardsSliceInfo(uint256 fiduSharePriceAtDrawdown, uint256 principalDeployedAtDrawdown, uint256 rewardsAccumulatorAtDrawdown) internal pure returns (struct BackerRewards.StakingRewardsSliceInfo)

Return an initialized StakingRewardsSliceInfo with the given parameters

_calculateProRatedRewardsForPeriod

function _calculateProRatedRewardsForPeriod(uint256 rewardsAccruedSinceLastCheckpoint, uint256 lastUpdatedTime, uint256 currentTime, uint256 endTime) internal pure returns (uint256)

Returns the amount of rewards accrued from `lastUpdatedTime` to `endTime` We assume the reward rate was linear during this time

NameTypeDescription
rewardsAccruedSinceLastCheckpointuint256rewards accumulated between `lastUpdatedTime` and `currentTime`
lastUpdatedTimeuint256the last timestamp the rewards accumulator was updated
currentTimeuint256the current timestamp
endTimeuint256the end time of the period that is elligible to accrue rewards
NameTypeDescription
[0]uint256approximate rewards accrued from `lastUpdateTime` to `endTime`

_updateStakingRewardsPoolInfoAccumulator

function _updateStakingRewardsPoolInfoAccumulator(struct BackerRewards.StakingRewardsPoolInfo poolInfo, uint256 newAccumulatorValue) internal

update a Pool's staking rewards accumulator

onlyPool

modifier onlyPool()

BackerRewardsClaimed

event BackerRewardsClaimed(address owner, uint256 tokenId, uint256 amountOfTranchedPoolRewards, uint256 amountOfSeniorPoolRewards)

BackerRewardsSetTotalRewards

event BackerRewardsSetTotalRewards(address owner, uint256 totalRewards, uint256 totalRewardPercentOfTotalGFI)

BackerRewardsSetTotalInterestReceived

event BackerRewardsSetTotalInterestReceived(address owner, uint256 totalInterestReceived)

BackerRewardsSetMaxInterestDollarsEligible

event BackerRewardsSetMaxInterestDollarsEligible(address owner, uint256 maxInterestDollarsEligible)