@paraswap/dex-lib 3.5.4-v6.2.0 → 3.5.4-v6.2.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 (43) hide show
  1. package/build/dex/balancer-v2/balancer-v2.d.ts +2 -2
  2. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  3. package/build/dex/curve-v1/curve-v1.d.ts +2 -2
  4. package/build/dex/curve-v1/curve-v1.js.map +1 -1
  5. package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +2 -2
  6. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  7. package/build/dex/curve-v2/curve-v2.d.ts +2 -2
  8. package/build/dex/curve-v2/curve-v2.js.map +1 -1
  9. package/build/dex/generic-rfq/generic-rfq.d.ts +1 -1
  10. package/build/dex/generic-rfq/generic-rfq.js.map +1 -1
  11. package/build/dex/idex.d.ts +2 -2
  12. package/build/dex/maker-psm/maker-psm.d.ts +12 -3
  13. package/build/dex/maker-psm/maker-psm.js +66 -0
  14. package/build/dex/maker-psm/maker-psm.js.map +1 -1
  15. package/build/dex/maker-psm/scripts/gem.abi.json +136 -0
  16. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  17. package/build/dex/maker-psm/scripts/validate-state.js +185 -0
  18. package/build/dex/maker-psm/scripts/validate-state.js.map +1 -0
  19. package/build/dex/maker-psm/scripts/vat.abi.json +243 -0
  20. package/build/dex/maker-psm/types.d.ts +15 -1
  21. package/build/dex/uniswap-v2/uniswap-v2.d.ts +2 -2
  22. package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
  23. package/build/dex/uniswap-v3/uniswap-v3.d.ts +2 -2
  24. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  25. package/build/dex/zerox/index.d.ts +1 -1
  26. package/build/dex/zerox/index.js.map +1 -1
  27. package/package.json +1 -1
  28. package/src/dex/balancer-v2/balancer-v2.ts +2 -2
  29. package/src/dex/curve-v1/curve-v1.ts +2 -2
  30. package/src/dex/curve-v1-factory/curve-v1-factory.ts +2 -2
  31. package/src/dex/curve-v2/curve-v2.ts +2 -2
  32. package/src/dex/generic-rfq/generic-rfq.ts +1 -1
  33. package/src/dex/idex.ts +2 -2
  34. package/src/dex/maker-psm/maker-psm-e2e.test.ts +8 -33
  35. package/src/dex/maker-psm/maker-psm.ts +136 -5
  36. package/src/dex/maker-psm/scripts/gem.abi.json +136 -0
  37. package/src/dex/maker-psm/scripts/validate-state.ts +221 -0
  38. package/src/dex/maker-psm/scripts/vat.abi.json +243 -0
  39. package/src/dex/maker-psm/types.ts +17 -1
  40. package/src/dex/uniswap-v2/uniswap-v2.ts +2 -2
  41. package/src/dex/uniswap-v3/uniswap-v3.ts +2 -2
  42. package/src/dex/zerox/index.ts +1 -1
  43. package/tests/constants-e2e.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraswap/dex-lib",
3
- "version": "3.5.4-v6.2.0",
3
+ "version": "3.5.4-v6.2.1",
4
4
  "main": "build/index.js",
5
5
  "types": "build/index.d.ts",
6
6
  "repository": "https://github.com/paraswap/paraswap-dex-lib",
@@ -1326,7 +1326,7 @@ export class BalancerV2
1326
1326
  deadline: NumberAsString,
1327
1327
  partner: string,
1328
1328
  beneficiary: string,
