@0dotxyz/p0-ts-sdk 2.0.0-alpha.4 → 2.0.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 +294 -259
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +293 -258
- package/dist/index.js.map +1 -1
- package/dist/vendor.cjs +27 -27
- package/dist/vendor.cjs.map +1 -1
- package/dist/vendor.d.cts +20 -20
- package/dist/vendor.d.ts +20 -20
- package/dist/vendor.js +32 -32
- package/dist/vendor.js.map +1 -1
- package/package.json +25 -22
package/dist/vendor.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import { PublicKey, TransactionInstruction, Connection, Transaction, Commitment,
|
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { R as ReserveRaw, d as ObligationRaw, O as ObligationJSON, b as ReserveJSON, C as CurvePointFields, l as RewardInfoFields, e as FarmStateRaw, c as FarmStateJSON, H as HistoricalOracleData, m as HistoricalIndexData, P as PoolBalance, I as InsuranceFund, n as FeeStructureJSON, o as OracleGuardRailsJSON, p as FeeStructure, q as OracleGuardRails, S as SpotPosition, k as DriftUserStats, i as DriftUserStatsJSON, j as DriftUser, g as DriftUserJSON, D as DriftSpotMarket, f as DriftSpotMarketJSON, a as DriftRewards, h as DriftRewardsJSON, r as DriftSpotBalanceType } from './rewards.types-2ooCYOAZ.cjs';
|
|
5
5
|
export { ab as BigFractionBytesFields, ad as BigFractionBytesJSON, J as BorrowRateCurveFields, Y as BorrowRateCurveJSON, w as CrossbarSimulatePayload, t as CurrentResult, Z as CurvePointJSON, al as FeeTier, am as FeeTierJSON, F as FeedResponse, au as HistoricalIndexDataJSON, at as HistoricalOracleDataJSON, aw as InsuranceFundJSON, aa as LastUpdateFields, ac as LastUpdateJSON, a7 as ObligationCollateralFields, a5 as ObligationCollateralJSON, a8 as ObligationLiquidityFields, a4 as ObligationLiquidityJSON, a9 as ObligationOrderFields, a6 as ObligationOrderJSON, u as OracleSubmission, an as OrderFillerRewardStructure, ao as OrderFillerRewardStructureJSON, av as PoolBalanceJSON, ap as PriceDivergenceGuardRails, aq as PriceDivergenceGuardRailsJSON, K as PriceHeuristicFields, $ as PriceHeuristicJSON, v as PullFeedAccountData, N as PythConfigurationFields, a2 as PythConfigurationJSON, B as ReserveCollateralFields, U as ReserveCollateralJSON, E as ReserveConfigFields, V as ReserveConfigJSON, G as ReserveFeesFields, X as ReserveFeesJSON, A as ReserveLiquidityFields, Q as ReserveLiquidityJSON, ae as RewardPerTimeUnitPointFields, ah as RewardPerTimeUnitPointJSON, af as RewardScheduleCurveFields, ag as RewardScheduleCurveJSON, s as SWITCHBOARD_ONDEMANDE_PRICE_PRECISION, L as ScopeConfigurationFields, a0 as ScopeConfigurationJSON, ax as SpotBalanceType, ay as SpotPositionJSON, M as SwitchboardConfigurationFields, a1 as SwitchboardConfigurationJSON, T as TokenInfoFields, _ as TokenInfoJSON, aj as UserFeesFields, ai as UserFeesJSON, ar as ValidityGuardRails, as as ValidityGuardRailsJSON, W as WithdrawalCapsFields, a3 as WithdrawalCapsJSON, z as decodeSwitchboardPullFeedData, y as getSwitchboardProgram, ak as isSpotBalanceTypeVariant, x as switchboardAccountCoder } from './rewards.types-2ooCYOAZ.cjs';
|
|
6
|
-
import { Program, BorshCoder, Address
|
|
6
|
+
import { Program, BorshCoder, Address } from '@coral-xyz/anchor';
|
|
7
7
|
import Decimal from 'decimal.js';
|
|
8
8
|
import * as _solana_buffer_layout from '@solana/buffer-layout';
|
|
9
9
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
@@ -22438,38 +22438,38 @@ declare function deriveDriftSpotMarketVault(marketIndex: number, programId?: Pub
|
|
|
22438
22438
|
* - Core rate calculations (APR)
|
|
22439
22439
|
* - APY calculations (with compounding)
|
|
22440
22440
|
*/
|
|
22441
|
-
declare const ZERO: BN
|
|
22442
|
-
declare const ONE: BN
|
|
22443
|
-
declare const TEN: BN
|
|
22444
|
-
declare const PERCENTAGE_PRECISION_EXP: BN
|
|
22445
|
-
declare const PERCENTAGE_PRECISION: BN
|
|
22446
|
-
declare const SPOT_MARKET_RATE_PRECISION_EXP: BN
|
|
22447
|
-
declare const SPOT_MARKET_RATE_PRECISION: BN
|
|
22448
|
-
declare const SPOT_MARKET_UTILIZATION_PRECISION_EXP: BN
|
|
22449
|
-
declare const SPOT_MARKET_UTILIZATION_PRECISION: BN
|
|
22450
|
-
declare const ONE_YEAR: BN
|
|
22441
|
+
declare const ZERO: BN;
|
|
22442
|
+
declare const ONE: BN;
|
|
22443
|
+
declare const TEN: BN;
|
|
22444
|
+
declare const PERCENTAGE_PRECISION_EXP: BN;
|
|
22445
|
+
declare const PERCENTAGE_PRECISION: BN;
|
|
22446
|
+
declare const SPOT_MARKET_RATE_PRECISION_EXP: BN;
|
|
22447
|
+
declare const SPOT_MARKET_RATE_PRECISION: BN;
|
|
22448
|
+
declare const SPOT_MARKET_UTILIZATION_PRECISION_EXP: BN;
|
|
22449
|
+
declare const SPOT_MARKET_UTILIZATION_PRECISION: BN;
|
|
22450
|
+
declare const ONE_YEAR: BN;
|
|
22451
22451
|
/**
|
|
22452
22452
|
* Calculates the spot token amount including any accumulated interest.
|
|
22453
22453
|
*/
|
|
22454
|
-
declare function getDriftTokenAmount(balanceAmount: BN
|
|
22454
|
+
declare function getDriftTokenAmount(balanceAmount: BN, spotMarket: DriftSpotMarket, balanceType: DriftSpotBalanceType): BN;
|
|
22455
22455
|
/**
|
|
22456
22456
|
* Calculates the utilization rate of a spot market
|
|
22457
22457
|
* Utilization = borrows / deposits
|
|
22458
22458
|
*/
|
|
22459
|
-
declare function calculateDriftUtilization(bank: DriftSpotMarket, delta?: BN
|
|
22459
|
+
declare function calculateDriftUtilization(bank: DriftSpotMarket, delta?: BN): BN;
|
|
22460
22460
|
/**
|
|
22461
22461
|
* Calculates the interest rate based on utilization using a piecewise curve
|
|
22462
22462
|
*/
|
|
22463
|
-
declare function calculateDriftInterestRate(bank: DriftSpotMarket, delta?: BN
|
|
22463
|
+
declare function calculateDriftInterestRate(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null): BN;
|
|
22464
22464
|
/**
|
|
22465
22465
|
* Calculates the borrow rate (APR) for a spot market
|
|
22466
22466
|
*/
|
|
22467
|
-
declare function calculateDriftBorrowRate(bank: DriftSpotMarket, delta?: BN
|
|
22467
|
+
declare function calculateDriftBorrowRate(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null): BN;
|
|
22468
22468
|
/**
|
|
22469
22469
|
* Calculates the deposit rate (APR) for a spot market
|
|
22470
22470
|
* This is the annualized interest rate lenders earn
|
|
22471
22471
|
*/
|
|
22472
|
-
declare function calculateDriftDepositRate(bank: DriftSpotMarket, delta?: BN
|
|
22472
|
+
declare function calculateDriftDepositRate(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null): BN;
|
|
22473
22473
|
/**
|
|
22474
22474
|
* Calculates the Annual Percentage Yield (APY) for a lending/deposit position.
|
|
22475
22475
|
*
|
|
@@ -22491,7 +22491,7 @@ declare function calculateDriftDepositRate(bank: DriftSpotMarket, delta?: BN$1,
|
|
|
22491
22491
|
* console.log(`Lending APY: ${apyPercent.toFixed(2)}%`);
|
|
22492
22492
|
* ```
|
|
22493
22493
|
*/
|
|
22494
|
-
declare function calculateDriftLendingAPY(bank: DriftSpotMarket, delta?: BN
|
|
22494
|
+
declare function calculateDriftLendingAPY(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null, compoundingPeriodsPerYear?: number): BN;
|
|
22495
22495
|
/**
|
|
22496
22496
|
* Calculates a simplified lending APY without compounding (essentially the APR).
|
|
22497
22497
|
* This is faster but less accurate than calculateLendingAPY.
|
|
@@ -22501,7 +22501,7 @@ declare function calculateDriftLendingAPY(bank: DriftSpotMarket, delta?: BN$1, c
|
|
|
22501
22501
|
* @param currentUtilization - Optional pre-calculated utilization (default: null)
|
|
22502
22502
|
* @returns APR as a percentage scaled by PERCENTAGE_PRECISION
|
|
22503
22503
|
*/
|
|
22504
|
-
declare function calculateDriftLendingAPR(bank: DriftSpotMarket, delta?: BN
|
|
22504
|
+
declare function calculateDriftLendingAPR(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null): BN;
|
|
22505
22505
|
/**
|
|
22506
22506
|
* Calculates the borrowing APY for a borrow position.
|
|
22507
22507
|
*
|
|
@@ -22511,7 +22511,7 @@ declare function calculateDriftLendingAPR(bank: DriftSpotMarket, delta?: BN$1, c
|
|
|
22511
22511
|
* @param compoundingPeriodsPerYear - Number of times interest compounds per year (default: 365)
|
|
22512
22512
|
* @returns APY as a percentage scaled by PERCENTAGE_PRECISION
|
|
22513
22513
|
*/
|
|
22514
|
-
declare function calculateDriftBorrowAPY(bank: DriftSpotMarket, delta?: BN
|
|
22514
|
+
declare function calculateDriftBorrowAPY(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null, compoundingPeriodsPerYear?: number): BN;
|
|
22515
22515
|
/**
|
|
22516
22516
|
* Calculates the borrowing APR (without compounding).
|
|
22517
22517
|
*
|
|
@@ -22520,7 +22520,7 @@ declare function calculateDriftBorrowAPY(bank: DriftSpotMarket, delta?: BN$1, cu
|
|
|
22520
22520
|
* @param currentUtilization - Optional pre-calculated utilization (default: null)
|
|
22521
22521
|
* @returns APR as a percentage scaled by PERCENTAGE_PRECISION
|
|
22522
22522
|
*/
|
|
22523
|
-
declare function calculateDriftBorrowAPR(bank: DriftSpotMarket, delta?: BN
|
|
22523
|
+
declare function calculateDriftBorrowAPR(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null): BN;
|
|
22524
22524
|
/**
|
|
22525
22525
|
* Interest rate curve point for visualization
|
|
22526
22526
|
*/
|
package/dist/vendor.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { PublicKey, TransactionInstruction, Connection, Transaction, Commitment,
|
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { R as ReserveRaw, d as ObligationRaw, O as ObligationJSON, b as ReserveJSON, C as CurvePointFields, l as RewardInfoFields, e as FarmStateRaw, c as FarmStateJSON, H as HistoricalOracleData, m as HistoricalIndexData, P as PoolBalance, I as InsuranceFund, n as FeeStructureJSON, o as OracleGuardRailsJSON, p as FeeStructure, q as OracleGuardRails, S as SpotPosition, k as DriftUserStats, i as DriftUserStatsJSON, j as DriftUser, g as DriftUserJSON, D as DriftSpotMarket, f as DriftSpotMarketJSON, a as DriftRewards, h as DriftRewardsJSON, r as DriftSpotBalanceType } from './rewards.types-2ooCYOAZ.js';
|
|
5
5
|
export { ab as BigFractionBytesFields, ad as BigFractionBytesJSON, J as BorrowRateCurveFields, Y as BorrowRateCurveJSON, w as CrossbarSimulatePayload, t as CurrentResult, Z as CurvePointJSON, al as FeeTier, am as FeeTierJSON, F as FeedResponse, au as HistoricalIndexDataJSON, at as HistoricalOracleDataJSON, aw as InsuranceFundJSON, aa as LastUpdateFields, ac as LastUpdateJSON, a7 as ObligationCollateralFields, a5 as ObligationCollateralJSON, a8 as ObligationLiquidityFields, a4 as ObligationLiquidityJSON, a9 as ObligationOrderFields, a6 as ObligationOrderJSON, u as OracleSubmission, an as OrderFillerRewardStructure, ao as OrderFillerRewardStructureJSON, av as PoolBalanceJSON, ap as PriceDivergenceGuardRails, aq as PriceDivergenceGuardRailsJSON, K as PriceHeuristicFields, $ as PriceHeuristicJSON, v as PullFeedAccountData, N as PythConfigurationFields, a2 as PythConfigurationJSON, B as ReserveCollateralFields, U as ReserveCollateralJSON, E as ReserveConfigFields, V as ReserveConfigJSON, G as ReserveFeesFields, X as ReserveFeesJSON, A as ReserveLiquidityFields, Q as ReserveLiquidityJSON, ae as RewardPerTimeUnitPointFields, ah as RewardPerTimeUnitPointJSON, af as RewardScheduleCurveFields, ag as RewardScheduleCurveJSON, s as SWITCHBOARD_ONDEMANDE_PRICE_PRECISION, L as ScopeConfigurationFields, a0 as ScopeConfigurationJSON, ax as SpotBalanceType, ay as SpotPositionJSON, M as SwitchboardConfigurationFields, a1 as SwitchboardConfigurationJSON, T as TokenInfoFields, _ as TokenInfoJSON, aj as UserFeesFields, ai as UserFeesJSON, ar as ValidityGuardRails, as as ValidityGuardRailsJSON, W as WithdrawalCapsFields, a3 as WithdrawalCapsJSON, z as decodeSwitchboardPullFeedData, y as getSwitchboardProgram, ak as isSpotBalanceTypeVariant, x as switchboardAccountCoder } from './rewards.types-2ooCYOAZ.js';
|
|
6
|
-
import { Program, BorshCoder, Address
|
|
6
|
+
import { Program, BorshCoder, Address } from '@coral-xyz/anchor';
|
|
7
7
|
import Decimal from 'decimal.js';
|
|
8
8
|
import * as _solana_buffer_layout from '@solana/buffer-layout';
|
|
9
9
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
@@ -22438,38 +22438,38 @@ declare function deriveDriftSpotMarketVault(marketIndex: number, programId?: Pub
|
|
|
22438
22438
|
* - Core rate calculations (APR)
|
|
22439
22439
|
* - APY calculations (with compounding)
|
|
22440
22440
|
*/
|
|
22441
|
-
declare const ZERO: BN
|
|
22442
|
-
declare const ONE: BN
|
|
22443
|
-
declare const TEN: BN
|
|
22444
|
-
declare const PERCENTAGE_PRECISION_EXP: BN
|
|
22445
|
-
declare const PERCENTAGE_PRECISION: BN
|
|
22446
|
-
declare const SPOT_MARKET_RATE_PRECISION_EXP: BN
|
|
22447
|
-
declare const SPOT_MARKET_RATE_PRECISION: BN
|
|
22448
|
-
declare const SPOT_MARKET_UTILIZATION_PRECISION_EXP: BN
|
|
22449
|
-
declare const SPOT_MARKET_UTILIZATION_PRECISION: BN
|
|
22450
|
-
declare const ONE_YEAR: BN
|
|
22441
|
+
declare const ZERO: BN;
|
|
22442
|
+
declare const ONE: BN;
|
|
22443
|
+
declare const TEN: BN;
|
|
22444
|
+
declare const PERCENTAGE_PRECISION_EXP: BN;
|
|
22445
|
+
declare const PERCENTAGE_PRECISION: BN;
|
|
22446
|
+
declare const SPOT_MARKET_RATE_PRECISION_EXP: BN;
|
|
22447
|
+
declare const SPOT_MARKET_RATE_PRECISION: BN;
|
|
22448
|
+
declare const SPOT_MARKET_UTILIZATION_PRECISION_EXP: BN;
|
|
22449
|
+
declare const SPOT_MARKET_UTILIZATION_PRECISION: BN;
|
|
22450
|
+
declare const ONE_YEAR: BN;
|
|
22451
22451
|
/**
|
|
22452
22452
|
* Calculates the spot token amount including any accumulated interest.
|
|
22453
22453
|
*/
|
|
22454
|
-
declare function getDriftTokenAmount(balanceAmount: BN
|
|
22454
|
+
declare function getDriftTokenAmount(balanceAmount: BN, spotMarket: DriftSpotMarket, balanceType: DriftSpotBalanceType): BN;
|
|
22455
22455
|
/**
|
|
22456
22456
|
* Calculates the utilization rate of a spot market
|
|
22457
22457
|
* Utilization = borrows / deposits
|
|
22458
22458
|
*/
|
|
22459
|
-
declare function calculateDriftUtilization(bank: DriftSpotMarket, delta?: BN
|
|
22459
|
+
declare function calculateDriftUtilization(bank: DriftSpotMarket, delta?: BN): BN;
|
|
22460
22460
|
/**
|
|
22461
22461
|
* Calculates the interest rate based on utilization using a piecewise curve
|
|
22462
22462
|
*/
|
|
22463
|
-
declare function calculateDriftInterestRate(bank: DriftSpotMarket, delta?: BN
|
|
22463
|
+
declare function calculateDriftInterestRate(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null): BN;
|
|
22464
22464
|
/**
|
|
22465
22465
|
* Calculates the borrow rate (APR) for a spot market
|
|
22466
22466
|
*/
|
|
22467
|
-
declare function calculateDriftBorrowRate(bank: DriftSpotMarket, delta?: BN
|
|
22467
|
+
declare function calculateDriftBorrowRate(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null): BN;
|
|
22468
22468
|
/**
|
|
22469
22469
|
* Calculates the deposit rate (APR) for a spot market
|
|
22470
22470
|
* This is the annualized interest rate lenders earn
|
|
22471
22471
|
*/
|
|
22472
|
-
declare function calculateDriftDepositRate(bank: DriftSpotMarket, delta?: BN
|
|
22472
|
+
declare function calculateDriftDepositRate(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null): BN;
|
|
22473
22473
|
/**
|
|
22474
22474
|
* Calculates the Annual Percentage Yield (APY) for a lending/deposit position.
|
|
22475
22475
|
*
|
|
@@ -22491,7 +22491,7 @@ declare function calculateDriftDepositRate(bank: DriftSpotMarket, delta?: BN$1,
|
|
|
22491
22491
|
* console.log(`Lending APY: ${apyPercent.toFixed(2)}%`);
|
|
22492
22492
|
* ```
|
|
22493
22493
|
*/
|
|
22494
|
-
declare function calculateDriftLendingAPY(bank: DriftSpotMarket, delta?: BN
|
|
22494
|
+
declare function calculateDriftLendingAPY(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null, compoundingPeriodsPerYear?: number): BN;
|
|
22495
22495
|
/**
|
|
22496
22496
|
* Calculates a simplified lending APY without compounding (essentially the APR).
|
|
22497
22497
|
* This is faster but less accurate than calculateLendingAPY.
|
|
@@ -22501,7 +22501,7 @@ declare function calculateDriftLendingAPY(bank: DriftSpotMarket, delta?: BN$1, c
|
|
|
22501
22501
|
* @param currentUtilization - Optional pre-calculated utilization (default: null)
|
|
22502
22502
|
* @returns APR as a percentage scaled by PERCENTAGE_PRECISION
|
|
22503
22503
|
*/
|
|
22504
|
-
declare function calculateDriftLendingAPR(bank: DriftSpotMarket, delta?: BN
|
|
22504
|
+
declare function calculateDriftLendingAPR(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null): BN;
|
|
22505
22505
|
/**
|
|
22506
22506
|
* Calculates the borrowing APY for a borrow position.
|
|
22507
22507
|
*
|
|
@@ -22511,7 +22511,7 @@ declare function calculateDriftLendingAPR(bank: DriftSpotMarket, delta?: BN$1, c
|
|
|
22511
22511
|
* @param compoundingPeriodsPerYear - Number of times interest compounds per year (default: 365)
|
|
22512
22512
|
* @returns APY as a percentage scaled by PERCENTAGE_PRECISION
|
|
22513
22513
|
*/
|
|
22514
|
-
declare function calculateDriftBorrowAPY(bank: DriftSpotMarket, delta?: BN
|
|
22514
|
+
declare function calculateDriftBorrowAPY(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null, compoundingPeriodsPerYear?: number): BN;
|
|
22515
22515
|
/**
|
|
22516
22516
|
* Calculates the borrowing APR (without compounding).
|
|
22517
22517
|
*
|
|
@@ -22520,7 +22520,7 @@ declare function calculateDriftBorrowAPY(bank: DriftSpotMarket, delta?: BN$1, cu
|
|
|
22520
22520
|
* @param currentUtilization - Optional pre-calculated utilization (default: null)
|
|
22521
22521
|
* @returns APR as a percentage scaled by PERCENTAGE_PRECISION
|
|
22522
22522
|
*/
|
|
22523
|
-
declare function calculateDriftBorrowAPR(bank: DriftSpotMarket, delta?: BN
|
|
22523
|
+
declare function calculateDriftBorrowAPR(bank: DriftSpotMarket, delta?: BN, currentUtilization?: BN | null): BN;
|
|
22524
22524
|
/**
|
|
22525
22525
|
* Interest rate curve point for visualization
|
|
22526
22526
|
*/
|
package/dist/vendor.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { PublicKey, TransactionInstruction, SYSVAR_RENT_PUBKEY, SystemProgram, STAKE_CONFIG_ID, Transaction, LAMPORTS_PER_SOL, StakeProgram, SYSVAR_CLOCK_PUBKEY } from '@solana/web3.js';
|
|
2
2
|
import 'bignumber.js';
|
|
3
3
|
import { deserialize } from 'borsh';
|
|
4
|
-
import BN2, { BN
|
|
4
|
+
import BN2, { BN } from 'bn.js';
|
|
5
5
|
import { struct, u8, u32 } from '@solana/buffer-layout';
|
|
6
6
|
import { bool, publicKey, u64 } from '@solana/buffer-layout-utils';
|
|
7
7
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
8
|
-
import { BorshCoder, BorshAccountsCoder,
|
|
8
|
+
import { BorshCoder, BorshAccountsCoder, Program } from '@coral-xyz/anchor';
|
|
9
9
|
import * as borsh from '@coral-xyz/borsh';
|
|
10
10
|
import { struct as struct$1, bool as bool$1, publicKey as publicKey$1, array, u64 as u64$1, u8 as u8$1, u32 as u32$1, u128 } from '@coral-xyz/borsh';
|
|
11
11
|
import Decimal3 from 'decimal.js';
|
|
@@ -671,7 +671,7 @@ var SinglePoolInstruction = {
|
|
|
671
671
|
const data = Buffer.concat([
|
|
672
672
|
Buffer.from([3 /* WithdrawStake */]),
|
|
673
673
|
userStakeAuthority.toBuffer(),
|
|
674
|
-
Buffer.from(new BN
|
|
674
|
+
Buffer.from(new BN(rawAmount.toString()).toArray("le", 8))
|
|
675
675
|
]);
|
|
676
676
|
return createTransactionInstruction(
|
|
677
677
|
SINGLE_POOL_PROGRAM_ID,
|
|
@@ -826,8 +826,8 @@ var createAccountIx = (from, newAccount, lamports, space, programAddress) => {
|
|
|
826
826
|
const data = Buffer.concat([
|
|
827
827
|
Buffer.from([0]),
|
|
828
828
|
// Assuming the first byte is an instruction type or similar
|
|
829
|
-
Buffer.from(new BN
|
|
830
|
-
Buffer.from(new BN
|
|
829
|
+
Buffer.from(new BN(lamports).toArray("le", 8)),
|
|
830
|
+
Buffer.from(new BN(space).toArray("le", 8)),
|
|
831
831
|
programAddress.toBuffer()
|
|
832
832
|
]);
|
|
833
833
|
const accounts = [
|
|
@@ -27915,18 +27915,18 @@ function deriveDriftSpotMarketVault(marketIndex, programId = DRIFT_PROGRAM_ID) {
|
|
|
27915
27915
|
programId
|
|
27916
27916
|
);
|
|
27917
27917
|
}
|
|
27918
|
-
var ZERO = new
|
|
27919
|
-
var ONE = new
|
|
27920
|
-
var TEN = new
|
|
27921
|
-
var PERCENTAGE_PRECISION_EXP = new
|
|
27922
|
-
var PERCENTAGE_PRECISION = new
|
|
27923
|
-
var SPOT_MARKET_RATE_PRECISION_EXP = new
|
|
27924
|
-
var SPOT_MARKET_RATE_PRECISION = new
|
|
27925
|
-
var SPOT_MARKET_UTILIZATION_PRECISION_EXP = new
|
|
27926
|
-
var SPOT_MARKET_UTILIZATION_PRECISION = new
|
|
27918
|
+
var ZERO = new BN2(0);
|
|
27919
|
+
var ONE = new BN2(1);
|
|
27920
|
+
var TEN = new BN2(10);
|
|
27921
|
+
var PERCENTAGE_PRECISION_EXP = new BN2(6);
|
|
27922
|
+
var PERCENTAGE_PRECISION = new BN2(10).pow(PERCENTAGE_PRECISION_EXP);
|
|
27923
|
+
var SPOT_MARKET_RATE_PRECISION_EXP = new BN2(6);
|
|
27924
|
+
var SPOT_MARKET_RATE_PRECISION = new BN2(10).pow(SPOT_MARKET_RATE_PRECISION_EXP);
|
|
27925
|
+
var SPOT_MARKET_UTILIZATION_PRECISION_EXP = new BN2(6);
|
|
27926
|
+
var SPOT_MARKET_UTILIZATION_PRECISION = new BN2(10).pow(
|
|
27927
27927
|
SPOT_MARKET_UTILIZATION_PRECISION_EXP
|
|
27928
27928
|
);
|
|
27929
|
-
var ONE_YEAR = new
|
|
27929
|
+
var ONE_YEAR = new BN2(31536e3);
|
|
27930
27930
|
function divCeil(a, b) {
|
|
27931
27931
|
const quotient = a.div(b);
|
|
27932
27932
|
const remainder = a.mod(b);
|
|
@@ -27936,7 +27936,7 @@ function divCeil(a, b) {
|
|
|
27936
27936
|
return quotient;
|
|
27937
27937
|
}
|
|
27938
27938
|
function getDriftTokenAmount(balanceAmount, spotMarket, balanceType) {
|
|
27939
|
-
const precisionDecrease = TEN.pow(new
|
|
27939
|
+
const precisionDecrease = TEN.pow(new BN2(19 - spotMarket.decimals));
|
|
27940
27940
|
if (isSpotBalanceTypeVariant(balanceType, "deposit")) {
|
|
27941
27941
|
return balanceAmount.mul(spotMarket.cumulativeDepositInterest).div(precisionDecrease);
|
|
27942
27942
|
} else {
|
|
@@ -27971,18 +27971,18 @@ function calculateDriftUtilization(bank, delta = ZERO) {
|
|
|
27971
27971
|
}
|
|
27972
27972
|
function calculateDriftInterestRate(bank, delta = ZERO, currentUtilization = null) {
|
|
27973
27973
|
const utilization = currentUtilization || calculateDriftUtilization(bank, delta);
|
|
27974
|
-
const optimalUtil = new
|
|
27975
|
-
const optimalRate = new
|
|
27976
|
-
const maxRate = new
|
|
27977
|
-
const minRate = new
|
|
27978
|
-
const weightsDivisor = new
|
|
27974
|
+
const optimalUtil = new BN2(bank.optimalUtilization);
|
|
27975
|
+
const optimalRate = new BN2(bank.optimalBorrowRate);
|
|
27976
|
+
const maxRate = new BN2(bank.maxBorrowRate);
|
|
27977
|
+
const minRate = new BN2(bank.minBorrowRate).mul(PERCENTAGE_PRECISION.divn(200));
|
|
27978
|
+
const weightsDivisor = new BN2(1e3);
|
|
27979
27979
|
const segments = [
|
|
27980
|
-
[new
|
|
27981
|
-
[new
|
|
27982
|
-
[new
|
|
27983
|
-
[new
|
|
27984
|
-
[new
|
|
27985
|
-
[SPOT_MARKET_UTILIZATION_PRECISION, new
|
|
27980
|
+
[new BN2(85e4), new BN2(50)],
|
|
27981
|
+
[new BN2(9e5), new BN2(100)],
|
|
27982
|
+
[new BN2(95e4), new BN2(150)],
|
|
27983
|
+
[new BN2(99e4), new BN2(200)],
|
|
27984
|
+
[new BN2(995e3), new BN2(250)],
|
|
27985
|
+
[SPOT_MARKET_UTILIZATION_PRECISION, new BN2(250)]
|
|
27986
27986
|
];
|
|
27987
27987
|
let rate;
|
|
27988
27988
|
if (utilization.lte(optimalUtil)) {
|
|
@@ -28007,7 +28007,7 @@ function calculateDriftInterestRate(bank, delta = ZERO, currentUtilization = nul
|
|
|
28007
28007
|
}
|
|
28008
28008
|
}
|
|
28009
28009
|
}
|
|
28010
|
-
return
|
|
28010
|
+
return BN2.max(minRate, rate);
|
|
28011
28011
|
}
|
|
28012
28012
|
function calculateDriftBorrowRate(bank, delta = ZERO, currentUtilization = null) {
|
|
28013
28013
|
return calculateDriftInterestRate(bank, delta, currentUtilization);
|
|
@@ -28015,7 +28015,7 @@ function calculateDriftBorrowRate(bank, delta = ZERO, currentUtilization = null)
|
|
|
28015
28015
|
function calculateDriftDepositRate(bank, delta = ZERO, currentUtilization = null) {
|
|
28016
28016
|
const utilization = currentUtilization || calculateDriftUtilization(bank, delta);
|
|
28017
28017
|
const borrowRate = calculateDriftBorrowRate(bank, delta, utilization);
|
|
28018
|
-
const depositRate = borrowRate.mul(PERCENTAGE_PRECISION.sub(new
|
|
28018
|
+
const depositRate = borrowRate.mul(PERCENTAGE_PRECISION.sub(new BN2(bank.insuranceFund.totalFactor))).mul(utilization).div(SPOT_MARKET_UTILIZATION_PRECISION).div(PERCENTAGE_PRECISION);
|
|
28019
28019
|
return depositRate;
|
|
28020
28020
|
}
|
|
28021
28021
|
function calculateDriftLendingAPY(bank, delta = ZERO, currentUtilization = null, compoundingPeriodsPerYear = 365) {
|
|
@@ -28023,7 +28023,7 @@ function calculateDriftLendingAPY(bank, delta = ZERO, currentUtilization = null,
|
|
|
28023
28023
|
if (depositRate.eq(ZERO)) {
|
|
28024
28024
|
return ZERO;
|
|
28025
28025
|
}
|
|
28026
|
-
const CALC_PRECISION = new
|
|
28026
|
+
const CALC_PRECISION = new BN2(10).pow(new BN2(18));
|
|
28027
28027
|
const rateInCalcPrecisionDecimal = depositRate.mul(CALC_PRECISION).div(SPOT_MARKET_RATE_PRECISION);
|
|
28028
28028
|
let expResult = CALC_PRECISION;
|
|
28029
28029
|
let term = rateInCalcPrecisionDecimal;
|
|
@@ -28056,7 +28056,7 @@ function calculateDriftBorrowAPY(bank, delta = ZERO, currentUtilization = null,
|
|
|
28056
28056
|
if (borrowRate.eq(ZERO)) {
|
|
28057
28057
|
return ZERO;
|
|
28058
28058
|
}
|
|
28059
|
-
const CALC_PRECISION = new
|
|
28059
|
+
const CALC_PRECISION = new BN2(10).pow(new BN2(18));
|
|
28060
28060
|
const rateInCalcPrecisionDecimal = borrowRate.mul(CALC_PRECISION).div(SPOT_MARKET_RATE_PRECISION);
|
|
28061
28061
|
let expResult = CALC_PRECISION;
|
|
28062
28062
|
let term = rateInCalcPrecisionDecimal;
|
|
@@ -28092,7 +28092,7 @@ function calculateAPYFromAPR2(apr) {
|
|
|
28092
28092
|
function generateDriftReserveCurve(spotMarket) {
|
|
28093
28093
|
return Array.from({ length: 101 }, (_, i) => {
|
|
28094
28094
|
const utilizationPercent = i / 100;
|
|
28095
|
-
const utilizationBN = new
|
|
28095
|
+
const utilizationBN = new BN2(
|
|
28096
28096
|
Math.floor(utilizationPercent * SPOT_MARKET_UTILIZATION_PRECISION.toNumber())
|
|
28097
28097
|
);
|
|
28098
28098
|
const borrowRateBN = calculateDriftBorrowRate(spotMarket, ZERO, utilizationBN);
|