@strkfarm/sdk 2.0.0-dev.13 → 2.0.0-dev.14
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/dist/index.browser.global.js +345 -328
- package/dist/index.browser.mjs +807 -790
- package/dist/index.d.ts +19 -1
- package/dist/index.js +353 -334
- package/dist/index.mjs +807 -790
- package/package.json +1 -1
- package/src/strategies/universal-adapters/index.ts +2 -1
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +40 -0
package/package.json
CHANGED
|
@@ -5,4 +5,5 @@ export * from "./vesu-supply-only-adapter";
|
|
|
5
5
|
export * from "./vesu-multiply-adapter";
|
|
6
6
|
export * from "./extended-adapter";
|
|
7
7
|
export * from "./adapter-utils";
|
|
8
|
-
export * from "./unused-balance-adapter";
|
|
8
|
+
export * from "./unused-balance-adapter";
|
|
9
|
+
export * from "./avnu-adapter";
|
|
@@ -317,6 +317,46 @@ export const calculateAmountDepositOnExtendedWhenIncurringLosses = async (
|
|
|
317
317
|
}
|
|
318
318
|
};
|
|
319
319
|
|
|
320
|
+
/**
|
|
321
|
+
* calculate the amount of collateral to deposit to maintain the ltv
|
|
322
|
+
* The formula is:
|
|
323
|
+
* ((debt * debtPrice * targetHF) - (collateral * collateralPrice * ltv)) / ltv
|
|
324
|
+
* @param collateralAmount in collateral units
|
|
325
|
+
* @param debtAmount in debt units
|
|
326
|
+
* @param debtPrice in usd
|
|
327
|
+
* @param maxLtv
|
|
328
|
+
* @param collateralPrice in usd
|
|
329
|
+
* @param targetHF
|
|
330
|
+
* @returns deltaCollateralAmountUnits in collateral units
|
|
331
|
+
* null if there is an error
|
|
332
|
+
*/
|
|
333
|
+
export const calculateWBTCAmountToMaintainLTV = (
|
|
334
|
+
collateralAmount: Web3Number,
|
|
335
|
+
debtAmount: Web3Number,
|
|
336
|
+
debtPrice: number,
|
|
337
|
+
maxLtv: number = MAX_LIQUIDATION_RATIO,
|
|
338
|
+
collateralPrice: number,
|
|
339
|
+
targetHF: number = TARGET_HF,
|
|
340
|
+
) =>{
|
|
341
|
+
try {
|
|
342
|
+
const numerator1 = (collateralAmount)
|
|
343
|
+
.multipliedBy(collateralPrice)
|
|
344
|
+
.multipliedBy(maxLtv)
|
|
345
|
+
const numerator2 = debtAmount
|
|
346
|
+
.multipliedBy(debtPrice)
|
|
347
|
+
.multipliedBy(targetHF);
|
|
348
|
+
const denominator = maxLtv;
|
|
349
|
+
const collateralAmountToMaintainLTV = numerator2.minus(numerator1).dividedBy(denominator);
|
|
350
|
+
let deltaCollateralAmountUnits = new Web3Number(
|
|
351
|
+
collateralAmountToMaintainLTV.dividedBy(collateralPrice).toFixed(WBTC_TOKEN_DECIMALS),
|
|
352
|
+
WBTC_TOKEN_DECIMALS
|
|
353
|
+
);
|
|
354
|
+
return {deltaCollateralAmountUnits};
|
|
355
|
+
} catch (err) {
|
|
356
|
+
return { deltaCollateralAmountUnits: null };
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
320
360
|
export const calculateExposureDelta = (
|
|
321
361
|
exposure_extended: number,
|
|
322
362
|
exposure_vesu: number
|