Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerKSI committed Nov 18, 2024
2 parents f6af97d + 3acf765 commit ea857b1
Show file tree
Hide file tree
Showing 18 changed files with 819 additions and 330 deletions.
290 changes: 236 additions & 54 deletions api/band/tunnel/v1beta1/params.pulsar.go

Large diffs are not rendered by default.

231 changes: 114 additions & 117 deletions api/band/tunnel/v1beta1/tx.pulsar.go

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions proto/band/tunnel/v1beta1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ import "cosmos/base/v1beta1/coin.proto";
message Params {
option (gogoproto.equal) = true; // Use gogoproto.equal for proto3 message equality checks

// min_deposit is the minimum deposit required to create a tunnel
// min_deposit is the minimum deposit required to create a tunnel.
repeated cosmos.base.v1beta1.Coin min_deposit = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
// min_interval is the minimum interval in seconds
// min_interval is the minimum interval in seconds.
uint64 min_interval = 2;
// max_interval is the maximum interval in seconds.
uint64 max_interval = 3;
// min_deviation_bps is the minimum deviation in basis points.
uint64 min_deviation_bps = 4 [(gogoproto.customname) = "MinDeviationBPS"];
// max_deviation_bps is the maximum deviation in basis points.
uint64 max_deviation_bps = 5 [(gogoproto.customname) = "MaxDeviationBPS"];
// max_signals defines the maximum number of signals allowed per tunnel.
uint64 max_signals = 3;
// base_packet_fee is the base fee for each packet
repeated cosmos.base.v1beta1.Coin base_packet_fee = 4
uint64 max_signals = 6;
// base_packet_fee is the base fee for each packet.
repeated cosmos.base.v1beta1.Coin base_packet_fee = 7
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
}
6 changes: 2 additions & 4 deletions proto/band/tunnel/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ message MsgDepositToTunnel {
option (amino.name) = "tunnel/MsgDepositToTunnel";

// tunnel_id defines the unique id of the tunnel.
uint64 tunnel_id = 1
[(gogoproto.customname) = "TunnelID", (gogoproto.jsontag) = "tunnel_id", (amino.dont_omitempty) = true];
uint64 tunnel_id = 1 [(gogoproto.customname) = "TunnelID"];

// amount to be deposited by depositor.
repeated cosmos.base.v1beta1.Coin amount = 2 [
Expand All @@ -161,8 +160,7 @@ message MsgWithdrawFromTunnel {
option (amino.name) = "tunnel/MsgWithdrawFromTunnel";

// tunnel_id defines the unique id of the tunnel.
uint64 tunnel_id = 1
[(gogoproto.customname) = "TunnelID", (gogoproto.jsontag) = "tunnel_id", (amino.dont_omitempty) = true];
uint64 tunnel_id = 1 [(gogoproto.customname) = "TunnelID"];

// amount to be withdrawn by withdrawer.
repeated cosmos.base.v1beta1.Coin amount = 2 [
Expand Down
12 changes: 9 additions & 3 deletions x/tunnel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The Tunnel module is designed to decentralize the creation of push-based price d
- [ActiveTunnelID](#activetunnelid)
- [Tunnel](#tunnel-1)
- [Packet](#packet-1)
- [LatestPrices](#latestPrices)
- [LatestPrices](#latestprices)
- [Deposit](#deposit)
- [Params](#params)
- [Msg](#msg)
Expand All @@ -31,8 +31,8 @@ The Tunnel module is designed to decentralize the creation of push-based price d
- [MsgActivate](#msgactivate)
- [MsgDeactivate](#msgdeactivate)
- [MsgTriggerTunnel](#msgtriggertunnel)
- [MsgDepositToTunnel](#MsgDepositToTunnel)
- [MsgWithdrawFromTunnel](#MsgWithdrawFromTunnel)
- [MsgDepositToTunnel](#msgdeposittotunnel)
- [MsgWithdrawFromTunnel](#msgwithdrawfromtunnel)
- [Events](#events)
- [Event: `create_tunnel`](#event-create_tunnel)
- [Event: `update_and_reset_tunnel`](#event-update_and_reset_tunnel)
Expand Down Expand Up @@ -189,6 +189,12 @@ type Params struct {
MinDeposit sdk.Coins
// MinInterval is the minimum interval in seconds.
MinInterval uint64
// MinInterval is the minimum interval in seconds.
MinInterval uint64
// MinDeviationBPS is the minimum deviation in basis points.
MinDeviationBPS uint64
// MaxDeviationBPS is the maximum deviation in basis points.
MaxDeviationBPS uint64
// MaxSignals defines the maximum number of signals allowed per tunnel.
MaxSignals uint64
// BasePacketFee is the base fee for each packet.
Expand Down
1 change: 0 additions & 1 deletion x/tunnel/client/cli/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func TestParseSignalDeviations(t *testing.T) {
defer cleanup()

result, err := parseSignalDeviations(file)

require.NoError(t, err)
require.Equal(t, signalDeviations, result.SignalDeviations)
}
Expand Down
2 changes: 1 addition & 1 deletion x/tunnel/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewKeeper(

// ensure that authority is a valid AccAddress
if _, err := sdk.AccAddressFromBech32(authority); err != nil {
panic(fmt.Errorf("invalid bandtss authority address: %w", err))
panic(fmt.Errorf("invalid authority address: %w", err))
}

return Keeper{
Expand Down
File renamed without changes.
25 changes: 15 additions & 10 deletions x/tunnel/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ func (ms msgServer) CreateTunnel(
) (*types.MsgCreateTunnelResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// validate signal infos and interval
params := ms.Keeper.GetParams(ctx)
if len(msg.SignalDeviations) > int(params.MaxSignals) {
return nil, types.ErrMaxSignalsExceeded

// validate signal infos and interval
if err := types.ValidateSignalDeviations(msg.SignalDeviations, params); err != nil {
return nil, err
}

if msg.Interval < params.MinInterval {
return nil, types.ErrIntervalTooLow
// validate interval
if err := types.ValidateInterval(msg.Interval, params); err != nil {
return nil, err
}

creator, err := sdk.AccAddressFromBech32(msg.Creator)
Expand Down Expand Up @@ -83,13 +85,16 @@ func (ms msgServer) UpdateAndResetTunnel(
) (*types.MsgUpdateAndResetTunnelResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// validate signal infos and interval
params := ms.Keeper.GetParams(ctx)
if len(msg.SignalDeviations) > int(params.MaxSignals) {
return nil, types.ErrMaxSignalsExceeded

// validate signal infos and interval
if err := types.ValidateSignalDeviations(msg.SignalDeviations, params); err != nil {
return nil, err
}
if msg.Interval < params.MinInterval {
return nil, types.ErrIntervalTooLow

// validate interval
if err := types.ValidateInterval(msg.Interval, params); err != nil {
return nil, err
}

tunnel, err := ms.Keeper.GetTunnel(ctx, msg.TunnelID)
Expand Down
69 changes: 58 additions & 11 deletions x/tunnel/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *KeeperTestSuite) TestMsgCreateTunnel() {

return types.NewMsgCreateTunnel(
signalDeviations,
10,
60,
route,
feedstypes.ENCODER_FIXED_POINT_ABI,
sdk.NewCoins(sdk.NewCoin("uband", sdkmath.NewInt(100))),
Expand All @@ -53,7 +53,26 @@ func (s *KeeperTestSuite) TestMsgCreateTunnel() {
expErr: true,
expErrMsg: "max signals exceeded",
},
"interval too low": {
"deviation out of range": {
preRun: func() (*types.MsgCreateTunnel, error) {
params := types.DefaultParams()
params.MinDeviationBPS = 1000
params.MaxDeviationBPS = 10000
s.Require().NoError(s.keeper.SetParams(s.ctx, params))

return types.NewMsgCreateTunnel(
signalDeviations,
60,
route,
feedstypes.ENCODER_FIXED_POINT_ABI,
sdk.NewCoins(sdk.NewCoin("uband", sdkmath.NewInt(100))),
sdk.AccAddress([]byte("creator_address")),
)
},
expErr: true,
expErrMsg: "deviation out of range",
},
"interval out of range": {
preRun: func() (*types.MsgCreateTunnel, error) {
params := types.DefaultParams()
params.MinInterval = 5
Expand All @@ -69,7 +88,7 @@ func (s *KeeperTestSuite) TestMsgCreateTunnel() {
)
},
expErr: true,
expErrMsg: "interval too low",
expErrMsg: "interval out of range",
},
"all good without initial deposit": {
preRun: func() (*types.MsgCreateTunnel, error) {
Expand All @@ -81,7 +100,7 @@ func (s *KeeperTestSuite) TestMsgCreateTunnel() {

return types.NewMsgCreateTunnel(
signalDeviations,
10,
60,
route,
feedstypes.ENCODER_FIXED_POINT_ABI,
sdk.NewCoins(),
Expand All @@ -107,7 +126,7 @@ func (s *KeeperTestSuite) TestMsgCreateTunnel() {

return types.NewMsgCreateTunnel(
signalDeviations,
10,
60,
route,
feedstypes.ENCODER_FIXED_POINT_ABI,
depositAmount,
Expand Down Expand Up @@ -169,14 +188,42 @@ func (s *KeeperTestSuite) TestMsgUpdateAndResetTunnel() {
return types.NewMsgUpdateAndResetTunnel(
1,
editedSignalDeviations,
10,
60,
sdk.AccAddress([]byte("creator_address")).String(),
)
},
expErr: true,
expErrMsg: "max signals exceeded",
},
"interval too low": {
"deviation out of range": {
preRun: func() *types.MsgUpdateAndResetTunnel {
params := types.DefaultParams()
params.MinDeviationBPS = 1000
params.MaxDeviationBPS = 10000
err := s.keeper.SetParams(s.ctx, params)
s.Require().NoError(err)

s.AddSampleTunnel(false)

editedSignalDeviations := []types.SignalDeviation{
{
SignalID: "BTC",
SoftDeviationBPS: 200,
HardDeviationBPS: 200,
},
}

return types.NewMsgUpdateAndResetTunnel(
1,
editedSignalDeviations,
60,
sdk.AccAddress([]byte("creator_address")).String(),
)
},
expErr: true,
expErrMsg: "deviation out of range",
},
"interval out of range": {
preRun: func() *types.MsgUpdateAndResetTunnel {
params := types.DefaultParams()
params.MinInterval = 5
Expand All @@ -201,14 +248,14 @@ func (s *KeeperTestSuite) TestMsgUpdateAndResetTunnel() {
)
},
expErr: true,
expErrMsg: "interval too low",
expErrMsg: "interval out of range",
},
"tunnel not found": {
preRun: func() *types.MsgUpdateAndResetTunnel {
return types.NewMsgUpdateAndResetTunnel(
1,
[]types.SignalDeviation{},
10,
60,
sdk.AccAddress([]byte("creator_address")).String(),
)
},
Expand All @@ -222,7 +269,7 @@ func (s *KeeperTestSuite) TestMsgUpdateAndResetTunnel() {
return types.NewMsgUpdateAndResetTunnel(
1,
[]types.SignalDeviation{},
10,
60,
sdk.AccAddress([]byte("wrong_creator_address")).String(),
)
},
Expand All @@ -244,7 +291,7 @@ func (s *KeeperTestSuite) TestMsgUpdateAndResetTunnel() {
return types.NewMsgUpdateAndResetTunnel(
1,
editedSignalDeviations,
10,
60,
sdk.AccAddress([]byte("creator_address")).String(),
)
},
Expand Down
37 changes: 19 additions & 18 deletions x/tunnel/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ import (
var (
ErrInvalidGenesis = errorsmod.Register(ModuleName, 2, "invalid genesis")
ErrMaxSignalsExceeded = errorsmod.Register(ModuleName, 3, "max signals exceeded")
ErrIntervalTooLow = errorsmod.Register(ModuleName, 4, "interval too low")
ErrTunnelNotFound = errorsmod.Register(ModuleName, 5, "tunnel not found")
ErrLatestPricesNotFound = errorsmod.Register(ModuleName, 6, "latest prices not found")
ErrPacketNotFound = errorsmod.Register(ModuleName, 7, "packet not found")
ErrNoPacketContent = errorsmod.Register(ModuleName, 8, "no packet content")
ErrInvalidTunnelCreator = errorsmod.Register(ModuleName, 9, "invalid creator of the tunnel")
ErrAccountAlreadyExist = errorsmod.Register(ModuleName, 10, "account already exist")
ErrInvalidRoute = errorsmod.Register(ModuleName, 11, "invalid tunnel route")
ErrInactiveTunnel = errorsmod.Register(ModuleName, 12, "inactive tunnel")
ErrAlreadyActive = errorsmod.Register(ModuleName, 13, "already active")
ErrAlreadyInactive = errorsmod.Register(ModuleName, 14, "already inactive")
ErrInvalidDepositDenom = errorsmod.Register(ModuleName, 15, "invalid deposit denom")
ErrDepositNotFound = errorsmod.Register(ModuleName, 16, "deposit not found")
ErrInsufficientDeposit = errorsmod.Register(ModuleName, 17, "insufficient deposit")
ErrInsufficientFund = errorsmod.Register(ModuleName, 18, "insufficient fund")
ErrDeviationNotFound = errorsmod.Register(ModuleName, 19, "deviation not found")
ErrInvalidVersion = errorsmod.Register(ModuleName, 20, "invalid ICS20 version")
ErrChannelCapabilityNotFound = errorsmod.Register(ModuleName, 21, "channel capability not found")
ErrIntervalOutOfRange = errorsmod.Register(ModuleName, 4, "interval out of range")
ErrDeviationOutOfRange = errorsmod.Register(ModuleName, 5, "deviation out of range")
ErrTunnelNotFound = errorsmod.Register(ModuleName, 6, "tunnel not found")
ErrLatestPricesNotFound = errorsmod.Register(ModuleName, 7, "latest prices not found")
ErrPacketNotFound = errorsmod.Register(ModuleName, 8, "packet not found")
ErrNoPacketContent = errorsmod.Register(ModuleName, 9, "no packet content")
ErrInvalidTunnelCreator = errorsmod.Register(ModuleName, 10, "invalid creator of the tunnel")
ErrAccountAlreadyExist = errorsmod.Register(ModuleName, 11, "account already exist")
ErrInvalidRoute = errorsmod.Register(ModuleName, 12, "invalid tunnel route")
ErrInactiveTunnel = errorsmod.Register(ModuleName, 13, "inactive tunnel")
ErrAlreadyActive = errorsmod.Register(ModuleName, 14, "already active")
ErrAlreadyInactive = errorsmod.Register(ModuleName, 15, "already inactive")
ErrInvalidDepositDenom = errorsmod.Register(ModuleName, 16, "invalid deposit denom")
ErrDepositNotFound = errorsmod.Register(ModuleName, 17, "deposit not found")
ErrInsufficientDeposit = errorsmod.Register(ModuleName, 18, "insufficient deposit")
ErrInsufficientFund = errorsmod.Register(ModuleName, 19, "insufficient fund")
ErrDeviationNotFound = errorsmod.Register(ModuleName, 20, "deviation not found")
ErrInvalidVersion = errorsmod.Register(ModuleName, 21, "invalid ICS20 version")
ErrChannelCapabilityNotFound = errorsmod.Register(ModuleName, 22, "channel capability not found")
)
Loading

0 comments on commit ea857b1

Please sign in to comment.