@paraswap/dex-lib 3.8.1-lo-v6-encoding-bug.0 → 3.8.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 (37) hide show
  1. package/build/dex/index.js +1 -19
  2. package/build/dex/index.js.map +1 -1
  3. package/build/generic-swap-transaction-builder.js +1 -3
  4. package/build/generic-swap-transaction-builder.js.map +1 -1
  5. package/build/router/simpleswap.js +1 -3
  6. package/build/router/simpleswap.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/dex/index.ts +1 -18
  9. package/src/dex/paraswap-limit-orders/paraswap-limit-orders-e2e.test.ts +1 -1
  10. package/src/generic-swap-transaction-builder.ts +1 -3
  11. package/src/router/simpleswap.ts +1 -3
  12. package/tests/constants-e2e.ts +0 -10
  13. package/src/abi/BProtocol.json +0 -1155
  14. package/src/abi/Jarvis.json +0 -1172
  15. package/src/abi/MStableAsset.json +0 -1545
  16. package/src/abi/OneInchLp.json +0 -1304
  17. package/src/abi/Onebit.json +0 -736
  18. package/src/abi/Shell.json +0 -1294
  19. package/src/abi/TraderJoeV2Router.json +0 -50
  20. package/src/abi/zrx.v2.json +0 -1967
  21. package/src/abi/zrx.v3.json +0 -3454
  22. package/src/abi/zrx.v4.json +0 -2193
  23. package/src/dex/OneInchLp.ts +0 -84
  24. package/src/dex/bProtocol/bProtocol-e2e.test.ts +0 -93
  25. package/src/dex/bProtocol/bProtocol.ts +0 -108
  26. package/src/dex/bProtocol/types.ts +0 -13
  27. package/src/dex/jarvis.ts +0 -262
  28. package/src/dex/mStable.ts +0 -147
  29. package/src/dex/onebit/onebit.ts +0 -113
  30. package/src/dex/onebit/types.ts +0 -17
  31. package/src/dex/shell.ts +0 -84
  32. package/src/dex/trader-joe-v2.ts +0 -148
  33. package/src/dex/zerox/config.ts +0 -31
  34. package/src/dex/zerox/index.ts +0 -328
  35. package/src/dex/zerox/order.ts +0 -62
  36. package/src/dex/zerox/types.ts +0 -82
  37. 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
- }