@0dotxyz/p0-ts-sdk 3.0.0-next.0 → 3.0.0-next.2

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 CHANGED
@@ -95,6 +95,7 @@ var FLASHLOAN_ENABLED_FLAG = 1 << 2;
95
95
  var TRANSFER_ACCOUNT_AUTHORITY_FLAG = 1 << 3;
96
96
  var STAKED_ORACLE_DISABLED_FLAG = 1 << 9;
97
97
  var STAKED_ORACLE_USES_ONRAMP_FLAG = 1 << 10;
98
+ var CIRCUIT_BREAKER_ENABLED_FLAG = 1 << 11;
98
99
  var PREMIUM_ACTIVE_FLAG = 1 << 13;
99
100
  var KAMINO_MARKET_EMERGENCY_FLAG = 1 << 14;
100
101
  var MAX_COSTLY_POSITIONS = 4;
@@ -11062,6 +11063,11 @@ function toBankDto(bank) {
11062
11063
  premiumActive: bank.premiumActive,
11063
11064
  premiumActivatedAt: bank.premiumActivatedAt,
11064
11065
  kaminoEmergency: bank.kaminoEmergency,
11066
+ liquidationLiquidatorFee: bank.liquidationLiquidatorFee,
11067
+ liquidationInsuranceFee: bank.liquidationInsuranceFee,
11068
+ isCircuitBreakerEnabled: bank.isCircuitBreakerEnabled,
11069
+ cbTier: bank.cbTier,
11070
+ cbHaltEndedAt: bank.cbHaltEndedAt,
11065
11071
  rateLimiter: bank.rateLimiter ? toBankRateLimiterDto(bank.rateLimiter) : void 0,
11066
11072
  tokenSymbol: bank.tokenSymbol,
11067
11073
  feesDestinationAccount: bank.feesDestinationAccount,
@@ -11123,7 +11129,10 @@ function toBankConfigDto(bankConfig) {
11123
11129
  configFlags: bankConfig.configFlags,
11124
11130
  oracleMaxConfidence: bankConfig.oracleMaxConfidence,
11125
11131
  fixedPrice: bankConfig.fixedPrice.toString(),
11126
- scopeEntryIndex: bankConfig.scopeEntryIndex
11132
+ scopeEntryIndex: bankConfig.scopeEntryIndex,
11133
+ cbWindowMaxUpBps: bankConfig.cbWindowMaxUpBps,
11134
+ cbWindowMaxDownBps: bankConfig.cbWindowMaxDownBps,
11135
+ cbWindowSeconds: bankConfig.cbWindowSeconds
11127
11136
  };
11128
11137
  }
