Skip to content

Commit

Permalink
fix: make certain fields optional
Browse files Browse the repository at this point in the history
Signed-off-by: Elias Van Ootegem <[email protected]>
  • Loading branch information
EVODelavega committed Jun 17, 2024
1 parent 8e9554e commit eff3eb2
Show file tree
Hide file tree
Showing 6 changed files with 1,116 additions and 1,088 deletions.
49 changes: 35 additions & 14 deletions datanode/api/trading_data_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5572,24 +5572,39 @@ func (t *TradingDataServiceV2) EstimateAMMBounds(ctx context.Context, req *v2.Es
return nil, formatE(ErrInvalidBasePrice)
}

upperPrice, overflow := num.UintFromString(req.UpperPrice, 10)
if overflow || upperPrice.IsNegative() {
return nil, formatE(ErrInvalidUpperPrice)
upperPrice := num.UintZero()
if req.UpperPrice != nil {
upperP, overflow := num.UintFromString(*req.UpperPrice, 10)
if overflow || upperPrice.IsNegative() || upperPrice.LTE(basePrice) {
return nil, formatE(ErrInvalidUpperPrice)
}
upperPrice = upperP
}

lowerPrice, overflow := num.UintFromString(req.LowerPrice, 10)
if overflow || lowerPrice.IsNegative() {
return nil, formatE(ErrInvalidLowerPrice)
lowerPrice := num.UintZero()
if req.LowerPrice != nil {
lowerP, overflow := num.UintFromString(*req.LowerPrice, 10)
if overflow || lowerPrice.IsNegative() || lowerPrice.GTE(basePrice) {
return nil, formatE(ErrInvalidLowerPrice)
}
lowerPrice = lowerP
}

leverageLowerPrice, err := num.DecimalFromString(req.LeverageAtLowerPrice)
if err != nil || leverageLowerPrice.IsNegative() {
return nil, formatE(ErrInvalidLeverageAtLowerPrice, err)
var leverageLowerPrice, leverageUpperPrice *num.Decimal
if req.LeverageAtLowerPrice != nil {
llPrice, err := num.DecimalFromString(*req.LeverageAtLowerPrice)
if err != nil || leverageLowerPrice.IsNegative() {
return nil, formatE(ErrInvalidLeverageAtLowerPrice, err)
}
leverageLowerPrice = &llPrice
}

leverageUpperPrice, err := num.DecimalFromString(req.LeverageAtUpperPrice)
if err != nil || leverageUpperPrice.IsNegative() {
return nil, formatE(ErrInvalidLeverageAtUpperPrice, err)
if req.LeverageAtUpperPrice != nil {
luPrice, err := num.DecimalFromString(*req.LeverageAtUpperPrice)
if err != nil || leverageUpperPrice.IsNegative() {
return nil, formatE(ErrInvalidLeverageAtUpperPrice, err)
}
leverageUpperPrice = &luPrice
}

commitmentAmount, overflow := num.UintFromString(req.CommitmentAmount, 10)
Expand Down Expand Up @@ -5619,6 +5634,12 @@ func (t *TradingDataServiceV2) EstimateAMMBounds(ctx context.Context, req *v2.Es
if err != nil {
return nil, formatE(ErrEstimateAMMBounds, err)
}
if leverageLowerPrice == nil {
leverageLowerPrice = &riskFactor.Short
}
if leverageUpperPrice == nil {
leverageUpperPrice = &riskFactor.Long
}

sqrt := amm.NewSqrter()

Expand All @@ -5627,8 +5648,8 @@ func (t *TradingDataServiceV2) EstimateAMMBounds(ctx context.Context, req *v2.Es
lowerPrice,
basePrice,
upperPrice,
leverageLowerPrice,
leverageUpperPrice,
*leverageLowerPrice,
*leverageUpperPrice,
commitmentAmount,
linearSlippageFactor,
initialMargin,
Expand Down
24 changes: 12 additions & 12 deletions datanode/gateway/graphql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion datanode/gateway/graphql/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ func (r *myDepositResolver) CreditedTimestamp(_ context.Context, obj *vegapb.Dep

type myQueryResolver VegaResolverRoot

func (r *myQueryResolver) EstimateAMMBounds(ctx context.Context, basePrice string, upperPrice string, lowerPrice string, leverageAtUpperPrice string, leverageAtLowerPrice string, commitmentAmount string, marketID string) (*v2.EstimateAMMBoundsResponse, error) {
func (r *myQueryResolver) EstimateAMMBounds(ctx context.Context, basePrice string, upperPrice, lowerPrice, leverageAtUpperPrice, leverageAtLowerPrice *string, commitmentAmount string, marketID string) (*v2.EstimateAMMBoundsResponse, error) {
res, err := r.tradingDataClientV2.EstimateAMMBounds(ctx, &v2.EstimateAMMBoundsRequest{
BasePrice: basePrice,
UpperPrice: upperPrice,
Expand Down
8 changes: 4 additions & 4 deletions datanode/gateway/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -783,16 +783,16 @@ type Query {
Upper price of the AMM pool, the price is an integer, for example `123456` is a correctly
formatted price of `1.23456` assuming market configured to 5 decimal places.
"""
upperPrice: String!
upperPrice: String
"""
Lower price of the AMM pool, the price is an integer, for example `123456` is a correctly
formatted price of `1.23456` assuming market configured to 5 decimal places.
"""
lowerPrice: String!
lowerPrice: String
"Leverage at the upper price of the AMM pool."
leverageAtUpperPrice: String!
leverageAtUpperPrice: String
"Leverage at the lower price of the AMM pool."
leverageAtLowerPrice: String!
leverageAtLowerPrice: String
"Amount of the asset that the party is willing to commit to the AMM pool."
commitmentAmount: String!
"Market ID to filter for."
Expand Down
Loading

0 comments on commit eff3eb2

Please sign in to comment.