Skip to content

Commit

Permalink
Refactoring: L2Beat change enpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jan 29, 2025
1 parent fb06116 commit a54cacf
Show file tree
Hide file tree
Showing 17 changed files with 308 additions and 132 deletions.
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@
"../../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"
}
]
}
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ api:
quotes:
cd cmd/quotes && go run . -c ../../configs/dipdup.yml

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

build:
cd cmd/indexer && go build -a -o ../../bin/indexer .
cd cmd/api && go build -a -o ../../bin/api .
Expand Down Expand Up @@ -40,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
go generate -v ./internal/blob ./internal/storage ./internal/storage/types ./pkg/node ./internal/binance ./internal/tvl/l2beat ./internal/tvl/lama

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

.PHONY: init indexer api build clean compose lint test adr mock api-docs check-licenses cover license-header
.PHONY: init indexer api build clean compose lint test adr mock api-docs check-licenses cover license-header tvl
1 change: 0 additions & 1 deletion internal/storage/mock/namespace.go

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

56 changes: 28 additions & 28 deletions internal/storage/mock/rollup.go

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

1 change: 0 additions & 1 deletion internal/storage/mock/stats.go

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

1 change: 0 additions & 1 deletion internal/storage/mock/tvl.go

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

14 changes: 2 additions & 12 deletions internal/storage/tvl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@ package storage

import (
"context"
"github.com/shopspring/decimal"
"github.com/uptrace/bun"
"time"
)

type TvlTimeframe string

const (
TvlTimeframeWeek TvlTimeframe = "7d"
TvlTimeframeMonth TvlTimeframe = "30d"
TvlTimeframe3Month TvlTimeframe = "90d"
TvlTimeframe6Month TvlTimeframe = "180d"
TvlTimeframeYear TvlTimeframe = "1y"
TvlTimeframeMax TvlTimeframe = "max"
"github.com/shopspring/decimal"
"github.com/uptrace/bun"
)

//go:generate mockgen -source=$GOFILE -destination=mock/$GOFILE -package=mock -typed
Expand Down
16 changes: 15 additions & 1 deletion internal/test_suite/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@

package testsuite

import "encoding/hex"
import (
"crypto/rand"
"encoding/hex"
"math/big"

"github.com/shopspring/decimal"
)

// Ptr - returns pointer of value for testing purpose
//
Expand All @@ -22,3 +28,11 @@ func MustHexDecode(s string) []byte {
}
return data
}

// RandomDecimal - returns random decimal value
//
// data := RandomDecimal()
func RandomDecimal() decimal.Decimal {
val, _ := rand.Int(rand.Reader, big.NewInt(1000))
return decimal.NewFromBigInt(val, 1)
}
3 changes: 1 addition & 2 deletions internal/tvl/l2beat/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ package l2beat

import (
"context"
"github.com/celenium-io/celestia-indexer/internal/storage"
)

//go:generate mockgen -source=$GOFILE -destination=mock/$GOFILE -package=mock -typed
type IApi interface {
TVL(ctx context.Context, rollupName string, timeframe storage.TvlTimeframe) (result TVLResponse, err error)
TVL(ctx context.Context, rollupName string, timeframe TvlTimeframe) (result TVLResponse, err error)
}
11 changes: 6 additions & 5 deletions internal/tvl/l2beat/mock/interface.go

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

17 changes: 17 additions & 0 deletions internal/tvl/l2beat/timeframe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2024 PK Lab AG <[email protected]>
// SPDX-License-Identifier: MIT

package l2beat

/*
ENUM(
7d,
30d,
90d,
180d,
1y,
max
)
*/
//go:generate go-enum --marshal --values --names
type TvlTimeframe string
Loading

0 comments on commit a54cacf

Please sign in to comment.