From 29c87b7aabd4848969a063137413c51e3a654e52 Mon Sep 17 00:00:00 2001 From: ze97286 Date: Fri, 3 Nov 2023 12:47:59 +0000 Subject: [PATCH] feat: transfer infra fees directly to general account without going through vesting --- CHANGELOG.md | 1 + core/collateral/engine.go | 20 +++++++++++++++----- core/collateral/engine_test.go | 6 +++--- core/rewards/engine.go | 4 ++-- core/rewards/engine_test.go | 13 ++++++------- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9303f0953e..530bc5e7405 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - [9940](https://github.com/vegaprotocol/vega/issues/9940) - Truncate fee stats in quantum down to the 6 decimal. - [9956](https://github.com/vegaprotocol/vega/issues/9956) - Prevent validator node from starting if they do not have a Ethereum `RPCAddress` set. - [9952](https://github.com/vegaprotocol/vega/issues/9952) - `PnL` flickering fix. +- [9977](https://github.com/vegaprotocol/vega/issues/9977) - Transfer infra fees directly to general account without going through vesting. ## 0.73.0 diff --git a/core/collateral/engine.go b/core/collateral/engine.go index ce104418772..c32ec36b73c 100644 --- a/core/collateral/engine.go +++ b/core/collateral/engine.go @@ -804,7 +804,7 @@ func (e *Engine) TransferFees(ctx context.Context, marketID string, assetID stri // returns the corresponding transfer request for the slice of transfers // if the reward accound doesn't exist return error // if the party account doesn't exist log the error and continue. -func (e *Engine) getRewardTransferRequests(ctx context.Context, rewardAccountID string, transfers []*types.Transfer) ([]*types.TransferRequest, error) { +func (e *Engine) getRewardTransferRequests(ctx context.Context, rewardAccountID string, transfers []*types.Transfer, rewardType types.AccountType) ([]*types.TransferRequest, error) { rewardAccount, err := e.GetAccountByID(rewardAccountID) if err != nil { return nil, err @@ -812,27 +812,37 @@ func (e *Engine) getRewardTransferRequests(ctx context.Context, rewardAccountID rewardTRs := make([]*types.TransferRequest, 0, len(transfers)) for _, t := range transfers { - vesting := e.GetOrCreatePartyVestingRewardAccount(ctx, t.Owner, t.Amount.Asset) + var destination *types.Account + if rewardType == types.AccountTypeFeesInfrastructure { + destination, err = e.GetPartyGeneralAccount(t.Owner, t.Amount.Asset) + if err != nil { + e.CreatePartyGeneralAccount(ctx, t.Owner, t.Amount.Asset) + destination, _ = e.GetPartyGeneralAccount(t.Owner, t.Amount.Asset) + } + } else { + destination = e.GetOrCreatePartyVestingRewardAccount(ctx, t.Owner, t.Amount.Asset) + } + rewardTRs = append(rewardTRs, &types.TransferRequest{ Amount: t.Amount.Amount.Clone(), MinAmount: t.Amount.Amount.Clone(), Asset: t.Amount.Asset, Type: types.TransferTypeRewardPayout, FromAccount: []*types.Account{rewardAccount}, - ToAccount: []*types.Account{vesting}, + ToAccount: []*types.Account{destination}, }) } return rewardTRs, nil } // TransferRewards takes a slice of transfers and serves them to transfer rewards from the reward account to parties general account. -func (e *Engine) TransferRewards(ctx context.Context, rewardAccountID string, transfers []*types.Transfer) ([]*types.LedgerMovement, error) { +func (e *Engine) TransferRewards(ctx context.Context, rewardAccountID string, transfers []*types.Transfer, rewardType types.AccountType) ([]*types.LedgerMovement, error) { responses := make([]*types.LedgerMovement, 0, len(transfers)) if len(transfers) == 0 { return responses, nil } - transferReqs, err := e.getRewardTransferRequests(ctx, rewardAccountID, transfers) + transferReqs, err := e.getRewardTransferRequests(ctx, rewardAccountID, transfers, rewardType) if err != nil { return nil, err } diff --git a/core/collateral/engine_test.go b/core/collateral/engine_test.go index 3ace5dd0e80..1e16893ce8e 100644 --- a/core/collateral/engine_test.go +++ b/core/collateral/engine_test.go @@ -250,7 +250,7 @@ func testTransferRewardsEmptySlice(t *testing.T) { eng := getTestEngine(t) defer eng.Finish() eng.broker.EXPECT().Send(gomock.Any()).AnyTimes() - res, err := eng.TransferRewards(context.Background(), "reward", []*types.Transfer{}) + res, err := eng.TransferRewards(context.Background(), "reward", []*types.Transfer{}, types.AccountTypeGlobalReward) assert.Nil(t, err) assert.Equal(t, 0, len(res)) } @@ -272,7 +272,7 @@ func testTransferRewardsNoRewardsAccount(t *testing.T) { }, } - res, err := eng.TransferRewards(context.Background(), "rewardAccID", transfers) + res, err := eng.TransferRewards(context.Background(), "rewardAccID", transfers, types.AccountTypeGlobalReward) require.Error(t, errors.New("account does not exists"), err) require.Nil(t, res) } @@ -300,7 +300,7 @@ func testTransferRewardsSuccess(t *testing.T) { }, } - lm, err := eng.TransferRewards(context.Background(), rewardAcc.ID, transfers) + lm, err := eng.TransferRewards(context.Background(), rewardAcc.ID, transfers, types.AccountTypeGlobalReward) require.Nil(t, err) partyAccount, _ := eng.GetAccountByID(partyAccountID) require.Equal(t, num.NewUint(1000), partyAccount.Balance) diff --git a/core/rewards/engine.go b/core/rewards/engine.go index a6cb0e876b4..c1a11dd5bb1 100644 --- a/core/rewards/engine.go +++ b/core/rewards/engine.go @@ -64,7 +64,7 @@ type Delegation interface { // Collateral engine provides access to account data and transferring rewards. type Collateral interface { GetAccountByID(id string) (*types.Account, error) - TransferRewards(ctx context.Context, rewardAccountID string, transfers []*types.Transfer) ([]*types.LedgerMovement, error) + TransferRewards(ctx context.Context, rewardAccountID string, transfers []*types.Transfer, rewardType types.AccountType) ([]*types.LedgerMovement, error) GetRewardAccountsByType(rewardAcccountType types.AccountType) []*types.Account } @@ -441,7 +441,7 @@ func (e *Engine) distributePayout(ctx context.Context, po *payout) { }) } - responses, err := e.collateral.TransferRewards(ctx, po.fromAccount, transfers) + responses, err := e.collateral.TransferRewards(ctx, po.fromAccount, transfers, po.rewardType) if err != nil { e.log.Error("error in transfer rewards", logging.Error(err)) return diff --git a/core/rewards/engine_test.go b/core/rewards/engine_test.go index acf1a1b61e8..decbd18dfd3 100644 --- a/core/rewards/engine_test.go +++ b/core/rewards/engine_test.go @@ -396,13 +396,12 @@ func TestErsatzTendermintRewardSplit(t *testing.T) { // node 4 gets 25000 // get party account balances - ctx := context.Background() - party1Acc := testEngine.collateral.GetOrCreatePartyVestingRewardAccount(ctx, "party1", "VEGA") - party2Acc := testEngine.collateral.GetOrCreatePartyVestingRewardAccount(ctx, "party2", "VEGA") - node1Acc := testEngine.collateral.GetOrCreatePartyVestingRewardAccount(ctx, "node1", "VEGA") - node2Acc := testEngine.collateral.GetOrCreatePartyVestingRewardAccount(ctx, "node2", "VEGA") - node3Acc := testEngine.collateral.GetOrCreatePartyVestingRewardAccount(ctx, "node3", "VEGA") - node4Acc := testEngine.collateral.GetOrCreatePartyVestingRewardAccount(ctx, "node4", "VEGA") + party1Acc, _ := testEngine.collateral.GetPartyGeneralAccount("party1", "VEGA") + party2Acc, _ := testEngine.collateral.GetPartyGeneralAccount("party2", "VEGA") + node1Acc, _ := testEngine.collateral.GetPartyGeneralAccount("node1", "VEGA") + node2Acc, _ := testEngine.collateral.GetPartyGeneralAccount("node2", "VEGA") + node3Acc, _ := testEngine.collateral.GetPartyGeneralAccount("node3", "VEGA") + node4Acc, _ := testEngine.collateral.GetPartyGeneralAccount("node4", "VEGA") require.Equal(t, num.NewUint(172500), party1Acc.Balance) require.Equal(t, num.NewUint(15000), party2Acc.Balance)