Skip to content
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

feat(axelarnet)!: refund from escrow address to IBC account #2202

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions x/axelarnet/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
return err
}

return m.setRoutedPacketFailed(ctx, packet)
return m.setRoutedPacketFailed(ctx, packet, m.bank)
}
}

Expand All @@ -287,7 +287,7 @@
return err
}

return m.setRoutedPacketFailed(ctx, packet)
return m.setRoutedPacketFailed(ctx, packet, m.bank)
}

// returns the transfer id and delete the existing mapping
Expand Down Expand Up @@ -334,7 +334,7 @@
return nil
}

func (m AxelarnetIBCModule) setRoutedPacketFailed(ctx sdk.Context, packet channeltypes.Packet) error {
func (m AxelarnetIBCModule) setRoutedPacketFailed(ctx sdk.Context, packet channeltypes.Packet, bank types.BankKeeper) error {
// IBC ack/timeout packets, by convention, use the source port/channel to represent native chain -> counterparty chain channel id
// https://github.com/cosmos/ibc/tree/main/spec/core/ics-004-channel-and-packet-semantics#definitions
port, channel, sequence := packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()
Expand All @@ -347,6 +347,11 @@
return err
}

err = refund_from_asset_escrow_address_to_ibc_account(ctx, packet, bank)
if err != nil {
return err
}

Check warning on line 353 in x/axelarnet/module.go

View check run for this annotation

Codecov / codecov/patch

x/axelarnet/module.go#L352-L353

Added lines #L352 - L353 were not covered by tests

err = lockableAsset.LockFrom(ctx, types.AxelarIBCAccount)
if err != nil {
return err
Expand Down Expand Up @@ -395,3 +400,25 @@

return sdk.NewCoin(trace.IBCDenom(), amount)
}

// Temporary logic to handle in-transit IBC transfers during upgrade. Previously IBC transfers sent from asset escrow address; now sent from IBC account.
haiyizxx marked this conversation as resolved.
Show resolved Hide resolved
// Deprecated: Remove this function after the v1.1 upgrade
haiyizxx marked this conversation as resolved.
Show resolved Hide resolved
func refund_from_asset_escrow_address_to_ibc_account(ctx sdk.Context, packet channeltypes.Packet, bank types.BankKeeper) error {
haiyizxx marked this conversation as resolved.
Show resolved Hide resolved
// Packet is validated by the IBC module, so we can safely assume it's a valid ICS20 packet
data := funcs.Must(types.ToICS20Packet(packet))

// decode the sender address
originalSender := funcs.Must(sdk.AccAddressFromBech32(data.Sender))
if originalSender.Equals(types.AxelarIBCAccount) {
return nil
}

// parse the denomination from the full denom path
trace := ibctransfertypes.ParseDenomTrace(data.Denom)

// parse the transfer amount
transferAmount := funcs.MustOk(sdk.NewIntFromString(data.Amount))
haiyizxx marked this conversation as resolved.
Show resolved Hide resolved

token := sdk.NewCoin(trace.IBCDenom(), transferAmount)
return bank.SendCoins(ctx, originalSender, types.AxelarIBCAccount, sdk.NewCoins(token))
}
16 changes: 16 additions & 0 deletions x/axelarnet/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func TestIBCModule(t *testing.T) {
transfer := funcs.MustOk(k.GetTransfer(ctx, transfer.ID))
assert.Equal(t, types.TransferFailed, transfer.Status)
assert.Len(t, lockableAsset.LockFromCalls(), 1)
assert.Len(t, bankK.SendCoinsCalls(), 2)
}),

whenPendingTransfersExist.
Expand Down Expand Up @@ -237,5 +238,20 @@ func TestIBCModule(t *testing.T) {
assert.Equal(t, nexus.Failed, message.Status)
assert.Len(t, lockableAsset.LockFromCalls(), 1)
}),

seqMapsToID.
When2(whenChainIsActivated).
When("lock coin succeeds", lockCoin(true)).
When("packet sender is from IBC account", func() {
fungibleTokenPacket.Sender = types.AxelarIBCAccount.String()
packet = channeltypes.NewPacket(fungibleTokenPacket.GetBytes(), packetSeq, ibctransfertypes.PortID, channelID, ibctransfertypes.PortID, channelID, clienttypes.NewHeight(0, 110), 0)
}).
When2(whenOnTimeout).
Then("should not trigger refund from asset escrow to IBC account", func(t *testing.T) {
transfer := funcs.MustOk(k.GetTransfer(ctx, transfer.ID))
assert.Equal(t, types.TransferFailed, transfer.Status)
assert.Len(t, lockableAsset.LockFromCalls(), 1)
assert.Len(t, bankK.SendCoinsCalls(), 1)
}),
).Run(t)
}
Loading