From ac645cd951658d636de716080ccfbe2fc7ed8f28 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Tue, 18 Oct 2022 15:10:29 +0530 Subject: [PATCH 01/13] testcase fix --- x/asset/keeper/asset_test.go | 1 + x/auction/keeper/dutch_test.go | 80 +++++++------------ x/liquidation/keeper/liquidate_vaults_test.go | 58 ++++++-------- x/vault/keeper/keeper_test.go | 44 +++------- 4 files changed, 68 insertions(+), 115 deletions(-) diff --git a/x/asset/keeper/asset_test.go b/x/asset/keeper/asset_test.go index 1fc57f884..06477df0d 100644 --- a/x/asset/keeper/asset_test.go +++ b/x/asset/keeper/asset_test.go @@ -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"), diff --git a/x/auction/keeper/dutch_test.go b/x/auction/keeper/dutch_test.go index a811f3196..570982478 100644 --- a/x/auction/keeper/dutch_test.go +++ b/x/auction/keeper/dutch_test.go @@ -46,8 +46,8 @@ func (s *KeeperTestSuite) AddPairAndExtendedPairVault1() { AssetOutPrice: 1000000, MinUsdValueLeft: 1000000000000, }, + 1, 2, - 3, }, } { s.Run(tc.name, func() { @@ -65,30 +65,26 @@ func (s *KeeperTestSuite) AddPairAndExtendedPairVault1() { } } -func (s *KeeperTestSuite) SetInitialOraclePriceForID(asset1 uint64, asset2 uint64) { - ctx := &s.ctx - twa1 := markettypes.TimeWeightedAverage{ - AssetID: asset1, - IsPriceActive: true, - Twa: 2000000, - } - s.marketKeeper.SetTwa(*ctx, twa1) - twa2 := markettypes.TimeWeightedAverage{ - AssetID: asset1, +func (s *KeeperTestSuite) SetOraclePrice(assetID uint64, price uint64) { + market := markettypes.TimeWeightedAverage{ + AssetID: assetID, + ScriptID: 12, + Twa: price, + CurrentIndex: 0, IsPriceActive: true, - Twa: 1000000, + PriceValue: []uint64{price}, } - s.marketKeeper.SetTwa(*ctx, twa2) + s.app.MarketKeeper.SetTwa(s.ctx, market) + +} + +func (s *KeeperTestSuite) SetInitialOraclePriceForID(asset1 uint64, asset2 uint64) { + s.SetOraclePrice(asset1, 2000000) + s.SetOraclePrice(asset2, 1000000) } func (s *KeeperTestSuite) ChangeOraclePrice(asset uint64) { - ctx := &s.ctx - twa := markettypes.TimeWeightedAverage{ - AssetID: asset, - IsPriceActive: true, - Twa: 1000000, - } - s.marketKeeper.SetTwa(*ctx, twa) + s.SetOraclePrice(asset, 1000000) } func (s *KeeperTestSuite) CreateVault() { @@ -171,33 +167,19 @@ func (s *KeeperTestSuite) AddAppAsset() { GovTimeInSeconds: 900, GenesisToken: []assetTypes.MintGenesisToken{ { - 3, - genesisSupply, - true, - userAddress1, + AssetId: 3, + GenesisSupply :genesisSupply, + IsGovToken: true, + Recipient: userAddress1, }, { - 2, - genesisSupply, - true, - userAddress1, + AssetId: 2, + GenesisSupply :genesisSupply, + IsGovToken: true, + Recipient: userAddress1, }, }, } - // { - // Name: "commodo", - // ShortName: "commodo", - // MinGovDeposit: sdk.NewIntFromUint64(10000000), - // GovTimeInSeconds: 900, - // GenesisToken: []assetTypes.MintGenesisToken{ - // { - // 3, - // genesisSupply, - // true, - // userAddress1, - // }, - // }, - // }, err = assetKeeper.AddAppRecords(*ctx, msg1) s.Require().NoError(err) @@ -258,7 +240,7 @@ func (s *KeeperTestSuite) LiquidateVaults1() { s.Require().Equal(id, uint64(0)) // Liquidation should happen as price changed - s.ChangeOraclePrice(2) + s.ChangeOraclePrice(1) err = liquidationKeeper.LiquidateVaults(*ctx) s.Require().NoError(err) id = liquidationKeeper.GetLockedVaultID(*ctx) @@ -272,15 +254,15 @@ func (s *KeeperTestSuite) LiquidateVaults1() { s.Require().Equal(lockedVault[0].Owner, beforeVault.Owner) s.Require().Equal(lockedVault[0].AmountIn, beforeVault.AmountIn) s.Require().Equal(lockedVault[0].AmountOut, beforeVault.AmountOut) - s.Require().Equal(lockedVault[0].UpdatedAmountOut, beforeVault.AmountOut.Add(beforeVault.InterestAccumulated).Add(beforeVault.ClosingFeeAccumulated)) + s.Require().Equal(lockedVault[0].UpdatedAmountOut, sdk.ZeroInt()) s.Require().Equal(lockedVault[0].Initiator, liquidationTypes.ModuleName) s.Require().Equal(lockedVault[0].IsAuctionInProgress, false) s.Require().Equal(lockedVault[0].IsAuctionComplete, false) s.Require().Equal(lockedVault[0].SellOffHistory, []string(nil)) - price, found := s.app.MarketKeeper.GetTwa(*ctx, uint64(1)) - s.Require().True(found) - s.Require().Equal(lockedVault[0].CollateralToBeAuctioned, beforeVault.AmountIn.ToDec().Mul(sdk.NewIntFromUint64(price.Twa).ToDec())) - s.Require().Equal(lockedVault[0].CrAtLiquidation, lockedVault[0].AmountIn.ToDec().Mul(s.GetAssetPrice(1)).Quo(lockedVault[0].UpdatedAmountOut.ToDec().Mul(s.GetAssetPrice(2)))) + price, err := s.app.MarketKeeper.CalcAssetPrice(*ctx, uint64(1), beforeVault.AmountIn) + s.Require().NoError(err) + s.Require().Equal(lockedVault[0].CollateralToBeAuctioned, price) + s.Require().Equal(lockedVault[0].CrAtLiquidation, lockedVault[0].AmountIn.ToDec().Mul(s.GetAssetPrice(1)).Quo(lockedVault[0].AmountOut.ToDec().Mul(s.GetAssetPrice(2)))) } func (s *KeeperTestSuite) AddAuctionParams() { @@ -334,7 +316,7 @@ func (s *KeeperTestSuite) TestDutchActivator() { inFlowTokenTargetAmount := lockedVault.AmountOut mulfactor := inFlowTokenTargetAmount.ToDec().Mul(dutchAuction.LiquidationPenalty) - inFlowTokenTargetAmount = inFlowTokenTargetAmount.Add(mulfactor.TruncateInt()) + inFlowTokenTargetAmount = inFlowTokenTargetAmount.Add(mulfactor.TruncateInt()).Add(lockedVault.InterestAccumulated) s.Require().Equal(dutchAuction.InflowTokenTargetAmount.Amount, inFlowTokenTargetAmount) diff --git a/x/liquidation/keeper/liquidate_vaults_test.go b/x/liquidation/keeper/liquidate_vaults_test.go index 0325a09ee..f63d9098f 100644 --- a/x/liquidation/keeper/liquidate_vaults_test.go +++ b/x/liquidation/keeper/liquidate_vaults_test.go @@ -43,8 +43,8 @@ func (s *KeeperTestSuite) AddPairAndExtendedPairVault1() { AssetOutPrice: 1000000, MinUsdValueLeft: 1000000, }, + 1, 2, - 3, }, } { s.Run(tc.name, func() { @@ -62,30 +62,26 @@ func (s *KeeperTestSuite) AddPairAndExtendedPairVault1() { } } -func (s *KeeperTestSuite) SetInitialOraclePriceForID(asset1 uint64, asset2 uint64) { - ctx := &s.ctx - twa1 := markettypes.TimeWeightedAverage{ - AssetID: asset1, - IsPriceActive: true, - Twa: 2000000, - } - s.marketKeeper.SetTwa(*ctx, twa1) - twa2 := markettypes.TimeWeightedAverage{ - AssetID: asset1, +func (s *KeeperTestSuite) SetOraclePrice(assetID uint64, price uint64) { + market := markettypes.TimeWeightedAverage{ + AssetID: assetID, + ScriptID: 12, + Twa: price, + CurrentIndex: 0, IsPriceActive: true, - Twa: 1000000, + PriceValue: []uint64{price}, } - s.marketKeeper.SetTwa(*ctx, twa2) + s.app.MarketKeeper.SetTwa(s.ctx, market) + +} + +func (s *KeeperTestSuite) SetInitialOraclePriceForID(asset1 uint64, asset2 uint64) { + s.SetOraclePrice(asset1, 2000000) + s.SetOraclePrice(asset2, 1000000) } func (s *KeeperTestSuite) ChangeOraclePrice(asset uint64) { - ctx := &s.ctx - twa := markettypes.TimeWeightedAverage{ - AssetID: asset, - IsPriceActive: true, - Twa: 1000000, - } - s.marketKeeper.SetTwa(*ctx, twa) + s.SetOraclePrice(asset, 1000000) } func (s *KeeperTestSuite) CreateVault() { @@ -147,10 +143,9 @@ func (s *KeeperTestSuite) GetVaultCountForExtendedPairIDbyAppID(appID, extID uin } func (s *KeeperTestSuite) GetAssetPrice(id uint64) sdk.Dec { - marketKeeper, ctx := &s.marketKeeper, &s.ctx - price, found := marketKeeper.GetTwa(*ctx, id) - s.Require().True(found) - price1 := sdk.NewDecFromInt(sdk.NewIntFromUint64(price.Twa)) + price, err := s.app.MarketKeeper.GetLatestPrice(s.ctx, id) + s.Suite.NoError(err) + price1 := sdk.NewDecFromInt(sdk.NewIntFromUint64(price)) return price1 } @@ -243,7 +238,7 @@ func (s *KeeperTestSuite) TestLiquidateVaults1() { s.Require().Equal(id, uint64(0)) // Liquidation should happen as price changed - s.ChangeOraclePrice(2) + s.ChangeOraclePrice(1) err = liquidationKeeper.LiquidateVaults(*ctx) s.Require().NoError(err) id = liquidationKeeper.GetLockedVaultID(*ctx) @@ -257,15 +252,15 @@ func (s *KeeperTestSuite) TestLiquidateVaults1() { s.Require().Equal(lockedVault[0].Owner, beforeVault.Owner) s.Require().Equal(lockedVault[0].AmountIn, beforeVault.AmountIn) s.Require().Equal(lockedVault[0].AmountOut, beforeVault.AmountOut) - s.Require().Equal(lockedVault[0].UpdatedAmountOut, beforeVault.AmountOut.Add(beforeVault.InterestAccumulated).Add(beforeVault.ClosingFeeAccumulated)) + s.Require().Equal(lockedVault[0].UpdatedAmountOut, sdk.ZeroInt()) s.Require().Equal(lockedVault[0].Initiator, liquidationTypes.ModuleName) s.Require().Equal(lockedVault[0].IsAuctionInProgress, false) s.Require().Equal(lockedVault[0].IsAuctionComplete, false) s.Require().Equal(lockedVault[0].SellOffHistory, []string(nil)) - price, found := s.app.MarketKeeper.GetTwa(*ctx, uint64(1)) - s.Require().True(found) - s.Require().Equal(lockedVault[0].CollateralToBeAuctioned, beforeVault.AmountIn.ToDec().Mul(sdk.NewIntFromUint64(price.Twa).ToDec())) - s.Require().Equal(lockedVault[0].CrAtLiquidation, lockedVault[0].AmountIn.ToDec().Mul(s.GetAssetPrice(1)).Quo(lockedVault[0].UpdatedAmountOut.ToDec().Mul(s.GetAssetPrice(2)))) + price, err := s.app.MarketKeeper.CalcAssetPrice(*ctx, uint64(1), beforeVault.AmountIn) + s.Require().NoError(err) + s.Require().Equal(lockedVault[0].CollateralToBeAuctioned, price) + s.Require().Equal(lockedVault[0].CrAtLiquidation, lockedVault[0].AmountIn.ToDec().Mul(s.GetAssetPrice(1)).Quo(lockedVault[0].AmountOut.ToDec().Mul(s.GetAssetPrice(2)))) } func (s *KeeperTestSuite) TestUpdateLockedVaults() { @@ -273,8 +268,7 @@ func (s *KeeperTestSuite) TestUpdateLockedVaults() { liquidationKeeper, ctx := &s.liquidationKeeper, &s.ctx lockedVault1 := liquidationKeeper.GetLockedVaults(*ctx) - - s.Require().Equal(lockedVault1[0].CrAtLiquidation, lockedVault1[0].AmountIn.ToDec().Mul(s.GetAssetPrice(1)).Quo(lockedVault1[0].UpdatedAmountOut.ToDec().Mul(s.GetAssetPrice(2)))) + s.Require().Equal(lockedVault1[0].CrAtLiquidation, lockedVault1[0].AmountIn.ToDec().Mul(s.GetAssetPrice(1)).Quo(lockedVault1[0].AmountOut.ToDec().Mul(s.GetAssetPrice(2)))) } func (s *KeeperTestSuite) TestSetFlags() { diff --git a/x/vault/keeper/keeper_test.go b/x/vault/keeper/keeper_test.go index f820ea72d..75661b594 100644 --- a/x/vault/keeper/keeper_test.go +++ b/x/vault/keeper/keeper_test.go @@ -118,42 +118,18 @@ func (s *KeeperTestSuite) CreateNewAsset(name, denom string, price uint64) uint6 } s.Require().NotZero(assetID) - twa1 := markettypes.TimeWeightedAverage{ - AssetID: 1, - ScriptID: 10, - Twa: 12000000, - CurrentIndex: 1, + market := markettypes.TimeWeightedAverage{ + AssetID: assetID, + ScriptID: 12, + Twa: price, + CurrentIndex: 0, IsPriceActive: true, - PriceValue: nil, + PriceValue: []uint64{price}, } - twa2 := markettypes.TimeWeightedAverage{ - AssetID: 2, - ScriptID: 10, - Twa: 100000, - CurrentIndex: 1, - IsPriceActive: true, - PriceValue: nil, - } - twa3 := markettypes.TimeWeightedAverage{ - AssetID: 3, - ScriptID: 10, - Twa: 1000000, - CurrentIndex: 1, - IsPriceActive: true, - PriceValue: nil, - } - twa4 := markettypes.TimeWeightedAverage{ - AssetID: 4, - ScriptID: 10, - Twa: 2500000, - CurrentIndex: 1, - IsPriceActive: true, - PriceValue: nil, - } - s.app.MarketKeeper.SetTwa(s.ctx, twa1) - s.app.MarketKeeper.SetTwa(s.ctx, twa2) - s.app.MarketKeeper.SetTwa(s.ctx, twa3) - s.app.MarketKeeper.SetTwa(s.ctx, twa4) + s.app.MarketKeeper.SetTwa(s.ctx, market) + _, err = s.app.MarketKeeper.GetLatestPrice(s.ctx, assetID) + s.Suite.NoError(err) + return assetID } From 7bca7bf45488aae1d5142c3bf984cc61782cb920 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Thu, 20 Oct 2022 12:23:57 +0530 Subject: [PATCH 02/13] wasm query added --- app/app.go | 2 +- app/wasm/bindings/query.go | 31 ++++++++++++++++++++++++++++ app/wasm/queries.go | 24 ++++++++++++++++++++++ app/wasm/query_plugin.go | 37 ++++++++++++++++++++++++++++++++++ app/wasm/test/messages_test.go | 36 ++++++++++++++++++++++++--------- app/wasm/wasm.go | 6 +++++- x/lend/keeper/lend.go | 11 ++++++++++ x/liquidity/keeper/store.go | 9 +++++++++ x/vault/keeper/vault.go | 5 +++++ 9 files changed, 150 insertions(+), 11 deletions(-) diff --git a/app/app.go b/app/app.go index 46ef01b02..5a60b847b 100644 --- a/app/app.go +++ b/app/app.go @@ -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, diff --git a/app/wasm/bindings/query.go b/app/wasm/bindings/query.go index 0e7665aec..43a2a838a 100644 --- a/app/wasm/bindings/query.go +++ b/app/wasm/bindings/query.go @@ -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 { @@ -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"` +} diff --git a/app/wasm/queries.go b/app/wasm/queries.go index 0623a4b46..26165c5f5 100644 --- a/app/wasm/queries.go +++ b/app/wasm/queries.go @@ -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" @@ -22,6 +24,8 @@ type QueryPlugin struct { liquidationKeeper *liquidationKeeper.Keeper esmKeeper *esmKeeper.Keeper vaultKeeper *vaultKeeper.Keeper + lendKeeper *lendKeeper.Keeper + liquidityKeeper *liquidityKeeper.Keeper } func NewQueryPlugin( @@ -33,6 +37,9 @@ func NewQueryPlugin( liquidation *liquidationKeeper.Keeper, esmKeeper *esmKeeper.Keeper, vaultKeeper *vaultKeeper.Keeper, + lendKeeper *lendKeeper.Keeper, + liquidityKeeper *liquidityKeeper.Keeper, + ) *QueryPlugin { return &QueryPlugin{ assetKeeper: assetKeeper, @@ -43,6 +50,8 @@ func NewQueryPlugin( liquidationKeeper: liquidation, esmKeeper: esmKeeper, vaultKeeper: vaultKeeper, + lendKeeper: lendKeeper, + liquidityKeeper: liquidityKeeper, } } @@ -164,3 +173,18 @@ 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.WasmCheckVaultCreatedQuery(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) { + found = qp.liquidityKeeper.WasmCheckLiquidityProvided(ctx, appID, poolID, address) + return found +} \ No newline at end of file diff --git a/app/wasm/query_plugin.go b/app/wasm/query_plugin.go index 8ff5d2306..eb621a9c3 100644 --- a/app/wasm/query_plugin.go +++ b/app/wasm/query_plugin.go @@ -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"} } diff --git a/app/wasm/test/messages_test.go b/app/wasm/test/messages_test.go index cd1778601..f08968098 100644 --- a/app/wasm/test/messages_test.go +++ b/app/wasm/test/messages_test.go @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/app/wasm/wasm.go b/app/wasm/wasm.go index 29318d5b0..dbc5d9017 100644 --- a/app/wasm/wasm.go +++ b/app/wasm/wasm.go @@ -13,6 +13,8 @@ import ( rewardsKeeper "github.com/comdex-official/comdex/x/rewards/keeper" tokenMintkeeper "github.com/comdex-official/comdex/x/tokenmint/keeper" vaultKeeper "github.com/comdex-official/comdex/x/vault/keeper" + lendKeeper "github.com/comdex-official/comdex/x/lend/keeper" + liquidityKeeper "github.com/comdex-official/comdex/x/liquidity/keeper" ) func RegisterCustomPlugins( @@ -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), diff --git a/x/lend/keeper/lend.go b/x/lend/keeper/lend.go index 77ab12dcb..d9b5604c6 100644 --- a/x/lend/keeper/lend.go +++ b/x/lend/keeper/lend.go @@ -426,3 +426,14 @@ func (k Keeper) DeleteBorrowIDFromUserMapping(ctx sdk.Context, owner string, len k.SetUserLendBorrowMapping(ctx, userData) } } + +func (k Keeper) WasmHasBorrowForAddressAndAsset(ctx sdk.Context, assetID uint64, address string) bool { + mappingData := k.GetUserTotalMappingData(ctx, address) + for _, data := range mappingData { + lend, _ := k.GetLend(ctx, data.LendId) + if lend.AssetID == assetID && len(data.BorrowId) > 0 { + return true + } + } + return false +} diff --git a/x/liquidity/keeper/store.go b/x/liquidity/keeper/store.go index c81fe1372..70061759f 100644 --- a/x/liquidity/keeper/store.go +++ b/x/liquidity/keeper/store.go @@ -721,3 +721,12 @@ func (k Keeper) GetAllQueuedFarmers(ctx sdk.Context, appID, poolID uint64) (queu }) return queuedFarmers } + +func (k Keeper) WasmCheckLiquidityProvided(ctx sdk.Context, appID, poolID uint64, farmer string) (found bool) { + address, err := sdk.AccAddressFromBech32(farmer) + if err != nil { + return false + } + _, found = k.GetActiveFarmer(ctx, appID, poolID, address) + return found +} \ No newline at end of file diff --git a/x/vault/keeper/vault.go b/x/vault/keeper/vault.go index 8958a85b2..15d96b108 100644 --- a/x/vault/keeper/vault.go +++ b/x/vault/keeper/vault.go @@ -657,3 +657,8 @@ func (k Keeper) WasmMsgAddEmissionRewards(ctx sdk.Context, appID uint64, amount return nil } + +func (k Keeper) WasmCheckVaultCreatedQuery(ctx sdk.Context, address string, appID uint64) (found bool) { + _, found = k.GetUserAppMappingData(ctx, address, appID) + return found +} From 316ce763aa87f83e6afd217dc587faeb11714d9e Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Thu, 20 Oct 2022 12:46:03 +0530 Subject: [PATCH 03/13] wasm query modified --- app/wasm/queries.go | 10 +++++++--- x/liquidity/keeper/store.go | 9 --------- x/vault/keeper/vault.go | 5 ----- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/app/wasm/queries.go b/app/wasm/queries.go index 26165c5f5..811e180ac 100644 --- a/app/wasm/queries.go +++ b/app/wasm/queries.go @@ -175,7 +175,7 @@ func (qp QueryPlugin) WasmCheckWhitelistedAsset(ctx sdk.Context, denom string) ( } func (qp QueryPlugin) WasmCheckVaultCreated(ctx sdk.Context, address string, appID uint64) (found bool) { - found = qp.vaultKeeper.WasmCheckVaultCreatedQuery(ctx, address, appID) + _, found = qp.vaultKeeper.GetUserAppMappingData(ctx, address, appID) return found } @@ -185,6 +185,10 @@ func (qp QueryPlugin) WasmCheckBorrowed(ctx sdk.Context, assetID uint64, address } func (qp QueryPlugin) WasmCheckLiquidityProvided(ctx sdk.Context, appID, poolID uint64, address string) (found bool) { - found = qp.liquidityKeeper.WasmCheckLiquidityProvided(ctx, appID, poolID, address) + farmer, err := sdk.AccAddressFromBech32(address) + if err != nil { + return false + } + _, found = qp.liquidityKeeper.GetActiveFarmer(ctx, appID, poolID, farmer) return found -} \ No newline at end of file +} diff --git a/x/liquidity/keeper/store.go b/x/liquidity/keeper/store.go index 70061759f..c81fe1372 100644 --- a/x/liquidity/keeper/store.go +++ b/x/liquidity/keeper/store.go @@ -721,12 +721,3 @@ func (k Keeper) GetAllQueuedFarmers(ctx sdk.Context, appID, poolID uint64) (queu }) return queuedFarmers } - -func (k Keeper) WasmCheckLiquidityProvided(ctx sdk.Context, appID, poolID uint64, farmer string) (found bool) { - address, err := sdk.AccAddressFromBech32(farmer) - if err != nil { - return false - } - _, found = k.GetActiveFarmer(ctx, appID, poolID, address) - return found -} \ No newline at end of file diff --git a/x/vault/keeper/vault.go b/x/vault/keeper/vault.go index 15d96b108..8958a85b2 100644 --- a/x/vault/keeper/vault.go +++ b/x/vault/keeper/vault.go @@ -657,8 +657,3 @@ func (k Keeper) WasmMsgAddEmissionRewards(ctx sdk.Context, appID uint64, amount return nil } - -func (k Keeper) WasmCheckVaultCreatedQuery(ctx sdk.Context, address string, appID uint64) (found bool) { - _, found = k.GetUserAppMappingData(ctx, address, appID) - return found -} From 5a59971835080ca52d0b0ca75dde24bd286bf8e1 Mon Sep 17 00:00:00 2001 From: Pratik Date: Thu, 20 Oct 2022 16:02:21 +0530 Subject: [PATCH 04/13] Adding MsgCalculateInterestAndRewards txn --- proto/comdex/lend/v1beta1/tx.proto | 14 +- x/lend/client/cli/tx.go | 42 +- x/lend/handler.go | 8 +- x/lend/keeper/iter.go | 2 +- x/lend/keeper/keeper.go | 43 +- x/lend/keeper/keeper_test.go | 2 +- x/lend/keeper/msg_server.go | 24 +- x/lend/keeper/msg_server_test.go | 610 +++++++++++++------------- x/lend/types/codec.go | 6 +- x/lend/types/params.go | 23 +- x/lend/types/tx.go | 54 +-- x/lend/types/tx.pb.go | 657 ++++++----------------------- 12 files changed, 513 insertions(+), 972 deletions(-) diff --git a/proto/comdex/lend/v1beta1/tx.proto b/proto/comdex/lend/v1beta1/tx.proto index e34f8618e..165a8c0ce 100644 --- a/proto/comdex/lend/v1beta1/tx.proto +++ b/proto/comdex/lend/v1beta1/tx.proto @@ -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 { @@ -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 {} @@ -147,6 +141,4 @@ message MsgBorrowAlternateResponse {} message MsgFundModuleAccountsResponse {} -message MsgCalculateBorrowInterestResponse {} - -message MsgCalculateLendRewardsResponse {} \ No newline at end of file +message MsgCalculateInterestAndRewardsResponse {} diff --git a/x/lend/client/cli/tx.go b/x/lend/client/cli/tx.go index 4885cebf0..a248c5969 100644 --- a/x/lend/client/cli/tx.go +++ b/x/lend/client/cli/tx.go @@ -39,8 +39,7 @@ func GetTxCmd() *cobra.Command { txCloseBorrowAsset(), txBorrowAssetAlternate(), txFundModuleAccounts(), - txCalculateBorrowInterest(), - txCalculateLendRewards(), + txCalculateInterestAndRewards(), ) return cmd @@ -990,49 +989,18 @@ func NewAddAuctionParams(clientCtx client.Context, txf tx.Factory, fs *flag.Flag return txf, msg, nil } -func txCalculateBorrowInterest() *cobra.Command { +func txCalculateInterestAndRewards() *cobra.Command { cmd := &cobra.Command{ - Use: "calculate-borrow-interest [borrow-id] ", + Use: "calculate-borrow-interest", Short: " calculate borrow interest for a borrow position", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - ctx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - borrowID, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return err - } - - msg := types.NewMsgCalculateBorrowInterest(ctx.GetFromAddress().String(), borrowID) - - return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - return cmd -} - -func txCalculateLendRewards() *cobra.Command { - cmd := &cobra.Command{ - Use: "calculate-lend-rewards [lend-id] ", - Short: " calculate lend rewards for a lend position", - Args: cobra.ExactArgs(1), + Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { ctx, err := client.GetClientTxContext(cmd) if err != nil { return err } - borrowID, err := strconv.ParseUint(args[0], 10, 64) - if err != nil { - return err - } - - msg := types.NewMsgCalculateLendRewards(ctx.GetFromAddress().String(), borrowID) + msg := types.NewMsgCalculateInterestAndRewards(ctx.GetFromAddress().String()) return tx.GenerateOrBroadcastTxCLI(ctx, cmd.Flags(), msg) }, diff --git a/x/lend/handler.go b/x/lend/handler.go index b3a028b54..fe9f0a4b8 100644 --- a/x/lend/handler.go +++ b/x/lend/handler.go @@ -65,12 +65,8 @@ func NewHandler(k keeper.Keeper) sdk.Handler { res, err := server.FundModuleAccounts(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) - case *types.MsgCalculateBorrowInterest: - res, err := server.CalculateBorrowInterest(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) - - case *types.MsgCalculateLendRewards: - res, err := server.CalculateLendRewards(sdk.WrapSDKContext(ctx), msg) + case *types.MsgCalculateInterestAndRewards: + res, err := server.CalculateInterestAndRewards(sdk.WrapSDKContext(ctx), msg) return sdk.WrapServiceResult(ctx, res, err) default: diff --git a/x/lend/keeper/iter.go b/x/lend/keeper/iter.go index b458cef4f..4a7a4130c 100644 --- a/x/lend/keeper/iter.go +++ b/x/lend/keeper/iter.go @@ -67,7 +67,7 @@ func (k Keeper) IterateLends(ctx sdk.Context, ID uint64) (sdk.Dec, error) { } // subtracting newInterestPerInteraction from global lend and interest accumulated poolAssetLBMappingData.TotalInterestAccumulated = poolAssetLBMappingData.TotalInterestAccumulated.Sub(newInterestPerInteraction) - poolAssetLBMappingData.TotalLend = poolAssetLBMappingData.TotalLend.Sub(newInterestPerInteraction) + //poolAssetLBMappingData.TotalLend = poolAssetLBMappingData.TotalLend.Sub(newInterestPerInteraction) k.SetAssetStatsByPoolIDAndAssetID(ctx, poolAssetLBMappingData) k.SetLend(ctx, lend) } diff --git a/x/lend/keeper/keeper.go b/x/lend/keeper/keeper.go index 8e99fd03a..994e8b491 100644 --- a/x/lend/keeper/keeper.go +++ b/x/lend/keeper/keeper.go @@ -160,7 +160,11 @@ func (k Keeper) LendAsset(ctx sdk.Context, lenderAddr string, AssetID uint64, Am if !found { return sdkerrors.Wrap(types.ErrorAssetRatesParamsNotFound, strconv.FormatUint(AssetID, 10)) } - cAsset, _ := k.GetAsset(ctx, assetRatesStat.CAssetID) + cAsset, found := k.GetAsset(ctx, assetRatesStat.CAssetID) + if !found { + return assettypes.ErrorAssetDoesNotExist + } + cToken := sdk.NewCoin(cAsset.Denom, Amount.Amount) if err = k.bank.SendCoinsFromAccountToModule(ctx, addr, pool.ModuleName, loanTokens); err != nil { @@ -236,7 +240,8 @@ func (k Keeper) WithdrawAsset(ctx sdk.Context, addr string, lendID uint64, withd return types.ErrLendNotFound } - if withdrawal.Amount.Equal(lendPos.AvailableToBorrow) { + // if user wants to withdraw all amount then his position will be closed + if withdrawal.Amount.Equal(lendPos.AvailableToBorrow) && lendPos.AvailableToBorrow.GTE(lendPos.AmountIn.Amount) { err = k.CloseLend(ctx, addr, lendID) if err != nil { return err @@ -1583,3 +1588,37 @@ func (k Keeper) MsgCalculateLendRewards(ctx sdk.Context, addr string, lendID uin k.SetLend(ctx, lendPos) return nil } + +func (k Keeper) MsgCalculateInterestAndRewards(ctx sdk.Context, addr string) error { + var ( + lendIDs []uint64 + borrowIDs []uint64 + ) + mappingData := k.GetUserTotalMappingData(ctx, addr) + + for _, data := range mappingData { + lendIDs = append(lendIDs, data.LendId) + } + if len(lendIDs) == 0 { + return types.ErrLendNotFound + } + for _, v := range lendIDs { + lendBorrowMappingData, _ := k.GetUserLendBorrowMapping(ctx, addr, v) + borrowIDs = append(borrowIDs, lendBorrowMappingData.BorrowId...) + } + if len(borrowIDs) != 0 { + for _, borrowID := range borrowIDs { + err := k.MsgCalculateBorrowInterest(ctx, addr, borrowID) + if err != nil { + continue + } + } + } + for _, lendID := range lendIDs { + err := k.MsgCalculateLendRewards(ctx, addr, lendID) + if err != nil { + return err + } + } + return nil +} diff --git a/x/lend/keeper/keeper_test.go b/x/lend/keeper/keeper_test.go index ca0bfa0d9..0f5d1c8e0 100644 --- a/x/lend/keeper/keeper_test.go +++ b/x/lend/keeper/keeper_test.go @@ -154,7 +154,7 @@ func (s *KeeperTestSuite) CreateNewAsset(name, denom string, price uint64) uint6 s.app.MarketKeeper.SetTwa(s.ctx, twa3) s.app.MarketKeeper.SetTwa(s.ctx, twa4) // s.Suite.Require().False(exists) - s.app.MarketKeeper.SetMarketForAsset(s.ctx, assetID, name) + //s.app.MarketKeeper.SetMarketForAsset(s.ctx, assetID, name) return assetID } diff --git a/x/lend/keeper/msg_server.go b/x/lend/keeper/msg_server.go index 111a3e259..b90834664 100644 --- a/x/lend/keeper/msg_server.go +++ b/x/lend/keeper/msg_server.go @@ -164,30 +164,14 @@ func (m msgServer) FundModuleAccounts(goCtx context.Context, accounts *types.Msg return &types.MsgFundModuleAccountsResponse{}, nil } -func (m msgServer) CalculateBorrowInterest(goCtx context.Context, interest *types.MsgCalculateBorrowInterest) (*types.MsgCalculateBorrowInterestResponse, error) { +func (m msgServer) CalculateInterestAndRewards(goCtx context.Context, rewards *types.MsgCalculateInterestAndRewards) (*types.MsgCalculateInterestAndRewardsResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - borrowID := interest.BorrowId - - if err := m.keeper.MsgCalculateBorrowInterest(ctx, interest.Borrower, borrowID); err != nil { - return nil, err - } - - ctx.GasMeter().ConsumeGas(types.CalculateBorrowInterestGas, "CalculateBorrowInterestGas") - - return &types.MsgCalculateBorrowInterestResponse{}, nil -} - -func (m msgServer) CalculateLendRewards(goCtx context.Context, rewards *types.MsgCalculateLendRewards) (*types.MsgCalculateLendRewardsResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - borrowID := rewards.LendId - - if err := m.keeper.MsgCalculateLendRewards(ctx, rewards.Lender, borrowID); err != nil { + if err := m.keeper.MsgCalculateInterestAndRewards(ctx, rewards.Borrower); err != nil { return nil, err } - ctx.GasMeter().ConsumeGas(types.CalculateLendRewardGas, "CalculateLendRewardGas") + ctx.GasMeter().ConsumeGas(types.CalculateInterestAndRewardGas, "CalculateInterestAndRewardGas") - return &types.MsgCalculateLendRewardsResponse{}, nil + return &types.MsgCalculateInterestAndRewardsResponse{}, nil } diff --git a/x/lend/keeper/msg_server_test.go b/x/lend/keeper/msg_server_test.go index 3aeb4b7a6..019c419ce 100644 --- a/x/lend/keeper/msg_server_test.go +++ b/x/lend/keeper/msg_server_test.go @@ -1928,308 +1928,308 @@ func (s *KeeperTestSuite) TestMsgBorrowAlternate() { } } -func (s *KeeperTestSuite) TestMsgCalculateBorrowInterest() { - assetOneID := s.CreateNewAsset("ASSETONE", "uasset1", 1000000) - assetTwoID := s.CreateNewAsset("ASSETTWO", "uasset2", 2000000) - assetThreeID := s.CreateNewAsset("ASSETTHREE", "uasset3", 2000000) - assetFourID := s.CreateNewAsset("ASSETFOUR", "uasset4", 2000000) - cAssetOneID := s.CreateNewAsset("CASSETONE", "ucasset1", 1000000) - cAssetTwoID := s.CreateNewAsset("CASSETTWO", "ucasset2", 2000000) - cAssetThreeID := s.CreateNewAsset("CASSETTHRE", "ucasset3", 2000000) - // cAssetFourID := s.CreateNewAsset("CASSETFOUR", "ucasset4", 2000000) - - var ( - assetDataPoolOne []*types.AssetDataPoolMapping - assetDataPoolTwo []*types.AssetDataPoolMapping - ) - assetDataPoolOneAssetOne := &types.AssetDataPoolMapping{ - AssetID: assetOneID, - AssetTransitType: 3, - SupplyCap: uint64(5000000000000000000), - } - assetDataPoolOneAssetTwo := &types.AssetDataPoolMapping{ - AssetID: assetTwoID, - AssetTransitType: 1, - SupplyCap: uint64(1000000000000000000), - } - assetDataPoolOneAssetThree := &types.AssetDataPoolMapping{ - AssetID: assetThreeID, - AssetTransitType: 2, - SupplyCap: uint64(5000000000000000000), - } - assetDataPoolTwoAssetFour := &types.AssetDataPoolMapping{ - AssetID: assetFourID, - AssetTransitType: 1, - SupplyCap: uint64(3000000000000000000), - } - - assetDataPoolOne = append(assetDataPoolOne, assetDataPoolOneAssetOne, assetDataPoolOneAssetTwo, assetDataPoolOneAssetThree) - assetDataPoolTwo = append(assetDataPoolOne, assetDataPoolTwoAssetFour, assetDataPoolOneAssetTwo, assetDataPoolOneAssetThree) - - poolOneID := s.CreateNewPool("cmdx", "CMDX-ATOM-CMST", assetDataPoolOne) - poolTwoID := s.CreateNewPool("osmo", "OSMO-ATOM-CMST", assetDataPoolTwo) - - s.AddAssetRatesStats(assetThreeID, newDec("0.8"), newDec("0.002"), newDec("0.06"), newDec("0.6"), true, newDec("0.04"), newDec("0.04"), newDec("0.06"), newDec("0.8"), newDec("0.85"), newDec("0.025"), newDec("0.025"), newDec("0.1"), cAssetThreeID) - s.AddAssetRatesStats(assetOneID, newDec("0.75"), newDec("0.002"), newDec("0.07"), newDec("1.25"), false, newDec("0.0"), newDec("0.0"), newDec("0.0"), newDec("0.7"), newDec("0.75"), newDec("0.05"), newDec("0.05"), newDec("0.2"), cAssetOneID) - // s.AddAssetRatesStats(assetFourID, newDec("0.65"), newDec("0.002"), newDec("0.08"), newDec("1.5"), false, newDec("0.0"), newDec("0.0"), newDec("0.0"), newDec("0.6"), newDec("0.65"), newDec("0.05"), newDec("0.05"), newDec("0.2"), cAssetFourID) - s.AddAssetRatesStats(assetTwoID, newDec("0.5"), newDec("0.002"), newDec("0.08"), newDec("2.0"), false, newDec("0.0"), newDec("0.0"), newDec("0.0"), newDec("0.5"), newDec("0.55"), newDec("0.05"), newDec("0.05"), newDec("0.2"), cAssetTwoID) - - pairOneID := s.AddExtendedLendPair(assetTwoID, assetThreeID, false, poolOneID, 1000000) - pairTwoID := s.AddExtendedLendPair(assetTwoID, assetOneID, false, poolOneID, 1000000) - pairThreeID := s.AddExtendedLendPair(assetOneID, assetTwoID, false, poolOneID, 1000000) - pairFourID := s.AddExtendedLendPair(assetOneID, assetThreeID, false, poolOneID, 1000000) - pairFiveID := s.AddExtendedLendPair(assetThreeID, assetTwoID, false, poolOneID, 1000000) - pairSixID := s.AddExtendedLendPair(assetThreeID, assetOneID, false, poolOneID, 1000000) - pairSevenID := s.AddExtendedLendPair(assetFourID, assetThreeID, false, poolTwoID, 1000000) - pairEightID := s.AddExtendedLendPair(assetFourID, assetOneID, false, poolTwoID, 1000000) - pairNineID := s.AddExtendedLendPair(assetOneID, assetFourID, false, poolTwoID, 1000000) - pairTenID := s.AddExtendedLendPair(assetOneID, assetThreeID, false, poolTwoID, 1000000) - pairElevenID := s.AddExtendedLendPair(assetThreeID, assetFourID, false, poolTwoID, 1000000) - pairTwelveID := s.AddExtendedLendPair(assetThreeID, assetOneID, false, poolTwoID, 1000000) - pairThirteenID := s.AddExtendedLendPair(assetTwoID, assetFourID, true, poolTwoID, 1000000) - pairFourteenID := s.AddExtendedLendPair(assetThreeID, assetFourID, true, poolTwoID, 1000000) - pairFifteenID := s.AddExtendedLendPair(assetOneID, assetFourID, true, poolTwoID, 1000000) - pairSixteenID := s.AddExtendedLendPair(assetFourID, assetTwoID, true, poolOneID, 1000000) - pairSeventeenID := s.AddExtendedLendPair(assetThreeID, assetTwoID, true, poolOneID, 1000000) - pairEighteenID := s.AddExtendedLendPair(assetOneID, assetTwoID, true, poolOneID, 1000000) - - s.AddAssetToPair(assetOneID, poolOneID, []uint64{pairThreeID, pairFourID, pairFifteenID}) - s.AddAssetToPair(assetTwoID, poolOneID, []uint64{pairOneID, pairTwoID, pairThirteenID}) - s.AddAssetToPair(assetThreeID, poolOneID, []uint64{pairFiveID, pairSixID, pairFourteenID}) - s.AddAssetToPair(assetFourID, poolTwoID, []uint64{pairSevenID, pairEightID, pairSixteenID}) - s.AddAssetToPair(assetOneID, poolTwoID, []uint64{pairNineID, pairTenID, pairEighteenID}) - s.AddAssetToPair(assetThreeID, poolTwoID, []uint64{pairElevenID, pairTwelveID, pairSeventeenID}) - - appOneID := s.CreateNewApp("commodo", "cmmdo") - // appTwoID := s.CreateNewApp("cswap", "cswap") - msg := types.NewMsgLend("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", assetOneID, sdk.NewCoin("uasset1", newInt(300)), poolOneID, appOneID) - msgLend2 := types.NewMsgLend("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", assetTwoID, sdk.NewCoin("uasset2", newInt(10000000000)), poolOneID, appOneID) - - msg3 := types.NewMsgFundModuleAccounts("cmdx", assetOneID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset1", newInt(10000000000))) - msg4 := types.NewMsgFundModuleAccounts("cmdx", assetTwoID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset2", newInt(10000000000))) - msg5 := types.NewMsgFundModuleAccounts("cmdx", assetThreeID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset3", newInt(120000000))) - // msg6 := types.NewMsgFundModuleAccounts("osmo", assetThreeID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset3", newInt(10000000000))) - msg7 := types.NewMsgFundModuleAccounts("osmo", assetOneID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset1", newInt(10000000000))) - msg8 := types.NewMsgFundModuleAccounts("osmo", assetFourID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset4", newInt(10000000000))) - - s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset1", newInt(100000000000)))) - s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset2", newInt(100000000000)))) - s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset3", newInt(100000000000)))) - s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset4", newInt(100000000000)))) - _, _ = s.msgServer.Lend(sdk.WrapSDKContext(s.ctx), msg) - _, _ = s.msgServer.Lend(sdk.WrapSDKContext(s.ctx), msgLend2) - _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg3) - _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg4) - _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg5) - //_, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg6) - _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg7) - _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg8) - - msg2 := types.NewMsgBorrow("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", 1, 3, false, sdk.NewCoin("ucasset1", newInt(100)), sdk.NewCoin("uasset2", newInt(10))) - _, _ = s.msgServer.Borrow(sdk.WrapSDKContext(s.ctx), msg2) - - testCases := []struct { - Name string - Msg types.MsgCalculateBorrowInterest - ExpErr error - ExpResp *types.MsgCalculateBorrowInterestResponse - QueryResponseIndex uint64 - QueryResponse *types.MsgCalculateBorrowInterest - AvailableBalance sdk.Coins - }{ - { - Name: "Borrow Position not found", - Msg: *types.NewMsgCalculateBorrowInterest("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", 10), - ExpErr: types.ErrBorrowNotFound, - ExpResp: nil, - QueryResponseIndex: 0, - QueryResponse: nil, - AvailableBalance: sdk.NewCoins(sdk.NewCoin("uasset1", newInt(0))), - }, - { - Name: "success Valid case", - Msg: *types.NewMsgCalculateBorrowInterest("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", 1), - ExpErr: nil, - ExpResp: &types.MsgCalculateBorrowInterestResponse{}, - QueryResponseIndex: 0, - QueryResponse: &types.MsgCalculateBorrowInterest{ - Borrower: "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", - BorrowId: 1, - }, - // AvailableBalance: sdk.NewCoins(sdk.NewCoin("uasset1", newInt(0))), - }, - } - for _, tc := range testCases { - tc := tc - s.Run(tc.Name, func() { - ctx := sdk.WrapSDKContext(s.ctx) - resp, err := s.msgServer.CalculateBorrowInterest(ctx, &tc.Msg) - if tc.ExpErr != nil { - s.Require().Error(err) - s.Require().EqualError(err, tc.ExpErr.Error()) - s.Require().Equal(tc.ExpResp, resp) - } else { - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tc.ExpResp, resp) - - // availableBalances := s.getBalances(sdk.MustAccAddressFromBech32(tc.Msg.Lender)) - // fmt.Println("availableBalances", availableBalances) - // s.Require().True(tc.AvailableBalance.IsEqual(availableBalances)) - } - }) - } -} - -func (s *KeeperTestSuite) TestMsgCalculateLendRewards() { - assetOneID := s.CreateNewAsset("ASSETONE", "uasset1", 1000000) - assetTwoID := s.CreateNewAsset("ASSETTWO", "uasset2", 2000000) - assetThreeID := s.CreateNewAsset("ASSETTHREE", "uasset3", 2000000) - assetFourID := s.CreateNewAsset("ASSETFOUR", "uasset4", 2000000) - cAssetOneID := s.CreateNewAsset("CASSETONE", "ucasset1", 1000000) - cAssetTwoID := s.CreateNewAsset("CASSETTWO", "ucasset2", 2000000) - cAssetThreeID := s.CreateNewAsset("CASSETTHRE", "ucasset3", 2000000) - // cAssetFourID := s.CreateNewAsset("CASSETFOUR", "ucasset4", 2000000) - - var ( - assetDataPoolOne []*types.AssetDataPoolMapping - assetDataPoolTwo []*types.AssetDataPoolMapping - ) - assetDataPoolOneAssetOne := &types.AssetDataPoolMapping{ - AssetID: assetOneID, - AssetTransitType: 3, - SupplyCap: uint64(5000000000000000000), - } - assetDataPoolOneAssetTwo := &types.AssetDataPoolMapping{ - AssetID: assetTwoID, - AssetTransitType: 1, - SupplyCap: uint64(1000000000000000000), - } - assetDataPoolOneAssetThree := &types.AssetDataPoolMapping{ - AssetID: assetThreeID, - AssetTransitType: 2, - SupplyCap: uint64(5000000000000000000), - } - assetDataPoolTwoAssetFour := &types.AssetDataPoolMapping{ - AssetID: assetFourID, - AssetTransitType: 1, - SupplyCap: uint64(3000000000000000000), - } - - assetDataPoolOne = append(assetDataPoolOne, assetDataPoolOneAssetOne, assetDataPoolOneAssetTwo, assetDataPoolOneAssetThree) - assetDataPoolTwo = append(assetDataPoolOne, assetDataPoolTwoAssetFour, assetDataPoolOneAssetTwo, assetDataPoolOneAssetThree) - - poolOneID := s.CreateNewPool("cmdx", "CMDX-ATOM-CMST", assetDataPoolOne) - poolTwoID := s.CreateNewPool("osmo", "OSMO-ATOM-CMST", assetDataPoolTwo) - - s.AddAssetRatesStats(assetThreeID, newDec("0.8"), newDec("0.002"), newDec("0.06"), newDec("0.6"), true, newDec("0.04"), newDec("0.04"), newDec("0.06"), newDec("0.8"), newDec("0.85"), newDec("0.025"), newDec("0.025"), newDec("0.1"), cAssetThreeID) - s.AddAssetRatesStats(assetOneID, newDec("0.75"), newDec("0.002"), newDec("0.07"), newDec("1.25"), false, newDec("0.0"), newDec("0.0"), newDec("0.0"), newDec("0.7"), newDec("0.75"), newDec("0.05"), newDec("0.05"), newDec("0.2"), cAssetOneID) - // s.AddAssetRatesStats(assetFourID, newDec("0.65"), newDec("0.002"), newDec("0.08"), newDec("1.5"), false, newDec("0.0"), newDec("0.0"), newDec("0.0"), newDec("0.6"), newDec("0.65"), newDec("0.05"), newDec("0.05"), newDec("0.2"), cAssetFourID) - s.AddAssetRatesStats(assetTwoID, newDec("0.5"), newDec("0.002"), newDec("0.08"), newDec("2.0"), false, newDec("0.0"), newDec("0.0"), newDec("0.0"), newDec("0.5"), newDec("0.55"), newDec("0.05"), newDec("0.05"), newDec("0.2"), cAssetTwoID) - - pairOneID := s.AddExtendedLendPair(assetTwoID, assetThreeID, false, poolOneID, 1000000) - pairTwoID := s.AddExtendedLendPair(assetTwoID, assetOneID, false, poolOneID, 1000000) - pairThreeID := s.AddExtendedLendPair(assetOneID, assetTwoID, false, poolOneID, 1000000) - pairFourID := s.AddExtendedLendPair(assetOneID, assetThreeID, false, poolOneID, 1000000) - pairFiveID := s.AddExtendedLendPair(assetThreeID, assetTwoID, false, poolOneID, 1000000) - pairSixID := s.AddExtendedLendPair(assetThreeID, assetOneID, false, poolOneID, 1000000) - pairSevenID := s.AddExtendedLendPair(assetFourID, assetThreeID, false, poolTwoID, 1000000) - pairEightID := s.AddExtendedLendPair(assetFourID, assetOneID, false, poolTwoID, 1000000) - pairNineID := s.AddExtendedLendPair(assetOneID, assetFourID, false, poolTwoID, 1000000) - pairTenID := s.AddExtendedLendPair(assetOneID, assetThreeID, false, poolTwoID, 1000000) - pairElevenID := s.AddExtendedLendPair(assetThreeID, assetFourID, false, poolTwoID, 1000000) - pairTwelveID := s.AddExtendedLendPair(assetThreeID, assetOneID, false, poolTwoID, 1000000) - pairThirteenID := s.AddExtendedLendPair(assetTwoID, assetFourID, true, poolTwoID, 1000000) - pairFourteenID := s.AddExtendedLendPair(assetThreeID, assetFourID, true, poolTwoID, 1000000) - pairFifteenID := s.AddExtendedLendPair(assetOneID, assetFourID, true, poolTwoID, 1000000) - pairSixteenID := s.AddExtendedLendPair(assetFourID, assetTwoID, true, poolOneID, 1000000) - pairSeventeenID := s.AddExtendedLendPair(assetThreeID, assetTwoID, true, poolOneID, 1000000) - pairEighteenID := s.AddExtendedLendPair(assetOneID, assetTwoID, true, poolOneID, 1000000) - - s.AddAssetToPair(assetOneID, poolOneID, []uint64{pairThreeID, pairFourID, pairFifteenID}) - s.AddAssetToPair(assetTwoID, poolOneID, []uint64{pairOneID, pairTwoID, pairThirteenID}) - s.AddAssetToPair(assetThreeID, poolOneID, []uint64{pairFiveID, pairSixID, pairFourteenID}) - s.AddAssetToPair(assetFourID, poolTwoID, []uint64{pairSevenID, pairEightID, pairSixteenID}) - s.AddAssetToPair(assetOneID, poolTwoID, []uint64{pairNineID, pairTenID, pairEighteenID}) - s.AddAssetToPair(assetThreeID, poolTwoID, []uint64{pairElevenID, pairTwelveID, pairSeventeenID}) - - appOneID := s.CreateNewApp("commodo", "cmmdo") - // appTwoID := s.CreateNewApp("cswap", "cswap") - msg := types.NewMsgLend("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", assetOneID, sdk.NewCoin("uasset1", newInt(300)), poolOneID, appOneID) - msgLend2 := types.NewMsgLend("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", assetTwoID, sdk.NewCoin("uasset2", newInt(10000000000)), poolOneID, appOneID) - - msg3 := types.NewMsgFundModuleAccounts("cmdx", assetOneID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset1", newInt(10000000000))) - msg4 := types.NewMsgFundModuleAccounts("cmdx", assetTwoID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset2", newInt(10000000000))) - msg5 := types.NewMsgFundModuleAccounts("cmdx", assetThreeID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset3", newInt(120000000))) - // msg6 := types.NewMsgFundModuleAccounts("osmo", assetThreeID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset3", newInt(10000000000))) - msg7 := types.NewMsgFundModuleAccounts("osmo", assetOneID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset1", newInt(10000000000))) - msg8 := types.NewMsgFundModuleAccounts("osmo", assetFourID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset4", newInt(10000000000))) - - s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset1", newInt(100000000000)))) - s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset2", newInt(100000000000)))) - s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset3", newInt(100000000000)))) - s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset4", newInt(100000000000)))) - _, _ = s.msgServer.Lend(sdk.WrapSDKContext(s.ctx), msg) - _, _ = s.msgServer.Lend(sdk.WrapSDKContext(s.ctx), msgLend2) - _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg3) - _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg4) - _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg5) - //_, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg6) - _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg7) - _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg8) - - msg2 := types.NewMsgBorrow("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", 1, 3, false, sdk.NewCoin("ucasset1", newInt(100)), sdk.NewCoin("uasset2", newInt(10))) - _, _ = s.msgServer.Borrow(sdk.WrapSDKContext(s.ctx), msg2) - - testCases := []struct { - Name string - Msg types.MsgCalculateLendRewards - ExpErr error - ExpResp *types.MsgCalculateLendRewardsResponse - QueryResponseIndex uint64 - QueryResponse *types.MsgCalculateLendRewards - AvailableBalance sdk.Coins - }{ - { - Name: "Lend Position not found", - Msg: *types.NewMsgCalculateLendRewards("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", 10), - ExpErr: types.ErrLendNotFound, - ExpResp: nil, - QueryResponseIndex: 0, - QueryResponse: nil, - AvailableBalance: sdk.NewCoins(sdk.NewCoin("uasset1", newInt(0))), - }, - { - Name: "success Valid case", - Msg: *types.NewMsgCalculateLendRewards("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", 1), - ExpErr: nil, - ExpResp: &types.MsgCalculateLendRewardsResponse{}, - QueryResponseIndex: 0, - QueryResponse: &types.MsgCalculateLendRewards{ - Lender: "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", - LendId: 1, - }, - // AvailableBalance: sdk.NewCoins(sdk.NewCoin("uasset1", newInt(0))), - }, - } - for _, tc := range testCases { - tc := tc - s.Run(tc.Name, func() { - ctx := sdk.WrapSDKContext(s.ctx) - resp, err := s.msgServer.CalculateLendRewards(ctx, &tc.Msg) - if tc.ExpErr != nil { - s.Require().Error(err) - s.Require().EqualError(err, tc.ExpErr.Error()) - s.Require().Equal(tc.ExpResp, resp) - } else { - s.Require().NoError(err) - s.Require().NotNil(resp) - s.Require().Equal(tc.ExpResp, resp) - - // availableBalances := s.getBalances(sdk.MustAccAddressFromBech32(tc.Msg.Lender)) - // fmt.Println("availableBalances", availableBalances) - // s.Require().True(tc.AvailableBalance.IsEqual(availableBalances)) - } - }) - } -} +//func (s *KeeperTestSuite) TestMsgCalculateBorrowInterest() { +// assetOneID := s.CreateNewAsset("ASSETONE", "uasset1", 1000000) +// assetTwoID := s.CreateNewAsset("ASSETTWO", "uasset2", 2000000) +// assetThreeID := s.CreateNewAsset("ASSETTHREE", "uasset3", 2000000) +// assetFourID := s.CreateNewAsset("ASSETFOUR", "uasset4", 2000000) +// cAssetOneID := s.CreateNewAsset("CASSETONE", "ucasset1", 1000000) +// cAssetTwoID := s.CreateNewAsset("CASSETTWO", "ucasset2", 2000000) +// cAssetThreeID := s.CreateNewAsset("CASSETTHRE", "ucasset3", 2000000) +// // cAssetFourID := s.CreateNewAsset("CASSETFOUR", "ucasset4", 2000000) +// +// var ( +// assetDataPoolOne []*types.AssetDataPoolMapping +// assetDataPoolTwo []*types.AssetDataPoolMapping +// ) +// assetDataPoolOneAssetOne := &types.AssetDataPoolMapping{ +// AssetID: assetOneID, +// AssetTransitType: 3, +// SupplyCap: uint64(5000000000000000000), +// } +// assetDataPoolOneAssetTwo := &types.AssetDataPoolMapping{ +// AssetID: assetTwoID, +// AssetTransitType: 1, +// SupplyCap: uint64(1000000000000000000), +// } +// assetDataPoolOneAssetThree := &types.AssetDataPoolMapping{ +// AssetID: assetThreeID, +// AssetTransitType: 2, +// SupplyCap: uint64(5000000000000000000), +// } +// assetDataPoolTwoAssetFour := &types.AssetDataPoolMapping{ +// AssetID: assetFourID, +// AssetTransitType: 1, +// SupplyCap: uint64(3000000000000000000), +// } +// +// assetDataPoolOne = append(assetDataPoolOne, assetDataPoolOneAssetOne, assetDataPoolOneAssetTwo, assetDataPoolOneAssetThree) +// assetDataPoolTwo = append(assetDataPoolOne, assetDataPoolTwoAssetFour, assetDataPoolOneAssetTwo, assetDataPoolOneAssetThree) +// +// poolOneID := s.CreateNewPool("cmdx", "CMDX-ATOM-CMST", assetDataPoolOne) +// poolTwoID := s.CreateNewPool("osmo", "OSMO-ATOM-CMST", assetDataPoolTwo) +// +// s.AddAssetRatesStats(assetThreeID, newDec("0.8"), newDec("0.002"), newDec("0.06"), newDec("0.6"), true, newDec("0.04"), newDec("0.04"), newDec("0.06"), newDec("0.8"), newDec("0.85"), newDec("0.025"), newDec("0.025"), newDec("0.1"), cAssetThreeID) +// s.AddAssetRatesStats(assetOneID, newDec("0.75"), newDec("0.002"), newDec("0.07"), newDec("1.25"), false, newDec("0.0"), newDec("0.0"), newDec("0.0"), newDec("0.7"), newDec("0.75"), newDec("0.05"), newDec("0.05"), newDec("0.2"), cAssetOneID) +// // s.AddAssetRatesStats(assetFourID, newDec("0.65"), newDec("0.002"), newDec("0.08"), newDec("1.5"), false, newDec("0.0"), newDec("0.0"), newDec("0.0"), newDec("0.6"), newDec("0.65"), newDec("0.05"), newDec("0.05"), newDec("0.2"), cAssetFourID) +// s.AddAssetRatesStats(assetTwoID, newDec("0.5"), newDec("0.002"), newDec("0.08"), newDec("2.0"), false, newDec("0.0"), newDec("0.0"), newDec("0.0"), newDec("0.5"), newDec("0.55"), newDec("0.05"), newDec("0.05"), newDec("0.2"), cAssetTwoID) +// +// pairOneID := s.AddExtendedLendPair(assetTwoID, assetThreeID, false, poolOneID, 1000000) +// pairTwoID := s.AddExtendedLendPair(assetTwoID, assetOneID, false, poolOneID, 1000000) +// pairThreeID := s.AddExtendedLendPair(assetOneID, assetTwoID, false, poolOneID, 1000000) +// pairFourID := s.AddExtendedLendPair(assetOneID, assetThreeID, false, poolOneID, 1000000) +// pairFiveID := s.AddExtendedLendPair(assetThreeID, assetTwoID, false, poolOneID, 1000000) +// pairSixID := s.AddExtendedLendPair(assetThreeID, assetOneID, false, poolOneID, 1000000) +// pairSevenID := s.AddExtendedLendPair(assetFourID, assetThreeID, false, poolTwoID, 1000000) +// pairEightID := s.AddExtendedLendPair(assetFourID, assetOneID, false, poolTwoID, 1000000) +// pairNineID := s.AddExtendedLendPair(assetOneID, assetFourID, false, poolTwoID, 1000000) +// pairTenID := s.AddExtendedLendPair(assetOneID, assetThreeID, false, poolTwoID, 1000000) +// pairElevenID := s.AddExtendedLendPair(assetThreeID, assetFourID, false, poolTwoID, 1000000) +// pairTwelveID := s.AddExtendedLendPair(assetThreeID, assetOneID, false, poolTwoID, 1000000) +// pairThirteenID := s.AddExtendedLendPair(assetTwoID, assetFourID, true, poolTwoID, 1000000) +// pairFourteenID := s.AddExtendedLendPair(assetThreeID, assetFourID, true, poolTwoID, 1000000) +// pairFifteenID := s.AddExtendedLendPair(assetOneID, assetFourID, true, poolTwoID, 1000000) +// pairSixteenID := s.AddExtendedLendPair(assetFourID, assetTwoID, true, poolOneID, 1000000) +// pairSeventeenID := s.AddExtendedLendPair(assetThreeID, assetTwoID, true, poolOneID, 1000000) +// pairEighteenID := s.AddExtendedLendPair(assetOneID, assetTwoID, true, poolOneID, 1000000) +// +// s.AddAssetToPair(assetOneID, poolOneID, []uint64{pairThreeID, pairFourID, pairFifteenID}) +// s.AddAssetToPair(assetTwoID, poolOneID, []uint64{pairOneID, pairTwoID, pairThirteenID}) +// s.AddAssetToPair(assetThreeID, poolOneID, []uint64{pairFiveID, pairSixID, pairFourteenID}) +// s.AddAssetToPair(assetFourID, poolTwoID, []uint64{pairSevenID, pairEightID, pairSixteenID}) +// s.AddAssetToPair(assetOneID, poolTwoID, []uint64{pairNineID, pairTenID, pairEighteenID}) +// s.AddAssetToPair(assetThreeID, poolTwoID, []uint64{pairElevenID, pairTwelveID, pairSeventeenID}) +// +// appOneID := s.CreateNewApp("commodo", "cmmdo") +// // appTwoID := s.CreateNewApp("cswap", "cswap") +// msg := types.NewMsgLend("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", assetOneID, sdk.NewCoin("uasset1", newInt(300)), poolOneID, appOneID) +// msgLend2 := types.NewMsgLend("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", assetTwoID, sdk.NewCoin("uasset2", newInt(10000000000)), poolOneID, appOneID) +// +// msg3 := types.NewMsgFundModuleAccounts("cmdx", assetOneID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset1", newInt(10000000000))) +// msg4 := types.NewMsgFundModuleAccounts("cmdx", assetTwoID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset2", newInt(10000000000))) +// msg5 := types.NewMsgFundModuleAccounts("cmdx", assetThreeID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset3", newInt(120000000))) +// // msg6 := types.NewMsgFundModuleAccounts("osmo", assetThreeID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset3", newInt(10000000000))) +// msg7 := types.NewMsgFundModuleAccounts("osmo", assetOneID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset1", newInt(10000000000))) +// msg8 := types.NewMsgFundModuleAccounts("osmo", assetFourID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset4", newInt(10000000000))) +// +// s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset1", newInt(100000000000)))) +// s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset2", newInt(100000000000)))) +// s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset3", newInt(100000000000)))) +// s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset4", newInt(100000000000)))) +// _, _ = s.msgServer.Lend(sdk.WrapSDKContext(s.ctx), msg) +// _, _ = s.msgServer.Lend(sdk.WrapSDKContext(s.ctx), msgLend2) +// _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg3) +// _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg4) +// _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg5) +// //_, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg6) +// _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg7) +// _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg8) +// +// msg2 := types.NewMsgBorrow("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", 1, 3, false, sdk.NewCoin("ucasset1", newInt(100)), sdk.NewCoin("uasset2", newInt(10))) +// _, _ = s.msgServer.Borrow(sdk.WrapSDKContext(s.ctx), msg2) +// +// testCases := []struct { +// Name string +// Msg types.MsgCalculateBorrowInterest +// ExpErr error +// ExpResp *types.MsgCalculateBorrowInterestResponse +// QueryResponseIndex uint64 +// QueryResponse *types.MsgCalculateBorrowInterest +// AvailableBalance sdk.Coins +// }{ +// { +// Name: "Borrow Position not found", +// Msg: *types.NewMsgCalculateBorrowInterest("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", 10), +// ExpErr: types.ErrBorrowNotFound, +// ExpResp: nil, +// QueryResponseIndex: 0, +// QueryResponse: nil, +// AvailableBalance: sdk.NewCoins(sdk.NewCoin("uasset1", newInt(0))), +// }, +// { +// Name: "success Valid case", +// Msg: *types.NewMsgCalculateBorrowInterest("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", 1), +// ExpErr: nil, +// ExpResp: &types.MsgCalculateBorrowInterestResponse{}, +// QueryResponseIndex: 0, +// QueryResponse: &types.MsgCalculateBorrowInterest{ +// Borrower: "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", +// BorrowId: 1, +// }, +// // AvailableBalance: sdk.NewCoins(sdk.NewCoin("uasset1", newInt(0))), +// }, +// } +// for _, tc := range testCases { +// tc := tc +// s.Run(tc.Name, func() { +// ctx := sdk.WrapSDKContext(s.ctx) +// resp, err := s.msgServer.CalculateBorrowInterest(ctx, &tc.Msg) +// if tc.ExpErr != nil { +// s.Require().Error(err) +// s.Require().EqualError(err, tc.ExpErr.Error()) +// s.Require().Equal(tc.ExpResp, resp) +// } else { +// s.Require().NoError(err) +// s.Require().NotNil(resp) +// s.Require().Equal(tc.ExpResp, resp) +// +// // availableBalances := s.getBalances(sdk.MustAccAddressFromBech32(tc.Msg.Lender)) +// // fmt.Println("availableBalances", availableBalances) +// // s.Require().True(tc.AvailableBalance.IsEqual(availableBalances)) +// } +// }) +// } +//} +// +//func (s *KeeperTestSuite) TestMsgCalculateLendRewards() { +// assetOneID := s.CreateNewAsset("ASSETONE", "uasset1", 1000000) +// assetTwoID := s.CreateNewAsset("ASSETTWO", "uasset2", 2000000) +// assetThreeID := s.CreateNewAsset("ASSETTHREE", "uasset3", 2000000) +// assetFourID := s.CreateNewAsset("ASSETFOUR", "uasset4", 2000000) +// cAssetOneID := s.CreateNewAsset("CASSETONE", "ucasset1", 1000000) +// cAssetTwoID := s.CreateNewAsset("CASSETTWO", "ucasset2", 2000000) +// cAssetThreeID := s.CreateNewAsset("CASSETTHRE", "ucasset3", 2000000) +// // cAssetFourID := s.CreateNewAsset("CASSETFOUR", "ucasset4", 2000000) +// +// var ( +// assetDataPoolOne []*types.AssetDataPoolMapping +// assetDataPoolTwo []*types.AssetDataPoolMapping +// ) +// assetDataPoolOneAssetOne := &types.AssetDataPoolMapping{ +// AssetID: assetOneID, +// AssetTransitType: 3, +// SupplyCap: uint64(5000000000000000000), +// } +// assetDataPoolOneAssetTwo := &types.AssetDataPoolMapping{ +// AssetID: assetTwoID, +// AssetTransitType: 1, +// SupplyCap: uint64(1000000000000000000), +// } +// assetDataPoolOneAssetThree := &types.AssetDataPoolMapping{ +// AssetID: assetThreeID, +// AssetTransitType: 2, +// SupplyCap: uint64(5000000000000000000), +// } +// assetDataPoolTwoAssetFour := &types.AssetDataPoolMapping{ +// AssetID: assetFourID, +// AssetTransitType: 1, +// SupplyCap: uint64(3000000000000000000), +// } +// +// assetDataPoolOne = append(assetDataPoolOne, assetDataPoolOneAssetOne, assetDataPoolOneAssetTwo, assetDataPoolOneAssetThree) +// assetDataPoolTwo = append(assetDataPoolOne, assetDataPoolTwoAssetFour, assetDataPoolOneAssetTwo, assetDataPoolOneAssetThree) +// +// poolOneID := s.CreateNewPool("cmdx", "CMDX-ATOM-CMST", assetDataPoolOne) +// poolTwoID := s.CreateNewPool("osmo", "OSMO-ATOM-CMST", assetDataPoolTwo) +// +// s.AddAssetRatesStats(assetThreeID, newDec("0.8"), newDec("0.002"), newDec("0.06"), newDec("0.6"), true, newDec("0.04"), newDec("0.04"), newDec("0.06"), newDec("0.8"), newDec("0.85"), newDec("0.025"), newDec("0.025"), newDec("0.1"), cAssetThreeID) +// s.AddAssetRatesStats(assetOneID, newDec("0.75"), newDec("0.002"), newDec("0.07"), newDec("1.25"), false, newDec("0.0"), newDec("0.0"), newDec("0.0"), newDec("0.7"), newDec("0.75"), newDec("0.05"), newDec("0.05"), newDec("0.2"), cAssetOneID) +// // s.AddAssetRatesStats(assetFourID, newDec("0.65"), newDec("0.002"), newDec("0.08"), newDec("1.5"), false, newDec("0.0"), newDec("0.0"), newDec("0.0"), newDec("0.6"), newDec("0.65"), newDec("0.05"), newDec("0.05"), newDec("0.2"), cAssetFourID) +// s.AddAssetRatesStats(assetTwoID, newDec("0.5"), newDec("0.002"), newDec("0.08"), newDec("2.0"), false, newDec("0.0"), newDec("0.0"), newDec("0.0"), newDec("0.5"), newDec("0.55"), newDec("0.05"), newDec("0.05"), newDec("0.2"), cAssetTwoID) +// +// pairOneID := s.AddExtendedLendPair(assetTwoID, assetThreeID, false, poolOneID, 1000000) +// pairTwoID := s.AddExtendedLendPair(assetTwoID, assetOneID, false, poolOneID, 1000000) +// pairThreeID := s.AddExtendedLendPair(assetOneID, assetTwoID, false, poolOneID, 1000000) +// pairFourID := s.AddExtendedLendPair(assetOneID, assetThreeID, false, poolOneID, 1000000) +// pairFiveID := s.AddExtendedLendPair(assetThreeID, assetTwoID, false, poolOneID, 1000000) +// pairSixID := s.AddExtendedLendPair(assetThreeID, assetOneID, false, poolOneID, 1000000) +// pairSevenID := s.AddExtendedLendPair(assetFourID, assetThreeID, false, poolTwoID, 1000000) +// pairEightID := s.AddExtendedLendPair(assetFourID, assetOneID, false, poolTwoID, 1000000) +// pairNineID := s.AddExtendedLendPair(assetOneID, assetFourID, false, poolTwoID, 1000000) +// pairTenID := s.AddExtendedLendPair(assetOneID, assetThreeID, false, poolTwoID, 1000000) +// pairElevenID := s.AddExtendedLendPair(assetThreeID, assetFourID, false, poolTwoID, 1000000) +// pairTwelveID := s.AddExtendedLendPair(assetThreeID, assetOneID, false, poolTwoID, 1000000) +// pairThirteenID := s.AddExtendedLendPair(assetTwoID, assetFourID, true, poolTwoID, 1000000) +// pairFourteenID := s.AddExtendedLendPair(assetThreeID, assetFourID, true, poolTwoID, 1000000) +// pairFifteenID := s.AddExtendedLendPair(assetOneID, assetFourID, true, poolTwoID, 1000000) +// pairSixteenID := s.AddExtendedLendPair(assetFourID, assetTwoID, true, poolOneID, 1000000) +// pairSeventeenID := s.AddExtendedLendPair(assetThreeID, assetTwoID, true, poolOneID, 1000000) +// pairEighteenID := s.AddExtendedLendPair(assetOneID, assetTwoID, true, poolOneID, 1000000) +// +// s.AddAssetToPair(assetOneID, poolOneID, []uint64{pairThreeID, pairFourID, pairFifteenID}) +// s.AddAssetToPair(assetTwoID, poolOneID, []uint64{pairOneID, pairTwoID, pairThirteenID}) +// s.AddAssetToPair(assetThreeID, poolOneID, []uint64{pairFiveID, pairSixID, pairFourteenID}) +// s.AddAssetToPair(assetFourID, poolTwoID, []uint64{pairSevenID, pairEightID, pairSixteenID}) +// s.AddAssetToPair(assetOneID, poolTwoID, []uint64{pairNineID, pairTenID, pairEighteenID}) +// s.AddAssetToPair(assetThreeID, poolTwoID, []uint64{pairElevenID, pairTwelveID, pairSeventeenID}) +// +// appOneID := s.CreateNewApp("commodo", "cmmdo") +// // appTwoID := s.CreateNewApp("cswap", "cswap") +// msg := types.NewMsgLend("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", assetOneID, sdk.NewCoin("uasset1", newInt(300)), poolOneID, appOneID) +// msgLend2 := types.NewMsgLend("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", assetTwoID, sdk.NewCoin("uasset2", newInt(10000000000)), poolOneID, appOneID) +// +// msg3 := types.NewMsgFundModuleAccounts("cmdx", assetOneID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset1", newInt(10000000000))) +// msg4 := types.NewMsgFundModuleAccounts("cmdx", assetTwoID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset2", newInt(10000000000))) +// msg5 := types.NewMsgFundModuleAccounts("cmdx", assetThreeID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset3", newInt(120000000))) +// // msg6 := types.NewMsgFundModuleAccounts("osmo", assetThreeID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset3", newInt(10000000000))) +// msg7 := types.NewMsgFundModuleAccounts("osmo", assetOneID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset1", newInt(10000000000))) +// msg8 := types.NewMsgFundModuleAccounts("osmo", assetFourID, "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", sdk.NewCoin("uasset4", newInt(10000000000))) +// +// s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset1", newInt(100000000000)))) +// s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset2", newInt(100000000000)))) +// s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset3", newInt(100000000000)))) +// s.fundAddr(sdk.MustAccAddressFromBech32("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t"), sdk.NewCoins(sdk.NewCoin("uasset4", newInt(100000000000)))) +// _, _ = s.msgServer.Lend(sdk.WrapSDKContext(s.ctx), msg) +// _, _ = s.msgServer.Lend(sdk.WrapSDKContext(s.ctx), msgLend2) +// _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg3) +// _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg4) +// _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg5) +// //_, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg6) +// _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg7) +// _, _ = s.msgServer.FundModuleAccounts(sdk.WrapSDKContext(s.ctx), msg8) +// +// msg2 := types.NewMsgBorrow("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", 1, 3, false, sdk.NewCoin("ucasset1", newInt(100)), sdk.NewCoin("uasset2", newInt(10))) +// _, _ = s.msgServer.Borrow(sdk.WrapSDKContext(s.ctx), msg2) +// +// testCases := []struct { +// Name string +// Msg types.MsgCalculateLendRewards +// ExpErr error +// ExpResp *types.MsgCalculateLendRewardsResponse +// QueryResponseIndex uint64 +// QueryResponse *types.MsgCalculateLendRewards +// AvailableBalance sdk.Coins +// }{ +// { +// Name: "Lend Position not found", +// Msg: *types.NewMsgCalculateLendRewards("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", 10), +// ExpErr: types.ErrLendNotFound, +// ExpResp: nil, +// QueryResponseIndex: 0, +// QueryResponse: nil, +// AvailableBalance: sdk.NewCoins(sdk.NewCoin("uasset1", newInt(0))), +// }, +// { +// Name: "success Valid case", +// Msg: *types.NewMsgCalculateLendRewards("cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", 1), +// ExpErr: nil, +// ExpResp: &types.MsgCalculateLendRewardsResponse{}, +// QueryResponseIndex: 0, +// QueryResponse: &types.MsgCalculateLendRewards{ +// Lender: "cosmos1yq8lgssgxlx9smjhes6ryjasmqmd3ts2559g0t", +// LendId: 1, +// }, +// // AvailableBalance: sdk.NewCoins(sdk.NewCoin("uasset1", newInt(0))), +// }, +// } +// for _, tc := range testCases { +// tc := tc +// s.Run(tc.Name, func() { +// ctx := sdk.WrapSDKContext(s.ctx) +// resp, err := s.msgServer.CalculateLendRewards(ctx, &tc.Msg) +// if tc.ExpErr != nil { +// s.Require().Error(err) +// s.Require().EqualError(err, tc.ExpErr.Error()) +// s.Require().Equal(tc.ExpResp, resp) +// } else { +// s.Require().NoError(err) +// s.Require().NotNil(resp) +// s.Require().Equal(tc.ExpResp, resp) +// +// // availableBalances := s.getBalances(sdk.MustAccAddressFromBech32(tc.Msg.Lender)) +// // fmt.Println("availableBalances", availableBalances) +// // s.Require().True(tc.AvailableBalance.IsEqual(availableBalances)) +// } +// }) +// } +//} diff --git a/x/lend/types/codec.go b/x/lend/types/codec.go index a17234e30..27f82c242 100644 --- a/x/lend/types/codec.go +++ b/x/lend/types/codec.go @@ -27,8 +27,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&AddAssetToPairProposal{}, "comdex/lend/AddAssetToPairProposal", nil) cdc.RegisterConcrete(&AddAssetRatesParams{}, "comdex/lend/AddAssetRatesParams", nil) cdc.RegisterConcrete(&AddAuctionParamsProposal{}, "comdex/lend/AddAuctionParamsProposal", nil) - cdc.RegisterConcrete(&MsgCalculateBorrowInterest{}, "comdex/lend/MsgCalculateBorrowInterest", nil) - cdc.RegisterConcrete(&MsgCalculateLendRewards{}, "comdex/lend/MsgCalculateLendRewards", nil) + cdc.RegisterConcrete(&MsgCalculateInterestAndRewards{}, "comdex/lend/MsgCalculateInterestAndRewards", nil) } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { @@ -54,8 +53,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &MsgRepay{}, &MsgBorrowAlternate{}, &MsgFundModuleAccounts{}, - &MsgCalculateBorrowInterest{}, - &MsgCalculateLendRewards{}, + &MsgCalculateInterestAndRewards{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/lend/types/params.go b/x/lend/types/params.go index c202be269..067dbabba 100644 --- a/x/lend/types/params.go +++ b/x/lend/types/params.go @@ -9,18 +9,17 @@ import ( var _ paramtypes.ParamSet = (*Params)(nil) const ( - LendGas = sdk.Gas(32763) - WithdrawGas = sdk.Gas(22763) - DepositGas = sdk.Gas(22763) - CloseLendGas = sdk.Gas(22763) - BorrowAssetGas = sdk.Gas(22763) - DrawAssetGas = sdk.Gas(22763) - RepayAssetGas = sdk.Gas(22763) - DepositBorrowAssetGas = sdk.Gas(22763) - CloseBorrowAssetGas = sdk.Gas(22763) - BorrowAssetAlternateGas = sdk.Gas(22763) - CalculateBorrowInterestGas = sdk.Gas(22763) - CalculateLendRewardGas = sdk.Gas(22763) + LendGas = sdk.Gas(32763) + WithdrawGas = sdk.Gas(22763) + DepositGas = sdk.Gas(22763) + CloseLendGas = sdk.Gas(22763) + BorrowAssetGas = sdk.Gas(22763) + DrawAssetGas = sdk.Gas(22763) + RepayAssetGas = sdk.Gas(22763) + DepositBorrowAssetGas = sdk.Gas(22763) + CloseBorrowAssetGas = sdk.Gas(22763) + BorrowAssetAlternateGas = sdk.Gas(22763) + CalculateInterestAndRewardGas = sdk.Gas(22763) ) const ( diff --git a/x/lend/types/tx.go b/x/lend/types/tx.go index 1ef9a8ff9..d1bc0add7 100644 --- a/x/lend/types/tx.go +++ b/x/lend/types/tx.go @@ -475,29 +475,25 @@ func (msg *MsgBorrowAlternate) GetSignBytes() []byte { return sdk.MustSortJSON(bz) } -func NewMsgCalculateBorrowInterest(borrower string, borrowID uint64) *MsgCalculateBorrowInterest { - return &MsgCalculateBorrowInterest{ +func NewMsgCalculateInterestAndRewards(borrower string) *MsgCalculateInterestAndRewards { + return &MsgCalculateInterestAndRewards{ Borrower: borrower, - BorrowId: borrowID, } } -func (msg MsgCalculateBorrowInterest) Route() string { return ModuleName } -func (msg MsgCalculateBorrowInterest) Type() string { return TypeCalculateBorrowInterestRequest } +func (msg MsgCalculateInterestAndRewards) Route() string { return ModuleName } +func (msg MsgCalculateInterestAndRewards) Type() string { return TypeCalculateLendRewardsRequest } -func (msg *MsgCalculateBorrowInterest) ValidateBasic() error { +func (msg *MsgCalculateInterestAndRewards) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.GetBorrower()) if err != nil { return err } - if msg.BorrowId <= 0 { - return fmt.Errorf("borrow id should be positive: %d > 0", msg.BorrowId) - } return nil } -func (msg *MsgCalculateBorrowInterest) GetSigners() []sdk.AccAddress { +func (msg *MsgCalculateInterestAndRewards) GetSigners() []sdk.AccAddress { lender, err := sdk.AccAddressFromBech32(msg.GetBorrower()) if err != nil { panic(err) @@ -506,43 +502,7 @@ func (msg *MsgCalculateBorrowInterest) GetSigners() []sdk.AccAddress { } // GetSignBytes get the bytes for the message signer to sign on. -func (msg *MsgCalculateBorrowInterest) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(msg) - return sdk.MustSortJSON(bz) -} - -func NewMsgCalculateLendRewards(lender string, lendID uint64) *MsgCalculateLendRewards { - return &MsgCalculateLendRewards{ - Lender: lender, - LendId: lendID, - } -} - -func (msg MsgCalculateLendRewards) Route() string { return ModuleName } -func (msg MsgCalculateLendRewards) Type() string { return TypeCalculateLendRewardsRequest } - -func (msg *MsgCalculateLendRewards) ValidateBasic() error { - _, err := sdk.AccAddressFromBech32(msg.GetLender()) - if err != nil { - return err - } - - if msg.LendId <= 0 { - return fmt.Errorf("lend id should be positive: %d > 0", msg.LendId) - } - return nil -} - -func (msg *MsgCalculateLendRewards) GetSigners() []sdk.AccAddress { - lender, err := sdk.AccAddressFromBech32(msg.GetLender()) - if err != nil { - panic(err) - } - return []sdk.AccAddress{lender} -} - -// GetSignBytes get the bytes for the message signer to sign on. -func (msg *MsgCalculateLendRewards) GetSignBytes() []byte { +func (msg *MsgCalculateInterestAndRewards) GetSignBytes() []byte { bz := ModuleCdc.MustMarshalJSON(msg) return sdk.MustSortJSON(bz) } diff --git a/x/lend/types/tx.pb.go b/x/lend/types/tx.pb.go index 326a5b6ee..67bc4e813 100644 --- a/x/lend/types/tx.pb.go +++ b/x/lend/types/tx.pb.go @@ -761,23 +761,22 @@ func (m *MsgFundModuleAccounts) GetAmount() types.Coin { return types.Coin{} } -type MsgCalculateBorrowInterest struct { +type MsgCalculateInterestAndRewards struct { Borrower string `protobuf:"bytes,1,opt,name=borrower,proto3" json:"borrower,omitempty"` - BorrowId uint64 `protobuf:"varint,2,opt,name=borrow_id,json=borrowId,proto3" json:"borrow_id,omitempty"` } -func (m *MsgCalculateBorrowInterest) Reset() { *m = MsgCalculateBorrowInterest{} } -func (m *MsgCalculateBorrowInterest) String() string { return proto.CompactTextString(m) } -func (*MsgCalculateBorrowInterest) ProtoMessage() {} -func (*MsgCalculateBorrowInterest) Descriptor() ([]byte, []int) { +func (m *MsgCalculateInterestAndRewards) Reset() { *m = MsgCalculateInterestAndRewards{} } +func (m *MsgCalculateInterestAndRewards) String() string { return proto.CompactTextString(m) } +func (*MsgCalculateInterestAndRewards) ProtoMessage() {} +func (*MsgCalculateInterestAndRewards) Descriptor() ([]byte, []int) { return fileDescriptor_957d64b59d60594d, []int{11} } -func (m *MsgCalculateBorrowInterest) XXX_Unmarshal(b []byte) error { +func (m *MsgCalculateInterestAndRewards) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgCalculateBorrowInterest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgCalculateInterestAndRewards) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgCalculateBorrowInterest.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgCalculateInterestAndRewards.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -787,84 +786,25 @@ func (m *MsgCalculateBorrowInterest) XXX_Marshal(b []byte, deterministic bool) ( return b[:n], nil } } -func (m *MsgCalculateBorrowInterest) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCalculateBorrowInterest.Merge(m, src) +func (m *MsgCalculateInterestAndRewards) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCalculateInterestAndRewards.Merge(m, src) } -func (m *MsgCalculateBorrowInterest) XXX_Size() int { +func (m *MsgCalculateInterestAndRewards) XXX_Size() int { return m.Size() } -func (m *MsgCalculateBorrowInterest) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCalculateBorrowInterest.DiscardUnknown(m) +func (m *MsgCalculateInterestAndRewards) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCalculateInterestAndRewards.DiscardUnknown(m) } -var xxx_messageInfo_MsgCalculateBorrowInterest proto.InternalMessageInfo +var xxx_messageInfo_MsgCalculateInterestAndRewards proto.InternalMessageInfo -func (m *MsgCalculateBorrowInterest) GetBorrower() string { +func (m *MsgCalculateInterestAndRewards) GetBorrower() string { if m != nil { return m.Borrower } return "" } -func (m *MsgCalculateBorrowInterest) GetBorrowId() uint64 { - if m != nil { - return m.BorrowId - } - return 0 -} - -type MsgCalculateLendRewards struct { - Lender string `protobuf:"bytes,1,opt,name=lender,proto3" json:"lender,omitempty"` - LendId uint64 `protobuf:"varint,2,opt,name=lend_id,json=lendId,proto3" json:"lend_id,omitempty"` -} - -func (m *MsgCalculateLendRewards) Reset() { *m = MsgCalculateLendRewards{} } -func (m *MsgCalculateLendRewards) String() string { return proto.CompactTextString(m) } -func (*MsgCalculateLendRewards) ProtoMessage() {} -func (*MsgCalculateLendRewards) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{12} -} -func (m *MsgCalculateLendRewards) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgCalculateLendRewards) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgCalculateLendRewards.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgCalculateLendRewards) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCalculateLendRewards.Merge(m, src) -} -func (m *MsgCalculateLendRewards) XXX_Size() int { - return m.Size() -} -func (m *MsgCalculateLendRewards) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCalculateLendRewards.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgCalculateLendRewards proto.InternalMessageInfo - -func (m *MsgCalculateLendRewards) GetLender() string { - if m != nil { - return m.Lender - } - return "" -} - -func (m *MsgCalculateLendRewards) GetLendId() uint64 { - if m != nil { - return m.LendId - } - return 0 -} - type MsgLendResponse struct { } @@ -872,7 +812,7 @@ func (m *MsgLendResponse) Reset() { *m = MsgLendResponse{} } func (m *MsgLendResponse) String() string { return proto.CompactTextString(m) } func (*MsgLendResponse) ProtoMessage() {} func (*MsgLendResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{13} + return fileDescriptor_957d64b59d60594d, []int{12} } func (m *MsgLendResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -908,7 +848,7 @@ func (m *MsgWithdrawResponse) Reset() { *m = MsgWithdrawResponse{} } func (m *MsgWithdrawResponse) String() string { return proto.CompactTextString(m) } func (*MsgWithdrawResponse) ProtoMessage() {} func (*MsgWithdrawResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{14} + return fileDescriptor_957d64b59d60594d, []int{13} } func (m *MsgWithdrawResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -944,7 +884,7 @@ func (m *MsgDepositResponse) Reset() { *m = MsgDepositResponse{} } func (m *MsgDepositResponse) String() string { return proto.CompactTextString(m) } func (*MsgDepositResponse) ProtoMessage() {} func (*MsgDepositResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{15} + return fileDescriptor_957d64b59d60594d, []int{14} } func (m *MsgDepositResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -980,7 +920,7 @@ func (m *MsgCloseLendResponse) Reset() { *m = MsgCloseLendResponse{} } func (m *MsgCloseLendResponse) String() string { return proto.CompactTextString(m) } func (*MsgCloseLendResponse) ProtoMessage() {} func (*MsgCloseLendResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{16} + return fileDescriptor_957d64b59d60594d, []int{15} } func (m *MsgCloseLendResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1016,7 +956,7 @@ func (m *MsgBorrowResponse) Reset() { *m = MsgBorrowResponse{} } func (m *MsgBorrowResponse) String() string { return proto.CompactTextString(m) } func (*MsgBorrowResponse) ProtoMessage() {} func (*MsgBorrowResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{17} + return fileDescriptor_957d64b59d60594d, []int{16} } func (m *MsgBorrowResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1052,7 +992,7 @@ func (m *MsgRepayResponse) Reset() { *m = MsgRepayResponse{} } func (m *MsgRepayResponse) String() string { return proto.CompactTextString(m) } func (*MsgRepayResponse) ProtoMessage() {} func (*MsgRepayResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{18} + return fileDescriptor_957d64b59d60594d, []int{17} } func (m *MsgRepayResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1088,7 +1028,7 @@ func (m *MsgDepositBorrowResponse) Reset() { *m = MsgDepositBorrowRespon func (m *MsgDepositBorrowResponse) String() string { return proto.CompactTextString(m) } func (*MsgDepositBorrowResponse) ProtoMessage() {} func (*MsgDepositBorrowResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{19} + return fileDescriptor_957d64b59d60594d, []int{18} } func (m *MsgDepositBorrowResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1124,7 +1064,7 @@ func (m *MsgDrawResponse) Reset() { *m = MsgDrawResponse{} } func (m *MsgDrawResponse) String() string { return proto.CompactTextString(m) } func (*MsgDrawResponse) ProtoMessage() {} func (*MsgDrawResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{20} + return fileDescriptor_957d64b59d60594d, []int{19} } func (m *MsgDrawResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1160,7 +1100,7 @@ func (m *MsgCloseBorrowResponse) Reset() { *m = MsgCloseBorrowResponse{} func (m *MsgCloseBorrowResponse) String() string { return proto.CompactTextString(m) } func (*MsgCloseBorrowResponse) ProtoMessage() {} func (*MsgCloseBorrowResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{21} + return fileDescriptor_957d64b59d60594d, []int{20} } func (m *MsgCloseBorrowResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1196,7 +1136,7 @@ func (m *MsgBorrowAlternateResponse) Reset() { *m = MsgBorrowAlternateRe func (m *MsgBorrowAlternateResponse) String() string { return proto.CompactTextString(m) } func (*MsgBorrowAlternateResponse) ProtoMessage() {} func (*MsgBorrowAlternateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{22} + return fileDescriptor_957d64b59d60594d, []int{21} } func (m *MsgBorrowAlternateResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1232,7 +1172,7 @@ func (m *MsgFundModuleAccountsResponse) Reset() { *m = MsgFundModuleAcco func (m *MsgFundModuleAccountsResponse) String() string { return proto.CompactTextString(m) } func (*MsgFundModuleAccountsResponse) ProtoMessage() {} func (*MsgFundModuleAccountsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{23} + return fileDescriptor_957d64b59d60594d, []int{22} } func (m *MsgFundModuleAccountsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1261,57 +1201,23 @@ func (m *MsgFundModuleAccountsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgFundModuleAccountsResponse proto.InternalMessageInfo -type MsgCalculateBorrowInterestResponse struct { -} - -func (m *MsgCalculateBorrowInterestResponse) Reset() { *m = MsgCalculateBorrowInterestResponse{} } -func (m *MsgCalculateBorrowInterestResponse) String() string { return proto.CompactTextString(m) } -func (*MsgCalculateBorrowInterestResponse) ProtoMessage() {} -func (*MsgCalculateBorrowInterestResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{24} +type MsgCalculateInterestAndRewardsResponse struct { } -func (m *MsgCalculateBorrowInterestResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgCalculateBorrowInterestResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgCalculateBorrowInterestResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgCalculateBorrowInterestResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCalculateBorrowInterestResponse.Merge(m, src) -} -func (m *MsgCalculateBorrowInterestResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgCalculateBorrowInterestResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCalculateBorrowInterestResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgCalculateBorrowInterestResponse proto.InternalMessageInfo -type MsgCalculateLendRewardsResponse struct { +func (m *MsgCalculateInterestAndRewardsResponse) Reset() { + *m = MsgCalculateInterestAndRewardsResponse{} } - -func (m *MsgCalculateLendRewardsResponse) Reset() { *m = MsgCalculateLendRewardsResponse{} } -func (m *MsgCalculateLendRewardsResponse) String() string { return proto.CompactTextString(m) } -func (*MsgCalculateLendRewardsResponse) ProtoMessage() {} -func (*MsgCalculateLendRewardsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_957d64b59d60594d, []int{25} +func (m *MsgCalculateInterestAndRewardsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCalculateInterestAndRewardsResponse) ProtoMessage() {} +func (*MsgCalculateInterestAndRewardsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_957d64b59d60594d, []int{23} } -func (m *MsgCalculateLendRewardsResponse) XXX_Unmarshal(b []byte) error { +func (m *MsgCalculateInterestAndRewardsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *MsgCalculateLendRewardsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *MsgCalculateInterestAndRewardsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_MsgCalculateLendRewardsResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_MsgCalculateInterestAndRewardsResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -1321,17 +1227,17 @@ func (m *MsgCalculateLendRewardsResponse) XXX_Marshal(b []byte, deterministic bo return b[:n], nil } } -func (m *MsgCalculateLendRewardsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgCalculateLendRewardsResponse.Merge(m, src) +func (m *MsgCalculateInterestAndRewardsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCalculateInterestAndRewardsResponse.Merge(m, src) } -func (m *MsgCalculateLendRewardsResponse) XXX_Size() int { +func (m *MsgCalculateInterestAndRewardsResponse) XXX_Size() int { return m.Size() } -func (m *MsgCalculateLendRewardsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgCalculateLendRewardsResponse.DiscardUnknown(m) +func (m *MsgCalculateInterestAndRewardsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCalculateInterestAndRewardsResponse.DiscardUnknown(m) } -var xxx_messageInfo_MsgCalculateLendRewardsResponse proto.InternalMessageInfo +var xxx_messageInfo_MsgCalculateInterestAndRewardsResponse proto.InternalMessageInfo func init() { proto.RegisterType((*MsgLend)(nil), "comdex.lend.v1beta1.MsgLend") @@ -1345,8 +1251,7 @@ func init() { proto.RegisterType((*MsgCloseBorrow)(nil), "comdex.lend.v1beta1.MsgCloseBorrow") proto.RegisterType((*MsgBorrowAlternate)(nil), "comdex.lend.v1beta1.MsgBorrowAlternate") proto.RegisterType((*MsgFundModuleAccounts)(nil), "comdex.lend.v1beta1.MsgFundModuleAccounts") - proto.RegisterType((*MsgCalculateBorrowInterest)(nil), "comdex.lend.v1beta1.MsgCalculateBorrowInterest") - proto.RegisterType((*MsgCalculateLendRewards)(nil), "comdex.lend.v1beta1.MsgCalculateLendRewards") + proto.RegisterType((*MsgCalculateInterestAndRewards)(nil), "comdex.lend.v1beta1.MsgCalculateInterestAndRewards") proto.RegisterType((*MsgLendResponse)(nil), "comdex.lend.v1beta1.MsgLendResponse") proto.RegisterType((*MsgWithdrawResponse)(nil), "comdex.lend.v1beta1.MsgWithdrawResponse") proto.RegisterType((*MsgDepositResponse)(nil), "comdex.lend.v1beta1.MsgDepositResponse") @@ -1358,74 +1263,71 @@ func init() { proto.RegisterType((*MsgCloseBorrowResponse)(nil), "comdex.lend.v1beta1.MsgCloseBorrowResponse") proto.RegisterType((*MsgBorrowAlternateResponse)(nil), "comdex.lend.v1beta1.MsgBorrowAlternateResponse") proto.RegisterType((*MsgFundModuleAccountsResponse)(nil), "comdex.lend.v1beta1.MsgFundModuleAccountsResponse") - proto.RegisterType((*MsgCalculateBorrowInterestResponse)(nil), "comdex.lend.v1beta1.MsgCalculateBorrowInterestResponse") - proto.RegisterType((*MsgCalculateLendRewardsResponse)(nil), "comdex.lend.v1beta1.MsgCalculateLendRewardsResponse") + proto.RegisterType((*MsgCalculateInterestAndRewardsResponse)(nil), "comdex.lend.v1beta1.MsgCalculateInterestAndRewardsResponse") } func init() { proto.RegisterFile("comdex/lend/v1beta1/tx.proto", fileDescriptor_957d64b59d60594d) } var fileDescriptor_957d64b59d60594d = []byte{ - // 960 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x57, 0xdd, 0x6e, 0x1b, 0x45, - 0x14, 0xce, 0xc6, 0x8e, 0x7f, 0x4e, 0xa0, 0x3f, 0x93, 0x3f, 0x77, 0x49, 0x37, 0xa9, 0x69, 0xa9, - 0xf9, 0xe9, 0x5a, 0x0d, 0x48, 0xbd, 0x41, 0xa0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00, 0x00, 0x00, 0xff, 0xff, 0x7b, 0x33, 0x52, 0x38, 0x31, 0x0e, 0x00, 0x00, + // 926 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x57, 0x5f, 0x6f, 0xdb, 0x54, + 0x14, 0xaf, 0x9b, 0xd4, 0x49, 0x4e, 0x61, 0x7f, 0x6e, 0xff, 0x2c, 0xf3, 0x3a, 0xb7, 0x18, 0xb6, + 0x05, 0xd0, 0x6c, 0xad, 0x7b, 0xe0, 0x81, 0x09, 0xd4, 0xae, 0x42, 0x64, 0xc2, 0x80, 0x32, 0x09, + 0x04, 0x2f, 0xd1, 0x4d, 0x7c, 0xe7, 0x59, 0x38, 0xbe, 0x96, 0xef, 0xcd, 0xb2, 0x09, 0x5e, 0x10, + 0xbc, 0xc3, 0x67, 0x40, 0xe2, 0x3b, 0xf0, 0x11, 0xf6, 0xb8, 0x47, 0x9e, 0x10, 0x6a, 0xbf, 0x08, + 0xf2, 0xf5, 0xf5, 0x8d, 0xd3, 0xc5, 0x4e, 0xba, 0x8a, 0xbe, 0xf9, 0x9e, 0xf3, 0x3b, 0x7f, 0x7a, + 0xce, 0xef, 0x9c, 0xd3, 0xc0, 0xce, 0x90, 0x8e, 0x3c, 0xf2, 0xdc, 0x09, 0x49, 0xe4, 0x39, 0xcf, + 0xee, 0x0d, 0x08, 0xc7, 0xf7, 0x1c, 0xfe, 0xdc, 0x8e, 0x13, 0xca, 0x29, 0xda, 0xc8, 0xb4, 0x76, + 0xaa, 0xb5, 0xa5, 0xd6, 0x30, 0x87, 0x94, 0x8d, 0x28, 0x73, 0x06, 0x98, 0x11, 0x65, 0x32, 0xa4, + 0x41, 0x94, 0x19, 0x19, 0x9b, 0x3e, 0xf5, 0xa9, 0xf8, 0x74, 0xd2, 0xaf, 0x4c, 0x6a, 0xfd, 0xa9, + 0x41, 0xc3, 0x65, 0xfe, 0x17, 0x24, 0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b8, 0x4b, 0x9f, 0x3c, 0x09, 0x86, + 0x01, 0x0e, 0xe5, 0xdb, 0x91, 0xbf, 0x90, 0xf8, 0x8b, 0x98, 0xb0, 0x81, 0x2e, 0x7e, 0xd2, 0xdc, + 0xff, 0x2f, 0x00, 0x00, 0xff, 0xff, 0xad, 0x28, 0x2c, 0x5f, 0x3d, 0x0d, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1457,8 +1359,7 @@ type MsgClient interface { BorrowAlternate(ctx context.Context, in *MsgBorrowAlternate, opts ...grpc.CallOption) (*MsgBorrowAlternateResponse, error) // FundModuleAccounts funds an existing module account FundModuleAccounts(ctx context.Context, in *MsgFundModuleAccounts, opts ...grpc.CallOption) (*MsgFundModuleAccountsResponse, error) - CalculateBorrowInterest(ctx context.Context, in *MsgCalculateBorrowInterest, opts ...grpc.CallOption) (*MsgCalculateBorrowInterestResponse, error) - CalculateLendRewards(ctx context.Context, in *MsgCalculateLendRewards, opts ...grpc.CallOption) (*MsgCalculateLendRewardsResponse, error) + CalculateInterestAndRewards(ctx context.Context, in *MsgCalculateInterestAndRewards, opts ...grpc.CallOption) (*MsgCalculateInterestAndRewardsResponse, error) } type msgClient struct { @@ -1568,18 +1469,9 @@ func (c *msgClient) FundModuleAccounts(ctx context.Context, in *MsgFundModuleAcc return out, nil } -func (c *msgClient) CalculateBorrowInterest(ctx context.Context, in *MsgCalculateBorrowInterest, opts ...grpc.CallOption) (*MsgCalculateBorrowInterestResponse, error) { - out := new(MsgCalculateBorrowInterestResponse) - err := c.cc.Invoke(ctx, "/comdex.lend.v1beta1.Msg/CalculateBorrowInterest", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *msgClient) CalculateLendRewards(ctx context.Context, in *MsgCalculateLendRewards, opts ...grpc.CallOption) (*MsgCalculateLendRewardsResponse, error) { - out := new(MsgCalculateLendRewardsResponse) - err := c.cc.Invoke(ctx, "/comdex.lend.v1beta1.Msg/CalculateLendRewards", in, out, opts...) +func (c *msgClient) CalculateInterestAndRewards(ctx context.Context, in *MsgCalculateInterestAndRewards, opts ...grpc.CallOption) (*MsgCalculateInterestAndRewardsResponse, error) { + out := new(MsgCalculateInterestAndRewardsResponse) + err := c.cc.Invoke(ctx, "/comdex.lend.v1beta1.Msg/CalculateInterestAndRewards", in, out, opts...) if err != nil { return nil, err } @@ -1605,8 +1497,7 @@ type MsgServer interface { BorrowAlternate(context.Context, *MsgBorrowAlternate) (*MsgBorrowAlternateResponse, error) // FundModuleAccounts funds an existing module account FundModuleAccounts(context.Context, *MsgFundModuleAccounts) (*MsgFundModuleAccountsResponse, error) - CalculateBorrowInterest(context.Context, *MsgCalculateBorrowInterest) (*MsgCalculateBorrowInterestResponse, error) - CalculateLendRewards(context.Context, *MsgCalculateLendRewards) (*MsgCalculateLendRewardsResponse, error) + CalculateInterestAndRewards(context.Context, *MsgCalculateInterestAndRewards) (*MsgCalculateInterestAndRewardsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -1646,11 +1537,8 @@ func (*UnimplementedMsgServer) BorrowAlternate(ctx context.Context, req *MsgBorr func (*UnimplementedMsgServer) FundModuleAccounts(ctx context.Context, req *MsgFundModuleAccounts) (*MsgFundModuleAccountsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method FundModuleAccounts not implemented") } -func (*UnimplementedMsgServer) CalculateBorrowInterest(ctx context.Context, req *MsgCalculateBorrowInterest) (*MsgCalculateBorrowInterestResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method CalculateBorrowInterest not implemented") -} -func (*UnimplementedMsgServer) CalculateLendRewards(ctx context.Context, req *MsgCalculateLendRewards) (*MsgCalculateLendRewardsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method CalculateLendRewards not implemented") +func (*UnimplementedMsgServer) CalculateInterestAndRewards(ctx context.Context, req *MsgCalculateInterestAndRewards) (*MsgCalculateInterestAndRewardsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CalculateInterestAndRewards not implemented") } func RegisterMsgServer(s grpc1.Server, srv MsgServer) { @@ -1855,38 +1743,20 @@ func _Msg_FundModuleAccounts_Handler(srv interface{}, ctx context.Context, dec f return interceptor(ctx, in, info, handler) } -func _Msg_CalculateBorrowInterest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgCalculateBorrowInterest) +func _Msg_CalculateInterestAndRewards_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCalculateInterestAndRewards) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MsgServer).CalculateBorrowInterest(ctx, in) + return srv.(MsgServer).CalculateInterestAndRewards(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/comdex.lend.v1beta1.Msg/CalculateBorrowInterest", + FullMethod: "/comdex.lend.v1beta1.Msg/CalculateInterestAndRewards", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).CalculateBorrowInterest(ctx, req.(*MsgCalculateBorrowInterest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Msg_CalculateLendRewards_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgCalculateLendRewards) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).CalculateLendRewards(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/comdex.lend.v1beta1.Msg/CalculateLendRewards", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).CalculateLendRewards(ctx, req.(*MsgCalculateLendRewards)) + return srv.(MsgServer).CalculateInterestAndRewards(ctx, req.(*MsgCalculateInterestAndRewards)) } return interceptor(ctx, in, info, handler) } @@ -1940,12 +1810,8 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Handler: _Msg_FundModuleAccounts_Handler, }, { - MethodName: "CalculateBorrowInterest", - Handler: _Msg_CalculateBorrowInterest_Handler, - }, - { - MethodName: "CalculateLendRewards", - Handler: _Msg_CalculateLendRewards_Handler, + MethodName: "CalculateInterestAndRewards", + Handler: _Msg_CalculateInterestAndRewards_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -2504,7 +2370,7 @@ func (m *MsgFundModuleAccounts) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *MsgCalculateBorrowInterest) Marshal() (dAtA []byte, err error) { +func (m *MsgCalculateInterestAndRewards) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -2514,21 +2380,16 @@ func (m *MsgCalculateBorrowInterest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgCalculateBorrowInterest) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgCalculateInterestAndRewards) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgCalculateBorrowInterest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgCalculateInterestAndRewards) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if m.BorrowId != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.BorrowId)) - i-- - dAtA[i] = 0x10 - } if len(m.Borrower) > 0 { i -= len(m.Borrower) copy(dAtA[i:], m.Borrower) @@ -2539,41 +2400,6 @@ func (m *MsgCalculateBorrowInterest) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } -func (m *MsgCalculateLendRewards) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgCalculateLendRewards) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgCalculateLendRewards) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.LendId != 0 { - i = encodeVarintTx(dAtA, i, uint64(m.LendId)) - i-- - dAtA[i] = 0x10 - } - if len(m.Lender) > 0 { - i -= len(m.Lender) - copy(dAtA[i:], m.Lender) - i = encodeVarintTx(dAtA, i, uint64(len(m.Lender))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - func (m *MsgLendResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -2827,30 +2653,7 @@ func (m *MsgFundModuleAccountsResponse) MarshalToSizedBuffer(dAtA []byte) (int, return len(dAtA) - i, nil } -func (m *MsgCalculateBorrowInterestResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgCalculateBorrowInterestResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgCalculateBorrowInterestResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - -func (m *MsgCalculateLendRewardsResponse) Marshal() (dAtA []byte, err error) { +func (m *MsgCalculateInterestAndRewardsResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -2860,12 +2663,12 @@ func (m *MsgCalculateLendRewardsResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *MsgCalculateLendRewardsResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *MsgCalculateInterestAndRewardsResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MsgCalculateLendRewardsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *MsgCalculateInterestAndRewardsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -3110,7 +2913,7 @@ func (m *MsgFundModuleAccounts) Size() (n int) { return n } -func (m *MsgCalculateBorrowInterest) Size() (n int) { +func (m *MsgCalculateInterestAndRewards) Size() (n int) { if m == nil { return 0 } @@ -3120,25 +2923,6 @@ func (m *MsgCalculateBorrowInterest) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - if m.BorrowId != 0 { - n += 1 + sovTx(uint64(m.BorrowId)) - } - return n -} - -func (m *MsgCalculateLendRewards) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Lender) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - if m.LendId != 0 { - n += 1 + sovTx(uint64(m.LendId)) - } return n } @@ -3241,16 +3025,7 @@ func (m *MsgFundModuleAccountsResponse) Size() (n int) { return n } -func (m *MsgCalculateBorrowInterestResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func (m *MsgCalculateLendRewardsResponse) Size() (n int) { +func (m *MsgCalculateInterestAndRewardsResponse) Size() (n int) { if m == nil { return 0 } @@ -4925,7 +4700,7 @@ func (m *MsgFundModuleAccounts) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgCalculateBorrowInterest) Unmarshal(dAtA []byte) error { +func (m *MsgCalculateInterestAndRewards) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -4948,10 +4723,10 @@ func (m *MsgCalculateBorrowInterest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgCalculateBorrowInterest: wiretype end group for non-group") + return fmt.Errorf("proto: MsgCalculateInterestAndRewards: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCalculateBorrowInterest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgCalculateInterestAndRewards: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -4986,126 +4761,6 @@ func (m *MsgCalculateBorrowInterest) Unmarshal(dAtA []byte) error { } m.Borrower = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field BorrowId", wireType) - } - m.BorrowId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.BorrowId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgCalculateLendRewards) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgCalculateLendRewards: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCalculateLendRewards: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Lender", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Lender = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field LendId", wireType) - } - m.LendId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.LendId |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) @@ -5677,57 +5332,7 @@ func (m *MsgFundModuleAccountsResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgCalculateBorrowInterestResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgCalculateBorrowInterestResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCalculateBorrowInterestResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgCalculateLendRewardsResponse) Unmarshal(dAtA []byte) error { +func (m *MsgCalculateInterestAndRewardsResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -5750,10 +5355,10 @@ func (m *MsgCalculateLendRewardsResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: MsgCalculateLendRewardsResponse: wiretype end group for non-group") + return fmt.Errorf("proto: MsgCalculateInterestAndRewardsResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: MsgCalculateLendRewardsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: MsgCalculateInterestAndRewardsResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: From 8d46edca32b65c3d3627e15a0c2062aa9b72f089 Mon Sep 17 00:00:00 2001 From: Pratik Date: Thu, 20 Oct 2022 16:06:14 +0530 Subject: [PATCH 05/13] Adding MsgCalculateInterestAndRewards txn --- x/lend/client/cli/tx.go | 4 ++-- x/lend/types/keys.go | 25 ++++++++++++------------- x/lend/types/tx.go | 4 +++- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/x/lend/client/cli/tx.go b/x/lend/client/cli/tx.go index a248c5969..b48622cbb 100644 --- a/x/lend/client/cli/tx.go +++ b/x/lend/client/cli/tx.go @@ -991,8 +991,8 @@ func NewAddAuctionParams(clientCtx client.Context, txf tx.Factory, fs *flag.Flag func txCalculateInterestAndRewards() *cobra.Command { cmd := &cobra.Command{ - Use: "calculate-borrow-interest", - Short: " calculate borrow interest for a borrow position", + Use: "calculate-interest-rewards", + Short: " calculate interest and rewards for a user", Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) error { ctx, err := client.GetClientTxContext(cmd) diff --git a/x/lend/types/keys.go b/x/lend/types/keys.go index 11c0aa6a5..5b3277813 100644 --- a/x/lend/types/keys.go +++ b/x/lend/types/keys.go @@ -29,19 +29,18 @@ const ( ) var ( - TypeLendAssetRequest = ModuleName + ":lend" - TypeWithdrawAssetRequest = ModuleName + ":withdraw" - TypeBorrowAssetRequest = ModuleName + ":borrow" - TypeRepayAssetRequest = ModuleName + ":repay" - TypeFundModuleAccountRequest = ModuleName + ":fund-module" - TypeDepositAssetRequest = ModuleName + ":deposit" - TypeCloseLendAssetRequest = ModuleName + ":close-lend" - TypeCloseBorrowAssetRequest = ModuleName + ":close-borrow" - TypeDrawAssetRequest = ModuleName + ":draw" - TypeDepositBorrowAssetRequest = ModuleName + ":deposit-borrow" - TypeBorrowAlternateAssetRequest = ModuleName + ":borrow-alternate" - TypeCalculateBorrowInterestRequest = ModuleName + ":calculate-borrow-interest" - TypeCalculateLendRewardsRequest = ModuleName + ":calculate-lend-rewards" + TypeLendAssetRequest = ModuleName + ":lend" + TypeWithdrawAssetRequest = ModuleName + ":withdraw" + TypeBorrowAssetRequest = ModuleName + ":borrow" + TypeRepayAssetRequest = ModuleName + ":repay" + TypeFundModuleAccountRequest = ModuleName + ":fund-module" + TypeDepositAssetRequest = ModuleName + ":deposit" + TypeCloseLendAssetRequest = ModuleName + ":close-lend" + TypeCloseBorrowAssetRequest = ModuleName + ":close-borrow" + TypeDrawAssetRequest = ModuleName + ":draw" + TypeDepositBorrowAssetRequest = ModuleName + ":deposit-borrow" + TypeBorrowAlternateAssetRequest = ModuleName + ":borrow-alternate" + TypeCalculateInterestAndRewardsRequest = ModuleName + ":calculate-interest-rewards" ) var ( diff --git a/x/lend/types/tx.go b/x/lend/types/tx.go index d1bc0add7..2a2f3b045 100644 --- a/x/lend/types/tx.go +++ b/x/lend/types/tx.go @@ -482,7 +482,9 @@ func NewMsgCalculateInterestAndRewards(borrower string) *MsgCalculateInterestAnd } func (msg MsgCalculateInterestAndRewards) Route() string { return ModuleName } -func (msg MsgCalculateInterestAndRewards) Type() string { return TypeCalculateLendRewardsRequest } +func (msg MsgCalculateInterestAndRewards) Type() string { + return TypeCalculateInterestAndRewardsRequest +} func (msg *MsgCalculateInterestAndRewards) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.GetBorrower()) From ccf37ab2c6da5ad1217da5b425865fd3c7fdd781 Mon Sep 17 00:00:00 2001 From: Dheeraj Dubey Date: Thu, 20 Oct 2022 19:11:43 +0530 Subject: [PATCH 06/13] lint fix --- app/wasm/queries.go | 1 - app/wasm/wasm.go | 4 ++-- x/auction/keeper/dutch_test.go | 16 ++++++++-------- x/lend/keeper/iter.go | 2 +- x/vault/keeper/keeper_test.go | 1 - 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/wasm/queries.go b/app/wasm/queries.go index 811e180ac..9b908edbd 100644 --- a/app/wasm/queries.go +++ b/app/wasm/queries.go @@ -39,7 +39,6 @@ func NewQueryPlugin( vaultKeeper *vaultKeeper.Keeper, lendKeeper *lendKeeper.Keeper, liquidityKeeper *liquidityKeeper.Keeper, - ) *QueryPlugin { return &QueryPlugin{ assetKeeper: assetKeeper, diff --git a/app/wasm/wasm.go b/app/wasm/wasm.go index dbc5d9017..6f8bcc5ef 100644 --- a/app/wasm/wasm.go +++ b/app/wasm/wasm.go @@ -8,13 +8,13 @@ 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" vaultKeeper "github.com/comdex-official/comdex/x/vault/keeper" - lendKeeper "github.com/comdex-official/comdex/x/lend/keeper" - liquidityKeeper "github.com/comdex-official/comdex/x/liquidity/keeper" ) func RegisterCustomPlugins( diff --git a/x/auction/keeper/dutch_test.go b/x/auction/keeper/dutch_test.go index 570982478..fd6fac8d1 100644 --- a/x/auction/keeper/dutch_test.go +++ b/x/auction/keeper/dutch_test.go @@ -167,16 +167,16 @@ func (s *KeeperTestSuite) AddAppAsset() { GovTimeInSeconds: 900, GenesisToken: []assetTypes.MintGenesisToken{ { - AssetId: 3, - GenesisSupply :genesisSupply, - IsGovToken: true, - Recipient: userAddress1, + AssetId: 3, + GenesisSupply: genesisSupply, + IsGovToken: true, + Recipient: userAddress1, }, { - AssetId: 2, - GenesisSupply :genesisSupply, - IsGovToken: true, - Recipient: userAddress1, + AssetId: 2, + GenesisSupply: genesisSupply, + IsGovToken: true, + Recipient: userAddress1, }, }, } diff --git a/x/lend/keeper/iter.go b/x/lend/keeper/iter.go index 4a7a4130c..ac932602c 100644 --- a/x/lend/keeper/iter.go +++ b/x/lend/keeper/iter.go @@ -67,7 +67,7 @@ func (k Keeper) IterateLends(ctx sdk.Context, ID uint64) (sdk.Dec, error) { } // subtracting newInterestPerInteraction from global lend and interest accumulated poolAssetLBMappingData.TotalInterestAccumulated = poolAssetLBMappingData.TotalInterestAccumulated.Sub(newInterestPerInteraction) - //poolAssetLBMappingData.TotalLend = poolAssetLBMappingData.TotalLend.Sub(newInterestPerInteraction) + // poolAssetLBMappingData.TotalLend = poolAssetLBMappingData.TotalLend.Sub(newInterestPerInteraction) k.SetAssetStatsByPoolIDAndAssetID(ctx, poolAssetLBMappingData) k.SetLend(ctx, lend) } diff --git a/x/vault/keeper/keeper_test.go b/x/vault/keeper/keeper_test.go index 75661b594..708ee95bd 100644 --- a/x/vault/keeper/keeper_test.go +++ b/x/vault/keeper/keeper_test.go @@ -130,7 +130,6 @@ func (s *KeeperTestSuite) CreateNewAsset(name, denom string, price uint64) uint6 _, err = s.app.MarketKeeper.GetLatestPrice(s.ctx, assetID) s.Suite.NoError(err) - return assetID } From 40c5d0219faf92096ad44b993314dc2647b8c24c Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Fri, 21 Oct 2022 09:09:03 +0530 Subject: [PATCH 07/13] testcase fix, band integration in esm, twa batch size added in proposal --- proto/comdex/bandoracle/v1beta1/tx.proto | 1 + x/auction/abci.go | 14 --- x/auction/keeper/debt_test.go | 7 +- x/auction/keeper/dutch.go | 2 +- x/auction/keeper/dutch_test.go | 15 ++-- x/auction/keeper/surplus.go | 3 +- x/auction/keeper/surplus_test.go | 24 ++++-- x/bandoracle/client/cli/tx.go | 10 ++- x/bandoracle/keeper/oracle.go | 1 + x/bandoracle/types/fetch_price.go | 5 ++ x/bandoracle/types/gov.go | 4 + x/bandoracle/types/tx.pb.go | 105 +++++++++++++++-------- x/esm/keeper/esm.go | 60 ++++++++----- x/liquidation/keeper/liquidate_vaults.go | 5 +- x/market/abci.go | 3 +- x/market/keeper/oracle.go | 18 ++-- 16 files changed, 176 insertions(+), 101 deletions(-) diff --git a/proto/comdex/bandoracle/v1beta1/tx.proto b/proto/comdex/bandoracle/v1beta1/tx.proto index ac5002b42..aa7c53fee 100644 --- a/proto/comdex/bandoracle/v1beta1/tx.proto +++ b/proto/comdex/bandoracle/v1beta1/tx.proto @@ -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 { diff --git a/x/auction/abci.go b/x/auction/abci.go index 2b3f2e694..9a5a7c336 100644 --- a/x/auction/abci.go +++ b/x/auction/abci.go @@ -33,20 +33,6 @@ func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { } } - // 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 := k.GetApps(ctx) if appsFound { diff --git a/x/auction/keeper/debt_test.go b/x/auction/keeper/debt_test.go index 42e0b9b52..e8c50b8c8 100644 --- a/x/auction/keeper/debt_test.go +++ b/x/auction/keeper/debt_test.go @@ -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) @@ -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) @@ -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) } diff --git a/x/auction/keeper/dutch.go b/x/auction/keeper/dutch.go index 138900882..fc839c082 100644 --- a/x/auction/keeper/dutch.go +++ b/x/auction/keeper/dutch.go @@ -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) } diff --git a/x/auction/keeper/dutch_test.go b/x/auction/keeper/dutch_test.go index 570982478..02dc71377 100644 --- a/x/auction/keeper/dutch_test.go +++ b/x/auction/keeper/dutch_test.go @@ -6,6 +6,7 @@ import ( "github.com/comdex-official/comdex/x/auction" auctionKeeper "github.com/comdex-official/comdex/x/auction/keeper" auctionTypes "github.com/comdex-official/comdex/x/auction/types" + collectorTypes "github.com/comdex-official/comdex/x/collector/types" liquidationTypes "github.com/comdex-official/comdex/x/liquidation/types" markettypes "github.com/comdex-official/comdex/x/market/types" vaultKeeper1 "github.com/comdex-official/comdex/x/vault/keeper" @@ -44,7 +45,7 @@ func (s *KeeperTestSuite) AddPairAndExtendedPairVault1() { PairName: "CMDX-B", AssetOutOraclePrice: true, AssetOutPrice: 1000000, - MinUsdValueLeft: 1000000000000, + MinUsdValueLeft: 1000000, }, 1, 2, @@ -514,10 +515,10 @@ func (s *KeeperTestSuite) TestCloseDutchAuction() { func (s *KeeperTestSuite) TestCloseDutchAuctionWithProtocolLoss() { userAddress1 := "cosmos1q7q90qsl9g0gl2zz0njxwv2a649yqrtyxtnv3v" - s.AddAppAsset() - s.AddPairAndExtendedPairVault1() - s.LiquidateVaults1() - s.AddAuctionParams() + // s.AddAppAsset() + // s.AddPairAndExtendedPairVault1() + // s.LiquidateVaults1() + // s.AddAuctionParams() s.TestDutchBid() k, liquidationKeeper, ctx := &s.keeper, &s.liquidationKeeper, &s.ctx // k, ctx := &s.keeper, &s.ctx @@ -542,9 +543,9 @@ func (s *KeeperTestSuite) TestCloseDutchAuctionWithProtocolLoss() { err = k.RestartDutch(*ctx) s.Require().NoError(err)*/ - err1 := k.FundModule(*ctx, "auction", "ucmst", 10000000) + err1 := k.FundModule(*ctx, auctionTypes.ModuleName, "ucmst", 10000000) s.Require().NoError(err1) - err = k.SendCoinsFromModuleToModule(*ctx, "auction", "collector", sdk.NewCoins(sdk.NewCoin("ucmst", sdk.NewInt(10000000)))) + err = k.SendCoinsFromModuleToModule(*ctx, auctionTypes.ModuleName, collectorTypes.ModuleName, sdk.NewCoins(sdk.NewCoin("ucmst", sdk.NewInt(10000000)))) s.Require().NoError(err) err = s.app.CollectorKeeper.SetNetFeeCollectedData(*ctx, 1, 2, sdk.NewInt(10000000)) diff --git a/x/auction/keeper/surplus.go b/x/auction/keeper/surplus.go index 92b7df3ca..0b82b6493 100644 --- a/x/auction/keeper/surplus.go +++ b/x/auction/keeper/surplus.go @@ -1,6 +1,7 @@ package keeper import ( + "fmt" "time" esmtypes "github.com/comdex-official/comdex/x/esm/types" @@ -66,7 +67,6 @@ func (k Keeper) checkStatusOfNetFeesCollectedAndStartSurplusAuction(ctx sdk.Cont if NetFeeCollectedData.NetFeesCollected.GTE(sdk.NewIntFromUint64(collector.SurplusThreshold + collector.LotSize)) { // START SURPLUS AUCTION . WITH COLLECTOR ASSET ID AS token given to user of lot size and secondary asset as received from user and burnt , bid factor // calculate inflow token amount - assetBuyID := collector.SecondaryAssetId assetSellID := collector.CollectorAssetId @@ -82,6 +82,7 @@ func (k Keeper) checkStatusOfNetFeesCollectedAndStartSurplusAuction(ctx sdk.Cont _, err := k.GetAmountFromCollector(ctx, appID, assetID, sellToken.Amount) if err != nil { + fmt.Println("insidervgrerbg") return status, err } diff --git a/x/auction/keeper/surplus_test.go b/x/auction/keeper/surplus_test.go index c8280558e..f5b119fbc 100644 --- a/x/auction/keeper/surplus_test.go +++ b/x/auction/keeper/surplus_test.go @@ -8,6 +8,8 @@ import ( "github.com/comdex-official/comdex/app/wasm/bindings" auctionKeeper "github.com/comdex-official/comdex/x/auction/keeper" 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" tokenmintKeeper1 "github.com/comdex-official/comdex/x/tokenmint/keeper" tokenminttypes "github.com/comdex-official/comdex/x/tokenmint/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -56,22 +58,32 @@ func (s *KeeperTestSuite) TestSurplusActivator() { s.AddPairAndExtendedPairVault1() s.AddAuctionParams() s.WasmSetCollectorLookupTableAndAuctionControlForSurplus() - s.WasmUpdateCollectorLookupTable(1000, 19800, 100, 300) k, collectorKeeper, ctx := &s.keeper, &s.collectorKeeper, &s.ctx - auction.BeginBlocker(*ctx, s.keeper) - // s.Require().NoError(err) - appId := uint64(1) auctionMappingId := uint64(1) auctionId := uint64(1) - surplusAuction, err := k.GetSurplusAuction(*ctx, appId, auctionMappingId, auctionId) + err := k.SetNetFeeCollectedData(*ctx, uint64(1), 2, sdk.NewIntFromUint64(100000000)) s.Require().NoError(err) - collectorLookUp, found := collectorKeeper.GetCollectorLookupTable(*ctx, 1, 2) s.Require().True(found) + auctionMapData, auctionMappingFound := k.GetAuctionMappingForApp(*ctx, appId, collectorLookUp.CollectorAssetId) + s.Require().True(auctionMappingFound) + klswData := esmtypes.KillSwitchParams{ + AppId: 1, + BreakerEnable: false, + } + err2 := k.FundModule(*ctx, auctionTypes.ModuleName, "ucmst", 1000000000) + s.Require().NoError(err2) + err3 := k.SendCoinsFromModuleToModule(*ctx, auctionTypes.ModuleName, collectorTypes.ModuleName, sdk.NewCoins(sdk.NewCoin("ucmst", sdk.NewIntFromUint64(1000000000)))) + s.Require().NoError(err3) + err1 := k.SurplusActivator(*ctx, auctionMapData, klswData, false) + s.Require().NoError(err1) + + surplusAuction, err := k.GetSurplusAuction(*ctx, appId, auctionMappingId, auctionId) + s.Require().NoError(err) netFees, found := k.GetNetFeeCollectedData(*ctx, uint64(1), 2) s.Require().True(found) diff --git a/x/bandoracle/client/cli/tx.go b/x/bandoracle/client/cli/tx.go index 6506bb125..e84c6a63e 100644 --- a/x/bandoracle/client/cli/tx.go +++ b/x/bandoracle/client/cli/tx.go @@ -15,8 +15,8 @@ import ( func NewCmdSubmitFetchPriceProposal() *cobra.Command { cmd := &cobra.Command{ - Use: "fetch-price [market-script-id] [requested-validator-count] [sufficient-validator-count]", - Args: cobra.ExactArgs(3), + Use: "fetch-price [market-script-id] [requested-validator-count] [sufficient-validator-count] [twa-batch-size]", + Args: cobra.ExactArgs(4), Short: "Make a new FetchPrice query request via an existing BandChain market script", RunE: func(cmd *cobra.Command, args []string) error { // retrieve the market script id. @@ -38,6 +38,11 @@ func NewCmdSubmitFetchPriceProposal() *cobra.Command { return err } + twaBatch, err := strconv.ParseUint(args[3], 10, 64) + if err != nil { + return err + } + channel, err := cmd.Flags().GetString(flagChannel) if err != nil { return err @@ -97,6 +102,7 @@ func NewCmdSubmitFetchPriceProposal() *cobra.Command { feeLimit, prepareGas, executeGas, + twaBatch, ) title, err := cmd.Flags().GetString(cli.FlagTitle) diff --git a/x/bandoracle/keeper/oracle.go b/x/bandoracle/keeper/oracle.go index 6d459f7ca..a4b1627e4 100644 --- a/x/bandoracle/keeper/oracle.go +++ b/x/bandoracle/keeper/oracle.go @@ -119,6 +119,7 @@ func (k Keeper) SetFetchPriceMsg(ctx sdk.Context, msg types.MsgFetchPriceData) { msg.FeeLimit, msg.PrepareGas, msg.ExecuteGas, + msg.TwaBatchSize, ) value = k.cdc.MustMarshal(v) ) diff --git a/x/bandoracle/types/fetch_price.go b/x/bandoracle/types/fetch_price.go index 19f80f1cb..d8488c0b2 100644 --- a/x/bandoracle/types/fetch_price.go +++ b/x/bandoracle/types/fetch_price.go @@ -37,6 +37,7 @@ func NewMsgFetchPriceData( feeLimit sdk.Coins, prepareGas uint64, executeGas uint64, + twaBatch uint64, ) *MsgFetchPriceData { return &MsgFetchPriceData{ ClientID: FetchPriceClientIDKey, @@ -49,6 +50,7 @@ func NewMsgFetchPriceData( FeeLimit: feeLimit, PrepareGas: prepareGas, ExecuteGas: executeGas, + TwaBatchSize: twaBatch, } } @@ -86,6 +88,9 @@ func (m *MsgFetchPriceData) ValidateBasic() error { if m.SourceChannel == "" { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid source channel") } + if m.TwaBatchSize == 0 { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid batch size") + } return nil } diff --git a/x/bandoracle/types/gov.go b/x/bandoracle/types/gov.go index 628c6162a..93b0ba925 100644 --- a/x/bandoracle/types/gov.go +++ b/x/bandoracle/types/gov.go @@ -2,6 +2,7 @@ package types import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) const ( @@ -29,6 +30,9 @@ func (p *FetchPriceProposal) ProposalType() string { return ProposalFetchPrice } func (p *FetchPriceProposal) ValidateBasic() error { err := govtypes.ValidateAbstract(p) + if p.FetchPrice.TwaBatchSize == 0 { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid batch size") + } if err != nil { return err } diff --git a/x/bandoracle/types/tx.pb.go b/x/bandoracle/types/tx.pb.go index c223c313a..8baf125cc 100644 --- a/x/bandoracle/types/tx.pb.go +++ b/x/bandoracle/types/tx.pb.go @@ -37,6 +37,7 @@ type MsgFetchPriceData struct { PrepareGas uint64 `protobuf:"varint,9,opt,name=prepare_gas,json=prepareGas,proto3" json:"prepare_gas,omitempty"` ExecuteGas uint64 `protobuf:"varint,10,opt,name=execute_gas,json=executeGas,proto3" json:"execute_gas,omitempty"` ClientID string `protobuf:"bytes,11,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` + TwaBatchSize uint64 `protobuf:"varint,12,opt,name=twa_batch_size,json=twaBatchSize,proto3" json:"twa_batch_size,omitempty"` } func (m *MsgFetchPriceData) Reset() { *m = MsgFetchPriceData{} } @@ -149,6 +150,13 @@ func (m *MsgFetchPriceData) GetClientID() string { return "" } +func (m *MsgFetchPriceData) GetTwaBatchSize() uint64 { + if m != nil { + return m.TwaBatchSize + } + return 0 +} + type MsgFetchPriceDataResponse struct { } @@ -195,40 +203,42 @@ func init() { } var fileDescriptor_e41ad8b392d8eeff = []byte{ - // 519 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xdd, 0x6e, 0xd3, 0x30, - 0x14, 0xc7, 0x1b, 0x56, 0xb6, 0xd4, 0x85, 0x0a, 0x22, 0x24, 0xd2, 0x4d, 0x4a, 0xaa, 0x4a, 0x48, - 0x45, 0xa8, 0x09, 0x1b, 0x5c, 0x71, 0xd9, 0x56, 0xa0, 0x8a, 0x4f, 0x85, 0x0b, 0x24, 0x6e, 0x22, - 0xd7, 0x39, 0x6d, 0xad, 0x26, 0x76, 0xb0, 0x5d, 0xd4, 0xbe, 0x05, 0xcf, 0xb1, 0x27, 0xd9, 0xe5, - 0x2e, 0xb9, 0x2a, 0xa8, 0x7d, 0x03, 0x9e, 0x00, 0xd9, 0x0e, 0x2b, 0x03, 0xed, 0x2a, 0xf1, 0xff, - 0xff, 0x3b, 0x3e, 0x3e, 0x1f, 0xa8, 0x4b, 0x78, 0x91, 0xc1, 0x2a, 0x9e, 0x60, 0x96, 0x71, 0x81, - 0x49, 0x0e, 0xf1, 0xd7, 0xd3, 0x09, 0x28, 0x7c, 0x1a, 0xab, 0x55, 0x54, 0x0a, 0xae, 0xb8, 0xd7, - 0xb6, 0x4c, 0xb4, 0x67, 0xa2, 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e, 0x6b, 0xb3, 0xa0, - 0xac, 0x32, 0x0f, 0xad, 0x59, 0x50, 0x66, 0xcd, 0x39, 0x6a, 0x4c, 0x01, 0xd2, 0x9c, 0x16, 0x54, - 0xf9, 0x47, 0x9d, 0x83, 0x5e, 0xf3, 0xac, 0x1d, 0xd9, 0xa9, 0x44, 0x7a, 0x2a, 0x57, 0xf9, 0x87, - 0x9c, 0xb2, 0xc1, 0xd3, 0x8b, 0x4d, 0x58, 0x3b, 0xff, 0x11, 0xf6, 0x66, 0x54, 0xcd, 0x97, 0x13, - 0xfd, 0xdc, 0xb8, 0x1a, 0xa1, 0xfd, 0xf4, 0x65, 0xb6, 0x88, 0xd5, 0xba, 0x04, 0x69, 0x02, 0x64, - 0xe2, 0x4e, 0x01, 0xde, 0xe8, 0xcb, 0xbd, 0x10, 0x35, 0x05, 0x7c, 0x59, 0x82, 0x54, 0xe9, 0x02, - 0xd6, 0xbe, 0x6b, 0x5a, 0x82, 0x2a, 0xe9, 0x35, 0xac, 0x35, 0x50, 0x0a, 0x28, 0xb1, 0x80, 0x74, - 0x86, 0xa5, 0xdf, 0x30, 0x2f, 0x45, 0x95, 0xf4, 0x0a, 0x4b, 0x0d, 0xc0, 0x0a, 0xc8, 0x52, 0x59, - 0x00, 0x59, 0xa0, 0x92, 0x34, 0xf0, 0x18, 0x35, 0x48, 0x4e, 0x81, 0x99, 0x51, 0x36, 0x75, 0x82, - 0xc1, 0x9d, 0xed, 0x26, 0x74, 0x87, 0x46, 0x1c, 0x8f, 0x12, 0xd7, 0xda, 0xe3, 0xac, 0x7b, 0x82, - 0xda, 0xff, 0xed, 0x4a, 0x02, 0xb2, 0xe4, 0x4c, 0xc2, 0xe0, 0xdd, 0xc5, 0x36, 0x70, 0x2e, 0xb7, - 0x81, 0xf3, 0x73, 0x1b, 0x38, 0xdf, 0x76, 0x41, 0xed, 0x72, 0x17, 0xd4, 0xbe, 0xef, 0x82, 0xda, - 0xe7, 0xe7, 0xd7, 0x0a, 0xd7, 0xb3, 0xea, 0xf3, 0xe9, 0x94, 0x12, 0x8a, 0xf3, 0xea, 0x1c, 0x5f, - 0xdb, 0x56, 0xd3, 0x8a, 0xc9, 0xa1, 0x59, 0xd0, 0x67, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x1b, - 0xde, 0x17, 0xd2, 0x44, 0x03, 0x00, 0x00, + // 545 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xcf, 0x6e, 0xd3, 0x40, + 0x10, 0xc6, 0x63, 0x5a, 0x5a, 0x67, 0x13, 0x22, 0xb0, 0x90, 0x70, 0x5a, 0xc9, 0x8e, 0x22, 0x90, + 0x82, 0x50, 0x6c, 0x5a, 0x38, 0x71, 0x4c, 0x22, 0x50, 0xc4, 0x5f, 0xb9, 0x07, 0x24, 0x2e, 0xd6, + 0x7a, 0x3d, 0x49, 0x56, 0xb1, 0xbd, 0xc6, 0xbb, 0xa1, 0x49, 0x9f, 0x82, 0xe7, 0xe0, 0x49, 0x7a, + 0xcc, 0x91, 0x53, 0x40, 0xce, 0x1b, 0xf0, 0x04, 0x68, 0x77, 0x4d, 0x43, 0x41, 0x3d, 0xd9, 0xfb, + 0x7d, 0xbf, 0x99, 0xd9, 0x9d, 0x19, 0xd4, 0x25, 0x2c, 0x8d, 0x61, 0xe9, 0x47, 0x38, 0x8b, 0x59, + 0x81, 0x49, 0x02, 0xfe, 0x97, 0x93, 0x08, 0x04, 0x3e, 0xf1, 0xc5, 0xd2, 0xcb, 0x0b, 0x26, 0x98, + 0xd5, 0xd6, 0x8c, 0xb7, 0x63, 0xbc, 0x8a, 0x39, 0xba, 0x3f, 0x65, 0x53, 0xa6, 0x28, 0x5f, 0xfe, + 0xe9, 0x80, 0x23, 0x87, 0x30, 0x9e, 0x32, 0xee, 0x47, 0x98, 0xef, 0xd2, 0x11, 0x46, 0xb3, 0xca, + 0x7f, 0x72, 0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x72, + 0xa2, 0x7d, 0x36, 0x99, 0x50, 0x42, 0x71, 0x52, 0x9d, 0xfd, 0x6b, 0x3b, 0xad, 0x1a, 0x16, 0x1d, + 0xa8, 0x35, 0x7e, 0xf6, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x72, 0x6f, 0x20, 0x23, 0x6a, 0x03, 0x00, + 0x00, } func (m *MsgFetchPriceData) Marshal() (dAtA []byte, err error) { @@ -251,6 +261,11 @@ func (m *MsgFetchPriceData) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.TwaBatchSize != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.TwaBatchSize)) + i-- + dAtA[i] = 0x60 + } if len(m.ClientID) > 0 { i -= len(m.ClientID) copy(dAtA[i:], m.ClientID) @@ -414,6 +429,9 @@ func (m *MsgFetchPriceData) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + if m.TwaBatchSize != 0 { + n += 1 + sovTx(uint64(m.TwaBatchSize)) + } return n } @@ -754,6 +772,25 @@ func (m *MsgFetchPriceData) Unmarshal(dAtA []byte) error { } m.ClientID = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 12: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TwaBatchSize", wireType) + } + m.TwaBatchSize = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TwaBatchSize |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/x/esm/keeper/esm.go b/x/esm/keeper/esm.go index 82a06fb57..cb2a3b8c3 100644 --- a/x/esm/keeper/esm.go +++ b/x/esm/keeper/esm.go @@ -330,9 +330,10 @@ func (k Keeper) SetUpCollateralRedemptionForVault(ctx sdk.Context, appID uint64) itemc.AssetID = assetInData.Id itemc.Amount = data.AmountIn - x := sdk.NewIntFromUint64(rateIn).Mul(data.AmountIn) - coolOffData.CollateralTotalAmount = sdk.NewDecFromInt(x) - itemc.Share = sdk.NewDecFromInt(x).Quo(coolOffData.CollateralTotalAmount) + x, _ := k.CalcDollarValueOfToken(ctx, assetInData.Id, rateIn, data.AmountIn) + // x := sdk.NewIntFromUint64(rateIn).Mul(data.AmountIn) + coolOffData.CollateralTotalAmount = x + itemc.Share = x.Quo(coolOffData.CollateralTotalAmount) err := k.bank.SendCoinsFromModuleToModule(ctx, vaulttypes.ModuleName, types.ModuleName, sdk.NewCoins(sdk.NewCoin(assetInData.Denom, data.AmountIn))) if err != nil { @@ -342,9 +343,10 @@ func (k Keeper) SetUpCollateralRedemptionForVault(ctx sdk.Context, appID uint64) itemd.AssetID = assetOutData.Id itemd.Amount = data.AmountOut - y := sdk.NewIntFromUint64(rateOut).Mul(data.AmountOut) - coolOffData.DebtTotalAmount = sdk.NewDecFromInt(y) - itemd.Share = sdk.NewDecFromInt(y).Quo(coolOffData.DebtTotalAmount) + y, _ := k.CalcDollarValueOfToken(ctx, assetOutData.Id, rateOut, data.AmountOut) + // y := sdk.NewIntFromUint64(rateOut).Mul(data.AmountOut) + coolOffData.DebtTotalAmount = y + itemd.Share = y.Quo(coolOffData.DebtTotalAmount) itemd.DebtTokenWorth = coolOffData.CollateralTotalAmount.Mul(itemd.Share).Quo(sdk.NewDecFromInt(itemd.Amount)) @@ -357,9 +359,10 @@ func (k Keeper) SetUpCollateralRedemptionForVault(ctx sdk.Context, appID uint64) if indata.AssetID == assetInData.Id { count++ indata.Amount = indata.Amount.Add(data.AmountIn) - x := sdk.NewIntFromUint64(rateIn).Mul(data.AmountIn) - coolOffData.CollateralTotalAmount = coolOffData.CollateralTotalAmount.Add(sdk.NewDecFromInt(x)) - indata.Share = sdk.NewDecFromInt(x).Quo(coolOffData.CollateralTotalAmount) + x, _ := k.CalcDollarValueOfToken(ctx, assetInData.Id, rateIn, data.AmountIn) + // x := sdk.NewIntFromUint64(rateIn).Mul(data.AmountIn) + coolOffData.CollateralTotalAmount = coolOffData.CollateralTotalAmount.Add(x) + indata.Share = x.Quo(coolOffData.CollateralTotalAmount) err := k.bank.SendCoinsFromModuleToModule(ctx, vaulttypes.ModuleName, types.ModuleName, sdk.NewCoins(sdk.NewCoin(assetInData.Denom, data.AmountIn))) if err != nil { return err @@ -374,9 +377,10 @@ func (k Keeper) SetUpCollateralRedemptionForVault(ctx sdk.Context, appID uint64) item.AssetID = assetInData.Id item.Amount = data.AmountIn - x := sdk.NewIntFromUint64(rateIn).Mul(data.AmountIn) - coolOffData.CollateralTotalAmount = coolOffData.CollateralTotalAmount.Add(sdk.NewDecFromInt(x)) - item.Share = sdk.NewDecFromInt(x).Quo(coolOffData.CollateralTotalAmount) + x, _ := k.CalcDollarValueOfToken(ctx, assetInData.Id, rateIn, data.AmountIn) + // x := sdk.NewIntFromUint64(rateIn).Mul(data.AmountIn) + coolOffData.CollateralTotalAmount = coolOffData.CollateralTotalAmount.Add(x) + item.Share = x.Quo(coolOffData.CollateralTotalAmount) err := k.bank.SendCoinsFromModuleToModule(ctx, vaulttypes.ModuleName, types.ModuleName, sdk.NewCoins(sdk.NewCoin(assetInData.Denom, data.AmountIn))) if err != nil { @@ -389,9 +393,10 @@ func (k Keeper) SetUpCollateralRedemptionForVault(ctx sdk.Context, appID uint64) if indatadebt.AssetID == assetOutData.Id { count++ indatadebt.Amount = indatadebt.Amount.Add(data.AmountOut) - y := sdk.NewIntFromUint64(rateOut).Mul(data.AmountOut) - coolOffData.DebtTotalAmount = coolOffData.DebtTotalAmount.Add(sdk.NewDecFromInt(y)) - indatadebt.Share = sdk.NewDecFromInt(y).Quo(coolOffData.DebtTotalAmount) + y, _ := k.CalcDollarValueOfToken(ctx, assetOutData.Id, rateOut, data.AmountOut) + // y := sdk.NewIntFromUint64(rateOut).Mul(data.AmountOut) + coolOffData.DebtTotalAmount = coolOffData.DebtTotalAmount.Add(y) + indatadebt.Share = y.Quo(coolOffData.DebtTotalAmount) indatadebt.DebtTokenWorth = coolOffData.CollateralTotalAmount.Mul(indatadebt.Share).Quo(sdk.NewDecFromInt(indatadebt.Amount)) coolOffData.DebtAsset = append(coolOffData.DebtAsset[:i], coolOffData.DebtAsset[i+1:]...) coolOffData.DebtAsset = append(coolOffData.DebtAsset, indatadebt) @@ -403,9 +408,10 @@ func (k Keeper) SetUpCollateralRedemptionForVault(ctx sdk.Context, appID uint64) itemx.AssetID = assetOutData.Id itemx.Amount = data.AmountOut - z := sdk.NewIntFromUint64(rateOut).Mul(data.AmountOut) - coolOffData.DebtTotalAmount = coolOffData.DebtTotalAmount.Add(sdk.NewDecFromInt(z)) - itemx.Share = sdk.NewDecFromInt(z).Quo(coolOffData.DebtTotalAmount) + z, _ := k.CalcDollarValueOfToken(ctx, assetOutData.Id, rateOut, data.AmountOut) + // z := sdk.NewIntFromUint64(rateOut).Mul(data.AmountOut) + coolOffData.DebtTotalAmount = coolOffData.DebtTotalAmount.Add(z) + itemx.Share = z.Quo(coolOffData.DebtTotalAmount) itemx.DebtTokenWorth = coolOffData.CollateralTotalAmount.Mul(itemx.Share).Quo(sdk.NewDecFromInt(itemx.Amount)) coolOffData.DebtAsset = append(coolOffData.DebtAsset, itemx) } @@ -574,9 +580,10 @@ func (k Keeper) SetUpCollateralRedemptionForStableVault(ctx sdk.Context, appID u } } indatanet.Amount = indatanet.Amount.Sub(data.NetFeesCollected) - x := sdk.NewIntFromUint64(rateOut).Mul(indatanet.Amount) - coolOffData.DebtTotalAmount = coolOffData.DebtTotalAmount.Sub(sdk.NewDecFromInt(x)) - indatanet.Share = sdk.NewDecFromInt(x).Quo(coolOffData.DebtTotalAmount) + x, _ := k.CalcDollarValueOfToken(ctx, data.AssetId, rateOut, indatanet.Amount) + // x := sdk.NewIntFromUint64(rateOut).Mul(indatanet.Amount) + coolOffData.DebtTotalAmount = coolOffData.DebtTotalAmount.Sub(x) + indatanet.Share = x.Quo(coolOffData.DebtTotalAmount) indatanet.DebtTokenWorth = coolOffData.CollateralTotalAmount.Mul(indatanet.Share).Quo(sdk.NewDecFromInt(indatanet.Amount)) coolOffData.DebtAsset = append(coolOffData.DebtAsset[:i], coolOffData.DebtAsset[i+1:]...) coolOffData.DebtAsset = append(coolOffData.DebtAsset, indatanet) @@ -637,3 +644,14 @@ func (k Keeper) GetSnapshotOfPrices(ctx sdk.Context, appID, assetID uint64) (pri k.cdc.MustUnmarshal(value, &id) return id.GetValue(), true } + +func (k Keeper) CalcDollarValueOfToken(ctx sdk.Context, id uint64, rate uint64, amt sdk.Int) (price sdk.Dec, err error) { + asset, found := k.GetAsset(ctx, id) + if !found { + return sdk.ZeroDec(), assettypes.ErrorAssetDoesNotExist + } + + numerator := sdk.NewDecFromInt(amt).Mul(sdk.NewDecFromInt(sdk.NewIntFromUint64(rate))) + denominator := sdk.NewDecFromInt(sdk.NewIntFromUint64(uint64(asset.Decimals))) + return numerator.Quo(denominator), nil +} diff --git a/x/liquidation/keeper/liquidate_vaults.go b/x/liquidation/keeper/liquidate_vaults.go index be025c711..c2ab054d3 100644 --- a/x/liquidation/keeper/liquidate_vaults.go +++ b/x/liquidation/keeper/liquidate_vaults.go @@ -21,6 +21,7 @@ func (k Keeper) LiquidateVaults(ctx sdk.Context) error { } klwsParams, _ := k.GetKillSwitchData(ctx, appIds[i]) if klwsParams.BreakerEnable || status { + ctx.Logger().Info("Kill Switch Or ESM is enabled") continue } @@ -77,7 +78,7 @@ func (k Keeper) LiquidateVaults(ctx sdk.Context) error { if err != nil { continue } - err = k.CreateLockedVault(ctx, vault, totalIn, collateralizationRatio, appIds[i], totalOut, totalFees) + err = k.CreateLockedVault(ctx, vault, totalIn, collateralizationRatio, appIds[i], totalFees) if err != nil { continue } @@ -95,7 +96,7 @@ func (k Keeper) LiquidateVaults(ctx sdk.Context) error { return nil } -func (k Keeper) CreateLockedVault(ctx sdk.Context, vault vaulttypes.Vault, totalIn sdk.Dec, collateralizationRatio sdk.Dec, appID uint64, totalOut, totalFees sdk.Int) error { +func (k Keeper) CreateLockedVault(ctx sdk.Context, vault vaulttypes.Vault, totalIn sdk.Dec, collateralizationRatio sdk.Dec, appID uint64, totalFees sdk.Int) error { lockedVaultID := k.GetLockedVaultID(ctx) value := types.LockedVault{ diff --git a/x/market/abci.go b/x/market/abci.go index 1751e54f7..ad49bca1c 100644 --- a/x/market/abci.go +++ b/x/market/abci.go @@ -22,13 +22,14 @@ func BeginBlocker(ctx sdk.Context, _ abci.RequestBeginBlock, k keeper.Keeper) { id := k.GetLastFetchPriceID(ctx) data, _ := k.GetFetchPriceResult(ctx, bandoraclemoduletypes.OracleRequestID(id)) scriptID := k.GetFetchPriceMsg(ctx).OracleScriptID + twaBatch := k.GetFetchPriceMsg(ctx).TwaBatchSize index := -1 length := len(data.Rates) for _, asset := range assets { if asset.IsOraclePriceRequired && data.Rates != nil { index = index + 1 if length > index { - k.UpdatePriceList(ctx, asset.Id, scriptID, data.Rates[index]) + k.UpdatePriceList(ctx, asset.Id, scriptID, data.Rates[index], twaBatch) } } } diff --git a/x/market/keeper/oracle.go b/x/market/keeper/oracle.go index 28e0e2164..bb12b0a6f 100644 --- a/x/market/keeper/oracle.go +++ b/x/market/keeper/oracle.go @@ -53,7 +53,7 @@ func (k Keeper) GetAllTwa(ctx sdk.Context) (twa []types.TimeWeightedAverage) { return twa } -func (k Keeper) UpdatePriceList(ctx sdk.Context, id, scriptID, rate uint64) { +func (k Keeper) UpdatePriceList(ctx sdk.Context, id, scriptID, rate, twaBatch uint64) { twa, found := k.GetTwa(ctx, id) if !found { twa.AssetID = id @@ -67,30 +67,30 @@ func (k Keeper) UpdatePriceList(ctx sdk.Context, id, scriptID, rate uint64) { if twa.IsPriceActive { twa.PriceValue[twa.CurrentIndex] = rate twa.CurrentIndex = twa.CurrentIndex + 1 - twa.Twa = k.CalculateTwa(ctx, twa) - if twa.CurrentIndex == 30 { + twa.Twa = k.CalculateTwa(ctx, twa, twaBatch) + if twa.CurrentIndex == twaBatch { twa.CurrentIndex = 0 } k.SetTwa(ctx, twa) } else { twa.PriceValue = append(twa.PriceValue, rate) twa.CurrentIndex = twa.CurrentIndex + 1 - if twa.CurrentIndex == 30 { + if twa.CurrentIndex == twaBatch { twa.IsPriceActive = true twa.CurrentIndex = 0 - twa.Twa = k.CalculateTwa(ctx, twa) + twa.Twa = k.CalculateTwa(ctx, twa, twaBatch) } k.SetTwa(ctx, twa) } } } -func (k Keeper) CalculateTwa(ctx sdk.Context, twa types.TimeWeightedAverage) uint64 { +func (k Keeper) CalculateTwa(ctx sdk.Context, twa types.TimeWeightedAverage, twaBatch uint64) uint64 { var sum uint64 - for _, price := range twa.PriceValue { - sum += price + for i := 0; i < int(twaBatch); i++ { + sum = sum + twa.PriceValue[i] } - twa.Twa = sum / 30 + twa.Twa = sum / twaBatch return twa.Twa } From de93a92b954461d0f3c282935e7b59f87cc1cfce Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Fri, 21 Oct 2022 10:17:55 +0530 Subject: [PATCH 08/13] alias issue fixed --- x/auction/keeper/debt_test.go | 14 +++++++------- x/auction/keeper/dutch_test.go | 22 +++++++++++----------- x/auction/keeper/surplus_test.go | 14 +++++++------- x/collector/keeper/collector_test.go | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/x/auction/keeper/debt_test.go b/x/auction/keeper/debt_test.go index e8c50b8c8..ba21ab5c8 100644 --- a/x/auction/keeper/debt_test.go +++ b/x/auction/keeper/debt_test.go @@ -171,7 +171,7 @@ func (s *KeeperTestSuite) TestDebtActivatorBetweenThreshholdAndLotsize() { k, ctx := &s.keeper, &s.ctx - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) // s.Require().NoError(err) appId := uint64(1) @@ -193,7 +193,7 @@ func (s *KeeperTestSuite) TestDebtActivator() { k, collectorKeeper, ctx := &s.keeper, &s.collectorKeeper, &s.ctx - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) appId := uint64(1) auctionMappingId := uint64(2) @@ -202,17 +202,17 @@ func (s *KeeperTestSuite) TestDebtActivator() { collectorLookUp, found := collectorKeeper.GetCollectorLookupTable(*ctx, 1, 2) s.Require().True(found) - auctionMapData, auctionMappingFound := k.GetAuctionMappingForApp(*ctx, appId, collectorLookUp.CollectorAssetId) + auctionMapData, auctionMappingFound := collectorKeeper.GetAuctionMappingForApp(*ctx, appId, collectorLookUp.CollectorAssetId) s.Require().True(auctionMappingFound) klswData := esmtypes.KillSwitchParams{ 1, false, } - err := k.SetNetFeeCollectedData(*ctx, uint64(1), 2, sdk.NewIntFromUint64(4700000)) + err := collectorKeeper.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) + netFees, found := collectorKeeper.GetNetFeeCollectedData(*ctx, uint64(1), 2) s.Require().True(found) debtAuction, err := k.GetDebtAuction(*ctx, appId, auctionMappingId, auctionId) @@ -233,7 +233,7 @@ func (s *KeeperTestSuite) TestDebtActivator() { // Test restart debt auction s.advanceseconds(301) - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) s.Require().NoError(err) debtAuction1, err := k.GetDebtAuction(*ctx, appId, auctionMappingId, auctionId) s.Require().NoError(err) @@ -465,7 +465,7 @@ func (s *KeeperTestSuite) TestCloseDebtAuction() { s.Require().NoError(err) s.advanceseconds(int64(tc.seconds)) - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) s.Require().NoError(err) afterHarborBalance, err := s.getBalance(winnerAddress, "uharbor") diff --git a/x/auction/keeper/dutch_test.go b/x/auction/keeper/dutch_test.go index 6e859373c..8c8fc0fe4 100644 --- a/x/auction/keeper/dutch_test.go +++ b/x/auction/keeper/dutch_test.go @@ -226,12 +226,12 @@ func (s *KeeperTestSuite) AddAppAsset() { } func (s *KeeperTestSuite) LiquidateVaults1() { - liquidationKeeper, ctx := &s.liquidationKeeper, &s.ctx + liquidationKeeper, vaultKeeper, ctx := &s.liquidationKeeper, &s.vaultKeeper, &s.ctx s.CreateVault() currentVaultsCount := 2 s.Require().Equal(s.GetVaultCount(), currentVaultsCount) s.Require().Equal(s.GetVaultCountForExtendedPairIDbyAppID(uint64(1), 1), currentVaultsCount) - beforeVault, found := liquidationKeeper.GetVault(*ctx, 1) + beforeVault, found := vaultKeeper.GetVault(*ctx, 1) s.Require().True(found) // Liquidation shouldn't happen as price not changed @@ -293,7 +293,7 @@ func (s *KeeperTestSuite) TestDutchActivator() { s.AddAuctionParams() k, liquidationKeeper, ctx := &s.keeper, &s.liquidationKeeper, &s.ctx - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) /*s.Require().NoError(err) err = k.RestartDutch(*ctx) s.Require().NoError(err)*/ @@ -418,7 +418,7 @@ func (s *KeeperTestSuite) TestDutchBid() { } { s.Run(tc.name, func() { s.advanceseconds(tc.advanceSeconds) - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) /*s.Require().NoError(err) err = k.RestartDutch(*ctx) s.Require().NoError(err)*/ @@ -433,7 +433,7 @@ func (s *KeeperTestSuite) TestDutchBid() { _, err = server.MsgPlaceDutchBid(sdk.WrapSDKContext(*ctx), &tc.msg) if tc.isErrorExpected { s.advanceseconds(301 - tc.advanceSeconds) - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) /*s.Require().NoError(err1) err2 := k.RestartDutch(*ctx) s.Require().NoError(err2) @@ -538,14 +538,14 @@ func (s *KeeperTestSuite) TestCloseDutchAuctionWithProtocolLoss() { s.Require().NoError(err) s.advanceseconds(250) - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) /*s.Require().NoError(err1) err = k.RestartDutch(*ctx) s.Require().NoError(err)*/ err1 := k.FundModule(*ctx, auctionTypes.ModuleName, "ucmst", 10000000) s.Require().NoError(err1) - err = k.SendCoinsFromModuleToModule(*ctx, auctionTypes.ModuleName, collectorTypes.ModuleName, sdk.NewCoins(sdk.NewCoin("ucmst", sdk.NewInt(10000000)))) + err = s.app.BankKeeper.SendCoinsFromModuleToModule(*ctx, auctionTypes.ModuleName, collectorTypes.ModuleName, sdk.NewCoins(sdk.NewCoin("ucmst", sdk.NewInt(10000000)))) s.Require().NoError(err) err = s.app.CollectorKeeper.SetNetFeeCollectedData(*ctx, 1, 2, sdk.NewInt(10000000)) @@ -596,7 +596,7 @@ func (s *KeeperTestSuite) TestRestartDutchAuction() { s.advanceseconds(300) startPrice := dutchAuction.OutflowTokenCurrentPrice - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) /*s.Require().NoError(err) err = k.RestartDutch(*ctx) s.Require().NoError(err)*/ @@ -611,9 +611,9 @@ func (s *KeeperTestSuite) TestRestartDutchAuction() { beforeAuction, err := k.GetDutchAuction(*ctx, appId, auctionMappingId, auctionId) s.Require().NoError(err) - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) s.Require().NoError(err) - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) s.Require().NoError(err) afterAuction, err := k.GetDutchAuction(*ctx, appId, auctionMappingId, auctionId) @@ -640,7 +640,7 @@ func (s *KeeperTestSuite) TestRestartDutchAuction() { // half the auction duration s.advanceseconds(150) - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) /*s.Require().NoError(err) err = k.RestartDutch(*ctx) s.Require().NoError(err)*/ diff --git a/x/auction/keeper/surplus_test.go b/x/auction/keeper/surplus_test.go index f5b119fbc..3f0873691 100644 --- a/x/auction/keeper/surplus_test.go +++ b/x/auction/keeper/surplus_test.go @@ -41,7 +41,7 @@ func (s *KeeperTestSuite) TestSurplusActivatorBetweenThreshholdAndLotsize() { k, ctx := &s.keeper, &s.ctx - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) // err := k.SurplusActivator(*ctx) // s.Require().NoError(err) @@ -65,11 +65,11 @@ func (s *KeeperTestSuite) TestSurplusActivator() { auctionMappingId := uint64(1) auctionId := uint64(1) - err := k.SetNetFeeCollectedData(*ctx, uint64(1), 2, sdk.NewIntFromUint64(100000000)) + err := collectorKeeper.SetNetFeeCollectedData(*ctx, uint64(1), 2, sdk.NewIntFromUint64(100000000)) s.Require().NoError(err) collectorLookUp, found := collectorKeeper.GetCollectorLookupTable(*ctx, 1, 2) s.Require().True(found) - auctionMapData, auctionMappingFound := k.GetAuctionMappingForApp(*ctx, appId, collectorLookUp.CollectorAssetId) + auctionMapData, auctionMappingFound := collectorKeeper.GetAuctionMappingForApp(*ctx, appId, collectorLookUp.CollectorAssetId) s.Require().True(auctionMappingFound) klswData := esmtypes.KillSwitchParams{ AppId: 1, @@ -77,7 +77,7 @@ func (s *KeeperTestSuite) TestSurplusActivator() { } err2 := k.FundModule(*ctx, auctionTypes.ModuleName, "ucmst", 1000000000) s.Require().NoError(err2) - err3 := k.SendCoinsFromModuleToModule(*ctx, auctionTypes.ModuleName, collectorTypes.ModuleName, sdk.NewCoins(sdk.NewCoin("ucmst", sdk.NewIntFromUint64(1000000000)))) + err3 := s.app.BankKeeper.SendCoinsFromModuleToModule(*ctx, auctionTypes.ModuleName, collectorTypes.ModuleName, sdk.NewCoins(sdk.NewCoin("ucmst", sdk.NewIntFromUint64(1000000000)))) s.Require().NoError(err3) err1 := k.SurplusActivator(*ctx, auctionMapData, klswData, false) s.Require().NoError(err1) @@ -85,7 +85,7 @@ func (s *KeeperTestSuite) TestSurplusActivator() { surplusAuction, err := k.GetSurplusAuction(*ctx, appId, auctionMappingId, auctionId) s.Require().NoError(err) - netFees, found := k.GetNetFeeCollectedData(*ctx, uint64(1), 2) + netFees, found := collectorKeeper.GetNetFeeCollectedData(*ctx, uint64(1), 2) s.Require().True(found) s.Require().Equal(surplusAuction.AppId, appId) @@ -103,7 +103,7 @@ func (s *KeeperTestSuite) TestSurplusActivator() { // Test restart surplus auction s.advanceseconds(301) - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) s.Require().NoError(err) surplusAuction1, err := k.GetSurplusAuction(*ctx, appId, auctionMappingId, auctionId) s.Require().NoError(err) @@ -315,7 +315,7 @@ func (s *KeeperTestSuite) TestCloseSurplusAuction() { s.Require().NoError(err) s.advanceseconds(int64(tc.seconds)) - auction.BeginBlocker(*ctx, s.keeper) + auction.BeginBlocker(*ctx, s.app.AuctionKeeper, s.app.AssetKeeper, s.app.CollectorKeeper, s.app.EsmKeeper) s.Require().NoError(err) afterCmstBalance, err := s.getBalance(winnerAddress, "ucmst") diff --git a/x/collector/keeper/collector_test.go b/x/collector/keeper/collector_test.go index b538d2118..d2c145223 100644 --- a/x/collector/keeper/collector_test.go +++ b/x/collector/keeper/collector_test.go @@ -394,7 +394,7 @@ func (s *KeeperTestSuite) TestGetAmountFromCollector() { s.Run(tc.name, func() { err := auctionKeeper.FundModule(*ctx, "auctionV1", tc.denom, tc.FundAmount) s.Require().NoError(err) - err = auctionKeeper.SendCoinsFromModuleToModule(*ctx, "auctionV1", "collectorV1", sdk.NewCoins(sdk.NewCoin(tc.denom, sdk.NewIntFromUint64(tc.FundAmount)))) + err = s.app.BankKeeper.SendCoinsFromModuleToModule(*ctx, "auctionV1", "collectorV1", sdk.NewCoins(sdk.NewCoin(tc.denom, sdk.NewIntFromUint64(tc.FundAmount)))) s.Require().NoError(err) beforeCollectorBalance := auctionKeeper.GetModuleAccountBalance(*ctx, "collectorV1", tc.denom) returnAmount, err := collectorKeeper.GetAmountFromCollector(*ctx, tc.appID, tc.assetID, tc.GetAmount) From aac2332c9b8af685b1864df4859f2064ec8bb49c Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Fri, 21 Oct 2022 11:23:36 +0530 Subject: [PATCH 09/13] auction genesis changes, delete added for TWA --- proto/comdex/auction/v1beta1/genesis.proto | 1 + x/auction/genesis.go | 6 ++ x/auction/types/genesis.go | 5 +- x/auction/types/genesis.pb.go | 90 +++++++++++++++------- x/bandoracle/expected/keeper.go | 6 +- x/bandoracle/keeper/oracle.go | 4 + x/market/keeper/oracle.go | 63 +++------------ 7 files changed, 92 insertions(+), 83 deletions(-) diff --git a/proto/comdex/auction/v1beta1/genesis.proto b/proto/comdex/auction/v1beta1/genesis.proto index a13242c64..d860e12a8 100644 --- a/proto/comdex/auction/v1beta1/genesis.proto +++ b/proto/comdex/auction/v1beta1/genesis.proto @@ -20,4 +20,5 @@ message GenesisState { repeated AuctionParams auctionParams = 5 [ (gogoproto.moretags) = "yaml:\"auctionParams\"", (gogoproto.nullable) = false ]; Params params = 6 [(gogoproto.nullable) = false]; + uint64 UserBiddingID = 7 ; } diff --git a/x/auction/genesis.go b/x/auction/genesis.go index 5585e4ff6..5ff4bc559 100644 --- a/x/auction/genesis.go +++ b/x/auction/genesis.go @@ -9,6 +9,7 @@ import ( func InitGenesis(ctx sdk.Context, k keeper.Keeper, state *types.GenesisState) { k.SetParams(ctx, state.Params) + var auctionID uint64 for _, item := range state.SurplusAuction { err := k.SetSurplusAuction(ctx, item) @@ -29,8 +30,12 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, state *types.GenesisState) { if err != nil { return } + auctionID = item.AuctionId } + k.SetAuctionID(ctx, auctionID) + k.SetUserBiddingID(ctx, state.UserBiddingID) + for _, item := range state.ProtocolStatistics { k.SetProtocolStatistics(ctx, item.AppId, item.AssetId, sdk.Int(item.Loss)) } @@ -48,5 +53,6 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { k.GetAllProtocolStat(ctx), k.GetAllAuctionParams(ctx), k.GetParams(ctx), + k.GetUserBiddingID(ctx), ) } diff --git a/x/auction/types/genesis.go b/x/auction/types/genesis.go index e08f2569d..eb8b0a796 100644 --- a/x/auction/types/genesis.go +++ b/x/auction/types/genesis.go @@ -1,6 +1,6 @@ package types -func NewGenesisState(surplusAuction []SurplusAuction, debtAuction []DebtAuction, dutchAuction []DutchAuction, protocolStatistics []ProtocolStatistics, auctionParams []AuctionParams, params Params) *GenesisState { +func NewGenesisState(surplusAuction []SurplusAuction, debtAuction []DebtAuction, dutchAuction []DutchAuction, protocolStatistics []ProtocolStatistics, auctionParams []AuctionParams, params Params, userBiddingID uint64) *GenesisState { return &GenesisState{ SurplusAuction: surplusAuction, DebtAuction: debtAuction, @@ -8,10 +8,12 @@ func NewGenesisState(surplusAuction []SurplusAuction, debtAuction []DebtAuction, ProtocolStatistics: protocolStatistics, AuctionParams: auctionParams, Params: params, + UserBiddingID: userBiddingID, } } func DefaultGenesisState() *GenesisState { + var UserBiddingID uint64 return NewGenesisState( []SurplusAuction{}, []DebtAuction{}, @@ -19,6 +21,7 @@ func DefaultGenesisState() *GenesisState { []ProtocolStatistics{}, []AuctionParams{}, DefaultParams(), + UserBiddingID, ) } diff --git a/x/auction/types/genesis.pb.go b/x/auction/types/genesis.pb.go index d18c6b927..1d9e045a8 100644 --- a/x/auction/types/genesis.pb.go +++ b/x/auction/types/genesis.pb.go @@ -30,6 +30,7 @@ type GenesisState struct { ProtocolStatistics []ProtocolStatistics `protobuf:"bytes,4,rep,name=protocolStatistics,proto3" json:"protocolStatistics" yaml:"protocolStatistics"` AuctionParams []AuctionParams `protobuf:"bytes,5,rep,name=auctionParams,proto3" json:"auctionParams" yaml:"auctionParams"` Params Params `protobuf:"bytes,6,opt,name=params,proto3" json:"params"` + UserBiddingID uint64 `protobuf:"varint,7,opt,name=UserBiddingID,proto3" json:"UserBiddingID,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -107,6 +108,13 @@ func (m *GenesisState) GetParams() Params { return Params{} } +func (m *GenesisState) GetUserBiddingID() uint64 { + if m != nil { + return m.UserBiddingID + } + return 0 +} + func init() { proto.RegisterType((*GenesisState)(nil), "comdex.auction.v1beta1.GenesisState") } @@ -116,33 +124,34 @@ func init() { } var fileDescriptor_49088f171dd3086d = []byte{ - // 403 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x31, 0xcf, 0xd2, 0x40, - 0x18, 0x80, 0x5b, 0x41, 0x86, 0x03, 0x1d, 0x4e, 0x34, 0xb5, 0x6a, 0xc1, 0x02, 0x86, 0x98, 0xd8, - 0x06, 0xdc, 0x8c, 0x0b, 0x8d, 0x89, 0x83, 0x0b, 0x29, 0x9b, 0xdb, 0xb5, 0x3d, 0xca, 0x25, 0x2d, - 0xd7, 0xd0, 0xab, 0x91, 0xc1, 0xff, 0xe0, 0xcf, 0x62, 0x64, 0x74, 0x22, 0x06, 0x7e, 0xc0, 0x97, - 0x7c, 0xbf, 0xe0, 0x4b, 0xef, 0x8e, 0xd0, 0x7e, 0x70, 0x5b, 0x9b, 0x3e, 0xf7, 0x3c, 0xbd, 0x37, - 0x2f, 0x18, 0x86, 0x34, 0x8d, 0xf0, 0x6f, 0x17, 0x15, 0x21, 0x23, 0x74, 0xed, 0xfe, 0x9a, 0x04, - 0x98, 0xa1, 0x89, 0x1b, 0xe3, 0x35, 0xce, 0x49, 0xee, 0x64, 0x1b, 0xca, 0x28, 0x7c, 0x25, 0x28, - 0x47, 0x52, 0x8e, 0xa4, 0xcc, 0x6e, 0x4c, 0x63, 0xca, 0x11, 0xb7, 0x7c, 0x12, 0xb4, 0x39, 0x50, - 0x38, 0x33, 0xb4, 0x41, 0xa9, 0x54, 0x9a, 0xaa, 0xf0, 0x39, 0x21, 0xa8, 0x91, 0x82, 0x0a, 0x48, - 0x14, 0x91, 0x75, 0x2c, 0x65, 0xf6, 0x5d, 0x13, 0x74, 0xbe, 0x8b, 0x3f, 0x5e, 0x30, 0xc4, 0x30, - 0x4c, 0xc1, 0xf3, 0xbc, 0xd8, 0x64, 0x49, 0x91, 0xcf, 0xc4, 0x49, 0x43, 0xef, 0x37, 0xc6, 0xed, - 0xe9, 0x07, 0xe7, 0xf6, 0x4d, 0x9c, 0x45, 0x8d, 0xf6, 0xde, 0xed, 0x0e, 0x3d, 0xed, 0xfe, 0xd0, - 0x7b, 0xb9, 0x45, 0x69, 0xf2, 0xc5, 0xae, 0xbb, 0x6c, 0xff, 0x91, 0x1c, 0x22, 0xd0, 0x8e, 0x70, - 0xc0, 0xce, 0xad, 0x27, 0xbc, 0x35, 0x50, 0xb5, 0xbe, 0x5d, 0x50, 0xcf, 0x94, 0x21, 0x28, 0x42, - 0x15, 0x8b, 0xed, 0x57, 0x9d, 0x10, 0x83, 0x4e, 0x54, 0xb0, 0x70, 0x75, 0x6e, 0x34, 0x78, 0x63, - 0xa8, 0x6c, 0x54, 0x58, 0xef, 0x8d, 0x8c, 0xbc, 0x90, 0x91, 0xca, 0x37, 0xdb, 0xaf, 0x69, 0xe1, - 0x1f, 0x00, 0xf9, 0x48, 0x43, 0x9a, 0x94, 0x93, 0x24, 0x39, 0x23, 0x61, 0x6e, 0x34, 0x79, 0xec, - 0xa3, 0x2a, 0x36, 0xbf, 0x3a, 0xe1, 0xbd, 0x97, 0xc9, 0xd7, 0x22, 0x79, 0xed, 0xb4, 0xfd, 0x1b, - 0x21, 0x48, 0xc0, 0x33, 0x29, 0x9f, 0xf3, 0x65, 0x31, 0x9e, 0xf2, 0xf2, 0x48, 0x55, 0x9e, 0x55, - 0x61, 0xef, 0xad, 0x8c, 0x76, 0x45, 0xb4, 0x66, 0xb2, 0xfd, 0xba, 0x19, 0x7e, 0x05, 0x2d, 0xb1, - 0x90, 0x46, 0xab, 0xaf, 0x8f, 0xdb, 0x53, 0x4b, 0x79, 0x3b, 0x21, 0x6f, 0x96, 0x72, 0x5f, 0x9e, - 0xf1, 0x7e, 0xec, 0x8e, 0x96, 0xbe, 0x3f, 0x5a, 0xfa, 0xff, 0xa3, 0xa5, 0xff, 0x3d, 0x59, 0xda, - 0xfe, 0x64, 0x69, 0xff, 0x4e, 0x96, 0xf6, 0x73, 0x12, 0x13, 0xb6, 0x2a, 0x82, 0xd2, 0xe6, 0x0a, - 0xe3, 0x27, 0xba, 0x5c, 0x92, 0x90, 0xa0, 0x44, 0xbe, 0xbb, 0x97, 0x7d, 0x66, 0xdb, 0x0c, 0xe7, - 0x41, 0x8b, 0x4f, 0xe2, 0xf3, 0x43, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2d, 0x9a, 0x13, 0x71, 0x8d, - 0x03, 0x00, 0x00, + // 425 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xb1, 0x8e, 0xd3, 0x30, + 0x18, 0x80, 0x13, 0xae, 0x57, 0x24, 0xf7, 0x8e, 0xc1, 0x1c, 0x28, 0x04, 0xc8, 0x95, 0x5c, 0x0f, + 0x55, 0x48, 0x24, 0xea, 0xb1, 0x21, 0x96, 0x8b, 0x2a, 0x21, 0xc4, 0x52, 0xa5, 0x62, 0x61, 0x73, + 0x12, 0x37, 0xb5, 0x94, 0xd4, 0x51, 0xec, 0x20, 0x3a, 0xf0, 0x0e, 0x2c, 0xbc, 0x53, 0xc7, 0x8e, + 0x4c, 0x15, 0x6a, 0xdf, 0x80, 0x27, 0x40, 0xb1, 0x5d, 0x35, 0xa1, 0xf5, 0xd6, 0x26, 0x9f, 0xbf, + 0x2f, 0xfe, 0xf5, 0x83, 0x41, 0x4c, 0xf3, 0x04, 0x7f, 0xf7, 0x51, 0x15, 0x73, 0x42, 0x17, 0xfe, + 0xb7, 0x51, 0x84, 0x39, 0x1a, 0xf9, 0x29, 0x5e, 0x60, 0x46, 0x98, 0x57, 0x94, 0x94, 0x53, 0xf8, + 0x54, 0x52, 0x9e, 0xa2, 0x3c, 0x45, 0xd9, 0x57, 0x29, 0x4d, 0xa9, 0x40, 0xfc, 0xfa, 0x97, 0xa4, + 0xed, 0x1b, 0x8d, 0xb3, 0x40, 0x25, 0xca, 0x95, 0xd2, 0xd6, 0x85, 0xf7, 0x09, 0x49, 0xdd, 0x6a, + 0xa8, 0x88, 0x24, 0x09, 0x59, 0xa4, 0x4a, 0xe6, 0xfe, 0x3a, 0x07, 0x17, 0x1f, 0xe5, 0x17, 0x4f, + 0x39, 0xe2, 0x18, 0xe6, 0xe0, 0x11, 0xab, 0xca, 0x22, 0xab, 0xd8, 0xbd, 0x3c, 0x69, 0x99, 0xfd, + 0xb3, 0x61, 0xef, 0xee, 0xb5, 0x77, 0xfa, 0x26, 0xde, 0xb4, 0x45, 0x07, 0x2f, 0x57, 0x9b, 0x6b, + 0xe3, 0xef, 0xe6, 0xfa, 0xc9, 0x12, 0xe5, 0xd9, 0x7b, 0xb7, 0xed, 0x72, 0xc3, 0xff, 0xe4, 0x10, + 0x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d9, 0x7d, 0x4b, 0x67, 0x33, 0x12, 0x13, 0x94, 0xa9, 0xff, + 0xfe, 0x61, 0xeb, 0xf9, 0xb2, 0xc0, 0x2c, 0xea, 0x8a, 0x79, 0xbd, 0xfb, 0x17, 0x00, 0x00, 0xff, + 0xff, 0x51, 0x21, 0x0b, 0xb7, 0xb3, 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -165,6 +174,11 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.UserBiddingID != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.UserBiddingID)) + i-- + dAtA[i] = 0x38 + } { size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -297,6 +311,9 @@ func (m *GenesisState) Size() (n int) { } l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) + if m.UserBiddingID != 0 { + n += 1 + sovGenesis(uint64(m.UserBiddingID)) + } return n } @@ -538,6 +555,25 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field UserBiddingID", wireType) + } + m.UserBiddingID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.UserBiddingID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/bandoracle/expected/keeper.go b/x/bandoracle/expected/keeper.go index 2c8e134f5..6bc6a4396 100644 --- a/x/bandoracle/expected/keeper.go +++ b/x/bandoracle/expected/keeper.go @@ -7,9 +7,13 @@ import ( ibcexported "github.com/cosmos/ibc-go/v3/modules/core/exported" assettypes "github.com/comdex-official/comdex/x/asset/types" + marketttypes "github.com/comdex-official/comdex/x/market/types" ) -type MarketKeeper interface{} +type MarketKeeper interface { + DeleteTwaData(ctx sdk.Context, assetID uint64) + GetAllTwa(ctx sdk.Context) (twa []marketttypes.TimeWeightedAverage) +} type AssetKeeper interface { GetAssets(ctx sdk.Context, id uint64) (assettypes.Asset, bool) diff --git a/x/bandoracle/keeper/oracle.go b/x/bandoracle/keeper/oracle.go index 21238d09e..c4122da8b 100644 --- a/x/bandoracle/keeper/oracle.go +++ b/x/bandoracle/keeper/oracle.go @@ -158,6 +158,10 @@ func (k Keeper) AddFetchPriceRecords(ctx sdk.Context, price types.MsgFetchPriceD k.SetFetchPriceMsg(ctx, price) k.SetLastBlockHeight(ctx, ctx.BlockHeight()) k.SetCheckFlag(ctx, false) + allTwa := k.market.GetAllTwa(ctx) + for _, data := range allTwa { + k.market.DeleteTwaData(ctx, data.AssetID) + } return nil } diff --git a/x/market/keeper/oracle.go b/x/market/keeper/oracle.go index 2ad61b057..d8e2c7f27 100644 --- a/x/market/keeper/oracle.go +++ b/x/market/keeper/oracle.go @@ -53,6 +53,15 @@ func (k Keeper) GetAllTwa(ctx sdk.Context) (twa []types.TimeWeightedAverage) { return twa } +func (k Keeper) DeleteTwaData(ctx sdk.Context, assetID uint64) { + var ( + store = k.Store(ctx) + key = types.TwaKey(assetID) + ) + + store.Delete(key) +} + func (k Keeper) UpdatePriceList(ctx sdk.Context, id, scriptID, rate, twaBatch uint64) { twa, found := k.GetTwa(ctx, id) if !found { @@ -115,57 +124,3 @@ func (k Keeper) CalcAssetPrice(ctx sdk.Context, id uint64, amt sdk.Int) (price s } return sdk.ZeroDec(), types.ErrorPriceNotActive } - -// UNComment below and comment respective functions - -// func (k Keeper) CalcAssetPrice(ctx sdk.Context, id uint64, amt sdk.Int) (price sdk.Dec, err error) { -// asset, found := k.GetAsset(ctx, id) -// if !found { -// return sdk.ZeroDec(), assetTypes.ErrorAssetDoesNotExist -// } -// // twa, found := k.GetTwa(ctx, id) -// var rate uint64 -// if id == 1 { -// rate = 11632845 -// } -// if id == 2 { -// rate = 14053 -// } -// if id == 3 { -// rate = 1000000 -// } -// if id == 4 { -// rate = 2200000 -// } -// if id == 10 { -// rate = 1297119384 -// } -// if found { -// numerator := sdk.NewDecFromInt(amt).Mul(sdk.NewDecFromInt(sdk.NewIntFromUint64(rate))) -// denominator := sdk.NewDecFromInt(sdk.NewIntFromUint64(uint64(asset.Decimals))) -// return numerator.Quo(denominator), nil -// } -// return sdk.ZeroDec(), types.ErrorPriceNotActive -// } - -// func (k Keeper) GetTwa(ctx sdk.Context, id uint64) (twa types.TimeWeightedAverage, found bool) { -// twa.AssetID = id -// twa.IsPriceActive = true -// if id == 1 { -// twa.Twa = 11632845 -// } -// if id == 2 { -// twa.Twa = 140530 -// } -// if id == 3 { -// twa.Twa = 1000000 -// } -// if id == 4 { -// twa.Twa = 2200000 -// } -// if id == 10 { -// twa.Twa = 1297119384 -// } - -// return twa, true -// } From ac8beb30cb769b2668e411c5a15759f2cdd235bf Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Fri, 21 Oct 2022 13:58:36 +0530 Subject: [PATCH 10/13] wasm change, band check added --- app/wasm/queries.go | 6 +++++- x/bandoracle/abci.go | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/wasm/queries.go b/app/wasm/queries.go index 9b908edbd..46b9ddf9e 100644 --- a/app/wasm/queries.go +++ b/app/wasm/queries.go @@ -189,5 +189,9 @@ func (qp QueryPlugin) WasmCheckLiquidityProvided(ctx sdk.Context, appID, poolID return false } _, found = qp.liquidityKeeper.GetActiveFarmer(ctx, appID, poolID, farmer) - return found + _, found2 := qp.liquidityKeeper.GetQueuedFarmer(ctx, appID, poolID, farmer) + if found || found2 { + return true + } + return false } diff --git a/x/bandoracle/abci.go b/x/bandoracle/abci.go index b82143667..f0d91f68f 100644 --- a/x/bandoracle/abci.go +++ b/x/bandoracle/abci.go @@ -25,6 +25,7 @@ func BeginBlocker(ctx sdk.Context, _ abci.RequestBeginBlock, k keeper.Keeper) { } k.SetTempFetchPriceID(ctx, 0) k.SetCheckFlag(ctx, true) + k.SetOracleValidationResult(ctx, false) } else { msg := k.GetFetchPriceMsg(ctx) _, err := k.FetchPrice(ctx, msg) From a0007c87bdb41a15a501baca47c35e0612debc51 Mon Sep 17 00:00:00 2001 From: Dheeraj Dubey Date: Fri, 21 Oct 2022 14:11:05 +0530 Subject: [PATCH 11/13] resolve linting --- x/bandoracle/types/gov.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/bandoracle/types/gov.go b/x/bandoracle/types/gov.go index 93b0ba925..99a1bdc3d 100644 --- a/x/bandoracle/types/gov.go +++ b/x/bandoracle/types/gov.go @@ -1,8 +1,8 @@ package types import ( - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) const ( From e01065b48f671820fb80bb382418b16f8e46f888 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Fri, 21 Oct 2022 17:53:01 +0530 Subject: [PATCH 12/13] script updated --- scripts/comdex_local_setup/states.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/comdex_local_setup/states.py b/scripts/comdex_local_setup/states.py index 60a713151..916a4a2bd 100644 --- a/scripts/comdex_local_setup/states.py +++ b/scripts/comdex_local_setup/states.py @@ -411,7 +411,7 @@ "name": "Vesting Contract", "contractAddressKey": "vesting_contract", "contractLink": "https://github.com/comdex-official/test-wasm-artifacts/raw/main/token_vesting.wasm", - "contractPath": f"{COMDEX_DIR_PATH}/scripts/comdex_local_setup/token_vesting.wasm", + "contractPath": f"./token_vesting.wasm", "initator": {}, "formatKeys": [] }, @@ -419,7 +419,7 @@ "name": "Locking Contract", "contractAddressKey": "locking_contract", "contractLink": "https://github.com/comdex-official/test-wasm-artifacts/raw/main/locking_contract.wasm", - "contractPath": f"{COMDEX_DIR_PATH}/scripts/comdex_local_setup/locking_contract.wasm", + "contractPath": f"./locking_contract.wasm", "initator": { "t1": {"period": 500, "weight": "0.25"}, "t2": {"period": 1000, "weight": "0.50"}, @@ -434,9 +434,11 @@ "app_id": 1, "total_rewards": "10000000000000", "rewards_pending": "10000000000000", - "emmission_rate": "0.01", + "emission_rate": "0.01", "distributed_rewards": "0", }, + "min_lock_amount" : "200", + "admin":"comdex1rljg3wwgv6qezu3p05vxny9pwk3mdwl0ja407z" }, "formatKeys": ['vesting_contract'] }, @@ -444,7 +446,7 @@ "name": "Governance Contract", "contractAddressKey": "governance_contract", "contractLink": "https://github.com/comdex-official/test-wasm-artifacts/raw/main/governance.wasm", - "contractPath": f"{COMDEX_DIR_PATH}/scripts/comdex_local_setup/governance.wasm", + "contractPath": f"./governance.wasm", "initator": { "threshold": {"threshold_quorum": {"threshold": "0.50", "quorum": "0.33"}}, "target": "0.0.0.0:9090", From 4e9d6f1d356c9f76985e304b65776126cb793538 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Fri, 21 Oct 2022 18:02:10 +0530 Subject: [PATCH 13/13] admin changed --- scripts/comdex_local_setup/states.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/comdex_local_setup/states.py b/scripts/comdex_local_setup/states.py index 916a4a2bd..259446b51 100644 --- a/scripts/comdex_local_setup/states.py +++ b/scripts/comdex_local_setup/states.py @@ -438,7 +438,7 @@ "distributed_rewards": "0", }, "min_lock_amount" : "200", - "admin":"comdex1rljg3wwgv6qezu3p05vxny9pwk3mdwl0ja407z" + "admin":"comdex1qaqxur3esruxdmxtyhxl4safu88l273dfkplk2" }, "formatKeys": ['vesting_contract'] },