mm-sol 0.3.6__py3-none-any.whl → 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mm_sol/cli/cli.py +22 -35
- mm_sol/cli/cli_utils.py +18 -0
- mm_sol/cli/cmd/transfer_cmd.py +248 -0
- mm_sol/cli/examples/transfer.toml +23 -0
- mm_sol/cli/validators.py +4 -0
- {mm_sol-0.3.6.dist-info → mm_sol-0.4.0.dist-info}/METADATA +2 -2
- {mm_sol-0.3.6.dist-info → mm_sol-0.4.0.dist-info}/RECORD +9 -11
- mm_sol/cli/cmd/transfer_sol_cmd.py +0 -159
- mm_sol/cli/cmd/transfer_token_cmd.py +0 -188
- mm_sol/cli/examples/transfer-sol.toml +0 -9
- mm_sol/cli/examples/transfer-token.toml +0 -9
- {mm_sol-0.3.6.dist-info → mm_sol-0.4.0.dist-info}/WHEEL +0 -0
- {mm_sol-0.3.6.dist-info → mm_sol-0.4.0.dist-info}/entry_points.txt +0 -0
mm_sol/cli/cli.py
CHANGED
|
@@ -8,12 +8,15 @@ from mm_std import print_plain
|
|
|
8
8
|
from mm_sol.account import PHANTOM_DERIVATION_PATH
|
|
9
9
|
|
|
10
10
|
from . import cli_utils
|
|
11
|
-
from .cmd import balance_cmd, balances_cmd, example_cmd, node_cmd,
|
|
11
|
+
from .cmd import balance_cmd, balances_cmd, example_cmd, node_cmd, transfer_cmd
|
|
12
|
+
from .cmd.transfer_cmd import TransferCmdParams
|
|
12
13
|
from .cmd.wallet import keypair_cmd, mnemonic_cmd
|
|
13
14
|
|
|
14
15
|
app = typer.Typer(no_args_is_help=True, pretty_exceptions_enable=False, add_completion=False)
|
|
15
16
|
|
|
16
|
-
wallet_app = typer.Typer(
|
|
17
|
+
wallet_app = typer.Typer(
|
|
18
|
+
no_args_is_help=True, help="Wallet-related commands: generate new accounts, derive addresses from private keys, and more"
|
|
19
|
+
)
|
|
17
20
|
app.add_typer(wallet_app, name="wallet")
|
|
18
21
|
app.add_typer(wallet_app, name="w", hidden=True)
|
|
19
22
|
|
|
@@ -31,11 +34,10 @@ def main(_version: bool = typer.Option(None, "--version", callback=version_callb
|
|
|
31
34
|
|
|
32
35
|
class ConfigExample(str, Enum):
|
|
33
36
|
balances = "balances"
|
|
34
|
-
|
|
35
|
-
transfer_token = "transfer-token" # noqa: S105 # nosec
|
|
37
|
+
transfer = "transfer"
|
|
36
38
|
|
|
37
39
|
|
|
38
|
-
@app.command(name="example", help="
|
|
40
|
+
@app.command(name="example", help="Displays an example configuration for a command")
|
|
39
41
|
def example_command(command: Annotated[ConfigExample, typer.Argument()]) -> None:
|
|
40
42
|
example_cmd.run(command.value)
|
|
41
43
|
|
|
@@ -51,52 +53,37 @@ def balance_command(
|
|
|
51
53
|
balance_cmd.run(rpc_url, wallet_address, token_address, lamport, proxies_url)
|
|
52
54
|
|
|
53
55
|
|
|
54
|
-
@app.command(name="balances", help="
|
|
56
|
+
@app.command(name="balances", help="Displays SOL and token balances for multiple accounts")
|
|
55
57
|
def balances_command(
|
|
56
58
|
config_path: Path, print_config: Annotated[bool, typer.Option("--config", "-c", help="Print config and exit")] = False
|
|
57
59
|
) -> None:
|
|
58
60
|
balances_cmd.run(config_path, print_config)
|
|
59
61
|
|
|
60
62
|
|
|
61
|
-
@app.command(name="transfer
|
|
62
|
-
def
|
|
63
|
+
@app.command(name="transfer", help="Transfers SOL or SPL tokens, supporting multiple routes, delays, and expression-based values")
|
|
64
|
+
def transfer_command(
|
|
63
65
|
config_path: Path,
|
|
64
66
|
print_balances: bool = typer.Option(False, "--balances", "-b", help="Print balances and exit"),
|
|
65
67
|
print_config: bool = typer.Option(False, "--config", "-c", help="Print config and exit"),
|
|
68
|
+
config_verbose: bool = typer.Option(False, "--config-verbose", help="Print config in verbose mode and exit"),
|
|
66
69
|
emulate: bool = typer.Option(False, "--emulate", "-e", help="Emulate transaction posting"),
|
|
67
70
|
no_confirmation: bool = typer.Option(False, "--no-confirmation", "-nc", help="Do not wait for confirmation"),
|
|
68
71
|
debug: bool = typer.Option(False, "--debug", "-d", help="Print debug info"),
|
|
69
72
|
) -> None:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
transfer_cmd.run(
|
|
74
|
+
TransferCmdParams(
|
|
75
|
+
config_path=config_path,
|
|
76
|
+
print_balances=print_balances,
|
|
77
|
+
debug=debug,
|
|
78
|
+
no_confirmation=no_confirmation,
|
|
79
|
+
emulate=emulate,
|
|
80
|
+
print_config_and_exit=print_config or config_verbose,
|
|
81
|
+
print_config_verbose=config_verbose,
|
|
82
|
+
)
|
|
77
83
|
)
|
|
78
84
|
|
|
79
85
|
|
|
80
|
-
@app.command(name="
|
|
81
|
-
def transfer_token_command(
|
|
82
|
-
config_path: Path,
|
|
83
|
-
print_balances: bool = typer.Option(False, "--balances", "-b", help="Print balances and exit"),
|
|
84
|
-
print_config: bool = typer.Option(False, "--config", "-c", help="Print config and exit"),
|
|
85
|
-
emulate: bool = typer.Option(False, "--emulate", "-e", help="Emulate transaction posting"),
|
|
86
|
-
no_confirmation: bool = typer.Option(False, "--no-confirmation", "-nc", help="Do not wait for confirmation"),
|
|
87
|
-
debug: bool = typer.Option(False, "--debug", "-d", help="Print debug info"),
|
|
88
|
-
) -> None:
|
|
89
|
-
transfer_token_cmd.run(
|
|
90
|
-
config_path,
|
|
91
|
-
print_balances=print_balances,
|
|
92
|
-
print_config=print_config,
|
|
93
|
-
debug=debug,
|
|
94
|
-
no_confirmation=no_confirmation,
|
|
95
|
-
emulate=emulate,
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
@app.command(name="node", help="Check RPC urls")
|
|
86
|
+
@app.command(name="node", help="Checks RPC URLs for availability and status")
|
|
100
87
|
def node_command(
|
|
101
88
|
urls: Annotated[list[str], typer.Argument()],
|
|
102
89
|
proxy: Annotated[str | None, typer.Option("--proxy", "-p", help="Proxy")] = None,
|
mm_sol/cli/cli_utils.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import importlib.metadata
|
|
2
2
|
import time
|
|
3
|
+
from pathlib import Path
|
|
3
4
|
|
|
4
5
|
import mm_crypto_utils
|
|
5
6
|
from loguru import logger
|
|
6
7
|
from mm_crypto_utils import Nodes, Proxies
|
|
8
|
+
from mm_std import BaseConfig, print_json
|
|
9
|
+
from pydantic import BaseModel
|
|
7
10
|
from solders.signature import Signature
|
|
8
11
|
|
|
9
12
|
from mm_sol.utils import get_client
|
|
@@ -13,6 +16,21 @@ def get_version() -> str:
|
|
|
13
16
|
return importlib.metadata.version("mm-sol")
|
|
14
17
|
|
|
15
18
|
|
|
19
|
+
class BaseConfigParams(BaseModel):
|
|
20
|
+
config_path: Path
|
|
21
|
+
print_config_and_exit: bool
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def print_config(
|
|
25
|
+
config: BaseConfig, verbose: bool, exclude_fields: set[str] | None = None, count_fields: set[str] | None = None
|
|
26
|
+
) -> None:
|
|
27
|
+
data = config.model_dump(exclude=exclude_fields)
|
|
28
|
+
if not verbose and count_fields:
|
|
29
|
+
for k in count_fields:
|
|
30
|
+
data[k] = len(data[k])
|
|
31
|
+
print_json(data)
|
|
32
|
+
|
|
33
|
+
|
|
16
34
|
def public_rpc_url(url: str | None) -> str:
|
|
17
35
|
if not url:
|
|
18
36
|
return "https://api.mainnet-beta.solana.com"
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import time
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Annotated, Self
|
|
5
|
+
|
|
6
|
+
import mm_crypto_utils
|
|
7
|
+
from loguru import logger
|
|
8
|
+
from mm_crypto_utils import AddressToPrivate, TxRoute
|
|
9
|
+
from mm_std import BaseConfig, Err, fatal, utc_now
|
|
10
|
+
from pydantic import AfterValidator, BeforeValidator, Field, model_validator
|
|
11
|
+
from rich.live import Live
|
|
12
|
+
from rich.table import Table
|
|
13
|
+
from solders.signature import Signature
|
|
14
|
+
|
|
15
|
+
from mm_sol import transfer
|
|
16
|
+
from mm_sol.balance import get_sol_balance_with_retries, get_token_balance_with_retries
|
|
17
|
+
from mm_sol.cli import calcs, cli_utils
|
|
18
|
+
from mm_sol.cli.cli_utils import BaseConfigParams
|
|
19
|
+
from mm_sol.cli.validators import Validators
|
|
20
|
+
from mm_sol.converters import lamports_to_sol, to_token
|
|
21
|
+
from mm_sol.token import get_decimals_with_retries
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Config(BaseConfig):
|
|
25
|
+
nodes: Annotated[list[str], BeforeValidator(Validators.nodes())]
|
|
26
|
+
routes: Annotated[list[TxRoute], BeforeValidator(Validators.sol_routes())]
|
|
27
|
+
private_keys: Annotated[AddressToPrivate, BeforeValidator(Validators.sol_private_keys())]
|
|
28
|
+
proxies: Annotated[list[str], Field(default_factory=list), BeforeValidator(Validators.proxies())]
|
|
29
|
+
token: Annotated[str | None, AfterValidator(Validators.sol_address())] = None
|
|
30
|
+
token_decimals: int = -1
|
|
31
|
+
value: Annotated[str, AfterValidator(Validators.valid_sol_or_token_expression("balance"))]
|
|
32
|
+
value_min_limit: Annotated[str | None, AfterValidator(Validators.valid_sol_or_token_expression())] = None
|
|
33
|
+
delay: Annotated[str | None, AfterValidator(Validators.valid_calc_decimal_value())] = None # in seconds
|
|
34
|
+
round_ndigits: int = 5
|
|
35
|
+
log_debug: Annotated[Path | None, BeforeValidator(Validators.log_file())] = None
|
|
36
|
+
log_info: Annotated[Path | None, BeforeValidator(Validators.log_file())] = None
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def from_addresses(self) -> list[str]:
|
|
40
|
+
return [r.from_address for r in self.routes]
|
|
41
|
+
|
|
42
|
+
@model_validator(mode="after")
|
|
43
|
+
def final_validator(self) -> Self:
|
|
44
|
+
if not self.private_keys.contains_all_addresses(self.from_addresses):
|
|
45
|
+
raise ValueError("private keys are not set for all addresses")
|
|
46
|
+
|
|
47
|
+
if self.token:
|
|
48
|
+
Validators.valid_token_expression("balance")(self.value)
|
|
49
|
+
if self.value_min_limit:
|
|
50
|
+
Validators.valid_token_expression()(self.value_min_limit)
|
|
51
|
+
else:
|
|
52
|
+
Validators.valid_sol_expression("balance")(self.value)
|
|
53
|
+
if self.value_min_limit:
|
|
54
|
+
Validators.valid_sol_expression()(self.value_min_limit)
|
|
55
|
+
|
|
56
|
+
if self.token:
|
|
57
|
+
res = get_decimals_with_retries(self.nodes, self.token, retries=3, proxies=self.proxies)
|
|
58
|
+
if isinstance(res, Err):
|
|
59
|
+
fatal(f"can't get decimals for token={self.token}, error={res.err}")
|
|
60
|
+
self.token_decimals = res.ok
|
|
61
|
+
|
|
62
|
+
return self
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class TransferCmdParams(BaseConfigParams):
|
|
66
|
+
print_balances: bool
|
|
67
|
+
debug: bool
|
|
68
|
+
no_confirmation: bool
|
|
69
|
+
emulate: bool
|
|
70
|
+
print_config_verbose: bool
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def run(cmd_params: TransferCmdParams) -> None:
|
|
74
|
+
config = Config.read_toml_config_or_exit(cmd_params.config_path)
|
|
75
|
+
|
|
76
|
+
if cmd_params.print_config_and_exit:
|
|
77
|
+
cli_utils.print_config(config, cmd_params.print_config_verbose, {"private_keys"}, {"proxies"})
|
|
78
|
+
sys.exit(0)
|
|
79
|
+
|
|
80
|
+
mm_crypto_utils.init_logger(cmd_params.debug, config.log_debug, config.log_info)
|
|
81
|
+
|
|
82
|
+
if cmd_params.print_balances:
|
|
83
|
+
_print_balances(config)
|
|
84
|
+
sys.exit(0)
|
|
85
|
+
|
|
86
|
+
_run_transfers(config, cmd_params)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _run_transfers(config: Config, cmd_params: TransferCmdParams) -> None:
|
|
90
|
+
logger.info(f"transfer {cmd_params.config_path}: started at {utc_now()} UTC")
|
|
91
|
+
logger.debug(f"config={config.model_dump(exclude={'private_keys'}) | {'version': cli_utils.get_version()}}")
|
|
92
|
+
for i, route in enumerate(config.routes):
|
|
93
|
+
_transfer(route, config, cmd_params)
|
|
94
|
+
if not cmd_params.emulate and config.delay is not None and i < len(config.routes) - 1:
|
|
95
|
+
delay_value = mm_crypto_utils.calc_decimal_value(config.delay)
|
|
96
|
+
logger.debug(f"delay {delay_value} seconds")
|
|
97
|
+
time.sleep(float(delay_value))
|
|
98
|
+
logger.info(f"transfer {cmd_params.config_path}: finished at {utc_now()} UTC")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _calc_value(route: TxRoute, config: Config, transfer_sol_fee: int) -> int | None:
|
|
102
|
+
if config.token:
|
|
103
|
+
value_res = calcs.calc_token_value_for_address(
|
|
104
|
+
nodes=config.nodes,
|
|
105
|
+
value_expression=config.value,
|
|
106
|
+
wallet_address=route.from_address,
|
|
107
|
+
proxies=config.proxies,
|
|
108
|
+
token_mint_address=config.token,
|
|
109
|
+
token_decimals=config.token_decimals,
|
|
110
|
+
)
|
|
111
|
+
else:
|
|
112
|
+
value_res = calcs.calc_sol_value_for_address(
|
|
113
|
+
nodes=config.nodes,
|
|
114
|
+
value_expression=config.value,
|
|
115
|
+
address=route.from_address,
|
|
116
|
+
proxies=config.proxies,
|
|
117
|
+
fee=transfer_sol_fee,
|
|
118
|
+
)
|
|
119
|
+
logger.debug(f"{route.log_prefix}: value={value_res.ok_or_err()}")
|
|
120
|
+
if isinstance(value_res, Err):
|
|
121
|
+
logger.info(f"{route.log_prefix}: calc value error, {value_res.err}")
|
|
122
|
+
|
|
123
|
+
return value_res.ok
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _check_value_min_limit(route: TxRoute, value: int, config: Config) -> bool:
|
|
127
|
+
"""Returns False if the transfer should be skipped."""
|
|
128
|
+
if config.value_min_limit:
|
|
129
|
+
if config.token:
|
|
130
|
+
value_min_limit = calcs.calc_token_expression(config.value_min_limit, config.token_decimals)
|
|
131
|
+
else:
|
|
132
|
+
value_min_limit = calcs.calc_sol_expression(config.value_min_limit)
|
|
133
|
+
if value < value_min_limit:
|
|
134
|
+
logger.info(f"{route.log_prefix}: value<value_min_limit, value={_value_with_suffix(value, config)}")
|
|
135
|
+
return True
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _value_with_suffix(value: int, config: Config) -> str:
|
|
139
|
+
if config.token:
|
|
140
|
+
return f"{to_token(value, decimals=config.token_decimals, ndigits=config.round_ndigits)}t"
|
|
141
|
+
return f"{lamports_to_sol(value, config.round_ndigits)}sol"
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _send_tx(route: TxRoute, value: int, config: Config) -> Signature | None:
|
|
145
|
+
logger.debug(f"{route.log_prefix}: value={_value_with_suffix(value, config)}")
|
|
146
|
+
if config.token:
|
|
147
|
+
res = transfer.transfer_token_with_retries(
|
|
148
|
+
nodes=config.nodes,
|
|
149
|
+
token_mint_address=config.token,
|
|
150
|
+
from_address=route.from_address,
|
|
151
|
+
private_key=config.private_keys[route.from_address],
|
|
152
|
+
to_address=route.to_address,
|
|
153
|
+
amount=value,
|
|
154
|
+
decimals=config.token_decimals,
|
|
155
|
+
proxies=config.proxies,
|
|
156
|
+
retries=3,
|
|
157
|
+
)
|
|
158
|
+
else:
|
|
159
|
+
res = transfer.transfer_sol_with_retries(
|
|
160
|
+
nodes=config.nodes,
|
|
161
|
+
from_address=route.from_address,
|
|
162
|
+
private_key=config.private_keys[route.from_address],
|
|
163
|
+
to_address=route.to_address,
|
|
164
|
+
lamports=value,
|
|
165
|
+
proxies=config.proxies,
|
|
166
|
+
retries=3,
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
if isinstance(res, Err):
|
|
170
|
+
logger.info(f"{route.log_prefix}: tx error {res.err}")
|
|
171
|
+
return None
|
|
172
|
+
return res.ok
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _transfer(route: TxRoute, config: Config, cmd_params: TransferCmdParams) -> None:
|
|
176
|
+
transfer_sol_fee = 5000
|
|
177
|
+
|
|
178
|
+
value = _calc_value(route, config, transfer_sol_fee)
|
|
179
|
+
if value is None:
|
|
180
|
+
return
|
|
181
|
+
|
|
182
|
+
if not _check_value_min_limit(route, value, config):
|
|
183
|
+
return
|
|
184
|
+
|
|
185
|
+
if cmd_params.emulate:
|
|
186
|
+
logger.info(f"{route.log_prefix}: emulate, value={_value_with_suffix(value, config)}")
|
|
187
|
+
return
|
|
188
|
+
|
|
189
|
+
signature = _send_tx(route, value, config)
|
|
190
|
+
if signature is None:
|
|
191
|
+
return
|
|
192
|
+
|
|
193
|
+
status = "UNKNOWN"
|
|
194
|
+
if not cmd_params.no_confirmation:
|
|
195
|
+
logger.debug(f"{route.log_prefix}: waiting for confirmation, sig={signature}")
|
|
196
|
+
if cli_utils.wait_confirmation(config.nodes, config.proxies, signature, route.log_prefix):
|
|
197
|
+
status = "OK"
|
|
198
|
+
|
|
199
|
+
logger.info(f"{route.log_prefix}: sig={signature}, value={_value_with_suffix(value, config)}, status={status}")
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _print_balances(config: Config) -> None:
|
|
203
|
+
if config.token:
|
|
204
|
+
headers = ["n", "from_address", "sol", "t", "to_address", "sol", "t"]
|
|
205
|
+
else:
|
|
206
|
+
headers = ["n", "from_address", "sol", "to_address", "sol"]
|
|
207
|
+
table = Table(*headers, title="balances")
|
|
208
|
+
with Live(table, refresh_per_second=0.5):
|
|
209
|
+
for count, route in enumerate(config.routes):
|
|
210
|
+
from_sol_balance = _get_sol_balance_str(route.from_address, config)
|
|
211
|
+
to_sol_balance = _get_sol_balance_str(route.to_address, config)
|
|
212
|
+
from_t_balance = _get_token_balance_str(route.from_address, config) if config.token else ""
|
|
213
|
+
to_t_balance = _get_token_balance_str(route.to_address, config) if config.token else ""
|
|
214
|
+
|
|
215
|
+
if config.token:
|
|
216
|
+
table.add_row(
|
|
217
|
+
str(count),
|
|
218
|
+
route.from_address,
|
|
219
|
+
from_sol_balance,
|
|
220
|
+
from_t_balance,
|
|
221
|
+
route.to_address,
|
|
222
|
+
to_sol_balance,
|
|
223
|
+
to_t_balance,
|
|
224
|
+
)
|
|
225
|
+
else:
|
|
226
|
+
table.add_row(
|
|
227
|
+
str(count),
|
|
228
|
+
route.from_address,
|
|
229
|
+
from_sol_balance,
|
|
230
|
+
route.to_address,
|
|
231
|
+
to_sol_balance,
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def _get_sol_balance_str(address: str, config: Config) -> str:
|
|
236
|
+
return get_sol_balance_with_retries(config.nodes, address, proxies=config.proxies, retries=5).map_or_else(
|
|
237
|
+
lambda err: err,
|
|
238
|
+
lambda ok: str(lamports_to_sol(ok, config.round_ndigits)),
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def _get_token_balance_str(address: str, config: Config) -> str:
|
|
243
|
+
if not config.token:
|
|
244
|
+
raise ValueError("token is not set")
|
|
245
|
+
return get_token_balance_with_retries(config.nodes, address, config.token, proxies=config.proxies, retries=5).map_or_else(
|
|
246
|
+
lambda err: err,
|
|
247
|
+
lambda ok: str(to_token(ok, config.token_decimals, ndigits=config.round_ndigits)),
|
|
248
|
+
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
routes = """
|
|
2
|
+
Bd8CxCTLez2ckVTqEJjuZkWjYFSRbo8fA1qYbd7yFVP9 Eaft9xXzfgbRqsHd65WspoaxTtH7pkznM9YA8tsDKGwj # comments are allowed
|
|
3
|
+
Fc2TRJVCpFZpRz56mFnQETctib1zwFnwHcS7HoQSgUzZ EVJctTWikt29rUXBf49tyQdK87x837HtvpCwqeSjp1Ur
|
|
4
|
+
file: /from/addresses.txt /to/addresses.txt
|
|
5
|
+
"""
|
|
6
|
+
token = "6VBTMLgv256c7scudNf8T5GoTJcEE8WfgcJhxbGYPQ8G" # if token is not specified, then SOL is used
|
|
7
|
+
private_keys = """
|
|
8
|
+
5VTfgpKKkckrsK33vcw6cEgv8SjLiwaorU8sd2ftjo2sx4tCV6N44dF4P9VigLaKNT2vpX3VuiFAiNpEBnMq3CiB
|
|
9
|
+
DE9poAKvs6tENFbADZ25W1zfKeiCbuDnFbafkBgo4rT28ZGkemqnF1zAqX9WGvBKUXSRVhXgX1RHe3qn11xfjR8
|
|
10
|
+
file: ./path/to/privates.txt
|
|
11
|
+
# Extra keys are not a problem, nor is their order.
|
|
12
|
+
"""
|
|
13
|
+
value = "0.2balance + random(1t, 2.50t) - 100" # If transferring SOL, the suffix ‘sol’ is used. For any other tokens, the suffix ‘t’ is used.
|
|
14
|
+
delay = "random(10, 100)" # seconds, optional
|
|
15
|
+
proxies = """
|
|
16
|
+
http://usr:pass@123.123.123.123:1234
|
|
17
|
+
env_url: MM_SOL_PROXIES_URL
|
|
18
|
+
url: https://site.com/api/proxies
|
|
19
|
+
"""
|
|
20
|
+
nodes = """
|
|
21
|
+
https://api.devnet.solana.com
|
|
22
|
+
http://localhost:8899
|
|
23
|
+
"""
|
mm_sol/cli/validators.py
CHANGED
|
@@ -30,3 +30,7 @@ class Validators(ConfigValidators):
|
|
|
30
30
|
@staticmethod
|
|
31
31
|
def valid_token_expression(var_name: str | None = None) -> Callable[[str], str]:
|
|
32
32
|
return ConfigValidators.valid_calc_int_expression(var_name, {"t": 6})
|
|
33
|
+
|
|
34
|
+
@staticmethod
|
|
35
|
+
def valid_sol_or_token_expression(var_name: str | None = None) -> Callable[[str], str]:
|
|
36
|
+
return ConfigValidators.valid_calc_int_expression(var_name, SUFFIX_DECIMALS | {"t": 6})
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mm-sol
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Requires-Python: >=3.12
|
|
5
5
|
Requires-Dist: base58~=2.1.1
|
|
6
6
|
Requires-Dist: jinja2>=3.1.5
|
|
7
|
-
Requires-Dist: mm-crypto-utils>=0.1.
|
|
7
|
+
Requires-Dist: mm-crypto-utils>=0.1.5
|
|
8
8
|
Requires-Dist: mnemonic==0.21
|
|
9
9
|
Requires-Dist: solana~=0.36.3
|
|
10
10
|
Requires-Dist: typer>=0.15.1
|
|
@@ -12,23 +12,21 @@ mm_sol/transfer.py,sha256=taf2NTLpo-bxISeaILARXEGLldUvqvP-agp5IDva7Hw,5825
|
|
|
12
12
|
mm_sol/utils.py,sha256=NE0G564GiT9d7rW_lPPxUb1eq62WiXh28xtvtzNQIqw,556
|
|
13
13
|
mm_sol/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
14
|
mm_sol/cli/calcs.py,sha256=-r9RlsQyOziTDf84uIsvTgZmsUdNrVeazu3vTj9hhNA,1887
|
|
15
|
-
mm_sol/cli/cli.py,sha256=
|
|
16
|
-
mm_sol/cli/cli_utils.py,sha256=
|
|
17
|
-
mm_sol/cli/validators.py,sha256=
|
|
15
|
+
mm_sol/cli/cli.py,sha256=_6Fv3_RC20Yllee3NUXBO_DUfdaAD0vvL_jW_YVcrFo,4444
|
|
16
|
+
mm_sol/cli/cli_utils.py,sha256=rYcunR8w3uyFX44zs8GT4vNZbkrcMtQWgjRi7gkBCos,1912
|
|
17
|
+
mm_sol/cli/validators.py,sha256=q9Na86x4w21CX4_1DawKDHd8JF7HHtkAOZdsaDo9_zk,1371
|
|
18
18
|
mm_sol/cli/cmd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
19
|
mm_sol/cli/cmd/balance_cmd.py,sha256=DfUZY3-Hr-F7Y0xp1faol0yLnPu6iDU3b839VhdwAbw,2587
|
|
20
20
|
mm_sol/cli/cmd/balances_cmd.py,sha256=gMRZXAnCOPESsKRqz33ALPzSOqGGeZF225kMRO6sV-c,2876
|
|
21
21
|
mm_sol/cli/cmd/example_cmd.py,sha256=M5dvRg9jvpVUwxvMRiRnO77aKR7c57bMY9booxMAswM,222
|
|
22
22
|
mm_sol/cli/cmd/node_cmd.py,sha256=2AEAjq2M9f8-RZiI0rif6wITdns9QUb4Kr34QPsI2CA,238
|
|
23
|
-
mm_sol/cli/cmd/
|
|
24
|
-
mm_sol/cli/cmd/transfer_token_cmd.py,sha256=gepB8dds1xnGMYT1UBwV8EgpKmST3SvWS99lXnc2X3E,7470
|
|
23
|
+
mm_sol/cli/cmd/transfer_cmd.py,sha256=7LEQ2e-aTeawwTXkNwtsB044zHFsNEHXj3cCbp5rb-Q,9832
|
|
25
24
|
mm_sol/cli/cmd/wallet/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
26
25
|
mm_sol/cli/cmd/wallet/keypair_cmd.py,sha256=cRHVVTs9zNYmUozZ8ZlJoutn9V6r8I1AEHBrszR7dTE,538
|
|
27
26
|
mm_sol/cli/cmd/wallet/mnemonic_cmd.py,sha256=IiON_fJT5AFfIr_E1LR6_iDYZ3c_jWCFc-wSYqk61V8,648
|
|
28
27
|
mm_sol/cli/examples/balances.toml,sha256=jyfUXusAWe6suuuwnPIfqWdU2kfT3hfMjkZ6uYMg8s0,347
|
|
29
|
-
mm_sol/cli/examples/transfer
|
|
30
|
-
mm_sol
|
|
31
|
-
mm_sol-0.
|
|
32
|
-
mm_sol-0.
|
|
33
|
-
mm_sol-0.
|
|
34
|
-
mm_sol-0.3.6.dist-info/RECORD,,
|
|
28
|
+
mm_sol/cli/examples/transfer.toml,sha256=C8cHd0BMmD4KPqU4OWLrV8Deu7VVEOJ71H2YZxHhuLg,1027
|
|
29
|
+
mm_sol-0.4.0.dist-info/METADATA,sha256=t249_PGnuxYLN2_2GSoIrIQHSp-whVl_SMarQtufQ9Y,259
|
|
30
|
+
mm_sol-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
31
|
+
mm_sol-0.4.0.dist-info/entry_points.txt,sha256=MrYnosumy9nsITSAw5TiR3WXDwsdoF0YvUIlZ38TLLs,46
|
|
32
|
+
mm_sol-0.4.0.dist-info/RECORD,,
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import time
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from typing import Annotated, Self
|
|
5
|
-
|
|
6
|
-
import mm_crypto_utils
|
|
7
|
-
from loguru import logger
|
|
8
|
-
from mm_crypto_utils import AddressToPrivate, TxRoute
|
|
9
|
-
from mm_std import BaseConfig, Err, utc_now
|
|
10
|
-
from pydantic import AfterValidator, BeforeValidator, Field, model_validator
|
|
11
|
-
from rich.live import Live
|
|
12
|
-
from rich.table import Table
|
|
13
|
-
|
|
14
|
-
from mm_sol import transfer
|
|
15
|
-
from mm_sol.balance import get_sol_balance_with_retries
|
|
16
|
-
from mm_sol.cli import calcs, cli_utils
|
|
17
|
-
from mm_sol.cli.calcs import calc_sol_expression
|
|
18
|
-
from mm_sol.cli.validators import Validators
|
|
19
|
-
from mm_sol.converters import lamports_to_sol
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# noinspection DuplicatedCode
|
|
23
|
-
class Config(BaseConfig):
|
|
24
|
-
nodes: Annotated[list[str], BeforeValidator(Validators.nodes())]
|
|
25
|
-
routes: Annotated[list[TxRoute], BeforeValidator(Validators.sol_routes())]
|
|
26
|
-
private_keys: Annotated[AddressToPrivate, BeforeValidator(Validators.sol_private_keys())]
|
|
27
|
-
proxies: Annotated[list[str], Field(default_factory=list), BeforeValidator(Validators.proxies())]
|
|
28
|
-
value: Annotated[str, AfterValidator(Validators.valid_sol_expression("balance"))]
|
|
29
|
-
value_min_limit: Annotated[str | None, AfterValidator(Validators.valid_sol_expression())] = None
|
|
30
|
-
delay: Annotated[str | None, AfterValidator(Validators.valid_calc_decimal_value())] = None # in seconds
|
|
31
|
-
round_ndigits: int = 5
|
|
32
|
-
log_debug: Annotated[Path | None, BeforeValidator(Validators.log_file())] = None
|
|
33
|
-
log_info: Annotated[Path | None, BeforeValidator(Validators.log_file())] = None
|
|
34
|
-
|
|
35
|
-
@property
|
|
36
|
-
def from_addresses(self) -> list[str]:
|
|
37
|
-
return [r.from_address for r in self.routes]
|
|
38
|
-
|
|
39
|
-
@model_validator(mode="after")
|
|
40
|
-
def final_validator(self) -> Self:
|
|
41
|
-
if not self.private_keys.contains_all_addresses(self.from_addresses):
|
|
42
|
-
raise ValueError("private keys are not set for all addresses")
|
|
43
|
-
|
|
44
|
-
return self
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def run(
|
|
48
|
-
config_path: Path,
|
|
49
|
-
*,
|
|
50
|
-
print_balances: bool,
|
|
51
|
-
print_config: bool,
|
|
52
|
-
debug: bool,
|
|
53
|
-
no_confirmation: bool,
|
|
54
|
-
emulate: bool,
|
|
55
|
-
) -> None:
|
|
56
|
-
config = Config.read_toml_config_or_exit(config_path)
|
|
57
|
-
|
|
58
|
-
if print_config:
|
|
59
|
-
config.print_and_exit({"private_keys"})
|
|
60
|
-
|
|
61
|
-
mm_crypto_utils.init_logger(debug, config.log_debug, config.log_info)
|
|
62
|
-
|
|
63
|
-
if print_balances:
|
|
64
|
-
_print_balances(config)
|
|
65
|
-
sys.exit(0)
|
|
66
|
-
|
|
67
|
-
_run_transfers(config, no_confirmation=no_confirmation, emulate=emulate)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def _run_transfers(config: Config, *, no_confirmation: bool, emulate: bool) -> None:
|
|
71
|
-
logger.info(f"started at {utc_now()} UTC")
|
|
72
|
-
logger.debug(f"config={config.model_dump(exclude={'private_keys'}) | {'version': cli_utils.get_version()}}")
|
|
73
|
-
for i, route in enumerate(config.routes):
|
|
74
|
-
_transfer(
|
|
75
|
-
from_address=route.from_address,
|
|
76
|
-
to_address=route.to_address,
|
|
77
|
-
config=config,
|
|
78
|
-
no_confirmation=no_confirmation,
|
|
79
|
-
emulate=emulate,
|
|
80
|
-
)
|
|
81
|
-
if not emulate and config.delay is not None and i < len(config.routes) - 1:
|
|
82
|
-
delay_value = mm_crypto_utils.calc_decimal_value(config.delay)
|
|
83
|
-
logger.debug(f"delay {delay_value} seconds")
|
|
84
|
-
time.sleep(float(delay_value))
|
|
85
|
-
logger.info(f"finished at {utc_now()} UTC")
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def _transfer(*, from_address: str, to_address: str, config: Config, no_confirmation: bool, emulate: bool) -> None:
|
|
89
|
-
log_prefix = f"{from_address}->{to_address}"
|
|
90
|
-
fee = 5000
|
|
91
|
-
# get value
|
|
92
|
-
value_res = calcs.calc_sol_value_for_address(
|
|
93
|
-
nodes=config.nodes, value_expression=config.value, address=from_address, proxies=config.proxies, fee=fee
|
|
94
|
-
)
|
|
95
|
-
logger.debug(f"{log_prefix}value={value_res.ok_or_err()}")
|
|
96
|
-
if isinstance(value_res, Err):
|
|
97
|
-
logger.info(f"{log_prefix}calc value error, {value_res.err}")
|
|
98
|
-
return
|
|
99
|
-
value = value_res.ok
|
|
100
|
-
|
|
101
|
-
# value_min_limit
|
|
102
|
-
if config.value_min_limit:
|
|
103
|
-
value_min_limit = calc_sol_expression(config.value_min_limit)
|
|
104
|
-
if value < value_min_limit:
|
|
105
|
-
logger.info(f"{log_prefix}: value<value_min_limit, value={lamports_to_sol(value, config.round_ndigits)}sol")
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
# emulate?
|
|
109
|
-
if emulate:
|
|
110
|
-
msg = f"{log_prefix}: emulate, value={lamports_to_sol(value, config.round_ndigits)}SOL,"
|
|
111
|
-
msg += f" fee={fee}"
|
|
112
|
-
logger.info(msg)
|
|
113
|
-
return
|
|
114
|
-
|
|
115
|
-
debug_tx_params = {"fee": fee, "value": value, "to": to_address}
|
|
116
|
-
logger.debug(f"{log_prefix}: tx_params={debug_tx_params}")
|
|
117
|
-
|
|
118
|
-
res = transfer.transfer_sol_with_retries(
|
|
119
|
-
nodes=config.nodes,
|
|
120
|
-
from_address=from_address,
|
|
121
|
-
private_key=config.private_keys[from_address],
|
|
122
|
-
to_address=to_address,
|
|
123
|
-
lamports=value,
|
|
124
|
-
proxies=config.proxies,
|
|
125
|
-
retries=3,
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
if isinstance(res, Err):
|
|
129
|
-
logger.info(f"{log_prefix}: send_error: {res.err}")
|
|
130
|
-
return
|
|
131
|
-
signature = res.ok
|
|
132
|
-
|
|
133
|
-
if no_confirmation:
|
|
134
|
-
msg = f"{log_prefix}: sig={signature}, value={lamports_to_sol(value, config.round_ndigits)}"
|
|
135
|
-
logger.info(msg)
|
|
136
|
-
else:
|
|
137
|
-
logger.debug(f"{log_prefix}: sig={signature}, waiting for confirmation")
|
|
138
|
-
status = "UNKNOWN"
|
|
139
|
-
if cli_utils.wait_confirmation(config.nodes, config.proxies, signature, log_prefix):
|
|
140
|
-
status = "OK"
|
|
141
|
-
msg = f"{log_prefix}: sig={signature}, value={lamports_to_sol(value, config.round_ndigits)}, status={status}"
|
|
142
|
-
logger.info(msg)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
def _print_balances(config: Config) -> None:
|
|
146
|
-
table = Table("n", "from_address", "sol", "to_address", "sol", title="balances")
|
|
147
|
-
with Live(table, refresh_per_second=0.5):
|
|
148
|
-
for count, route in enumerate(config.routes):
|
|
149
|
-
from_balance = _get_sol_balance_str(route.from_address, config)
|
|
150
|
-
to_balance = _get_sol_balance_str(route.to_address, config)
|
|
151
|
-
row: list[str] = [str(count), route.from_address, from_balance, route.to_address, to_balance]
|
|
152
|
-
table.add_row(*row)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
def _get_sol_balance_str(address: str, config: Config) -> str:
|
|
156
|
-
return get_sol_balance_with_retries(config.nodes, address, proxies=config.proxies, retries=5).map_or_else(
|
|
157
|
-
lambda err: err,
|
|
158
|
-
lambda ok: str(lamports_to_sol(ok, config.round_ndigits)),
|
|
159
|
-
)
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import time
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from typing import Annotated, Self
|
|
5
|
-
|
|
6
|
-
import mm_crypto_utils
|
|
7
|
-
from loguru import logger
|
|
8
|
-
from mm_crypto_utils import AddressToPrivate, TxRoute
|
|
9
|
-
from mm_std import BaseConfig, Err, fatal, utc_now
|
|
10
|
-
from pydantic import AfterValidator, BeforeValidator, Field, model_validator
|
|
11
|
-
from rich.live import Live
|
|
12
|
-
from rich.table import Table
|
|
13
|
-
|
|
14
|
-
from mm_sol import transfer
|
|
15
|
-
from mm_sol.balance import get_sol_balance_with_retries, get_token_balance_with_retries
|
|
16
|
-
from mm_sol.cli import calcs, cli_utils
|
|
17
|
-
from mm_sol.cli.validators import Validators
|
|
18
|
-
from mm_sol.converters import lamports_to_sol, to_token
|
|
19
|
-
from mm_sol.token import get_decimals_with_retries
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# noinspection DuplicatedCode
|
|
23
|
-
class Config(BaseConfig):
|
|
24
|
-
nodes: Annotated[list[str], BeforeValidator(Validators.nodes())]
|
|
25
|
-
routes: Annotated[list[TxRoute], BeforeValidator(Validators.sol_routes())]
|
|
26
|
-
private_keys: Annotated[AddressToPrivate, BeforeValidator(Validators.sol_private_keys())]
|
|
27
|
-
proxies: Annotated[list[str], Field(default_factory=list), BeforeValidator(Validators.proxies())]
|
|
28
|
-
token: Annotated[str, AfterValidator(Validators.sol_address())]
|
|
29
|
-
value: Annotated[str, AfterValidator(Validators.valid_token_expression("balance"))]
|
|
30
|
-
value_min_limit: Annotated[str | None, AfterValidator(Validators.valid_token_expression())] = None
|
|
31
|
-
delay: Annotated[str | None, AfterValidator(Validators.valid_calc_decimal_value())] = None # in seconds
|
|
32
|
-
round_ndigits: int = 5
|
|
33
|
-
log_debug: Annotated[Path | None, BeforeValidator(Validators.log_file())] = None
|
|
34
|
-
log_info: Annotated[Path | None, BeforeValidator(Validators.log_file())] = None
|
|
35
|
-
|
|
36
|
-
@property
|
|
37
|
-
def from_addresses(self) -> list[str]:
|
|
38
|
-
return [r.from_address for r in self.routes]
|
|
39
|
-
|
|
40
|
-
@model_validator(mode="after")
|
|
41
|
-
def final_validator(self) -> Self:
|
|
42
|
-
if not self.private_keys.contains_all_addresses(self.from_addresses):
|
|
43
|
-
raise ValueError("private keys are not set for all addresses")
|
|
44
|
-
|
|
45
|
-
return self
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def run(
|
|
49
|
-
config_path: Path,
|
|
50
|
-
*,
|
|
51
|
-
print_balances: bool,
|
|
52
|
-
print_config: bool,
|
|
53
|
-
debug: bool,
|
|
54
|
-
no_confirmation: bool,
|
|
55
|
-
emulate: bool,
|
|
56
|
-
) -> None:
|
|
57
|
-
config = Config.read_toml_config_or_exit(config_path)
|
|
58
|
-
|
|
59
|
-
if print_config:
|
|
60
|
-
config.print_and_exit({"private_keys"})
|
|
61
|
-
|
|
62
|
-
mm_crypto_utils.init_logger(debug, config.log_debug, config.log_info)
|
|
63
|
-
|
|
64
|
-
decimals_res = get_decimals_with_retries(config.nodes, config.token, retries=3, proxies=config.proxies)
|
|
65
|
-
if isinstance(decimals_res, Err):
|
|
66
|
-
fatal(f"can't get decimals for token={config.token}, error={decimals_res.err}")
|
|
67
|
-
|
|
68
|
-
token_decimals = decimals_res.ok
|
|
69
|
-
logger.debug(f"token decimals={token_decimals}")
|
|
70
|
-
|
|
71
|
-
if print_balances:
|
|
72
|
-
_print_balances(config, token_decimals)
|
|
73
|
-
sys.exit(0)
|
|
74
|
-
|
|
75
|
-
_run_transfers(config, token_decimals, no_confirmation=no_confirmation, emulate=emulate)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def _run_transfers(config: Config, token_decimals: int, *, no_confirmation: bool, emulate: bool) -> None:
|
|
79
|
-
logger.info(f"started at {utc_now()} UTC")
|
|
80
|
-
logger.debug(f"config={config.model_dump(exclude={'private_keys'}) | {'version': cli_utils.get_version()}}")
|
|
81
|
-
for i, route in enumerate(config.routes):
|
|
82
|
-
_transfer(
|
|
83
|
-
route=route,
|
|
84
|
-
token_decimals=token_decimals,
|
|
85
|
-
config=config,
|
|
86
|
-
no_confirmation=no_confirmation,
|
|
87
|
-
emulate=emulate,
|
|
88
|
-
)
|
|
89
|
-
if not emulate and config.delay is not None and i < len(config.routes) - 1:
|
|
90
|
-
delay_value = mm_crypto_utils.calc_decimal_value(config.delay)
|
|
91
|
-
logger.debug(f"delay {delay_value} seconds")
|
|
92
|
-
time.sleep(float(delay_value))
|
|
93
|
-
logger.info(f"finished at {utc_now()} UTC")
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def _transfer(*, route: TxRoute, config: Config, token_decimals: int, no_confirmation: bool, emulate: bool) -> None:
|
|
97
|
-
log_prefix = f"{route.from_address}->{route.to_address}"
|
|
98
|
-
fee = 5000
|
|
99
|
-
|
|
100
|
-
# get value
|
|
101
|
-
value_res = calcs.calc_token_value_for_address(
|
|
102
|
-
nodes=config.nodes,
|
|
103
|
-
value_expression=config.value,
|
|
104
|
-
wallet_address=route.from_address,
|
|
105
|
-
proxies=config.proxies,
|
|
106
|
-
token_mint_address=config.token,
|
|
107
|
-
token_decimals=token_decimals,
|
|
108
|
-
)
|
|
109
|
-
logger.debug(f"{log_prefix}: value={value_res.ok_or_err()}")
|
|
110
|
-
if isinstance(value_res, Err):
|
|
111
|
-
logger.info(f"{log_prefix}: calc value error, {value_res.err}")
|
|
112
|
-
return
|
|
113
|
-
value = value_res.ok
|
|
114
|
-
value_t = f"{to_token(value, decimals=token_decimals, ndigits=config.round_ndigits)}t"
|
|
115
|
-
|
|
116
|
-
# value_min_limit
|
|
117
|
-
if config.value_min_limit:
|
|
118
|
-
value_min_limit = calcs.calc_token_expression(config.value_min_limit, token_decimals)
|
|
119
|
-
if value < value_min_limit:
|
|
120
|
-
logger.info(f"{log_prefix}: value<value_min_limit, value={value_t}")
|
|
121
|
-
return
|
|
122
|
-
|
|
123
|
-
if emulate:
|
|
124
|
-
logger.info(f"{log_prefix}: emulate, value={value_t}, fee={fee}lamports")
|
|
125
|
-
return
|
|
126
|
-
|
|
127
|
-
logger.debug(f"{log_prefix}: value={to_token(value, decimals=token_decimals)}t, fee={fee}lamports")
|
|
128
|
-
res = transfer.transfer_token_with_retries(
|
|
129
|
-
nodes=config.nodes,
|
|
130
|
-
token_mint_address=config.token,
|
|
131
|
-
from_address=route.from_address,
|
|
132
|
-
private_key=config.private_keys[route.from_address],
|
|
133
|
-
to_address=route.to_address,
|
|
134
|
-
amount=value,
|
|
135
|
-
decimals=token_decimals,
|
|
136
|
-
proxies=config.proxies,
|
|
137
|
-
retries=3,
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
if isinstance(res, Err):
|
|
141
|
-
logger.info(f"{log_prefix}: send_error: {res.err}")
|
|
142
|
-
return
|
|
143
|
-
signature = res.ok
|
|
144
|
-
|
|
145
|
-
if no_confirmation:
|
|
146
|
-
msg = f"{log_prefix}: sig={signature}, value={value_t}"
|
|
147
|
-
logger.info(msg)
|
|
148
|
-
else:
|
|
149
|
-
logger.debug(f"{log_prefix}: sig={signature}, waiting for confirmation")
|
|
150
|
-
status = "UNKNOWN"
|
|
151
|
-
if cli_utils.wait_confirmation(config.nodes, config.proxies, signature, log_prefix):
|
|
152
|
-
status = "OK"
|
|
153
|
-
msg = f"{log_prefix}: sig={signature}, value={value_t}, status={status}"
|
|
154
|
-
logger.info(msg)
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
def _print_balances(config: Config, token_decimals: int) -> None:
|
|
158
|
-
table = Table("n", "from_address", "sol", "t", "to_address", "sol", "t", title="balances")
|
|
159
|
-
with Live(table, refresh_per_second=0.5):
|
|
160
|
-
for count, route in enumerate(config.routes):
|
|
161
|
-
from_sol_balance = _get_sol_balance_str(route.from_address, config)
|
|
162
|
-
to_sol_balance = _get_sol_balance_str(route.to_address, config)
|
|
163
|
-
from_t_balance = _get_token_balance_str(route.from_address, config, token_decimals)
|
|
164
|
-
to_t_balance = _get_token_balance_str(route.to_address, config, token_decimals)
|
|
165
|
-
row: list[str] = [
|
|
166
|
-
str(count),
|
|
167
|
-
route.from_address,
|
|
168
|
-
from_sol_balance,
|
|
169
|
-
from_t_balance,
|
|
170
|
-
route.to_address,
|
|
171
|
-
to_sol_balance,
|
|
172
|
-
to_t_balance,
|
|
173
|
-
]
|
|
174
|
-
table.add_row(*row)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
def _get_sol_balance_str(address: str, config: Config) -> str:
|
|
178
|
-
return get_sol_balance_with_retries(config.nodes, address, proxies=config.proxies, retries=5).map_or_else(
|
|
179
|
-
lambda err: err,
|
|
180
|
-
lambda ok: str(lamports_to_sol(ok, config.round_ndigits)),
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
def _get_token_balance_str(address: str, config: Config, token_decimals: int) -> str:
|
|
185
|
-
return get_token_balance_with_retries(config.nodes, address, config.token, proxies=config.proxies, retries=5).map_or_else(
|
|
186
|
-
lambda err: err,
|
|
187
|
-
lambda ok: str(to_token(ok, token_decimals, ndigits=config.round_ndigits)),
|
|
188
|
-
)
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
routes = """
|
|
2
|
-
Bd8CxCTLez2ckVTqEJjuZkWjYFSRbo8fA1qYbd7yFVP9 Eaft9xXzfgbRqsHd65WspoaxTtH7pkznM9YA8tsDKGwj
|
|
3
|
-
Fc2TRJVCpFZpRz56mFnQETctib1zwFnwHcS7HoQSgUzZ EVJctTWikt29rUXBf49tyQdK87x837HtvpCwqeSjp1Ur
|
|
4
|
-
"""
|
|
5
|
-
private_keys = "file: ./path/to/privates.txt"
|
|
6
|
-
value = "0.5balance - 0.012sol"
|
|
7
|
-
delay = "random(5,10)"
|
|
8
|
-
proxies = "url: https://site.com/api/get-proxies"
|
|
9
|
-
nodes = "https://api.devnet.solana.com"
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
routes = """
|
|
2
|
-
Bd8CxCTLez2ckVTqEJjuZkWjYFSRbo8fA1qYbd7yFVP9 Eaft9xXzfgbRqsHd65WspoaxTtH7pkznM9YA8tsDKGwj
|
|
3
|
-
Fc2TRJVCpFZpRz56mFnQETctib1zwFnwHcS7HoQSgUzZ EVJctTWikt29rUXBf49tyQdK87x837HtvpCwqeSjp1Ur
|
|
4
|
-
"""
|
|
5
|
-
token = "6VBTMLgv256c7scudNf8T5GoTJcEE8WfgcJhxbGYPQ8G"
|
|
6
|
-
private_keys = "file: ./path/to/privates.txt"
|
|
7
|
-
value = "0.012 t"
|
|
8
|
-
proxies = "https://site.com/api/get-proxies"
|
|
9
|
-
nodes = "https://api.devnet.solana.com"
|
|
File without changes
|
|
File without changes
|