Skip to content

Commit

Permalink
fix algebra v2 dexes
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Feb 1, 2025
1 parent 0bb3e14 commit 12f5e62
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 53 deletions.
61 changes: 32 additions & 29 deletions packages/sushi/src/router/liquidity-providers/AlgebraV1Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,42 @@ import {
bitmapIndex,
} from './UniswapV3Base.js'

export const globalStateAbi = [
{
inputs: [],
name: 'globalState',
outputs: [
{ internalType: 'uint160', name: 'price', type: 'uint160' },
{ internalType: 'int24', name: 'tick', type: 'int24' },
{ internalType: 'uint16', name: 'fee', type: 'uint16' },
{
internalType: 'uint16',
name: 'timepointIndex',
type: 'uint16',
},
{
internalType: 'uint8',
name: 'communityFeeToken0',
type: 'uint8',
},
{
internalType: 'uint8',
name: 'communityFeeToken1',
type: 'uint8',
},
{ internalType: 'bool', name: 'unlocked', type: 'bool' },
],
stateMutability: 'view',
type: 'function',
},
] as const

export abstract class AlgebraV1BaseProvider extends UniswapV3BaseProvider {
override TICK_SPACINGS: Record<string, number> = {}

readonly BASE_FEE = 100
DEFAULT_TICK_SPACING = 1
gloablStateAbi = globalStateAbi

poolDeployer: Record<number, Address> = {}

Expand Down Expand Up @@ -67,35 +98,7 @@ export abstract class AlgebraV1BaseProvider extends UniswapV3BaseProvider {
({
address: pool.address,
chainId: this.chainId,
abi: [
{
inputs: [],
name: 'globalState',
outputs: [
{ internalType: 'uint160', name: 'price', type: 'uint160' },
{ internalType: 'int24', name: 'tick', type: 'int24' },
{ internalType: 'uint16', name: 'fee', type: 'uint16' },
{
internalType: 'uint16',
name: 'timepointIndex',
type: 'uint16',
},
{
internalType: 'uint8',
name: 'communityFeeToken0',
type: 'uint8',
},
{
internalType: 'uint8',
name: 'communityFeeToken1',
type: 'uint8',
},
{ internalType: 'bool', name: 'unlocked', type: 'bool' },
],
stateMutability: 'view',
type: 'function',
},
] as const,
abi: this.gloablStateAbi,
functionName: 'globalState',
}) as const,
),
Expand Down
22 changes: 22 additions & 0 deletions packages/sushi/src/router/liquidity-providers/AlgebraV2Base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { AlgebraV1BaseProvider } from './AlgebraV1Base.js'

export const globalStateAbi = [
{
inputs: [],
name: 'globalState',
outputs: [
{ internalType: 'uint160', name: 'price', type: 'uint160' },
{ internalType: 'int24', name: 'tick', type: 'int24' },
{ internalType: 'uint16', name: 'lastFee', type: 'uint16' },
{ internalType: 'uint8', name: 'pluginConfig', type: 'uint8' },
{ internalType: 'uint16', name: 'communityFee', type: 'uint16' },
{ internalType: 'bool', name: 'unlocked', type: 'bool' },
],
stateMutability: 'view',
type: 'function',
},
] as const

export abstract class AlgebraV2BaseProvider extends AlgebraV1BaseProvider {
override gloablStateAbi = globalStateAbi as any
}
4 changes: 2 additions & 2 deletions packages/sushi/src/router/liquidity-providers/BladeSwap.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PublicClient } from 'viem'
import { ChainId } from '../../chain/index.js'
import { AlgebraV1BaseProvider } from './AlgebraV1Base.js'
import { AlgebraV2BaseProvider } from './AlgebraV2Base.js'
import { LiquidityProviders } from './LiquidityProvider.js'

