Skip to content

Commit

Permalink
Refactoring: remove TVL
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Feb 1, 2025
1 parent 07f966a commit cdf842c
Show file tree
Hide file tree
Showing 44 changed files with 12 additions and 1,891 deletions.
21 changes: 1 addition & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,6 @@ jobs:
cache-to: type=gha,mode=max
tags: ${{ steps.meta-quotes.outputs.tags }}
labels: ${{ steps.meta-quotes.outputs.labels }}

# Tvl

- name: Tvl image tags & labels
id: meta-tvl
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_BASE }}-tvl

- name: Tvl image build & push
uses: docker/build-push-action@v5
with:
context: .
file: build/tvl/Dockerfile
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta-tvl.outputs.tags }}
labels: ${{ steps.meta-tvl.outputs.labels }}

# Celestials

Expand All @@ -124,4 +105,4 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta-celestials.outputs.tags }}
labels: ${{ steps.meta-celestials.outputs.labels }}
labels: ${{ steps.meta-celestials.outputs.labels }}
11 changes: 0 additions & 11 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@
"../../configs/dipdup.yml",
],
"envFile": "${workspaceFolder}/.env"
}, {
"name": "Launch TVL",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/tvl",
"args": [
"-c",
"../../configs/dipdup.yml",
],
"envFile": "${workspaceFolder}/.env"
}, {
"name": "Launch Celestials",
"type": "go",
Expand Down
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ api:
quotes:
cd cmd/quotes && go run . -c ../../configs/dipdup.yml

tvl:
cd cmd/tvl && go run . -c ../../configs/dipdup.yml

celestials:
cd cmd/celestials && go run . -c ../../configs/dipdup.yml

Expand Down Expand Up @@ -46,7 +43,7 @@ adr:
@cp adr/adr-template.md adr/adr-$(NUM)-$(TITLE).md

generate:
go generate -v ./internal/blob ./internal/storage ./internal/storage/types ./pkg/node ./internal/binance ./internal/celestials ./internal/tvl/l2beat ./internal/tvl/lama
go generate -v ./internal/blob ./internal/storage ./internal/storage/types ./pkg/node ./internal/binance ./internal/celestials

api-docs:
cd cmd/api && swag init --md markdown -parseDependency --parseInternal --parseDepth 1 --outputTypes json
Expand Down Expand Up @@ -84,4 +81,4 @@ cover:
license-header:
update-license -path=./ -license=./HEADER

.PHONY: init indexer api celestials quotes build clean compose lint test adr mock api-docs check-licenses cover license-header tvl
.PHONY: init indexer api build clean compose lint test adr mock api-docs check-licenses cover license-header celestials
37 changes: 0 additions & 37 deletions build/tvl/Dockerfile

This file was deleted.

28 changes: 9 additions & 19 deletions cmd/api/handler/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (handler RollupHandler) GetBlobs(c echo.Context) error {
type rollupStatsRequest struct {
Id uint64 `example:"1" param:"id" swaggertype:"integer" validate:"required,min=1"`
Timeframe string `example:"hour" param:"timeframe" swaggertype:"string" validate:"required,oneof=hour day month"`
SeriesName string `example:"tps" param:"name" swaggertype:"string" validate:"required,oneof=blobs_count size size_per_blob fee tvl"`
SeriesName string `example:"tps" param:"name" swaggertype:"string" validate:"required,oneof=blobs_count size size_per_blob fee"`
From int64 `example:"1692892095" query:"from" swaggertype:"integer" validate:"omitempty,min=1"`
To int64 `example:"1692892095" query:"to" swaggertype:"integer" validate:"omitempty,min=1"`
}
Expand All @@ -347,7 +347,7 @@ type rollupStatsRequest struct {
// @Tags rollup
// @ID get-rollup-stats
// @Param id path integer true "Internal identity" mininum(1)
// @Param name path string true "Series name" Enums(blobs_count, size, size_per_blob, fee, tvl)
// @Param name path string true "Series name" Enums(blobs_count, size, size_per_blob, fee)
// @Param timeframe path string true "Timeframe" Enums(hour, day, month)
// @Param from query integer false "Time from in unix timestamp" mininum(1)
// @Param to query integer false "Time to in unix timestamp" mininum(1)
Expand All @@ -362,23 +362,13 @@ func (handler RollupHandler) Stats(c echo.Context) error {
return badRequestError(c, err)
}

var histogram []storage.HistogramItem
if req.SeriesName == "tvl" {
histogram, err = handler.rollups.Tvl(
c.Request().Context(),
req.Id,
storage.Timeframe(req.Timeframe),
storage.NewSeriesRequest(req.From, req.To),
)
} else {
histogram, err = handler.rollups.Series(
c.Request().Context(),
req.Id,
storage.Timeframe(req.Timeframe),
req.SeriesName,
storage.NewSeriesRequest(req.From, req.To),
)
}
histogram, err := handler.rollups.Series(
c.Request().Context(),
req.Id,
storage.Timeframe(req.Timeframe),
req.SeriesName,
storage.NewSeriesRequest(req.From, req.To),
)

if err != nil {
return handleError(c, err, handler.rollups)
Expand Down
31 changes: 0 additions & 31 deletions cmd/api/handler/rollup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,37 +319,6 @@ func (s *RollupTestSuite) TestGetBlobs() {
s.Require().Len(logs, 1)
}

func (s *RollupTestSuite) TestTvl() {
name := "tvl"
for _, tf := range []storage.Timeframe{storage.TimeframeDay, storage.TimeframeMonth} {
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
c := s.echo.NewContext(req, rec)
c.SetPath("/rollup/:id/stats/:name/:timeframe")
c.SetParamNames("id", "name", "timeframe")
c.SetParamValues("1", name, string(tf))

s.rollups.EXPECT().
Tvl(gomock.Any(), uint64(1), tf, storage.NewSeriesRequest(0, 0)).
Return([]storage.HistogramItem{
{
Value: "12345678",
Time: testTime,
},
}, nil)

s.Require().NoError(s.handler.Stats(c))
s.Require().Equal(http.StatusOK, rec.Code)

var histogram []responses.HistogramItem
err := json.NewDecoder(rec.Body).Decode(&histogram)
s.Require().NoError(err)
s.Require().Len(histogram, 1)
s.Require().EqualValues("12345678", histogram[0].Value)
s.Require().EqualValues(testTime, histogram[0].Time)
}
}

func (s *RollupTestSuite) TestStats() {
for _, name := range []string{"blobs_count", "size", "size_per_blob", "fee"} {
for _, tf := range []storage.Timeframe{storage.TimeframeHour, storage.TimeframeDay, storage.TimeframeMonth} {
Expand Down
63 changes: 0 additions & 63 deletions cmd/api/handler/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,66 +544,3 @@ func (sh StatsHandler) MessagesCount24h(c echo.Context) error {
}
return returnArray(c, response)
}

// Tvs godoc
//
// @Summary Get TVS of the network
// @Description Get TVS of the network
// @Tags stats
// @ID stats-tvs
// @Produce json
// @Success 200 {integer} float64
// @Failure 500 {object} Error
// @Router /stats/tvs [get]
func (sh StatsHandler) Tvs(c echo.Context) error {
tvs, err := sh.repo.Tvs(c.Request().Context())
if err != nil {
return handleError(c, err, sh.nsRepo)
}
return c.JSON(http.StatusOK, tvs)
}

// TvsSeries godoc
//
// @Summary Get histogram for network TVS
// @Description Get histogram for network TVS by timeframe
// @Tags stats
// @ID stats-tvs-series
// @Param timeframe path string true "Timeframe" Enums(day, month)
// @Param from query integer false "Time from in unix timestamp" mininum(1)
// @Param to query integer false "Time to in unix timestamp" mininum(1)
// @Produce json
// @Success 200 {array} responses.SeriesItem
// @Failure 400 {object} Error
// @Failure 500 {object} Error
// @Router /stats/tvs/{timeframe} [get]
func (sh StatsHandler) TvsSeries(c echo.Context) error {
req, err := bindAndValidate[tvsSeriesRequest](c)
if err != nil {
return badRequestError(c, err)
}

tvs, err := sh.repo.TvsSeries(
c.Request().Context(),
storage.Timeframe(req.Timeframe),
storage.NewSeriesRequest(req.From, req.To))

if err != nil {
return handleError(c, err, sh.nsRepo)
}
if len(tvs) == 0 {
return c.JSON(http.StatusOK, []any{})
}

response := make([]responses.SeriesItem, len(tvs))
for i := range tvs {
response[i] = responses.NewSeriesItem(tvs[i])
}
return returnArray(c, response)
}

type tvsSeriesRequest struct {
Timeframe string `example:"hour" param:"timeframe" swaggertype:"string" validate:"required,oneof=day month"`
From int64 `example:"1692892095" query:"from" swaggertype:"integer" validate:"omitempty,min=1"`
To int64 `example:"1692892095" query:"to" swaggertype:"integer" validate:"omitempty,min=1"`
}
62 changes: 0 additions & 62 deletions cmd/api/handler/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,65 +583,3 @@ func (s *StatsTestSuite) TestMessgaesCount24h() {
s.Require().EqualValues("test", response[0].Name)
s.Require().EqualValues(100, response[0].Value)
}

func (s *StatsTestSuite) TestTvs() {
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
c := s.echo.NewContext(req, rec)
c.SetPath("/v1/stats/tvs")

s.stats.EXPECT().
Tvs(gomock.Any()).
Return(decimal.NewFromFloat(12345678.90), nil)

s.Require().NoError(s.handler.Tvs(c))
s.Require().Equal(http.StatusOK, rec.Code)

var response decimal.Decimal
err := json.NewDecoder(rec.Body).Decode(&response)
s.Require().NoError(err)
s.Require().Equal(decimal.NewFromFloat(12345678.90), response)
}

func (s *StatsTestSuite) TestTvsSeries() {
for _, tf := range []storage.Timeframe{
storage.TimeframeDay,
storage.TimeframeMonth,
} {
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
c := s.echo.NewContext(req, rec)
c.SetPath("/v1/stats/tvs/:timeframe")
c.SetParamNames("timeframe")
c.SetParamValues(string(tf))

s.stats.EXPECT().
TvsSeries(gomock.Any(), tf, gomock.Any()).
Return([]storage.SeriesItem{
{
Time: testTime,
Value: "12345678",
},
{
Time: testTime,
Value: "87654321",
},
}, nil)

s.Require().NoError(s.handler.TvsSeries(c))
s.Require().Equal(http.StatusOK, rec.Code)

var response []responses.SeriesItem
err := json.NewDecoder(rec.Body).Decode(&response)
s.Require().NoError(err)
s.Require().Len(response, 2)

item1 := response[0]
s.Require().Equal("12345678", item1.Value)
s.Require().Equal(testTime, item1.Time)

item2 := response[1]
s.Require().Equal("87654321", item2.Value)
s.Require().Equal(testTime, item2.Time)
}
}
2 changes: 0 additions & 2 deletions cmd/api/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ func initHandlers(ctx context.Context, e *echo.Echo, cfg Config, db postgres.Sto
stats.GET("/rollup_stats_24h", statsHandler.RollupStats24h)
stats.GET("/square_size", statsHandler.SquareSize)
stats.GET("/messages_count_24h", statsHandler.MessagesCount24h)
stats.GET("/tvs", statsHandler.Tvs)
stats.GET("/tvs/:timeframe", statsHandler.TvsSeries)

price := stats.Group("/price")
{
Expand Down
2 changes: 0 additions & 2 deletions cmd/api/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ func TestRoutes(t *testing.T) {
"/v1/rollup/stats/series GET": {},
"/v1/rollup/group GET": {},
"/v1/blob/proofs POST": {},
"/v1/stats/tvs GET": {},
"/v1/stats/tvs/:timeframe GET": {},
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down
Loading

0 comments on commit cdf842c

Please sign in to comment.