Skip to content

Commit

Permalink
init (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidterpay authored May 21, 2024
1 parent d19bdf9 commit 147396b
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 47 deletions.
19 changes: 13 additions & 6 deletions x/auction/keeper/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ func (k Keeper) ExtractBid(ctx sdk.Context, bidder sdk.AccAddress, bid sdk.Coin)

var proposerReward sdk.Coins
if params.ProposerFee.IsZero() {
// send the entire bid to the escrow account when no proposer fee is set
if err := k.bankKeeper.SendCoins(ctx, bidder, escrowAddress, sdk.NewCoins(bid)); err != nil {
return err
}
return k.SendBid(ctx, bidder, escrowAddress, sdk.NewCoins(bid))
} else {

Check warning on line 106 in x/auction/keeper/auction.go

View workflow job for this annotation

GitHub Actions / golangci-lint

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
rewardsAddress, err := k.rewardsAddressProvider.GetRewardsAddress(ctx)
if err != nil {
Expand All @@ -118,7 +115,7 @@ func (k Keeper) ExtractBid(ctx sdk.Context, bidder sdk.AccAddress, bid sdk.Coin)
bid := sdk.NewDecCoinsFromCoins(bid)
proposerReward, _ = bid.MulDecTruncate(params.ProposerFee).TruncateDecimal()

if err := k.bankKeeper.SendCoins(ctx, bidder, rewardsAddress, proposerReward); err != nil {
if err := k.SendBid(ctx, bidder, rewardsAddress, proposerReward); err != nil {
return err
}

Expand All @@ -127,7 +124,7 @@ func (k Keeper) ExtractBid(ctx sdk.Context, bidder sdk.AccAddress, bid sdk.Coin)
escrowTotal := bid.Sub(sdk.NewDecCoinsFromCoins(proposerReward...))
escrowReward, _ := escrowTotal.TruncateDecimal()

if err := k.bankKeeper.SendCoins(ctx, bidder, escrowAddress, escrowReward); err != nil {
if err := k.SendBid(ctx, bidder, escrowAddress, escrowReward); err != nil {
return err
}
}
Expand Down Expand Up @@ -206,6 +203,16 @@ func (k Keeper) ValidateBundleTimeouts(bidInfo *types.BidInfo) error {
return nil
}

// SendBid sends the bid from the bidder to the relevant address.
func (k Keeper) SendBid(ctx sdk.Context, from, to sdk.AccAddress, bid sdk.Coins) error {
moduleAddress := k.accountKeeper.GetModuleAddress(types.ModuleName)
if moduleAddress.Equals(to) {
return k.bankKeeper.SendCoinsFromAccountToModule(ctx, from, types.ModuleName, bid)
}

return k.bankKeeper.SendCoins(ctx, from, to, bid)
}

// filterSigners removes any signers from the currentSigners map that are not in the txSigners map.
func filterSigners(currentSigners, txSigners map[string]struct{}) {
for signer := range currentSigners {
Expand Down
2 changes: 2 additions & 0 deletions x/auction/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey

accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
rewardsAddressProvider types.RewardsAddressProvider

Expand Down Expand Up @@ -73,6 +74,7 @@ func NewKeeperWithRewardsAddressProvider(
return Keeper{
cdc: cdc,
storeKey: storeKey,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
rewardsAddressProvider: rewardsAddressProvider,
authority: authority,
Expand Down
5 changes: 3 additions & 2 deletions x/auction/types/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
context "context"
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand All @@ -18,7 +18,8 @@ type AccountKeeper interface {
//
//go:generate mockery --name BankKeeper --output ./mocks --outpkg mocks --case underscore
type BankKeeper interface {
SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
SendCoins(ctx context.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
}

Expand Down
9 changes: 2 additions & 7 deletions x/auction/types/mocks/account_keeper.go

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

27 changes: 16 additions & 11 deletions x/auction/types/mocks/bank_keeper.go

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

9 changes: 2 additions & 7 deletions x/auction/types/mocks/distribution_keeper.go

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

9 changes: 2 additions & 7 deletions x/auction/types/mocks/rewards_address_provider.go

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

9 changes: 2 additions & 7 deletions x/auction/types/mocks/staking_keeper.go

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

0 comments on commit 147396b

Please sign in to comment.