@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.
- package/README.md +1 -1
- package/build/abi/fluid-dex/resolver.abi.json +0 -30
- package/build/abi/m-token/WrappedM.abi.json +1708 -0
- package/build/dex/aave-v3-stata-v2/config.js +0 -13
- package/build/dex/aave-v3-stata-v2/config.js.map +1 -1
- package/build/dex/algebra/config.js +1 -1
- package/build/dex/algebra/config.js.map +1 -1
- package/build/dex/balancer-v2/pools/gyro/GyroEPool.js.map +1 -1
- package/build/dex/balancer-v3/balancer-v3-pool.d.ts +1 -6
- package/build/dex/balancer-v3/balancer-v3-pool.js +17 -45
- package/build/dex/balancer-v3/balancer-v3-pool.js.map +1 -1
- package/build/dex/balancer-v3/balancer-v3.d.ts +0 -4
- package/build/dex/balancer-v3/balancer-v3.js +4 -30
- package/build/dex/balancer-v3/balancer-v3.js.map +1 -1
- package/build/dex/balancer-v3/config.js +0 -51
- package/build/dex/balancer-v3/config.js.map +1 -1
- package/build/dex/balancer-v3/getOnChainState.d.ts +2 -1
- package/build/dex/balancer-v3/getOnChainState.js +2 -0
- package/build/dex/balancer-v3/getOnChainState.js.map +1 -1
- package/build/dex/balancer-v3/getPoolsApi.d.ts +1 -2
- package/build/dex/balancer-v3/getPoolsApi.js +10 -17
- package/build/dex/balancer-v3/getPoolsApi.js.map +1 -1
- package/build/dex/balancer-v3/getTopPoolsApi.d.ts +1 -5
- package/build/dex/balancer-v3/getTopPoolsApi.js +3 -6
- package/build/dex/balancer-v3/getTopPoolsApi.js.map +1 -1
- package/build/dex/balancer-v3/types.d.ts +1 -4
- package/build/dex/cables/cables.d.ts +1 -1
- package/build/dex/cables/cables.js +7 -26
- package/build/dex/cables/cables.js.map +1 -1
- package/build/dex/fluid-dex/config.js +2 -2
- package/build/dex/fluid-dex/constants.d.ts +1 -1
- package/build/dex/fluid-dex/constants.js +1 -2
- package/build/dex/fluid-dex/constants.js.map +1 -1
- package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js +1 -3
- package/build/dex/fluid-dex/fluid-dex-liquidity-proxy.js.map +1 -1
- package/build/dex/fluid-dex/fluid-dex.d.ts +5 -4
- package/build/dex/fluid-dex/fluid-dex.js +59 -61
- package/build/dex/fluid-dex/fluid-dex.js.map +1 -1
- package/build/dex/fluid-dex/types.d.ts +0 -3
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/m-token/config.d.ts +3 -0
- package/build/dex/m-token/config.js +19 -0
- package/build/dex/m-token/config.js.map +1 -0
- package/build/dex/m-token/m-token.d.ts +29 -0
- package/build/dex/m-token/m-token.js +145 -0
- package/build/dex/m-token/m-token.js.map +1 -0
- package/build/dex/m-token/m-wrapped-m.d.ts +17 -0
- package/build/dex/m-token/m-wrapped-m.js +50 -0
- package/build/dex/m-token/m-wrapped-m.js.map +1 -0
- package/build/dex/m-token/types.d.ts +12 -0
- package/build/dex/m-token/types.js +3 -0
- package/build/dex/m-token/types.js.map +1 -0
- package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js +0 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js.map +1 -1
- package/build/dex/uniswap-v3/constants.d.ts +0 -2
- package/build/dex/uniswap-v3/constants.js +1 -8
- package/build/dex/uniswap-v3/constants.js.map +1 -1
- package/build/dex/uniswap-v3/contract-math/TickBitMap.d.ts +2 -2
- package/build/dex/uniswap-v3/contract-math/TickBitMap.js +8 -10
- package/build/dex/uniswap-v3/contract-math/TickBitMap.js.map +1 -1
- package/build/dex/uniswap-v3/contract-math/uniswap-v3-math.js +3 -3
- package/build/dex/uniswap-v3/contract-math/uniswap-v3-math.js.map +1 -1
- package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js +0 -1
- package/build/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.js.map +1 -1
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.js +0 -1
- package/build/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.js.map +1 -1
- package/build/dex/uniswap-v3/types.d.ts +0 -1
- package/build/dex/uniswap-v3/types.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3-pool.js +1 -5
- package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
- package/build/dex/wusdm/config.js +0 -6
- package/build/dex/wusdm/config.js.map +1 -1
- package/build/generic-swap-transaction-builder.d.ts +1 -1
- package/build/generic-swap-transaction-builder.js +1 -6
- package/build/generic-swap-transaction-builder.js.map +1 -1
- package/build/implementations/local-paraswap-sdk.js +1 -1
- package/build/implementations/local-paraswap-sdk.js.map +1 -1
- package/package.json +3 -3
- package/scripts/run-dex-integration-v3.ts +4 -4
- package/src/abi/fluid-dex/resolver.abi.json +0 -30
- package/src/abi/m-token/WrappedM.abi.json +1708 -0
- package/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-e2e.test.ts +32 -11
- package/src/dex/aave-v3-stata-v2/config.ts +0 -16
- package/src/dex/algebra/config.ts +1 -1
- package/src/dex/balancer-v2/balancer-v2-integration.test.ts +12 -11
- package/src/dex/balancer-v2/pools/gyro/GyroEPool.ts +1 -0
- package/src/dex/balancer-v3/balancer-v3-e2e.test.ts +0 -130
- package/src/dex/balancer-v3/balancer-v3-events.test.ts +84 -157
- package/src/dex/balancer-v3/balancer-v3-integration.test.ts +202 -103
- package/src/dex/balancer-v3/balancer-v3-pool.ts +26 -85
- package/src/dex/balancer-v3/balancer-v3.ts +2 -43
- package/src/dex/balancer-v3/config.ts +0 -51
- package/src/dex/balancer-v3/getOnChainState.ts +4 -1
- package/src/dex/balancer-v3/getPoolsApi.ts +23 -42
- package/src/dex/balancer-v3/getTopPoolsApi.ts +2 -13
- package/src/dex/balancer-v3/types.ts +2 -4
- package/src/dex/cables/cables-e2e.test.ts +40 -40
- package/src/dex/cables/cables.ts +10 -37
- package/src/dex/fluid-dex/config.ts +2 -2
- package/src/dex/fluid-dex/constants.ts +1 -2
- package/src/dex/fluid-dex/fluid-dex-e2e.test.ts +117 -61
- package/src/dex/fluid-dex/fluid-dex-liquidity-proxy.ts +0 -3
- package/src/dex/fluid-dex/fluid-dex.ts +94 -96
- package/src/dex/fluid-dex/types.ts +0 -3
- package/src/dex/index.ts +2 -0
- package/src/dex/m-token/config.ts +18 -0
- package/src/dex/m-token/m-token-e2e.test.ts +93 -0
- package/src/dex/m-token/m-token-integration.test.ts +199 -0
- package/src/dex/m-token/m-token.ts +167 -0
- package/src/dex/m-token/m-wrapped-m.ts +68 -0
- package/src/dex/m-token/types.ts +10 -0
- package/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts +0 -1
- package/src/dex/uniswap-v3/constants.ts +0 -10
- package/src/dex/uniswap-v3/contract-math/TickBitMap.ts +9 -29
- package/src/dex/uniswap-v3/contract-math/uniswap-v3-math.ts +1 -3
- package/src/dex/uniswap-v3/forks/ramses-v2/ramses-v2-pool.ts +0 -1
- package/src/dex/uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream-pool.ts +0 -1
- package/src/dex/uniswap-v3/types.ts +0 -1
- package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +302 -647
- package/src/dex/uniswap-v3/uniswap-v3-pool.ts +1 -11
- package/src/dex/wusdm/config.ts +0 -7
- package/src/dex/wusdm/wusdm-e2e.test.ts +0 -20
- package/src/generic-swap-transaction-builder.ts +2 -10
- package/src/implementations/local-paraswap-sdk.ts +1 -1
- package/tests/constants-e2e.ts +8 -63
- package/tests/tenderly-simulation.ts +0 -3
- package/tests/utils-e2e.ts +7 -4
- package/src/abi/balancer-v3/directionalFeeHook.json +0 -684
- package/src/abi/balancer-v3/stableSurgeHook.json +0 -976
- package/src/dex/balancer-v3/balancer-hooks-events.test.ts +0 -166
- package/src/dex/balancer-v3/balancer-stableSurge.test.ts +0 -110
- package/src/dex/balancer-v3/balancer-test-helpers.ts +0 -199
- package/src/dex/balancer-v3/hooks/balancer-hook-event-subscriber.ts +0 -212
- package/src/dex/balancer-v3/hooks/directionalFeeHook.ts +0 -51
- package/src/dex/balancer-v3/hooks/loadHooksConfig.ts +0 -12
- 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
|
-
}
|