Skip to content

Commit

Permalink
Remove partner rewards
Browse files Browse the repository at this point in the history
Signed-off-by: cyc60 <[email protected]>
  • Loading branch information
cyc60 committed Nov 25, 2024
1 parent 012ba19 commit cddb9b2
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 126 deletions.
15 changes: 0 additions & 15 deletions oracle/oracle/common/graphql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,3 @@
}
"""
)


PARTNERS_QUERY = gql(
"""
query getPartners($block_number: Int) {
partners(block: { number: $block_number }) {
id
contributedAmount
revenueShare
distributorPoints
updatedAtBlock
}
}
"""
)
100 changes: 0 additions & 100 deletions oracle/oracle/distributor/common/eth1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
DISABLED_STAKER_ACCOUNTS_QUERY,
DISTRIBUTOR_CLAIMED_ACCOUNTS_QUERY,
ONE_TIME_DISTRIBUTIONS_QUERY,
PARTNERS_QUERY,
PERIODIC_DISTRIBUTIONS_QUERY,
)
from oracle.oracle.distributor.common.ipfs import get_one_time_rewards_allocations
Expand Down Expand Up @@ -188,105 +187,6 @@ async def get_operators_rewards(
return rewards, Wei(total_reward - operators_reward)


async def get_partners_rewards(
network: str,
from_block: BlockNumber,
to_block: BlockNumber,
total_reward: Wei,
reward_token_address: ChecksumAddress,
) -> Tuple[Rewards, Wei]:
"""Fetches partners rewards."""
result: Dict = await execute_sw_gql_query(
network=network,
query=PARTNERS_QUERY,
variables=dict(
block_number=to_block,
),
)
partners = result["partners"]

# process partners
points: Dict[ChecksumAddress, int] = {}
total_points = 0
total_contributed = 0
for partner in partners:
account = Web3.toChecksumAddress(partner["id"])
if account == EMPTY_ADDR_HEX:
continue

contributed_amount = Wei(int(partner["contributedAmount"]))
total_contributed += contributed_amount

revenue_share = int(partner["revenueShare"])
prev_account_points = int(partner["distributorPoints"])
updated_at_block = BlockNumber(int(partner["updatedAtBlock"]))
if from_block > updated_at_block:
updated_at_block = from_block
prev_account_points = 0

account_points = prev_account_points + (
contributed_amount * revenue_share * (to_block - updated_at_block)
)
if account_points <= 0:
continue

points[account] = account_points
total_points += account_points

if total_contributed <= 0:
return {}, total_reward

partners_reward = Wei(
(total_reward * total_points)
// (total_contributed * 10000 * (to_block - from_block))
)
if partners_reward <= 0:
return {}, total_reward

partners_reward = min(total_reward, partners_reward)
rewards = calculate_points_based_rewards(
total_reward=partners_reward,
points=points,
total_points=total_points,
reward_token=reward_token_address,
)

return rewards, Wei(total_reward - partners_reward)


def calculate_points_based_rewards(
total_reward: int,
points: Dict[ChecksumAddress, int],
total_points: int,
reward_token: ChecksumAddress,
) -> Rewards:
"""Calculates points based rewards."""
if total_reward <= 0 or total_points <= 0:
return {}

rewards: Rewards = {}
last_account_index = len(points) - 1
distributed = 0
for i, account in enumerate(points):
if i == last_account_index:
reward = total_reward - distributed
else:
reward = (total_reward * points[account]) // total_points

if reward <= 0:
continue

DistributorRewards.add_value(
rewards=rewards,
to=account,
reward_token=reward_token,
amount=reward,
)
distributed += reward

return rewards


async def get_one_time_rewards(
network: str,
from_block: BlockNumber,
Expand Down
11 changes: 2 additions & 9 deletions oracle/oracle/distributor/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
get_distributor_claimed_accounts,
get_one_time_rewards,
get_operators_rewards,
get_partners_rewards,
get_periodic_allocations,
)
from oracle.oracle.distributor.common.merkle_tree import calculate_merkle_root
Expand Down Expand Up @@ -167,13 +166,7 @@ async def process(self, voting_params: DistributorVotingParameters) -> None:
reward_token_address=NETWORK_CONFIG["REWARD_TOKEN_CONTRACT_ADDRESS"],
operator_address=NETWORK_CONFIG["OPERATOR_ADDRESS"],
)
partners_rewards, left_reward = await get_partners_rewards(
network=NETWORK,
from_block=from_block,
to_block=to_block,
total_reward=left_reward,
reward_token_address=NETWORK_CONFIG["REWARD_TOKEN_CONTRACT_ADDRESS"],
)

if left_reward > 0:
fallback_rewards: Rewards = {
self.distributor_fallback_address: {
Expand All @@ -185,7 +178,7 @@ async def process(self, voting_params: DistributorVotingParameters) -> None:
rewards2=fallback_rewards,
)

for rewards in [operators_rewards, partners_rewards]:
for rewards in [operators_rewards]:
final_rewards = DistributorRewards.merge_rewards(final_rewards, rewards)

# merge final rewards with unclaimed rewards
Expand Down
2 changes: 1 addition & 1 deletion oracle/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
IPFS_FETCH_ENDPOINTS = config(
"IPFS_FETCH_ENDPOINTS",
cast=Csv(),
default="http://cloudflare-ipfs.com,https://ipfs.io,https://gateway.pinata.cloud",
default="https://ipfs.io,https://gateway.pinata.cloud",
)

LOCAL_IPFS_CLIENT_ENDPOINT = config("LOCAL_IPFS_CLIENT_ENDPOINT", default="")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "oracle"
version = "3.3.1"
version = "3.4.0"
description = "StakeWise Oracles are responsible for submitting off-chain data."
authors = ["Dmitri Tsumak <[email protected]>"]
license = "AGPL-3.0-only"
Expand Down

0 comments on commit cddb9b2

Please sign in to comment.