@paraswap/dex-lib 2.28.10-ramses-v2 → 2.28.10

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 (50) hide show
  1. package/build/abi/uniswap-v3/UniswapV3QuoterV2.abi.json +155 -0
  2. package/build/dex/index.js +0 -2
  3. package/build/dex/index.js.map +1 -1
  4. package/build/dex/uniswap-v3/config.js +0 -22
  5. package/build/dex/uniswap-v3/config.js.map +1 -1
  6. package/build/dex/uniswap-v3/types.d.ts +1 -6
  7. package/build/dex/uniswap-v3/types.js.map +1 -1
  8. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +2 -3
  9. package/build/dex/uniswap-v3/uniswap-v3-pool.js +2 -5
  10. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  11. package/build/dex/uniswap-v3/uniswap-v3.js +5 -9
  12. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  13. package/build/lib/multi-wrapper.js +3 -5
  14. package/build/lib/multi-wrapper.js.map +1 -1
  15. package/package.json +1 -1
  16. package/src/dex/index.ts +0 -2
  17. package/src/dex/uniswap-v3/config.ts +0 -22
  18. package/src/dex/uniswap-v3/types.ts +1 -7
  19. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +354 -445
  20. package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +3 -26
  21. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +4 -9
  22. package/src/dex/uniswap-v3/uniswap-v3.ts +4 -9
  23. package/src/lib/multi-wrapper.ts +4 -4
  24. package/tests/constants-e2e.ts +5 -1
  25. package/src/abi/RamsesV2Pool.abi.json +0 -1554
  26. package/src/abi/RamsesV2StateMulticall.abi.json +0 -891
  27. package/src/dex/ramses-v2/config.ts +0 -31
  28. package/src/dex/ramses-v2/constants.ts +0 -41
  29. package/src/dex/ramses-v2/contract-math/BitMath.ts +0 -90
  30. package/src/dex/ramses-v2/contract-math/FixedPoint128.ts +0 -3
  31. package/src/dex/ramses-v2/contract-math/FixedPoint96.ts +0 -4
  32. package/src/dex/ramses-v2/contract-math/FullMath.ts +0 -30
  33. package/src/dex/ramses-v2/contract-math/LiquidityMath.ts +0 -17
  34. package/src/dex/ramses-v2/contract-math/Oracle.ts +0 -226
  35. package/src/dex/ramses-v2/contract-math/SqrtPriceMath.ts +0 -226
  36. package/src/dex/ramses-v2/contract-math/SwapMath.ts +0 -139
  37. package/src/dex/ramses-v2/contract-math/Tick.ts +0 -82
  38. package/src/dex/ramses-v2/contract-math/TickBitMap.ts +0 -128
  39. package/src/dex/ramses-v2/contract-math/TickMath.ts +0 -211
  40. package/src/dex/ramses-v2/contract-math/UnsafeMath.ts +0 -5
  41. package/src/dex/ramses-v2/contract-math/uniswap-v3-math.ts +0 -666
  42. package/src/dex/ramses-v2/contract-math/utils.ts +0 -11
  43. package/src/dex/ramses-v2/ramses-v2-e2e.test.ts +0 -100
  44. package/src/dex/ramses-v2/ramses-v2-events.test.ts +0 -182
  45. package/src/dex/ramses-v2/ramses-v2-integration.test.ts +0 -462
  46. package/src/dex/ramses-v2/ramses-v2-pool.ts +0 -513
  47. package/src/dex/ramses-v2/ramses-v2.ts +0 -1136
  48. package/src/dex/ramses-v2/types.ts +0 -177
  49. package/src/dex/ramses-v2/utils.ts +0 -90
  50. package/src/dex/uniswap-v3/forks/ramses-v2/utils.ts +0 -72
