@paraswap/dex-lib 3.7.9-dex-deprecation.0 → 3.8.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 (262) hide show
  1. package/.idea/aws.xml +17 -0
  2. package/.idea/codeStyles/Project.xml +19 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/paraswap-dex-lib.iml +9 -0
  7. package/.idea/prettier.xml +7 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/build/abi/curve-v1-factory/CurveV1Router.abi.json +331 -0
  10. package/build/config.js +1 -1
  11. package/build/dex/curve-v1-factory/config.js +47 -10
  12. package/build/dex/curve-v1-factory/config.js.map +1 -1
  13. package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +2 -2
  14. package/build/dex/curve-v1-factory/curve-v1-factory.js +96 -36
  15. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  16. package/build/dex/curve-v1-factory/optimizer.d.ts +2 -0
  17. package/build/dex/curve-v1-factory/optimizer.js +54 -0
  18. package/build/dex/curve-v1-factory/optimizer.js.map +1 -0
  19. package/build/dex/curve-v1-factory/price-handlers/functions/constants.js.map +1 -1
  20. package/build/dex/curve-v1-factory/price-handlers/functions/get_dx.js +13 -1
  21. package/build/dex/curve-v1-factory/price-handlers/functions/get_dx.js.map +1 -1
  22. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.d.ts +2 -2
  23. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js +1 -1
  24. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js.map +1 -1
  25. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +1 -1
  26. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
  27. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.d.ts +4 -3
  28. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js +24 -9
  29. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js.map +1 -1
  30. package/build/dex/curve-v1-factory/types.d.ts +20 -4
  31. package/build/dex/curve-v1-factory/types.js +11 -3
  32. package/build/dex/curve-v1-factory/types.js.map +1 -1
  33. package/build/dex/curve-v1-stable-ng/config.js +18 -0
  34. package/build/dex/curve-v1-stable-ng/config.js.map +1 -1
  35. package/build/dex/index.js +18 -0
  36. package/build/dex/index.js.map +1 -1
  37. package/build/utils.d.ts +1 -1
  38. package/package.json +2 -2
  39. package/src/abi/BProtocol.json +1155 -0
  40. package/src/abi/Jarvis.json +1172 -0
  41. package/src/abi/MStableAsset.json +1545 -0
  42. package/src/abi/OneInchLp.json +1304 -0
  43. package/src/abi/Onebit.json +736 -0
  44. package/src/abi/Shell.json +1294 -0
  45. package/src/abi/TraderJoeV2Router.json +50 -0
  46. package/src/abi/curve-v1-factory/CurveV1Router.abi.json +331 -0
  47. package/src/abi/zrx.v2.json +1967 -0
  48. package/src/abi/zrx.v3.json +3454 -0
  49. package/src/abi/zrx.v4.json +2193 -0
  50. package/src/config.ts +1 -1
  51. package/src/dex/OneInchLp.ts +84 -0
  52. package/src/dex/bProtocol/bProtocol-e2e.test.ts +93 -0
  53. package/src/dex/bProtocol/bProtocol.ts +108 -0
  54. package/src/dex/bProtocol/types.ts +13 -0
  55. package/src/dex/curve-v1-factory/config.ts +47 -10
  56. package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +92 -16
  57. package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +125 -5
  58. package/src/dex/curve-v1-factory/curve-v1-factory.ts +137 -45
  59. package/src/dex/curve-v1-factory/optimizer.ts +61 -0
  60. package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +0 -2
  61. package/src/dex/curve-v1-factory/price-handlers/functions/get_dx.ts +24 -1
  62. package/src/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.ts +3 -2
  63. package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +1 -0
  64. package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +31 -10
  65. package/src/dex/curve-v1-factory/types.ts +22 -6
  66. package/src/dex/curve-v1-stable-ng/config.ts +18 -0
  67. package/src/dex/curve-v1-stable-ng/curve-v1-stable-ng-e2e.test.ts +17 -0
  68. package/src/dex/index.ts +18 -0
  69. package/src/dex/jarvis.ts +262 -0
  70. package/src/dex/mStable.ts +147 -0
  71. package/src/dex/onebit/onebit.ts +113 -0
  72. package/src/dex/onebit/types.ts +17 -0
  73. package/src/dex/shell.ts +84 -0
  74. package/src/dex/trader-joe-v2.ts +148 -0
  75. package/src/dex/zerox/config.ts +31 -0
  76. package/src/dex/zerox/index.ts +328 -0
  77. package/src/dex/zerox/order.ts +62 -0
  78. package/src/dex/zerox/types.ts +82 -0
  79. package/src/dex/zerox/zerox-e2e.test.ts +110 -0
  80. package/tests/constants-e2e.ts +1 -1
  81. package/tests/utils-e2e.ts +2 -0
  82. package/.vscode/launch.json +0 -53
  83. package/.vscode/settings.json +0 -2
  84. package/.vscode/tasks.json +0 -15
  85. package/build/abi/AaveV1_lending_pool.json +0 -27
  86. package/build/abi/platypus/asset.json +0 -490
  87. package/build/abi/platypus/avax-pool.json +0 -820
  88. package/build/abi/platypus/oracle.json +0 -119
  89. package/build/abi/platypus/pool.json +0 -677
  90. package/build/abi/smardex/all/smardex-router.json +0 -648
  91. package/build/abi/smardex/layer-1/smardex-factory.json +0 -242
  92. package/build/abi/smardex/layer-1/smardex-pool.json +0 -506
  93. package/build/abi/smardex/layer-2/smardex-factory.json +0 -185
  94. package/build/abi/smardex/layer-2/smardex-pool.json +0 -578
  95. package/build/abi/swaap-v1/pool.json +0 -1346
  96. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
  97. package/build/abi/wombat/pool.json +0 -1289
  98. package/build/dex/aave-v1/aave-v1.d.ts +0 -34
  99. package/build/dex/aave-v1/aave-v1.js +0 -181
  100. package/build/dex/aave-v1/aave-v1.js.map +0 -1
  101. package/build/dex/aave-v1/config.d.ts +0 -11
  102. package/build/dex/aave-v1/config.js +0 -20
  103. package/build/dex/aave-v1/config.js.map +0 -1
  104. package/build/dex/aave-v1/tokens-mainnet.json +0 -134
  105. package/build/dex/aave-v1/tokens.d.ts +0 -3
  106. package/build/dex/aave-v1/tokens.js +0 -50
  107. package/build/dex/aave-v1/tokens.js.map +0 -1
  108. package/build/dex/aave-v1/types.d.ts +0 -12
  109. package/build/dex/aave-v1/types.js +0 -3
  110. package/build/dex/aave-v1/types.js.map +0 -1
  111. package/build/dex/aave-v2/tokens-avalanche.json +0 -44
  112. package/build/dex/aave-v2/tokens-mainnet.json +0 -188
  113. package/build/dex/aave-v2/tokens-polygon.json +0 -44
  114. package/build/dex/bProtocol.d.ts +0 -18
  115. package/build/dex/bProtocol.js +0 -39
  116. package/build/dex/bProtocol.js.map +0 -1
  117. package/build/dex/bancor.d.ts +0 -26
  118. package/build/dex/bancor.js +0 -58
  119. package/build/dex/bancor.js.map +0 -1
  120. package/build/dex/compound.d.ts +0 -18
  121. package/build/dex/compound.js +0 -46
  122. package/build/dex/compound.js.map +0 -1
  123. package/build/dex/curve-v2.d.ts +0 -58
  124. package/build/dex/curve-v2.js +0 -180
  125. package/build/dex/curve-v2.js.map +0 -1
  126. package/build/dex/dodo-v1.d.ts +0 -33
  127. package/build/dex/dodo-v1.js +0 -63
  128. package/build/dex/dodo-v1.js.map +0 -1
  129. package/build/dex/lido.d.ts +0 -19
  130. package/build/dex/lido.js +0 -42
  131. package/build/dex/lido.js.map +0 -1
  132. package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
  133. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  134. package/build/dex/maker-psm/scripts/validate-state.js +0 -185
  135. package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
  136. package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
  137. package/build/dex/onebit.d.ts +0 -25
  138. package/build/dex/onebit.js +0 -42
  139. package/build/dex/onebit.js.map +0 -1
  140. package/build/dex/platypus/asset.d.ts +0 -14
  141. package/build/dex/platypus/asset.js +0 -97
  142. package/build/dex/platypus/asset.js.map +0 -1
  143. package/build/dex/platypus/config.d.ts +0 -11
  144. package/build/dex/platypus/config.js +0 -69
  145. package/build/dex/platypus/config.js.map +0 -1
  146. package/build/dex/platypus/platypus.d.ts +0 -63
  147. package/build/dex/platypus/platypus.js +0 -487
  148. package/build/dex/platypus/platypus.js.map +0 -1
  149. package/build/dex/platypus/pool-avax.d.ts +0 -8
  150. package/build/dex/platypus/pool-avax.js +0 -54
  151. package/build/dex/platypus/pool-avax.js.map +0 -1
  152. package/build/dex/platypus/pool-base.d.ts +0 -19
  153. package/build/dex/platypus/pool-base.js +0 -86
  154. package/build/dex/platypus/pool-base.js.map +0 -1
  155. package/build/dex/platypus/pool-pure.d.ts +0 -8
  156. package/build/dex/platypus/pool-pure.js +0 -37
  157. package/build/dex/platypus/pool-pure.js.map +0 -1
  158. package/build/dex/platypus/pool-subscriber.d.ts +0 -14
  159. package/build/dex/platypus/pool-subscriber.js +0 -167
  160. package/build/dex/platypus/pool-subscriber.js.map +0 -1
  161. package/build/dex/platypus/pool.d.ts +0 -8
  162. package/build/dex/platypus/pool.js +0 -58
  163. package/build/dex/platypus/pool.js.map +0 -1
  164. package/build/dex/platypus/types.d.ts +0 -92
  165. package/build/dex/platypus/types.js +0 -10
  166. package/build/dex/platypus/types.js.map +0 -1
  167. package/build/dex/quickswap/spiritswap-v3.d.ts +0 -6
  168. package/build/dex/quickswap/spiritswap-v3.js +0 -19
  169. package/build/dex/quickswap/spiritswap-v3.js.map +0 -1
  170. package/build/dex/smardex/config.d.ts +0 -4
  171. package/build/dex/smardex/config.js +0 -64
  172. package/build/dex/smardex/config.js.map +0 -1
  173. package/build/dex/smardex/constants.d.ts +0 -18
  174. package/build/dex/smardex/constants.js +0 -33
  175. package/build/dex/smardex/constants.js.map +0 -1
  176. package/build/dex/smardex/sdk/constants.d.ts +0 -6
  177. package/build/dex/smardex/sdk/constants.js +0 -13
  178. package/build/dex/smardex/sdk/constants.js.map +0 -1
  179. package/build/dex/smardex/sdk/core.d.ts +0 -113
  180. package/build/dex/smardex/sdk/core.js +0 -499
  181. package/build/dex/smardex/sdk/core.js.map +0 -1
  182. package/build/dex/smardex/sdk/errors.d.ts +0 -15
  183. package/build/dex/smardex/sdk/errors.js +0 -22
  184. package/build/dex/smardex/sdk/errors.js.map +0 -1
  185. package/build/dex/smardex/sdk/types.d.ts +0 -62
  186. package/build/dex/smardex/sdk/types.js +0 -3
  187. package/build/dex/smardex/sdk/types.js.map +0 -1
  188. package/build/dex/smardex/sdk/utils.d.ts +0 -44
  189. package/build/dex/smardex/sdk/utils.js +0 -133
  190. package/build/dex/smardex/sdk/utils.js.map +0 -1
  191. package/build/dex/smardex/smardex-event-pool.d.ts +0 -28
  192. package/build/dex/smardex/smardex-event-pool.js +0 -119
  193. package/build/dex/smardex/smardex-event-pool.js.map +0 -1
  194. package/build/dex/smardex/smardex.d.ts +0 -65
  195. package/build/dex/smardex/smardex.js +0 -519
  196. package/build/dex/smardex/smardex.js.map +0 -1
  197. package/build/dex/smardex/types.d.ts +0 -55
  198. package/build/dex/smardex/types.js +0 -3
  199. package/build/dex/smardex/types.js.map +0 -1
  200. package/build/dex/smoothy.d.ts +0 -26
  201. package/build/dex/smoothy.js +0 -48
  202. package/build/dex/smoothy.js.map +0 -1
  203. package/build/dex/solidly/forks-override/cone.d.ts +0 -22
  204. package/build/dex/solidly/forks-override/cone.js +0 -53
  205. package/build/dex/solidly/forks-override/cone.js.map +0 -1
  206. package/build/dex/solidly/forks-override/solisnek.d.ts +0 -8
  207. package/build/dex/solidly/forks-override/solisnek.js +0 -15
  208. package/build/dex/solidly/forks-override/solisnek.js.map +0 -1
  209. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +0 -1
  210. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
  211. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
  212. package/build/dex/stable-pool.d.ts +0 -28
  213. package/build/dex/stable-pool.js +0 -55
  214. package/build/dex/stable-pool.js.map +0 -1
  215. package/build/dex/swaap-v1/config.d.ts +0 -17
  216. package/build/dex/swaap-v1/config.js +0 -56
  217. package/build/dex/swaap-v1/config.js.map +0 -1
  218. package/build/dex/swaap-v1/constants.d.ts +0 -6
  219. package/build/dex/swaap-v1/constants.js +0 -17
  220. package/build/dex/swaap-v1/constants.js.map +0 -1
  221. package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +0 -25
  222. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +0 -62
  223. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +0 -1
  224. package/build/dex/swaap-v1/libraries/Const.d.ts +0 -18
  225. package/build/dex/swaap-v1/libraries/Const.js +0 -26
  226. package/build/dex/swaap-v1/libraries/Const.js.map +0 -1
  227. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +0 -77
  228. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +0 -316
  229. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +0 -1
  230. package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +0 -75
  231. package/build/dex/swaap-v1/libraries/LogExpMath.js +0 -418
  232. package/build/dex/swaap-v1/libraries/LogExpMath.js.map +0 -1
  233. package/build/dex/swaap-v1/libraries/MathMMM.d.ts +0 -185
  234. package/build/dex/swaap-v1/libraries/MathMMM.js +0 -453
  235. package/build/dex/swaap-v1/libraries/MathMMM.js.map +0 -1
  236. package/build/dex/swaap-v1/libraries/Num.d.ts +0 -31
  237. package/build/dex/swaap-v1/libraries/Num.js +0 -167
  238. package/build/dex/swaap-v1/libraries/Num.js.map +0 -1
  239. package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +0 -23
  240. package/build/dex/swaap-v1/libraries/PoolQuotations.js +0 -131
  241. package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +0 -1
  242. package/build/dex/swaap-v1/libraries/Struct.d.ts +0 -56
  243. package/build/dex/swaap-v1/libraries/Struct.js +0 -3
  244. package/build/dex/swaap-v1/libraries/Struct.js.map +0 -1
  245. package/build/dex/swaap-v1/swaap-v1-pool.d.ts +0 -45
  246. package/build/dex/swaap-v1/swaap-v1-pool.js +0 -656
  247. package/build/dex/swaap-v1/swaap-v1-pool.js.map +0 -1
  248. package/build/dex/swaap-v1/swaap-v1.d.ts +0 -62
  249. package/build/dex/swaap-v1/swaap-v1.js +0 -383
  250. package/build/dex/swaap-v1/swaap-v1.js.map +0 -1
  251. package/build/dex/swaap-v1/types.d.ts +0 -106
  252. package/build/dex/swaap-v1/types.js +0 -9
  253. package/build/dex/swaap-v1/types.js.map +0 -1
  254. package/build/dex/trader-joe-v2.1.d.ts +0 -43
  255. package/build/dex/trader-joe-v2.1.js +0 -79
  256. package/build/dex/trader-joe-v2.1.js.map +0 -1
  257. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
  258. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
  259. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
  260. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
  261. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
  262. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
