Skip to content

Commit

Permalink
replace "staking balance" with "Delegating balance" across the board
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasochem committed Jun 26, 2024
1 parent 4e59753 commit 790acbb
Show file tree
Hide file tree
Showing 46 changed files with 127 additions and 127 deletions.
6 changes: 3 additions & 3 deletions src/Dexter/dexter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_dexter_balance_map(contract_id, snapshot_block, api_provider):
def process_original_delegators_map(
delegator_map, contract_id, snapshot_block, api_provider
):
contract_balance = delegator_map[contract_id]["staking_balance"]
contract_balance = delegator_map[contract_id]["delegating_balance"]
dexter_liquidity_provider_map, totalLiquidity = get_dexter_balance_map(
contract_id, snapshot_block, api_provider
)
Expand All @@ -34,10 +34,10 @@ def process_original_delegators_map(
/ totalLiquidity
)
if delegator in delegator_map:
delegator_map[delegator]["staking_balance"] += balance
delegator_map[delegator]["delegating_balance"] += balance
else:
delegator_map[delegator] = {}
delegator_map[delegator]["staking_balance"] = balance
delegator_map[delegator]["delegating_balance"] = balance
delegator_map[delegator]["current_balance"] = dexter_liquidity_provider_map[
delegator
]["current_balance"]
Expand Down
6 changes: 3 additions & 3 deletions src/blockwatch/tzpro_reward_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, nw, baking_address, tzpro_api_key):
def get_rewards_for_cycle_map(self, cycle, rewards_type):
root = self.helper.get_rewards_for_cycle(cycle)

delegate_staking_balance = root["delegate_staking_balance"]
delegate_delegating_balance = root["delegate_delegating_balance"]
num_baking_rights = root["num_baking_rights"]
delegators_balances_dict = root["delegators_balances"]
rewards_and_fees = root["rewards_and_fees"]
Expand All @@ -48,7 +48,7 @@ def get_rewards_for_cycle_map(self, cycle, rewards_type):
# https://tezos-dev.slack.com/archives/CV5NX7F2L/p1649433246273169?thread_ts=1648854391.875409&cid=CV5NX7F2L
potential_endorsement_rewards = int(
math.floor(
delegate_staking_balance
delegate_delegating_balance
* number_of_endorsements_per_cycle
/ total_active_stake
)
Expand All @@ -69,7 +69,7 @@ def get_rewards_for_cycle_map(self, cycle, rewards_type):
)

return RewardProviderModel(
delegate_staking_balance,
delegate_delegating_balance,
num_baking_rights,
potential_endorsement_rewards,
total_reward_amount,
Expand Down
10 changes: 5 additions & 5 deletions src/blockwatch/tzpro_reward_provider_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, nw, baking_address, key):

