Skip to content

Commit

Permalink
remove packet fee
Browse files Browse the repository at this point in the history
  • Loading branch information
nkitlabs committed Jan 7, 2025
1 parent 833f448 commit 8d87db3
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 634 deletions.
445 changes: 68 additions & 377 deletions api/band/tunnel/v1beta1/tunnel.pulsar.go

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions proto/band/tunnel/v1beta1/tunnel.proto
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,8 @@ message Packet {
repeated band.feeds.v1beta1.Price prices = 3 [(gogoproto.nullable) = false];
// receipt represents the confirmation of the packet delivery to the destination via the specified route.
google.protobuf.Any receipt = 4 [(cosmos_proto.accepts_interface) = "PacketReceiptI"];
// base_fee is the base fee of the packet
repeated cosmos.base.v1beta1.Coin base_fee = 5
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
// route_fee is the route fee of the packet
repeated cosmos.base.v1beta1.Coin route_fee = 6
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
// created_at is the timestamp when the packet is created
int64 created_at = 7;
int64 created_at = 5;
}

// Deposit defines an amount deposited by an account address to the tunnel.
Expand Down
17 changes: 0 additions & 17 deletions x/tunnel/keeper/keeper_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ func (k Keeper) CreatePacket(
tunnelID uint64,
prices []feedstypes.Price,
) (types.Packet, error) {
// get tunnel and prices info
params := k.GetParams(ctx)

tunnel, err := k.GetTunnel(ctx, tunnelID)
if err != nil {
return types.Packet{}, err
Expand All @@ -159,25 +156,11 @@ func (k Keeper) CreatePacket(
return types.Packet{}, sdkerrors.Wrapf(err, "failed to deduct base packet fee for tunnel %d", tunnel.ID)
}

// get the route
route, err := tunnel.GetRouteValue()
if err != nil {
return types.Packet{}, err
}

// get the route fee
routeFee, err := k.GetRouteFee(ctx, route)
if err != nil {
return types.Packet{}, err
}

tunnel.Sequence++
packet := types.NewPacket(
tunnelID,
tunnel.Sequence,
prices,
params.BasePacketFee,
routeFee,
ctx.BlockTime().Unix(),
)

Expand Down
8 changes: 0 additions & 8 deletions x/tunnel/keeper/keeper_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ func (s *KeeperTestSuite) TestGetSetPacket() {
func (s *KeeperTestSuite) TestCreatePacket() {
ctx, k := s.ctx, s.keeper

params := k.GetParams(ctx)

feePayer := sdk.AccAddress([]byte("fee_payer_address"))
tunnel := types.Tunnel{
ID: 1,
Expand All @@ -75,10 +73,6 @@ func (s *KeeperTestSuite) TestCreatePacket() {
{Status: feedstypes.PRICE_STATUS_AVAILABLE, SignalID: "CS:BAND-USD", Price: 5000000, Timestamp: 1733000000},
}

s.bandtssKeeper.EXPECT().GetSigningFee(gomock.Any()).Return(
sdk.NewCoins(sdk.NewCoin("uband", sdkmath.NewInt(20))), nil,
)

s.bankKeeper.EXPECT().
SendCoinsFromAccountToModule(ctx, feePayer, types.ModuleName, k.GetParams(ctx).BasePacketFee).
Return(nil)
Expand All @@ -93,8 +87,6 @@ func (s *KeeperTestSuite) TestCreatePacket() {
TunnelID: 1,
Sequence: 1,
Prices: prices,
BaseFee: params.BasePacketFee,
RouteFee: sdk.NewCoins(sdk.NewCoin("uband", sdkmath.NewInt(20))),
CreatedAt: ctx.BlockTime().Unix(),
}

Expand Down
7 changes: 6 additions & 1 deletion x/tunnel/keeper/keeper_packet_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func (k Keeper) SendTSSPacket(
route.Encoder,
)

tssFee, err := k.bandtssKeeper.GetSigningFee(ctx)
if err != nil {
return nil, err
}

// try signing TSS packet, if success, write the context.
signingID, err := k.bandtssKeeper.CreateTunnelSigningRequest(
ctx,
Expand All @@ -28,7 +33,7 @@ func (k Keeper) SendTSSPacket(
route.DestinationContractAddress,
content,
feePayer,
packet.RouteFee,
tssFee,
)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions x/tunnel/keeper/keeper_packet_tss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func (s *KeeperTestSuite) TestSendTSSPacket() {
1, // tunnelID
1, // sequence
[]feedstypes.Price{}, // priceInfos[]
sdk.NewCoins(), // baseFee
sdk.NewCoins(sdk.NewCoin("uband", sdkmath.NewInt(20))), // routeFee
time.Now().Unix(),
)

s.bandtssKeeper.EXPECT().GetSigningFee(ctx).Return(sdk.NewCoins(sdk.NewCoin("uband", sdkmath.NewInt(20))), nil)

// Mock the TSS keeper and set the state for checking later
s.bandtssKeeper.EXPECT().CreateTunnelSigningRequest(
gomock.Any(),
Expand Down
12 changes: 0 additions & 12 deletions x/tunnel/keeper/keeper_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,3 @@ func (k Keeper) GenerateTunnelAccount(ctx sdk.Context, key string) (sdk.AccAddre

return tunnelAccAddr, nil
}

// GetRouteFee returns the fee of the given route
func (k Keeper) GetRouteFee(ctx sdk.Context, route types.RouteI) (sdk.Coins, error) {
switch route.(type) {
case *types.TSSRoute:
return k.bandtssKeeper.GetSigningFee(ctx)
case *types.IBCRoute:
return sdk.Coins{}, nil
default:
return sdk.Coins{}, types.ErrInvalidRoute
}
}
5 changes: 0 additions & 5 deletions x/tunnel/types/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
proto "github.com/cosmos/gogoproto/proto"

"github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

feedstypes "github.com/bandprotocol/chain/v3/x/feeds/types"
Expand All @@ -18,17 +17,13 @@ func NewPacket(
tunnelID uint64,
sequence uint64,
prices []feedstypes.Price,
baseFee sdk.Coins,
routeFee sdk.Coins,
createdAt int64,
) Packet {
return Packet{
TunnelID: tunnelID,
Sequence: sequence,
Prices: prices,
Receipt: nil,
BaseFee: baseFee,
RouteFee: routeFee,
CreatedAt: createdAt,
}
}
Expand Down
4 changes: 2 additions & 2 deletions x/tunnel/types/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestGetSetPacketReceipt(t *testing.T) {
packet := types.NewPacket(1, 1, nil, nil, nil, 0)
packet := types.NewPacket(1, 1, nil, 0)
receipt := &types.TSSPacketReceipt{SigningID: 1}

err := packet.SetReceipt(receipt)
Expand All @@ -23,7 +23,7 @@ func TestGetSetPacketReceipt(t *testing.T) {
}

func TestPacketUnpackInterfaces(t *testing.T) {
packet := types.NewPacket(1, 1, nil, nil, nil, 0)
packet := types.NewPacket(1, 1, nil, 0)
packetResult := &types.TSSPacketReceipt{SigningID: 1}

err := packet.SetReceipt(packetResult)
Expand Down
Loading

0 comments on commit 8d87db3

Please sign in to comment.