Skip to content

Commit c3e608d

Browse files
authored
Merge branch 'develop' into cometv1
2 parents 5e65924 + 1d5ba45 commit c3e608d

14 files changed

Lines changed: 158 additions & 61 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
- [11209](https://github.com/vegaprotocol/vega/issues/11209) - Publish ongoing games data.
1616
- [11242](https://github.com/vegaprotocol/vega/issues/11242) - Add configuration to visor to help control binary retries a bit better.
17+
- [11408](https://github.com/vegaprotocol/vega/issues/11408) - Relax finality check to allow instant deposits over the `Arbitrum` bridge.
1718
- [11196](https://github.com/vegaprotocol/vega/issues/11196) - Add an active field in the price monitoring bounds payload.
1819
- [11211](https://github.com/vegaprotocol/vega/issues/11211) - Liquidation engine includes `vAMM` shapes as available volume.
1920
- [11217](https://github.com/vegaprotocol/vega/issues/11217) - Allow market proposals to override risk factors.
@@ -47,6 +48,7 @@
4748
- [11368](https://github.com/vegaprotocol/vega/issues/11368) - Add support for update vesting stats in REST API and fix summing the quantum balance for vesting stats.
4849
- [11380](https://github.com/vegaprotocol/vega/issues/11380) - Handle broken stop orders in prepare proposal.
4950
- [11136](https://github.com/vegaprotocol/vega/issues/11136) - Fix premature invocation of post commit hooks in case of fee stats event.
51+
- [11409](https://github.com/vegaprotocol/vega/issues/11409) - When updating a capped market - copy the cap from the existing market definition.
5052

5153
## 0.76.1
5254

cmd/vega/commands/node/node.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,11 @@ func (n *Command) startBlockchainClients() error {
478478

479479
n.primaryEthConfirmations = ethclient.NewEthereumConfirmations(n.conf.Ethereum, n.primaryEthClient, nil, ethclient.FinalityStateFinalized)
480480

481-
// for arbitrum we can use the weaker check for finality and only require that the block is marked as "safe".
482-
// This is because "safe" means that the batch has been send to L1 Ethereum and from then on its "final" on
483-
// Arbitrum. If the batched-transaction is part of a re-org on Ethereum, it doesn't matter to Vega because core
484-
// is only looking at the Arbitrum blocks we don't track the batch, so we don't need to wait for full finality.
485-
n.secondaryEthConfirmations = ethclient.NewEthereumConfirmations(n.conf.Ethereum, n.secondaryEthClient, nil, ethclient.FinalityStateSafe)
481+
// for arbitrum the finality state of a block is in now way connected to the Arbitrum network reaching consensus so Vega gains nothing
482+
// from waiting for safe/finalized. Instead we just wait for the event to be seen in the latest block and rely on the consensus check
483+
// Vega performs itself with node-votes. If each validator is running their own Arbitrum node, or is using a node that they need trustworthy
484+
// then this is sufficient. A far as is know, block reorgs do not happen on Arbitrum.
485+
n.secondaryEthConfirmations = ethclient.NewEthereumConfirmations(n.conf.Ethereum, n.secondaryEthClient, nil, ethclient.FinalityStateLatest)
486486

487487
return nil
488488
}

core/client/eth/ethereum_confirmations.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ func (e *EthereumConfirmations) Check(block uint64) error {
109109
return err
110110
}
111111

112+
// if finality state is "latest" we do not need to check as this will already be done by the confirmations count
113+
if e.finState == nil {
114+
return nil
115+
}
116+
112117
finalized, err := e.finalizedHeight(context.Background())
113118
if err != nil {
114119
return err

core/execution/amm/pool.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,25 @@ func (c *curve) volumeBetweenPrices(sqrt sqrtFn, st, nd *num.Uint) uint64 {
5454
return 0
5555
}
5656

57+
stP := impliedPosition(sqrt(st), sqrt(c.high), c.l)
58+
ndP := impliedPosition(sqrt(nd), sqrt(c.high), c.l)
59+
5760
// abs(P(st) - P(nd))
58-
volume, _ := num.UintZero().Delta(
59-
impliedPosition(sqrt(st), sqrt(c.high), c.l),
60-
impliedPosition(sqrt(nd), sqrt(c.high), c.l),
61-
)
62-
return volume.Uint64()
61+
volume := stP.Sub(ndP).Abs()
62+
return uint64(volume.IntPart())
6363
}
6464

6565
// positionAtPrice returns the position of the AMM if its fair-price were the given price. This
6666
// will be signed for long/short as usual.
6767
func (c *curve) positionAtPrice(sqrt sqrtFn, price *num.Uint) int64 {
6868
pos := impliedPosition(sqrt(price), sqrt(c.high), c.l)
6969
if c.isLower {
70-
return int64(pos.Uint64())
70+
return pos.IntPart()
7171
}
7272

7373
// if we are in the upper curve the position of 0 in "curve-space" is -cu.pv in Vega position
7474
// so we need to flip the interval
75-
return -c.pv.Sub(pos.ToDecimal()).IntPart()
75+
return -c.pv.Sub(pos).IntPart()
7676
}
7777

7878
type Pool struct {
@@ -494,16 +494,15 @@ func (p *Pool) setCurves(
494494
// impliedPosition returns the position of the pool if its fair-price were the given price. `l` is
495495
// the virtual liquidity of the pool, and `sqrtPrice` and `sqrtHigh` are, the square-roots of the
496496
// price to calculate the position for, and higher boundary of the curve.
497-
func impliedPosition(sqrtPrice, sqrtHigh num.Decimal, l num.Decimal) *num.Uint {
497+
func impliedPosition(sqrtPrice, sqrtHigh num.Decimal, l num.Decimal) num.Decimal {
498498
// L * (sqrt(high) - sqrt(price))
499499
numer := sqrtHigh.Sub(sqrtPrice).Mul(l)
500500

501501
// sqrt(high) * sqrt(price)
502502
denom := sqrtHigh.Mul(sqrtPrice)
503503

504504
// L * (sqrt(high) - sqrt(price)) / sqrt(high) * sqrt(price)
505-
res, _ := num.UintFromDecimal(numer.Div(denom))
506-
return res
505+
return numer.Div(denom)
507506
}
508507

509508
// OrderbookShape returns slices of virtual buy and sell orders that the AMM has over a given range

core/execution/amm/pool_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,52 @@ func testTradeableVolumeInRange(t *testing.T) {
133133
}
134134
}
135135

136+
func TestTradeableVolumeWhenAtBoundary(t *testing.T) {
137+
// from ticket 11389 this replicates a scenario found during fuzz testing
138+
submit := &types.SubmitAMM{
139+
AMMBaseCommand: types.AMMBaseCommand{
140+
Party: vgcrypto.RandomHash(),
141+
MarketID: vgcrypto.RandomHash(),
142+
SlippageTolerance: num.DecimalFromFloat(0.1),
143+
},
144+
CommitmentAmount: num.MustUintFromString("2478383748073213000000", 10),
145+
Parameters: &types.ConcentratedLiquidityParameters{
146+
Base: num.NewUint(676540),
147+
LowerBound: num.NewUint(671272),
148+
UpperBound: nil,
149+
LeverageAtLowerBound: ptr.From(num.DecimalFromFloat(39.1988064541227)),
150+
LeverageAtUpperBound: nil,
151+
},
152+
}
153+
154+
p := newTestPoolWithSubmission(t,
155+
num.DecimalFromInt64(1000),
156+
submit,
157+
)
158+
defer p.ctrl.Finish()
159+
160+
// when position is zero fair-price should be the base
161+
ensurePositionN(t, p.pos, 0, num.UintZero(), 3)
162+
fp := p.pool.BestPrice(nil)
163+
assert.Equal(t, "6765400000000000000000", fp.String())
164+
165+
fullLong := 12546
166+
167+
// volume from base -> low is 12546, but in reality it is 12546.4537027400278, but we can only trade int volume.
168+
volume := p.pool.TradableVolumeInRange(types.SideSell, num.MustUintFromString("6712720000000000000000", 10), num.MustUintFromString("6765400000000000000000", 10))
169+
assert.Equal(t, fullLong, int(volume))
170+
171+
// now lets pretend the AMM has fully traded out in that direction, best price will be near but not quite the lower bound
172+
ensurePositionN(t, p.pos, int64(fullLong), num.UintZero(), 3)
173+
fp = p.pool.BestPrice(nil)
174+
assert.Equal(t, "6712721893865935337785", fp.String())
175+
assert.True(t, fp.GTE(num.MustUintFromString("6712720000000000000000", 10)))
176+
177+
// now the fair-price is not *quite* on the lower boundary but the volume between it at the lower bound should be 0.
178+
volume = p.pool.TradableVolumeInRange(types.SideSell, num.MustUintFromString("6712720000000000000000", 10), fp)
179+
assert.Equal(t, 0, int(volume))
180+
}
181+
136182
func testPoolPositionFactor(t *testing.T) {
137183
p := newTestPoolWithPositionFactor(t, num.DecimalFromInt64(1000))
138184
defer p.ctrl.Finish()
@@ -806,6 +852,45 @@ func newTestPoolWithOpts(t *testing.T, positionFactor num.Decimal, low, base, hi
806852
}
807853
}
808854

855+
func newTestPoolWithSubmission(t *testing.T, positionFactor num.Decimal, submit *types.SubmitAMM) *tstPool {
856+
t.Helper()
857+
ctrl := gomock.NewController(t)
858+
col := mocks.NewMockCollateral(ctrl)
859+
pos := mocks.NewMockPosition(ctrl)
860+
861+
sqrter := &Sqrter{cache: map[string]num.Decimal{}}
862+
863+
pool, err := NewPool(
864+
vgcrypto.RandomHash(),
865+
vgcrypto.RandomHash(),
866+
vgcrypto.RandomHash(),
867+
submit,
868+
sqrter.sqrt,
869+
col,
870+
pos,
871+
&types.RiskFactor{
872+
Short: num.DecimalFromFloat(0.009937604878885509),
873+
Long: num.DecimalFromFloat(0.00984363574304481),
874+
},
875+
&types.ScalingFactors{
876+
InitialMargin: num.DecimalFromFloat(1.5), // this is 1/0.8 which is margin_usage_at_bound_above in the note-book
877+
},
878+
num.DecimalFromFloat(0.001),
879+
num.DecimalFromFloat(10000000000000000),
880+
positionFactor,
881+
num.NewUint(1000),
882+
)
883+
assert.NoError(t, err)
884+
885+
return &tstPool{
886+
submission: submit,
887+
pool: pool,
888+
col: col,
889+
pos: pos,
890+
ctrl: ctrl,
891+
}
892+
}
893+
809894
type marketPosition struct {
810895
size int64
811896
averageEntry *num.Uint

core/governance/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,7 @@ func (e *Engine) updatedMarketFromProposal(p *proposal) (*types.Market, types.Pr
13491349
DataSourceSpecForSettlementData: product.Future.DataSourceSpecForSettlementData,
13501350
DataSourceSpecForTradingTermination: product.Future.DataSourceSpecForTradingTermination,
13511351
DataSourceSpecBinding: product.Future.DataSourceSpecBinding,
1352+
Cap: existingMarket.GetFuture().Cap(),
13521353
},
13531354
}
13541355
case *types.UpdateInstrumentConfigurationPerps:
@@ -1377,7 +1378,6 @@ func (e *Engine) updatedMarketFromProposal(p *proposal) (*types.Market, types.Pr
13771378
if newMarket.Changes.LiquidationStrategy == nil {
13781379
newMarket.Changes.LiquidationStrategy = existingMarket.LiquidationStrategy
13791380
}
1380-
13811381
if perr, err := validateUpdateMarketChange(terms, existingMarket, &enactmentTime{current: p.Terms.EnactmentTimestamp, shouldNotVerify: true}, e.timeService.GetTimeNow(), e.netp); err != nil {
13821382
return nil, perr, err
13831383
}

core/integration/features/amm/0042-LIQF-109.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,6 @@ Feature: Test vAMM implied commitment is working as expected
206206
#virtual stake is 75% * 4669 = 3501
207207
And the liquidity provider fee shares for the market "ETH/MAR22" should be:
208208
| party | equity like share | virtual stake | average entry valuation |
209-
| 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 3501.0000000000000000 | 23501 |
209+
| 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0 | 3502.0000000000000000 | 23502 |
210210

211211

core/integration/features/amm/0090-VAMM-005.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ Feature: Test vAMM submission works as expected (invalid submission)
119119

120120
When the parties submit the following AMM:
121121
| party | market id | amount | slippage | base | lower bound | lower leverage | proposed fee |
122-
| vamm4 | ETH/MAR22 | 100000 | 0.1 | 105 | 99 | 0.1 | 0.01 |
122+
| vamm4 | ETH/MAR22 | 100000 | 0.1 | 100 | 99 | 0.1 | 0.01 |
123123
Then the AMM pool status should be:
124124
| party | market id | amount | status | base | lower bound | lower leverage |
125-
| vamm4 | ETH/MAR22 | 100000 | STATUS_ACTIVE | 105 | 99 | 0.1 |
125+
| vamm4 | ETH/MAR22 | 100000 | STATUS_ACTIVE | 100 | 99 | 0.1 |
126126

127127
When the parties submit the following AMM:
128128
| party | market id | amount | slippage | base | upper bound | upper leverage | proposed fee |

core/integration/features/amm/0090-VAMM-016.feature

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Feature: vAMM has the same ELS as liquidity provision with the same commitment a
9090
When the parties submit the following liquidity provision:
9191
# Using 9788 instead of exactly 10,000 makes things easier because getting exactly 10,000 from an AMM pool as virtual stake can be tricky due to complex math.
9292
| id | party | market id | commitment amount | fee | lp type |
93-
| lp_2 | lp2 | ETH/MAR22 | 9884 | 0.03 | submission |
93+
| lp_2 | lp2 | ETH/MAR22 | 9887 | 0.03 | submission |
9494

9595
When the parties submit the following AMM:
9696
| party | market id | amount | slippage | base | lower bound | upper bound | lower leverage | upper leverage | proposed fee |
@@ -110,8 +110,8 @@ Feature: vAMM has the same ELS as liquidity provision with the same commitment a
110110
And the current epoch is "2"
111111
And the liquidity provider fee shares for the market "ETH/MAR22" should be:
112112
| party | equity like share | virtual stake | average entry valuation |
113-
| lp2 | 0.3320343993550121 | 9884.0000000000000000 | 29768 |
114-
| 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0.3320343993550121 | 9884.0000000000000000 | 19884 |
113+
| lp2 | 0.3320682474642305 | 9887.0000000000000000 | 29774 |
114+
| 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0.3320682474642305 | 9887.0000000000000000 | 19887 |
115115

116116
@VAMM
117117
Scenario: 0090-VAMM-017: A vAMM's virtual ELS should be equal to the ELS of a regular LP with the same committed volume on the book (i.e. if a vAMM has an average volume on each side of the book across the epoch of 10k USDT, their ELS should be equal to that of a regular LP who has a commitment which requires supplying 10k USDT who joined at the same time as them).
@@ -123,7 +123,7 @@ Feature: vAMM has the same ELS as liquidity provision with the same commitment a
123123
When the parties submit the following liquidity provision:
124124
# Using 10,093 instead of exactly 10,000 makes things easier because getting exactly 10,000 from an AMM pool as virtual stake can be tricky due to complex math.
125125
| id | party | market id | commitment amount | fee | lp type |
126-
| lp_2 | lp2 | ETH/MAR22 | 9884 | 0.03 | submission |
126+
| lp_2 | lp2 | ETH/MAR22 | 9887 | 0.03 | submission |
127127

128128
And the parties place the following orders:
129129
| party | market id | side | volume | price | resulting trades | type | tif |
@@ -148,13 +148,13 @@ Feature: vAMM has the same ELS as liquidity provision with the same commitment a
148148
And the current epoch is "2"
149149
And the liquidity provider fee shares for the market "ETH/MAR22" should be:
150150
| party | equity like share | virtual stake | average entry valuation |
151-
| lp2 | 0.3320343993550121 | 9884.0000000000000000 | 29768 |
152-
| 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0.3320343993550121 | 9884.0000000000000000 | 19884 |
151+
| lp2 | 0.3320682474642305 | 9887.0000000000000000 | 29774 |
152+
| 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0.3320682474642305 | 9887.0000000000000000 | 19887 |
153153

154154
Then the network moves ahead "2" epochs
155155
And the current epoch is "4"
156156

157157
And the liquidity provider fee shares for the market "ETH/MAR22" should be:
158158
| party | equity like share | virtual stake | average entry valuation |
159-
| lp2 | 0.3320343993550121 | 9884.0000000000000000 | 29768 |
160-
| 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0.3320343993550121 | 9884.0000000000000000 | 19884 |
159+
| lp2 | 0.3320682474642305 | 9887.0000000000000000 | 29774 |
160+
| 137112507e25d3845a56c47db15d8ced0f28daa8498a0fd52648969c4b296aba | 0.3320682474642305 | 9887.0000000000000000 | 19887 |

0 commit comments

Comments
 (0)