-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Tunnel] implement route - IBC Hook #485
Open
satawatnack
wants to merge
17
commits into
master
Choose a base branch
from
tunnel-ibc-hook
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
84fb20e
init tunnel ibc hook
92439a1
Merge branch 'tunnel-ibc' into tunnel-ibc-hook
75a1316
Merge branch 'master' into tunnel-ibc-hook
da789a7
add mint uhook coin
7836b72
Merge branch 'master' into tunnel-ibc-hook
830e5a7
fix review
975bcdf
update hook transfer
5d581f2
add update route
32d762b
Merge branch 'master' into tunnel-ibc-hook
12643e9
clean up
46ee44f
update create ibc hook tunnel script
db37cfb
clean up
df79661
clean up
8d79515
Merge branch 'master' into tunnel-ibc-hook
5436e84
update hook route
3e50b99
clean up
337078d
clean up
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 osmo1hsj6zc68xh4ydpt57mkynye7frhx5ndzdqhkcl88k4duyfgzqc9qf8gxdx 1000000000uband 60 ./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,78 @@ | ||
package keeper | ||
|
||
import ( | ||
"time" | ||
|
||
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, | ||
interval uint64, | ||
) (types.PacketReceiptI, error) { | ||
// create memo string for ibc transfer | ||
pricePacket := types.NewTunnelPricesPacketData(packet.TunnelID, packet.Sequence, packet.Prices, packet.CreatedAt) | ||
memoStr := types.NewIBCHookMemo(route.DestinationContractAddress, pricePacket).JSONString() | ||
|
||
// mint coin to the fee payer | ||
err := k.MintIBCHookCoinToAccount(ctx, packet.TunnelID, feePayer, types.HookTransferAmount) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// create ibc transfer message with the memo string | ||
msg := ibctransfertypes.NewMsgTransfer( | ||
ibctransfertypes.PortID, | ||
route.ChannelID, | ||
sdk.NewInt64Coin(types.FormatHookDenomIdentifier(packet.TunnelID), int64(types.HookTransferAmount)), | ||
feePayer.String(), | ||
route.DestinationContractAddress, | ||
clienttypes.ZeroHeight(), | ||
uint64(ctx.BlockTime().UnixNano())+interval*uint64(time.Second)*2, | ||
memoStr, | ||
) | ||
|
||
// send packet | ||
res, err := k.transferKeeper.Transfer(ctx, msg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return types.NewIBCHookPacketReceipt(res.Sequence), nil | ||
} | ||
|
||
// MintIBCHookCoinToAccount mints hook coin to the account | ||
func (k Keeper) MintIBCHookCoinToAccount( | ||
ctx sdk.Context, | ||
tunnelID uint64, | ||
account sdk.AccAddress, | ||
amount uint64, | ||
) error { | ||
// create hook coins | ||
hookCoins := sdk.NewCoins( | ||
sdk.NewInt64Coin(types.FormatHookDenomIdentifier(tunnelID), int64(amount)), | ||
) | ||
|
||
// mint coins to the module account | ||
err := k.bankKeeper.MintCoins(ctx, types.ModuleName, hookCoins) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// send coins to the account | ||
return k.bankKeeper.SendCoinsFromModuleToAccount( | ||
ctx, | ||
types.ModuleName, | ||
account, | ||
hookCoins, | ||
) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not signal-infos