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

feat(v2.11): smart accounts #270

Open
wants to merge 70 commits into
base: release/v2.11
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
b50947e
create smartaccounts skeleton
freeelancer Feb 16, 2024
51510f6
added setting proto
freeelancer Feb 17, 2024
6cbcb55
added ante and post handlers
freeelancer Feb 18, 2024
deb83ca
created msg skeletons
freeelancer Feb 18, 2024
b0ddee5
added basic impl for msgserver
freeelancer Feb 18, 2024
27bebde
added genesis file
freeelancer Feb 18, 2024
e15310e
updated readme
freeelancer Feb 18, 2024
b6b8712
feat: added wasm interfaces
javiersuweijie Feb 20, 2024
f85d59b
added wasmkeeper
freeelancer Feb 20, 2024
84a6d23
able to call create-smart-account
freeelancer Feb 21, 2024
b80ca06
added setting query
freeelancer Feb 21, 2024
4de7aaf
fixed linting errors
freeelancer Feb 21, 2024
ae663b9
feat: added pre-txn hooks + testing framework
javiersuweijie Feb 21, 2024
515e46a
feat: store settings in ctx
javiersuweijie Feb 22, 2024
777132c
fix lint
freeelancer Feb 22, 2024
965500f
Merge pull request #264 from terra-money/feat/pre-transaction-hooks
freeelancer Feb 22, 2024
b65a038
test: added sample auth contract wasm for testing
javiersuweijie Feb 22, 2024
73b0173
only support single sig
freeelancer Feb 23, 2024
23fe780
fix review
freeelancer Feb 26, 2024
b8f2482
reduce branching
freeelancer Feb 26, 2024
23c8508
Merge pull request #263 from terra-money/feat/smartaccounts/wasm
javiersuweijie Feb 26, 2024
cb6f9c1
make decorator format consistent
freeelancer Feb 28, 2024
3b763db
Added sudo msgs
freeelancer Feb 28, 2024
63ffbb3
added auth tests
freeelancer Feb 28, 2024
49a40be
fix: wasm contract interface
javiersuweijie Feb 29, 2024
f1bbecf
latest contracts
freeelancer Feb 29, 2024
c967ef9
only support single sig for now
freeelancer Feb 29, 2024
5f9603a
update to latest interface
freeelancer Feb 29, 2024
f5c7fcf
update auth interface and wasm contract
javiersuweijie Feb 29, 2024
7b16b90
Revert "only support single sig for now"
freeelancer Feb 29, 2024
4f0114f
Merge branch 'release/v2.10' of https://github.com/terra-money/core i…
emidev98 Feb 29, 2024
8e08a83
passed auth_test
freeelancer Mar 1, 2024
a859d3a
fix tests
freeelancer Mar 2, 2024
fb448bb
added posttx tests
freeelancer Mar 2, 2024
113c6c4
added msg_server tests
freeelancer Mar 4, 2024
307363b
added test for update auth
freeelancer Mar 4, 2024
08771d4
add amino codec
freeelancer Mar 4, 2024
7549699
added test for updateTxHooks
freeelancer Mar 4, 2024
1ef05b7
update setting api url
freeelancer Mar 5, 2024
ef4ba86
changed fallback casing
freeelancer Mar 5, 2024
33943b0
added smartaccount.test.ts
freeelancer Mar 7, 2024
d8a0a4f
change to senderAcc
freeelancer Mar 7, 2024
519bdca
init auth account from update auth
freeelancer Mar 7, 2024
07092bc
change update auth message
freeelancer Mar 7, 2024
b68ffad
fixed UpdateAuth tests
freeelancer Mar 7, 2024
29004fb
changed query to return human readable base64
freeelancer Mar 8, 2024
dea147e
refactor: remove bad comments
javiersuweijie Mar 11, 2024
67596fe
changed initialization proto
freeelancer Mar 11, 2024
6af225b
fixed smartaccount test
freeelancer Mar 11, 2024
d89467f
split to two files
freeelancer Mar 11, 2024
50629a4
feat: handle multi signatures
javiersuweijie Mar 12, 2024
5d95841
removed adding ctx setting
freeelancer Mar 12, 2024
de029a4
added msgdisable test
freeelancer Mar 12, 2024
8c23207
tests + fixes: custom multisig tests
javiersuweijie Mar 12, 2024
7663195
fix all tests
freeelancer Mar 12, 2024
4e1ab0c
Update x/smartaccount/ante/auth.go
javiersuweijie Mar 12, 2024
cd5bdfd
feat: handle nested native multisigs
javiersuweijie Mar 12, 2024
e37dcd5
Merge branch 'feat/smartaccounts/multisig' of github.com:terra-money/…
javiersuweijie Mar 12, 2024
7704816
fix: get sa settings using ctx
javiersuweijie Mar 12, 2024
bbb9e44
fix: get settings when simulating
javiersuweijie Mar 12, 2024
2a77d90
refactor: moved simulation check
javiersuweijie Mar 12, 2024
e0989c7
update package.json
freeelancer Mar 12, 2024
eae5583
Merge pull request #278 from terra-money/fix/setting-with-value
javiersuweijie Mar 12, 2024
7052fa9
change sender to senders
freeelancer Mar 12, 2024
48a1b2f
Merge pull request #277 from terra-money/feat/smartaccounts/multisig
javiersuweijie Mar 12, 2024
c8fbdb0
added unit test for limit min coins hooks
freeelancer Mar 14, 2024
3394cc5
added posttx tests
freeelancer Mar 14, 2024
2871b26
fixed tests
freeelancer Mar 14, 2024
f764d50
Merge pull request #281 from terra-money/feat/smartaccounts/posttx
emidev98 Mar 19, 2024
00969a1
Merge branch 'release/v2.11' of https://github.com/terra-money/core i…
emidev98 Mar 25, 2024
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
37 changes: 27 additions & 10 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
feesharekeeper "github.com/terra-money/core/v2/x/feeshare/keeper"

