@defisaver/positions-sdk 2.1.175-looping-dev → 2.1.175-pendle-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.d.ts +4 -4
- package/cjs/aaveV2/index.js +7 -7
- package/cjs/aaveV3/index.d.ts +4 -3
- package/cjs/aaveV3/index.js +14 -10
- package/cjs/aaveV3/merkl.d.ts +5 -1
- package/cjs/aaveV3/merkl.js +8 -3
- package/cjs/aaveV4/index.d.ts +4 -3
- package/cjs/aaveV4/index.js +19 -16
- package/cjs/aaveV4/merkl.d.ts +10 -2
- package/cjs/aaveV4/merkl.js +15 -6
- package/cjs/claiming/aaveV3.d.ts +2 -2
- package/cjs/claiming/aaveV3.js +5 -4
- package/cjs/claiming/king.d.ts +2 -2
- package/cjs/claiming/king.js +3 -2
- package/cjs/claiming/spark.d.ts +3 -3
- package/cjs/claiming/spark.js +8 -7
- package/cjs/claiming/uniswap.d.ts +2 -2
- package/cjs/claiming/uniswap.js +3 -2
- package/cjs/compoundV2/index.d.ts +4 -4
- package/cjs/compoundV2/index.js +9 -9
- package/cjs/compoundV3/index.d.ts +5 -4
- package/cjs/compoundV3/index.js +17 -13
- package/cjs/compoundV3/merkl.d.ts +1 -1
- package/cjs/compoundV3/merkl.js +2 -5
- package/cjs/curveUsd/index.d.ts +5 -5
- package/cjs/curveUsd/index.js +17 -17
- package/cjs/fluid/index.d.ts +23 -22
- package/cjs/fluid/index.js +75 -72
- package/cjs/fluid/merkl.d.ts +5 -3
- package/cjs/fluid/merkl.js +11 -6
- package/cjs/helpers/aaveHelpers/index.js +1 -1
- package/cjs/helpers/aaveV4Helpers/index.js +14 -2
- package/cjs/helpers/compoundHelpers/index.js +2 -2
- package/cjs/helpers/curveUsdHelpers/index.js +1 -1
- package/cjs/helpers/fluidHelpers/index.js +1 -1
- package/cjs/helpers/liquityV2Helpers/index.js +1 -1
- package/cjs/helpers/llamaLendHelpers/index.js +1 -1
- package/cjs/helpers/morphoBlueHelpers/index.js +1 -1
- package/cjs/helpers/morphoMidnightHelpers/index.js +1 -1
- package/cjs/helpers/sparkHelpers/index.js +1 -1
- package/cjs/liquity/index.d.ts +4 -4
- package/cjs/liquity/index.js +23 -23
- package/cjs/liquityV2/index.d.ts +10 -10
- package/cjs/liquityV2/index.js +59 -59
- package/cjs/llamaLend/index.d.ts +5 -5
- package/cjs/llamaLend/index.js +13 -13
- package/cjs/maker/index.d.ts +6 -6
- package/cjs/maker/index.js +16 -16
- package/cjs/markets/morphoBlue/index.d.ts +2 -0
- package/cjs/markets/morphoBlue/index.js +19 -2
- package/cjs/moneymarket/moneymarketCommonService.js +14 -3
- package/cjs/morphoBlue/index.d.ts +7 -7
- package/cjs/morphoBlue/index.js +28 -26
- package/cjs/morphoBlue/merkl.d.ts +5 -3
- package/cjs/morphoBlue/merkl.js +6 -8
- package/cjs/morphoMidnight/index.d.ts +5 -5
- package/cjs/morphoMidnight/index.js +18 -18
- package/cjs/portfolio/customDeFiData.d.ts +3 -0
- package/cjs/portfolio/customDeFiData.js +267 -0
- package/cjs/portfolio/index.d.ts +1 -0
- package/cjs/portfolio/index.js +1 -0
- package/cjs/services/merkl.d.ts +46 -2
- package/cjs/services/merkl.js +190 -19
- package/cjs/services/priceService.d.ts +12 -12
- package/cjs/services/priceService.js +30 -29
- package/cjs/services/viem.d.ts +10 -2
- package/cjs/services/viem.js +27 -1
- package/cjs/spark/index.d.ts +4 -4
- package/cjs/spark/index.js +9 -9
- package/cjs/staking/staking.js +3 -1
- package/cjs/types/aaveV4.d.ts +1 -0
- package/cjs/types/common.d.ts +1 -0
- package/cjs/types/common.js +1 -0
- package/cjs/types/merkl.d.ts +18 -0
- package/cjs/types/morphoBlue.d.ts +1 -0
- package/cjs/types/morphoBlue.js +1 -0
- package/cjs/types/portfolio.d.ts +37 -0
- package/cjs/types/portfolio.js +18 -0
- package/cjs/umbrella/index.d.ts +2 -2
- package/cjs/umbrella/index.js +5 -4
- package/esm/aaveV2/index.d.ts +4 -4
- package/esm/aaveV2/index.js +8 -8
- package/esm/aaveV3/index.d.ts +4 -3
- package/esm/aaveV3/index.js +15 -11
- package/esm/aaveV3/merkl.d.ts +5 -1
- package/esm/aaveV3/merkl.js +9 -4
- package/esm/aaveV4/index.d.ts +4 -3
- package/esm/aaveV4/index.js +20 -17
- package/esm/aaveV4/merkl.d.ts +10 -2
- package/esm/aaveV4/merkl.js +16 -7
- package/esm/claiming/aaveV3.d.ts +2 -2
- package/esm/claiming/aaveV3.js +5 -4
- package/esm/claiming/king.d.ts +2 -2
- package/esm/claiming/king.js +3 -2
- package/esm/claiming/spark.d.ts +3 -3
- package/esm/claiming/spark.js +8 -7
- package/esm/claiming/uniswap.d.ts +2 -2
- package/esm/claiming/uniswap.js +3 -2
- package/esm/compoundV2/index.d.ts +4 -4
- package/esm/compoundV2/index.js +9 -9
- package/esm/compoundV3/index.d.ts +5 -4
- package/esm/compoundV3/index.js +19 -15
- package/esm/compoundV3/merkl.d.ts +1 -1
- package/esm/compoundV3/merkl.js +3 -6
- package/esm/curveUsd/index.d.ts +5 -5
- package/esm/curveUsd/index.js +17 -17
- package/esm/fluid/index.d.ts +23 -22
- package/esm/fluid/index.js +76 -73
- package/esm/fluid/merkl.d.ts +5 -3
- package/esm/fluid/merkl.js +12 -7
- package/esm/helpers/aaveHelpers/index.js +1 -1
- package/esm/helpers/aaveV4Helpers/index.js +15 -3
- package/esm/helpers/compoundHelpers/index.js +2 -2
- package/esm/helpers/curveUsdHelpers/index.js +1 -1
- package/esm/helpers/fluidHelpers/index.js +1 -1
- package/esm/helpers/liquityV2Helpers/index.js +1 -1
- package/esm/helpers/llamaLendHelpers/index.js +1 -1
- package/esm/helpers/morphoBlueHelpers/index.js +1 -1
- package/esm/helpers/morphoMidnightHelpers/index.js +1 -1
- package/esm/helpers/sparkHelpers/index.js +1 -1
- package/esm/liquity/index.d.ts +4 -4
- package/esm/liquity/index.js +23 -23
- package/esm/liquityV2/index.d.ts +10 -10
- package/esm/liquityV2/index.js +60 -60
- package/esm/llamaLend/index.d.ts +5 -5
- package/esm/llamaLend/index.js +13 -13
- package/esm/maker/index.d.ts +6 -6
- package/esm/maker/index.js +16 -16
- package/esm/markets/morphoBlue/index.d.ts +2 -0
- package/esm/markets/morphoBlue/index.js +16 -0
- package/esm/moneymarket/moneymarketCommonService.js +14 -3
- package/esm/morphoBlue/index.d.ts +7 -7
- package/esm/morphoBlue/index.js +29 -27
- package/esm/morphoBlue/merkl.d.ts +5 -3
- package/esm/morphoBlue/merkl.js +7 -9
- package/esm/morphoMidnight/index.d.ts +5 -5
- package/esm/morphoMidnight/index.js +18 -18
- package/esm/portfolio/customDeFiData.d.ts +3 -0
- package/esm/portfolio/customDeFiData.js +261 -0
- package/esm/portfolio/index.d.ts +1 -0
- package/esm/portfolio/index.js +1 -0
- package/esm/services/merkl.d.ts +46 -2
- package/esm/services/merkl.js +180 -18
- package/esm/services/priceService.d.ts +12 -12
- package/esm/services/priceService.js +31 -30
- package/esm/services/viem.d.ts +10 -2
- package/esm/services/viem.js +25 -0
- package/esm/spark/index.d.ts +4 -4
- package/esm/spark/index.js +10 -10
- package/esm/staking/staking.js +3 -1
- package/esm/types/aaveV4.d.ts +1 -0
- package/esm/types/common.d.ts +1 -0
- package/esm/types/common.js +1 -0
- package/esm/types/merkl.d.ts +18 -0
- package/esm/types/morphoBlue.d.ts +1 -0
- package/esm/types/morphoBlue.js +1 -0
- package/esm/types/portfolio.d.ts +37 -0
- package/esm/types/portfolio.js +17 -1
- package/esm/umbrella/index.d.ts +2 -2
- package/esm/umbrella/index.js +5 -4
- package/package.json +2 -2
- package/src/aaveV2/index.ts +7 -7
- package/src/aaveV3/index.ts +15 -11
- package/src/aaveV3/merkl.ts +9 -4
- package/src/aaveV4/index.ts +19 -16
- package/src/aaveV4/merkl.ts +16 -7
- package/src/claiming/aaveV3.ts +5 -3
- package/src/claiming/king.ts +6 -3
- package/src/claiming/spark.ts +9 -6
- package/src/claiming/uniswap.ts +4 -3
- package/src/compoundV2/index.ts +10 -9
- package/src/compoundV3/index.ts +20 -14
- package/src/compoundV3/merkl.ts +5 -4
- package/src/curveUsd/index.ts +19 -17
- package/src/fluid/index.ts +88 -70
- package/src/fluid/merkl.ts +12 -7
- package/src/helpers/aaveHelpers/index.ts +1 -1
- package/src/helpers/aaveV4Helpers/index.ts +16 -2
- package/src/helpers/compoundHelpers/index.ts +2 -2
- package/src/helpers/curveUsdHelpers/index.ts +1 -1
- package/src/helpers/fluidHelpers/index.ts +1 -1
- package/src/helpers/liquityV2Helpers/index.ts +1 -1
- package/src/helpers/llamaLendHelpers/index.ts +1 -1
- package/src/helpers/morphoBlueHelpers/index.ts +1 -1
- package/src/helpers/morphoMidnightHelpers/index.ts +1 -1
- package/src/helpers/sparkHelpers/index.ts +1 -1
- package/src/liquity/index.ts +23 -23
- package/src/liquityV2/index.ts +64 -56
- package/src/llamaLend/index.ts +15 -13
- package/src/maker/index.ts +19 -16
- package/src/markets/morphoBlue/index.ts +16 -0
- package/src/moneymarket/moneymarketCommonService.ts +15 -3
- package/src/morphoBlue/index.ts +23 -20
- package/src/morphoBlue/merkl.ts +9 -6
- package/src/morphoMidnight/index.ts +13 -13
- package/src/portfolio/customDeFiData.ts +385 -0
- package/src/portfolio/index.ts +1 -0
- package/src/services/merkl.ts +209 -19
- package/src/services/priceService.ts +33 -30
- package/src/services/viem.ts +16 -0
- package/src/spark/index.ts +11 -8
- package/src/staking/staking.ts +2 -1
- package/src/types/aaveV4.ts +1 -0
- package/src/types/common.ts +1 -0
- package/src/types/merkl.ts +20 -0
- package/src/types/morphoBlue.ts +1 -0
- package/src/types/portfolio.ts +40 -0
- package/src/umbrella/index.ts +6 -5
package/esm/maker/index.js
CHANGED
|
@@ -63,12 +63,12 @@ export const _getMakerAccountBalances = (provider, network, block, addressMappin
|
|
|
63
63
|
return balances;
|
|
64
64
|
});
|
|
65
65
|
export const getMakerAccountBalances = (provider, network, block, addressMapping, cdpId, _managerAddress) => __awaiter(void 0, void 0, void 0, function* () { return _getMakerAccountBalances(getViemProvider(provider, network, { batch: { multicall: true } }), network, block, addressMapping, cdpId, _managerAddress); });
|
|
66
|
-
export const _getUserCdps = (
|
|
66
|
+
export const _getUserCdps = (provider_1, network_1, userAddress_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, userAddress_1, ...args_1], void 0, function* (provider, network, userAddress, blockNumber = 'latest') {
|
|
67
67
|
if (!userAddress)
|
|
68
68
|
return [];
|
|
69
69
|
const mcdGetCdpsContract = McdGetCdpsContractViem(provider, network);
|
|
70
70
|
const mcdCdpManagerAddress = getConfigContractAddress('McdCdpManager', network);
|
|
71
|
-
const standardCdps = yield mcdGetCdpsContract.read.getCdpsAsc([mcdCdpManagerAddress, userAddress]);
|
|
71
|
+
const standardCdps = yield mcdGetCdpsContract.read.getCdpsAsc([mcdCdpManagerAddress, userAddress], setViemBlockNumber(blockNumber));
|
|
72
72
|
const parsedStandardCdps = standardCdps[0].map((id, i) => ({
|
|
73
73
|
id: parseInt(id.toString(), 10),
|
|
74
74
|
ilk: standardCdps[2][i].toLowerCase(), // collateral type
|
|
@@ -80,36 +80,36 @@ export const _getUserCdps = (provider, network, userAddress) => __awaiter(void 0
|
|
|
80
80
|
}));
|
|
81
81
|
return parsedStandardCdps;
|
|
82
82
|
});
|
|
83
|
-
export const getUserCdps = (
|
|
84
|
-
export const _getMakerIlksData = (
|
|
83
|
+
export const getUserCdps = (provider_1, network_1, userAddress_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, userAddress_1, ...args_1], void 0, function* (provider, network, userAddress, blockNumber = 'latest') { return _getUserCdps(getViemProvider(provider, network), network, userAddress, blockNumber); });
|
|
84
|
+
export const _getMakerIlksData = (provider_1, network_1, ilkLabels_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, ilkLabels_1, ...args_1], void 0, function* (provider, network, ilkLabels, blockNumber = 'latest') {
|
|
85
85
|
const vatContract = McdVatContractViem(provider, network);
|
|
86
86
|
const spotterContract = McdSpotterContractViem(provider, network);
|
|
87
87
|
const dogContract = McdDogContractViem(provider, network);
|
|
88
88
|
const jugContract = McdJugContractViem(provider, network);
|
|
89
|
-
const par = yield spotterContract.read.par();
|
|
89
|
+
const par = yield spotterContract.read.par(setViemBlockNumber(blockNumber));
|
|
90
90
|
const ilksInfo = yield Promise.all(ilkLabels.map((ilkLabel) => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
91
|
const ilk = stringToBytes(ilkLabel);
|
|
92
92
|
const [[_, mat], [artGlobal, rate, spot, line, dust], [duty], futureRate, chop,] = yield Promise.all([
|
|
93
|
-
spotterContract.read.ilks([ilk]),
|
|
94
|
-
vatContract.read.ilks([ilk]),
|
|
95
|
-
jugContract.read.ilks([ilk]),
|
|
96
|
-
jugContract.read.drip([ilk]),
|
|
97
|
-
dogContract.read.chop([ilk]),
|
|
93
|
+
spotterContract.read.ilks([ilk], setViemBlockNumber(blockNumber)),
|
|
94
|
+
vatContract.read.ilks([ilk], setViemBlockNumber(blockNumber)),
|
|
95
|
+
jugContract.read.ilks([ilk], setViemBlockNumber(blockNumber)),
|
|
96
|
+
jugContract.read.drip([ilk], setViemBlockNumber(blockNumber)),
|
|
97
|
+
dogContract.read.chop([ilk], setViemBlockNumber(blockNumber)),
|
|
98
98
|
]);
|
|
99
99
|
return parseCollateralInfo(ilk, par.toString(), mat.toString(), artGlobal.toString(), rate.toString(), spot.toString(), line.toString(), dust.toString(), duty.toString(), futureRate.toString(), chop.toString());
|
|
100
100
|
})));
|
|
101
101
|
return Object.fromEntries(ilksInfo.map((ilkInfo) => [ilkInfo.ilkLabel, ilkInfo]));
|
|
102
102
|
});
|
|
103
|
-
export const getMakerIlksData = (
|
|
103
|
+
export const getMakerIlksData = (provider_1, network_1, ilkLabels_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, ilkLabels_1, ...args_1], void 0, function* (provider, network, ilkLabels, blockNumber = 'latest') { return _getMakerIlksData(getViemProvider(provider, network, { batch: { multicall: true } }), network, ilkLabels, blockNumber); });
|
|
104
104
|
/**
|
|
105
105
|
* @param ilkInfo optional precomputed ilk data (from `_getMakerIlksData`); when provided the per-ilk reads are skipped
|
|
106
106
|
*/
|
|
107
|
-
export const _getMakerCdpData = (
|
|
107
|
+
export const _getMakerCdpData = (provider_1, network_1, cdp_1, ilkInfo_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, cdp_1, ilkInfo_1, ...args_1], void 0, function* (provider, network, cdp, ilkInfo, blockNumber = 'latest') {
|
|
108
108
|
const vatContract = McdVatContractViem(provider, network);
|
|
109
109
|
const [[ink, art], coll, fetchedIlkInfo, collStakingApy,] = yield Promise.all([
|
|
110
|
-
vatContract.read.urns([cdp.ilk, cdp.urn]),
|
|
111
|
-
vatContract.read.gem([cdp.ilk, cdp.urn]),
|
|
112
|
-
ilkInfo || _getMakerIlksData(provider, network, [cdp.ilkLabel]).then((ilks) => ilks[cdp.ilkLabel]),
|
|
110
|
+
vatContract.read.urns([cdp.ilk, cdp.urn], setViemBlockNumber(blockNumber)),
|
|
111
|
+
vatContract.read.gem([cdp.ilk, cdp.urn], setViemBlockNumber(blockNumber)),
|
|
112
|
+
ilkInfo || _getMakerIlksData(provider, network, [cdp.ilkLabel], blockNumber).then((ilks) => ilks[cdp.ilkLabel]),
|
|
113
113
|
STAKING_ASSETS.includes(cdp.asset) ? getStakingApy(cdp.asset) : Promise.resolve('0'),
|
|
114
114
|
]);
|
|
115
115
|
const collInfo = fetchedIlkInfo;
|
|
@@ -173,4 +173,4 @@ export const _getMakerCdpData = (provider, network, cdp, ilkInfo) => __awaiter(v
|
|
|
173
173
|
incentiveUsd,
|
|
174
174
|
};
|
|
175
175
|
});
|
|
176
|
-
export const getMakerCdpData = (
|
|
176
|
+
export const getMakerCdpData = (provider_1, network_1, cdp_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, cdp_1, ...args_1], void 0, function* (provider, network, cdp, blockNumber = 'latest') { return _getMakerCdpData(getViemProvider(provider, network), network, cdp, undefined, blockNumber); });
|
|
@@ -84,6 +84,7 @@ export declare const MORPHO_BLUE_WBTC_EURCV_860: (networkId?: NetworkNumber) =>
|
|
|
84
84
|
export declare const MORPHO_BLUE_WSTETH_EURCV_860: (networkId?: NetworkNumber) => MorphoBlueMarketData;
|
|
85
85
|
export declare const MORPHO_BLUE_CBBTC_EURCV_860: (networkId?: NetworkNumber) => MorphoBlueMarketData;
|
|
86
86
|
export declare const MORPHO_BLUE_WBTC_EURC_860: (networkId?: NetworkNumber) => MorphoBlueMarketData;
|
|
87
|
+
export declare const MORPHO_BLUE_PTUSDATJAN_USDC_915: (networkId?: NetworkNumber) => MorphoBlueMarketData;
|
|
87
88
|
export declare const MORPHO_BLUE_CBETH_USDC_860_BASE: (networkId?: NetworkNumber) => MorphoBlueMarketData;
|
|
88
89
|
export declare const MORPHO_BLUE_CBETH_USDC_860_BASE_1c21c59d: (networkId?: NetworkNumber) => MorphoBlueMarketData;
|
|
89
90
|
export declare const MORPHO_BLUE_WSTETH_ETH_945_BASE: (networkId?: NetworkNumber) => MorphoBlueMarketData;
|
|
@@ -210,6 +211,7 @@ export declare const MorphoBlueMarkets: (networkId: NetworkNumber) => {
|
|
|
210
211
|
readonly morphobluewstetheurcv_860: MorphoBlueMarketData;
|
|
211
212
|
readonly morphobluecbbtceurcv_860: MorphoBlueMarketData;
|
|
212
213
|
readonly morphobluewbtceurc_860: MorphoBlueMarketData;
|
|
214
|
+
readonly morphoblueptusdatjanusdc_915: MorphoBlueMarketData;
|
|
213
215
|
readonly morphobluecbethusdc_860_base: MorphoBlueMarketData;
|
|
214
216
|
readonly morphobluecbethusdc_860_base_1c21c59d: MorphoBlueMarketData;
|
|
215
217
|
readonly morphobluewstethusdc_860_base: MorphoBlueMarketData;
|
|
@@ -1276,6 +1276,21 @@ export const MORPHO_BLUE_WBTC_EURC_860 = (networkId = NetworkNumber.Eth) => ({
|
|
|
1276
1276
|
marketId: '0xff527fe9c6516f9d82a3d51422ccb031d123266e6e26d4c22c942a948c180a75',
|
|
1277
1277
|
protocolName: 'morpho-blue',
|
|
1278
1278
|
});
|
|
1279
|
+
export const MORPHO_BLUE_PTUSDATJAN_USDC_915 = (networkId = NetworkNumber.Eth) => ({
|
|
1280
|
+
chainIds: [NetworkNumber.Eth],
|
|
1281
|
+
label: 'Morpho Blue',
|
|
1282
|
+
shortLabel: 'PT USDat Jan/USDC',
|
|
1283
|
+
value: MorphoBlueVersions.MorphoBluePTUSDatJanUSDC_915,
|
|
1284
|
+
url: 'ptusdatjanusdc-c7e49dd4',
|
|
1285
|
+
loanToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
1286
|
+
collateralToken: '0xba96292eE7673E3b546cC90dB6d97111Cd9A314F',
|
|
1287
|
+
oracle: '0x034f45AcCB8949e55366BEc6d4023d1C1E372Dad',
|
|
1288
|
+
oracleType: MorphoBlueOracleType.MARKET_RATE,
|
|
1289
|
+
irm: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1290
|
+
lltv: 0.915,
|
|
1291
|
+
marketId: '0xc7e49dd404825da16988955201ed22ecf8a7b25f0337db8a698d70d7a9f343ea',
|
|
1292
|
+
protocolName: 'morpho-blue',
|
|
1293
|
+
});
|
|
1279
1294
|
// BASE
|
|
1280
1295
|
export const MORPHO_BLUE_CBETH_USDC_860_BASE = (networkId = NetworkNumber.Eth) => ({
|
|
1281
1296
|
chainIds: [NetworkNumber.Base],
|
|
@@ -1965,6 +1980,7 @@ export const MorphoBlueMarkets = (networkId) => ({
|
|
|
1965
1980
|
[MorphoBlueVersions.MorphoBlueWstEthEURCV_860]: MORPHO_BLUE_WSTETH_EURCV_860(networkId),
|
|
1966
1981
|
[MorphoBlueVersions.MorphoBlueCbBTCEURCV_860]: MORPHO_BLUE_CBBTC_EURCV_860(networkId),
|
|
1967
1982
|
[MorphoBlueVersions.MorphoBlueWBTCEURC_860]: MORPHO_BLUE_WBTC_EURC_860(networkId),
|
|
1983
|
+
[MorphoBlueVersions.MorphoBluePTUSDatJanUSDC_915]: MORPHO_BLUE_PTUSDATJAN_USDC_915(networkId),
|
|
1968
1984
|
// BASE
|
|
1969
1985
|
[MorphoBlueVersions.MorphoBlueCbEthUSDC_860_Base]: MORPHO_BLUE_CBETH_USDC_860_BASE(networkId),
|
|
1970
1986
|
[MorphoBlueVersions.MorphoBlueCbEthUSDC_860_Base_1c21c59d]: MORPHO_BLUE_CBETH_USDC_860_BASE_1c21c59d(networkId),
|
|
@@ -11,7 +11,7 @@ export const calcShortLiqPrice = (assetPrice, borrowedUsd, borrowLimitUsd) => ne
|
|
|
11
11
|
export const calcLeverageLiqPrice = (leverageType, assetPrice, borrowedUsd, borrowLimitUsd) => {
|
|
12
12
|
if (leverageType === LeverageType.Short || leverageType === LeverageType.VolatilePairReverse)
|
|
13
13
|
return calcShortLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
14
|
-
if (leverageType === LeverageType.Long || leverageType === LeverageType.VolatilePair)
|
|
14
|
+
if (leverageType === LeverageType.Long || leverageType === LeverageType.VolatilePair || leverageType === LeverageType.StablePair)
|
|
15
15
|
return calcLongLiqPrice(assetPrice, borrowedUsd, borrowLimitUsd);
|
|
16
16
|
console.error('invalid leverageType', leverageType);
|
|
17
17
|
return '0';
|
|
@@ -24,7 +24,7 @@ export const STABLE_ASSETS = [
|
|
|
24
24
|
'PT sUSDe Feb', 'PT USDe Feb', 'PT sUSDe Apr', 'PT USDe Apr', 'PT sUSDe May', 'PT USDe May', 'PT srUSDe Apr', 'frxUSD', 'PT sUSDe June',
|
|
25
25
|
'PT USDe June', 'PT srUSDe Jun', 'PT srUSDe Oct', 'PT USDG May', 'PT sUSDS Nov', 'PT sUSDe Oct', 'PT USDG Sep',
|
|
26
26
|
'USDG', 'mUSD', 'PYUSD', 'USDbC', 'MAI', 'sGHO', 'USD3', 'stUSDS', 'PRIME',
|
|
27
|
-
'crvUSD', 'syrupUSDC', 'syrupUSDT', 'syrupUSDG', 'PT syrupUSDC Aug',
|
|
27
|
+
'crvUSD', 'syrupUSDC', 'syrupUSDT', 'syrupUSDG', 'PT syrupUSDC Aug', 'USDat', 'PT USDat Jan',
|
|
28
28
|
];
|
|
29
29
|
export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
30
30
|
let borrowUnstable = 0;
|
|
@@ -33,11 +33,14 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
33
33
|
let supplyUnstable = 0;
|
|
34
34
|
let longAsset = '';
|
|
35
35
|
let shortAsset = '';
|
|
36
|
+
let stableCollAsset = '';
|
|
36
37
|
Object.values(usedAssets).forEach(({ symbol, suppliedUsd, borrowedUsd, collateral, }) => {
|
|
37
38
|
const isSupplied = (+suppliedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
38
39
|
const isBorrowed = (+borrowedUsd) > dustLimit; // ignore dust like <limit leftover supply
|
|
39
|
-
if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral)
|
|
40
|
+
if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral) {
|
|
40
41
|
supplyStable += 1;
|
|
42
|
+
stableCollAsset = symbol;
|
|
43
|
+
}
|
|
41
44
|
if (isBorrowed && STABLE_ASSETS.includes(symbol))
|
|
42
45
|
borrowStable += 1;
|
|
43
46
|
if (isBorrowed && !STABLE_ASSETS.includes(symbol)) {
|
|
@@ -52,6 +55,7 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
52
55
|
const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
|
|
53
56
|
const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
|
|
54
57
|
const isVolatilePair = supplyUnstable === 1 && borrowUnstable === 1 && supplyStable === 0 && borrowStable === 0;
|
|
58
|
+
const isStablePair = supplyStable > 0 && borrowStable > 0 && supplyUnstable === 0 && borrowUnstable === 0;
|
|
55
59
|
if (isLong) {
|
|
56
60
|
return {
|
|
57
61
|
leveragedType: LeverageType.Long,
|
|
@@ -70,6 +74,13 @@ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
|
70
74
|
leveragedAsset: longAsset,
|
|
71
75
|
};
|
|
72
76
|
}
|
|
77
|
+
if (isStablePair) {
|
|
78
|
+
return {
|
|
79
|
+
leveragedType: LeverageType.StablePair,
|
|
80
|
+
// with multiple stable collaterals there is no single leveraged asset (and no liquidation price)
|
|
81
|
+
leveragedAsset: supplyStable === 1 ? stableCollAsset : '',
|
|
82
|
+
};
|
|
83
|
+
}
|
|
73
84
|
return {
|
|
74
85
|
leveragedType: LeverageType.None,
|
|
75
86
|
leveragedAsset: '',
|
|
@@ -3,15 +3,15 @@ import { Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances
|
|
|
3
3
|
import { MorphoBlueEarnData, MorphoBlueMarketData, MorphoBlueMarketInfo, MorphoBlueMarketRewards, MorphoBluePositionData } from '../types';
|
|
4
4
|
export { MorphoBlueMerklOpportunityType, addMorphoBlueMerklOpportunitiesToMarketInfo, getMorphoBlueMerklOpportunities, addMorphoBlueMerklRewardsToMarketInfo, } from './merkl';
|
|
5
5
|
export declare const addMorphoBlueRewardsToMarketInfo: (marketInfo: MorphoBlueMarketInfo, rewards: MorphoBlueMarketRewards) => MorphoBlueMarketInfo;
|
|
6
|
-
export declare function _getMorphoBlueMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketInfo>;
|
|
7
|
-
export declare function _getMorphoBluePortfolioMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketInfo>;
|
|
8
|
-
export declare function getMorphoBlueMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketInfo>;
|
|
9
|
-
export declare function getMorphoBluePortfolioMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketInfo>;
|
|
6
|
+
export declare function _getMorphoBlueMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoBlueMarketData, blockNumber?: Blockish): Promise<MorphoBlueMarketInfo>;
|
|
7
|
+
export declare function _getMorphoBluePortfolioMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoBlueMarketData, blockNumber?: Blockish): Promise<MorphoBlueMarketInfo>;
|
|
8
|
+
export declare function getMorphoBlueMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoBlueMarketData, blockNumber?: Blockish): Promise<MorphoBlueMarketInfo>;
|
|
9
|
+
export declare function getMorphoBluePortfolioMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoBlueMarketData, blockNumber?: Blockish): Promise<MorphoBlueMarketInfo>;
|
|
10
10
|
export declare const getMorphoBluePositionDataWithMarketInfo: (data: MorphoBluePositionData, marketInfo: MorphoBlueMarketInfo) => MorphoBluePositionData;
|
|
11
11
|
export declare const getMorphoEarnDataWithMarketInfo: (data: MorphoBlueEarnData, marketInfo: MorphoBlueMarketInfo) => MorphoBlueEarnData;
|
|
12
12
|
export declare function getMorphoBlueMarketRewards(network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketRewards>;
|
|
13
13
|
export declare const _getMorphoBlueAccountBalances: (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, selectedMarket: MorphoBlueMarketData) => Promise<PositionBalances>;
|
|
14
14
|
export declare const getMorphoBlueAccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, selectedMarket: MorphoBlueMarketData) => Promise<PositionBalances>;
|
|
15
|
-
export declare function _getMorphoBlueAccountData(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData>;
|
|
16
|
-
export declare function getMorphoBlueAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData>;
|
|
17
|
-
export declare function getMorphoEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBlueEarnData>;
|
|
15
|
+
export declare function _getMorphoBlueAccountData(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo, blockNumber?: Blockish): Promise<MorphoBluePositionData>;
|
|
16
|
+
export declare function getMorphoBlueAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo, blockNumber?: Blockish): Promise<MorphoBluePositionData>;
|
|
17
|
+
export declare function getMorphoEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo, blockNumber?: Blockish): Promise<MorphoBlueEarnData>;
|
package/esm/morphoBlue/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { calculateNetApy, getStakingApy, STAKING_ASSETS } from '../staking';
|
|
|
16
16
|
import { isMainnetNetwork, wethToEth } from '../services/utils';
|
|
17
17
|
import { getBorrowRate, getMorphoBlueAggregatedPositionData, getRewardsForMarket, getSupplyRate, } from '../helpers/morphoBlueHelpers';
|
|
18
18
|
import { getChainlinkAssetAddress } from '../services/priceService';
|
|
19
|
-
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
19
|
+
import { getBlockTimestamp, getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
20
20
|
import { addMorphoBlueMerklOpportunitiesToMarketInfo, getMorphoBlueMerklOpportunities } from './merkl';
|
|
21
21
|
export { MorphoBlueMerklOpportunityType, addMorphoBlueMerklOpportunitiesToMarketInfo, getMorphoBlueMerklOpportunities, addMorphoBlueMerklRewardsToMarketInfo, } from './merkl';
|
|
22
22
|
const HARDCODED_USD_STABLE_PRICE = '100000000'; // $1 with 8 decimals
|
|
@@ -33,8 +33,8 @@ export const addMorphoBlueRewardsToMarketInfo = (marketInfo, rewards) => (Object
|
|
|
33
33
|
...marketInfo.assetsData[marketInfo.loanToken].borrowIncentives.filter(({ token }) => token !== 'MORPHO'),
|
|
34
34
|
...getMorphoRewardIncentives(rewards.borrowApy),
|
|
35
35
|
] }) }) }));
|
|
36
|
-
function getMorphoBlueMarketDataInternal(
|
|
37
|
-
return __awaiter(this,
|
|
36
|
+
function getMorphoBlueMarketDataInternal(provider_1, network_1, selectedMarket_1) {
|
|
37
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, selectedMarket, blockNumber = 'latest') {
|
|
38
38
|
const { loanToken, collateralToken, oracle, irm, lltv, oracleType, } = selectedMarket;
|
|
39
39
|
const lltvInWei = new Dec(lltv).mul(WAD).toString();
|
|
40
40
|
const loanTokenInfo = getAssetInfoByAddress(loanToken, network);
|
|
@@ -48,8 +48,8 @@ function getMorphoBlueMarketDataInternal(provider, network, selectedMarket) {
|
|
|
48
48
|
if (isMainnet) {
|
|
49
49
|
const feedRegistryContract = FeedRegistryContractViem(provider, NetworkNumber.Eth);
|
|
50
50
|
const [_loanTokenPrice, _marketInfo] = yield Promise.all([
|
|
51
|
-
isHardcodedUsdStable ? Promise.resolve(HARDCODED_USD_STABLE_PRICE) : feedRegistryContract.read.latestAnswer([loanTokenFeedAddress, USD_QUOTE]),
|
|
52
|
-
morphoBlueViewContract.read.getMarketInfoNotTuple([loanToken, collateralToken, oracle, irm, BigInt(lltvInWei)]),
|
|
51
|
+
isHardcodedUsdStable ? Promise.resolve(HARDCODED_USD_STABLE_PRICE) : feedRegistryContract.read.latestAnswer([loanTokenFeedAddress, USD_QUOTE], setViemBlockNumber(blockNumber)),
|
|
52
|
+
morphoBlueViewContract.read.getMarketInfoNotTuple([loanToken, collateralToken, oracle, irm, BigInt(lltvInWei)], setViemBlockNumber(blockNumber)),
|
|
53
53
|
]);
|
|
54
54
|
marketInfo = _marketInfo;
|
|
55
55
|
loanTokenPrice = _loanTokenPrice;
|
|
@@ -59,8 +59,8 @@ function getMorphoBlueMarketDataInternal(provider, network, selectedMarket) {
|
|
|
59
59
|
const feedRegistryContract = DFSFeedRegistryContractViem(provider, network);
|
|
60
60
|
const [loanTokenPriceRound, _marketInfo] = yield Promise.all([
|
|
61
61
|
isHardcodedUsdStable ? Promise.resolve([0, HARDCODED_USD_STABLE_PRICE]) // Normalize to match the expected object structure
|
|
62
|
-
: feedRegistryContract.read.latestRoundData([loanTokenFeedAddress, USD_QUOTE]),
|
|
63
|
-
morphoBlueViewContract.read.getMarketInfoNotTuple([loanToken, collateralToken, oracle, irm, BigInt(lltvInWei)]),
|
|
62
|
+
: feedRegistryContract.read.latestRoundData([loanTokenFeedAddress, USD_QUOTE], setViemBlockNumber(blockNumber)),
|
|
63
|
+
morphoBlueViewContract.read.getMarketInfoNotTuple([loanToken, collateralToken, oracle, irm, BigInt(lltvInWei)], setViemBlockNumber(blockNumber)),
|
|
64
64
|
]);
|
|
65
65
|
marketInfo = _marketInfo;
|
|
66
66
|
loanTokenPrice = loanTokenPriceRound[1].toString();
|
|
@@ -119,29 +119,31 @@ function getMorphoBlueMarketDataInternal(provider, network, selectedMarket) {
|
|
|
119
119
|
};
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
-
export function _getMorphoBlueMarketData(
|
|
123
|
-
return __awaiter(this,
|
|
122
|
+
export function _getMorphoBlueMarketData(provider_1, network_1, selectedMarket_1) {
|
|
123
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, selectedMarket, blockNumber = 'latest') {
|
|
124
124
|
const [marketInfo, rewards, merklOpportunities] = yield Promise.all([
|
|
125
|
-
getMorphoBlueMarketDataInternal(provider, network, selectedMarket),
|
|
125
|
+
getMorphoBlueMarketDataInternal(provider, network, selectedMarket, blockNumber),
|
|
126
126
|
getRewardsForMarket(selectedMarket.marketId, network).catch((error) => {
|
|
127
127
|
console.error(error);
|
|
128
128
|
return { supplyApy: '0', borrowApy: '0' };
|
|
129
129
|
}),
|
|
130
|
-
|
|
130
|
+
// Merkl rewards are keyed by time: a historical block resolves to its timestamp first (one RPC
|
|
131
|
+
// call, none for 'latest') so the rewards in force at that moment are attached.
|
|
132
|
+
getBlockTimestamp(provider, blockNumber).then((asOfTimestamp) => getMorphoBlueMerklOpportunities(asOfTimestamp, network)),
|
|
131
133
|
]);
|
|
132
134
|
return addMorphoBlueMerklOpportunitiesToMarketInfo(addMorphoBlueRewardsToMarketInfo(marketInfo, rewards), selectedMarket, network, merklOpportunities);
|
|
133
135
|
});
|
|
134
136
|
}
|
|
135
|
-
export function _getMorphoBluePortfolioMarketData(provider, network, selectedMarket) {
|
|
136
|
-
return getMorphoBlueMarketDataInternal(provider, network, selectedMarket);
|
|
137
|
+
export function _getMorphoBluePortfolioMarketData(provider, network, selectedMarket, blockNumber = 'latest') {
|
|
138
|
+
return getMorphoBlueMarketDataInternal(provider, network, selectedMarket, blockNumber);
|
|
137
139
|
}
|
|
138
|
-
export function getMorphoBlueMarketData(
|
|
139
|
-
return __awaiter(this,
|
|
140
|
-
return _getMorphoBlueMarketData(getViemProvider(provider, network), network, selectedMarket);
|
|
140
|
+
export function getMorphoBlueMarketData(provider_1, network_1, selectedMarket_1) {
|
|
141
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, selectedMarket, blockNumber = 'latest') {
|
|
142
|
+
return _getMorphoBlueMarketData(getViemProvider(provider, network), network, selectedMarket, blockNumber);
|
|
141
143
|
});
|
|
142
144
|
}
|
|
143
|
-
export function getMorphoBluePortfolioMarketData(provider, network, selectedMarket) {
|
|
144
|
-
return _getMorphoBluePortfolioMarketData(getViemProvider(provider, network), network, selectedMarket);
|
|
145
|
+
export function getMorphoBluePortfolioMarketData(provider, network, selectedMarket, blockNumber = 'latest') {
|
|
146
|
+
return _getMorphoBluePortfolioMarketData(getViemProvider(provider, network), network, selectedMarket, blockNumber);
|
|
145
147
|
}
|
|
146
148
|
export const getMorphoBluePositionDataWithMarketInfo = (data, marketInfo) => (Object.assign(Object.assign({}, data), getMorphoBlueAggregatedPositionData({
|
|
147
149
|
usedAssets: data.usedAssets,
|
|
@@ -195,8 +197,8 @@ export const _getMorphoBlueAccountBalances = (provider, network, block, addressM
|
|
|
195
197
|
return balances;
|
|
196
198
|
});
|
|
197
199
|
export const getMorphoBlueAccountBalances = (provider, network, block, addressMapping, address, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () { return _getMorphoBlueAccountBalances(getViemProvider(provider, network), network, block, addressMapping, address, selectedMarket); });
|
|
198
|
-
export function _getMorphoBlueAccountData(
|
|
199
|
-
return __awaiter(this,
|
|
200
|
+
export function _getMorphoBlueAccountData(provider_1, network_1, account_1, selectedMarket_1, marketInfo_1) {
|
|
201
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, account, selectedMarket, marketInfo, blockNumber = 'latest') {
|
|
200
202
|
const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
|
|
201
203
|
const lltvInWei = new Dec(lltv).mul(WAD).toString();
|
|
202
204
|
const viewContract = MorphoBlueViewContractViem(provider, network);
|
|
@@ -205,7 +207,7 @@ export function _getMorphoBlueAccountData(provider, network, account, selectedMa
|
|
|
205
207
|
loanToken, collateralToken, oracle, irm, lltv: BigInt(lltvInWei),
|
|
206
208
|
},
|
|
207
209
|
account
|
|
208
|
-
]));
|
|
210
|
+
], setViemBlockNumber(blockNumber)));
|
|
209
211
|
const usedAssets = {};
|
|
210
212
|
const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
|
|
211
213
|
const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
|
|
@@ -235,13 +237,13 @@ export function _getMorphoBlueAccountData(provider, network, account, selectedMa
|
|
|
235
237
|
return Object.assign({ supplyShares: loanInfo.supplyShares.toString(), borrowShares: loanInfo.borrowShares.toString(), usedAssets }, getMorphoBlueAggregatedPositionData({ usedAssets, assetsData: marketInfo.assetsData, marketInfo }));
|
|
236
238
|
});
|
|
237
239
|
}
|
|
238
|
-
export function getMorphoBlueAccountData(
|
|
239
|
-
return __awaiter(this,
|
|
240
|
-
return _getMorphoBlueAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo);
|
|
240
|
+
export function getMorphoBlueAccountData(provider_1, network_1, account_1, selectedMarket_1, marketInfo_1) {
|
|
241
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, account, selectedMarket, marketInfo, blockNumber = 'latest') {
|
|
242
|
+
return _getMorphoBlueAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo, blockNumber);
|
|
241
243
|
});
|
|
242
244
|
}
|
|
243
|
-
export function getMorphoEarn(
|
|
244
|
-
return __awaiter(this,
|
|
245
|
+
export function getMorphoEarn(provider_1, network_1, account_1, selectedMarket_1, marketInfo_1) {
|
|
246
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, account, selectedMarket, marketInfo, blockNumber = 'latest') {
|
|
245
247
|
const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
|
|
246
248
|
const lltvInWei = new Dec(lltv).mul(WAD).toString();
|
|
247
249
|
const viewContract = MorphoBlueViewContractViem(provider, network);
|
|
@@ -250,7 +252,7 @@ export function getMorphoEarn(provider, network, account, selectedMarket, market
|
|
|
250
252
|
loanToken, collateralToken, oracle, irm, lltv: BigInt(lltvInWei),
|
|
251
253
|
},
|
|
252
254
|
account
|
|
253
|
-
]));
|
|
255
|
+
], setViemBlockNumber(blockNumber)));
|
|
254
256
|
const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
|
|
255
257
|
const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
|
|
256
258
|
const loanTokenSuppliedUsd = new Dec(loanTokenSupplied).mul(loanTokenInfo.price).toString();
|
|
@@ -24,10 +24,12 @@ export declare enum MorphoBlueMerklOpportunityType {
|
|
|
24
24
|
*/
|
|
25
25
|
export declare const addMorphoBlueMerklOpportunitiesToMarketInfo: (marketInfo: MorphoBlueMarketInfo, selectedMarket: MorphoBlueMarketData, chainId: NetworkNumber, opportunities: MerklOpportunity[]) => MorphoBlueMarketInfo;
|
|
26
26
|
/**
|
|
27
|
-
* Fetches live market-scoped Morpho Blue campaigns for all chains
|
|
28
|
-
*
|
|
27
|
+
* Fetches live market-scoped Morpho Blue campaigns for all chains (or one, when `chainId` is given).
|
|
28
|
+
* With `asOfTimestamp` (unix seconds) the campaigns and APRs are the ones Merkl had at that moment
|
|
29
|
+
* instead. Never throws — on any failure it returns an empty list, so Merkl being down can't break
|
|
30
|
+
* market data.
|
|
29
31
|
*/
|
|
30
|
-
export declare const getMorphoBlueMerklOpportunities: () => Promise<MerklOpportunity[]>;
|
|
32
|
+
export declare const getMorphoBlueMerklOpportunities: (asOfTimestamp?: number, chainId?: NetworkNumber) => Promise<MerklOpportunity[]>;
|
|
31
33
|
/**
|
|
32
34
|
* Fetches live Merkl campaigns and appends the ones for the market to its `assetsData` incentive
|
|
33
35
|
* arrays. Never throws — on any failure the market info is returned unchanged.
|
package/esm/morphoBlue/merkl.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { aprToApy } from '../moneymarket';
|
|
11
|
-
import {
|
|
11
|
+
import { fetchMerklOpportunities } from '../services/merkl';
|
|
12
12
|
import { IncentiveKind, OpportunityStatus, } from '../types';
|
|
13
13
|
/**
|
|
14
14
|
* Merkl tags Morpho Blue market-level reward campaigns via the opportunity `type` field:
|
|
@@ -73,16 +73,14 @@ export const addMorphoBlueMerklOpportunitiesToMarketInfo = (marketInfo, selected
|
|
|
73
73
|
return Object.assign(Object.assign({}, marketInfo), { assetsData: Object.assign(Object.assign({}, marketInfo.assetsData), { [marketInfo.collateralToken]: Object.assign(Object.assign({}, collateralAsset), { supplyIncentives: [...withoutMerklIncentives(collateralAsset.supplyIncentives), ...collateralSupply] }), [marketInfo.loanToken]: Object.assign(Object.assign({}, loanAsset), { supplyIncentives: [...withoutMerklIncentives(loanAsset.supplyIncentives), ...loanSupply], borrowIncentives: [...withoutMerklIncentives(loanAsset.borrowIncentives), ...loanBorrow] }) }) });
|
|
74
74
|
};
|
|
75
75
|
/**
|
|
76
|
-
* Fetches live market-scoped Morpho Blue campaigns for all chains
|
|
77
|
-
*
|
|
76
|
+
* Fetches live market-scoped Morpho Blue campaigns for all chains (or one, when `chainId` is given).
|
|
77
|
+
* With `asOfTimestamp` (unix seconds) the campaigns and APRs are the ones Merkl had at that moment
|
|
78
|
+
* instead. Never throws — on any failure it returns an empty list, so Merkl being down can't break
|
|
79
|
+
* market data.
|
|
78
80
|
*/
|
|
79
|
-
export const getMorphoBlueMerklOpportunities = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
export const getMorphoBlueMerklOpportunities = (asOfTimestamp, chainId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
82
|
try {
|
|
81
|
-
return yield
|
|
82
|
-
mainProtocolId: 'morpho',
|
|
83
|
-
type: Object.values(MorphoBlueMerklOpportunityType).join(','),
|
|
84
|
-
status: OpportunityStatus.LIVE,
|
|
85
|
-
});
|
|
83
|
+
return yield fetchMerklOpportunities(Object.assign({ mainProtocolId: 'morpho', type: Object.values(MorphoBlueMerklOpportunityType).join(','), status: OpportunityStatus.LIVE }, (chainId ? { chainId: chainId.toString() } : {})), asOfTimestamp);
|
|
86
84
|
}
|
|
87
85
|
catch (e) {
|
|
88
86
|
console.error('Failed to fetch Morpho Blue Merkl campaigns', e);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import { Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances } from '../types/common';
|
|
3
3
|
import { MorphoMidnightMarketData, MorphoMidnightMarketInfo, MorphoMidnightPositionData } from '../types';
|
|
4
|
-
export declare function _getMorphoMidnightMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoMidnightMarketData): Promise<MorphoMidnightMarketInfo>;
|
|
5
|
-
export declare function getMorphoMidnightMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoMidnightMarketData): Promise<MorphoMidnightMarketInfo>;
|
|
6
|
-
export declare function _getMorphoMidnightAccountData(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoMidnightMarketData, marketInfo: MorphoMidnightMarketInfo): Promise<MorphoMidnightPositionData>;
|
|
7
|
-
export declare function getMorphoMidnightAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoMidnightMarketData, marketInfo: MorphoMidnightMarketInfo): Promise<MorphoMidnightPositionData>;
|
|
4
|
+
export declare function _getMorphoMidnightMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoMidnightMarketData, blockNumber?: Blockish): Promise<MorphoMidnightMarketInfo>;
|
|
5
|
+
export declare function getMorphoMidnightMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoMidnightMarketData, blockNumber?: Blockish): Promise<MorphoMidnightMarketInfo>;
|
|
6
|
+
export declare function _getMorphoMidnightAccountData(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoMidnightMarketData, marketInfo: MorphoMidnightMarketInfo, blockNumber?: Blockish): Promise<MorphoMidnightPositionData>;
|
|
7
|
+
export declare function getMorphoMidnightAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoMidnightMarketData, marketInfo: MorphoMidnightMarketInfo, blockNumber?: Blockish): Promise<MorphoMidnightPositionData>;
|
|
8
8
|
export declare const _getMorphoMidnightAccountBalances: (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, selectedMarket: MorphoMidnightMarketData, includeCredit?: boolean) => Promise<PositionBalances>;
|
|
9
9
|
export declare const getMorphoMidnightAccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, selectedMarket: MorphoMidnightMarketData) => Promise<PositionBalances>;
|
|
10
|
-
export declare function getMorphoMidnightEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoMidnightMarketData, marketInfo: MorphoMidnightMarketInfo): Promise<{
|
|
10
|
+
export declare function getMorphoMidnightEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoMidnightMarketData, marketInfo: MorphoMidnightMarketInfo, blockNumber?: Blockish): Promise<{
|
|
11
11
|
apy: string;
|
|
12
12
|
amount: string;
|
|
13
13
|
amountUsd: string;
|
|
@@ -20,8 +20,8 @@ import { getChainlinkAssetAddress } from '../services/priceService';
|
|
|
20
20
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
21
21
|
const HARDCODED_USD_STABLE_PRICE = '100000000'; // $1 with 8 decimals
|
|
22
22
|
const nowInSeconds = () => Math.floor(Date.now() / 1000);
|
|
23
|
-
export function _getMorphoMidnightMarketData(
|
|
24
|
-
return __awaiter(this,
|
|
23
|
+
export function _getMorphoMidnightMarketData(provider_1, network_1, selectedMarket_1) {
|
|
24
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, selectedMarket, blockNumber = 'latest') {
|
|
25
25
|
const { loanToken, collaterals, marketId } = selectedMarket;
|
|
26
26
|
const loanTokenInfo = getAssetInfoByAddress(loanToken, network);
|
|
27
27
|
const loanSym = wethToEth(loanTokenInfo.symbol);
|
|
@@ -33,8 +33,8 @@ export function _getMorphoMidnightMarketData(provider, network, selectedMarket)
|
|
|
33
33
|
if (isMainnetNetwork(network)) {
|
|
34
34
|
const feedRegistryContract = FeedRegistryContractViem(provider, NetworkNumber.Eth);
|
|
35
35
|
const [_loanTokenPrice, _marketInfo] = yield Promise.all([
|
|
36
|
-
isHardcodedUsdStable ? Promise.resolve(HARDCODED_USD_STABLE_PRICE) : feedRegistryContract.read.latestAnswer([loanTokenFeedAddress, USD_QUOTE]),
|
|
37
|
-
viewContract.read.getMarketInfo([marketId]),
|
|
36
|
+
isHardcodedUsdStable ? Promise.resolve(HARDCODED_USD_STABLE_PRICE) : feedRegistryContract.read.latestAnswer([loanTokenFeedAddress, USD_QUOTE], setViemBlockNumber(blockNumber)),
|
|
37
|
+
viewContract.read.getMarketInfo([marketId], setViemBlockNumber(blockNumber)),
|
|
38
38
|
]);
|
|
39
39
|
marketInfo = _marketInfo;
|
|
40
40
|
loanTokenPrice = _loanTokenPrice;
|
|
@@ -43,8 +43,8 @@ export function _getMorphoMidnightMarketData(provider, network, selectedMarket)
|
|
|
43
43
|
// Currently only Base is supported
|
|
44
44
|
const feedRegistryContract = DFSFeedRegistryContractViem(provider, network);
|
|
45
45
|
const [loanTokenPriceRound, _marketInfo] = yield Promise.all([
|
|
46
|
-
isHardcodedUsdStable ? Promise.resolve([0, HARDCODED_USD_STABLE_PRICE]) : feedRegistryContract.read.latestRoundData([loanTokenFeedAddress, USD_QUOTE]),
|
|
47
|
-
viewContract.read.getMarketInfo([marketId]),
|
|
46
|
+
isHardcodedUsdStable ? Promise.resolve([0, HARDCODED_USD_STABLE_PRICE]) : feedRegistryContract.read.latestRoundData([loanTokenFeedAddress, USD_QUOTE], setViemBlockNumber(blockNumber)),
|
|
47
|
+
viewContract.read.getMarketInfo([marketId], setViemBlockNumber(blockNumber)),
|
|
48
48
|
]);
|
|
49
49
|
marketInfo = _marketInfo;
|
|
50
50
|
loanTokenPrice = loanTokenPriceRound[1].toString();
|
|
@@ -114,16 +114,16 @@ export function _getMorphoMidnightMarketData(provider, network, selectedMarket)
|
|
|
114
114
|
};
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
|
-
export function getMorphoMidnightMarketData(
|
|
118
|
-
return __awaiter(this,
|
|
119
|
-
return _getMorphoMidnightMarketData(getViemProvider(provider, network), network, selectedMarket);
|
|
117
|
+
export function getMorphoMidnightMarketData(provider_1, network_1, selectedMarket_1) {
|
|
118
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, selectedMarket, blockNumber = 'latest') {
|
|
119
|
+
return _getMorphoMidnightMarketData(getViemProvider(provider, network), network, selectedMarket, blockNumber);
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
-
export function _getMorphoMidnightAccountData(
|
|
123
|
-
return __awaiter(this,
|
|
122
|
+
export function _getMorphoMidnightAccountData(provider_1, network_1, account_1, selectedMarket_1, marketInfo_1) {
|
|
123
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, account, selectedMarket, marketInfo, blockNumber = 'latest') {
|
|
124
124
|
const { marketId, collaterals } = selectedMarket;
|
|
125
125
|
const viewContract = MorphoMidnightViewContractViem(provider, network);
|
|
126
|
-
const positionInfo = yield viewContract.read.getPositionInfo([marketId, account]);
|
|
126
|
+
const positionInfo = yield viewContract.read.getPositionInfo([marketId, account], setViemBlockNumber(blockNumber));
|
|
127
127
|
const usedAssets = {};
|
|
128
128
|
const loanTokenData = marketInfo.assetsData[marketInfo.loanToken];
|
|
129
129
|
const credit = assetAmountInEth(positionInfo.credit.toString(), marketInfo.loanToken);
|
|
@@ -205,9 +205,9 @@ export function _getMorphoMidnightAccountData(provider, network, account, select
|
|
|
205
205
|
borrowInfoStatus, maturity: marketInfo.maturity, isMatured: marketInfo.isMatured }, getMorphoMidnightAggregatedPositionData({ usedAssets, assetsData: assetsDataForApy, marketInfo }));
|
|
206
206
|
});
|
|
207
207
|
}
|
|
208
|
-
export function getMorphoMidnightAccountData(
|
|
209
|
-
return __awaiter(this,
|
|
210
|
-
return _getMorphoMidnightAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo);
|
|
208
|
+
export function getMorphoMidnightAccountData(provider_1, network_1, account_1, selectedMarket_1, marketInfo_1) {
|
|
209
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, account, selectedMarket, marketInfo, blockNumber = 'latest') {
|
|
210
|
+
return _getMorphoMidnightAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo, blockNumber);
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
213
|
export const _getMorphoMidnightAccountBalances = (provider_1, network_1, block_1, addressMapping_1, address_1, selectedMarket_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, block_1, addressMapping_1, address_1, selectedMarket_1, ...args_1], void 0, function* (provider, network, block, addressMapping, address, selectedMarket, includeCredit = false) {
|
|
@@ -240,11 +240,11 @@ export const _getMorphoMidnightAccountBalances = (provider_1, network_1, block_1
|
|
|
240
240
|
export const getMorphoMidnightAccountBalances = (provider, network, block, addressMapping, address, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () { return _getMorphoMidnightAccountBalances(getViemProvider(provider, network), network, block, addressMapping, address, selectedMarket); });
|
|
241
241
|
// Lender-side (credit-only) supply position, mirroring getMorphoEarn. `amount` is the credit face value
|
|
242
242
|
// redeemable at maturity; `apy` is '0' in MVP because the fixed yield is orderbook-derived, not on-chain.
|
|
243
|
-
export function getMorphoMidnightEarn(
|
|
244
|
-
return __awaiter(this,
|
|
243
|
+
export function getMorphoMidnightEarn(provider_1, network_1, account_1, selectedMarket_1, marketInfo_1) {
|
|
244
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, account, selectedMarket, marketInfo, blockNumber = 'latest') {
|
|
245
245
|
const { marketId } = selectedMarket;
|
|
246
246
|
const viewContract = MorphoMidnightViewContractViem(provider, network);
|
|
247
|
-
const positionInfo = yield viewContract.read.getPositionInfo([marketId, account]);
|
|
247
|
+
const positionInfo = yield viewContract.read.getPositionInfo([marketId, account], setViemBlockNumber(blockNumber));
|
|
248
248
|
const loanTokenData = marketInfo.assetsData[marketInfo.loanToken];
|
|
249
249
|
const credit = assetAmountInEth(positionInfo.credit.toString(), marketInfo.loanToken);
|
|
250
250
|
const creditUsd = new Dec(credit).mul(loanTokenData.price).toString();
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
2
|
+
import { CustomDeFiData, CustomDeFiDataOptions } from '../types';
|
|
3
|
+
export declare function getCustomDeFiData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], options?: CustomDeFiDataOptions): Promise<CustomDeFiData>;
|