@paraswap/dex-lib 2.20.3 → 2.21.1
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 +91 -9
- package/build/dex/curve-v1-factory/config.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.js +9 -3
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.js +2 -0
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.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 -4
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js +2 -5
- 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/polling-manager.d.ts +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/polling-manager.js +28 -3
- package/build/dex/curve-v1-factory/state-polling-pools/polling-manager.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/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/quickswap/camelot-v3.d.ts +6 -0
- package/build/dex/quickswap/camelot-v3.js +19 -0
- package/build/dex/quickswap/camelot-v3.js.map +1 -0
- package/build/dex/quickswap/config.js +8 -0
- package/build/dex/quickswap/config.js.map +1 -1
- package/build/dex/swaap-v2/rate-fetcher.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 +91 -9
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +36 -0
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +12 -1
- package/src/dex/curve-v1-factory/curve-v1-pool-manager.ts +6 -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 +5 -3
- package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +42 -1
- package/src/dex/curve-v1-factory/state-polling-pools/polling-manager.ts +43 -9
- 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/src/dex/index.ts +2 -0
- package/src/dex/quickswap/camelot-v3.ts +15 -0
- package/src/dex/quickswap/config.ts +9 -0
- package/src/dex/quickswap/quickswap-e2e.test.ts +109 -0
- package/src/dex/swaap-v2/rate-fetcher.ts +10 -10
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +1 -4
- package/tests/constants-e2e.ts +6 -10
|
@@ -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;
|
|
@@ -100,9 +100,9 @@ export class CustomBasePoolForFactory extends PoolPollingBase {
|
|
|
100
100
|
readonly dexKey: string,
|
|
101
101
|
network: number,
|
|
102
102
|
cacheStateKey: string,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
implementationName: ImplementationNames,
|
|
104
|
+
implementationAddress: Address,
|
|
105
|
+
address: Address,
|
|
106
106
|
stateUpdatePeriodMs: number,
|
|
107
107
|
readonly poolIdentifier: string,
|
|
108
108
|
readonly poolConstants: PoolConstants,
|
|
@@ -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
|
}
|
|
@@ -3,7 +3,7 @@ import { Network } from '../../../constants';
|
|
|
3
3
|
import { IDexHelper } from '../../../dex-helper';
|
|
4
4
|
import { Utils, _require } from '../../../utils';
|
|
5
5
|
import { PoolState } from '../types';
|
|
6
|
-
import { PoolPollingBase } from './pool-polling-base';
|
|
6
|
+
import { MulticallReturnedTypes, PoolPollingBase } from './pool-polling-base';
|
|
7
7
|
|
|
8
8
|
/*
|
|
9
9
|
* Since we are updating all pools state at once, I need some generalized iterator without state,
|
|
@@ -15,7 +15,7 @@ export class StatePollingManager {
|
|
|
15
15
|
dexHelper: IDexHelper,
|
|
16
16
|
pools: PoolPollingBase[],
|
|
17
17
|
blockNumber?: number,
|
|
18
|
-
): Promise<PoolState[]> {
|
|
18
|
+
): Promise<(PoolState | null)[]> {
|
|
19
19
|
if (pools.length === 0) {
|
|
20
20
|
return [];
|
|
21
21
|
}
|
|
@@ -42,7 +42,8 @@ export class StatePollingManager {
|
|
|
42
42
|
_blockNumber = 0;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const
|
|
45
|
+
const results = await dexHelper.multiWrapper.tryAggregate(
|
|
46
|
+
false,
|
|
46
47
|
callDatas,
|
|
47
48
|
blockNumber,
|
|
48
49
|
1000,
|
|
@@ -52,8 +53,36 @@ export class StatePollingManager {
|
|
|
52
53
|
let lastStart = 0;
|
|
53
54
|
|
|
54
55
|
for (const [i, p] of pools.entries()) {
|
|
56
|
+
const resultsForPool = results.slice(
|
|
57
|
+
lastStart,
|
|
58
|
+
lastStart + poolResultDividers[i],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
let someCallsFailed = false;
|
|
62
|
+
let failedCalls: number[] = [];
|
|
63
|
+
const multiOutputs = resultsForPool.map((result, i) => {
|
|
64
|
+
if (result.success === false) {
|
|
65
|
+
someCallsFailed = true;
|
|
66
|
+
failedCalls.push(i);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return result.returnData;
|
|
70
|
+
// I consider this conversion safe without further checks, because if call failed, we won't proceed to state parsing
|
|
71
|
+
}) as MulticallReturnedTypes[];
|
|
72
|
+
|
|
73
|
+
if (someCallsFailed) {
|
|
74
|
+
const multiCallRequests = p.getStateMultiCalldata();
|
|
75
|
+
failedCalls.forEach(i => {
|
|
76
|
+
p.logger.error(
|
|
77
|
+
`Call number ${i} for pool=${p.address} to ${multiCallRequests[i].target} with ${multiCallRequests[i].callData} failed`,
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
newStates[i] = null;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
|
|
55
84
|
const newState = p.parseMultiResultsToStateValues(
|
|
56
|
-
|
|
85
|
+
multiOutputs,
|
|
57
86
|
_blockNumber,
|
|
58
87
|
updatedAt,
|
|
59
88
|
);
|
|
@@ -86,13 +115,18 @@ export class StatePollingManager {
|
|
|
86
115
|
);
|
|
87
116
|
await Promise.all(
|
|
88
117
|
pools.map(async (p, i) => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
118
|
+
if (newStates[i] !== null) {
|
|
119
|
+
await dexHelper.cache.hset(
|
|
120
|
+
p.cacheStateKey,
|
|
121
|
+
p.poolIdentifier,
|
|
122
|
+
Utils.Serialize(newStates[i]),
|
|
123
|
+
);
|
|
124
|
+
} else {
|
|
125
|
+
await dexHelper.cache.hdel(p.cacheStateKey, [p.poolIdentifier]);
|
|
126
|
+
}
|
|
94
127
|
}),
|
|
95
128
|
);
|
|
129
|
+
|
|
96
130
|
logger.info(
|
|
97
131
|
`${dexKey}: all (${pools.length}) pools state was successfully updated on network ${dexHelper.config.data.network}`,
|
|
98
132
|
);
|
|
@@ -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/src/dex/index.ts
CHANGED
|
@@ -63,6 +63,7 @@ import { SolidlyEthereum } from './solidly/solidly-ethereum';
|
|
|
63
63
|
import { MaverickV1 } from './maverick-v1/maverick-v1';
|
|
64
64
|
import { QuickSwapV3 } from './quickswap/quickswap-v3';
|
|
65
65
|
import { ZyberSwapV3 } from './quickswap/zyberswap-v3';
|
|
66
|
+
import { CamelotV3 } from './quickswap/camelot-v3';
|
|
66
67
|
import { TraderJoeV2 } from './trader-joe-v2';
|
|
67
68
|
import { SwaapV2 } from './swaap-v2/swaap-v2';
|
|
68
69
|
import { SpiritSwapV3 } from './quickswap/spiritswap-v3';
|
|
@@ -85,6 +86,7 @@ const LegacyDexes = [
|
|
|
85
86
|
DodoV2,
|
|
86
87
|
QuickSwapV3,
|
|
87
88
|
ZyberSwapV3,
|
|
89
|
+
CamelotV3,
|
|
88
90
|
SpiritSwapV3,
|
|
89
91
|
TraderJoeV2,
|
|
90
92
|
TraderJoeV21,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IDexHelper } from '../../dex-helper';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import { QuickSwapConfig } from './config';
|
|
4
|
+
import { QuickSwapV3 } from './quickswap-v3';
|
|
5
|
+
|
|
6
|
+
const config = _.pick(QuickSwapConfig, ['CamelotV3']).CamelotV3;
|
|
7
|
+
|
|
8
|
+
export class CamelotV3 extends QuickSwapV3 {
|
|
9
|
+
static dexKeys = ['camelotv3'];
|
|
10
|
+
|
|
11
|
+
// public static dexKeysWithNetwork
|
|
12
|
+
constructor(dexHelper: IDexHelper) {
|
|
13
|
+
super(dexHelper, 'camelotv3', config[dexHelper.config.data.network].router);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -3,6 +3,15 @@ import { Network } from '../../constants';
|
|
|
3
3
|
import { DexParams } from './types';
|
|
4
4
|
|
|
5
5
|
export const QuickSwapConfig: DexConfigMap<DexParams> = {
|
|
6
|
+
CamelotV3: {
|
|
7
|
+
[Network.ARBITRUM]: {
|
|
8
|
+
factoryAddress: '0x1a3c9B1d2F0529D97f2afC5136Cc23e58f1FD35B',
|
|
9
|
+
router: '0x1F721E2E82F6676FCE4eA07A5958cF098D339e18',
|
|
10
|
+
quoteAddress: '0x0Fc73040b26E9bC8514fA028D998E73A254Fa76E',
|
|
11
|
+
initCode:
|
|
12
|
+
'0x6c1bebd370ba84753516bc1393c0d0a6c645856da55f5393ac8ab3d6dbc861d3',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
6
15
|
ZyberSwapV3: {
|
|
7
16
|
[Network.ARBITRUM]: {
|
|
8
17
|
factoryAddress: '0x9C2ABD632771b433E5E7507BcaA41cA3b25D8544',
|
|
@@ -353,6 +353,115 @@ describe('QuickSwap', () => {
|
|
|
353
353
|
});
|
|
354
354
|
});
|
|
355
355
|
});
|
|
356
|
+
|
|
357
|
+
describe('CamelotV3', () => {
|
|
358
|
+
const dexKey = 'CamelotV3';
|
|
359
|
+
|
|
360
|
+
const sideToContractMethods = new Map([
|
|
361
|
+
[
|
|
362
|
+
SwapSide.SELL,
|
|
363
|
+
[
|
|
364
|
+
ContractMethod.simpleSwap,
|
|
365
|
+
ContractMethod.multiSwap,
|
|
366
|
+
ContractMethod.megaSwap,
|
|
367
|
+
],
|
|
368
|
+
],
|
|
369
|
+
[SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
|
|
370
|
+
]);
|
|
371
|
+
|
|
372
|
+
const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
|
|
373
|
+
[
|
|
374
|
+
[
|
|
375
|
+
{
|
|
376
|
+
name: 'WBTC',
|
|
377
|
+
sellAmount: '1000',
|
|
378
|
+
buyAmount: '151080000000000',
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
name: 'WETH',
|
|
382
|
+
sellAmount: '1050000000000',
|
|
383
|
+
buyAmount: '1000',
|
|
384
|
+
},
|
|
385
|
+
],
|
|
386
|
+
[
|
|
387
|
+
{
|
|
388
|
+
name: 'WBTC',
|
|
389
|
+
sellAmount: '1000',
|
|
390
|
+
buyAmount: '1300000',
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
name: 'USDC',
|
|
394
|
+
sellAmount: '1000000',
|
|
395
|
+
buyAmount: '1000',
|
|
396
|
+
},
|
|
397
|
+
],
|
|
398
|
+
[
|
|
399
|
+
{
|
|
400
|
+
name: 'WETH',
|
|
401
|
+
sellAmount: '10000000000',
|
|
402
|
+
buyAmount: '10000000',
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
name: 'USDC',
|
|
406
|
+
sellAmount: '10000000',
|
|
407
|
+
buyAmount: '10000000000',
|
|
408
|
+
},
|
|
409
|
+
],
|
|
410
|
+
[
|
|
411
|
+
{
|
|
412
|
+
name: 'ETH',
|
|
413
|
+
sellAmount: '10000000000',
|
|
414
|
+
buyAmount: '10000000',
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
name: 'USDC',
|
|
418
|
+
sellAmount: '10000000',
|
|
419
|
+
buyAmount: '10000000000',
|
|
420
|
+
},
|
|
421
|
+
],
|
|
422
|
+
];
|
|
423
|
+
|
|
424
|
+
sideToContractMethods.forEach((contractMethods, side) =>
|
|
425
|
+
describe(`${side}`, () => {
|
|
426
|
+
contractMethods.forEach((contractMethod: ContractMethod) => {
|
|
427
|
+
pairs.forEach(pair => {
|
|
428
|
+
describe(`${contractMethod}`, () => {
|
|
429
|
+
it(`${pair[0].name} -> ${pair[1].name}`, async () => {
|
|
430
|
+
await testE2E(
|
|
431
|
+
tokens[pair[0].name],
|
|
432
|
+
tokens[pair[1].name],
|
|
433
|
+
holders[pair[0].name],
|
|
434
|
+
side === SwapSide.SELL
|
|
435
|
+
? pair[0].sellAmount
|
|
436
|
+
: pair[0].buyAmount,
|
|
437
|
+
side,
|
|
438
|
+
dexKey,
|
|
439
|
+
contractMethod,
|
|
440
|
+
network,
|
|
441
|
+
provider,
|
|
442
|
+
);
|
|
443
|
+
});
|
|
444
|
+
it(`${pair[1].name} -> ${pair[0].name}`, async () => {
|
|
445
|
+
await testE2E(
|
|
446
|
+
tokens[pair[1].name],
|
|
447
|
+
tokens[pair[0].name],
|
|
448
|
+
holders[pair[1].name],
|
|
449
|
+
side === SwapSide.SELL
|
|
450
|
+
? pair[1].sellAmount
|
|
451
|
+
: pair[1].buyAmount,
|
|
452
|
+
side,
|
|
453
|
+
dexKey,
|
|
454
|
+
contractMethod,
|
|
455
|
+
network,
|
|
456
|
+
provider,
|
|
457
|
+
);
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
}),
|
|
463
|
+
);
|
|
464
|
+
});
|
|
356
465
|
});
|
|
357
466
|
|
|
358
467
|
describe('Fantom', () => {
|
|
@@ -8,11 +8,14 @@ import {
|
|
|
8
8
|
SwaapV2QuoteResponse,
|
|
9
9
|
SwaapV2PriceLevels,
|
|
10
10
|
SwaapV2QuoteRequest,
|
|
11
|
-
SwaapV2OrderType,
|
|
11
|
+
SwaapV2OrderType,
|
|
12
|
+
SwaapV2TokensResponse,
|
|
13
|
+
TokensMap,
|
|
12
14
|
} from './types';
|
|
13
15
|
import {
|
|
14
16
|
priceLevelsResponseValidator,
|
|
15
|
-
getQuoteResponseValidator,
|
|
17
|
+
getQuoteResponseValidator,
|
|
18
|
+
getTokensResponseValidator,
|
|
16
19
|
} from './validators';
|
|
17
20
|
import { normalizeTokenAddress } from './utils';
|
|
18
21
|
import { SWAAP_RFQ_QUOTE_TIMEOUT_MS } from './constants';
|
|
@@ -71,7 +74,7 @@ export class RateFetcher {
|
|
|
71
74
|
},
|
|
72
75
|
config.tokensConfig.tokensIntervalMs,
|
|
73
76
|
logger,
|
|
74
|
-
)
|
|
77
|
+
);
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
start() {
|
|
@@ -89,13 +92,10 @@ export class RateFetcher {
|
|
|
89
92
|
return;
|
|
90
93
|
}
|
|
91
94
|
|
|
92
|
-
const tokensMap = Object.keys(resp.tokens).reduce(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
},
|
|
97
|
-
{} as TokensMap,
|
|
98
|
-
);
|
|
95
|
+
const tokensMap = Object.keys(resp.tokens).reduce((acc, key: string) => {
|
|
96
|
+
acc[key.toLowerCase()] = resp.tokens[key];
|
|
97
|
+
return acc;
|
|
98
|
+
}, {} as TokensMap);
|
|
99
99
|
|
|
100
100
|
this.dexHelper.cache.setex(
|
|
101
101
|
this.dexKey,
|
|
@@ -2,10 +2,7 @@ import dotenv from 'dotenv';
|
|
|
2
2
|
dotenv.config();
|
|
3
3
|
|
|
4
4
|
import { testE2E } from '../../../tests/utils-e2e';
|
|
5
|
-
import {
|
|
6
|
-
Tokens,
|
|
7
|
-
Holders,
|
|
8
|
-
} from '../../../tests/constants-e2e';
|
|
5
|
+
import { Tokens, Holders } from '../../../tests/constants-e2e';
|
|
9
6
|
import { Network, ContractMethod, SwapSide } from '../../constants';
|
|
10
7
|
import { StaticJsonRpcProvider } from '@ethersproject/providers';
|
|
11
8
|
import { generateConfig } from '../../config';
|
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,
|
|
@@ -271,10 +275,6 @@ export const Tokens: {
|
|
|
271
275
|
address: '0x853d955aCEf822Db058eb8505911ED77F175b99e',
|
|
272
276
|
decimals: 18,
|
|
273
277
|
},
|
|
274
|
-
sBTC: {
|
|
275
|
-
address: '0xfE18be6b3Bd88A2D2A7f928d00292E7a9963CfC6',
|
|
276
|
-
decimals: 18,
|
|
277
|
-
},
|
|
278
278
|
sETH: {
|
|
279
279
|
address: '0x5e74C9036fb86BD7eCdcb084a0673EFc32eA31cb',
|
|
280
280
|
decimals: 18,
|
|
@@ -796,10 +796,6 @@ export const Tokens: {
|
|
|
796
796
|
address: '0x4200000000000000000000000000000000000042',
|
|
797
797
|
decimals: 18,
|
|
798
798
|
},
|
|
799
|
-
sBTC: {
|
|
800
|
-
address: '0x298B9B95708152ff6968aafd889c6586e9169f1D',
|
|
801
|
-
decimals: 18,
|
|
802
|
-
},
|
|
803
799
|
sETH: {
|
|
804
800
|
address: '0xE405de8F52ba7559f9df3C368500B6E6ae6Cee49',
|
|
805
801
|
decimals: 18,
|
|
@@ -833,7 +829,8 @@ export const Holders: {
|
|
|
833
829
|
[Network.MAINNET]: {
|
|
834
830
|
ETH: '0x176F3DAb24a159341c0509bB36B833E7fdd0a132',
|
|
835
831
|
USDC: '0x79E2Ba942B0e8fDB6ff3d406e930289d10B49ADe',
|
|
836
|
-
WBTC: '
|
|
832
|
+
WBTC: '0x1cb17a66dc606a52785f69f08f4256526abd4943',
|
|
833
|
+
sBTC: '0xA2e3475D13776C6E42ff37B47286827d959B2195',
|
|
837
834
|
BADGER: '0x34e2741a3f8483dbe5231f61c005110ff4b9f50a',
|
|
838
835
|
STETH: '0x9bdb521a97e95177bf252c253e256a60c3e14447',
|
|
839
836
|
wstETH: '0x6cE0F913F035ec6195bC3cE885aec4C66E485BC4',
|
|
@@ -878,7 +875,6 @@ export const Holders: {
|
|
|
878
875
|
aWETH: '0x3ddfa8ec3052539b6c9549f12cea2c295cff5296',
|
|
879
876
|
aUSDT: '0x4aef720f7bbe98f916221bbc2fb5a15efe6d2cb8',
|
|
880
877
|
BBAUSD: '0x4361b7425cff39b1be9bf12cee2ef32f89656cda',
|
|
881
|
-
sBTC: '0xc8c2b727d864cc75199f5118f0943d2087fb543b',
|
|
882
878
|
sETH: '0x5fe009d78afabc1b04abd2d4361f8e95cd402648',
|
|
883
879
|
sUSD: '0xcfb87039a1eda5428e2c8386d31ccf121835ecdb',
|
|
884
880
|
USDD: '0xf89d7b9c864f589bbf53a82105107622b35eaa40',
|