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: External liquidity integration #412

Open
wants to merge 15 commits into
base: elys
Choose a base branch
from
24 changes: 18 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ type (
// CurrencyPair defines a price quote of the exchange rate for two different
// currencies and the supported providers for getting the exchange rate.
CurrencyPair struct {
Base string `mapstructure:"base" validate:"required"`
Quote string `mapstructure:"quote" validate:"required"`
PairAddress []PairAddressProvider `mapstructure:"pair_address_providers" validate:"dive"`
Providers []types.ProviderName `mapstructure:"providers" validate:"required,gt=0,dive,required"`
Base string `mapstructure:"base" validate:"required"`
Quote string `mapstructure:"quote" validate:"required"`
BaseProxy string `mapstructure:"base_proxy"`
QuoteProxy string `mapstructure:"quote_proxy"`
PairAddress []PairAddressProvider `mapstructure:"pair_address_providers" validate:"dive"`
Providers []types.ProviderName `mapstructure:"providers" validate:"required,gt=0,dive,required"`
PoolID uint64 `mapstructure:"pool_id"`
ExternLiquidityProvider types.ProviderName `mapstructure:"extern_liquidity_provider"`
CryptoCompareExchange string `mapstructure:"cryptocompare_exchange"`
}

PairAddressProvider struct {
Expand Down Expand Up @@ -237,6 +242,10 @@ func (c Config) ProviderPairs() map[types.ProviderName][]types.CurrencyPair {

for _, pair := range c.CurrencyPairs {
for _, provider := range pair.Providers {
poolID := uint64(0)
if provider == pair.ExternLiquidityProvider {
poolID = pair.PoolID
}
if len(pair.PairAddress) > 0 {
for _, uniPair := range pair.PairAddress {
if (uniPair.Provider == provider) && (uniPair.Address != "") {
Expand All @@ -249,8 +258,11 @@ func (c Config) ProviderPairs() map[types.ProviderName][]types.CurrencyPair {
}
} else {
providerPairs[provider] = append(providerPairs[provider], types.CurrencyPair{
Base: pair.Base,
Quote: pair.Quote,
Base: pair.Base,
Quote: pair.Quote,
BaseProxy: pair.BaseProxy,
QuoteProxy: pair.QuoteProxy,
PoolID: poolID,
})
}
}
Expand Down
6 changes: 5 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,12 @@ enabled = false
_, err = tmpFile.Write(content)
require.NoError(t, err)

_, err = config.ParseConfig(tmpFile.Name())
cfg, err := config.ParseConfig(tmpFile.Name())
require.NoError(t, err)

logger := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).Level(zerolog.InfoLevel).With().Timestamp().Logger()
err = config.CheckProviderMins(context.TODO(), logger, cfg)
require.EqualError(t, err, "must have at least 3 providers for ATOM")
}

func TestProviderWithAPIKey_Valid(t *testing.T) {
Expand Down
56 changes: 36 additions & 20 deletions config/supported_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,28 @@ var (
// SupportedProviders defines a lookup table of all the supported currency API
// providers and whether or not they require an API key to be passed in.
SupportedProviders = map[types.ProviderName]APIKeyRequired{
provider.ProviderKraken: false,
provider.ProviderBinance: false,
provider.ProviderBinanceUS: false,
provider.ProviderOsmosis: false,
provider.ProviderOkx: false,
provider.ProviderHuobi: false,
provider.ProviderGate: false,
provider.ProviderCoinbase: false,
provider.ProviderBitget: false,
provider.ProviderMexc: false,
provider.ProviderCrypto: false,
provider.ProviderPolygon: true,
provider.ProviderEthUniswap: false,
provider.ProviderEthCamelot: false,
provider.ProviderEthBalancer: false,
provider.ProviderEthPancake: false,
provider.ProviderEthCurve: false,
provider.ProviderKujira: false,
provider.ProviderAstroport: false,
provider.ProviderMock: false,
provider.ProviderKraken: false,
provider.ProviderBinance: false,
provider.ProviderBinanceUS: false,
provider.ProviderOsmosis: false,
provider.ProviderOkx: false,
provider.ProviderHuobi: false,
provider.ProviderGate: false,
provider.ProviderCoinbase: false,
provider.ProviderBitget: false,
provider.ProviderMexc: false,
provider.ProviderCrypto: false,
provider.ProviderPolygon: true,
provider.ProviderEthUniswap: false,
provider.ProviderEthCamelot: false,
provider.ProviderEthBalancer: false,
provider.ProviderEthPancake: false,
provider.ProviderEthCurve: false,
provider.ProviderKujira: false,
provider.ProviderAstroport: false,
provider.ProviderMock: false,
provider.ProviderCoinEx: false,
provider.ProviderCryptoCompare: true,
}

// SupportedConversions defines a lookup table for which currency pairs we
Expand All @@ -55,6 +57,20 @@ var (
{Base: "INJ", Quote: "USDT"}: {},
{Base: "TIA", Quote: "USDT"}: {},
{Base: "WSTETH", Quote: "WETH"}: {},

{Base: "MATIC", Quote: "USD"}: {},
{Base: "AVAX", Quote: "USD"}: {},
{Base: "BNB", Quote: "USD"}: {},

{Base: "ETH", Quote: "USDT"}: {},
{Base: "MATIC", Quote: "USDT"}: {},
{Base: "AVAX", Quote: "USDT"}: {},
{Base: "BNB", Quote: "USDT"}: {},

{Base: "ETH", Quote: "USDC"}: {},
{Base: "MATIC", Quote: "USDC"}: {},
{Base: "AVAX", Quote: "USDC"}: {},
{Base: "BNB", Quote: "USDC"}: {},
}

SupportedUniswapCurrencies = map[string]struct{}{
Expand Down
112 changes: 112 additions & 0 deletions elys-provider-config/currency-pairs.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
[[currency_pairs]]
base = "USDT"
providers = [
"coinbase",
"kraken",
"crypto",
]
quote = "USD"

[[currency_pairs]]
base = "USDC"
providers = [
"kraken",
]
quote = "USD"

[[currency_pairs]]
base = "ATOM"
base_proxy = "ATOM"
providers = [
"binance",
]
quote = "USDT"
quote_proxy = "USDC"
extern_liquidity_provider = "binance"
pool_id = 2

[[currency_pairs]]
base = "ATOM"
providers = [
"kraken",
]
quote = "USD"

[[currency_pairs]]
base = "OSMO"
providers = [
"osmosis",
]
quote = "ATOM"

[[currency_pairs]]
base = "OSMO"
providers = [
"crypto",
]
quote = "USD"

[[currency_pairs]]
base = "JUNO"
quote = "OSMO"
providers = [ "osmosis",]

[[currency_pairs]]
base = "BTC"
providers = [
"binance",
]
quote = "USDT"

[[currency_pairs]]
base = "ETH"
providers = [
"binance",
]
quote = "USDT"

[[currency_pairs]]
base = "ETH"
providers = [
"binance",
]
quote = "USDT"

[[currency_pairs]]
base = "ETH"
base_proxy = "ETH"
providers = [
"binance",
]
quote = "USDT"
quote_proxy = "USDC"

[[currency_pairs]]
base = "MATIC"
providers = [
"binance",
]
quote = "USDT"
quote_proxy = "USDC"


[[currency_pairs]]
base = "BNB"
providers = [
"binance",
]
quote = "USDC"

[[currency_pairs]]
base = "AVAX"
providers = [
"binance",
]
quote = "USDC"

[[currency_pairs]]
base = "AKT"
providers = [
"gate",
]
quote = "USDT"
139 changes: 139 additions & 0 deletions elys-provider-config/deviation-thresholds.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
[[deviation_thresholds]]
base = "MARS"
threshold = "1.5"

[[deviation_thresholds]]
base = "CMST"
threshold = "1.5"

[[deviation_thresholds]]
base = "USDT"
threshold = "1.5"

[[deviation_thresholds]]
base = "UMEE"
threshold = "1.5"

[[deviation_thresholds]]
base = "ATOM"
threshold = "1.5"

[[deviation_thresholds]]
base = "USDC"
threshold = "1.5"

[[deviation_thresholds]]
base = "CRO"
threshold = "1.5"

[[deviation_thresholds]]
base = "DAI"
threshold = "2"

[[deviation_thresholds]]
base = "ETH"
threshold = "2"

[[deviation_thresholds]]
base = "BTC"
threshold = "2"

[[deviation_thresholds]]
base = "BNB"
threshold = "2"

[[deviation_thresholds]]
base = "JUNO"
threshold = "2"

[[deviation_thresholds]]
base = "OSMO"
threshold = "2"

[[deviation_thresholds]]
base = "stATOM"
threshold = "2"

[[deviation_thresholds]]
base = "stOSMO"
threshold = "2"

[[deviation_thresholds]]
base = "IST"
threshold = "2"

[[deviation_thresholds]]
base = "AKT"
threshold = "1.5"

[[deviation_thresholds]]
base = "LUNA"
threshold = "1.5"

[[deviation_thresholds]]
base = "WAXL"
threshold = "1.5"

[[deviation_thresholds]]
base = "MATIC"
threshold = "1.5"

[[deviation_thresholds]]
base = "DOT"
threshold = "1.5"

[[deviation_thresholds]]
base = "stkATOM"
threshold = "1.5"

[[deviation_thresholds]]
base = "qATOM"
threshold = "1.5"

[[deviation_thresholds]]
base = "CBETH"
threshold = "1.5"

[[deviation_thresholds]]
base = "stJUNO"
threshold = "2"

[[deviation_thresholds]]
base = "USK"
threshold = "2"

[[deviation_thresholds]]
base = "stUMEE"
threshold = "2"

[[deviation_thresholds]]
base = "RETH"
threshold = "2"

[[deviation_thresholds]]
base = "LINK"
threshold = "2"

[[deviation_thresholds]]
base = "WETH"
threshold = "2"

[[deviation_thresholds]]
base = "WBTC"
threshold = "2"

[[deviation_thresholds]]
base = "ETH"
threshold = "2"

[[deviation_thresholds]]
base = "AVAX"
threshold = "2"

[[deviation_thresholds]]
base = "MATIC"
threshold = "2"

[[deviation_thresholds]]
base = "BNB"
threshold = "2"
Loading
Loading