| 
14 | 14 |     DISABLED_STAKER_ACCOUNTS_QUERY,  | 
15 | 15 |     DISTRIBUTOR_CLAIMED_ACCOUNTS_QUERY,  | 
16 | 16 |     ONE_TIME_DISTRIBUTIONS_QUERY,  | 
17 |  | -    OPERATORS_REWARDS_QUERY,  | 
18 |  | -    PARTNERS_QUERY,  | 
19 | 17 |     PERIODIC_DISTRIBUTIONS_QUERY,  | 
20 | 18 | )  | 
21 | 19 | from oracle.oracle.distributor.common.ipfs import get_one_time_rewards_allocations  | 
@@ -162,171 +160,31 @@ async def get_distributor_claimed_accounts(  | 
162 | 160 | 
 
  | 
163 | 161 | 
 
  | 
164 | 162 | async def get_operators_rewards(  | 
165 |  | -    network: str,  | 
166 |  | -    from_block: BlockNumber,  | 
167 |  | -    to_block: BlockNumber,  | 
168 | 163 |     total_reward: Wei,  | 
 | 164 | +    operator_address: ChecksumAddress,  | 
169 | 165 |     reward_token_address: ChecksumAddress,  | 
170 |  | -    validators_split: dict,  | 
171 | 166 | ) -> Tuple[Rewards, Wei]:  | 
172 |  | -    """Fetches operators rewards."""  | 
173 |  | -    result: Dict = await execute_sw_gql_query(  | 
174 |  | -        network=network,  | 
175 |  | -        query=OPERATORS_REWARDS_QUERY,  | 
176 |  | -        variables=dict(  | 
177 |  | -            block_number=to_block,  | 
178 |  | -        ),  | 
179 |  | -    )  | 
180 |  | -    operators = result["operators"]  | 
181 |  | - | 
182 |  | -    # process operators  | 
183 |  | -    points: Dict[ChecksumAddress, int] = {}  | 
184 |  | -    total_points = 0  | 
185 |  | -    total_validators = 0  | 
186 |  | -    for operator in operators:  | 
187 |  | -        account = Web3.toChecksumAddress(operator["id"])  | 
188 |  | -        if account == EMPTY_ADDR_HEX:  | 
189 |  | -            continue  | 
190 |  | - | 
191 |  | -        validators_count = int(operator["validatorsCount"]) + validators_split.get(  | 
192 |  | -            account, 0  | 
193 |  | -        )  | 
194 |  | -        total_validators += validators_count  | 
195 |  | - | 
196 |  | -        revenue_share = int(operator["revenueShare"])  | 
197 |  | -        prev_account_points = int(operator["distributorPoints"])  | 
198 |  | -        updated_at_block = BlockNumber(int(operator["updatedAtBlock"]))  | 
199 |  | -        if from_block > updated_at_block:  | 
200 |  | -            updated_at_block = from_block  | 
201 |  | -            prev_account_points = 0  | 
202 |  | - | 
203 |  | -        account_points = prev_account_points + (  | 
204 |  | -            validators_count * revenue_share * (to_block - updated_at_block)  | 
205 |  | -        )  | 
206 |  | -        if account_points <= 0:  | 
207 |  | -            continue  | 
208 |  | - | 
209 |  | -        points[account] = points.get(account, 0) + account_points  | 
210 |  | -        total_points += account_points  | 
211 |  | - | 
212 |  | -    if total_validators <= 0:  | 
 | 167 | +    """Send half of rewards to a single operator address."""  | 
 | 168 | +    if operator_address == EMPTY_ADDR_HEX:  | 
 | 169 | +        logger.error("Invalid operator address")  | 
213 | 170 |         return {}, total_reward  | 
214 | 171 | 
 
  | 
215 |  | -    operators_reward = Wei(  | 
216 |  | -        (total_reward * total_points)  | 
217 |  | -        // (total_validators * 10000 * (to_block - from_block))  | 
218 |  | -    )  | 
 | 172 | +    operators_reward = Wei(total_reward // 2)  | 
 | 173 | + | 
219 | 174 |     if operators_reward <= 0:  | 
220 | 175 |         return {}, total_reward  | 
221 | 176 | 
 
  | 
222 | 177 |     operators_reward = min(total_reward, operators_reward)  | 
223 |  | -    rewards = calculate_points_based_rewards(  | 
224 |  | -        total_reward=operators_reward,  | 
225 |  | -        points=points,  | 
226 |  | -        total_points=total_points,  | 
227 |  | -        reward_token=reward_token_address,  | 
228 |  | -    )  | 
229 |  | - | 
230 |  | -    return rewards, Wei(total_reward - operators_reward)  | 
231 |  | - | 
232 |  | - | 
233 |  | -async def get_partners_rewards(  | 
234 |  | -    network: str,  | 
235 |  | -    from_block: BlockNumber,  | 
236 |  | -    to_block: BlockNumber,  | 
237 |  | -    total_reward: Wei,  | 
238 |  | -    reward_token_address: ChecksumAddress,  | 
239 |  | -) -> Tuple[Rewards, Wei]:  | 
240 |  | -    """Fetches partners rewards."""  | 
241 |  | -    result: Dict = await execute_sw_gql_query(  | 
242 |  | -        network=network,  | 
243 |  | -        query=PARTNERS_QUERY,  | 
244 |  | -        variables=dict(  | 
245 |  | -            block_number=to_block,  | 
246 |  | -        ),  | 
247 |  | -    )  | 
248 |  | -    partners = result["partners"]  | 
249 |  | - | 
250 |  | -    # process partners  | 
251 |  | -    points: Dict[ChecksumAddress, int] = {}  | 
252 |  | -    total_points = 0  | 
253 |  | -    total_contributed = 0  | 
254 |  | -    for partner in partners:  | 
255 |  | -        account = Web3.toChecksumAddress(partner["id"])  | 
256 |  | -        if account == EMPTY_ADDR_HEX:  | 
257 |  | -            continue  | 
258 |  | - | 
259 |  | -        contributed_amount = Wei(int(partner["contributedAmount"]))  | 
260 |  | -        total_contributed += contributed_amount  | 
261 |  | - | 
262 |  | -        revenue_share = int(partner["revenueShare"])  | 
263 |  | -        prev_account_points = int(partner["distributorPoints"])  | 
264 |  | -        updated_at_block = BlockNumber(int(partner["updatedAtBlock"]))  | 
265 |  | -        if from_block > updated_at_block:  | 
266 |  | -            updated_at_block = from_block  | 
267 |  | -            prev_account_points = 0  | 
268 |  | - | 
269 |  | -        account_points = prev_account_points + (  | 
270 |  | -            contributed_amount * revenue_share * (to_block - updated_at_block)  | 
271 |  | -        )  | 
272 |  | -        if account_points <= 0:  | 
273 |  | -            continue  | 
274 |  | - | 
275 |  | -        points[account] = account_points  | 
276 |  | -        total_points += account_points  | 
277 |  | - | 
278 |  | -    if total_contributed <= 0:  | 
279 |  | -        return {}, total_reward  | 
280 |  | - | 
281 |  | -    partners_reward = Wei(  | 
282 |  | -        (total_reward * total_points)  | 
283 |  | -        // (total_contributed * 10000 * (to_block - from_block))  | 
284 |  | -    )  | 
285 |  | -    if partners_reward <= 0:  | 
286 |  | -        return {}, total_reward  | 
287 | 178 | 
 
  | 
288 |  | -    partners_reward = min(total_reward, partners_reward)  | 
289 |  | -    rewards = calculate_points_based_rewards(  | 
290 |  | -        total_reward=partners_reward,  | 
291 |  | -        points=points,  | 
292 |  | -        total_points=total_points,  | 
 | 179 | +    rewards: Rewards = {}  | 
 | 180 | +    DistributorRewards.add_value(  | 
 | 181 | +        rewards=rewards,  | 
 | 182 | +        to=operator_address,  | 
293 | 183 |         reward_token=reward_token_address,  | 
 | 184 | +        amount=operators_reward,  | 
294 | 185 |     )  | 
295 | 186 | 
 
  | 
296 |  | -    return rewards, Wei(total_reward - partners_reward)  | 
297 |  | - | 
298 |  | - | 
299 |  | -def calculate_points_based_rewards(  | 
300 |  | -    total_reward: int,  | 
301 |  | -    points: Dict[ChecksumAddress, int],  | 
302 |  | -    total_points: int,  | 
303 |  | -    reward_token: ChecksumAddress,  | 
304 |  | -) -> Rewards:  | 
305 |  | -    """Calculates points based rewards."""  | 
306 |  | -    if total_reward <= 0 or total_points <= 0:  | 
307 |  | -        return {}  | 
308 |  | - | 
309 |  | -    rewards: Rewards = {}  | 
310 |  | -    last_account_index = len(points) - 1  | 
311 |  | -    distributed = 0  | 
312 |  | -    for i, account in enumerate(points):  | 
313 |  | -        if i == last_account_index:  | 
314 |  | -            reward = total_reward - distributed  | 
315 |  | -        else:  | 
316 |  | -            reward = (total_reward * points[account]) // total_points  | 
317 |  | - | 
318 |  | -        if reward <= 0:  | 
319 |  | -            continue  | 
320 |  | - | 
321 |  | -        DistributorRewards.add_value(  | 
322 |  | -            rewards=rewards,  | 
323 |  | -            to=account,  | 
324 |  | -            reward_token=reward_token,  | 
325 |  | -            amount=reward,  | 
326 |  | -        )  | 
327 |  | -        distributed += reward  | 
328 |  | - | 
329 |  | -    return rewards  | 
 | 187 | +    return rewards, Wei(total_reward - operators_reward)  | 
330 | 188 | 
 
  | 
331 | 189 | 
 
  | 
332 | 190 | async def get_one_time_rewards(  | 
 | 
0 commit comments