@paraswap/dex-lib 3.3.0-v6-only → 3.3.1-idle

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 (57) hide show
  1. package/build/abi/angle-transmuter/TransmuterSidechain.json +1798 -0
  2. package/build/config.js +2 -0
  3. package/build/config.js.map +1 -1
  4. package/build/dex/angle-staked-stable/angle-staked-stable.d.ts +2 -1
  5. package/build/dex/angle-staked-stable/angle-staked-stable.js +15 -37
  6. package/build/dex/angle-staked-stable/angle-staked-stable.js.map +1 -1
  7. package/build/dex/angle-transmuter/angle-transmuter-pool.d.ts +1 -1
  8. package/build/dex/angle-transmuter/angle-transmuter-pool.js +19 -10
  9. package/build/dex/angle-transmuter/angle-transmuter-pool.js.map +1 -1
  10. package/build/dex/angle-transmuter/angle-transmuter.d.ts +3 -2
  11. package/build/dex/angle-transmuter/angle-transmuter.js +23 -4
  12. package/build/dex/angle-transmuter/angle-transmuter.js.map +1 -1
  13. package/build/dex/angle-transmuter/config.js +20 -0
  14. package/build/dex/angle-transmuter/config.js.map +1 -1
  15. package/build/dex/angle-transmuter/constants.d.ts +5 -72
  16. package/build/dex/angle-transmuter/constants.js +44 -1
  17. package/build/dex/angle-transmuter/constants.js.map +1 -1
  18. package/build/dex/angle-transmuter/morphoVault.d.ts +1 -0
  19. package/build/dex/angle-transmuter/morphoVault.js +6 -0
  20. package/build/dex/angle-transmuter/morphoVault.js.map +1 -1
  21. package/build/dex/angle-transmuter/transmuter.d.ts +5 -2
  22. package/build/dex/angle-transmuter/transmuter.js +61 -23
  23. package/build/dex/angle-transmuter/transmuter.js.map +1 -1
  24. package/build/dex/angle-transmuter/types.d.ts +3 -2
  25. package/build/dex/angle-transmuter/types.js.map +1 -1
  26. package/build/dex/angle-transmuter/utils.d.ts +2 -2
  27. package/build/dex/angle-transmuter/utils.js +9 -4
  28. package/build/dex/angle-transmuter/utils.js.map +1 -1
  29. package/build/dex/idle-dao/config.d.ts +2 -1
  30. package/build/dex/idle-dao/config.js +543 -1
  31. package/build/dex/idle-dao/config.js.map +1 -1
  32. package/build/dex/idle-dao/idle-dao.d.ts +3 -3
  33. package/build/dex/idle-dao/idle-dao.js +18 -8
  34. package/build/dex/idle-dao/idle-dao.js.map +1 -1
  35. package/build/dex/idle-dao/utils.js +5 -3
  36. package/build/dex/idle-dao/utils.js.map +1 -1
  37. package/build/dex/index.js +2 -0
  38. package/build/dex/index.js.map +1 -1
  39. package/build/types.d.ts +1 -0
  40. package/package.json +1 -1
  41. package/src/abi/idle-dao/idle-cdo-factory.json +38 -0
  42. package/src/abi/idle-dao/idle-cdo.json +1245 -0
  43. package/src/config.ts +3 -0
  44. package/src/dex/angle-staked-stable/angle-staked-stable.ts +36 -37
  45. package/src/dex/idle-dao/config.ts +574 -0
  46. package/src/dex/idle-dao/idle-dao-e2e.test.ts +113 -0
  47. package/src/dex/idle-dao/idle-dao-events.test.ts +133 -0
  48. package/src/dex/idle-dao/idle-dao-integration.test.ts +166 -0
  49. package/src/dex/idle-dao/idle-dao-pool.ts +304 -0
  50. package/src/dex/idle-dao/idle-dao-pooling-pool.ts +87 -0
  51. package/src/dex/idle-dao/idle-dao.ts +508 -0
  52. package/src/dex/idle-dao/tokens.ts +117 -0
  53. package/src/dex/idle-dao/types.ts +48 -0
  54. package/src/dex/idle-dao/utils.ts +216 -0
  55. package/src/dex/index.ts +2 -0
  56. package/src/types.ts +1 -0
  57. package/tests/constants-e2e.ts +70 -4
