@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
package/.mocharc.json CHANGED
@@ -1,4 +1,4 @@
1
- {
2
- "require": "ts-node/register",
3
- "extension": ["ts"]
4
- }
1
+ {
2
+ "require": "ts-node/register",
3
+ "extension": ["ts"]
4
+ }
package/.nvmrc CHANGED
@@ -1 +1 @@
1
- v20.17.0
1
+ v20.17.0
package/CLAUDE.md ADDED
@@ -0,0 +1,32 @@
1
+ # DeFiSaver Positions SDK
2
+
3
+ TypeScript SDK for DeFi positions tracking and management.
4
+
5
+ ## Commands
6
+
7
+ ```bash
8
+ # Development
9
+ npm run dev # Watch mode compilation
10
+ npm run build # Lint and build both CJS and ESM
11
+ npm run build:cjs # Build CommonJS
12
+ npm run build:esm # Build ES modules
13
+
14
+ # Linting
15
+ npm run lint # Lint and fix
16
+ npm run lint-check # Lint without fixing
17
+
18
+ # Testing
19
+ npm run test # Run all tests
20
+ npm run test-single # Run single test (use --name=filename)
21
+ npm run test:debugger # Run tests with debugger
22
+
23
+ # Versioning
24
+ npm run version-bump # Commit and bump patch version
25
+ ```
26
+
27
+ ## Project Structure
28
+
29
+ - `src/` - TypeScript source code
30
+ - `tests/` - Test files
31
+ - `esm/` - ES module build output
32
+ - `cjs/` - CommonJS build output
package/README.md CHANGED
@@ -1,64 +1,64 @@
1
- # DeFi Saver Positions SDK
2
-
3
- Supported protocols:
4
- - [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
5
- - [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
6
- - [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
7
- - [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
8
- - [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
9
- - [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
10
- - [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
11
- - [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
12
-
13
- ## Setup
14
- Supported Node version is v10.
15
-
16
- - run `npm install` (first time)
17
- - run `npm run build`
18
-
19
- `build` command will generate contracts and build ejs and esm folders
20
-
21
- ## How to use
22
- [All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
23
-
24
- This is a Compound V3 example, and every other protocol is similar
25
- ```js
26
- import { compoundV3 } from '@defisaver/positions-sdk';
27
-
28
-
29
- // every protocol has market data and user data getters
30
- const {
31
- getCompoundV3MarketsData,
32
- getCompoundV3AccountData,
33
- } = compoundV3;
34
-
35
- const provider = 'Your RPC provider';
36
-
37
- const user = '0x123...';
38
-
39
- const { assetsData } = await getCompoundV3MarketsData(
40
- provider, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
41
- 1, // network
42
- selectedMarket, // market object like in /src/markets/compound/index.ts
43
- provider, // this must be mainnet rpc - used for getting prices onchain and calculating apys
44
- );
45
-
46
- const userData = await getCompoundV3AccountData(
47
- provider,
48
- 1, // network
49
- userAddress, // EOA or DSProxy
50
- '', // proxy address of the user, or just empty string if checking for EOA
51
- {
52
- selectedMarket, // market object as in /src/markets/compound/index.ts
53
- assetsData,
54
- }
55
- );
56
- ```
57
-
58
- More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
59
-
60
- ## Testing
61
-
62
- `npm run test` - Run all tests
63
-
64
- `npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
1
+ # DeFi Saver Positions SDK
2
+
3
+ Supported protocols:
4
+ - [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
5
+ - [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
6
+ - [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
7
+ - [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
8
+ - [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
9
+ - [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
10
+ - [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
11
+ - [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
12
+
13
+ ## Setup
14
+ Supported Node version is v10.
15
+
16
+ - run `npm install` (first time)
17
+ - run `npm run build`
18
+
19
+ `build` command will generate contracts and build ejs and esm folders
20
+
21
+ ## How to use
22
+ [All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
23
+
24
+ This is a Compound V3 example, and every other protocol is similar
25
+ ```js
26
+ import { compoundV3 } from '@defisaver/positions-sdk';
27
+
28
+
29
+ // every protocol has market data and user data getters
30
+ const {
31
+ getCompoundV3MarketsData,
32
+ getCompoundV3AccountData,
33
+ } = compoundV3;
34
+
35
+ const provider = 'Your RPC provider';
36
+
37
+ const user = '0x123...';
38
+
39
+ const { assetsData } = await getCompoundV3MarketsData(
40
+ provider, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
41
+ 1, // network
42
+ selectedMarket, // market object like in /src/markets/compound/index.ts
43
+ provider, // this must be mainnet rpc - used for getting prices onchain and calculating apys
44
+ );
45
+
46
+ const userData = await getCompoundV3AccountData(
47
+ provider,
48
+ 1, // network
49
+ userAddress, // EOA or DSProxy
50
+ '', // proxy address of the user, or just empty string if checking for EOA
51
+ {
52
+ selectedMarket, // market object as in /src/markets/compound/index.ts
53
+ assetsData,
54
+ }
55
+ );
56
+ ```
57
+
58
+ More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
59
+
60
+ ## Testing
61
+
62
+ `npm run test` - Run all tests
63
+
64
+ `npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
@@ -101,6 +101,7 @@ const _getAaveV2AccountBalances = (provider, network, block, addressMapping, add
101
101
  const marketAddress = market.providerAddress;
102
102
  // @ts-ignore
103
103
  const protocolDataProviderContract = (0, contracts_1.createViemContractFromConfigFunc)(market.protocolData, market.protocolDataAddress)(provider, network);
104
+ // @ts-ignore
104
105
  const reserveTokens = yield protocolDataProviderContract.read.getAllReservesTokens((0, viem_1.setViemBlockNumber)(block));
105
106
  const symbols = reserveTokens.map(({ symbol }) => symbol);
106
107
  const _addresses = reserveTokens.map(({ tokenAddress }) => tokenAddress);
@@ -32,3 +32,15 @@ export declare const getAaveV3AccountBalances: (provider: EthereumProvider, netw
32
32
  export declare const _getAaveV3AccountData: (provider: Client, network: NetworkNumber, address: EthAddress, extractedState: any, blockNumber?: "latest" | number) => Promise<AaveV3PositionData>;
33
33
  export declare const getAaveV3AccountData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, extractedState: any, blockNumber?: "latest" | number) => Promise<AaveV3PositionData>;
34
34
  export declare const getAaveV3FullPositionData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, market: AaveMarketInfo) => Promise<AaveV3PositionData>;
35
+ export declare const REWARDABLE_ASSETS: readonly ["0x028171bCA77440897B824Ca71D1c56caC55b68A3", "0x6C3c78838c761c6Ac7bE9F59fe808ea2A6E4379d", "0xD37EE7e4f452C6638c96536e68090De8cBcdb583", "0x279AF5b99540c1A3A7E3CDd326e19659401eF99e", "0xBcca60bB61934080951369a648Fb03DF4F96263C", "0x619beb58998eD2278e08620f97007e1116D5D25b", "0x3Ed3B47Dd13EC9a98b44e6204A523E766B225811", "0x531842cEbbdD378f8ee36D171d6cC9C4fcf475Ec", "0x9ff58f4fFB29fA2266Ab25e75e2A8b3503311656", "0x9c39809Dec7F95F5e0713634a4D0701329B3b4d2", "0x030bA81f1c18d280636F32af80b9AAd02Cf0854e", "0xF63B34710400CAd3e044cFfDcAb00a0f32E33eCf", "0xa06bC25B5805d5F8d82847D191Cb4Af5A3e873E0", "0x0b8f12b1788BFdE65Aa1ca52E3e9F3Ba401be16D", "0x6C5024Cd4F8A59110119C56f8933403A539555EB", "0xdC6a3Ab17299D9C2A412B0e0a4C1f55446AE0817", "0x5165d24277cD063F5ac44Efd447B27025e888f37", "0x7EbD09022Be45AD993BAA1CEc61166Fcc8644d97", "0xF256CC7847E919FAc9B808cC216cAc87CCF2f47a", "0xfAFEDF95E21184E3d880bd56D4806c4b8d31c69A", "0xB9D7CB55f463405CDfBe4E90a6D2Df01C2B92BF1", "0x5BdB050A92CADcCfCDcCCBFC17204a1C9cC0Ab73", "0xc713e5E149D5D0715DcD1c156a020976e7E56B88", "0xba728eAd5e496BE00DCF66F650b6d7758eCB50f8", "0x101cc05f4A51C0319f570d5E146a8C625198e636", "0x01C0eb1f8c6F1C1bF74ae028697ce7AA2a8b0E92", "0xc9BC48c72154ef3e5425641a3c747242112a46AF", "0xB5385132EE8321977FfF44b60cDE9fE9AB0B4e6b", "0x272F97b7a56a387aE942350bBC7Df5700f8a4576", "0x13210D4Fe0d5402bd7Ecbc4B5bC5cFcA3b71adB0", "0x2e8f4bdbe3d47d7d7de490437aea9915d930f1a3", "0xfdb93b3b10936cf81fa59a02a7523b6e2149b2b7", "0xA361718326c15715591c299427c62086F69923D9", "0xbA429f7011c9fa04cDd46a2Da24dc0FF0aC6099c", "0xd4937682df3C8aEF4FE912A96A74121C0829E664", "0xfE8F19B17fFeF0fDbfe2671F248903055AFAA8Ca", "0x683923dB55Fead99A79Fa01A27EeC3cB19679cC3", "0xC2e10006AccAb7B45D9184FcF5b7EC7763f5BaAe", "0x8dAE6Cb04688C62d939ed9B68d32Bc62e49970b1", "0x00ad8eBF64F141f1C81e9f8f792d3d1631c6c684", "0x6F634c6135D2EBD550000ac92F494F9CB8183dAe", "0x4dDff5885a67E4EffeC55875a3977D7E60F82ae0"];
36
+ export declare const fetchYearlyMeritApyForStakingGho: () => Promise<string>;
37
+ export declare const getStakeAaveData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<{
38
+ activatedCooldown: string;
39
+ activatedCooldownAmount: string;
40
+ stkAaveRewardsBalance: string;
41
+ aaveRewardsBalance: string;
42
+ stkAaveBalance: string;
43
+ stkGhoBalance: string;
44
+ ghoMeritApy: string;
45
+ stkAaveApy: string;
46
+ }>;
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getAaveV3FullPositionData = exports.getAaveV3AccountData = exports._getAaveV3AccountData = exports.getAaveV3AccountBalances = exports._getAaveV3AccountBalances = exports.EMPTY_AAVE_DATA = exports.aaveV3EmodeCategoriesMapping = void 0;
15
+ exports.getStakeAaveData = exports.fetchYearlyMeritApyForStakingGho = exports.REWARDABLE_ASSETS = exports.getAaveV3FullPositionData = exports.getAaveV3AccountData = exports._getAaveV3AccountData = exports.getAaveV3AccountBalances = exports._getAaveV3AccountBalances = exports.EMPTY_AAVE_DATA = exports.aaveV3EmodeCategoriesMapping = void 0;
16
16
  exports._getAaveV3MarketData = _getAaveV3MarketData;
17
17
  exports.getAaveV3MarketData = getAaveV3MarketData;
18
18
  const tokens_1 = require("@defisaver/tokens");
@@ -25,6 +25,7 @@ const utils_1 = require("../services/utils");
25
25
  const staking_1 = require("../staking");
26
26
  const common_1 = require("../types/common");
27
27
  const viem_1 = require("../services/viem");
28
+ const constants_1 = require("../constants");
28
29
  const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
29
30
  const { eModeCategoriesData } = extractedState;
30
31
  const usedAssetsValues = Object.values(usedAssets);
@@ -313,6 +314,7 @@ const _getAaveV3AccountBalances = (provider, network, block, addressMapping, add
313
314
  const marketAddress = market.providerAddress;
314
315
  // @ts-ignore
315
316
  const protocolDataProviderContract = (0, contracts_1.createViemContractFromConfigFunc)(market.protocolData, market.protocolDataAddress)(provider, network);
317
+ // @ts-ignore
316
318
  const reserveTokens = yield protocolDataProviderContract.read.getAllReservesTokens((0, viem_1.setViemBlockNumber)(block));
317
319
  const symbols = reserveTokens.map(({ symbol }) => symbol);
318
320
  const _addresses = reserveTokens.map(({ tokenAddress }) => tokenAddress);
@@ -417,3 +419,93 @@ const getAaveV3FullPositionData = (provider, network, address, market) => __awai
417
419
  return positionData;
418
420
  });
419
421
  exports.getAaveV3FullPositionData = getAaveV3FullPositionData;
422
+ // aTokens eligible for AAVE rewards
423
+ exports.REWARDABLE_ASSETS = [
424
+ '0x028171bCA77440897B824Ca71D1c56caC55b68A3', // DAI
425
+ '0x6C3c78838c761c6Ac7bE9F59fe808ea2A6E4379d',
426
+ '0xD37EE7e4f452C6638c96536e68090De8cBcdb583', // GUSD
427
+ '0x279AF5b99540c1A3A7E3CDd326e19659401eF99e',
428
+ '0xBcca60bB61934080951369a648Fb03DF4F96263C', // USDC
429
+ '0x619beb58998eD2278e08620f97007e1116D5D25b',
430
+ '0x3Ed3B47Dd13EC9a98b44e6204A523E766B225811', // USDT
431
+ '0x531842cEbbdD378f8ee36D171d6cC9C4fcf475Ec',
432
+ '0x9ff58f4fFB29fA2266Ab25e75e2A8b3503311656', // WBTC
433
+ '0x9c39809Dec7F95F5e0713634a4D0701329B3b4d2',
434
+ '0x030bA81f1c18d280636F32af80b9AAd02Cf0854e', // WETH
435
+ '0xF63B34710400CAd3e044cFfDcAb00a0f32E33eCf',
436
+ '0xa06bC25B5805d5F8d82847D191Cb4Af5A3e873E0', // LINK
437
+ '0x0b8f12b1788BFdE65Aa1ca52E3e9F3Ba401be16D',
438
+ '0x6C5024Cd4F8A59110119C56f8933403A539555EB', // SUSD
439
+ '0xdC6a3Ab17299D9C2A412B0e0a4C1f55446AE0817',
440
+ '0x5165d24277cD063F5ac44Efd447B27025e888f37', // YFI
441
+ '0x7EbD09022Be45AD993BAA1CEc61166Fcc8644d97',
442
+ '0xF256CC7847E919FAc9B808cC216cAc87CCF2f47a', // xSUSHI
443
+ '0xfAFEDF95E21184E3d880bd56D4806c4b8d31c69A',
444
+ '0xB9D7CB55f463405CDfBe4E90a6D2Df01C2B92BF1', // UNI
445
+ '0x5BdB050A92CADcCfCDcCCBFC17204a1C9cC0Ab73',
446
+ '0xc713e5E149D5D0715DcD1c156a020976e7E56B88', // MKR
447
+ '0xba728eAd5e496BE00DCF66F650b6d7758eCB50f8',
448
+ '0x101cc05f4A51C0319f570d5E146a8C625198e636', // TUSD
449
+ '0x01C0eb1f8c6F1C1bF74ae028697ce7AA2a8b0E92',
450
+ '0xc9BC48c72154ef3e5425641a3c747242112a46AF', // RAI
451
+ '0xB5385132EE8321977FfF44b60cDE9fE9AB0B4e6b',
452
+ '0x272F97b7a56a387aE942350bBC7Df5700f8a4576', // BAL
453
+ '0x13210D4Fe0d5402bd7Ecbc4B5bC5cFcA3b71adB0',
454
+ '0x2e8f4bdbe3d47d7d7de490437aea9915d930f1a3', // USDP
455
+ '0xfdb93b3b10936cf81fa59a02a7523b6e2149b2b7',
456
+ '0xA361718326c15715591c299427c62086F69923D9', // BUSD
457
+ '0xbA429f7011c9fa04cDd46a2Da24dc0FF0aC6099c',
458
+ '0xd4937682df3C8aEF4FE912A96A74121C0829E664', // FRAX
459
+ '0xfE8F19B17fFeF0fDbfe2671F248903055AFAA8Ca',
460
+ '0x683923dB55Fead99A79Fa01A27EeC3cB19679cC3', // FEI
461
+ '0xC2e10006AccAb7B45D9184FcF5b7EC7763f5BaAe',
462
+ '0x8dAE6Cb04688C62d939ed9B68d32Bc62e49970b1', // CRV
463
+ '0x00ad8eBF64F141f1C81e9f8f792d3d1631c6c684',
464
+ '0x6F634c6135D2EBD550000ac92F494F9CB8183dAe', // DPI
465
+ '0x4dDff5885a67E4EffeC55875a3977D7E60F82ae0',
466
+ ];
467
+ const fetchYearlyMeritApyForStakingGho = () => __awaiter(void 0, void 0, void 0, function* () {
468
+ var _a, _b;
469
+ try {
470
+ const response = yield fetch('https://apps.aavechan.com/api/merit/aprs', { signal: AbortSignal.timeout(5000) });
471
+ const data = yield response.json();
472
+ const apr = ((_b = (_a = data === null || data === void 0 ? void 0 : data.currentAPR) === null || _a === void 0 ? void 0 : _a.actionsAPR) === null || _b === void 0 ? void 0 : _b['ethereum-stkgho']) || '0';
473
+ const apy = (0, moneymarket_1.aprToApy)(apr);
474
+ const apyWithDFSBonus = new decimal_js_1.default(apy).mul(1.05).toString(); // 5% bonus for DFS users
475
+ return apyWithDFSBonus;
476
+ }
477
+ catch (e) {
478
+ const message = 'External API Failure: Failed to fetch yearly merit APY for staking GHO';
479
+ console.error(message, e);
480
+ return '0';
481
+ }
482
+ });
483
+ exports.fetchYearlyMeritApyForStakingGho = fetchYearlyMeritApyForStakingGho;
484
+ const getStakeAaveData = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () {
485
+ const stkGhoAddress = (0, tokens_1.getAssetInfo)('stkGHO').address;
486
+ const stkAaveAddress = (0, tokens_1.getAssetInfo)('stkAAVE').address;
487
+ const AaveIncentivesController = (0, contracts_1.AaveIncentivesControllerViem)(provider, network);
488
+ const stkAAVE = (0, contracts_1.StkAAVEViem)(provider, network);
489
+ const stkGHO = (0, contracts_1.createViemContractFromConfigFunc)('Erc20', stkGhoAddress)(provider, network);
490
+ const [aaveRewardsBalance, emissionsPerSecond, stkAAVEBalance, stkAAVETotalSupply, stkGHOBalance, ghoMeritApy] = yield Promise.all([
491
+ AaveIncentivesController.read.getRewardsBalance([exports.REWARDABLE_ASSETS, address]),
492
+ stkAAVE.read.assets([stkAaveAddress]),
493
+ stkAAVE.read.balanceOf([address]),
494
+ stkAAVE.read.totalSupply(),
495
+ stkGHO.read.balanceOf([address]),
496
+ (0, exports.fetchYearlyMeritApyForStakingGho)(),
497
+ ]);
498
+ const stkAaveApy = new decimal_js_1.default((0, tokens_1.assetAmountInEth)(emissionsPerSecond[0].toString(), 'GHO') || 0).mul(constants_1.SECONDS_PER_YEAR).mul(100).div((0, tokens_1.assetAmountInEth)(stkAAVETotalSupply.toString(), 'stkAAVE'))
499
+ .toString();
500
+ return {
501
+ activatedCooldown: '0',
502
+ activatedCooldownAmount: '0',
503
+ stkAaveRewardsBalance: '0',
504
+ aaveRewardsBalance: (0, tokens_1.assetAmountInEth)(aaveRewardsBalance.toString(), 'AAVE'),
505
+ stkAaveBalance: (0, tokens_1.assetAmountInEth)(stkAAVEBalance.toString(), 'stkAAVE'),
506
+ stkGhoBalance: (0, tokens_1.assetAmountInEth)(stkGHOBalance.toString(), 'GHO'),
507
+ ghoMeritApy,
508
+ stkAaveApy,
509
+ };
510
+ });
511
+ exports.getStakeAaveData = getStakeAaveData;
@@ -0,0 +1,9 @@
1
+ import { Client } from 'viem';
2
+ import { EthAddress, NetworkNumber } from '../types/common';
3
+ import { ClaimableToken } from '../types/claiming';
4
+ /**
5
+ * won't cover all cases
6
+ */
7
+ export declare const getAaveUnderlyingSymbol: (_symbol?: string) => any;
8
+ export declare function getUnclaimedRewardsForAllMarkets(provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress): Promise<ClaimableToken[]>;
9
+ export declare function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber, acceptMorpho?: boolean): Promise<ClaimableToken[]>;
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getAaveUnderlyingSymbol = void 0;
16
+ exports.getUnclaimedRewardsForAllMarkets = getUnclaimedRewardsForAllMarkets;
17
+ exports.getMeritUnclaimedRewards = getMeritUnclaimedRewards;
18
+ const decimal_js_1 = __importDefault(require("decimal.js"));
19
+ const claiming_1 = require("../types/claiming");
20
+ const contracts_1 = require("../contracts");
21
+ const utils_1 = require("../services/utils");
22
+ /**
23
+ * won't cover all cases
24
+ */
25
+ const getAaveUnderlyingSymbol = (_symbol = '') => {
26
+ let symbol = _symbol
27
+ .replace(/^aEthLido/, '')
28
+ .replace(/^aEthEtherFi/, '')
29
+ .replace(/^aEth/, '')
30
+ .replace(/^aArb/, '')
31
+ .replace(/^aOpt/, '')
32
+ .replace(/^aBas/, '');
33
+ if (symbol.startsWith('a'))
34
+ symbol = symbol.slice(1);
35
+ return (0, utils_1.wethToEth)(symbol);
36
+ };
37
+ exports.getAaveUnderlyingSymbol = getAaveUnderlyingSymbol;
38
+ const mapAaveRewardsToClaimableTokens = (aaveRewards, marketAddress, walletAddress) => aaveRewards.map(reward => ({
39
+ symbol: reward.symbol,
40
+ amount: reward.amount,
41
+ claimType: claiming_1.ClaimType.AAVE_REWARDS,
42
+ tokenAddress: reward.rewardTokenAddress,
43
+ underlyingSymbol: reward.underlyingAsset,
44
+ walletAddress,
45
+ label: 'AAVE Rewards',
46
+ additionalClaimFields: {
47
+ marketAddress,
48
+ aTokenAddresses: reward.aTokenAddresses,
49
+ isAaveToken: reward.symbol.startsWith('a'),
50
+ },
51
+ }));
52
+ function getUnclaimedRewardsForAllMarkets(provider, network, walletAddress, marketAddress) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const contract = (0, contracts_1.AaveIncentiveDataProviderV3ContractViem)(provider, network);
55
+ const tokensData = yield contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
56
+ const allTokensDataArrays = tokensData.reduce((acc, val) => {
57
+ acc.push(val.aTokenIncentivesUserData.userRewardsInformation);
58
+ acc.push(val.vTokenIncentivesUserData.userRewardsInformation);
59
+ return acc;
60
+ }, []);
61
+ const allATokens = tokensData.reduce((acc, val) => {
62
+ acc.push(val.aTokenIncentivesUserData.tokenAddress);
63
+ acc.push(val.vTokenIncentivesUserData.tokenAddress);
64
+ return acc;
65
+ }, []);
66
+ // array of rewards for each market (aToken/vToken)
67
+ // reward can be any token like wstETH, but also aToken like aWETH
68
+ const aaveRewardsController = (0, contracts_1.AaveRewardsControllerViem)(provider, network);
69
+ const rewardsPerAAsset = yield Promise.all(allATokens.map((token) => aaveRewardsController.read.getAllUserRewards([[token], walletAddress])));
70
+ // match amounts to token symbol, parse decimal amounts
71
+ const rewardsPerAAssetWithInfo = rewardsPerAAsset.map((rewardForAAsset, aaIndex) => {
72
+ const rewardsList = rewardForAAsset[0];
73
+ const amounts = rewardForAAsset[1];
74
+ const rewardsDataArraysForAAsset = allTokensDataArrays[aaIndex];
75
+ const aTokenAddress = allATokens[aaIndex];
76
+ return rewardsList.map((rewardTokenAddress, rewardIndex) => {
77
+ var _a, _b;
78
+ const dataArrIndex = rewardsDataArraysForAAsset.findIndex((arr) => (0, utils_1.compareAddresses)(arr.rewardTokenAddress, rewardTokenAddress));
79
+ const amountWei = amounts[rewardIndex];
80
+ const amount = (0, utils_1.getEthAmountForDecimals)(amountWei.toString(), (_a = rewardsDataArraysForAAsset[dataArrIndex]) === null || _a === void 0 ? void 0 : _a.rewardTokenDecimals);
81
+ const symbol = ((_b = rewardsDataArraysForAAsset[dataArrIndex]) === null || _b === void 0 ? void 0 : _b.rewardTokenSymbol) || '';
82
+ const underlyingAsset = (0, exports.getAaveUnderlyingSymbol)(symbol);
83
+ return ({
84
+ amount,
85
+ symbol,
86
+ underlyingAsset,
87
+ rewardTokenAddress,
88
+ aTokenAddress,
89
+ });
90
+ });
91
+ });
92
+ // sum all unclaimed rewards of all markets per each token
93
+ // (e.g. how much awstETH is claimable in total from both aUSDC and awstETH markets)
94
+ const totalUnclaimedPerRewardToken = {};
95
+ rewardsPerAAssetWithInfo
96
+ .flat()
97
+ .forEach(({ amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddress, }) => {
98
+ if (+amount > 0) {
99
+ if (!totalUnclaimedPerRewardToken[symbol]) {
100
+ totalUnclaimedPerRewardToken[symbol] = {
101
+ amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddresses: [aTokenAddress],
102
+ };
103
+ }
104
+ else {
105
+ totalUnclaimedPerRewardToken[symbol].amount =
106
+ new decimal_js_1.default(totalUnclaimedPerRewardToken[symbol].amount).add(amount).toString();
107
+ totalUnclaimedPerRewardToken[symbol].aTokenAddresses.push(aTokenAddress);
108
+ }
109
+ }
110
+ }, []);
111
+ return mapAaveRewardsToClaimableTokens(Object.values(totalUnclaimedPerRewardToken), marketAddress, walletAddress);
112
+ });
113
+ }
114
+ function getMeritUnclaimedRewards(account_1, network_1) {
115
+ return __awaiter(this, arguments, void 0, function* (account, network, acceptMorpho = true) {
116
+ const res = yield fetch(`https://api.merkl.xyz/v4/users/${account}/rewards?chainId=${network}`, { signal: AbortSignal.timeout(3000) });
117
+ const data = yield res.json();
118
+ const claimableTokens = [];
119
+ data.forEach((item) => {
120
+ item.rewards.forEach(reward => {
121
+ const { token, amount, claimed, proofs, } = reward;
122
+ const isTokenMorpho = token.symbol === 'MORPHO';
123
+ if (!token || !token.symbol || amount === '0' || (isTokenMorpho && !acceptMorpho))
124
+ return;
125
+ const unclaimedAmount = new decimal_js_1.default(amount).minus(claimed || 0).toString();
126
+ if (unclaimedAmount === '0')
127
+ return;
128
+ const unclaimed = (0, utils_1.getEthAmountForDecimals)(unclaimedAmount, token.decimals);
129
+ claimableTokens.push({
130
+ claimType: claiming_1.ClaimType.AAVE_MERIT_REWARDS,
131
+ amount: unclaimed,
132
+ symbol: token.symbol,
133
+ tokenAddress: token.address,
134
+ walletAddress: account,
135
+ label: 'AAVE Merit Rewards',
136
+ underlyingSymbol: (0, exports.getAaveUnderlyingSymbol)(token.symbol),
137
+ additionalClaimFields: {
138
+ accumulated: amount,
139
+ proof: proofs,
140
+ decimals: token.decimals,
141
+ unclaimed: unclaimedAmount,
142
+ },
143
+ });
144
+ });
145
+ });
146
+ return claimableTokens;
147
+ });
148
+ }
@@ -0,0 +1,15 @@
1
+ import { Client } from 'viem';
2
+ import { EthAddress, NetworkNumber } from '../types/common';
3
+ import { ClaimType } from '../types/claiming';
4
+ export declare const getCompoundV3Rewards: (provider: Client, network: NetworkNumber, user: EthAddress, market: any) => Promise<{
5
+ symbol: string;
6
+ underlyingSymbol: string;
7
+ tokenAddress: `0x${string}`;
8
+ amount: string;
9
+ walletAddress: `0x${string}`;
10
+ label: string;
11
+ claimType: ClaimType;
12
+ additionalClaimFields: {
13
+ marketAddress: any;
14
+ };
15
+ }[]>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getCompoundV3Rewards = void 0;
13
+ const tokens_1 = require("@defisaver/tokens");
14
+ const contracts_1 = require("../contracts");
15
+ const claiming_1 = require("../types/claiming");
16
+ const getCompoundV3Rewards = (provider, network, user, market) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const compV3View = (0, contracts_1.CompV3ViewContractViem)(provider, network);
18
+ const rewards = yield compV3View.read.getRewardsOwed([market, user]);
19
+ if (!rewards || rewards.owed.toString() === '0' || (0, tokens_1.getAssetInfoByAddress)(rewards.token, network).symbol !== 'COMP')
20
+ return [];
21
+ return [{
22
+ symbol: 'COMP',
23
+ underlyingSymbol: 'COMP',
24
+ tokenAddress: rewards.token,
25
+ amount: (0, tokens_1.assetAmountInEth)(rewards.owed.toString() || 0, 'COMP'),
26
+ walletAddress: user,
27
+ label: 'Compound V3',
28
+ claimType: claiming_1.ClaimType.COMPOUND_V3_COMP,
29
+ additionalClaimFields: {
30
+ marketAddress: market,
31
+ },
32
+ }];
33
+ });
34
+ exports.getCompoundV3Rewards = getCompoundV3Rewards;
@@ -0,0 +1,6 @@
1
+ import * as aaveV3Claim from './aaveV3';
2
+ import * as compV3Claim from './compV3';
3
+ import * as kingV3Claim from './king';
4
+ import * as morphoBlueClaim from './morphoBlue';
5
+ import * as sparkClaim from './spark';
6
+ export { aaveV3Claim, compV3Claim, kingV3Claim, morphoBlueClaim, sparkClaim, };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.sparkClaim = exports.morphoBlueClaim = exports.kingV3Claim = exports.compV3Claim = exports.aaveV3Claim = void 0;
37
+ const aaveV3Claim = __importStar(require("./aaveV3"));
38
+ exports.aaveV3Claim = aaveV3Claim;
39
+ const compV3Claim = __importStar(require("./compV3"));
40
+ exports.compV3Claim = compV3Claim;
41
+ const kingV3Claim = __importStar(require("./king"));
42
+ exports.kingV3Claim = kingV3Claim;
43
+ const morphoBlueClaim = __importStar(require("./morphoBlue"));
44
+ exports.morphoBlueClaim = morphoBlueClaim;
45
+ const sparkClaim = __importStar(require("./spark"));
46
+ exports.sparkClaim = sparkClaim;
@@ -0,0 +1,4 @@
1
+ import { Client } from 'viem';
2
+ import { EthAddress, NetworkNumber } from '../types/common';
3
+ export declare const fetchKingRewards: (walletAddress: EthAddress) => Promise<any>;
4
+ export declare const getKingRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, any[]>>;