Skip to content

Commit

Permalink
Support non critical opt extions in clob and sending cli
Browse files Browse the repository at this point in the history
  • Loading branch information
jayy04 committed Dec 19, 2024
1 parent 81ec99c commit 7678a61
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 9 deletions.
29 changes: 29 additions & 0 deletions protocol/app/flags/permissioned_keys_flags.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion protocol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions protocol/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
24 changes: 23 additions & 1 deletion protocol/x/clob/client/cli/tx_batch_cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
24 changes: 23 additions & 1 deletion protocol/x/clob/client/cli/tx_cancel_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
24 changes: 23 additions & 1 deletion protocol/x/clob/client/cli/tx_place_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
24 changes: 23 additions & 1 deletion protocol/x/sending/client/cli/tx_create_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
24 changes: 23 additions & 1 deletion protocol/x/sending/client/cli/tx_deposit_to_subaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
24 changes: 23 additions & 1 deletion protocol/x/sending/client/cli/tx_withdraw_from_subaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit 7678a61

Please sign in to comment.