0

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:

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?

1 Answer 1

0

You are trying to send ETH (FTM in this case) in your transaction: "value": Web3.toWei(balance+1, "ether")}). but swapExactTokensForETH is a non-payable function, which would cause a revert. You are trying to give the contract TOMB and receive FTM, so there is no reason to pay the contract your FTM. Also make sure that both contracts have sufficient allowance to take your TOMB (done via ERC20.approve())

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.