@paraswap/dex-lib 4.0.3-Cables.0 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) 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/{integral/pool.json → inception/inception-ineth-pool.json} +558 -537
  5. package/build/abi/inception/inception-ratio-feed.json +329 -0
  6. package/build/abi/inception/inception-vault.json +991 -0
  7. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
  8. package/build/abi/usual-m-smart-m/usualM.abi.json +483 -0
  9. package/build/abi/usual-m-usd0/usualCollateralDao.abi.json +681 -0
  10. package/build/abi/usual-m-wrapped-m/usualM.abi.json +509 -0
  11. package/build/abi/{integral/relayer.json → wombat/pool.json} +474 -721
  12. package/build/dex/aave-v1/aave-v1.d.ts +2 -1
  13. package/build/dex/aave-v1/aave-v1.js +23 -0
  14. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  15. package/build/dex/aave-v2/tokens-avalanche.json +44 -0
  16. package/build/dex/aave-v2/tokens-mainnet.json +188 -0
  17. package/build/dex/aave-v2/tokens-polygon.json +44 -0
  18. package/build/dex/algebra/algebra.js +2 -31
  19. package/build/dex/algebra/algebra.js.map +1 -1
  20. package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +729 -0
  21. package/build/dex/balancer-v3/abi/balancerBatchRouter.js +732 -0
  22. package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +1 -0
  23. package/build/dex/balancer-v3/abi/balancerRouter.d.ts +1406 -0
  24. package/build/dex/balancer-v3/abi/balancerRouter.js +1175 -0
  25. package/build/dex/balancer-v3/abi/balancerRouter.js.map +1 -0
  26. package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +2081 -0
  27. package/build/dex/balancer-v3/abi/vaultExtension.V3.js +1851 -0
  28. package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +1 -0
  29. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.d.ts +34 -0
  30. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js +406 -0
  31. package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js.map +1 -0
  32. package/build/dex/bebop/bebop.js +1 -1
  33. package/build/dex/bebop/bebop.js.map +1 -1
  34. package/build/dex/cables/cables.d.ts +0 -1
  35. package/build/dex/cables/cables.js +88 -145
  36. package/build/dex/cables/cables.js.map +1 -1
  37. package/build/dex/cables/constants.js +1 -1
  38. package/build/dex/cables/constants.js.map +1 -1
  39. package/build/dex/cables/rate-fetcher.d.ts +0 -1
  40. package/build/dex/cables/rate-fetcher.js +10 -30
  41. package/build/dex/cables/rate-fetcher.js.map +1 -1
  42. package/build/dex/cables/types.d.ts +15 -16
  43. package/build/dex/cables/types.js +5 -2
  44. package/build/dex/cables/types.js.map +1 -1
  45. package/build/dex/dexalot/dexalot.js.map +1 -1
  46. package/build/dex/inception/config.d.ts +4 -0
  47. package/build/dex/inception/config.js +109 -0
  48. package/build/dex/inception/config.js.map +1 -0
  49. package/build/dex/inception/inception-event-pool.d.ts +16 -0
  50. package/build/dex/inception/inception-event-pool.js +49 -0
  51. package/build/dex/inception/inception-event-pool.js.map +1 -0
  52. package/build/dex/inception/inception.d.ts +43 -0
  53. package/build/dex/inception/inception.js +180 -0
  54. package/build/dex/inception/inception.js.map +1 -0
  55. package/build/dex/inception/tokens.d.ts +9 -0
  56. package/build/dex/inception/tokens.js +28 -0
  57. package/build/dex/inception/tokens.js.map +1 -0
  58. package/build/dex/inception/types.d.ts +22 -0
  59. package/build/dex/inception/types.js +3 -0
  60. package/build/dex/inception/types.js.map +1 -0
  61. package/build/dex/inception/utils.d.ts +7 -0
  62. package/build/dex/inception/utils.js +58 -0
  63. package/build/dex/inception/utils.js.map +1 -0
  64. package/build/dex/index.js +0 -2
  65. package/build/dex/index.js.map +1 -1
  66. package/build/dex/jarvis.d.ts +2 -1
  67. package/build/dex/jarvis.js +58 -0
  68. package/build/dex/jarvis.js.map +1 -1
  69. package/build/dex/maker-psm/scripts/gem.abi.json +136 -0
  70. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  71. package/build/dex/maker-psm/scripts/validate-state.js +185 -0
  72. package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
  73. package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
  74. package/build/dex/platypus/platypus.d.ts +2 -1
  75. package/build/dex/platypus/platypus.js +45 -0
  76. package/build/dex/platypus/platypus.js.map +1 -1
  77. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
  78. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
  79. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
  80. package/build/dex/stable-pool.js +1 -8
  81. package/build/dex/stable-pool.js.map +1 -1
  82. package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
  83. package/build/dex/swaap-v1/swaap-v1.js +14 -0
  84. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  85. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
  86. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
  87. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
  88. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
  89. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
  90. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
  91. package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +4 -0
  92. package/build/dex/uniswap-v3/uniswap-v3-pricing.js +43 -0
  93. package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +1 -0
  94. package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +1 -0
  95. package/build/dex/uniswap-v3/uniswap-v3-worker.js +10 -0
  96. package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +1 -0
  97. package/build/dex/usual/types.d.ts +13 -0
  98. package/build/dex/usual/types.js +3 -0
  99. package/build/dex/usual/types.js.map +1 -0
  100. package/build/dex/usual/usual-bond.d.ts +18 -0
  101. package/build/dex/usual/usual-bond.js +52 -0
  102. package/build/dex/usual/usual-bond.js.map +1 -0
  103. package/build/dex/usual/usual-m-smart-m.d.ts +17 -0
  104. package/build/dex/usual/usual-m-smart-m.js +50 -0
  105. package/build/dex/usual/usual-m-smart-m.js.map +1 -0
  106. package/build/dex/usual/usual-m-usd0.d.ts +17 -0
  107. package/build/dex/usual/usual-m-usd0.js +51 -0
  108. package/build/dex/usual/usual-m-usd0.js.map +1 -0
  109. package/build/dex/usual/usual-m-wrapped-m.d.ts +17 -0
  110. package/build/dex/usual/usual-m-wrapped-m.js +50 -0
  111. package/build/dex/usual/usual-m-wrapped-m.js.map +1 -0
  112. package/build/dex/usual/usual.d.ts +27 -0
  113. package/build/dex/usual/usual.js +125 -0
  114. package/build/dex/usual/usual.js.map +1 -0
  115. package/build/dex/usual-m-smart-m/config.d.ts +3 -0
  116. package/build/dex/usual-m-smart-m/config.js +13 -0
  117. package/build/dex/usual-m-smart-m/config.js.map +1 -0
  118. package/build/dex/usual-m-smart-m/types.d.ts +7 -0
  119. package/build/dex/usual-m-smart-m/types.js +3 -0
  120. package/build/dex/usual-m-smart-m/types.js.map +1 -0
  121. package/build/dex/usual-m-smart-m/usual-m-smart-m.d.ts +35 -0
  122. package/build/dex/usual-m-smart-m/usual-m-smart-m.js +161 -0
  123. package/build/dex/usual-m-smart-m/usual-m-smart-m.js.map +1 -0
  124. package/build/dex/usual-m-usd0/config.d.ts +3 -0
  125. package/build/dex/usual-m-usd0/config.js +14 -0
  126. package/build/dex/usual-m-usd0/config.js.map +1 -0
  127. package/build/dex/usual-m-usd0/types.d.ts +8 -0
  128. package/build/dex/usual-m-usd0/types.js +3 -0
  129. package/build/dex/usual-m-usd0/types.js.map +1 -0
  130. package/build/dex/usual-m-usd0/usual-m-usd0.d.ts +35 -0
  131. package/build/dex/usual-m-usd0/usual-m-usd0.js +159 -0
  132. package/build/dex/usual-m-usd0/usual-m-usd0.js.map +1 -0
  133. package/build/dex/zerox/index.d.ts +4 -26
  134. package/build/dex/zerox/index.js +50 -42
  135. package/build/dex/zerox/index.js.map +1 -1
  136. package/build/dex/zerox/types.d.ts +29 -0
  137. package/build/dex/zerox/types.js +8 -1
  138. package/build/dex/zerox/types.js.map +1 -1
  139. package/build/executor/Executor01BytecodeBuilder.js +6 -11
  140. package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
  141. package/build/executor/Executor02BytecodeBuilder.js +6 -11
  142. package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
  143. package/build/executor/Executor03BytecodeBuilder.js +6 -11
  144. package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
  145. package/build/lib/pub-sub.d.ts +35 -0
  146. package/build/lib/pub-sub.js +106 -0
  147. package/build/lib/pub-sub.js.map +1 -0
  148. package/build/types.d.ts +0 -1
  149. package/package.json +1 -1
  150. package/src/dex/algebra/algebra.ts +9 -48
  151. package/src/dex/bebop/bebop.ts +1 -1
  152. package/src/dex/dexalot/dexalot.ts +0 -1
  153. package/src/dex/index.ts +0 -2
  154. package/src/executor/Executor01BytecodeBuilder.ts +11 -15
  155. package/src/executor/Executor02BytecodeBuilder.ts +9 -13
  156. package/src/executor/Executor03BytecodeBuilder.ts +9 -16
  157. package/src/types.ts +0 -1
  158. package/tests/constants-e2e.ts +2 -2
  159. package/.idea/aws.xml +0 -17
  160. package/.idea/codeStyles/Project.xml +0 -19
  161. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  162. package/.idea/misc.xml +0 -6
  163. package/.idea/modules.xml +0 -8
  164. package/.idea/paraswap-dex-lib.iml +0 -9
  165. package/.idea/prettier.xml +0 -7
  166. package/.idea/vcs.xml +0 -6
  167. package/build/abi/integral/factory.json +0 -333
  168. package/build/abi/integral/oracle.json +0 -501
  169. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +0 -49
  170. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +0 -104
  171. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +0 -1
  172. package/build/dex/integral/config.d.ts +0 -4
  173. package/build/dex/integral/config.js +0 -20
  174. package/build/dex/integral/config.js.map +0 -1
  175. package/build/dex/integral/context.d.ts +0 -40
  176. package/build/dex/integral/context.js +0 -158
  177. package/build/dex/integral/context.js.map +0 -1
  178. package/build/dex/integral/integral-factory.d.ts +0 -24
  179. package/build/dex/integral/integral-factory.js +0 -95
  180. package/build/dex/integral/integral-factory.js.map +0 -1
  181. package/build/dex/integral/integral-pool.d.ts +0 -50
  182. package/build/dex/integral/integral-pool.js +0 -149
  183. package/build/dex/integral/integral-pool.js.map +0 -1
  184. package/build/dex/integral/integral-pricing.d.ts +0 -18
  185. package/build/dex/integral/integral-pricing.js +0 -114
  186. package/build/dex/integral/integral-pricing.js.map +0 -1
  187. package/build/dex/integral/integral-relayer.d.ts +0 -42
  188. package/build/dex/integral/integral-relayer.js +0 -192
  189. package/build/dex/integral/integral-relayer.js.map +0 -1
  190. package/build/dex/integral/integral-token.d.ts +0 -27
  191. package/build/dex/integral/integral-token.js +0 -59
  192. package/build/dex/integral/integral-token.js.map +0 -1
  193. package/build/dex/integral/integral.d.ts +0 -41
  194. package/build/dex/integral/integral.js +0 -376
  195. package/build/dex/integral/integral.js.map +0 -1
  196. package/build/dex/integral/types.d.ts +0 -85
  197. package/build/dex/integral/types.js +0 -9
  198. package/build/dex/integral/types.js.map +0 -1
  199. package/build/dex/integral/utils-e2e.d.ts +0 -9
  200. package/build/dex/integral/utils-e2e.js +0 -131
  201. package/build/dex/integral/utils-e2e.js.map +0 -1
  202. package/build/dex/integral/utils.d.ts +0 -17
  203. package/build/dex/integral/utils.js +0 -94
  204. package/build/dex/integral/utils.js.map +0 -1
  205. package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
  206. package/build/dex/trader-joe-v2.1/optimizer.js +0 -47
  207. package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
  208. package/src/abi/cables/CablesMainnetRFQ.json +0 -1083
  209. package/src/dex/cables/cables-e2e.test.ts +0 -207
  210. package/src/dex/cables/cables-integration.test.ts +0 -391
  211. package/src/dex/cables/cables.ts +0 -1006
  212. package/src/dex/cables/config.ts +0 -13
  213. package/src/dex/cables/constants.ts +0 -35
  214. package/src/dex/cables/rate-fetcher.ts +0 -219
  215. package/src/dex/cables/types.ts +0 -130
  216. package/src/dex/cables/validators.test.ts +0 -151
  217. package/src/dex/cables/validators.ts +0 -61
