Skip to content

Commit

Permalink
Feat: in given out for /custom-direct-quote (#420)
Browse files Browse the repository at this point in the history
* Feat: in given out for /custom-direct-quote

* Feat: in given out for /custom-direct-quote

Add humanDenoms support

* Feat: in given out for /custom-direct-quote

Update swagger

* Feat: in given out for /custom-direct-quote

Update docs

* Feat: in given out for /custom-direct-quote

Add docs for supported route types

* Feat: in given out for /custom-direct-quote (#423)

* Feat: in given out for /custom-direct-quote

e2e tests for exact amount out init

* fix merge error

* WIP

* WIP

* Feat: in given out for /custom-direct-quote

e2e tests for /custom-direct-quote

* Feat: in given out for /custom-direct-quote

Break run_quote_test into smaller individual parts for reusability

* Feat: in given out for /custom-direct-quote

Introduce calculate_expected_base_out_quote_spot_price

* Feat: in given out for /custom-direct-quote

Add synthetic tests for /quote and /custom-direct-quote

* Update tests/route.py

---------

Co-authored-by: Deividas Petraitis <[email protected]>

* code rabbit

---------

Co-authored-by: Roman <[email protected]>
  • Loading branch information
deividaspetraitis and p0mvn authored Aug 17, 2024
1 parent 7fa4e31 commit ae2b8eb
Show file tree
Hide file tree
Showing 24 changed files with 1,430 additions and 413 deletions.
43 changes: 33 additions & 10 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const docTemplate = `{
},
"/router/custom-direct-quote": {
"get": {
"description": "Call does not search for the route rather directly computes the quote for the given poolID.",
"description": "Call does not search for the route rather directly computes the quote for the given poolID.\nNOTE: Endpoint only supports multi-hop routes, split routes are not supported.\n\nFor exact amount in swap method, the ` + "`" + `tokenIn` + "`" + ` and ` + "`" + `tokenOutDenom` + "`" + ` are required.\nFor exact amount out swap method, the ` + "`" + `tokenOut` + "`" + ` and ` + "`" + `tokenInDenom` + "`" + ` are required.\nMixing swap method parameters in other way than specified will result in an error.\n",
"produces": [
"application/json"
],
Expand All @@ -150,28 +150,47 @@ const docTemplate = `{
"parameters": [
{
"type": "string",
"example": "5OSMO",
"description": "String representation of the sdk.Coin for the token in.",
"example": "1000000uosmo",
"description": "String representation of the sdk.Coin denoting the input token for the exact amount in swap method.",
"name": "tokenIn",
"in": "query",
"required": true
"in": "query"
},
{
"type": "string",
"example": "ATOM,USDC",
"description": "String representing the list of the token denom out separated by comma.",
"example": "uion",
"description": "String representing the list of the output token denominations separated by comma for the exact amount in swap method.",
"name": "tokenOutDenom",
"in": "query",
"required": true
"in": "query"
},
{
"type": "string",
"example": "2353uion",
"description": "String representation of the sdk.Coin denoting the output token for the exact amount out swap method.",
"name": "tokenOut",
"in": "query"
},
{
"type": "string",
"example": "1,2,3",
"example": "uosmo",
"description": "String representing the list of the input token denominations separated by comma for the exact amount out swap method.",
"name": "tokenInDenom",
"in": "query"
},
{
"type": "string",
"example": "1100",
"description": "String representing list of the pool ID.",
"name": "poolID",
"in": "query",
"required": true
},
{
"type": "boolean",
"description": "Boolean flag indicating whether the given denoms are human readable or not. Human denoms get converted to chain internally",
"name": "humanDenoms",
"in": "query",
"required": true
},
{
"type": "boolean",
"description": "Boolean flag indicating whether to apply exponents to the spot price. False by default.",
Expand All @@ -198,24 +217,28 @@ const docTemplate = `{
"parameters": [
{
"type": "string",
"example": "1000000uosmo",
"description": "String representation of the sdk.Coin denoting the input token for the exact amount in swap method.",
"name": "tokenIn",
"in": "query"
},
{
"type": "string",
"example": "uion",
"description": "String representing the denomination of the output token for the exact amount in swap method.",
"name": "tokenOutDenom",
"in": "query"
},
{
"type": "string",
"example": "2353uion",
"description": "String representation of the sdk.Coin denoting the output token for the exact amount out swap method.",
"name": "tokenOut",
"in": "query"
},
{
"type": "string",
"example": "uosmo",
"description": "String representing the denomination of the input token for the exact amount out swap method.",
"name": "tokenInDenom",
"in": "query"
Expand Down
43 changes: 33 additions & 10 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
},
"/router/custom-direct-quote": {
"get": {
"description": "Call does not search for the route rather directly computes the quote for the given poolID.",
"description": "Call does not search for the route rather directly computes the quote for the given poolID.\nNOTE: Endpoint only supports multi-hop routes, split routes are not supported.\n\nFor exact amount in swap method, the `tokenIn` and `tokenOutDenom` are required.\nFor exact amount out swap method, the `tokenOut` and `tokenInDenom` are required.\nMixing swap method parameters in other way than specified will result in an error.\n",
"produces": [
"application/json"
],
Expand All @@ -141,28 +141,47 @@
"parameters": [
{
"type": "string",
"example": "5OSMO",
"description": "String representation of the sdk.Coin for the token in.",
"example": "1000000uosmo",
"description": "String representation of the sdk.Coin denoting the input token for the exact amount in swap method.",
"name": "tokenIn",
"in": "query",
"required": true
"in": "query"
},
{
"type": "string",
"example": "ATOM,USDC",
"description": "String representing the list of the token denom out separated by comma.",
"example": "uion",
"description": "String representing the list of the output token denominations separated by comma for the exact amount in swap method.",
"name": "tokenOutDenom",
"in": "query",
"required": true
"in": "query"
},
{
"type": "string",
"example": "2353uion",
"description": "String representation of the sdk.Coin denoting the output token for the exact amount out swap method.",
"name": "tokenOut",
"in": "query"
},
{
"type": "string",
"example": "1,2,3",
"example": "uosmo",
"description": "String representing the list of the input token denominations separated by comma for the exact amount out swap method.",
"name": "tokenInDenom",
"in": "query"
},
{
"type": "string",
"example": "1100",
"description": "String representing list of the pool ID.",
"name": "poolID",
"in": "query",
"required": true
},
{
"type": "boolean",
"description": "Boolean flag indicating whether the given denoms are human readable or not. Human denoms get converted to chain internally",
"name": "humanDenoms",
"in": "query",
"required": true
},
{
"type": "boolean",
"description": "Boolean flag indicating whether to apply exponents to the spot price. False by default.",
Expand All @@ -189,24 +208,28 @@
"parameters": [
{
"type": "string",
"example": "1000000uosmo",
"description": "String representation of the sdk.Coin denoting the input token for the exact amount in swap method.",
"name": "tokenIn",
"in": "query"
},
{
"type": "string",
"example": "uion",
"description": "String representing the denomination of the output token for the exact amount in swap method.",
"name": "tokenOutDenom",
"in": "query"
},
{
"type": "string",
"example": "2353uion",
"description": "String representation of the sdk.Coin denoting the output token for the exact amount out swap method.",
"name": "tokenOut",
"in": "query"
},
{
"type": "string",
"example": "uosmo",
"description": "String representing the denomination of the input token for the exact amount out swap method.",
"name": "tokenInDenom",
"in": "query"
Expand Down
46 changes: 36 additions & 10 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,29 +157,51 @@ paths:
summary: Get entries for all supported orderbook base and quote denoms.
/router/custom-direct-quote:
get:
description: Call does not search for the route rather directly computes the
quote for the given poolID.
description: |
Call does not search for the route rather directly computes the quote for the given poolID.
NOTE: Endpoint only supports multi-hop routes, split routes are not supported.
For exact amount in swap method, the `tokenIn` and `tokenOutDenom` are required.
For exact amount out swap method, the `tokenOut` and `tokenInDenom` are required.
Mixing swap method parameters in other way than specified will result in an error.
operationId: get-direct-quote
parameters:
- description: String representation of the sdk.Coin for the token in.
example: 5OSMO
- description: String representation of the sdk.Coin denoting the input token
for the exact amount in swap method.
example: 1000000uosmo
in: query
name: tokenIn
required: true
type: string
- description: String representing the list of the token denom out separated
by comma.
example: ATOM,USDC
- description: String representing the list of the output token denominations
separated by comma for the exact amount in swap method.
example: uion
in: query
name: tokenOutDenom
required: true
type: string
- description: String representation of the sdk.Coin denoting the output token
for the exact amount out swap method.
example: 2353uion
in: query
name: tokenOut
type: string
- description: String representing the list of the input token denominations
separated by comma for the exact amount out swap method.
example: uosmo
in: query
name: tokenInDenom
type: string
- description: String representing list of the pool ID.
example: 1,2,3
example: "1100"
in: query
name: poolID
required: true
type: string
- description: Boolean flag indicating whether the given denoms are human readable
or not. Human denoms get converted to chain internally
in: query
name: humanDenoms
required: true
type: boolean
- description: Boolean flag indicating whether to apply exponents to the spot
price. False by default.
in: query
Expand All @@ -206,21 +228,25 @@ paths:
parameters:
- description: String representation of the sdk.Coin denoting the input token
for the exact amount in swap method.
example: 1000000uosmo
in: query
name: tokenIn
type: string
- description: String representing the denomination of the output token for
the exact amount in swap method.
example: uion
in: query
name: tokenOutDenom
type: string
- description: String representation of the sdk.Coin denoting the output token
for the exact amount out swap method.
example: 2353uion
in: query
name: tokenOut
type: string
- description: String representing the denomination of the input token for the
exact amount out swap method.
example: uosmo
in: query
name: tokenInDenom
type: string
Expand Down
8 changes: 8 additions & 0 deletions domain/mocks/router_usecase_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type RouterUsecaseMock struct {
GetBestSingleRouteQuoteFunc func(ctx context.Context, tokenIn sdk.Coin, tokenOutDenom string) (domain.Quote, error)
GetCustomDirectQuoteFunc func(ctx context.Context, tokenIn sdk.Coin, tokenOutDenom string, poolID uint64) (domain.Quote, error)
GetCustomDirectQuoteMultiPoolFunc func(ctx context.Context, tokenIn sdk.Coin, tokenOutDenom []string, poolIDs []uint64) (domain.Quote, error)
GetCustomDirectQuoteMultiPoolInGivenOutFunc func(ctx context.Context, tokenOut sdk.Coin, tokenInDenom []string, poolIDs []uint64) (domain.Quote, error)
GetCandidateRoutesFunc func(ctx context.Context, tokenIn sdk.Coin, tokenOutDenom string) (sqsdomain.CandidateRoutes, error)
GetTakerFeeFunc func(poolID uint64) ([]sqsdomain.TakerFeeForPair, error)
SetTakerFeesFunc func(takerFees sqsdomain.TakerFeeMap)
Expand Down Expand Up @@ -93,6 +94,13 @@ func (m *RouterUsecaseMock) GetCustomDirectQuoteMultiPool(ctx context.Context, t
panic("unimplemented")
}

func (m *RouterUsecaseMock) GetCustomDirectQuoteMultiPoolInGivenOut(ctx context.Context, tokenOut sdk.Coin, tokenInDenom []string, poolIDs []uint64) (domain.Quote, error) {
if m.GetCustomDirectQuoteMultiPoolInGivenOutFunc != nil {
return m.GetCustomDirectQuoteMultiPoolInGivenOutFunc(ctx, tokenOut, tokenInDenom, poolIDs)
}
panic("unimplemented")
}

func (m *RouterUsecaseMock) GetCandidateRoutes(ctx context.Context, tokenIn sdk.Coin, tokenOutDenom string) (sqsdomain.CandidateRoutes, error) {
if m.GetCandidateRoutesFunc != nil {
return m.GetCandidateRoutesFunc(ctx, tokenIn, tokenOutDenom)
Expand Down
5 changes: 4 additions & 1 deletion domain/mvc/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ type RouterUsecase interface {
// This allows to bypass a min liquidity requirement in the router when attempting to swap over a specific pool.
GetCustomDirectQuote(ctx context.Context, tokenIn sdk.Coin, tokenOutDenom string, poolID uint64) (domain.Quote, error)
// GetCustomDirectQuoteMultiPool calculates direct custom quote for given tokenIn and tokenOutDenom over given poolID route.
// Otherwise it implements same rules as GetCustomDirectQuote.
// Underlying implementation uses GetCustomDirectQuote.
GetCustomDirectQuoteMultiPool(ctx context.Context, tokenIn sdk.Coin, tokenOutDenom []string, poolIDs []uint64) (domain.Quote, error)
// GetCustomDirectQuoteMultiPool calculates direct custom quote for given tokenOut and tokenInDenom over given poolID route.
// Underlying implementation uses GetCustomDirectQuote.
GetCustomDirectQuoteMultiPoolInGivenOut(ctx context.Context, tokenOut sdk.Coin, tokenInDenom []string, poolIDs []uint64) (domain.Quote, error)
// GetCandidateRoutes returns the candidate routes for the given tokenIn and tokenOutDenom.
GetCandidateRoutes(ctx context.Context, tokenIn sdk.Coin, tokenOutDenom string) (sqsdomain.CandidateRoutes, error)
// GetTakerFee returns the taker fee for all token pairs in a pool.
Expand Down
6 changes: 0 additions & 6 deletions router/delivery/http/export_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
package http

import "github.com/labstack/echo/v4"

func GetPoolsValidTokenInTokensOut(c echo.Context) (poolIDs []uint64, tokenOut []string, tokenIn string, err error) {
return getPoolsValidTokenInTokensOut(c)
}
Loading

0 comments on commit ae2b8eb

Please sign in to comment.