@0dotxyz/p0-ts-sdk 2.10.0-alpha.0 → 2.10.0-alpha.1
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 +33 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -4
- package/dist/index.d.ts +36 -4
- package/dist/index.js +33 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -76376,11 +76376,22 @@ function computePremiumRatesByBank(params) {
|
|
|
76376
76376
|
const rates = /* @__PURE__ */ new Map();
|
|
76377
76377
|
for (const [bankKey, bank] of params.banksMap) {
|
|
76378
76378
|
if (bank.premiumActive) {
|
|
76379
|
-
rates.set(
|
|
76379
|
+
rates.set(
|
|
76380
|
+
bankKey,
|
|
76381
|
+
breakdownPremium(collateral, params.premiumEntries, bank.premiumTag).reduce(
|
|
76382
|
+
(rate, row) => rate.plus(row.contributionApr),
|
|
76383
|
+
new BigNumber3.BigNumber(0)
|
|
76384
|
+
)
|
|
76385
|
+
);
|
|
76380
76386
|
}
|
|
76381
76387
|
}
|
|
76382
76388
|
return rates;
|
|
76383
76389
|
}
|
|
76390
|
+
function computePremiumBreakdown(params, liabilityBank) {
|
|
76391
|
+
const bank = params.banksMap.get(liabilityBank.toBase58());
|
|
76392
|
+
if (!bank?.premiumActive) return [];
|
|
76393
|
+
return breakdownPremium(computePremiumCollateral(params), params.premiumEntries, bank.premiumTag);
|
|
76394
|
+
}
|
|
76384
76395
|
function computePremiumImpact(params) {
|
|
76385
76396
|
const { activeBalances, banksMap, oraclePricesByBank, premiumEntries, actions } = params;
|
|
76386
76397
|
const nowSeconds = Date.now() / 1e3;
|
|
@@ -76416,6 +76427,7 @@ function computePremiumImpact(params) {
|
|
|
76416
76427
|
);
|
|
76417
76428
|
const usd = collateral.get(bankKey)?.usd ?? new BigNumber3.BigNumber(0);
|
|
76418
76429
|
collateral.set(bankKey, {
|
|
76430
|
+
bank: action.bank,
|
|
76419
76431
|
tag: bank.premiumTag,
|
|
76420
76432
|
usd: action.type === "deposit" ? usd.plus(delta) : BigNumber3.BigNumber.max(0, usd.minus(delta))
|
|
76421
76433
|
});
|
|
@@ -76453,8 +76465,9 @@ function computePremiumImpact(params) {
|
|
|
76453
76465
|
const liabilities = /* @__PURE__ */ new Map();
|
|
76454
76466
|
const debtsAfter = [];
|
|
76455
76467
|
for (const [bankKey, debt] of debts) {
|
|
76456
|
-
const
|
|
76457
|
-
|
|
76468
|
+
const breakdown = breakdownPremium(collateral, premiumEntries, debt.bank.premiumTag);
|
|
76469
|
+
const after = breakdown.reduce((rate, row) => rate.plus(row.contributionApr), new BigNumber3.BigNumber(0));
|
|
76470
|
+
liabilities.set(bankKey, { before: debt.storedRate, after, breakdown });
|
|
76458
76471
|
debtsAfter.push({ ...debt, rate: after });
|
|
76459
76472
|
}
|
|
76460
76473
|
return {
|
|
@@ -76484,6 +76497,7 @@ function computePremiumCollateral({
|
|
|
76484
76497
|
continue;
|
|
76485
76498
|
}
|
|
76486
76499
|
collateral.set(bankKey, {
|
|
76500
|
+
bank: balance.bankPk,
|
|
76487
76501
|
tag: bank.premiumTag,
|
|
76488
76502
|
usd: computeUsdValue({
|
|
76489
76503
|
bank,
|
|
@@ -76497,17 +76511,15 @@ function computePremiumCollateral({
|
|
|
76497
76511
|
}
|
|
76498
76512
|
return collateral;
|
|
76499
76513
|
}
|
|
76500
|
-
function
|
|
76501
|
-
|
|
76502
|
-
|
|
76503
|
-
|
|
76514
|
+
function breakdownPremium(collateral, premiumEntries, liabilityTag) {
|
|
76515
|
+
const counted = [...collateral.values()].filter(({ usd }) => usd.gt(0));
|
|
76516
|
+
const totalUsd = counted.reduce((sum, { usd }) => sum.plus(usd), new BigNumber3.BigNumber(0));
|
|
76517
|
+
return counted.map(({ bank, tag, usd }) => {
|
|
76504
76518
|
const pairRate = premiumEntries.find(
|
|
76505
76519
|
(entry) => entry.collateralTag === tag && entry.liabilityTag === liabilityTag
|
|
76506
|
-
)?.rate;
|
|
76507
|
-
|
|
76508
|
-
|
|
76509
|
-
}
|
|
76510
|
-
return totalUsd.gt(0) ? weightedUsd.div(totalUsd) : new BigNumber3.BigNumber(0);
|
|
76520
|
+
)?.rate ?? new BigNumber3.BigNumber(0);
|
|
76521
|
+
return { bank, tag, usd, pairRate, contributionApr: usd.times(pairRate).div(totalUsd) };
|
|
76522
|
+
});
|
|
76511
76523
|
}
|
|
76512
76524
|
function sumAnnualPremiumUsd(debts, oraclePricesByBank) {
|
|
76513
76525
|
return debts.reduce((sum, { bank, principal, rate }) => {
|
|
@@ -87986,7 +87998,7 @@ var MarginfiGroup = class _MarginfiGroup {
|
|
|
87986
87998
|
// ----------------------------------------------------------------------------
|
|
87987
87999
|
static fromAccountParsed(address, accountData) {
|
|
87988
88000
|
const rateLimiter = accountData.rateLimiter ? parseBankRateLimiterRaw(accountData.rateLimiter) : void 0;
|
|
87989
|
-
const premiumEntries =
|
|
88001
|
+
const premiumEntries = accountData.premiumEntries.slice(0, accountData.premiumSettings.entryCount).map((entry) => ({ ...entry, rate: rateFromU32(entry.rate) }));
|
|
87990
88002
|
return new _MarginfiGroup(accountData.admin, address, rateLimiter, premiumEntries);
|
|
87991
88003
|
}
|
|
87992
88004
|
static fromBuffer(address, rawData, idl) {
|
|
@@ -88760,6 +88772,13 @@ var MarginfiAccountWrapper = class {
|
|
|
88760
88772
|
getPremiumRatesByBank() {
|
|
88761
88773
|
return computePremiumRatesByBank(this.premiumRateParams());
|
|
88762
88774
|
}
|
|
88775
|
+
/**
|
|
88776
|
+
* Per-collateral breakdown of the premium rate `liabilityBank` would charge this account.
|
|
88777
|
+
* See {@link computePremiumBreakdown}.
|
|
88778
|
+
*/
|
|
88779
|
+
getPremiumBreakdown(liabilityBank) {
|
|
88780
|
+
return computePremiumBreakdown(this.premiumRateParams(), liabilityBank);
|
|
88781
|
+
}
|
|
88763
88782
|
/**
|
|
88764
88783
|
* How `actions` would change this account's premium rates and yearly premium.
|
|
88765
88784
|
* See {@link computePremiumImpact}.
|
|
@@ -89472,6 +89491,7 @@ exports.computeMaxWithdrawForBank = computeMaxWithdrawForBank;
|
|
|
89472
89491
|
exports.computeNetApy = computeNetApy;
|
|
89473
89492
|
exports.computeOracleMultiplier = computeOracleMultiplier;
|
|
89474
89493
|
exports.computeOracleMultipliers = computeOracleMultipliers;
|
|
89494
|
+
exports.computePremiumBreakdown = computePremiumBreakdown;
|
|
89475
89495
|
exports.computePremiumImpact = computePremiumImpact;
|
|
89476
89496
|
exports.computePremiumRatesByBank = computePremiumRatesByBank;
|
|
89477
89497
|
exports.computeProjectedActiveBalancesNoCpi = computeProjectedActiveBalancesNoCpi;
|