/
erc20.go
143 lines (128 loc) · 4.93 KB
/
erc20.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package keeper
import (
"testing"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
simparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/bank"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
nfttypes "github.com/cosmos/cosmos-sdk/x/nft"
"github.com/cosmos/cosmos-sdk/x/params"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
"github.com/warmage-sports/warmage/x/erc20/keeper"
"github.com/warmage-sports/warmage/x/erc20/types"
erc20types "github.com/warmage-sports/warmage/x/erc20/types"
gaugetypes "github.com/warmage-sports/warmage/x/gauge/types"
makertypes "github.com/warmage-sports/warmage/x/maker/types"
oracletypes "github.com/warmage-sports/warmage/x/oracle/types"
vetypes "github.com/warmage-sports/warmage/x/ve/types"
customvestingtypes "github.com/warmage-sports/warmage/x/vesting/types"
votertypes "github.com/warmage-sports/warmage/x/voter/types"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmdb "github.com/tendermint/tm-db"
ethermint "github.com/tharsis/ethermint/types"
"github.com/tharsis/ethermint/x/evm"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
)
const faucetAccountName = "faucet"
var (
// module account permissions
maccPerms = map[string][]string{
faucetAccountName: {authtypes.Minter},
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account
erc20types.ModuleName: {authtypes.Minter, authtypes.Burner},
oracletypes.ModuleName: nil,
makertypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking},
nfttypes.ModuleName: nil,
vetypes.ModuleName: {authtypes.Burner},
vetypes.EmissionPoolName: {authtypes.Minter},
vetypes.DistributionPoolName: nil,
gaugetypes.ModuleName: nil,
votertypes.ModuleName: nil,
customvestingtypes.ModuleName: {authtypes.Minter},
}
ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
bank.AppModuleBasic{},
params.AppModuleBasic{},
evm.AppModuleBasic{},
)
InitTokens = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
InitCoins = sdk.NewCoins(sdk.NewCoin("uusd", InitTokens))
)
// MakeEncodingConfig nolint
func MakeEncodingConfig(_ *testing.T) simparams.EncodingConfig {
amino := codec.NewLegacyAmino()
interfaceRegistry := codectypes.NewInterfaceRegistry()
marshaler := codec.NewProtoCodec(interfaceRegistry)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)
std.RegisterInterfaces(interfaceRegistry)
std.RegisterLegacyAminoCodec(amino)
ModuleBasics.RegisterLegacyAminoCodec(amino)
ModuleBasics.RegisterInterfaces(interfaceRegistry)
types.RegisterCodec(amino)
types.RegisterInterfaces(interfaceRegistry)
return simparams.EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: txCfg,
Amino: amino,
}
}
func Erc20Keeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
stateStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, db)
require.NoError(t, stateStore.LoadLatestVersion())
registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)
paramsSubspace := typesparams.NewSubspace(cdc,
types.Amino,
storeKey,
nil,
"Erc20Params",
)
// AccountKeeper
akKey := sdk.NewKVStoreKey(authtypes.StoreKey)
akSubspace := typesparams.NewSubspace(cdc,
types.Amino,
akKey,
nil,
authtypes.ModuleName,
)
accountKeeper := authkeeper.NewAccountKeeper(
cdc, akKey, akSubspace, ethermint.ProtoAccount, maccPerms,
)
k := keeper.NewKeeper(
cdc,
storeKey,
paramsSubspace,
accountKeeper,
nil,
nil,
)
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
// Initialize params
k.SetParams(ctx, types.DefaultParams())
return k, ctx
}