@paraswap/dex-lib 3.7.2 → 3.7.3-idle.2

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 (251) hide show
  1. package/build/abi/Redstone.json +739 -0
  2. package/build/abi/aavev3stata/Factory.json +128 -0
  3. package/build/abi/aavev3stata/Token.json +735 -0
  4. package/build/abi/angle-transmuter/MorphoOracle.json +193 -0
  5. package/build/abi/angle-transmuter/MorphoVault.json +2506 -0
  6. package/build/abi/angle-transmuter/Pyth.json +1534 -0
  7. package/build/abi/angle-transmuter/Transmuter.json +1711 -0
  8. package/build/abi/angle-transmuter/TransmuterSidechain.json +1798 -0
  9. package/build/abi/idle-dao/idle-cdo-factory.json +38 -0
  10. package/build/abi/idle-dao/idle-cdo.json +1245 -0
  11. package/build/config.js +2 -0
  12. package/build/config.js.map +1 -1
  13. package/build/dex/aave-v1/aave-v1.d.ts +2 -1
  14. package/build/dex/aave-v1/aave-v1.js +22 -0
  15. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  16. package/build/dex/aave-v3-stata/aave-v3-stata.d.ts +50 -0
  17. package/build/dex/aave-v3-stata/aave-v3-stata.js +390 -0
  18. package/build/dex/aave-v3-stata/aave-v3-stata.js.map +1 -0
  19. package/build/dex/aave-v3-stata/config.d.ts +4 -0
  20. package/build/dex/aave-v3-stata/config.js +50 -0
  21. package/build/dex/aave-v3-stata/config.js.map +1 -0
  22. package/build/dex/aave-v3-stata/tokens.d.ts +10 -0
  23. package/build/dex/aave-v3-stata/tokens.js +43 -0
  24. package/build/dex/aave-v3-stata/tokens.js.map +1 -0
  25. package/build/dex/aave-v3-stata/types.d.ts +46 -0
  26. package/build/dex/aave-v3-stata/types.js +23 -0
  27. package/build/dex/aave-v3-stata/types.js.map +1 -0
  28. package/build/dex/aave-v3-stata/utils.d.ts +4 -0
  29. package/build/dex/aave-v3-stata/utils.js +67 -0
  30. package/build/dex/aave-v3-stata/utils.js.map +1 -0
  31. package/build/dex/angle-transmuter/angle-transmuter-pool.d.ts +67 -0
  32. package/build/dex/angle-transmuter/angle-transmuter-pool.js +448 -0
  33. package/build/dex/angle-transmuter/angle-transmuter-pool.js.map +1 -0
  34. package/build/dex/angle-transmuter/angle-transmuter.d.ts +59 -0
  35. package/build/dex/angle-transmuter/angle-transmuter.js +264 -0
  36. package/build/dex/angle-transmuter/angle-transmuter.js.map +1 -0
  37. package/build/dex/angle-transmuter/backedOracle.d.ts +19 -0
  38. package/build/dex/angle-transmuter/backedOracle.js +56 -0
  39. package/build/dex/angle-transmuter/backedOracle.js.map +1 -0
  40. package/build/dex/angle-transmuter/config.d.ts +4 -0
  41. package/build/dex/angle-transmuter/config.js +50 -0
  42. package/build/dex/angle-transmuter/config.js.map +1 -0
  43. package/build/dex/angle-transmuter/constants.d.ts +9 -0
  44. package/build/dex/angle-transmuter/constants.js +136 -0
  45. package/build/dex/angle-transmuter/constants.js.map +1 -0
  46. package/build/dex/angle-transmuter/morphoOracle.d.ts +42 -0
  47. package/build/dex/angle-transmuter/morphoOracle.js +179 -0
  48. package/build/dex/angle-transmuter/morphoOracle.js.map +1 -0
  49. package/build/dex/angle-transmuter/morphoVault.d.ts +20 -0
  50. package/build/dex/angle-transmuter/morphoVault.js +84 -0
  51. package/build/dex/angle-transmuter/morphoVault.js.map +1 -0
  52. package/build/dex/angle-transmuter/pyth.d.ts +19 -0
  53. package/build/dex/angle-transmuter/pyth.js +70 -0
  54. package/build/dex/angle-transmuter/pyth.js.map +1 -0
  55. package/build/dex/angle-transmuter/redstone.d.ts +20 -0
  56. package/build/dex/angle-transmuter/redstone.js +64 -0
  57. package/build/dex/angle-transmuter/redstone.js.map +1 -0
  58. package/build/dex/angle-transmuter/transmuter.d.ts +55 -0
  59. package/build/dex/angle-transmuter/transmuter.js +398 -0
  60. package/build/dex/angle-transmuter/transmuter.js.map +1 -0
  61. package/build/dex/angle-transmuter/types.d.ts +189 -0
  62. package/build/dex/angle-transmuter/types.js +33 -0
  63. package/build/dex/angle-transmuter/types.js.map +1 -0
  64. package/build/dex/angle-transmuter/utils.d.ts +9 -0
  65. package/build/dex/angle-transmuter/utils.js +257 -0
  66. package/build/dex/angle-transmuter/utils.js.map +1 -0
  67. package/build/dex/idle-dao/config.d.ts +6 -0
  68. package/build/dex/idle-dao/config.js +307 -0
  69. package/build/dex/idle-dao/config.js.map +1 -0
  70. package/build/dex/idle-dao/idle-dao-pool.d.ts +56 -0
  71. package/build/dex/idle-dao/idle-dao-pool.js +176 -0
  72. package/build/dex/idle-dao/idle-dao-pool.js.map +1 -0
  73. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +16 -0
  74. package/build/dex/idle-dao/idle-dao-pooling-pool.js +57 -0
  75. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +1 -0
  76. package/build/dex/idle-dao/idle-dao.d.ts +41 -0
  77. package/build/dex/idle-dao/idle-dao.js +236 -0
  78. package/build/dex/idle-dao/idle-dao.js.map +1 -0
  79. package/build/dex/idle-dao/scripts.d.ts +9 -0
  80. package/build/dex/idle-dao/scripts.js +552 -0
  81. package/build/dex/idle-dao/scripts.js.map +1 -0
  82. package/build/dex/idle-dao/tokens.d.ts +9 -0
  83. package/build/dex/idle-dao/tokens.js +65 -0
  84. package/build/dex/idle-dao/tokens.js.map +1 -0
  85. package/build/dex/idle-dao/types.d.ts +35 -0
  86. package/build/dex/idle-dao/types.js +11 -0
  87. package/build/dex/idle-dao/types.js.map +1 -0
  88. package/build/dex/idle-dao/utils.d.ts +8 -0
  89. package/build/dex/idle-dao/utils.js +148 -0
  90. package/build/dex/idle-dao/utils.js.map +1 -0
  91. package/build/dex/index.js +4 -0
  92. package/build/dex/index.js.map +1 -1
  93. package/build/dex/platypus/platypus.d.ts +2 -1
  94. package/build/dex/platypus/platypus.js +31 -0
  95. package/build/dex/platypus/platypus.js.map +1 -1
  96. package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
  97. package/build/dex/swaap-v1/swaap-v1.js +10 -0
  98. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  99. package/build/lib/chainlink.d.ts +2 -0
  100. package/build/lib/chainlink.js +9 -0
  101. package/build/lib/chainlink.js.map +1 -1
  102. package/build/types.d.ts +1 -0
  103. package/build/utils.d.ts +1 -1
  104. package/package.json +1 -1
  105. package/src/abi/Redstone.json +739 -0
  106. package/src/abi/angle-transmuter/ChainlinkAccessControlledOffchainAggregator.json +1246 -0
  107. package/src/abi/angle-transmuter/ChainlinkEACAggregatorProxy.json +509 -0
  108. package/src/abi/angle-transmuter/MorphoOracle.json +193 -0
  109. package/src/abi/angle-transmuter/MorphoVault.json +2506 -0
  110. package/src/abi/angle-transmuter/Pyth.json +1534 -0
  111. package/src/abi/angle-transmuter/Transmuter.json +1711 -0
  112. package/src/abi/angle-transmuter/TransmuterSidechain.json +1798 -0
  113. package/src/abi/idle-dao/idle-cdo-factory.json +38 -0
  114. package/src/abi/idle-dao/idle-cdo.json +1245 -0
  115. package/src/config.ts +3 -0
  116. package/src/dex/angle-transmuter/angle-transmuter-e2e.test.ts +156 -0
  117. package/src/dex/angle-transmuter/angle-transmuter-events.test.ts +365 -0
  118. package/src/dex/angle-transmuter/angle-transmuter-integration.test.ts +390 -0
  119. package/src/dex/angle-transmuter/angle-transmuter-pool.ts +895 -0
  120. package/src/dex/angle-transmuter/angle-transmuter.ts +408 -0
  121. package/src/dex/angle-transmuter/backedOracle.ts +91 -0
  122. package/src/dex/angle-transmuter/config.ts +50 -0
  123. package/src/dex/angle-transmuter/constants.ts +138 -0
  124. package/src/dex/angle-transmuter/morphoOracle.ts +335 -0
  125. package/src/dex/angle-transmuter/morphoVault.ts +134 -0
  126. package/src/dex/angle-transmuter/pyth.ts +105 -0
  127. package/src/dex/angle-transmuter/redstone.ts +105 -0
  128. package/src/dex/angle-transmuter/transmuter.ts +619 -0
  129. package/src/dex/angle-transmuter/types.ts +203 -0
  130. package/src/dex/angle-transmuter/utils.ts +358 -0
  131. package/src/dex/idle-dao/config.ts +309 -0
  132. package/src/dex/idle-dao/idle-dao-e2e.test.ts +112 -0
  133. package/src/dex/idle-dao/idle-dao-integration.test.ts +155 -0
  134. package/src/dex/idle-dao/idle-dao.ts +361 -0
  135. package/src/dex/idle-dao/scripts.ts +553 -0
  136. package/src/dex/idle-dao/tokens.ts +90 -0
  137. package/src/dex/idle-dao/types.ts +43 -0
  138. package/src/dex/idle-dao/utils.ts +215 -0
  139. package/src/dex/index.ts +4 -0
  140. package/src/lib/chainlink.ts +15 -0
  141. package/src/types.ts +1 -0
  142. package/tests/constants-e2e.ts +117 -6
  143. package/build/abi/Uncompressor.json +0 -250
  144. package/build/dex/bProtocol.d.ts +0 -18
  145. package/build/dex/bProtocol.js +0 -39
  146. package/build/dex/bProtocol.js.map +0 -1
  147. package/build/dex/bancor.d.ts +0 -26
  148. package/build/dex/bancor.js +0 -58
  149. package/build/dex/bancor.js.map +0 -1
  150. package/build/dex/compound.d.ts +0 -18
  151. package/build/dex/compound.js +0 -46
  152. package/build/dex/compound.js.map +0 -1
  153. package/build/dex/curve-v2.d.ts +0 -58
  154. package/build/dex/curve-v2.js +0 -180
  155. package/build/dex/curve-v2.js.map +0 -1
  156. package/build/dex/dodo-v1.d.ts +0 -33
  157. package/build/dex/dodo-v1.js +0 -63
  158. package/build/dex/dodo-v1.js.map +0 -1
  159. package/build/dex/etherfi/etherfi.d.ts +0 -26
  160. package/build/dex/etherfi/etherfi.js +0 -96
  161. package/build/dex/etherfi/etherfi.js.map +0 -1
  162. package/build/dex/lido.d.ts +0 -19
  163. package/build/dex/lido.js +0 -42
  164. package/build/dex/lido.js.map +0 -1
  165. package/build/dex/onebit.d.ts +0 -25
  166. package/build/dex/onebit.js +0 -42
  167. package/build/dex/onebit.js.map +0 -1
  168. package/build/dex/sdai/config.d.ts +0 -11
  169. package/build/dex/sdai/config.js +0 -21
  170. package/build/dex/sdai/config.js.map +0 -1
  171. package/build/dex/sdai/constants.d.ts +0 -2
  172. package/build/dex/sdai/constants.js +0 -6
  173. package/build/dex/sdai/constants.js.map +0 -1
  174. package/build/dex/sdai/scripts/validate-state.d.ts +0 -1
  175. package/build/dex/sdai/scripts/validate-state.js +0 -102
  176. package/build/dex/sdai/scripts/validate-state.js.map +0 -1
  177. package/build/dex/sdai/sdai-pool.d.ts +0 -16
  178. package/build/dex/sdai/sdai-pool.js +0 -85
  179. package/build/dex/sdai/sdai-pool.js.map +0 -1
  180. package/build/dex/sdai/sdai.d.ts +0 -51
  181. package/build/dex/sdai/sdai.js +0 -172
  182. package/build/dex/sdai/sdai.js.map +0 -1
  183. package/build/dex/sdai/types.d.ts +0 -21
  184. package/build/dex/sdai/types.js +0 -11
  185. package/build/dex/sdai/types.js.map +0 -1
  186. package/build/dex/sdai/utils.d.ts +0 -4
  187. package/build/dex/sdai/utils.js +0 -39
  188. package/build/dex/sdai/utils.js.map +0 -1
  189. package/build/dex/smoothy.d.ts +0 -26
  190. package/build/dex/smoothy.js +0 -48
  191. package/build/dex/smoothy.js.map +0 -1
  192. package/build/dex/stable-pool.d.ts +0 -28
  193. package/build/dex/stable-pool.js +0 -62
  194. package/build/dex/stable-pool.js.map +0 -1
  195. package/build/dex/trader-joe-v2.1.d.ts +0 -43
  196. package/build/dex/trader-joe-v2.1.js +0 -79
  197. package/build/dex/trader-joe-v2.1.js.map +0 -1
  198. package/build/executor/compressor/Compressor.d.ts +0 -23
  199. package/build/executor/compressor/Compressor.js +0 -144
  200. package/build/executor/compressor/Compressor.js.map +0 -1
  201. package/build/executor/compressor/compress.d.ts +0 -17
  202. package/build/executor/compressor/compress.js +0 -187
  203. package/build/executor/compressor/compress.js.map +0 -1
  204. package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +0 -6
  205. package/build/executor/compressor/compress_functions/addressSubstitution.js +0 -29
  206. package/build/executor/compressor/compress_functions/addressSubstitution.js.map +0 -1
  207. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +0 -10
  208. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +0 -40
  209. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +0 -1
  210. package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +0 -11
  211. package/build/executor/compressor/compress_functions/byteSubstitution.js +0 -64
  212. package/build/executor/compressor/compress_functions/byteSubstitution.js.map +0 -1
  213. package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +0 -7
  214. package/build/executor/compressor/compress_functions/ffSubstitution.js +0 -54
  215. package/build/executor/compressor/compress_functions/ffSubstitution.js.map +0 -1
  216. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +0 -8
  217. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +0 -67
  218. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +0 -1
  219. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +0 -8
  220. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +0 -61
  221. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +0 -1
  222. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +0 -6
  223. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +0 -37
  224. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +0 -1
  225. package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +0 -9
  226. package/build/executor/compressor/compress_functions/searchUnusedBytes.js +0 -33
  227. package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +0 -1
  228. package/build/executor/compressor/fetchSaved.d.ts +0 -0
  229. package/build/executor/compressor/fetchSaved.js +0 -17
  230. package/build/executor/compressor/fetchSaved.js.map +0 -1
  231. package/build/executor/compressor/utils/computeCostL2.d.ts +0 -2
  232. package/build/executor/compressor/utils/computeCostL2.js +0 -14
  233. package/build/executor/compressor/utils/computeCostL2.js.map +0 -1
  234. package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +0 -2
  235. package/build/executor/compressor/utils/findLongestDuplicatedString.js +0 -30
  236. package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +0 -1
  237. package/build/executor/compressor/utils/getAllIndexes.d.ts +0 -2
  238. package/build/executor/compressor/utils/getAllIndexes.js +0 -12
  239. package/build/executor/compressor/utils/getAllIndexes.js.map +0 -1
  240. package/build/executor/compressor/utils/getByteForAddress.d.ts +0 -2
  241. package/build/executor/compressor/utils/getByteForAddress.js +0 -14
  242. package/build/executor/compressor/utils/getByteForAddress.js.map +0 -1
  243. package/build/executor/compressor/utils/intTo2Bytes.d.ts +0 -2
  244. package/build/executor/compressor/utils/intTo2Bytes.js +0 -14
  245. package/build/executor/compressor/utils/intTo2Bytes.js.map +0 -1
  246. package/build/executor/compressor/utils/intTo3Bytes.d.ts +0 -2
  247. package/build/executor/compressor/utils/intTo3Bytes.js +0 -18
  248. package/build/executor/compressor/utils/intTo3Bytes.js.map +0 -1
  249. package/build/executor/compressor/utils/intToByte.d.ts +0 -2
  250. package/build/executor/compressor/utils/intToByte.js +0 -10
  251. package/build/executor/compressor/utils/intToByte.js.map +0 -1
