@defisaver/positions-sdk 2.1.79 → 2.1.82

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 (75) hide show
  1. package/cjs/aaveV4/index.d.ts +7 -0
  2. package/cjs/aaveV4/index.js +243 -0
  3. package/cjs/aaveV4/lend.d.ts +55 -0
  4. package/cjs/aaveV4/lend.js +131 -0
  5. package/cjs/config/contracts.d.ts +1551 -0
  6. package/cjs/config/contracts.js +9 -0
  7. package/cjs/contracts.d.ts +32741 -0
  8. package/cjs/contracts.js +2 -1
  9. package/cjs/eulerV2/index.d.ts +1 -2
  10. package/cjs/eulerV2/index.js +4 -5
  11. package/cjs/helpers/aaveV4Helpers/index.d.ts +25 -0
  12. package/cjs/helpers/aaveV4Helpers/index.js +233 -0
  13. package/cjs/helpers/index.d.ts +1 -0
  14. package/cjs/helpers/index.js +2 -1
  15. package/cjs/index.d.ts +2 -1
  16. package/cjs/index.js +3 -1
  17. package/cjs/markets/aaveV4/index.d.ts +34 -0
  18. package/cjs/markets/aaveV4/index.js +182 -0
  19. package/cjs/markets/index.d.ts +1 -0
  20. package/cjs/markets/index.js +3 -1
  21. package/cjs/moneymarket/moneymarketCommonService.js +1 -1
  22. package/cjs/portfolio/index.js +20 -0
  23. package/cjs/services/utils.d.ts +1 -1
  24. package/cjs/services/utils.js +3 -3
  25. package/cjs/types/aaveV4.d.ts +159 -0
  26. package/cjs/types/aaveV4.js +22 -0
  27. package/cjs/types/index.d.ts +1 -0
  28. package/cjs/types/index.js +1 -0
  29. package/cjs/types/portfolio.d.ts +4 -0
  30. package/esm/aaveV4/index.d.ts +7 -0
  31. package/esm/aaveV4/index.js +200 -0
  32. package/esm/aaveV4/lend.d.ts +55 -0
  33. package/esm/aaveV4/lend.js +124 -0
  34. package/esm/config/contracts.d.ts +1551 -0
  35. package/esm/config/contracts.js +8 -0
  36. package/esm/contracts.d.ts +32741 -0
  37. package/esm/contracts.js +1 -0
  38. package/esm/eulerV2/index.d.ts +1 -2
  39. package/esm/eulerV2/index.js +5 -6
  40. package/esm/helpers/aaveV4Helpers/index.d.ts +25 -0
  41. package/esm/helpers/aaveV4Helpers/index.js +221 -0
  42. package/esm/helpers/index.d.ts +1 -0
  43. package/esm/helpers/index.js +1 -0
  44. package/esm/index.d.ts +2 -1
  45. package/esm/index.js +2 -1
  46. package/esm/markets/aaveV4/index.d.ts +34 -0
  47. package/esm/markets/aaveV4/index.js +161 -0
  48. package/esm/markets/index.d.ts +1 -0
  49. package/esm/markets/index.js +1 -0
  50. package/esm/moneymarket/moneymarketCommonService.js +1 -1
  51. package/esm/portfolio/index.js +21 -1
  52. package/esm/services/utils.d.ts +1 -1
  53. package/esm/services/utils.js +1 -1
  54. package/esm/types/aaveV4.d.ts +159 -0
  55. package/esm/types/aaveV4.js +19 -0
  56. package/esm/types/index.d.ts +1 -0
  57. package/esm/types/index.js +1 -0
  58. package/esm/types/portfolio.d.ts +4 -0
  59. package/package.json +2 -2
  60. package/src/aaveV4/index.ts +221 -0
  61. package/src/aaveV4/lend.ts +185 -0
  62. package/src/config/contracts.ts +8 -0
  63. package/src/contracts.ts +2 -0
  64. package/src/eulerV2/index.ts +12 -7
  65. package/src/helpers/aaveV4Helpers/index.ts +291 -0
  66. package/src/helpers/index.ts +1 -0
  67. package/src/index.ts +2 -0
  68. package/src/markets/aaveV4/index.ts +191 -0
  69. package/src/markets/index.ts +6 -1
  70. package/src/moneymarket/moneymarketCommonService.ts +1 -1
  71. package/src/portfolio/index.ts +20 -0
  72. package/src/services/utils.ts +1 -1
  73. package/src/types/aaveV4.ts +175 -0
  74. package/src/types/index.ts +2 -1
  75. package/src/types/portfolio.ts +4 -0
