Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API-224: GetLiquidationParameters #25

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading