|
| 1 | +import os |
| 2 | + |
| 3 | +from mypylib.mypylib import color_print |
| 4 | +from mytonctrl.modules.pool import PoolModule |
| 5 | + |
| 6 | + |
| 7 | +class NominatorPoolModule(PoolModule): |
| 8 | + |
| 9 | + def new_pool(self, args): |
| 10 | + try: |
| 11 | + pool_name = args[0] |
| 12 | + validator_reward_share_percent = float(args[1]) |
| 13 | + max_nominators_count = int(args[2]) |
| 14 | + min_validator_stake = int(args[3]) |
| 15 | + min_nominator_stake = int(args[4]) |
| 16 | + except: |
| 17 | + color_print("{red}Bad args. Usage:{endc} new_pool <pool-name> <validator-reward-share-percent> <max-nominators-count> <min-validator-stake> <min-nominator-stake>") |
| 18 | + return |
| 19 | + self.ton.CreatePool(pool_name, validator_reward_share_percent, max_nominators_count, min_validator_stake, min_nominator_stake) |
| 20 | + color_print("NewPool - {green}OK{endc}") |
| 21 | + |
| 22 | + def activate_pool(self, args): |
| 23 | + try: |
| 24 | + pool_name = args[0] |
| 25 | + except: |
| 26 | + color_print("{red}Bad args. Usage:{endc} activate_pool <pool-name>") |
| 27 | + return |
| 28 | + pool = self.ton.GetLocalPool(pool_name) |
| 29 | + if not os.path.isfile(pool.bocFilePath): |
| 30 | + self.local.add_log(f"Pool {pool_name} already activated", "warning") |
| 31 | + return |
| 32 | + self.ton.ActivatePool(pool) |
| 33 | + color_print("ActivatePool - {green}OK{endc}") |
| 34 | + |
| 35 | + def deposit_to_pool(self, args): |
| 36 | + try: |
| 37 | + poll_addr = args[0] |
| 38 | + amount = float(args[1]) |
| 39 | + except: |
| 40 | + color_print("{red}Bad args. Usage:{endc} deposit_to_pool <pool-addr> <amount>") |
| 41 | + return |
| 42 | + self.ton.DepositToPool(poll_addr, amount) |
| 43 | + color_print("DepositToPool - {green}OK{endc}") |
| 44 | + |
| 45 | + def withdraw_from_pool(self, args): |
| 46 | + try: |
| 47 | + pool_addr = args[0] |
| 48 | + amount = float(args[1]) |
| 49 | + except: |
| 50 | + color_print("{red}Bad args. Usage:{endc} withdraw_from_pool <pool-addr> <amount>") |
| 51 | + return |
| 52 | + self.ton.WithdrawFromPool(pool_addr, amount) |
| 53 | + color_print("WithdrawFromPool - {green}OK{endc}") |
| 54 | + |
| 55 | + def update_validator_set(self, args): |
| 56 | + try: |
| 57 | + pool_addr = args[0] |
| 58 | + except: |
| 59 | + color_print("{red}Bad args. Usage:{endc} update_validator_set <pool-addr>") |
| 60 | + return |
| 61 | + wallet = self.ton.GetValidatorWallet() |
| 62 | + self.ton.PoolUpdateValidatorSet(pool_addr, wallet) |
| 63 | + color_print("UpdateValidatorSet - {green}OK{endc}") |
| 64 | + |
| 65 | + def add_console_commands(self, console): |
| 66 | + console.AddItem("new_pool", self.new_pool, self.local.translate("new_pool_cmd")) |
| 67 | + console.AddItem("activate_pool", self.activate_pool, self.local.translate("activate_pool_cmd")) |
| 68 | + console.AddItem("deposit_to_pool", self.deposit_to_pool, self.local.translate("deposit_to_pool_cmd")) |
| 69 | + console.AddItem("withdraw_from_pool", self.withdraw_from_pool, self.local.translate("withdraw_from_pool_cmd")) |
| 70 | + console.AddItem("update_validator_set", self.update_validator_set, self.local.translate("update_validator_set_cmd")) |
| 71 | + |
| 72 | + |
0 commit comments