@@ -5,7 +5,13 @@ import {
5
5
  MAX_ALLOWED_STATE_DELAY_FACTOR,
6
6
  MIN_LIQUIDITY_IN_USD,
7
7
  } from '../constants';
8
- import { CurveV1FactoryData, PoolConstants, PoolState } from '../types';
8
+ import {
9
+ CurveV1FactoryData,
10
+ ImplementationNames,
11
+ PoolConstants,
12
+ PoolContextConstants,
13
+ PoolState,
14
+ } from '../types';
9
15
  import { Address } from '@paraswap/core';
10
16
 
11
17
  export type MulticallReturnedTypes = bigint | bigint[];
@@ -38,11 +44,12 @@ export abstract class PoolPollingBase {
38
44
  readonly dexKey: string,
39
45
  readonly network: number,
40
46
  readonly cacheStateKey: string,
41
- readonly implementationName: string,
47
+ readonly implementationName: ImplementationNames,
42
48
  readonly implementationAddress: Address,
43
49
  readonly stateUpdatePeriodMs: number,
44
50
  readonly poolIdentifier: string,
45
51
  readonly poolConstants: PoolConstants,
52
+ readonly poolContextConstants: PoolContextConstants,
46
53
  readonly address: Address,
47
54
  readonly curveLiquidityApiSlug: string,
48
55
  readonly isLendingPool: boolean,
@@ -120,10 +127,17 @@ export abstract class PoolPollingBase {
120
127
 
121
128
  if (iC !== undefined && jC !== undefined) {
122
129
  return {
123
- exchange: this.address,
124
- i: iC,
125
- j: jC,
126
- underlyingSwap: false,
130
+ path: [
131
+ {
132
+ tokenIn: srcAddress,
133
+ tokenOut: destAddress,
134
+ exchange: this.address,
135
+ i: iC,
136
+ j: jC,
137
+ underlyingSwap: false,
138
+ n_coins: this.poolConstants.COINS.length,
139
+ },
140
+ ],
127
141
  };
128
142
  }
129
143
 
@@ -140,10 +154,17 @@ export abstract class PoolPollingBase {
140
154
  // I expect them to be included in old CurveV1 implementation
141
155
  if (iU !== undefined && jU !== undefined && !(iU > 0 && jU > 0)) {
142
156
  return {
143
- exchange: this.address,
144
- i: iU,
145
- j: jU,
146
- underlyingSwap: true,
157
+ path: [
158
+ {
159
+ tokenIn: srcAddress,
160
+ tokenOut: destAddress,
161
+ exchange: this.address,
162
+ i: iU,
163
+ j: jU,
164
+ underlyingSwap: true,
165
+ n_coins: this.poolConstants.COINS.length,
166
+ },
167
+ ],
147
168
  };
148
169
  }
149
170
  }
@@ -15,6 +15,7 @@ export type PoolContextConstants = {
15
15
  // for all pools
16
16
  isWrapNative: boolean;
17
17
  isLending: boolean;
18
+ isStable?: boolean;
18
19
 
19
20
  // Starting from this point, constants are context relevant for pricing
20
21
 
@@ -68,10 +69,15 @@ export type PoolStateWithUpdateInfo<T> = {
68
69
  };
69
70
 
70
71
  export type CurveV1FactoryData = {
71
- exchange: Address;
72
- i: number;
73
- j: number;
74
- underlyingSwap: boolean;
72
+ path: {
73
+ tokenIn: Address;
74
+ tokenOut: Address;
75
+ exchange: Address;
76
+ i: number;
77
+ j: number;
78
+ underlyingSwap: boolean;
79
+ n_coins: number;
80
+ }[];
75
81
  isApproved?: boolean;
76
82
  };
77
83
 
@@ -118,8 +124,6 @@ export enum FactoryImplementationNames {
118
124
  FACTORY_PLAIN_4_OPTIMIZED = 'factory_plain_4_optimized',
119
125
 
120
126
  FACTORY_STABLE_NG = 'factory_stable_ng',
121
- // FACTORY_STABLE_6_NG = 'factory_stable_6_ng',
122
- // FACTORY_STABLE_8_NG = 'factory_stable_8_ng',
123
127
  }
124
128
 
125
129
  export enum CustomImplementationNames {
@@ -188,6 +192,7 @@ type DexParamFactory = {
188
192
 
189
193
  export type DexParams = {
190
194
  factories: DexParamFactory[] | null;
195
+ router: Address;
191
196
  stateUpdatePeriodMs: number;
192
197
  factoryPoolImplementations: Record<Address, FactoryPoolImplementations>;
193
198
  customPools: Record<string, CustomPoolConfig>;
@@ -202,8 +207,19 @@ export enum CurveSwapFunctions {
202
207
  exchange_underlying = 'exchange_underlying',
203
208
  }
204
209
 
210
+ export enum CurveRouterSwapType {
211
+ exchange = 1,
212
+ exchange_underlying = 2,
213
+ }
214
+
215
+ export enum CurveRouterPoolType {
216
+ non_stable = 0,
217
+ stable = 10,
218
+ }
219
+
205
220
  export type CurveV1FactoryIfaces = {
206
221
  exchangeRouter: Interface;
222
+ curveV1Router: Interface;
207
223
  factory: Interface;
208
224
  erc20: Interface;
209
225
  threePool: Interface;
@@ -13,6 +13,7 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
13
13
  isStableNg: true,
14
14
  },
15
15
  ],
16
+ router: '0x16C6521Dff6baB339122a0FE25a9116693265353', // https://github.com/curvefi/curve-router-ng
16
17
  stateUpdatePeriodMs: 5 * 1000,
17
18
  disabledPools: new Set([]),
18
19
  disabledImplementations: new Set([]),
@@ -59,6 +60,18 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
59
60
  liquidityApiSlug: '/factory-stable-ng',
60
61
  isStoreRateSupported: true,
61
62
  },
63
+ '0xc65cb3156225380beda366610bab18d5835a1647': {
64
+ name: ImplementationNames.FACTORY_STABLE_NG,
65
+ address: '0xc65cb3156225380beda366610bab18d5835a1647',
66
+ liquidityApiSlug: '/factory-stable-ng',
67
+ isStoreRateSupported: true,
68
+ },
69
+ '0xa0ec67a3c483674f77915893346a8ca3abe2b785': {
70
+ name: ImplementationNames.FACTORY_STABLE_NG,
71
+ address: '0xa0ec67a3c483674f77915893346a8ca3abe2b785',
72
+ liquidityApiSlug: '/factory-stable-ng',
73
+ isStoreRateSupported: true,
74
+ },
62
75
  },
63
76
  customPools: {},
64
77
  },
@@ -69,6 +82,7 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
69
82
  isStableNg: true,
70
83
  },
71
84
  ],
