@paraswap/dex-lib 2.20.3 → 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.
Files changed (144) hide show
  1. package/.idea/aws.xml +17 -0
  2. package/.idea/codeStyles/Project.xml +19 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/paraswap-dex-lib.iml +9 -0
  7. package/.idea/vcs.xml +6 -0
  8. package/build/config.js +2 -4
  9. package/build/config.js.map +1 -1
  10. package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
  11. package/build/dex/aave-v3/tokens/avalanche.json +74 -0
  12. package/build/dex/aave-v3/tokens/fantom.json +62 -0
  13. package/build/dex/aave-v3/tokens/optimism.json +50 -0
  14. package/build/dex/aave-v3/tokens/polygon.json +116 -0
  15. package/build/dex/balancer-v2/balancer-v2.d.ts +3 -9
  16. package/build/dex/balancer-v2/balancer-v2.js +0 -83
  17. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  18. package/build/dex/balancer-v2/constants.d.ts +0 -4
  19. package/build/dex/balancer-v2/constants.js +1 -6
  20. package/build/dex/balancer-v2/constants.js.map +1 -1
  21. package/build/dex/balancer-v2/types.d.ts +1 -20
  22. package/build/dex/balancer-v2/types.js.map +1 -1
  23. package/build/dex/curve-v1/constants.d.ts +0 -1
  24. package/build/dex/curve-v1/constants.js +1 -2
  25. package/build/dex/curve-v1/constants.js.map +1 -1
  26. package/build/dex/curve-v1/curve-v1.d.ts +3 -9
  27. package/build/dex/curve-v1/curve-v1.js +4 -92
  28. package/build/dex/curve-v1/curve-v1.js.map +1 -1
  29. package/build/dex/curve-v1/types.d.ts +0 -24
  30. package/build/dex/curve-v1/types.js +1 -6
  31. package/build/dex/curve-v1/types.js.map +1 -1
  32. package/build/dex/curve-v1-factory/constants.d.ts +0 -1
  33. package/build/dex/curve-v1-factory/constants.js +1 -2
  34. package/build/dex/curve-v1-factory/constants.js.map +1 -1
  35. package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +4 -11
  36. package/build/dex/curve-v1-factory/curve-v1-factory.js +0 -87
  37. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  38. package/build/dex/curve-v1-factory/types.d.ts +0 -24
  39. package/build/dex/curve-v1-factory/types.js +1 -6
  40. package/build/dex/curve-v1-factory/types.js.map +1 -1
  41. package/build/dex/curve-v2.d.ts +7 -29
  42. package/build/dex/curve-v2.js +1 -91
  43. package/build/dex/curve-v2.js.map +1 -1
  44. package/build/dex/idex.d.ts +1 -1
  45. package/build/dex/index.js +2 -2
  46. package/build/dex/index.js.map +1 -1
  47. package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +2 -2
  48. package/build/dex/pancakeswap-v3/types.d.ts +14 -0
  49. package/build/dex/pancakeswap-v3/types.js +3 -0
  50. package/build/dex/pancakeswap-v3/types.js.map +1 -0
  51. package/build/dex/pancakeswap-v3/utils.js.map +1 -1
  52. package/build/dex/quickswap/camelot-v3.d.ts +6 -0
  53. package/build/dex/quickswap/camelot-v3.js +19 -0
  54. package/build/dex/quickswap/camelot-v3.js.map +1 -0
  55. package/build/dex/simple-exchange.d.ts +0 -2
  56. package/build/dex/simple-exchange.js +0 -1
  57. package/build/dex/simple-exchange.js.map +1 -1
  58. package/build/dex/solidly/config.js +13 -0
  59. package/build/dex/solidly/config.js.map +1 -1
  60. package/build/dex/solidly/forks-override/chronos.d.ts +23 -0
  61. package/build/dex/solidly/forks-override/chronos.js +132 -0
  62. package/build/dex/solidly/forks-override/chronos.js.map +1 -0
  63. package/build/dex/solidly/solidly.js +1 -0
  64. package/build/dex/solidly/solidly.js.map +1 -1
  65. package/build/dex/uniswap-v2/uniswap-v2.d.ts +1 -1
  66. package/build/dex/uniswap-v2/uniswap-v2.js +1 -1
  67. package/build/dex/uniswap-v2/uniswap-v2.js.map +1 -1
  68. package/build/dex/uniswap-v3/constants.d.ts +0 -4
  69. package/build/dex/uniswap-v3/constants.js +1 -6
  70. package/build/dex/uniswap-v3/constants.js.map +1 -1
  71. package/build/dex/uniswap-v3/types.d.ts +3 -20
  72. package/build/dex/uniswap-v3/types.js.map +1 -1
  73. package/build/dex/uniswap-v3/uniswap-v3.d.ts +1 -7
  74. package/build/dex/uniswap-v3/uniswap-v3.js +1 -85
  75. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  76. package/build/dex/woo-fi-v2/config.js +6 -6
  77. package/build/dex/zerox/index.d.ts +1 -1
  78. package/build/dex/zerox/index.js +1 -1
  79. package/build/dex/zerox/index.js.map +1 -1
  80. package/build/implementations/local-paraswap-sdk.js +1 -5
  81. package/build/implementations/local-paraswap-sdk.js.map +1 -1
  82. package/build/router/directswap.js +1 -7
  83. package/build/router/directswap.js.map +1 -1
  84. package/build/router/index.js.map +1 -1
  85. package/build/router/payload-encoder.js +6 -16
  86. package/build/router/payload-encoder.js.map +1 -1
  87. package/build/types.d.ts +0 -2
  88. package/build/utils.d.ts +0 -2
  89. package/build/utils.js +1 -5
  90. package/build/utils.js.map +1 -1
  91. package/package.json +4 -6
  92. package/src/config.ts +2 -5
  93. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +0 -79
  94. package/src/dex/balancer-v2/balancer-v2.ts +4 -153
  95. package/src/dex/balancer-v2/constants.ts +0 -5
  96. package/src/dex/balancer-v2/types.ts +1 -21
  97. package/src/dex/curve-v1/constants.ts +0 -2
  98. package/src/dex/curve-v1/curve-v1-e2e.test.ts +0 -57
  99. package/src/dex/curve-v1/curve-v1.ts +5 -144
  100. package/src/dex/curve-v1/types.ts +0 -26
  101. package/src/dex/curve-v1-factory/constants.ts +0 -2
  102. package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +0 -1
  103. package/src/dex/curve-v1-factory/curve-v1-factory.ts +4 -140
  104. package/src/dex/curve-v1-factory/types.ts +0 -26
  105. package/src/dex/curve-v2.ts +8 -169
  106. package/src/dex/idex.ts +0 -6
  107. package/src/dex/index.ts +2 -2
  108. package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +6 -3
  109. package/src/dex/pancakeswap-v3/pancakeswap-v3-integration.test.ts +14 -3
  110. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +3 -3
  111. package/src/dex/pancakeswap-v3/utils.ts +4 -1
  112. package/src/dex/simple-exchange.ts +0 -6
  113. package/src/dex/solidly/config.ts +14 -0
  114. package/src/dex/solidly/forks-override/chronos.ts +206 -0
  115. package/src/dex/solidly/solidly-e2e.test.ts +205 -31
  116. package/src/dex/solidly/solidly-integration.test.ts +141 -0
  117. package/src/dex/solidly/solidly.ts +1 -0
  118. package/src/dex/uniswap-v2/uniswap-v2.ts +0 -6
  119. package/src/dex/uniswap-v3/constants.ts +0 -5
  120. package/src/dex/uniswap-v3/types.ts +3 -23
  121. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +2 -100
  122. package/src/dex/uniswap-v3/uniswap-v3.ts +3 -138
  123. package/src/dex/woo-fi-v2/config.ts +6 -6
  124. package/src/dex/zerox/index.ts +0 -7
  125. package/src/implementations/local-paraswap-sdk.ts +1 -8
  126. package/src/router/directswap.ts +0 -23
  127. package/src/router/index.ts +2 -0
  128. package/src/router/payload-encoder.ts +5 -22
  129. package/src/types.ts +0 -2
  130. package/src/utils.ts +0 -5
  131. package/tests/constants-e2e.ts +9 -4
  132. package/tests/utils-e2e.ts +20 -140
  133. package/tests/utils.ts +0 -52
  134. package/src/abi/DirectSwap.json +0 -1018
  135. package/src/abi/swaap-v2/vault.json +0 -918
  136. package/src/dex/swaap-v2/config.ts +0 -19
  137. package/src/dex/swaap-v2/constants.ts +0 -37
  138. package/src/dex/swaap-v2/rate-fetcher.ts +0 -214
  139. package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +0 -172
  140. package/src/dex/swaap-v2/swaap-v2-integration.test.ts +0 -142
  141. package/src/dex/swaap-v2/swaap-v2.ts +0 -901
  142. package/src/dex/swaap-v2/types.ts +0 -95
  143. package/src/dex/swaap-v2/utils.ts +0 -36
  144. 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);