Skip to content

Commit 56d9540

Browse files
authored
Update operator rewards (#164)
* Update operator rewards calc Signed-off-by: cyc60 <[email protected]> * Remove partner rewards Signed-off-by: cyc60 <[email protected]> * Update operator addresses Signed-off-by: cyc60 <[email protected]> --------- Signed-off-by: cyc60 <[email protected]>
1 parent 8fed0dc commit 56d9540

File tree

6 files changed

+25
-215
lines changed

6 files changed

+25
-215
lines changed

oracle/networks.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
"0x144a98cb1CdBb23610501fE6108858D9B7D24934"
5454
),
5555
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
56-
ORACLE_STAKEWISE_OPERATOR=Web3.toChecksumAddress(
57-
"0x5fc60576b92c5ce5c341c43e3b2866eb9e0cddd1"
56+
OPERATOR_ADDRESS=Web3.toChecksumAddress(
57+
"0xf330b5fE72E91d1a3782E65eED876CF3624c7802"
5858
),
5959
WITHDRAWALS_GENESIS_EPOCH=194048,
6060
AWS_BUCKET_NAME=config("AWS_BUCKET_NAME", default="oracle-votes-mainnet"),
@@ -75,11 +75,6 @@
7575
SYNC_PERIOD=timedelta(days=1),
7676
IS_POA=False,
7777
DEPOSIT_TOKEN_SYMBOL="ETH",
78-
VALIDATORS_SPLIT={
79-
Web3.toChecksumAddress("0xfe26832d3580e0ade4813f9e60e7c17b45e92cba"): 64,
80-
Web3.toChecksumAddress("0x59ecf48345a221e0731e785ed79ed40d0a94e2a5"): 63,
81-
Web3.toChecksumAddress("0x01f26d7f195a37d368cb772ed75ef70dd29700f5"): 64,
82-
},
8378
),
8479
HARBOUR_MAINNET: dict(
8580
STAKEWISE_SUBGRAPH_URLS=config(
@@ -117,7 +112,7 @@
117112
"0x6C7692dB59FDC7A659208EEE57C2c876aE54a448"
118113
),
119114
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
120-
ORACLE_STAKEWISE_OPERATOR=EMPTY_ADDR_HEX,
115+
OPERATOR_ADDRESS=EMPTY_ADDR_HEX,
121116
WITHDRAWALS_GENESIS_EPOCH=194048,
122117
AWS_BUCKET_NAME=config(
123118
"AWS_BUCKET_NAME",
@@ -140,7 +135,6 @@
140135
SYNC_PERIOD=timedelta(days=1),
141136
IS_POA=False,
142137
DEPOSIT_TOKEN_SYMBOL="ETH",
143-
VALIDATORS_SPLIT={},
144138
),
145139
GOERLI: dict(
146140
STAKEWISE_SUBGRAPH_URLS=config(
@@ -178,7 +172,7 @@
178172
"0x1867c96601bc5fE24F685d112314B8F3Fe228D5A"
179173
),
180174
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
181-
ORACLE_STAKEWISE_OPERATOR=EMPTY_ADDR_HEX,
175+
OPERATOR_ADDRESS=EMPTY_ADDR_HEX,
182176
WITHDRAWALS_GENESIS_EPOCH=162304,
183177
AWS_BUCKET_NAME=config("AWS_BUCKET_NAME", default="oracle-votes-goerli"),
184178
AWS_REGION=config("AWS_REGION", default="eu-central-1"),
@@ -198,7 +192,6 @@
198192
SYNC_PERIOD=timedelta(hours=1),
199193
IS_POA=True,
200194
DEPOSIT_TOKEN_SYMBOL="ETH",
201-
VALIDATORS_SPLIT={},
202195
),
203196
HARBOUR_GOERLI: dict(
204197
STAKEWISE_SUBGRAPH_URLS=config(
@@ -236,7 +229,7 @@
236229
"0x66D6c253084d8d51c7CFfDb3C188A0b53D998a3d"
237230
),
238231
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
239-
ORACLE_STAKEWISE_OPERATOR=EMPTY_ADDR_HEX,
232+
OPERATOR_ADDRESS=EMPTY_ADDR_HEX,
240233
WITHDRAWALS_GENESIS_EPOCH=162304,
241234
AWS_BUCKET_NAME=config(
242235
"AWS_BUCKET_NAME",
@@ -259,7 +252,6 @@
259252
SYNC_PERIOD=timedelta(days=1),
260253
IS_POA=True,
261254
DEPOSIT_TOKEN_SYMBOL="ETH",
262-
VALIDATORS_SPLIT={},
263255
),
264256
GNOSIS_CHAIN: dict(
265257
STAKEWISE_SUBGRAPH_URLS=config(
@@ -297,7 +289,9 @@
297289
"0x8737f638E9af54e89ed9E1234dbC68B115CD169e"
298290
),
299291
ORACLE_PRIVATE_KEY=config("ORACLE_PRIVATE_KEY", default=""),
300-
ORACLE_STAKEWISE_OPERATOR=EMPTY_ADDR_HEX,
292+
OPERATOR_ADDRESS=Web3.toChecksumAddress(
293+
"0x6Da6B1EfCCb7216078B9004535941b71EeD30b0F"
294+
),
301295
WITHDRAWALS_GENESIS_EPOCH=648704,
302296
AWS_BUCKET_NAME=config("AWS_BUCKET_NAME", default="oracle-votes-gnosis"),
303297
AWS_REGION=config("AWS_REGION", default="eu-north-1"),
@@ -317,9 +311,5 @@
317311
SYNC_PERIOD=timedelta(days=1),
318312
IS_POA=True,
319313
DEPOSIT_TOKEN_SYMBOL="GNO",
320-
VALIDATORS_SPLIT={
321-
Web3.toChecksumAddress("0x59ecf48345a221e0731e785ed79ed40d0a94e2a5"): 4971,
322-
Web3.toChecksumAddress("0xf37c8f35fc820354b402054699610c098559ae44"): 4971,
323-
},
324314
),
325315
}

oracle/oracle/common/graphql_queries.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -341,31 +341,3 @@
341341
}
342342
"""
343343
)
344-
345-
OPERATORS_REWARDS_QUERY = gql(
346-
"""
347-
query getOperatorsRewards($block_number: Int) {
348-
operators(block: { number: $block_number }) {
349-
id
350-
validatorsCount
351-
revenueShare
352-
distributorPoints
353-
updatedAtBlock
354-
}
355-
}
356-
"""
357-
)
358-
359-
PARTNERS_QUERY = gql(
360-
"""
361-
query getPartners($block_number: Int) {
362-
partners(block: { number: $block_number }) {
363-
id
364-
contributedAmount
365-
revenueShare
366-
distributorPoints
367-
updatedAtBlock
368-
}
369-
}
370-
"""
371-
)

oracle/oracle/distributor/common/eth1.py

Lines changed: 12 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
DISABLED_STAKER_ACCOUNTS_QUERY,
1515
DISTRIBUTOR_CLAIMED_ACCOUNTS_QUERY,
1616
ONE_TIME_DISTRIBUTIONS_QUERY,
17-
OPERATORS_REWARDS_QUERY,
18-
PARTNERS_QUERY,
1917
PERIODIC_DISTRIBUTIONS_QUERY,
2018
)
2119
from oracle.oracle.distributor.common.ipfs import get_one_time_rewards_allocations
@@ -162,171 +160,31 @@ async def get_distributor_claimed_accounts(
162160

163161

164162
async def get_operators_rewards(
165-
network: str,
166-
from_block: BlockNumber,
167-
to_block: BlockNumber,
168163
total_reward: Wei,
164+
operator_address: ChecksumAddress,
169165
reward_token_address: ChecksumAddress,
170-
validators_split: dict,
171166
) -> 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")
213170
return {}, total_reward
214171

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+
219174
if operators_reward <= 0:
220175
return {}, total_reward
221176

222177
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
287178

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,
293183
reward_token=reward_token_address,
184+
amount=operators_reward,
294185
)
295186

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)
330188

331189

332190
async def get_one_time_rewards(

oracle/oracle/distributor/controller.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
get_distributor_claimed_accounts,
1515
get_one_time_rewards,
1616
get_operators_rewards,
17-
get_partners_rewards,
1817
get_periodic_allocations,
1918
)
2019
from oracle.oracle.distributor.common.merkle_tree import calculate_merkle_root
@@ -163,20 +162,11 @@ async def process(self, voting_params: DistributorVotingParameters) -> None:
163162

164163
protocol_reward = voting_params["protocol_reward"]
165164
operators_rewards, left_reward = await get_operators_rewards(
166-
network=NETWORK,
167-
from_block=from_block,
168-
to_block=to_block,
169165
total_reward=protocol_reward,
170166
reward_token_address=NETWORK_CONFIG["REWARD_TOKEN_CONTRACT_ADDRESS"],
171-
validators_split=NETWORK_CONFIG["VALIDATORS_SPLIT"],
172-
)
173-
partners_rewards, left_reward = await get_partners_rewards(
174-
network=NETWORK,
175-
from_block=from_block,
176-
to_block=to_block,
177-
total_reward=left_reward,
178-
reward_token_address=NETWORK_CONFIG["REWARD_TOKEN_CONTRACT_ADDRESS"],
167+
operator_address=NETWORK_CONFIG["OPERATOR_ADDRESS"],
179168
)
169+
180170
if left_reward > 0:
181171
fallback_rewards: Rewards = {
182172
self.distributor_fallback_address: {
@@ -188,7 +178,7 @@ async def process(self, voting_params: DistributorVotingParameters) -> None:
188178
rewards2=fallback_rewards,
189179
)
190180

191-
for rewards in [operators_rewards, partners_rewards]:
181+
for rewards in [operators_rewards]:
192182
final_rewards = DistributorRewards.merge_rewards(final_rewards, rewards)
193183

194184
# merge final rewards with unclaimed rewards

oracle/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
IPFS_FETCH_ENDPOINTS = config(
3535
"IPFS_FETCH_ENDPOINTS",
3636
cast=Csv(),
37-
default="http://cloudflare-ipfs.com,https://ipfs.io,https://gateway.pinata.cloud",
37+
default="https://ipfs.io,https://gateway.pinata.cloud",
3838
)
3939

4040
LOCAL_IPFS_CLIENT_ENDPOINT = config("LOCAL_IPFS_CLIENT_ENDPOINT", default="")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "oracle"
3-
version = "3.3.1"
3+
version = "3.4.0"
44
description = "StakeWise Oracles are responsible for submitting off-chain data."
55
authors = ["Dmitri Tsumak <[email protected]>"]
66
license = "AGPL-3.0-only"

0 commit comments

Comments
 (0)