@paraswap/dex-lib 3.8.22-infusion.3 → 3.8.23-remove-logs

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 (268) hide show
  1. package/.vscode/launch.json +16 -0
  2. package/.vscode/settings.json +3 -0
  3. package/build/abi/Uncompressor.json +250 -0
  4. package/build/abi/integral/factory.json +333 -0
  5. package/build/abi/integral/oracle.json +501 -0
  6. package/build/abi/{inception/inception-ineth-pool.json → integral/pool.json} +522 -543
  7. package/build/abi/integral/relayer.json +1536 -0
  8. package/build/abi/maverick-v2/MaverickV2Router.json +778 -0
  9. package/build/dex/aave-v1/aave-v1.d.ts +1 -2
  10. package/build/dex/aave-v1/aave-v1.js +0 -22
  11. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  12. package/build/dex/bProtocol.d.ts +18 -0
  13. package/build/dex/bProtocol.js +39 -0
  14. package/build/dex/bProtocol.js.map +1 -0
  15. package/build/dex/bancor.d.ts +26 -0
  16. package/build/dex/bancor.js +58 -0
  17. package/build/dex/bancor.js.map +1 -0
  18. package/build/dex/compound.d.ts +18 -0
  19. package/build/dex/compound.js +46 -0
  20. package/build/dex/compound.js.map +1 -0
  21. package/build/dex/curve-v2.d.ts +58 -0
  22. package/build/dex/curve-v2.js +180 -0
  23. package/build/dex/curve-v2.js.map +1 -0
  24. package/build/dex/dodo-v1.d.ts +33 -0
  25. package/build/dex/dodo-v1.js +63 -0
  26. package/build/dex/dodo-v1.js.map +1 -0
  27. package/build/dex/etherfi/etherfi.d.ts +26 -0
  28. package/build/dex/etherfi/etherfi.js +96 -0
  29. package/build/dex/etherfi/etherfi.js.map +1 -0
  30. package/build/dex/generic-rfq/rate-fetcher.js +1 -1
  31. package/build/dex/generic-rfq/rate-fetcher.js.map +1 -1
  32. package/build/dex/index.js +0 -2
  33. package/build/dex/index.js.map +1 -1
  34. package/build/dex/integral/config.d.ts +4 -0
  35. package/build/dex/integral/config.js +20 -0
  36. package/build/dex/integral/config.js.map +1 -0
  37. package/build/dex/integral/context.d.ts +40 -0
  38. package/build/dex/integral/context.js +158 -0
  39. package/build/dex/integral/context.js.map +1 -0
  40. package/build/dex/integral/helpers.d.ts +17 -0
  41. package/build/dex/integral/helpers.js +157 -0
  42. package/build/dex/integral/helpers.js.map +1 -0
  43. package/build/dex/integral/integral-factory.d.ts +24 -0
  44. package/build/dex/integral/integral-factory.js +95 -0
  45. package/build/dex/integral/integral-factory.js.map +1 -0
  46. package/build/dex/integral/integral-pool.d.ts +50 -0
  47. package/build/dex/integral/integral-pool.js +149 -0
  48. package/build/dex/integral/integral-pool.js.map +1 -0
  49. package/build/dex/integral/integral-pricing.d.ts +18 -0
  50. package/build/dex/integral/integral-pricing.js +114 -0
  51. package/build/dex/integral/integral-pricing.js.map +1 -0
  52. package/build/dex/integral/integral-relayer.d.ts +42 -0
  53. package/build/dex/integral/integral-relayer.js +192 -0
  54. package/build/dex/integral/integral-relayer.js.map +1 -0
  55. package/build/dex/integral/integral-token.d.ts +27 -0
  56. package/build/dex/integral/integral-token.js +59 -0
  57. package/build/dex/integral/integral-token.js.map +1 -0
  58. package/build/dex/{inception/inception-native.d.ts → integral/integral.d.ts} +19 -21
  59. package/build/dex/integral/integral.js +376 -0
  60. package/build/dex/integral/integral.js.map +1 -0
  61. package/build/dex/integral/types.d.ts +85 -0
  62. package/build/dex/integral/types.js +9 -0
  63. package/build/dex/integral/types.js.map +1 -0
  64. package/build/dex/integral/utils-e2e.d.ts +9 -0
  65. package/build/dex/integral/utils-e2e.js +131 -0
  66. package/build/dex/integral/utils-e2e.js.map +1 -0
  67. package/build/dex/integral/utils.d.ts +17 -0
  68. package/build/dex/integral/utils.js +94 -0
  69. package/build/dex/integral/utils.js.map +1 -0
  70. package/build/dex/lido.d.ts +19 -0
  71. package/build/dex/lido.js +42 -0
  72. package/build/dex/lido.js.map +1 -0
  73. package/build/dex/lite-psm/lite-psm.js +5 -2
  74. package/build/dex/lite-psm/lite-psm.js.map +1 -1
  75. package/build/dex/maker-psm/maker-psm.js +6 -2
  76. package/build/dex/maker-psm/maker-psm.js.map +1 -1
  77. package/build/dex/maverick-v2/config.js +4 -0
  78. package/build/dex/maverick-v2/config.js.map +1 -1
  79. package/build/dex/maverick-v2/maverick-math/maverick-pool-math.js +4 -0
  80. package/build/dex/maverick-v2/maverick-math/maverick-pool-math.js.map +1 -1
  81. package/build/dex/maverick-v2/maverick-v2-pool.d.ts +1 -1
  82. package/build/dex/maverick-v2/maverick-v2-pool.js +8 -8
  83. package/build/dex/maverick-v2/maverick-v2-pool.js.map +1 -1
  84. package/build/dex/maverick-v2/maverick-v2.d.ts +5 -4
  85. package/build/dex/maverick-v2/maverick-v2.js +73 -63
  86. package/build/dex/maverick-v2/maverick-v2.js.map +1 -1
  87. package/build/dex/maverick-v2/types.d.ts +4 -0
  88. package/build/dex/onebit.d.ts +25 -0
  89. package/build/dex/onebit.js +42 -0
  90. package/build/dex/onebit.js.map +1 -0
  91. package/build/dex/oswap/oswap-pool.js +8 -8
  92. package/build/dex/oswap/oswap-pool.js.map +1 -1
  93. package/build/dex/oswap/oswap.js +8 -8
  94. package/build/dex/oswap/oswap.js.map +1 -1
  95. package/build/dex/oswap/types.d.ts +4 -4
  96. package/build/dex/platypus/platypus.d.ts +1 -2
  97. package/build/dex/platypus/platypus.js +0 -31
  98. package/build/dex/platypus/platypus.js.map +1 -1
  99. package/build/dex/sdai/config.d.ts +11 -0
  100. package/build/dex/sdai/config.js +21 -0
  101. package/build/dex/sdai/config.js.map +1 -0
  102. package/build/dex/sdai/constants.d.ts +2 -0
  103. package/build/dex/sdai/constants.js +6 -0
  104. package/build/dex/sdai/constants.js.map +1 -0
  105. package/build/dex/sdai/scripts/validate-state.d.ts +1 -0
  106. package/build/dex/sdai/scripts/validate-state.js +102 -0
  107. package/build/dex/sdai/scripts/validate-state.js.map +1 -0
  108. package/build/dex/sdai/sdai-pool.d.ts +16 -0
  109. package/build/dex/sdai/sdai-pool.js +85 -0
  110. package/build/dex/sdai/sdai-pool.js.map +1 -0
  111. package/build/dex/sdai/sdai.d.ts +51 -0
  112. package/build/dex/sdai/sdai.js +172 -0
  113. package/build/dex/sdai/sdai.js.map +1 -0
  114. package/build/dex/sdai/types.d.ts +21 -0
  115. package/build/dex/sdai/types.js +11 -0
  116. package/build/dex/sdai/types.js.map +1 -0
  117. package/build/dex/sdai/utils.d.ts +4 -0
  118. package/build/dex/sdai/utils.js +39 -0
  119. package/build/dex/sdai/utils.js.map +1 -0
  120. package/build/dex/smoothy.d.ts +26 -0
  121. package/build/dex/smoothy.js +48 -0
  122. package/build/dex/smoothy.js.map +1 -0
  123. package/build/dex/stable-pool.d.ts +28 -0
  124. package/build/dex/stable-pool.js +62 -0
  125. package/build/dex/stable-pool.js.map +1 -0
  126. package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
  127. package/build/dex/swaap-v1/swaap-v1.js +0 -10
  128. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  129. package/build/dex/trader-joe-v2.1/optimizer.d.ts +2 -0
  130. package/build/dex/trader-joe-v2.1/optimizer.js +44 -0
  131. package/build/dex/trader-joe-v2.1/optimizer.js.map +1 -0
  132. package/build/dex/trader-joe-v2.1.d.ts +43 -0
  133. package/build/dex/trader-joe-v2.1.js +79 -0
  134. package/build/dex/trader-joe-v2.1.js.map +1 -0
  135. package/build/executor/compressor/Compressor.d.ts +23 -0
  136. package/build/executor/compressor/Compressor.js +144 -0
  137. package/build/executor/compressor/Compressor.js.map +1 -0
  138. package/build/executor/compressor/compress.d.ts +17 -0
  139. package/build/executor/compressor/compress.js +187 -0
  140. package/build/executor/compressor/compress.js.map +1 -0
  141. package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +6 -0
  142. package/build/executor/compressor/compress_functions/addressSubstitution.js +29 -0
  143. package/build/executor/compressor/compress_functions/addressSubstitution.js.map +1 -0
  144. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +10 -0
  145. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +40 -0
  146. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +1 -0
  147. package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +11 -0
  148. package/build/executor/compressor/compress_functions/byteSubstitution.js +64 -0
  149. package/build/executor/compressor/compress_functions/byteSubstitution.js.map +1 -0
  150. package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +7 -0
  151. package/build/executor/compressor/compress_functions/ffSubstitution.js +54 -0
  152. package/build/executor/compressor/compress_functions/ffSubstitution.js.map +1 -0
  153. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +8 -0
  154. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +67 -0
  155. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +1 -0
  156. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +8 -0
  157. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +61 -0
  158. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +1 -0
  159. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +6 -0
  160. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +37 -0
  161. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +1 -0
  162. package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +9 -0
  163. package/build/executor/compressor/compress_functions/searchUnusedBytes.js +33 -0
  164. package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +1 -0
  165. package/build/executor/compressor/fetchSaved.d.ts +0 -0
  166. package/build/executor/compressor/fetchSaved.js +17 -0
  167. package/build/executor/compressor/fetchSaved.js.map +1 -0
  168. package/build/executor/compressor/utils/computeCostL2.d.ts +2 -0
  169. package/build/executor/compressor/utils/computeCostL2.js +14 -0
  170. package/build/executor/compressor/utils/computeCostL2.js.map +1 -0
  171. package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +2 -0
  172. package/build/executor/compressor/utils/findLongestDuplicatedString.js +30 -0
  173. package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +1 -0
  174. package/build/executor/compressor/utils/getAllIndexes.d.ts +2 -0
  175. package/build/executor/compressor/utils/getAllIndexes.js +12 -0
  176. package/build/executor/compressor/utils/getAllIndexes.js.map +1 -0
  177. package/build/executor/compressor/utils/getByteForAddress.d.ts +2 -0
  178. package/build/executor/compressor/utils/getByteForAddress.js +14 -0
  179. package/build/executor/compressor/utils/getByteForAddress.js.map +1 -0
  180. package/build/executor/compressor/utils/intTo2Bytes.d.ts +2 -0
  181. package/build/executor/compressor/utils/intTo2Bytes.js +14 -0
  182. package/build/executor/compressor/utils/intTo2Bytes.js.map +1 -0
  183. package/build/executor/compressor/utils/intTo3Bytes.d.ts +2 -0
  184. package/build/executor/compressor/utils/intTo3Bytes.js +18 -0
  185. package/build/executor/compressor/utils/intTo3Bytes.js.map +1 -0
  186. package/build/executor/compressor/utils/intToByte.d.ts +2 -0
  187. package/build/executor/compressor/utils/intToByte.js +10 -0
  188. package/build/executor/compressor/utils/intToByte.js.map +1 -0
  189. package/package.json +1 -1
  190. package/src/abi/maverick-v2/MaverickV2Router.json +778 -0
  191. package/src/dex/generic-rfq/rate-fetcher.ts +6 -5
  192. package/src/dex/index.ts +0 -2
  193. package/src/dex/lite-psm/lite-psm.ts +5 -2
  194. package/src/dex/maker-psm/maker-psm.ts +6 -2
  195. package/src/dex/maverick-v2/config.ts +4 -0
  196. package/src/dex/maverick-v2/maverick-math/maverick-pool-math.ts +5 -0
  197. package/src/dex/maverick-v2/maverick-v2-e2e.test.ts +21 -43
  198. package/src/dex/maverick-v2/maverick-v2-integration.test.ts +100 -96
  199. package/src/dex/maverick-v2/maverick-v2-pool.ts +8 -8
  200. package/src/dex/maverick-v2/maverick-v2.ts +111 -81
  201. package/src/dex/maverick-v2/types.ts +4 -0
  202. package/tests/constants-e2e.ts +10 -1
  203. package/build/abi/inception/inception-ineth.json +0 -609
  204. package/build/abi/inception/inception-ratio-feed.json +0 -93
  205. package/build/abi/inception/inception-vault.json +0 -991
  206. package/build/abi/infusion/InfusionFactory.json +0 -147
  207. package/build/abi/infusion/InfusionPair.json +0 -658
  208. package/build/abi/infusion/InfusionRouter.json +0 -442
  209. package/build/dex/idle-dao/idle-dao-pool.d.ts +0 -56
  210. package/build/dex/idle-dao/idle-dao-pool.js +0 -176
  211. package/build/dex/idle-dao/idle-dao-pool.js.map +0 -1
  212. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +0 -16
  213. package/build/dex/idle-dao/idle-dao-pooling-pool.js +0 -57
  214. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +0 -1
  215. package/build/dex/idle-dao/scripts.d.ts +0 -9
  216. package/build/dex/idle-dao/scripts.js +0 -552
  217. package/build/dex/idle-dao/scripts.js.map +0 -1
  218. package/build/dex/inception/config.d.ts +0 -5
  219. package/build/dex/inception/config.js +0 -112
  220. package/build/dex/inception/config.js.map +0 -1
  221. package/build/dex/inception/inception-event-pool.d.ts +0 -23
  222. package/build/dex/inception/inception-event-pool.js +0 -34
  223. package/build/dex/inception/inception-event-pool.js.map +0 -1
  224. package/build/dex/inception/inception-native.js +0 -131
  225. package/build/dex/inception/inception-native.js.map +0 -1
  226. package/build/dex/inception/inception-pool.d.ts +0 -18
  227. package/build/dex/inception/inception-pool.js +0 -32
  228. package/build/dex/inception/inception-pool.js.map +0 -1
  229. package/build/dex/inception/inception-price-feed.d.ts +0 -19
  230. package/build/dex/inception/inception-price-feed.js +0 -51
  231. package/build/dex/inception/inception-price-feed.js.map +0 -1
  232. package/build/dex/inception/inception.d.ts +0 -44
  233. package/build/dex/inception/inception.js +0 -162
  234. package/build/dex/inception/inception.js.map +0 -1
  235. package/build/dex/inception/tokens.d.ts +0 -9
  236. package/build/dex/inception/tokens.js +0 -28
  237. package/build/dex/inception/tokens.js.map +0 -1
  238. package/build/dex/inception/types.d.ts +0 -22
  239. package/build/dex/inception/types.js +0 -3
  240. package/build/dex/inception/types.js.map +0 -1
  241. package/build/dex/inception/utils.d.ts +0 -7
  242. package/build/dex/inception/utils.js +0 -58
  243. package/build/dex/inception/utils.js.map +0 -1
  244. package/build/dex/infusion/config.d.ts +0 -3
  245. package/build/dex/infusion/config.js +0 -20
  246. package/build/dex/infusion/config.js.map +0 -1
  247. package/build/dex/infusion/infusion-stable-pool.d.ts +0 -4
  248. package/build/dex/infusion/infusion-stable-pool.js +0 -74
  249. package/build/dex/infusion/infusion-stable-pool.js.map +0 -1
  250. package/build/dex/infusion/infusion.d.ts +0 -51
  251. package/build/dex/infusion/infusion.js +0 -458
  252. package/build/dex/infusion/infusion.js.map +0 -1
  253. package/build/dex/infusion/types.d.ts +0 -47
  254. package/build/dex/infusion/types.js +0 -3
  255. package/build/dex/infusion/types.js.map +0 -1
  256. package/build/dex/infusion/utils/isStablePair.d.ts +0 -2
  257. package/build/dex/infusion/utils/isStablePair.js +0 -18
  258. package/build/dex/infusion/utils/isStablePair.js.map +0 -1
  259. package/src/abi/infusion/InfusionFactory.json +0 -147
  260. package/src/abi/infusion/InfusionPair.json +0 -658
  261. package/src/abi/infusion/InfusionRouter.json +0 -442
  262. package/src/dex/infusion/config.ts +0 -21
  263. package/src/dex/infusion/infusion-e2e.test.ts +0 -110
  264. package/src/dex/infusion/infusion-integration.test.ts +0 -232
  265. package/src/dex/infusion/infusion-stable-pool.ts +0 -91
  266. package/src/dex/infusion/infusion.ts +0 -653
  267. package/src/dex/infusion/types.ts +0 -60
  268. package/src/dex/infusion/utils/isStablePair.ts +0 -18
