diff --git a/scripts/comdex_local_setup/main.py b/scripts/comdex_local_setup/main.py index 3fb31159c..8f7d41ee2 100644 --- a/scripts/comdex_local_setup/main.py +++ b/scripts/comdex_local_setup/main.py @@ -190,7 +190,7 @@ def CreateLiquidityPair(appID, baseCoinDenom, quoteCoinDenom): print(f"New Liquidity Pair ({baseCoinDenom}, {quoteCoinDenom}) Proposal Submitted ✔️") def CreateLiquidityPool(appID, pairID, depositCoins): - command = f"comdex tx liquidityV1 create-pool {appID} {pairID} {depositCoins} --from {GENESIS_ACCOUNT_NAME} --chain-id {CHAIN_ID} --gas 5000000 --keyring-backend test -y" + command = f"comdex tx liquidity create-pool {appID} {pairID} {depositCoins} --from {GENESIS_ACCOUNT_NAME} --chain-id {CHAIN_ID} --gas 5000000 --keyring-backend test -y" output = subprocess.getstatusoutput(command)[1] output = json.loads(output) if int(output["code"]) != 0: diff --git a/x/auction/expected/keeper.go b/x/auction/expected/keeper.go index b696209d2..a58dde61a 100644 --- a/x/auction/expected/keeper.go +++ b/x/auction/expected/keeper.go @@ -90,6 +90,11 @@ type TokenMintKeeper interface { type EsmKeeper interface { GetKillSwitchData(ctx sdk.Context, appID uint64) (esmtypes.KillSwitchParams, bool) GetESMStatus(ctx sdk.Context, id uint64) (esmStatus esmtypes.ESMStatus, found bool) + CalcDollarValueOfToken(ctx sdk.Context, rate uint64, amt sdk.Int, decimals sdk.Int) (price sdk.Dec) + SetAssetToAmount(ctx sdk.Context, assetToAmount esmtypes.AssetToAmount) + GetDataAfterCoolOff(ctx sdk.Context, id uint64) (esmDataAfterCoolOff esmtypes.DataAfterCoolOff, found bool) + SetDataAfterCoolOff(ctx sdk.Context, esmDataAfterCoolOff esmtypes.DataAfterCoolOff) + GetSnapshotOfPrices(ctx sdk.Context, appID, assetID uint64) (price uint64, found bool) } type LendKeeper interface { diff --git a/x/auction/keeper/dutch.go b/x/auction/keeper/dutch.go index fd8fe28c4..d6b95db6b 100644 --- a/x/auction/keeper/dutch.go +++ b/x/auction/keeper/dutch.go @@ -16,6 +16,7 @@ import ( utils "github.com/comdex-official/comdex/types" auctiontypes "github.com/comdex-official/comdex/x/auction/types" collectortypes "github.com/comdex-official/comdex/x/collector/types" + esmtypes "github.com/comdex-official/comdex/x/esm/types" ) func (k Keeper) DutchActivator(ctx sdk.Context, lockedVault liquidationtypes.LockedVault) error { @@ -290,8 +291,6 @@ func (k Keeper) PlaceDutchAuctionBid(ctx sdk.Context, appID, auctionMappingID, a // calculate inflow amount and outflow amount if user transaction successful auction.OutflowTokenCurrentAmount = auction.OutflowTokenCurrentAmount.Sub(outFlowTokenCoin) auction.InflowTokenCurrentAmount = auction.InflowTokenCurrentAmount.Add(inFlowTokenCoin) - outflowToReduce := outFlowTokenCoin - inflowToReduce := inFlowTokenCoin // collateral not over but target cmst reached then send remaining collateral to owner // if inflow token current amount >= InflowTokenTargetAmount if auction.InflowTokenCurrentAmount.IsGTE(auction.InflowTokenTargetAmount) { @@ -304,7 +303,6 @@ func (k Keeper) PlaceDutchAuctionBid(ctx sdk.Context, appID, auctionMappingID, a return err } } - outflowToReduce = outflowToReduce.Add(total) err = k.SetDutchAuction(ctx, auction) if err != nil { @@ -323,7 +321,6 @@ func (k Keeper) PlaceDutchAuctionBid(ctx sdk.Context, appID, auctionMappingID, a if err != nil { return err } - inflowToReduce = inflowToReduce.Add(requiredAmount) // storing protocol loss k.SetProtocolStatistics(ctx, auction.AppId, auction.AssetInId, requiredAmount.Amount) @@ -344,10 +341,6 @@ func (k Keeper) PlaceDutchAuctionBid(ctx sdk.Context, appID, auctionMappingID, a return err } } - err = k.UpdateProtocolData(ctx, outflowToReduce, inflowToReduce, lockedVault.ExtendedPairId) - if err != nil { - return err - } return nil } @@ -424,8 +417,14 @@ func (k Keeper) CloseDutchAuction( return err } } + + err := k.UpdateProtocolData(ctx, dutchAuction.OutflowTokenInitAmount, burnToken, lockedVault.ExtendedPairId) + if err != nil { + return err + } + // call increase function in collector - err := k.collector.SetNetFeeCollectedData(ctx, dutchAuction.AppId, dutchAuction.AssetInId, penaltyCoin.Amount) + err = k.collector.SetNetFeeCollectedData(ctx, dutchAuction.AppId, dutchAuction.AssetInId, penaltyCoin.Amount) if err != nil { return err } @@ -524,33 +523,93 @@ func (k Keeper) RestartDutchAuctions(ctx sdk.Context, appID uint64) error { // close auction func call inflowLeft := dutchAuction.InflowTokenTargetAmount.Amount.Sub(dutchAuction.InflowTokenCurrentAmount.Amount) penaltyAmt := dutchAuction.InflowTokenTargetAmount.Amount.Sub(lockedVault.AmountOut) + flag := false + if dutchAuction.InflowTokenCurrentAmount.Amount.GTE(lockedVault.AmountOut) { + flag = true + } + penaltyCoin := sdk.NewCoin(dutchAuction.InflowTokenCurrentAmount.Denom, sdk.ZeroInt()) + // burn and send target CMST to collector + burnToken := sdk.NewCoin(dutchAuction.InflowTokenCurrentAmount.Denom, sdk.ZeroInt()) + burnToken.Amount = lockedVault.AmountOut + penaltyCoin.Amount = dutchAuction.InflowTokenCurrentAmount.Amount.Sub(burnToken.Amount) vaultID, userExists := k.vault.GetUserAppExtendedPairMappingData(ctx, dutchAuction.VaultOwner.String(), dutchAuction.AppId, lockedVault.ExtendedPairId) - if userExists { - vaultData, _ := k.vault.GetVault(ctx, vaultID.VaultId) - if dutchAuction.OutflowTokenCurrentAmount.Amount.GT(sdk.ZeroInt()) { - err := k.bank.SendCoinsFromModuleToModule(ctx, auctiontypes.ModuleName, vaulttypes.ModuleName, sdk.NewCoins(dutchAuction.OutflowTokenCurrentAmount)) + if !flag { + if userExists { + vaultData, _ := k.vault.GetVault(ctx, vaultID.VaultId) + if dutchAuction.OutflowTokenCurrentAmount.Amount.GT(sdk.ZeroInt()) { + err := k.bank.SendCoinsFromModuleToModule(ctx, auctiontypes.ModuleName, vaulttypes.ModuleName, sdk.NewCoins(dutchAuction.OutflowTokenCurrentAmount)) + if err != nil { + return err + } + } + // append to existing vault + vaultData.AmountIn = vaultData.AmountIn.Add(dutchAuction.OutflowTokenCurrentAmount.Amount) + vaultData.AmountOut = vaultData.AmountOut.Add(inflowLeft).Sub(penaltyAmt) + k.vault.SetVault(ctx, vaultData) + } else { + if dutchAuction.OutflowTokenCurrentAmount.Amount.GT(sdk.ZeroInt()) { + err1 := k.bank.SendCoinsFromModuleToModule(ctx, auctiontypes.ModuleName, vaulttypes.ModuleName, sdk.NewCoins(dutchAuction.OutflowTokenCurrentAmount)) + if err1 != nil { + return err1 + } + } + // create new vault done + err := k.vault.CreateNewVault(ctx, dutchAuction.VaultOwner.String(), lockedVault.AppId, lockedVault.ExtendedPairId, dutchAuction.OutflowTokenCurrentAmount.Amount, inflowLeft.Sub(penaltyAmt)) if err != nil { return err } + length := k.vault.GetLengthOfVault(ctx) + k.vault.SetLengthOfVault(ctx, length+1) } - // append to existing vault - vaultData.AmountIn = vaultData.AmountIn.Add(dutchAuction.OutflowTokenCurrentAmount.Amount) - vaultData.AmountOut = vaultData.AmountOut.Add(inflowLeft).Sub(penaltyAmt) - k.vault.SetVault(ctx, vaultData) - } else { - if dutchAuction.OutflowTokenCurrentAmount.Amount.GT(sdk.ZeroInt()) { - err1 := k.bank.SendCoinsFromModuleToModule(ctx, auctiontypes.ModuleName, vaulttypes.ModuleName, sdk.NewCoins(dutchAuction.OutflowTokenCurrentAmount)) - if err1 != nil { - return err1 + burnToken.Amount = dutchAuction.InflowTokenCurrentAmount.Amount + } + // burning + if burnToken.Amount.GT(sdk.ZeroInt()) { + err := k.bank.BurnCoins(ctx, auctiontypes.ModuleName, sdk.NewCoins(burnToken)) + if err != nil { + return err + } + } + if flag { + // send penalty + if penaltyCoin.Amount.GT(sdk.ZeroInt()) { + err := k.bank.SendCoinsFromModuleToModule(ctx, auctiontypes.ModuleName, collectortypes.ModuleName, sdk.NewCoins(penaltyCoin)) + if err != nil { + return err } } - // create new vault done - err := k.vault.CreateNewVault(ctx, dutchAuction.VaultOwner.String(), lockedVault.AppId, lockedVault.ExtendedPairId, dutchAuction.OutflowTokenCurrentAmount.Amount, inflowLeft.Sub(penaltyAmt)) + + err = k.collector.SetNetFeeCollectedData(ctx, dutchAuction.AppId, dutchAuction.AssetInId, penaltyCoin.Amount) if err != nil { return err } - length := k.vault.GetLengthOfVault(ctx) - k.vault.SetLengthOfVault(ctx, length+1) + rateIn, found := k.esm.GetSnapshotOfPrices(ctx, appID, dutchAuction.AssetOutId) + if !found { + return esmtypes.ErrPriceNotFound + } + assetData, _ := k.asset.GetAsset(ctx, dutchAuction.AssetOutId) + var coolOffData esmtypes.DataAfterCoolOff + coolOffData.AppId = appID + var itemc esmtypes.AssetToAmount + itemc.AppId = appID + itemc.AssetID = dutchAuction.AssetOutId + itemc.Amount = dutchAuction.OutflowTokenCurrentAmount.Amount + itemc.IsCollateral = true + coolOffData.CollateralTotalAmount = k.esm.CalcDollarValueOfToken(ctx, rateIn, itemc.Amount, assetData.Decimals) + coolOffData.DebtTotalAmount = sdk.ZeroDec() + itemc.Share = sdk.OneDec() + err := k.bank.SendCoinsFromModuleToModule(ctx, auctiontypes.ModuleName, esmtypes.ModuleName, sdk.NewCoins(sdk.NewCoin(dutchAuction.OutflowTokenCurrentAmount.Denom, itemc.Amount))) + if err != nil { + return err + } + k.esm.SetAssetToAmount(ctx, itemc) + k.esm.SetDataAfterCoolOff(ctx, coolOffData) + // send that collateral to esm data for asset + } + + err := k.UpdateProtocolData(ctx, dutchAuction.OutflowTokenInitAmount.Sub(dutchAuction.OutflowTokenCurrentAmount), burnToken, lockedVault.ExtendedPairId) + if err != nil { + return err } dutchAuction.AuctionStatus = auctiontypes.AuctionEnded diff --git a/x/bandoracle/client/cli/cli.go b/x/bandoracle/client/cli/cli.go index 2f9b861f4..82fbf5229 100644 --- a/x/bandoracle/client/cli/cli.go +++ b/x/bandoracle/client/cli/cli.go @@ -6,16 +6,14 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - - "github.com/comdex-official/comdex/x/bandoracle/types" ) // GetQueryCmd returns the cli query commands for this module. func GetQueryCmd(queryRoute string) *cobra.Command { // Group bandoracle queries under a subcommand. cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Use: "bandoracle", + Short: fmt.Sprintf("Querying commands for the %s module", "bandoracle"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, @@ -32,8 +30,8 @@ func GetQueryCmd(queryRoute string) *cobra.Command { // GetTxCmd returns the transaction commands for this module. func GetTxCmd() *cobra.Command { cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + Use: "bandoracle", + Short: fmt.Sprintf("%s transactions subcommands", "bandoracle"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, diff --git a/x/collector/client/cli/tx.go b/x/collector/client/cli/tx.go index 7cd18e97b..51d692e61 100644 --- a/x/collector/client/cli/tx.go +++ b/x/collector/client/cli/tx.go @@ -13,7 +13,7 @@ import ( // GetTxCmd returns the transaction commands for this module. func GetTxCmd() *cobra.Command { cmd := &cobra.Command{ - Use: types.ModuleName, + Use: "collector", Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, diff --git a/x/esm/client/cli/query.go b/x/esm/client/cli/query.go index 332b2a377..fa6d3d0f8 100644 --- a/x/esm/client/cli/query.go +++ b/x/esm/client/cli/query.go @@ -18,8 +18,8 @@ import ( func GetQueryCmd(queryRoute string) *cobra.Command { // Group esm queries under a subcommand cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Use: "esm", + Short: fmt.Sprintf("Querying commands for the %s module", "esm"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, diff --git a/x/esm/client/cli/tx.go b/x/esm/client/cli/tx.go index a175077b8..83a593b15 100644 --- a/x/esm/client/cli/tx.go +++ b/x/esm/client/cli/tx.go @@ -16,8 +16,8 @@ import ( func GetTxCmd() *cobra.Command { cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + Use: "esm", + Short: fmt.Sprintf("%s transactions subcommands", "esm"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, diff --git a/x/esm/keeper/keeper.go b/x/esm/keeper/keeper.go index e0806b8ae..d6b293e82 100644 --- a/x/esm/keeper/keeper.go +++ b/x/esm/keeper/keeper.go @@ -217,9 +217,9 @@ func (k Keeper) CalculateCollateral(ctx sdk.Context, appID uint64, amount sdk.Co if tokenData.IsCollateral && !tokenData.Amount.IsZero() { // unitRate, _ := k.GetSnapshotOfPrices(ctx, appID, assetData.Id) - unitRate := k.GetRateOfAsset(ctx, appID, assetID.Id) + unitRate := k.GetRateOfAsset(ctx, appID, assetData.Id) if unitRate == 0 { - unitRate, found = k.GetSnapshotOfPrices(ctx, appID, assetID.Id) + unitRate, found = k.GetSnapshotOfPrices(ctx, appID, assetData.Id) if !found { return types.ErrPriceNotFound } diff --git a/x/liquidity/client/cli/query.go b/x/liquidity/client/cli/query.go index e7addd864..f5afa2dec 100644 --- a/x/liquidity/client/cli/query.go +++ b/x/liquidity/client/cli/query.go @@ -17,8 +17,8 @@ import ( // GetQueryCmd returns the cli query commands for this module. func GetQueryCmd() *cobra.Command { cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Use: "liquidity", + Short: fmt.Sprintf("Querying commands for the %s module", "liquidity"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, diff --git a/x/liquidity/client/cli/tx.go b/x/liquidity/client/cli/tx.go index 8f8d2f891..32f4bb5fc 100644 --- a/x/liquidity/client/cli/tx.go +++ b/x/liquidity/client/cli/tx.go @@ -21,8 +21,8 @@ import ( // GetTxCmd returns the transaction commands for the module. func GetTxCmd() *cobra.Command { cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + Use: "liquidity", + Short: fmt.Sprintf("%s transactions subcommands", "liquidity"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, diff --git a/x/locker/client/cli/cli.go b/x/locker/client/cli/cli.go index 467240343..4201482d6 100644 --- a/x/locker/client/cli/cli.go +++ b/x/locker/client/cli/cli.go @@ -6,16 +6,14 @@ import ( "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - - "github.com/comdex-official/comdex/x/locker/types" ) // GetQueryCmd returns the cli query commands for this module. func GetQueryCmd() *cobra.Command { // Group locker queries under a subcommand cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Use: "locker", + Short: fmt.Sprintf("Querying commands for the %s module", "locker"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, @@ -48,8 +46,8 @@ func GetQueryCmd() *cobra.Command { // GetTxCmd returns the transaction commands for this module. func GetTxCmd() *cobra.Command { cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + Use: "locker", + Short: fmt.Sprintf("%s transactions subcommands", "locker"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, diff --git a/x/rewards/client/cli/query.go b/x/rewards/client/cli/query.go index ed1651595..76467ecf9 100644 --- a/x/rewards/client/cli/query.go +++ b/x/rewards/client/cli/query.go @@ -20,8 +20,8 @@ import ( func GetQueryCmd() *cobra.Command { // Group rewards queries under a subcommand cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Use: "rewards", + Short: fmt.Sprintf("Querying commands for the %s module", "rewards"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, diff --git a/x/rewards/client/cli/tx.go b/x/rewards/client/cli/tx.go index 953dcf885..bb2cb5ef6 100644 --- a/x/rewards/client/cli/tx.go +++ b/x/rewards/client/cli/tx.go @@ -20,8 +20,8 @@ import ( // GetTxCmd returns the transaction commands for this module . func GetTxCmd() *cobra.Command { cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + Use: "rewards", + Short: fmt.Sprintf("%s transactions subcommands", "rewards"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, diff --git a/x/tokenmint/client/cli/query.go b/x/tokenmint/client/cli/query.go index da9a20e0d..0ca960c7e 100644 --- a/x/tokenmint/client/cli/query.go +++ b/x/tokenmint/client/cli/query.go @@ -16,8 +16,8 @@ import ( func GetQueryCmd() *cobra.Command { // Group tokenmint queries under a subcommand cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Use: "tokenmint", + Short: fmt.Sprintf("Querying commands for the %s module", "tokenmint"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, diff --git a/x/tokenmint/client/cli/tx.go b/x/tokenmint/client/cli/tx.go index f8b1ef869..e2409b781 100644 --- a/x/tokenmint/client/cli/tx.go +++ b/x/tokenmint/client/cli/tx.go @@ -16,8 +16,8 @@ import ( // GetTxCmd returns the transaction commands for this module. func GetTxCmd() *cobra.Command { cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + Use: "tokenmint", + Short: fmt.Sprintf("%s transactions subcommands", "tokenmint"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, diff --git a/x/vault/client/cli/query.go b/x/vault/client/cli/query.go index 2e36719a0..8d61b8f0d 100644 --- a/x/vault/client/cli/query.go +++ b/x/vault/client/cli/query.go @@ -14,8 +14,8 @@ import ( func GetQueryCmd() *cobra.Command { cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + Use: "vault", + Short: fmt.Sprintf("Querying commands for the %s module", "vault"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd, diff --git a/x/vault/client/cli/tx.go b/x/vault/client/cli/tx.go index f4e59805c..f71f0c89a 100644 --- a/x/vault/client/cli/tx.go +++ b/x/vault/client/cli/tx.go @@ -17,8 +17,8 @@ import ( // GetTxCmd returns the transaction commands for this module . func GetTxCmd() *cobra.Command { cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + Use: "vault", + Short: fmt.Sprintf("%s transactions subcommands", "vault"), DisableFlagParsing: true, SuggestionsMinimumDistance: 2, RunE: client.ValidateCmd,