@paraswap/dex-lib 3.8.37 → 3.8.39-bebop
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/abi/USDM.json +807 -0
- package/build/abi/bebop/BebopSettlement.abi.json +2137 -0
- package/build/abi/cables/CablesMainnetRFQ.json +1073 -0
- package/build/abi/wUSDM.json +757 -0
- package/build/config.js +7 -0
- package/build/config.js.map +1 -1
- package/build/dex/bebop/bebop.d.ts +55 -0
- package/build/dex/bebop/bebop.js +524 -0
- package/build/dex/bebop/bebop.js.map +1 -0
- package/build/dex/bebop/config.d.ts +3 -0
- package/build/dex/bebop/config.js +38 -0
- package/build/dex/bebop/config.js.map +1 -0
- package/build/dex/bebop/constants.d.ts +9 -0
- package/build/dex/bebop/constants.js +13 -0
- package/build/dex/bebop/constants.js.map +1 -0
- package/build/dex/bebop/rate-fetcher.d.ts +22 -0
- package/build/dex/bebop/rate-fetcher.js +80 -0
- package/build/dex/bebop/rate-fetcher.js.map +1 -0
- package/build/dex/bebop/types.d.ts +76 -0
- package/build/dex/bebop/types.js +3 -0
- package/build/dex/bebop/types.js.map +1 -0
- package/build/dex/bebop/validators.d.ts +4 -0
- package/build/dex/bebop/validators.js +42 -0
- package/build/dex/bebop/validators.js.map +1 -0
- package/build/dex/bebop/websocket-fetcher.d.ts +35 -0
- package/build/dex/bebop/websocket-fetcher.js +87 -0
- package/build/dex/bebop/websocket-fetcher.js.map +1 -0
- package/build/dex/cables/cables.d.ts +64 -0
- package/build/dex/cables/cables.js +445 -0
- package/build/dex/cables/cables.js.map +1 -0
- package/build/dex/cables/config.d.ts +4 -0
- package/build/dex/cables/config.js +15 -0
- package/build/dex/cables/config.js.map +1 -0
- package/build/dex/cables/constants.d.ts +19 -0
- package/build/dex/cables/constants.js +26 -0
- package/build/dex/cables/constants.js.map +1 -0
- package/build/dex/cables/rate-fetcher.d.ts +34 -0
- package/build/dex/cables/rate-fetcher.js +117 -0
- package/build/dex/cables/rate-fetcher.js.map +1 -0
- package/build/dex/cables/types.d.ts +106 -0
- package/build/dex/cables/types.js +12 -0
- package/build/dex/cables/types.js.map +1 -0
- package/build/dex/cables/validators.d.ts +5 -0
- package/build/dex/cables/validators.js +49 -0
- package/build/dex/cables/validators.js.map +1 -0
- package/build/dex/index.js +2 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/spark/config.js +25 -0
- package/build/dex/spark/config.js.map +1 -1
- package/build/dex/spark/scripts/validate-state.js +1 -1
- package/build/dex/spark/scripts/validate-state.js.map +1 -1
- package/build/dex/spark/spark-sdai-pool.d.ts +7 -3
- package/build/dex/spark/spark-sdai-pool.js +24 -28
- package/build/dex/spark/spark-sdai-pool.js.map +1 -1
- package/build/dex/spark/spark.d.ts +10 -5
- package/build/dex/spark/spark.js +46 -31
- package/build/dex/spark/spark.js.map +1 -1
- package/build/dex/spark/types.d.ts +6 -0
- package/build/dex/spark/types.js.map +1 -1
- package/build/dex/spark/utils.d.ts +3 -1
- package/build/dex/spark/utils.js +43 -7
- package/build/dex/spark/utils.js.map +1 -1
- package/build/dex/woo-fi-v2/woo-fi-v2-pool.d.ts +2 -2
- package/build/dex/woo-fi-v2/woo-fi-v2-pool.js +30 -9
- package/build/dex/woo-fi-v2/woo-fi-v2-pool.js.map +1 -1
- package/build/dex/woo-fi-v2/woo-fi-v2.js +1 -1
- package/build/dex/woo-fi-v2/woo-fi-v2.js.map +1 -1
- package/build/dex/wusdm/config.d.ts +3 -0
- package/build/dex/wusdm/config.js +29 -0
- package/build/dex/wusdm/config.js.map +1 -0
- package/build/dex/wusdm/types.d.ts +10 -0
- package/build/dex/wusdm/types.js +3 -0
- package/build/dex/wusdm/types.js.map +1 -0
- package/build/dex/wusdm/wusdm.d.ts +39 -0
- package/build/dex/wusdm/wusdm.js +212 -0
- package/build/dex/wusdm/wusdm.js.map +1 -0
- package/build/lib/fetcher/wsFetcher.d.ts +35 -0
- package/build/lib/fetcher/wsFetcher.js +87 -0
- package/build/lib/fetcher/wsFetcher.js.map +1 -0
- package/build/types.d.ts +1 -0
- package/package.json +4 -2
- package/src/abi/bebop/BebopSettlement.abi.json +2137 -0
- package/src/abi/sdai/SavingsUSDS.abi.json +720 -0
- package/src/config.ts +8 -0
- package/src/dex/bebop/bebop-e2e.test.ts +195 -0
- package/src/dex/bebop/bebop-integration.test.ts +170 -0
- package/src/dex/bebop/bebop.ts +732 -0
- package/src/dex/bebop/config.ts +37 -0
- package/src/dex/bebop/constants.ts +9 -0
- package/src/dex/bebop/rate-fetcher.ts +138 -0
- package/src/dex/bebop/types.ts +81 -0
- package/src/dex/bebop/validators.ts +43 -0
- package/src/dex/index.ts +2 -0
- package/src/dex/spark/config.ts +24 -0
- package/src/dex/spark/scripts/validate-state.ts +1 -0
- package/src/dex/spark/spark-e2e.test.ts +25 -21
- package/src/dex/spark/spark-events.test.ts +77 -62
- package/src/dex/spark/spark-integration.test.ts +290 -7
- package/src/dex/spark/spark-sdai-pool.ts +22 -19
- package/src/dex/spark/spark.ts +62 -36
- package/src/dex/spark/types.ts +6 -0
- package/src/dex/spark/utils.ts +83 -19
- package/src/dex/woo-fi-v2/woo-fi-v2-pool.ts +58 -27
- package/src/dex/woo-fi-v2/woo-fi-v2.ts +1 -2
- package/src/lib/fetcher/wsFetcher.ts +126 -0
- package/src/types.ts +1 -0
- package/tests/constants-e2e.ts +5 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { DexParams } from './types';
|
|
2
|
+
import { DexConfigMap } from '../../types';
|
|
3
|
+
import { Network } from '../../constants';
|
|
4
|
+
|
|
5
|
+
export const BebopConfig: DexConfigMap<DexParams> = {
|
|
6
|
+
Bebop: {
|
|
7
|
+
[Network.MAINNET]: {
|
|
8
|
+
settlementAddress: '0xbbbbbBB520d69a9775E85b458C58c648259FAD5F',
|
|
9
|
+
chainName: 'ethereum',
|
|
10
|
+
middleTokens: [
|
|
11
|
+
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
|
|
12
|
+
'0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
|
|
13
|
+
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
[Network.ARBITRUM]: {
|
|
17
|
+
settlementAddress: '0xbbbbbBB520d69a9775E85b458C58c648259FAD5F',
|
|
18
|
+
chainName: 'arbitrum',
|
|
19
|
+
middleTokens: [
|
|
20
|
+
'0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8', // USDC.e
|
|
21
|
+
'0xaf88d065e77c8cC2239327C5EDb3A432268e5831', // USDC
|
|
22
|
+
'0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9', // USDT
|
|
23
|
+
'0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', // WETH
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
[Network.BASE]: {
|
|
27
|
+
settlementAddress: '0xbbbbbBB520d69a9775E85b458C58c648259FAD5F',
|
|
28
|
+
chainName: 'base',
|
|
29
|
+
middleTokens: ['0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'],
|
|
30
|
+
},
|
|
31
|
+
[Network.OPTIMISM]: {
|
|
32
|
+
settlementAddress: '0xbbbbbBB520d69a9775E85b458C58c648259FAD5F',
|
|
33
|
+
chainName: 'optimism',
|
|
34
|
+
middleTokens: ['0x7F5c764cBc14f9669B88837ca1490cCa17c31607'],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const BEBOP_INIT_TIMEOUT_MS = 5000;
|
|
2
|
+
export const BEBOP_PRICES_CACHE_TTL = 10;
|
|
3
|
+
export const BEBOP_TOKENS_CACHE_TTL = 60;
|
|
4
|
+
export const BEBOP_TOKENS_POLLING_INTERVAL_MS = 30 * 1000;
|
|
5
|
+
export const BEBOP_API_URL = 'https://api.bebop.xyz';
|
|
6
|
+
export const BEBOP_WS_API_URL = 'wss://api.bebop.xyz';
|
|
7
|
+
export const BEBOP_GAS_COST = 120_000;
|
|
8
|
+
export const BEBOP_AUTH_NAME = 'paraswap';
|
|
9
|
+
export const BEBOP_QUOTE_TIMEOUT_MS = 2000;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { ETHER_ADDRESS, 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 {
|
|
7
|
+
BebopPricingResponse,
|
|
8
|
+
BebopRateFetcherConfig,
|
|
9
|
+
BebopTokensResponse,
|
|
10
|
+
} from './types';
|
|
11
|
+
import { pricesResponseValidator, tokensResponseValidator } from './validators';
|
|
12
|
+
import { WebSocketFetcher } from '../../lib/fetcher/wsFetcher';
|
|
13
|
+
|
|
14
|
+
export class RateFetcher {
|
|
15
|
+
private pricesFetcher: WebSocketFetcher<BebopPricingResponse>;
|
|
16
|
+
private pricesCacheKey: string;
|
|
17
|
+
private pricesCacheTTL: number;
|
|
18
|
+
|
|
19
|
+
private tokensFetcher: Fetcher<BebopTokensResponse>;
|
|
20
|
+
private tokensAddrCacheKey: string;
|
|
21
|
+
private tokensCacheKey: string;
|
|
22
|
+
private tokensCacheTTL: number;
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
private dexHelper: IDexHelper,
|
|
26
|
+
private dexKey: string,
|
|
27
|
+
private network: Network,
|
|
28
|
+
private logger: Logger,
|
|
29
|
+
config: BebopRateFetcherConfig,
|
|
30
|
+
) {
|
|
31
|
+
this.pricesCacheKey = config.rateConfig.pricesCacheKey;
|
|
32
|
+
this.pricesCacheTTL = config.rateConfig.pricesCacheTTLSecs;
|
|
33
|
+
this.pricesFetcher = new WebSocketFetcher<BebopPricingResponse>(
|
|
34
|
+
{
|
|
35
|
+
info: {
|
|
36
|
+
requestOptions: config.rateConfig.pricesReqParams,
|
|
37
|
+
caster: (data: unknown) => {
|
|
38
|
+
return validateAndCast<BebopPricingResponse>(
|
|
39
|
+
data,
|
|
40
|
+
pricesResponseValidator,
|
|
41
|
+
);
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
handler: this.handlePricesResponse.bind(this),
|
|
45
|
+
},
|
|
46
|
+
logger,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
this.tokensAddrCacheKey = config.rateConfig.tokensAddrCacheKey;
|
|
50
|
+
this.tokensCacheKey = config.rateConfig.tokensCacheKey;
|
|
51
|
+
this.tokensCacheTTL = config.rateConfig.tokensCacheTTLSecs;
|
|
52
|
+
this.tokensFetcher = new Fetcher<BebopTokensResponse>(
|
|
53
|
+
dexHelper.httpRequest,
|
|
54
|
+
{
|
|
55
|
+
info: {
|
|
56
|
+
requestOptions: config.rateConfig.tokensReqParams,
|
|
57
|
+
caster: (data: unknown) => {
|
|
58
|
+
return validateAndCast<BebopTokensResponse>(
|
|
59
|
+
data,
|
|
60
|
+
tokensResponseValidator,
|
|
61
|
+
);
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
handler: this.handleTokensResponse.bind(this),
|
|
65
|
+
},
|
|
66
|
+
config.rateConfig.tokensIntervalMs,
|
|
67
|
+
logger,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
start() {
|
|
72
|
+
this.pricesFetcher.startPolling();
|
|
73
|
+
this.tokensFetcher.startPolling();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
stop() {
|
|
77
|
+
this.pricesFetcher.stopPolling();
|
|
78
|
+
this.tokensFetcher.stopPolling();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private handleTokensResponse(resp: BebopTokensResponse): void {
|
|
82
|
+
const tokenMap: { [address: string]: Token } = {};
|
|
83
|
+
const tokenAddrMap: { [symbol: string]: Token } = {};
|
|
84
|
+
|
|
85
|
+
Object.keys(resp.tokens).forEach(tokenSymbol => {
|
|
86
|
+
const token = resp.tokens[tokenSymbol];
|
|
87
|
+
const tokenData = {
|
|
88
|
+
address: token.contractAddress.toLowerCase(),
|
|
89
|
+
symbol: token.ticker,
|
|
90
|
+
decimals: token.decimals,
|
|
91
|
+
};
|
|
92
|
+
tokenAddrMap[token.contractAddress.toLowerCase()] = tokenData;
|
|
93
|
+
tokenMap[token.ticker.toLowerCase()] = tokenData;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
this.dexHelper.cache.setex(
|
|
97
|
+
this.dexKey,
|
|
98
|
+
this.network,
|
|
99
|
+
this.tokensCacheKey,
|
|
100
|
+
this.tokensCacheTTL,
|
|
101
|
+
JSON.stringify(tokenMap),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
this.dexHelper.cache.setex(
|
|
105
|
+
this.dexKey,
|
|
106
|
+
this.network,
|
|
107
|
+
this.tokensAddrCacheKey,
|
|
108
|
+
this.tokensCacheTTL,
|
|
109
|
+
JSON.stringify(tokenAddrMap),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private handlePricesResponse(resp: BebopPricingResponse): void {
|
|
114
|
+
const wethAddress =
|
|
115
|
+
this.dexHelper.config.data.wrappedNativeTokenAddress.toLowerCase();
|
|
116
|
+
const normalizedPrices: BebopPricingResponse = {};
|
|
117
|
+
for (const [pair, levels] of Object.entries(resp)) {
|
|
118
|
+
normalizedPrices[pair.toLowerCase()] = levels;
|
|
119
|
+
const [base, quote] = pair.split('/');
|
|
120
|
+
// Also enter native token prices. Pricing doesn't come with these
|
|
121
|
+
if (
|
|
122
|
+
base.toLowerCase() === wethAddress ||
|
|
123
|
+
quote.toLowerCase() === wethAddress
|
|
124
|
+
) {
|
|
125
|
+
const nativePair = pair.replace(base, ETHER_ADDRESS);
|
|
126
|
+
normalizedPrices[nativePair.toLowerCase()] = levels;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.dexHelper.cache.setex(
|
|
131
|
+
this.dexKey,
|
|
132
|
+
this.network,
|
|
133
|
+
this.pricesCacheKey,
|
|
134
|
+
this.pricesCacheTTL,
|
|
135
|
+
JSON.stringify(normalizedPrices),
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { SwapSide } from '../../constants';
|
|
2
|
+
import { RequestHeaders } from '../../dex-helper';
|
|
3
|
+
|
|
4
|
+
export type BebopRateFetcherConfig = {
|
|
5
|
+
rateConfig: {
|
|
6
|
+
pricesReqParams: {
|
|
7
|
+
url: string;
|
|
8
|
+
headers?: RequestHeaders;
|
|
9
|
+
params?: any;
|
|
10
|
+
};
|
|
11
|
+
tokensReqParams: {
|
|
12
|
+
url: string;
|
|
13
|
+
headers?: RequestHeaders;
|
|
14
|
+
params?: any;
|
|
15
|
+
};
|
|
16
|
+
tokensIntervalMs: number;
|
|
17
|
+
pricesCacheKey: string;
|
|
18
|
+
tokensAddrCacheKey: string;
|
|
19
|
+
tokensCacheKey: string;
|
|
20
|
+
pricesCacheTTLSecs: number;
|
|
21
|
+
tokensCacheTTLSecs: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type TokenDataMap = { [index: string]: BebopToken };
|
|
26
|
+
|
|
27
|
+
export type BebopToken = {
|
|
28
|
+
decimals: number;
|
|
29
|
+
contractAddress: string;
|
|
30
|
+
ticker: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type BebopTokensResponse = {
|
|
34
|
+
tokens: { [symbol: string]: BebopToken };
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type BebopLevel = [price: number, size: number];
|
|
38
|
+
|
|
39
|
+
export type BebopPair = {
|
|
40
|
+
bids: BebopLevel[];
|
|
41
|
+
asks: BebopLevel[];
|
|
42
|
+
last_update_ts: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type BebopPricingResponse = {
|
|
46
|
+
[pair: string]: BebopPair;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export interface BebopTx {
|
|
50
|
+
to: string;
|
|
51
|
+
value: string;
|
|
52
|
+
data: string;
|
|
53
|
+
from: string;
|
|
54
|
+
gas: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type BebopTokenAmount = {
|
|
58
|
+
amount: string;
|
|
59
|
+
priceUsd: number;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// For now nothing but we may have to add something
|
|
63
|
+
export type BebopData = {
|
|
64
|
+
expiry?: number;
|
|
65
|
+
buyTokens?: { [address: string]: BebopTokenAmount };
|
|
66
|
+
sellTokens?: { [address: string]: BebopTokenAmount };
|
|
67
|
+
tx?: BebopTx;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type DexParams = {
|
|
71
|
+
settlementAddress: string;
|
|
72
|
+
chainName: string;
|
|
73
|
+
middleTokens: string[];
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export type RoutingInstruction = {
|
|
77
|
+
side: SwapSide; // Buy for bids, Sell for asks
|
|
78
|
+
book: BebopPair;
|
|
79
|
+
pair: string;
|
|
80
|
+
targetQuote: boolean;
|
|
81
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import joi from 'joi';
|
|
2
|
+
|
|
3
|
+
// const pairValidator = joi.object({
|
|
4
|
+
// base: joi.string().min(1).required(),
|
|
5
|
+
// quote: joi.string().min(1).required(),
|
|
6
|
+
// liquidityUSD: joi.number().min(0).required(),
|
|
7
|
+
// baseAddress: joi.string().min(1).required(),
|
|
8
|
+
// quoteAddress: joi.string().min(1).required(),
|
|
9
|
+
// baseDecimals: joi.number().min(0).required(),
|
|
10
|
+
// quoteDecimals: joi.number().min(0).required(),
|
|
11
|
+
// });
|
|
12
|
+
|
|
13
|
+
// export const pairsResponseValidator = joi
|
|
14
|
+
// .object()
|
|
15
|
+
// .pattern(joi.string(), pairValidator);
|
|
16
|
+
|
|
17
|
+
const levelValidator = joi.array().items(joi.number()).length(2);
|
|
18
|
+
|
|
19
|
+
const pairValidator = joi.object({
|
|
20
|
+
bids: joi.array().items(levelValidator).required(),
|
|
21
|
+
asks: joi.array().items(levelValidator).required(),
|
|
22
|
+
last_update_ts: joi.number().min(0).required(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const pricesResponseValidator = joi
|
|
26
|
+
.object()
|
|
27
|
+
.pattern(joi.string(), pairValidator);
|
|
28
|
+
|
|
29
|
+
const tokenValidator = joi
|
|
30
|
+
.object({
|
|
31
|
+
ticker: joi.string().min(1).required(),
|
|
32
|
+
contractAddress: joi.string().min(1).required(),
|
|
33
|
+
decimals: joi.number().min(0).required(),
|
|
34
|
+
})
|
|
35
|
+
.unknown(true);
|
|
36
|
+
|
|
37
|
+
export const tokensResponseValidator = joi.object({
|
|
38
|
+
tokens: joi.object().pattern(joi.string(), tokenValidator),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const blacklistResponseValidator = joi.object({
|
|
42
|
+
blacklist: joi.array().items(joi.string().min(1)).required(),
|
|
43
|
+
});
|
package/src/dex/index.ts
CHANGED
|
@@ -76,6 +76,7 @@ import { AngleStakedStable } from './angle-staked-stable/angle-staked-stable';
|
|
|
76
76
|
import { QuickPerps } from './quick-perps/quick-perps';
|
|
77
77
|
import { NomiswapV2 } from './uniswap-v2/nomiswap-v2';
|
|
78
78
|
import { Dexalot } from './dexalot/dexalot';
|
|
79
|
+
import { Bebop } from './bebop/bebop';
|
|
79
80
|
import { Wombat } from './wombat/wombat';
|
|
80
81
|
import { Swell } from './swell/swell';
|
|
81
82
|
import { PharaohV1 } from './solidly/forks-override/pharaohV1';
|
|
@@ -110,6 +111,7 @@ const LegacyDexes = [
|
|
|
110
111
|
];
|
|
111
112
|
|
|
112
113
|
const Dexes = [
|
|
114
|
+
Bebop,
|
|
113
115
|
Dexalot,
|
|
114
116
|
CurveV1,
|
|
115
117
|
CurveFork,
|
package/src/dex/spark/config.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { SparkParams } from './types';
|
|
|
2
2
|
import { DexConfigMap } from '../../types';
|
|
3
3
|
import { Network } from '../../constants';
|
|
4
4
|
import { SwapSide } from '@paraswap/core';
|
|
5
|
+
import PotAbi from '../../abi/maker-psm/pot.json';
|
|
6
|
+
import SavingsUSDSAbi from '../../abi/sdai/SavingsUSDS.abi.json';
|
|
7
|
+
import { Interface } from '@ethersproject/abi';
|
|
5
8
|
|
|
6
9
|
export const SDaiConfig: DexConfigMap<SparkParams> = {
|
|
7
10
|
Spark: {
|
|
@@ -9,6 +12,27 @@ export const SDaiConfig: DexConfigMap<SparkParams> = {
|
|
|
9
12
|
sdaiAddress: '0x83F20F44975D03b1b09e64809B757c47f942BEeA',
|
|
10
13
|
daiAddress: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
|
|
11
14
|
potAddress: '0x197E90f9FAD81970bA7976f33CbD77088E5D7cf7',
|
|
15
|
+
savingsRate: {
|
|
16
|
+
symbol: 'dsr',
|
|
17
|
+
// bytes32 repr of "dsr" string
|
|
18
|
+
topic:
|
|
19
|
+
'0x6473720000000000000000000000000000000000000000000000000000000000',
|
|
20
|
+
},
|
|
21
|
+
poolInterface: new Interface(PotAbi),
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
sUSDS: {
|
|
25
|
+
[Network.MAINNET]: {
|
|
26
|
+
sdaiAddress: '0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD', // sUSDS
|
|
27
|
+
daiAddress: '0xdC035D45d973E3EC169d2276DDab16f1e407384F', // USDS
|
|
28
|
+
potAddress: '0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD', // no separate pot, sUSDS is the pot
|
|
29
|
+
savingsRate: {
|
|
30
|
+
symbol: 'ssr',
|
|
31
|
+
// bytes32 repr of "ssr" string
|
|
32
|
+
topic:
|
|
33
|
+
'0x7373720000000000000000000000000000000000000000000000000000000000',
|
|
34
|
+
},
|
|
35
|
+
poolInterface: new Interface(SavingsUSDSAbi),
|
|
12
36
|
},
|
|
13
37
|
},
|
|
14
38
|
};
|
|
@@ -23,23 +23,8 @@ function testForNetwork(
|
|
|
23
23
|
const holders = Holders[network];
|
|
24
24
|
|
|
25
25
|
const sideToContractMethods = new Map([
|
|
26
|
-
[
|
|
27
|
-
|
|
28
|
-
[
|
|
29
|
-
ContractMethod.simpleSwap,
|
|
30
|
-
ContractMethod.multiSwap,
|
|
31
|
-
ContractMethod.megaSwap,
|
|
32
|
-
ContractMethod.swapExactAmountIn,
|
|
33
|
-
],
|
|
34
|
-
],
|
|
35
|
-
[
|
|
36
|
-
SwapSide.BUY,
|
|
37
|
-
[
|
|
38
|
-
ContractMethod.simpleBuy,
|
|
39
|
-
ContractMethod.buy,
|
|
40
|
-
ContractMethod.swapExactAmountOut,
|
|
41
|
-
],
|
|
42
|
-
],
|
|
26
|
+
[SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
|
|
27
|
+
[SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
|
|
43
28
|
]);
|
|
44
29
|
|
|
45
30
|
describe(`${network}`, () => {
|
|
@@ -80,10 +65,9 @@ function testForNetwork(
|
|
|
80
65
|
});
|
|
81
66
|
}
|
|
82
67
|
|
|
83
|
-
describe('
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
describe('Mainnet', () => {
|
|
68
|
+
describe('Spark E2E', () => {
|
|
69
|
+
describe('sDai', () => {
|
|
70
|
+
const dexKey = 'Spark';
|
|
87
71
|
const network = Network.MAINNET;
|
|
88
72
|
|
|
89
73
|
const tokenASymbol: string = 'DAI';
|
|
@@ -101,4 +85,24 @@ describe('sDAI E2E', () => {
|
|
|
101
85
|
tokenBAmount,
|
|
102
86
|
);
|
|
103
87
|
});
|
|
88
|
+
|
|
89
|
+
describe('sUSDS', () => {
|
|
90
|
+
const dexKey = 'sUSDS';
|
|
91
|
+
const network = Network.MAINNET;
|
|
92
|
+
|
|
93
|
+
const tokenASymbol: string = 'USDS';
|
|
94
|
+
const tokenBSymbol: string = 'sUSDS';
|
|
95
|
+
|
|
96
|
+
const tokenAAmount: string = '1000000000000000000';
|
|
97
|
+
const tokenBAmount: string = '1000000000000000000';
|
|
98
|
+
|
|
99
|
+
testForNetwork(
|
|
100
|
+
network,
|
|
101
|
+
dexKey,
|
|
102
|
+
tokenASymbol,
|
|
103
|
+
tokenBSymbol,
|
|
104
|
+
tokenAAmount,
|
|
105
|
+
tokenBAmount,
|
|
106
|
+
);
|
|
107
|
+
});
|
|
104
108
|
});
|
|
@@ -12,41 +12,7 @@ import PotAbi from '../../abi/maker-psm/pot.json';
|
|
|
12
12
|
import { Interface } from '@ethersproject/abi';
|
|
13
13
|
import _ from 'lodash';
|
|
14
14
|
|
|
15
|
-
/*
|
|
16
|
-
README
|
|
17
|
-
======
|
|
18
|
-
|
|
19
|
-
This test script adds unit tests for SDai event based
|
|
20
|
-
system. This is done by fetching the state on-chain before the
|
|
21
|
-
event block, manually pushing the block logs to the event-subscriber,
|
|
22
|
-
comparing the local state with on-chain state.
|
|
23
|
-
|
|
24
|
-
Most of the logic for testing is abstracted by `testEventSubscriber`.
|
|
25
|
-
You need to do two things to make the tests work:
|
|
26
|
-
|
|
27
|
-
1. Fetch the block numbers where certain events were released. You
|
|
28
|
-
can modify the `./scripts/fetch-event-blocknumber.ts` to get the
|
|
29
|
-
block numbers for different events. Make sure to get sufficient
|
|
30
|
-
number of blockNumbers to cover all possible cases for the event
|
|
31
|
-
mutations.
|
|
32
|
-
|
|
33
|
-
2. Complete the implementation for fetchPoolState function. The
|
|
34
|
-
function should fetch the on-chain state of the event subscriber
|
|
35
|
-
using just the blocknumber.
|
|
36
|
-
|
|
37
|
-
The template tests only include the test for a single event
|
|
38
|
-
subscriber. There can be cases where multiple event subscribers
|
|
39
|
-
exist for a single DEX. In such cases additional tests should be
|
|
40
|
-
added.
|
|
41
|
-
|
|
42
|
-
You can run this individual test script by running:
|
|
43
|
-
`npx jest src/dex/<dex-name>/<dex-name>-events.test.ts`
|
|
44
|
-
|
|
45
|
-
(This comment should be removed from the final implementation)
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
15
|
jest.setTimeout(50 * 1000);
|
|
49
|
-
const dexKey = 'Spark';
|
|
50
16
|
const network = Network.MAINNET;
|
|
51
17
|
|
|
52
18
|
async function fetchPoolState(
|
|
@@ -56,7 +22,8 @@ async function fetchPoolState(
|
|
|
56
22
|
return sdaiPool.generateState(blockNumber);
|
|
57
23
|
}
|
|
58
24
|
|
|
59
|
-
describe('SDai
|
|
25
|
+
describe('SDai', function () {
|
|
26
|
+
const dexKey = 'Spark';
|
|
60
27
|
const blockNumbers: { [eventName: string]: number[] } = {
|
|
61
28
|
drip: [19827559, 19827524, 19827163, 19827124, 19827000, 19826892],
|
|
62
29
|
// TODO: no matching logs, you have to manually call "file"
|
|
@@ -69,33 +36,81 @@ describe('SDai Event', function () {
|
|
|
69
36
|
potAddress: SDaiConfig[dexKey][network].potAddress,
|
|
70
37
|
};
|
|
71
38
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
)
|
|
98
|
-
|
|
39
|
+
const potIface = SDaiConfig[dexKey][network].poolInterface;
|
|
40
|
+
|
|
41
|
+
Object.keys(blockNumbers).forEach((event: string) => {
|
|
42
|
+
blockNumbers[event].forEach((blockNumber: number) => {
|
|
43
|
+
it(`Should return the correct state after the ${blockNumber}:${event}`, async function () {
|
|
44
|
+
const dexHelper = new DummyDexHelper(network);
|
|
45
|
+
const logger = dexHelper.getLogger(dexKey);
|
|
46
|
+
|
|
47
|
+
const sdaiPool = new SparkSDaiEventPool(
|
|
48
|
+
dexKey,
|
|
49
|
+
network,
|
|
50
|
+
`dai-sdai-pool`,
|
|
51
|
+
dexHelper,
|
|
52
|
+
addresses.potAddress,
|
|
53
|
+
potIface,
|
|
54
|
+
logger,
|
|
55
|
+
'0x6473720000000000000000000000000000000000000000000000000000000000',
|
|
56
|
+
'dsr',
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
await sdaiPool.initialize(blockNumber);
|
|
60
|
+
|
|
61
|
+
await testEventSubscriber(
|
|
62
|
+
sdaiPool,
|
|
63
|
+
sdaiPool.addressesSubscribed,
|
|
64
|
+
(_blockNumber: number) => fetchPoolState(sdaiPool, _blockNumber),
|
|
65
|
+
blockNumber,
|
|
66
|
+
`${dexKey}_${sdaiPool}`,
|
|
67
|
+
dexHelper.provider,
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('sUSDS', function () {
|
|
75
|
+
const dexKey = 'sUSDS';
|
|
76
|
+
const blockNumbers: { [eventName: string]: number[] } = {
|
|
77
|
+
drip: [20812786, 20812797, 20813343, 20813668, 20814065, 20814418],
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const addresses: { [contract: string]: string } = {
|
|
81
|
+
potAddress: SDaiConfig[dexKey][network].potAddress,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const potIface = SDaiConfig[dexKey][network].poolInterface;
|
|
85
|
+
|
|
86
|
+
Object.keys(blockNumbers).forEach((event: string) => {
|
|
87
|
+
blockNumbers[event].forEach((blockNumber: number) => {
|
|
88
|
+
it(`Should return the correct state after the ${blockNumber}:${event}`, async function () {
|
|
89
|
+
const dexHelper = new DummyDexHelper(network);
|
|
90
|
+
const logger = dexHelper.getLogger(dexKey);
|
|
91
|
+
|
|
92
|
+
const sUSDSPool = new SparkSDaiEventPool(
|
|
93
|
+
dexKey,
|
|
94
|
+
network,
|
|
95
|
+
`usds-susds-pool`,
|
|
96
|
+
dexHelper,
|
|
97
|
+
addresses.potAddress,
|
|
98
|
+
potIface,
|
|
99
|
+
logger,
|
|
100
|
+
'0x7373720000000000000000000000000000000000000000000000000000000000',
|
|
101
|
+
'ssr',
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
await sUSDSPool.initialize(blockNumber);
|
|
105
|
+
|
|
106
|
+
await testEventSubscriber(
|
|
107
|
+
sUSDSPool,
|
|
108
|
+
sUSDSPool.addressesSubscribed,
|
|
109
|
+
(_blockNumber: number) => fetchPoolState(sUSDSPool, _blockNumber),
|
|
110
|
+
blockNumber,
|
|
111
|
+
`${dexKey}_${sUSDSPool}`,
|
|
112
|
+
dexHelper.provider,
|
|
113
|
+
);
|
|
99
114
|
});
|
|
100
115
|
});
|
|
101
116
|
});
|