MagnaSim1.py 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #! /usr/bin/env python3
  2. import math
  3. import numpy as np
  4. import pandas as pd
  5. import copy
  6. class Populations:
  7. """
  8. This class is made of a pd.Series of the clients and the operation that
  9. can be made on the population.
  10. """
  11. def __init__(self, carac):
  12. """
  13. Population constructor, initialises the client population with
  14. the caracterictic given to it.
  15. """
  16. self.CONFIG_TOKEN = {"BTC":(1,0,0),"ETH":(0,1,0),"MGN":(0,0,1)\
  17. ,"BTC/ETH":(1,1,0),"ETH/MGN":(0,1,1),"MGN/BTC":(1,0,1)\
  18. ,"B/E/M":(1,1,1)}
  19. self.population = pd.Series()
  20. self.nmbr = copy.deepcopy(carac)
  21. for token in self.CONFIG_TOKEN:
  22. self.add_client(self.nmbr[token], self.CONFIG_TOKEN[token])
  23. """
  24. We have to define more caracteristics. We will start with a
  25. simple serie of inds and their number
  26. """
  27. return
  28. def add_client(self, nb,token_usage):#Need to add an arg "habits"
  29. """
  30. Add 'nb' clients to the population.
  31. """
  32. start = len(self.population)
  33. end = start + nb
  34. inds = []
  35. for i in range(nb):
  36. inds.append(Individu(token_usage))
  37. self.population = self.population.append(pd.Series(inds, index=range(start, end)))
  38. #self.nmbr += nb
  39. return
  40. class Individu: #tout OK
  41. """
  42. This class define the clients, it's caracteristics being :
  43. - User habits :
  44. - The habits with the Magna Wallet and the 3 tokens :
  45. -self.magna_wallet_btc
  46. -self.magna_wallet_eth
  47. -self.magna_wallet_mgn
  48. They containe statisctical law of the user habits.
  49. The methods of this class operate on only one client.
  50. """
  51. def __init__(self,token_usage):#OK
  52. """
  53. Constructeur d'une instance 'individu'.
  54. Ce constructeur fait appel aux fonction especes et aleatoire
  55. pour initialisé les variables d'un individu aux valeurs propres
  56. à son espèce.
  57. """
  58. # Those 3 caracteristic are the users habits concerning the client
  59. # use of Magna Wallet
  60. if token_usage[0] == 0:
  61. self.magna_wallet_btc = (0, 0)
  62. else:
  63. self.magna_wallet_btc = (
  64. np.random.normal(
  65. loc=0.00001, scale=0.002),
  66. abs(np.random.normal(
  67. loc=0.002, scale=0.01))
  68. )
  69. if token_usage[1] == 0:
  70. self.magna_wallet_eth = (0, 0)
  71. else :
  72. self.magna_wallet_eth = (
  73. np.random.normal(
  74. loc=0.01, scale=0.9),
  75. abs(np.random.normal(
  76. loc=0.5, scale=5))
  77. )
  78. if token_usage[2] == 0:
  79. self.magna_wallet_mgn = (0, 0)
  80. else:
  81. self.magna_wallet_mgn = (
  82. np.random.normal(
  83. loc=1, scale=10),
  84. abs(np.random.normal(
  85. loc=10, scale=50))
  86. )
  87. return
  88. class Transaction:
  89. """
  90. This class keeps track of the transactions
  91. """
  92. def __init__(self):
  93. self.btc=0
  94. self.eth=0
  95. self.mgn=0
  96. return
  97. def fees_btc(nbr_transaction_btc):
  98. """
  99. Cette fonction calcule une version simplifié des frais de transaction
  100. """
  101. # Dans un premier temps je vais prendre pour valeur pour valeur de transfere :
  102. # 20sat/byte
  103. # On simplifie aussi en considerant qu'on a 1 input et 1 output
  104. fees_btc = (nbr_transaction_btc*180 + 40 + nbr_transaction_btc)*20
  105. return fees_btc
  106. def fees_eth(nbr_transaction_eth):
  107. """
  108. Cette fonction est destinee a calculer les frais de transaction en ETH
  109. La premiere approximation faire est de considerer toutes les transactions
  110. comme de simple transfere.
  111. On fixe donc la valeur d'un transfert simple 21 000 gas et 20Gwei/gas
  112. """
  113. gwei_per_gas = 20
  114. gas = 21000*nbr_transaction_eth
  115. fees_eth = gas*20
  116. return fees_eth
  117. def fees_mgn(nbr_transaction_mgn):
  118. """
  119. Cette fonction calcule le cout de transfère des tokens magna
  120. basés sur Stellar.
  121. There are two special values used to calculate fees:
  122. The base fee (currently 100 stroops) is used in transaction fees.
  123. The base reserve (currently 0.5 XLM) is used in minimum account balances.
  124. 100 stroops (0.00001 XLM)
  125. """
  126. fees_mgn = nbr_transaction_mgn*100
  127. return fees_mgn