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

Fix IBC Hooks and PFM #417

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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: 7 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keepers
import (
"path/filepath"

forward "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router"
forwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router/keeper"
forwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router/types"
icacontrollerkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller/keeper"
Expand Down Expand Up @@ -108,6 +109,7 @@ type AppKeepers struct {
Ics20WasmHooks *ibchooks.WasmHooks
IBCHooksWrapper *ibchooks.ICS4Middleware
TransferStack ibctransfer.IBCModule
ForwardModule forward.AppModule

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -375,13 +377,14 @@ func NewAppKeepers(
appCodec,
appKeepers.keys[ibctransfertypes.StoreKey],
appKeepers.GetSubspace(ibctransfertypes.ModuleName),
appKeepers.IBCHooksWrapper,
&appKeepers.ForwardKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
scopedTransferKeeper,
)
appKeepers.ForwardKeeper.SetTransferKeeper(appKeepers.TransferKeeper)

wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
Expand Down Expand Up @@ -471,6 +474,8 @@ func NewAppKeepers(
appKeepers.ScopedIBCFeeKeeper = scopedIBCFeeKeeper
appKeepers.ScopedWasmKeeper = scopedWasmKeeper

appKeepers.ForwardModule = forward.NewAppModule(&appKeepers.ForwardKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := appKeepers.newIBCRouter()
appKeepers.IBCKeeper.SetRouter(ibcRouter)
Expand Down Expand Up @@ -505,6 +510,7 @@ func initParamsKeeper(
paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(dyncommtypes.ModuleName)
paramsKeeper.Subspace(ibchooktypes.ModuleName)
paramsKeeper.Subspace(forwardtypes.ModuleName).WithKeyTable(forwardtypes.ParamKeyTable())

return paramsKeeper
}
Expand Down
94 changes: 46 additions & 48 deletions app/modules.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
package app

import (
ica "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts"
icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types"
ibcfee "github.com/cosmos/ibc-go/v6/modules/apps/29-fee"
ibcfeetypes "github.com/cosmos/ibc-go/v6/modules/apps/29-fee/types"
transfer "github.com/cosmos/ibc-go/v6/modules/apps/transfer"
ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v6/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v6/modules/core/02-client/client"
ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host"

"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
terraappparams "github.com/classic-terra/core/v2/app/params"
customauth "github.com/classic-terra/core/v2/custom/auth"
customauthsim "github.com/classic-terra/core/v2/custom/auth/simulation"
customauthz "github.com/classic-terra/core/v2/custom/authz"
custombank "github.com/classic-terra/core/v2/custom/bank"
customcrisis "github.com/classic-terra/core/v2/custom/crisis"
customdistr "github.com/classic-terra/core/v2/custom/distribution"
customevidence "github.com/classic-terra/core/v2/custom/evidence"
customfeegrant "github.com/classic-terra/core/v2/custom/feegrant"
customgov "github.com/classic-terra/core/v2/custom/gov"
custommint "github.com/classic-terra/core/v2/custom/mint"
customparams "github.com/classic-terra/core/v2/custom/params"
customslashing "github.com/classic-terra/core/v2/custom/slashing"
customstaking "github.com/classic-terra/core/v2/custom/staking"
customupgrade "github.com/classic-terra/core/v2/custom/upgrade"
customwasm "github.com/classic-terra/core/v2/custom/wasm"
"github.com/classic-terra/core/v2/x/dyncomm"
dyncommtypes "github.com/classic-terra/core/v2/x/dyncomm/types"
"github.com/classic-terra/core/v2/x/market"
markettypes "github.com/classic-terra/core/v2/x/market/types"
"github.com/classic-terra/core/v2/x/oracle"
oracletypes "github.com/classic-terra/core/v2/x/oracle/types"
"github.com/classic-terra/core/v2/x/treasury"
treasuryclient "github.com/classic-terra/core/v2/x/treasury/client"
treasurytypes "github.com/classic-terra/core/v2/x/treasury/types"
"github.com/classic-terra/core/v2/x/vesting"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -45,42 +64,19 @@ import (
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

terraappparams "github.com/classic-terra/core/v2/app/params"

customauth "github.com/classic-terra/core/v2/custom/auth"
customauthsim "github.com/classic-terra/core/v2/custom/auth/simulation"
customauthz "github.com/classic-terra/core/v2/custom/authz"
custombank "github.com/classic-terra/core/v2/custom/bank"
customcrisis "github.com/classic-terra/core/v2/custom/crisis"
customdistr "github.com/classic-terra/core/v2/custom/distribution"
customevidence "github.com/classic-terra/core/v2/custom/evidence"
customfeegrant "github.com/classic-terra/core/v2/custom/feegrant"
customgov "github.com/classic-terra/core/v2/custom/gov"
custommint "github.com/classic-terra/core/v2/custom/mint"
customparams "github.com/classic-terra/core/v2/custom/params"
customslashing "github.com/classic-terra/core/v2/custom/slashing"
customstaking "github.com/classic-terra/core/v2/custom/staking"
customupgrade "github.com/classic-terra/core/v2/custom/upgrade"
customwasm "github.com/classic-terra/core/v2/custom/wasm"

"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/classic-terra/core/v2/x/dyncomm"
dyncommtypes "github.com/classic-terra/core/v2/x/dyncomm/types"
"github.com/classic-terra/core/v2/x/market"
markettypes "github.com/classic-terra/core/v2/x/market/types"
"github.com/classic-terra/core/v2/x/oracle"
oracletypes "github.com/classic-terra/core/v2/x/oracle/types"
"github.com/classic-terra/core/v2/x/treasury"
treasuryclient "github.com/classic-terra/core/v2/x/treasury/client"
treasurytypes "github.com/classic-terra/core/v2/x/treasury/types"
"github.com/classic-terra/core/v2/x/vesting"

forward "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router"
forwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router/types"
ica "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts"
icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types"
ibcfee "github.com/cosmos/ibc-go/v6/modules/apps/29-fee"
ibcfeetypes "github.com/cosmos/ibc-go/v6/modules/apps/29-fee/types"
transfer "github.com/cosmos/ibc-go/v6/modules/apps/transfer"
ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v6/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v6/modules/core/02-client/client"
ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host"
// unnamed import of statik for swagger UI support
_ "github.com/classic-terra/core/v2/client/docs/statik"

ibchooks "github.com/terra-money/core/v2/x/ibc-hooks"
ibchooktypes "github.com/terra-money/core/v2/x/ibc-hooks/types"
)
Expand Down Expand Up @@ -117,6 +113,7 @@ var (
customfeegrant.AppModuleBasic{},
ibc.AppModuleBasic{},
ica.AppModuleBasic{},
forward.AppModuleBasic{},
customupgrade.AppModuleBasic{},
customevidence.AppModuleBasic{},
transfer.AppModuleBasic{},
Expand All @@ -129,7 +126,6 @@ var (
dyncomm.AppModuleBasic{},
ibchooks.AppModuleBasic{},
)

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil, // just added to enable align fee
Expand All @@ -148,7 +144,6 @@ var (
wasm.ModuleName: {authtypes.Burner},
ibchooktypes.ModuleName: nil,
}

// module accounts that are allowed to receive tokens
allowedReceivingModAcc = map[string]bool{
oracletypes.ModuleName: true,
Expand All @@ -162,7 +157,6 @@ func appModules(
skipGenesisInvariants bool,
) []module.AppModule {
appCodec := encodingConfig.Marshaler

return []module.AppModule{
genutil.NewAppModule(
app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx,
Expand Down Expand Up @@ -192,6 +186,7 @@ func appModules(
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
dyncomm.NewAppModule(appCodec, app.DyncommKeeper, app.StakingKeeper),
ibchooks.NewAppModule(app.AccountKeeper),
app.ForwardModule,
}
}

Expand All @@ -201,7 +196,6 @@ func simulationModules(
_ bool,
) []module.AppModuleSimulation {
appCodec := encodingConfig.Marshaler

return []module.AppModuleSimulation{
customauth.NewAppModule(appCodec, app.AccountKeeper, customauthsim.RandomGenesisAccounts),
custombank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
Expand All @@ -224,6 +218,7 @@ func simulationModules(
treasury.NewAppModule(appCodec, app.TreasuryKeeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
dyncomm.NewAppModule(appCodec, app.DyncommKeeper, app.StakingKeeper),
app.ForwardModule,
}
}

Expand All @@ -248,6 +243,7 @@ func orderBeginBlockers() []string {
ibchost.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
forwardtypes.ModuleName,
ibcfeetypes.ModuleName,
ibchooktypes.ModuleName,
// Terra Classic modules
Expand Down Expand Up @@ -280,6 +276,7 @@ func orderEndBlockers() []string {
ibchost.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
forwardtypes.ModuleName,
ibcfeetypes.ModuleName,
ibchooktypes.ModuleName,
// Terra Classic modules
Expand Down Expand Up @@ -312,6 +309,7 @@ func orderInitGenesis() []string {
ibchost.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
forwardtypes.ModuleName,
ibcfeetypes.ModuleName,
ibchooktypes.ModuleName,
// Terra Classic modules
Expand Down
40 changes: 40 additions & 0 deletions app/params/params.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@
package params

import (
"github.com/cosmos/cosmos-sdk/types/address"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/classic-terra/core/v2/types/util"
)

// Simulation parameter constants
const (
StakePerAccount = "stake_per_account"
InitiallyBondedValidators = "initially_bonded_validators"
BondDenom = "uluna"
)

func init() {
phamminh0811 marked this conversation as resolved.
Show resolved Hide resolved
SetAddressPrefixes()
}

// SetAddressPrefixes builds the Config with Bech32 addressPrefix and publKeyPrefix for accounts, validators, and consensus nodes and verifies that addreeses have correct format.
func SetAddressPrefixes() {
phamminh0811 marked this conversation as resolved.
Show resolved Hide resolved
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(util.Bech32PrefixAccAddr, util.Bech32PrefixAccPub)
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
config.SetBech32PrefixForValidator(util.Bech32PrefixValAddr, util.Bech32PrefixValPub)
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
config.SetBech32PrefixForConsensusNode(util.Bech32PrefixConsAddr, util.Bech32PrefixConsPub)
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

// This is copied from the cosmos sdk v0.43.0-beta1
// source: https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/types/address.go#L141
config.SetAddressVerifier(func(bytes []byte) error {
if len(bytes) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty")
}

if len(bytes) > address.MaxAddrLen {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes))
}

// TODO: Do we want to allow addresses of lengths other than 20 and 32 bytes?
if len(bytes) != 20 && len(bytes) != 32 {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes))
}

return nil
})
}
96 changes: 96 additions & 0 deletions custom/bank/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -12,6 +14,8 @@ import (
feeutils "github.com/classic-terra/core/v2/custom/auth/client/utils"
)

var FlagSplit = "split"

// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Expand All @@ -23,6 +27,7 @@ func GetTxCmd() *cobra.Command {
}

txCmd.AddCommand(sendTxCmd())
txCmd.AddCommand(multiSendTxCmd())

return txCmd
}
Expand Down Expand Up @@ -86,3 +91,94 @@ ignored as it is implied from [from_key_or_address].`,

return cmd
}

// multiSendTxCmd create command handler for creating a MsgMultiSend transaction.
func multiSendTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "multi-send [from_key_or_address] [to_address_1 to_address_2 ...] [amount]",
Short: "Send funds from one account to two or more accounts.",
Long: `Send funds from one account to two or more accounts.
By default, sends the [amount] to each address of the list.
Using the '--split' flag, the [amount] is split equally between the addresses.`,
Args: cobra.MinimumNArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Flags().Set(flags.FlagFrom, args[0])
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

coins, err := sdk.ParseCoinsNormalized(args[len(args)-1])
if err != nil {
return err
}

if coins.IsZero() {
return fmt.Errorf("must send positive amount")
}

split, err := cmd.Flags().GetBool(FlagSplit)
if err != nil {
return err
}

totalAddrs := sdk.NewInt(int64(len(args) - 2))
// coins to be received by the addresses
sendCoins := coins
if split {
sendCoins = coins.QuoInt(totalAddrs)
}

var output []types.Output
for _, arg := range args[1 : len(args)-1] {
toAddr, err := sdk.AccAddressFromBech32(arg)
if err != nil {
return err
}

output = append(output, types.NewOutput(toAddr, sendCoins))
}

// amount to be send from the from address
var amount sdk.Coins
if split {
// user input: 1000stake to send to 3 addresses
// actual: 333stake to each address (=> 999stake actually sent)
amount = sendCoins.MulInt(totalAddrs)
} else {
amount = coins.MulInt(totalAddrs)
}

msg := types.NewMsgMultiSend([]types.Input{types.NewInput(clientCtx.FromAddress, amount)}, output)
if err := msg.ValidateBasic(); err != nil {
return err
}

// Generate transaction factory for gas simulation
txf := tx.NewFactoryCLI(clientCtx, cmd.Flags())

if !clientCtx.GenerateOnly && txf.Fees().IsZero() {
// estimate tax and gas
stdFee, err := feeutils.ComputeFeesWithCmd(clientCtx, cmd.Flags(), msg)
if err != nil {
return err
}

// override gas and fees
txf = txf.
WithFees(stdFee.Amount.String()).
WithGas(stdFee.Gas).
WithSimulateAndExecute(false).
WithGasPrices("")
}

return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
},
}

cmd.Flags().Bool(FlagSplit, false, "Send the equally split token amount to each address")

flags.AddTxFlagsToCmd(cmd)

return cmd
}
Loading
Loading