Skip to content

Commit

Permalink
Update operator rewards calc
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 8fed0dc commit 012ba19
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 88 deletions.
22 changes: 5 additions & 17 deletions oracle/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"0x144a98cb1CdBb23610501fE6108858D9B7D24934"
),
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
ORACLE_STAKEWISE_OPERATOR=Web3.toChecksumAddress(
OPERATOR_ADDRESS=Web3.toChecksumAddress(
"0x5fc60576b92c5ce5c341c43e3b2866eb9e0cddd1"
),
WITHDRAWALS_GENESIS_EPOCH=194048,
Expand All @@ -75,11 +75,6 @@
SYNC_PERIOD=timedelta(days=1),
IS_POA=False,
DEPOSIT_TOKEN_SYMBOL="ETH",
VALIDATORS_SPLIT={
Web3.toChecksumAddress("0xfe26832d3580e0ade4813f9e60e7c17b45e92cba"): 64,
Web3.toChecksumAddress("0x59ecf48345a221e0731e785ed79ed40d0a94e2a5"): 63,
Web3.toChecksumAddress("0x01f26d7f195a37d368cb772ed75ef70dd29700f5"): 64,
},
),
HARBOUR_MAINNET: dict(
STAKEWISE_SUBGRAPH_URLS=config(
Expand Down Expand Up @@ -117,7 +112,7 @@
"0x6C7692dB59FDC7A659208EEE57C2c876aE54a448"
),
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
ORACLE_STAKEWISE_OPERATOR=EMPTY_ADDR_HEX,
OPERATOR_ADDRESS=EMPTY_ADDR_HEX,
WITHDRAWALS_GENESIS_EPOCH=194048,
AWS_BUCKET_NAME=config(
"AWS_BUCKET_NAME",
Expand All @@ -140,7 +135,6 @@
SYNC_PERIOD=timedelta(days=1),
IS_POA=False,
DEPOSIT_TOKEN_SYMBOL="ETH",
VALIDATORS_SPLIT={},
),
GOERLI: dict(
STAKEWISE_SUBGRAPH_URLS=config(
Expand Down Expand Up @@ -178,7 +172,7 @@
"0x1867c96601bc5fE24F685d112314B8F3Fe228D5A"
),
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
ORACLE_STAKEWISE_OPERATOR=EMPTY_ADDR_HEX,
OPERATOR_ADDRESS=EMPTY_ADDR_HEX,
WITHDRAWALS_GENESIS_EPOCH=162304,
AWS_BUCKET_NAME=config("AWS_BUCKET_NAME", default="oracle-votes-goerli"),
AWS_REGION=config("AWS_REGION", default="eu-central-1"),
Expand All @@ -198,7 +192,6 @@
SYNC_PERIOD=timedelta(hours=1),
IS_POA=True,
DEPOSIT_TOKEN_SYMBOL="ETH",
VALIDATORS_SPLIT={},
),
HARBOUR_GOERLI: dict(
STAKEWISE_SUBGRAPH_URLS=config(
Expand Down Expand Up @@ -236,7 +229,7 @@
"0x66D6c253084d8d51c7CFfDb3C188A0b53D998a3d"
),
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
ORACLE_STAKEWISE_OPERATOR=EMPTY_ADDR_HEX,
OPERATOR_ADDRESS=EMPTY_ADDR_HEX,
WITHDRAWALS_GENESIS_EPOCH=162304,
AWS_BUCKET_NAME=config(
"AWS_BUCKET_NAME",
Expand All @@ -259,7 +252,6 @@
SYNC_PERIOD=timedelta(days=1),
IS_POA=True,
DEPOSIT_TOKEN_SYMBOL="ETH",
VALIDATORS_SPLIT={},
),
GNOSIS_CHAIN: dict(
STAKEWISE_SUBGRAPH_URLS=config(
Expand Down Expand Up @@ -297,7 +289,7 @@
"0x8737f638E9af54e89ed9E1234dbC68B115CD169e"
),
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
ORACLE_STAKEWISE_OPERATOR=EMPTY_ADDR_HEX,
OPERATOR_ADDRESS=EMPTY_ADDR_HEX,
WITHDRAWALS_GENESIS_EPOCH=648704,
AWS_BUCKET_NAME=config("AWS_BUCKET_NAME", default="oracle-votes-gnosis"),
AWS_REGION=config("AWS_REGION", default="eu-north-1"),
Expand All @@ -317,9 +309,5 @@
SYNC_PERIOD=timedelta(days=1),
IS_POA=True,
DEPOSIT_TOKEN_SYMBOL="GNO",
VALIDATORS_SPLIT={
Web3.toChecksumAddress("0x59ecf48345a221e0731e785ed79ed40d0a94e2a5"): 4971,
Web3.toChecksumAddress("0xf37c8f35fc820354b402054699610c098559ae44"): 4971,
},
),
}
13 changes: 0 additions & 13 deletions oracle/oracle/common/graphql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,19 +342,6 @@
"""
)

OPERATORS_REWARDS_QUERY = gql(
"""
query getOperatorsRewards($block_number: Int) {
operators(block: { number: $block_number }) {
id
validatorsCount
revenueShare
distributorPoints
updatedAtBlock
}
}
"""
)

PARTNERS_QUERY = gql(
"""
Expand Down
66 changes: 12 additions & 54 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,
OPERATORS_REWARDS_QUERY,
PARTNERS_QUERY,
PERIODIC_DISTRIBUTIONS_QUERY,
)
Expand Down Expand Up @@ -162,69 +161,28 @@ async def get_distributor_claimed_accounts(


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

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

validators_count = int(operator["validatorsCount"]) + validators_split.get(
account, 0
)
total_validators += validators_count

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

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

points[account] = points.get(account, 0) + account_points
total_points += account_points

if total_validators <= 0:
"""Send half of rewards to a single operator address."""
if operator_address == EMPTY_ADDR_HEX:
logger.error("Invalid operator address")
return {}, total_reward

operators_reward = Wei(
(total_reward * total_points)
// (total_validators * 10000 * (to_block - from_block))
)
operators_reward = Wei(total_reward // 2)

if operators_reward <= 0:
return {}, total_reward

operators_reward = min(total_reward, operators_reward)
rewards = calculate_points_based_rewards(
total_reward=operators_reward,
points=points,
total_points=total_points,

rewards: Rewards = {}
DistributorRewards.add_value(
rewards=rewards,
to=operator_address,
reward_token=reward_token_address,
amount=operators_reward,
)

return rewards, Wei(total_reward - operators_reward)
Expand Down
5 changes: 1 addition & 4 deletions oracle/oracle/distributor/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,9 @@ async def process(self, voting_params: DistributorVotingParameters) -> None:

protocol_reward = voting_params["protocol_reward"]
operators_rewards, left_reward = await get_operators_rewards(
network=NETWORK,
from_block=from_block,
to_block=to_block,
total_reward=protocol_reward,
reward_token_address=NETWORK_CONFIG["REWARD_TOKEN_CONTRACT_ADDRESS"],
validators_split=NETWORK_CONFIG["VALIDATORS_SPLIT"],
operator_address=NETWORK_CONFIG["OPERATOR_ADDRESS"],
)
partners_rewards, left_reward = await get_partners_rewards(
network=NETWORK,
Expand Down

0 comments on commit 012ba19

Please sign in to comment.