def get_rewards_for_cycle(self, cycle):
root = {
"delegate_staking_balance": 0,
"delegate_delegating_balance": 0,
"num_baking_rights": 0,
"potential_endorsement_rewards": 0,
"rewards_and_fees": 0,
Expand Down Expand Up @@ -149,11 +149,11 @@ def get_rewards_for_cycle(self, cycle):

resp = resp.json()

root["delegate_staking_balance"] = int(resp["staking_balance"])
root["delegate_delegating_balance"] = int(resp["delegating_balance"])
for delegator in resp["delegators"]:
delegator_info = {"staking_balance": 0, "current_balance": 0}
delegator_info["staking_balance"] = int(delegator["balance"])
if delegator_info["staking_balance"] > 0:
delegator_info = {"delegating_balance": 0, "current_balance": 0}
delegator_info["delegating_balance"] = int(delegator["balance"])
if delegator_info["delegating_balance"] > 0:
root["delegators_balances"][delegator["address"]] = delegator_info

#
Expand Down
10 changes: 5 additions & 5 deletions src/calc/calculate_phase0.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ def calculate(self, reward_logs=None, total_reward_amount=None):

for address, delegator_info in delegators_balance_dict.items():
# NOTE: Staking_balance is a misnomer. It should be delegated_balance now. will rename later
staking_balance = delegator_info["delegated_balance"]
delegating_balance = delegator_info["delegated_balance"]
current_balance = delegator_info["current_balance"]
originaladdress = (
delegator_info["originaladdress"]
if "originaladdress" in delegator_info
else None
)
total_delegator_balance += staking_balance
total_delegator_balance += delegating_balance

ratio = staking_balance / total_delegated_balance
ratio = delegating_balance / total_delegated_balance
reward_item = RewardLog(
address=address,
type=reward_log.TYPE_DELEGATOR,
staking_balance=staking_balance,
delegating_balance=delegating_balance,
current_balance=current_balance,
originaladdress=originaladdress,
)
Expand All @@ -69,7 +69,7 @@ def calculate(self, reward_logs=None, total_reward_amount=None):
owners_rl = RewardLog(
address=reward_log.TYPE_OWNERS_PARENT,
type=reward_log.TYPE_OWNERS_PARENT,
staking_balance=own_delegated_balance,
delegating_balance=own_delegated_balance,
current_balance=0,
)
owners_rl.ratio = 1 - ratio_sum
Expand Down
10 changes: 5 additions & 5 deletions src/calc/calculate_phase1.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ def calculate(self, reward_data0, total_amount):

# exclude requested addresses from reward list
for rl0 in reward_data0:
total_balance += rl0.staking_balance
total_balance += rl0.delegating_balance
if rl0.address in self.excluded_set:
rl0.skip(desc=BY_CONFIGURATION, phase=self.phase)
rewards.append(rl0)
total_balance_excluded += rl0.staking_balance
total_balance_excluded += rl0.delegating_balance
elif (
MIN_DELEGATION_KEY in self.excluded_set
and rl0.staking_balance < self.min_delegation_amount
and rl0.delegating_balance < self.min_delegation_amount
):
rl0.skip(desc=BY_MIN_DELEGATION, phase=self.phase)
rewards.append(rl0)
total_balance_excluded += rl0.staking_balance
total_balance_excluded += rl0.delegating_balance
else:
# ratio will be replaced with actual ratio, read below
rewards.append(rl0)
Expand All @@ -62,7 +62,7 @@ def calculate(self, reward_data0, total_amount):

# calculate new ratio using remaining balance
for rl1 in self.filterskipped(rewards):
rl1.ratio = rl1.staking_balance / new_total_balance
rl1.ratio = rl1.delegating_balance / new_total_balance
rl1.ratio1 = rl1.ratio

# total reward amount needs to be diminished at the same rate total balance diminishes
Expand Down
10 changes: 5 additions & 5 deletions src/calc/calculate_phase2.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ def calculate(self, reward_data1, total_amount):

# exclude requested addresses from reward list
for rl1 in self.filterskipped(reward_data1):
total_balance += rl1.staking_balance
total_balance += rl1.delegating_balance

if rl1.address in self.excluded_set:
rl1.skip(desc=BY_CONFIGURATION, phase=self.phase)
rewards.append(rl1)
total_balance_excluded += rl1.staking_balance
total_balance_excluded += rl1.delegating_balance
elif (
MIN_DELEGATION_KEY in self.excluded_set
and rl1.staking_balance < self.min_delegation_amount
and rl1.delegating_balance < self.min_delegation_amount
):
rl1.skip(desc=BY_MIN_DELEGATION, phase=self.phase)
rewards.append(rl1)
total_balance_excluded += rl1.staking_balance
total_balance_excluded += rl1.delegating_balance
else:
# ratio2 will be replaced with actual ratio, read below
rewards.append(rl1)
Expand All @@ -61,7 +61,7 @@ def calculate(self, reward_data1, total_amount):

# calculate new ratio using remaining balance
for rl2 in self.filterskipped(rewards):
rl2.ratio = rl2.staking_balance / new_total_balance
rl2.ratio = rl2.delegating_balance / new_total_balance
rl2.ratio2 = rl2.ratio

# total reward amount remains the same
Expand Down
4 changes: 2 additions & 2 deletions src/calc/calculate_phase3.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def calculate(self, reward_data2, total_amount):
total_excluded_ratio += rl2.ratio
elif (
MIN_DELEGATION_KEY in self.excluded_set
and rl2.staking_balance < self.min_delegation_amount
and rl2.delegating_balance < self.min_delegation_amount
):
rl2.skip(desc=BY_MIN_DELEGATION, phase=self.phase)
new_rewards.append(rl2)
Expand All @@ -67,7 +67,7 @@ def calculate(self, reward_data2, total_amount):
rl = RewardLog(
address=TYPE_FOUNDERS_PARENT,
type=TYPE_FOUNDERS_PARENT,
staking_balance=0,
delegating_balance=0,
current_balance=0,
)
rl.service_fee_rate = 0
Expand Down
2 changes: 1 addition & 1 deletion src/calc/calculate_phase4.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def calculate(self, reward_data3, total_amount):

elif rl3.type == TYPE_OWNERS_PARENT:
for addr, ratio in self.owners_map.items():
rl4 = RewardLog(addr, TYPE_OWNER, ratio * rl3.staking_balance, 0)
rl4 = RewardLog(addr, TYPE_OWNER, ratio * rl3.delegating_balance, 0)
# new ratio is parent ratio * ratio of the owner
rl4.ratio = ratio * rl3.ratio
rl4.ratio4 = rl4.ratio
Expand Down
4 changes: 2 additions & 2 deletions src/calc/calculate_phaseMerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def calculate(self, reward_logs):

for addr, rl_list in payment_address_list_dict.items():
if len(rl_list) > 1:
total_staking_balance = sum([rl.staking_balance for rl in rl_list])
total_delegating_balance = sum([rl.delegating_balance for rl in rl_list])
total_current_balance = sum([rl.current_balance for rl in rl_list])
total_ratio = sum([rl.ratio for rl in rl_list])
total_payment_amount = sum([rl.amount for rl in rl_list])
Expand All @@ -45,7 +45,7 @@ def calculate(self, reward_logs):
total_service_fee_ratio = sum([rl.service_fee_ratio for rl in rl_list])

merged = RewardLog(
addr, TYPE_MERGED, total_staking_balance, total_current_balance
addr, TYPE_MERGED, total_delegating_balance, total_current_balance
)
merged.ratio = total_ratio
merged.amount = total_payment_amount
Expand Down
8 changes: 4 additions & 4 deletions src/calc/phased_payment_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def calculate(self, reward_provider_model, adjustments=None, rerun=False):
return [], 0

assert reward_provider_model.external_delegated_balance + reward_provider_model.own_delegated_balance == sum(
[rl.staking_balance for rl in rwrd_logs]
[rl.delegating_balance for rl in rwrd_logs]
)
assert self.almost_equal(1, sum([rl.ratio for rl in rwrd_logs]))

Expand Down Expand Up @@ -154,11 +154,11 @@ def calculate(self, reward_provider_model, adjustments=None, rerun=False):
self.min_delegation_amnt = int(
min(
[
rl.staking_balance
rl.delegating_balance
for rl in rwrd_logs
if not rl.skipped
and rl.adjusted_amount > self.min_payment_amnt
and rl.staking_balance
and rl.delegating_balance
]
)
)
Expand All @@ -174,7 +174,7 @@ def calculate(self, reward_provider_model, adjustments=None, rerun=False):
return rwrd_logs, total_rwrd_amnt

# sort rewards according to type and balance
rwrd_logs.sort(key=lambda rl: (rl.type, -rl.staking_balance))
rwrd_logs.sort(key=lambda rl: (rl.type, -rl.delegating_balance))

# check if there is difference between sum of calculated amounts and total_rewards
total_delegator_amounts = int(
Expand Down
24 changes: 12 additions & 12 deletions src/model/reward_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

class RewardLog:
def __init__(
self, address, type, staking_balance, current_balance, originaladdress=None
self, address, type, delegating_balance, current_balance, originaladdress=None
) -> None:
super().__init__()
self.staking_balance = int(staking_balance)
self.delegating_balance = int(delegating_balance)
self.current_balance = int(current_balance)
self.address = str(address)
self.paymentaddress = str(address)
Expand Down Expand Up @@ -73,7 +73,7 @@ def __repr__(self) -> str:
self.address,
self.paymentaddress,
self.type,
self.staking_balance,
self.delegating_balance,
self.current_balance,
self.amount,
self.adjusted_amount,
Expand All @@ -86,7 +86,7 @@ def ExitInstance():
return RewardLog(
address=EXIT_PAYMENT_TYPE,
type=EXIT_PAYMENT_TYPE,
staking_balance=0,
delegating_balance=0,
current_balance=0,
)

Expand All @@ -101,14 +101,14 @@ def ExternalInstance(file_name, address, amount):
def cmp_by_skip_type_balance(rl1, rl2):
if rl1.skipped == rl2.skipped:
if rl1.type == rl2.type:
if rl1.staking_balance is None:
if rl1.delegating_balance is None:
return 1
if rl2.staking_balance is None:
if rl2.delegating_balance is None:
return -1
if rl1.staking_balance == rl2.staking_balance:
if rl1.delegating_balance == rl2.delegating_balance:
return 1
else:
return rl2.staking_balance - rl1.staking_balance
return rl2.delegating_balance - rl1.delegating_balance
else:
return types[rl2.type] - types[rl1.type]
else:
Expand All @@ -120,13 +120,13 @@ def cmp_by_skip_type_balance(rl1, rl2):

def cmp_by_type_balance(rl1, rl2):
if rl1.type == rl2.type:
if rl1.staking_balance is None:
if rl1.delegating_balance is None:
return 1
if rl2.staking_balance is None:
if rl2.delegating_balance is None:
return -1
if rl1.staking_balance == rl2.staking_balance:
if rl1.delegating_balance == rl2.delegating_balance:
return 1
else:
return rl2.staking_balance - rl1.staking_balance
return rl2.delegating_balance - rl1.delegating_balance
else:
return types[rl2.type] - types[rl1.type]
2 changes: 1 addition & 1 deletion src/pay/payment_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _consume_batch(self, payment_batch):
payment_items, self.reactivate_zeroed
)

payment_items.sort(key=lambda rl: (rl.type, -rl.staking_balance))
payment_items.sort(key=lambda rl: (rl.type, -rl.delegating_balance))

batch_payer = BatchPayer(
self.node_addr,
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def generate_payload(self, subject, message, rewards):
"paymentAddress": reward.paymentaddress,
"addressType": reward.type,
"cycle": reward.cycle,
"stakingBalance": reward.staking_balance,
"stakingBalance": reward.delegating_balance,
"ratio": reward.ratio,
"feeRatio": reward.service_fee_ratio,
"adjustedAmount": reward.adjusted_amount,
Expand Down Expand Up @@ -84,7 +84,7 @@ def cast(self, reward):
reward.paymentaddress = str(reward.paymentaddress)
reward.type = str(reward.type)
reward.cycle = int(reward.cycle)
reward.staking_balance = int(reward.staking_balance)
reward.delegating_balance = int(reward.delegating_balance)
reward.ratio = round(float(reward.ratio), 8)
reward.service_fee_ratio = round(float(reward.service_fee_ratio), 8)
reward.adjusted_amount = int(reward.adjusted_amount)
Expand Down
Loading

0 comments on commit 790acbb

Please sign in to comment.