@paraswap/dex-lib 4.1.6 → 4.1.7-mwrappedm.0

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 (137) hide show
  1. package/README.md +1 -1
  2. package/build/abi/fluid-dex/resolver.abi.json +0 -30
  3. package/build/abi/m-token/WrappedM.abi.json +1708 -0
  4. package/build/dex/aave-v3-stata-v2/config.js +0 -13
  5. package/build/dex/aave-v3-stata-v2/config.js.map +1 -1
  6. package/build/dex/algebra/config.js +1 -1
  7. package/build/dex/algebra/config.js.map +1 -1
  8. package/build/dex/balancer-v2/pools/gyro/GyroEPool.js.map +1 -1
  9. package/build/dex/balancer-v3/balancer-v3-pool.d.ts +1 -6
  10. package/build/dex/balancer-v3/balancer-v3-pool.js +17 -45
  11. package/build/dex/balancer-v3/balancer-v3-pool.js.map +1 -1
  12. package/build/dex/balancer-v3/balancer-v3.d.ts +0 -4
  13. package/build/dex/balancer-v3/balancer-v3.js +4 -30
  14. package/build/dex/balancer-v3/balancer-v3.js.map +1 -1
  15. package/build/dex/balancer-v3/config.js +0 -51
  16. package/build/dex/balancer-v3/config.js.map +1 -1
  17. package/build/dex/balancer-v3/getOnChainState.d.ts +2 -1
  18. package/build/dex/balancer-v3/getOnChainState.js +2 -0
  19. package/build/dex/balancer-v3/getOnChainState.js.map +1 -1
  20. package/build/dex/balancer-v3/getPoolsApi.d.ts +1 -2
  21. package/build/dex/balancer-v3/getPoolsApi.js +10 -17
  22. package/build/dex/balancer-v3/getPoolsApi.js.map +1 -1
  23. package/build/dex/balancer-v3/getTopPoolsApi.d.ts +1 -5
  24. package/build/dex/balancer-v3/getTopPoolsApi.js +3 -6
  25. package/build/dex/balancer-v3/getTopPoolsApi.js.map +1 -1
  26. package/build/dex/balancer-v3/types.d.ts +1 -4
  27. package/build/dex/cables/cables.d.ts +1 -1
  28. package/build/dex/cables/cables.js +7 -26
  29. package/build/dex/cables/cables.js.map +1 -1
  30. package/build/dex/fluid-dex/config.js +2 -2
  31. package/build/dex/fluid-dex/constants.d.ts +1 -1
  32. package/build/dex/fluid-dex/constants.js +1 -2
  33. package/build/dex/fluid-dex/constants.js.map +1 -1
  34. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js +1 -3
  35. package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js.map +1 -1
  36. package/build/dex/fluid-dex/fluid-dex.d.ts +5 -4
  37. package/build/dex/fluid-dex/fluid-dex.js +59 -61
  38. package/build/dex/fluid-dex/fluid-dex.js.map +1 -1
  39. package/build/dex/fluid-dex/types.d.ts +0 -3
  40. package/build/dex/index.js +2 -0
  41. package/build/dex/index.js.map +1 -1
  42. package/build/dex/m-token/config.d.ts +3 -0
  43. package/build/dex/m-token/config.js +19 -0
  44. package/build/dex/m-token/config.js.map +1 -0
  45. package/build/dex/m-token/m-token.d.ts +29 -0
  46. package/build/dex/m-token/m-token.js +145 -0
  47. package/build/dex/m-token/m-token.js.map +1 -0
  48. package/build/dex/m-token/m-wrapped-m.d.ts +17 -0
  49. package/build/dex/m-token/m-wrapped-m.js +50 -0
  50. package/build/dex/m-token/m-wrapped-m.js.map +1 -0
  51. package/build/dex/m-token/types.d.ts +12 -0
  52. package/build/dex/m-token/types.js +3 -0
  53. package/build/dex/m-token/types.js.map +1 -0
  54. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js +0 -1
  55. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js.map +1 -1
  56. package/build/dex/uniswap-v3/constants.d.ts +0 -2
  57. package/build/dex/uniswap-v3/constants.js +1 -8
  58. package/build/dex/uniswap-v3/constants.js.map +1 -1
  59. package/build/dex/uniswap-v3/contract-math/TickBitMap.d.ts +2 -2
  60. package/build/dex/uniswap-v3/contract-math/TickBitMap.js +8 -10
  61. package/build/dex/uniswap-v3/contract-math/TickBitMap.js.map +1 -1
  62. package/build/dex/uniswap-v3/contract-math/uniswap-v3-math.js +3 -3
  63. package/build/dex/uniswap-v3/contract-math/uniswap-v3-math.js.map +1 -1
  64. package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js +0 -1
  65. package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js.map +1 -1
  66. package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.js +0 -1
  67. package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.js.map +1 -1
  68. package/build/dex/uniswap-v3/types.d.ts +0 -1
  69. package/build/dex/uniswap-v3/types.js.map +1 -1
  70. package/build/dex/uniswap-v3/uniswap-v3-pool.js +1 -5
  71. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  72. package/build/dex/wusdm/config.js +0 -6
  73. package/build/dex/wusdm/config.js.map +1 -1
  74. package/build/generic-swap-transaction-builder.d.ts +1 -1
  75. package/build/generic-swap-transaction-builder.js +1 -6
  76. package/build/generic-swap-transaction-builder.js.map +1 -1
  77. package/build/implementations/local-paraswap-sdk.js +1 -1
  78. package/build/implementations/local-paraswap-sdk.js.map +1 -1
  79. package/package.json +3 -3
  80. package/scripts/run-dex-integration-v3.ts +4 -4
  81. package/src/abi/fluid-dex/resolver.abi.json +0 -30
  82. package/src/abi/m-token/WrappedM.abi.json +1708 -0
  83. package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-e2e.test.ts +32 -11
  84. package/src/dex/aave-v3-stata-v2/config.ts +0 -16
  85. package/src/dex/algebra/config.ts +1 -1
  86. package/src/dex/balancer-v2/balancer-v2-integration.test.ts +12 -11
  87. package/src/dex/balancer-v2/pools/gyro/GyroEPool.ts +1 -0
  88. package/src/dex/balancer-v3/balancer-v3-e2e.test.ts +0 -130
  89. package/src/dex/balancer-v3/balancer-v3-events.test.ts +84 -157
  90. package/src/dex/balancer-v3/balancer-v3-integration.test.ts +202 -103
  91. package/src/dex/balancer-v3/balancer-v3-pool.ts +26 -85
  92. package/src/dex/balancer-v3/balancer-v3.ts +2 -43
  93. package/src/dex/balancer-v3/config.ts +0 -51
  94. package/src/dex/balancer-v3/getOnChainState.ts +4 -1
  95. package/src/dex/balancer-v3/getPoolsApi.ts +23 -42
  96. package/src/dex/balancer-v3/getTopPoolsApi.ts +2 -13
  97. package/src/dex/balancer-v3/types.ts +2 -4
  98. package/src/dex/cables/cables-e2e.test.ts +40 -40
  99. package/src/dex/cables/cables.ts +10 -37
  100. package/src/dex/fluid-dex/config.ts +2 -2
  101. package/src/dex/fluid-dex/constants.ts +1 -2
  102. package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +117 -61
  103. package/src/dex/fluid-dex/fluid-dex-liquidity-proxy.ts +0 -3
  104. package/src/dex/fluid-dex/fluid-dex.ts +94 -96
  105. package/src/dex/fluid-dex/types.ts +0 -3
  106. package/src/dex/index.ts +2 -0
  107. package/src/dex/m-token/config.ts +18 -0
  108. package/src/dex/m-token/m-token-e2e.test.ts +93 -0
  109. package/src/dex/m-token/m-token-integration.test.ts +199 -0
  110. package/src/dex/m-token/m-token.ts +167 -0
  111. package/src/dex/m-token/m-wrapped-m.ts +68 -0
  112. package/src/dex/m-token/types.ts +10 -0
  113. package/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts +0 -1
  114. package/src/dex/uniswap-v3/constants.ts +0 -10
  115. package/src/dex/uniswap-v3/contract-math/TickBitMap.ts +9 -29
  116. package/src/dex/uniswap-v3/contract-math/uniswap-v3-math.ts +1 -3
  117. package/src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts +0 -1
  118. package/src/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.ts +0 -1
  119. package/src/dex/uniswap-v3/types.ts +0 -1
  120. package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +302 -647
  121. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +1 -11
  122. package/src/dex/wusdm/config.ts +0 -7
  123. package/src/dex/wusdm/wusdm-e2e.test.ts +0 -20
  124. package/src/generic-swap-transaction-builder.ts +2 -10
  125. package/src/implementations/local-paraswap-sdk.ts +1 -1
  126. package/tests/constants-e2e.ts +8 -63
  127. package/tests/tenderly-simulation.ts +0 -3
  128. package/tests/utils-e2e.ts +7 -4
  129. package/src/abi/balancer-v3/directionalFeeHook.json +0 -684
  130. package/src/abi/balancer-v3/stableSurgeHook.json +0 -976
  131. package/src/dex/balancer-v3/balancer-hooks-events.test.ts +0 -166
  132. package/src/dex/balancer-v3/balancer-stableSurge.test.ts +0 -110
  133. package/src/dex/balancer-v3/balancer-test-helpers.ts +0 -199
  134. package/src/dex/balancer-v3/hooks/balancer-hook-event-subscriber.ts +0 -212
  135. package/src/dex/balancer-v3/hooks/directionalFeeHook.ts +0 -51
  136. package/src/dex/balancer-v3/hooks/loadHooksConfig.ts +0 -12
  137. package/src/dex/balancer-v3/hooks/stableSurgeHook.ts +0 -198
