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

test cases fix #516

Merged
merged 18 commits into from
Oct 21, 2022
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func New(
}
supportedFeatures := "iterator,staking,stargate,comdex"

wasmOpts = append(cwasm.RegisterCustomPlugins(&app.LockerKeeper, &app.TokenmintKeeper, &app.AssetKeeper, &app.Rewardskeeper, &app.CollectorKeeper, &app.LiquidationKeeper, &app.AuctionKeeper, &app.EsmKeeper, &app.VaultKeeper), wasmOpts...)
wasmOpts = append(cwasm.RegisterCustomPlugins(&app.LockerKeeper, &app.TokenmintKeeper, &app.AssetKeeper, &app.Rewardskeeper, &app.CollectorKeeper, &app.LiquidationKeeper, &app.AuctionKeeper, &app.EsmKeeper, &app.VaultKeeper, &app.LendKeeper, &app.LiquidityKeeper), wasmOpts...)

app.WasmKeeper = wasmkeeper.NewKeeper(
app.cdc,
Expand Down
31 changes: 31 additions & 0 deletions app/wasm/bindings/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type ComdexQuery struct {
ExtendedPairByApp *ExtendedPairByApp `json:"extended_pair_by_app,omitempty"`
CheckSurplusReward *CheckSurplusReward `json:"check_surplus_reward,omitempty"`
CheckWhitelistedAsset *CheckWhitelistedAsset `json:"check_whitelisted_asset,omitempty"`
CheckVaultCreated *CheckVaultCreated `json:"check_vault_created,omitempty"`
CheckBorrowed *CheckBorrowed `json:"check_borrowed,omitempty"`
CheckLiquidityProvided *CheckLiquidityProvided `json:"check_liquidity_provided,omitempty"`
}

type AppData struct {
Expand Down Expand Up @@ -251,3 +254,31 @@ type CheckWhitelistedAsset struct {
type CheckWhitelistedAssetResponse struct {
Found bool `json:"found"`
}

type CheckVaultCreated struct {
Address string `json:"address"`
AppID uint64 `json:"app_id"`
}

type VaultCreatedResponse struct {
IsCompleted bool `json:"is_completed"`
}

type CheckBorrowed struct {
AssetID uint64 `json:"asset_id"`
Address string `json:"address"`
}

type BorrowedResponse struct {
IsCompleted bool `json:"is_completed"`
}

type CheckLiquidityProvided struct {
AppID uint64 `json:"app_id"`
PoolID uint64 `json:"pool_id"`
Address string `json:"address"`
}

type LiquidityProvidedResponse struct {
IsCompleted bool `json:"is_completed"`
}
27 changes: 27 additions & 0 deletions app/wasm/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
assetKeeper "github.com/comdex-official/comdex/x/asset/keeper"
collectorkeeper "github.com/comdex-official/comdex/x/collector/keeper"
esmKeeper "github.com/comdex-official/comdex/x/esm/keeper"
lendKeeper "github.com/comdex-official/comdex/x/lend/keeper"
liquidationKeeper "github.com/comdex-official/comdex/x/liquidation/keeper"
liquidityKeeper "github.com/comdex-official/comdex/x/liquidity/keeper"
lockerkeeper "github.com/comdex-official/comdex/x/locker/keeper"
rewardsKeeper "github.com/comdex-official/comdex/x/rewards/keeper"
tokenMintKeeper "github.com/comdex-official/comdex/x/tokenmint/keeper"
Expand All @@ -22,6 +24,8 @@ type QueryPlugin struct {
liquidationKeeper *liquidationKeeper.Keeper
esmKeeper *esmKeeper.Keeper
vaultKeeper *vaultKeeper.Keeper
lendKeeper *lendKeeper.Keeper
liquidityKeeper *liquidityKeeper.Keeper
}

func NewQueryPlugin(
Expand All @@ -33,6 +37,8 @@ func NewQueryPlugin(
liquidation *liquidationKeeper.Keeper,
esmKeeper *esmKeeper.Keeper,
vaultKeeper *vaultKeeper.Keeper,
lendKeeper *lendKeeper.Keeper,
liquidityKeeper *liquidityKeeper.Keeper,
) *QueryPlugin {
return &QueryPlugin{
assetKeeper: assetKeeper,
Expand All @@ -43,6 +49,8 @@ func NewQueryPlugin(
liquidationKeeper: liquidation,
esmKeeper: esmKeeper,
vaultKeeper: vaultKeeper,
lendKeeper: lendKeeper,
liquidityKeeper: liquidityKeeper,
}
}

Expand Down Expand Up @@ -164,3 +172,22 @@ func (qp QueryPlugin) WasmCheckWhitelistedAsset(ctx sdk.Context, denom string) (
found = qp.assetKeeper.WasmCheckWhitelistedAssetQuery(ctx, denom)
return found
}

func (qp QueryPlugin) WasmCheckVaultCreated(ctx sdk.Context, address string, appID uint64) (found bool) {
_, found = qp.vaultKeeper.GetUserAppMappingData(ctx, address, appID)
return found
}

func (qp QueryPlugin) WasmCheckBorrowed(ctx sdk.Context, assetID uint64, address string) (found bool) {
found = qp.lendKeeper.WasmHasBorrowForAddressAndAsset(ctx, assetID, address)
return found
}

func (qp QueryPlugin) WasmCheckLiquidityProvided(ctx sdk.Context, appID, poolID uint64, address string) (found bool) {
farmer, err := sdk.AccAddressFromBech32(address)
if err != nil {
return false
}
_, found = qp.liquidityKeeper.GetActiveFarmer(ctx, appID, poolID, farmer)
return found
}
37 changes: 37 additions & 0 deletions app/wasm/query_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,43 @@ func CustomQuerier(queryPlugin *QueryPlugin) func(ctx sdk.Context, request json.
return nil, sdkerrors.Wrap(err, "CheckWhitelistedAssetResponse query response")
}
return bz, nil
} else if comdexQuery.CheckVaultCreated != nil {
Address := comdexQuery.CheckVaultCreated.Address
AppID := comdexQuery.CheckVaultCreated.AppID
found := queryPlugin.WasmCheckVaultCreated(ctx, Address, AppID)
res := bindings.VaultCreatedResponse{
IsCompleted: found,
}
bz, err := json.Marshal(res)
if err != nil {
return nil, sdkerrors.Wrap(err, "VaultCreatedResponse query response")
}
return bz, nil
} else if comdexQuery.CheckBorrowed != nil {
AssetID := comdexQuery.CheckBorrowed.AssetID
Address := comdexQuery.CheckBorrowed.Address
found := queryPlugin.WasmCheckBorrowed(ctx, AssetID, Address)
res := bindings.BorrowedResponse{
IsCompleted: found,
}
bz, err := json.Marshal(res)
if err != nil {
return nil, sdkerrors.Wrap(err, "BorrowedResponse query response")
}
return bz, nil
} else if comdexQuery.CheckLiquidityProvided != nil {
AppID := comdexQuery.CheckLiquidityProvided.AppID
PoolID := comdexQuery.CheckLiquidityProvided.PoolID
Address := comdexQuery.CheckLiquidityProvided.Address
found := queryPlugin.WasmCheckLiquidityProvided(ctx, AppID, PoolID, Address)
res := bindings.LiquidityProvidedResponse{
IsCompleted: found,
}
bz, err := json.Marshal(res)
if err != nil {
return nil, sdkerrors.Wrap(err, "LiquidityProvidedResponse query response")
}
return bz, nil
}
return nil, wasmvmtypes.UnsupportedRequest{Kind: "unknown App Data query variant"}
}
Expand Down
36 changes: 27 additions & 9 deletions app/wasm/test/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ func TestWhitelistAssetLocker(t *testing.T) {
&comdex.CollectorKeeper,
&comdex.LiquidationKeeper,
&comdex.EsmKeeper,
&comdex.VaultKeeper)
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgWhiteListAssetLocker
Expand Down Expand Up @@ -61,7 +63,9 @@ func TestAddMsgAddExtendedPairsVault(t *testing.T) {
&comdex.CollectorKeeper,
&comdex.LiquidationKeeper,
&comdex.EsmKeeper,
&comdex.VaultKeeper)
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgAddExtendedPairsVault
Expand Down Expand Up @@ -116,7 +120,9 @@ func TestMsgSetCollectorLookupTable(t *testing.T) {
&comdex.CollectorKeeper,
&comdex.LiquidationKeeper,
&comdex.EsmKeeper,
&comdex.VaultKeeper)
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgSetCollectorLookupTable
Expand Down Expand Up @@ -165,7 +171,9 @@ func TestMsgSetAuctionMappingForApp(t *testing.T) {
&comdex.CollectorKeeper,
&comdex.LiquidationKeeper,
&comdex.EsmKeeper,
&comdex.VaultKeeper)
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgSetAuctionMappingForApp
Expand Down Expand Up @@ -213,7 +221,9 @@ func TestMsgUpdateCollectorLookupTable(t *testing.T) {
&comdex.CollectorKeeper,
&comdex.LiquidationKeeper,
&comdex.EsmKeeper,
&comdex.VaultKeeper)
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgUpdateCollectorLookupTable
Expand Down Expand Up @@ -262,7 +272,9 @@ func TestMsgUpdatePairsVault(t *testing.T) {
&comdex.CollectorKeeper,
&comdex.LiquidationKeeper,
&comdex.EsmKeeper,
&comdex.VaultKeeper)
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgUpdatePairsVault
Expand Down Expand Up @@ -315,7 +327,9 @@ func TestMsgWhitelistAppIDLiquidation(t *testing.T) {
&comdex.CollectorKeeper,
&comdex.LiquidationKeeper,
&comdex.EsmKeeper,
&comdex.VaultKeeper)
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgWhitelistAppIDLiquidation
Expand Down Expand Up @@ -360,7 +374,9 @@ func TestMsgRemoveWhitelistAppIDLiquidation(t *testing.T) {
&comdex.CollectorKeeper,
&comdex.LiquidationKeeper,
&comdex.EsmKeeper,
&comdex.VaultKeeper)
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgRemoveWhitelistAppIDLiquidation
Expand Down Expand Up @@ -401,7 +417,9 @@ func TestMsgAddAuctionParams(t *testing.T) {
&comdex.CollectorKeeper,
&comdex.LiquidationKeeper,
&comdex.EsmKeeper,
&comdex.VaultKeeper)
&comdex.VaultKeeper,
&comdex.LendKeeper,
&comdex.LiquidityKeeper)
for _, tc := range []struct {
name string
msg *bindings.MsgAddAuctionParams
Expand Down
6 changes: 5 additions & 1 deletion app/wasm/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
auctionKeeper "github.com/comdex-official/comdex/x/auction/keeper"
collectorKeeper "github.com/comdex-official/comdex/x/collector/keeper"
esmKeeper "github.com/comdex-official/comdex/x/esm/keeper"
lendKeeper "github.com/comdex-official/comdex/x/lend/keeper"
liquidationKeeper "github.com/comdex-official/comdex/x/liquidation/keeper"
liquidityKeeper "github.com/comdex-official/comdex/x/liquidity/keeper"
lockerkeeper "github.com/comdex-official/comdex/x/locker/keeper"
rewardsKeeper "github.com/comdex-official/comdex/x/rewards/keeper"
tokenMintkeeper "github.com/comdex-official/comdex/x/tokenmint/keeper"
Expand All @@ -25,8 +27,10 @@ func RegisterCustomPlugins(
auction *auctionKeeper.Keeper,
esm *esmKeeper.Keeper,
vault *vaultKeeper.Keeper,
lend *lendKeeper.Keeper,
liquidity *liquidityKeeper.Keeper,
) []wasmkeeper.Option {
comdexQueryPlugin := NewQueryPlugin(asset, locker, tokenMint, rewards, collector, liquidation, esm, vault)
comdexQueryPlugin := NewQueryPlugin(asset, locker, tokenMint, rewards, collector, liquidation, esm, vault, lend, liquidity)

appDataQueryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{
Custom: CustomQuerier(comdexQueryPlugin),
Expand Down
1 change: 1 addition & 0 deletions proto/comdex/bandoracle/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ message MsgFetchPriceData {
uint64 prepare_gas = 9;
uint64 execute_gas = 10;
string client_id = 11 [(gogoproto.customname) = "ClientID"];
uint64 twa_batch_size = 12;
}

message MsgFetchPriceDataResponse {
Expand Down
14 changes: 3 additions & 11 deletions proto/comdex/lend/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ service Msg {
// FundModuleAccounts funds an existing module account
rpc FundModuleAccounts(MsgFundModuleAccounts) returns (MsgFundModuleAccountsResponse);

rpc CalculateBorrowInterest(MsgCalculateBorrowInterest) returns (MsgCalculateBorrowInterestResponse);
rpc CalculateInterestAndRewards(MsgCalculateInterestAndRewards) returns (MsgCalculateInterestAndRewardsResponse);

rpc CalculateLendRewards(MsgCalculateLendRewards) returns (MsgCalculateLendRewardsResponse);
}

message MsgLend {
Expand Down Expand Up @@ -115,15 +114,10 @@ message MsgFundModuleAccounts {
cosmos.base.v1beta1.Coin amount = 4 [(gogoproto.nullable) = false];
}

message MsgCalculateBorrowInterest {
message MsgCalculateInterestAndRewards {
string borrower = 1;
uint64 borrow_id = 2;
}

message MsgCalculateLendRewards{
string lender = 1;
uint64 lend_id = 2;
}

message MsgLendResponse {}

Expand All @@ -147,6 +141,4 @@ message MsgBorrowAlternateResponse {}

message MsgFundModuleAccountsResponse {}

message MsgCalculateBorrowInterestResponse {}

message MsgCalculateLendRewardsResponse {}
message MsgCalculateInterestAndRewardsResponse {}
1 change: 1 addition & 0 deletions x/asset/keeper/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ func (s *KeeperTestSuite) TestWasmUpdatePairsVault() {
ClosingFee: sdk.MustNewDecFromStr("233.23"),
LiquidationPenalty: sdk.MustNewDecFromStr("0.56"),
DrawDownFee: sdk.MustNewDecFromStr("0.29"),
IsVaultActive: true,
DebtCeiling: 1000000000,
DebtFloor: 1000,
MinCr: sdk.MustNewDecFromStr("1.8"),
Expand Down
14 changes: 0 additions & 14 deletions x/auction/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,6 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper, assetKeeper expected.AssetKe
}
}

// lockedVaults := k.GetLockedVaults(ctx)

//if len(lockedVaults) > 0 {
// err3 := k.DutchActivator(ctx, lockedVaults)
// if err3 != nil {
// ctx.Logger().Error("error in dutch activator")
// }
//
// err5 := k.LendDutchActivator(ctx, lockedVaults)
// if err5 != nil {
// ctx.Logger().Error("error in lend dutch activator")
// }
//}

apps, appsFound := assetKeeper.GetApps(ctx)

if appsFound {
Expand Down
7 changes: 4 additions & 3 deletions x/auction/keeper/debt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,10 @@ func (s *KeeperTestSuite) TestDebtActivator() {
1,
false,
}
err := k.SetNetFeeCollectedData(*ctx, uint64(1), 2, sdk.NewIntFromUint64(4700000))
s.Require().NoError(err)
err1 := k.DebtActivator(*ctx, auctionMapData, klswData, false)
s.Require().NoError(err1)

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

Expand All @@ -228,7 +229,7 @@ func (s *KeeperTestSuite) TestDebtActivator() {
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)))
s.Require().True(netFees.NetFeesCollected.LTE(sdk.NewIntFromUint64(collectorLookUp.DebtThreshold - collectorLookUp.LotSize)))

// Test restart debt auction
s.advanceseconds(301)
Expand All @@ -248,7 +249,7 @@ func (s *KeeperTestSuite) TestDebtActivator() {
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().True(netFees.NetFeesCollected.LTE(sdk.NewIntFromUint64(collectorLookUp.DebtThreshold - collectorLookUp.LotSize)))
s.Require().Equal(ctx.BlockTime().Add(time.Second*time.Duration(300)), debtAuction1.EndTime)
}

Expand Down
2 changes: 1 addition & 1 deletion x/auction/keeper/dutch.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (k Keeper) PlaceDutchAuctionBid(ctx sdk.Context, appID, auctionMappingID, a
}

// Dust check for debt
if amountLeftInPUSDforDebt.LT(sdk.NewDecFromInt(dust)) {
if amountLeftInPUSDforDebt.LT(sdk.NewDecFromInt(dust)) && !amountLeftInPUSDforDebt.Equal(sdk.ZeroDec()) && !amountLeftInPUSD.Equal(sdk.ZeroDec()) {
dust := dust.Uint64()
return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "Minimum amount left to be recovered should not be less than %d ", dust)
}
Expand Down
Loading