Skip to content

Commit 68699af

Browse files
authored
feat(protocol-contracts): improve fees management in staking contracts (#1482)
1 parent f0dcecd commit 68699af

File tree

12 files changed

+564
-222
lines changed

12 files changed

+564
-222
lines changed

protocol-contracts/staking/.env.example

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ OPERATOR_STAKING_COPRO_INITIAL_DEPOSIT_ASSETS_0=100000000000000000000000
6262
OPERATOR_STAKING_COPRO_INITIAL_DEPOSIT_RECEIVER_0="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" # accounts[0] (address)
6363

6464
# OperatorRewarder coprocessor 1
65-
# Initial owner fee
66-
# Note: The owner fee is in basis points (in 1/100th of a percent, so 10000 = 100.00%)
67-
OPERATOR_REWARDER_COPRO_OWNER_FEE_0=2000
65+
OPERATOR_REWARDER_COPRO_BENEFICIARY_0="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" # accounts[0] (address)
66+
67+
# Initial fee
68+
# Note: The fee is in basis points (in 1/100th of a percent, so 10000 = 100.00%)
69+
OPERATOR_REWARDER_COPRO_MAX_FEE_0=2000
70+
OPERATOR_REWARDER_COPRO_FEE_0=2000
6871

6972
# OperatorStaking coprocessor 2
7073
OPERATOR_STAKING_COPRO_TOKEN_NAME_1="OperatorStakingCopro2"
@@ -76,9 +79,12 @@ OPERATOR_STAKING_COPRO_INITIAL_DEPOSIT_ASSETS_1=250000000000000000000000
7679
OPERATOR_STAKING_COPRO_INITIAL_DEPOSIT_RECEIVER_1="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" # accounts[0] (address)
7780

7881
# OperatorRewarder coprocessor 2
79-
# Initial owner fee
80-
# Note: The owner fee is in basis points (in 1/100th of a percent, so 10000 = 100.00%)
81-
OPERATOR_REWARDER_COPRO_OWNER_FEE_1=1000
82+
OPERATOR_REWARDER_COPRO_BENEFICIARY_1="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" # accounts[0] (address)
83+
84+
# Initial fee
85+
# Note: The fee is in basis points (in 1/100th of a percent, so 10000 = 100.00%)
86+
OPERATOR_REWARDER_COPRO_MAX_FEE_1=2000
87+
OPERATOR_REWARDER_COPRO_FEE_1=1000
8288

8389
# ----------------------------------------------------------------------------
8490
# KMS
@@ -96,9 +102,12 @@ OPERATOR_STAKING_KMS_INITIAL_DEPOSIT_ASSETS_0=500000000000000000000000
96102
OPERATOR_STAKING_KMS_INITIAL_DEPOSIT_RECEIVER_0="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" # accounts[0] (address)
97103

98104
# OperatorRewarder KMS 1
99-
# Initial owner fee
100-
# Note: The owner fee is in basis points (in 1/100th of a percent, so 10000 = 100.00%)
101-
OPERATOR_REWARDER_KMS_OWNER_FEE_0=1500
105+
OPERATOR_REWARDER_KMS_BENEFICIARY_0="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" # accounts[0] (address)
106+
107+
# Initial fee
108+
# Note: The fee is in basis points (in 1/100th of a percent, so 10000 = 100.00%)
109+
OPERATOR_REWARDER_KMS_MAX_FEE_0=2000
110+
OPERATOR_REWARDER_KMS_FEE_0=1500
102111

103112
# OperatorStaking KMS 2
104113
OPERATOR_STAKING_KMS_TOKEN_NAME_1="OperatorStakingKms2"
@@ -110,9 +119,12 @@ OPERATOR_STAKING_KMS_INITIAL_DEPOSIT_ASSETS_1=750000000000000000000000
110119
OPERATOR_STAKING_KMS_INITIAL_DEPOSIT_RECEIVER_1="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" # accounts[0] (address)
111120

112121
# OperatorRewarder KMS 2
113-
# Initial owner fee
114-
# Note: The owner fee is in basis points (in 1/100th of a percent, so 10000 = 100.00%)
115-
OPERATOR_REWARDER_KMS_OWNER_FEE_1=1000
122+
OPERATOR_REWARDER_KMS_BENEFICIARY_1="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" # accounts[0] (address)
123+
124+
# Initial fee
125+
# Note: The fee is in basis points (in 1/100th of a percent, so 10000 = 100.00%)
126+
OPERATOR_REWARDER_KMS_MAX_FEE_1=2000
127+
OPERATOR_REWARDER_KMS_FEE_1=1000
116128

117129
# OperatorStaking KMS 3
118130
OPERATOR_STAKING_KMS_TOKEN_NAME_2="OperatorStakingKms3"
@@ -124,6 +136,9 @@ OPERATOR_STAKING_KMS_INITIAL_DEPOSIT_ASSETS_2=1000000000000000000000000
124136
OPERATOR_STAKING_KMS_INITIAL_DEPOSIT_RECEIVER_2="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" # accounts[0] (address)
125137

126138
# OperatorRewarder KMS 3
127-
# Initial owner fee
128-
# Note: The owner fee is in basis points (in 1/100th of a percent, so 10000 = 100.00%)
129-
OPERATOR_REWARDER_KMS_OWNER_FEE_2=500
139+
OPERATOR_REWARDER_KMS_BENEFICIARY_2="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" # accounts[0] (address)
140+
141+
# Initial fee
142+
# Note: The fee is in basis points (in 1/100th of a percent, so 10000 = 100.00%)
143+
OPERATOR_REWARDER_KMS_MAX_FEE_2=2000
144+
OPERATOR_REWARDER_KMS_FEE_2=500

protocol-contracts/staking/APY.ipynb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,31 @@
3636
},
3737
{
3838
"cell_type": "code",
39-
"execution_count": 4,
39+
"execution_count": null,
4040
"id": "d86910eb-2a7d-423a-be04-3e6018cc373f",
4141
"metadata": {},
4242
"outputs": [],
4343
"source": [
4444
"# reward_rate : same value as given by `ProtocolStaking:rewardRate()`\n",
4545
"# num_tokens_per_pool: same values as given by `ProtocolStaking:balanceOf(address(OperatorStaking))` for every eligible OperatorStaking\n",
46-
"# owner_fees_per_pool: same values as given by `OperatorRewarder:ownerFeeBasisPoints()` for every corresponding OperatorRewarder\n",
47-
"def compute_native_APR(reward_rate: int, num_tokens_per_pool: list[int], owner_fees_per_pool: list[int]) -> list[float]:\n",
46+
"# fees_per_pool: same values as given by `OperatorRewarder:feeBasisPoints()` for every corresponding OperatorRewarder\n",
47+
"def compute_native_APR(reward_rate: int, num_tokens_per_pool: list[int], fees_per_pool: list[int]) -> list[float]:\n",
4848
" \"\"\"\n",
4949
" :param reward_rate: in amount of tokens per second according to the EVM, i.e reward_rate of 1e18 <=> 1 ZAMA token per second\n",
5050
" :param num_tokens_per_pool: list of amount of tokens deposited in each OperatorStaking pool\n",
51-
" :param owner_fees_per_pool: list of owner fees, one per OperatorStaking pool, in basis points, i.e owner_fee of 10000 <=> 100% fees \n",
51+
" :param fees_per_pool: list of fees, one per OperatorStaking pool, in basis points, i.e fee of 10000 <=> 100% fees \n",
5252
" \n",
5353
" :return: a float corresponding to the PERCENTAGE of _native_ APR i.e not considering direct token donations to OperatorStaking.\n",
54-
" It assumes reward_rate, num_tokens_per_pool and list_owner_fees are constants, to get an instantaneous APR value.\n",
54+
" It assumes reward_rate, num_tokens_per_pool and fees_per_pool are constants, to get an instantaneous APR value.\n",
5555
" \"\"\"\n",
56-
" assert len(num_tokens_per_pool)==len(owner_fees_per_pool), \"`num_tokens_per_pool` and `owner_fees_per_pool` length mismatch\"\n",
57-
" assert all(0 <= fee <= 10000 for fee in owner_fees_per_pool), \"owner fees must be in [0, 10000]\"\n",
56+
" assert len(num_tokens_per_pool)==len(fees_per_pool), \"`num_tokens_per_pool` and `fees_per_pool` length mismatch\"\n",
57+
" assert all(0 <= fee <= 10000 for fee in fees_per_pool), \"fees must be in [0, 10000]\"\n",
5858
" assert all(0 <= num_token for num_token in num_tokens_per_pool), \"number of tokens must be non-negative\"\n",
5959
" assert reward_rate >=0, \"`reward_rate` must be non-negative\"\n",
6060
"\n",
6161
" weights = [int(math.sqrt(x)) for x in num_tokens_per_pool]\n",
6262
" total_weight = sum(weights)\n",
63-
" fee_factors = [1-fee/10000 for fee in owner_fees_per_pool]\n",
63+
" fee_factors = [1-fee/10000 for fee in fees_per_pool]\n",
6464
" reward_rate_per_sec_per_pool = [reward_rate * (pool_weight / total_weight) for pool_weight in weights]\n",
6565
" pool_aprs = []\n",
6666
" for i in range(len(fee_factors)):\n",
@@ -72,22 +72,22 @@
7272
},
7373
{
7474
"cell_type": "code",
75-
"execution_count": 5,
75+
"execution_count": null,
7676
"id": "4802969a-2f8d-4a49-9fa3-8f293a719865",
7777
"metadata": {},
7878
"outputs": [],
7979
"source": [
8080
"def compute_native_APY(\n",
8181
" reward_rate: int,\n",
8282
" num_tokens_per_pool: list[int],\n",
83-
" owner_fees_per_pool: list[int],\n",
83+
" fees_per_pool: list[int],\n",
8484
" compounds: int,\n",
8585
") -> list[float]:\n",
8686
" \"\"\"\n",
8787
" Same inputs as compute_native_APR plus `compounds` per year.\n",
8888
" Returns APY as PERCENT (e.g. 5.1 for 5.1%).\n",
8989
" \"\"\"\n",
90-
" aprs_percent = compute_native_APR(reward_rate, num_tokens_per_pool, owner_fees_per_pool)\n",
90+
" aprs_percent = compute_native_APR(reward_rate, num_tokens_per_pool, fees_per_pool)\n",
9191
" apys_percent = [\n",
9292
" apr_to_apy(apr / 100.0, compounds) * 100.0 # convert % -> fraction -> APY -> %\n",
9393
" for apr in aprs_percent\n",
@@ -117,7 +117,7 @@
117117
},
118118
{
119119
"cell_type": "code",
120-
"execution_count": 7,
120+
"execution_count": null,
121121
"id": "5318b359-36d3-4eec-8b45-d509880699ff",
122122
"metadata": {},
123123
"outputs": [
@@ -133,14 +133,14 @@
133133
"source": [
134134
"reward_rate = 1e18\n",
135135
"num_tokens_per_pool = 5*[100_000_000*1e18]\n",
136-
"owner_fees_per_pool = [0] + 4*[500] # first pool owner takes no fee, other 4 owners take 5%\n",
137-
"print(\"APRs in % for each pool :\" , compute_native_APR(reward_rate, num_tokens_per_pool, owner_fees_per_pool))\n",
138-
"print(\"APYs in % for same pools :\", compute_native_APY(reward_rate, num_tokens_per_pool, owner_fees_per_pool, 365))"
136+
"fees_per_pool = [0] + 4*[500] # first pool owner takes no fee, other 4 owners take 5%\n",
137+
"print(\"APRs in % for each pool :\" , compute_native_APR(reward_rate, num_tokens_per_pool, fees_per_pool))\n",
138+
"print(\"APYs in % for same pools :\", compute_native_APY(reward_rate, num_tokens_per_pool, fees_per_pool, 365))"
139139
]
140140
},
141141
{
142142
"cell_type": "code",
143-
"execution_count": 8,
143+
"execution_count": null,
144144
"id": "9226d508-6b2a-470b-a7ca-10d0c6d3b170",
145145
"metadata": {},
146146
"outputs": [
@@ -156,15 +156,15 @@
156156
"source": [
157157
"reward_rate = 1e18\n",
158158
"num_tokens_per_pool = [1_000_000*1e18] + 4*[100_000_000*1e18] # first OperatorStaking pool has -99% less tokens staked than the other 4 pools\n",
159-
"owner_fees_per_pool = 5*[500] # first pool owner takes no fee, other 4 owners take 5%\n",
160-
"print(\"APRs in % for each pool :\" , compute_native_APR(reward_rate, num_tokens_per_pool, owner_fees_per_pool))\n",
161-
"print(\"APYs in % for same pools :\", compute_native_APY(reward_rate, num_tokens_per_pool, owner_fees_per_pool, 365))"
159+
"fees_per_pool = 5*[500] # first pool owner takes no fee, other 4 owners take 5%\n",
160+
"print(\"APRs in % for each pool :\" , compute_native_APR(reward_rate, num_tokens_per_pool, fees_per_pool))\n",
161+
"print(\"APYs in % for same pools :\", compute_native_APY(reward_rate, num_tokens_per_pool, fees_per_pool, 365))"
162162
]
163163
}
164164
],
165165
"metadata": {
166166
"kernelspec": {
167-
"display_name": "Python 3 (ipykernel)",
167+
"display_name": "Python 3",
168168
"language": "python",
169169
"name": "python3"
170170
},
@@ -178,7 +178,7 @@
178178
"name": "python",
179179
"nbconvert_exporter": "python",
180180
"pygments_lexer": "ipython3",
181-
"version": "3.11.10"
181+
"version": "3.10.11"
182182
}
183183
},
184184
"nbformat": 4,

0 commit comments

Comments
 (0)