@@ -1,177 +0,0 @@
1
- import { BigNumber } from 'ethers';
2
- import { NumberAsString } from '../../types';
3
- import { Address } from '../../types';
4
-
5
- export type OracleObservation = {
6
- blockTimestamp: bigint;
7
- tickCumulative: bigint;
8
- secondsPerLiquidityCumulativeX128: bigint;
9
- initialized: boolean;
10
- };
11
-
12
- export type OracleObservationCandidates = {
13
- beforeOrAt: OracleObservation;
14
- atOrAfter: OracleObservation;
15
- };
16
-
17
- export type TickInfo = {
18
- liquidityGross: bigint;
19
- liquidityNet: bigint;
20
- tickCumulativeOutside: bigint;
21
- secondsPerLiquidityOutsideX128: bigint;
22
- secondsOutside: bigint;
23
- initialized: boolean;
24
- };
25
-
26
- export type Slot0 = {
27
- sqrtPriceX96: bigint;
28
- tick: bigint;
29
- observationIndex: number;
30
- observationCardinality: number;
31
- observationCardinalityNext: number;
32
- feeProtocol: bigint;
33
- };
34
-
35
- export type PoolState = {
36
- pool: string;
37
- blockTimestamp: bigint;
38
- tickSpacing: bigint;
39
- fee: bigint;
40
- slot0: Slot0;
41
- liquidity: bigint;
42
- maxLiquidityPerTick: bigint;
43
- tickBitmap: Record<NumberAsString, bigint>;
44
- ticks: Record<NumberAsString, TickInfo>;
45
- observations: Record<number, OracleObservation>;
46
- isValid: boolean;
47
- startTickBitmap: bigint;
48
- lowestKnownTick: bigint;
49
- highestKnownTick: bigint;
50
- balance0: bigint;
51
- balance1: bigint;
52
- };
53
-
54
- export type RamsesV2Data = {
55
- path: {
56
- tokenIn: Address;
57
- tokenOut: Address;
58
- fee: NumberAsString;
59
- }[];
60
- isApproved?: boolean;
61
- };
62
-
63
- export type DexParams = {
64
- router: Address;
65
- quoter: Address;
66
- factory: Address;
67
- stateMulticall: Address;
68
- uniswapMulticall: Address;
69
- supportedFees: bigint[];
70
- chunksCount: number;
71
- deployer?: Address;
72
- subgraphURL: string;
73
- initHash: string;
74
- };
75
-
76
- export type RamsesV2SimpleSwapSellParam = {
77
- path: string;
78
- recipient: Address;
79
- deadline: string;
80
- amountIn: NumberAsString;
81
- amountOutMinimum: NumberAsString;
82
- };
83
-
84
- export type RamsesV2SimpleSwapBuyParam = {
85
- path: string;
86
- recipient: Address;
87
- deadline: string;
88
- amountOut: NumberAsString;
89
- amountInMaximum: NumberAsString;
90
- };
91
-
92
- export type RamsesV2SimpleSwapParams =
93
- | RamsesV2SimpleSwapSellParam
94
- | RamsesV2SimpleSwapBuyParam;
95
-
96
- export type RamsesV2Param = [
97
- fromToken: Address,
98
- toToken: Address,
99
- exchange: Address,
100
- fromAmount: NumberAsString,
101
- toAmount: NumberAsString,
102
- expectedAmount: NumberAsString,
103
- feePercent: NumberAsString,
104
- deadline: NumberAsString,
105
- partner: Address,
106
- isApproved: boolean,
107
- beneficiary: Address,
108
- path: string,
109
- permit: string,
110
- uuid: string,
111
- ];
112
-
113
- export enum RamsesV2Functions {
114
- exactInput = 'exactInput',
115
- exactOutput = 'exactOutput',
116
- }
117
-
118
- export type TickInfoMappings = {
119
- index: number;
120
- value: TickInfo;
121
- };
122
-
123
- export type TickBitMapMappings = {
124
- index: number;
125
- value: bigint;
126
- };
127
-
128
- export type OutputResult = {
129
- outputs: bigint[];
130
- tickCounts: number[];
131
- };
132
-
133
- // Just rewrote every type with BigNumber basically
134
-
135
- export type TickBitMapMappingsWithBigNumber = {
136
- index: number;
137
- value: BigNumber;
138
- };
139
-
140
- export type TickInfoWithBigNumber = {
141
- initialized: boolean;
142
- liquidityGross: BigNumber;
143
- liquidityNet: BigNumber;
144
- secondsOutside: number;
145
- secondsPerLiquidityOutsideX128: BigNumber;
146
- tickCumulativeOutside: BigNumber;
147
- };
148
-
149
- export type TickInfoMappingsWithBigNumber = {
150
- index: number;
151
- value: TickInfoWithBigNumber;
152
- };
153
-
154
- export type DecodedStateMultiCallResultWithRelativeBitmaps = {
155
- pool: Address;
156
- blockTimestamp: BigNumber;
157
- slot0: {
158
- feeProtocol: number;
159
- observationCardinality: number;
160
- observationCardinalityNext: number;
161
- observationIndex: number;
162
- sqrtPriceX96: BigNumber;
163
- tick: number;
164
- unlocked: boolean;
165
- };
166
- liquidity: BigNumber;
167
- tickSpacing: number;
168
- maxLiquidityPerTick: BigNumber;
169
- observation: {
170
- blockTimestamp: number;
171
- initialized: boolean;
172
- secondsPerLiquidityCumulativeX128: BigNumber;
173
- tickCumulative: BigNumber;
174
- };
175
- tickBitmap: TickBitMapMappingsWithBigNumber[];
176
- ticks: TickInfoMappingsWithBigNumber[];
177
- };
@@ -1,90 +0,0 @@
1
- import { BytesLike, ethers } from 'ethers';
2
- import { assert } from 'ts-essentials';
3
- import { extractSuccessAndValue } from '../../lib/decoders';
4
- import { MultiResult } from '../../lib/multi-wrapper';
5
- import { DexConfigMap } from '../../types';
6
- import {
7
- DexParams,
8
- DecodedStateMultiCallResultWithRelativeBitmaps,
9
- } from './types';
10
-
11
- export function getUniswapV3DexKey(UniswapV3Config: DexConfigMap<DexParams>) {
12
- const UniswapV3Keys = Object.keys(UniswapV3Config);
13
- if (UniswapV3Keys.length !== 1) {
14
- throw new Error(
15
- `UniswapV3 key in UniswapV3Config is not unique. Update relevant places (optimizer) or fix config issue. Received: ${JSON.stringify(
16
- UniswapV3Config,
17
- (_0, value) => (typeof value === 'bigint' ? value.toString() : value),
18
- )}`,
19
- );
20
- }
21
-
22
- return UniswapV3Keys[0].toLowerCase();
23
- }
24
-
25
- export function decodeStateMultiCallResultWithRelativeBitmaps(
26
- result: MultiResult<BytesLike> | BytesLike,
27
- ): DecodedStateMultiCallResultWithRelativeBitmaps {
28
- const [isSuccess, toDecode] = extractSuccessAndValue(result);
29
-
30
- assert(
31
- isSuccess && toDecode !== '0x',
32
- `decodeStateMultiCallResultWithRelativeBitmaps failed to get decodable result: ${result}`,
33
- );
34
-
35
- const decoded = ethers.utils.defaultAbiCoder.decode(
36
- [
37
- // I don't want to pass here any interface, so I just use it in ethers format
38
- `
39
- tuple(
40
- address pool,
41
- uint256 blockTimestamp,
42
- tuple(
43
- uint160 sqrtPriceX96,
44
- int24 tick,
45
- uint16 observationIndex,
46
- uint16 observationCardinality,
47
- uint16 observationCardinalityNext,
48
- uint8 feeProtocol,
49
- bool unlocked,
50
- ) slot0,
51
- uint128 liquidity,
52
- int24 tickSpacing,
53
- uint128 maxLiquidityPerTick,
54
- tuple(
55
- uint32 blockTimestamp,
56
- int56 tickCumulative,
57
- uint160 secondsPerLiquidityCumulativeX128,
58
- bool initialized,
59
- uint160 secondsPerBoostedLiquidityPeriodX128,
60
- uint32 boostedInRange,
61
- ) observation,
62
- tuple(
63
- int16 index,
64
- uint256 value
65
- )[] tickBitmap,
66
- tuple(
67
- int24 index,
68
- tuple(
69
- uint128 liquidityGross,
70
- int128 liquidityNet,
71
- uint128 cleanUnusedSlot,
72
- uint128 cleanUnusedSlot2,
73
- uint256 feeGrowthOutside0X128,
74
- uint256 feeGrowthOutside1X128,
75
- int56 tickCumulativeOutside,
76
- uint160 secondsPerLiquidityOutsideX128,
77
- uint32 secondsOutside,
78
- bool initialized,
79
- ) value,
80
- )[] ticks
81
- )
82
- `,
83
- ],
84
- toDecode,
85
- )[0];
86
-
87
- // This conversion is not precise, because when we decode, we have more values
88
- // But I typed only the ones that are used later
89
- return decoded as DecodedStateMultiCallResultWithRelativeBitmaps;
90
- }
@@ -1,72 +0,0 @@
1
- import { MultiResult } from '../../../../lib/multi-wrapper';
2
- import { BytesLike, ethers } from 'ethers';
3
- import { DecodedStateMultiCallResultWithRelativeBitmaps } from '../../../ramses-v2/types';
4
- import { extractSuccessAndValue } from '../../../../lib/decoders';
5
- import { assert } from 'ts-essentials';
6
-
7
- export function decodeStateMultiCallResultWithRelativeBitmaps(
8
- result: MultiResult<BytesLike> | BytesLike,
9
- ): DecodedStateMultiCallResultWithRelativeBitmaps {
10
- const [isSuccess, toDecode] = extractSuccessAndValue(result);
11
-
12
- assert(
13
- isSuccess && toDecode !== '0x',
14
- `decodeStateMultiCallResultWithRelativeBitmaps failed to get decodable result: ${result}`,
15
- );
16
-
17
- const decoded = ethers.utils.defaultAbiCoder.decode(
18
- [
19
- // I don't want to pass here any interface, so I just use it in ethers format
20
- `
21
- tuple(
22
- address pool,
23
- uint256 blockTimestamp,
24
- tuple(
25
- uint160 sqrtPriceX96,
26
- int24 tick,
27
- uint16 observationIndex,
28
- uint16 observationCardinality,
29
- uint16 observationCardinalityNext,
30
- uint8 feeProtocol,
31
- bool unlocked,
32
- ) slot0,
33
- uint128 liquidity,
34
- int24 tickSpacing,
35
- uint128 maxLiquidityPerTick,
36
- tuple(
37
- uint32 blockTimestamp,
38
- int56 tickCumulative,
39
- uint160 secondsPerLiquidityCumulativeX128,
40
- bool initialized,
41
- uint160 secondsPerBoostedLiquidityPeriodX128,
42
- uint32 boostedInRange,
43
- ) observation,
44
- tuple(
45
- int16 index,
46
- uint256 value
47
- )[] tickBitmap,
48
- tuple(
49
- int24 index,
50
- tuple(
51
- uint128 liquidityGross,
52
- int128 liquidityNet,
53
- uint128 cleanUnusedSlot,
54
- uint128 cleanUnusedSlot2,
55
- uint256 feeGrowthOutside0X128,
56
- uint256 feeGrowthOutside1X128,
57
- int56 tickCumulativeOutside,
58
- uint160 secondsPerLiquidityOutsideX128,
59
- uint32 secondsOutside,
60
- bool initialized,
61
- ) value,
62
- )[] ticks
63
- )
64
- `,
65
- ],
66
- toDecode,
67
- )[0];
68
-
69
- // This conversion is not precise, because when we decode, we have more values
70
- // But I typed only the ones that are used later
71
- return decoded as DecodedStateMultiCallResultWithRelativeBitmaps;
72
- }