Skip to content

Commit

Permalink
Updating appointee set & remove to support output parameters (#271)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Chatham <[email protected]>
  • Loading branch information
bdchatham and Brandon Chatham authored Dec 17, 2024
1 parent 0e5a6eb commit 7f37efa
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 32 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/Layr-Labs/eigenlayer-contracts v0.3.2-mainnet-rewards
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.12
github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241217222530-549e0185cee6
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241217234459-1dd4a5c5b30a
github.com/blang/semver/v4 v4.0.0
github.com/consensys/gnark-crypto v0.12.1
github.com/ethereum/go-ethereum v1.14.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-
github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e/go.mod h1:T7tYN8bTdca2pkMnz9G2+ZwXYWw5gWqQUIu4KLgC/vM=
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241217222530-549e0185cee6 h1:v2SQn+Yq/HMAkv0a11NHnZXJS0K+2F4JWU0ogOV6+jg=
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241217222530-549e0185cee6/go.mod h1:aYdNURUhaqeYOS+Cq12TfSdPbjFfiLaHkxPdR4Exq/s=
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241217234459-1dd4a5c5b30a h1:spyS+Tp1PgVIPmAesVVRuOkC3jAZRyKXhttAieTBxmg=
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241217234459-1dd4a5c5b30a/go.mod h1:aYdNURUhaqeYOS+Cq12TfSdPbjFfiLaHkxPdR4Exq/s=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
Expand Down
45 changes: 23 additions & 22 deletions pkg/user/appointee/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
"github.com/Layr-Labs/eigensdk-go/logging"
eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
gethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
Expand All @@ -25,6 +26,7 @@ type RemoveAppointeePermissionWriter interface {
request elcontracts.RemovePermissionRequest,
) (*gethtypes.Receipt, error)
NewRemovePermissionTx(
txOpts *bind.TransactOpts,
request elcontracts.RemovePermissionRequest,
) (*gethtypes.Transaction, error)
}
Expand Down Expand Up @@ -69,10 +71,27 @@ func removeAppointeePermission(
if config.Broadcast {
return broadcastRemoveAppointeeTx(ctx, permissionWriter, config, removePermissionRequest)
}
return printRemoveAppointeeResult(logger, permissionWriter, config, removePermissionRequest)
return printRemoveAppointeeTx(logger, permissionWriter, config, removePermissionRequest)
}

