Skip to content

Commit

Permalink
Fix IBC Hooks and PFM (#417)
Browse files Browse the repository at this point in the history
Co-authored-by: Dong Lieu <[email protected]>
  • Loading branch information
phamminh0811 and DongLieu authored Jan 31, 2024
1 parent 7f289db commit be3295a
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 56 deletions.
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
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
}
10 changes: 5 additions & 5 deletions scripts/burn-tax-exemption-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
HOME=mytestnet
ROOT=$(pwd)
DENOM=uluna
KEY="test"
KEY="test0"
KEY1="test1"
KEY2="test2"
KEYRING="test"
CHAIN_ID="test"
CHAIN_ID="localterra"

# underscore so that go tool will not take gocache into account
mkdir -p _build/gocache
Expand All @@ -32,7 +32,7 @@ sleep 20
test1=$(./_build/new/terrad keys show $KEY1 -a --keyring-backend $KEYRING --home $HOME)
test2=$(./_build/new/terrad keys show $KEY2 -a --keyring-backend $KEYRING --home $HOME)
echo "addresses = $test1,$test2"
./_build/new/terrad tx gov submit-proposal add-burn-tax-exemption-address "$test1,$test2" --title "burn tax exemption address" --description "burn tax exemption address" --from $KEY --keyring-backend $KEYRING --chain-id $CHAIN_ID --home $HOME -y
./_build/new/terrad tx gov submit-legacy-proposal add-burn-tax-exemption-address "$test1,$test2" --title "burn tax exemption address" --description "burn tax exemption address" --from $KEY --keyring-backend $KEYRING --chain-id $CHAIN_ID --home $HOME -y

sleep 5

Expand All @@ -48,7 +48,7 @@ sleep 5

sleep 5

while true; do
while true; do
PROPOSAL_STATUS=$(./_build/new/terrad q gov proposal 1 --output=json | jq ".status" -r)
echo $PROPOSAL_STATUS
if [ $PROPOSAL_STATUS = "PROPOSAL_STATUS_PASSED" ]; then
Expand All @@ -68,7 +68,7 @@ echo ""
# query burn tax exemption list through rest api
curl -s http://localhost:1317/treasury/burn_tax_exemption_list | jq ".result.addresses"

./_build/new/terrad tx gov submit-proposal remove-burn-tax-exemption-address "$test1" --title "burn tax exemption address" --description "burn tax exemption address" --from $KEY --keyring-backend $KEYRING --chain-id $CHAIN_ID --home $HOME -y
./_build/new/terrad tx gov submit-legacy-proposal remove-burn-tax-exemption-address "$test1" --title "burn tax exemption address" --description "burn tax exemption address" --from $KEY --keyring-backend $KEYRING --chain-id $CHAIN_ID --home $HOME -y

sleep 5

Expand Down
3 changes: 2 additions & 1 deletion types/assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ const (
MicroGBPDenom = "ugbp"
MicroMNTDenom = "umnt"

MicroUnit = int64(1e6)
MicroUnit = int64(1e6)
ExponentUint = int64(6)
)
Loading

0 comments on commit be3295a

Please sign in to comment.