@defisaver/positions-sdk 0.0.183-dev-allocator-5 → 0.0.183-dev-allocator-7

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.
@@ -16,11 +16,34 @@ export declare const getApyAfterValuesEstimation: (selectedMarket: MorphoBlueMar
16
16
  borrowRate: string;
17
17
  supplyRate: string;
18
18
  }>;
19
+ /**
20
+ *Get reallocatable liquidity and target borrow utilization for a given market
21
+ *@param marketId - The unique key of the market
22
+ *@param network - The network number
23
+ *@returns The reallocatable liquidity and target borrow utilization
24
+ */
19
25
  export declare const getReallocatableLiquidity: (marketId: string, network?: NetworkNumber) => Promise<{
20
26
  reallocatableLiquidity: string;
21
27
  targetBorrowUtilization: string;
22
28
  }>;
29
+ /**
30
+ *Get liquidity to allocate for a given amount to borrow. First, the function will try to calculate the amount of liquidity to allocate to be able to hit the target utilization.
31
+ * If it is not possible to allocate enough liquidity to hit the target utilization, the function will allocate the amount of liquidity needed to be able to borrow the selected amount.
32
+ * @param amountToBorrow - The amount to borrow
33
+ * @param totalBorrow - The total amount borrowed
34
+ * @param totalSupply - The total amount supplied
35
+ * @param targetBorrowUtilization - The target borrow utilization
36
+ * @param reallocatableLiquidityAssets - The amount of liquidity that can be reallocated
37
+ * @returns The amount of liquidity to allocate
38
+ */
23
39
  export declare const getLiquidityToAllocate: (amountToBorrow: string, totalBorrow: string, totalSupply: string, targetBorrowUtilization: string, reallocatableLiquidityAssets: string) => string;
