|
36 | 36 | }, |
37 | 37 | { |
38 | 38 | "cell_type": "code", |
39 | | - "execution_count": 4, |
| 39 | + "execution_count": null, |
40 | 40 | "id": "d86910eb-2a7d-423a-be04-3e6018cc373f", |
41 | 41 | "metadata": {}, |
42 | 42 | "outputs": [], |
43 | 43 | "source": [ |
44 | 44 | "# reward_rate : same value as given by `ProtocolStaking:rewardRate()`\n", |
45 | 45 | "# 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", |
48 | 48 | " \"\"\"\n", |
49 | 49 | " :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", |
50 | 50 | " :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", |
52 | 52 | " \n", |
53 | 53 | " :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", |
55 | 55 | " \"\"\"\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", |
58 | 58 | " assert all(0 <= num_token for num_token in num_tokens_per_pool), \"number of tokens must be non-negative\"\n", |
59 | 59 | " assert reward_rate >=0, \"`reward_rate` must be non-negative\"\n", |
60 | 60 | "\n", |
61 | 61 | " weights = [int(math.sqrt(x)) for x in num_tokens_per_pool]\n", |
62 | 62 | " 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", |
64 | 64 | " reward_rate_per_sec_per_pool = [reward_rate * (pool_weight / total_weight) for pool_weight in weights]\n", |
65 | 65 | " pool_aprs = []\n", |
66 | 66 | " for i in range(len(fee_factors)):\n", |
|
72 | 72 | }, |
73 | 73 | { |
74 | 74 | "cell_type": "code", |
75 | | - "execution_count": 5, |
| 75 | + "execution_count": null, |
76 | 76 | "id": "4802969a-2f8d-4a49-9fa3-8f293a719865", |
77 | 77 | "metadata": {}, |
78 | 78 | "outputs": [], |
79 | 79 | "source": [ |
80 | 80 | "def compute_native_APY(\n", |
81 | 81 | " reward_rate: int,\n", |
82 | 82 | " num_tokens_per_pool: list[int],\n", |
83 | | - " owner_fees_per_pool: list[int],\n", |
| 83 | + " fees_per_pool: list[int],\n", |
84 | 84 | " compounds: int,\n", |
85 | 85 | ") -> list[float]:\n", |
86 | 86 | " \"\"\"\n", |
87 | 87 | " Same inputs as compute_native_APR plus `compounds` per year.\n", |
88 | 88 | " Returns APY as PERCENT (e.g. 5.1 for 5.1%).\n", |
89 | 89 | " \"\"\"\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", |
91 | 91 | " apys_percent = [\n", |
92 | 92 | " apr_to_apy(apr / 100.0, compounds) * 100.0 # convert % -> fraction -> APY -> %\n", |
93 | 93 | " for apr in aprs_percent\n", |
|
117 | 117 | }, |
118 | 118 | { |
119 | 119 | "cell_type": "code", |
120 | | - "execution_count": 7, |
| 120 | + "execution_count": null, |
121 | 121 | "id": "5318b359-36d3-4eec-8b45-d509880699ff", |
122 | 122 | "metadata": {}, |
123 | 123 | "outputs": [ |
|
133 | 133 | "source": [ |
134 | 134 | "reward_rate = 1e18\n", |
135 | 135 | "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))" |
139 | 139 | ] |
140 | 140 | }, |
141 | 141 | { |
142 | 142 | "cell_type": "code", |
143 | | - "execution_count": 8, |
| 143 | + "execution_count": null, |
144 | 144 | "id": "9226d508-6b2a-470b-a7ca-10d0c6d3b170", |
145 | 145 | "metadata": {}, |
146 | 146 | "outputs": [ |
|
156 | 156 | "source": [ |
157 | 157 | "reward_rate = 1e18\n", |
158 | 158 | "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))" |
162 | 162 | ] |
163 | 163 | } |
164 | 164 | ], |
165 | 165 | "metadata": { |
166 | 166 | "kernelspec": { |
167 | | - "display_name": "Python 3 (ipykernel)", |
| 167 | + "display_name": "Python 3", |
168 | 168 | "language": "python", |
169 | 169 | "name": "python3" |
170 | 170 | }, |
|
178 | 178 | "name": "python", |
179 | 179 | "nbconvert_exporter": "python", |
180 | 180 | "pygments_lexer": "ipython3", |
181 | | - "version": "3.11.10" |
| 181 | + "version": "3.10.11" |
182 | 182 | } |
183 | 183 | }, |
184 | 184 | "nbformat": 4, |
|
0 commit comments