@paraswap/dex-lib 4.0.3 → 4.0.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/.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/prettier.xml +7 -0
- package/.idea/vcs.xml +6 -0
- package/build/abi/integral/factory.json +333 -0
- package/build/abi/integral/oracle.json +501 -0
- package/build/abi/{inception/inception-ineth-pool.json → integral/pool.json} +522 -543
- package/build/abi/{wombat/pool.json → integral/relayer.json} +720 -473
- package/build/dex/aave-v1/aave-v1.d.ts +1 -2
- package/build/dex/aave-v1/aave-v1.js +0 -23
- package/build/dex/aave-v1/aave-v1.js.map +1 -1
- package/build/dex/bebop/bebop.js +1 -1
- package/build/dex/bebop/bebop.js.map +1 -1
- package/build/dex/cables/cables.d.ts +4 -2
- package/build/dex/cables/cables.js +90 -155
- package/build/dex/cables/cables.js.map +1 -1
- package/build/dex/cables/constants.d.ts +0 -1
- package/build/dex/cables/constants.js +2 -3
- package/build/dex/cables/constants.js.map +1 -1
- package/build/dex/cables/rate-fetcher.js +26 -10
- package/build/dex/cables/rate-fetcher.js.map +1 -1
- package/build/dex/cables/types.d.ts +15 -28
- package/build/dex/cables/types.js +2 -13
- package/build/dex/cables/types.js.map +1 -1
- package/build/dex/dexalot/dexalot.js.map +1 -1
- package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +49 -0
- package/build/dex/fluid-dex/fluid-dex-generate-pool.js +104 -0
- package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +1 -0
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/integral/config.d.ts +4 -0
- package/build/dex/integral/config.js +20 -0
- package/build/dex/integral/config.js.map +1 -0
- package/build/dex/integral/context.d.ts +40 -0
- package/build/dex/integral/context.js +158 -0
- package/build/dex/integral/context.js.map +1 -0
- package/build/dex/integral/integral-factory.d.ts +24 -0
- package/build/dex/integral/integral-factory.js +95 -0
- package/build/dex/integral/integral-factory.js.map +1 -0
- package/build/dex/integral/integral-pool.d.ts +50 -0
- package/build/dex/integral/integral-pool.js +149 -0
- package/build/dex/integral/integral-pool.js.map +1 -0
- package/build/dex/integral/integral-pricing.d.ts +18 -0
- package/build/dex/integral/integral-pricing.js +114 -0
- package/build/dex/integral/integral-pricing.js.map +1 -0
- package/build/dex/integral/integral-relayer.d.ts +42 -0
- package/build/dex/integral/integral-relayer.js +192 -0
- package/build/dex/integral/integral-relayer.js.map +1 -0
- package/build/dex/integral/integral-token.d.ts +27 -0
- package/build/dex/integral/integral-token.js +59 -0
- package/build/dex/integral/integral-token.js.map +1 -0
- package/build/dex/integral/integral.d.ts +41 -0
- package/build/dex/integral/integral.js +376 -0
- package/build/dex/integral/integral.js.map +1 -0
- package/build/dex/integral/types.d.ts +85 -0
- package/build/dex/integral/types.js +9 -0
- package/build/dex/integral/types.js.map +1 -0
- package/build/dex/integral/utils-e2e.d.ts +9 -0
- package/build/dex/integral/utils-e2e.js +131 -0
- package/build/dex/integral/utils-e2e.js.map +1 -0
- package/build/dex/integral/utils.d.ts +17 -0
- package/build/dex/integral/utils.js +94 -0
- package/build/dex/integral/utils.js.map +1 -0
- package/build/dex/jarvis.d.ts +1 -2
- package/build/dex/jarvis.js +0 -58
- package/build/dex/jarvis.js.map +1 -1
- package/build/dex/platypus/platypus.d.ts +1 -2
- package/build/dex/platypus/platypus.js +0 -45
- package/build/dex/platypus/platypus.js.map +1 -1
- package/build/dex/stable-pool.js +8 -1
- package/build/dex/stable-pool.js.map +1 -1
- package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
- package/build/dex/swaap-v1/swaap-v1.js +0 -14
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
- package/build/dex/trader-joe-v2.1/optimizer.d.ts +2 -0
- package/build/dex/trader-joe-v2.1/optimizer.js +47 -0
- package/build/dex/trader-joe-v2.1/optimizer.js.map +1 -0
- package/build/dex/zerox/index.d.ts +26 -4
- package/build/dex/zerox/index.js +42 -50
- package/build/dex/zerox/index.js.map +1 -1
- package/build/dex/zerox/types.d.ts +0 -29
- package/build/dex/zerox/types.js +1 -8
- package/build/dex/zerox/types.js.map +1 -1
- package/build/executor/Executor01BytecodeBuilder.js +11 -6
- package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor02BytecodeBuilder.js +11 -6
- package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor03BytecodeBuilder.js +11 -6
- package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
- package/build/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/abi/cables/CablesMainnetRFQ.json +1083 -0
- package/src/dex/bebop/bebop.ts +1 -1
- package/src/dex/cables/cables-e2e.test.ts +207 -0
- package/src/dex/cables/cables-integration.test.ts +391 -0
- package/src/dex/cables/cables.ts +823 -0
- package/src/dex/cables/config.ts +13 -0
- package/src/dex/cables/constants.ts +33 -0
- package/src/dex/cables/rate-fetcher.ts +212 -0
- package/src/dex/cables/types.ts +113 -0
- package/src/dex/cables/validators.test.ts +151 -0
- package/src/dex/cables/validators.ts +61 -0
- package/src/dex/dexalot/dexalot.ts +1 -0
- package/src/dex/index.ts +2 -0
- package/src/executor/Executor01BytecodeBuilder.ts +15 -11
- package/src/executor/Executor02BytecodeBuilder.ts +13 -9
- package/src/executor/Executor03BytecodeBuilder.ts +16 -9
- package/src/types.ts +1 -0
- package/tests/constants-e2e.ts +2 -2
- package/.vscode/launch.json +0 -53
- package/.vscode/settings.json +0 -2
- package/.vscode/tasks.json +0 -15
- package/build/abi/inception/inception-ratio-feed.json +0 -329
- package/build/abi/inception/inception-vault.json +0 -991
- package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
- package/build/abi/usual-m-smart-m/usualM.abi.json +0 -483
- package/build/abi/usual-m-usd0/usualCollateralDao.abi.json +0 -681
- package/build/abi/usual-m-wrapped-m/usualM.abi.json +0 -509
- package/build/dex/aave-v2/tokens-avalanche.json +0 -44
- package/build/dex/aave-v2/tokens-mainnet.json +0 -188
- package/build/dex/aave-v2/tokens-polygon.json +0 -44
- package/build/dex/balancer-v3/abi/balancerBatchRouter.d.ts +0 -729
- package/build/dex/balancer-v3/abi/balancerBatchRouter.js +0 -732
- package/build/dex/balancer-v3/abi/balancerBatchRouter.js.map +0 -1
- package/build/dex/balancer-v3/abi/balancerRouter.d.ts +0 -1406
- package/build/dex/balancer-v3/abi/balancerRouter.js +0 -1175
- package/build/dex/balancer-v3/abi/balancerRouter.js.map +0 -1
- package/build/dex/balancer-v3/abi/vaultExtension.V3.d.ts +0 -2081
- package/build/dex/balancer-v3/abi/vaultExtension.V3.js +0 -1851
- package/build/dex/balancer-v3/abi/vaultExtension.V3.js.map +0 -1
- package/build/dex/balancer-v3/balancer-v3-sepolia-pools.d.ts +0 -34
- package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js +0 -406
- package/build/dex/balancer-v3/balancer-v3-sepolia-pools.js.map +0 -1
- package/build/dex/inception/config.d.ts +0 -4
- package/build/dex/inception/config.js +0 -109
- package/build/dex/inception/config.js.map +0 -1
- package/build/dex/inception/inception-event-pool.d.ts +0 -16
- package/build/dex/inception/inception-event-pool.js +0 -49
- package/build/dex/inception/inception-event-pool.js.map +0 -1
- package/build/dex/inception/inception.d.ts +0 -43
- package/build/dex/inception/inception.js +0 -180
- package/build/dex/inception/inception.js.map +0 -1
- package/build/dex/inception/tokens.d.ts +0 -9
- package/build/dex/inception/tokens.js +0 -28
- package/build/dex/inception/tokens.js.map +0 -1
- package/build/dex/inception/types.d.ts +0 -22
- package/build/dex/inception/types.js +0 -3
- package/build/dex/inception/types.js.map +0 -1
- package/build/dex/inception/utils.d.ts +0 -7
- package/build/dex/inception/utils.js +0 -58
- package/build/dex/inception/utils.js.map +0 -1
- package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
- package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
- package/build/dex/maker-psm/scripts/validate-state.js +0 -185
- package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
- package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
- package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +0 -1
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
- package/build/dex/uniswap-v3/uniswap-v3-pricing.d.ts +0 -4
- package/build/dex/uniswap-v3/uniswap-v3-pricing.js +0 -43
- package/build/dex/uniswap-v3/uniswap-v3-pricing.js.map +0 -1
- package/build/dex/uniswap-v3/uniswap-v3-worker.d.ts +0 -1
- package/build/dex/uniswap-v3/uniswap-v3-worker.js +0 -10
- package/build/dex/uniswap-v3/uniswap-v3-worker.js.map +0 -1
- package/build/dex/usual/types.d.ts +0 -13
- package/build/dex/usual/types.js +0 -3
- package/build/dex/usual/types.js.map +0 -1
- package/build/dex/usual/usual-bond.d.ts +0 -18
- package/build/dex/usual/usual-bond.js +0 -52
- package/build/dex/usual/usual-bond.js.map +0 -1
- package/build/dex/usual/usual-m-smart-m.d.ts +0 -17
- package/build/dex/usual/usual-m-smart-m.js +0 -50
- package/build/dex/usual/usual-m-smart-m.js.map +0 -1
- package/build/dex/usual/usual-m-usd0.d.ts +0 -17
- package/build/dex/usual/usual-m-usd0.js +0 -51
- package/build/dex/usual/usual-m-usd0.js.map +0 -1
- package/build/dex/usual/usual-m-wrapped-m.d.ts +0 -17
- package/build/dex/usual/usual-m-wrapped-m.js +0 -50
- package/build/dex/usual/usual-m-wrapped-m.js.map +0 -1
- package/build/dex/usual/usual.d.ts +0 -27
- package/build/dex/usual/usual.js +0 -125
- package/build/dex/usual/usual.js.map +0 -1
- package/build/dex/usual-m-smart-m/config.d.ts +0 -3
- package/build/dex/usual-m-smart-m/config.js +0 -13
- package/build/dex/usual-m-smart-m/config.js.map +0 -1
- package/build/dex/usual-m-smart-m/types.d.ts +0 -7
- package/build/dex/usual-m-smart-m/types.js +0 -3
- package/build/dex/usual-m-smart-m/types.js.map +0 -1
- package/build/dex/usual-m-smart-m/usual-m-smart-m.d.ts +0 -35
- package/build/dex/usual-m-smart-m/usual-m-smart-m.js +0 -161
- package/build/dex/usual-m-smart-m/usual-m-smart-m.js.map +0 -1
- package/build/dex/usual-m-usd0/config.d.ts +0 -3
- package/build/dex/usual-m-usd0/config.js +0 -14
- package/build/dex/usual-m-usd0/config.js.map +0 -1
- package/build/dex/usual-m-usd0/types.d.ts +0 -8
- package/build/dex/usual-m-usd0/types.js +0 -3
- package/build/dex/usual-m-usd0/types.js.map +0 -1
- package/build/dex/usual-m-usd0/usual-m-usd0.d.ts +0 -35
- package/build/dex/usual-m-usd0/usual-m-usd0.js +0 -159
- package/build/dex/usual-m-usd0/usual-m-usd0.js.map +0 -1
- package/build/lib/pub-sub.d.ts +0 -35
- package/build/lib/pub-sub.js +0 -106
- package/build/lib/pub-sub.js.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Network } from '../../constants';
|
|
2
|
+
import { DexConfigMap } from '../../types';
|
|
3
|
+
|
|
4
|
+
export const CablesConfig: DexConfigMap<{ mainnetRFQAddress: string }> = {
|
|
5
|
+
Cables: {
|
|
6
|
+
[Network.AVALANCHE]: {
|
|
7
|
+
mainnetRFQAddress: '0xfA12DCB2e1FD72bD92E8255Db6A781b2c76adC20',
|
|
8
|
+
},
|
|
9
|
+
[Network.ARBITRUM]: {
|
|
10
|
+
mainnetRFQAddress: '0xfA12DCB2e1FD72bD92E8255Db6A781b2c76adC20',
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cables
|
|
5
|
+
*/
|
|
6
|
+
export const CABLES_API_URL =
|
|
7
|
+
'https://cables-evm-rfq-service.cryptosrvc.com/v1';
|
|
8
|
+
|
|
9
|
+
export const CABLES_PRICES_CACHES_TTL_S = 10;
|
|
10
|
+
export const CABLES_API_PRICES_POLLING_INTERVAL_MS = 2000; // 2 sec
|
|
11
|
+
|
|
12
|
+
export const CABLES_PAIRS_CACHES_TTL_S = 12;
|
|
13
|
+
export const CABLES_API_PAIRS_POLLING_INTERVAL_MS = 10000; // 10 sec
|
|
14
|
+
|
|
15
|
+
export const CABLES_BLACKLIST_CACHES_TTL_S = 60;
|
|
16
|
+
export const CABLES_API_BLACKLIST_POLLING_INTERVAL_MS = 30000; // 30 sec
|
|
17
|
+
|
|
18
|
+
export const CABLES_TOKENS_CACHES_TTL_S = 60;
|
|
19
|
+
export const CABLES_API_TOKENS_POLLING_INTERVAL_MS = 30000; // 30 sec
|
|
20
|
+
|
|
21
|
+
export const CABLES_FIRM_QUOTE_TIMEOUT_MS = 2000;
|
|
22
|
+
|
|
23
|
+
export const CABLES_RESTRICTED_CACHE_KEY = 'restricted';
|
|
24
|
+
|
|
25
|
+
export const CABLES_ERRORS_CACHE_KEY = 'errors';
|
|
26
|
+
|
|
27
|
+
export const CABLES_RESTRICT_CHECK_INTERVAL_MS = 1000 * 60 * 3; // 3 min
|
|
28
|
+
|
|
29
|
+
export const CABLES_RESTRICT_COUNT_THRESHOLD = 3;
|
|
30
|
+
|
|
31
|
+
export const CABLES_RESTRICT_TTL_S = 10 * 60; // 10 min
|
|
32
|
+
|
|
33
|
+
export const CABLES_GAS_COST = 120_000;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { Network } from '../../constants';
|
|
2
|
+
import { IDexHelper } from '../../dex-helper';
|
|
3
|
+
import { Fetcher } from '../../lib/fetcher/fetcher';
|
|
4
|
+
import { validateAndCast } from '../../lib/validators';
|
|
5
|
+
import { Logger, Token } from '../../types';
|
|
6
|
+
import { PairData } from '../cables/types';
|
|
7
|
+
import {
|
|
8
|
+
CablesBlacklistResponse,
|
|
9
|
+
CablesPairsResponse,
|
|
10
|
+
CablesPricesResponse,
|
|
11
|
+
CablesRateFetcherConfig,
|
|
12
|
+
CablesTokensResponse,
|
|
13
|
+
} from './types';
|
|
14
|
+
import {
|
|
15
|
+
blacklistResponseValidator,
|
|
16
|
+
pairsResponseValidator,
|
|
17
|
+
pricesResponseValidator,
|
|
18
|
+
tokensResponseValidator,
|
|
19
|
+
} from './validators';
|
|
20
|
+
|
|
21
|
+
export class CablesRateFetcher {
|
|
22
|
+
public tokensFetcher: Fetcher<CablesTokensResponse>;
|
|
23
|
+
public tokensCacheKey: string;
|
|
24
|
+
public tokensCacheTTL: number;
|
|
25
|
+
|
|
26
|
+
public pairsFetcher: Fetcher<CablesPairsResponse>;
|
|
27
|
+
public pairsCacheKey: string;
|
|
28
|
+
public pairsCacheTTL: number;
|
|
29
|
+
|
|
30
|
+
public pricesFetcher: Fetcher<CablesPricesResponse>;
|
|
31
|
+
public pricesCacheKey: string;
|
|
32
|
+
public pricesCacheTTL: number;
|
|
33
|
+
|
|
34
|
+
public blacklistFetcher: Fetcher<CablesBlacklistResponse>;
|
|
35
|
+
public blacklistCacheKey: string;
|
|
36
|
+
public blacklistCacheTTL: number;
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
private dexHelper: IDexHelper,
|
|
40
|
+
private dexKey: string,
|
|
41
|
+
private network: Network,
|
|
42
|
+
private logger: Logger,
|
|
43
|
+
config: CablesRateFetcherConfig,
|
|
44
|
+
) {
|
|
45
|
+
this.tokensCacheKey = config.rateConfig.tokensCacheKey;
|
|
46
|
+
this.tokensCacheTTL = config.rateConfig.tokensCacheTTLSecs;
|
|
47
|
+
|
|
48
|
+
this.pairsCacheKey = config.rateConfig.pairsCacheKey;
|
|
49
|
+
this.pairsCacheTTL = config.rateConfig.pairsCacheTTLSecs;
|
|
50
|
+
|
|
51
|
+
this.pricesCacheKey = config.rateConfig.pricesCacheKey;
|
|
52
|
+
this.pricesCacheTTL = config.rateConfig.pricesCacheTTLSecs;
|
|
53
|
+
|
|
54
|
+
this.blacklistCacheKey = config.rateConfig.blacklistCacheKey;
|
|
55
|
+
this.blacklistCacheTTL = config.rateConfig.blacklistCacheTTLSecs;
|
|
56
|
+
|
|
57
|
+
this.pairsFetcher = new Fetcher<CablesPairsResponse>(
|
|
58
|
+
dexHelper.httpRequest,
|
|
59
|
+
{
|
|
60
|
+
info: {
|
|
61
|
+
requestOptions: config.rateConfig.pairsReqParams,
|
|
62
|
+
caster: (data: unknown) => {
|
|
63
|
+
return validateAndCast<CablesPairsResponse>(
|
|
64
|
+
data,
|
|
65
|
+
pairsResponseValidator,
|
|
66
|
+
);
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
handler: this.handlePairsResponse.bind(this),
|
|
70
|
+
},
|
|
71
|
+
config.rateConfig.pairsIntervalMs,
|
|
72
|
+
logger,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
this.pricesFetcher = new Fetcher<CablesPricesResponse>(
|
|
76
|
+
dexHelper.httpRequest,
|
|
77
|
+
{
|
|
78
|
+
info: {
|
|
79
|
+
requestOptions: config.rateConfig.pricesReqParams,
|
|
80
|
+
caster: (data: unknown) => {
|
|
81
|
+
return validateAndCast<CablesPricesResponse>(
|
|
82
|
+
data,
|
|
83
|
+
pricesResponseValidator,
|
|
84
|
+
);
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
handler: this.handlePricesResponse.bind(this),
|
|
88
|
+
},
|
|
89
|
+
config.rateConfig.pricesIntervalMs,
|
|
90
|
+
logger,
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
this.blacklistFetcher = new Fetcher<CablesBlacklistResponse>(
|
|
94
|
+
dexHelper.httpRequest,
|
|
95
|
+
{
|
|
96
|
+
info: {
|
|
97
|
+
requestOptions: config.rateConfig.blacklistReqParams,
|
|
98
|
+
caster: (data: unknown) => {
|
|
99
|
+
return validateAndCast<CablesBlacklistResponse>(
|
|
100
|
+
data,
|
|
101
|
+
blacklistResponseValidator,
|
|
102
|
+
);
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
handler: this.handleBlacklistResponse.bind(this),
|
|
106
|
+
},
|
|
107
|
+
config.rateConfig.blacklistIntervalMs,
|
|
108
|
+
logger,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
this.tokensFetcher = new Fetcher<CablesTokensResponse>(
|
|
112
|
+
dexHelper.httpRequest,
|
|
113
|
+
{
|
|
114
|
+
info: {
|
|
115
|
+
requestOptions: config.rateConfig.tokensReqParams,
|
|
116
|
+
caster: (data: unknown) => {
|
|
117
|
+
return validateAndCast<CablesTokensResponse>(
|
|
118
|
+
data,
|
|
119
|
+
tokensResponseValidator,
|
|
120
|
+
);
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
handler: this.handleTokensResponse.bind(this),
|
|
124
|
+
},
|
|
125
|
+
config.rateConfig.tokensIntervalMs,
|
|
126
|
+
logger,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Utils
|
|
132
|
+
*/
|
|
133
|
+
start() {
|
|
134
|
+
this.pairsFetcher.startPolling();
|
|
135
|
+
this.pricesFetcher.startPolling();
|
|
136
|
+
this.blacklistFetcher.startPolling();
|
|
137
|
+
this.tokensFetcher.startPolling();
|
|
138
|
+
}
|
|
139
|
+
stop() {
|
|
140
|
+
this.pairsFetcher.stopPolling();
|
|
141
|
+
this.pricesFetcher.stopPolling();
|
|
142
|
+
this.blacklistFetcher.stopPolling();
|
|
143
|
+
this.tokensFetcher.stopPolling();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private handlePairsResponse(res: CablesPairsResponse): void {
|
|
147
|
+
const networkId = String(this.network);
|
|
148
|
+
const pairs = res.pairs[networkId];
|
|
149
|
+
|
|
150
|
+
let normalized_pairs: { [token: string]: PairData } = {};
|
|
151
|
+
Object.keys(pairs).forEach(key => {
|
|
152
|
+
normalized_pairs[key.toLowerCase()] = pairs[key];
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
this.dexHelper.cache.setex(
|
|
156
|
+
this.dexKey,
|
|
157
|
+
this.network,
|
|
158
|
+
this.pairsCacheKey,
|
|
159
|
+
this.pairsCacheTTL,
|
|
160
|
+
JSON.stringify(normalized_pairs),
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private handlePricesResponse(res: CablesPricesResponse): void {
|
|
165
|
+
const networkId = String(this.network);
|
|
166
|
+
const prices = res.prices[networkId];
|
|
167
|
+
|
|
168
|
+
this.dexHelper.cache.setex(
|
|
169
|
+
this.dexKey,
|
|
170
|
+
this.network,
|
|
171
|
+
this.pricesCacheKey,
|
|
172
|
+
this.pricesCacheTTL,
|
|
173
|
+
JSON.stringify(prices),
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private handleBlacklistResponse(res: CablesBlacklistResponse): void {
|
|
178
|
+
const { blacklist } = res;
|
|
179
|
+
this.dexHelper.cache.setex(
|
|
180
|
+
this.dexKey,
|
|
181
|
+
this.network,
|
|
182
|
+
this.blacklistCacheKey,
|
|
183
|
+
this.blacklistCacheTTL,
|
|
184
|
+
JSON.stringify(blacklist.map(item => item.toLowerCase())),
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Convert addresses to lowercase
|
|
189
|
+
private normalizeAddressesToLowerCase = (
|
|
190
|
+
jsonData: Record<string, { address: string }>,
|
|
191
|
+
) => {
|
|
192
|
+
Object.keys(jsonData).forEach(key => {
|
|
193
|
+
jsonData[key].address = jsonData[key].address.toLowerCase();
|
|
194
|
+
});
|
|
195
|
+
return jsonData;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
private async handleTokensResponse(res: CablesTokensResponse): Promise<void> {
|
|
199
|
+
const networkId = String(this.network);
|
|
200
|
+
const tokens = res.tokens[networkId];
|
|
201
|
+
|
|
202
|
+
const normalizedTokens = this.normalizeAddressesToLowerCase(tokens);
|
|
203
|
+
|
|
204
|
+
this.dexHelper.cache.setex(
|
|
205
|
+
this.dexKey,
|
|
206
|
+
this.network,
|
|
207
|
+
this.tokensCacheKey,
|
|
208
|
+
this.tokensCacheTTL,
|
|
209
|
+
JSON.stringify(normalizedTokens),
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { RequestHeaders } from '../../dex-helper';
|
|
2
|
+
import { Token } from '../../types';
|
|
3
|
+
import { Method } from '../../dex-helper/irequest-wrapper';
|
|
4
|
+
import { AugustusRFQOrderData } from '../augustus-rfq';
|
|
5
|
+
|
|
6
|
+
export type CablesRFQResponse = {
|
|
7
|
+
order: AugustusRFQOrderData;
|
|
8
|
+
signature: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type CablesData = {
|
|
12
|
+
quoteData?: AugustusRFQOrderData;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Types
|
|
16
|
+
*/
|
|
17
|
+
export type PairData = {
|
|
18
|
+
base: string;
|
|
19
|
+
quote: string;
|
|
20
|
+
liquidityUSD: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type PriceAndAmount = [string, string];
|
|
24
|
+
|
|
25
|
+
type PriceData = {
|
|
26
|
+
bids: PriceAndAmount[];
|
|
27
|
+
asks: PriceAndAmount[];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type PriceDataMap = {
|
|
31
|
+
[network: string]: {
|
|
32
|
+
[pair: string]: PriceData;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type TokenDataMap = {
|
|
37
|
+
[network: string]: {
|
|
38
|
+
[token: string]: Token;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type PairsDataMap = {
|
|
43
|
+
[network: string]: {
|
|
44
|
+
[token: string]: PairData;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Responses
|
|
50
|
+
*/
|
|
51
|
+
export type CablesPricesResponse = {
|
|
52
|
+
prices: PriceDataMap;
|
|
53
|
+
};
|
|
54
|
+
export type CablesBlacklistResponse = {
|
|
55
|
+
blacklist: string[];
|
|
56
|
+
};
|
|
57
|
+
export type CablesTokensResponse = {
|
|
58
|
+
tokens: TokenDataMap;
|
|
59
|
+
};
|
|
60
|
+
export type CablesPairsResponse = {
|
|
61
|
+
pairs: PairsDataMap;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Rate Fetcher
|
|
66
|
+
*/
|
|
67
|
+
export type CablesRateFetcherConfig = {
|
|
68
|
+
rateConfig: {
|
|
69
|
+
pairsReqParams: {
|
|
70
|
+
url: string;
|
|
71
|
+
headers?: RequestHeaders;
|
|
72
|
+
params?: any;
|
|
73
|
+
};
|
|
74
|
+
pricesReqParams: {
|
|
75
|
+
url: string;
|
|
76
|
+
headers?: RequestHeaders;
|
|
77
|
+
params?: any;
|
|
78
|
+
};
|
|
79
|
+
blacklistReqParams: {
|
|
80
|
+
url: string;
|
|
81
|
+
headers?: RequestHeaders;
|
|
82
|
+
params?: any;
|
|
83
|
+
};
|
|
84
|
+
tokensReqParams: {
|
|
85
|
+
url: string;
|
|
86
|
+
headers?: RequestHeaders;
|
|
87
|
+
params?: any;
|
|
88
|
+
};
|
|
89
|
+
pairsIntervalMs: number;
|
|
90
|
+
pricesIntervalMs: number;
|
|
91
|
+
blacklistIntervalMs: number;
|
|
92
|
+
tokensIntervalMs: number;
|
|
93
|
+
|
|
94
|
+
pairsCacheKey: string;
|
|
95
|
+
pricesCacheKey: string;
|
|
96
|
+
blacklistCacheKey: string;
|
|
97
|
+
tokensCacheKey: string;
|
|
98
|
+
|
|
99
|
+
blacklistCacheTTLSecs: number;
|
|
100
|
+
pairsCacheTTLSecs: number;
|
|
101
|
+
pricesCacheTTLSecs: number;
|
|
102
|
+
tokensCacheTTLSecs: number;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type RestrictData = {
|
|
107
|
+
count: number;
|
|
108
|
+
addedDatetimeMs: number;
|
|
109
|
+
} | null;
|
|
110
|
+
|
|
111
|
+
export class SlippageError extends Error {
|
|
112
|
+
isSlippageError = true;
|
|
113
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import Joi from 'joi';
|
|
2
|
+
import {
|
|
3
|
+
pairsResponseValidator,
|
|
4
|
+
pricesResponseValidator,
|
|
5
|
+
tokensResponseValidator,
|
|
6
|
+
blacklistResponseValidator,
|
|
7
|
+
} from './validators'; //
|
|
8
|
+
|
|
9
|
+
describe('Validation Schemas', () => {
|
|
10
|
+
describe('pairsResponseValidator', () => {
|
|
11
|
+
it('should validate correct pairs response', () => {
|
|
12
|
+
const validData = {
|
|
13
|
+
pairs: { '43114': { 'USDC/USDT': { base: 'USDC', quote: 'USDT' } } },
|
|
14
|
+
};
|
|
15
|
+
const { error } = pairsResponseValidator.validate(validData);
|
|
16
|
+
expect(error).toBeUndefined();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should invalidate incorrect pairs response', () => {
|
|
20
|
+
const invalidData = { pairs: { '43114': 'USDC/USDT' } };
|
|
21
|
+
const { error } = pairsResponseValidator.validate(invalidData);
|
|
22
|
+
expect(error).toBeDefined();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('pricesResponseValidator', () => {
|
|
27
|
+
it('should validate correct prices response', () => {
|
|
28
|
+
const validData = {
|
|
29
|
+
prices: {
|
|
30
|
+
'43114': {
|
|
31
|
+
'USDC/USDT': {
|
|
32
|
+
bids: [
|
|
33
|
+
['0.9996', '244305.9'],
|
|
34
|
+
['0.9995', '236021.6'],
|
|
35
|
+
],
|
|
36
|
+
asks: [
|
|
37
|
+
['0.9996', '244305.9'],
|
|
38
|
+
['0.9995', '236021.6'],
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const { error } = pricesResponseValidator.validate(validData);
|
|
45
|
+
expect(error).toBeUndefined();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should invalidate incorrect prices response', () => {
|
|
49
|
+
const invalidData = {
|
|
50
|
+
prices: {
|
|
51
|
+
chain1: {
|
|
52
|
+
bids: [
|
|
53
|
+
['1000'], // invalid entry length
|
|
54
|
+
],
|
|
55
|
+
asks: [['1010', '1']],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const { error } = pricesResponseValidator.validate(invalidData);
|
|
60
|
+
expect(error).toBeDefined();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('tokensResponseValidator', () => {
|
|
65
|
+
it('should validate correct tokens response', () => {
|
|
66
|
+
const validData = {
|
|
67
|
+
tokens: {
|
|
68
|
+
'43114': {
|
|
69
|
+
AVAX: {
|
|
70
|
+
symbol: 'AVAX',
|
|
71
|
+
decimals: 18,
|
|
72
|
+
name: 'AVAX',
|
|
73
|
+
address: '0x0000000000000000000000000000000000000000',
|
|
74
|
+
},
|
|
75
|
+
WAVAX: {
|
|
76
|
+
symbol: 'WAVAX',
|
|
77
|
+
decimals: 18,
|
|
78
|
+
name: 'WAVAX',
|
|
79
|
+
address: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7',
|
|
80
|
+
},
|
|
81
|
+
'WETH.e': {
|
|
82
|
+
symbol: 'WETH.e',
|
|
83
|
+
decimals: 18,
|
|
84
|
+
name: 'WETH.e',
|
|
85
|
+
address: '0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB',
|
|
86
|
+
},
|
|
87
|
+
USDT: {
|
|
88
|
+
symbol: 'USDT',
|
|
89
|
+
decimals: 6,
|
|
90
|
+
name: 'USDT',
|
|
91
|
+
address: '0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7',
|
|
92
|
+
},
|
|
93
|
+
USDC: {
|
|
94
|
+
symbol: 'USDC',
|
|
95
|
+
decimals: 6,
|
|
96
|
+
name: 'USDC',
|
|
97
|
+
address: '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E',
|
|
98
|
+
},
|
|
99
|
+
'USDC.e': {
|
|
100
|
+
symbol: 'USDC.e',
|
|
101
|
+
decimals: 6,
|
|
102
|
+
name: 'USDC.e',
|
|
103
|
+
address: '0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664',
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
const { error } = tokensResponseValidator.validate(validData);
|
|
109
|
+
expect(error).toBeUndefined();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should invalidate incorrect tokens response', () => {
|
|
113
|
+
const invalidData = {
|
|
114
|
+
tokens: {
|
|
115
|
+
chain1: {
|
|
116
|
+
ETH: {
|
|
117
|
+
symbol: '', // invalid value
|
|
118
|
+
name: 'Ethereum',
|
|
119
|
+
description: 'A popular cryptocurrency',
|
|
120
|
+
address: '0x...',
|
|
121
|
+
decimals: 18,
|
|
122
|
+
type: 'ERC20',
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
const { error } = tokensResponseValidator.validate(invalidData);
|
|
128
|
+
expect(error).toBeDefined();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('blacklistResponseValidator', () => {
|
|
133
|
+
it('should validate correct blacklist response', () => {
|
|
134
|
+
const validData = {
|
|
135
|
+
blacklist: ['0xAddress1', '0xAddress2'],
|
|
136
|
+
};
|
|
137
|
+
const { error } = blacklistResponseValidator.validate(validData);
|
|
138
|
+
expect(error).toBeUndefined();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should invalidate incorrect blacklist response', () => {
|
|
142
|
+
const invalidData = {
|
|
143
|
+
blacklist: [
|
|
144
|
+
'', // invalid value
|
|
145
|
+
],
|
|
146
|
+
};
|
|
147
|
+
const { error } = blacklistResponseValidator.validate(invalidData);
|
|
148
|
+
expect(error).toBeDefined();
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import joi from 'joi';
|
|
2
|
+
|
|
3
|
+
const pairValidator = joi.object({
|
|
4
|
+
base: joi.string().min(1),
|
|
5
|
+
quote: joi.string().min(1),
|
|
6
|
+
liquidityUSD: joi.number().min(0),
|
|
7
|
+
baseAddress: joi.string().min(1),
|
|
8
|
+
quoteAddress: joi.string().min(1),
|
|
9
|
+
baseDecimals: joi.number().min(0),
|
|
10
|
+
quoteDecimals: joi.number().min(0),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const pairMap = joi.object().pattern(
|
|
14
|
+
joi.string(), // Pair name ETH/USDT
|
|
15
|
+
pairValidator,
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
export const pairsResponseValidator = joi.object({
|
|
19
|
+
pairs: joi.object().pattern(
|
|
20
|
+
joi.string(), // chain id
|
|
21
|
+
pairMap,
|
|
22
|
+
),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const orderbookEntry = joi.array().items(joi.string().min(1)).length(2);
|
|
26
|
+
|
|
27
|
+
const orderbookValidator = joi.object({
|
|
28
|
+
bids: joi.array().items(orderbookEntry),
|
|
29
|
+
asks: joi.array().items(orderbookEntry),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const chainDataSchema = joi.object().pattern(
|
|
33
|
+
joi.string(), // pair name USDC/USDT
|
|
34
|
+
orderbookValidator,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export const pricesResponseValidator = joi.object({
|
|
38
|
+
prices: joi.object().pattern(
|
|
39
|
+
joi.string(), // chain id
|
|
40
|
+
chainDataSchema,
|
|
41
|
+
),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const tokenValidator = joi.object({
|
|
45
|
+
symbol: joi.string().min(1),
|
|
46
|
+
name: joi.string().min(1),
|
|
47
|
+
description: joi.string().min(1),
|
|
48
|
+
address: joi.string().min(1),
|
|
49
|
+
decimals: joi.number().min(0),
|
|
50
|
+
type: joi.string().min(1),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const chainTokens = joi.object().pattern(joi.string(), tokenValidator);
|
|
54
|
+
|
|
55
|
+
export const tokensResponseValidator = joi.object({
|
|
56
|
+
tokens: joi.object().pattern(joi.string(), chainTokens),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const blacklistResponseValidator = joi.object({
|
|
60
|
+
blacklist: joi.array().items(joi.string().min(1)),
|
|
61
|
+
});
|
|
@@ -593,6 +593,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
|
|
|
593
593
|
.multipliedBy(10000)
|
|
594
594
|
.toFixed(0)
|
|
595
595
|
: options.slippageFactor.minus(1).multipliedBy(10000).toFixed(0);
|
|
596
|
+
|
|
596
597
|
const rfqParams = {
|
|
597
598
|
makerAsset: ethers.utils.getAddress(makerToken.address),
|
|
598
599
|
takerAsset: ethers.utils.getAddress(takerToken.address),
|
package/src/dex/index.ts
CHANGED
|
@@ -96,6 +96,7 @@ import { StkGHO } from './stkgho/stkgho';
|
|
|
96
96
|
import { BalancerV3 } from './balancer-v3/balancer-v3';
|
|
97
97
|
import { balancerV3Merge } from './balancer-v3/optimizer';
|
|
98
98
|
import { SkyConverter } from './sky-converter/sky-converter';
|
|
99
|
+
import { Cables } from './cables/cables';
|
|
99
100
|
import { Stader } from './stader/stader';
|
|
100
101
|
|
|
101
102
|
const LegacyDexes = [
|
|
@@ -187,6 +188,7 @@ const Dexes = [
|
|
|
187
188
|
UsualBond,
|
|
188
189
|
StkGHO,
|
|
189
190
|
SkyConverter,
|
|
191
|
+
Cables,
|
|
190
192
|
FluidDex,
|
|
191
193
|
];
|
|
192
194
|
|
|
@@ -379,17 +379,21 @@ export class Executor01BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
379
379
|
|
|
380
380
|
let fromAmountPos = 0;
|
|
381
381
|
if (insertFromAmount) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
382
|
+
if (exchangeParam.insertFromAmountPos) {
|
|
383
|
+
fromAmountPos = exchangeParam.insertFromAmountPos;
|
|
384
|
+
} else {
|
|
385
|
+
const fromAmount = ethers.utils.defaultAbiCoder.encode(
|
|
386
|
+
['uint256'],
|
|
387
|
+
[swap.swapExchanges[swapExchangeIndex].srcAmount],
|
|
388
|
+
);
|
|
389
|
+
|
|
390
|
+
const fromAmountIndex = exchangeData
|
|
391
|
+
.replace('0x', '')
|
|
392
|
+
.indexOf(fromAmount.replace('0x', ''));
|
|
393
|
+
|
|
394
|
+
fromAmountPos =
|
|
395
|
+
(fromAmountIndex !== -1 ? fromAmountIndex : exchangeData.length) / 2;
|
|
396
|
+
}
|
|
393
397
|
}
|
|
394
398
|
|
|
395
399
|
return this.buildCallData(
|
|
@@ -335,16 +335,20 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
|
|
|
335
335
|
|
|
336
336
|
let fromAmountPos = 0;
|
|
337
337
|
if (insertFromAmount) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
338
|
+
if (exchangeParam.insertFromAmountPos) {
|
|
339
|
+
fromAmountPos = exchangeParam.insertFromAmountPos;
|
|
340
|
+
} else {
|
|
341
|
+
const fromAmount = ethers.utils.defaultAbiCoder.encode(
|
|
342
|
+
['uint256'],
|
|
343
|
+
[swapExchange.srcAmount],
|
|
344
|
+
);
|
|
345
|
+
const fromAmountIndex = exchangeData
|
|
346
|
+
.replace('0x', '')
|
|
347
|
+
.indexOf(fromAmount.replace('0x', ''));
|
|
345
348
|
|
|
346
|
-
|
|
347
|
-
|
|
349
|
+
fromAmountPos =
|
|
350
|
+
(fromAmountIndex !== -1 ? fromAmountIndex : exchangeData.length) / 2;
|
|
351
|
+
}
|
|
348
352
|
}
|
|
349
353
|
|
|
350
354
|
return this.buildCallData(
|