Skip to content

Commit

Permalink
Merge pull request #41 from gateway-fm/feat/collateral-amount
Browse files Browse the repository at this point in the history
feat: add get collateral amount method
  • Loading branch information
asolovov authored Dec 15, 2023
2 parents c35ace2 + 186862d commit 0724373
Show file tree
Hide file tree
Showing 4 changed files with 35 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.

7 changes: 7 additions & 0 deletions perpsv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ type IPerpsv3 interface {
// GetAccountOwner is used to get accounts owner address for given account ID
GetAccountOwner(accountId *big.Int) (string, error)

// GetCollateralAmount is used to get accounts collateral amount for given market ID
GetCollateralAmount(accountId *big.Int, marketId *big.Int) (*big.Int, error)

// GetRequiredMaintenanceMargin is used to get required maintenance margin for given account ID
GetRequiredMaintenanceMargin(accountId *big.Int) (*big.Int, error)

Expand Down Expand Up @@ -313,6 +316,10 @@ func (p *Perpsv3) GetAccountOwner(accountId *big.Int) (string, error) {
return p.service.GetAccountOwner(accountId)
}

func (p *Perpsv3) GetCollateralAmount(accountId *big.Int, marketId *big.Int) (*big.Int, error) {
return p.service.GetCollateralAmount(accountId, marketId)
}

func (p *Perpsv3) GetRequiredMaintenanceMargin(accountId *big.Int) (*big.Int, error) {
return p.service.GetRequiredMaintenanceMargin(accountId)
}
Expand Down
10 changes: 10 additions & 0 deletions services/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ func (s *Service) GetAccountOwner(accountId *big.Int) (string, error) {
return owner.Hex(), nil
}

func (s *Service) GetCollateralAmount(accountId *big.Int, marketId *big.Int) (*big.Int, error) {
amount, err := s.perpsMarket.GetCollateralAmount(nil, accountId, marketId)
if err != nil {
logger.Log().WithField("layer", "Service-GetCollateralAmount").Errorf("get colleteral amount error: %v", err.Error())
return nil, errors.GetReadContractErr(err, "perps market", "GetCollateralAmount")
}

return amount, nil
}

// formatAccounts is used to get accounts from the contract using event filter function for 'AccountCreated' event
// and given filter options
func (s *Service) formatAccounts(opts *bind.FilterOpts) ([]*models.Account, error) {
Expand Down
3 changes: 3 additions & 0 deletions services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ type IService interface {
// GetAccountOwner is used to get accounts owner address for given account ID
GetAccountOwner(accountId *big.Int) (string, error)

// GetCollateralAmount is used to get accounts collateral amount for given market ID
GetCollateralAmount(accountId *big.Int, marketId *big.Int) (*big.Int, error)

// GetRequiredMaintenanceMargin is used to get required maintenance margin for given account ID
GetRequiredMaintenanceMargin(accountId *big.Int) (*big.Int, error)

Expand Down

0 comments on commit 0724373

Please sign in to comment.