Skip to content

Commit

Permalink
Improve liquidation value UI in info cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Schwartz10 committed Jan 22, 2024
1 parent e21baf7 commit a78091a
Showing 1 changed file with 41 additions and 23 deletions.
64 changes: 41 additions & 23 deletions cmd/agent_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ var agentInfoCmd = &cobra.Command{
logFatal(err)
}

agentData, err := econInfo(cmd.Context(), agentAddr, agentID, lapi, s)
agentData, ats, err := econInfo(cmd.Context(), agentAddr, agentID, lapi, s)
if err != nil {
logFatal(err)
}

err = agentHealth(cmd.Context(), agentAddr, agentData, s)
err = agentHealth(cmd.Context(), agentAddr, agentData, ats, s)
if err != nil {
logFatal(err)
}
Expand Down Expand Up @@ -167,18 +167,18 @@ func basicInfo(ctx context.Context, agent common.Address, agentDel address.Addre
return agentID, agentFILIDAddr, agVersion, ntwVersion, nil
}

func econInfo(ctx context.Context, agent common.Address, agentID *big.Int, lapi *api.FullNodeStruct, s *spinner.Spinner) (*vc.AgentData, error) {
func econInfo(ctx context.Context, agent common.Address, agentID *big.Int, lapi *api.FullNodeStruct, s *spinner.Spinner) (*vc.AgentData, terminate.PreviewAgentTerminationSummary, error) {

Check failure on line 170 in cmd/agent_info.go

View workflow job for this annotation

GitHub Actions / build

undefined: terminate.PreviewAgentTerminationSummary
query := PoolsSDK.Query()

adoCloser, err := PoolsSDK.Extern().ConnectAdoClient(ctx)
if err != nil {
return nil, err
return nil, terminate.PreviewAgentTerminationSummary{}, err

Check failure on line 175 in cmd/agent_info.go

View workflow job for this annotation

GitHub Actions / build

undefined: terminate.PreviewAgentTerminationSummary
}
defer adoCloser()

agentData, err := rpc.ADOClient.AgentData(context.Background(), agent)
if err != nil {
return nil, err
return nil, terminate.PreviewAgentTerminationSummary{}, err

Check failure on line 181 in cmd/agent_info.go

View workflow job for this annotation

GitHub Actions / build

undefined: terminate.PreviewAgentTerminationSummary
}

tasks := []util.TaskFunc{
Expand Down Expand Up @@ -209,24 +209,25 @@ func econInfo(ctx context.Context, agent common.Address, agentID *big.Int, lapi

results, err := util.Multiread(tasks)
if err != nil {
return nil, err
return nil, terminate.PreviewAgentTerminationSummary{}, err

Check failure on line 212 in cmd/agent_info.go

View workflow job for this annotation

GitHub Actions / build

undefined: terminate.PreviewAgentTerminationSummary
}
assets := results[0].(*big.Int)
maxBorrow := results[1].(*big.Int)
ats := results[2].(terminate.PreviewAgentTerminationSummary)

Check failure on line 216 in cmd/agent_info.go

View workflow job for this annotation

GitHub Actions / build

undefined: terminate.PreviewAgentTerminationSummary
liquidationValue := ats.LiquidationValue()
amountOwed := results[3].(*big.Int)
lvlAndCap := results[4].([]interface{})
lvl := lvlAndCap[0].(*big.Int)
cap := lvlAndCap[1].(float64)

nullCred, err := vc.NullishVerifiableCredential(*agentData)
if err != nil {
return nil, err
return nil, terminate.PreviewAgentTerminationSummary{}, err

Check failure on line 225 in cmd/agent_info.go

View workflow job for this annotation

GitHub Actions / build

undefined: terminate.PreviewAgentTerminationSummary
}

rate, err := query.InfPoolGetRate(ctx, *nullCred)
if err != nil {
return nil, err
return nil, terminate.PreviewAgentTerminationSummary{}, err

Check failure on line 230 in cmd/agent_info.go

View workflow job for this annotation

GitHub Actions / build

undefined: terminate.PreviewAgentTerminationSummary
}

wpr := new(big.Float).Mul(new(big.Float).SetInt(rate), big.NewFloat(constants.EpochsInWeek))
Expand Down Expand Up @@ -262,8 +263,10 @@ func econInfo(ctx context.Context, agent common.Address, agentID *big.Int, lapi

printTable([]string{
"Liquidation value",
"Recovery rate",
}, []string{
fmt.Sprintf("%0.09f FIL", util.ToFIL(ats.LiquidationValue())),
fmt.Sprintf("\033[1m%0.09f FIL\033[0m", util.ToFIL(liquidationValue)),
fmt.Sprintf("%0.03f%%", bigIntAttoToPercent(ats.RecoveryRate())),
})

if lvl.Cmp(big.NewInt(0)) == 0 && chainID == constants.MainnetChainID {
Expand Down Expand Up @@ -308,33 +311,39 @@ func econInfo(ctx context.Context, agent common.Address, agentID *big.Int, lapi
printTable(somethingBorrowedKeys, somethingBorrowedValues)

dti := new(big.Int).Div(dailyFees, agentData.ExpectedDailyRewards)
dtiFloat := new(big.Float).Mul(new(big.Float).SetInt(dti), big.NewFloat(100))
dtiFloat.Quo(dtiFloat, big.NewFloat(1e18))

ltv := ats.LTV(agentData.Principal)

coreEconKeys := []string{
"Agent's liquid FIL",
"Agent's total FIL",
"Agent's equity",
"Agent's expected weekly earnings",
"Agent's debt-to-equity (DTE)",
"Agent's debt-to-income (DTI)",
"Liquid FIL",
"Total FIL",
"Equity",
"Expected weekly earnings",
"Debt-to-liquidation-value (LTV)",
"Debt-to-equity (DTE)",
"Debt-to-income (DTI)",
}

coreEconValues := []string{
fmt.Sprintf("%0.08f FIL", util.ToFIL(assets)),
fmt.Sprintf("%0.08f FIL", util.ToFIL(agentData.AgentValue)),
fmt.Sprintf("%0.08f FIL", util.ToFIL(equity)),
fmt.Sprintf("%0.08f FIL", util.ToFIL(weeklyEarnings)),
fmt.Sprintf("%0.03f%% (must stay below 100%%)", dte.Mul(dte, big.NewFloat(100))),
fmt.Sprintf("%0.03f%% (must stay below 25%%)", dtiFloat),
fmt.Sprintf("%0.03f%% (must stay below %0.00f%%)", bigIntAttoToPercent(ltv), bigIntAttoToPercent(constants.MAX_LTV)),

Check failure on line 332 in cmd/agent_info.go

View workflow job for this annotation

GitHub Actions / build

undefined: constants.MAX_LTV
fmt.Sprintf("%0.03f%% (must stay below %0.00f%%)", dte.Mul(dte, big.NewFloat(100)), bigIntAttoToPercent(constants.MAX_DTE)),
fmt.Sprintf("%0.03f%% (must stay below %0.00f%%)", bigIntAttoToPercent(dti), bigIntAttoToPercent(constants.MAX_DTI)),
}

printTable(coreEconKeys, coreEconValues)
}

s.Start()

return agentData, nil
return agentData, ats, nil
}

func bigIntAttoToPercent(atto *big.Int) *big.Float {
return new(big.Float).Mul(util.ToFIL(atto), big.NewFloat(100))
}

func printTable(keys []string, values []string) {
Expand All @@ -348,7 +357,7 @@ func printTable(keys []string, values []string) {
tbl.Print()
}

func agentHealth(ctx context.Context, agent common.Address, agentData *vc.AgentData, s *spinner.Spinner) error {
func agentHealth(ctx context.Context, agent common.Address, agentData *vc.AgentData, ats terminate.PreviewAgentTerminationSummary, s *spinner.Spinner) error {

Check failure on line 360 in cmd/agent_info.go

View workflow job for this annotation

GitHub Actions / build

undefined: terminate.PreviewAgentTerminationSummary
query := PoolsSDK.Query()

tasks := []util.TaskFunc{
Expand Down Expand Up @@ -381,6 +390,8 @@ func agentHealth(ctx context.Context, agent common.Address, agentData *vc.AgentD
defaultEpoch := results[3].(*big.Int)
account := results[4].(abigen.Account)

overLTV := ats.LTV(agentData.Principal).Cmp(constants.MAX_LTV) > 0

weekOneDeadline := new(big.Int).Add(defaultEpoch, big.NewInt(constants.EpochsInWeek*2))

weekOneDeadlineTime := util.EpochHeightToTimestamp(weekOneDeadline, query.ChainID())
Expand Down Expand Up @@ -413,7 +424,7 @@ func agentHealth(ctx context.Context, agent common.Address, agentData *vc.AgentD
// convert limit into percentage for logging
limit := new(big.Float).Mul(constants.FAULTY_SECTOR_TOLERANCE, big.NewFloat(100))

if !badPmtStatus && !badFaultStatus && !pendingBadFaultStatus {
if !badPmtStatus && !badFaultStatus && !pendingBadFaultStatus && !overLTV {
fmt.Printf("Status healthy 🟢\n")
if owesPmt {
fmt.Printf("Your account owes its weekly payment (`to-current`) within the next: %s (by epoch # %s)\n", formatSinceDuration(weekOneDeadlineTime, epochsPaidTime), weekOneDeadline)
Expand All @@ -422,12 +433,19 @@ func agentHealth(ctx context.Context, agent common.Address, agentData *vc.AgentD
fmt.Println(chalk.Bold.TextStyle("Status unhealthy 🔴"))
}

if overLTV {
fmt.Printf("WARNING: Your Agent is over the LTV limit of %0.00f%%\n", bigIntAttoToPercent(constants.MAX_LTV))
fmt.Printf("Your Agent must pay down its debt or increase its collateral to avoid liquidation\n")
fmt.Printf("Contact the GLIF team as soon as possible\n")
}

if badPmtStatus {
fmt.Println("You are late on your weekly payment")
fmt.Printf("Your account *must* make a payment to-current within the next: %s (by epoch # %s)\n", formatSinceDuration(defaultEpochTime, epochsPaidTime), defaultEpoch)
}

if badFaultStatus {
// since we have to report faulty sectors when the Agent is overLTV, we only display this message if the Agent is not overLTV AND has faulty sectors
if badFaultStatus && !overLTV {
chainHeight, err := query.ChainHeight(ctx)
if err != nil {
return err
Expand Down

0 comments on commit a78091a

Please sign in to comment.