11129
11138
  function toInterestRateConfigDto(interestRateConfig) {
@@ -11397,6 +11406,11 @@ function parseBankRaw(address23, accountParsed, bankMetadata) {
11397
11406
  premiumActive,
11398
11407
  premiumActivatedAt: Number(accountParsed.premiumActivatedAt),
11399
11408
  kaminoEmergency: (flags & KAMINO_MARKET_EMERGENCY_FLAG) > 0,
11409
+ liquidationLiquidatorFee: accountParsed.liquidationLiquidatorFee,
11410
+ liquidationInsuranceFee: accountParsed.liquidationInsuranceFee,
11411
+ isCircuitBreakerEnabled: (flags & CIRCUIT_BREAKER_ENABLED_FLAG) > 0,
11412
+ cbTier: accountParsed.cbTier,
11413
+ cbHaltEndedAt: Number(accountParsed.cbHaltEndedAt),
11400
11414
  rateLimiter,
11401
11415
  tokenSymbol,
11402
11416
  kaminoIntegrationAccounts,
@@ -11443,6 +11457,11 @@ function dtoToBank(bankDto) {
11443
11457
  premiumActive: bankDto.premiumActive ?? false,
11444
11458
  premiumActivatedAt: bankDto.premiumActivatedAt ?? 0,
11445
11459
  kaminoEmergency: bankDto.kaminoEmergency ?? false,
11460
+ liquidationLiquidatorFee: bankDto.liquidationLiquidatorFee ?? 0,
11461
+ liquidationInsuranceFee: bankDto.liquidationInsuranceFee ?? 0,
11462
+ isCircuitBreakerEnabled: bankDto.isCircuitBreakerEnabled ?? false,
11463
+ cbTier: bankDto.cbTier ?? 0,
11464
+ cbHaltEndedAt: bankDto.cbHaltEndedAt ?? 0,
11446
11465
  rateLimiter: bankDto.rateLimiter ? dtoToBankRateLimiter(bankDto.rateLimiter) : void 0,
11447
11466
  tokenSymbol: bankDto.tokenSymbol,
11448
11467
  feesDestinationAccount: bankDto.feesDestinationAccount ? kit.address(bankDto.feesDestinationAccount) : void 0,
@@ -11520,7 +11539,10 @@ function dtoToBankConfig(bankConfigDto) {
11520
11539
  interestRateConfig: dtoToInterestRateConfig(bankConfigDto.interestRateConfig),
11521
11540
  oracleMaxConfidence: bankConfigDto.oracleMaxConfidence,
11522
11541
  fixedPrice: new bignumber_js.BigNumber(bankConfigDto.fixedPrice),
11523
- scopeEntryIndex: bankConfigDto.scopeEntryIndex
11542
+ scopeEntryIndex: bankConfigDto.scopeEntryIndex,
11543
+ cbWindowMaxUpBps: bankConfigDto.cbWindowMaxUpBps ?? 0,
11544
+ cbWindowMaxDownBps: bankConfigDto.cbWindowMaxDownBps ?? 0,
11545
+ cbWindowSeconds: bankConfigDto.cbWindowSeconds ?? 0
11524
11546
  };
11525
11547
  }
11526
11548
  function dtoToInterestRateConfig(interestRateConfigDto) {
@@ -11602,7 +11624,10 @@ function parseBankConfigRaw(bankConfigRaw) {
11602
11624
  interestRateConfig,
11603
11625
  oracleMaxConfidence,
11604
11626
  fixedPrice,
11605
- scopeEntryIndex
11627
+ scopeEntryIndex,
11628
+ cbWindowMaxUpBps: bankConfigRaw.cbWindowMaxUpBps,
11629
+ cbWindowMaxDownBps: bankConfigRaw.cbWindowMaxDownBps,
11630
+ cbWindowSeconds: bankConfigRaw.cbWindowSeconds
11606
11631
  };
11607
11632
  }
11608
11633
  function parseRiskTier(riskTierRaw) {
@@ -15461,6 +15486,15 @@ function getLiabilityWeight(config, marginRequirementType) {
15461
15486
  throw new Error("Invalid margin requirement type");
15462
15487
  }
15463
15488
  }
15489
+ var DEFAULT_LIQUIDATION_FEE = new bignumber_js.BigNumber(0.025);
15490
+ var U32_MAX2 = 4294967295;
15491
+ function getBankLiquidationFees(bank) {
15492
+ const toFraction = (fee) => fee === 0 ? DEFAULT_LIQUIDATION_FEE : new bignumber_js.BigNumber(fee).div(U32_MAX2);
15493
+ return {
15494
+ liquidatorFee: toFraction(bank.liquidationLiquidatorFee),
15495
+ insuranceFee: toFraction(bank.liquidationInsuranceFee)
15496
+ };
15497
+ }
15464
15498
  function computeUsdValue(params) {
15465
15499
  const {
15466
15500
  bank,
@@ -15585,9 +15619,9 @@ function computeInterestRates(bank) {
15585
15619
  const borrowingRate = baseInterestRate.times(new bignumber_js.BigNumber(1).plus(rateFee)).plus(fixedFee);
15586
15620
  return { lendingRate, borrowingRate };
15587
15621
  }
15588
- var U32_MAX2 = 4294967295;
15622
+ var U32_MAX3 = 4294967295;
15589
15623
  function rateFromU32(rate) {
15590
- const ratio = new bignumber_js.BigNumber(rate).div(U32_MAX2);
15624
+ const ratio = new bignumber_js.BigNumber(rate).div(U32_MAX3);
15591
15625
  return ratio.times(10);
15592
15626
  }
15593
15627
  function calculateRateBetweenPoints(startX, startY, endX, endY, targetX) {
@@ -15618,7 +15652,7 @@ function computeMultipointCurve(utilizationRate, zeroUtilRate, hundredUtilRate,
15618
15652
  let prevUtil = new bignumber_js.BigNumber(0);
15619
15653
  let prevRate = zeroRate;
15620
15654
  for (const point of nonPaddingPoints) {
15621
- const pointUtil = new bignumber_js.BigNumber(point.util).div(U32_MAX2);
15655
+ const pointUtil = new bignumber_js.BigNumber(point.util).div(U32_MAX3);
15622
15656
  const pointRate = rateFromU32(point.rate);
15623
15657
  if (clampedUtilizationRate.lte(pointUtil)) {
15624
15658
  return calculateRateBetweenPoints(
@@ -15688,6 +15722,9 @@ function isStandardDepositable(bank) {
15688
15722
  const { assetTag, operationalState } = bank.config;
15689
15723
  return (assetTag === 0 /* DEFAULT */ || assetTag === 1 /* SOL */) && operationalState === "Operational" /* Operational */;
15690
15724
  }
15725
+ function isBankCircuitBreakerHalted(bank, nowSeconds) {
15726
+ return bank.isCircuitBreakerEnabled && bank.cbTier > 0 && nowSeconds < bank.cbHaltEndedAt;
15727
+ }
15691
15728
  var SECONDS_PER_DAY = 24 * 60 * 60;
15692
15729
  var SECONDS_PER_YEAR = SECONDS_PER_DAY * 365;
15693
15730
  var EXECUTION_HEADROOM_SECONDS = 120;
@@ -18206,7 +18243,6 @@ function deserializeJupiterInstruction(instruction) {
18206
18243
  function toJupiterConfig(apiConfig) {
18207
18244
  if (!apiConfig) return void 0;
18208
18245
  return {
18209
- basePath: apiConfig.basePath,
18210
18246
  apiKey: apiConfig.apiKey,
18211
18247
  headers: apiConfig.headers
18212
18248
  };
@@ -20154,14 +20190,16 @@ async function simulateAccountHealthCacheWithFallback(params) {
20154
20190
  marginfiAccount,
20155
20191
  bankIntegrationMap
20156
20192
  });
20157
- marginfiAccount = parseMarginfiAccountRaw(params.marginfiAccount.address, {
20158
- ...simulatedAccount,
20193
+ const simulated = parseMarginfiAccountRaw(params.marginfiAccount.address, simulatedAccount);
20194
+ marginfiAccount = {
20195
+ ...simulated,
20159
20196
  healthCache: {
20160
- ...simulatedAccount.healthCache,
20161
- assetValueEquity: bigNumberToWrappedI80F48(assetValueEquity),
20162
- liabilityValueEquity: bigNumberToWrappedI80F48(liabilityValueEquity)
20197
+ ...simulated.healthCache,
20198
+ assetValueEquity,
20199
+ liabilityValueEquity,
20200
+ simulationStatus: 1 /* ONCHAIN */
20163
20201
  }
20164
- });
20202
+ };
20165
20203
  } catch (e) {
20166
20204
  const { assets: assetValueMaint, liabilities: liabilityValueMaint } = computeHealthComponentsFromBalances({
20167
20205
  activeBalances,
@@ -23826,7 +23864,7 @@ async function makeVaultCompleteWithdrawalTx(params) {
23826
23864
 
23827
23865
  // src/models/bank.ts
23828
23866
  var Bank = class _Bank {
23829
- constructor(address23, mint, mintDecimals, group, assetShareValue, liabilityShareValue, liquidityVault, liquidityVaultBump, liquidityVaultAuthorityBump, insuranceVault, insuranceVaultBump, insuranceVaultAuthorityBump, collectedInsuranceFeesOutstanding, feeVault, feeVaultBump, feeVaultAuthorityBump, collectedGroupFeesOutstanding, lastUpdate, config, totalAssetShares, totalLiabilityShares, emissionsActiveBorrowing, emissionsActiveLending, emissionsRate, emissionsMint, emissionsRemaining, collectedProgramFeesOutstanding, oracleKey, emode, premiumTag, premiumActive, premiumActivatedAt, kaminoEmergency, stakedOracleDisabled, stakedOracleUsesOnramp, rateLimiter, kaminoIntegrationAccounts, driftIntegrationAccounts, solendIntegrationAccounts, jupLendIntegrationAccounts, stakedIntegrationAccounts, feesDestinationAccount, lendingPositionCount, borrowingPositionCount, tokenSymbol) {
23867
+ constructor(address23, mint, mintDecimals, group, assetShareValue, liabilityShareValue, liquidityVault, liquidityVaultBump, liquidityVaultAuthorityBump, insuranceVault, insuranceVaultBump, insuranceVaultAuthorityBump, collectedInsuranceFeesOutstanding, feeVault, feeVaultBump, feeVaultAuthorityBump, collectedGroupFeesOutstanding, lastUpdate, config, totalAssetShares, totalLiabilityShares, emissionsActiveBorrowing, emissionsActiveLending, emissionsRate, emissionsMint, emissionsRemaining, collectedProgramFeesOutstanding, oracleKey, emode, premiumTag, premiumActive, premiumActivatedAt, kaminoEmergency, liquidationLiquidatorFee, liquidationInsuranceFee, isCircuitBreakerEnabled, cbTier, cbHaltEndedAt, stakedOracleDisabled, stakedOracleUsesOnramp, rateLimiter, kaminoIntegrationAccounts, driftIntegrationAccounts, solendIntegrationAccounts, jupLendIntegrationAccounts, stakedIntegrationAccounts, feesDestinationAccount, lendingPositionCount, borrowingPositionCount, tokenSymbol) {
23830
23868
  this.address = address23;
23831
23869
  this.mint = mint;
23832
23870
  this.mintDecimals = mintDecimals;
@@ -23860,6 +23898,11 @@ var Bank = class _Bank {
23860
23898
  this.premiumActive = premiumActive;
23861
23899
  this.premiumActivatedAt = premiumActivatedAt;
23862
23900
  this.kaminoEmergency = kaminoEmergency;
23901
+ this.liquidationLiquidatorFee = liquidationLiquidatorFee;
23902
+ this.liquidationInsuranceFee = liquidationInsuranceFee;
23903
+ this.isCircuitBreakerEnabled = isCircuitBreakerEnabled;
23904
+ this.cbTier = cbTier;
23905
+ this.cbHaltEndedAt = cbHaltEndedAt;
23863
23906
  this.stakedOracleDisabled = stakedOracleDisabled;
23864
23907
  this.stakedOracleUsesOnramp = stakedOracleUsesOnramp;
23865
23908
  this.rateLimiter = rateLimiter;
@@ -23907,6 +23950,9 @@ var Bank = class _Bank {
23907
23950
  bankType.config.operationalState,
23908
23951
  bankType.config.oracleMaxConfidence,
23909
23952
  bankType.config.fixedPrice,
23953
+ bankType.config.cbWindowMaxUpBps,
23954
+ bankType.config.cbWindowMaxDownBps,
23955
+ bankType.config.cbWindowSeconds,
23910
23956
  bankType.config.configFlags,
23911
23957
  bankType.config.scopeEntryIndex
23912
23958
  );
@@ -23944,6 +23990,11 @@ var Bank = class _Bank {
23944
23990
  bankType.premiumActive,
23945
23991
  bankType.premiumActivatedAt,
23946
23992
  bankType.kaminoEmergency,
23993
+ bankType.liquidationLiquidatorFee,
23994
+ bankType.liquidationInsuranceFee,
23995
+ bankType.isCircuitBreakerEnabled,
23996
+ bankType.cbTier,
23997
+ bankType.cbHaltEndedAt,
23947
23998
  bankType.stakedOracleDisabled,
23948
23999
  bankType.stakedOracleUsesOnramp,
23949
24000
  bankType.rateLimiter,
@@ -24088,7 +24139,7 @@ var Bank = class _Bank {
24088
24139
  }
24089
24140
  };
24090
24141
  var BankConfig = class {
24091
- constructor(assetWeightInit, assetWeightMaint, liabilityWeightInit, liabilityWeightMaint, depositLimit, borrowLimit, riskTier, totalAssetValueInitLimit, assetTag, oracleSetup, oracleKeys, oracleMaxAge, interestRateConfig, operationalState, oracleMaxConfidence, fixedPrice, configFlags, scopeEntryIndex) {
24142
+ constructor(assetWeightInit, assetWeightMaint, liabilityWeightInit, liabilityWeightMaint, depositLimit, borrowLimit, riskTier, totalAssetValueInitLimit, assetTag, oracleSetup, oracleKeys, oracleMaxAge, interestRateConfig, operationalState, oracleMaxConfidence, fixedPrice, cbWindowMaxUpBps, cbWindowMaxDownBps, cbWindowSeconds, configFlags, scopeEntryIndex) {
24092
24143
  this.assetWeightInit = assetWeightInit;
24093
24144
  this.assetWeightMaint = assetWeightMaint;
24094
24145
  this.liabilityWeightInit = liabilityWeightInit;
@@ -24105,6 +24156,9 @@ var BankConfig = class {
24105
24156
  this.operationalState = operationalState;
24106
24157
  this.oracleMaxConfidence = oracleMaxConfidence;
24107
24158
  this.fixedPrice = fixedPrice;
24159
+ this.cbWindowMaxUpBps = cbWindowMaxUpBps;
24160
+ this.cbWindowMaxDownBps = cbWindowMaxDownBps;
24161
+ this.cbWindowSeconds = cbWindowSeconds;
24108
24162
  this.configFlags = configFlags;
24109
24163
  this.scopeEntryIndex = scopeEntryIndex;
24110
24164
  }
@@ -24643,7 +24697,7 @@ var MarginfiAccountWrapper = class {
24643
24697
  }
24644
24698
  /**
24645
24699
  * Withdraw instructions for `amount` (UI units) from `bankAddress`; `withdrawAll` closes the
24646
- * balance.
24700
+ * balance. `opts.groupRateLimiterEnabled` defaults to the group's limiter state.
24647
24701
  * @throws Error if `amount` isn't positive without `withdrawAll`
24648
24702
  */
24649
24703
  async makeWithdrawIx(bankAddress, amount, withdrawAll = false, opts = {}) {
@@ -24654,7 +24708,10 @@ var MarginfiAccountWrapper = class {
24654
24708
  ...await this.lendingContext(bankAddress),
24655
24709
  amount,
24656
24710
  withdrawAll,
24657
- opts
24711
+ opts: {
24712
+ groupRateLimiterEnabled: isGroupRateLimiterEnabled(this.client.group.rateLimiter),
24713
+ ...opts
24714
+ }
24658
24715
  });
24659
24716
  }
24660
24717
  /**
@@ -24684,14 +24741,17 @@ var MarginfiAccountWrapper = class {
24684
24741
  }
24685
24742
  /**
24686
24743
  * Withdraw transaction for `amount` (UI units) from `bankAddress`; `withdrawAll` closes the
24687
- * balance.
24744
+ * balance. `opts.groupRateLimiterEnabled` defaults to the group's limiter state.
24688
24745
  */
24689
24746
  async makeWithdrawTx(bankAddress, amount, withdrawAll = false, opts = {}) {
24690
24747
  return this.account.makeWithdrawTx({
24691
24748
  ...await this.lendingContext(bankAddress),
24692
24749
  amount,
24693
24750
  withdrawAll,
24694
- opts
24751
+ opts: {
24752
+ groupRateLimiterEnabled: isGroupRateLimiterEnabled(this.client.group.rateLimiter),
24753
+ ...opts
24754
+ }
24695
24755
  });
24696
24756
  }
24697
24757
  /** Borrow transaction for `amount` (UI units) from `bankAddress`. */
@@ -25308,6 +25368,7 @@ exports.Balance = Balance;
25308
25368
  exports.Bank = Bank;
25309
25369
  exports.BankConfig = BankConfig;
25310
25370
  exports.BankConfigFlag = BankConfigFlag;
25371
+ exports.CIRCUIT_BREAKER_ENABLED_FLAG = CIRCUIT_BREAKER_ENABLED_FLAG;
25311
25372
  exports.DEFAULT_ADDRESS = DEFAULT_ADDRESS;
25312
25373
  exports.DEFAULT_BRIDGE_MINTS = DEFAULT_BRIDGE_MINTS;
25313
25374
  exports.DEFAULT_ORACLE_MAX_AGE = DEFAULT_ORACLE_MAX_AGE;
@@ -25552,6 +25613,7 @@ exports.getAssetShares = getAssetShares;
25552
25613
  exports.getAssetWeight = getAssetWeight;
25553
25614
  exports.getBalance = getBalance;
25554
25615
  exports.getBalanceUsdValueWithPriceBias = getBalanceUsdValueWithPriceBias;
25616
+ exports.getBankLiquidationFees = getBankLiquidationFees;
25555
25617
  exports.getConfig = getConfig;
25556
25618
  exports.getEffectiveDepositLimit = getEffectiveDepositLimit;
25557
25619
  exports.getEmodePairs = getEmodePairs;
@@ -25580,6 +25642,7 @@ exports.hasEmodeEntryFlag = hasEmodeEntryFlag;
25580
25642
  exports.hasEmodeFlag = hasEmodeFlag;
25581
25643
  exports.hasHealthCacheFlag = hasHealthCacheFlag;
25582
25644
  exports.healthCacheToDto = healthCacheToDto;
25645
+ exports.isBankCircuitBreakerHalted = isBankCircuitBreakerHalted;
25583
25646
  exports.isBorrowLimitActive = isBorrowLimitActive;
25584
25647
  exports.isBridgeConflictError = isBridgeConflictError;
25585
25648
  exports.isCostlyBank = isCostlyBank;