@jup-ag/lend 0.0.89 → 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.
- package/dist/borrow/index.d.mts +4 -8
- package/dist/borrow/index.d.ts +4 -8
- package/dist/borrow/index.mjs +69 -47
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/borrow/index.d.mts
CHANGED
|
@@ -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,
|
|
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;
|
package/dist/borrow/index.d.ts
CHANGED
|
@@ -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,
|
|
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;
|
package/dist/borrow/index.mjs
CHANGED
|
@@ -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,18 +885,23 @@ 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) {
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
894
|
+
userLiquidationStatus = true;
|
|
895
|
+
let [tickIdData, branches] = await Promise.all([
|
|
896
|
+
program.account.tickIdLiquidation.fetch(
|
|
897
|
+
getTickIdLiquidation(
|
|
898
|
+
vaultId,
|
|
899
|
+
positionTick,
|
|
900
|
+
position.tickId
|
|
901
|
+
)
|
|
902
|
+
).catch(() => null),
|
|
903
|
+
getAllBranches({ vaultId, program })
|
|
904
|
+
]);
|
|
899
905
|
if (!tickIdData) {
|
|
900
906
|
tickIdData = {
|
|
901
907
|
vaultId,
|
|
@@ -912,7 +918,6 @@ const getCurrentPositionState = async ({
|
|
|
912
918
|
debtFactor3: new BN(0)
|
|
913
919
|
};
|
|
914
920
|
}
|
|
915
|
-
const branches = await getAllBranches({ vaultId, program });
|
|
916
921
|
const { isFullyLiquidated, branchId, connectionFactor } = getLiquidationStatus(position.tickId, tickData, tickIdData);
|
|
917
922
|
if (isFullyLiquidated) {
|
|
918
923
|
return {
|
|
@@ -922,7 +927,8 @@ const getCurrentPositionState = async ({
|
|
|
922
927
|
debtRaw: new BN(0),
|
|
923
928
|
dustDebtRaw: new BN(0),
|
|
924
929
|
finalAmount: new BN(0),
|
|
925
|
-
isSupplyOnlyPosition: true
|
|
930
|
+
isSupplyOnlyPosition: true,
|
|
931
|
+
userLiquidationStatus: true
|
|
926
932
|
};
|
|
927
933
|
}
|
|
928
934
|
const { finalTick, finalColRaw, finalDebtRaw } = await processLiquidatedPosition({
|
|
@@ -939,7 +945,8 @@ const getCurrentPositionState = async ({
|
|
|
939
945
|
debtRaw: finalDebtRaw,
|
|
940
946
|
dustDebtRaw,
|
|
941
947
|
finalAmount: netDebtRaw2.gt(new BN(0)) ? finalColRaw : new BN(0),
|
|
942
|
-
isSupplyOnlyPosition: finalTick === MIN_TICK
|
|
948
|
+
isSupplyOnlyPosition: finalTick === MIN_TICK,
|
|
949
|
+
userLiquidationStatus
|
|
943
950
|
};
|
|
944
951
|
}
|
|
945
952
|
}
|
|
@@ -951,7 +958,8 @@ const getCurrentPositionState = async ({
|
|
|
951
958
|
debtRaw,
|
|
952
959
|
dustDebtRaw,
|
|
953
960
|
finalAmount: netDebtRaw.gt(new BN(0)) ? colRaw : new BN(0),
|
|
954
|
-
isSupplyOnlyPosition: positionTick === MIN_TICK
|
|
961
|
+
isSupplyOnlyPosition: positionTick === MIN_TICK,
|
|
962
|
+
userLiquidationStatus
|
|
955
963
|
};
|
|
956
964
|
};
|
|
957
965
|
async function getAllBranches({
|
|
@@ -1148,7 +1156,7 @@ const getFinalPosition = async ({
|
|
|
1148
1156
|
isSupplyOnlyPosition
|
|
1149
1157
|
};
|
|
1150
1158
|
};
|
|
1151
|
-
async function loadRelevantBranches(vaultId, vaultState, program) {
|
|
1159
|
+
async function loadRelevantBranches(vaultId, vaultState, liquidationStatus, program) {
|
|
1152
1160
|
const addedBranchIds = /* @__PURE__ */ new Set();
|
|
1153
1161
|
const currentBranchId = vaultState.currentBranchId;
|
|
1154
1162
|
let connectedBranchId = 0;
|
|
@@ -1165,38 +1173,50 @@ async function loadRelevantBranches(vaultId, vaultState, program) {
|
|
|
1165
1173
|
console.warn(`Failed to fetch current branch ${currentBranchId}:`, error);
|
|
1166
1174
|
}
|
|
1167
1175
|
}
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
if (
|
|
1175
|
-
addedBranchIds.
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
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
|
+
}
|
|
1184
1194
|
}
|
|
1195
|
+
if (!addedBranchIds.has(0)) addedBranchIds.add(0);
|
|
1185
1196
|
}
|
|
1186
|
-
if (!addedBranchIds.has(0)) addedBranchIds.add(0);
|
|
1187
1197
|
return [...addedBranchIds];
|
|
1188
1198
|
}
|
|
1189
|
-
async function loadRelevantTicksHasDebtArrays(vaultId, topTick,
|
|
1190
|
-
|
|
1191
|
-
if (
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
)
|
|
1199
|
-
|
|
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];
|
|
1200
1220
|
}
|
|
1201
1221
|
async function getExchangePrices({
|
|
1202
1222
|
vaultId,
|
|
@@ -1423,18 +1443,18 @@ async function getOtherInstructionsOperate(vaultId, vaultState, currentPosition,
|
|
|
1423
1443
|
const tickHelper = (tickValue) => {
|
|
1424
1444
|
return tickValue === 0 ? INIT_TICK : tickValue;
|
|
1425
1445
|
};
|
|
1426
|
-
async function getRemainingAccountsOperate(vaultId, vaultState, vaultConfig, finalPositionTick, program) {
|
|
1446
|
+
async function getRemainingAccountsOperate(vaultId, vaultState, vaultConfig, finalPositionTick, existingPositionTick, liquidationStatus, program) {
|
|
1427
1447
|
const remainingAccounts = [];
|
|
1428
1448
|
const oracleProgram = new Program(oracle, program.provider);
|
|
1429
1449
|
const [oracleData, branches, tickHasDebt] = await Promise.all([
|
|
1430
1450
|
oracleProgram.account.oracle.fetch(new PublicKey(vaultConfig.oracle)),
|
|
1431
1451
|
// Add branch accounts (next 10 remaining accounts)
|
|
1432
|
-
loadRelevantBranches(vaultId, vaultState, program),
|
|
1452
|
+
loadRelevantBranches(vaultId, vaultState, liquidationStatus, program),
|
|
1433
1453
|
loadRelevantTicksHasDebtArrays(
|
|
1434
1454
|
vaultId,
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1455
|
+
tickHelper(vaultState.topmostTick),
|
|
1456
|
+
existingPositionTick,
|
|
1457
|
+
finalPositionTick
|
|
1438
1458
|
)
|
|
1439
1459
|
]);
|
|
1440
1460
|
const sourceLength = oracleData.sources.length;
|
|
@@ -1455,7 +1475,7 @@ async function getRemainingAccountsOperate(vaultId, vaultState, vaultConfig, fin
|
|
|
1455
1475
|
const tickHasDebtLength = tickHasDebt.length;
|
|
1456
1476
|
for (const tickHasDebtArray of tickHasDebt)
|
|
1457
1477
|
remainingAccounts.push({
|
|
1458
|
-
pubkey:
|
|
1478
|
+
pubkey: tickHasDebtArray,
|
|
1459
1479
|
isWritable: true,
|
|
1460
1480
|
isSigner: false
|
|
1461
1481
|
});
|
|
@@ -1547,6 +1567,8 @@ async function getOperateContext({
|
|
|
1547
1567
|
vaultState,
|
|
1548
1568
|
vaultConfig,
|
|
1549
1569
|
finalPosition.tick,
|
|
1570
|
+
existingPositionTick,
|
|
1571
|
+
currentPosition.userLiquidationStatus,
|
|
1550
1572
|
program
|
|
1551
1573
|
);
|
|
1552
1574
|
const accounts = {
|
package/dist/index.mjs
CHANGED