0

I'm currently using web3.py to try to buy tokens using a script, but I'm currently having some issues. Question 1. If the LP pair of token is USDT https://poocoin.app/tokens/0x2f0D30A46CAc1197F93679e39c7B1D1652Bad6bf, and I use WBNB to buy, call the swapExactETHForTokens method, then Route: WBNB→USDT→token[ex: YES DAO], this is after 2 router exchanges.

pancakeswap_txn = contract.functions.swapExactETHForTokens(
    amountOutMin,
    [spend,usdt,buyToken],  #WBNB → USDT → token
    senderAddress,
    (int(start) + 10000)
).buildTransaction({
    'from':senderAddress,
    'value':web3.toWei(0.0001,'ether'),
    'gas':500000, 
    'gasPrice': web3.toWei('5', 'gwei'),
    'nonce':nonce
})

But if the LP pair of the token only has the WBNB transaction pair, for example: https://poocoin.app/tokens/0xffad7f9f704a5fdc6265e24b436b4b35ed52def2, then if the swapExactETHForTokens method is used, then the router conversion of WBNB→USDT→token cannot be used, it must be WBNB →token

pancakeswap_txn = contract.functions.swapExactETHForTokens(
    amountOutMin,
    [spend,buyToken], # WBNB→ token
    senderAddress,
    (int(start) + 10000)
).buildTransaction({
    'from':senderAddress,
    'value':web3.toWei(0.0001,'ether'),
    'gas':500000,  
    'gasPrice': web3.toWei('5', 'gwei'),
    'nonce':nonce
})

If you use swapExactTokensForTokens method,How should I get the value of amountIn and amountOutMin similar。enter image description here

Question 2: Now a token has two trading pairs, that is, two LP Pair addresses such as: https://poocoin.app/tokens/0x84DFDb5F025011572D7167201D89573e3fF6A7e3, its largest LP is USDT LP, and its BNB LP is only 0.02B , if I use the python script to purchase using swapExactETHForTokens, then I will definitely buy the BNB LP pool, so I will lose my money, then how to get the largest LP pair address in the smart contract, and then execute the purchase before the steps Judge the size of the pool, so as not to buy the wrong one.enter image description here

1 Answer 1

1

I have found it, get the getPair function after instantiating the factory contract

token_a = web3.toChecksumAddress(token_input)
token_b = web3.toChecksumAddress(wbnb)
pair_traded = [token_a.lower(), token_b.lower()]  # token_a, token_b are the address's
pair_traded.sort()
hexadem = '0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5'
abiEncoded_1 = encode_abi_packed(['address', 'address'], (pair_traded[0], pair_traded[1]))
salt_ = web3.solidityKeccak(['bytes'], ['0x' + abiEncoded_1.hex()])
abiEncoded_2 = encode_abi_packed(['address', 'bytes32'], (factoryAddress, salt_))
pair_address = web3.toChecksumAddress(web3.solidityKeccak(['bytes', 'bytes'], ['0xff' + abiEncoded_2.hex(), hexadem])[12:])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.