@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
|
@@ -25,69 +25,18 @@ export const BalancerV3Config: DexConfigMap<DexParams> = {
|
|
|
25
25
|
apiNetworkName: 'SEPOLIA',
|
|
26
26
|
balancerRouterAddress: '0x0BF61f706105EA44694f2e92986bD01C39930280',
|
|
27
27
|
balancerBatchRouterAddress: '0xC85b652685567C1B074e8c0D4389f83a2E458b1C',
|
|
28
|
-
hooks: [
|
|
29
|
-
{
|
|
30
|
-
type: 'DirectionalFee',
|
|
31
|
-
address: '0xd68372e85d8a14afa5fdb3d506bf765939aaf382',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
type: 'StableSurge',
|
|
35
|
-
factory: '0x9eB9867C1d4B6fd3a7D0dAd3101b5A153b1107Ec', // Pools with StableSurge hook will always be deployed from this factory
|
|
36
|
-
address: '0xc0cbcdd6b823a4f22aa6bbdde44c17e754266aef', // Address of the hook that will be used by pools
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
28
|
},
|
|
40
29
|
[Network.GNOSIS]: {
|
|
41
30
|
vaultAddress: '0xbA1333333333a1BA1108E8412f11850A5C319bA9',
|
|
42
31
|
apiNetworkName: 'GNOSIS',
|
|
43
32
|
balancerRouterAddress: '0x84813aA3e079A665C0B80F944427eE83cBA63617',
|
|
44
33
|
balancerBatchRouterAddress: '0xe2fa4e1d17725e72dcdAfe943Ecf45dF4B9E285b',
|
|
45
|
-
hooks: [
|
|
46
|
-
{
|
|
47
|
-
type: 'StableSurge',
|
|
48
|
-
factory: '0x268E2EE1413D768b6e2dc3F5a4ddc9Ae03d9AF42', // Pools with StableSurge hook will always be deployed from this factory
|
|
49
|
-
address: '0xe4f1878eC9710846E2B529C1b5037F8bA94583b1', // Address of the hook that will be used by pools
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
34
|
},
|
|
53
35
|
[Network.MAINNET]: {
|
|
54
36
|
vaultAddress: '0xbA1333333333a1BA1108E8412f11850A5C319bA9',
|
|
55
37
|
apiNetworkName: 'MAINNET',
|
|
56
38
|
balancerRouterAddress: '0x5C6fb490BDFD3246EB0bB062c168DeCAF4bD9FDd',
|
|
57
39
|
balancerBatchRouterAddress: '0x136f1EFcC3f8f88516B9E94110D56FDBfB1778d1',
|
|
58
|
-
hooks: [
|
|
59
|
-
{
|
|
60
|
-
type: 'StableSurge',
|
|
61
|
-
factory: '0xD53F5d8d926fb2a0f7Be614B16e649B8aC102D83', // Pools with StableSurge hook will always be deployed from this factory
|
|
62
|
-
address: '0xb18fA0cb5DE8cecB8899AAE6e38b1B7ed77885dA', // Address of the hook that will be used by pools
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
},
|
|
66
|
-
[Network.ARBITRUM]: {
|
|
67
|
-
vaultAddress: '0xbA1333333333a1BA1108E8412f11850A5C319bA9',
|
|
68
|
-
apiNetworkName: 'ARBITRUM',
|
|
69
|
-
balancerRouterAddress: '0x0f08eEf2C785AA5e7539684aF04755dEC1347b7c',
|
|
70
|
-
balancerBatchRouterAddress: '0xaD89051bEd8d96f045E8912aE1672c6C0bF8a85E',
|
|
71
|
-
hooks: [
|
|
72
|
-
{
|
|
73
|
-
type: 'StableSurge',
|
|
74
|
-
factory: '0x86e67E115f96DF37239E0479441303De0de7bc2b', // Pools with StableSurge hook will always be deployed from this factory
|
|
75
|
-
address: '0x0Fa0f9990D7969a7aE6f9961d663E4A201Ed6417', // Address of the hook that will be used by pools
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
},
|
|
79
|
-
[Network.BASE]: {
|
|
80
|
-
vaultAddress: '0xbA1333333333a1BA1108E8412f11850A5C319bA9',
|
|
81
|
-
apiNetworkName: 'BASE',
|
|
82
|
-
balancerRouterAddress: '0x76578ecf9a141296Ec657847fb45B0585bCDa3a6',
|
|
83
|
-
balancerBatchRouterAddress: '0x85a80afee867aDf27B50BdB7b76DA70f1E853062',
|
|
84
|
-
hooks: [
|
|
85
|
-
{
|
|
86
|
-
type: 'StableSurge',
|
|
87
|
-
factory: '0x4fb47126Fa83A8734991E41B942Ac29A3266C968', // Pools with StableSurge hook will always be deployed from this factory
|
|
88
|
-
address: '0xb2007B8B7E0260042517f635CFd8E6dD2Dd7f007', // Address of the hook that will be used by pools
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
40
|
},
|
|
92
41
|
},
|
|
93
42
|
};
|
|
@@ -10,7 +10,7 @@ import { Interface, Result } from '@ethersproject/abi';
|
|
|
10
10
|
import { IDexHelper } from '../../dex-helper';
|
|
11
11
|
import { WAD } from './balancer-v3-pool';
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
interface callData {
|
|
14
14
|
target: string;
|
|
15
15
|
callData: string;
|
|
16
16
|
}
|
|
@@ -161,6 +161,9 @@ const poolOnChain: Record<
|
|
|
161
161
|
(r: string) => BigInt(r),
|
|
162
162
|
),
|
|
163
163
|
isPoolPaused: resultIsPoolPaused[0],
|
|
164
|
+
hasHook:
|
|
165
|
+
resultHooksConfig[0].hooksContract !==
|
|
166
|
+
'0x0000000000000000000000000000000000000000',
|
|
164
167
|
};
|
|
165
168
|
},
|
|
166
169
|
},
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
} from './config';
|
|
8
8
|
import { CommonImmutablePoolState, ImmutablePoolStateMap } from './types';
|
|
9
9
|
import { parseUnits } from 'ethers/lib/utils';
|
|
10
|
-
import { HooksConfigMap } from './hooks/balancer-hook-event-subscriber';
|
|
11
10
|
|
|
12
11
|
interface PoolToken {
|
|
13
12
|
address: string;
|
|
@@ -22,9 +21,6 @@ interface Pool {
|
|
|
22
21
|
id: string;
|
|
23
22
|
type: string;
|
|
24
23
|
poolTokens: PoolToken[];
|
|
25
|
-
hook: {
|
|
26
|
-
address: string;
|
|
27
|
-
} | null;
|
|
28
24
|
}
|
|
29
25
|
|
|
30
26
|
interface QueryResponse {
|
|
@@ -48,6 +44,7 @@ function createQuery(
|
|
|
48
44
|
const whereClause = {
|
|
49
45
|
chainIn: networkString,
|
|
50
46
|
protocolVersionIn: 3,
|
|
47
|
+
hasHook: false,
|
|
51
48
|
poolTypeIn: `[${poolTypesString}]`,
|
|
52
49
|
...(timestamp && { createTime: `{lt: ${timestamp}}` }),
|
|
53
50
|
...(disabledPoolIdsString && { idNotIn: `[${disabledPoolIdsString}]` }),
|
|
@@ -72,53 +69,37 @@ function createQuery(
|
|
|
72
69
|
address
|
|
73
70
|
}
|
|
74
71
|
}
|
|
75
|
-
hook {
|
|
76
|
-
address
|
|
77
|
-
}
|
|
78
72
|
}
|
|
79
73
|
}
|
|
80
74
|
`;
|
|
81
75
|
}
|
|
82
76
|
|
|
83
|
-
function toImmutablePoolStateMap(
|
|
84
|
-
pools
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
),
|
|
105
|
-
poolType: pool.type,
|
|
106
|
-
hookAddress: pool.hook ? pool.hook.address.toLowerCase() : undefined,
|
|
107
|
-
hookType: pool.hook
|
|
108
|
-
? hooksConfigMap[pool.hook.address.toLowerCase()].type
|
|
109
|
-
: undefined,
|
|
110
|
-
supportsUnbalancedLiquidity: true, // can default to true as only required for add/remove maths which we don't use
|
|
111
|
-
};
|
|
112
|
-
map[pool.id] = immutablePoolState;
|
|
113
|
-
return map;
|
|
114
|
-
}, {} as ImmutablePoolStateMap)
|
|
115
|
-
);
|
|
77
|
+
function toImmutablePoolStateMap(pools: Pool[]): ImmutablePoolStateMap {
|
|
78
|
+
return pools.reduce((map, pool) => {
|
|
79
|
+
const immutablePoolState: CommonImmutablePoolState = {
|
|
80
|
+
poolAddress: pool.id,
|
|
81
|
+
tokens: pool.poolTokens.map(t => t.address),
|
|
82
|
+
tokensUnderlying: pool.poolTokens.map(t =>
|
|
83
|
+
t.underlyingToken ? t.underlyingToken.address : null,
|
|
84
|
+
),
|
|
85
|
+
weights: pool.poolTokens.map(t =>
|
|
86
|
+
t.weight ? parseUnits(t.weight, 18).toBigInt() : 0n,
|
|
87
|
+
),
|
|
88
|
+
poolType: pool.type,
|
|
89
|
+
// TODO add scalingFactors once API provides them
|
|
90
|
+
// scalingFactors: pool.poolTokens.map(t => parseUnits('1', 18).toBigInt()),
|
|
91
|
+
// TODO Hook support will be added in future PR
|
|
92
|
+
hookType: undefined,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
map[pool.id] = immutablePoolState;
|
|
96
|
+
return map;
|
|
97
|
+
}, {} as ImmutablePoolStateMap);
|
|
116
98
|
}
|
|
117
99
|
|
|
118
100
|
// Any data from API will be immutable. Mutable data such as balances, etc will be fetched via onchain/event state.
|
|
119
101
|
export async function getPoolsApi(
|
|
120
102
|
network: number,
|
|
121
|
-
hooksConfigMap: HooksConfigMap,
|
|
122
103
|
timestamp?: number,
|
|
123
104
|
): Promise<ImmutablePoolStateMap> {
|
|
124
105
|
try {
|
|
@@ -140,7 +121,7 @@ export async function getPoolsApi(
|
|
|
140
121
|
);
|
|
141
122
|
|
|
142
123
|
const pools = response.data.data.poolGetAggregatorPools;
|
|
143
|
-
return toImmutablePoolStateMap(pools
|
|
124
|
+
return toImmutablePoolStateMap(pools);
|
|
144
125
|
} catch (error) {
|
|
145
126
|
// console.error('Error executing GraphQL query:', error);
|
|
146
127
|
throw error;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { apiUrl, BalancerV3Config, disabledPoolIds } from './config';
|
|
3
|
-
import { HooksConfigMap } from './hooks/balancer-hook-event-subscriber';
|
|
4
3
|
|
|
5
4
|
interface PoolToken {
|
|
6
5
|
address: string;
|
|
@@ -17,9 +16,6 @@ export interface Pool {
|
|
|
17
16
|
dynamicData: {
|
|
18
17
|
totalLiquidity: string;
|
|
19
18
|
};
|
|
20
|
-
hook: {
|
|
21
|
-
address: string;
|
|
22
|
-
} | null;
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
interface QueryResponse {
|
|
@@ -43,6 +39,7 @@ function createQuery(
|
|
|
43
39
|
const whereClause = {
|
|
44
40
|
chainIn: networkString,
|
|
45
41
|
protocolVersionIn: 3,
|
|
42
|
+
hasHook: false,
|
|
46
43
|
idIn: `[${poolIdString}]`,
|
|
47
44
|
...(disabledPoolIdsString && { idNotIn: `[${disabledPoolIdsString}]` }),
|
|
48
45
|
};
|
|
@@ -71,9 +68,6 @@ function createQuery(
|
|
|
71
68
|
dynamicData {
|
|
72
69
|
totalLiquidity
|
|
73
70
|
}
|
|
74
|
-
hook {
|
|
75
|
-
address
|
|
76
|
-
}
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
73
|
`;
|
|
@@ -83,7 +77,6 @@ export async function getTopPoolsApi(
|
|
|
83
77
|
networkId: number,
|
|
84
78
|
poolsFilter: string[],
|
|
85
79
|
count: number,
|
|
86
|
-
hooksTypeMap: HooksConfigMap,
|
|
87
80
|
): Promise<Pool[]> {
|
|
88
81
|
try {
|
|
89
82
|
const query = createQuery(networkId, poolsFilter, count);
|
|
@@ -99,11 +92,7 @@ export async function getTopPoolsApi(
|
|
|
99
92
|
},
|
|
100
93
|
);
|
|
101
94
|
|
|
102
|
-
const pools = response.data.data.poolGetAggregatorPools
|
|
103
|
-
pool =>
|
|
104
|
-
!pool.hook ||
|
|
105
|
-
(pool.hook && pool.hook.address.toLowerCase() in hooksTypeMap),
|
|
106
|
-
);
|
|
95
|
+
const pools = response.data.data.poolGetAggregatorPools;
|
|
107
96
|
return pools;
|
|
108
97
|
} catch (error) {
|
|
109
98
|
// console.error('Error executing GraphQL query:', error);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { BufferState } from '@balancer-labs/balancer-maths';
|
|
2
2
|
import { Address } from '../../types';
|
|
3
|
-
import { HookConfig } from './hooks/balancer-hook-event-subscriber';
|
|
4
3
|
|
|
5
4
|
// Immutable data types available on all pools (Available from API)
|
|
6
5
|
export type CommonImmutablePoolState = {
|
|
@@ -13,9 +12,7 @@ export type CommonImmutablePoolState = {
|
|
|
13
12
|
weights: bigint[];
|
|
14
13
|
// TODO re-introduce this once added to API
|
|
15
14
|
// scalingFactors: bigint[];
|
|
16
|
-
hookAddress: string | undefined;
|
|
17
15
|
hookType: string | undefined;
|
|
18
|
-
supportsUnbalancedLiquidity: boolean;
|
|
19
16
|
};
|
|
20
17
|
|
|
21
18
|
// Mutable data types available on all pools (Available via onchain calls/events)
|
|
@@ -29,6 +26,8 @@ export interface CommonMutableState {
|
|
|
29
26
|
isPoolPaused: boolean;
|
|
30
27
|
// TODO remove this once API provides it
|
|
31
28
|
scalingFactors: bigint[];
|
|
29
|
+
// TODO remove this once API provides it
|
|
30
|
+
hasHook: boolean;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
type CommonPoolState = CommonImmutablePoolState & CommonMutableState;
|
|
@@ -77,7 +76,6 @@ export type DexParams = {
|
|
|
77
76
|
// https://github.com/balancer/balancer-v3-monorepo/blob/main/pkg/interfaces/contracts/vault/IRouter.sol
|
|
78
77
|
balancerRouterAddress: string;
|
|
79
78
|
balancerBatchRouterAddress: string;
|
|
80
|
-
hooks?: HookConfig[];
|
|
81
79
|
};
|
|
82
80
|
|
|
83
81
|
export type TokenInfo = {
|
|
@@ -14,7 +14,7 @@ describe('Cables E2E', () => {
|
|
|
14
14
|
|
|
15
15
|
const sideToContractMethods = new Map([
|
|
16
16
|
[SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
|
|
17
|
-
|
|
17
|
+
[SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
|
|
18
18
|
]);
|
|
19
19
|
|
|
20
20
|
describe('Arbitrum', () => {
|
|
@@ -30,7 +30,7 @@ describe('Cables E2E', () => {
|
|
|
30
30
|
[
|
|
31
31
|
{
|
|
32
32
|
name: 'USDC',
|
|
33
|
-
sellAmount: '
|
|
33
|
+
sellAmount: '500000',
|
|
34
34
|
buyAmount: '700000',
|
|
35
35
|
},
|
|
36
36
|
{
|
|
@@ -39,18 +39,18 @@ describe('Cables E2E', () => {
|
|
|
39
39
|
buyAmount: '850000',
|
|
40
40
|
},
|
|
41
41
|
],
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
[
|
|
43
|
+
{
|
|
44
|
+
name: 'WETH',
|
|
45
|
+
sellAmount: '100000000000000000',
|
|
46
|
+
buyAmount: '200000000000000000',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'USDT',
|
|
50
|
+
sellAmount: '6000000',
|
|
51
|
+
buyAmount: '8000000',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
54
|
];
|
|
55
55
|
|
|
56
56
|
sideToContractMethods.forEach((contractMethods, side) =>
|
|
@@ -84,32 +84,32 @@ describe('Cables E2E', () => {
|
|
|
84
84
|
sleepMs,
|
|
85
85
|
);
|
|
86
86
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
87
|
+
it(`${pair[1].name} -> ${pair[0].name}`, async () => {
|
|
88
|
+
await testE2E(
|
|
89
|
+
side === SwapSide.SELL
|
|
90
|
+
? tokens[pair[1].name]
|
|
91
|
+
: tokens[pair[0].name],
|
|
92
|
+
side === SwapSide.SELL
|
|
93
|
+
? tokens[pair[0].name]
|
|
94
|
+
: tokens[pair[1].name],
|
|
95
|
+
side === SwapSide.SELL
|
|
96
|
+
? holders[pair[1].name]
|
|
97
|
+
: holders[pair[0].name],
|
|
98
|
+
side === SwapSide.SELL
|
|
99
|
+
? pair[1].sellAmount
|
|
100
|
+
: pair[1].buyAmount,
|
|
101
|
+
side,
|
|
102
|
+
dexKey,
|
|
103
|
+
contractMethod,
|
|
104
|
+
network,
|
|
105
|
+
provider,
|
|
106
|
+
undefined,
|
|
107
|
+
undefined,
|
|
108
|
+
undefined,
|
|
109
|
+
slippage,
|
|
110
|
+
sleepMs,
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
115
|
});
|
package/src/dex/cables/cables.ts
CHANGED
|
@@ -399,15 +399,11 @@ export class Cables extends SimpleExchange implements IDex<any> {
|
|
|
399
399
|
let decimals = baseToken.decimals;
|
|
400
400
|
let out_decimals = quoteToken.decimals;
|
|
401
401
|
|
|
402
|
-
let price =
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
Number(amt) / 10 ** decimals,
|
|
408
|
-
isInputQuote,
|
|
409
|
-
);
|
|
410
|
-
} catch {}
|
|
402
|
+
let price = this.calculatePriceSwap(
|
|
403
|
+
orderbook,
|
|
404
|
+
Number(amt) / 10 ** decimals,
|
|
405
|
+
isInputQuote,
|
|
406
|
+
);
|
|
411
407
|
result.push(BigInt(Math.round(price * 10 ** out_decimals)));
|
|
412
408
|
}
|
|
413
409
|
return result;
|
|
@@ -420,17 +416,11 @@ export class Cables extends SimpleExchange implements IDex<any> {
|
|
|
420
416
|
) {
|
|
421
417
|
let sumBaseQty = 0;
|
|
422
418
|
let sumQuoteQty = 0;
|
|
423
|
-
|
|
424
419
|
const selectedRows: string[][] = [];
|
|
425
420
|
|
|
426
421
|
const isBase = qtyMode;
|
|
427
422
|
const isQuote = !qtyMode;
|
|
428
423
|
|
|
429
|
-
const totalVolume: number = prices.reduce(
|
|
430
|
-
(sum, [, volume]) => sum + Number(volume),
|
|
431
|
-
0,
|
|
432
|
-
);
|
|
433
|
-
|
|
434
424
|
for (const [price, volume] of prices) {
|
|
435
425
|
if (isBase) {
|
|
436
426
|
if (sumBaseQty >= requiredQty) {
|
|
@@ -470,10 +460,6 @@ export class Cables extends SimpleExchange implements IDex<any> {
|
|
|
470
460
|
selectedRows.push([price, currentBaseQty.toString()]);
|
|
471
461
|
}
|
|
472
462
|
|
|
473
|
-
if (sumBaseQty == 0) {
|
|
474
|
-
return 0;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
463
|
const vSumBase = selectedRows.reduce((sum: number, [price, volume]) => {
|
|
478
464
|
return sum + Number(price) * Number(volume);
|
|
479
465
|
}, 0);
|
|
@@ -482,24 +468,11 @@ export class Cables extends SimpleExchange implements IDex<any> {
|
|
|
482
468
|
.dividedBy(new BigNumber(sumBaseQty))
|
|
483
469
|
.toNumber();
|
|
484
470
|
|
|
485
|
-
let result: any;
|
|
486
471
|
if (isBase) {
|
|
487
|
-
|
|
472
|
+
return requiredQty / price;
|
|
488
473
|
} else {
|
|
489
|
-
|
|
474
|
+
return requiredQty * price;
|
|
490
475
|
}
|
|
491
|
-
|
|
492
|
-
if (isQuote) {
|
|
493
|
-
if (requiredQty > totalVolume) {
|
|
494
|
-
result = 0;
|
|
495
|
-
}
|
|
496
|
-
} else {
|
|
497
|
-
if (result > totalVolume) {
|
|
498
|
-
result = 0;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
return result;
|
|
503
476
|
}
|
|
504
477
|
|
|
505
478
|
async getPricesVolume(
|
|
@@ -565,10 +538,10 @@ export class Cables extends SimpleExchange implements IDex<any> {
|
|
|
565
538
|
const priceData = priceMap[pairKey];
|
|
566
539
|
|
|
567
540
|
let orderbook: any[] = [];
|
|
568
|
-
|
|
569
|
-
// reverse orderbook if isInputQuote
|
|
570
|
-
if (isInputQuote) {
|
|
541
|
+
if (side === SwapSide.BUY) {
|
|
571
542
|
orderbook = priceData.asks;
|
|
543
|
+
} else {
|
|
544
|
+
orderbook = priceData.bids;
|
|
572
545
|
}
|
|
573
546
|
if (orderbook?.length === 0) {
|
|
574
547
|
throw new Error(`Empty orderbook for ${pairKey}`);
|
|
@@ -7,14 +7,14 @@ export const FluidDexConfig: DexConfigMap<DexParams> = {
|
|
|
7
7
|
[Network.MAINNET]: {
|
|
8
8
|
commonAddresses: {
|
|
9
9
|
liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497',
|
|
10
|
-
resolver: '
|
|
10
|
+
resolver: '0x45f4ad57e300da55c33dea579a40fcee000d7b94',
|
|
11
11
|
dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085',
|
|
12
12
|
},
|
|
13
13
|
},
|
|
14
14
|
[Network.ARBITRUM]: {
|
|
15
15
|
commonAddresses: {
|
|
16
16
|
liquidityProxy: '0x52Aa899454998Be5b000Ad077a46Bbe360F4e497',
|
|
17
|
-
resolver: '
|
|
17
|
+
resolver: '0xb8f526718FF58758E256D9aD86bC194a9ff5986D',
|
|
18
18
|
dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085',
|
|
19
19
|
},
|
|
20
20
|
},
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const MIN_SWAP_LIQUIDITY = 8500n;
|
|
1
|
+
export const MIN_SWAP_LIQUIDITY = 10n ** 4n;
|