smartaccountante "github.com/terra-money/core/v2/x/smartaccount/ante"
smartaccountkeeper "github.com/terra-money/core/v2/x/smartaccount/keeper"

"github.com/cosmos/cosmos-sdk/client"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -14,19 +17,22 @@ import (

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"
terrawasmkeeper "github.com/terra-money/core/v2/x/wasm/keeper"
)

// HandlerOptions extends the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
ante.HandlerOptions

IBCkeeper *ibckeeper.Keeper
FeeShareKeeper feesharekeeper.Keeper
BankKeeper bankKeeper.Keeper
TxCounterStoreKey storetypes.StoreKey
WasmConfig wasmTypes.WasmConfig
TxConfig client.TxConfig
IBCkeeper *ibckeeper.Keeper
FeeShareKeeper feesharekeeper.Keeper
BankKeeper bankKeeper.Keeper
SmartAccountKeeper *smartaccountkeeper.Keeper
WasmKeeper *terrawasmkeeper.Keeper
TxCounterStoreKey storetypes.StoreKey
WasmConfig wasmTypes.WasmConfig
TxConfig client.TxConfig
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
Expand All @@ -45,6 +51,14 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

if options.SmartAccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "smart account keeper is required for ante builder")
}

if options.WasmKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm keeper is required for ante builder")
}

