@paraswap/dex-lib 2.42.3 → 2.42.4-baseswap
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.
- package/build/dex/balancer-v1/balancer-v1.js +21 -10
- package/build/dex/balancer-v1/balancer-v1.js.map +1 -1
- package/build/dex/balancer-v1/config.d.ts +2 -1
- package/build/dex/balancer-v1/config.js +3 -2
- package/build/dex/balancer-v1/config.js.map +1 -1
- package/build/dex/baseswap-v3/baseswap-v3-factory.d.ts +26 -0
- package/build/dex/baseswap-v3/baseswap-v3-factory.js +44 -0
- package/build/dex/baseswap-v3/baseswap-v3-factory.js.map +1 -0
- package/build/dex/baseswap-v3/baseswap-v3-pool.d.ts +46 -0
- package/build/dex/baseswap-v3/baseswap-v3-pool.js +312 -0
- package/build/dex/baseswap-v3/baseswap-v3-pool.js.map +1 -0
- package/build/dex/baseswap-v3/baseswap-v3.d.ts +71 -0
- package/build/dex/baseswap-v3/baseswap-v3.js +752 -0
- package/build/dex/baseswap-v3/baseswap-v3.js.map +1 -0
- package/build/dex/baseswap-v3/config.d.ts +9 -0
- package/build/dex/baseswap-v3/config.js +48 -0
- package/build/dex/baseswap-v3/config.js.map +1 -0
- package/build/dex/baseswap-v3/constants.d.ts +28 -0
- package/build/dex/baseswap-v3/constants.js +35 -0
- package/build/dex/baseswap-v3/constants.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/BitMath.d.ts +4 -0
- package/build/dex/baseswap-v3/contract-math/BitMath.js +93 -0
- package/build/dex/baseswap-v3/contract-math/BitMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint128.d.ts +3 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint128.js +8 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint128.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint96.d.ts +4 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint96.js +9 -0
- package/build/dex/baseswap-v3/contract-math/FixedPoint96.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/FullMath.d.ts +4 -0
- package/build/dex/baseswap-v3/contract-math/FullMath.js +19 -0
- package/build/dex/baseswap-v3/contract-math/FullMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/LiquidityMath.d.ts +3 -0
- package/build/dex/baseswap-v3/contract-math/LiquidityMath.js +22 -0
- package/build/dex/baseswap-v3/contract-math/LiquidityMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/Oracle.d.ts +10 -0
- package/build/dex/baseswap-v3/contract-math/Oracle.js +133 -0
- package/build/dex/baseswap-v3/contract-math/Oracle.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.d.ts +10 -0
- package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js +91 -0
- package/build/dex/baseswap-v3/contract-math/SqrtPriceMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/SwapMath.d.ts +8 -0
- package/build/dex/baseswap-v3/contract-math/SwapMath.js +70 -0
- package/build/dex/baseswap-v3/contract-math/SwapMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/Tick.d.ts +7 -0
- package/build/dex/baseswap-v3/contract-math/Tick.js +45 -0
- package/build/dex/baseswap-v3/contract-math/Tick.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/TickBitMap.d.ts +7 -0
- package/build/dex/baseswap-v3/contract-math/TickBitMap.js +84 -0
- package/build/dex/baseswap-v3/contract-math/TickBitMap.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/TickMath.d.ts +8 -0
- package/build/dex/baseswap-v3/contract-math/TickMath.js +162 -0
- package/build/dex/baseswap-v3/contract-math/TickMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/UnsafeMath.d.ts +3 -0
- package/build/dex/baseswap-v3/contract-math/UnsafeMath.js +10 -0
- package/build/dex/baseswap-v3/contract-math/UnsafeMath.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.d.ts +37 -0
- package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js +393 -0
- package/build/dex/baseswap-v3/contract-math/uniswap-v3-math.js.map +1 -0
- package/build/dex/baseswap-v3/contract-math/utils.d.ts +7 -0
- package/build/dex/baseswap-v3/contract-math/utils.js +42 -0
- package/build/dex/baseswap-v3/contract-math/utils.js.map +1 -0
- package/build/dex/baseswap-v3/types.d.ts +164 -0
- package/build/dex/baseswap-v3/types.js +9 -0
- package/build/dex/baseswap-v3/types.js.map +1 -0
- package/build/dex/baseswap-v3/utils.d.ts +6 -0
- package/build/dex/baseswap-v3/utils.js +65 -0
- package/build/dex/baseswap-v3/utils.js.map +1 -0
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/package.json +1 -1
- package/src/dex/balancer-v1/balancer-v1.ts +32 -13
- package/src/dex/balancer-v1/config.ts +2 -1
- package/src/dex/baseswap-v3/baseswap-v3-e2e.test.ts +129 -0
- package/src/dex/baseswap-v3/baseswap-v3-events.test.ts +141 -0
- package/src/dex/baseswap-v3/baseswap-v3-factory.ts +73 -0
- package/src/dex/baseswap-v3/baseswap-v3-integration.test.ts +472 -0
- package/src/dex/baseswap-v3/baseswap-v3-pool.ts +519 -0
- package/src/dex/baseswap-v3/baseswap-v3.ts +1243 -0
- package/src/dex/baseswap-v3/config.ts +53 -0
- package/src/dex/baseswap-v3/constants.ts +41 -0
- package/src/dex/baseswap-v3/contract-math/BitMath.ts +90 -0
- package/src/dex/baseswap-v3/contract-math/FixedPoint128.ts +3 -0
- package/src/dex/baseswap-v3/contract-math/FixedPoint96.ts +4 -0
- package/src/dex/baseswap-v3/contract-math/FullMath.ts +30 -0
- package/src/dex/baseswap-v3/contract-math/LiquidityMath.ts +17 -0
- package/src/dex/baseswap-v3/contract-math/Oracle.ts +226 -0
- package/src/dex/baseswap-v3/contract-math/SqrtPriceMath.ts +226 -0
- package/src/dex/baseswap-v3/contract-math/SwapMath.ts +139 -0
- package/src/dex/baseswap-v3/contract-math/Tick.ts +82 -0
- package/src/dex/baseswap-v3/contract-math/TickBitMap.ts +123 -0
- package/src/dex/baseswap-v3/contract-math/TickMath.ts +211 -0
- package/src/dex/baseswap-v3/contract-math/UnsafeMath.ts +5 -0
- package/src/dex/baseswap-v3/contract-math/uniswap-v3-math.ts +666 -0
- package/src/dex/baseswap-v3/contract-math/utils.ts +55 -0
- package/src/dex/baseswap-v3/types.ts +191 -0
- package/src/dex/baseswap-v3/utils.ts +83 -0
- package/src/dex/index.ts +2 -0
- package/tests/constants-e2e.ts +1 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { BigNumber, BytesLike } from 'ethers';
|
|
2
|
+
import { NumberAsString } from '../../types';
|
|
3
|
+
import { Address } from '../../types';
|
|
4
|
+
import { AbiItem } from 'web3-utils';
|
|
5
|
+
import { MultiResult } from '../../lib/multi-wrapper';
|
|
6
|
+
import { BaseswapV3EventPool } from './baseswap-v3-pool';
|
|
7
|
+
|
|
8
|
+
export type OracleObservation = {
|
|
9
|
+
blockTimestamp: bigint;
|
|
10
|
+
tickCumulative: bigint;
|
|
11
|
+
secondsPerLiquidityCumulativeX128: bigint;
|
|
12
|
+
initialized: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type OracleObservationCandidates = {
|
|
16
|
+
beforeOrAt: OracleObservation;
|
|
17
|
+
atOrAfter: OracleObservation;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type TickInfo = {
|
|
21
|
+
liquidityGross: bigint;
|
|
22
|
+
liquidityNet: bigint;
|
|
23
|
+
tickCumulativeOutside: bigint;
|
|
24
|
+
secondsPerLiquidityOutsideX128: bigint;
|
|
25
|
+
secondsOutside: bigint;
|
|
26
|
+
initialized: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type Slot0 = {
|
|
30
|
+
sqrtPriceX96: bigint;
|
|
31
|
+
tick: bigint;
|
|
32
|
+
observationIndex: number;
|
|
33
|
+
observationCardinality: number;
|
|
34
|
+
observationCardinalityNext: number;
|
|
35
|
+
feeProtocol: bigint;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type PoolState = {
|
|
39
|
+
pool: string;
|
|
40
|
+
blockTimestamp: bigint;
|
|
41
|
+
tickSpacing: bigint;
|
|
42
|
+
fee: bigint;
|
|
43
|
+
slot0: Slot0;
|
|
44
|
+
liquidity: bigint;
|
|
45
|
+
maxLiquidityPerTick: bigint;
|
|
46
|
+
tickBitmap: Record<NumberAsString, bigint>;
|
|
47
|
+
ticks: Record<NumberAsString, TickInfo>;
|
|
48
|
+
observations: Record<number, OracleObservation>;
|
|
49
|
+
isValid: boolean;
|
|
50
|
+
startTickBitmap: bigint;
|
|
51
|
+
lowestKnownTick: bigint;
|
|
52
|
+
highestKnownTick: bigint;
|
|
53
|
+
balance0: bigint;
|
|
54
|
+
balance1: bigint;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type FactoryState = Record<string, never>;
|
|
58
|
+
|
|
59
|
+
export type UniswapV3Data = {
|
|
60
|
+
path: {
|
|
61
|
+
tokenIn: Address;
|
|
62
|
+
tokenOut: Address;
|
|
63
|
+
fee: NumberAsString;
|
|
64
|
+
currentFee?: NumberAsString;
|
|
65
|
+
}[];
|
|
66
|
+
isApproved?: boolean;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type DecodeStateMultiCallFunc = (
|
|
70
|
+
result: MultiResult<BytesLike> | BytesLike,
|
|
71
|
+
) => DecodedStateMultiCallResultWithRelativeBitmaps;
|
|
72
|
+
|
|
73
|
+
export type DexParams = {
|
|
74
|
+
router: Address;
|
|
75
|
+
quoter: Address;
|
|
76
|
+
factory: Address;
|
|
77
|
+
stateMulticall: Address;
|
|
78
|
+
uniswapMulticall: Address;
|
|
79
|
+
supportedFees: bigint[];
|
|
80
|
+
chunksCount: number;
|
|
81
|
+
initRetryFrequency: number;
|
|
82
|
+
deployer?: Address;
|
|
83
|
+
subgraphURL: string;
|
|
84
|
+
initHash: string;
|
|
85
|
+
stateMultiCallAbi?: AbiItem[];
|
|
86
|
+
eventPoolImplementation?: typeof BaseswapV3EventPool;
|
|
87
|
+
decodeStateMultiCallResultWithRelativeBitmaps?: DecodeStateMultiCallFunc;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type UniswapV3SimpleSwapSellParam = {
|
|
91
|
+
path: string;
|
|
92
|
+
recipient: Address;
|
|
93
|
+
deadline: string;
|
|
94
|
+
amountIn: NumberAsString;
|
|
95
|
+
amountOutMinimum: NumberAsString;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export type UniswapV3SimpleSwapBuyParam = {
|
|
99
|
+
path: string;
|
|
100
|
+
recipient: Address;
|
|
101
|
+
deadline: string;
|
|
102
|
+
amountOut: NumberAsString;
|
|
103
|
+
amountInMaximum: NumberAsString;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type UniswapV3SimpleSwapParams =
|
|
107
|
+
| UniswapV3SimpleSwapSellParam
|
|
108
|
+
| UniswapV3SimpleSwapBuyParam;
|
|
109
|
+
|
|
110
|
+
export type UniswapV3Param = [
|
|
111
|
+
fromToken: Address,
|
|
112
|
+
toToken: Address,
|
|
113
|
+
exchange: Address,
|
|
114
|
+
fromAmount: NumberAsString,
|
|
115
|
+
toAmount: NumberAsString,
|
|
116
|
+
expectedAmount: NumberAsString,
|
|
117
|
+
feePercent: NumberAsString,
|
|
118
|
+
deadline: NumberAsString,
|
|
119
|
+
partner: Address,
|
|
120
|
+
isApproved: boolean,
|
|
121
|
+
beneficiary: Address,
|
|
122
|
+
path: string,
|
|
123
|
+
permit: string,
|
|
124
|
+
uuid: string,
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
export enum UniswapV3Functions {
|
|
128
|
+
exactInput = 'exactInput',
|
|
129
|
+
exactOutput = 'exactOutput',
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export type TickInfoMappings = {
|
|
133
|
+
index: number;
|
|
134
|
+
value: TickInfo;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export type TickBitMapMappings = {
|
|
138
|
+
index: number;
|
|
139
|
+
value: bigint;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export type OutputResult = {
|
|
143
|
+
outputs: bigint[];
|
|
144
|
+
tickCounts: number[];
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// Just rewrote every type with BigNumber basically
|
|
148
|
+
|
|
149
|
+
export type TickBitMapMappingsWithBigNumber = {
|
|
150
|
+
index: number;
|
|
151
|
+
value: BigNumber;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export type TickInfoWithBigNumber = {
|
|
155
|
+
initialized: boolean;
|
|
156
|
+
liquidityGross: BigNumber;
|
|
157
|
+
liquidityNet: BigNumber;
|
|
158
|
+
secondsOutside: number;
|
|
159
|
+
secondsPerLiquidityOutsideX128: BigNumber;
|
|
160
|
+
tickCumulativeOutside: BigNumber;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export type TickInfoMappingsWithBigNumber = {
|
|
164
|
+
index: number;
|
|
165
|
+
value: TickInfoWithBigNumber;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export type DecodedStateMultiCallResultWithRelativeBitmaps = {
|
|
169
|
+
pool: Address;
|
|
170
|
+
blockTimestamp: BigNumber;
|
|
171
|
+
slot0: {
|
|
172
|
+
feeProtocol: number;
|
|
173
|
+
observationCardinality: number;
|
|
174
|
+
observationCardinalityNext: number;
|
|
175
|
+
observationIndex: number;
|
|
176
|
+
sqrtPriceX96: BigNumber;
|
|
177
|
+
tick: number;
|
|
178
|
+
unlocked: boolean;
|
|
179
|
+
};
|
|
180
|
+
liquidity: BigNumber;
|
|
181
|
+
tickSpacing: number;
|
|
182
|
+
maxLiquidityPerTick: BigNumber;
|
|
183
|
+
observation: {
|
|
184
|
+
blockTimestamp: number;
|
|
185
|
+
initialized: boolean;
|
|
186
|
+
secondsPerLiquidityCumulativeX128: BigNumber;
|
|
187
|
+
tickCumulative: BigNumber;
|
|
188
|
+
};
|
|
189
|
+
tickBitmap: TickBitMapMappingsWithBigNumber[];
|
|
190
|
+
ticks: TickInfoMappingsWithBigNumber[];
|
|
191
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
) observation,
|
|
60
|
+
tuple(
|
|
61
|
+
int16 index,
|
|
62
|
+
uint256 value,
|
|
63
|
+
)[] tickBitmap,
|
|
64
|
+
tuple(
|
|
65
|
+
int24 index,
|
|
66
|
+
tuple(
|
|
67
|
+
uint128 liquidityGross,
|
|
68
|
+
int128 liquidityNet,
|
|
69
|
+
int56 tickCumulativeOutside,
|
|
70
|
+
uint160 secondsPerLiquidityOutsideX128,
|
|
71
|
+
uint32 secondsOutside,
|
|
72
|
+
bool initialized,
|
|
73
|
+
) value,
|
|
74
|
+
)[] ticks
|
|
75
|
+
)
|
|
76
|
+
`,
|
|
77
|
+
],
|
|
78
|
+
toDecode,
|
|
79
|
+
)[0];
|
|
80
|
+
// This conversion is not precise, because when we decode, we have more values
|
|
81
|
+
// But I typed only the ones that are used later
|
|
82
|
+
return decoded as DecodedStateMultiCallResultWithRelativeBitmaps;
|
|
83
|
+
}
|
package/src/dex/index.ts
CHANGED
|
@@ -80,6 +80,7 @@ import { Algebra } from './algebra/algebra';
|
|
|
80
80
|
import { QuickPerps } from './quick-perps/quick-perps';
|
|
81
81
|
import { NomiswapV2 } from './uniswap-v2/nomiswap-v2';
|
|
82
82
|
import { Dexalot } from './dexalot/dexalot';
|
|
83
|
+
import { BaseswapV3 } from './baseswap-v3/baseswap-v3';
|
|
83
84
|
|
|
84
85
|
const LegacyDexes = [
|
|
85
86
|
CurveV2,
|
|
@@ -157,6 +158,7 @@ const Dexes = [
|
|
|
157
158
|
SwaapV2,
|
|
158
159
|
QuickPerps,
|
|
159
160
|
NomiswapV2,
|
|
161
|
+
BaseswapV3,
|
|
160
162
|
];
|
|
161
163
|
|
|
162
164
|
export type LegacyDexConstructor = new (dexHelper: IDexHelper) => IDexTxBuilder<
|
package/tests/constants-e2e.ts
CHANGED
|
@@ -961,7 +961,7 @@ export const Holders: {
|
|
|
961
961
|
} = {
|
|
962
962
|
[Network.MAINNET]: {
|
|
963
963
|
ETH: '0x176F3DAb24a159341c0509bB36B833E7fdd0a132',
|
|
964
|
-
USDC: '
|
|
964
|
+
USDC: '0x7713974908be4bed47172370115e8b1219f4a5f0',
|
|
965
965
|
AMPL: '0x223592a191ECfC7FDC38a9256c3BD96E771539A9',
|
|
966
966
|
WBTC: '0x1cb17a66dc606a52785f69f08f4256526abd4943',
|
|
967
967
|
sBTC: '0xA2e3475D13776C6E42ff37B47286827d959B2195',
|