diff --git a/staking/gpt.py b/staking/gpt.py index aff5248..ea1da13 100644 --- a/staking/gpt.py +++ b/staking/gpt.py @@ -5,8 +5,8 @@ getcontext().prec = 28 class StakingContract: def __init__(self): - self.rewards_pct = Decimal('0.6') - self.community_pct = Decimal('0.3') + self.rewards_pct = Decimal('0.7') + self.community_pct = Decimal('0.2') self.developer_pct = Decimal('0.1') self.balances = { @@ -21,7 +21,7 @@ class StakingContract: def deposit(self, user: str, amount: float): amount = Decimal(amount) # Convert to Decimal stake, reward, community, developer = self.calc_fee(amount) - print(f'User {user} staked {amount} ($JENNER)') + print(f'{user} staked {amount} ($JENNER)') self.add_fees_to_balances(stake, reward, community, developer) self.add_stake_to_user(user, stake) @@ -39,13 +39,34 @@ class StakingContract: self.balances['reward'] -= reward_share # Reset user stake to 0 - self.users[user] = Decimal('0.0') + del self.users[user] # Total amount returned to the user total_withdrawal = initial_stake + reward_share - print(f'User {user} withdrew {total_withdrawal} ($JENNER)') + print(f'{user} withdrew {total_withdrawal:.4f} ($JENNER) - (reward: {reward_share:.4f})') return total_withdrawal + # def withdraw(self, user: str): + # if user not in self.users: + # print(f"No staked amount found for user {user}.") + # return Decimal('0.0') + # + # initial_stake = self.users[user] + # reward_share = self.calculate_reward_share(user) + # + # # Update balances + # self.balances['stakes'] -= initial_stake + # self.balances['reward'] -= reward_share + # + # # Reset user stake to 0 + # # self.users[user] = Decimal('0.0') + # del self.users[user] + # + # # Total amount returned to the user + # total_withdrawal = initial_stake + reward_share + # print(f'{user} withdrew {total_withdrawal:.4f} ($JENNER) - (reward: {reward_share:.4f})') + # return total_withdrawal + def calculate_reward_share(self, user): total_stakes = sum(self.users.values()) if total_stakes == 0: # Avoid division by zero @@ -90,23 +111,53 @@ class StakingContract: def main(): pool = StakingContract() - pool.deposit("owner", 1) - pool.deposit("user5", 1000000) - pool.deposit("user1", 1000) - pool.deposit("user2", 200000) - pool.deposit("user3", 90283) - pool.deposit("user4", 1000) + pool.deposit("owner", 50000) + pool.deposit("user1", 50000) + pool.deposit("user2", 50000) + pool.show_stats() pool.withdraw("user1") pool.withdraw("user2") - pool.withdraw("user3") - pool.withdraw("user4") - pool.withdraw("user5") pool.withdraw("owner") pool.show_stats() + # pool = StakingContract() + # + # pool.deposit("owner", 50000) + # pool.deposit("user5", 10000000) + # pool.deposit("user1", 1000) + # pool.deposit("user2", 200000) + # pool.deposit("user3", 90283) + # pool.deposit("user4", 1000) + # pool.deposit("user5", 1000000) + # pool.deposit("user6", 1000000) + # # pool.deposit("user5", 1000000) + # # pool.deposit("user5", 1000000) + # # pool.deposit("user5", 1000000) + # # + # # for n in range(200): + # # pool.deposit(f"user{n+6}", 5000) + # # + # # pool.deposit("user5", 1000000) + # + # pool.show_stats() + # + # pool.withdraw("user1") + # pool.withdraw("user2") + # pool.withdraw("user3") + # pool.withdraw("user4") + # pool.withdraw("user5") + # pool.withdraw("user6") + # # + # # for n in range(200): + # # pool.withdraw(f"user{n+6}") + # + # pool.withdraw("owner") + # + # pool.show_stats() + if __name__ == '__main__': main()