Skip to content

Commit

Permalink
Merge pull request #249 from comdex-official/testdev_auction
Browse files Browse the repository at this point in the history
Testdev auction
  • Loading branch information
cgsingh33 authored Jun 15, 2022
2 parents 89b62af + 1d78763 commit 2571024
Show file tree
Hide file tree
Showing 26 changed files with 3,419 additions and 1,717 deletions.
2 changes: 2 additions & 0 deletions app/wasm/bindings/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type MsgSetCollectorLookupTable struct {
LockerSavingRate sdk.Dec `json:"locker_saving_rate"`
LotSize uint64 `json:"lot_size"`
BidFactor sdk.Dec `json:"bid_factor"`
DebtLotSize uint64 `json:"debt_lot_size"`
}

type MsgSetAuctionMappingForApp struct {
Expand Down Expand Up @@ -120,4 +121,5 @@ type MsgAddAuctionParams struct {
SurplusId uint64 `json:"surplus_id"`
DebtId uint64 `json:"debt_id"`
DutchId uint64 `json:"dutch_id"`
BidDurationSeconds uint64 `json:"bid_duration_seconds"`
}
4 changes: 2 additions & 2 deletions app/wasm/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (m *CustomMessenger) SetCollectorLookupTable(ctx sdk.Context, contractAddr

func MsgSetCollectorLookupTable(collectorKeeper collectorkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress,
a *bindings.MsgSetCollectorLookupTable) error {
err := collectorKeeper.WasmSetCollectorLookupTable(ctx, a.AppMappingId, a.CollectorAssetId, a.SecondaryAssetId, a.SurplusThreshold, a.DebtThreshold, a.LockerSavingRate, a.LotSize, a.BidFactor)
err := collectorKeeper.WasmSetCollectorLookupTable(ctx, a.AppMappingId, a.CollectorAssetId, a.SecondaryAssetId, a.SurplusThreshold, a.DebtThreshold, a.LockerSavingRate, a.LotSize, a.BidFactor, a.DebtLotSize)
if err != nil {
return err
}
Expand Down Expand Up @@ -345,7 +345,7 @@ func (m *CustomMessenger) AddAuctionParams(ctx sdk.Context, contractAddr sdk.Acc

func MsgAddAuctionParams(auctionKeeper auctionkeeper.Keeper, ctx sdk.Context, contractAddr sdk.AccAddress,
a *bindings.MsgAddAuctionParams) error {
err := auctionKeeper.AddAuctionParams(ctx, a.AppMappingId, a.AuctionDurationSeconds, a.Buffer, a.Cusp, a.Step, a.PriceFunctionType, a.SurplusId, a.DebtId, a.DutchId)
err := auctionKeeper.AddAuctionParams(ctx, a.AppMappingId, a.AuctionDurationSeconds, a.Buffer, a.Cusp, a.Step, a.PriceFunctionType, a.SurplusId, a.DebtId, a.DutchId, a.BidDurationSeconds)
if err != nil {
return err
}
Expand Down
58 changes: 38 additions & 20 deletions proto/comdex/auction/v1beta1/auction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ message SurplusAuction {
(gogoproto.moretags) = "yaml:\"auction_id\""
];

cosmos.base.v1beta1.Coin outflow_token = 2 [
cosmos.base.v1beta1.Coin sell_token = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"outflow_token\"",
(gogoproto.moretags) = "yaml:\"sell_token\"",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
cosmos.base.v1beta1.Coin inflow_token = 3 [
cosmos.base.v1beta1.Coin buy_token = 3 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"inflow_token\"",
(gogoproto.moretags) = "yaml:\"buy_token\"",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
uint64 active_bidding_id = 4 [
Expand Down Expand Up @@ -72,6 +72,11 @@ message SurplusAuction {
uint64 asset_out_id = 15 [
(gogoproto.moretags) = "yaml:\"asset_out_id\""
];
google.protobuf.Timestamp bid_end_time = 16 [
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true,
(gogoproto.moretags) = "yaml:\"bid_end_time\""
];
}

message DebtAuction {
Expand Down Expand Up @@ -136,6 +141,11 @@ message DebtAuction {
uint64 asset_out_id = 16 [
(gogoproto.moretags) = "yaml:\"asset_out_id\""
];
google.protobuf.Timestamp bid_end_time = 17 [
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true,
(gogoproto.moretags) = "yaml:\"bid_end_time\""
];
}


Expand Down Expand Up @@ -163,68 +173,73 @@ message DutchAuction {
(gogoproto.moretags) = "yaml:\"inflow_token_current_amount\"",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
string outflow_token_initial_price = 6 [
cosmos.base.v1beta1.Coin to_burn_amount = 6 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"to_burn_amount\"",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.Coin"
];
string outflow_token_initial_price = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"outflow_token_initial_price\""
];
string outflow_token_current_price = 7 [
string outflow_token_current_price = 8 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"outflow_token_current_price\""
];
string outflow_token_end_price = 8 [
string outflow_token_end_price = 9 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"outflow_token_end_price\""
];
string inflow_token_current_price = 9 [
string inflow_token_current_price = 10 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"inflow_token_current_price\""
];

google.protobuf.Timestamp end_time = 10 [
google.protobuf.Timestamp end_time = 11 [
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true,
(gogoproto.moretags) = "yaml:\"end_time\""
];
uint64 auction_status = 11 [
uint64 auction_status = 12 [
(gogoproto.moretags) = "yaml:\"auction_status\""
];
google.protobuf.Timestamp start_time = 12 [
google.protobuf.Timestamp start_time = 13 [
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true,
(gogoproto.moretags) = "yaml:\"start_time\""
];
repeated bidOwnerMapping bidding_ids = 13[
repeated bidOwnerMapping bidding_ids = 14[
(gogoproto.moretags) = "yaml:\"bidding_ids\""
];
uint64 auction_mapping_id = 14 [
uint64 auction_mapping_id = 15 [
(gogoproto.moretags) = "yaml:\"auction_mapping_id\""
];
uint64 app_id = 15 [
uint64 app_id = 16 [
(gogoproto.moretags) = "yaml:\"app_id\""
];
uint64 asset_in_id = 16 [
uint64 asset_in_id = 17 [
(gogoproto.moretags) = "yaml:\"asset_in_id\""
];
uint64 asset_out_id = 17 [
uint64 asset_out_id = 18 [
(gogoproto.moretags) = "yaml:\"asset_out_id\""
];
uint64 locked_vault_id = 18 [
uint64 locked_vault_id = 19 [
(gogoproto.moretags) = "yaml:\"locked_vault_id\""
];
string vault_owner = 19 [
string vault_owner = 20 [
(gogoproto.moretags) = "yaml:\"vault_owner\"",
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"
];
string liquidation_penalty = 20 [
string liquidation_penalty = 21 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"liquidatin_penalty\""
];
bool is_locked_vault_amount_in_zero = 21 [
bool is_locked_vault_amount_in_zero = 22 [
(gogoproto.moretags) = "yaml:\"is_locked_vault_amount_in_zero\""
];
}
Expand Down Expand Up @@ -282,4 +297,7 @@ message AuctionParams{
uint64 dutch_id = 9 [
(gogoproto.moretags) = "yaml:\"dutch_id\""
];
uint64 bid_duration_seconds = 10 [
(gogoproto.moretags) = "yaml:\"bid_duration_seconds\""
];
}
8 changes: 4 additions & 4 deletions proto/comdex/auction/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ message MsgPlaceDutchBidRequest {
uint64 auction_id = 1;
string bidder = 2;
cosmos.base.v1beta1.Coin amount = 3 [(gogoproto.nullable) = false];
string max= 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"max\""];
// string max= 4 [
// (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
// (gogoproto.nullable) = false,
// (gogoproto.moretags) = "yaml:\"max\""];
uint64 app_id =5;
uint64 auction_mapping_id =6;
}
Expand Down
2 changes: 2 additions & 0 deletions proto/comdex/collector/v1beta1/collector.proto
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ message CollectorLookupTable {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"bid_factor\""
];
uint64 debt_lot_size = 9 [
(gogoproto.moretags) = "yaml:\"debt_lot_size\""];
}

message CollectorLookup {
Expand Down
17 changes: 15 additions & 2 deletions x/auction/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,21 @@ import (

func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
//k.CreateNewAuctions(ctx)
err := k.CloseAndRestartAuctions(ctx)
if err != nil {
// err := k.CloseAndRestartAuctions(ctx)
// if err != nil {
// return
// }

err1 := k.SurplusActivator(ctx)
if err1 != nil {
return
}
err2 := k.DebtActivator(ctx)
if err2 != nil {
return
}
err3 := k.DutchActivator(ctx)
if err3 != nil {
return
}
}
12 changes: 6 additions & 6 deletions x/auction/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ func txPlaceDebtBid() *cobra.Command {

func txPlaceDutchBid() *cobra.Command {
cmd := &cobra.Command{
Use: "bid-dutch [auction-id] [amount] [maxamountpercollateraltoken] [app-id] [auction-mapping-id]",
Use: "bid-dutch [auction-id] [amount] [app-id] [auction-mapping-id]",
Short: "Place a Dutch bid on an auction",
Args: cobra.ExactArgs(5),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -124,19 +124,19 @@ func txPlaceDutchBid() *cobra.Command {
return err
}

max := sdk.MustNewDecFromStr(args[2])
// max := sdk.MustNewDecFromStr(args[1])

appId, err := strconv.ParseUint(args[3], 10, 64)
appId, err := strconv.ParseUint(args[2], 10, 64)
if err != nil {
return fmt.Errorf("auction-id '%s' not a valid uint", args[0])
}

auctionMappingId, err := strconv.ParseUint(args[4], 10, 64)
auctionMappingId, err := strconv.ParseUint(args[3], 10, 64)
if err != nil {
return fmt.Errorf("auction-id '%s' not a valid uint", args[0])
}

msg := types.NewMsgPlaceDutchBid(clientCtx.GetFromAddress(), auctionId, amt, max, appId, auctionMappingId)
msg := types.NewMsgPlaceDutchBid(clientCtx.GetFromAddress(), auctionId, amt, appId, auctionMappingId)
err = msg.ValidateBasic()
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions x/auction/expected/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type CollectorKeeper interface {
GetAmountFromCollector(ctx sdk.Context, appId, asset_id uint64, amount sdk.Int) (sdk.Int, error)
SetNetFeeCollectedData(ctx sdk.Context, app_id, asset_id uint64, fee sdk.Int) error
SetAuctionMappingForApp(ctx sdk.Context, records ...types.CollectorAuctionLookupTable) error
GetAllAuctionMappingForApp(ctx sdk.Context) (collectorAuctionLookupTable []types.CollectorAuctionLookupTable, found bool)
}

type TokenMintKeeper interface {
Expand Down
4 changes: 4 additions & 0 deletions x/auction/keeper/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,8 @@ func (k *Keeper) UpdateTokenMintedAmountLockerMapping(ctx sdk.Context, valutLook
}
func (k *Keeper) UpdateCollateralLockedAmountLockerMapping(ctx sdk.Context, valutLookupData vaultttypes.AppExtendedPairVaultMapping, extendedPairId uint64, amount sdk.Int, changeType bool) {
k.vault.UpdateCollateralLockedAmountLockerMapping(ctx, valutLookupData, extendedPairId, amount, changeType)
}

func (k *Keeper) GetAllAuctionMappingForApp(ctx sdk.Context) (collectorAuctionLookupTable []types.CollectorAuctionLookupTable, found bool) {
return k.collector.GetAllAuctionMappingForApp(ctx)
}
Loading

0 comments on commit 2571024

Please sign in to comment.