@indigo-labs/indigo-sdk 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -4639,17 +4639,22 @@ declare function parseStableswapOrderRedeemer(redeemerCborHex: string): option.O
4639
4639
  declare function parseStableswapOrderRedeemerOrThrow(redeemerCborHex: string): StableswapOrderRedeemer;
4640
4640
 
4641
4641
  declare const BASE_MAX_EXECUTION_FEE = 1620000n;
4642
- type OrderProcessConfig = {
4642
+ type PSMProcessingConfig = {
4643
4643
  /**
4644
- * Whether to ignore that an order has max execution fee set lower
4645
- * than the threshold (i.e. the processor might be paying the remaining cardano tx fee).
4644
+ * Whether to enforce that an order has max execution fee satisfying
4645
+ * min threshold (i.e. the processor might be paying the remaining cardano tx fee).
4646
4646
  *
4647
- * The default should be `false`. In case, owner wants to process
4648
- * such order himself, he can ignore the constraint.
4647
+ * In case, owner wants to process such order himself, he can ignore the constraint.
4648
+ * @default true
4649
4649
  */
4650
- ignoreMaxExecutionFeeConstraint: boolean;
4650
+ enforceMaxExecutionFeeConstraint?: boolean;
4651
+ /**
4652
+ * Whether to enforce the minimum lovelace constraint. If not enforced,
4653
+ * the processor might need to pay the min lovelace for the order output.
4654
+ * @default true
4655
+ */
4656
+ enforceMinLovelaceConstraint?: boolean;
4651
4657
  };
4652
- declare const defaultOrderProcessingConfig: OrderProcessConfig;
4653
4658
  declare function createDestinationDatum(datum: Data$1.Data | null, outRef: OutRef): string;
4654
4659
  type StableswapInfo = {
4655
4660
  suppliedIasset: bigint;
@@ -4664,6 +4669,15 @@ type StableswapOrderInfo = {
4664
4669
  orderType: 'MINTING' | 'REDEEMING';
4665
4670
  swapInfo: StableswapInfo;
4666
4671
  };
4672
+ /**
4673
+ * This is an approximation of the amount of lovelace that will be needed to pay for the output.
4674
+ */
4675
+ declare function estimateMinOrderOutputLovelaces(lucid: LucidEvolution, orderDatum: StableswapOrderDatum,
4676
+ /**
4677
+ * Including execution fee as well.
4678
+ */
4679
+ orderAssets: Assets): bigint;
4680
+ type OrderTypeError = 'VALUE_ERROR';
4667
4681
  /**
4668
4682
  * Determine the PSM order type.
4669
4683
  */
@@ -4675,27 +4689,32 @@ declare function psmOrderType(order: ParsedOutput<StableswapOrderDatum>, sysPara
4675
4689
  suppliedIassets: bigint;
4676
4690
  } | {
4677
4691
  type: 'ERROR';
4692
+ errorTag: OrderTypeError;
4678
4693
  reason: string;
4679
4694
  };
4695
+ type SummaryError = OrderTypeError | 'ASSET_MISMATCH' | 'EXECUTION_FEE' | 'MAX_FEE' | 'INSUFFICIENT_LOVELACES';
4680
4696
  type SummaryResult = {
4681
4697
  _tag: 'SUCCESS';
4682
4698
  result: StableswapOrderInfo;
4683
4699
  } | {
4684
4700
  _tag: 'ERROR';
4685
- reason: string;
4701
+ errorTag: SummaryError;
4702
+ description: string;
4686
4703
  };
4687
4704
  /**
4688
- * Summarise the order in detail
4705
+ * Summarise the order. Validate all the necessary constraints
4706
+ * for this order to be processed.
4689
4707
  */
4690
- declare function summariseOrder(order: ParsedOutput<StableswapOrderDatum>, psmPool: ParsedOutput<StableswapPoolContent>, sysParams: SystemParams, orderProcessingConfig: OrderProcessConfig): SummaryResult;
4708
+ declare function summariseOrder(lucid: LucidEvolution, order: ParsedOutput<StableswapOrderDatum>, psmPool: ParsedOutput<StableswapPoolContent>, sysParams: SystemParams, psmProcessingConfig?: PSMProcessingConfig): SummaryResult;
4691
4709
  /**
4692
- * Pick only orders that are valid and can be processed based on available liquidity.
4710
+ * Pick only orders that are valid, belong to the PSM pool,
4711
+ * and can be processed based on available liquidity.
4693
4712
  */
4694
- declare function pickValidSatisfiableOrders(orders: ParsedOutput<StableswapOrderDatum>[], pool: ParsedOutput<StableswapPoolContent>, sysParams: SystemParams, orderProcessingConfig: OrderProcessConfig): ParsedOutput<StableswapOrderDatum>[];
4713
+ declare function pickValidSatisfiableOrders(lucid: LucidEvolution, orders: ParsedOutput<StableswapOrderDatum>[], pool: ParsedOutput<StableswapPoolContent>, sysParams: SystemParams, psmProcessingConfig?: PSMProcessingConfig): ParsedOutput<StableswapOrderDatum>[];
4695
4714
 
4696
4715
  declare function createStableswapOrder(iasset: string, collateralAsset: AssetClass, amount: bigint, minting: boolean, poolDatum: StableswapPoolContent, params: SystemParams, lucid: LucidEvolution, destinationAddress?: Address, destinationInlineDatum?: Core.Data.Data, maxExecutionFee?: bigint, additionalLovelaces?: bigint, maxFeeRatio?: Rational): Promise<TxBuilder>;
4697
4716
  declare function cancelStableswapOrder(stableswapOrderOref: OutRef, sysParams: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
4698
- declare function batchProcessStableswapOrders(stableswapOrderOrefs: OutRef[], stableswapPoolOref: OutRef, treasuryOref: OutRef, sysParams: SystemParams, lucid: LucidEvolution, orderProcessingConfig?: OrderProcessConfig): Promise<TxBuilder>;
4717
+ declare function batchProcessStableswapOrders(stableswapOrderOrefs: OutRef[], stableswapPoolOref: OutRef, treasuryOref: OutRef, sysParams: SystemParams, lucid: LucidEvolution, psmProcessingConfig?: PSMProcessingConfig): Promise<TxBuilder>;
4699
4718
  declare function updateStableswapPoolFees(stableswapPoolOutRef: OutRef, stableswapFeeOutRef: OutRef, newMintingFeeRatio: Rational | null, newRedemptionFeeRatio: Rational | null, sysParams: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
4700
4719
 
4701
4720
  declare const StableswapParamsSchema: _lucid_evolution_lucid.TObject<{
@@ -4723,4 +4742,4 @@ declare function mkAuthTokenPolicy(ac: AssetClass, tn: string): MintingPolicy;
4723
4742
 
4724
4743
  declare const alwaysFailValidator: SpendingValidator;
4725
4744
 
4726
- 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 OrderProcessConfig, 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 StableswapInfo, type StableswapOrderDatum, StableswapOrderDatumSchema, type StableswapOrderInfo, type StableswapOrderRedeemer, type StableswapOutputDatum, type StableswapParamsSP, type StableswapPoolContent, StakeCredential, StakeCredentialSchema, type StakingManager, type StakingManagerOutput, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingPositionOutput, type StakingRedeemer, type StartTime, type StateSnapshot, type SumSnapshot, type SystemParams, type TokenNameSP, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type UpgradePaths, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, adjustCdp, adjustPriceToDecimals, adjustRob, adjustStakingPosition, alwaysFailValidator, annulRequest, approximateLeverageRedemptions, attachOracle, balance, batchCollectInterest, batchProcessStableswapOrders, bigintMax, bigintMin, buildRedemptionsTx, burnCdp, calculateAccruedInterest, calculateAdaReward, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculatePurchaseAmtWhenRobBuyOrder, calculatePurchaseAmtWhenRobSellOrder, calculateSpendAmtWhenRobBuyOrder, calculateSpendAmtWhenRobSellOrder, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castOneShotParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectPriceFeedIds, collectorFeeTx, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, defaultOrderProcessingConfig, depositCdp, deriveAuthToken, derivePythPrice, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findAdminInterestCollectors, findAllInterestCollectors, findAllTreasuryUtxos, findAllTreasuryUtxosWithNonAdaAsset, findCollateralAsset, findE2s2sSnapshots, findIAsset, findRandomCdpCreator, findRandomNonAdminInterestCollector, findRandomTreasuryUtxo, findRandomTreasuryUtxoWithAsset, findRandomTreasuryUtxoWithOnlyAda, findRelevantE2s2sIdxs, findStabilityPool, findStabilityPoolAccount, 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, pickValidSatisfiableOrders, processSpRequest, psmOrderType, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, rewardsPerAsset, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, 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, summariseOrder, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
4745
+ 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 PSMProcessingConfig, type ParsedOutput, type PollDatum, type PollManagerContent, PollManagerParams, type PollManagerParamsSP, type PollManagerRedeemer, type PollShardContent, PollShardParams, type PollShardParamsSP, type PollShardRedeemer, type PollStatus, type PriceOracleDatum, type PriceOracleParam, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PriceUpdate, type ProcessRequestAccountContent, type ProposalContent, ProposalContentSchema, type ProposeAssetContent, type ProposeStableswapPoolContent, type ProtocolParams, ProtocolParamsSchema, type PubKeyHash, type PythConfig, type PythConfiguration, type PythFeedConfig, type PythFeedParams, type PythFeedParamsSP, type PythFeedRedeemer, type PythMessageParts, type PythOracleParam, type PythPriceConfigurationSP, type PythStateDatum, type PythUpdatesRedeemer, type Rational, RationalSchema, type RedeemCdpWithdrawalRedeemer, type RobDatum, type RobOrderType, type RobOutput, type RobParams, type RobParamsSP, RobParamsSchema, type RobRedeemer, SOLANA_FORMAT_MAGIC, type SPInteger, SPIntegerSchema, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, type SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, type StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, type StabilityPoolRedeemer, StabilityPoolRedeemerSchema, type StableswapInfo, type StableswapOrderDatum, StableswapOrderDatumSchema, type StableswapOrderInfo, type StableswapOrderRedeemer, type StableswapOutputDatum, type StableswapParamsSP, type StableswapPoolContent, StakeCredential, StakeCredentialSchema, type StakingManager, type StakingManagerOutput, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingPositionOutput, type StakingRedeemer, type StartTime, type StateSnapshot, type SumSnapshot, type SystemParams, type TokenNameSP, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type UpgradePaths, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, adjustCdp, adjustPriceToDecimals, adjustRob, adjustStakingPosition, alwaysFailValidator, annulRequest, approximateLeverageRedemptions, attachOracle, balance, batchCollectInterest, batchProcessStableswapOrders, bigintMax, bigintMin, buildRedemptionsTx, burnCdp, calculateAccruedInterest, calculateAdaReward, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculatePurchaseAmtWhenRobBuyOrder, calculatePurchaseAmtWhenRobSellOrder, calculateSpendAmtWhenRobBuyOrder, calculateSpendAmtWhenRobSellOrder, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castOneShotParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectPriceFeedIds, collectorFeeTx, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, derivePythPrice, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateMinOrderOutputLovelaces, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findAdminInterestCollectors, findAllInterestCollectors, findAllTreasuryUtxos, findAllTreasuryUtxosWithNonAdaAsset, findCollateralAsset, findE2s2sSnapshots, findIAsset, findRandomCdpCreator, findRandomNonAdminInterestCollector, findRandomTreasuryUtxo, findRandomTreasuryUtxoWithAsset, findRandomTreasuryUtxoWithOnlyAda, findRelevantE2s2sIdxs, findStabilityPool, findStabilityPoolAccount, 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, pickValidSatisfiableOrders, processSpRequest, psmOrderType, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, rewardsPerAsset, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, 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, summariseOrder, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
package/dist/index.d.ts CHANGED
@@ -4639,17 +4639,22 @@ declare function parseStableswapOrderRedeemer(redeemerCborHex: string): option.O
4639
4639
  declare function parseStableswapOrderRedeemerOrThrow(redeemerCborHex: string): StableswapOrderRedeemer;
4640
4640
 
4641
4641
  declare const BASE_MAX_EXECUTION_FEE = 1620000n;
4642
- type OrderProcessConfig = {
4642
+ type PSMProcessingConfig = {
4643
4643
  /**
4644
- * Whether to ignore that an order has max execution fee set lower
4645
- * than the threshold (i.e. the processor might be paying the remaining cardano tx fee).
4644
+ * Whether to enforce that an order has max execution fee satisfying
4645
+ * min threshold (i.e. the processor might be paying the remaining cardano tx fee).
4646
4646
  *
4647
- * The default should be `false`. In case, owner wants to process
4648
- * such order himself, he can ignore the constraint.
4647
+ * In case, owner wants to process such order himself, he can ignore the constraint.
4648
+ * @default true
4649
4649
  */
4650
- ignoreMaxExecutionFeeConstraint: boolean;
4650
+ enforceMaxExecutionFeeConstraint?: boolean;
4651
+ /**
4652
+ * Whether to enforce the minimum lovelace constraint. If not enforced,
4653
+ * the processor might need to pay the min lovelace for the order output.
4654
+ * @default true
4655
+ */
4656
+ enforceMinLovelaceConstraint?: boolean;
4651
4657
  };
4652
- declare const defaultOrderProcessingConfig: OrderProcessConfig;
4653
4658
  declare function createDestinationDatum(datum: Data$1.Data | null, outRef: OutRef): string;
4654
4659
  type StableswapInfo = {
4655
4660
  suppliedIasset: bigint;
@@ -4664,6 +4669,15 @@ type StableswapOrderInfo = {
4664
4669
  orderType: 'MINTING' | 'REDEEMING';
4665
4670
  swapInfo: StableswapInfo;
4666
4671
  };
4672
+ /**
4673
+ * This is an approximation of the amount of lovelace that will be needed to pay for the output.
4674
+ */
4675
+ declare function estimateMinOrderOutputLovelaces(lucid: LucidEvolution, orderDatum: StableswapOrderDatum,
4676
+ /**
4677
+ * Including execution fee as well.
4678
+ */
4679
+ orderAssets: Assets): bigint;
4680
+ type OrderTypeError = 'VALUE_ERROR';
4667
4681
  /**
4668
4682
  * Determine the PSM order type.
4669
4683
  */
@@ -4675,27 +4689,32 @@ declare function psmOrderType(order: ParsedOutput<StableswapOrderDatum>, sysPara
4675
4689
  suppliedIassets: bigint;
4676
4690
  } | {
4677
4691
  type: 'ERROR';
4692
+ errorTag: OrderTypeError;
4678
4693
  reason: string;
4679
4694
  };
4695
+ type SummaryError = OrderTypeError | 'ASSET_MISMATCH' | 'EXECUTION_FEE' | 'MAX_FEE' | 'INSUFFICIENT_LOVELACES';
4680
4696
  type SummaryResult = {
4681
4697
  _tag: 'SUCCESS';
4682
4698
  result: StableswapOrderInfo;
4683
4699
  } | {
4684
4700
  _tag: 'ERROR';
4685
- reason: string;
4701
+ errorTag: SummaryError;
4702
+ description: string;
4686
4703
  };
4687
4704
  /**
4688
- * Summarise the order in detail
4705
+ * Summarise the order. Validate all the necessary constraints
4706
+ * for this order to be processed.
4689
4707
  */
4690
- declare function summariseOrder(order: ParsedOutput<StableswapOrderDatum>, psmPool: ParsedOutput<StableswapPoolContent>, sysParams: SystemParams, orderProcessingConfig: OrderProcessConfig): SummaryResult;
4708
+ declare function summariseOrder(lucid: LucidEvolution, order: ParsedOutput<StableswapOrderDatum>, psmPool: ParsedOutput<StableswapPoolContent>, sysParams: SystemParams, psmProcessingConfig?: PSMProcessingConfig): SummaryResult;
4691
4709
  /**
4692
- * Pick only orders that are valid and can be processed based on available liquidity.
4710
+ * Pick only orders that are valid, belong to the PSM pool,
4711
+ * and can be processed based on available liquidity.
4693
4712
  */
4694
- declare function pickValidSatisfiableOrders(orders: ParsedOutput<StableswapOrderDatum>[], pool: ParsedOutput<StableswapPoolContent>, sysParams: SystemParams, orderProcessingConfig: OrderProcessConfig): ParsedOutput<StableswapOrderDatum>[];
4713
+ declare function pickValidSatisfiableOrders(lucid: LucidEvolution, orders: ParsedOutput<StableswapOrderDatum>[], pool: ParsedOutput<StableswapPoolContent>, sysParams: SystemParams, psmProcessingConfig?: PSMProcessingConfig): ParsedOutput<StableswapOrderDatum>[];
4695
4714
 
4696
4715
  declare function createStableswapOrder(iasset: string, collateralAsset: AssetClass, amount: bigint, minting: boolean, poolDatum: StableswapPoolContent, params: SystemParams, lucid: LucidEvolution, destinationAddress?: Address, destinationInlineDatum?: Core.Data.Data, maxExecutionFee?: bigint, additionalLovelaces?: bigint, maxFeeRatio?: Rational): Promise<TxBuilder>;
4697
4716
  declare function cancelStableswapOrder(stableswapOrderOref: OutRef, sysParams: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
4698
- declare function batchProcessStableswapOrders(stableswapOrderOrefs: OutRef[], stableswapPoolOref: OutRef, treasuryOref: OutRef, sysParams: SystemParams, lucid: LucidEvolution, orderProcessingConfig?: OrderProcessConfig): Promise<TxBuilder>;
4717
+ declare function batchProcessStableswapOrders(stableswapOrderOrefs: OutRef[], stableswapPoolOref: OutRef, treasuryOref: OutRef, sysParams: SystemParams, lucid: LucidEvolution, psmProcessingConfig?: PSMProcessingConfig): Promise<TxBuilder>;
4699
4718
  declare function updateStableswapPoolFees(stableswapPoolOutRef: OutRef, stableswapFeeOutRef: OutRef, newMintingFeeRatio: Rational | null, newRedemptionFeeRatio: Rational | null, sysParams: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
4700
4719
 
4701
4720
  declare const StableswapParamsSchema: _lucid_evolution_lucid.TObject<{
@@ -4723,4 +4742,4 @@ declare function mkAuthTokenPolicy(ac: AssetClass, tn: string): MintingPolicy;
4723
4742
 
4724
4743
  declare const alwaysFailValidator: SpendingValidator;
4725
4744
 
4726
- 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 OrderProcessConfig, 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 StableswapInfo, type StableswapOrderDatum, StableswapOrderDatumSchema, type StableswapOrderInfo, type StableswapOrderRedeemer, type StableswapOutputDatum, type StableswapParamsSP, type StableswapPoolContent, StakeCredential, StakeCredentialSchema, type StakingManager, type StakingManagerOutput, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingPositionOutput, type StakingRedeemer, type StartTime, type StateSnapshot, type SumSnapshot, type SystemParams, type TokenNameSP, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type UpgradePaths, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, adjustCdp, adjustPriceToDecimals, adjustRob, adjustStakingPosition, alwaysFailValidator, annulRequest, approximateLeverageRedemptions, attachOracle, balance, batchCollectInterest, batchProcessStableswapOrders, bigintMax, bigintMin, buildRedemptionsTx, burnCdp, calculateAccruedInterest, calculateAdaReward, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculatePurchaseAmtWhenRobBuyOrder, calculatePurchaseAmtWhenRobSellOrder, calculateSpendAmtWhenRobBuyOrder, calculateSpendAmtWhenRobSellOrder, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castOneShotParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectPriceFeedIds, collectorFeeTx, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, defaultOrderProcessingConfig, depositCdp, deriveAuthToken, derivePythPrice, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findAdminInterestCollectors, findAllInterestCollectors, findAllTreasuryUtxos, findAllTreasuryUtxosWithNonAdaAsset, findCollateralAsset, findE2s2sSnapshots, findIAsset, findRandomCdpCreator, findRandomNonAdminInterestCollector, findRandomTreasuryUtxo, findRandomTreasuryUtxoWithAsset, findRandomTreasuryUtxoWithOnlyAda, findRelevantE2s2sIdxs, findStabilityPool, findStabilityPoolAccount, 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, pickValidSatisfiableOrders, processSpRequest, psmOrderType, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, rewardsPerAsset, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, 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, summariseOrder, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
4745
+ 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 PSMProcessingConfig, type ParsedOutput, type PollDatum, type PollManagerContent, PollManagerParams, type PollManagerParamsSP, type PollManagerRedeemer, type PollShardContent, PollShardParams, type PollShardParamsSP, type PollShardRedeemer, type PollStatus, type PriceOracleDatum, type PriceOracleParam, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PriceUpdate, type ProcessRequestAccountContent, type ProposalContent, ProposalContentSchema, type ProposeAssetContent, type ProposeStableswapPoolContent, type ProtocolParams, ProtocolParamsSchema, type PubKeyHash, type PythConfig, type PythConfiguration, type PythFeedConfig, type PythFeedParams, type PythFeedParamsSP, type PythFeedRedeemer, type PythMessageParts, type PythOracleParam, type PythPriceConfigurationSP, type PythStateDatum, type PythUpdatesRedeemer, type Rational, RationalSchema, type RedeemCdpWithdrawalRedeemer, type RobDatum, type RobOrderType, type RobOutput, type RobParams, type RobParamsSP, RobParamsSchema, type RobRedeemer, SOLANA_FORMAT_MAGIC, type SPInteger, SPIntegerSchema, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, type SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, type StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, type StabilityPoolRedeemer, StabilityPoolRedeemerSchema, type StableswapInfo, type StableswapOrderDatum, StableswapOrderDatumSchema, type StableswapOrderInfo, type StableswapOrderRedeemer, type StableswapOutputDatum, type StableswapParamsSP, type StableswapPoolContent, StakeCredential, StakeCredentialSchema, type StakingManager, type StakingManagerOutput, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingPositionOutput, type StakingRedeemer, type StartTime, type StateSnapshot, type SumSnapshot, type SystemParams, type TokenNameSP, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type UpgradePaths, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, adjustCdp, adjustPriceToDecimals, adjustRob, adjustStakingPosition, alwaysFailValidator, annulRequest, approximateLeverageRedemptions, attachOracle, balance, batchCollectInterest, batchProcessStableswapOrders, bigintMax, bigintMin, buildRedemptionsTx, burnCdp, calculateAccruedInterest, calculateAdaReward, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculatePurchaseAmtWhenRobBuyOrder, calculatePurchaseAmtWhenRobSellOrder, calculateSpendAmtWhenRobBuyOrder, calculateSpendAmtWhenRobSellOrder, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castOneShotParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectPriceFeedIds, collectorFeeTx, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, derivePythPrice, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateMinOrderOutputLovelaces, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findAdminInterestCollectors, findAllInterestCollectors, findAllTreasuryUtxos, findAllTreasuryUtxosWithNonAdaAsset, findCollateralAsset, findE2s2sSnapshots, findIAsset, findRandomCdpCreator, findRandomNonAdminInterestCollector, findRandomTreasuryUtxo, findRandomTreasuryUtxoWithAsset, findRandomTreasuryUtxoWithOnlyAda, findRelevantE2s2sIdxs, findStabilityPool, findStabilityPoolAccount, 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, pickValidSatisfiableOrders, processSpRequest, psmOrderType, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, rewardsPerAsset, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, 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, summariseOrder, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
package/dist/index.js CHANGED
@@ -147,7 +147,6 @@ __export(index_exports, {
147
147
  createStableswapOrder: () => createStableswapOrder,
148
148
  decodePriceUpdate: () => decodePriceUpdate,
149
149
  decodePythMessage: () => decodePythMessage,
150
- defaultOrderProcessingConfig: () => defaultOrderProcessingConfig,
151
150
  depositCdp: () => depositCdp,
152
151
  deriveAuthToken: () => deriveAuthToken,
153
152
  derivePythPrice: () => derivePythPrice,
@@ -159,6 +158,7 @@ __export(index_exports, {
159
158
  encodePythMessage: () => encodePythMessage,
160
159
  encodeSignedPythMessage: () => encodeSignedPythMessage,
161
160
  endProposal: () => endProposal,
161
+ estimateMinOrderOutputLovelaces: () => estimateMinOrderOutputLovelaces,
162
162
  estimateUtxoMinLovelace: () => estimateUtxoMinLovelace,
163
163
  executeProposal: () => executeProposal,
164
164
  feedInterestOracle: () => feedInterestOracle,
@@ -11469,8 +11469,9 @@ function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
11469
11469
  var import_evolution21 = require("@evolution-sdk/evolution");
11470
11470
  var import_cardano_offchain_common35 = require("@3rd-eye-labs/cardano-offchain-common");
11471
11471
  var BASE_MAX_EXECUTION_FEE = 1620000n;
11472
- var defaultOrderProcessingConfig = {
11473
- ignoreMaxExecutionFeeConstraint: false
11472
+ var defaultPSMProcessingConfig = {
11473
+ enforceMaxExecutionFeeConstraint: true,
11474
+ enforceMinLovelaceConstraint: true
11474
11475
  };
11475
11476
  function createDestinationDatum(datum, outRef) {
11476
11477
  if (!datum) {
@@ -11484,6 +11485,22 @@ function createDestinationDatum(datum, outRef) {
11484
11485
  }
11485
11486
  return import_evolution21.Data.toCBORHex(datum);
11486
11487
  }
11488
+ function estimateMinOrderOutputLovelaces(lucid, orderDatum, orderAssets) {
11489
+ const expectedOutputLovelaces = estimateUtxoMinLovelace(
11490
+ lucid.config().protocolParameters,
11491
+ (0, import_cardano_offchain_common35.addressToBech32)(orderDatum.destination, lucid.config().network),
11492
+ orderAssets,
11493
+ {
11494
+ kind: "inline",
11495
+ value: createDestinationDatum(orderDatum.destinationInlineDatum ?? null, {
11496
+ txHash: "0000000000000000000000000000000000000000000000000000000000000000",
11497
+ outputIndex: 0
11498
+ })
11499
+ }
11500
+ );
11501
+ const roundedExpectedOutputLovelaces = (expectedOutputLovelaces / 1000000n + 1n) * 1000000n;
11502
+ return roundedExpectedOutputLovelaces;
11503
+ }
11487
11504
  function psmOrderType(order, sysParams) {
11488
11505
  const iassetAc = {
11489
11506
  currencySymbol: (0, import_lucid66.fromHex)(
@@ -11499,28 +11516,56 @@ function psmOrderType(order, sysParams) {
11499
11516
  if (suppliedIasset != 0n && suppliedCollateralAsset != 0n || suppliedIasset == 0n && suppliedCollateralAsset == 0n) {
11500
11517
  return {
11501
11518
  type: "ERROR",
11519
+ errorTag: "VALUE_ERROR",
11502
11520
  reason: "An order must supply either iAsset or collateral asset"
11503
11521
  };
11504
11522
  }
11505
11523
  const isMinting = suppliedCollateralAsset > 0n;
11506
11524
  return isMinting ? { type: "MINTING", suppliedCollateral: suppliedCollateralAsset } : { type: "REDEEMING", suppliedIassets: suppliedIasset };
11507
11525
  }
11508
- function summariseOrder(order, psmPool, sysParams, orderProcessingConfig) {
11526
+ function summariseOrder(lucid, order, psmPool, sysParams, psmProcessingConfig) {
11527
+ const config = {
11528
+ ...defaultPSMProcessingConfig,
11529
+ ...psmProcessingConfig
11530
+ };
11509
11531
  const orderType = psmOrderType(order, sysParams);
11510
11532
  if (orderType.type === "ERROR") {
11511
- return { _tag: "ERROR", reason: orderType.reason };
11533
+ return {
11534
+ _tag: "ERROR",
11535
+ errorTag: orderType.errorTag,
11536
+ description: orderType.reason
11537
+ };
11538
+ }
11539
+ if ((0, import_lucid66.toHex)(order.datum.iasset) !== (0, import_lucid66.toHex)(psmPool.datum.iasset) || (0, import_lucid66.toHex)(order.datum.collateralAsset.currencySymbol) !== (0, import_lucid66.toHex)(psmPool.datum.collateralAsset.currencySymbol) || (0, import_lucid66.toHex)(order.datum.collateralAsset.tokenName) !== (0, import_lucid66.toHex)(psmPool.datum.collateralAsset.tokenName)) {
11540
+ return {
11541
+ _tag: "ERROR",
11542
+ errorTag: "ASSET_MISMATCH",
11543
+ description: "Order - PSM assets mismatch"
11544
+ };
11512
11545
  }
11513
11546
  const isOneToOne = psmPool.datum.collateralToIassetRatio.numerator === psmPool.datum.collateralToIassetRatio.denominator;
11514
- if (!orderProcessingConfig.ignoreMaxExecutionFeeConstraint && order.datum.maxExecutionFee < BASE_MAX_EXECUTION_FEE) {
11547
+ if (config.enforceMaxExecutionFeeConstraint && order.datum.maxExecutionFee < BASE_MAX_EXECUTION_FEE) {
11548
+ return {
11549
+ _tag: "ERROR",
11550
+ errorTag: "EXECUTION_FEE",
11551
+ description: `Max execution fee is too low. Minimum: ${BASE_MAX_EXECUTION_FEE}`
11552
+ };
11553
+ }
11554
+ if (config.enforceMinLovelaceConstraint && (0, import_cardano_offchain_common35.lovelacesAmt)(order.utxo.assets) < estimateMinOrderOutputLovelaces(lucid, order.datum, order.utxo.assets) + order.datum.maxExecutionFee) {
11515
11555
  return {
11516
11556
  _tag: "ERROR",
11517
- reason: `Max execution fee is too low. Minimum: ${BASE_MAX_EXECUTION_FEE}`
11557
+ errorTag: "INSUFFICIENT_LOVELACES",
11558
+ description: "Order has insufficient lovelaces to cover execution fee and order output."
11518
11559
  };
11519
11560
  }
11520
11561
  if (orderType.type === "MINTING") {
11521
11562
  const suppliedCollateralAsset = orderType.suppliedCollateral;
11522
11563
  if (rationalToFloat(order.datum.maxFeeRatio) < rationalToFloat(psmPool.datum.mintingFeeRatio)) {
11523
- return { _tag: "ERROR", reason: "Max fee ratio not satisfied" };
11564
+ return {
11565
+ _tag: "ERROR",
11566
+ errorTag: "MAX_FEE",
11567
+ description: "Max fee ratio not satisfied"
11568
+ };
11524
11569
  }
11525
11570
  if (isOneToOne) {
11526
11571
  const fee = calculateFeeFromRatio(
@@ -11584,7 +11629,11 @@ function summariseOrder(order, psmPool, sysParams, orderProcessingConfig) {
11584
11629
  } else {
11585
11630
  const suppliedIasset = orderType.suppliedIassets;
11586
11631
  if (rationalToFloat(order.datum.maxFeeRatio) < rationalToFloat(psmPool.datum.redemptionFeeRatio)) {
11587
- return { _tag: "ERROR", reason: "Max fee ratio not satisfied" };
11632
+ return {
11633
+ _tag: "ERROR",
11634
+ errorTag: "MAX_FEE",
11635
+ description: "Max fee ratio not satisfied"
11636
+ };
11588
11637
  }
11589
11638
  const fee = calculateFeeFromRatio(
11590
11639
  psmPool.datum.redemptionFeeRatio,
@@ -11649,14 +11698,20 @@ function summariseOrder(order, psmPool, sysParams, orderProcessingConfig) {
11649
11698
  }
11650
11699
  }
11651
11700
  }
11652
- function pickValidSatisfiableOrders(orders, pool, sysParams, orderProcessingConfig) {
11701
+ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessingConfig) {
11653
11702
  const psmAvailableLiq = (0, import_cardano_offchain_common35.assetClassValueOf)(
11654
11703
  pool.utxo.assets,
11655
11704
  pool.datum.collateralAsset
11656
11705
  );
11657
11706
  const validOrders = orders.flatMap((order) => {
11658
11707
  try {
11659
- const res = summariseOrder(order, pool, sysParams, orderProcessingConfig);
11708
+ const res = summariseOrder(
11709
+ lucid,
11710
+ order,
11711
+ pool,
11712
+ sysParams,
11713
+ psmProcessingConfig
11714
+ );
11660
11715
  return res._tag === "SUCCESS" ? [res.result] : [];
11661
11716
  } catch (_) {
11662
11717
  return [];
@@ -11734,19 +11789,16 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
11734
11789
  },
11735
11790
  amount
11736
11791
  );
11737
- const expectedOutputLovelaces = estimateUtxoMinLovelace(
11738
- lucid.config().protocolParameters,
11739
- myAddress,
11792
+ const orderAssetsPlusFees = (0, import_lucid67.addAssets)(
11740
11793
  assetsToSwap,
11741
- {
11742
- kind: "inline",
11743
- value: createDestinationDatum(destinationInlineDatum ?? null, {
11744
- txHash: "0000000000000000000000000000000000000000000000000000000000000000",
11745
- outputIndex: 0
11746
- })
11747
- }
11794
+ (0, import_cardano_offchain_common36.mkLovelacesOf)(maxExecutionFee),
11795
+ (0, import_cardano_offchain_common36.mkLovelacesOf)(additionalLovelaces)
11796
+ );
11797
+ const expectedMinOutputLovelaces = estimateMinOrderOutputLovelaces(
11798
+ lucid,
11799
+ datum,
11800
+ orderAssetsPlusFees
11748
11801
  );
11749
- const roundedExpectedOutputLovelaces = (expectedOutputLovelaces / 1000000n + 1n) * 1000000n;
11750
11802
  return lucid.newTx().pay.ToContract(
11751
11803
  (0, import_lucid67.credentialToAddress)(lucid.config().network, {
11752
11804
  hash: params.validatorHashes.stableswapHash,
@@ -11756,12 +11808,7 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
11756
11808
  kind: "inline",
11757
11809
  value: serialiseStableswapOrderDatum(datum)
11758
11810
  },
11759
- (0, import_lucid67.addAssets)(
11760
- assetsToSwap,
11761
- (0, import_cardano_offchain_common36.mkLovelacesOf)(
11762
- roundedExpectedOutputLovelaces + maxExecutionFee + additionalLovelaces
11763
- )
11764
- )
11811
+ (0, import_lucid67.addAssets)(orderAssetsPlusFees, (0, import_cardano_offchain_common36.mkLovelacesOf)(expectedMinOutputLovelaces))
11765
11812
  );
11766
11813
  }
11767
11814
  async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
@@ -11785,7 +11832,7 @@ async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
11785
11832
  serialiseStableswapOrderRedeemer("CancelStableswapOrder")
11786
11833
  ).addSignerKey((0, import_lucid67.toHex)(stableswapOrderDatum.owner));
11787
11834
  }
11788
- async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPoolOref, treasuryOref, sysParams, lucid, orderProcessingConfig = defaultOrderProcessingConfig) {
11835
+ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPoolOref, treasuryOref, sysParams, lucid, psmProcessingConfig) {
11789
11836
  const stableswapScriptRefUtxo = (0, import_cardano_offchain_common36.matchSingle)(
11790
11837
  await lucid.utxosByOutRef([
11791
11838
  fromSystemParamsScriptRef(
@@ -11842,17 +11889,15 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11842
11889
  const orderDatum = parseStableswapOrderDatumOrThrow(
11843
11890
  (0, import_cardano_offchain_common36.getInlineDatumOrThrow)(orderUtxo)
11844
11891
  );
11845
- if ((0, import_lucid67.toHex)(orderDatum.iasset) != (0, import_lucid67.toHex)(mainOrderDatum.iasset) || (0, import_lucid67.toHex)(orderDatum.collateralAsset.currencySymbol) != (0, import_lucid67.toHex)(mainOrderDatum.collateralAsset.currencySymbol) || (0, import_lucid67.toHex)(orderDatum.collateralAsset.tokenName) != (0, import_lucid67.toHex)(mainOrderDatum.collateralAsset.tokenName)) {
11846
- throw new Error("Wrong batch of orders");
11847
- }
11848
11892
  const res = summariseOrder(
11893
+ lucid,
11849
11894
  { utxo: orderUtxo, datum: orderDatum },
11850
11895
  { utxo: stableswapPoolUtxo, datum: stableswapPoolDatum },
11851
11896
  sysParams,
11852
- orderProcessingConfig
11897
+ psmProcessingConfig
11853
11898
  );
11854
11899
  if (res._tag === "ERROR") {
11855
- throw new Error(res.reason);
11900
+ throw new Error(res.description);
11856
11901
  }
11857
11902
  return res.result;
11858
11903
  }
@@ -12143,7 +12188,6 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
12143
12188
  createStableswapOrder,
12144
12189
  decodePriceUpdate,
12145
12190
  decodePythMessage,
12146
- defaultOrderProcessingConfig,
12147
12191
  depositCdp,
12148
12192
  deriveAuthToken,
12149
12193
  derivePythPrice,
@@ -12155,6 +12199,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
12155
12199
  encodePythMessage,
12156
12200
  encodeSignedPythMessage,
12157
12201
  endProposal,
12202
+ estimateMinOrderOutputLovelaces,
12158
12203
  estimateUtxoMinLovelace,
12159
12204
  executeProposal,
12160
12205
  feedInterestOracle,