Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Make Goerli work again #275

Merged
6 changes: 3 additions & 3 deletions raiden_installer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class Settings:
client_release_channel: str
client_release_version: str
services_version: str
ethereum_amount_required: int
ethereum_amount_required_after_swap: int
service_token: TokenSettings
transfer_token: TokenSettings
ethereum_amount_required: int
ethereum_amount_required_after_swap: int = 0
routing_mode: str = "pfs"
monitoring_enabled: bool = True
# matrix_server and pfs address are only used if client_release_channel = "demo_env"
Expand Down Expand Up @@ -63,6 +63,6 @@ def _get_settings(network):
return Settings(**configuration_data)


_NETWORKS = ["mainnet"]
_NETWORKS = ["mainnet", "goerli"]
network_settings = {network: _get_settings(network) for network in _NETWORKS}
default_settings = network_settings["mainnet"]
2 changes: 1 addition & 1 deletion raiden_installer/raiden.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def version(self):

class RaidenTestnetRelease(RaidenClient):
BINARY_NAME_FORMAT = "raiden-testnet-{release}"
FILE_NAME_PATTERN = r"raiden-v(?P<major>\d+)\.(?P<minor>\d+)\.(?P<revision>\d+)(?P<extra>.+)"
FILE_NAME_PATTERN = r"raiden-v(?P<major>\d+)\.(?P<minor>\d+)\.(?P<revision>\d+)(?P<extra>.*)"

@property
def version(self):
Expand Down
10 changes: 6 additions & 4 deletions raiden_installer/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,12 @@ class TokensV37(Enum):
RDN = Erc20Token(
ticker="RDN",
wei_ticker="REI",
addresses={
"goerli": "0xc116edAD88cda44E703ef1fc59766268E4aa187B",
"mainnet": "0x255aa6df07540cb5d3d297f0d0d4d84cb52bc8e6",
},
addresses={"mainnet": "0x255aa6df07540cb5d3d297f0d0d4d84cb52bc8e6"},
)
SVT = Erc20Token(
ticker="SVT",
wei_ticker="SEI",
addresses={"goerli": "0x5Fc523e13fBAc2140F056AD7A96De2cC0C4Cc63A"},
)
DAI = _DAI
WIZ = _WizardToken
Expand Down
4 changes: 0 additions & 4 deletions raiden_installer/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def deposit_service_tokens(w3: Web3, account: Account, token: Erc20Token, amount
def approve(w3, account, allowed_address, allowance: Wei, token: Erc20Token):
token_proxy = _make_token_proxy(w3=w3, token=token)
old_allowance = token_proxy.functions.allowance(account.address, allowed_address).call()
nonce = w3.eth.getTransactionCount(account.address)

if old_allowance > 0:
send_raw_transaction(
Expand All @@ -77,9 +76,7 @@ def approve(w3, account, allowed_address, allowance: Wei, token: Erc20Token):
allowed_address,
0,
gas=GAS_REQUIRED_FOR_APPROVE,
nonce=nonce,
)
nonce += 1

transaction_receipt = send_raw_transaction(
w3,
Expand All @@ -88,7 +85,6 @@ def approve(w3, account, allowed_address, allowance: Wei, token: Erc20Token):
allowed_address,
allowance,
gas=GAS_REQUIRED_FOR_APPROVE,
nonce=nonce,
)

wait_for_transaction(w3, transaction_receipt)
Expand Down
4 changes: 2 additions & 2 deletions raiden_installer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_contract_address(chain_id, contract_name):
def estimate_gas(w3, account, contract_function, *args, **kw):
transaction_params = {
"chainId": int(w3.net.version),
"nonce": w3.eth.getTransactionCount(account.address),
"nonce": w3.eth.getTransactionCount(account.address, "pending"),
}
transaction_params.update(**kw)
result = contract_function(*args)
Expand All @@ -50,7 +50,7 @@ def estimate_gas(w3, account, contract_function, *args, **kw):
def send_raw_transaction(w3, account, contract_function, *args, **kw):
transaction_params = {
"chainId": int(w3.net.version),
"nonce": w3.eth.getTransactionCount(account.address),
"nonce": w3.eth.getTransactionCount(account.address, "pending"),
"gasPrice": kw.pop("gas_price", (w3.eth.generateGasPrice())),
"gas": kw.pop("gas", None),
}
Expand Down
96 changes: 64 additions & 32 deletions raiden_installer/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ def _send_txhash_message(self, text, tx_hash):
self.write_message(message)
log.info(f"Waiting for confirmation of txhash {tx_hash}")

def _send_next_step(self, message_text, title, step):
if not isinstance(message_text, list):
message_text = [message_text]
body = {"type": "next-step", "text": message_text, "title": title, "step": step}
self.write_message(json.dumps(body))
log.info(" ".join(message_text))
log.info(f"Update progress to step {step}: {title}")

def on_message(self, message):
data = json.loads(message)

Expand All @@ -154,14 +162,22 @@ def on_message(self, message):
"create_wallet": self._run_create_wallet,
"swap": self._run_swap,
"track_transaction": self._run_track_transaction,
"fund": self._run_funding,
}.get(method)

