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

overridable univ3 fees/ticks literals for univ3 based dexes #18

Merged
merged 10 commits into from
Jun 29, 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
63 changes: 58 additions & 5 deletions .github/workflows/rain-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Rain CI
on: [push]

jobs:
install-build-lint-test:
router-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -21,8 +21,61 @@ jobs:

- name: Check ./packages/sushi Types
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
nix develop -c pnpm exec turbo run test --filter=./protocols/route-processor
run: nix develop -c pnpm exec turbo run test --filter=./packages/sushi

datafetcher-test:
strategy:
fail-fast: false
# chains to run datafetcher on (all supported chains)
matrix:
chain: [
ETHEREUM,
POLYGON,
FANTOM,
GNOSIS,
BSC,
ARBITRUM,
ARBITRUM_NOVA,
AVALANCHE,
HARMONY,
OKEX,
CELO,
MOONRIVER,
FUSE,
TELOS,
MOONBEAM,
OPTIMISM,
KAVA,
METIS,
BOBA,
BOBA_BNB,
BTTC,
POLYGON_ZKEVM,
THUNDERCORE,
FILECOIN,
HAQQ,
CORE,
LINEA,
BASE,
SCROLL,
ZETACHAIN,
CRONOS,
BLAST,
FLARE,
]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: DeterminateSystems/nix-installer-action@v4
- uses: DeterminateSystems/magic-nix-cache-action@v2

- name: Install deps
run: nix develop -c pnpm install --frozen-lockfile

- name: Test DataFecther
run: nix develop -c pnpm exec turbo run test --filter=./protocols/route-processor
env:
CHAIN: ${{ matrix.chain }}
45 changes: 45 additions & 0 deletions packages/sushi/src/router/liquidity-providers/LiquidityProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,48 @@ export abstract class LiquidityProvider {
.sort((first, second) => (first > second ? -1 : 1))
.join(':')
}

export const UniV2LiquidityProviders: LiquidityProviders[] = [
LiquidityProviders.SushiSwapV2,
LiquidityProviders.UniswapV2,
LiquidityProviders.QuickSwap,
LiquidityProviders.ApeSwap,
LiquidityProviders.PancakeSwapV2,
LiquidityProviders.TraderJoe,
LiquidityProviders.Dfyn,
LiquidityProviders.Elk,
LiquidityProviders.JetSwap,
LiquidityProviders.SpookySwapV2,
LiquidityProviders.NetSwap,
LiquidityProviders.HoneySwap,
LiquidityProviders.UbeSwap,
LiquidityProviders.Biswap,
LiquidityProviders.LaserSwap,
LiquidityProviders.BaseSwap,
LiquidityProviders.Solarbeam,
LiquidityProviders.Swapsicle,
LiquidityProviders.VVSStandard,
LiquidityProviders.Fraxswap,
LiquidityProviders.SwapBlast,
LiquidityProviders.BlastDEX,
LiquidityProviders.MonoswapV2,
LiquidityProviders.ThrusterV2,
LiquidityProviders.DyorV2,
LiquidityProviders.HyperBlast,
LiquidityProviders.KinetixV2,
LiquidityProviders.Camelot,
LiquidityProviders.Enosys,
LiquidityProviders.BlazeSwap,
]

export const UniV3LiquidityProviders: LiquidityProviders[] = [
LiquidityProviders.SushiSwapV3,
LiquidityProviders.UniswapV3,
LiquidityProviders.DovishV3,
LiquidityProviders.KinetixV3,
LiquidityProviders.MonoswapV3,
LiquidityProviders.ThrusterV3,
LiquidityProviders.SpookySwapV3,
LiquidityProviders.PancakeSwapV3,
LiquidityProviders.Wagmi,
]
68 changes: 67 additions & 1 deletion packages/sushi/src/router/liquidity-providers/PancakeSwapV3.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { PublicClient } from 'viem'
import { Address, PublicClient } from 'viem'
import { uniswapV3FactoryAbi } from '../../abi/uniswapV3FactoryAbi.js'
import { ChainId } from '../../chain/index.js'
import {
PANCAKESWAP_V3_FEE_SPACING_MAP,
PancakeSwapV3FeeAmount,
} from '../../config/index.js'
import { LiquidityProviders } from './LiquidityProvider.js'
import { UniswapV3BaseProvider } from './UniswapV3Base.js'

