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

fix: fix the rewards collects for bid #2539

Merged
merged 9 commits into from
Jun 6, 2024
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
2 changes: 1 addition & 1 deletion proto/umee/auction/v1/auction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ message RewardsParams {

// Bid records a user bid
message Bid {
bytes bidder = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string bidder = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string amount = 2 [(cosmos_proto.scalar) = "cosmos.Int", (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false];
}

Expand Down
3 changes: 2 additions & 1 deletion proto/umee/auction/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package umee.auction.v1;

import "google/protobuf/timestamp.proto";
import "google/api/annotations.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "umee/auction/v1/auction.proto";
import "cosmos/base/v1beta1/coin.proto";
Expand Down Expand Up @@ -42,7 +43,7 @@ message QueryRewardsAuction {
message QueryRewardsAuctionResponse {
uint32 id = 1;
// highest bidder
string bidder = 2;
string bidder = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
cosmos.base.v1beta1.Coin bid = 3 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin rewards = 4 [(gogoproto.nullable) = false];
google.protobuf.Timestamp ends_at = 5 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
Expand Down
70 changes: 34 additions & 36 deletions x/auction/auction.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions x/auction/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func TestGenesis(t *testing.T) {
{4, auction.Rewards{newCoin(412313), randTime()}},
}
gs.RewardsBids = []auction.BidKV{
{1, auction.Bid{accs.Alice, sdkmath.NewInt(153252)}},
{2, auction.Bid{accs.Alice, sdkmath.NewInt(8521)}},
{1, auction.Bid{accs.Alice.String(), sdkmath.NewInt(153252)}},
{2, auction.Bid{accs.Alice.String(), sdkmath.NewInt(8521)}},
}
check(gs)
}
2 changes: 1 addition & 1 deletion x/auction/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
bid, id := q.Keeper(&ctx).getRewardsBid(msg.Id)
r := &auction.QueryRewardsAuctionResponse{Id: id}
if bid != nil {
r.Bidder = sdk.AccAddress(bid.Bidder).String()
gsk967 marked this conversation as resolved.
Show resolved Hide resolved
r.Bidder = bid.Bidder

Check warning on line 40 in x/auction/keeper/grpc_query.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/grpc_query.go#L40

Added line #L40 was not covered by tests
r.Bid = coin.UmeeInt(bid.Amount)
}
rewards, _ := q.Keeper(&ctx).getRewardsAuction(msg.Id)
Expand Down
30 changes: 12 additions & 18 deletions x/auction/keeper/rewards.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package keeper

import (
"bytes"
"errors"
"fmt"
"strconv"
"time"

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

"github.com/umee-network/umee/v6/util"
"github.com/umee-network/umee/v6/util/coin"
"github.com/umee-network/umee/v6/util/sdkutil"
"github.com/umee-network/umee/v6/util/store"
Expand All @@ -27,10 +25,10 @@
return nil
}

newCoins := k.bank.GetAllBalances(*k.ctx, k.accs.RewardsCollect)
bid, _ := k.getRewardsBid(id)
if bid != nil && len(bid.Bidder) != 0 {
err := k.sendCoins(k.accs.RewardsCollect, bid.Bidder, a.Rewards)
bidderAccAddr := sdk.MustAccAddressFromBech32(bid.Bidder)
err := k.sendCoins(k.accs.RewardsCollect, bidderAccAddr, a.Rewards)

Check warning on line 31 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L30-L31

Added lines #L30 - L31 were not covered by tests
if err != nil {
return fmt.Errorf("can't send coins to finalize the auction [%w]", err)
}
Expand All @@ -42,12 +40,10 @@
Id: id,
Bidder: sdk.AccAddress(bid.Bidder).String(),
})
} else if len(a.Rewards) != 0 {
// rollover the past rewards if there was no bidder
newCoins = newCoins.Add(a.Rewards...)
}

return k.initNewAuction(id+1, newCoins)
remainingRewards := k.bank.GetAllBalances(*k.ctx, k.accs.RewardsCollect)
return k.initNewAuction(id+1, remainingRewards)

Check warning on line 46 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L45-L46

Added lines #L45 - L46 were not covered by tests
}

func (k Keeper) initNewAuction(id uint32, rewards sdk.Coins) error {
Expand Down Expand Up @@ -79,26 +75,26 @@
return err
}

sender, err := sdk.AccAddressFromBech32(msg.Sender)
util.Panic(err)

toAuction := msg.Amount
if lastBid != nil {
if bytes.Equal(sender, lastBid.Bidder) {
if msg.Sender == lastBid.Bidder {

Check warning on line 80 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L80

Added line #L80 was not covered by tests
// bidder updates his last bid: send only diff
toAuction = msg.Amount.SubAmount(lastBid.Amount)
} else {
returned := coin.UmeeInt(lastBid.Amount)
if err = k.sendFromModule(lastBid.Bidder, returned); err != nil {
bidderAccAddr := sdk.MustAccAddressFromBech32(lastBid.Bidder)
if err := k.sendFromModule(bidderAccAddr, returned); err != nil {

Check warning on line 86 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L85-L86

Added lines #L85 - L86 were not covered by tests
return err
}
}
}
if err = k.sendToModule(sender, toAuction); err != nil {

sender := sdk.MustAccAddressFromBech32(msg.Sender)
if err := k.sendToModule(sender, toAuction); err != nil {

Check warning on line 93 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L92-L93

Added lines #L92 - L93 were not covered by tests
return err
}

bid := auction.Bid{Bidder: sender, Amount: msg.Amount.Amount}
bid := auction.Bid{Bidder: msg.Sender, Amount: msg.Amount.Amount}

Check warning on line 97 in x/auction/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L97

Added line #L97 was not covered by tests
return store.SetValue(k.store, key, &bid, keyMsg)
}

Expand All @@ -112,8 +108,7 @@
}

func (k Keeper) getAllRewardsBids() ([]auction.BidKV, error) {
elems, err := store.LoadAllKV[*store.Uint32, store.Uint32, *auction.Bid](
k.store, keyPrefixRewardsBid)
elems, err := store.LoadAllKV[*store.Uint32, store.Uint32, *auction.Bid](k.store, keyPrefixRewardsBid)
if err != nil {
return nil, err
}
Expand All @@ -123,7 +118,6 @@
bids[i].Bid = elems[i].Val
}
return bids, nil

}

func (k Keeper) storeAllRewardsBids(elems []auction.BidKV) error {
Expand Down
19 changes: 0 additions & 19 deletions x/auction/module/genesis.go

This file was deleted.

67 changes: 35 additions & 32 deletions x/auction/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/leverage/keeper/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
}
if !toAuctionCheck.IsZero() {
auction.EmitFundRewardsAuction(&ctx, toOracleCheck)
return send(ctx, types.ModuleName, auction.ModuleName, toAuctionCheck)
return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, k.rewardsAuction, toAuctionCheck)

Check warning on line 300 in x/leverage/keeper/oracle.go

View check run for this annotation

Codecov / codecov/patch

x/leverage/keeper/oracle.go#L300

Added line #L300 was not covered by tests
}

return nil
Expand Down
Loading