@paraswap/dex-lib 2.33.4-balancer-v2-multihop.2 → 2.34.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.
Files changed (156) hide show
  1. package/build/abi/algebra/AlgebraPool.abi.json +727 -0
  2. package/build/config.js +27 -0
  3. package/build/config.js.map +1 -1
  4. package/build/dex/algebra/algebra-pool-v1_1.d.ts +16 -2
  5. package/build/dex/algebra/algebra-pool-v1_1.js +166 -4
  6. package/build/dex/algebra/algebra-pool-v1_1.js.map +1 -1
  7. package/build/dex/algebra/algebra-pool.d.ts +46 -0
  8. package/build/dex/algebra/algebra-pool.js +336 -0
  9. package/build/dex/algebra/algebra-pool.js.map +1 -0
  10. package/build/dex/algebra/algebra.js +9 -7
  11. package/build/dex/algebra/algebra.js.map +1 -1
  12. package/build/dex/algebra/config.js +1 -0
  13. package/build/dex/algebra/config.js.map +1 -1
  14. package/build/dex/algebra/types.d.ts +3 -2
  15. package/build/dex/algebra/utils.d.ts +3 -1
  16. package/build/dex/algebra/utils.js +59 -1
  17. package/build/dex/algebra/utils.js.map +1 -1
  18. package/build/dex/balancer-v2/optimizer.d.ts +0 -1
  19. package/build/dex/balancer-v2/optimizer.js +21 -29
  20. package/build/dex/balancer-v2/optimizer.js.map +1 -1
  21. package/build/dex/solidly/forks-override/velodromeV2.js +4 -1
  22. package/build/dex/solidly/forks-override/velodromeV2.js.map +1 -1
  23. package/build/dex/uniswap-v2/nomiswap-v2.js.map +1 -1
  24. package/build/dex/uniswap-v3/uniswap-v3.js +7 -1
  25. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  26. package/build/lib/decoders.d.ts +3 -0
  27. package/build/lib/decoders.js +9 -1
  28. package/build/lib/decoders.js.map +1 -1
  29. package/build/stateful-event-subscriber.d.ts +1 -0
  30. package/build/stateful-event-subscriber.js +6 -0
  31. package/build/stateful-event-subscriber.js.map +1 -1
  32. package/package.json +1 -1
  33. package/src/abi/algebra/AlgebraFactory-v1_1.abi.json +250 -0
  34. package/src/config.ts +30 -0
  35. package/src/dex/algebra/algebra-integration.test.ts +122 -0
  36. package/src/dex/algebra/algebra-pool-v1_1.ts +259 -8
  37. package/src/dex/algebra/algebra.ts +9 -6
  38. package/src/dex/algebra/config.ts +1 -0
  39. package/src/dex/algebra/types.ts +3 -2
  40. package/src/dex/algebra/utils.ts +83 -2
  41. package/src/dex/balancer-v2/optimizer.ts +23 -38
  42. package/src/dex/solidly/forks-override/velodromeV2.ts +4 -2
  43. package/src/dex/uniswap-v2/nomiswap-v2.ts +2 -1
  44. package/src/dex/uniswap-v2/uniswap-v2-e2e-bsc.test.ts +6 -8
  45. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +52 -47
  46. package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +1 -9
  47. package/src/dex/uniswap-v3/uniswap-v3.ts +7 -1
  48. package/src/lib/decoders.ts +13 -0
  49. package/src/stateful-event-subscriber.ts +8 -0
  50. package/build/abi/api3-proxy.json +0 -46
  51. package/build/abi/api3-server-v1.json +0 -463
  52. package/build/abi/quick-perps/fast-price-events.json +0 -70
  53. package/build/abi/quick-perps/fast-price-feed.json +0 -741
  54. package/build/abi/quick-perps/reader.json +0 -313
  55. package/build/abi/quick-perps/vault-price-feed.json +0 -323
  56. package/build/abi/quick-perps/vault.json +0 -1953
  57. package/build/abi/quickPerps/fast-price-events.json +0 -70
  58. package/build/abi/quickPerps/fast-price-feed.json +0 -748
  59. package/build/abi/quickPerps/reader.json +0 -313
  60. package/build/abi/quickPerps/vault-price-feed.json +0 -477
  61. package/build/abi/quickPerps/vault.json +0 -1953
  62. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
  63. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
  64. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  65. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  66. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  67. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  68. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  69. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  70. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  71. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  72. package/build/dex/balancer-v2/LinearMath.d.ts +0 -19
  73. package/build/dex/balancer-v2/LinearMath.js +0 -179
  74. package/build/dex/balancer-v2/LinearMath.js.map +0 -1
  75. package/build/dex/balancer-v2/LinearPool.d.ts +0 -47
  76. package/build/dex/balancer-v2/LinearPool.js +0 -324
  77. package/build/dex/balancer-v2/LinearPool.js.map +0 -1
  78. package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -47
  79. package/build/dex/balancer-v2/PhantomStablePool.js +0 -294
  80. package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
  81. package/build/dex/balancer-v2/StableMath.d.ts +0 -9
  82. package/build/dex/balancer-v2/StableMath.js +0 -272
  83. package/build/dex/balancer-v2/StableMath.js.map +0 -1
  84. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -75
  85. package/build/dex/balancer-v2/balancer-v2-pool.js +0 -417
  86. package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
  87. package/build/dex/quick-perps/config.d.ts +0 -11
  88. package/build/dex/quick-perps/config.js +0 -27
  89. package/build/dex/quick-perps/config.js.map +0 -1
  90. package/build/dex/quick-perps/fast-price-feed.d.ts +0 -26
  91. package/build/dex/quick-perps/fast-price-feed.js +0 -176
  92. package/build/dex/quick-perps/fast-price-feed.js.map +0 -1
  93. package/build/dex/quick-perps/pool.d.ts +0 -21
  94. package/build/dex/quick-perps/pool.js +0 -210
  95. package/build/dex/quick-perps/pool.js.map +0 -1
  96. package/build/dex/quick-perps/quick-perps.d.ts +0 -52
  97. package/build/dex/quick-perps/quick-perps.js +0 -205
  98. package/build/dex/quick-perps/quick-perps.js.map +0 -1
  99. package/build/dex/quick-perps/types.d.ts +0 -98
  100. package/build/dex/quick-perps/types.js +0 -3
  101. package/build/dex/quick-perps/types.js.map +0 -1
  102. package/build/dex/quick-perps/usdq.d.ts +0 -15
  103. package/build/dex/quick-perps/usdq.js +0 -61
  104. package/build/dex/quick-perps/usdq.js.map +0 -1
  105. package/build/dex/quick-perps/vault-price-feed.d.ts +0 -43
  106. package/build/dex/quick-perps/vault-price-feed.js +0 -194
  107. package/build/dex/quick-perps/vault-price-feed.js.map +0 -1
  108. package/build/dex/quick-perps/vault-utils.d.ts +0 -8
  109. package/build/dex/quick-perps/vault-utils.js +0 -41
  110. package/build/dex/quick-perps/vault-utils.js.map +0 -1
  111. package/build/dex/quick-perps/vault.d.ts +0 -46
  112. package/build/dex/quick-perps/vault.js +0 -166
  113. package/build/dex/quick-perps/vault.js.map +0 -1
  114. package/build/dex/quickswap-v3.d.ts +0 -21
  115. package/build/dex/quickswap-v3.js +0 -40
  116. package/build/dex/quickswap-v3.js.map +0 -1
  117. package/build/dex/test-dex/config.d.ts +0 -4
  118. package/build/dex/test-dex/config.js +0 -15
  119. package/build/dex/test-dex/config.js.map +0 -1
  120. package/build/dex/test-dex/test-dex-pool.d.ts +0 -39
  121. package/build/dex/test-dex/test-dex-pool.js +0 -63
  122. package/build/dex/test-dex/test-dex-pool.js.map +0 -1
  123. package/build/dex/test-dex/test-dex.d.ts +0 -37
  124. package/build/dex/test-dex/test-dex.js +0 -126
  125. package/build/dex/test-dex/test-dex.js.map +0 -1
  126. package/build/dex/test-dex/types.d.ts +0 -6
  127. package/build/dex/test-dex/types.js +0 -3
  128. package/build/dex/test-dex/types.js.map +0 -1
  129. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
  130. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
  131. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
  132. package/build/dex/woo-fi/config.d.ts +0 -4
  133. package/build/dex/woo-fi/config.js +0 -141
  134. package/build/dex/woo-fi/config.js.map +0 -1
  135. package/build/dex/woo-fi/constants.d.ts +0 -5
  136. package/build/dex/woo-fi/constants.js +0 -20
  137. package/build/dex/woo-fi/constants.js.map +0 -1
  138. package/build/dex/woo-fi/types.d.ts +0 -48
  139. package/build/dex/woo-fi/types.js +0 -3
  140. package/build/dex/woo-fi/types.js.map +0 -1
  141. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  142. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  143. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  144. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  145. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  146. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  147. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  148. package/build/dex/woo-fi/woo-fi.js +0 -480
  149. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  150. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +0 -16
  151. package/build/dex/woo-fi-v2/woo-fi-math.js +0 -137
  152. package/build/dex/woo-fi-v2/woo-fi-math.js.map +0 -1
  153. package/build/lib/api3-feed.d.ts +0 -26
  154. package/build/lib/api3-feed.js +0 -82
  155. package/build/lib/api3-feed.js.map +0 -1
  156. package/src/dex/balancer-v2/balancer-v2-optimizer.test.ts +0 -226
