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

Protocol v2 #158

Merged
merged 15 commits into from
Sep 4, 2024
367 changes: 82 additions & 285 deletions cmd/agent_info.go

Large diffs are not rendered by default.

50 changes: 23 additions & 27 deletions cmd/agent_liquidation_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ package cmd
import (
"fmt"
"log"
"math/big"
"time"

"github.com/briandowns/spinner"
"github.com/glifio/go-pools/terminate"
"github.com/glifio/go-pools/econ"
"github.com/glifio/go-pools/util"
"github.com/spf13/cobra"
"github.com/ttacon/chalk"
)

var liquidationValueCmd = &cobra.Command{
Expand All @@ -31,14 +31,12 @@ var liquidationValueCmd = &cobra.Command{
s.Start()
defer s.Stop()

agentCollateralStats, err := PoolsSDK.Query().AgentCollateralStatsQuick(cmd.Context(), agentAddr)
miners, baseFis, err := econ.GetBaseFisFromAPI(agentAddr, PoolsSDK.Extern().GetEventsURL())
if err != nil {
logFatal(err)
}
s.Stop()

ats := agentCollateralStats.Summarize()

minersKeys := []string{
"Miner liquidation values",
}
Expand All @@ -47,38 +45,36 @@ var liquidationValueCmd = &cobra.Command{
"",
}

for _, minerCollateral := range agentCollateralStats.MinersTerminationStats {
minersKeys = append(minersKeys, fmt.Sprintf("%s", minerCollateral.Address))
// here we instantiate a PreviewAgentTerminationSummary type to reuse its liquidation value and recovery rate funcs
ts := terminate.PreviewAgentTerminationSummary{
TerminationPenalty: minerCollateral.TerminationPenalty,
InitialPledge: minerCollateral.Pledged,
VestingBalance: minerCollateral.Vesting,
MinersAvailableBal: minerCollateral.Available,
AgentAvailableBal: big.NewInt(0),
}

minersValues = append(minersValues, fmt.Sprintf("%0.04f FIL (%0.02f%%)", util.ToFIL(ts.LiquidationValue()), bigIntAttoToPercent(ts.RecoveryRate())))
for i, miner := range miners {
baseFi := baseFis[i]
minersKeys = append(minersKeys, miner.String())
minersValues = append(minersValues, fmt.Sprintf("%0.04f FIL (%0.02f%%)", util.ToFIL(baseFi.LiquidationValue()), baseFi.RecoveryRate()*100))
}

agentCollateralStatsKeys := []string{
"Agent liquidation value",
}

agentCollateralStatsVals := []string{
fmt.Sprintf("%0.03f FIL (%0.02f%% recovery)", util.ToFIL(ats.LiquidationValue()), bigIntAttoToPercent(ats.RecoveryRate())),
"Agent liquidation value breakdown",
"Liquid FIL",
"Pledged",
"Vesting",
"Termination penalty",
"Total",
}

agentLiquidFILKey := []string{
"Agent's liquid FIL",
afi, err := econ.GetAgentFiFromAPI(agentAddr, PoolsSDK.Extern().GetEventsURL())
if err != nil {
logFatal(err)
}

agentLiquidFILValue := []string{
fmt.Sprintf("%0.04f FIL", util.ToFIL(ats.AgentAvailableBal)),
agentCollateralStatsVals := []string{
"",
fmt.Sprintf("%0.04f FIL", util.ToFIL(afi.AvailableBalance)),
fmt.Sprintf("%0.04f FIL", util.ToFIL(afi.InitialPledge)),
fmt.Sprintf("%0.04f FIL", util.ToFIL(afi.LockedRewards)),
fmt.Sprintf("-%0.04f FIL", util.ToFIL(afi.TerminationFee)),
fmt.Sprintf(chalk.Bold.TextStyle("%0.03f FIL (%0.02f%% recovery rate)"), util.ToFIL(afi.LiquidationValue()), afi.RecoveryRate()*100),
}

printTable(agentCollateralStatsKeys, agentCollateralStatsVals)
printTable(agentLiquidFILKey, agentLiquidFILValue)
printTable(minersKeys, minersValues)
fmt.Println()
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent_miners_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ var addCmd = &cobra.Command{

func init() {
minersCmd.AddCommand(addCmd)
addCmd.Flags().BoolVar(&addPreview, "preview", false, "preview the financial outcome of an add miner action")
addCmd.Flags().BoolVar(&addPreview, "preview", false, "DEPRECATED: preview the financial outcome of an add miner action")
}
2 changes: 1 addition & 1 deletion cmd/agent_miners_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ var rmCmd = &cobra.Command{

func init() {
minersCmd.AddCommand(rmCmd)
rmCmd.Flags().BoolVar(&removePreview, "preview", false, "preview the financial outcome of a remove miner action")
rmCmd.Flags().BoolVar(&removePreview, "preview", false, "DEPRECATED: preview the financial outcome of a remove miner action")
}
13 changes: 1 addition & 12 deletions cmd/agent_pay_current.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ var payToCurrentCmd = &cobra.Command{
Long: "Pays off all fees owed",
Run: func(cmd *cobra.Command, args []string) {
if payToCurrentPreview {
agentAddr, err := getAgentAddressWithFlags(cmd)
if err != nil {
logFatal(err)
}

amountOwed, err := PoolsSDK.Query().AgentInterestOwed(cmd.Context(), agentAddr, nil)
if err != nil {
logFatal(err)
}

args = append(args, util.ToFIL(amountOwed).String())
previewAction(cmd, args, constants.MethodPay)
return
}
Expand All @@ -46,5 +35,5 @@ func init() {
payCmd.AddCommand(payToCurrentCmd)
payToCurrentCmd.Flags().String("pool-name", "infinity-pool", "name of the pool to make a payment")
payToCurrentCmd.Flags().String("from", "", "address to send the transaction from")
payToCurrentCmd.Flags().BoolVar(&payToCurrentPreview, "preview", false, "preview financial outcome of pay to-current action")
payToCurrentCmd.Flags().BoolVar(&payToCurrentPreview, "preview", false, "DEPRECATED: preview financial outcome of pay to-current action")
}
2 changes: 1 addition & 1 deletion cmd/agent_pay_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ func init() {
payCmd.AddCommand(payCustomCmd)
payCustomCmd.Flags().String("pool-name", "infinity-pool", "name of the pool to make a payment")
payCustomCmd.Flags().String("from", "", "address to send the transaction from")
payCustomCmd.Flags().BoolVar(&payCustomPreview, "preview", false, "preview financial outcome of pay custom action")
payCustomCmd.Flags().BoolVar(&payCustomPreview, "preview", false, "DEPRECATED: preview financial outcome of pay custom action")
}
19 changes: 1 addition & 18 deletions cmd/agent_pay_principal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cmd

import (
"fmt"
"math/big"

"github.com/glifio/go-pools/constants"
"github.com/glifio/go-pools/util"
Expand All @@ -21,22 +20,6 @@ var payPrincipalCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if payPrincipalPreview {
agentAddr, err := getAgentAddressWithFlags(cmd)
if err != nil {
logFatal(err)
}
amount, err := parseFILAmount(args[0])
if err != nil {
logFatal(err)
}

amountOwed, err := PoolsSDK.Query().AgentInterestOwed(cmd.Context(), agentAddr, nil)
if err != nil {
logFatal(err)
}

payAmt := new(big.Int).Add(amount, amountOwed)
args = append(args, util.ToFIL(payAmt).String())
previewAction(cmd, args, constants.MethodPay)
return
}
Expand All @@ -53,5 +36,5 @@ func init() {
payCmd.AddCommand(payPrincipalCmd)
payPrincipalCmd.Flags().String("pool-name", "infinity-pool", "name of the pool to make a payment")
payPrincipalCmd.Flags().String("from", "", "address to send the transaction from")
payPrincipalCmd.Flags().BoolVar(&payPrincipalPreview, "preview", false, "preview financial outcome of pay principal action")
payPrincipalCmd.Flags().BoolVar(&payPrincipalPreview, "preview", false, "DEPRECATED: preview financial outcome of pay principal action")
}
94 changes: 0 additions & 94 deletions cmd/agent_preview.go

This file was deleted.

61 changes: 61 additions & 0 deletions cmd/ifil_allowance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cmd

import (
"fmt"
"time"

"github.com/briandowns/spinner"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/glifio/go-pools/abigen"
"github.com/glifio/go-pools/util"
"github.com/spf13/cobra"
)

var iFILAllowanceCmd = &cobra.Command{
Use: "allowance [owner] [spender]",
Short: "Get the iFIL balance of an address",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
owner := args[0]
spender := args[1]
fmt.Printf("Checking iFIL allowance of spender: %s on behalf of owner: %s ...", spender, owner)

s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
s.Start()
defer s.Stop()
ownerAddr, err := AddressOrAccountNameToEVM(cmd.Context(), owner)
if err != nil {
logFatalf("Failed to parse owner address %s", err)
}

spenderAddr, err := AddressOrAccountNameToEVM(cmd.Context(), spender)
if err != nil {
logFatalf("Failed to parse spender address %s", err)
}

client, err := PoolsSDK.Extern().ConnectEthClient()
if err != nil {
logFatalf("Failed to get iFIL balance %s", err)
}
defer client.Close()

poolToken, err := abigen.NewPoolTokenCaller(PoolsSDK.Query().IFIL(), client)
if err != nil {
logFatalf("Failed to get iFIL balance %s", err)
}

allow, err := poolToken.Allowance(&bind.CallOpts{}, ownerAddr, spenderAddr)
if err != nil {
logFatalf("Failed to get iFIL allowance %s", err)
}

s.Stop()

fmt.Printf("iFIL allowance for spender: %s on behalf of owner: %s is %.09f\n", spender, owner, util.ToFIL(allow))

},
}

func init() {
iFILCmd.AddCommand(iFILAllowanceCmd)
}
49 changes: 0 additions & 49 deletions cmd/infpool_rate_from_gcred.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/infpool_redeem.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var redeemFILCmd = &cobra.Command{
s.Start()
defer s.Stop()

tx, err := PoolsSDK.Act().RampRedeem(cmd.Context(), auth, amount, senderAccount.Address, receiver)
tx, err := PoolsSDK.Act().InfPoolRedeem(cmd.Context(), auth, amount, senderAccount.Address, receiver)
if err != nil {
logFatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/infpool_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var withdrawFILCmd = &cobra.Command{
s.Start()
defer s.Stop()

tx, err := PoolsSDK.Act().RampWithdraw(cmd.Context(), auth, amount, senderAccount.Address, receiver)
tx, err := PoolsSDK.Act().InfPoolWithdraw(cmd.Context(), auth, amount, senderAccount.Address, receiver)
if err != nil {
logFatal(err)
}
Expand Down
Loading
Loading