@paraswap/dex-lib 3.8.33-pt-fix → 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.
@@ -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',