Skip to content

Commit 7f70e76

Browse files
authored
feat: EnableCommunityPoolFeeFunding (#7)
* chore: tweak verification for better debugging * EnableCommunityPoolFeeFunding
1 parent d85c7ba commit 7f70e76

File tree

9 files changed

+390
-6
lines changed

9 files changed

+390
-6
lines changed

app/app.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ var (
152152
tokenfactorytypes.EnableForceTransfer,
153153
tokenfactorytypes.EnableSetMetadata,
154154
tokenfactorytypes.EnableSudoMint,
155+
tokenfactorytypes.EnableCommunityPoolFeeFunding,
155156
}
156157
)
157158

@@ -547,6 +548,7 @@ func NewApp(
547548
app.TokenFactoryKeeper = tokenfactorykeeper.NewKeeper(
548549
appCodec,
549550
app.keys[tokenfactorytypes.StoreKey],
551+
maccPerms,
550552
app.AccountKeeper,
551553
app.BankKeeper,
552554
app.DistrKeeper,

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,5 @@ require (
216216
github.com/opencontainers/runc v1.1.5 // indirect
217217
github.com/sirupsen/logrus v1.9.3 // indirect
218218
)
219+
220+
require github.com/gogo/status v1.1.0

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+
11221122
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
11231123
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
11241124
github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
1125+
github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
11251126
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
11261127
github.com/gogo/googleapis v1.4.1-0.20201022092350-68b0159b7869/go.mod h1:5YRNX2z1oM5gXdAkurHa942MDgEJyk02w4OecKY87+c=
11271128
github.com/gogo/googleapis v1.4.1 h1:1Yx4Myt7BxzvUr5ldGSbwYiZG6t9wGBZ+8/fX3Wvtq0=
@@ -1132,6 +1133,8 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV
11321133
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
11331134
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
11341135
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
1136+
github.com/gogo/status v1.1.0 h1:+eIkrewn5q6b30y+g/BJINVVdi2xH7je5MPJ3ZPK3JA=
1137+
github.com/gogo/status v1.1.0/go.mod h1:BFv9nrluPLmrS0EmGVvLaPNmRosr9KapBYd5/hpY1WM=
11351138
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
11361139
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
11371140
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
@@ -2379,6 +2382,7 @@ google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCID
23792382
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
23802383
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
23812384
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
2385+
google.golang.org/genproto v0.0.0-20180518175338-11a468237815/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
23822386
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
23832387
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
23842388
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
@@ -2557,6 +2561,7 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.
25572561
google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13/go.mod h1:KSqppvjFjtoCI+KGd4PELB0qLNxdJHRGqRI09mB6pQA=
25582562
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 h1:/jFB8jK5R3Sq3i/lmeZO0cATSzFfZaJq1J2Euan3XKU=
25592563
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0/go.mod h1:FUoWkonphQm3RhTS+kOEhF8h0iDpm4tdXolVCeZ9KKA=
2564+
google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
25602565
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
25612566
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
25622567
google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM=

go.work.sum

Lines changed: 330 additions & 0 deletions
Large diffs are not rendered by default.

x/tokenfactory/keeper/bankactions.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package keeper
22

33
import (
44
"fmt"
5+
"sort"
56

7+
"github.com/gogo/status"
68
"github.com/strangelove-ventures/tokenfactory/x/tokenfactory/types"
9+
"google.golang.org/grpc/codes"
710

811
sdk "github.com/cosmos/cosmos-sdk/types"
912
)
@@ -75,6 +78,23 @@ func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr string,
7578
return err
7679
}
7780

81+
sortedPermAddrs := make([]string, 0, len(k.permAddrs))
82+
for moduleName := range k.permAddrs {
83+
sortedPermAddrs = append(sortedPermAddrs, moduleName)
84+
}
85+
sort.Strings(sortedPermAddrs)
86+
87+
for _, moduleName := range sortedPermAddrs {
88+
account := k.accountKeeper.GetModuleAccount(ctx, moduleName)
89+
if account == nil {
90+
return status.Errorf(codes.NotFound, "account %s not found", moduleName)
91+
}
92+
93+
if account.GetAddress().Equals(fromSdkAddr) {
94+
return status.Errorf(codes.Internal, "send from module acc not available")
95+
}
96+
}
97+
7898
toSdkAddr, err := sdk.AccAddressFromBech32(toAddr)
7999
if err != nil {
80100
return err

x/tokenfactory/keeper/createdenom.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,20 @@ func (k Keeper) chargeForCreateDenom(ctx sdk.Context, creatorAddr string, _ stri
8484
return err
8585
}
8686

87-
if err := k.communityPoolKeeper.FundCommunityPool(ctx, params.DenomCreationFee, accAddr); err != nil {
88-
return err
87+
if types.IsCapabilityEnabled(k.enabledCapabilities, types.EnableCommunityPoolFeeFunding) {
88+
if err := k.communityPoolKeeper.FundCommunityPool(ctx, params.DenomCreationFee, accAddr); err != nil {
89+
return err
90+
}
91+
} else {
92+
err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, accAddr, types.ModuleName, params.DenomCreationFee)
93+
if err != nil {
94+
return err
95+
}
96+
97+
err = k.bankKeeper.BurnCoins(ctx, types.ModuleName, params.DenomCreationFee)
98+
if err != nil {
99+
return err
100+
}
89101
}
90102
}
91103

x/tokenfactory/keeper/keeper.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66

7+
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
78
"github.com/strangelove-ventures/tokenfactory/x/tokenfactory/types"
89

910
"cosmossdk.io/log"
@@ -19,8 +20,9 @@ type (
1920
IsSudoAdmin func(ctx context.Context, addr string) bool
2021

2122
Keeper struct {
22-
cdc codec.BinaryCodec
23-
storeKey store.StoreKey
23+
cdc codec.BinaryCodec
24+
storeKey store.StoreKey
25+
permAddrs map[string]authtypes.PermissionsForAddress
2426

2527
accountKeeper types.AccountKeeper
2628
bankKeeper types.BankKeeper
@@ -40,6 +42,7 @@ type (
4042
func NewKeeper(
4143
cdc codec.BinaryCodec,
4244
storeKey store.StoreKey,
45+
maccPerms map[string][]string,
4346
accountKeeper types.AccountKeeper,
4447
bankKeeper types.BankKeeper,
4548
communityPoolKeeper types.CommunityPoolKeeper,
@@ -48,9 +51,15 @@ func NewKeeper(
4851
isSudoAdminFunc IsSudoAdmin,
4952
authority string,
5053
) Keeper {
54+
permAddrs := make(map[string]authtypes.PermissionsForAddress)
55+
for name, perms := range maccPerms {
56+
permAddrs[name] = authtypes.NewPermissionsForAddress(name, perms)
57+
}
58+
5159
return Keeper{
52-
cdc: cdc,
53-
storeKey: storeKey,
60+
cdc: cdc,
61+
storeKey: storeKey,
62+
permAddrs: permAddrs,
5463

5564
accountKeeper: accountKeeper,
5665
bankKeeper: bankKeeper,

x/tokenfactory/types/capabilities.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const (
77
// Allows addresses of your choosing to mint tokens based on specific conditions.
88
// via the IsSudoAdminFunc
99
EnableSudoMint = "enable_admin_sudo_mint"
10+
// EnableCommunityPoolFeeFunding sends tokens to the community pool when a new fee is charged (if one is set in params).
11+
// This is useful for ICS chains, or networks who wish to just have the fee tokens burned (not gas fees, just the extra on top).
12+
EnableCommunityPoolFeeFunding = "enable_community_pool_fee_funding"
1013
)
1114

1215
func IsCapabilityEnabled(enabledCapabilities []string, capability string) bool {

x/tokenfactory/types/expected_keepers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type BankKeeper interface {
3232
type AccountKeeper interface {
3333
SetModuleAccount(ctx context.Context, macc sdk.ModuleAccountI)
3434
GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
35+
GetModuleAccount(ctx context.Context, moduleName string) sdk.ModuleAccountI
3536
}
3637

3738
// CommunityPoolKeeper defines the contract needed to be fulfilled for community pool interactions.

0 commit comments

Comments
 (0)