Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the way we are displaying SD and ETH values #173

Merged
merged 8 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions shared/types/api/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ type ClaimRewards struct {
Error string `json:"error"`
OperatorRewardsBalance *big.Int `json:"operatorRewardsBalance"`
OperatorRewardAddress common.Address `json:"operatorRewardAddress"`
RewardsClaimed *big.Int `json:"rewardsClaimed"`
TxHash common.Hash `json:"txHash"`
}

Expand Down
16 changes: 10 additions & 6 deletions stader-cli/node/claim-rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/stader-labs/stader-node/shared/services/gas"
"github.com/stader-labs/stader-node/shared/services/stader"
cliutils "github.com/stader-labs/stader-node/shared/utils/cli"
"github.com/stader-labs/stader-node/shared/utils/math"
"github.com/stader-labs/stader-node/stader-lib/utils/eth"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -50,11 +49,16 @@ func ClaimRewards(c *cli.Context) error {
if sdStatusResponse.SDStatus.SdUtilizerLatestBalance.Cmp(big.NewInt(0)) > 0 {
totalFee := sdStatus.AccumulatedInterest

fmt.Printf("You need to first pay %f and close the utilization position to get back your funds. Execute the following command to repay your utilized SD stader-cli repay-sd --amount <SD amount> \n", eth.WeiToEth(totalFee))
fmt.Printf("You need to first pay %s and close the utilization position to get back your funds. Execute the following command to repay your utilized SD stader-cli repay-sd --amount <SD amount> \n", eth.DisplayAmountInUnits(totalFee, "sd"))

fmt.Printf("Based on the current Health Factor, you can claim upto %.6f ETH.\n", eth.WeiToEth(canClaimRewardsResponse.WithdrawableInEth))
fmt.Printf("Based on the current Health Factor, you can claim upto %s.\n", eth.DisplayAmountInUnits(canClaimRewardsResponse.WithdrawableInEth, "eth"))

fmt.Printf("Note: Please repay your utilized SD by using the following command to claim the remaining ETH: stader-cli sd repay --amount <amount of SD to be repaid>.\n\n")
fmt.Printf("Note: Please repay your utilized SD by using the following command to claim the remaining ETH: stader-cli sd repay --amount <amount of SD to be repaid>.\n")

if !cliutils.Confirm("Are you sure you want to proceed?\n\n") {
fmt.Println("Cancelled.")
return nil
}
}
}

