Skip to content
Open
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
7 changes: 5 additions & 2 deletions src/dex/ekubo-v3/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ export const ORACLE_ADDRESS = '0x517E506700271AEa091b02f42756F5E174Af5230';
export const MEV_CAPTURE_ADDRESS = '0x5555fF9Ff2757500BF4EE020DcfD0210CFfa41Be';
export const BOOSTED_FEES_CONCENTRATED_ADDRESS =
'0xd4B54d0ca6979Da05F25895E6e269E678ba00f9e';
export const TWAMM_ADDRESS = '0xd4F1060cB9c1A13e1d2d20379b8aa2cF7541eD9b';
export const TWAMM_V1_ADDRESS = '0xd4F1060cB9c1A13e1d2d20379b8aa2cF7541eD9b';
export const TWAMM_V2_ADDRESS = '0xd47f1B1eDCfEaBb08F6eBd8FC337c27E636C75BA';
export const QUOTE_DATA_FETCHER_ADDRESS =
'0x5a3f0f1da4ac0c4b937d5685f330704c8e8303f1';
export const TWAMM_DATA_FETCHER_ADDRESS =
export const TWAMM_V1_DATA_FETCHER_ADDRESS =
'0xc07e5b80750247c8b5d7234a9c79dfc58785392b';
export const TWAMM_V2_DATA_FETCHER_ADDRESS =
'0xdefe25e56a7891cc4c0e1401879f3dc81f1cc4a6';
export const BOOSTED_FEES_DATA_FETCHER_ADDRESS =
'0x7A2fF5819Dc71Bb99133a97c38dA512E60c30475';
export const ROUTER_ADDRESS = '0xd26f20001a72a18C002b00e6710000d68700ce00';
Expand Down
35 changes: 22 additions & 13 deletions src/dex/ekubo-v3/ekubo-v3-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
DEX_KEY,
EKUBO_V3_CONFIG,
EkuboSupportedNetwork,
TWAMM_ADDRESS,
TWAMM_V1_ADDRESS,
TWAMM_V2_ADDRESS,
} from './config';
import {
ConcentratedPool,
Expand Down Expand Up @@ -184,11 +185,21 @@ const eventFixtures: Record<
),
);

