@paraswap/dex-lib 3.8.33 → 3.8.34-converters

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 (32) hide show
  1. package/build/abi/sky-converter/DaiUsdsConverter.json +116 -0
  2. package/build/abi/sky-converter/MkrSkyConverter.json +118 -0
  3. package/build/dex/aave-gsm/aave-gsm.d.ts +0 -1
  4. package/build/dex/aave-gsm/aave-gsm.js +0 -4
  5. package/build/dex/aave-gsm/aave-gsm.js.map +1 -1
  6. package/build/dex/inception/inception.js +9 -1
  7. package/build/dex/inception/inception.js.map +1 -1
  8. package/build/dex/inception/utils.d.ts +0 -1
  9. package/build/dex/inception/utils.js +1 -22
  10. package/build/dex/inception/utils.js.map +1 -1
  11. package/build/dex/index.js +2 -0
  12. package/build/dex/index.js.map +1 -1
  13. package/build/dex/sky-converter/config.d.ts +3 -0
  14. package/build/dex/sky-converter/config.js +35 -0
  15. package/build/dex/sky-converter/config.js.map +1 -0
  16. package/build/dex/sky-converter/sky-converter.d.ts +35 -0
  17. package/build/dex/sky-converter/sky-converter.js +170 -0
  18. package/build/dex/sky-converter/sky-converter.js.map +1 -0
  19. package/build/dex/sky-converter/types.d.ts +12 -0
  20. package/build/dex/sky-converter/types.js +3 -0
  21. package/build/dex/sky-converter/types.js.map +1 -0
  22. package/package.json +1 -1
  23. package/src/abi/sky-converter/DaiUsdsConverter.json +116 -0
  24. package/src/abi/sky-converter/MkrSkyConverter.json +118 -0
  25. package/src/dex/aave-gsm/aave-gsm.ts +0 -5
  26. package/src/dex/index.ts +2 -0
  27. package/src/dex/sky-converter/config.ts +31 -0
  28. package/src/dex/sky-converter/sky-converter-e2e.test.ts +113 -0
  29. package/src/dex/sky-converter/sky-converter-integration.test.ts +135 -0
  30. package/src/dex/sky-converter/sky-converter.ts +222 -0
  31. package/src/dex/sky-converter/types.ts +14 -0
  32. package/tests/constants-e2e.ts +15 -0
