Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#380 - Use the locked OCEAN amount instead of veOCEAN balance #799

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion df_py/util/test/test_dftool_ganache.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def test_calc_without_amount(tmp_path, monkeypatch):
csvs.save_owners_csv(owners_at_chain, csv_dir, CHAINID)

vebals = {"0xlp_addr1": 1e8}
locked_amt = {"0xlp_addr1": 10.0}
locked_amt = {"0xlp_addr1": 1e8}
unlock_time = {"0xlp_addr1": 1}
csvs.save_vebals_csv(vebals, locked_amt, unlock_time, csv_dir)

Expand Down
9 changes: 6 additions & 3 deletions df_py/volume/allocations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enforce_typing import enforce_types

from df_py.volume import cleancase, csvs
from typing import Tuple


@enforce_types
Expand Down Expand Up @@ -33,14 +34,16 @@ def allocs_to_stakes(allocs: dict, vebals: dict) -> dict:


@enforce_types
def load_stakes(csv_dir: str) -> dict:
def load_stakes(csv_dir: str) -> Tuple[dict, dict]:
"""
Loads allocs and vebals, computes stakes from it, and returns stakes.

@return
stakes - dict of [chainID][nft_addr][LP_addr] : veOCEAN_float - abs alloc
locked_amts_per_nft - dict of [chainID][nft_addr][LP_addr] : OCEAN_float - abs alloc
"""
allocs = csvs.load_allocation_csvs(csv_dir)
vebals, _, _ = csvs.load_vebals_csv(csv_dir)
vebals, locked_amts, _ = csvs.load_vebals_csv(csv_dir)
stakes = allocs_to_stakes(allocs, vebals)
return stakes
locked_amts_per_nft = allocs_to_stakes(allocs, locked_amts)
return stakes, locked_amts_per_nft
5 changes: 4 additions & 1 deletion df_py/volume/calc_rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def calc_volume_rewards_from_csvs(
do_pubrewards: Optional[bool] = DO_PUBREWARDS,
do_rank: Optional[bool] = DO_RANK,
):
S = allocations.load_stakes(csv_dir)
S, L = allocations.load_stakes(csv_dir)
V = csvs.load_nftvols_csvs(csv_dir)
C = csvs.load_owners_csvs(csv_dir)
SYM = csvs.load_symbols_csvs(csv_dir)
Expand All @@ -30,6 +30,7 @@ def calc_volume_rewards_from_csvs(

rewperlp, rewinfo = calc_volume_rewards(
S,
L,
V,
C,
SYM,
Expand All @@ -46,6 +47,7 @@ def calc_volume_rewards_from_csvs(

def calc_volume_rewards(
S: Dict[int, Dict[str, Dict[str, float]]],
L: Dict[int, Dict[str, Dict[str, float]]],
V: Dict[int, Dict[str, Dict[str, float]]],
C: Dict[int, Dict[str, str]],
SYM: Dict[int, Dict[str, str]],
Expand Down Expand Up @@ -73,6 +75,7 @@ def calc_volume_rewards(

vol_calculator = RewardCalculator(
S,
L,
V,
C,
SYM,
Expand Down
19 changes: 15 additions & 4 deletions df_py/volume/reward_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __setattr__(self, attr, value):
def __init__(
self,
stakes: Dict[int, Dict[str, Dict[str, float]]],
locked_ocean_amts: Dict[int, Dict[str, Dict[str, float]]],
nftvols: Dict[int, Dict[str, Dict[str, float]]],
owners: Dict[int, Dict[str, str]],
symbols: Dict[int, Dict[str, str]],
Expand All @@ -51,6 +52,7 @@ def __init__(
"""
@arguments
stakes - dict of [chainID][nft_addr][LP_addr] : veOCEAN_float
locked_ocean_amts: dict of [chainID][nft_addr][LP_addr] : OCEAN amount
nftvols -- dict of [chainID][basetoken_addr][nft_addr] : consume_vol_float
owners -- dict of [chainID][nft_addr] : owner_addr
symbols -- dict of [chainID][basetoken_addr] : basetoken_symbol_str
Expand All @@ -63,6 +65,7 @@ def __init__(
self._freeze_attributes = False

self.stakes = cc.mod_stakes(stakes)
self.locked_ocean_amts = cc.mod_stakes(locked_ocean_amts)
self.nftvols = cc.mod_nft_vols(nftvols)
self.owners = cc.mod_owners(owners)
self.symbols = cc.mod_symbols(symbols)
Expand All @@ -87,6 +90,7 @@ def __init__(
self.V_USD: np.ndarray
self.M: np.ndarray
self.R: np.ndarray
self.L: np.ndarray

self._freeze_attributes = True

Expand All @@ -99,7 +103,9 @@ def calculate(self):
"""
self._freeze_attributes = False

self.S, self.V_USD, self.M, self.C = self._stake_vol_owner_dicts_to_arrays()
self.S, self.V_USD, self.M, self.C, self.L = (
self._stake_vol_owner_dicts_to_arrays()
)
self.R = self._calc_rewards_usd()

self._freeze_attributes = True
Expand All @@ -112,7 +118,7 @@ def calculate(self):
@enforce_types
def _stake_vol_owner_dicts_to_arrays(
self,
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
"""
@return
S -- 2d array of [LP i, chain_nft j] -- stake for each {i,j}, in veOCEAN
Expand All @@ -125,11 +131,13 @@ def _stake_vol_owner_dicts_to_arrays(
S = np.zeros((N_i, N_j), dtype=float)
V_USD = np.zeros(N_j, dtype=float)
C = np.zeros(N_j, dtype=int)
L = np.zeros((N_i, N_j), dtype=float)

for j, (chainID, nft_addr) in enumerate(self.chain_nft_tups):
for i, LP_addr in enumerate(self.LP_addrs):
assert nft_addr in self.stakes[chainID], "each tup should be in stakes"
S[i, j] = self.stakes[chainID][nft_addr].get(LP_addr, 0.0)
L[i, j] = self.locked_ocean_amts[chainID][nft_addr].get(LP_addr, 0.0)
V_USD[j] += self.nftvols_USD[chainID].get(nft_addr, 0.0)

M[j] = calc_dcv_multiplier(
Expand All @@ -143,7 +151,7 @@ def _stake_vol_owner_dicts_to_arrays(
else self.LP_addrs.index(owner_addr)
)

return S, V_USD, M, C
return S, V_USD, M, C, L

@freeze_attributes
@enforce_types
Expand All @@ -159,6 +167,7 @@ def _calc_rewards_usd(self) -> np.ndarray:
return np.zeros((N_i, N_j), dtype=float)

S = np.copy(self.S)
L = np.copy(self.L)
# modify S's: owners get rewarded as if 2x stake on their asset
if self.do_pubrewards:
for j in range(N_j):
Expand All @@ -185,11 +194,13 @@ def _calc_rewards_usd(self) -> np.ndarray:
stake_ij = S[i, j]
perc_at_ij = stake_ij / stake_j

ocean_locked_ij = L[i, j]

# main formula!
# reward amount in OCEAN
R[i, j] = min(
perc_at_j * perc_at_ij * self.OCEAN_avail,
stake_ij * TARGET_WPY, # bound rewards by max APY
ocean_locked_ij * TARGET_WPY, # bound rewards by max APY
DCV_OCEAN_j * multiplier, # bound rewards by DCV
)

Expand Down
7 changes: 5 additions & 2 deletions df_py/volume/test/test_allocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ def test_load_stakes(tmp_path):
csvs.save_allocation_csv(allocs, csv_dir)

vebals = {ST1: 100.0, ST2: 200.0}
locked_amt = {ST1: 10.0, ST2: 20.0}
locked_amt = {ST1: 200.0, ST2: 400.0}
unlock_time = {ST1: 1, ST2: 1}
csvs.save_vebals_csv(vebals, locked_amt, unlock_time, csv_dir)

target_stakes = allocs_to_stakes(allocs, vebals)
target_locked_amts = allocs_to_stakes(allocs, locked_amt)

with patch("web3.main.Web3.to_checksum_address") as mock:
mock.side_effect = lambda value: value
loaded_stakes = load_stakes(csv_dir)
loaded_stakes, loaded_locked_amts = load_stakes(csv_dir)
assert loaded_stakes == target_stakes
assert loaded_locked_amts == target_locked_amts
Loading
Loading