Skip to content

Commit 7b17db7

Browse files
committed
optimize bridge pegout via ibc
1 parent 8b347be commit 7b17db7

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

app/app.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,6 @@ func New(
586586
scopedTransferKeeper,
587587
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
588588
)
589-
transferModule := transfer.NewAppModule(app.TransferKeeper)
590589

591590
app.ICAHostKeeper = icahostkeeper.NewKeeper(
592591
appCodec, keys[icahosttypes.StoreKey],
@@ -835,7 +834,7 @@ func New(
835834
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
836835
ibc.NewAppModule(app.IBCKeeper),
837836
params.NewAppModule(app.ParamsKeeper),
838-
transferModule,
837+
transfer.NewAppModule(app.TransferKeeper),
839838
ibcFeeModule,
840839
icaModule,
841840
ibctm.AppModule{},

x/btcbridge/keeper/ibc.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ func (k Keeper) IterateIBCWithdrawRequestQueue(ctx sdk.Context, cb func(req *typ
105105
}
106106
}
107107

108-
// CheckSBTCAutoPegOut returns true if the given packet is to receive native sBTC and auto-pegout enabled, false otherwise
109-
func (k Keeper) CheckSBTCAutoPegOut(ctx sdk.Context, packet ibcexported.PacketI, data transfertypes.FungibleTokenPacketData) bool {
108+
// CheckSBTC returns true if the given packet is to receive native sBTC, false otherwise
109+
func (k Keeper) CheckSBTC(ctx sdk.Context, packet ibcexported.PacketI, data transfertypes.FungibleTokenPacketData) bool {
110110
// check if the receiving chain is source
111111
if !transfertypes.ReceiverChainIsSource(packet.GetSourcePort(), packet.GetSourceChannel(), data.Denom) {
112112
return false
@@ -118,7 +118,7 @@ func (k Keeper) CheckSBTCAutoPegOut(ctx sdk.Context, packet ibcexported.PacketI,
118118
// remove sender prefix
119119
unprefixedDenom := data.Denom[len(prefix):]
120120

121-
return unprefixedDenom == k.BtcDenom(ctx) && data.Memo == types.FlagAutoPegOut
121+
return unprefixedDenom == k.BtcDenom(ctx)
122122
}
123123

124124
// GetClientHeight gets the current client height by the given source port and channel
@@ -188,14 +188,19 @@ func (k Keeper) IBCReceivePacketCallback(
188188
ack ibcexported.Acknowledgement,
189189
contractAddress string,
190190
) error {
191+
// check if the callback address is the expected address
192+
if contractAddress != types.CallbackAddress {
193+
return nil
194+
}
195+
191196
// check if withdrawal is enabled
192197
if !k.WithdrawEnabled(ctx) {
193198
return nil
194199
}
195200

196201
// check if the packet is sBTC token transfer and auto-pegout enabled
197202
data, ok := tryGetFungibleTokenPacketData(packet)
198-
if !ok || !k.CheckSBTCAutoPegOut(ctx, packet, data) {
203+
if !ok || !k.CheckSBTC(ctx, packet, data) {
199204
return nil
200205
}
201206

x/btcbridge/types/ibc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const (
1212
// default memo for IBC transfer
1313
DefaultMemo = "BTC bridge | Side Chain"
1414

15-
// flag to enable auto pegout
16-
FlagAutoPegOut = "auto-pegout"
15+
// callback address to enable auto pegout
16+
CallbackAddress = "btcbridge"
1717

1818
// default max gas for IBC callback
1919
DefaultMaxIBCCallbackGas = uint64(1_000_000)

0 commit comments

Comments
 (0)