@@ -0,0 +1,135 @@
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+
4
+ import { DummyDexHelper } from '../../dex-helper/index';
5
+ import { Network, SwapSide } from '../../constants';
6
+ import { SkyConverter } from './sky-converter';
7
+ import { checkPoolPrices, checkPoolsLiquidity } from '../../../tests/utils';
8
+ import { Tokens } from '../../../tests/constants-e2e';
9
+ import { BI_POWS } from '../../bigint-constants';
10
+
11
+ const network = Network.MAINNET;
12
+
13
+ const tokenAAmounts = [
14
+ 0n,
15
+ 1n * BI_POWS[18],
16
+ 2n * BI_POWS[18],
17
+ 3n * BI_POWS[18],
18
+ 4n * BI_POWS[18],
19
+ 5n * BI_POWS[18],
20
+ 6n * BI_POWS[18],
21
+ 7n * BI_POWS[18],
22
+ 8n * BI_POWS[18],
23
+ 9n * BI_POWS[18],
24
+ 10n * BI_POWS[18],
25
+ ];
26
+
27
+ const tokenBAmounts = [
28
+ 0n,
29
+ 1n * BI_POWS[18],
30
+ 2n * BI_POWS[18],
31
+ 3n * BI_POWS[18],
32
+ 4n * BI_POWS[18],
33
+ 5n * BI_POWS[18],
34
+ 6n * BI_POWS[18],
35
+ 7n * BI_POWS[18],
36
+ 8n * BI_POWS[18],
37
+ 9n * BI_POWS[18],
38
+ 10n * BI_POWS[18],
39
+ ];
40
+
41
+ ['DaiUsds', 'MkrSky'].forEach(dexKey => {
42
+ const TokenASymbol = dexKey === 'DaiUsds' ? 'DAI' : 'MKR';
43
+ const TokenA = Tokens[network][TokenASymbol];
44
+
45
+ const TokenBSymbol = dexKey === 'DaiUsds' ? 'USDS' : 'SKY';
46
+ const TokenB = Tokens[network][TokenBSymbol];
47
+
48
+ describe(dexKey, function () {
49
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
50
+ const dexHelper = new DummyDexHelper(network);
51
+ const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
52
+ const skyConverter = new SkyConverter(network, dexKey, dexHelper);
53
+
54
+ const pools = await skyConverter.getPoolIdentifiers(
55
+ TokenA,
56
+ TokenB,
57
+ SwapSide.SELL,
58
+ blocknumber,
59
+ );
60
+ console.log(
61
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
62
+ pools,
63
+ );
64
+
65
+ expect(pools.length).toBeGreaterThan(0);
66
+
67
+ const poolPrices = await skyConverter.getPricesVolume(
68
+ TokenA,
69
+ TokenB,
70
+ tokenAAmounts,
71
+ SwapSide.SELL,
72
+ blocknumber,
73
+ pools,
74
+ );
75
+ console.log(
76
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
77
+ poolPrices,
78
+ );
79
+
80
+ expect(poolPrices).not.toBeNull();
81
+ checkPoolPrices(poolPrices!, tokenAAmounts, SwapSide.SELL, dexKey);
82
+ });
83
+
84
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
85
+ const dexHelper = new DummyDexHelper(network);
86
+ const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
87
+ const skyConverter = new SkyConverter(network, dexKey, dexHelper);
88
+
89
+ const pools = await skyConverter.getPoolIdentifiers(
90
+ TokenA,
91
+ TokenB,
92
+ SwapSide.BUY,
93
+ blocknumber,
94
+ );
95
+ console.log(
96
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
97
+ pools,
98
+ );
99
+
100
+ expect(pools.length).toBeGreaterThan(0);
101
+
102
+ const poolPrices = await skyConverter.getPricesVolume(
103
+ TokenA,
104
+ TokenB,
105
+ tokenBAmounts,
106
+ SwapSide.BUY,
107
+ blocknumber,
108
+ pools,
109
+ );
110
+ console.log(
111
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
112
+ poolPrices,
113
+ );
114
+
115
+ expect(poolPrices).not.toBeNull();
116
+ checkPoolPrices(poolPrices!, tokenBAmounts, SwapSide.BUY, dexKey);
117
+ });
118
+
119
+ it('getTopPoolsForToken', async function () {
120
+ const dexHelper = new DummyDexHelper(network);
121
+ const skyConverter = new SkyConverter(network, dexKey, dexHelper);
122
+
123
+ const poolLiquidity = await skyConverter.getTopPoolsForToken(
124
+ TokenA.address,
125
+ 10,
126
+ );
127
+ console.log(
128
+ `${TokenASymbol} Top Pools:`,
129
+ JSON.stringify(poolLiquidity, null, 2),
130
+ );
131
+
132
+ checkPoolsLiquidity(poolLiquidity, TokenA.address, dexKey);
133
+ });
134
+ });
135
+ });
@@ -0,0 +1,222 @@
1
+ import {
2
+ Token,
3
+ Address,
4
+ ExchangePrices,
5
+ PoolPrices,
6
+ AdapterExchangeParam,
7
+ PoolLiquidity,
8
+ Logger,
9
+ NumberAsString,
10
+ DexExchangeParam,
11
+ } from '../../types';
12
+ import { SwapSide, Network } from '../../constants';
13
+ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
14
+ import { getDexKeysWithNetwork } from '../../utils';
15
+ import { IDex } from '../../dex/idex';
16
+ import { IDexHelper } from '../../dex-helper/idex-helper';
17
+ import { SkyConverterData } from './types';
18
+ import { SimpleExchange } from '../simple-exchange';
19
+ import { SkyConverterConfig } from './config';
20
+ import { BI_POWS } from '../../bigint-constants';
21
+
22
+ export class SkyConverter
23
+ extends SimpleExchange
24
+ implements IDex<SkyConverterData>
25
+ {
26
+ readonly hasConstantPriceLargeAmounts = true;
27
+ readonly needWrapNative = false;
28
+
29
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
30
+ getDexKeysWithNetwork(SkyConverterConfig);
31
+
32
+ logger: Logger;
33
+
34
+ oldToken: Address;
35
+ newToken: Address;
36
+
37
+ constructor(
38
+ readonly network: Network,
39
+ readonly dexKey: string,
40
+ readonly dexHelper: IDexHelper,
41
+ readonly config = SkyConverterConfig[dexKey][network],
42
+ ) {
43
+ super(dexHelper, dexKey);
44
+ this.logger = dexHelper.getLogger(dexKey);
45
+
46
+ this.oldToken = this.config.oldTokenAddress.toLowerCase();
47
+ this.newToken = this.config.newTokenAddress.toLowerCase();
48
+ }
49
+
50
+ async initializePricing(blockNumber: number) {}
51
+
52
+ getAdapters(side: SwapSide): { name: string; index: number }[] | null {
53
+ return null;
54
+ }
55
+
56
+ async getPoolIdentifiers(
57
+ srcToken: Token,
58
+ destToken: Token,
59
+ side: SwapSide,
60
+ blockNumber: number,
61
+ ): Promise<string[]> {
62
+ if (
63
+ srcToken.address.toLowerCase() === this.oldToken &&
64
+ destToken.address.toLowerCase() === this.newToken
65
+ ) {
66
+ return [`${this.dexKey}_${destToken.address}`];
67
+ } else if (
68
+ srcToken.address.toLowerCase() === this.newToken &&
69
+ destToken.address.toLowerCase() === this.oldToken
70
+ ) {
71
+ return [`${this.dexKey}_${srcToken.address}`];
72
+ } else {
73
+ return [];
74
+ }
75
+ }
76
+
77
+ oldAmountToNewAmount(amount: bigint) {
78
+ return amount * this.config.newTokenRateMultiplier;
79
+ }
80
+
81
+ newAmountToOldAmount(amount: bigint) {
82
+ return amount / this.config.newTokenRateMultiplier;
83
+ }
84
+
85
+ async getPricesVolume(
86
+ srcToken: Token,
87
+ destToken: Token,
88
+ amounts: bigint[],
89
+ side: SwapSide,
90
+ blockNumber: number,
91
+ limitPools?: string[],
92
+ ): Promise<null | ExchangePrices<SkyConverterData>> {
93
+ const isKnown =
94
+ (srcToken.address.toLowerCase() === this.oldToken &&
95
+ destToken.address.toLowerCase() === this.newToken) ||
96
+ (srcToken.address.toLowerCase() === this.newToken &&
97
+ destToken.address.toLowerCase() === this.oldToken);
98
+
99
+ if (!isKnown) {
100
+ return null;
101
+ }
102
+
103
+ const isOldToNew = srcToken.address.toLowerCase() === this.oldToken;
104
+
105
+ let mappingFunction: Function;
106
+
107
+ if (side === SwapSide.SELL) {
108
+ if (isOldToNew) {
109
+ mappingFunction = this.oldAmountToNewAmount.bind(this);
110
+ } else {
111
+ mappingFunction = this.newAmountToOldAmount.bind(this);
112
+ }
113
+ } else {
114
+ if (isOldToNew) {
115
+ mappingFunction = this.newAmountToOldAmount.bind(this);
116
+ } else {
117
+ mappingFunction = this.oldAmountToNewAmount.bind(this);
118
+ }
119
+ }
120
+
121
+ return [
122
+ {
123
+ prices: amounts.map(el => mappingFunction(el)),
124
+ unit: BI_POWS[18],
125
+ // TODO: Update after simulations
126
+ gasCost: 40_000,
127
+ exchange: this.dexKey,
128
+ poolAddresses: [this.config.converterAddress],
129
+ data: null,
130
+ },
131
+ ];
132
+ }
133
+
134
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
135
+ getCalldataGasCost(
136
+ poolPrices: PoolPrices<SkyConverterData>,
137
+ ): number | number[] {
138
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
139
+ }
140
+
141
+ getAdapterParam(
142
+ srcToken: string,
143
+ destToken: string,
144
+ srcAmount: string,
145
+ destAmount: string,
146
+ data: SkyConverterData,
147
+ side: SwapSide,
148
+ ): AdapterExchangeParam {
149
+ // Encode here the payload for adapter
150
+ const payload = '';
151
+
152
+ return {
153
+ targetExchange: '0x',
154
+ payload,
155
+ networkFee: '0',
156
+ };
157
+ }
158
+
159
+ getDexParam(
160
+ srcToken: Address,
161
+ destToken: Address,
162
+ srcAmount: NumberAsString,
163
+ destAmount: NumberAsString,
164
+ recipient: Address,
165
+ data: SkyConverterData,
166
+ side: SwapSide,
167
+ ): DexExchangeParam {
168
+ const swapData = this.config.converterIface.encodeFunctionData(
169
+ srcToken === this.oldToken
170
+ ? this.config.oldToNewFunctionName
171
+ : this.config.newToOldFunctionName,
172
+ [recipient, srcAmount],
173
+ );
174
+
175
+ return {
176
+ needWrapNative: this.needWrapNative,
177
+ dexFuncHasRecipient: true,
178
+ exchangeData: swapData,
179
+ targetExchange: this.config.converterAddress,
180
+ returnAmountPos: undefined,
181
+ };
182
+ }
183
+
184
+ // Returns list of top pools based on liquidity. Max
185
+ // limit number pools should be returned.
186
+ async getTopPoolsForToken(
187
+ tokenAddress: Address,
188
+ limit: number,
189
+ ): Promise<PoolLiquidity[]> {
190
+ if (tokenAddress.toLowerCase() === this.oldToken) {
191
+ return [
192
+ {
193
+ exchange: this.dexKey,
194
+ address: this.config.converterAddress,
195
+ connectorTokens: [
196
+ {
197
+ decimals: 18,
198
+ address: this.newToken,
199
+ },
200
+ ],
201
+ liquidityUSD: 1000000000, // infinite
202
+ },
203
+ ];
204
+ } else if (tokenAddress.toLowerCase() === this.newToken) {
205
+ return [
206
+ {
207
+ exchange: this.dexKey,
208
+ address: this.config.converterAddress,
209
+ connectorTokens: [
210
+ {
211
+ decimals: 18,
212
+ address: this.oldToken,
213
+ },
214
+ ],
215
+ liquidityUSD: 1000000000, // infinite
216
+ },
217
+ ];
218
+ }
219
+
220
+ return [];
221
+ }
222
+ }
@@ -0,0 +1,14 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { Address } from '../../types';
3
+
4
+ export type SkyConverterData = null;
5
+
6
+ export type DexParams = {
7
+ converterAddress: Address;
8
+ oldTokenAddress: Address;
9
+ newTokenAddress: Address;
10
+ newTokenRateMultiplier: bigint;
11
+ oldToNewFunctionName: string;
12
+ newToOldFunctionName: string;
13
+ converterIface: Interface;
14
+ };
@@ -19,6 +19,18 @@ export const Tokens: {
19
19
  [network: number]: { [symbol: string]: SmartTokenParams };
20
20
  } = {
21
21
  [Network.MAINNET]: {
22
+ USDS: {
23
+ address: '0xdC035D45d973E3EC169d2276DDab16f1e407384F',
24
+ decimals: 18,
25
+ },
26
+ SKY: {
27
+ address: '0x56072C95FAA701256059aa122697B133aDEd9279',
28
+ decimals: 18,
29
+ },
30
+ MKR: {
31
+ address: '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2',
32
+ decimals: 18,
33
+ },
22
34
  AA_wstETH: {
23
35
  decimals: 18,
24
36
  address: '0x2688fc68c4eac90d9e5e1b94776cf14eade8d877',
@@ -1488,6 +1500,9 @@ export const Holders: {
1488
1500
  [network: number]: { [tokenAddress: string]: Address };
1489
1501
  } = {
1490
1502
  [Network.MAINNET]: {
1503
+ USDS: '0xE99d0ba6966c74BF78bF394BD29DCA154c6BC217',
1504
+ SKY: '0x0ddda327A6614130CCb20bc0097313A282176A01',
1505
+ MKR: '0xe9aAA7A9DDc0877626C1779AbC29993aD89A6c1f',
1491
1506
  // Idle tokens
1492
1507
  AA_wstETH: '0xd7C1b48877A7dFA7D51cf1144c89C0A3F134F935',
1493
1508
  'AA_idle_cpPOR-USDC': '0x085c8eaccA6911fE60aE3f8FbAe5F3012E3A05Ec',