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(nexus): gmp events metadata (#2189) #2199

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions docs/proto/proto-docs.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions proto/axelar/axelarnet/v1beta1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ message FeePaid {
cosmos.base.v1beta1.Coin fee = 3 [ (gogoproto.nullable) = false ];
string refund_recipient = 4;
string asset = 5; // registered asset name in nexus
string source_chain = 6
[ (gogoproto.casttype) =
"github.com/axelarnetwork/axelar-core/x/nexus/exported.ChainName" ];
string destination_chain = 7
[ (gogoproto.casttype) =
"github.com/axelarnetwork/axelar-core/x/nexus/exported.ChainName" ];
}

message ContractCallSubmitted {
Expand Down
30 changes: 27 additions & 3 deletions proto/axelar/nexus/v1beta1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,35 @@ message MessageReceived {
[ (gogoproto.nullable) = false ];
}

message MessageProcessing { string id = 1 [ (gogoproto.customname) = "ID" ]; }
message MessageProcessing {
string id = 1 [ (gogoproto.customname) = "ID" ];
string source_chain = 2
[ (gogoproto.casttype) =
"github.com/axelarnetwork/axelar-core/x/nexus/exported.ChainName" ];
string destination_chain = 3
[ (gogoproto.casttype) =
"github.com/axelarnetwork/axelar-core/x/nexus/exported.ChainName" ];
}

message MessageExecuted { string id = 1 [ (gogoproto.customname) = "ID" ]; }
message MessageExecuted {
string id = 1 [ (gogoproto.customname) = "ID" ];
string source_chain = 2
[ (gogoproto.casttype) =
"github.com/axelarnetwork/axelar-core/x/nexus/exported.ChainName" ];
string destination_chain = 3
[ (gogoproto.casttype) =
"github.com/axelarnetwork/axelar-core/x/nexus/exported.ChainName" ];
}

message MessageFailed { string id = 1 [ (gogoproto.customname) = "ID" ]; }
message MessageFailed {
string id = 1 [ (gogoproto.customname) = "ID" ];
string source_chain = 2
[ (gogoproto.casttype) =
"github.com/axelarnetwork/axelar-core/x/nexus/exported.ChainName" ];
string destination_chain = 3
[ (gogoproto.casttype) =
"github.com/axelarnetwork/axelar-core/x/nexus/exported.ChainName" ];
}

message WasmMessageRouted {
exported.v1beta1.WasmMessage message = 1 [ (gogoproto.nullable) = false ];
Expand Down
10 changes: 6 additions & 4 deletions x/axelarnet/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ func (s msgServer) CallContract(c context.Context, req *types.CallContractReques
}

feePaidEvent := types.FeePaid{
MessageID: msgID,
Recipient: req.Fee.Recipient,
Fee: req.Fee.Amount,
Asset: lockableAsset.GetAsset().Denom,
MessageID: msgID,
Recipient: req.Fee.Recipient,
Fee: req.Fee.Amount,
Asset: lockableAsset.GetAsset().Denom,
SourceChain: msg.GetSourceChain(),
DestinationChain: msg.GetDestinationChain(),
}
if req.Fee.RefundRecipient != nil {
feePaidEvent.RefundRecipient = req.Fee.RefundRecipient.String()
Expand Down
28 changes: 15 additions & 13 deletions x/axelarnet/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,6 @@
func handleMessage(ctx sdk.Context, n types.Nexus, b types.BankKeeper, ibcK types.IBCKeeper, sourceAddress nexus.CrossChainAddress, msg Message, token nexus.LockableAsset) error {
id, txID, nonce := n.GenerateMessageID(ctx)

// ignore token for call contract
_, err := deductFee(ctx, n, b, ibcK, msg.Fee, token, id)
if err != nil {
return err
}

destChain, ok := n.GetChain(ctx, nexus.ChainName(msg.DestinationChain))
if !ok {
// try forwarding it to wasm router if destination chain is not registered
Expand All @@ -260,6 +254,12 @@
destChain = nexus.Chain{Name: destChainName, SupportsForeignAssets: false, KeyType: tss.None, Module: wasm.ModuleName}
}

// ignore token for call contract
_, err := deductFee(ctx, n, b, ibcK, msg.Fee, token, id, sourceAddress.Chain.Name, destChain.GetName())
if err != nil {
return err
}

Check warning on line 261 in x/axelarnet/message_handler.go

View check run for this annotation

Codecov / codecov/patch

x/axelarnet/message_handler.go#L260-L261

Added lines #L260 - L261 were not covered by tests

recipient := nexus.CrossChainAddress{Chain: destChain, Address: msg.DestinationAddress}
m := nexus.NewGeneralMessage(
id,
Expand All @@ -286,8 +286,9 @@

func handleMessageWithToken(ctx sdk.Context, n types.Nexus, b types.BankKeeper, ibcK types.IBCKeeper, sourceAddress nexus.CrossChainAddress, msg Message, token nexus.LockableAsset) error {
id, txID, nonce := n.GenerateMessageID(ctx)
destChain := funcs.MustOk(n.GetChain(ctx, nexus.ChainName(msg.DestinationChain)))

token, err := deductFee(ctx, n, b, ibcK, msg.Fee, token, id)
token, err := deductFee(ctx, n, b, ibcK, msg.Fee, token, id, sourceAddress.Chain.Name, destChain.GetName())
if err != nil {
return err
}
Expand All @@ -296,7 +297,6 @@
return err
}

destChain := funcs.MustOk(n.GetChain(ctx, nexus.ChainName(msg.DestinationChain)))
recipient := nexus.CrossChainAddress{Chain: destChain, Address: msg.DestinationAddress}
coin := token.GetAsset()
m := nexus.NewGeneralMessage(
Expand Down Expand Up @@ -393,7 +393,7 @@
}

// deductFee pays the fee and returns the updated transfer amount with the fee deducted
func deductFee(ctx sdk.Context, n types.Nexus, b types.BankKeeper, ibcK types.IBCKeeper, fee *Fee, token nexus.LockableAsset, msgID string) (nexus.LockableAsset, error) {
func deductFee(ctx sdk.Context, n types.Nexus, b types.BankKeeper, ibcK types.IBCKeeper, fee *Fee, token nexus.LockableAsset, msgID string, sourceChain nexus.ChainName, destinationChain nexus.ChainName) (nexus.LockableAsset, error) {
if fee == nil {
return token, nil
}
Expand All @@ -403,10 +403,12 @@
recipient := funcs.Must(sdk.AccAddressFromBech32(fee.Recipient))

feePaidEvent := types.FeePaid{
MessageID: msgID,
Recipient: recipient,
Fee: feeCoin,
Asset: token.GetAsset().Denom,
MessageID: msgID,
Recipient: recipient,
Fee: feeCoin,
Asset: token.GetAsset().Denom,
SourceChain: sourceChain,
DestinationChain: destinationChain,
}
if fee.RefundRecipient != nil {
feePaidEvent.RefundRecipient = *fee.RefundRecipient
Expand Down
Loading
Loading