@indigo-labs/indigo-sdk 0.6.0 → 0.6.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.d.mts CHANGED
@@ -3553,10 +3553,26 @@ declare function spMul(a: SPInteger, b: SPInteger): SPInteger;
3553
3553
  declare function spDiv(a: SPInteger, b: SPInteger): SPInteger;
3554
3554
  declare function spZeroNegatives(a: SPInteger): SPInteger;
3555
3555
 
3556
+ /**
3557
+ * Number of slots back in time that are considered safe.
3558
+ * Otherwise, currentSlot might not succeed to be submitted.
3559
+ */
3560
+ declare const SP_LEDGER_SLOT_BUFFER = 20;
3556
3561
  declare const BASE_MAX_TX_FEE = 1250000n;
3557
3562
  declare const MAX_E2S2S_ENTRIES_COUNT = 5;
3558
3563
  declare const initSumVal: SPInteger;
3559
3564
  declare const initSpState: StateSnapshot;
3565
+ /**
3566
+ * Uses bias/2 distance from current time to validFrom and validTo as well.
3567
+ * When the cooldown isn't passed in that case, use validFrom closer to current time
3568
+ * still keeping some buffer for it to have higher probability to succeed.
3569
+ *
3570
+ * Returns `null` when the cooldown hasn't passed yet.
3571
+ */
3572
+ declare function getSpProcessingValidityRange(lucid: LucidEvolution, currentSlot: number, sysParams: SystemParams, accountDatum: AccountContent): {
3573
+ validateFrom: number;
3574
+ validateTo: number;
3575
+ } | null;
3560
3576
  declare function mkStabilityPoolAddr(lucid: LucidEvolution, sysParams: SystemParams): Address;
3561
3577
  declare function isSameEpochToScaleKey(a: EpochToScaleKey, b: EpochToScaleKey): boolean;
