Implement on-the-fly skETH distribution strategy
Summary
Supersedes investigative card at #2144 (closed)
We can add gas price calculations to all SKALE contract calls, like so, and have the user call an endpoint (and wait for the transaction to come in) if they do not have enough skETH to make a transaction.
Spec
Engine
The endpoint should be added to the SKALE routes, merging into the feat/skale-prototype branch
, and MUST be rate-limited, best to do this by user_guid
, ip_hash
, eth_address
, and phone_num_hash
(?) in separate checks.
The request would ideally be made as a POST to api/v3/blockchain/skale/faucet
with a parameter to pass the requested address through. It should only be accessible to logged-in users.
The endpoint should call a function in the SKALE Controller
, which in turn should call a function in the SKALE Manager
, that generates a new SKALE transaction to send an amount of skETH (see below "How much should we send" section).
This amount should be configurable in our settings.php
.
The gas price per unit should also be configurable in our settings.php
and exported to the front-end in the skale
section of our blockchain config.
Front
The front-end will need modifying with all SKALE calls first checking the balance, using modified contract functions with an estimateGas param as here. We need to get the amount of gas required, multiply it by the gas price, then check a users balance to determine whether they have enough funds - if they do, we can let them withdraw, if they do not, we need to make a request to the engine endpoint above, then we should either:
- Implement a waiting state where a user waits for the tx, then metamask opens.
- Simply throw a toast warning saying we've send some skETH so they can make the transaction, and ask them to wait a short while and try again.
How much should we send
44,005 is the largest amount of gas I found required digging through the block explorer. We can see this tx cost 0.0000000044005 skETH
. I think initially an amount of 0.00000022 SKETH
would provide enough for 50 of those large contract interactions, and sustain a user for quite a whilst, while remaining sustainable for us to distribute.