@paraswap/dex-lib 3.11.8-stader.3 → 3.11.8

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 (269) hide show
  1. package/.vscode/launch.json +53 -0
  2. package/.vscode/settings.json +2 -0
  3. package/.vscode/tasks.json +15 -0
  4. package/build/abi/balancer-v3/batch-router.json +989 -0
  5. package/build/abi/balancer-v3/router.json +1792 -0
  6. package/build/abi/balancer-v3/vault-extension.json +2834 -0
  7. package/build/abi/{cables/CablesMainnetRFQ.json → inception/inception-ineth-pool.json} +489 -510
  8. package/build/abi/inception/inception-ratio-feed.json +329 -0
  9. package/build/abi/inception/inception-vault.json +991 -0
  10. package/build/abi/permit2.json +581 -0
  11. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
  12. package/build/abi/usual-m-smart-m/usualM.abi.json +483 -0
  13. package/build/abi/usual-m-usd0/usualCollateralDao.abi.json +681 -0
  14. package/build/abi/{integral/relayer.json → wombat/pool.json} +474 -721
  15. package/build/dex/aave-v1/aave-v1.d.ts +2 -1
  16. package/build/dex/aave-v1/aave-v1.js +23 -0
  17. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  18. package/build/dex/aave-v2/tokens-avalanche.json +44 -0
  19. package/build/dex/aave-v2/tokens-mainnet.json +188 -0
  20. package/build/dex/aave-v2/tokens-polygon.json +44 -0
  21. package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +729 -0
  22. package/build/dex/balancer-v3/abi/balancerBatchRouter.js +732 -0
  23. package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +1 -0
  24. package/build/dex/balancer-v3/abi/balancerRouter.d.ts +1406 -0
  25. package/build/dex/balancer-v3/abi/balancerRouter.js +1175 -0
  26. package/build/dex/balancer-v3/abi/balancerRouter.js.map +1 -0
  27. package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +2081 -0
  28. package/build/dex/balancer-v3/abi/vaultExtension.V3.js +1851 -0
  29. package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +1 -0
  30. package/build/dex/balancer-v3/balancer-v3-pool.d.ts +80 -0
  31. package/build/dex/balancer-v3/balancer-v3-pool.js +461 -0
  32. package/build/dex/balancer-v3/balancer-v3-pool.js.map +1 -0
  33. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.d.ts +34 -0
  34. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js +406 -0
  35. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js.map +1 -0
  36. package/build/dex/balancer-v3/balancer-v3.d.ts +57 -0
  37. package/build/dex/balancer-v3/balancer-v3.js +383 -0
  38. package/build/dex/balancer-v3/balancer-v3.js.map +1 -0
  39. package/build/dex/balancer-v3/config.d.ts +8 -0
  40. package/build/dex/balancer-v3/config.js +24 -0
  41. package/build/dex/balancer-v3/config.js.map +1 -0
  42. package/build/dex/balancer-v3/getGasCost.d.ts +2 -0
  43. package/build/dex/balancer-v3/getGasCost.js +41 -0
  44. package/build/dex/balancer-v3/getGasCost.js.map +1 -0
  45. package/build/dex/balancer-v3/getOnChainState.d.ts +10 -0
  46. package/build/dex/balancer-v3/getOnChainState.js +164 -0
  47. package/build/dex/balancer-v3/getOnChainState.js.map +1 -0
  48. package/build/dex/balancer-v3/getPoolsApi.d.ts +2 -0
  49. package/build/dex/balancer-v3/getPoolsApi.js +81 -0
  50. package/build/dex/balancer-v3/getPoolsApi.js.map +1 -0
  51. package/build/dex/balancer-v3/getTopPoolsApi.d.ts +13 -0
  52. package/build/dex/balancer-v3/getTopPoolsApi.js +62 -0
  53. package/build/dex/balancer-v3/getTopPoolsApi.js.map +1 -0
  54. package/build/dex/balancer-v3/optimizer.d.ts +2 -0
  55. package/build/dex/{trader-joe-v2.1 → balancer-v3}/optimizer.js +17 -16
  56. package/build/dex/balancer-v3/optimizer.js.map +1 -0
  57. package/build/dex/balancer-v3/stablePool.d.ts +7 -0
  58. package/build/dex/balancer-v3/stablePool.js +73 -0
  59. package/build/dex/balancer-v3/stablePool.js.map +1 -0
  60. package/build/dex/balancer-v3/types.d.ts +62 -0
  61. package/build/dex/balancer-v3/types.js +3 -0
  62. package/build/dex/balancer-v3/types.js.map +1 -0
  63. package/build/dex/balancer-v3/weightedPool.d.ts +1 -0
  64. package/build/dex/balancer-v3/weightedPool.js +6 -0
  65. package/build/dex/balancer-v3/weightedPool.js.map +1 -0
  66. package/build/dex/bebop/constants.d.ts +1 -1
  67. package/build/dex/bebop/constants.js +1 -1
  68. package/build/dex/inception/config.d.ts +4 -0
  69. package/build/dex/inception/config.js +109 -0
  70. package/build/dex/inception/config.js.map +1 -0
  71. package/build/dex/inception/inception-event-pool.d.ts +16 -0
  72. package/build/dex/inception/inception-event-pool.js +49 -0
  73. package/build/dex/inception/inception-event-pool.js.map +1 -0
  74. package/build/dex/inception/inception.d.ts +43 -0
  75. package/build/dex/inception/inception.js +180 -0
  76. package/build/dex/inception/inception.js.map +1 -0
  77. package/build/dex/inception/tokens.d.ts +9 -0
  78. package/build/dex/inception/tokens.js +28 -0
  79. package/build/dex/inception/tokens.js.map +1 -0
  80. package/build/dex/inception/types.d.ts +22 -0
  81. package/build/dex/inception/types.js +3 -0
  82. package/build/dex/inception/types.js.map +1 -0
  83. package/build/dex/inception/utils.d.ts +7 -0
  84. package/build/dex/inception/utils.js +58 -0
  85. package/build/dex/inception/utils.js.map +1 -0
  86. package/build/dex/index.js +0 -2
  87. package/build/dex/index.js.map +1 -1
  88. package/build/dex/jarvis.d.ts +2 -1
  89. package/build/dex/jarvis.js +58 -0
  90. package/build/dex/jarvis.js.map +1 -1
  91. package/build/dex/maker-psm/scripts/gem.abi.json +136 -0
  92. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  93. package/build/dex/maker-psm/scripts/validate-state.js +185 -0
  94. package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
  95. package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
  96. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.d.ts +1 -0
  97. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js +20 -0
  98. package/build/dex/pancakeswap-v3/pancakeswap-v3-pool.js.map +1 -1
  99. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +4 -0
  100. package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
  101. package/build/dex/platypus/platypus.d.ts +2 -1
  102. package/build/dex/platypus/platypus.js +45 -0
  103. package/build/dex/platypus/platypus.js.map +1 -1
  104. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
  105. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
  106. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
  107. package/build/dex/stable-pool.js +1 -8
  108. package/build/dex/stable-pool.js.map +1 -1
  109. package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
  110. package/build/dex/swaap-v1/swaap-v1.js +14 -0
  111. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  112. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
  113. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
  114. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
  115. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
  116. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
  117. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
  118. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +1 -0
  119. package/build/dex/uniswap-v3/uniswap-v3-pool.js +20 -0
  120. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  121. package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +4 -0
  122. package/build/dex/uniswap-v3/uniswap-v3-pricing.js +43 -0
  123. package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +1 -0
  124. package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +1 -0
  125. package/build/dex/uniswap-v3/uniswap-v3-worker.js +10 -0
  126. package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +1 -0
  127. package/build/dex/uniswap-v3/uniswap-v3.js +5 -0
  128. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  129. package/build/dex/usual/types.d.ts +13 -0
  130. package/build/dex/usual/types.js +3 -0
  131. package/build/dex/usual/types.js.map +1 -0
  132. package/build/dex/usual/usual-bond.d.ts +18 -0
  133. package/build/dex/usual/usual-bond.js +52 -0
  134. package/build/dex/usual/usual-bond.js.map +1 -0
  135. package/build/dex/usual/usual-m-smart-m.d.ts +17 -0
  136. package/build/dex/usual/usual-m-smart-m.js +50 -0
  137. package/build/dex/usual/usual-m-smart-m.js.map +1 -0
  138. package/build/dex/usual/usual-m-usd0.d.ts +17 -0
  139. package/build/dex/usual/usual-m-usd0.js +51 -0
  140. package/build/dex/usual/usual-m-usd0.js.map +1 -0
  141. package/build/dex/usual/usual.d.ts +27 -0
  142. package/build/dex/usual/usual.js +125 -0
  143. package/build/dex/usual/usual.js.map +1 -0
  144. package/build/dex/usual-m-smart-m/config.d.ts +3 -0
  145. package/build/dex/usual-m-smart-m/config.js +13 -0
  146. package/build/dex/usual-m-smart-m/config.js.map +1 -0
  147. package/build/dex/usual-m-smart-m/types.d.ts +7 -0
  148. package/build/dex/usual-m-smart-m/types.js +3 -0
  149. package/build/dex/usual-m-smart-m/types.js.map +1 -0
  150. package/build/dex/usual-m-smart-m/usual-m-smart-m.d.ts +35 -0
  151. package/build/dex/usual-m-smart-m/usual-m-smart-m.js +161 -0
  152. package/build/dex/usual-m-smart-m/usual-m-smart-m.js.map +1 -0
  153. package/build/dex/{stader → usual-m-usd0}/config.d.ts +1 -1
  154. package/build/dex/usual-m-usd0/config.js +14 -0
  155. package/build/dex/usual-m-usd0/config.js.map +1 -0
  156. package/build/dex/usual-m-usd0/types.d.ts +8 -0
  157. package/build/dex/usual-m-usd0/types.js +3 -0
  158. package/build/dex/usual-m-usd0/types.js.map +1 -0
  159. package/build/dex/usual-m-usd0/usual-m-usd0.d.ts +35 -0
  160. package/build/dex/usual-m-usd0/usual-m-usd0.js +159 -0
  161. package/build/dex/usual-m-usd0/usual-m-usd0.js.map +1 -0
  162. package/build/dex/zerox/index.d.ts +4 -26
  163. package/build/dex/zerox/index.js +50 -42
  164. package/build/dex/zerox/index.js.map +1 -1
  165. package/build/dex/zerox/types.d.ts +29 -0
  166. package/build/dex/zerox/types.js +8 -1
  167. package/build/dex/zerox/types.js.map +1 -1
  168. package/package.json +1 -1
  169. package/src/dex/balancer-v3/balancer-v3-sepolia-pools.ts +404 -0
  170. package/src/dex/bebop/constants.ts +1 -1
  171. package/src/dex/index.ts +0 -2
  172. package/src/dex/pancakeswap-v3/pancakeswap-v3-pool.ts +30 -0
  173. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +10 -0
  174. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +30 -0
  175. package/src/dex/uniswap-v3/uniswap-v3.ts +11 -0
  176. package/tests/constants-e2e.ts +0 -5
  177. package/.idea/aws.xml +0 -17
  178. package/.idea/codeStyles/Project.xml +0 -19
  179. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  180. package/.idea/misc.xml +0 -6
  181. package/.idea/modules.xml +0 -8
  182. package/.idea/paraswap-dex-lib.iml +0 -9
  183. package/.idea/prettier.xml +0 -7
  184. package/.idea/vcs.xml +0 -6
  185. package/build/abi/SSPM.json +0 -829
  186. package/build/abi/StaderOracle.json +0 -2170
  187. package/build/abi/integral/factory.json +0 -333
  188. package/build/abi/integral/oracle.json +0 -501
  189. package/build/abi/integral/pool.json +0 -1041
  190. package/build/dex/cables/cables.d.ts +0 -59
  191. package/build/dex/cables/cables.js +0 -614
  192. package/build/dex/cables/cables.js.map +0 -1
  193. package/build/dex/cables/config.d.ts +0 -4
  194. package/build/dex/cables/config.js +0 -15
  195. package/build/dex/cables/config.js.map +0 -1
  196. package/build/dex/cables/constants.d.ts +0 -20
  197. package/build/dex/cables/constants.js +0 -24
  198. package/build/dex/cables/constants.js.map +0 -1
  199. package/build/dex/cables/rate-fetcher.d.ts +0 -34
  200. package/build/dex/cables/rate-fetcher.js +0 -106
  201. package/build/dex/cables/rate-fetcher.js.map +0 -1
  202. package/build/dex/cables/types.d.ts +0 -113
  203. package/build/dex/cables/types.js +0 -19
  204. package/build/dex/cables/types.js.map +0 -1
  205. package/build/dex/cables/validators.d.ts +0 -5
  206. package/build/dex/cables/validators.js +0 -49
  207. package/build/dex/cables/validators.js.map +0 -1
  208. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +0 -49
  209. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +0 -104
  210. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +0 -1
  211. package/build/dex/integral/config.d.ts +0 -4
  212. package/build/dex/integral/config.js +0 -20
  213. package/build/dex/integral/config.js.map +0 -1
  214. package/build/dex/integral/context.d.ts +0 -40
  215. package/build/dex/integral/context.js +0 -158
  216. package/build/dex/integral/context.js.map +0 -1
  217. package/build/dex/integral/integral-factory.d.ts +0 -24
  218. package/build/dex/integral/integral-factory.js +0 -95
  219. package/build/dex/integral/integral-factory.js.map +0 -1
  220. package/build/dex/integral/integral-pool.d.ts +0 -50
  221. package/build/dex/integral/integral-pool.js +0 -149
  222. package/build/dex/integral/integral-pool.js.map +0 -1
  223. package/build/dex/integral/integral-pricing.d.ts +0 -18
  224. package/build/dex/integral/integral-pricing.js +0 -114
  225. package/build/dex/integral/integral-pricing.js.map +0 -1
  226. package/build/dex/integral/integral-relayer.d.ts +0 -42
  227. package/build/dex/integral/integral-relayer.js +0 -192
  228. package/build/dex/integral/integral-relayer.js.map +0 -1
  229. package/build/dex/integral/integral-token.d.ts +0 -27
  230. package/build/dex/integral/integral-token.js +0 -59
  231. package/build/dex/integral/integral-token.js.map +0 -1
  232. package/build/dex/integral/integral.d.ts +0 -41
  233. package/build/dex/integral/integral.js +0 -376
  234. package/build/dex/integral/integral.js.map +0 -1
  235. package/build/dex/integral/types.d.ts +0 -85
  236. package/build/dex/integral/types.js +0 -9
  237. package/build/dex/integral/types.js.map +0 -1
  238. package/build/dex/integral/utils-e2e.d.ts +0 -9
  239. package/build/dex/integral/utils-e2e.js +0 -131
  240. package/build/dex/integral/utils-e2e.js.map +0 -1
  241. package/build/dex/integral/utils.d.ts +0 -17
  242. package/build/dex/integral/utils.js +0 -94
  243. package/build/dex/integral/utils.js.map +0 -1
  244. package/build/dex/stader/config.js +0 -14
  245. package/build/dex/stader/config.js.map +0 -1
  246. package/build/dex/stader/stader-pool.d.ts +0 -18
  247. package/build/dex/stader/stader-pool.js +0 -47
  248. package/build/dex/stader/stader-pool.js.map +0 -1
  249. package/build/dex/stader/stader.d.ts +0 -42
  250. package/build/dex/stader/stader.js +0 -141
  251. package/build/dex/stader/stader.js.map +0 -1
  252. package/build/dex/stader/types.d.ts +0 -13
  253. package/build/dex/stader/types.js +0 -8
  254. package/build/dex/stader/types.js.map +0 -1
  255. package/build/dex/stader/utils.d.ts +0 -4
  256. package/build/dex/stader/utils.js +0 -24
  257. package/build/dex/stader/utils.js.map +0 -1
  258. package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
  259. package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
  260. package/src/abi/SSPM.json +0 -829
  261. package/src/abi/StaderOracle.json +0 -2170
  262. package/src/dex/stader/config.ts +0 -13
  263. package/src/dex/stader/stader-e2e.test.ts +0 -74
  264. package/src/dex/stader/stader-events.test.ts +0 -64
  265. package/src/dex/stader/stader-integration.test.ts +0 -210
  266. package/src/dex/stader/stader-pool.ts +0 -68
  267. package/src/dex/stader/stader.ts +0 -208
  268. package/src/dex/stader/types.ts +0 -16
  269. package/src/dex/stader/utils.ts +0 -34
