Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated msg bindings & vault refactor #194

Merged
merged 1 commit into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions app/wasm/bindings/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions app/wasm/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
20 changes: 11 additions & 9 deletions x/collector/keeper/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions x/liquidation/keeper/liquidate_vaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
36 changes: 9 additions & 27 deletions x/vault/keeper/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}