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

Sd utilize #149

Merged
merged 196 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
196 commits
Select commit Hold shift + click to select a range
47540a6
Add contract API
batphonghan Nov 20, 2023
170badd
Add validator
batphonghan Nov 27, 2023
e419ffb
Update CLI
batphonghan Nov 28, 2023
1da6fe0
Check various require
batphonghan Nov 28, 2023
2dff0b3
Refactoring
batphonghan Nov 29, 2023
ce7b118
Refactor
batphonghan Nov 29, 2023
915985b
Refactor
batphonghan Nov 29, 2023
8974392
Update cli
batphonghan Nov 30, 2023
5740f6a
Update response
batphonghan Nov 30, 2023
d662db4
Refactor
batphonghan Nov 30, 2023
e258c3a
Refactor
batphonghan Nov 30, 2023
0d42106
Refactor
batphonghan Nov 30, 2023
4a27fc8
Fix typo
batphonghan Dec 1, 2023
34825ea
Add metrics
batphonghan Dec 4, 2023
9dee647
Refactor
batphonghan Dec 4, 2023
eb8f863
Refactoring
batphonghan Dec 4, 2023
8548583
Merge pull request #150 from stader-labs/SD_utilize_metrics
batphonghan Dec 5, 2023
3ea3bb0
Update deposit command
batphonghan Dec 5, 2023
a1c1b55
Refactor repay excess SD
batphonghan Dec 5, 2023
17b72da
Remove unused sd status
batphonghan Dec 5, 2023
7cd1954
Fix linter
batphonghan Dec 5, 2023
95d7143
add auto-deposit feature
bharath-123 Dec 5, 2023
5e06938
Update get SD status
batphonghan Dec 5, 2023
58b532c
Update ABI
batphonghan Dec 5, 2023
7504ce1
Update validator keys
batphonghan Dec 5, 2023
eb11955
Handle error in pool not had enough SD
batphonghan Dec 5, 2023
90e0865
Refactor
batphonghan Dec 5, 2023
02e9b3a
Update status
batphonghan Dec 5, 2023
8304a01
Merge pull request #151 from stader-labs/auto-deposit
batphonghan Dec 5, 2023
d32c379
Refactor
batphonghan Dec 5, 2023
98dacbe
Update percent
batphonghan Dec 5, 2023
0638c7a
Approve SD for repay
batphonghan Dec 5, 2023
daf3aa4
Update stader-cli/node/commands.go
batphonghan Dec 6, 2023
6f9824c
Add some more logs
batphonghan Dec 6, 2023
6da993b
Update status amount
batphonghan Dec 6, 2023
e87f16f
Refactor
batphonghan Dec 6, 2023
5241011
Update excess amount
batphonghan Dec 6, 2023
04a8d1a
Add interest
batphonghan Dec 6, 2023
4fb223a
Rename
batphonghan Dec 7, 2023
5d10895
refactor + withdraw-sd changes
bharath-123 Dec 7, 2023
204cdb7
prompt user to use deposit-sd cmd if they don't have enough collateral
bharath-123 Dec 7, 2023
7985ebb
some refactor
bharath-123 Dec 7, 2023
a8ca64e
minor refactor
bharath-123 Dec 7, 2023
4512d11
minor refactoring
bharath-123 Dec 7, 2023
1bdd683
refactor cmds
bharath-123 Dec 7, 2023
d3b862c
refactor
bharath-123 Dec 7, 2023
59aec33
Merge pull request #153 from stader-labs/withdraw-sd-rework
batphonghan Dec 7, 2023
d18607f
Update Reward Eligible
batphonghan Dec 7, 2023
d924c35
Merge pull request #154 from stader-labs/SD_utilize_refactor
batphonghan Dec 7, 2023
23381bf
Early return error
batphonghan Dec 7, 2023
b31dcc7
fix build errors
bharath-123 Dec 7, 2023
3f90e90
Merge branch 'SD_utilize' of https://github.com/stader-labs/stader-no…
bharath-123 Dec 7, 2023
ab21a31
Merge pull request #155 from stader-labs/withdraw-sd-rework
bharath-123 Dec 7, 2023
caf4ac5
withdraw-sd new flow
bharath-123 Dec 11, 2023
d38bc9f
Add SD utility pool balance metrics to grafana
bharath-123 Dec 11, 2023
a9dcd83
minor fix
bharath-123 Dec 11, 2023
0aed4f8
Calculate max SD can utilize
batphonghan Dec 11, 2023
a79924a
Update InsufficientEthBalance in SD status
batphonghan Dec 11, 2023
8b0ea08
improve text for repay-sd
bharath-123 Dec 11, 2023
fadf5dc
improve texts for utilize-sd
bharath-123 Dec 11, 2023
50fbb4e
improve texts
bharath-123 Dec 11, 2023
36f81a1
Update deposit flow
batphonghan Dec 11, 2023
d92152f
Remove check eth in sd status
batphonghan Dec 11, 2023
9b7f3b1
Refactor
batphonghan Dec 11, 2023
4e0f26a
Update copies
batphonghan Dec 11, 2023
b83e22b
Get utilizationRate
batphonghan Dec 11, 2023
1c0963f
Update APR
batphonghan Dec 11, 2023
8be5e06
In rate in float
batphonghan Dec 11, 2023
c36decb
Revert back comment
batphonghan Dec 11, 2023
6b41fed
Merge pull request #158 from stader-labs/sd_utility_update_copies
batphonghan Dec 11, 2023
3ed64c4
Merge remote-tracking branch 'origin/SD_utilize' into max_sd_utility
batphonghan Dec 11, 2023
77cfca7
Updated ABI
batphonghan Dec 11, 2023
70c7464
Merge pull request #157 from stader-labs/max_sd_utility
batphonghan Dec 11, 2023
1a5067c
update claim rewards flow
bharath-123 Dec 11, 2023
e422232
Merge branch 'SD_utilize' of https://github.com/stader-labs/stader-no…
bharath-123 Dec 11, 2023
64cf40d
add comment
bharath-123 Dec 11, 2023
0b0207f
minr refactor
bharath-123 Dec 11, 2023
e5fdff4
Merge pull request #156 from stader-labs/withdraw-sd
bharath-123 Dec 11, 2023
7f8b77a
Update version
bharath-123 Dec 11, 2023
a1487a5
Update success messages
batphonghan Dec 12, 2023
2cde7a7
Rename alias
batphonghan Dec 12, 2023
3f1952f
Refactor
batphonghan Dec 12, 2023
7455bdf
Merge pull request #160 from stader-labs/alias_update
batphonghan Dec 12, 2023
d589b50
Merge pull request #159 from stader-labs/SD_utilize_update_succes_msg
batphonghan Dec 12, 2023
e3ebeb8
check if sd collateral require amount is 0 when there are no validators
bharath-123 Dec 13, 2023
9bb4983
Merge pull request #162 from stader-labs/fixes
bharath-123 Dec 13, 2023
0f0c00b
Handle almost equal
batphonghan Dec 13, 2023
a8eebf2
Refactor
batphonghan Dec 13, 2023
bec65c8
Update totalCollateral amount
batphonghan Dec 13, 2023
d89534a
Update metrics
batphonghan Dec 13, 2023
b7e3b49
Merge pull request #161 from stader-labs/fixes
batphonghan Dec 13, 2023
41d6d23
Merge pull request #164 from stader-labs/SD_utilize_update_metrics
batphonghan Dec 13, 2023
e6bea6d
Merge remote-tracking branch 'origin/SD_utilize' into SD_utilize_hand…
batphonghan Dec 13, 2023
4f96879
Merge pull request #163 from stader-labs/SD_utilize_handle_almost_equ…
batphonghan Dec 13, 2023
8c9a1e2
fix getAvailablePoolBalance
bharath-123 Dec 13, 2023
a90dda3
Merge pull request #165 from stader-labs/update-total-utility-pool-ba…
bharath-123 Dec 13, 2023
2834927
Merge branch 'SD_utilize' of https://github.com/stader-labs/stader-no…
bharath-123 Dec 13, 2023
a5e1fe1
Merge branch 'SD_utilize_testing' of https://github.com/stader-labs/s…
bharath-123 Dec 13, 2023
5a3908b
some copy changes
bharath-123 Dec 13, 2023
42bd2bb
minor fixes
bharath-123 Dec 13, 2023
0abbcac
Merge pull request #166 from stader-labs/more-fixes
bharath-123 Dec 13, 2023
1258a37
Update withdraw SD message
batphonghan Dec 14, 2023
9f1d06d
Fix approve issue
batphonghan Dec 14, 2023
e559d81
Revert back build config
batphonghan Dec 14, 2023
dc4cdee
Merge pull request #167 from stader-labs/SD_utilize_update_withdraw_s…
batphonghan Dec 15, 2023
98880a9
Show small amount in float format
batphonghan Dec 15, 2023
ceb6bba
Remove convert from float to bigint
batphonghan Dec 15, 2023
53e3fee
increase precision of socializing pool rewards while displaying
bharath-123 Dec 18, 2023
c37fa59
minor fixes
bharath-123 Dec 18, 2023
a832fcd
Update contract
batphonghan Dec 24, 2023
cf1a202
Revert "Update contract"
batphonghan Dec 26, 2023
545be85
Merge remote-tracking branch 'origin/main' into SD_utilize
batphonghan Dec 26, 2023
b9719e9
referral id integration
bharath-123 Dec 27, 2023
aca491b
Merge branch 'SD_utilize' of https://github.com/stader-labs/stader-no…
bharath-123 Dec 27, 2023
31af385
Update status
batphonghan Dec 27, 2023
fb16a90
clamp max utilizable value
bharath-123 Jan 1, 2024
92609e6
add a newline
bharath-123 Jan 2, 2024
1b37f8e
minor refactoring
bharath-123 Jan 2, 2024
273c3ea
fix total collateral amount
bharath-123 Jan 2, 2024
836100d
sd utility pool contract to get-contracts-info
bharath-123 Jan 2, 2024
8794f71
add a newline
bharath-123 Jan 2, 2024
d9d2661
Update metrics
batphonghan Jan 2, 2024
26d8bfa
make sd float equality threshold 0.1
bharath-123 Jan 2, 2024
2347fb8
Merge remote-tracking branch 'origin/main' into SD_utilize
batphonghan Jan 3, 2024
9ee8c19
use claimFor
bharath-123 Jan 3, 2024
7615317
Merge branch 'SD_utilize' of https://github.com/stader-labs/stader-no…
bharath-123 Jan 3, 2024
198d3b2
fetch fee from userdata
bharath-123 Jan 3, 2024
27c79e2
fetch fee from userdata
bharath-123 Jan 3, 2024
8cfbaf5
dont show collateral info if there are no registered validators
bharath-123 Jan 3, 2024
982cd26
don't show claim amount below 0.00001 eth
bharath-123 Jan 3, 2024
4640473
add a newline
bharath-123 Jan 3, 2024
c26734c
use close approximations when converting wei to eth
bharath-123 Jan 3, 2024
d4cf25c
minor fixes
bharath-123 Jan 3, 2024
95de273
convert wei to gwei
bharath-123 Jan 3, 2024
8d8e9fc
minor fix
bharath-123 Jan 3, 2024
a7ee242
hard code the referral id
bharath-123 Jan 3, 2024
386f0ff
fix arg counts
bharath-123 Jan 4, 2024
98d8412
fix arg count
bharath-123 Jan 4, 2024
82e6492
add ethToWeiWithValCheck when repaying sd collateral
bharath-123 Jan 4, 2024
f006bcf
refactor display
bharath-123 Jan 4, 2024
edfaa0f
update precision
bharath-123 Jan 4, 2024
ee3623b
revert build info
bharath-123 Jan 4, 2024
94641d7
refactor
bharath-123 Jan 4, 2024
b3a835d
refactor repay-sd
bharath-123 Jan 4, 2024
59ecb25
refactor withdraw-sd
bharath-123 Jan 4, 2024
9e562c2
refactor remaining places
bharath-123 Jan 5, 2024
4913520
only display health factor if there is some utilized balance
bharath-123 Jan 5, 2024
bf426ba
Merge pull request #173 from stader-labs/display-refactor
bharath-123 Jan 5, 2024
290193b
cap bondable sd to user's balance
bharath-123 Jan 5, 2024
00c96e9
minor fixes
bharath-123 Jan 5, 2024
29667e9
fix copies
bharath-123 Jan 5, 2024
0266932
Update apr format
batphonghan Jan 6, 2024
ca89a11
Reload keys
batphonghan Jan 6, 2024
315962d
SD utilize fix phase 2
batphonghan Jan 10, 2024
d6e6028
Merge pull request #176 from stader-labs/SD_utilize_fixes_phase_2
batphonghan Jan 10, 2024
e4f6ba8
Add full options on repay-sd
batphonghan Jan 10, 2024
55d4576
minor updates
bharath-123 Jan 10, 2024
94f3953
minor typo fix
bharath-123 Jan 10, 2024
3a4632c
Inlcuded SdUtilizerLatestBalance in self bond flow
batphonghan Jan 10, 2024
f024f9c
update the version to a dev version
bharath-123 Jan 10, 2024
fcd9908
minor fixes
bharath-123 Jan 10, 2024
66fa3ab
minor fix
bharath-123 Jan 10, 2024
d1924f2
minor copy changes
bharath-123 Jan 10, 2024
67fac08
various fixes
batphonghan Jan 10, 2024
f0dde6c
Put back not enough excess SD collateral check
batphonghan Jan 11, 2024
aec1760
Update copy
batphonghan Jan 11, 2024
cd07ed1
Repay SD flow update
batphonghan Jan 12, 2024
de2eb8e
Update metrics
batphonghan Jan 15, 2024
5fdb79d
Merge remote-tracking branch 'origin/main' into SD_utilize
batphonghan Jan 16, 2024
26e4376
minor fixes
bharath-123 Jan 16, 2024
2a3732e
do not show repayment instructions if there is no utilized position
bharath-123 Jan 16, 2024
9a59885
Remove confirm on withdraw sd
batphonghan Jan 16, 2024
4eeecf5
Check if had any validator
batphonghan Jan 16, 2024
04e3834
Various number fixes
batphonghan Jan 16, 2024
7dd973e
Update copies
batphonghan Jan 16, 2024
c8dc8b7
Update maxUtilizable
batphonghan Jan 16, 2024
1bb8e44
use only one claim function
bharath-123 Jan 16, 2024
74fb129
display withdrawable eth in claim vault instead of complete claim bal…
bharath-123 Jan 17, 2024
a588f9c
WIP: c8dc8b70 Update maxUtilizable
batphonghan Jan 17, 2024
b79a0ef
Merge remote-tracking branch 'origin/main' into SD_utilize
batphonghan Jan 18, 2024
8bb260b
Add more metrics
batphonghan Jan 19, 2024
b3af591
Update metrics
batphonghan Jan 19, 2024
31355b8
Update metrics
batphonghan Jan 30, 2024
f1c373d
Update metrics's name
batphonghan Jan 30, 2024
128c585
Merge remote-tracking branch 'origin/main' into SD_utilize
batphonghan Jan 30, 2024
0f8796d
if there are no active validators, then pay interest from self bonded…
bharath-123 Jan 30, 2024
ee4830d
changes
bharath-123 Feb 1, 2024
60fdedd
Merge remote-tracking branch 'origin/main' into SD_utilize
batphonghan Feb 21, 2024
775d934
Merge remote-tracking branch 'origin/main' into SD_utilize
batphonghan Feb 22, 2024
caef917
Merge remote-tracking branch 'origin/main' into SD_utilize
batphonghan Feb 26, 2024
555849c
Refactor
batphonghan Feb 26, 2024
63c4f42
Merge remote-tracking branch 'origin/main' into SD_utilize
batphonghan Mar 1, 2024
466e9d1
Min to utility always be 1 SD
batphonghan Mar 1, 2024
d3870e3
Refactor
batphonghan Mar 4, 2024
194d41e
Update message
batphonghan Mar 4, 2024
03609fe
Update ABI
batphonghan Mar 4, 2024
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: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ linters:
- gocritic
- gofmt
- goimports
- gomnd
- gocyclo
- gosec
- gosimple
Expand Down
28 changes: 28 additions & 0 deletions shared/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ func GetStakePoolManagerAddress(c *cli.Context) (common.Address, error) {
return stader_config.GetStakePoolManagerAddress(sdcfg, nil)
}

