Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Pitasi committed Jun 14, 2022
1 parent 5de654d commit 9557d8d
Show file tree
Hide file tree
Showing 25 changed files with 863 additions and 172 deletions.
140 changes: 0 additions & 140 deletions api/cached/api.go

This file was deleted.

24 changes: 24 additions & 0 deletions api/database/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,27 @@ func (d *Database) ChainsOnlineStatuses(ctx context.Context) ([]ChainOnlineStatu

return rows, nil
}

func (d *Database) Denoms(ctx context.Context) ([]cns.Denom, error) {
defer sentry.StartSpan(ctx, "db.DenomTicker").Finish()

q := `
SELECT denoms
FROM cns.chains
WHERE enabled
`

var rows []struct {
Denoms cns.DenomList `db:"denoms"`
}
if err := d.dbi.DB.SelectContext(ctx, &rows, q); err != nil {
return nil, err
}

var ret []cns.Denom
for _, r := range rows {
ret = append(ret, r.Denoms...)
}

return ret, nil
}
6 changes: 6 additions & 0 deletions api/database/chains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,9 @@ func (s *TestSuite) TestChainsOnlineStatuses() {
})
}
}

func (s *TestSuite) TestDenoms() {
denoms, err := s.ctx.Router.DB.Denoms(context.Background())
s.Require().NoError(err)
s.Require().Greater(len(denoms), 0)
}
55 changes: 55 additions & 0 deletions api/prices/prices.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package prices

import (
"net/http"

"github.com/emerishq/demeris-api-server/lib/ginutils"
"github.com/emerishq/demeris-api-server/usecase"
"github.com/emerishq/emeris-utils/logging"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)

type PricesAPI struct {
app usecase.IApp
}

func New(app usecase.IApp) *PricesAPI {
return &PricesAPI{
app: app,
}
}

func Register(router *gin.Engine, app usecase.IApp) {
api := New(app)

router.Group("/prices").
GET("/pools", api.GetPoolsPrices)
}

type GetPoolsPricesResponse struct {
PoolResults usecase.PoolPricesResult `json:"pool_results"`
}

// GetPoolsPrices returns the list of available pools and their associated token's price.
// @Summary Get pools' tokens prices
// @Tags Price
// @ID get-pools-prices
// @Produce json
// @Success 200 {object} GetPoolsPricesResponse
// @Failure 500 {object} apierrors.UserFacingError
// @Router /prices/pools [get]
func (api *PricesAPI) GetPoolsPrices(c *gin.Context) {
prices := api.app.PoolPrices(c.Request.Context())

logger := ginutils.GetValue[*zap.SugaredLogger](c, logging.LoggerKey)
for _, opt := range prices {
if opt.Err != nil {
logger.Errorw("fetching pool price", "err", opt.Err)
}
}

c.JSON(http.StatusOK, GetPoolsPricesResponse{
PoolResults: prices,
})
}
8 changes: 4 additions & 4 deletions api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"

"github.com/emerishq/demeris-api-server/api/block"
"github.com/emerishq/demeris-api-server/api/cached"
"github.com/emerishq/demeris-api-server/api/liquidity"
"github.com/emerishq/demeris-api-server/api/prices"
"github.com/emerishq/demeris-api-server/lib/apierrors"
"github.com/emerishq/demeris-api-server/lib/stringcache"
"github.com/emerishq/demeris-api-server/sdkservice"
Expand Down Expand Up @@ -162,7 +162,7 @@ func registerRoutes(engine *gin.Engine, db *database.Database, s *store.Store,
// @tag.description pool-related endpoints
liquidity.Register(engine, db, s)

// @tag.name cached
// @tag.description cached data endpoints
cached.Register(engine, db, s)
// @tag.name prices
// @tag.description prices related endpoints
prices.Register(engine, app)
}
13 changes: 12 additions & 1 deletion cmd/api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/emerishq/demeris-api-server/api/database"
"github.com/emerishq/demeris-api-server/api/router"
"github.com/emerishq/demeris-api-server/lib/fflag"
"github.com/emerishq/demeris-api-server/lib/poclient"
"github.com/emerishq/demeris-api-server/sdkservice"
"github.com/emerishq/demeris-api-server/usecase"
"github.com/emerishq/emeris-utils/k8s"
Expand Down Expand Up @@ -108,7 +109,17 @@ func main() {
l.Panicw("cannot initialize sdk-service clients", "error", err)
}

app := usecase.NewApp(sdkServiceClients)
osmosisClient := usecase.NewOsmosisClient("osmosis:9090")

crescentClient := usecase.NewCrescentClient("crescent:9090")

priceOracle := poclient.NewPOClient("http://price-oracle:8000")

denomer := usecase.NewDatabaseDenomer(dbi)

denomPricer := usecase.NewPriceOracleDenomPricer(denomer, dbi, priceOracle)

app := usecase.NewApp(sdkServiceClients, osmosisClient, crescentClient, denomPricer)

r := router.New(
dbi,
Expand Down
1 change: 0 additions & 1 deletion docs/swagger_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
_ "github.com/emerishq/demeris-backend-models/tracelistener"
_ "github.com/emerishq/emeris-utils/exported/sdktypes"
_ "github.com/emerishq/emeris-utils/store"
_ "github.com/gravity-devs/liquidity/x/liquidity/types"
_ "github.com/swaggo/swag"
_ "github.com/tendermint/tendermint/proto/tendermint/version"
_ "github.com/tendermint/tendermint/rpc/core/types"
Expand Down
15 changes: 8 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/allinbits/starport-operator v0.0.1-alpha.45
github.com/cockroachdb/cockroach-go/v2 v2.2.8
github.com/cosmos/cosmos-sdk v0.45.3
github.com/crescent-network/crescent v1.1.0
github.com/emerishq/demeris-backend-models v1.5.0
github.com/emerishq/emeris-cns-server v0.0.0-20220422070001-a18e063b6374
github.com/emerishq/emeris-price-oracle v1.0.0
Expand All @@ -27,9 +28,9 @@ require (
github.com/gofrs/uuid v4.2.0+incompatible
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.5.7
github.com/gravity-devs/liquidity v1.5.0
github.com/jmoiron/sqlx v1.3.3
github.com/lib/pq v1.10.4
github.com/osmosis-labs/osmosis/v7 v7.3.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/stretchr/testify v1.7.1
github.com/swaggo/swag v1.8.0
Expand Down Expand Up @@ -72,7 +73,7 @@ require (
github.com/danieljoos/wincred v1.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/dgraph-io/badger/v2 v2.2007.2 // indirect
github.com/dgraph-io/badger/v2 v2.2007.3 // indirect
github.com/dgraph-io/ristretto v0.0.3 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
Expand Down Expand Up @@ -107,7 +108,7 @@ require (
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.0.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.8.0 // indirect
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
Expand All @@ -132,7 +133,7 @@ require (
github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/libp2p/go-buffer-pool v0.0.2 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
Expand All @@ -149,7 +150,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/common v0.33.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
Expand Down Expand Up @@ -184,7 +185,7 @@ require (
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
Expand All @@ -206,5 +207,5 @@ require (
k8s.io/kube-openapi v0.0.0-20210527164424-3c818078ee3d // indirect
k8s.io/utils v0.0.0-20210527160623-6fdb442a123b // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 9557d8d

Please sign in to comment.