From 94ce19fbcc8dd38253e9dbfc8436063e300c7be4 Mon Sep 17 00:00:00 2001 From: vic-en <31972210+vic-en@users.noreply.github.com> Date: Tue, 16 May 2023 00:01:24 -0500 Subject: [PATCH 1/5] refactor connectors --- ...cronos-base-uniswapish-connector.config.ts | 38 ------------------- .../cronos-base-uniswapish-connector.ts | 6 +-- src/connectors/connectors.request.ts | 1 + src/connectors/connectors.routes.ts | 19 ++++++++++ .../defikingdoms/defikingdoms.config.ts | 4 +- src/connectors/defira/defira.config.ts | 4 +- src/connectors/dexalot/dexalot.clob.config.ts | 2 + .../injective/injective.clob.config.ts | 2 + .../mad_meerkat/mad_meerkat.config.ts | 19 ++++++---- src/connectors/mad_meerkat/mad_meerkat.ts | 4 +- src/connectors/openocean/openocean.config.ts | 37 ++++-------------- .../pancakeswap/pancakeswap.config.ts | 35 ++++------------- src/connectors/pangolin/pangolin.config.ts | 35 ++++------------- src/connectors/perp/perp.config.ts | 4 +- src/connectors/quickswap/quickswap.config.ts | 33 ++++------------ src/connectors/ref/ref.config.ts | 29 ++++---------- src/connectors/sushiswap/sushiswap.config.ts | 4 +- src/connectors/traderjoe/traderjoe.config.ts | 35 ++++------------- src/connectors/uniswap/uniswap.config.ts | 4 +- src/connectors/vvs/vvs.config.ts | 16 ++++++-- src/connectors/vvs/vvs.ts | 4 +- src/connectors/xsswap/xsswap.config.ts | 33 ++++------------ src/connectors/zigzag/zigzag.config.ts | 4 +- src/network/network.utils.ts | 36 ++++++++++++++++++ 24 files changed, 159 insertions(+), 249 deletions(-) delete mode 100644 src/chains/cronos/cronos-base/cronos-base-uniswapish-connector.config.ts create mode 100644 src/network/network.utils.ts diff --git a/src/chains/cronos/cronos-base/cronos-base-uniswapish-connector.config.ts b/src/chains/cronos/cronos-base/cronos-base-uniswapish-connector.config.ts deleted file mode 100644 index 31f79330fb..0000000000 --- a/src/chains/cronos/cronos-base/cronos-base-uniswapish-connector.config.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { AvailableNetworks } from '../../../services/config-manager-types'; -import { ConfigManagerV2 } from '../../../services/config-manager-v2'; - -export namespace CronosBaseUniswapishConnectorConfig { - export interface NetworkConfig { - allowedSlippage: string; - gasLimitEstimate: number; - ttl: number; - routerAddress: (network: string) => string; - tradingTypes: Array; - availableNetworks: Array; - } - - export function buildConfig( - connector: string, - tradingTypes: Array - ): NetworkConfig { - const contractAddresses: any = ConfigManagerV2.getInstance().get( - `${connector}.contractAddresses` // todo: test - ); - const networks: Array = Object.keys(contractAddresses); - return { - allowedSlippage: ConfigManagerV2.getInstance().get( - `${connector}.allowedSlippage` - ), - gasLimitEstimate: ConfigManagerV2.getInstance().get( - `${connector}.gasLimitEstimate` - ), - ttl: ConfigManagerV2.getInstance().get(`${connector}.ttl`), - routerAddress: (network: string) => - ConfigManagerV2.getInstance().get( - `${connector}.contractAddresses.` + network + '.routerAddress' - ), - tradingTypes: tradingTypes, - availableNetworks: [{ chain: 'cronos', networks: networks }], - }; - } -} diff --git a/src/chains/cronos/cronos-base/cronos-base-uniswapish-connector.ts b/src/chains/cronos/cronos-base/cronos-base-uniswapish-connector.ts index ebd1912c25..faca099b4f 100644 --- a/src/chains/cronos/cronos-base/cronos-base-uniswapish-connector.ts +++ b/src/chains/cronos/cronos-base/cronos-base-uniswapish-connector.ts @@ -18,16 +18,16 @@ import { Transaction, Wallet, } from 'ethers'; -import { CronosBaseUniswapishConnectorConfig } from './cronos-base-uniswapish-connector.config'; import { Cronos } from '../cronos'; import { logger } from '../../../services/logger'; import { UniswapishPriceError } from '../../../services/error-handler'; import { isFractionString } from '../../../services/validators'; import { percentRegexp } from '../../../services/config-manager-v2'; +import { NetworkConfig } from '../../../network/network.utils'; export abstract class CronosBaseUniswapishConnector implements Uniswapish { private static _instances: { [name: string]: CronosBaseUniswapishConnector }; - private _config: CronosBaseUniswapishConnectorConfig.NetworkConfig; + private _config: NetworkConfig; private _cronos: Cronos; private _chainId: number; private _chain: string; @@ -71,7 +71,7 @@ export abstract class CronosBaseUniswapishConnector implements Uniswapish { return this._ready; } - protected abstract buildConfig(): CronosBaseUniswapishConnectorConfig.NetworkConfig; + protected abstract buildConfig(): NetworkConfig; /** * Router address. diff --git a/src/connectors/connectors.request.ts b/src/connectors/connectors.request.ts index 72cc9a5820..6ac895694a 100644 --- a/src/connectors/connectors.request.ts +++ b/src/connectors/connectors.request.ts @@ -4,6 +4,7 @@ export interface ConnectorsResponse { connectors: Array<{ name: string; trading_type: Array; + chainType: string; available_networks: Array; additional_spenders?: Array; additional_add_wallet_prompts?: Record; diff --git a/src/connectors/connectors.routes.ts b/src/connectors/connectors.routes.ts index 1ac2cfa018..36e3c45160 100644 --- a/src/connectors/connectors.routes.ts +++ b/src/connectors/connectors.routes.ts @@ -32,11 +32,13 @@ export namespace ConnectorsRoutes { { name: 'uniswap', trading_type: UniswapConfig.config.tradingTypes('swap'), + chainType: UniswapConfig.config.chainType, available_networks: UniswapConfig.config.availableNetworks, }, { name: 'uniswapLP', trading_type: UniswapConfig.config.tradingTypes('LP'), + chainType: UniswapConfig.config.chainType, available_networks: JSON.parse( JSON.stringify(UniswapConfig.config.availableNetworks) ), @@ -45,66 +47,79 @@ export namespace ConnectorsRoutes { { name: 'pangolin', trading_type: PangolinConfig.config.tradingTypes, + chainType: PangolinConfig.config.chainType, available_networks: PangolinConfig.config.availableNetworks, }, { name: 'openocean', trading_type: OpenoceanConfig.config.tradingTypes, + chainType: OpenoceanConfig.config.chainType, available_networks: OpenoceanConfig.config.availableNetworks, }, { name: 'quickswap', trading_type: QuickswapConfig.config.tradingTypes, + chainType: QuickswapConfig.config.chainType, available_networks: QuickswapConfig.config.availableNetworks, }, { name: 'perp', trading_type: PerpConfig.config.tradingTypes('perp'), + chainType: PerpConfig.config.chainType, available_networks: PerpConfig.config.availableNetworks, }, { name: 'sushiswap', trading_type: SushiswapConfig.config.tradingTypes, + chainType: SushiswapConfig.config.chainType, available_networks: SushiswapConfig.config.availableNetworks, }, { name: 'traderjoe', trading_type: TraderjoeConfig.config.tradingTypes, + chainType: TraderjoeConfig.config.chainType, available_networks: TraderjoeConfig.config.availableNetworks, }, { name: 'defikingdoms', trading_type: DefikingdomsConfig.config.tradingTypes, + chainType: DefikingdomsConfig.config.chainType, available_networks: DefikingdomsConfig.config.availableNetworks, }, { name: 'defira', trading_type: DefiraConfig.config.tradingTypes, + chainType: DefiraConfig.config.chainType, available_networks: DefiraConfig.config.availableNetworks, }, { name: 'mad_meerkat', trading_type: MadMeerkatConfig.config.tradingTypes, + chainType: MadMeerkatConfig.config.chainType, available_networks: MadMeerkatConfig.config.availableNetworks, }, { name: 'vvs', trading_type: VVSConfig.config.tradingTypes, + chainType: VVSConfig.config.chainType, available_networks: VVSConfig.config.availableNetworks, }, { name: 'ref', trading_type: RefConfig.config.tradingTypes, + chainType: RefConfig.config.chainType, available_networks: RefConfig.config.availableNetworks, }, { name: 'pancakeswap', trading_type: PancakeSwapConfig.config.tradingTypes, + chainType: PancakeSwapConfig.config.chainType, available_networks: PancakeSwapConfig.config.availableNetworks, }, { name: 'injective', trading_type: InjectiveCLOBConfig.config.tradingTypes('spot'), + chainType: InjectiveCLOBConfig.config.chainType, available_networks: InjectiveCLOBConfig.config.availableNetworks, additional_add_wallet_prompts: { accountId: @@ -114,6 +129,7 @@ export namespace ConnectorsRoutes { { name: 'injective_perpetual', trading_type: InjectiveCLOBConfig.config.tradingTypes('perp'), + chainType: InjectiveCLOBConfig.config.chainType, available_networks: InjectiveCLOBConfig.config.availableNetworks, additional_add_wallet_prompts: { accountId: @@ -123,11 +139,13 @@ export namespace ConnectorsRoutes { { name: 'xswap', trading_type: XsswapConfig.config.tradingTypes, + chainType: XsswapConfig.config.chainType, available_networks: XsswapConfig.config.availableNetworks, }, { name: 'dexalot', trading_type: DexalotCLOBConfig.config.tradingTypes('spot'), + chainType: DexalotCLOBConfig.config.chainType, available_networks: DexalotCLOBConfig.config.availableNetworks, additional_add_wallet_prompts: { api_key: @@ -137,6 +155,7 @@ export namespace ConnectorsRoutes { { name: 'zigzag', trading_type: ZigZagConfig.config.tradingTypes, + chainType: ZigZagConfig.config.chainType, available_networks: ZigZagConfig.config.availableNetworks, }, ], diff --git a/src/connectors/defikingdoms/defikingdoms.config.ts b/src/connectors/defikingdoms/defikingdoms.config.ts index 8e5d81b891..cd6ffd041c 100644 --- a/src/connectors/defikingdoms/defikingdoms.config.ts +++ b/src/connectors/defikingdoms/defikingdoms.config.ts @@ -7,6 +7,7 @@ export namespace DefikingdomsConfig { ttl: number; routerAddress: (network: string) => string; tradingTypes: Array; + chainType: string; availableNetworks: Array; } @@ -20,7 +21,8 @@ export namespace DefikingdomsConfig { ConfigManagerV2.getInstance().get( `defikingdoms.contractAddresses.${network}.routerAddress` ), - tradingTypes: ['EVM_AMM'], + tradingTypes: ['AMM'], + chainType: 'EVM', availableNetworks: [ { chain: 'harmony', diff --git a/src/connectors/defira/defira.config.ts b/src/connectors/defira/defira.config.ts index 739235add3..ae95e3910b 100644 --- a/src/connectors/defira/defira.config.ts +++ b/src/connectors/defira/defira.config.ts @@ -8,6 +8,7 @@ export namespace DefiraConfig { routerAddress: (network: string) => string; initCodeHash: (network: string) => string; tradingTypes: Array; + chainType: string; availableNetworks: Array; } @@ -25,7 +26,8 @@ export namespace DefiraConfig { ConfigManagerV2.getInstance().get( `defira.contractAddresses.${network}.initCodeHash` ), - tradingTypes: ['EVM_AMM'], + tradingTypes: ['AMM'], + chainType: 'EVM', availableNetworks: [ { chain: 'harmony', diff --git a/src/connectors/dexalot/dexalot.clob.config.ts b/src/connectors/dexalot/dexalot.clob.config.ts index c5051f4c43..66fdb5da57 100644 --- a/src/connectors/dexalot/dexalot.clob.config.ts +++ b/src/connectors/dexalot/dexalot.clob.config.ts @@ -5,6 +5,7 @@ export namespace DexalotCLOBConfig { export interface NetworkConfig { gasLimitEstimate: number; tradingTypes: (type: string) => Array; + chainType: string; availableNetworks: Array; addresses: (network: string) => { [name: string]: string }; maxLRUCacheInstances: number; @@ -18,6 +19,7 @@ export namespace DexalotCLOBConfig { tradingTypes: (type: string) => { return type === 'spot' ? ['CLOB_SPOT'] : ['CLOB_PERP']; }, + chainType: 'EVM', availableNetworks: [ { chain: 'avalanche', diff --git a/src/connectors/injective/injective.clob.config.ts b/src/connectors/injective/injective.clob.config.ts index 3ff3360fb9..aaed5efad2 100644 --- a/src/connectors/injective/injective.clob.config.ts +++ b/src/connectors/injective/injective.clob.config.ts @@ -5,6 +5,7 @@ export namespace InjectiveCLOBConfig { export interface NetworkConfig { gasLimitEstimate: number; tradingTypes: (type: string) => Array; + chainType: string; availableNetworks: Array; } @@ -15,6 +16,7 @@ export namespace InjectiveCLOBConfig { tradingTypes: (type: string) => { return type === 'spot' ? ['CLOB_SPOT'] : ['CLOB_PERP']; }, + chainType: 'INJECTIVE', availableNetworks: [ { chain: 'injective', diff --git a/src/connectors/mad_meerkat/mad_meerkat.config.ts b/src/connectors/mad_meerkat/mad_meerkat.config.ts index 735163ef90..f02e21e39f 100644 --- a/src/connectors/mad_meerkat/mad_meerkat.config.ts +++ b/src/connectors/mad_meerkat/mad_meerkat.config.ts @@ -1,10 +1,15 @@ -import { CronosBaseUniswapishConnectorConfig } from '../../chains/cronos/cronos-base/cronos-base-uniswapish-connector.config'; +import { buildConfig, NetworkConfig } from '../../network/network.utils'; +import { ConfigManagerV2 } from '../../services/config-manager-v2'; export namespace MadMeerkatConfig { - const tradingTypes = ['EVM_AMM']; - export const config: CronosBaseUniswapishConnectorConfig.NetworkConfig = - CronosBaseUniswapishConnectorConfig.buildConfig( - 'mad_meerkat', - tradingTypes - ); + const contractAddresses: any = ConfigManagerV2.getInstance().get( + 'mad_meerkat.contractAddresses' + ); + const networks: Array = Object.keys(contractAddresses); + export const config: NetworkConfig = buildConfig( + 'mad_meerkat', + ['EVM'], + [{ chain: 'cronos', networks }], + 'AMM' + ); } diff --git a/src/connectors/mad_meerkat/mad_meerkat.ts b/src/connectors/mad_meerkat/mad_meerkat.ts index d59bbd1061..53912d6756 100644 --- a/src/connectors/mad_meerkat/mad_meerkat.ts +++ b/src/connectors/mad_meerkat/mad_meerkat.ts @@ -19,16 +19,16 @@ import { CronosBaseUniswapishSDKProvider, CronosBaseUniswapishConnector, } from '../../chains/cronos/cronos-base/cronos-base-uniswapish-connector'; -import { CronosBaseUniswapishConnectorConfig } from '../../chains/cronos/cronos-base/cronos-base-uniswapish-connector.config'; import routerAbi from './abi.json'; import { MadMeerkatConfig } from './mad_meerkat.config'; +import { NetworkConfig } from '../../network/network.utils'; export class MadMeerkat extends CronosBaseUniswapishConnector { constructor(chain: string, network: string) { const sdkProvider = new MadMeerkatSDKProvider(); super(sdkProvider, routerAbi, chain, network); } - protected buildConfig(): CronosBaseUniswapishConnectorConfig.NetworkConfig { + protected buildConfig(): NetworkConfig { return MadMeerkatConfig.config; } } diff --git a/src/connectors/openocean/openocean.config.ts b/src/connectors/openocean/openocean.config.ts index 18fd2b843b..9b9526f883 100644 --- a/src/connectors/openocean/openocean.config.ts +++ b/src/connectors/openocean/openocean.config.ts @@ -1,34 +1,10 @@ -import { ConfigManagerV2 } from '../../services/config-manager-v2'; -import { AvailableNetworks } from '../../services/config-manager-types'; +import { buildConfig, NetworkConfig } from '../../network/network.utils'; export namespace OpenoceanConfig { - export interface NetworkConfig { - allowedSlippage: string; - gasLimitEstimate: number; - ttl: number; - routerAddress: (chain: string, network: string) => string; - tradingTypes: Array; - availableNetworks: Array; - } - - export const config: NetworkConfig = { - allowedSlippage: ConfigManagerV2.getInstance().get( - 'openocean.allowedSlippage' - ), - gasLimitEstimate: ConfigManagerV2.getInstance().get( - `openocean.gasLimitEstimate` - ), - ttl: ConfigManagerV2.getInstance().get('openocean.ttl'), - routerAddress: (chain: string, network: string) => - ConfigManagerV2.getInstance().get( - 'openocean.contractAddresses.' + - chain + - '.' + - network + - '.routerAddress' - ), - tradingTypes: ['EVM_AMM'], - availableNetworks: [ + export const config: NetworkConfig = buildConfig( + 'openocean', + ['AMM'], + [ { chain: 'avalanche', networks: ['avalanche'] }, { chain: 'ethereum', networks: ['mainnet', 'arbitrum_one', 'optimism'] }, { chain: 'polygon', networks: ['mainnet'] }, @@ -36,5 +12,6 @@ export namespace OpenoceanConfig { { chain: 'binance-smart-chain', networks: ['mainnet'] }, { chain: 'cronos', networks: ['mainnet'] }, ], - }; + 'EVM' + ); } diff --git a/src/connectors/pancakeswap/pancakeswap.config.ts b/src/connectors/pancakeswap/pancakeswap.config.ts index 599fbb2bd9..baa01e62b1 100644 --- a/src/connectors/pancakeswap/pancakeswap.config.ts +++ b/src/connectors/pancakeswap/pancakeswap.config.ts @@ -1,31 +1,10 @@ -import { ConfigManagerV2 } from '../../services/config-manager-v2'; -import { AvailableNetworks } from '../../services/config-manager-types'; +import { buildConfig, NetworkConfig } from '../../network/network.utils'; export namespace PancakeSwapConfig { - export interface ExchangeConfig { - allowedSlippage: string; - gasLimitEstimate: number; - ttl: number; - routerAddress: (network: string) => string; - tradingTypes: Array; - availableNetworks: Array; - } - - export const config: ExchangeConfig = { - allowedSlippage: ConfigManagerV2.getInstance().get( - 'pancakeswap.allowedSlippage' - ), - gasLimitEstimate: ConfigManagerV2.getInstance().get( - `pancakeswap.gasLimitEstimate` - ), - ttl: ConfigManagerV2.getInstance().get('pancakeswap.ttl'), - routerAddress: (network: string) => - ConfigManagerV2.getInstance().get( - 'pancakeswap.contractAddresses.' + network + '.routerAddress' - ), - tradingTypes: ['EVM_AMM'], - availableNetworks: [ - { chain: 'binance-smart-chain', networks: ['mainnet', 'testnet'] }, - ], - }; + export const config: NetworkConfig = buildConfig( + 'pancakeswap', + ['AMM'], + [{ chain: 'binance-smart-chain', networks: ['mainnet', 'testnet'] }], + 'EVM' + ); } diff --git a/src/connectors/pangolin/pangolin.config.ts b/src/connectors/pangolin/pangolin.config.ts index 13aa570ef7..2312b6d57f 100644 --- a/src/connectors/pangolin/pangolin.config.ts +++ b/src/connectors/pangolin/pangolin.config.ts @@ -1,31 +1,10 @@ -import { ConfigManagerV2 } from '../../services/config-manager-v2'; -import { AvailableNetworks } from '../../services/config-manager-types'; +import { buildConfig, NetworkConfig } from '../../network/network.utils'; export namespace PangolinConfig { - export interface NetworkConfig { - allowedSlippage: string; - gasLimitEstimate: number; - ttl: number; - routerAddress: (network: string) => string; - tradingTypes: Array; - availableNetworks: Array; - } - - export const config: NetworkConfig = { - allowedSlippage: ConfigManagerV2.getInstance().get( - 'pangolin.allowedSlippage' - ), - gasLimitEstimate: ConfigManagerV2.getInstance().get( - `pangolin.gasLimitEstimate` - ), - ttl: ConfigManagerV2.getInstance().get('pangolin.ttl'), - routerAddress: (network: string) => - ConfigManagerV2.getInstance().get( - 'pangolin.contractAddresses.' + network + '.routerAddress' - ), - tradingTypes: ['EVM_AMM'], - availableNetworks: [ - { chain: 'avalanche', networks: ['avalanche', 'fuji'] }, - ], - }; + export const config: NetworkConfig = buildConfig( + 'pangolin', + ['AMM'], + [{ chain: 'avalanche', networks: ['avalanche', 'fuji'] }], + 'EVM' + ); } diff --git a/src/connectors/perp/perp.config.ts b/src/connectors/perp/perp.config.ts index 7dfdaba74c..91d14aebdc 100644 --- a/src/connectors/perp/perp.config.ts +++ b/src/connectors/perp/perp.config.ts @@ -5,6 +5,7 @@ export namespace PerpConfig { allowedSlippage: string; ttl: number; tradingTypes: (type: string) => Array; + chainType: string; availableNetworks: Array; } @@ -12,7 +13,8 @@ export namespace PerpConfig { allowedSlippage: ConfigManagerV2.getInstance().get(`perp.allowedSlippage`), ttl: ConfigManagerV2.getInstance().get(`perp.versions.ttl`), tradingTypes: (type: string) => - type === 'perp' ? ['EVM_Perpetual'] : ['EVM_AMM_LP'], + type === 'perp' ? ['Perpetual'] : ['AMM_LP'], + chainType: 'EVM', availableNetworks: [{ chain: 'ethereum', networks: ['optimism'] }], }; } diff --git a/src/connectors/quickswap/quickswap.config.ts b/src/connectors/quickswap/quickswap.config.ts index 9af5ca8938..b52195c8da 100644 --- a/src/connectors/quickswap/quickswap.config.ts +++ b/src/connectors/quickswap/quickswap.config.ts @@ -1,29 +1,10 @@ -import { ConfigManagerV2 } from '../../services/config-manager-v2'; -import { AvailableNetworks } from '../../services/config-manager-types'; +import { buildConfig, NetworkConfig } from '../../network/network.utils'; export namespace QuickswapConfig { - export interface NetworkConfig { - allowedSlippage: string; - gasLimitEstimate: number; - ttl: number; - routerAddress: (network: string) => string; - tradingTypes: Array; - availableNetworks: Array; - } - - export const config: NetworkConfig = { - allowedSlippage: ConfigManagerV2.getInstance().get( - 'quickswap.allowedSlippage' - ), - gasLimitEstimate: ConfigManagerV2.getInstance().get( - 'quickswap.gasLimitEstimate' - ), - ttl: ConfigManagerV2.getInstance().get('quickswap.ttl'), - routerAddress: (network: string) => - ConfigManagerV2.getInstance().get( - 'quickswap.contractAddresses.' + network + '.routerAddress' - ), - tradingTypes: ['EVM_AMM'], - availableNetworks: [{ chain: 'polygon', networks: ['mainnet', 'mumbai'] }], - }; + export const config: NetworkConfig = buildConfig( + 'quickswap', + ['AMM'], + [{ chain: 'polygon', networks: ['mainnet', 'mumbai'] }], + 'EVM' + ); } diff --git a/src/connectors/ref/ref.config.ts b/src/connectors/ref/ref.config.ts index aa7c3d93db..a27fd5b58d 100644 --- a/src/connectors/ref/ref.config.ts +++ b/src/connectors/ref/ref.config.ts @@ -1,25 +1,11 @@ import { ConfigManagerV2 } from '../../services/config-manager-v2'; -import { AvailableNetworks } from '../../services/config-manager-types'; -export namespace RefConfig { - export interface NetworkConfig { - allowedSlippage: string; - gasLimitEstimate: number; - ttl: number; - routerAddress: (network: string) => string; - tradingTypes: Array; - availableNetworks: Array; - } +import { buildConfig, NetworkConfig } from '../../network/network.utils'; - export const config: NetworkConfig = { - allowedSlippage: ConfigManagerV2.getInstance().get(`ref.allowedSlippage`), - gasLimitEstimate: ConfigManagerV2.getInstance().get(`ref.gasLimitEstimate`), - ttl: ConfigManagerV2.getInstance().get(`ref.ttl`), - routerAddress: (network: string) => - ConfigManagerV2.getInstance().get( - `ref.contractAddresses.${network}.routerAddress` - ), - tradingTypes: ['NEAR_AMM'], - availableNetworks: [ +export namespace RefConfig { + export const config: NetworkConfig = buildConfig( + 'ref', + ['AMM'], + [ { chain: 'near', networks: Object.keys( @@ -31,5 +17,6 @@ export namespace RefConfig { ), }, ], - }; + 'NEAR' + ); } diff --git a/src/connectors/sushiswap/sushiswap.config.ts b/src/connectors/sushiswap/sushiswap.config.ts index 222240d4d8..01366bdc6b 100644 --- a/src/connectors/sushiswap/sushiswap.config.ts +++ b/src/connectors/sushiswap/sushiswap.config.ts @@ -8,6 +8,7 @@ export namespace SushiswapConfig { ttl: number; sushiswapRouterAddress: (chain: string, network: string) => string; tradingTypes: Array; + chainType: string; availableNetworks: Array; } @@ -27,7 +28,8 @@ export namespace SushiswapConfig { network + '.sushiswapRouterAddress' ), - tradingTypes: ['EVM_AMM'], + tradingTypes: ['AMM'], + chainType: 'EVM', availableNetworks: [ { chain: 'ethereum', diff --git a/src/connectors/traderjoe/traderjoe.config.ts b/src/connectors/traderjoe/traderjoe.config.ts index 18d5803a09..0610f41b0c 100644 --- a/src/connectors/traderjoe/traderjoe.config.ts +++ b/src/connectors/traderjoe/traderjoe.config.ts @@ -1,31 +1,10 @@ -import { ConfigManagerV2 } from '../../services/config-manager-v2'; -import { AvailableNetworks } from '../../services/config-manager-types'; +import { buildConfig, NetworkConfig } from '../../network/network.utils'; export namespace TraderjoeConfig { - export interface NetworkConfig { - allowedSlippage: string; - gasLimitEstimate: number; - ttl: number; - routerAddress: (network: string) => string; - tradingTypes: Array; - availableNetworks: Array; - } - - export const config: NetworkConfig = { - allowedSlippage: ConfigManagerV2.getInstance().get( - 'traderjoe.allowedSlippage' - ), - gasLimitEstimate: ConfigManagerV2.getInstance().get( - 'traderjoe.gasLimitEstimate' - ), - ttl: ConfigManagerV2.getInstance().get('traderjoe.ttl'), - routerAddress: (network: string) => - ConfigManagerV2.getInstance().get( - 'traderjoe.contractAddresses.' + network + '.routerAddress' - ), - tradingTypes: ['EVM_AMM'], - availableNetworks: [ - { chain: 'avalanche', networks: ['avalanche', 'fuji'] }, - ], - }; + export const config: NetworkConfig = buildConfig( + 'traderjoe', + ['AMM'], + [{ chain: 'avalanche', networks: ['avalanche', 'fuji'] }], + 'EVM' + ); } diff --git a/src/connectors/uniswap/uniswap.config.ts b/src/connectors/uniswap/uniswap.config.ts index 320d496eed..e3b5d104ba 100644 --- a/src/connectors/uniswap/uniswap.config.ts +++ b/src/connectors/uniswap/uniswap.config.ts @@ -9,6 +9,7 @@ export namespace UniswapConfig { uniswapV3SmartOrderRouterAddress: (network: string) => string; uniswapV3NftManagerAddress: (network: string) => string; tradingTypes: (type: string) => Array; + chainType: string; availableNetworks: Array; } @@ -30,8 +31,9 @@ export namespace UniswapConfig { `uniswap.contractAddresses.${network}.uniswapV3NftManagerAddress` ), tradingTypes: (type: string) => { - return type === 'swap' ? ['EVM_AMM'] : ['EVM_AMM_LP']; + return type === 'swap' ? ['AMM'] : ['AMM_LP']; }, + chainType: 'EVM', availableNetworks: [ { chain: 'ethereum', diff --git a/src/connectors/vvs/vvs.config.ts b/src/connectors/vvs/vvs.config.ts index 4993a9cd36..3c30bfc9e9 100644 --- a/src/connectors/vvs/vvs.config.ts +++ b/src/connectors/vvs/vvs.config.ts @@ -1,7 +1,15 @@ -import { CronosBaseUniswapishConnectorConfig } from '../../chains/cronos/cronos-base/cronos-base-uniswapish-connector.config'; +import { buildConfig, NetworkConfig } from '../../network/network.utils'; +import { ConfigManagerV2 } from '../../services/config-manager-v2'; export namespace VVSConfig { - const tradingTypes = ['EVM_AMM']; - export const config: CronosBaseUniswapishConnectorConfig.NetworkConfig = - CronosBaseUniswapishConnectorConfig.buildConfig('vvs', tradingTypes); + const contractAddresses: any = ConfigManagerV2.getInstance().get( + 'vvs.contractAddresses' + ); + const networks: Array = Object.keys(contractAddresses); + export const config: NetworkConfig = buildConfig( + 'vvs', + ['AMM'], + [{ chain: 'cronos', networks }], + 'EVM' + ); } diff --git a/src/connectors/vvs/vvs.ts b/src/connectors/vvs/vvs.ts index 45537c02e6..2b190d9b06 100644 --- a/src/connectors/vvs/vvs.ts +++ b/src/connectors/vvs/vvs.ts @@ -19,16 +19,16 @@ import { CronosBaseUniswapishSDKProvider, CronosBaseUniswapishConnector, } from '../../chains/cronos/cronos-base/cronos-base-uniswapish-connector'; -import { CronosBaseUniswapishConnectorConfig } from '../../chains/cronos/cronos-base/cronos-base-uniswapish-connector.config'; import routerAbi from './abi.json'; import { VVSConfig } from './vvs.config'; +import { NetworkConfig } from '../../network/network.utils'; export class VVSConnector extends CronosBaseUniswapishConnector { constructor(chain: string, network: string) { const sdkProvider = new VVSSDKProvider(); super(sdkProvider, routerAbi, chain, network); } - protected buildConfig(): CronosBaseUniswapishConnectorConfig.NetworkConfig { + protected buildConfig(): NetworkConfig { return VVSConfig.config; } } diff --git a/src/connectors/xsswap/xsswap.config.ts b/src/connectors/xsswap/xsswap.config.ts index 72859097f7..ac1608f6bd 100644 --- a/src/connectors/xsswap/xsswap.config.ts +++ b/src/connectors/xsswap/xsswap.config.ts @@ -1,29 +1,10 @@ -import { AvailableNetworks } from '../../services/config-manager-types'; -import { ConfigManagerV2 } from '../../services/config-manager-v2'; +import { buildConfig, NetworkConfig } from '../../network/network.utils'; export namespace XsswapConfig { - export interface NetworkConfig { - allowedSlippage: string; - gasLimitEstimate: number; - ttl: number; - routerAddress: (network: string) => string; - tradingTypes: Array; - availableNetworks: Array; - } - - export const config: NetworkConfig = { - allowedSlippage: ConfigManagerV2.getInstance().get( - 'xsswap.allowedSlippage' - ), - gasLimitEstimate: ConfigManagerV2.getInstance().get( - 'xsswap.gasLimitEstimate' - ), - ttl: ConfigManagerV2.getInstance().get('xsswap.ttl'), - routerAddress: (network: string) => - ConfigManagerV2.getInstance().get( - 'xsswap.contractAddresses.' + network + '.routerAddress' - ), - tradingTypes: ['EVM_AMM'], - availableNetworks: [{ chain: 'xdc', networks: ['xinfin', 'apothem'] }], - }; + export const config: NetworkConfig = buildConfig( + 'xsswap', + ['AMM'], + [{ chain: 'xdc', networks: ['xinfin', 'apothem'] }], + 'EVM' + ); } diff --git a/src/connectors/zigzag/zigzag.config.ts b/src/connectors/zigzag/zigzag.config.ts index d97ee9cd74..f6f7f465d9 100644 --- a/src/connectors/zigzag/zigzag.config.ts +++ b/src/connectors/zigzag/zigzag.config.ts @@ -5,6 +5,7 @@ export namespace ZigZagConfig { export interface NetworkConfig { contractAddress: (network: string) => string; tradingTypes: Array; + chainType: string; availableNetworks: Array; } @@ -13,7 +14,8 @@ export namespace ZigZagConfig { ConfigManagerV2.getInstance().get( `zigzag.networks.${network}.contractAddress` ), - tradingTypes: ['EVM_AMM'], + tradingTypes: ['AMM'], + chainType: 'EVM', availableNetworks: [ { chain: 'ethereum', diff --git a/src/network/network.utils.ts b/src/network/network.utils.ts new file mode 100644 index 0000000000..f9b48fce1b --- /dev/null +++ b/src/network/network.utils.ts @@ -0,0 +1,36 @@ +import { AvailableNetworks } from '../services/config-manager-types'; +import { ConfigManagerV2 } from '../services/config-manager-v2'; + +export interface NetworkConfig { + allowedSlippage: string; + gasLimitEstimate: number; + ttl: number; + routerAddress: (network: string) => string; + tradingTypes: Array; + chainType: string; + availableNetworks: Array; +} + +export function buildConfig( + connector: string, + tradingTypes: Array, + availableNetworks: Array, + chainType: string = 'EVM' +): NetworkConfig { + return { + allowedSlippage: ConfigManagerV2.getInstance().get( + `${connector}.allowedSlippage` + ), + gasLimitEstimate: ConfigManagerV2.getInstance().get( + `${connector}.gasLimitEstimate` + ), + ttl: ConfigManagerV2.getInstance().get(`${connector}.ttl`), + routerAddress: (network: string) => + ConfigManagerV2.getInstance().get( + `${connector}.contractAddresses.` + network + '.routerAddress' + ), + tradingTypes: tradingTypes, + chainType: chainType, + availableNetworks, + }; +} From 881851967d8c71b87bc4009abed518e9b57d4582 Mon Sep 17 00:00:00 2001 From: vic-en <31972210+vic-en@users.noreply.github.com> Date: Tue, 16 May 2023 00:09:46 -0500 Subject: [PATCH 2/5] revert changes to opeanocean --- src/connectors/openocean/openocean.config.ts | 39 ++++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/connectors/openocean/openocean.config.ts b/src/connectors/openocean/openocean.config.ts index 9b9526f883..612dcc94cc 100644 --- a/src/connectors/openocean/openocean.config.ts +++ b/src/connectors/openocean/openocean.config.ts @@ -1,10 +1,36 @@ -import { buildConfig, NetworkConfig } from '../../network/network.utils'; +import { AvailableNetworks } from '../../services/config-manager-types'; +import { ConfigManagerV2 } from '../../services/config-manager-v2'; export namespace OpenoceanConfig { - export const config: NetworkConfig = buildConfig( - 'openocean', - ['AMM'], - [ + export interface NetworkConfig { + allowedSlippage: string; + gasLimitEstimate: number; + ttl: number; + routerAddress: (chain: string, network: string) => string; + tradingTypes: Array; + chainType: string; + availableNetworks: Array; + } + + export const config: NetworkConfig = { + allowedSlippage: ConfigManagerV2.getInstance().get( + 'openocean.allowedSlippage' + ), + gasLimitEstimate: ConfigManagerV2.getInstance().get( + `openocean.gasLimitEstimate` + ), + ttl: ConfigManagerV2.getInstance().get('openocean.ttl'), + routerAddress: (chain: string, network: string) => + ConfigManagerV2.getInstance().get( + 'openocean.contractAddresses.' + + chain + + '.' + + network + + '.routerAddress' + ), + tradingTypes: ['AMM'], + chainType: 'EVM', + availableNetworks: [ { chain: 'avalanche', networks: ['avalanche'] }, { chain: 'ethereum', networks: ['mainnet', 'arbitrum_one', 'optimism'] }, { chain: 'polygon', networks: ['mainnet'] }, @@ -12,6 +38,5 @@ export namespace OpenoceanConfig { { chain: 'binance-smart-chain', networks: ['mainnet'] }, { chain: 'cronos', networks: ['mainnet'] }, ], - 'EVM' - ); + }; } From 9a4456ad8299b97f8a4b683f2eeda8fd584878f3 Mon Sep 17 00:00:00 2001 From: vic-en <31972210+vic-en@users.noreply.github.com> Date: Tue, 16 May 2023 00:30:07 -0500 Subject: [PATCH 3/5] update perp --- src/connectors/perp/perp.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connectors/perp/perp.config.ts b/src/connectors/perp/perp.config.ts index 91d14aebdc..96cb197369 100644 --- a/src/connectors/perp/perp.config.ts +++ b/src/connectors/perp/perp.config.ts @@ -13,7 +13,7 @@ export namespace PerpConfig { allowedSlippage: ConfigManagerV2.getInstance().get(`perp.allowedSlippage`), ttl: ConfigManagerV2.getInstance().get(`perp.versions.ttl`), tradingTypes: (type: string) => - type === 'perp' ? ['Perpetual'] : ['AMM_LP'], + type === 'perp' ? ['AMM_Perpetual'] : ['AMM_LP'], chainType: 'EVM', availableNetworks: [{ chain: 'ethereum', networks: ['optimism'] }], }; From 0a6081554f42d2877d26082d5a631af10aa780dd Mon Sep 17 00:00:00 2001 From: vic-en <31972210+vic-en@users.noreply.github.com> Date: Tue, 16 May 2023 00:56:49 -0500 Subject: [PATCH 4/5] rename chainType to chain_type --- src/connectors/connectors.request.ts | 2 +- src/connectors/connectors.routes.ts | 38 ++++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/connectors/connectors.request.ts b/src/connectors/connectors.request.ts index 6ac895694a..614d007c6a 100644 --- a/src/connectors/connectors.request.ts +++ b/src/connectors/connectors.request.ts @@ -4,7 +4,7 @@ export interface ConnectorsResponse { connectors: Array<{ name: string; trading_type: Array; - chainType: string; + chain_type: string; available_networks: Array; additional_spenders?: Array; additional_add_wallet_prompts?: Record; diff --git a/src/connectors/connectors.routes.ts b/src/connectors/connectors.routes.ts index 36e3c45160..93ea2f46f2 100644 --- a/src/connectors/connectors.routes.ts +++ b/src/connectors/connectors.routes.ts @@ -32,13 +32,13 @@ export namespace ConnectorsRoutes { { name: 'uniswap', trading_type: UniswapConfig.config.tradingTypes('swap'), - chainType: UniswapConfig.config.chainType, + chain_type: UniswapConfig.config.chainType, available_networks: UniswapConfig.config.availableNetworks, }, { name: 'uniswapLP', trading_type: UniswapConfig.config.tradingTypes('LP'), - chainType: UniswapConfig.config.chainType, + chain_type: UniswapConfig.config.chainType, available_networks: JSON.parse( JSON.stringify(UniswapConfig.config.availableNetworks) ), @@ -47,79 +47,79 @@ export namespace ConnectorsRoutes { { name: 'pangolin', trading_type: PangolinConfig.config.tradingTypes, - chainType: PangolinConfig.config.chainType, + chain_type: PangolinConfig.config.chainType, available_networks: PangolinConfig.config.availableNetworks, }, { name: 'openocean', trading_type: OpenoceanConfig.config.tradingTypes, - chainType: OpenoceanConfig.config.chainType, + chain_type: OpenoceanConfig.config.chainType, available_networks: OpenoceanConfig.config.availableNetworks, }, { name: 'quickswap', trading_type: QuickswapConfig.config.tradingTypes, - chainType: QuickswapConfig.config.chainType, + chain_type: QuickswapConfig.config.chainType, available_networks: QuickswapConfig.config.availableNetworks, }, { name: 'perp', trading_type: PerpConfig.config.tradingTypes('perp'), - chainType: PerpConfig.config.chainType, + chain_type: PerpConfig.config.chainType, available_networks: PerpConfig.config.availableNetworks, }, { name: 'sushiswap', trading_type: SushiswapConfig.config.tradingTypes, - chainType: SushiswapConfig.config.chainType, + chain_type: SushiswapConfig.config.chainType, available_networks: SushiswapConfig.config.availableNetworks, }, { name: 'traderjoe', trading_type: TraderjoeConfig.config.tradingTypes, - chainType: TraderjoeConfig.config.chainType, + chain_type: TraderjoeConfig.config.chainType, available_networks: TraderjoeConfig.config.availableNetworks, }, { name: 'defikingdoms', trading_type: DefikingdomsConfig.config.tradingTypes, - chainType: DefikingdomsConfig.config.chainType, + chain_type: DefikingdomsConfig.config.chainType, available_networks: DefikingdomsConfig.config.availableNetworks, }, { name: 'defira', trading_type: DefiraConfig.config.tradingTypes, - chainType: DefiraConfig.config.chainType, + chain_type: DefiraConfig.config.chainType, available_networks: DefiraConfig.config.availableNetworks, }, { name: 'mad_meerkat', trading_type: MadMeerkatConfig.config.tradingTypes, - chainType: MadMeerkatConfig.config.chainType, + chain_type: MadMeerkatConfig.config.chainType, available_networks: MadMeerkatConfig.config.availableNetworks, }, { name: 'vvs', trading_type: VVSConfig.config.tradingTypes, - chainType: VVSConfig.config.chainType, + chain_type: VVSConfig.config.chainType, available_networks: VVSConfig.config.availableNetworks, }, { name: 'ref', trading_type: RefConfig.config.tradingTypes, - chainType: RefConfig.config.chainType, + chain_type: RefConfig.config.chainType, available_networks: RefConfig.config.availableNetworks, }, { name: 'pancakeswap', trading_type: PancakeSwapConfig.config.tradingTypes, - chainType: PancakeSwapConfig.config.chainType, + chain_type: PancakeSwapConfig.config.chainType, available_networks: PancakeSwapConfig.config.availableNetworks, }, { name: 'injective', trading_type: InjectiveCLOBConfig.config.tradingTypes('spot'), - chainType: InjectiveCLOBConfig.config.chainType, + chain_type: InjectiveCLOBConfig.config.chainType, available_networks: InjectiveCLOBConfig.config.availableNetworks, additional_add_wallet_prompts: { accountId: @@ -129,7 +129,7 @@ export namespace ConnectorsRoutes { { name: 'injective_perpetual', trading_type: InjectiveCLOBConfig.config.tradingTypes('perp'), - chainType: InjectiveCLOBConfig.config.chainType, + chain_type: InjectiveCLOBConfig.config.chainType, available_networks: InjectiveCLOBConfig.config.availableNetworks, additional_add_wallet_prompts: { accountId: @@ -139,13 +139,13 @@ export namespace ConnectorsRoutes { { name: 'xswap', trading_type: XsswapConfig.config.tradingTypes, - chainType: XsswapConfig.config.chainType, + chain_type: XsswapConfig.config.chainType, available_networks: XsswapConfig.config.availableNetworks, }, { name: 'dexalot', trading_type: DexalotCLOBConfig.config.tradingTypes('spot'), - chainType: DexalotCLOBConfig.config.chainType, + chain_type: DexalotCLOBConfig.config.chainType, available_networks: DexalotCLOBConfig.config.availableNetworks, additional_add_wallet_prompts: { api_key: @@ -155,7 +155,7 @@ export namespace ConnectorsRoutes { { name: 'zigzag', trading_type: ZigZagConfig.config.tradingTypes, - chainType: ZigZagConfig.config.chainType, + chain_type: ZigZagConfig.config.chainType, available_networks: ZigZagConfig.config.availableNetworks, }, ], From a2440881ed750fe47fe2e704ef8e27db160d2d16 Mon Sep 17 00:00:00 2001 From: vic-en <31972210+vic-en@users.noreply.github.com> Date: Tue, 16 May 2023 02:18:03 -0500 Subject: [PATCH 5/5] update mmf --- src/connectors/mad_meerkat/mad_meerkat.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connectors/mad_meerkat/mad_meerkat.config.ts b/src/connectors/mad_meerkat/mad_meerkat.config.ts index f02e21e39f..8ab36dca87 100644 --- a/src/connectors/mad_meerkat/mad_meerkat.config.ts +++ b/src/connectors/mad_meerkat/mad_meerkat.config.ts @@ -8,8 +8,8 @@ export namespace MadMeerkatConfig { const networks: Array = Object.keys(contractAddresses); export const config: NetworkConfig = buildConfig( 'mad_meerkat', - ['EVM'], + ['AMM'], [{ chain: 'cronos', networks }], - 'AMM' + 'EVM' ); }