Skip to content

Commit

Permalink
feat(nexus): gmp events metadata (#2189) (#2199)
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyizxx authored Oct 18, 2024
1 parent 2a8810a commit fad8abd
Show file tree
Hide file tree
Showing 8 changed files with 592 additions and 127 deletions.
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 validateMessage(ctx sdk.Context, ibcK keeper.IBCKeeper, n types.Nexus, ibcP
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 @@ func handleMessage(ctx sdk.Context, n types.Nexus, b types.BankKeeper, ibcK type
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
}

recipient := nexus.CrossChainAddress{Chain: destChain, Address: msg.DestinationAddress}
m := nexus.NewGeneralMessage(
id,
Expand All @@ -286,8 +286,9 @@ func handleMessage(ctx sdk.Context, n types.Nexus, b types.BankKeeper, ibcK type

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 @@ func handleMessageWithToken(ctx sdk.Context, n types.Nexus, b types.BankKeeper,
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 @@ 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, 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 @@ func deductFee(ctx sdk.Context, n types.Nexus, b types.BankKeeper, ibcK types.IB
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

0 comments on commit fad8abd

Please sign in to comment.