@0dotxyz/p0-ts-sdk 2.2.2 → 2.2.3-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/index.cjs +118 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +117 -83
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -19996,7 +19996,7 @@ function dtoToOraclePrice(dto) {
|
|
|
19996
19996
|
}
|
|
19997
19997
|
|
|
19998
19998
|
// src/services/price/utils/crankability.utils.ts
|
|
19999
|
-
async function checkBatchOracleCrankability(feedHashes, crossbarUrl = "https://
|
|
19999
|
+
async function checkBatchOracleCrankability(feedHashes, crossbarUrl = "https://crossbar.0.xyz") {
|
|
20000
20000
|
const results = /* @__PURE__ */ new Map();
|
|
20001
20001
|
if (feedHashes.length === 0) {
|
|
20002
20002
|
return results;
|
|
@@ -20528,16 +20528,72 @@ function createActiveEmodePairFromPairs(pairs) {
|
|
|
20528
20528
|
assetWeightInit: bestPair.assetWeightInit
|
|
20529
20529
|
};
|
|
20530
20530
|
}
|
|
20531
|
+
function indexConfiguredPairs(emodePairs) {
|
|
20532
|
+
const configured = [];
|
|
20533
|
+
const liabTagByBank = /* @__PURE__ */ new Map();
|
|
20534
|
+
for (const p of emodePairs) {
|
|
20535
|
+
if (p.collateralBankTag === 0 /* UNSET */ || p.liabilityBankTag === 0 /* UNSET */) {
|
|
20536
|
+
continue;
|
|
20537
|
+
}
|
|
20538
|
+
const liabStr = p.liabilityBank.toBase58();
|
|
20539
|
+
const liabTagStr = p.liabilityBankTag.toString();
|
|
20540
|
+
configured.push({
|
|
20541
|
+
orig: p,
|
|
20542
|
+
liabStr,
|
|
20543
|
+
liabTagStr,
|
|
20544
|
+
collTagStr: p.collateralBankTag.toString(),
|
|
20545
|
+
collStrs: p.collateralBanks.map((b) => b.toBase58())
|
|
20546
|
+
});
|
|
20547
|
+
liabTagByBank.set(liabStr, liabTagStr);
|
|
20548
|
+
}
|
|
20549
|
+
return { configured, liabTagByBank };
|
|
20550
|
+
}
|
|
20551
|
+
function activePairsFromIndex(configured, liabTagByBank, liabSet, collSet) {
|
|
20552
|
+
const requiredTags = /* @__PURE__ */ new Set();
|
|
20553
|
+
for (const liab of liabSet) {
|
|
20554
|
+
const tag = liabTagByBank.get(liab);
|
|
20555
|
+
if (!tag) return [];
|
|
20556
|
+
requiredTags.add(tag);
|
|
20557
|
+
}
|
|
20558
|
+
const possible = configured.filter(
|
|
20559
|
+
(p) => liabSet.has(p.liabStr) && p.collStrs.some((c) => collSet.has(c))
|
|
20560
|
+
);
|
|
20561
|
+
if (possible.length === 0) return [];
|
|
20562
|
+
const byCollTag = {};
|
|
20563
|
+
for (const p of possible) {
|
|
20564
|
+
(byCollTag[p.collTagStr] ||= []).push(p);
|
|
20565
|
+
}
|
|
20566
|
+
const validGroups = [];
|
|
20567
|
+
for (const group of Object.values(byCollTag)) {
|
|
20568
|
+
const supports = new Set(group.map((p) => p.liabTagStr));
|
|
20569
|
+
let coversAll = true;
|
|
20570
|
+
for (const rt of requiredTags) {
|
|
20571
|
+
if (!supports.has(rt)) {
|
|
20572
|
+
coversAll = false;
|
|
20573
|
+
break;
|
|
20574
|
+
}
|
|
20575
|
+
}
|
|
20576
|
+
if (coversAll) validGroups.push(group);
|
|
20577
|
+
}
|
|
20578
|
+
if (validGroups.length === 0) return [];
|
|
20579
|
+
return validGroups.flat().map((p) => p.orig);
|
|
20580
|
+
}
|
|
20531
20581
|
function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, allBanks) {
|
|
20532
|
-
const
|
|
20533
|
-
const
|
|
20534
|
-
const
|
|
20535
|
-
const
|
|
20582
|
+
const liabBaseSet = new Set(activeLiabilities.map((b) => b.toBase58()));
|
|
20583
|
+
const collBaseSet = new Set(activeCollateral.map((b) => b.toBase58()));
|
|
20584
|
+
const { configured, liabTagByBank } = indexConfiguredPairs(emodePairs);
|
|
20585
|
+
const liabTagMapAll = /* @__PURE__ */ new Map();
|
|
20586
|
+
for (const p of emodePairs) {
|
|
20587
|
+
liabTagMapAll.set(p.liabilityBank.toBase58(), p.liabilityBankTag.toString());
|
|
20588
|
+
}
|
|
20589
|
+
const allCollateralBankStrs = /* @__PURE__ */ new Set();
|
|
20536
20590
|
for (const p of emodePairs) {
|
|
20537
|
-
|
|
20591
|
+
for (const c of p.collateralBanks) allCollateralBankStrs.add(c.toBase58());
|
|
20538
20592
|
}
|
|
20593
|
+
const basePairs = activePairsFromIndex(configured, liabTagByBank, liabBaseSet, collBaseSet);
|
|
20594
|
+
const baseOn = basePairs.length > 0;
|
|
20539
20595
|
const existingTags = new Set(
|
|
20540
|
-
|
|
20596
|
+
Array.from(liabBaseSet).map((l) => liabTagMapAll.get(l)).filter((t) => !!t)
|
|
20541
20597
|
);
|
|
20542
20598
|
function minWeight(ps) {
|
|
20543
20599
|
let m = ps[0].assetWeightInit;
|
|
@@ -20554,27 +20610,26 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
|
|
|
20554
20610
|
if (aMin.lt(bMin)) return 3 /* ReduceEmode */;
|
|
20555
20611
|
return 1 /* ExtendEmode */;
|
|
20556
20612
|
}
|
|
20557
|
-
function simulate(
|
|
20558
|
-
|
|
20559
|
-
let L = [...activeLiabilities], C = [...activeCollateral];
|
|
20613
|
+
function simulate(bankStr, action) {
|
|
20614
|
+
const L = new Set(liabBaseSet), C = new Set(collBaseSet);
|
|
20560
20615
|
switch (action) {
|
|
20561
20616
|
case "borrow":
|
|
20562
|
-
|
|
20617
|
+
L.add(bankStr);
|
|
20563
20618
|
break;
|
|
20564
20619
|
case "repay":
|
|
20565
|
-
L
|
|
20620
|
+
L.delete(bankStr);
|
|
20566
20621
|
break;
|
|
20567
20622
|
case "supply":
|
|
20568
|
-
|
|
20623
|
+
C.add(bankStr);
|
|
20569
20624
|
break;
|
|
20570
20625
|
case "withdraw":
|
|
20571
|
-
C
|
|
20626
|
+
C.delete(bankStr);
|
|
20572
20627
|
break;
|
|
20573
20628
|
}
|
|
20574
|
-
const after =
|
|
20629
|
+
const after = activePairsFromIndex(configured, liabTagByBank, L, C);
|
|
20575
20630
|
let status = diffState(basePairs, after);
|
|
20576
20631
|
if (action === "borrow") {
|
|
20577
|
-
const tag =
|
|
20632
|
+
const tag = liabTagMapAll.get(bankStr);
|
|
20578
20633
|
if (!tag) {
|
|
20579
20634
|
status = baseOn ? 4 /* RemoveEmode */ : 5 /* InactiveEmode */;
|
|
20580
20635
|
} else if (baseOn) {
|
|
@@ -20610,66 +20665,29 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
|
|
|
20610
20665
|
}
|
|
20611
20666
|
const result = {};
|
|
20612
20667
|
for (const bank of allBanks) {
|
|
20613
|
-
const key =
|
|
20668
|
+
const key = bank.toBase58();
|
|
20614
20669
|
const impact = {};
|
|
20615
|
-
if (!
|
|
20616
|
-
impact.borrowImpact = simulate(
|
|
20670
|
+
if (!collBaseSet.has(key)) {
|
|
20671
|
+
impact.borrowImpact = simulate(key, "borrow");
|
|
20617
20672
|
}
|
|
20618
|
-
|
|
20619
|
-
|
|
20620
|
-
impact.supplyImpact = simulate(bank, "supply");
|
|
20673
|
+
if (allCollateralBankStrs.has(key) && !collBaseSet.has(key) && !liabBaseSet.has(key)) {
|
|
20674
|
+
impact.supplyImpact = simulate(key, "supply");
|
|
20621
20675
|
}
|
|
20622
|
-
if (
|
|
20623
|
-
impact.repayAllImpact = simulate(
|
|
20676
|
+
if (liabBaseSet.has(key)) {
|
|
20677
|
+
impact.repayAllImpact = simulate(key, "repay");
|
|
20624
20678
|
}
|
|
20625
|
-
if (
|
|
20626
|
-
impact.withdrawAllImpact = simulate(
|
|
20679
|
+
if (collBaseSet.has(key)) {
|
|
20680
|
+
impact.withdrawAllImpact = simulate(key, "withdraw");
|
|
20627
20681
|
}
|
|
20628
20682
|
result[key] = impact;
|
|
20629
20683
|
}
|
|
20630
20684
|
return result;
|
|
20631
20685
|
}
|
|
20632
20686
|
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();
|
|
20687
|
+
const { configured, liabTagByBank } = indexConfiguredPairs(emodePairs);
|
|
20688
|
+
const liabSet = new Set(activeLiabilities.map((b) => b.toBase58()));
|
|
20689
|
+
const collSet = new Set(activeCollateral.map((b) => b.toBase58()));
|
|
20690
|
+
return activePairsFromIndex(configured, liabTagByBank, liabSet, collSet);
|
|
20673
20691
|
}
|
|
20674
20692
|
function computeBalanceUsdValue(params) {
|
|
20675
20693
|
const {
|
|
@@ -48776,7 +48794,8 @@ async function getHealthSimulationTransactions({
|
|
|
48776
48794
|
authority,
|
|
48777
48795
|
luts,
|
|
48778
48796
|
includeCrankTx,
|
|
48779
|
-
blockhash
|
|
48797
|
+
blockhash,
|
|
48798
|
+
crossbarUrl
|
|
48780
48799
|
}) {
|
|
48781
48800
|
const additionalTxs = [];
|
|
48782
48801
|
const computeIx = web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
@@ -48788,7 +48807,8 @@ async function getHealthSimulationTransactions({
|
|
|
48788
48807
|
marginfiAccount,
|
|
48789
48808
|
bankMap,
|
|
48790
48809
|
projectedActiveBanks,
|
|
48791
|
-
program.provider
|
|
48810
|
+
program.provider,
|
|
48811
|
+
crossbarUrl
|
|
48792
48812
|
);
|
|
48793
48813
|
}
|
|
48794
48814
|
const activeBanks = marginfiAccount.balances.filter((b) => b.active).map((b) => b.bankPk);
|
|
@@ -50481,11 +50501,14 @@ async function makeSmartCrankSwbFeedIx(params) {
|
|
|
50481
50501
|
const { instructions: instructions2, luts } = await makeUpdateSwbFeedIx({
|
|
50482
50502
|
swbPullOracles: oraclesToCrank,
|
|
50483
50503
|
feePayer: params.marginfiAccount.authority,
|
|
50484
|
-
connection: params.connection
|
|
50504
|
+
connection: params.connection,
|
|
50505
|
+
crossbarUrl: params.crossbarUrl
|
|
50485
50506
|
});
|
|
50486
50507
|
return { instructions: instructions2, luts };
|
|
50487
50508
|
}
|
|
50488
|
-
|
|
50509
|
+
var DEFAULT_CROSSBAR_URL = "https://crossbar.0.xyz";
|
|
50510
|
+
var DEFAULT_FALLBACK_CROSSBAR_URL = "https://crossbar.switchboard.xyz";
|
|
50511
|
+
async function makeCrankSwbFeedIx(marginfiAccount, bankMap, newBanksPk, provider, crossbarUrl) {
|
|
50489
50512
|
const activeBanksPk = marginfiAccount.balances.filter((balance) => balance.active).map((balance) => balance.bankPk);
|
|
50490
50513
|
const allActiveBanks = [
|
|
50491
50514
|
...(/* @__PURE__ */ new Set([
|
|
@@ -50504,7 +50527,8 @@ async function makeCrankSwbFeedIx(marginfiAccount, bankMap, newBanksPk, provider
|
|
|
50504
50527
|
const { instructions: instructions2, luts } = await makeUpdateSwbFeedIx({
|
|
50505
50528
|
swbPullOracles: staleOracles.map((oracle) => ({ key: oracle })),
|
|
50506
50529
|
feePayer: provider.publicKey,
|
|
50507
|
-
connection: provider.connection
|
|
50530
|
+
connection: provider.connection,
|
|
50531
|
+
crossbarUrl
|
|
50508
50532
|
});
|
|
50509
50533
|
return { instructions: instructions2, luts };
|
|
50510
50534
|
}
|
|
@@ -50534,16 +50558,26 @@ async function makeUpdateSwbFeedIx(props) {
|
|
|
50534
50558
|
if (pullFeedInstances.length === 0) {
|
|
50535
50559
|
return { instructions: [], luts: [] };
|
|
50536
50560
|
}
|
|
50537
|
-
const
|
|
50538
|
-
|
|
50539
|
-
|
|
50540
|
-
|
|
50541
|
-
|
|
50542
|
-
|
|
50543
|
-
|
|
50544
|
-
|
|
50545
|
-
|
|
50546
|
-
|
|
50561
|
+
const primaryUrl = props.crossbarUrl ?? DEFAULT_CROSSBAR_URL;
|
|
50562
|
+
const fallbackUrl = props.fallbackCrossbarUrl ?? DEFAULT_FALLBACK_CROSSBAR_URL;
|
|
50563
|
+
try {
|
|
50564
|
+
const [pullIx, luts] = await onDemand.PullFeed.fetchUpdateManyIx(swbProgram, {
|
|
50565
|
+
feeds: pullFeedInstances,
|
|
50566
|
+
numSignatures: 1,
|
|
50567
|
+
crossbarClient: new common.CrossbarClient(primaryUrl),
|
|
50568
|
+
payer: props.feePayer
|
|
50569
|
+
});
|
|
50570
|
+
return { instructions: pullIx, luts };
|
|
50571
|
+
} catch (primaryError) {
|
|
50572
|
+
console.warn(`Primary crossbar endpoint failed (${primaryUrl}), trying fallback:`, primaryError);
|
|
50573
|
+
const [pullIx, luts] = await onDemand.PullFeed.fetchUpdateManyIx(swbProgram, {
|
|
50574
|
+
feeds: pullFeedInstances,
|
|
50575
|
+
numSignatures: 1,
|
|
50576
|
+
crossbarClient: new common.CrossbarClient(fallbackUrl),
|
|
50577
|
+
payer: props.feePayer
|
|
50578
|
+
});
|
|
50579
|
+
return { instructions: pullIx, luts };
|
|
50580
|
+
}
|
|
50547
50581
|
}
|
|
50548
50582
|
|
|
50549
50583
|
// src/services/price/actions/klend-reserve-refresh.ts
|
|
@@ -51034,7 +51068,7 @@ var fetchSwbOracleData = async (banks, opts) => {
|
|
|
51034
51068
|
} else {
|
|
51035
51069
|
crossbarResponse = await fetchSwbOraclePricesFromCrossbar(
|
|
51036
51070
|
swbFeedIds,
|
|
51037
|
-
opts.crossbarEndpoint || "https://
|
|
51071
|
+
opts.crossbarEndpoint || "https://crossbar.0.xyz",
|
|
51038
51072
|
"https://crossbar.switchboard.xyz"
|
|
51039
51073
|
);
|
|
51040
51074
|
birdeyeResponse = {};
|
|
@@ -55535,6 +55569,8 @@ exports.Bank = Bank;
|
|
|
55535
55569
|
exports.BankConfig = BankConfig;
|
|
55536
55570
|
exports.BankConfigFlag = BankConfigFlag;
|
|
55537
55571
|
exports.BankVaultType = BankVaultType;
|
|
55572
|
+
exports.DEFAULT_CROSSBAR_URL = DEFAULT_CROSSBAR_URL;
|
|
55573
|
+
exports.DEFAULT_FALLBACK_CROSSBAR_URL = DEFAULT_FALLBACK_CROSSBAR_URL;
|
|
55538
55574
|
exports.DEFAULT_ORACLE_MAX_AGE = DEFAULT_ORACLE_MAX_AGE;
|
|
55539
55575
|
exports.DISABLED_FLAG = DISABLED_FLAG;
|
|
55540
55576
|
exports.EMPTY_HEALTH_CACHE = EMPTY_HEALTH_CACHE;
|