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 8 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 app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

// update leverage and metoken params to include burn auction fee share.
lparams := app.LeverageKeeper.GetParams(ctx)
lparams.RewardsAuctionFee = sdk.MustNewDecFromStr("0.01")
lparams.RewardsAuctionFee = sdk.MustNewDecFromStr("0.05") // NOTE: this is for testing!

Check warning on line 68 in app/upgrades.go

View check run for this annotation

Codecov / codecov/patch

app/upgrades.go#L68

Added line #L68 was not covered by tests
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
if err := app.LeverageKeeper.SetParams(ctx, lparams); err != nil {
return nil, err
}
Expand Down
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"];
gsk967 marked this conversation as resolved.
Show resolved Hide resolved
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.

2 changes: 1 addition & 1 deletion x/auction/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// DefaultGenesis creates a default genesis state
func DefaultGenesis() *GenesisState {
return &GenesisState{
RewardsParams: RewardsParams{BidDuration: 14 * 24 * 3600}, // 14 days
RewardsParams: RewardsParams{BidDuration: 4 * 3600}, // 4 hours. NOTE: this is for testing!

Check warning on line 13 in x/auction/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/auction/genesis.go#L13

Added line #L13 was not covered by tests
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
RewardAuctionId: 0,
RewardsAuctions: []RewardsKV{},
RewardsBids: []BidKV{},
Expand Down
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
50 changes: 29 additions & 21 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 @@ -30,7 +28,11 @@
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, err := sdk.AccAddressFromBech32(bid.Bidder)
gsk967 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L31 - L33 were not covered by tests
}
err = k.sendCoins(k.accs.RewardsCollect, bidderAccAddr, a.Rewards)

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

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L35

Added line #L35 was not covered by tests
if err != nil {
return fmt.Errorf("can't send coins to finalize the auction [%w]", err)
}
Expand Down Expand Up @@ -79,25 +81,33 @@
return err
}

toAuction := msg.Amount
if lastBid != nil {
if msg.Sender == lastBid.Bidder {

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#L84-L86

Added lines #L84 - L86 were not covered by tests
// bidder updates his last bid: send only diff
toAuction = msg.Amount.SubAmount(lastBid.Amount)
} else {
returned := coin.UmeeInt(lastBid.Amount)
bidderAccAddr, err := sdk.AccAddressFromBech32(lastBid.Bidder)
gsk967 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err

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#L88-L93

Added lines #L88 - L93 were not covered by tests
}
if err = k.sendFromModule(bidderAccAddr, returned); err != nil {
return err

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

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L95-L96

Added lines #L95 - L96 were not covered by tests
}
}
}

sender, err := sdk.AccAddressFromBech32(msg.Sender)
gsk967 marked this conversation as resolved.
Show resolved Hide resolved
util.Panic(err)
if err != nil {
return err

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

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L102-L103

Added lines #L102 - L103 were not covered by tests
}

if !bytes.Equal(sender, lastBid.Bidder) {
returned := coin.UmeeInt(lastBid.Amount)
if err = k.sendFromModule(lastBid.Bidder, returned); err != nil {
return err
}
if err = k.sendToModule(sender, msg.Amount); err != nil {
return err
}
} else {
diff := msg.Amount.SubAmount(lastBid.Amount)
if err = k.sendToModule(sender, diff); err != nil {
return err
}
if err = k.sendToModule(sender, toAuction); err != nil {
return err

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

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L106-L107

Added lines #L106 - L107 were not covered by tests
}

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

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

View check run for this annotation

Codecov / codecov/patch

x/auction/keeper/rewards.go#L110

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

Expand All @@ -111,8 +121,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 @@ -122,7 +131,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