Package: tfm-sdk
TFM SDKAsynchronous usagePreferred way to use the SDK is to use it as an asynchronous context manager. This way the SDK will be closed properly and all resources will be released.SDK usage examplesSee alsoexamplesfolder for more.Get chain(s)fromtfm_sdkimportTfmSdkfromtfm_sdk.typesimportChain,Token,NetworkType,RouteOperationSwap,SwapPairasyncwithTfmSdk()assdk:# chains loads automatically# list of chainschains:list[Chain]=sdk.chains.get_list()# get chain by name or idterra:Chain=sdk.chains.find("phoenix-1")# mainnet chainsmainnet_chains:list[Chain]=sdk.chains.mainnet_only()# reachable chains for swap from terraterra_swap_chains:list[Chain]=awaitsdk.chains.get_reachable(terra)Get tokensasyncwithTfmSdk()assdk:# chains loads automatically# get chain by name or idterra:Chain=sdk.chains.find("phoenix-1")assertterra.network_type==NetworkType.MAINNET# get all chain tokenstokens:list[Token]=awaitterra.get_tokens()# get token priceuluna:Token=awaitterra.get_token_by_denom("uluna")price:float=awaituluna.get_price()Transfer token from one chain to anotherasyncwithTfmSdk()assdk:from_chain=sdk.chains.find("phoenix-1")to_chain=sdk.chains.find("osmosis-1")sdk.set_source_chain(from_chain)sdk.set_destination_chain(to_chain)# call sdk.reverse() to swap chains# tokens transferable from terra to osmotransferable_tokens:list[SwapPair]=awaitsdk.transfer.get_transferable_tokens()# route and msg to transfer token from phoenix-1 to osmosis-1route=awaitsdk.transfer.get_route(transferable_tokens[0],1000)msg=awaitsdk.transfer.get_msg(transferable_tokens[0],1000)combined_msg=awaitsdk.transfer.get_route_swap(transferable_tokens[0],1000)Dex operationsasyncwithTfmSdk()assdk:chain=sdk.chains.find("phoenix-1")token0=awaitchain.get_token_by_denom("uluna")token1=awaitchain.get_token_by_denom("terra1vzd98s9kqdkatahxs7rsd8m474lf2f8ct39zdgd6shj4nh5e6kuskaz2gy")route=awaitsdk.dex.get_route(chain,token0,token1,amount=10000)msg=awaitsdk.dex.get_msg(chain,token0,token1,amount=10000,slippage=0.01)Swap operationsasyncwithTfmSdk()assdk:chain_from=sdk.chains.find("Terra")chain_to=sdk.chains.find("juno-1")sdk.set_source_chain(chain_from)sdk.set_destination_chain(chain_to)token0=awaitchain_from.get_token_by_denom("uluna")token1=awaitchain_to.get_token_by_denom("ujuno")pair=SwapPair(source_token=token0,destination_token=token1,)route=awaitsdk.swap.get_route(pair,1000000)msgs=awaitsdk.swap.get_msg(pair,1000000,slippage=0.01)route_and_msgs=awaitsdk.swap.get_route_swap(pair,1000000,slippage=0.01)Check API healthasyncwithTfmSdk()assdk:is_online:bool=awaitsdk.is_api_online()Low level apifromtfm_sdk.apiimportTfmApiasyncwithTfmApi()asapi:chain=api.chains.get_chains()...# orapi=TfmApi()...awaitapi.close()Low level api usage examplesGet chain(s)all_chains=awaitapi.chains.get_chains()mainnet_chains=awaitapi.chains.get_chains(network_type='mainnet',is_trading=True)Get chain tokenstokens=awaitapi.chains.get_tokens(chain_id='phoenix-1')native_tokens=awaitapi.chains.get_tokens(chain_id='phoenix-1',token_type='native')Dex methodsroute=awaitapi.dex.get_route(chain_id='phoenix-1',token0='uluna',token1='uusd',amount=1000000)msg=awaitapi.dex.get_msg(chain_id='phoenix-1',token0='uluna',token1='uusd',amount=1000000,slippage=0.01)Get priceprice=awaitapi.price.get_price('phoenix-1','uluna')price_at_timestamp=awaitapi.price.get_price('phoenix-1','uluna',timestamp=1620000000)IBC methods to transfer tokens# where we can send tokens from phoenix-1reachable_chains=awaitapi.ibc.chain.get_reachable('phoenix-1')# can we send uluna from phoenix-1 to osmosis-1is_reachable=awaitapi.ibc.chain.is_reachable('phoenix-1','osmosis-1','uluna')# get list of tokens we can transfer from phoenix-1 to osmosis-1transferable_tokens=awaitapi.ibc.chain.get_transferable_tokens('phoenix-1','osmosis-1')# can we transfer uluna from phoenix-1 to osmosis-1is_token_transferable=awaitapi.ibc.chain.is_token_transferable('phoenix-1','osmosis-1','uluna')# get route to transfer uluna from phoenix-1 to osmosis-1route=awaitapi.ibc.transfer.get_route('uluna','phoenix-1','ibc/785AFEC6B3741100D15E7AF01374E3C4C36F24888E96479B1C33F5C71F364EF9',# uluna ibc address in osmosis-1'osmosis-1',amount=1000000)# msg to send to blockchainmsg=awaitapi.ibc.transfer.get_msg('uluna','phoenix-1','ibc/785AFEC6B3741100D15E7AF01374E3C4C36F24888E96479B1C33F5C71F364EF9',# uluna ibc address in osmosis-1'osmosis-1',amount=1000000,slippage=0.01)# combined method returns both route and msgmsg_and_route=awaitapi.ibc.transfer.get_route_msg_combined('uluna','phoenix-1','ibc/785AFEC6B3741100D15E7AF01374E3C4C36F24888E96479B1C33F5C71F364EF9',# uluna ibc address in osmosis-1'osmosis-1',amount=1000000,slippage=0.01)IBC methods to swap token for token cross chain# get route to transfer uluna from phoenix-1 to osmosis-1route=awaitapi.ibc.swap.get_route('uluna','phoenix-1','ibc/9F9B07EF9AD291167CF5700628145DE1DEB777C2CFC7907553B24446515F6D0E',# USDC'osmosis-1',amount=1000000,swap_mode="Turbo",# or Savings)# msg to send to blockchainmsg=awaitapi.ibc.swap.get_msg('uluna','phoenix-1','ibc/9F9B07EF9AD291167CF5700628145DE1DEB777C2CFC7907553B24446515F6D0E',# USDC'osmosis-1',amount=1000000,slippage=0.01,swap_mode="Turbo",# or Savings)# combined method returns both route and msgmsg_and_route=awaitapi.ibc.swap.get_route_msg_combined('uluna','phoenix-1','ibc/9F9B07EF9AD291167CF5700628145DE1DEB777C2CFC7907553B24446515F6D0E',# USDC'osmosis-1',amount=1000000,slippage=0.01,swap_mode="Turbo",# or Savings)Sync version of api clientSeeexamplesfolder for more.fromtfm_sdk.apiimportTfmApiSyncapi=TfmApiSync()is_api_healthty=api.health()# get list of chainschains=api.chain.get_chains(network_type="mainnet")Run testspoetry install
poe test_unit