@jup-ag/lend 0.0.90 → 0.0.92

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;
@@ -4076,9 +4072,15 @@ declare function readOraclePrice({ connection, signer, oracle, }: {
4076
4072
  invert: boolean;
4077
4073
  multiplier: BN;
4078
4074
  divisor: BN;
4079
- sourceType: {} & {
4075
+ sourceType: ({
4076
+ stakePool?: undefined;
4077
+ } & {
4080
4078
  pyth: Record<string, never>;
4081
- };
4079
+ }) | ({
4080
+ pyth?: undefined;
4081
+ } & {
4082
+ stakePool: Record<string, never>;
4083
+ });
4082
4084
  }[];
4083
4085
  }>;
4084
4086
 
@@ -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;
@@ -4076,9 +4072,15 @@ declare function readOraclePrice({ connection, signer, oracle, }: {
4076
4072
  invert: boolean;
4077
4073
  multiplier: BN;
4078
4074
  divisor: BN;
4079
- sourceType: {} & {
4075
+ sourceType: ({
4076
+ stakePool?: undefined;
4077
+ } & {
4080
4078
  pyth: Record<string, never>;
4081
- };
4079
+ }) | ({
4080
+ pyth?: undefined;
4081
+ } & {
4082
+ stakePool: Record<string, never>;
4083
+ });
4082
4084
  }[];
4083
4085
  }>;
4084
4086
 
@@ -14,6 +14,30 @@ const metadata = {
14
14
  description: "Created with Anchor"
15
15
  };
