@defisaver/positions-sdk 0.0.183-dev-allocator-4 → 0.0.183-dev-allocator-6

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.
@@ -188,8 +188,8 @@ const getLiquidityToAllocate = (amountToBorrow, totalBorrow, totalSupply, target
188
188
  let liquidityToAllocate = new decimal_js_1.default(newTotalBorrowAssets).div(targetBorrowUtilization).mul(1e18).sub(totalSupply)
189
189
  .toFixed(0)
190
190
  .toString();
191
- if (new decimal_js_1.default(reallocatableLiquidityAssets).lt(liquidityToAllocate)) {
192
- liquidityToAllocate = new decimal_js_1.default(amountToBorrow).sub(leftToBorrow).toString();
191
+ if (new decimal_js_1.default(reallocatableLiquidityAssets).lt(liquidityToAllocate) || new decimal_js_1.default(liquidityToAllocate).lt('0')) {
192
+ liquidityToAllocate = new decimal_js_1.default(amountToBorrow).lt(leftToBorrow) ? '0' : new decimal_js_1.default(amountToBorrow).sub(leftToBorrow).toString();
193
193
  if (new decimal_js_1.default(reallocatableLiquidityAssets).lt(liquidityToAllocate))
194
194
  throw new Error('Not enough liquidity available to allocate');
195
195
  }
@@ -177,8 +177,8 @@ export const getLiquidityToAllocate = (amountToBorrow, totalBorrow, totalSupply,
177
177
  let liquidityToAllocate = new Dec(newTotalBorrowAssets).div(targetBorrowUtilization).mul(1e18).sub(totalSupply)
178
178
  .toFixed(0)
179
179
  .toString();
180
- if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate)) {
181
- liquidityToAllocate = new Dec(amountToBorrow).sub(leftToBorrow).toString();
180
+ if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate) || new Dec(liquidityToAllocate).lt('0')) {
181
+ liquidityToAllocate = new Dec(amountToBorrow).lt(leftToBorrow) ? '0' : new Dec(amountToBorrow).sub(leftToBorrow).toString();
182
182
  if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate))
183
183
  throw new Error('Not enough liquidity available to allocate');
184
184
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "0.0.183-dev-allocator-4",
3
+ "version": "0.0.183-dev-allocator-6",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -201,8 +201,8 @@ export const getLiquidityToAllocate = (amountToBorrow: string, totalBorrow: stri
201
201
  .toFixed(0)
202
202
  .toString();
203
203
 
204
- if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate)) {
205
- liquidityToAllocate = new Dec(amountToBorrow).sub(leftToBorrow).toString();
204
+ if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate) || new Dec(liquidityToAllocate).lt('0')) {
205
+ liquidityToAllocate = new Dec(amountToBorrow).lt(leftToBorrow) ? '0' : new Dec(amountToBorrow).sub(leftToBorrow).toString();
206
206
  if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate)) throw new Error('Not enough liquidity available to allocate');
207
207
  }
208
208