@defisaver/positions-sdk 0.0.52 → 0.0.53
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/curveUsd/index.js
CHANGED
|
@@ -102,13 +102,14 @@ const getCurveUsdGlobalData = (web3, network, selectedMarket) => __awaiter(void
|
|
|
102
102
|
futureBorrowRate, bands: bandsData, leftToBorrow });
|
|
103
103
|
});
|
|
104
104
|
exports.getCurveUsdGlobalData = getCurveUsdGlobalData;
|
|
105
|
-
const getStatusForUser = (bandRange, activeBand, crvUSDSupplied, collSupplied) => {
|
|
105
|
+
const getStatusForUser = (bandRange, activeBand, crvUSDSupplied, collSupplied, healthPercent) => {
|
|
106
106
|
// if bands are equal, that can only be [0,0] which means user doesn't have loan (min number of bands is 4)
|
|
107
107
|
if (new decimal_js_1.default(bandRange[0]).eq(bandRange[1]))
|
|
108
108
|
return types_1.CrvUSDStatus.Nonexistant;
|
|
109
109
|
// if user doesn't have crvUSD as collateral, then his position is not in soft liquidation
|
|
110
110
|
if (new decimal_js_1.default(crvUSDSupplied).lte(0)) {
|
|
111
|
-
|
|
111
|
+
const isHealthRisky = new decimal_js_1.default(healthPercent).lt(10);
|
|
112
|
+
if (new decimal_js_1.default(bandRange[0]).minus(activeBand).lte(3) || isHealthRisky)
|
|
112
113
|
return types_1.CrvUSDStatus.Risk; // if user band is less than 3 bands away from active band, his position is at risk
|
|
113
114
|
return types_1.CrvUSDStatus.Safe;
|
|
114
115
|
}
|
|
@@ -180,7 +181,7 @@ const getCurveUsdUserData = (web3, network, address, selectedMarket, activeBand)
|
|
|
180
181
|
const priceHigh = (0, tokens_1.assetAmountInEth)(data.priceHigh);
|
|
181
182
|
const priceLow = (0, tokens_1.assetAmountInEth)(data.priceLow);
|
|
182
183
|
const _userBands = data.loanExists ? (yield getAndFormatBands(web3, network, selectedMarket, data.bandRange[0], data.bandRange[1])) : [];
|
|
183
|
-
const status = data.loanExists ? getStatusForUser(data.bandRange, activeBand, crvUSDSupplied, collSupplied) : types_1.CrvUSDStatus.Nonexistant;
|
|
184
|
+
const status = data.loanExists ? getStatusForUser(data.bandRange, activeBand, crvUSDSupplied, collSupplied, healthPercent) : types_1.CrvUSDStatus.Nonexistant;
|
|
184
185
|
const userBands = _userBands.map((band, index) => (Object.assign(Object.assign({}, band), { userDebtAmount: (0, tokens_1.assetAmountInEth)(data.usersBands[0][index], debtAsset), userCollAmount: (0, tokens_1.assetAmountInEth)(data.usersBands[1][index], collAsset) }))).sort((a, b) => parseInt(b.id, 10) - parseInt(a.id, 10));
|
|
185
186
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, data), { debtAmount: (0, tokens_1.assetAmountInEth)(data.debtAmount, debtAsset), health,
|
|
186
187
|
healthPercent,
|
package/cjs/llamaLend/index.js
CHANGED
|
@@ -133,13 +133,14 @@ const getLlamaLendGlobalData = (web3, network, selectedMarket) => __awaiter(void
|
|
|
133
133
|
futureBorrowRate, bands: bandsData, leftToBorrow });
|
|
134
134
|
});
|
|
135
135
|
exports.getLlamaLendGlobalData = getLlamaLendGlobalData;
|
|
136
|
-
const getStatusForUser = (bandRange, activeBand, debtSupplied, collSupplied) => {
|
|
136
|
+
const getStatusForUser = (bandRange, activeBand, debtSupplied, collSupplied, healthPercent) => {
|
|
137
137
|
// if bands are equal, that can only be [0,0] which means user doesn't have loan (min number of bands is 4)
|
|
138
138
|
if (new decimal_js_1.default(bandRange[0]).eq(bandRange[1]))
|
|
139
139
|
return types_1.LlamaLendStatus.Nonexistant;
|
|
140
140
|
// if user doesn't have debtAsset as collateral, then his position is not in soft liquidation
|
|
141
141
|
if (new decimal_js_1.default(debtSupplied).lte(0)) {
|
|
142
|
-
|
|
142
|
+
const isHealthRisky = new decimal_js_1.default(healthPercent).lt(10);
|
|
143
|
+
if (new decimal_js_1.default(bandRange[0]).minus(activeBand).lte(3) || isHealthRisky)
|
|
143
144
|
return types_1.LlamaLendStatus.Risk; // if user band is less than 3 bands away from active band, his position is at risk
|
|
144
145
|
return types_1.LlamaLendStatus.Safe;
|
|
145
146
|
}
|
|
@@ -219,7 +220,7 @@ const getLlamaLendUserData = (web3, network, address, selectedMarket, marketData
|
|
|
219
220
|
const priceHigh = (0, tokens_1.assetAmountInEth)(data.priceHigh);
|
|
220
221
|
const priceLow = (0, tokens_1.assetAmountInEth)(data.priceLow);
|
|
221
222
|
const _userBands = data.loanExists ? (yield getAndFormatBands(web3, network, selectedMarket, data.bandRange[0], data.bandRange[1])) : [];
|
|
222
|
-
const status = data.loanExists ? getStatusForUser(data.bandRange, marketData.activeBand, debtSupplied, collSupplied) : types_1.LlamaLendStatus.Nonexistant;
|
|
223
|
+
const status = data.loanExists ? getStatusForUser(data.bandRange, marketData.activeBand, debtSupplied, collSupplied, healthPercent) : types_1.LlamaLendStatus.Nonexistant;
|
|
223
224
|
const userBands = _userBands.map((band, index) => (Object.assign(Object.assign({}, band), { userDebtAmount: (0, tokens_1.assetAmountInEth)(data.usersBands[0][index], debtAsset), userCollAmount: (0, tokens_1.assetAmountInEth)(data.usersBands[1][index], collAsset) }))).sort((a, b) => parseInt(b.id, 10) - parseInt(a.id, 10));
|
|
224
225
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, data), { debtAmount: (0, tokens_1.assetAmountInEth)(data.debtAmount, debtAsset), health,
|
|
225
226
|
healthPercent,
|
package/esm/curveUsd/index.js
CHANGED
|
@@ -95,13 +95,14 @@ export const getCurveUsdGlobalData = (web3, network, selectedMarket) => __awaite
|
|
|
95
95
|
ammPrice, oraclePrice: assetAmountInEth(data.oraclePrice, debtAsset), basePrice: assetAmountInEth(data.basePrice, debtAsset), minted: assetAmountInEth(data.minted, debtAsset), redeemed: assetAmountInEth(data.redeemed, debtAsset), borrowRate,
|
|
96
96
|
futureBorrowRate, bands: bandsData, leftToBorrow });
|
|
97
97
|
});
|
|
98
|
-
const getStatusForUser = (bandRange, activeBand, crvUSDSupplied, collSupplied) => {
|
|
98
|
+
const getStatusForUser = (bandRange, activeBand, crvUSDSupplied, collSupplied, healthPercent) => {
|
|
99
99
|
// if bands are equal, that can only be [0,0] which means user doesn't have loan (min number of bands is 4)
|
|
100
100
|
if (new Dec(bandRange[0]).eq(bandRange[1]))
|
|
101
101
|
return CrvUSDStatus.Nonexistant;
|
|
102
102
|
// if user doesn't have crvUSD as collateral, then his position is not in soft liquidation
|
|
103
103
|
if (new Dec(crvUSDSupplied).lte(0)) {
|
|
104
|
-
|
|
104
|
+
const isHealthRisky = new Dec(healthPercent).lt(10);
|
|
105
|
+
if (new Dec(bandRange[0]).minus(activeBand).lte(3) || isHealthRisky)
|
|
105
106
|
return CrvUSDStatus.Risk; // if user band is less than 3 bands away from active band, his position is at risk
|
|
106
107
|
return CrvUSDStatus.Safe;
|
|
107
108
|
}
|
|
@@ -172,7 +173,7 @@ export const getCurveUsdUserData = (web3, network, address, selectedMarket, acti
|
|
|
172
173
|
const priceHigh = assetAmountInEth(data.priceHigh);
|
|
173
174
|
const priceLow = assetAmountInEth(data.priceLow);
|
|
174
175
|
const _userBands = data.loanExists ? (yield getAndFormatBands(web3, network, selectedMarket, data.bandRange[0], data.bandRange[1])) : [];
|
|
175
|
-
const status = data.loanExists ? getStatusForUser(data.bandRange, activeBand, crvUSDSupplied, collSupplied) : CrvUSDStatus.Nonexistant;
|
|
176
|
+
const status = data.loanExists ? getStatusForUser(data.bandRange, activeBand, crvUSDSupplied, collSupplied, healthPercent) : CrvUSDStatus.Nonexistant;
|
|
176
177
|
const userBands = _userBands.map((band, index) => (Object.assign(Object.assign({}, band), { userDebtAmount: assetAmountInEth(data.usersBands[0][index], debtAsset), userCollAmount: assetAmountInEth(data.usersBands[1][index], collAsset) }))).sort((a, b) => parseInt(b.id, 10) - parseInt(a.id, 10));
|
|
177
178
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, data), { debtAmount: assetAmountInEth(data.debtAmount, debtAsset), health,
|
|
178
179
|
healthPercent,
|
package/esm/llamaLend/index.js
CHANGED
|
@@ -126,13 +126,14 @@ export const getLlamaLendGlobalData = (web3, network, selectedMarket) => __await
|
|
|
126
126
|
lendRate,
|
|
127
127
|
futureBorrowRate, bands: bandsData, leftToBorrow });
|
|
128
128
|
});
|
|
129
|
-
const getStatusForUser = (bandRange, activeBand, debtSupplied, collSupplied) => {
|
|
129
|
+
const getStatusForUser = (bandRange, activeBand, debtSupplied, collSupplied, healthPercent) => {
|
|
130
130
|
// if bands are equal, that can only be [0,0] which means user doesn't have loan (min number of bands is 4)
|
|
131
131
|
if (new Dec(bandRange[0]).eq(bandRange[1]))
|
|
132
132
|
return LlamaLendStatus.Nonexistant;
|
|
133
133
|
// if user doesn't have debtAsset as collateral, then his position is not in soft liquidation
|
|
134
134
|
if (new Dec(debtSupplied).lte(0)) {
|
|
135
|
-
|
|
135
|
+
const isHealthRisky = new Dec(healthPercent).lt(10);
|
|
136
|
+
if (new Dec(bandRange[0]).minus(activeBand).lte(3) || isHealthRisky)
|
|
136
137
|
return LlamaLendStatus.Risk; // if user band is less than 3 bands away from active band, his position is at risk
|
|
137
138
|
return LlamaLendStatus.Safe;
|
|
138
139
|
}
|
|
@@ -211,7 +212,7 @@ export const getLlamaLendUserData = (web3, network, address, selectedMarket, mar
|
|
|
211
212
|
const priceHigh = assetAmountInEth(data.priceHigh);
|
|
212
213
|
const priceLow = assetAmountInEth(data.priceLow);
|
|
213
214
|
const _userBands = data.loanExists ? (yield getAndFormatBands(web3, network, selectedMarket, data.bandRange[0], data.bandRange[1])) : [];
|
|
214
|
-
const status = data.loanExists ? getStatusForUser(data.bandRange, marketData.activeBand, debtSupplied, collSupplied) : LlamaLendStatus.Nonexistant;
|
|
215
|
+
const status = data.loanExists ? getStatusForUser(data.bandRange, marketData.activeBand, debtSupplied, collSupplied, healthPercent) : LlamaLendStatus.Nonexistant;
|
|
215
216
|
const userBands = _userBands.map((band, index) => (Object.assign(Object.assign({}, band), { userDebtAmount: assetAmountInEth(data.usersBands[0][index], debtAsset), userCollAmount: assetAmountInEth(data.usersBands[1][index], collAsset) }))).sort((a, b) => parseInt(b.id, 10) - parseInt(a.id, 10));
|
|
216
217
|
return Object.assign(Object.assign(Object.assign(Object.assign({}, data), { debtAmount: assetAmountInEth(data.debtAmount, debtAsset), health,
|
|
217
218
|
healthPercent,
|
package/package.json
CHANGED
package/src/curveUsd/index.ts
CHANGED
|
@@ -111,12 +111,13 @@ export const getCurveUsdGlobalData = async (web3: Web3, network: NetworkNumber,
|
|
|
111
111
|
};
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
const getStatusForUser = (bandRange: string[], activeBand: string, crvUSDSupplied: string, collSupplied: string) => {
|
|
114
|
+
const getStatusForUser = (bandRange: string[], activeBand: string, crvUSDSupplied: string, collSupplied: string, healthPercent: string) => {
|
|
115
115
|
// if bands are equal, that can only be [0,0] which means user doesn't have loan (min number of bands is 4)
|
|
116
116
|
if (new Dec(bandRange[0]).eq(bandRange[1])) return CrvUSDStatus.Nonexistant;
|
|
117
117
|
// if user doesn't have crvUSD as collateral, then his position is not in soft liquidation
|
|
118
118
|
if (new Dec(crvUSDSupplied).lte(0)) {
|
|
119
|
-
|
|
119
|
+
const isHealthRisky = new Dec(healthPercent).lt(10);
|
|
120
|
+
if (new Dec(bandRange[0]).minus(activeBand).lte(3) || isHealthRisky) return CrvUSDStatus.Risk; // if user band is less than 3 bands away from active band, his position is at risk
|
|
120
121
|
return CrvUSDStatus.Safe;
|
|
121
122
|
}
|
|
122
123
|
if (new Dec(bandRange[0]).lte(activeBand) && new Dec(bandRange[1]).gte(activeBand)) return CrvUSDStatus.SoftLiquidating; // user has crvUSD as coll so he is in soft liquidation
|
|
@@ -196,7 +197,7 @@ export const getCurveUsdUserData = async (web3: Web3, network: NetworkNumber, ad
|
|
|
196
197
|
|
|
197
198
|
const _userBands = data.loanExists ? (await getAndFormatBands(web3, network, selectedMarket, data.bandRange[0], data.bandRange[1])) : [];
|
|
198
199
|
|
|
199
|
-
const status = data.loanExists ? getStatusForUser(data.bandRange, activeBand, crvUSDSupplied, collSupplied) : CrvUSDStatus.Nonexistant;
|
|
200
|
+
const status = data.loanExists ? getStatusForUser(data.bandRange, activeBand, crvUSDSupplied, collSupplied, healthPercent) : CrvUSDStatus.Nonexistant;
|
|
200
201
|
|
|
201
202
|
const userBands = _userBands.map((band, index) => ({
|
|
202
203
|
...band,
|
package/src/llamaLend/index.ts
CHANGED
|
@@ -146,12 +146,13 @@ export const getLlamaLendGlobalData = async (web3: Web3, network: NetworkNumber,
|
|
|
146
146
|
};
|
|
147
147
|
};
|
|
148
148
|
|
|
149
|
-
const getStatusForUser = (bandRange: string[], activeBand: string, debtSupplied: string, collSupplied: string) => {
|
|
149
|
+
const getStatusForUser = (bandRange: string[], activeBand: string, debtSupplied: string, collSupplied: string, healthPercent: string) => {
|
|
150
150
|
// if bands are equal, that can only be [0,0] which means user doesn't have loan (min number of bands is 4)
|
|
151
151
|
if (new Dec(bandRange[0]).eq(bandRange[1])) return LlamaLendStatus.Nonexistant;
|
|
152
152
|
// if user doesn't have debtAsset as collateral, then his position is not in soft liquidation
|
|
153
153
|
if (new Dec(debtSupplied).lte(0)) {
|
|
154
|
-
|
|
154
|
+
const isHealthRisky = new Dec(healthPercent).lt(10);
|
|
155
|
+
if (new Dec(bandRange[0]).minus(activeBand).lte(3) || isHealthRisky) return LlamaLendStatus.Risk; // if user band is less than 3 bands away from active band, his position is at risk
|
|
155
156
|
return LlamaLendStatus.Safe;
|
|
156
157
|
}
|
|
157
158
|
if (new Dec(bandRange[0]).lte(activeBand) && new Dec(bandRange[1]).gte(activeBand)) return LlamaLendStatus.SoftLiquidating; // user has debtAsset as coll so he is in soft liquidation
|
|
@@ -245,7 +246,7 @@ export const getLlamaLendUserData = async (web3: Web3, network: NetworkNumber, a
|
|
|
245
246
|
|
|
246
247
|
const _userBands = data.loanExists ? (await getAndFormatBands(web3, network, selectedMarket, data.bandRange[0], data.bandRange[1])) : [];
|
|
247
248
|
|
|
248
|
-
const status = data.loanExists ? getStatusForUser(data.bandRange, marketData.activeBand, debtSupplied, collSupplied) : LlamaLendStatus.Nonexistant;
|
|
249
|
+
const status = data.loanExists ? getStatusForUser(data.bandRange, marketData.activeBand, debtSupplied, collSupplied, healthPercent) : LlamaLendStatus.Nonexistant;
|
|
249
250
|
|
|
250
251
|
const userBands = _userBands.map((band, index) => ({
|
|
251
252
|
...band,
|