@jup-ag/lend 0.0.13 → 0.0.15
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/README.md +1 -1
- package/dist/borrow/index.d.mts +1 -1
- package/dist/borrow/index.d.ts +1 -1
- package/dist/borrow/index.mjs +36 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ import { getOperateIx } from "@jup-ag/lend/borrow";
|
|
|
42
42
|
const connection = new Connection("https://api.devnet.solana.com");
|
|
43
43
|
const signer = new PublicKey("signerAddress");
|
|
44
44
|
|
|
45
|
-
const { ixs,
|
|
45
|
+
const { ixs, addressLookupTableAccounts } = await getOperateIx({
|
|
46
46
|
vaultId: 1,
|
|
47
47
|
positionId: 0,
|
|
48
48
|
|
package/dist/borrow/index.d.mts
CHANGED
|
@@ -3634,7 +3634,7 @@ declare function getInitPositionContext(vaultId: number, positionId: number, sig
|
|
|
3634
3634
|
};
|
|
3635
3635
|
declare const getOperateIx: ({ vaultId, positionId, colAmount, debtAmount, connection, signer, recipient, positionOwner, }: OperateParams) => Promise<{
|
|
3636
3636
|
nftId: number;
|
|
3637
|
-
addressLookupTableAccounts:
|
|
3637
|
+
addressLookupTableAccounts: _solana_web3_js.AddressLookupTableAccount[];
|
|
3638
3638
|
ixs: TransactionInstruction[];
|
|
3639
3639
|
}>;
|
|
3640
3640
|
|
package/dist/borrow/index.d.ts
CHANGED
|
@@ -3634,7 +3634,7 @@ declare function getInitPositionContext(vaultId: number, positionId: number, sig
|
|
|
3634
3634
|
};
|
|
3635
3635
|
declare const getOperateIx: ({ vaultId, positionId, colAmount, debtAmount, connection, signer, recipient, positionOwner, }: OperateParams) => Promise<{
|
|
3636
3636
|
nftId: number;
|
|
3637
|
-
addressLookupTableAccounts:
|
|
3637
|
+
addressLookupTableAccounts: _solana_web3_js.AddressLookupTableAccount[];
|
|
3638
3638
|
ixs: TransactionInstruction[];
|
|
3639
3639
|
}>;
|
|
3640
3640
|
|
package/dist/borrow/index.mjs
CHANGED
|
@@ -475,12 +475,12 @@ const oracle = {
|
|
|
475
475
|
types: types
|
|
476
476
|
};
|
|
477
477
|
|
|
478
|
-
const MIN_TICK$
|
|
478
|
+
const MIN_TICK$1 = -16383;
|
|
479
479
|
const MAX_TICK$1 = 16383;
|
|
480
480
|
const ZERO_TICK_SCALED_RATIO$1 = new BN(281474976710656);
|
|
481
481
|
function getRatioAtTick(tick) {
|
|
482
|
-
if (tick < MIN_TICK$
|
|
483
|
-
throw new Error(`Tick ${tick} out of range [${MIN_TICK$
|
|
482
|
+
if (tick < MIN_TICK$1 || tick > MAX_TICK$1) {
|
|
483
|
+
throw new Error(`Tick ${tick} out of range [${MIN_TICK$1}, ${MAX_TICK$1}]`);
|
|
484
484
|
}
|
|
485
485
|
const FACTOR00 = new BN("18446744073709551616");
|
|
486
486
|
const FACTOR01 = new BN("18419115400608638658");
|
|
@@ -669,7 +669,7 @@ function mulBigNumber(bigNumber1, bigNumber2) {
|
|
|
669
669
|
}
|
|
670
670
|
|
|
671
671
|
const INIT_TICK = -2147483648;
|
|
672
|
-
const MIN_TICK
|
|
672
|
+
const MIN_TICK = -16383;
|
|
673
673
|
const MAX_TICK = 16383;
|
|
674
674
|
const MAX_MASK_DEBT_FACTOR = new BN("1125899906842623");
|
|
675
675
|
const EXCHANGE_PRICES_PRECISION = new BN(10).pow(new BN(12));
|
|
@@ -684,11 +684,11 @@ const getCurrentPositionState = async ({
|
|
|
684
684
|
}) => {
|
|
685
685
|
let positionTick = position.tick;
|
|
686
686
|
if (positionTick === INIT_TICK) {
|
|
687
|
-
positionTick = MIN_TICK
|
|
687
|
+
positionTick = MIN_TICK;
|
|
688
688
|
}
|
|
689
689
|
if (position.isSupplyOnlyPosition) {
|
|
690
690
|
return {
|
|
691
|
-
tick: MIN_TICK
|
|
691
|
+
tick: MIN_TICK,
|
|
692
692
|
tickId: 0,
|
|
693
693
|
colRaw: new BN(position.supplyAmount.toString()),
|
|
694
694
|
finalAmount: new BN(position.supplyAmount.toString()),
|
|
@@ -700,14 +700,14 @@ const getCurrentPositionState = async ({
|
|
|
700
700
|
let colRaw = new BN(position.supplyAmount.toString());
|
|
701
701
|
let dustDebtRaw = new BN(position.dustDebtAmount.toString());
|
|
702
702
|
let debtRaw = new BN(0);
|
|
703
|
-
if (positionTick > MIN_TICK
|
|
703
|
+
if (positionTick > MIN_TICK) {
|
|
704
704
|
const collateralForDebtCalc = colRaw.add(new BN(1));
|
|
705
705
|
const ratio = getRatioAtTick(positionTick);
|
|
706
706
|
debtRaw = ratio.mul(collateralForDebtCalc).shrn(48).add(new BN(1));
|
|
707
707
|
} else {
|
|
708
708
|
debtRaw = new BN(0);
|
|
709
709
|
}
|
|
710
|
-
if (positionTick > MIN_TICK
|
|
710
|
+
if (positionTick > MIN_TICK) {
|
|
711
711
|
const tickData = await program.account.tick.fetch(
|
|
712
712
|
getTick(vaultId, positionTick)
|
|
713
713
|
);
|
|
@@ -719,7 +719,7 @@ const getCurrentPositionState = async ({
|
|
|
719
719
|
const { isFullyLiquidated, branchId, connectionFactor } = getLiquidationStatus(position.tickId, tickData, tickIdData);
|
|
720
720
|
if (isFullyLiquidated) {
|
|
721
721
|
return {
|
|
722
|
-
tick: MIN_TICK
|
|
722
|
+
tick: MIN_TICK,
|
|
723
723
|
tickId: 0,
|
|
724
724
|
colRaw: new BN(0),
|
|
725
725
|
debtRaw: new BN(0),
|
|
@@ -742,7 +742,7 @@ const getCurrentPositionState = async ({
|
|
|
742
742
|
debtRaw: finalDebtRaw,
|
|
743
743
|
dustDebtRaw,
|
|
744
744
|
finalAmount: netDebtRaw2.gt(new BN(0)) ? finalColRaw : new BN(0),
|
|
745
|
-
isSupplyOnlyPosition: finalTick === MIN_TICK
|
|
745
|
+
isSupplyOnlyPosition: finalTick === MIN_TICK
|
|
746
746
|
};
|
|
747
747
|
}
|
|
748
748
|
}
|
|
@@ -754,7 +754,7 @@ const getCurrentPositionState = async ({
|
|
|
754
754
|
debtRaw,
|
|
755
755
|
dustDebtRaw,
|
|
756
756
|
finalAmount: netDebtRaw.gt(new BN(0)) ? colRaw : new BN(0),
|
|
757
|
-
isSupplyOnlyPosition: positionTick === MIN_TICK
|
|
757
|
+
isSupplyOnlyPosition: positionTick === MIN_TICK
|
|
758
758
|
};
|
|
759
759
|
};
|
|
760
760
|
async function getAllBranches({
|
|
@@ -841,7 +841,7 @@ async function processLiquidatedPosition({
|
|
|
841
841
|
let positionDebtRaw = new BN(0);
|
|
842
842
|
if (currentBranch.status === 3 || currentConnectionFactor.eq(MAX_MASK_DEBT_FACTOR)) {
|
|
843
843
|
positionDebtRaw = new BN(0);
|
|
844
|
-
finalTick = MIN_TICK
|
|
844
|
+
finalTick = MIN_TICK;
|
|
845
845
|
} else {
|
|
846
846
|
positionDebtRaw = mulDivNormal(
|
|
847
847
|
initialDebtRaw,
|
|
@@ -862,7 +862,7 @@ async function processLiquidatedPosition({
|
|
|
862
862
|
ratioLength.mul(new BN(currentBranch.minimaTickPartials)).div(X30)
|
|
863
863
|
);
|
|
864
864
|
finalColRaw = positionDebtRaw.mul(ZERO_TICK_SCALED_RATIO).div(finalRatio);
|
|
865
|
-
} else finalTick = MIN_TICK
|
|
865
|
+
} else finalTick = MIN_TICK;
|
|
866
866
|
}
|
|
867
867
|
return {
|
|
868
868
|
finalTick,
|
|
@@ -920,7 +920,7 @@ const calculateFinalPosition = async ({
|
|
|
920
920
|
let finalTick;
|
|
921
921
|
let isSupplyOnlyPosition;
|
|
922
922
|
if (netDebtRaw.eq(new BN(0)) || colRaw.eq(new BN(0))) {
|
|
923
|
-
finalTick = MIN_TICK
|
|
923
|
+
finalTick = MIN_TICK;
|
|
924
924
|
isSupplyOnlyPosition = true;
|
|
925
925
|
} else {
|
|
926
926
|
const marginAdjustedDebt = netDebtRaw.mul(new BN(1000000001)).div(new BN(1e9)).add(new BN(1));
|
|
@@ -930,8 +930,8 @@ const calculateFinalPosition = async ({
|
|
|
930
930
|
finalTick = baseTickAtRatio + 1;
|
|
931
931
|
const ratioNew = ratioAtTick.mul(TICK_SPACING).div(new BN(1e4));
|
|
932
932
|
ratioNew.mul(colRaw).shrn(48);
|
|
933
|
-
if (finalTick < MIN_TICK
|
|
934
|
-
finalTick = MIN_TICK
|
|
933
|
+
if (finalTick < MIN_TICK) {
|
|
934
|
+
finalTick = MIN_TICK;
|
|
935
935
|
} else if (finalTick > MAX_TICK) {
|
|
936
936
|
finalTick = MAX_TICK;
|
|
937
937
|
}
|
|
@@ -1007,7 +1007,7 @@ async function loadRelevantBranches(vaultId, vaultState, program) {
|
|
|
1007
1007
|
branches.push({
|
|
1008
1008
|
branchId: 1,
|
|
1009
1009
|
status: 0,
|
|
1010
|
-
minimaTick: MIN_TICK
|
|
1010
|
+
minimaTick: MIN_TICK,
|
|
1011
1011
|
minimaTickPartials: 0,
|
|
1012
1012
|
debtLiquidity: 0,
|
|
1013
1013
|
debtFactor: 0,
|
|
@@ -1030,15 +1030,13 @@ async function loadRelevantTicksHasDebtArrays(vaultId, program) {
|
|
|
1030
1030
|
}
|
|
1031
1031
|
|
|
1032
1032
|
const MIN_I128 = new BN("170141183460469231731687303715884105728").neg();
|
|
1033
|
-
const MIN_TICK = -16383;
|
|
1034
1033
|
async function getOtherInstructionsOperate(vaultId, vaultState, currentPosition, finalPosition, currentTick, program, signer) {
|
|
1035
1034
|
const otherIxs = [];
|
|
1036
1035
|
const tickToRead = [currentTick];
|
|
1037
1036
|
let currentTickData;
|
|
1038
1037
|
let finalTickData;
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
tickToRead.push(finalPosition.tick);
|
|
1038
|
+
tickToRead.push(currentPosition.tick);
|
|
1039
|
+
tickToRead.push(finalPosition.tick);
|
|
1042
1040
|
if (tickToRead.length > 0) {
|
|
1043
1041
|
const tickData = await program.account.tick.fetchMultiple(
|
|
1044
1042
|
tickToRead.map((tick) => getTick(vaultId, tick))
|
|
@@ -1082,11 +1080,22 @@ async function getOtherInstructionsOperate(vaultId, vaultState, currentPosition,
|
|
|
1082
1080
|
finalPosition.tick,
|
|
1083
1081
|
finalTickData ? finalTickData.totalIds : 0
|
|
1084
1082
|
);
|
|
1085
|
-
if (finalPosition.tick !== currentTick
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1083
|
+
if (finalPosition.tick !== currentTick)
|
|
1084
|
+
if (finalTickData) {
|
|
1085
|
+
tickIdsToRead.push({
|
|
1086
|
+
tick: finalPosition.tick,
|
|
1087
|
+
totalIds: finalTickData.totalIds
|
|
1088
|
+
});
|
|
1089
|
+
} else {
|
|
1090
|
+
const context = await getInitTickIdLiquidationContext(
|
|
1091
|
+
vaultId,
|
|
1092
|
+
finalPosition.tick,
|
|
1093
|
+
signer,
|
|
1094
|
+
program
|
|
1095
|
+
);
|
|
1096
|
+
const ix = await program.methods.initTickIdLiquidation(vaultId, finalPosition.tick, 0).accounts(context).instruction();
|
|
1097
|
+
otherIxs.push(ix);
|
|
1098
|
+
}
|
|
1090
1099
|
const tickIdData = await program.account.tickIdLiquidation.fetchMultiple(
|
|
1091
1100
|
tickIdsToRead.map(
|
|
1092
1101
|
({ tick, totalIds }) => getTickIdLiquidation(vaultId, tick, totalIds)
|
|
@@ -1378,7 +1387,7 @@ const getOperateIx = async ({
|
|
|
1378
1387
|
]);
|
|
1379
1388
|
return {
|
|
1380
1389
|
nftId,
|
|
1381
|
-
addressLookupTableAccounts: [addressLookupTable.value],
|
|
1390
|
+
addressLookupTableAccounts: addressLookupTable.value ? [addressLookupTable.value] : [],
|
|
1382
1391
|
ixs: initPositionIx ? [initPositionIx, ...otherIxs, operateIx] : [...otherIxs, operateIx]
|
|
1383
1392
|
};
|
|
1384
1393
|
};
|