DXSP (DeX SwaP), A defi swap helper package. Easy peasy Swap.
Project description
dxsp
DXSP (DeX SwaP), A defi swap helper package. Easy peasy Swap.
Install
pip install dxsp
How to use it
from dxsp import DexSwap
dex = DexSwap(w3,chain_id,wallet_address,private_key,protocol,dex_exchange,block_explorer_api)
tx = await dex.get_swap(10,'USDC','wBTC')
print(tx)
2 swap protocol mode are supported:
- 1inch API v5 (#1 default)
- Uniswap version 2 router DEX type (#2)
Limit SWAP via 1inch API v3 and Uniswap version to be done
.Env
Mandatory
- None
Optional
- TOKENLIST: URL of a standard token list following tokenlist.org format
- TESTTOKENLIST: URL of a standard testnet token list following tokenlist.org format
Example
import os
from dotenv import load_dotenv
import asyncio
from web3 import Web3
import many_abis as ma
#YOUR VARIABLES
load_dotenv()
#chain ID being used refer to https://chainlist.org/
chain_id = os.getenv("CHAIN_ID", 10)
#your wallet details
wallet_address = os.getenv("WALLET_ADDRESS", "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE")
private_key = os.getenv("PRIVATE_KEY", "0x111111111117dc0aa78b770fa6a738034120c302")
#1 for 1inch and 2 for Uniswap V2
protocol = os.getenv("PROTOCOL", 1)
#DATA from MANY_ABIS FOR RPC and EXCHANGE
chain = ma.get_chain_by_id(chain_id=int(chain_id))
network_provider_url = os.getenv("NETWORK_PROVIDER_URL", chain['rpc'][0])
dex_exchange = os.getenv("DEX_EXCHANGE", 'Uniswap V2')
amount_trading_option = os.getenv("AMOUNT_TRADING_OPTION", 1)
#Block explorer API from ETHERSCAN TYPE EXPLORER
block_explorer_api = os.getenv("BLOCK_EXPLORER_API", "1X23Q4ACZ5T3KXG67WIAH7X8C510F1972TM")
#DEX CONNECTIVITY
w3 = Web3(Web3.HTTPProvider(network_provider_url))
+from dxsp import DexSwap
async def main():
#SWAP HELPER
print(w3,chain_id,wallet_address,private_key,protocol,dex_exchange,amount_trading_option,block_explorer_api)
+ dex = DexSwap(w3,chain_id,wallet_address,private_key,protocol,dex_exchange,amount_trading_option,block_explorer_api=block_explorer_api)
#get Contract Address
bitcoinaddress = await dex.search_contract('wBTC')
print("bitcoinaddress ", bitcoinaddress)
#bitcoinaddress 0x68f180fcCe6836688e9084f035309E29Bf0A2095
# check : https://optimistic.etherscan.io/token/0x68f180fcce6836688e9084f035309e29bf0a2095?a=0x5bb949b4938aaf1b2e97f4871a8968a4abea7c98
#getABI
bitcoinaddressABI = await dex.get_abi(bitcoinaddress)
print(bitcoinaddressABI)
#QUOTE
quote = await dex.get_quote('wBTC')
print("quote ", quote)
#BUY 10 USDC of BITCOIN
+ demo_tx = await dex.get_swap('USDC','wBTC',10)
print("demo_tx ", demo_tx)
#NORMAL SWAP
# transaction_amount_out = 10
# asset_out_symbol = "USDT"
# asset_in_symbol = "ETH"
#SWAP EXECUTION
# transaction = await dex.get_swap(transaction_amount_out,asset_out_symbol,asset_in_symbol)
# print("transaction ", transaction)
if __name__ == "__main__":
asyncio.run(main())
Real case
Roadmap
V1
- 1inch API v5 (#1 default)
- Uniswap version 2 router DEX type (#2)
- Limit SWAP via 1inch API v3 (#3)
V2
- Uniswap V3 Support
- Ox or other API based swap or orderbook platfrom
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dxsp-0.0.39.tar.gz
(10.3 kB
view details)
Built Distribution
dxsp-0.0.39-py3-none-any.whl
(9.7 kB
view details)
File details
Details for the file dxsp-0.0.39.tar.gz
.
File metadata
- Download URL: dxsp-0.0.39.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9e5b86b49dea2f38bddcbc7246674e871f0ea6233c582d062c0631751d3e011 |
|
MD5 | ad06ecb483d84147d90bc8a5ab4ffe6c |
|
BLAKE2b-256 | d40c1d09765c1779c73f4f07a81ccc1d5004cea193a8c4c85cc967361a3930b4 |
File details
Details for the file dxsp-0.0.39-py3-none-any.whl
.
File metadata
- Download URL: dxsp-0.0.39-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67608da1b0e1daf08193c65f778a37ab89ba0ed5afbdc138103774e3703978e3 |
|
MD5 | 28f003de8d1d1964137b66d00440730d |
|
BLAKE2b-256 | 6dfee0c1b6002960cda98bdaac6bfb7a5d15284df3a56a541c40f6965cf4aa34 |