@defisaver/positions-sdk 0.0.97 → 0.0.99
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/README.md +63 -63
- package/cjs/config/contracts.d.ts +45 -1
- package/cjs/config/contracts.js +3 -3
- package/cjs/helpers/morphoBlueHelpers/index.d.ts +9 -2
- package/cjs/helpers/morphoBlueHelpers/index.js +66 -1
- package/cjs/morphoBlue/index.d.ts +2 -1
- package/cjs/morphoBlue/index.js +33 -28
- package/cjs/types/contracts/generated/MorphoBlueView.d.ts +61 -0
- package/esm/config/contracts.d.ts +45 -1
- package/esm/config/contracts.js +3 -3
- package/esm/helpers/morphoBlueHelpers/index.d.ts +9 -2
- package/esm/helpers/morphoBlueHelpers/index.js +62 -0
- package/esm/morphoBlue/index.d.ts +2 -1
- package/esm/morphoBlue/index.js +32 -28
- package/esm/types/contracts/generated/MorphoBlueView.d.ts +61 -0
- package/package.json +40 -40
- package/src/aaveV2/index.ts +227 -227
- package/src/aaveV3/index.ts +558 -558
- package/src/assets/index.ts +60 -60
- package/src/chickenBonds/index.ts +123 -123
- package/src/compoundV2/index.ts +219 -219
- package/src/compoundV3/index.ts +266 -266
- package/src/config/contracts.js +848 -848
- package/src/constants/index.ts +5 -5
- package/src/contracts.ts +128 -128
- package/src/curveUsd/index.ts +229 -229
- package/src/exchange/index.ts +17 -17
- package/src/helpers/aaveHelpers/index.ts +134 -134
- package/src/helpers/chickenBondsHelpers/index.ts +23 -23
- package/src/helpers/compoundHelpers/index.ts +181 -181
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/index.ts +7 -7
- package/src/helpers/llamaLendHelpers/index.ts +45 -45
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/morphoBlueHelpers/index.ts +117 -56
- package/src/helpers/sparkHelpers/index.ts +106 -106
- package/src/index.ts +46 -46
- package/src/liquity/index.ts +116 -116
- package/src/llamaLend/index.ts +268 -268
- package/src/maker/index.ts +117 -117
- package/src/markets/aave/index.ts +80 -80
- package/src/markets/aave/marketAssets.ts +24 -24
- package/src/markets/compound/index.ts +142 -142
- package/src/markets/compound/marketsAssets.ts +50 -50
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/index.ts +5 -5
- package/src/markets/llamaLend/contractAddresses.ts +95 -95
- package/src/markets/llamaLend/index.ts +150 -150
- package/src/markets/morphoBlue/index.ts +611 -611
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +10 -10
- package/src/moneymarket/moneymarketCommonService.ts +76 -76
- package/src/morphoAaveV2/index.ts +256 -256
- package/src/morphoAaveV3/index.ts +612 -612
- package/src/morphoBlue/index.ts +171 -162
- package/src/multicall/index.ts +22 -22
- package/src/services/dsrService.ts +15 -15
- package/src/services/priceService.ts +21 -21
- package/src/services/utils.ts +51 -51
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +424 -424
- package/src/staking/staking.ts +187 -187
- package/src/types/aave.ts +256 -256
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +84 -84
- package/src/types/compound.ts +128 -128
- package/src/types/contracts/generated/MorphoBlueView.ts +87 -0
- package/src/types/curveUsd.ts +118 -118
- package/src/types/index.ts +8 -8
- package/src/types/liquity.ts +30 -30
- package/src/types/llamaLend.ts +143 -143
- package/src/types/maker.ts +50 -50
- package/src/types/morphoBlue.ts +139 -139
- package/src/types/spark.ts +106 -106
package/esm/config/contracts.js
CHANGED
|
@@ -818,13 +818,13 @@ module.exports = {
|
|
|
818
818
|
}
|
|
819
819
|
},
|
|
820
820
|
"MorphoBlueView": {
|
|
821
|
-
"abi": [{ "inputs": [], "name": "MORPHO_BLUE_ADDRESS", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketId", "outputs": [{ "internalType": "Id", "name": "id", "type": "bytes32" }], "stateMutability": "pure", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketInfo", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "name": "getMarketInfoNotTuple", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getUserInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "supplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "suppliedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "borrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "borrowedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }], "internalType": "struct MorphoBlueView.PositionInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "morphoBlue", "outputs": [{ "internalType": "contract IMorphoBlue", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }],
|
|
821
|
+
"abi": [{ "inputs": [], "name": "MORPHO_BLUE_ADDRESS", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "bool", "name": "isBorrowOperation", "type": "bool" }, { "internalType": "uint256", "name": "liquidityAdded", "type": "uint256" }, { "internalType": "uint256", "name": "liquidityRemoved", "type": "uint256" }], "internalType": "struct MorphoBlueView.LiquidityChangeParams", "name": "params", "type": "tuple" }], "name": "getApyAfterValuesEstimation", "outputs": [{ "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "components": [{ "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint128", "name": "lastUpdate", "type": "uint128" }, { "internalType": "uint128", "name": "fee", "type": "uint128" }], "internalType": "struct Market", "name": "market", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketId", "outputs": [{ "internalType": "Id", "name": "id", "type": "bytes32" }], "stateMutability": "pure", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }], "name": "getMarketInfo", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "name": "getMarketInfoNotTuple", "outputs": [{ "components": [{ "internalType": "Id", "name": "id", "type": "bytes32" }, { "internalType": "uint128", "name": "totalSupplyAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalSupplyShares", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowAssets", "type": "uint128" }, { "internalType": "uint128", "name": "totalBorrowShares", "type": "uint128" }, { "internalType": "uint256", "name": "lastUpdate", "type": "uint256" }, { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "internalType": "uint256", "name": "borrowRate", "type": "uint256" }, { "internalType": "uint256", "name": "oracle", "type": "uint256" }], "internalType": "struct MorphoBlueView.MarketInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "Id", "name": "marketId", "type": "bytes32" }, { "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatio", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "Id", "name": "marketId", "type": "bytes32" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatioUsingId", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getRatioUsingParams", "outputs": [{ "internalType": "uint256", "name": "ratio", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "loanToken", "type": "address" }, { "internalType": "address", "name": "collateralToken", "type": "address" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "uint256", "name": "lltv", "type": "uint256" }], "internalType": "struct MarketParams", "name": "marketParams", "type": "tuple" }, { "internalType": "address", "name": "owner", "type": "address" }], "name": "getUserInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "supplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "suppliedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "borrowShares", "type": "uint256" }, { "internalType": "uint256", "name": "borrowedInAssets", "type": "uint256" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }], "internalType": "struct MorphoBlueView.PositionInfo", "name": "", "type": "tuple" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "morphoBlue", "outputs": [{ "internalType": "contract IMorphoBlue", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }],
|
|
822
822
|
"networks": {
|
|
823
823
|
"1": {
|
|
824
|
-
"address": "
|
|
824
|
+
"address": "0x10B621823D4f3E85fBDF759e252598e4e097C1fd",
|
|
825
825
|
},
|
|
826
826
|
"8453": {
|
|
827
|
-
"address": "
|
|
827
|
+
"address": "0x53c0E962bd0AC53928ca04703238b2ec2894195B",
|
|
828
828
|
}
|
|
829
829
|
}
|
|
830
830
|
},
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import Web3 from 'web3';
|
|
2
|
+
import { MMUsedAssets, NetworkNumber } from '../../types/common';
|
|
3
|
+
import { MorphoBlueAggregatedPositionData, MorphoBlueAssetsData, MorphoBlueMarketData, MorphoBlueMarketInfo } from '../../types';
|
|
3
4
|
export declare const getMorphoBlueAggregatedPositionData: ({ usedAssets, assetsData, marketInfo }: {
|
|
4
5
|
usedAssets: MMUsedAssets;
|
|
5
6
|
assetsData: MorphoBlueAssetsData;
|
|
6
7
|
marketInfo: MorphoBlueMarketInfo;
|
|
7
8
|
}) => MorphoBlueAggregatedPositionData;
|
|
9
|
+
export declare const getSupplyRate: (totalSupplyAssets: string, totalBorrowAssets: string, borrowRate: string, fee: string) => string;
|
|
10
|
+
export declare const getBorrowRate: (borrowRate: string, totalBorrowShares: string) => string;
|
|
11
|
+
export declare const getApyAfterValuesEstimation: (selectedMarket: MorphoBlueMarketData, action: string, amount: string, asset: string, web3: Web3, network: NetworkNumber) => Promise<{
|
|
12
|
+
borrowRate: string;
|
|
13
|
+
supplyRate: string;
|
|
14
|
+
}>;
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import Dec from 'decimal.js';
|
|
11
|
+
import { assetAmountInWei } from '@defisaver/tokens';
|
|
2
12
|
import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
|
|
3
13
|
import { calculateNetApy } from '../../staking';
|
|
14
|
+
import { SECONDS_PER_YEAR, WAD } from '../../constants';
|
|
15
|
+
import { MorphoBlueViewContract } from '../../contracts';
|
|
4
16
|
export const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, marketInfo }) => {
|
|
5
17
|
var _a, _b, _c, _d, _e, _f;
|
|
6
18
|
const payload = {};
|
|
@@ -39,3 +51,53 @@ export const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, ma
|
|
|
39
51
|
}
|
|
40
52
|
return payload;
|
|
41
53
|
};
|
|
54
|
+
const compound = (ratePerSeconds) => {
|
|
55
|
+
const compounding = new Dec(ratePerSeconds).mul(SECONDS_PER_YEAR).toString();
|
|
56
|
+
const apyNumber = Math.expm1(new Dec(compounding).div(WAD).toNumber());
|
|
57
|
+
return new Dec(apyNumber).mul(WAD).floor().toString();
|
|
58
|
+
};
|
|
59
|
+
export const getSupplyRate = (totalSupplyAssets, totalBorrowAssets, borrowRate, fee) => {
|
|
60
|
+
if (totalBorrowAssets === '0' || totalSupplyAssets === '0') {
|
|
61
|
+
return '0';
|
|
62
|
+
}
|
|
63
|
+
const utillization = new Dec(totalBorrowAssets).mul(WAD).div(totalSupplyAssets).ceil()
|
|
64
|
+
.toString();
|
|
65
|
+
const supplyRate = new Dec(utillization).mul(borrowRate).div(WAD).ceil()
|
|
66
|
+
.toString();
|
|
67
|
+
const ratePerSecond = new Dec(supplyRate).mul(new Dec(WAD).minus(fee)).div(WAD).ceil()
|
|
68
|
+
.toString();
|
|
69
|
+
return new Dec(compound(ratePerSecond)).div(1e18).mul(100).toString();
|
|
70
|
+
};
|
|
71
|
+
export const getBorrowRate = (borrowRate, totalBorrowShares) => {
|
|
72
|
+
if (totalBorrowShares === '0') {
|
|
73
|
+
return '0';
|
|
74
|
+
}
|
|
75
|
+
return new Dec(compound(borrowRate)).div(1e18).mul(100).toString();
|
|
76
|
+
};
|
|
77
|
+
const borrowOperations = ['borrow', 'payback'];
|
|
78
|
+
export const getApyAfterValuesEstimation = (selectedMarket, action, amount, asset, web3, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
const morphoBlueViewContract = MorphoBlueViewContract(web3, network);
|
|
80
|
+
const lltvInWei = assetAmountInWei(selectedMarket.lltv, 'ETH');
|
|
81
|
+
const marketData = [selectedMarket.loanToken, selectedMarket.collateralToken, selectedMarket.oracle, selectedMarket.irm, lltvInWei];
|
|
82
|
+
const isBorrowOperation = borrowOperations.includes(action);
|
|
83
|
+
const amountInWei = assetAmountInWei(amount, asset);
|
|
84
|
+
let liquidityAdded;
|
|
85
|
+
let liquidityRemoved;
|
|
86
|
+
if (isBorrowOperation) {
|
|
87
|
+
liquidityAdded = action === 'payback' ? amountInWei : '0';
|
|
88
|
+
liquidityRemoved = action === 'borrow' ? amountInWei : '0';
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
liquidityAdded = action === 'collateral' ? amountInWei : '0';
|
|
92
|
+
liquidityRemoved = action === 'withdraw' ? amountInWei : '0';
|
|
93
|
+
}
|
|
94
|
+
const data = yield morphoBlueViewContract.methods.getApyAfterValuesEstimation([
|
|
95
|
+
marketData,
|
|
96
|
+
isBorrowOperation,
|
|
97
|
+
liquidityAdded,
|
|
98
|
+
liquidityRemoved,
|
|
99
|
+
]).call();
|
|
100
|
+
const borrowRate = getBorrowRate(data.borrowRate, data.market.totalBorrowShares);
|
|
101
|
+
const supplyRate = getSupplyRate(data.market.totalSupplyAssets, data.market.totalBorrowAssets, data.borrowRate, data.market.fee);
|
|
102
|
+
return { borrowRate, supplyRate };
|
|
103
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Web3 from 'web3';
|
|
2
|
-
import { NetworkNumber } from '../types/common';
|
|
2
|
+
import { Blockish, EthAddress, NetworkNumber, PositionBalances } from '../types/common';
|
|
3
3
|
import { MorphoBlueMarketData, MorphoBlueMarketInfo, MorphoBluePositionData } from '../types';
|
|
4
4
|
export declare function getMorphoBlueMarketData(web3: Web3, network: NetworkNumber, selectedMarket: MorphoBlueMarketData, mainnetWeb3: Web3): Promise<MorphoBlueMarketInfo>;
|
|
5
|
+
export declare const getMorphoBlueAccountBalances: (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, selectedMarket: MorphoBlueMarketData) => Promise<PositionBalances>;
|
|
5
6
|
export declare function getMorphoBlueAccountData(web3: Web3, network: NetworkNumber, account: string, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData>;
|
package/esm/morphoBlue/index.js
CHANGED
|
@@ -9,35 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
12
|
-
import { NetworkNumber } from '../types/common';
|
|
12
|
+
import { NetworkNumber, } from '../types/common';
|
|
13
13
|
import { FeedRegistryContract, MorphoBlueViewContract, } from '../contracts';
|
|
14
|
-
import { WAD,
|
|
14
|
+
import { WAD, USD_QUOTE } from '../constants';
|
|
15
15
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
16
16
|
import { wethToEth } from '../services/utils';
|
|
17
|
-
import { getMorphoBlueAggregatedPositionData } from '../helpers/morphoBlueHelpers';
|
|
18
|
-
const compound = (ratePerSeconds) => {
|
|
19
|
-
const compounding = new Dec(ratePerSeconds).mul(SECONDS_PER_YEAR).toString();
|
|
20
|
-
const apyNumber = Math.expm1(new Dec(compounding).div(WAD).toNumber());
|
|
21
|
-
return new Dec(apyNumber).mul(WAD).floor().toString();
|
|
22
|
-
};
|
|
23
|
-
const getSupplyRate = (totalSupplyAssets, totalBorrowAssets, borrowRate, fee) => {
|
|
24
|
-
if (totalBorrowAssets === '0' || totalSupplyAssets === '0') {
|
|
25
|
-
return 0;
|
|
26
|
-
}
|
|
27
|
-
const utillization = new Dec(totalBorrowAssets).mul(WAD).div(totalSupplyAssets).ceil()
|
|
28
|
-
.toString();
|
|
29
|
-
const supplyRate = new Dec(utillization).mul(borrowRate).div(WAD).ceil()
|
|
30
|
-
.toString();
|
|
31
|
-
const ratePerSecond = new Dec(supplyRate).mul(new Dec(WAD).minus(fee)).div(WAD).ceil()
|
|
32
|
-
.toString();
|
|
33
|
-
return compound(ratePerSecond);
|
|
34
|
-
};
|
|
35
|
-
const getBorrowRate = (borrowRate, totalBorrowShares) => {
|
|
36
|
-
if (totalBorrowShares === '0') {
|
|
37
|
-
return 0;
|
|
38
|
-
}
|
|
39
|
-
return compound(borrowRate);
|
|
40
|
-
};
|
|
17
|
+
import { getBorrowRate, getMorphoBlueAggregatedPositionData, getSupplyRate } from '../helpers/morphoBlueHelpers';
|
|
41
18
|
export function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWeb3) {
|
|
42
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
20
|
const { loanToken, collateralToken, oracle, irm, lltv, oracleType, } = selectedMarket;
|
|
@@ -67,8 +44,8 @@ export function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWe
|
|
|
67
44
|
symbol: wethToEth(loanTokenInfo.symbol),
|
|
68
45
|
address: loanToken,
|
|
69
46
|
price: new Dec(loanTokenPrice).div(1e8).toString(),
|
|
70
|
-
supplyRate
|
|
71
|
-
borrowRate:
|
|
47
|
+
supplyRate,
|
|
48
|
+
borrowRate: compoundedBorrowRate,
|
|
72
49
|
totalSupply: new Dec(marketInfo.totalSupplyAssets).div(scale).toString(),
|
|
73
50
|
totalBorrow: new Dec(marketInfo.totalBorrowAssets).div(scale).toString(),
|
|
74
51
|
canBeSupplied: true,
|
|
@@ -101,6 +78,33 @@ export function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWe
|
|
|
101
78
|
};
|
|
102
79
|
});
|
|
103
80
|
}
|
|
81
|
+
export const getMorphoBlueAccountBalances = (web3, network, block, addressMapping, address, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
+
let balances = {
|
|
83
|
+
collateral: {},
|
|
84
|
+
debt: {},
|
|
85
|
+
};
|
|
86
|
+
if (!address) {
|
|
87
|
+
return balances;
|
|
88
|
+
}
|
|
89
|
+
const viewContract = MorphoBlueViewContract(web3, network, block);
|
|
90
|
+
const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
|
|
91
|
+
const lltvInWei = new Dec(lltv).mul(WAD).toString();
|
|
92
|
+
const marketObject = {
|
|
93
|
+
loanToken, collateralToken, oracle, irm, lltv: lltvInWei,
|
|
94
|
+
};
|
|
95
|
+
const loanInfo = yield viewContract.methods.getUserInfo(marketObject, address).call({}, block);
|
|
96
|
+
const loanTokenInfo = getAssetInfoByAddress(selectedMarket.loanToken, network);
|
|
97
|
+
const collateralTokenInfo = getAssetInfoByAddress(selectedMarket.collateralToken, network);
|
|
98
|
+
balances = {
|
|
99
|
+
collateral: {
|
|
100
|
+
[addressMapping ? collateralTokenInfo.address.toLowerCase() : wethToEth(collateralTokenInfo.symbol)]: assetAmountInEth(loanInfo.collateral, collateralTokenInfo.symbol),
|
|
101
|
+
},
|
|
102
|
+
debt: {
|
|
103
|
+
[addressMapping ? loanTokenInfo.address.toLowerCase() : wethToEth(loanTokenInfo.symbol)]: assetAmountInEth(loanInfo.borrowedInAssets, loanTokenInfo.symbol),
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
return balances;
|
|
107
|
+
});
|
|
104
108
|
export function getMorphoBlueAccountData(web3, network, account, selectedMarket, marketInfo) {
|
|
105
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
110
|
const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
|
|
@@ -31,7 +31,58 @@ export type MarketParamsStructOutputStruct = {
|
|
|
31
31
|
lltv: string;
|
|
32
32
|
};
|
|
33
33
|
export type MarketParamsStructOutput = MarketParamsStructOutputArray & MarketParamsStructOutputStruct;
|
|
34
|
+
export type MarketStruct = [
|
|
35
|
+
number | string | BN,
|
|
36
|
+
number | string | BN,
|
|
37
|
+
number | string | BN,
|
|
38
|
+
number | string | BN,
|
|
39
|
+
number | string | BN,
|
|
40
|
+
number | string | BN
|
|
41
|
+
] | {
|
|
42
|
+
totalSupplyAssets: number | string | BN;
|
|
43
|
+
totalSupplyShares: number | string | BN;
|
|
44
|
+
totalBorrowAssets: number | string | BN;
|
|
45
|
+
totalBorrowShares: number | string | BN;
|
|
46
|
+
lastUpdate: number | string | BN;
|
|
47
|
+
fee: number | string | BN;
|
|
48
|
+
};
|
|
49
|
+
export type MarketStructOutputArray = [
|
|
50
|
+
string,
|
|
51
|
+
string,
|
|
52
|
+
string,
|
|
53
|
+
string,
|
|
54
|
+
string,
|
|
55
|
+
string
|
|
56
|
+
];
|
|
57
|
+
export type MarketStructOutputStruct = {
|
|
58
|
+
totalSupplyAssets: string;
|
|
59
|
+
totalSupplyShares: string;
|
|
60
|
+
totalBorrowAssets: string;
|
|
61
|
+
totalBorrowShares: string;
|
|
62
|
+
lastUpdate: string;
|
|
63
|
+
fee: string;
|
|
64
|
+
};
|
|
65
|
+
export type MarketStructOutput = MarketStructOutputArray & MarketStructOutputStruct;
|
|
34
66
|
export declare namespace MorphoBlueView {
|
|
67
|
+
type LiquidityChangeParamsStruct = [MarketParamsStruct, boolean, number | string | BN, number | string | BN] | {
|
|
68
|
+
marketParams: MarketParamsStruct;
|
|
69
|
+
isBorrowOperation: boolean;
|
|
70
|
+
liquidityAdded: number | string | BN;
|
|
71
|
+
liquidityRemoved: number | string | BN;
|
|
72
|
+
};
|
|
73
|
+
type LiquidityChangeParamsStructOutputArray = [
|
|
74
|
+
MarketParamsStructOutput,
|
|
75
|
+
boolean,
|
|
76
|
+
string,
|
|
77
|
+
string
|
|
78
|
+
];
|
|
79
|
+
type LiquidityChangeParamsStructOutputStruct = {
|
|
80
|
+
marketParams: MarketParamsStructOutput;
|
|
81
|
+
isBorrowOperation: boolean;
|
|
82
|
+
liquidityAdded: string;
|
|
83
|
+
liquidityRemoved: string;
|
|
84
|
+
};
|
|
85
|
+
type LiquidityChangeParamsStructOutput = LiquidityChangeParamsStructOutputArray & LiquidityChangeParamsStructOutputStruct;
|
|
35
86
|
type MarketInfoStruct = [
|
|
36
87
|
string | number[],
|
|
37
88
|
number | string | BN,
|
|
@@ -110,9 +161,19 @@ export interface MorphoBlueView extends BaseContract {
|
|
|
110
161
|
clone(): MorphoBlueView;
|
|
111
162
|
methods: {
|
|
112
163
|
MORPHO_BLUE_ADDRESS(): NonPayableTransactionObject<string>;
|
|
164
|
+
getApyAfterValuesEstimation(params: MorphoBlueView.LiquidityChangeParamsStruct): NonPayableTransactionObject<[
|
|
165
|
+
string,
|
|
166
|
+
MarketStructOutput
|
|
167
|
+
] & {
|
|
168
|
+
borrowRate: string;
|
|
169
|
+
market: MarketStructOutput;
|
|
170
|
+
}>;
|
|
113
171
|
getMarketId(marketParams: MarketParamsStruct): NonPayableTransactionObject<string>;
|
|
114
172
|
getMarketInfo(marketParams: MarketParamsStruct): NonPayableTransactionObject<MorphoBlueView.MarketInfoStructOutput>;
|
|
115
173
|
getMarketInfoNotTuple(loanToken: string, collToken: string, oracle: string, irm: string, lltv: number | string | BN): NonPayableTransactionObject<MorphoBlueView.MarketInfoStructOutput>;
|
|
174
|
+
getRatio(marketId: string | number[], marketParams: MarketParamsStruct, owner: string): NonPayableTransactionObject<string>;
|
|
175
|
+
getRatioUsingId(marketId: string | number[], owner: string): NonPayableTransactionObject<string>;
|
|
176
|
+
getRatioUsingParams(marketParams: MarketParamsStruct, owner: string): NonPayableTransactionObject<string>;
|
|
116
177
|
getUserInfo(marketParams: MarketParamsStruct, owner: string): NonPayableTransactionObject<MorphoBlueView.PositionInfoStructOutput>;
|
|
117
178
|
morphoBlue(): NonPayableTransactionObject<string>;
|
|
118
179
|
};
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@defisaver/positions-sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "./cjs/index.js",
|
|
6
|
-
"module": "./esm/index.js",
|
|
7
|
-
"types": "./esm/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build:esm": "rm -rf esm && tsc -p tsconfig.json",
|
|
10
|
-
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
|
|
11
|
-
"build": "npm run generate-contracts && npm run build:cjs && npm run build:esm",
|
|
12
|
-
"dev": "npm run generate-contracts && tsc -p tsconfig.cjs.json --watch",
|
|
13
|
-
"lint": "eslint src/ --fix",
|
|
14
|
-
"generate-contracts": "node scripts/generateContracts.js",
|
|
15
|
-
"test": "mocha tests/*",
|
|
16
|
-
"build-test": "npm run build && mocha tests/*"
|
|
17
|
-
},
|
|
18
|
-
"keywords": [],
|
|
19
|
-
"author": "",
|
|
20
|
-
"license": "ISC",
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"@defisaver/tokens": "^1.5.26",
|
|
23
|
-
"@ethersproject/bignumber": "^5.7.0",
|
|
24
|
-
"@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
|
|
25
|
-
"decimal.js": "^10.4.3"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@defisaver/eslint-config": "^1.0.1",
|
|
29
|
-
"chai": "^4.3.8",
|
|
30
|
-
"dotenv": "^16.3.1",
|
|
31
|
-
"eslint": "^8.49.0",
|
|
32
|
-
"mocha": "^10.2.0",
|
|
33
|
-
"typechain": "^8.3.1",
|
|
34
|
-
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
35
|
-
"typescript": "^5.2.2"
|
|
36
|
-
},
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"web3": "^1.10.2"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@defisaver/positions-sdk",
|
|
3
|
+
"version": "0.0.99",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./cjs/index.js",
|
|
6
|
+
"module": "./esm/index.js",
|
|
7
|
+
"types": "./esm/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build:esm": "rm -rf esm && tsc -p tsconfig.json",
|
|
10
|
+
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
|
|
11
|
+
"build": "npm run generate-contracts && npm run build:cjs && npm run build:esm",
|
|
12
|
+
"dev": "npm run generate-contracts && tsc -p tsconfig.cjs.json --watch",
|
|
13
|
+
"lint": "eslint src/ --fix",
|
|
14
|
+
"generate-contracts": "node scripts/generateContracts.js",
|
|
15
|
+
"test": "mocha tests/*",
|
|
16
|
+
"build-test": "npm run build && mocha tests/*"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [],
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "ISC",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@defisaver/tokens": "^1.5.26",
|
|
23
|
+
"@ethersproject/bignumber": "^5.7.0",
|
|
24
|
+
"@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
|
|
25
|
+
"decimal.js": "^10.4.3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@defisaver/eslint-config": "^1.0.1",
|
|
29
|
+
"chai": "^4.3.8",
|
|
30
|
+
"dotenv": "^16.3.1",
|
|
31
|
+
"eslint": "^8.49.0",
|
|
32
|
+
"mocha": "^10.2.0",
|
|
33
|
+
"typechain": "^8.3.1",
|
|
34
|
+
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
35
|
+
"typescript": "^5.2.2"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"web3": "^1.10.2"
|
|
39
|
+
}
|
|
40
|
+
}
|