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

Feature/dev #597

Merged
merged 6 commits into from
Nov 14, 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
2 changes: 1 addition & 1 deletion scripts/comdex_local_setup/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions x/auction/expected/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
111 changes: 85 additions & 26 deletions x/auction/keeper/dutch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions x/bandoracle/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion x/collector/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/esm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/esm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/esm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions x/liquidity/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/liquidity/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions x/locker/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/rewards/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/rewards/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/tokenmint/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/tokenmint/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/vault/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions x/vault/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down