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

Configurable liquidity and tx count thresholds #112

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
47 changes: 47 additions & 0 deletions go-ooo/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/spf13/viper"
oooapidextypes "go-ooo/ooo_api/dex/types"
"os"
)

Expand Down Expand Up @@ -64,6 +65,21 @@ type ApiKeysConfig struct {
GraphNetwork string `mapstructure:"graph_network_key"`
}

type DexConfig struct {
MinReserveUsd uint64 `mapstructure:"min_reserve_usd"`
MinTxCount uint64 `mapstructure:"min_tx_count"`
}

type DexList struct {
BscPancakeswapV3 DexConfig `mapstructure:"bsc_pancakeswap_v3"`
EthShibaswap DexConfig `mapstructure:"eth_shibaswap"`
EthSushiswap DexConfig `mapstructure:"eth_sushiswap"`
EthUniswapV2 DexConfig `mapstructure:"eth_uniswap_v2"`
EthUniswapV3 DexConfig `mapstructure:"eth_uniswap_v3"`
PolygonPosQuickswapV3 DexConfig `mapstructure:"polygon_pos_quickswap_v3"`
XdaiHoneyswap DexConfig `mapstructure:"xdai_honeyswap"`
}

type Config struct {
Jobs JobsConfig `mapstructure:"jobs"`
Serve ServeConfig `mapstructure:"serve"`
Expand All @@ -74,6 +90,7 @@ type Config struct {
Log LogConfig `mapstructure:"log"`
Subchain SubchainConfig `mapstructure:"subchain"`
ApiKeys ApiKeysConfig `mapstructure:"api_keys"`
Dexs DexList `mapstructure:"dexs"`
}

// DefaultConfig returns server's default configuration.
Expand Down Expand Up @@ -127,6 +144,36 @@ func DefaultConfig() *Config {
ApiKeys: ApiKeysConfig{
GraphNetwork: "",
},
Dexs: DexList{
BscPancakeswapV3: DexConfig{
MinReserveUsd: oooapidextypes.DefaultMinLiquidity,
MinTxCount: oooapidextypes.DefaultMinTxCount,
},
EthShibaswap: DexConfig{
MinReserveUsd: oooapidextypes.DefaultMinLiquidity,
MinTxCount: oooapidextypes.DefaultMinTxCount,
},
EthSushiswap: DexConfig{
MinReserveUsd: oooapidextypes.DefaultMinLiquidity,
MinTxCount: oooapidextypes.DefaultMinTxCount,
},
EthUniswapV2: DexConfig{
MinReserveUsd: oooapidextypes.DefaultMinLiquidity,
MinTxCount: oooapidextypes.DefaultMinTxCount,
},
EthUniswapV3: DexConfig{
MinReserveUsd: oooapidextypes.DefaultMinLiquidity,
MinTxCount: oooapidextypes.DefaultMinTxCount,
},
PolygonPosQuickswapV3: DexConfig{
MinReserveUsd: oooapidextypes.DefaultMinLiquidity,
MinTxCount: oooapidextypes.DefaultMinTxCount,
},
XdaiHoneyswap: DexConfig{
MinReserveUsd: oooapidextypes.DefaultMinLiquidity,
MinTxCount: oooapidextypes.DefaultMinTxCount,
},
},
}
}

