@0dotxyz/p0-ts-sdk 2.2.3-alpha.0 → 2.2.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/index.cjs +65 -83
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +65 -83
- package/dist/index.js.map +1 -1
- package/dist/vendor.cjs +2834 -0
- package/dist/vendor.cjs.map +1 -1
- package/dist/vendor.d.cts +2835 -1
- package/dist/vendor.d.ts +2835 -1
- package/dist/vendor.js +2834 -1
- package/dist/vendor.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20528,72 +20528,16 @@ 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
|
-
}
|
|
20581
20531
|
function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, allBanks) {
|
|
20582
|
-
const
|
|
20583
|
-
const
|
|
20584
|
-
const
|
|
20585
|
-
const
|
|
20586
|
-
for (const p of emodePairs) {
|
|
20587
|
-
liabTagMapAll.set(p.liabilityBank.toBase58(), p.liabilityBankTag.toString());
|
|
20588
|
-
}
|
|
20589
|
-
const allCollateralBankStrs = /* @__PURE__ */ new Set();
|
|
20532
|
+
const toKey = (k) => k.toBase58();
|
|
20533
|
+
const basePairs = computeActiveEmodePairs(emodePairs, activeLiabilities, activeCollateral);
|
|
20534
|
+
const baseOn = basePairs.length > 0;
|
|
20535
|
+
const liabTagMap = /* @__PURE__ */ new Map();
|
|
20590
20536
|
for (const p of emodePairs) {
|
|
20591
|
-
|
|
20537
|
+
liabTagMap.set(p.liabilityBank.toBase58(), p.liabilityBankTag.toString());
|
|
20592
20538
|
}
|
|
20593
|
-
const basePairs = activePairsFromIndex(configured, liabTagByBank, liabBaseSet, collBaseSet);
|
|
20594
|
-
const baseOn = basePairs.length > 0;
|
|
20595
20539
|
const existingTags = new Set(
|
|
20596
|
-
|
|
20540
|
+
activeLiabilities.map((l) => liabTagMap.get(l.toBase58())).filter((t) => !!t)
|
|
20597
20541
|
);
|
|
20598
20542
|
function minWeight(ps) {
|
|
20599
20543
|
let m = ps[0].assetWeightInit;
|
|
@@ -20610,26 +20554,27 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
|
|
|
20610
20554
|
if (aMin.lt(bMin)) return 3 /* ReduceEmode */;
|
|
20611
20555
|
return 1 /* ExtendEmode */;
|
|
20612
20556
|
}
|
|
20613
|
-
function simulate(
|
|
20614
|
-
|
|
20557
|
+
function simulate(bank, action) {
|
|
20558
|
+
bank.equals(new web3_js.PublicKey("CCKtUs6Cgwo4aaQUmBPmyoApH2gUDErxNZCAntD6LYGh"));
|
|
20559
|
+
let L = [...activeLiabilities], C = [...activeCollateral];
|
|
20615
20560
|
switch (action) {
|
|
20616
20561
|
case "borrow":
|
|
20617
|
-
L.
|
|
20562
|
+
if (!L.some((x) => x.equals(bank))) L.push(bank);
|
|
20618
20563
|
break;
|
|
20619
20564
|
case "repay":
|
|
20620
|
-
L.
|
|
20565
|
+
L = L.filter((x) => !x.equals(bank));
|
|
20621
20566
|
break;
|
|
20622
20567
|
case "supply":
|
|
20623
|
-
C.
|
|
20568
|
+
if (!C.some((x) => x.equals(bank))) C.push(bank);
|
|
20624
20569
|
break;
|
|
20625
20570
|
case "withdraw":
|
|
20626
|
-
C.
|
|
20571
|
+
C = C.filter((x) => !x.equals(bank));
|
|
20627
20572
|
break;
|
|
20628
20573
|
}
|
|
20629
|
-
const after =
|
|
20574
|
+
const after = computeActiveEmodePairs(emodePairs, L, C);
|
|
20630
20575
|
let status = diffState(basePairs, after);
|
|
20631
20576
|
if (action === "borrow") {
|
|
20632
|
-
const tag =
|
|
20577
|
+
const tag = liabTagMap.get(bank.toBase58());
|
|
20633
20578
|
if (!tag) {
|
|
20634
20579
|
status = baseOn ? 4 /* RemoveEmode */ : 5 /* InactiveEmode */;
|
|
20635
20580
|
} else if (baseOn) {
|
|
@@ -20665,29 +20610,66 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
|
|
|
20665
20610
|
}
|
|
20666
20611
|
const result = {};
|
|
20667
20612
|
for (const bank of allBanks) {
|
|
20668
|
-
const key = bank
|
|
20613
|
+
const key = toKey(bank);
|
|
20669
20614
|
const impact = {};
|
|
20670
|
-
if (!
|
|
20671
|
-
impact.borrowImpact = simulate(
|
|
20615
|
+
if (!activeCollateral.some((x) => x.equals(bank))) {
|
|
20616
|
+
impact.borrowImpact = simulate(bank, "borrow");
|
|
20672
20617
|
}
|
|
20673
|
-
|
|
20674
|
-
|
|
20618
|
+
const collSet = new Set(emodePairs.flatMap((p) => p.collateralBanks.map((c) => c.toBase58())));
|
|
20619
|
+
if (collSet.has(key) && !activeCollateral.some((x) => x.equals(bank)) && !activeLiabilities.some((x) => x.equals(bank))) {
|
|
20620
|
+
impact.supplyImpact = simulate(bank, "supply");
|
|
20675
20621
|
}
|
|
20676
|
-
if (
|
|
20677
|
-
impact.repayAllImpact = simulate(
|
|
20622
|
+
if (activeLiabilities.some((x) => x.equals(bank))) {
|
|
20623
|
+
impact.repayAllImpact = simulate(bank, "repay");
|
|
20678
20624
|
}
|
|
20679
|
-
if (
|
|
20680
|
-
impact.withdrawAllImpact = simulate(
|
|
20625
|
+
if (activeCollateral.some((x) => x.equals(bank))) {
|
|
20626
|
+
impact.withdrawAllImpact = simulate(bank, "withdraw");
|
|
20681
20627
|
}
|
|
20682
20628
|
result[key] = impact;
|
|
20683
20629
|
}
|
|
20684
20630
|
return result;
|
|
20685
20631
|
}
|
|
20686
20632
|
function computeActiveEmodePairs(emodePairs, activeLiabilities, activeCollateral) {
|
|
20687
|
-
const
|
|
20688
|
-
|
|
20689
|
-
|
|
20690
|
-
|
|
20633
|
+
const configured = emodePairs.filter(
|
|
20634
|
+
(p) => p.collateralBankTag !== 0 /* UNSET */ && p.liabilityBankTag !== 0 /* UNSET */
|
|
20635
|
+
);
|
|
20636
|
+
const liabTagByBank = /* @__PURE__ */ new Map();
|
|
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();
|
|
20691
20673
|
}
|
|
20692
20674
|
function computeBalanceUsdValue(params) {
|
|
20693
20675
|
const {
|