@@ -1,59 +0,0 @@
1
- import { Address, NumberAsString, OptimalSwapExchange, SwapSide } from '@paraswap/core';
2
- import { AsyncOrSync } from 'ts-essentials';
3
- import { Network } from '../../constants';
4
- import { IDexHelper } from '../../dex-helper';
5
- import { AdapterExchangeParam, DexExchangeParam, ExchangePrices, ExchangeTxInfo, Logger, PoolLiquidity, PoolPrices, PreprocessTransactionOptions, Token, TransferFeeParams } from '../../types';
6
- import { IDex } from '../idex';
7
- import { SimpleExchange } from '../simple-exchange';
8
- import { CablesData } from './types';
9
- import { Interface } from 'ethers/lib/utils';
10
- export declare class Cables extends SimpleExchange implements IDex<any> {
11
- readonly network: Network;
12
- readonly dexKey: string;
13
- readonly dexHelper: IDexHelper;
14
- readonly mainnetRFQAddress: string;
15
- protected rfqInterface: Interface;
16
- static dexKeysWithNetwork: {
17
- key: string;
18
- networks: Network[];
19
- }[];
20
- readonly isStatePollingDex = true;
21
- private rateFetcher;
22
- logger: Logger;
23
- private tokensMap;
24
- hasConstantPriceLargeAmounts: boolean;
25
- constructor(network: Network, dexKey: string, dexHelper: IDexHelper, mainnetRFQAddress?: string, rfqInterface?: Interface);
26
- preProcessTransaction?(optimalSwapExchange: OptimalSwapExchange<CablesData>, srcToken: Token, destToken: Token, side: SwapSide, options: PreprocessTransactionOptions): Promise<[OptimalSwapExchange<CablesData>, ExchangeTxInfo]>;
27
- getDexParam(srcToken: Address, destToken: Address, srcAmount: NumberAsString, destAmount: NumberAsString, recipient: Address, data: CablesData, side: SwapSide): DexExchangeParam;
28
- getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: CablesData, side: SwapSide): AdapterExchangeParam;
29
- normalizeToken(token: Token): Token;
30
- normalizeTokenAddress(address: Address): Address;
31
- getTokenFromAddress(address: Address): Token;
32
- getPoolIdentifier(srcAddress: Address, destAddress: Address, mm?: string): string;
33
- getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
34
- calculateOrderPrice(amounts: bigint[], orderbook: string[][], baseToken: Token, quoteToken: Token, isInputQuote: boolean): bigint[];
35
- calculatePriceSwap(prices: string[][], requiredQty: number, qtyMode: Boolean): number;
36
- getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[], transferFees?: TransferFeeParams, isFirstSwap?: boolean): Promise<ExchangePrices<CablesData> | null>;
37
- getCalldataGasCost(poolPrices: PoolPrices<CablesData>): number | number[];
38
- initializePricing(blockNumber: number): Promise<void>;
39
- getAdapters(side: SwapSide): {
40
- name: string;
41
- index: number;
42
- }[] | null;
43
- releaseResources?(): AsyncOrSync<void>;
44
- normalizeAddress(address: string): string;
45
- getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
46
- /**
47
- * CACHED UTILS
48
- */
49
- getCachedTokens(): Promise<any>;
50
- getCachedPairs(): Promise<any>;
51
- getCachedPrices(): Promise<any>;
52
- getCachedTokensAddr(): Promise<any>;
53
- getPairString(baseToken: Token, quoteToken: Token): string;
54
- private findKeyByAddress;
55
- getPairData(srcToken: Token, destToken: Token): Promise<any>;
56
- isBlacklisted(txOrigin: Address): Promise<boolean>;
57
- isRestricted(): Promise<boolean>;
58
- restrict(): Promise<void>;
59
- }
@@ -1,614 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Cables = void 0;
30
- const core_1 = require("@paraswap/core");
31
- const ts_essentials_1 = require("ts-essentials");
32
- const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
33
- const constants_1 = require("../../constants");
34
- const utils_1 = require("../../utils");
35
- const simple_exchange_1 = require("../simple-exchange");
36
- const config_1 = require("./config");
37
- const constants_2 = require("./constants");
38
- const rate_fetcher_1 = require("./rate-fetcher");
39
- const types_1 = require("./types");
40
- const CablesMainnetRFQ_json_1 = __importDefault(require("../../abi/cables/CablesMainnetRFQ.json"));
41
- const utils_2 = require("ethers/lib/utils");
42
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
43
- const ethers_1 = require("ethers");
44
- const bigint_constants_1 = require("../../bigint-constants");
45
- class Cables extends simple_exchange_1.SimpleExchange {
46
- constructor(network, dexKey, dexHelper, mainnetRFQAddress = config_1.CablesConfig['Cables'][network]
47
- .mainnetRFQAddress, rfqInterface = new utils_2.Interface(CablesMainnetRFQ_json_1.default)) {
48
- super(dexHelper, dexKey);
49
- this.network = network;
50
- this.dexKey = dexKey;
51
- this.dexHelper = dexHelper;
52
- this.mainnetRFQAddress = mainnetRFQAddress;
53
- this.rfqInterface = rfqInterface;
54
- this.isStatePollingDex = true;
55
- this.tokensMap = {};
56
- this.hasConstantPriceLargeAmounts = false;
57
- // Function to find a key by address
58
- this.findKeyByAddress = (jsonData, targetAddress) => {
59
- const entries = Object.entries(jsonData);
60
- const foundEntry = entries.find(([_, value]) => value.address.toLowerCase() === targetAddress.toLowerCase());
61
- return foundEntry ? foundEntry[0] : undefined;
62
- };
63
- this.logger = dexHelper.getLogger(dexKey);
64
- this.rateFetcher = new rate_fetcher_1.CablesRateFetcher(this.dexHelper, this.dexKey, this.network, this.logger, {
65
- rateConfig: {
66
- pairsReqParams: {
67
- url: constants_2.CABLES_API_URL + '/pairs',
68
- },
69
- pricesReqParams: {
70
- url: constants_2.CABLES_API_URL + '/prices',
71
- },
72
- blacklistReqParams: {
73
- url: constants_2.CABLES_API_URL + '/blacklist',
74
- },
75
- tokensReqParams: {
76
- url: constants_2.CABLES_API_URL + '/tokens',
77
- },
78
- pricesIntervalMs: constants_2.CABLES_API_PRICES_POLLING_INTERVAL_MS,
79
- pricesCacheTTLSecs: constants_2.CABLES_PRICES_CACHES_TTL_S,
80
- pricesCacheKey: 'cablesPricesCacheKey',
81
- pairsIntervalMs: constants_2.CABLES_API_PAIRS_POLLING_INTERVAL_MS,
82
- pairsCacheTTLSecs: constants_2.CABLES_PAIRS_CACHES_TTL_S,
83
- pairsCacheKey: 'cablesPairsCacheKey',
84
- tokensIntervalMs: constants_2.CABLES_API_TOKENS_POLLING_INTERVAL_MS,
85
- tokensCacheTTLSecs: constants_2.CABLES_TOKENS_CACHES_TTL_S,
86
- tokensCacheKey: 'cablesTokensCacheKey',
87
- blacklistIntervalMs: constants_2.CABLES_API_BLACKLIST_POLLING_INTERVAL_MS,
88
- blacklistCacheTTLSecs: constants_2.CABLES_BLACKLIST_CACHES_TTL_S,
89
- blacklistCacheKey: constants_2.CABLES_BLACKLIST_CACHE_KEY,
90
- },
91
- });
92
- }
93
- async preProcessTransaction(optimalSwapExchange, srcToken, destToken, side, options) {
94
- if (await this.isBlacklisted(options.txOrigin)) {
95
- this.logger.warn(`${this.dexKey}-${this.network}: blacklisted TX Origin address '${options.txOrigin}' trying to build a transaction. Bailing...`);
96
- throw new Error(`${this.dexKey}-${this.network}: user=${options.txOrigin.toLowerCase()} is blacklisted`);
97
- }
98
- if (BigInt(optimalSwapExchange.srcAmount) === 0n) {
99
- throw new Error('getFirmRate failed with srcAmount === 0');
100
- }
101
- const normalizedSrcToken = this.normalizeToken(srcToken);
102
- const normalizedDestToken = this.normalizeToken(destToken);
103
- const swapIdentifier = `${this.dexKey}_${normalizedSrcToken.address}_${normalizedDestToken.address}_${side}`;
104
- try {
105
- let makerToken = normalizedDestToken;
106
- let takerToken = normalizedSrcToken;
107
- const isSell = side === core_1.SwapSide.SELL;
108
- const isBuy = side === core_1.SwapSide.BUY;
109
- const rfqParams = {
110
- makerAsset: ethers_1.ethers.utils.getAddress(makerToken.address),
111
- takerAsset: ethers_1.ethers.utils.getAddress(takerToken.address),
112
- ...(isBuy && { makerAmount: optimalSwapExchange.destAmount }),
113
- ...(isSell && { takerAmount: optimalSwapExchange.srcAmount }),
114
- userAddress: options.executionContractAddress,
115
- chainId: String(this.network),
116
- };
117
- const rfq = await this.dexHelper.httpRequest.post(`${constants_2.CABLES_API_URL}/quote`, rfqParams, constants_2.CABLES_FIRM_QUOTE_TIMEOUT_MS);
118
- if (!rfq) {
119
- throw new Error('Failed to fetch RFQ' +
120
- swapIdentifier +
121
- JSON.stringify(rfq + 'params' + rfqParams));
122
- }
123
- const { order } = rfq;
124
- (0, ts_essentials_1.assert)(order.makerAsset.toLowerCase() === makerToken.address, `QuoteData makerAsset=${order.makerAsset} is different from Paraswap makerAsset=${makerToken.address}`);
125
- (0, ts_essentials_1.assert)(order.takerAsset.toLowerCase() === takerToken.address, `QuoteData takerAsset=${order.takerAsset} is different from Paraswap takerAsset=${takerToken.address}`);
126
- if (isSell) {
127
- (0, ts_essentials_1.assert)(order.takerAmount === optimalSwapExchange.srcAmount, `QuoteData takerAmount=${order.takerAmount} is different from Paraswap srcAmount=${optimalSwapExchange.srcAmount}`);
128
- }
129
- else {
130
- (0, ts_essentials_1.assert)(order.makerAmount === optimalSwapExchange.destAmount, `QuoteData makerAmount=${order.makerAmount} is different from Paraswap destAmount=${optimalSwapExchange.destAmount}`);
131
- }
132
- const expiryAsBigInt = BigInt(order.expiry);
133
- const minDeadline = expiryAsBigInt > 0 ? expiryAsBigInt : bigint_constants_1.BI_MAX_UINT256;
134
- if (side === core_1.SwapSide.BUY) {
135
- const requiredAmount = BigInt(optimalSwapExchange.srcAmount);
136
- const quoteAmount = BigInt(order.takerAmount);
137
- const requiredAmountWithSlippage = new bignumber_js_1.default(requiredAmount.toString())
138
- .multipliedBy(options.slippageFactor)
139
- .toFixed(0);
140
- if (quoteAmount > BigInt(requiredAmountWithSlippage)) {
141
- throw new types_1.SlippageError(`Slipped, factor: ${quoteAmount.toString()} > ${requiredAmountWithSlippage}`);
142
- }
143
- }
144
- else {
145
- const requiredAmount = BigInt(optimalSwapExchange.destAmount);
146
- const quoteAmount = BigInt(order.makerAmount);
147
- const requiredAmountWithSlippage = new bignumber_js_1.default(requiredAmount.toString())
148
- .multipliedBy(options.slippageFactor)
149
- .toFixed(0);
150
- if (quoteAmount < BigInt(requiredAmountWithSlippage)) {
151
- throw new types_1.SlippageError(`Slipped, factor: ${options.slippageFactor} ${quoteAmount.toString()} < ${requiredAmountWithSlippage}`);
152
- }
153
- }
154
- return [
155
- {
156
- ...optimalSwapExchange,
157
- data: {
158
- quoteData: order,
159
- },
160
- },
161
- { deadline: minDeadline },
162
- ];
163
- }
164
- catch (e) {
165
- const message = `${this.dexKey}-${this.network}: ${e}`;
166
- this.logger.error(message);
167
- if (!e?.isSlippageError) {
168
- this.restrict();
169
- }
170
- throw new Error(message);
171
- }
172
- }
173
- getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side) {
174
- const { quoteData } = data;
175
- (0, ts_essentials_1.assert)(quoteData !== undefined, `${this.dexKey}-${this.network}: quoteData undefined`);
176
- const swapFunction = 'simpleSwap';
177
- const swapFunctionParams = [
178
- [
179
- quoteData.nonceAndMeta,
180
- quoteData.expiry,
181
- quoteData.makerAsset,
182
- quoteData.takerAsset,
183
- quoteData.maker,
184
- quoteData.taker,
185
- quoteData.makerAmount,
186
- quoteData.takerAmount,
187
- ],
188
- quoteData.signature,
189
- ];
190
- const exchangeData = this.rfqInterface.encodeFunctionData(swapFunction, swapFunctionParams);
191
- return {
192
- exchangeData,
193
- swappedAmountNotPresentInExchangeData: true,
194
- needWrapNative: this.needWrapNative,
195
- dexFuncHasRecipient: false,
196
- targetExchange: this.mainnetRFQAddress,
197
- returnAmountPos: undefined,
198
- };
199
- }
200
- getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
201
- const { quoteData } = data;
202
- (0, ts_essentials_1.assert)(quoteData !== undefined, `${this.dexKey}-${this.network}: quoteData undefined`);
203
- const params = [
204
- {
205
- nonceAndMeta: quoteData.nonceAndMeta,
206
- expiry: quoteData.expiry,
207
- makerAsset: quoteData.makerAsset,
208
- takerAsset: quoteData.takerAsset,
209
- maker: quoteData.maker,
210
- taker: quoteData.taker,
211
- makerAmount: quoteData.makerAmount,
212
- takerAmount: quoteData.takerAmount,
213
- },
214
- quoteData.signature,
215
- ];
216
- const payload = this.abiCoder.encodeParameter({
217
- ParentStruct: {
218
- order: {
219
- nonceAndMeta: 'uint256',
220
- expiry: 'uint128',
221
- makerAsset: 'address',
222
- takerAsset: 'address',
223
- maker: 'address',
224
- taker: 'address',
225
- makerAmount: 'uint256',
226
- takerAmount: 'uint256',
227
- },
228
- signature: 'bytes',
229
- },
230
- }, {
231
- order: params[0],
232
- signature: params[1],
233
- });
234
- return {
235
- targetExchange: this.mainnetRFQAddress,
236
- payload,
237
- networkFee: '0',
238
- };
239
- }
240
- normalizeToken(token) {
241
- return {
242
- ...token,
243
- address: this.normalizeTokenAddress(token.address),
244
- };
245
- }
246
- normalizeTokenAddress(address) {
247
- return address.toLowerCase();
248
- }
249
- getTokenFromAddress(address) {
250
- return this.tokensMap[this.normalizeAddress(address)];
251
- }
252
- getPoolIdentifier(srcAddress, destAddress, mm) {
253
- return `${this.dexKey}_${srcAddress}_${destAddress}`.toLowerCase();
254
- return `${this.dexKey}_${srcAddress}_${destAddress}_${mm}`.toLowerCase();
255
- }
256
- async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
257
- if (!srcToken || !destToken) {
258
- return [];
259
- }
260
- if (srcToken.address.toLowerCase() === destToken.address.toLowerCase()) {
261
- return [];
262
- }
263
- const pairData = await this.getPairData(srcToken, destToken);
264
- if (!pairData) {
265
- return [];
266
- }
267
- const tokensAddr = (await this.getCachedTokensAddr()) || {};
268
- return [
269
- this.getPoolIdentifier(tokensAddr[pairData.base.toLowerCase()], tokensAddr[pairData.quote.toLowerCase()]),
270
- ];
271
- }
272
- calculateOrderPrice(amounts, orderbook, baseToken, quoteToken, isInputQuote) {
273
- let result = [];
274
- for (let i = 0; i < amounts.length; i++) {
275
- let amt = amounts[i];
276
- if (amt === 0n) {
277
- result.push(amt);
278
- continue;
279
- }
280
- let decimals = baseToken.decimals;
281
- let out_decimals = quoteToken.decimals;
282
- let price = this.calculatePriceSwap(orderbook, Number(amt) / 10 ** decimals, isInputQuote);
283
- result.push(BigInt(Math.round(price * 10 ** out_decimals)));
284
- }
285
- return result;
286
- }
287
- calculatePriceSwap(prices, requiredQty, qtyMode) {
288
- let sumBaseQty = 0;
289
- let sumQuoteQty = 0;
290
- const selectedRows = [];
291
- const isBase = qtyMode;
292
- const isQuote = !qtyMode;
293
- for (const [price, volume] of prices) {
294
- if (isBase) {
295
- if (sumBaseQty >= requiredQty) {
296
- break;
297
- }
298
- }
299
- if (isQuote) {
300
- if (sumQuoteQty >= requiredQty) {
301
- break;
302
- }
303
- }
304
- let currentBaseQty = Number(volume);
305
- let currentQuoteQty = Number(volume) * Number(price);
306
- const overQty = isBase
307
- ? currentBaseQty + sumBaseQty > requiredQty
308
- : currentQuoteQty + sumQuoteQty > requiredQty;
309
- if (overQty) {
310
- if (isBase) {
311
- currentBaseQty = requiredQty - sumBaseQty;
312
- currentQuoteQty = currentBaseQty * Number(price);
313
- }
314
- if (isQuote) {
315
- currentQuoteQty = requiredQty - sumQuoteQty;
316
- currentBaseQty =
317
- currentQuoteQty *
318
- new bignumber_js_1.default(1).dividedBy(new bignumber_js_1.default(price)).toNumber();
319
- }
320
- }
321
- sumBaseQty += currentBaseQty;
322
- sumQuoteQty += currentQuoteQty;
323
- selectedRows.push([price, currentBaseQty.toString()]);
324
- }
325
- const vSumBase = selectedRows.reduce((sum, [price, volume]) => {
326
- return sum + Number(price) * Number(volume);
327
- }, 0);
328
- const price = new bignumber_js_1.default(vSumBase)
329
- .dividedBy(new bignumber_js_1.default(sumBaseQty))
330
- .toNumber();
331
- if (isBase) {
332
- return requiredQty / price;
333
- }
334
- else {
335
- return requiredQty * price;
336
- }
337
- }
338
- async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools, transferFees, isFirstSwap) {
339
- const isRestricted = await this.isRestricted();
340
- if (isRestricted) {
341
- return null;
342
- }
343
- try {
344
- const normalizedSrcToken = this.normalizeToken(srcToken);
345
- const normalizedDestToken = this.normalizeToken(destToken);
346
- // If: same token, return null
347
- if (normalizedSrcToken.address.toLowerCase() ===
348
- normalizedDestToken.address.toLowerCase()) {
349
- return null;
350
- }
351
- // Ensure that "symbol" is set
352
- const tokens = await this.getCachedTokens();
353
- this.tokensMap = Object.keys(tokens).reduce((acc, key) => {
354
- //@ts-ignore
355
- acc[tokens[key].address.toLowerCase()] = tokens[key];
356
- return acc;
357
- }, {});
358
- for (const symbol of Object.keys(tokens)) {
359
- const normalizedTokenAddress = tokens[symbol].address.toLowerCase();
360
- if (normalizedSrcToken.address === normalizedTokenAddress) {
361
- normalizedSrcToken.symbol = tokens[symbol].symbol;
362
- }
363
- if (normalizedDestToken.address === normalizedTokenAddress) {
364
- normalizedDestToken.symbol = tokens[symbol].symbol;
365
- }
366
- }
367
- // ---------- Pools ----------
368
- let pools = await this.getPoolIdentifiers(srcToken, destToken, side, blockNumber);
369
- if (pools.length === 0)
370
- return null;
371
- // ---------- Prices ----------
372
- const priceMap = await this.getCachedPrices();
373
- if (!priceMap)
374
- return null;
375
- let isInputQuote = false;
376
- let pairKey = `${normalizedSrcToken.symbol}/${normalizedDestToken.symbol}`;
377
- const pairsKeys = Object.keys(priceMap);
378
- if (!pairsKeys.includes(pairKey)) {
379
- // Revert
380
- isInputQuote = true;
381
- pairKey = `${normalizedDestToken.symbol}/${normalizedSrcToken.symbol}`;
382
- if (!pairsKeys.includes(pairKey)) {
383
- return null;
384
- }
385
- }
386
- /**
387
- * Orderbook
388
- */
389
- const priceData = priceMap[pairKey];
390
- let orderbook = [];
391
- if (side === core_1.SwapSide.BUY) {
392
- orderbook = priceData.asks;
393
- }
394
- else {
395
- orderbook = priceData.bids;
396
- }
397
- if (orderbook?.length === 0) {
398
- throw new Error(`Empty orderbook for ${pairKey}`);
399
- }
400
- const prices = this.calculateOrderPrice(amounts, orderbook, side === core_1.SwapSide.SELL ? srcToken : destToken, side === core_1.SwapSide.SELL ? destToken : srcToken, side === core_1.SwapSide.SELL ? isInputQuote : !isInputQuote);
401
- const result = [
402
- {
403
- prices: prices,
404
- unit: BigInt(normalizedDestToken.decimals),
405
- exchange: this.dexKey,
406
- gasCost: constants_2.CABLES_GAS_COST,
407
- poolAddresses: [this.mainnetRFQAddress],
408
- data: {},
409
- },
410
- ];
411
- return result;
412
- }
413
- catch (e) {
414
- this.logger.error(`Error in getPricesVolume`, {
415
- srcToken: srcToken.address || srcToken.symbol,
416
- destToken: destToken.address || destToken.symbol,
417
- side,
418
- }, e);
419
- return null;
420
- }
421
- }
422
- getCalldataGasCost(poolPrices) {
423
- return (CALLDATA_GAS_COST.DEX_OVERHEAD +
424
- // addresses: makerAsset, takerAsset, maker, taker
425
- CALLDATA_GAS_COST.ADDRESS * 4 +
426
- // uint256: expiry
427
- CALLDATA_GAS_COST.wordNonZeroBytes(16) +
428
- // uint256: nonceAndMeta, makerAmount, takerAmount
429
- CALLDATA_GAS_COST.AMOUNT * 3 +
430
- // bytes: _signature (65 bytes)
431
- CALLDATA_GAS_COST.FULL_WORD * 2 +
432
- CALLDATA_GAS_COST.OFFSET_SMALL);
433
- }
434
- async initializePricing(blockNumber) {
435
- if (!this.dexHelper.config.isSlave) {
436
- this.rateFetcher.start();
437
- }
438
- return;
439
- }
440
- getAdapters(side) {
441
- return null;
442
- }
443
- releaseResources() {
444
- if (this.rateFetcher) {
445
- this.rateFetcher.stop();
446
- }
447
- }
448
- normalizeAddress(address) {
449
- return address.toLowerCase() === constants_1.ETHER_ADDRESS
450
- ? constants_1.NULL_ADDRESS
451
- : address.toLowerCase();
452
- }
453
- async getTopPoolsForToken(tokenAddress, limit) {
454
- // const tokens = (await this.getCachedTokens()) as { [key: string]: Token };
455
- // const token = Object.values(tokens).find(
456
- // token => token.address.toLowerCase() === tokenAddress.toLowerCase(),
457
- // );
458
- //
459
- // console.log('TOKEN: ', token);
460
- //
461
- // if (!token) {
462
- // return [];
463
- // }
464
- //
465
- // const tokenPriceUsd = await this.dexHelper.getTokenUSDPrice(
466
- // token,
467
- // BigInt(10 ** token.decimals),
468
- // );
469
- //
470
- // const erc20BalanceCalldata = this.erc20Interface.encodeFunctionData(
471
- // 'balanceOf',
472
- // [this.mainnetRFQAddress],
473
- // );
474
- //
475
- // const tokenBalanceMultiCall = [
476
- // {
477
- // target: token.address,
478
- // callData: erc20BalanceCalldata,
479
- // },
480
- // ];
481
- // const res = (
482
- // await this.dexHelper.multiContract.methods
483
- // .aggregate(tokenBalanceMultiCall)
484
- // .call()
485
- // ).returnData[0];
486
- //
487
- // let tokenLiquidity = BigInt(res);
488
- //
489
- // let tokenLiquidityUsd =
490
- // (tokenLiquidity * BigInt(tokenPriceUsd * 1_000_000)) /
491
- // BigInt(1_000_000 * 10 ** token.decimals);
492
- //
493
- // let tokenWithLiquidity = [];
494
- //
495
- // tokenWithLiquidity.push({
496
- // exchange: this.dexKey,
497
- // address: this.mainnetRFQAddress,
498
- // connectorTokens: [
499
- // {
500
- // address: token.address,
501
- // decimals: token.decimals,
502
- // },
503
- // ],
504
- // liquidityUSD: Number(tokenLiquidityUsd),
505
- // });
506
- //
507
- // return tokenWithLiquidity;
508
- return [];
509
- }
510
- /**
511
- * CACHED UTILS
512
- */
513
- async getCachedTokens() {
514
- const cachedTokens = await this.dexHelper.cache.get(this.dexKey, this.network, this.rateFetcher.tokensCacheKey);
515
- return cachedTokens ? JSON.parse(cachedTokens) : {};
516
- }
517
- async getCachedPairs() {
518
- const cachedPairs = await this.dexHelper.cache.get(this.dexKey, this.network, this.rateFetcher.pairsCacheKey);
519
- return cachedPairs ? JSON.parse(cachedPairs) : {};
520
- }
521
- async getCachedPrices() {
522
- const cachedPrices = await this.dexHelper.cache.get(this.dexKey, this.network, this.rateFetcher.pricesCacheKey);
523
- return cachedPrices ? JSON.parse(cachedPrices) : {};
524
- }
525
- async getCachedTokensAddr() {
526
- const tokens = await this.getCachedTokens();
527
- const tokensAddr = {};
528
- for (const key of Object.keys(tokens)) {
529
- tokensAddr[tokens[key].symbol.toLowerCase()] = tokens[key].address;
530
- }
531
- return tokensAddr;
532
- }
533
- getPairString(baseToken, quoteToken) {
534
- return `${baseToken.symbol}/${quoteToken.symbol}`.toLowerCase();
535
- }
536
- async getPairData(srcToken, destToken) {
537
- const normalizedSrcToken = this.normalizeToken(srcToken);
538
- const normalizedDestToken = this.normalizeToken(destToken);
539
- if (normalizedSrcToken.address === normalizedDestToken.address) {
540
- return null;
541
- }
542
- const cachedTokens = await this.getCachedTokens();
543
- normalizedSrcToken.symbol = this.findKeyByAddress(cachedTokens, normalizedSrcToken.address);
544
- normalizedDestToken.symbol = this.findKeyByAddress(cachedTokens, normalizedDestToken.address);
545
- const cachedPairs = await this.getCachedPairs();
546
- const potentialPairs = [
547
- {
548
- base: normalizedSrcToken.symbol,
549
- quote: normalizedDestToken.symbol,
550
- identifier: this.getPairString(normalizedSrcToken, normalizedDestToken),
551
- isSrcBase: true,
552
- },
553
- {
554
- base: normalizedDestToken.symbol,
555
- quote: normalizedSrcToken.symbol,
556
- identifier: this.getPairString(normalizedDestToken, normalizedSrcToken),
557
- isSrcBase: false,
558
- },
559
- ];
560
- for (const pair of potentialPairs) {
561
- if (pair.identifier in cachedPairs) {
562
- const pairData = cachedPairs[pair.identifier];
563
- pairData.isSrcBase = pair.isSrcBase;
564
- return pairData;
565
- }
566
- }
567
- return null;
568
- }
569
- async isBlacklisted(txOrigin) {
570
- const cachedBlacklist = await this.dexHelper.cache.get(this.dexKey, this.network, constants_2.CABLES_BLACKLIST_CACHE_KEY);
571
- if (cachedBlacklist) {
572
- const blacklist = JSON.parse(cachedBlacklist);
573
- return blacklist.includes(txOrigin.toLowerCase());
574
- }
575
- return false;
576
- }
577
- async isRestricted() {
578
- const result = await this.dexHelper.cache.get(this.dexKey, this.network, constants_2.CABLES_RESTRICTED_CACHE_KEY);
579
- return result === 'true';
580
- }
581
- async restrict() {
582
- const errorsDataRaw = await this.dexHelper.cache.get(this.dexKey, this.network, constants_2.CABLES_ERRORS_CACHE_KEY);
583
- const errorsData = utils_1.Utils.Parse(errorsDataRaw);
584
- const ERRORS_TTL_S = Math.floor(constants_2.CABLES_RESTRICT_CHECK_INTERVAL_MS / 1000);
585
- if (!errorsData ||
586
- errorsData?.addedDatetimeMs + constants_2.CABLES_RESTRICT_CHECK_INTERVAL_MS <
587
- Date.now()) {
588
- this.logger.warn(`${this.dexKey}-${this.network}: First encounter of error OR error ocurred outside of threshold, setting up counter`);
589
- const data = {
590
- count: 1,
591
- addedDatetimeMs: Date.now(),
592
- };
593
- await this.dexHelper.cache.setex(this.dexKey, this.network, constants_2.CABLES_ERRORS_CACHE_KEY, ERRORS_TTL_S, utils_1.Utils.Serialize(data));
594
- return;
595
- }
596
- else {
597
- if (errorsData.count + 1 >= constants_2.CABLES_RESTRICT_COUNT_THRESHOLD) {
598
- this.logger.warn(`${this.dexKey}-${this.network}: Restricting due to error count=${errorsData.count + 1} within ${constants_2.CABLES_RESTRICT_CHECK_INTERVAL_MS / 1000 / 60} minutes`);
599
- await this.dexHelper.cache.setex(this.dexKey, this.network, constants_2.CABLES_RESTRICTED_CACHE_KEY, constants_2.CABLES_RESTRICT_TTL_S, 'true');
600
- }
601
- else {
602
- this.logger.warn(`${this.dexKey}-${this.network}: Error count increased`);
603
- const data = {
604
- count: errorsData.count + 1,
605
- addedDatetimeMs: errorsData.addedDatetimeMs,
606
- };
607
- await this.dexHelper.cache.setex(this.dexKey, this.network, constants_2.CABLES_RESTRICTED_CACHE_KEY, ERRORS_TTL_S, utils_1.Utils.Serialize(data));
608
- }
609
- }
610
- }
611
- }
612
- exports.Cables = Cables;
613
- Cables.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.CablesConfig);
614
- //# sourceMappingURL=cables.js.map