Code Monkey home page Code Monkey logo

tunaswap's Introduction

TunaSwap

A high level interface for swapping tokens on Terra(Luna) blockchain based on the Terra.py SDK

Disclaimer

This project is by no means affiliated with any dog shit on Binance Smart Chain. The author does not assume responsibilities for the use of the code, nor is warranty granted.

Features

  • Support Terraswap, Astroport , Loop, Prism and native swaps using Terra's built-in market module
  • Fully async
  • Simulate and predict actual trading price locally
  • Find the best route with the least spread for a swap
  • Create, sign and broadcast transactions
  • Limit order and stop loss order
  • Manage Anchor LTV

Usage Examples

Simulate swap result on a specific pair

>>> from order import *
>>> await Pool('bLuna', 'Luna', 'terra_swap').simulate('LUNA', 100)
From 100.0 luna To 100.708998 bluna
Rate 1.007090 bluna per luna
Spread 0.330% Commission 0.303036 bluna

Find the best route with the least spread for a swap

>>> await Dex('terra_swap').dijkstra_routing('nLuna', 100, 'bLuna')
Route(100.0 nluna -> 191475.553937 psi -> 7275.843784 ust -> 89.299495 luna -> 89.618139 bluna on terra_swap)

Meanwhile, Terraswap gives

multi_hop_swap

OrderBook accepts and executes limit order or stop loss order.

>>> book = OrderBook('astro_swap')
>>> book.submit(StopLoss('', 'bluna', 1, 'ust', price=1000))
>>> book.submit(LimitOrder('', 'ust', 100, 'luna', price=0.001))
>>> task = asyncio.create_task(book.start(broker=True))
Open stop order 1: 1000.0 ust -> 1.0 luna on astro_swap
Trigger price 0.001 luna per ust
Open limit order 2: 1.0 luna -> 1000.0 ust on astro_swap
Limit price 1000 ust per luna

1   Query price
2   Place order
3   Cancel order
4   Pending orders
q   Quit

Create, sign and broadcast transaction

>>> msgs = await Dex('terra_swap').swap('nLuna', 100, 'bLuna')
>>> tx = await wallet.create_and_sign_tx(msgs, memo='')
>>> result = await wallet.broadcast(tx)

Query pair info on DEX

>>> await pair_query('terra_swap', 'ust', 'bluna')
{'asset_infos': [{'token': {'contract_addr': 'terra1kc87mu460fwkqte29rquh4hc20m54fxwtsx7gp'}},
                 {'native_token': {'denom': 'uusd'}}],
 'contract_addr': 'terra1qpd9n7afwf45rkjlpujrrdfh83pldec8rpujgn',
 'liquidity_token': 'terra1qmr8j3m9x53dhws0yxhymzsvnkjq886yk8k93m'}

Validate local pairs' info with blockchain

>>> await validate_pool_info()

Installation

Install Python 3.10+ and required packages.

pip install -r requirements.txt

Save seed phrases in a specific file or generate new ones.

Set testnet = False in consts.py for mainnet.

python main.py

License

This project is licensed under the AGPL-3.0 License. See LICENSE for full disclosure.

Permissions of this license are conditioned on making available complete source code of licensed works and modifications, which include larger works using a licensed work, under the same license. Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. When a modified version is used to provide a service over a network, the complete source code of the modified version must be made available.

tunaswap's People

Contributors

aureliano90 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tunaswap's Issues

Collaborate

Are you interested in collaborating? If so, do you have an email I can reach out to you at?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.