@@ -0,0 +1,361 @@
1
+ import { assert } from 'ts-essentials';
2
+ import { Interface } from '@ethersproject/abi';
3
+ import {
4
+ Token,
5
+ Address,
6
+ ExchangePrices,
7
+ PoolPrices,
8
+ AdapterExchangeParam,
9
+ PoolLiquidity,
10
+ Logger,
11
+ NumberAsString,
12
+ DexExchangeParam,
13
+ } from '../../types';
14
+ import { SwapSide, Network, NULL_ADDRESS } from '../../constants';
15
+ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
16
+ import { getDexKeysWithNetwork, getBigIntPow } from '../../utils';
17
+ import { Context, IDex } from '../../dex/idex';
18
+ import { IDexHelper } from '../../dex-helper/idex-helper';
19
+ import { IdleDaoData, Param, PoolFunctions, IdleToken } from './types';
20
+ import { SimpleExchange } from '../simple-exchange';
21
+ import { Config, Adapters } from './config';
22
+ import { fetchTokenList_api } from './utils';
23
+ import {
24
+ getIdleTokenIfIdleDaoPair,
25
+ setTokensOnNetwork,
26
+ getPoolsByTokenAddress,
27
+ getTokenFromIdleToken,
28
+ } from './tokens';
29
+ import FACTORY_ABI from '../../abi/idle-dao/idle-cdo-factory.json';
30
+ import CDO_ABI from '../../abi/idle-dao/idle-cdo.json';
31
+
32
+ export const TOKEN_LIST_CACHE_KEY = 'token-list';
33
+ const TOKEN_LIST_TTL_SECONDS = 24 * 60 * 60;
34
+ const TOKEN_LIST_LOCAL_TTL_SECONDS = 3 * 60 * 60;
35
+
36
+ export class IdleDao extends SimpleExchange implements IDex<IdleDaoData> {
37
+ readonly hasConstantPriceLargeAmounts = false;
38
+ readonly needWrapNative = true;
39
+
40
+ readonly isFeeOnTransferSupported = false;
41
+
42
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
43
+ getDexKeysWithNetwork(Config);
44
+
45
+ logger: Logger;
46
+
47
+ private cdo: Interface;
48
+ private factory: Interface;
49
+
50
+ private tokenList: IdleToken[] = [];
51
+ private idleDaoAuthToken: string;
52
+
53
+ constructor(
54
+ readonly network: Network,
55
+ readonly dexKey: string,
56
+ readonly dexHelper: IDexHelper,
57
+ protected config = Config[dexKey][network],
58
+ protected adapters = Adapters[network] || {},
59
+ ) {
60
+ super(dexHelper, dexKey);
61
+ this.logger = dexHelper.getLogger(dexKey);
62
+ this.cdo = new Interface(CDO_ABI);
63
+ this.factory = new Interface(FACTORY_ABI);
64
+
65
+ const idleDaoAuthToken = dexHelper.config.data.idleDaoAuthToken;
66
+ assert(
67
+ idleDaoAuthToken !== undefined,
68
+ 'idleDaoAuthToken auth token is not specified with env variable',
69
+ );
70
+
71
+ this.idleDaoAuthToken = idleDaoAuthToken;
72
+ }
73
+
74
+ async getTokensList(blockNumber: number): Promise<Record<string, IdleToken>> {
75
+ if (!this.tokenList) {
76
+ this.tokenList = await fetchTokenList_api(
77
+ this.network,
78
+ this.dexHelper,
79
+ blockNumber,
80
+ this.cdo,
81
+ this.erc20Interface,
82
+ this.dexHelper.multiWrapper,
83
+ this.idleDaoAuthToken,
84
+ );
85
+ }
86
+
87
+ return this.tokenList.reduce(
88
+ (acc: Record<string, IdleToken>, idleToken: IdleToken) => {
89
+ return {
90
+ ...acc,
91
+ [idleToken.idleAddress]: idleToken,
92
+ };
93
+ },
94
+ {},
95
+ );
96
+ }
97
+
98
+ async initializePricing(blockNumber: number) {
99
+ let cachedTokenList = await this.dexHelper.cache.get(
100
+ this.dexKey,
101
+ this.network,
102
+ TOKEN_LIST_CACHE_KEY,
103
+ );
104
+
105
+ if (cachedTokenList !== null) {
106
+ const tokens: IdleToken[] = JSON.parse(cachedTokenList);
107
+ setTokensOnNetwork(this.network, tokens, this.dexHelper);
108
+
109
+ this.tokenList = tokens;
110
+ return;
111
+ }
112
+
113
+ this.tokenList = await fetchTokenList_api(
114
+ this.network,
115
+ this.dexHelper,
116
+ blockNumber,
117
+ this.cdo,
118
+ this.erc20Interface,
119
+ this.dexHelper.multiWrapper,
120
+ this.idleDaoAuthToken,
121
+ );
122
+
123
+ await this.dexHelper.cache.setex(
124
+ this.dexKey,
125
+ this.network,
126
+ TOKEN_LIST_CACHE_KEY,
127
+ TOKEN_LIST_TTL_SECONDS,
128
+ JSON.stringify(this.tokenList),
129
+ );
130
+
131
+ setTokensOnNetwork(this.network, this.tokenList, this.dexHelper);
132
+ }
133
+
134
+ getAdapters(side: SwapSide): { name: string; index: number }[] | null {
135
+ return this.adapters[side] ? this.adapters[side] : null;
136
+ }
137
+
138
+ private _getPoolIdentifier(srcToken: Token, destToken: Token): string {
139
+ return (
140
+ this.dexKey +
141
+ [srcToken.address.toLowerCase(), destToken.address.toLowerCase()]
142
+ .sort((a, b) => (a > b ? 1 : -1))
143
+ .join('_')
144
+ );
145
+ }
146
+
147
+ async getPoolIdentifiers(
148
+ srcToken: Token,
149
+ destToken: Token,
150
+ ): Promise<string[]> {
151
+ const idleToken = getIdleTokenIfIdleDaoPair(
152
+ this.network,
153
+ this.dexHelper.config.wrapETH(srcToken),
154
+ this.dexHelper.config.wrapETH(destToken),
155
+ );
156
+
157
+ if (idleToken === null) return [];
158
+
159
+ return [this._getPoolIdentifier(srcToken, destToken)];
160
+ }
161
+
162
+ async getPricesVolume(
163
+ srcToken: Token,
164
+ destToken: Token,
165
+ amounts: bigint[],
166
+ side: SwapSide,
167
+ blockNumber: number,
168
+ limitPools?: string[],
169
+ ): Promise<null | ExchangePrices<IdleDaoData>> {
170
+ try {
171
+ const _src = this.dexHelper.config.wrapETH(srcToken);
172
+ const _dst = this.dexHelper.config.wrapETH(destToken);
173
+
174
+ // Look for idleToken
175
+ const idleToken = getIdleTokenIfIdleDaoPair(this.network, _src, _dst);
176
+ if (!idleToken) {
177
+ return null;
178
+ }
179
+
180
+ const fromIdleToken =
181
+ idleToken.idleAddress.toLowerCase() == _src.address.toLowerCase();
182
+
183
+ const tokenPrice = await this.getTokenPrice(idleToken, blockNumber);
184
+
185
+ if (!tokenPrice) {
186
+ return null;
187
+ }
188
+
189
+ const unitVolume = getBigIntPow(
190
+ (side === SwapSide.SELL ? srcToken : destToken).decimals,
191
+ );
192
+
193
+ const prices = [unitVolume, ...amounts].map((amount: bigint) => {
194
+ let output = 0;
195
+ if (side === SwapSide.SELL) {
196
+ // SELL idleToken (amount = 1000000000000000000 AA_idle_cpPOR-USDC, output = 1000000000000000000*tokenPrice/1e18)
197
+ if (fromIdleToken) {
198
+ output = Math.round(
199
+ (parseFloat('' + tokenPrice) * parseFloat('' + amount)) /
200
+ parseFloat(`1e${idleToken.idleDecimals}`),
201
+ );
202
+ // SELL underlyingToken (amount = 1000000 USDC), output = 1000000/tokenPrice*1e18
203
+ } else {
204
+ output = Math.round(
205
+ (parseFloat('' + amount) / parseFloat('' + tokenPrice)) *
206
+ parseFloat(`1e${idleToken.idleDecimals}`),
207
+ );
208
+ }
209
+ } else {
210
+ // BUY idleToken (amount = 1000000 USDC, output = 1000000/tokenPrice*1e18)
211
+ if (fromIdleToken) {
212
+ output = Math.round(
213
+ (parseFloat('' + amount) / parseFloat('' + tokenPrice)) *
214
+ parseFloat(`1e${idleToken.idleDecimals}`),
215
+ );
216
+ // BUY underlyingToken (amount = 1000000000000000000 AA_idle_cpPOR-USDC, output = 1000000000000000000*tokenPrice/1e18)
217
+ } else {
218
+ output = Math.round(
219
+ (parseFloat('' + tokenPrice) * parseFloat('' + amount)) /
220
+ parseFloat(`1e${idleToken.idleDecimals}`),
221
+ );
222
+ }
223
+ }
224
+ return BigInt(output);
225
+ });
226
+
227
+ return [
228
+ {
229
+ unit: prices[0],
230
+ prices: prices.slice(1),
231
+ gasCost: this.config.lendingGasCost,
232
+ exchange: this.dexKey,
233
+ data: {
234
+ idleToken: {
235
+ cdoAddress: idleToken.cdoAddress,
236
+ tokenType: idleToken.tokenType,
237
+ },
238
+ fromIdleToken,
239
+ },
240
+ poolAddresses: [fromIdleToken ? srcToken.address : destToken.address],
241
+ },
242
+ ];
243
+ } catch (e) {
244
+ if (blockNumber === 0)
245
+ this.logger.error(
246
+ `Error_getPricesVolume: Aurelius block manager not yet instantiated`,
247
+ );
248
+ this.logger.error(`Error_getPrices:`, e);
249
+ return null;
250
+ }
251
+ }
252
+
253
+ // Cannot be implemented fully event-based.
254
+ // Rate changes almost every block.
255
+ // rpc-based pricing is only done for limited amount of tokens that are supported
256
+ async getTokenPrice(
257
+ idleToken: IdleToken,
258
+ blockNumber: number,
259
+ ): Promise<bigint | null> {
260
+ if (!idleToken.cdoContract) {
261
+ return null;
262
+ }
263
+
264
+ const tranchePrice = await idleToken.cdoContract.methods['virtualPrice'](
265
+ idleToken.idleAddress,
266
+ ).call({}, blockNumber);
267
+
268
+ return BigInt(tranchePrice);
269
+ }
270
+
271
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
272
+ getCalldataGasCost(poolPrices: PoolPrices<IdleDaoData>): number | number[] {
273
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
274
+ }
275
+
276
+ getAdapterParam(
277
+ srcToken: string,
278
+ destToken: string,
279
+ srcAmount: string,
280
+ destAmount: string,
281
+ data: IdleDaoData,
282
+ side: SwapSide,
283
+ ): AdapterExchangeParam {
284
+ return {
285
+ // target exchange is not used by the contract
286
+ targetExchange: NULL_ADDRESS,
287
+ payload: '0x',
288
+ networkFee: '0',
289
+ };
290
+ }
291
+
292
+ getDexParam(
293
+ srcToken: Address,
294
+ destToken: Address,
295
+ srcAmount: NumberAsString,
296
+ destAmount: NumberAsString,
297
+ recipient: Address,
298
+ data: IdleDaoData,
299
+ side: SwapSide,
300
+ _: Context,
301
+ executorAddress: Address,
302
+ ): DexExchangeParam {
303
+ const [Interface, swapCallee, swapFunction, swapFunctionParams] = ((): [
304
+ Interface,
305
+ Address,
306
+ PoolFunctions,
307
+ Param,
308
+ ] => {
309
+ if (data.fromIdleToken) {
310
+ return [
311
+ this.cdo,
312
+ data.idleToken.cdoAddress,
313
+ PoolFunctions[`withdraw${data.idleToken.tokenType}`],
314
+ [srcAmount],
315
+ ];
316
+ }
317
+
318
+ return [
319
+ this.cdo,
320
+ data.idleToken.cdoAddress,
321
+ PoolFunctions[`deposit${data.idleToken.tokenType}`],
322
+ [srcAmount, recipient],
323
+ ];
324
+ })();
325
+
326
+ const exchangeData = Interface.encodeFunctionData(
327
+ swapFunction,
328
+ swapFunctionParams,
329
+ );
330
+
331
+ return {
332
+ needWrapNative: this.needWrapNative,
333
+ dexFuncHasRecipient: false,
334
+ exchangeData,
335
+ targetExchange: swapCallee,
336
+ returnAmountPos: undefined,
337
+ };
338
+ }
339
+
340
+ async getTopPoolsForToken(
341
+ tokenAddress: Address,
342
+ limit: number,
343
+ ): Promise<PoolLiquidity[]> {
344
+ if (!this.tokenList) {
345
+ const blockNumber =
346
+ await this.dexHelper.web3Provider.eth.getBlockNumber();
347
+ this.initializePricing(blockNumber);
348
+ }
349
+ const idleTokens: IdleToken[] = getPoolsByTokenAddress(tokenAddress);
350
+
351
+ return idleTokens
352
+ .map((idleToken: IdleToken) => ({
353
+ // liquidity is infinite, tokens are minted when swapping for idle tokens
354
+ liquidityUSD: 1e12,
355
+ exchange: this.dexKey,
356
+ address: idleToken.cdoAddress,
357
+ connectorTokens: [getTokenFromIdleToken(idleToken)],
358
+ }))
359
+ .slice(0, limit);
360
+ }
361
+ }