@paraswap/dex-lib 2.16.3 → 2.16.4-traderjoev2.1.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 (55) hide show
  1. package/build/abi/TraderJoeV21Router.json +1489 -0
  2. package/build/dex/index.js +2 -0
  3. package/build/dex/index.js.map +1 -1
  4. package/build/dex/trader-joe-v2.1.d.ts +43 -0
  5. package/build/dex/trader-joe-v2.1.js +74 -0
  6. package/build/dex/trader-joe-v2.1.js.map +1 -0
  7. package/package.json +1 -1
  8. package/src/abi/TraderJoeV21Router.json +1489 -0
  9. package/src/dex/index.ts +2 -0
  10. package/src/dex/trader-joe-v2.1.ts +151 -0
  11. package/build/abi/DirectSwap.json +0 -970
  12. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  13. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  14. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  15. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  16. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  17. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  18. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  19. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  20. package/build/dex/quickswap-v3.d.ts +0 -21
  21. package/build/dex/quickswap-v3.js +0 -40
  22. package/build/dex/quickswap-v3.js.map +0 -1
  23. package/build/dex/test-dex/config.d.ts +0 -4
  24. package/build/dex/test-dex/config.js +0 -15
  25. package/build/dex/test-dex/config.js.map +0 -1
  26. package/build/dex/test-dex/test-dex-pool.d.ts +0 -39
  27. package/build/dex/test-dex/test-dex-pool.js +0 -63
  28. package/build/dex/test-dex/test-dex-pool.js.map +0 -1
  29. package/build/dex/test-dex/test-dex.d.ts +0 -37
  30. package/build/dex/test-dex/test-dex.js +0 -126
  31. package/build/dex/test-dex/test-dex.js.map +0 -1
  32. package/build/dex/test-dex/types.d.ts +0 -6
  33. package/build/dex/test-dex/types.js +0 -3
  34. package/build/dex/test-dex/types.js.map +0 -1
  35. package/build/dex/woo-fi/config.d.ts +0 -4
  36. package/build/dex/woo-fi/config.js +0 -141
  37. package/build/dex/woo-fi/config.js.map +0 -1
  38. package/build/dex/woo-fi/constants.d.ts +0 -5
  39. package/build/dex/woo-fi/constants.js +0 -20
  40. package/build/dex/woo-fi/constants.js.map +0 -1
  41. package/build/dex/woo-fi/types.d.ts +0 -48
  42. package/build/dex/woo-fi/types.js +0 -3
  43. package/build/dex/woo-fi/types.js.map +0 -1
  44. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  45. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  46. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  47. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  48. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  49. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  50. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  51. package/build/dex/woo-fi/woo-fi.js +0 -480
  52. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  53. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +0 -16
  54. package/build/dex/woo-fi-v2/woo-fi-math.js +0 -137
  55. package/build/dex/woo-fi-v2/woo-fi-math.js.map +0 -1
package/src/dex/index.ts CHANGED
@@ -65,6 +65,7 @@ import { ZyberSwapV3 } from './quickswap/zyberswap-v3';
65
65
  import { TraderJoeV2 } from './trader-joe-v2';
66
66
  import { SpiritSwapV3 } from './quickswap/spiritswap-v3';
67
67
  import { PancakeswapV3 } from './uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3';
68
+ import { TraderJoeV21 } from './trader-joe-v2.1';
68
69
 
