Skip to content

Commit

Permalink
fix: include status Refunding to poller query (#58)
Browse files Browse the repository at this point in the history
* add status refunding

* Fix min fee check
  • Loading branch information
zale144 authored Dec 11, 2024
1 parent db9780b commit 93b2ff9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 466 deletions.
11 changes: 9 additions & 2 deletions eibc/order_fulfiller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,23 @@ func (ol *orderFulfiller) fulfillAuthorizedDemandOrders(demandOrder ...*demandOr
fulfillMsgs := make([]sdk.Msg, len(demandOrder))

for i, order := range demandOrder {
fulfillMsgs[i] = types.NewMsgFulfillOrderAuthorized(
msg := types.NewMsgFulfillOrderAuthorized(
order.id,
order.rollappId,
order.lpAddress,
ol.operatorAddress,
order.fee.Amount.String(),
order.price,
order.operatorFeePart,
sdk.IntProto{Int: order.amount},
sdk.DecProto{Dec: order.operatorFeePart},
order.settlementValidated,
)

if err := msg.ValidateBasic(); err != nil {
ol.logger.Error("failed to validate message", zap.Error(err))
return fmt.Errorf("failed to validate message: %w", err)
}
fulfillMsgs[i] = msg
}

// bech32 decode the policy address
Expand Down
2 changes: 1 addition & 1 deletion eibc/order_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newOrderPoller(
}

const (
ordersQuery = `{"query": "{ibcTransferDetails(filter: {network: {equalTo: \"%s\"} status: {equalTo: EibcPending}, blockHeight: { greaterThan: \"%s\" }}) {nodes { eibcOrderId amount proofHeight blockHeight price rollappId eibcFee }}}"}`
ordersQuery = `{"query": "{ibcTransferDetails(filter: {network: {equalTo: \"%s\"} status: { in: [EibcPending, Refunding] }, blockHeight: { greaterThan: \"%s\" }}) {nodes { eibcOrderId amount proofHeight blockHeight price rollappId eibcFee }}}"}`
)

type Order struct {
Expand Down
2 changes: 1 addition & 1 deletion eibc/order_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func (or *orderTracker) filterLPsForOrder(order *demandOrder) ([]*lp, []string)
}

// check the fee is at least the minimum for what the lp wants
minFee := sdk.NewDecFromInt(order.fee.Amount).Mul(rollapp.minFeePercentage).RoundInt()
minFee := sdk.NewDecFromInt(order.amount).Mul(rollapp.minFeePercentage).RoundInt()

if order.fee.Amount.LT(minFee) {
lpSkip = append(lpSkip, fmt.Sprintf("%s: min_fee", lp.address))
Expand Down
51 changes: 15 additions & 36 deletions types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@ package types

import (
"encoding/hex"
"errors"
"fmt"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

var (
_ = sdk.Msg(&MsgFulfillOrderAuthorized{})
_ = sdk.Msg(&MsgFinalizePacketByPacketKey{})
sdk "github.com/cosmos/cosmos-sdk/types"
)

var _ = sdk.Msg(&MsgFulfillOrderAuthorized{})

func NewMsgFulfillOrderAuthorized(
orderId,
rollappId,
granterAddress,
operatorFeeAddress,
expectedFee string,
price sdk.Coins,
operatorFeePart sdk.Dec,
amount sdk.IntProto,
fulfillerFeePart sdk.DecProto,
settlementValidated bool,
) *MsgFulfillOrderAuthorized {
return &MsgFulfillOrderAuthorized{
Expand All @@ -32,7 +30,8 @@ func NewMsgFulfillOrderAuthorized(
OperatorFeeAddress: operatorFeeAddress,
ExpectedFee: expectedFee,
Price: price,
OperatorFeeShare: sdk.DecProto{Dec: operatorFeePart},
Amount: amount,
OperatorFeeShare: fulfillerFeePart,
SettlementValidated: settlementValidated,
}
}
Expand Down Expand Up @@ -72,12 +71,16 @@ func (msg *MsgFulfillOrderAuthorized) ValidateBasic() error {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, err.Error())
}

if msg.Price.IsAnyNegative() {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "price cannot be negative")
if !msg.Price.IsValid() {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "price is invalid")
}

if msg.OperatorFeeShare.Dec.IsNegative() {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "operator fee share cannot be negative")
if msg.Amount.Int.IsNil() || msg.Amount.Int.IsNegative() {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "amount cannot be empty or negative")
}

if msg.OperatorFeeShare.Dec.IsNil() || msg.OperatorFeeShare.Dec.IsNegative() {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "operator fee share cannot be empty or negative")
}

if msg.OperatorFeeShare.Dec.GT(sdk.OneDec()) {
Expand Down Expand Up @@ -128,27 +131,3 @@ func validateCommon(orderId, fee string, address ...string) error {

return nil
}

func (m MsgFinalizePacketByPacketKey) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(m.Sender)
if err != nil {
return errors.Join(
sdkerrors.ErrInvalidAddress,
errorsmod.Wrapf(err, "sender must be a valid bech32 address: %s", m.Sender),
)
}
if len(m.PacketKey) == 0 {
return fmt.Errorf("packet key must be non-empty")
}

return nil
}

func (m MsgFinalizePacketByPacketKey) GetSigners() []sdk.AccAddress {
signer, _ := sdk.AccAddressFromBech32(m.Sender)
return []sdk.AccAddress{signer}
}

func (*MsgFinalizePacketByPacketKey) XXX_MessageName() string {
return "dymensionxyz.dymension.delayedack.MsgFinalizePacketByPacketKey"
}
Loading

0 comments on commit 93b2ff9

Please sign in to comment.