sigGasConsumer := options.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
Expand All @@ -60,11 +74,14 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
// TODO: remove the following line after the migration to the new signature verification decorator is done
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
// ante.NewSetPubKeyDecorator(options.AccountKeeper),
// ante.NewValidateSigCountDecorator(options.AccountKeeper),
// ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
// ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
smartaccountante.NewSmartAccountAuthDecorator(*options.SmartAccountKeeper, options.WasmKeeper, options.AccountKeeper, sigGasConsumer, options.SignModeHandler),
smartaccountante.NewPreTransactionHookDecorator(*options.SmartAccountKeeper, options.WasmKeeper),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCkeeper),
}
Expand Down
19 changes: 11 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,24 @@ func NewTerraApp(
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: cosmosante.DefaultSigVerificationGasConsumer,
},
BankKeeper: app.Keepers.BankKeeper,
FeeShareKeeper: app.Keepers.FeeShareKeeper,
IBCkeeper: app.Keepers.IBCKeeper,
TxCounterStoreKey: app.keys[wasmtypes.StoreKey],
WasmConfig: wasmConfig,
BankKeeper: app.Keepers.BankKeeper,
SmartAccountKeeper: &app.Keepers.SmartAccountKeeper,
WasmKeeper: &app.Keepers.WasmKeeper,
FeeShareKeeper: app.Keepers.FeeShareKeeper,
IBCkeeper: app.Keepers.IBCKeeper,
TxCounterStoreKey: app.keys[wasmtypes.StoreKey],
WasmConfig: wasmConfig,
},
)
if err != nil {
panic(err)
}
postHandler := post.NewPostHandler(
post.HandlerOptions{
FeeShareKeeper: app.Keepers.FeeShareKeeper,
BankKeeper: app.Keepers.BankKeeper,
WasmKeeper: app.Keepers.WasmKeeper,
FeeShareKeeper: app.Keepers.FeeShareKeeper,
BankKeeper: app.Keepers.BankKeeper,
WasmKeeper: app.Keepers.WasmKeeper,
SmartAccountKeeper: &app.Keepers.SmartAccountKeeper,
},
)

Expand Down
7 changes: 7 additions & 0 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
smartaccounttypes "github.com/terra-money/core/v2/x/smartaccount/types"
)

// GenesisState - The genesis state of the blockchain is represented here as a map of raw json
Expand Down Expand Up @@ -79,6 +80,12 @@ func (genState GenesisState) SetDefaultTerraConfig(cdc codec.JSONCodec) GenesisS
}
genState[icatypes.ModuleName] = cdc.MustMarshalJSON(&icaGenState)

var smartaccountGenState smartaccounttypes.GenesisState
cdc.MustUnmarshalJSON(genState[smartaccounttypes.ModuleName], &smartaccountGenState)
setting := smartaccounttypes.NewSetting("terra1tck9vx8vwu6l83zy76ssdkhnhw8dfcrt80hc6x")
smartaccountGenState.Settings = smartaccounttypes.NewSettings(&setting)
genState[smartaccounttypes.ModuleName] = cdc.MustMarshalJSON(&smartaccountGenState)

return genState
}

Expand Down
41 changes: 41 additions & 0 deletions app/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app_test

import (
"encoding/json"
"io/ioutil"
"os"
"testing"
"time"
Expand All @@ -20,6 +21,7 @@ import (
"github.com/terra-money/alliance/x/alliance"
"github.com/terra-money/core/v2/app"
"github.com/terra-money/core/v2/x/feeshare"
"github.com/terra-money/core/v2/x/smartaccount"
"github.com/terra-money/core/v2/x/tokenfactory"

mocktestutils "github.com/cosmos/cosmos-sdk/testutil/mock"
Expand Down Expand Up @@ -224,6 +226,7 @@ func (s *AppGenesisTestSuite) TestMigration() {
"upgrade": upgrade.AppModule{}.ConsensusVersion(),
"vesting": vesting.AppModule{}.ConsensusVersion(),
"wasm": wasm.AppModule{}.ConsensusVersion(),
"smartaccount": smartaccount.AppModule{}.ConsensusVersion(),
},
)
s.Require().NoError(err)
Expand Down Expand Up @@ -257,6 +260,7 @@ func (s *AppGenesisTestSuite) TestMigration() {
"upgrade": 2,
"vesting": 1,
"wasm": 4,
"smartaccount": 1,
})
}

