Skip to content

Commit

Permalink
Merge pull request #270 from comdex-official/testdev_auction
Browse files Browse the repository at this point in the history
Burning binding, extra update params added for collector lookup
  • Loading branch information
dheerajkd30 authored Jun 21, 2022
2 parents 3c0a91e + 04aa887 commit aafa358
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 13 deletions.
18 changes: 15 additions & 3 deletions app/wasm/bindings/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ComdexMessages struct {
MsgWhitelistAppIdLiquidation *MsgWhitelistAppIdLiquidation `json:"msg_whitelist_app_id_liquidation,omitempty"`
MsgRemoveWhitelistAppIdLiquidation *MsgRemoveWhitelistAppIdLiquidation `json:"msg_remove_whitelist_app_id_liquidation,omitempty"`
MsgAddAuctionParams *MsgAddAuctionParams `json:"msg_add_auction_params,omitempty"`
MsgBurnGovTokensForApp *MsgBurnGovTokensForApp `json:"msg_burn_gov_tokens_for_app,omitempty"`
}

type MsgWhiteListAssetLocker struct {
Expand Down Expand Up @@ -89,9 +90,14 @@ type MsgUpdateLsrInPairsVault struct {
}

type MsgUpdateLsrInCollectorLookupTable struct {
AppMappingId uint64 `json:"app_mapping_id"`
AssetId uint64 `json:"asset_id"`
LSR sdk.Dec `json:"lsr"`
AppMappingId uint64 `json:"app_mapping_id"`
AssetId uint64 `json:"asset_id"`
DebtThreshold uint64 `json:"debt_threshold"`
SurplusThreshold uint64 `json:"surplus_threshold"`
LotSize uint64 `json:"lot_size"`
DebtLotSize uint64 `json:"debt_lot_size"`
BidFactor sdk.Dec `json:"bid_factor"`
LSR sdk.Dec `json:"lsr"`
}

type MsgRemoveWhitelistAssetLocker struct {
Expand Down Expand Up @@ -123,3 +129,9 @@ type MsgAddAuctionParams struct {
DutchId uint64 `json:"dutch_id"`
BidDurationSeconds uint64 `json:"bid_duration_seconds"`
}

type MsgBurnGovTokensForApp struct {
AppMappingId uint64 `json:"app_mapping_id"`
From sdk.AccAddress `json:"from"`
Amount sdk.Coin `json:"amount"`
}
24 changes: 23 additions & 1 deletion app/wasm/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
auctionkeeper "github.com/comdex-official/comdex/x/auction/keeper"
liquidationkeeper "github.com/comdex-official/comdex/x/liquidation/keeper"
tokenmintkeeper "github.com/comdex-official/comdex/x/tokenmint/keeper"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
Expand Down Expand Up @@ -40,6 +41,7 @@ type CustomMessenger struct {
collectorKeeper collectorkeeper.Keeper
liquidationKeeper liquidationkeeper.Keeper
auctionKeeper auctionkeeper.Keeper
tokenmintKeeper tokenmintkeeper.Keeper
}

var _ wasmkeeper.Messenger = (*CustomMessenger)(nil)
Expand Down Expand Up @@ -91,6 +93,9 @@ func (m *CustomMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddre
if comdexMsg.MsgAddAuctionParams != nil {
return m.AddAuctionParams(ctx, contractAddr, comdexMsg.MsgAddAuctionParams)
}
if comdexMsg.MsgBurnGovTokensForApp != nil {
return m.BurnGovTokensForApp(ctx, contractAddr, comdexMsg.MsgBurnGovTokensForApp)
}
}
return m.wrapped.DispatchMsg(ctx, contractAddr, contractIBCPortID, msg)
}
Expand Down Expand Up @@ -256,7 +261,7 @@ func (m *CustomMessenger) UpdateLsrInCollectorLookupTable(ctx sdk.Context, contr

func MsgUpdateLsrInCollectorLookupTable(collectorKeeper collectorkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress,
a *bindings.MsgUpdateLsrInCollectorLookupTable) error {
err := collectorKeeper.WasmUpdateLsrInCollectorLookupTable(ctx, a.AppMappingId, a.AssetId, a.LSR)
err := collectorKeeper.WasmUpdateLsrInCollectorLookupTable(ctx, a.AppMappingId, a.AssetId, a.DebtThreshold, a.SurplusThreshold, a.LotSize, a.DebtLotSize, a.BidFactor, a.LSR)
if err != nil {
return err
}
Expand Down Expand Up @@ -347,3 +352,20 @@ func MsgAddAuctionParams(auctionKeeper auctionkeeper.Keeper, ctx sdk.Context, co
}
return nil
}

func (m *CustomMessenger) BurnGovTokensForApp(ctx sdk.Context, contractAddr sdk.AccAddress, a *bindings.MsgBurnGovTokensForApp) ([]sdk.Event, [][]byte, error) {
err := MsgBurnGovTokensForApp(m.tokenmintKeeper, ctx, contractAddr, a)
if err != nil {
return nil, nil, sdkerrors.Wrap(err, "BurnGovTokensForApp error")
}
return nil, nil, nil
}

func MsgBurnGovTokensForApp(tokenmintKeeper tokenmintkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress,
a *bindings.MsgBurnGovTokensForApp) error {
err := tokenmintKeeper.BurnGovTokensForApp(ctx, a.AppMappingId, a.From, a.Amount)
if err != nil {
return err
}
return nil
}
18 changes: 9 additions & 9 deletions x/collector/keeper/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,21 +585,21 @@ func (k *Keeper) WasmSetAuctionMappingForAppQuery(ctx sdk.Context, appID uint64)
return true, ""
}

func (k *Keeper) WasmUpdateLsrInCollectorLookupTable(ctx sdk.Context, appID, assetID uint64, lsr sdk.Dec) error {
func (k *Keeper) WasmUpdateLsrInCollectorLookupTable(ctx sdk.Context, appID, assetID, debtThreshold, surplusThreshold, lotSize, debtLotSize uint64, bidFactor, lsr sdk.Dec) error {
var Collector types.CollectorLookupTable
accmLookup, _ := k.GetCollectorLookupTable(ctx, appID)

for _, data := range accmLookup.AssetRateInfo {
if data.CollectorAssetId == assetID {
Collector.CollectorAssetId = assetID
Collector.AppId = data.AppId
Collector.BidFactor = data.BidFactor
Collector.DebtThreshold = data.DebtThreshold
Collector.SurplusThreshold = data.SurplusThreshold
Collector.LockerSavingRate = lsr
Collector.LotSize = data.LotSize
Collector.SecondaryAssetId = data.SecondaryAssetId
Collector.DebtLotSize = data.DebtLotSize
Collector.AppId = data.AppId
Collector.BidFactor = bidFactor
Collector.DebtThreshold = debtThreshold
Collector.SurplusThreshold = surplusThreshold
Collector.LockerSavingRate = lsr
Collector.LotSize = lotSize
Collector.SecondaryAssetId = data.SecondaryAssetId
Collector.DebtLotSize = debtLotSize
}
}
err := k.SetCollectorLookupTableForWasm(ctx, Collector)
Expand Down
1 change: 1 addition & 0 deletions x/tokenmint/expected/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ type AssetKeeper interface {
GetApp(ctx sdk.Context, id uint64) (assettypes.AppMapping, bool)
GetApps(ctx sdk.Context) ([]assettypes.AppMapping, bool)
GetAsset(ctx sdk.Context, id uint64) (assettypes.Asset, bool)
GetAssetForDenom(ctx sdk.Context, denom string) (assettypes.Asset, bool)
GetMintGenesisTokenData(ctx sdk.Context, appId, assetId uint64) (assettypes.MintGenesisToken, bool)
}
4 changes: 4 additions & 0 deletions x/tokenmint/keeper/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ func (k *Keeper) GetApps(ctx sdk.Context) ([]assettypes.AppMapping, bool) {
func (k *Keeper) GetMintGenesisTokenData(ctx sdk.Context, appId, assetId uint64) (assettypes.MintGenesisToken, bool) {
return k.asset.GetMintGenesisTokenData(ctx, appId, assetId)
}

func (k *Keeper) GetAssetForDenom(ctx sdk.Context, denom string) (assettypes.Asset, bool){
return k.asset.GetAssetForDenom(ctx,denom)
}
34 changes: 34 additions & 0 deletions x/tokenmint/keeper/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,37 @@ func (k *Keeper) UpdateAssetDataInTokenMintByApp(ctx sdk.Context, appMappingId u
}

}

func (k *Keeper) BurnGovTokensForApp(ctx sdk.Context, appMappingId uint64, from sdk.AccAddress, amount sdk.Coin) error {

_, found := k.GetApp(ctx, appMappingId)
if !found {
return types.ErrorAppMappingDoesNotExists
}

err := k.BurnFrom(ctx, amount, from)
if err != nil {
return err
}
asset, _ := k.GetAssetForDenom(ctx, amount.Denom)

k.UpdateAssetDataInTokenMintByApp(ctx, appMappingId, asset.Id, false, amount.Amount)

return nil
}

func (k *Keeper) BurnFrom(ctx sdk.Context, amount sdk.Coin, burnFrom sdk.AccAddress) error {

// addr, err := sdk.AccAddressFromBech32(burnFrom)
// if err != nil {
// return err
// }
err := k.SendCoinFromAccountToModule(ctx,
burnFrom,
types.ModuleName,
amount)
if err != nil {
return err
}
return k.BurnCoin(ctx, types.ModuleName, amount)
}

0 comments on commit aafa358

Please sign in to comment.