@jup-ag/lend 0.0.90 → 0.0.91

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.
@@ -4021,6 +4021,7 @@ declare const getCurrentPosition: ({ vaultId, positionId, connection, }: GetCurr
4021
4021
  debtRaw: BN;
4022
4022
  dustDebtRaw: BN;
4023
4023
  isSupplyOnlyPosition: boolean;
4024
+ userLiquidationStatus: boolean;
4024
4025
  }>;
4025
4026
  declare const getCurrentPositionState: ({ vaultId, position, program, }: GetCurrentPositionStateParams) => Promise<{
4026
4027
  tick: number;
@@ -4030,6 +4031,7 @@ declare const getCurrentPositionState: ({ vaultId, position, program, }: GetCurr
4030
4031
  debtRaw: BN;
4031
4032
  dustDebtRaw: BN;
4032
4033
  isSupplyOnlyPosition: boolean;
4034
+ userLiquidationStatus: boolean;
4033
4035
  }>;
4034
4036
  declare const getFinalPosition: ({ vaultId, currentPosition, newColAmount, newDebtAmount, program, connection, signer, }: {
4035
4037
  vaultId: number;
@@ -4048,14 +4050,8 @@ declare const getFinalPosition: ({ vaultId, currentPosition, newColAmount, newDe
4048
4050
  finalAmount: BN;
4049
4051
  isSupplyOnlyPosition: boolean;
4050
4052
  }>;
4051
- declare function loadRelevantBranches(vaultId: number, vaultState: VaultState, program: Program<Vaults>): Promise<number[]>;
4052
- declare function loadRelevantTicksHasDebtArrays(vaultId: number, topTick: number, program: Program<Vaults>): Promise<{
4053
- vaultId: number;
4054
- index: number;
4055
- tickHasDebt: {
4056
- childrenBits: number[];
4057
- }[];
4058
- }[]>;
4053
+ declare function loadRelevantBranches(vaultId: number, vaultState: VaultState, liquidationStatus: boolean, program: Program<Vaults>): Promise<number[]>;
4054
+ declare function loadRelevantTicksHasDebtArrays(vaultId: number, topTick: number, existingPositionTick: number, finalTick: number): Promise<PublicKey[]>;
4059
4055
  declare function loadRelevantTicksHasDebtArraysLiquidate(vaultId: number, topTick: number, nextTick: number, program: Program<Vaults>): Promise<{
4060
4056
  vaultId: number;
4061
4057
  index: number;
@@ -4021,6 +4021,7 @@ declare const getCurrentPosition: ({ vaultId, positionId, connection, }: GetCurr
4021
4021
  debtRaw: BN;
4022
4022
  dustDebtRaw: BN;
4023
4023
  isSupplyOnlyPosition: boolean;
4024
+ userLiquidationStatus: boolean;
4024
4025
  }>;
4025
4026
  declare const getCurrentPositionState: ({ vaultId, position, program, }: GetCurrentPositionStateParams) => Promise<{
4026
4027
  tick: number;
@@ -4030,6 +4031,7 @@ declare const getCurrentPositionState: ({ vaultId, position, program, }: GetCurr
4030
4031
  debtRaw: BN;
4031
4032
  dustDebtRaw: BN;
4032
4033
  isSupplyOnlyPosition: boolean;
4034
+ userLiquidationStatus: boolean;
4033
4035
  }>;
4034
4036
  declare const getFinalPosition: ({ vaultId, currentPosition, newColAmount, newDebtAmount, program, connection, signer, }: {
4035
4037
  vaultId: number;
@@ -4048,14 +4050,8 @@ declare const getFinalPosition: ({ vaultId, currentPosition, newColAmount, newDe
4048
4050
  finalAmount: BN;
4049
4051
  isSupplyOnlyPosition: boolean;
4050
4052
  }>;
4051
- declare function loadRelevantBranches(vaultId: number, vaultState: VaultState, program: Program<Vaults>): Promise<number[]>;
4052
- declare function loadRelevantTicksHasDebtArrays(vaultId: number, topTick: number, program: Program<Vaults>): Promise<{
4053
- vaultId: number;
4054
- index: number;
4055
- tickHasDebt: {
4056
- childrenBits: number[];
4057
- }[];
4058
- }[]>;
4053
+ declare function loadRelevantBranches(vaultId: number, vaultState: VaultState, liquidationStatus: boolean, program: Program<Vaults>): Promise<number[]>;
4054
+ declare function loadRelevantTicksHasDebtArrays(vaultId: number, topTick: number, existingPositionTick: number, finalTick: number): Promise<PublicKey[]>;
4059
4055
  declare function loadRelevantTicksHasDebtArraysLiquidate(vaultId: number, topTick: number, nextTick: number, program: Program<Vaults>): Promise<{
4060
4056
  vaultId: number;
4061
4057
  index: number;
@@ -871,7 +871,8 @@ const getCurrentPositionState = async ({
871
871
  finalAmount: new BN(position.supplyAmount.toString()),
872
872
  debtRaw: new BN(0),
873
873
  dustDebtRaw: new BN(0),
874
- isSupplyOnlyPosition: true
874
+ isSupplyOnlyPosition: true,
875
+ userLiquidationStatus: false
875
876
  };
876
877
  }
877
878
  const colRaw = new BN(position.supplyAmount.toString());
@@ -884,11 +885,13 @@ const getCurrentPositionState = async ({
884
885
  } else {
885
886
  debtRaw = new BN(0);
886
887
  }
888
+ let userLiquidationStatus = false;
887
889
  if (positionTick > MIN_TICK) {
888
890
  const tickData = await program.account.tick.fetch(
889
891
  getTick(vaultId, positionTick)
890
892
  );
891
893
  if (tickData.isLiquidated || tickData.totalIds > position.tickId) {
894
+ userLiquidationStatus = true;
892
895
  let [tickIdData, branches] = await Promise.all([
893
896
  program.account.tickIdLiquidation.fetch(
894
897
  getTickIdLiquidation(
@@ -924,7 +927,8 @@ const getCurrentPositionState = async ({
924
927
  debtRaw: new BN(0),
925
928
  dustDebtRaw: new BN(0),
926
929
  finalAmount: new BN(0),
927
- isSupplyOnlyPosition: true
930
+ isSupplyOnlyPosition: true,
931
+ userLiquidationStatus: true
928
932
  };
929
933
  }
930
934
  const { finalTick, finalColRaw, finalDebtRaw } = await processLiquidatedPosition({
@@ -941,7 +945,8 @@ const getCurrentPositionState = async ({
941
945
  debtRaw: finalDebtRaw,
942
946
  dustDebtRaw,
943
947
  finalAmount: netDebtRaw2.gt(new BN(0)) ? finalColRaw : new BN(0),
944
- isSupplyOnlyPosition: finalTick === MIN_TICK
948
+ isSupplyOnlyPosition: finalTick === MIN_TICK,
949
+ userLiquidationStatus
945
950
  };
946
951
  }
947
952
  }
@@ -953,7 +958,8 @@ const getCurrentPositionState = async ({
953
958
  debtRaw,
954
959
  dustDebtRaw,
955
960
  finalAmount: netDebtRaw.gt(new BN(0)) ? colRaw : new BN(0),
956
- isSupplyOnlyPosition: positionTick === MIN_TICK
961
+ isSupplyOnlyPosition: positionTick === MIN_TICK,
962
+ userLiquidationStatus
957
963
  };
958
964
  };
959
965
  async function getAllBranches({
@@ -1150,7 +1156,7 @@ const getFinalPosition = async ({
1150
1156
  isSupplyOnlyPosition
1151
1157
  };
1152
1158
  };
1153
- async function loadRelevantBranches(vaultId, vaultState, program) {
1159
+ async function loadRelevantBranches(vaultId, vaultState, liquidationStatus, program) {
1154
1160
  const addedBranchIds = /* @__PURE__ */ new Set();
1155
1161
  const currentBranchId = vaultState.currentBranchId;
1156
1162
  let connectedBranchId = 0;
@@ -1167,38 +1173,50 @@ async function loadRelevantBranches(vaultId, vaultState, program) {
1167
1173
  console.warn(`Failed to fetch current branch ${currentBranchId}:`, error);
1168
1174
  }
1169
1175
  }
1170
- while (connectedBranchId > 0) {
1171
- try {
1172
- const connectedBranch = await program.account.branch.fetch(
1173
- getBranch(vaultId, connectedBranchId)
1174
- );
1175
- if (connectedBranch) {
1176
- if (!addedBranchIds.has(connectedBranch.branchId))
1177
- addedBranchIds.add(connectedBranch.branchId);
1178
- connectedBranchId = connectedBranch.connectedBranchId;
1179
- } else break;
1180
- } catch (error) {
1181
- console.warn(
1182
- `Failed to fetch connected branch ${connectedBranchId}:`,
1183
- error
1184
- );
1185
- break;
1176
+ if (liquidationStatus) {
1177
+ while (connectedBranchId > 0) {
1178
+ try {
1179
+ const connectedBranch = await program.account.branch.fetch(
1180
+ getBranch(vaultId, connectedBranchId)
1181
+ );
1182
+ if (connectedBranch) {
1183
+ if (!addedBranchIds.has(connectedBranch.branchId))
1184
+ addedBranchIds.add(connectedBranch.branchId);
1185
+ connectedBranchId = connectedBranch.connectedBranchId;
1186
+ } else break;
1187
+ } catch (error) {
1188
+ console.warn(
1189
+ `Failed to fetch connected branch ${connectedBranchId}:`,
1190
+ error
1191
+ );
1192
+ break;
1193
+ }
1186
1194
  }
1195
+ if (!addedBranchIds.has(0)) addedBranchIds.add(0);
1187
1196
  }
1188
- if (!addedBranchIds.has(0)) addedBranchIds.add(0);
1189
1197
  return [...addedBranchIds];
1190
1198
  }
1191
- async function loadRelevantTicksHasDebtArrays(vaultId, topTick, program) {
1192
- let { arrayIndex: topTickIndex } = getTickIndices(topTick);
1193
- if (topTickIndex < 15) topTickIndex += 1;
1194
- return await Promise.all(
1195
- Array.from(
1196
- { length: topTickIndex },
1197
- (_, i) => program.account.tickHasDebtArray.fetch(
1198
- getTickHasDebt(vaultId, topTickIndex - i)
1199
- )
1200
- )
1201
- );
1199
+ async function loadRelevantTicksHasDebtArrays(vaultId, topTick, existingPositionTick, finalTick) {
1200
+ const tickHasDebtArrays = /* @__PURE__ */ new Set();
1201
+ if (existingPositionTick == topTick && finalTick < topTick) {
1202
+ let { arrayIndex: startIndex } = getTickIndices(finalTick);
1203
+ let { arrayIndex: endIndex } = getTickIndices(topTick);
1204
+ if (endIndex < 15) endIndex++;
1205
+ try {
1206
+ for (let arrIdx = startIndex; arrIdx <= endIndex; arrIdx++)
1207
+ tickHasDebtArrays.add(getTickHasDebt(vaultId, arrIdx));
1208
+ } catch (error) {
1209
+ console.warn(`Error finding next tick with debt:`, error);
1210
+ }
1211
+ } else {
1212
+ let { arrayIndex: finalTickIndex } = getTickIndices(finalTick);
1213
+ let { arrayIndex: existingPositionTickIndex } = getTickIndices(existingPositionTick);
1214
+ tickHasDebtArrays.add(getTickHasDebt(vaultId, finalTickIndex));
1215
+ tickHasDebtArrays.add(
1216
+ getTickHasDebt(vaultId, existingPositionTickIndex)
1217
+ );
1218
+ }
1219
+ return [...tickHasDebtArrays];
1202
1220
  }
1203
1221
  async function getExchangePrices({
1204
1222
  vaultId,
@@ -1425,18 +1443,18 @@ async function getOtherInstructionsOperate(vaultId, vaultState, currentPosition,
1425
1443
  const tickHelper = (tickValue) => {
1426
1444
  return tickValue === 0 ? INIT_TICK : tickValue;
1427
1445
  };
1428
- async function getRemainingAccountsOperate(vaultId, vaultState, vaultConfig, finalPositionTick, program) {
1446
+ async function getRemainingAccountsOperate(vaultId, vaultState, vaultConfig, finalPositionTick, existingPositionTick, liquidationStatus, program) {
1429
1447
  const remainingAccounts = [];
1430
1448
  const oracleProgram = new Program(oracle, program.provider);
1431
1449
  const [oracleData, branches, tickHasDebt] = await Promise.all([
1432
1450
  oracleProgram.account.oracle.fetch(new PublicKey(vaultConfig.oracle)),
1433
1451
  // Add branch accounts (next 10 remaining accounts)
1434
- loadRelevantBranches(vaultId, vaultState, program),
1452
+ loadRelevantBranches(vaultId, vaultState, liquidationStatus, program),
1435
1453
  loadRelevantTicksHasDebtArrays(
1436
1454
  vaultId,
1437
- Math.max(finalPositionTick, tickHelper(vaultState.topmostTick)),
1438
- // max of both ticks
1439
- program
1455
+ tickHelper(vaultState.topmostTick),
1456
+ existingPositionTick,
1457
+ finalPositionTick
1440
1458
  )
1441
1459
  ]);
1442
1460
  const sourceLength = oracleData.sources.length;
@@ -1457,7 +1475,7 @@ async function getRemainingAccountsOperate(vaultId, vaultState, vaultConfig, fin
1457
1475
  const tickHasDebtLength = tickHasDebt.length;
1458
1476
  for (const tickHasDebtArray of tickHasDebt)
1459
1477
  remainingAccounts.push({
1460
- pubkey: getTickHasDebt(vaultId, tickHasDebtArray.index),
1478
+ pubkey: tickHasDebtArray,
1461
1479
  isWritable: true,
1462
1480
  isSigner: false
1463
1481
  });
@@ -1549,6 +1567,8 @@ async function getOperateContext({
1549
1567
  vaultState,
1550
1568
  vaultConfig,
1551
1569
  finalPosition.tick,
1570
+ existingPositionTick,
1571
+ currentPosition.userLiquidationStatus,
1552
1572
  program
1553
1573
  );
1554
1574
  const accounts = {
package/dist/index.mjs CHANGED
@@ -8,6 +8,6 @@ import './shared/lend.CioR9-te.mjs';
8
8
  import '@solana/spl-token';
9
9
  import 'bn.js';
10
10
 
11
- const version = "0.0.90";
11
+ const version = "0.0.91";
12
12
 
13
13
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jup-ag/lend",
3
- "version": "0.0.90",
3
+ "version": "0.0.91",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "type": "module",