Skip to content

Commit

Permalink
feat: new auction ending mechanism (#15)
Browse files Browse the repository at this point in the history
* go.mod: update dependencies

* x/marketplace: update auction ending mechanism

* feat: add maximum auction duration

* remove ignite config
  • Loading branch information
harish551 authored Jun 8, 2023
1 parent 6030678 commit 57b4811
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 103 deletions.
23 changes: 14 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/cosmos/ibc-go/v3/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v3/modules/core"
ibcclient "github.com/cosmos/ibc-go/v3/modules/core/02-client"
ibcporttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"

icahostkeeper "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/keeper"
"github.com/cosmos/ibc-go/v4/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v4/modules/core"
ibcclient "github.com/cosmos/ibc-go/v4/modules/core/02-client"
ibcporttypes "github.com/cosmos/ibc-go/v4/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
Expand Down Expand Up @@ -201,15 +203,18 @@ type App struct {
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
IBCICAHostKeeper icahostkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ONFTKeeper onftkeeper.Keeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper

// OmniFlix Native modules
ONFTKeeper onftkeeper.Keeper
MarketplaceKeeper marketplacemodulekeeper.Keeper

// the module manager
Expand Down
11 changes: 0 additions & 11 deletions config.yml

This file was deleted.

12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/OmniFlix/marketplace
go 1.19

require (
github.com/OmniFlix/onft v0.5.0-alpha.2
github.com/cosmos/cosmos-sdk v0.45.15
github.com/cosmos/ibc-go/v3 v3.4.0
github.com/OmniFlix/onft v0.6.0-alpha.1
github.com/cosmos/cosmos-sdk v0.45.16
github.com/cosmos/ibc-go/v4 v4.4.2
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
github.com/google/uuid v1.3.0
Expand All @@ -14,7 +14,7 @@ require (
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/tendermint/tendermint v0.34.27
github.com/tendermint/tendermint v0.34.28
github.com/tendermint/tm-db v0.6.7
golang.org/x/exp v0.0.0-20221019170559-20944726eadf
google.golang.org/genproto v0.0.0-20230125152338-dcaf20b6aeaa
Expand All @@ -29,7 +29,7 @@ require (
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect
github.com/DataDog/zstd v1.5.0 // indirect
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
github.com/Workiva/go-datastructures v1.0.53 // indirect
Expand Down Expand Up @@ -144,6 +144,6 @@ replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
// use cometbft
github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.27
github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.28
google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg=
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4=
github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM=
github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4=
github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EFZQ978U7x8IRnstaskI3IysnWY5Ao3QgZUKOXlsAdw=
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno=
github.com/CloudyKit/jet v2.1.3-0.20180809161101-62edd43e4f88+incompatible/go.mod h1:HPYO+50pSWkPoj9Q/eq0aRGByCL6ScRlUmiEX5Zgm+w=
Expand All @@ -76,8 +76,8 @@ github.com/Joker/jade v1.0.1-0.20190614124447-d475f43051e7/go.mod h1:6E6s8o2AE4K
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
github.com/OmniFlix/onft v0.5.0-alpha.2 h1:pp0HTYkvgbgdqcoCH48rHp//+IU2hOTjbx0h9avkWPQ=
github.com/OmniFlix/onft v0.5.0-alpha.2/go.mod h1:ZvNsefiGp3bqn5fwS2J/AkZdDmwgwg0yukaVDFo1KoE=
github.com/OmniFlix/onft v0.6.0-alpha.1 h1:3FXGd2BcZMg0GhhMLm4Q6MqNG8KYHsof2no/kDcMq7w=
github.com/OmniFlix/onft v0.6.0-alpha.1/go.mod h1:RW0ooCgUtutpMElh38kbYf3Qb05BmDKK18jCRImwinI=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
Expand Down Expand Up @@ -203,8 +203,8 @@ github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcju
github.com/coinbase/kryptology v1.8.0/go.mod h1:RYXOAPdzOGUe3qlSFkMGn58i3xUA8hmxYHksuq+8ciI=
github.com/coinbase/rosetta-sdk-go v0.7.9 h1:lqllBjMnazTjIqYrOGv8h8jxjg9+hJazIGZr9ZvoCcA=
github.com/coinbase/rosetta-sdk-go v0.7.9/go.mod h1:0/knutI7XGVqXmmH4OQD8OckFrbQ8yMsUZTG7FXCR2M=
github.com/cometbft/cometbft v0.34.27 h1:ri6BvmwjWR0gurYjywcBqRe4bbwc3QVs9KRcCzgh/J0=
github.com/cometbft/cometbft v0.34.27/go.mod h1:BcCbhKv7ieM0KEddnYXvQZR+pZykTKReJJYf7YC7qhw=
github.com/cometbft/cometbft v0.34.28 h1:gwryf55P1SWMUP4nOXpRVI2D0yPoYEzN+IBqmRBOsDc=
github.com/cometbft/cometbft v0.34.28/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw=
github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo=
github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0=
github.com/confio/ics23/go v0.9.0 h1:cWs+wdbS2KRPZezoaaj+qBleXgUk5WOQFMP3CQFGTr4=
Expand All @@ -226,17 +226,17 @@ github.com/cosmos/cosmos-db v0.0.0-20221226095112-f3c38ecb5e32 h1:zlCp9n3uwQieEL
github.com/cosmos/cosmos-db v0.0.0-20221226095112-f3c38ecb5e32/go.mod h1:kwMlEC4wWvB48zAShGKVqboJL6w4zCLesaNQ3YLU2BQ=
github.com/cosmos/cosmos-proto v1.0.0-beta.1 h1:iDL5qh++NoXxG8hSy93FdYJut4XfgbShIocllGaXx/0=
github.com/cosmos/cosmos-proto v1.0.0-beta.1/go.mod h1:8k2GNZghi5sDRFw/scPL8gMSowT1vDA+5ouxL8GjaUE=
github.com/cosmos/cosmos-sdk v0.45.15 h1:yyLZ9PylnR1DADf9FYGxnn8t3+Y5K2mMUXNUN38MI5A=
github.com/cosmos/cosmos-sdk v0.45.15/go.mod h1:bScuNwWAP0TZJpUf+SHXRU3xGoUPp+X9nAzfeIXts40=
github.com/cosmos/cosmos-sdk v0.45.16 h1:5ba/Bh5/LE55IwHQuCU4fiG4eXeDKtSWzehXRpaKDcw=
github.com/cosmos/cosmos-sdk v0.45.16/go.mod h1:bScuNwWAP0TZJpUf+SHXRU3xGoUPp+X9nAzfeIXts40=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y=
github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw=
github.com/cosmos/iavl v0.19.5 h1:rGA3hOrgNxgRM5wYcSCxgQBap7fW82WZgY78V9po/iY=
github.com/cosmos/iavl v0.19.5/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
github.com/cosmos/ibc-go/v3 v3.4.0 h1:ha3cqEG36pqMWqA1D+kxDWBTZXpeFMd/aZIQF7I0xro=
github.com/cosmos/ibc-go/v3 v3.4.0/go.mod h1:VwB/vWu4ysT5DN2aF78d17LYmx3omSAdq6gpKvM7XRA=
github.com/cosmos/ibc-go/v4 v4.4.2 h1:PG4Yy0/bw6Hvmha3RZbc53KYzaCwuB07Ot4GLyzcBvo=
github.com/cosmos/ibc-go/v4 v4.4.2/go.mod h1:j/kD2JCIaV5ozvJvaEkWhLxM2zva7/KTM++EtKFYcB8=
github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo=
github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA=
github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA=
Expand Down
5 changes: 5 additions & 0 deletions proto/marketplace/v1beta1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ message Params {
(gogoproto.stdduration) = true,
(gogoproto.nullable) = false
];
google.protobuf.Duration max_auction_duration = 4 [
(gogoproto.moretags) = "yaml:\"max_auction_duration\"",
(gogoproto.stdduration) = true,
(gogoproto.nullable) = false
];
}

message Distribution {
Expand Down
66 changes: 42 additions & 24 deletions x/marketplace/keeper/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,30 +219,43 @@ func (k Keeper) UpdateAuctionStatusesAndProcessBids(ctx sdk.Context) error {
for ; iterator.Valid(); iterator.Next() {
var auction types.AuctionListing
k.cdc.MustUnmarshal(iterator.Value(), &auction)

// if auction is active
if auction.StartTime.Before(ctx.BlockTime()) {

durationFromStartTime := ctx.BlockTime().Sub(auction.StartTime)
bidCloseDuration := k.GetBidCloseDuration(ctx)
bid, found := k.GetBid(ctx, auction.GetId())
if !found && auction.EndTime != nil && auction.EndTime.Before(ctx.BlockTime()) {
err := k.nftKeeper.TransferOwnership(ctx, auction.GetDenomId(), auction.GetNftId(),
k.accountKeeper.GetModuleAddress(types.ModuleName), auction.GetOwner())
if err != nil {
return err
}
k.RemoveAuctionListing(ctx, auction.GetId())
k.removeAuctionEvent(ctx, auction)
} else if !found && auction.EndTime == nil &&
ctx.BlockTime().Sub(auction.StartTime).Seconds() > k.GetBidCloseDuration(ctx).Seconds() {
err := k.nftKeeper.TransferOwnership(ctx, auction.GetDenomId(), auction.GetNftId(),
k.accountKeeper.GetModuleAddress(types.ModuleName), auction.GetOwner())
if err != nil {
return err
}
k.RemoveAuctionListing(ctx, auction.GetId())
k.removeAuctionEvent(ctx, auction)

} else if found && ctx.BlockTime().Sub(bid.Time).Seconds() > k.GetBidCloseDuration(ctx).Seconds() {
err := k.processBid(ctx, auction, bid)
if err != nil {
return err
// if auction has ended
if auction.EndTime != nil && auction.EndTime.Before(ctx.BlockTime()) ||
auction.EndTime == nil && durationFromStartTime > bidCloseDuration {

// process bid if found else return NFT to owner
if found {
err := k.processBid(ctx, auction, bid)
if err != nil {
return err
}
// emit events
k.processBidEvent(ctx, auction, bid)
k.RemoveAuctionListing(ctx, auction.GetId())
k.RemoveBid(ctx, auction.GetId())

} else {
err := k.returnNftToOwner(
ctx,
auction.GetDenomId(),
auction.GetNftId(),
k.accountKeeper.GetModuleAddress(types.ModuleName),
auction.GetOwner(),
)
if err != nil {
return err
}
// emit events
k.RemoveAuctionListing(ctx, auction.GetId())
k.removeAuctionEvent(ctx, auction)
}
}
}
Expand Down Expand Up @@ -327,8 +340,13 @@ func (k Keeper) processBid(ctx sdk.Context, auction types.AuctionListing, bid ty
return err
}
}
k.processBidEvent(ctx, auction, bid)
k.RemoveAuctionListing(ctx, auction.GetId())
k.RemoveBid(ctx, auction.GetId())
return nil
}

func (k Keeper) returnNftToOwner(ctx sdk.Context, denomId, nftId string, moduleAddress, owner sdk.AccAddress) error {
err := k.nftKeeper.TransferOwnership(ctx, denomId, nftId, moduleAddress, owner)
if err != nil {
return err
}
return nil
}
7 changes: 6 additions & 1 deletion x/marketplace/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (m msgServer) BuyNFT(goCtx context.Context, msg *types.MsgBuyNFT) (*types.M
return &types.MsgBuyNFTResponse{}, nil
}

// CreateAuction
// CreateAuction creates a new auction
func (m msgServer) CreateAuction(goCtx context.Context, msg *types.MsgCreateAuction) (*types.MsgCreateAuctionResponse, error) {

ctx := sdk.UnwrapSDKContext(goCtx)
Expand All @@ -154,6 +154,11 @@ func (m msgServer) CreateAuction(goCtx context.Context, msg *types.MsgCreateAuct
if err := msg.Validate(ctx.BlockTime()); err != nil {
return nil, err
}
maxAuctionDuration := m.Keeper.GetMaxAuctionDuration(ctx)
if msg.Duration.Seconds() > maxAuctionDuration.Seconds() {
return nil, sdkerrors.Wrapf(types.ErrInvalidDuration,
"duration %s exceeds max auction duration %s", msg.Duration.String(), maxAuctionDuration.String())
}

nft, err := m.nftKeeper.GetONFT(ctx, msg.DenomId, msg.NftId)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion x/marketplace/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/OmniFlix/marketplace/x/marketplace/types"
sdk "github.com/cosmos/cosmos-sdk/types"

)

// GetParams gets the parameters for the marketplace module.
Expand Down Expand Up @@ -36,3 +35,9 @@ func (k Keeper) GetBidCloseDuration(ctx sdk.Context) (duration time.Duration) {
k.paramSpace.Get(ctx, types.ParamStoreKeyBidCloseDuration, &duration)
return duration
}

// GetMaxAuctionDuration returns the maximum duration for auctions.
func (k Keeper) GetMaxAuctionDuration(ctx sdk.Context) (duration time.Duration) {
k.paramSpace.Get(ctx, types.ParamStoreKeyMaxAuctionDuration, &duration)
return duration
}
43 changes: 34 additions & 9 deletions x/marketplace/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// Default period for closing bids for an auction
const (
DefaultBidClosePeriod time.Duration = time.Hour * 12 // 12 Hours
// DefaultBidClosePeriod Default period for closing bids for an auction
DefaultBidClosePeriod time.Duration = time.Hour * 12 // 12 Hours
DefaultMaxAuctionDuration time.Duration = time.Hour * 24 * 90 // 90 Days
)

// Parameter keys
var (
ParamStoreKeySaleCommission = []byte("SaleCommission")
ParamStoreKeyDistribution = []byte("MarketplaceDistribution")
ParamStoreKeyBidCloseDuration = []byte("BidCloseDuration")
ParamStoreKeySaleCommission = []byte("SaleCommission")
ParamStoreKeyDistribution = []byte("MarketplaceDistribution")
ParamStoreKeyBidCloseDuration = []byte("BidCloseDuration")
ParamStoreKeyMaxAuctionDuration = []byte("MaxAuctionDuration")
)

var _ paramtypes.ParamSet = (*Params)(nil)
Expand All @@ -27,11 +29,18 @@ func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}

func NewMarketplaceParams(saleCommission sdk.Dec, distribution Distribution, bidCloseDuration time.Duration) Params {
func NewMarketplaceParams(
saleCommission sdk.Dec,
distribution Distribution,
bidCloseDuration time.Duration,
maxAuctionDuration time.Duration,
) Params {

return Params{
SaleCommission: saleCommission,
Distribution: distribution,
BidCloseDuration: bidCloseDuration,
SaleCommission: saleCommission,
Distribution: distribution,
BidCloseDuration: bidCloseDuration,
MaxAuctionDuration: maxAuctionDuration,
}
}

Expand All @@ -44,6 +53,7 @@ func DefaultParams() Params {
CommunityPool: sdk.NewDecWithPrec(50, 2), // 50%
},
DefaultBidClosePeriod,
DefaultMaxAuctionDuration,
)
}

Expand All @@ -53,6 +63,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(ParamStoreKeySaleCommission, &p.SaleCommission, validateSaleCommission),
paramtypes.NewParamSetPair(ParamStoreKeyDistribution, &p.Distribution, validateMarketplaceDistributionParams),
paramtypes.NewParamSetPair(ParamStoreKeyBidCloseDuration, &p.BidCloseDuration, validateBidCloseDuration),
paramtypes.NewParamSetPair(ParamStoreKeyMaxAuctionDuration, &p.MaxAuctionDuration, validateMaxAuctionDuration),
}
}

Expand All @@ -67,6 +78,9 @@ func (p Params) ValidateBasic() error {
if err := validateBidCloseDuration(p.BidCloseDuration); err != nil {
return err
}
if err := validateMaxAuctionDuration(p.MaxAuctionDuration); err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -157,3 +171,14 @@ func validateBidCloseDuration(i interface{}) error {

return nil
}

func validateMaxAuctionDuration(d interface{}) error {
v, ok := d.(time.Duration)
if !ok {
return fmt.Errorf("invalid parameter type: %T", d)
}
if v.Seconds() <= 0 {
return fmt.Errorf("max auction duration must be positive: %f", v.Seconds())
}
return nil
}
Loading

0 comments on commit 57b4811

Please sign in to comment.