gpt is bad at math

This commit is contained in:
agatha 2024-06-03 00:14:33 -04:00
parent e93d1f93f0
commit 0c53f86049

View File

@ -5,8 +5,8 @@ getcontext().prec = 28
class StakingContract: class StakingContract:
def __init__(self): def __init__(self):
self.rewards_pct = Decimal('0.6') self.rewards_pct = Decimal('0.7')
self.community_pct = Decimal('0.3') self.community_pct = Decimal('0.2')
self.developer_pct = Decimal('0.1') self.developer_pct = Decimal('0.1')
self.balances = { self.balances = {
@ -21,7 +21,7 @@ class StakingContract:
def deposit(self, user: str, amount: float): def deposit(self, user: str, amount: float):
amount = Decimal(amount) # Convert to Decimal amount = Decimal(amount) # Convert to Decimal
stake, reward, community, developer = self.calc_fee(amount) 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_fees_to_balances(stake, reward, community, developer)
self.add_stake_to_user(user, stake) self.add_stake_to_user(user, stake)
@ -39,13 +39,34 @@ class StakingContract:
self.balances['reward'] -= reward_share self.balances['reward'] -= reward_share
# Reset user stake to 0 # Reset user stake to 0
self.users[user] = Decimal('0.0') del self.users[user]
# Total amount returned to the user # Total amount returned to the user
total_withdrawal = initial_stake + reward_share 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 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): def calculate_reward_share(self, user):
total_stakes = sum(self.users.values()) total_stakes = sum(self.users.values())
if total_stakes == 0: # Avoid division by zero if total_stakes == 0: # Avoid division by zero
@ -90,23 +111,53 @@ class StakingContract:
def main(): def main():
pool = StakingContract() pool = StakingContract()
pool.deposit("owner", 1) pool.deposit("owner", 50000)
pool.deposit("user5", 1000000) pool.deposit("user1", 50000)
pool.deposit("user1", 1000) pool.deposit("user2", 50000)
pool.deposit("user2", 200000)
pool.deposit("user3", 90283)
pool.deposit("user4", 1000)
pool.show_stats() pool.show_stats()
pool.withdraw("user1") pool.withdraw("user1")
pool.withdraw("user2") pool.withdraw("user2")
pool.withdraw("user3")
pool.withdraw("user4")
pool.withdraw("user5")
pool.withdraw("owner") pool.withdraw("owner")
pool.show_stats() 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__': if __name__ == '__main__':
main() main()