@defisaver/positions-sdk 0.0.183-dev-allocator-2 → 0.0.183-dev-allocator-3

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.
@@ -15,5 +15,5 @@ export declare const getApyAfterValuesEstimation: (selectedMarket: MorphoBlueMar
15
15
  export declare const getReallocatableLiquidity: (marketId: string, network?: NetworkNumber) => Promise<string>;
16
16
  export declare const getReallocation: (marketId: string, amountToBorrow: string, network?: NetworkNumber) => Promise<{
17
17
  vaults: string[];
18
- withdrawals: [string[], string][][];
18
+ withdrawals: (string | string[])[][][];
19
19
  }>;
@@ -236,6 +236,7 @@ const getReallocation = (marketId, amountToBorrow, network = common_1.NetworkNum
236
236
  item.allocationMarket.lltv,
237
237
  ],
238
238
  amountToTake.toString(),
239
+ item.allocationMarket.uniqueKey,
239
240
  ];
240
241
  if (!withdrawalsPerVault[vaultAddress]) {
241
242
  withdrawalsPerVault[vaultAddress] = [];
@@ -244,7 +245,7 @@ const getReallocation = (marketId, amountToBorrow, network = common_1.NetworkNum
244
245
  }
245
246
  }
246
247
  const vaults = Object.keys(withdrawalsPerVault);
247
- const withdrawals = vaults.map((vaultAddress) => withdrawalsPerVault[vaultAddress]);
248
+ const withdrawals = vaults.map((vaultAddress) => withdrawalsPerVault[vaultAddress].sort((a, b) => a[2].localeCompare(b[2])).map(w => [w[0], w[1]]));
248
249
  return {
249
250
  vaults,
250
251
  withdrawals,
@@ -152,6 +152,7 @@ export interface MorphoBlueAllocationMarket {
152
152
  };
153
153
  irmAddress: string;
154
154
  lltv: string;
155
+ uniqueKey: string;
155
156
  }
156
157
  export interface MorphoBluePublicAllocatorItem {
157
158
  vault: MorphoBlueVault;
@@ -15,5 +15,5 @@ export declare const getApyAfterValuesEstimation: (selectedMarket: MorphoBlueMar
15
15
  export declare const getReallocatableLiquidity: (marketId: string, network?: NetworkNumber) => Promise<string>;
16
16
  export declare const getReallocation: (marketId: string, amountToBorrow: string, network?: NetworkNumber) => Promise<{
17
17
  vaults: string[];
18
- withdrawals: [string[], string][][];
18
+ withdrawals: (string | string[])[][][];
19
19
  }>;
@@ -225,6 +225,7 @@ export const getReallocation = (marketId, amountToBorrow, network = NetworkNumbe
225
225
  item.allocationMarket.lltv,
226
226
  ],
227
227
  amountToTake.toString(),
228
+ item.allocationMarket.uniqueKey,
228
229
  ];
229
230
  if (!withdrawalsPerVault[vaultAddress]) {
230
231
  withdrawalsPerVault[vaultAddress] = [];
@@ -233,7 +234,7 @@ export const getReallocation = (marketId, amountToBorrow, network = NetworkNumbe
233
234
  }
234
235
  }
235
236
  const vaults = Object.keys(withdrawalsPerVault);
236
- const withdrawals = vaults.map((vaultAddress) => withdrawalsPerVault[vaultAddress]);
237
+ const withdrawals = vaults.map((vaultAddress) => withdrawalsPerVault[vaultAddress].sort((a, b) => a[2].localeCompare(b[2])).map(w => [w[0], w[1]]));
237
238
  return {
238
239
  vaults,
239
240
  withdrawals,
@@ -152,6 +152,7 @@ export interface MorphoBlueAllocationMarket {
152
152
  };
153
153
  irmAddress: string;
154
154
  lltv: string;
155
+ uniqueKey: string;
155
156
  }
156
157
  export interface MorphoBluePublicAllocatorItem {
157
158
  vault: MorphoBlueVault;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "0.0.183-dev-allocator-2",
3
+ "version": "0.0.183-dev-allocator-3",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -233,7 +233,7 @@ export const getReallocation = async (marketId: string, amountToBorrow: string,
233
233
  ([, a]: [string, string], [, b]: [string, string]) => new Dec(b || '0').sub(a || '0').toNumber(),
234
234
  );
235
235
 
236
- const withdrawalsPerVault: Record<string, [string[], string][]> = {};
236
+ const withdrawalsPerVault: Record<string, [string[], string, string][]> = {};
237
237
  let totalReallocated = '0';
238
238
  for (const [vaultAddress] of sortedVaults) {
239
239
  if (new Dec(totalReallocated).gte(liquidityToAllocate)) break;
@@ -247,7 +247,7 @@ export const getReallocation = async (marketId: string, amountToBorrow: string,
247
247
  const leftToAllocate = new Dec(liquidityToAllocate).sub(totalReallocated).toString();
248
248
  const amountToTake = new Dec(itemAmount).lt(leftToAllocate) ? itemAmount : leftToAllocate;
249
249
  totalReallocated = new Dec(totalReallocated).add(amountToTake).toString();
250
- const withdrawal: [string[], string] = [
250
+ const withdrawal: [string[], string, string] = [
251
251
  [
252
252
  item.allocationMarket.loanAsset.address,
253
253
  item.allocationMarket.collateralAsset?.address,
@@ -256,6 +256,7 @@ export const getReallocation = async (marketId: string, amountToBorrow: string,
256
256
  item.allocationMarket.lltv,
257
257
  ],
258
258
  amountToTake.toString(),
259
+ item.allocationMarket.uniqueKey,
259
260
  ];
260
261
  if (!withdrawalsPerVault[vaultAddress]) {
261
262
  withdrawalsPerVault[vaultAddress] = [];
@@ -266,7 +267,9 @@ export const getReallocation = async (marketId: string, amountToBorrow: string,
266
267
 
267
268
  const vaults = Object.keys(withdrawalsPerVault);
268
269
  const withdrawals = vaults.map(
269
- (vaultAddress) => withdrawalsPerVault[vaultAddress],
270
+ (vaultAddress) => withdrawalsPerVault[vaultAddress].sort(
271
+ (a, b) => a[2].localeCompare(b[2]),
272
+ ).map(w => [w[0], w[1]]),
270
273
  );
271
274
  return {
272
275
  vaults,
@@ -163,6 +163,7 @@ export interface MorphoBlueAllocationMarket {
163
163
  oracle: { address: string },
164
164
  irmAddress: string,
165
165
  lltv: string,
166
+ uniqueKey: string,
166
167
  }
167
168
 
168
169
  export interface MorphoBluePublicAllocatorItem {