1329
- contractMethod?: string,
1329
+ contractMethod: string,
1330
1330
  ): TxInfo<BalancerV2DirectParam> {
1331
1331
  if (
1332
1332
  contractMethod !== DirectMethods.directSell &&
@@ -1397,7 +1397,7 @@ export class BalancerV2
1397
1397
  partnerAndFee: string,
1398
1398
  beneficiary: string,
1399
1399
  blockNumber: number,
1400
- contractMethod?: string,
1400
+ contractMethod: string,
1401
1401
  ) {
1402
1402
  if (!contractMethod) throw new Error(`contractMethod need to be passed`);
1403
1403
 
@@ -937,7 +937,7 @@ export class CurveV1
937
937
  deadline: NumberAsString,
938
938
  partner: string,
939
939
  beneficiary: string,
940
- contractMethod?: string,
940
+ contractMethod: string,
941
941
  ): TxInfo<DirectCurveV1Param> {
942
942
  if (contractMethod !== DIRECT_METHOD_NAME) {
943
943
  throw new Error(`Invalid contract method ${contractMethod}`);
@@ -997,7 +997,7 @@ export class CurveV1
997
997
  partnerAndFee: string,
998
998
  beneficiary: string,
999
999
  blockNumber: number,
1000
- contractMethod?: string,
1000
+ contractMethod: string,
1001
1001
  ) {
1002
1002
  if (contractMethod !== DIRECT_METHOD_NAME_V6) {
1003
1003
  throw new Error(`Invalid contract method ${contractMethod}`);
@@ -999,7 +999,7 @@ export class CurveV1Factory
999
999
  deadline: NumberAsString,
1000
1000
  partner: string,
1001
1001
  beneficiary: string,
1002
- contractMethod?: string,
1002
+ contractMethod: string,
1003
1003
  ): TxInfo<DirectCurveV1Param> {
1004
1004
  if (contractMethod !== DIRECT_METHOD_NAME) {
1005
1005
  throw new Error(`Invalid contract method ${contractMethod}`);
@@ -1059,7 +1059,7 @@ export class CurveV1Factory
1059
1059
  partnerAndFee: string,
1060
1060
  beneficiary: string,
1061
1061
  blockNumber: number,
1062
- contractMethod?: string,
1062
+ contractMethod: string,
1063
1063
  ) {
1064
1064
  if (contractMethod !== DIRECT_METHOD_NAME_V6) {
1065
1065
  throw new Error(`Invalid contract method ${contractMethod}`);
@@ -213,7 +213,7 @@ export class CurveV2
213
213
  _0: NumberAsString,
214
214
  partner: string,
215
215
  beneficiary: string,
216
- contractMethod?: string,
216
+ contractMethod: string,
217
217
  ): TxInfo<DirectCurveV2Param> {
218
218
  if (contractMethod !== DIRECT_METHOD_NAME) {
219
219
  throw new Error(`Invalid contract method ${contractMethod}`);
@@ -272,7 +272,7 @@ export class CurveV2
272
272
  partnerAndFee: string,
273
273
  beneficiary: string,
274
274
  blockNumber: number,
275
- contractMethod?: string,
275
+ contractMethod: string,
276
276
  ) {
277
277
  if (contractMethod !== DIRECT_METHOD_NAME_V6) {
278
278
  throw new Error(`Invalid contract method ${contractMethod}`);
@@ -221,7 +221,7 @@ export class GenericRFQ extends ParaSwapLimitOrders {
221
221
  partnerAndFee: string,
222
222
  beneficiary: string,
223
223
  blockNumber: number,
224
- contractMethod?: string,
224
+ contractMethod: string,
225
225
  ) {
226
226
  if (!contractMethod) throw new Error(`contractMethod need to be passed`);
227
227
  if (!GenericRFQ.getDirectFunctionNameV6().includes(contractMethod!)) {
package/src/dex/idex.ts CHANGED
@@ -106,7 +106,7 @@ export interface IDexTxBuilder<ExchangeData, DirectParam = null> {
106
106
  deadline: NumberAsString,
107
107
  partner: string,
108
108
  beneficiary: string,
109
- contractMethod?: string,
109
+ contractMethod: string,
110
110
  ): TxInfo<DirectParam>;
111
111
 
112
112
  // Same as above but for V6
@@ -123,7 +123,7 @@ export interface IDexTxBuilder<ExchangeData, DirectParam = null> {
123
123
  partnerAndFee: string,
124
124
  beneficiary: string,
125
125
  blockNumber: number,
126
- contractMethod?: string,
126
+ contractMethod: string,
127
127
  ): TxInfo<DirectParam>;
128
128
  }
129
129
 
@@ -25,24 +25,25 @@ describe('MakerPsm E2E', () => {
25
25
 
26
26
  const tokenASymbol: string = 'USDC';
27
27
  const tokenBSymbol: string = 'DAI';
28
- const nativeTokenSymbol = 'ETH';
29
28
 
30
29
  const tokenAAmount: string = '10000000';
31
30
  const tokenBAmount: string = '10000000000000000';
32
- const nativeTokenAmount: string = '10000000000000000';
33
31
 
34
32
  const sideToContractMethods = new Map([
35
33
  [
36
34
  SwapSide.SELL,
37
35
  [
38
36
  ContractMethod.swapExactAmountIn,
39
- // ContractMethod.simpleSwap,
40
- // ContractMethod.multiSwap,
41
- // ContractMethod.megaSwap,
37
+ ContractMethod.swapExactAmountInOutOnMakerPSM,
38
+ ],
39
+ ],
40
+ [
41
+ SwapSide.BUY,
42
+ [
43
+ ContractMethod.swapExactAmountOut,
44
+ ContractMethod.swapExactAmountInOutOnMakerPSM,
42
45
  ],
43
46
  ],
44
- // [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
45
- [SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
46
47
  ]);
47
48
 
48
49
  sideToContractMethods.forEach((contractMethods, side) =>
@@ -75,32 +76,6 @@ describe('MakerPsm E2E', () => {
75
76
  provider,
76
77
  );
77
78
  });
78
- // it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => {
79
- // await testE2E(
80
- // tokens[nativeTokenSymbol],
81
- // tokens[tokenASymbol],
82
- // holders[nativeTokenSymbol],
83
- // side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount,
84
- // side,
85
- // dexKey,
86
- // contractMethod,
87
- // network,
88
- // provider,
89
- // );
90
- // });
91
- // it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
92
- // await testE2E(
93
- // tokens[tokenASymbol],
94
- // tokens[nativeTokenSymbol],
95
- // holders[tokenASymbol],
96
- // side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
97
- // side,
98
- // dexKey,
99
- // contractMethod,
100
- // network,
101
- // provider,
102
- // );
103
- // });
104
79
  });
105
80
  }),
106
81
  );
@@ -13,14 +13,26 @@ import {
13
13
  Logger,
14
14
  NumberAsString,
15
15
  DexExchangeParam,
16
+ ExchangeTxInfo,
17
+ PreprocessTransactionOptions,
16
18
  } from '../../types';
17
- import { SwapSide, Network } from '../../constants';
19
+ import { SwapSide, Network, NULL_ADDRESS } from '../../constants';
18
20
  import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
19
21
  import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
20
- import { getDexKeysWithNetwork, getBigIntPow } from '../../utils';
22
+ import {
23
+ getDexKeysWithNetwork,
24
+ getBigIntPow,
25
+ uuidToBytes16,
26
+ } from '../../utils';
21
27
  import { IDex } from '../../dex/idex';
22
28
  import { IDexHelper } from '../../dex-helper/idex-helper';
23
- import { MakerPsmData, PoolState, PoolConfig } from './types';
29
+ import {
30
+ MakerPsmData,
31
+ PoolState,
32
+ PoolConfig,
33
+ MakerPsmParams,
34
+ MakerPsmDirectPayload,
35
+ } from './types';
24
36
  import { SimpleExchange } from '../simple-exchange';
25
37
  import { MakerPsmConfig, Adapters } from './config';
26
38
  import PsmABI from '../../abi/maker-psm/psm.json';
@@ -28,7 +40,12 @@ import VatABI from '../../abi/maker-psm/vat.json';
28
40
  import { BI_POWS } from '../../bigint-constants';
29
41
  import { SpecialDex } from '../../executor/types';
30
42
  import { hexConcat, hexZeroPad, hexlify } from '@ethersproject/bytes';
31
- import { ZEROS_12_BYTES } from '../../executor/constants';
43
+ import {
44
+ ContractMethodV6,
45
+ OptimalSwapExchange,
46
+ ParaSwapVersion,
47
+ } from '@paraswap/core';
48
+ import { BigNumber } from 'ethers';
32
49
 
33
50
  const vatInterface = new Interface(VatABI);
34
51
  const psmInterface = new Interface(PsmABI);
@@ -191,7 +208,10 @@ export class MakerPsmEventPool extends StatefulEventSubscriber<PoolState> {
191
208
  }
192
209
  }
193
210
 
194
- export class MakerPsm extends SimpleExchange implements IDex<MakerPsmData> {
211
+ export class MakerPsm
212
+ extends SimpleExchange
213
+ implements IDex<MakerPsmData, MakerPsmDirectPayload>
214
+ {
195
215
  protected eventPools: { [gemAddress: string]: MakerPsmEventPool };
196
216
 
197
217
  // warning: There is limit on swap
@@ -228,6 +248,10 @@ export class MakerPsm extends SimpleExchange implements IDex<MakerPsmData> {
228
248
  );
229
249
  }
230
250
 
251
+ static getDirectFunctionNameV6(): string[] {
252
+ return [ContractMethodV6.swapExactAmountInOutOnMakerPSM];
253
+ }
254
+
231
255
  async initializePricing(blockNumber: number) {
232
256
  const poolStates = await getOnChainState(
233
257
  this.dexHelper.multiContract,
@@ -496,6 +520,46 @@ export class MakerPsm extends SimpleExchange implements IDex<MakerPsmData> {
496
520
  );
497
521
  }
498
522
 
523
+ getTokenFromAddress(address: Address): Token {
524
+ return { address, decimals: 0 };
525
+ }
526
+
527
+ async preProcessTransaction?(
528
+ optimalSwapExchange: OptimalSwapExchange<MakerPsmData>,
529
+ srcToken: Token,
530
+ destToken: Token,
531
+ side: SwapSide,
532
+ options: PreprocessTransactionOptions,
533
+ ): Promise<[OptimalSwapExchange<MakerPsmData>, ExchangeTxInfo]> {
534
+ if (!optimalSwapExchange.data) {
535
+ throw new Error(
536
+ `Error_${this.dexKey}_preProcessTransaction payload is not received`,
537
+ );
538
+ }
539
+
540
+ let isApproved = false;
541
+
542
+ // isApproved is only used in direct method and available only for v6, then no need to check approve for v5
543
+ // because it's either done in getSimpleParam or approve call in the adapter smart contract
544
+ if (options.version === ParaSwapVersion.V6 && options.isDirectMethod) {
545
+ isApproved = await this.dexHelper.augustusApprovals.hasApproval(
546
+ options.executionContractAddress,
547
+ srcToken.address,
548
+ srcToken.address.toLowerCase() === this.dai.address.toLowerCase()
549
+ ? optimalSwapExchange.data.psmAddress
550
+ : optimalSwapExchange.data.gemJoinAddress,
551
+ );
552
+ }
553
+
554
+ return [
555
+ {
556
+ ...optimalSwapExchange,
557
+ data: { ...optimalSwapExchange.data, isApproved },
558
+ },
559
+ {},
560
+ ];
561
+ }
562
+
499
563
  getDexParam(
500
564
  srcToken: Address,
501
565
  destToken: Address,
@@ -544,6 +608,73 @@ export class MakerPsm extends SimpleExchange implements IDex<MakerPsmData> {
544
608
  returnAmountPos: undefined,
545
609
  };
546
610
  }
611
+
612
+ getDirectParamV6(
613
+ srcToken: Address,
614
+ destToken: Address,
615
+ fromAmount: NumberAsString,
616
+ toAmount: NumberAsString,
617
+ quotedAmount: NumberAsString,
618
+ data: MakerPsmData,
619
+ side: SwapSide,
620
+ permit: string,
621
+ uuid: string,
622
+ partnerAndFee: string,
623
+ beneficiary: string,
624
+ blockNumber: number,
625
+ contractMethod: string,
626
+ ) {
627
+ if (!contractMethod) throw new Error(`contractMethod need to be passed`);
628
+ if (!MakerPsm.getDirectFunctionNameV6().includes(contractMethod!)) {
629
+ throw new Error(`Invalid contract method ${contractMethod}`);
630
+ }
631
+
632
+ const beneficiaryParam = BigNumber.from(
633
+ '0x96a18a51d8e8320cba1e4ae45c69fbec0146a14f',
634
+ );
635
+ const approveParam = !data.isApproved
636
+ ? BigNumber.from(1).shl(255)
637
+ : BigNumber.from(0);
638
+ const directionParam =
639
+ side === SwapSide.SELL ? BigNumber.from(0) : BigNumber.from(1).shl(254);
640
+
641
+ const beneficiaryDirectionApproveFlag = beneficiaryParam
642
+ .or(directionParam)
643
+ .or(approveParam);
644
+
645
+ const to18ConversionFactor = getBigIntPow(18 - data.gemDecimals);
646
+
647
+ const metadata = hexConcat([
648
+ hexZeroPad(uuidToBytes16(uuid), 16),
649
+ hexZeroPad(hexlify(blockNumber), 16),
650
+ ]);
651
+
652
+ const params: MakerPsmParams = [
653
+ srcToken,
654
+ // dest token is not used on the contract
655
+ NULL_ADDRESS,
656
+ fromAmount,
657
+ toAmount,
658
+ data.toll,
659
+ to18ConversionFactor.toString(),
660
+ data.psmAddress,
661
+ data.gemJoinAddress,
662
+ metadata,
663
+ beneficiaryDirectionApproveFlag.toString(),
664
+ ];
665
+
666
+ const payload: MakerPsmDirectPayload = [params, permit];
667
+
668
+ const encoder = (...params: (string | MakerPsmDirectPayload)[]) => {
669
+ return this.augustusV6Interface.encodeFunctionData(
670
+ ContractMethodV6.swapExactAmountInOutOnMakerPSM,
671
+ [...params],
672
+ );
673
+ };
674
+
675
+ return { params: payload, encoder, networkFee: '0' };
676
+ }
677
+
547
678
  // Returns list of top pools based on liquidity. Max
548
679
  // limit number pools should be returned.
549
680
  async getTopPoolsForToken(
@@ -0,0 +1,136 @@
1
+ [
2
+ {
3
+ "inputs": [
4
+ { "internalType": "address", "name": "vat_", "type": "address" },
5
+ { "internalType": "bytes32", "name": "ilk_", "type": "bytes32" },
6
+ { "internalType": "address", "name": "gem_", "type": "address" }
7
+ ],
8
+ "stateMutability": "nonpayable",
9
+ "type": "constructor"
10
+ },
11
+ {
12
+ "anonymous": true,
13
+ "inputs": [
14
+ {
15
+ "indexed": true,
16
+ "internalType": "bytes4",
17
+ "name": "sig",
18
+ "type": "bytes4"
19
+ },
20
+ {
21
+ "indexed": true,
22
+ "internalType": "address",
23
+ "name": "usr",
24
+ "type": "address"
25
+ },
26
+ {
27
+ "indexed": true,
28
+ "internalType": "bytes32",
29
+ "name": "arg1",
30
+ "type": "bytes32"
31
+ },
32
+ {
33
+ "indexed": true,
34
+ "internalType": "bytes32",
35
+ "name": "arg2",
36
+ "type": "bytes32"
37
+ },
38
+ {
39
+ "indexed": false,
40
+ "internalType": "bytes",
41
+ "name": "data",
42
+ "type": "bytes"
43
+ }
44
+ ],
45
+ "name": "LogNote",
46
+ "type": "event"
47
+ },
48
+ {
49
+ "inputs": [],
50
+ "name": "cage",
51
+ "outputs": [],
52
+ "stateMutability": "nonpayable",
53
+ "type": "function"
54
+ },
55
+ {
56
+ "inputs": [],
57
+ "name": "dec",
58
+ "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
59
+ "stateMutability": "view",
60
+ "type": "function"
61
+ },
62
+ {
63
+ "inputs": [{ "internalType": "address", "name": "usr", "type": "address" }],
64
+ "name": "deny",
65
+ "outputs": [],
66
+ "stateMutability": "nonpayable",
67
+ "type": "function"
68
+ },
69
+ {
70
+ "inputs": [
71
+ { "internalType": "address", "name": "guy", "type": "address" },
72
+ { "internalType": "uint256", "name": "wad", "type": "uint256" }
73
+ ],
74
+ "name": "exit",
75
+ "outputs": [],
76
+ "stateMutability": "nonpayable",
77
+ "type": "function"
78
+ },
79
+ {
80
+ "inputs": [],
81
+ "name": "gem",
82
+ "outputs": [
83
+ { "internalType": "contract GemLike_2", "name": "", "type": "address" }
84
+ ],
85
+ "stateMutability": "view",
86
+ "type": "function"
87
+ },
88
+ {
89
+ "inputs": [],
90
+ "name": "ilk",
91
+ "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
92
+ "stateMutability": "view",
93
+ "type": "function"
94
+ },
95
+ {
96
+ "inputs": [
97
+ { "internalType": "address", "name": "urn", "type": "address" },
98
+ { "internalType": "uint256", "name": "wad", "type": "uint256" },
99
+ { "internalType": "address", "name": "_msgSender", "type": "address" }
100
+ ],
101
+ "name": "join",
102
+ "outputs": [],
103
+ "stateMutability": "nonpayable",
104
+ "type": "function"
105
+ },
106
+ {
107
+ "inputs": [],
108
+ "name": "live",
109
+ "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
110
+ "stateMutability": "view",
111
+ "type": "function"
112
+ },
113
+ {
114
+ "inputs": [{ "internalType": "address", "name": "usr", "type": "address" }],
115
+ "name": "rely",
116
+ "outputs": [],
117
+ "stateMutability": "nonpayable",
118
+ "type": "function"
119
+ },
120
+ {
121
+ "inputs": [],
122
+ "name": "vat",
123
+ "outputs": [
124
+ { "internalType": "contract VatLike_4", "name": "", "type": "address" }
125
+ ],
126
+ "stateMutability": "view",
127
+ "type": "function"
128
+ },
129
+ {
130
+ "inputs": [{ "internalType": "address", "name": "", "type": "address" }],
131
+ "name": "wards",
132
+ "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
133
+ "stateMutability": "view",
134
+ "type": "function"
135
+ }
136
+ ]