@paraswap/dex-lib 3.7.7-skip-approval → 3.7.7-skip-approval.2

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 (46) hide show
  1. package/build/abi/idle-dao/idle-cdo-factory.json +38 -0
  2. package/build/abi/idle-dao/idle-cdo.json +1245 -0
  3. package/build/config.js +2 -0
  4. package/build/config.js.map +1 -1
  5. package/build/dex/aave-v3-stata/aave-v3-stata.js +1 -0
  6. package/build/dex/aave-v3-stata/aave-v3-stata.js.map +1 -1
  7. package/build/dex/idle-dao/config.d.ts +5 -0
  8. package/build/dex/idle-dao/config.js +25 -0
  9. package/build/dex/idle-dao/config.js.map +1 -0
  10. package/build/dex/idle-dao/idle-dao.d.ts +42 -0
  11. package/build/dex/idle-dao/idle-dao.js +260 -0
  12. package/build/dex/idle-dao/idle-dao.js.map +1 -0
  13. package/build/dex/idle-dao/token_list.d.ts +4 -0
  14. package/build/dex/idle-dao/token_list.js +289 -0
  15. package/build/dex/idle-dao/token_list.js.map +1 -0
  16. package/build/dex/idle-dao/tokens.d.ts +9 -0
  17. package/build/dex/idle-dao/tokens.js +68 -0
  18. package/build/dex/idle-dao/tokens.js.map +1 -0
  19. package/build/dex/idle-dao/types.d.ts +35 -0
  20. package/build/dex/idle-dao/types.js +11 -0
  21. package/build/dex/idle-dao/types.js.map +1 -0
  22. package/build/dex/idle-dao/utils.d.ts +8 -0
  23. package/build/dex/idle-dao/utils.js +149 -0
  24. package/build/dex/idle-dao/utils.js.map +1 -0
  25. package/build/dex/index.js +2 -0
  26. package/build/dex/index.js.map +1 -1
  27. package/build/generic-swap-transaction-builder.js +3 -1
  28. package/build/generic-swap-transaction-builder.js.map +1 -1
  29. package/build/types.d.ts +1 -0
  30. package/package.json +1 -1
  31. package/src/abi/idle-dao/idle-cdo-factory.json +38 -0
  32. package/src/abi/idle-dao/idle-cdo.json +1245 -0
  33. package/src/config.ts +3 -0
  34. package/src/dex/aave-v3-stata/aave-v3-stata.ts +1 -0
  35. package/src/dex/idle-dao/config.ts +26 -0
  36. package/src/dex/idle-dao/idle-dao-e2e.test.ts +112 -0
  37. package/src/dex/idle-dao/idle-dao-integration.test.ts +155 -0
  38. package/src/dex/idle-dao/idle-dao.ts +402 -0
  39. package/src/dex/idle-dao/token_list.ts +287 -0
  40. package/src/dex/idle-dao/tokens.ts +99 -0
  41. package/src/dex/idle-dao/types.ts +43 -0
  42. package/src/dex/idle-dao/utils.ts +216 -0
  43. package/src/dex/index.ts +2 -0
  44. package/src/generic-swap-transaction-builder.ts +3 -1
  45. package/src/types.ts +1 -0
  46. package/tests/constants-e2e.ts +69 -3