85
+ router: '0x0DCDED3545D565bA3B19E683431381007245d983', // https://github.com/curvefi/curve-router-ng
72
86
  stateUpdatePeriodMs: 2 * 1000,
73
87
  disabledPools: new Set([]),
74
88
  disabledImplementations: new Set([]),
@@ -95,6 +109,7 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
95
109
  isStableNg: true,
96
110
  },
97
111
  ],
112
+ router: '0x0DCDED3545D565bA3B19E683431381007245d983', // https://github.com/curvefi/curve-router-ng
98
113
  stateUpdatePeriodMs: 2 * 1000,
99
114
  disabledPools: new Set([]),
100
115
  disabledImplementations: new Set([]),
@@ -115,6 +130,7 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
115
130
  isStableNg: true,
116
131
  },
117
132
  ],
133
+ router: '0x2191718CD32d02B8E60BAdFFeA33E4B5DD9A0A0D', // https://github.com/curvefi/curve-router-ng
118
134
  stateUpdatePeriodMs: 2 * 1000,
119
135
  disabledPools: new Set([]),
120
136
  disabledImplementations: new Set([]),
@@ -141,6 +157,7 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
141
157
  isStableNg: true,
142
158
  },
143
159
  ],
160
+ router: '0x0DCDED3545D565bA3B19E683431381007245d983', // https://github.com/curvefi/curve-router-ng
144
161
  stateUpdatePeriodMs: 2 * 1000,
