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

new dexes #11

Merged
merged 18 commits into from
May 6, 2024
4 changes: 3 additions & 1 deletion .github/workflows/rain-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ jobs:
run: nix develop -c pnpm exec turbo run check --filter=./packages/sushi

- name: Test ./packages/sushi
run: nix develop -c pnpm exec turbo run test --filter=./packages/sushi
run: |
nix develop -c pnpm exec turbo run test --filter=./packages/sushi
nix develop -c pnpm exec turbo run test --filter=./protocols/route-processor
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ exports
# cache
cache
mem-cache
test-cache

# generated
generated
Expand Down
100 changes: 84 additions & 16 deletions packages/sushi/src/router/data-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,54 @@ import { ChainId, TestnetChainId } from '../chain/index.js'
import { publicClientConfig } from '../config/index.js'
import { Type } from '../currency/index.js'
import { ApeSwapProvider } from './liquidity-providers/ApeSwap.js'
import { BaseSwapProvider } from './liquidity-providers/BaseSwap.js'
import { BiswapProvider } from './liquidity-providers/Biswap.js'
import { BlastDEXProvider } from './liquidity-providers/BlastDEX.js'
import { BlazeSwapProvider } from './liquidity-providers/BlazeSwap.js'
import { CamelotProvider } from './liquidity-providers/Camelot.js'
import { CurveProvider } from './liquidity-providers/CurveProvider.js'
import { DfynProvider } from './liquidity-providers/Dfyn.js'
import { DovishV3Provider } from './liquidity-providers/DovishV3.js'
import { DyorV2Provider } from './liquidity-providers/DyorV2.js'
import { ElkProvider } from './liquidity-providers/Elk.js'
import { EnosysProvider } from './liquidity-providers/Enosys.js'
import { HoneySwapProvider } from './liquidity-providers/HoneySwap.js'
import { HyperBlastProvider } from './liquidity-providers/HyperBlast.js'
import { JetSwapProvider } from './liquidity-providers/JetSwap.js'
import { KinetixV2Provider } from './liquidity-providers/KinetixV2.js'
import { KinetixV3Provider } from './liquidity-providers/KinetixV3.js'
import { LaserSwapV2Provider } from './liquidity-providers/LaserSwap.js'
import {
LiquidityProvider,
LiquidityProviders,
} from './liquidity-providers/LiquidityProvider.js'
import { MonoswapV2Provider } from './liquidity-providers/MonoSwapV2.js'
import { MonoswapV3Provider } from './liquidity-providers/MonoSwapV3.js'
import { NativeWrapProvider } from './liquidity-providers/NativeWrapProvider.js'
import { NetSwapProvider } from './liquidity-providers/NetSwap.js'
import { PancakeSwapProvider } from './liquidity-providers/PancakeSwap.js'
import { PancakeSwapV2Provider } from './liquidity-providers/PancakeSwapV2.js'
import { PancakeSwapV3Provider } from './liquidity-providers/PancakeSwapV3.js'
import { QuickSwapProvider } from './liquidity-providers/QuickSwap.js'
import { SpookySwapProvider } from './liquidity-providers/SpookySwap.js'
import { SolarbeamProvider } from './liquidity-providers/Solarbeam.js'
import { SpookySwapV2Provider } from './liquidity-providers/SpookySwapV2.js'
import { SpookySwapV3Provider } from './liquidity-providers/SpookySwapV3.js'
import { SushiSwapV2Provider } from './liquidity-providers/SushiSwapV2.js'
import { SushiSwapV3Provider } from './liquidity-providers/SushiSwapV3.js'
import { SwapBlastProvider } from './liquidity-providers/SwapBlast.js'
import {
ThrusterV2_1Provider,
ThrusterV2_3Provider,
} from './liquidity-providers/ThrusterV2.js'
import { ThrusterV3Provider } from './liquidity-providers/ThrusterV3.js'
import { TraderJoeProvider } from './liquidity-providers/TraderJoe.js'
import { TridentProvider } from './liquidity-providers/Trident.js'
import { UbeSwapProvider } from './liquidity-providers/UbeSwap.js'
import { UniswapV2Provider } from './liquidity-providers/UniswapV2.js'
import { UniswapV3Provider } from './liquidity-providers/UniswapV3.js'
import { VVSStandardProvider } from './liquidity-providers/VVSStandard.js'
import { WagmiProvider } from './liquidity-providers/Wagmi.js'
import type { PoolCode } from './pool-codes/index.js'
import { promiseTimeout } from './timeout.js'

