Skip to content

Storage

dexterslabor edited this page Apr 19, 2021 · 2 revisions
type delegator = address
type delegatorRecord = {
    lpTokenBalance: nat,
    accumulatedRewardPerShareStart: nat,
};

type claimedRewards = {
    unpaid: nat,
    paid: nat,
};

type plannedRewards = {
    totalBlocks: nat,
    rewardPerBlock: nat,
};

type farm = {
    lastBlockUpdate: nat,
    accumulatedRewardPerShare: nat,
    claimedRewards: claimedRewards,
    plannedRewards: plannedRewards
};

type addresses = {
    admin: address,
    lpTokenContract: address,
    rewardTokenContract: address,
    rewardReserve: address
};

type storage = {
    farm: farm,
    delegators: big_map(delegator, delegatorRecord),
    farmLpTokenBalance: nat,
    addresses: addresses
};
  • claimedRewards: claimedRewards

    Keeps track of pool rewards that have been paid or are pending to be paid out

    • unpaid
    • paid
  • plannedRewards: plannedRewards

    Configuration object set at origination, specifying how much of the reward token should be paid out every block. And how many blocks of lifetime the farm has.

    The overall amount of the reward token distributed is calculated as totalBlocks * rewardPerBlock.

    • totalBlocks
    • rewardPerBlock
  • delegators: big_map(delegator, delegatorRecord)

    (big) Map of delegator addresses and their staking balances & reward debts.

    - key: delegator (address)
    - value: delegatorRecord
    • balance

      Represents the total staked balance (of the staking token) of the current delegator.

    • stakingStart

      Represents the accumulatedRewardPerShare at the time the delegator started staking (joined the staking pool), or has claimed the reward payout the last time.

  • lastBlockUpdate: nat

    Keeps track of the last time the pool state was updated. This is used to prevent duplicate pool state updates in the same block. Invariant of the system achieved thanks to the lastBlockUpdate is that the delegation rewards start accumulating only in the n+1 block after depositing.

    E.g. if you deposit in block 0, you're only eligible for rewards from block 1

  • accumulatedRewardPerShare: nat

    Keeps track of how many reward token each liquidity pool share (staked LP token) is worth. This number is recalculated at every pool update.

  • admin: address

    Address of the administrator who has permission to update plannedRewards (total blocks & reward per block) and set another address as admin.

  • lpTokenContract: address

    Address of the token being staked, originally an LP token from a DEX.

  • farmLpTokenBalance: nat

    Balance of the lpTokenContract tokens for the current farm contract. This standalone "ledger" entry exists to avoid exploits with operations that may introduce issues & overhead due to Tezos' message passing architecture (BFS), specifically when calling tokenContract%getBalance.

  • rewardTokenContract: address

    Address of the reward token contract.

  • rewardReserve: address

    Address of the account that holds the reward tokens to be paid out. This account gives an allowance to the farm contract through the approve method of the FA1.2 contract.