@0dotxyz/p0-ts-sdk 2.2.3 → 2.2.5-alpha.0
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/{dto-rate-model.types-AQ40wS-P.d.cts → dto-rate-model.types-DveIB9Ll.d.cts} +1 -1
- package/dist/{dto-rate-model.types-AQ40wS-P.d.ts → dto-rate-model.types-DveIB9Ll.d.ts} +1 -1
- package/dist/index.cjs +242 -171
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -76
- package/dist/index.d.ts +55 -76
- package/dist/index.js +243 -172
- package/dist/index.js.map +1 -1
- package/dist/instructions.cjs +10 -2
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.d.cts +3 -2
- package/dist/instructions.d.ts +3 -2
- package/dist/instructions.js +10 -2
- package/dist/instructions.js.map +1 -1
- package/dist/jupiter.cjs +61 -0
- package/dist/jupiter.cjs.map +1 -0
- package/dist/jupiter.d.cts +124 -0
- package/dist/jupiter.d.ts +124 -0
- package/dist/jupiter.js +58 -0
- package/dist/jupiter.js.map +1 -0
- package/dist/{types-DGWxbPM1.d.ts → types-CZtn4lP8.d.ts} +6 -6
- package/dist/{types-ZvnTjjh4.d.cts → types-Dw9hSftB.d.cts} +6 -6
- package/dist/vendor.d.cts +2 -2
- package/dist/vendor.d.ts +2 -2
- package/package.json +6 -2
|
@@ -1723,4 +1723,4 @@ interface JupRateModelJSON {
|
|
|
1723
1723
|
rateAtKink2: number;
|
|
1724
1724
|
}
|
|
1725
1725
|
|
|
1726
|
-
export { type ScopeConfigurationJSON as $, type ReserveConfigFields as A, type ReserveFeesFields as B, type CurvePointFields as C, type DriftSpotMarket as D, type BorrowRateCurveFields as E, type
|
|
1726
|
+
export { type ScopeConfigurationJSON as $, type ReserveConfigFields as A, type ReserveFeesFields as B, type CurvePointFields as C, type DriftSpotMarket as D, type BorrowRateCurveFields as E, type FarmStateRaw as F, type PriceHeuristicFields as G, type HistoricalOracleData as H, type InsuranceFund as I, type JupLendingState as J, type ScopeConfigurationFields as K, type SwitchboardConfigurationFields as L, type PythConfigurationFields as M, type ReserveLiquidityJSON as N, type ObligationRaw as O, type PoolBalance as P, type ReserveCollateralJSON as Q, type ReserveRaw as R, type SpotPosition as S, type TokenInfoFields$1 as T, type ReserveConfigJSON as U, type ReserveFeesJSON as V, type WithdrawalCapsFields as W, type BorrowRateCurveJSON as X, type CurvePointJSON as Y, type TokenInfoJSON$1 as Z, type PriceHeuristicJSON as _, type DriftUser as a, type SwitchboardConfigurationJSON as a0, type PythConfigurationJSON as a1, type WithdrawalCapsJSON as a2, type ObligationLiquidityJSON as a3, type ObligationCollateralJSON as a4, type ObligationOrderJSON as a5, type ObligationCollateralFields as a6, type ObligationLiquidityFields as a7, type ObligationOrderFields as a8, type LastUpdateFields as a9, type BigFractionBytesFields as aa, type LastUpdateJSON as ab, type BigFractionBytesJSON as ac, type RewardPerTimeUnitPointFields as ad, type RewardScheduleCurveFields as ae, type RewardScheduleCurveJSON as af, type RewardPerTimeUnitPointJSON as ag, type UserFeesJSON as ah, type UserFeesFields as ai, isSpotBalanceTypeVariant as aj, type FeeTier as ak, type FeeTierJSON as al, type OrderFillerRewardStructure as am, type OrderFillerRewardStructureJSON as an, type PriceDivergenceGuardRails as ao, type PriceDivergenceGuardRailsJSON as ap, type ValidityGuardRails as aq, type ValidityGuardRailsJSON as ar, type HistoricalOracleDataJSON as as, type HistoricalIndexDataJSON as at, type PoolBalanceJSON as au, type InsuranceFundJSON as av, SpotBalanceType as aw, type SpotPositionJSON as ax, type DriftRewards as b, type DriftUserStats as c, type JupTokenReserve as d, type JupLendingRewardsRateModel as e, type JupRateModel as f, type ReserveJSON as g, type ObligationJSON as h, type FarmStateJSON as i, type DriftSpotMarketJSON as j, type DriftUserJSON as k, type DriftRewardsJSON as l, type DriftUserStatsJSON as m, type JupLendingStateJSON as n, type JupTokenReserveJSON as o, type JupLendingRewardsRateModelJSON as p, type JupRateModelJSON as q, type RewardInfoFields as r, type HistoricalIndexData as s, type FeeStructureJSON as t, type OracleGuardRailsJSON as u, type FeeStructure as v, type OracleGuardRails as w, DriftSpotBalanceType as x, type ReserveLiquidityFields as y, type ReserveCollateralFields as z };
|
|
@@ -1723,4 +1723,4 @@ interface JupRateModelJSON {
|
|
|
1723
1723
|
rateAtKink2: number;
|
|
1724
1724
|
}
|
|
1725
1725
|
|
|
1726
|
-
export { type ScopeConfigurationJSON as $, type ReserveConfigFields as A, type ReserveFeesFields as B, type CurvePointFields as C, type DriftSpotMarket as D, type BorrowRateCurveFields as E, type
|
|
1726
|
+
export { type ScopeConfigurationJSON as $, type ReserveConfigFields as A, type ReserveFeesFields as B, type CurvePointFields as C, type DriftSpotMarket as D, type BorrowRateCurveFields as E, type FarmStateRaw as F, type PriceHeuristicFields as G, type HistoricalOracleData as H, type InsuranceFund as I, type JupLendingState as J, type ScopeConfigurationFields as K, type SwitchboardConfigurationFields as L, type PythConfigurationFields as M, type ReserveLiquidityJSON as N, type ObligationRaw as O, type PoolBalance as P, type ReserveCollateralJSON as Q, type ReserveRaw as R, type SpotPosition as S, type TokenInfoFields$1 as T, type ReserveConfigJSON as U, type ReserveFeesJSON as V, type WithdrawalCapsFields as W, type BorrowRateCurveJSON as X, type CurvePointJSON as Y, type TokenInfoJSON$1 as Z, type PriceHeuristicJSON as _, type DriftUser as a, type SwitchboardConfigurationJSON as a0, type PythConfigurationJSON as a1, type WithdrawalCapsJSON as a2, type ObligationLiquidityJSON as a3, type ObligationCollateralJSON as a4, type ObligationOrderJSON as a5, type ObligationCollateralFields as a6, type ObligationLiquidityFields as a7, type ObligationOrderFields as a8, type LastUpdateFields as a9, type BigFractionBytesFields as aa, type LastUpdateJSON as ab, type BigFractionBytesJSON as ac, type RewardPerTimeUnitPointFields as ad, type RewardScheduleCurveFields as ae, type RewardScheduleCurveJSON as af, type RewardPerTimeUnitPointJSON as ag, type UserFeesJSON as ah, type UserFeesFields as ai, isSpotBalanceTypeVariant as aj, type FeeTier as ak, type FeeTierJSON as al, type OrderFillerRewardStructure as am, type OrderFillerRewardStructureJSON as an, type PriceDivergenceGuardRails as ao, type PriceDivergenceGuardRailsJSON as ap, type ValidityGuardRails as aq, type ValidityGuardRailsJSON as ar, type HistoricalOracleDataJSON as as, type HistoricalIndexDataJSON as at, type PoolBalanceJSON as au, type InsuranceFundJSON as av, SpotBalanceType as aw, type SpotPositionJSON as ax, type DriftRewards as b, type DriftUserStats as c, type JupTokenReserve as d, type JupLendingRewardsRateModel as e, type JupRateModel as f, type ReserveJSON as g, type ObligationJSON as h, type FarmStateJSON as i, type DriftSpotMarketJSON as j, type DriftUserJSON as k, type DriftRewardsJSON as l, type DriftUserStatsJSON as m, type JupLendingStateJSON as n, type JupTokenReserveJSON as o, type JupLendingRewardsRateModelJSON as p, type JupRateModelJSON as q, type RewardInfoFields as r, type HistoricalIndexData as s, type FeeStructureJSON as t, type OracleGuardRailsJSON as u, type FeeStructure as v, type OracleGuardRails as w, DriftSpotBalanceType as x, type ReserveLiquidityFields as y, type ReserveCollateralFields as z };
|
package/dist/index.cjs
CHANGED
|
@@ -13,7 +13,6 @@ var borsh$1 = require('borsh');
|
|
|
13
13
|
var borsh = require('@coral-xyz/borsh');
|
|
14
14
|
var WebSocket = require('ws');
|
|
15
15
|
var msgpack = require('@msgpack/msgpack');
|
|
16
|
-
var api = require('@jup-ag/api');
|
|
17
16
|
var onDemand = require('@switchboard-xyz/on-demand');
|
|
18
17
|
var common = require('@switchboard-xyz/common');
|
|
19
18
|
|
|
@@ -15629,12 +15628,20 @@ function makeEndFlashLoanIx(mfiProgram, accounts, remainingAccounts = []) {
|
|
|
15629
15628
|
}).accountsPartial(optionalAccounts).remainingAccounts(remainingAccounts).instruction();
|
|
15630
15629
|
}
|
|
15631
15630
|
async function makeAccountTransferToNewAccountIx(mfProgram, accounts) {
|
|
15632
|
-
const {
|
|
15631
|
+
const {
|
|
15632
|
+
oldMarginfiAccount,
|
|
15633
|
+
newMarginfiAccount,
|
|
15634
|
+
newAuthority,
|
|
15635
|
+
globalFeeWallet,
|
|
15636
|
+
feePayer,
|
|
15637
|
+
...optionalAccounts
|
|
15638
|
+
} = accounts;
|
|
15633
15639
|
return mfProgram.methods.transferToNewAccount().accounts({
|
|
15634
15640
|
oldMarginfiAccount,
|
|
15635
15641
|
newMarginfiAccount,
|
|
15636
15642
|
newAuthority,
|
|
15637
|
-
globalFeeWallet
|
|
15643
|
+
globalFeeWallet,
|
|
15644
|
+
feePayer
|
|
15638
15645
|
}).accountsPartial(optionalAccounts).instruction();
|
|
15639
15646
|
}
|
|
15640
15647
|
async function makeGroupInitIx(mfProgram, accounts) {
|
|
@@ -20528,16 +20535,77 @@ function createActiveEmodePairFromPairs(pairs) {
|
|
|
20528
20535
|
assetWeightInit: bestPair.assetWeightInit
|
|
20529
20536
|
};
|
|
20530
20537
|
}
|
|
20538
|
+
function indexConfiguredPairs(emodePairs) {
|
|
20539
|
+
const configured = [];
|
|
20540
|
+
const liabTagByBank = /* @__PURE__ */ new Map();
|
|
20541
|
+
for (const p of emodePairs) {
|
|
20542
|
+
if (p.collateralBankTag === 0 /* UNSET */ || p.liabilityBankTag === 0 /* UNSET */) {
|
|
20543
|
+
continue;
|
|
20544
|
+
}
|
|
20545
|
+
const liabStr = p.liabilityBank.toBase58();
|
|
20546
|
+
const liabTagStr = p.liabilityBankTag.toString();
|
|
20547
|
+
configured.push({
|
|
20548
|
+
orig: p,
|
|
20549
|
+
liabStr,
|
|
20550
|
+
liabTagStr,
|
|
20551
|
+
collTagStr: p.collateralBankTag.toString(),
|
|
20552
|
+
collStrs: p.collateralBanks.map((b) => b.toBase58())
|
|
20553
|
+
});
|
|
20554
|
+
liabTagByBank.set(liabStr, liabTagStr);
|
|
20555
|
+
}
|
|
20556
|
+
return { configured, liabTagByBank };
|
|
20557
|
+
}
|
|
20558
|
+
function activePairsFromIndex(configured, liabTagByBank, liabSet, collSet) {
|
|
20559
|
+
const requiredTags = /* @__PURE__ */ new Set();
|
|
20560
|
+
for (const liab of liabSet) {
|
|
20561
|
+
const tag = liabTagByBank.get(liab);
|
|
20562
|
+
if (!tag) return [];
|
|
20563
|
+
requiredTags.add(tag);
|
|
20564
|
+
}
|
|
20565
|
+
const possible = configured.filter(
|
|
20566
|
+
(p) => liabSet.has(p.liabStr) && p.collStrs.some((c) => collSet.has(c))
|
|
20567
|
+
);
|
|
20568
|
+
if (possible.length === 0) return [];
|
|
20569
|
+
const byCollTag = {};
|
|
20570
|
+
for (const p of possible) {
|
|
20571
|
+
(byCollTag[p.collTagStr] ||= []).push(p);
|
|
20572
|
+
}
|
|
20573
|
+
const validGroups = [];
|
|
20574
|
+
for (const group of Object.values(byCollTag)) {
|
|
20575
|
+
const supports = new Set(group.map((p) => p.liabTagStr));
|
|
20576
|
+
let coversAll = true;
|
|
20577
|
+
for (const rt of requiredTags) {
|
|
20578
|
+
if (!supports.has(rt)) {
|
|
20579
|
+
coversAll = false;
|
|
20580
|
+
break;
|
|
20581
|
+
}
|
|
20582
|
+
}
|
|
20583
|
+
if (coversAll) validGroups.push(group);
|
|
20584
|
+
}
|
|
20585
|
+
if (validGroups.length === 0) return [];
|
|
20586
|
+
return validGroups.flat().map((p) => p.orig);
|
|
20587
|
+
}
|
|
20531
20588
|
function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, allBanks) {
|
|
20532
|
-
const
|
|
20533
|
-
const
|
|
20534
|
-
const
|
|
20535
|
-
const
|
|
20589
|
+
const activeLiabilitiesSet = new Set(activeLiabilities.map((b) => b.toBase58()));
|
|
20590
|
+
const activeCollateralSet = new Set(activeCollateral.map((b) => b.toBase58()));
|
|
20591
|
+
const { configured, liabTagByBank } = indexConfiguredPairs(emodePairs);
|
|
20592
|
+
const liabTagMapAll = /* @__PURE__ */ new Map();
|
|
20536
20593
|
for (const p of emodePairs) {
|
|
20537
|
-
|
|
20594
|
+
liabTagMapAll.set(p.liabilityBank.toBase58(), p.liabilityBankTag.toString());
|
|
20538
20595
|
}
|
|
20596
|
+
const allCollateralBankStrs = /* @__PURE__ */ new Set();
|
|
20597
|
+
for (const p of emodePairs) {
|
|
20598
|
+
for (const c of p.collateralBanks) allCollateralBankStrs.add(c.toBase58());
|
|
20599
|
+
}
|
|
20600
|
+
const basePairs = activePairsFromIndex(
|
|
20601
|
+
configured,
|
|
20602
|
+
liabTagByBank,
|
|
20603
|
+
activeLiabilitiesSet,
|
|
20604
|
+
activeCollateralSet
|
|
20605
|
+
);
|
|
20606
|
+
const baseOn = basePairs.length > 0;
|
|
20539
20607
|
const existingTags = new Set(
|
|
20540
|
-
|
|
20608
|
+
Array.from(activeLiabilitiesSet).map((l) => liabTagMapAll.get(l)).filter((t) => !!t)
|
|
20541
20609
|
);
|
|
20542
20610
|
function minWeight(ps) {
|
|
20543
20611
|
let m = ps[0].assetWeightInit;
|
|
@@ -20554,27 +20622,26 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
|
|
|
20554
20622
|
if (aMin.lt(bMin)) return 3 /* ReduceEmode */;
|
|
20555
20623
|
return 1 /* ExtendEmode */;
|
|
20556
20624
|
}
|
|
20557
|
-
function simulate(
|
|
20558
|
-
|
|
20559
|
-
let L = [...activeLiabilities], C = [...activeCollateral];
|
|
20625
|
+
function simulate(bankStr, action) {
|
|
20626
|
+
const L = new Set(activeLiabilitiesSet), C = new Set(activeCollateralSet);
|
|
20560
20627
|
switch (action) {
|
|
20561
20628
|
case "borrow":
|
|
20562
|
-
|
|
20629
|
+
L.add(bankStr);
|
|
20563
20630
|
break;
|
|
20564
20631
|
case "repay":
|
|
20565
|
-
L
|
|
20632
|
+
L.delete(bankStr);
|
|
20566
20633
|
break;
|
|
20567
20634
|
case "supply":
|
|
20568
|
-
|
|
20635
|
+
C.add(bankStr);
|
|
20569
20636
|
break;
|
|
20570
20637
|
case "withdraw":
|
|
20571
|
-
C
|
|
20638
|
+
C.delete(bankStr);
|
|
20572
20639
|
break;
|
|
20573
20640
|
}
|
|
20574
|
-
const after =
|
|
20641
|
+
const after = activePairsFromIndex(configured, liabTagByBank, L, C);
|
|
20575
20642
|
let status = diffState(basePairs, after);
|
|
20576
20643
|
if (action === "borrow") {
|
|
20577
|
-
const tag =
|
|
20644
|
+
const tag = liabTagMapAll.get(bankStr);
|
|
20578
20645
|
if (!tag) {
|
|
20579
20646
|
status = baseOn ? 4 /* RemoveEmode */ : 5 /* InactiveEmode */;
|
|
20580
20647
|
} else if (baseOn) {
|
|
@@ -20610,66 +20677,29 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
|
|
|
20610
20677
|
}
|
|
20611
20678
|
const result = {};
|
|
20612
20679
|
for (const bank of allBanks) {
|
|
20613
|
-
const key =
|
|
20680
|
+
const key = bank.toBase58();
|
|
20614
20681
|
const impact = {};
|
|
20615
|
-
if (!
|
|
20616
|
-
impact.borrowImpact = simulate(
|
|
20682
|
+
if (!activeCollateralSet.has(key)) {
|
|
20683
|
+
impact.borrowImpact = simulate(key, "borrow");
|
|
20617
20684
|
}
|
|
20618
|
-
|
|
20619
|
-
|
|
20620
|
-
impact.supplyImpact = simulate(bank, "supply");
|
|
20685
|
+
if (allCollateralBankStrs.has(key) && !activeCollateralSet.has(key) && !activeLiabilitiesSet.has(key)) {
|
|
20686
|
+
impact.supplyImpact = simulate(key, "supply");
|
|
20621
20687
|
}
|
|
20622
|
-
if (
|
|
20623
|
-
impact.repayAllImpact = simulate(
|
|
20688
|
+
if (activeLiabilitiesSet.has(key)) {
|
|
20689
|
+
impact.repayAllImpact = simulate(key, "repay");
|
|
20624
20690
|
}
|
|
20625
|
-
if (
|
|
20626
|
-
impact.withdrawAllImpact = simulate(
|
|
20691
|
+
if (activeCollateralSet.has(key)) {
|
|
20692
|
+
impact.withdrawAllImpact = simulate(key, "withdraw");
|
|
20627
20693
|
}
|
|
20628
20694
|
result[key] = impact;
|
|
20629
20695
|
}
|
|
20630
20696
|
return result;
|
|
20631
20697
|
}
|
|
20632
20698
|
function computeActiveEmodePairs(emodePairs, activeLiabilities, activeCollateral) {
|
|
20633
|
-
const configured = emodePairs
|
|
20634
|
-
|
|
20635
|
-
);
|
|
20636
|
-
|
|
20637
|
-
for (const p of configured) {
|
|
20638
|
-
liabTagByBank.set(p.liabilityBank.toBase58(), p.liabilityBankTag.toString());
|
|
20639
|
-
}
|
|
20640
|
-
const requiredTags = /* @__PURE__ */ new Set();
|
|
20641
|
-
for (const liab of activeLiabilities) {
|
|
20642
|
-
const tag = liabTagByBank.get(liab.toBase58());
|
|
20643
|
-
if (!tag) {
|
|
20644
|
-
return [];
|
|
20645
|
-
}
|
|
20646
|
-
requiredTags.add(tag);
|
|
20647
|
-
}
|
|
20648
|
-
const possible = configured.filter(
|
|
20649
|
-
(p) => activeLiabilities.some((l) => l.equals(p.liabilityBank)) && p.collateralBanks.some((c) => activeCollateral.some((a) => a.equals(c)))
|
|
20650
|
-
);
|
|
20651
|
-
if (possible.length === 0) return [];
|
|
20652
|
-
const byCollTag = {};
|
|
20653
|
-
for (const p of possible) {
|
|
20654
|
-
const ct = p.collateralBankTag.toString();
|
|
20655
|
-
(byCollTag[ct] ||= []).push(p);
|
|
20656
|
-
}
|
|
20657
|
-
const validGroups = [];
|
|
20658
|
-
for (const group of Object.values(byCollTag)) {
|
|
20659
|
-
const supports = new Set(group.map((p) => p.liabilityBankTag.toString()));
|
|
20660
|
-
let coversAll = true;
|
|
20661
|
-
for (const rt of requiredTags) {
|
|
20662
|
-
if (!supports.has(rt)) {
|
|
20663
|
-
coversAll = false;
|
|
20664
|
-
break;
|
|
20665
|
-
}
|
|
20666
|
-
}
|
|
20667
|
-
if (coversAll) {
|
|
20668
|
-
validGroups.push(group);
|
|
20669
|
-
}
|
|
20670
|
-
}
|
|
20671
|
-
if (validGroups.length === 0) return [];
|
|
20672
|
-
return validGroups.flat();
|
|
20699
|
+
const { configured, liabTagByBank } = indexConfiguredPairs(emodePairs);
|
|
20700
|
+
const liabSet = new Set(activeLiabilities.map((b) => b.toBase58()));
|
|
20701
|
+
const collSet = new Set(activeCollateral.map((b) => b.toBase58()));
|
|
20702
|
+
return activePairsFromIndex(configured, liabTagByBank, liabSet, collSet);
|
|
20673
20703
|
}
|
|
20674
20704
|
function computeBalanceUsdValue(params) {
|
|
20675
20705
|
const {
|
|
@@ -20848,62 +20878,6 @@ function computeHealthComponentsFromBalances(params) {
|
|
|
20848
20878
|
}
|
|
20849
20879
|
return { assets: totalAssets, liabilities: totalLiabilities };
|
|
20850
20880
|
}
|
|
20851
|
-
function computeHealthComponentsWithoutBiasFromBalances(params) {
|
|
20852
|
-
const {
|
|
20853
|
-
activeBalances,
|
|
20854
|
-
banksMap,
|
|
20855
|
-
oraclePricesByBank,
|
|
20856
|
-
marginRequirement,
|
|
20857
|
-
assetShareValueMultiplierByBank,
|
|
20858
|
-
activeEmodeWeightsByBank,
|
|
20859
|
-
excludedBanks
|
|
20860
|
-
} = params;
|
|
20861
|
-
const filteredBalances = activeBalances.filter(
|
|
20862
|
-
(accountBalance) => !(excludedBanks ?? []).find((b) => b.equals(accountBalance.bankPk))
|
|
20863
|
-
);
|
|
20864
|
-
let totalAssets = new BigNumber3__default.default(0);
|
|
20865
|
-
let totalLiabilities = new BigNumber3__default.default(0);
|
|
20866
|
-
for (const accountBalance of filteredBalances) {
|
|
20867
|
-
const bankKey = accountBalance.bankPk.toBase58();
|
|
20868
|
-
const bank = banksMap.get(bankKey);
|
|
20869
|
-
if (!bank) {
|
|
20870
|
-
console.warn(
|
|
20871
|
-
`Bank ${shortenAddress(accountBalance.bankPk)} not found, excluding from health computation`
|
|
20872
|
-
);
|
|
20873
|
-
continue;
|
|
20874
|
-
}
|
|
20875
|
-
const oraclePrice = oraclePricesByBank.get(bankKey);
|
|
20876
|
-
if (!oraclePrice) {
|
|
20877
|
-
console.warn(
|
|
20878
|
-
`Price info for bank ${shortenAddress(accountBalance.bankPk)} not found, excluding from health computation`
|
|
20879
|
-
);
|
|
20880
|
-
continue;
|
|
20881
|
-
}
|
|
20882
|
-
const emodeWeight = activeEmodeWeightsByBank?.get(bankKey);
|
|
20883
|
-
const assetShareValueMultiplier = assetShareValueMultiplierByBank?.get(bankKey);
|
|
20884
|
-
const activeEmodeWeights = emodeWeight ? {
|
|
20885
|
-
assetWeightInit: BigNumber3__default.default.max(
|
|
20886
|
-
bank.config.assetWeightInit,
|
|
20887
|
-
emodeWeight.assetWeightInit ?? bank.config.assetWeightInit
|
|
20888
|
-
),
|
|
20889
|
-
assetWeightMaint: BigNumber3__default.default.max(
|
|
20890
|
-
bank.config.assetWeightMaint,
|
|
20891
|
-
emodeWeight.assetWeightMaint ?? bank.config.assetWeightMaint
|
|
20892
|
-
)
|
|
20893
|
-
} : void 0;
|
|
20894
|
-
const { assets, liabilities } = computeBalanceUsdValue({
|
|
20895
|
-
balance: accountBalance,
|
|
20896
|
-
bank,
|
|
20897
|
-
oraclePrice,
|
|
20898
|
-
marginRequirement,
|
|
20899
|
-
activeEmodeWeights,
|
|
20900
|
-
assetShareValueMultiplier
|
|
20901
|
-
});
|
|
20902
|
-
totalAssets = totalAssets.plus(assets);
|
|
20903
|
-
totalLiabilities = totalLiabilities.plus(liabilities);
|
|
20904
|
-
}
|
|
20905
|
-
return { assets: totalAssets, liabilities: totalLiabilities };
|
|
20906
|
-
}
|
|
20907
20881
|
function computeHealthCacheStatus(params) {
|
|
20908
20882
|
const {
|
|
20909
20883
|
activeBalances,
|
|
@@ -20912,7 +20886,7 @@ function computeHealthCacheStatus(params) {
|
|
|
20912
20886
|
assetShareValueMultiplierByBank,
|
|
20913
20887
|
activeEmodeWeightsByBank
|
|
20914
20888
|
} = params;
|
|
20915
|
-
const { assets: assetValueEquity, liabilities: liabilityValueEquity } =
|
|
20889
|
+
const { assets: assetValueEquity, liabilities: liabilityValueEquity } = computeHealthComponentsFromBalances({
|
|
20916
20890
|
activeBalances,
|
|
20917
20891
|
marginRequirement: 2 /* Equity */,
|
|
20918
20892
|
banksMap,
|
|
@@ -36088,6 +36062,48 @@ async function makeCloseMarginfiAccountTx({
|
|
|
36088
36062
|
);
|
|
36089
36063
|
return closeTx;
|
|
36090
36064
|
}
|
|
36065
|
+
async function makeAccountTransferToNewAccountTx({
|
|
36066
|
+
connection,
|
|
36067
|
+
program,
|
|
36068
|
+
marginfiAccount,
|
|
36069
|
+
newMarginfiAccount,
|
|
36070
|
+
newAuthority,
|
|
36071
|
+
feePayer
|
|
36072
|
+
}) {
|
|
36073
|
+
const feePayerKey = feePayer instanceof web3_js.Keypair ? feePayer.publicKey : feePayer ?? marginfiAccount.authority;
|
|
36074
|
+
const [feeStateKey] = web3_js.PublicKey.findProgramAddressSync(
|
|
36075
|
+
[Buffer.from("feestate", "utf-8")],
|
|
36076
|
+
program.programId
|
|
36077
|
+
);
|
|
36078
|
+
const feeState = await program.account.feeState.fetch(feeStateKey);
|
|
36079
|
+
const transferIx = await instructions_default.makeAccountTransferToNewAccountIx(program, {
|
|
36080
|
+
oldMarginfiAccount: marginfiAccount.address,
|
|
36081
|
+
newMarginfiAccount: newMarginfiAccount.publicKey,
|
|
36082
|
+
newAuthority,
|
|
36083
|
+
globalFeeWallet: feeState.globalFeeWallet,
|
|
36084
|
+
feePayer: feePayerKey
|
|
36085
|
+
});
|
|
36086
|
+
const {
|
|
36087
|
+
value: { blockhash }
|
|
36088
|
+
} = await connection.getLatestBlockhashAndContext("confirmed");
|
|
36089
|
+
const signers = [newMarginfiAccount];
|
|
36090
|
+
if (feePayer instanceof web3_js.Keypair) signers.push(feePayer);
|
|
36091
|
+
const transferTx = addTransactionMetadata(
|
|
36092
|
+
new web3_js.VersionedTransaction(
|
|
36093
|
+
new web3_js.TransactionMessage({
|
|
36094
|
+
instructions: [transferIx],
|
|
36095
|
+
payerKey: feePayerKey,
|
|
36096
|
+
recentBlockhash: blockhash
|
|
36097
|
+
}).compileToV0Message([])
|
|
36098
|
+
),
|
|
36099
|
+
{
|
|
36100
|
+
signers,
|
|
36101
|
+
addressLookupTables: [],
|
|
36102
|
+
type: "TRANSFER_AUTH" /* TRANSFER_AUTH */
|
|
36103
|
+
}
|
|
36104
|
+
);
|
|
36105
|
+
return transferTx;
|
|
36106
|
+
}
|
|
36091
36107
|
async function makeCreateAccountTxWithProjection(props) {
|
|
36092
36108
|
const [marginfiAccountAddress] = deriveMarginfiAccount(
|
|
36093
36109
|
props.program.programId,
|
|
@@ -48545,7 +48561,7 @@ async function simulateAccountHealthCacheWithFallback(params) {
|
|
|
48545
48561
|
} = params;
|
|
48546
48562
|
let marginfiAccount = params.marginfiAccount;
|
|
48547
48563
|
const activeBalances = marginfiAccount.balances.filter((b) => b.active);
|
|
48548
|
-
const { assets: assetValueEquity, liabilities: liabilityValueEquity } =
|
|
48564
|
+
const { assets: assetValueEquity, liabilities: liabilityValueEquity } = computeHealthComponentsFromBalances({
|
|
48549
48565
|
activeBalances,
|
|
48550
48566
|
banksMap,
|
|
48551
48567
|
oraclePricesByBank,
|
|
@@ -49158,6 +49174,61 @@ function computeMaxWithdrawForBank(params) {
|
|
|
49158
49174
|
const maxWithdraw = initUntiedCollateralForBank.div(initWeightedPrice);
|
|
49159
49175
|
return maxWithdraw;
|
|
49160
49176
|
}
|
|
49177
|
+
|
|
49178
|
+
// src/vendor/jupiter/client.ts
|
|
49179
|
+
var DEFAULT_BASE_PATH = "https://lite-api.jup.ag/swap/v1";
|
|
49180
|
+
var JupiterApiError = class _JupiterApiError extends Error {
|
|
49181
|
+
status;
|
|
49182
|
+
body;
|
|
49183
|
+
constructor(status, body) {
|
|
49184
|
+
super(`Jupiter API request failed with status ${status}: ${body}`);
|
|
49185
|
+
this.name = "JupiterApiError";
|
|
49186
|
+
Object.setPrototypeOf(this, _JupiterApiError.prototype);
|
|
49187
|
+
this.status = status;
|
|
49188
|
+
this.body = body;
|
|
49189
|
+
}
|
|
49190
|
+
};
|
|
49191
|
+
function buildQuoteSearchParams(request) {
|
|
49192
|
+
const params = new URLSearchParams();
|
|
49193
|
+
for (const [key, value] of Object.entries(request)) {
|
|
49194
|
+
if (value === void 0 || value === null) continue;
|
|
49195
|
+
if (Array.isArray(value)) {
|
|
49196
|
+
if (value.length > 0) params.append(key, value.join(","));
|
|
49197
|
+
continue;
|
|
49198
|
+
}
|
|
49199
|
+
params.append(key, String(value));
|
|
49200
|
+
}
|
|
49201
|
+
return params;
|
|
49202
|
+
}
|
|
49203
|
+
function createJupiterClient(config = {}) {
|
|
49204
|
+
const basePath = (config.basePath ?? DEFAULT_BASE_PATH).replace(/\/+$/, "");
|
|
49205
|
+
const baseHeaders = { ...config.headers };
|
|
49206
|
+
if (config.apiKey) baseHeaders["x-api-key"] = config.apiKey;
|
|
49207
|
+
const request = async (path, init) => {
|
|
49208
|
+
const response = await fetch(`${basePath}${path}`, init);
|
|
49209
|
+
if (!response.ok) {
|
|
49210
|
+
const body = await response.text().catch(() => "");
|
|
49211
|
+
throw new JupiterApiError(response.status, body);
|
|
49212
|
+
}
|
|
49213
|
+
return await response.json();
|
|
49214
|
+
};
|
|
49215
|
+
return {
|
|
49216
|
+
quoteGet(quoteRequest) {
|
|
49217
|
+
const search = buildQuoteSearchParams(quoteRequest);
|
|
49218
|
+
return request(`/quote?${search.toString()}`, {
|
|
49219
|
+
method: "GET",
|
|
49220
|
+
headers: baseHeaders
|
|
49221
|
+
});
|
|
49222
|
+
},
|
|
49223
|
+
swapInstructionsPost({ swapRequest }) {
|
|
49224
|
+
return request(`/swap-instructions`, {
|
|
49225
|
+
method: "POST",
|
|
49226
|
+
headers: { ...baseHeaders, "content-type": "application/json" },
|
|
49227
|
+
body: JSON.stringify(swapRequest)
|
|
49228
|
+
});
|
|
49229
|
+
}
|
|
49230
|
+
};
|
|
49231
|
+
}
|
|
49161
49232
|
var TITAN_FEE_WALLET = new web3_js.PublicKey("FEES6XLN7dMz2iBwKab9Hri9Kwc4WJ6TmDAiT4BNhyej");
|
|
49162
49233
|
var getTitanFeeAccount = (mint) => {
|
|
49163
49234
|
return getAssociatedTokenAddressSync(mint, TITAN_FEE_WALLET, true);
|
|
@@ -49535,15 +49606,17 @@ function getExactOutProviderFn({
|
|
|
49535
49606
|
});
|
|
49536
49607
|
case "JUPITER" /* JUPITER */:
|
|
49537
49608
|
return async () => {
|
|
49538
|
-
const
|
|
49539
|
-
const jupiterApiClient = configParams?.basePath ? new api.SwapApi(new api.Configuration(configParams)) : api.createJupiterApiClient(configParams);
|
|
49609
|
+
const jupiterApiClient = createJupiterClient(toJupiterConfig(apiConfig));
|
|
49540
49610
|
const estimateQuote = await jupiterApiClient.quoteGet({
|
|
49541
49611
|
inputMint,
|
|
49542
49612
|
outputMint,
|
|
49543
49613
|
amount,
|
|
49544
49614
|
swapMode: "ExactOut",
|
|
49545
49615
|
dynamicSlippage: swapOpts.swapConfig ? swapOpts.swapConfig.slippageMode === "DYNAMIC" : true,
|
|
49546
|
-
slippageBps: swapOpts.swapConfig?.slippageBps
|
|
49616
|
+
slippageBps: swapOpts.swapConfig?.slippageBps,
|
|
49617
|
+
// Match the bundle-compatible routing used by the executed flashloan
|
|
49618
|
+
// swap so the ExactOut estimate reflects an achievable route.
|
|
49619
|
+
forJitoBundle: true
|
|
49547
49620
|
});
|
|
49548
49621
|
const quoteResult = mapJupiterQuoteToSwapQuoteResult(estimateQuote);
|
|
49549
49622
|
return { otherAmountThreshold: quoteResult.otherAmountThreshold, quoteResult };
|
|
@@ -49699,7 +49772,7 @@ function toJupiterConfig(apiConfig) {
|
|
|
49699
49772
|
if (!apiConfig) return void 0;
|
|
49700
49773
|
return {
|
|
49701
49774
|
basePath: apiConfig.basePath,
|
|
49702
|
-
apiKey: apiConfig.apiKey
|
|
49775
|
+
apiKey: apiConfig.apiKey,
|
|
49703
49776
|
headers: apiConfig.headers
|
|
49704
49777
|
};
|
|
49705
49778
|
}
|
|
@@ -49711,8 +49784,7 @@ var getJupiterSwapIxsForFlashloan = async ({
|
|
|
49711
49784
|
apiConfig,
|
|
49712
49785
|
maxSwapAccounts
|
|
49713
49786
|
}) => {
|
|
49714
|
-
const
|
|
49715
|
-
const jupiterApiClient = configParams?.basePath ? new api.SwapApi(new api.Configuration(configParams)) : api.createJupiterApiClient(configParams);
|
|
49787
|
+
const jupiterApiClient = createJupiterClient(toJupiterConfig(apiConfig));
|
|
49716
49788
|
const feeMint = quoteParams.swapMode === "ExactIn" ? quoteParams.outputMint : quoteParams.inputMint;
|
|
49717
49789
|
const { feeAccount, hasFeeAccount } = await checkFeeAccount(connection, new web3_js.PublicKey(feeMint));
|
|
49718
49790
|
const project0JupiterLut = (await connection.getAddressLookupTable(ADDRESS_LOOKUP_TABLE_FOR_SWAP))?.value;
|
|
@@ -49731,7 +49803,10 @@ var getJupiterSwapIxsForFlashloan = async ({
|
|
|
49731
49803
|
const maxAccounts = maxSwapAccounts !== void 0 ? maxSwapAccounts - JUPITER_MAX_ACCOUNTS_MARGIN : 40;
|
|
49732
49804
|
const swapQuote = await jupiterApiClient.quoteGet({
|
|
49733
49805
|
...finalQuoteParams,
|
|
49734
|
-
maxAccounts
|
|
49806
|
+
maxAccounts,
|
|
49807
|
+
// Flashloan swaps are landed via a Jito bundle, so restrict routing to
|
|
49808
|
+
// bundle-compatible DEXes (excludes e.g. HumidiFi).
|
|
49809
|
+
forJitoBundle: true
|
|
49735
49810
|
});
|
|
49736
49811
|
const swapInstructionResponse = await jupiterApiClient.swapInstructionsPost({
|
|
49737
49812
|
swapRequest: {
|
|
@@ -51367,7 +51442,7 @@ function mergeOracleResults(results, allBanks) {
|
|
|
51367
51442
|
|
|
51368
51443
|
// src/services/bank/utils/compute/value-computations.utils.ts
|
|
51369
51444
|
function isWeightedPrice(marginRequirement) {
|
|
51370
|
-
return marginRequirement === 0 /* Initial */;
|
|
51445
|
+
return marginRequirement === 0 /* Initial */ || marginRequirement === 2 /* Equity */;
|
|
51371
51446
|
}
|
|
51372
51447
|
function getAssetWeight(params) {
|
|
51373
51448
|
const {
|
|
@@ -51378,6 +51453,12 @@ function getAssetWeight(params) {
|
|
|
51378
51453
|
activeEmodeWeights,
|
|
51379
51454
|
ignoreSoftLimits
|
|
51380
51455
|
} = params;
|
|
51456
|
+
if (bank.config.riskTier === "Isolated" /* Isolated */) {
|
|
51457
|
+
return new BigNumber3__default.default(0);
|
|
51458
|
+
}
|
|
51459
|
+
if (marginRequirement === 0 /* Initial */ && bank.config.operationalState === "ReduceOnly" /* ReduceOnly */) {
|
|
51460
|
+
return new BigNumber3__default.default(0);
|
|
51461
|
+
}
|
|
51381
51462
|
const assetWeightInit = BigNumber3__default.default.max(
|
|
51382
51463
|
activeEmodeWeights?.assetWeightInit ?? BigNumber3__default.default(0),
|
|
51383
51464
|
bank.config.assetWeightInit
|
|
@@ -51394,6 +51475,8 @@ function getAssetWeight(params) {
|
|
|
51394
51475
|
bank,
|
|
51395
51476
|
oraclePrice,
|
|
51396
51477
|
assetShares: bank.totalAssetShares,
|
|
51478
|
+
// Unweighted (Equity => weight 1) total bank value, priced at the same time-weighted
|
|
51479
|
+
// low price used for the Initial balance valuation (program: maybe_get_asset_weight_init_discount).
|
|
51397
51480
|
marginRequirement: 2 /* Equity */,
|
|
51398
51481
|
priceBias: 0 /* Lowest */,
|
|
51399
51482
|
assetShareValueMultiplier,
|
|
@@ -53816,21 +53899,6 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
53816
53899
|
...params
|
|
53817
53900
|
});
|
|
53818
53901
|
}
|
|
53819
|
-
/**
|
|
53820
|
-
* Computes health components from balances without price bias.
|
|
53821
|
-
*
|
|
53822
|
-
* Returns weighted asset and liability values using neutral pricing
|
|
53823
|
-
* (no conservative adjustments).
|
|
53824
|
-
*
|
|
53825
|
-
* @param params - Configuration for health computation (excluding activeBalances)
|
|
53826
|
-
* @returns Object containing assets and liabilities values in USD
|
|
53827
|
-
*/
|
|
53828
|
-
computeHealthComponentsWithoutBiasFromBalances(params) {
|
|
53829
|
-
return computeHealthComponentsWithoutBiasFromBalances({
|
|
53830
|
-
activeBalances: this.activeBalances,
|
|
53831
|
-
...params
|
|
53832
|
-
});
|
|
53833
|
-
}
|
|
53834
53902
|
/**
|
|
53835
53903
|
* Computes the total account value (equity).
|
|
53836
53904
|
*
|
|
@@ -54066,29 +54134,29 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
54066
54134
|
return makeEndFlashLoanIx3(program, this.address, banks, authority);
|
|
54067
54135
|
}
|
|
54068
54136
|
/**
|
|
54069
|
-
*
|
|
54137
|
+
* Builds a transaction to transfer this account to a new authority.
|
|
54070
54138
|
*
|
|
54071
|
-
*
|
|
54139
|
+
* Thin wrapper over the {@link makeAccountTransferToNewAccountTx} action,
|
|
54140
|
+
* injecting the connection and this account from context. The global fee
|
|
54141
|
+
* wallet is derived inside the action from the program's fee state.
|
|
54072
54142
|
*
|
|
54073
54143
|
* @param program - The Marginfi program instance
|
|
54074
|
-
* @param newMarginfiAccount -
|
|
54144
|
+
* @param newMarginfiAccount - Freshly generated keypair for the destination account
|
|
54075
54145
|
* @param newAuthority - The new authority public key
|
|
54146
|
+
* @param feePayer - Optional `PublicKey` (adapter-signed) or `Keypair` (separate
|
|
54147
|
+
* payer); defaults to this account's authority
|
|
54076
54148
|
*
|
|
54077
|
-
* @returns Promise resolving to
|
|
54078
|
-
*
|
|
54079
|
-
* @see {@link makeAccountTransferToNewAccountIx} for implementation
|
|
54149
|
+
* @returns Promise resolving to the transfer transaction
|
|
54080
54150
|
*/
|
|
54081
|
-
async
|
|
54082
|
-
|
|
54151
|
+
async makeAccountTransferToNewAccountTx(program, newMarginfiAccount, newAuthority, feePayer) {
|
|
54152
|
+
return makeAccountTransferToNewAccountTx({
|
|
54153
|
+
connection: program.provider.connection,
|
|
54083
54154
|
program,
|
|
54084
|
-
|
|
54085
|
-
|
|
54086
|
-
|
|
54087
|
-
|
|
54088
|
-
|
|
54089
|
-
}
|
|
54090
|
-
);
|
|
54091
|
-
return { instructions: [accountTransferToNewAccountIx], keys: [] };
|
|
54155
|
+
marginfiAccount: this,
|
|
54156
|
+
newMarginfiAccount,
|
|
54157
|
+
newAuthority,
|
|
54158
|
+
feePayer
|
|
54159
|
+
});
|
|
54092
54160
|
}
|
|
54093
54161
|
/**
|
|
54094
54162
|
* Creates an instruction to close this marginfi account.
|
|
@@ -54736,16 +54804,19 @@ var MarginfiAccountWrapper = class {
|
|
|
54736
54804
|
);
|
|
54737
54805
|
}
|
|
54738
54806
|
/**
|
|
54739
|
-
*
|
|
54807
|
+
* Builds a transaction to transfer this account to a new authority.
|
|
54740
54808
|
*
|
|
54741
|
-
* @param newMarginfiAccount -
|
|
54809
|
+
* @param newMarginfiAccount - Freshly generated keypair for the destination account
|
|
54742
54810
|
* @param newAuthority - New authority public key
|
|
54811
|
+
* @param feePayer - Optional `PublicKey` (adapter-signed) or `Keypair` (separate
|
|
54812
|
+
* payer); defaults to this account's authority
|
|
54743
54813
|
*/
|
|
54744
|
-
async
|
|
54745
|
-
return this.account.
|
|
54814
|
+
async makeAccountTransferToNewAccountTx(newMarginfiAccount, newAuthority, feePayer) {
|
|
54815
|
+
return this.account.makeAccountTransferToNewAccountTx(
|
|
54746
54816
|
this.client.program,
|
|
54747
54817
|
newMarginfiAccount,
|
|
54748
|
-
newAuthority
|
|
54818
|
+
newAuthority,
|
|
54819
|
+
feePayer
|
|
54749
54820
|
);
|
|
54750
54821
|
}
|
|
54751
54822
|
/**
|
|
@@ -55675,7 +55746,6 @@ exports.computeHealthCacheStatus = computeHealthCacheStatus;
|
|
|
55675
55746
|
exports.computeHealthCheckAccounts = computeHealthCheckAccounts;
|
|
55676
55747
|
exports.computeHealthComponentsFromBalances = computeHealthComponentsFromBalances;
|
|
55677
55748
|
exports.computeHealthComponentsFromCache = computeHealthComponentsFromCache;
|
|
55678
|
-
exports.computeHealthComponentsWithoutBiasFromBalances = computeHealthComponentsWithoutBiasFromBalances;
|
|
55679
55749
|
exports.computeInterestRates = computeInterestRates;
|
|
55680
55750
|
exports.computeLiabilityHealthComponent = computeLiabilityHealthComponent;
|
|
55681
55751
|
exports.computeLiabilityUsdValue = computeLiabilityUsdValue;
|
|
@@ -55812,6 +55882,7 @@ exports.isFlashloan = isFlashloan;
|
|
|
55812
55882
|
exports.isV0Tx = isV0Tx;
|
|
55813
55883
|
exports.isWeightedPrice = isWeightedPrice;
|
|
55814
55884
|
exports.isWholePosition = isWholePosition;
|
|
55885
|
+
exports.makeAccountTransferToNewAccountTx = makeAccountTransferToNewAccountTx;
|
|
55815
55886
|
exports.makeAddPermissionlessStakedBankIx = makeAddPermissionlessStakedBankIx;
|
|
55816
55887
|
exports.makeBeginFlashLoanIx = makeBeginFlashLoanIx3;
|
|
55817
55888
|
exports.makeBorrowIx = makeBorrowIx3;
|