func GetSdUtilityAddress(c *cli.Context) (common.Address, error) {
sdcfg, err := GetStaderConfigContract(c)
if err != nil {
return common.Address{}, err
}

return stader_config.GetSDUtilityPoolAddress(sdcfg, nil)
}

func GetPermissionlessNodeRegistry(c *cli.Context) (*stader.PermissionlessNodeRegistryContractManager, error) {
cfg, err := getConfig(c)
if err != nil {
Expand Down Expand Up @@ -422,6 +431,25 @@ func GetStakePoolManager(c *cli.Context) (*stader.StakePoolManagerContractManage
return stader.NewStakePoolManager(ec, stakePoolManagerAddress)
}

func GetSdUtilityContract(c *cli.Context) (*stader.SDUtilityPoolContractManager, error) {
_cfg, err := getConfig(c)
if err != nil {
return nil, err
}

ec, err := getEthClient(c, _cfg)
if err != nil {
return nil, err
}

sdUtilityAddress, err := GetSdUtilityAddress(c)
if err != nil {
return nil, err
}

return stader.NewSDUtilityPool(ec, sdUtilityAddress)
}

func GetBeaconClient(c *cli.Context) (*BeaconClientManager, error) {
cfg, err := getConfig(c)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion shared/services/stader/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,6 @@ func (c *Client) GetDockerContainerShutdownTime(container string) (time.Time, er
}

func (c *Client) UpdateGuardianConfiguration(contents []byte) error {

guardianTemplatePath, err := homedir.Expand(fmt.Sprintf("%s/%s/%s", c.configPath, templatesDir, GuardianFileTemplate))
if err != nil {
return fmt.Errorf("error expanding Guardian template path: %w", err)
Expand Down
101 changes: 97 additions & 4 deletions shared/services/stader/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ func (c *Client) GetNodeDepositSdAllowance() (api.NodeDepositSdAllowanceResponse
}

// Check whether the node can make a deposit
func (c *Client) CanNodeDeposit(amountWei *big.Int, numValidators *big.Int, reloadKeys bool) (api.CanNodeDepositResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("validator can-deposit %s %s %t", amountWei.String(), numValidators, reloadKeys))
func (c *Client) CanNodeDeposit(amountBasedWei, amountUtilityWei, numValidators *big.Int, reloadKeys bool) (api.CanNodeDepositResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("validator can-deposit %s %s %s %t", amountBasedWei.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 @@ -268,8 +268,8 @@ func (c *Client) GetContractsInfo() (api.ContractsInfoResponse, error) {
}

// Make a node deposit
func (c *Client) NodeDeposit(amountWei *big.Int, numValidators *big.Int, reloadKeys bool) (api.NodeDepositResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("validator deposit %s %s %t", amountWei.String(), numValidators, reloadKeys))
func (c *Client) NodeDeposit(amountWei, numValidators, utilitySDAmount *big.Int, reloadKeys bool) (api.NodeDepositResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("validator deposit %s %s %s %t", amountWei.String(), utilitySDAmount.String(), numValidators, reloadKeys))
if err != nil {
return api.NodeDepositResponse{}, fmt.Errorf("could not make validator deposit as er: %w", err)
}
Expand Down Expand Up @@ -625,12 +625,105 @@ func (c *Client) SetRewardAddress(operatorRewardAddress common.Address) (api.Set
if err != nil {
return api.SetRewardAddress{}, fmt.Errorf("could not get set-reward-address response: %w", err)
}

var response api.SetRewardAddress
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.SetRewardAddress{}, fmt.Errorf("could not decode set-reward-address response: %w", err)
}

if response.Error != "" {
return api.SetRewardAddress{}, fmt.Errorf("could not get set-reward-address response: %s", response.Error)
}

return response, nil
}

func (c *Client) RepaySd(amountWei *big.Int) (api.NodeRepaySDResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node repay-sd %s", amountWei.String()))
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)
}

return response, nil
}

func (c *Client) CanRepaySd(amountWei *big.Int) (api.CanRepaySDResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node can-repay-sd %s", amountWei.String()))
if err != nil {
return api.CanRepaySDResponse{}, fmt.Errorf("could not get CanNodeRepaySd SD: %w", err)
}

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

if response.Error != "" {
return api.CanRepaySDResponse{}, fmt.Errorf("could not can-repay SD: %s", response.Error)
}

return response, nil
}

func (c *Client) NodeUtilizeSd(amountWei *big.Int) (api.NodeUtilitySDResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node utilize-sd %s", amountWei.String()))
if err != nil {
return api.NodeUtilitySDResponse{}, fmt.Errorf("could not utilize SD: %w", err)
}

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

if response.Error != "" {
return api.NodeUtilitySDResponse{}, fmt.Errorf("could not utilize SD: %s", response.Error)
}

return response, nil
}

func (c *Client) CanNodeUtilizeSd(amountWei *big.Int) (api.CanUtilitySDResponse, error) {
responseBytes, err := c.callAPI(fmt.Sprintf("node can-utilize-sd %s", amountWei.String()))
if err != nil {
return api.CanUtilitySDResponse{}, fmt.Errorf("could not utilize SD: %w", err)
}

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

if response.Error != "" {
return api.CanUtilitySDResponse{}, fmt.Errorf("could not utilize SD: %s", response.Error)
}

return response, nil
}

func (c *Client) GetSDStatus() (api.GetSdStatusResponse, error) {
responseBytes, err := c.callAPI("node get-sd-status")
if err != nil {
return api.GetSdStatusResponse{}, fmt.Errorf("could not get-sd-status: %w", err)
}

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

if response.Error != "" {
return api.GetSdStatusResponse{}, fmt.Errorf("could not get SD status: %s", response.Error)
}

return response, nil
}
20 changes: 20 additions & 0 deletions shared/services/state/network-state.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/stader-labs/stader-node/shared/services"
"github.com/stader-labs/stader-node/shared/utils/stdr"
"github.com/stader-labs/stader-node/stader-lib/contracts"
"github.com/stader-labs/stader-node/stader-lib/sdutility"
"github.com/urfave/cli"

"github.com/stader-labs/stader-node/shared/utils/math"
Expand Down Expand Up @@ -114,6 +115,9 @@ type MetricDetails struct {
OperatorStakedSdInEth float64
// done
OperatorEthCollateral float64

// done
OperatorSDUtilized float64
}

type MetricsCache struct {
Expand Down Expand Up @@ -153,6 +157,11 @@ func CreateMetricsCache(
if err != nil {
return nil, err
}

sduAddress, err := services.GetSdUtilityAddress(c)
if err != nil {
return nil, err
}
ethxAddress, err := services.GetEthxTokenAddress(c)
if err != nil {
return nil, err
Expand Down Expand Up @@ -212,6 +221,11 @@ func CreateMetricsCache(
return nil, err
}

sdu, err := stader.NewSDUtilityPool(ec, sduAddress)
if err != nil {
return nil, err
}

// Get the execution block for the given slot
beaconBlock, exists, err := bc.GetBeaconBlock(fmt.Sprintf("%d", slotNumber))
if err != nil {
Expand Down Expand Up @@ -449,6 +463,11 @@ func CreateMetricsCache(
return nil, err
}

sdUtilized, err := sdutility.GetUtilizerLatestBalance(sdu, nodeAddress, nil)
if err != nil {
return nil, err
}

minThreshold := math.RoundDown(eth.WeiToEth(permissionlessPoolThreshold.MinThreshold), 2)
sdPriceFormatted := math.RoundDown(eth.WeiToEth(sdPrice), 2)
collateralRatioInSd := minThreshold * sdPriceFormatted
Expand Down Expand Up @@ -497,6 +516,7 @@ func CreateMetricsCache(
metricsDetails.UnclaimedSocializingPoolElRewards = math.RoundDown(eth.WeiToEth(rewardClaimData.unclaimedEth), SixDecimalRound)
metricsDetails.UnclaimedSocializingPoolSDRewards = math.RoundDown(eth.WeiToEth(rewardClaimData.unclaimedSd), SixDecimalRound)

metricsDetails.OperatorSDUtilized = math.RoundDown(eth.WeiToEth(sdUtilized), SixDecimalRound)
batphonghan marked this conversation as resolved.
Show resolved Hide resolved
state.StaderNetworkDetails = metricsDetails

state.logLine("Retrieved Stader Network Details (total time: %s)", time.Since(start))
Expand Down
77 changes: 67 additions & 10 deletions shared/types/api/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type CanNodeDepositSdResponse struct {
InsufficientBalance bool `json:"insufficientBalance"`
GasInfo stader.GasInfo `json:"gasInfo"`
}

type NodeDepositSdApproveGasResponse struct {
Status string `json:"status"`
Error string `json:"error"`
Expand Down Expand Up @@ -97,7 +98,6 @@ type CanNodeDepositResponse struct {
InsufficientBalance bool `json:"insufficientBalance"`
InvalidAmount bool `json:"invalidAmount"`
DepositPaused bool `json:"depositPaused"`
NotEnoughSdCollateral bool `json:"notEnoughSdCollateral"`
batphonghan marked this conversation as resolved.
Show resolved Hide resolved
MaxValidatorLimitReached bool `json:"maxValidatorLimitReached"`
InputKeyLimitReached bool `json:"inputKeyLimitReached"`
InputKeyLimit uint16 `json:"inputKeyLimit"`
Expand Down Expand Up @@ -265,11 +265,12 @@ type SendElRewardsResponse struct {
}

type CanWithdrawSdResponse struct {
Status string `json:"status"`
Error string `json:"error"`
InsufficientSdCollateral bool `json:"insufficientSdCollateral"`
InsufficientWithdrawableSd bool `json:"insufficientWithdrawableSd"`
GasInfo stader.GasInfo `json:"gasInfo"`
Status string `json:"status"`
Error string `json:"error"`
InsufficientSdCollateral bool `json:"insufficientSdCollateral"`
InsufficientWithdrawableSd bool `json:"insufficientWithdrawableSd"`
SdStatusResponse *SdStatusResponse `json:"sdStatusResponse"`
batphonghan marked this conversation as resolved.
Show resolved Hide resolved
GasInfo stader.GasInfo `json:"gasInfo"`
}

type WithdrawSdResponse struct {
Expand Down Expand Up @@ -393,10 +394,11 @@ type NodeSignResponse struct {
}

type CanClaimRewards struct {
Status string `json:"status"`
Error string `json:"error"`
NoRewards bool `json:"noRewards"`
GasInfo stader.GasInfo `json:"gasInfo"`
Status string `json:"status"`
Error string `json:"error"`
NoRewards bool `json:"noRewards"`
SdStatusResponse *SdStatusResponse `json:"sdStatusResponse"`
GasInfo stader.GasInfo `json:"gasInfo"`
}

type ClaimRewards struct {
Expand All @@ -406,3 +408,58 @@ type ClaimRewards struct {
OperatorRewardAddress common.Address `json:"operatorRewardAddress"`
TxHash common.Hash `json:"txHash"`
}

type NodeRepaySDResponse struct {
Status string `json:"status"`
Error string `json:"error"`
TxHash common.Hash `json:"txHash"`
}

type CanRepaySDResponse struct {
SdStatusResponse *SdStatusResponse `json:"sdStatusResponse"`
Status string `json:"status"`
Error string `json:"error"`
GasInfo stader.GasInfo `json:"gasInfo"`
}

type NodeUtilitySDResponse struct {
Status string `json:"status"`
Error string `json:"error"`
TxHash common.Hash `json:"txHash"`
}

type CanUtilitySDResponse struct {
Status string `json:"status"`
Error string `json:"error"`
GasInfo stader.GasInfo `json:"gasInfo"`
}

type GetSdStatusResponse struct {
SDStatus *SdStatusResponse `json:"sdStatusResponse"`
Status string `json:"status"`
Error string `json:"error"`
}

type SdStatusResponse struct {
SdUtilizerLatestBalance *big.Int `json:"sdUtilizerLatestBalance"`
SdCollateralCurrentAmount *big.Int `json:"sdCollateralCurrentAmount"`
SdCollateralRequireAmount *big.Int `json:"sdCollateralRequireAmount"`
SdMaxUtilizableAmount *big.Int `json:"sdMaxUtilizableAmount"`
SdMaxCollateralAmount *big.Int `json:"sdMaxCollateralAmount"`
SdBalance *big.Int `json:"sdBalance"`
PoolAvailableSDBalance *big.Int `json:"poolAvailableSDBalance"`
NotEnoughSdCollateral bool `json:"notEnoughSdCollateral"`
}

type NodeRepayExcessSDResponse struct {
Status string `json:"status"`
Error string `json:"error"`
TxHash common.Hash `json:"txHash"`
}

type CanRepayExcessSDResponse struct {
SdStatusResponse *SdStatusResponse `json:"sdStatusResponse"`
Status string `json:"status"`
Error string `json:"error"`
GasInfo stader.GasInfo `json:"gasInfo"`
}
8 changes: 8 additions & 0 deletions shared/utils/cli/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,11 @@ func ConfirmSecureSession(warning string) bool {

return true
}

func PrintError(msg string) {
fmt.Printf("%s%s%s\n", colorRed, msg, colorReset)
}

func PrintWarning(msg string) {
fmt.Printf("%s%s%s\n", colorYellow, msg, colorReset)
}
Loading