if not utils.is_contract(c.get_account(FACTORY_ADDRESS)):
    raise Exception(f"{FACTORY_ADDRESS} is not a smart contract")

if not utils.is_contract(c.get_account(token_1_address)):
    raise Exception(f"{token_1_address} is not a smart contract")

if not utils.is_contract(c.get_account(token_2_address)):
    raise Exception(f"{token_2_address} is not a smart contract")

# Call on factory to create a pool of token 1 and token 2
response = c.transact(w, factory_contract, 'createPair',
                      [token_1_address, token_2_address], FACTORY_ADDRESS)
tx_id = response['id']

# Wait for Receipt
receipt = c.wait_for_tx_receipt(tx_id, 30)
if not receipt:
    raise Exception(f"receipt not found! by tx id: {tx_id}")

# Print deployed address
if utils.is_reverted(receipt):
    print(c.replay_tx(tx_id))
    raise Exception(f"{tx_id} is reverted!")

print('createPair() call success, tx_id:', tx_id)

# Read newly created pool contract address
response = c.call(w.getAddress(), factory_contract, 'getPair',
                  [token_1_address, token_2_address], FACTORY_ADDRESS)
print(response['decoded']['0'])
if not utils.is_contract(c.get_account(token_1_address)):
    raise Exception(f"{token_1_address} is not a smart contract")

if not utils.is_contract(c.get_account(token_2_address)):
    raise Exception(f"{token_2_address} is not a smart contract")

# Call to approve() vtho to be used by router02
response = c.transact(w, erc20_contract, 'approve',
                      [ROUTER02_ADDRESS, token_2_amount], token_2_address)
tx_id = response['id']
receipt = c.wait_for_tx_receipt(tx_id, 30)
if not receipt:
    raise Exception(f"receipt not found! by tx id: {tx_id}")

assert utils.is_reverted(receipt) == False
print('approve tx_id', tx_id)

# Call to deposit vet and vtho
response = c.transact(w, router02_contract, 'addLiquidityETH', [
    token_2_address, token_2_amount,
    round(token_2_amount * 0.9),
    round(token_1_amount * 0.9),
    w.getAddress(),
    int(time.time()) + 1000
], ROUTER02_ADDRESS, token_1_amount)
tx_id = response['id']
receipt = c.wait_for_tx_receipt(tx_id, 30)
if not receipt:
    raise Exception(f"receipt not found! by tx id: {tx_id}")