@paraswap/dex-lib 4.7.14-multi-route.0 → 4.7.14-multi-route.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/build/abi/pharaoh-v3/PharaohV3Factory.abi.json +39 -0
  2. package/build/abi/pharaoh-v3/PharaohV3Pool.abi.json +802 -0
  3. package/build/abi/pharaoh-v3/PharaohV3StateMulticall.abi.json +781 -0
  4. package/build/abi/uniswap-v4/hooks/arena/arena-fee-helper.abi.json +476 -0
  5. package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3-factory.d.ts +7 -0
  6. package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3-factory.js +20 -0
  7. package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3-factory.js.map +1 -0
  8. package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3-pool.d.ts +12 -0
  9. package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3-pool.js +139 -0
  10. package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3-pool.js.map +1 -0
  11. package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3.d.ts +11 -0
  12. package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3.js +128 -0
  13. package/build/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3.js.map +1 -0
  14. package/build/dex/uniswap-v3/forks/pharaoh-v3/utils.d.ts +4 -0
  15. package/build/dex/uniswap-v3/forks/pharaoh-v3/utils.js +56 -0
  16. package/build/dex/uniswap-v3/forks/pharaoh-v3/utils.js.map +1 -0
  17. package/build/dex/uniswap-v4/hooks/arena/arena-fee-helper.d.ts +36 -0
  18. package/build/dex/uniswap-v4/hooks/arena/arena-fee-helper.js +125 -0
  19. package/build/dex/uniswap-v4/hooks/arena/arena-fee-helper.js.map +1 -0
  20. package/build/dex/uniswap-v4/hooks/arena/arena-hook.d.ts +21 -0
  21. package/build/dex/uniswap-v4/hooks/arena/arena-hook.js +93 -0
  22. package/build/dex/uniswap-v4/hooks/arena/arena-hook.js.map +1 -0
  23. package/build/dex/uniswap-v4/hooks/arena/config.d.ts +3 -0
  24. package/build/dex/uniswap-v4/hooks/arena/config.js +11 -0
  25. package/build/dex/uniswap-v4/hooks/arena/config.js.map +1 -0
  26. package/build/dex/uniswap-v4/hooks/arena/types.d.ts +5 -0
  27. package/build/dex/uniswap-v4/hooks/arena/types.js +3 -0
  28. package/build/dex/uniswap-v4/hooks/arena/types.js.map +1 -0
  29. package/build/dex/uniswap-v4/hooks/types.d.ts +60 -0
  30. package/build/dex/uniswap-v4/hooks/types.js +3 -0
  31. package/build/dex/uniswap-v4/hooks/types.js.map +1 -0
  32. package/build/executor/types.d.ts +3 -3
  33. package/build/generic-swap-transaction-builder.d.ts +3 -2
  34. package/build/generic-swap-transaction-builder.js +61 -50
  35. package/build/generic-swap-transaction-builder.js.map +1 -1
  36. package/package.json +1 -1