@@ -0,0 +1,124 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
11
+ import { AaveV4ViewContractViem } from '../contracts';
12
+ import { getViemProvider } from '../services/viem';
13
+ import { wethToEth } from '../services/utils';
14
+ import { NetworkNumber, } from '../types/common';
15
+ export const AAVE_V4_TOKENIZED_SPOKES = {
16
+ EURC_CORE: '0x6D9e2Cdd61CaF69af99b275704B6e272C41c6718',
17
+ GHO_CORE: '0x58C14a5E061c9bC6926c5b853445290F296C2F7B',
18
+ RLUSD_CORE: '0xC8a125AE4275a78AADc53B46Ca10566Bc9B249E0',
19
+ USDC_CORE: '0x531E90a2376902DE8915789Fcc1075e3B0c153E7',
20
+ USDG_CORE: '0xAC2435E3C25e8246870D33ce0a26988A46d5DB68',
21
+ USDT_CORE: '0x5eC44a70F309854fe04d495cFE1B5dA63DD1cc73',
22
+ WBTC_CORE: '0x82A9CC4656784E55Ef2E78F704028B5E1Bfc1732',
23
+ WETH_CORE: '0x7320CF22Ac095bA2a2e0a652F77efB836c2E751b',
24
+ cbBTC_CORE: '0x33B41B74366F55327d959FfF6D6b6fBc2853dbB1',
25
+ frxUSD_CORE: '0x2226749630775ee20230Ad65214fB339087eF30D',
26
+ GHO_PLUS: '0xA54382db40EC602c0a173A08f9E86Ed40F9D4D10',
27
+ USDC_PLUS: '0xc94bdd83D2c7655C280655D60954e79E88D4F949',
28
+ USDT_PLUS: '0x80835EB50694EE0e519743f67e5401e6FD300006',
29
+ USDe_PLUS: '0x502Cd81da6a8F1785eb2eEE72713B7388E16A854',
30
+ GHO_PRIME: '0x900fD46d565d1ac8995928c0179052ec02a6D0E1',
31
+ USDC_PRIME: '0x486415fb1F8b062c89ED548f871cf64304AACb31',
32
+ USDT_PRIME: '0x46c588DD8453aC259c1f6a54b4C9A93C2aC3762D',
33
+ };
34
+ export const AAVE_V4_TOKENIZED_SPOKE_ADDRESSES = {
35
+ [NetworkNumber.Eth]: Object.values(AAVE_V4_TOKENIZED_SPOKES),
36
+ };
37
+ export const aaveV4GetTokenizedHubKey = (hubNameOrKey) => {
38
+ if (!hubNameOrKey)
39
+ return null;
40
+ const normalized = hubNameOrKey.trim().toUpperCase();
41
+ if (normalized === 'CORE' || normalized === 'CORE HUB')
42
+ return 'CORE';
43
+ if (normalized === 'PLUS' || normalized === 'PLUS HUB')
44
+ return 'PLUS';
45
+ if (normalized === 'PRIME' || normalized === 'PRIME HUB')
46
+ return 'PRIME';
47
+ if (normalized.includes('CORE'))
48
+ return 'CORE';
49
+ if (normalized.includes('PLUS'))
50
+ return 'PLUS';
51
+ if (normalized.includes('PRIME'))
52
+ return 'PRIME';
53
+ return null;
54
+ };
55
+ export const aaveV4GetTokenizedVaultKey = (symbol, hubNameOrKey) => {
56
+ if (!symbol)
57
+ return null;
58
+ const hubKey = aaveV4GetTokenizedHubKey(hubNameOrKey);
59
+ if (!hubKey)
60
+ return null;
61
+ const normalizedSymbol = symbol.trim().replace(/-/g, '_');
62
+ return `${normalizedSymbol}_${hubKey}`;
63
+ };
64
+ export const aaveV4GetTokenizedVaultAddress = (network, symbol, hubNameOrKey) => {
65
+ if (network !== NetworkNumber.Eth)
66
+ return undefined;
67
+ const key = aaveV4GetTokenizedVaultKey(symbol, hubNameOrKey);
68
+ if (!key)
69
+ return undefined;
70
+ return AAVE_V4_TOKENIZED_SPOKES[key];
71
+ };
72
+ const AAVE_V4_TOKENIZED_SPOKE_ADDRESS_TO_KEY = Object.entries(AAVE_V4_TOKENIZED_SPOKES).reduce((acc, [k, v]) => {
73
+ acc[v.toLowerCase()] = k;
74
+ return acc;
75
+ }, {});
76
+ /**
77
+ * Fetches tokenization vault data for the given user via getTokenizationSpokesData.
78
+ * Returns parsed data including userSuppliedAssets in human-readable form for each vault.
79
+ */
80
+ export function getAaveV4TokenizationSpokesData(provider, network, userAddress) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ var _a;
83
+ const spokes = (_a = AAVE_V4_TOKENIZED_SPOKE_ADDRESSES[network]) !== null && _a !== void 0 ? _a : [];
84
+ if (spokes.length === 0)
85
+ return [];
86
+ const client = getViemProvider(provider, network);
87
+ const viewContract = AaveV4ViewContractViem(client, network);
88
+ const raw = yield viewContract.read.getTokenizationSpokesData([spokes, userAddress]);
89
+ return raw.map((r, i) => {
90
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
91
+ const vaultAddress = spokes[i];
92
+ const key = (_a = AAVE_V4_TOKENIZED_SPOKE_ADDRESS_TO_KEY[vaultAddress.toLowerCase()]) !== null && _a !== void 0 ? _a : null;
93
+ const symbol = wethToEth(getAssetInfoByAddress(r.underlyingAsset, network).symbol);
94
+ if (symbol === '?') { // unsupported asset
95
+ return null;
96
+ }
97
+ const hubKey = key ? (_b = key.split('_').pop()) !== null && _b !== void 0 ? _b : '' : '';
98
+ const decimals = Number((_c = r.decimals) !== null && _c !== void 0 ? _c : 18);
99
+ const userSuppliedAssetsRaw = (_d = r.userSuppliedAssets) !== null && _d !== void 0 ? _d : 0;
100
+ const userSuppliedSharesRaw = (_e = r.userSuppliedShares) !== null && _e !== void 0 ? _e : 0;
101
+ const userSuppliedAssetsEth = assetAmountInEth(userSuppliedAssetsRaw.toString(), symbol);
102
+ const userSuppliedSharesEth = assetAmountInEth(userSuppliedSharesRaw.toString(), symbol);
103
+ return {
104
+ vaultAddress,
105
+ key,
106
+ symbol,
107
+ hubKey,
108
+ spokeActive: (_f = r.spokeActive) !== null && _f !== void 0 ? _f : true,
109
+ spokeHalted: (_g = r.spokeHalted) !== null && _g !== void 0 ? _g : false,
110
+ spokeDepositCap: ((_h = r.spokeDepositCap) !== null && _h !== void 0 ? _h : 0).toString(),
111
+ spokeTotalAssets: ((_j = r.spokeTotalAssets) !== null && _j !== void 0 ? _j : 0).toString(),
112
+ hubLiquidity: ((_k = r.hubLiquidity) !== null && _k !== void 0 ? _k : 0).toString(),
113
+ convertToShares: ((_l = r.convertToShares) !== null && _l !== void 0 ? _l : 0).toString(),
114
+ userSuppliedAssetsEth,
115
+ userSuppliedSharesEth,
116
+ userSuppliedAssets: userSuppliedAssetsRaw.toString(),
117
+ userSuppliedShares: userSuppliedSharesRaw.toString(),
118
+ underlyingAsset: r.underlyingAsset,
119
+ spoke: r.spoke,
120
+ decimals,
121
+ };
122
+ }).filter(item => item != null);
123
+ });
124
+ }