40
+ /**
41
+ * Get the vaults and withdrawals needed to reallocate liquidity for a given amount to borrow
42
+ * @param marketId - The unique key of the market
43
+ * @param amountToBorrow - The amount to borrow
44
+ * @param network - The network number
45
+ * @returns The vaults and withdrawals needed to reallocate liquidity
46
+ */
24
47
  export declare const getReallocation: (marketId: string, amountToBorrow: string, network?: NetworkNumber) => Promise<{
25
48
  vaults: string[];
26
49
  withdrawals: (string | string[])[][][];
@@ -165,6 +165,12 @@ const MARKET_QUERY = `
165
165
  }
166
166
  }
167
167
  `;
168
+ /**
169
+ *Get reallocatable liquidity and target borrow utilization for a given market
170
+ *@param marketId - The unique key of the market
171
+ *@param network - The network number
172
+ *@returns The reallocatable liquidity and target borrow utilization
173
+ */
168
174
  const getReallocatableLiquidity = (marketId, network = common_1.NetworkNumber.Eth) => __awaiter(void 0, void 0, void 0, function* () {
169
175
  var _a;
170
176
  const response = yield fetch(API_URL, {
@@ -182,6 +188,16 @@ const getReallocatableLiquidity = (marketId, network = common_1.NetworkNumber.Et
182
188
  return { reallocatableLiquidity: marketData.reallocatableLiquidityAssets, targetBorrowUtilization: marketData.targetBorrowUtilization };
183
189
  });
184
190
  exports.getReallocatableLiquidity = getReallocatableLiquidity;
191
+ /**
192
+ *Get liquidity to allocate for a given amount to borrow. First, the function will try to calculate the amount of liquidity to allocate to be able to hit the target utilization.
193
+ * If it is not possible to allocate enough liquidity to hit the target utilization, the function will allocate the amount of liquidity needed to be able to borrow the selected amount.
194
+ * @param amountToBorrow - The amount to borrow
195
+ * @param totalBorrow - The total amount borrowed
196
+ * @param totalSupply - The total amount supplied
197
+ * @param targetBorrowUtilization - The target borrow utilization
198
+ * @param reallocatableLiquidityAssets - The amount of liquidity that can be reallocated
199
+ * @returns The amount of liquidity to allocate
200
+ */
185
201
  const getLiquidityToAllocate = (amountToBorrow, totalBorrow, totalSupply, targetBorrowUtilization, reallocatableLiquidityAssets) => {
186
202
  const newTotalBorrowAssets = new decimal_js_1.default(totalBorrow).add(amountToBorrow).toString();
187
203
  const leftToBorrow = new decimal_js_1.default(totalSupply).sub(totalBorrow).toString();
@@ -189,13 +205,20 @@ const getLiquidityToAllocate = (amountToBorrow, totalBorrow, totalSupply, target
189
205
  .toFixed(0)
190
206
  .toString();
191
207
  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).sub(leftToBorrow).toString();
208
+ liquidityToAllocate = new decimal_js_1.default(amountToBorrow).lt(leftToBorrow) ? '0' : new decimal_js_1.default(amountToBorrow).sub(leftToBorrow).toString();
193
209
  if (new decimal_js_1.default(reallocatableLiquidityAssets).lt(liquidityToAllocate))
194
210
  throw new Error('Not enough liquidity available to allocate');
195
211
  }
196
212
  return liquidityToAllocate;
197
213
  };
198
214
  exports.getLiquidityToAllocate = getLiquidityToAllocate;
215
+ /**
216
+ * Get the vaults and withdrawals needed to reallocate liquidity for a given amount to borrow
217
+ * @param marketId - The unique key of the market
218
+ * @param amountToBorrow - The amount to borrow
219
+ * @param network - The network number
220
+ * @returns The vaults and withdrawals needed to reallocate liquidity
221
+ */
199
222
  const getReallocation = (marketId, amountToBorrow, network = common_1.NetworkNumber.Eth) => __awaiter(void 0, void 0, void 0, function* () {
200
223
  var _b, _c, _d;
201
224
  const response = yield fetch(API_URL, {
@@ -16,11 +16,34 @@ export declare const getApyAfterValuesEstimation: (selectedMarket: MorphoBlueMar
16
16
  borrowRate: string;
17
17
  supplyRate: string;
18
18
  }>;
19
+ /**
20
+ *Get reallocatable liquidity and target borrow utilization for a given market
21
+ *@param marketId - The unique key of the market
22
+ *@param network - The network number
23
+ *@returns The reallocatable liquidity and target borrow utilization
24
+ */
19
25
  export declare const getReallocatableLiquidity: (marketId: string, network?: NetworkNumber) => Promise<{
20
26
  reallocatableLiquidity: string;
21
27
  targetBorrowUtilization: string;
22
28
  }>;
29
+ /**
30
+ *Get liquidity to allocate for a given amount to borrow. First, the function will try to calculate the amount of liquidity to allocate to be able to hit the target utilization.
31
+ * If it is not possible to allocate enough liquidity to hit the target utilization, the function will allocate the amount of liquidity needed to be able to borrow the selected amount.
32
+ * @param amountToBorrow - The amount to borrow
33
+ * @param totalBorrow - The total amount borrowed
34
+ * @param totalSupply - The total amount supplied
35
+ * @param targetBorrowUtilization - The target borrow utilization
36
+ * @param reallocatableLiquidityAssets - The amount of liquidity that can be reallocated
37
+ * @returns The amount of liquidity to allocate
38
+ */
23
39
  export declare const getLiquidityToAllocate: (amountToBorrow: string, totalBorrow: string, totalSupply: string, targetBorrowUtilization: string, reallocatableLiquidityAssets: string) => string;
40
+ /**
41
+ * Get the vaults and withdrawals needed to reallocate liquidity for a given amount to borrow
42
+ * @param marketId - The unique key of the market
43
+ * @param amountToBorrow - The amount to borrow
44
+ * @param network - The network number
45
+ * @returns The vaults and withdrawals needed to reallocate liquidity
46
+ */
24
47
  export declare const getReallocation: (marketId: string, amountToBorrow: string, network?: NetworkNumber) => Promise<{
25
48
  vaults: string[];
26
49
  withdrawals: (string | string[])[][][];
@@ -155,6 +155,12 @@ const MARKET_QUERY = `
155
155
  }
156
156
  }
157
157
  `;
158
+ /**
159
+ *Get reallocatable liquidity and target borrow utilization for a given market
160
+ *@param marketId - The unique key of the market
161
+ *@param network - The network number
162
+ *@returns The reallocatable liquidity and target borrow utilization
163
+ */
158
164
  export const getReallocatableLiquidity = (marketId, network = NetworkNumber.Eth) => __awaiter(void 0, void 0, void 0, function* () {
159
165
  var _a;
160
166
  const response = yield fetch(API_URL, {
@@ -171,6 +177,16 @@ export const getReallocatableLiquidity = (marketId, network = NetworkNumber.Eth)
171
177
  throw new Error('Market data not found');
172
178
  return { reallocatableLiquidity: marketData.reallocatableLiquidityAssets, targetBorrowUtilization: marketData.targetBorrowUtilization };
173
179
  });
180
+ /**
181
+ *Get liquidity to allocate for a given amount to borrow. First, the function will try to calculate the amount of liquidity to allocate to be able to hit the target utilization.
182
+ * If it is not possible to allocate enough liquidity to hit the target utilization, the function will allocate the amount of liquidity needed to be able to borrow the selected amount.
183
+ * @param amountToBorrow - The amount to borrow
184
+ * @param totalBorrow - The total amount borrowed
185
+ * @param totalSupply - The total amount supplied
186
+ * @param targetBorrowUtilization - The target borrow utilization
187
+ * @param reallocatableLiquidityAssets - The amount of liquidity that can be reallocated
188
+ * @returns The amount of liquidity to allocate
189
+ */
174
190
  export const getLiquidityToAllocate = (amountToBorrow, totalBorrow, totalSupply, targetBorrowUtilization, reallocatableLiquidityAssets) => {
175
191
  const newTotalBorrowAssets = new Dec(totalBorrow).add(amountToBorrow).toString();
176
192
  const leftToBorrow = new Dec(totalSupply).sub(totalBorrow).toString();
@@ -178,12 +194,19 @@ export const getLiquidityToAllocate = (amountToBorrow, totalBorrow, totalSupply,
178
194
  .toFixed(0)
179
195
  .toString();
180
196
  if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate) || new Dec(liquidityToAllocate).lt('0')) {
181
- liquidityToAllocate = new Dec(amountToBorrow).sub(leftToBorrow).toString();
197
+ liquidityToAllocate = new Dec(amountToBorrow).lt(leftToBorrow) ? '0' : new Dec(amountToBorrow).sub(leftToBorrow).toString();
182
198
  if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate))
183
199
  throw new Error('Not enough liquidity available to allocate');
184
200
  }
185
201
  return liquidityToAllocate;
186
202
  };
203
+ /**
204
+ * Get the vaults and withdrawals needed to reallocate liquidity for a given amount to borrow
205
+ * @param marketId - The unique key of the market
206
+ * @param amountToBorrow - The amount to borrow
207
+ * @param network - The network number
208
+ * @returns The vaults and withdrawals needed to reallocate liquidity
209
+ */
187
210
  export const getReallocation = (marketId, amountToBorrow, network = NetworkNumber.Eth) => __awaiter(void 0, void 0, void 0, function* () {
188
211
  var _b, _c, _d;
189
212
  const response = yield fetch(API_URL, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "0.0.183-dev-allocator-5",
3
+ "version": "0.0.183-dev-allocator-7",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -176,6 +176,12 @@ const MARKET_QUERY = `
176
176
  }
177
177
  `;
178
178
 
179
+ /**
180
+ *Get reallocatable liquidity and target borrow utilization for a given market
181
+ *@param marketId - The unique key of the market
182
+ *@param network - The network number
183
+ *@returns The reallocatable liquidity and target borrow utilization
184
+ */
179
185
  export const getReallocatableLiquidity = async (marketId: string, network: NetworkNumber = NetworkNumber.Eth): Promise<{ reallocatableLiquidity: string, targetBorrowUtilization: string }> => {
180
186
  const response = await fetch(API_URL, {
181
187
  method: 'POST',
@@ -194,6 +200,16 @@ export const getReallocatableLiquidity = async (marketId: string, network: Netwo
194
200
  return { reallocatableLiquidity: marketData.reallocatableLiquidityAssets, targetBorrowUtilization: marketData.targetBorrowUtilization };
195
201
  };
196
202
 
203
+ /**
204
+ *Get liquidity to allocate for a given amount to borrow. First, the function will try to calculate the amount of liquidity to allocate to be able to hit the target utilization.
205
+ * If it is not possible to allocate enough liquidity to hit the target utilization, the function will allocate the amount of liquidity needed to be able to borrow the selected amount.
206
+ * @param amountToBorrow - The amount to borrow
207
+ * @param totalBorrow - The total amount borrowed
208
+ * @param totalSupply - The total amount supplied
209
+ * @param targetBorrowUtilization - The target borrow utilization
210
+ * @param reallocatableLiquidityAssets - The amount of liquidity that can be reallocated
211
+ * @returns The amount of liquidity to allocate
212
+ */
197
213
  export const getLiquidityToAllocate = (amountToBorrow: string, totalBorrow: string, totalSupply: string, targetBorrowUtilization: string, reallocatableLiquidityAssets: string) => {
198
214
  const newTotalBorrowAssets = new Dec(totalBorrow).add(amountToBorrow).toString();
199
215
  const leftToBorrow = new Dec(totalSupply).sub(totalBorrow).toString();
@@ -202,13 +218,20 @@ export const getLiquidityToAllocate = (amountToBorrow: string, totalBorrow: stri
202
218
  .toString();
203
219
 
204
220
  if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate) || new Dec(liquidityToAllocate).lt('0')) {
205
- liquidityToAllocate = new Dec(amountToBorrow).sub(leftToBorrow).toString();
221
+ liquidityToAllocate = new Dec(amountToBorrow).lt(leftToBorrow) ? '0' : new Dec(amountToBorrow).sub(leftToBorrow).toString();
206
222
  if (new Dec(reallocatableLiquidityAssets).lt(liquidityToAllocate)) throw new Error('Not enough liquidity available to allocate');
207
223
  }
208
224
 
209
225
  return liquidityToAllocate;
210
226
  };
211
227
 
228
+ /**
229
+ * Get the vaults and withdrawals needed to reallocate liquidity for a given amount to borrow
230
+ * @param marketId - The unique key of the market
231
+ * @param amountToBorrow - The amount to borrow
232
+ * @param network - The network number
233
+ * @returns The vaults and withdrawals needed to reallocate liquidity
234
+ */
212
235
  export const getReallocation = async (marketId: string, amountToBorrow: string, network: NetworkNumber = NetworkNumber.Eth) => {
213
236
  const response = await fetch(API_URL, {
214
237
  method: 'POST',