@indigo-labs/indigo-sdk 0.5.14 → 0.5.16

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
@@ -831,6 +831,14 @@ declare function numberToRational(num: number, precision?: number): Rational;
831
831
  * Amount of iasset equal in value to the given number of collateral amount.
832
832
  */
833
833
  declare function iassetValueOfCollateral(collateralAmt: bigint, oraclePrice: Rational): bigint;
834
+ /**
835
+ * Resolves the effective debt and collateral of a CDP
836
+ * after applying all accrued interest and fees.
837
+ */
838
+ declare function computeEffectiveCdpState(now: bigint, cdpUtxoAssets: Assets, cdpContent: CDPContent, interestOracleDatum: InterestOracleDatum): {
839
+ mintedAmt: bigint;
840
+ collateralAmt: bigint;
841
+ };
834
842
  declare function cdpCollateralRatioPercentage(
835
843
  /**
836
844
  * Should be ideally the result of the following: lucid.slotToUnixTime(lucid.currentSlot()).
@@ -4723,6 +4731,16 @@ declare function summariseOrder(lucid: LucidEvolution, order: ParsedOutput<Stabl
4723
4731
  */
4724
4732
  declare function pickValidSatisfiableOrders(lucid: LucidEvolution, orders: ParsedOutput<StableswapOrderDatum>[], pool: ParsedOutput<StableswapPoolContent>, sysParams: SystemParams, psmProcessingConfig?: PSMProcessingConfig): ParsedOutput<StableswapOrderDatum>[];
4725
4733
 
4734
+ declare function findAllStableswapPools(lucid: LucidEvolution, sysParams: SystemParams): Promise<ParsedOutput<StableswapPoolContent>[]>;
4735
+ declare function findStableswapPool(lucid: LucidEvolution, sysParams: SystemParams, iassetName: string,
4736
+ /**
4737
+ * PSM pool's collateral
4738
+ */
4739
+ collateralAsset: AssetClass): Promise<{
4740
+ utxo: UTxO;
4741
+ datum: StableswapPoolContent;
4742
+ }>;
4743
+
4726
4744
  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>;
4727
4745
  declare function cancelStableswapOrder(stableswapOrderOref: OutRef, sysParams: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
4728
4746
  declare function batchProcessStableswapOrders(stableswapOrderOrefs: OutRef[], stableswapPoolOref: OutRef, treasuryOref: OutRef | undefined, sysParams: SystemParams, lucid: LucidEvolution, psmProcessingConfig?: PSMProcessingConfig): Promise<TxBuilder>;
@@ -4753,4 +4771,4 @@ declare function mkAuthTokenPolicy(ac: AssetClass, tn: string): MintingPolicy;
4753
4771
 
4754
4772
  declare const alwaysFailValidator: SpendingValidator;
4755
4773
 
4756
- 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, findInterestOracle, 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, numberToRational, oneShotMintTx, openCdp, openRob, openStakingPosition, parseAccountDatum, parseAccountDatumOrThrow, parseCdpDatum, parseCdpDatumOrThrow, parseCdpRedeemer, parseCdpRedeemerOrThrow, parseCollateralAssetDatum, parseCollateralAssetDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestCollectionDatum, parseInterestOracleDatum, parsePollManager, parsePollManagerOrThrow, parsePollShard, parsePollShardOrThrow, parsePollShardRedeemer, parsePollShardRedeemerOrThrow, parsePriceOracleDatum, parsePythStateDatum, parseRobDatum, parseRobDatumOrThrow, parseRobRedeemer, parseRobRedeemerOrThrow, parseSnapshotEpochToScaleToSumDatum, parseSnapshotEpochToScaleToSumDatumOrThrow, parseStabilityPoolDatum, parseStabilityPoolDatumOrThrow, parseStabilityPoolRedeemer, parseStabilityPoolRedeemerOrThrow, parseStableswapOrderDatum, parseStableswapOrderDatumOrThrow, parseStableswapOrderRedeemer, parseStableswapOrderRedeemerOrThrow, parseStableswapPoolDatum, parseStableswapPoolDatumOrThrow, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, parseStakingRedeemer, parseStakingRedeemerOrThrow, partitionEpochToScaleToSums, pickValidSatisfiableOrders, processSpRequest, psmOrderType, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, rewardsPerAsset, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, 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 };
4774
+ 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, computeEffectiveCdpState, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, derivePythPrice, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateMinOrderOutputLovelaces, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findAdminInterestCollectors, findAllInterestCollectors, findAllStableswapPools, findAllTreasuryUtxos, findAllTreasuryUtxosWithNonAdaAsset, findCollateralAsset, findE2s2sSnapshots, findIAsset, findInterestOracle, findRandomCdpCreator, findRandomNonAdminInterestCollector, findRandomTreasuryUtxo, findRandomTreasuryUtxoWithAsset, findRandomTreasuryUtxoWithOnlyAda, findRelevantE2s2sIdxs, findStabilityPool, findStabilityPoolAccount, findStableswapPool, findStakingManager, findStakingManagerByOutRef, findStakingPositionByOutRef, freezeCdp, fromDataDerivedPythPrice, fromDecimal, fromSPInteger, fromSysParamsCredential, fromSysParamsDerivedPythPrice, fromSysParamsPythFeedParams, fromSysParamsStakeCredential, fromSystemParamsAsset, fromSystemParamsAssetLucid, fromSystemParamsScriptRef, getAssetClassComparisonStr, getInlineDatumOrThrow, getPythFeedConfig, getUpdatedAccountDeposit, handleOracleForCollateralAsset, iassetValueOfCollateral, init, initCDPCreator, initCollector, initGovernance, initInterestCollector, initPythConfig, 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, numberToRational, oneShotMintTx, openCdp, openRob, openStakingPosition, parseAccountDatum, parseAccountDatumOrThrow, parseCdpDatum, parseCdpDatumOrThrow, parseCdpRedeemer, parseCdpRedeemerOrThrow, parseCollateralAssetDatum, parseCollateralAssetDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestCollectionDatum, parseInterestOracleDatum, parsePollManager, parsePollManagerOrThrow, parsePollShard, parsePollShardOrThrow, parsePollShardRedeemer, parsePollShardRedeemerOrThrow, parsePriceOracleDatum, parsePythStateDatum, parseRobDatum, parseRobDatumOrThrow, parseRobRedeemer, parseRobRedeemerOrThrow, parseSnapshotEpochToScaleToSumDatum, parseSnapshotEpochToScaleToSumDatumOrThrow, parseStabilityPoolDatum, parseStabilityPoolDatumOrThrow, parseStabilityPoolRedeemer, parseStabilityPoolRedeemerOrThrow, parseStableswapOrderDatum, parseStableswapOrderDatumOrThrow, parseStableswapOrderRedeemer, parseStableswapOrderRedeemerOrThrow, parseStableswapPoolDatum, parseStableswapPoolDatumOrThrow, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, parseStakingRedeemer, parseStakingRedeemerOrThrow, partitionEpochToScaleToSums, pickValidSatisfiableOrders, processSpRequest, psmOrderType, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, rewardsPerAsset, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, 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
@@ -831,6 +831,14 @@ declare function numberToRational(num: number, precision?: number): Rational;
831
831
  * Amount of iasset equal in value to the given number of collateral amount.
832
832
  */
833
833
  declare function iassetValueOfCollateral(collateralAmt: bigint, oraclePrice: Rational): bigint;
834
+ /**
835
+ * Resolves the effective debt and collateral of a CDP
836
+ * after applying all accrued interest and fees.
837
+ */
838
+ declare function computeEffectiveCdpState(now: bigint, cdpUtxoAssets: Assets, cdpContent: CDPContent, interestOracleDatum: InterestOracleDatum): {
839
+ mintedAmt: bigint;
840
+ collateralAmt: bigint;
841
+ };
834
842
  declare function cdpCollateralRatioPercentage(
835
843
  /**
836
844
  * Should be ideally the result of the following: lucid.slotToUnixTime(lucid.currentSlot()).
@@ -4723,6 +4731,16 @@ declare function summariseOrder(lucid: LucidEvolution, order: ParsedOutput<Stabl
4723
4731
  */
4724
4732
  declare function pickValidSatisfiableOrders(lucid: LucidEvolution, orders: ParsedOutput<StableswapOrderDatum>[], pool: ParsedOutput<StableswapPoolContent>, sysParams: SystemParams, psmProcessingConfig?: PSMProcessingConfig): ParsedOutput<StableswapOrderDatum>[];
4725
4733
 
4734
+ declare function findAllStableswapPools(lucid: LucidEvolution, sysParams: SystemParams): Promise<ParsedOutput<StableswapPoolContent>[]>;
4735
+ declare function findStableswapPool(lucid: LucidEvolution, sysParams: SystemParams, iassetName: string,
4736
+ /**
4737
+ * PSM pool's collateral
4738
+ */
4739
+ collateralAsset: AssetClass): Promise<{
4740
+ utxo: UTxO;
4741
+ datum: StableswapPoolContent;
4742
+ }>;
4743
+
4726
4744
  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>;
4727
4745
  declare function cancelStableswapOrder(stableswapOrderOref: OutRef, sysParams: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
4728
4746
  declare function batchProcessStableswapOrders(stableswapOrderOrefs: OutRef[], stableswapPoolOref: OutRef, treasuryOref: OutRef | undefined, sysParams: SystemParams, lucid: LucidEvolution, psmProcessingConfig?: PSMProcessingConfig): Promise<TxBuilder>;
@@ -4753,4 +4771,4 @@ declare function mkAuthTokenPolicy(ac: AssetClass, tn: string): MintingPolicy;
4753
4771
 
4754
4772
  declare const alwaysFailValidator: SpendingValidator;
4755
4773
 
4756
- 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, findInterestOracle, 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, numberToRational, oneShotMintTx, openCdp, openRob, openStakingPosition, parseAccountDatum, parseAccountDatumOrThrow, parseCdpDatum, parseCdpDatumOrThrow, parseCdpRedeemer, parseCdpRedeemerOrThrow, parseCollateralAssetDatum, parseCollateralAssetDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestCollectionDatum, parseInterestOracleDatum, parsePollManager, parsePollManagerOrThrow, parsePollShard, parsePollShardOrThrow, parsePollShardRedeemer, parsePollShardRedeemerOrThrow, parsePriceOracleDatum, parsePythStateDatum, parseRobDatum, parseRobDatumOrThrow, parseRobRedeemer, parseRobRedeemerOrThrow, parseSnapshotEpochToScaleToSumDatum, parseSnapshotEpochToScaleToSumDatumOrThrow, parseStabilityPoolDatum, parseStabilityPoolDatumOrThrow, parseStabilityPoolRedeemer, parseStabilityPoolRedeemerOrThrow, parseStableswapOrderDatum, parseStableswapOrderDatumOrThrow, parseStableswapOrderRedeemer, parseStableswapOrderRedeemerOrThrow, parseStableswapPoolDatum, parseStableswapPoolDatumOrThrow, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, parseStakingRedeemer, parseStakingRedeemerOrThrow, partitionEpochToScaleToSums, pickValidSatisfiableOrders, processSpRequest, psmOrderType, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, rewardsPerAsset, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, 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 };
4774
+ 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, computeEffectiveCdpState, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, derivePythPrice, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateMinOrderOutputLovelaces, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findAdminInterestCollectors, findAllInterestCollectors, findAllStableswapPools, findAllTreasuryUtxos, findAllTreasuryUtxosWithNonAdaAsset, findCollateralAsset, findE2s2sSnapshots, findIAsset, findInterestOracle, findRandomCdpCreator, findRandomNonAdminInterestCollector, findRandomTreasuryUtxo, findRandomTreasuryUtxoWithAsset, findRandomTreasuryUtxoWithOnlyAda, findRelevantE2s2sIdxs, findStabilityPool, findStabilityPoolAccount, findStableswapPool, findStakingManager, findStakingManagerByOutRef, findStakingPositionByOutRef, freezeCdp, fromDataDerivedPythPrice, fromDecimal, fromSPInteger, fromSysParamsCredential, fromSysParamsDerivedPythPrice, fromSysParamsPythFeedParams, fromSysParamsStakeCredential, fromSystemParamsAsset, fromSystemParamsAssetLucid, fromSystemParamsScriptRef, getAssetClassComparisonStr, getInlineDatumOrThrow, getPythFeedConfig, getUpdatedAccountDeposit, handleOracleForCollateralAsset, iassetValueOfCollateral, init, initCDPCreator, initCollector, initGovernance, initInterestCollector, initPythConfig, 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, numberToRational, oneShotMintTx, openCdp, openRob, openStakingPosition, parseAccountDatum, parseAccountDatumOrThrow, parseCdpDatum, parseCdpDatumOrThrow, parseCdpRedeemer, parseCdpRedeemerOrThrow, parseCollateralAssetDatum, parseCollateralAssetDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestCollectionDatum, parseInterestOracleDatum, parsePollManager, parsePollManagerOrThrow, parsePollShard, parsePollShardOrThrow, parsePollShardRedeemer, parsePollShardRedeemerOrThrow, parsePriceOracleDatum, parsePythStateDatum, parseRobDatum, parseRobDatumOrThrow, parseRobRedeemer, parseRobRedeemerOrThrow, parseSnapshotEpochToScaleToSumDatum, parseSnapshotEpochToScaleToSumDatumOrThrow, parseStabilityPoolDatum, parseStabilityPoolDatumOrThrow, parseStabilityPoolRedeemer, parseStabilityPoolRedeemerOrThrow, parseStableswapOrderDatum, parseStableswapOrderDatumOrThrow, parseStableswapOrderRedeemer, parseStableswapOrderRedeemerOrThrow, parseStableswapPoolDatum, parseStableswapPoolDatumOrThrow, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, parseStakingRedeemer, parseStakingRedeemerOrThrow, partitionEpochToScaleToSums, pickValidSatisfiableOrders, processSpRequest, psmOrderType, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, rewardsPerAsset, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, 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
@@ -141,6 +141,7 @@ __export(index_exports, {
141
141
  collectInterestTx: () => collectInterestTx,
142
142
  collectPriceFeedIds: () => collectPriceFeedIds,
143
143
  collectorFeeTx: () => collectorFeeTx,
144
+ computeEffectiveCdpState: () => computeEffectiveCdpState,
144
145
  createDestinationDatum: () => createDestinationDatum,
145
146
  createE2s2sSnapshots: () => createE2s2sSnapshots,
146
147
  createProcessRequestAccountRedeemer: () => createProcessRequestAccountRedeemer,
@@ -168,6 +169,7 @@ __export(index_exports, {
168
169
  feedPriceOracleTx: () => feedPriceOracleTx,
169
170
  findAdminInterestCollectors: () => findAdminInterestCollectors,
170
171
  findAllInterestCollectors: () => findAllInterestCollectors,
172
+ findAllStableswapPools: () => findAllStableswapPools,
171
173
  findAllTreasuryUtxos: () => findAllTreasuryUtxos,
172
174
  findAllTreasuryUtxosWithNonAdaAsset: () => findAllTreasuryUtxosWithNonAdaAsset,
173
175
  findCollateralAsset: () => findCollateralAsset,
@@ -182,6 +184,7 @@ __export(index_exports, {
182
184
  findRelevantE2s2sIdxs: () => findRelevantE2s2sIdxs,
183
185
  findStabilityPool: () => findStabilityPool,
184
186
  findStabilityPoolAccount: () => findStabilityPoolAccount,
187
+ findStableswapPool: () => findStableswapPool,
185
188
  findStakingManager: () => findStakingManager,
186
189
  findStakingManagerByOutRef: () => findStakingManagerByOutRef,
187
190
  findStakingPositionByOutRef: () => findStakingPositionByOutRef,
@@ -867,28 +870,41 @@ function iassetValueOfCollateral(collateralAmt, oraclePrice) {
867
870
  rationalDiv(rationalFromInt(collateralAmt), oraclePrice)
868
871
  );
869
872
  }
870
- function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpContent, interestOracleDatum) {
871
- return (0, import_ts_pattern5.match)(cdpContent.cdpFees).with({ ActiveCDPInterestTracking: import_ts_pattern5.P.select() }, (interest) => {
872
- const interestAmt = calculateAccruedInterest(
873
+ function computeEffectiveCdpState(now, cdpUtxoAssets, cdpContent, interestOracleDatum) {
874
+ const interestAmt = (0, import_ts_pattern5.match)(cdpContent.cdpFees).with(
875
+ { ActiveCDPInterestTracking: import_ts_pattern5.P.select() },
876
+ (interest) => calculateAccruedInterest(
873
877
  now,
874
878
  interest.unitaryInterestSnapshot,
875
879
  cdpContent.mintedAmt,
876
880
  interest.lastSettled,
877
881
  interestOracleDatum
878
- );
879
- const collateral = (0, import_cardano_offchain_common.assetClassValueOf)(
880
- cdpUtxoAssets,
881
- cdpContent.collateralAsset
882
- );
883
- const ratio = rationalDiv(
884
- rationalFromInt(collateral),
885
- rationalMul(
886
- rationalFromInt(cdpContent.mintedAmt + interestAmt),
887
- iassetPrice
888
- )
889
- );
890
- return Number(ratio.numerator) * 100 / Number(ratio.denominator);
891
- }).with({ FrozenCDPAccumulatedFees: import_ts_pattern5.P.any }, () => 0).exhaustive();
882
+ )
883
+ ).with(
884
+ { FrozenCDPAccumulatedFees: import_ts_pattern5.P.select() },
885
+ (fees) => fees.iassetInterest
886
+ ).exhaustive();
887
+ const collateralAmt = (0, import_cardano_offchain_common.assetClassValueOf)(
888
+ cdpUtxoAssets,
889
+ cdpContent.collateralAsset
890
+ );
891
+ return {
892
+ mintedAmt: cdpContent.mintedAmt + interestAmt,
893
+ collateralAmt
894
+ };
895
+ }
896
+ function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpContent, interestOracleDatum) {
897
+ const cdpState = computeEffectiveCdpState(
898
+ now,
899
+ cdpUtxoAssets,
900
+ cdpContent,
901
+ interestOracleDatum
902
+ );
903
+ const ratio = rationalDiv(
904
+ rationalFromInt(cdpState.collateralAmt),
905
+ rationalMul(rationalFromInt(cdpState.mintedAmt), iassetPrice)
906
+ );
907
+ return Number(ratio.numerator) * 100 / Number(ratio.denominator);
892
908
  }
893
909
  function calculateIAssetRedemptionAmt(collateralAmt, mintedAmt, price, rmr) {
894
910
  return rationalCeil(
@@ -10702,15 +10718,19 @@ async function initPyth(lucid) {
10702
10718
  alwaysSucceedValidator
10703
10719
  )
10704
10720
  );
10705
- await runAndAwaitTxBuilder(
10706
- lucid,
10707
- lucid.newTx().register.Stake(
10708
- (0, import_lucid63.credentialToRewardAddress)(lucid.config().network, {
10709
- hash: (0, import_lucid63.validatorToScriptHash)(alwaysSucceedValidator),
10710
- type: "Script"
10711
- })
10712
- )
10721
+ const alwaysSucceedRewardAddress = (0, import_lucid63.credentialToRewardAddress)(
10722
+ lucid.config().network,
10723
+ { hash: (0, import_lucid63.validatorToScriptHash)(alwaysSucceedValidator), type: "Script" }
10724
+ );
10725
+ const { registered } = await lucid.rewardAccountAt(
10726
+ alwaysSucceedRewardAddress
10713
10727
  );
10728
+ if (!registered) {
10729
+ await runAndAwaitTxBuilder(
10730
+ lucid,
10731
+ lucid.newTx().register.Stake(alwaysSucceedRewardAddress)
10732
+ );
10733
+ }
10714
10734
  return pythStateAsset;
10715
10735
  }
10716
10736
 
@@ -10735,23 +10755,18 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
10735
10755
  lucid,
10736
10756
  pythFeedValidator
10737
10757
  );
10738
- try {
10758
+ const pythFeedRewardAddress = (0, import_lucid64.credentialToRewardAddress)(
10759
+ lucid.config().network,
10760
+ { hash: (0, import_lucid64.validatorToScriptHash)(pythFeedValidator), type: "Script" }
10761
+ );
10762
+ const { registered } = await lucid.rewardAccountAt(
10763
+ pythFeedRewardAddress
10764
+ );
10765
+ if (!registered) {
10739
10766
  await runAndAwaitTxBuilder(
10740
10767
  lucid,
10741
- lucid.newTx().register.Stake(
10742
- (0, import_lucid64.credentialToRewardAddress)(lucid.config().network, {
10743
- hash: (0, import_lucid64.validatorToScriptHash)(pythFeedValidator),
10744
- type: "Script"
10745
- })
10746
- )
10768
+ lucid.newTx().register.Stake(pythFeedRewardAddress)
10747
10769
  );
10748
- } catch (error) {
10749
- const message = error instanceof Error ? error.message : String(error);
10750
- if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes(
10751
- "Trying to re-register some already known credentials."
10752
- )) {
10753
- throw error;
10754
- }
10755
10770
  }
10756
10771
  const key = `${asset.name}/${(0, import_lucid64.toHex)(collateral.collateralAsset.currencySymbol)}.${(0, import_lucid64.toHex)(collateral.collateralAsset.tokenName)}`;
10757
10772
  return {
@@ -10942,16 +10957,12 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
10942
10957
  lucid.config().network,
10943
10958
  (0, import_lucid64.scriptHashToCredential)(cdpRedeemValHash)
10944
10959
  );
10945
- try {
10960
+ const { registered: cdpRedeemRegistered } = await lucid.rewardAccountAt(cdpRedeemRewardAddr);
10961
+ if (!cdpRedeemRegistered) {
10946
10962
  await runAndAwaitTxBuilder(
10947
10963
  lucid,
10948
10964
  lucid.newTx().register.Stake(cdpRedeemRewardAddr)
10949
10965
  );
10950
- } catch (error) {
10951
- const message = error instanceof Error ? error.message : String(error);
10952
- if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes("Trying to re-register some already known credentials.")) {
10953
- throw error;
10954
- }
10955
10966
  }
10956
10967
  const cdpParams = {
10957
10968
  cdpAuthToken: toSystemParamsAsset(cdpToken),
@@ -11783,35 +11794,78 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
11783
11794
  return [...mintingOrders, ...selected].map((o) => o.order);
11784
11795
  }
11785
11796
 
11786
- // src/contracts/stableswap/transactions.ts
11797
+ // src/contracts/stableswap/queries.ts
11787
11798
  var import_lucid67 = require("@lucid-evolution/lucid");
11788
11799
  var import_cardano_offchain_common36 = require("@indigo-labs/cardano-offchain-common");
11789
11800
  var import_fp_ts30 = require("fp-ts");
11801
+ async function findAllStableswapPools(lucid, sysParams) {
11802
+ const cdpUtxos = await lucid.utxosAtWithUnit(
11803
+ createScriptAddress(
11804
+ lucid.config().network,
11805
+ sysParams.validatorHashes.cdpHash
11806
+ ),
11807
+ (0, import_cardano_offchain_common36.assetClassToUnit)(
11808
+ fromSystemParamsAsset(sysParams.stableswapParams.cdpToken)
11809
+ )
11810
+ );
11811
+ return import_fp_ts30.function.pipe(
11812
+ cdpUtxos.map(
11813
+ (utxo) => import_fp_ts30.function.pipe(
11814
+ import_fp_ts30.option.fromNullable(utxo.datum),
11815
+ import_fp_ts30.option.flatMap(parseStableswapPoolDatum),
11816
+ import_fp_ts30.option.map((datum) => ({ utxo, datum }))
11817
+ )
11818
+ ),
11819
+ import_fp_ts30.array.compact
11820
+ );
11821
+ }
11822
+ async function findStableswapPool(lucid, sysParams, iassetName, collateralAsset) {
11823
+ const stableswapPools = await findAllStableswapPools(lucid, sysParams);
11824
+ return (0, import_cardano_offchain_common36.matchSingle)(
11825
+ import_fp_ts30.function.pipe(
11826
+ stableswapPools.map((pool) => {
11827
+ if ((0, import_lucid67.toHex)(pool.datum.iasset) === iassetName && (0, import_cardano_offchain_common36.isSameAssetClass)(pool.datum.collateralAsset, collateralAsset)) {
11828
+ return import_fp_ts30.option.some(pool);
11829
+ }
11830
+ return import_fp_ts30.option.none;
11831
+ }),
11832
+ import_fp_ts30.array.compact
11833
+ ),
11834
+ (res) => new Error(
11835
+ "Expected a single stableswap pool UTXO.: " + JSON.stringify(res)
11836
+ )
11837
+ );
11838
+ }
11839
+
11840
+ // src/contracts/stableswap/transactions.ts
11841
+ var import_lucid68 = require("@lucid-evolution/lucid");
11842
+ var import_cardano_offchain_common37 = require("@indigo-labs/cardano-offchain-common");
11843
+ var import_fp_ts31 = require("fp-ts");
11790
11844
  async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
11791
11845
  const myAddress = await lucid.wallet().address();
11792
- const pkh = (0, import_lucid67.paymentCredentialOf)(myAddress);
11846
+ const pkh = (0, import_lucid68.paymentCredentialOf)(myAddress);
11793
11847
  const datum = {
11794
- iasset: (0, import_lucid67.fromHex)((0, import_lucid67.fromText)(iasset)),
11848
+ iasset: (0, import_lucid68.fromHex)((0, import_lucid68.fromText)(iasset)),
11795
11849
  collateralAsset,
11796
- owner: (0, import_lucid67.fromHex)(pkh.hash),
11797
- destination: (0, import_cardano_offchain_common36.addressFromBech32)(destinationAddress ?? myAddress),
11850
+ owner: (0, import_lucid68.fromHex)(pkh.hash),
11851
+ destination: (0, import_cardano_offchain_common37.addressFromBech32)(destinationAddress ?? myAddress),
11798
11852
  destinationInlineDatum: destinationInlineDatum ?? null,
11799
11853
  maxExecutionFee,
11800
11854
  maxFeeRatio: maxFeeRatio ?? (minting ? poolDatum.mintingFeeRatio : poolDatum.redemptionFeeRatio)
11801
11855
  };
11802
- const assetsToSwap = minting ? (0, import_cardano_offchain_common36.mkAssetsOf)(collateralAsset, amount) : (0, import_cardano_offchain_common36.mkAssetsOf)(
11856
+ const assetsToSwap = minting ? (0, import_cardano_offchain_common37.mkAssetsOf)(collateralAsset, amount) : (0, import_cardano_offchain_common37.mkAssetsOf)(
11803
11857
  {
11804
- currencySymbol: (0, import_lucid67.fromHex)(
11858
+ currencySymbol: (0, import_lucid68.fromHex)(
11805
11859
  params.stableswapParams.iassetSymbol.unCurrencySymbol
11806
11860
  ),
11807
- tokenName: (0, import_lucid67.fromHex)((0, import_lucid67.fromText)(iasset))
11861
+ tokenName: (0, import_lucid68.fromHex)((0, import_lucid68.fromText)(iasset))
11808
11862
  },
11809
11863
  amount
11810
11864
  );
11811
- const orderAssetsPlusFees = (0, import_lucid67.addAssets)(
11865
+ const orderAssetsPlusFees = (0, import_lucid68.addAssets)(
11812
11866
  assetsToSwap,
11813
- (0, import_cardano_offchain_common36.mkLovelacesOf)(maxExecutionFee),
11814
- (0, import_cardano_offchain_common36.mkLovelacesOf)(additionalLovelaces)
11867
+ (0, import_cardano_offchain_common37.mkLovelacesOf)(maxExecutionFee),
11868
+ (0, import_cardano_offchain_common37.mkLovelacesOf)(additionalLovelaces)
11815
11869
  );
11816
11870
  const expectedMinOutputLovelaces = estimateMinOrderOutputLovelaces(
11817
11871
  lucid,
@@ -11819,7 +11873,7 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
11819
11873
  orderAssetsPlusFees
11820
11874
  );
11821
11875
  return lucid.newTx().pay.ToContract(
11822
- (0, import_lucid67.credentialToAddress)(lucid.config().network, {
11876
+ (0, import_lucid68.credentialToAddress)(lucid.config().network, {
11823
11877
  hash: params.validatorHashes.stableswapHash,
11824
11878
  type: "Script"
11825
11879
  }),
@@ -11827,11 +11881,11 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
11827
11881
  kind: "inline",
11828
11882
  value: serialiseStableswapOrderDatum(datum)
11829
11883
  },
11830
- (0, import_lucid67.addAssets)(orderAssetsPlusFees, (0, import_cardano_offchain_common36.mkLovelacesOf)(expectedMinOutputLovelaces))
11884
+ (0, import_lucid68.addAssets)(orderAssetsPlusFees, (0, import_cardano_offchain_common37.mkLovelacesOf)(expectedMinOutputLovelaces))
11831
11885
  );
11832
11886
  }
11833
11887
  async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
11834
- const stableswapScriptRefUtxo = (0, import_cardano_offchain_common36.matchSingle)(
11888
+ const stableswapScriptRefUtxo = (0, import_cardano_offchain_common37.matchSingle)(
11835
11889
  await lucid.utxosByOutRef([
11836
11890
  fromSystemParamsScriptRef(
11837
11891
  sysParams.scriptReferences.stableswapValidatorRef
@@ -11839,20 +11893,20 @@ async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
11839
11893
  ]),
11840
11894
  (_) => new Error("Expected a single Stableswap Ref Script UTXO")
11841
11895
  );
11842
- const stableswapOrderUtxo = (0, import_cardano_offchain_common36.matchSingle)(
11896
+ const stableswapOrderUtxo = (0, import_cardano_offchain_common37.matchSingle)(
11843
11897
  await lucid.utxosByOutRef([stableswapOrderOref]),
11844
11898
  (_) => new Error("Expected a single Stableswap Order UTXO.")
11845
11899
  );
11846
11900
  const stableswapOrderDatum = parseStableswapOrderDatumOrThrow(
11847
- (0, import_cardano_offchain_common36.getInlineDatumOrThrow)(stableswapOrderUtxo)
11901
+ (0, import_cardano_offchain_common37.getInlineDatumOrThrow)(stableswapOrderUtxo)
11848
11902
  );
11849
11903
  return lucid.newTx().readFrom([stableswapScriptRefUtxo]).collectFrom(
11850
11904
  [stableswapOrderUtxo],
11851
11905
  serialiseStableswapOrderRedeemer("CancelStableswapOrder")
11852
- ).addSignerKey((0, import_lucid67.toHex)(stableswapOrderDatum.owner));
11906
+ ).addSignerKey((0, import_lucid68.toHex)(stableswapOrderDatum.owner));
11853
11907
  }
11854
11908
  async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPoolOref, treasuryOref, sysParams, lucid, psmProcessingConfig) {
11855
- const stableswapScriptRefUtxo = (0, import_cardano_offchain_common36.matchSingle)(
11909
+ const stableswapScriptRefUtxo = (0, import_cardano_offchain_common37.matchSingle)(
11856
11910
  await lucid.utxosByOutRef([
11857
11911
  fromSystemParamsScriptRef(
11858
11912
  sysParams.scriptReferences.stableswapValidatorRef
@@ -11860,13 +11914,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11860
11914
  ]),
11861
11915
  (_) => new Error("Expected a single Stableswap Ref Script UTXO")
11862
11916
  );
11863
- const cdpScriptRefUtxo = (0, import_cardano_offchain_common36.matchSingle)(
11917
+ const cdpScriptRefUtxo = (0, import_cardano_offchain_common37.matchSingle)(
11864
11918
  await lucid.utxosByOutRef([
11865
11919
  fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
11866
11920
  ]),
11867
11921
  (_) => new Error("Expected a single CDP Ref Script UTXO")
11868
11922
  );
11869
- const iAssetTokenPolicyRefScriptUtxo = (0, import_cardano_offchain_common36.matchSingle)(
11923
+ const iAssetTokenPolicyRefScriptUtxo = (0, import_cardano_offchain_common37.matchSingle)(
11870
11924
  await lucid.utxosByOutRef([
11871
11925
  fromSystemParamsScriptRef(
11872
11926
  sysParams.scriptReferences.iAssetTokenPolicyRef
@@ -11874,11 +11928,11 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11874
11928
  ]),
11875
11929
  (_) => new Error("Expected a single iasset token policy Ref Script UTXO")
11876
11930
  );
11877
- if (import_fp_ts30.array.isEmpty(stableswapOrderOrefs)) {
11931
+ if (import_fp_ts31.array.isEmpty(stableswapOrderOrefs)) {
11878
11932
  throw new Error("At least one order must be provided.");
11879
11933
  }
11880
11934
  const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
11881
- const sortedStableswapOrderUtxos = (0, import_lucid67.sortUTxOs)(
11935
+ const sortedStableswapOrderUtxos = (0, import_lucid68.sortUTxOs)(
11882
11936
  stableswapOrderUtxos,
11883
11937
  "Canonical"
11884
11938
  );
@@ -11887,26 +11941,26 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11887
11941
  }
11888
11942
  const mainOrderUtxo = sortedStableswapOrderUtxos[0];
11889
11943
  const mainOrderDatum = parseStableswapOrderDatumOrThrow(
11890
- (0, import_cardano_offchain_common36.getInlineDatumOrThrow)(mainOrderUtxo)
11944
+ (0, import_cardano_offchain_common37.getInlineDatumOrThrow)(mainOrderUtxo)
11891
11945
  );
11892
11946
  const iassetAc = {
11893
- currencySymbol: (0, import_lucid67.fromHex)(
11947
+ currencySymbol: (0, import_lucid68.fromHex)(
11894
11948
  sysParams.stableswapParams.iassetSymbol.unCurrencySymbol
11895
11949
  ),
11896
11950
  tokenName: mainOrderDatum.iasset
11897
11951
  };
11898
11952
  const collateralAc = mainOrderDatum.collateralAsset;
11899
- const stableswapPoolUtxo = (0, import_cardano_offchain_common36.matchSingle)(
11953
+ const stableswapPoolUtxo = (0, import_cardano_offchain_common37.matchSingle)(
11900
11954
  await lucid.utxosByOutRef([stableswapPoolOref]),
11901
11955
  (_) => new Error("Expected a single cdp UTXO")
11902
11956
  );
11903
11957
  const stableswapPoolDatum = parseStableswapPoolDatumOrThrow(
11904
- (0, import_cardano_offchain_common36.getInlineDatumOrThrow)(stableswapPoolUtxo)
11958
+ (0, import_cardano_offchain_common37.getInlineDatumOrThrow)(stableswapPoolUtxo)
11905
11959
  );
11906
11960
  const ordersInfo = sortedStableswapOrderUtxos.map(
11907
11961
  (orderUtxo) => {
11908
11962
  const orderDatum = parseStableswapOrderDatumOrThrow(
11909
- (0, import_cardano_offchain_common36.getInlineDatumOrThrow)(orderUtxo)
11963
+ (0, import_cardano_offchain_common37.getInlineDatumOrThrow)(orderUtxo)
11910
11964
  );
11911
11965
  const res = summariseOrder(
11912
11966
  lucid,
@@ -11921,9 +11975,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11921
11975
  return res.result;
11922
11976
  }
11923
11977
  );
11924
- const totalSwapInfo = import_fp_ts30.function.pipe(
11978
+ const totalSwapInfo = import_fp_ts31.function.pipe(
11925
11979
  ordersInfo,
11926
- import_fp_ts30.array.reduce(
11980
+ import_fp_ts31.array.reduce(
11927
11981
  {
11928
11982
  suppliedCollateralAsset: 0n,
11929
11983
  suppliedIasset: 0n,
@@ -11945,11 +11999,11 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11945
11999
  )
11946
12000
  );
11947
12001
  const collateralAmtChangePool = totalSwapInfo.suppliedCollateralAsset - totalSwapInfo.owedCollateralAsset;
11948
- const newPsmPoolValue = (0, import_lucid67.addAssets)(
12002
+ const newPsmPoolValue = (0, import_lucid68.addAssets)(
11949
12003
  stableswapPoolUtxo.assets,
11950
- (0, import_cardano_offchain_common36.mkAssetsOf)(collateralAc, collateralAmtChangePool)
12004
+ (0, import_cardano_offchain_common37.mkAssetsOf)(collateralAc, collateralAmtChangePool)
11951
12005
  );
11952
- if ((0, import_cardano_offchain_common36.assetClassValueOf)(newPsmPoolValue, collateralAc) < 0n) {
12006
+ if ((0, import_cardano_offchain_common37.assetClassValueOf)(newPsmPoolValue, collateralAc) < 0n) {
11953
12007
  throw new Error("Cannot batch more than liquidity allows");
11954
12008
  }
11955
12009
  const amountToMint = totalSwapInfo.owedIasset - totalSwapInfo.suppliedIasset + totalSwapInfo.mintingFee;
@@ -11975,14 +12029,14 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11975
12029
  newPsmPoolValue
11976
12030
  ).setMinFee(stableswapOrderOrefs.length > 1 ? 1498875n : 1030000n);
11977
12031
  if (amountToMint !== 0n) {
11978
- tx.mintAssets((0, import_cardano_offchain_common36.mkAssetsOf)(iassetAc, amountToMint), import_lucid67.Data.void());
12032
+ tx.mintAssets((0, import_cardano_offchain_common37.mkAssetsOf)(iassetAc, amountToMint), import_lucid68.Data.void());
11979
12033
  }
11980
- import_fp_ts30.function.pipe(
12034
+ import_fp_ts31.function.pipe(
11981
12035
  ordersInfo,
11982
- import_fp_ts30.array.reduce(tx, (acc, orderInfo) => {
12036
+ import_fp_ts31.array.reduce(tx, (acc, orderInfo) => {
11983
12037
  return acc.collectFrom(
11984
12038
  [orderInfo.order.utxo],
11985
- (0, import_cardano_offchain_common36.isSameOutRef)(orderInfo.order.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
12039
+ (0, import_cardano_offchain_common37.isSameOutRef)(orderInfo.order.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
11986
12040
  kind: "selected",
11987
12041
  makeRedeemer: (inputIndices) => {
11988
12042
  return serialiseStableswapOrderRedeemer({
@@ -11995,7 +12049,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11995
12049
  inputs: [orderInfo.order.utxo, mainOrderUtxo]
11996
12050
  }
11997
12051
  ).pay.ToAddressWithData(
11998
- (0, import_cardano_offchain_common36.addressToBech32)(
12052
+ (0, import_cardano_offchain_common37.addressToBech32)(
11999
12053
  orderInfo.order.datum.destination,
12000
12054
  lucid.config().network
12001
12055
  ),
@@ -12006,13 +12060,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
12006
12060
  orderInfo.order.utxo
12007
12061
  )
12008
12062
  },
12009
- (0, import_lucid67.addAssets)(
12063
+ (0, import_lucid68.addAssets)(
12010
12064
  // NOTICE: Currently, we always take the max execution fee from the order utxo.
12011
12065
  // This can be improved so that we take the actual execution fee.
12012
- (0, import_cardano_offchain_common36.mkLovelacesOf)(
12013
- (0, import_cardano_offchain_common36.lovelacesAmt)(orderInfo.order.utxo.assets) - orderInfo.order.datum.maxExecutionFee
12066
+ (0, import_cardano_offchain_common37.mkLovelacesOf)(
12067
+ (0, import_cardano_offchain_common37.lovelacesAmt)(orderInfo.order.utxo.assets) - orderInfo.order.datum.maxExecutionFee
12014
12068
  ),
12015
- orderInfo.orderType === "MINTING" ? (0, import_cardano_offchain_common36.mkAssetsOf)(iassetAc, orderInfo.swapInfo.owedIasset) : (0, import_cardano_offchain_common36.mkAssetsOf)(
12069
+ orderInfo.orderType === "MINTING" ? (0, import_cardano_offchain_common37.mkAssetsOf)(iassetAc, orderInfo.swapInfo.owedIasset) : (0, import_cardano_offchain_common37.mkAssetsOf)(
12016
12070
  collateralAc,
12017
12071
  orderInfo.swapInfo.owedCollateralAsset
12018
12072
  )
@@ -12035,7 +12089,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
12035
12089
  return tx;
12036
12090
  }
12037
12091
  async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRef, newMintingFeeRatio, newRedemptionFeeRatio, sysParams, lucid) {
12038
- const stableswapScriptRefUtxo = (0, import_cardano_offchain_common36.matchSingle)(
12092
+ const stableswapScriptRefUtxo = (0, import_cardano_offchain_common37.matchSingle)(
12039
12093
  await lucid.utxosByOutRef([
12040
12094
  fromSystemParamsScriptRef(
12041
12095
  sysParams.scriptReferences.stableswapValidatorRef
@@ -12043,22 +12097,22 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
12043
12097
  ]),
12044
12098
  (_) => new Error("Expected a single Stableswap Ref Script UTXO")
12045
12099
  );
12046
- const cdpScriptRefUtxo = (0, import_cardano_offchain_common36.matchSingle)(
12100
+ const cdpScriptRefUtxo = (0, import_cardano_offchain_common37.matchSingle)(
12047
12101
  await lucid.utxosByOutRef([
12048
12102
  fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
12049
12103
  ]),
12050
12104
  (_) => new Error("Expected a single CDP Ref Script UTXO")
12051
12105
  );
12052
- const stableswapPool = (0, import_cardano_offchain_common36.matchSingle)(
12106
+ const stableswapPool = (0, import_cardano_offchain_common37.matchSingle)(
12053
12107
  await lucid.utxosByOutRef([stableswapPoolOutRef]),
12054
12108
  (_) => new Error("Expected a single Stableswap Pool UTXO.")
12055
12109
  );
12056
- const stableswapFeeUtxo = (0, import_cardano_offchain_common36.matchSingle)(
12110
+ const stableswapFeeUtxo = (0, import_cardano_offchain_common37.matchSingle)(
12057
12111
  await lucid.utxosByOutRef([stableswapFeeOutRef]),
12058
12112
  (_) => new Error("Expected a single Stableswap Fee UTXO.")
12059
12113
  );
12060
12114
  const stableswapPoolDatum = parseStableswapPoolDatumOrThrow(
12061
- (0, import_cardano_offchain_common36.getInlineDatumOrThrow)(stableswapPool)
12115
+ (0, import_cardano_offchain_common37.getInlineDatumOrThrow)(stableswapPool)
12062
12116
  );
12063
12117
  const newStableswapPoolDatum = {
12064
12118
  ...stableswapPoolDatum,
@@ -12086,7 +12140,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
12086
12140
  value: serialiseStableswapPoolDatum(newStableswapPoolDatum)
12087
12141
  },
12088
12142
  stableswapPool.assets
12089
- ).addSignerKey((0, import_lucid67.toHex)(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
12143
+ ).addSignerKey((0, import_lucid68.toHex)(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
12090
12144
  }
12091
12145
  // Annotate the CommonJS export names for ESM import in node:
12092
12146
  0 && (module.exports = {
@@ -12201,6 +12255,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
12201
12255
  collectInterestTx,
12202
12256
  collectPriceFeedIds,
12203
12257
  collectorFeeTx,
12258
+ computeEffectiveCdpState,
12204
12259
  createDestinationDatum,
12205
12260
  createE2s2sSnapshots,
12206
12261
  createProcessRequestAccountRedeemer,
@@ -12228,6 +12283,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
12228
12283
  feedPriceOracleTx,
12229
12284
  findAdminInterestCollectors,
12230
12285
  findAllInterestCollectors,
12286
+ findAllStableswapPools,
12231
12287
  findAllTreasuryUtxos,
12232
12288
  findAllTreasuryUtxosWithNonAdaAsset,
12233
12289
  findCollateralAsset,
@@ -12242,6 +12298,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
12242
12298
  findRelevantE2s2sIdxs,
12243
12299
  findStabilityPool,
12244
12300
  findStabilityPoolAccount,
12301
+ findStableswapPool,
12245
12302
  findStakingManager,
12246
12303
  findStakingManagerByOutRef,
12247
12304
  findStakingPositionByOutRef,
package/dist/index.mjs CHANGED
@@ -475,28 +475,41 @@ function iassetValueOfCollateral(collateralAmt, oraclePrice) {
475
475
  rationalDiv(rationalFromInt(collateralAmt), oraclePrice)
476
476
  );
477
477
  }
478
- function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpContent, interestOracleDatum) {
479
- return match4(cdpContent.cdpFees).with({ ActiveCDPInterestTracking: P4.select() }, (interest) => {
480
- const interestAmt = calculateAccruedInterest(
478
+ function computeEffectiveCdpState(now, cdpUtxoAssets, cdpContent, interestOracleDatum) {
479
+ const interestAmt = match4(cdpContent.cdpFees).with(
480
+ { ActiveCDPInterestTracking: P4.select() },
481
+ (interest) => calculateAccruedInterest(
481
482
  now,
482
483
  interest.unitaryInterestSnapshot,
483
484
  cdpContent.mintedAmt,
484
485
  interest.lastSettled,
485
486
  interestOracleDatum
486
- );
487
- const collateral = assetClassValueOf(
488
- cdpUtxoAssets,
489
- cdpContent.collateralAsset
490
- );
491
- const ratio = rationalDiv(
492
- rationalFromInt(collateral),
493
- rationalMul(
494
- rationalFromInt(cdpContent.mintedAmt + interestAmt),
495
- iassetPrice
496
- )
497
- );
498
- return Number(ratio.numerator) * 100 / Number(ratio.denominator);
499
- }).with({ FrozenCDPAccumulatedFees: P4.any }, () => 0).exhaustive();
487
+ )
488
+ ).with(
489
+ { FrozenCDPAccumulatedFees: P4.select() },
490
+ (fees) => fees.iassetInterest
491
+ ).exhaustive();
492
+ const collateralAmt = assetClassValueOf(
493
+ cdpUtxoAssets,
494
+ cdpContent.collateralAsset
495
+ );
496
+ return {
497
+ mintedAmt: cdpContent.mintedAmt + interestAmt,
498
+ collateralAmt
499
+ };
500
+ }
501
+ function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpContent, interestOracleDatum) {
502
+ const cdpState = computeEffectiveCdpState(
503
+ now,
504
+ cdpUtxoAssets,
505
+ cdpContent,
506
+ interestOracleDatum
507
+ );
508
+ const ratio = rationalDiv(
509
+ rationalFromInt(cdpState.collateralAmt),
510
+ rationalMul(rationalFromInt(cdpState.mintedAmt), iassetPrice)
511
+ );
512
+ return Number(ratio.numerator) * 100 / Number(ratio.denominator);
500
513
  }
501
514
  function calculateIAssetRedemptionAmt(collateralAmt, mintedAmt, price, rmr) {
502
515
  return rationalCeil(
@@ -10580,15 +10593,19 @@ async function initPyth(lucid) {
10580
10593
  alwaysSucceedValidator
10581
10594
  )
10582
10595
  );
10583
- await runAndAwaitTxBuilder(
10584
- lucid,
10585
- lucid.newTx().register.Stake(
10586
- credentialToRewardAddress3(lucid.config().network, {
10587
- hash: validatorToScriptHash4(alwaysSucceedValidator),
10588
- type: "Script"
10589
- })
10590
- )
10596
+ const alwaysSucceedRewardAddress = credentialToRewardAddress3(
10597
+ lucid.config().network,
10598
+ { hash: validatorToScriptHash4(alwaysSucceedValidator), type: "Script" }
10599
+ );
10600
+ const { registered } = await lucid.rewardAccountAt(
10601
+ alwaysSucceedRewardAddress
10591
10602
  );
10603
+ if (!registered) {
10604
+ await runAndAwaitTxBuilder(
10605
+ lucid,
10606
+ lucid.newTx().register.Stake(alwaysSucceedRewardAddress)
10607
+ );
10608
+ }
10592
10609
  return pythStateAsset;
10593
10610
  }
10594
10611
 
@@ -10613,23 +10630,18 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
10613
10630
  lucid,
10614
10631
  pythFeedValidator
10615
10632
  );
10616
- try {
10633
+ const pythFeedRewardAddress = credentialToRewardAddress4(
10634
+ lucid.config().network,
10635
+ { hash: validatorToScriptHash5(pythFeedValidator), type: "Script" }
10636
+ );
10637
+ const { registered } = await lucid.rewardAccountAt(
10638
+ pythFeedRewardAddress
10639
+ );
10640
+ if (!registered) {
10617
10641
  await runAndAwaitTxBuilder(
10618
10642
  lucid,
10619
- lucid.newTx().register.Stake(
10620
- credentialToRewardAddress4(lucid.config().network, {
10621
- hash: validatorToScriptHash5(pythFeedValidator),
10622
- type: "Script"
10623
- })
10624
- )
10643
+ lucid.newTx().register.Stake(pythFeedRewardAddress)
10625
10644
  );
10626
- } catch (error) {
10627
- const message = error instanceof Error ? error.message : String(error);
10628
- if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes(
10629
- "Trying to re-register some already known credentials."
10630
- )) {
10631
- throw error;
10632
- }
10633
10645
  }
10634
10646
  const key = `${asset.name}/${toHex17(collateral.collateralAsset.currencySymbol)}.${toHex17(collateral.collateralAsset.tokenName)}`;
10635
10647
  return {
@@ -10820,16 +10832,12 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
10820
10832
  lucid.config().network,
10821
10833
  scriptHashToCredential4(cdpRedeemValHash)
10822
10834
  );
10823
- try {
10835
+ const { registered: cdpRedeemRegistered } = await lucid.rewardAccountAt(cdpRedeemRewardAddr);
10836
+ if (!cdpRedeemRegistered) {
10824
10837
  await runAndAwaitTxBuilder(
10825
10838
  lucid,
10826
10839
  lucid.newTx().register.Stake(cdpRedeemRewardAddr)
10827
10840
  );
10828
- } catch (error) {
10829
- const message = error instanceof Error ? error.message : String(error);
10830
- if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes("Trying to re-register some already known credentials.")) {
10831
- throw error;
10832
- }
10833
10841
  }
10834
10842
  const cdpParams = {
10835
10843
  cdpAuthToken: toSystemParamsAsset(cdpToken),
@@ -11677,6 +11685,53 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
11677
11685
  return [...mintingOrders, ...selected].map((o) => o.order);
11678
11686
  }
11679
11687
 
11688
+ // src/contracts/stableswap/queries.ts
11689
+ import { toHex as toHex20 } from "@lucid-evolution/lucid";
11690
+ import {
11691
+ assetClassToUnit as assetClassToUnit8,
11692
+ isSameAssetClass as isSameAssetClass6,
11693
+ matchSingle as matchSingle7
11694
+ } from "@indigo-labs/cardano-offchain-common";
11695
+ import { array as A18, function as F28, option as O23 } from "fp-ts";
11696
+ async function findAllStableswapPools(lucid, sysParams) {
11697
+ const cdpUtxos = await lucid.utxosAtWithUnit(
11698
+ createScriptAddress(
11699
+ lucid.config().network,
11700
+ sysParams.validatorHashes.cdpHash
11701
+ ),
11702
+ assetClassToUnit8(
11703
+ fromSystemParamsAsset(sysParams.stableswapParams.cdpToken)
11704
+ )
11705
+ );
11706
+ return F28.pipe(
11707
+ cdpUtxos.map(
11708
+ (utxo) => F28.pipe(
11709
+ O23.fromNullable(utxo.datum),
11710
+ O23.flatMap(parseStableswapPoolDatum),
11711
+ O23.map((datum) => ({ utxo, datum }))
11712
+ )
11713
+ ),
11714
+ A18.compact
11715
+ );
11716
+ }
11717
+ async function findStableswapPool(lucid, sysParams, iassetName, collateralAsset) {
11718
+ const stableswapPools = await findAllStableswapPools(lucid, sysParams);
11719
+ return matchSingle7(
11720
+ F28.pipe(
11721
+ stableswapPools.map((pool) => {
11722
+ if (toHex20(pool.datum.iasset) === iassetName && isSameAssetClass6(pool.datum.collateralAsset, collateralAsset)) {
11723
+ return O23.some(pool);
11724
+ }
11725
+ return O23.none;
11726
+ }),
11727
+ A18.compact
11728
+ ),
11729
+ (res) => new Error(
11730
+ "Expected a single stableswap pool UTXO.: " + JSON.stringify(res)
11731
+ )
11732
+ );
11733
+ }
11734
+
11680
11735
  // src/contracts/stableswap/transactions.ts
11681
11736
  import {
11682
11737
  addAssets as addAssets18,
@@ -11686,20 +11741,20 @@ import {
11686
11741
  fromText as fromText15,
11687
11742
  paymentCredentialOf as paymentCredentialOf3,
11688
11743
  sortUTxOs as sortUTxOs2,
11689
- toHex as toHex20
11744
+ toHex as toHex21
11690
11745
  } from "@lucid-evolution/lucid";
11691
11746
  import {
11692
11747
  addressFromBech32 as addressFromBech323,
11693
11748
  addressToBech32 as addressToBech324,
11694
11749
  getInlineDatumOrThrow as getInlineDatumOrThrow6,
11695
- matchSingle as matchSingle7,
11750
+ matchSingle as matchSingle8,
11696
11751
  mkAssetsOf as mkAssetsOf16,
11697
11752
  mkLovelacesOf as mkLovelacesOf9,
11698
11753
  lovelacesAmt as lovelacesAmt6,
11699
11754
  isSameOutRef as isSameOutRef2,
11700
11755
  assetClassValueOf as assetClassValueOf13
11701
11756
  } from "@indigo-labs/cardano-offchain-common";
11702
- import { array as A18, function as F28 } from "fp-ts";
11757
+ import { array as A19, function as F29 } from "fp-ts";
11703
11758
  async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
11704
11759
  const myAddress = await lucid.wallet().address();
11705
11760
  const pkh = paymentCredentialOf3(myAddress);
@@ -11744,7 +11799,7 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
11744
11799
  );
11745
11800
  }
11746
11801
  async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
11747
- const stableswapScriptRefUtxo = matchSingle7(
11802
+ const stableswapScriptRefUtxo = matchSingle8(
11748
11803
  await lucid.utxosByOutRef([
11749
11804
  fromSystemParamsScriptRef(
11750
11805
  sysParams.scriptReferences.stableswapValidatorRef
@@ -11752,7 +11807,7 @@ async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
11752
11807
  ]),
11753
11808
  (_) => new Error("Expected a single Stableswap Ref Script UTXO")
11754
11809
  );
11755
- const stableswapOrderUtxo = matchSingle7(
11810
+ const stableswapOrderUtxo = matchSingle8(
11756
11811
  await lucid.utxosByOutRef([stableswapOrderOref]),
11757
11812
  (_) => new Error("Expected a single Stableswap Order UTXO.")
11758
11813
  );
@@ -11762,10 +11817,10 @@ async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
11762
11817
  return lucid.newTx().readFrom([stableswapScriptRefUtxo]).collectFrom(
11763
11818
  [stableswapOrderUtxo],
11764
11819
  serialiseStableswapOrderRedeemer("CancelStableswapOrder")
11765
- ).addSignerKey(toHex20(stableswapOrderDatum.owner));
11820
+ ).addSignerKey(toHex21(stableswapOrderDatum.owner));
11766
11821
  }
11767
11822
  async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPoolOref, treasuryOref, sysParams, lucid, psmProcessingConfig) {
11768
- const stableswapScriptRefUtxo = matchSingle7(
11823
+ const stableswapScriptRefUtxo = matchSingle8(
11769
11824
  await lucid.utxosByOutRef([
11770
11825
  fromSystemParamsScriptRef(
11771
11826
  sysParams.scriptReferences.stableswapValidatorRef
@@ -11773,13 +11828,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11773
11828
  ]),
11774
11829
  (_) => new Error("Expected a single Stableswap Ref Script UTXO")
11775
11830
  );
11776
- const cdpScriptRefUtxo = matchSingle7(
11831
+ const cdpScriptRefUtxo = matchSingle8(
11777
11832
  await lucid.utxosByOutRef([
11778
11833
  fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
11779
11834
  ]),
11780
11835
  (_) => new Error("Expected a single CDP Ref Script UTXO")
11781
11836
  );
11782
- const iAssetTokenPolicyRefScriptUtxo = matchSingle7(
11837
+ const iAssetTokenPolicyRefScriptUtxo = matchSingle8(
11783
11838
  await lucid.utxosByOutRef([
11784
11839
  fromSystemParamsScriptRef(
11785
11840
  sysParams.scriptReferences.iAssetTokenPolicyRef
@@ -11787,7 +11842,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11787
11842
  ]),
11788
11843
  (_) => new Error("Expected a single iasset token policy Ref Script UTXO")
11789
11844
  );
11790
- if (A18.isEmpty(stableswapOrderOrefs)) {
11845
+ if (A19.isEmpty(stableswapOrderOrefs)) {
11791
11846
  throw new Error("At least one order must be provided.");
11792
11847
  }
11793
11848
  const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
@@ -11809,7 +11864,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11809
11864
  tokenName: mainOrderDatum.iasset
11810
11865
  };
11811
11866
  const collateralAc = mainOrderDatum.collateralAsset;
11812
- const stableswapPoolUtxo = matchSingle7(
11867
+ const stableswapPoolUtxo = matchSingle8(
11813
11868
  await lucid.utxosByOutRef([stableswapPoolOref]),
11814
11869
  (_) => new Error("Expected a single cdp UTXO")
11815
11870
  );
@@ -11834,9 +11889,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11834
11889
  return res.result;
11835
11890
  }
11836
11891
  );
11837
- const totalSwapInfo = F28.pipe(
11892
+ const totalSwapInfo = F29.pipe(
11838
11893
  ordersInfo,
11839
- A18.reduce(
11894
+ A19.reduce(
11840
11895
  {
11841
11896
  suppliedCollateralAsset: 0n,
11842
11897
  suppliedIasset: 0n,
@@ -11890,9 +11945,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11890
11945
  if (amountToMint !== 0n) {
11891
11946
  tx.mintAssets(mkAssetsOf16(iassetAc, amountToMint), Data53.void());
11892
11947
  }
11893
- F28.pipe(
11948
+ F29.pipe(
11894
11949
  ordersInfo,
11895
- A18.reduce(tx, (acc, orderInfo) => {
11950
+ A19.reduce(tx, (acc, orderInfo) => {
11896
11951
  return acc.collectFrom(
11897
11952
  [orderInfo.order.utxo],
11898
11953
  isSameOutRef2(orderInfo.order.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
@@ -11948,7 +12003,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11948
12003
  return tx;
11949
12004
  }
11950
12005
  async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRef, newMintingFeeRatio, newRedemptionFeeRatio, sysParams, lucid) {
11951
- const stableswapScriptRefUtxo = matchSingle7(
12006
+ const stableswapScriptRefUtxo = matchSingle8(
11952
12007
  await lucid.utxosByOutRef([
11953
12008
  fromSystemParamsScriptRef(
11954
12009
  sysParams.scriptReferences.stableswapValidatorRef
@@ -11956,17 +12011,17 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
11956
12011
  ]),
11957
12012
  (_) => new Error("Expected a single Stableswap Ref Script UTXO")
11958
12013
  );
11959
- const cdpScriptRefUtxo = matchSingle7(
12014
+ const cdpScriptRefUtxo = matchSingle8(
11960
12015
  await lucid.utxosByOutRef([
11961
12016
  fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
11962
12017
  ]),
11963
12018
  (_) => new Error("Expected a single CDP Ref Script UTXO")
11964
12019
  );
11965
- const stableswapPool = matchSingle7(
12020
+ const stableswapPool = matchSingle8(
11966
12021
  await lucid.utxosByOutRef([stableswapPoolOutRef]),
11967
12022
  (_) => new Error("Expected a single Stableswap Pool UTXO.")
11968
12023
  );
11969
- const stableswapFeeUtxo = matchSingle7(
12024
+ const stableswapFeeUtxo = matchSingle8(
11970
12025
  await lucid.utxosByOutRef([stableswapFeeOutRef]),
11971
12026
  (_) => new Error("Expected a single Stableswap Fee UTXO.")
11972
12027
  );
@@ -11999,7 +12054,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
11999
12054
  value: serialiseStableswapPoolDatum(newStableswapPoolDatum)
12000
12055
  },
12001
12056
  stableswapPool.assets
12002
- ).addSignerKey(toHex20(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
12057
+ ).addSignerKey(toHex21(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
12003
12058
  }
12004
12059
  export {
12005
12060
  AccountContentSchema,
@@ -12113,6 +12168,7 @@ export {
12113
12168
  collectInterestTx,
12114
12169
  collectPriceFeedIds,
12115
12170
  collectorFeeTx,
12171
+ computeEffectiveCdpState,
12116
12172
  createDestinationDatum,
12117
12173
  createE2s2sSnapshots,
12118
12174
  createProcessRequestAccountRedeemer,
@@ -12140,6 +12196,7 @@ export {
12140
12196
  feedPriceOracleTx,
12141
12197
  findAdminInterestCollectors,
12142
12198
  findAllInterestCollectors,
12199
+ findAllStableswapPools,
12143
12200
  findAllTreasuryUtxos,
12144
12201
  findAllTreasuryUtxosWithNonAdaAsset,
12145
12202
  findCollateralAsset,
@@ -12154,6 +12211,7 @@ export {
12154
12211
  findRelevantE2s2sIdxs,
12155
12212
  findStabilityPool,
12156
12213
  findStabilityPoolAccount,
12214
+ findStableswapPool,
12157
12215
  findStakingManager,
12158
12216
  findStakingManagerByOutRef,
12159
12217
  findStakingPositionByOutRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigo-labs/indigo-sdk",
3
- "version": "0.5.14",
3
+ "version": "0.5.16",
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",