Skip to content

Commit

Permalink
make max fee amount required
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed Feb 28, 2024
1 parent b1a7ad2 commit 7af0973
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
2 changes: 0 additions & 2 deletions api/regen/ecocredit/marketplace/v1/tx.pulsar.go

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

2 changes: 0 additions & 2 deletions proto/regen/ecocredit/marketplace/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ message MsgBuyDirect {

// max_fee_amount is the maximum amount of buyer side fees being paid to the marketplace.
// If the marketplace fees end up being greater than this amount, the transaction will fail.
// If this field is left empty, the marketplace fees will be calculated based on the bid price
// and quantity and automatically deducted from the buyer's account.
// Fees are always paid in the same denomination as the bid price.
//
// Since Revision 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ Feature: Msg/BuyDirect
* bob has bank balance "110foo"
* alice has bank balance "0foo"
* buyer fees are 0.1 and seller fees are 0.05
* bob sets a max fee of "10foo"
When bob attempts to buy credits with quantity "10" and bid price "10foo"
Then expect no error
* expect alice bank balance "95foo"
Expand Down Expand Up @@ -438,6 +439,7 @@ Feature: Msg/BuyDirect
* bob has bank balance "240uregen"
* alice has bank balance "0regen"
* buyer fees are 0.2 and seller fees are 0.1
* bob sets a max fee of "40uregen"
When bob attempts to buy credits with quantity "10" and bid price "20uregen"
Then expect no error
* expect alice bank balance "180uregen"
Expand Down
18 changes: 10 additions & 8 deletions x/ecocredit/marketplace/keeper/msg_buy_direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,16 @@ func (k Keeper) BuyDirect(ctx context.Context, req *types.MsgBuyDirect) (*types.
totalCost := sdk.Coin{Amount: total.SdkIntTrim(), Denom: market.BankDenom}

// check max fee
if maxFee := order.MaxFeeAmount; maxFee != nil {
buyerFeeCoin := sdk.Coin{Amount: buyerFee.SdkIntTrim(), Denom: market.BankDenom}
if maxFee.IsLT(buyerFeeCoin) {
return nil, sdkerrors.ErrInvalidRequest.Wrapf(
"%s: max fee: %s, required fee: %s",
orderIndex, maxFee, buyerFeeCoin,
)
}
maxFee := order.MaxFeeAmount
if maxFee == nil {
maxFee = &sdk.Coin{Amount: sdk.NewInt(0), Denom: market.BankDenom}
}
buyerFeeCoin := sdk.Coin{Amount: buyerFee.SdkIntTrim(), Denom: market.BankDenom}
if maxFee.IsLT(buyerFeeCoin) {
return nil, sdkerrors.ErrInvalidRequest.Wrapf(
"%s: max fee: %s, required fee: %s",
orderIndex, maxFee, buyerFeeCoin,
)
}

// check address has the total cost
Expand Down
2 changes: 0 additions & 2 deletions x/ecocredit/marketplace/types/v1/tx.pb.go

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

0 comments on commit 7af0973

Please sign in to comment.