@defisaver/positions-sdk 0.0.166-dev-liquity-v2 → 0.0.166-dev2-liquity-v2

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.
@@ -48,6 +48,14 @@ const getLiquityV2AggregatedPositionData = ({ usedAssets, assetsData, minRatio,
48
48
  payload.netApy = netApy;
49
49
  payload.incentiveUsd = incentiveUsd;
50
50
  payload.totalInterestUsd = totalInterestUsd;
51
+ const { leveragedType, leveragedAsset } = (0, moneymarket_1.isLeveragedPos)(usedAssets);
52
+ payload.leveragedType = leveragedType;
53
+ payload.leveragedAsset = leveragedAsset;
54
+ payload.liquidationPrice = '';
55
+ if (leveragedType !== '') {
56
+ const assetPrice = assetsData[leveragedAsset].price;
57
+ payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, assetPrice, payload.borrowedUsd, payload.borrowLimitUsd);
58
+ }
51
59
  return payload;
52
60
  };
53
61
  exports.getLiquityV2AggregatedPositionData = getLiquityV2AggregatedPositionData;
@@ -67,6 +67,8 @@ const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsData, mark
67
67
  suppliedUsd: '0',
68
68
  borrowed,
69
69
  borrowedUsd: new decimal_js_1.default(borrowed).mul(debtAssetData.price).toString(),
70
+ isBorrowed: true,
71
+ isSupplied: false,
70
72
  };
71
73
  const collAssetData = assetsData[collateralToken];
72
74
  const suppliedColl = (0, tokens_1.assetAmountInEth)(data.collAmount);
@@ -78,6 +80,8 @@ const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsData, mark
78
80
  suppliedUsd: new decimal_js_1.default(suppliedColl).mul(collAssetData.price).toString(),
79
81
  borrowed: '0',
80
82
  borrowedUsd: '0',
83
+ isBorrowed: false,
84
+ isSupplied: true,
81
85
  };
82
86
  const ratio = new decimal_js_1.default(data.TCRatio).div(1e16).toString();
83
87
  const interestRate = new decimal_js_1.default(data.annualInterestRate).div(1e16).toString();
@@ -43,6 +43,8 @@ export interface LiquityV2UsedAsset {
43
43
  suppliedUsd: string;
44
44
  borrowed: string;
45
45
  borrowedUsd: string;
46
+ isSupplied: boolean;
47
+ isBorrowed: boolean;
46
48
  }
