@defisaver/positions-sdk 0.0.96 → 0.0.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +63 -63
  2. package/cjs/markets/compound/marketsAssets.js +1 -1
  3. package/cjs/morphoBlue/index.d.ts +2 -1
  4. package/cjs/morphoBlue/index.js +29 -1
  5. package/esm/markets/compound/marketsAssets.js +1 -1
  6. package/esm/morphoBlue/index.d.ts +2 -1
  7. package/esm/morphoBlue/index.js +28 -1
  8. package/package.json +40 -40
  9. package/src/aaveV2/index.ts +227 -227
  10. package/src/aaveV3/index.ts +558 -558
  11. package/src/assets/index.ts +60 -60
  12. package/src/chickenBonds/index.ts +123 -123
  13. package/src/compoundV2/index.ts +219 -219
  14. package/src/compoundV3/index.ts +266 -266
  15. package/src/config/contracts.js +848 -848
  16. package/src/constants/index.ts +5 -5
  17. package/src/contracts.ts +128 -128
  18. package/src/curveUsd/index.ts +229 -229
  19. package/src/exchange/index.ts +17 -17
  20. package/src/helpers/aaveHelpers/index.ts +134 -134
  21. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  22. package/src/helpers/compoundHelpers/index.ts +181 -181
  23. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  24. package/src/helpers/index.ts +7 -7
  25. package/src/helpers/llamaLendHelpers/index.ts +45 -45
  26. package/src/helpers/makerHelpers/index.ts +94 -94
  27. package/src/helpers/morphoBlueHelpers/index.ts +56 -56
  28. package/src/helpers/sparkHelpers/index.ts +106 -106
  29. package/src/index.ts +46 -46
  30. package/src/liquity/index.ts +116 -116
  31. package/src/llamaLend/index.ts +268 -268
  32. package/src/maker/index.ts +117 -117
  33. package/src/markets/aave/index.ts +80 -80
  34. package/src/markets/aave/marketAssets.ts +24 -24
  35. package/src/markets/compound/index.ts +142 -142
  36. package/src/markets/compound/marketsAssets.ts +50 -50
  37. package/src/markets/curveUsd/index.ts +69 -69
  38. package/src/markets/index.ts +5 -5
  39. package/src/markets/llamaLend/contractAddresses.ts +95 -95
  40. package/src/markets/llamaLend/index.ts +150 -150
  41. package/src/markets/morphoBlue/index.ts +611 -611
  42. package/src/markets/spark/index.ts +29 -29
  43. package/src/markets/spark/marketAssets.ts +10 -10
  44. package/src/moneymarket/moneymarketCommonService.ts +76 -76
  45. package/src/morphoAaveV2/index.ts +256 -256
  46. package/src/morphoAaveV3/index.ts +612 -612
  47. package/src/morphoBlue/index.ts +199 -162
  48. package/src/multicall/index.ts +22 -22
  49. package/src/services/dsrService.ts +15 -15
  50. package/src/services/priceService.ts +21 -21
  51. package/src/services/utils.ts +51 -51
  52. package/src/setup.ts +8 -8
  53. package/src/spark/index.ts +424 -424
  54. package/src/staking/staking.ts +187 -187
  55. package/src/types/aave.ts +256 -256
  56. package/src/types/chickenBonds.ts +45 -45
  57. package/src/types/common.ts +84 -84
  58. package/src/types/compound.ts +128 -128
  59. package/src/types/curveUsd.ts +118 -118
  60. package/src/types/index.ts +8 -8
  61. package/src/types/liquity.ts +30 -30
  62. package/src/types/llamaLend.ts +143 -143
  63. package/src/types/maker.ts +50 -50
  64. package/src/types/morphoBlue.ts +139 -139
  65. package/src/types/spark.ts +106 -106
