Skip to content

Commit

Permalink
fix: CompatibilityGetBytes fx ibc transfer
Browse files Browse the repository at this point in the history
* retain ibc fee is ibc router is empty
  • Loading branch information
fx0x55 committed Dec 22, 2022
1 parent 635d440 commit a5ea47e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
12 changes: 12 additions & 0 deletions types/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"math"
"os"
"sync"

Expand All @@ -12,13 +13,17 @@ const (
TestnetChainId = "payalebar"
testnetMintDenom = "bsc0x0BEdB58eC8D603E71556ef8aA4014c68DBd57AD7"
testnetStakingBondDenom = "ibc/169A52CA4862329131348484982CE75B3D6CC78AFB94C3107026C70CB66E7B2E"

testnetCompatibilityIBCTransferHeight = math.MaxInt64
)

// mainnet constant
const (
MainnetChainId = "PUNDIX"
mainnetMintDenom = "bsc0x29a63F4B209C29B4DC47f06FFA896F32667DAD2C"
mainnetStakingBondDenom = "ibc/55367B7B6572631B78A93C66EF9FDFCE87CDE372CC4ED7848DA78C1EB1DCDD78"

mainnetCompatibilityIBCTransferHeight = math.MaxInt64
)

var (
Expand Down Expand Up @@ -62,3 +67,10 @@ func StakingBondDenom() string {
}
return mainnetStakingBondDenom
}

func CompatibilityIBCTransferHeight() int64 {
if TestnetChainId == ChainId() {
return testnetCompatibilityIBCTransferHeight
}
return mainnetCompatibilityIBCTransferHeight
}
10 changes: 9 additions & 1 deletion x/ibc/applications/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"fmt"
pxtypes "github.com/pundix/pundix/types"
"strings"

coretypes "github.com/cosmos/ibc-go/v3/modules/core/types"
Expand Down Expand Up @@ -163,8 +164,15 @@ func (k Keeper) sendTransfer(ctx sdk.Context, sourcePort, sourceChannel string,
}
}

// hard fork: compatibility fx ibc transfer fee
var packetDateBytes []byte
if ctx.BlockHeight() >= pxtypes.CompatibilityIBCTransferHeight() {
packetDateBytes = packetData.CompatibilityGetBytes()
} else {
packetDateBytes = packetData.GetBytes()
}
packet := channeltypes.NewPacket(
packetData.GetBytes(),
packetDateBytes,
sequence,
sourcePort,
sourceChannel,
Expand Down
5 changes: 5 additions & 0 deletions x/ibc/applications/transfer/types/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func (ftpd FungibleTokenPacketData) GetBytes() []byte {
return sdk.MustSortJSON(mustProtoMarshalJSON(&ftpd))
}

// CompatibilityGetBytes is a helper for serialising, compatibility fx ibc transfer
func (ftpd FungibleTokenPacketData) CompatibilityGetBytes() []byte {
return sdk.MustSortJSON(mustProtoMarshalJSON(&ftpd))
}

// GetBytes is a helper for serialising
func (ftpd FungibleTokenPacketData) ToIBCPacketData() transfertypes.FungibleTokenPacketData {
result := transfertypes.NewFungibleTokenPacketData(ftpd.Denom, ftpd.Amount, ftpd.Sender, ftpd.Receiver)
Expand Down
28 changes: 28 additions & 0 deletions x/ibc/applications/transfer/types/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ func TestUnmarshalJSON(t *testing.T) {
Fee: "",
},
},
{
name: "fx transfer packet - no router - Compatibility",
data: types.NewFungibleTokenPacketData("FX", "100", "Add1", "Add2", "", "0").CompatibilityGetBytes(),
pass: true,
expErr: nil,
exp: types.FungibleTokenPacketData{
Denom: "FX",
Amount: "100",
Sender: "Add1",
Receiver: "Add2",
Router: "",
Fee: "0",
},
},
{
name: "fx transfer packet - router with 0fee",
data: types.NewFungibleTokenPacketData("FX", "100", "Add1", "Add2", "router", "0").GetBytes(),
Expand All @@ -89,6 +103,20 @@ func TestUnmarshalJSON(t *testing.T) {
Fee: "0",
},
},
{
name: "fx transfer packet - router with 0fee",
data: types.NewFungibleTokenPacketData("FX", "100", "Add1", "Add2", "router", "0").CompatibilityGetBytes(),
pass: true,
expErr: nil,
exp: types.FungibleTokenPacketData{
Denom: "FX",
Amount: "100",
Sender: "Add1",
Receiver: "Add2",
Router: "router",
Fee: "0",
},
},
{
name: "fx transfer packet - router with empty fee",
data: types.NewFungibleTokenPacketData("FX", "100", "Add1", "Add2", "router", "").GetBytes(),
Expand Down

0 comments on commit a5ea47e

Please sign in to comment.