I am developing a trading bot, that directly interacts with smart contracts on Fantom, an EVM compatible blockchain. Smart contracts I tried in order to swap TOMB tokens to FTM tokens:
- Solidly
- SpookySwap (UniSwap fork)
Python code that results in reverted transactions:
from brownie import Contract, accounts, config, network, interface
balance = 1
network.gas_limit( 305000 )
solidly_contract = Contract.from_explorer(solidly_contract_address)
account = accounts.add(config["wallets"]["from_key"])
solidly_contract.swapExactTokensForFTM(
Web3.toWei(balance, "ether"),
Web3.toWei(balance, "ether")*0.9,
[tomb_contract, ftm_contract, True]],
account,
int(time.time())+2*60,
{"from": account, "value": Web3.toWei(balance+1, "ether")})
spooky_swap_contract.swapExactTokensForETH(
Web3.toWei(balance, "ether"),
Web3.toWei(balance, "ether")*0.9,
[tomb_contract, ftm_contract],
account,
int(time.time())+2*60,
{"from": account, "value": Web3.toWei(balance*2, "ether")})
However, bot contract calls result only in
ValueError: Execution reverted during call: 'execution reverted'. This transaction will likely revert. If you wish to broadcast, include `allow_revert:True` as a transaction parameter.
I have no idea what I am doing wrong here. However, when calling those functions directly using ftmscan, the transaction succeeds. I also tried swapExactTokensForTokens on both contracts, with no result. Just to be clear, I have enough TOMB and FTM for the transaction, so the insufficient funds should not be the problem.
Any ideas how to make the transaction go through?