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 #2187

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 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
20 changes: 18 additions & 2 deletions proto/axelar/nexus/v1beta1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,25 @@ message MessageReceived {

message MessageProcessing { string id = 1 [ (gogoproto.customname) = "ID" ]; }
Copy link
Member

@milapsheth milapsheth Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about this one? Let's add it here for consistency as well. I think axelarscan might have requested this at some point as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can add, they didn't ask for this


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 @@ -93,10 +93,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: token.GetDenom(),
MessageID: msgID,
Recipient: req.Fee.Recipient,
Fee: req.Fee.Amount,
Asset: token.GetDenom(),
SourceChain: msg.GetSourceChain(),
DestinationChain: msg.GetDestinationChain(),
}
if req.Fee.RefundRecipient != nil {
feePaidEvent.RefundRecipient = req.Fee.RefundRecipient.String()
Expand Down
29 changes: 16 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, sourceAddress nexus.CrossChainAddress, msg Message, token keeper.Coin) error {
id, txID, nonce := n.GenerateMessageID(ctx)

// ignore token for call contract
_, err := deductFee(ctx, b, 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, b, msg.Fee, token, id, sourceAddress.Chain.Name, destChain.Name)
if err != nil {
return err

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

View check run for this annotation

Codecov / codecov/patch

x/axelarnet/message_handler.go#L260

Added line #L260 was not covered by tests
}

recipient := nexus.CrossChainAddress{Chain: destChain, Address: msg.DestinationAddress}
m := nexus.NewGeneralMessage(
id,
Expand Down Expand Up @@ -287,7 +287,9 @@
func handleMessageWithToken(ctx sdk.Context, n types.Nexus, b types.BankKeeper, sourceAddress nexus.CrossChainAddress, msg Message, token keeper.Coin) error {
id, txID, nonce := n.GenerateMessageID(ctx)

token, err := deductFee(ctx, b, msg.Fee, token, id)
destChain := funcs.MustOk(n.GetChain(ctx, nexus.ChainName(msg.DestinationChain)))
haiyizxx marked this conversation as resolved.
Show resolved Hide resolved

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

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

// deductFee pays the fee and returns the updated transfer amount with the fee deducted
func deductFee(ctx sdk.Context, b types.BankKeeper, fee *Fee, token keeper.Coin, msgID string) (keeper.Coin, error) {
func deductFee(ctx sdk.Context, b types.BankKeeper, fee *Fee, token keeper.Coin, msgID string, sourceChain nexus.ChainName, destinationChain nexus.ChainName) (keeper.Coin, error) {
haiyizxx marked this conversation as resolved.
Show resolved Hide resolved
if fee == nil {
return token, nil
}
Expand All @@ -402,10 +403,12 @@
recipient := funcs.Must(sdk.AccAddressFromBech32(fee.Recipient))

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