@paraswap/dex-lib 3.5.4-v6.2.1 → 3.5.4
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.
- package/build/config.js +36 -36
- package/build/dex/balancer-v2/balancer-v2.d.ts +2 -2
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/curve-v1/curve-v1.d.ts +2 -2
- package/build/dex/curve-v1/curve-v1.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +2 -2
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v2/curve-v2.d.ts +2 -2
- package/build/dex/curve-v2/curve-v2.js.map +1 -1
- package/build/dex/generic-rfq/generic-rfq.d.ts +1 -1
- package/build/dex/generic-rfq/generic-rfq.js.map +1 -1
- package/build/dex/idex.d.ts +2 -2
- package/build/dex/maker-psm/maker-psm.d.ts +3 -12
- package/build/dex/maker-psm/maker-psm.js +0 -66
- package/build/dex/maker-psm/maker-psm.js.map +1 -1
- package/build/dex/maker-psm/types.d.ts +1 -15
- package/build/dex/uniswap-v2/uniswap-v2.d.ts +2 -2
- package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.d.ts +2 -2
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex/zerox/index.d.ts +1 -1
- package/build/dex/zerox/index.js.map +1 -1
- package/package.json +2 -2
- package/src/config.ts +36 -36
- package/src/dex/balancer-v2/balancer-v2.ts +2 -2
- package/src/dex/curve-v1/curve-v1.ts +2 -2
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +2 -2
- package/src/dex/curve-v2/curve-v2.ts +2 -2
- package/src/dex/generic-rfq/generic-rfq.ts +1 -1
- package/src/dex/idex.ts +2 -2
- package/src/dex/maker-psm/maker-psm-e2e.test.ts +33 -8
- package/src/dex/maker-psm/maker-psm.ts +5 -136
- package/src/dex/maker-psm/types.ts +1 -17
- package/src/dex/uniswap-v2/uniswap-v2.ts +2 -2
- package/src/dex/uniswap-v3/uniswap-v3.ts +2 -2
- package/src/dex/zerox/index.ts +1 -1
- package/tests/constants-e2e.ts +1 -1
|
@@ -25,25 +25,24 @@ describe('MakerPsm E2E', () => {
|
|
|
25
25
|
|
|
26
26
|
const tokenASymbol: string = 'USDC';
|
|
27
27
|
const tokenBSymbol: string = 'DAI';
|
|
28
|
+
const nativeTokenSymbol = 'ETH';
|
|
28
29
|
|
|
29
30
|
const tokenAAmount: string = '10000000';
|
|
30
31
|
const tokenBAmount: string = '10000000000000000';
|
|
32
|
+
const nativeTokenAmount: string = '10000000000000000';
|
|
31
33
|
|
|
32
34
|
const sideToContractMethods = new Map([
|
|
33
35
|
[
|
|
34
36
|
SwapSide.SELL,
|
|
35
37
|
[
|
|
36
38
|
ContractMethod.swapExactAmountIn,
|
|
37
|
-
ContractMethod.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
[
|
|
41
|
-
SwapSide.BUY,
|
|
42
|
-
[
|
|
43
|
-
ContractMethod.swapExactAmountOut,
|
|
44
|
-
ContractMethod.swapExactAmountInOutOnMakerPSM,
|
|
39
|
+
// ContractMethod.simpleSwap,
|
|
40
|
+
// ContractMethod.multiSwap,
|
|
41
|
+
// ContractMethod.megaSwap,
|
|
45
42
|
],
|
|
46
43
|
],
|
|
44
|
+
// [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
|
|
45
|
+
[SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
|
|
47
46
|
]);
|
|
48
47
|
|
|
49
48
|
sideToContractMethods.forEach((contractMethods, side) =>
|
|
@@ -76,6 +75,32 @@ describe('MakerPsm E2E', () => {
|
|
|
76
75
|
provider,
|
|
77
76
|
);
|
|
78
77
|
});
|
|
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
|
+
// });
|
|
79
104
|
});
|
|
80
105
|
}),
|
|
81
106
|
);
|
|
@@ -13,26 +13,14 @@ import {
|
|
|
13
13
|
Logger,
|
|
14
14
|
NumberAsString,
|
|
15
15
|
DexExchangeParam,
|
|
16
|
-
ExchangeTxInfo,
|
|
17
|
-
PreprocessTransactionOptions,
|
|
18
16
|
} from '../../types';
|
|
19
|
-
import { SwapSide, Network
|
|
17
|
+
import { SwapSide, Network } from '../../constants';
|
|
20
18
|
import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
|
|
21
19
|
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
22
|
-
import {
|
|
23
|
-
getDexKeysWithNetwork,
|
|
24
|
-
getBigIntPow,
|
|
25
|
-
uuidToBytes16,
|
|
26
|
-
} from '../../utils';
|
|
20
|
+
import { getDexKeysWithNetwork, getBigIntPow } from '../../utils';
|
|
27
21
|
import { IDex } from '../../dex/idex';
|
|
28
22
|
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
29
|
-
import {
|
|
30
|
-
MakerPsmData,
|
|
31
|
-
PoolState,
|
|
32
|
-
PoolConfig,
|
|
33
|
-
MakerPsmParams,
|
|
34
|
-
MakerPsmDirectPayload,
|
|
35
|
-
} from './types';
|
|
23
|
+
import { MakerPsmData, PoolState, PoolConfig } from './types';
|
|
36
24
|
import { SimpleExchange } from '../simple-exchange';
|
|
37
25
|
import { MakerPsmConfig, Adapters } from './config';
|
|
38
26
|
import PsmABI from '../../abi/maker-psm/psm.json';
|
|
@@ -40,12 +28,7 @@ import VatABI from '../../abi/maker-psm/vat.json';
|
|
|
40
28
|
import { BI_POWS } from '../../bigint-constants';
|
|
41
29
|
import { SpecialDex } from '../../executor/types';
|
|
42
30
|
import { hexConcat, hexZeroPad, hexlify } from '@ethersproject/bytes';
|
|
43
|
-
import {
|
|
44
|
-
ContractMethodV6,
|
|
45
|
-
OptimalSwapExchange,
|
|
46
|
-
ParaSwapVersion,
|
|
47
|
-
} from '@paraswap/core';
|
|
48
|
-
import { BigNumber } from 'ethers';
|
|
31
|
+
import { ZEROS_12_BYTES } from '../../executor/constants';
|
|
49
32
|
|
|
50
33
|
const vatInterface = new Interface(VatABI);
|
|
51
34
|
const psmInterface = new Interface(PsmABI);
|
|
@@ -208,10 +191,7 @@ export class MakerPsmEventPool extends StatefulEventSubscriber<PoolState> {
|
|
|
208
191
|
}
|
|
209
192
|
}
|
|
210
193
|
|
|
211
|
-
export class MakerPsm
|
|
212
|
-
extends SimpleExchange
|
|
213
|
-
implements IDex<MakerPsmData, MakerPsmDirectPayload>
|
|
214
|
-
{
|
|
194
|
+
export class MakerPsm extends SimpleExchange implements IDex<MakerPsmData> {
|
|
215
195
|
protected eventPools: { [gemAddress: string]: MakerPsmEventPool };
|
|
216
196
|
|
|
217
197
|
// warning: There is limit on swap
|
|
@@ -248,10 +228,6 @@ export class MakerPsm
|
|
|
248
228
|
);
|
|
249
229
|
}
|
|
250
230
|
|
|
251
|
-
static getDirectFunctionNameV6(): string[] {
|
|
252
|
-
return [ContractMethodV6.swapExactAmountInOutOnMakerPSM];
|
|
253
|
-
}
|
|
254
|
-
|
|
255
231
|
async initializePricing(blockNumber: number) {
|
|
256
232
|
const poolStates = await getOnChainState(
|
|
257
233
|
this.dexHelper.multiContract,
|
|
@@ -520,46 +496,6 @@ export class MakerPsm
|
|
|
520
496
|
);
|
|
521
497
|
}
|
|
522
498
|
|
|
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
|
-
|
|
563
499
|
getDexParam(
|
|
564
500
|
srcToken: Address,
|
|
565
501
|
destToken: Address,
|
|
@@ -608,73 +544,6 @@ export class MakerPsm
|
|
|
608
544
|
returnAmountPos: undefined,
|
|
609
545
|
};
|
|
610
546
|
}
|
|
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
|
-
|
|
678
547
|
// Returns list of top pools based on liquidity. Max
|
|
679
548
|
// limit number pools should be returned.
|
|
680
549
|
async getTopPoolsForToken(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address,
|
|
1
|
+
import { Address, Token } from '../../types';
|
|
2
2
|
|
|
3
3
|
export type PoolState = {
|
|
4
4
|
tin: bigint; // toll in
|
|
@@ -13,7 +13,6 @@ export type MakerPsmData = {
|
|
|
13
13
|
gemJoinAddress: Address;
|
|
14
14
|
gemDecimals: number;
|
|
15
15
|
toll: string;
|
|
16
|
-
isApproved?: boolean;
|
|
17
16
|
};
|
|
18
17
|
|
|
19
18
|
export type PoolConfig = {
|
|
@@ -28,18 +27,3 @@ export type DexParams = {
|
|
|
28
27
|
vatAddress: Address;
|
|
29
28
|
pools: PoolConfig[];
|
|
30
29
|
};
|
|
31
|
-
|
|
32
|
-
export type MakerPsmParams = [
|
|
33
|
-
srcToken: Address,
|
|
34
|
-
destToken: Address,
|
|
35
|
-
fromAmount: NumberAsString,
|
|
36
|
-
toAmount: NumberAsString,
|
|
37
|
-
toll: NumberAsString,
|
|
38
|
-
to18ConversionFactor: NumberAsString,
|
|
39
|
-
exchange: Address,
|
|
40
|
-
gemJoinAddress: Address,
|
|
41
|
-
metadata: string,
|
|
42
|
-
beneficiaryDirectionApproveFlag: NumberAsString,
|
|
43
|
-
];
|
|
44
|
-
|
|
45
|
-
export type MakerPsmDirectPayload = [params: MakerPsmParams, permit: string];
|
|
@@ -938,7 +938,7 @@ export class UniswapV2
|
|
|
938
938
|
deadline: NumberAsString,
|
|
939
939
|
partner: string,
|
|
940
940
|
beneficiary: string,
|
|
941
|
-
contractMethod
|
|
941
|
+
contractMethod?: string,
|
|
942
942
|
): TxInfo<UniswapParam> {
|
|
943
943
|
if (!contractMethod) throw new Error(`contractMethod need to be passed`);
|
|
944
944
|
if (permit !== '0x') contractMethod += 'WithPermit';
|
|
@@ -1014,7 +1014,7 @@ export class UniswapV2
|
|
|
1014
1014
|
partnerAndFee: string,
|
|
1015
1015
|
beneficiary: string,
|
|
1016
1016
|
blockNumber: number,
|
|
1017
|
-
contractMethod
|
|
1017
|
+
contractMethod?: string,
|
|
1018
1018
|
) {
|
|
1019
1019
|
if (!contractMethod) throw new Error(`contractMethod need to be passed`);
|
|
1020
1020
|
if (!UniswapV2.getDirectFunctionNameV6().includes(contractMethod!)) {
|
|
@@ -960,7 +960,7 @@ export class UniswapV3
|
|
|
960
960
|
deadline: NumberAsString,
|
|
961
961
|
partner: string,
|
|
962
962
|
beneficiary: string,
|
|
963
|
-
contractMethod
|
|
963
|
+
contractMethod?: string,
|
|
964
964
|
): TxInfo<UniswapV3Param> {
|
|
965
965
|
if (!UniswapV3.getDirectFunctionName().includes(contractMethod!)) {
|
|
966
966
|
throw new Error(`Invalid contract method ${contractMethod}`);
|
|
@@ -1023,7 +1023,7 @@ export class UniswapV3
|
|
|
1023
1023
|
partnerAndFee: string,
|
|
1024
1024
|
beneficiary: string,
|
|
1025
1025
|
blockNumber: number,
|
|
1026
|
-
contractMethod
|
|
1026
|
+
contractMethod?: string,
|
|
1027
1027
|
) {
|
|
1028
1028
|
if (!UniswapV3.getDirectFunctionNameV6().includes(contractMethod!)) {
|
|
1029
1029
|
throw new Error(`Invalid contract method ${contractMethod}`);
|
package/src/dex/zerox/index.ts
CHANGED
|
@@ -275,7 +275,7 @@ export class ZeroX
|
|
|
275
275
|
deadline: NumberAsString,
|
|
276
276
|
partner: string,
|
|
277
277
|
beneficiary: string,
|
|
278
|
-
contractMethod
|
|
278
|
+
contractMethod?: string,
|
|
279
279
|
): TxInfo<ZeroXParam> {
|
|
280
280
|
const usePermit = permit !== '0x';
|
|
281
281
|
const encoder = (...params: ZeroXParam) => {
|
package/tests/constants-e2e.ts
CHANGED
|
@@ -1314,7 +1314,7 @@ export const Holders: {
|
|
|
1314
1314
|
CVX: '0x0aCA67Fa70B142A3b9bF2eD89A81B40ff85dACdC',
|
|
1315
1315
|
MIM: '0xa046a8660e66d178ee07ec97c585eeb6aa18c26c',
|
|
1316
1316
|
AnkETH: '0xF7260D4ADc48fEefd5a19a9Eb23f9747CeE15C92',
|
|
1317
|
-
DAI: '
|
|
1317
|
+
DAI: '0x2fEb1512183545f48f6b9C5b4EbfCaF49CfCa6F3',
|
|
1318
1318
|
oldFRAX: '0x183d0dc5867c01bfb1dbbc41d6a9d3de6e044626',
|
|
1319
1319
|
newFRAX: '0x183d0dc5867c01bfb1dbbc41d6a9d3de6e044626',
|
|
1320
1320
|
FEI: '0x19c549357034d10db8d75ed812b45be1dd8a7218',
|