w3sandbox/staking/stakecalc2.py

84 lines
2.2 KiB
Python
Raw Normal View History

class StakingPool:
def __init__(self):
# TODO: Add mutex
# self.mutex = None
self.fee_rate = 0.03
self.share_pct = 0.6
self.community_pct = 0.3
self.developer_pct = 0.1
self.contract_fund = 0.0
self.community_fund = 0.0
self.developer_fund = 0.0
self.user_balances = {}
def stake(self, user: str, amount: float):
# Calculate fee
2024-06-03 04:25:18 +00:00
total_fee = amount * self.fee_rate
# Distribute fee
# TODO: Handle edge case where pool has no initial users == Community funds gets the reward
# 1. Community funds
2024-06-03 04:25:18 +00:00
community_fee = total_fee * self.community_pct
# 2. Developer funds
2024-06-03 04:25:18 +00:00
developer_fee = total_fee * self.developer_pct
# 3. Reward stakers
2024-06-03 04:25:18 +00:00
reward_amount = total_fee - community_fee - developer_fee
self.__distribute_reward(reward_amount)
2024-06-03 04:21:21 +00:00
# Deposit amount minus fee to contract_fund (wallet)
# Update user_balances with deposit amount
2024-06-03 04:25:18 +00:00
if user not in self.user_balances:
self.user_balances[user] = amount - total_fee
else:
self.user_balances[user] += amount - total_fee
def unstake(self, user: str):
# Fetch amount from user_balances
# Remove user from pool to prevent self-reward leaving a hanging balance
# Calculate fee
# Distribute fee
# TODO: User needs to be removed from the pool first to avoid hanging balances after rewarding stakers
# 1. Community funds
# 2. Developer funds
# 3. Reward stakers
2024-06-03 04:21:21 +00:00
# Transfer tokens from contract_funds (wallet) to user's wallet address
pass
def dev_withdrawal(self, destination: str, amount: float):
pass
def community_withdrawal(self, destination: str, amount: float):
pass
def __distribute_reward(self, amount):
# # # #
# Lock user_balances mutex
# # # #
# Get total staked amount
# Determine distribution amongst users
# Update self.user_balances
# # # #
# Unlock user_balances mutex
# # # #
pass
def main():
pass
if __name__ == '__main__':
main()