@defisaver/positions-sdk 0.0.69 → 0.0.70

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.
@@ -140,7 +140,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
140
140
  if (nativeAsset && facilitatorsList && discountRate && minDiscountTokenBalance && minGhoBalanceForDiscount && ghoDiscountedPerDiscountToken) {
141
141
  const facilitatorBucket = yield ghoContract.methods.getFacilitatorBucket(facilitatorsList[0]).call();
142
142
  const availableFacilitatorCap = (0, tokens_1.assetAmountInEth)(new decimal_js_1.default(facilitatorBucket[0]).sub(facilitatorBucket[1]).toString(), 'GHO');
143
- borrowCap = decimal_js_1.default.min(borrowCap, availableFacilitatorCap).toString();
143
+ borrowCap = decimal_js_1.default.min(borrowCap, (0, tokens_1.assetAmountInEth)(facilitatorBucket[0], 'GHO')).toString();
144
144
  discountRateOnBorrow = (0, exports.aaveV3CalculateDiscountRate)(tokenMarket.totalBorrow.toString(), '3160881469228662060510133', // stkAAVE total supply
145
145
  discountRate, minDiscountTokenBalance, minGhoBalanceForDiscount, ghoDiscountedPerDiscountToken);
146
146
  }
@@ -7,7 +7,7 @@ exports.morphoAaveV2AssetDefaultMarket = ['DAI', 'ETH', 'USDC', 'USDT', 'WBTC',
7
7
  exports.morphoAaveV3AssetEthMarket = [
8
8
  'ETH', 'wstETH', 'DAI', 'USDC', 'WBTC', 'rETH', 'cbETH', 'sDAI', 'USDT',
9
9
  ];
10
- exports.aaveV3AssetsDefaultMarketEth = ['ETH', 'wstETH', 'WBTC', 'USDC', 'DAI', 'LINK', 'AAVE', 'cbETH', 'USDT', 'rETH', 'LUSD', 'CRV', 'MKR', 'SNX', 'BAL', 'UNI', 'LDO', 'ENS', '1INCH', 'FRAX', 'GHO', 'RPL', 'sDAI', 'STG', 'KNC', 'FXS', 'crvUSD', 'PYUSD', 'weETH'];
10
+ exports.aaveV3AssetsDefaultMarketEth = ['ETH', 'wstETH', 'WBTC', 'USDC', 'DAI', 'LINK', 'AAVE', 'cbETH', 'USDT', 'rETH', 'LUSD', 'CRV', 'MKR', 'SNX', 'BAL', 'UNI', 'LDO', 'ENS', '1INCH', 'FRAX', 'GHO', 'RPL', 'sDAI', 'STG', 'KNC', 'FXS', 'crvUSD', 'PYUSD', 'weETH', 'osETH'];
11
11
  exports.aaveV3AssetsDefaultMarketOpt = [
12
12
  'DAI', 'USDC.e', 'USDT', 'SUSD', 'AAVE', 'LINK', 'WBTC', 'ETH', 'OP', 'wstETH', 'LUSD', 'MAI', 'rETH', 'USDC',
13
13
  ];
@@ -44,7 +44,7 @@ const getLlamaLendMarketData = (market, network = 1) => (0, exports.LlamaLendMar
44
44
  exports.getLlamaLendMarketData = getLlamaLendMarketData;
45
45
  const getLlamaLendMarketFromControllerAddress = (controllerAddress, network) => {
46
46
  const markets = (0, exports.LlamaLendMarkets)(network);
47
- const market = Object.values(markets).find((market) => market.controllerAddress === controllerAddress);
47
+ const market = Object.values(markets).find((tempMarket) => tempMarket.controllerAddress === controllerAddress);
48
48
  if (!market)
49
49
  throw new Error('Market not found');
50
50
  return market;
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getStETHByWstETHMultiple = exports.getStETHByWstETH = exports.getWstETHByStETH = exports.calculateNetApy = exports.calculateInterestEarned = exports.getStakingApy = exports.STAKING_ASSETS = exports.getSUSDeApy = exports.getDsrApy = exports.getREthApr = exports.getCbETHApr = exports.getStETHApr = void 0;
16
16
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
+ const v3_sdk_1 = require("@stakewise/v3-sdk");
17
18
  const contracts_1 = require("../contracts");
18
19
  const common_1 = require("../types/common");
19
20
  const constants_1 = require("../constants");
@@ -93,12 +94,16 @@ const getSUSDeApy = () => __awaiter(void 0, void 0, void 0, function* () {
93
94
  });
94
95
  exports.getSUSDeApy = getSUSDeApy;
95
96
  const getWeEthApr = () => __awaiter(void 0, void 0, void 0, function* () {
96
- const res = yield fetch('https://www.etherfi.bid/api/etherfi/apr');
97
+ const res = yield fetch('https://app.defisaver.com/api/staking/apy?asset=weETH');
97
98
  const data = yield res.json();
98
- const total = data.latest_aprs.reduce((acc, apr) => new decimal_js_1.default(acc).add(apr).toString());
99
- return new decimal_js_1.default(total).div(data.latest_aprs.length).div(100).toString();
99
+ return data.apy;
100
+ });
101
+ const getOsETHApy = () => __awaiter(void 0, void 0, void 0, function* () {
102
+ const sdk = new v3_sdk_1.StakeWiseSDK({ network: v3_sdk_1.Network.Mainnet });
103
+ const apy = yield sdk.osToken.getAPY();
104
+ return apy;
100
105
  });
101
- exports.STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH'];
106
+ exports.STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe', 'osETH'];
102
107
  const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefined) => {
103
108
  try {
104
109
  if (asset === 'stETH' || asset === 'wstETH')
@@ -113,6 +118,8 @@ const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefine
113
118
  return (0, exports.getSUSDeApy)();
114
119
  if (asset === 'weETH')
115
120
  return getWeEthApr();
121
+ if (asset === 'osETH')
122
+ return getOsETHApy();
116
123
  }
117
124
  catch (e) {
118
125
  console.error(`Failed to fetch APY for ${asset}`);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LlamaLendStatus = exports.LlamaLendVersions = exports.LLVersionsArb = exports.LLVersionsEth = void 0;
4
4
  var LLVersionsEth;
5
5
  (function (LLVersionsEth) {
6
- //long only
6
+ // long only
7
7
  LLVersionsEth["LLWstethCrvusd"] = "llamaLendwstETHcrvUSD";
8
8
  LLVersionsEth["LLSusdeCrvusd"] = "llamaLendsUSDecrvUSD";
9
9
  // long and short crv
@@ -18,7 +18,7 @@ var LLVersionsEth;
18
18
  })(LLVersionsEth || (exports.LLVersionsEth = LLVersionsEth = {}));
19
19
  var LLVersionsArb;
20
20
  (function (LLVersionsArb) {
21
- //long only
21
+ // long only
22
22
  LLVersionsArb["LLArbCrvusd"] = "llamaLendArbcrvUSD";
23
23
  LLVersionsArb["LLFxnCrvusd"] = "llamaLendFXNcrvUSD";
24
24
  LLVersionsArb["LLWbtcCrvusd"] = "llamaLendWBTCcrvUSD";
@@ -131,7 +131,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
131
131
  if (nativeAsset && facilitatorsList && discountRate && minDiscountTokenBalance && minGhoBalanceForDiscount && ghoDiscountedPerDiscountToken) {
132
132
  const facilitatorBucket = yield ghoContract.methods.getFacilitatorBucket(facilitatorsList[0]).call();
133
133
  const availableFacilitatorCap = assetAmountInEth(new Dec(facilitatorBucket[0]).sub(facilitatorBucket[1]).toString(), 'GHO');
134
- borrowCap = Dec.min(borrowCap, availableFacilitatorCap).toString();
134
+ borrowCap = Dec.min(borrowCap, assetAmountInEth(facilitatorBucket[0], 'GHO')).toString();
135
135
  discountRateOnBorrow = aaveV3CalculateDiscountRate(tokenMarket.totalBorrow.toString(), '3160881469228662060510133', // stkAAVE total supply
136
136
  discountRate, minDiscountTokenBalance, minGhoBalanceForDiscount, ghoDiscountedPerDiscountToken);
137
137
  }
@@ -4,7 +4,7 @@ export const morphoAaveV2AssetDefaultMarket = ['DAI', 'ETH', 'USDC', 'USDT', 'WB
4
4
  export const morphoAaveV3AssetEthMarket = [
5
5
  'ETH', 'wstETH', 'DAI', 'USDC', 'WBTC', 'rETH', 'cbETH', 'sDAI', 'USDT',
6
6
  ];
7
- export const aaveV3AssetsDefaultMarketEth = ['ETH', 'wstETH', 'WBTC', 'USDC', 'DAI', 'LINK', 'AAVE', 'cbETH', 'USDT', 'rETH', 'LUSD', 'CRV', 'MKR', 'SNX', 'BAL', 'UNI', 'LDO', 'ENS', '1INCH', 'FRAX', 'GHO', 'RPL', 'sDAI', 'STG', 'KNC', 'FXS', 'crvUSD', 'PYUSD', 'weETH'];
7
+ export const aaveV3AssetsDefaultMarketEth = ['ETH', 'wstETH', 'WBTC', 'USDC', 'DAI', 'LINK', 'AAVE', 'cbETH', 'USDT', 'rETH', 'LUSD', 'CRV', 'MKR', 'SNX', 'BAL', 'UNI', 'LDO', 'ENS', '1INCH', 'FRAX', 'GHO', 'RPL', 'sDAI', 'STG', 'KNC', 'FXS', 'crvUSD', 'PYUSD', 'weETH', 'osETH'];
8
8
  export const aaveV3AssetsDefaultMarketOpt = [
9
9
  'DAI', 'USDC.e', 'USDT', 'SUSD', 'AAVE', 'LINK', 'WBTC', 'ETH', 'OP', 'wstETH', 'LUSD', 'MAI', 'rETH', 'USDC',
10
10
  ];
@@ -28,7 +28,7 @@ export const LlamaLendMarkets = (networkId) => ({
28
28
  export const getLlamaLendMarketData = (market, network = 1) => LlamaLendMarkets(network)[market];
29
29
  export const getLlamaLendMarketFromControllerAddress = (controllerAddress, network) => {
30
30
  const markets = LlamaLendMarkets(network);
31
- const market = Object.values(markets).find((market) => market.controllerAddress === controllerAddress);
31
+ const market = Object.values(markets).find((tempMarket) => tempMarket.controllerAddress === controllerAddress);
32
32
  if (!market)
33
33
  throw new Error('Market not found');
34
34
  return market;
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import Dec from 'decimal.js';
11
+ import { StakeWiseSDK, Network } from '@stakewise/v3-sdk';
11
12
  import { CbEthContract, LidoContract, PotContract, REthContract, wstETHContract, } from '../contracts';
12
13
  import { NetworkNumber } from '../types/common';
13
14
  import { BLOCKS_IN_A_YEAR, SECONDS_PER_YEAR, AVG_BLOCK_TIME } from '../constants';
@@ -82,12 +83,16 @@ export const getSUSDeApy = () => __awaiter(void 0, void 0, void 0, function* ()
82
83
  return data.apy;
83
84
  });
84
85
  const getWeEthApr = () => __awaiter(void 0, void 0, void 0, function* () {
85
- const res = yield fetch('https://www.etherfi.bid/api/etherfi/apr');
86
+ const res = yield fetch('https://app.defisaver.com/api/staking/apy?asset=weETH');
86
87
  const data = yield res.json();
87
- const total = data.latest_aprs.reduce((acc, apr) => new Dec(acc).add(apr).toString());
88
- return new Dec(total).div(data.latest_aprs.length).div(100).toString();
88
+ return data.apy;
89
+ });
90
+ const getOsETHApy = () => __awaiter(void 0, void 0, void 0, function* () {
91
+ const sdk = new StakeWiseSDK({ network: Network.Mainnet });
92
+ const apy = yield sdk.osToken.getAPY();
93
+ return apy;
89
94
  });
90
- export const STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH'];
95
+ export const STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe', 'osETH'];
91
96
  export const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefined) => {
92
97
  try {
93
98
  if (asset === 'stETH' || asset === 'wstETH')
@@ -102,6 +107,8 @@ export const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = u
102
107
  return getSUSDeApy();
103
108
  if (asset === 'weETH')
104
109
  return getWeEthApr();
110
+ if (asset === 'osETH')
111
+ return getOsETHApy();
105
112
  }
106
113
  catch (e) {
107
114
  console.error(`Failed to fetch APY for ${asset}`);
@@ -1,6 +1,6 @@
1
1
  export var LLVersionsEth;
2
2
  (function (LLVersionsEth) {
3
- //long only
3
+ // long only
4
4
  LLVersionsEth["LLWstethCrvusd"] = "llamaLendwstETHcrvUSD";
5
5
  LLVersionsEth["LLSusdeCrvusd"] = "llamaLendsUSDecrvUSD";
6
6
  // long and short crv
@@ -15,7 +15,7 @@ export var LLVersionsEth;
15
15
  })(LLVersionsEth || (LLVersionsEth = {}));
16
16
  export var LLVersionsArb;
17
17
  (function (LLVersionsArb) {
18
- //long only
18
+ // long only
19
19
  LLVersionsArb["LLArbCrvusd"] = "llamaLendArbcrvUSD";
20
20
  LLVersionsArb["LLFxnCrvusd"] = "llamaLendFXNcrvUSD";
21
21
  LLVersionsArb["LLWbtcCrvusd"] = "llamaLendWBTCcrvUSD";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "0.0.69",
3
+ "version": "0.0.70",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -183,7 +183,7 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
183
183
  const facilitatorBucket = await ghoContract.methods.getFacilitatorBucket(facilitatorsList[0]).call();
184
184
  const availableFacilitatorCap = assetAmountInEth(new Dec(facilitatorBucket[0]).sub(facilitatorBucket[1]).toString(), 'GHO');
185
185
 
186
- borrowCap = Dec.min(borrowCap, availableFacilitatorCap).toString();
186
+ borrowCap = Dec.min(borrowCap, assetAmountInEth(facilitatorBucket[0],'GHO')).toString();
187
187
 
188
188
  discountRateOnBorrow = aaveV3CalculateDiscountRate(
189
189
  tokenMarket.totalBorrow.toString(),
@@ -85,7 +85,7 @@ export const getSUSDeApy = async () => {
85
85
  };
86
86
 
87
87
  const getWeEthApr = async () => {
88
- const res = await fetch('hhttps://app.defisaver.com/api/staking/apy?asset=weETH');
88
+ const res = await fetch('https://app.defisaver.com/api/staking/apy?asset=weETH');
89
89
  const data = await res.json();
90
90
  return data.apy;
91
91
  };