-
Notifications
You must be signed in to change notification settings - Fork 4
/
infpool_util_rate.go
43 lines (34 loc) · 1.05 KB
/
infpool_util_rate.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
package cmd
import (
"fmt"
"math/big"
"time"
"github.com/briandowns/spinner"
"github.com/spf13/cobra"
)
var inpoolUtilizationRateCmd = &cobra.Command{
Use: "utilization-rate",
Short: "Returns the percentage of FIL currently deployed from the Infinity Pool to Agents",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Querying the amount of FIL currently outstanding from the Infinity Pool")
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.Start()
defer s.Stop()
borrowed, err := PoolsSDK.Query().InfPoolTotalBorrowed(cmd.Context(), nil)
if err != nil {
logFatalf("Failed to get total borrowed %s", err)
}
assets, err := PoolsSDK.Query().InfPoolTotalAssets(cmd.Context(), nil)
if err != nil {
logFatalf("Failed to get iFIL balance %s", err)
}
s.Stop()
q := big.NewFloat(0).Quo(borrowed, assets)
per := big.NewFloat(0).Mul(q, big.NewFloat(100))
fmt.Printf("Infinity Pool deployed: %.04f%%\n", per)
},
}
func init() {
infinitypoolCmd.AddCommand(inpoolUtilizationRateCmd)
}