export class BladeSwapProvider extends AlgebraV1BaseProvider {
export class BladeSwapProvider extends AlgebraV2BaseProvider {
constructor(chainId: ChainId, web3Client: PublicClient) {
const factory = {
[ChainId.BLAST]: '0xA87DbF5082Af26c9A6Ab2B854E378f704638CCa5',
Expand Down
4 changes: 2 additions & 2 deletions packages/sushi/src/router/liquidity-providers/Fenix.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PublicClient } from 'viem'
import { ChainId } from '../../chain/index.js'
import { AlgebraV1BaseProvider } from './AlgebraV1Base.js'
import { AlgebraV2BaseProvider } from './AlgebraV2Base.js'
import { LiquidityProviders } from './LiquidityProvider.js'

export class FenixProvider extends AlgebraV1BaseProvider {
export class FenixProvider extends AlgebraV2BaseProvider {
constructor(chainId: ChainId, web3Client: PublicClient) {
const factory = {
[ChainId.BLAST]: '0x7a44CD060afC1B6F4c80A2B9b37f4473E74E25Df',
Expand Down
12 changes: 6 additions & 6 deletions packages/sushi/src/router/liquidity-providers/GlyphV4.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { PublicClient } from 'viem'
import { ChainId } from '../../chain/index.js'
import { AlgebraV1BaseProvider } from './AlgebraV1Base.js'
import { AlgebraV2BaseProvider } from './AlgebraV2Base.js'
import { LiquidityProviders } from './LiquidityProvider.js'

export class GlyphV4Provider extends AlgebraV1BaseProvider {
export class GlyphV4Provider extends AlgebraV2BaseProvider {
constructor(chainId: ChainId, web3Client: PublicClient) {
const factory = {
[ChainId.BLAST]: '0x74EfE55beA4988e7D92D03EFd8ddB8BF8b7bD597',
[ChainId.CORE]: '0x74EfE55beA4988e7D92D03EFd8ddB8BF8b7bD597',
} as const
const poolDeployer = {
[ChainId.BLAST]: '0x24196b3f35E1B8313016b9f6641D605dCf48A76a',
[ChainId.CORE]: '0x24196b3f35E1B8313016b9f6641D605dCf48A76a',
} as const
const initCodeHash = {
[ChainId.BLAST]:
[ChainId.CORE]:
'0xf96d2474815c32e070cd63233f06af5413efc5dcb430aee4ff18cc29007c562d',
} as const
const tickLens = {
[ChainId.BLAST]: '0x433cef5888C701831360686e54668376330cED6D',
[ChainId.CORE]: '0x433cef5888C701831360686e54668376330cED6D',
} as const
super(chainId, web3Client, factory, initCodeHash, tickLens, poolDeployer)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/sushi/src/router/liquidity-providers/Horizon.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PublicClient } from 'viem'
import { ChainId } from '../../chain/index.js'
import { AlgebraV1BaseProvider } from './AlgebraV1Base.js'
import { AlgebraV2BaseProvider } from './AlgebraV2Base.js'
import { LiquidityProviders } from './LiquidityProvider.js'

export class HorizonProvider extends AlgebraV1BaseProvider {
export class HorizonProvider extends AlgebraV2BaseProvider {
constructor(chainId: ChainId, web3Client: PublicClient) {
const factory = {
[ChainId.LINEA]: '0xec4f2937e57a6F39087187816eCc83191E6dB1aB',
Expand Down
4 changes: 2 additions & 2 deletions packages/sushi/src/router/liquidity-providers/KimV4.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PublicClient } from 'viem'
import { ChainId } from '../../chain/index.js'
import { AlgebraV1BaseProvider } from './AlgebraV1Base.js'
import { AlgebraV2BaseProvider } from './AlgebraV2Base.js'
import { LiquidityProviders } from './LiquidityProvider.js'

export class KimV4Provider extends AlgebraV1BaseProvider {
export class KimV4Provider extends AlgebraV2BaseProvider {
constructor(chainId: ChainId, web3Client: PublicClient) {
const factory = {
[ChainId.BASE]: '0x2F0d41f94d5D1550b79A83D2fe85C82d68c5a3ca',
Expand Down
4 changes: 2 additions & 2 deletions packages/sushi/src/router/liquidity-providers/Scribe.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PublicClient } from 'viem'
import { ChainId } from '../../chain/index.js'
import { AlgebraV1BaseProvider } from './AlgebraV1Base.js'
import { AlgebraV2BaseProvider } from './AlgebraV2Base.js'
import { LiquidityProviders } from './LiquidityProvider.js'

export class ScribeProvider extends AlgebraV1BaseProvider {
export class ScribeProvider extends AlgebraV2BaseProvider {
constructor(chainId: ChainId, web3Client: PublicClient) {
const factory = {
[ChainId.SCROLL]: '0xDc62aCDF75cc7EA4D93C69B2866d9642E79d5e2e',
Expand Down
12 changes: 6 additions & 6 deletions packages/sushi/src/router/liquidity-providers/Swapsicle.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { PublicClient } from 'viem'
import { ChainId } from '../../chain/index.js'
import { AlgebraV1BaseProvider } from './AlgebraV1Base.js'
import { AlgebraV2BaseProvider } from './AlgebraV2Base.js'
import { LiquidityProviders } from './LiquidityProvider.js'

export class SwapsicleProvider extends AlgebraV1BaseProvider {
export class SwapsicleProvider extends AlgebraV2BaseProvider {
constructor(chainId: ChainId, web3Client: PublicClient) {
const factory = {
[ChainId.SCROLL]: '0xA09BAbf9A48003ae9b9333966a8Bda94d820D0d9',
[ChainId.TELOS]: '0xA09BAbf9A48003ae9b9333966a8Bda94d820D0d9',
} as const
const poolDeployer = {
[ChainId.SCROLL]: '0x061e47Ab9f31D293172efb88674782f80eCa88de',
[ChainId.TELOS]: '0x061e47Ab9f31D293172efb88674782f80eCa88de',
} as const
const initCodeHash = {
[ChainId.SCROLL]:
[ChainId.TELOS]:
'0x177d5fbf994f4d130c008797563306f1a168dc689f81b2fa23b4396931014d91',
} as const
const tickLens = {
[ChainId.SCROLL]: '0x9dE2dEA5c68898eb4cb2DeaFf357DFB26255a4aa',
[ChainId.TELOS]: '0x9dE2dEA5c68898eb4cb2DeaFf357DFB26255a4aa',
} as const
super(chainId, web3Client, factory, initCodeHash, tickLens, poolDeployer)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/sushi/src/router/liquidity-providers/VVSFlawless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class VVSFlawlessProvider extends UniswapV3BaseProvider {
abi: [
{
inputs: [],
name: 'factory',
name: 'factoryAddress',
outputs: [
{
internalType: 'address',
Expand All @@ -82,7 +82,7 @@ export class VVSFlawlessProvider extends UniswapV3BaseProvider {
type: 'function',
},
],
functionName: 'factory',
functionName: 'factoryAddress',
} as const,
],
})
Expand Down
97 changes: 97 additions & 0 deletions protocols/route-processor/test/DataFetcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,66 @@ async function runTest() {
)
}

// only for kimv4 on base
if (chainId === ChainId.BASE) {
const token = new Token({
chainId: ChainId.BASE,
address: '0x5dC25aA049837B696d1dc0F966aC8DF1491f819B',
decimals: 18,
symbol: 'KIM',
})
allFoundPools.push(
await testDF(
chName,
dataFetcher,
token,
WNATIVE[chainId as keyof typeof WNATIVE],
'KIM',
'WETH',
),
)

foundRouteReports.push(
findRoute(
dataFetcher,
token,
WNATIVE[chainId as keyof typeof WNATIVE],
chainId,
[LiquidityProviders.KimV4],
),
)
}

// only for horizon on linea
if (chainId === ChainId.LINEA) {
const token = new Token({
chainId: ChainId.LINEA,
address: '0x7d43AABC515C356145049227CeE54B608342c0ad',
decimals: 18,
symbol: 'BUSD',
})
allFoundPools.push(
await testDF(
chName,
dataFetcher,
token,
WNATIVE[chainId as keyof typeof WNATIVE],
'BUSD',
'WETH',
),
)

foundRouteReports.push(
findRoute(
dataFetcher,
token,
WNATIVE[chainId as keyof typeof WNATIVE],
chainId,
[LiquidityProviders.Horizon],
),
)
}

// only for Dfyn and JetSwap on fantom chain
if (
chainId === ChainId.FANTOM &&
Expand Down Expand Up @@ -263,6 +323,43 @@ async function runTest() {
)
}

// only for Blast chain
if (
chainId === ChainId.BLAST &&
reportMissingDexes(allFoundPools).hasMissingDex
) {
const token0 = new Token({
chainId: ChainId.BLAST,
address: '0x18755D2ceC785aB87680Edb8e117615E4B005430',
decimals: 18,
symbol: 'fwRING',
})
const token1 = new Token({
chainId: ChainId.BLAST,
address: '0x66714DB8F3397c767d0A602458B5b4E3C0FE7dd1',
decimals: 18,
symbol: 'fwWETH',
})
allFoundPools.push(
await testDF(
chName,
dataFetcher,
token0,
token1,
'fwRING',
'fwWETH',
),
)
foundRouteReports.push(
findRoute(
dataFetcher,
token0,
token1,
chainId,
),
)
}

// only for Moonbeam chain
if (
chainId === ChainId.MOONBEAM &&
Expand Down

0 comments on commit 12f5e62

Please sign in to comment.