0

Code

This code works fine with kovan testnet like i can deposit but when trying on mainnet-fork it give safemath overflow error:

Brownie v1.19.0 - Python development framework for Ethereum

AaveBrowniePyProject is the active project.

Launching 'ganache-cli.cmd --accounts 10 --fork https://eth-mainnet.alchemyapi.io/v2/_Z-H35Cw4-kIaLun7L14IU92c1AcDNYx --mnemonic brownie --port 8545 --hardfork istanbul'...

Running 'scripts\aave_borrow.py::main'... Transaction sent: 0x9faf515e94a14b4d2f9355a8263748bfda87d7a7932fe7f9a037f27db81ac7e2 Gas price: 0.0 gwei Gas limit: 6721975 Nonce: 5 Transaction confirmed Block: 15109440 Gas used: 43738 (0.65%)

Transaction confirmed Block: 15109440 Gas used: 43738 (0.65%)

Recieved 0.1 WEth !!! Approving ERC20 token !!! Transaction sent: 0x505c439cbf32efef0620308f31bf1a6ded9d710b15e0ae90cccf2d27c3ce2b60 Gas price: 0.0 gwei Gas limit: 6721975 Nonce: 6 Transaction confirmed Block: 15109441 Gas used: 43952 (0.65%)

Transaction confirmed Block: 15109441 Gas used: 43952 (0.65%)

Approved !!! Depositing !!! Transaction sent: 0x63e8960252b8a116d292809754f6773edef7b3c7ea64fb18ce6de9acd66975c5 Gas price: 0.0 gwei Gas limit: 6721975 Nonce: 7 Transaction confirmed (SafeMath: subtraction overflow) Block: 15109442 Gas used: 38086 (0.57%)

File "C:\Users\amanp.local\pipx\venvs\eth-brownie\lib\site-packages\brownie_cli\run.py", line 51, in main return_value, frame = run( File "C:\Users\amanp.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\project\scripts.py", line 110, in run return_value = f_locals[method_name](*args, **kwargs) File ".\scripts\aave_borrow.py", line 21, in main tx = lending_pool.deposit(erc20_address, AMOUNT, account.address, 0, {"from": account}) File "C:\Users\amanp.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py", line 1861, in call return self.transact(*args) File "C:\Users\amanp.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\contract.py", line 1734, in transact return tx["from"].transfer( File "C:\Users\amanp.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\account.py", line 682, in transfer receipt._raise_if_reverted(exc) File "C:\Users\amanp.local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\transaction.py", line 446, in _raise_if_reverted raise exc._with_attr( VirtualMachineError: revert: SafeMath: subtraction overflow Terminating local RPC client...

from scripts.helpful_scripts import get_account
from scripts.get_weth import get_weth
from web3 import Web3

AMOUNT = Web3.toWei(0.1, "ether")

def main():
account = get_account(1)
erc20_address = config["networks"][network.show_active()]["weth_token"]
if network.show_active() in ["mainnet-fork"]:
get_weth()
lending_pool = get_lending_pool()

approve_erc20_tokens(AMOUNT, lending_pool.address, erc20_address, account)

print("Depositing !!!")
tx = lending_pool.deposit(erc20_address, AMOUNT, account.address, 0, {"from": account})
tx.wait(1)
print("Deposited !!!")

def approve_erc20_tokens(amount, spender, erc20_address, account):
print("Approving ERC20 token !!!")
erc20 = interface.IERC20(erc20_address)
tx = erc20.approve(spender, amount, {"from": account})
tx.wait(1)
print("Approved !!!")
return tx

def get_lending_pool():
lending_pool_addresses_provider = interface.ILendingPoolAddressesProvider(config["networks"][network.show_active()]["lending_pool_addresses_provider"])
lending_pool_address = lending_pool_addresses_provider.getLendingPool()

lending_pool = interface.ILendingPool(lending_pool_address)
return lending_pool**strong text**
  • You should never publicly post/upload you API key. I recommend censoring your key ASAP. – Derawi Jul 10 '22 at 08:01
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 10 '22 at 17:30
  • Can you please follow this guide to re-format your question: https://stackoverflow.com/help/how-to-ask – Patrick Collins Jul 11 '22 at 12:30

0 Answers0