@defisaver/positions-sdk 2.0.12 → 2.0.14-dev-portfolio

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 (170) hide show
  1. package/.mocharc.json +4 -4
  2. package/.nvmrc +1 -1
  3. package/CLAUDE.md +32 -0
  4. package/README.md +64 -64
  5. package/cjs/aaveV2/index.js +1 -0
  6. package/cjs/aaveV3/index.d.ts +12 -0
  7. package/cjs/aaveV3/index.js +93 -1
  8. package/cjs/claiming/aaveV3.d.ts +9 -0
  9. package/cjs/claiming/aaveV3.js +148 -0
  10. package/cjs/claiming/compV3.d.ts +15 -0
  11. package/cjs/claiming/compV3.js +34 -0
  12. package/cjs/claiming/index.d.ts +6 -0
  13. package/cjs/claiming/index.js +46 -0
  14. package/cjs/claiming/king.d.ts +4 -0
  15. package/cjs/claiming/king.js +72 -0
  16. package/cjs/claiming/morphoBlue.d.ts +6 -0
  17. package/cjs/claiming/morphoBlue.js +113 -0
  18. package/cjs/claiming/spark.d.ts +6 -0
  19. package/cjs/claiming/spark.js +188 -0
  20. package/cjs/config/contracts.d.ts +2667 -0
  21. package/cjs/config/contracts.js +103 -2
  22. package/cjs/constants/index.d.ts +4 -0
  23. package/cjs/constants/index.js +6 -2
  24. package/cjs/contracts.d.ts +2882 -23
  25. package/cjs/contracts.js +10 -1
  26. package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
  27. package/cjs/index.d.ts +2 -1
  28. package/cjs/index.js +3 -1
  29. package/cjs/liquity/index.d.ts +11 -0
  30. package/cjs/liquity/index.js +39 -1
  31. package/cjs/liquityV2/index.d.ts +8 -0
  32. package/cjs/liquityV2/index.js +161 -0
  33. package/cjs/markets/aave/marketAssets.js +1 -1
  34. package/cjs/markets/compound/marketsAssets.js +2 -2
  35. package/cjs/markets/spark/marketAssets.js +1 -1
  36. package/cjs/morphoBlue/index.d.ts +5 -0
  37. package/cjs/morphoBlue/index.js +38 -4
  38. package/cjs/portfolio/index.d.ts +6 -1
  39. package/cjs/portfolio/index.js +256 -10
  40. package/cjs/services/utils.d.ts +5 -0
  41. package/cjs/services/utils.js +33 -1
  42. package/cjs/services/viem.d.ts +12 -12
  43. package/cjs/spark/index.js +1 -0
  44. package/cjs/staking/staking.js +3 -1
  45. package/cjs/types/claiming.d.ts +93 -0
  46. package/cjs/types/claiming.js +27 -0
  47. package/cjs/umbrella/index.d.ts +5 -0
  48. package/cjs/umbrella/index.js +50 -0
  49. package/cjs/umbrella/umbrellaUtils.d.ts +22 -0
  50. package/cjs/umbrella/umbrellaUtils.js +34 -0
  51. package/esm/aaveV2/index.js +1 -0
  52. package/esm/aaveV3/index.d.ts +12 -0
  53. package/esm/aaveV3/index.js +91 -1
  54. package/esm/claiming/aaveV3.d.ts +9 -0
  55. package/esm/claiming/aaveV3.js +139 -0
  56. package/esm/claiming/compV3.d.ts +15 -0
  57. package/esm/claiming/compV3.js +30 -0
  58. package/esm/claiming/index.d.ts +6 -0
  59. package/esm/claiming/index.js +6 -0
  60. package/esm/claiming/king.d.ts +4 -0
  61. package/esm/claiming/king.js +64 -0
  62. package/esm/claiming/morphoBlue.d.ts +6 -0
  63. package/esm/claiming/morphoBlue.js +104 -0
  64. package/esm/claiming/spark.d.ts +6 -0
  65. package/esm/claiming/spark.js +179 -0
  66. package/esm/config/contracts.d.ts +2667 -0
  67. package/esm/config/contracts.js +102 -1
  68. package/esm/constants/index.d.ts +4 -0
  69. package/esm/constants/index.js +5 -1
  70. package/esm/contracts.d.ts +2882 -23
  71. package/esm/contracts.js +9 -0
  72. package/esm/helpers/morphoBlueHelpers/index.js +66 -66
  73. package/esm/index.d.ts +2 -1
  74. package/esm/index.js +2 -1
  75. package/esm/liquity/index.d.ts +11 -0
  76. package/esm/liquity/index.js +38 -1
  77. package/esm/liquityV2/index.d.ts +8 -0
  78. package/esm/liquityV2/index.js +162 -1
  79. package/esm/markets/aave/marketAssets.js +1 -1
  80. package/esm/markets/compound/marketsAssets.js +2 -2
  81. package/esm/markets/spark/marketAssets.js +1 -1
  82. package/esm/morphoBlue/index.d.ts +5 -0
  83. package/esm/morphoBlue/index.js +38 -5
  84. package/esm/portfolio/index.d.ts +6 -1
  85. package/esm/portfolio/index.js +260 -14
  86. package/esm/services/utils.d.ts +5 -0
  87. package/esm/services/utils.js +31 -0
  88. package/esm/services/viem.d.ts +12 -12
  89. package/esm/spark/index.js +1 -0
  90. package/esm/staking/staking.js +3 -1
  91. package/esm/types/claiming.d.ts +93 -0
  92. package/esm/types/claiming.js +24 -0
  93. package/esm/umbrella/index.d.ts +5 -0
  94. package/esm/umbrella/index.js +46 -0
  95. package/esm/umbrella/umbrellaUtils.d.ts +22 -0
  96. package/esm/umbrella/umbrellaUtils.js +28 -0
  97. package/package.json +47 -47
  98. package/src/aaveV2/index.ts +237 -236
  99. package/src/aaveV3/index.ts +586 -488
  100. package/src/claiming/aaveV3.ts +163 -0
  101. package/src/claiming/compV3.ts +23 -0
  102. package/src/claiming/index.ts +13 -0
  103. package/src/claiming/king.ts +66 -0
  104. package/src/claiming/morphoBlue.ts +119 -0
  105. package/src/claiming/spark.ts +226 -0
  106. package/src/compoundV2/index.ts +240 -240
  107. package/src/compoundV3/index.ts +270 -270
  108. package/src/config/contracts.ts +1208 -1108
  109. package/src/constants/index.ts +10 -6
  110. package/src/contracts.ts +121 -108
  111. package/src/curveUsd/index.ts +250 -250
  112. package/src/eulerV2/index.ts +314 -314
  113. package/src/exchange/index.ts +25 -25
  114. package/src/fluid/index.ts +1568 -1568
  115. package/src/helpers/aaveHelpers/index.ts +170 -170
  116. package/src/helpers/compoundHelpers/index.ts +261 -261
  117. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  118. package/src/helpers/eulerHelpers/index.ts +259 -259
  119. package/src/helpers/fluidHelpers/index.ts +324 -324
  120. package/src/helpers/index.ts +10 -10
  121. package/src/helpers/liquityV2Helpers/index.ts +80 -80
  122. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  123. package/src/helpers/makerHelpers/index.ts +52 -52
  124. package/src/helpers/morphoBlueHelpers/index.ts +390 -390
  125. package/src/helpers/sparkHelpers/index.ts +155 -155
  126. package/src/index.ts +47 -45
  127. package/src/liquity/index.ts +160 -105
  128. package/src/liquityV2/index.ts +583 -408
  129. package/src/llamaLend/index.ts +296 -296
  130. package/src/maker/index.ts +223 -223
  131. package/src/markets/aave/index.ts +116 -116
  132. package/src/markets/aave/marketAssets.ts +49 -49
  133. package/src/markets/compound/index.ts +227 -227
  134. package/src/markets/compound/marketsAssets.ts +90 -90
  135. package/src/markets/curveUsd/index.ts +69 -69
  136. package/src/markets/euler/index.ts +26 -26
  137. package/src/markets/fluid/index.ts +2456 -2456
  138. package/src/markets/index.ts +25 -25
  139. package/src/markets/liquityV2/index.ts +102 -102
  140. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  141. package/src/markets/llamaLend/index.ts +235 -235
  142. package/src/markets/morphoBlue/index.ts +895 -895
  143. package/src/markets/spark/index.ts +29 -29
  144. package/src/markets/spark/marketAssets.ts +11 -11
  145. package/src/moneymarket/moneymarketCommonService.ts +80 -80
  146. package/src/morphoBlue/index.ts +259 -222
  147. package/src/portfolio/index.ts +533 -285
  148. package/src/services/priceService.ts +159 -159
  149. package/src/services/utils.ts +100 -64
  150. package/src/services/viem.ts +32 -32
  151. package/src/setup.ts +8 -8
  152. package/src/spark/index.ts +457 -456
  153. package/src/staking/staking.ts +194 -193
  154. package/src/types/aave.ts +194 -194
  155. package/src/types/claiming.ts +109 -0
  156. package/src/types/common.ts +88 -88
  157. package/src/types/compound.ts +136 -136
  158. package/src/types/curveUsd.ts +121 -121
  159. package/src/types/euler.ts +174 -174
  160. package/src/types/fluid.ts +450 -450
  161. package/src/types/index.ts +11 -11
  162. package/src/types/liquity.ts +30 -30
  163. package/src/types/liquityV2.ts +126 -126
  164. package/src/types/llamaLend.ts +157 -157
  165. package/src/types/maker.ts +63 -63
  166. package/src/types/morphoBlue.ts +194 -194
  167. package/src/types/portfolio.ts +60 -60
  168. package/src/types/spark.ts +137 -137
  169. package/src/umbrella/index.ts +70 -0
  170. package/src/umbrella/umbrellaUtils.ts +30 -0
