Comment on page
The Return Pool(s) are where the core protocol logic is executed. Each return pool maps to a set of Return NFTs, a yield generating protocol and specific pool, and a tokenized carbon credit (TCO2) corresponding to a specific climate project. At each change in state in the pool, the pool will check for yield earned, purchase the corresponding offset token, and retire that offset. Individual NFT offset amounts are calculated using a mathematical formula and global values, as it is inefficient and not scalable to write and store a value for each staked NFT each time an offset occurs.
There are no publicly callable functions, any function calls should be made through the Pool Manager contract.
The Return Pool contract maintains 2 global arrays pertaining to offset amounts purchased and retired, each index in the array corresponds to a state change within the contract.
- 1.offsetPerShare: The amount of offset token each staked token in the pool is entitled to for offset purchase i
offsetPerShare[i] = offsets purchased[i] / total staked amount[i]
2. adjustedOffsetPerShare: Running total of all offsets purchased
adjustedOffsetPerShare[i] = adjustedOffsetPerShare[i-1] + offsetPerShare[i]
The Return Pool also maintains an offsetCorrectionIndex for each NFT, which is used to determine when the NFT joined the pool, as well as an offsetEarned value, corresponding to any one time offsets that may have been made.
NFT.correctionIndex = adjustedOffsetPerShare.length (at time of user action)
To calculate the total offset for an NFT with ID X there are 3 cases:
if (X.correctionIndex == adjustedOffsetPerShare.length):
totalOffset = 0 + X.offsetEarn
NFT X was the last to change the pool state, they are not entitled to any offsets other than historical one-time offsets.
else if (X.correctionIndex == 0):
totalOffset = (X.amount * adjustedOffsetPerShare[-1]) + X.offsetEarn
NFT X was staked at the inception of the pool, it is entitled to its amount staked multiplied by the total offset earned per token staked.
totalOffset = (X.amount * (adjustedOffsetPerShare[-1] - adjustedOffsetPerShare[X.correctionIndex - 1])) + X.offsetEarn
NFT X was staked for some time, it is entitled to the amount staked multiplied by the total offset earned per token staked over the time period of which it has been staked in the pool.