3562
3578
  type StabilityPoolListIdx = {
@@ -3676,7 +3692,7 @@ declare function processSpRequest(stabilityPoolUtxo: UTxO, accountUtxo: UTxO, iA
3676
3692
  /**
3677
3693
  * For performance provide only the ones related to the pool's iAsset.
3678
3694
  */
3679
- allE2s2sSnapshotOrefs: OutRef[], sysParams: SystemParams, lucid: LucidEvolution, currentSlot?: number): Promise<TxBuilder>;
3695
+ allE2s2sSnapshotOrefs: OutRef[], sysParams: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
3680
3696
  declare function createE2s2sSnapshots(stabilityPoolOref: OutRef, sysParams: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
3681
3697
  declare function annulRequest(accountUtxo: UTxO, params: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
3682
3698
 
@@ -4792,4 +4808,4 @@ declare function mkAuthTokenPolicy(ac: AssetClass, tn: string): MintingPolicy;
4792
4808
 
4793
4809
  declare const alwaysFailValidator: SpendingValidator;
4794
4810
 
4795
- export { type AccountAction, type AccountContent, AccountContentSchema, type ActionReturnDatum, type AddCollateralAsssetContent, type AddressCredential, type AddressCredentialOrDatum, type AddressSP, AikenIntervalIntervalBound, AikenIntervalIntervalBoundType, type Amount, type AssetClassD, type AssetClassSP, AssetClassSchema, type AssetInfo, type AssetSnapshot, type AssetState, type AuthTokenPolicies, BASE_MAX_EXECUTION_FEE, BASE_MAX_TX_FEE, BigIntOrd, type CDPContent, CDPCreatorParams, type CDPCreatorParamsSP, type CDPDatum, CardanoTransactionValidityRange, type CdpParams, type CdpParamsSP, type CdpRedeemParams, type CdpRedeemParamsSP, type CdpRedeemer, type CollateralAssetContent, type CollateralAssetInfo, type CollateralAssetOutput, type CollectorParamsSP, type CollectorRedeemer, CollectorRedeemerSchema, CredentialD, CredentialSchema, type CurrencySymbolSP, DEFAULT_INIT_OPTIONS, type DerivedPythPrice, type DerivedPythPriceSP, DerivedPythPriceSchema, type E2S2SIndex, type E2S2SIndicesPerAsset, type EpochToScaleKey, type EpochToScaleToSumEntry, type ExecuteDatum, ExecuteParams, type ExecuteParamsSP, type Feed, type FindE2S2SIdxResult, type GovDatum, GovParams, type GovParamsSP, type GovRedeemer, type IAssetContent, type IAssetDatum, type IAssetOutput, type IAssetParamsSP, type IAssetPriceInfo, IAssetPriceInfoSchema, type IAssetRedeemer, IAssetScriptParams, INIT_TOKEN_NAMES, type IndigoOracleNftParam, type InitialAssetParam, type InitialCollateralAssetParam, type InitialStablepoolParam, type InitializeOptions, type Input, type InterestCollectionDatum, type InterestCollectionParams, type InterestCollectionParamsSP, InterestCollectionParamsSchema, type InterestCollectionRedeemer, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type InterestOracleRedeemer, type LoanAdjustments, MAX_BUY_ROB_REDEMPTIONS_COUNT, MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET, MAX_E2S2S_ENTRIES_COUNT, MAX_REDEMPTIONS_WITH_CDP_OPEN, MAX_SELL_ROB_REDEMPTIONS_COUNT, MIN_ROB_COLLATERAL_AMT, type MarketSession, type ModifyStableswapPoolContent, ONE_DAY, ONE_HOUR, ONE_SECOND, ONE_YEAR, type OneShotParams, OneShotParamsSchema, type OracleIdx, OracleIdxSchema, type Output, PRICE_UPDATE_MAGIC, type PSMProcessingConfig, type ParsedOutput, type PollDatum, type PollManagerContent, PollManagerParams, type PollManagerParamsSP, type PollManagerRedeemer, type PollShardContent, PollShardParams, type PollShardParamsSP, type PollShardRedeemer, type PollStatus, type PriceOracleDatum, type PriceOracleParam, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PriceUpdate, type ProcessRequestAccountContent, type ProposalContent, ProposalContentSchema, type ProposeAssetContent, type ProposeStableswapPoolContent, type ProtocolParams, ProtocolParamsSchema, type PubKeyHash, type PythConfig, type PythConfiguration, type PythFeedConfig, type PythFeedParams, type PythFeedParamsSP, type PythFeedRedeemer, type PythMessageParts, type PythOracleParam, type PythPriceConfigurationSP, type PythStateDatum, type PythUpdatesRedeemer, type Rational, RationalSchema, type RedeemCdpWithdrawalRedeemer, type RobDatum, type RobOrderType, type RobOutput, type RobParams, type RobParamsSP, RobParamsSchema, type RobRedeemer, SOLANA_FORMAT_MAGIC, type SPInteger, SPIntegerSchema, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, type SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, type StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, type StabilityPoolRedeemer, StabilityPoolRedeemerSchema, type StableswapInfo, type StableswapOrderDatum, StableswapOrderDatumSchema, type StableswapOrderInfo, type StableswapOrderRedeemer, type StableswapOutputDatum, type StableswapParamsSP, type StableswapPoolContent, StakeCredential, StakeCredentialSchema, type StakingManager, type StakingManagerOutput, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingPositionOutput, type StakingRedeemer, type StartTime, type StateSnapshot, type SubmissionConfig, type SumSnapshot, type SystemParams, type TokenNameSP, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type UpgradePaths, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, adjustCdp, adjustPriceToDecimals, adjustRob, adjustStakingPosition, alwaysFailValidator, annulRequest, approximateLeverageRedemptions, attachOracle, balance, batchCollectInterest, batchProcessStableswapOrders, bigintMax, bigintMin, buildRedemptionsTx, burnCdp, calculateAccruedInterest, calculateAdaReward, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculatePurchaseAmtWhenRobBuyOrder, calculatePurchaseAmtWhenRobSellOrder, calculateSpendAmtWhenRobBuyOrder, calculateSpendAmtWhenRobSellOrder, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castOneShotParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectPriceFeedIds, collectorFeeTx, computeEffectiveCdpState, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, derivePythPrice, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateMinOrderOutputLovelaces, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findAdminInterestCollectors, findAllInterestCollectors, findAllStableswapPools, findAllTreasuryUtxos, findAllTreasuryUtxosWithNonAdaAsset, findCollateralAsset, findE2s2sSnapshots, findIAsset, findInterestOracle, findRandomCdpCreator, findRandomNonAdminInterestCollector, findRandomTreasuryUtxo, findRandomTreasuryUtxoWithAsset, findRandomTreasuryUtxoWithOnlyAda, findRelevantE2s2sIdxs, findStabilityPool, findStabilityPoolAccount, findStableswapPool, findStakingManager, findStakingManagerByOutRef, findStakingPositionByOutRef, freezeCdp, fromDataDerivedPythPrice, fromDecimal, fromSPInteger, fromSysParamsCredential, fromSysParamsDerivedPythPrice, fromSysParamsPythFeedParams, fromSysParamsStakeCredential, fromSystemParamsAsset, fromSystemParamsAssetLucid, fromSystemParamsScriptRef, getAssetClassComparisonStr, getInlineDatumOrThrow, getPythFeedConfig, getUpdatedAccountDeposit, handleOracleForCollateralAsset, iassetValueOfCollateral, init, initCDPCreator, initCollector, initGovernance, initInterestCollector, initPythConfig, initSpState, initStakingManager, initSumVal, initTreasury, initializeAsset, insertSorted, isBuyOrderFullyRedeemed, isFullyRedeemed, isSameEpochToScaleKey, leverageCdpWithRob, liquidateCdp, liquidationHelper, loadSystemParamsFromFile, loadSystemParamsFromUrl, matchSingle, mergeCdps, mergeShards, mintAuthTokenDirect, mintCdp, mintOneTimeAsset, mintOneTimeToken, mkAuthTokenPolicy, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkCdpRedeemValidatorFromSP, mkCdpValidatorFromSP, mkCollectorValidatorFromSP, mkExecuteValidator, mkExecuteValidatorFromSP, mkGovValidator, mkGovValidatorFromSP, mkIAssetTokenPolicy, mkIAssetValidatorFromSP, mkInterestCollectionValidator, mkInterestCollectionValidatorFromSP, mkInterestOracleValidator, mkOneShotPolicy, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkPriceOracleValidator, mkPythFeedValidator, mkRobValidator, mkRobValidatorFromSP, mkSPInteger, mkStabilityPoolAddr, mkStabilityPoolValidator, mkStabilityPoolValidatorFromSP, mkStableswapValidator, mkStableswapValidatorFromSP, mkStakingValidatorFromSP, mkTreasuryAddr, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, numberToRational, oneShotMintTx, openCdp, openRob, openStakingPosition, parseAccountDatum, parseAccountDatumOrThrow, parseCdpDatum, parseCdpDatumOrThrow, parseCdpRedeemer, parseCdpRedeemerOrThrow, parseCollateralAssetDatum, parseCollateralAssetDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestCollectionDatum, parseInterestOracleDatum, parsePollManager, parsePollManagerOrThrow, parsePollShard, parsePollShardOrThrow, parsePollShardRedeemer, parsePollShardRedeemerOrThrow, parsePriceOracleDatum, parsePythStateDatum, parseRobDatum, parseRobDatumOrThrow, parseRobRedeemer, parseRobRedeemerOrThrow, parseSnapshotEpochToScaleToSumDatum, parseSnapshotEpochToScaleToSumDatumOrThrow, parseStabilityPoolDatum, parseStabilityPoolDatumOrThrow, parseStabilityPoolRedeemer, parseStabilityPoolRedeemerOrThrow, parseStableswapOrderDatum, parseStableswapOrderDatumOrThrow, parseStableswapOrderRedeemer, parseStableswapOrderRedeemerOrThrow, parseStableswapPoolDatum, parseStableswapPoolDatumOrThrow, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, parseStakingRedeemer, parseStakingRedeemerOrThrow, partitionEpochToScaleToSums, pickValidSatisfiableOrders, processSpRequest, psmOrderType, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, rewardsPerAsset, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, runAndAwaitTxBuilder, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseActionReturnDatum, serialiseCdpDatum, serialiseCdpRedeemer, serialiseCollectorRedeemer, serialiseExecuteDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseGovRedeemer, serialiseIAssetDatum, serialiseIAssetRedeemer, serialiseInterestCollectionDatum, serialiseInterestCollectionRedeemer, serialiseInterestOracleDatum, serialisePollDatum, serialisePollManagerRedeemer, serialisePollShardRedeemer, serialisePriceOracleDatum, serialisePriceOracleRedeemer, serialisePythFeedParams, serialisePythFeedRedeemer, serialisePythStateDatum, serialisePythUpdatesRedeemer, serialiseRedeemCdpWithdrawalRedeemer, serialiseRobDatum, serialiseRobRedeemer, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, serialiseStableswapOrderDatum, serialiseStableswapOrderRedeemer, serialiseStableswapOutputDatum, serialiseStableswapPoolDatum, serialiseStakingDatum, serialiseStakingRedeemer, shuffle, signersAllOf, spAdd, spDiv, spMul, spSub, spZeroNegatives, startInterestOracle, startPriceOracleTx, sum, summariseOrder, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, toSystemParamsInput, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
4811
+ export { type AccountAction, type AccountContent, AccountContentSchema, type ActionReturnDatum, type AddCollateralAsssetContent, type AddressCredential, type AddressCredentialOrDatum, type AddressSP, AikenIntervalIntervalBound, AikenIntervalIntervalBoundType, type Amount, type AssetClassD, type AssetClassSP, AssetClassSchema, type AssetInfo, type AssetSnapshot, type AssetState, type AuthTokenPolicies, BASE_MAX_EXECUTION_FEE, BASE_MAX_TX_FEE, BigIntOrd, type CDPContent, CDPCreatorParams, type CDPCreatorParamsSP, type CDPDatum, CardanoTransactionValidityRange, type CdpParams, type CdpParamsSP, type CdpRedeemParams, type CdpRedeemParamsSP, type CdpRedeemer, type CollateralAssetContent, type CollateralAssetInfo, type CollateralAssetOutput, type CollectorParamsSP, type CollectorRedeemer, CollectorRedeemerSchema, CredentialD, CredentialSchema, type CurrencySymbolSP, DEFAULT_INIT_OPTIONS, type DerivedPythPrice, type DerivedPythPriceSP, DerivedPythPriceSchema, type E2S2SIndex, type E2S2SIndicesPerAsset, type EpochToScaleKey, type EpochToScaleToSumEntry, type ExecuteDatum, ExecuteParams, type ExecuteParamsSP, type Feed, type FindE2S2SIdxResult, type GovDatum, GovParams, type GovParamsSP, type GovRedeemer, type IAssetContent, type IAssetDatum, type IAssetOutput, type IAssetParamsSP, type IAssetPriceInfo, IAssetPriceInfoSchema, type IAssetRedeemer, IAssetScriptParams, INIT_TOKEN_NAMES, type IndigoOracleNftParam, type InitialAssetParam, type InitialCollateralAssetParam, type InitialStablepoolParam, type InitializeOptions, type Input, type InterestCollectionDatum, type InterestCollectionParams, type InterestCollectionParamsSP, InterestCollectionParamsSchema, type InterestCollectionRedeemer, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type InterestOracleRedeemer, type LoanAdjustments, MAX_BUY_ROB_REDEMPTIONS_COUNT, MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET, MAX_E2S2S_ENTRIES_COUNT, MAX_REDEMPTIONS_WITH_CDP_OPEN, MAX_SELL_ROB_REDEMPTIONS_COUNT, MIN_ROB_COLLATERAL_AMT, type MarketSession, type ModifyStableswapPoolContent, ONE_DAY, ONE_HOUR, ONE_SECOND, ONE_YEAR, type OneShotParams, OneShotParamsSchema, type OracleIdx, OracleIdxSchema, type Output, PRICE_UPDATE_MAGIC, type PSMProcessingConfig, type ParsedOutput, type PollDatum, type PollManagerContent, PollManagerParams, type PollManagerParamsSP, type PollManagerRedeemer, type PollShardContent, PollShardParams, type PollShardParamsSP, type PollShardRedeemer, type PollStatus, type PriceOracleDatum, type PriceOracleParam, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PriceUpdate, type ProcessRequestAccountContent, type ProposalContent, ProposalContentSchema, type ProposeAssetContent, type ProposeStableswapPoolContent, type ProtocolParams, ProtocolParamsSchema, type PubKeyHash, type PythConfig, type PythConfiguration, type PythFeedConfig, type PythFeedParams, type PythFeedParamsSP, type PythFeedRedeemer, type PythMessageParts, type PythOracleParam, type PythPriceConfigurationSP, type PythStateDatum, type PythUpdatesRedeemer, type Rational, RationalSchema, type RedeemCdpWithdrawalRedeemer, type RobDatum, type RobOrderType, type RobOutput, type RobParams, type RobParamsSP, RobParamsSchema, type RobRedeemer, SOLANA_FORMAT_MAGIC, type SPInteger, SPIntegerSchema, SP_LEDGER_SLOT_BUFFER, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, type SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, type StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, type StabilityPoolRedeemer, StabilityPoolRedeemerSchema, type StableswapInfo, type StableswapOrderDatum, StableswapOrderDatumSchema, type StableswapOrderInfo, type StableswapOrderRedeemer, type StableswapOutputDatum, type StableswapParamsSP, type StableswapPoolContent, StakeCredential, StakeCredentialSchema, type StakingManager, type StakingManagerOutput, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingPositionOutput, type StakingRedeemer, type StartTime, type StateSnapshot, type SubmissionConfig, type SumSnapshot, type SystemParams, type TokenNameSP, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type UpgradePaths, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, adjustCdp, adjustPriceToDecimals, adjustRob, adjustStakingPosition, alwaysFailValidator, annulRequest, approximateLeverageRedemptions, attachOracle, balance, batchCollectInterest, batchProcessStableswapOrders, bigintMax, bigintMin, buildRedemptionsTx, burnCdp, calculateAccruedInterest, calculateAdaReward, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculatePurchaseAmtWhenRobBuyOrder, calculatePurchaseAmtWhenRobSellOrder, calculateSpendAmtWhenRobBuyOrder, calculateSpendAmtWhenRobSellOrder, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castOneShotParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectPriceFeedIds, collectorFeeTx, computeEffectiveCdpState, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, derivePythPrice, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateMinOrderOutputLovelaces, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findAdminInterestCollectors, findAllInterestCollectors, findAllStableswapPools, findAllTreasuryUtxos, findAllTreasuryUtxosWithNonAdaAsset, findCollateralAsset, findE2s2sSnapshots, findIAsset, findInterestOracle, findRandomCdpCreator, findRandomNonAdminInterestCollector, findRandomTreasuryUtxo, findRandomTreasuryUtxoWithAsset, findRandomTreasuryUtxoWithOnlyAda, findRelevantE2s2sIdxs, findStabilityPool, findStabilityPoolAccount, findStableswapPool, findStakingManager, findStakingManagerByOutRef, findStakingPositionByOutRef, freezeCdp, fromDataDerivedPythPrice, fromDecimal, fromSPInteger, fromSysParamsCredential, fromSysParamsDerivedPythPrice, fromSysParamsPythFeedParams, fromSysParamsStakeCredential, fromSystemParamsAsset, fromSystemParamsAssetLucid, fromSystemParamsScriptRef, getAssetClassComparisonStr, getInlineDatumOrThrow, getPythFeedConfig, getSpProcessingValidityRange, getUpdatedAccountDeposit, handleOracleForCollateralAsset, iassetValueOfCollateral, init, initCDPCreator, initCollector, initGovernance, initInterestCollector, initPythConfig, initSpState, initStakingManager, initSumVal, initTreasury, initializeAsset, insertSorted, isBuyOrderFullyRedeemed, isFullyRedeemed, isSameEpochToScaleKey, leverageCdpWithRob, liquidateCdp, liquidationHelper, loadSystemParamsFromFile, loadSystemParamsFromUrl, matchSingle, mergeCdps, mergeShards, mintAuthTokenDirect, mintCdp, mintOneTimeAsset, mintOneTimeToken, mkAuthTokenPolicy, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkCdpRedeemValidatorFromSP, mkCdpValidatorFromSP, mkCollectorValidatorFromSP, mkExecuteValidator, mkExecuteValidatorFromSP, mkGovValidator, mkGovValidatorFromSP, mkIAssetTokenPolicy, mkIAssetValidatorFromSP, mkInterestCollectionValidator, mkInterestCollectionValidatorFromSP, mkInterestOracleValidator, mkOneShotPolicy, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkPriceOracleValidator, mkPythFeedValidator, mkRobValidator, mkRobValidatorFromSP, mkSPInteger, mkStabilityPoolAddr, mkStabilityPoolValidator, mkStabilityPoolValidatorFromSP, mkStableswapValidator, mkStableswapValidatorFromSP, mkStakingValidatorFromSP, mkTreasuryAddr, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, numberToRational, oneShotMintTx, openCdp, openRob, openStakingPosition, parseAccountDatum, parseAccountDatumOrThrow, parseCdpDatum, parseCdpDatumOrThrow, parseCdpRedeemer, parseCdpRedeemerOrThrow, parseCollateralAssetDatum, parseCollateralAssetDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestCollectionDatum, parseInterestOracleDatum, parsePollManager, parsePollManagerOrThrow, parsePollShard, parsePollShardOrThrow, parsePollShardRedeemer, parsePollShardRedeemerOrThrow, parsePriceOracleDatum, parsePythStateDatum, parseRobDatum, parseRobDatumOrThrow, parseRobRedeemer, parseRobRedeemerOrThrow, parseSnapshotEpochToScaleToSumDatum, parseSnapshotEpochToScaleToSumDatumOrThrow, parseStabilityPoolDatum, parseStabilityPoolDatumOrThrow, parseStabilityPoolRedeemer, parseStabilityPoolRedeemerOrThrow, parseStableswapOrderDatum, parseStableswapOrderDatumOrThrow, parseStableswapOrderRedeemer, parseStableswapOrderRedeemerOrThrow, parseStableswapPoolDatum, parseStableswapPoolDatumOrThrow, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, parseStakingRedeemer, parseStakingRedeemerOrThrow, partitionEpochToScaleToSums, pickValidSatisfiableOrders, processSpRequest, psmOrderType, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, rewardsPerAsset, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, runAndAwaitTxBuilder, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseActionReturnDatum, serialiseCdpDatum, serialiseCdpRedeemer, serialiseCollectorRedeemer, serialiseExecuteDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseGovRedeemer, serialiseIAssetDatum, serialiseIAssetRedeemer, serialiseInterestCollectionDatum, serialiseInterestCollectionRedeemer, serialiseInterestOracleDatum, serialisePollDatum, serialisePollManagerRedeemer, serialisePollShardRedeemer, serialisePriceOracleDatum, serialisePriceOracleRedeemer, serialisePythFeedParams, serialisePythFeedRedeemer, serialisePythStateDatum, serialisePythUpdatesRedeemer, serialiseRedeemCdpWithdrawalRedeemer, serialiseRobDatum, serialiseRobRedeemer, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, serialiseStableswapOrderDatum, serialiseStableswapOrderRedeemer, serialiseStableswapOutputDatum, serialiseStableswapPoolDatum, serialiseStakingDatum, serialiseStakingRedeemer, shuffle, signersAllOf, spAdd, spDiv, spMul, spSub, spZeroNegatives, startInterestOracle, startPriceOracleTx, sum, summariseOrder, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, toSystemParamsInput, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
package/dist/index.d.ts CHANGED
@@ -3553,10 +3553,26 @@ declare function spMul(a: SPInteger, b: SPInteger): SPInteger;
3553
3553
  declare function spDiv(a: SPInteger, b: SPInteger): SPInteger;
3554
3554
  declare function spZeroNegatives(a: SPInteger): SPInteger;
3555
3555
 
3556
+ /**
3557
+ * Number of slots back in time that are considered safe.
3558
+ * Otherwise, currentSlot might not succeed to be submitted.
3559
+ */
3560
+ declare const SP_LEDGER_SLOT_BUFFER = 20;
3556
3561
  declare const BASE_MAX_TX_FEE = 1250000n;
3557
3562
  declare const MAX_E2S2S_ENTRIES_COUNT = 5;
3558
3563
  declare const initSumVal: SPInteger;
3559
3564
  declare const initSpState: StateSnapshot;
3565
+ /**
3566
+ * Uses bias/2 distance from current time to validFrom and validTo as well.
3567
+ * When the cooldown isn't passed in that case, use validFrom closer to current time
3568
+ * still keeping some buffer for it to have higher probability to succeed.
3569
+ *
3570
+ * Returns `null` when the cooldown hasn't passed yet.
3571
+ */
3572
+ declare function getSpProcessingValidityRange(lucid: LucidEvolution, currentSlot: number, sysParams: SystemParams, accountDatum: AccountContent): {
3573
+ validateFrom: number;
3574
+ validateTo: number;
3575
+ } | null;
3560
3576
  declare function mkStabilityPoolAddr(lucid: LucidEvolution, sysParams: SystemParams): Address;
3561
3577
  declare function isSameEpochToScaleKey(a: EpochToScaleKey, b: EpochToScaleKey): boolean;
3562
3578
  type StabilityPoolListIdx = {
@@ -3676,7 +3692,7 @@ declare function processSpRequest(stabilityPoolUtxo: UTxO, accountUtxo: UTxO, iA
3676
3692
  /**
3677
3693
  * For performance provide only the ones related to the pool's iAsset.
3678
3694
  */
3679
- allE2s2sSnapshotOrefs: OutRef[], sysParams: SystemParams, lucid: LucidEvolution, currentSlot?: number): Promise<TxBuilder>;
3695
+ allE2s2sSnapshotOrefs: OutRef[], sysParams: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
3680
3696
  declare function createE2s2sSnapshots(stabilityPoolOref: OutRef, sysParams: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
3681
3697
  declare function annulRequest(accountUtxo: UTxO, params: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
3682
3698
 
@@ -4792,4 +4808,4 @@ declare function mkAuthTokenPolicy(ac: AssetClass, tn: string): MintingPolicy;
4792
4808
 
4793
4809
  declare const alwaysFailValidator: SpendingValidator;
4794
4810
 
4795
- export { type AccountAction, type AccountContent, AccountContentSchema, type ActionReturnDatum, type AddCollateralAsssetContent, type AddressCredential, type AddressCredentialOrDatum, type AddressSP, AikenIntervalIntervalBound, AikenIntervalIntervalBoundType, type Amount, type AssetClassD, type AssetClassSP, AssetClassSchema, type AssetInfo, type AssetSnapshot, type AssetState, type AuthTokenPolicies, BASE_MAX_EXECUTION_FEE, BASE_MAX_TX_FEE, BigIntOrd, type CDPContent, CDPCreatorParams, type CDPCreatorParamsSP, type CDPDatum, CardanoTransactionValidityRange, type CdpParams, type CdpParamsSP, type CdpRedeemParams, type CdpRedeemParamsSP, type CdpRedeemer, type CollateralAssetContent, type CollateralAssetInfo, type CollateralAssetOutput, type CollectorParamsSP, type CollectorRedeemer, CollectorRedeemerSchema, CredentialD, CredentialSchema, type CurrencySymbolSP, DEFAULT_INIT_OPTIONS, type DerivedPythPrice, type DerivedPythPriceSP, DerivedPythPriceSchema, type E2S2SIndex, type E2S2SIndicesPerAsset, type EpochToScaleKey, type EpochToScaleToSumEntry, type ExecuteDatum, ExecuteParams, type ExecuteParamsSP, type Feed, type FindE2S2SIdxResult, type GovDatum, GovParams, type GovParamsSP, type GovRedeemer, type IAssetContent, type IAssetDatum, type IAssetOutput, type IAssetParamsSP, type IAssetPriceInfo, IAssetPriceInfoSchema, type IAssetRedeemer, IAssetScriptParams, INIT_TOKEN_NAMES, type IndigoOracleNftParam, type InitialAssetParam, type InitialCollateralAssetParam, type InitialStablepoolParam, type InitializeOptions, type Input, type InterestCollectionDatum, type InterestCollectionParams, type InterestCollectionParamsSP, InterestCollectionParamsSchema, type InterestCollectionRedeemer, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type InterestOracleRedeemer, type LoanAdjustments, MAX_BUY_ROB_REDEMPTIONS_COUNT, MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET, MAX_E2S2S_ENTRIES_COUNT, MAX_REDEMPTIONS_WITH_CDP_OPEN, MAX_SELL_ROB_REDEMPTIONS_COUNT, MIN_ROB_COLLATERAL_AMT, type MarketSession, type ModifyStableswapPoolContent, ONE_DAY, ONE_HOUR, ONE_SECOND, ONE_YEAR, type OneShotParams, OneShotParamsSchema, type OracleIdx, OracleIdxSchema, type Output, PRICE_UPDATE_MAGIC, type PSMProcessingConfig, type ParsedOutput, type PollDatum, type PollManagerContent, PollManagerParams, type PollManagerParamsSP, type PollManagerRedeemer, type PollShardContent, PollShardParams, type PollShardParamsSP, type PollShardRedeemer, type PollStatus, type PriceOracleDatum, type PriceOracleParam, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PriceUpdate, type ProcessRequestAccountContent, type ProposalContent, ProposalContentSchema, type ProposeAssetContent, type ProposeStableswapPoolContent, type ProtocolParams, ProtocolParamsSchema, type PubKeyHash, type PythConfig, type PythConfiguration, type PythFeedConfig, type PythFeedParams, type PythFeedParamsSP, type PythFeedRedeemer, type PythMessageParts, type PythOracleParam, type PythPriceConfigurationSP, type PythStateDatum, type PythUpdatesRedeemer, type Rational, RationalSchema, type RedeemCdpWithdrawalRedeemer, type RobDatum, type RobOrderType, type RobOutput, type RobParams, type RobParamsSP, RobParamsSchema, type RobRedeemer, SOLANA_FORMAT_MAGIC, type SPInteger, SPIntegerSchema, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, type SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, type StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, type StabilityPoolRedeemer, StabilityPoolRedeemerSchema, type StableswapInfo, type StableswapOrderDatum, StableswapOrderDatumSchema, type StableswapOrderInfo, type StableswapOrderRedeemer, type StableswapOutputDatum, type StableswapParamsSP, type StableswapPoolContent, StakeCredential, StakeCredentialSchema, type StakingManager, type StakingManagerOutput, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingPositionOutput, type StakingRedeemer, type StartTime, type StateSnapshot, type SubmissionConfig, type SumSnapshot, type SystemParams, type TokenNameSP, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type UpgradePaths, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, adjustCdp, adjustPriceToDecimals, adjustRob, adjustStakingPosition, alwaysFailValidator, annulRequest, approximateLeverageRedemptions, attachOracle, balance, batchCollectInterest, batchProcessStableswapOrders, bigintMax, bigintMin, buildRedemptionsTx, burnCdp, calculateAccruedInterest, calculateAdaReward, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculatePurchaseAmtWhenRobBuyOrder, calculatePurchaseAmtWhenRobSellOrder, calculateSpendAmtWhenRobBuyOrder, calculateSpendAmtWhenRobSellOrder, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castOneShotParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectPriceFeedIds, collectorFeeTx, computeEffectiveCdpState, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, derivePythPrice, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateMinOrderOutputLovelaces, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findAdminInterestCollectors, findAllInterestCollectors, findAllStableswapPools, findAllTreasuryUtxos, findAllTreasuryUtxosWithNonAdaAsset, findCollateralAsset, findE2s2sSnapshots, findIAsset, findInterestOracle, findRandomCdpCreator, findRandomNonAdminInterestCollector, findRandomTreasuryUtxo, findRandomTreasuryUtxoWithAsset, findRandomTreasuryUtxoWithOnlyAda, findRelevantE2s2sIdxs, findStabilityPool, findStabilityPoolAccount, findStableswapPool, findStakingManager, findStakingManagerByOutRef, findStakingPositionByOutRef, freezeCdp, fromDataDerivedPythPrice, fromDecimal, fromSPInteger, fromSysParamsCredential, fromSysParamsDerivedPythPrice, fromSysParamsPythFeedParams, fromSysParamsStakeCredential, fromSystemParamsAsset, fromSystemParamsAssetLucid, fromSystemParamsScriptRef, getAssetClassComparisonStr, getInlineDatumOrThrow, getPythFeedConfig, getUpdatedAccountDeposit, handleOracleForCollateralAsset, iassetValueOfCollateral, init, initCDPCreator, initCollector, initGovernance, initInterestCollector, initPythConfig, initSpState, initStakingManager, initSumVal, initTreasury, initializeAsset, insertSorted, isBuyOrderFullyRedeemed, isFullyRedeemed, isSameEpochToScaleKey, leverageCdpWithRob, liquidateCdp, liquidationHelper, loadSystemParamsFromFile, loadSystemParamsFromUrl, matchSingle, mergeCdps, mergeShards, mintAuthTokenDirect, mintCdp, mintOneTimeAsset, mintOneTimeToken, mkAuthTokenPolicy, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkCdpRedeemValidatorFromSP, mkCdpValidatorFromSP, mkCollectorValidatorFromSP, mkExecuteValidator, mkExecuteValidatorFromSP, mkGovValidator, mkGovValidatorFromSP, mkIAssetTokenPolicy, mkIAssetValidatorFromSP, mkInterestCollectionValidator, mkInterestCollectionValidatorFromSP, mkInterestOracleValidator, mkOneShotPolicy, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkPriceOracleValidator, mkPythFeedValidator, mkRobValidator, mkRobValidatorFromSP, mkSPInteger, mkStabilityPoolAddr, mkStabilityPoolValidator, mkStabilityPoolValidatorFromSP, mkStableswapValidator, mkStableswapValidatorFromSP, mkStakingValidatorFromSP, mkTreasuryAddr, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, numberToRational, oneShotMintTx, openCdp, openRob, openStakingPosition, parseAccountDatum, parseAccountDatumOrThrow, parseCdpDatum, parseCdpDatumOrThrow, parseCdpRedeemer, parseCdpRedeemerOrThrow, parseCollateralAssetDatum, parseCollateralAssetDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestCollectionDatum, parseInterestOracleDatum, parsePollManager, parsePollManagerOrThrow, parsePollShard, parsePollShardOrThrow, parsePollShardRedeemer, parsePollShardRedeemerOrThrow, parsePriceOracleDatum, parsePythStateDatum, parseRobDatum, parseRobDatumOrThrow, parseRobRedeemer, parseRobRedeemerOrThrow, parseSnapshotEpochToScaleToSumDatum, parseSnapshotEpochToScaleToSumDatumOrThrow, parseStabilityPoolDatum, parseStabilityPoolDatumOrThrow, parseStabilityPoolRedeemer, parseStabilityPoolRedeemerOrThrow, parseStableswapOrderDatum, parseStableswapOrderDatumOrThrow, parseStableswapOrderRedeemer, parseStableswapOrderRedeemerOrThrow, parseStableswapPoolDatum, parseStableswapPoolDatumOrThrow, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, parseStakingRedeemer, parseStakingRedeemerOrThrow, partitionEpochToScaleToSums, pickValidSatisfiableOrders, processSpRequest, psmOrderType, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, rewardsPerAsset, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, runAndAwaitTxBuilder, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseActionReturnDatum, serialiseCdpDatum, serialiseCdpRedeemer, serialiseCollectorRedeemer, serialiseExecuteDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseGovRedeemer, serialiseIAssetDatum, serialiseIAssetRedeemer, serialiseInterestCollectionDatum, serialiseInterestCollectionRedeemer, serialiseInterestOracleDatum, serialisePollDatum, serialisePollManagerRedeemer, serialisePollShardRedeemer, serialisePriceOracleDatum, serialisePriceOracleRedeemer, serialisePythFeedParams, serialisePythFeedRedeemer, serialisePythStateDatum, serialisePythUpdatesRedeemer, serialiseRedeemCdpWithdrawalRedeemer, serialiseRobDatum, serialiseRobRedeemer, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, serialiseStableswapOrderDatum, serialiseStableswapOrderRedeemer, serialiseStableswapOutputDatum, serialiseStableswapPoolDatum, serialiseStakingDatum, serialiseStakingRedeemer, shuffle, signersAllOf, spAdd, spDiv, spMul, spSub, spZeroNegatives, startInterestOracle, startPriceOracleTx, sum, summariseOrder, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, toSystemParamsInput, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
4811
+ export { type AccountAction, type AccountContent, AccountContentSchema, type ActionReturnDatum, type AddCollateralAsssetContent, type AddressCredential, type AddressCredentialOrDatum, type AddressSP, AikenIntervalIntervalBound, AikenIntervalIntervalBoundType, type Amount, type AssetClassD, type AssetClassSP, AssetClassSchema, type AssetInfo, type AssetSnapshot, type AssetState, type AuthTokenPolicies, BASE_MAX_EXECUTION_FEE, BASE_MAX_TX_FEE, BigIntOrd, type CDPContent, CDPCreatorParams, type CDPCreatorParamsSP, type CDPDatum, CardanoTransactionValidityRange, type CdpParams, type CdpParamsSP, type CdpRedeemParams, type CdpRedeemParamsSP, type CdpRedeemer, type CollateralAssetContent, type CollateralAssetInfo, type CollateralAssetOutput, type CollectorParamsSP, type CollectorRedeemer, CollectorRedeemerSchema, CredentialD, CredentialSchema, type CurrencySymbolSP, DEFAULT_INIT_OPTIONS, type DerivedPythPrice, type DerivedPythPriceSP, DerivedPythPriceSchema, type E2S2SIndex, type E2S2SIndicesPerAsset, type EpochToScaleKey, type EpochToScaleToSumEntry, type ExecuteDatum, ExecuteParams, type ExecuteParamsSP, type Feed, type FindE2S2SIdxResult, type GovDatum, GovParams, type GovParamsSP, type GovRedeemer, type IAssetContent, type IAssetDatum, type IAssetOutput, type IAssetParamsSP, type IAssetPriceInfo, IAssetPriceInfoSchema, type IAssetRedeemer, IAssetScriptParams, INIT_TOKEN_NAMES, type IndigoOracleNftParam, type InitialAssetParam, type InitialCollateralAssetParam, type InitialStablepoolParam, type InitializeOptions, type Input, type InterestCollectionDatum, type InterestCollectionParams, type InterestCollectionParamsSP, InterestCollectionParamsSchema, type InterestCollectionRedeemer, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type InterestOracleRedeemer, type LoanAdjustments, MAX_BUY_ROB_REDEMPTIONS_COUNT, MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET, MAX_E2S2S_ENTRIES_COUNT, MAX_REDEMPTIONS_WITH_CDP_OPEN, MAX_SELL_ROB_REDEMPTIONS_COUNT, MIN_ROB_COLLATERAL_AMT, type MarketSession, type ModifyStableswapPoolContent, ONE_DAY, ONE_HOUR, ONE_SECOND, ONE_YEAR, type OneShotParams, OneShotParamsSchema, type OracleIdx, OracleIdxSchema, type Output, PRICE_UPDATE_MAGIC, type PSMProcessingConfig, type ParsedOutput, type PollDatum, type PollManagerContent, PollManagerParams, type PollManagerParamsSP, type PollManagerRedeemer, type PollShardContent, PollShardParams, type PollShardParamsSP, type PollShardRedeemer, type PollStatus, type PriceOracleDatum, type PriceOracleParam, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PriceUpdate, type ProcessRequestAccountContent, type ProposalContent, ProposalContentSchema, type ProposeAssetContent, type ProposeStableswapPoolContent, type ProtocolParams, ProtocolParamsSchema, type PubKeyHash, type PythConfig, type PythConfiguration, type PythFeedConfig, type PythFeedParams, type PythFeedParamsSP, type PythFeedRedeemer, type PythMessageParts, type PythOracleParam, type PythPriceConfigurationSP, type PythStateDatum, type PythUpdatesRedeemer, type Rational, RationalSchema, type RedeemCdpWithdrawalRedeemer, type RobDatum, type RobOrderType, type RobOutput, type RobParams, type RobParamsSP, RobParamsSchema, type RobRedeemer, SOLANA_FORMAT_MAGIC, type SPInteger, SPIntegerSchema, SP_LEDGER_SLOT_BUFFER, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, type SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, type StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, type StabilityPoolRedeemer, StabilityPoolRedeemerSchema, type StableswapInfo, type StableswapOrderDatum, StableswapOrderDatumSchema, type StableswapOrderInfo, type StableswapOrderRedeemer, type StableswapOutputDatum, type StableswapParamsSP, type StableswapPoolContent, StakeCredential, StakeCredentialSchema, type StakingManager, type StakingManagerOutput, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingPositionOutput, type StakingRedeemer, type StartTime, type StateSnapshot, type SubmissionConfig, type SumSnapshot, type SystemParams, type TokenNameSP, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type UpgradePaths, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, adjustCdp, adjustPriceToDecimals, adjustRob, adjustStakingPosition, alwaysFailValidator, annulRequest, approximateLeverageRedemptions, attachOracle, balance, batchCollectInterest, batchProcessStableswapOrders, bigintMax, bigintMin, buildRedemptionsTx, burnCdp, calculateAccruedInterest, calculateAdaReward, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculatePurchaseAmtWhenRobBuyOrder, calculatePurchaseAmtWhenRobSellOrder, calculateSpendAmtWhenRobBuyOrder, calculateSpendAmtWhenRobSellOrder, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castOneShotParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectPriceFeedIds, collectorFeeTx, computeEffectiveCdpState, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, derivePythPrice, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateMinOrderOutputLovelaces, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findAdminInterestCollectors, findAllInterestCollectors, findAllStableswapPools, findAllTreasuryUtxos, findAllTreasuryUtxosWithNonAdaAsset, findCollateralAsset, findE2s2sSnapshots, findIAsset, findInterestOracle, findRandomCdpCreator, findRandomNonAdminInterestCollector, findRandomTreasuryUtxo, findRandomTreasuryUtxoWithAsset, findRandomTreasuryUtxoWithOnlyAda, findRelevantE2s2sIdxs, findStabilityPool, findStabilityPoolAccount, findStableswapPool, findStakingManager, findStakingManagerByOutRef, findStakingPositionByOutRef, freezeCdp, fromDataDerivedPythPrice, fromDecimal, fromSPInteger, fromSysParamsCredential, fromSysParamsDerivedPythPrice, fromSysParamsPythFeedParams, fromSysParamsStakeCredential, fromSystemParamsAsset, fromSystemParamsAssetLucid, fromSystemParamsScriptRef, getAssetClassComparisonStr, getInlineDatumOrThrow, getPythFeedConfig, getSpProcessingValidityRange, getUpdatedAccountDeposit, handleOracleForCollateralAsset, iassetValueOfCollateral, init, initCDPCreator, initCollector, initGovernance, initInterestCollector, initPythConfig, initSpState, initStakingManager, initSumVal, initTreasury, initializeAsset, insertSorted, isBuyOrderFullyRedeemed, isFullyRedeemed, isSameEpochToScaleKey, leverageCdpWithRob, liquidateCdp, liquidationHelper, loadSystemParamsFromFile, loadSystemParamsFromUrl, matchSingle, mergeCdps, mergeShards, mintAuthTokenDirect, mintCdp, mintOneTimeAsset, mintOneTimeToken, mkAuthTokenPolicy, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkCdpRedeemValidatorFromSP, mkCdpValidatorFromSP, mkCollectorValidatorFromSP, mkExecuteValidator, mkExecuteValidatorFromSP, mkGovValidator, mkGovValidatorFromSP, mkIAssetTokenPolicy, mkIAssetValidatorFromSP, mkInterestCollectionValidator, mkInterestCollectionValidatorFromSP, mkInterestOracleValidator, mkOneShotPolicy, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkPriceOracleValidator, mkPythFeedValidator, mkRobValidator, mkRobValidatorFromSP, mkSPInteger, mkStabilityPoolAddr, mkStabilityPoolValidator, mkStabilityPoolValidatorFromSP, mkStableswapValidator, mkStableswapValidatorFromSP, mkStakingValidatorFromSP, mkTreasuryAddr, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, numberToRational, oneShotMintTx, openCdp, openRob, openStakingPosition, parseAccountDatum, parseAccountDatumOrThrow, parseCdpDatum, parseCdpDatumOrThrow, parseCdpRedeemer, parseCdpRedeemerOrThrow, parseCollateralAssetDatum, parseCollateralAssetDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestCollectionDatum, parseInterestOracleDatum, parsePollManager, parsePollManagerOrThrow, parsePollShard, parsePollShardOrThrow, parsePollShardRedeemer, parsePollShardRedeemerOrThrow, parsePriceOracleDatum, parsePythStateDatum, parseRobDatum, parseRobDatumOrThrow, parseRobRedeemer, parseRobRedeemerOrThrow, parseSnapshotEpochToScaleToSumDatum, parseSnapshotEpochToScaleToSumDatumOrThrow, parseStabilityPoolDatum, parseStabilityPoolDatumOrThrow, parseStabilityPoolRedeemer, parseStabilityPoolRedeemerOrThrow, parseStableswapOrderDatum, parseStableswapOrderDatumOrThrow, parseStableswapOrderRedeemer, parseStableswapOrderRedeemerOrThrow, parseStableswapPoolDatum, parseStableswapPoolDatumOrThrow, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, parseStakingRedeemer, parseStakingRedeemerOrThrow, partitionEpochToScaleToSums, pickValidSatisfiableOrders, processSpRequest, psmOrderType, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, rewardsPerAsset, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, runAndAwaitTxBuilder, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseActionReturnDatum, serialiseCdpDatum, serialiseCdpRedeemer, serialiseCollectorRedeemer, serialiseExecuteDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseGovRedeemer, serialiseIAssetDatum, serialiseIAssetRedeemer, serialiseInterestCollectionDatum, serialiseInterestCollectionRedeemer, serialiseInterestOracleDatum, serialisePollDatum, serialisePollManagerRedeemer, serialisePollShardRedeemer, serialisePriceOracleDatum, serialisePriceOracleRedeemer, serialisePythFeedParams, serialisePythFeedRedeemer, serialisePythStateDatum, serialisePythUpdatesRedeemer, serialiseRedeemCdpWithdrawalRedeemer, serialiseRobDatum, serialiseRobRedeemer, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, serialiseStableswapOrderDatum, serialiseStableswapOrderRedeemer, serialiseStableswapOutputDatum, serialiseStableswapPoolDatum, serialiseStakingDatum, serialiseStakingRedeemer, shuffle, signersAllOf, spAdd, spDiv, spMul, spSub, spZeroNegatives, startInterestOracle, startPriceOracleTx, sum, summariseOrder, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, toSystemParamsInput, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
package/dist/index.js CHANGED
@@ -77,6 +77,7 @@ __export(index_exports, {
77
77
  RobParamsSchema: () => RobParamsSchema,
78
78
  SOLANA_FORMAT_MAGIC: () => SOLANA_FORMAT_MAGIC,
79
79
  SPIntegerSchema: () => SPIntegerSchema,
80
+ SP_LEDGER_SLOT_BUFFER: () => SP_LEDGER_SLOT_BUFFER,
80
81
  SnapshotEpochToScaleToSumContentSchema: () => SnapshotEpochToScaleToSumContentSchema,
81
82
  StabilityPoolContentSchema: () => StabilityPoolContentSchema,
82
83
  StabilityPoolDatumSchema: () => StabilityPoolDatumSchema,
@@ -202,6 +203,7 @@ __export(index_exports, {
202
203
  getAssetClassComparisonStr: () => getAssetClassComparisonStr,
203
204
  getInlineDatumOrThrow: () => getInlineDatumOrThrow,
204
205
  getPythFeedConfig: () => getPythFeedConfig,
206
+ getSpProcessingValidityRange: () => getSpProcessingValidityRange,
205
207
  getUpdatedAccountDeposit: () => getUpdatedAccountDeposit,
206
208
  handleOracleForCollateralAsset: () => handleOracleForCollateralAsset,
207
209
  iassetValueOfCollateral: () => iassetValueOfCollateral,
@@ -860,8 +862,9 @@ function calculateAccruedInterest(now, unitaryInterestSnapshot, mintedAmount, in
860
862
 
861
863
  // src/contracts/price-oracle/helpers.ts
862
864
  function oracleExpirationAwareValidity(lucid, biasTime, oracleExpiration) {
863
- const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
864
- const defaultValidateTo = validateFrom + biasTime;
865
+ const currentTime = lucid.slotToUnixTime(lucid.currentSlot());
866
+ const validateFrom = currentTime - Math.floor(biasTime / 2);
867
+ const defaultValidateTo = currentTime + Math.floor(biasTime / 2);
865
868
  const cappedValidateTo = lucid.slotToUnixTime(
866
869
  lucid.unixTimeToSlot(oracleExpiration) - 1
867
870
  );
@@ -1470,6 +1473,7 @@ var mkStabilityPoolValidatorFromSP = (params) => {
1470
1473
  };
1471
1474
 
1472
1475
  // src/contracts/stability-pool/helpers.ts
1476
+ var SP_LEDGER_SLOT_BUFFER = 20;
1473
1477
  var BASE_MAX_TX_FEE = 1250000n;
1474
1478
  var MAX_E2S2S_ENTRIES_COUNT = 5;
1475
1479
  var newScaleMultiplier = 1000000000n;
@@ -1480,6 +1484,24 @@ var initSpState = {
1480
1484
  epoch: 0n,
1481
1485
  scale: 0n
1482
1486
  };
1487
+ function getSpProcessingValidityRange(lucid, currentSlot, sysParams, accountDatum) {
1488
+ const biasMs = sysParams.stabilityPoolParams.accountProcessingBiasMs;
1489
+ const currentTime = BigInt(lucid.slotToUnixTime(currentSlot));
1490
+ const cooldownTime = accountDatum.lastRequestProcessingTime + BigInt(sysParams.stabilityPoolParams.accountProcessingCooldownMs);
1491
+ let validateFrom = Number(currentTime - BigInt(biasMs) / 2n);
1492
+ let validateTo = Number(currentTime + BigInt(biasMs) / 2n);
1493
+ if (BigInt(validateFrom) < cooldownTime) {
1494
+ const alternativeValidFrom = lucid.slotToUnixTime(
1495
+ currentSlot - SP_LEDGER_SLOT_BUFFER
1496
+ );
1497
+ if (BigInt(alternativeValidFrom) < cooldownTime) {
1498
+ return null;
1499
+ }
1500
+ validateFrom = alternativeValidFrom;
1501
+ validateTo = alternativeValidFrom + biasMs;
1502
+ }
1503
+ return { validateFrom, validateTo };
1504
+ }
1483
1505
  function mkStabilityPoolAddr(lucid, sysParams) {
1484
1506
  return (0, import_lucid6.credentialToAddress)(
1485
1507
  lucid.config().network,
@@ -2600,8 +2622,12 @@ async function batchCollectInterest(collateralAssetOref, interestCollectorOutRef
2600
2622
  referenceInputs,
2601
2623
  false
2602
2624
  );
2603
- const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
2604
- const validateTo = validateFrom + Number(params.cdpParams.biasTime);
2625
+ const validateFrom = Number(
2626
+ currentTime - BigInt(params.cdpParams.biasTime) / 2n
2627
+ );
2628
+ const validateTo = Number(
2629
+ currentTime + BigInt(params.cdpParams.biasTime) / 2n
2630
+ );
2605
2631
  const tx = lucid.newTx().validFrom(validateFrom).validTo(validateTo).readFrom(referenceInputs).collectFrom([interestCollectorUtxo], {
2606
2632
  kind: "selected",
2607
2633
  makeRedeemer: (inputIndices) => {
@@ -4107,6 +4133,8 @@ function derivePythPrice(derivedPythPrice, messageHex) {
4107
4133
 
4108
4134
  // src/contracts/iasset/helpers.ts
4109
4135
  var Core = __toESM(require("@evolution-sdk/evolution"));
4136
+ var MAX_PYTH_FEED_DELAY = 280 * 1e3;
4137
+ var PYTH_FEED_LEDGER_TIME_BUFFER = 20 * 1e3;
4110
4138
  var MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET = 9;
4111
4139
  function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythStateOref, pythMessage, pythConfig, biasTime, lucid, tx) {
4112
4140
  return (0, import_ts_pattern12.match)(priceInfo).returnType().with({ Delisted: import_ts_pattern12.P.any }, () => {
@@ -4187,9 +4215,8 @@ function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythS
4187
4215
  auxiliaryData: Core.Data.fromCBORHex(import_lucid11.Data.void())
4188
4216
  })
4189
4217
  );
4190
- const pythMaxDelay = 280 * 1e3;
4191
- const validFrom = Number(pythTimestamp);
4192
- const validTo = Number(pythTimestamp + pythMaxDelay);
4218
+ const validFrom = Number(pythTimestamp - PYTH_FEED_LEDGER_TIME_BUFFER);
4219
+ const validTo = Number(pythTimestamp + MAX_PYTH_FEED_DELAY);
4193
4220
  return {
4194
4221
  interval: {
4195
4222
  validFrom,
@@ -4673,8 +4700,12 @@ async function closeCdp(cdpOref, collateralAssetOref, interestOracleOref, intere
4673
4700
  const interestOracleDatum = parseInterestOracleDatum(
4674
4701
  getInlineDatumOrThrow(interestOracleUtxo)
4675
4702
  );
4676
- const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
4677
- const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
4703
+ const validateFrom = Number(
4704
+ currentTime - BigInt(sysParams.cdpParams.biasTime) / 2n
4705
+ );
4706
+ const validateTo = Number(
4707
+ currentTime + BigInt(sysParams.cdpParams.biasTime) / 2n
4708
+ );
4678
4709
  const tx = lucid.newTx().readFrom([
4679
4710
  cdpRefScriptUtxo,
4680
4711
  iAssetTokenPolicyRefScriptUtxo,
@@ -4869,8 +4900,12 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, coll
4869
4900
  referenceInputs.push(priceOracleUtxo);
4870
4901
  tx.validFrom(txValidity.validFrom).validTo(txValidity.validTo);
4871
4902
  } else {
4872
- const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
4873
- const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
4903
+ const validateFrom = Number(
4904
+ currentTime - BigInt(sysParams.cdpParams.biasTime) / 2n
4905
+ );
4906
+ const validateTo = Number(
4907
+ currentTime + BigInt(sysParams.cdpParams.biasTime) / 2n
4908
+ );
4874
4909
  tx.validFrom(validateFrom).validTo(validateTo);
4875
4910
  }
4876
4911
  const partialRedemptionFee = import_fp_ts13.function.pipe(
@@ -8377,9 +8412,9 @@ async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee =
8377
8412
  )
8378
8413
  ).addSignerKey((0, import_lucid47.toHex)(oldAccountDatum.owner));
8379
8414
  }
8380
- async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, txFee, currentSlot) {
8381
- const slot = currentSlot !== void 0 ? currentSlot : lucid.currentSlot();
8382
- const currentTime = BigInt(lucid.slotToUnixTime(slot));
8415
+ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, txFee) {
8416
+ const currentSlot = lucid.currentSlot();
8417
+ const currentTime = BigInt(lucid.slotToUnixTime(currentSlot));
8383
8418
  const stabilityPoolScriptRef = (0, import_cardano_offchain_common24.matchSingle)(
8384
8419
  await lucid.utxosByOutRef([
8385
8420
  fromSystemParamsScriptRef(
@@ -8395,8 +8430,14 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
8395
8430
  getInlineDatumOrThrow(stabilityPoolUtxo)
8396
8431
  );
8397
8432
  const baseRefInputs = [iAssetUtxo, stabilityPoolScriptRef];
8398
- const validFrom = lucid.slotToUnixTime(slot - 1);
8399
- const tx = lucid.newTx().validFrom(validFrom).validTo(validFrom + sysParams.stabilityPoolParams.accountProcessingBiasMs).readFrom(baseRefInputs).collectFrom([stabilityPoolUtxo], {
8433
+ const validity = getSpProcessingValidityRange(
8434
+ lucid,
8435
+ currentSlot,
8436
+ sysParams,
8437
+ accountDatum
8438
+ );
8439
+ if (!validity) throw new Error("Cooldown hasn't passed yet");
8440
+ const tx = lucid.newTx().validFrom(validity.validateFrom).validTo(validity.validateTo).readFrom(baseRefInputs).collectFrom([stabilityPoolUtxo], {
8400
8441
  kind: "selected",
8401
8442
  inputs: [stabilityPoolUtxo, accountUtxo],
8402
8443
  makeRedeemer: (indices) => serialiseStabilityPoolRedeemer({
@@ -8767,7 +8808,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
8767
8808
  }).exhaustive();
8768
8809
  return tx;
8769
8810
  }
8770
- async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, currentSlot) {
8811
+ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid) {
8771
8812
  const draftTx = processSpRequestAuxiliary(
8772
8813
  stabilityPoolUtxo,
8773
8814
  accountUtxo,
@@ -8776,8 +8817,7 @@ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE
8776
8817
  sysParams,
8777
8818
  lucid,
8778
8819
  // Placeholder transation fee
8779
- 1n,
8780
- currentSlot
8820
+ 1n
8781
8821
  );
8782
8822
  const fee = (await (await draftTx).complete()).toTransaction().body().fee();
8783
8823
  return processSpRequestAuxiliary(
@@ -8787,8 +8827,7 @@ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE
8787
8827
  allE2s2sSnapshotOrefs,
8788
8828
  sysParams,
8789
8829
  lucid,
8790
- fee,
8791
- currentSlot
8830
+ fee
8792
8831
  );
8793
8832
  }
8794
8833
  async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
@@ -12272,6 +12311,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
12272
12311
  RobParamsSchema,
12273
12312
  SOLANA_FORMAT_MAGIC,
12274
12313
  SPIntegerSchema,
12314
+ SP_LEDGER_SLOT_BUFFER,
12275
12315
  SnapshotEpochToScaleToSumContentSchema,
12276
12316
  StabilityPoolContentSchema,
12277
12317
  StabilityPoolDatumSchema,
@@ -12397,6 +12437,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
12397
12437
  getAssetClassComparisonStr,
12398
12438
  getInlineDatumOrThrow,
12399
12439
  getPythFeedConfig,
12440
+ getSpProcessingValidityRange,
12400
12441
  getUpdatedAccountDeposit,
12401
12442
  handleOracleForCollateralAsset,
12402
12443
  iassetValueOfCollateral,
package/dist/index.mjs CHANGED
@@ -465,8 +465,9 @@ function calculateAccruedInterest(now, unitaryInterestSnapshot, mintedAmount, in
465
465
 
466
466
  // src/contracts/price-oracle/helpers.ts
467
467
  function oracleExpirationAwareValidity(lucid, biasTime, oracleExpiration) {
468
- const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
469
- const defaultValidateTo = validateFrom + biasTime;
468
+ const currentTime = lucid.slotToUnixTime(lucid.currentSlot());
469
+ const validateFrom = currentTime - Math.floor(biasTime / 2);
470
+ const defaultValidateTo = currentTime + Math.floor(biasTime / 2);
470
471
  const cappedValidateTo = lucid.slotToUnixTime(
471
472
  lucid.unixTimeToSlot(oracleExpiration) - 1
472
473
  );
@@ -1100,6 +1101,7 @@ var mkStabilityPoolValidatorFromSP = (params) => {
1100
1101
  };
1101
1102
 
1102
1103
  // src/contracts/stability-pool/helpers.ts
1104
+ var SP_LEDGER_SLOT_BUFFER = 20;
1103
1105
  var BASE_MAX_TX_FEE = 1250000n;
1104
1106
  var MAX_E2S2S_ENTRIES_COUNT = 5;
1105
1107
  var newScaleMultiplier = 1000000000n;
@@ -1110,6 +1112,24 @@ var initSpState = {
1110
1112
  epoch: 0n,
1111
1113
  scale: 0n
1112
1114
  };
1115
+ function getSpProcessingValidityRange(lucid, currentSlot, sysParams, accountDatum) {
1116
+ const biasMs = sysParams.stabilityPoolParams.accountProcessingBiasMs;
1117
+ const currentTime = BigInt(lucid.slotToUnixTime(currentSlot));
1118
+ const cooldownTime = accountDatum.lastRequestProcessingTime + BigInt(sysParams.stabilityPoolParams.accountProcessingCooldownMs);
1119
+ let validateFrom = Number(currentTime - BigInt(biasMs) / 2n);
1120
+ let validateTo = Number(currentTime + BigInt(biasMs) / 2n);
1121
+ if (BigInt(validateFrom) < cooldownTime) {
1122
+ const alternativeValidFrom = lucid.slotToUnixTime(
1123
+ currentSlot - SP_LEDGER_SLOT_BUFFER
1124
+ );
1125
+ if (BigInt(alternativeValidFrom) < cooldownTime) {
1126
+ return null;
1127
+ }
1128
+ validateFrom = alternativeValidFrom;
1129
+ validateTo = alternativeValidFrom + biasMs;
1130
+ }
1131
+ return { validateFrom, validateTo };
1132
+ }
1113
1133
  function mkStabilityPoolAddr(lucid, sysParams) {
1114
1134
  return credentialToAddress2(
1115
1135
  lucid.config().network,
@@ -2244,8 +2264,12 @@ async function batchCollectInterest(collateralAssetOref, interestCollectorOutRef
2244
2264
  referenceInputs,
2245
2265
  false
2246
2266
  );
2247
- const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
2248
- const validateTo = validateFrom + Number(params.cdpParams.biasTime);
2267
+ const validateFrom = Number(
2268
+ currentTime - BigInt(params.cdpParams.biasTime) / 2n
2269
+ );
2270
+ const validateTo = Number(
2271
+ currentTime + BigInt(params.cdpParams.biasTime) / 2n
2272
+ );
2249
2273
  const tx = lucid.newTx().validFrom(validateFrom).validTo(validateTo).readFrom(referenceInputs).collectFrom([interestCollectorUtxo], {
2250
2274
  kind: "selected",
2251
2275
  makeRedeemer: (inputIndices) => {
@@ -3788,6 +3812,8 @@ function derivePythPrice(derivedPythPrice, messageHex) {
3788
3812
 
3789
3813
  // src/contracts/iasset/helpers.ts
3790
3814
  import * as Core from "@evolution-sdk/evolution";
3815
+ var MAX_PYTH_FEED_DELAY = 280 * 1e3;
3816
+ var PYTH_FEED_LEDGER_TIME_BUFFER = 20 * 1e3;
3791
3817
  var MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET = 9;
3792
3818
  function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythStateOref, pythMessage, pythConfig, biasTime, lucid, tx) {
3793
3819
  return match11(priceInfo).returnType().with({ Delisted: P12.any }, () => {
@@ -3868,9 +3894,8 @@ function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythS
3868
3894
  auxiliaryData: Core.Data.fromCBORHex(Data18.void())
3869
3895
  })
3870
3896
  );
3871
- const pythMaxDelay = 280 * 1e3;
3872
- const validFrom = Number(pythTimestamp);
3873
- const validTo = Number(pythTimestamp + pythMaxDelay);
3897
+ const validFrom = Number(pythTimestamp - PYTH_FEED_LEDGER_TIME_BUFFER);
3898
+ const validTo = Number(pythTimestamp + MAX_PYTH_FEED_DELAY);
3874
3899
  return {
3875
3900
  interval: {
3876
3901
  validFrom,
@@ -4357,8 +4382,12 @@ async function closeCdp(cdpOref, collateralAssetOref, interestOracleOref, intere
4357
4382
  const interestOracleDatum = parseInterestOracleDatum(
4358
4383
  getInlineDatumOrThrow(interestOracleUtxo)
4359
4384
  );
4360
- const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
4361
- const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
4385
+ const validateFrom = Number(
4386
+ currentTime - BigInt(sysParams.cdpParams.biasTime) / 2n
4387
+ );
4388
+ const validateTo = Number(
4389
+ currentTime + BigInt(sysParams.cdpParams.biasTime) / 2n
4390
+ );
4362
4391
  const tx = lucid.newTx().readFrom([
4363
4392
  cdpRefScriptUtxo,
4364
4393
  iAssetTokenPolicyRefScriptUtxo,
@@ -4553,8 +4582,12 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, coll
4553
4582
  referenceInputs.push(priceOracleUtxo);
4554
4583
  tx.validFrom(txValidity.validFrom).validTo(txValidity.validTo);
4555
4584
  } else {
4556
- const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
4557
- const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
4585
+ const validateFrom = Number(
4586
+ currentTime - BigInt(sysParams.cdpParams.biasTime) / 2n
4587
+ );
4588
+ const validateTo = Number(
4589
+ currentTime + BigInt(sysParams.cdpParams.biasTime) / 2n
4590
+ );
4558
4591
  tx.validFrom(validateFrom).validTo(validateTo);
4559
4592
  }
4560
4593
  const partialRedemptionFee = F12.pipe(
@@ -8160,9 +8193,9 @@ async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee =
8160
8193
  )
8161
8194
  ).addSignerKey(toHex12(oldAccountDatum.owner));
8162
8195
  }
8163
- async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, txFee, currentSlot) {
8164
- const slot = currentSlot !== void 0 ? currentSlot : lucid.currentSlot();
8165
- const currentTime = BigInt(lucid.slotToUnixTime(slot));
8196
+ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, txFee) {
8197
+ const currentSlot = lucid.currentSlot();
8198
+ const currentTime = BigInt(lucid.slotToUnixTime(currentSlot));
8166
8199
  const stabilityPoolScriptRef = matchSingle5(
8167
8200
  await lucid.utxosByOutRef([
8168
8201
  fromSystemParamsScriptRef(
@@ -8178,8 +8211,14 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
8178
8211
  getInlineDatumOrThrow(stabilityPoolUtxo)
8179
8212
  );
8180
8213
  const baseRefInputs = [iAssetUtxo, stabilityPoolScriptRef];
8181
- const validFrom = lucid.slotToUnixTime(slot - 1);
8182
- const tx = lucid.newTx().validFrom(validFrom).validTo(validFrom + sysParams.stabilityPoolParams.accountProcessingBiasMs).readFrom(baseRefInputs).collectFrom([stabilityPoolUtxo], {
8214
+ const validity = getSpProcessingValidityRange(
8215
+ lucid,
8216
+ currentSlot,
8217
+ sysParams,
8218
+ accountDatum
8219
+ );
8220
+ if (!validity) throw new Error("Cooldown hasn't passed yet");
8221
+ const tx = lucid.newTx().validFrom(validity.validateFrom).validTo(validity.validateTo).readFrom(baseRefInputs).collectFrom([stabilityPoolUtxo], {
8183
8222
  kind: "selected",
8184
8223
  inputs: [stabilityPoolUtxo, accountUtxo],
8185
8224
  makeRedeemer: (indices) => serialiseStabilityPoolRedeemer({
@@ -8550,7 +8589,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
8550
8589
  }).exhaustive();
8551
8590
  return tx;
8552
8591
  }
8553
- async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, currentSlot) {
8592
+ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid) {
8554
8593
  const draftTx = processSpRequestAuxiliary(
8555
8594
  stabilityPoolUtxo,
8556
8595
  accountUtxo,
@@ -8559,8 +8598,7 @@ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE
8559
8598
  sysParams,
8560
8599
  lucid,
8561
8600
  // Placeholder transation fee
8562
- 1n,
8563
- currentSlot
8601
+ 1n
8564
8602
  );
8565
8603
  const fee = (await (await draftTx).complete()).toTransaction().body().fee();
8566
8604
  return processSpRequestAuxiliary(
@@ -8570,8 +8608,7 @@ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE
8570
8608
  allE2s2sSnapshotOrefs,
8571
8609
  sysParams,
8572
8610
  lucid,
8573
- fee,
8574
- currentSlot
8611
+ fee
8575
8612
  );
8576
8613
  }
8577
8614
  async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
@@ -12185,6 +12222,7 @@ export {
12185
12222
  RobParamsSchema,
12186
12223
  SOLANA_FORMAT_MAGIC,
12187
12224
  SPIntegerSchema,
12225
+ SP_LEDGER_SLOT_BUFFER,
12188
12226
  SnapshotEpochToScaleToSumContentSchema,
12189
12227
  StabilityPoolContentSchema,
12190
12228
  StabilityPoolDatumSchema,
@@ -12310,6 +12348,7 @@ export {
12310
12348
  getAssetClassComparisonStr,
12311
12349
  getInlineDatumOrThrow,
12312
12350
  getPythFeedConfig,
12351
+ getSpProcessingValidityRange,
12313
12352
  getUpdatedAccountDeposit,
12314
12353
  handleOracleForCollateralAsset,
12315
12354
  iassetValueOfCollateral,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigo-labs/indigo-sdk",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Indigo SDK for interacting with Indigo endpoints via lucid-evolution",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -41,7 +41,7 @@
41
41
  "@indigo-labs/cardano-offchain-common": "1.5.2",
42
42
  "@evolution-sdk/evolution": "^0.3.22",
43
43
  "@harmoniclabs/crypto": "^0.3.0",
44
- "@lucid-evolution/lucid": "0.6.2",
44
+ "@lucid-evolution/lucid": "0.6.4",
45
45
  "@noble/ed25519": "^3.0.0",
46
46
  "@pythnetwork/pyth-lazer-sdk": "^6.0.0",
47
47
  "decimal.js": "^10.6.0",