@indigo-labs/indigo-sdk 0.3.19 → 0.3.21

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
@@ -3715,6 +3715,38 @@ declare function serialisePriceOracleDatum(d: PriceOracleDatum): string;
3715
3715
  declare function parsePriceOracleDatum(datum: string): PriceOracleDatum;
3716
3716
 
3717
3717
  declare const MIN_ROB_COLLATERAL_AMT = 3000000n;
3718
+ /**
3719
+ * The maximum of redemptions for a Tx that is doing only sell order redemptions.
3720
+ * Based on the benchmarks.
3721
+ */
3722
+ declare const MAX_SELL_ROB_REDEMPTIONS_COUNT = 18;
3723
+ /**
3724
+ * The maximum of redemptions for a Tx that is doing only buy order redemptions.
3725
+ * Based on the benchmarks.
3726
+ */
3727
+ declare const MAX_BUY_ROB_REDEMPTIONS_COUNT = 20;
3728
+ /**
3729
+ * Helper for ROB redemptions. A redeemer is selling iAssets against
3730
+ * a buy order, i.e. buying a collateral asset.
3731
+ * The return is the amount of collateral asset he buys.
3732
+ */
3733
+ declare function calculatePurchaseAmtWhenRobBuyOrder(sellIassetAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
3734
+ /**
3735
+ * A redeemer is purchasing given collateral amount against buy order.
3736
+ * Calculate what is the amount of iAsset the user sells/spends.
3737
+ */
3738
+ declare function calculateSpendAmtWhenRobBuyOrder(purchaseCollateralAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
3739
+ /**
3740
+ * Helper for ROB redemptions. A redeemer is selling collateral against
3741
+ * a sell order, i.e. buying iassets.
3742
+ * The return is the amount of iassets he buys.
3743
+ */
3744
+ declare function calculatePurchaseAmtWhenRobSellOrder(sellCollateralAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
3745
+ /**
3746
+ * A redeemer is purchasing given iasset amount against sell order.
3747
+ * Calculate what is the amount of collateral the user sells/spends.
3748
+ */
3749
+ declare function calculateSpendAmtWhenRobSellOrder(purchaseIassetAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
3718
3750
  /**
3719
3751
  * The amount of collateral asset available in the ROB when buy order. In case of ADA, take
3720
3752
  * into account the min UTXO collateral.
@@ -3872,6 +3904,9 @@ declare const OneShotParamsSchema: _lucid_evolution_lucid.TObject<{
3872
3904
  }>>;
3873
3905
  }>;
3874
3906
  type OneShotParams = Data.Static<typeof OneShotParamsSchema>;
3907
+ declare function castOneShotParams(params: OneShotParams): Data;
3908
+
3909
+ declare function mkOneShotPolicy(params: OneShotParams): MintingPolicy;
3875
3910
 
3876
3911
  declare function oneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<[TxBuilder, PolicyId]>;
3877
3912
  declare function runOneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<PolicyId>;
@@ -4570,4 +4605,4 @@ declare function mkAuthTokenPolicy(ac: AssetClass, tn: string): MintingPolicy;
4570
4605
 
4571
4606
  declare const alwaysFailValidator: SpendingValidator;
4572
4607
 
4573
- 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, MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET, MAX_E2S2S_ENTRIES_COUNT, MAX_REDEMPTIONS_WITH_CDP_OPEN, MIN_ROB_COLLATERAL_AMT, type MarketSession, type ModifyStableswapPoolContent, ONE_DAY, ONE_HOUR, ONE_SECOND, ONE_YEAR, type OracleIdx, OracleIdxSchema, type Output, PRICE_UPDATE_MAGIC, 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 StableswapOrderDatum, StableswapOrderDatumSchema, 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 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, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectorFeeTx, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findRelevantE2s2sIdxs, 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, initScriptRef, 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, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkPriceOracleValidator, mkPythFeedValidator, mkRobValidator, mkRobValidatorFromSP, mkSPInteger, mkStabilityPoolAddr, mkStabilityPoolValidator, mkStabilityPoolValidatorFromSP, mkStableswapValidator, mkStableswapValidatorFromSP, mkStakingValidatorFromSP, mkTreasuryAddr, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, 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, processSpRequest, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, 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, submitTx, sum, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
4608
+ 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, 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 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 StableswapOrderDatum, StableswapOrderDatumSchema, 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 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, collectorFeeTx, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findRelevantE2s2sIdxs, 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, initScriptRef, 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, 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, processSpRequest, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, 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, submitTx, sum, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
package/dist/index.d.ts CHANGED
@@ -3715,6 +3715,38 @@ declare function serialisePriceOracleDatum(d: PriceOracleDatum): string;
3715
3715
  declare function parsePriceOracleDatum(datum: string): PriceOracleDatum;
3716
3716
 
3717
3717
  declare const MIN_ROB_COLLATERAL_AMT = 3000000n;
3718
+ /**
3719
+ * The maximum of redemptions for a Tx that is doing only sell order redemptions.
3720
+ * Based on the benchmarks.
3721
+ */
3722
+ declare const MAX_SELL_ROB_REDEMPTIONS_COUNT = 18;
3723
+ /**
3724
+ * The maximum of redemptions for a Tx that is doing only buy order redemptions.
3725
+ * Based on the benchmarks.
3726
+ */
3727
+ declare const MAX_BUY_ROB_REDEMPTIONS_COUNT = 20;
3728
+ /**
3729
+ * Helper for ROB redemptions. A redeemer is selling iAssets against
3730
+ * a buy order, i.e. buying a collateral asset.
3731
+ * The return is the amount of collateral asset he buys.
3732
+ */
3733
+ declare function calculatePurchaseAmtWhenRobBuyOrder(sellIassetAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
3734
+ /**
3735
+ * A redeemer is purchasing given collateral amount against buy order.
3736
+ * Calculate what is the amount of iAsset the user sells/spends.
3737
+ */
3738
+ declare function calculateSpendAmtWhenRobBuyOrder(purchaseCollateralAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
3739
+ /**
3740
+ * Helper for ROB redemptions. A redeemer is selling collateral against
3741
+ * a sell order, i.e. buying iassets.
3742
+ * The return is the amount of iassets he buys.
3743
+ */
3744
+ declare function calculatePurchaseAmtWhenRobSellOrder(sellCollateralAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
3745
+ /**
3746
+ * A redeemer is purchasing given iasset amount against sell order.
3747
+ * Calculate what is the amount of collateral the user sells/spends.
3748
+ */
3749
+ declare function calculateSpendAmtWhenRobSellOrder(purchaseIassetAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
3718
3750
  /**
3719
3751
  * The amount of collateral asset available in the ROB when buy order. In case of ADA, take
3720
3752
  * into account the min UTXO collateral.
@@ -3872,6 +3904,9 @@ declare const OneShotParamsSchema: _lucid_evolution_lucid.TObject<{
3872
3904
  }>>;
3873
3905
  }>;
3874
3906
  type OneShotParams = Data.Static<typeof OneShotParamsSchema>;
3907
+ declare function castOneShotParams(params: OneShotParams): Data;
3908
+
3909
+ declare function mkOneShotPolicy(params: OneShotParams): MintingPolicy;
3875
3910
 
3876
3911
  declare function oneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<[TxBuilder, PolicyId]>;
3877
3912
  declare function runOneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<PolicyId>;
@@ -4570,4 +4605,4 @@ declare function mkAuthTokenPolicy(ac: AssetClass, tn: string): MintingPolicy;
4570
4605
 
4571
4606
  declare const alwaysFailValidator: SpendingValidator;
4572
4607
 
4573
- 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, MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET, MAX_E2S2S_ENTRIES_COUNT, MAX_REDEMPTIONS_WITH_CDP_OPEN, MIN_ROB_COLLATERAL_AMT, type MarketSession, type ModifyStableswapPoolContent, ONE_DAY, ONE_HOUR, ONE_SECOND, ONE_YEAR, type OracleIdx, OracleIdxSchema, type Output, PRICE_UPDATE_MAGIC, 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 StableswapOrderDatum, StableswapOrderDatumSchema, 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 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, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectorFeeTx, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findRelevantE2s2sIdxs, 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, initScriptRef, 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, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkPriceOracleValidator, mkPythFeedValidator, mkRobValidator, mkRobValidatorFromSP, mkSPInteger, mkStabilityPoolAddr, mkStabilityPoolValidator, mkStabilityPoolValidatorFromSP, mkStableswapValidator, mkStableswapValidatorFromSP, mkStakingValidatorFromSP, mkTreasuryAddr, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, 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, processSpRequest, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, 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, submitTx, sum, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
4608
+ 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, 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 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 StableswapOrderDatum, StableswapOrderDatumSchema, 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 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, collectorFeeTx, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findRelevantE2s2sIdxs, 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, initScriptRef, 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, 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, processSpRequest, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, 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, submitTx, sum, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
package/dist/index.js CHANGED
@@ -52,14 +52,17 @@ __export(index_exports, {
52
52
  InterestCollectionParamsSchema: () => InterestCollectionParamsSchema,
53
53
  InterestOracleDatumSchema: () => InterestOracleDatumSchema,
54
54
  InterestOracleParamsSchema: () => InterestOracleParamsSchema,
55
+ MAX_BUY_ROB_REDEMPTIONS_COUNT: () => MAX_BUY_ROB_REDEMPTIONS_COUNT,
55
56
  MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET: () => MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET,
56
57
  MAX_E2S2S_ENTRIES_COUNT: () => MAX_E2S2S_ENTRIES_COUNT,
57
58
  MAX_REDEMPTIONS_WITH_CDP_OPEN: () => MAX_REDEMPTIONS_WITH_CDP_OPEN,
59
+ MAX_SELL_ROB_REDEMPTIONS_COUNT: () => MAX_SELL_ROB_REDEMPTIONS_COUNT,
58
60
  MIN_ROB_COLLATERAL_AMT: () => MIN_ROB_COLLATERAL_AMT,
59
61
  ONE_DAY: () => ONE_DAY,
60
62
  ONE_HOUR: () => ONE_HOUR,
61
63
  ONE_SECOND: () => ONE_SECOND,
62
64
  ONE_YEAR: () => ONE_YEAR,
65
+ OneShotParamsSchema: () => OneShotParamsSchema,
63
66
  OracleIdxSchema: () => OracleIdxSchema,
64
67
  PRICE_UPDATE_MAGIC: () => PRICE_UPDATE_MAGIC,
65
68
  PollManagerParams: () => PollManagerParams,
@@ -104,6 +107,10 @@ __export(index_exports, {
104
107
  calculateIAssetRedemptionAmt: () => calculateIAssetRedemptionAmt,
105
108
  calculateLeverageFromCollateralRatio: () => calculateLeverageFromCollateralRatio,
106
109
  calculateMinCollateralCappedIAssetRedemptionAmt: () => calculateMinCollateralCappedIAssetRedemptionAmt,
110
+ calculatePurchaseAmtWhenRobBuyOrder: () => calculatePurchaseAmtWhenRobBuyOrder,
111
+ calculatePurchaseAmtWhenRobSellOrder: () => calculatePurchaseAmtWhenRobSellOrder,
112
+ calculateSpendAmtWhenRobBuyOrder: () => calculateSpendAmtWhenRobBuyOrder,
113
+ calculateSpendAmtWhenRobSellOrder: () => calculateSpendAmtWhenRobSellOrder,
107
114
  calculateTotalCollateralForRedemption: () => calculateTotalCollateralForRedemption,
108
115
  calculateUnitaryInterest: () => calculateUnitaryInterest,
109
116
  calculateUnitaryInterestSinceOracleLastUpdated: () => calculateUnitaryInterestSinceOracleLastUpdated,
@@ -116,6 +123,7 @@ __export(index_exports, {
116
123
  castGovParams: () => castGovParams,
117
124
  castInterestCollectionParams: () => castInterestCollectionParams,
118
125
  castInterestOracleParams: () => castInterestOracleParams,
126
+ castOneShotParams: () => castOneShotParams,
119
127
  castPollManagerParams: () => castPollManagerParams,
120
128
  castPollShardParams: () => castPollShardParams,
121
129
  castPriceOracleParams: () => castPriceOracleParams,
@@ -216,6 +224,7 @@ __export(index_exports, {
216
224
  mkInterestCollectionValidator: () => mkInterestCollectionValidator,
217
225
  mkInterestCollectionValidatorFromSP: () => mkInterestCollectionValidatorFromSP,
218
226
  mkInterestOracleValidator: () => mkInterestOracleValidator,
227
+ mkOneShotPolicy: () => mkOneShotPolicy,
219
228
  mkPollManagerValidator: () => mkPollManagerValidator,
220
229
  mkPollManagerValidatorFromSP: () => mkPollManagerValidatorFromSP,
221
230
  mkPollShardValidator: () => mkPollShardValidator,
@@ -8647,7 +8656,49 @@ function parseRobRedeemerOrThrow(redeemerCborHex) {
8647
8656
  var import_fp_ts17 = require("fp-ts");
8648
8657
  var import_ts_pattern19 = require("ts-pattern");
8649
8658
  var import_cardano_offchain_common22 = require("@3rd-eye-labs/cardano-offchain-common");
8659
+ var import_decimal = __toESM(require("decimal.js"));
8650
8660
  var MIN_ROB_COLLATERAL_AMT = 3000000n;
8661
+ var MAX_SELL_ROB_REDEMPTIONS_COUNT = 18;
8662
+ var MAX_BUY_ROB_REDEMPTIONS_COUNT = 20;
8663
+ function calculatePurchaseAmtWhenRobBuyOrder(sellIassetAmt, redemptionReimbursementRatio, price) {
8664
+ const reimbursementIAsset = calculateFeeFromRatio(
8665
+ redemptionReimbursementRatio,
8666
+ sellIassetAmt
8667
+ );
8668
+ const collateralForRedemption = rationalFloor(
8669
+ rationalMul(rationalFromInt(sellIassetAmt - reimbursementIAsset), price)
8670
+ );
8671
+ return collateralForRedemption;
8672
+ }
8673
+ function calculateSpendAmtWhenRobBuyOrder(purchaseCollateralAmt, redemptionReimbursementRatio, price) {
8674
+ const priceDecimal = (0, import_decimal.default)(price.numerator).div(price.denominator);
8675
+ const reimbRatio = (0, import_decimal.default)(redemptionReimbursementRatio.numerator).div(
8676
+ redemptionReimbursementRatio.denominator
8677
+ );
8678
+ return fromDecimal(
8679
+ (0, import_decimal.default)(purchaseCollateralAmt).div(priceDecimal).floor().div((0, import_decimal.default)(1).minus(reimbRatio)).floor()
8680
+ );
8681
+ }
8682
+ function calculatePurchaseAmtWhenRobSellOrder(sellCollateralAmt, redemptionReimbursementRatio, price) {
8683
+ const reimbursementCollateral = calculateFeeFromRatio(
8684
+ redemptionReimbursementRatio,
8685
+ sellCollateralAmt
8686
+ );
8687
+ const redeemedIAssetAmt = iassetValueOfCollateral(
8688
+ sellCollateralAmt - reimbursementCollateral,
8689
+ price
8690
+ );
8691
+ return redeemedIAssetAmt;
8692
+ }
8693
+ function calculateSpendAmtWhenRobSellOrder(purchaseIassetAmt, redemptionReimbursementRatio, price) {
8694
+ const priceDecimal = (0, import_decimal.default)(price.numerator).div(price.denominator);
8695
+ const reimbRatio = (0, import_decimal.default)(redemptionReimbursementRatio.numerator).div(
8696
+ redemptionReimbursementRatio.denominator
8697
+ );
8698
+ return fromDecimal(
8699
+ (0, import_decimal.default)(purchaseIassetAmt).mul(priceDecimal).floor().div((0, import_decimal.default)(1).minus(reimbRatio)).floor()
8700
+ );
8701
+ }
8651
8702
  function robCollateralAmtToSpend(robAssets, robOrderType) {
8652
8703
  return (0, import_ts_pattern19.match)(robOrderType).returnType().with({ BuyIAssetOrder: import_ts_pattern19.P.select() }, (content) => {
8653
8704
  if ((0, import_cardano_offchain_common22.isSameAssetClass)(import_cardano_offchain_common22.adaAssetClass, content.collateralAsset)) {
@@ -8743,15 +8794,10 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8743
8794
  throw new Error("Only same collateral asset");
8744
8795
  }
8745
8796
  const payoutIAssetAmt = payoutAmt;
8746
- const reimburstmentIAsset = calculateFeeFromRatio(
8797
+ const collateralForRedemption = calculatePurchaseAmtWhenRobBuyOrder(
8798
+ payoutIAssetAmt,
8747
8799
  redemptionReimbursementRatio,
8748
- payoutIAssetAmt
8749
- );
8750
- const collateralForRedemption = rationalFloor(
8751
- rationalMul(
8752
- rationalFromInt(payoutIAssetAmt - reimburstmentIAsset),
8753
- price
8754
- )
8800
+ price
8755
8801
  );
8756
8802
  const resultVal = (0, import_lucid49.addAssets)(
8757
8803
  robUtxo.assets,
@@ -8778,12 +8824,9 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8778
8824
  })
8779
8825
  );
8780
8826
  const payoutCollateralAmt = payoutAmt;
8781
- const reimbursementCollateral = calculateFeeFromRatio(
8827
+ const redeemedIAssetAmt = calculatePurchaseAmtWhenRobSellOrder(
8828
+ payoutCollateralAmt,
8782
8829
  redemptionReimbursementRatio,
8783
- payoutCollateralAmt
8784
- );
8785
- const redeemedIAssetAmt = iassetValueOfCollateral(
8786
- payoutCollateralAmt - reimbursementCollateral,
8787
8830
  price
8788
8831
  );
8789
8832
  const resultVal = (0, import_lucid49.addAssets)(
@@ -9225,22 +9268,22 @@ var import_lucid53 = require("@lucid-evolution/lucid");
9225
9268
 
9226
9269
  // src/contracts/rob-leverage/helpers.ts
9227
9270
  var import_fp_ts19 = require("fp-ts");
9228
- var import_decimal = require("decimal.js");
9271
+ var import_decimal2 = require("decimal.js");
9229
9272
  var MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
9230
9273
  function approximateLeverageRedemptions(baseCollateral, targetLeverage, redemptionReimbursementRatio, debtMintingFeeRatio) {
9231
- const debtMintingFeeRatioDecimal = (0, import_decimal.Decimal)(debtMintingFeeRatio.numerator).div(
9274
+ const debtMintingFeeRatioDecimal = (0, import_decimal2.Decimal)(debtMintingFeeRatio.numerator).div(
9232
9275
  debtMintingFeeRatio.denominator
9233
9276
  );
9234
- const redemptionReimbursementRatioDecimal = (0, import_decimal.Decimal)(
9277
+ const redemptionReimbursementRatioDecimal = (0, import_decimal2.Decimal)(
9235
9278
  redemptionReimbursementRatio.numerator
9236
9279
  ).div(redemptionReimbursementRatio.denominator);
9237
9280
  const totalFeeRatio = debtMintingFeeRatioDecimal.add(
9238
9281
  redemptionReimbursementRatioDecimal
9239
9282
  );
9240
- const bExFees = (0, import_decimal.Decimal)(baseCollateral).mul(targetLeverage).minus(baseCollateral).floor();
9241
- const b = bExFees.div((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
9283
+ const bExFees = (0, import_decimal2.Decimal)(baseCollateral).mul(targetLeverage).minus(baseCollateral).floor();
9284
+ const b = bExFees.div((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
9242
9285
  const collateralRatio = {
9243
- numerator: fromDecimal((0, import_decimal.Decimal)(baseCollateral).add(bExFees)),
9286
+ numerator: fromDecimal((0, import_decimal2.Decimal)(baseCollateral).add(bExFees)),
9244
9287
  denominator: fromDecimal(b)
9245
9288
  };
9246
9289
  return {
@@ -9250,12 +9293,6 @@ function approximateLeverageRedemptions(baseCollateral, targetLeverage, redempti
9250
9293
  };
9251
9294
  }
9252
9295
  function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement, redemptionReimbursementRatio, iassetPrice, redemptionLrps) {
9253
- const priceDecimal = (0, import_decimal.Decimal)(iassetPrice.numerator).div(
9254
- iassetPrice.denominator
9255
- );
9256
- const reimbRatio = (0, import_decimal.Decimal)(redemptionReimbursementRatio.numerator).div(
9257
- redemptionReimbursementRatio.denominator
9258
- );
9259
9296
  const redemptionDetails = import_fp_ts19.function.pipe(
9260
9297
  redemptionLrps,
9261
9298
  import_fp_ts19.array.reduce(
@@ -9282,8 +9319,10 @@ function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursem
9282
9319
  0n
9283
9320
  );
9284
9321
  const collateralToSpendInitial = acc.remainingCollateralToSpend - newRemainingCollateral;
9285
- const finalPayoutIAssets = fromDecimal(
9286
- (0, import_decimal.Decimal)(collateralToSpendInitial).div(priceDecimal).floor().div((0, import_decimal.Decimal)(1).minus(reimbRatio)).floor()
9322
+ const finalPayoutIAssets = calculateSpendAmtWhenRobBuyOrder(
9323
+ collateralToSpendInitial,
9324
+ redemptionReimbursementRatio,
9325
+ iassetPrice
9287
9326
  );
9288
9327
  const feeIAssetAmt = calculateFeeFromRatio(
9289
9328
  redemptionReimbursementRatio,
@@ -9335,10 +9374,10 @@ function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursem
9335
9374
  };
9336
9375
  }
9337
9376
  function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage, baseCollateral, iassetPrice, debtMintingFeePercentage, redemptionReimbursementPercentage, allLrps) {
9338
- const debtMintingFeeRatioDecimal = (0, import_decimal.Decimal)(
9377
+ const debtMintingFeeRatioDecimal = (0, import_decimal2.Decimal)(
9339
9378
  debtMintingFeePercentage.getOnChainInt
9340
9379
  ).div(OCD_DECIMAL_UNIT).div(100);
9341
- const redemptionReimbursementRatioDecimal = (0, import_decimal.Decimal)(
9380
+ const redemptionReimbursementRatioDecimal = (0, import_decimal2.Decimal)(
9342
9381
  redemptionReimbursementPercentage.getOnChainInt
9343
9382
  ).div(OCD_DECIMAL_UNIT).div(100);
9344
9383
  const totalFeeRatio = debtMintingFeeRatioDecimal.add(
@@ -9354,15 +9393,15 @@ function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage,
9354
9393
  if (leverage <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
9355
9394
  return void 0;
9356
9395
  }
9357
- const bExFees = (0, import_decimal.Decimal)(baseCollateral).mul(leverage).minus(baseCollateral).floor();
9358
- const b = bExFees.div((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
9396
+ const bExFees = (0, import_decimal2.Decimal)(baseCollateral).mul(leverage).minus(baseCollateral).floor();
9397
+ const b = bExFees.div((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
9359
9398
  const cappedB = bigintMin(
9360
9399
  maxAvailableCollateralForRedemption,
9361
9400
  fromDecimal(b)
9362
9401
  );
9363
- const cappedBExFees = (0, import_decimal.Decimal)(cappedB).mul((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
9364
- const collateralRatio = (0, import_decimal.Decimal)(
9365
- (0, import_decimal.Decimal)(baseCollateral).add(cappedBExFees)
9402
+ const cappedBExFees = (0, import_decimal2.Decimal)(cappedB).mul((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
9403
+ const collateralRatio = (0, import_decimal2.Decimal)(
9404
+ (0, import_decimal2.Decimal)(baseCollateral).add(cappedBExFees)
9366
9405
  ).div(cappedB);
9367
9406
  return {
9368
9407
  getOnChainInt: fromDecimal(
@@ -9371,16 +9410,16 @@ function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage,
9371
9410
  };
9372
9411
  }
9373
9412
  function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collateralRatio, baseCollateral, iassetPrice, debtMintingFeeRatio, redemptionReimbursementRatio, allLrps) {
9374
- const debtMintingFeeRatioDecimal = (0, import_decimal.Decimal)(debtMintingFeeRatio.numerator).div(
9413
+ const debtMintingFeeRatioDecimal = (0, import_decimal2.Decimal)(debtMintingFeeRatio.numerator).div(
9375
9414
  debtMintingFeeRatio.denominator
9376
9415
  );
9377
- const redemptionReimbursementRatioDecimal = (0, import_decimal.Decimal)(
9416
+ const redemptionReimbursementRatioDecimal = (0, import_decimal2.Decimal)(
9378
9417
  redemptionReimbursementRatio.numerator
9379
9418
  ).div(redemptionReimbursementRatio.denominator);
9380
9419
  const totalFeeRatio = debtMintingFeeRatioDecimal.add(
9381
9420
  redemptionReimbursementRatioDecimal
9382
9421
  );
9383
- const collateralRatioDecimal = (0, import_decimal.Decimal)(collateralRatio.numerator).div(
9422
+ const collateralRatioDecimal = (0, import_decimal2.Decimal)(collateralRatio.numerator).div(
9384
9423
  collateralRatio.denominator
9385
9424
  );
9386
9425
  const maxAvailableCollateralForRedemption = calculateTotalCollateralForRedemption(
@@ -9393,20 +9432,20 @@ function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collatera
9393
9432
  if (collateralRatioDecimal.toNumber() <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
9394
9433
  return void 0;
9395
9434
  }
9396
- const theoreticalMaxLeverage = (0, import_decimal.Decimal)((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).div(collateralRatioDecimal.minus(1).add(totalFeeRatio)).add(1);
9435
+ const theoreticalMaxLeverage = (0, import_decimal2.Decimal)((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).div(collateralRatioDecimal.minus(1).add(totalFeeRatio)).add(1);
9397
9436
  const bExFees = theoreticalMaxLeverage.mul(baseCollateral).minus(baseCollateral).floor();
9398
- const b = bExFees.div((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
9437
+ const b = bExFees.div((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
9399
9438
  const cappedB = bigintMin(
9400
9439
  maxAvailableCollateralForRedemption,
9401
9440
  fromDecimal(b)
9402
9441
  );
9403
- const cappedBExFees = (0, import_decimal.Decimal)(cappedB).mul((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
9404
- return (0, import_decimal.Decimal)(baseCollateral).add(cappedBExFees).div(baseCollateral).toNumber();
9442
+ const cappedBExFees = (0, import_decimal2.Decimal)(cappedB).mul((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
9443
+ return (0, import_decimal2.Decimal)(baseCollateral).add(cappedBExFees).div(baseCollateral).toNumber();
9405
9444
  }
9406
9445
 
9407
9446
  // src/contracts/rob-leverage/transactions.ts
9408
9447
  var import_cardano_offchain_common24 = require("@3rd-eye-labs/cardano-offchain-common");
9409
- var import_decimal2 = __toESM(require("decimal.js"));
9448
+ var import_decimal3 = __toESM(require("decimal.js"));
9410
9449
  async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, cdpCreatorOref, interestOracleOref, treasuryOref, sysParams, lucid, allRobs, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
9411
9450
  const network = lucid.config().network;
9412
9451
  const currentTime = BigInt((0, import_lucid53.slotToUnixTime)(network, currentSlot));
@@ -9517,9 +9556,9 @@ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, i
9517
9556
  )
9518
9557
  );
9519
9558
  const mintedAmt = fromDecimal(
9520
- (0, import_decimal2.default)(redemptionDetails.totalIAssetPayout).div(
9521
- (0, import_decimal2.default)(1).minus(
9522
- (0, import_decimal2.default)(iassetDatum.debtMintingFeeRatio.numerator).div(
9559
+ (0, import_decimal3.default)(redemptionDetails.totalIAssetPayout).div(
9560
+ (0, import_decimal3.default)(1).minus(
9561
+ (0, import_decimal3.default)(iassetDatum.debtMintingFeeRatio.numerator).div(
9523
9562
  iassetDatum.debtMintingFeeRatio.denominator
9524
9563
  )
9525
9564
  )
@@ -11539,14 +11578,17 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
11539
11578
  InterestCollectionParamsSchema,
11540
11579
  InterestOracleDatumSchema,
11541
11580
  InterestOracleParamsSchema,
11581
+ MAX_BUY_ROB_REDEMPTIONS_COUNT,
11542
11582
  MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET,
11543
11583
  MAX_E2S2S_ENTRIES_COUNT,
11544
11584
  MAX_REDEMPTIONS_WITH_CDP_OPEN,
11585
+ MAX_SELL_ROB_REDEMPTIONS_COUNT,
11545
11586
  MIN_ROB_COLLATERAL_AMT,
11546
11587
  ONE_DAY,
11547
11588
  ONE_HOUR,
11548
11589
  ONE_SECOND,
11549
11590
  ONE_YEAR,
11591
+ OneShotParamsSchema,
11550
11592
  OracleIdxSchema,
11551
11593
  PRICE_UPDATE_MAGIC,
11552
11594
  PollManagerParams,
@@ -11591,6 +11633,10 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
11591
11633
  calculateIAssetRedemptionAmt,
11592
11634
  calculateLeverageFromCollateralRatio,
11593
11635
  calculateMinCollateralCappedIAssetRedemptionAmt,
11636
+ calculatePurchaseAmtWhenRobBuyOrder,
11637
+ calculatePurchaseAmtWhenRobSellOrder,
11638
+ calculateSpendAmtWhenRobBuyOrder,
11639
+ calculateSpendAmtWhenRobSellOrder,
11594
11640
  calculateTotalCollateralForRedemption,
11595
11641
  calculateUnitaryInterest,
11596
11642
  calculateUnitaryInterestSinceOracleLastUpdated,
@@ -11603,6 +11649,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
11603
11649
  castGovParams,
11604
11650
  castInterestCollectionParams,
11605
11651
  castInterestOracleParams,
11652
+ castOneShotParams,
11606
11653
  castPollManagerParams,
11607
11654
  castPollShardParams,
11608
11655
  castPriceOracleParams,
@@ -11703,6 +11750,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
11703
11750
  mkInterestCollectionValidator,
11704
11751
  mkInterestCollectionValidatorFromSP,
11705
11752
  mkInterestOracleValidator,
11753
+ mkOneShotPolicy,
11706
11754
  mkPollManagerValidator,
11707
11755
  mkPollManagerValidatorFromSP,
11708
11756
  mkPollShardValidator,
package/dist/index.mjs CHANGED
@@ -8482,7 +8482,49 @@ import {
8482
8482
  lovelacesAmt as lovelacesAmt3,
8483
8483
  mkAssetsOf as mkAssetsOf9
8484
8484
  } from "@3rd-eye-labs/cardano-offchain-common";
8485
+ import Decimal from "decimal.js";
8485
8486
  var MIN_ROB_COLLATERAL_AMT = 3000000n;
8487
+ var MAX_SELL_ROB_REDEMPTIONS_COUNT = 18;
8488
+ var MAX_BUY_ROB_REDEMPTIONS_COUNT = 20;
8489
+ function calculatePurchaseAmtWhenRobBuyOrder(sellIassetAmt, redemptionReimbursementRatio, price) {
8490
+ const reimbursementIAsset = calculateFeeFromRatio(
8491
+ redemptionReimbursementRatio,
8492
+ sellIassetAmt
8493
+ );
8494
+ const collateralForRedemption = rationalFloor(
8495
+ rationalMul(rationalFromInt(sellIassetAmt - reimbursementIAsset), price)
8496
+ );
8497
+ return collateralForRedemption;
8498
+ }
8499
+ function calculateSpendAmtWhenRobBuyOrder(purchaseCollateralAmt, redemptionReimbursementRatio, price) {
8500
+ const priceDecimal = Decimal(price.numerator).div(price.denominator);
8501
+ const reimbRatio = Decimal(redemptionReimbursementRatio.numerator).div(
8502
+ redemptionReimbursementRatio.denominator
8503
+ );
8504
+ return fromDecimal(
8505
+ Decimal(purchaseCollateralAmt).div(priceDecimal).floor().div(Decimal(1).minus(reimbRatio)).floor()
8506
+ );
8507
+ }
8508
+ function calculatePurchaseAmtWhenRobSellOrder(sellCollateralAmt, redemptionReimbursementRatio, price) {
8509
+ const reimbursementCollateral = calculateFeeFromRatio(
8510
+ redemptionReimbursementRatio,
8511
+ sellCollateralAmt
8512
+ );
8513
+ const redeemedIAssetAmt = iassetValueOfCollateral(
8514
+ sellCollateralAmt - reimbursementCollateral,
8515
+ price
8516
+ );
8517
+ return redeemedIAssetAmt;
8518
+ }
8519
+ function calculateSpendAmtWhenRobSellOrder(purchaseIassetAmt, redemptionReimbursementRatio, price) {
8520
+ const priceDecimal = Decimal(price.numerator).div(price.denominator);
8521
+ const reimbRatio = Decimal(redemptionReimbursementRatio.numerator).div(
8522
+ redemptionReimbursementRatio.denominator
8523
+ );
8524
+ return fromDecimal(
8525
+ Decimal(purchaseIassetAmt).mul(priceDecimal).floor().div(Decimal(1).minus(reimbRatio)).floor()
8526
+ );
8527
+ }
8486
8528
  function robCollateralAmtToSpend(robAssets, robOrderType) {
8487
8529
  return match18(robOrderType).returnType().with({ BuyIAssetOrder: P18.select() }, (content) => {
8488
8530
  if (isSameAssetClass3(adaAssetClass5, content.collateralAsset)) {
@@ -8578,15 +8620,10 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8578
8620
  throw new Error("Only same collateral asset");
8579
8621
  }
8580
8622
  const payoutIAssetAmt = payoutAmt;
8581
- const reimburstmentIAsset = calculateFeeFromRatio(
8623
+ const collateralForRedemption = calculatePurchaseAmtWhenRobBuyOrder(
8624
+ payoutIAssetAmt,
8582
8625
  redemptionReimbursementRatio,
8583
- payoutIAssetAmt
8584
- );
8585
- const collateralForRedemption = rationalFloor(
8586
- rationalMul(
8587
- rationalFromInt(payoutIAssetAmt - reimburstmentIAsset),
8588
- price
8589
- )
8626
+ price
8590
8627
  );
8591
8628
  const resultVal = addAssets12(
8592
8629
  robUtxo.assets,
@@ -8613,12 +8650,9 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
8613
8650
  })
8614
8651
  );
8615
8652
  const payoutCollateralAmt = payoutAmt;
8616
- const reimbursementCollateral = calculateFeeFromRatio(
8653
+ const redeemedIAssetAmt = calculatePurchaseAmtWhenRobSellOrder(
8654
+ payoutCollateralAmt,
8617
8655
  redemptionReimbursementRatio,
8618
- payoutCollateralAmt
8619
- );
8620
- const redeemedIAssetAmt = iassetValueOfCollateral(
8621
- payoutCollateralAmt - reimbursementCollateral,
8622
8656
  price
8623
8657
  );
8624
8658
  const resultVal = addAssets12(
@@ -9084,22 +9118,22 @@ import {
9084
9118
 
9085
9119
  // src/contracts/rob-leverage/helpers.ts
9086
9120
  import { array as A11, function as F18 } from "fp-ts";
9087
- import { Decimal } from "decimal.js";
9121
+ import { Decimal as Decimal2 } from "decimal.js";
9088
9122
  var MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
9089
9123
  function approximateLeverageRedemptions(baseCollateral, targetLeverage, redemptionReimbursementRatio, debtMintingFeeRatio) {
9090
- const debtMintingFeeRatioDecimal = Decimal(debtMintingFeeRatio.numerator).div(
9124
+ const debtMintingFeeRatioDecimal = Decimal2(debtMintingFeeRatio.numerator).div(
9091
9125
  debtMintingFeeRatio.denominator
9092
9126
  );
9093
- const redemptionReimbursementRatioDecimal = Decimal(
9127
+ const redemptionReimbursementRatioDecimal = Decimal2(
9094
9128
  redemptionReimbursementRatio.numerator
9095
9129
  ).div(redemptionReimbursementRatio.denominator);
9096
9130
  const totalFeeRatio = debtMintingFeeRatioDecimal.add(
9097
9131
  redemptionReimbursementRatioDecimal
9098
9132
  );
9099
- const bExFees = Decimal(baseCollateral).mul(targetLeverage).minus(baseCollateral).floor();
9100
- const b = bExFees.div(Decimal(1).minus(totalFeeRatio)).floor();
9133
+ const bExFees = Decimal2(baseCollateral).mul(targetLeverage).minus(baseCollateral).floor();
9134
+ const b = bExFees.div(Decimal2(1).minus(totalFeeRatio)).floor();
9101
9135
  const collateralRatio = {
9102
- numerator: fromDecimal(Decimal(baseCollateral).add(bExFees)),
9136
+ numerator: fromDecimal(Decimal2(baseCollateral).add(bExFees)),
9103
9137
  denominator: fromDecimal(b)
9104
9138
  };
9105
9139
  return {
@@ -9109,12 +9143,6 @@ function approximateLeverageRedemptions(baseCollateral, targetLeverage, redempti
9109
9143
  };
9110
9144
  }
9111
9145
  function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement, redemptionReimbursementRatio, iassetPrice, redemptionLrps) {
9112
- const priceDecimal = Decimal(iassetPrice.numerator).div(
9113
- iassetPrice.denominator
9114
- );
9115
- const reimbRatio = Decimal(redemptionReimbursementRatio.numerator).div(
9116
- redemptionReimbursementRatio.denominator
9117
- );
9118
9146
  const redemptionDetails = F18.pipe(
9119
9147
  redemptionLrps,
9120
9148
  A11.reduce(
@@ -9141,8 +9169,10 @@ function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursem
9141
9169
  0n
9142
9170
  );
9143
9171
  const collateralToSpendInitial = acc.remainingCollateralToSpend - newRemainingCollateral;
9144
- const finalPayoutIAssets = fromDecimal(
9145
- Decimal(collateralToSpendInitial).div(priceDecimal).floor().div(Decimal(1).minus(reimbRatio)).floor()
9172
+ const finalPayoutIAssets = calculateSpendAmtWhenRobBuyOrder(
9173
+ collateralToSpendInitial,
9174
+ redemptionReimbursementRatio,
9175
+ iassetPrice
9146
9176
  );
9147
9177
  const feeIAssetAmt = calculateFeeFromRatio(
9148
9178
  redemptionReimbursementRatio,
@@ -9194,10 +9224,10 @@ function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursem
9194
9224
  };
9195
9225
  }
9196
9226
  function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage, baseCollateral, iassetPrice, debtMintingFeePercentage, redemptionReimbursementPercentage, allLrps) {
9197
- const debtMintingFeeRatioDecimal = Decimal(
9227
+ const debtMintingFeeRatioDecimal = Decimal2(
9198
9228
  debtMintingFeePercentage.getOnChainInt
9199
9229
  ).div(OCD_DECIMAL_UNIT).div(100);
9200
- const redemptionReimbursementRatioDecimal = Decimal(
9230
+ const redemptionReimbursementRatioDecimal = Decimal2(
9201
9231
  redemptionReimbursementPercentage.getOnChainInt
9202
9232
  ).div(OCD_DECIMAL_UNIT).div(100);
9203
9233
  const totalFeeRatio = debtMintingFeeRatioDecimal.add(
@@ -9213,15 +9243,15 @@ function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage,
9213
9243
  if (leverage <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
9214
9244
  return void 0;
9215
9245
  }
9216
- const bExFees = Decimal(baseCollateral).mul(leverage).minus(baseCollateral).floor();
9217
- const b = bExFees.div(Decimal(1).minus(totalFeeRatio)).floor();
9246
+ const bExFees = Decimal2(baseCollateral).mul(leverage).minus(baseCollateral).floor();
9247
+ const b = bExFees.div(Decimal2(1).minus(totalFeeRatio)).floor();
9218
9248
  const cappedB = bigintMin(
9219
9249
  maxAvailableCollateralForRedemption,
9220
9250
  fromDecimal(b)
9221
9251
  );
9222
- const cappedBExFees = Decimal(cappedB).mul(Decimal(1).minus(totalFeeRatio)).floor();
9223
- const collateralRatio = Decimal(
9224
- Decimal(baseCollateral).add(cappedBExFees)
9252
+ const cappedBExFees = Decimal2(cappedB).mul(Decimal2(1).minus(totalFeeRatio)).floor();
9253
+ const collateralRatio = Decimal2(
9254
+ Decimal2(baseCollateral).add(cappedBExFees)
9225
9255
  ).div(cappedB);
9226
9256
  return {
9227
9257
  getOnChainInt: fromDecimal(
@@ -9230,16 +9260,16 @@ function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage,
9230
9260
  };
9231
9261
  }
9232
9262
  function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collateralRatio, baseCollateral, iassetPrice, debtMintingFeeRatio, redemptionReimbursementRatio, allLrps) {
9233
- const debtMintingFeeRatioDecimal = Decimal(debtMintingFeeRatio.numerator).div(
9263
+ const debtMintingFeeRatioDecimal = Decimal2(debtMintingFeeRatio.numerator).div(
9234
9264
  debtMintingFeeRatio.denominator
9235
9265
  );
9236
- const redemptionReimbursementRatioDecimal = Decimal(
9266
+ const redemptionReimbursementRatioDecimal = Decimal2(
9237
9267
  redemptionReimbursementRatio.numerator
9238
9268
  ).div(redemptionReimbursementRatio.denominator);
9239
9269
  const totalFeeRatio = debtMintingFeeRatioDecimal.add(
9240
9270
  redemptionReimbursementRatioDecimal
9241
9271
  );
9242
- const collateralRatioDecimal = Decimal(collateralRatio.numerator).div(
9272
+ const collateralRatioDecimal = Decimal2(collateralRatio.numerator).div(
9243
9273
  collateralRatio.denominator
9244
9274
  );
9245
9275
  const maxAvailableCollateralForRedemption = calculateTotalCollateralForRedemption(
@@ -9252,20 +9282,20 @@ function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collatera
9252
9282
  if (collateralRatioDecimal.toNumber() <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
9253
9283
  return void 0;
9254
9284
  }
9255
- const theoreticalMaxLeverage = Decimal(Decimal(1).minus(totalFeeRatio)).div(collateralRatioDecimal.minus(1).add(totalFeeRatio)).add(1);
9285
+ const theoreticalMaxLeverage = Decimal2(Decimal2(1).minus(totalFeeRatio)).div(collateralRatioDecimal.minus(1).add(totalFeeRatio)).add(1);
9256
9286
  const bExFees = theoreticalMaxLeverage.mul(baseCollateral).minus(baseCollateral).floor();
9257
- const b = bExFees.div(Decimal(1).minus(totalFeeRatio)).floor();
9287
+ const b = bExFees.div(Decimal2(1).minus(totalFeeRatio)).floor();
9258
9288
  const cappedB = bigintMin(
9259
9289
  maxAvailableCollateralForRedemption,
9260
9290
  fromDecimal(b)
9261
9291
  );
9262
- const cappedBExFees = Decimal(cappedB).mul(Decimal(1).minus(totalFeeRatio)).floor();
9263
- return Decimal(baseCollateral).add(cappedBExFees).div(baseCollateral).toNumber();
9292
+ const cappedBExFees = Decimal2(cappedB).mul(Decimal2(1).minus(totalFeeRatio)).floor();
9293
+ return Decimal2(baseCollateral).add(cappedBExFees).div(baseCollateral).toNumber();
9264
9294
  }
9265
9295
 
9266
9296
  // src/contracts/rob-leverage/transactions.ts
9267
9297
  import { mkAssetsOf as mkAssetsOf11 } from "@3rd-eye-labs/cardano-offchain-common";
9268
- import Decimal2 from "decimal.js";
9298
+ import Decimal3 from "decimal.js";
9269
9299
  async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, cdpCreatorOref, interestOracleOref, treasuryOref, sysParams, lucid, allRobs, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
9270
9300
  const network = lucid.config().network;
9271
9301
  const currentTime = BigInt(slotToUnixTime10(network, currentSlot));
@@ -9376,9 +9406,9 @@ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, i
9376
9406
  )
9377
9407
  );
9378
9408
  const mintedAmt = fromDecimal(
9379
- Decimal2(redemptionDetails.totalIAssetPayout).div(
9380
- Decimal2(1).minus(
9381
- Decimal2(iassetDatum.debtMintingFeeRatio.numerator).div(
9409
+ Decimal3(redemptionDetails.totalIAssetPayout).div(
9410
+ Decimal3(1).minus(
9411
+ Decimal3(iassetDatum.debtMintingFeeRatio.numerator).div(
9382
9412
  iassetDatum.debtMintingFeeRatio.denominator
9383
9413
  )
9384
9414
  )
@@ -11471,14 +11501,17 @@ export {
11471
11501
  InterestCollectionParamsSchema,
11472
11502
  InterestOracleDatumSchema,
11473
11503
  InterestOracleParamsSchema,
11504
+ MAX_BUY_ROB_REDEMPTIONS_COUNT,
11474
11505
  MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET,
11475
11506
  MAX_E2S2S_ENTRIES_COUNT,
11476
11507
  MAX_REDEMPTIONS_WITH_CDP_OPEN,
11508
+ MAX_SELL_ROB_REDEMPTIONS_COUNT,
11477
11509
  MIN_ROB_COLLATERAL_AMT,
11478
11510
  ONE_DAY,
11479
11511
  ONE_HOUR,
11480
11512
  ONE_SECOND,
11481
11513
  ONE_YEAR,
11514
+ OneShotParamsSchema,
11482
11515
  OracleIdxSchema,
11483
11516
  PRICE_UPDATE_MAGIC,
11484
11517
  PollManagerParams,
@@ -11523,6 +11556,10 @@ export {
11523
11556
  calculateIAssetRedemptionAmt,
11524
11557
  calculateLeverageFromCollateralRatio,
11525
11558
  calculateMinCollateralCappedIAssetRedemptionAmt,
11559
+ calculatePurchaseAmtWhenRobBuyOrder,
11560
+ calculatePurchaseAmtWhenRobSellOrder,
11561
+ calculateSpendAmtWhenRobBuyOrder,
11562
+ calculateSpendAmtWhenRobSellOrder,
11526
11563
  calculateTotalCollateralForRedemption,
11527
11564
  calculateUnitaryInterest,
11528
11565
  calculateUnitaryInterestSinceOracleLastUpdated,
@@ -11535,6 +11572,7 @@ export {
11535
11572
  castGovParams,
11536
11573
  castInterestCollectionParams,
11537
11574
  castInterestOracleParams,
11575
+ castOneShotParams,
11538
11576
  castPollManagerParams,
11539
11577
  castPollShardParams,
11540
11578
  castPriceOracleParams,
@@ -11635,6 +11673,7 @@ export {
11635
11673
  mkInterestCollectionValidator,
11636
11674
  mkInterestCollectionValidatorFromSP,
11637
11675
  mkInterestOracleValidator,
11676
+ mkOneShotPolicy,
11638
11677
  mkPollManagerValidator,
11639
11678
  mkPollManagerValidatorFromSP,
11640
11679
  mkPollShardValidator,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigo-labs/indigo-sdk",
3
- "version": "0.3.19",
3
+ "version": "0.3.21",
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",
@@ -14,7 +14,12 @@ import {
14
14
  serialiseRobRedeemer,
15
15
  } from './types-new';
16
16
  import { calculateFeeFromRatio } from '../../utils/indigo-helpers';
17
- import { BigIntOrd, sum, zeroNegatives } from '../../utils/bigint-utils';
17
+ import {
18
+ BigIntOrd,
19
+ fromDecimal,
20
+ sum,
21
+ zeroNegatives,
22
+ } from '../../utils/bigint-utils';
18
23
  import {
19
24
  readonlyArray as RA,
20
25
  array as A,
@@ -43,9 +48,117 @@ import {
43
48
  import { insertSorted, shuffle } from '../../utils/array-utils';
44
49
  import { iassetValueOfCollateral } from '../cdp/helpers';
45
50
  import { OracleIdx } from '../price-oracle/types-new';
51
+ import Decimal from 'decimal.js';
46
52
 
47
53
  export const MIN_ROB_COLLATERAL_AMT = 3_000_000n;
48
54
 
55
+ /**
56
+ * The maximum of redemptions for a Tx that is doing only sell order redemptions.
57
+ * Based on the benchmarks.
58
+ */
59
+ export const MAX_SELL_ROB_REDEMPTIONS_COUNT = 18;
60
+ /**
61
+ * The maximum of redemptions for a Tx that is doing only buy order redemptions.
62
+ * Based on the benchmarks.
63
+ */
64
+ export const MAX_BUY_ROB_REDEMPTIONS_COUNT = 20;
65
+
66
+ /**
67
+ * Helper for ROB redemptions. A redeemer is selling iAssets against
68
+ * a buy order, i.e. buying a collateral asset.
69
+ * The return is the amount of collateral asset he buys.
70
+ */
71
+ export function calculatePurchaseAmtWhenRobBuyOrder(
72
+ sellIassetAmt: bigint,
73
+ redemptionReimbursementRatio: Rational,
74
+ price: Rational,
75
+ ): bigint {
76
+ const reimbursementIAsset = calculateFeeFromRatio(
77
+ redemptionReimbursementRatio,
78
+ sellIassetAmt,
79
+ );
80
+
81
+ const collateralForRedemption = rationalFloor(
82
+ rationalMul(rationalFromInt(sellIassetAmt - reimbursementIAsset), price),
83
+ );
84
+
85
+ return collateralForRedemption;
86
+ }
87
+
88
+ /**
89
+ * A redeemer is purchasing given collateral amount against buy order.
90
+ * Calculate what is the amount of iAsset the user sells/spends.
91
+ */
92
+ export function calculateSpendAmtWhenRobBuyOrder(
93
+ purchaseCollateralAmt: bigint,
94
+ redemptionReimbursementRatio: Rational,
95
+ price: Rational,
96
+ ): bigint {
97
+ const priceDecimal = Decimal(price.numerator).div(price.denominator);
98
+ const reimbRatio = Decimal(redemptionReimbursementRatio.numerator).div(
99
+ redemptionReimbursementRatio.denominator,
100
+ );
101
+
102
+ // TODO: make corrections here in case we can be ceiling this number instead.
103
+ // We want to be flooring here so that we don't go over the collateral to spend.
104
+ // Flooring multiple times is necessary here otherwise we could go over the collateral available.
105
+ // iassets = floor(collateral / price) / floor(1 - reimbursement fee)
106
+ return fromDecimal(
107
+ Decimal(purchaseCollateralAmt)
108
+ .div(priceDecimal)
109
+ .floor()
110
+ .div(Decimal(1).minus(reimbRatio))
111
+ .floor(),
112
+ );
113
+ }
114
+
115
+ /**
116
+ * Helper for ROB redemptions. A redeemer is selling collateral against
117
+ * a sell order, i.e. buying iassets.
118
+ * The return is the amount of iassets he buys.
119
+ */
120
+ export function calculatePurchaseAmtWhenRobSellOrder(
121
+ sellCollateralAmt: bigint,
122
+ redemptionReimbursementRatio: Rational,
123
+ price: Rational,
124
+ ): bigint {
125
+ const reimbursementCollateral = calculateFeeFromRatio(
126
+ redemptionReimbursementRatio,
127
+ sellCollateralAmt,
128
+ );
129
+
130
+ const redeemedIAssetAmt = iassetValueOfCollateral(
131
+ sellCollateralAmt - reimbursementCollateral,
132
+ price,
133
+ );
134
+
135
+ return redeemedIAssetAmt;
136
+ }
137
+
138
+ /**
139
+ * A redeemer is purchasing given iasset amount against sell order.
140
+ * Calculate what is the amount of collateral the user sells/spends.
141
+ */
142
+ export function calculateSpendAmtWhenRobSellOrder(
143
+ purchaseIassetAmt: bigint,
144
+ redemptionReimbursementRatio: Rational,
145
+ price: Rational,
146
+ ): bigint {
147
+ const priceDecimal = Decimal(price.numerator).div(price.denominator);
148
+ const reimbRatio = Decimal(redemptionReimbursementRatio.numerator).div(
149
+ redemptionReimbursementRatio.denominator,
150
+ );
151
+
152
+ // collateral = floor(iasset * price) / floor(1 - reimbursement fee)
153
+ return fromDecimal(
154
+ Decimal(purchaseIassetAmt)
155
+ .mul(priceDecimal)
156
+ .floor()
157
+ .div(Decimal(1).minus(reimbRatio))
158
+ .floor(),
159
+ );
160
+ }
161
+
49
162
  /**
50
163
  * The amount of collateral asset available in the ROB when buy order. In case of ADA, take
51
164
  * into account the min UTXO collateral.
@@ -181,6 +294,7 @@ export function robBuyOrderSummary(
181
294
  } {
182
295
  const redeemable = robCollateralAmtToSpend(robAssets, robOrderType);
183
296
 
297
+ // TODO: this is incorrect since it doesn't take into account the reimbursement ratio.
184
298
  const payoutAmt = iassetValueOfCollateral(redeemable, oraclePrice);
185
299
 
186
300
  return {
@@ -286,16 +400,10 @@ export function buildRedemptionsTx(
286
400
 
287
401
  const payoutIAssetAmt = payoutAmt;
288
402
 
289
- const reimburstmentIAsset = calculateFeeFromRatio(
290
- redemptionReimbursementRatio,
403
+ const collateralForRedemption = calculatePurchaseAmtWhenRobBuyOrder(
291
404
  payoutIAssetAmt,
292
- );
293
-
294
- const collateralForRedemption = rationalFloor(
295
- rationalMul(
296
- rationalFromInt(payoutIAssetAmt - reimburstmentIAsset),
297
- price,
298
- ),
405
+ redemptionReimbursementRatio,
406
+ price,
299
407
  );
300
408
 
301
409
  const resultVal = addAssets(
@@ -327,13 +435,9 @@ export function buildRedemptionsTx(
327
435
 
328
436
  const payoutCollateralAmt = payoutAmt;
329
437
 
330
- const reimbursementCollateral = calculateFeeFromRatio(
331
- redemptionReimbursementRatio,
438
+ const redeemedIAssetAmt = calculatePurchaseAmtWhenRobSellOrder(
332
439
  payoutCollateralAmt,
333
- );
334
-
335
- const redeemedIAssetAmt = iassetValueOfCollateral(
336
- payoutCollateralAmt - reimbursementCollateral,
440
+ redemptionReimbursementRatio,
337
441
  price,
338
442
  );
339
443
 
@@ -57,6 +57,7 @@ import { bigintMax, bigintMin, fromDecimal } from '../../utils/bigint-utils';
57
57
  import { array as A, function as F } from 'fp-ts';
58
58
  import { Decimal } from 'decimal.js';
59
59
  import {
60
+ calculateSpendAmtWhenRobBuyOrder,
60
61
  calculateTotalCollateralForRedemption,
61
62
  robCollateralAmtToSpend,
62
63
  } from '../rob/helpers';
@@ -160,20 +161,12 @@ export function summarizeActualLeverageRedemptions(
160
161
  */
161
162
  totalIAssetPayout: bigint;
162
163
  } {
163
- const priceDecimal = Decimal(iassetPrice.numerator).div(
164
- iassetPrice.denominator,
165
- );
166
-
167
164
  type Accumulator = {
168
165
  /// The remaining collateral to spend from ROBs
169
166
  remainingCollateralToSpend: bigint;
170
167
  redemptions: ROBRedemptionDetails[];
171
168
  };
172
169
 
173
- const reimbRatio = Decimal(redemptionReimbursementRatio.numerator).div(
174
- redemptionReimbursementRatio.denominator,
175
- );
176
-
177
170
  const redemptionDetails = F.pipe(
178
171
  redemptionLrps,
179
172
  A.reduce<[UTxO, RobDatum], Accumulator>(
@@ -208,16 +201,10 @@ export function summarizeActualLeverageRedemptions(
208
201
  const collateralToSpendInitial =
209
202
  acc.remainingCollateralToSpend - newRemainingCollateral;
210
203
 
211
- // TODO: make corrections here in case we can be ceiling this number instead.
212
- // We want to be flooring here so that we don't go over the collateral to spend.
213
- // Flooring multiple times is necessary here otherwise we could go over the collateral available.
214
- // iassets = floor(collateral / price) / floor(1 - reimbursement fee)
215
- const finalPayoutIAssets = fromDecimal(
216
- Decimal(collateralToSpendInitial)
217
- .div(priceDecimal)
218
- .floor()
219
- .div(Decimal(1).minus(reimbRatio))
220
- .floor(),
204
+ const finalPayoutIAssets = calculateSpendAmtWhenRobBuyOrder(
205
+ collateralToSpendInitial,
206
+ redemptionReimbursementRatio,
207
+ iassetPrice,
221
208
  );
222
209
 
223
210
  const feeIAssetAmt = calculateFeeFromRatio(
package/src/index.ts CHANGED
@@ -55,7 +55,9 @@ export * from './contracts/rob/types';
55
55
  export * from './contracts/rob/types-new';
56
56
  export * from './contracts/rob/transactions';
57
57
  export * from './contracts/rob/scripts';
58
+ export * from './contracts/one-shot/scripts';
58
59
  export * from './contracts/one-shot/transactions';
60
+ export * from './contracts/one-shot/types';
59
61
  export * from './contracts/rob-leverage/transactions';
60
62
  export * from './contracts/rob-leverage/helpers';
61
63
  export * from './contracts/price-oracle/transactions';