В связи с этим для себя* написал на python скрипт для прямого взаимодействия с блохчейном.
Для его работы необходимы библиотеки xrpl-py и asyncio.
pip install --user xrpl-py
pip install --user asyncio
Сам скрипт:
from xrpl.models.transactions import AMMDeposit, AMMDepositFlag, AMMWithdraw, AMMWithdrawFlag, AMMVote
from xrpl.account import get_next_valid_seq_number
from xrpl.transaction import sign_and_submit
from xrpl.clients import JsonRpcClient
from xrpl.utils import xrp_to_drops
from xrpl.wallet import Wallet
from xrpl.models.amounts import IssuedCurrencyAmount
from xrpl.models.currencies import XRP, IssuedCurrency
import random, traceback, asyncio
#AMM Pools https://xrpscan.com/amms
#На данный момент Active pools: 316
#START SETTINGS
_URL = ["https://s1.ripple.com:51234", "https://s2.ripple.com:51234"]
_ACCOUNT = "YOU_ADDRESS"
_PRIVATE_KEY = "YOU_PRIVATE_KEY"
_ASSET1 = XRP()
_AMOUNT1 = xrp_to_drops(1000)
_ASSET2 = IssuedCurrency(currency="5553444300000000000000000000000000000000", issuer="rcEGREd8NmkKRE8GE424sksyt1tJVFZwu")
_AMOUNT2 = IssuedCurrencyAmount(currency=_ASSET2.currency, issuer=_ASSET2.issuer, value="600")
_LPTOKEN_CURRENCY = "03B20F3A7D26D33C6DA3503E5CCE3E67B102D4D2"
_LPTOKEN_ISSUER = "rGHt6LT5v9DVaEAmFzj5ciuxuj41ZjLofs"
_TRADING_FEE = 500
#for deposit
TWO_ASSET = True
#TWO_ASSET = True вводит не более _AMOUNT1 и _AMOUNT2
#TWO_ASSET = False вводит не более _ASSET1, с оплатой комиссии за ковертацию
#for withdraw
WITHDRAW_TWO = True
#WITHDRAW_TWO = True выводится максимально доступное количества обоих активов
#WITHDRAW_TWO = False выводится в _ASSET1, если WITHDRAW_AMOUNT = "0" то максимально возможный объем, с оплатой комиссии за ковертацию
#Если _ASSET1 XRP
WITHDRAW_AMOUNT = "0"
#Если _ASSET1 not XRP
#WITHDRAW_AMOUNT = IssuedCurrencyAmount(currency=_ASSET1.currency, issuer=_ASSET1.issuer, value="0")
#FINISH SETTINGS
class RippleAMM:
def __init__(self):
self.account = _ACCOUNT
self.client = self.get_client()
self.sequence = self.get_sequence()
def get_client(self):
return JsonRpcClient(random.choice(_URL))
def get_sequence(self):
return get_next_valid_seq_number(self.account, self.client)
def amm_deposit(self):
if TWO_ASSET:
return AMMDeposit(
account=self.account,
sequence=self.sequence,
asset=_ASSET1,
asset2=_ASSET2,
amount=_AMOUNT1,
amount2=_AMOUNT2,
flags=AMMDepositFlag.TF_TWO_ASSET)
else:
return AMMDeposit(
account=self.account,
sequence=self.sequence,
asset=_ASSET1,
asset2=_ASSET2,
amount=_AMOUNT1,
flags=AMMDepositFlag.TF_SINGLE_ASSET)
def amm_withdraw(self):
if WITHDRAW_TWO:
return AMMWithdraw(
account=self.account,
sequence=self.sequence,
asset=_ASSET1,
asset2=_ASSET2,
flags=AMMWithdrawFlag.TF_WITHDRAW_ALL)
else:
return AMMWithdraw(
account=self.account,
sequence=self.sequence,
asset=_ASSET1,
asset2=_ASSET2,
amount=WITHDRAW_AMOUNT,
flags=AMMWithdrawFlag.TF_ONE_ASSET_WITHDRAW_ALL)
def amm_vote(self):
return AMMVote(
account=self.account,
asset=_ASSET1,
asset2=_ASSET2,
trading_fee=_TRADING_FEE)
def secure_signing(self, transaction):
try:
wallet = Wallet.from_seed(seed=_PRIVATE_KEY)
response = sign_and_submit(transaction, self.client, wallet)
data = response.result
self.sequence = int(data["account_sequence_available"])
return {"result": data["engine_result"]}
except asyncio.TimeoutError:
return "TimeoutError"
except Exception:
return traceback.format_exc()
if __name__ == "__main__":
do = input(
f"""
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!Внимательно проверь блок SETTINGS!!!!!!!!!!!!!!
!!!Подписанные и отправленные в сеть транзакции НЕОБРАТИМЫ!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Доступные операции:
1. Deposit pool
2. Withdraw pool
3. Voting on pool trading fee
Что делаем? """)
tx = None
amm = RippleAMM()
if do == 1: tx = amm.amm_deposit()
elif do == 2: tx = amm.amm_withdraw()
elif do == 3: tx = amm.amm_vote()
print(tx)
if input("Sign and submit? y/N ").lower() == "y":
print(amm.secure_signing(tx))
print("The end")
Вставляем код в файл (например: amm.py), вносим правку в блок SETTINGS, запускаем:
python amm.py
*Используя этот скрипт Вы берете ВСЮ ответственность за последствия на СЕБЯ.
Всем Успехов!