Skip to content

Commit

Permalink
API-224: GetLiquidationParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
asolovov committed Sep 27, 2023
1 parent c1fcc01 commit 42bb3a5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mocks/service/mockService.go

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

24 changes: 24 additions & 0 deletions models/marketData.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,30 @@ type MarketSummary struct {
IndexPrice *big.Int
}

type LiquidationParameters struct {
InitialMarginRatio *big.Int
MinimumInitialMarginRatio *big.Int
MaintenanceMarginScalar *big.Int
LiquidationRewardRatio *big.Int
MinimumPositionMargin *big.Int
}

func GetLiquidationParameters(resp struct {
InitialMarginRatioD18 *big.Int
MinimumInitialMarginRatioD18 *big.Int
MaintenanceMarginScalarD18 *big.Int
LiquidationRewardRatioD18 *big.Int
MinimumPositionMargin *big.Int
}) *LiquidationParameters {
return &LiquidationParameters{
LiquidationRewardRatio: resp.LiquidationRewardRatioD18,
MinimumInitialMarginRatio: resp.MinimumInitialMarginRatioD18,
MaintenanceMarginScalar: resp.MaintenanceMarginScalarD18,
InitialMarginRatio: resp.InitialMarginRatioD18,
MinimumPositionMargin: resp.MinimumPositionMargin,
}
}

// GetMarketUpdateFromEvent is used to get MarketUpdate struct from given event and block timestamp
func GetMarketUpdateFromEvent(event *perpsMarketGoerli.PerpsMarketGoerliMarketUpdated, time uint64) *MarketUpdate {
if event == nil {
Expand Down
7 changes: 7 additions & 0 deletions perpsv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ type IPerpsv3 interface {
// GetAvailableMargin is used to get available margin for given account ID
GetAvailableMargin(accountId *big.Int) (*big.Int, error)

// GetLiquidationParameters is used to get liquidation params for given market ID
GetLiquidationParameters(marketId *big.Int) (*models.LiquidationParameters, error)

// FormatAccount is used to get account, and it's additional data from the contract by given account id
FormatAccount(id *big.Int) (*models.Account, error)

Expand Down Expand Up @@ -236,6 +239,10 @@ func (p *Perpsv3) GetAvailableMargin(accountId *big.Int) (*big.Int, error) {
return p.service.GetAvailableMargin(accountId)
}

func (p *Perpsv3) GetLiquidationParameters(marketId *big.Int) (*models.LiquidationParameters, error) {
return p.service.GetLiquidationParameters(marketId)
}

func (p *Perpsv3) FormatAccounts() ([]*models.Account, error) {
return p.service.FormatAccounts()
}
Expand Down
10 changes: 10 additions & 0 deletions services/marketData.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ func (s *Service) GetMarketIDs() ([]*big.Int, error) {
return res, nil
}

func (s *Service) GetLiquidationParameters(marketId *big.Int) (*models.LiquidationParameters, error) {
resp, err := s.perpsMarket.GetLiquidationParameters(nil, marketId)
if err != nil {
logger.Log().WithField("layer", "").Errorf("")
return nil, errors.GetReadContractErr(err, "", "")
}

return models.GetLiquidationParameters(resp), nil
}

func (s *Service) GetFoundingRate(marketId *big.Int) (*big.Int, error) {
rate, err := s.perpsMarket.CurrentFundingRate(nil, marketId)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ type IService interface {
// GetAvailableMargin is used to get available margin for given account ID
GetAvailableMargin(accountId *big.Int) (*big.Int, error)

// GetLiquidationParameters is used to get liquidation params for given market ID
GetLiquidationParameters(marketId *big.Int) (*models.LiquidationParameters, error)

// FormatAccount is used to get account, and it's additional data from the contract by given account id
FormatAccount(id *big.Int) (*models.Account, error)

Expand Down

0 comments on commit 42bb3a5

Please sign in to comment.