Expand Down Expand Up @@ -685,6 +689,41 @@ func (s *AppGenesisTestSuite) TestGenesis() {
"redelegations": [],
"exported": false
},
"smartaccount": {
"params": {
},
"settings": [
{
"owner": "terra1tck9vx8vwu6l83zy76ssdkhnhw8dfcrt80hc6x",
"authorization": [],
"pre_transaction": [],
"post_transaction": [],
"fallback": true
}
]
},
"staking": {
"delegations": [
],
"exported": false,
"last_total_power": "0",
"last_validator_powers": [
],
"params": {
"bond_denom": "uluna",
"historical_entries": 10000,
"max_entries": 7,
"max_validators": 100,
"min_commission_rate": "0.000000000000000000",
"unbonding_time": "1814400s"
},
"redelegations": [
],
"unbonding_delegations": [
],
"validators": [
]
},
"tokenfactory": {
"params": {
"denom_creation_fee": [
Expand Down Expand Up @@ -721,5 +760,7 @@ func (s *AppGenesisTestSuite) TestGenesis() {
"sequences": []
}
}`
// write jsonGenState to file for debugging
ioutil.WriteFile("genesis1.json", jsonGenState, 0644)
s.Require().JSONEq(string(jsonGenState), expectedState)
}
15 changes: 12 additions & 3 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package keepers

import (

// #nosec G702

"path/filepath"

"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/router"
Expand Down Expand Up @@ -100,6 +97,9 @@ import (
feesharekeeper "github.com/terra-money/core/v2/x/feeshare/keeper"
feesharetypes "github.com/terra-money/core/v2/x/feeshare/types"

smartaccountkeeper "github.com/terra-money/core/v2/x/smartaccount/keeper"
smartaccounttypes "github.com/terra-money/core/v2/x/smartaccount/types"

terraappconfig "github.com/terra-money/core/v2/app/config"
// unnamed import of statik for swagger UI support
_ "github.com/terra-money/core/v2/client/docs/statik"
Expand All @@ -123,6 +123,7 @@ var maccPerms = map[string][]string{
tokenfactorytypes.ModuleName: {authtypes.Burner, authtypes.Minter},
alliancetypes.ModuleName: {authtypes.Burner, authtypes.Minter},
alliancetypes.RewardsPoolName: nil,
smartaccounttypes.ModuleName: nil,
}

type TerraAppKeepers struct {
Expand Down Expand Up @@ -157,6 +158,7 @@ type TerraAppKeepers struct {
AllianceKeeper alliancekeeper.Keeper
FeeShareKeeper feesharekeeper.Keeper
ICQKeeper icqkeeper.Keeper
SmartAccountKeeper smartaccountkeeper.Keeper

// IBC hooks
IBCHooksKeeper *ibchookskeeper.Keeper
Expand Down Expand Up @@ -469,6 +471,12 @@ func NewTerraAppKeepers(
wasmOpts...,
)

keepers.SmartAccountKeeper = smartaccountkeeper.NewKeeper(
appCodec,
keys[smartaccounttypes.StoreKey],
keepers.WasmKeeper.Keeper,
)

keepers.Ics20WasmHooks.ContractKeeper = keepers.WasmKeeper.Keeper
// Setup the contract keepers.WasmKeeper before the
// hook for the BankKeeper othrwise the WasmKeeper
Expand Down Expand Up @@ -571,6 +579,7 @@ func (app *TerraAppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legacyA
paramsKeeper.Subspace(tokenfactorytypes.ModuleName).WithKeyTable(tokenfactorytypes.ParamKeyTable())
paramsKeeper.Subspace(feesharetypes.ModuleName).WithKeyTable(feesharetypes.ParamKeyTable())
paramsKeeper.Subspace(alliancetypes.ModuleName).WithKeyTable(alliancetypes.ParamKeyTable())
paramsKeeper.Subspace(smartaccounttypes.ModuleName).WithKeyTable(smartaccounttypes.ParamKeyTable())

return paramsKeeper
}
Expand Down
3 changes: 3 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import (
alliancetypes "github.com/terra-money/alliance/x/alliance/types"
feesharetypes "github.com/terra-money/core/v2/x/feeshare/types"

smartaccounttypes "github.com/terra-money/core/v2/x/smartaccount/types"

// unnamed import of statik for swagger UI support
_ "github.com/terra-money/core/v2/client/docs/statik"
)
Expand All @@ -61,6 +63,7 @@ func (keepers *TerraAppKeepers) GenerateKeys() {
consensusparamtypes.StoreKey, tokenfactorytypes.StoreKey, wasmtypes.StoreKey,
ibcfeetypes.StoreKey, ibchookstypes.StoreKey, crisistypes.StoreKey,
alliancetypes.StoreKey, feesharetypes.StoreKey, icqtypes.StoreKey,
smartaccounttypes.StoreKey,
)

keepers.tkeys = sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down
7 changes: 7 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/terra-money/core/v2/x/smartaccount"
smartaccounttypes "github.com/terra-money/core/v2/x/smartaccount/types"

"github.com/cosmos/cosmos-sdk/x/gov"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
Expand Down Expand Up @@ -117,6 +119,7 @@ var ModuleBasics = module.NewBasicManager(
alliance.AppModuleBasic{},
feeshare.AppModuleBasic{},
icq.AppModuleBasic{},
smartaccount.AppModuleBasic{},
)

// NOTE: Any module instantiated in the module manager that is later modified
Expand Down Expand Up @@ -154,6 +157,7 @@ func appModules(app *TerraApp, encodingConfig terrappsparams.EncodingConfig, ski
alliance.NewAppModule(app.appCodec, app.Keepers.AllianceKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.interfaceRegistry, app.GetSubspace(alliancetypes.ModuleName)),
feeshare.NewAppModule(app.Keepers.FeeShareKeeper, app.Keepers.AccountKeeper, app.GetSubspace(feesharetypes.ModuleName)),
icq.NewAppModule(app.Keepers.ICQKeeper),
smartaccount.NewAppModule(app.Keepers.SmartAccountKeeper, app.GetSubspace(smartaccounttypes.ModuleName)),
}
}

Expand Down Expand Up @@ -191,6 +195,7 @@ var initGenesisOrder = []string{
feesharetypes.ModuleName,
consensusparamtypes.ModuleName,
icqtypes.ModuleName,
smartaccounttypes.ModuleName,
}

var beginBlockersOrder = []string{
Expand Down Expand Up @@ -223,6 +228,7 @@ var beginBlockersOrder = []string{
feesharetypes.ModuleName,
consensusparamtypes.ModuleName,
icqtypes.ModuleName,
smartaccounttypes.ModuleName,
}

var endBlockerOrder = []string{
Expand Down Expand Up @@ -255,4 +261,5 @@ var endBlockerOrder = []string{
feesharetypes.ModuleName,
consensusparamtypes.ModuleName,
icqtypes.ModuleName,
smartaccounttypes.ModuleName,
}
5 changes: 5 additions & 0 deletions app/post/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package post

import (
feesharepost "github.com/terra-money/core/v2/x/feeshare/post"
smartaccountkeeper "github.com/terra-money/core/v2/x/smartaccount/keeper"
smartaccountpost "github.com/terra-money/core/v2/x/smartaccount/post"
customwasmkeeper "github.com/terra-money/core/v2/x/wasm/keeper"
wasmpost "github.com/terra-money/core/v2/x/wasm/post"

Expand All @@ -12,13 +14,16 @@ type HandlerOptions struct {
FeeShareKeeper feesharepost.FeeShareKeeper
BankKeeper feesharepost.BankKeeper
WasmKeeper customwasmkeeper.Keeper

SmartAccountKeeper *smartaccountkeeper.Keeper
}

func NewPostHandler(options HandlerOptions) sdk.PostHandler {

postDecorators := []sdk.PostDecorator{
feesharepost.NewFeeSharePayoutDecorator(options.FeeShareKeeper, options.BankKeeper, options.WasmKeeper),
wasmpost.NewWasmdDecorator(options.WasmKeeper),
smartaccountpost.NewPostTransactionHookDecorator(options.SmartAccountKeeper, options.WasmKeeper),
}

return sdk.ChainPostDecorators(postDecorators...)
Expand Down
Loading
Loading