Skip to content

Commit

Permalink
Merge pull request #11210 from vegaprotocol/feature/amm-base-branch
Browse files Browse the repository at this point in the history
Feature/amm base branch
  • Loading branch information
jeremyletang authored May 15, 2024
2 parents 1aa1963 + 0b95242 commit 1262a7b
Show file tree
Hide file tree
Showing 166 changed files with 30,043 additions and 10,992 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
- [11143](https://github.com/vegaprotocol/vega/issues/11143) - Add support for new asset proposal in batch governance proposal
- [11182](https://github.com/vegaprotocol/vega/issues/11182) - Remove reduce only restriction on spot markets stop orders.
- [11153](https://github.com/vegaprotocol/vega/issues/11153) - Add check on start-up that bridge `RPC-endpoints` are functional.
- [11211](https://github.com/vegaprotocol/vega/issues/11211) - Liquidation engine includes `vAMM` shapes as available volume.

### 🐛 Fixes

Expand Down Expand Up @@ -197,6 +198,7 @@

- [10702](https://github.com/vegaprotocol/vega/pull/10700) - Use second precision in `GetMarginIncrease()` so that perpetual product uses second precision everywhere.
- [10698](https://github.com/vegaprotocol/vega/issues/10698) - Prevent `L2` from making too many `RPC` calls.
- [971](https://github.com/vegaprotocol/core-test-coverage/issues/971) - Add `AMM` support to the integration test framework.

## 0.74.2

Expand Down Expand Up @@ -231,6 +233,9 @@
- [10611](https://github.com/vegaprotocol/vega/issues/10611) - Added internal config price to update `perps`.
- [10615](https://github.com/vegaprotocol/vega/issues/10615) - Fix oracle scaling function in internal composite price.
- [10621](https://github.com/vegaprotocol/vega/issues/10621) - Fix market activity tracker storing incorrect data for previous `epochMakerFeesPaid`.
- [10643](https://github.com/vegaprotocol/vega/issues/10643) - Games `API` not showing quantum values and added filter for team and party.

## 0.74.0

### 🚨 Breaking changes

Expand Down
1 change: 1 addition & 0 deletions cmd/data-node/commands/start/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func (l *NodeCommand) createGRPCServer(config api.Config) *api.GRPCServer {
l.marginModesService,
l.timeWeightedNotionalPositionService,
l.gameScoreService,
l.ammPoolsService,
)
return grpcServer
}
8 changes: 8 additions & 0 deletions cmd/data-node/commands/start/sqlsubscribers.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type SQLSubscribers struct {
marginModesStore *sqlstore.MarginModes
timeWeightedNotionalPositionStore *sqlstore.TimeWeightedNotionalPosition
gameScoreStore *sqlstore.GameScores
ammPoolsStore *sqlstore.AMMPools

// Services
candleService *candlesv2.Svc
Expand Down Expand Up @@ -140,6 +141,7 @@ type SQLSubscribers struct {
marginModesService *service.MarginModes
timeWeightedNotionalPositionService *service.TimeWeightedNotionalPosition
gameScoreService *service.GameScore
ammPoolsService *service.AMMPools

// Subscribers
accountSub *sqlsubscribers.Account
Expand Down Expand Up @@ -193,6 +195,7 @@ type SQLSubscribers struct {
marginModesSub *sqlsubscribers.MarginModes
timeWeightedNotionalPositionSub *sqlsubscribers.TimeWeightedNotionalPosition
gameScoreSub *sqlsubscribers.GameScore
ammPoolsSub *sqlsubscribers.AMMPools
}

func (s *SQLSubscribers) GetSQLSubscribers() []broker.SQLBrokerSubscriber {
Expand Down Expand Up @@ -250,6 +253,7 @@ func (s *SQLSubscribers) GetSQLSubscribers() []broker.SQLBrokerSubscriber {
s.marginModesSub,
s.timeWeightedNotionalPositionSub,
s.gameScoreSub,
s.ammPoolsSub,
}
}

Expand Down Expand Up @@ -312,6 +316,7 @@ func (s *SQLSubscribers) CreateAllStores(ctx context.Context, Log *logging.Logge
s.marginModesStore = sqlstore.NewMarginModes(transactionalConnectionSource)
s.timeWeightedNotionalPositionStore = sqlstore.NewTimeWeightedNotionalPosition(transactionalConnectionSource)
s.gameScoreStore = sqlstore.NewGameScores(transactionalConnectionSource)
s.ammPoolsStore = sqlstore.NewAMMPools(transactionalConnectionSource)
}

func (s *SQLSubscribers) SetupServices(ctx context.Context, log *logging.Logger, candlesConfig candlesv2.Config) error {
Expand Down Expand Up @@ -369,6 +374,8 @@ func (s *SQLSubscribers) SetupServices(ctx context.Context, log *logging.Logger,
s.marginModesService = service.NewMarginModes(s.marginModesStore)
s.timeWeightedNotionalPositionService = service.NewTimeWeightedNotionalPosition(s.timeWeightedNotionalPositionStore)
s.gameScoreService = service.NewGameScore(s.gameScoreStore, log)
s.ammPoolsService = service.NewAMMPools(s.ammPoolsStore)

s.transactionResultsSub = sqlsubscribers.NewTransactionResults(log)
s.transactionResultsService = service.NewTransactionResults(s.transactionResultsSub)

Expand Down Expand Up @@ -438,4 +445,5 @@ func (s *SQLSubscribers) SetupSQLSubscribers() {
s.marginModesSub = sqlsubscribers.NewMarginModes(s.marginModesService)
s.timeWeightedNotionalPositionSub = sqlsubscribers.NewTimeWeightedNotionalPosition(s.timeWeightedNotionalPositionService)
s.gameScoreSub = sqlsubscribers.NewGameScore(s.gameScoreStore)
s.ammPoolsSub = sqlsubscribers.NewAMMPools(s.ammPoolsService)
}
128 changes: 128 additions & 0 deletions commands/amend_amm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// Copyright (C) 2023 Gobalsky Labs Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package commands

import (
"math/big"

"code.vegaprotocol.io/vega/libs/num"
commandspb "code.vegaprotocol.io/vega/protos/vega/commands/v1"
)

func CheckAmendAMM(cmd *commandspb.AmendAMM) error {
return checkAmendAMM(cmd).ErrorOrNil()
}

func checkAmendAMM(cmd *commandspb.AmendAMM) Errors {
errs := NewErrors()

if cmd == nil {
return errs.FinalAddForProperty("amend_amm", ErrIsRequired)
}

if len(cmd.MarketId) <= 0 {
errs.AddForProperty("amend_amm.market_id", ErrIsRequired)
} else if !IsVegaID(cmd.MarketId) {
errs.AddForProperty("amend_amm.market_id", ErrShouldBeAValidVegaID)
}

if len(cmd.SlippageTolerance) <= 0 {
errs.AddForProperty("amend_amm.slippage_tolerance", ErrIsRequired)
} else if slippageTolerance, err := num.DecimalFromString(cmd.SlippageTolerance); err != nil {
errs.AddForProperty("amend_amm.slippage_tolerance", ErrIsNotValidNumber)
} else if slippageTolerance.LessThanOrEqual(num.DecimalZero()) || slippageTolerance.GreaterThan(num.DecimalOne()) {
errs.AddForProperty("amend_amm.slippage_tolerance", ErrMustBeBetween01)
}

var hasUpdate bool

if cmd.CommitmentAmount != nil {
hasUpdate = true
if amount, _ := big.NewInt(0).SetString(*cmd.CommitmentAmount, 10); amount == nil {
errs.FinalAddForProperty("amend_amm.commitment_amount", ErrIsNotValidNumber)
} else if amount.Cmp(big.NewInt(0)) <= 0 {
errs.AddForProperty("amend_amm.commitment_amount", ErrMustBePositive)
}
}

if cmd.ProposedFee != nil {
hasUpdate = true
if proposedFee, err := num.DecimalFromString(*cmd.ProposedFee); err != nil {
errs.AddForProperty("amend_amm.proposed_fee", ErrIsNotValid)
} else if proposedFee.LessThanOrEqual(num.DecimalZero()) {
errs.AddForProperty("amend_amm.proposed_fee", ErrMustBePositive)
}
}

if cmd.ConcentratedLiquidityParameters != nil {
hasUpdate = true
if amount, _ := big.NewInt(0).SetString(cmd.ConcentratedLiquidityParameters.Base, 10); amount == nil {
errs.FinalAddForProperty("amend_amm.concentrated_liquidity_parameters.base", ErrIsNotValidNumber)
} else if amount.Cmp(big.NewInt(0)) <= 0 {
errs.AddForProperty("amend_amm.concentrated_liquidity_parameters.base", ErrMustBePositive)
}

if cmd.ConcentratedLiquidityParameters.LowerBound != nil {
hasUpdate = true
if amount, _ := big.NewInt(0).SetString(*cmd.ConcentratedLiquidityParameters.LowerBound, 10); amount == nil {
errs.FinalAddForProperty("amend_amm.concentrated_liquidity_parameters.lower_bound", ErrIsNotValidNumber)
} else if amount.Cmp(big.NewInt(0)) <= 0 {
errs.AddForProperty("amend_amm.concentrated_liquidity_parameters.lower_bound", ErrMustBePositive)
}
}
if cmd.ConcentratedLiquidityParameters.UpperBound != nil {
hasUpdate = true
if amount, _ := big.NewInt(0).SetString(*cmd.ConcentratedLiquidityParameters.UpperBound, 10); amount == nil {
errs.FinalAddForProperty("amend_amm.concentrated_liquidity_parameters.upper_bound", ErrIsNotValidNumber)
} else if amount.Cmp(big.NewInt(0)) <= 0 {
errs.AddForProperty("amend_amm.concentrated_liquidity_parameters.upper_bound", ErrMustBePositive)
}
}

if cmd.ConcentratedLiquidityParameters.LeverageAtUpperBound != nil {
hasUpdate = true
if leverage, err := num.DecimalFromString(*cmd.ConcentratedLiquidityParameters.LeverageAtUpperBound); err != nil {
errs.AddForProperty("amend_amm.concentrated_liquidity_parameters.leverage_at_upper_bound", ErrIsNotValidNumber)
} else if leverage.LessThan(num.DecimalZero()) {
errs.AddForProperty("amend_amm.concentrated_liquidity_parameters.leverage_at_upper_bound", ErrMustBePositive)
}
}

if cmd.ConcentratedLiquidityParameters.LeverageAtLowerBound != nil {
hasUpdate = true
if leverage, err := num.DecimalFromString(*cmd.ConcentratedLiquidityParameters.LeverageAtLowerBound); err != nil {
errs.AddForProperty("amend_amm.concentrated_liquidity_parameters.leverage_at_lower_bound", ErrIsNotValidNumber)
} else if leverage.LessThan(num.DecimalZero()) {
errs.AddForProperty("amend_amm.concentrated_liquidity_parameters.leverage_at_lower_bound", ErrMustBePositive)
}
}

if len(cmd.SlippageTolerance) <= 0 {
errs.AddForProperty("submit_amm.slippage_tolerance", ErrIsRequired)
} else if slippageTolerance, err := num.DecimalFromString(cmd.SlippageTolerance); err != nil {
errs.AddForProperty("submit_amm.slippage_tolerance", ErrIsNotValidNumber)
} else if slippageTolerance.LessThan(num.DecimalZero()) {
errs.AddForProperty("submit_amm.slippage_tolerance", ErrMustBePositive)
}
}

// no update, but also no error, invalid
if !hasUpdate && errs.Empty() {
errs.FinalAdd(ErrNoUpdatesProvided)
}

return errs
}
Loading

0 comments on commit 1262a7b

Please sign in to comment.