145
162
  disabledPools: new Set([]),
146
163
  disabledImplementations: new Set([]),
@@ -161,6 +178,7 @@ const CurveV1StableNgConfig: DexConfigMap<DexParams> = {
161
178
  isStableNg: true,
162
179
  },
163
180
  ],
181
+ router: '0x4f37A9d177470499A2dD084621020b023fcffc1F', // https://github.com/curvefi/curve-router-ng
164
182
  stateUpdatePeriodMs: 2 * 1000,
165
183
  disabledPools: new Set([]),
166
184
  disabledImplementations: new Set([]),
@@ -63,6 +63,23 @@ describe('CurveV1StableNG E2E', () => {
63
63
  sidesToContractMethods,
64
64
  );
65
65
  });
66
+
67
+ describe('GHO -> crvUSD', () => {
68
+ const tokenASymbol: string = 'GHO';
69
+ const tokenBSymbol: string = 'crvUSD';
70
+
71
+ const tokenAAmount: string = '1000000000000000000';
72
+ const tokenBAmount: string = '1000000000000000000';
73
+
74
+ testForNetwork(
75
+ network,
76
+ dexKey,
77
+ tokenASymbol,
78
+ tokenBSymbol,
79
+ tokenAAmount,
80
+ tokenBAmount,
81
+ );
82
+ });
66
83
  });
