@paraswap/dex-lib 2.20.1 → 2.20.2-curve-new-implementations.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/build/dex/aave-v3/tokens/arbitrum.json +50 -0
- package/build/dex/aave-v3/tokens/avalanche.json +74 -0
- package/build/dex/aave-v3/tokens/fantom.json +62 -0
- package/build/dex/aave-v3/tokens/optimism.json +50 -0
- package/build/dex/aave-v3/tokens/polygon.json +116 -0
- package/build/dex/curve-v1-factory/config.js +87 -8
- package/build/dex/curve-v1-factory/config.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.js +2 -2
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js +27 -3
- package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js +6 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js +6 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js +6 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js +6 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js +6 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js +6 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/constants.js +66 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/constants.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js +6 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js +20 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js +6 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js +26 -3
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js +6 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js +6 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js +6 -0
- package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.d.ts +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js +2 -2
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.d.ts +3 -1
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +22 -3
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.d.ts +2 -1
- package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js +2 -1
- package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js.map +1 -1
- package/build/dex/curve-v1-factory/types.d.ts +16 -0
- package/build/dex/curve-v1-factory/types.js +6 -0
- package/build/dex/curve-v1-factory/types.js.map +1 -1
- package/build/dex/test-dex/config.d.ts +4 -0
- package/build/dex/test-dex/config.js +15 -0
- package/build/dex/test-dex/config.js.map +1 -0
- package/build/dex/test-dex/test-dex-pool.d.ts +39 -0
- package/build/dex/test-dex/test-dex-pool.js +63 -0
- package/build/dex/test-dex/test-dex-pool.js.map +1 -0
- package/build/dex/test-dex/test-dex.d.ts +37 -0
- package/build/dex/test-dex/test-dex.js +126 -0
- package/build/dex/test-dex/test-dex.js.map +1 -0
- package/build/dex/test-dex/types.d.ts +6 -0
- package/build/dex/test-dex/types.js +3 -0
- package/build/dex/test-dex/types.js.map +1 -0
- package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
- package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
- package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
- package/package.json +1 -1
- package/src/dex/curve-v1-factory/config.ts +87 -8
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +36 -0
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +3 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.ts +53 -6
- package/src/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.ts +7 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/_rates.ts +7 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/_xp.ts +7 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/_xp_mem.ts +7 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.ts +7 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.ts +7 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +78 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D.ts +13 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D_mem.ts +40 -3
- package/src/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.ts +7 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_dy.ts +53 -4
- package/src/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.ts +7 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_y.ts +7 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_y_D.ts +7 -0
- package/src/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.ts +2 -0
- package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +42 -1
- package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +1 -0
- package/src/dex/curve-v1-factory/types.ts +14 -0
- package/tests/constants-e2e.ts +6 -1
|
@@ -3,7 +3,7 @@ import { ImplementationNames, PoolState } from '../../types';
|
|
|
3
3
|
import { get_D_mem, IPoolContext } from '../types';
|
|
4
4
|
import { requireConstant, throwNotExist, throwNotImplemented } from './utils';
|
|
5
5
|
|
|
6
|
-
const factoryPlain2Basic = (
|
|
6
|
+
const factoryPlain2Basic: get_D_mem = (
|
|
7
7
|
self: IPoolContext,
|
|
8
8
|
state: PoolState,
|
|
9
9
|
_balances: bigint[],
|
|
@@ -13,7 +13,7 @@ const factoryPlain2Basic = (
|
|
|
13
13
|
return self.get_D(self, self._xp_mem(self, rates, _balances), amp);
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
const customPlain3CoinThree = (
|
|
16
|
+
const customPlain3CoinThree: get_D_mem = (
|
|
17
17
|
self: IPoolContext,
|
|
18
18
|
state: PoolState,
|
|
19
19
|
_balances: bigint[],
|
|
@@ -23,7 +23,7 @@ const customPlain3CoinThree = (
|
|
|
23
23
|
return self.get_D(self, self._xp_mem(self, [...RATES], _balances), amp);
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
const customPlain3CoinSbtc = (
|
|
26
|
+
const customPlain3CoinSbtc: get_D_mem = (
|
|
27
27
|
self: IPoolContext,
|
|
28
28
|
state: PoolState,
|
|
29
29
|
_balances: bigint[],
|
|
@@ -36,6 +36,36 @@ const customPlain3CoinSbtc = (
|
|
|
36
36
|
);
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
const factoryMetaBtcSbtc2: get_D_mem = (
|
|
40
|
+
self: IPoolContext,
|
|
41
|
+
state: PoolState,
|
|
42
|
+
_balances: bigint[],
|
|
43
|
+
amp: bigint,
|
|
44
|
+
): bigint => {
|
|
45
|
+
if (state.virtualPrice === undefined) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`${self.IMPLEMENTATION_NAME} factoryMetaBtcSbtc2: virtualPrice is not provided`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const rates = [state.constants.rate_multipliers[0], state.virtualPrice];
|
|
51
|
+
return self.get_D(self, self._xp_mem(self, rates, _balances), amp);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const factoryPlain2EthEma2: get_D_mem = (
|
|
55
|
+
self: IPoolContext,
|
|
56
|
+
state: PoolState,
|
|
57
|
+
_balances: bigint[],
|
|
58
|
+
amp: bigint,
|
|
59
|
+
) => {
|
|
60
|
+
if (state.storedRates === undefined) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`${self.IMPLEMENTATION_NAME} factoryPlain2EthEma2: storedRates is not provided`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
const rates = [...state.storedRates];
|
|
66
|
+
return self.get_D(self, self._xp_mem(self, rates, _balances), amp);
|
|
67
|
+
};
|
|
68
|
+
|
|
39
69
|
const notImplemented: get_D_mem = (
|
|
40
70
|
self: IPoolContext,
|
|
41
71
|
state: PoolState,
|
|
@@ -57,6 +87,7 @@ const notExist: get_D_mem = (
|
|
|
57
87
|
export const implementations: Record<ImplementationNames, get_D_mem> = {
|
|
58
88
|
[ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: customPlain3CoinThree,
|
|
59
89
|
[ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: customPlain3CoinSbtc,
|
|
90
|
+
[ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: customPlain3CoinThree,
|
|
60
91
|
[ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: customPlain3CoinSbtc,
|
|
61
92
|
[ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: customPlain3CoinThree,
|
|
62
93
|
|
|
@@ -103,6 +134,12 @@ export const implementations: Record<ImplementationNames, get_D_mem> = {
|
|
|
103
134
|
[ImplementationNames.FACTORY_PLAIN_4_BASIC]: notImplemented,
|
|
104
135
|
[ImplementationNames.FACTORY_PLAIN_4_ETH]: notImplemented,
|
|
105
136
|
[ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notImplemented,
|
|
137
|
+
|
|
138
|
+
[ImplementationNames.FACTORY_META_BTC_SBTC2]: factoryMetaBtcSbtc2,
|
|
139
|
+
[ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: factoryMetaBtcSbtc2,
|
|
140
|
+
[ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: factoryPlain2Basic,
|
|
141
|
+
[ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: factoryPlain2Basic,
|
|
142
|
+
[ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2EthEma2,
|
|
106
143
|
};
|
|
107
144
|
|
|
108
145
|
export default implementations;
|
|
@@ -51,6 +51,7 @@ const makeFuncCacheable = (func: get_D_precisions): get_D_precisions => {
|
|
|
51
51
|
const implementations: Record<ImplementationNames, get_D_precisions> = {
|
|
52
52
|
[ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: notExist,
|
|
53
53
|
[ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: notExist,
|
|
54
|
+
[ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: notExist,
|
|
54
55
|
[ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: notExist,
|
|
55
56
|
[ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: notExist,
|
|
56
57
|
|
|
@@ -105,6 +106,12 @@ const implementations: Record<ImplementationNames, get_D_precisions> = {
|
|
|
105
106
|
[ImplementationNames.FACTORY_PLAIN_4_BASIC]: notExist,
|
|
106
107
|
[ImplementationNames.FACTORY_PLAIN_4_ETH]: notExist,
|
|
107
108
|
[ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notExist,
|
|
109
|
+
|
|
110
|
+
[ImplementationNames.FACTORY_META_BTC_SBTC2]: notExist,
|
|
111
|
+
[ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: notExist,
|
|
112
|
+
[ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: notExist,
|
|
113
|
+
[ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
|
|
114
|
+
[ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
|
|
108
115
|
};
|
|
109
116
|
|
|
110
117
|
export default implementations;
|
|
@@ -3,16 +3,15 @@ import { ImplementationNames, PoolState } from '../../types';
|
|
|
3
3
|
import { get_dy, IPoolContext } from '../types';
|
|
4
4
|
import { requireConstant, requireValue } from './utils';
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const _genericFactoryPlain2Basic = (
|
|
7
7
|
self: IPoolContext,
|
|
8
8
|
state: PoolState,
|
|
9
9
|
i: number,
|
|
10
10
|
j: number,
|
|
11
11
|
dx: bigint,
|
|
12
|
-
|
|
12
|
+
rates: bigint[],
|
|
13
|
+
) => {
|
|
13
14
|
const { PRECISION, FEE_DENOMINATOR } = self.constants;
|
|
14
|
-
const { rate_multipliers } = state.constants;
|
|
15
|
-
const rates = [...rate_multipliers];
|
|
16
15
|
const xp = self._xp_mem(self, rates, state.balances);
|
|
17
16
|
|
|
18
17
|
const x = xp[i] + (dx * rates[i]) / PRECISION;
|
|
@@ -22,6 +21,49 @@ const factoryPlain2Basic: get_dy = (
|
|
|
22
21
|
return ((dy - _fee) * PRECISION) / rates[j];
|
|
23
22
|
};
|
|
24
23
|
|
|
24
|
+
const factoryPlain2Basic: get_dy = (
|
|
25
|
+
self: IPoolContext,
|
|
26
|
+
state: PoolState,
|
|
27
|
+
i: number,
|
|
28
|
+
j: number,
|
|
29
|
+
dx: bigint,
|
|
30
|
+
): bigint => {
|
|
31
|
+
const { rate_multipliers } = state.constants;
|
|
32
|
+
const rates = [...rate_multipliers];
|
|
33
|
+
return _genericFactoryPlain2Basic(self, state, i, j, dx, rates);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const factoryPlain2EthEma2: get_dy = (
|
|
37
|
+
self: IPoolContext,
|
|
38
|
+
state: PoolState,
|
|
39
|
+
i: number,
|
|
40
|
+
j: number,
|
|
41
|
+
dx: bigint,
|
|
42
|
+
): bigint => {
|
|
43
|
+
if (state.storedRates === undefined) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`${self.IMPLEMENTATION_NAME} factoryPlain2EthEma2: storedRates is not provided`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
const rates = [...state.storedRates];
|
|
49
|
+
return _genericFactoryPlain2Basic(self, state, i, j, dx, rates);
|
|
50
|
+
};
|
|
51
|
+
const factoryMetaBtcSbtc2: get_dy = (
|
|
52
|
+
self: IPoolContext,
|
|
53
|
+
state: PoolState,
|
|
54
|
+
i: number,
|
|
55
|
+
j: number,
|
|
56
|
+
dx: bigint,
|
|
57
|
+
): bigint => {
|
|
58
|
+
if (state.virtualPrice === undefined) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`${self.IMPLEMENTATION_NAME} factoryMetaBtcSbtc2: virtualPrice is not provided`,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const rates = [state.constants.rate_multipliers[0], state.virtualPrice];
|
|
64
|
+
return _genericFactoryPlain2Basic(self, state, i, j, dx, rates);
|
|
65
|
+
};
|
|
66
|
+
|
|
25
67
|
const factoryPlain2Optimized: get_dy = (
|
|
26
68
|
self: IPoolContext,
|
|
27
69
|
state: PoolState,
|
|
@@ -167,6 +209,7 @@ const customAvalanche3CoinLending: get_dy = (
|
|
|
167
209
|
const implementations: Record<ImplementationNames, get_dy> = {
|
|
168
210
|
[ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: customPlain2CoinFrax,
|
|
169
211
|
[ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: customPlain3CoinBtc,
|
|
212
|
+
[ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: customPlain2CoinFrax,
|
|
170
213
|
[ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: customPlain3CoinBtc,
|
|
171
214
|
[ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: customPlain3CoinThree,
|
|
172
215
|
|
|
@@ -217,6 +260,12 @@ const implementations: Record<ImplementationNames, get_dy> = {
|
|
|
217
260
|
[ImplementationNames.FACTORY_PLAIN_4_BASIC]: factoryPlain2Basic,
|
|
218
261
|
[ImplementationNames.FACTORY_PLAIN_4_ETH]: factoryPlain2Basic,
|
|
219
262
|
[ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: factoryPlain2Optimized,
|
|
263
|
+
|
|
264
|
+
[ImplementationNames.FACTORY_META_BTC_SBTC2]: factoryMetaBtcSbtc2,
|
|
265
|
+
[ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: factoryMetaBtcSbtc2,
|
|
266
|
+
[ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: factoryPlain2Basic,
|
|
267
|
+
[ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: factoryPlain2Basic,
|
|
268
|
+
[ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2EthEma2,
|
|
220
269
|
};
|
|
221
270
|
|
|
222
271
|
export default implementations;
|
|
@@ -231,6 +231,7 @@ const notExist: get_dy_underlying = (
|
|
|
231
231
|
const implementations: Record<ImplementationNames, get_dy_underlying> = {
|
|
232
232
|
[ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: notExist,
|
|
233
233
|
[ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: notExist,
|
|
234
|
+
[ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: notExist,
|
|
234
235
|
[ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: notExist,
|
|
235
236
|
[ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: notExist,
|
|
236
237
|
|
|
@@ -278,6 +279,12 @@ const implementations: Record<ImplementationNames, get_dy_underlying> = {
|
|
|
278
279
|
[ImplementationNames.FACTORY_PLAIN_4_BASIC]: notExist,
|
|
279
280
|
[ImplementationNames.FACTORY_PLAIN_4_ETH]: notExist,
|
|
280
281
|
[ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notExist,
|
|
282
|
+
|
|
283
|
+
[ImplementationNames.FACTORY_META_BTC_SBTC2]: factoryMetaUsdFraxUsdc,
|
|
284
|
+
[ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: factoryMetaUsdFraxUsdc,
|
|
285
|
+
[ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: notExist,
|
|
286
|
+
[ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
|
|
287
|
+
[ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
|
|
281
288
|
};
|
|
282
289
|
|
|
283
290
|
export default implementations;
|
|
@@ -135,6 +135,7 @@ const customPlain2CoinFrax = (
|
|
|
135
135
|
const implementations: Record<ImplementationNames, get_y> = {
|
|
136
136
|
[ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: customPlain2CoinFrax,
|
|
137
137
|
[ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: customPlain3CoinThree,
|
|
138
|
+
[ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: customPlain2CoinFrax,
|
|
138
139
|
[ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: customPlain3CoinThree,
|
|
139
140
|
[ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: customPlain3CoinThree,
|
|
140
141
|
|
|
@@ -182,6 +183,12 @@ const implementations: Record<ImplementationNames, get_y> = {
|
|
|
182
183
|
[ImplementationNames.FACTORY_PLAIN_4_BASIC]: customPlain2CoinFrax,
|
|
183
184
|
[ImplementationNames.FACTORY_PLAIN_4_ETH]: customPlain2CoinFrax,
|
|
184
185
|
[ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: customPlain2CoinFrax,
|
|
186
|
+
|
|
187
|
+
[ImplementationNames.FACTORY_META_BTC_SBTC2]: customPlain2CoinFrax,
|
|
188
|
+
[ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: customPlain2CoinFrax,
|
|
189
|
+
[ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: customPlain2CoinFrax,
|
|
190
|
+
[ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain2CoinFrax,
|
|
191
|
+
[ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain2CoinFrax,
|
|
185
192
|
};
|
|
186
193
|
|
|
187
194
|
export default implementations;
|
|
@@ -122,6 +122,7 @@ const notImplemented: get_y_D = (
|
|
|
122
122
|
const implementations: Record<ImplementationNames, get_y_D> = {
|
|
123
123
|
[ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: customPlain2CoinFrax,
|
|
124
124
|
[ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: customPlain3CoinThree,
|
|
125
|
+
[ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: customPlain2CoinFrax,
|
|
125
126
|
[ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: customPlain3CoinThree,
|
|
126
127
|
[ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: customPlain3CoinThree,
|
|
127
128
|
|
|
@@ -168,6 +169,12 @@ const implementations: Record<ImplementationNames, get_y_D> = {
|
|
|
168
169
|
[ImplementationNames.FACTORY_PLAIN_4_BASIC]: notImplemented,
|
|
169
170
|
[ImplementationNames.FACTORY_PLAIN_4_ETH]: notImplemented,
|
|
170
171
|
[ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notImplemented,
|
|
172
|
+
|
|
173
|
+
[ImplementationNames.FACTORY_META_BTC_SBTC2]: customPlain2CoinFrax,
|
|
174
|
+
[ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: customPlain2CoinFrax,
|
|
175
|
+
[ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: customPlain2CoinFrax,
|
|
176
|
+
[ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain2CoinFrax,
|
|
177
|
+
[ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain2CoinFrax,
|
|
171
178
|
};
|
|
172
179
|
|
|
173
180
|
export default implementations;
|
|
@@ -114,6 +114,7 @@ export class CustomBasePoolForFactory extends PoolPollingBase {
|
|
|
114
114
|
readonly useLending?: boolean[],
|
|
115
115
|
readonly isUsedForPricing: boolean = false,
|
|
116
116
|
readonly contractABIs = ContractABIs,
|
|
117
|
+
customGasCost?: number,
|
|
117
118
|
) {
|
|
118
119
|
// Current custom pools are always plain
|
|
119
120
|
super(
|
|
@@ -131,6 +132,7 @@ export class CustomBasePoolForFactory extends PoolPollingBase {
|
|
|
131
132
|
isLendingPool,
|
|
132
133
|
undefined,
|
|
133
134
|
CustomBasePoolForFactory.IS_SRC_FEE_ON_TRANSFER_SUPPORTED,
|
|
135
|
+
customGasCost,
|
|
134
136
|
);
|
|
135
137
|
}
|
|
136
138
|
|
|
@@ -14,10 +14,21 @@ import { BytesLike } from 'ethers/lib/utils';
|
|
|
14
14
|
import { Address } from '@paraswap/core';
|
|
15
15
|
import { BigNumber } from 'ethers';
|
|
16
16
|
import { _require } from '../../../utils';
|
|
17
|
+
import { AbiItem } from 'web3-utils';
|
|
17
18
|
|
|
18
19
|
const DEFAULT_2_ZERO_ARRAY = [0n, 0n];
|
|
19
20
|
const DEFAULT_4_ZERO_ARRAY = [0n, 0n, 0n, 0n];
|
|
20
21
|
|
|
22
|
+
type AdditionalContractFunctions = 'stored_rates';
|
|
23
|
+
|
|
24
|
+
const getStoredRatesABI = (n: number) => ({
|
|
25
|
+
name: 'stored_rates',
|
|
26
|
+
stateMutability: 'view',
|
|
27
|
+
type: 'function',
|
|
28
|
+
inputs: [],
|
|
29
|
+
outputs: [{ name: '', type: `uint256[${n}]` }],
|
|
30
|
+
});
|
|
31
|
+
|
|
21
32
|
export class FactoryStateHandler extends PoolPollingBase {
|
|
22
33
|
constructor(
|
|
23
34
|
readonly logger: Logger,
|
|
@@ -34,9 +45,14 @@ export class FactoryStateHandler extends PoolPollingBase {
|
|
|
34
45
|
readonly poolContextConstants: PoolContextConstants,
|
|
35
46
|
readonly isSrcFeeOnTransferSupported: boolean,
|
|
36
47
|
baseStatePoolPolling?: PoolPollingBase,
|
|
48
|
+
customGasCost?: number,
|
|
49
|
+
readonly isStoredRatesSupported: boolean = false,
|
|
37
50
|
private factoryIface: Interface = new Interface(
|
|
38
51
|
FactoryCurveV1ABI as JsonFragment[],
|
|
39
52
|
),
|
|
53
|
+
private additionalFuncsIface: Interface = new Interface([
|
|
54
|
+
getStoredRatesABI(poolContextConstants.N_COINS),
|
|
55
|
+
]),
|
|
40
56
|
) {
|
|
41
57
|
super(
|
|
42
58
|
logger,
|
|
@@ -53,6 +69,7 @@ export class FactoryStateHandler extends PoolPollingBase {
|
|
|
53
69
|
false,
|
|
54
70
|
baseStatePoolPolling,
|
|
55
71
|
isSrcFeeOnTransferSupported,
|
|
72
|
+
customGasCost,
|
|
56
73
|
);
|
|
57
74
|
|
|
58
75
|
if (this.isMetaPool && this.baseStatePoolPolling === undefined) {
|
|
@@ -93,6 +110,24 @@ export class FactoryStateHandler extends PoolPollingBase {
|
|
|
93
110
|
),
|
|
94
111
|
},
|
|
95
112
|
];
|
|
113
|
+
|
|
114
|
+
if (this.isStoredRatesSupported) {
|
|
115
|
+
calls.push({
|
|
116
|
+
target: this.address,
|
|
117
|
+
callData: this.additionalFuncsIface.encodeFunctionData(
|
|
118
|
+
'stored_rates',
|
|
119
|
+
[],
|
|
120
|
+
),
|
|
121
|
+
decodeFunction: (result: MultiResult<BytesLike> | BytesLike) =>
|
|
122
|
+
generalDecoder(
|
|
123
|
+
result,
|
|
124
|
+
[`uint256[${this.poolContextConstants.N_COINS}]`],
|
|
125
|
+
new Array(this.poolContextConstants.N_COINS).fill(0n),
|
|
126
|
+
parsed => parsed[0].map((p: BigNumber) => p.toBigInt()),
|
|
127
|
+
),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
96
131
|
return calls;
|
|
97
132
|
}
|
|
98
133
|
|
|
@@ -101,7 +136,12 @@ export class FactoryStateHandler extends PoolPollingBase {
|
|
|
101
136
|
blockNumber: number,
|
|
102
137
|
updatedAtMs: number,
|
|
103
138
|
): PoolState {
|
|
104
|
-
const [A, fees, balances] = multiOutputs as [
|
|
139
|
+
const [A, fees, balances, storedRates] = multiOutputs as [
|
|
140
|
+
bigint,
|
|
141
|
+
bigint[],
|
|
142
|
+
bigint[],
|
|
143
|
+
bigint[] | undefined,
|
|
144
|
+
];
|
|
105
145
|
|
|
106
146
|
let basePoolState: PoolState | undefined;
|
|
107
147
|
if (this.isMetaPool) {
|
|
@@ -126,6 +166,7 @@ export class FactoryStateHandler extends PoolPollingBase {
|
|
|
126
166
|
basePoolState,
|
|
127
167
|
updatedAtMs,
|
|
128
168
|
blockNumber,
|
|
169
|
+
storedRates,
|
|
129
170
|
};
|
|
130
171
|
}
|
|
131
172
|
}
|
|
@@ -48,6 +48,7 @@ export abstract class PoolPollingBase {
|
|
|
48
48
|
readonly isLendingPool: boolean,
|
|
49
49
|
readonly baseStatePoolPolling: PoolPollingBase | undefined,
|
|
50
50
|
readonly isSrcFeeOnTransferSupported: boolean,
|
|
51
|
+
readonly customGasCost: number | undefined,
|
|
51
52
|
) {
|
|
52
53
|
this.fullName = `${dexKey}-${network}-${this.CLASS_NAME}-${this.implementationName}-${this.address}`;
|
|
53
54
|
this.isMetaPool = baseStatePoolPolling !== undefined;
|
|
@@ -57,6 +57,7 @@ export type PoolState = {
|
|
|
57
57
|
exchangeRateCurrent?: (bigint | undefined)[]; // from cToken -> exchangeRateCurrent()
|
|
58
58
|
offpeg_fee_multiplier?: bigint; // from pool
|
|
59
59
|
basePoolState?: PoolState;
|
|
60
|
+
storedRates?: bigint[]; // from pool, but only for oracle ones
|
|
60
61
|
};
|
|
61
62
|
|
|
62
63
|
export type PoolStateWithUpdateInfo<T> = {
|
|
@@ -84,6 +85,9 @@ export enum FactoryImplementationNames {
|
|
|
84
85
|
FACTORY_META_BTC = 'factory_meta_btc',
|
|
85
86
|
FACTORY_META_BTC_BALANCES = 'factory_meta_btc_balances',
|
|
86
87
|
|
|
88
|
+
FACTORY_META_BTC_SBTC2 = 'factory_meta_btc_sbtc2',
|
|
89
|
+
FACTORY_META_BTC_BALANCES_SBTC2 = 'factory_meta_btc_balances_sbtc2',
|
|
90
|
+
|
|
87
91
|
FACTORY_META_BTC_REN = 'factory_meta_btc_ren',
|
|
88
92
|
FACTORY_META_BTC_BALANCES_REN = 'factory_meta_btc_balances_ren',
|
|
89
93
|
|
|
@@ -95,7 +99,10 @@ export enum FactoryImplementationNames {
|
|
|
95
99
|
|
|
96
100
|
FACTORY_PLAIN_2_BALANCES = 'factory_plain_2_balances',
|
|
97
101
|
FACTORY_PLAIN_2_BASIC = 'factory_plain_2_basic',
|
|
102
|
+
FACTORY_PLAIN_2_BASIC_EMA = 'factory_plain_2_basic_ema',
|
|
98
103
|
FACTORY_PLAIN_2_ETH = 'factory_plain_2_eth',
|
|
104
|
+
FACTORY_PLAIN_2_ETH_EMA = 'factory_plain_2_eth_ema',
|
|
105
|
+
FACTORY_PLAIN_2_ETH_EMA2 = 'factory_plain_2_eth_ema2',
|
|
99
106
|
FACTORY_PLAIN_2_OPTIMIZED = 'factory_plain_2_optimized',
|
|
100
107
|
|
|
101
108
|
FACTORY_PLAIN_3_BALANCES = 'factory_plain_3_balances',
|
|
@@ -114,6 +121,7 @@ export enum CustomImplementationNames {
|
|
|
114
121
|
CUSTOM_PLAIN_2COIN_RENBTC = 'custom_plain_2coin_renbtc',
|
|
115
122
|
CUSTOM_PLAIN_3COIN_SBTC = 'custom_plain_3coin_sbtc',
|
|
116
123
|
CUSTOM_PLAIN_3COIN_THREE = 'custom_plain_3coin_three',
|
|
124
|
+
CUSTOM_PLAIN_2COIN_WBTC = 'custom_plain_2coin_wbtc',
|
|
117
125
|
|
|
118
126
|
CUSTOM_ARBITRUM_2COIN_USD = 'custom_arbitrum_2coin_usd',
|
|
119
127
|
CUSTOM_ARBITRUM_2COIN_BTC = 'custom_arbitrum_2coin_btc',
|
|
@@ -144,6 +152,8 @@ export type FactoryPoolImplementations = {
|
|
|
144
152
|
name: FactoryImplementationNames;
|
|
145
153
|
address: Address;
|
|
146
154
|
basePoolAddress?: Address;
|
|
155
|
+
customGasCost?: number;
|
|
156
|
+
isStoreRateSupported?: boolean;
|
|
147
157
|
};
|
|
148
158
|
|
|
149
159
|
export type CustomPoolConfig = {
|
|
@@ -157,6 +167,10 @@ export type CustomPoolConfig = {
|
|
|
157
167
|
// You must specify what typ must be encoded/decoded for coins request
|
|
158
168
|
coinsInputType: string;
|
|
159
169
|
balancesInputType: string;
|
|
170
|
+
// Because we have legacy event based implementation and new one, we don't want to use all
|
|
171
|
+
// pools for pricing. Only the ones that are explicitly specified. After legacy is fully moved to this implementation
|
|
172
|
+
// we can remove this flag
|
|
173
|
+
useForPricing: boolean;
|
|
160
174
|
};
|
|
161
175
|
|
|
162
176
|
export type DexParams = {
|
package/tests/constants-e2e.ts
CHANGED
|
@@ -43,6 +43,10 @@ export const Tokens: {
|
|
|
43
43
|
addBalance: balancesFn,
|
|
44
44
|
addAllowance: allowedFn,
|
|
45
45
|
},
|
|
46
|
+
sBTC: {
|
|
47
|
+
address: '0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6',
|
|
48
|
+
decimals: 18,
|
|
49
|
+
},
|
|
46
50
|
BADGER: {
|
|
47
51
|
address: '0x3472A5A71965499acd81997a54BBA8D852C6E53d',
|
|
48
52
|
decimals: 18,
|
|
@@ -833,7 +837,8 @@ export const Holders: {
|
|
|
833
837
|
[Network.MAINNET]: {
|
|
834
838
|
ETH: '0x176F3DAb24a159341c0509bB36B833E7fdd0a132',
|
|
835
839
|
USDC: '0x79E2Ba942B0e8fDB6ff3d406e930289d10B49ADe',
|
|
836
|
-
WBTC: '
|
|
840
|
+
WBTC: '0x1cb17a66dc606a52785f69f08f4256526abd4943',
|
|
841
|
+
sBTC: '0xA2e3475D13776C6E42ff37B47286827d959B2195',
|
|
837
842
|
BADGER: '0x34e2741a3f8483dbe5231f61c005110ff4b9f50a',
|
|
838
843
|
STETH: '0x9bdb521a97e95177bf252c253e256a60c3e14447',
|
|
839
844
|
wstETH: '0x6cE0F913F035ec6195bC3cE885aec4C66E485BC4',
|