diff --git a/app/wasm/bindings/msg.go b/app/wasm/bindings/msg.go index b043c06b7..cfec016c9 100644 --- a/app/wasm/bindings/msg.go +++ b/app/wasm/bindings/msg.go @@ -59,10 +59,12 @@ type MsgSetCollectorLookupTable struct { } type MsgSetAuctionMappingForApp struct { - AppMappingId uint64 `json:"app_mapping_id"` - AssetId []uint64 `json:"asset_id"` - IsSurplusAuction []bool `json:"is_surplus_auction"` - IsDebtAuction []bool `json:"is_debt_auction"` + AppMappingId uint64 `json:"app_mapping_id"` + AssetId []uint64 `json:"asset_id"` + IsSurplusAuction []bool `json:"is_surplus_auction"` + IsDebtAuction []bool `json:"is_debt_auction"` + AssetOutOraclePrice []bool `json:"asset_out_oracle_price"` + AssetOutPrice []uint64 `json:"asset_out_price"` } type MsgUpdateLsrInPairsVault struct { @@ -74,8 +76,8 @@ type MsgUpdateLsrInPairsVault struct { LiquidationPenalty sdk.Dec `json:"liquidation_penalty"` DrawDownFee sdk.Dec `json:"draw_down_fee"` MinCr sdk.Dec `json:"min_cr"` - DebtCeiling uint64 `json:"debt_ceiling"` - DebtFloor uint64 `json:"debt_floor"` + DebtCeiling uint64 `json:"debt_ceiling"` + DebtFloor uint64 `json:"debt_floor"` } type MsgUpdateLsrInCollectorLookupTable struct { diff --git a/app/wasm/message_plugin.go b/app/wasm/message_plugin.go index 23ba8714c..752526512 100644 --- a/app/wasm/message_plugin.go +++ b/app/wasm/message_plugin.go @@ -204,7 +204,7 @@ func (m *CustomMessenger) SetAuctionMappingForApp(ctx sdk.Context, contractAddr func MsgSetAuctionMappingForApp(collectorKeeper collectorkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, a *bindings.MsgSetAuctionMappingForApp) error { - err := collectorKeeper.WasmSetAuctionMappingForApp(ctx, a.AppMappingId, a.AssetId, a.IsSurplusAuction, a.IsDebtAuction) + err := collectorKeeper.WasmSetAuctionMappingForApp(ctx, a.AppMappingId, a.AssetId, a.IsSurplusAuction, a.IsDebtAuction, a.AssetOutOraclePrice, a.AssetOutPrice) if err != nil { return err } @@ -221,8 +221,8 @@ func (m *CustomMessenger) UpdateLsrInPairsVault(ctx sdk.Context, contractAddr sd func MsgUpdateLsrInPairsVault(assetKeeper assetkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress, a *bindings.MsgUpdateLsrInPairsVault) error { - err := assetKeeper.WasmUpdateLsrInPairsVault(ctx, a.AppMappingId, a.ExtPairId, a.LiquidationRatio ,a.StabilityFee, a.ClosingFee, - a.LiquidationPenalty, a.DrawDownFee,a.MinCr, a.DebtCeiling, a.DebtFloor) + err := assetKeeper.WasmUpdateLsrInPairsVault(ctx, a.AppMappingId, a.ExtPairId, a.LiquidationRatio, a.StabilityFee, a.ClosingFee, + a.LiquidationPenalty, a.DrawDownFee, a.MinCr, a.DebtCeiling, a.DebtFloor) if err != nil { return err } diff --git a/x/collector/keeper/collector.go b/x/collector/keeper/collector.go index 520337dab..f66de96c3 100644 --- a/x/collector/keeper/collector.go +++ b/x/collector/keeper/collector.go @@ -530,16 +530,18 @@ func (k *Keeper) WasmSetCollectorLookupTableQuery(ctx sdk.Context, AppId, Collec return true, "" } -func (k *Keeper) WasmSetAuctionMappingForApp(ctx sdk.Context, AppId uint64, AssetId []uint64, IsSurplusAuction, IsDebtAuction []bool) error { +func (k *Keeper) WasmSetAuctionMappingForApp(ctx sdk.Context, AppId uint64, AssetId []uint64, IsSurplusAuction, IsDebtAuction, AssetOutOraclePrice []bool, AssetOutPrice []uint64) error { var collectorAuctionLookup types.CollectorAuctionLookupTable collectorAuctionLookup.AppId = AppId var AssetIdToAuctionLookups []types.AssetIdToAuctionLookupTable for i := range AssetId { AssetIdToAuctionLookup := types.AssetIdToAuctionLookupTable{ - AssetId: AssetId[i], - IsSurplusAuction: IsSurplusAuction[i], - IsDebtAuction: IsDebtAuction[i], + AssetId: AssetId[i], + IsSurplusAuction: IsSurplusAuction[i], + IsDebtAuction: IsDebtAuction[i], + AssetOutOraclePrice: AssetOutOraclePrice[i], + AssetOutPrice: AssetOutPrice[i], } AssetIdToAuctionLookups = append(AssetIdToAuctionLookups, AssetIdToAuctionLookup) } @@ -558,17 +560,17 @@ func (k *Keeper) WasmSetAuctionMappingForApp(ctx sdk.Context, AppId uint64, Asse func (k *Keeper) WasmSetAuctionMappingForAppQuery(ctx sdk.Context, AppId uint64) (bool, string) { _, _ = k.GetAppidToAssetCollectorMapping(ctx, AppId) - + return true, "" } func (k *Keeper) WasmUpdateLsrInCollectorLookupTable(ctx sdk.Context, appId, assetId uint64, lsr sdk.Dec) error { - + var Collector types.CollectorLookupTable accmLookup, _ := k.GetCollectorLookupTable(ctx, appId) - for _, data:= range accmLookup.AssetRateInfo{ - if data.CollectorAssetId == assetId{ + for _, data := range accmLookup.AssetRateInfo { + if data.CollectorAssetId == assetId { Collector.CollectorAssetId = assetId Collector.AppId = data.AppId Collector.BidFactor = data.BidFactor @@ -577,8 +579,8 @@ func (k *Keeper) WasmUpdateLsrInCollectorLookupTable(ctx sdk.Context, appId, ass Collector.LotSize = data.LotSize Collector.SecondaryAssetId = data.SecondaryAssetId Collector.DebtThreshold = data.DebtThreshold + } } -} k.SetCollectorLookupTable(ctx, Collector) // var ( // store = ctx.KVStore(k.storeKey) diff --git a/x/liquidation/keeper/liquidate_vaults.go b/x/liquidation/keeper/liquidate_vaults.go index 3bcb68fb0..7079fa1b1 100644 --- a/x/liquidation/keeper/liquidate_vaults.go +++ b/x/liquidation/keeper/liquidate_vaults.go @@ -247,12 +247,12 @@ func (k Keeper) UnliquidateLockedVaults(ctx sdk.Context) error { continue } - if lockedVault.AmountIn.IsZero() { + if lockedVault.AmountIn.IsZero() && lockedVault.AmountOut.IsZero() { err := k.CreateLockedVaultHistory(ctx, lockedVault) if err != nil { return err } - + k.UpdateUserVaultExtendedPairMapping(ctx, lockedVault.ExtendedPairId, lockedVault.Owner, lockedVault.AppMappingId) k.DeleteLockedVault(ctx, lockedVault.LockedVaultId) } @@ -263,7 +263,7 @@ func (k Keeper) UnliquidateLockedVaults(ctx sdk.Context) error { return err } - //k.DeleteAddressFromAppExtendedPairVaultMapping(ctx, lockedVault.ExtendedPairId, lockedVault.OriginalVaultId, lockedVault.AppMappingId) + k.UpdateUserVaultExtendedPairMapping(ctx, lockedVault.ExtendedPairId, lockedVault.Owner, lockedVault.AppMappingId) k.DeleteLockedVault(ctx, lockedVault.LockedVaultId) if err := k.SendCoinFromModuleToAccount(ctx, vaulttypes.ModuleName, userAddress, sdk.NewCoin(assetIn.Denom, lockedVault.AmountIn)); err != nil { @@ -290,7 +290,7 @@ func (k Keeper) UnliquidateLockedVaults(ctx sdk.Context) error { if err != nil { return err } - //k.DeleteAddressFromAppExtendedPairVaultMapping(ctx, lockedVault.ExtendedPairId, lockedVault.OriginalVaultId, lockedVault.AppMappingId) + k.UpdateUserVaultExtendedPairMapping(ctx, lockedVault.ExtendedPairId, lockedVault.Owner, lockedVault.AppMappingId) err = k.CreteNewVault(ctx, lockedVault.Owner, lockedVault.AppMappingId, lockedVault.ExtendedPairId, lockedVault.AmountIn, lockedVault.AmountOut) if err != nil { diff --git a/x/vault/keeper/vault.go b/x/vault/keeper/vault.go index 7bc36a8ca..1db1acb6a 100644 --- a/x/vault/keeper/vault.go +++ b/x/vault/keeper/vault.go @@ -495,39 +495,21 @@ func (k *Keeper) CreteNewVault(ctx sdk.Context, From string, AppMappingId uint64 k.UpdateAppExtendedPairVaultMappingDataOnMsgCreate(ctx, updated_counter, new_vault) - user_vault_extendedPair_mapping_data, user_exists := k.GetUserVaultExtendedPairMapping(ctx, From) - if !user_exists { - //UserData does not exists - //Create a new instance - var user_mapping_data types.UserVaultAssetMapping - var user_app_data types.VaultToAppMapping - var user_extendedPair_data types.ExtendedPairToVaultMapping - - user_extendedPair_data.ExtendedPairId = new_vault.ExtendedPairVaultID - user_extendedPair_data.VaultId = new_vault.Id - user_app_data.AppMappingId = appMapping.Id - user_app_data.UserExtendedPairVault = append(user_app_data.UserExtendedPairVault, &user_extendedPair_data) - user_mapping_data.Owner = From - user_mapping_data.UserVaultApp = append(user_mapping_data.UserVaultApp, &user_app_data) - - k.SetUserVaultExtendedPairMapping(ctx, user_mapping_data) - } else { - - //So only need to add the locker id with asset - var user_extendedPair_data types.ExtendedPairToVaultMapping - user_extendedPair_data.VaultId = new_vault.Id - user_extendedPair_data.ExtendedPairId = new_vault.ExtendedPairVaultID + userVaultExtendedpairMappingData, _ := k.GetUserVaultExtendedPairMapping(ctx, From) - for _, appData := range user_vault_extendedPair_mapping_data.UserVaultApp { - if appData.AppMappingId == appMapping.Id { + //So only need to add the locker id with asset + var userExtendedpairData types.ExtendedPairToVaultMapping + userExtendedpairData.VaultId = new_vault.Id + userExtendedpairData.ExtendedPairId = new_vault.ExtendedPairVaultID - appData.UserExtendedPairVault = append(appData.UserExtendedPairVault, &user_extendedPair_data) - } + for _, appData := range userVaultExtendedpairMappingData.UserVaultApp { + if appData.AppMappingId == appMapping.Id { + appData.UserExtendedPairVault = append(appData.UserExtendedPairVault, &userExtendedpairData) } - k.SetUserVaultExtendedPairMapping(ctx, user_vault_extendedPair_mapping_data) } + k.SetUserVaultExtendedPairMapping(ctx, userVaultExtendedpairMappingData) return nil }