THORChain client
THORChain client
THORChain protocol client
- class xchainpy2_thorchain.client.THORChainClient(network=NetworkType.MAINNET, phrase: str | None = None, private_key: str | bytes | callable | None = None, fee_bound: FeeBounds | None = None, root_derivation_paths: Dict[NetworkType, str] | None = None, client_urls={NetworkType.MAINNET: ('https://thornode.ninerealms.com', 'https://rpc.ninerealms.com'), NetworkType.STAGENET: ('https://stagenet-thornode.ninerealms.com', 'https://stagenet-rpc.ninerealms.com'), NetworkType.TESTNET: ('deprecated', 'deprecated')}, fallback_client_urls={NetworkType.MAINNET: [('https://thornode-v1.ninerealms.com', 'https://rpc-v1.ninerealms.com'), ('https://thornode.thorswap.net/', 'https://rpc.thorswap.net'), ('https://thornode-v0.ninerealms.com', 'https://rpc-v0.ninerealms.com')], NetworkType.STAGENET: [('https://stagenet-thornode.ninerealms.com', 'https://stagenet-rpc.ninerealms.com')], NetworkType.TESTNET: []}, chain_ids={NetworkType.MAINNET: 'thorchain-1', NetworkType.STAGENET: 'thorchain-stagenet-2', NetworkType.TESTNET: 'deprecated'}, explorer_providers={NetworkType.MAINNET: ('https://runescan.io', 'https://runescan.io/address/{address}', 'https://runescan.io/tx/{tx_id}'), NetworkType.STAGENET: ('https://runescan.io?network=stagenet', 'https://runescan.io/address/{address}?network=stagenet', 'https://runescan.io/tx/{tx_id}?network=stagenet'), NetworkType.TESTNET: ('https://runescan.io?network=testnet', 'https://runescan.io/address/{address}?network=testnet', 'https://runescan.io/tx/{tx_id}?network=testnet')}, wallet_index=0)
Bases:
CosmosGaiaClient- build_transfer_tx(what: CryptoAmount, recipient: str) Transaction
Build a transfer transaction of THORChain native asset.
- Parameters:
what (CryptoAmount) – What to transfer
recipient (str) – THORChain address of the recipient
- Returns:
Transaction
- async close()
Close the client.
- async deposit(what: CryptoAmount | Amount | int | float, memo: str, second_asset: CryptoAmount | None = None, gas_limit: int | None = None, sequence: int | None = None, account_number: int | None = None, check_balance: bool = True, fee=None, return_full_response=False) SubmittedTx | str
Send a deposit transaction. MsgDeposit is a special kind of transaction to invoke THORChain protocol’s action like swap or liquidity addition. Note! It is not on ordinary transfer of tokens. It has no destination address. For more info see: https://dev.thorchain.org/concepts/sending-transactions.html?highlight=MsgDeposit#thorchain
- Parameters:
what – Amount and Asset
second_asset – optional second asset if needed
memo – Memo string (usually a command to the AMM)
gas_limit – if not specified, we’ll use the default value
sequence – sequence number. If it is None, it will be fetched automatically
check_balance – Flag to check the balance before sending Tx
fee – string like “0rune”, default is 0
account_number – Your account number. If it is none, we will fetch it
return_full_response – when it is not enough to have just tx hash
- Returns:
submitted tx hash or full response (SubmittedTt object) if requested
- async fetch_transaction_from_thornode_raw(tx_hash: str) dict
Fetch transaction from THORNode, try to use fallback client if main client is not available Url: https://node/thorchain/tx/{tx_hash} :param tx_hash: Tx Hash :return: Transaction data (raw, unparsed)
- classmethod from_node_ip(ip: str)
Initialize THORChainClient from node IP address.
- Parameters:
ip – IP address of the node
- Returns:
THORChainClient
- async get_balance(address: str = '', with_trade_accounts=True) List[CryptoAmount]
Get the native balance of a given address. If with_trade_accounts is True, the balance will include trade assets, that takes 2 API calls.
- Parameters:
address
with_trade_accounts – Whether include trade account balance or not
- Returns:
List[CryptoAmount]
- get_denom(asset: Asset) str
Get the denomination of the asset. RUNE is a special case. Other native assets (like synths and trade assets) are lowercase.
- Parameters:
asset – Asset to get the denomination for
- Returns:
str
- async get_fees() Fees
Get THORChain interaction fees from THORNode API.
- Returns:
Fees object
- async get_trade_asset_balance(address: str = '') List[CryptoAmount]
Get the balance of trade assets of a given address. Trade assets are not listed in the ordinary cosmos/bank. This method calls a special THORChain API endpoint. See: https://dev.thorchain.org/concepts/trade-accounts.html
- Parameters:
address (str) – THORChain address, if not specified, the address of the wallet will be used
- Returns:
List of CryptoAmount
- Return type:
List[CryptoAmount]
- async get_transaction_data(tx_id: str, address: str = '') XcTx
Get transaction details by Tx Hash. :param tx_id: :param address: :return: XcTx
- async get_transaction_data_thornode(tx_id: str) XcTx
Fetch transaction data from THORNode (parsed to XcTx instance) This function is used when inbound or outbound tx is not of THORChain. It is called “getTransactionDataThornode” in xchainjs Parsing “observed_tx” object. Url: https://node/thorchain/tx/{tx_hash} :param tx_id: Tx Hash :return: XcTx result
- parse_denom_to_asset(denom: str) Asset
Parse denomination to Asset. RUNE is a special case (just ‘rune’)
- Parameters:
denom – Cosmos coin denomination string
- Returns:
Asset
- async refresh_chain_id()
Refresh chain ID for the current network.
- property rest_session: ClientSession
- property rpc_url: str
Get RPC URL for THORChain.
- Returns:
str
- property server_url: str
Get THORNode URL.
- Returns:
str
- set_network(network: NetworkType)
Set/update the current network. :param network: :return: None
- validate_address(address: str) bool
Validate THORChain address.
- Parameters:
address – Address to validate
- Returns:
bool
THORChain constants
- xchainpy2_thorchain.const.AssetRuneBNBMainnet = ('BNB', 'RUNE', 'B1A', AssetKind.NORMAL)
BEP2 RUNE asset on Binance mainnet. No longer used.
- xchainpy2_thorchain.const.AssetRuneBNBTestnet = ('BNB', 'RUNE', '67C', AssetKind.NORMAL)
BEP2 RUNE asset on Binance testnet. No longer used.
- xchainpy2_thorchain.const.AssetRuneERC20Mainnet = ('ETH', 'RUNE', '0x3155ba85d5f96b2d030a4966af206230e46849cb', AssetKind.NORMAL)
ERC20 RUNE asset on Ethereum mainnet. No longer used.
- xchainpy2_thorchain.const.AssetRuneERC20Testnet = ('ETH', 'RUNE', '0xd601c6A3a36721320573885A8d8420746dA3d7A0', AssetKind.NORMAL)
ERC20 RUNE asset on Ethereum testnet. No longer used.
- xchainpy2_thorchain.const.DEFAULT_CHAIN_IDS = {NetworkType.MAINNET: 'thorchain-1', NetworkType.STAGENET: 'thorchain-stagenet-2', NetworkType.TESTNET: 'deprecated'}
Default chain IDs for the THORChain network. Subject to change.
- xchainpy2_thorchain.const.DEFAULT_CLIENT_URLS = {NetworkType.MAINNET: ('https://thornode.ninerealms.com', 'https://rpc.ninerealms.com'), NetworkType.STAGENET: ('https://stagenet-thornode.ninerealms.com', 'https://stagenet-rpc.ninerealms.com'), NetworkType.TESTNET: ('deprecated', 'deprecated')}
Default client URLs for the THORChain network.
- xchainpy2_thorchain.const.DEFAULT_EXPLORER_URL = 'https://runescan.io{path}{network_tag}'
Default explorer URL for the THORChain network.
- xchainpy2_thorchain.const.DEFAULT_GAS_LIMIT_VALUE = 6000000
Default gas limit for transactions. Refers to Cosmos SDK
- xchainpy2_thorchain.const.DEFAULT_RUNE_FEE = (2000000, 8, Denomination.ASSET)
Default fee for RUNE transactions. Subject to change.
- xchainpy2_thorchain.const.DEFAULT_RUNE_NETWORK_FEE = ((2000000, 8, Denomination.ASSET), ('THOR', 'RUNE', '', AssetKind.DERIVED))
Default network fee for RUNE transactions. This may be overridden by the network constants. Please check the network constants for the actual network fee.
- xchainpy2_thorchain.const.DENOM_RUNE_NATIVE = 'rune'
Denomination for RUNE on THORChain (COSMOS demon).
- xchainpy2_thorchain.const.DEPOSIT_GAS_LIMIT_VALUE = 600000000
Default gas limit for deposit transactions. Refers to Cosmos SDK
- xchainpy2_thorchain.const.FALLBACK_CLIENT_URLS = {NetworkType.MAINNET: [('https://thornode-v1.ninerealms.com', 'https://rpc-v1.ninerealms.com'), ('https://thornode.thorswap.net/', 'https://rpc.thorswap.net'), ('https://thornode-v0.ninerealms.com', 'https://rpc-v0.ninerealms.com')], NetworkType.STAGENET: [('https://stagenet-thornode.ninerealms.com', 'https://stagenet-rpc.ninerealms.com')], NetworkType.TESTNET: []}
Fallback client URLs for the THORChain network.
- xchainpy2_thorchain.const.MAX_PAGES_PER_FUNCTION_CALL = 15
Maximum number of pages per function call.
- xchainpy2_thorchain.const.MAX_TX_COUNT_PER_FUNCTION_CALL = 500
Maximum number of transactions per function call.
- xchainpy2_thorchain.const.MAX_TX_COUNT_PER_PAGE = 100
Maximum number of transactions per page.
- xchainpy2_thorchain.const.ROOT_DERIVATION_PATH = "44'/931'/0'/0/"
Root derivation path of crypto-keys for THORChain network.
- xchainpy2_thorchain.const.ROOT_DERIVATION_PATHS = {NetworkType.MAINNET: "44'/931'/0'/0/", NetworkType.STAGENET: "44'/931'/0'/0/", NetworkType.TESTNET: "44'/931'/0'/0/"}
Root derivation paths for the THORChain network.
- xchainpy2_thorchain.const.RPC_PORTS = {NetworkType.MAINNET: 27147, NetworkType.STAGENET: 26657, NetworkType.TESTNET: 26657}
Cosmos SDK RPC ports for the THORChain network.
- xchainpy2_thorchain.const.RUNE_DISPLAY_SYMBOL = 'ᚱ'
Display symbol for the RUNE token. Raido glyph from the Elder Futhark alphabet.
- xchainpy2_thorchain.const.RUNE_TICKER = 'RUNE'
Ticker symbol for the RUNE token.
- xchainpy2_thorchain.const.THORNODE_PORT = 1317
Default API port for THORNode.
- xchainpy2_thorchain.const.THOR_AFFILIATE_BASIS_POINT_MAX = 1000
Affiliate cannot receive more than 10% of the trade value.
- xchainpy2_thorchain.const.THOR_BASIS_POINT_MAX = 10000
Maximum basis point value for THORChain.
- xchainpy2_thorchain.const.THOR_BLOCK_TIME_SEC = 6.0
Typical time in seconds for a block to be produced in THORChain.
- xchainpy2_thorchain.const.THOR_EXPLORERS = {NetworkType.MAINNET: ('https://runescan.io', 'https://runescan.io/address/{address}', 'https://runescan.io/tx/{tx_id}'), NetworkType.STAGENET: ('https://runescan.io?network=stagenet', 'https://runescan.io/address/{address}?network=stagenet', 'https://runescan.io/tx/{tx_id}?network=stagenet'), NetworkType.TESTNET: ('https://runescan.io?network=testnet', 'https://runescan.io/address/{address}?network=testnet', 'https://runescan.io/tx/{tx_id}?network=testnet')}
Explorer objects for the THORChain network.
- xchainpy2_thorchain.const.make_client_urls_from_ip_address(ip_address: str, network=NetworkType.MAINNET, protocol='http')
Make client URLs dict from an IP address.
- Parameters:
ip_address – THORNode IP address
network – Network type
protocol – HTTP or HTTPS
- Returns:
dict of client URLs
- xchainpy2_thorchain.const.make_explorer_object(network_tag: str)
Make an explorer object.
- Parameters:
network_tag – Query string to append to the base URL
- Returns:
ExplorerProvider object
THORChain Memo
See: https://dev.thorchain.org/thorchain-dev/concepts/memos
- class xchainpy2_thorchain.memo.ActionType(value)
Bases:
EnumAn enumeration.
- ADD_LIQUIDITY = 'addLiquidity'
- BOND = 'bond'
- DONATE = 'donate'
- LEAVE = 'leave'
- LIMIT_ORDER = 'limit_order'
- LOAN_CLOSE = 'loan-'
- LOAN_OPEN = 'loan+'
- NOOP = 'noop'
- OUTBOUND = 'out'
- REFUND = 'refund'
- RESERVE = 'reserve'
- RUNEPOOL_ADD = 'pool+'
- RUNEPOOL_WITHDRAW = 'pool-'
- SWAP = 'swap'
- THORNAME = 'thorname'
- TRADE_ACC_DEPOSIT = 'trade+'
- TRADE_ACC_WITHDRAW = 'trade-'
- UNBOND = 'unbond'
- UNKNOWN = '_unknown_'
- WITHDRAW = 'withdraw'
- class xchainpy2_thorchain.memo.Affiliate(address, fee_bp)
Bases:
NamedTuple- address: str
Alias for field number 0
- fee_bp: int
Alias for field number 1
- class xchainpy2_thorchain.memo.THORMemo(action: xchainpy2_thorchain.memo.ActionType, asset: str = '', dest_address: str = '', limit: int = 0, s_swap_interval: int = 0, s_swap_quantity: int = 0, affiliates: list[xchainpy2_thorchain.memo.Affiliate] = None, dex_aggregator_address: str = '', final_asset_address: str = '', min_amount_out: int = 0, tx_id: str = '', withdraw_portion_bp: int = 0, pool: str = '', node_address: str = '', provider_address: str = '', amount: int = 0, no_vault: bool = False, refund_address: str = '', name: str = '', owner: str = '', chain: str = 'THOR', affiliate_asset: str = '', name_expiry: str | int = '')
Bases:
object- action: ActionType
- classmethod add_liquidity(pool: str, paired_address: str = '', affiliate_address: str = '', affiliate_fee_bp: int = 0, affiliates: List[Affiliate] | None = None)
- classmethod add_savers(pool: str, affiliate_address: str = '', affiliate_fee_bp: int = 0, affiliates: List[Affiliate] | None = None)
- property affiliate_address: str
Returns affiliate address/THORName when there is only one affiliate Returns ‘’ if no affiliates Returns concatenated addresses when multiple affiliates, glued by ‘/’ :return: Affiliate address/name
- affiliate_asset: str = ''
- property affiliate_fee_0_1: float
Returns affiliate fee in 0…1 range when there is only one affiliate
- property affiliate_fee_bp: int
Returns affiliate fee in basis points (0…1000) when there is only one affiliate Returns 0 if no affiliates Returns sum of all affiliates’ fees if multiple affiliates :return: Affiliate fee in basis points
- amount: int = 0
- asset: str = ''
- classmethod bond(node_address: str, provider_address: str = '', fee_bp: int | None = None)
- build()
- chain: str = 'THOR'
- classmethod deposit_trade_account(dest_address: str)
- dest_address: str = ''
- dex_aggregator_address: str = ''
- classmethod donate(pool: str)
- final_asset_address: str = ''
- property has_affiliate_part
Returns True if there are any affiliates :return:
- property is_streaming
- classmethod ith_or_default(a, index, default=None, is_number=False) str | int | float
- classmethod leave(node_address: str)
- limit: int = 0
- classmethod limit_order()
- classmethod loan_close(asset: str, dest_address: str, min_out: int = 0)
- classmethod loan_open(asset: str, dest_address: str, limit: int = 0, affiliate_address: str = '', affiliate_fee_bp: int = 0, affiliates: List[Affiliate] | None = None)
- min_amount_out: int = 0
- name: str = ''
- name_expiry: str | int = ''
- no_vault: bool = False
- node_address: str = ''
- classmethod noop(no_vault=False)
- classmethod outbound(tx_id: str)
- owner: str = ''
- static parse_dest_address(dest_address: str)
- classmethod parse_memo(memo: str, no_raise=False)
- pool: str = ''
- provider_address: str = ''
- classmethod refund(tx_id: str)
- refund_address: str = ''
- classmethod reserve()
- classmethod runepool_add()
- classmethod runepool_withdraw(bp: int, affiliate_address: str = '', affiliate_fee_bp: int = 0, affiliates: List[Affiliate] | None = None)
- s_swap_interval: int = 0
- s_swap_quantity: int = 0
- classmethod swap(asset: str, dest_address: str, limit: int = 0, s_swap_interval: int = 0, s_swap_quantity: int | None = None, affiliate_address: str = '', affiliate_fee_bp: int = 0, affiliates: List[Affiliate] | None = None, dex_aggregator_address: str = '', dex_final_asset_address: str = '', dex_min_amount_out: int = 0, refund_address: str = '')
- classmethod thorname_register_or_renew(name: str, chain: str, address: str, thor_owner: str = '', preferred_asset: str = '', expiry='')
- tx_id: str = ''
- classmethod unbond(node_address: str, amount: int, provider_address: str = '')
- property uses_aggregator_out
- classmethod withdraw(pool: str, withdraw_portion_bp=10000, asset: str = '')
- classmethod withdraw_asset(pool: str, withdraw_portion_bp=10000)
- withdraw_portion_bp: int = 0
- classmethod withdraw_rune(pool: str, withdraw_portion_bp=10000)
- classmethod withdraw_savers(pool: str, withdraw_portion_bp=10000)
- classmethod withdraw_symmetric(pool: str, withdraw_portion_bp=10000)
- classmethod withdraw_trade_account(dest_address: str)
- xchainpy2_thorchain.memo.nothing_if_0(x)
THORChain Utils
- class xchainpy2_thorchain.utils.NativeTxType
Bases:
object- DEPOSIT = 'deposit'
- SEND = 'send'
- UNKNOWN = 'unknown'
- xchainpy2_thorchain.utils.build_deposit_tx_unsigned(what: CryptoAmount, memo: str, signer_public_key: PublicKey, sequence_num: int, prefix: str = 'thor', fee=None, gas_limit=600000000, second_asset: CryptoAmount | None = None) Transaction
- xchainpy2_thorchain.utils.build_transfer_tx_draft(what: CryptoAmount, denom: str, sender: str, recipient: str, prefix: str) Transaction
- xchainpy2_thorchain.utils.convert_coin_to_crypto_amount(coin: Coin, decimals=8) CryptoAmount
- xchainpy2_thorchain.utils.crypto_amount_to_msg_coin(a: CryptoAmount) Coin
- xchainpy2_thorchain.utils.get_native_tx_type(raw_json)
- xchainpy2_thorchain.utils.get_thor_address_prefix(network: NetworkType) str
Get address prefix based on the network. :param network: :return: string address prefix
THORChain Models
- class xchainpy2_thorchain.models.NodeURL(node, rpc)
Bases:
NamedTuple- classmethod from_ip_address(ip_address: str, thornode_port: int, rpc_port: int, protocol='http')
- node: str
Alias for field number 0
- rpc: str
Alias for field number 1
- class xchainpy2_thorchain.models.RPCTxResult(hash, height, index, tx_results, tx)
Bases:
NamedTuple- hash: str
Alias for field number 0
- height: int
Alias for field number 1
- index: int
Alias for field number 2
- tx: str
Alias for field number 4
- tx_results: RPCTxResultInner
Alias for field number 3
- class xchainpy2_thorchain.models.RPCTxResultInner(code, data, log, info, gas_wanted, gas_used, events, codespace)
Bases:
NamedTuple- code: int
Alias for field number 0
- codespace: str
Alias for field number 7
- data: str
Alias for field number 1
- events: list
Alias for field number 6
- gas_used: str
Alias for field number 5
- gas_wanted: str
Alias for field number 4
- info: str
Alias for field number 3
- log: str
Alias for field number 2