Skip to content

Commit

Permalink
feature(auction) genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed May 6, 2024
1 parent 9a0a5a9 commit d9ab125
Show file tree
Hide file tree
Showing 7 changed files with 506 additions and 105 deletions.
25 changes: 15 additions & 10 deletions proto/umee/auction/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
syntax = "proto3";
package umee.auction.v1;

import "google/protobuf/timestamp.proto";
import "cosmos/base/v1beta1/coin.proto";
import "gogoproto/gogo.proto";
import "umee/auction/v1/auction.proto";

Expand All @@ -16,13 +14,20 @@ message GenesisState {
RewardsParams rewards_params = 1 [(gogoproto.nullable) = false];
// Latest active (in bid phase) reward auction.
uint32 reward_auction_id = 2;
// Latest highest rewards bid.
Bid highest_rewards_bid = 3 [(gogoproto.nullable) = false];
// All rewards auctions with ID.
repeated RewardsKV rewards_auctions = 3 [(gogoproto.nullable) = false];
// Highest bids for all rewards auctions with ID.
repeated BidKV rewards_bids = 4 [(gogoproto.nullable) = false];
}

// RewardsKV combines a storage key (id) an value (rewards)
message RewardsKV {
uint32 id = 1;
Rewards rewards = 2 [(gogoproto.nullable) = false];
}

google.protobuf.Timestamp current_rewards_auction_end = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
// Tokens collected for the current auction.
repeated cosmos.base.v1beta1.Coin current_rewards = 5 [(gogoproto.nullable) = false];
// Tokens collected for the next auction, while the current reward auction is still in the
// bid phase.
repeated cosmos.base.v1beta1.Coin next_rewards = 6 [(gogoproto.nullable) = false];
// BidKV combines a storage key (id) an value (bid)
message BidKV {
uint32 id = 1;
Bid bid = 2 [(gogoproto.nullable) = false];
}
37 changes: 34 additions & 3 deletions x/auction/genesis.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
package auction

import (
"errors"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// DefaultGenesis creates a default genesis state
func DefaultGenesis() *GenesisState {
// TODO
return &GenesisState{}
return &GenesisState{
RewardsParams: RewardsParams{BidDuration: 14 * 24 * 3600}, // 14 days
RewardAuctionId: 0,
RewardsAuctions: []RewardsKV{},
RewardsBids: []BidKV{},
}
}

func (gs *GenesisState) Validate() error {
// TODO
if gs.RewardsParams.BidDuration <= 60 {
return errors.New("RewardsParams.BidDuration must be at least 60s")
}
if gs.RewardsParams.BidDuration >= 180*24*3600 {
return errors.New("RewardsParams.BidDuration must be at most 15552000s = 180days")
}
for _, elem := range gs.RewardsAuctions {
coins := sdk.Coins(elem.Rewards.Rewards)
if err := coins.Validate(); err != nil {
return err
}
if elem.Id > gs.RewardAuctionId {
return fmt.Errorf("rewards_auctions ID must be at most rewards_auction_id")
}
}
for _, elem := range gs.RewardsBids {
if elem.Id > gs.RewardAuctionId {
return fmt.Errorf("rewards_bids ID must be at most rewards_auction_id")
}
}

return nil
}
Loading

0 comments on commit d9ab125

Please sign in to comment.