func printRemoveAppointeeResult(
func broadcastRemoveAppointeeTx(
ctx context.Context,
permissionWriter RemoveAppointeePermissionWriter,
config *removeConfig,
request elcontracts.RemovePermissionRequest,
) error {
receipt, err := permissionWriter.RemovePermission(
ctx,
request,
)
if err != nil {
return err
}
common.PrintTransactionInfo(receipt.TxHash.String(), config.ChainID)
return nil
}

func printRemoveAppointeeTx(
logger logging.Logger,
permissionWriter RemoveAppointeePermissionWriter,
config *removeConfig,
Expand All @@ -84,10 +103,9 @@ func printRemoveAppointeeResult(
}
noSendTxOpts := common.GetNoSendTxOpts(config.CallerAddress)
if common.IsSmartContractAddress(config.CallerAddress, ethClient) {
// address is a smart contract
noSendTxOpts.GasLimit = 150_000
}
unsignedTx, err := permissionWriter.NewRemovePermissionTx(request)
unsignedTx, err := permissionWriter.NewRemovePermissionTx(noSendTxOpts, request)
if err != nil {
return eigenSdkUtils.WrapError("failed to create unsigned tx", err)
}
Expand All @@ -109,7 +127,7 @@ func printRemoveAppointeeResult(
fmt.Println()
}
fmt.Printf(
"Appointee %s will be lose permission to target %s selector %s by account %s\n",
"Appointee %s will lose permission to target %s selector %s for account %s\n",
config.AppointeeAddress,
config.Target,
config.Selector,
Expand All @@ -123,23 +141,6 @@ func printRemoveAppointeeResult(
return nil
}

func broadcastRemoveAppointeeTx(
ctx context.Context,
permissionWriter RemoveAppointeePermissionWriter,
config *removeConfig,
request elcontracts.RemovePermissionRequest,
) error {
receipt, err := permissionWriter.RemovePermission(
ctx,
request,
)
if err != nil {
return err
}
common.PrintTransactionInfo(receipt.TxHash.String(), config.ChainID)
return nil
}

func generateRemoveAppointeePermissionWriter(
prompter utils.Prompter,
) func(
Expand Down
33 changes: 30 additions & 3 deletions pkg/user/appointee/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"testing"

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

"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
Expand All @@ -16,7 +17,7 @@ import (

type mockRemoveAppointeePermissionWriter struct {
removePermissionFunc func(ctx context.Context, request elcontracts.RemovePermissionRequest) (*gethtypes.Receipt, error)
newRemovePermissionTxFunc func(request elcontracts.RemovePermissionRequest) (*gethtypes.Transaction, error)
newRemovePermissionTxFunc func(txOpts *bind.TransactOpts, request elcontracts.RemovePermissionRequest) (*gethtypes.Transaction, error)
}

func (m *mockRemoveAppointeePermissionWriter) RemovePermission(
Expand All @@ -27,9 +28,10 @@ func (m *mockRemoveAppointeePermissionWriter) RemovePermission(
}

func (m *mockRemoveAppointeePermissionWriter) NewRemovePermissionTx(
txOpts *bind.TransactOpts,
request elcontracts.RemovePermissionRequest,
) (*gethtypes.Transaction, error) {
return m.newRemovePermissionTxFunc(request)
return m.newRemovePermissionTxFunc(txOpts, request)
}

func generateMockRemoveWriter(err error) func(logging.Logger, *removeConfig) (RemoveAppointeePermissionWriter, error) {
Expand All @@ -38,7 +40,7 @@ func generateMockRemoveWriter(err error) func(logging.Logger, *removeConfig) (Re
removePermissionFunc: func(ctx context.Context, request elcontracts.RemovePermissionRequest) (*gethtypes.Receipt, error) {
return &gethtypes.Receipt{}, err
},
newRemovePermissionTxFunc: func(request elcontracts.RemovePermissionRequest) (*gethtypes.Transaction, error) {
newRemovePermissionTxFunc: func(txOpts *bind.TransactOpts, request elcontracts.RemovePermissionRequest) (*gethtypes.Transaction, error) {
return &gethtypes.Transaction{}, err
},
}, nil
Expand Down Expand Up @@ -94,3 +96,28 @@ func TestRemoveCmd_GeneratorError(t *testing.T) {
assert.Error(t, err)
assert.Contains(t, err.Error(), expectedError)
}

func TestRemoveCmd_RemovePermissionError(t *testing.T) {
expectedError := "error removing appointee permission"
app := cli.NewApp()
app.Commands = []*cli.Command{
RemoveCmd(generateMockRemoveWriter(errors.New(expectedError))),
}

args := []string{
"TestRemoveCmd_RemovePermissionError",
"remove",
"--account-address", "0x1234567890abcdef1234567890abcdef12345678",
"--appointee-address", "0xabcdef1234567890abcdef1234567890abcdef12",
"--target-address", "0x9876543210fedcba9876543210fedcba98765432",
"--selector", "0x1A2B3C4D",
"--network", "holesky",
"--eth-rpc-url", "https://ethereum-holesky.publicnode.com/",
"--ecdsa-private-key", "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd",
"--broadcast",
}

err := app.Run(args)
assert.Error(t, err)
assert.Contains(t, err.Error(), expectedError)
}
6 changes: 4 additions & 2 deletions pkg/user/appointee/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
"github.com/Layr-Labs/eigensdk-go/logging"
eigenSdkUtils "github.com/Layr-Labs/eigensdk-go/utils"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
gethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
Expand All @@ -25,6 +26,7 @@ type SetAppointeePermissionWriter interface {
request elcontracts.SetPermissionRequest,
) (*gethtypes.Receipt, error)
NewSetPermissionTx(
txOpts *bind.TransactOpts,
request elcontracts.SetPermissionRequest,
) (*gethtypes.Transaction, error)
}
Expand Down Expand Up @@ -109,11 +111,11 @@ func printSetAppointeeResults(
if common.IsSmartContractAddress(config.CallerAddress, ethClient) {
noSendTxOpts.GasLimit = 150_000
}
tx, err := permissionWriter.NewSetPermissionTx(request)

tx, err := permissionWriter.NewSetPermissionTx(noSendTxOpts, request)
if err != nil {
return eigenSdkUtils.WrapError("failed to create unsigned tx", err)
}

if config.OutputType == string(common.OutputType_Calldata) {
calldataHex := gethcommon.Bytes2Hex(tx.Data())
if !common.IsEmptyString(config.OutputFile) {
Expand Down
10 changes: 6 additions & 4 deletions pkg/user/appointee/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (

"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/assert"

"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v2"
)

type mockSetAppointeePermissionWriter struct {
setPermissionFunc func(ctx context.Context, request elcontracts.SetPermissionRequest) (*gethtypes.Receipt, error)
newSetPermissionTxFunc func(request elcontracts.SetPermissionRequest) (*gethtypes.Transaction, error)
newSetPermissionTxFunc func(txOpts *bind.TransactOpts, request elcontracts.SetPermissionRequest) (*gethtypes.Transaction, error)
}

func (m *mockSetAppointeePermissionWriter) SetPermission(
Expand All @@ -26,9 +27,10 @@ func (m *mockSetAppointeePermissionWriter) SetPermission(
}

func (m *mockSetAppointeePermissionWriter) NewSetPermissionTx(
txOpts *bind.TransactOpts,
request elcontracts.SetPermissionRequest,
) (*gethtypes.Transaction, error) {
return m.newSetPermissionTxFunc(request)
return m.newSetPermissionTxFunc(txOpts, request)
}

func generateMockSetWriter(err error) func(logging.Logger, *setConfig) (SetAppointeePermissionWriter, error) {
Expand All @@ -37,7 +39,7 @@ func generateMockSetWriter(err error) func(logging.Logger, *setConfig) (SetAppoi
setPermissionFunc: func(ctx context.Context, request elcontracts.SetPermissionRequest) (*gethtypes.Receipt, error) {
return &gethtypes.Receipt{}, err
},
newSetPermissionTxFunc: func(request elcontracts.SetPermissionRequest) (*gethtypes.Transaction, error) {
newSetPermissionTxFunc: func(txOpts *bind.TransactOpts, request elcontracts.SetPermissionRequest) (*gethtypes.Transaction, error) {
return &gethtypes.Transaction{}, err
},
}, nil
Expand Down

0 comments on commit 7f37efa

Please sign in to comment.