16
16
  const instructions = [
17
+ {
18
+ name: "get_both_exchange_rate",
19
+ discriminator: [
20
+ 92,
21
+ 88,
22
+ 161,
23
+ 46,
24
+ 230,
25
+ 193,
26
+ 46,
27
+ 237
28
+ ],
29
+ accounts: [
30
+ {
31
+ name: "oracle"
32
+ }
33
+ ],
34
+ args: [
35
+ {
36
+ name: "_nonce",
37
+ type: "u16"
38
+ }
39
+ ]
40
+ },
17
41
  {
18
42
  name: "get_exchange_rate",
19
43
  discriminator: [
@@ -275,6 +299,19 @@ const accounts = [
275
299
  }
276
300
  ];
277
301
  const events = [
302
+ {
303
+ name: "LogUpdateAuthority",
304
+ discriminator: [
305
+ 150,
306
+ 152,
307
+ 157,
308
+ 143,
309
+ 6,
310
+ 135,
311
+ 193,
312
+ 101
313
+ ]
314
+ },
278
315
  {
279
316
  name: "LogUpdateAuths",
280
317
  discriminator: [
@@ -312,43 +349,58 @@ const errors = [
312
349
  },
313
350
  {
314
351
  code: 6004,
352
+ name: "InvalidPythSourceMultiplierAndDivisor",
353
+ msg: "INVALID_PYTH_SOURCE_MULTIPLIER_AND_DIVISOR"
354
+ },
355
+ {
356
+ code: 6005,
315
357
  name: "InvalidSource",
316
358
  msg: "INVALID_SOURCE"
317
359
  },
318
360
  {
319
- code: 6005,
361
+ code: 6006,
320
362
  name: "InvalidSourcesLength",
321
363
  msg: "INVALID_SOURCES_LENGTH"
322
364
  },
323
365
  {
324
- code: 6006,
366
+ code: 6007,
325
367
  name: "OracleAdminOnlyAuthority",
326
368
  msg: "ORACLE_ADMIN_ONLY_AUTHORITY"
327
369
  },
328
370
  {
329
- code: 6007,
371
+ code: 6008,
330
372
  name: "OracleAdminOnlyAuth",
331
373
  msg: "ORACLE_ADMIN_ONLY_AUTH"
332
374
  },
333
375
  {
334
- code: 6008,
376
+ code: 6009,
335
377
  name: "OracleAdminMaxAuthCountReached",
336
378
  msg: "ORACLE_ADMIN_MAX_AUTH_COUNT_REACHED"
337
379
  },
338
380
  {
339
- code: 6009,
381
+ code: 6010,
340
382
  name: "OracleAdminInvalidParams",
341
383
  msg: "ORACLE_ADMIN_INVALID_PARAMS"
342
384
  },
343
385
  {
344
- code: 6010,
386
+ code: 6011,
345
387
  name: "OracleNonceMismatch",
346
388
  msg: "ORACLE_NONCE_MISMATCH"
347
389
  },
348
390
  {
349
- code: 6011,
391
+ code: 6012,
350
392
  name: "PriceConfidenceNotSufficient",
351
393
  msg: "PRICE_CONFIDENCE_NOT_SUFFICIENT"
394
+ },
395
+ {
396
+ code: 6013,
397
+ name: "StakePoolNotRefreshed",
398
+ msg: "STAKE_POOL_NOT_REFRESHED"
399
+ },
400
+ {
401
+ code: 6014,
402
+ name: "InvalidPrice",
403
+ msg: "INVALID_PRICE"
352
404
  }
353
405
  ];
354
406
  const types = [
@@ -368,6 +420,18 @@ const types = [
368
420
  ]
369
421
  }
370
422
  },
423
+ {
424
+ name: "LogUpdateAuthority",
425
+ type: {
426
+ kind: "struct",
427
+ fields: [
428
+ {
429
+ name: "new_authority",
430
+ type: "pubkey"
431
+ }
432
+ ]
433
+ }
434
+ },
371
435
  {
372
436
  name: "LogUpdateAuths",
373
437
  type: {
@@ -437,6 +501,9 @@ const types = [
437
501
  variants: [
438
502
  {
439
503
  name: "Pyth"
504
+ },
505
+ {
506
+ name: "StakePool"
440
507
  }
441
508
  ]
442
509
  }
@@ -871,7 +938,8 @@ const getCurrentPositionState = async ({
871
938
  finalAmount: new BN(position.supplyAmount.toString()),
872
939
  debtRaw: new BN(0),
873
940
  dustDebtRaw: new BN(0),
874
- isSupplyOnlyPosition: true
941
+ isSupplyOnlyPosition: true,
942
+ userLiquidationStatus: false
875
943
  };
876
944
  }
877
945
  const colRaw = new BN(position.supplyAmount.toString());
@@ -884,11 +952,13 @@ const getCurrentPositionState = async ({
884
952
  } else {
885
953
  debtRaw = new BN(0);
886
954
  }
955
+ let userLiquidationStatus = false;
887
956
  if (positionTick > MIN_TICK) {
888
957
  const tickData = await program.account.tick.fetch(
889
958
  getTick(vaultId, positionTick)
890
959
  );
891
960
  if (tickData.isLiquidated || tickData.totalIds > position.tickId) {
961
+ userLiquidationStatus = true;
892
962
  let [tickIdData, branches] = await Promise.all([
893
963
  program.account.tickIdLiquidation.fetch(
894
964
  getTickIdLiquidation(
@@ -924,7 +994,8 @@ const getCurrentPositionState = async ({
924
994
  debtRaw: new BN(0),
925
995
  dustDebtRaw: new BN(0),
926
996
  finalAmount: new BN(0),
927
- isSupplyOnlyPosition: true
997
+ isSupplyOnlyPosition: true,
998
+ userLiquidationStatus: true
928
999
  };
929
1000
  }
930
1001
  const { finalTick, finalColRaw, finalDebtRaw } = await processLiquidatedPosition({
@@ -941,7 +1012,8 @@ const getCurrentPositionState = async ({
941
1012
  debtRaw: finalDebtRaw,
942
1013
  dustDebtRaw,
943
1014
  finalAmount: netDebtRaw2.gt(new BN(0)) ? finalColRaw : new BN(0),
944
- isSupplyOnlyPosition: finalTick === MIN_TICK
1015
+ isSupplyOnlyPosition: finalTick === MIN_TICK,
1016
+ userLiquidationStatus
945
1017
  };
946
1018
  }
947
1019
  }
@@ -953,7 +1025,8 @@ const getCurrentPositionState = async ({
953
1025
  debtRaw,
954
1026
  dustDebtRaw,
955
1027
  finalAmount: netDebtRaw.gt(new BN(0)) ? colRaw : new BN(0),
956
- isSupplyOnlyPosition: positionTick === MIN_TICK
1028
+ isSupplyOnlyPosition: positionTick === MIN_TICK,
1029
+ userLiquidationStatus
957
1030
  };
958
1031
  };
959
1032
  async function getAllBranches({
@@ -1150,7 +1223,7 @@ const getFinalPosition = async ({
1150
1223
  isSupplyOnlyPosition
1151
1224
  };
1152
1225
  };
1153
- async function loadRelevantBranches(vaultId, vaultState, program) {
1226
+ async function loadRelevantBranches(vaultId, vaultState, liquidationStatus, program) {
1154
1227
  const addedBranchIds = /* @__PURE__ */ new Set();
1155
1228
  const currentBranchId = vaultState.currentBranchId;
1156
1229
  let connectedBranchId = 0;
@@ -1167,38 +1240,50 @@ async function loadRelevantBranches(vaultId, vaultState, program) {
1167
1240
  console.warn(`Failed to fetch current branch ${currentBranchId}:`, error);
1168
1241
  }
1169
1242
  }
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;
1243
+ if (liquidationStatus) {
1244
+ while (connectedBranchId > 0) {
1245
+ try {
1246
+ const connectedBranch = await program.account.branch.fetch(
1247
+ getBranch(vaultId, connectedBranchId)
1248
+ );
1249
+ if (connectedBranch) {
1250
+ if (!addedBranchIds.has(connectedBranch.branchId))
1251
+ addedBranchIds.add(connectedBranch.branchId);
1252
+ connectedBranchId = connectedBranch.connectedBranchId;
1253
+ } else break;
1254
+ } catch (error) {
1255
+ console.warn(
1256
+ `Failed to fetch connected branch ${connectedBranchId}:`,
1257
+ error
1258
+ );
1259
+ break;
1260
+ }
1186
1261
  }
1262
+ if (!addedBranchIds.has(0)) addedBranchIds.add(0);
1187
1263
  }
1188
- if (!addedBranchIds.has(0)) addedBranchIds.add(0);
1189
1264
  return [...addedBranchIds];
1190
1265
  }
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
- );
1266
+ async function loadRelevantTicksHasDebtArrays(vaultId, topTick, existingPositionTick, finalTick) {
1267
+ const tickHasDebtArrays = /* @__PURE__ */ new Set();
1268
+ if (existingPositionTick == topTick && finalTick < topTick) {
1269
+ let { arrayIndex: startIndex } = getTickIndices(finalTick);
1270
+ let { arrayIndex: endIndex } = getTickIndices(topTick);
1271
+ if (endIndex < 15) endIndex++;
1272
+ try {
1273
+ for (let arrIdx = startIndex; arrIdx <= endIndex; arrIdx++)
1274
+ tickHasDebtArrays.add(getTickHasDebt(vaultId, arrIdx));
1275
+ } catch (error) {
1276
+ console.warn(`Error finding next tick with debt:`, error);
1277
+ }
1278
+ } else {
1279
+ let { arrayIndex: finalTickIndex } = getTickIndices(finalTick);
1280
+ let { arrayIndex: existingPositionTickIndex } = getTickIndices(existingPositionTick);
1281
+ tickHasDebtArrays.add(getTickHasDebt(vaultId, finalTickIndex));
1282
+ tickHasDebtArrays.add(
1283
+ getTickHasDebt(vaultId, existingPositionTickIndex)
1284
+ );
1285
+ }
1286
+ return [...tickHasDebtArrays];
1202
1287
  }
1203
1288
  async function getExchangePrices({
1204
1289
  vaultId,
@@ -1425,18 +1510,18 @@ async function getOtherInstructionsOperate(vaultId, vaultState, currentPosition,
1425
1510
  const tickHelper = (tickValue) => {
1426
1511
  return tickValue === 0 ? INIT_TICK : tickValue;
1427
1512
  };
1428
- async function getRemainingAccountsOperate(vaultId, vaultState, vaultConfig, finalPositionTick, program) {
1513
+ async function getRemainingAccountsOperate(vaultId, vaultState, vaultConfig, finalPositionTick, existingPositionTick, liquidationStatus, program) {
1429
1514
  const remainingAccounts = [];
1430
1515
  const oracleProgram = new Program(oracle, program.provider);
1431
1516
  const [oracleData, branches, tickHasDebt] = await Promise.all([
1432
1517
  oracleProgram.account.oracle.fetch(new PublicKey(vaultConfig.oracle)),
1433
1518
  // Add branch accounts (next 10 remaining accounts)
1434
- loadRelevantBranches(vaultId, vaultState, program),
1519
+ loadRelevantBranches(vaultId, vaultState, liquidationStatus, program),
1435
1520
  loadRelevantTicksHasDebtArrays(
1436
1521
  vaultId,
1437
- Math.max(finalPositionTick, tickHelper(vaultState.topmostTick)),
1438
- // max of both ticks
1439
- program
1522
+ tickHelper(vaultState.topmostTick),
1523
+ existingPositionTick,
1524
+ finalPositionTick
1440
1525
  )
1441
1526
  ]);
1442
1527
  const sourceLength = oracleData.sources.length;
@@ -1457,7 +1542,7 @@ async function getRemainingAccountsOperate(vaultId, vaultState, vaultConfig, fin
1457
1542
  const tickHasDebtLength = tickHasDebt.length;
1458
1543
  for (const tickHasDebtArray of tickHasDebt)
1459
1544
  remainingAccounts.push({
1460
- pubkey: getTickHasDebt(vaultId, tickHasDebtArray.index),
1545
+ pubkey: tickHasDebtArray,
1461
1546
  isWritable: true,
1462
1547
  isSigner: false
1463
1548
  });
@@ -1549,6 +1634,8 @@ async function getOperateContext({
1549
1634
  vaultState,
1550
1635
  vaultConfig,
1551
1636
  finalPosition.tick,
1637
+ existingPositionTick,
1638
+ currentPosition.userLiquidationStatus,
1552
1639
  program
1553
1640
  );
1554
1641
  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.92";
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.92",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "type": "module",