@defisaver/positions-sdk 2.1.161-portfolio-api-1-dev → 2.1.161-portfolio-api-3-dev
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.
- package/cjs/aaveV2/index.js +2 -0
- package/cjs/aaveV3/index.d.ts +41 -12
- package/cjs/aaveV3/index.js +237 -2
- package/cjs/aaveV3/sgho.d.ts +2 -16
- package/cjs/aaveV4/lend.d.ts +2 -43
- package/cjs/claiming/aaveV3.d.ts +2 -2
- package/cjs/claiming/ethena.d.ts +2 -1
- package/cjs/claiming/king.d.ts +2 -1
- package/cjs/claiming/spark.d.ts +2 -2
- package/cjs/curveUsd/index.d.ts +5 -2
- package/cjs/curveUsd/index.js +30 -15
- package/cjs/fluid/index.d.ts +10 -49
- package/cjs/fluid/index.js +36 -1
- package/cjs/helpers/aaveHelpers/index.d.ts +9 -1
- package/cjs/helpers/aaveHelpers/index.js +26 -6
- package/cjs/helpers/aaveV4Helpers/index.js +1 -0
- package/cjs/helpers/compoundHelpers/index.js +2 -0
- package/cjs/helpers/curveUsdHelpers/index.d.ts +3 -1
- package/cjs/helpers/curveUsdHelpers/index.js +15 -2
- package/cjs/helpers/fluidHelpers/index.js +1 -0
- package/cjs/helpers/liquityV2Helpers/index.js +1 -0
- package/cjs/helpers/llamaLendHelpers/index.js +1 -0
- package/cjs/helpers/makerHelpers/index.d.ts +1 -1
- package/cjs/helpers/makerHelpers/index.js +2 -2
- package/cjs/helpers/morphoBlueHelpers/index.js +2 -0
- package/cjs/helpers/morphoMidnightHelpers/index.js +2 -0
- package/cjs/helpers/sparkHelpers/index.js +1 -0
- package/cjs/liquity/index.d.ts +2 -12
- package/cjs/liquity/index.js +15 -2
- package/cjs/liquityV2/index.d.ts +8 -23
- package/cjs/liquityV2/index.js +37 -19
- package/cjs/maker/index.d.ts +7 -2
- package/cjs/maker/index.js +44 -12
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +3 -1
- package/cjs/markets/maker/index.d.ts +1 -0
- package/cjs/markets/maker/index.js +13 -0
- package/cjs/moneymarket/moneymarketCommonService.d.ts +9 -0
- package/cjs/moneymarket/moneymarketCommonService.js +13 -1
- package/cjs/portfolio/index.d.ts +17 -5
- package/cjs/portfolio/index.js +583 -381
- package/cjs/portfolio/lendingProtocols.d.ts +184 -0
- package/cjs/portfolio/lendingProtocols.js +196 -0
- package/cjs/savings/index.d.ts +8 -2
- package/cjs/savings/index.js +37 -5
- package/cjs/savings/morphoVaults/index.d.ts +1 -1
- package/cjs/savings/morphoVaults/index.js +56 -18
- package/cjs/savings/morphoVaults/options.d.ts +2 -0
- package/cjs/savings/morphoVaults/options.js +61 -1
- package/cjs/spark/index.js +1 -0
- package/cjs/staking/staking.d.ts +20 -0
- package/cjs/staking/staking.js +19 -1
- package/cjs/types/aave.d.ts +86 -0
- package/cjs/types/aaveV4.d.ts +45 -0
- package/cjs/types/compound.d.ts +2 -0
- package/cjs/types/curveUsd.d.ts +6 -0
- package/cjs/types/fluid.d.ts +14 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/liquity.d.ts +16 -0
- package/cjs/types/liquityV2.d.ts +26 -0
- package/cjs/types/maker.d.ts +4 -0
- package/cjs/types/morphoBlue.d.ts +2 -0
- package/cjs/types/morphoMidnight.d.ts +1 -0
- package/cjs/types/portfolio.d.ts +127 -6
- package/cjs/types/savings/index.d.ts +9 -1
- package/cjs/types/savings/morphoVaults.d.ts +10 -2
- package/cjs/types/savings/morphoVaults.js +9 -1
- package/cjs/types/spark.d.ts +2 -0
- package/cjs/umbrella/index.d.ts +2 -3
- package/esm/aaveV2/index.js +2 -0
- package/esm/aaveV3/index.d.ts +41 -12
- package/esm/aaveV3/index.js +231 -2
- package/esm/aaveV3/sgho.d.ts +2 -16
- package/esm/aaveV4/lend.d.ts +2 -43
- package/esm/claiming/aaveV3.d.ts +2 -2
- package/esm/claiming/aaveV3.js +1 -1
- package/esm/claiming/ethena.d.ts +2 -1
- package/esm/claiming/king.d.ts +2 -1
- package/esm/claiming/spark.d.ts +2 -2
- package/esm/claiming/spark.js +1 -1
- package/esm/curveUsd/index.d.ts +5 -2
- package/esm/curveUsd/index.js +30 -15
- package/esm/fluid/index.d.ts +10 -49
- package/esm/fluid/index.js +33 -0
- package/esm/helpers/aaveHelpers/index.d.ts +9 -1
- package/esm/helpers/aaveHelpers/index.js +23 -5
- package/esm/helpers/aaveV4Helpers/index.js +1 -0
- package/esm/helpers/compoundHelpers/index.js +2 -0
- package/esm/helpers/curveUsdHelpers/index.d.ts +3 -1
- package/esm/helpers/curveUsdHelpers/index.js +16 -3
- package/esm/helpers/fluidHelpers/index.js +1 -0
- package/esm/helpers/liquityV2Helpers/index.js +1 -0
- package/esm/helpers/llamaLendHelpers/index.js +2 -1
- package/esm/helpers/makerHelpers/index.d.ts +1 -1
- package/esm/helpers/makerHelpers/index.js +2 -2
- package/esm/helpers/morphoBlueHelpers/index.js +2 -0
- package/esm/helpers/morphoMidnightHelpers/index.js +2 -0
- package/esm/helpers/sparkHelpers/index.js +1 -0
- package/esm/liquity/index.d.ts +2 -12
- package/esm/liquity/index.js +16 -3
- package/esm/liquityV2/index.d.ts +8 -23
- package/esm/liquityV2/index.js +35 -18
- package/esm/maker/index.d.ts +7 -2
- package/esm/maker/index.js +44 -14
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/markets/maker/index.d.ts +1 -0
- package/esm/markets/maker/index.js +10 -0
- package/esm/moneymarket/moneymarketCommonService.d.ts +9 -0
- package/esm/moneymarket/moneymarketCommonService.js +11 -0
- package/esm/portfolio/index.d.ts +17 -5
- package/esm/portfolio/index.js +584 -385
- package/esm/portfolio/lendingProtocols.d.ts +184 -0
- package/esm/portfolio/lendingProtocols.js +189 -0
- package/esm/savings/index.d.ts +8 -2
- package/esm/savings/index.js +35 -4
- package/esm/savings/morphoVaults/index.d.ts +1 -1
- package/esm/savings/morphoVaults/index.js +57 -19
- package/esm/savings/morphoVaults/options.d.ts +2 -0
- package/esm/savings/morphoVaults/options.js +61 -1
- package/esm/spark/index.js +1 -0
- package/esm/staking/staking.d.ts +20 -0
- package/esm/staking/staking.js +17 -0
- package/esm/types/aave.d.ts +86 -0
- package/esm/types/aaveV4.d.ts +45 -0
- package/esm/types/compound.d.ts +2 -0
- package/esm/types/curveUsd.d.ts +6 -0
- package/esm/types/fluid.d.ts +14 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/liquity.d.ts +16 -0
- package/esm/types/liquityV2.d.ts +26 -0
- package/esm/types/maker.d.ts +4 -0
- package/esm/types/morphoBlue.d.ts +2 -0
- package/esm/types/morphoMidnight.d.ts +1 -0
- package/esm/types/portfolio.d.ts +127 -6
- package/esm/types/savings/index.d.ts +9 -1
- package/esm/types/savings/morphoVaults.d.ts +10 -2
- package/esm/types/savings/morphoVaults.js +8 -0
- package/esm/types/spark.d.ts +2 -0
- package/esm/umbrella/index.d.ts +2 -3
- package/package.json +3 -2
- package/src/aaveV2/index.ts +2 -0
- package/src/aaveV3/index.ts +293 -2
- package/src/aaveV3/sgho.ts +2 -17
- package/src/aaveV4/lend.ts +2 -48
- package/src/claiming/aaveV3.ts +4 -2
- package/src/claiming/ethena.ts +5 -5
- package/src/claiming/king.ts +3 -3
- package/src/claiming/spark.ts +6 -4
- package/src/curveUsd/index.ts +33 -16
- package/src/fluid/index.ts +44 -3
- package/src/helpers/aaveHelpers/index.ts +27 -7
- package/src/helpers/aaveV4Helpers/index.ts +1 -0
- package/src/helpers/compoundHelpers/index.ts +2 -0
- package/src/helpers/curveUsdHelpers/index.ts +23 -3
- package/src/helpers/fluidHelpers/index.ts +1 -0
- package/src/helpers/liquityV2Helpers/index.ts +1 -0
- package/src/helpers/llamaLendHelpers/index.ts +2 -1
- package/src/helpers/makerHelpers/index.ts +2 -1
- package/src/helpers/morphoBlueHelpers/index.ts +2 -0
- package/src/helpers/morphoMidnightHelpers/index.ts +2 -0
- package/src/helpers/sparkHelpers/index.ts +1 -0
- package/src/liquity/index.ts +19 -5
- package/src/liquityV2/index.ts +48 -22
- package/src/maker/index.ts +77 -30
- package/src/markets/index.ts +2 -1
- package/src/markets/maker/index.ts +10 -0
- package/src/moneymarket/moneymarketCommonService.ts +15 -0
- package/src/portfolio/index.ts +477 -248
- package/src/portfolio/lendingProtocols.ts +281 -0
- package/src/savings/index.ts +45 -5
- package/src/savings/morphoVaults/index.ts +73 -21
- package/src/savings/morphoVaults/options.ts +67 -1
- package/src/spark/index.ts +1 -0
- package/src/staking/staking.ts +28 -0
- package/src/types/aave.ts +90 -0
- package/src/types/aaveV4.ts +50 -0
- package/src/types/compound.ts +2 -0
- package/src/types/curveUsd.ts +7 -0
- package/src/types/fluid.ts +15 -0
- package/src/types/index.ts +2 -1
- package/src/types/liquity.ts +19 -1
- package/src/types/liquityV2.ts +28 -1
- package/src/types/maker.ts +6 -0
- package/src/types/morphoBlue.ts +2 -0
- package/src/types/morphoMidnight.ts +1 -0
- package/src/types/portfolio.ts +153 -7
- package/src/types/savings/index.ts +12 -1
- package/src/types/savings/morphoVaults.ts +11 -1
- package/src/types/spark.ts +2 -0
- package/src/umbrella/index.ts +2 -1
package/cjs/aaveV2/index.js
CHANGED
|
@@ -177,6 +177,8 @@ const _getAaveV2AccountData = (provider, network, address, assetsData, market) =
|
|
|
177
177
|
payload.collRatio = payload.borrowedUsd && payload.borrowedUsd !== '0'
|
|
178
178
|
? new decimal_js_1.default(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString()
|
|
179
179
|
: '0';
|
|
180
|
+
// Aave v2 has no LTV-0 fallback (AaveV3View only), so its safety ratio is the plain ratio.
|
|
181
|
+
payload.safetyRatio = payload.ratio;
|
|
180
182
|
// Calculate borrow limits per asset
|
|
181
183
|
Object.values(payload.usedAssets).forEach((item) => {
|
|
182
184
|
if (item.isBorrowed) {
|
package/cjs/aaveV3/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
|
-
import { AaveMarketInfo, AaveV3MarketData, AaveV3PositionData, AaveV3UsedAssets, EModeCategoryDataMapping } from '../types';
|
|
2
|
+
import { AaveMarketInfo, AaveV3MarketData, AaveV3PositionData, AaveV3UsedAssets, EModeCategoryDataMapping, StakeAaveData } from '../types';
|
|
3
3
|
import { Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances } from '../types/common';
|
|
4
4
|
import { getMeritCampaigns } from './merit';
|
|
5
5
|
import { getMerkleCampaigns } from './merkl';
|
|
@@ -32,22 +32,51 @@ export declare const EMPTY_AAVE_DATA: {
|
|
|
32
32
|
};
|
|
33
33
|
export declare const _getAaveV3AccountBalances: (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
34
34
|
export declare const getAaveV3AccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
35
|
+
export interface AaveV3ReserveTokenAddresses {
|
|
36
|
+
[symbol: string]: {
|
|
37
|
+
symbol: string;
|
|
38
|
+
underlyingAddress: EthAddress;
|
|
39
|
+
aTokenAddress: EthAddress;
|
|
40
|
+
stableDebtTokenAddress: EthAddress;
|
|
41
|
+
variableDebtTokenAddress: EthAddress;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface AaveV3HistoricalBalance {
|
|
45
|
+
block: number;
|
|
46
|
+
suppliedUsd: string;
|
|
47
|
+
borrowedUsd: string;
|
|
48
|
+
netUsd: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Fetches the aToken / stable-debt / variable-debt token addresses for every asset in the market.
|
|
52
|
+
* These are effectively immutable per reserve, so fetch once and reuse across all history points.
|
|
53
|
+
*/
|
|
54
|
+
export declare const _getAaveV3ReserveTokenAddresses: (provider: Client, network: NetworkNumber, market: AaveMarketInfo) => Promise<AaveV3ReserveTokenAddresses>;
|
|
55
|
+
export declare const getAaveV3ReserveTokenAddresses: (provider: EthereumProvider, network: NetworkNumber, market: AaveMarketInfo) => Promise<AaveV3ReserveTokenAddresses>;
|
|
56
|
+
/**
|
|
57
|
+
* Resolves the price oracle the market's addresses provider points at (at `block`, or latest).
|
|
58
|
+
* Aave can rotate the oracle over time, so a caller hoisting one address across many historical
|
|
59
|
+
* points must resolve it at both ends of its block range and only reuse it when the two agree —
|
|
60
|
+
* otherwise leave `oracleAddress` unset on _getAaveV3HistoricalBalance and it resolves per block.
|
|
61
|
+
*/
|
|
62
|
+
export declare const _getAaveV3OracleAddress: (provider: Client, network: NetworkNumber, market: AaveMarketInfo, block?: Blockish) => Promise<EthAddress>;
|
|
63
|
+
export declare const getAaveV3OracleAddress: (provider: EthereumProvider, network: NetworkNumber, market: AaveMarketInfo, block?: Blockish) => Promise<EthAddress>;
|
|
64
|
+
/**
|
|
65
|
+
* Computes a user's Aave v3 net USD balance (supplied collateral - borrowed debt) at a historical block,
|
|
66
|
+
* without touching the AaveV3View contract. Pass `reserveTokens` (from getAaveV3ReserveTokenAddresses)
|
|
67
|
+
* to avoid refetching token addresses for every point, and `oracleAddress` (from getAaveV3OracleAddress,
|
|
68
|
+
* verified identical at both ends of the sampled range) to collapse the point into a single multicall —
|
|
69
|
+
* with it the balances and all prices ride one request; without it the oracle is resolved at the block
|
|
70
|
+
* inside the balance multicall and the active assets are priced in a second one.
|
|
71
|
+
*/
|
|
72
|
+
export declare const _getAaveV3HistoricalBalance: (provider: Client, network: NetworkNumber, market: AaveMarketInfo, address: EthAddress, block: number, reserveTokens?: AaveV3ReserveTokenAddresses, oracleAddress?: EthAddress) => Promise<AaveV3HistoricalBalance>;
|
|
73
|
+
export declare const getAaveV3HistoricalBalance: (provider: EthereumProvider, network: NetworkNumber, market: AaveMarketInfo, address: EthAddress, block: number, reserveTokens?: AaveV3ReserveTokenAddresses, oracleAddress?: EthAddress) => Promise<AaveV3HistoricalBalance>;
|
|
35
74
|
export declare const _getAaveV3AccountData: (provider: Client, network: NetworkNumber, address: EthAddress, extractedState: any, blockNumber?: "latest" | number) => Promise<AaveV3PositionData>;
|
|
36
75
|
export declare const getAaveV3AccountData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, extractedState: any, blockNumber?: "latest" | number) => Promise<AaveV3PositionData>;
|
|
37
76
|
export declare const getAaveV3FullPositionData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, market: AaveMarketInfo) => Promise<AaveV3PositionData>;
|
|
38
77
|
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"];
|
|
39
78
|
export declare const fetchYearlyMeritApyForStakingGho: () => Promise<string>;
|
|
40
|
-
export declare const getStakeAaveData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<
|
|
41
|
-
activatedCooldown: string;
|
|
42
|
-
activatedCooldownAmount: string;
|
|
43
|
-
stkAaveRewardsBalance: string;
|
|
44
|
-
aaveRewardsBalance: string;
|
|
45
|
-
stkAaveBalance: string;
|
|
46
|
-
stkGhoBalance: string;
|
|
47
|
-
ghoMeritApy: string;
|
|
48
|
-
stkAaveApy: string;
|
|
49
|
-
sgho: import("./sgho").SghoData;
|
|
50
|
-
}>;
|
|
79
|
+
export declare const getStakeAaveData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<StakeAaveData>;
|
|
51
80
|
export { getMeritCampaigns, getMerkleCampaigns, };
|
|
52
81
|
export { getSghoData } from './sgho';
|
|
53
82
|
export type { SghoData, SghoUserData } from './sgho';
|
package/cjs/aaveV3/index.js
CHANGED
|
@@ -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.getSghoData = exports.getMerkleCampaigns = exports.getMeritCampaigns = 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;
|
|
15
|
+
exports.getSghoData = exports.getMerkleCampaigns = exports.getMeritCampaigns = exports.getStakeAaveData = exports.fetchYearlyMeritApyForStakingGho = exports.REWARDABLE_ASSETS = exports.getAaveV3FullPositionData = exports.getAaveV3AccountData = exports._getAaveV3AccountData = exports.getAaveV3HistoricalBalance = exports._getAaveV3HistoricalBalance = exports.getAaveV3OracleAddress = exports._getAaveV3OracleAddress = exports.getAaveV3ReserveTokenAddresses = exports._getAaveV3ReserveTokenAddresses = 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");
|
|
@@ -41,7 +41,10 @@ const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
|
41
41
|
: !usedAssetsValues.filter(u => u.isBorrowed && !e.borrowAssets.includes(u.symbol)).length;
|
|
42
42
|
const afterEnteringCategory = (0, aaveHelpers_1.aaveAnyGetAggregatedPositionData)(Object.assign(Object.assign({}, extractedState), { usedAssets, eModeCategory: e.id }));
|
|
43
43
|
const willStayOverCollateralized = new decimal_js_1.default(afterEnteringCategory.ratio === 'NaN' ? '0' : afterEnteringCategory.ratio).eq(0) || new decimal_js_1.default(afterEnteringCategory.ratio).gt(afterEnteringCategory.liqPercent);
|
|
44
|
-
const
|
|
44
|
+
const collateralOnlyFromCategory = e.id === 0 || !e.isolated
|
|
45
|
+
? true
|
|
46
|
+
: !usedAssetsValues.filter(u => u.isSupplied && u.collateral && !e.collateralAssets.includes(u.symbol)).length;
|
|
47
|
+
const enteringTerms = [borrowingOnlyFromCategory, willStayOverCollateralized, collateralOnlyFromCategory];
|
|
45
48
|
categoriesMapping[e.id] = {
|
|
46
49
|
enteringTerms,
|
|
47
50
|
canEnterCategory: !enteringTerms.includes(false),
|
|
@@ -59,6 +62,7 @@ const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
|
59
62
|
exports.aaveV3EmodeCategoriesMapping = aaveV3EmodeCategoriesMapping;
|
|
60
63
|
function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
61
64
|
return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
|
|
65
|
+
var _a;
|
|
62
66
|
const _addresses = market.assets.map(a => (0, tokens_1.getAssetInfo)((0, utils_1.getWrappedNativeAssetFromUnwrapped)(a), network).address);
|
|
63
67
|
const loanInfoContract = (0, contracts_1.AaveV3ViewContractViem)(provider, network);
|
|
64
68
|
const aaveIncentivesContract = (0, contracts_1.AaveIncentiveDataProviderV3ContractViem)(provider, network);
|
|
@@ -92,6 +96,7 @@ function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
|
92
96
|
borrowableBitmap: eModesInfo[i].borrowableBitmap.toString(),
|
|
93
97
|
collateralBitmap: eModesInfo[i].collateralBitmap.toString(),
|
|
94
98
|
ltvzeroBitmap: eModesInfo[i].ltvzeroBitmap.toString(),
|
|
99
|
+
isolated: (_a = eModesInfo[i].isolated) !== null && _a !== void 0 ? _a : false,
|
|
95
100
|
borrowAssets: [],
|
|
96
101
|
collateralAssets: [],
|
|
97
102
|
ltvZeroAssets: [],
|
|
@@ -307,6 +312,7 @@ function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
|
307
312
|
collateralAssets: assetsData.map((a) => a.symbol),
|
|
308
313
|
borrowAssets: assetsData.map((a) => a.symbol),
|
|
309
314
|
ltvZeroAssets: [],
|
|
315
|
+
isolated: false,
|
|
310
316
|
};
|
|
311
317
|
return { assetsData: payload, eModeCategoriesData };
|
|
312
318
|
});
|
|
@@ -375,6 +381,235 @@ const _getAaveV3AccountBalances = (provider, network, block, addressMapping, add
|
|
|
375
381
|
exports._getAaveV3AccountBalances = _getAaveV3AccountBalances;
|
|
376
382
|
const getAaveV3AccountBalances = (provider, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () { return (0, exports._getAaveV3AccountBalances)((0, viem_1.getViemProvider)(provider, network), network, block, addressMapping, address); });
|
|
377
383
|
exports.getAaveV3AccountBalances = getAaveV3AccountBalances;
|
|
384
|
+
/**
|
|
385
|
+
* Historical net-balance helpers that bypass the AaveV3View contract.
|
|
386
|
+
*
|
|
387
|
+
* The View contract (and therefore `getAaveV3AccountData` / `getAaveV3AccountBalances`) can only be
|
|
388
|
+
* queried from its deployment block onwards, so it cannot read balances for positions older than that.
|
|
389
|
+
* The aTokens/debt tokens, the ProtocolDataProvider and the Aave price oracle all exist from Aave v3
|
|
390
|
+
* launch, so reading `balanceOf` on those tokens + the oracle price directly reaches much further back
|
|
391
|
+
* and costs ~1 multicall per point. Used to build a position balance-history chart.
|
|
392
|
+
*/
|
|
393
|
+
// matches morphoVaults' batchSize; stays under the 500k portfolio discovery allows on simulation fork RPCs
|
|
394
|
+
const HISTORICAL_MULTICALL_BATCH_SIZE = 250000;
|
|
395
|
+
// Minimal Aave price oracle ABI (getAssetPrice returns the asset price in the market base currency).
|
|
396
|
+
const AAVE_ORACLE_ABI = [
|
|
397
|
+
{
|
|
398
|
+
inputs: [{ internalType: 'address', name: 'asset', type: 'address' }],
|
|
399
|
+
name: 'getAssetPrice',
|
|
400
|
+
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
401
|
+
stateMutability: 'view',
|
|
402
|
+
type: 'function',
|
|
403
|
+
},
|
|
404
|
+
];
|
|
405
|
+
/**
|
|
406
|
+
* Fetches the aToken / stable-debt / variable-debt token addresses for every asset in the market.
|
|
407
|
+
* These are effectively immutable per reserve, so fetch once and reuse across all history points.
|
|
408
|
+
*/
|
|
409
|
+
const _getAaveV3ReserveTokenAddresses = (provider, network, market) => __awaiter(void 0, void 0, void 0, function* () {
|
|
410
|
+
const symbols = market.assets;
|
|
411
|
+
const underlyingAddresses = symbols.map((a) => (0, tokens_1.getAssetInfo)((0, utils_1.getWrappedNativeAssetFromUnwrapped)(a), network).address);
|
|
412
|
+
// @ts-ignore market.protocolData is a valid config key at runtime
|
|
413
|
+
const dataProviderAbi = (0, contracts_1.getConfigContractAbi)(market.protocolData, network);
|
|
414
|
+
const contracts = underlyingAddresses.map((underlying) => ({
|
|
415
|
+
address: market.protocolDataAddress,
|
|
416
|
+
abi: dataProviderAbi,
|
|
417
|
+
functionName: 'getReserveTokensAddresses',
|
|
418
|
+
args: [underlying],
|
|
419
|
+
}));
|
|
420
|
+
// @ts-ignore
|
|
421
|
+
const results = yield provider.multicall({ contracts, allowFailure: true, batchSize: HISTORICAL_MULTICALL_BATCH_SIZE });
|
|
422
|
+
const mapping = {};
|
|
423
|
+
results.forEach((res, i) => {
|
|
424
|
+
if (res.status !== 'success' || !res.result)
|
|
425
|
+
return;
|
|
426
|
+
// outputs order: [aTokenAddress, stableDebtTokenAddress, variableDebtTokenAddress]
|
|
427
|
+
const [aTokenAddress, stableDebtTokenAddress, variableDebtTokenAddress] = res.result;
|
|
428
|
+
mapping[symbols[i]] = {
|
|
429
|
+
symbol: symbols[i],
|
|
430
|
+
underlyingAddress: underlyingAddresses[i],
|
|
431
|
+
aTokenAddress,
|
|
432
|
+
stableDebtTokenAddress,
|
|
433
|
+
variableDebtTokenAddress,
|
|
434
|
+
};
|
|
435
|
+
});
|
|
436
|
+
return mapping;
|
|
437
|
+
});
|
|
438
|
+
exports._getAaveV3ReserveTokenAddresses = _getAaveV3ReserveTokenAddresses;
|
|
439
|
+
const getAaveV3ReserveTokenAddresses = (provider, network, market) => __awaiter(void 0, void 0, void 0, function* () { return (0, exports._getAaveV3ReserveTokenAddresses)((0, viem_1.getViemProvider)(provider, network, { batch: { multicall: true } }), network, market); });
|
|
440
|
+
exports.getAaveV3ReserveTokenAddresses = getAaveV3ReserveTokenAddresses;
|
|
441
|
+
/**
|
|
442
|
+
* Resolves the price oracle the market's addresses provider points at (at `block`, or latest).
|
|
443
|
+
* Aave can rotate the oracle over time, so a caller hoisting one address across many historical
|
|
444
|
+
* points must resolve it at both ends of its block range and only reuse it when the two agree —
|
|
445
|
+
* otherwise leave `oracleAddress` unset on _getAaveV3HistoricalBalance and it resolves per block.
|
|
446
|
+
*/
|
|
447
|
+
const _getAaveV3OracleAddress = (provider_1, network_1, market_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, market_1, ...args_1], void 0, function* (provider, network, market, block = 'latest') {
|
|
448
|
+
// @ts-ignore market.provider is a valid config key at runtime
|
|
449
|
+
const providerAbi = (0, contracts_1.getConfigContractAbi)(market.provider, network);
|
|
450
|
+
// @ts-ignore readContract exists on the public client returned by getViemProvider
|
|
451
|
+
const oracleAddress = yield provider.readContract(Object.assign({ address: market.providerAddress, abi: providerAbi, functionName: 'getPriceOracle' }, (0, viem_1.setViemBlockNumber)(block)));
|
|
452
|
+
if (!oracleAddress)
|
|
453
|
+
throw new Error(`AaveV3 oracle unavailable at block ${block}`);
|
|
454
|
+
return oracleAddress;
|
|
455
|
+
});
|
|
456
|
+
exports._getAaveV3OracleAddress = _getAaveV3OracleAddress;
|
|
457
|
+
const getAaveV3OracleAddress = (provider_1, network_1, market_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, market_1, ...args_1], void 0, function* (provider, network, market, block = 'latest') { return (0, exports._getAaveV3OracleAddress)((0, viem_1.getViemProvider)(provider, network, { batch: { multicall: true } }), network, market, block); });
|
|
458
|
+
exports.getAaveV3OracleAddress = getAaveV3OracleAddress;
|
|
459
|
+
// supply = aToken.balanceOf, debt = variableDebtToken.balanceOf + stableDebtToken.balanceOf — three reads per reserve
|
|
460
|
+
const getHistoricalBalanceContracts = (entries, address) => {
|
|
461
|
+
const erc20Abi = (0, contracts_1.getConfigContractAbi)('Erc20');
|
|
462
|
+
return entries.flatMap((e) => ([
|
|
463
|
+
{
|
|
464
|
+
address: e.aTokenAddress, abi: erc20Abi, functionName: 'balanceOf', args: [address],
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
address: e.variableDebtTokenAddress, abi: erc20Abi, functionName: 'balanceOf', args: [address],
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
address: e.stableDebtTokenAddress, abi: erc20Abi, functionName: 'balanceOf', args: [address],
|
|
471
|
+
},
|
|
472
|
+
]));
|
|
473
|
+
};
|
|
474
|
+
const getAssetPriceContract = (oracle, underlyingAddress) => ({
|
|
475
|
+
address: oracle,
|
|
476
|
+
abi: AAVE_ORACLE_ABI,
|
|
477
|
+
functionName: 'getAssetPrice',
|
|
478
|
+
args: [underlyingAddress],
|
|
479
|
+
});
|
|
480
|
+
/**
|
|
481
|
+
* Pairs each reserve with its three balance reads and keeps the assets the wallet actually held.
|
|
482
|
+
* Throws when every read failed — a totally failed fetch must not masquerade as a real $0 balance,
|
|
483
|
+
* so the caller can distinguish "fetch failed" (gap) from "position was empty" (genuine 0).
|
|
484
|
+
*/
|
|
485
|
+
const toActiveHistoricalAssets = (entries, balanceResults, block) => {
|
|
486
|
+
const anyBalanceRead = balanceResults.some((r) => (r === null || r === void 0 ? void 0 : r.status) === 'success');
|
|
487
|
+
if (!anyBalanceRead)
|
|
488
|
+
throw new Error(`AaveV3 historical balance: all balance reads failed at block ${block}`);
|
|
489
|
+
return entries.map((e, i) => {
|
|
490
|
+
const supplyRes = balanceResults[i * 3];
|
|
491
|
+
const varDebtRes = balanceResults[(i * 3) + 1];
|
|
492
|
+
const stableDebtRes = balanceResults[(i * 3) + 2];
|
|
493
|
+
const supplied = (supplyRes === null || supplyRes === void 0 ? void 0 : supplyRes.status) === 'success' ? supplyRes.result.toString() : '0';
|
|
494
|
+
const varDebt = (varDebtRes === null || varDebtRes === void 0 ? void 0 : varDebtRes.status) === 'success' ? varDebtRes.result.toString() : '0';
|
|
495
|
+
const stableDebt = (stableDebtRes === null || stableDebtRes === void 0 ? void 0 : stableDebtRes.status) === 'success' ? stableDebtRes.result.toString() : '0';
|
|
496
|
+
const debt = new decimal_js_1.default(varDebt).add(stableDebt).toString();
|
|
497
|
+
return Object.assign(Object.assign({}, e), { supplied, debt });
|
|
498
|
+
}).filter((a) => a.supplied !== '0' || a.debt !== '0');
|
|
499
|
+
};
|
|
500
|
+
/**
|
|
501
|
+
* Sums the active assets into the point's USD totals. Throws when every price read failed — the
|
|
502
|
+
* oracle couldn't serve this block (pruned state, or a hoisted oracle that wasn't deployed yet back
|
|
503
|
+
* then), and totalling it up anyway would return a fake near-$0 balance. A single asset's price
|
|
504
|
+
* failure still just skips that asset, matching the live data path.
|
|
505
|
+
*/
|
|
506
|
+
const sumHistoricalUsd = (activeAssets, priceResBySymbol, block) => {
|
|
507
|
+
const anyPriceRead = activeAssets.some((a) => { var _a; return ((_a = priceResBySymbol[a.symbol]) === null || _a === void 0 ? void 0 : _a.status) === 'success'; });
|
|
508
|
+
if (!anyPriceRead)
|
|
509
|
+
throw new Error(`AaveV3 historical balance: all price reads failed at block ${block}`);
|
|
510
|
+
let suppliedUsd = new decimal_js_1.default(0);
|
|
511
|
+
let borrowedUsd = new decimal_js_1.default(0);
|
|
512
|
+
activeAssets.forEach((a) => {
|
|
513
|
+
const priceRes = priceResBySymbol[a.symbol];
|
|
514
|
+
if ((priceRes === null || priceRes === void 0 ? void 0 : priceRes.status) !== 'success')
|
|
515
|
+
return;
|
|
516
|
+
const priceUsd = new decimal_js_1.default(priceRes.result.toString()).div(1e8); // Aave v3 base currency is USD with 8 decimals
|
|
517
|
+
if (a.supplied !== '0')
|
|
518
|
+
suppliedUsd = suppliedUsd.add(new decimal_js_1.default((0, tokens_1.assetAmountInEth)(a.supplied, a.symbol)).mul(priceUsd));
|
|
519
|
+
if (a.debt !== '0')
|
|
520
|
+
borrowedUsd = borrowedUsd.add(new decimal_js_1.default((0, tokens_1.assetAmountInEth)(a.debt, a.symbol)).mul(priceUsd));
|
|
521
|
+
});
|
|
522
|
+
return {
|
|
523
|
+
block,
|
|
524
|
+
suppliedUsd: suppliedUsd.toString(),
|
|
525
|
+
borrowedUsd: borrowedUsd.toString(),
|
|
526
|
+
netUsd: suppliedUsd.minus(borrowedUsd).toString(),
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
/**
|
|
530
|
+
* Fast path, ONE multicall: balances plus a price read for every reserve through the caller-hoisted
|
|
531
|
+
* oracle. Prices are read for all reserves because which assets are active isn't known until the
|
|
532
|
+
* balances come back — extra reads inside an already-paid multicall are nearly free.
|
|
533
|
+
*/
|
|
534
|
+
const fetchHistoricalPointWithOracle = (provider, entries, address, block, oracleAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
535
|
+
const balanceContracts = getHistoricalBalanceContracts(entries, address);
|
|
536
|
+
const priceContracts = entries.map((e) => getAssetPriceContract(oracleAddress, e.underlyingAddress));
|
|
537
|
+
// @ts-ignore
|
|
538
|
+
const results = yield provider.multicall({
|
|
539
|
+
contracts: [...balanceContracts, ...priceContracts], allowFailure: true, blockNumber: BigInt(block), batchSize: HISTORICAL_MULTICALL_BATCH_SIZE,
|
|
540
|
+
});
|
|
541
|
+
const activeAssets = toActiveHistoricalAssets(entries, results.slice(0, balanceContracts.length), block);
|
|
542
|
+
const priceResBySymbol = {};
|
|
543
|
+
results.slice(balanceContracts.length).forEach((res, i) => {
|
|
544
|
+
priceResBySymbol[entries[i].symbol] = res;
|
|
545
|
+
});
|
|
546
|
+
return { activeAssets, priceResBySymbol };
|
|
547
|
+
});
|
|
548
|
+
/**
|
|
549
|
+
* Fallback path, TWO multicalls: balances plus getPriceOracle (resolving the oracle that was active
|
|
550
|
+
* AT the block — Aave can rotate it over time), then prices for just the active assets. The oracle
|
|
551
|
+
* read has no fallback: if it fails (bad archive node, rate limit, ...) the failure must surface
|
|
552
|
+
* rather than silently returning $0 — the caller renders a gap instead of a misleading zero.
|
|
553
|
+
*/
|
|
554
|
+
const fetchHistoricalPointResolvingOracle = (provider, network, market, entries, address, block) => __awaiter(void 0, void 0, void 0, function* () {
|
|
555
|
+
const balanceContracts = getHistoricalBalanceContracts(entries, address);
|
|
556
|
+
// @ts-ignore market.provider is a valid config key at runtime
|
|
557
|
+
const providerAbi = (0, contracts_1.getConfigContractAbi)(market.provider, network);
|
|
558
|
+
const oracleContract = {
|
|
559
|
+
address: market.providerAddress,
|
|
560
|
+
abi: providerAbi,
|
|
561
|
+
functionName: 'getPriceOracle',
|
|
562
|
+
};
|
|
563
|
+
const blockNumber = BigInt(block);
|
|
564
|
+
// @ts-ignore
|
|
565
|
+
const results = yield provider.multicall({
|
|
566
|
+
contracts: [...balanceContracts, oracleContract], allowFailure: true, blockNumber, batchSize: HISTORICAL_MULTICALL_BATCH_SIZE,
|
|
567
|
+
});
|
|
568
|
+
const oracleRes = results[balanceContracts.length];
|
|
569
|
+
if ((oracleRes === null || oracleRes === void 0 ? void 0 : oracleRes.status) !== 'success' || !oracleRes.result)
|
|
570
|
+
throw new Error(`AaveV3 historical balance: oracle unavailable at block ${block}`);
|
|
571
|
+
const activeAssets = toActiveHistoricalAssets(entries, results.slice(0, balanceContracts.length), block);
|
|
572
|
+
if (!activeAssets.length)
|
|
573
|
+
return { activeAssets, priceResBySymbol: {} };
|
|
574
|
+
const priceContracts = activeAssets.map((a) => getAssetPriceContract(oracleRes.result, a.underlyingAddress));
|
|
575
|
+
// @ts-ignore
|
|
576
|
+
const priceResults = yield provider.multicall({
|
|
577
|
+
contracts: priceContracts, allowFailure: true, blockNumber, batchSize: HISTORICAL_MULTICALL_BATCH_SIZE,
|
|
578
|
+
});
|
|
579
|
+
const priceResBySymbol = {};
|
|
580
|
+
priceResults.forEach((res, i) => {
|
|
581
|
+
priceResBySymbol[activeAssets[i].symbol] = res;
|
|
582
|
+
});
|
|
583
|
+
return { activeAssets, priceResBySymbol };
|
|
584
|
+
});
|
|
585
|
+
/**
|
|
586
|
+
* Computes a user's Aave v3 net USD balance (supplied collateral - borrowed debt) at a historical block,
|
|
587
|
+
* without touching the AaveV3View contract. Pass `reserveTokens` (from getAaveV3ReserveTokenAddresses)
|
|
588
|
+
* to avoid refetching token addresses for every point, and `oracleAddress` (from getAaveV3OracleAddress,
|
|
589
|
+
* verified identical at both ends of the sampled range) to collapse the point into a single multicall —
|
|
590
|
+
* with it the balances and all prices ride one request; without it the oracle is resolved at the block
|
|
591
|
+
* inside the balance multicall and the active assets are priced in a second one.
|
|
592
|
+
*/
|
|
593
|
+
const _getAaveV3HistoricalBalance = (provider, network, market, address, block, reserveTokens, oracleAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
594
|
+
const empty = {
|
|
595
|
+
block, suppliedUsd: '0', borrowedUsd: '0', netUsd: '0',
|
|
596
|
+
};
|
|
597
|
+
if (!address)
|
|
598
|
+
return empty;
|
|
599
|
+
const tokens = reserveTokens || (yield (0, exports._getAaveV3ReserveTokenAddresses)(provider, network, market));
|
|
600
|
+
const entries = Object.values(tokens);
|
|
601
|
+
if (!entries.length)
|
|
602
|
+
return empty;
|
|
603
|
+
const { activeAssets, priceResBySymbol } = oracleAddress
|
|
604
|
+
? yield fetchHistoricalPointWithOracle(provider, entries, address, block, oracleAddress)
|
|
605
|
+
: yield fetchHistoricalPointResolvingOracle(provider, network, market, entries, address, block);
|
|
606
|
+
if (!activeAssets.length)
|
|
607
|
+
return empty;
|
|
608
|
+
return sumHistoricalUsd(activeAssets, priceResBySymbol, block);
|
|
609
|
+
});
|
|
610
|
+
exports._getAaveV3HistoricalBalance = _getAaveV3HistoricalBalance;
|
|
611
|
+
const getAaveV3HistoricalBalance = (provider, network, market, address, block, reserveTokens, oracleAddress) => __awaiter(void 0, void 0, void 0, function* () { return (0, exports._getAaveV3HistoricalBalance)((0, viem_1.getViemProvider)(provider, network, { batch: { multicall: true } }), network, market, address, block, reserveTokens, oracleAddress); });
|
|
612
|
+
exports.getAaveV3HistoricalBalance = getAaveV3HistoricalBalance;
|
|
378
613
|
const _getAaveV3AccountData = (provider_1, network_1, address_1, extractedState_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, address_1, extractedState_1, ...args_1], void 0, function* (provider, network, address, extractedState, blockNumber = 'latest') {
|
|
379
614
|
const { selectedMarket: market, assetsData, eModeCategoriesData, } = extractedState;
|
|
380
615
|
let payload = Object.assign(Object.assign({}, exports.EMPTY_AAVE_DATA), { lastUpdated: Date.now() });
|
package/cjs/aaveV3/sgho.d.ts
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
1
|
import { EthAddress, NetworkNumber } from '../types/common';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
balance: string;
|
|
5
|
-
maxDeposit: string;
|
|
6
|
-
maxWithdraw: string;
|
|
7
|
-
underlyingBalance: string;
|
|
8
|
-
}
|
|
9
|
-
export interface SghoData {
|
|
10
|
-
totalAssets: string;
|
|
11
|
-
totalSupply: string;
|
|
12
|
-
supplyCap: string;
|
|
13
|
-
/** Target savings rate as an APY percent (e.g. "4.25" for 4.25%). */
|
|
14
|
-
targetRate: string;
|
|
15
|
-
paused: boolean;
|
|
16
|
-
user: SghoUserData;
|
|
17
|
-
}
|
|
2
|
+
import { SghoData } from '../types/aave';
|
|
3
|
+
export type { SghoData, SghoUserData } from '../types/aave';
|
|
18
4
|
export declare const getSghoData: (network: NetworkNumber, address?: EthAddress) => Promise<SghoData>;
|
package/cjs/aaveV4/lend.d.ts
CHANGED
|
@@ -1,53 +1,12 @@
|
|
|
1
1
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
assetId: string;
|
|
5
|
-
decimals: number;
|
|
6
|
-
spoke: EthAddress;
|
|
7
|
-
spokeActive: boolean;
|
|
8
|
-
spokeHalted: boolean;
|
|
9
|
-
spokeDepositCap: string;
|
|
10
|
-
spokeTotalAssets: string;
|
|
11
|
-
spokeTotalShares: string;
|
|
12
|
-
hub: EthAddress;
|
|
13
|
-
hubLiquidity: string;
|
|
14
|
-
hubDrawnRate: string;
|
|
15
|
-
convertToShares: string;
|
|
16
|
-
convertToAssets: string;
|
|
17
|
-
user: EthAddress;
|
|
18
|
-
userSuppliedAssets: string;
|
|
19
|
-
userSuppliedShares: string;
|
|
20
|
-
}
|
|
2
|
+
import { AaveV4TokenizationSpokeDataParsed } from '../types/aaveV4';
|
|
3
|
+
export type { AaveV4TokenizationSpokeData, AaveV4TokenizationSpokeDataParsed } from '../types/aaveV4';
|
|
21
4
|
export declare const AAVE_V4_TOKENIZED_SPOKES: Record<string, EthAddress>;
|
|
22
5
|
export declare const AAVE_V4_TOKENIZED_SPOKE_ADDRESSES: Partial<Record<NetworkNumber, EthAddress[]>>;
|
|
23
6
|
export type AaveV4TokenizedHubKey = 'CORE' | 'PLUS' | 'PRIME' | 'PAXOS';
|
|
24
7
|
export declare const aaveV4GetTokenizedHubKey: (hubNameOrKey?: string | null) => AaveV4TokenizedHubKey | null;
|
|
25
8
|
export declare const aaveV4GetTokenizedVaultKey: (symbol: string, hubNameOrKey?: string | null) => string | null;
|
|
26
9
|
export declare const aaveV4GetTokenizedVaultAddress: (network: NetworkNumber, symbol: string, hubNameOrKey?: string | null) => EthAddress | undefined;
|
|
27
|
-
/** Parsed tokenization spoke data with human-readable supplied amounts for display */
|
|
28
|
-
export interface AaveV4TokenizationSpokeDataParsed {
|
|
29
|
-
vaultAddress: EthAddress;
|
|
30
|
-
key: string | null;
|
|
31
|
-
symbol: string;
|
|
32
|
-
hubKey: string;
|
|
33
|
-
spokeActive: boolean;
|
|
34
|
-
spokeHalted: boolean;
|
|
35
|
-
/** Deposit cap in asset units (wei string) */
|
|
36
|
-
spokeDepositCap: string;
|
|
37
|
-
/** Total assets currently in spoke in asset units (wei string) */
|
|
38
|
-
spokeTotalAssets: string;
|
|
39
|
-
/** Available hub liquidity in asset units (wei string) */
|
|
40
|
-
hubLiquidity: string;
|
|
41
|
-
/** The conversion rate from assets to shares expressed in asset units. */
|
|
42
|
-
convertToShares: string;
|
|
43
|
-
userSuppliedAssetsEth: string;
|
|
44
|
-
userSuppliedSharesEth: string;
|
|
45
|
-
userSuppliedAssets: string;
|
|
46
|
-
userSuppliedShares: string;
|
|
47
|
-
underlyingAsset: EthAddress;
|
|
48
|
-
spoke: EthAddress;
|
|
49
|
-
decimals: number;
|
|
50
|
-
}
|
|
51
10
|
/**
|
|
52
11
|
* Fetches tokenization vault data for the given user via getTokenizationSpokesData.
|
|
53
12
|
* Returns parsed data including userSuppliedAssets in human-readable form for each vault.
|
package/cjs/claiming/aaveV3.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import { EthAddress, NetworkNumber } from '../types';
|
|
3
|
-
import { ClaimableToken, MerklRewardsClaimableToken } from '../types/claiming';
|
|
4
|
-
export declare function getUnclaimedRewardsForAllMarkets(provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress): Promise<
|
|
3
|
+
import { AaveRewardsClaimableToken, ClaimableToken, MerklRewardsClaimableToken } from '../types/claiming';
|
|
4
|
+
export declare function getUnclaimedRewardsForAllMarkets(provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress): Promise<AaveRewardsClaimableToken[]>;
|
|
5
5
|
export declare function getMerklUnclaimedRewards(account: EthAddress, network: NetworkNumber): Promise<MerklRewardsClaimableToken[]>;
|
|
6
6
|
export declare function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber): Promise<ClaimableToken[]>;
|
package/cjs/claiming/ethena.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { EthAddress } from '../types/common';
|
|
2
|
+
import { EthenaAirdropClaimableToken } from '../types/claiming';
|
|
2
3
|
export declare const fetchEthenaAirdropReward: (address: EthAddress) => Promise<any>;
|
|
3
|
-
export declare const fetchEthenaAirdropRewards: (walletAddresses: EthAddress[]) => Promise<Record<string,
|
|
4
|
+
export declare const fetchEthenaAirdropRewards: (walletAddresses: EthAddress[]) => Promise<Record<string, EthenaAirdropClaimableToken[]>>;
|
package/cjs/claiming/king.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
|
+
import { KingRewardsClaimableToken } from '../types/claiming';
|
|
3
4
|
export declare const fetchKingRewards: (walletAddress: EthAddress) => Promise<any>;
|
|
4
|
-
export declare const getKingRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string,
|
|
5
|
+
export declare const getKingRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, KingRewardsClaimableToken[]>>;
|
package/cjs/claiming/spark.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
|
-
import { SparkRewardsClaimableToken } from '../types/claiming';
|
|
3
|
+
import { SparkAirdropClaimableToken, SparkRewardsClaimableToken } from '../types/claiming';
|
|
4
4
|
export declare const fetchSpkAirdropRewards: (walletAddress: EthAddress) => Promise<any>;
|
|
5
|
-
export declare const fetchSparkAirdropRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string,
|
|
5
|
+
export declare const fetchSparkAirdropRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, SparkAirdropClaimableToken[]>>;
|
|
6
6
|
export declare const fetchSparkRewards: (provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress) => Promise<SparkRewardsClaimableToken[]>;
|
package/cjs/curveUsd/index.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ export declare const _getCurveUsdGlobalData: (provider: Client, network: Network
|
|
|
5
5
|
export declare const getCurveUsdGlobalData: (provider: EthereumProvider, network: NetworkNumber, selectedMarket: CrvUSDMarketData) => Promise<CrvUSDGlobalMarketData>;
|
|
6
6
|
export declare const _getCrvUsdAccountBalances: (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, controllerAddress: EthAddress) => Promise<PositionBalances>;
|
|
7
7
|
export declare const getCrvUsdAccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, controllerAddress: EthAddress) => Promise<PositionBalances>;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @param borrowRate market borrow APY in % (`CrvUSDGlobalMarketData.borrowRate`); when omitted it is read from the view contract
|
|
10
|
+
*/
|
|
11
|
+
export declare const _getCurveUsdUserData: (provider: Client, network: NetworkNumber, address: EthAddress, selectedMarket: CrvUSDMarketData, activeBand: string, borrowRate?: string) => Promise<CrvUSDUserData>;
|
|
12
|
+
export declare const getCurveUsdUserData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, selectedMarket: CrvUSDMarketData, activeBand: string, borrowRate?: string) => Promise<CrvUSDUserData>;
|
|
10
13
|
export declare const getCurveUsdFullPositionData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, selectedMarket: CrvUSDMarketData) => Promise<CrvUSDUserData>;
|
package/cjs/curveUsd/index.js
CHANGED
|
@@ -22,6 +22,12 @@ const curveUsdHelpers_1 = require("../helpers/curveUsdHelpers");
|
|
|
22
22
|
const markets_1 = require("../markets");
|
|
23
23
|
const utils_1 = require("../services/utils");
|
|
24
24
|
const viem_1 = require("../services/viem");
|
|
25
|
+
const staking_1 = require("../staking");
|
|
26
|
+
/** Converts a per-second AMM rate (wei, 18 decimals) into a yearly compounded borrow APY in %. */
|
|
27
|
+
const ammRateToBorrowApy = (rateWei) => {
|
|
28
|
+
const exponent = new decimal_js_1.default((0, tokens_1.assetAmountInEth)(rateWei)).mul(365).mul(86400);
|
|
29
|
+
return new decimal_js_1.default(new decimal_js_1.default(2.718281828459).pow(exponent).minus(1)).mul(100).toString();
|
|
30
|
+
};
|
|
25
31
|
const getAndFormatBands = (provider, network, selectedMarket, _minBand, _maxBand) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
32
|
const contract = (0, contracts_1.CrvUSDViewContractViem)(provider, network);
|
|
27
33
|
const minBand = parseInt(_minBand, 10);
|
|
@@ -71,14 +77,8 @@ const _getCurveUsdGlobalData = (provider, network, selectedMarket) => __awaiter(
|
|
|
71
77
|
// all prices are in 18 decimals
|
|
72
78
|
const totalDebt = (0, tokens_1.assetAmountInEth)(data.totalDebt.toString(), debtAsset);
|
|
73
79
|
const ammPrice = (0, tokens_1.assetAmountInEth)(data.ammPrice.toString(), debtAsset);
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const exponentRate = new decimal_js_1.default(rate).mul(365).mul(86400);
|
|
77
|
-
const exponentFutureRate = new decimal_js_1.default(futureRate).mul(365).mul(86400);
|
|
78
|
-
const borrowRate = new decimal_js_1.default(new decimal_js_1.default(2.718281828459).pow(exponentRate).minus(1)).mul(100)
|
|
79
|
-
.toString();
|
|
80
|
-
const futureBorrowRate = new decimal_js_1.default(new decimal_js_1.default(2.718281828459).pow(exponentFutureRate).minus(1)).mul(100)
|
|
81
|
-
.toString();
|
|
80
|
+
const borrowRate = ammRateToBorrowApy(data.ammRate.toString());
|
|
81
|
+
const futureBorrowRate = ammRateToBorrowApy(data.monetaryPolicyRate.toString());
|
|
82
82
|
const bandsData = yield getAndFormatBands(provider, network, selectedMarket, data.minBand.toString(), data.maxBand.toString());
|
|
83
83
|
const leftToBorrow = new decimal_js_1.default(debtCeiling.toString()).minus(totalDebt).toString();
|
|
84
84
|
const loanDiscount = (0, tokens_1.assetAmountInEth)(loanDiscountWei.toString(), debtAsset);
|
|
@@ -131,11 +131,20 @@ const _getCrvUsdAccountBalances = (provider, network, block, addressMapping, add
|
|
|
131
131
|
exports._getCrvUsdAccountBalances = _getCrvUsdAccountBalances;
|
|
132
132
|
const getCrvUsdAccountBalances = (provider, network, block, addressMapping, address, controllerAddress) => __awaiter(void 0, void 0, void 0, function* () { return (0, exports._getCrvUsdAccountBalances)((0, viem_1.getViemProvider)(provider, network), network, block, addressMapping, address, controllerAddress); });
|
|
133
133
|
exports.getCrvUsdAccountBalances = getCrvUsdAccountBalances;
|
|
134
|
-
|
|
134
|
+
/**
|
|
135
|
+
* @param borrowRate market borrow APY in % (`CrvUSDGlobalMarketData.borrowRate`); when omitted it is read from the view contract
|
|
136
|
+
*/
|
|
137
|
+
const _getCurveUsdUserData = (provider, network, address, selectedMarket, activeBand, borrowRate) => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
138
|
const contract = (0, contracts_1.CrvUSDViewContractViem)(provider, network);
|
|
136
|
-
const data = yield contract.read.userData([selectedMarket.controllerAddress, address]);
|
|
137
139
|
const collAsset = selectedMarket.collAsset;
|
|
138
140
|
const debtAsset = selectedMarket.baseAsset;
|
|
141
|
+
const [data, collStakingApy, marketBorrowRate] = yield Promise.all([
|
|
142
|
+
contract.read.userData([selectedMarket.controllerAddress, address]),
|
|
143
|
+
staking_1.STAKING_ASSETS.includes(collAsset) ? (0, staking_1.getStakingApy)(collAsset) : Promise.resolve('0'),
|
|
144
|
+
borrowRate !== undefined
|
|
145
|
+
? Promise.resolve(borrowRate)
|
|
146
|
+
: contract.read.globalData([selectedMarket.controllerAddress]).then((globalData) => ammRateToBorrowApy(globalData.ammRate.toString())),
|
|
147
|
+
]);
|
|
139
148
|
const health = (0, tokens_1.assetAmountInEth)(data.health.toString());
|
|
140
149
|
const healthPercent = new decimal_js_1.default(health).mul(100).toString();
|
|
141
150
|
const collPrice = (0, tokens_1.assetAmountInEth)(data.collateralPrice.toString(), debtAsset);
|
|
@@ -166,7 +175,7 @@ const _getCurveUsdUserData = (provider, network, address, selectedMarket, active
|
|
|
166
175
|
isBorrowed: new decimal_js_1.default(debtBorrowed).gt('0'),
|
|
167
176
|
symbol: 'crvUSD',
|
|
168
177
|
price: '1',
|
|
169
|
-
interestRate:
|
|
178
|
+
interestRate: marketBorrowRate,
|
|
170
179
|
},
|
|
171
180
|
} : {};
|
|
172
181
|
const priceHigh = (0, tokens_1.assetAmountInEth)(data.priceHigh.toString());
|
|
@@ -178,16 +187,22 @@ const _getCurveUsdUserData = (provider, network, address, selectedMarket, active
|
|
|
178
187
|
healthPercent,
|
|
179
188
|
priceHigh,
|
|
180
189
|
priceLow, liquidationDiscount: (0, tokens_1.assetAmountInEth)(data.liquidationDiscount.toString()), numOfBands: data.N.toString(), usedAssets,
|
|
181
|
-
status }), (0, curveUsdHelpers_1.getCrvUsdAggregatedData)({
|
|
182
|
-
loanExists: data.loanExists,
|
|
190
|
+
status, borrowRate: marketBorrowRate }), (0, curveUsdHelpers_1.getCrvUsdAggregatedData)({
|
|
191
|
+
loanExists: data.loanExists,
|
|
192
|
+
usedAssets,
|
|
193
|
+
network: common_1.NetworkNumber.Eth,
|
|
194
|
+
selectedMarket,
|
|
195
|
+
numOfBands: data.N.toString(),
|
|
196
|
+
borrowRate: marketBorrowRate,
|
|
197
|
+
collStakingApy,
|
|
183
198
|
})), { userBands });
|
|
184
199
|
});
|
|
185
200
|
exports._getCurveUsdUserData = _getCurveUsdUserData;
|
|
186
|
-
const getCurveUsdUserData = (provider, network, address, selectedMarket, activeBand) => __awaiter(void 0, void 0, void 0, function* () { return (0, exports._getCurveUsdUserData)((0, viem_1.getViemProvider)(provider, network), network, address, selectedMarket, activeBand); });
|
|
201
|
+
const getCurveUsdUserData = (provider, network, address, selectedMarket, activeBand, borrowRate) => __awaiter(void 0, void 0, void 0, function* () { return (0, exports._getCurveUsdUserData)((0, viem_1.getViemProvider)(provider, network), network, address, selectedMarket, activeBand, borrowRate); });
|
|
187
202
|
exports.getCurveUsdUserData = getCurveUsdUserData;
|
|
188
203
|
const getCurveUsdFullPositionData = (provider, network, address, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () {
|
|
189
204
|
const marketData = yield (0, exports.getCurveUsdGlobalData)(provider, network, selectedMarket);
|
|
190
|
-
const positionData = yield (0, exports.getCurveUsdUserData)(provider, network, address, selectedMarket, marketData.activeBand);
|
|
205
|
+
const positionData = yield (0, exports.getCurveUsdUserData)(provider, network, address, selectedMarket, marketData.activeBand, marketData.borrowRate);
|
|
191
206
|
return positionData;
|
|
192
207
|
});
|
|
193
208
|
exports.getCurveUsdFullPositionData = getCurveUsdFullPositionData;
|