@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.
- package/cjs/helpers/morphoBlueHelpers/index.d.ts +1 -1
- package/cjs/helpers/morphoBlueHelpers/index.js +2 -1
- package/cjs/types/morphoBlue.d.ts +1 -0
- package/esm/helpers/morphoBlueHelpers/index.d.ts +1 -1
- package/esm/helpers/morphoBlueHelpers/index.js +2 -1
- package/esm/types/morphoBlue.d.ts +1 -0
- package/package.json +1 -1
- package/src/helpers/morphoBlueHelpers/index.ts +6 -3
- package/src/types/morphoBlue.ts +1 -0
|
@@ -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:
|
|
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,
|
|
@@ -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:
|
|
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,
|
package/package.json
CHANGED
|
@@ -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,
|