Skip to content

Commit 179a4ff

Browse files
authored
Fix rewards calculation with total fees (#113)
* Fix rewards calculation with total fees * Fix trailing space * Fix tests * Update log message
1 parent 01347d2 commit 179a4ff

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ dist
55
.idea
66
local.env
77
*.env
8-
*jwtsecret
8+
*jwtsecret

oracle/oracle/common/eth1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ async def get_voting_parameters(
113113
rewards = RewardsVotingParameters(
114114
rewards_nonce=int(network["oraclesRewardsNonce"]),
115115
total_rewards=Wei(int(reward_token["totalRewards"])),
116+
total_fees=Wei(int(reward_token["totalFees"])),
116117
rewards_updated_at_timestamp=Timestamp(int(reward_token["updatedAtTimestamp"])),
117118
)
118119
distributor = DistributorVotingParameters(

oracle/oracle/rewards/controller.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async def process(
9999
checkpoints = await get_finality_checkpoints(self.aiohttp_session)
100100

101101
state_id = str(update_epoch * self.slots_per_epoch)
102-
total_rewards: Wei = Wei(0)
102+
total_rewards: Wei = voting_params["total_fees"]
103103
activated_validators = 0
104104
chunk_size = NETWORK_CONFIG["VALIDATORS_FETCH_CHUNK_SIZE"]
105105

@@ -115,16 +115,20 @@ async def process(
115115
continue
116116

117117
activated_validators += 1
118-
total_rewards += Wei(
118+
validator_reward = (
119119
Web3.toWei(validator["balance"], "gwei") - self.deposit_amount
120120
)
121-
122-
if NETWORK == GNOSIS_CHAIN:
123-
# apply mGNO <-> GNO exchange rate
124-
total_rewards = Wei(int(total_rewards * WAD // MGNO_RATE))
121+
if NETWORK == GNOSIS_CHAIN:
122+
# apply mGNO <-> GNO exchange rate
123+
validator_reward = Wei(int(validator_reward * WAD // MGNO_RATE))
124+
total_rewards += validator_reward
125125

126126
pretty_total_rewards = self.format_ether(total_rewards)
127-
logger.info(f"Retrieved pool validator rewards: total={pretty_total_rewards}")
127+
logger.info(
128+
f"Retrieved pool validator rewards:"
129+
f" total={pretty_total_rewards},"
130+
f" fees={self.format_ether(voting_params['total_fees'])}"
131+
)
128132
if not total_rewards:
129133
logger.info("No staking rewards, waiting for validators to be activated...")
130134
return

oracle/oracle/rewards/tests/test_controller.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ async def test_process_success(self):
8282
session = aiohttp.ClientSession()
8383
rewards_nonce = faker.random_int(1000, 2000)
8484
total_rewards = faker.wei_amount()
85+
total_fees = faker.wei_amount()
86+
total_rewards += total_fees
8587

8688
controller = RewardsController(
8789
aiohttp_session=session,
@@ -92,6 +94,7 @@ async def test_process_success(self):
9294
voting_params=RewardsVotingParameters(
9395
rewards_nonce=rewards_nonce,
9496
total_rewards=total_rewards,
97+
total_fees=total_fees,
9598
rewards_updated_at_timestamp=Timestamp(1649854536),
9699
),
97100
current_block_number=BlockNumber(14583706),

oracle/oracle/rewards/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class RewardsVotingParameters(TypedDict):
88
rewards_nonce: int
99
total_rewards: Wei
10+
total_fees: Wei
1011
rewards_updated_at_timestamp: Timestamp
1112

1213

0 commit comments

Comments
 (0)