-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
satawatnack
committed
Nov 25, 2024
1 parent
74212e6
commit 84fb20e
Showing
19 changed files
with
1,960 additions
and
93 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 @@ | ||
bandd tx tunnel create-tunnel ibc-hook channel-0 wasm1vjq0k3fj47s8wns4a7zw5c4lsjd8l6r2kzzlpk 1 1uband 10 ./scripts/tunnel/signal_deviations.json --from requester --keyring-backend test --gas-prices 0.0025uband -y --chain-id bandchain |
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
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,51 @@ | ||
package keeper | ||
|
||
import ( | ||
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" | ||
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/bandprotocol/chain/v3/x/tunnel/types" | ||
) | ||
|
||
// SendIBCHookPacket sends a packet to the destination chain using IBC Hook | ||
func (k Keeper) SendIBCHookPacket( | ||
ctx sdk.Context, | ||
route *types.IBCHookRoute, | ||
packet types.Packet, | ||
feePayer sdk.AccAddress, | ||
) (types.PacketReceiptI, error) { | ||
// create memo string for ibc transfer | ||
memoStr, err := types.NewIBCHookMemo( | ||
route.DestinationContractAddress, | ||
packet.TunnelID, | ||
packet.Sequence, | ||
packet.Prices, | ||
packet.CreatedAt, | ||
).String() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// create ibc transfer message | ||
msg := ibctransfertypes.NewMsgTransfer( | ||
ibctransfertypes.PortID, | ||
route.ChannelID, | ||
// TODO: align the token to send with msg transfer | ||
sdk.NewInt64Coin("uband", 1), | ||
feePayer.String(), | ||
route.DestinationContractAddress, | ||
clienttypes.ZeroHeight(), | ||
uint64(ctx.BlockTime().UnixNano()+packetExpireTime), | ||
memoStr, | ||
) | ||
|
||
// send packet | ||
res, err := k.transferKeeper.Transfer(ctx, msg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return types.NewIBCHookPacketReceipt(res.Sequence), nil | ||
} |
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,50 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"time" | ||
|
||
"go.uber.org/mock/gomock" | ||
|
||
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
feedstypes "github.com/bandprotocol/chain/v3/x/feeds/types" | ||
"github.com/bandprotocol/chain/v3/x/tunnel/types" | ||
) | ||
|
||
func (s *KeeperTestSuite) TestSendRouterPacket() { | ||
ctx, k := s.ctx, s.keeper | ||
|
||
route := &types.IBCHookRoute{ | ||
ChannelID: "channel-0", | ||
DestinationContractAddress: "wasm1vjq0k3fj47s8wns4a7zw5c4lsjd8l6r2kzzlpk", | ||
} | ||
|
||
packet := types.Packet{ | ||
TunnelID: 1, | ||
Sequence: 1, | ||
Prices: []feedstypes.Price{}, | ||
CreatedAt: time.Now().Unix(), | ||
} | ||
|
||
expectedPacketReceipt := types.IBCHookPacketReceipt{ | ||
Sequence: 1, | ||
} | ||
|
||
s.transferKeeper.EXPECT().Transfer(ctx, gomock.Any()).Return(&ibctransfertypes.MsgTransferResponse{ | ||
Sequence: 1, | ||
}, nil) | ||
|
||
content, err := k.SendIBCHookPacket( | ||
ctx, | ||
route, | ||
packet, | ||
sdk.AccAddress("feePayer"), | ||
) | ||
s.Require().NoError(err) | ||
|
||
receipt, ok := content.(*types.IBCHookPacketReceipt) | ||
s.Require().True(ok) | ||
s.Require().Equal(expectedPacketReceipt, *receipt) | ||
} |
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
Oops, something went wrong.