@@ -1,653 +0,0 @@
1
- import { UniswapV2 } from '../uniswap-v2/uniswap-v2';
2
- import {
3
- Network,
4
- NULL_ADDRESS,
5
- SUBGRAPH_TIMEOUT,
6
- DEST_TOKEN_PARASWAP_TRANSFERS,
7
- SRC_TOKEN_PARASWAP_TRANSFERS,
8
- } from '../../constants';
9
- import {
10
- AdapterExchangeParam,
11
- Address,
12
- DexExchangeParam,
13
- ExchangePrices,
14
- PoolLiquidity,
15
- Token,
16
- TransferFeeParams,
17
- } from '../../types';
18
- import { IDexHelper } from '../../dex-helper';
19
- import erc20ABI from '../../abi/erc20.json';
20
- import { getBigIntPow, getDexKeysWithNetwork, isETHAddress } from '../../utils';
21
- import infusionFactoryABI from '../../abi/infusion/InfusionFactory.json';
22
- import infusionPairABI from '../../abi/infusion/InfusionPair.json';
23
- import infusionRouterABI from '../../abi/infusion/InfusionRouter.json';
24
- import _ from 'lodash';
25
- import { NumberAsString, SwapSide } from '@paraswap/core';
26
- import { Interface, AbiCoder } from '@ethersproject/abi';
27
- import { InfusionStablePool } from './infusion-stable-pool';
28
- import { Uniswapv2ConstantProductPool } from '../uniswap-v2/uniswap-v2-constant-product-pool';
29
- import {
30
- PoolState,
31
- InfusionData,
32
- InfusionPair,
33
- InfusionPoolOrderedParams,
34
- InfusionParam,
35
- } from './types';
36
- import { InfusionConfig } from './config';
37
- import { applyTransferFee } from '../../lib/token-transfer-fee';
38
- import { isStablePair } from './utils/isStablePair';
39
-
40
- export enum InfusionRouterFunctions {
41
- sellExactEth = 'swapExactETHForTokens',
42
- sellExactToken = 'swapExactTokensForETH',
43
- swapExactIn = 'swapExactTokensForTokens',
44
- }
45
-
46
- const VelodromeFactoryABI = [
47
- {
48
- inputs: [{ internalType: 'bool', name: '_stable', type: 'bool' }],
49
- name: 'getFee',
50
- outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
51
- stateMutability: 'view',
52
- type: 'function',
53
- },
54
- ];
55
-
56
- const velodromeFactoryIface = new Interface(VelodromeFactoryABI);
57
- const erc20Iface = new Interface(erc20ABI);
58
- const infusionPairIface = new Interface(infusionPairABI);
59
- const defaultAbiCoder = new AbiCoder();
60
-
61
- export class Infusion extends UniswapV2 {
62
- pairs: { [key: string]: InfusionPair } = {};
63
- stableFee?: number;
64
- volatileFee?: number;
65
-
66
- readonly isFeeOnTransferSupported: boolean = true;
67
- readonly SRC_TOKEN_DEX_TRANSFERS = 1;
68
- readonly DEST_TOKEN_DEX_TRANSFERS = 1;
69
-
70
- public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
71
- getDexKeysWithNetwork(_.pick(InfusionConfig, ['Infusion']));
72
-
73
- constructor(
74
- protected network: Network,
75
- dexKey: string,
76
- protected dexHelper: IDexHelper,
77
- isDynamicFees = true,
78
- factoryAddress?: Address,
79
- subgraphURL?: string,
80
- initCode?: string,
81
- feeCode?: number,
82
- poolGasCost?: number,
83
- routerAddress?: Address,
84
- ) {
85
- super(
86
- network,
87
- dexKey,
88
- dexHelper,
89
- isDynamicFees,
90
- factoryAddress !== undefined
91
- ? factoryAddress
92
- : InfusionConfig[dexKey][network].factoryAddress,
93
- subgraphURL === ''
94
- ? undefined
95
- : subgraphURL !== undefined
96
- ? subgraphURL
97
- : InfusionConfig[dexKey][network].subgraphURL,
98
- initCode !== undefined
99
- ? initCode
100
- : InfusionConfig[dexKey][network].initCode,
101
- feeCode !== undefined ? feeCode : InfusionConfig[dexKey][network].feeCode,
102
- poolGasCost !== undefined
103
- ? poolGasCost
104
- : InfusionConfig[dexKey][network].poolGasCost,
105
- infusionPairIface,
106
- );
107
-
108
- this.stableFee = InfusionConfig[dexKey][network].stableFee;
109
- this.volatileFee = InfusionConfig[dexKey][network].volatileFee;
110
-
111
- this.factory = new dexHelper.web3Provider.eth.Contract(
112
- infusionFactoryABI as any,
113
- factoryAddress !== undefined
114
- ? factoryAddress
115
- : InfusionConfig[dexKey][network].factoryAddress,
116
- );
117
-
118
- this.router =
119
- routerAddress !== undefined
120
- ? routerAddress
121
- : InfusionConfig[dexKey][network].router || '';
122
-
123
- this.feeFactor =
124
- InfusionConfig[dexKey][network].feeFactor || this.feeFactor;
125
- }
126
-
127
- async findInfusionPair(from: Token, to: Token, stable: boolean) {
128
- if (from.address.toLowerCase() === to.address.toLowerCase()) return null;
129
- const [token0, token1] =
130
- from.address.toLowerCase() < to.address.toLowerCase()
131
- ? [from, to]
132
- : [to, from];
133
-
134
- const typePostfix = this.poolPostfix(stable);
135
- const key = `${token0.address.toLowerCase()}-${token1.address.toLowerCase()}-${typePostfix}`;
136
- let pair = this.pairs[key];
137
- if (pair) return pair;
138
-
139
- let exchange = await this.factory.methods
140
- // Infusion has additional boolean parameter "StablePool"
141
- // At first we look for uniswap-like volatile pool
142
- .getPair(token0.address, token1.address, stable)
143
- .call();
144
-
145
- if (exchange === NULL_ADDRESS) {
146
- pair = { token0, token1, stable };
147
- } else {
148
- pair = { token0, token1, exchange, stable };
149
- }
150
- this.pairs[key] = pair;
151
- return pair;
152
- }
153
-
154
- async batchCatchUpPairs(pairs: [Token, Token][], blockNumber: number) {
155
- if (!blockNumber) return;
156
- const pairsToFetch: InfusionPair[] = [];
157
- for (const _pair of pairs) {
158
- const pairs = await Promise.all([
159
- this.findInfusionPair(_pair[0], _pair[1], true),
160
- this.findInfusionPair(_pair[0], _pair[1], false),
161
- ]);
162
- for (const pair of pairs) {
163
- if (!(pair && pair.exchange)) continue;
164
- if (!pair.pool) {
165
- pairsToFetch.push(pair);
166
- } else if (!pair.pool.getState(blockNumber)) {
167
- pairsToFetch.push(pair);
168
- }
169
- }
170
- }
171
-
172
- if (!pairsToFetch.length) return;
173
-
174
- const reserves = await this.getManyPoolReserves(pairsToFetch, blockNumber);
175
-
176
- if (reserves.length !== pairsToFetch.length) {
177
- this.logger.error(
178
- `Error_getManyPoolReserves didn't get any pool reserves`,
179
- );
180
- }
181
-
182
- for (let i = 0; i < pairsToFetch.length; i++) {
183
- const pairState = reserves[i];
184
- const pair = pairsToFetch[i];
185
- if (!pair.pool) {
186
- await this.addPool(
187
- pair,
188
- pairState.reserves0,
189
- pairState.reserves1,
190
- pairState.feeCode,
191
- blockNumber,
192
- );
193
- } else pair.pool.setState(pairState, blockNumber);
194
- }
195
- }
196
-
197
- async getManyPoolReserves(
198
- pairs: InfusionPair[],
199
- blockNumber: number,
200
- ): Promise<PoolState[]> {
201
- try {
202
- const multiCallFeeData = pairs.map(pair =>
203
- this.getFeesMultiCallData(pair),
204
- );
205
- const calldata = pairs
206
- .map((pair, i) => {
207
- let calldata = [
208
- {
209
- target: pair.token0.address,
210
- callData: erc20Iface.encodeFunctionData('balanceOf', [
211
- pair.exchange!,
212
- ]),
213
- },
214
- {
215
- target: pair.token1.address,
216
- callData: erc20Iface.encodeFunctionData('balanceOf', [
217
- pair.exchange!,
218
- ]),
219
- },
220
- ];
221
- if (this.isDynamicFees) calldata.push(multiCallFeeData[i]!.callEntry);
222
- return calldata;
223
- })
224
- .flat();
225
-
226
- const data: { returnData: any[] } =
227
- await this.dexHelper.multiContract.methods
228
- .aggregate(calldata)
229
- .call({}, blockNumber);
230
-
231
- const returnData = _.chunk(data.returnData, this.isDynamicFees ? 3 : 2);
232
-
233
- return pairs.map((pair, i) => ({
234
- reserves0: defaultAbiCoder
235
- .decode(['uint256'], returnData[i][0])[0]
236
- .toString(),
237
- reserves1: defaultAbiCoder
238
- .decode(['uint256'], returnData[i][1])[0]
239
- .toString(),
240
- feeCode: this.isDynamicFees
241
- ? multiCallFeeData[i]!.callDecoder(returnData[i][2])
242
- : (pair.stable ? this.stableFee : this.volatileFee) || this.feeCode,
243
- }));
244
- } catch (e) {
245
- this.logger.error(
246
- `Error_getManyPoolReserves could not get reserves with error:`,
247
- e,
248
- );
249
- return [];
250
- }
251
- }
252
-
253
- async getSellPrice(
254
- priceParams: InfusionPoolOrderedParams,
255
- srcAmount: bigint,
256
- ): Promise<bigint> {
257
- return priceParams.stable
258
- ? InfusionStablePool.getSellPrice(priceParams, srcAmount, this.feeFactor)
259
- : Uniswapv2ConstantProductPool.getSellPrice(
260
- priceParams,
261
- srcAmount,
262
- this.feeFactor,
263
- );
264
- }
265
-
266
- async getPricesVolume(
267
- _from: Token,
268
- _to: Token,
269
- amounts: bigint[],
270
- side: SwapSide,
271
- blockNumber: number,
272
- // list of pool identifiers to use for pricing, if undefined use all pools
273
- limitPools?: string[],
274
- transferFees: TransferFeeParams = {
275
- srcFee: 0,
276
- destFee: 0,
277
- srcDexFee: 0,
278
- destDexFee: 0,
279
- },
280
- ): Promise<ExchangePrices<InfusionData> | null> {
281
- try {
282
- if (side === SwapSide.BUY) return null; // Buy side not implemented yet
283
- const from = this.dexHelper.config.wrapETH(_from);
284
- const to = this.dexHelper.config.wrapETH(_to);
285
-
286
- if (from.address.toLowerCase() === to.address.toLowerCase()) {
287
- return null;
288
- }
289
-
290
- const tokenAddress = [
291
- from.address.toLowerCase(),
292
- to.address.toLowerCase(),
293
- ]
294
- .sort((a, b) => (a > b ? 1 : -1))
295
- .join('_');
296
-
297
- await this.batchCatchUpPairs([[from, to]], blockNumber);
298
-
299
- const resultPromises = [false, true].map(async stable => {
300
- // We don't support fee on transfer for stable pools yet
301
- if (
302
- stable &&
303
- (transferFees.srcFee !== 0 || transferFees.srcDexFee !== 0)
304
- ) {
305
- return null;
306
- }
307
-
308
- const poolIdentifier =
309
- `${this.dexKey}_${tokenAddress}` + this.poolPostfix(stable);
310
-
311
- if (limitPools && limitPools.every(p => p !== poolIdentifier))
312
- return null;
313
-
314
- const isSell = side === SwapSide.SELL;
315
- const pairParam = await this.getInfusionPairOrderedParams(
316
- from,
317
- to,
318
- blockNumber,
319
- stable,
320
- transferFees.srcDexFee,
321
- );
322
-
323
- if (!pairParam) return null;
324
-
325
- const unitAmount = getBigIntPow(from.decimals);
326
-
327
- const [unitVolumeWithFee, ...amountsWithFee] = applyTransferFee(
328
- [unitAmount, ...amounts],
329
- side,
330
- isSell ? transferFees.srcFee : transferFees.destFee,
331
- isSell ? SRC_TOKEN_PARASWAP_TRANSFERS : DEST_TOKEN_PARASWAP_TRANSFERS,
332
- );
333
-
334
- const unit = await this.getSellPricePath(unitVolumeWithFee, [
335
- pairParam,
336
- ]);
337
-
338
- const prices = await Promise.all(
339
- amountsWithFee.map(amount =>
340
- amount === 0n ? 0n : this.getSellPricePath(amount, [pairParam]),
341
- ),
342
- );
343
-
344
- const [unitOutWithFee, ...outputsWithFee] = applyTransferFee(
345
- [unit, ...prices],
346
- side,
347
- // This part is confusing, because we treat differently SELL and BUY fees
348
- // If Buy, we should apply transfer fee on srcToken on top of dexFee applied earlier
349
- // But for Sell we should apply only one dexFee
350
- isSell ? transferFees.destDexFee : transferFees.srcFee,
351
- isSell ? this.DEST_TOKEN_DEX_TRANSFERS : SRC_TOKEN_PARASWAP_TRANSFERS,
352
- );
353
-
354
- return {
355
- prices: outputsWithFee,
356
- unit: unitOutWithFee,
357
- data: {
358
- router: this.router,
359
- path: [from.address.toLowerCase(), to.address.toLowerCase()],
360
- factory: this.factoryAddress,
361
- initCode: this.initCode,
362
- feeFactor: this.feeFactor,
363
- isFeeTokenInRoute: Object.values(transferFees).some(f => f !== 0),
364
- pools: [
365
- {
366
- address: pairParam.exchange,
367
- fee: parseInt(pairParam.fee),
368
- direction: pairParam.direction,
369
- },
370
- ],
371
- isStable: stable,
372
- },
373
- exchange: this.dexKey,
374
- poolIdentifier,
375
- gasCost: this.poolGasCost,
376
- poolAddresses: [pairParam.exchange],
377
- };
378
- });
379
-
380
- const resultPools = (await Promise.all(
381
- resultPromises,
382
- )) as ExchangePrices<InfusionData>;
383
- const resultPoolsFiltered = resultPools.filter(item => !!item); // filter null elements
384
- return resultPoolsFiltered.length > 0 ? resultPoolsFiltered : null;
385
- } catch (e) {
386
- if (blockNumber === 0)
387
- this.logger.error(
388
- `Error_getPricesVolume: Aurelius block manager not yet instantiated`,
389
- );
390
- this.logger.error(`Error_getPrices:`, e);
391
- return null;
392
- }
393
- }
394
-
395
- async getTopPoolsForToken(
396
- tokenAddress: Address,
397
- count: number,
398
- ): Promise<PoolLiquidity[]> {
399
- if (!this.subgraphURL) return [];
400
-
401
- let stableFieldKey = 'isStable';
402
-
403
- const query = `query ($token: Bytes!, $count: Int) {
404
- pools0: pairs(first: $count, orderBy: reserveUSD, orderDirection: desc, where: {token0: $token, reserve0_gt: 1, reserve1_gt: 1}) {
405
- id
406
- ${stableFieldKey}
407
- token0 {
408
- id
409
- decimals
410
- }
411
- token1 {
412
- id
413
- decimals
414
- }
415
- reserveUSD
416
- }
417
- pools1: pairs(first: $count, orderBy: reserveUSD, orderDirection: desc, where: {token1: $token, reserve0_gt: 1, reserve1_gt: 1}) {
418
- id
419
- ${stableFieldKey}
420
- token0 {
421
- id
422
- decimals
423
- }
424
- token1 {
425
- id
426
- decimals
427
- }
428
- reserveUSD
429
- }
430
- }`;
431
-
432
- const { data } = await this.dexHelper.httpRequest.post(
433
- this.subgraphURL,
434
- {
435
- query,
436
- variables: { token: tokenAddress.toLowerCase(), count },
437
- },
438
- SUBGRAPH_TIMEOUT,
439
- );
440
-
441
- if (!(data && data.pools0 && data.pools1))
442
- throw new Error("Couldn't fetch the pools from the subgraph");
443
- const pools0 = _.map(data.pools0, pool => ({
444
- exchange: this.dexKey,
445
- stable: pool[stableFieldKey],
446
- address: pool.id.toLowerCase(),
447
- connectorTokens: [
448
- {
449
- address: pool.token1.id.toLowerCase(),
450
- decimals: parseInt(pool.token1.decimals),
451
- },
452
- ],
453
- liquidityUSD: parseFloat(pool.reserveUSD),
454
- }));
455
-
456
- const pools1 = _.map(data.pools1, pool => ({
457
- exchange: this.dexKey,
458
- stable: pool[stableFieldKey],
459
- address: pool.id.toLowerCase(),
460
- connectorTokens: [
461
- {
462
- address: pool.token0.id.toLowerCase(),
463
- decimals: parseInt(pool.token0.decimals),
464
- },
465
- ],
466
- liquidityUSD: parseFloat(pool.reserveUSD),
467
- }));
468
-
469
- return _.slice(
470
- _.sortBy(_.concat(pools0, pools1), [pool => -1 * pool.liquidityUSD]),
471
- 0,
472
- count,
473
- );
474
- }
475
-
476
- // Same as at uniswap-v2-pool.json, but extended with decimals and stable
477
- async getInfusionPairOrderedParams(
478
- from: Token,
479
- to: Token,
480
- blockNumber: number,
481
- stable: boolean,
482
- tokenDexTransferFee: number,
483
- ): Promise<InfusionPoolOrderedParams | null> {
484
- const pair = await this.findInfusionPair(from, to, stable);
485
- if (!(pair && pair.pool && pair.exchange)) return null;
486
- const pairState = pair?.pool.getState(blockNumber);
487
-
488
- if (!pairState) {
489
- this.logger.error(
490
- `Error_orderPairParams expected reserves, got none (maybe the pool doesn't exist) ${
491
- from.symbol || from.address
492
- } ${to.symbol || to.address}`,
493
- );
494
- return null;
495
- }
496
-
497
- const fee = (pairState.feeCode + tokenDexTransferFee).toString();
498
- const pairReversed =
499
- pair.token1.address.toLowerCase() === from.address.toLowerCase();
500
- if (pairReversed) {
501
- return {
502
- tokenIn: from.address,
503
- tokenOut: to.address,
504
- reservesIn: pairState.reserves1,
505
- reservesOut: pairState.reserves0,
506
- fee,
507
- direction: false,
508
- exchange: pair.exchange,
509
- decimalsIn: from.decimals,
510
- decimalsOut: to.decimals,
511
- stable,
512
- };
513
- }
514
- return {
515
- tokenIn: from.address,
516
- tokenOut: to.address,
517
- reservesIn: pairState.reserves0,
518
- reservesOut: pairState.reserves1,
519
- fee,
520
- direction: true,
521
- exchange: pair.exchange,
522
- decimalsIn: from.decimals,
523
- decimalsOut: to.decimals,
524
- stable,
525
- };
526
- }
527
-
528
- async getPoolIdentifiers(
529
- _from: Token,
530
- _to: Token,
531
- side: SwapSide,
532
- blockNumber: number,
533
- ): Promise<string[]> {
534
- if (side === SwapSide.BUY) return [];
535
-
536
- const from = this.dexHelper.config.wrapETH(_from);
537
- const to = this.dexHelper.config.wrapETH(_to);
538
-
539
- if (from.address.toLowerCase() === to.address.toLowerCase()) {
540
- return [];
541
- }
542
-
543
- const tokenAddress = [from.address.toLowerCase(), to.address.toLowerCase()]
544
- .sort((a, b) => (a > b ? 1 : -1))
545
- .join('_');
546
-
547
- const poolIdentifier = `${this.dexKey}_${tokenAddress}`;
548
- const poolIdentifierUniswap = poolIdentifier + this.poolPostfix(false);
549
- const poolIdentifierStable = poolIdentifier + this.poolPostfix(true);
550
- return [poolIdentifierUniswap, poolIdentifierStable];
551
- }
552
-
553
- poolPostfix(stable: boolean) {
554
- return stable ? 'S' : 'V';
555
- }
556
-
557
- getAdapters(side: SwapSide): { name: string; index: number }[] | null {
558
- return null;
559
- }
560
-
561
- getAdapterParam(
562
- srcToken: Address,
563
- destToken: Address,
564
- srcAmount: NumberAsString,
565
- toAmount: NumberAsString, // required for buy case
566
- data: InfusionData,
567
- side: SwapSide,
568
- ): AdapterExchangeParam {
569
- return {
570
- targetExchange: data.router,
571
- payload: '',
572
- networkFee: '0',
573
- };
574
- }
575
-
576
- getDexParam(
577
- src: Address,
578
- dest: Address,
579
- srcAmount: NumberAsString,
580
- destAmount: NumberAsString,
581
- recipient: Address,
582
- data: InfusionData,
583
- side: SwapSide,
584
- ): DexExchangeParam {
585
- if (side === SwapSide.BUY) throw new Error(`Buy not supported`);
586
-
587
- let routerMethod: any;
588
- let routerArgs: InfusionParam;
589
- const stable = isStablePair(this.network, src, dest);
590
-
591
- const from = isETHAddress(src)
592
- ? this.dexHelper.config.data.wrappedNativeTokenAddress
593
- : src;
594
- const to = isETHAddress(dest)
595
- ? this.dexHelper.config.data.wrappedNativeTokenAddress
596
- : dest;
597
-
598
- routerMethod = isETHAddress(src)
599
- ? InfusionRouterFunctions.sellExactEth
600
- : InfusionRouterFunctions.swapExactIn;
601
- routerMethod = isETHAddress(dest)
602
- ? InfusionRouterFunctions.sellExactToken
603
- : routerMethod;
604
-
605
- routerArgs = isETHAddress(src)
606
- ? [
607
- destAmount,
608
- [{ from, to, stable }],
609
- recipient,
610
- Math.floor(new Date().getTime() / 1000) + 120,
611
- ]
612
- : [
613
- srcAmount,
614
- destAmount,
615
- [{ from, to, stable }],
616
- recipient,
617
- Math.floor(new Date().getTime() / 1000) + 120,
618
- ];
619
-
620
- const exchangeData = new Interface(infusionRouterABI).encodeFunctionData(
621
- routerMethod,
622
- routerArgs as InfusionParam,
623
- );
624
-
625
- return {
626
- needWrapNative: this.needWrapNative,
627
- dexFuncHasRecipient: true,
628
- exchangeData,
629
- targetExchange: data.router,
630
- returnAmountPos: undefined,
631
- };
632
- }
633
-
634
- protected getFeesMultiCallData(pair: InfusionPair) {
635
- const callEntry = {
636
- target: this.factoryAddress,
637
- callData: velodromeFactoryIface.encodeFunctionData('getFee', [
638
- pair.stable,
639
- ]),
640
- };
641
- const callDecoder = (values: any[]) =>
642
- parseInt(
643
- velodromeFactoryIface
644
- .decodeFunctionResult('getFee', values)[0]
645
- .toString(),
646
- );
647
-
648
- return {
649
- callEntry,
650
- callDecoder,
651
- };
652
- }
653
- }
@@ -1,60 +0,0 @@
1
- import {
2
- UniswapV2Data,
3
- UniswapV2PoolOrderedParams,
4
- DexParams as UniswapV2DexParams,
5
- UniswapPool,
6
- } from '../uniswap-v2/types';
7
- import { UniswapV2Pair } from '../uniswap-v2/uniswap-v2';
8
-
9
- export type PoolState = {
10
- reserves0: string;
11
- reserves1: string;
12
- feeCode: number;
13
- };
14
-
15
- // to calculate prices for stable pool, we need decimals of the stable tokens
16
- export interface InfusionPoolOrderedParams extends UniswapV2PoolOrderedParams {
17
- decimalsIn: number;
18
- decimalsOut: number;
19
- stable: boolean;
20
- }
21
-
22
- export type InfusionData = UniswapV2Data & { isFeeTokenInRoute: boolean };
23
-
24
- export type InfusionPool = UniswapPool;
25
-
26
- export interface DexParams extends Omit<UniswapV2DexParams, 'feeCode'> {
27
- feeCode: number;
28
- stableFee?: number;
29
- volatileFee?: number;
30
- feeFactor?: number;
31
- }
32
-
33
- export interface InfusionPair extends UniswapV2Pair {
34
- stable: boolean;
35
- }
36
-
37
- export type InfusionParam = SellOnInfusionParam | SellETHOnInfusionParam;
38
-
39
- export type SellOnInfusionParam = [
40
- amountIn: string,
41
- amountOutMin: string,
42
- routes: {
43
- from: string;
44
- to: string;
45
- stable: boolean;
46
- }[],
47
- to: string,
48
- deadline: number,
49
- ];
50
-
51
- export type SellETHOnInfusionParam = [
52
- amountOutMin: string,
53
- routes: {
54
- from: string;
55
- to: string;
56
- stable: boolean;
57
- }[],
58
- to: string,
59
- deadline: number,
60
- ];