return action and action(**data)

def _run_close(self, **kw):
sys.exit()

def _run_funding(self, configuration_file: RaidenConfigurationFile):
def _run_funding(self, **kw):
try:
configuration_file_name = kw.get("configuration_file_name")
configuration_file = RaidenConfigurationFile.get_by_filename(configuration_file_name)
except Exception as exc:
self._send_error_message(str(exc))
return

network = configuration_file.network
settings = network_settings[network.name]

Expand All @@ -179,19 +195,57 @@ def _run_funding(self, configuration_file: RaidenConfigurationFile):
balance = account.wait_for_ethereum_funds(w3=w3, expected_amount=EthereumAmount(0.01))
self._send_status_update(f"Account funded with {balance.formatted}")

service_token = Erc20Token.find_by_ticker(
settings.service_token.ticker, settings.network
)

if settings.service_token.mintable:
service_token = Erc20Token.find_by_ticker(
settings.service_token.ticker, settings.network
self._send_next_step(
f"Minting {service_token.ticker}",
f"Fund Account with {service_token.ticker}",
3,
)
self._send_status_update(f"Minting {service_token.ticker}")
mint_tokens(w3, account, service_token)
transaction_receipt = mint_tokens(w3, account, service_token)
wait_for_transaction(w3, transaction_receipt)

service_token_balance = get_token_balance(w3, account, service_token)

if service_token_balance.as_wei > 0:
self._run_udc_deposit(w3, account, service_token, service_token_balance)

if settings.transfer_token.mintable:
transfer_token = Erc20Token.find_by_ticker(
settings.transfer_token.ticker, settings.network
)
self._send_status_update(f"Minting {transfer_token.ticker}")
mint_tokens(w3, account, transfer_token)
self._send_next_step(
f"Minting {transfer_token.ticker}",
f"Fund Account with {transfer_token.ticker}",
4,
)
transaction_receipt = mint_tokens(w3, account, transfer_token)
wait_for_transaction(w3, transaction_receipt)

self._send_redirect(self.reverse_url("launch", configuration_file_name))

def _run_udc_deposit(self, w3, account, service_token, service_token_balance):
self._send_status_update(
f"Making deposit of {service_token_balance.formatted} to the "
"User Deposit Contract"
)
self._send_status_update(f"This might take a few minutes")
transaction_receipt = deposit_service_tokens(
w3=w3,
account=account,
token=service_token,
amount=service_token_balance.as_wei,
)
wait_for_transaction(w3, transaction_receipt)
service_token_deposited = get_token_deposit(
w3=w3, account=account, token=service_token
)
self._send_status_update(
f"Total amount deposited at UDC: {service_token_deposited.formatted}"
)

def _run_unlock(self, **kw):
passphrase = kw.get("passphrase")
Expand Down Expand Up @@ -246,12 +300,8 @@ def _run_setup(self, **kw):
enable_monitoring=form.data["use_rsb"],
)
conf_file.save()

if network.FAUCET_AVAILABLE:
self._run_funding(configuration_file=conf_file)
self._send_redirect(self.reverse_url("launch", conf_file.file_name))
else:
self._send_redirect(self.reverse_url("account", conf_file.file_name))

self._send_redirect(self.reverse_url("account", conf_file.file_name))
else:
self._send_error_message(f"Failed to create account. Error: {form.errors}")

Expand Down Expand Up @@ -371,25 +421,7 @@ def _run_swap(self, **kw):
raise ExchangeError("Exchange was not successful")

elif service_token_balance.as_wei > 0:

self._send_status_update(
f"Making deposit of {service_token_balance.formatted} to the "
"User Deposit Contract"
)
self._send_status_update(f"This might take a few minutes")
transaction_receipt = deposit_service_tokens(
w3=w3,
account=account,
token=service_token,
amount=service_token_balance.as_wei,
)
wait_for_transaction(w3, transaction_receipt)
service_token_deposited = get_token_deposit(
w3=w3, account=account, token=service_token
)
self._send_status_update(
f"Total amount deposited at UDC: {service_token_deposited.formatted}"
)
self._run_udc_deposit(w3, account, service_token, service_token_balance)

if transfer_token_balance < required.transfer_token:
redirect_url = self.reverse_url(
Expand Down
4 changes: 2 additions & 2 deletions resources/conf/goerli.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
network = "goerli"
client_release_channel = "testing"
client_release_version = "v0.200.0-rc2"
client_release_version = "v1.1.0"
services_version = "test"
ethereum_amount_required = 2e16

[service_token]
ticker = "RDN"
ticker = "SVT"
amount_required = 6e18
swap_amount_1 = 10e18
swap_amount_2 = 20e18
Expand Down
Loading