Expand Down
38 changes: 37 additions & 1 deletion go-ooo/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const DefaultConfigTemplate = `# This is a TOML config file.

[chain]
# Address of the Router smart contract
contract_address = "{{ .Chain.ContractAddresses }}"
contract_address = "{{ .Chain.ContractAddress }}"

# Network Id, e.g. 1 for mainnet etc.
network_id = {{ .Chain.NetworkId }}
Expand Down Expand Up @@ -140,6 +140,42 @@ shibarium_http_rpc = "{{ .Subchain.ShibariumHttpRpc }}"

[api_keys]
graph_network_key = "{{ .ApiKeys.GraphNetwork }}"

##########################################
## DEX Limits ##
##########################################

# Minimum Liquidity (USD) and Tx thresholds, below which
# a pair is not included in an AdHoc query

[dexs.bsc_pancakeswap_v3]
min_reserve_usd = "{{ .Dexs.BscPancakeswapV3.MinReserveUsd }}"
min_tx_count = "{{ .Dexs.BscPancakeswapV3.MinTxCount }}"

[dexs.eth_shibaswap]
min_reserve_usd = "{{ .Dexs.EthShibaswap.MinReserveUsd }}"
min_tx_count = "{{ .Dexs.EthShibaswap.MinTxCount }}"

[dexs.eth_sushiswap]
min_reserve_usd = "{{ .Dexs.EthSushiswap.MinReserveUsd }}"
min_tx_count = "{{ .Dexs.EthSushiswap.MinTxCount }}"

[dexs.eth_uniswap_v2]
min_reserve_usd = "{{ .Dexs.EthUniswapV2.MinReserveUsd }}"
min_tx_count = "{{ .Dexs.EthUniswapV2.MinTxCount }}"

[dexs.eth_uniswap_v3]
min_reserve_usd = "{{ .Dexs.EthUniswapV3.MinReserveUsd }}"
min_tx_count = "{{ .Dexs.EthUniswapV3.MinTxCount }}"

[dexs.polygon_pos_quickswap_v3]
min_reserve_usd = "{{ .Dexs.PolygonPosQuickswapV3.MinReserveUsd }}"
min_tx_count = "{{ .Dexs.PolygonPosQuickswapV3.MinTxCount }}"

[dexs.xdai_honeyswap]
min_reserve_usd = "{{ .Dexs.XdaiHoneyswap.MinReserveUsd }}"
min_tx_count = "{{ .Dexs.XdaiHoneyswap.MinTxCount }}"

`

