@paraswap/dex-lib 3.8.0 → 3.8.1

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 (224) hide show
  1. package/.vscode/launch.json +53 -0
  2. package/.vscode/settings.json +2 -0
  3. package/.vscode/tasks.json +15 -0
  4. package/build/abi/AaveV1_lending_pool.json +27 -0
  5. package/build/abi/platypus/asset.json +490 -0
  6. package/build/abi/platypus/avax-pool.json +820 -0
  7. package/build/abi/platypus/oracle.json +119 -0
  8. package/build/abi/platypus/pool.json +677 -0
  9. package/build/abi/smardex/all/smardex-router.json +648 -0
  10. package/build/abi/smardex/layer-1/smardex-factory.json +242 -0
  11. package/build/abi/smardex/layer-1/smardex-pool.json +506 -0
  12. package/build/abi/smardex/layer-2/smardex-factory.json +185 -0
  13. package/build/abi/smardex/layer-2/smardex-pool.json +578 -0
  14. package/build/abi/swaap-v1/pool.json +1346 -0
  15. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
  16. package/build/abi/wombat/pool.json +1289 -0
  17. package/build/dex/aave-v1/aave-v1.d.ts +34 -0
  18. package/build/dex/aave-v1/aave-v1.js +181 -0
  19. package/build/dex/aave-v1/aave-v1.js.map +1 -0
  20. package/build/dex/aave-v1/config.d.ts +11 -0
  21. package/build/dex/aave-v1/config.js +20 -0
  22. package/build/dex/aave-v1/config.js.map +1 -0
  23. package/build/dex/aave-v1/tokens-mainnet.json +134 -0
  24. package/build/dex/aave-v1/tokens.d.ts +3 -0
  25. package/build/dex/aave-v1/tokens.js +50 -0
  26. package/build/dex/aave-v1/tokens.js.map +1 -0
  27. package/build/dex/aave-v1/types.d.ts +12 -0
  28. package/build/dex/aave-v1/types.js +3 -0
  29. package/build/dex/aave-v1/types.js.map +1 -0
  30. package/build/dex/aave-v2/tokens-avalanche.json +44 -0
  31. package/build/dex/aave-v2/tokens-mainnet.json +188 -0
  32. package/build/dex/aave-v2/tokens-polygon.json +44 -0
  33. package/build/dex/bProtocol.d.ts +18 -0
  34. package/build/dex/bProtocol.js +39 -0
  35. package/build/dex/bProtocol.js.map +1 -0
  36. package/build/dex/bancor.d.ts +26 -0
  37. package/build/dex/bancor.js +58 -0
  38. package/build/dex/bancor.js.map +1 -0
  39. package/build/dex/compound.d.ts +18 -0
  40. package/build/dex/compound.js +46 -0
  41. package/build/dex/compound.js.map +1 -0
  42. package/build/dex/curve-v2.d.ts +58 -0
  43. package/build/dex/curve-v2.js +180 -0
  44. package/build/dex/curve-v2.js.map +1 -0
  45. package/build/dex/dodo-v1.d.ts +33 -0
  46. package/build/dex/dodo-v1.js +63 -0
  47. package/build/dex/dodo-v1.js.map +1 -0
  48. package/build/dex/index.js +1 -19
  49. package/build/dex/index.js.map +1 -1
  50. package/build/dex/lido.d.ts +19 -0
  51. package/build/dex/lido.js +42 -0
  52. package/build/dex/lido.js.map +1 -0
  53. package/build/dex/maker-psm/scripts/gem.abi.json +136 -0
  54. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  55. package/build/dex/maker-psm/scripts/validate-state.js +185 -0
  56. package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
  57. package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
  58. package/build/dex/onebit.d.ts +25 -0
  59. package/build/dex/onebit.js +42 -0
  60. package/build/dex/onebit.js.map +1 -0
  61. package/build/dex/platypus/asset.d.ts +14 -0
  62. package/build/dex/platypus/asset.js +97 -0
  63. package/build/dex/platypus/asset.js.map +1 -0
  64. package/build/dex/platypus/config.d.ts +11 -0
  65. package/build/dex/platypus/config.js +69 -0
  66. package/build/dex/platypus/config.js.map +1 -0
  67. package/build/dex/platypus/platypus.d.ts +63 -0
  68. package/build/dex/platypus/platypus.js +487 -0
  69. package/build/dex/platypus/platypus.js.map +1 -0
  70. package/build/dex/platypus/pool-avax.d.ts +8 -0
  71. package/build/dex/platypus/pool-avax.js +54 -0
  72. package/build/dex/platypus/pool-avax.js.map +1 -0
  73. package/build/dex/platypus/pool-base.d.ts +19 -0
  74. package/build/dex/platypus/pool-base.js +86 -0
  75. package/build/dex/platypus/pool-base.js.map +1 -0
  76. package/build/dex/platypus/pool-pure.d.ts +8 -0
  77. package/build/dex/platypus/pool-pure.js +37 -0
  78. package/build/dex/platypus/pool-pure.js.map +1 -0
  79. package/build/dex/platypus/pool-subscriber.d.ts +14 -0
  80. package/build/dex/platypus/pool-subscriber.js +167 -0
  81. package/build/dex/platypus/pool-subscriber.js.map +1 -0
  82. package/build/dex/platypus/pool.d.ts +8 -0
  83. package/build/dex/platypus/pool.js +58 -0
  84. package/build/dex/platypus/pool.js.map +1 -0
  85. package/build/dex/platypus/types.d.ts +92 -0
  86. package/build/dex/platypus/types.js +10 -0
  87. package/build/dex/platypus/types.js.map +1 -0
  88. package/build/dex/quickswap/spiritswap-v3.d.ts +6 -0
  89. package/build/dex/quickswap/spiritswap-v3.js +19 -0
  90. package/build/dex/quickswap/spiritswap-v3.js.map +1 -0
  91. package/build/dex/smardex/config.d.ts +4 -0
  92. package/build/dex/smardex/config.js +64 -0
  93. package/build/dex/smardex/config.js.map +1 -0
  94. package/build/dex/smardex/constants.d.ts +18 -0
  95. package/build/dex/smardex/constants.js +33 -0
  96. package/build/dex/smardex/constants.js.map +1 -0
  97. package/build/dex/smardex/sdk/constants.d.ts +6 -0
  98. package/build/dex/smardex/sdk/constants.js +13 -0
  99. package/build/dex/smardex/sdk/constants.js.map +1 -0
  100. package/build/dex/smardex/sdk/core.d.ts +113 -0
  101. package/build/dex/smardex/sdk/core.js +499 -0
  102. package/build/dex/smardex/sdk/core.js.map +1 -0
  103. package/build/dex/smardex/sdk/errors.d.ts +15 -0
  104. package/build/dex/smardex/sdk/errors.js +22 -0
  105. package/build/dex/smardex/sdk/errors.js.map +1 -0
  106. package/build/dex/smardex/sdk/types.d.ts +62 -0
  107. package/build/dex/smardex/sdk/types.js +3 -0
  108. package/build/dex/smardex/sdk/types.js.map +1 -0
  109. package/build/dex/smardex/sdk/utils.d.ts +44 -0
  110. package/build/dex/smardex/sdk/utils.js +133 -0
  111. package/build/dex/smardex/sdk/utils.js.map +1 -0
  112. package/build/dex/smardex/smardex-event-pool.d.ts +28 -0
  113. package/build/dex/smardex/smardex-event-pool.js +119 -0
  114. package/build/dex/smardex/smardex-event-pool.js.map +1 -0
  115. package/build/dex/smardex/smardex.d.ts +65 -0
  116. package/build/dex/smardex/smardex.js +519 -0
  117. package/build/dex/smardex/smardex.js.map +1 -0
  118. package/build/dex/smardex/types.d.ts +55 -0
  119. package/build/dex/smardex/types.js +3 -0
  120. package/build/dex/smardex/types.js.map +1 -0
  121. package/build/dex/smoothy.d.ts +26 -0
  122. package/build/dex/smoothy.js +48 -0
  123. package/build/dex/smoothy.js.map +1 -0
  124. package/build/dex/solidly/forks-override/cone.d.ts +22 -0
  125. package/build/dex/solidly/forks-override/cone.js +53 -0
  126. package/build/dex/solidly/forks-override/cone.js.map +1 -0
  127. package/build/dex/solidly/forks-override/solisnek.d.ts +8 -0
  128. package/build/dex/solidly/forks-override/solisnek.js +15 -0
  129. package/build/dex/solidly/forks-override/solisnek.js.map +1 -0
  130. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +1 -0
  131. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +53 -0
  132. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +1 -0
  133. package/build/dex/stable-pool.d.ts +28 -0
  134. package/build/dex/stable-pool.js +55 -0
  135. package/build/dex/stable-pool.js.map +1 -0
  136. package/build/dex/swaap-v1/config.d.ts +17 -0
  137. package/build/dex/swaap-v1/config.js +56 -0
  138. package/build/dex/swaap-v1/config.js.map +1 -0
  139. package/build/dex/swaap-v1/constants.d.ts +6 -0
  140. package/build/dex/swaap-v1/constants.js +17 -0
  141. package/build/dex/swaap-v1/constants.js.map +1 -0
  142. package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +25 -0
  143. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +62 -0
  144. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +1 -0
  145. package/build/dex/swaap-v1/libraries/Const.d.ts +18 -0
  146. package/build/dex/swaap-v1/libraries/Const.js +26 -0
  147. package/build/dex/swaap-v1/libraries/Const.js.map +1 -0
  148. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +77 -0
  149. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +316 -0
  150. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +1 -0
  151. package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +75 -0
  152. package/build/dex/swaap-v1/libraries/LogExpMath.js +418 -0
  153. package/build/dex/swaap-v1/libraries/LogExpMath.js.map +1 -0
  154. package/build/dex/swaap-v1/libraries/MathMMM.d.ts +185 -0
  155. package/build/dex/swaap-v1/libraries/MathMMM.js +453 -0
  156. package/build/dex/swaap-v1/libraries/MathMMM.js.map +1 -0
  157. package/build/dex/swaap-v1/libraries/Num.d.ts +31 -0
  158. package/build/dex/swaap-v1/libraries/Num.js +167 -0
  159. package/build/dex/swaap-v1/libraries/Num.js.map +1 -0
  160. package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +23 -0
  161. package/build/dex/swaap-v1/libraries/PoolQuotations.js +131 -0
  162. package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +1 -0
  163. package/build/dex/swaap-v1/libraries/Struct.d.ts +56 -0
  164. package/build/dex/swaap-v1/libraries/Struct.js +3 -0
  165. package/build/dex/swaap-v1/libraries/Struct.js.map +1 -0
  166. package/build/dex/swaap-v1/swaap-v1-pool.d.ts +45 -0
  167. package/build/dex/swaap-v1/swaap-v1-pool.js +656 -0
  168. package/build/dex/swaap-v1/swaap-v1-pool.js.map +1 -0
  169. package/build/dex/swaap-v1/swaap-v1.d.ts +62 -0
  170. package/build/dex/swaap-v1/swaap-v1.js +383 -0
  171. package/build/dex/swaap-v1/swaap-v1.js.map +1 -0
  172. package/build/dex/swaap-v1/types.d.ts +106 -0
  173. package/build/dex/swaap-v1/types.js +9 -0
  174. package/build/dex/swaap-v1/types.js.map +1 -0
  175. package/build/dex/trader-joe-v2.1.d.ts +43 -0
  176. package/build/dex/trader-joe-v2.1.js +79 -0
  177. package/build/dex/trader-joe-v2.1.js.map +1 -0
  178. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +17 -0
  179. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +64 -0
  180. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +1 -0
  181. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +17 -0
  182. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +79 -0
  183. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +1 -0
  184. package/build/generic-swap-transaction-builder.js +1 -3
  185. package/build/generic-swap-transaction-builder.js.map +1 -1
  186. package/build/router/simpleswap.js +1 -3
  187. package/build/router/simpleswap.js.map +1 -1
  188. package/package.json +1 -1
  189. package/src/dex/index.ts +1 -18
  190. package/src/generic-swap-transaction-builder.ts +1 -3
  191. package/src/router/simpleswap.ts +1 -3
  192. package/.idea/aws.xml +0 -17
  193. package/.idea/codeStyles/Project.xml +0 -19
  194. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  195. package/.idea/misc.xml +0 -6
  196. package/.idea/modules.xml +0 -8
  197. package/.idea/paraswap-dex-lib.iml +0 -9
  198. package/.idea/prettier.xml +0 -7
  199. package/.idea/vcs.xml +0 -6
  200. package/src/abi/BProtocol.json +0 -1155
  201. package/src/abi/Jarvis.json +0 -1172
  202. package/src/abi/MStableAsset.json +0 -1545
  203. package/src/abi/OneInchLp.json +0 -1304
  204. package/src/abi/Onebit.json +0 -736
  205. package/src/abi/Shell.json +0 -1294
  206. package/src/abi/TraderJoeV2Router.json +0 -50
  207. package/src/abi/zrx.v2.json +0 -1967
  208. package/src/abi/zrx.v3.json +0 -3454
  209. package/src/abi/zrx.v4.json +0 -2193
  210. package/src/dex/OneInchLp.ts +0 -84
  211. package/src/dex/bProtocol/bProtocol-e2e.test.ts +0 -93
  212. package/src/dex/bProtocol/bProtocol.ts +0 -108
  213. package/src/dex/bProtocol/types.ts +0 -13
  214. package/src/dex/jarvis.ts +0 -262
  215. package/src/dex/mStable.ts +0 -147
  216. package/src/dex/onebit/onebit.ts +0 -113
  217. package/src/dex/onebit/types.ts +0 -17
  218. package/src/dex/shell.ts +0 -84
  219. package/src/dex/trader-joe-v2.ts +0 -148
  220. package/src/dex/zerox/config.ts +0 -31
  221. package/src/dex/zerox/index.ts +0 -328
  222. package/src/dex/zerox/order.ts +0 -62
  223. package/src/dex/zerox/types.ts +0 -82
  224. package/src/dex/zerox/zerox-e2e.test.ts +0 -110
