@paraswap/dex-lib 4.0.3-Cables.1 → 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 (216) 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 +2 -4
  35. package/build/dex/cables/cables.js +154 -89
  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.js +10 -26
  40. package/build/dex/cables/rate-fetcher.js.map +1 -1
  41. package/build/dex/cables/types.d.ts +28 -15
  42. package/build/dex/cables/types.js +13 -2
  43. package/build/dex/cables/types.js.map +1 -1
  44. package/build/dex/dexalot/dexalot.js.map +1 -1
  45. package/build/dex/inception/config.d.ts +4 -0
  46. package/build/dex/inception/config.js +109 -0
  47. package/build/dex/inception/config.js.map +1 -0
  48. package/build/dex/inception/inception-event-pool.d.ts +16 -0
  49. package/build/dex/inception/inception-event-pool.js +49 -0
  50. package/build/dex/inception/inception-event-pool.js.map +1 -0
  51. package/build/dex/inception/inception.d.ts +43 -0
  52. package/build/dex/inception/inception.js +180 -0
  53. package/build/dex/inception/inception.js.map +1 -0
  54. package/build/dex/inception/tokens.d.ts +9 -0
  55. package/build/dex/inception/tokens.js +28 -0
  56. package/build/dex/inception/tokens.js.map +1 -0
  57. package/build/dex/inception/types.d.ts +22 -0
  58. package/build/dex/inception/types.js +3 -0
  59. package/build/dex/inception/types.js.map +1 -0
  60. package/build/dex/inception/utils.d.ts +7 -0
  61. package/build/dex/inception/utils.js +58 -0
  62. package/build/dex/inception/utils.js.map +1 -0
  63. package/build/dex/index.js +0 -2
  64. package/build/dex/index.js.map +1 -1
  65. package/build/dex/jarvis.d.ts +2 -1
  66. package/build/dex/jarvis.js +58 -0
  67. package/build/dex/jarvis.js.map +1 -1
  68. package/build/dex/maker-psm/scripts/gem.abi.json +136 -0
  69. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  70. package/build/dex/maker-psm/scripts/validate-state.js +185 -0
  71. package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
  72. package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
  73. package/build/dex/platypus/platypus.d.ts +2 -1
  74. package/build/dex/platypus/platypus.js +45 -0
  75. package/build/dex/platypus/platypus.js.map +1 -1
  76. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
  77. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
  78. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
  79. package/build/dex/stable-pool.js +1 -8
  80. package/build/dex/stable-pool.js.map +1 -1
  81. package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
  82. package/build/dex/swaap-v1/swaap-v1.js +14 -0
  83. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  84. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
  85. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
  86. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
  87. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
  88. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
  89. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
  90. package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +4 -0
  91. package/build/dex/uniswap-v3/uniswap-v3-pricing.js +43 -0
  92. package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +1 -0
  93. package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +1 -0
  94. package/build/dex/uniswap-v3/uniswap-v3-worker.js +10 -0
  95. package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +1 -0
  96. package/build/dex/usual/types.d.ts +13 -0
  97. package/build/dex/usual/types.js +3 -0
  98. package/build/dex/usual/types.js.map +1 -0
  99. package/build/dex/usual/usual-bond.d.ts +18 -0
  100. package/build/dex/usual/usual-bond.js +52 -0
  101. package/build/dex/usual/usual-bond.js.map +1 -0
  102. package/build/dex/usual/usual-m-smart-m.d.ts +17 -0
  103. package/build/dex/usual/usual-m-smart-m.js +50 -0
  104. package/build/dex/usual/usual-m-smart-m.js.map +1 -0
  105. package/build/dex/usual/usual-m-usd0.d.ts +17 -0
  106. package/build/dex/usual/usual-m-usd0.js +51 -0
  107. package/build/dex/usual/usual-m-usd0.js.map +1 -0
  108. package/build/dex/usual/usual-m-wrapped-m.d.ts +17 -0
  109. package/build/dex/usual/usual-m-wrapped-m.js +50 -0
  110. package/build/dex/usual/usual-m-wrapped-m.js.map +1 -0
  111. package/build/dex/usual/usual.d.ts +27 -0
  112. package/build/dex/usual/usual.js +125 -0
  113. package/build/dex/usual/usual.js.map +1 -0
  114. package/build/dex/usual-m-smart-m/config.d.ts +3 -0
  115. package/build/dex/usual-m-smart-m/config.js +13 -0
  116. package/build/dex/usual-m-smart-m/config.js.map +1 -0
  117. package/build/dex/usual-m-smart-m/types.d.ts +7 -0
  118. package/build/dex/usual-m-smart-m/types.js +3 -0
  119. package/build/dex/usual-m-smart-m/types.js.map +1 -0
  120. package/build/dex/usual-m-smart-m/usual-m-smart-m.d.ts +35 -0
  121. package/build/dex/usual-m-smart-m/usual-m-smart-m.js +161 -0
  122. package/build/dex/usual-m-smart-m/usual-m-smart-m.js.map +1 -0
  123. package/build/dex/usual-m-usd0/config.d.ts +3 -0
  124. package/build/dex/usual-m-usd0/config.js +14 -0
  125. package/build/dex/usual-m-usd0/config.js.map +1 -0
  126. package/build/dex/usual-m-usd0/types.d.ts +8 -0
  127. package/build/dex/usual-m-usd0/types.js +3 -0
  128. package/build/dex/usual-m-usd0/types.js.map +1 -0
  129. package/build/dex/usual-m-usd0/usual-m-usd0.d.ts +35 -0
  130. package/build/dex/usual-m-usd0/usual-m-usd0.js +159 -0
  131. package/build/dex/usual-m-usd0/usual-m-usd0.js.map +1 -0
  132. package/build/dex/zerox/index.d.ts +4 -26
  133. package/build/dex/zerox/index.js +50 -42
  134. package/build/dex/zerox/index.js.map +1 -1
  135. package/build/dex/zerox/types.d.ts +29 -0
  136. package/build/dex/zerox/types.js +8 -1
  137. package/build/dex/zerox/types.js.map +1 -1
  138. package/build/executor/Executor01BytecodeBuilder.js +6 -11
  139. package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
  140. package/build/executor/Executor02BytecodeBuilder.js +6 -11
  141. package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
  142. package/build/executor/Executor03BytecodeBuilder.js +6 -11
  143. package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
  144. package/build/lib/pub-sub.d.ts +35 -0
  145. package/build/lib/pub-sub.js +106 -0
  146. package/build/lib/pub-sub.js.map +1 -0
  147. package/build/types.d.ts +0 -1
  148. package/package.json +1 -1
  149. package/src/dex/algebra/algebra.ts +9 -48
  150. package/src/dex/bebop/bebop.ts +1 -1
  151. package/src/dex/dexalot/dexalot.ts +0 -1
  152. package/src/dex/index.ts +0 -2
  153. package/src/executor/Executor01BytecodeBuilder.ts +11 -15
  154. package/src/executor/Executor02BytecodeBuilder.ts +9 -13
  155. package/src/executor/Executor03BytecodeBuilder.ts +9 -16
  156. package/src/types.ts +0 -1
  157. package/tests/constants-e2e.ts +2 -2
  158. package/.idea/aws.xml +0 -17
  159. package/.idea/codeStyles/Project.xml +0 -19
  160. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  161. package/.idea/misc.xml +0 -6
  162. package/.idea/modules.xml +0 -8
  163. package/.idea/paraswap-dex-lib.iml +0 -9
  164. package/.idea/prettier.xml +0 -7
  165. package/.idea/vcs.xml +0 -6
  166. package/build/abi/integral/factory.json +0 -333
  167. package/build/abi/integral/oracle.json +0 -501
  168. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +0 -49
  169. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +0 -104
  170. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +0 -1
  171. package/build/dex/integral/config.d.ts +0 -4
  172. package/build/dex/integral/config.js +0 -20
  173. package/build/dex/integral/config.js.map +0 -1
  174. package/build/dex/integral/context.d.ts +0 -40
  175. package/build/dex/integral/context.js +0 -158
  176. package/build/dex/integral/context.js.map +0 -1
  177. package/build/dex/integral/integral-factory.d.ts +0 -24
  178. package/build/dex/integral/integral-factory.js +0 -95
  179. package/build/dex/integral/integral-factory.js.map +0 -1
  180. package/build/dex/integral/integral-pool.d.ts +0 -50
  181. package/build/dex/integral/integral-pool.js +0 -149
  182. package/build/dex/integral/integral-pool.js.map +0 -1
  183. package/build/dex/integral/integral-pricing.d.ts +0 -18
  184. package/build/dex/integral/integral-pricing.js +0 -114
  185. package/build/dex/integral/integral-pricing.js.map +0 -1
  186. package/build/dex/integral/integral-relayer.d.ts +0 -42
  187. package/build/dex/integral/integral-relayer.js +0 -192
  188. package/build/dex/integral/integral-relayer.js.map +0 -1
  189. package/build/dex/integral/integral-token.d.ts +0 -27
  190. package/build/dex/integral/integral-token.js +0 -59
  191. package/build/dex/integral/integral-token.js.map +0 -1
  192. package/build/dex/integral/integral.d.ts +0 -41
  193. package/build/dex/integral/integral.js +0 -376
  194. package/build/dex/integral/integral.js.map +0 -1
  195. package/build/dex/integral/types.d.ts +0 -85
  196. package/build/dex/integral/types.js +0 -9
  197. package/build/dex/integral/types.js.map +0 -1
  198. package/build/dex/integral/utils-e2e.d.ts +0 -9
  199. package/build/dex/integral/utils-e2e.js +0 -131
  200. package/build/dex/integral/utils-e2e.js.map +0 -1
  201. package/build/dex/integral/utils.d.ts +0 -17
  202. package/build/dex/integral/utils.js +0 -94
  203. package/build/dex/integral/utils.js.map +0 -1
  204. package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
  205. package/build/dex/trader-joe-v2.1/optimizer.js +0 -47
  206. package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
  207. package/src/abi/cables/CablesMainnetRFQ.json +0 -1083
  208. package/src/dex/cables/cables-e2e.test.ts +0 -207
  209. package/src/dex/cables/cables-integration.test.ts +0 -391
  210. package/src/dex/cables/cables.ts +0 -824
  211. package/src/dex/cables/config.ts +0 -13
  212. package/src/dex/cables/constants.ts +0 -35
  213. package/src/dex/cables/rate-fetcher.ts +0 -212
  214. package/src/dex/cables/types.ts +0 -113
  215. package/src/dex/cables/validators.test.ts +0 -151
  216. 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,212 +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