@@ -0,0 +1,99 @@
1
+ import { Token } from '../../types';
2
+ import { Network } from '../../constants';
3
+
4
+ import { IdleToken } from './types';
5
+ import { IDexHelper } from '../../dex-helper';
6
+ import CDO_ABI from '../../abi/idle-dao/idle-cdo.json';
7
+ import { AbiItem } from 'web3-utils';
8
+
9
+ const poolsByTokenAddress: {
10
+ [network: number]: { [address: string]: IdleToken[] };
11
+ } = {};
12
+
13
+ const TokensByAddress: { [network: number]: { [address: string]: IdleToken } } =
14
+ {};
15
+
16
+ export const getPoolsByTokenAddress = (
17
+ network: number,
18
+ address: string,
19
+ ): IdleToken[] => {
20
+ return poolsByTokenAddress[network]?.[address] || [];
21
+ };
22
+
23
+ // return null if the pair does not exists otherwise return the idleToken
24
+ export function getIdleTokenIfIdleDaoPair(
25
+ network: number,
26
+ src: Token,
27
+ dst: Token,
28
+ ): IdleToken | null {
29
+ const srcAddr = src.address.toLowerCase();
30
+ const dstAddr = dst.address.toLowerCase();
31
+
32
+ if (srcAddr === dstAddr) {
33
+ return null;
34
+ }
35
+
36
+ const _src = TokensByAddress[network][srcAddr];
37
+ const _dst = TokensByAddress[network][dstAddr];
38
+
39
+ if (_src && _src.address.toLowerCase() == dstAddr) {
40
+ return _src;
41
+ }
42
+
43
+ if (_dst && _dst.address.toLowerCase() == srcAddr) {
44
+ return _dst;
45
+ }
46
+
47
+ return null;
48
+ }
49
+
50
+ export function getTokenFromIdleToken(idleToken: IdleToken): Token {
51
+ return {
52
+ address: idleToken.idleAddress,
53
+ decimals: idleToken.idleDecimals,
54
+ symbol: idleToken.idleSymbol,
55
+ };
56
+ }
57
+
58
+ export function getIdleTokenByAddress(
59
+ network: Network,
60
+ address: string,
61
+ ): IdleToken | undefined {
62
+ return TokensByAddress[network]?.[address];
63
+ }
64
+
65
+ export function setTokensOnNetwork(
66
+ network: Network,
67
+ tokens: IdleToken[],
68
+ dexHelper: IDexHelper,
69
+ ): any {
70
+ for (let token of tokens) {
71
+ token.address = token.address.toLowerCase();
72
+ token.idleAddress = token.idleAddress.toLowerCase();
73
+
74
+ if (TokensByAddress[network] === undefined) {
75
+ TokensByAddress[network] = {};
76
+ }
77
+
78
+ if (poolsByTokenAddress[network] === undefined) {
79
+ poolsByTokenAddress[network] = {};
80
+ }
81
+
82
+ if (poolsByTokenAddress[network][token.address] === undefined) {
83
+ poolsByTokenAddress[network][token.address] = [];
84
+ }
85
+
86
+ const tokenWithContract: IdleToken = {
87
+ ...token,
88
+ cdoContract: new dexHelper.web3Provider.eth.Contract(
89
+ CDO_ABI as AbiItem[],
90
+ token.cdoAddress,
91
+ ),
92
+ };
93
+ TokensByAddress[network][token.idleAddress] = tokenWithContract;
94
+ TokensByAddress[network][token.address] = tokenWithContract;
95
+ poolsByTokenAddress[network][token.address].push(token);
96
+ }
97
+
98
+ return TokensByAddress[network];
99
+ }
@@ -0,0 +1,43 @@
1
+ import { Address } from '@paraswap/core';
2
+ import { Contract } from 'web3-eth-contract';
3
+
4
+ export type DexParams = {
5
+ lendingGasCost: number;
6
+ factoryAddress: Address;
7
+ };
8
+
9
+ export type IdleToken = {
10
+ idleDecimals: number;
11
+ idleSymbol: string;
12
+ idleAddress: string;
13
+ cdoAddress: string;
14
+ cdoContract?: Contract; // used to get virtualPrice
15
+ tokenType: 'AA' | 'BB';
16
+ blockNumber: number;
17
+ address: string;
18
+ decimals: number;
19
+ };
20
+
21
+ export type TrancheToken = {
22
+ idleAddress: IdleToken['idleAddress'];
23
+ cdoAddress: IdleToken['cdoAddress'];
24
+ tokenType: IdleToken['tokenType'];
25
+ };
26
+
27
+ export type IdleDaoData = {
28
+ idleToken: Pick<IdleToken, 'cdoAddress' | 'tokenType'>;
29
+ fromIdleToken: boolean;
30
+ };
31
+
32
+ export type Deposit = [amount: string, referral?: string];
33
+
34
+ export type Withdraw = [amount: string];
35
+
36
+ export type Param = Deposit | Withdraw;
37
+
38
+ export enum PoolFunctions {
39
+ withdrawAA = 'withdrawAA',
40
+ depositAA = 'depositAARef',
41
+ withdrawBB = 'withdrawBB',
42
+ depositBB = 'depositBBRef',
43
+ }
@@ -0,0 +1,216 @@
1
+ import { endpoints } 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
+ import { TOKEN_LISTS } from './token_list';
16
+
17
+ export const BNify = (s: any): BigNumber =>
18
+ new BigNumber(typeof s === 'object' ? s : String(s));
19
+
20
+ async function _getIdleTokenSymbols(
21
+ idleTokens: string[],
22
+ erc20Interface: Interface,
23
+ multiWrapper: MultiWrapper,
24
+ blockNumber?: number,
25
+ ): Promise<any> {
26
+ let calls: MultiCallParams<any>[] = [];
27
+
28
+ for (const idleAddress of idleTokens) {
29
+ calls.push({
30
+ target: idleAddress,
31
+ callData: erc20Interface.encodeFunctionData('symbol', []),
32
+ decodeFunction: (result: MultiResult<BytesLike> | BytesLike): any => {
33
+ return {
34
+ idleAddress,
35
+ idleSymbol: stringDecode(result),
36
+ };
37
+ },
38
+ });
39
+ }
40
+ const results = await multiWrapper.aggregate<any>(calls, blockNumber);
41
+
42
+ return results.reduce((output, item) => {
43
+ return {
44
+ ...output,
45
+ [item.idleAddress]: item.idleSymbol,
46
+ };
47
+ }, {});
48
+ }
49
+
50
+ async function _getIdleTokenDecimals(
51
+ underlyingTokens: string[],
52
+ erc20Interface: Interface,
53
+ multiWrapper: MultiWrapper,
54
+ blockNumber?: number,
55
+ ): Promise<any> {
56
+ let calls: MultiCallParams<any>[] = [];
57
+
58
+ for (const address of underlyingTokens) {
59
+ calls.push({
60
+ target: address,
61
+ callData: erc20Interface.encodeFunctionData('decimals', []),
62
+ decodeFunction: (result: MultiResult<BytesLike> | BytesLike): any => {
63
+ return {
64
+ address,
65
+ decimals: uint8ToNumber(result),
66
+ };
67
+ },
68
+ });
69
+ }
70
+ const results = await multiWrapper.aggregate<any>(calls, blockNumber);
71
+
72
+ return results.reduce((output, item) => {
73
+ return {
74
+ ...output,
75
+ [item.address]: item.decimals,
76
+ };
77
+ }, {});
78
+ }
79
+
80
+ const getDataWithAuth = async (
81
+ endpoint: string,
82
+ token: string,
83
+ error_callback?: Function,
84
+ ) => {
85
+ const config = {
86
+ headers: { Authorization: `Bearer ${token}` },
87
+ };
88
+
89
+ const data = await axios.post(endpoint, {}, config).catch(err => {
90
+ if (typeof error_callback === 'function') {
91
+ error_callback(err);
92
+ }
93
+ });
94
+ return data?.data;
95
+ };
96
+
97
+ export const fetchTokenList_api = async (
98
+ network: Network,
99
+ dexHelper: IDexHelper,
100
+ cdoInterface: Interface,
101
+ erc20Interface: Interface,
102
+ multiWrapper: MultiWrapper,
103
+ token: string,
104
+ blockNumber?: number,
105
+ ): Promise<IdleToken[]> => {
106
+ const data = await getDataWithAuth(endpoints[network], token);
107
+
108
+ // Fetch tokenslist from static file
109
+ if (!data) {
110
+ return TOKEN_LISTS[network];
111
+ }
112
+
113
+ const deployedContract = data
114
+ .filter((d: any) => !!d.cdoAddress)
115
+ .reduce((acc: any[], d: any) => {
116
+ if (acc.includes(d.cdoAddress)) return acc;
117
+ return [...acc, d.cdoAddress];
118
+ }, []);
119
+
120
+ const calls = deployedContract.reduce(
121
+ (calls: MultiCallParams<any>[], cdoAddress: string) => {
122
+ calls.push({
123
+ target: cdoAddress,
124
+ callData: cdoInterface.encodeFunctionData('AATranche', []),
125
+ decodeFunction: (
126
+ result: MultiResult<BytesLike> | BytesLike,
127
+ ): TrancheToken => {
128
+ return {
129
+ cdoAddress,
130
+ tokenType: 'AA',
131
+ idleAddress: addressDecode(result),
132
+ };
133
+ },
134
+ });
135
+
136
+ calls.push({
137
+ target: cdoAddress,
138
+ callData: cdoInterface.encodeFunctionData('BBTranche', []),
139
+ decodeFunction: (
140
+ result: MultiResult<BytesLike> | BytesLike,
141
+ ): TrancheToken => {
142
+ return {
143
+ cdoAddress,
144
+ tokenType: 'BB',
145
+ idleAddress: addressDecode(result),
146
+ };
147
+ },
148
+ });
149
+
150
+ calls.push({
151
+ target: cdoAddress,
152
+ callData: cdoInterface.encodeFunctionData('token', []),
153
+ decodeFunction: (result: MultiResult<BytesLike> | BytesLike): any => {
154
+ return {
155
+ cdoAddress,
156
+ address: addressDecode(result),
157
+ };
158
+ },
159
+ });
160
+
161
+ return calls;
162
+ },
163
+ [],
164
+ );
165
+
166
+ const results = await multiWrapper.aggregate<Record<string, string>>(
167
+ calls,
168
+ blockNumber,
169
+ );
170
+
171
+ const cdosUnderlying: Record<string, string> = results.reduce(
172
+ (cdosUnderlying, result: any) => {
173
+ if (!result.address) return cdosUnderlying;
174
+ return {
175
+ ...cdosUnderlying,
176
+ [result.cdoAddress]: result.address,
177
+ };
178
+ },
179
+ {},
180
+ );
181
+
182
+ const idleTokenSymbolsList = await _getIdleTokenSymbols(
183
+ results
184
+ .filter(result => !!result.tokenType)
185
+ .map(result => result.idleAddress),
186
+ erc20Interface,
187
+ multiWrapper,
188
+ blockNumber,
189
+ );
190
+
191
+ const idleTokenDecimals = await _getIdleTokenDecimals(
192
+ results.filter(result => !result.tokenType).map(result => result.address),
193
+ erc20Interface,
194
+ multiWrapper,
195
+ blockNumber,
196
+ );
197
+
198
+ const output: IdleToken[] = [];
199
+ for (const result of results) {
200
+ if (result.tokenType) {
201
+ const idleToken: IdleToken = {
202
+ blockNumber: 0,
203
+ idleDecimals: 18,
204
+ cdoAddress: result.cdoAddress,
205
+ idleAddress: result.idleAddress,
206
+ address: cdosUnderlying[result.cdoAddress],
207
+ idleSymbol: idleTokenSymbolsList[result.idleAddress],
208
+ tokenType: result.tokenType as IdleToken['tokenType'],
209
+ decimals: idleTokenDecimals[cdosUnderlying[result.cdoAddress]],
210
+ };
211
+ output.push(idleToken);
212
+ }
213
+ }
214
+
215
+ return output;
216
+ };
package/src/dex/index.ts CHANGED
@@ -25,6 +25,7 @@ import { Onebit } from './onebit/onebit';
25
25
  import { Compound } from './compound/compound';
