From fa7038be461de448ac36181249d5f170fba24c2f Mon Sep 17 00:00:00 2001 From: jayy04 <103467857+jayy04@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:15:33 -0500 Subject: [PATCH] Support non critical opt extions in clob and sending cli (#2667) --- protocol/app/flags/permissioned_keys_flags.go | 29 +++++++++++++++++++ protocol/go.mod | 2 +- protocol/go.sum | 4 +-- protocol/x/clob/client/cli/tx_batch_cancel.go | 24 ++++++++++++++- protocol/x/clob/client/cli/tx_cancel_order.go | 24 ++++++++++++++- protocol/x/clob/client/cli/tx_place_order.go | 24 ++++++++++++++- .../sending/client/cli/tx_create_transfer.go | 24 ++++++++++++++- .../client/cli/tx_deposit_to_subaccount.go | 24 ++++++++++++++- .../client/cli/tx_withdraw_from_subaccount.go | 24 ++++++++++++++- 9 files changed, 170 insertions(+), 9 deletions(-) create mode 100644 protocol/app/flags/permissioned_keys_flags.go diff --git a/protocol/app/flags/permissioned_keys_flags.go b/protocol/app/flags/permissioned_keys_flags.go new file mode 100644 index 0000000000..46c4779cf1 --- /dev/null +++ b/protocol/app/flags/permissioned_keys_flags.go @@ -0,0 +1,29 @@ +package flags + +import ( + "github.com/spf13/cobra" +) + +const ( + FlagAuthenticators = "authenticators" +) + +// AddTxPermissionedKeyFlagsToCmd adds common flags to a module tx command. +func AddTxPermissionedKeyFlagsToCmd(cmd *cobra.Command) { + f := cmd.Flags() + f.UintSlice(FlagAuthenticators, nil, "Authenticators to use for authenticating this transaction.") +} + +// GetPermisionedKeyAuthenticatorsForExtOptions returns the authenticators from the provided command flags. +func GetPermisionedKeyAuthenticatorsForExtOptions(cmd *cobra.Command) ([]uint64, error) { + flags := cmd.Flags() + values, err := flags.GetUintSlice(FlagAuthenticators) + if err == nil { + authenticators := make([]uint64, len(values)) + for i, v := range values { + authenticators[i] = uint64(v) + } + return authenticators, nil + } + return nil, err +} diff --git a/protocol/go.mod b/protocol/go.mod index 0f4821444f..711afff49a 100644 --- a/protocol/go.mod +++ b/protocol/go.mod @@ -472,7 +472,7 @@ replace ( // Use dYdX fork of CometBFT github.com/cometbft/cometbft => github.com/dydxprotocol/cometbft v0.38.6-0.20241126215519-69cdde955fd0 // Use dYdX fork of Cosmos SDK - github.com/cosmos/cosmos-sdk => github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241127172510-4ee58434cdea + github.com/cosmos/cosmos-sdk => github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241219194626-713334f028e7 github.com/cosmos/iavl => github.com/dydxprotocol/iavl v1.1.1-0.20240509161911-1c8b8e787e85 ) diff --git a/protocol/go.sum b/protocol/go.sum index fc9ec1f3b6..8264635399 100644 --- a/protocol/go.sum +++ b/protocol/go.sum @@ -960,8 +960,8 @@ github.com/dvsekhvalnov/jose2go v1.6.0 h1:Y9gnSnP4qEI0+/uQkHvFXeD2PLPJeXEL+ySMEA github.com/dvsekhvalnov/jose2go v1.6.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU= github.com/dydxprotocol/cometbft v0.38.6-0.20241126215519-69cdde955fd0 h1:KBMuBNAE91SVeULnq2XBnmSDGeimI6aM1+YxlLb0yOI= github.com/dydxprotocol/cometbft v0.38.6-0.20241126215519-69cdde955fd0/go.mod h1:XSQX1hQbr54qaJb4/5YNNZGXkAQHHa6bi/KMcN1SQ7w= -github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241127172510-4ee58434cdea h1:5jsj2e6zqnx7Q7SiNTYC7UGEW0ymgKFTbLxzp27/2Fg= -github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241127172510-4ee58434cdea/go.mod h1:z/5+LD4MJzLqbe+fBCWI2pZLnQbOlzSM82snAw2zceg= +github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241219194626-713334f028e7 h1:uYf2XRrDik5Aq93hIWOPG5qW+k5I4RMEuSQPT+fZOCs= +github.com/dydxprotocol/cosmos-sdk v0.50.6-0.20241219194626-713334f028e7/go.mod h1:z/5+LD4MJzLqbe+fBCWI2pZLnQbOlzSM82snAw2zceg= github.com/dydxprotocol/cosmos-sdk/store v1.0.3-0.20240326192503-dd116391188d h1:HgLu1FD2oDFzlKW6/+SFXlH5Os8cwNTbplQIrQOWx8w= github.com/dydxprotocol/cosmos-sdk/store v1.0.3-0.20240326192503-dd116391188d/go.mod h1:zMcD3hfNwd0WMTpdRUhS3QxoCoEtBXWeoKsu3iaLBbQ= github.com/dydxprotocol/iavl v1.1.1-0.20240509161911-1c8b8e787e85 h1:5B/yGZyTBX/OZASQQMnk6Ms/TZja56MYd8OBaVc0Mho= diff --git a/protocol/x/clob/client/cli/tx_batch_cancel.go b/protocol/x/clob/client/cli/tx_batch_cancel.go index 3051f95358..b4b500b005 100644 --- a/protocol/x/clob/client/cli/tx_batch_cancel.go +++ b/protocol/x/clob/client/cli/tx_batch_cancel.go @@ -7,6 +7,9 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + customflags "github.com/dydxprotocol/v4-chain/protocol/app/flags" + aptypes "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" "github.com/spf13/cast" @@ -70,11 +73,30 @@ func CmdBatchCancel() *cobra.Command { if err := msg.ValidateBasic(); err != nil { return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + + txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + authenticatorIds, err := customflags.GetPermisionedKeyAuthenticatorsForExtOptions(cmd) + if err == nil && len(authenticatorIds) > 0 { + value, err := codectypes.NewAnyWithValue( + &aptypes.TxExtension{ + SelectedAuthenticators: authenticatorIds, + }, + ) + if err != nil { + return err + } + txf = txf.WithNonCriticalExtensionOptions(value) + } + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) }, } flags.AddTxFlagsToCmd(cmd) + customflags.AddTxPermissionedKeyFlagsToCmd(cmd) return cmd } diff --git a/protocol/x/clob/client/cli/tx_cancel_order.go b/protocol/x/clob/client/cli/tx_cancel_order.go index 303d362192..96d3bdbd65 100644 --- a/protocol/x/clob/client/cli/tx_cancel_order.go +++ b/protocol/x/clob/client/cli/tx_cancel_order.go @@ -4,6 +4,9 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + customflags "github.com/dydxprotocol/v4-chain/protocol/app/flags" + aptypes "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" "github.com/spf13/cast" @@ -58,11 +61,30 @@ func CmdCancelOrder() *cobra.Command { if err := msg.ValidateBasic(); err != nil { return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + + txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + authenticatorIds, err := customflags.GetPermisionedKeyAuthenticatorsForExtOptions(cmd) + if err == nil && len(authenticatorIds) > 0 { + value, err := codectypes.NewAnyWithValue( + &aptypes.TxExtension{ + SelectedAuthenticators: authenticatorIds, + }, + ) + if err != nil { + return err + } + txf = txf.WithNonCriticalExtensionOptions(value) + } + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) }, } flags.AddTxFlagsToCmd(cmd) + customflags.AddTxPermissionedKeyFlagsToCmd(cmd) return cmd } diff --git a/protocol/x/clob/client/cli/tx_place_order.go b/protocol/x/clob/client/cli/tx_place_order.go index 28e9d69ff1..5882df90d0 100644 --- a/protocol/x/clob/client/cli/tx_place_order.go +++ b/protocol/x/clob/client/cli/tx_place_order.go @@ -4,6 +4,9 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + customflags "github.com/dydxprotocol/v4-chain/protocol/app/flags" + aptypes "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" "github.com/spf13/cast" @@ -77,11 +80,30 @@ func CmdPlaceOrder() *cobra.Command { if err := msg.ValidateBasic(); err != nil { return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + + txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + authenticatorIds, err := customflags.GetPermisionedKeyAuthenticatorsForExtOptions(cmd) + if err == nil && len(authenticatorIds) > 0 { + value, err := codectypes.NewAnyWithValue( + &aptypes.TxExtension{ + SelectedAuthenticators: authenticatorIds, + }, + ) + if err != nil { + return err + } + txf = txf.WithNonCriticalExtensionOptions(value) + } + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) }, } flags.AddTxFlagsToCmd(cmd) + customflags.AddTxPermissionedKeyFlagsToCmd(cmd) return cmd } diff --git a/protocol/x/sending/client/cli/tx_create_transfer.go b/protocol/x/sending/client/cli/tx_create_transfer.go index dfb8073bdc..c161d37cc9 100644 --- a/protocol/x/sending/client/cli/tx_create_transfer.go +++ b/protocol/x/sending/client/cli/tx_create_transfer.go @@ -6,6 +6,9 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + customflags "github.com/dydxprotocol/v4-chain/protocol/app/flags" + aptypes "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" "github.com/dydxprotocol/v4-chain/protocol/x/sending/types" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" @@ -65,11 +68,30 @@ func CmdCreateTransfer() *cobra.Command { if err := msg.ValidateBasic(); err != nil { return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + + txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + authenticatorIds, err := customflags.GetPermisionedKeyAuthenticatorsForExtOptions(cmd) + if err == nil && len(authenticatorIds) > 0 { + value, err := codectypes.NewAnyWithValue( + &aptypes.TxExtension{ + SelectedAuthenticators: authenticatorIds, + }, + ) + if err != nil { + return err + } + txf = txf.WithNonCriticalExtensionOptions(value) + } + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) }, } flags.AddTxFlagsToCmd(cmd) + customflags.AddTxPermissionedKeyFlagsToCmd(cmd) return cmd } diff --git a/protocol/x/sending/client/cli/tx_deposit_to_subaccount.go b/protocol/x/sending/client/cli/tx_deposit_to_subaccount.go index 07f53c9e8e..13730b1604 100644 --- a/protocol/x/sending/client/cli/tx_deposit_to_subaccount.go +++ b/protocol/x/sending/client/cli/tx_deposit_to_subaccount.go @@ -4,6 +4,9 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + customflags "github.com/dydxprotocol/v4-chain/protocol/app/flags" + aptypes "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" "github.com/dydxprotocol/v4-chain/protocol/x/sending/types" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" @@ -60,11 +63,30 @@ Note, the '--from' flag is ignored as it is implied from [sender_key_or_address] if err := msg.ValidateBasic(); err != nil { return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + + txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + authenticatorIds, err := customflags.GetPermisionedKeyAuthenticatorsForExtOptions(cmd) + if err == nil && len(authenticatorIds) > 0 { + value, err := codectypes.NewAnyWithValue( + &aptypes.TxExtension{ + SelectedAuthenticators: authenticatorIds, + }, + ) + if err != nil { + return err + } + txf = txf.WithNonCriticalExtensionOptions(value) + } + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) }, } flags.AddTxFlagsToCmd(cmd) + customflags.AddTxPermissionedKeyFlagsToCmd(cmd) return cmd } diff --git a/protocol/x/sending/client/cli/tx_withdraw_from_subaccount.go b/protocol/x/sending/client/cli/tx_withdraw_from_subaccount.go index 9302f59d02..ae1f57cabe 100644 --- a/protocol/x/sending/client/cli/tx_withdraw_from_subaccount.go +++ b/protocol/x/sending/client/cli/tx_withdraw_from_subaccount.go @@ -4,6 +4,9 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + customflags "github.com/dydxprotocol/v4-chain/protocol/app/flags" + aptypes "github.com/dydxprotocol/v4-chain/protocol/x/accountplus/types" assettypes "github.com/dydxprotocol/v4-chain/protocol/x/assets/types" "github.com/dydxprotocol/v4-chain/protocol/x/sending/types" satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" @@ -60,11 +63,30 @@ Note, the '--from' flag is ignored as it is implied from [sender_key_or_address] if err := msg.ValidateBasic(); err != nil { return err } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + + txf, err := tx.NewFactoryCLI(clientCtx, cmd.Flags()) + if err != nil { + return err + } + + authenticatorIds, err := customflags.GetPermisionedKeyAuthenticatorsForExtOptions(cmd) + if err == nil && len(authenticatorIds) > 0 { + value, err := codectypes.NewAnyWithValue( + &aptypes.TxExtension{ + SelectedAuthenticators: authenticatorIds, + }, + ) + if err != nil { + return err + } + txf = txf.WithNonCriticalExtensionOptions(value) + } + return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg) }, } flags.AddTxFlagsToCmd(cmd) + customflags.AddTxPermissionedKeyFlagsToCmd(cmd) return cmd }