@jup-ag/lend 0.0.26 → 0.0.28

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.
@@ -3709,13 +3709,14 @@ declare const getCurrentPositionState: ({ vaultId, position, program, }: GetCurr
3709
3709
  dustDebtRaw: BN;
3710
3710
  isSupplyOnlyPosition: boolean;
3711
3711
  }>;
3712
- declare const calculateFinalPosition: ({ vaultId, currentPosition, newColAmount, newDebtAmount, program, connection, }: {
3712
+ declare const calculateFinalPosition: ({ vaultId, currentPosition, newColAmount, newDebtAmount, program, connection, signer, }: {
3713
3713
  vaultId: number;
3714
3714
  currentPosition: Awaited<ReturnType<typeof getCurrentPositionState>>;
3715
3715
  newColAmount: BN;
3716
3716
  newDebtAmount: BN;
3717
3717
  program: Program<Vaults>;
3718
3718
  connection: Connection;
3719
+ signer: PublicKey;
3719
3720
  }) => Promise<{
3720
3721
  tick: number;
3721
3722
  tickId: number;
@@ -3725,26 +3726,7 @@ declare const calculateFinalPosition: ({ vaultId, currentPosition, newColAmount,
3725
3726
  finalAmount: BN;
3726
3727
  isSupplyOnlyPosition: boolean;
3727
3728
  }>;
3728
- declare function loadRelevantBranches(vaultId: number, vaultState: VaultState, program: Program<Vaults>): Promise<({
3729
- vaultId: number;
3730
- branchId: number;
3731
- status: number;
3732
- minimaTick: number;
3733
- minimaTickPartials: number;
3734
- debtLiquidity: BN;
3735
- debtFactor: BN;
3736
- connectedBranchId: number;
3737
- connectedMinimaTick: number;
3738
- } | {
3739
- branchId: number;
3740
- status: number;
3741
- minimaTick: number;
3742
- minimaTickPartials: number;
3743
- debtLiquidity: number;
3744
- debtFactor: number;
3745
- connectedBranchId: number;
3746
- connectedMinimaTick: number;
3747
- } | undefined)[]>;
3729
+ declare function loadRelevantBranches(vaultId: number, vaultState: VaultState, program: Program<Vaults>): Promise<number[]>;
3748
3730
  declare function loadRelevantTicksHasDebtArrays(vaultId: number, program: Program<Vaults>): Promise<{
3749
3731
  vaultId: number;
3750
3732
  index: number;
@@ -3709,13 +3709,14 @@ declare const getCurrentPositionState: ({ vaultId, position, program, }: GetCurr
3709
3709
  dustDebtRaw: BN;
3710
3710
  isSupplyOnlyPosition: boolean;
3711
3711
  }>;
3712
- declare const calculateFinalPosition: ({ vaultId, currentPosition, newColAmount, newDebtAmount, program, connection, }: {
3712
+ declare const calculateFinalPosition: ({ vaultId, currentPosition, newColAmount, newDebtAmount, program, connection, signer, }: {
3713
3713
  vaultId: number;
3714
3714
  currentPosition: Awaited<ReturnType<typeof getCurrentPositionState>>;
3715
3715
  newColAmount: BN;
3716
3716
  newDebtAmount: BN;
3717
3717
  program: Program<Vaults>;
3718
3718
  connection: Connection;
3719
+ signer: PublicKey;
3719
3720
  }) => Promise<{
3720
3721
  tick: number;
3721
3722
  tickId: number;
@@ -3725,26 +3726,7 @@ declare const calculateFinalPosition: ({ vaultId, currentPosition, newColAmount,
3725
3726
  finalAmount: BN;
3726
3727
  isSupplyOnlyPosition: boolean;
3727
3728
  }>;
3728
- declare function loadRelevantBranches(vaultId: number, vaultState: VaultState, program: Program<Vaults>): Promise<({
3729
- vaultId: number;
3730
- branchId: number;
3731
- status: number;
3732
- minimaTick: number;
3733
- minimaTickPartials: number;
3734
- debtLiquidity: BN;
3735
- debtFactor: BN;
3736
- connectedBranchId: number;
3737
- connectedMinimaTick: number;
3738
- } | {
3739
- branchId: number;
3740
- status: number;
3741
- minimaTick: number;
3742
- minimaTickPartials: number;
3743
- debtLiquidity: number;
3744
- debtFactor: number;
3745
- connectedBranchId: number;
3746
- connectedMinimaTick: number;
3747
- } | undefined)[]>;
3729
+ declare function loadRelevantBranches(vaultId: number, vaultState: VaultState, program: Program<Vaults>): Promise<number[]>;
3748
3730
  declare function loadRelevantTicksHasDebtArrays(vaultId: number, program: Program<Vaults>): Promise<{
3749
3731
  vaultId: number;
3750
3732
  index: number;
@@ -876,7 +876,8 @@ const calculateFinalPosition = async ({
876
876
  newColAmount,
877
877
  newDebtAmount,
878
878
  program,
879
- connection
879
+ connection,
880
+ signer
880
881
  }) => {
881
882
  const [vaultConfig] = await Promise.all([
882
883
  program.account.vaultConfig.fetch(getVaultConfig(vaultId))
@@ -884,7 +885,7 @@ const calculateFinalPosition = async ({
884
885
  const {
885
886
  vaultSupplyExchangePrice: supplyExPrice,
886
887
  vaultBorrowExchangePrice: borrowExPrice
887
- } = await getExchangePrices({ vaultId, vaultConfig, connection });
888
+ } = await getExchangePrices({ vaultId, vaultConfig, connection, signer });
888
889
  const borrowFee = vaultConfig.borrowFee;
889
890
  let { colRaw, debtRaw, dustDebtRaw } = currentPosition;
890
891
  if (newColAmount.gt(new BN(0))) {
@@ -950,75 +951,42 @@ const calculateFinalPosition = async ({
950
951
  };
951
952
  };
952
953
  async function loadRelevantBranches(vaultId, vaultState, program) {
953
- const branches = [];
954
+ const addedBranchIds = /* @__PURE__ */ new Set();
954
955
  const currentBranchId = vaultState.currentBranchId;
956
+ let connectedBranchId = 0;
955
957
  if (currentBranchId > 0) {
956
958
  try {
957
959
  const currentBranch = await program.account.branch.fetch(
958
960
  getBranch(vaultId, currentBranchId)
959
961
  );
960
962
  if (currentBranch) {
961
- branches.push(currentBranch);
963
+ addedBranchIds.add(currentBranch.branchId);
964
+ connectedBranchId = currentBranch.connectedBranchId;
962
965
  }
963
966
  } catch (error) {
964
967
  console.warn(`Failed to fetch current branch ${currentBranchId}:`, error);
965
968
  }
966
969
  }
967
- if (branches.length > 0) {
968
- let connectedBranchId = branches[0].connectedBranchId;
969
- while (connectedBranchId > 0 && branches.length < 10) {
970
- try {
971
- const connectedBranch = await program.account.branch.fetch(
972
- getBranch(vaultId, connectedBranchId)
973
- );
974
- if (connectedBranch) {
975
- branches.push(connectedBranch);
976
- connectedBranchId = connectedBranch.connectedBranchId;
977
- } else {
978
- break;
979
- }
980
- } catch (error) {
981
- console.warn(
982
- `Failed to fetch connected branch ${connectedBranchId}:`,
983
- error
984
- );
985
- break;
986
- }
987
- }
988
- }
989
- if (branches.length < 10) {
990
- for (let i = 1; i <= vaultState.totalBranchId && branches.length < 10; i++) {
991
- if (branches.some((b) => b.branchId === i)) {
992
- continue;
993
- }
994
- try {
995
- const branch = await program.account.branch.fetch(
996
- getBranch(vaultId, i)
997
- );
998
- if (branch) {
999
- branches.push(branch);
1000
- }
1001
- } catch (error) {
1002
- }
1003
- }
1004
- }
1005
- while (branches.length < 10) {
1006
- if (branches.length > 0) {
1007
- branches.push(branches[0]);
1008
- } else {
1009
- branches.push({
1010
- branchId: 1,
1011
- status: 0,
1012
- minimaTick: MIN_TICK,
1013
- minimaTickPartials: 0,
1014
- debtLiquidity: 0,
1015
- debtFactor: 0,
1016
- connectedBranchId: 0,
1017
- connectedMinimaTick: 0
1018
- });
970
+ while (connectedBranchId > 0) {
971
+ try {
972
+ const connectedBranch = await program.account.branch.fetch(
973
+ getBranch(vaultId, connectedBranchId)
974
+ );
975
+ if (connectedBranch) {
976
+ if (!addedBranchIds.has(connectedBranch.branchId))
977
+ addedBranchIds.add(connectedBranch.branchId);
978
+ connectedBranchId = connectedBranch.connectedBranchId;
979
+ } else break;
980
+ } catch (error) {
981
+ console.warn(
982
+ `Failed to fetch connected branch ${connectedBranchId}:`,
983
+ error
984
+ );
985
+ break;
1019
986
  }
1020
987
  }
1021
- return branches.slice(0, 10);
988
+ if (!addedBranchIds.has(0)) addedBranchIds.add(0);
989
+ return Array.from(addedBranchIds);
1022
990
  }
1023
991
  async function loadRelevantTicksHasDebtArrays(vaultId, program) {
1024
992
  return await Promise.all(
@@ -1033,7 +1001,8 @@ async function loadRelevantTicksHasDebtArrays(vaultId, program) {
1033
1001
  async function getExchangePrices({
1034
1002
  vaultId,
1035
1003
  vaultConfig,
1036
- connection
1004
+ connection,
1005
+ signer
1037
1006
  }) {
1038
1007
  const program = new Program(vaults, { connection });
1039
1008
  const ix = await program.methods.getExchangePrices().accounts({
@@ -1045,9 +1014,7 @@ async function getExchangePrices({
1045
1014
  const transaction = new Transaction().add(ix);
1046
1015
  const latestBlockHash = await connection.getLatestBlockhash();
1047
1016
  transaction.recentBlockhash = latestBlockHash.blockhash;
1048
- transaction.feePayer = new PublicKey(
1049
- "7ty28gFJMqjxz3YxAY3uBZs7vYXU7rcM8j7F96Akx9tQ"
1050
- );
1017
+ transaction.feePayer = signer;
1051
1018
  const raw = await connection.simulateTransaction(transaction);
1052
1019
  const returnLog = raw.value.logs?.find(
1053
1020
  (log) => log.startsWith("Program return:")
@@ -1185,7 +1152,7 @@ async function getRemainingAccountsOperate(vaultId, vaultState, vaultConfig, pro
1185
1152
  for (const branch of branches) {
1186
1153
  if (!branch) continue;
1187
1154
  remainingAccounts.push({
1188
- pubkey: getBranch(vaultId, branch.branchId),
1155
+ pubkey: getBranch(vaultId, branch),
1189
1156
  isWritable: true,
1190
1157
  isSigner: false
1191
1158
  });
@@ -1270,7 +1237,8 @@ async function getOperateContext({
1270
1237
  newColAmount: newCol,
1271
1238
  newDebtAmount: newDebt,
1272
1239
  program,
1273
- connection
1240
+ connection,
1241
+ signer
1274
1242
  });
1275
1243
  const { otherIxs, newBranchPda, currentTickIdDataPda, finalTickIdDataPda } = await getOtherInstructionsOperate(
1276
1244
  vaultId,
package/dist/index.mjs CHANGED
@@ -5,6 +5,6 @@ import '@solana/web3.js';
5
5
  import '@solana/spl-token';
6
6
  import 'bn.js';
7
7
 
8
- const version = "0.0.26";
8
+ const version = "0.0.28";
9
9
 
10
10
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jup-ag/lend",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "type": "module",