-
Notifications
You must be signed in to change notification settings - Fork 4
/
infpool_rate_from_gcred.go
49 lines (39 loc) · 1.33 KB
/
infpool_rate_from_gcred.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
/*
Copyright © 2023 Glif LTD
*/
package cmd
import (
"fmt"
"math/big"
"time"
"github.com/briandowns/spinner"
"github.com/glifio/go-pools/constants"
"github.com/spf13/cobra"
)
var rateFromGcredCmd = &cobra.Command{
Use: "rate-from-gcred <gcred>",
Short: "Get a preview of the Pool's fee rate from the current GCRED score.",
Long: "Get a preview of the Pool's fee rate from the current GCRED score. For example, `20%` means an Agent who borrows 100 will pay 20 in fees over 1 years worth of epochs.",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Querying the rate from a GCRED of %s from the Infinity Pool...\n", args[0])
s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.Start()
defer s.Stop()
gcred, ok := new(big.Int).SetString(args[0], 10)
if !ok {
logFatal(fmt.Errorf("Failed to parse GCRED %s", args[0]))
}
rate, err := PoolsSDK.Query().InfPoolRateFromGCRED(cmd.Context(), gcred)
if err != nil {
logFatal(err)
}
wprFloat, _ := new(big.Float).Mul(rate, big.NewFloat(constants.EpochsInWeek)).Float64()
aprFloat, _ := new(big.Float).Mul(rate, big.NewFloat(constants.EpochsInYear)).Float64()
s.Stop()
fmt.Printf("%.03f%% annually, %.03f%% weekly\n", aprFloat*100, wprFloat*100)
},
}
func init() {
infinitypoolCmd.AddCommand(rateFromGcredCmd)
}