Skip to content

Commit

Permalink
moved network SWC address getter/setter to protocol dao settings
Browse files Browse the repository at this point in the history
  • Loading branch information
moles1 committed Mar 1, 2021
1 parent eb77374 commit fb20418
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 88 deletions.
15 changes: 15 additions & 0 deletions dao/protocol/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"

"github.com/rocket-pool/rocketpool-go/rocketpool"
Expand Down Expand Up @@ -41,6 +42,20 @@ func BootstrapUint(rp *rocketpool.RocketPool, contractName, settingPath string,
}


// Bootstrap an address setting
func BootstrapAddress(rp *rocketpool.RocketPool, contractName, settingPath string, value common.Address, opts *bind.TransactOpts) (*types.Receipt, error) {
rocketDAOProtocol, err := getRocketDAOProtocol(rp)
if err != nil {
return nil, err
}
txReceipt, err := rocketDAOProtocol.Transact(opts, "bootstrapSettingAddress", contractName, settingPath, value)
if err != nil {
return nil, fmt.Errorf("Could not bootstrap protocol setting %s.%s: %w", contractName, settingPath, err)
}
return txReceipt, nil
}


// Bootstrap a rewards claimer
func BootstrapClaimer(rp *rocketpool.RocketPool, contractName string, amount float64, opts *bind.TransactOpts) (*types.Receipt, error) {
rocketDAOProtocol, err := getRocketDAOProtocol(rp)
Expand Down
50 changes: 0 additions & 50 deletions network/withdrawal.go

This file was deleted.

18 changes: 18 additions & 0 deletions settings/protocol/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"

protocoldao "github.com/rocket-pool/rocketpool-go/dao/protocol"
Expand Down Expand Up @@ -205,6 +206,23 @@ func BootstrapTargetRethCollateralRate(rp *rocketpool.RocketPool, value float64,
}


// The eth2 system withdrawal contract address
func GetSystemWithdrawalContractAddress(rp *rocketpool.RocketPool, opts *bind.CallOpts) (common.Address, error) {
networkSettingsContract, err := getNetworkSettingsContract(rp)
if err != nil {
return common.Address{}, err
}
value := new(common.Address)
if err := networkSettingsContract.Call(opts, value, "getSystemWithdrawalContractAddress"); err != nil {
return common.Address{}, fmt.Errorf("Could not get system withdrawal contract address: %w", err)
}
return *value, nil
}
func BootstrapSystemWithdrawalContractAddress(rp *rocketpool.RocketPool, value common.Address, opts *bind.TransactOpts) (*types.Receipt, error) {
return protocoldao.BootstrapAddress(rp, NetworkSettingsContractName, "network.withdrawal.contract.address", value, opts)
}


// Get contracts
var networkSettingsContractLock sync.Mutex
func getNetworkSettingsContract(rp *rocketpool.RocketPool) (*rocketpool.Contract, error) {
Expand Down
2 changes: 1 addition & 1 deletion tests/minipool/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func TestWithdrawValidatorBalance(t *testing.T) {
if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.Address, eth.EthToWei(32), eth.EthToWei(32), trustedNodeAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Set SWC address
if _, err := network.SetSystemWithdrawalContractAddress(rp, swcAccount.Address, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := protocol.BootstrapSystemWithdrawalContractAddress(rp, swcAccount.Address, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Get & check initial minipool validator balance withdrawn status
if validatorBalanceWithdrawn, err := mp.GetValidatorBalanceWithdrawn(nil); err != nil {
Expand Down
35 changes: 0 additions & 35 deletions tests/network/withdrawal_test.go

This file was deleted.

12 changes: 12 additions & 0 deletions tests/settings/protocol/network_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package protocol

import (
"bytes"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/rocket-pool/rocketpool-go/settings/protocol"
"github.com/rocket-pool/rocketpool-go/utils/eth"

Expand Down Expand Up @@ -126,5 +128,15 @@ func TestNetworkSettings(t *testing.T) {
t.Error("Incorrect target rETH collateral rate value")
}

// Set & get system withdrawal contract address
swcAddress := common.HexToAddress("0x1111111111111111111111111111111111111111")
if _, err := protocol.BootstrapSystemWithdrawalContractAddress(rp, swcAddress, ownerAccount.GetTransactor()); err != nil {
t.Error(err)
} else if value, err := protocol.GetSystemWithdrawalContractAddress(rp, nil); err != nil {
t.Error(err)
} else if !bytes.Equal(value.Bytes(), swcAddress.Bytes()) {
t.Error("Incorrect system withdrawal contract address")
}

}

4 changes: 2 additions & 2 deletions tests/tokens/neth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/ethereum/go-ethereum/common"

"github.com/rocket-pool/rocketpool-go/network"
"github.com/rocket-pool/rocketpool-go/settings/protocol"
"github.com/rocket-pool/rocketpool-go/tokens"
"github.com/rocket-pool/rocketpool-go/utils/eth"

Expand Down Expand Up @@ -127,7 +127,7 @@ func TestBurnNETH(t *testing.T) {
if err != nil { t.Fatal(err) }

// Set SWC address
if _, err := network.SetSystemWithdrawalContractAddress(rp, swcAccount.Address, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }
if _, err := protocol.BootstrapSystemWithdrawalContractAddress(rp, swcAccount.Address, ownerAccount.GetTransactor()); err != nil { t.Fatal(err) }

// Withdraw minipool validator balance
opts := swcAccount.GetTransactor()
Expand Down

0 comments on commit fb20418

Please sign in to comment.