diff --git a/app/app.go b/app/app.go index 0f097d74..4036493d 100644 --- a/app/app.go +++ b/app/app.go @@ -311,6 +311,7 @@ func NewApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, app.cdc, keys[bep3.StoreKey], app.supplyKeeper, + app.accountKeeper, bep3Subspace, ) app.kavadistKeeper = kavadist.NewKeeper( diff --git a/x/bep3/alias.go b/x/bep3/alias.go index 1a315ad9..15babfab 100644 --- a/x/bep3/alias.go +++ b/x/bep3/alias.go @@ -135,7 +135,6 @@ type ( QueryAssetSupply = types.QueryAssetSupply QueryAtomicSwapByID = types.QueryAtomicSwapByID QueryAtomicSwaps = types.QueryAtomicSwaps - SupplyKeeper = types.SupplyKeeper SwapDirection = types.SwapDirection SwapStatus = types.SwapStatus ) diff --git a/x/bep3/genesis.go b/x/bep3/genesis.go index b6d01ad4..e3f34694 100644 --- a/x/bep3/genesis.go +++ b/x/bep3/genesis.go @@ -4,10 +4,12 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/kava-labs/kava/x/bep3/types" ) // InitGenesis initializes the store state from a genesis state. -func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper SupplyKeeper, gs GenesisState) { +func InitGenesis(ctx sdk.Context, keeper Keeper, supplyKeeper types.SupplyKeeper, gs GenesisState) { if err := gs.Validate(); err != nil { panic(fmt.Sprintf("failed to validate %s genesis state: %s", ModuleName, err)) } diff --git a/x/bep3/keeper/keeper.go b/x/bep3/keeper/keeper.go index 430f658d..ec1eb9a4 100644 --- a/x/bep3/keeper/keeper.go +++ b/x/bep3/keeper/keeper.go @@ -19,10 +19,14 @@ type Keeper struct { cdc *codec.Codec paramSubspace subspace.Subspace supplyKeeper types.SupplyKeeper + accountKeeper types.AccountKeeper } // NewKeeper creates a bep3 keeper -func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, sk types.SupplyKeeper, paramstore subspace.Subspace) Keeper { +func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, + sk types.SupplyKeeper, ak types.AccountKeeper, + paramstore subspace.Subspace, +) Keeper { if addr := sk.GetModuleAddress(types.ModuleName); addr == nil { panic(fmt.Sprintf("%s module account has not been set", types.ModuleName)) } @@ -36,6 +40,7 @@ func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, sk types.SupplyKeeper, params cdc: cdc, paramSubspace: paramstore, supplyKeeper: sk, + accountKeeper: ak, } return keeper } diff --git a/x/bep3/keeper/swap.go b/x/bep3/keeper/swap.go index 5f4fc811..ac58affd 100644 --- a/x/bep3/keeper/swap.go +++ b/x/bep3/keeper/swap.go @@ -55,6 +55,13 @@ func (k Keeper) CreateAtomicSwap(ctx sdk.Context, randomNumberHash []byte, times switch direction { case types.Incoming: + // If recipient's account doesn't exist, register it in state so that the address can send + // a claim swap tx without needing to be registered in state by receiving a coin transfer. + recipientAcc := k.accountKeeper.GetAccount(ctx, recipient) + if recipientAcc == nil { + newAcc := k.accountKeeper.NewAccountWithAddress(ctx, recipient) + k.accountKeeper.SetAccount(ctx, newAcc) + } err = k.IncrementIncomingAssetSupply(ctx, amount[0]) case types.Outgoing: err = k.IncrementOutgoingAssetSupply(ctx, amount[0]) diff --git a/x/bep3/module.go b/x/bep3/module.go index de15fac9..1154bcf7 100644 --- a/x/bep3/module.go +++ b/x/bep3/module.go @@ -11,7 +11,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/cosmos/cosmos-sdk/x/auth" sim "github.com/cosmos/cosmos-sdk/x/simulation" abci "github.com/tendermint/tendermint/abci/types" @@ -19,6 +18,7 @@ import ( "github.com/kava-labs/kava/x/bep3/client/cli" "github.com/kava-labs/kava/x/bep3/client/rest" "github.com/kava-labs/kava/x/bep3/simulation" + "github.com/kava-labs/kava/x/bep3/types" ) var ( @@ -78,12 +78,12 @@ type AppModule struct { AppModuleBasic keeper Keeper - accountKeeper auth.AccountKeeper - supplyKeeper SupplyKeeper + accountKeeper types.AccountKeeper + supplyKeeper types.SupplyKeeper } // NewAppModule creates a new AppModule object -func NewAppModule(keeper Keeper, accountKeeper auth.AccountKeeper, supplyKeeper SupplyKeeper) AppModule { +func NewAppModule(keeper Keeper, accountKeeper types.AccountKeeper, supplyKeeper types.SupplyKeeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, keeper: keeper, diff --git a/x/bep3/simulation/operations.go b/x/bep3/simulation/operations.go index 0f3592f5..814845e2 100644 --- a/x/bep3/simulation/operations.go +++ b/x/bep3/simulation/operations.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp/helpers" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/simulation" appparams "github.com/kava-labs/kava/app/params" @@ -28,7 +27,7 @@ const ( // WeightedOperations returns all the operations from the module with their respective weights func WeightedOperations( - appParams simulation.AppParams, cdc *codec.Codec, ak auth.AccountKeeper, k keeper.Keeper, + appParams simulation.AppParams, cdc *codec.Codec, ak types.AccountKeeper, k keeper.Keeper, ) simulation.WeightedOperations { var weightCreateAtomicSwap int @@ -47,7 +46,7 @@ func WeightedOperations( } // SimulateMsgCreateAtomicSwap generates a MsgCreateAtomicSwap with random values -func SimulateMsgCreateAtomicSwap(ak auth.AccountKeeper, k keeper.Keeper) simulation.Operation { +func SimulateMsgCreateAtomicSwap(ak types.AccountKeeper, k keeper.Keeper) simulation.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account, chainID string, ) (simulation.OperationMsg, []simulation.FutureOperation, error) { @@ -143,7 +142,7 @@ func SimulateMsgCreateAtomicSwap(ak auth.AccountKeeper, k keeper.Keeper) simulat } } -func operationClaimAtomicSwap(ak auth.AccountKeeper, k keeper.Keeper, swapID []byte, randomNumber []byte) simulation.Operation { +func operationClaimAtomicSwap(ak types.AccountKeeper, k keeper.Keeper, swapID []byte, randomNumber []byte) simulation.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account, chainID string, ) (simulation.OperationMsg, []simulation.FutureOperation, error) { @@ -176,7 +175,7 @@ func operationClaimAtomicSwap(ak auth.AccountKeeper, k keeper.Keeper, swapID []b } } -func operationRefundAtomicSwap(ak auth.AccountKeeper, k keeper.Keeper, swapID []byte) simulation.Operation { +func operationRefundAtomicSwap(ak types.AccountKeeper, k keeper.Keeper, swapID []byte) simulation.Operation { return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simulation.Account, chainID string, ) (simulation.OperationMsg, []simulation.FutureOperation, error) { diff --git a/x/bep3/types/expected_keepers.go b/x/bep3/types/expected_keepers.go index bb58ef9b..13eeb6b6 100644 --- a/x/bep3/types/expected_keepers.go +++ b/x/bep3/types/expected_keepers.go @@ -2,10 +2,11 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" + authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" supplyexported "github.com/cosmos/cosmos-sdk/x/supply/exported" ) -// SupplyKeeper defines the expected supply Keeper +// SupplyKeeper defines the expected supply keeper (noalias) type SupplyKeeper interface { GetModuleAddress(name string) sdk.AccAddress GetModuleAccount(ctx sdk.Context, moduleName string) supplyexported.ModuleAccountI @@ -17,3 +18,10 @@ type SupplyKeeper interface { BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error } + +// AccountKeeper defines the expected account keeper (noalias) +type AccountKeeper interface { + GetAccount(ctx sdk.Context, addr sdk.AccAddress) authexported.Account + NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authexported.Account + SetAccount(ctx sdk.Context, acc authexported.Account) +}