code.vegaprotocol.io/vega@v0.79.0/datanode/entities/liquidity_provider.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package entities
    17  
    18  import (
    19  	"encoding/json"
    20  	"fmt"
    21  
    22  	v2 "code.vegaprotocol.io/vega/protos/data-node/api/v2"
    23  	"code.vegaprotocol.io/vega/protos/vega"
    24  )
    25  
    26  type LiquidityProvider struct {
    27  	PartyID    PartyID
    28  	MarketID   MarketID
    29  	Ordinality int64
    30  	FeeShare   *vega.LiquidityProviderFeeShare
    31  	SLA        *vega.LiquidityProviderSLA
    32  }
    33  
    34  type LiquidityProviderCursor struct {
    35  	MarketID   MarketID `json:"marketId"`
    36  	PartyID    PartyID  `json:"partyId"`
    37  	Ordinality int64    `json:"ordinality"`
    38  }
    39  
    40  func (c LiquidityProviderCursor) String() string {
    41  	bs, err := json.Marshal(c)
    42  	if err != nil {
    43  		panic(fmt.Errorf("could not marshal liquidity provision cursor: %w", err))
    44  	}
    45  	return string(bs)
    46  }
    47  
    48  func (c *LiquidityProviderCursor) Parse(cursorString string) error {
    49  	if cursorString == "" {
    50  		return nil
    51  	}
    52  
    53  	return json.Unmarshal([]byte(cursorString), c)
    54  }
    55  
    56  func (lp LiquidityProvider) ToProto() *v2.LiquidityProvider {
    57  	return &v2.LiquidityProvider{
    58  		PartyId:  lp.PartyID.String(),
    59  		MarketId: lp.MarketID.String(),
    60  		FeeShare: lp.FeeShare,
    61  		Sla:      lp.SLA,
    62  	}
    63  }
    64  
    65  func (lp LiquidityProvider) Cursor() *Cursor {
    66  	c := LiquidityProviderCursor{
    67  		PartyID: lp.PartyID,
    68  	}
    69  
    70  	return NewCursor(c.String())
    71  }
    72  
    73  func (lp LiquidityProvider) ToProtoEdge(...any) (*v2.LiquidityProviderEdge, error) {
    74  	return &v2.LiquidityProviderEdge{
    75  		Node:   lp.ToProto(),
    76  		Cursor: lp.Cursor().Encode(),
    77  	}, nil
    78  }