code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/the_liquidation_strategy.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 steps
    17  
    18  import (
    19  	"time"
    20  
    21  	"code.vegaprotocol.io/vega/core/integration/steps/market"
    22  	"code.vegaprotocol.io/vega/core/types"
    23  	"code.vegaprotocol.io/vega/libs/num"
    24  
    25  	"github.com/cucumber/godog"
    26  )
    27  
    28  func TheLiquidationStrategies(config *market.Config, table *godog.Table) error {
    29  	rows := parseLiquidationStrategyTable(table)
    30  	for _, row := range rows {
    31  		lsr := lsRow{
    32  			r: row,
    33  		}
    34  		config.LiquidationStrat.Add(lsr.name(), lsr.liquidationStrategy().IntoProto())
    35  	}
    36  	return nil
    37  }
    38  
    39  func parseLiquidationStrategyTable(table *godog.Table) []RowWrapper {
    40  	return StrictParseTable(table, []string{
    41  		"name",
    42  		"disposal step",
    43  		"disposal fraction",
    44  		"full disposal size",
    45  		"max fraction consumed",
    46  		"disposal slippage range",
    47  	}, nil)
    48  }
    49  
    50  type lsRow struct {
    51  	r RowWrapper
    52  }
    53  
    54  func (l lsRow) liquidationStrategy() *types.LiquidationStrategy {
    55  	return &types.LiquidationStrategy{
    56  		DisposalTimeStep:    l.disposalStep(),
    57  		DisposalFraction:    l.disposalFraction(),
    58  		FullDisposalSize:    l.fullDisposalSize(),
    59  		MaxFractionConsumed: l.maxFraction(),
    60  		DisposalSlippage:    l.disposalSlippage(),
    61  	}
    62  }
    63  
    64  func (l lsRow) name() string {
    65  	return l.r.MustStr("name")
    66  }
    67  
    68  func (l lsRow) disposalStep() time.Duration {
    69  	i := l.r.MustI64("disposal step")
    70  	return time.Duration(i) * time.Second
    71  }
    72  
    73  func (l lsRow) disposalFraction() num.Decimal {
    74  	return l.r.MustDecimal("disposal fraction")
    75  }
    76  
    77  func (l lsRow) fullDisposalSize() uint64 {
    78  	return l.r.MustU64("full disposal size")
    79  }
    80  
    81  func (l lsRow) maxFraction() num.Decimal {
    82  	return l.r.MustDecimal("max fraction consumed")
    83  }
    84  
    85  func (l lsRow) disposalSlippage() num.Decimal {
    86  	return l.r.MustDecimal("disposal slippage range")
    87  }