@@ -1,51 +0,0 @@
1
- /**
2
- * Each supported hook should implement its own version of this file making it easy to retrieve required onchain state.
3
- */
4
- import _ from 'lodash';
5
- import { Log } from '../../../types';
6
- import { DeepReadonly } from 'ts-essentials';
7
- import { HookStateMap } from './balancer-hook-event-subscriber';
8
-
9
- export const DirectionalFee = {
10
- type: 'DirectionalFee' as const,
11
- };
12
-
13
- export type DirectionalFeeConfig = {
14
- type: typeof DirectionalFee.type;
15
- address: string;
16
- };
17
-
18
- export type DirectionalFeeHookState = {
19
- test: string; // Note - this is just a dummy example as this specific test hook doesn't have any required state but is used to prove concept
20
- };
21
-
22
- /**
23
- * Retrieve any initial hook state required.
24
- * @returns
25
- */
26
- export async function getDirectionalFeeHookState(): Promise<DirectionalFeeHookState> {
27
- // Note - for other hooks this function would retrieve any initial state using onchain calls
28
- return { test: 'initial' };
29
- }
30
-
31
- /**
32
- * Handles the event emitted when a new hook is registered.
33
- * @param event
34
- * @param state
35
- * @param log
36
- * @returns
37
- */
38
- export function exitFeeHookExampleRegisteredEvent(
39
- event: any,
40
- state: DeepReadonly<HookStateMap>,
41
- log: Readonly<Log>,
42
- ): DeepReadonly<HookStateMap> | null {
43
- // Note - This is a non-important event but demos the use case. Other hooks would implement this for any state changes required for swap maths.
44
- const hookAddress = event.args.hooksContract.toLowerCase();
45
- if (!state[hookAddress]) {
46
- return null;
47
- }
48
- const newState = _.cloneDeep(state) as HookStateMap;
49
- newState[hookAddress] = { test: event.args.pool };
50
- return newState;
51
- }
@@ -1,12 +0,0 @@
1
- import { BalancerV3Config } from './../config';
2
- import { HooksConfigMap } from './balancer-hook-event-subscriber';
3
-
4
- export function loadHooksConfig(network: number): HooksConfigMap {
5
- const hooks = BalancerV3Config.BalancerV3[network].hooks;
6
-
7
- if (!hooks) return {};
8
-
9
- return Object.fromEntries(
10
- hooks.map(hook => [hook.address.toLowerCase(), hook]),
11
- );
12
- }
@@ -1,198 +0,0 @@
1
- import _ from 'lodash';
2
- import { Log } from '../../../types';
3
- import { DeepReadonly } from 'ts-essentials';
4
- import { HookStateMap } from './balancer-hook-event-subscriber';
5
- import { Interface } from '@ethersproject/abi';
6
- import { Contract } from 'ethers';
7
- import { IDexHelper } from '../../../dex-helper';
8
- import { callData, decodeThrowError } from '../getOnChainState';
9
- import { Logger } from 'log4js';
10
-
11
- export const StableSurge = {
12
- type: 'StableSurge' as const,
13
- };
14
-
15
- export type StableSurgeConfig = {
16
- type: typeof StableSurge.type;
17
- factory: string;
18
- address: string;
19
- };
20
-
21
- export type StableSurgePoolSetting = {
22
- surgeThresholdPercentage?: bigint;
23
- maxSurgeFeePercentage?: bigint;
24
- };
25
-
26
- export type StableSurgeHookState = Record<string, StableSurgePoolSetting>;
27
-
28
- /**
29
- * Retrieve any initial hook state required.
30
- * @returns
31
- */
32
- export async function getStableSurgeHookState(
33
- hookInterface: Interface,
34
- hookAddress: string,
35
- factoryAddress: string,
36
- dexHelper: IDexHelper,
37
- blockNumber: number,
38
- ): Promise<StableSurgeHookState> {
39
- // Find all pools with hook
40
- const resolverContract = new Contract(
41
- factoryAddress,
42
- ['function getPools() external view returns (address[])'],
43
- dexHelper.provider,
44
- );
45
- const pools = (await resolverContract.callStatic.getPools({
46
- blockTag: blockNumber,
47
- })) as string[];
48
- const surgeThresholdCallData: callData[] = pools.flatMap(pool => {
49
- return [
50
- {
51
- target: hookAddress,
52
- callData: hookInterface.encodeFunctionData(
53
- 'getSurgeThresholdPercentage',
54
- [pool],
55
- ),
56
- },
57
- {
58
- target: hookAddress,
59
- callData: hookInterface.encodeFunctionData('getMaxSurgeFeePercentage', [
60
- pool,
61
- ]),
62
- },
63
- ];
64
- });
65
-
66
- // 500 is an arbitrary number chosen based on the blockGasLimit
67
- const slicedMultiCallData = _.chunk(surgeThresholdCallData, 500);
68
-
69
- const multicallDataResult = (
70
- await Promise.all(
71
- slicedMultiCallData.map(async _multiCallData =>
72
- dexHelper.multiContract.methods
73
- .tryAggregate(false, _multiCallData)
74
- .call({}, blockNumber),
75
- ),
76
- )
77
- ).flat();
78
-
79
- return mapPoolsToDecodedData(hookInterface, pools, multicallDataResult);
80
- }
81
-
82
- function mapPoolsToDecodedData(
83
- hookInterface: Interface,
84
- pools: string[],
85
- data: any[],
86
- ): StableSurgeHookState {
87
- return pools.reduce((acc, pool, index) => {
88
- const dataIndex = index * 2;
89
-
90
- // Ensure we have enough data
91
- if (dataIndex + 1 >= data.length) {
92
- throw new Error(`Insufficient data for pool ${pool}`);
93
- }
94
-
95
- // Decode the corresponding data pairs
96
- const decodedX = decodeThrowError(
97
- hookInterface,
98
- 'getSurgeThresholdPercentage',
99
- data[dataIndex],
100
- pool,
101
- );
102
- const decodedY = decodeThrowError(
103
- hookInterface,
104
- 'getMaxSurgeFeePercentage',
105
- data[dataIndex + 1],
106
- pool,
107
- );
108
- // Add to accumulator
109
- acc[pool.toLowerCase()] = {
110
- surgeThresholdPercentage: decodedX[0].toBigInt(),
111
- maxSurgeFeePercentage: decodedY[0].toBigInt(),
112
- };
113
-
114
- return acc;
115
- }, {} as StableSurgeHookState);
116
- }
117
-
118
- /**
119
- * Handles the event emitted when threshold surge percentage changed.
120
- * @param event
121
- * @param state
122
- * @param log
123
- * @returns
124
- */
125
- export function thresholdSurgePercentageChangedEvent(
126
- event: any,
127
- state: DeepReadonly<HookStateMap>,
128
- log: Readonly<Log>,
129
- logger: Logger,
130
- ): DeepReadonly<HookStateMap> | null {
131
- // ThresholdSurgePercentageChanged(pool, newSurgeThresholdPercentage)
132
- const hookAddress = log.address.toLowerCase();
133
-
134
- if (!state[hookAddress]) {
135
- logger.info(`State for hook ${hookAddress} was not found...`);
136
- return state;
137
- }
138
-
139
- const newState = _.cloneDeep(state) as HookStateMap;
140
-
141
- if (
142
- newState[hookAddress] &&
143
- !(newState[hookAddress] as StableSurgeHookState)[
144
- event.args.pool.toLowerCase()
145
- ]
146
- ) {
147
- (newState[hookAddress] as StableSurgeHookState)[
148
- event.args.pool.toLowerCase()
149
- ] = {
150
- surgeThresholdPercentage: BigInt(event.args.newSurgeThresholdPercentage),
151
- };
152
- } else {
153
- (newState[hookAddress] as StableSurgeHookState)[
154
- event.args.pool.toLowerCase()
155
- ].surgeThresholdPercentage = BigInt(event.args.newSurgeThresholdPercentage);
156
- }
157
-
158
- return newState;
159
- }
160
-
161
- /**
162
- * Handles the event emitted when max surge fee percentage changed.
163
- * @param event
164
- * @param state
165
- * @param log
166
- * @returns
167
- */
168
- export function maxSurgeFeePercentageChangedEvent(
169
- event: any,
170
- state: DeepReadonly<HookStateMap>,
171
- log: Readonly<Log>,
172
- ): DeepReadonly<HookStateMap> | null {
173
- // MaxSurgeFeePercentageChanged(pool, newMaxSurgeFeePercentage)
174
- const hookAddress = log.address.toLowerCase();
175
- if (!state[hookAddress]) {
176
- return null;
177
- }
178
- const newState = _.cloneDeep(state) as HookStateMap;
179
-
180
- if (
181
- newState[hookAddress] &&
182
- !(newState[hookAddress] as StableSurgeHookState)[
183
- event.args.pool.toLowerCase() as string
184
- ]
185
- ) {
186
- (newState[hookAddress] as StableSurgeHookState)[
187
- event.args.pool.toLowerCase()
188
- ] = {
189
- maxSurgeFeePercentage: BigInt(event.args.newMaxSurgeFeePercentage),
190
- };
191
- } else {
192
- (newState[hookAddress] as StableSurgeHookState)[
193
- event.args.pool.toLowerCase()
194
- ].maxSurgeFeePercentage = BigInt(event.args.newMaxSurgeFeePercentage);
195
- }
196
-
197
- return newState;
198
- }