@paraswap/dex-lib 2.37.8-dexalot → 2.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/build/config.js +2 -4
  2. package/build/config.js.map +1 -1
  3. package/build/dex/gmx/config.js +1 -1
  4. package/build/dex/idex.d.ts +1 -1
  5. package/build/dex/index.js +0 -2
  6. package/build/dex/index.js.map +1 -1
  7. package/build/dex/uniswap-v2/config.js +22 -0
  8. package/build/dex/uniswap-v2/config.js.map +1 -1
  9. package/build/types.d.ts +0 -1
  10. package/package.json +1 -1
  11. package/src/config.ts +2 -5
  12. package/src/dex/gmx/config.ts +1 -1
  13. package/src/dex/idex.ts +0 -2
  14. package/src/dex/index.ts +0 -2
  15. package/src/dex/uniswap-v2/config.ts +23 -0
  16. package/src/types.ts +0 -1
  17. package/tests/constants-e2e.ts +2 -2
  18. package/.idea/aws.xml +0 -17
  19. package/.idea/codeStyles/Project.xml +0 -19
  20. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  21. package/.idea/misc.xml +0 -6
  22. package/.idea/modules.xml +0 -8
  23. package/.idea/paraswap-dex-lib.iml +0 -9
  24. package/.idea/vcs.xml +0 -6
  25. package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
  26. package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
  27. package/build/abi/dexalot/DexalotMainnetRFQ.json +0 -952
  28. package/build/abi/sushiswap-v3/QuoterV2.json +0 -267
  29. package/build/abi/sushiswap-v3/RouterProcessor3.json +0 -289
  30. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
  31. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
  32. package/build/abi/wBETH.json +0 -1527
  33. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  34. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  35. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  36. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  37. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  38. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  39. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  40. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  41. package/build/dex/balancer-v2/LinearMath.d.ts +0 -19
  42. package/build/dex/balancer-v2/LinearMath.js +0 -179
  43. package/build/dex/balancer-v2/LinearMath.js.map +0 -1
  44. package/build/dex/balancer-v2/LinearPool.d.ts +0 -47
  45. package/build/dex/balancer-v2/LinearPool.js +0 -324
  46. package/build/dex/balancer-v2/LinearPool.js.map +0 -1
  47. package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -47
  48. package/build/dex/balancer-v2/PhantomStablePool.js +0 -294
  49. package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
  50. package/build/dex/balancer-v2/StableMath.d.ts +0 -9
  51. package/build/dex/balancer-v2/StableMath.js +0 -272
  52. package/build/dex/balancer-v2/StableMath.js.map +0 -1
  53. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -75
  54. package/build/dex/balancer-v2/balancer-v2-pool.js +0 -417
  55. package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
  56. package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
  57. package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
  58. package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
  59. package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
  60. package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
  61. package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
  62. package/build/dex/dexalot/config.d.ts +0 -4
  63. package/build/dex/dexalot/config.js +0 -18
  64. package/build/dex/dexalot/config.js.map +0 -1
  65. package/build/dex/dexalot/constants.d.ts +0 -15
  66. package/build/dex/dexalot/constants.js +0 -22
  67. package/build/dex/dexalot/constants.js.map +0 -1
  68. package/build/dex/dexalot/dexalot.d.ts +0 -69
  69. package/build/dex/dexalot/dexalot.js +0 -642
  70. package/build/dex/dexalot/dexalot.js.map +0 -1
  71. package/build/dex/dexalot/rate-fetcher.d.ts +0 -28
  72. package/build/dex/dexalot/rate-fetcher.js +0 -100
  73. package/build/dex/dexalot/rate-fetcher.js.map +0 -1
  74. package/build/dex/dexalot/types.d.ts +0 -114
  75. package/build/dex/dexalot/types.js +0 -12
  76. package/build/dex/dexalot/types.js.map +0 -1
  77. package/build/dex/dexalot/validators.d.ts +0 -5
  78. package/build/dex/dexalot/validators.js +0 -45
  79. package/build/dex/dexalot/validators.js.map +0 -1
  80. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  81. package/build/dex/pancakeswap-v3/types.js +0 -3
  82. package/build/dex/pancakeswap-v3/types.js.map +0 -1
  83. package/build/dex/quickswap-v3.d.ts +0 -21
  84. package/build/dex/quickswap-v3.js +0 -40
  85. package/build/dex/quickswap-v3.js.map +0 -1
  86. package/build/dex/ramses-v2/config.d.ts +0 -4
  87. package/build/dex/ramses-v2/config.js +0 -28
  88. package/build/dex/ramses-v2/config.js.map +0 -1
  89. package/build/dex/ramses-v2/constants.d.ts +0 -28
  90. package/build/dex/ramses-v2/constants.js +0 -35
  91. package/build/dex/ramses-v2/constants.js.map +0 -1
  92. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
  93. package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
  94. package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
  95. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
  96. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
  97. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
  98. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
  99. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
  100. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
  101. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
  102. package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
  103. package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
  104. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
  105. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
  106. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
  107. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
  108. package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
  109. package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
  110. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
  111. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
  112. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
  113. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
  114. package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
  115. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
  116. package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
  117. package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
  118. package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
  119. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
  120. package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
  121. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
  122. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
  123. package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
  124. package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
  125. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
  126. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
  127. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
  128. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
  129. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
  130. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
  131. package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
  132. package/build/dex/ramses-v2/contract-math/utils.js +0 -16
  133. package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
  134. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
  135. package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
  136. package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
  137. package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
  138. package/build/dex/ramses-v2/ramses-v2.js +0 -690
  139. package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
  140. package/build/dex/ramses-v2/types.d.ts +0 -154
  141. package/build/dex/ramses-v2/types.js +0 -9
  142. package/build/dex/ramses-v2/types.js.map +0 -1
  143. package/build/dex/ramses-v2/utils.d.ts +0 -6
  144. package/build/dex/ramses-v2/utils.js +0 -71
  145. package/build/dex/ramses-v2/utils.js.map +0 -1
  146. package/build/dex/sushiswap-v3/config.d.ts +0 -4
  147. package/build/dex/sushiswap-v3/config.js +0 -132
  148. package/build/dex/sushiswap-v3/config.js.map +0 -1
  149. package/build/dex/sushiswap-v3/constants.d.ts +0 -4
  150. package/build/dex/sushiswap-v3/constants.js +0 -32
  151. package/build/dex/sushiswap-v3/constants.js.map +0 -1
  152. package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +0 -56
  153. package/build/dex/sushiswap-v3/sushiswap-v3-original.js +0 -598
  154. package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +0 -1
  155. package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +0 -1
  156. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +0 -6
  157. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +0 -1
  158. package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +0 -21
  159. package/build/dex/sushiswap-v3/sushiswap-v3.js +0 -58
  160. package/build/dex/sushiswap-v3/sushiswap-v3.js.map +0 -1
  161. package/build/dex/sushiswap-v3/token.d.ts +0 -6
  162. package/build/dex/sushiswap-v3/token.js +0 -23
  163. package/build/dex/sushiswap-v3/token.js.map +0 -1
  164. package/build/dex/sushiswap-v3/types.d.ts +0 -15
  165. package/build/dex/sushiswap-v3/types.js +0 -18
  166. package/build/dex/sushiswap-v3/types.js.map +0 -1
  167. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
  168. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
  169. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
  170. package/build/dex/woo-fi/config.d.ts +0 -4
  171. package/build/dex/woo-fi/config.js +0 -141
  172. package/build/dex/woo-fi/config.js.map +0 -1
  173. package/build/dex/woo-fi/constants.d.ts +0 -5
  174. package/build/dex/woo-fi/constants.js +0 -20
  175. package/build/dex/woo-fi/constants.js.map +0 -1
  176. package/build/dex/woo-fi/types.d.ts +0 -48
  177. package/build/dex/woo-fi/types.js +0 -3
  178. package/build/dex/woo-fi/types.js.map +0 -1
  179. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  180. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  181. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  182. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  183. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  184. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  185. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  186. package/build/dex/woo-fi/woo-fi.js +0 -480
  187. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  188. package/src/abi/dexalot/DexalotMainnetRFQ.json +0 -952
  189. package/src/dex/dexalot/config.ts +0 -18
  190. package/src/dex/dexalot/constants.ts +0 -29
  191. package/src/dex/dexalot/dexalot-e2e.test.ts +0 -192
  192. package/src/dex/dexalot/dexalot-integration.test.ts +0 -188
  193. package/src/dex/dexalot/dexalot.ts +0 -998
  194. package/src/dex/dexalot/rate-fetcher.ts +0 -197
  195. package/src/dex/dexalot/types.ts +0 -131
  196. package/src/dex/dexalot/validators.ts +0 -46
