@jup-ag/lend 0.1.10-beta.2 → 0.1.10-beta.3
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
CHANGED
|
@@ -17,10 +17,11 @@ type GetCurrentPositionStateParams = {
|
|
|
17
17
|
vaultId: number;
|
|
18
18
|
position: PositionData;
|
|
19
19
|
program: Program<Vaults>;
|
|
20
|
+
market: "main" | "ethena";
|
|
20
21
|
};
|
|
21
22
|
declare const getVaultsProgram: ({ connection, signer, market, }: {
|
|
22
23
|
connection: Connection;
|
|
23
|
-
signer
|
|
24
|
+
signer?: PublicKey;
|
|
24
25
|
market: "main" | "ethena";
|
|
25
26
|
}) => Program<Vaults>;
|
|
26
27
|
declare const INIT_TICK = -2147483648;
|
|
@@ -41,7 +42,7 @@ declare const getCurrentPosition: ({ vaultId, positionId, connection, market, }:
|
|
|
41
42
|
userLiquidationStatus: boolean;
|
|
42
43
|
postLiquidationBranchId: number;
|
|
43
44
|
}>;
|
|
44
|
-
declare const getCurrentPositionState: ({ vaultId, position, program, }: GetCurrentPositionStateParams) => Promise<{
|
|
45
|
+
declare const getCurrentPositionState: ({ vaultId, position, program, market, }: GetCurrentPositionStateParams) => Promise<{
|
|
45
46
|
tick: number;
|
|
46
47
|
tickId: number;
|
|
47
48
|
colRaw: BN__default;
|
|
@@ -52,7 +53,7 @@ declare const getCurrentPositionState: ({ vaultId, position, program, }: GetCurr
|
|
|
52
53
|
userLiquidationStatus: boolean;
|
|
53
54
|
postLiquidationBranchId: number;
|
|
54
55
|
}>;
|
|
55
|
-
declare const getFinalPosition: ({ vaultId, currentPosition, newColAmount, newDebtAmount, program, connection, signer, }: {
|
|
56
|
+
declare const getFinalPosition: ({ vaultId, currentPosition, newColAmount, newDebtAmount, program, connection, signer, market, }: {
|
|
56
57
|
vaultId: number;
|
|
57
58
|
currentPosition: Awaited<ReturnType<typeof getCurrentPositionState>>;
|
|
58
59
|
newColAmount: BN__default;
|
|
@@ -60,6 +61,7 @@ declare const getFinalPosition: ({ vaultId, currentPosition, newColAmount, newDe
|
|
|
60
61
|
program?: Program<Vaults>;
|
|
61
62
|
connection: Connection;
|
|
62
63
|
signer: PublicKey;
|
|
64
|
+
market: "main" | "ethena";
|
|
63
65
|
}) => Promise<{
|
|
64
66
|
tick: number;
|
|
65
67
|
tickId: number;
|
|
@@ -69,16 +71,16 @@ declare const getFinalPosition: ({ vaultId, currentPosition, newColAmount, newDe
|
|
|
69
71
|
finalAmount: BN__default;
|
|
70
72
|
isSupplyOnlyPosition: boolean;
|
|
71
73
|
}>;
|
|
72
|
-
declare function loadRelevantBranches(vaultId: number, vaultState: VaultState, liquidationStatus: boolean, postLiquidationBranchId: number, program: Program<Vaults
|
|
73
|
-
declare function loadRelevantTicksHasDebtArrays(vaultId: number, topTick: number, existingPositionTick: number, finalTick: number, program: Program<Vaults
|
|
74
|
-
declare function loadRelevantTicksHasDebtArraysLiquidate(vaultId: number, topTick: number, nextTick: number, program: Program<Vaults
|
|
74
|
+
declare function loadRelevantBranches(vaultId: number, vaultState: VaultState, liquidationStatus: boolean, postLiquidationBranchId: number, program: Program<Vaults>, market: "main" | "ethena"): Promise<number[]>;
|
|
75
|
+
declare function loadRelevantTicksHasDebtArrays(vaultId: number, topTick: number, existingPositionTick: number, finalTick: number, program: Program<Vaults>, market: "main" | "ethena"): Promise<PublicKey[]>;
|
|
76
|
+
declare function loadRelevantTicksHasDebtArraysLiquidate(vaultId: number, topTick: number, nextTick: number, program: Program<Vaults>, market: "main" | "ethena"): Promise<{
|
|
75
77
|
vaultId: number;
|
|
76
78
|
index: number;
|
|
77
79
|
tickHasDebt: {
|
|
78
80
|
childrenBits: number[];
|
|
79
81
|
}[];
|
|
80
82
|
}[]>;
|
|
81
|
-
declare function loadRelevantBranchesForLiquidate(vaultId: number, vaultState: any, program: Program<Vaults
|
|
83
|
+
declare function loadRelevantBranchesForLiquidate(vaultId: number, vaultState: any, program: Program<Vaults>, market: "main" | "ethena"): Promise<any[]>;
|
|
82
84
|
declare function readOraclePrice({ connection, signer, oracle, }: {
|
|
83
85
|
connection: Connection;
|
|
84
86
|
signer?: PublicKey;
|
|
@@ -193,10 +195,11 @@ declare function getTickIndices(tick: number): {
|
|
|
193
195
|
byteIndex: number;
|
|
194
196
|
bitIndex: number;
|
|
195
197
|
};
|
|
196
|
-
declare function readTickHasDebtArray({ vaultId, index, program, }: {
|
|
198
|
+
declare function readTickHasDebtArray({ vaultId, index, program, market, }: {
|
|
197
199
|
vaultId: number;
|
|
198
200
|
index: number;
|
|
199
201
|
program: Program<Vaults>;
|
|
202
|
+
market: "main" | "ethena";
|
|
200
203
|
}): Promise<{
|
|
201
204
|
vaultId: number;
|
|
202
205
|
index: number;
|
|
@@ -204,7 +207,7 @@ declare function readTickHasDebtArray({ vaultId, index, program, }: {
|
|
|
204
207
|
childrenBits: number[];
|
|
205
208
|
}[];
|
|
206
209
|
}>;
|
|
207
|
-
declare function findNextTickWithDebt(vaultId: number, startTick: number, program: Program<Vaults
|
|
210
|
+
declare function findNextTickWithDebt(vaultId: number, startTick: number, program: Program<Vaults>, market: "main" | "ethena"): Promise<number>;
|
|
208
211
|
|
|
209
212
|
declare const simulateLiquidate: (params: LiquidateParams) => Promise<_solana_web3_js.SimulatedTransactionResponse>;
|
|
210
213
|
declare const getLiquidations: (params: Omit<LiquidateParams, "debtAmount">) => Promise<{
|
package/dist/borrow/index.d.ts
CHANGED
|
@@ -17,10 +17,11 @@ type GetCurrentPositionStateParams = {
|
|
|
17
17
|
vaultId: number;
|
|
18
18
|
position: PositionData;
|
|
19
19
|
program: Program<Vaults>;
|
|
20
|
+
market: "main" | "ethena";
|
|
20
21
|
};
|
|
21
22
|
declare const getVaultsProgram: ({ connection, signer, market, }: {
|
|
22
23
|
connection: Connection;
|
|
23
|
-
signer
|
|
24
|
+
signer?: PublicKey;
|
|
24
25
|
market: "main" | "ethena";
|
|
25
26
|
}) => Program<Vaults>;
|
|
26
27
|
declare const INIT_TICK = -2147483648;
|
|
@@ -41,7 +42,7 @@ declare const getCurrentPosition: ({ vaultId, positionId, connection, market, }:
|
|
|
41
42
|
userLiquidationStatus: boolean;
|
|
42
43
|
postLiquidationBranchId: number;
|
|
43
44
|
}>;
|
|
44
|
-
declare const getCurrentPositionState: ({ vaultId, position, program, }: GetCurrentPositionStateParams) => Promise<{
|
|
45
|
+
declare const getCurrentPositionState: ({ vaultId, position, program, market, }: GetCurrentPositionStateParams) => Promise<{
|
|
45
46
|
tick: number;
|
|
46
47
|
tickId: number;
|
|
47
48
|
colRaw: BN__default;
|
|
@@ -52,7 +53,7 @@ declare const getCurrentPositionState: ({ vaultId, position, program, }: GetCurr
|
|
|
52
53
|
userLiquidationStatus: boolean;
|
|
53
54
|
postLiquidationBranchId: number;
|
|
54
55
|
}>;
|
|
55
|
-
declare const getFinalPosition: ({ vaultId, currentPosition, newColAmount, newDebtAmount, program, connection, signer, }: {
|
|
56
|
+
declare const getFinalPosition: ({ vaultId, currentPosition, newColAmount, newDebtAmount, program, connection, signer, market, }: {
|
|
56
57
|
vaultId: number;
|
|
57
58
|
currentPosition: Awaited<ReturnType<typeof getCurrentPositionState>>;
|
|
58
59
|
newColAmount: BN__default;
|
|
@@ -60,6 +61,7 @@ declare const getFinalPosition: ({ vaultId, currentPosition, newColAmount, newDe
|
|
|
60
61
|
program?: Program<Vaults>;
|
|
61
62
|
connection: Connection;
|
|
62
63
|
signer: PublicKey;
|
|
64
|
+
market: "main" | "ethena";
|
|
63
65
|
}) => Promise<{
|
|
64
66
|
tick: number;
|
|
65
67
|
tickId: number;
|
|
@@ -69,16 +71,16 @@ declare const getFinalPosition: ({ vaultId, currentPosition, newColAmount, newDe
|
|
|
69
71
|
finalAmount: BN__default;
|
|
70
72
|
isSupplyOnlyPosition: boolean;
|
|
71
73
|
}>;
|
|
72
|
-
declare function loadRelevantBranches(vaultId: number, vaultState: VaultState, liquidationStatus: boolean, postLiquidationBranchId: number, program: Program<Vaults
|
|
73
|
-
declare function loadRelevantTicksHasDebtArrays(vaultId: number, topTick: number, existingPositionTick: number, finalTick: number, program: Program<Vaults
|
|
74
|
-
declare function loadRelevantTicksHasDebtArraysLiquidate(vaultId: number, topTick: number, nextTick: number, program: Program<Vaults
|
|
74
|
+
declare function loadRelevantBranches(vaultId: number, vaultState: VaultState, liquidationStatus: boolean, postLiquidationBranchId: number, program: Program<Vaults>, market: "main" | "ethena"): Promise<number[]>;
|
|
75
|
+
declare function loadRelevantTicksHasDebtArrays(vaultId: number, topTick: number, existingPositionTick: number, finalTick: number, program: Program<Vaults>, market: "main" | "ethena"): Promise<PublicKey[]>;
|
|
76
|
+
declare function loadRelevantTicksHasDebtArraysLiquidate(vaultId: number, topTick: number, nextTick: number, program: Program<Vaults>, market: "main" | "ethena"): Promise<{
|
|
75
77
|
vaultId: number;
|
|
76
78
|
index: number;
|
|
77
79
|
tickHasDebt: {
|
|
78
80
|
childrenBits: number[];
|
|
79
81
|
}[];
|
|
80
82
|
}[]>;
|
|
81
|
-
declare function loadRelevantBranchesForLiquidate(vaultId: number, vaultState: any, program: Program<Vaults
|
|
83
|
+
declare function loadRelevantBranchesForLiquidate(vaultId: number, vaultState: any, program: Program<Vaults>, market: "main" | "ethena"): Promise<any[]>;
|
|
82
84
|
declare function readOraclePrice({ connection, signer, oracle, }: {
|
|
83
85
|
connection: Connection;
|
|
84
86
|
signer?: PublicKey;
|
|
@@ -193,10 +195,11 @@ declare function getTickIndices(tick: number): {
|
|
|
193
195
|
byteIndex: number;
|
|
194
196
|
bitIndex: number;
|
|
195
197
|
};
|
|
196
|
-
declare function readTickHasDebtArray({ vaultId, index, program, }: {
|
|
198
|
+
declare function readTickHasDebtArray({ vaultId, index, program, market, }: {
|
|
197
199
|
vaultId: number;
|
|
198
200
|
index: number;
|
|
199
201
|
program: Program<Vaults>;
|
|
202
|
+
market: "main" | "ethena";
|
|
200
203
|
}): Promise<{
|
|
201
204
|
vaultId: number;
|
|
202
205
|
index: number;
|
|
@@ -204,7 +207,7 @@ declare function readTickHasDebtArray({ vaultId, index, program, }: {
|
|
|
204
207
|
childrenBits: number[];
|
|
205
208
|
}[];
|
|
206
209
|
}>;
|
|
207
|
-
declare function findNextTickWithDebt(vaultId: number, startTick: number, program: Program<Vaults
|
|
210
|
+
declare function findNextTickWithDebt(vaultId: number, startTick: number, program: Program<Vaults>, market: "main" | "ethena"): Promise<number>;
|
|
208
211
|
|
|
209
212
|
declare const simulateLiquidate: (params: LiquidateParams) => Promise<_solana_web3_js.SimulatedTransactionResponse>;
|
|
210
213
|
declare const getLiquidations: (params: Omit<LiquidateParams, "debtAmount">) => Promise<{
|
package/dist/borrow/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getLiquidateIx, a as getVaultsProgram } from '../shared/lend.
|
|
2
|
-
export { I as INIT_TICK, h as MAX_REPAY_AMOUNT, u as MAX_TICK, i as MAX_WITHDRAW_AMOUNT, M as MIN_I128, t as MIN_TICK, v as TICKS_PER_TICK_HAS_DEBT, T as TICK_HAS_DEBT_ARRAY_SIZE, w as TICK_HAS_DEBT_CHILDREN_SIZE, x as TICK_HAS_DEBT_CHILDREN_SIZE_IN_BITS, y as TOTAL_INDICES_NEEDED, Z as ZERO_TICK_SCALED_RATIO, E as findNextTickWithDebt, j as getAccountOwner, k as getCurrentPosition, l as getCurrentPositionState, m as getFinalPosition, B as getFirstTickForIndex, d as getInitPositionContext, c as getInitPositionIx, f as getLiquidateContext, s as getLiquidityProgramId, b as getOperateContext, e as getOperateIx, z as getRatioAtTick, A as getTickAtRatio, C as getTickIndices, n as loadRelevantBranches, q as loadRelevantBranchesForLiquidate, o as loadRelevantTicksHasDebtArrays, p as loadRelevantTicksHasDebtArraysLiquidate, r as readOraclePrice, D as readTickHasDebtArray } from '../shared/lend.
|
|
1
|
+
import { g as getLiquidateIx, a as getVaultsProgram } from '../shared/lend.DfKhG_eQ.mjs';
|
|
2
|
+
export { I as INIT_TICK, h as MAX_REPAY_AMOUNT, u as MAX_TICK, i as MAX_WITHDRAW_AMOUNT, M as MIN_I128, t as MIN_TICK, v as TICKS_PER_TICK_HAS_DEBT, T as TICK_HAS_DEBT_ARRAY_SIZE, w as TICK_HAS_DEBT_CHILDREN_SIZE, x as TICK_HAS_DEBT_CHILDREN_SIZE_IN_BITS, y as TOTAL_INDICES_NEEDED, Z as ZERO_TICK_SCALED_RATIO, E as findNextTickWithDebt, j as getAccountOwner, k as getCurrentPosition, l as getCurrentPositionState, m as getFinalPosition, B as getFirstTickForIndex, d as getInitPositionContext, c as getInitPositionIx, f as getLiquidateContext, s as getLiquidityProgramId, b as getOperateContext, e as getOperateIx, z as getRatioAtTick, A as getTickAtRatio, C as getTickIndices, n as loadRelevantBranches, q as loadRelevantBranchesForLiquidate, o as loadRelevantTicksHasDebtArrays, p as loadRelevantTicksHasDebtArraysLiquidate, r as readOraclePrice, D as readTickHasDebtArray } from '../shared/lend.DfKhG_eQ.mjs';
|
|
3
3
|
import { PublicKey, TransactionMessage, ComputeBudgetProgram, VersionedTransaction } from '@solana/web3.js';
|
|
4
4
|
import BN from 'bn.js';
|
|
5
5
|
import { g as getVaultAdmin } from '../shared/lend.BsvjWilv.mjs';
|
package/dist/index.mjs
CHANGED
package/dist/refinance/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { e as getOperateIx, F as vaultsIdl } from '../shared/lend.
|
|
1
|
+
import { e as getOperateIx, F as vaultsIdl } from '../shared/lend.DfKhG_eQ.mjs';
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
import 'bn.js';
|
|
@@ -1528,12 +1528,13 @@ function getTickIndices(tick) {
|
|
|
1528
1528
|
async function readTickHasDebtArray({
|
|
1529
1529
|
vaultId,
|
|
1530
1530
|
index,
|
|
1531
|
-
program
|
|
1531
|
+
program,
|
|
1532
|
+
market
|
|
1532
1533
|
}) {
|
|
1533
|
-
const tickPda = getTickHasDebt(vaultId, index);
|
|
1534
|
+
const tickPda = getTickHasDebt(vaultId, index, market);
|
|
1534
1535
|
return await program.account.tickHasDebtArray.fetch(tickPda);
|
|
1535
1536
|
}
|
|
1536
|
-
async function findNextTickWithDebt(vaultId, startTick, program) {
|
|
1537
|
+
async function findNextTickWithDebt(vaultId, startTick, program, market) {
|
|
1537
1538
|
try {
|
|
1538
1539
|
const { arrayIndex, mapIndex, byteIndex, bitIndex } = getTickIndices(startTick);
|
|
1539
1540
|
let currentArrayIndex = arrayIndex;
|
|
@@ -1541,7 +1542,8 @@ async function findNextTickWithDebt(vaultId, startTick, program) {
|
|
|
1541
1542
|
let tickHasDebtData = await readTickHasDebtArray({
|
|
1542
1543
|
vaultId,
|
|
1543
1544
|
index: currentArrayIndex,
|
|
1544
|
-
program
|
|
1545
|
+
program,
|
|
1546
|
+
market
|
|
1545
1547
|
});
|
|
1546
1548
|
if (!tickHasDebtData) {
|
|
1547
1549
|
return MIN_TICK$1;
|
|
@@ -1563,7 +1565,8 @@ async function findNextTickWithDebt(vaultId, startTick, program) {
|
|
|
1563
1565
|
tickHasDebtData = await readTickHasDebtArray({
|
|
1564
1566
|
vaultId,
|
|
1565
1567
|
index: currentArrayIndex,
|
|
1566
|
-
program
|
|
1568
|
+
program,
|
|
1569
|
+
market
|
|
1567
1570
|
});
|
|
1568
1571
|
if (!tickHasDebtData) {
|
|
1569
1572
|
return MIN_TICK$1;
|
|
@@ -6555,13 +6558,15 @@ const getCurrentPosition = async ({
|
|
|
6555
6558
|
return await getCurrentPositionState({
|
|
6556
6559
|
vaultId,
|
|
6557
6560
|
position,
|
|
6558
|
-
program
|
|
6561
|
+
program,
|
|
6562
|
+
market
|
|
6559
6563
|
});
|
|
6560
6564
|
};
|
|
6561
6565
|
const getCurrentPositionState = async ({
|
|
6562
6566
|
vaultId,
|
|
6563
6567
|
position,
|
|
6564
|
-
program
|
|
6568
|
+
program,
|
|
6569
|
+
market
|
|
6565
6570
|
}) => {
|
|
6566
6571
|
let positionTick = position.tick;
|
|
6567
6572
|
if (positionTick === INIT_TICK) {
|
|
@@ -6594,7 +6599,7 @@ const getCurrentPositionState = async ({
|
|
|
6594
6599
|
let postLiquidationBranchId = 0;
|
|
6595
6600
|
if (positionTick > MIN_TICK) {
|
|
6596
6601
|
const tickData = await program.account.tick.fetch(
|
|
6597
|
-
getTick(vaultId, positionTick)
|
|
6602
|
+
getTick(vaultId, positionTick, market)
|
|
6598
6603
|
);
|
|
6599
6604
|
if (tickData.isLiquidated || tickData.totalIds > position.tickId) {
|
|
6600
6605
|
userLiquidationStatus = true;
|
|
@@ -6603,10 +6608,11 @@ const getCurrentPositionState = async ({
|
|
|
6603
6608
|
getTickIdLiquidation(
|
|
6604
6609
|
vaultId,
|
|
6605
6610
|
positionTick,
|
|
6606
|
-
position.tickId
|
|
6611
|
+
position.tickId,
|
|
6612
|
+
market
|
|
6607
6613
|
)
|
|
6608
6614
|
).catch(() => null),
|
|
6609
|
-
getAllBranches({ vaultId, program })
|
|
6615
|
+
getAllBranches({ vaultId, program, market })
|
|
6610
6616
|
]);
|
|
6611
6617
|
if (!tickIdData) {
|
|
6612
6618
|
tickIdData = {
|
|
@@ -6674,15 +6680,16 @@ const getCurrentPositionState = async ({
|
|
|
6674
6680
|
};
|
|
6675
6681
|
async function getAllBranches({
|
|
6676
6682
|
vaultId,
|
|
6677
|
-
program
|
|
6683
|
+
program,
|
|
6684
|
+
market
|
|
6678
6685
|
}) {
|
|
6679
6686
|
const vaultState = await program.account.vaultState.fetch(
|
|
6680
|
-
getVaultState(vaultId)
|
|
6687
|
+
getVaultState(vaultId, market)
|
|
6681
6688
|
);
|
|
6682
6689
|
const branchPromises = [];
|
|
6683
6690
|
for (let i = 0; i <= vaultState.totalBranchId; i++) {
|
|
6684
6691
|
branchPromises.push(
|
|
6685
|
-
program.account.branch.fetch(getBranch(vaultId, i)).catch(() => null)
|
|
6692
|
+
program.account.branch.fetch(getBranch(vaultId, i, market)).catch(() => null)
|
|
6686
6693
|
);
|
|
6687
6694
|
}
|
|
6688
6695
|
const branchResults = await Promise.all(branchPromises);
|
|
@@ -6787,11 +6794,12 @@ const getFinalPosition = async ({
|
|
|
6787
6794
|
newDebtAmount,
|
|
6788
6795
|
program,
|
|
6789
6796
|
connection,
|
|
6790
|
-
signer
|
|
6797
|
+
signer,
|
|
6798
|
+
market
|
|
6791
6799
|
}) => {
|
|
6792
|
-
program = program ?? getVaultsProgram({ connection, signer });
|
|
6800
|
+
program = program ?? getVaultsProgram({ connection, signer, market });
|
|
6793
6801
|
const vaultConfig = await program.account.vaultConfig.fetch(
|
|
6794
|
-
getVaultConfig(vaultId)
|
|
6802
|
+
getVaultConfig(vaultId, market)
|
|
6795
6803
|
);
|
|
6796
6804
|
const {
|
|
6797
6805
|
vaultSupplyExchangePrice: supplyExPrice,
|
|
@@ -6800,7 +6808,8 @@ const getFinalPosition = async ({
|
|
|
6800
6808
|
vaultId,
|
|
6801
6809
|
vaultConfig,
|
|
6802
6810
|
connection,
|
|
6803
|
-
signer
|
|
6811
|
+
signer,
|
|
6812
|
+
market
|
|
6804
6813
|
});
|
|
6805
6814
|
const borrowFee = vaultConfig.borrowFee;
|
|
6806
6815
|
let { colRaw, debtRaw, dustDebtRaw } = currentPosition;
|
|
@@ -6862,14 +6871,14 @@ const getFinalPosition = async ({
|
|
|
6862
6871
|
isSupplyOnlyPosition
|
|
6863
6872
|
};
|
|
6864
6873
|
};
|
|
6865
|
-
async function loadRelevantBranches(vaultId, vaultState, liquidationStatus, postLiquidationBranchId, program) {
|
|
6874
|
+
async function loadRelevantBranches(vaultId, vaultState, liquidationStatus, postLiquidationBranchId, program, market) {
|
|
6866
6875
|
const addedBranchIds = /* @__PURE__ */ new Set();
|
|
6867
6876
|
const currentBranchId = postLiquidationBranchId > 0 ? postLiquidationBranchId : vaultState.currentBranchId;
|
|
6868
6877
|
let connectedBranchId = 0;
|
|
6869
6878
|
if (currentBranchId > 0) {
|
|
6870
6879
|
try {
|
|
6871
6880
|
const currentBranch = await program.account.branch.fetch(
|
|
6872
|
-
getBranch(vaultId, currentBranchId)
|
|
6881
|
+
getBranch(vaultId, currentBranchId, market)
|
|
6873
6882
|
);
|
|
6874
6883
|
if (currentBranch) {
|
|
6875
6884
|
addedBranchIds.add(currentBranch.branchId);
|
|
@@ -6883,7 +6892,7 @@ async function loadRelevantBranches(vaultId, vaultState, liquidationStatus, post
|
|
|
6883
6892
|
while (connectedBranchId > 0) {
|
|
6884
6893
|
try {
|
|
6885
6894
|
const connectedBranch = await program.account.branch.fetch(
|
|
6886
|
-
getBranch(vaultId, connectedBranchId)
|
|
6895
|
+
getBranch(vaultId, connectedBranchId, market)
|
|
6887
6896
|
);
|
|
6888
6897
|
if (connectedBranch) {
|
|
6889
6898
|
if (!addedBranchIds.has(connectedBranch.branchId))
|
|
@@ -6902,32 +6911,41 @@ async function loadRelevantBranches(vaultId, vaultState, liquidationStatus, post
|
|
|
6902
6911
|
}
|
|
6903
6912
|
return [...addedBranchIds];
|
|
6904
6913
|
}
|
|
6905
|
-
async function loadRelevantTicksHasDebtArrays(vaultId, topTick, existingPositionTick, finalTick, program) {
|
|
6914
|
+
async function loadRelevantTicksHasDebtArrays(vaultId, topTick, existingPositionTick, finalTick, program, market) {
|
|
6906
6915
|
const tickHasDebtArrays = /* @__PURE__ */ new Set();
|
|
6907
6916
|
if (existingPositionTick == topTick) {
|
|
6908
6917
|
let nextTickWithDebt = await findNextTickWithDebt(
|
|
6909
6918
|
vaultId,
|
|
6910
6919
|
topTick,
|
|
6911
|
-
program
|
|
6920
|
+
program,
|
|
6921
|
+
market
|
|
6912
6922
|
);
|
|
6913
6923
|
let { arrayIndex: startIndex } = getTickIndices(nextTickWithDebt);
|
|
6914
6924
|
let { arrayIndex: endIndex } = getTickIndices(topTick);
|
|
6915
6925
|
let { arrayIndex: finalTickIndex } = getTickIndices(finalTick);
|
|
6916
|
-
let finalTickHasDebtPda = getTickHasDebt(
|
|
6926
|
+
let finalTickHasDebtPda = getTickHasDebt(
|
|
6927
|
+
vaultId,
|
|
6928
|
+
finalTickIndex,
|
|
6929
|
+
market
|
|
6930
|
+
);
|
|
6917
6931
|
tickHasDebtArrays.add(finalTickHasDebtPda);
|
|
6918
6932
|
if (endIndex < 15) endIndex++;
|
|
6919
6933
|
try {
|
|
6920
6934
|
for (let arrIdx = startIndex; arrIdx <= endIndex; arrIdx++)
|
|
6921
|
-
tickHasDebtArrays.add(
|
|
6935
|
+
tickHasDebtArrays.add(
|
|
6936
|
+
getTickHasDebt(vaultId, arrIdx, market)
|
|
6937
|
+
);
|
|
6922
6938
|
} catch (error) {
|
|
6923
6939
|
console.warn(`Error finding next tick with debt:`, error);
|
|
6924
6940
|
}
|
|
6925
6941
|
} else {
|
|
6926
6942
|
let { arrayIndex: finalTickIndex } = getTickIndices(finalTick);
|
|
6927
6943
|
let { arrayIndex: existingPositionTickIndex } = getTickIndices(existingPositionTick);
|
|
6928
|
-
tickHasDebtArrays.add(getTickHasDebt(vaultId, finalTickIndex));
|
|
6929
6944
|
tickHasDebtArrays.add(
|
|
6930
|
-
getTickHasDebt(vaultId,
|
|
6945
|
+
getTickHasDebt(vaultId, finalTickIndex, market)
|
|
6946
|
+
);
|
|
6947
|
+
tickHasDebtArrays.add(
|
|
6948
|
+
getTickHasDebt(vaultId, existingPositionTickIndex, market)
|
|
6931
6949
|
);
|
|
6932
6950
|
}
|
|
6933
6951
|
return [...tickHasDebtArrays];
|
|
@@ -6936,14 +6954,25 @@ async function getExchangePrices({
|
|
|
6936
6954
|
vaultId,
|
|
6937
6955
|
vaultConfig,
|
|
6938
6956
|
connection,
|
|
6939
|
-
signer
|
|
6957
|
+
signer,
|
|
6958
|
+
market
|
|
6940
6959
|
}) {
|
|
6941
|
-
const program =
|
|
6960
|
+
const program = getVaultsProgram({
|
|
6961
|
+
connection,
|
|
6962
|
+
signer,
|
|
6963
|
+
market
|
|
6964
|
+
});
|
|
6942
6965
|
const ix = await program.methods.getExchangePrices().accounts({
|
|
6943
|
-
vaultState: getVaultState(vaultId),
|
|
6944
|
-
vaultConfig: getVaultConfig(vaultId),
|
|
6945
|
-
supplyTokenReserves: getReserve(
|
|
6946
|
-
|
|
6966
|
+
vaultState: getVaultState(vaultId, market),
|
|
6967
|
+
vaultConfig: getVaultConfig(vaultId, market),
|
|
6968
|
+
supplyTokenReserves: getReserve(
|
|
6969
|
+
vaultConfig.supplyToken,
|
|
6970
|
+
market
|
|
6971
|
+
),
|
|
6972
|
+
borrowTokenReserves: getReserve(
|
|
6973
|
+
vaultConfig.borrowToken,
|
|
6974
|
+
market
|
|
6975
|
+
)
|
|
6947
6976
|
}).instruction();
|
|
6948
6977
|
const transaction = new Transaction().add(ix);
|
|
6949
6978
|
const latestBlockHash = await connection.getLatestBlockhash();
|
|
@@ -6955,7 +6984,8 @@ async function getExchangePrices({
|
|
|
6955
6984
|
vaultId,
|
|
6956
6985
|
vaultConfig,
|
|
6957
6986
|
connection,
|
|
6958
|
-
signer: new PublicKey("HEyJLdMfZhhQ7FHCtjD5DWDFNFQhaeAVAsHeWqoY6dSD")
|
|
6987
|
+
signer: new PublicKey("HEyJLdMfZhhQ7FHCtjD5DWDFNFQhaeAVAsHeWqoY6dSD"),
|
|
6988
|
+
market
|
|
6959
6989
|
});
|
|
6960
6990
|
}
|
|
6961
6991
|
const returnLog = raw.value.logs?.find(
|
|
@@ -6979,14 +7009,14 @@ async function getExchangePrices({
|
|
|
6979
7009
|
vaultBorrowExchangePrice
|
|
6980
7010
|
};
|
|
6981
7011
|
}
|
|
6982
|
-
async function loadRelevantTicksHasDebtArraysLiquidate(vaultId, topTick, nextTick, program) {
|
|
7012
|
+
async function loadRelevantTicksHasDebtArraysLiquidate(vaultId, topTick, nextTick, program, market) {
|
|
6983
7013
|
const { arrayIndex: topTickIndex } = getTickIndices(topTick);
|
|
6984
7014
|
const { arrayIndex: nextTickIndex } = getTickIndices(nextTick);
|
|
6985
7015
|
const promises = [];
|
|
6986
7016
|
for (let arrIdx = topTickIndex; arrIdx >= nextTickIndex; arrIdx--) {
|
|
6987
7017
|
promises.push(
|
|
6988
7018
|
program.account.tickHasDebtArray.fetch(
|
|
6989
|
-
getTickHasDebt(vaultId, arrIdx)
|
|
7019
|
+
getTickHasDebt(vaultId, arrIdx, market)
|
|
6990
7020
|
)
|
|
6991
7021
|
);
|
|
6992
7022
|
}
|
|
@@ -6996,13 +7026,13 @@ async function loadRelevantTicksHasDebtArraysLiquidate(vaultId, topTick, nextTic
|
|
|
6996
7026
|
);
|
|
6997
7027
|
return tickHasDebtArrays;
|
|
6998
7028
|
}
|
|
6999
|
-
async function loadRelevantBranchesForLiquidate(vaultId, vaultState, program) {
|
|
7029
|
+
async function loadRelevantBranchesForLiquidate(vaultId, vaultState, program, market) {
|
|
7000
7030
|
const branches = [];
|
|
7001
7031
|
const currentBranchId = vaultState.currentBranchId;
|
|
7002
7032
|
if (currentBranchId > 0) {
|
|
7003
7033
|
try {
|
|
7004
7034
|
const currentBranch = await program.account.branch.fetch(
|
|
7005
|
-
getBranch(vaultId, currentBranchId)
|
|
7035
|
+
getBranch(vaultId, currentBranchId, market)
|
|
7006
7036
|
);
|
|
7007
7037
|
if (currentBranch) branches.push(currentBranch);
|
|
7008
7038
|
} catch (error) {
|
|
@@ -7014,7 +7044,7 @@ async function loadRelevantBranchesForLiquidate(vaultId, vaultState, program) {
|
|
|
7014
7044
|
while (!doesBranchExist(connectedBranchId)) {
|
|
7015
7045
|
try {
|
|
7016
7046
|
const connectedBranch = await program.account.branch.fetch(
|
|
7017
|
-
getBranch(vaultId, connectedBranchId)
|
|
7047
|
+
getBranch(vaultId, connectedBranchId, market)
|
|
7018
7048
|
);
|
|
7019
7049
|
connectedBranchId = connectedBranch.connectedBranchId;
|
|
7020
7050
|
if (connectedBranch) branches.push(connectedBranch);
|
|
@@ -7188,14 +7218,16 @@ async function getRemainingAccountsOperate(vaultId, vaultState, vaultConfig, fin
|
|
|
7188
7218
|
vaultState,
|
|
7189
7219
|
liquidationStatus,
|
|
7190
7220
|
postLiquidationBranchId,
|
|
7191
|
-
program
|
|
7221
|
+
program,
|
|
7222
|
+
market
|
|
7192
7223
|
),
|
|
7193
7224
|
loadRelevantTicksHasDebtArrays(
|
|
7194
7225
|
vaultId,
|
|
7195
7226
|
tickHelper(vaultState.topmostTick),
|
|
7196
7227
|
existingPositionTick,
|
|
7197
7228
|
finalPositionTick,
|
|
7198
|
-
program
|
|
7229
|
+
program,
|
|
7230
|
+
market
|
|
7199
7231
|
)
|
|
7200
7232
|
]);
|
|
7201
7233
|
const sourceLength = oracleData.sources.length;
|
|
@@ -7282,7 +7314,8 @@ async function getOperateContext({
|
|
|
7282
7314
|
const currentPosition = await getCurrentPositionState({
|
|
7283
7315
|
vaultId,
|
|
7284
7316
|
position: positionData,
|
|
7285
|
-
program
|
|
7317
|
+
program,
|
|
7318
|
+
market
|
|
7286
7319
|
});
|
|
7287
7320
|
if (existingPositionTick === -2147483648) {
|
|
7288
7321
|
existingPositionTick = currentPosition.tick;
|
|
@@ -7300,7 +7333,8 @@ async function getOperateContext({
|
|
|
7300
7333
|
newDebtAmount: newDebt,
|
|
7301
7334
|
program,
|
|
7302
7335
|
connection,
|
|
7303
|
-
signer
|
|
7336
|
+
signer,
|
|
7337
|
+
market
|
|
7304
7338
|
});
|
|
7305
7339
|
const { otherIxs, newBranchPda, currentTickIdDataPda, finalTickIdDataPda } = await getOtherInstructionsOperate(
|
|
7306
7340
|
vaultId,
|
|
@@ -7792,7 +7826,7 @@ async function loadRelevantTicksForLiquidate(vaultId, vaultState, liquidationTic
|
|
|
7792
7826
|
}
|
|
7793
7827
|
let nextTick = MIN_TICK$1;
|
|
7794
7828
|
try {
|
|
7795
|
-
nextTick = await findNextTickWithDebt(vaultId, topTick, program);
|
|
7829
|
+
nextTick = await findNextTickWithDebt(vaultId, topTick, program, market);
|
|
7796
7830
|
} catch {
|
|
7797
7831
|
}
|
|
7798
7832
|
const doesTickExist = (tick) => ticks.some((t) => t.tick === tick);
|
|
@@ -7803,7 +7837,7 @@ async function loadRelevantTicksForLiquidate(vaultId, vaultState, liquidationTic
|
|
|
7803
7837
|
);
|
|
7804
7838
|
if (nextTickData) ticks.push({ ...nextTickData, tick: nextTick });
|
|
7805
7839
|
else throw new Error("Tick not found to load");
|
|
7806
|
-
nextTick = await findNextTickWithDebt(vaultId, nextTick, program);
|
|
7840
|
+
nextTick = await findNextTickWithDebt(vaultId, nextTick, program, market);
|
|
7807
7841
|
} catch {
|
|
7808
7842
|
}
|
|
7809
7843
|
}
|
|
@@ -7827,7 +7861,7 @@ async function getRemainingAccountsLiquidate(vaultId, vaultState, vaultConfig, o
|
|
|
7827
7861
|
});
|
|
7828
7862
|
}
|
|
7829
7863
|
const [branches, { ticks: tickAccounts, nextTick }] = await Promise.all([
|
|
7830
|
-
loadRelevantBranchesForLiquidate(vaultId, vaultState, program),
|
|
7864
|
+
loadRelevantBranchesForLiquidate(vaultId, vaultState, program, market),
|
|
7831
7865
|
loadRelevantTicksForLiquidate(
|
|
7832
7866
|
vaultId,
|
|
7833
7867
|
vaultState,
|
|
@@ -7840,7 +7874,8 @@ async function getRemainingAccountsLiquidate(vaultId, vaultState, vaultConfig, o
|
|
|
7840
7874
|
vaultId,
|
|
7841
7875
|
vaultState.topmostTick,
|
|
7842
7876
|
nextTick,
|
|
7843
|
-
program
|
|
7877
|
+
program,
|
|
7878
|
+
market
|
|
7844
7879
|
);
|
|
7845
7880
|
for (const branch of branches) {
|
|
7846
7881
|
remainingAccounts.push({
|