Skip to content

merge main into release branch #326

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

Merged
merged 2 commits into from
May 27, 2025
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
77 changes: 0 additions & 77 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,6 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/address/screening": {
"get": {
"description": "Checks address risk",
"produces": [
"application/json"
],
"tags": [
"v2"
],
"summary": "Checks address risk",
"parameters": [
{
"type": "string",
"description": "BTC address to check",
"name": "btc_address",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "Risk of provided address",
"schema": {
"$ref": "#/definitions/handler.PublicResponse-v2handlers_AddressScreeningResponse"
}
},
"400": {
"description": "Error: Bad Request",
"schema": {
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_shared_types.Error"
}
},
"404": {
"description": "Error: Not Found",
"schema": {
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_shared_types.Error"
}
},
"500": {
"description": "Error: Internal Server Error",
"schema": {
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_shared_types.Error"
}
}
}
}
},
"/healthcheck": {
"get": {
"description": "Health check the service, including ping database connection",
Expand Down Expand Up @@ -566,12 +519,6 @@ const docTemplate = `{
"$ref": "#/definitions/handler.PublicResponse-array_v2service_FinalityProviderStatsPublic"
}
},
"400": {
"description": "Invalid parameters or malformed request",
"schema": {
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_shared_types.Error"
}
},
"404": {
"description": "No finality providers found",
"schema": {
Expand Down Expand Up @@ -854,17 +801,6 @@ const docTemplate = `{
}
}
},
"handler.PublicResponse-v2handlers_AddressScreeningResponse": {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/v2handlers.AddressScreeningResponse"
},
"pagination": {
"$ref": "#/definitions/handler.paginationResponse"
}
}
},
"handler.PublicResponse-v2service_DelegationPublic": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1280,19 +1216,6 @@ const docTemplate = `{
}
}
},
"v2handlers.AddressScreeningResponse": {
"type": "object",
"properties": {
"btc_address": {
"type": "object",
"properties": {
"risk": {
"type": "string"
}
}
}
}
},
"v2service.CovenantSignature": {
"type": "object",
"properties": {
Expand Down
77 changes: 0 additions & 77 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,6 @@
"version": "2.0"
},
"paths": {
"/address/screening": {
"get": {
"description": "Checks address risk",
"produces": [
"application/json"
],
"tags": [
"v2"
],
"summary": "Checks address risk",
"parameters": [
{
"type": "string",
"description": "BTC address to check",
"name": "btc_address",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "Risk of provided address",
"schema": {
"$ref": "#/definitions/handler.PublicResponse-v2handlers_AddressScreeningResponse"
}
},
"400": {
"description": "Error: Bad Request",
"schema": {
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_shared_types.Error"
}
},
"404": {
"description": "Error: Not Found",
"schema": {
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_shared_types.Error"
}
},
"500": {
"description": "Error: Internal Server Error",
"schema": {
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_shared_types.Error"
}
}
}
}
},
"/healthcheck": {
"get": {
"description": "Health check the service, including ping database connection",
Expand Down Expand Up @@ -558,12 +511,6 @@
"$ref": "#/definitions/handler.PublicResponse-array_v2service_FinalityProviderStatsPublic"
}
},
"400": {
"description": "Invalid parameters or malformed request",
"schema": {
"$ref": "#/definitions/github_com_babylonlabs-io_staking-api-service_internal_shared_types.Error"
}
},
"404": {
"description": "No finality providers found",
"schema": {
Expand Down Expand Up @@ -846,17 +793,6 @@
}
}
},
"handler.PublicResponse-v2handlers_AddressScreeningResponse": {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/v2handlers.AddressScreeningResponse"
},
"pagination": {
"$ref": "#/definitions/handler.paginationResponse"
}
}
},
"handler.PublicResponse-v2service_DelegationPublic": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1272,19 +1208,6 @@
}
}
},
"v2handlers.AddressScreeningResponse": {
"type": "object",
"properties": {
"btc_address": {
"type": "object",
"properties": {
"risk": {
"type": "string"
}
}
}
}
},
"v2service.CovenantSignature": {
"type": "object",
"properties": {
Expand Down
50 changes: 0 additions & 50 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ definitions:
pagination:
$ref: '#/definitions/handler.paginationResponse'
type: object
handler.PublicResponse-v2handlers_AddressScreeningResponse:
properties:
data:
$ref: '#/definitions/v2handlers.AddressScreeningResponse'
pagination:
$ref: '#/definitions/handler.paginationResponse'
type: object
handler.PublicResponse-v2service_DelegationPublic:
properties:
data:
Expand Down Expand Up @@ -370,14 +363,6 @@ definitions:
version:
type: integer
type: object
v2handlers.AddressScreeningResponse:
properties:
btc_address:
properties:
risk:
type: string
type: object
type: object
v2service.CovenantSignature:
properties:
covenant_btc_pk_hex:
Expand Down Expand Up @@ -576,37 +561,6 @@ info:
title: Babylon Staking API
version: "2.0"
paths:
/address/screening:
get:
description: Checks address risk
parameters:
- description: BTC address to check
in: query
name: btc_address
required: true
type: string
produces:
- application/json
responses:
"200":
description: Risk of provided address
schema:
$ref: '#/definitions/handler.PublicResponse-v2handlers_AddressScreeningResponse'
"400":
description: 'Error: Bad Request'
schema:
$ref: '#/definitions/github_com_babylonlabs-io_staking-api-service_internal_shared_types.Error'
"404":
description: 'Error: Not Found'
schema:
$ref: '#/definitions/github_com_babylonlabs-io_staking-api-service_internal_shared_types.Error'
"500":
description: 'Error: Internal Server Error'
schema:
$ref: '#/definitions/github_com_babylonlabs-io_staking-api-service_internal_shared_types.Error'
summary: Checks address risk
tags:
- v2
/healthcheck:
get:
description: Health check the service, including ping database connection
Expand Down Expand Up @@ -961,10 +915,6 @@ paths:
description: List of finality providers with its stats
schema:
$ref: '#/definitions/handler.PublicResponse-array_v2service_FinalityProviderStatsPublic'
"400":
description: Invalid parameters or malformed request
schema:
$ref: '#/definitions/github_com_babylonlabs-io_staking-api-service_internal_shared_types.Error'
"404":
description: No finality providers found
schema:
Expand Down
10 changes: 0 additions & 10 deletions internal/v2/api/handlers/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ type AddressScreeningResponse struct {
} `json:"btc_address"`
}

// AddressScreening checks address risk against address screening providers
// @Summary Checks address risk
// @Description Checks address risk
// @Produce json
// @Tags v2
// @Param btc_address query string true "BTC address to check"
// @Success 200 {object} handler.PublicResponse[AddressScreeningResponse] "Risk of provided address"
// @Failure 400 {object} types.Error "Error: Bad Request"
// @Failure 500 {object} types.Error "Error: Internal Server Error"
// @Router /address/screening [get]
func (h *V2Handler) AddressScreening(request *http.Request) (*handler.Result, *types.Error) {
btcAddress := request.URL.Query().Get("btc_address")
if btcAddress == "" {
Expand Down
12 changes: 6 additions & 6 deletions internal/v2/service/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func (s *V2Service) GetOverallStats(

// Calculate the APR for BTC staking on Babylon Genesis
// The APR is calculated based on the activeTvl of the overall stats
btcStakingAPR, errAprCalculation := s.GetBTCStakingAPR(
btcStakingAPR, errAprCalculation := s.getBTCStakingAPR(
ctx, overallStats.ActiveTvl,
)
if errAprCalculation != nil {
log.Ctx(ctx).Error().Err(errAprCalculation).
Msg("error while calculating BTC staking APR")
return nil, types.NewInternalServiceError(errAprCalculation)
// in case of error we use zero value in BTCStakingAPR
}

return &OverallStatsPublic{
Expand All @@ -107,9 +107,9 @@ func (s *V2Service) GetOverallStats(
}, nil
}

func (s *V2Service) GetBTCStakingAPR(
func (s *V2Service) getBTCStakingAPR(
ctx context.Context, activeTvl int64,
) (float64, *types.Error) {
) (float64, error) {
// Skip calculation if activeTvl is 0
if activeTvl <= 0 {
return 0, nil
Expand All @@ -128,12 +128,12 @@ func (s *V2Service) GetBTCStakingAPR(

btcPrice, err := s.sharedService.GetLatestBTCPrice(ctx)
if err != nil {
return 0, types.NewInternalServiceError(err)
return 0, err
}

babyPrice, err := s.sharedService.GetLatestBABYPrice(ctx)
if err != nil {
return 0, types.NewInternalServiceError(err)
return 0, err
}

// Calculate the APR of the BTC staking on Babylon Genesis
Expand Down
Loading
Loading