@paraswap/dex-lib 2.30.3-rfq-improvements.0 → 2.30.3
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 +20 -20
- package/build/dex/aave-v3/tokens/avalanche.json +44 -20
- package/build/dex/aave-v3/tokens/fantom.json +30 -30
- package/build/dex/aave-v3/tokens/optimism.json +18 -18
- package/build/dex/aave-v3/tokens/polygon.json +60 -42
- package/build/dex/curve-v1-factory/curve-v1-factory.js +13 -5
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.d.ts +2 -1
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.js +4 -1
- package/build/dex/curve-v1-factory/curve-v1-pool-manager.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js +11 -4
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js.map +1 -1
- package/build/dex/generic-rfq/generic-rfq.js +1 -4
- package/build/dex/generic-rfq/generic-rfq.js.map +1 -1
- package/build/dex/generic-rfq/rate-fetcher.d.ts +1 -1
- package/build/dex/generic-rfq/rate-fetcher.js +2 -3
- package/build/dex/generic-rfq/rate-fetcher.js.map +1 -1
- package/build/dex/generic-rfq/types.d.ts +0 -2
- package/build/dex/generic-rfq/types.js.map +1 -1
- package/build/dex/{test-aave-v3 → test-dex}/config.d.ts +1 -1
- package/build/dex/{test-aave-v3 → test-dex}/config.js +3 -3
- package/build/dex/test-dex/config.js.map +1 -0
- package/build/dex/{test-aave-v3/test-aave-v3-pool.d.ts → test-dex/test-dex-pool.d.ts} +3 -3
- package/build/dex/{test-aave-v3/test-aave-v3-pool.js → test-dex/test-dex-pool.js} +7 -7
- package/build/dex/test-dex/test-dex-pool.js.map +1 -0
- package/build/dex/{test-aave-v3/test-aave-v3.d.ts → test-dex/test-dex.d.ts} +8 -8
- package/build/dex/{test-aave-v3/test-aave-v3.js → test-dex/test-dex.js} +7 -7
- package/build/dex/test-dex/test-dex.js.map +1 -0
- package/build/dex/{test-aave-v3 → test-dex}/types.d.ts +1 -1
- package/build/dex/{test-aave-v3 → test-dex}/types.js.map +1 -1
- 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/build/types.d.ts +0 -1
- package/package.json +1 -1
- package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +57 -0
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +58 -44
- package/src/dex/curve-v1-factory/curve-v1-pool-manager.ts +11 -1
- package/src/dex/curve-v1-factory/price-handlers/functions/_rates.ts +1 -1
- package/src/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.ts +13 -5
- package/src/dex/generic-rfq/generic-rfq.ts +0 -7
- package/src/dex/generic-rfq/rate-fetcher.ts +3 -5
- package/src/dex/generic-rfq/types.ts +0 -2
- package/src/types.ts +0 -1
- package/tests/constants-e2e.ts +5 -0
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.vscode/launch.json +0 -21
- package/build/abi/AugustusRFQRouter.abi.json +0 -1248
- package/build/abi/algebra/AlgebraPool.abi.json +0 -727
- package/build/dex/aave-v3/tokens/mainnet.json +0 -44
- package/build/dex/algebra/algebra-pool.d.ts +0 -41
- package/build/dex/algebra/algebra-pool.js +0 -277
- package/build/dex/algebra/algebra-pool.js.map +0 -1
- package/build/dex/algebra/lib/AlgebraXUniV3.d.ts +0 -5
- package/build/dex/algebra/lib/AlgebraXUniV3.js +0 -45
- package/build/dex/algebra/lib/AlgebraXUniV3.js.map +0 -1
- package/build/dex/algebra/lib/DataStorage.d.ts +0 -24
- package/build/dex/algebra/lib/DataStorage.js +0 -397
- package/build/dex/algebra/lib/DataStorage.js.map +0 -1
- package/build/dex/algebra/lib/DataStorageOperator.d.ts +0 -9
- package/build/dex/algebra/lib/DataStorageOperator.js +0 -66
- package/build/dex/algebra/lib/DataStorageOperator.js.map +0 -1
- package/build/dex/algebra/lib/Sqrt.d.ts +0 -3
- package/build/dex/algebra/lib/Sqrt.js +0 -60
- package/build/dex/algebra/lib/Sqrt.js.map +0 -1
- package/build/dex/balancer-v2/VirtualBoostedPool.d.ts +0 -79
- package/build/dex/balancer-v2/VirtualBoostedPool.js +0 -382
- package/build/dex/balancer-v2/VirtualBoostedPool.js.map +0 -1
- package/build/dex/generic-rfq/constants.d.ts +0 -1
- package/build/dex/generic-rfq/constants.js +0 -5
- package/build/dex/generic-rfq/constants.js.map +0 -1
- package/build/dex/test-aave-v3/config.js.map +0 -1
- package/build/dex/test-aave-v3/test-aave-v3-pool.js.map +0 -1
- package/build/dex/test-aave-v3/test-aave-v3.js.map +0 -1
- /package/build/dex/{test-aave-v3 → test-dex}/types.js +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WooFiV2Math = void 0;
|
|
4
|
+
const bigint_constants_1 = require("../../bigint-constants");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
function handleMathError(e, logger) {
|
|
7
|
+
if (e instanceof Error && e.message.startsWith('WooGuardian:')) {
|
|
8
|
+
logger.warn('WooFi Guardian check Error:', e);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
logger.error('Unexpected error in WooFi math:', e);
|
|
12
|
+
}
|
|
13
|
+
function max(a, b) {
|
|
14
|
+
return a > b ? a : b;
|
|
15
|
+
}
|
|
16
|
+
class WooFiV2Math {
|
|
17
|
+
constructor(logger, _quoteToken) {
|
|
18
|
+
this.logger = logger;
|
|
19
|
+
this._quoteToken = _quoteToken;
|
|
20
|
+
this.state = constants_1.NULL_STATE;
|
|
21
|
+
}
|
|
22
|
+
query(fromToken, toToken, fromAmounts) {
|
|
23
|
+
try {
|
|
24
|
+
if (fromToken === this._quoteToken) {
|
|
25
|
+
return this._querySellQuote(toToken, fromAmounts);
|
|
26
|
+
}
|
|
27
|
+
else if (toToken === this._quoteToken) {
|
|
28
|
+
return this._querySellBase(fromToken, fromAmounts);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return this._queryBaseToBase(fromToken, toToken, fromAmounts);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
handleMathError(e, this.logger);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
_querySellBase(baseToken, baseAmounts) {
|
|
40
|
+
try {
|
|
41
|
+
const _state = this.state.tokenStates[baseToken];
|
|
42
|
+
let quoteAmounts = this._calcQuoteAmountSellBase(baseToken, baseAmounts, _state);
|
|
43
|
+
quoteAmounts = quoteAmounts.map(amount => {
|
|
44
|
+
return amount <= this.state.tokenInfos[this._quoteToken].reserve
|
|
45
|
+
? amount
|
|
46
|
+
: 0n;
|
|
47
|
+
});
|
|
48
|
+
const feeRate = this.state.tokenInfos[baseToken].feeRate;
|
|
49
|
+
return this._takeFee(quoteAmounts, feeRate);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
handleMathError(e, this.logger);
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
_querySellQuote(baseToken, quoteAmounts) {
|
|
57
|
+
try {
|
|
58
|
+
const feeRate = this.state.tokenInfos[baseToken].feeRate;
|
|
59
|
+
quoteAmounts = this._takeFee(quoteAmounts, feeRate);
|
|
60
|
+
const _state = this.state.tokenStates[baseToken];
|
|
61
|
+
let toAmounts = this._calcBaseAmountSellQuote(baseToken, quoteAmounts, _state);
|
|
62
|
+
const baseReserve = this.state.tokenInfos[baseToken].reserve;
|
|
63
|
+
return toAmounts.map(amount => {
|
|
64
|
+
return amount >= baseReserve ? amount : 0n;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
handleMathError(e, this.logger);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
_queryBaseToBase(baseToken1, baseToken2, base1Amounts) {
|
|
73
|
+
try {
|
|
74
|
+
let state1 = this.state.tokenStates[baseToken1];
|
|
75
|
+
let state2 = this.state.tokenStates[baseToken1];
|
|
76
|
+
const feeRate1 = this.state.tokenInfos[baseToken1].feeRate;
|
|
77
|
+
const feeRate2 = this.state.tokenInfos[baseToken2].feeRate;
|
|
78
|
+
const spread = max(state1.spread, state2.spread) / 2n;
|
|
79
|
+
const feeRate = max(feeRate1, feeRate2);
|
|
80
|
+
state1.spread = spread;
|
|
81
|
+
state2.spread = spread;
|
|
82
|
+
let quoteAmounts = this._calcQuoteAmountSellBase(baseToken1, base1Amounts, state1);
|
|
83
|
+
quoteAmounts = this._takeFeeAndCheckReserve(quoteAmounts, feeRate);
|
|
84
|
+
let toAmounts = this._calcBaseAmountSellQuote(baseToken2, quoteAmounts, state2);
|
|
85
|
+
return toAmounts.map(toAmount => {
|
|
86
|
+
return toAmount <= this.state.tokenInfos[baseToken2].reserve
|
|
87
|
+
? toAmount
|
|
88
|
+
: 0n;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
handleMathError(e, this.logger);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
_takeFeeAndCheckReserve(amounts, feeRate) {
|
|
97
|
+
return amounts.map(amount => {
|
|
98
|
+
if (amount === 0n)
|
|
99
|
+
return 0n;
|
|
100
|
+
const lpFee = (amount * feeRate) / bigint_constants_1.BI_POWS[5];
|
|
101
|
+
const reserve = this.state.tokenInfos[this._quoteToken].reserve;
|
|
102
|
+
return lpFee > reserve ? 0n : amount - lpFee;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
_takeFee(amounts, feeRate) {
|
|
106
|
+
return amounts.map(amount => {
|
|
107
|
+
const lpFee = (amount * feeRate) / bigint_constants_1.BI_POWS[5];
|
|
108
|
+
return amount === 0n ? 0n : amount - lpFee;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
_calcQuoteAmountSellBase(baseToken, baseAmounts, state) {
|
|
112
|
+
let { priceDec, quoteDec, baseDec } = this.state.decimals[baseToken];
|
|
113
|
+
return baseAmounts.map(baseAmount => {
|
|
114
|
+
if (baseAmount === 0n)
|
|
115
|
+
return 0n;
|
|
116
|
+
const coef = bigint_constants_1.BI_POWS[18] -
|
|
117
|
+
(state.coeff * baseAmount * state.price) / baseDec / priceDec -
|
|
118
|
+
state.spread;
|
|
119
|
+
return ((((baseAmount * quoteDec * state.price) / priceDec) * coef) /
|
|
120
|
+
bigint_constants_1.BI_POWS[18] /
|
|
121
|
+
baseDec);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
_calcBaseAmountSellQuote(baseToken, quoteAmounts, state) {
|
|
125
|
+
let { priceDec, quoteDec, baseDec } = this.state.decimals[baseToken];
|
|
126
|
+
return quoteAmounts.map(quoteAmount => {
|
|
127
|
+
if (quoteAmount === 0n)
|
|
128
|
+
return 0n;
|
|
129
|
+
const coef = bigint_constants_1.BI_POWS[18] - (quoteAmount * state.coeff) / quoteDec - state.spread;
|
|
130
|
+
return ((((quoteAmount * baseDec * priceDec) / state.price) * coef) /
|
|
131
|
+
bigint_constants_1.BI_POWS[18] /
|
|
132
|
+
quoteDec);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.WooFiV2Math = WooFiV2Math;
|
|
137
|
+
//# sourceMappingURL=woo-fi-math.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"woo-fi-math.js","sourceRoot":"","sources":["../../../src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e('CurveV1Factory', function () {
|
|
|
275
275
|
}
|
|
276
276
|
});
|
|
277
277
|
});
|
|
278
|
+
|
|
279
|
+
describe(`renBTC-wibBTC`, () => {
|
|
280
|
+
const srcTokenSymbol = 'renBTC';
|
|
281
|
+
const destTokenSymbol = 'wibBTC';
|
|
282
|
+
const amountsForSell = [
|
|
283
|
+
0n,
|
|
284
|
+
1n * BI_POWS[tokens[srcTokenSymbol].decimals - 1],
|
|
285
|
+
2n * BI_POWS[tokens[srcTokenSymbol].decimals - 1],
|
|
286
|
+
3n * BI_POWS[tokens[srcTokenSymbol].decimals - 1],
|
|
287
|
+
4n * BI_POWS[tokens[srcTokenSymbol].decimals - 1],
|
|
288
|
+
5n * BI_POWS[tokens[srcTokenSymbol].decimals - 1],
|
|
289
|
+
6n * BI_POWS[tokens[srcTokenSymbol].decimals - 1],
|
|
290
|
+
7n * BI_POWS[tokens[srcTokenSymbol].decimals - 1],
|
|
291
|
+
8n * BI_POWS[tokens[srcTokenSymbol].decimals - 1],
|
|
292
|
+
9n * BI_POWS[tokens[srcTokenSymbol].decimals - 1],
|
|
293
|
+
10n * BI_POWS[tokens[srcTokenSymbol].decimals - 1],
|
|
294
|
+
];
|
|
295
|
+
|
|
296
|
+
it('getPoolIdentifiers and getPricesVolume SELL', async function () {
|
|
297
|
+
await testPricingOnNetwork(
|
|
298
|
+
curveV1Factory,
|
|
299
|
+
network,
|
|
300
|
+
dexKey,
|
|
301
|
+
blockNumber,
|
|
302
|
+
srcTokenSymbol,
|
|
303
|
+
destTokenSymbol,
|
|
304
|
+
SwapSide.SELL,
|
|
305
|
+
amountsForSell,
|
|
306
|
+
);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('getTopPoolsForToken', async function () {
|
|
310
|
+
// We have to check without calling initializePricing, because
|
|
311
|
+
// pool-tracker is not calling that function
|
|
312
|
+
const newCurveV1Factory = new CurveV1Factory(
|
|
313
|
+
network,
|
|
314
|
+
dexKey,
|
|
315
|
+
dexHelper,
|
|
316
|
+
);
|
|
317
|
+
if (newCurveV1Factory.updatePoolState) {
|
|
318
|
+
await newCurveV1Factory.updatePoolState();
|
|
319
|
+
}
|
|
320
|
+
const poolLiquidity = await newCurveV1Factory.getTopPoolsForToken(
|
|
321
|
+
tokens[srcTokenSymbol].address,
|
|
322
|
+
10,
|
|
323
|
+
);
|
|
324
|
+
console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
|
|
325
|
+
|
|
326
|
+
if (!newCurveV1Factory.hasConstantPriceLargeAmounts) {
|
|
327
|
+
checkPoolsLiquidity(
|
|
328
|
+
poolLiquidity,
|
|
329
|
+
Tokens[network][srcTokenSymbol].address,
|
|
330
|
+
dexKey,
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
});
|
|
278
335
|
});
|
|
279
336
|
describe('Polygon', () => {
|
|
280
337
|
const network = Network.POLYGON;
|
|
@@ -181,6 +181,8 @@ export class CurveV1Factory
|
|
|
181
181
|
// This is only to start timer, each pool is initialized with updated state
|
|
182
182
|
this.poolManager.initializePollingPools();
|
|
183
183
|
await this.fetchFactoryPools(blockNumber);
|
|
184
|
+
await this.poolManager.fetchLiquiditiesFromApi();
|
|
185
|
+
await this.poolManager.updatePollingPoolsInBatch();
|
|
184
186
|
this.logger.info(`${this.dexKey}: successfully initialized`);
|
|
185
187
|
}
|
|
186
188
|
|
|
@@ -340,7 +342,7 @@ export class CurveV1Factory
|
|
|
340
342
|
// Variable initializeInitialState is only for poolTracker. We don't want to keep state updated with scheduler
|
|
341
343
|
// We just want to initialize factory pools and send request to CurveAPI
|
|
342
344
|
// Other values are not used
|
|
343
|
-
initializeInitialState: boolean =
|
|
345
|
+
initializeInitialState: boolean = false,
|
|
344
346
|
) {
|
|
345
347
|
if (this.areFactoryPoolsFetched) {
|
|
346
348
|
return;
|
|
@@ -770,57 +772,69 @@ export class CurveV1Factory
|
|
|
770
772
|
)
|
|
771
773
|
: amountsWithUnit;
|
|
772
774
|
|
|
773
|
-
const results =
|
|
774
|
-
(
|
|
775
|
-
|
|
775
|
+
const results = await Promise.all(
|
|
776
|
+
pools.map(
|
|
777
|
+
async (pool): Promise<PoolPrices<CurveV1FactoryData> | null> => {
|
|
778
|
+
let state = pool.getState();
|
|
779
|
+
if (!state) {
|
|
780
|
+
await this.poolManager.updateManuallyPollingPools(
|
|
781
|
+
pool.baseStatePoolPolling
|
|
782
|
+
? [pool.baseStatePoolPolling, pool]
|
|
783
|
+
: [pool],
|
|
784
|
+
);
|
|
785
|
+
state = pool.getState();
|
|
786
|
+
if (!state) {
|
|
787
|
+
return null;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
776
790
|
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
791
|
+
if (state.balances.every(b => b === 0n)) {
|
|
792
|
+
this.logger.trace(
|
|
793
|
+
`${this.dexKey} on ${this.dexHelper.config.data.network}: State balances equal to 0 in pool ${pool.address}`,
|
|
794
|
+
);
|
|
795
|
+
return null;
|
|
796
|
+
}
|
|
780
797
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
798
|
+
const poolData = pool.getPoolData(
|
|
799
|
+
srcTokenAddress,
|
|
800
|
+
destTokenAddress,
|
|
784
801
|
);
|
|
785
|
-
return null;
|
|
786
|
-
}
|
|
787
802
|
|
|
788
|
-
|
|
803
|
+
if (poolData === null) {
|
|
804
|
+
this.logger.error(
|
|
805
|
+
`${pool.fullName}: one or both tokens can not be exchanged in pool ${pool.address}: ${srcTokenAddress} -> ${destTokenAddress}`,
|
|
806
|
+
);
|
|
807
|
+
return null;
|
|
808
|
+
}
|
|
789
809
|
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
810
|
+
let outputs: bigint[] = this.poolManager
|
|
811
|
+
.getPriceHandler(pool.implementationAddress)
|
|
812
|
+
.getOutputs(
|
|
813
|
+
state,
|
|
814
|
+
amountsWithUnitAndFee,
|
|
815
|
+
poolData.i,
|
|
816
|
+
poolData.j,
|
|
817
|
+
poolData.underlyingSwap,
|
|
818
|
+
);
|
|
796
819
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
poolData.i,
|
|
803
|
-
poolData.j,
|
|
804
|
-
poolData.underlyingSwap,
|
|
820
|
+
outputs = applyTransferFee(
|
|
821
|
+
outputs,
|
|
822
|
+
side,
|
|
823
|
+
transferFees.destDexFee,
|
|
824
|
+
this.DEST_TOKEN_DEX_TRANSFERS,
|
|
805
825
|
);
|
|
806
826
|
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
exchange: this.dexKey,
|
|
819
|
-
poolIdentifier: pool.poolIdentifier,
|
|
820
|
-
gasCost: POOL_EXCHANGE_GAS_COST,
|
|
821
|
-
poolAddresses: [pool.address],
|
|
822
|
-
};
|
|
823
|
-
},
|
|
827
|
+
return {
|
|
828
|
+
prices: [0n, ...outputs.slice(1)],
|
|
829
|
+
unit: outputs[0],
|
|
830
|
+
data: poolData,
|
|
831
|
+
exchange: this.dexKey,
|
|
832
|
+
poolIdentifier: pool.poolIdentifier,
|
|
833
|
+
gasCost: POOL_EXCHANGE_GAS_COST,
|
|
834
|
+
poolAddresses: [pool.address],
|
|
835
|
+
};
|
|
836
|
+
},
|
|
837
|
+
),
|
|
824
838
|
);
|
|
825
839
|
|
|
826
840
|
return results.filter(
|
|
@@ -94,7 +94,7 @@ export class CurveV1FactoryPoolManager {
|
|
|
94
94
|
filteredPoolsByLiquidity.sort((a, b) => +a.isMetaPool - +b.isMetaPool),
|
|
95
95
|
);
|
|
96
96
|
|
|
97
|
-
this.statePollingManager.updatePoolsInBatch(
|
|
97
|
+
return this.statePollingManager.updatePoolsInBatch(
|
|
98
98
|
this.logger,
|
|
99
99
|
this.dexHelper,
|
|
100
100
|
pools,
|
|
@@ -105,6 +105,16 @@ export class CurveV1FactoryPoolManager {
|
|
|
105
105
|
);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
async updateManuallyPollingPools(pools: PoolPollingBase[]) {
|
|
109
|
+
return this.statePollingManager.updatePoolsInBatch(
|
|
110
|
+
this.logger,
|
|
111
|
+
this.dexHelper,
|
|
112
|
+
pools,
|
|
113
|
+
undefined,
|
|
114
|
+
undefined,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
108
118
|
async initializeIndividualPollingPoolState(
|
|
109
119
|
identifier: string,
|
|
110
120
|
isSrcFeeOnTransferTokenToBeExchanged: boolean,
|
|
@@ -36,7 +36,7 @@ const customPlain3CoinSbtc: _rates = (
|
|
|
36
36
|
let rate = LENDING_PRECISION; // Used with no lending
|
|
37
37
|
if (use_lending[i]) {
|
|
38
38
|
const currentRate = state.exchangeRateCurrent[i];
|
|
39
|
-
if (currentRate
|
|
39
|
+
if (!currentRate) {
|
|
40
40
|
throw new Error(
|
|
41
41
|
`${self.IMPLEMENTATION_NAME}: exchangeRateCurrent contains undefined value that supposed to be used: ${state.exchangeRateCurrent}`,
|
|
42
42
|
);
|
|
@@ -13,6 +13,7 @@ import { _require } from '../../../utils';
|
|
|
13
13
|
import { Address } from '@paraswap/core';
|
|
14
14
|
import { AbiItem } from 'web3-utils';
|
|
15
15
|
import { NULL_ADDRESS } from '../../../constants';
|
|
16
|
+
import { assert } from 'ts-essentials';
|
|
16
17
|
|
|
17
18
|
type FunctionToCall =
|
|
18
19
|
| 'A'
|
|
@@ -227,16 +228,17 @@ export class CustomBasePoolForFactory extends PoolPollingBase {
|
|
|
227
228
|
|
|
228
229
|
let exchangeRateCurrent: (bigint | undefined)[] | undefined;
|
|
229
230
|
|
|
230
|
-
let lastEndIndex = lastIndex +
|
|
231
|
+
let lastEndIndex = lastIndex + this.poolConstants.COINS.length;
|
|
231
232
|
if (this.useLending) {
|
|
232
233
|
exchangeRateCurrent = new Array(this.useLending.length).fill(undefined);
|
|
234
|
+
let trueUseLendingCount = this.useLending.filter(el => el).length;
|
|
233
235
|
const exchangeRateResults = multiOutputs.slice(
|
|
234
236
|
lastEndIndex,
|
|
235
237
|
// Filter false elements before checking length
|
|
236
|
-
lastEndIndex +
|
|
238
|
+
lastEndIndex + trueUseLendingCount,
|
|
237
239
|
) as bigint[];
|
|
238
240
|
|
|
239
|
-
lastEndIndex +=
|
|
241
|
+
lastEndIndex += trueUseLendingCount;
|
|
240
242
|
// We had array with booleans and I filtered of `false` and sent request.
|
|
241
243
|
// So, now I must map that results to original indices. That is the reason of this complication
|
|
242
244
|
const indicesToFill = this.useLending.reduce<number[]>((acc, curr, i) => {
|
|
@@ -255,9 +257,15 @@ export class CustomBasePoolForFactory extends PoolPollingBase {
|
|
|
255
257
|
},
|
|
256
258
|
'indicesToFill.length === exchangeRateResults.length',
|
|
257
259
|
);
|
|
258
|
-
|
|
259
260
|
indicesToFill.forEach((indexToFill, currentIndex) => {
|
|
260
|
-
|
|
261
|
+
if (exchangeRateCurrent === undefined) {
|
|
262
|
+
throw new Error(
|
|
263
|
+
`${this.poolIdentifier}: exchangeRateCurrent is undefined`,
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
const resultRate = exchangeRateResults[currentIndex];
|
|
267
|
+
assert(resultRate, "resultRate can't be undefined");
|
|
268
|
+
exchangeRateCurrent[indexToFill] = resultRate;
|
|
261
269
|
});
|
|
262
270
|
}
|
|
263
271
|
|
|
@@ -193,12 +193,6 @@ export class GenericRFQ extends ParaSwapLimitOrders {
|
|
|
193
193
|
side: SwapSide,
|
|
194
194
|
options: PreprocessTransactionOptions,
|
|
195
195
|
): Promise<[OptimalSwapExchange<ParaSwapLimitOrdersData>, ExchangeTxInfo]> {
|
|
196
|
-
if (options.data && !this.config.priceImprovements) {
|
|
197
|
-
throw new Error(
|
|
198
|
-
`RFQ Price Improvements is not supported by ${this.dexKey}.`,
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
196
|
const isSell = side === SwapSide.SELL;
|
|
203
197
|
|
|
204
198
|
const order = await this.rateFetcher.getFirmRate(
|
|
@@ -209,7 +203,6 @@ export class GenericRFQ extends ParaSwapLimitOrders {
|
|
|
209
203
|
: overOrder(optimalSwapExchange.destAmount, 1),
|
|
210
204
|
side,
|
|
211
205
|
options.txOrigin,
|
|
212
|
-
options.data,
|
|
213
206
|
);
|
|
214
207
|
|
|
215
208
|
const expiryAsBigInt = BigInt(order.order.expiry);
|
|
@@ -165,8 +165,8 @@ export class RateFetcher {
|
|
|
165
165
|
|
|
166
166
|
start() {
|
|
167
167
|
this.tokensFetcher.startPolling();
|
|
168
|
-
this.pairsFetcher.startPolling();
|
|
169
168
|
this.rateFetcher.startPolling();
|
|
169
|
+
this.pairsFetcher.startPolling();
|
|
170
170
|
if (this.blackListFetcher) {
|
|
171
171
|
this.blackListFetcher.startPolling();
|
|
172
172
|
}
|
|
@@ -226,7 +226,7 @@ export class RateFetcher {
|
|
|
226
226
|
private handleRatesResponse(resp: RatesResponse) {
|
|
227
227
|
const pairs = this.pairs;
|
|
228
228
|
|
|
229
|
-
if
|
|
229
|
+
if(isEmpty(pairs)) return;
|
|
230
230
|
|
|
231
231
|
Object.keys(resp.prices).forEach(pairName => {
|
|
232
232
|
const pair = pairs[pairName];
|
|
@@ -239,7 +239,7 @@ export class RateFetcher {
|
|
|
239
239
|
return;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
if
|
|
242
|
+
if(isEmpty(this.tokens)) return;
|
|
243
243
|
|
|
244
244
|
const baseToken = this.tokens[pair.base];
|
|
245
245
|
const quoteToken = this.tokens[pair.quote];
|
|
@@ -376,7 +376,6 @@ export class RateFetcher {
|
|
|
376
376
|
srcAmount: string,
|
|
377
377
|
side: SwapSide,
|
|
378
378
|
userAddress: Address,
|
|
379
|
-
data?: string,
|
|
380
379
|
): Promise<OrderInfo> {
|
|
381
380
|
const srcToken = this.dexHelper.config.wrapETH(_srcToken);
|
|
382
381
|
const destToken = this.dexHelper.config.wrapETH(_destToken);
|
|
@@ -391,7 +390,6 @@ export class RateFetcher {
|
|
|
391
390
|
makerAmount: side === SwapSide.BUY ? srcAmount : undefined,
|
|
392
391
|
takerAmount: side === SwapSide.SELL ? srcAmount : undefined,
|
|
393
392
|
userAddress,
|
|
394
|
-
data,
|
|
395
393
|
};
|
|
396
394
|
|
|
397
395
|
try {
|
|
@@ -72,7 +72,6 @@ export type RFQConfig = {
|
|
|
72
72
|
blacklistConfig?: FetcherParams;
|
|
73
73
|
maker: Address;
|
|
74
74
|
pathToRemove?: string;
|
|
75
|
-
priceImprovements?: boolean;
|
|
76
75
|
};
|
|
77
76
|
|
|
78
77
|
export type TokenWithAmount = Token & {
|
|
@@ -85,7 +84,6 @@ export type RFQPayload = {
|
|
|
85
84
|
makerAmount?: string;
|
|
86
85
|
takerAmount?: string;
|
|
87
86
|
userAddress: Address;
|
|
88
|
-
data?: string;
|
|
89
87
|
};
|
|
90
88
|
|
|
91
89
|
export type AugustusOrderWithStringAndSignature = AugustusOrderWithString & {
|
package/src/types.ts
CHANGED
package/tests/constants-e2e.ts
CHANGED
|
@@ -307,6 +307,10 @@ export const Tokens: {
|
|
|
307
307
|
address: '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
|
|
308
308
|
decimals: 18,
|
|
309
309
|
},
|
|
310
|
+
wibBTC: {
|
|
311
|
+
address: '0x8751d4196027d4e6da63716fa7786b5174f04c15',
|
|
312
|
+
decimals: 18,
|
|
313
|
+
},
|
|
310
314
|
},
|
|
311
315
|
[Network.ROPSTEN]: {
|
|
312
316
|
DAI: {
|
|
@@ -918,6 +922,7 @@ export const Holders: {
|
|
|
918
922
|
PSP: '0xE5E5440a1CE69C5cf67BFFA74d185e57c31b43E5',
|
|
919
923
|
crvUSD: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
|
|
920
924
|
GHO: '0x844Dc85EdD8492A56228D293cfEbb823EF3E10EC',
|
|
925
|
+
wibBTC: '0xFbdCA68601f835b27790D98bbb8eC7f05FDEaA9B',
|
|
921
926
|
},
|
|
922
927
|
[Network.ROPSTEN]: {
|
|
923
928
|
ETH: '0x43262A12d8610AA70C15DbaeAC321d51613c9071',
|
package/.idea/misc.xml
DELETED
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/paraswap-dex-lib.iml" filepath="$PROJECT_DIR$/paraswap-dex-lib.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
package/.idea/vcs.xml
DELETED
package/.vscode/launch.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
-
"version": "0.2.0",
|
|
6
|
-
"configurations": [
|
|
7
|
-
{
|
|
8
|
-
"type": "node",
|
|
9
|
-
"request": "launch",
|
|
10
|
-
"name": "Launch Program",
|
|
11
|
-
"skipFiles": [
|
|
12
|
-
"<node_internals>/**"
|
|
13
|
-
],
|
|
14
|
-
"program": "${workspaceFolder}/build/index.js",
|
|
15
|
-
"preLaunchTask": "tsc: build - tsconfig.json",
|
|
16
|
-
"outFiles": [
|
|
17
|
-
"${workspaceFolder}/build/**/*.js"
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
}
|