def test_sushiswap(): u = UniswapV2Client(dfb.config('address'), dfb.config('private_key'), provider=dfb.config('provider'), router_config="sushiswap") # USDT/ETH assert(u.get_pair('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48') \ == '0x397FF1542f962076d0BFE58eA045FfA2d347ACa0') assert(u.get_reserves_graphql('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', 11548680) == \ [104737025632327970998821, 75552143369019, 1599678405])
def uniswap(self, router: Optional[str]=None) -> UniswapV2Client: if router is None: router = self.router_config if router not in self._uniswap: if 'provider_archive' in self._config: provider = self.config('provider_archive') else: provider = self.config('provider') self._uniswap[router] = UniswapV2Client( self.config('address'), self.config('private_key'), provider=provider, router_config=router ) return self._uniswap[router]
import eth_tokens from uniswap.uniswap import UniswapV2Client from eth_client import EthClient from erc_20_token import Erc20Token from configparser import ConfigParser cfg = ConfigParser() cfg.read("app.ini") privateKey = cfg.get('main', 'privateKey') address = cfg.get('main', 'address') print("读取账户成功:", address) ethClient = EthClient(network="mainnet") uniSwap = UniswapV2Client(address=address, private_key=privateKey, provider=defaults.CONF_MAINNET.get("http")) ROOM = Erc20Token(contract_address=eth_tokens.TOKEN_ROOM, web3=ethClient.web3) USDT = Erc20Token(contract_address=eth_tokens.TOKEN_USDT, web3=ethClient.web3) WETH = Erc20Token(contract_address=eth_tokens.TOKEN_WETH, web3=ethClient.web3) # 设置gas价格 uniSwap.gasPrice = eth_utils.to_wei(50, "gwei") IN_TOKEN = USDT OUT_TOKEN = ROOM # 买入总额 500刀 IN_AMOUNT = 500 # 交易滑点 0.5% , 增加成功率的话可以调高一点
from uniswap.uniswap import UniswapV2Client from uniswap.uniswap import UniswapV2Utils as utils import threading import random config = json.load(open('config.json')) network = config['network'] address = config['address'] privkey = config['privkey'] http_addr = config[network]['http'] wss_addr = config[network]['wss'] printer_addr = config['printer'][network] printer_sushi_addr = config['printer_sushi'] printer_abi = json.load(open('abi/printer.json')) uni = UniswapV2Client(address, privkey, http_addr) w3 = Web3(HTTPProvider(http_addr, request_kwargs={'timeout': 6000})) ws = Web3(WebsocketProvider(wss_addr)) pairABI = json.load(open('abi/IUniswapV2Pair.json'))['abi'] erc20abi = json.load(open('./abi/erc20.abi')) printer = w3.eth.contract(address=printer_addr, abi=printer_abi) printer_sushi = w3.eth.contract(address=printer_sushi_addr, abi=printer_abi) usdc = config['usdc'][network] ycrv = config['ycrv'][network] weth = config['weth'][network] usdt = config['usdt'][network] dai = config['dai'][network] yycrv = w3.toChecksumAddress("0x199ddb4bdf09f699d2cf9ca10212bd5e3b570ac2")
"outputs": [{ "name": "", "type": "uint8" }], "type": "function" }] my_provider = Web3.HTTPProvider(NETWORK) w3 = Web3(my_provider) return w3.eth.contract(Web3.toChecksumAddress(ACC), abi=minABI) if __name__ == "__main__": print("bot start!!!") client = UniswapV2Client(ACC, PRIVATE_KEY, provider=NETWORK_WSS) my_balance = get_my_balance() print('my balance: ' + str(my_balance)) b_token_balance = get_my_token_balance() print("B token = " + B_TOKEN) print("B token balance: " + str(b_token_balance)) '''get W-eth token''' WETH_ADDRESS = client.get_weth_address() print("W-eth address = " + WETH_ADDRESS) ''' check liquid added or not''' while True: pair = client.get_pair(WETH_ADDRESS, B_TOKEN) if pair == '0x0000000000000000000000000000000000000000':
def setUp(self): self.uniswap = UniswapV2Client(self.address, self.private_key, self.provider)
def setUpClass(cls): cls.factory = Web3.toChecksumAddress( "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f") cls.link_token = Web3.toChecksumAddress( "0x20fe562d797a42dcb3399062ae9546cd06f63280") cls.weth_token = Web3.toChecksumAddress( "0xc778417E063141139Fce010982780140Aa0cD5Ab") cls.link_weth_pair = Web3.toChecksumAddress( "0x98A608D3f29EebB496815901fcFe8eCcC32bE54a") with open( os.path.abspath( f"{os.path.dirname(os.path.abspath(__file__))}/config.json" )) as f: raw_json = json.load(f) cls.address = Web3.toChecksumAddress(raw_json["account"]["address"]) cls.private_key = raw_json["account"]["private-key"] cls.provider = raw_json["provider"] cls.token_0 = raw_json["tokens"][0] # Token A for the ERC20-ERC20 pair cls.token_1 = raw_json["tokens"][1] # Token B for the ERC20-ERC20 pair cls.token_2 = raw_json["tokens"][2] # Token for the ERC20-WETH pair uniswap = UniswapV2Client(cls.address, cls.private_key, provider=cls.provider) # create a pair for token_0/token_1 if not already created cls.token_pair = uniswap.get_pair(cls.token_0["address"], cls.token_1["address"]) if cls.token_pair == "0x0000000000000000000000000000000000000000": print("Creating ERC20-ERC20 pair...") token_tx = uniswap.add_liquidity( token_a=cls.token_0["address"], token_b=cls.token_1["address"], amount_a=int(cls.token_0["supply"] * 10**-1), # 1/10 of the total supply of A amount_b=int(cls.token_1["supply"] * 10**-1), # 1/10 of the total supply of B min_a=int(cls.token_1["supply"] / cls.token_0["supply"] * 1.01), # allow 1% slippage on B/A min_b=int(cls.token_0["supply"] / cls.token_1["supply"] * 1.01), # allow 1% slippage on B/A to=cls.address, deadline=int(time.time() + 10**3)) uniswap.conn.eth.waitForTransactionReceipt(token_tx, timeout=2000) cls.token_pair = uniswap.get_pair(cls.token_0["address"], cls.token_1["address"]) # create a pair for token_2/weth if not already created cls.weth_pair = uniswap.get_pair(cls.token_2["address"], uniswap.get_weth_address()) if cls.weth_pair == "0x0000000000000000000000000000000000000000": print("Creating ERC20-WETH pair...") weth_tx = uniswap.add_liquidity_eth( token=cls.token_2["address"], amount_token=int( cls.token_2["supply"] * 10**-1), # 1/10 of the total supply of the token amount_eth=100, # 100 wei min_token=int(1000 / cls.token_2["supply"] * 1.01), # allow 1% slippage on B/A min_eth=int(cls.token_2["supply"] / 1000 * 1.01), # allow 1% slippage on B/A to=cls.address, deadline=int(time.time() + 10**3)) uniswap.conn.eth.waitForTransactionReceipt(weth_tx, timeout=2000) cls.weth_pair = uniswap.get_pair(cls.token_2["address"], uniswap.get_weth_address())