@paraswap/dex-lib 2.42.19 → 2.42.20
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/config.js +1 -1
- package/build/dex/algebra/algebra.d.ts +5 -6
- package/build/dex/algebra/algebra.js +36 -89
- package/build/dex/algebra/algebra.js.map +1 -1
- package/build/dex/algebra/config.js +1 -1
- package/build/dex/algebra/types.d.ts +0 -10
- package/build/dex/algebra/types.js +0 -7
- package/build/dex/algebra/types.js.map +1 -1
- package/build/dex/swaap-v2/constants.d.ts +2 -1
- package/build/dex/swaap-v2/constants.js +3 -2
- package/build/dex/swaap-v2/constants.js.map +1 -1
- package/build/dex/swaap-v2/stable-coins.d.ts +5 -0
- package/build/dex/swaap-v2/stable-coins.js +26 -0
- package/build/dex/swaap-v2/stable-coins.js.map +1 -0
- package/build/dex/swaap-v2/swaap-v2.js +4 -1
- package/build/dex/swaap-v2/swaap-v2.js.map +1 -1
- package/build/dex/swaap-v2/utils.d.ts +2 -0
- package/build/dex/swaap-v2/utils.js +11 -1
- package/build/dex/swaap-v2/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +1 -1
- package/src/dex/algebra/algebra-e2e.test.ts +13 -84
- package/src/dex/algebra/algebra.ts +49 -150
- package/src/dex/algebra/config.ts +1 -1
- package/src/dex/algebra/types.ts +0 -12
- package/src/dex/swaap-v2/constants.ts +3 -1
- package/src/dex/swaap-v2/stable-coins.ts +25 -0
- package/src/dex/swaap-v2/swaap-v2.ts +17 -3
- package/src/dex/swaap-v2/utils.ts +18 -1
- package/tests/constants-e2e.ts +1 -6
- package/build/abi/algebra/SwapRouter.json +0 -281
- package/find-diff-tests.sh +0 -75
- package/src/abi/algebra/SwapRouter.json +0 -281
|
@@ -4,34 +4,21 @@ import { AbiItem } from 'web3-utils';
|
|
|
4
4
|
import { pack } from '@ethersproject/solidity';
|
|
5
5
|
import _ from 'lodash';
|
|
6
6
|
import {
|
|
7
|
+
Token,
|
|
8
|
+
Address,
|
|
7
9
|
ExchangePrices,
|
|
8
10
|
PoolPrices,
|
|
9
11
|
AdapterExchangeParam,
|
|
10
12
|
SimpleExchangeParam,
|
|
11
|
-
Logger,
|
|
12
|
-
TransferFeeParams,
|
|
13
|
-
Address,
|
|
14
13
|
PoolLiquidity,
|
|
15
|
-
|
|
14
|
+
Logger,
|
|
16
15
|
} from '../../types';
|
|
17
16
|
import { SwapSide, Network, CACHE_PREFIX } from '../../constants';
|
|
18
17
|
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
19
|
-
import {
|
|
20
|
-
_require,
|
|
21
|
-
getBigIntPow,
|
|
22
|
-
getDexKeysWithNetwork,
|
|
23
|
-
interpolate,
|
|
24
|
-
isDestTokenTransferFeeToBeExchanged,
|
|
25
|
-
isSrcTokenTransferFeeToBeExchanged,
|
|
26
|
-
} from '../../utils';
|
|
18
|
+
import { getBigIntPow, getDexKeysWithNetwork, interpolate } from '../../utils';
|
|
27
19
|
import { IDex } from '../../dex/idex';
|
|
28
20
|
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
29
|
-
import {
|
|
30
|
-
AlgebraData,
|
|
31
|
-
AlgebraFunctions,
|
|
32
|
-
DexParams,
|
|
33
|
-
IAlgebraPoolState,
|
|
34
|
-
} from './types';
|
|
21
|
+
import { AlgebraData, DexParams, IAlgebraPoolState } from './types';
|
|
35
22
|
import {
|
|
36
23
|
SimpleExchange,
|
|
37
24
|
getLocalDeadlineAsFriendlyPlaceholder,
|
|
@@ -39,16 +26,19 @@ import {
|
|
|
39
26
|
import { AlgebraConfig, Adapters } from './config';
|
|
40
27
|
import { Contract } from 'web3-eth-contract';
|
|
41
28
|
import { Interface } from 'ethers/lib/utils';
|
|
42
|
-
import
|
|
29
|
+
import UniswapV3RouterABI from '../../abi/uniswap-v3/UniswapV3Router.abi.json';
|
|
43
30
|
import AlgebraQuoterABI from '../../abi/algebra/AlgebraQuoter.abi.json';
|
|
44
31
|
import UniswapV3MultiABI from '../../abi/uniswap-v3/UniswapMulti.abi.json';
|
|
45
32
|
import AlgebraStateMulticallABI from '../../abi/algebra/AlgebraStateMulticall.abi.json';
|
|
46
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
OutputResult,
|
|
35
|
+
UniswapV3Functions,
|
|
36
|
+
UniswapV3SimpleSwapParams,
|
|
37
|
+
} from '../uniswap-v3/types';
|
|
47
38
|
import { AlgebraMath } from './lib/AlgebraMath';
|
|
48
39
|
import { AlgebraEventPoolV1_1 } from './algebra-pool-v1_1';
|
|
49
40
|
import { AlgebraEventPoolV1_9 } from './algebra-pool-v1_9';
|
|
50
41
|
import { AlgebraFactory, OnPoolCreatedCallback } from './algebra-factory';
|
|
51
|
-
import { applyTransferFee } from '../../lib/token-transfer-fee';
|
|
52
42
|
|
|
53
43
|
type PoolPairsInfo = {
|
|
54
44
|
token0: Address;
|
|
@@ -71,7 +61,7 @@ type IAlgebraEventPool = AlgebraEventPoolV1_1 | AlgebraEventPoolV1_9;
|
|
|
71
61
|
|
|
72
62
|
export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
73
63
|
private readonly factory: AlgebraFactory;
|
|
74
|
-
readonly isFeeOnTransferSupported: boolean =
|
|
64
|
+
readonly isFeeOnTransferSupported: boolean = false;
|
|
75
65
|
protected eventPools: Record<string, IAlgebraEventPool | null> = {};
|
|
76
66
|
|
|
77
67
|
private newlyCreatedPoolKeys: Set<string> = new Set();
|
|
@@ -95,15 +85,12 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
95
85
|
| typeof AlgebraEventPoolV1_1
|
|
96
86
|
| typeof AlgebraEventPoolV1_9;
|
|
97
87
|
|
|
98
|
-
readonly SRC_TOKEN_DEX_TRANSFERS = 1;
|
|
99
|
-
readonly DEST_TOKEN_DEX_TRANSFERS = 1;
|
|
100
|
-
|
|
101
88
|
constructor(
|
|
102
89
|
protected network: Network,
|
|
103
90
|
dexKey: string,
|
|
104
91
|
protected dexHelper: IDexHelper,
|
|
105
92
|
protected adapters = Adapters[network] || {},
|
|
106
|
-
readonly routerIface = new Interface(
|
|
93
|
+
readonly routerIface = new Interface(UniswapV3RouterABI), // same abi as uniswapV3
|
|
107
94
|
readonly quoterIface = new Interface(AlgebraQuoterABI),
|
|
108
95
|
readonly config = AlgebraConfig[dexKey][network],
|
|
109
96
|
) {
|
|
@@ -422,12 +409,6 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
422
409
|
amounts: bigint[],
|
|
423
410
|
side: SwapSide,
|
|
424
411
|
pool: IAlgebraEventPool,
|
|
425
|
-
transferFees: TransferFeeParams = {
|
|
426
|
-
srcFee: 0,
|
|
427
|
-
destFee: 0,
|
|
428
|
-
srcDexFee: 0,
|
|
429
|
-
destDexFee: 0,
|
|
430
|
-
},
|
|
431
412
|
): Promise<ExchangePrices<AlgebraData> | null> {
|
|
432
413
|
if (!this.config.forceRPC) {
|
|
433
414
|
this.logger.warn(
|
|
@@ -435,11 +416,6 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
435
416
|
);
|
|
436
417
|
}
|
|
437
418
|
|
|
438
|
-
const _isSrcTokenTransferFeeToBeExchanged =
|
|
439
|
-
isSrcTokenTransferFeeToBeExchanged(transferFees);
|
|
440
|
-
const _isDestTokenTransferFeeToBeExchanged =
|
|
441
|
-
isDestTokenTransferFeeToBeExchanged(transferFees);
|
|
442
|
-
|
|
443
419
|
const unitVolume = getBigIntPow(
|
|
444
420
|
(side === SwapSide.SELL ? from : to).decimals,
|
|
445
421
|
);
|
|
@@ -454,16 +430,7 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
454
430
|
),
|
|
455
431
|
);
|
|
456
432
|
|
|
457
|
-
const
|
|
458
|
-
? applyTransferFee(
|
|
459
|
-
_amounts,
|
|
460
|
-
side,
|
|
461
|
-
transferFees.srcDexFee,
|
|
462
|
-
this.SRC_TOKEN_DEX_TRANSFERS,
|
|
463
|
-
)
|
|
464
|
-
: _amounts;
|
|
465
|
-
|
|
466
|
-
const calldata = _amountsWithFee.map(_amount => ({
|
|
433
|
+
const calldata = _amounts.map(_amount => ({
|
|
467
434
|
target: this.config.quoter,
|
|
468
435
|
gasLimit: ALGEBRA_QUOTE_GASLIMIT,
|
|
469
436
|
callData:
|
|
@@ -504,22 +471,12 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
504
471
|
: Math.round(totalGasCost / totalSuccessFullSwaps);
|
|
505
472
|
|
|
506
473
|
let i = 0;
|
|
507
|
-
const _rates =
|
|
508
|
-
|
|
509
|
-
const _ratesWithFee = _isDestTokenTransferFeeToBeExchanged
|
|
510
|
-
? applyTransferFee(
|
|
511
|
-
_rates,
|
|
512
|
-
side,
|
|
513
|
-
transferFees.destDexFee,
|
|
514
|
-
this.DEST_TOKEN_DEX_TRANSFERS,
|
|
515
|
-
)
|
|
516
|
-
: _rates;
|
|
517
|
-
|
|
518
|
-
const unit: bigint = _ratesWithFee[0];
|
|
474
|
+
const _rates = _amounts.map(() => decode(i++));
|
|
475
|
+
const unit: bigint = _rates[0];
|
|
519
476
|
|
|
520
477
|
const prices = interpolate(
|
|
521
|
-
|
|
522
|
-
|
|
478
|
+
_amounts.slice(1),
|
|
479
|
+
_rates.slice(1),
|
|
523
480
|
amounts,
|
|
524
481
|
side,
|
|
525
482
|
);
|
|
@@ -529,7 +486,6 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
529
486
|
prices,
|
|
530
487
|
unit,
|
|
531
488
|
data: {
|
|
532
|
-
feeOnTransfer: _isSrcTokenTransferFeeToBeExchanged,
|
|
533
489
|
path: [
|
|
534
490
|
{
|
|
535
491
|
tokenIn: from.address,
|
|
@@ -552,12 +508,6 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
552
508
|
side: SwapSide,
|
|
553
509
|
blockNumber: number,
|
|
554
510
|
limitPools?: string[],
|
|
555
|
-
transferFees: TransferFeeParams = {
|
|
556
|
-
srcFee: 0,
|
|
557
|
-
destFee: 0,
|
|
558
|
-
srcDexFee: 0,
|
|
559
|
-
destDexFee: 0,
|
|
560
|
-
},
|
|
561
511
|
): Promise<null | ExchangePrices<AlgebraData>> {
|
|
562
512
|
try {
|
|
563
513
|
const _srcToken = this.dexHelper.config.wrapETH(srcToken);
|
|
@@ -568,11 +518,6 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
568
518
|
_destToken,
|
|
569
519
|
);
|
|
570
520
|
|
|
571
|
-
const _isSrcTokenTransferFeeToBeExchanged =
|
|
572
|
-
isSrcTokenTransferFeeToBeExchanged(transferFees);
|
|
573
|
-
const _isDestTokenTransferFeeToBeExchanged =
|
|
574
|
-
isDestTokenTransferFeeToBeExchanged(transferFees);
|
|
575
|
-
|
|
576
521
|
if (_srcAddress === _destAddress) return null;
|
|
577
522
|
|
|
578
523
|
if (
|
|
@@ -581,14 +526,8 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
581
526
|
return null;
|
|
582
527
|
|
|
583
528
|
const pool = await this.getPool(_srcAddress, _destAddress, blockNumber);
|
|
584
|
-
if (!pool) return null;
|
|
585
529
|
|
|
586
|
-
if (
|
|
587
|
-
this.logger.error(
|
|
588
|
-
`pool: ${pool.poolAddress} doesn't support buy for tax srcToken ${srcToken.address}`,
|
|
589
|
-
);
|
|
590
|
-
return null;
|
|
591
|
-
}
|
|
530
|
+
if (!pool) return null;
|
|
592
531
|
|
|
593
532
|
if (this.config.forceRPC) {
|
|
594
533
|
const rpcPrice = await this.getPricingFromRpc(
|
|
@@ -597,7 +536,6 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
597
536
|
amounts,
|
|
598
537
|
side,
|
|
599
538
|
pool,
|
|
600
|
-
transferFees,
|
|
601
539
|
);
|
|
602
540
|
|
|
603
541
|
return rpcPrice;
|
|
@@ -632,7 +570,6 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
632
570
|
amounts,
|
|
633
571
|
side,
|
|
634
572
|
pool,
|
|
635
|
-
transferFees,
|
|
636
573
|
);
|
|
637
574
|
|
|
638
575
|
return rpcPrice;
|
|
@@ -664,26 +601,16 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
664
601
|
const balanceDestToken =
|
|
665
602
|
_destAddress === pool.token0 ? state.balance0 : state.balance1;
|
|
666
603
|
|
|
667
|
-
const [unitAmountWithFee, ...amountsWithFee] =
|
|
668
|
-
_isSrcTokenTransferFeeToBeExchanged
|
|
669
|
-
? applyTransferFee(
|
|
670
|
-
[unitAmount, ..._amounts],
|
|
671
|
-
side,
|
|
672
|
-
transferFees.srcDexFee,
|
|
673
|
-
this.SRC_TOKEN_DEX_TRANSFERS,
|
|
674
|
-
)
|
|
675
|
-
: [unitAmount, ..._amounts];
|
|
676
|
-
|
|
677
604
|
const unitResult = this._getOutputs(
|
|
678
605
|
state,
|
|
679
|
-
[
|
|
606
|
+
[unitAmount],
|
|
680
607
|
zeroForOne,
|
|
681
608
|
side,
|
|
682
609
|
balanceDestToken,
|
|
683
610
|
);
|
|
684
611
|
const pricesResult = this._getOutputs(
|
|
685
612
|
state,
|
|
686
|
-
|
|
613
|
+
_amounts,
|
|
687
614
|
zeroForOne,
|
|
688
615
|
side,
|
|
689
616
|
balanceDestToken,
|
|
@@ -694,20 +621,10 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
694
621
|
return null;
|
|
695
622
|
}
|
|
696
623
|
|
|
697
|
-
const [
|
|
698
|
-
_isDestTokenTransferFeeToBeExchanged
|
|
699
|
-
? applyTransferFee(
|
|
700
|
-
[unitResult.outputs[0], ...pricesResult.outputs],
|
|
701
|
-
side,
|
|
702
|
-
transferFees.destDexFee,
|
|
703
|
-
this.DEST_TOKEN_DEX_TRANSFERS,
|
|
704
|
-
)
|
|
705
|
-
: [unitResult.outputs[0], ...pricesResult.outputs];
|
|
706
|
-
|
|
707
|
-
const prices = [0n, ...pricesResultWithFee];
|
|
624
|
+
const prices = [0n, ...pricesResult.outputs];
|
|
708
625
|
const gasCost = [
|
|
709
626
|
0,
|
|
710
|
-
...
|
|
627
|
+
...pricesResult.outputs.map((p, index) => {
|
|
711
628
|
if (p == 0n) {
|
|
712
629
|
return 0;
|
|
713
630
|
} else {
|
|
@@ -722,10 +639,9 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
722
639
|
|
|
723
640
|
return [
|
|
724
641
|
{
|
|
725
|
-
unit:
|
|
642
|
+
unit: unitResult.outputs[0],
|
|
726
643
|
prices,
|
|
727
644
|
data: {
|
|
728
|
-
feeOnTransfer: _isSrcTokenTransferFeeToBeExchanged,
|
|
729
645
|
path: [
|
|
730
646
|
{
|
|
731
647
|
tokenIn: _srcAddress,
|
|
@@ -758,20 +674,19 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
758
674
|
data: AlgebraData,
|
|
759
675
|
side: SwapSide,
|
|
760
676
|
): AdapterExchangeParam {
|
|
761
|
-
|
|
677
|
+
const { path: rawPath } = data;
|
|
678
|
+
const path = this._encodePath(rawPath, side);
|
|
762
679
|
|
|
763
680
|
const payload = this.abiCoder.encodeParameter(
|
|
764
681
|
{
|
|
765
682
|
ParentStruct: {
|
|
766
683
|
path: 'bytes',
|
|
767
684
|
deadline: 'uint256',
|
|
768
|
-
feeOnTransfer: 'bool',
|
|
769
685
|
},
|
|
770
686
|
},
|
|
771
687
|
{
|
|
772
688
|
path,
|
|
773
689
|
deadline: getLocalDeadlineAsFriendlyPlaceholder(), // FIXME: more gas efficient to pass block.timestamp in adapter
|
|
774
|
-
feeOnTransfer: data.feeOnTransfer,
|
|
775
690
|
},
|
|
776
691
|
);
|
|
777
692
|
|
|
@@ -815,46 +730,30 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
|
|
|
815
730
|
data: AlgebraData,
|
|
816
731
|
side: SwapSide,
|
|
817
732
|
): Promise<SimpleExchangeParam> {
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
? {
|
|
841
|
-
recipient: this.augustusAddress,
|
|
842
|
-
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
843
|
-
amountIn: srcAmount,
|
|
844
|
-
amountOutMinimum: destAmount,
|
|
845
|
-
path,
|
|
846
|
-
}
|
|
847
|
-
: {
|
|
848
|
-
recipient: this.augustusAddress,
|
|
849
|
-
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
850
|
-
amountOut: destAmount,
|
|
851
|
-
amountInMaximum: srcAmount,
|
|
852
|
-
path,
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
|
|
733
|
+
const swapFunction =
|
|
734
|
+
side === SwapSide.SELL
|
|
735
|
+
? UniswapV3Functions.exactInput
|
|
736
|
+
: UniswapV3Functions.exactOutput;
|
|
737
|
+
|
|
738
|
+
const path = this._encodePath(data.path, side);
|
|
739
|
+
const swapFunctionParams: UniswapV3SimpleSwapParams =
|
|
740
|
+
side === SwapSide.SELL
|
|
741
|
+
? {
|
|
742
|
+
recipient: this.augustusAddress,
|
|
743
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
744
|
+
amountIn: srcAmount,
|
|
745
|
+
amountOutMinimum: destAmount,
|
|
746
|
+
path,
|
|
747
|
+
}
|
|
748
|
+
: {
|
|
749
|
+
recipient: this.augustusAddress,
|
|
750
|
+
deadline: getLocalDeadlineAsFriendlyPlaceholder(),
|
|
751
|
+
amountOut: destAmount,
|
|
752
|
+
amountInMaximum: srcAmount,
|
|
753
|
+
path,
|
|
754
|
+
};
|
|
856
755
|
const swapData = this.routerIface.encodeFunctionData(swapFunction, [
|
|
857
|
-
|
|
756
|
+
swapFunctionParams,
|
|
858
757
|
]);
|
|
859
758
|
|
|
860
759
|
return this.buildSimpleParamWithoutWETHConversion(
|
|
@@ -98,7 +98,7 @@ export const Adapters: Record<number, AdapterMappings> = {
|
|
|
98
98
|
[SwapSide.BUY]: [{ name: 'PolygonZkEvmBuyAdapter', index: 1 }],
|
|
99
99
|
},
|
|
100
100
|
[Network.ARBITRUM]: {
|
|
101
|
-
[SwapSide.SELL]: [{ name: '
|
|
101
|
+
[SwapSide.SELL]: [{ name: 'ArbitrumAdapter01', index: 3 }],
|
|
102
102
|
[SwapSide.BUY]: [{ name: 'ArbitrumBuyAdapter', index: 2 }],
|
|
103
103
|
},
|
|
104
104
|
[Network.OPTIMISM]: {
|
package/src/dex/algebra/types.ts
CHANGED
|
@@ -58,21 +58,9 @@ export type AlgebraData = {
|
|
|
58
58
|
tokenIn: Address;
|
|
59
59
|
tokenOut: Address;
|
|
60
60
|
}[];
|
|
61
|
-
feeOnTransfer: boolean;
|
|
62
61
|
isApproved?: boolean;
|
|
63
62
|
};
|
|
64
63
|
|
|
65
|
-
export type AlgebraDataWithFee = {
|
|
66
|
-
tokenIn: Address;
|
|
67
|
-
tokenOut: Address;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export enum AlgebraFunctions {
|
|
71
|
-
exactInput = 'exactInput',
|
|
72
|
-
exactOutput = 'exactOutput',
|
|
73
|
-
exactInputWithFeeToken = 'exactInputSingleSupportingFeeOnTransferTokens',
|
|
74
|
-
}
|
|
75
|
-
|
|
76
64
|
export type DexParams = {
|
|
77
65
|
router: Address;
|
|
78
66
|
quoter: Address;
|
|
@@ -30,7 +30,9 @@ export const SWAAP_429_TTL_S = 60 * 60 * 1; // 1 hour
|
|
|
30
30
|
|
|
31
31
|
export const SWAAP_POOL_RESTRICT_TTL_S = 60 * 30; // 30 minutes
|
|
32
32
|
|
|
33
|
-
export const
|
|
33
|
+
export const STABLE_SWAP_GAS_COST_ESTIMATION = 130_000;
|
|
34
|
+
|
|
35
|
+
export const VOLATILE_SWAP_GAS_COST_ESTIMATION = 150_000;
|
|
34
36
|
|
|
35
37
|
export const BATCH_SWAP_SELECTOR = '0x945bcec9';
|
|
36
38
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Network } from '../../constants';
|
|
2
|
+
|
|
3
|
+
// addresses must be consistant with utils.normalizeTokenAddress
|
|
4
|
+
export const STABLE_COINS: {
|
|
5
|
+
[network: number]: { [symbol: string]: boolean };
|
|
6
|
+
} = {
|
|
7
|
+
[Network.MAINNET]: {
|
|
8
|
+
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': true, // USDT
|
|
9
|
+
'0xdac17f958d2ee523a2206206994597c13d831ec7': true, // USDC
|
|
10
|
+
'0x6b175474e89094c44da98b954eedeac495271d0f': true, // DAI
|
|
11
|
+
'0x853d955acef822db058eb8505911ed77f175b99e': true, // FRAX
|
|
12
|
+
},
|
|
13
|
+
[Network.POLYGON]: {
|
|
14
|
+
'0x3c499c542cef5e3811e1192ce70d8cc03d5c3359': true, // USDC
|
|
15
|
+
'0x2791bca1f2de4661ed88a30c99a7a9449aa84174': true, // USDC.e
|
|
16
|
+
'0xc2132d05d31c914a87c6611c10748aeb04b58e8f': true, // USDT
|
|
17
|
+
'0x8f3cf7ad23cd3cadbd9735aff958023239c6a063': true, // DAI
|
|
18
|
+
},
|
|
19
|
+
[Network.ARBITRUM]: {
|
|
20
|
+
'0xaf88d065e77c8cc2239327c5edb3a432268e5831': true, // USDC
|
|
21
|
+
'0xff970a61a04b1ca14834a43f5de4533ebddb5cc8': true, // USDC.e
|
|
22
|
+
'0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9': true, // USDT
|
|
23
|
+
'0xda10009cbd5d07dd0cecc66161fc93d7c9000da1': true, // DAI
|
|
24
|
+
},
|
|
25
|
+
};
|
|
@@ -45,7 +45,8 @@ import {
|
|
|
45
45
|
SWAAP_RFQ_QUOTE_ENDPOINT,
|
|
46
46
|
SWAAP_RFQ_API_PRICES_POLLING_INTERVAL_MS,
|
|
47
47
|
SWAAP_RFQ_PRICES_CACHES_TTL_S,
|
|
48
|
-
|
|
48
|
+
STABLE_SWAP_GAS_COST_ESTIMATION,
|
|
49
|
+
VOLATILE_SWAP_GAS_COST_ESTIMATION,
|
|
49
50
|
BATCH_SWAP_SELECTOR,
|
|
50
51
|
CALLER_SLOT,
|
|
51
52
|
SWAAP_403_TTL_S,
|
|
@@ -62,7 +63,12 @@ import {
|
|
|
62
63
|
SWAAP_BANNED_CODE,
|
|
63
64
|
SWAAP_NOTIFY_ENDPOINT,
|
|
64
65
|
} from './constants';
|
|
65
|
-
import {
|
|
66
|
+
import {
|
|
67
|
+
getPoolIdentifier,
|
|
68
|
+
normalizeTokenAddress,
|
|
69
|
+
getPairName,
|
|
70
|
+
isStablePair,
|
|
71
|
+
} from './utils';
|
|
66
72
|
import { Method } from '../../dex-helper/irequest-wrapper';
|
|
67
73
|
import {
|
|
68
74
|
SlippageCheckError,
|
|
@@ -404,8 +410,16 @@ export class SwaapV2 extends SimpleExchange implements IDex<SwaapV2Data> {
|
|
|
404
410
|
return null;
|
|
405
411
|
}
|
|
406
412
|
|
|
413
|
+
const gasCost = isStablePair(
|
|
414
|
+
this.network,
|
|
415
|
+
normalizedSrcToken.address,
|
|
416
|
+
normalizedDestToken.address,
|
|
417
|
+
)
|
|
418
|
+
? STABLE_SWAP_GAS_COST_ESTIMATION
|
|
419
|
+
: VOLATILE_SWAP_GAS_COST_ESTIMATION;
|
|
420
|
+
|
|
407
421
|
return {
|
|
408
|
-
gasCost:
|
|
422
|
+
gasCost: gasCost,
|
|
409
423
|
exchange: this.dexKey,
|
|
410
424
|
data: {},
|
|
411
425
|
prices,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Address } from '../../types';
|
|
1
|
+
import { Address, Token } from '../../types';
|
|
2
2
|
import { ETHER_ADDRESS, NULL_ADDRESS } from '../../constants';
|
|
3
|
+
import { Network } from '../../constants';
|
|
4
|
+
import { STABLE_COINS } from './stable-coins';
|
|
3
5
|
|
|
4
6
|
export const getIdentifierPrefix = (
|
|
5
7
|
dexKey: string,
|
|
@@ -27,3 +29,18 @@ export const normalizeTokenAddress = (address: string): string => {
|
|
|
27
29
|
? NULL_ADDRESS
|
|
28
30
|
: address.toLowerCase();
|
|
29
31
|
};
|
|
32
|
+
|
|
33
|
+
export const isStablePair = (
|
|
34
|
+
network: Network,
|
|
35
|
+
normalizedSrcTokenAddress: string,
|
|
36
|
+
normalizedDestTokenAddress: string,
|
|
37
|
+
): boolean => {
|
|
38
|
+
const networkStableCoins = STABLE_COINS[network];
|
|
39
|
+
if (networkStableCoins === undefined) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return (
|
|
43
|
+
networkStableCoins[normalizedSrcTokenAddress] === true &&
|
|
44
|
+
networkStableCoins[normalizedDestTokenAddress] === true
|
|
45
|
+
);
|
|
46
|
+
};
|
package/tests/constants-e2e.ts
CHANGED
|
@@ -853,10 +853,6 @@ export const Tokens: {
|
|
|
853
853
|
address: '0x3d9907f9a368ad0a51be60f7da3b97cf940982d8',
|
|
854
854
|
decimals: 18,
|
|
855
855
|
},
|
|
856
|
-
RDPX: {
|
|
857
|
-
address: '0x32eb7902d4134bf98a28b963d26de779af92a212',
|
|
858
|
-
decimals: 18,
|
|
859
|
-
},
|
|
860
856
|
},
|
|
861
857
|
[Network.OPTIMISM]: {
|
|
862
858
|
DAI: {
|
|
@@ -1149,13 +1145,12 @@ export const Holders: {
|
|
|
1149
1145
|
AMPL: '0xfcaA5ea7F8eb0631BcA72C345025C0A5a6D93f0E',
|
|
1150
1146
|
},
|
|
1151
1147
|
[Network.ARBITRUM]: {
|
|
1152
|
-
RDPX: '0x2fa6f21ecfe274f594f470c376f5bdd061e08a37',
|
|
1153
1148
|
ARB: '0xb65edba80a3d81903ecd499c8eb9cf0e19096bd0',
|
|
1154
1149
|
ETH: '0xF977814e90dA44bFA03b6295A0616a897441aceC',
|
|
1155
1150
|
DAI: '0x07d7f291e731a41d3f0ea4f1ae5b6d920ffb3fe0',
|
|
1156
1151
|
WETH: '0xc31e54c7a869b9fcbecc14363cf510d1c41fa443',
|
|
1157
1152
|
USDCe: '0x62383739d68dd0f844103db8dfb05a7eded5bbe6',
|
|
1158
|
-
USDC: '
|
|
1153
|
+
USDC: '0xa843392198862f98d17e3aa1421b08f2c2020cff',
|
|
1159
1154
|
OHM: '0xebce5f29ff5ca9aa330ebdf7ec6b5f474bff271e',
|
|
1160
1155
|
USDT: '0x5ff47d4ab75bcaff6807c81f1367abb53439883c',
|
|
1161
1156
|
POPS: '0x4b78b52e7de4d8b7d367297cb8a87c1875a9d591',
|