@paraswap/dex-lib 2.18.4 → 2.18.6-swaap-v2
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/.idea/aws.xml +17 -0
- package/.idea/codeStyles/Project.xml +19 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/paraswap-dex-lib.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/build/abi/swaap-v2/vault.json +918 -0
- package/build/config.js +4 -2
- package/build/config.js.map +1 -1
- package/build/dex/hashflow/hashflow.js +8 -19
- package/build/dex/hashflow/hashflow.js.map +1 -1
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/pancakeswap-v3/types.d.ts +14 -0
- package/build/dex/{test-dex → pancakeswap-v3}/types.js.map +1 -1
- package/build/dex/{test-dex → swaap-v2}/config.d.ts +1 -1
- package/build/dex/swaap-v2/config.js +25 -0
- package/build/dex/swaap-v2/config.js.map +1 -0
- package/build/dex/swaap-v2/constants.d.ts +9 -0
- package/build/dex/swaap-v2/constants.js +13 -0
- package/build/dex/swaap-v2/constants.js.map +1 -0
- package/build/dex/swaap-v2/rate-fetcher.d.ts +16 -0
- package/build/dex/swaap-v2/rate-fetcher.js +100 -0
- package/build/dex/swaap-v2/rate-fetcher.js.map +1 -0
- package/build/dex/swaap-v2/swaap-v2.d.ts +55 -0
- package/build/dex/swaap-v2/swaap-v2.js +465 -0
- package/build/dex/swaap-v2/swaap-v2.js.map +1 -0
- package/build/dex/swaap-v2/types.d.ts +64 -0
- package/build/dex/swaap-v2/types.js +7 -0
- package/build/dex/swaap-v2/types.js.map +1 -0
- package/build/dex/swaap-v2/utils.d.ts +7 -0
- package/build/dex/swaap-v2/utils.js +34 -0
- package/build/dex/swaap-v2/utils.js.map +1 -0
- package/build/dex/swaap-v2/validators.d.ts +5 -0
- package/build/dex/swaap-v2/validators.js +120 -0
- package/build/dex/swaap-v2/validators.js.map +1 -0
- package/build/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/abi/swaap-v2/vault.json +918 -0
- package/src/config.ts +5 -2
- package/src/dex/hashflow/hashflow.ts +8 -24
- package/src/dex/index.ts +2 -0
- package/src/dex/swaap-v2/config.ts +25 -0
- package/src/dex/swaap-v2/constants.ts +14 -0
- package/src/dex/swaap-v2/rate-fetcher.ts +164 -0
- package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +199 -0
- package/src/dex/swaap-v2/swaap-v2-integration.test.ts +142 -0
- package/src/dex/swaap-v2/swaap-v2.ts +714 -0
- package/src/dex/swaap-v2/types.ts +74 -0
- package/src/dex/swaap-v2/utils.ts +44 -0
- package/src/dex/swaap-v2/validators.ts +123 -0
- package/src/types.ts +1 -0
- package/tests/constants-e2e.ts +1 -1
- package/tests/utils-e2e.ts +5 -0
- package/build/abi/DirectSwap.json +0 -1018
- package/build/dex/test-dex/config.js +0 -15
- package/build/dex/test-dex/config.js.map +0 -1
- package/build/dex/test-dex/test-dex-pool.d.ts +0 -39
- package/build/dex/test-dex/test-dex-pool.js +0 -63
- package/build/dex/test-dex/test-dex-pool.js.map +0 -1
- package/build/dex/test-dex/test-dex.d.ts +0 -37
- package/build/dex/test-dex/test-dex.js +0 -126
- package/build/dex/test-dex/test-dex.js.map +0 -1
- package/build/dex/test-dex/types.d.ts +0 -6
- package/build/dex/woo-fi-v2/woo-fi-math.d.ts +0 -16
- package/build/dex/woo-fi-v2/woo-fi-math.js +0 -137
- package/build/dex/woo-fi-v2/woo-fi-math.js.map +0 -1
- /package/build/dex/{test-dex → pancakeswap-v3}/types.js +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { RequestHeaders } from '../../dex-helper';
|
|
2
|
+
import { Method } from '../../dex-helper/irequest-wrapper';
|
|
3
|
+
|
|
4
|
+
export type SwaapV2Data = {
|
|
5
|
+
router: string;
|
|
6
|
+
callData: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type DexParams = {
|
|
10
|
+
routerAddress: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export class SwaapV2QuoteError extends Error {}
|
|
14
|
+
|
|
15
|
+
export interface SwaapV2PriceLevel {
|
|
16
|
+
level: number;
|
|
17
|
+
price: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type SwaapV2PriceLevels = {
|
|
21
|
+
bids: Array<SwaapV2PriceLevel>;
|
|
22
|
+
asks: Array<SwaapV2PriceLevel>;
|
|
23
|
+
quote: string;
|
|
24
|
+
base: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type SwaapV2PriceLevelsResponse = {
|
|
28
|
+
levels: Record<string, SwaapV2PriceLevels>;
|
|
29
|
+
success: boolean;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type SwaapV2RateFetcherConfig = {
|
|
33
|
+
rateConfig: {
|
|
34
|
+
pricesReqParams: SwaapV2APIParameters;
|
|
35
|
+
pricesIntervalMs: number;
|
|
36
|
+
pricesCacheTTLSecs: number;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type SwaapV2QuoteResponse = {
|
|
41
|
+
id: string;
|
|
42
|
+
calldata: string;
|
|
43
|
+
router: string;
|
|
44
|
+
expiration: number;
|
|
45
|
+
amount: string;
|
|
46
|
+
recipient: string;
|
|
47
|
+
guaranteed_price: number;
|
|
48
|
+
success: boolean;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export declare enum SwaapV2OrderType {
|
|
52
|
+
SELL = 1,
|
|
53
|
+
BUY = 2,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type SwaapV2QuoteRequest = {
|
|
57
|
+
network_id: number;
|
|
58
|
+
origin: string;
|
|
59
|
+
sender: string;
|
|
60
|
+
recipient: string;
|
|
61
|
+
timestamp: number;
|
|
62
|
+
order_type: SwaapV2OrderType;
|
|
63
|
+
token_in: string;
|
|
64
|
+
token_out: string;
|
|
65
|
+
amount: string;
|
|
66
|
+
tolerance: number;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type SwaapV2APIParameters = {
|
|
70
|
+
url: string;
|
|
71
|
+
headers?: RequestHeaders;
|
|
72
|
+
params?: any;
|
|
73
|
+
method?: Method;
|
|
74
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
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 getCacheKey = (dexKey: string, cacheType: string) => {
|
|
21
|
+
return `${CACHE_PREFIX}_${dexKey}_${cacheType}`.toLowerCase();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const getPriceLevelsCacheKey = (dexKey: string) => {
|
|
25
|
+
return getCacheKey(dexKey, 'price_levels');
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const getPoolIdentifier = (
|
|
29
|
+
dexKey: string,
|
|
30
|
+
srcAddress: Address,
|
|
31
|
+
destAddress: Address,
|
|
32
|
+
) => {
|
|
33
|
+
return `${getIdentifierPrefix(
|
|
34
|
+
dexKey,
|
|
35
|
+
srcAddress,
|
|
36
|
+
destAddress,
|
|
37
|
+
)}`.toLowerCase();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const normalizeTokenAddress = (address: string): string => {
|
|
41
|
+
return address.toLowerCase() === ETHER_ADDRESS
|
|
42
|
+
? NULL_ADDRESS
|
|
43
|
+
: address.toLowerCase();
|
|
44
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
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
|
+
|
|
7
|
+
const priceLevelsValidator = joi.array().items(
|
|
8
|
+
joi.object({
|
|
9
|
+
level: joi.number().required(),
|
|
10
|
+
price: joi.number().required(),
|
|
11
|
+
}),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const ext: joi.Extension = {
|
|
15
|
+
type: 'validatedpriceLevels',
|
|
16
|
+
base: joi.object({
|
|
17
|
+
bids: priceLevelsValidator,
|
|
18
|
+
asks: priceLevelsValidator,
|
|
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 getQuoteResponseValidator = joi
|
|
111
|
+
.object({
|
|
112
|
+
id: joi.string().required(),
|
|
113
|
+
recipient: addressSchema.required().custom(mustBeAugustusSwapper),
|
|
114
|
+
expiration: joi.number().min(0),
|
|
115
|
+
amount: joi
|
|
116
|
+
.string()
|
|
117
|
+
.min(0)
|
|
118
|
+
.custom(stringPositiveBigIntValidator)
|
|
119
|
+
.required(),
|
|
120
|
+
calldata: joi.string().required(),
|
|
121
|
+
success: joi.boolean().required(),
|
|
122
|
+
})
|
|
123
|
+
.unknown(true);
|
package/src/types.ts
CHANGED
package/tests/constants-e2e.ts
CHANGED
|
@@ -901,7 +901,7 @@ export const Holders: {
|
|
|
901
901
|
WETH: '0x72a53cdbbcc1b9efa39c834a540550e23463aacb',
|
|
902
902
|
WMATIC: '0xFffbCD322cEace527C8ec6Da8de2461C6D9d4e6e',
|
|
903
903
|
AMWMATIC: '0x8832924854e3Cedb0a6Abf372e6CCFF9F7654332',
|
|
904
|
-
USDC: '
|
|
904
|
+
USDC: '0xf89d7b9c864f589bbf53a82105107622b35eaa40',
|
|
905
905
|
POPS: '0x2693b57ee51f4e2a26dfb339a911fa8731061f49',
|
|
906
906
|
MUST: '0x9f2a409848fb9b7bd058b24a23e8dbf1e166a109',
|
|
907
907
|
AMDAI: '0xFA0DCe8280FCDf369a4cbFc1830d3302789307a6',
|
package/tests/utils-e2e.ts
CHANGED
|
@@ -189,6 +189,7 @@ export async function testE2E(
|
|
|
189
189
|
transferFees?: TransferFeeParams,
|
|
190
190
|
// Specified in BPS: part of 10000
|
|
191
191
|
slippage?: number,
|
|
192
|
+
sleepMs?: number,
|
|
192
193
|
) {
|
|
193
194
|
const amount = BigInt(_amount);
|
|
194
195
|
const ts = new TenderlySimulation(network);
|
|
@@ -231,6 +232,10 @@ export async function testE2E(
|
|
|
231
232
|
: new LocalParaswapSDK(network, dexKey, '', limitOrderProvider);
|
|
232
233
|
|
|
233
234
|
if (paraswap.initializePricing) await paraswap.initializePricing();
|
|
235
|
+
|
|
236
|
+
if (sleepMs) {
|
|
237
|
+
await sleep(sleepMs);
|
|
238
|
+
}
|
|
234
239
|
|
|
235
240
|
if (paraswap.dexHelper?.replaceProviderWithRPC) {
|
|
236
241
|
paraswap.dexHelper?.replaceProviderWithRPC(
|