26
26
  import { AaveV2 } from './aave-v2/aave-v2';
27
27
  import { AaveV3 } from './aave-v3/aave-v3';
28
+ import { IdleDao } from './idle-dao/idle-dao';
28
29
  import { OneInchLp } from './OneInchLp';
29
30
  import { DodoV1 } from './dodo-v1/dodo-v1';
30
31
  import { DodoV2 } from './dodo-v2';
@@ -130,6 +131,7 @@ const Dexes = [
130
131
  Excalibur,
131
132
  AaveV2,
132
133
  AaveV3,
134
+ IdleDao,
133
135
  KyberDmm,
134
136
  Weth,
135
137
  PolygonMigrator,
@@ -716,7 +716,9 @@ export class GenericSwapTransactionBuilder {
716
716
  ];
717
717
 
718
718
  approvals.forEach((alreadyApproved, index) => {
719
- if (!alreadyApproved && !skipApproval) {
719
+ // TODO: uncomment after testing
720
+ // if (!alreadyApproved && !skipApproval) {
721
+ if (!skipApproval) {
720
722
  const [token, target] = tokenTargetMapping[index].params;
721
723
  const exchangeParamIndex = tokenTargetMapping[index].exchangeParamIndex;
722
724
  const curExchangeParam = dexExchangeParams[exchangeParamIndex];
package/src/types.ts CHANGED
@@ -304,6 +304,7 @@ export type Config = {
304
304
  uniswapV3EventLoggingSampleRate?: number;
305
305
  swaapV2AuthToken?: string;
306
306
  dexalotAuthToken?: string;
307
+ idleDaoAuthToken?: string;
307
308
  forceRpcFallbackDexs: string[];
308
309
  apiKeyTheGraph: string;
309
310
  };
@@ -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,
@@ -1416,8 +1468,22 @@ export const Holders: {
1416
1468
  [network: number]: { [tokenAddress: string]: Address };
1417
1469
  } = {
1418
1470
  [Network.MAINNET]: {
1419
- ETH: '0x0a4c79cE84202b03e95B7a692E5D728d83C44c76',
1420
- USDC: '0x7713974908Be4BEd47172370115e8b1219F4A5f0',
1471
+ // Idle tokens
1472
+ AA_wstETH: '0xd7C1b48877A7dFA7D51cf1144c89C0A3F134F935',
1473
+ 'AA_idle_cpPOR-USDC': '0x085c8eaccA6911fE60aE3f8FbAe5F3012E3A05Ec',
1474
+ 'BB_idle_cpFAS-USDT': '0xFDAD59EF0686C3Da702b7D651a3bD35a539c8Bc4',
1475
+ AA_steakUSDC: '0x28C1eCF5B0f16E1D85B9D2677EfB79d68167cAf2',
1476
+ BB_steakUSDC: '0x442Aea0Fd2AFbd3391DAE768F7046f132F0a6300',
1477
+ AA_Re7WETH: '0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb',
1478
+ BB_Re7WETH: '0x442Aea0Fd2AFbd3391DAE768F7046f132F0a6300',
1479
+ BB_dUSDCV3: '0xFb3bD022D5DAcF95eE28a6B07825D4Ff9C5b3814',
1480
+ AA_sUSDe: '0xaFeb95DEF3B2A3D532D74DaBd51E62048d6c07A4',
1481
+ BB_sUSDe: '0xaFeb95DEF3B2A3D532D74DaBd51E62048d6c07A4',
1482
+ AA_iETHv2: '0xA118aD79E2152b9a3c7Df8B8791887762b0f1D49',
1483
+ BB_iETHv2: '0x15079cBAa74C1df2a602fAc88Bd5b98B08FfE6A4',
1484
+ ETH: '0x176F3DAb24a159341c0509bB36B833E7fdd0a132',
1485
+ USDC: '0x7713974908be4bed47172370115e8b1219f4a5f0',
1486
+ USDE: '0x8707f238936c12c309bfc2B9959C35828AcFc512',
1421
1487
  AMPL: '0x223592a191ECfC7FDC38a9256c3BD96E771539A9',
1422
1488
  WBTC: '0x6daB3bCbFb336b29d06B9C793AEF7eaA57888922',
1423
1489
  tBTCv2: '0x84eA3907b9206427F45c7b2614925a2B86D12611',
@@ -1426,7 +1492,7 @@ export const Holders: {
1426
1492
  aEthUSDC: '0x42EFD1E0DB4ADa762cc5092ECBD052dE7c6e72E2',
1427
1493
  MAV: '0x92582aa69BB6117903a01eDdfe6EFfDDe564A69f',
1428
1494
  BADGER: '0x34e2741a3f8483dbe5231f61c005110ff4b9f50a',
1429
- STETH: '0x50b42514389F25E1f471C8F03f6f5954df0204b0',
1495
+ STETH: '0x6663613FbD927cE78abBF7F5Ca7e2c3FE0d96d18',
1430
1496
  SUSHI: '0x8a108e4761386c94b8d2f98A5fFe13E472cFE76a',
1431
1497
  wstETH: '0x5fEC2f34D80ED82370F733043B6A536d7e9D7f8d',
1432
1498
  WETH: '0x6B44ba0a126a2A1a8aa6cD1AdeeD002e141Bcd44',