Skip to content

Commit

Permalink
Merge pull request #433 from comdex-official/feature/dev
Browse files Browse the repository at this point in the history
Feature/dev
  • Loading branch information
dheerajkd30 authored Aug 30, 2022
2 parents 99037b2 + a97d63a commit d1872b4
Show file tree
Hide file tree
Showing 25 changed files with 461 additions and 361 deletions.
2 changes: 1 addition & 1 deletion proto/comdex/auction/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ message QueryDutchLendBiddingsResponse {

message QueryFilterDutchAuctionsRequest {
uint64 app_id = 1;
string denom = 2;
repeated string denom = 2;
bool history = 3;
cosmos.base.query.v1beta1.PageRequest pagination = 4
[(gogoproto.moretags) = "yaml:\"pagination\""];
Expand Down
24 changes: 13 additions & 11 deletions x/asset/keeper/pairs_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
rewardstypes "github.com/comdex-official/comdex/x/rewards/types"
sdk "github.com/cosmos/cosmos-sdk/types"
protobuftypes "github.com/gogo/protobuf/types"
"regexp"

"github.com/comdex-official/comdex/x/asset/types"
)
Expand Down Expand Up @@ -90,7 +91,7 @@ func (k Keeper) GetPairsVaults(ctx sdk.Context) (apps []types.ExtendedPairVault,
return apps, true
}

func (k Keeper) WasmExtendedPairByAppQuery(ctx sdk.Context, appID uint64) (extId []uint64, found bool) {
func (k Keeper) WasmExtendedPairByAppQuery(ctx sdk.Context, appID uint64) (extID []uint64, found bool) {
var (
store = k.Store(ctx)
iter = sdk.KVStorePrefixIterator(store, types.PairsVaultKeyPrefix)
Expand All @@ -106,15 +107,15 @@ func (k Keeper) WasmExtendedPairByAppQuery(ctx sdk.Context, appID uint64) (extId
for ; iter.Valid(); iter.Next() {
var extPair types.ExtendedPairVault
k.cdc.MustUnmarshal(iter.Value(), &extPair)
if extPair.AppId == appID {
extId = append(extId, extPair.Id)
if extPair.AppId == appID && !extPair.IsStableMintVault {
extID = append(extID, extPair.Id)
}
}
if extId == nil {
if extID == nil {
return nil, false
}

return extId, true
return extID, true
}

func (k Keeper) WasmAddExtendedPairsVaultRecords(ctx sdk.Context, pairVaultBinding *bindings.MsgAddExtendedPairsVault) error {
Expand All @@ -130,6 +131,12 @@ func (k Keeper) WasmAddExtendedPairsVaultRecords(ctx sdk.Context, pairVaultBindi
return types.ErrorPairDoesNotExist
}

var IsLetter = regexp.MustCompile(`^[A-Z-]+$`).MatchString

if !IsLetter(pairVaultBinding.PairName) {
return types.ErrorNameDidNotMeetCriterion
}

var id = k.GetPairsVaultID(ctx)

extendedPairVault, _ := k.GetPairsVaults(ctx)
Expand Down Expand Up @@ -229,13 +236,12 @@ func (k Keeper) WasmUpdatePairsVault(ctx sdk.Context, updatePairVault *bindings.
}
_, found1 := k.rewards.GetAppIDByApp(ctx, updatePairVault.AppID)
if found1 {
if ExtPairVaultData.StabilityFee != updatePairVault.StabilityFee {
if ExtPairVaultData.StabilityFee != updatePairVault.StabilityFee && !ExtPairVaultData.IsStableMintVault {
if updatePairVault.StabilityFee.IsZero() {
// run script to distrubyte reward
k.VaultIterateRewards(ctx, ExtPairVaultData.StabilityFee, ExtPairVaultData.BlockHeight, ExtPairVaultData.BlockTime.Unix(), updatePairVault.AppID, ExtPairVaultData.Id, false)
ExtPairVaultData.BlockTime = ctx.BlockTime()
ExtPairVaultData.BlockHeight = 0

} else if ExtPairVaultData.StabilityFee.IsZero() {
// do nothing
ExtPairVaultData.BlockHeight = ctx.BlockHeight()
Expand All @@ -245,7 +251,6 @@ func (k Keeper) WasmUpdatePairsVault(ctx sdk.Context, updatePairVault *bindings.
k.VaultIterateRewards(ctx, ExtPairVaultData.StabilityFee, ExtPairVaultData.BlockHeight, ExtPairVaultData.BlockTime.Unix(), updatePairVault.AppID, ExtPairVaultData.Id, true)
ExtPairVaultData.BlockHeight = ctx.BlockHeight()
ExtPairVaultData.BlockTime = ctx.BlockTime()

}
}
}
Expand Down Expand Up @@ -287,7 +292,6 @@ func (k Keeper) WasmCheckWhitelistedAssetQuery(ctx sdk.Context, denom string) (f
}

func (k Keeper) VaultIterateRewards(ctx sdk.Context, collectorLsr sdk.Dec, collectorBh, collectorBt int64, appID, pairVaultID uint64, changeTypes bool) {

extPairVault, found := k.vault.GetAppExtendedPairVaultMappingData(ctx, appID, pairVaultID)
if found {
for _, valID := range extPairVault.VaultIds {
Expand Down Expand Up @@ -349,8 +353,6 @@ func (k Keeper) VaultIterateRewards(ctx sdk.Context, collectorLsr sdk.Dec, colle
}
k.vault.SetVault(ctx, vaultData)
}

}
}

}
11 changes: 11 additions & 0 deletions x/auction/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"github.com/cosmos/cosmos-sdk/client"
"strings"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -54,3 +55,13 @@ func GetTxCmd() *cobra.Command {

return cmd
}

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

parsedStrings = append(parsedStrings, s)
}
return parsedStrings, nil
}
7 changes: 5 additions & 2 deletions x/auction/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,10 @@ func queryFilterDutchAuctions() *cobra.Command {
if err != nil {
return err
}
denom := args[1]
denoms, err := ParseStringFromString(args[1], ",")
if err != nil {
return err
}
history, err := strconv.ParseBool(args[2])
if err != nil {
return err
Expand All @@ -685,7 +688,7 @@ func queryFilterDutchAuctions() *cobra.Command {
context.Background(),
&types.QueryFilterDutchAuctionsRequest{
AppId: appID,
Denom: denom,
Denom: denoms,
History: history,
Pagination: pagination,
},
Expand Down
136 changes: 68 additions & 68 deletions x/auction/keeper/debt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (s *KeeperTestSuite) WasmSetCollectorLookupTableAndAuctionControlForSurplus
//userAddress := "cosmos1q7q90qsl9g0gl2zz0njxwv2a649yqrtyxtnv3v"
collectorKeeper, ctx := &s.collectorKeeper, &s.ctx

for index, tc := range []struct {
for _, tc := range []struct {
name string
msg bindings.MsgSetCollectorLookupTable
}{
Expand All @@ -39,49 +39,49 @@ func (s *KeeperTestSuite) WasmSetCollectorLookupTableAndAuctionControlForSurplus
s.Run(tc.name, func() {
err := collectorKeeper.WasmSetCollectorLookupTable(*ctx, &tc.msg)
s.Require().NoError(err)
result, found := collectorKeeper.GetCollectorLookupTable(*ctx, tc.msg.AppID)
result, found := collectorKeeper.GetCollectorLookupTable(*ctx, tc.msg.AppID, tc.msg.CollectorAssetID)
s.Require().True(found)
s.Require().Equal(result.AssetRateInfo[index].AppId, tc.msg.AppID)
s.Require().Equal(result.AssetRateInfo[index].CollectorAssetId, tc.msg.CollectorAssetID)
s.Require().Equal(result.AssetRateInfo[index].SecondaryAssetId, tc.msg.SecondaryAssetID)
s.Require().Equal(result.AssetRateInfo[index].SurplusThreshold, tc.msg.SurplusThreshold)
s.Require().Equal(result.AssetRateInfo[index].DebtThreshold, tc.msg.DebtThreshold)
s.Require().Equal(result.AssetRateInfo[index].LockerSavingRate, tc.msg.LockerSavingRate)
s.Require().Equal(result.AssetRateInfo[index].LotSize, tc.msg.LotSize)
s.Require().Equal(result.AssetRateInfo[index].BidFactor, tc.msg.BidFactor)
s.Require().Equal(result.AssetRateInfo[index].DebtLotSize, tc.msg.DebtLotSize)
s.Require().Equal(result.AppId, tc.msg.AppID)
s.Require().Equal(result.CollectorAssetId, tc.msg.CollectorAssetID)
s.Require().Equal(result.SecondaryAssetId, tc.msg.SecondaryAssetID)
s.Require().Equal(result.SurplusThreshold, tc.msg.SurplusThreshold)
s.Require().Equal(result.DebtThreshold, tc.msg.DebtThreshold)
s.Require().Equal(result.LockerSavingRate, tc.msg.LockerSavingRate)
s.Require().Equal(result.LotSize, tc.msg.LotSize)
s.Require().Equal(result.BidFactor, tc.msg.BidFactor)
s.Require().Equal(result.DebtLotSize, tc.msg.DebtLotSize)
})
}
//s.AddAuctionParams()
for index, tc := range []struct {
for _, tc := range []struct {
name string
msg bindings.MsgSetAuctionMappingForApp
}{
{
"Wasm Add Auction Control AppID 1 AssetID 2",
bindings.MsgSetAuctionMappingForApp{
AppID: 1,
AssetIDs: []uint64{2},
IsSurplusAuctions: []bool{true},
IsDebtAuctions: []bool{false},
IsDistributor: []bool{false},
AssetOutOraclePrices: []bool{false},
AssetOutPrices: []uint64{1000000},
AssetIDs: uint64(2),
IsSurplusAuctions: bool(true),
IsDebtAuctions: bool(false),
IsDistributor: bool(false),
AssetOutOraclePrices: bool(false),
AssetOutPrices: uint64(1000000),
},
},
} {
s.Run(tc.name, func() {
err := collectorKeeper.WasmSetAuctionMappingForApp(*ctx, &tc.msg)
s.Require().NoError(err)
result1, found := collectorKeeper.GetAuctionMappingForApp(*ctx, tc.msg.AppID)
result1, found := collectorKeeper.GetAuctionMappingForApp(*ctx, tc.msg.AppID, tc.msg.AssetIDs)
s.Require().True(found)
s.Require().Equal(result1.AssetIdToAuctionLookup[index].AssetId, tc.msg.AssetIDs[0])
s.Require().Equal(result1.AssetIdToAuctionLookup[index].IsSurplusAuction, tc.msg.IsSurplusAuctions[0])
s.Require().Equal(result1.AssetIdToAuctionLookup[index].IsDebtAuction, tc.msg.IsDebtAuctions[0])
s.Require().Equal(result1.AssetIdToAuctionLookup[index].IsDistributor, tc.msg.IsDistributor[0])
s.Require().Equal(result1.AssetIdToAuctionLookup[index].IsAuctionActive, false)
s.Require().Equal(result1.AssetIdToAuctionLookup[index].AssetOutOraclePrice, tc.msg.AssetOutOraclePrices[0])
s.Require().Equal(result1.AssetIdToAuctionLookup[index].AssetOutPrice, tc.msg.AssetOutPrices[0])
s.Require().Equal(result1.AssetId, tc.msg.AssetIDs)
s.Require().Equal(result1.IsSurplusAuction, tc.msg.IsSurplusAuctions)
s.Require().Equal(result1.IsDebtAuction, tc.msg.IsDebtAuctions)
s.Require().Equal(result1.IsDistributor, tc.msg.IsDistributor)
s.Require().Equal(result1.IsAuctionActive, false)
s.Require().Equal(result1.AssetOutOraclePrice, tc.msg.AssetOutOraclePrices)
s.Require().Equal(result1.AssetOutPrice, tc.msg.AssetOutPrices)
})
}

Expand All @@ -91,7 +91,7 @@ func (s *KeeperTestSuite) WasmSetCollectorLookupTableAndAuctionControlForDebt()
//userAddress := "cosmos1q7q90qsl9g0gl2zz0njxwv2a649yqrtyxtnv3v"
collectorKeeper, ctx := &s.collectorKeeper, &s.ctx

for index, tc := range []struct {
for _, tc := range []struct {
name string
msg bindings.MsgSetCollectorLookupTable
}{
Expand All @@ -112,49 +112,49 @@ func (s *KeeperTestSuite) WasmSetCollectorLookupTableAndAuctionControlForDebt()
s.Run(tc.name, func() {
err := collectorKeeper.WasmSetCollectorLookupTable(*ctx, &tc.msg)
s.Require().NoError(err)
result, found := collectorKeeper.GetCollectorLookupTable(*ctx, tc.msg.AppID)
result, found := collectorKeeper.GetCollectorLookupTable(*ctx, tc.msg.AppID, tc.msg.CollectorAssetID)
s.Require().True(found)
s.Require().Equal(result.AssetRateInfo[index].AppId, tc.msg.AppID)
s.Require().Equal(result.AssetRateInfo[index].CollectorAssetId, tc.msg.CollectorAssetID)
s.Require().Equal(result.AssetRateInfo[index].SecondaryAssetId, tc.msg.SecondaryAssetID)
s.Require().Equal(result.AssetRateInfo[index].SurplusThreshold, tc.msg.SurplusThreshold)
s.Require().Equal(result.AssetRateInfo[index].DebtThreshold, tc.msg.DebtThreshold)
s.Require().Equal(result.AssetRateInfo[index].LockerSavingRate, tc.msg.LockerSavingRate)
s.Require().Equal(result.AssetRateInfo[index].LotSize, tc.msg.LotSize)
s.Require().Equal(result.AssetRateInfo[index].BidFactor, tc.msg.BidFactor)
s.Require().Equal(result.AssetRateInfo[index].DebtLotSize, tc.msg.DebtLotSize)
s.Require().Equal(result.AppId, tc.msg.AppID)
s.Require().Equal(result.CollectorAssetId, tc.msg.CollectorAssetID)
s.Require().Equal(result.SecondaryAssetId, tc.msg.SecondaryAssetID)
s.Require().Equal(result.SurplusThreshold, tc.msg.SurplusThreshold)
s.Require().Equal(result.DebtThreshold, tc.msg.DebtThreshold)
s.Require().Equal(result.LockerSavingRate, tc.msg.LockerSavingRate)
s.Require().Equal(result.LotSize, tc.msg.LotSize)
s.Require().Equal(result.BidFactor, tc.msg.BidFactor)
s.Require().Equal(result.DebtLotSize, tc.msg.DebtLotSize)
})
}
//s.AddAuctionParams()
for index, tc := range []struct {
for _, tc := range []struct {
name string
msg bindings.MsgSetAuctionMappingForApp
}{
{
"Wasm Add Auction Control AppID 1 AssetID 2",
bindings.MsgSetAuctionMappingForApp{
AppID: 1,
AssetIDs: []uint64{2},
IsSurplusAuctions: []bool{false},
IsDebtAuctions: []bool{true},
IsDistributor: []bool{false},
AssetOutOraclePrices: []bool{false},
AssetOutPrices: []uint64{1000000},
AssetIDs: uint64(2),
IsSurplusAuctions: bool(false),
IsDebtAuctions: bool(true),
IsDistributor: bool(false),
AssetOutOraclePrices: bool(false),
AssetOutPrices: uint64(1000000),
},
},
} {
s.Run(tc.name, func() {
err := collectorKeeper.WasmSetAuctionMappingForApp(*ctx, &tc.msg)
s.Require().NoError(err)
result1, found := collectorKeeper.GetAuctionMappingForApp(*ctx, tc.msg.AppID)
result1, found := collectorKeeper.GetAuctionMappingForApp(*ctx, tc.msg.AppID, tc.msg.AssetIDs)
s.Require().True(found)
s.Require().Equal(result1.AssetIdToAuctionLookup[index].AssetId, tc.msg.AssetIDs[0])
s.Require().Equal(result1.AssetIdToAuctionLookup[index].IsSurplusAuction, tc.msg.IsSurplusAuctions[0])
s.Require().Equal(result1.AssetIdToAuctionLookup[index].IsDebtAuction, tc.msg.IsDebtAuctions[0])
s.Require().Equal(result1.AssetIdToAuctionLookup[index].IsDistributor, tc.msg.IsDistributor[0])
s.Require().Equal(result1.AssetIdToAuctionLookup[index].IsAuctionActive, false)
s.Require().Equal(result1.AssetIdToAuctionLookup[index].AssetOutOraclePrice, tc.msg.AssetOutOraclePrices[0])
s.Require().Equal(result1.AssetIdToAuctionLookup[index].AssetOutPrice, tc.msg.AssetOutPrices[0])
s.Require().Equal(result1.AssetId, tc.msg.AssetIDs)
s.Require().Equal(result1.IsSurplusAuction, tc.msg.IsSurplusAuctions)
s.Require().Equal(result1.IsDebtAuction, tc.msg.IsDebtAuctions)
s.Require().Equal(result1.IsDistributor, tc.msg.IsDistributor)
s.Require().Equal(result1.IsAuctionActive, false)
s.Require().Equal(result1.AssetOutOraclePrice, tc.msg.AssetOutOraclePrices)
s.Require().Equal(result1.AssetOutPrice, tc.msg.AssetOutPrices)
})
}

Expand Down Expand Up @@ -202,24 +202,24 @@ func (s *KeeperTestSuite) TestDebtActivator() {
debtAuction, err := k.GetDebtAuction(*ctx, appId, auctionMappingId, auctionId)
s.Require().NoError(err)

collectorLookUp, found := collectorKeeper.GetCollectorLookupTable(*ctx, 1)
collectorLookUp, found := collectorKeeper.GetCollectorLookupTable(*ctx, 1, 3)
s.Require().True(found)

netFees, found := k.GetNetFeeCollectedData(*ctx, uint64(1))
netFees, found := k.GetNetFeeCollectedData(*ctx, uint64(1), 3)
s.Require().True(found)

s.Require().Equal(debtAuction.AppId, appId)
s.Require().Equal(debtAuction.AuctionId, auctionId)
s.Require().Equal(debtAuction.AuctionMappingId, auctionMappingId)
s.Require().Equal(debtAuction.ActiveBiddingId, uint64(0))
s.Require().Equal(debtAuction.AuctionStatus, auctionTypes.AuctionStartNoBids)
s.Require().Equal(debtAuction.AssetInId, collectorLookUp.AssetRateInfo[0].CollectorAssetId)
s.Require().Equal(debtAuction.AssetOutId, collectorLookUp.AssetRateInfo[0].SecondaryAssetId)
s.Require().Equal(debtAuction.BidFactor, collectorLookUp.AssetRateInfo[0].BidFactor)
s.Require().Equal(debtAuction.ExpectedUserToken.Amount.Uint64(), collectorLookUp.AssetRateInfo[0].LotSize)
s.Require().Equal(debtAuction.AuctionedToken.Amount.Uint64(), collectorLookUp.AssetRateInfo[0].DebtLotSize)
s.Require().Equal(debtAuction.ExpectedMintedToken.Amount.Uint64(), collectorLookUp.AssetRateInfo[0].DebtLotSize)
s.Require().True(netFees.AssetIdToFeeCollected[0].NetFeesCollected.LTE(sdk.NewIntFromUint64(collectorLookUp.AssetRateInfo[0].DebtThreshold - collectorLookUp.AssetRateInfo[0].DebtLotSize)))
s.Require().Equal(debtAuction.AssetInId, collectorLookUp.CollectorAssetId)
s.Require().Equal(debtAuction.AssetOutId, collectorLookUp.SecondaryAssetId)
s.Require().Equal(debtAuction.BidFactor, collectorLookUp.BidFactor)
s.Require().Equal(debtAuction.ExpectedUserToken.Amount.Uint64(), collectorLookUp.LotSize)
s.Require().Equal(debtAuction.AuctionedToken.Amount.Uint64(), collectorLookUp.DebtLotSize)
s.Require().Equal(debtAuction.ExpectedMintedToken.Amount.Uint64(), collectorLookUp.DebtLotSize)
s.Require().True(netFees.NetFeesCollected.LTE(sdk.NewIntFromUint64(collectorLookUp.DebtThreshold - collectorLookUp.DebtLotSize)))

//Test restart debt auction
s.advanceseconds(301)
Expand All @@ -233,13 +233,13 @@ func (s *KeeperTestSuite) TestDebtActivator() {
s.Require().Equal(debtAuction1.AuctionMappingId, auctionMappingId)
s.Require().Equal(debtAuction1.ActiveBiddingId, uint64(0))
s.Require().Equal(debtAuction1.AuctionStatus, auctionTypes.AuctionStartNoBids)
s.Require().Equal(debtAuction1.AssetInId, collectorLookUp.AssetRateInfo[0].CollectorAssetId)
s.Require().Equal(debtAuction1.AssetOutId, collectorLookUp.AssetRateInfo[0].SecondaryAssetId)
s.Require().Equal(debtAuction1.BidFactor, collectorLookUp.AssetRateInfo[0].BidFactor)
s.Require().Equal(debtAuction1.ExpectedUserToken.Amount.Uint64(), collectorLookUp.AssetRateInfo[0].LotSize)
s.Require().Equal(debtAuction1.AuctionedToken.Amount.Uint64(), collectorLookUp.AssetRateInfo[0].DebtLotSize)
s.Require().Equal(debtAuction1.ExpectedMintedToken.Amount.Uint64(), collectorLookUp.AssetRateInfo[0].DebtLotSize)
s.Require().True(netFees.AssetIdToFeeCollected[0].NetFeesCollected.LTE(sdk.NewIntFromUint64(collectorLookUp.AssetRateInfo[0].DebtThreshold - collectorLookUp.AssetRateInfo[0].DebtLotSize)))
s.Require().Equal(debtAuction1.AssetInId, collectorLookUp.CollectorAssetId)
s.Require().Equal(debtAuction1.AssetOutId, collectorLookUp.SecondaryAssetId)
s.Require().Equal(debtAuction1.BidFactor, collectorLookUp.BidFactor)
s.Require().Equal(debtAuction1.ExpectedUserToken.Amount.Uint64(), collectorLookUp.LotSize)
s.Require().Equal(debtAuction1.AuctionedToken.Amount.Uint64(), collectorLookUp.DebtLotSize)
s.Require().Equal(debtAuction1.ExpectedMintedToken.Amount.Uint64(), collectorLookUp.DebtLotSize)
s.Require().True(netFees.NetFeesCollected.LTE(sdk.NewIntFromUint64(collectorLookUp.DebtThreshold - collectorLookUp.DebtLotSize)))
s.Require().Equal(ctx.BlockTime().Add(time.Second*time.Duration(300)), debtAuction1.EndTime)
}

Expand Down
Loading

0 comments on commit d1872b4

Please sign in to comment.