const twammEthUsdcPoolKey = new PoolKey(
const twammV1EthUsdcPoolKey = new PoolKey(
NATIVE_TOKEN_ADDRESS,
USDC,
new PoolConfig(
BigInt(TWAMM_ADDRESS),
BigInt(TWAMM_V1_ADDRESS),
55340232221128654n,
StableswapPoolTypeConfig.fullRangeConfig(),
),
);

const twammV2EthEkuboPoolKey = new PoolKey(
NATIVE_TOKEN_ADDRESS,
EKUBO,
new PoolConfig(
BigInt(TWAMM_V2_ADDRESS),
55340232221128654n,
StableswapPoolTypeConfig.fullRangeConfig(),
),
Expand All @@ -208,21 +219,19 @@ const eventFixtures: Record<
poolStateEvents: {
Swapped: [
[newPool(ConcentratedPool, clEthUsdcPoolKey), 24175246], // https://etherscan.io/tx/0xee56e1f3bad803bd857fb118e55d7eabb5368a94ae8f11e83724278f474294ca
[newPool(TwammPool, twammEthUsdcPoolKey), 24175264], // https://etherscan.io/tx/0x01c02e32ac563e3a761382cb8ef278cfed9ed9dc758b5a95f38dd44978e87b2e
[newPool(TwammPool, twammV1EthUsdcPoolKey), 24175264], // https://etherscan.io/tx/0x01c02e32ac563e3a761382cb8ef278cfed9ed9dc758b5a95f38dd44978e87b2e
],
PositionUpdated: [
[newPool(ConcentratedPool, clEthUsdcPoolKey), 24169215], // Add liquidity https://etherscan.io/tx/0x52f469327de230f3da91eb7b77069852757d383450943307f5da63016476c0fb
[newPool(ConcentratedPool, clEthUsdcPoolKey), 24169222], // Withdraw liquidity https://etherscan.io/tx/0x00cfe35092d58aab347abc58345878092f87d37c7f0f0126fb1c890c791cdc02
[newPool(TwammPool, twammEthUsdcPoolKey), 24169228], // Add liquidity https://etherscan.io/tx/0x5fceec2c8fce56c7a73b8e3efca77f9ef8561b40a08b05785e9084cba684b5f8
[newPool(TwammPool, twammEthUsdcPoolKey), 24169235], // Withdraw liquidity https://etherscan.io/tx/0x920f865071397a145e2e9558dfaedb7e138456d8fe43c1899187778a16b00c8b
],
OrderUpdated: [
[newPool(TwammPool, twammEthUsdcPoolKey), 24169245], // Create order https://etherscan.io/tx/0x67bb5ba44397d8b9d9ffe753e9c7f1b478eadfac22464a39521bdd3541f6a68f
[newPool(TwammPool, twammEthUsdcPoolKey), 24169249], // Stop order https://etherscan.io/tx/0xde6812e959a49e245f15714d1b50571f43ca7711c91d2df1087178a38bc554b7
[newPool(TwammPool, twammV1EthUsdcPoolKey), 24169228], // Add liquidity https://etherscan.io/tx/0x5fceec2c8fce56c7a73b8e3efca77f9ef8561b40a08b05785e9084cba684b5f8
[newPool(TwammPool, twammV1EthUsdcPoolKey), 24169235], // Withdraw liquidity https://etherscan.io/tx/0x920f865071397a145e2e9558dfaedb7e138456d8fe43c1899187778a16b00c8b
],
VirtualOrdersExecuted: [
[newPool(TwammPool, twammEthUsdcPoolKey), 24169245], // Create order https://etherscan.io/tx/0x67bb5ba44397d8b9d9ffe753e9c7f1b478eadfac22464a39521bdd3541f6a68f
[newPool(TwammPool, twammEthUsdcPoolKey), 24169249], // Stop order https://etherscan.io/tx/0xde6812e959a49e245f15714d1b50571f43ca7711c91d2df1087178a38bc554b7
VirtualOrdersExecutedAndOrderUpdated: [
[newPool(TwammPool, twammV1EthUsdcPoolKey), 24169245], // Create order https://etherscan.io/tx/0x67bb5ba44397d8b9d9ffe753e9c7f1b478eadfac22464a39521bdd3541f6a68f
[newPool(TwammPool, twammV1EthUsdcPoolKey), 24169249], // Stop order https://etherscan.io/tx/0xde6812e959a49e245f15714d1b50571f43ca7711c91d2df1087178a38bc554b7
[newPool(TwammPool, twammV2EthEkuboPoolKey), 25167059], // Create order https://etherscan.io/tx/0x32de015a5cd9a2a3f7fab3e19ad6bed01af3f91aeeb49d936831d97919504ed9
[newPool(TwammPool, twammV2EthEkuboPoolKey), 25178860], // Stop order https://etherscan.io/tx/0x43ba3ba3afde750748fdc6ee47a7c3e7592924eb419c482d61490410dbf5045a
],
PoolBoosted: [
[newPool(BoostedFeesPool, boostedFeesEkuboUsdcPoolKey), 24486286], // https://etherscan.io/tx/0xe8b84a98592609c8b49bfaeafa76b0187bd6afd90b8df27469f9435f4b17318e#eventlog#235
Expand Down
51 changes: 28 additions & 23 deletions src/dex/ekubo-v3/ekubo-v3-pool-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
CORE_ADDRESS,
MEV_CAPTURE_ADDRESS,
ORACLE_ADDRESS,
TWAMM_ADDRESS,
TWAMM_V2_ADDRESS,
TWAMM_V1_ADDRESS,
} from './config';
import { FullRangePool, FullRangePoolState } from './pools/full-range';
import { StableswapPool } from './pools/stableswap';
Expand All @@ -35,14 +36,16 @@ import { ExtensionType, extensionType } from './extension-type';

export const EVENT_EMITTERS = [
CORE_ADDRESS,
TWAMM_ADDRESS,
TWAMM_V2_ADDRESS,
TWAMM_V1_ADDRESS,
BOOSTED_FEES_CONCENTRATED_ADDRESS,
];

const SUBGRAPH_PAGE_SIZE = 1000;
const SUBGRAPH_EXTENSIONS = [
ORACLE_ADDRESS,
TWAMM_ADDRESS,
TWAMM_V2_ADDRESS,
TWAMM_V1_ADDRESS,
MEV_CAPTURE_ADDRESS,
BOOSTED_FEES_CONCENTRATED_ADDRESS,
];
Expand Down Expand Up @@ -146,7 +149,7 @@ export class EkuboV3PoolManager implements EventSubscriber {
) {
const {
core: { contract: coreContract, interface: coreIface },
twamm: { contract: twammContract, interface: twammIface },
twamm: { v1: twammV1, v2: twammV2, interface: twammIface },
boostedFees: {
contract: boostedFeesContract,
interface: boostedFeesIface,
Expand All @@ -164,32 +167,34 @@ export class EkuboV3PoolManager implements EventSubscriber {
parsePoolIdByLogDataOffsetFn(32),
],
]),
[twammContract.address]: new Map<
string,
(data: string) => bigint | string
>([
['', parsePoolIdByLogDataOffsetFn(0)],
[
twammIface.getEventTopic('OrderUpdated'),
data =>
new PoolKey(
BigInt(hexDataSlice(data, 64, 96)),
BigInt(hexDataSlice(data, 96, 128)),
new PoolConfig(
BigInt(TWAMM_ADDRESS),
BigInt(hexDataSlice(data, 128, 136)),
StableswapPoolTypeConfig.fullRangeConfig(),
),
).stringId,
],
]),
[boostedFeesContract.address]: new Map([
['', parsePoolIdByLogDataOffsetFn(0)],
[
boostedFeesIface.getEventTopic('PoolBoosted'),
parsePoolIdByLogDataOffsetFn(0),
],
]),
...Object.fromEntries(
[twammV1.address, twammV2.address].map(address => [
address,
new Map<string, (data: string) => bigint | string>([
['', parsePoolIdByLogDataOffsetFn(0)],
[
twammIface.getEventTopic('OrderUpdated'),
data =>
new PoolKey(
BigInt(hexDataSlice(data, 64, 96)),
BigInt(hexDataSlice(data, 96, 128)),
new PoolConfig(
BigInt(address),
BigInt(hexDataSlice(data, 128, 136)),
StableswapPoolTypeConfig.fullRangeConfig(),
),
).stringId,
],
]),
]),
),
};
}

Expand Down
6 changes: 4 additions & 2 deletions src/dex/ekubo-v3/extension-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
BOOSTED_FEES_CONCENTRATED_ADDRESS,
MEV_CAPTURE_ADDRESS,
ORACLE_ADDRESS,
TWAMM_ADDRESS,
TWAMM_V2_ADDRESS,
TWAMM_V1_ADDRESS,
} from './config';

export const enum ExtensionType {
Expand All @@ -16,7 +17,8 @@ export const enum ExtensionType {

const KNOWN_EXTENSION_TYPES = new Map<bigint, ExtensionType>([
[BigInt(ORACLE_ADDRESS), ExtensionType.Oracle],
[BigInt(TWAMM_ADDRESS), ExtensionType.Twamm],
[BigInt(TWAMM_V1_ADDRESS), ExtensionType.Twamm],
[BigInt(TWAMM_V2_ADDRESS), ExtensionType.Twamm],
[BigInt(MEV_CAPTURE_ADDRESS), ExtensionType.MevCapture],
[
BigInt(BOOSTED_FEES_CONCENTRATED_ADDRESS),
Expand Down
19 changes: 14 additions & 5 deletions src/dex/ekubo-v3/pools/twamm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ export class TwammPool extends EkuboPool<
contract: { address: coreAddress },
interface: coreIface,
} = contracts.core;
const {
contract: { address: twammAddress },
interface: twammIface,
quoteDataFetcher: twammDataFetcher,
} = contracts.twamm;
const { v1: twammV1, v2: twammV2, interface: twammIface } = contracts.twamm;

const extension = key.config.extension;
let twammDeployment;

if (extension === BigInt(twammV1.address)) {
twammDeployment = twammV1;
} else if (extension === BigInt(twammV2.address)) {
twammDeployment = twammV2;
} else {
throw new Error('unknown TWAMM extension');
}
const { address: twammAddress, quoteDataFetcher: twammDataFetcher } =
twammDeployment;

super(
parentName,
Expand Down
17 changes: 13 additions & 4 deletions src/dex/ekubo-v3/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,19 @@ export type EkuboContract = {
quoteDataFetcher: Contract;
};

export type EkuboContracts = Record<
'core' | 'twamm' | 'boostedFees',
EkuboContract
>;
export type EkuboContracts = Record<'core' | 'boostedFees', EkuboContract> & {
twamm: {
interface: Interface;
v1: {
address: string;
quoteDataFetcher: Contract;
};
v2: {
address: string;
quoteDataFetcher: Contract;
};
};
};

export type BoostedFeesQuoteData = {
sqrtRatio: BigNumber;
Expand Down
28 changes: 20 additions & 8 deletions src/dex/ekubo-v3/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import {
BOOSTED_FEES_DATA_FETCHER_ADDRESS,
CORE_ADDRESS,
QUOTE_DATA_FETCHER_ADDRESS,
TWAMM_ADDRESS,
TWAMM_DATA_FETCHER_ADDRESS,
TWAMM_V2_ADDRESS,
TWAMM_V1_ADDRESS,
TWAMM_V1_DATA_FETCHER_ADDRESS,
TWAMM_V2_DATA_FETCHER_ADDRESS,
} from './config';

export const NATIVE_TOKEN_ADDRESS = 0x0000000000000000000000000000000000000000n;
Expand Down Expand Up @@ -56,13 +58,23 @@ export function ekuboContracts(provider: Provider): EkuboContracts {
),
},
twamm: {
contract: new Contract(TWAMM_ADDRESS, TwammABI, provider),
v1: {
address: TWAMM_V1_ADDRESS,
quoteDataFetcher: new Contract(
TWAMM_V1_DATA_FETCHER_ADDRESS,
TwammDataFetcherABI,
provider,
),
},
v2: {
address: TWAMM_V2_ADDRESS,
quoteDataFetcher: new Contract(
TWAMM_V2_DATA_FETCHER_ADDRESS,
TwammDataFetcherABI,
provider,
),
},
interface: new Interface(TwammABI),
quoteDataFetcher: new Contract(
TWAMM_DATA_FETCHER_ADDRESS,
TwammDataFetcherABI,
provider,
),
},
boostedFees: {
contract: new Contract(
Expand Down