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

Merged
merged 8 commits into from
Sep 30, 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 @@ -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
18 changes: 11 additions & 7 deletions x/axelarnet/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func handleMessage(ctx sdk.Context, n types.Nexus, b types.BankKeeper, sourceAdd
id, txID, nonce := n.GenerateMessageID(ctx)

// ignore token for call contract
_, err := deductFee(ctx, b, msg.Fee, token, id)
_, err := deductFee(ctx, b, msg.Fee, token, id, sourceAddress.Chain.Name, nexus.ChainName(msg.DestinationChain))
if err != nil {
return err
}
Expand Down Expand Up @@ -287,7 +287,7 @@ func handleMessage(ctx sdk.Context, n types.Nexus, b types.BankKeeper, sourceAdd
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)
token, err := deductFee(ctx, b, msg.Fee, token, id, sourceAddress.Chain.Name, nexus.ChainName(msg.DestinationChain))
if err != nil {
return err
}
Expand Down Expand Up @@ -392,20 +392,24 @@ func extractTokenFromPacketData(ctx sdk.Context, ibcK keeper.IBCKeeper, n types.
}

// 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) {
if fee == nil {
return token, nil
}

feeAmount := funcs.MustOk(sdk.NewIntFromString(fee.Amount))
coin := sdk.NewCoin(funcs.Must(token.GetOriginalDenom()), feeAmount)
recipient := funcs.Must(sdk.AccAddressFromBech32(fee.Recipient))
// destination chain is from user input, normalize it to lowercase
destinationChain = nexus.ChainName(strings.ToLower(destinationChain.String()))

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