-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: adding second endpoint for async pay fee + renaming types * feat: adding escrow logic * feat: updating proto types & escrow logic * fix: stub fn & proto comment * feat: adding PayFee & PayFeeTimeout & escrow_test * test: adding happy path for EscrowPacketFee * fix: comments, error handling * fix: comments & grammar * test: adding unhappy path for escrow * tests(escrow): adding hasBalance check for module acc * test(PayFee): adding happy path for PayFee tests * tests(PayFee, PayFeeTimeout): adding tests * fix: adding relayers back to IdentifiedPacket * fix: removing refund acc from key * fix: storing IdentifiedPacketFee in state instead of Fee * feat: adding msg_server test for registerCPAddr, wiring for codec + stubs for sdk.Msg interface * test: adding msg_server test for PayPacketFee * test: adding PayPacketFeeAsync msg_server test * chore: updating PayFee -> DistributeFee & minor nits * nit: removing unnecessary nil check * refactor: add portId to store key & use packetId as param * fix: add DeleteFeeInEscrow & remove fee on successful distribution * tests: adding validation & signer tests for PayFee/Async & updating proto to use Signer sdk standard * chore: adding NewIdentifiedPacketFee fn * fix: getter/setter for counterparty address + fix NewIdentifiedPacketFee * fix: updating EscrowPacketFee with correct usage of coins api * test: adding balance check for refund acc after escrow * fix: remove unncessary errors * test: updating escrow tests + miscellaneous fixes * nit: updating var names * docs: godoc * refactor: IdentifiedPacketFee & Fee no longer pointers * fixes: small fixes * Update modules/apps/29-fee/keeper/escrow.go Co-authored-by: Aditya <[email protected]> * Update modules/apps/29-fee/keeper/escrow.go Co-authored-by: Aditya <[email protected]> * Update modules/apps/29-fee/keeper/keeper.go Co-authored-by: Aditya <[email protected]> * Update modules/apps/29-fee/keeper/msg_server.go Co-authored-by: Aditya <[email protected]> * Update modules/apps/29-fee/keeper/msg_server.go Co-authored-by: Aditya <[email protected]> * Update modules/apps/29-fee/types/msgs.go Co-authored-by: Aditya <[email protected]> * nit: proto doc & error fix * fix: escrow test * test: updating distribute fee tests * test: adding validation check for fee and updating tests * test: allow counterparty address to be arbitrary string * fix: message validation should pass if one fee is valid * Update modules/apps/29-fee/keeper/escrow.go Co-authored-by: colin axnér <[email protected]> * Update modules/apps/29-fee/keeper/escrow.go Co-authored-by: colin axnér <[email protected]> * fix: nits * Update modules/apps/29-fee/keeper/escrow.go Co-authored-by: colin axnér <[email protected]> * test: adding isZero check for msgs Co-authored-by: Aditya <[email protected]> Co-authored-by: colin axnér <[email protected]>
- Loading branch information
1 parent
dd4f8c7
commit 67bd594
Showing
21 changed files
with
2,111 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
"github.com/cosmos/ibc-go/modules/apps/29-fee/types" | ||
channeltypes "github.com/cosmos/ibc-go/modules/core/04-channel/types" | ||
) | ||
|
||
// EscrowPacketFee sends the packet fee to the 29-fee module account to hold in escrow | ||
func (k Keeper) EscrowPacketFee(ctx sdk.Context, refundAcc sdk.AccAddress, identifiedFee *types.IdentifiedPacketFee) error { | ||
// check if the refund account exists | ||
hasRefundAcc := k.authKeeper.GetAccount(ctx, refundAcc) | ||
if hasRefundAcc == nil { | ||
return sdkerrors.Wrap(types.ErrRefundAccNotFound, fmt.Sprintf("Account with address: %s not found", refundAcc)) | ||
} | ||
|
||
coins := identifiedFee.Fee.ReceiveFee | ||
coins = coins.Add(identifiedFee.Fee.AckFee...) | ||
coins = coins.Add(identifiedFee.Fee.TimeoutFee...) | ||
|
||
if err := k.bankKeeper.SendCoinsFromAccountToModule( | ||
ctx, refundAcc, types.ModuleName, coins, | ||
); err != nil { | ||
return err | ||
} | ||
|
||
// Store fee in state for reference later | ||
// feeInEscrow/<port-id>/<channel-id>/packet/<sequence-id>/ -> Fee (timeout, ack, onrecv) | ||
k.SetFeeInEscrow(ctx, identifiedFee) | ||
return nil | ||
} | ||
|
||
// DistributeFee pays the acknowledgement fee & receive fee for a given packetId while refunding the timeout fee to the refund account associated with the Fee | ||
func (k Keeper) DistributeFee(ctx sdk.Context, refundAcc, forwardRelayer, reverseRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error { | ||
// check if there is a Fee in escrow for the given packetId | ||
feeInEscrow, found := k.GetFeeInEscrow(ctx, packetID) | ||
if !found { | ||
return sdkerrors.Wrapf(types.ErrFeeNotFound, "with channelID %s, sequence %d", packetID.ChannelId, packetID.Sequence) | ||
} | ||
|
||
// get module accAddr | ||
feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) | ||
|
||
// send receive fee to forward relayer | ||
err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, forwardRelayer, feeInEscrow.Fee.ReceiveFee) | ||
if err != nil { | ||
return sdkerrors.Wrap(err, "failed to send fee to forward relayer") | ||
} | ||
|
||
// send ack fee to reverse relayer | ||
err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, reverseRelayer, feeInEscrow.Fee.AckFee) | ||
if err != nil { | ||
return sdkerrors.Wrap(err, "error sending fee to reverse relayer") | ||
} | ||
|
||
// refund timeout fee to refundAddr | ||
err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.TimeoutFee) | ||
if err != nil { | ||
return sdkerrors.Wrap(err, "error refunding timeout fee") | ||
} | ||
|
||
// removes the fee from the store as fee is now paid | ||
k.DeleteFeeInEscrow(ctx, packetID) | ||
|
||
return nil | ||
} | ||
|
||
// DistributeFeeTimeout pays the timeout fee for a given packetId while refunding the acknowledgement fee & receive fee to the refund account associated with the Fee | ||
func (k Keeper) DistributeFeeTimeout(ctx sdk.Context, refundAcc, timeoutRelayer sdk.AccAddress, packetID *channeltypes.PacketId) error { | ||
// check if there is a Fee in escrow for the given packetId | ||
feeInEscrow, found := k.GetFeeInEscrow(ctx, packetID) | ||
if !found { | ||
return sdkerrors.Wrap(types.ErrFeeNotFound, refundAcc.String()) | ||
} | ||
|
||
// get module accAddr | ||
feeModuleAccAddr := k.authKeeper.GetModuleAddress(types.ModuleName) | ||
|
||
// refund the receive fee | ||
err := k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.ReceiveFee) | ||
if err != nil { | ||
return sdkerrors.Wrap(err, "error refunding receive fee") | ||
} | ||
|
||
// refund the ack fee | ||
err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, refundAcc, feeInEscrow.Fee.AckFee) | ||
if err != nil { | ||
return sdkerrors.Wrap(err, "error refunding ack fee") | ||
} | ||
|
||
// pay the timeout fee to the reverse relayer | ||
err = k.bankKeeper.SendCoins(ctx, feeModuleAccAddr, timeoutRelayer, feeInEscrow.Fee.TimeoutFee) | ||
if err != nil { | ||
return sdkerrors.Wrap(err, "error sending fee to timeout relayer") | ||
} | ||
|
||
// removes the fee from the store as fee is now paid | ||
k.DeleteFeeInEscrow(ctx, packetID) | ||
|
||
return nil | ||
} |
Oops, something went wrong.