|
14 | 14 | DISABLED_STAKER_ACCOUNTS_QUERY, |
15 | 15 | DISTRIBUTOR_CLAIMED_ACCOUNTS_QUERY, |
16 | 16 | ONE_TIME_DISTRIBUTIONS_QUERY, |
17 | | - PARTNERS_QUERY, |
18 | 17 | PERIODIC_DISTRIBUTIONS_QUERY, |
19 | 18 | ) |
20 | 19 | from oracle.oracle.distributor.common.ipfs import get_one_time_rewards_allocations |
@@ -188,105 +187,6 @@ async def get_operators_rewards( |
188 | 187 | return rewards, Wei(total_reward - operators_reward) |
189 | 188 |
|
190 | 189 |
|
191 | | -async def get_partners_rewards( |
192 | | - network: str, |
193 | | - from_block: BlockNumber, |
194 | | - to_block: BlockNumber, |
195 | | - total_reward: Wei, |
196 | | - reward_token_address: ChecksumAddress, |
197 | | -) -> Tuple[Rewards, Wei]: |
198 | | - """Fetches partners rewards.""" |
199 | | - result: Dict = await execute_sw_gql_query( |
200 | | - network=network, |
201 | | - query=PARTNERS_QUERY, |
202 | | - variables=dict( |
203 | | - block_number=to_block, |
204 | | - ), |
205 | | - ) |
206 | | - partners = result["partners"] |
207 | | - |
208 | | - # process partners |
209 | | - points: Dict[ChecksumAddress, int] = {} |
210 | | - total_points = 0 |
211 | | - total_contributed = 0 |
212 | | - for partner in partners: |
213 | | - account = Web3.toChecksumAddress(partner["id"]) |
214 | | - if account == EMPTY_ADDR_HEX: |
215 | | - continue |
216 | | - |
217 | | - contributed_amount = Wei(int(partner["contributedAmount"])) |
218 | | - total_contributed += contributed_amount |
219 | | - |
220 | | - revenue_share = int(partner["revenueShare"]) |
221 | | - prev_account_points = int(partner["distributorPoints"]) |
222 | | - updated_at_block = BlockNumber(int(partner["updatedAtBlock"])) |
223 | | - if from_block > updated_at_block: |
224 | | - updated_at_block = from_block |
225 | | - prev_account_points = 0 |
226 | | - |
227 | | - account_points = prev_account_points + ( |
228 | | - contributed_amount * revenue_share * (to_block - updated_at_block) |
229 | | - ) |
230 | | - if account_points <= 0: |
231 | | - continue |
232 | | - |
233 | | - points[account] = account_points |
234 | | - total_points += account_points |
235 | | - |
236 | | - if total_contributed <= 0: |
237 | | - return {}, total_reward |
238 | | - |
239 | | - partners_reward = Wei( |
240 | | - (total_reward * total_points) |
241 | | - // (total_contributed * 10000 * (to_block - from_block)) |
242 | | - ) |
243 | | - if partners_reward <= 0: |
244 | | - return {}, total_reward |
245 | | - |
246 | | - partners_reward = min(total_reward, partners_reward) |
247 | | - rewards = calculate_points_based_rewards( |
248 | | - total_reward=partners_reward, |
249 | | - points=points, |
250 | | - total_points=total_points, |
251 | | - reward_token=reward_token_address, |
252 | | - ) |
253 | | - |
254 | | - return rewards, Wei(total_reward - partners_reward) |
255 | | - |
256 | | - |
257 | | -def calculate_points_based_rewards( |
258 | | - total_reward: int, |
259 | | - points: Dict[ChecksumAddress, int], |
260 | | - total_points: int, |
261 | | - reward_token: ChecksumAddress, |
262 | | -) -> Rewards: |
263 | | - """Calculates points based rewards.""" |
264 | | - if total_reward <= 0 or total_points <= 0: |
265 | | - return {} |
266 | | - |
267 | | - rewards: Rewards = {} |
268 | | - last_account_index = len(points) - 1 |
269 | | - distributed = 0 |
270 | | - for i, account in enumerate(points): |
271 | | - if i == last_account_index: |
272 | | - reward = total_reward - distributed |
273 | | - else: |
274 | | - reward = (total_reward * points[account]) // total_points |
275 | | - |
276 | | - if reward <= 0: |
277 | | - continue |
278 | | - |
279 | | - DistributorRewards.add_value( |
280 | | - rewards=rewards, |
281 | | - to=account, |
282 | | - reward_token=reward_token, |
283 | | - amount=reward, |
284 | | - ) |
285 | | - distributed += reward |
286 | | - |
287 | | - return rewards |
288 | | - |
289 | | - |
290 | 190 | async def get_one_time_rewards( |
291 | 191 | network: str, |
292 | 192 | from_block: BlockNumber, |
|
0 commit comments