Skip to content

Commit

Permalink
Merge branch 'develop' into 11457
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyletang authored Jul 15, 2024
2 parents e03e11e + 11fd3cd commit b8ccac8
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 225 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- [11400](https://github.com/vegaprotocol/vega/issues/11400) - Add support for long block auction.
- [11026](https://github.com/vegaprotocol/vega/issues/11026) - Add API flag to get paid liquidity fees for a `vAMM` using the parent key.
- [11027](https://github.com/vegaprotocol/vega/issues/11027) - Add API filters to get fees and rewards by market, across epochs.
- [10360](https://github.com/vegaprotocol/vega/issues/10360) - Scale funding payment by fraction of period spent outside of auction.

### 🐛 Fixes

Expand All @@ -57,6 +58,8 @@
- [11442](https://github.com/vegaprotocol/vega/issues/11442) - Add validation to `submitAMM` to ensure the curves can be successfully generated.
- [11448](https://github.com/vegaprotocol/vega/issues/11448) - Fix team game score query with epoch filter.
- [11457](https://github.com/vegaprotocol/vega/issues/11457) - Fix cursor column ordering for game scores.
- [11454](https://github.com/vegaprotocol/vega/issues/11454) - Ensure ended transfers proper handling.


## 0.76.1

Expand Down
8 changes: 8 additions & 0 deletions core/banking/recurring_transfers.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ func (e *Engine) distributeRecurringTransfers(ctx context.Context, newEpoch uint
continue
}

// if the transfer should have been ended and has not, end it now.
if v.EndEpoch != nil && *v.EndEpoch < e.currentEpoch {
v.Status = types.TransferStatusDone
transfersDone = append(transfersDone, events.NewRecurringTransferFundsEvent(ctx, v, e.getGameID(v)))
doneIDs = append(doneIDs, v.ID)
continue
}

if v.DispatchStrategy != nil && v.DispatchStrategy.TransferInterval != nil &&
((newEpoch-v.StartEpoch+1) < uint64(*v.DispatchStrategy.TransferInterval) ||
(newEpoch-v.StartEpoch+1)%uint64(*v.DispatchStrategy.TransferInterval) != 0) {
Expand Down
56 changes: 56 additions & 0 deletions core/banking/recurring_transfers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,62 @@ func TestRecurringTransfers(t *testing.T) {
t.Run("invalid recurring transfers, in the past", testInvalidRecurringTransfersInThePast)
}

func TestExpireOldTransfers(t *testing.T) {
e := getTestEngine(t)

ctx := context.Background()

e.OnMinTransferQuantumMultiple(context.Background(), num.DecimalFromFloat(1))
e.assets.EXPECT().Get(gomock.Any()).AnyTimes().Return(assets.NewAsset(&mockAsset{name: assetNameETH, quantum: num.DecimalFromFloat(10)}), nil)
e.broker.EXPECT().Send(gomock.Any()).AnyTimes()
fromAcc := types.Account{
Balance: num.NewUint(100000), // enough for the all
}
e.col.EXPECT().GetPartyGeneralAccount(gomock.Any(), gomock.Any()).AnyTimes().Return(&fromAcc, nil)

endEpoch := uint64(12)
transfers := []*types.TransferFunds{}
for i := 0; i < 10; i++ {
transfers = append(transfers, &types.TransferFunds{
Kind: types.TransferCommandKindRecurring,
Recurring: &types.RecurringTransfer{
TransferBase: &types.TransferBase{
ID: fmt.Sprintf("TRANSFERID-%d", i),
From: "03ae90688632c649c4beab6040ff5bd04dbde8efbf737d8673bbda792a110301",
FromAccountType: types.AccountTypeGeneral,
To: crypto.RandomHash(),
ToAccountType: types.AccountTypeGeneral,
Asset: assetNameETH,
Amount: num.NewUint(10),
Reference: "someref",
},
StartEpoch: 10,
EndEpoch: &endEpoch,
Factor: num.MustDecimalFromString("1"),
},
})
require.NoError(t, e.TransferFunds(ctx, transfers[i]))
}
e.col.EXPECT().TransferFunds(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes()

seenEvts := []events.Event{}
e.broker.EXPECT().SendBatch(gomock.Any()).DoAndReturn(func(evts []events.Event) {
seenEvts = append(seenEvts, evts...)
}).AnyTimes()

e.OnEpoch(context.Background(), types.Epoch{Seq: 15, Action: vega.EpochAction_EPOCH_ACTION_START})
e.OnEpoch(context.Background(), types.Epoch{Seq: 15, Action: vega.EpochAction_EPOCH_ACTION_END})

require.Equal(t, 10, len(seenEvts))
stoppedIDs := map[string]struct{}{}
for _, e2 := range seenEvts {
if e2.StreamMessage().GetTransfer().Status == types.TransferStatusDone {
stoppedIDs[e2.StreamMessage().GetTransfer().Id] = struct{}{}
}
}
require.Equal(t, 10, len(stoppedIDs))
}

func TestMaturation(t *testing.T) {
e := getTestEngine(t)

Expand Down
76 changes: 54 additions & 22 deletions core/integration/features/settlement/0019-MCAL_018.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: check when settlement data precision is different/equal to the settleme

Background:

And the following assets are registered:
Given the following assets are registered:
| id | decimal places |
| USD | 2 |

Expand All @@ -26,15 +26,15 @@ Feature: check when settlement data precision is different/equal to the settleme

@Perpetual
Scenario: 001 oracle data decimal > asset decimal 0070-MKTD-018, 0019-MCAL-091
# start at this timestamp
Given time is updated to "2021-02-11T16:35:21Z"
And the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | position decimal places | market type | sla params |
| ETH/DEC19 | ETH | USD | default-simple-risk-model-3 | default-margin-calculator | 1 | default-none | default-none | perp-oracle-1 | 0.25 | 0 | -1 | perp | default-futures |
And the following network parameters are set:
| name | value |
| market.auction.minimumDuration | 1 |
| limits.markets.maxPeggedOrders | 2 |
Given the following network parameters are set:
| name | value |
| market.auction.minimumDuration | 1 |
| limits.markets.maxPeggedOrders | 2 |
| network.markPriceUpdateMaximumFrequency | 5s |
And the parties deposit on asset's general account the following amount:
| party | asset | amount |
Expand Down Expand Up @@ -62,11 +62,13 @@ Feature: check when settlement data precision is different/equal to the settleme
| aux2 | ETH/DEC19 | buy | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| aux | ETH/DEC19 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |

Then the opening auction period ends for market "ETH/DEC19"
# Time moves forwards 2s
Then the network moves ahead "2" blocks
And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"

# Another +1s making it 2021-02-11T16:35:24
When the network moves ahead "1" blocks
When the parties place the following orders:
And the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| party1 | ETH/DEC19 | sell | 1 | 1000 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | ETH/DEC19 | buy | 1 | 1000 | 1 | TYPE_LIMIT | TIF_GTC |
Expand All @@ -88,9 +90,18 @@ Feature: check when settlement data precision is different/equal to the settleme
| party3 | USD | ETH/DEC19 | 132000 | 99866000 |
| lp1 | USD | ETH/DEC19 | 6600000 | 492200000 |

When the oracles broadcast data with block time signed with "0xCAFECAFE1":

And the oracles broadcast data with block time signed with "0xCAFECAFE1":
| name | value | time offset |
| perp.funding.cue | 1613061324 | 0s |
# 4320h is 6 * 30 * 24 (180days, or 6 months) with a block duration of 10 days (so 18 ticks)
# making it 2021-08-10T16:35:24
Then the network moves ahead "4320h" with block duration of "240h"
# now move ahead the remaining time to get to 2021-08-11T11:04:07
# We're moving by 66,583s (18 * 3600 + 29 * 60 + 43), divisible by 11 (6053)
# So set block duration to 6053 for 11 ticks
And the network moves ahead "18h29m43s" with block duration of "6053s"
#When time is updated to "2021-08-12T11:04:07Z"

When the network moves ahead "5" blocks
When the oracles broadcast data with block time signed with "0xCAFECAFE1":
Expand All @@ -109,6 +120,7 @@ Feature: check when settlement data precision is different/equal to the settleme

@Perpetual
Scenario: 002 oracle data decimal < asset decimal 0070-MKTD-019
Given time is updated to "2021-02-11T16:35:21Z"
And the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | position decimal places | decimal places | market type | sla params |
| ETH/DEC19 | ETH | USD | default-simple-risk-model-3 | default-margin-calculator | 1 | default-none | default-none | perp-oracle-3 | 0.25 | 0 | 1 | 2 | perp | default-futures |
Expand Down Expand Up @@ -145,11 +157,12 @@ Feature: check when settlement data precision is different/equal to the settleme
| aux2 | ETH/DEC19 | buy | 100 | 100000 | 0 | TYPE_LIMIT | TIF_GTC |
| aux | ETH/DEC19 | sell | 100 | 100000 | 0 | TYPE_LIMIT | TIF_GTC |

Then the opening auction period ends for market "ETH/DEC19"
Then the network moves ahead "2" blocks
And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"

# Time at start of the scenario is now +3s
When the network moves ahead "1" blocks
When the parties place the following orders:
And the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif |
| party1 | ETH/DEC19 | sell | 100 | 100000 | 0 | TYPE_LIMIT | TIF_GTC |
| party2 | ETH/DEC19 | buy | 100 | 100000 | 1 | TYPE_LIMIT | TIF_GTC |
Expand All @@ -171,17 +184,29 @@ Feature: check when settlement data precision is different/equal to the settleme
| party3 | USD | ETH/DEC19 | 132000 | 99866000 |
| lp1 | USD | ETH/DEC19 | 6600000 | 492200000 |


When the oracles broadcast data with block time signed with "0xCAFECAFE3":
| name | value | time offset |
| perp.funding.cue | 1613061324 | 0s |

When the network moves ahead "5" blocks
When the oracles broadcast data with block time signed with "0xCAFECAFE3":
# 4320h is 6 * 30 * 24 (180days, or 6 months) with a block duration of 10 days (so 18 ticks)
# making it 2021-08-10T16:35:24
Then the network moves ahead "4320h" with block duration of "240h"
# now move ahead the remaining time to get to 2021-08-11T11:04:07
# We're moving by 66,583s (18 * 3600 + 29 * 60 + 43), divisible by 11 (6053)
# So set block duration to 6053 for 11 ticks
And the network moves ahead "18h29m43s" with block duration of "6053s"

# When time is updated to "2021-08-12T11:04:07Z"

And the network moves ahead "5" blocks
Then the oracles broadcast data with block time signed with "0xCAFECAFE3":
| name | value | time offset |
| perp.ETH.value | 30000 | 0s |
| perp.funding.cue | 1628766252 | 0s |
#1628766252 is half year after the first oracel time

#Then debug funding period events
And the following transfers should happen:
| from | to | from account | to account | market id | amount | asset |
| aux2 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 74700 | USD |
Expand All @@ -190,15 +215,17 @@ Feature: check when settlement data precision is different/equal to the settleme
| market | aux | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 74700 | USD |
| market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 149400 | USD |

@PBlock
Scenario: 003 oracle data decimal = asset decimal, while market decimal is 1, 0070-MKTD-020
Given time is updated to "2021-02-11T16:35:21Z"
And the markets:
| id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | decimal places | position decimal places | market type | sla params |
| ETH/DEC19 | ETH | USD | default-simple-risk-model-3 | default-margin-calculator | 1 | default-none | default-none | perp-oracle-2 | 0.25 | 0 | 1 | -1 | perp | default-futures |
And the following network parameters are set:
| name | value |
| market.auction.minimumDuration | 1 |
| limits.markets.maxPeggedOrders | 2 |
Given the following network parameters are set:
And the following network parameters are set:
| name | value |
| network.markPriceUpdateMaximumFrequency | 5s |
And the parties deposit on asset's general account the following amount:
Expand Down Expand Up @@ -227,7 +254,7 @@ Feature: check when settlement data precision is different/equal to the settleme
| aux2 | ETH/DEC19 | buy | 1 | 10000 | 0 | TYPE_LIMIT | TIF_GTC |
| aux | ETH/DEC19 | sell | 1 | 10000 | 0 | TYPE_LIMIT | TIF_GTC |

Then the opening auction period ends for market "ETH/DEC19"
Then the network moves ahead "2" blocks
And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"

When the network moves ahead "1" blocks
Expand All @@ -253,25 +280,30 @@ Feature: check when settlement data precision is different/equal to the settleme
| party3 | USD | ETH/DEC19 | 132000 | 99866000 |
| lp1 | USD | ETH/DEC19 | 6600000 | 492200000 |


When the oracles broadcast data with block time signed with "0xCAFECAFE2":
| name | value | time offset |
| perp.funding.cue | 1613061324 | 0s |

When the network moves ahead "5" blocks
When the oracles broadcast data with block time signed with "0xCAFECAFE2":

# 4320h is 6 * 30 * 24 (180days, or 6 months) with a block duration of 10 days (so 18 ticks)
# making it 2021-08-10T16:35:24
Then the network moves ahead "4320h" with block duration of "240h"
# now move ahead the remaining time to get to 2021-08-11T11:04:07
# We're moving by 66,583s (18 * 3600 + 29 * 60 + 43), divisible by 11 (6053)
# So set block duration to 6053 for 11 ticks
And the network moves ahead "18h29m43s" with block duration of "6053s"

And the network moves ahead "5" blocks
And the oracles broadcast data with block time signed with "0xCAFECAFE2":
| name | value | time offset |
| perp.ETH.value | 300000 | 0s |
| perp.funding.cue | 1628766252 | 0s |
#1628766252 is half year after the first oracel time

And the following transfers should happen:
Then the following transfers should happen:
| from | to | from account | to account | market id | amount | asset |
| aux2 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 74700 | USD |
| party2 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 74700 | USD |
| party3 | market | ACCOUNT_TYPE_MARGIN | ACCOUNT_TYPE_SETTLEMENT | ETH/DEC19 | 74700 | USD |
| market | aux | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 74700 | USD |
| market | party1 | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN | ETH/DEC19 | 149400 | USD |




Loading

0 comments on commit b8ccac8

Please sign in to comment.