-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup faucet for sepolia env #1563
Changes from 3 commits
bae978c
9de7b1b
dfdd614
16b280e
968605a
cf7b609
dab4c30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,10 @@ const ( | |
serverPortName = "serverPort" | ||
serverPortDefault = 80 | ||
serverPortUsage = "Port where the web server binds to" | ||
|
||
defaultAmountName = "defaultAmount" | ||
defaultAmountDefault = 100.0 | ||
defaultAmountUsage = "Default amount of token to fund (in ETH)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's a pet annoyance, I'll leave it to you consideration. The flags receive ETH but the config struct receives WEI. Worth normalizing one way or the other imo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like we should mostly use explicit big.Int for token values everywhere in code, seems to be mostly what geth does. But the CLI is a human configured interface, imo it makes sense for it to use human readable values but not to leak that into other layers. If I'm checking the config for each env I don't want to have to count the zeroes ideally. |
||
) | ||
|
||
func parseCLIArgs() *faucet.Config { | ||
|
@@ -41,15 +45,25 @@ func parseCLIArgs() *faucet.Config { | |
faucetPK := flag.String(faucetPKName, faucetPKDefault, faucetPKUsage) | ||
jwtSecret := flag.String(jwtSecretName, jwtSecretDefault, jwtSecretUsage) | ||
serverPort := flag.Int(serverPortName, serverPortDefault, serverPortUsage) | ||
defaultAmount := flag.Float64(defaultAmountName, defaultAmountDefault, defaultAmountUsage) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any need for it to be a float ? |
||
flag.Parse() | ||
|
||
return &faucet.Config{ | ||
Port: *faucetPort, | ||
Host: *nodeHost, | ||
HTTPPort: *nodeHTTPPort, | ||
PK: *faucetPK, | ||
JWTSecret: *jwtSecret, | ||
ServerPort: *serverPort, | ||
ChainID: big.NewInt(443), // TODO make this configurable | ||
Port: *faucetPort, | ||
Host: *nodeHost, | ||
HTTPPort: *nodeHTTPPort, | ||
PK: *faucetPK, | ||
JWTSecret: *jwtSecret, | ||
ServerPort: *serverPort, | ||
ChainID: big.NewInt(443), // TODO make this configurable | ||
DefaultFundAmount: toWei(defaultAmount), | ||
} | ||
} | ||
|
||
func toWei(amount *float64) *big.Int { | ||
amtFloat := new(big.Float).SetFloat64(*amount) | ||
weiFloat := new(big.Float).Mul(amtFloat, big.NewFloat(1e18)) | ||
// don't care about the accuracy here, float should have less than 18 decimal places | ||
wei, _ := weiFloat.Int(nil) | ||
return wei | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That does sound better but I can't find it. I've changed 1e18 magic number to use geth's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could swear there was a ParseEther(string), but had a double look and nothing. params.Ether sounds good. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,18 +13,18 @@ import ( | |
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/params" | ||
"github.com/obscuronet/go-obscuro/go/obsclient" | ||
"github.com/obscuronet/go-obscuro/go/rpc" | ||
"github.com/obscuronet/go-obscuro/go/wallet" | ||
) | ||
|
||
const ( | ||
_timeout = 60 * time.Second | ||
OBXNativeToken = "obx" | ||
WrappedOBX = "wobx" | ||
WrappedEth = "weth" | ||
WrappedUSDC = "usdc" | ||
_timeout = 60 * time.Second | ||
NativeToken = "eth" | ||
DeprecatedNativeToken = "obx" // leaving this in temporarily for tooling that is getting native funds using `/obx` URL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better to rip the band aid straight off imo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed with Moray, we want to make it less painful to transition. No need to break the discord faucet and e2e tests unnecessarily even if it's an easy fix. I'll add a todo to remove it. |
||
WrappedOBX = "wobx" | ||
WrappedEth = "weth" | ||
WrappedUSDC = "usdc" | ||
) | ||
|
||
type Faucet struct { | ||
|
@@ -50,11 +50,11 @@ func NewFaucet(rpcURL string, chainID int64, pkString string) (*Faucet, error) { | |
}, nil | ||
} | ||
|
||
func (f *Faucet) Fund(address *common.Address, token string, amount int64) error { | ||
func (f *Faucet) Fund(address *common.Address, token string, amount *big.Int) error { | ||
var err error | ||
var signedTx *types.Transaction | ||
|
||
if token == OBXNativeToken { | ||
if token == NativeToken || token == DeprecatedNativeToken { | ||
signedTx, err = f.fundNativeToken(address, amount) | ||
} else { | ||
return fmt.Errorf("token not fundable atm") | ||
|
@@ -105,7 +105,7 @@ func (f *Faucet) validateTx(tx *types.Transaction) error { | |
return fmt.Errorf("unable to fetch tx receipt after %s", _timeout) | ||
} | ||
|
||
func (f *Faucet) fundNativeToken(address *common.Address, amount int64) (*types.Transaction, error) { | ||
func (f *Faucet) fundNativeToken(address *common.Address, amount *big.Int) (*types.Transaction, error) { | ||
// only one funding at the time | ||
f.fundMutex.Lock() | ||
defer f.fundMutex.Unlock() | ||
|
@@ -125,7 +125,7 @@ func (f *Faucet) fundNativeToken(address *common.Address, amount int64) (*types. | |
GasPrice: big.NewInt(225), | ||
Gas: gas, | ||
To: address, | ||
Value: new(big.Int).Mul(big.NewInt(amount), big.NewInt(params.Ether)), | ||
Value: amount, | ||
} | ||
|
||
signedTx, err := f.wallet.SignTransaction(tx) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
float ?