@@ -1,642 +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.Dexalot = void 0;
30
- const constants_1 = require("../../constants");
31
- const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
32
- const utils_1 = require("../../utils");
33
- const types_1 = require("./types");
34
- const types_2 = require("../generic-rfq/types");
35
- const simple_exchange_1 = require("../simple-exchange");
36
- const config_1 = require("./config");
37
- const rate_fetcher_1 = require("./rate-fetcher");
38
- const DexalotMainnetRFQ_json_1 = __importDefault(require("../../abi/dexalot/DexalotMainnetRFQ.json"));
39
- const utils_2 = require("ethers/lib/utils");
40
- const ts_essentials_1 = require("ts-essentials");
41
- const constants_2 = require("./constants");
42
- const bigint_constants_1 = require("../../bigint-constants");
43
- const ethers_1 = require("ethers");
44
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
45
- class Dexalot extends simple_exchange_1.SimpleExchange {
46
- constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}, mainnetRFQAddress = config_1.DexalotConfig['Dexalot'][network]
47
- .mainnetRFQAddress, rfqInterface = new utils_2.Interface(DexalotMainnetRFQ_json_1.default)) {
48
- super(dexHelper, dexKey);
49
- this.network = network;
50
- this.dexKey = dexKey;
51
- this.dexHelper = dexHelper;
52
- this.adapters = adapters;
53
- this.mainnetRFQAddress = mainnetRFQAddress;
54
- this.rfqInterface = rfqInterface;
55
- this.isStatePollingDex = true;
56
- this.hasConstantPriceLargeAmounts = false;
57
- this.needWrapNative = false;
58
- this.isFeeOnTransferSupported = false;
59
- this.tokensMap = {};
60
- this.logger = dexHelper.getLogger(dexKey);
61
- const authToken = dexHelper.config.data.dexalotAuthToken;
62
- (0, ts_essentials_1.assert)(authToken !== undefined, 'Dexalot auth token is not specified with env variable');
63
- this.dexalotAuthToken = authToken;
64
- this.pricesCacheKey = 'prices';
65
- this.pairsCacheKey = 'pairs';
66
- this.tokensAddrCacheKey = 'tokens_addr';
67
- this.tokensCacheKey = 'tokens';
68
- this.blacklistCacheKey = 'blacklist';
69
- this.rateFetcher = new rate_fetcher_1.RateFetcher(this.dexHelper, this.dexKey, this.network, this.logger, {
70
- rateConfig: {
71
- pairsIntervalMs: constants_2.DEXALOT_API_PAIRS_POLLING_INTERVAL_MS,
72
- pricesIntervalMs: constants_2.DEXALOT_API_PRICES_POLLING_INTERVAL_MS,
73
- blacklistIntervalMs: constants_2.DEXALOT_API_BLACKLIST_POLLING_INTERVAL_MS,
74
- pairsReqParams: this.getAPIReqParams('api/rfq/pairs', 'GET'),
75
- pricesReqParams: this.getAPIReqParams('api/rfq/prices', 'GET'),
76
- blacklistReqParams: this.getAPIReqParams('api/rfq/blacklist', 'GET'),
77
- pairsCacheKey: this.pairsCacheKey,
78
- pairsCacheTTLSecs: constants_2.DEXALOT_PAIRS_CACHES_TTL_S,
79
- pricesCacheKey: this.pricesCacheKey,
80
- pricesCacheTTLSecs: constants_2.DEXALOT_PRICES_CACHES_TTL_S,
81
- tokensAddrCacheKey: this.tokensAddrCacheKey,
82
- tokensCacheKey: this.tokensCacheKey,
83
- tokensCacheTTLSecs: constants_2.DEXALOT_TOKENS_CACHES_TTL_S,
84
- blacklistCacheKey: this.blacklistCacheKey,
85
- blacklistCacheTTLSecs: constants_2.DEXALOT_BLACKLIST_CACHES_TTL_S,
86
- },
87
- });
88
- }
89
- async initializePricing(blockNumber) {
90
- if (!this.dexHelper.config.isSlave) {
91
- this.rateFetcher.start();
92
- }
93
- return;
94
- }
95
- getAdapters(side) {
96
- return this.adapters[side] ? this.adapters[side] : null;
97
- }
98
- getPairString(baseToken, quoteToken) {
99
- return `${baseToken.symbol}/${quoteToken.symbol}`.toLowerCase();
100
- }
101
- async getPairData(srcToken, destToken) {
102
- const normalizedSrcToken = this.normalizeToken(srcToken);
103
- const normalizedDestToken = this.normalizeToken(destToken);
104
- if (normalizedSrcToken.address === normalizedDestToken.address) {
105
- return null;
106
- }
107
- const cachedTokens = (await this.getCachedTokens()) || {};
108
- if (!(normalizedSrcToken.address in cachedTokens) ||
109
- !(normalizedDestToken.address in cachedTokens)) {
110
- return null;
111
- }
112
- normalizedSrcToken.symbol = cachedTokens[normalizedSrcToken.address].symbol;
113
- normalizedDestToken.symbol =
114
- cachedTokens[normalizedDestToken.address].symbol;
115
- const cachedPairs = (await this.getCachedPairs()) || {};
116
- const potentialPairs = [
117
- {
118
- identifier: this.getPairString(normalizedSrcToken, normalizedDestToken),
119
- isSrcBase: true,
120
- },
121
- {
122
- identifier: this.getPairString(normalizedDestToken, normalizedSrcToken),
123
- isSrcBase: false,
124
- },
125
- ];
126
- for (const pair of potentialPairs) {
127
- if (pair.identifier in cachedPairs) {
128
- const pairData = cachedPairs[pair.identifier];
129
- pairData.isSrcBase = pair.isSrcBase;
130
- return pairData;
131
- }
132
- }
133
- return null;
134
- }
135
- getIdentifier(srcAddress, destAddress) {
136
- const sortedAddresses = srcAddress < destAddress
137
- ? [srcAddress, destAddress]
138
- : [destAddress, srcAddress];
139
- return `${this.dexKey}_${sortedAddresses[0].toLowerCase()}_${sortedAddresses[1].toLowerCase()}`;
140
- }
141
- async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
142
- if (!srcToken || !destToken) {
143
- return [];
144
- }
145
- const pairData = await this.getPairData(srcToken, destToken);
146
- if (!pairData) {
147
- return [];
148
- }
149
- const tokensAddr = (await this.getCachedTokensAddr()) || {};
150
- return [this.getIdentifier(tokensAddr[pairData.base.toLowerCase()], tokensAddr[pairData.quote.toLowerCase()])];
151
- }
152
- async getCachedPairs() {
153
- const cachedPairs = await this.dexHelper.cache.get(this.dexKey, this.network, this.pairsCacheKey);
154
- if (cachedPairs) {
155
- return JSON.parse(cachedPairs);
156
- }
157
- return null;
158
- }
159
- async getCachedPrices() {
160
- const cachedPrices = await this.dexHelper.cache.get(this.dexKey, this.network, this.pricesCacheKey);
161
- if (cachedPrices) {
162
- return JSON.parse(cachedPrices);
163
- }
164
- return null;
165
- }
166
- async getCachedTokensAddr() {
167
- const cachedTokensAddr = await this.dexHelper.cache.get(this.dexKey, this.network, this.tokensAddrCacheKey);
168
- if (cachedTokensAddr) {
169
- return JSON.parse(cachedTokensAddr);
170
- }
171
- return null;
172
- }
173
- async getCachedTokens() {
174
- const cachedTokens = await this.dexHelper.cache.get(this.dexKey, this.network, this.tokensCacheKey);
175
- if (cachedTokens) {
176
- return JSON.parse(cachedTokens);
177
- }
178
- return null;
179
- }
180
- normalizeAddress(address) {
181
- return address.toLowerCase() === constants_1.ETHER_ADDRESS
182
- ? constants_1.NULL_ADDRESS
183
- : address.toLowerCase();
184
- }
185
- denormalizeAddress(address) {
186
- return address.toLowerCase() === constants_1.NULL_ADDRESS
187
- ? constants_1.ETHER_ADDRESS
188
- : address.toLowerCase();
189
- }
190
- // Dexalot protocol for native token expects 0x00000... instead of 0xeeeee...
191
- normalizeToken(token) {
192
- return {
193
- address: this.normalizeAddress(token.address),
194
- decimals: token.decimals,
195
- };
196
- }
197
- denormalizeToken(token) {
198
- return {
199
- address: this.denormalizeAddress(token.address),
200
- decimals: token.decimals,
201
- };
202
- }
203
- calculateOrderPrice(amounts, orderbook, baseToken, quoteToken, side) {
204
- let result = [];
205
- for (let i = 0; i < amounts.length; i++) {
206
- let amt = amounts[i];
207
- if (amt === 0n) {
208
- result.push(amt);
209
- continue;
210
- }
211
- let left = 0, right = orderbook.length;
212
- let qty = BigInt(0);
213
- while (left < right) {
214
- let mid = Math.floor((left + right) / 2);
215
- qty = BigInt(ethers_1.ethers.utils
216
- .parseUnits(orderbook[mid][1], quoteToken.decimals)
217
- .toString());
218
- if (side === types_1.ClobSide.ASK) {
219
- const price = BigInt(ethers_1.ethers.utils
220
- .parseUnits(orderbook[mid][0], baseToken.decimals)
221
- .toString());
222
- qty =
223
- (qty * BigInt(10 ** (baseToken.decimals * 2))) /
224
- (price * BigInt(10 ** quoteToken.decimals));
225
- }
226
- if (qty <= amt) {
227
- left = mid + 1;
228
- }
229
- else {
230
- right = mid;
231
- }
232
- }
233
- let price, amount = BigInt(0);
234
- if (left === orderbook.length) {
235
- price = BigInt(ethers_1.ethers.utils
236
- .parseUnits(orderbook[left - 1][0], baseToken.decimals)
237
- .toString());
238
- amount = qty;
239
- }
240
- else if (amounts[i] === qty) {
241
- price = BigInt(ethers_1.ethers.utils
242
- .parseUnits(orderbook[left][0], baseToken.decimals)
243
- .toString());
244
- amount = amounts[i];
245
- }
246
- else {
247
- const lPrice = BigInt(ethers_1.ethers.utils
248
- .parseUnits(orderbook[left][0], baseToken.decimals)
249
- .toString());
250
- const rPrice = BigInt(ethers_1.ethers.utils
251
- .parseUnits(orderbook[left + 1][0], baseToken.decimals)
252
- .toString());
253
- const lQty = qty;
254
- let rQty = BigInt(ethers_1.ethers.utils
255
- .parseUnits(orderbook[left + 1][1], quoteToken.decimals)
256
- .toString());
257
- if (side === types_1.ClobSide.ASK) {
258
- rQty = (rQty * rPrice) / BigInt(10 ** quoteToken.decimals);
259
- }
260
- price = lPrice + ((rPrice - lPrice) * (amt - lQty)) / (rQty - lQty);
261
- amount = amounts[i];
262
- }
263
- if (side === types_1.ClobSide.BID) {
264
- result.push((amount * BigInt(10 ** (baseToken.decimals * 2))) /
265
- (price * BigInt(10 ** quoteToken.decimals)));
266
- }
267
- else {
268
- result.push((price * amount * BigInt(10 ** quoteToken.decimals)) /
269
- BigInt(10 ** (baseToken.decimals * 2)));
270
- }
271
- }
272
- return result;
273
- }
274
- async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools, transferFees) {
275
- try {
276
- if (await this.isRestricted()) {
277
- return null;
278
- }
279
- const normalizedSrcToken = this.normalizeToken(srcToken);
280
- const normalizedDestToken = this.normalizeToken(destToken);
281
- this.tokensMap = (await this.getCachedTokens()) || {};
282
- if (normalizedSrcToken.address === normalizedDestToken.address) {
283
- return null;
284
- }
285
- const pools = limitPools
286
- ? limitPools.filter(p => p ===
287
- this.getIdentifier(normalizedSrcToken.address, normalizedDestToken.address))
288
- : await this.getPoolIdentifiers(srcToken, destToken, side, blockNumber);
289
- if (pools.length === 0) {
290
- return null;
291
- }
292
- const pairData = await this.getPairData(normalizedSrcToken, normalizedDestToken);
293
- if (!pairData) {
294
- return null;
295
- }
296
- const priceMap = await this.getCachedPrices();
297
- if (!priceMap) {
298
- return null;
299
- }
300
- const tokensAddr = (await this.getCachedTokensAddr()) || {};
301
- const pairKey = `${pairData.base}/${pairData.quote}`.toLowerCase();
302
- if (!(pairKey in priceMap)
303
- || !pools.includes(this.getIdentifier(tokensAddr[pairData.base.toLowerCase()], tokensAddr[pairData.quote.toLowerCase()]))) {
304
- return null;
305
- }
306
- const priceData = priceMap[pairKey];
307
- const baseToken = pairData.isSrcBase
308
- ? normalizedSrcToken
309
- : normalizedDestToken;
310
- const quoteToken = pairData.isSrcBase
311
- ? normalizedDestToken
312
- : normalizedSrcToken;
313
- // convert from swap to clob side
314
- let orderbook = priceData.asks;
315
- let clobSide = types_1.ClobSide.BID;
316
- if ((side === constants_1.SwapSide.SELL && pairData.isSrcBase) ||
317
- (side === constants_1.SwapSide.BUY && !pairData.isSrcBase)) {
318
- orderbook = priceData.bids;
319
- clobSide = types_1.ClobSide.ASK;
320
- }
321
- if (orderbook.length === 0) {
322
- throw new Error(`Empty orderbook for ${pairKey}`);
323
- }
324
- const prices = this.calculateOrderPrice(amounts, orderbook, baseToken, quoteToken, clobSide);
325
- const outDecimals = clobSide === types_1.ClobSide.BID ? baseToken.decimals : quoteToken.decimals;
326
- const poolIdentifier = this.getIdentifier(pairData.base, pairData.quote);
327
- return [
328
- {
329
- prices,
330
- unit: BigInt(outDecimals),
331
- data: {},
332
- poolIdentifier: poolIdentifier,
333
- exchange: this.dexKey,
334
- gasCost: constants_2.DEXALOT_GAS_COST,
335
- poolAddresses: [this.mainnetRFQAddress],
336
- },
337
- ];
338
- }
339
- catch (e) {
340
- this.logger.error(`Error_getPricesVolume ${srcToken.address || srcToken.symbol}, ${destToken.address || destToken.symbol}, ${side}:`, e);
341
- return null;
342
- }
343
- }
344
- generateRFQError(errorStr, swapIdentifier) {
345
- const message = `${this.dexKey}-${this.network}: Failed to fetch RFQ for ${swapIdentifier}. ${errorStr}`;
346
- this.logger.warn(message);
347
- throw new types_1.DexalotRfqError(message);
348
- }
349
- async preProcessTransaction(optimalSwapExchange, srcToken, destToken, side, options) {
350
- if (await this.isBlacklisted(options.txOrigin)) {
351
- this.logger.warn(`${this.dexKey}-${this.network}: blacklisted TX Origin address '${options.txOrigin}' trying to build a transaction. Bailing...`);
352
- throw new Error(`${this.dexKey}-${this.network}: user=${options.txOrigin.toLowerCase()} is blacklisted`);
353
- }
354
- if (BigInt(optimalSwapExchange.srcAmount) === 0n) {
355
- throw new Error('getFirmRate failed with srcAmount === 0');
356
- }
357
- const normalizedSrcToken = this.normalizeToken(srcToken);
358
- const normalizedDestToken = this.normalizeToken(destToken);
359
- const swapIdentifier = `${this.getIdentifier(normalizedSrcToken.address, normalizedDestToken.address)}_${side}`;
360
- try {
361
- const makerToken = normalizedDestToken;
362
- const takerToken = normalizedSrcToken;
363
- const rfqParams = {
364
- makerAsset: ethers_1.ethers.utils.getAddress(makerToken.address),
365
- takerAsset: ethers_1.ethers.utils.getAddress(takerToken.address),
366
- makerAmount: side === constants_1.SwapSide.BUY ? optimalSwapExchange.destAmount : undefined,
367
- takerAmount: side === constants_1.SwapSide.SELL ? optimalSwapExchange.srcAmount : undefined,
368
- userAddress: options.txOrigin,
369
- chainid: this.network,
370
- };
371
- const rfq = await this.dexHelper.httpRequest.post(`${constants_2.DEXALOT_API_URL}/api/rfq/firm`, rfqParams, undefined, { 'x-apikey': this.dexalotAuthToken });
372
- if (!rfq) {
373
- this.generateRFQError('Missing quote data', `RFQ ${swapIdentifier} ${JSON.stringify(rfq)}`);
374
- }
375
- else if (!rfq.signature) {
376
- this.generateRFQError('Missing signature', swapIdentifier);
377
- }
378
- rfq.order.signature = rfq.signature;
379
- const { order } = rfq;
380
- (0, ts_essentials_1.assert)(order.makerAsset.toLowerCase() === makerToken.address, `QuoteData makerAsset=${order.makerAsset} is different from Paraswap makerAsset=${makerToken.address}`);
381
- (0, ts_essentials_1.assert)(order.takerAsset.toLowerCase() === takerToken.address, `QuoteData takerAsset=${order.takerAsset} is different from Paraswap takerAsset=${takerToken.address}`);
382
- if (side === constants_1.SwapSide.SELL) {
383
- (0, ts_essentials_1.assert)(order.takerAmount === optimalSwapExchange.srcAmount, `QuoteData takerAmount=${order.takerAmount} is different from Paraswap srcAmount=${optimalSwapExchange.srcAmount}`);
384
- }
385
- else {
386
- (0, ts_essentials_1.assert)(order.makerAmount === optimalSwapExchange.destAmount, `QuoteData makerAmount=${order.makerAmount} is different from Paraswap destAmount=${optimalSwapExchange.destAmount}`);
387
- }
388
- const expiryAsBigInt = BigInt(order.expiry);
389
- const minDeadline = expiryAsBigInt > 0 ? expiryAsBigInt : bigint_constants_1.BI_MAX_UINT256;
390
- const slippageFactor = options.slippageFactor;
391
- let isFailOnSlippage = false;
392
- let slippageErrorMessage = '';
393
- if (side === constants_1.SwapSide.SELL) {
394
- if (BigInt(order.makerAmount) <
395
- BigInt(new bignumber_js_1.default(optimalSwapExchange.destAmount.toString())
396
- .times(slippageFactor)
397
- .toFixed(0))) {
398
- isFailOnSlippage = true;
399
- const message = `${this.dexKey}-${this.network}: too much slippage on quote ${side} quoteTokenAmount ${order.makerAmount} / destAmount ${optimalSwapExchange.destAmount} < ${slippageFactor}`;
400
- slippageErrorMessage = message;
401
- this.logger.warn(message);
402
- }
403
- }
404
- else {
405
- if (BigInt(order.takerAmount) >
406
- BigInt(slippageFactor.times(optimalSwapExchange.srcAmount.toString()).toFixed(0))) {
407
- isFailOnSlippage = true;
408
- const message = `${this.dexKey}-${this.network}: too much slippage on quote ${side} baseTokenAmount ${order.takerAmount} / srcAmount ${optimalSwapExchange.srcAmount} > ${slippageFactor.toFixed()}`;
409
- slippageErrorMessage = message;
410
- this.logger.warn(message);
411
- }
412
- }
413
- let isTooStrictSlippage = false;
414
- if (isFailOnSlippage &&
415
- side === constants_1.SwapSide.SELL &&
416
- new bignumber_js_1.default(1)
417
- .minus(slippageFactor)
418
- .lt(constants_2.DEXALOT_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION)) {
419
- isTooStrictSlippage = true;
420
- }
421
- else if (isFailOnSlippage &&
422
- side === constants_1.SwapSide.BUY &&
423
- slippageFactor
424
- .minus(1)
425
- .lt(constants_2.DEXALOT_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION)) {
426
- isTooStrictSlippage = true;
427
- }
428
- if (isFailOnSlippage && isTooStrictSlippage) {
429
- throw new types_2.TooStrictSlippageCheckError(slippageErrorMessage);
430
- }
431
- else if (isFailOnSlippage && !isTooStrictSlippage) {
432
- throw new types_2.SlippageCheckError(slippageErrorMessage);
433
- }
434
- return [
435
- {
436
- ...optimalSwapExchange,
437
- data: {
438
- quoteData: order,
439
- },
440
- },
441
- { deadline: minDeadline },
442
- ];
443
- }
444
- catch (e) {
445
- if ((0, utils_1.isAxiosError)(e) && e.response && e.response.data) {
446
- const errorData = e.response.data;
447
- if (errorData.ReasonCode === 'FQ-009') {
448
- this.logger.warn(`${this.dexKey}-${this.network}: Encountered rate limited user=${options.txOrigin}. Adding to local rate limit cache`);
449
- await this.setRateLimited(options.txOrigin, errorData.RetryAfter);
450
- }
451
- else {
452
- await this.setBlacklist(options.txOrigin);
453
- this.logger.error(`${this.dexKey}-${this.network}: Failed to fetch RFQ for ${swapIdentifier}: ${errorData.Reason}`);
454
- }
455
- }
456
- else {
457
- if (e instanceof types_2.TooStrictSlippageCheckError) {
458
- this.logger.warn(`${this.dexKey}-${this.network}: failed to build transaction on side ${side} with too strict slippage. Skipping restriction`);
459
- }
460
- else {
461
- this.logger.warn(`${this.dexKey}-${this.network}: protocol is restricted`);
462
- await this.restrict();
463
- }
464
- }
465
- throw e;
466
- }
467
- }
468
- getCalldataGasCost(poolPrices) {
469
- return (CALLDATA_GAS_COST.DEX_OVERHEAD +
470
- // addresses: makerAsset, takerAsset, maker, taker
471
- CALLDATA_GAS_COST.ADDRESS * 4 +
472
- // uint256: expiry
473
- CALLDATA_GAS_COST.wordNonZeroBytes(16) +
474
- // uint256: nonceAndMeta, makerAmount, takerAmount
475
- CALLDATA_GAS_COST.AMOUNT * 3 +
476
- // bytes: _signature (65 bytes)
477
- CALLDATA_GAS_COST.FULL_WORD * 2 +
478
- CALLDATA_GAS_COST.OFFSET_SMALL);
479
- }
480
- getTokenFromAddress(address) {
481
- return this.tokensMap[this.normalizeAddress(address)];
482
- }
483
- getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
484
- const { quoteData } = data;
485
- (0, ts_essentials_1.assert)(quoteData !== undefined, `${this.dexKey}-${this.network}: quoteData undefined`);
486
- const params = [
487
- {
488
- nonceAndMeta: quoteData.nonceAndMeta,
489
- expiry: quoteData.expiry,
490
- makerAsset: quoteData.makerAsset,
491
- takerAsset: quoteData.takerAsset,
492
- maker: quoteData.maker,
493
- taker: quoteData.taker,
494
- makerAmount: quoteData.makerAmount,
495
- takerAmount: quoteData.takerAmount,
496
- },
497
- quoteData.signature,
498
- ];
499
- const payload = this.abiCoder.encodeParameter({
500
- ParentStruct: {
501
- order: {
502
- nonceAndMeta: 'uint256',
503
- expiry: 'uint128',
504
- makerAsset: 'address',
505
- takerAsset: 'address',
506
- maker: 'address',
507
- taker: 'address',
508
- makerAmount: 'uint256',
509
- takerAmount: 'uint256',
510
- },
511
- signature: 'bytes',
512
- },
513
- }, {
514
- order: params[0],
515
- signature: params[1],
516
- });
517
- return {
518
- targetExchange: this.mainnetRFQAddress,
519
- payload,
520
- networkFee: '0',
521
- };
522
- }
523
- async restrict(ttl = constants_2.DEXALOT_RESTRICT_TTL_S) {
524
- await this.dexHelper.cache.setex(this.dexKey, this.network, constants_2.DEXALOT_RESTRICTED_CACHE_KEY, ttl, 'true');
525
- return true;
526
- }
527
- async isRestricted() {
528
- const result = await this.dexHelper.cache.get(this.dexKey, this.network, constants_2.DEXALOT_RESTRICTED_CACHE_KEY);
529
- return result === 'true';
530
- }
531
- async setBlacklist(txOrigin, ttl = constants_2.DEXALOT_BLACKLIST_CACHES_TTL_S) {
532
- const cachedBlacklist = await this.dexHelper.cache.get(this.dexKey, this.network, this.blacklistCacheKey);
533
- let blacklist = [];
534
- if (cachedBlacklist) {
535
- blacklist = JSON.parse(cachedBlacklist);
536
- }
537
- blacklist.push(txOrigin.toLowerCase());
538
- this.dexHelper.cache.setex(this.dexKey, this.network, this.blacklistCacheKey, ttl, JSON.stringify(blacklist));
539
- return true;
540
- }
541
- async isBlacklisted(txOrigin) {
542
- const cachedBlacklist = await this.dexHelper.cache.get(this.dexKey, this.network, this.blacklistCacheKey);
543
- if (cachedBlacklist) {
544
- const blacklist = JSON.parse(cachedBlacklist);
545
- return blacklist.includes(txOrigin.toLowerCase());
546
- }
547
- // To not show pricing for rate limited users
548
- if (await this.isRateLimited(txOrigin)) {
549
- return true;
550
- }
551
- return false;
552
- }
553
- getRateLimitedKey(address) {
554
- return `rate_limited_${address}`.toLowerCase();
555
- }
556
- async isRateLimited(txOrigin) {
557
- const result = await this.dexHelper.cache.get(this.dexKey, this.network, this.getRateLimitedKey(txOrigin));
558
- return result === constants_2.DEXALOT_RATELIMIT_CACHE_VALUE;
559
- }
560
- async setRateLimited(txOrigin, ttl = constants_2.DEXALOT_RATE_LIMITED_TTL_S) {
561
- await this.dexHelper.cache.setex(this.dexKey, this.network, this.getRateLimitedKey(txOrigin), ttl, constants_2.DEXALOT_RATELIMIT_CACHE_VALUE);
562
- return true;
563
- }
564
- async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
565
- const { quoteData } = data;
566
- (0, ts_essentials_1.assert)(quoteData !== undefined, `${this.dexKey}-${this.network}: quoteData undefined`);
567
- const swapFunction = 'simpleSwap';
568
- const swapFunctionParams = [
569
- [
570
- quoteData.nonceAndMeta,
571
- quoteData.expiry,
572
- quoteData.makerAsset,
573
- quoteData.takerAsset,
574
- quoteData.maker,
575
- quoteData.taker,
576
- quoteData.makerAmount,
577
- quoteData.takerAmount,
578
- ],
579
- quoteData.signature,
580
- ];
581
- const swapData = this.rfqInterface.encodeFunctionData(swapFunction, swapFunctionParams);
582
- return this.buildSimpleParamWithoutWETHConversion(srcToken, srcAmount, destToken, destAmount, swapData, this.mainnetRFQAddress);
583
- }
584
- async getTopPoolsForToken(tokenAddress, limit) {
585
- const normalizedTokenAddress = this.normalizeAddress(tokenAddress);
586
- const pairs = (await this.getCachedPairs()) || {};
587
- this.tokensMap = (await this.getCachedTokens()) || {};
588
- const tokensAddr = (await this.getCachedTokensAddr()) || {};
589
- const token = this.getTokenFromAddress(normalizedTokenAddress);
590
- if (!token) {
591
- return [];
592
- }
593
- const tokenSymbol = token.symbol?.toLowerCase() || '';
594
- let pairsByLiquidity = [];
595
- for (const pairName of Object.keys(pairs)) {
596
- if (!pairName.includes(tokenSymbol)) {
597
- continue;
598
- }
599
- const tokensInPair = pairName.split('/');
600
- if (tokensInPair.length !== 2) {
601
- continue;
602
- }
603
- const [baseToken, quoteToken] = tokensInPair;
604
- const addr = tokensAddr[baseToken.toLowerCase()];
605
- let outputToken = this.getTokenFromAddress(addr);
606
- if (baseToken === tokenSymbol) {
607
- const addr = tokensAddr[quoteToken.toLowerCase()];
608
- outputToken = this.getTokenFromAddress(addr);
609
- }
610
- const denormalizedToken = this.denormalizeToken(outputToken);
611
- pairsByLiquidity.push({
612
- exchange: this.dexKey,
613
- address: this.mainnetRFQAddress,
614
- connectorTokens: [{
615
- address: denormalizedToken.address,
616
- decimals: denormalizedToken.decimals,
617
- }],
618
- liquidityUSD: pairs[pairName].liquidityUSD,
619
- });
620
- }
621
- pairsByLiquidity.sort((a, b) => b.liquidityUSD - a.liquidityUSD);
622
- return pairsByLiquidity.slice(0, limit);
623
- }
624
- getAPIReqParams(endpoint, method) {
625
- return {
626
- url: `${constants_2.DEXALOT_API_URL}/${endpoint}`,
627
- headers: { 'x-apikey': this.dexalotAuthToken },
628
- params: {
629
- chainid: this.network,
630
- },
631
- method: method,
632
- };
633
- }
634
- releaseResources() {
635
- if (this.rateFetcher) {
636
- this.rateFetcher.stop();
637
- }
638
- }
639
- }
640
- exports.Dexalot = Dexalot;
641
- Dexalot.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.DexalotConfig);
642
- //# sourceMappingURL=dexalot.js.map