package/README.md CHANGED
@@ -1,63 +1,63 @@
1
- # DeFi Saver Positions SDK
2
-
3
- Supported protocols:
4
- - [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
5
- - [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
6
- - [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
7
- - [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
8
- - [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
9
- - [Morpho Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV2)
10
- - [Morpho Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV3)
11
- - [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
12
- - [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
13
- - [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
14
- - [Chicken Bonds](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/chickenBonds)
15
-
16
- ## Setup
17
- Supported Node version is v10.
18
-
19
- - run `npm install` (first time)
20
- - run `npm run build`
21
-
22
- `build` command will generate contracts and build ejs and esm folders
23
-
24
- ## How to use
25
- [All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
26
-
27
- This is a Compound V3 example, and every other protocol is similar
28
- ```js
29
- import Web3 from 'web3';
30
- import { compoundV3 } from '@defisaver/positions-sdk';
31
-
32
-
33
- // every protocol has market data and user data getters
34
- const {
35
- getCompoundV3MarketsData,
36
- getCompoundV3AccountData,
37
- } = compoundV3;
38
-
39
- const provider = 'Your RPC provider';
40
- const web3 = new Web3(provider);
41
-
42
- const user = '0x123...';
43
-
44
- const { assetsData } = await getCompoundV3MarketsData(
45
- web3, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
46
- 1, // network
47
- selectedMarket, // market object like in /src/markets/compound/index.ts
48
- web3, // this must be mainnet rpc - used for getting prices onchain and calculating apys
49
- );
50
-
51
- const userData = await getCompoundV3AccountData(
52
- web3,
53
- 1, // network
54
- userAddress, // EOA or DSProxy
55
- '', // proxy address of the user, or just empty string if checking for EOA
56
- {
57
- selectedMarket, // market object as in /src/markets/compound/index.ts
58
- assetsData,
59
- }
60
- );
61
- ```
62
-
63
- More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
1
+ # DeFi Saver Positions SDK
2
+
3
+ Supported protocols:
4
+ - [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
5
+ - [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
6
+ - [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
7
+ - [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
8
+ - [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
9
+ - [Morpho Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV2)
10
+ - [Morpho Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV3)
11
+ - [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
12
+ - [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
13
+ - [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
14
+ - [Chicken Bonds](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/chickenBonds)
15
+
16
+ ## Setup
17
+ Supported Node version is v10.
18
+
19
+ - run `npm install` (first time)
20
+ - run `npm run build`
21
+
22
+ `build` command will generate contracts and build ejs and esm folders
23
+
24
+ ## How to use
25
+ [All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
26
+
27
+ This is a Compound V3 example, and every other protocol is similar
28
+ ```js
29
+ import Web3 from 'web3';
30
+ import { compoundV3 } from '@defisaver/positions-sdk';
31
+
32
+
33
+ // every protocol has market data and user data getters
34
+ const {
35
+ getCompoundV3MarketsData,
36
+ getCompoundV3AccountData,
37
+ } = compoundV3;
38
+
39
+ const provider = 'Your RPC provider';
40
+ const web3 = new Web3(provider);
41
+
42
+ const user = '0x123...';
43
+
44
+ const { assetsData } = await getCompoundV3MarketsData(
45
+ web3, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
46
+ 1, // network
47
+ selectedMarket, // market object like in /src/markets/compound/index.ts
48
+ web3, // this must be mainnet rpc - used for getting prices onchain and calculating apys
49
+ );
50
+
51
+ const userData = await getCompoundV3AccountData(
52
+ web3,
53
+ 1, // network
54
+ userAddress, // EOA or DSProxy
55
+ '', // proxy address of the user, or just empty string if checking for EOA
56
+ {
57
+ selectedMarket, // market object as in /src/markets/compound/index.ts
58
+ assetsData,
59
+ }
60
+ );
61
+ ```
62
+
63
+ More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
@@ -26,7 +26,7 @@ exports.v3USDCeCollAssets = {
26
26
  [common_1.NetworkNumber.Arb]: exports.v3USDCeCollAssetsArb,
27
27
  [common_1.NetworkNumber.Base]: [],
28
28
  };
29
- exports.v3ETHCollAssetsEth = ['cbETH', 'wstETH', 'rETH', 'rsETH'];
29
+ exports.v3ETHCollAssetsEth = ['cbETH', 'wstETH', 'rETH', 'rsETH', 'weETH'];
30
30
  exports.v3ETHCollAssetsBase = ['cbETH'];
31
31
  // @dev Keep assets in array, do not assign directly, so we can parse it and edit it programmatically with `scripts/updateMarkets`
32
32
  exports.v3ETHCollAssets = {
@@ -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>;
@@ -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.getMorphoBlueAccountData = exports.getMorphoBlueMarketData = void 0;
15
+ exports.getMorphoBlueAccountData = exports.getMorphoBlueAccountBalances = exports.getMorphoBlueMarketData = void 0;
16
16
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
17
  const tokens_1 = require("@defisaver/tokens");
18
18
  const common_1 = require("../types/common");
@@ -108,6 +108,34 @@ function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWeb3) {
108
108
  });
109
109
  }
110
110
  exports.getMorphoBlueMarketData = getMorphoBlueMarketData;
111
+ const getMorphoBlueAccountBalances = (web3, network, block, addressMapping, address, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () {
112
+ let balances = {
113
+ collateral: {},
114
+ debt: {},
115
+ };
116
+ if (!address) {
117
+ return balances;
118
+ }
119
+ const viewContract = (0, contracts_1.MorphoBlueViewContract)(web3, network, block);
120
+ const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
121
+ const lltvInWei = new decimal_js_1.default(lltv).mul(constants_1.WAD).toString();
122
+ const marketObject = {
123
+ loanToken, collateralToken, oracle, irm, lltv: lltvInWei,
124
+ };
125
+ const loanInfo = yield viewContract.methods.getUserInfo(marketObject, address).call({}, block);
126
+ const loanTokenInfo = (0, tokens_1.getAssetInfoByAddress)(selectedMarket.loanToken, network);
127
+ const collateralTokenInfo = (0, tokens_1.getAssetInfoByAddress)(selectedMarket.collateralToken, network);
128
+ balances = {
129
+ collateral: {
130
+ [addressMapping ? collateralTokenInfo.address.toLowerCase() : (0, utils_1.wethToEth)(collateralTokenInfo.symbol)]: (0, tokens_1.assetAmountInEth)(loanInfo.collateral, collateralTokenInfo.symbol),
131
+ },
132
+ debt: {
133
+ [addressMapping ? loanTokenInfo.address.toLowerCase() : (0, utils_1.wethToEth)(loanTokenInfo.symbol)]: (0, tokens_1.assetAmountInEth)(loanInfo.borrowedInAssets, loanTokenInfo.symbol),
134
+ },
135
+ };
136
+ return balances;
137
+ });
138
+ exports.getMorphoBlueAccountBalances = getMorphoBlueAccountBalances;
111
139
  function getMorphoBlueAccountData(web3, network, account, selectedMarket, marketInfo) {
112
140
  return __awaiter(this, void 0, void 0, function* () {
113
141
  const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
@@ -23,7 +23,7 @@ export const v3USDCeCollAssets = {
23
23
  [NetworkNumber.Arb]: v3USDCeCollAssetsArb,
24
24
  [NetworkNumber.Base]: [],
25
25
  };
26
- export const v3ETHCollAssetsEth = ['cbETH', 'wstETH', 'rETH', 'rsETH'];
26
+ export const v3ETHCollAssetsEth = ['cbETH', 'wstETH', 'rETH', 'rsETH', 'weETH'];
27
27
  export const v3ETHCollAssetsBase = ['cbETH'];
28
28
  // @dev Keep assets in array, do not assign directly, so we can parse it and edit it programmatically with `scripts/updateMarkets`
29
29
  export const v3ETHCollAssets = {
@@ -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>;
@@ -9,7 +9,7 @@ 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
14
  import { WAD, SECONDS_PER_YEAR, USD_QUOTE } from '../constants';
15
15
  import { getStakingApy, STAKING_ASSETS } from '../staking';
@@ -101,6 +101,33 @@ export function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWe
101
101
  };
102
102
  });
103
103
  }
104
+ export const getMorphoBlueAccountBalances = (web3, network, block, addressMapping, address, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () {
105
+ let balances = {
106
+ collateral: {},
107
+ debt: {},
108
+ };
109
+ if (!address) {
110
+ return balances;
111
+ }
112
+ const viewContract = MorphoBlueViewContract(web3, network, block);
113
+ const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
114
+ const lltvInWei = new Dec(lltv).mul(WAD).toString();
115
+ const marketObject = {
116
+ loanToken, collateralToken, oracle, irm, lltv: lltvInWei,
117
+ };
118
+ const loanInfo = yield viewContract.methods.getUserInfo(marketObject, address).call({}, block);
119
+ const loanTokenInfo = getAssetInfoByAddress(selectedMarket.loanToken, network);
120
+ const collateralTokenInfo = getAssetInfoByAddress(selectedMarket.collateralToken, network);
121
+ balances = {
122
+ collateral: {
123
+ [addressMapping ? collateralTokenInfo.address.toLowerCase() : wethToEth(collateralTokenInfo.symbol)]: assetAmountInEth(loanInfo.collateral, collateralTokenInfo.symbol),
124
+ },
125
+ debt: {
126
+ [addressMapping ? loanTokenInfo.address.toLowerCase() : wethToEth(loanTokenInfo.symbol)]: assetAmountInEth(loanInfo.borrowedInAssets, loanTokenInfo.symbol),
127
+ },
128
+ };
129
+ return balances;
130
+ });
104
131
  export function getMorphoBlueAccountData(web3, network, account, selectedMarket, marketInfo) {
105
132
  return __awaiter(this, void 0, void 0, function* () {
106
133
  const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
package/package.json CHANGED
@@ -1,40 +1,40 @@
1
- {
2
- "name": "@defisaver/positions-sdk",
3
- "version": "0.0.96",
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.98",
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
+ }