47
49
  export type LiquityV2UsedAssets = {
48
50
  [key: string]: LiquityV2UsedAsset;
@@ -55,6 +57,9 @@ export interface LiquityV2AggregatedTroveData {
55
57
  netApy: string;
56
58
  incentiveUsd: string;
57
59
  totalInterestUsd: string;
60
+ leveragedType: string;
61
+ leveragedAsset: string;
62
+ liquidationPrice: string;
58
63
  }
59
64
  export interface LiquityV2TroveData {
60
65
  usedAssets: LiquityV2UsedAssets;
@@ -70,4 +75,7 @@ export interface LiquityV2TroveData {
70
75
  totalInterestUsd: string;
71
76
  interestBatchManager: EthAddress;
72
77
  troveStatus: string;
78
+ leveragedType: string;
79
+ leveragedAsset: string;
80
+ liquidationPrice: string;
73
81
  }
@@ -1,5 +1,5 @@
1
1
  import Dec from 'decimal.js';
2
- import { getAssetsTotal } from '../../moneymarket';
2
+ import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
3
3
  import { calculateInterestEarned } from '../../staking';
4
4
  export const calculateNetApyLiquityV2 = (usedAssets, assetsData, interestRate) => {
5
5
  const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
@@ -41,5 +41,13 @@ export const getLiquityV2AggregatedPositionData = ({ usedAssets, assetsData, min
41
41
  payload.netApy = netApy;
42
42
  payload.incentiveUsd = incentiveUsd;
43
43
  payload.totalInterestUsd = totalInterestUsd;
44
+ const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
45
+ payload.leveragedType = leveragedType;
46
+ payload.leveragedAsset = leveragedAsset;
47
+ payload.liquidationPrice = '';
48
+ if (leveragedType !== '') {
49
+ const assetPrice = assetsData[leveragedAsset].price;
50
+ payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.borrowLimitUsd);
51
+ }
44
52
  return payload;
45
53
  };
@@ -60,6 +60,8 @@ export const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsDat
60
60
  suppliedUsd: '0',
61
61
  borrowed,
62
62
  borrowedUsd: new Dec(borrowed).mul(debtAssetData.price).toString(),
63
+ isBorrowed: true,
64
+ isSupplied: false,
63
65
  };
64
66
  const collAssetData = assetsData[collateralToken];
65
67
  const suppliedColl = assetAmountInEth(data.collAmount);
@@ -71,6 +73,8 @@ export const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsDat
71
73
  suppliedUsd: new Dec(suppliedColl).mul(collAssetData.price).toString(),
72
74
  borrowed: '0',
73
75
  borrowedUsd: '0',
76
+ isBorrowed: false,
77
+ isSupplied: true,
74
78
  };
75
79
  const ratio = new Dec(data.TCRatio).div(1e16).toString();
76
80
  const interestRate = new Dec(data.annualInterestRate).div(1e16).toString();
@@ -43,6 +43,8 @@ export interface LiquityV2UsedAsset {
43
43
  suppliedUsd: string;
44
44
  borrowed: string;
45
45
  borrowedUsd: string;
46
+ isSupplied: boolean;
47
+ isBorrowed: boolean;
46
48
  }
47
49
  export type LiquityV2UsedAssets = {
48
50
  [key: string]: LiquityV2UsedAsset;
@@ -55,6 +57,9 @@ export interface LiquityV2AggregatedTroveData {
55
57
  netApy: string;
56
58
  incentiveUsd: string;
57
59
  totalInterestUsd: string;
60
+ leveragedType: string;
61
+ leveragedAsset: string;
62
+ liquidationPrice: string;
58
63
  }
59
64
  export interface LiquityV2TroveData {
60
65
  usedAssets: LiquityV2UsedAssets;
@@ -70,4 +75,7 @@ export interface LiquityV2TroveData {
70
75
  totalInterestUsd: string;
71
76
  interestBatchManager: EthAddress;
72
77
  troveStatus: string;
78
+ leveragedType: string;
79
+ leveragedAsset: string;
80
+ liquidationPrice: string;
73
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "0.0.166-dev-liquity-v2",
3
+ "version": "0.0.166-dev2-liquity-v2",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -1,5 +1,5 @@
1
1
  import Dec from 'decimal.js';
2
- import { getAssetsTotal } from '../../moneymarket';
2
+ import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
3
3
  import {
4
4
  LiquityV2AggregatedTroveData, LiquityV2AssetsData, LiquityV2UsedAsset, LiquityV2UsedAssets,
5
5
  } from '../../types';
@@ -65,5 +65,14 @@ export const getLiquityV2AggregatedPositionData = ({
65
65
  payload.incentiveUsd = incentiveUsd;
66
66
  payload.totalInterestUsd = totalInterestUsd;
67
67
 
68
+ const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
69
+ payload.leveragedType = leveragedType;
70
+ payload.leveragedAsset = leveragedAsset;
71
+ payload.liquidationPrice = '';
72
+ if (leveragedType !== '') {
73
+ const assetPrice = assetsData[leveragedAsset].price;
74
+ payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.borrowLimitUsd);
75
+ }
76
+
68
77
  return payload;
69
78
  };
@@ -77,6 +77,8 @@ export const getLiquityV2TroveData = async (
77
77
  suppliedUsd: '0',
78
78
  borrowed,
79
79
  borrowedUsd: new Dec(borrowed).mul(debtAssetData.price).toString(),
80
+ isBorrowed: true,
81
+ isSupplied: false,
80
82
  };
81
83
 
82
84
  const collAssetData = assetsData[collateralToken];
@@ -89,6 +91,8 @@ export const getLiquityV2TroveData = async (
89
91
  suppliedUsd: new Dec(suppliedColl).mul(collAssetData.price).toString(),
90
92
  borrowed: '0',
91
93
  borrowedUsd: '0',
94
+ isBorrowed: false,
95
+ isSupplied: true,
92
96
  };
93
97
 
94
98
  const ratio = new Dec(data.TCRatio).div(1e16).toString();
@@ -48,6 +48,8 @@ export interface LiquityV2UsedAsset {
48
48
  suppliedUsd: string,
49
49
  borrowed: string,
50
50
  borrowedUsd: string,
51
+ isSupplied: boolean,
52
+ isBorrowed: boolean,
51
53
  }
52
54
 
53
55
  export type LiquityV2UsedAssets = { [key: string]: LiquityV2UsedAsset };
@@ -60,6 +62,9 @@ export interface LiquityV2AggregatedTroveData {
60
62
  netApy: string,
61
63
  incentiveUsd: string,
62
64
  totalInterestUsd: string,
65
+ leveragedType: string,
66
+ leveragedAsset: string,
67
+ liquidationPrice: string,
63
68
  }
64
69
 
65
70
  export interface LiquityV2TroveData {
@@ -76,4 +81,7 @@ export interface LiquityV2TroveData {
76
81
  totalInterestUsd: string,
77
82
  interestBatchManager: EthAddress,
78
83
  troveStatus: string,
84
+ leveragedType: string,
85
+ leveragedAsset: string,
86
+ liquidationPrice: string,
79
87
  }