@@ -0,0 +1,11 @@
1
+ import { Network } from '../../../../constants';
2
+ import { VelodromeSlipstream } from '../velodrome-slipstream/velodrome-slipstream';
3
+ import { Address } from '@paraswap/core';
4
+ import { PoolLiquidity } from '../../../../types';
5
+ export declare class PharaohV3 extends VelodromeSlipstream {
6
+ static dexKeysWithNetwork: {
7
+ key: string;
8
+ networks: Network[];
9
+ }[];
10
+ getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
11
+ }
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PharaohV3 = void 0;
7
+ const config_1 = require("../../config");
8
+ const utils_1 = require("../../../../utils");
9
+ const lodash_1 = __importDefault(require("lodash"));
10
+ const velodrome_slipstream_1 = require("../velodrome-slipstream/velodrome-slipstream");
11
+ const constants_1 = require("../../constants");
12
+ class PharaohV3 extends velodrome_slipstream_1.VelodromeSlipstream {
13
+ static dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(lodash_1.default.pick(config_1.UniswapV3Config, ['PharaohV3']));
14
+ async getTopPoolsForToken(tokenAddress, limit) {
15
+ if (!this.config.subgraphURL)
16
+ return [];
17
+ const _tokenAddress = tokenAddress.toLowerCase();
18
+ const res = await this._querySubgraph(`query ($token: Bytes!, $count: Int) {
19
+ pools0: clPools(
20
+ orderBy: totalValueLockedToken0
21
+ orderDirection: desc
22
+ first: $count
23
+ skip: 0
24
+ where: { token0: $token }
25
+ ) {
26
+ id
27
+ token0 {
28
+ id
29
+ decimals
30
+ }
31
+ token1 {
32
+ id
33
+ decimals
34
+ }
35
+ }
36
+
37
+ pools1: clPools(
38
+ orderBy: totalValueLockedToken1
39
+ orderDirection: desc
40
+ first: $count
41
+ skip: 0
42
+ where: { token1: $token }
43
+ ) {
44
+ id
45
+ token0 {
46
+ id
47
+ decimals
48
+ }
49
+ token1 {
50
+ id
51
+ decimals
52
+ }
53
+ }
54
+ }`, {
55
+ token: _tokenAddress,
56
+ count: limit,
57
+ });
58
+ if (!(res && res.pools0 && res.pools1)) {
59
+ this.logger.error(`Error_${this.dexKey}_Subgraph: couldn't fetch pools from subgraph`);
60
+ return [];
61
+ }
62
+ const pools0 = res.pools0.map((pool) => ({
63
+ exchange: this.dexKey,
64
+ address: pool.id.toLowerCase(),
65
+ connectorTokens: [
66
+ {
67
+ address: pool.token1.id.toLowerCase(),
68
+ decimals: Number(pool.token1.decimals),
69
+ },
70
+ ],
71
+ liquidityUSD: 0,
72
+ }));
73
+ const pools1 = res.pools1.map((pool) => ({
74
+ exchange: this.dexKey,
75
+ address: pool.id.toLowerCase(),
76
+ connectorTokens: [
77
+ {
78
+ address: pool.token0.id.toLowerCase(),
79
+ decimals: Number(pool.token0.decimals),
80
+ },
81
+ ],
82
+ liquidityUSD: 0,
83
+ }));
84
+ const allPools = [...pools0, ...pools1];
85
+ if (allPools.length === 0)
86
+ return [];
87
+ const poolBalances = await this._getPoolBalances(allPools.map(p => [
88
+ p.address,
89
+ tokenAddress,
90
+ p.connectorTokens[0].address,
91
+ ]));
92
+ const tokensAmounts = allPools
93
+ .map((p, i) => {
94
+ return [
95
+ [tokenAddress, poolBalances[i][0]],
96
+ [p.connectorTokens[0].address, poolBalances[i][1]],
97
+ ];
98
+ })
99
+ .flat();
100
+ const poolUsdBalances = await this.dexHelper.getUsdTokenAmounts(tokensAmounts);
101
+ const pools = allPools.map((pool, i) => {
102
+ const tokenUsdBalance = poolUsdBalances[i * 2];
103
+ const connectorTokenUsdBalance = poolUsdBalances[i * 2 + 1];
104
+ const tokenUsdLiquidity = tokenUsdBalance
105
+ ? tokenUsdBalance * constants_1.UNISWAPV3_EFFICIENCY_FACTOR
106
+ : null;
107
+ const connectorTokenUsdLiquidity = connectorTokenUsdBalance
108
+ ? connectorTokenUsdBalance * constants_1.UNISWAPV3_EFFICIENCY_FACTOR
109
+ : null;
110
+ if (tokenUsdLiquidity) {
111
+ pool.connectorTokens[0] = {
112
+ ...pool.connectorTokens[0],
113
+ liquidityUSD: tokenUsdLiquidity,
114
+ };
115
+ }
116
+ const liquidityUSD = connectorTokenUsdLiquidity || tokenUsdLiquidity || 0;
117
+ return {
118
+ ...pool,
119
+ liquidityUSD,
120
+ };
121
+ });
122
+ return pools
123
+ .sort((a, b) => b.liquidityUSD - a.liquidityUSD)
124
+ .slice(0, limit);
125
+ }
126
+ }
127
+ exports.PharaohV3 = PharaohV3;
128
+ //# sourceMappingURL=pharaoh-v3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pharaoh-v3.js","sourceRoot":"","sources":["../../../../../src/dex/uniswap-v3/forks/pharaoh-v3/pharaoh-v3.ts"],"names":[],"mappings":";;;;;;AACA,yCAA+C;AAC/C,6CAA0D;AAC1D,oDAAuB;AACvB,uFAAmF;AAGnF,+CAA8D;AAkB9D,MAAa,SAAU,SAAQ,0CAAmB;I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AAM,wBAAwB,GAAG,eAAe,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YAE5D,MAAM,iBAAiB,GAAG,eAAe;gBACvC,CAAC,CAAC,eAAe,GAAG,uCAA2B;gBAC/C,CAAC,CAAC,IAAI,CAAC;YAET,MAAM,0BAA0B,GAAG,wBAAwB;gBACzD,CAAC,CAAC,wBAAwB,GAAG,uCAA2B;gBACxD,CAAC,CAAC,IAAI,CAAC;YAET,IAAI,iBAAiB,EAAE,CAAC;gBACtB,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG;oBACxB,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;oBAC1B,YAAY,EAAE,iBAAiB;iBAChC,CAAC;YACJ,CAAC;YAED,MAAM,YAAY,GAAG,0BAA0B,IAAI,iBAAiB,IAAI,CAAC,CAAC;YAE1E,OAAO;gBACL,GAAG,IAAI;gBACP,YAAY;aACb,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK;aACT,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY,CAAC;aAC/C,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACrB,CAAC;;AA9IH,8BA+IC"}
@@ -0,0 +1,4 @@
1
+ import { MultiResult } from '../../../../lib/multi-wrapper';
2
+ import { BytesLike } from 'ethers';
3
+ import { DecodedStateMultiCallResultWithRelativeBitmaps } from '../../types';
4
+ export declare function decodeStateMultiCallResultWithRelativeBitmaps(result: MultiResult<BytesLike> | BytesLike): DecodedStateMultiCallResultWithRelativeBitmaps;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeStateMultiCallResultWithRelativeBitmaps = decodeStateMultiCallResultWithRelativeBitmaps;
4
+ const ethers_1 = require("ethers");
5
+ const decoders_1 = require("../../../../lib/decoders");
6
+ const ts_essentials_1 = require("ts-essentials");
7
+ function decodeStateMultiCallResultWithRelativeBitmaps(result) {
8
+ const [isSuccess, toDecode] = (0, decoders_1.extractSuccessAndValue)(result);
9
+ (0, ts_essentials_1.assert)(isSuccess && toDecode !== '0x', `decodeStateMultiCallResultWithRelativeBitmaps failed to get decodable result: ${result}`);
10
+ const decoded = ethers_1.ethers.utils.defaultAbiCoder.decode([
11
+ // I don't want to pass here any interface, so I just use it in ethers format
12
+ `
13
+ tuple(
14
+ address pool,
15
+ uint256 blockTimestamp,
16
+ tuple(
17
+ uint160 sqrtPriceX96,
18
+ int24 tick,
19
+ uint16 observationIndex,
20
+ uint16 observationCardinality,
21
+ uint16 observationCardinalityNext,
22
+ uint24 feeProtocol,
23
+ bool unlocked,
24
+ ) slot0,
25
+ uint128 liquidity,
26
+ int24 tickSpacing,
27
+ uint128 maxLiquidityPerTick,
28
+ tuple(
29
+ uint32 blockTimestamp,
30
+ int56 tickCumulative,
31
+ uint160 secondsPerLiquidityCumulativeX128,
32
+ bool initialized,
33
+ ) observation,
34
+ tuple(
35
+ int16 index,
36
+ uint256 value
37
+ )[] tickBitmap,
38
+ tuple(
39
+ int24 index,
40
+ tuple(
41
+ uint128 liquidityGross,
42
+ int128 liquidityNet,
43
+ int56 tickCumulativeOutside,
44
+ uint160 secondsPerLiquidityOutsideX128,
45
+ uint32 secondsOutside,
46
+ bool initialized,
47
+ ) value,
48
+ )[] ticks
49
+ )
50
+ `,
51
+ ], toDecode)[0];
52
+ // This conversion is not precise, because when we decode, we have more values
53
+ // But I typed only the ones that are used later
54
+ return decoded;
55
+ }
56
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../src/dex/uniswap-v3/forks/pharaoh-v3/utils.ts"],"names":[],"mappings":";;AAMA,sGA2DC;AAhED,mCAA2C;AAE3C,uDAAkE;AAClE,iDAAuC;AAEvC,SAAgB,6CAA6C,CAC3D,MAA0C;IAE1C,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,IAAA,iCAAsB,EAAC,MAAM,CAAC,CAAC;IAE7D,IAAA,sBAAM,EACJ,SAAS,IAAI,QAAQ,KAAK,IAAI,EAC9B,iFAAiF,MAAM,EAAE,CAC1F,CAAC;IAEF,MAAM,OAAO,GAAG,eAAM,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,CACjD;QACE,6EAA6E;QAC7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsCD;KACA,EACD,QAAQ,CACT,CAAC,CAAC,CAAC,CAAC;IAEL,8EAA8E;IAC9E,gDAAgD;IAChD,OAAO,OAAyD,CAAC;AACnE,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { Interface } from 'ethers/lib/utils';
2
+ import { InitializeStateOptions, StatefulEventSubscriber } from '../../../../stateful-event-subscriber';
3
+ import { IDexHelper } from '../../../../dex-helper';
4
+ import { Logger, Log, Address } from '../../../../types';
5
+ import { DeepReadonly } from 'ts-essentials';
6
+ type ProtocolFeeSettings = {
7
+ recipient: Address;
8
+ protocolFeePpm: number;
9
+ referralFeePpm: number;
10
+ };
11
+ export type ArenaFeeHelperState = {
12
+ protocolFeePpm: ProtocolFeeSettings['protocolFeePpm'];
13
+ poolIdToTotalFeePpm: Record<string, bigint>;
14
+ };
15
+ export declare class ArenaFeeHelper extends StatefulEventSubscriber<ArenaFeeHelperState> {
16
+ readonly parentName: string;
17
+ protected network: number;
18
+ protected dexHelper: IDexHelper;
19
+ protected ArenaFeeHelperIface: Interface;
20
+ handlers: {
21
+ [event: string]: (event: any, state: DeepReadonly<ArenaFeeHelperState>, log: Readonly<Log>) => DeepReadonly<ArenaFeeHelperState> | null;
22
+ };
23
+ logDecoder: (log: Log) => any;
24
+ private readonly feeHelperAddress;
25
+ private readonly feeHelper;
26
+ protected poolIds: Set<string>;
27
+ constructor(parentName: string, network: number, dexHelper: IDexHelper, logger: Logger, ArenaFeeHelperIface?: Interface);
28
+ initialize(blockNumber: number, options?: InitializeStateOptions<ArenaFeeHelperState>): Promise<void>;
29
+ protected processLog(state: DeepReadonly<ArenaFeeHelperState>, log: Readonly<Log>): DeepReadonly<ArenaFeeHelperState> | null;
30
+ generateState(blockNumber?: number | 'latest'): Promise<DeepReadonly<ArenaFeeHelperState>>;
31
+ addPoolId(poolId: string): void;
32
+ getOrGenerateState(blockNumber: number): Promise<ArenaFeeHelperState>;
33
+ handleFeeArraySet(event: any, state: DeepReadonly<ArenaFeeHelperState>, log: Readonly<Log>): DeepReadonly<ArenaFeeHelperState> | null;
34
+ handleProtocolFeeSettingsSet(event: any, state: DeepReadonly<ArenaFeeHelperState>, log: Readonly<Log>): DeepReadonly<ArenaFeeHelperState> | null;
35
+ }
36
+ export {};
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ArenaFeeHelper = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const utils_1 = require("ethers/lib/utils");
9
+ const stateful_event_subscriber_1 = require("../../../../stateful-event-subscriber");
10
+ const arena_fee_helper_abi_json_1 = __importDefault(require("../../../../abi/uniswap-v4/hooks/arena/arena-fee-helper.abi.json"));
11
+ const config_1 = require("./config");
12
+ const utils_2 = require("../../../../utils");
13
+ const decoders_1 = require("../../../../lib/decoders");
14
+ class ArenaFeeHelper extends stateful_event_subscriber_1.StatefulEventSubscriber {
15
+ parentName;
16
+ network;
17
+ dexHelper;
18
+ ArenaFeeHelperIface;
19
+ handlers = {};
20
+ logDecoder;
21
+ feeHelperAddress;
22
+ feeHelper;
23
+ poolIds = new Set();
24
+ constructor(parentName, network, dexHelper, logger, ArenaFeeHelperIface = new utils_1.Interface(arena_fee_helper_abi_json_1.default)) {
25
+ super(parentName, 'ArenaFeeHelper', dexHelper, logger, false);
26
+ this.parentName = parentName;
27
+ this.network = network;
28
+ this.dexHelper = dexHelper;
29
+ this.ArenaFeeHelperIface = ArenaFeeHelperIface;
30
+ this.feeHelperAddress =
31
+ config_1.ArenaHookConfig[this.network].feeHelperAddress.toLowerCase();
32
+ this.feeHelper = new ethers_1.Contract(this.feeHelperAddress, arena_fee_helper_abi_json_1.default, dexHelper.provider);
33
+ this.logDecoder = (log) => this.ArenaFeeHelperIface.parseLog(log);
34
+ this.addressesSubscribed = [this.feeHelperAddress];
35
+ this.handlers['FeeArraySet'] = this.handleFeeArraySet.bind(this);
36
+ this.handlers['ProtocolFeeSettingsSet'] =
37
+ this.handleProtocolFeeSettingsSet.bind(this);
38
+ }
39
+ async initialize(blockNumber, options) {
40
+ return super.initialize(blockNumber, options);
41
+ }
42
+ processLog(state, log) {
43
+ try {
44
+ const event = this.logDecoder(log);
45
+ if (event.name in this.handlers) {
46
+ return this.handlers[event.name](event, state, log);
47
+ }
48
+ }
49
+ catch (e) {
50
+ (0, utils_2.catchParseLogError)(e, this.logger);
51
+ }
52
+ return null;
53
+ }
54
+ async generateState(blockNumber) {
55
+ const protocolFeeSettings = await this.feeHelper.protocolFeeSettings();
56
+ const poolIdToTotalFeePpm = {};
57
+ const calls = [];
58
+ const poolIds = Array.from(this.poolIds);
59
+ for (const poolId of poolIds) {
60
+ calls.push({
61
+ target: this.feeHelperAddress,
62
+ callData: this.feeHelper.interface.encodeFunctionData('poolIdToTotalFeePpm', [poolId]),
63
+ decodeFunction: decoders_1.uint256ToBigInt,
64
+ });
65
+ }
66
+ const data = await this.dexHelper.multiWrapper.tryAggregate(false, calls);
67
+ data.forEach((result, index) => {
68
+ poolIdToTotalFeePpm[poolIds[index]] = result.success
69
+ ? result.returnData
70
+ : 0n;
71
+ });
72
+ return {
73
+ protocolFeePpm: protocolFeeSettings.protocolFeePpm,
74
+ poolIdToTotalFeePpm,
75
+ };
76
+ }
77
+ addPoolId(poolId) {
78
+ if (this.poolIds.has(poolId))
79
+ return;
80
+ this.poolIds.add(poolId);
81
+ const state = this.getStaleState();
82
+ if (state) {
83
+ const poolIdToTotalFeePpm = { ...state.poolIdToTotalFeePpm };
84
+ if (!(poolId in poolIdToTotalFeePpm)) {
85
+ poolIdToTotalFeePpm[poolId] = 0n;
86
+ }
87
+ this.setState({
88
+ ...state,
89
+ poolIdToTotalFeePpm,
90
+ }, this.stateBlockNumber);
91
+ }
92
+ }
93
+ async getOrGenerateState(blockNumber) {
94
+ let state = this.getState(blockNumber);
95
+ if (!state) {
96
+ state = await this.generateState(blockNumber);
97
+ this.setState(state, blockNumber);
98
+ }
99
+ return state;
100
+ }
101
+ handleFeeArraySet(event, state, log) {
102
+ const poolId = event.args.poolId.toLowerCase();
103
+ const fees = event.args.fees;
104
+ let total = 0n;
105
+ for (const fee of fees) {
106
+ total += BigInt(fee.feePpm.toString());
107
+ }
108
+ return {
109
+ protocolFeePpm: state.protocolFeePpm,
110
+ poolIdToTotalFeePpm: {
111
+ ...state.poolIdToTotalFeePpm,
112
+ [poolId]: total,
113
+ },
114
+ };
115
+ }
116
+ handleProtocolFeeSettingsSet(event, state, log) {
117
+ const settings = event.args.settings;
118
+ return {
119
+ protocolFeePpm: Number(settings.protocolFeePpm),
120
+ poolIdToTotalFeePpm: { ...state.poolIdToTotalFeePpm },
121
+ };
122
+ }
123
+ }
124
+ exports.ArenaFeeHelper = ArenaFeeHelper;
125
+ //# sourceMappingURL=arena-fee-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arena-fee-helper.js","sourceRoot":"","sources":["../../../../../src/dex/uniswap-v4/hooks/arena/arena-fee-helper.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAkC;AAClC,4CAA6C;AAC7C,qFAG+C;AAG/C,iIAAiG;AAEjG,qCAA2C;AAC3C,6CAAuD;AAEvD,uDAA2D;AAkB3D,MAAa,cAAe,SAAQ,mDAA4C;IAkBnE;IACC;IACA;IAEA;IArBZ,QAAQ,GAMJ,EAAE,CAAC;IAEP,UAAU,CAAoB;IAEb,gBAAgB,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AAI,KAAK,GAAG,EAAE,CAAC;QACf,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,KAAK,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzC,CAAC;QAED,OAAO;YACL,cAAc,EAAE,KAAK,CAAC,cAAc;YACpC,mBAAmB,EAAE;gBACnB,GAAG,KAAK,CAAC,mBAAmB;gBAC5B,CAAC,MAAM,CAAC,EAAE,KAAK;aAChB;SACF,CAAC;IACJ,CAAC;IAED,4BAA4B,CAC1B,KAAU,EACV,KAAwC,EACxC,GAAkB;QAElB,MAAM,QAAQ,GAAwB,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;QAE1D,OAAO;YACL,cAAc,EAAE,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC;YAC/C,mBAAmB,EAAE,EAAE,GAAG,KAAK,CAAC,mBAAmB,EAAE;SACtD,CAAC;IACJ,CAAC;CACF;AApKD,wCAoKC"}
@@ -0,0 +1,21 @@
1
+ import { IDexHelper } from '../../../../dex-helper';
2
+ import { Network } from '../../../../constants';
3
+ import { Logger } from '../../../../types';
4
+ import { PoolKey } from '../../types';
5
+ import { SwapParams, BalanceDelta, HooksPermissions, IBaseHook } from '../types';
6
+ import { ArenaFeeHelper } from './arena-fee-helper';
7
+ export declare class ArenaHook implements IBaseHook {
8
+ readonly dexHelper: IDexHelper;
9
+ readonly network: Network;
10
+ readonly logger: Logger;
11
+ readonly feeHelperAddress: string;
12
+ readonly name: string;
13
+ readonly address: string;
14
+ readonly arenaFeeHelper: ArenaFeeHelper;
15
+ constructor(dexHelper: IDexHelper, network: Network, logger: Logger, feeHelperAddress?: string);
16
+ registerPool(poolId: string, _poolKey: PoolKey): void;
17
+ initialize(blockNumber: number): Promise<void>;
18
+ getHookPermissions(): HooksPermissions;
19
+ afterSwap(_sender: string, key: PoolKey, params: SwapParams, delta: BalanceDelta, _hookData: string): bigint;
20
+ private getTotalFeePpm;
21
+ }
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArenaHook = void 0;
4
+ const config_1 = require("./config");
5
+ const utils_1 = require("../../utils");
6
+ const utils_2 = require("../../../../utils");
7
+ const arena_fee_helper_1 = require("./arena-fee-helper");
8
+ const MAX_HOOK_FEE = 1000000n; // 100%
9
+ const UINT128_MAX = (1n << 128n) - 1n;
10
+ const INT128_MAX = (1n << 127n) - 1n;
11
+ class ArenaHook {
12
+ dexHelper;
13
+ network;
14
+ logger;
15
+ feeHelperAddress;
16
+ name = this.constructor.name;
17
+ address;
18
+ arenaFeeHelper;
19
+ constructor(dexHelper, network, logger, feeHelperAddress = config_1.ArenaHookConfig[network].feeHelperAddress.toLowerCase()) {
20
+ this.dexHelper = dexHelper;
21
+ this.network = network;
22
+ this.logger = logger;
23
+ this.feeHelperAddress = feeHelperAddress;
24
+ this.address = config_1.ArenaHookConfig[network].hookAddress.toLowerCase();
25
+ this.arenaFeeHelper = new arena_fee_helper_1.ArenaFeeHelper(this.name, network, dexHelper, logger);
26
+ }
27
+ registerPool(poolId, _poolKey) {
28
+ this.arenaFeeHelper.addPoolId(poolId.toLowerCase());
29
+ }
30
+ async initialize(blockNumber) {
31
+ if (!this.arenaFeeHelper.isInitialized) {
32
+ await this.arenaFeeHelper.initialize(blockNumber);
33
+ }
34
+ }
35
+ getHookPermissions() {
36
+ return {
37
+ beforeInitialize: true,
38
+ afterInitialize: false,
39
+ beforeAddLiquidity: false,
40
+ afterAddLiquidity: false,
41
+ beforeRemoveLiquidity: false,
42
+ afterRemoveLiquidity: false,
43
+ beforeSwap: false,
44
+ afterSwap: true,
45
+ beforeDonate: false,
46
+ afterDonate: false,
47
+ beforeSwapReturnDelta: false,
48
+ afterSwapReturnDelta: true,
49
+ afterAddLiquidityReturnDelta: false,
50
+ afterRemoveLiquidityReturnDelta: false,
51
+ };
52
+ }
53
+ afterSwap(_sender, key, params, delta, _hookData) {
54
+ const { amountSpecified, zeroForOne } = params;
55
+ const isExactInput = BigInt(amountSpecified) < 0n;
56
+ // Determine the unspecified (output) delta based on swap direction and type:
57
+ // - ExactInput + zeroForOne: input is token0, output is token1 (amount1)
58
+ // - ExactInput + oneForZero: input is token1, output is token0 (amount0)
59
+ // - ExactOutput + zeroForOne: output is token1, input is token0 (amount0 is unspecified)
60
+ // - ExactOutput + oneForZero: output is token0, input is token1 (amount1 is unspecified)
61
+ const outputIsToken1 = isExactInput === zeroForOne;
62
+ const unspecifiedDelta = outputIsToken1 ? delta.amount1 : delta.amount0;
63
+ if (unspecifiedDelta === 0n) {
64
+ return 0n;
65
+ }
66
+ const output = unspecifiedDelta < 0n ? -unspecifiedDelta : unspecifiedDelta;
67
+ (0, utils_2._require)(output <= UINT128_MAX, 'Unspecified output exceeds uint128', { output }, 'output <= UINT128_MAX');
68
+ const totalFeePpm = this.getTotalFeePpm((0, utils_1.toId)(key));
69
+ if (totalFeePpm === 0n) {
70
+ return output;
71
+ }
72
+ (0, utils_2._require)(totalFeePpm <= MAX_HOOK_FEE, 'Hook fee too large', { totalFeePpm }, 'totalFeePpm <= MAX_HOOK_FEE');
73
+ const feeAmount = (output * totalFeePpm) / MAX_HOOK_FEE;
74
+ (0, utils_2._require)(feeAmount <= INT128_MAX, 'Hook fee exceeds int128', { feeAmount }, 'feeAmount <= INT128_MAX');
75
+ // For exact input: user receives output minus fee
76
+ // For exact output: user must provide more input to cover fee
77
+ const netOutput = isExactInput ? output - feeAmount : output + feeAmount;
78
+ return netOutput;
79
+ }
80
+ getTotalFeePpm(poolId) {
81
+ if (!this.arenaFeeHelper?.isInitialized) {
82
+ return 0n;
83
+ }
84
+ const state = this.arenaFeeHelper.getStaleState();
85
+ if (!state) {
86
+ return 0n;
87
+ }
88
+ const poolFee = state.poolIdToTotalFeePpm[poolId] ?? 0n;
89
+ return poolFee + BigInt(state.protocolFeePpm);
90
+ }
91
+ }
92
+ exports.ArenaHook = ArenaHook;
93
+ //# sourceMappingURL=arena-hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arena-hook.js","sourceRoot":"","sources":["../../../../../src/dex/uniswap-v4/hooks/arena/arena-hook.ts"],"names":[],"mappings":";;;AACA,qCAA2C;AAU3C,uCAAmC;AACnC,6CAA6C;AAC7C,yDAAoD;AAEpD,MAAM,YAAY,GAAG,QAAU,CAAC,CAAC,OAAO;AACxC,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;AACtC,MAAM,UAAU,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;AAErC,MAAa,SAAS;IAMT;IACA;IACA;IACA;IARF,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC7B,OAAO,CAAS;IAChB,cAAc,CAAiB;IAExC,YACW,SAAqB,EACrB,OAAgB,EAChB,MAAc,EACd,mBAAmB,wBAAe,CACzC,OAAO,CACR,CAAC,gBAAgB,CAAC,WAAW,EAAE;QALvB,cAAS,GAAT,SAAS,CAAY;QACrB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,qBAAgB,GAAhB,gBAAgB,CAEO;QAEhC,IAAI,CAAC,OAAO,GAAG,wBAAe,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC;QAElE,IAAI,CAAC,cAAc,GAAG,IAAI,iCAAc,CACtC,IAAI,CAAC,IAAI,EACT,OAAO,EACP,SAAS,EACT,MAAM,CACP,CAAC;IACJ,CAAC;IAED,YAAY,CAAC,MAAc,EAAE,QAAiB;QAC5C,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,WAAmB;QAClC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC;YACvC,MAAM,IAAI,CAAC,cAAc,CAAC,UA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c,CAAC,IAAA,YAAI,EAAC,GAAG,CAAC,CAAC,CAAC;QAEnD,IAAI,WAAW,KAAK,EAAE,EAAE,CAAC;YACvB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,IAAA,gBAAQ,EACN,WAAW,IAAI,YAAY,EAC3B,oBAAoB,EACpB,EAAE,WAAW,EAAE,EACf,6BAA6B,CAC9B,CAAC;QAEF,MAAM,SAAS,GAAG,CAAC,MAAM,GAAG,WAAW,CAAC,GAAG,YAAY,CAAC;QAExD,IAAA,gBAAQ,EACN,SAAS,IAAI,UAAU,EACvB,yBAAyB,EACzB,EAAE,SAAS,EAAE,EACb,yBAAyB,CAC1B,CAAC;QAEF,kDAAkD;QAClD,8DAA8D;QAC9D,MAAM,SAAS,GAAG,YAAY,CAAC,CAAC,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,MAAM,GAAG,SAAS,CAAC;QAEzE,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,cAAc,CAAC,MAAc;QACnC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,aAAa,EAAE,CAAC;YACxC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC;QAClD,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,OAAO,GAAG,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAExD,OAAO,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAChD,CAAC;CACF;AA/HD,8BA+HC"}
@@ -0,0 +1,3 @@
1
+ import { HookConfig } from '../types';
2
+ import { HookParams } from './types';
3
+ export declare const ArenaHookConfig: HookConfig<HookParams>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArenaHookConfig = void 0;
4
+ const constants_1 = require("../../../../constants");
5
+ exports.ArenaHookConfig = {
6
+ [constants_1.Network.AVALANCHE]: {
7
+ hookAddress: '0xe32a5d788c568fc5a671255d17b618e70552e044',
8
+ feeHelperAddress: '0x537505da49b4249b576fc8d00028bfddf6189077',
9
+ },
10
+ };
11
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../../src/dex/uniswap-v4/hooks/arena/config.ts"],"names":[],"mappings":";;;AAEA,qDAAgD;AAEnC,QAAA,eAAe,GAA2B;IACrD,CAAC,mBAAO,CAAC,SAAS,CAAC,EAAE;QACnB,WAAW,EAAE,4CAA4C;QACzD,gBAAgB,EAAE,4CAA4C;KAC/D;CACF,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Address } from '@paraswap/core';
2
+ export type HookParams = {
3
+ hookAddress: Address;
4
+ feeHelperAddress: Address;
5
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/dex/uniswap-v4/hooks/arena/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,60 @@
1
+ import { PoolKey } from '../types';
2
+ import { IDexHelper } from '../../../dex-helper';
3
+ import { Network } from '../../../constants';
4
+ import { Logger } from '../../../types';
5
+ export type HookConfig<HookParams> = {
6
+ [network: number]: HookParams;
7
+ };
8
+ export interface BalanceDelta {
9
+ amount0: bigint;
10
+ amount1: bigint;
11
+ }
12
+ export interface BeforeSwapDelta {
13
+ amount0: bigint;
14
+ amount1: bigint;
15
+ }
16
+ export interface SwapParams {
17
+ zeroForOne: boolean;
18
+ amountSpecified: string;
19
+ sqrtPriceLimitX96: string;
20
+ }
21
+ export interface ModifyLiquidityParams {
22
+ tickLower: number;
23
+ tickUpper: number;
24
+ liquidityDelta: string;
25
+ salt: string;
26
+ }
27
+ export interface HooksPermissions {
28
+ beforeInitialize: boolean;
29
+ afterInitialize: boolean;
30
+ beforeAddLiquidity: boolean;
31
+ afterAddLiquidity: boolean;
32
+ beforeRemoveLiquidity: boolean;
33
+ afterRemoveLiquidity: boolean;
34
+ beforeSwap: boolean;
35
+ afterSwap: boolean;
36
+ beforeDonate: boolean;
37
+ afterDonate: boolean;
38
+ beforeSwapReturnDelta: boolean;
39
+ afterSwapReturnDelta: boolean;
40
+ afterAddLiquidityReturnDelta: boolean;
41
+ afterRemoveLiquidityReturnDelta: boolean;
42
+ }
43
+ export interface IBaseHook {
44
+ readonly name: string;
45
+ readonly address: string;
46
+ getHookPermissions(): HooksPermissions;
47
+ registerPool(poolId: string, poolKey: PoolKey): void;
48
+ initialize(blockNumber: number): Promise<void>;
49
+ beforeInitialize?(sender: string, key: PoolKey, sqrtPriceX96: string): string;
50
+ afterInitialize?(sender: string, key: PoolKey, sqrtPriceX96: string, tick: number): string;
51
+ beforeAddLiquidity?(sender: string, key: PoolKey, params: ModifyLiquidityParams, hookData: string): string;
52
+ beforeRemoveLiquidity?(sender: string, key: PoolKey, params: ModifyLiquidityParams, hookData: string): string;
53
+ afterAddLiquidity?(sender: string, key: PoolKey, params: ModifyLiquidityParams, delta0: BalanceDelta, delta1: BalanceDelta, hookData: string): [string, BalanceDelta];
54
+ afterRemoveLiquidity?(sender: string, key: PoolKey, params: ModifyLiquidityParams, delta0: BalanceDelta, delta1: BalanceDelta, hookData: string): [string, BalanceDelta];
55
+ beforeSwap?(sender: string, key: PoolKey, params: SwapParams, hookData: string): [string, BeforeSwapDelta, number];
56
+ afterSwap?(sender: string, key: PoolKey, params: SwapParams, delta: BalanceDelta, hookData: string): bigint;
57
+ beforeDonate?(sender: string, key: PoolKey, amount0: string, amount1: string, hookData: string): string;
58
+ afterDonate?(sender: string, key: PoolKey, amount0: string, amount1: string, hookData: string): string;
59
+ }
60
+ export type HookConstructor = new (dexHelper: IDexHelper, network: Network, logger: Logger) => IBaseHook;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/dex/uniswap-v4/hooks/types.ts"],"names":[],"mappings":""}
@@ -1,5 +1,5 @@
1
1
  import { OptimalSwap, OptimalSwapExchange } from '@paraswap/core';
2
- import { DexExchangeParamWithBooleanNeedWrapNative } from '../types';
2
+ import { DexExchangeBuildParam } from '../types';
3
3
  export declare enum Flag {
4
4
  SEND_ETH_EQUAL_TO_FROM_AMOUNT_PLUS_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP = 18,// // (flag 18 mod 4) = case 2: sendEth equal to fromAmount + insert fromAmount, (flag 18 mod 3) = case 0: don't check balance after swap
5
5
  SEND_ETH_EQUAL_TO_FROM_AMOUNT_PLUS_INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP = 14,// (flag 14 mod 4) = case 2: sendEth equal to fromAmount + insert fromAmount, (flag 14 mod 3) = case 2: case 2: check "srcToken" balance after swap
@@ -53,10 +53,10 @@ export type GenericRouteSwaps<TSwap> = {
53
53
  export type RouteSwaps = GenericRouteSwaps<OptimalSwap>;
54
54
  export type RouteBuildSwaps = GenericRouteSwaps<BuildSwap>;
55
55
  export type BuildSwapExchange<T> = OptimalSwapExchange<T> & {
56
- dexParams: DexExchangeParamWithBooleanNeedWrapNative;
56
+ dexParams: DexExchangeBuildParam;
57
57
  wethDeposit: bigint;
58
58
  wethWithdraw: bigint;
59
59
  };
60
- export type BuildSwap = OptimalSwap & {
60
+ export type BuildSwap = Omit<OptimalSwap, 'swapExchanges'> & {
61
61
  swapExchanges: BuildSwapExchange<any>[];
62
62
  };