Skip to content

Commit

Permalink
Add support for Prater testnet.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Mar 12, 2021
1 parent 9f71dfe commit 8050d34
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,21 @@ $ ethereal account nonce --address=0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf
243
```

### `beacon` commands

Beacon commands focus on interactions with the Ethereum 2 beacon deposit contract.

### `deposit`

`ethereal beacon deposit` creates and sends an Ethereum 2 beacon deposit contract transaction. For example:

```sh
TODO
$ ethereal beacon deposit
```

Note that `ethereal` obtains the information about the amount of Ether to send with deposits from the supplied deposit data.

### `block` commands

Block commands focus on information about specific blocks.
Expand Down
35 changes: 29 additions & 6 deletions cmd/beacondeposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/wealdtech/ethereal/cli"
"github.com/wealdtech/ethereal/util"
"github.com/wealdtech/ethereal/util/contracts"
Expand Down Expand Up @@ -80,6 +81,15 @@ var beaconDepositKnownContracts = []*beaconDepositContract{
maxVersion: 3,
subgraph: "attestantio/eth2deposits-pyrmont",
},
{
network: "Pater",
chainID: big.NewInt(5),
address: util.MustDecodeHexString("0xff50ed3d0ec03aC01D4C79aAd74928BFF48a7b2b"),
forkVersion: []byte{0x00, 0x00, 0x10, 0x20},
minVersion: 3,
maxVersion: 3,
subgraph: "attestantio/eth2deposits-pater",
},
}

// beaconDepositCmd represents the beacon deposit command
Expand Down Expand Up @@ -205,7 +215,14 @@ func sendOffline(deposits []*util.DepositInfo, contractDetails *beaconDepositCon
copy(depositDataRoot[:], deposit.DepositDataRoot)
dataBytes, err := abi.Pack("deposit", deposit.PublicKey, deposit.WithdrawalCredentials, deposit.Signature, depositDataRoot)
cli.ErrCheck(err, quiet, "Failed to create deposit transaction")
value := new(big.Int).Mul(new(big.Int).SetUint64(deposit.Amount), big.NewInt(1000000000))
var value *big.Int
if deposit.Amount == 0 {
cli.Assert(viper.GetString("value") != "", quiet, "No value from either deposit data or command line; cannot create transaction")
value, err = string2eth.StringToWei(viper.GetString("value"))
cli.ErrCheck(err, quiet, "Failed to understand value")
} else {
value = new(big.Int).Mul(new(big.Int).SetUint64(deposit.Amount), big.NewInt(1000000000))
}
signedTx, err := createSignedTransaction(fromAddress, &address, value, 500000, dataBytes)
cli.ErrCheck(err, quiet, "Failed to create signed transaction")
buf := new(bytes.Buffer)
Expand All @@ -226,8 +243,14 @@ func sendOnline(deposits []*util.DepositInfo, contractDetails *beaconDepositCont
for _, deposit := range deposits {
opts, err := generateTxOpts(fromAddress)
cli.ErrCheck(err, quiet, "Failed to generate deposit options")
// Need to override the value with the info from the JSON
opts.Value = new(big.Int).Mul(new(big.Int).SetUint64(deposit.Amount), big.NewInt(1000000000))
// Need to override the value with the info from the JSON (if present).
if deposit.Amount == 0 {
cli.Assert(opts.Value.Cmp(big.NewInt(0)) != 0, quiet, "No value from either deposit data or command line; cannot create transaction")
opts.Value, err = string2eth.StringToWei(viper.GetString("value"))
cli.ErrCheck(err, quiet, "Failed to understand value")
} else {
opts.Value = new(big.Int).Mul(new(big.Int).SetUint64(deposit.Amount), big.NewInt(1000000000))
}

// Need to set gas limit because it moves around a fair bit with the merkle tree calculations.
// This is just above the maximum gas possible used by the contract, as calculated in section 4.2 of
Expand Down Expand Up @@ -372,7 +395,7 @@ func init() {
beaconDepositCmd.Flags().BoolVar(&beaconDepositAllowNewData, "allow-new-data", false, "Allow sending from a newer version of deposit data than supported (WARNING: only if you know what you are doing)")
beaconDepositCmd.Flags().BoolVar(&beaconDepositAllowExcessiveDeposit, "allow-excessive-deposit", false, "Allow sending more than 32 Ether in a single deposit (WARNING: only if you know what you are doing)")
beaconDepositCmd.Flags().BoolVar(&beaconDepositAllowDuplicateDeposit, "allow-duplicate-deposit", false, "Allow sending multiple deposits with the same validator public key (WARNING: only if you know what you are doing)")
beaconDepositCmd.Flags().StringVar(&beaconDepositContractAddress, "address", "", "The address to which to send the deposit (overrides network)")
beaconDepositCmd.Flags().StringVar(&beaconDepositEth2Network, "eth2network", "mainnet", "The name of the network to which to send the deposit (mainnet/pyrmont)")
addTransactionFlags(beaconDepositCmd, "passphrase for the account that owns the account")
beaconDepositCmd.Flags().StringVar(&beaconDepositContractAddress, "address", "", "The contract address to which to send the deposit (overrides the value obtained from eth2network)")
beaconDepositCmd.Flags().StringVar(&beaconDepositEth2Network, "eth2network", "mainnet", "The name of the Ethereum 2 network for which to send the deposit (mainnet/pyrmont/pater)")
addTransactionFlags(beaconDepositCmd, "the account from which to send the deposit")
}
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var versionCmd = &cobra.Command{
ethereal version.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("2.4.0")
fmt.Println("2.5.0")
if viper.GetBool("verbose") {
buildInfo, ok := dbg.ReadBuildInfo()
if ok {
Expand Down

0 comments on commit 8050d34

Please sign in to comment.