@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.js
CHANGED
|
@@ -20501,72 +20501,16 @@ function createActiveEmodePairFromPairs(pairs) {
|
|
|
20501
20501
|
assetWeightInit: bestPair.assetWeightInit
|
|
20502
20502
|
};
|
|
20503
20503
|
}
|
|
20504
|
-
function indexConfiguredPairs(emodePairs) {
|
|
20505
|
-
const configured = [];
|
|
20506
|
-
const liabTagByBank = /* @__PURE__ */ new Map();
|
|
20507
|
-
for (const p of emodePairs) {
|
|
20508
|
-
if (p.collateralBankTag === 0 /* UNSET */ || p.liabilityBankTag === 0 /* UNSET */) {
|
|
20509
|
-
continue;
|
|
20510
|
-
}
|
|
20511
|
-
const liabStr = p.liabilityBank.toBase58();
|
|
20512
|
-
const liabTagStr = p.liabilityBankTag.toString();
|
|
20513
|
-
configured.push({
|
|
20514
|
-
orig: p,
|
|
20515
|
-
liabStr,
|
|
20516
|
-
liabTagStr,
|
|
20517
|
-
collTagStr: p.collateralBankTag.toString(),
|
|
20518
|
-
collStrs: p.collateralBanks.map((b) => b.toBase58())
|
|
20519
|
-
});
|
|
20520
|
-
liabTagByBank.set(liabStr, liabTagStr);
|
|
20521
|
-
}
|
|
20522
|
-
return { configured, liabTagByBank };
|
|
20523
|
-
}
|
|
20524
|
-
function activePairsFromIndex(configured, liabTagByBank, liabSet, collSet) {
|
|
20525
|
-
const requiredTags = /* @__PURE__ */ new Set();
|
|
20526
|
-
for (const liab of liabSet) {
|
|
20527
|
-
const tag = liabTagByBank.get(liab);
|
|
20528
|
-
if (!tag) return [];
|
|
20529
|
-
requiredTags.add(tag);
|
|
20530
|
-
}
|
|
20531
|
-
const possible = configured.filter(
|
|
20532
|
-
(p) => liabSet.has(p.liabStr) && p.collStrs.some((c) => collSet.has(c))
|
|
20533
|
-
);
|
|
20534
|
-
if (possible.length === 0) return [];
|
|
20535
|
-
const byCollTag = {};
|
|
20536
|
-
for (const p of possible) {
|
|
20537
|
-
(byCollTag[p.collTagStr] ||= []).push(p);
|
|
20538
|
-
}
|
|
20539
|
-
const validGroups = [];
|
|
20540
|
-
for (const group of Object.values(byCollTag)) {
|
|
20541
|
-
const supports = new Set(group.map((p) => p.liabTagStr));
|
|
20542
|
-
let coversAll = true;
|
|
20543
|
-
for (const rt of requiredTags) {
|
|
20544
|
-
if (!supports.has(rt)) {
|
|
20545
|
-
coversAll = false;
|
|
20546
|
-
break;
|
|
20547
|
-
}
|
|
20548
|
-
}
|
|
20549
|
-
if (coversAll) validGroups.push(group);
|
|
20550
|
-
}
|
|
20551
|
-
if (validGroups.length === 0) return [];
|
|
20552
|
-
return validGroups.flat().map((p) => p.orig);
|
|
20553
|
-
}
|
|
20554
20504
|
function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, allBanks) {
|
|
20555
|
-
const
|
|
20556
|
-
const
|
|
20557
|
-
const
|
|
20558
|
-
const
|
|
20559
|
-
for (const p of emodePairs) {
|
|
20560
|
-
liabTagMapAll.set(p.liabilityBank.toBase58(), p.liabilityBankTag.toString());
|
|
20561
|
-
}
|
|
20562
|
-
const allCollateralBankStrs = /* @__PURE__ */ new Set();
|
|
20505
|
+
const toKey = (k) => k.toBase58();
|
|
20506
|
+
const basePairs = computeActiveEmodePairs(emodePairs, activeLiabilities, activeCollateral);
|
|
20507
|
+
const baseOn = basePairs.length > 0;
|
|
20508
|
+
const liabTagMap = /* @__PURE__ */ new Map();
|
|
20563
20509
|
for (const p of emodePairs) {
|
|
20564
|
-
|
|
20510
|
+
liabTagMap.set(p.liabilityBank.toBase58(), p.liabilityBankTag.toString());
|
|
20565
20511
|
}
|
|
20566
|
-
const basePairs = activePairsFromIndex(configured, liabTagByBank, liabBaseSet, collBaseSet);
|
|
20567
|
-
const baseOn = basePairs.length > 0;
|
|
20568
20512
|
const existingTags = new Set(
|
|
20569
|
-
|
|
20513
|
+
activeLiabilities.map((l) => liabTagMap.get(l.toBase58())).filter((t) => !!t)
|
|
20570
20514
|
);
|
|
20571
20515
|
function minWeight(ps) {
|
|
20572
20516
|
let m = ps[0].assetWeightInit;
|
|
@@ -20583,26 +20527,27 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
|
|
|
20583
20527
|
if (aMin.lt(bMin)) return 3 /* ReduceEmode */;
|
|
20584
20528
|
return 1 /* ExtendEmode */;
|
|
20585
20529
|
}
|
|
20586
|
-
function simulate(
|
|
20587
|
-
|
|
20530
|
+
function simulate(bank, action) {
|
|
20531
|
+
bank.equals(new PublicKey("CCKtUs6Cgwo4aaQUmBPmyoApH2gUDErxNZCAntD6LYGh"));
|
|
20532
|
+
let L = [...activeLiabilities], C = [...activeCollateral];
|
|
20588
20533
|
switch (action) {
|
|
20589
20534
|
case "borrow":
|
|
20590
|
-
L.
|
|
20535
|
+
if (!L.some((x) => x.equals(bank))) L.push(bank);
|
|
20591
20536
|
break;
|
|
20592
20537
|
case "repay":
|
|
20593
|
-
L.
|
|
20538
|
+
L = L.filter((x) => !x.equals(bank));
|
|
20594
20539
|
break;
|
|
20595
20540
|
case "supply":
|
|
20596
|
-
C.
|
|
20541
|
+
if (!C.some((x) => x.equals(bank))) C.push(bank);
|
|
20597
20542
|
break;
|
|
20598
20543
|
case "withdraw":
|
|
20599
|
-
C.
|
|
20544
|
+
C = C.filter((x) => !x.equals(bank));
|
|
20600
20545
|
break;
|
|
20601
20546
|
}
|
|
20602
|
-
const after =
|
|
20547
|
+
const after = computeActiveEmodePairs(emodePairs, L, C);
|
|
20603
20548
|
let status = diffState(basePairs, after);
|
|
20604
20549
|
if (action === "borrow") {
|
|
20605
|
-
const tag =
|
|
20550
|
+
const tag = liabTagMap.get(bank.toBase58());
|
|
20606
20551
|
if (!tag) {
|
|
20607
20552
|
status = baseOn ? 4 /* RemoveEmode */ : 5 /* InactiveEmode */;
|
|
20608
20553
|
} else if (baseOn) {
|
|
@@ -20638,29 +20583,66 @@ function computeEmodeImpacts(emodePairs, activeLiabilities, activeCollateral, al
|
|
|
20638
20583
|
}
|
|
20639
20584
|
const result = {};
|
|
20640
20585
|
for (const bank of allBanks) {
|
|
20641
|
-
const key = bank
|
|
20586
|
+
const key = toKey(bank);
|
|
20642
20587
|
const impact = {};
|
|
20643
|
-
if (!
|
|
20644
|
-
impact.borrowImpact = simulate(
|
|
20588
|
+
if (!activeCollateral.some((x) => x.equals(bank))) {
|
|
20589
|
+
impact.borrowImpact = simulate(bank, "borrow");
|
|
20645
20590
|
}
|
|
20646
|
-
|
|
20647
|
-
|
|
20591
|
+
const collSet = new Set(emodePairs.flatMap((p) => p.collateralBanks.map((c) => c.toBase58())));
|
|
20592
|
+
if (collSet.has(key) && !activeCollateral.some((x) => x.equals(bank)) && !activeLiabilities.some((x) => x.equals(bank))) {
|
|
20593
|
+
impact.supplyImpact = simulate(bank, "supply");
|
|
20648
20594
|
}
|
|
20649
|
-
if (
|
|
20650
|
-
impact.repayAllImpact = simulate(
|
|
20595
|
+
if (activeLiabilities.some((x) => x.equals(bank))) {
|
|
20596
|
+
impact.repayAllImpact = simulate(bank, "repay");
|
|
20651
20597
|
}
|
|
20652
|
-
if (
|
|
20653
|
-
impact.withdrawAllImpact = simulate(
|
|
20598
|
+
if (activeCollateral.some((x) => x.equals(bank))) {
|
|
20599
|
+
impact.withdrawAllImpact = simulate(bank, "withdraw");
|
|
20654
20600
|
}
|
|
20655
20601
|
result[key] = impact;
|
|
20656
20602
|
}
|
|
20657
20603
|
return result;
|
|
20658
20604
|
}
|
|
20659
20605
|
function computeActiveEmodePairs(emodePairs, activeLiabilities, activeCollateral) {
|
|
20660
|
-
const
|
|
20661
|
-
|
|
20662
|
-
|
|
20663
|
-
|
|
20606
|
+
const configured = emodePairs.filter(
|
|
20607
|
+
(p) => p.collateralBankTag !== 0 /* UNSET */ && p.liabilityBankTag !== 0 /* UNSET */
|
|
20608
|
+
);
|
|
20609
|
+
const liabTagByBank = /* @__PURE__ */ new Map();
|
|
20610
|
+
for (const p of configured) {
|
|
20611
|
+
liabTagByBank.set(p.liabilityBank.toBase58(), p.liabilityBankTag.toString());
|
|
20612
|
+
}
|
|
20613
|
+
const requiredTags = /* @__PURE__ */ new Set();
|
|
20614
|
+
for (const liab of activeLiabilities) {
|
|
20615
|
+
const tag = liabTagByBank.get(liab.toBase58());
|
|
20616
|
+
if (!tag) {
|
|
20617
|
+
return [];
|
|
20618
|
+
}
|
|
20619
|
+
requiredTags.add(tag);
|
|
20620
|
+
}
|
|
20621
|
+
const possible = configured.filter(
|
|
20622
|
+
(p) => activeLiabilities.some((l) => l.equals(p.liabilityBank)) && p.collateralBanks.some((c) => activeCollateral.some((a) => a.equals(c)))
|
|
20623
|
+
);
|
|
20624
|
+
if (possible.length === 0) return [];
|
|
20625
|
+
const byCollTag = {};
|
|
20626
|
+
for (const p of possible) {
|
|
20627
|
+
const ct = p.collateralBankTag.toString();
|
|
20628
|
+
(byCollTag[ct] ||= []).push(p);
|
|
20629
|
+
}
|
|
20630
|
+
const validGroups = [];
|
|
20631
|
+
for (const group of Object.values(byCollTag)) {
|
|
20632
|
+
const supports = new Set(group.map((p) => p.liabilityBankTag.toString()));
|
|
20633
|
+
let coversAll = true;
|
|
20634
|
+
for (const rt of requiredTags) {
|
|
20635
|
+
if (!supports.has(rt)) {
|
|
20636
|
+
coversAll = false;
|
|
20637
|
+
break;
|
|
20638
|
+
}
|
|
20639
|
+
}
|
|
20640
|
+
if (coversAll) {
|
|
20641
|
+
validGroups.push(group);
|
|
20642
|
+
}
|
|
20643
|
+
}
|
|
20644
|
+
if (validGroups.length === 0) return [];
|
|
20645
|
+
return validGroups.flat();
|
|
20664
20646
|
}
|
|
20665
20647
|
function computeBalanceUsdValue(params) {
|
|
20666
20648
|
const {
|