// options for data fetching, such as pinning block number and memoize
export type DataFetcherOptions = {
Expand All @@ -39,6 +62,8 @@ export type DataFetcherOptions = {
blockNumber?: bigint
/** Determines if memoizer should be used or not */
memoize?: boolean
/** Determines a timeout (in ms) for fetching pools for a token pair */
fetchPoolsTimeout?: number
}

// TODO: Should be a mode on the config for DataFetcher
Expand Down Expand Up @@ -123,25 +148,45 @@ export class DataFetcher {
this.providers = [new NativeWrapProvider(this.chainId, this.web3Client)]
;[
ApeSwapProvider,
BaseSwapProvider,
BiswapProvider,
BlastDEXProvider,
BlazeSwapProvider,
CamelotProvider,
CurveProvider,
DfynProvider,
DovishV3Provider,
DyorV2Provider,
ElkProvider,
EnosysProvider,
HoneySwapProvider,
HyperBlastProvider,
JetSwapProvider,
KinetixV2Provider,
KinetixV3Provider,
LaserSwapV2Provider,
MonoswapV2Provider,
MonoswapV3Provider,
NetSwapProvider,
PancakeSwapProvider,
SpookySwapProvider,
PancakeSwapV2Provider,
PancakeSwapV3Provider,
QuickSwapProvider,
SolarbeamProvider,
SpookySwapV2Provider,
SpookySwapV3Provider,
SushiSwapV2Provider,
SushiSwapV3Provider,
SwapBlastProvider,
ThrusterV2_1Provider,
ThrusterV2_3Provider,
ThrusterV3Provider,
TraderJoeProvider,
QuickSwapProvider,
TridentProvider,
UbeSwapProvider,
UniswapV2Provider,
UniswapV3Provider,
VVSStandardProvider,
WagmiProvider,
].forEach((p) => {
try {
const provider = new p(this.chainId, this.web3Client)
Expand Down Expand Up @@ -191,12 +236,22 @@ export class DataFetcher {
)
if (provider) {
try {
await provider.fetchPoolsForToken(
currency0.wrapped,
currency1.wrapped,
excludePools,
options,
)
options?.fetchPoolsTimeout
? await promiseTimeout(
provider.fetchPoolsForToken(
currency0.wrapped,
currency1.wrapped,
excludePools,
options,
),
options.fetchPoolsTimeout,
)
: await provider.fetchPoolsForToken(
currency0.wrapped,
currency1.wrapped,
excludePools,
options,
)
} catch {
/**/
}
Expand All @@ -207,11 +262,24 @@ export class DataFetcher {
currency0.wrapped.sortsBefore(currency1.wrapped)
? [currency0.wrapped, currency1.wrapped]
: [currency1.wrapped, currency0.wrapped]
await Promise.allSettled(
this.providers.map((p) =>
p.fetchPoolsForToken(token0, token1, excludePools, options),
),
)
try {
options?.fetchPoolsTimeout
? await promiseTimeout(
Promise.allSettled(
this.providers.map((p) =>
p.fetchPoolsForToken(token0, token1, excludePools, options),
),
),
options.fetchPoolsTimeout,
)
: await Promise.allSettled(
this.providers.map((p) =>
p.fetchPoolsForToken(token0, token1, excludePools, options),
),
)
} catch {
/**/
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@ import { ChainId } from '../../chain/index.js'
import { LiquidityProviders } from './LiquidityProvider.js'
import { UniswapV2BaseProvider } from './UniswapV2Base.js'

export class PancakeSwapProvider extends UniswapV2BaseProvider {
export class BaseSwapProvider extends UniswapV2BaseProvider {
override fee = 0.0025
constructor(chainId: ChainId, web3Client: PublicClient) {
const factory = {
[ChainId.ETHEREUM]: '0x1097053Fd2ea711dad45caCcc45EfF7548fCB362',
[ChainId.BSC]: '0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73',
[ChainId.BASE]: '0xFDa619b6d20975be80A10332cD39b9a4b0FAa8BB',
} as const
const initCodeHash = {
[ChainId.ETHEREUM]:
'0x57224589c67f3f30a6b0d7a1b54cf3153ab84563bc609ef41dfb34f8b2974d2d',
[ChainId.BSC]:
'0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5',
[ChainId.BASE]:
'0xb618a2730fae167f5f8ac7bd659dd8436d571872655bcb6fd11f2158c8a64a3b',
} as const
super(chainId, web3Client, factory, initCodeHash)
}
getType(): LiquidityProviders {
return LiquidityProviders.PancakeSwap
return LiquidityProviders.BaseSwap
}
getPoolProviderName(): string {
return 'PancakeSwap'
return 'BaseSwap'
}
}
1 change: 0 additions & 1 deletion packages/sushi/src/router/liquidity-providers/Biswap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { PublicClient } from 'viem'
import { ChainId } from '../../chain/index.js'

import { LiquidityProviders } from './LiquidityProvider.js'
import { UniswapV2BaseProvider } from './UniswapV2Base.js'

Expand Down
24 changes: 24 additions & 0 deletions packages/sushi/src/router/liquidity-providers/BlastDEX.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { PublicClient } from 'viem'
import { ChainId } from '../../chain/index.js'
import { LiquidityProviders } from './LiquidityProvider.js'
import { UniswapV2BaseProvider } from './UniswapV2Base.js'

export class BlastDEXProvider extends UniswapV2BaseProvider {
override fee = 0.002
constructor(chainId: ChainId, web3Client: PublicClient) {
const factory = {
[ChainId.BLAST]: '0x66346aac17d0e61156AC5F2A934ccF2a9BDe4c65',
} as const
const initCodeHash = {
[ChainId.BLAST]:
'0x376acff9b60b853f5ccc9f1caecb8dcf722793593330ac58aac8a880a3eb8b9e',
} as const
super(chainId, web3Client, factory, initCodeHash)
}
getType(): LiquidityProviders {
return LiquidityProviders.BlastDEX
}
getPoolProviderName(): string {
return 'BlastDEX'
}
}
23 changes: 23 additions & 0 deletions packages/sushi/src/router/liquidity-providers/BlazeSwap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { PublicClient } from 'viem'
import { ChainId } from '../../chain/index.js'
import { LiquidityProviders } from './LiquidityProvider.js'
import { UniswapV2BaseProvider } from './UniswapV2Base.js'

export class BlazeSwapProvider extends UniswapV2BaseProvider {
constructor(chainId: ChainId, web3Client: PublicClient) {
const factory = {
[ChainId.FLARE]: '0x440602f459D7Dd500a74528003e6A20A46d6e2A6',
} as const
const initCodeHash = {
[ChainId.FLARE]:
'0xbf4c1c435583a2bb8d763765a34a46e376071c3b3d80e5bbac0950aeecdf31cb',
} as const
super(chainId, web3Client, factory, initCodeHash)
}
getType(): LiquidityProviders {
return LiquidityProviders.BlazeSwap
}
getPoolProviderName(): string {
return 'BlazeSwap'
}
}
28 changes: 28 additions & 0 deletions packages/sushi/src/router/liquidity-providers/Camelot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { PublicClient, parseAbi } from 'viem'
import { ChainId } from '../../chain/index.js'
import { LiquidityProviders } from './LiquidityProvider.js'
import { UniswapV2BaseProvider } from './UniswapV2Base.js'

export class CamelotProvider extends UniswapV2BaseProvider {
// Camelot has a slightly different getReserves() abi
// so needs to be overriden
override getReservesAbi = parseAbi([
'function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint16 _token0FeePercent, uint16 _token1FeePercent)',
])
constructor(chainId: ChainId, web3Client: PublicClient) {
const factory = {
[ChainId.ARBITRUM]: '0x6EcCab422D763aC031210895C81787E87B43A652',
} as const
const initCodeHash = {
[ChainId.ARBITRUM]:
'0xa856464ae65f7619087bc369daaf7e387dae1e5af69cfa7935850ebf754b04c1',
} as const
super(chainId, web3Client, factory, initCodeHash)
}
getType(): LiquidityProviders {
return LiquidityProviders.Camelot
}
getPoolProviderName(): string {
return 'Camelot'
}
}
27 changes: 27 additions & 0 deletions packages/sushi/src/router/liquidity-providers/DyorV2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { PublicClient } from 'viem'
import { ChainId } from '../../chain/index.js'
import { LiquidityProviders } from './LiquidityProvider.js'
import { UniswapV2BaseProvider } from './UniswapV2Base.js'

export class DyorV2Provider extends UniswapV2BaseProvider {
override fee = 0.003
constructor(chainId: ChainId, web3Client: PublicClient) {
const factory = {
[ChainId.BLAST]: '0xA1da7a7eB5A858da410dE8FBC5092c2079B58413',
[ChainId.ZETACHAIN]: '0xA1da7a7eB5A858da410dE8FBC5092c2079B58413',
} as const
const initCodeHash = {
[ChainId.BLAST]:
'0xda2f1a903916d7de88d9357d27d763f123502a5d48e3b229d5fa049b3ffdeeb5',
[ChainId.ZETACHAIN]:
'0xda2f1a903916d7de88d9357d27d763f123502a5d48e3b229d5fa049b3ffdeeb5',
} as const
super(chainId, web3Client, factory, initCodeHash)
}
getType(): LiquidityProviders {
return LiquidityProviders.DyorV2
}
getPoolProviderName(): string {
return 'DyorV2'
}
}
Loading
Loading