Expand All @@ -75,13 +79,13 @@ func ClaimRewards(c *cli.Context) error {
if err != nil {
return err
}
fmt.Printf("Withdrawing %.6f ETH Rewards to Operator Reward Address: %s\n\n", math.RoundDown(eth.WeiToEth(res.OperatorRewardsBalance), 6), res.OperatorRewardAddress)
fmt.Printf("Withdrawing %s Rewards to Operator Reward Address: %s\n\n", eth.DisplayAmountInUnits(res.RewardsClaimed, "eth"), res.OperatorRewardAddress)
cliutils.PrintTransactionHash(staderClient, res.TxHash)
if _, err = staderClient.WaitForTransaction(res.TxHash); err != nil {
return err
}

// Log & return
fmt.Printf("Successful withdrawal of %.6f ETH to Operator Reward Address: %s\n\n", math.RoundDown(eth.WeiToEth(res.OperatorRewardsBalance), 6), res.OperatorRewardAddress)
fmt.Printf("Successful withdrawal of %s to Operator Reward Address: %s\n\n", eth.DisplayAmountInUnits(res.RewardsClaimed, "eth"), res.OperatorRewardAddress)
return nil
}
12 changes: 6 additions & 6 deletions stader-cli/node/claim-sp-rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func ClaimSpRewards(c *cli.Context) error {

depositSd := false
if totalClaimableSd.Cmp(big.NewInt(0)) > 0 {
fmt.Printf("You will claim %f SD and %f ETH with the following selection - cycles %v\n\n", eth.WeiToEth(totalClaimableSd), eth.WeiToEth(totalClaimableEth), cyclesToClaimArray)
fmt.Printf("You will claim %s and %s with the following selection - cycles %v\n\n", eth.DisplayAmountInUnits(totalClaimableSd, "sd"), eth.DisplayAmountInUnits(totalClaimableEth, "eth"), cyclesToClaimArray)
fmt.Printf("Your ETH rewards will be sent to your Reward Address\n")
fmt.Printf("For SD rewards, you can claim all the rewards to your Reward Address or redeposit them as SD collateral to earn more rewards\n")

Expand All @@ -169,13 +169,13 @@ func ClaimSpRewards(c *cli.Context) error {
option := cliutils.Prompt("", "^(1|2)$", "Please enter a valid option")
if option == "1" {
if !cliutils.Confirm(fmt.Sprintf(
"Are you sure you want to claim %f ETH and %f SD for cycles %v to your reward address?", eth.WeiToEth(totalClaimableEth), eth.WeiToEth(totalClaimableSd), cyclesToClaimArray)) {
"Are you sure you want to claim %s and %s for cycles %v to your reward address?", eth.DisplayAmountInUnits(totalClaimableEth, "eth"), eth.DisplayAmountInUnits(totalClaimableSd, "sd"), cyclesToClaimArray)) {
fmt.Println("Claim Cancelled.")
return nil
}
} else if option == "2" {
if !cliutils.Confirm(fmt.Sprintf(
"Your %f ETH rewards will be sent to your Reward Address.\nFor your %f SD rewards, are you sure you want to re-deposit it as SD collateral for additional earnings?", eth.WeiToEth(totalClaimableEth), eth.WeiToEth(totalClaimableSd))) {
"Your %s rewards will be sent to your Reward Address.\nFor your %s rewards, are you sure you want to re-deposit it as SD collateral for additional earnings?", eth.DisplayAmountInUnits(totalClaimableEth, "eth"), eth.DisplayAmountInUnits(totalClaimableSd, "sd"))) {
fmt.Println("Claim Cancelled.")
return nil
}
Expand Down Expand Up @@ -216,12 +216,12 @@ func ClaimSpRewards(c *cli.Context) error {

fmt.Printf("Transaction Successful\n")
if depositSd {
fmt.Printf("%f ETH rewards have been sent to your Reward Address and %f SD rewards have been re-deposited as SD collateral\n", eth.WeiToEth(totalClaimableEth), eth.WeiToEth(totalClaimableSd))
fmt.Printf("%s rewards have been sent to your Reward Address and %s rewards have been re-deposited as SD collateral\n", eth.DisplayAmountInUnits(totalClaimableEth, "eth"), eth.DisplayAmountInUnits(totalClaimableSd, "sd"))
} else {
if totalClaimableSd.Cmp(big.NewInt(0)) <= 0 {
fmt.Printf("%f ETH rewards have been sent to your Reward Address\n", eth.WeiToEth(totalClaimableEth))
fmt.Printf("%s rewards have been sent to your Reward Address\n", eth.DisplayAmountInUnits(totalClaimableEth, "eth"))
} else {
fmt.Printf("%f SD rewards and %f ETH rewards have been sent to your Reward Address\n", eth.WeiToEth(totalClaimableSd), eth.WeiToEth(totalClaimableEth))
fmt.Printf("%s rewards and %s rewards have been sent to your Reward Address\n", eth.DisplayAmountInUnits(totalClaimableSd, "sd"), eth.DisplayAmountInUnits(totalClaimableEth, "eth"))
}
}

Expand Down
7 changes: 3 additions & 4 deletions stader-cli/node/deposit-sd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/stader-labs/stader-node/shared/services/gas"
"github.com/stader-labs/stader-node/shared/services/stader"
cliutils "github.com/stader-labs/stader-node/shared/utils/cli"
"github.com/stader-labs/stader-node/shared/utils/math"
)

func nodeDepositSd(c *cli.Context) error {
Expand Down Expand Up @@ -61,7 +60,7 @@ func DepositSdWithAmount(staderClient *stader.Client, amountWei *big.Int, autoCo
}

if allowance.Allowance.Cmp(amountWei) < 0 {
fmt.Println("Before depositing SD, you must first give the collateral contract approval to interact with your SD. Amount to approve: ", eth.WeiToEth(amountWei))
fmt.Println("Before depositing SD, you must first give the collateral contract approval to interact with your SD. Amount to approve: ", eth.DisplayAmountInUnits(amountWei, "sd"))
err = nodeApproveSdWithAmountAndAddress(staderClient, amountWei, contracts.SdCollateralContract, autoConfirm, nonce)
if err != nil {
return err
Expand Down Expand Up @@ -90,7 +89,7 @@ func DepositSdWithAmount(staderClient *stader.Client, amountWei *big.Int, autoCo
}

// Prompt for confirmation
if !(autoConfirm || cliutils.Confirm(fmt.Sprintf("Are you sure you want to deposit %f SD as collateral?", math.RoundDown(eth.WeiToEth(amountWei), 6)))) {
if !(autoConfirm || cliutils.Confirm(fmt.Sprintf("Are you sure you want to deposit %s as collateral?", eth.DisplayAmountInUnits(amountWei, "sd")))) {
fmt.Println("Cancelled.")
return nil
}
Expand All @@ -108,7 +107,7 @@ func DepositSdWithAmount(staderClient *stader.Client, amountWei *big.Int, autoCo
}

// Log & return
fmt.Printf("Successfully deposited %.6f SD.\n", math.RoundDown(eth.WeiToEth(amountWei), 6))
fmt.Printf("Successfully deposited %s.\n", eth.DisplayAmountInUnits(amountWei, "sd"))

return nil
}
8 changes: 4 additions & 4 deletions stader-cli/node/repay-sd.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func repaySD(c *cli.Context) error {

// 1. Check if repay more than need
if amountWei.Cmp(sdStatus.SdUtilizerLatestBalance) > 0 {
fmt.Printf("Repayment amount greater than the Utilization position. Your current Utilization Position is %0.6f \n", eth.WeiToEth(sdStatus.SdUtilizerLatestBalance))
fmt.Printf("Repayment amount greater than the Utilization position. Your current Utilization Position is %s \n", eth.DisplayAmountInUnits(sdStatus.SdUtilizerLatestBalance, "sd"))
return nil
}

Expand All @@ -84,7 +84,7 @@ func repaySD(c *cli.Context) error {
}

if allowance.Allowance.Cmp(amountWei) < 0 {
fmt.Printf("Before repaying the SD, you must first give the utility contract approval to interact with your SD. Amount to approve: %.6f\n", eth.WeiToEth(amountWei))
fmt.Printf("Before repaying the SD, you must first give the utility contract approval to interact with your SD. Amount to approve: %s\n", eth.DisplayAmountInUnits(amountWei, "sd"))

err = nodeApproveUtilitySd(c, amountInString)
if err != nil {
Expand All @@ -104,7 +104,7 @@ func repaySD(c *cli.Context) error {

// Prompt for confirmation
if !(c.Bool("yes") || cliutils.Confirm(fmt.Sprintf(
"Are you sure you want to repay %0.6f SD from your Operator Address and reduce or close your Utilization Position?", eth.WeiToEth(amountWei)))) {
"Are you sure you want to repay %s from your Operator Address and reduce or close your Utilization Position?", eth.DisplayAmountInUnits(amountWei, "sd")))) {
fmt.Println("Cancelled.")
return nil
}
Expand All @@ -121,7 +121,7 @@ func repaySD(c *cli.Context) error {
}

remainUtilize := new(big.Int).Sub(sdStatus.SdUtilizerLatestBalance, amountWei)
fmt.Printf("Repayment of %.6f SD successful. Current Utilization Position: %.6f SD.\n", eth.WeiToEth(amountWei), eth.WeiToEth(remainUtilize))
fmt.Printf("Repayment of %s successful. Current Utilization Position: %s.\n", eth.DisplayAmountInUnits(amountWei, "sd"), eth.DisplayAmountInUnits(remainUtilize, "sd"))

return nil
}
5 changes: 2 additions & 3 deletions stader-cli/node/send-el-rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/stader-labs/stader-node/shared/services/gas"
"github.com/stader-labs/stader-node/shared/services/stader"
cliutils "github.com/stader-labs/stader-node/shared/utils/cli"
"github.com/stader-labs/stader-node/shared/utils/math"
"github.com/stader-labs/stader-node/stader-lib/utils/eth"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -53,13 +52,13 @@ func SendElRewards(c *cli.Context) error {
if err != nil {
return err
}
fmt.Printf("Sending %.6f EL Rewards to Claim Vault\n\n", math.RoundDown(eth.WeiToEth(res.ElRewardsAmount), 6))
fmt.Printf("Sending %s EL Rewards to Claim Vault\n\n", eth.DisplayAmountInUnits(res.ElRewardsAmount, "eth"))
cliutils.PrintTransactionHash(staderClient, res.TxHash)
if _, err = staderClient.WaitForTransaction(res.TxHash); err != nil {
return err
}

// Log & return
fmt.Printf("Sent %.6f EL Rewards to Claim Vault\n\n", math.RoundDown(eth.WeiToEth(res.ElRewardsAmount), 6))
fmt.Printf("Sent %s EL Rewards to Claim Vault\n\n", eth.DisplayAmountInUnits(res.ElRewardsAmount, "eth"))
return nil
}
2 changes: 1 addition & 1 deletion stader-cli/node/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func nodeSend(c *cli.Context, amount float64, token string, toAddressOrENS strin
}

// Prompt for confirmation
if !(c.Bool("yes") || cliutils.Confirm(fmt.Sprintf("Are you sure you want to send %.6f %s to %s? This action cannot be undone!", math.RoundDown(eth.WeiToEth(amountWei), 6), token, toAddressString))) {
if !(c.Bool("yes") || cliutils.Confirm(fmt.Sprintf("Are you sure you want to send %.6f %s to %s? This action cannot be undone!", eth.WeiToEth(amountWei), token, toAddressString))) {
fmt.Println("Cancelled.")
return nil
}
Expand Down
Loading