Skip to content

Commit e6bbb6d

Browse files
committed
feat: epoched reward distribution part 1 - buffer
First, buffer the rewards in the vbank module.
1 parent a74e826 commit e6bbb6d

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

golang/cosmos/x/vbank/README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ the bridge to act upon the bank account. Updates to the bank account balance are
99
sent over the bridge to update the bank purse, whose balance can be queried
1010
entirely at the ERTP level.
1111

12+
## Parameters
13+
14+
- `feeCollectorName`: the module which handles fee distribution to stakers.
15+
- `feeEpochDuration`: the duration (in seconds) over which fees should be given to the fee collector.
16+
1217
## State
1318

1419
The Vbank module maintains no significant state, but will access stored state through the bank module.
@@ -29,8 +34,9 @@ The following fields are common to the Vbank messages:
2934

3035
Downcalls from JS to Cosmos (by `type`):
3136
- `VBANK_GET_BALANCE (type, address, denom)`: gets the account balance in the given denomination from the bank. Returns the amount as a string.
32-
- `VBANK_GRAB (type, sender, denom, amount)`: burns amount of denomination from account balance to reflect withdrawal from virtual purse. Returns a `VBANK_BALANCE_UPDATE` message restricted to the sender account and denomination.
3337
- `VBANK_GIVE (type, recipeient, denom, amount)`: adds amount of denomination to account balance to reflect a deposit to the virtual purse. Returns a `VBANK_BALANCE_UPDATE` message restricted to the recipient account and denomination.
38+
- `VBANK_GIVE_TO_FEE_COLLECTOR (type, denom, amount)`: stores rewards which will be gradually sent to the fee collector
39+
- `VBANK_GRAB (type, sender, denom, amount)`: burns amount of denomination from account balance to reflect withdrawal from virtual purse. Returns a `VBANK_BALANCE_UPDATE` message restricted to the sender account and denomination.
3440

3541
Upcalls from Cosmos to JS: (by `type`)
3642
- `VBANK_BALANCE_UPDATE (type, nonce, updated)`: inform virtual purse of change to the account balance (including a change initiated by VBANK_GRAB or VBANK_GIVE).

golang/cosmos/x/vbank/keeper/keeper.go

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func (k Keeper) GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
5959
return k.bankKeeper.GetAllBalances(ctx, addr)
6060
}
6161

62+
func (k Keeper) StoreFeeCoins(ctx sdk.Context, amt sdk.Coins) error {
63+
return k.bankKeeper.MintCoins(ctx, types.ModuleName, amt)
64+
}
65+
6266
func (k Keeper) SendCoinsToFeeCollector(ctx sdk.Context, amt sdk.Coins) error {
6367
if err := k.bankKeeper.MintCoins(ctx, types.ModuleName, amt); err != nil {
6468
return err

golang/cosmos/x/vbank/vbank.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ func (ch portHandler) Receive(ctx *vm.ControllerContext, str string) (ret string
150150
return "", fmt.Errorf("cannot convert %s to int", msg.Amount)
151151
}
152152
coins := sdk.NewCoins(sdk.NewCoin(msg.Denom, value))
153-
if err := keeper.SendCoinsToFeeCollector(ctx.Context, coins); err != nil {
154-
return "", fmt.Errorf("cannot give %s coins: %w", coins.Sort().String(), err)
153+
if err := keeper.StoreFeeCoins(ctx.Context, coins); err != nil {
154+
return "", fmt.Errorf("cannot store fee %s coins: %w", coins.Sort().String(), err)
155155
}
156156
if err != nil {
157157
return "", err

golang/cosmos/x/vbank/vbank_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,32 @@ func Test_Receive_Give(t *testing.T) {
272272
}
273273
}
274274

275+
func Test_Receive_GiveToFeeCollector(t *testing.T) {
276+
bank := &mockBank{}
277+
keeper := makeTestKeeper(bank)
278+
ch := NewPortHandler(AppModule{}, keeper)
279+
sdkCtx := sdk.NewContext(nil, tmproto.Header{}, false, log.NewNopLogger())
280+
ctx := &vm.ControllerContext{Context: sdkCtx}
281+
282+
ret, err := ch.Receive(ctx, `{
283+
"type": "VBANK_GIVE_TO_FEE_COLLECTOR",
284+
"amount": "1000",
285+
"denom": "urun"
286+
}`)
287+
if err != nil {
288+
t.Fatalf("got error = %v", err)
289+
}
290+
if ret != `true` {
291+
t.Errorf("got %v, want \"true\"", ret)
292+
}
293+
wantCalls := []string{
294+
"MintCoins vbank 1000urun",
295+
}
296+
if !reflect.DeepEqual(bank.calls, wantCalls) {
297+
t.Errorf("got calls %v, want %v", bank.calls, wantCalls)
298+
}
299+
}
300+
275301
func Test_Receive_Grab(t *testing.T) {
276302
bank := &mockBank{balance: map[string]sdk.Coin{
277303
addr1: sdk.NewInt64Coin("ubld", 1000),

0 commit comments

Comments
 (0)