69
70
  const LegacyDexes = [
70
71
  CurveV2,
@@ -84,6 +85,7 @@ const LegacyDexes = [
84
85
  ZyberSwapV3,
85
86
  SpiritSwapV3,
86
87
  TraderJoeV2,
88
+ TraderJoeV21,
87
89
  Jarvis,
88
90
  Lido,
89
91
  AugustusRFQOrder,
@@ -0,0 +1,151 @@
1
+ import { Network, SwapSide } from '../constants';
2
+ import { AdapterExchangeParam, Address, SimpleExchangeParam } from '../types';
3
+ import { IDexTxBuilder } from './idex';
4
+ import { IDexHelper } from '../dex-helper';
5
+ import {
6
+ getLocalDeadlineAsFriendlyPlaceholder,
7
+ SimpleExchange,
8
+ } from './simple-exchange';
9
+ import { NumberAsString } from '@paraswap/core';
10
+ import { AsyncOrSync } from 'ts-essentials';
11
+ import { Interface, JsonFragment } from '@ethersproject/abi';
12
+ import TraderJoeV21RouterABI from '../abi/TraderJoeV21Router.json';
13
+
14
+ const TRADERJOE_V2_1_ROUTER_ADDRESS: { [network: number]: Address } = {
15
+ [Network.AVALANCHE]: '0xb4315e873dBcf96Ffd0acd8EA43f689D8c20fB30',
16
+ [Network.ARBITRUM]: '0xb4315e873dBcf96Ffd0acd8EA43f689D8c20fB30',
17
+ [Network.BSC]: '0xb4315e873dBcf96Ffd0acd8EA43f689D8c20fB30',
18
+ };
19
+
20
+ type RouterPath = [
21
+ pairBinSteps: NumberAsString[],
22
+ versions: NumberAsString[],
23
+ tokenPath: Address[],
24
+ ];
25
+ type TraderJoeV2RouterSellParams = [
26
+ _amountIn: NumberAsString,
27
+ _amountOutMin: NumberAsString,
28
+ _routerPath: RouterPath,
29
+ to: Address,
30
+ _deadline: string,
31
+ ];
32
+
33
+ type TraderJoeV2RouterBuyParams = [
34
+ _amountOut: NumberAsString,
35
+ _amountInMax: NumberAsString,
36
+ _routerPath: RouterPath,
37
+ to: Address,
38
+ _deadline: string,
39
+ ];
40
+
41
+ type TraderJoeV2RouterParam =
42
+ | TraderJoeV2RouterSellParams
43
+ | TraderJoeV2RouterBuyParams;
44
+
45
+ export type TraderJoeV2Data = {
46
+ tokenIn: string; // redundant
47
+ tokenOut: string; // redundant
48
+ binStep: string;
49
+ };
50
+
51
+ enum TraderJoeV2RouterFunctions {
52
+ swapExactTokensForTokens = 'swapExactTokensForTokens',
53
+ swapTokensForExactTokens = 'swapTokensForExactTokens',
54
+ }
55
+ export class TraderJoeV21
56
+ extends SimpleExchange
57
+ implements IDexTxBuilder<TraderJoeV2Data, TraderJoeV2RouterParam>
58
+ {
59
+ static dexKeys = ['traderjoev2.1'];
60
+ protected routerAddress: string;
61
+ exchangeRouterInterface: Interface;
62
+ needWrapNative = true;
63
+
64
+ constructor(dexHelper: IDexHelper) {
65
+ super(dexHelper, 'traderjoev2.1');
66
+
67
+ this.routerAddress =
68
+ TRADERJOE_V2_1_ROUTER_ADDRESS[dexHelper.config.data.network];
69
+
70
+ this.exchangeRouterInterface = new Interface(
71
+ TraderJoeV21RouterABI as JsonFragment[],
72
+ );
73
+ }
74
+
75
+ getAdapterParam(
76
+ srcToken: Address,
77
+ destToken: Address,
78
+ srcAmount: NumberAsString,
79
+ destAmount: NumberAsString,
80
+ data: TraderJoeV2Data,
81
+ side: SwapSide,
82
+ ): AdapterExchangeParam {
83
+ const payload = this.abiCoder.encodeParameter(
84
+ {
85
+ ParentStruct: {
86
+ _pairBinSteps: 'uint256[]',
87
+ _tokenPath: 'address[]',
88
+ _deadline: 'uint256',
89
+ _mintOutAmount: 'uint256',
90
+ },
91
+ },
92
+ {
93
+ _pairBinSteps: [data.binStep],
94
+ _tokenPath: [data.tokenIn, data.tokenOut], // FIXME: redundant, shoot & read from contract
95
+ _deadline: getLocalDeadlineAsFriendlyPlaceholder(), // FIXME: more gas efficient to pass block.timestamp in adapter
96
+ _minOutAmount: destAmount,
97
+ },
98
+ );
99
+
100
+ return {
101
+ targetExchange: this.routerAddress,
102
+ payload,
103
+ networkFee: '0',
104
+ };
105
+ }
106
+
107
+ getSimpleParam(
108
+ srcToken: Address,
109
+ destToken: Address,
110
+ srcAmount: NumberAsString,
111
+ destAmount: NumberAsString,
112
+ data: TraderJoeV2Data,
113
+ side: SwapSide,
114
+ ): AsyncOrSync<SimpleExchangeParam> {
115
+ const swapFunction =
116
+ side === SwapSide.SELL
117
+ ? TraderJoeV2RouterFunctions.swapExactTokensForTokens
118
+ : TraderJoeV2RouterFunctions.swapTokensForExactTokens;
119
+
120
+ const swapFunctionParams: TraderJoeV2RouterParam =
121
+ side === SwapSide.SELL
122
+ ? [
123
+ srcAmount,
124
+ destAmount,
125
+ [[data.binStep], ['2'], [srcToken, destToken]],
126
+ this.augustusAddress,
127
+ getLocalDeadlineAsFriendlyPlaceholder(),
128
+ ]
129
+ : [
130
+ destAmount,
131
+ srcAmount,
132
+ [[data.binStep], ['2'], [srcToken, destToken]],
133
+ this.augustusAddress,
134
+ getLocalDeadlineAsFriendlyPlaceholder(),
135
+ ];
136
+
137
+ const swapData = this.exchangeRouterInterface.encodeFunctionData(
138
+ swapFunction,
139
+ swapFunctionParams,
140
+ );
141
+
142
+ return this.buildSimpleParamWithoutWETHConversion(
143
+ srcToken,
144
+ srcAmount,
145
+ destToken,
146
+ destAmount,
147
+ swapData,
148
+ this.routerAddress,
149
+ );
150
+ }
151
+ }