var configTemplate *template.Template
Expand Down
8 changes: 6 additions & 2 deletions go-ooo/ooo_api/dex/modules/bsc_pancakeswap_v3/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ var (
type DexModule struct {
ctx context.Context
graphNetworkApiKey string
minLiquidity uint64
minTxCount uint64
}

func NewDexModule(ctx context.Context, cfg *config.Config) DexModule {
return DexModule{
ctx: ctx,
graphNetworkApiKey: cfg.ApiKeys.GraphNetwork,
minLiquidity: cfg.Dexs.BscPancakeswapV3.MinReserveUsd,
minTxCount: cfg.Dexs.BscPancakeswapV3.MinTxCount,
}
}

Expand All @@ -41,11 +45,11 @@ func (d DexModule) Dex() string {
}

func (d DexModule) MinLiquidity() uint64 {
return MinLiquidity
return d.minLiquidity
}

func (d DexModule) MinTxCount() uint64 {
return MinTxCount
return d.minTxCount
}

func (d DexModule) GeneratePairsQuery(contractAddresses string) ([]byte, error) {
Expand Down
6 changes: 0 additions & 6 deletions go-ooo/ooo_api/dex/modules/bsc_pancakeswap_v3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ const (
GraphNetworkSubgraphId = "A1fvJWQLBeUAggX2WQTMm3FKjXTekNXo77ZySun4YN2m"
Chain = types.ChainBsc
Dex = "pancakeswap_v3"

// MinLiquidity - min liquidity a pair should have for the DEX pair search
MinLiquidity = types.MinLiquidity

// MinTxCount - min tx count a pair should have for the DEX pair search
MinTxCount = types.MinTxCount
)

type GraphQlToken struct {
Expand Down
8 changes: 6 additions & 2 deletions go-ooo/ooo_api/dex/modules/eth_shibaswap/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ var (
type DexModule struct {
ctx context.Context
graphNetworkApiKey string
minLiquidity uint64
minTxCount uint64
}

func NewDexModule(ctx context.Context, cfg *config.Config) DexModule {
return DexModule{
ctx: ctx,
graphNetworkApiKey: cfg.ApiKeys.GraphNetwork,
minLiquidity: cfg.Dexs.EthShibaswap.MinReserveUsd,
minTxCount: cfg.Dexs.EthShibaswap.MinTxCount,
}
}

Expand All @@ -45,11 +49,11 @@ func (d DexModule) Dex() string {
}

func (d DexModule) MinLiquidity() uint64 {
return MinLiquidity
return d.minLiquidity
}

func (d DexModule) MinTxCount() uint64 {
return MinTxCount
return d.minTxCount
}

func (d DexModule) GeneratePairsQuery(contractAddresses string) ([]byte, error) {
Expand Down
6 changes: 0 additions & 6 deletions go-ooo/ooo_api/dex/modules/eth_shibaswap/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ const (
GraphNetworkSubgraphId = "61LXXvGA1KXkJZbCceYqw9APcwTGefK5MytwnVsdAQpw"
Chain = types.ChainEth
Dex = "shibaswap"

// MinLiquidity - min liquidity a pair should have for the DEX pair search
MinLiquidity = types.MinLiquidity

// MinTxCount - min tx count a pair should have for the DEX pair search
MinTxCount = types.MinTxCount
)

type GraphQlToken struct {
Expand Down
8 changes: 6 additions & 2 deletions go-ooo/ooo_api/dex/modules/eth_sushiswap/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ var (
type DexModule struct {
ctx context.Context
graphNetworkApiKey string
minLiquidity uint64
minTxCount uint64
}

func NewDexModule(ctx context.Context, cfg *config.Config) DexModule {
return DexModule{
ctx: ctx,
graphNetworkApiKey: cfg.ApiKeys.GraphNetwork,
minLiquidity: cfg.Dexs.EthSushiswap.MinReserveUsd,
minTxCount: cfg.Dexs.EthSushiswap.MinTxCount,
}
}

Expand All @@ -45,11 +49,11 @@ func (d DexModule) Dex() string {
}

func (d DexModule) MinLiquidity() uint64 {
return MinLiquidity
return d.minLiquidity
}

func (d DexModule) MinTxCount() uint64 {
return MinTxCount
return d.minTxCount
}

func (d DexModule) GeneratePairsQuery(contractAddresses string) ([]byte, error) {
Expand Down
6 changes: 0 additions & 6 deletions go-ooo/ooo_api/dex/modules/eth_sushiswap/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ const (
GraphNetworkSubgraphId = "6NUtT5mGjZ1tSshKLf5Q3uEEJtjBZJo1TpL5MXsUBqrT"
Chain = types.ChainEth
Dex = "sushiswap"

// MinLiquidity - min liquidity a pair should have for the DEX pair search
MinLiquidity = types.MinLiquidity

// MinTxCount - min tx count a pair should have for the DEX pair search
MinTxCount = types.MinTxCount
)

type GraphQlToken struct {
Expand Down
8 changes: 6 additions & 2 deletions go-ooo/ooo_api/dex/modules/eth_uniswap_v2/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ var (
type DexModule struct {
ctx context.Context
graphNetworkApiKey string
minLiquidity uint64
minTxCount uint64
}

func NewDexModule(ctx context.Context, cfg *config.Config) DexModule {
return DexModule{
ctx: ctx,
graphNetworkApiKey: cfg.ApiKeys.GraphNetwork,
minLiquidity: cfg.Dexs.EthUniswapV2.MinReserveUsd,
minTxCount: cfg.Dexs.EthUniswapV2.MinTxCount,
}
}

Expand All @@ -45,11 +49,11 @@ func (d DexModule) Dex() string {
}

func (d DexModule) MinLiquidity() uint64 {
return MinLiquidity
return d.minLiquidity
}

func (d DexModule) MinTxCount() uint64 {
return MinTxCount
return d.minTxCount
}

func (d DexModule) GeneratePairsQuery(contractAddresses string) ([]byte, error) {
Expand Down
6 changes: 0 additions & 6 deletions go-ooo/ooo_api/dex/modules/eth_uniswap_v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ const (
GraphNetworkSubgraphId = "EYCKATKGBKLWvSfwvBjzfCBmGwYNdVkduYXVivCsLRFu"
Chain = types.ChainEth
Dex = "uniswap_v2"

// MinLiquidity - min liquidity a pair should have for the DEX pair search
MinLiquidity = 75000 // types.MinLiquidity

// MinTxCount - min tx count a pair should have for the DEX pair search
MinTxCount = types.MinTxCount
)

type GraphQlToken struct {
Expand Down
8 changes: 6 additions & 2 deletions go-ooo/ooo_api/dex/modules/eth_uniswap_v3/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ var (
type DexModule struct {
ctx context.Context
graphNetworkApiKey string
minLiquidity uint64
minTxCount uint64
}

func NewDexModule(ctx context.Context, cfg *config.Config) DexModule {
return DexModule{
ctx: ctx,
graphNetworkApiKey: cfg.ApiKeys.GraphNetwork,
minLiquidity: cfg.Dexs.EthUniswapV3.MinReserveUsd,
minTxCount: cfg.Dexs.EthUniswapV3.MinTxCount,
}
}

Expand All @@ -45,11 +49,11 @@ func (d DexModule) Dex() string {
}

func (d DexModule) MinLiquidity() uint64 {
return MinLiquidity
return d.minLiquidity
}

func (d DexModule) MinTxCount() uint64 {
return MinTxCount
return d.minTxCount
}

func (d DexModule) GeneratePairsQuery(contractAddresses string) ([]byte, error) {
Expand Down
6 changes: 0 additions & 6 deletions go-ooo/ooo_api/dex/modules/eth_uniswap_v3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ const (
GraphNetworkSubgraphId = "5zvR82QoaXYFyDEKLZ9t6v9adgnptxYpKpSbxtgVENFV"
Chain = types.ChainEth
Dex = "uniswap_v3"

// MinLiquidity - min liquidity a pair should have for the DEX pair search
MinLiquidity = 75000 // types.MinLiquidity

// MinTxCount - min tx count a pair should have for the DEX pair search
MinTxCount = types.MinTxCount
)

type GraphQlToken struct {
Expand Down
8 changes: 6 additions & 2 deletions go-ooo/ooo_api/dex/modules/polygon_pos_quickswap_v3/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ var (
type DexModule struct {
ctx context.Context
graphNetworkApiKey string
minLiquidity uint64
minTxCount uint64
}

func NewDexModule(ctx context.Context, cfg *config.Config) DexModule {
return DexModule{
ctx: ctx,
graphNetworkApiKey: cfg.ApiKeys.GraphNetwork,
minLiquidity: cfg.Dexs.PolygonPosQuickswapV3.MinReserveUsd,
minTxCount: cfg.Dexs.PolygonPosQuickswapV3.MinTxCount,
}
}

Expand All @@ -45,11 +49,11 @@ func (d DexModule) Dex() string {
}

func (d DexModule) MinLiquidity() uint64 {
return MinLiquidity
return d.minLiquidity
}

func (d DexModule) MinTxCount() uint64 {
return MinTxCount
return d.minTxCount
}

func (d DexModule) GeneratePairsQuery(contractAddresses string) ([]byte, error) {
Expand Down
6 changes: 0 additions & 6 deletions go-ooo/ooo_api/dex/modules/polygon_pos_quickswap_v3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ const (
GraphNetworkSubgraphId = "FqsRcH1XqSjqVx9GRTvEJe959aCbKrcyGgDWBrUkG24g"
Chain = types.ChainPolygon
Dex = "quickswap_v3"

// MinLiquidity - min liquidity a pair should have for the DEX pair search
MinLiquidity = types.MinLiquidity

// MinTxCount - min tx count a pair should have for the DEX pair search
MinTxCount = types.MinTxCount
)

type GraphQlToken struct {
Expand Down
Loading
Loading