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

update: add accounts public methods #30

Merged
merged 1 commit into from
Oct 29, 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
30 changes: 30 additions & 0 deletions mocks/service/mockService.go

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

14 changes: 14 additions & 0 deletions perpsv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ type IPerpsv3 interface {
// GetFundingParameters is used to get funding params for given market ID
GetFundingParameters(marketId *big.Int) (*models.FundingParameters, error)

// GetAccountLastInteraction is used to get accounts last interaction for given account ID
GetAccountLastInteraction(accountId *big.Int) (*big.Int, error)

// GetAccountOwner is used to get accounts owner address for given account ID
GetAccountOwner(accountId *big.Int) (string, 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 @@ -290,6 +296,14 @@ func (p *Perpsv3) GetFundingParameters(marketId *big.Int) (*models.FundingParame
return p.service.GetFundingParameters(marketId)
}

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

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

func (p *Perpsv3) FormatAccounts() ([]*models.Account, error) {
return p.service.FormatAccounts()
}
Expand Down
20 changes: 20 additions & 0 deletions services/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ func (s *Service) GetAvailableMargin(accountId *big.Int) (*big.Int, error) {
return margin, nil
}

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

return time, nil
}

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

return owner.Hex(), 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
6 changes: 6 additions & 0 deletions services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ type IService interface {
// GetFundingParameters is used to get funding params for given market ID
GetFundingParameters(marketId *big.Int) (*models.FundingParameters, error)

// GetAccountLastInteraction is used to get accounts last interaction for given account ID
GetAccountLastInteraction(accountId *big.Int) (*big.Int, error)

// GetAccountOwner is used to get accounts owner address for given account ID
GetAccountOwner(accountId *big.Int) (string, 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