67
84
 
68
85
  describe('Polygon', () => {
package/src/dex/index.ts CHANGED
@@ -2,10 +2,12 @@ import _ from 'lodash';
2
2
  import { UnoptimizedRate } from '../types';
3
3
  import { CurveV2 } from './curve-v2/curve-v2';
4
4
  import { IDexTxBuilder, DexConstructor, IDex, IRouteOptimizer } from './idex';
5
+ import { Jarvis } from './jarvis';
5
6
  import { JarvisV6 } from './jarvis-v6/jarvis-v6';
6
7
  import { StablePool } from './stable-pool/stable-pool';
7
8
  import { Weth } from './weth/weth';
8
9
  import { PolygonMigrator } from './polygon-migrator/polygon-migrator';
10
+ import { ZeroX } from './zerox';
9
11
  import { UniswapV3 } from './uniswap-v3/uniswap-v3';
10
12
  import { BalancerV2 } from './balancer-v2/balancer-v2';
11
13
  import { balancerV2Merge } from './balancer-v2/optimizer';
@@ -16,10 +18,15 @@ import { BiSwap } from './uniswap-v2/biswap';
16
18
  import { MDEX } from './uniswap-v2/mdex';
17
19
  import { Dfyn } from './uniswap-v2/dfyn';
18
20
  import { Bancor } from './bancor/bancor';
21
+ import { BProtocol } from './bProtocol/bProtocol';
22
+ import { MStable } from './mStable';
23
+ import { Shell } from './shell';
24
+ import { Onebit } from './onebit/onebit';
19
25
  import { Compound } from './compound/compound';
20
26
  import { AaveV2 } from './aave-v2/aave-v2';
21
27
  import { AaveV3 } from './aave-v3/aave-v3';
22
28
  import { IdleDao } from './idle-dao/idle-dao';
29
+ import { OneInchLp } from './OneInchLp';
23
30
  import { DodoV1 } from './dodo-v1/dodo-v1';
24
31
  import { DodoV2 } from './dodo-v2';
25
32
  import { Smoothy } from './smoothy/smoothy';
@@ -55,6 +62,7 @@ import { CurveFork } from './curve-v1/forks/curve-forks/curve-forks';
55
62
  import { Swerve } from './curve-v1/forks/swerve/swerve';
56
63
  import { CurveV1Factory } from './curve-v1-factory/curve-v1-factory';
57
64
  import { CurveV1StableNg } from './curve-v1-stable-ng/curve-v1-stable-ng';
65
+ import { curveV1Merge } from './curve-v1-factory/optimizer';
58
66
  import { GenericRFQ } from './generic-rfq/generic-rfq';
59
67
  import { WstETH } from './wsteth/wsteth';
60
68
  import { Camelot } from './camelot/camelot';
@@ -64,6 +72,7 @@ import { MaverickV1 } from './maverick-v1/maverick-v1';
64
72
  import { MaverickV2 } from './maverick-v2/maverick-v2';
65
73
  import { QuickSwapV3 } from './quickswap/quickswap-v3';
66
74
  import { ThenaFusion } from './quickswap/thena-fusion';
75
+ import { TraderJoeV2 } from './trader-joe-v2';
67
76
  import { SwaapV2 } from './swaap-v2/swaap-v2';
68
77
  import { TraderJoeV21 } from './trader-joe-v2.1/trader-joe-v2.1';
69
78
  import { PancakeswapV3 } from './pancakeswap-v3/pancakeswap-v3';
@@ -85,13 +94,21 @@ const LegacyDexes = [
85
94
  CurveV2,
86
95
  StablePool,
87
96
  Smoothy,
97
+ ZeroX,
88
98
  Bancor,
99
+ BProtocol,
100
+ MStable,
101
+ Shell,
102
+ Onebit,
89
103
  Compound,
104
+ OneInchLp,
90
105
  DodoV1,
91
106
  DodoV2,
92
107
  QuickSwapV3,
93
108
  ThenaFusion,
109
+ TraderJoeV2,
94
110
  TraderJoeV21,
111
+ Jarvis,
95
112
  Lido,
96
113
  AugustusRFQOrder,
97
114
  EtherFi,
@@ -187,6 +204,7 @@ export class DexAdapterService {
187
204
  balancerV1Merge,
188
205
  balancerV2Merge,
189
206
  uniswapMerge,
207
+ curveV1Merge,
190
208
  ];
191
209
 
192
210
  constructor(
@@ -0,0 +1,262 @@
1
+ import { Interface, JsonFragment } from '@ethersproject/abi';
2
+ import { NULL_ADDRESS, SwapSide } from '../constants';
3
+ import {
4
+ AdapterExchangeParam,
5
+ Address,
6
+ DexExchangeParam,
7
+ NumberAsString,
8
+ SimpleExchangeParam,
9
+ } from '../types';
10
+ import { IDexTxBuilder } from './idex';
11
+ import { SimpleExchange } from './simple-exchange';
12
+ import JarvisABI from '../abi/Jarvis.json';
13
+ import Web3 from 'web3';
14
+ import { IDexHelper } from '../dex-helper';
15
+ import { extractReturnAmountPosition } from '../executor/utils';
16
+
17
+ const THIRTY_MINUTES = 60 * 30;
18
+
19
+ export type JarvisData = {
20
+ derivatives: string;
21
+ destDerivatives?: string;
22
+ pools: string[];
23
+ fee: string;
24
+ method: JarvisFunctions;
25
+ router: Address;
26
+ };
27
+
28
+ type JarvisMintParam = [
29
+ derivative: string,
30
+ minNumTokens: string,
31
+ collateralAmount: string,
32
+ feePercentage: string,
33
+ expiration: string,
34
+ recipient: string,
35
+ ];
36
+
37
+ type JarvisRedeemParam = [
38
+ derivative: string,
39
+ numTokens: string,
40
+ minCollateral: string,
41
+ feePercentage: string,
42
+ expiration: string,
43
+ recipient: string,
44
+ ];
45
+
46
+ type JarvisExchangeParam = [
47
+ derivative: string,
48
+ destPool: string,
49
+ destDerivative: string,
50
+ numTokens: string,
51
+ minDestNumTokens: string,
52
+ feePercentage: string,
53
+ expiration: string,
54
+ recipient: string,
55
+ ];
56
+
57
+ type JarvisParam = JarvisExchangeParam | JarvisMintParam | JarvisRedeemParam;
58
+
59
+ enum JarvisFunctions {
60
+ mint = 'mint',
61
+ redeem = 'redeem',
62
+ exchange = 'exchange',
63
+ }
64
+
65
+ export class Jarvis
66
+ extends SimpleExchange
67
+ implements IDexTxBuilder<JarvisData, JarvisParam>
68
+ {
69
+ static dexKeys = ['jarvis'];
70
+ poolInterface: Interface;
71
+ needWrapNative = false;
72
+
73
+ constructor(dexHelper: IDexHelper) {
74
+ super(dexHelper, 'jarvis');
75
+ this.poolInterface = new Interface(JarvisABI as JsonFragment[]);
76
+ }
77
+
78
+ getAdapterParam(
79
+ srcToken: string,
80
+ destToken: string,
81
+ srcAmount: string,
82
+ destAmount: string,
83
+ data: JarvisData,
84
+ side: SwapSide,
85
+ ): AdapterExchangeParam {
86
+ const { method } = data;
87
+ const type = [
88
+ JarvisFunctions.mint,
89
+ JarvisFunctions.redeem,
90
+ JarvisFunctions.exchange,
91
+ ].indexOf(method);
92
+
93
+ if (type === undefined) {
94
+ throw new Error(
95
+ `Jarvis: Invalid OpType ${method}, Should be one of ['mint', 'exchange', 'redeem']`,
96
+ );
97
+ }
98
+
99
+ const payload = this.abiCoder.encodeParameter(
100
+ {
101
+ ParentStruct: {
102
+ opType: 'uint',
103
+ derivatives: 'address',
104
+ destDerivatives: 'address',
105
+ fee: 'uint128',
106
+ destPool: 'address',
107
+ expiration: 'uint128',
108
+ },
109
+ },
110
+ {
111
+ opType: type,
112
+ derivatives: data.derivatives,
113
+ destDerivatives: data.destDerivatives || NULL_ADDRESS,
114
+ fee: data.fee,
115
+ destPool: data.pools[1] || NULL_ADDRESS,
116
+ expiration: (Date.now() / 1000 + THIRTY_MINUTES).toFixed(0),
117
+ },
118
+ );
119
+
120
+ return {
121
+ targetExchange: data.pools[0],
122
+ payload,
123
+ networkFee: '0',
124
+ };
125
+ }
126
+
127
+ async getSimpleParam(
128
+ srcToken: string,
129
+ destToken: string,
130
+ srcAmount: string,
131
+ destAmount: string,
132
+ data: JarvisData,
133
+ side: SwapSide,
134
+ ): Promise<SimpleExchangeParam> {
135
+ const swapFunction = data.method;
136
+ const timestamp = (Date.now() / 1000 + THIRTY_MINUTES).toFixed(0);
137
+ let swapFunctionParams: JarvisParam;
138
+ switch (swapFunction) {
139
+ case JarvisFunctions.mint:
140
+ swapFunctionParams = [
141
+ data.derivatives,
142
+ destAmount,
143
+ srcAmount,
144
+ data.fee,
145
+ timestamp,
146
+ this.augustusAddress,
147
+ ];
148
+ break;
149
+ case JarvisFunctions.redeem:
150
+ swapFunctionParams = [
151
+ data.derivatives,
152
+ srcAmount,
153
+ destAmount,
154
+ data.fee,
155
+ timestamp,
156
+ this.augustusAddress,
157
+ ];
158
+ break;
159
+ case JarvisFunctions.exchange:
160
+ swapFunctionParams = [
161
+ data.derivatives,
162
+ data.pools[1],
163
+ data.destDerivatives!,
164
+ srcAmount,
165
+ destAmount,
166
+ data.fee,
167
+ timestamp,
168
+ this.augustusAddress,
169
+ ];
170
+ break;
171
+ default:
172
+ throw new Error(`Unknown function ${swapFunction}`);
173
+ }
174
+
175
+ const swapData = this.poolInterface.encodeFunctionData(swapFunction, [
176
+ swapFunctionParams,
177
+ ]);
178
+
179
+ return this.buildSimpleParamWithoutWETHConversion(
180
+ srcToken,
181
+ srcAmount,
182
+ destToken,
183
+ destAmount,
184
+ swapData,
185
+ data.pools[0],
186
+ );
187
+ }
188
+
189
+ getDexParam(
190
+ srcToken: Address,
191
+ destToken: Address,
192
+ srcAmount: NumberAsString,
193
+ destAmount: NumberAsString,
194
+ recipient: Address,
195
+ data: JarvisData,
196
+ side: SwapSide,
197
+ ): DexExchangeParam {
198
+ const swapFunction = data.method;
199
+ const timestamp = (Date.now() / 1000 + THIRTY_MINUTES).toFixed(0);
200
+ let swapFunctionParams: JarvisParam;
201
+ let outputName: string;
202
+
203
+ switch (swapFunction) {
204
+ case JarvisFunctions.mint:
205
+ swapFunctionParams = [
206
+ data.derivatives,
207
+ destAmount,
208
+ srcAmount,
209
+ data.fee,
210
+ timestamp,
211
+ recipient,
212
+ ];
213
+ outputName = 'syntheticTokensMinted';
214
+ break;
215
+ case JarvisFunctions.redeem:
216
+ swapFunctionParams = [
217
+ data.derivatives,
218
+ srcAmount,
219
+ destAmount,
220
+ data.fee,
221
+ timestamp,
222
+ recipient,
223
+ ];
224
+ outputName = 'collateralRedeemed';
225
+ break;
226
+ case JarvisFunctions.exchange:
227
+ swapFunctionParams = [
228
+ data.derivatives,
229
+ data.pools[1],
230
+ data.destDerivatives!,
231
+ srcAmount,
232
+ destAmount,
233
+ data.fee,
234
+ timestamp,
235
+ recipient,
236
+ ];
237
+ outputName = 'destNumTokensMinted';
238
+ break;
239
+ default:
240
+ throw new Error(`Unknown function ${swapFunction}`);
241
+ }
242
+
243
+ const swapData = this.poolInterface.encodeFunctionData(swapFunction, [
244
+ swapFunctionParams,
245
+ ]);
246
+
247
+ return {
248
+ needWrapNative: this.needWrapNative,
249
+ dexFuncHasRecipient: true,
250
+ exchangeData: swapData,
251
+ targetExchange: data.pools[0],
252
+ returnAmountPos:
253
+ side === SwapSide.SELL
254
+ ? extractReturnAmountPosition(
255
+ this.poolInterface,
256
+ swapFunction,
257
+ outputName,
258
+ )
259
+ : undefined,
260
+ };
261
+ }
262
+ }
@@ -0,0 +1,147 @@
1
+ import { Interface, JsonFragment } from '@ethersproject/abi';
2
+ import { Provider } from '@ethersproject/providers';
3
+ import { SwapSide } from '../constants';
4
+ import { AdapterExchangeParam, Address, SimpleExchangeParam } from '../types';
5
+ import { IDexTxBuilder } from './idex';
6
+ import { SimpleExchange } from './simple-exchange';
7
+ import MStableAssetABI from '../abi/MStableAsset.json';
8
+ import Web3 from 'web3';
9
+ import { IDexHelper } from '../dex-helper';
10
+
11
+ enum MStableFunctions {
12
+ mint = 'mint',
13
+ swap = 'swap',
14
+ redeem = 'redeem',
15
+ }
16
+ type MStableData = {
17
+ exchange: string;
18
+ opType: MStableFunctions;
19
+ isAssetContract: boolean;
20
+ };
21
+ type MStableMint = [
22
+ _input: string,
23
+ _inputQuantity: string,
24
+ _minOutputQuantity: string,
25
+ _recipient: string,
26
+ ];
27
+ type MStableSwap = [
28
+ _input: string,
29
+ _output: string,
30
+ _inputQuantity: string,
31
+ _minOutputQuantity: string,
32
+ _recipient: string,
33
+ ];
34
+ type MStableRedeem = [
35
+ _output: string,
36
+ _mAssetQuantity: string,
37
+ _minOutputQuantity: string,
38
+ _recipient: string,
39
+ ];
40
+
41
+ type MStableParam = MStableMint | MStableSwap | MStableRedeem;
42
+
43
+ export class MStable
44
+ extends SimpleExchange
45
+ implements IDexTxBuilder<MStableData, MStableParam>
46
+ {
47
+ static dexKeys = ['mStable'];
48
+ mStableAsset: Interface;
49
+
50
+ constructor(dexHelper: IDexHelper) {
51
+ super(dexHelper, 'mStable');
52
+ this.mStableAsset = new Interface(MStableAssetABI as JsonFragment[]);
53
+ }
54
+
55
+ getAdapterParam(
56
+ srcToken: string,
57
+ destToken: string,
58
+ srcAmount: string,
59
+ destAmount: string,
60
+ data: MStableData,
61
+ side: SwapSide,
62
+ ): AdapterExchangeParam {
63
+ const { opType } = data;
64
+ const type = [
65
+ MStableFunctions.swap,
66
+ MStableFunctions.mint,
67
+ MStableFunctions.redeem,
68
+ ].indexOf(opType);
69
+
70
+ if (type === undefined) {
71
+ throw new Error(
72
+ `mStable: Invalid OpType ${opType}, Should be one of ['mint', 'swap', 'redeem']`,
73
+ );
74
+ }
75
+
76
+ const payload = this.abiCoder.encodeParameter(
77
+ {
78
+ ParentStruct: {
79
+ opType: 'uint',
80
+ },
81
+ },
82
+ {
83
+ opType: type,
84
+ },
85
+ );
86
+
87
+ return {
88
+ targetExchange: data.exchange,
89
+ payload,
90
+ networkFee: '0',
91
+ };
92
+ }
93
+
94
+ async getSimpleParam(
95
+ srcToken: string,
96
+ destToken: string,
97
+ srcAmount: string,
98
+ destAmount: string,
99
+ data: MStableData,
100
+ side: SwapSide,
101
+ ): Promise<SimpleExchangeParam> {
102
+ const { opType, isAssetContract } = data;
103
+
104
+ const [swapFunction, swapFunctionsParams] = ((): [
105
+ MStableFunctions,
106
+ MStableParam,
107
+ ] => {
108
+ switch (opType) {
109
+ case MStableFunctions.mint:
110
+ return [
111
+ opType,
112
+ [srcToken, srcAmount, destAmount, this.augustusAddress],
113
+ ];
114
+ case MStableFunctions.swap:
115
+ return [
116
+ opType,
117
+ [srcToken, destToken, srcAmount, destAmount, this.augustusAddress],
118
+ ];
119
+ case MStableFunctions.redeem:
120
+ return [
121
+ opType,
122
+ [destToken, srcAmount, destAmount, this.augustusAddress],
123
+ ];
124
+ default:
125
+ throw new Error(
126
+ `mStable's OpType ${opType} not supported, failed to build`,
127
+ );
128
+ }
129
+ })();
130
+
131
+ // mStableAsset & mStablePool both have the same interface hence we can
132
+ // simply use mStableAsset contract
133
+ const swapData = this.mStableAsset.encodeFunctionData(
134
+ swapFunction,
135
+ swapFunctionsParams,
136
+ );
137
+
138
+ return this.buildSimpleParamWithoutWETHConversion(
139
+ srcToken,
140
+ srcAmount,
141
+ destToken,
142
+ destAmount,
143
+ swapData,
144
+ data.exchange,
145
+ );
146
+ }
147
+ }