-
Notifications
You must be signed in to change notification settings - Fork 2
/
econ.go
78 lines (59 loc) · 2.35 KB
/
econ.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package econ
import (
"context"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/filecoin-project/lotus/chain/types"
"github.com/glifio/go-pools/constants"
"github.com/glifio/go-pools/mstat"
poolstypes "github.com/glifio/go-pools/types"
"github.com/glifio/go-pools/vc"
)
// TODO https://github.com/glif-confidential/ado/issues/9
func ComputeAgentData(
ctx context.Context,
sdk poolstypes.PoolsSDK,
agentAvailableBalance *big.Int,
principal *big.Int,
aggMinerStats *mstat.MinerStats,
agentAddr common.Address,
tsk *types.TipSet,
) (*vc.AgentData, error) {
// here we just work our way through the AgentData, computing each key
// TODO: could probably parellize this elegently to speed things up
data := &vc.AgentData{}
data.QaPower = aggMinerStats.QualityAdjPower
data.GreenScore = aggMinerStats.GreenScore
data.AgentValue = big.NewInt(0).Add(agentAvailableBalance, aggMinerStats.Balance)
/* ~~~~~ CollateralValue ~~~~~ */
ats, err := sdk.Query().AgentPreviewTerminationPrecise(ctx, agentAddr, tsk)
if err != nil {
return nil, err
}
// here we replace the ats.AgentAvailableBal with the agentAvailableBalance passed in this call to compute the post-action liquidation value
ats.AgentAvailableBal = agentAvailableBalance
data.CollateralValue = ats.LiquidationValue()
/* ~~~~~ Principal ~~~~~ */
data.Principal = principal
/* ~~~~~ SectorInfo ~~~~~ */
data.LiveSectors = aggMinerStats.LiveSectors
// using wad math
numerator := new(big.Int).Mul(principal, constants.WAD)
if data.CollateralValue.Cmp(big.NewInt(0)) == 0 {
data.FaultySectors = aggMinerStats.FaultySectors
} else if (new(big.Int).Div(numerator, data.CollateralValue)).Cmp(constants.MAX_LTV) > 0 {
// if the LTV (loan to liquidation value) is greater than the max LTV, we report faulty sectors in order to trigger a liquidation
// this is a bit of a workaround until the liquidation value buffer is built-in to the contracts directly
data.FaultySectors = aggMinerStats.LiveSectors
} else {
data.FaultySectors = aggMinerStats.FaultySectors
}
/* ~~~~~ ExpectedDailyFaultPenalties ~~~~~ */
// COULD REMOVE
data.ExpectedDailyFaultPenalties = aggMinerStats.PenaltyFaultPerDay
/* ~~~~~ ExpectedDailyRewards ~~~~~ */
data.ExpectedDailyRewards = aggMinerStats.ExpectedDailyReward
/* ~~~~~ GCRED (NOT IN USE) ~~~~~ */
data.Gcred = big.NewInt(100)
return data, nil
}