@@ -0,0 +1,48 @@
1
+ import { Address } from '@paraswap/core';
2
+ import BigNumber from 'bignumber.js';
3
+
4
+ export type PoolState = {
5
+ tokenPrice: BigInt;
6
+ };
7
+
8
+ export type PoolsState = Record<string, PoolState>;
9
+
10
+ export type DexParams = {
11
+ fromBlock: number;
12
+ lendingGasCost: number;
13
+ factoryAddress: Address;
14
+ };
15
+
16
+ export type IdleToken = {
17
+ idleSymbol: string;
18
+ idleAddress: string;
19
+ cdoAddress: string;
20
+ tokenType: 'AA' | 'BB';
21
+ blockNumber: number;
22
+ address: string;
23
+ decimals: number;
24
+ };
25
+
26
+ export type TrancheToken = {
27
+ idleAddress: IdleToken['idleAddress'];
28
+ cdoAddress: IdleToken['cdoAddress'];
29
+ tokenType: IdleToken['tokenType'];
30
+ };
31
+
32
+ export type IdleDaoData = {
33
+ idleToken: IdleToken;
34
+ fromIdleToken: boolean;
35
+ };
36
+
37
+ export type Deposit = [amount: string, referral?: string];
38
+
39
+ export type Withdraw = [amount: string];
40
+
41
+ export type Param = Deposit | Withdraw;
42
+
43
+ export enum PoolFunctions {
44
+ withdrawAA = 'withdrawAA',
45
+ depositAA = 'depositAARef',
46
+ withdrawBB = 'withdrawBB',
47
+ depositBB = 'depositBBRef',
48
+ }
@@ -0,0 +1,216 @@
1
+ import { endpoints, TOKEN_LISTS } from './config';
2
+ import { BytesLike } from 'ethers';
3
+ import BigNumber from 'bignumber.js';
4
+ import { Interface } from '@ethersproject/abi';
5
+ import { stringDecode, addressDecode, uint8ToNumber } from '../../lib/decoders';
6
+ import {
7
+ MultiCallParams,
8
+ MultiResult,
9
+ MultiWrapper,
10
+ } from '../../lib/multi-wrapper';
11
+ import { IdleToken, TrancheToken } from './types';
12
+ import axios from 'axios';
13
+ import { Network } from '../../constants';
14
+ import { IDexHelper } from '../../dex-helper';
15
+
16
+ export const BNify = (s: any): BigNumber =>
17
+ new BigNumber(typeof s === 'object' ? s : String(s));
18
+
19
+ async function _getIdleTokenSymbols(
20
+ blockNumber: number,
21
+ idleTokens: string[],
22
+ erc20Interface: Interface,
23
+ multiWrapper: MultiWrapper,
24
+ ): Promise<any> {
25
+ let calls: MultiCallParams<any>[] = [];
26
+
27
+ for (const idleAddress of idleTokens) {
28
+ calls.push({
29
+ target: idleAddress,
30
+ callData: erc20Interface.encodeFunctionData('symbol', []),
31
+ decodeFunction: (result: MultiResult<BytesLike> | BytesLike): any => {
32
+ return {
33
+ idleAddress,
34
+ idleSymbol: stringDecode(result),
35
+ };
36
+ },
37
+ });
38
+ }
39
+ const results = await multiWrapper.aggregate<any>(calls, blockNumber);
40
+
41
+ return results.reduce((output, item) => {
42
+ return {
43
+ ...output,
44
+ [item.idleAddress]: item.idleSymbol,
45
+ };
46
+ }, {});
47
+ }
48
+
49
+ async function _getIdleTokenDecimals(
50
+ blockNumber: number,
51
+ underlyingTokens: string[],
52
+ erc20Interface: Interface,
53
+ multiWrapper: MultiWrapper,
54
+ ): Promise<any> {
55
+ let calls: MultiCallParams<any>[] = [];
56
+
57
+ for (const address of underlyingTokens) {
58
+ calls.push({
59
+ target: address,
60
+ callData: erc20Interface.encodeFunctionData('decimals', []),
61
+ decodeFunction: (result: MultiResult<BytesLike> | BytesLike): any => {
62
+ return {
63
+ address,
64
+ decimals: uint8ToNumber(result),
65
+ };
66
+ },
67
+ });
68
+ }
69
+ const results = await multiWrapper.aggregate<any>(calls, blockNumber);
70
+
71
+ return results.reduce((output, item) => {
72
+ return {
73
+ ...output,
74
+ [item.address]: item.decimals,
75
+ };
76
+ }, {});
77
+ }
78
+
79
+ const getDataWithAuth = async (
80
+ endpoint: string,
81
+ token: string,
82
+ error_callback?: Function,
83
+ ) => {
84
+ const config = {
85
+ headers: { Authorization: `Bearer ${token}` },
86
+ };
87
+
88
+ const data = await axios.post(endpoint, {}, config).catch(err => {
89
+ if (typeof error_callback === 'function') {
90
+ error_callback(err);
91
+ }
92
+ });
93
+ return data?.data;
94
+ };
95
+
96
+ export const fetchTokenList_api = async (
97
+ network: Network,
98
+ dexHelper: IDexHelper,
99
+ blockNumber: number,
100
+ cdoInterface: Interface,
101
+ erc20Interface: Interface,
102
+ multiWrapper: MultiWrapper,
103
+ token: string,
104
+ ): Promise<IdleToken[]> => {
105
+ // const AUTH_TOKEN_DECODED = atob(idleDaoAuthToken!);
106
+ const data = await getDataWithAuth(endpoints[network], token);
107
+ // console.log('api_response_data', data);
108
+
109
+ // Fetch tokenslist from static file
110
+ if (!data) {
111
+ return TOKEN_LISTS;
112
+ }
113
+
114
+ const deployedContract = data
115
+ .filter((d: any) => !!d.cdoAddress)
116
+ .map((d: any) => d.cdoAddress);
117
+
118
+ const calls = deployedContract.reduce(
119
+ (calls: MultiCallParams<any>[], cdoAddress: string) => {
120
+ calls.push({
121
+ target: cdoAddress,
122
+ callData: cdoInterface.encodeFunctionData('AATranche', []),
123
+ decodeFunction: (
124
+ result: MultiResult<BytesLike> | BytesLike,
125
+ ): TrancheToken => {
126
+ return {
127
+ cdoAddress,
128
+ tokenType: 'AA',
129
+ idleAddress: addressDecode(result),
130
+ };
131
+ },
132
+ });
133
+
134
+ calls.push({
135
+ target: cdoAddress,
136
+ callData: cdoInterface.encodeFunctionData('BBTranche', []),
137
+ decodeFunction: (
138
+ result: MultiResult<BytesLike> | BytesLike,
139
+ ): TrancheToken => {
140
+ return {
141
+ cdoAddress,
142
+ tokenType: 'BB',
143
+ idleAddress: addressDecode(result),
144
+ };
145
+ },
146
+ });
147
+
148
+ calls.push({
149
+ target: cdoAddress,
150
+ callData: cdoInterface.encodeFunctionData('token', []),
151
+ decodeFunction: (result: MultiResult<BytesLike> | BytesLike): any => {
152
+ return {
153
+ cdoAddress,
154
+ address: addressDecode(result),
155
+ };
156
+ },
157
+ });
158
+
159
+ return calls;
160
+ },
161
+ [],
162
+ );
163
+
164
+ const results = await multiWrapper.aggregate<Record<string, string>>(
165
+ calls,
166
+ blockNumber,
167
+ );
168
+
169
+ const cdosUnderlying: Record<string, string> = results.reduce(
170
+ (cdosUnderlying, result: any) => {
171
+ if (!result.address) return cdosUnderlying;
172
+ return {
173
+ ...cdosUnderlying,
174
+ [result.cdoAddress]: result.address,
175
+ };
176
+ },
177
+ {},
178
+ );
179
+
180
+ const idleTokenSymbolsList = await _getIdleTokenSymbols(
181
+ blockNumber,
182
+ results
183
+ .filter(result => !!result.tokenType)
184
+ .map(result => result.idleAddress),
185
+ erc20Interface,
186
+ multiWrapper,
187
+ );
188
+
189
+ const idleTokenDecimals = await _getIdleTokenDecimals(
190
+ blockNumber,
191
+ results.filter(result => !result.tokenType).map(result => result.address),
192
+ erc20Interface,
193
+ multiWrapper,
194
+ );
195
+
196
+ // console.log('idleTokenDecimals', idleTokenDecimals)
197
+ // console.log('cdosUnderlying', cdosUnderlying)
198
+
199
+ const output: IdleToken[] = [];
200
+ for (const result of results) {
201
+ if (result.tokenType) {
202
+ const idleToken: IdleToken = {
203
+ decimals: 18,
204
+ blockNumber: 0,
205
+ cdoAddress: result.cdoAddress,
206
+ idleAddress: result.idleAddress,
207
+ address: cdosUnderlying[result.cdoAddress],
208
+ idleSymbol: idleTokenSymbolsList[result.idleAddress],
209
+ tokenType: result.tokenType as IdleToken['tokenType'],
210
+ };
211
+ output.push(idleToken);
212
+ }
213
+ }
214
+
215
+ return output;
216
+ };
package/src/dex/index.ts CHANGED
@@ -26,6 +26,7 @@ import { Compound } from './compound/compound';
26
26
  import { AaveV1 } from './aave-v1/aave-v1';
