@paraswap/dex-lib 2.21.0 → 2.21.1-chronos
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 +2 -4
- package/build/config.js.map +1 -1
- package/build/dex/balancer-v2/balancer-v2.d.ts +3 -9
- package/build/dex/balancer-v2/balancer-v2.js +0 -83
- package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
- package/build/dex/balancer-v2/constants.d.ts +0 -4
- package/build/dex/balancer-v2/constants.js +1 -6
- package/build/dex/balancer-v2/constants.js.map +1 -1
- package/build/dex/balancer-v2/types.d.ts +1 -20
- package/build/dex/balancer-v2/types.js.map +1 -1
- package/build/dex/curve-v1/constants.d.ts +0 -1
- package/build/dex/curve-v1/constants.js +1 -2
- package/build/dex/curve-v1/constants.js.map +1 -1
- package/build/dex/curve-v1/curve-v1.d.ts +3 -9
- package/build/dex/curve-v1/curve-v1.js +4 -92
- package/build/dex/curve-v1/curve-v1.js.map +1 -1
- package/build/dex/curve-v1/types.d.ts +0 -24
- package/build/dex/curve-v1/types.js +1 -6
- package/build/dex/curve-v1/types.js.map +1 -1
- package/build/dex/curve-v1-factory/constants.d.ts +0 -1
- package/build/dex/curve-v1-factory/constants.js +1 -2
- package/build/dex/curve-v1-factory/constants.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +4 -11
- package/build/dex/curve-v1-factory/curve-v1-factory.js +0 -87
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/types.d.ts +0 -24
- package/build/dex/curve-v1-factory/types.js +1 -6
- package/build/dex/curve-v1-factory/types.js.map +1 -1
- package/build/dex/curve-v2.d.ts +7 -29
- package/build/dex/curve-v2.js +1 -91
- package/build/dex/curve-v2.js.map +1 -1
- package/build/dex/idex.d.ts +1 -1
- package/build/dex/index.js +2 -4
- package/build/dex/index.js.map +1 -1
- package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +2 -2
- package/build/dex/pancakeswap-v3/utils.js.map +1 -1
- package/build/dex/quickswap/config.js +0 -8
- package/build/dex/quickswap/config.js.map +1 -1
- package/build/dex/simple-exchange.d.ts +0 -2
- package/build/dex/simple-exchange.js +0 -1
- package/build/dex/simple-exchange.js.map +1 -1
- package/build/dex/solidly/config.js +13 -0
- package/build/dex/solidly/config.js.map +1 -1
- package/build/dex/solidly/forks-override/chronos.d.ts +3 -0
- package/build/dex/solidly/forks-override/chronos.js +88 -0
- package/build/dex/solidly/forks-override/chronos.js.map +1 -1
- package/build/dex/solidly/solidly.js +1 -0
- package/build/dex/solidly/solidly.js.map +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.d.ts +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.js +1 -1
- package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
- package/build/dex/uniswap-v3/constants.d.ts +0 -4
- package/build/dex/uniswap-v3/constants.js +1 -6
- package/build/dex/uniswap-v3/constants.js.map +1 -1
- package/build/dex/uniswap-v3/types.d.ts +3 -20
- package/build/dex/uniswap-v3/types.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3.d.ts +1 -7
- package/build/dex/uniswap-v3/uniswap-v3.js +1 -85
- package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
- package/build/dex/woo-fi-v2/config.js +6 -6
- package/build/dex/zerox/index.d.ts +1 -1
- package/build/dex/zerox/index.js +1 -1
- package/build/dex/zerox/index.js.map +1 -1
- package/build/implementations/local-paraswap-sdk.js +1 -5
- package/build/implementations/local-paraswap-sdk.js.map +1 -1
- package/build/router/directswap.js +1 -7
- package/build/router/directswap.js.map +1 -1
- package/build/router/index.js.map +1 -1
- package/build/router/payload-encoder.js +6 -16
- package/build/router/payload-encoder.js.map +1 -1
- package/build/types.d.ts +0 -2
- package/build/utils.d.ts +0 -2
- package/build/utils.js +1 -5
- package/build/utils.js.map +1 -1
- package/package.json +4 -6
- package/src/config.ts +2 -5
- package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +0 -79
- package/src/dex/balancer-v2/balancer-v2.ts +4 -153
- package/src/dex/balancer-v2/constants.ts +0 -5
- package/src/dex/balancer-v2/types.ts +1 -21
- package/src/dex/curve-v1/constants.ts +0 -2
- package/src/dex/curve-v1/curve-v1-e2e.test.ts +0 -57
- package/src/dex/curve-v1/curve-v1.ts +5 -144
- package/src/dex/curve-v1/types.ts +0 -26
- package/src/dex/curve-v1-factory/constants.ts +0 -2
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +0 -1
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +4 -140
- package/src/dex/curve-v1-factory/types.ts +0 -26
- package/src/dex/curve-v2.ts +8 -169
- package/src/dex/idex.ts +0 -6
- package/src/dex/index.ts +2 -4
- package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +6 -3
- package/src/dex/pancakeswap-v3/pancakeswap-v3-integration.test.ts +14 -3
- package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +3 -3
- package/src/dex/pancakeswap-v3/utils.ts +4 -1
- package/src/dex/quickswap/config.ts +0 -9
- package/src/dex/quickswap/quickswap-e2e.test.ts +0 -109
- package/src/dex/simple-exchange.ts +0 -6
- package/src/dex/solidly/config.ts +14 -0
- package/src/dex/solidly/forks-override/chronos.ts +206 -0
- package/src/dex/solidly/solidly-e2e.test.ts +205 -31
- package/src/dex/solidly/solidly-integration.test.ts +141 -0
- package/src/dex/solidly/solidly.ts +1 -0
- package/src/dex/uniswap-v2/uniswap-v2.ts +0 -6
- package/src/dex/uniswap-v3/constants.ts +0 -5
- package/src/dex/uniswap-v3/types.ts +3 -23
- package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +2 -100
- package/src/dex/uniswap-v3/uniswap-v3.ts +3 -138
- package/src/dex/woo-fi-v2/config.ts +6 -6
- package/src/dex/zerox/index.ts +0 -7
- package/src/implementations/local-paraswap-sdk.ts +1 -8
- package/src/router/directswap.ts +0 -23
- package/src/router/index.ts +2 -0
- package/src/router/payload-encoder.ts +5 -22
- package/src/types.ts +0 -2
- package/src/utils.ts +0 -5
- package/tests/constants-e2e.ts +9 -4
- package/tests/utils-e2e.ts +20 -140
- package/tests/utils.ts +0 -52
- package/src/abi/DirectSwap.json +0 -1018
- package/src/abi/swaap-v2/vault.json +0 -918
- package/src/dex/quickswap/camelot-v3.ts +0 -15
- package/src/dex/swaap-v2/config.ts +0 -19
- package/src/dex/swaap-v2/constants.ts +0 -37
- package/src/dex/swaap-v2/rate-fetcher.ts +0 -214
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +0 -172
- package/src/dex/swaap-v2/swaap-v2-integration.test.ts +0 -142
- package/src/dex/swaap-v2/swaap-v2.ts +0 -901
- package/src/dex/swaap-v2/types.ts +0 -95
- package/src/dex/swaap-v2/utils.ts +0 -36
- package/src/dex/swaap-v2/validators.ts +0 -128
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { RequestHeaders } from '../../dex-helper';
|
|
2
|
-
import { Method } from '../../dex-helper/irequest-wrapper';
|
|
3
|
-
import { Token } from '../../types';
|
|
4
|
-
|
|
5
|
-
export type SwaapV2Data = {
|
|
6
|
-
router: string;
|
|
7
|
-
callData: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type DexParams = {};
|
|
11
|
-
|
|
12
|
-
export class SwaapV2QuoteError extends Error {}
|
|
13
|
-
|
|
14
|
-
export interface SwaapV2PriceLevel {
|
|
15
|
-
level: number;
|
|
16
|
-
price: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type SwaapV2PriceLevels = {
|
|
20
|
-
bids: Array<SwaapV2PriceLevel>;
|
|
21
|
-
asks: Array<SwaapV2PriceLevel>;
|
|
22
|
-
quote: string;
|
|
23
|
-
base: string;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type SwaapV2PriceLevelsResponse = {
|
|
27
|
-
levels: Record<string, SwaapV2PriceLevels>;
|
|
28
|
-
success: boolean;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type SwaapV2RateFetcherConfig = {
|
|
32
|
-
rateConfig: {
|
|
33
|
-
pricesReqParams: SwaapV2APIParameters;
|
|
34
|
-
pricesIntervalMs: number;
|
|
35
|
-
pricesCacheTTLSecs: number;
|
|
36
|
-
pricesCacheKey: string;
|
|
37
|
-
};
|
|
38
|
-
tokensConfig: {
|
|
39
|
-
tokensReqParams: SwaapV2APIParameters;
|
|
40
|
-
tokensIntervalMs: number;
|
|
41
|
-
tokensCacheTTLSecs: number;
|
|
42
|
-
tokensCacheKey: string;
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export type SwaapV2TokensResponse = {
|
|
47
|
-
tokens: {
|
|
48
|
-
[address: string]: {
|
|
49
|
-
symbol: string;
|
|
50
|
-
address: string;
|
|
51
|
-
decimals: number;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
success: boolean;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export type SwaapV2QuoteResponse = {
|
|
58
|
-
id: string;
|
|
59
|
-
calldata: string;
|
|
60
|
-
router: string;
|
|
61
|
-
expiration: number;
|
|
62
|
-
amount: string;
|
|
63
|
-
recipient: string;
|
|
64
|
-
guaranteed_price: number;
|
|
65
|
-
success: boolean;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export declare enum SwaapV2OrderType {
|
|
69
|
-
SELL = 1,
|
|
70
|
-
BUY = 2,
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export type SwaapV2QuoteRequest = {
|
|
74
|
-
network_id: number;
|
|
75
|
-
origin: string;
|
|
76
|
-
sender: string;
|
|
77
|
-
recipient: string;
|
|
78
|
-
timestamp: number;
|
|
79
|
-
order_type: SwaapV2OrderType;
|
|
80
|
-
token_in: string;
|
|
81
|
-
token_out: string;
|
|
82
|
-
amount: string;
|
|
83
|
-
tolerance: number;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export type SwaapV2APIParameters = {
|
|
87
|
-
url: string;
|
|
88
|
-
headers?: RequestHeaders;
|
|
89
|
-
params?: any;
|
|
90
|
-
method?: Method;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export type TokensMap = {
|
|
94
|
-
[address: string]: Token;
|
|
95
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Address } from '../../types';
|
|
2
|
-
import { CACHE_PREFIX, ETHER_ADDRESS, NULL_ADDRESS } from '../../constants';
|
|
3
|
-
|
|
4
|
-
export const getIdentifierPrefix = (
|
|
5
|
-
dexKey: string,
|
|
6
|
-
srcAddress: Address,
|
|
7
|
-
destAddress: Address,
|
|
8
|
-
) => {
|
|
9
|
-
return `${dexKey}_${getPairName(srcAddress, destAddress)}`.toLowerCase();
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const getPairName = (srcAddress: Address, destAddress: Address) => {
|
|
13
|
-
const sortedAddresses =
|
|
14
|
-
srcAddress < destAddress
|
|
15
|
-
? [srcAddress, destAddress]
|
|
16
|
-
: [destAddress, srcAddress];
|
|
17
|
-
return `${sortedAddresses[0]}_${sortedAddresses[1]}`.toLowerCase();
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const getPoolIdentifier = (
|
|
21
|
-
dexKey: string,
|
|
22
|
-
srcAddress: Address,
|
|
23
|
-
destAddress: Address,
|
|
24
|
-
) => {
|
|
25
|
-
return `${getIdentifierPrefix(
|
|
26
|
-
dexKey,
|
|
27
|
-
srcAddress,
|
|
28
|
-
destAddress,
|
|
29
|
-
)}`.toLowerCase();
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const normalizeTokenAddress = (address: string): string => {
|
|
33
|
-
return address.toLowerCase() === ETHER_ADDRESS.toLowerCase()
|
|
34
|
-
? NULL_ADDRESS
|
|
35
|
-
: address.toLowerCase();
|
|
36
|
-
};
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
import joi, { CustomHelpers, ErrorReport } from 'joi';
|
|
3
|
-
import * as ethers from 'ethers';
|
|
4
|
-
import { SwaapV2PriceLevel } from './types';
|
|
5
|
-
|
|
6
|
-
const priceLevelsValidator = joi.array().items(
|
|
7
|
-
joi.object({
|
|
8
|
-
level: joi.number().required(),
|
|
9
|
-
price: joi.number().required(),
|
|
10
|
-
}),
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
const ext: joi.Extension = {
|
|
14
|
-
type: 'validatedpriceLevels',
|
|
15
|
-
base: joi.object({
|
|
16
|
-
bids: priceLevelsValidator,
|
|
17
|
-
asks: priceLevelsValidator,
|
|
18
|
-
liquidityUSD: joi.number(),
|
|
19
|
-
}),
|
|
20
|
-
rules: {
|
|
21
|
-
bidsLowerThanAsks: {
|
|
22
|
-
validate: (
|
|
23
|
-
values: { bids: SwaapV2PriceLevel[]; asks: SwaapV2PriceLevel[] },
|
|
24
|
-
helpers: CustomHelpers,
|
|
25
|
-
) => {
|
|
26
|
-
if (
|
|
27
|
-
!values.bids ||
|
|
28
|
-
!values.asks ||
|
|
29
|
-
values.bids.length === 0 ||
|
|
30
|
-
values.asks.length === 0
|
|
31
|
-
) {
|
|
32
|
-
return values;
|
|
33
|
-
}
|
|
34
|
-
const maxBid = values.bids
|
|
35
|
-
.map(pl => new BigNumber(pl.price))
|
|
36
|
-
.reduce(
|
|
37
|
-
(previousValue, currentValue) =>
|
|
38
|
-
currentValue.gte(previousValue) ? currentValue : previousValue,
|
|
39
|
-
new BigNumber(0),
|
|
40
|
-
);
|
|
41
|
-
const minAsk = values.asks
|
|
42
|
-
.map(pl => new BigNumber(pl.price))
|
|
43
|
-
.reduce(
|
|
44
|
-
(previousValue, currentValue) =>
|
|
45
|
-
currentValue.lte(previousValue) ? currentValue : previousValue,
|
|
46
|
-
new BigNumber('123456789012345678901234567890'),
|
|
47
|
-
);
|
|
48
|
-
return maxBid < minAsk
|
|
49
|
-
? values
|
|
50
|
-
: helpers.message({
|
|
51
|
-
custom: 'the maximum bid is higher than minimum ask',
|
|
52
|
-
});
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const priceLevelsResponseValidator = joi.object({
|
|
59
|
-
levels: joi
|
|
60
|
-
.object()
|
|
61
|
-
.pattern(
|
|
62
|
-
joi.string().min(1),
|
|
63
|
-
joi.extend(ext).validatedpriceLevels().bidsLowerThanAsks(),
|
|
64
|
-
),
|
|
65
|
-
success: joi.boolean().required(),
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
export const addressSchema = joi.string().custom((value, helpers) => {
|
|
69
|
-
if (ethers.utils.isAddress(value)) {
|
|
70
|
-
return value.toLowerCase();
|
|
71
|
-
}
|
|
72
|
-
return helpers.message({ custom: `'${value}' is not valid address` });
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
export const blacklistResponseValidator = joi.object({
|
|
76
|
-
blacklist: joi.array().items(addressSchema),
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const stringPositiveBigIntValidator = (
|
|
80
|
-
value: string,
|
|
81
|
-
helpers: CustomHelpers,
|
|
82
|
-
): string | ErrorReport => {
|
|
83
|
-
try {
|
|
84
|
-
const val = BigInt(value);
|
|
85
|
-
if (val < 0) {
|
|
86
|
-
return helpers.message({ custom: `${value} is < 0` });
|
|
87
|
-
}
|
|
88
|
-
return value;
|
|
89
|
-
} catch (e) {
|
|
90
|
-
return helpers.message({
|
|
91
|
-
custom: `${value} is not castable to BigInt`,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const mustBeAugustusSwapper = (
|
|
97
|
-
value: string,
|
|
98
|
-
helpers: CustomHelpers,
|
|
99
|
-
): string | ErrorReport => {
|
|
100
|
-
const allowedTakers = [
|
|
101
|
-
'0xDEF171Fe48CF0115B1d80b88dc8eAB59176FEe57'.toLowerCase(),
|
|
102
|
-
];
|
|
103
|
-
return allowedTakers.includes(value.toLowerCase())
|
|
104
|
-
? value
|
|
105
|
-
: helpers.message({
|
|
106
|
-
custom: `"order.taker" must be any of ${JSON.stringify(allowedTakers)}`,
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export const getTokensResponseValidator = joi.object({
|
|
111
|
-
tokens: joi.object().required(),
|
|
112
|
-
success: joi.boolean().required(),
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
export const getQuoteResponseValidator = joi
|
|
116
|
-
.object({
|
|
117
|
-
id: joi.string().required(),
|
|
118
|
-
recipient: addressSchema.required().custom(mustBeAugustusSwapper),
|
|
119
|
-
expiration: joi.number().min(0),
|
|
120
|
-
amount: joi
|
|
121
|
-
.string()
|
|
122
|
-
.min(0)
|
|
123
|
-
.custom(stringPositiveBigIntValidator)
|
|
124
|
-
.required(),
|
|
125
|
-
calldata: joi.string().required(),
|
|
126
|
-
success: joi.boolean().required(),
|
|
127
|
-
})
|
|
128
|
-
.unknown(true);
|