Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
batphonghan committed Nov 30, 2023
1 parent d662db4 commit 8a994ea
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 24 deletions.
1 change: 1 addition & 0 deletions shared/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ func GetSdUtilityContract(c *cli.Context) (*stader.SDUtilityPoolContractManager,
if err != nil {
return nil, err
}

ec, err := getEthClient(c, cfg)
if err != nil {
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion shared/services/stader/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (c *Client) GetNodeDepositSdAllowance() (api.NodeDepositSdAllowanceResponse
}

// Check whether the node can make a deposit
func (c *Client) CanNodeDeposit(amountWei, amountUtilityWei *big.Int, numValidators *big.Int, reloadKeys bool) (api.CanNodeDepositResponse, error) {
func (c *Client) CanNodeDeposit(amountWei, amountUtilityWei, numValidators *big.Int, reloadKeys bool) (api.CanNodeDepositResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("validator can-deposit %s %s %s %t", amountWei.String(), amountUtilityWei.String(), numValidators, reloadKeys))
if err != nil {
return api.CanNodeDepositResponse{}, fmt.Errorf("could not get can validator deposit status: %w", err)
Expand Down Expand Up @@ -640,10 +640,12 @@ func (c *Client) NodeRepaySd(amountWei *big.Int) (api.NodeRepaySDResponse, error
if err != nil {
return api.NodeRepaySDResponse{}, fmt.Errorf("could not repay SD: %w", err)
}

var response api.NodeRepaySDResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.NodeRepaySDResponse{}, fmt.Errorf("could not decode repay node SD response: %w", err)
}

if response.Error != "" {
return api.NodeRepaySDResponse{}, fmt.Errorf("could not repay SD: %s", response.Error)
}
Expand Down
6 changes: 1 addition & 5 deletions stader-cli/node/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,7 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
Usage: "Automatically confirm SD utilize",
},
},
Action: func(c *cli.Context) error {
return utilizeSD(c)
},
Action: utilizeSD,
},
{
Name: "repay-sd",
Expand All @@ -399,7 +397,6 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
},
},
Action: func(c *cli.Context) error {

if _, err := cliutils.ValidatePositiveEthAmount("sd repay amount", c.String("amount")); err != nil {
return err
}
Expand All @@ -424,7 +421,6 @@ func RegisterCommands(app *cli.App, name string, aliases []string) {
},
},
Action: func(c *cli.Context) error {

if _, err := cliutils.ValidatePositiveEthAmount("sd repay amount", c.String("amount")); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions stader-lib/stader/stader.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ func NewSDUtilityPool(client ExecutionClient, sdUtilizeAddress common.Address) (
if err != nil {
return nil, err
}

sdUtilizeContract := &Contract{
Contract: bind.NewBoundContract(sdUtilizeAddress, sdUtilizeAbi, client, client, client),
Address: &sdUtilizeAddress,
Expand Down
14 changes: 0 additions & 14 deletions stader/api/node/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ func RegisterSubcommands(command *cli.Command, name string, aliases []string) {
Usage: "Utilize SD",
UsageText: "stader-cli api node utilize-sd amount",
Action: func(c *cli.Context) error {

// Validate args
if err := cliutils.ValidateArgCount(c, 1); err != nil {
return err
Expand All @@ -191,15 +190,13 @@ func RegisterSubcommands(command *cli.Command, name string, aliases []string) {
// Run
api.PrintResponse(utilitySd(c, amountWei))
return nil

},
},
{
Name: "can-utilize-sd",
Usage: "Utilize SD",
UsageText: "stader-cli api node can-utilize-sd amount",
Action: func(c *cli.Context) error {

// Validate args
if err := cliutils.ValidateArgCount(c, 1); err != nil {
return err
Expand All @@ -208,19 +205,16 @@ func RegisterSubcommands(command *cli.Command, name string, aliases []string) {
if err != nil {
return err
}

// Run
api.PrintResponse(canUtilitySd(c, amountWei))
return nil

},
},
{
Name: "repay-sd",
Usage: "Utilize SD",
UsageText: "stader-cli api node repay-sd amount",
Action: func(c *cli.Context) error {

// Validate args
if err := cliutils.ValidateArgCount(c, 1); err != nil {
return err
Expand All @@ -233,15 +227,13 @@ func RegisterSubcommands(command *cli.Command, name string, aliases []string) {
// Run
api.PrintResponse(repaySD(c, amountWei))
return nil

},
},
{
Name: "can-repay-sd",
Usage: "Can repay SD",
UsageText: "stader-cli api node can-repay-sd amount",
Action: func(c *cli.Context) error {

// Validate args
if err := cliutils.ValidateArgCount(c, 1); err != nil {
return err
Expand All @@ -254,17 +246,14 @@ func RegisterSubcommands(command *cli.Command, name string, aliases []string) {
// Run
api.PrintResponse(canRepaySD(c, amountWei))
return nil

},
},

{
Name: "wait-and-deposit-sd",
Aliases: []string{"k2"},
Usage: "Deposit SD against the node, waiting for approval tx-hash to be included in a block first",
UsageText: "stader-cli api node wait-and-deposit-sd amount tx-hash",
Action: func(c *cli.Context) error {

// Validate args
if err := cliutils.ValidateArgCount(c, 2); err != nil {
return err
Expand Down Expand Up @@ -792,7 +781,6 @@ func RegisterSubcommands(command *cli.Command, name string, aliases []string) {
// Run
api.PrintResponse(SetRewardAddress(c, operatorRewardAddress))
return nil

},
},

Expand All @@ -801,15 +789,13 @@ func RegisterSubcommands(command *cli.Command, name string, aliases []string) {
Usage: "Get SD Status",
UsageText: "stader-cli api node get-sd-status",
Action: func(c *cli.Context) error {

// Validate args
if err := cliutils.ValidateArgCount(c, 0); err != nil {
return err
}
// Run
api.PrintResponse(getSDStatus(c))
return nil

},
},
},
Expand Down
4 changes: 2 additions & 2 deletions stader/api/node/sd-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func getSDStatus(c *cli.Context) (*api.GetSdStatusResponse, error) {
return nil, err
}

operatorId, err := node.GetOperatorId(prn, nodeAccount.Address, nil)
operatorID, err := node.GetOperatorId(prn, nodeAccount.Address, nil)
if err != nil {
return nil, err
}

totalValidatorKeys, err := node.GetTotalValidatorKeys(prn, operatorId, nil)
totalValidatorKeys, err := node.GetTotalValidatorKeys(prn, operatorID, nil)
if err != nil {
return nil, err
}
Expand Down
1 change: 0 additions & 1 deletion stader/api/node/utility-sd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func utilitySd(c *cli.Context, amountWei *big.Int) (*api.NodeUtilitySDResponse,
response.TxHash = tx.Hash()

return &response, nil

}

func canUtilitySd(c *cli.Context, amountWei *big.Int) (*api.CanUtilitySDResponse, error) {
Expand Down
1 change: 0 additions & 1 deletion stader/api/validator/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func GetSDStatus(
operatorAddress common.Address,
totalValidatorsPostAddition *big.Int,
) (*api.SdStatusResponse, error) {

sdUtilityBalance, err := sd_utility.GetUtilizerLatestBalance(sdu, operatorAddress, nil)
if err != nil {
return nil, err
Expand Down

0 comments on commit 8a994ea

Please sign in to comment.