27
27
  import { AaveV2 } from './aave-v2/aave-v2';
28
28
  import { AaveV3 } from './aave-v3/aave-v3';
29
+ import { IdleDao } from './idle-dao/idle-dao';
29
30
  import { OneInchLp } from './OneInchLp';
30
31
  import { DodoV1 } from './dodo-v1/dodo-v1';
31
32
  import { DodoV2 } from './dodo-v2';
@@ -135,6 +136,7 @@ const Dexes = [
135
136
  AaveV1,
136
137
  AaveV2,
137
138
  AaveV3,
139
+ IdleDao,
138
140
  KyberDmm,
139
141
  Weth,
140
142
  PolygonMigrator,
package/src/types.ts CHANGED
@@ -302,6 +302,7 @@ export type Config = {
302
302
  uniswapV3EventLoggingSampleRate?: number;
303
303
  swaapV2AuthToken?: string;
304
304
  dexalotAuthToken?: string;
305
+ idleDaoAuthToken?: string;
305
306
  smardexSubgraphAuthToken?: string;
306
307
  forceRpcFallbackDexs: string[];
307
308
  };
@@ -19,6 +19,58 @@ export const Tokens: {
19
19
  [network: number]: { [symbol: string]: SmartTokenParams };
20
20
  } = {
21
21
  [Network.MAINNET]: {
22
+ AA_wstETH: {
23
+ decimals: 18,
24
+ address: '0x2688fc68c4eac90d9e5e1b94776cf14eade8d877',
25
+ },
26
+ 'AA_idle_cpPOR-USDC': {
27
+ decimals: 18,
28
+ address: '0x9cacd44cfdf22731bc99facf3531c809d56bd4a2',
29
+ },
30
+ 'BB_idle_cpFAS-USDT': {
31
+ decimals: 18,
32
+ address: '0x3eb6318b8d9f362a0e1d99f6032edb1c4c602500',
33
+ },
34
+ AA_steakUSDC: {
35
+ decimals: 18,
36
+ address: '0x2b0e31b8ee653d2077db86dea3acf3f34ae9d5d2',
37
+ },
38
+ BB_steakUSDC: {
39
+ decimals: 18,
40
+ address: '0x7b713b1cb6eafd4061064581579ffccf7df21545',
41
+ },
42
+ AA_Re7WETH: {
43
+ decimals: 18,
44
+ address: '0x454bb3cb427b21e1c052a080e21a57753cd6969e',
45
+ },
46
+ BB_Re7WETH: {
47
+ decimals: 18,
48
+ address: '0x20aa3cd83044d2903181f7ef5c2b498a017d1c4a',
49
+ },
50
+ BB_dUSDCV3: {
51
+ decimals: 18,
52
+ address: '0x2a84a042db06222c486bcb815e961f26599d0df6',
53
+ },
54
+ AA_sUSDe: {
55
+ decimals: 18,
56
+ address: '0xf3188697bd35df73e4293d04a07ebaaf1ffc4018',
57
+ },
58
+ BB_sUSDe: {
59
+ decimals: 18,
60
+ address: '0xb8d0be502a8f12cc5213733285b430a43d07349d',
61
+ },
62
+ AA_iETHv2: {
63
+ decimals: 18,
64
+ address: '0xdf17c739b666B259DA3416d01f0310a6e429f592',
65
+ },
66
+ BB_iETHv2: {
67
+ decimals: 18,
68
+ address: '0x990b3aF34dDB502715E1070CE6778d8eB3c8Ea82',
69
+ },
70
+ USDE: {
71
+ address: '0x4c9edd5852cd905f086c759e8383e09bff1e68b3',
72
+ decimals: 18,
73
+ },
22
74
  ETH: {
23
75
  address: ETHER_ADDRESS,
24
76
  decimals: 18,
@@ -1296,8 +1348,22 @@ export const Holders: {
1296
1348
  [network: number]: { [tokenAddress: string]: Address };
1297
1349
  } = {
1298
1350
  [Network.MAINNET]: {
1299
- ETH: '0x0a4c79cE84202b03e95B7a692E5D728d83C44c76',
1300
- USDC: '0x7713974908Be4BEd47172370115e8b1219F4A5f0',
1351
+ // Idle tokens
1352
+ AA_wstETH: '0xd7C1b48877A7dFA7D51cf1144c89C0A3F134F935',
1353
+ 'AA_idle_cpPOR-USDC': '0x085c8eaccA6911fE60aE3f8FbAe5F3012E3A05Ec',
1354
+ 'BB_idle_cpFAS-USDT': '0xFDAD59EF0686C3Da702b7D651a3bD35a539c8Bc4',
1355
+ AA_steakUSDC: '0x28C1eCF5B0f16E1D85B9D2677EfB79d68167cAf2',
1356
+ BB_steakUSDC: '0x442Aea0Fd2AFbd3391DAE768F7046f132F0a6300',
1357
+ AA_Re7WETH: '0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb',
1358
+ BB_Re7WETH: '0x442Aea0Fd2AFbd3391DAE768F7046f132F0a6300',
1359
+ BB_dUSDCV3: '0xFb3bD022D5DAcF95eE28a6B07825D4Ff9C5b3814',
1360
+ AA_sUSDe: '0xaFeb95DEF3B2A3D532D74DaBd51E62048d6c07A4',
1361
+ BB_sUSDe: '0xaFeb95DEF3B2A3D532D74DaBd51E62048d6c07A4',
1362
+ AA_iETHv2: '0xA118aD79E2152b9a3c7Df8B8791887762b0f1D49',
1363
+ BB_iETHv2: '0x15079cBAa74C1df2a602fAc88Bd5b98B08FfE6A4',
1364
+ ETH: '0x176F3DAb24a159341c0509bB36B833E7fdd0a132',
1365
+ USDC: '0x7713974908be4bed47172370115e8b1219f4a5f0',
1366
+ USDE: '0x8707f238936c12c309bfc2B9959C35828AcFc512',
1301
1367
  AMPL: '0x223592a191ECfC7FDC38a9256c3BD96E771539A9',
1302
1368
  WBTC: '0x6daB3bCbFb336b29d06B9C793AEF7eaA57888922',
1303
1369
  tBTCv2: '0x84eA3907b9206427F45c7b2614925a2B86D12611',
@@ -1306,9 +1372,9 @@ export const Holders: {
1306
1372
  aEthUSDC: '0x42EFD1E0DB4ADa762cc5092ECBD052dE7c6e72E2',
1307
1373
  MAV: '0x92582aa69BB6117903a01eDdfe6EFfDDe564A69f',
1308
1374
  BADGER: '0x34e2741a3f8483dbe5231f61c005110ff4b9f50a',
1309
- STETH: '0x50b42514389F25E1f471C8F03f6f5954df0204b0',
1375
+ STETH: '0x6663613FbD927cE78abBF7F5Ca7e2c3FE0d96d18',
1376
+ wstETH: '0x6cE0F913F035ec6195bC3cE885aec4C66E485BC4',
1310
1377
  SUSHI: '0x8a108e4761386c94b8d2f98A5fFe13E472cFE76a',
1311
- wstETH: '0x5fEC2f34D80ED82370F733043B6A536d7e9D7f8d',
1312
1378
  WETH: '0x2fEb1512183545f48f6b9C5b4EbfCaF49CfCa6F3',
1313
1379
  USDT: '0xAf64555DDD61FcF7D094824dd9B4eBea165aFc5b',
1314
1380
  XAUT: '0xc4e161e8d8a4bc4ac762ab33a28bbac5474203d7',