@@ -2,6 +2,7 @@ package appointee
22
33import (
44 "context"
5+ "fmt"
56 "sort"
67
78 "github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
@@ -23,6 +24,9 @@ type RemoveAppointeePermissionWriter interface {
2324 ctx context.Context ,
2425 request elcontracts.RemovePermissionRequest ,
2526 ) (* gethtypes.Receipt , error )
27+ NewRemovePermissionTx (
28+ request elcontracts.RemovePermissionRequest ,
29+ ) (* gethtypes.Transaction , error )
2630}
2731
2832func RemoveCmd (generator func (logging.Logger , * removeConfig ) (RemoveAppointeePermissionWriter , error )) * cli.Command {
@@ -59,15 +63,79 @@ func removeAppointeePermission(
5963 if err != nil {
6064 return err
6165 }
66+ removePermissionRequest := elcontracts.RemovePermissionRequest {
67+ AccountAddress : config .AccountAddress ,
68+ AppointeeAddress : config .AppointeeAddress ,
69+ Target : config .Target ,
70+ Selector : config .Selector ,
71+ WaitForReceipt : true ,
72+ }
73+ if config .Broadcast {
74+ return broadcastRemoveAppointeeTx (ctx , permissionWriter , config , removePermissionRequest )
75+ }
76+ return printRemoveAppointeeResult (logger , permissionWriter , config , removePermissionRequest )
77+ }
78+
79+ func printRemoveAppointeeResult (
80+ logger logging.Logger ,
81+ permissionWriter RemoveAppointeePermissionWriter ,
82+ config * removeConfig ,
83+ request elcontracts.RemovePermissionRequest ,
84+ ) error {
85+ ethClient , err := ethclient .Dial (config .RPCUrl )
86+ if err != nil {
87+ return err
88+ }
89+ noSendTxOpts := common .GetNoSendTxOpts (config .AccountAddress )
90+ if common .IsSmartContractAddress (config .AccountAddress , ethClient ) {
91+ // address is a smart contract
92+ noSendTxOpts .GasLimit = 150_000
93+ }
94+ unsignedTx , err := permissionWriter .NewRemovePermissionTx (request )
95+ if err != nil {
96+ return eigenSdkUtils .WrapError ("failed to create unsigned tx" , err )
97+ }
98+
99+ if config .OutputType == string (common .OutputType_Calldata ) {
100+ calldataHex := gethcommon .Bytes2Hex (unsignedTx .Data ())
101+ if ! common .IsEmptyString (config .OutputFile ) {
102+ err = common .WriteToFile ([]byte (calldataHex ), config .OutputFile )
103+ if err != nil {
104+ return err
105+ }
106+ logger .Infof ("Call data written to file: %s" , config .OutputFile )
107+ } else {
108+ fmt .Println (calldataHex )
109+ }
110+ } else {
111+ if ! common .IsEmptyString (config .OutputType ) {
112+ fmt .Println ("output file not supported for pretty output type" )
113+ fmt .Println ()
114+ }
115+ fmt .Printf (
116+ "Appointee %s will be lose permission to target %s selector %s by account %s\n " ,
117+ config .AppointeeAddress ,
118+ config .Target ,
119+ config .Selector ,
120+ config .AccountAddress ,
121+ )
122+ }
123+ txFeeDetails := common .GetTxFeeDetails (unsignedTx )
124+ fmt .Println ()
125+ txFeeDetails .Print ()
126+ fmt .Println ("To broadcast the transaction, use the --broadcast flag" )
127+ return nil
128+ }
129+
130+ func broadcastRemoveAppointeeTx (
131+ ctx context.Context ,
132+ permissionWriter RemoveAppointeePermissionWriter ,
133+ config * removeConfig ,
134+ request elcontracts.RemovePermissionRequest ,
135+ ) error {
62136 receipt , err := permissionWriter .RemovePermission (
63137 ctx ,
64- elcontracts.RemovePermissionRequest {
65- AccountAddress : config .AccountAddress ,
66- AppointeeAddress : config .AppointeeAddress ,
67- Target : config .Target ,
68- Selector : config .Selector ,
69- WaitForReceipt : true ,
70- },
138+ request ,
71139 )
72140 if err != nil {
73141 return err
@@ -108,6 +176,9 @@ func readAndValidateRemoveConfig(cliContext *cli.Context, logger logging.Logger)
108176 ethRpcUrl := cliContext .String (flags .ETHRpcUrlFlag .Name )
109177 network := cliContext .String (flags .NetworkFlag .Name )
110178 environment := cliContext .String (flags .EnvironmentFlag .Name )
179+ outputFile := cliContext .String (flags .OutputFileFlag .Name )
180+ outputType := cliContext .String (flags .OutputTypeFlag .Name )
181+ broadcast := cliContext .Bool (flags .BroadcastFlag .Name )
111182 target := gethcommon .HexToAddress (cliContext .String (TargetAddressFlag .Name ))
112183 selector := cliContext .String (SelectorFlag .Name )
113184 selectorBytes , err := common .ValidateAndConvertSelectorString (selector )
@@ -155,6 +226,9 @@ func readAndValidateRemoveConfig(cliContext *cli.Context, logger logging.Logger)
155226 PermissionManagerAddress : gethcommon .HexToAddress (permissionManagerAddress ),
156227 ChainID : chainID ,
157228 Environment : environment ,
229+ Broadcast : broadcast ,
230+ OutputType : outputType ,
231+ OutputFile : outputFile ,
158232 }, nil
159233}
160234
@@ -170,6 +244,8 @@ func removeCommandFlags() []cli.Flag {
170244 & flags .EnvironmentFlag ,
171245 & flags .ETHRpcUrlFlag ,
172246 & flags .BroadcastFlag ,
247+ & flags .OutputFileFlag ,
248+ & flags .OutputTypeFlag ,
173249 }
174250 cmdFlags = append (cmdFlags , flags .GetSignerFlags ()... )
175251 sort .Sort (cli .FlagsByName (cmdFlags ))
0 commit comments