@@ -113,7 +113,6 @@ function testForNetwork(
113
113
  }
114
114
 
115
115
  describe('UniswapV3 E2E', () => {
116
-
117
116
  describe('UniswapV3', () => {
118
117
  const dexKey = 'UniswapV3';
119
118
 
@@ -790,32 +789,33 @@ describe('UniswapV3 E2E', () => {
790
789
  ],
791
790
  ]);
792
791
 
793
- const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [
794
- [
795
- {
796
- name: 'USDC',
797
- sellAmount: '100000000000000000000',
798
- buyAmount: '100000000000000000000',
799
- },
800
- {
801
- name: 'USDT',
802
- sellAmount: '100000000000000000000',
803
- buyAmount: '100000000000000000000',
804
- },
805
- ],
792
+ const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
806
793
  [
807
- {
808
- name: 'BNB',
809
- sellAmount: '1000000000000000000',
810
- buyAmount: '10000000000000000000',
811
- },
812
- {
813
- name: 'USDT',
814
- sellAmount: '1000000000000000000000',
815
- buyAmount: '20000000000000000',
816
- },
817
- ],
818
- ];
794
+ [
795
+ {
796
+ name: 'USDC',
797
+ sellAmount: '100000000000000000000',
798
+ buyAmount: '100000000000000000000',
799
+ },
800
+ {
801
+ name: 'USDT',
802
+ sellAmount: '100000000000000000000',
803
+ buyAmount: '100000000000000000000',
804
+ },
805
+ ],
806
+ [
807
+ {
808
+ name: 'BNB',
809
+ sellAmount: '1000000000000000000',
810
+ buyAmount: '10000000000000000000',
811
+ },
812
+ {
813
+ name: 'USDT',
814
+ sellAmount: '1000000000000000000000',
815
+ buyAmount: '20000000000000000',
816
+ },
817
+ ],
818
+ ];
819
819
 
820
820
  sideToContractMethods.forEach((contractMethods, side) =>
821
821
  describe(`${side}`, () => {
@@ -909,28 +909,33 @@ describe('UniswapV3 E2E', () => {
909
909
  ],
910
910
  ]);
911
911
 
912
- const pairs: { name: string; sellAmount: string; buyAmount: string }[][] = [
913
- [
914
- {
915
- name: 'FTM',
916
- sellAmount: '100000000000000000',
917
- buyAmount: '100000000',
918
- },
919
- {
920
- name: 'USDC',
921
- sellAmount: '100000000',
922
- buyAmount: '100000000000000000',
923
- },
924
- ],
912
+ const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
925
913
  [
926
- {
927
- name: 'WFTM',
928
- sellAmount: '100000000000000',
929
- buyAmount: '1000000000000000',
930
- },
931
- { name: 'WETH', sellAmount: '1000000000000000', buyAmount: '100000000000000' },
932
- ],
933
- ];
914
+ [
915
+ {
916
+ name: 'FTM',
917
+ sellAmount: '100000000000000000',
918
+ buyAmount: '100000000',
919
+ },
920
+ {
921
+ name: 'USDC',
922
+ sellAmount: '100000000',
923
+ buyAmount: '100000000000000000',
924
+ },
925
+ ],
926
+ [
927
+ {
928
+ name: 'WFTM',
929
+ sellAmount: '100000000000000',
930
+ buyAmount: '1000000000000000',
931
+ },
932
+ {
933
+ name: 'WETH',
934
+ sellAmount: '1000000000000000',
935
+ buyAmount: '100000000000000',
936
+ },
937
+ ],
938
+ ];
934
939
 
935
940
  sideToContractMethods.forEach((contractMethods, side) =>
936
941
  describe(`${side}`, () => {
@@ -629,15 +629,10 @@ describe('ChronosV3', () => {
629
629
  beforeEach(async () => {
630
630
  blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
631
631
  uniswapV3 = new UniswapV3(network, dexKey, dexHelper);
632
- uniswapV3Mainnet = new UniswapV3(
633
- Network.ARBITRUM,
634
- dexKey,
635
- dexHelper,
636
- );
632
+ uniswapV3Mainnet = new UniswapV3(Network.ARBITRUM, dexKey, dexHelper);
637
633
  });
638
634
 
639
635
  it('getPoolIdentifiers and getPricesVolume SELL', async function () {
640
-
641
636
  const amounts = [0n, BI_POWS[6], 2000000n];
642
637
 
643
638
  const pools = await uniswapV3.getPoolIdentifiers(
@@ -687,7 +682,6 @@ describe('ChronosV3', () => {
687
682
  });
688
683
 
689
684
  it('getPoolIdentifiers and getPricesVolume BUY', async function () {
690
-
691
685
  const amounts = [0n, BI_POWS[6], 2000000n];
692
686
 
693
687
  const pools = await uniswapV3.getPoolIdentifiers(
@@ -964,7 +958,5 @@ describe('SushiSwapV3', () => {
964
958
 
965
959
  expect(falseChecksCounter).toBeLessThan(poolPrices!.length);
966
960
  });
967
-
968
961
  });
969
962
  });
970
-
@@ -91,7 +91,13 @@ export class UniswapV3
91
91
 
92
92
  public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
93
93
  getDexKeysWithNetwork(
94
- _.pick(UniswapV3Config, ['UniswapV3', 'SushiSwapV3', 'QuickSwapV3.1', 'RamsesV2', 'ChronosV3']),
94
+ _.pick(UniswapV3Config, [
95
+ 'UniswapV3',
96
+ 'SushiSwapV3',
97
+ 'QuickSwapV3.1',
98
+ 'RamsesV2',
99
+ 'ChronosV3',
100
+ ]),
95
101
  );
96
102
 
97
103
  logger: Logger;
@@ -1,5 +1,6 @@
1
1
  import { Result } from '@ethersproject/abi';
2
2
  import BigNumber from 'bignumber.js';
3
+ import { BigNumber as EthersBigNumber } from 'ethers';
3
4
  import { BytesLike, defaultAbiCoder } from 'ethers/lib/utils';
4
5
  import _, { parseInt } from 'lodash';
5
6
  import { BN_0 } from '../bignumber-constants';
@@ -50,6 +51,18 @@ export const uint256ToBigInt = (
50
51
  return generalDecoder(result, ['uint256'], 0n, value => value[0].toBigInt());
51
52
  };
52
53
 
54
+ export const uint128ToBigNumber = (
55
+ result: MultiResult<BytesLike> | BytesLike,
56
+ ): EthersBigNumber => {
57
+ return generalDecoder(result, ['uint128'], 0n, value => value[0]);
58
+ };
59
+
60
+ export const int24ToNumber = (
61
+ result: MultiResult<BytesLike> | BytesLike,
62
+ ): number => {
63
+ return generalDecoder(result, ['int24'], 0n, value => value[0]);
64
+ };
65
+
53
66
  export const uint256ArrayDecode = (
54
67
  result: MultiResult<BytesLike> | BytesLike,
55
68
  ): bigint => {
@@ -18,6 +18,7 @@ type StateCache<State> = {
18
18
  export type InitializeStateOptions<State> = {
19
19
  state?: DeepReadonly<State>;
20
20
  initCallback?: (state: DeepReadonly<State>) => void;
21
+ forceRegenerate?: boolean;
21
22
  };
22
23
 
23
24
  export abstract class StatefulEventSubscriber<State>
@@ -89,6 +90,13 @@ export abstract class StatefulEventSubscriber<State>
89
90
  let masterBn: undefined | number = undefined;
90
91
  if (options && options.state) {
91
92
  this.setState(options.state, blockNumber);
93
+ } else if (options && options.forceRegenerate) {
94
+ // ZkEVM forces to always regenerate state when it is old
95
+ this.logger.debug(
96
+ `${this.parentName}: ${this.name}: forced to regenerate state`,
97
+ );
98
+ const state = await this.generateState(blockNumber);
99
+ this.setState(state, blockNumber);
92
100
  } else {
93
101
  if (this.dexHelper.config.isSlave && this.masterPoolNeeded) {
94
102
  let stateAsString = await this.dexHelper.cache.hget(
@@ -1,46 +0,0 @@
1
- [
2
- {
3
- "inputs": [],
4
- "name": "api3ServerV1",
5
- "outputs": [
6
- {
7
- "internalType": "address",
8
- "name": "",
9
- "type": "address"
10
- }
11
- ],
12
- "stateMutability": "view",
13
- "type": "function"
14
- },
15
- {
16
- "inputs": [],
17
- "name": "dataFeedId",
18
- "outputs": [
19
- {
20
- "internalType": "bytes32",
21
- "name": "",
22
- "type": "bytes32"
23
- }
24
- ],
25
- "stateMutability": "view",
26
- "type": "function"
27
- },
28
- {
29
- "inputs": [],
30
- "name": "read",
31
- "outputs": [
32
- {
33
- "internalType": "int224",
34
- "name": "value",
35
- "type": "int224"
36
- },
37
- {
38
- "internalType": "uint32",
39
- "name": "timestamp",
40
- "type": "uint32"
41
- }
42
- ],
43
- "stateMutability": "view",
44
- "type": "function"
45
- }
46
- ]