Skip to content

ra0321/low_risk

Repository files navigation

Low risk strategy contracts



How to run tests:

  • Run the npm i
  • Run the npx hardhat compile command to compile the smart contracts
  • Run the npx hardhat test

πŸ“„ Description:

One strategy includes two contracts: Logic and Storage.

Logic.sol

Provides manage depositors tokens ability to admin (oracle) strategy

Error codes:

  • E1 - Cannot accept
  • E2 - vTokens is not used
  • E3 - swap is not used
  • E4 - swapMaster is not used
  • E5 - vToken is not used
  • E6 - blid is already set
  • E7 - storage is already set
  • E11 - BLID deposit amount should be less
  • E12 - withdraw BLID amount less than balance
  • E13 - BlidPerBlock should be less
  • E14 - Sender is not AccumulatedDepositor
  • E15 - LeaveTokenLimit should be increased all the time

Storage.sol

This contract is upgradable. Interacts with users, distributes earned BLID, and associates with Logic contract.

Error codes:

  • E1 - token is not used
  • E2 - is not logicContract
  • E3 - Need more amount need than zero
  • E4 - Withdraw amount exceeds balance
  • E5 - Contracrt hasn't enough for interest fee, please contact the administrator
  • E6 - token is already added
  • E7 - You can call updateAccumulatedRewardsPerShare one time for token

/crosschain/CrosschainDepositor.sol

This contract is UUPS upgradeable, provides cross-chain token deposit.

Error codes:

  • CD1 - Token should be added via addStargateToken()
  • CD2 - Token address should not be address(0)
  • CD3 - Token as been added already
  • CD4 - AccumulateDepositor should be added
  • CD5 - Some eth is required
  • CD6 - Deposit amout should be > 0
  • CD7 - Transaction gas fee is too small
  • CD8 - AccumulateDepositor has been added already

/crosschain/AccumulatedDepositor.sol

This contract is UUPS upgradeable, provides cross-chain token accept and associates with Storage contract.

Error codes:

  • AD1 - Storage contract has been added already
  • AD2 - Token should be added via addStargateToken()
  • AD3 - Token address should not be address(0)
  • AD4 - Token as been added already
  • AD5 - Only StargateRouter can call sgReceive() method

Contracts Interaction architecture

image info

BLID distribution model

Bolide Low risk Strategy distribute all earned income once X hours (often it is about 6 times a day). Users can deposit their assets and withdraw at any moment regardless of distribution schedule. To support it Bolide’s strategies use following algorithm

Let’s say we have:

  • User 1 (U1) at time moment 1 (T1) deposited 2 USD (A1)
  • User 2 (U2) at moment 2 (T2) deposited 2 USD (A2)
  • The strategy made rewards distribution at moment 3 (t3) with 1 BLID distribution (B1)

The goal is to make an honest distribution 1 BLID between 2 users, the amounts of rewards should depend on the time before distribution and amount of users deposit.

Let's say β€œDollar Time” means the amount of deposit multiplied to the time between deposit and distribution

D o l l a r T i m e ( u ) = A ( U ) βˆ— β–³ T

For example D o l l a r T i m e ( U 1 ) = A ( U ) βˆ— Ξ” T = A 1 βˆ— ( T 3 βˆ’ T 1 ) = A 1 βˆ— T 3 βˆ’ A 1 βˆ— T 1 = 2 βˆ— 3 βˆ’ 2 βˆ— 1 = 4

D o l l a r T i m e ( U 2 ) = A ( U ) βˆ— Ξ” T = A 2 βˆ— ( T 3 βˆ’ T 2 ) = A 2 βˆ— T 3 βˆ’ A 2 βˆ— T 2 = 2 βˆ— 3 βˆ’ 2 βˆ— 2 = 2

Then β€œTotal Dollar timeβ€œ

T o t a l D o l l a r T i m e ( U ) = βˆ‘ n 1 D o l l a r T i m e ( U i )

Then β€œDollar Time Distribution” means how much BLID should be distributed per 1 DollarTime.

D o l l a r T i m e D i s t r i b u t i o n ( U ) = B T o t a l D o l l a r T i m e

For our example

D o l l a r T i m e D i s t r i b u t i o n ( T 3 ) = 1 ( 2 + 4 ) = 1 6

Or we can calculate DollarTimeDistribution as follows

$$\small DollarTimeDistribution(T) = \frac{B}{\sum_iAiT-\sum_iAiTi}$$

Then

D o l l a r T i m e D i s t r i b u t i o n ( T 3 ) = B 1 ( A 1 βˆ— T 3 + A 2 βˆ— T 3 ) βˆ’ ( A 1 βˆ— T 1 + A 2 βˆ— T 2 ) = 1 4 βˆ— 3 βˆ’ ( 2 βˆ— 1 + 2 βˆ— 2 ) = 1 6

After that, we can calculate user’s rewards as follows

R e w a r d s ( U i ) = D o l l a r T i m e D i s t r i b u t i o n ( T ) βˆ— D o l l a r T i m e ( U i ) = D o l l a r T i m e D i s t r i b u t i o n ( T ) βˆ— ( A i βˆ— T d βˆ’ A i βˆ— T i )

So we have

R e w a r d s ( U 1 ) = 1 6 βˆ— ( 2 βˆ— 3 βˆ’ 2 βˆ— 1 ) = 2 3

R e w a r d s ( U 2 ) = 1 6 βˆ— ( 2 βˆ— 3 βˆ’ 2 βˆ— 2 ) = 1 3

It's obvious that if user withdraw some amount of deposit than we should use Ai with β€œ-” sign in all calculations.

So the final formula is

R e w a r d s ( U ) = D o l l a r T i m e D i s t r i b u t i o n ( T ) βˆ— ( A i βˆ— T d βˆ’ A i βˆ— T i )

About

Low risk strategy contracts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published