@0dotxyz/p0-ts-sdk 2.7.1-alpha.0 → 2.7.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/README.md +2 -9
- package/dist/index.cjs +30 -216
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -184
- package/dist/index.d.ts +9 -184
- package/dist/index.js +31 -203
- package/dist/index.js.map +1 -1
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.d.cts +1 -1
- package/dist/instructions.d.ts +1 -1
- package/dist/instructions.js.map +1 -1
- package/dist/{types-B5SGXpex.d.ts → types-Ctm1kvCr.d.ts} +1 -1
- package/dist/{types-BFLi0Ozl.d.cts → types-DzbVhEfo.d.cts} +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -98,7 +98,7 @@ console.log(`Compute units: ${simulation.value.unitsConsumed}`);
|
|
|
98
98
|
### 5. Borrow Against Collateral
|
|
99
99
|
|
|
100
100
|
```typescript
|
|
101
|
-
// Check how much you can borrow
|
|
101
|
+
// Check how much you can borrow
|
|
102
102
|
const maxBorrow = wrappedAccount.computeMaxBorrowForBank(usdcBank.address);
|
|
103
103
|
console.log(`Max borrow: $${maxBorrow.toString()}`);
|
|
104
104
|
|
|
@@ -289,16 +289,9 @@ const health = wrapped.computeHealthComponents(
|
|
|
289
289
|
MarginRequirementType.Initial // or Maintenance
|
|
290
290
|
);
|
|
291
291
|
|
|
292
|
-
// Max amounts
|
|
293
|
-
// borrow = min(health-based, remaining borrow cap, available bank liquidity, rate-limit headroom)
|
|
294
|
-
// withdraw = min(health-based, available bank liquidity, rate-limit headroom)
|
|
295
|
-
// deposit = remaining deposit cap (optionally min'd with your wallet balance)
|
|
296
|
-
// (rate-limit headroom = bank net-outflow limiter in tokens + group USD limiter, if enabled)
|
|
292
|
+
// Max amounts
|
|
297
293
|
const maxBorrow = wrapped.computeMaxBorrowForBank(bankAddress);
|
|
298
294
|
const maxWithdraw = wrapped.computeMaxWithdrawForBank(bankAddress);
|
|
299
|
-
const maxDeposit = wrapped.computeMaxDepositForBank(bankAddress, { walletBalance: 1_000 });
|
|
300
|
-
|
|
301
|
-
// Pass { ignoreBankLimits: true } to get the purely health-based borrow/withdraw amount
|
|
302
295
|
```
|
|
303
296
|
|
|
304
297
|
## 🧪 Testing
|
package/dist/index.cjs
CHANGED
|
@@ -69509,6 +69509,7 @@ function makeEndFlashLoanIx2(programId, accounts, remainingAccounts = []) {
|
|
|
69509
69509
|
{ pubkey: accounts.group, isSigner: false, isWritable: false },
|
|
69510
69510
|
{ pubkey: accounts.authority, isSigner: true, isWritable: false }
|
|
69511
69511
|
];
|
|
69512
|
+
if (!isMarginfiV0110Live(programId)) keys.splice(1, 1);
|
|
69512
69513
|
keys.push(...remainingAccounts);
|
|
69513
69514
|
return new web3_js.TransactionInstruction({
|
|
69514
69515
|
keys,
|
|
@@ -69718,6 +69719,7 @@ function makePulseHealthIx3(programId, accounts, remainingAccounts = []) {
|
|
|
69718
69719
|
{ pubkey: accounts.marginfiAccount, isSigner: false, isWritable: true },
|
|
69719
69720
|
{ pubkey: accounts.group, isSigner: false, isWritable: false }
|
|
69720
69721
|
];
|
|
69722
|
+
if (!isMarginfiV0110Live(programId)) keys.splice(1, 1);
|
|
69721
69723
|
keys.push(...remainingAccounts);
|
|
69722
69724
|
return new web3_js.TransactionInstruction({
|
|
69723
69725
|
keys,
|
|
@@ -69737,6 +69739,7 @@ function makeAccountTransferToNewAccountIx2(programId, accounts) {
|
|
|
69737
69739
|
{ pubkey: accounts.feeState, isSigner: false, isWritable: false },
|
|
69738
69740
|
{ pubkey: web3_js.SystemProgram.programId, isSigner: false, isWritable: false }
|
|
69739
69741
|
];
|
|
69742
|
+
if (!isMarginfiV0110Live(programId)) keys.splice(7, 1);
|
|
69740
69743
|
return new web3_js.TransactionInstruction({
|
|
69741
69744
|
keys,
|
|
69742
69745
|
programId,
|
|
@@ -73885,20 +73888,6 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
73885
73888
|
...params
|
|
73886
73889
|
});
|
|
73887
73890
|
}
|
|
73888
|
-
/**
|
|
73889
|
-
* Calculates the maximum amount that can be deposited into a bank.
|
|
73890
|
-
*
|
|
73891
|
-
* Deposits are not constrained by account health, only by the bank's remaining deposit cap
|
|
73892
|
-
* and (optionally) the wallet balance.
|
|
73893
|
-
*
|
|
73894
|
-
* @param params - Configuration for max deposit computation
|
|
73895
|
-
* @returns Maximum depositable amount in UI units
|
|
73896
|
-
*
|
|
73897
|
-
* @see {@link computeMaxDepositForBank} for implementation details
|
|
73898
|
-
*/
|
|
73899
|
-
computeMaxDepositForBank(params) {
|
|
73900
|
-
return computeMaxDepositForBank(params);
|
|
73901
|
-
}
|
|
73902
73891
|
/**
|
|
73903
73892
|
* Gets the banks required for health check calculations.
|
|
73904
73893
|
*
|
|
@@ -77758,9 +77747,7 @@ function computeMaxBorrowForBank(params) {
|
|
|
77758
77747
|
assetShareValueMultiplierByBank,
|
|
77759
77748
|
emodeImpactStatus,
|
|
77760
77749
|
volatilityFactor,
|
|
77761
|
-
activePair
|
|
77762
|
-
groupRateLimiter,
|
|
77763
|
-
ignoreBankLimits
|
|
77750
|
+
activePair
|
|
77764
77751
|
} = params;
|
|
77765
77752
|
const bank = banksMap.get(bankAddress.toBase58());
|
|
77766
77753
|
if (!bank) throw Error(`Bank ${bankAddress.toBase58()} not found`);
|
|
@@ -77820,63 +77807,15 @@ function computeMaxBorrowForBank(params) {
|
|
|
77820
77807
|
assetShareValueMultiplier
|
|
77821
77808
|
});
|
|
77822
77809
|
const liabWeight = getLiabilityWeight(bank.config, 0 /* Initial */);
|
|
77823
|
-
|
|
77824
|
-
bank.
|
|
77825
|
-
|
|
77826
|
-
|
|
77827
|
-
|
|
77828
|
-
freeCollateral.minus(untiedCollateralForBank).div(
|
|
77829
|
-
) : untiedCollateralForBank.div(priceLowestBias.times(assetWeight)).plus(freeCollateral.minus(untiedCollateralForBank).div(liabPriceWeighted));
|
|
77830
|
-
if (ignoreBankLimits) return healthMaxBorrow;
|
|
77831
|
-
const borrowCapRemaining = new BigNumber3__default.default(computeBankBorrowCapRemaining(bank)).div(
|
|
77832
|
-
originationFeeFactor
|
|
77833
|
-
);
|
|
77834
|
-
const availableLiquidity = computeBankProjectedAvailableLiquidity(
|
|
77835
|
-
bank,
|
|
77836
|
-
assetShareValueMultiplier
|
|
77837
|
-
).div(originationFeeFactor);
|
|
77838
|
-
const rateLimitRemaining = computeOutflowRateLimitRemaining(bank, oraclePrice, groupRateLimiter);
|
|
77839
|
-
return BigNumber3__default.default.max(
|
|
77840
|
-
0,
|
|
77841
|
-
BigNumber3__default.default.min(healthMaxBorrow, borrowCapRemaining, availableLiquidity, rateLimitRemaining)
|
|
77842
|
-
);
|
|
77843
|
-
}
|
|
77844
|
-
function computeOutflowRateLimitRemaining(bank, oraclePrice, groupRateLimiter) {
|
|
77845
|
-
const nowSeconds = Date.now() / 1e3;
|
|
77846
|
-
let remaining = new BigNumber3__default.default(Infinity);
|
|
77847
|
-
const bankRemaining = computeBankRateLimitRemaining(bank, nowSeconds);
|
|
77848
|
-
if (bankRemaining !== null) remaining = BigNumber3__default.default.min(remaining, bankRemaining);
|
|
77849
|
-
const groupRemainingUsd = computeGroupRateLimitRemainingUsd(groupRateLimiter, nowSeconds);
|
|
77850
|
-
if (groupRemainingUsd !== null) {
|
|
77851
|
-
const price = getPrice(oraclePrice, 1 /* None */, false);
|
|
77852
|
-
if (price.gt(0)) remaining = BigNumber3__default.default.min(remaining, groupRemainingUsd.div(price));
|
|
77810
|
+
if (assetWeight.eq(0)) {
|
|
77811
|
+
return computeQuantityUi(balance, bank, assetShareValueMultiplier).assets.plus(
|
|
77812
|
+
freeCollateral.minus(untiedCollateralForBank).div(priceHighestBias.times(liabWeight))
|
|
77813
|
+
);
|
|
77814
|
+
} else {
|
|
77815
|
+
return untiedCollateralForBank.div(priceLowestBias.times(assetWeight)).plus(freeCollateral.minus(untiedCollateralForBank).div(priceHighestBias.times(liabWeight)));
|
|
77853
77816
|
}
|
|
77854
|
-
return remaining;
|
|
77855
77817
|
}
|
|
77856
77818
|
function computeMaxWithdrawForBank(params) {
|
|
77857
|
-
const {
|
|
77858
|
-
banksMap,
|
|
77859
|
-
bankAddress,
|
|
77860
|
-
oraclePricesByBank,
|
|
77861
|
-
assetShareValueMultiplierByBank,
|
|
77862
|
-
groupRateLimiter,
|
|
77863
|
-
ignoreBankLimits
|
|
77864
|
-
} = params;
|
|
77865
|
-
const bank = banksMap.get(bankAddress.toBase58());
|
|
77866
|
-
if (!bank) throw Error(`Bank ${bankAddress.toBase58()} not found`);
|
|
77867
|
-
const healthMaxWithdraw = computeHealthMaxWithdrawForBank(params);
|
|
77868
|
-
if (ignoreBankLimits) return healthMaxWithdraw;
|
|
77869
|
-
const oraclePrice = oraclePricesByBank.get(bankAddress.toBase58());
|
|
77870
|
-
if (!oraclePrice) throw Error(`Oracle price for ${bankAddress.toBase58()} not found`);
|
|
77871
|
-
const assetShareValueMultiplier = assetShareValueMultiplierByBank?.get(bankAddress.toBase58());
|
|
77872
|
-
const availableLiquidity = computeBankProjectedAvailableLiquidity(
|
|
77873
|
-
bank,
|
|
77874
|
-
assetShareValueMultiplier
|
|
77875
|
-
);
|
|
77876
|
-
const rateLimitRemaining = computeOutflowRateLimitRemaining(bank, oraclePrice, groupRateLimiter);
|
|
77877
|
-
return BigNumber3__default.default.max(0, BigNumber3__default.default.min(healthMaxWithdraw, availableLiquidity, rateLimitRemaining));
|
|
77878
|
-
}
|
|
77879
|
-
function computeHealthMaxWithdrawForBank(params) {
|
|
77880
77819
|
const {
|
|
77881
77820
|
account,
|
|
77882
77821
|
banksMap,
|
|
@@ -77972,17 +77911,6 @@ function computeHealthMaxWithdrawForBank(params) {
|
|
|
77972
77911
|
const maxWithdraw = initUntiedCollateralForBank.div(initWeightedPrice);
|
|
77973
77912
|
return maxWithdraw;
|
|
77974
77913
|
}
|
|
77975
|
-
function computeMaxDepositForBank(params) {
|
|
77976
|
-
const { banksMap, bankAddress, assetShareValueMultiplierByBank, walletBalance } = params;
|
|
77977
|
-
const bank = banksMap.get(bankAddress.toBase58());
|
|
77978
|
-
if (!bank) throw Error(`Bank ${bankAddress.toBase58()} not found`);
|
|
77979
|
-
const assetShareValueMultiplier = assetShareValueMultiplierByBank?.get(bankAddress.toBase58());
|
|
77980
|
-
const depositCapRemaining = new BigNumber3__default.default(computeBankDepositCapRemaining(bank)).times(
|
|
77981
|
-
assetShareValueMultiplier ?? 1
|
|
77982
|
-
);
|
|
77983
|
-
if (walletBalance === void 0) return depositCapRemaining;
|
|
77984
|
-
return BigNumber3__default.default.max(0, BigNumber3__default.default.min(depositCapRemaining, new BigNumber3__default.default(walletBalance)));
|
|
77985
|
-
}
|
|
77986
77914
|
|
|
77987
77915
|
// src/services/account/utils/misc.utils.ts
|
|
77988
77916
|
function floor(value, decimals) {
|
|
@@ -79655,21 +79583,6 @@ var fetchMultipleBanks = async (program, opts) => {
|
|
|
79655
79583
|
}
|
|
79656
79584
|
return bankDatas;
|
|
79657
79585
|
};
|
|
79658
|
-
var U64_MAX = new BigNumber3__default.default("18446744073709551615");
|
|
79659
|
-
var DRIFT_SCALED_BALANCE_DECIMALS = 9;
|
|
79660
|
-
function isDepositLimitActive(bank) {
|
|
79661
|
-
return !bank.config.depositLimit.eq(U64_MAX);
|
|
79662
|
-
}
|
|
79663
|
-
function isBorrowLimitActive(bank) {
|
|
79664
|
-
return !bank.config.borrowLimit.eq(U64_MAX);
|
|
79665
|
-
}
|
|
79666
|
-
function getEffectiveDepositLimit(bank) {
|
|
79667
|
-
const limit = bank.config.depositLimit;
|
|
79668
|
-
if (bank.config.assetTag !== 4 /* DRIFT */) return limit;
|
|
79669
|
-
const diff = DRIFT_SCALED_BALANCE_DECIMALS - bank.mintDecimals;
|
|
79670
|
-
if (diff === 0) return limit;
|
|
79671
|
-
return diff > 0 ? limit.times(10 ** diff) : limit.div(10 ** -diff);
|
|
79672
|
-
}
|
|
79673
79586
|
function computeInterestRates(bank) {
|
|
79674
79587
|
const { insuranceFeeFixedApr, insuranceIrFee, protocolFixedFeeApr, protocolIrFee } = bank.config.interestRateConfig;
|
|
79675
79588
|
const fixedFee = insuranceFeeFixedApr.plus(protocolFixedFeeApr);
|
|
@@ -79764,34 +79677,25 @@ function computeUtilizationRate(bank) {
|
|
|
79764
79677
|
return liabilities.div(assets);
|
|
79765
79678
|
}
|
|
79766
79679
|
var SECONDS_PER_DAY = 24 * 60 * 60;
|
|
79767
|
-
var SECONDS_PER_YEAR = SECONDS_PER_DAY * 365;
|
|
79768
|
-
var EXECUTION_HEADROOM_SECONDS = 120;
|
|
79769
|
-
function computeAccrualProjectionSeconds(bank, nowSeconds = Date.now() / 1e3) {
|
|
79770
|
-
const age = Math.max(0, nowSeconds - bank.lastUpdate);
|
|
79771
|
-
return Math.max(2 * age, age + EXECUTION_HEADROOM_SECONDS);
|
|
79772
|
-
}
|
|
79680
|
+
var SECONDS_PER_YEAR = SECONDS_PER_DAY * 365.25;
|
|
79773
79681
|
function computeRemainingCapacity(bank) {
|
|
79774
79682
|
const totalDeposits = getTotalAssetQuantity(bank);
|
|
79775
|
-
const remainingCapacity =
|
|
79776
|
-
0,
|
|
79777
|
-
getEffectiveDepositLimit(bank).minus(totalDeposits).minus(1).integerValue(BigNumber3__default.default.ROUND_FLOOR)
|
|
79778
|
-
) : U64_MAX;
|
|
79683
|
+
const remainingCapacity = BigNumber3__default.default.max(0, bank.config.depositLimit.minus(totalDeposits));
|
|
79779
79684
|
const totalBorrows = getTotalLiabilityQuantity(bank);
|
|
79780
|
-
const remainingBorrowCapacity =
|
|
79781
|
-
|
|
79782
|
-
bank.config.borrowLimit.minus(totalBorrows).minus(1).integerValue(BigNumber3__default.default.ROUND_FLOOR)
|
|
79783
|
-
) : U64_MAX;
|
|
79784
|
-
const projectionSeconds = computeAccrualProjectionSeconds(bank);
|
|
79685
|
+
const remainingBorrowCapacity = BigNumber3__default.default.max(0, bank.config.borrowLimit.minus(totalBorrows));
|
|
79686
|
+
const durationSinceLastAccrual = Date.now() / 1e3 - bank.lastUpdate;
|
|
79785
79687
|
const { lendingRate, borrowingRate } = computeInterestRates(bank);
|
|
79786
|
-
const
|
|
79787
|
-
const
|
|
79788
|
-
const depositCapacity = remainingCapacity.minus(
|
|
79789
|
-
const borrowCapacity = remainingBorrowCapacity.minus(
|
|
79688
|
+
const outstandingLendingInterest = lendingRate.times(durationSinceLastAccrual).dividedBy(SECONDS_PER_YEAR).times(totalDeposits);
|
|
79689
|
+
const outstandingBorrowInterest = borrowingRate.times(durationSinceLastAccrual).dividedBy(SECONDS_PER_YEAR).times(totalBorrows);
|
|
79690
|
+
const depositCapacity = remainingCapacity.minus(outstandingLendingInterest.times(2));
|
|
79691
|
+
const borrowCapacity = remainingBorrowCapacity.minus(outstandingBorrowInterest.times(2));
|
|
79790
79692
|
return {
|
|
79791
79693
|
depositCapacity,
|
|
79792
79694
|
borrowCapacity
|
|
79793
79695
|
};
|
|
79794
79696
|
}
|
|
79697
|
+
|
|
79698
|
+
// src/services/bank/utils/bank-metrics.utils.ts
|
|
79795
79699
|
function isStandardBorrowable(bank) {
|
|
79796
79700
|
const { assetTag, operationalState, borrowLimit } = bank.config;
|
|
79797
79701
|
return (assetTag === 0 /* DEFAULT */ || assetTag === 1 /* SOL */) && operationalState === "Operational" /* Operational */ && borrowLimit.gt(0);
|
|
@@ -79801,7 +79705,9 @@ function isStandardDepositable(bank) {
|
|
|
79801
79705
|
return (assetTag === 0 /* DEFAULT */ || assetTag === 1 /* SOL */) && operationalState === "Operational" /* Operational */;
|
|
79802
79706
|
}
|
|
79803
79707
|
function computeBankTotalDeposits(bank, assetShareValueMultiplier) {
|
|
79804
|
-
const totalAssets = getTotalAssetQuantity(bank).times(
|
|
79708
|
+
const totalAssets = getTotalAssetQuantity(bank).times(
|
|
79709
|
+
assetShareValueMultiplier ?? 1
|
|
79710
|
+
);
|
|
79805
79711
|
return nativeToUi(totalAssets, bank.mintDecimals);
|
|
79806
79712
|
}
|
|
79807
79713
|
function computeBankTotalBorrows(bank) {
|
|
@@ -79832,35 +79738,14 @@ function computeBankPoolSize(bank, assetShareValueMultiplier) {
|
|
|
79832
79738
|
const borrowCap = nativeToUi(bank.config.borrowLimit, bank.mintDecimals);
|
|
79833
79739
|
return Math.max(0, Math.min(totalDeposits, borrowCap) - totalBorrows);
|
|
79834
79740
|
}
|
|
79835
|
-
function computeBankAvailableLiquidity(bank, assetShareValueMultiplier) {
|
|
79836
|
-
const totalDeposits = computeBankTotalDeposits(bank, assetShareValueMultiplier);
|
|
79837
|
-
const totalBorrows = computeBankTotalBorrows(bank);
|
|
79838
|
-
return BigNumber3__default.default.max(0, new BigNumber3__default.default(totalDeposits).minus(totalBorrows));
|
|
79839
|
-
}
|
|
79840
79741
|
function computeBankDepositCapRemaining(bank) {
|
|
79841
|
-
if (!isDepositLimitActive(bank)) return Infinity;
|
|
79842
79742
|
const { depositCapacity } = computeRemainingCapacity(bank);
|
|
79843
79743
|
return Math.max(0, nativeToUi(depositCapacity, bank.mintDecimals));
|
|
79844
79744
|
}
|
|
79845
79745
|
function computeBankBorrowCapRemaining(bank) {
|
|
79846
|
-
if (!isBorrowLimitActive(bank)) return Infinity;
|
|
79847
79746
|
const { borrowCapacity } = computeRemainingCapacity(bank);
|
|
79848
79747
|
return Math.max(0, nativeToUi(borrowCapacity, bank.mintDecimals));
|
|
79849
79748
|
}
|
|
79850
|
-
function computeBankProjectedAvailableLiquidity(bank, assetShareValueMultiplier) {
|
|
79851
|
-
const liquidity = computeBankAvailableLiquidity(bank, assetShareValueMultiplier);
|
|
79852
|
-
const totalDeposits = computeBankTotalDeposits(bank, assetShareValueMultiplier);
|
|
79853
|
-
const totalBorrows = computeBankTotalBorrows(bank);
|
|
79854
|
-
const projectionYears = computeAccrualProjectionSeconds(bank) / SECONDS_PER_YEAR;
|
|
79855
|
-
const { lendingRate, borrowingRate } = computeInterestRates(bank);
|
|
79856
|
-
const projectedBorrowInterest = borrowingRate.times(totalBorrows).times(projectionYears);
|
|
79857
|
-
const projectedLendingInterest = lendingRate.times(totalDeposits).times(projectionYears);
|
|
79858
|
-
const liquidityLostToAccrual = BigNumber3__default.default.max(
|
|
79859
|
-
0,
|
|
79860
|
-
projectedBorrowInterest.minus(projectedLendingInterest)
|
|
79861
|
-
);
|
|
79862
|
-
return BigNumber3__default.default.max(0, liquidity.minus(liquidityLostToAccrual));
|
|
79863
|
-
}
|
|
79864
79749
|
function computeBankSupplyApy(bank) {
|
|
79865
79750
|
return aprToApy(computeInterestRates(bank).lendingRate.toNumber());
|
|
79866
79751
|
}
|
|
@@ -79873,7 +79758,11 @@ function computeBankMetrics(params) {
|
|
|
79873
79758
|
symbol,
|
|
79874
79759
|
totalDeposits: computeBankTotalDeposits(bank, assetShareValueMultiplier),
|
|
79875
79760
|
totalBorrows: computeBankTotalBorrows(bank),
|
|
79876
|
-
totalDepositsUsd: computeBankTotalDepositsUsd(
|
|
79761
|
+
totalDepositsUsd: computeBankTotalDepositsUsd(
|
|
79762
|
+
bank,
|
|
79763
|
+
oraclePrice,
|
|
79764
|
+
assetShareValueMultiplier
|
|
79765
|
+
),
|
|
79877
79766
|
totalBorrowsUsd: computeBankTotalBorrowsUsd(bank, oraclePrice),
|
|
79878
79767
|
utilizationRate: computeUtilizationRate(bank).toNumber(),
|
|
79879
79768
|
poolSize: computeBankPoolSize(bank, assetShareValueMultiplier),
|
|
@@ -79901,47 +79790,6 @@ function requireTokenProgram(tokenProgramsByBank, address, makeError = (message)
|
|
|
79901
79790
|
}
|
|
79902
79791
|
return tokenProgram;
|
|
79903
79792
|
}
|
|
79904
|
-
function computeRateLimitWindowRemainingCapacity(window, nowSeconds) {
|
|
79905
|
-
const { maxOutflow, windowDuration } = window;
|
|
79906
|
-
if (maxOutflow.lte(0)) return null;
|
|
79907
|
-
if (windowDuration === 0) return maxOutflow;
|
|
79908
|
-
let { windowStart, prevWindowOutflow, curWindowOutflow } = window;
|
|
79909
|
-
const elapsedRaw = Math.floor(nowSeconds) - windowStart;
|
|
79910
|
-
if (elapsedRaw >= windowDuration * 2) {
|
|
79911
|
-
windowStart = Math.floor(nowSeconds);
|
|
79912
|
-
prevWindowOutflow = new BigNumber3__default.default(0);
|
|
79913
|
-
curWindowOutflow = new BigNumber3__default.default(0);
|
|
79914
|
-
} else if (elapsedRaw >= windowDuration) {
|
|
79915
|
-
windowStart = windowStart + windowDuration;
|
|
79916
|
-
prevWindowOutflow = curWindowOutflow;
|
|
79917
|
-
curWindowOutflow = new BigNumber3__default.default(0);
|
|
79918
|
-
}
|
|
79919
|
-
const elapsed = Math.floor(nowSeconds) - windowStart;
|
|
79920
|
-
if (elapsed < 0) return new BigNumber3__default.default(0);
|
|
79921
|
-
if (elapsed >= windowDuration) return maxOutflow;
|
|
79922
|
-
const remainingTime = windowDuration - elapsed;
|
|
79923
|
-
const weightedPrev = prevWindowOutflow.abs().times(remainingTime).idiv(windowDuration).times(prevWindowOutflow.isNegative() ? -1 : 1);
|
|
79924
|
-
const totalNetOutflow = weightedPrev.plus(curWindowOutflow);
|
|
79925
|
-
return maxOutflow.minus(totalNetOutflow);
|
|
79926
|
-
}
|
|
79927
|
-
function computeRateLimiterRemainingCapacity(rateLimiter, nowSeconds) {
|
|
79928
|
-
if (!rateLimiter) return null;
|
|
79929
|
-
const hourly = computeRateLimitWindowRemainingCapacity(rateLimiter.hourly, nowSeconds);
|
|
79930
|
-
const daily = computeRateLimitWindowRemainingCapacity(rateLimiter.daily, nowSeconds);
|
|
79931
|
-
if (hourly === null) return daily;
|
|
79932
|
-
if (daily === null) return hourly;
|
|
79933
|
-
return BigNumber3__default.default.min(hourly, daily);
|
|
79934
|
-
}
|
|
79935
|
-
function computeBankRateLimitRemaining(bank, nowSeconds = Date.now() / 1e3) {
|
|
79936
|
-
const remaining = computeRateLimiterRemainingCapacity(bank.rateLimiter, nowSeconds);
|
|
79937
|
-
if (remaining === null) return null;
|
|
79938
|
-
return BigNumber3__default.default.max(0, nativeToUi(remaining, bank.mintDecimals));
|
|
79939
|
-
}
|
|
79940
|
-
function computeGroupRateLimitRemainingUsd(rateLimiter, nowSeconds = Date.now() / 1e3) {
|
|
79941
|
-
const remaining = computeRateLimiterRemainingCapacity(rateLimiter, nowSeconds);
|
|
79942
|
-
if (remaining === null) return null;
|
|
79943
|
-
return BigNumber3__default.default.max(0, remaining);
|
|
79944
|
-
}
|
|
79945
79793
|
|
|
79946
79794
|
// src/services/bank/bank.service.ts
|
|
79947
79795
|
async function freezeBankConfigIx(program, bankAddress, bankConfigOpt) {
|
|
@@ -82766,9 +82614,7 @@ var MarginfiAccountWrapper = class {
|
|
|
82766
82614
|
assetShareValueMultiplierByBank: this.client.assetShareValueMultiplierByBank,
|
|
82767
82615
|
emodeImpactStatus: borrowImpact?.status,
|
|
82768
82616
|
activePair: borrowImpact?.activePair,
|
|
82769
|
-
volatilityFactor: opts?.volatilityFactor
|
|
82770
|
-
groupRateLimiter: this.client.group.rateLimiter,
|
|
82771
|
-
ignoreBankLimits: opts?.ignoreBankLimits
|
|
82617
|
+
volatilityFactor: opts?.volatilityFactor
|
|
82772
82618
|
});
|
|
82773
82619
|
}
|
|
82774
82620
|
/**
|
|
@@ -82786,25 +82632,7 @@ var MarginfiAccountWrapper = class {
|
|
|
82786
82632
|
bankAddress,
|
|
82787
82633
|
assetShareValueMultiplierByBank: this.client.assetShareValueMultiplierByBank,
|
|
82788
82634
|
activePair,
|
|
82789
|
-
volatilityFactor: opts?.volatilityFactor
|
|
82790
|
-
groupRateLimiter: this.client.group.rateLimiter,
|
|
82791
|
-
ignoreBankLimits: opts?.ignoreBankLimits
|
|
82792
|
-
});
|
|
82793
|
-
}
|
|
82794
|
-
/**
|
|
82795
|
-
* Computes max deposit for a bank with auto-injected client data.
|
|
82796
|
-
*
|
|
82797
|
-
* Bounded by the bank's remaining deposit cap and, if provided, the wallet balance.
|
|
82798
|
-
*
|
|
82799
|
-
* @param bankAddress - Bank address to check max deposit for
|
|
82800
|
-
* @param opts - Optional wallet balance (UI units) to cap the result
|
|
82801
|
-
*/
|
|
82802
|
-
computeMaxDepositForBank(bankAddress, opts) {
|
|
82803
|
-
return this.account.computeMaxDepositForBank({
|
|
82804
|
-
banksMap: this.client.bankMap,
|
|
82805
|
-
bankAddress,
|
|
82806
|
-
assetShareValueMultiplierByBank: this.client.assetShareValueMultiplierByBank,
|
|
82807
|
-
walletBalance: opts?.walletBalance
|
|
82635
|
+
volatilityFactor: opts?.volatilityFactor
|
|
82808
82636
|
});
|
|
82809
82637
|
}
|
|
82810
82638
|
/**
|
|
@@ -83237,7 +83065,6 @@ exports.DEFAULT_ORACLE_MAX_AGE = DEFAULT_ORACLE_MAX_AGE;
|
|
|
83237
83065
|
exports.DEFAULT_REPAY_ALL_EXTRA_BUFFER_BPS = DEFAULT_REPAY_ALL_EXTRA_BUFFER_BPS;
|
|
83238
83066
|
exports.DISABLED_FLAG = DISABLED_FLAG;
|
|
83239
83067
|
exports.EMPTY_HEALTH_CACHE = EMPTY_HEALTH_CACHE;
|
|
83240
|
-
exports.EXECUTION_HEADROOM_SECONDS = EXECUTION_HEADROOM_SECONDS;
|
|
83241
83068
|
exports.EmodeEntryFlags = EmodeEntryFlags;
|
|
83242
83069
|
exports.EmodeFlags = EmodeFlags;
|
|
83243
83070
|
exports.EmodeImpactStatus = EmodeImpactStatus;
|
|
@@ -83286,7 +83113,6 @@ exports.PYTH_SPONSORED_SHARD_ID = PYTH_SPONSORED_SHARD_ID;
|
|
|
83286
83113
|
exports.PriceBias = PriceBias;
|
|
83287
83114
|
exports.Project0Client = Project0Client;
|
|
83288
83115
|
exports.RiskTier = RiskTier;
|
|
83289
|
-
exports.SECONDS_PER_YEAR = SECONDS_PER_YEAR;
|
|
83290
83116
|
exports.SINGLE_POOL_PROGRAM_ID = SINGLE_POOL_PROGRAM_ID;
|
|
83291
83117
|
exports.STAKED_ORACLE_DISABLED_FLAG = STAKED_ORACLE_DISABLED_FLAG;
|
|
83292
83118
|
exports.STAKED_ORACLE_USES_ONRAMP_FLAG = STAKED_ORACLE_USES_ONRAMP_FLAG;
|
|
@@ -83305,7 +83131,6 @@ exports.TransactionBuildingError = TransactionBuildingError;
|
|
|
83305
83131
|
exports.TransactionBuildingErrorCode = TransactionBuildingErrorCode;
|
|
83306
83132
|
exports.TransactionConfigMap = TransactionConfigMap;
|
|
83307
83133
|
exports.TransactionType = TransactionType;
|
|
83308
|
-
exports.U64_MAX = U64_MAX;
|
|
83309
83134
|
exports.USDC_DECIMALS = USDC_DECIMALS;
|
|
83310
83135
|
exports.USDC_MINT = USDC_MINT;
|
|
83311
83136
|
exports.USDT_MINT = USDT_MINT;
|
|
@@ -83344,19 +83169,15 @@ exports.compileFlashloanPrecheck = compileFlashloanPrecheck;
|
|
|
83344
83169
|
exports.composeBridgedSwap = composeBridgedSwap;
|
|
83345
83170
|
exports.composeRemainingAccounts = composeRemainingAccounts;
|
|
83346
83171
|
exports.computeAccountValue = computeAccountValue;
|
|
83347
|
-
exports.computeAccrualProjectionSeconds = computeAccrualProjectionSeconds;
|
|
83348
83172
|
exports.computeActiveEmodePairs = computeActiveEmodePairs;
|
|
83349
83173
|
exports.computeAssetHealthComponent = computeAssetHealthComponent;
|
|
83350
83174
|
exports.computeAssetUsdValue = computeAssetUsdValue;
|
|
83351
83175
|
exports.computeBalanceUsdValue = computeBalanceUsdValue;
|
|
83352
|
-
exports.computeBankAvailableLiquidity = computeBankAvailableLiquidity;
|
|
83353
83176
|
exports.computeBankBorrowApy = computeBankBorrowApy;
|
|
83354
83177
|
exports.computeBankBorrowCapRemaining = computeBankBorrowCapRemaining;
|
|
83355
83178
|
exports.computeBankDepositCapRemaining = computeBankDepositCapRemaining;
|
|
83356
83179
|
exports.computeBankMetrics = computeBankMetrics;
|
|
83357
83180
|
exports.computeBankPoolSize = computeBankPoolSize;
|
|
83358
|
-
exports.computeBankProjectedAvailableLiquidity = computeBankProjectedAvailableLiquidity;
|
|
83359
|
-
exports.computeBankRateLimitRemaining = computeBankRateLimitRemaining;
|
|
83360
83181
|
exports.computeBankSupplyApy = computeBankSupplyApy;
|
|
83361
83182
|
exports.computeBankTotalBorrows = computeBankTotalBorrows;
|
|
83362
83183
|
exports.computeBankTotalBorrowsUsd = computeBankTotalBorrowsUsd;
|
|
@@ -83371,7 +83192,6 @@ exports.computeFlashLoanNonSwapBudget = computeFlashLoanNonSwapBudget;
|
|
|
83371
83192
|
exports.computeFlashloanSwapConstraints = computeFlashloanSwapConstraints;
|
|
83372
83193
|
exports.computeFreeCollateralFromBalances = computeFreeCollateralFromBalances;
|
|
83373
83194
|
exports.computeFreeCollateralFromCache = computeFreeCollateralFromCache;
|
|
83374
|
-
exports.computeGroupRateLimitRemainingUsd = computeGroupRateLimitRemainingUsd;
|
|
83375
83195
|
exports.computeHealthAccountMetas = computeHealthAccountMetas;
|
|
83376
83196
|
exports.computeHealthCacheStatus = computeHealthCacheStatus;
|
|
83377
83197
|
exports.computeHealthCheckAccounts = computeHealthCheckAccounts;
|
|
@@ -83384,7 +83204,6 @@ exports.computeLiquidationPriceForBank = computeLiquidationPriceForBank;
|
|
|
83384
83204
|
exports.computeLoopingParams = computeLoopingParams;
|
|
83385
83205
|
exports.computeLowestEmodeWeights = computeLowestEmodeWeights;
|
|
83386
83206
|
exports.computeMaxBorrowForBank = computeMaxBorrowForBank;
|
|
83387
|
-
exports.computeMaxDepositForBank = computeMaxDepositForBank;
|
|
83388
83207
|
exports.computeMaxLeverage = computeMaxLeverage;
|
|
83389
83208
|
exports.computeMaxWithdrawForBank = computeMaxWithdrawForBank;
|
|
83390
83209
|
exports.computeNetApy = computeNetApy;
|
|
@@ -83392,8 +83211,6 @@ exports.computeProjectedActiveBalancesNoCpi = computeProjectedActiveBalancesNoCp
|
|
|
83392
83211
|
exports.computeProjectedActiveBanksNoCpi = computeProjectedActiveBanksNoCpi;
|
|
83393
83212
|
exports.computeQuantity = computeQuantity;
|
|
83394
83213
|
exports.computeQuantityUi = computeQuantityUi;
|
|
83395
|
-
exports.computeRateLimitWindowRemainingCapacity = computeRateLimitWindowRemainingCapacity;
|
|
83396
|
-
exports.computeRateLimiterRemainingCapacity = computeRateLimiterRemainingCapacity;
|
|
83397
83214
|
exports.computeRemainingCapacity = computeRemainingCapacity;
|
|
83398
83215
|
exports.computeSmartCrank = computeSmartCrank;
|
|
83399
83216
|
exports.computeStakedBankMultipliers = computeStakedBankMultipliers;
|
|
@@ -83487,7 +83304,6 @@ exports.getConfig = getConfig;
|
|
|
83487
83304
|
exports.getDriftCTokenMultiplier = getDriftCTokenMultiplier;
|
|
83488
83305
|
exports.getDriftMetadata = getDriftMetadata;
|
|
83489
83306
|
exports.getDriftStatesDto = getDriftStatesDto;
|
|
83490
|
-
exports.getEffectiveDepositLimit = getEffectiveDepositLimit;
|
|
83491
83307
|
exports.getEmodePairs = getEmodePairs;
|
|
83492
83308
|
exports.getExactOutEstimate = getExactOutEstimate;
|
|
83493
83309
|
exports.getFallbackPricesByFeedId = getFallbackPricesByFeedId;
|
|
@@ -83527,11 +83343,9 @@ exports.hasEmodeEntryFlag = hasEmodeEntryFlag;
|
|
|
83527
83343
|
exports.hasEmodeFlag = hasEmodeFlag;
|
|
83528
83344
|
exports.hasHealthCacheFlag = hasHealthCacheFlag;
|
|
83529
83345
|
exports.healthCacheToDto = healthCacheToDto;
|
|
83530
|
-
exports.isBorrowLimitActive = isBorrowLimitActive;
|
|
83531
83346
|
exports.isBridgeConflictError = isBridgeConflictError;
|
|
83532
83347
|
exports.isDecomposableSwapError = isDecomposableSwapError;
|
|
83533
83348
|
exports.isDepositIx = isDepositIx;
|
|
83534
|
-
exports.isDepositLimitActive = isDepositLimitActive;
|
|
83535
83349
|
exports.isFlashloan = isFlashloan;
|
|
83536
83350
|
exports.isGroupRateLimiterEnabled = isGroupRateLimiterEnabled;
|
|
83537
83351
|
exports.isMarginfiV0110Live = isMarginfiV0110Live;
|