export class PancakeSwapV3Provider extends UniswapV3BaseProvider {
override FEE = PancakeSwapV3FeeAmount
override TICK_SPACINGS = PANCAKESWAP_V3_FEE_SPACING_MAP
constructor(chainId: ChainId, web3Client: PublicClient) {
const factory = {
[ChainId.ARBITRUM]: '0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9',
Expand Down Expand Up @@ -47,4 +54,63 @@ export class PancakeSwapV3Provider extends UniswapV3BaseProvider {
getPoolProviderName(): string {
return 'PancakeSwapV3'
}
override async ensureFeeAndTicks(): Promise<boolean> {
const feeList = [
this.FEE.LOWEST,
this.FEE.LOW,
this.FEE.MEDIUM,
this.FEE.HIGH,
] as number[]
const factoryAddress = (
await this.client.multicall({
multicallAddress: this.client.chain?.contracts?.multicall3
?.address as Address,
allowFailure: false,
contracts: [
{
address: this.factory[this.chainId as keyof typeof this.factory]!,
abi: [
{
inputs: [],
name: 'factoryAddress',
outputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
},
],
functionName: 'factoryAddress',
} as const,
],
})
)[0]

const results = (await this.client.multicall({
multicallAddress: this.client.chain?.contracts?.multicall3
?.address as Address,
allowFailure: false,
contracts: feeList.map(
(fee) =>
({
chainId: this.chainId,
address: factoryAddress as Address,
abi: uniswapV3FactoryAbi,
functionName: 'feeAmountTickSpacing',
args: [fee],
}) as const,
),
})) as number[]

// fetched fee map to ticks should match correctly with hardcoded literals in the dex
return results.every(
(v, i) =>
this.TICK_SPACINGS[feeList[i] as PancakeSwapV3FeeAmount] === v ||
v === 0,
)
}
}
63 changes: 62 additions & 1 deletion packages/sushi/src/router/liquidity-providers/ThrusterV3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { PublicClient } from 'viem'
import { Address, PublicClient } from 'viem'
import { uniswapV3FactoryAbi } from '../../abi/uniswapV3FactoryAbi.js'
import { ChainId } from '../../chain/index.js'
import { SushiSwapV3FeeAmount } from '../../config/sushiswap-v3.js'
import { LiquidityProviders } from './LiquidityProvider.js'
import { UniswapV3BaseProvider } from './UniswapV3Base.js'

Expand All @@ -23,4 +25,63 @@ export class ThrusterV3Provider extends UniswapV3BaseProvider {
getPoolProviderName(): string {
return 'ThrusterV3'
}

override async ensureFeeAndTicks(): Promise<boolean> {
const feeList = [
this.FEE.LOWEST,
this.FEE.LOW,
this.FEE.MEDIUM,
this.FEE.HIGH,
] as number[]
const factoryAddress = (
await this.client.multicall({
multicallAddress: this.client.chain?.contracts?.multicall3
?.address as Address,
allowFailure: false,
contracts: [
{
address: this.factory[this.chainId as keyof typeof this.factory]!,
abi: [
{
inputs: [],
name: 'factory',
outputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
},
],
functionName: 'factory',
} as const,
],
})
)[0]

const results = (await this.client.multicall({
multicallAddress: this.client.chain?.contracts?.multicall3
?.address as Address,
allowFailure: false,
contracts: feeList.map(
(fee) =>
({
chainId: this.chainId,
address: factoryAddress as Address,
abi: uniswapV3FactoryAbi,
functionName: 'feeAmountTickSpacing',
args: [fee],
}) as const,
),
})) as number[]

// fetched fee map to ticks should match correctly with hardcoded literals in the dex
return results.every(
(v, i) =>
this.TICK_SPACINGS[feeList[i] as SushiSwapV3FeeAmount] === v || v === 0,
)
}
}
Loading
Loading