@paraswap/dex-lib 3.8.35 → 3.8.36-susds
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/lite-psm/usdsPsm.json +163 -0
- package/build/abi/sdai/SavingsUSDS.abi.json +720 -0
- package/build/dex/lite-psm/config.js +5 -1
- package/build/dex/lite-psm/config.js.map +1 -1
- package/build/dex/lite-psm/lite-psm.d.ts +4 -2
- package/build/dex/lite-psm/lite-psm.js +39 -26
- package/build/dex/lite-psm/lite-psm.js.map +1 -1
- package/build/dex/lite-psm/types.d.ts +2 -2
- 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 +4 -1
- package/build/dex/spark/spark-sdai-pool.js +6 -7
- package/build/dex/spark/spark-sdai-pool.js.map +1 -1
- package/build/dex/spark/spark.d.ts +3 -3
- package/build/dex/spark/spark.js +4 -4
- 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/usual-bond/usual-bond.js +5 -11
- package/build/dex/usual-bond/usual-bond.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/lite-psm/usdsPsm.json +163 -0
- package/src/abi/sdai/SavingsUSDS.abi.json +720 -0
- package/src/dex/lite-psm/config.ts +5 -1
- package/src/dex/lite-psm/lite-psm-e2e.test.ts +68 -1
- package/src/dex/lite-psm/lite-psm.ts +52 -31
- package/src/dex/lite-psm/types.ts +3 -2
- 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 +28 -9
- package/src/dex/spark/spark-events.test.ts +77 -62
- package/src/dex/spark/spark-integration.test.ts +141 -7
- package/src/dex/spark/spark-sdai-pool.ts +10 -5
- package/src/dex/spark/spark.ts +6 -2
- package/src/dex/spark/types.ts +6 -0
- package/src/dex/spark/utils.ts +83 -19
- package/tests/constants-e2e.ts +6 -1
|
@@ -10,6 +10,11 @@ export const LitePsmConfig: DexConfigMap<DexParams> = {
|
|
|
10
10
|
address: '0x6b175474e89094c44da98b954eedeac495271d0f',
|
|
11
11
|
decimals: 18,
|
|
12
12
|
},
|
|
13
|
+
usds: {
|
|
14
|
+
address: '0xdc035d45d973e3ec169d2276ddab16f1e407384f',
|
|
15
|
+
decimals: 18,
|
|
16
|
+
},
|
|
17
|
+
usdsPsmAddress: '0xA188EEC8F81263234dA3622A406892F3D630f98c',
|
|
13
18
|
vatAddress: '0x35d1b3f3d7966a1dfe207aa4514c12a259a0492b',
|
|
14
19
|
pools: [
|
|
15
20
|
{
|
|
@@ -17,7 +22,6 @@ export const LitePsmConfig: DexConfigMap<DexParams> = {
|
|
|
17
22
|
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
18
23
|
decimals: 6,
|
|
19
24
|
},
|
|
20
|
-
gemJoinAddress: '0xf6e72db5454dd049d0788e411b06cfaf16853042', // Same as psmAddress. LitePsm does not have an external gem join.
|
|
21
25
|
pocketAddress: '0x37305b1cd40574e4c5ce33f8e8306be057fd7341',
|
|
22
26
|
psmAddress: '0xf6e72db5454dd049d0788e411b06cfaf16853042',
|
|
23
27
|
identifier:
|
|
@@ -10,7 +10,7 @@ import { generateConfig } from '../../config';
|
|
|
10
10
|
describe('LitePsm E2E', () => {
|
|
11
11
|
const dexKey = 'LitePsm';
|
|
12
12
|
|
|
13
|
-
describe('LitePsm
|
|
13
|
+
describe('LitePsm DAI', () => {
|
|
14
14
|
const network = Network.MAINNET;
|
|
15
15
|
const tokens = Tokens[network];
|
|
16
16
|
const holders = Holders[network];
|
|
@@ -76,4 +76,71 @@ describe('LitePsm E2E', () => {
|
|
|
76
76
|
}),
|
|
77
77
|
);
|
|
78
78
|
});
|
|
79
|
+
|
|
80
|
+
describe('LitePsm USDS', () => {
|
|
81
|
+
const network = Network.MAINNET;
|
|
82
|
+
const tokens = Tokens[network];
|
|
83
|
+
const holders = Holders[network];
|
|
84
|
+
const provider = new StaticJsonRpcProvider(
|
|
85
|
+
generateConfig(network).privateHttpProvider,
|
|
86
|
+
network,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const tokenASymbol: string = 'USDC';
|
|
90
|
+
const tokenBSymbol: string = 'USDS';
|
|
91
|
+
|
|
92
|
+
const tokenAAmount: string = '10000000';
|
|
93
|
+
const tokenBAmount: string = '10000000000000000';
|
|
94
|
+
|
|
95
|
+
const sideToContractMethods = new Map([
|
|
96
|
+
[
|
|
97
|
+
SwapSide.SELL,
|
|
98
|
+
[
|
|
99
|
+
ContractMethod.swapExactAmountIn,
|
|
100
|
+
ContractMethod.swapExactAmountInOutOnMakerPSM,
|
|
101
|
+
],
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
SwapSide.BUY,
|
|
105
|
+
[
|
|
106
|
+
ContractMethod.swapExactAmountOut,
|
|
107
|
+
ContractMethod.swapExactAmountInOutOnMakerPSM,
|
|
108
|
+
],
|
|
109
|
+
],
|
|
110
|
+
]);
|
|
111
|
+
|
|
112
|
+
sideToContractMethods.forEach((contractMethods, side) =>
|
|
113
|
+
contractMethods.forEach((contractMethod: ContractMethod) => {
|
|
114
|
+
describe(`${contractMethod}`, () => {
|
|
115
|
+
it(`${side}:${tokenASymbol} -> ${tokenBSymbol}`, async () => {
|
|
116
|
+
await testE2E(
|
|
117
|
+
tokens[tokenASymbol],
|
|
118
|
+
tokens[tokenBSymbol],
|
|
119
|
+
holders[tokenASymbol],
|
|
120
|
+
side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
|
|
121
|
+
side,
|
|
122
|
+
dexKey,
|
|
123
|
+
contractMethod,
|
|
124
|
+
network,
|
|
125
|
+
provider,
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it(`${side}:${tokenBSymbol} -> ${tokenASymbol}`, async () => {
|
|
130
|
+
await testE2E(
|
|
131
|
+
tokens[tokenBSymbol],
|
|
132
|
+
tokens[tokenASymbol],
|
|
133
|
+
holders[tokenBSymbol],
|
|
134
|
+
side === SwapSide.SELL ? tokenBAmount : tokenAAmount,
|
|
135
|
+
side,
|
|
136
|
+
dexKey,
|
|
137
|
+
contractMethod,
|
|
138
|
+
network,
|
|
139
|
+
provider,
|
|
140
|
+
);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}),
|
|
144
|
+
);
|
|
145
|
+
});
|
|
79
146
|
});
|
|
@@ -4,9 +4,7 @@ import {
|
|
|
4
4
|
Address,
|
|
5
5
|
ExchangePrices,
|
|
6
6
|
PoolPrices,
|
|
7
|
-
Log,
|
|
8
7
|
AdapterExchangeParam,
|
|
9
|
-
SimpleExchangeParam,
|
|
10
8
|
PoolLiquidity,
|
|
11
9
|
Logger,
|
|
12
10
|
NumberAsString,
|
|
@@ -32,7 +30,8 @@ import {
|
|
|
32
30
|
} from './types';
|
|
33
31
|
import { SimpleExchange } from '../simple-exchange';
|
|
34
32
|
import { LitePsmConfig } from './config';
|
|
35
|
-
import
|
|
33
|
+
import DaiPsmABI from '../../abi/lite-psm/psm.json';
|
|
34
|
+
import UsdsPsmABI from '../../abi/lite-psm/usdsPsm.json';
|
|
36
35
|
import { BI_POWS } from '../../bigint-constants';
|
|
37
36
|
import { SpecialDex } from '../../executor/types';
|
|
38
37
|
import { hexConcat, hexZeroPad, hexlify } from '@ethersproject/bytes';
|
|
@@ -45,7 +44,8 @@ import { BigNumber } from 'ethers';
|
|
|
45
44
|
import { LitePsmEventPool, getOnChainState } from './lite-psm-event-pool';
|
|
46
45
|
import { extractReturnAmountPosition } from '../../executor/utils';
|
|
47
46
|
|
|
48
|
-
const
|
|
47
|
+
const daiPsmInterface = new Interface(DaiPsmABI);
|
|
48
|
+
const usdsPsmInterface = new Interface(UsdsPsmABI);
|
|
49
49
|
const WAD = BI_POWS[18];
|
|
50
50
|
|
|
51
51
|
const ceilDiv = (a: bigint, b: bigint) => (a + b - 1n) / b;
|
|
@@ -70,6 +70,8 @@ export class LitePsm
|
|
|
70
70
|
dexKey: string,
|
|
71
71
|
protected dexHelper: IDexHelper,
|
|
72
72
|
protected dai: Token = LitePsmConfig[dexKey][network].dai,
|
|
73
|
+
protected usds: Token = LitePsmConfig[dexKey][network].usds,
|
|
74
|
+
protected usdsPsm: Address = LitePsmConfig[dexKey][network].usdsPsmAddress,
|
|
73
75
|
protected vatAddress: Address = LitePsmConfig[dexKey][network].vatAddress,
|
|
74
76
|
protected poolConfigs: PoolConfig[] = LitePsmConfig[dexKey][network].pools,
|
|
75
77
|
) {
|
|
@@ -123,6 +125,8 @@ export class LitePsm
|
|
|
123
125
|
return (
|
|
124
126
|
(srcAddress === this.dai.address && this.eventPools[destAddress]) ||
|
|
125
127
|
(destAddress === this.dai.address && this.eventPools[srcAddress]) ||
|
|
128
|
+
(srcAddress === this.usds.address && this.eventPools[destAddress]) ||
|
|
129
|
+
(destAddress === this.usds.address && this.eventPools[srcAddress]) ||
|
|
126
130
|
null
|
|
127
131
|
);
|
|
128
132
|
}
|
|
@@ -153,7 +157,7 @@ export class LitePsm
|
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
computePrices(
|
|
156
|
-
|
|
160
|
+
isDestGem: boolean,
|
|
157
161
|
to18ConversionFactor: bigint,
|
|
158
162
|
side: SwapSide,
|
|
159
163
|
amounts: bigint[],
|
|
@@ -168,7 +172,7 @@ export class LitePsm
|
|
|
168
172
|
|
|
169
173
|
return amounts.map(a => {
|
|
170
174
|
if (side === SwapSide.SELL) {
|
|
171
|
-
if (
|
|
175
|
+
if (isDestGem) {
|
|
172
176
|
const gemAmt18 = (a * WAD) / (WAD + poolState.tout);
|
|
173
177
|
if (buyGemCheck(gemAmt18)) return gemAmt18 / to18ConversionFactor;
|
|
174
178
|
} else {
|
|
@@ -177,7 +181,7 @@ export class LitePsm
|
|
|
177
181
|
return gemAmt18 - (gemAmt18 * poolState.tin) / WAD;
|
|
178
182
|
}
|
|
179
183
|
} else {
|
|
180
|
-
if (
|
|
184
|
+
if (isDestGem) {
|
|
181
185
|
const gemAmt18 = to18ConversionFactor * a;
|
|
182
186
|
if (buyGemCheck(gemAmt18))
|
|
183
187
|
return gemAmt18 + (gemAmt18 * poolState.tout) / WAD;
|
|
@@ -214,33 +218,39 @@ export class LitePsm
|
|
|
214
218
|
(side === SwapSide.SELL ? srcToken : destToken).decimals,
|
|
215
219
|
);
|
|
216
220
|
|
|
217
|
-
const
|
|
218
|
-
const
|
|
221
|
+
const srcLower = srcToken.address.toLowerCase();
|
|
222
|
+
const isSrcDai = srcLower === this.dai.address;
|
|
223
|
+
const isDaiSwap =
|
|
224
|
+
isSrcDai || destToken.address.toLowerCase() === this.dai.address;
|
|
225
|
+
|
|
226
|
+
const isDestGem = isSrcDai || srcLower === this.usds.address;
|
|
227
|
+
|
|
228
|
+
const gem = isDestGem ? destToken : srcToken;
|
|
219
229
|
const toll =
|
|
220
|
-
(side === SwapSide.SELL &&
|
|
221
|
-
(side === SwapSide.BUY && !
|
|
230
|
+
(side === SwapSide.SELL && isDestGem) ||
|
|
231
|
+
(side === SwapSide.BUY && !isDestGem)
|
|
222
232
|
? poolState.tout
|
|
223
233
|
: poolState.tin;
|
|
224
234
|
|
|
225
235
|
const [unit, ...prices] = this.computePrices(
|
|
226
|
-
|
|
236
|
+
isDestGem,
|
|
227
237
|
eventPool.to18ConversionFactor,
|
|
228
238
|
side,
|
|
229
239
|
[unitVolume, ...amounts],
|
|
230
240
|
poolState,
|
|
231
241
|
);
|
|
232
242
|
|
|
243
|
+
const psm = isDaiSwap ? eventPool.poolConfig.psmAddress : this.usdsPsm;
|
|
233
244
|
return [
|
|
234
245
|
{
|
|
235
246
|
prices,
|
|
236
247
|
unit,
|
|
237
248
|
data: {
|
|
238
249
|
toll: toll.toString(),
|
|
239
|
-
psmAddress:
|
|
240
|
-
gemJoinAddress: eventPool.poolConfig.gemJoinAddress,
|
|
250
|
+
psmAddress: psm,
|
|
241
251
|
gemDecimals: gem.decimals,
|
|
242
252
|
},
|
|
243
|
-
poolAddresses: [
|
|
253
|
+
poolAddresses: [psm],
|
|
244
254
|
exchange: this.dexKey,
|
|
245
255
|
gasCost: 50000,
|
|
246
256
|
poolIdentifier,
|
|
@@ -270,10 +280,12 @@ export class LitePsm
|
|
|
270
280
|
data: LitePsmData,
|
|
271
281
|
side: SwapSide,
|
|
272
282
|
): { isGemSell: boolean; gemAmount: string } {
|
|
273
|
-
const
|
|
283
|
+
const isDestGem =
|
|
284
|
+
srcToken.toLowerCase() === this.dai.address ||
|
|
285
|
+
srcToken.toLowerCase() === this.usds.address;
|
|
274
286
|
const to18ConversionFactor = getBigIntPow(18 - data.gemDecimals);
|
|
275
287
|
if (side === SwapSide.SELL) {
|
|
276
|
-
if (
|
|
288
|
+
if (isDestGem) {
|
|
277
289
|
const gemAmt18 = (BigInt(srcAmount) * WAD) / (WAD + BigInt(data.toll));
|
|
278
290
|
return {
|
|
279
291
|
isGemSell: false,
|
|
@@ -283,7 +295,7 @@ export class LitePsm
|
|
|
283
295
|
return { isGemSell: true, gemAmount: srcAmount };
|
|
284
296
|
}
|
|
285
297
|
} else {
|
|
286
|
-
if (
|
|
298
|
+
if (isDestGem) {
|
|
287
299
|
return { isGemSell: false, gemAmount: destAmount };
|
|
288
300
|
} else {
|
|
289
301
|
const gemAmt = ceilDiv(
|
|
@@ -338,9 +350,7 @@ export class LitePsm
|
|
|
338
350
|
isApproved = await this.dexHelper.augustusApprovals.hasApproval(
|
|
339
351
|
options.executionContractAddress,
|
|
340
352
|
srcToken.address,
|
|
341
|
-
|
|
342
|
-
? optimalSwapExchange.data.psmAddress
|
|
343
|
-
: optimalSwapExchange.data.gemJoinAddress,
|
|
353
|
+
optimalSwapExchange.data.psmAddress,
|
|
344
354
|
);
|
|
345
355
|
}
|
|
346
356
|
|
|
@@ -370,10 +380,16 @@ export class LitePsm
|
|
|
370
380
|
side,
|
|
371
381
|
);
|
|
372
382
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
383
|
+
const isDaiSwap =
|
|
384
|
+
destToken.toLowerCase() === this.dai.address ||
|
|
385
|
+
srcToken.toLowerCase() === this.dai.address;
|
|
386
|
+
|
|
387
|
+
let exchangeData = (
|
|
388
|
+
isDaiSwap ? daiPsmInterface : usdsPsmInterface
|
|
389
|
+
).encodeFunctionData(isGemSell ? 'sellGem' : 'buyGem', [
|
|
390
|
+
recipient,
|
|
391
|
+
gemAmount,
|
|
392
|
+
]);
|
|
377
393
|
|
|
378
394
|
// append toll and to18ConversionFactor & set specialDexFlag = SWAP_ON_MAKER_PSM to
|
|
379
395
|
// - `buyGem` on Ex1 & Ex2
|
|
@@ -397,10 +413,14 @@ export class LitePsm
|
|
|
397
413
|
exchangeData,
|
|
398
414
|
targetExchange: data.psmAddress,
|
|
399
415
|
specialDexFlag,
|
|
400
|
-
spender:
|
|
416
|
+
spender: data.psmAddress, // psm is the join for both dai and usds
|
|
401
417
|
returnAmountPos:
|
|
402
418
|
side === SwapSide.SELL && isGemSell
|
|
403
|
-
? extractReturnAmountPosition(
|
|
419
|
+
? extractReturnAmountPosition(
|
|
420
|
+
isDaiSwap ? daiPsmInterface : usdsPsmInterface,
|
|
421
|
+
'sellGem',
|
|
422
|
+
isDaiSwap ? 'daiOutWad' : 'usdsOutWad',
|
|
423
|
+
)
|
|
404
424
|
: undefined,
|
|
405
425
|
};
|
|
406
426
|
}
|
|
@@ -453,7 +473,7 @@ export class LitePsm
|
|
|
453
473
|
data.toll,
|
|
454
474
|
to18ConversionFactor.toString(),
|
|
455
475
|
data.psmAddress,
|
|
456
|
-
data.
|
|
476
|
+
data.psmAddress,
|
|
457
477
|
metadata,
|
|
458
478
|
beneficiaryDirectionApproveFlag.toString(),
|
|
459
479
|
];
|
|
@@ -492,9 +512,10 @@ export class LitePsm
|
|
|
492
512
|
);
|
|
493
513
|
};
|
|
494
514
|
|
|
495
|
-
const
|
|
515
|
+
const isDaiOrUsds =
|
|
516
|
+
_tokenAddress === this.dai.address || _tokenAddress === this.usds.address;
|
|
496
517
|
|
|
497
|
-
const validPoolConfigs =
|
|
518
|
+
const validPoolConfigs = isDaiOrUsds
|
|
498
519
|
? this.poolConfigs
|
|
499
520
|
: this.eventPools[_tokenAddress]
|
|
500
521
|
? [this.eventPools[_tokenAddress].poolConfig]
|
|
@@ -513,7 +534,7 @@ export class LitePsm
|
|
|
513
534
|
exchange: this.dexKey,
|
|
514
535
|
address: p.psmAddress,
|
|
515
536
|
liquidityUSD: minLiq(poolStates[i], p.gem.decimals),
|
|
516
|
-
connectorTokens:
|
|
537
|
+
connectorTokens: isDaiOrUsds ? [p.gem] : [this.dai, this.usds],
|
|
517
538
|
}));
|
|
518
539
|
}
|
|
519
540
|
}
|
|
@@ -10,7 +10,6 @@ export type PoolState = {
|
|
|
10
10
|
|
|
11
11
|
export type LitePsmData = {
|
|
12
12
|
psmAddress: Address;
|
|
13
|
-
gemJoinAddress: Address;
|
|
14
13
|
gemDecimals: number;
|
|
15
14
|
toll: string;
|
|
16
15
|
isApproved?: boolean;
|
|
@@ -18,7 +17,6 @@ export type LitePsmData = {
|
|
|
18
17
|
|
|
19
18
|
export type PoolConfig = {
|
|
20
19
|
gem: Token;
|
|
21
|
-
gemJoinAddress: Address; // dai liquidity
|
|
22
20
|
pocketAddress: Address; // gem liquidity
|
|
23
21
|
psmAddress: Address;
|
|
24
22
|
identifier: string; // bytes32 of pool identifier (Eg. bytes32("PSM-USDC-A"))
|
|
@@ -26,6 +24,8 @@ export type PoolConfig = {
|
|
|
26
24
|
|
|
27
25
|
export type DexParams = {
|
|
28
26
|
dai: Token;
|
|
27
|
+
usds: Token;
|
|
28
|
+
usdsPsmAddress: Address;
|
|
29
29
|
vatAddress: Address;
|
|
30
30
|
pools: PoolConfig[];
|
|
31
31
|
};
|
|
@@ -38,6 +38,7 @@ export type LitePsmParams = [
|
|
|
38
38
|
toll: NumberAsString,
|
|
39
39
|
to18ConversionFactor: NumberAsString,
|
|
40
40
|
exchange: Address,
|
|
41
|
+
// psm (exchange) is the join for both dai and usds
|
|
41
42
|
gemJoinAddress: Address,
|
|
42
43
|
metadata: string,
|
|
43
44
|
beneficiaryDirectionApproveFlag: NumberAsString,
|
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
|
};
|
|
@@ -26,17 +26,17 @@ function testForNetwork(
|
|
|
26
26
|
[
|
|
27
27
|
SwapSide.SELL,
|
|
28
28
|
[
|
|
29
|
-
ContractMethod.simpleSwap,
|
|
30
|
-
ContractMethod.multiSwap,
|
|
31
|
-
ContractMethod.megaSwap,
|
|
29
|
+
// ContractMethod.simpleSwap,
|
|
30
|
+
// ContractMethod.multiSwap,
|
|
31
|
+
// ContractMethod.megaSwap,
|
|
32
32
|
ContractMethod.swapExactAmountIn,
|
|
33
33
|
],
|
|
34
34
|
],
|
|
35
35
|
[
|
|
36
36
|
SwapSide.BUY,
|
|
37
37
|
[
|
|
38
|
-
ContractMethod.simpleBuy,
|
|
39
|
-
ContractMethod.buy,
|
|
38
|
+
// ContractMethod.simpleBuy,
|
|
39
|
+
// ContractMethod.buy,
|
|
40
40
|
ContractMethod.swapExactAmountOut,
|
|
41
41
|
],
|
|
42
42
|
],
|
|
@@ -80,10 +80,9 @@ function testForNetwork(
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
describe('
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
describe('Mainnet', () => {
|
|
83
|
+
describe('Spark E2E', () => {
|
|
84
|
+
describe('sDai', () => {
|
|
85
|
+
const dexKey = 'Spark';
|
|
87
86
|
const network = Network.MAINNET;
|
|
88
87
|
|
|
89
88
|
const tokenASymbol: string = 'DAI';
|
|
@@ -101,4 +100,24 @@ describe('sDAI E2E', () => {
|
|
|
101
100
|
tokenBAmount,
|
|
102
101
|
);
|
|
103
102
|
});
|
|
103
|
+
|
|
104
|
+
describe('sUSDS', () => {
|
|
105
|
+
const dexKey = 'sUSDS';
|
|
106
|
+
const network = Network.MAINNET;
|
|
107
|
+
|
|
108
|
+
const tokenASymbol: string = 'USDS';
|
|
109
|
+
const tokenBSymbol: string = 'sUSDS';
|
|
110
|
+
|
|
111
|
+
const tokenAAmount: string = '1000000000000000000';
|
|
112
|
+
const tokenBAmount: string = '1000000000000000000';
|
|
113
|
+
|
|
114
|
+
testForNetwork(
|
|
115
|
+
network,
|
|
116
|
+
dexKey,
|
|
117
|
+
tokenASymbol,
|
|
118
|
+
tokenBSymbol,
|
|
119
|
+
tokenAAmount,
|
|
120
|
+
tokenBAmount,
|
|
121
|
+
);
|
|
122
|
+
});
|
|
104
123
|
});
|
|
@@ -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
|
});
|