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

update gov porposal for lend module #263

Merged
merged 1 commit into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions x/collector/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,15 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"strconv"
"time"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/comdex-official/comdex/x/collector/types"
)

var (
DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds())
)

// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -187,7 +181,6 @@ func NewCmdAuctionControlProposal() *cobra.Command {
}

func NewCreateAuctionControlParams(clientCtx client.Context, txf tx.Factory, fs *flag.FlagSet) (tx.Factory, sdk.Msg, error) {

auctionControlParams, err := parseAuctionControlParamsFlags(fs)

if err != nil {
Expand Down
93 changes: 71 additions & 22 deletions x/lend/client/cli/flags.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
package cli

import (
flag "github.com/spf13/pflag"
"strconv"
"strings"
)

const (
flagName = "name"
flagDenom = "denom"
flagDecimal = "decimal"
flagCollateralWeight = "collateralWeight"
flagLiquidationThreshold = "liquidationThreshold"
flagBaseBorrowRate = "baseBorrowRate"
flagBaseLendRate = "baseLendRate"
flagAssetOne = "assetOne"
flagAssetTwo = "assetTwo"
flagModuleAcc = "moduleAcc"
flagbaseborrowrateasset1 = "baseborrowrateasset1"
flagbaseborrowrateasset2 = "baseborrowrateasset2"
flagbaselendrateasset1 = "baselendrateasset1"
flagbaselendrateasset2 = "baselendrateasset2"
flagIsBridgedAsset = "isBridgedAsset"
FlagNewLendPairFile = "add-lend-pair-file"
FlagAddLendPoolFile = "add-lend-pool-file"
FlagAddAssetRatesStatsFile = "add-asset-rates-stats-file"
)

func ParseStringFromString(s string, seperator string) ([]string, error) {
func ParseStringFromString(s string, separator string) ([]string, error) {
var parsedStrings []string
for _, s := range strings.Split(s, seperator) {
for _, s := range strings.Split(s, separator) {
s = strings.TrimSpace(s)

parsedStrings = append(parsedStrings, s)
}
return parsedStrings, nil
}

func ParseInt64SliceFromString(s string, seperator string) ([]int64, error) {
func ParseInt64SliceFromString(s string, separator string) ([]int64, error) {
var parsedInts []int64
for _, s := range strings.Split(s, seperator) {
for _, s := range strings.Split(s, separator) {
s = strings.TrimSpace(s)

parsed, err := strconv.ParseInt(s, 10, 64)
Expand All @@ -47,9 +36,9 @@ func ParseInt64SliceFromString(s string, seperator string) ([]int64, error) {
return parsedInts, nil
}

func ParseUint64SliceFromString(s string, seperator string) ([]uint64, error) {
func ParseUint64SliceFromString(s string, separator string) ([]uint64, error) {
var parsedInts []uint64
for _, s := range strings.Split(s, seperator) {
for _, s := range strings.Split(s, separator) {
s = strings.TrimSpace(s)

parsed, err := strconv.ParseUint(s, 10, 64)
Expand All @@ -62,11 +51,71 @@ func ParseUint64SliceFromString(s string, seperator string) ([]uint64, error) {
}

func ParseBoolFromString(s uint64) bool {

switch s {
case 1:
return true
default:
return false
}
}

func FlagSetNewLendPairsMapping() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)

fs.String(FlagNewLendPairFile, "", "add new lend pairs json file path")
return fs
}

func FlagSetAddLendPoolMapping() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)

fs.String(FlagAddLendPoolFile, "", "add new lend pool json file path")
return fs
}

func FlagSetAddAssetRatesStatsMapping() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)

fs.String(FlagAddAssetRatesStatsFile, "", "add asset rates stats json file path")
return fs
}

type addNewLendPairsInputs struct {
AssetIn string `json:"asset_in"`
AssetOut string `json:"asset_out"`
IsInterPool string `json:"is_inter_pool"`
AssetOutPoolID string `json:"asset_out_pool_id"`
LiquidationRatio string `json:"liquidation_ratio"`
Title string
Description string
Deposit string
}

type addLendPoolInputs struct {
ModuleName string `json:"module_name"`
FirstBridgedAssetID string `json:"first_bridged_asset_id"`
SecondBridgedAssetID string `json:"second_bridged_asset_id"`
AssetID string `json:"asset_id"`
IsBridgedAsset string `json:"is_bridged_asset"`
Title string
Description string
Deposit string
}

type addAssetRatesStatsInputs struct {
AssetID string `json:"asset_id"`
UOptimal string `json:"u_optimal"`
Base string `json:"base"`
Slope1 string `json:"slope_1"`
Slope2 string `json:"slope_2"`
StableBase string `json:"stable_base"`
StableSlope1 string `json:"stable_slope_1"`
StableSlope2 string `json:"stable_slope_2"`
LTV string `json:"ltv"`
LiquidationThreshold string `json:"liquidation_threshold"`
LiquidationPenalty string `json:"liquidation_penalty"`
ReserveFactor string `json:"reserve_factor"`
Title string
Description string
Deposit string
}
134 changes: 134 additions & 0 deletions x/lend/client/cli/parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package cli

import (
"bytes"
"encoding/json"
"fmt"
"github.com/spf13/pflag"
"io/ioutil"
)

type XAddNewLendPairsInputs addNewLendPairsInputs
type XAddLendPoolInputs addLendPoolInputs
type XAddAssetRatesStatsInputs addAssetRatesStatsInputs

type XAddNewLendPairsInputsExceptions struct {
XAddNewLendPairsInputs
Other *string // Other won't raise an error
}

type XAddPoolInputsExceptions struct {
XAddLendPoolInputs
Other *string // Other won't raise an error
}
type XAddAssetRatesStatsInputsExceptions struct {
XAddAssetRatesStatsInputs
Other *string // Other won't raise an error
}

// UnmarshalJSON should error if there are fields unexpected.
func (release *addNewLendPairsInputs) UnmarshalJSON(data []byte) error {
var addNewLendPairsParamsE XAddNewLendPairsInputsExceptions
dec := json.NewDecoder(bytes.NewReader(data))
dec.DisallowUnknownFields() // Force

if err := dec.Decode(&addNewLendPairsParamsE); err != nil {
return err
}

*release = addNewLendPairsInputs(addNewLendPairsParamsE.XAddNewLendPairsInputs)
return nil
}

// UnmarshalJSON should error if there are fields unexpected.
func (release *addLendPoolInputs) UnmarshalJSON(data []byte) error {
var addPoolParamsE XAddPoolInputsExceptions
dec := json.NewDecoder(bytes.NewReader(data))
dec.DisallowUnknownFields() // Force

if err := dec.Decode(&addPoolParamsE); err != nil {
return err
}

*release = addLendPoolInputs(addPoolParamsE.XAddLendPoolInputs)
return nil
}

func (release *addAssetRatesStatsInputs) UnmarshalJSON(data []byte) error {
var addAssetRatesStatsE XAddAssetRatesStatsInputsExceptions
dec := json.NewDecoder(bytes.NewReader(data))
dec.DisallowUnknownFields() // Force

if err := dec.Decode(&addAssetRatesStatsE); err != nil {
return err
}

*release = addAssetRatesStatsInputs(addAssetRatesStatsE.XAddAssetRatesStatsInputs)
return nil
}

func parseAddNewLendPairsFlags(fs *pflag.FlagSet) (*addNewLendPairsInputs, error) {
addLendPairsParams := &addNewLendPairsInputs{}
addLendPairsParamsFile, _ := fs.GetString(FlagNewLendPairFile)

if addLendPairsParamsFile == "" {
return nil, fmt.Errorf("must pass in a add new lend pairs json using the --%s flag", FlagNewLendPairFile)
}

contents, err := ioutil.ReadFile(addLendPairsParamsFile)
if err != nil {
return nil, err
}

// make exception if unknown field exists
err = addLendPairsParams.UnmarshalJSON(contents)
if err != nil {
return nil, err
}

return addLendPairsParams, nil
}

func parseAddPoolFlags(fs *pflag.FlagSet) (*addLendPoolInputs, error) {
addPoolParams := &addLendPoolInputs{}
addPoolParamsParamsFile, _ := fs.GetString(FlagAddLendPoolFile)

if addPoolParamsParamsFile == "" {
return nil, fmt.Errorf("must pass in a add new pool json using the --%s flag", FlagAddLendPoolFile)
}

contents, err := ioutil.ReadFile(addPoolParamsParamsFile)
if err != nil {
return nil, err
}

// make exception if unknown field exists
err = addPoolParams.UnmarshalJSON(contents)
if err != nil {
return nil, err
}

return addPoolParams, nil
}

func parseAssetRateStatsFlags(fs *pflag.FlagSet) (*addAssetRatesStatsInputs, error) {
addAssetRatesStats := &addAssetRatesStatsInputs{}
addAssetRatesStatsFile, _ := fs.GetString(FlagAddAssetRatesStatsFile)

if addAssetRatesStatsFile == "" {
return nil, fmt.Errorf("must pass in a add asset rates stats json using the --%s flag", FlagAddAssetRatesStatsFile)
}

contents, err := ioutil.ReadFile(addAssetRatesStatsFile)
if err != nil {
return nil, err
}

// make exception if unknown field exists
err = addAssetRatesStats.UnmarshalJSON(contents)
if err != nil {
return nil, err
}

return addAssetRatesStats, nil
}
Loading