- constructor(
39
- private dexHelper: IDexHelper,
40
- private dexKey: string,
41
- private network: Network,
42
- private logger: Logger,
43
- config: CablesRateFetcherConfig,
44
- ) {
45
- this.tokensCacheKey = config.rateConfig.tokensCacheKey;
46
- this.tokensCacheTTL = config.rateConfig.tokensCacheTTLSecs;
47
-
48
- this.pairsCacheKey = config.rateConfig.pairsCacheKey;
49
- this.pairsCacheTTL = config.rateConfig.pairsCacheTTLSecs;
50
-
51
- this.pricesCacheKey = config.rateConfig.pricesCacheKey;
52
- this.pricesCacheTTL = config.rateConfig.pricesCacheTTLSecs;
53
-
54
- this.blacklistCacheKey = config.rateConfig.blacklistCacheKey;
55
- this.blacklistCacheTTL = config.rateConfig.blacklistCacheTTLSecs;
56
-
57
- this.pairsFetcher = new Fetcher<CablesPairsResponse>(
58
- dexHelper.httpRequest,
59
- {
60
- info: {
61
- requestOptions: config.rateConfig.pairsReqParams,
62
- caster: (data: unknown) => {
63
- return validateAndCast<CablesPairsResponse>(
64
- data,
65
- pairsResponseValidator,
66
- );
67
- },
68
- },
69
- handler: this.handlePairsResponse.bind(this),
70
- },
71
- config.rateConfig.pairsIntervalMs,
72
- logger,
73
- );
74
-
75
- this.pricesFetcher = new Fetcher<CablesPricesResponse>(
76
- dexHelper.httpRequest,
77
- {
78
- info: {
79
- requestOptions: config.rateConfig.pricesReqParams,
80
- caster: (data: unknown) => {
81
- return validateAndCast<CablesPricesResponse>(
82
- data,
83
- pricesResponseValidator,
84
- );
85
- },
86
- },
87
- handler: this.handlePricesResponse.bind(this),
88
- },
89
- config.rateConfig.pricesIntervalMs,
90
- logger,
91
- );
92
-
93
- this.blacklistFetcher = new Fetcher<CablesBlacklistResponse>(
94
- dexHelper.httpRequest,
95
- {
96
- info: {
97
- requestOptions: config.rateConfig.blacklistReqParams,
98
- caster: (data: unknown) => {
99
- return validateAndCast<CablesBlacklistResponse>(
100
- data,
101
- blacklistResponseValidator,
102
- );
103
- },
104
- },
105
- handler: this.handleBlacklistResponse.bind(this),
106
- },
107
- config.rateConfig.blacklistIntervalMs,
108
- logger,
109
- );
110
-
111
- this.tokensFetcher = new Fetcher<CablesTokensResponse>(
112
- dexHelper.httpRequest,
113
- {
114
- info: {
115
- requestOptions: config.rateConfig.tokensReqParams,
116
- caster: (data: unknown) => {
117
- return validateAndCast<CablesTokensResponse>(
118
- data,
119
- tokensResponseValidator,
120
- );
121
- },
122
- },
123
- handler: this.handleTokensResponse.bind(this),
124
- },
125
- config.rateConfig.tokensIntervalMs,
126
- logger,
127
- );
128
- }
129
-
130
- /**
131
- * Utils
132
- */
133
- start() {
134
- this.pairsFetcher.startPolling();
135
- this.pricesFetcher.startPolling();
136
- this.blacklistFetcher.startPolling();
137
- this.tokensFetcher.startPolling();
138
- }
139
- stop() {
140
- this.pairsFetcher.stopPolling();
141
- this.pricesFetcher.stopPolling();
142
- this.blacklistFetcher.stopPolling();
143
- this.tokensFetcher.stopPolling();
144
- }
145
-
146
- private handlePairsResponse(res: CablesPairsResponse): void {
147
- const networkId = String(this.network);
148
- const pairs = res.pairs[networkId];
149
-
150
- let normalized_pairs: { [token: string]: PairData } = {};
151
- Object.keys(pairs).forEach(key => {
152
- normalized_pairs[key.toLowerCase()] = pairs[key];
153
- });
154
-
155
- this.dexHelper.cache.setex(
156
- this.dexKey,
157
- this.network,
158
- this.pairsCacheKey,
159
- this.pairsCacheTTL,
160
- JSON.stringify(normalized_pairs),
161
- );
162
- }
163
-
164
- private handlePricesResponse(res: CablesPricesResponse): void {
165
- const networkId = String(this.network);
166
- const prices = res.prices[networkId];
167
-
168
- this.dexHelper.cache.setex(
169
- this.dexKey,
170
- this.network,
171
- this.pricesCacheKey,
172
- this.pricesCacheTTL,
173
- JSON.stringify(prices),
174
- );
175
- }
176
-
177
- private handleBlacklistResponse(res: CablesBlacklistResponse): void {
178
- const { blacklist } = res;
179
- this.dexHelper.cache.setex(
180
- this.dexKey,
181
- this.network,
182
- this.blacklistCacheKey,
183
- this.blacklistCacheTTL,
184
- JSON.stringify(blacklist.map(item => item.toLowerCase())),
185
- );
186
- }
187
-
188
- // Convert addresses to lowercase
189
- private normalizeAddressesToLowerCase = (
190
- jsonData: Record<string, { address: string }>,
191
- ) => {
192
- Object.keys(jsonData).forEach(key => {
193
- jsonData[key].address = jsonData[key].address.toLowerCase();
194
- });
195
- return jsonData;
196
- };
197
-
198
- private async handleTokensResponse(res: CablesTokensResponse): Promise<void> {
199
- const networkId = String(this.network);
200
- const tokens = res.tokens[networkId];
201
-
202
- const normalizedTokens = this.normalizeAddressesToLowerCase(tokens);
203
-
204
- this.dexHelper.cache.setex(
205
- this.dexKey,
206
- this.network,
207
- this.tokensCacheKey,
208
- this.tokensCacheTTL,
209
- JSON.stringify(normalizedTokens),
210
- );
211
- }
212
- }
@@ -1,113 +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
- * Types
16
- */
17
- export type PairData = {
18
- base: string;
19
- quote: string;
20
- liquidityUSD: number;
21
- };
22
-
23
- type PriceAndAmount = [string, string];
24
-
25
- type PriceData = {
26
- bids: PriceAndAmount[];
27
- asks: PriceAndAmount[];
28
- };
29
-
30
- type PriceDataMap = {
31
- [network: string]: {
32
- [pair: string]: PriceData;
33
- };
34
- };
35
-
36
- type TokenDataMap = {
37
- [network: string]: {
38
- [token: string]: Token;
39
- };
40
- };
41
-
42
- type PairsDataMap = {
43
- [network: string]: {
44
- [token: string]: PairData;
45
- };
46
- };
47
-
48
- /**
49
- * Responses
50
- */
51
- export type CablesPricesResponse = {
52
- prices: PriceDataMap;
53
- };
54
- export type CablesBlacklistResponse = {
55
- blacklist: string[];
56
- };
57
- export type CablesTokensResponse = {
58
- tokens: TokenDataMap;
59
- };
60
- export type CablesPairsResponse = {
61
- pairs: PairsDataMap;
62
- };
63
-
64
- /**
65
- * Rate Fetcher
66
- */
67
- export type CablesRateFetcherConfig = {
68
- rateConfig: {
69
- pairsReqParams: {
70
- url: string;
71
- headers?: RequestHeaders;
72
- params?: any;
73
- };
74
- pricesReqParams: {
75
- url: string;
76
- headers?: RequestHeaders;
77
- params?: any;
78
- };
79
- blacklistReqParams: {
80
- url: string;
81
- headers?: RequestHeaders;
82
- params?: any;
83
- };
84
- tokensReqParams: {
85
- url: string;
86
- headers?: RequestHeaders;
87
- params?: any;
88
- };
89
- pairsIntervalMs: number;
90
- pricesIntervalMs: number;
91
- blacklistIntervalMs: number;
92
- tokensIntervalMs: number;
93
-
94
- pairsCacheKey: string;
95
- pricesCacheKey: string;
96
- blacklistCacheKey: string;
97
- tokensCacheKey: string;
98
-
99
- blacklistCacheTTLSecs: number;
100
- pairsCacheTTLSecs: number;
101
- pricesCacheTTLSecs: number;
102
- tokensCacheTTLSecs: number;
103
- };
104
- };
105
-
106
- export type RestrictData = {
107
- count: number;
108
- addedDatetimeMs: number;
109
- } | null;
110
-
111
- export class SlippageError extends Error {
112
- isSlippageError = true;
113
- }
@@ -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
- });