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

feat: SQS pricing from on-chain source #85

Merged
merged 4 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion app/sidecar_query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ func NewSideCarQueryServer(appCodec codec.Codec, config domain.Config, logger lo
// HTTP handlers
poolsHttpDelivery.NewPoolsHandler(e, poolsUseCase)
systemhttpdelivery.NewSystemHandler(e, redisAddress, config, logger, chainInfoUseCase)
tokenshttpdelivery.NewTokensHandler(e, tokensUseCase, logger)
if err := tokenshttpdelivery.NewTokensHandler(e, tokensUseCase, routerUsecase, logger); err != nil {
return nil, err
}
routerHttpDelivery.NewRouterHandler(e, routerUsecase, tokensUseCase, logger)

go func() {
Expand Down
59 changes: 49 additions & 10 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const docTemplate = `{
}
}
},
"/tokens/metadata/{denom}": {
"/tokens/metadata": {
"get": {
"description": "returns token metadata with chain denom, human denom, and precision.\nFor testnet, uses osmo-test-5 asset list. For mainnet, uses osmosis-1 asset list.\nSee ` + "`" + `config.json` + "`" + ` and ` + "`" + `config-testnet.json` + "`" + ` in root for details.",
"produces": [
Expand All @@ -142,17 +142,60 @@ const docTemplate = `{
"parameters": [
{
"type": "string",
"description": "Denom can either be a human denom or a chain denom",
"name": "denom",
"in": "path",
"required": true
"description": "List of denoms where each can either be a human denom or a chain denom",
"name": "denoms",
"in": "path"
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/domain.Token"
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/domain.Token"
}
}
}
}
}
},
"/tokens/prices": {
"get": {
"description": "Given a list of base denominations, returns the spot price with a system-configured quote denomination.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Get prices",
"parameters": [
{
"type": "string",
"description": "Comma-separated list of base denominations (human-readable or chain format based on humanDenoms parameter)",
"name": "base",
"in": "query",
"required": true
},
{
"type": "boolean",
"description": "Specify true if input denominations are in human-readable format; defaults to false",
"name": "humanDenoms",
"in": "query"
}
],
"responses": {
"200": {
"description": "A map where each key is a base denomination (on-chain format), containing another map with a key as the quote denomination (on-chain format) and the value as the spot price.",
"schema": {
"type": "object",
"additionalProperties": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
Expand All @@ -163,10 +206,6 @@ const docTemplate = `{
"domain.Token": {
"type": "object",
"properties": {
"chain_denom": {
"description": "ChainDenom is the denom used in the chain state.",
"type": "string"
},
"human_denom": {
"description": "HumanDenom is the human readable denom.",
"type": "string"
Expand Down
59 changes: 49 additions & 10 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
}
}
},
"/tokens/metadata/{denom}": {
"/tokens/metadata": {
"get": {
"description": "returns token metadata with chain denom, human denom, and precision.\nFor testnet, uses osmo-test-5 asset list. For mainnet, uses osmosis-1 asset list.\nSee `config.json` and `config-testnet.json` in root for details.",
"produces": [
Expand All @@ -133,17 +133,60 @@
"parameters": [
{
"type": "string",
"description": "Denom can either be a human denom or a chain denom",
"name": "denom",
"in": "path",
"required": true
"description": "List of denoms where each can either be a human denom or a chain denom",
"name": "denoms",
"in": "path"
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/domain.Token"
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/domain.Token"
}
}
}
}
}
},
"/tokens/prices": {
"get": {
"description": "Given a list of base denominations, returns the spot price with a system-configured quote denomination.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Get prices",
"parameters": [
{
"type": "string",
"description": "Comma-separated list of base denominations (human-readable or chain format based on humanDenoms parameter)",
"name": "base",
"in": "query",
"required": true
},
{
"type": "boolean",
"description": "Specify true if input denominations are in human-readable format; defaults to false",
"name": "humanDenoms",
"in": "query"
}
],
"responses": {
"200": {
"description": "A map where each key is a base denomination (on-chain format), containing another map with a key as the quote denomination (on-chain format) and the value as the spot price.",
"schema": {
"type": "object",
"additionalProperties": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
Expand All @@ -154,10 +197,6 @@
"domain.Token": {
"type": "object",
"properties": {
"chain_denom": {
"description": "ChainDenom is the denom used in the chain state.",
"type": "string"
},
"human_denom": {
"description": "HumanDenom is the human readable denom.",
"type": "string"
Expand Down
47 changes: 39 additions & 8 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
definitions:
domain.Token:
properties:
chain_denom:
description: ChainDenom is the denom used in the chain state.
type: string
human_denom:
description: HumanDenom is the human readable denom.
type: string
Expand Down Expand Up @@ -127,25 +124,59 @@ paths:
$ref: '#/definitions/sqsdomain.CandidateRoutes'
type: array
summary: Token Routing Information
/tokens/metadata/{denom}:
/tokens/metadata:
get:
description: |-
returns token metadata with chain denom, human denom, and precision.
For testnet, uses osmo-test-5 asset list. For mainnet, uses osmosis-1 asset list.
See `config.json` and `config-testnet.json` in root for details.
operationId: get-token-metadata
parameters:
- description: Denom can either be a human denom or a chain denom
- description: List of denoms where each can either be a human denom or a chain
denom
in: path
name: denom
required: true
name: denoms
type: string
produces:
- application/json
responses:
"200":
description: Success
schema:
$ref: '#/definitions/domain.Token'
additionalProperties:
$ref: '#/definitions/domain.Token'
type: object
summary: Token Metadata
/tokens/prices:
get:
consumes:
- application/json
description: Given a list of base denominations, returns the spot price with
a system-configured quote denomination.
parameters:
- description: Comma-separated list of base denominations (human-readable or
chain format based on humanDenoms parameter)
in: query
name: base
required: true
type: string
- description: Specify true if input denominations are in human-readable format;
defaults to false
in: query
name: humanDenoms
type: boolean
produces:
- application/json
responses:
"200":
description: A map where each key is a base denomination (on-chain format),
containing another map with a key as the quote denomination (on-chain
format) and the value as the spot price.
schema:
additionalProperties:
additionalProperties:
type: string
type: object
type: object
summary: Get prices
swagger: "2.0"
17 changes: 15 additions & 2 deletions domain/mvc/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mvc
import (
"context"

"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/sqs/domain"
)

Expand All @@ -11,9 +12,21 @@ type TokensUsecase interface {
// GetMetadataByChainDenom returns token metadata for a given chain denom.
GetMetadataByChainDenom(ctx context.Context, denom string) (domain.Token, error)

// GetFullTokenMetadata returns token metadata for all chain denoms as a map.
GetFullTokenMetadata(ctx context.Context) (map[string]domain.Token, error)

// GetChainDenom returns chain denom by human denom
GetChainDenom(ctx context.Context, humanDenom string) (string, error)

// GetDenomPrecisions returns a map of all denom precisions.
GetDenomPrecisions(ctx context.Context) (map[string]int, error)
// GetChainScalingFactorByDenomMut returns a chain scaling factor for a given denom
// and a boolean flag indicating whether the scaling factor was found or not.
// Note that the returned decimal is a shared resource and must not be mutated.
// A clone should be made for any mutative operation.
GetChainScalingFactorByDenomMut(ctx context.Context, denom string) (osmomath.Dec, error)

// GetPrices returns prices for all given base and quote denoms given a pricing strategy or, otherwise, error, if any.
// The outer map consists of base denoms as keys.
// The inner map consists of quote denoms as keys.
// The result of the inner map is prices of the outer base and inner quote.
GetPrices(ctx context.Context, baseDenoms []string, quoteDenoms []string, pricingStrategy domain.PricingStrategy) (map[string]map[string]any, error)
}
27 changes: 27 additions & 0 deletions domain/pricing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package domain

import (
"context"

"github.com/osmosis-labs/osmosis/osmomath"
)

// PricingSource defines the enumeration
// for possible pricing sources.
type PricingSource int

const (
// ChainPricingSource defines the pricing source
// by routing through on-chain pools.
ChainPricingSource PricingSource = iota
// CoinGeckoPricingSource defines the pricing source
// that calls CoinGecko API.
CoinGeckoPricingSource
)

// PricingStrategy defines an interface that must be fulfilled by the specific
// implementation of the pricing stratgy.
type PricingStrategy interface {
// GetPrice returns the price given a bse and a quote denom or otherwise error, if any.
GetPrice(ctx context.Context, baseDenom string, quoteDenom string) (osmomath.BigDec, error)
}
2 changes: 0 additions & 2 deletions domain/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package domain

// Token represents the token's domain model
type Token struct {
// ChainDenom is the denom used in the chain state.
ChainDenom string `json:"chain_denom"`
// HumanDenom is the human readable denom.
HumanDenom string `json:"human_denom"`
// Precision is the precision of the token.
Expand Down
Loading
Loading