@@ -0,0 +1,5 @@
1
+ import { Client } from 'viem';
2
+ import { EthAddress, NetworkNumber } from '../types/common';
3
+ export declare const getUmbrellaData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<{
4
+ [k: string]: any;
5
+ }>;
@@ -0,0 +1,46 @@
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 { AaveUmbrellaViewViem, AaveV3ViewContractViem } from '../contracts';
11
+ import { compareAddresses, convertHybridArraysToObjects, getEthAmountForDecimals } from '../services/utils';
12
+ import { findMatching, tokenEntries } from './umbrellaUtils';
13
+ const umbrella = '0xD400fc38ED4732893174325693a63C30ee3881a8';
14
+ const aaveOracle = '0x54586bE62E3c3580375aE3723C145253060Ca0C2';
15
+ export const getUmbrellaData = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const umbrellaView = AaveUmbrellaViewViem(provider, network);
17
+ const aaveV3View = AaveV3ViewContractViem(provider, network);
18
+ const [tokensAggregatedData, additionalUmbrellaStakingData, userAggregatedData] = yield Promise.all([
19
+ umbrellaView.read.getTokensAggregatedData([umbrella, aaveOracle]),
20
+ aaveV3View.read.getAdditionalUmbrellaStakingData([umbrella, address]),
21
+ umbrellaView.read.getUserAggregatedData([umbrella, address]),
22
+ ]);
23
+ return Object.fromEntries(tokenEntries.map(([symbol, tokenAddr]) => {
24
+ // @ts-ignore
25
+ const fromTokens = convertHybridArraysToObjects(findMatching(tokensAggregatedData, tokenAddr));
26
+ // @ts-ignore
27
+ const fromUser = convertHybridArraysToObjects(findMatching(userAggregatedData, tokenAddr));
28
+ // @ts-ignore
29
+ const fromAdditionalData = convertHybridArraysToObjects(findMatching(additionalUmbrellaStakingData, tokenAddr));
30
+ const data = Object.assign(Object.assign(Object.assign(Object.assign({}, fromTokens), fromUser), fromAdditionalData), { account: {
31
+ stakeUserBalance: (fromUser === null || fromUser === void 0 ? void 0 : fromUser.stakeUserBalance) || '0',
32
+ rewardsTokenUserData: convertHybridArraysToObjects(fromUser === null || fromUser === void 0 ? void 0 : fromUser.rewardsTokenUserData) || [],
33
+ userCooldownAmount: (fromAdditionalData === null || fromAdditionalData === void 0 ? void 0 : fromAdditionalData.userCooldownAmount) || '0',
34
+ userEndOfCooldown: (fromAdditionalData === null || fromAdditionalData === void 0 ? void 0 : fromAdditionalData.userEndOfCooldown) || '0',
35
+ userWithdrawalWindow: (fromAdditionalData === null || fromAdditionalData === void 0 ? void 0 : fromAdditionalData.userWithdrawalWindow) || '0',
36
+ } });
37
+ const stakeTokenData = data.stakeTokenData;
38
+ return [symbol, Object.assign(Object.assign({}, data), { stakeTokenData: Object.assign(Object.assign({}, stakeTokenData), { price: getEthAmountForDecimals(stakeTokenData.price, 8) }), stkTokenToWaTokenRate: getEthAmountForDecimals(data.stkTokenToWaTokenRate, stakeTokenData.decimals), waTokenToATokenRate: getEthAmountForDecimals(data.waTokenToATokenRate, stakeTokenData.decimals), totalShares: getEthAmountForDecimals(data.totalShares, stakeTokenData.decimals), totalAssets: getEthAmountForDecimals(data.totalAssets, stakeTokenData.decimals), targetLiquidity: getEthAmountForDecimals(data.targetLiquidity, stakeTokenData.decimals), rewardsTokenData: data.rewardsTokenData.map((tokenData) => (Object.assign(Object.assign({}, tokenData), { rewardTokenData: Object.assign(Object.assign({}, tokenData.rewardTokenData), { price: getEthAmountForDecimals(tokenData.rewardTokenData.price, 8) }) }))), rewardsEmissionRates: data.rewardsEmissionRates.map((rate, i) => {
39
+ const tokenData = data.rewardsTokenData[i].rewardTokenData;
40
+ return getEthAmountForDecimals(rate, tokenData.decimals);
41
+ }), account: Object.assign(Object.assign({}, data.account), { stakeUserBalance: getEthAmountForDecimals(data.account.stakeUserBalance, stakeTokenData.decimals), userCooldownAmount: getEthAmountForDecimals(data.account.userCooldownAmount, stakeTokenData.decimals), rewardsTokenUserData: data.account.rewardsTokenUserData.map((reward) => {
42
+ const tokenData = data.rewardsTokenData.find((tknData) => compareAddresses(tknData.rewardTokenData.token, reward.reward));
43
+ return (Object.assign(Object.assign({}, reward), { currentReward: getEthAmountForDecimals(reward.currentReward, tokenData.rewardTokenData.decimals) }));
44
+ }) }) })];
45
+ }));
46
+ });
@@ -0,0 +1,22 @@
1
+ export declare enum UmbrellaStaking {
2
+ UmbrellaGHO = "UmbrellaGHO",
3
+ UmbrellaUSDC = "UmbrellaUSDC",
4
+ UmbrellaUSDT = "UmbrellaUSDT",
5
+ UmbrellaETH = "UmbrellaETH"
6
+ }
7
+ export declare const tokenMapping: {
8
+ readonly UmbrellaUSDC: "0x6bf183243FdD1e306ad2C4450BC7dcf6f0bf8Aa6";
9
+ readonly UmbrellaUSDT: "0xA484Ab92fe32B143AEE7019fC1502b1dAA522D31";
10
+ readonly UmbrellaETH: "0xaAFD07D53A7365D3e9fb6F3a3B09EC19676B73Ce";
11
+ readonly UmbrellaGHO: "0x4f827A63755855cDf3e8f3bcD20265C833f15033";
12
+ };
13
+ export declare const normalize: (addr?: string) => string;
14
+ export declare const tokenEntries: string[][];
15
+ export declare const extractAddress: (item?: {
16
+ stakeToken?: string;
17
+ stkToken?: string;
18
+ stakeTokenData?: {
19
+ token?: string;
20
+ };
21
+ }) => string;
22
+ export declare const findMatching: (dataset: any[], targetAddr: string) => any;
@@ -0,0 +1,28 @@
1
+ export var UmbrellaStaking;
2
+ (function (UmbrellaStaking) {
3
+ UmbrellaStaking["UmbrellaGHO"] = "UmbrellaGHO";
4
+ UmbrellaStaking["UmbrellaUSDC"] = "UmbrellaUSDC";
5
+ UmbrellaStaking["UmbrellaUSDT"] = "UmbrellaUSDT";
6
+ UmbrellaStaking["UmbrellaETH"] = "UmbrellaETH";
7
+ })(UmbrellaStaking || (UmbrellaStaking = {}));
8
+ export const tokenMapping = {
9
+ [UmbrellaStaking.UmbrellaUSDC]: '0x6bf183243FdD1e306ad2C4450BC7dcf6f0bf8Aa6',
10
+ [UmbrellaStaking.UmbrellaUSDT]: '0xA484Ab92fe32B143AEE7019fC1502b1dAA522D31',
11
+ [UmbrellaStaking.UmbrellaETH]: '0xaAFD07D53A7365D3e9fb6F3a3B09EC19676B73Ce',
12
+ [UmbrellaStaking.UmbrellaGHO]: '0x4f827A63755855cDf3e8f3bcD20265C833f15033',
13
+ };
14
+ // ----- chat gpt code for result mapping ---------
15
+ export const normalize = (addr) => { var _a, _b; return (_b = (_a = addr === null || addr === void 0 ? void 0 : addr.toLowerCase) === null || _a === void 0 ? void 0 : _a.call(addr)) !== null && _b !== void 0 ? _b : ''; };
16
+ export const tokenEntries = Object.entries(tokenMapping).map(([symbol, address]) => [
17
+ symbol,
18
+ normalize(address),
19
+ ]);
20
+ // 👇 Define how to extract the token address from each source type
21
+ export const extractAddress = (item) => {
22
+ var _a;
23
+ return normalize((item === null || item === void 0 ? void 0 : item.stakeToken)
24
+ || (item === null || item === void 0 ? void 0 : item.stkToken)
25
+ || ((_a = item === null || item === void 0 ? void 0 : item.stakeTokenData) === null || _a === void 0 ? void 0 : _a.token));
26
+ };
27
+ // 👇 Utility to find the matching object in a dataset
28
+ export const findMatching = (dataset, targetAddr) => dataset.find((item) => extractAddress(item) === targetAddr);
package/package.json CHANGED
@@ -1,47 +1,47 @@
1
- {
2
- "name": "@defisaver/positions-sdk",
3
- "version": "2.0.12",
4
- "description": "",
5
- "main": "./cjs/index.js",
6
- "module": "./esm/index.js",
7
- "types": "./esm/index.d.ts",
8
- "scripts": {
9
- "build:esm": "rm -rf esm && tsc -p tsconfig.esm.json",
10
- "build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
11
- "build": "npm run lint && npm run build:cjs && npm run build:esm",
12
- "dev": "tsc -p tsconfig.json --watch",
13
- "lint": "eslint src/ --fix",
14
- "lint-check": "eslint src/",
15
- "test": "mocha tests/*",
16
- "test-single": "mocha ./tests/$npm_config_name.ts",
17
- "test:debugger": "mocha --inspect-brk tests/*",
18
- "version-bump": "git commit -am \"Version bump to $(npm version patch | cut -c 2-)\""
19
- },
20
- "keywords": [],
21
- "author": "",
22
- "license": "ISC",
23
- "dependencies": {
24
- "@defisaver/tokens": "^1.7.0",
25
- "@types/lodash": "^4.17.15",
26
- "@types/memoizee": "^0.4.12",
27
- "decimal.js": "^10.6.0",
28
- "lodash": "^4.17.21",
29
- "memoizee": "^0.4.17",
30
- "viem": "^2.31.4"
31
- },
32
- "devDependencies": {
33
- "@defisaver/eslint-config": "^1.0.1",
34
- "@metamask/eth-json-rpc-middleware": "^15.0.1",
35
- "@metamask/eth-json-rpc-provider": "^4.1.6",
36
- "@types/chai": "^5.0.0",
37
- "@types/mocha": "^10.0.9",
38
- "chai": "^4.3.8",
39
- "dotenv": "^16.3.1",
40
- "eslint": "^8.49.0",
41
- "eslint-plugin-import": "^2.31.0",
42
- "mocha": "^10.2.0",
43
- "nock": "^14.0.0",
44
- "ts-node": "^10.9.2",
45
- "typescript": "^5.2.2"
46
- }
47
- }
1
+ {
2
+ "name": "@defisaver/positions-sdk",
3
+ "version": "2.0.14-dev-portfolio",
4
+ "description": "",
5
+ "main": "./cjs/index.js",
6
+ "module": "./esm/index.js",
7
+ "types": "./esm/index.d.ts",
8
+ "scripts": {
9
+ "build:esm": "rm -rf esm && tsc -p tsconfig.esm.json",
10
+ "build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
11
+ "build": "npm run lint && npm run build:cjs && npm run build:esm",
12
+ "dev": "tsc -p tsconfig.json --watch",
13
+ "lint": "eslint src/ --fix",
14
+ "lint-check": "eslint src/",
15
+ "test": "mocha tests/*",
16
+ "test-single": "mocha ./tests/$npm_config_name.ts",
17
+ "test:debugger": "mocha --inspect-brk tests/*",
18
+ "version-bump": "git commit -am \"Version bump to $(npm version patch | cut -c 2-)\""
19
+ },
20
+ "keywords": [],
21
+ "author": "",
22
+ "license": "ISC",
23
+ "dependencies": {
24
+ "@defisaver/tokens": "^1.7.1",
25
+ "@types/lodash": "^4.17.15",
26
+ "@types/memoizee": "^0.4.12",
27
+ "decimal.js": "^10.6.0",
28
+ "lodash": "^4.17.21",
29
+ "memoizee": "^0.4.17",
30
+ "viem": "^2.31.4"
31
+ },
32
+ "devDependencies": {
33
+ "@defisaver/eslint-config": "^1.0.1",
34
+ "@metamask/eth-json-rpc-middleware": "^15.0.1",
35
+ "@metamask/eth-json-rpc-provider": "^4.1.6",
36
+ "@types/chai": "^5.0.0",
37
+ "@types/mocha": "^10.0.9",
38
+ "chai": "^4.3.8",
39
+ "dotenv": "^16.3.1",
40
+ "eslint": "^8.49.0",
41
+ "eslint-plugin-import": "^2.31.0",
42
+ "mocha": "^10.2.0",
43
+ "nock": "^14.0.0",
44
+ "ts-node": "^10.9.2",
45
+ "typescript": "^5.2.2"
46
+ }
47
+ }