@@ -1,84 +0,0 @@
1
- import { Interface, JsonFragment } from '@ethersproject/abi';
2
- import { NULL_ADDRESS, SwapSide } from '../constants';
3
- import { AdapterExchangeParam, Address, SimpleExchangeParam } from '../types';
4
- import { IDexTxBuilder } from './idex';
5
- import { SimpleExchange } from './simple-exchange';
6
- import OneInchLpABI from '../abi/OneInchLp.json';
7
- import { isETHAddress } from '../utils';
8
- import Web3 from 'web3';
9
- import { IDexHelper } from '../dex-helper';
10
-
11
- export type OneInchLpData = {
12
- exchange: string; // _DOUBLE_CHECK_
13
- };
14
- type OneInchLpParam = [
15
- src: string,
16
- dst: string,
17
- amount: string,
18
- minReturn: string,
19
- referral: string,
20
- ];
21
- enum OneInchLpFunctions {
22
- swap = 'swap',
23
- }
24
-
25
- export class OneInchLp
26
- extends SimpleExchange
27
- implements IDexTxBuilder<OneInchLpData, OneInchLpParam>
28
- {
29
- static dexKeys = ['oneinchlp'];
30
- exchangeRouterInterface: Interface;
31
-
32
- constructor(dexHelper: IDexHelper) {
33
- super(dexHelper, 'oneinchlp');
34
- this.exchangeRouterInterface = new Interface(
35
- OneInchLpABI as JsonFragment[],
36
- );
37
- }
38
-
39
- getAdapterParam(
40
- srcToken: string,
41
- destToken: string,
42
- srcAmount: string,
43
- destAmount: string,
44
- data: OneInchLpData,
45
- side: SwapSide,
46
- ): AdapterExchangeParam {
47
- return {
48
- targetExchange: data.exchange,
49
- payload: '0x',
50
- networkFee: '0',
51
- };
52
- }
53
-
54
- async getSimpleParam(
55
- srcToken: string,
56
- destToken: string,
57
- srcAmount: string,
58
- destAmount: string,
59
- data: OneInchLpData,
60
- side: SwapSide,
61
- ): Promise<SimpleExchangeParam> {
62
- const swapFunction = OneInchLpFunctions.swap;
63
- const swapFunctionParams: OneInchLpParam = [
64
- isETHAddress(srcToken) ? NULL_ADDRESS : srcToken,
65
- isETHAddress(destToken) ? NULL_ADDRESS : destToken,
66
- srcAmount,
67
- destAmount,
68
- NULL_ADDRESS,
69
- ];
70
- const swapData = this.exchangeRouterInterface.encodeFunctionData(
71
- swapFunction,
72
- swapFunctionParams,
73
- );
74
-
75
- return this.buildSimpleParamWithoutWETHConversion(
76
- srcToken,
77
- srcAmount,
78
- destToken,
79
- destAmount,
80
- swapData,
81
- data.exchange,
82
- );
83
- }
84
- }
@@ -1,93 +0,0 @@
1
- import dotenv from 'dotenv';
2
- dotenv.config();
3
-
4
- import { testE2E } from '../../../tests/utils-e2e';
5
- import {
6
- Tokens,
7
- Holders,
8
- NativeTokenSymbols,
9
- } from '../../../tests/constants-e2e';
10
-
11
- import { ContractMethod, Network, SwapSide } from '../../constants';
12
- import { StaticJsonRpcProvider } from '@ethersproject/providers';
13
- import { generateConfig } from '../../config';
14
-
15
- const dexKey = 'bprotocol';
16
-
17
- // ! LIQUIDITY ISSUES
18
-
19
- const testForNetwork = (
20
- network: Network,
21
- swapMap: Map<SwapSide, ContractMethod[]>,
22
- ) => {
23
- const tokens = Tokens[network];
24
- const holders = Holders[network];
25
-
26
- const nativeSymbol = NativeTokenSymbols[network];
27
-
28
- const provider = new StaticJsonRpcProvider(
29
- generateConfig(network).privateHttpProvider,
30
- network,
31
- );
32
-
33
- const tokensToTest = [
34
- [
35
- {
36
- symbol: 'LUSD',
37
- amount: '100000000000000000000',
38
- },
39
- {
40
- symbol: 'ETH',
41
- amount: '35360886801038522',
42
- },
43
- ],
44
- ];
45
-
46
- swapMap.forEach((contractMethods, side) =>
47
- contractMethods.forEach((contractMethod: string) => {
48
- tokensToTest.forEach(pair => {
49
- describe(`${contractMethod}`, () => {
50
- it(`${pair[0].symbol} -> ${pair[1].symbol}`, async () => {
51
- await testE2E(
52
- tokens[pair[0].symbol],
53
- tokens[pair[1].symbol],
54
- holders[pair[0].symbol],
55
- side === SwapSide.SELL ? pair[0].amount : pair[1].amount,
56
- side,
57
- dexKey,
58
- contractMethod as any,
59
- network,
60
- provider,
61
- );
62
- });
63
-
64
- it(`${nativeSymbol} -> ${pair[0].symbol}`, async () => {
65
- await testE2E(
66
- tokens[nativeSymbol],
67
- tokens[pair[0].symbol],
68
- holders[nativeSymbol],
69
- side === SwapSide.SELL ? '1000000000000000000' : pair[0].amount,
70
- side,
71
- dexKey,
72
- contractMethod as any,
73
- network,
74
- provider,
75
- );
76
- });
77
- });
78
- });
79
- }),
80
- );
81
- };
82
-
83
- // Ensure you have the E2E_ENDPOINT_URL env variable set.
84
-
85
- describe('bProtocol E2E', () => {
86
- describe('Mainnet V6', () => {
87
- const swapMap = new Map<SwapSide, ContractMethod[]>([
88
- [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
89
- ]);
90
-
91
- testForNetwork(Network.MAINNET, swapMap);
92
- });
93
- });
@@ -1,108 +0,0 @@
1
- import { Interface, JsonFragment } from '@ethersproject/abi';
2
- import { 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 BProtocolABI from '../../abi/BProtocol.json';
13
- import { IDexHelper } from '../../dex-helper';
14
- import { BProtocolData, BProtocolFunctions, BProtocolParam } from './types';
15
- import { extractReturnAmountPosition } from '../../executor/utils';
16
-
17
- export class BProtocol
18
- extends SimpleExchange
19
- implements IDexTxBuilder<BProtocolData, BProtocolParam>
20
- {
21
- static dexKeys = ['bprotocol'];
22
- exchangeRouterInterface: Interface;
23
-
24
- constructor(dexHelper: IDexHelper) {
25
- super(dexHelper, 'bprotocol');
26
- this.exchangeRouterInterface = new Interface(
27
- BProtocolABI as JsonFragment[],
28
- );
29
- }
30
-
31
- getAdapterParam(
32
- srcToken: string,
33
- destToken: string,
34
- srcAmount: string,
35
- destAmount: string,
36
- data: BProtocolData,
37
- side: SwapSide,
38
- ): AdapterExchangeParam {
39
- return {
40
- targetExchange: data.exchange,
41
- payload: '0x',
42
- networkFee: '0',
43
- };
44
- }
45
-
46
- async getSimpleParam(
47
- srcToken: string,
48
- destToken: string,
49
- srcAmount: string,
50
- destAmount: string,
51
- data: BProtocolData,
52
- side: SwapSide,
53
- ): Promise<SimpleExchangeParam> {
54
- const swapFunction = BProtocolFunctions.swap;
55
- const swapFunctionParams: BProtocolParam = [
56
- srcAmount,
57
- destAmount,
58
- this.augustusAddress,
59
- ];
60
- const swapData = this.exchangeRouterInterface.encodeFunctionData(
61
- swapFunction,
62
- swapFunctionParams,
63
- );
64
-
65
- return this.buildSimpleParamWithoutWETHConversion(
66
- srcToken,
67
- srcAmount,
68
- destToken,
69
- destAmount,
70
- swapData,
71
- data.exchange,
72
- );
73
- }
74
-
75
- getDexParam(
76
- _srcToken: Address,
77
- _destToken: Address,
78
- srcAmount: NumberAsString,
79
- destAmount: NumberAsString,
80
- recipient: Address,
81
- data: BProtocolData,
82
- _side: SwapSide,
83
- ): DexExchangeParam {
84
- const swapFunction = BProtocolFunctions.swap;
85
- const swapFunctionParams: BProtocolParam = [
86
- srcAmount,
87
- destAmount,
88
- recipient,
89
- ];
90
- const swapData = this.exchangeRouterInterface.encodeFunctionData(
91
- swapFunction,
92
- swapFunctionParams,
93
- );
94
- return {
95
- needWrapNative: this.needWrapNative,
96
- dexFuncHasRecipient: true,
97
- exchangeData: swapData,
98
- targetExchange: data.exchange,
99
- returnAmountPos:
100
- _side === SwapSide.SELL
101
- ? extractReturnAmountPosition(
102
- this.exchangeRouterInterface,
103
- swapFunction,
104
- )
105
- : undefined,
106
- };
107
- }
108
- }
@@ -1,13 +0,0 @@
1
- export type BProtocolData = {
2
- exchange: string;
3
- };
4
-
5
- export type BProtocolParam = [
6
- lusdAmount: string,
7
- minEthReturn: string,
8
- dest: string,
9
- ];
10
-
11
- export enum BProtocolFunctions {
12
- swap = 'swap',
13
- }
package/src/dex/jarvis.ts DELETED
@@ -1,262 +0,0 @@
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
- }
@@ -1,147 +0,0 @@
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
- }