@0dotxyz/p0-ts-sdk 2.2.3 → 2.2.4
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 +231 -96
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -16
- package/dist/index.d.ts +55 -16
- package/dist/index.js +232 -98
- 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-CsLjciLo.d.cts} +2 -2
- package/dist/{types-ZvnTjjh4.d.cts → types-DuCxJVOn.d.ts} +2 -2
- 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();
|
|
20593
|
+
for (const p of emodePairs) {
|
|
20594
|
+
liabTagMapAll.set(p.liabilityBank.toBase58(), p.liabilityBankTag.toString());
|
|
20595
|
+
}
|
|
20596
|
+
const allCollateralBankStrs = /* @__PURE__ */ new Set();
|
|
20536
20597
|
for (const p of emodePairs) {
|
|
20537
|
-
|
|
20598
|
+
for (const c of p.collateralBanks) allCollateralBankStrs.add(c.toBase58());
|
|
20538
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 {
|
|
@@ -36088,6 +36118,48 @@ async function makeCloseMarginfiAccountTx({
|
|
|
36088
36118
|
);
|
|
36089
36119
|
return closeTx;
|
|
36090
36120
|
}
|
|
36121
|
+
async function makeAccountTransferToNewAccountTx({
|
|
36122
|
+
connection,
|
|
36123
|
+
program,
|
|
36124
|
+
marginfiAccount,
|
|
36125
|
+
newMarginfiAccount,
|
|
36126
|
+
newAuthority,
|
|
36127
|
+
feePayer
|
|
36128
|
+
}) {
|
|
36129
|
+
const feePayerKey = feePayer instanceof web3_js.Keypair ? feePayer.publicKey : feePayer ?? marginfiAccount.authority;
|
|
36130
|
+
const [feeStateKey] = web3_js.PublicKey.findProgramAddressSync(
|
|
36131
|
+
[Buffer.from("feestate", "utf-8")],
|
|
36132
|
+
program.programId
|
|
36133
|
+
);
|
|
36134
|
+
const feeState = await program.account.feeState.fetch(feeStateKey);
|
|
36135
|
+
const transferIx = await instructions_default.makeAccountTransferToNewAccountIx(program, {
|
|
36136
|
+
oldMarginfiAccount: marginfiAccount.address,
|
|
36137
|
+
newMarginfiAccount: newMarginfiAccount.publicKey,
|
|
36138
|
+
newAuthority,
|
|
36139
|
+
globalFeeWallet: feeState.globalFeeWallet,
|
|
36140
|
+
feePayer: feePayerKey
|
|
36141
|
+
});
|
|
36142
|
+
const {
|
|
36143
|
+
value: { blockhash }
|
|
36144
|
+
} = await connection.getLatestBlockhashAndContext("confirmed");
|
|
36145
|
+
const signers = [newMarginfiAccount];
|
|
36146
|
+
if (feePayer instanceof web3_js.Keypair) signers.push(feePayer);
|
|
36147
|
+
const transferTx = addTransactionMetadata(
|
|
36148
|
+
new web3_js.VersionedTransaction(
|
|
36149
|
+
new web3_js.TransactionMessage({
|
|
36150
|
+
instructions: [transferIx],
|
|
36151
|
+
payerKey: feePayerKey,
|
|
36152
|
+
recentBlockhash: blockhash
|
|
36153
|
+
}).compileToV0Message([])
|
|
36154
|
+
),
|
|
36155
|
+
{
|
|
36156
|
+
signers,
|
|
36157
|
+
addressLookupTables: [],
|
|
36158
|
+
type: "TRANSFER_AUTH" /* TRANSFER_AUTH */
|
|
36159
|
+
}
|
|
36160
|
+
);
|
|
36161
|
+
return transferTx;
|
|
36162
|
+
}
|
|
36091
36163
|
async function makeCreateAccountTxWithProjection(props) {
|
|
36092
36164
|
const [marginfiAccountAddress] = deriveMarginfiAccount(
|
|
36093
36165
|
props.program.programId,
|
|
@@ -49158,6 +49230,61 @@ function computeMaxWithdrawForBank(params) {
|
|
|
49158
49230
|
const maxWithdraw = initUntiedCollateralForBank.div(initWeightedPrice);
|
|
49159
49231
|
return maxWithdraw;
|
|
49160
49232
|
}
|
|
49233
|
+
|
|
49234
|
+
// src/vendor/jupiter/client.ts
|
|
49235
|
+
var DEFAULT_BASE_PATH = "https://lite-api.jup.ag/swap/v1";
|
|
49236
|
+
var JupiterApiError = class _JupiterApiError extends Error {
|
|
49237
|
+
status;
|
|
49238
|
+
body;
|
|
49239
|
+
constructor(status, body) {
|
|
49240
|
+
super(`Jupiter API request failed with status ${status}: ${body}`);
|
|
49241
|
+
this.name = "JupiterApiError";
|
|
49242
|
+
Object.setPrototypeOf(this, _JupiterApiError.prototype);
|
|
49243
|
+
this.status = status;
|
|
49244
|
+
this.body = body;
|
|
49245
|
+
}
|
|
49246
|
+
};
|
|
49247
|
+
function buildQuoteSearchParams(request) {
|
|
49248
|
+
const params = new URLSearchParams();
|
|
49249
|
+
for (const [key, value] of Object.entries(request)) {
|
|
49250
|
+
if (value === void 0 || value === null) continue;
|
|
49251
|
+
if (Array.isArray(value)) {
|
|
49252
|
+
if (value.length > 0) params.append(key, value.join(","));
|
|
49253
|
+
continue;
|
|
49254
|
+
}
|
|
49255
|
+
params.append(key, String(value));
|
|
49256
|
+
}
|
|
49257
|
+
return params;
|
|
49258
|
+
}
|
|
49259
|
+
function createJupiterClient(config = {}) {
|
|
49260
|
+
const basePath = (config.basePath ?? DEFAULT_BASE_PATH).replace(/\/+$/, "");
|
|
49261
|
+
const baseHeaders = { ...config.headers };
|
|
49262
|
+
if (config.apiKey) baseHeaders["x-api-key"] = config.apiKey;
|
|
49263
|
+
const request = async (path, init) => {
|
|
49264
|
+
const response = await fetch(`${basePath}${path}`, init);
|
|
49265
|
+
if (!response.ok) {
|
|
49266
|
+
const body = await response.text().catch(() => "");
|
|
49267
|
+
throw new JupiterApiError(response.status, body);
|
|
49268
|
+
}
|
|
49269
|
+
return await response.json();
|
|
49270
|
+
};
|
|
49271
|
+
return {
|
|
49272
|
+
quoteGet(quoteRequest) {
|
|
49273
|
+
const search = buildQuoteSearchParams(quoteRequest);
|
|
49274
|
+
return request(`/quote?${search.toString()}`, {
|
|
49275
|
+
method: "GET",
|
|
49276
|
+
headers: baseHeaders
|
|
49277
|
+
});
|
|
49278
|
+
},
|
|
49279
|
+
swapInstructionsPost({ swapRequest }) {
|
|
49280
|
+
return request(`/swap-instructions`, {
|
|
49281
|
+
method: "POST",
|
|
49282
|
+
headers: { ...baseHeaders, "content-type": "application/json" },
|
|
49283
|
+
body: JSON.stringify(swapRequest)
|
|
49284
|
+
});
|
|
49285
|
+
}
|
|
49286
|
+
};
|
|
49287
|
+
}
|
|
49161
49288
|
var TITAN_FEE_WALLET = new web3_js.PublicKey("FEES6XLN7dMz2iBwKab9Hri9Kwc4WJ6TmDAiT4BNhyej");
|
|
49162
49289
|
var getTitanFeeAccount = (mint) => {
|
|
49163
49290
|
return getAssociatedTokenAddressSync(mint, TITAN_FEE_WALLET, true);
|
|
@@ -49535,15 +49662,17 @@ function getExactOutProviderFn({
|
|
|
49535
49662
|
});
|
|
49536
49663
|
case "JUPITER" /* JUPITER */:
|
|
49537
49664
|
return async () => {
|
|
49538
|
-
const
|
|
49539
|
-
const jupiterApiClient = configParams?.basePath ? new api.SwapApi(new api.Configuration(configParams)) : api.createJupiterApiClient(configParams);
|
|
49665
|
+
const jupiterApiClient = createJupiterClient(toJupiterConfig(apiConfig));
|
|
49540
49666
|
const estimateQuote = await jupiterApiClient.quoteGet({
|
|
49541
49667
|
inputMint,
|
|
49542
49668
|
outputMint,
|
|
49543
49669
|
amount,
|
|
49544
49670
|
swapMode: "ExactOut",
|
|
49545
49671
|
dynamicSlippage: swapOpts.swapConfig ? swapOpts.swapConfig.slippageMode === "DYNAMIC" : true,
|
|
49546
|
-
slippageBps: swapOpts.swapConfig?.slippageBps
|
|
49672
|
+
slippageBps: swapOpts.swapConfig?.slippageBps,
|
|
49673
|
+
// Match the bundle-compatible routing used by the executed flashloan
|
|
49674
|
+
// swap so the ExactOut estimate reflects an achievable route.
|
|
49675
|
+
forJitoBundle: true
|
|
49547
49676
|
});
|
|
49548
49677
|
const quoteResult = mapJupiterQuoteToSwapQuoteResult(estimateQuote);
|
|
49549
49678
|
return { otherAmountThreshold: quoteResult.otherAmountThreshold, quoteResult };
|
|
@@ -49699,7 +49828,7 @@ function toJupiterConfig(apiConfig) {
|
|
|
49699
49828
|
if (!apiConfig) return void 0;
|
|
49700
49829
|
return {
|
|
49701
49830
|
basePath: apiConfig.basePath,
|
|
49702
|
-
apiKey: apiConfig.apiKey
|
|
49831
|
+
apiKey: apiConfig.apiKey,
|
|
49703
49832
|
headers: apiConfig.headers
|
|
49704
49833
|
};
|
|
49705
49834
|
}
|
|
@@ -49711,8 +49840,7 @@ var getJupiterSwapIxsForFlashloan = async ({
|
|
|
49711
49840
|
apiConfig,
|
|
49712
49841
|
maxSwapAccounts
|
|
49713
49842
|
}) => {
|
|
49714
|
-
const
|
|
49715
|
-
const jupiterApiClient = configParams?.basePath ? new api.SwapApi(new api.Configuration(configParams)) : api.createJupiterApiClient(configParams);
|
|
49843
|
+
const jupiterApiClient = createJupiterClient(toJupiterConfig(apiConfig));
|
|
49716
49844
|
const feeMint = quoteParams.swapMode === "ExactIn" ? quoteParams.outputMint : quoteParams.inputMint;
|
|
49717
49845
|
const { feeAccount, hasFeeAccount } = await checkFeeAccount(connection, new web3_js.PublicKey(feeMint));
|
|
49718
49846
|
const project0JupiterLut = (await connection.getAddressLookupTable(ADDRESS_LOOKUP_TABLE_FOR_SWAP))?.value;
|
|
@@ -49731,7 +49859,10 @@ var getJupiterSwapIxsForFlashloan = async ({
|
|
|
49731
49859
|
const maxAccounts = maxSwapAccounts !== void 0 ? maxSwapAccounts - JUPITER_MAX_ACCOUNTS_MARGIN : 40;
|
|
49732
49860
|
const swapQuote = await jupiterApiClient.quoteGet({
|
|
49733
49861
|
...finalQuoteParams,
|
|
49734
|
-
maxAccounts
|
|
49862
|
+
maxAccounts,
|
|
49863
|
+
// Flashloan swaps are landed via a Jito bundle, so restrict routing to
|
|
49864
|
+
// bundle-compatible DEXes (excludes e.g. HumidiFi).
|
|
49865
|
+
forJitoBundle: true
|
|
49735
49866
|
});
|
|
49736
49867
|
const swapInstructionResponse = await jupiterApiClient.swapInstructionsPost({
|
|
49737
49868
|
swapRequest: {
|
|
@@ -54066,29 +54197,29 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
54066
54197
|
return makeEndFlashLoanIx3(program, this.address, banks, authority);
|
|
54067
54198
|
}
|
|
54068
54199
|
/**
|
|
54069
|
-
*
|
|
54200
|
+
* Builds a transaction to transfer this account to a new authority.
|
|
54070
54201
|
*
|
|
54071
|
-
*
|
|
54202
|
+
* Thin wrapper over the {@link makeAccountTransferToNewAccountTx} action,
|
|
54203
|
+
* injecting the connection and this account from context. The global fee
|
|
54204
|
+
* wallet is derived inside the action from the program's fee state.
|
|
54072
54205
|
*
|
|
54073
54206
|
* @param program - The Marginfi program instance
|
|
54074
|
-
* @param newMarginfiAccount -
|
|
54207
|
+
* @param newMarginfiAccount - Freshly generated keypair for the destination account
|
|
54075
54208
|
* @param newAuthority - The new authority public key
|
|
54209
|
+
* @param feePayer - Optional `PublicKey` (adapter-signed) or `Keypair` (separate
|
|
54210
|
+
* payer); defaults to this account's authority
|
|
54076
54211
|
*
|
|
54077
|
-
* @returns Promise resolving to
|
|
54078
|
-
*
|
|
54079
|
-
* @see {@link makeAccountTransferToNewAccountIx} for implementation
|
|
54212
|
+
* @returns Promise resolving to the transfer transaction
|
|
54080
54213
|
*/
|
|
54081
|
-
async
|
|
54082
|
-
|
|
54214
|
+
async makeAccountTransferToNewAccountTx(program, newMarginfiAccount, newAuthority, feePayer) {
|
|
54215
|
+
return makeAccountTransferToNewAccountTx({
|
|
54216
|
+
connection: program.provider.connection,
|
|
54083
54217
|
program,
|
|
54084
|
-
|
|
54085
|
-
|
|
54086
|
-
|
|
54087
|
-
|
|
54088
|
-
|
|
54089
|
-
}
|
|
54090
|
-
);
|
|
54091
|
-
return { instructions: [accountTransferToNewAccountIx], keys: [] };
|
|
54218
|
+
marginfiAccount: this,
|
|
54219
|
+
newMarginfiAccount,
|
|
54220
|
+
newAuthority,
|
|
54221
|
+
feePayer
|
|
54222
|
+
});
|
|
54092
54223
|
}
|
|
54093
54224
|
/**
|
|
54094
54225
|
* Creates an instruction to close this marginfi account.
|
|
@@ -54736,16 +54867,19 @@ var MarginfiAccountWrapper = class {
|
|
|
54736
54867
|
);
|
|
54737
54868
|
}
|
|
54738
54869
|
/**
|
|
54739
|
-
*
|
|
54870
|
+
* Builds a transaction to transfer this account to a new authority.
|
|
54740
54871
|
*
|
|
54741
|
-
* @param newMarginfiAccount -
|
|
54872
|
+
* @param newMarginfiAccount - Freshly generated keypair for the destination account
|
|
54742
54873
|
* @param newAuthority - New authority public key
|
|
54874
|
+
* @param feePayer - Optional `PublicKey` (adapter-signed) or `Keypair` (separate
|
|
54875
|
+
* payer); defaults to this account's authority
|
|
54743
54876
|
*/
|
|
54744
|
-
async
|
|
54745
|
-
return this.account.
|
|
54877
|
+
async makeAccountTransferToNewAccountTx(newMarginfiAccount, newAuthority, feePayer) {
|
|
54878
|
+
return this.account.makeAccountTransferToNewAccountTx(
|
|
54746
54879
|
this.client.program,
|
|
54747
54880
|
newMarginfiAccount,
|
|
54748
|
-
newAuthority
|
|
54881
|
+
newAuthority,
|
|
54882
|
+
feePayer
|
|
54749
54883
|
);
|
|
54750
54884
|
}
|
|
54751
54885
|
/**
|
|
@@ -55812,6 +55946,7 @@ exports.isFlashloan = isFlashloan;
|
|
|
55812
55946
|
exports.isV0Tx = isV0Tx;
|
|
55813
55947
|
exports.isWeightedPrice = isWeightedPrice;
|
|
55814
55948
|
exports.isWholePosition = isWholePosition;
|
|
55949
|
+
exports.makeAccountTransferToNewAccountTx = makeAccountTransferToNewAccountTx;
|
|
55815
55950
|
exports.makeAddPermissionlessStakedBankIx = makeAddPermissionlessStakedBankIx;
|
|
55816
55951
|
exports.makeBeginFlashLoanIx = makeBeginFlashLoanIx3;
|
|
55817
55952
|
exports.makeBorrowIx = makeBorrowIx3;
|