-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add fee grant module #8061
Add fee grant module #8061
Changes from 237 commits
abce938
ea6fe7d
c46153c
42c17f5
0c137cb
67cb830
f6ba9bc
a002366
15c6361
410d1f1
f65db09
e0f6327
93c9b7e
7968441
7e82fb8
64d5159
8b2b64b
4e22edd
be12b44
c703e59
907776f
005afd9
45c64d2
87fd0ce
d03c650
e476c03
182eb34
071e111
0a362b8
98b88a3
376e9cd
529764f
d293aae
a8b3e31
e939e98
6aef5c8
1212772
f688116
61df0c6
d684f92
aacf6fb
92f64cc
4daf4af
a497575
73eab92
546fa8f
5f9e391
c45dc71
2be48ef
e8a624f
6756099
320bad4
a625fd0
4b4391b
9ec284b
4b34cf6
78f1f7a
a1951b4
17c39ca
9c399bb
6b9e06e
21b0ac5
2222d0e
eda42d4
a56b472
be29328
786bf01
5f2bcb5
314b099
29958e0
fb5b97a
eedb8d8
88df255
dbf3578
375f114
9af9f43
3c390e5
de694c5
720e9f4
eb46dd0
63cca04
8eddbb7
f32db1d
8dc477a
b8038ee
c34217a
bd0443c
3d72df8
8d42ee1
2e51274
1617e5a
76c38ec
13f503e
cb10556
ea8492c
7ed4d95
c89db6d
37aa0c1
aad466a
d8962c2
a96d5a5
550086e
2c1902b
6c16146
755da02
1892a3d
13eea6e
07847ab
29a1fc1
85cd87e
24b1c9a
d838333
0a258ac
695b143
e59e303
9ea89d9
debec04
fc4543d
865f70e
3b43fef
3c69591
5eb8f22
ec9dad3
f69d5dd
e424be4
1d54333
a5483f9
1907c0c
eedc5a5
182507f
bab66dd
3e00831
922a437
dc6eeb6
738bdd0
d06fb86
c5abc6e
9f74c5d
5adf5fe
d2f494c
14f6183
5f69caa
bd96862
07da6b0
eba8213
287b6ac
8b11072
4ca4304
5aaf0c5
1884fb7
5ffc768
e735ad8
9600bbf
dff0c63
b8f2f02
79e71ad
2a62fb9
7e74e35
ad3d8c4
8061f2d
1ea308a
38ff641
89ef367
9bd77ae
980b7db
0e48652
c9d5f81
26238b2
0225e2d
bef09b7
d8fd446
d7c63fb
b656a14
458e76e
d5d948c
fc9b0dc
35fe6a7
db78a92
0692eb0
a153873
cf547d9
ba0f83a
a893e92
ba9dd4a
9a68d51
90c3e7f
1a056a9
bfeb2d9
ec5129a
24fbc1a
de83e01
5b5a0fc
7131468
35bd132
b0299a4
3031218
6701433
f484c58
a05a4c6
fa5b4f2
25f18d8
b283eb7
7bf2195
958715e
96bc2ae
6716ffa
99c65bd
b0d5f7d
f40ed08
c234b1a
605b530
35d9fb1
f5fae0f
f2998e7
a22c736
9efd541
27c9182
d3423bf
0ff9ade
a0d67bd
3497817
65547e7
fa01503
4c091fd
86714f1
1d6f9cf
e908652
e5d2610
0ffebce
fa37825
f2b616f
d2cc66e
c172cca
8d8f137
3dfb3ab
3398c46
a344c78
6509b55
fc5b9e1
4987bd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
syntax = "proto3"; | ||
package cosmos.feegrant.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "google/protobuf/any.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
import "google/protobuf/timestamp.proto"; | ||
import "google/protobuf/duration.proto"; | ||
|
||
option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant/types"; | ||
|
||
// BasicFeeAllowance implements FeeAllowance with a one-time grant of tokens | ||
// that optionally expires. The delegatee can use up to SpendLimit to cover fees. | ||
message BasicFeeAllowance { | ||
option (cosmos_proto.implements_interface) = "FeeAllowanceI"; | ||
|
||
repeated cosmos.base.v1beta1.Coin spend_limit = 1 | ||
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; | ||
ExpiresAt expiration = 2 [(gogoproto.nullable) = false]; | ||
amaury1093 marked this conversation as resolved.
Show resolved
Hide resolved
atheeshp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// PeriodicFeeAllowance extends FeeAllowance to allow for both a maximum cap, | ||
// as well as a limit per time period. | ||
message PeriodicFeeAllowance { | ||
option (cosmos_proto.implements_interface) = "FeeAllowanceI"; | ||
|
||
BasicFeeAllowance basic = 1 [(gogoproto.nullable) = false]; | ||
amaury1093 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Duration period = 2 [(gogoproto.nullable) = false]; | ||
repeated cosmos.base.v1beta1.Coin period_spend_limit = 3 | ||
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; | ||
repeated cosmos.base.v1beta1.Coin period_can_spend = 4 | ||
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; | ||
|
||
ExpiresAt period_reset = 5 [(gogoproto.nullable) = false]; | ||
atheeshp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// Duration is a span of a clock time or number of blocks. | ||
// This is designed to be added to an ExpiresAt struct. | ||
message Duration { | ||
// sum is the oneof that represents either duration or block | ||
oneof sum { | ||
google.protobuf.Duration duration = 1 [(gogoproto.stdduration) = true]; | ||
uint64 blocks = 2; | ||
} | ||
} | ||
|
||
// ExpiresAt is a point in time where something expires. | ||
// It may be *either* block time or block height | ||
message ExpiresAt { | ||
// sum is the oneof that represents either time or height | ||
oneof sum { | ||
google.protobuf.Timestamp time = 1 [(gogoproto.stdtime) = true]; | ||
int64 height = 2; | ||
} | ||
} | ||
|
||
// FeeAllowanceGrant is stored in the KVStore to record a grant with full context | ||
message FeeAllowanceGrant { | ||
|
||
string granter = 1; | ||
string grantee = 2; | ||
google.protobuf.Any allowance = 3 [(cosmos_proto.accepts_interface) = "FeeAllowanceI"]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
syntax = "proto3"; | ||
package cosmos.feegrant.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos/feegrant/v1beta1/feegrant.proto"; | ||
|
||
option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant/types"; | ||
|
||
// GenesisState contains a set of fee allowances, persisted from the store | ||
message GenesisState { | ||
repeated FeeAllowanceGrant fee_allowances = 1 [(gogoproto.nullable) = false]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
syntax = "proto3"; | ||
package cosmos.feegrant.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos/feegrant/v1beta1/feegrant.proto"; | ||
import "cosmos/base/query/v1beta1/pagination.proto"; | ||
import "google/api/annotations.proto"; | ||
|
||
option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant/types"; | ||
|
||
// Query defines the gRPC querier service. | ||
service Query { | ||
|
||
// FeeAllowance returns fee granted to the grantee by the granter. | ||
atheeshp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rpc FeeAllowance(QueryFeeAllowanceRequest) returns (QueryFeeAllowanceResponse) { | ||
option (google.api.http).get = "/cosmos/feegrant/v1beta1/fee_allowance/{granter}/{grantee}"; | ||
} | ||
|
||
// FeeAllowances returns all the grants for address. | ||
rpc FeeAllowances(QueryFeeAllowancesRequest) returns (QueryFeeAllowancesResponse) { | ||
option (google.api.http).get = "/cosmos/feegrant/v1beta1/fee_allowances/{grantee}"; | ||
} | ||
} | ||
|
||
// QueryFeeAllowanceRequest is the request type for the Query/FeeAllowance RPC method. | ||
message QueryFeeAllowanceRequest { | ||
string granter = 1; | ||
string grantee = 2; | ||
} | ||
|
||
// QueryFeeAllowanceResponse is the response type for the Query/FeeAllowance RPC method. | ||
message QueryFeeAllowanceResponse { | ||
// fee_allowance is a fee_allowance granted for grantee by granter. | ||
cosmos.feegrant.v1beta1.FeeAllowanceGrant fee_allowance = 1; | ||
} | ||
|
||
// QueryFeeAllowancesRequest is the request type for the Query/FeeAllowances RPC method. | ||
message QueryFeeAllowancesRequest { | ||
string grantee = 1; | ||
|
||
// pagination defines an pagination for the request. | ||
cosmos.base.query.v1beta1.PageRequest pagination = 2; | ||
} | ||
|
||
// QueryFeeAllowancesResponse is the response type for the Query/FeeAllowances RPC method. | ||
message QueryFeeAllowancesResponse { | ||
// fee_allowances are fee_allowance's granted for grantee by granter. | ||
repeated cosmos.feegrant.v1beta1.FeeAllowanceGrant fee_allowances = 1; | ||
|
||
// pagination defines an pagination for the response. | ||
cosmos.base.query.v1beta1.PageResponse pagination = 2; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
syntax = "proto3"; | ||
package cosmos.feegrant.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "google/protobuf/any.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
|
||
option go_package = "github.com/cosmos/cosmos-sdk/x/feegrant/types"; | ||
|
||
// Msg defines the feegrant msg service. | ||
service Msg { | ||
|
||
// GrantFeeAllowance grants fee allowance to the grantee on the granter's | ||
// account with the provided expiration time. | ||
rpc GrantFeeAllowance(MsgGrantFeeAllowance) returns (MsgGrantFeeAllowanceResponse); | ||
|
||
// RevokeFeeAllowance revokes any fee allowance of granter's account that | ||
// has been granted to the grantee. | ||
rpc RevokeFeeAllowance(MsgRevokeFeeAllowance) returns (MsgRevokeFeeAllowanceResponse); | ||
amaury1093 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// MsgGrantFeeAllowance adds permission for Grantee to spend up to Allowance | ||
// of fees from the account of Granter. | ||
message MsgGrantFeeAllowance { | ||
string granter = 1; | ||
string grantee = 2; | ||
google.protobuf.Any allowance = 3 [(cosmos_proto.accepts_interface) = "FeeAllowanceI"]; | ||
} | ||
|
||
// MsgGrantFeeAllowanceResponse defines the Msg/GrantFeeAllowanceResponse response type. | ||
message MsgGrantFeeAllowanceResponse {} | ||
|
||
// MsgRevokeFeeAllowance removes any existing FeeAllowance from Granter to Grantee. | ||
message MsgRevokeFeeAllowance { | ||
string granter = 1; | ||
string grantee = 2; | ||
} | ||
|
||
// MsgRevokeFeeAllowanceResponse defines the Msg/RevokeFeeAllowanceResponse response type. | ||
message MsgRevokeFeeAllowanceResponse {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ante | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authante "github.com/cosmos/cosmos-sdk/x/auth/ante" | ||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" | ||
"github.com/cosmos/cosmos-sdk/x/auth/signing" | ||
feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" | ||
feegranttypes "github.com/cosmos/cosmos-sdk/x/feegrant/types" | ||
) | ||
|
||
// NewAnteHandler returns an AnteHandler that checks and increments sequence | ||
// numbers, checks signatures & account numbers, and deducts fees from the | ||
// fee_payer or from fee_granter (if valid grant exist). | ||
func NewAnteHandler( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't we just add the i don't think we need to have 2 of these big middleware chains. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I start working on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I totally agree that feegrant is an optional module. However, in simapp we want to add it, so simapp should just use x/auth/ante's antehandler (which includes DeductGrantedFeeDecorator). If an app developer doesn't want feegrant, they can just create their own |
||
ak authkeeper.AccountKeeper, bankKeeper feegranttypes.BankKeeper, feeGrantKeeper feegrantkeeper.Keeper, | ||
sigGasConsumer authante.SignatureVerificationGasConsumer, signModeHandler signing.SignModeHandler, | ||
) sdk.AnteHandler { | ||
|
||
return sdk.ChainAnteDecorators( | ||
authante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first | ||
authante.NewRejectExtensionOptionsDecorator(), | ||
authante.NewMempoolFeeDecorator(), | ||
authante.NewValidateBasicDecorator(), | ||
authante.TxTimeoutHeightDecorator{}, | ||
authante.NewValidateMemoDecorator(ak), | ||
authante.NewConsumeGasForTxSizeDecorator(ak), | ||
NewDeductGrantedFeeDecorator(ak, bankKeeper, feeGrantKeeper), | ||
authante.NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators | ||
authante.NewValidateSigCountDecorator(ak), | ||
authante.NewSigGasConsumeDecorator(ak, sigGasConsumer), | ||
authante.NewSigVerificationDecorator(ak, signModeHandler), | ||
authante.NewIncrementSequenceDecorator(ak), // innermost AnteDecorator | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.