@@ -1,13 +0,0 @@
1
- import { Network } from '../../constants';
2
- import { DexConfigMap } from '../../types';
3
-
4
- export const CablesConfig: DexConfigMap<{ mainnetRFQAddress: string }> = {
5
- Cables: {
6
- [Network.AVALANCHE]: {
7
- mainnetRFQAddress: '0xfA12DCB2e1FD72bD92E8255Db6A781b2c76adC20',
8
- },
9
- [Network.ARBITRUM]: {
10
- mainnetRFQAddress: '0xfA12DCB2e1FD72bD92E8255Db6A781b2c76adC20',
11
- },
12
- },
13
- };
@@ -1,35 +0,0 @@
1
- import BigNumber from 'bignumber.js';
2
-
3
- /**
4
- * Cables
5
- */
6
- export const CABLES_API_URL =
7
- 'https://cables-evm-rfq-service.cryptosrvc.com/v1';
8
-
9
- export const CABLES_PRICES_CACHES_TTL_S = 10;
10
- export const CABLES_API_PRICES_POLLING_INTERVAL_MS = 2000; // 2 sec
11
-
12
- export const CABLES_PAIRS_CACHES_TTL_S = 12;
13
- export const CABLES_API_PAIRS_POLLING_INTERVAL_MS = 10000; // 10 sec
14
-
15
- export const CABLES_BLACKLIST_CACHES_TTL_S = 60;
16
- export const CABLES_API_BLACKLIST_POLLING_INTERVAL_MS = 30000; // 30 sec
17
-
18
- export const CABLES_TOKENS_CACHES_TTL_S = 60;
19
- export const CABLES_API_TOKENS_POLLING_INTERVAL_MS = 30000; // 30 sec
20
-
21
- export const CABLES_FIRM_QUOTE_TIMEOUT_MS = 2000;
22
-
23
- export const CABLES_BLACKLIST_CACHE_KEY = 'cablesBlacklistCacheKey';
24
-
25
- export const CABLES_RESTRICTED_CACHE_KEY = 'restricted';
26
-
27
- export const CABLES_ERRORS_CACHE_KEY = 'errors';
28
-
29
- export const CABLES_RESTRICT_CHECK_INTERVAL_MS = 1000 * 60 * 3; // 3 min
30
-
31
- export const CABLES_RESTRICT_COUNT_THRESHOLD = 3;
32
-
33
- export const CABLES_RESTRICT_TTL_S = 10 * 60; // 10 min
34
-
35
- export const CABLES_GAS_COST = 120_000;
@@ -1,219 +0,0 @@
1
- import { Network } from '../../constants';
2
- import { IDexHelper } from '../../dex-helper';
3
- import { Fetcher } from '../../lib/fetcher/fetcher';
4
- import { validateAndCast } from '../../lib/validators';
5
- import { Logger, Token } from '../../types';
6
- import { PairData } from '../cables/types';
7
- import {
8
- CablesBlacklistResponse,
9
- CablesPairsResponse,
10
- CablesPricesResponse,
11
- CablesRateFetcherConfig,
12
- CablesTokensResponse,
13
- } from './types';
14
- import {
15
- blacklistResponseValidator,
16
- pairsResponseValidator,
17
- pricesResponseValidator,
18
- tokensResponseValidator,
19
- } from './validators';
20
-
21
- export class CablesRateFetcher {
22
- public tokensFetcher: Fetcher<CablesTokensResponse>;
23
- public tokensCacheKey: string;
24
- public tokensCacheTTL: number;
25
-
26
- public pairsFetcher: Fetcher<CablesPairsResponse>;
27
- public pairsCacheKey: string;
28
- public pairsCacheTTL: number;
29
-
30
- public pricesFetcher: Fetcher<CablesPricesResponse>;
31
- public pricesCacheKey: string;
32
- public pricesCacheTTL: number;
33
-
34
- public blacklistFetcher: Fetcher<CablesBlacklistResponse>;
35
- public blacklistCacheKey: string;
36
- public blacklistCacheTTL: number;
37
-
38
- tokensHandleResponseCallback: () => Promise<void>;
39
-
40
- constructor(
41
- private dexHelper: IDexHelper,
42
- private dexKey: string,
43
- private network: Network,
44
- private logger: Logger,
45
- config: CablesRateFetcherConfig,
46
- ) {
47
- this.tokensCacheKey = config.rateConfig.tokensCacheKey;
48
- this.tokensCacheTTL = config.rateConfig.tokensCacheTTLSecs;
49
-
50
- this.pairsCacheKey = config.rateConfig.pairsCacheKey;
51
- this.pairsCacheTTL = config.rateConfig.pairsCacheTTLSecs;
52
-
53
- this.pricesCacheKey = config.rateConfig.pricesCacheKey;
54
- this.pricesCacheTTL = config.rateConfig.pricesCacheTTLSecs;
55
-
56
- this.blacklistCacheKey = config.rateConfig.blacklistCacheKey;
57
- this.blacklistCacheTTL = config.rateConfig.blacklistCacheTTLSecs;
58
-
59
- this.tokensHandleResponseCallback =
60
- config.rateConfig.tokensHandleResponseCallback;
61
-
62
- this.pairsFetcher = new Fetcher<CablesPairsResponse>(
63
- dexHelper.httpRequest,
64
- {
65
- info: {
66
- requestOptions: config.rateConfig.pairsReqParams,
67
- caster: (data: unknown) => {
68
- return validateAndCast<CablesPairsResponse>(
69
- data,
70
- pairsResponseValidator,
71
- );
72
- },
73
- },
74
- handler: this.handlePairsResponse.bind(this),
75
- },
76
- config.rateConfig.pairsIntervalMs,
77
- logger,
78
- );
79
-
80
- this.pricesFetcher = new Fetcher<CablesPricesResponse>(
81
- dexHelper.httpRequest,
82
- {
83
- info: {
84
- requestOptions: config.rateConfig.pricesReqParams,
85
- caster: (data: unknown) => {
86
- return validateAndCast<CablesPricesResponse>(
87
- data,
88
- pricesResponseValidator,
89
- );
90
- },
91
- },
92
- handler: this.handlePricesResponse.bind(this),
93
- },
94
- config.rateConfig.pricesIntervalMs,
95
- logger,
96
- );
97
-
98
- this.blacklistFetcher = new Fetcher<CablesBlacklistResponse>(
99
- dexHelper.httpRequest,
100
- {
101
- info: {
102
- requestOptions: config.rateConfig.blacklistReqParams,
103
- caster: (data: unknown) => {
104
- return validateAndCast<CablesBlacklistResponse>(
105
- data,
106
- blacklistResponseValidator,
107
- );
108
- },
109
- },
110
- handler: this.handleBlacklistResponse.bind(this),
111
- },
112
- config.rateConfig.blacklistIntervalMs,
113
- logger,
114
- );
115
-
116
- this.tokensFetcher = new Fetcher<CablesTokensResponse>(
117
- dexHelper.httpRequest,
118
- {
119
- info: {
120
- requestOptions: config.rateConfig.tokensReqParams,
121
- caster: (data: unknown) => {
122
- return validateAndCast<CablesTokensResponse>(
123
- data,
124
- tokensResponseValidator,
125
- );
126
- },
127
- },
128
- handler: this.handleTokensResponse.bind(this),
129
- },
130
- config.rateConfig.tokensIntervalMs,
131
- logger,
132
- );
133
- }
134
-
135
- /**
136
- * Utils
137
- */
138
- start() {
139
- this.pairsFetcher.startPolling();
140
- this.pricesFetcher.startPolling();
141
- this.blacklistFetcher.startPolling();
142
- this.tokensFetcher.startPolling();
143
- }
144
- stop() {
145
- this.pairsFetcher.stopPolling();
146
- this.pricesFetcher.stopPolling();
147
- this.blacklistFetcher.stopPolling();
148
- this.tokensFetcher.stopPolling();
149
- }
150
-
151
- private handlePairsResponse(res: CablesPairsResponse): void {
152
- const networkId = String(this.network);
153
- const pairs = res.pairs[networkId];
154
-
155
- let normalized_pairs: { [token: string]: PairData } = {};
156
- Object.keys(pairs).forEach(key => {
157
- normalized_pairs[key.toLowerCase()] = pairs[key];
158
- });
159
-
160
- this.dexHelper.cache.setex(
161
- this.dexKey,
162
- this.network,
163
- this.pairsCacheKey,
164
- this.pairsCacheTTL,
165
- JSON.stringify(normalized_pairs),
166
- );
167
- }
168
-
169
- private handlePricesResponse(res: CablesPricesResponse): void {
170
- const networkId = String(this.network);
171
- const prices = res.prices[networkId];
172
-
173
- this.dexHelper.cache.setex(
174
- this.dexKey,
175
- this.network,
176
- this.pricesCacheKey,
177
- this.pricesCacheTTL,
178
- JSON.stringify(prices),
179
- );
180
- }
181
-
182
- private handleBlacklistResponse(res: CablesBlacklistResponse): void {
183
- const { blacklist } = res;
184
- this.dexHelper.cache.setex(
185
- this.dexKey,
186
- this.network,
187
- this.blacklistCacheKey,
188
- this.blacklistCacheTTL,
189
- JSON.stringify(blacklist.map(item => item.toLowerCase())),
190
- );
191
- }
192
-
193
- // Convert addresses to lowercase
194
- private normalizeAddressesToLowerCase = (
195
- jsonData: Record<string, { address: string }>,
196
- ) => {
197
- Object.keys(jsonData).forEach(key => {
198
- jsonData[key].address = jsonData[key].address.toLowerCase();
199
- });
200
- return jsonData;
201
- };
202
-
203
- private async handleTokensResponse(res: CablesTokensResponse): Promise<void> {
204
- const networkId = String(this.network);
205
- const tokens = res.tokens[networkId];
206
-
207
- const normalizedTokens = this.normalizeAddressesToLowerCase(tokens);
208
-
209
- this.dexHelper.cache.setex(
210
- this.dexKey,
211
- this.network,
212
- this.tokensCacheKey,
213
- this.tokensCacheTTL,
214
- JSON.stringify(normalizedTokens),
215
- );
216
-
217
- await this.tokensHandleResponseCallback();
218
- }
219
- }
@@ -1,130 +0,0 @@
1
- import { RequestHeaders } from '../../dex-helper';
2
- import { Token } from '../../types';
3
- import { Method } from '../../dex-helper/irequest-wrapper';
4
- import { AugustusRFQOrderData } from '../augustus-rfq';
5
-
6
- export type CablesRFQResponse = {
7
- order: AugustusRFQOrderData;
8
- signature: string;
9
- };
10
-
11
- export type CablesData = {
12
- quoteData?: AugustusRFQOrderData;
13
- };
14
-
15
- export enum OrderbookSide {
16
- bids = 'bids',
17
- asks = 'asks',
18
- }
19
-
20
- /**
21
- * Utils
22
- */
23
- export type CablesAPIParameters = {
24
- url: string;
25
- method: Method;
26
- };
27
- export class CablesRfqError extends Error {}
28
-
29
- /**
30
- * Types
31
- */
32
- export type PairData = {
33
- base: string;
34
- quote: string;
35
- liquidityUSD: number;
36
- };
37
-
38
- export type PriceAndAmount = [string, string];
39
-
40
- export type PriceData = {
41
- bids: PriceAndAmount[];
42
- asks: PriceAndAmount[];
43
- };
44
-
45
- export type PriceDataMap = {
46
- [network: string]: {
47
- [pair: string]: PriceData;
48
- };
49
- };
50
-
51
- export type TokenDataMap = {
52
- [network: string]: {
53
- [token: string]: Token;
54
- };
55
- };
56
-
57
- export type PairsDataMap = {
58
- [network: string]: {
59
- [token: string]: PairData;
60
- };
61
- };
62
-
63
- /**
64
- * Responses
65
- */
66
- export type CablesPricesResponse = {
67
- prices: PriceDataMap;
68
- };
69
- export type CablesBlacklistResponse = {
70
- blacklist: string[];
71
- };
72
- export type CablesTokensResponse = {
73
- tokens: TokenDataMap;
74
- };
75
- export type CablesPairsResponse = {
76
- pairs: PairsDataMap;
77
- };
78
-
79
- /**
80
- * Rate Fetcher
81
- */
82
- export type CablesRateFetcherConfig = {
83
- rateConfig: {
84
- pairsReqParams: {
85
- url: string;
86
- headers?: RequestHeaders;
87
- params?: any;
88
- };
89
- pricesReqParams: {
90
- url: string;
91
- headers?: RequestHeaders;
92
- params?: any;
93
- };
94
- blacklistReqParams: {
95
- url: string;
96
- headers?: RequestHeaders;
97
- params?: any;
98
- };
99
- tokensReqParams: {
100
- url: string;
101
- headers?: RequestHeaders;
102
- params?: any;
103
- };
104
- pairsIntervalMs: number;
105
- pricesIntervalMs: number;
106
- blacklistIntervalMs: number;
107
- tokensIntervalMs: number;
108
-
109
- pairsCacheKey: string;
110
- pricesCacheKey: string;
111
- blacklistCacheKey: string;
112
- tokensCacheKey: string;
113
-
114
- blacklistCacheTTLSecs: number;
115
- pairsCacheTTLSecs: number;
116
- pricesCacheTTLSecs: number;
117
- tokensCacheTTLSecs: number;
118
-
119
- tokensHandleResponseCallback: () => Promise<void>;
120
- };
121
- };
122
-
123
- export type RestrictData = {
124
- count: number;
125
- addedDatetimeMs: number;
126
- } | null;
127
-
128
- export class SlippageError extends Error {
129
- isSlippageError = true;
130
- }
@@ -1,151 +0,0 @@
1
- import Joi from 'joi';
2
- import {
3
- pairsResponseValidator,
4
- pricesResponseValidator,
5
- tokensResponseValidator,
6
- blacklistResponseValidator,
7
- } from './validators'; //
8
-
9
- describe('Validation Schemas', () => {
10
- describe('pairsResponseValidator', () => {
11
- it('should validate correct pairs response', () => {
12
- const validData = {
13
- pairs: { '43114': { 'USDC/USDT': { base: 'USDC', quote: 'USDT' } } },
14
- };
15
- const { error } = pairsResponseValidator.validate(validData);
16
- expect(error).toBeUndefined();
17
- });
18
-
19
- it('should invalidate incorrect pairs response', () => {
20
- const invalidData = { pairs: { '43114': 'USDC/USDT' } };
21
- const { error } = pairsResponseValidator.validate(invalidData);
22
- expect(error).toBeDefined();
23
- });
24
- });
25
-
26
- describe('pricesResponseValidator', () => {
27
- it('should validate correct prices response', () => {
28
- const validData = {
29
- prices: {
30
- '43114': {
31
- 'USDC/USDT': {
32
- bids: [
33
- ['0.9996', '244305.9'],
34
- ['0.9995', '236021.6'],
35
- ],
36
- asks: [
37
- ['0.9996', '244305.9'],
38
- ['0.9995', '236021.6'],
39
- ],
40
- },
41
- },
42
- },
43
- };
44
- const { error } = pricesResponseValidator.validate(validData);
45
- expect(error).toBeUndefined();
46
- });
47
-
48
- it('should invalidate incorrect prices response', () => {
49
- const invalidData = {
50
- prices: {
51
- chain1: {
52
- bids: [
53
- ['1000'], // invalid entry length
54
- ],
55
- asks: [['1010', '1']],
56
- },
57
- },
58
- };
59
- const { error } = pricesResponseValidator.validate(invalidData);
60
- expect(error).toBeDefined();
61
- });
62
- });
63
-
64
- describe('tokensResponseValidator', () => {
65
- it('should validate correct tokens response', () => {
66
- const validData = {
67
- tokens: {
68
- '43114': {
69
- AVAX: {
70
- symbol: 'AVAX',
71
- decimals: 18,
72
- name: 'AVAX',
73
- address: '0x0000000000000000000000000000000000000000',
74
- },
75
- WAVAX: {
76
- symbol: 'WAVAX',
77
- decimals: 18,
78
- name: 'WAVAX',
79
- address: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7',
80
- },
81
- 'WETH.e': {
82
- symbol: 'WETH.e',
83
- decimals: 18,
84
- name: 'WETH.e',
85
- address: '0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB',
86
- },
87
- USDT: {
88
- symbol: 'USDT',
89
- decimals: 6,
90
- name: 'USDT',
91
- address: '0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7',
92
- },
93
- USDC: {
94
- symbol: 'USDC',
95
- decimals: 6,
96
- name: 'USDC',
97
- address: '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E',
98
- },
99
- 'USDC.e': {
100
- symbol: 'USDC.e',
101
- decimals: 6,
102
- name: 'USDC.e',
103
- address: '0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664',
104
- },
105
- },
106
- },
107
- };
108
- const { error } = tokensResponseValidator.validate(validData);
109
- expect(error).toBeUndefined();
110
- });
111
-
112
- it('should invalidate incorrect tokens response', () => {
113
- const invalidData = {
114
- tokens: {
115
- chain1: {
116
- ETH: {
117
- symbol: '', // invalid value
118
- name: 'Ethereum',
119
- description: 'A popular cryptocurrency',
120
- address: '0x...',
121
- decimals: 18,
122
- type: 'ERC20',
123
- },
124
- },
125
- },
126
- };
127
- const { error } = tokensResponseValidator.validate(invalidData);
128
- expect(error).toBeDefined();
129
- });
130
- });
131
-
132
- describe('blacklistResponseValidator', () => {
133
- it('should validate correct blacklist response', () => {
134
- const validData = {
135
- blacklist: ['0xAddress1', '0xAddress2'],
136
- };
137
- const { error } = blacklistResponseValidator.validate(validData);
138
- expect(error).toBeUndefined();
139
- });
140
-
141
- it('should invalidate incorrect blacklist response', () => {
142
- const invalidData = {
143
- blacklist: [
144
- '', // invalid value
145
- ],
146
- };
147
- const { error } = blacklistResponseValidator.validate(invalidData);
148
- expect(error).toBeDefined();
149
- });
150
- });
151
- });
@@ -1,61 +0,0 @@
1
- import joi from 'joi';
2
-
3
- const pairValidator = joi.object({
4
- base: joi.string().min(1),
5
- quote: joi.string().min(1),
6
- liquidityUSD: joi.number().min(0),
7
- baseAddress: joi.string().min(1),
8
- quoteAddress: joi.string().min(1),
9
- baseDecimals: joi.number().min(0),
10
- quoteDecimals: joi.number().min(0),
11
- });
12
-
13
- const pairMap = joi.object().pattern(
14
- joi.string(), // Pair name ETH/USDT
15
- pairValidator,
16
- );
17
-
18
- export const pairsResponseValidator = joi.object({
19
- pairs: joi.object().pattern(
20
- joi.string(), // chain id
21
- pairMap,
22
- ),
23
- });
24
-
25
- const orderbookEntry = joi.array().items(joi.string().min(1)).length(2);
26
-
27
- const orderbookValidator = joi.object({
28
- bids: joi.array().items(orderbookEntry),
29
- asks: joi.array().items(orderbookEntry),
30
- });
31
-
32
- const chainDataSchema = joi.object().pattern(
33
- joi.string(), // pair name USDC/USDT
34
- orderbookValidator,
35
- );
36
-
37
- export const pricesResponseValidator = joi.object({
38
- prices: joi.object().pattern(
39
- joi.string(), // chain id
40
- chainDataSchema,
41
- ),
42
- });
43
-
44
- const tokenValidator = joi.object({
45
- symbol: joi.string().min(1),
46
- name: joi.string().min(1),
47
- description: joi.string().min(1),
48
- address: joi.string().min(1),
49
- decimals: joi.number().min(0),
50
- type: joi.string().min(1),
51
- });
52
-
53
- const chainTokens = joi.object().pattern(joi.string(), tokenValidator);
54
-
55
- export const tokensResponseValidator = joi.object({
56
- tokens: joi.object().pattern(joi.string(), chainTokens),
57
- });
58
-
59
- export const blacklistResponseValidator = joi.object({
60
- blacklist: joi.array().items(joi.string().min(1)),
61
- });