-
Diamond Standard for upgradeability
- started from the reference implementation here which was refactored
- the features presented below are implemented on a single facet in BarnFacet.sol
-
Diamond Storage for storage
- deposit
- withdraw
- lock
- delegate
balance
- current and snapshot = the actual amount a user staked (bonus not included)delegated power
- current and snapshot = how much power was delegated to a user by other usersvoting power
- current and snapshot =balance * (1 + bonus) + delegated power
total $BOND staked
- current and snapshot
- user can stake BOND for vBOND
- user can lock BOND for a period up to 1 year and he gets a bonus of vBOND
- bonus is linear, max 1 year, max 2x multiplier
- example:
- lock 1000 BOND for 1 year → get back 2000 vBOND
- lock 1000 BOND for 6 months → get back 1500 vBOND
- example:
- bonus has a linear decay relative to locking duration
- example: lock 1000 BOND for 1 year, get back 2000 vBOND at T0 → after 6 months, balance is 1500 vBOND → after 9 months, balance is 1250 vBOND
- user can only withdraw their BOND balance after lock expires
- bonus is linear, max 1 year, max 2x multiplier
- user can keep BOND unlocked and no bonus is applied, vBOND balance = BOND balance
- user can lock BOND for a period up to 1 year and he gets a bonus of vBOND
- user can stake more BOND
- no lock → just get back the same amount of vBOND
- lock
- lock period stays the same
- base balance is increased with the added BOND
- multiplier stays the same
- lock period is extended
- base balance is increased with the added BOND
- multiplier is recalculated relative to the new lock expiration date
- base balance is increased with the added BOND
- lock period stays the same
- user can delegate vBOND to another user
- there can be only one delegatee at a time
- only actual balance can be delegated, not the bonus
- delegated balance cannot be locked
- user can take back the delegated vBONDs at any time
The rewards contract is meant as a continuation of the pool 3 from BarnBridge's YieldFarming program. It is used to incentivize participation in the DAO.
The distribution mechanism is based on a continuous strategy (for example, if you staked for 5 minutes, you can claim a reward relative to those 5 minutes).
The Barn
contract calls the registerUserAction
hook on each deposit
/withdraw
the user executes.
- every time the
acKFunds
function detects a balance change, the multiplier is recalculated by the following formula:
newMultiplier = oldMultiplier + amountAdded / totalBondStaked
- whenever a user action is registered (either by automatic calls from the hook or by user action (claim)), we calculate the amount owed to the user by the following formula:
newOwed = currentlyOwed + userBalance * (currentMultiplier - oldUserMultiplier)
where:
- oldUserMultiplier is the multiplier at the time of last user action
- userBalance = barn.balanceOf(user) -- the amount of $BOND staked into the Barn
- update the oldUserMultiplier with the current multiplier -- signaling that we already calculated how much was owed to the user since his last action
Note: The result of tests is readily available here.
git clone [email protected]:BarnBridge/BarnBridge-Barn.git
yarn install
yarn test
# or if you want to run with coverage
yarn run coverage
DiamondCutFacet deployed to: 0x767f7d9E655161C9E6D8a3Dbb565666FCAa2BDf4
DiamondLoupeFacet deployed to: 0x04499B879F6A7E75802cd09354eF2B788BF4Cf26
OwnershipFacet deployed to: 0xeB8E3e48F770C5c13D9De2203Fc307B6D04381FF
ChangeRewardsFacet deployed to: 0xb93E511D913A17826D2Df5AC8BE122C0EBd1A26d
BarnFacet deployed at: 0xA62dA56e9a330646386365dC6B2945b5C4d120ed
-----
Barn deployed at: 0x10e138877df69Ca44Fdc68655f86c88CDe142D7F
Rewards deployed at: 0x9d0CF50547D848cC4b6A12BeDCF7696e9b334a22