@indigo-labs/indigo-sdk 0.3.19 → 0.3.20
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 +33 -1
- package/dist/index.d.ts +33 -1
- package/dist/index.js +87 -45
- package/dist/index.mjs +81 -45
- package/package.json +1 -1
- package/src/contracts/rob/helpers.ts +120 -16
- package/src/contracts/rob-leverage/helpers.ts +5 -18
package/dist/index.d.mts
CHANGED
|
@@ -3715,6 +3715,38 @@ declare function serialisePriceOracleDatum(d: PriceOracleDatum): string;
|
|
|
3715
3715
|
declare function parsePriceOracleDatum(datum: string): PriceOracleDatum;
|
|
3716
3716
|
|
|
3717
3717
|
declare const MIN_ROB_COLLATERAL_AMT = 3000000n;
|
|
3718
|
+
/**
|
|
3719
|
+
* The maximum of redemptions for a Tx that is doing only sell order redemptions.
|
|
3720
|
+
* Based on the benchmarks.
|
|
3721
|
+
*/
|
|
3722
|
+
declare const MAX_SELL_ROB_REDEMPTIONS_COUNT = 18;
|
|
3723
|
+
/**
|
|
3724
|
+
* The maximum of redemptions for a Tx that is doing only buy order redemptions.
|
|
3725
|
+
* Based on the benchmarks.
|
|
3726
|
+
*/
|
|
3727
|
+
declare const MAX_BUY_ROB_REDEMPTIONS_COUNT = 20;
|
|
3728
|
+
/**
|
|
3729
|
+
* Helper for ROB redemptions. A redeemer is selling iAssets against
|
|
3730
|
+
* a buy order, i.e. buying a collateral asset.
|
|
3731
|
+
* The return is the amount of collateral asset he buys.
|
|
3732
|
+
*/
|
|
3733
|
+
declare function calculatePurchaseAmtWhenRobBuyOrder(sellIassetAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
|
|
3734
|
+
/**
|
|
3735
|
+
* A redeemer is purchasing given collateral amount against buy order.
|
|
3736
|
+
* Calculate what is the amount of iAsset the user sells/spends.
|
|
3737
|
+
*/
|
|
3738
|
+
declare function calculateSpendAmtWhenRobBuyOrder(purchaseCollateralAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
|
|
3739
|
+
/**
|
|
3740
|
+
* Helper for ROB redemptions. A redeemer is selling collateral against
|
|
3741
|
+
* a sell order, i.e. buying iassets.
|
|
3742
|
+
* The return is the amount of iassets he buys.
|
|
3743
|
+
*/
|
|
3744
|
+
declare function calculatePurchaseAmtWhenRobSellOrder(sellCollateralAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
|
|
3745
|
+
/**
|
|
3746
|
+
* A redeemer is purchasing given iasset amount against sell order.
|
|
3747
|
+
* Calculate what is the amount of collateral the user sells/spends.
|
|
3748
|
+
*/
|
|
3749
|
+
declare function calculateSpendAmtWhenRobSellOrder(purchaseIassetAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
|
|
3718
3750
|
/**
|
|
3719
3751
|
* The amount of collateral asset available in the ROB when buy order. In case of ADA, take
|
|
3720
3752
|
* into account the min UTXO collateral.
|
|
@@ -4570,4 +4602,4 @@ declare function mkAuthTokenPolicy(ac: AssetClass, tn: string): MintingPolicy;
|
|
|
4570
4602
|
|
|
4571
4603
|
declare const alwaysFailValidator: SpendingValidator;
|
|
4572
4604
|
|
|
4573
|
-
export { type AccountAction, type AccountContent, AccountContentSchema, type ActionReturnDatum, type AddCollateralAsssetContent, type AddressCredential, type AddressCredentialOrDatum, type AddressSP, AikenIntervalIntervalBound, AikenIntervalIntervalBoundType, type Amount, type AssetClassD, type AssetClassSP, AssetClassSchema, type AssetInfo, type AssetSnapshot, type AssetState, type AuthTokenPolicies, BASE_MAX_EXECUTION_FEE, BASE_MAX_TX_FEE, BigIntOrd, type CDPContent, CDPCreatorParams, type CDPCreatorParamsSP, type CDPDatum, CardanoTransactionValidityRange, type CdpParams, type CdpParamsSP, type CdpRedeemParams, type CdpRedeemParamsSP, type CdpRedeemer, type CollateralAssetContent, type CollateralAssetInfo, type CollateralAssetOutput, type CollectorParamsSP, type CollectorRedeemer, CollectorRedeemerSchema, CredentialD, CredentialSchema, type CurrencySymbolSP, DEFAULT_INIT_OPTIONS, type DerivedPythPrice, type DerivedPythPriceSP, DerivedPythPriceSchema, type E2S2SIndex, type E2S2SIndicesPerAsset, type EpochToScaleKey, type EpochToScaleToSumEntry, type ExecuteDatum, ExecuteParams, type ExecuteParamsSP, type Feed, type FindE2S2SIdxResult, type GovDatum, GovParams, type GovParamsSP, type GovRedeemer, type IAssetContent, type IAssetDatum, type IAssetOutput, type IAssetParamsSP, type IAssetPriceInfo, IAssetPriceInfoSchema, type IAssetRedeemer, IAssetScriptParams, INIT_TOKEN_NAMES, type IndigoOracleNftParam, type InitialAssetParam, type InitialCollateralAssetParam, type InitialStablepoolParam, type InitializeOptions, type Input, type InterestCollectionDatum, type InterestCollectionParams, type InterestCollectionParamsSP, InterestCollectionParamsSchema, type InterestCollectionRedeemer, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type InterestOracleRedeemer, MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET, MAX_E2S2S_ENTRIES_COUNT, MAX_REDEMPTIONS_WITH_CDP_OPEN, MIN_ROB_COLLATERAL_AMT, type MarketSession, type ModifyStableswapPoolContent, ONE_DAY, ONE_HOUR, ONE_SECOND, ONE_YEAR, type OracleIdx, OracleIdxSchema, type Output, PRICE_UPDATE_MAGIC, type ParsedOutput, type PollDatum, type PollManagerContent, PollManagerParams, type PollManagerParamsSP, type PollManagerRedeemer, type PollShardContent, PollShardParams, type PollShardParamsSP, type PollShardRedeemer, type PollStatus, type PriceOracleDatum, type PriceOracleParam, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PriceUpdate, type ProcessRequestAccountContent, type ProposalContent, ProposalContentSchema, type ProposeAssetContent, type ProposeStableswapPoolContent, type ProtocolParams, ProtocolParamsSchema, type PubKeyHash, type PythConfig, type PythConfiguration, type PythFeedConfig, type PythFeedParams, type PythFeedParamsSP, type PythFeedRedeemer, type PythMessageParts, type PythOracleParam, type PythPriceConfigurationSP, type PythStateDatum, type PythUpdatesRedeemer, type Rational, RationalSchema, type RedeemCdpWithdrawalRedeemer, type RobDatum, type RobOrderType, type RobOutput, type RobParams, type RobParamsSP, RobParamsSchema, type RobRedeemer, SOLANA_FORMAT_MAGIC, type SPInteger, SPIntegerSchema, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, type SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, type StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, type StabilityPoolRedeemer, StabilityPoolRedeemerSchema, type StableswapOrderDatum, StableswapOrderDatumSchema, type StableswapOrderRedeemer, type StableswapOutputDatum, type StableswapParamsSP, type StableswapPoolContent, StakeCredential, StakeCredentialSchema, type StakingManager, type StakingManagerOutput, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingPositionOutput, type StakingRedeemer, type StartTime, type StateSnapshot, type SumSnapshot, type SystemParams, type TokenNameSP, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type UpgradePaths, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, adjustCdp, adjustPriceToDecimals, adjustRob, adjustStakingPosition, alwaysFailValidator, annulRequest, approximateLeverageRedemptions, attachOracle, balance, batchCollectInterest, batchProcessStableswapOrders, bigintMax, bigintMin, buildRedemptionsTx, burnCdp, calculateAccruedInterest, calculateAdaReward, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectorFeeTx, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findRelevantE2s2sIdxs, findStakingManager, findStakingManagerByOutRef, findStakingPositionByOutRef, freezeCdp, fromDataDerivedPythPrice, fromDecimal, fromSPInteger, fromSysParamsCredential, fromSysParamsDerivedPythPrice, fromSysParamsPythFeedParams, fromSysParamsStakeCredential, fromSystemParamsAsset, fromSystemParamsAssetLucid, fromSystemParamsScriptRef, getAssetClassComparisonStr, getInlineDatumOrThrow, getPythFeedConfig, getUpdatedAccountDeposit, handleOracleForCollateralAsset, iassetValueOfCollateral, init, initCDPCreator, initCollector, initGovernance, initInterestCollector, initPythConfig, initScriptRef, initSpState, initStakingManager, initSumVal, initTreasury, initializeAsset, insertSorted, isBuyOrderFullyRedeemed, isFullyRedeemed, isSameEpochToScaleKey, leverageCdpWithRob, liquidateCdp, liquidationHelper, loadSystemParamsFromFile, loadSystemParamsFromUrl, matchSingle, mergeCdps, mergeShards, mintAuthTokenDirect, mintCdp, mintOneTimeAsset, mintOneTimeToken, mkAuthTokenPolicy, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkCdpRedeemValidatorFromSP, mkCdpValidatorFromSP, mkCollectorValidatorFromSP, mkExecuteValidator, mkExecuteValidatorFromSP, mkGovValidator, mkGovValidatorFromSP, mkIAssetTokenPolicy, mkIAssetValidatorFromSP, mkInterestCollectionValidator, mkInterestCollectionValidatorFromSP, mkInterestOracleValidator, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkPriceOracleValidator, mkPythFeedValidator, mkRobValidator, mkRobValidatorFromSP, mkSPInteger, mkStabilityPoolAddr, mkStabilityPoolValidator, mkStabilityPoolValidatorFromSP, mkStableswapValidator, mkStableswapValidatorFromSP, mkStakingValidatorFromSP, mkTreasuryAddr, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, oneShotMintTx, openCdp, openRob, openStakingPosition, parseAccountDatum, parseAccountDatumOrThrow, parseCdpDatum, parseCdpDatumOrThrow, parseCdpRedeemer, parseCdpRedeemerOrThrow, parseCollateralAssetDatum, parseCollateralAssetDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestCollectionDatum, parseInterestOracleDatum, parsePollManager, parsePollManagerOrThrow, parsePollShard, parsePollShardOrThrow, parsePollShardRedeemer, parsePollShardRedeemerOrThrow, parsePriceOracleDatum, parsePythStateDatum, parseRobDatum, parseRobDatumOrThrow, parseRobRedeemer, parseRobRedeemerOrThrow, parseSnapshotEpochToScaleToSumDatum, parseSnapshotEpochToScaleToSumDatumOrThrow, parseStabilityPoolDatum, parseStabilityPoolDatumOrThrow, parseStabilityPoolRedeemer, parseStabilityPoolRedeemerOrThrow, parseStableswapOrderDatum, parseStableswapOrderDatumOrThrow, parseStableswapOrderRedeemer, parseStableswapOrderRedeemerOrThrow, parseStableswapPoolDatum, parseStableswapPoolDatumOrThrow, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, parseStakingRedeemer, parseStakingRedeemerOrThrow, partitionEpochToScaleToSums, processSpRequest, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseActionReturnDatum, serialiseCdpDatum, serialiseCdpRedeemer, serialiseCollectorRedeemer, serialiseExecuteDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseGovRedeemer, serialiseIAssetDatum, serialiseIAssetRedeemer, serialiseInterestCollectionDatum, serialiseInterestCollectionRedeemer, serialiseInterestOracleDatum, serialisePollDatum, serialisePollManagerRedeemer, serialisePollShardRedeemer, serialisePriceOracleDatum, serialisePriceOracleRedeemer, serialisePythFeedParams, serialisePythFeedRedeemer, serialisePythStateDatum, serialisePythUpdatesRedeemer, serialiseRedeemCdpWithdrawalRedeemer, serialiseRobDatum, serialiseRobRedeemer, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, serialiseStableswapOrderDatum, serialiseStableswapOrderRedeemer, serialiseStableswapOutputDatum, serialiseStableswapPoolDatum, serialiseStakingDatum, serialiseStakingRedeemer, shuffle, signersAllOf, spAdd, spDiv, spMul, spSub, spZeroNegatives, startInterestOracle, startPriceOracleTx, submitTx, sum, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
|
|
4605
|
+
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 OracleIdx, OracleIdxSchema, type Output, PRICE_UPDATE_MAGIC, type ParsedOutput, type PollDatum, type PollManagerContent, PollManagerParams, type PollManagerParamsSP, type PollManagerRedeemer, type PollShardContent, PollShardParams, type PollShardParamsSP, type PollShardRedeemer, type PollStatus, type PriceOracleDatum, type PriceOracleParam, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PriceUpdate, type ProcessRequestAccountContent, type ProposalContent, ProposalContentSchema, type ProposeAssetContent, type ProposeStableswapPoolContent, type ProtocolParams, ProtocolParamsSchema, type PubKeyHash, type PythConfig, type PythConfiguration, type PythFeedConfig, type PythFeedParams, type PythFeedParamsSP, type PythFeedRedeemer, type PythMessageParts, type PythOracleParam, type PythPriceConfigurationSP, type PythStateDatum, type PythUpdatesRedeemer, type Rational, RationalSchema, type RedeemCdpWithdrawalRedeemer, type RobDatum, type RobOrderType, type RobOutput, type RobParams, type RobParamsSP, RobParamsSchema, type RobRedeemer, SOLANA_FORMAT_MAGIC, type SPInteger, SPIntegerSchema, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, type SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, type StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, type StabilityPoolRedeemer, StabilityPoolRedeemerSchema, type StableswapOrderDatum, StableswapOrderDatumSchema, type StableswapOrderRedeemer, type StableswapOutputDatum, type StableswapParamsSP, type StableswapPoolContent, StakeCredential, StakeCredentialSchema, type StakingManager, type StakingManagerOutput, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingPositionOutput, type StakingRedeemer, type StartTime, type StateSnapshot, type SumSnapshot, type SystemParams, type TokenNameSP, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type UpgradePaths, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, adjustCdp, adjustPriceToDecimals, adjustRob, adjustStakingPosition, alwaysFailValidator, annulRequest, approximateLeverageRedemptions, attachOracle, balance, batchCollectInterest, batchProcessStableswapOrders, bigintMax, bigintMin, buildRedemptionsTx, burnCdp, calculateAccruedInterest, calculateAdaReward, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculatePurchaseAmtWhenRobBuyOrder, calculatePurchaseAmtWhenRobSellOrder, calculateSpendAmtWhenRobBuyOrder, calculateSpendAmtWhenRobSellOrder, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectorFeeTx, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findRelevantE2s2sIdxs, findStakingManager, findStakingManagerByOutRef, findStakingPositionByOutRef, freezeCdp, fromDataDerivedPythPrice, fromDecimal, fromSPInteger, fromSysParamsCredential, fromSysParamsDerivedPythPrice, fromSysParamsPythFeedParams, fromSysParamsStakeCredential, fromSystemParamsAsset, fromSystemParamsAssetLucid, fromSystemParamsScriptRef, getAssetClassComparisonStr, getInlineDatumOrThrow, getPythFeedConfig, getUpdatedAccountDeposit, handleOracleForCollateralAsset, iassetValueOfCollateral, init, initCDPCreator, initCollector, initGovernance, initInterestCollector, initPythConfig, initScriptRef, initSpState, initStakingManager, initSumVal, initTreasury, initializeAsset, insertSorted, isBuyOrderFullyRedeemed, isFullyRedeemed, isSameEpochToScaleKey, leverageCdpWithRob, liquidateCdp, liquidationHelper, loadSystemParamsFromFile, loadSystemParamsFromUrl, matchSingle, mergeCdps, mergeShards, mintAuthTokenDirect, mintCdp, mintOneTimeAsset, mintOneTimeToken, mkAuthTokenPolicy, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkCdpRedeemValidatorFromSP, mkCdpValidatorFromSP, mkCollectorValidatorFromSP, mkExecuteValidator, mkExecuteValidatorFromSP, mkGovValidator, mkGovValidatorFromSP, mkIAssetTokenPolicy, mkIAssetValidatorFromSP, mkInterestCollectionValidator, mkInterestCollectionValidatorFromSP, mkInterestOracleValidator, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkPriceOracleValidator, mkPythFeedValidator, mkRobValidator, mkRobValidatorFromSP, mkSPInteger, mkStabilityPoolAddr, mkStabilityPoolValidator, mkStabilityPoolValidatorFromSP, mkStableswapValidator, mkStableswapValidatorFromSP, mkStakingValidatorFromSP, mkTreasuryAddr, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, oneShotMintTx, openCdp, openRob, openStakingPosition, parseAccountDatum, parseAccountDatumOrThrow, parseCdpDatum, parseCdpDatumOrThrow, parseCdpRedeemer, parseCdpRedeemerOrThrow, parseCollateralAssetDatum, parseCollateralAssetDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestCollectionDatum, parseInterestOracleDatum, parsePollManager, parsePollManagerOrThrow, parsePollShard, parsePollShardOrThrow, parsePollShardRedeemer, parsePollShardRedeemerOrThrow, parsePriceOracleDatum, parsePythStateDatum, parseRobDatum, parseRobDatumOrThrow, parseRobRedeemer, parseRobRedeemerOrThrow, parseSnapshotEpochToScaleToSumDatum, parseSnapshotEpochToScaleToSumDatumOrThrow, parseStabilityPoolDatum, parseStabilityPoolDatumOrThrow, parseStabilityPoolRedeemer, parseStabilityPoolRedeemerOrThrow, parseStableswapOrderDatum, parseStableswapOrderDatumOrThrow, parseStableswapOrderRedeemer, parseStableswapOrderRedeemerOrThrow, parseStableswapPoolDatum, parseStableswapPoolDatumOrThrow, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, parseStakingRedeemer, parseStakingRedeemerOrThrow, partitionEpochToScaleToSums, processSpRequest, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseActionReturnDatum, serialiseCdpDatum, serialiseCdpRedeemer, serialiseCollectorRedeemer, serialiseExecuteDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseGovRedeemer, serialiseIAssetDatum, serialiseIAssetRedeemer, serialiseInterestCollectionDatum, serialiseInterestCollectionRedeemer, serialiseInterestOracleDatum, serialisePollDatum, serialisePollManagerRedeemer, serialisePollShardRedeemer, serialisePriceOracleDatum, serialisePriceOracleRedeemer, serialisePythFeedParams, serialisePythFeedRedeemer, serialisePythStateDatum, serialisePythUpdatesRedeemer, serialiseRedeemCdpWithdrawalRedeemer, serialiseRobDatum, serialiseRobRedeemer, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, serialiseStableswapOrderDatum, serialiseStableswapOrderRedeemer, serialiseStableswapOutputDatum, serialiseStableswapPoolDatum, serialiseStakingDatum, serialiseStakingRedeemer, shuffle, signersAllOf, spAdd, spDiv, spMul, spSub, spZeroNegatives, startInterestOracle, startPriceOracleTx, submitTx, sum, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
|
package/dist/index.d.ts
CHANGED
|
@@ -3715,6 +3715,38 @@ declare function serialisePriceOracleDatum(d: PriceOracleDatum): string;
|
|
|
3715
3715
|
declare function parsePriceOracleDatum(datum: string): PriceOracleDatum;
|
|
3716
3716
|
|
|
3717
3717
|
declare const MIN_ROB_COLLATERAL_AMT = 3000000n;
|
|
3718
|
+
/**
|
|
3719
|
+
* The maximum of redemptions for a Tx that is doing only sell order redemptions.
|
|
3720
|
+
* Based on the benchmarks.
|
|
3721
|
+
*/
|
|
3722
|
+
declare const MAX_SELL_ROB_REDEMPTIONS_COUNT = 18;
|
|
3723
|
+
/**
|
|
3724
|
+
* The maximum of redemptions for a Tx that is doing only buy order redemptions.
|
|
3725
|
+
* Based on the benchmarks.
|
|
3726
|
+
*/
|
|
3727
|
+
declare const MAX_BUY_ROB_REDEMPTIONS_COUNT = 20;
|
|
3728
|
+
/**
|
|
3729
|
+
* Helper for ROB redemptions. A redeemer is selling iAssets against
|
|
3730
|
+
* a buy order, i.e. buying a collateral asset.
|
|
3731
|
+
* The return is the amount of collateral asset he buys.
|
|
3732
|
+
*/
|
|
3733
|
+
declare function calculatePurchaseAmtWhenRobBuyOrder(sellIassetAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
|
|
3734
|
+
/**
|
|
3735
|
+
* A redeemer is purchasing given collateral amount against buy order.
|
|
3736
|
+
* Calculate what is the amount of iAsset the user sells/spends.
|
|
3737
|
+
*/
|
|
3738
|
+
declare function calculateSpendAmtWhenRobBuyOrder(purchaseCollateralAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
|
|
3739
|
+
/**
|
|
3740
|
+
* Helper for ROB redemptions. A redeemer is selling collateral against
|
|
3741
|
+
* a sell order, i.e. buying iassets.
|
|
3742
|
+
* The return is the amount of iassets he buys.
|
|
3743
|
+
*/
|
|
3744
|
+
declare function calculatePurchaseAmtWhenRobSellOrder(sellCollateralAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
|
|
3745
|
+
/**
|
|
3746
|
+
* A redeemer is purchasing given iasset amount against sell order.
|
|
3747
|
+
* Calculate what is the amount of collateral the user sells/spends.
|
|
3748
|
+
*/
|
|
3749
|
+
declare function calculateSpendAmtWhenRobSellOrder(purchaseIassetAmt: bigint, redemptionReimbursementRatio: Rational, price: Rational): bigint;
|
|
3718
3750
|
/**
|
|
3719
3751
|
* The amount of collateral asset available in the ROB when buy order. In case of ADA, take
|
|
3720
3752
|
* into account the min UTXO collateral.
|
|
@@ -4570,4 +4602,4 @@ declare function mkAuthTokenPolicy(ac: AssetClass, tn: string): MintingPolicy;
|
|
|
4570
4602
|
|
|
4571
4603
|
declare const alwaysFailValidator: SpendingValidator;
|
|
4572
4604
|
|
|
4573
|
-
export { type AccountAction, type AccountContent, AccountContentSchema, type ActionReturnDatum, type AddCollateralAsssetContent, type AddressCredential, type AddressCredentialOrDatum, type AddressSP, AikenIntervalIntervalBound, AikenIntervalIntervalBoundType, type Amount, type AssetClassD, type AssetClassSP, AssetClassSchema, type AssetInfo, type AssetSnapshot, type AssetState, type AuthTokenPolicies, BASE_MAX_EXECUTION_FEE, BASE_MAX_TX_FEE, BigIntOrd, type CDPContent, CDPCreatorParams, type CDPCreatorParamsSP, type CDPDatum, CardanoTransactionValidityRange, type CdpParams, type CdpParamsSP, type CdpRedeemParams, type CdpRedeemParamsSP, type CdpRedeemer, type CollateralAssetContent, type CollateralAssetInfo, type CollateralAssetOutput, type CollectorParamsSP, type CollectorRedeemer, CollectorRedeemerSchema, CredentialD, CredentialSchema, type CurrencySymbolSP, DEFAULT_INIT_OPTIONS, type DerivedPythPrice, type DerivedPythPriceSP, DerivedPythPriceSchema, type E2S2SIndex, type E2S2SIndicesPerAsset, type EpochToScaleKey, type EpochToScaleToSumEntry, type ExecuteDatum, ExecuteParams, type ExecuteParamsSP, type Feed, type FindE2S2SIdxResult, type GovDatum, GovParams, type GovParamsSP, type GovRedeemer, type IAssetContent, type IAssetDatum, type IAssetOutput, type IAssetParamsSP, type IAssetPriceInfo, IAssetPriceInfoSchema, type IAssetRedeemer, IAssetScriptParams, INIT_TOKEN_NAMES, type IndigoOracleNftParam, type InitialAssetParam, type InitialCollateralAssetParam, type InitialStablepoolParam, type InitializeOptions, type Input, type InterestCollectionDatum, type InterestCollectionParams, type InterestCollectionParamsSP, InterestCollectionParamsSchema, type InterestCollectionRedeemer, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type InterestOracleRedeemer, MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET, MAX_E2S2S_ENTRIES_COUNT, MAX_REDEMPTIONS_WITH_CDP_OPEN, MIN_ROB_COLLATERAL_AMT, type MarketSession, type ModifyStableswapPoolContent, ONE_DAY, ONE_HOUR, ONE_SECOND, ONE_YEAR, type OracleIdx, OracleIdxSchema, type Output, PRICE_UPDATE_MAGIC, type ParsedOutput, type PollDatum, type PollManagerContent, PollManagerParams, type PollManagerParamsSP, type PollManagerRedeemer, type PollShardContent, PollShardParams, type PollShardParamsSP, type PollShardRedeemer, type PollStatus, type PriceOracleDatum, type PriceOracleParam, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PriceUpdate, type ProcessRequestAccountContent, type ProposalContent, ProposalContentSchema, type ProposeAssetContent, type ProposeStableswapPoolContent, type ProtocolParams, ProtocolParamsSchema, type PubKeyHash, type PythConfig, type PythConfiguration, type PythFeedConfig, type PythFeedParams, type PythFeedParamsSP, type PythFeedRedeemer, type PythMessageParts, type PythOracleParam, type PythPriceConfigurationSP, type PythStateDatum, type PythUpdatesRedeemer, type Rational, RationalSchema, type RedeemCdpWithdrawalRedeemer, type RobDatum, type RobOrderType, type RobOutput, type RobParams, type RobParamsSP, RobParamsSchema, type RobRedeemer, SOLANA_FORMAT_MAGIC, type SPInteger, SPIntegerSchema, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, type SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, type StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, type StabilityPoolRedeemer, StabilityPoolRedeemerSchema, type StableswapOrderDatum, StableswapOrderDatumSchema, type StableswapOrderRedeemer, type StableswapOutputDatum, type StableswapParamsSP, type StableswapPoolContent, StakeCredential, StakeCredentialSchema, type StakingManager, type StakingManagerOutput, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingPositionOutput, type StakingRedeemer, type StartTime, type StateSnapshot, type SumSnapshot, type SystemParams, type TokenNameSP, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type UpgradePaths, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, adjustCdp, adjustPriceToDecimals, adjustRob, adjustStakingPosition, alwaysFailValidator, annulRequest, approximateLeverageRedemptions, attachOracle, balance, batchCollectInterest, batchProcessStableswapOrders, bigintMax, bigintMin, buildRedemptionsTx, burnCdp, calculateAccruedInterest, calculateAdaReward, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectorFeeTx, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findRelevantE2s2sIdxs, findStakingManager, findStakingManagerByOutRef, findStakingPositionByOutRef, freezeCdp, fromDataDerivedPythPrice, fromDecimal, fromSPInteger, fromSysParamsCredential, fromSysParamsDerivedPythPrice, fromSysParamsPythFeedParams, fromSysParamsStakeCredential, fromSystemParamsAsset, fromSystemParamsAssetLucid, fromSystemParamsScriptRef, getAssetClassComparisonStr, getInlineDatumOrThrow, getPythFeedConfig, getUpdatedAccountDeposit, handleOracleForCollateralAsset, iassetValueOfCollateral, init, initCDPCreator, initCollector, initGovernance, initInterestCollector, initPythConfig, initScriptRef, initSpState, initStakingManager, initSumVal, initTreasury, initializeAsset, insertSorted, isBuyOrderFullyRedeemed, isFullyRedeemed, isSameEpochToScaleKey, leverageCdpWithRob, liquidateCdp, liquidationHelper, loadSystemParamsFromFile, loadSystemParamsFromUrl, matchSingle, mergeCdps, mergeShards, mintAuthTokenDirect, mintCdp, mintOneTimeAsset, mintOneTimeToken, mkAuthTokenPolicy, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkCdpRedeemValidatorFromSP, mkCdpValidatorFromSP, mkCollectorValidatorFromSP, mkExecuteValidator, mkExecuteValidatorFromSP, mkGovValidator, mkGovValidatorFromSP, mkIAssetTokenPolicy, mkIAssetValidatorFromSP, mkInterestCollectionValidator, mkInterestCollectionValidatorFromSP, mkInterestOracleValidator, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkPriceOracleValidator, mkPythFeedValidator, mkRobValidator, mkRobValidatorFromSP, mkSPInteger, mkStabilityPoolAddr, mkStabilityPoolValidator, mkStabilityPoolValidatorFromSP, mkStableswapValidator, mkStableswapValidatorFromSP, mkStakingValidatorFromSP, mkTreasuryAddr, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, oneShotMintTx, openCdp, openRob, openStakingPosition, parseAccountDatum, parseAccountDatumOrThrow, parseCdpDatum, parseCdpDatumOrThrow, parseCdpRedeemer, parseCdpRedeemerOrThrow, parseCollateralAssetDatum, parseCollateralAssetDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestCollectionDatum, parseInterestOracleDatum, parsePollManager, parsePollManagerOrThrow, parsePollShard, parsePollShardOrThrow, parsePollShardRedeemer, parsePollShardRedeemerOrThrow, parsePriceOracleDatum, parsePythStateDatum, parseRobDatum, parseRobDatumOrThrow, parseRobRedeemer, parseRobRedeemerOrThrow, parseSnapshotEpochToScaleToSumDatum, parseSnapshotEpochToScaleToSumDatumOrThrow, parseStabilityPoolDatum, parseStabilityPoolDatumOrThrow, parseStabilityPoolRedeemer, parseStabilityPoolRedeemerOrThrow, parseStableswapOrderDatum, parseStableswapOrderDatumOrThrow, parseStableswapOrderRedeemer, parseStableswapOrderRedeemerOrThrow, parseStableswapPoolDatum, parseStableswapPoolDatumOrThrow, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, parseStakingRedeemer, parseStakingRedeemerOrThrow, partitionEpochToScaleToSums, processSpRequest, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseActionReturnDatum, serialiseCdpDatum, serialiseCdpRedeemer, serialiseCollectorRedeemer, serialiseExecuteDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseGovRedeemer, serialiseIAssetDatum, serialiseIAssetRedeemer, serialiseInterestCollectionDatum, serialiseInterestCollectionRedeemer, serialiseInterestOracleDatum, serialisePollDatum, serialisePollManagerRedeemer, serialisePollShardRedeemer, serialisePriceOracleDatum, serialisePriceOracleRedeemer, serialisePythFeedParams, serialisePythFeedRedeemer, serialisePythStateDatum, serialisePythUpdatesRedeemer, serialiseRedeemCdpWithdrawalRedeemer, serialiseRobDatum, serialiseRobRedeemer, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, serialiseStableswapOrderDatum, serialiseStableswapOrderRedeemer, serialiseStableswapOutputDatum, serialiseStableswapPoolDatum, serialiseStakingDatum, serialiseStakingRedeemer, shuffle, signersAllOf, spAdd, spDiv, spMul, spSub, spZeroNegatives, startInterestOracle, startPriceOracleTx, submitTx, sum, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
|
|
4605
|
+
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 OracleIdx, OracleIdxSchema, type Output, PRICE_UPDATE_MAGIC, type ParsedOutput, type PollDatum, type PollManagerContent, PollManagerParams, type PollManagerParamsSP, type PollManagerRedeemer, type PollShardContent, PollShardParams, type PollShardParamsSP, type PollShardRedeemer, type PollStatus, type PriceOracleDatum, type PriceOracleParam, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PriceUpdate, type ProcessRequestAccountContent, type ProposalContent, ProposalContentSchema, type ProposeAssetContent, type ProposeStableswapPoolContent, type ProtocolParams, ProtocolParamsSchema, type PubKeyHash, type PythConfig, type PythConfiguration, type PythFeedConfig, type PythFeedParams, type PythFeedParamsSP, type PythFeedRedeemer, type PythMessageParts, type PythOracleParam, type PythPriceConfigurationSP, type PythStateDatum, type PythUpdatesRedeemer, type Rational, RationalSchema, type RedeemCdpWithdrawalRedeemer, type RobDatum, type RobOrderType, type RobOutput, type RobParams, type RobParamsSP, RobParamsSchema, type RobRedeemer, SOLANA_FORMAT_MAGIC, type SPInteger, SPIntegerSchema, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, type SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, type StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, type StabilityPoolRedeemer, StabilityPoolRedeemerSchema, type StableswapOrderDatum, StableswapOrderDatumSchema, type StableswapOrderRedeemer, type StableswapOutputDatum, type StableswapParamsSP, type StableswapPoolContent, StakeCredential, StakeCredentialSchema, type StakingManager, type StakingManagerOutput, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingPositionOutput, type StakingRedeemer, type StartTime, type StateSnapshot, type SumSnapshot, type SystemParams, type TokenNameSP, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type UpgradePaths, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, adjustCdp, adjustPriceToDecimals, adjustRob, adjustStakingPosition, alwaysFailValidator, annulRequest, approximateLeverageRedemptions, attachOracle, balance, batchCollectInterest, batchProcessStableswapOrders, bigintMax, bigintMin, buildRedemptionsTx, burnCdp, calculateAccruedInterest, calculateAdaReward, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculatePurchaseAmtWhenRobBuyOrder, calculatePurchaseAmtWhenRobSellOrder, calculateSpendAmtWhenRobBuyOrder, calculateSpendAmtWhenRobSellOrder, calculateTotalCollateralForRedemption, calculateUnitaryInterest, calculateUnitaryInterestSinceOracleLastUpdated, cancelRob, cancelStableswapOrder, castCDPCreatorParams, castCdpParams, castCdpRedeemParams, castExecuteParams, castGovParams, castInterestCollectionParams, castInterestOracleParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castRobParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimRob, closeCdp, closeStakingPosition, collectInterestTx, collectorFeeTx, createDestinationDatum, createE2s2sSnapshots, createProcessRequestAccountRedeemer, createProposal, createScriptAddress, createShardsChunks, createStableswapOrder, decodePriceUpdate, decodePythMessage, depositCdp, deriveAuthToken, distributeAda, distributeInterest, distributeReward, divideOnChainCompatible, encodePriceUpdate, encodePythMessage, encodeSignedPythMessage, endProposal, estimateUtxoMinLovelace, executeProposal, feedInterestOracle, feedPriceOracleTx, findRelevantE2s2sIdxs, findStakingManager, findStakingManagerByOutRef, findStakingPositionByOutRef, freezeCdp, fromDataDerivedPythPrice, fromDecimal, fromSPInteger, fromSysParamsCredential, fromSysParamsDerivedPythPrice, fromSysParamsPythFeedParams, fromSysParamsStakeCredential, fromSystemParamsAsset, fromSystemParamsAssetLucid, fromSystemParamsScriptRef, getAssetClassComparisonStr, getInlineDatumOrThrow, getPythFeedConfig, getUpdatedAccountDeposit, handleOracleForCollateralAsset, iassetValueOfCollateral, init, initCDPCreator, initCollector, initGovernance, initInterestCollector, initPythConfig, initScriptRef, initSpState, initStakingManager, initSumVal, initTreasury, initializeAsset, insertSorted, isBuyOrderFullyRedeemed, isFullyRedeemed, isSameEpochToScaleKey, leverageCdpWithRob, liquidateCdp, liquidationHelper, loadSystemParamsFromFile, loadSystemParamsFromUrl, matchSingle, mergeCdps, mergeShards, mintAuthTokenDirect, mintCdp, mintOneTimeAsset, mintOneTimeToken, mkAuthTokenPolicy, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkCdpRedeemValidatorFromSP, mkCdpValidatorFromSP, mkCollectorValidatorFromSP, mkExecuteValidator, mkExecuteValidatorFromSP, mkGovValidator, mkGovValidatorFromSP, mkIAssetTokenPolicy, mkIAssetValidatorFromSP, mkInterestCollectionValidator, mkInterestCollectionValidatorFromSP, mkInterestOracleValidator, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkPriceOracleValidator, mkPythFeedValidator, mkRobValidator, mkRobValidatorFromSP, mkSPInteger, mkStabilityPoolAddr, mkStabilityPoolValidator, mkStabilityPoolValidatorFromSP, mkStableswapValidator, mkStableswapValidatorFromSP, mkStakingValidatorFromSP, mkTreasuryAddr, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, oneShotMintTx, openCdp, openRob, openStakingPosition, parseAccountDatum, parseAccountDatumOrThrow, parseCdpDatum, parseCdpDatumOrThrow, parseCdpRedeemer, parseCdpRedeemerOrThrow, parseCollateralAssetDatum, parseCollateralAssetDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestCollectionDatum, parseInterestOracleDatum, parsePollManager, parsePollManagerOrThrow, parsePollShard, parsePollShardOrThrow, parsePollShardRedeemer, parsePollShardRedeemerOrThrow, parsePriceOracleDatum, parsePythStateDatum, parseRobDatum, parseRobDatumOrThrow, parseRobRedeemer, parseRobRedeemerOrThrow, parseSnapshotEpochToScaleToSumDatum, parseSnapshotEpochToScaleToSumDatumOrThrow, parseStabilityPoolDatum, parseStabilityPoolDatumOrThrow, parseStabilityPoolRedeemer, parseStabilityPoolRedeemerOrThrow, parseStableswapOrderDatum, parseStableswapOrderDatumOrThrow, parseStableswapOrderRedeemer, parseStableswapOrderRedeemerOrThrow, parseStableswapPoolDatum, parseStableswapPoolDatumOrThrow, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, parseStakingRedeemer, parseStakingRedeemerOrThrow, partitionEpochToScaleToSums, processSpRequest, randomRobsSubsetSatisfyingTargetCollateral, rationalAdd, rationalCeil, rationalDiv, rationalFloor, rationalFromInt, rationalMul, rationalNegate, rationalSub, rationalToFloat, rationalZero, redeemCdp, redeemRob, repsertReadonlyArr, repsertWithReadonlyArr, requestSpAccountAdjustment, requestSpAccountClosure, requestSpAccountCreation, rewardSnapshotPrecision, robAmtToSpend, robBuyOrderFilledAssets, robBuyOrderSummary, robCollateralAmtToSpend, robIAssetAmtToSpend, robSellOrderFilledAssets, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseActionReturnDatum, serialiseCdpDatum, serialiseCdpRedeemer, serialiseCollectorRedeemer, serialiseExecuteDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseGovRedeemer, serialiseIAssetDatum, serialiseIAssetRedeemer, serialiseInterestCollectionDatum, serialiseInterestCollectionRedeemer, serialiseInterestOracleDatum, serialisePollDatum, serialisePollManagerRedeemer, serialisePollShardRedeemer, serialisePriceOracleDatum, serialisePriceOracleRedeemer, serialisePythFeedParams, serialisePythFeedRedeemer, serialisePythStateDatum, serialisePythUpdatesRedeemer, serialiseRedeemCdpWithdrawalRedeemer, serialiseRobDatum, serialiseRobRedeemer, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, serialiseStableswapOrderDatum, serialiseStableswapOrderRedeemer, serialiseStableswapOutputDatum, serialiseStableswapPoolDatum, serialiseStakingDatum, serialiseStakingRedeemer, shuffle, signersAllOf, spAdd, spDiv, spMul, spSub, spZeroNegatives, startInterestOracle, startPriceOracleTx, submitTx, sum, summarizeActualLeverageRedemptions, toAssetClassFromLucid, toDataDerivedPythPrice, toSystemParamsAsset, treasuryCollect, treasuryFeeTx, treasuryMerge, treasuryPrepareWithdrawal, treasurySplit, updateAccount, updatePermissions, updatePoolStateWhenWithdrawalFee, updateStableswapPoolFees, updateStakingLockedAmount, vote, withdrawCdp, zeroNegatives };
|
package/dist/index.js
CHANGED
|
@@ -52,9 +52,11 @@ __export(index_exports, {
|
|
|
52
52
|
InterestCollectionParamsSchema: () => InterestCollectionParamsSchema,
|
|
53
53
|
InterestOracleDatumSchema: () => InterestOracleDatumSchema,
|
|
54
54
|
InterestOracleParamsSchema: () => InterestOracleParamsSchema,
|
|
55
|
+
MAX_BUY_ROB_REDEMPTIONS_COUNT: () => MAX_BUY_ROB_REDEMPTIONS_COUNT,
|
|
55
56
|
MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET: () => MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET,
|
|
56
57
|
MAX_E2S2S_ENTRIES_COUNT: () => MAX_E2S2S_ENTRIES_COUNT,
|
|
57
58
|
MAX_REDEMPTIONS_WITH_CDP_OPEN: () => MAX_REDEMPTIONS_WITH_CDP_OPEN,
|
|
59
|
+
MAX_SELL_ROB_REDEMPTIONS_COUNT: () => MAX_SELL_ROB_REDEMPTIONS_COUNT,
|
|
58
60
|
MIN_ROB_COLLATERAL_AMT: () => MIN_ROB_COLLATERAL_AMT,
|
|
59
61
|
ONE_DAY: () => ONE_DAY,
|
|
60
62
|
ONE_HOUR: () => ONE_HOUR,
|
|
@@ -104,6 +106,10 @@ __export(index_exports, {
|
|
|
104
106
|
calculateIAssetRedemptionAmt: () => calculateIAssetRedemptionAmt,
|
|
105
107
|
calculateLeverageFromCollateralRatio: () => calculateLeverageFromCollateralRatio,
|
|
106
108
|
calculateMinCollateralCappedIAssetRedemptionAmt: () => calculateMinCollateralCappedIAssetRedemptionAmt,
|
|
109
|
+
calculatePurchaseAmtWhenRobBuyOrder: () => calculatePurchaseAmtWhenRobBuyOrder,
|
|
110
|
+
calculatePurchaseAmtWhenRobSellOrder: () => calculatePurchaseAmtWhenRobSellOrder,
|
|
111
|
+
calculateSpendAmtWhenRobBuyOrder: () => calculateSpendAmtWhenRobBuyOrder,
|
|
112
|
+
calculateSpendAmtWhenRobSellOrder: () => calculateSpendAmtWhenRobSellOrder,
|
|
107
113
|
calculateTotalCollateralForRedemption: () => calculateTotalCollateralForRedemption,
|
|
108
114
|
calculateUnitaryInterest: () => calculateUnitaryInterest,
|
|
109
115
|
calculateUnitaryInterestSinceOracleLastUpdated: () => calculateUnitaryInterestSinceOracleLastUpdated,
|
|
@@ -8647,7 +8653,49 @@ function parseRobRedeemerOrThrow(redeemerCborHex) {
|
|
|
8647
8653
|
var import_fp_ts17 = require("fp-ts");
|
|
8648
8654
|
var import_ts_pattern19 = require("ts-pattern");
|
|
8649
8655
|
var import_cardano_offchain_common22 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
8656
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
8650
8657
|
var MIN_ROB_COLLATERAL_AMT = 3000000n;
|
|
8658
|
+
var MAX_SELL_ROB_REDEMPTIONS_COUNT = 18;
|
|
8659
|
+
var MAX_BUY_ROB_REDEMPTIONS_COUNT = 20;
|
|
8660
|
+
function calculatePurchaseAmtWhenRobBuyOrder(sellIassetAmt, redemptionReimbursementRatio, price) {
|
|
8661
|
+
const reimbursementIAsset = calculateFeeFromRatio(
|
|
8662
|
+
redemptionReimbursementRatio,
|
|
8663
|
+
sellIassetAmt
|
|
8664
|
+
);
|
|
8665
|
+
const collateralForRedemption = rationalFloor(
|
|
8666
|
+
rationalMul(rationalFromInt(sellIassetAmt - reimbursementIAsset), price)
|
|
8667
|
+
);
|
|
8668
|
+
return collateralForRedemption;
|
|
8669
|
+
}
|
|
8670
|
+
function calculateSpendAmtWhenRobBuyOrder(purchaseCollateralAmt, redemptionReimbursementRatio, price) {
|
|
8671
|
+
const priceDecimal = (0, import_decimal.default)(price.numerator).div(price.denominator);
|
|
8672
|
+
const reimbRatio = (0, import_decimal.default)(redemptionReimbursementRatio.numerator).div(
|
|
8673
|
+
redemptionReimbursementRatio.denominator
|
|
8674
|
+
);
|
|
8675
|
+
return fromDecimal(
|
|
8676
|
+
(0, import_decimal.default)(purchaseCollateralAmt).div(priceDecimal).floor().div((0, import_decimal.default)(1).minus(reimbRatio)).floor()
|
|
8677
|
+
);
|
|
8678
|
+
}
|
|
8679
|
+
function calculatePurchaseAmtWhenRobSellOrder(sellCollateralAmt, redemptionReimbursementRatio, price) {
|
|
8680
|
+
const reimbursementCollateral = calculateFeeFromRatio(
|
|
8681
|
+
redemptionReimbursementRatio,
|
|
8682
|
+
sellCollateralAmt
|
|
8683
|
+
);
|
|
8684
|
+
const redeemedIAssetAmt = iassetValueOfCollateral(
|
|
8685
|
+
sellCollateralAmt - reimbursementCollateral,
|
|
8686
|
+
price
|
|
8687
|
+
);
|
|
8688
|
+
return redeemedIAssetAmt;
|
|
8689
|
+
}
|
|
8690
|
+
function calculateSpendAmtWhenRobSellOrder(purchaseIassetAmt, redemptionReimbursementRatio, price) {
|
|
8691
|
+
const priceDecimal = (0, import_decimal.default)(price.numerator).div(price.denominator);
|
|
8692
|
+
const reimbRatio = (0, import_decimal.default)(redemptionReimbursementRatio.numerator).div(
|
|
8693
|
+
redemptionReimbursementRatio.denominator
|
|
8694
|
+
);
|
|
8695
|
+
return fromDecimal(
|
|
8696
|
+
(0, import_decimal.default)(purchaseIassetAmt).mul(priceDecimal).floor().div((0, import_decimal.default)(1).minus(reimbRatio)).floor()
|
|
8697
|
+
);
|
|
8698
|
+
}
|
|
8651
8699
|
function robCollateralAmtToSpend(robAssets, robOrderType) {
|
|
8652
8700
|
return (0, import_ts_pattern19.match)(robOrderType).returnType().with({ BuyIAssetOrder: import_ts_pattern19.P.select() }, (content) => {
|
|
8653
8701
|
if ((0, import_cardano_offchain_common22.isSameAssetClass)(import_cardano_offchain_common22.adaAssetClass, content.collateralAsset)) {
|
|
@@ -8743,15 +8791,10 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8743
8791
|
throw new Error("Only same collateral asset");
|
|
8744
8792
|
}
|
|
8745
8793
|
const payoutIAssetAmt = payoutAmt;
|
|
8746
|
-
const
|
|
8794
|
+
const collateralForRedemption = calculatePurchaseAmtWhenRobBuyOrder(
|
|
8795
|
+
payoutIAssetAmt,
|
|
8747
8796
|
redemptionReimbursementRatio,
|
|
8748
|
-
|
|
8749
|
-
);
|
|
8750
|
-
const collateralForRedemption = rationalFloor(
|
|
8751
|
-
rationalMul(
|
|
8752
|
-
rationalFromInt(payoutIAssetAmt - reimburstmentIAsset),
|
|
8753
|
-
price
|
|
8754
|
-
)
|
|
8797
|
+
price
|
|
8755
8798
|
);
|
|
8756
8799
|
const resultVal = (0, import_lucid49.addAssets)(
|
|
8757
8800
|
robUtxo.assets,
|
|
@@ -8778,12 +8821,9 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8778
8821
|
})
|
|
8779
8822
|
);
|
|
8780
8823
|
const payoutCollateralAmt = payoutAmt;
|
|
8781
|
-
const
|
|
8824
|
+
const redeemedIAssetAmt = calculatePurchaseAmtWhenRobSellOrder(
|
|
8825
|
+
payoutCollateralAmt,
|
|
8782
8826
|
redemptionReimbursementRatio,
|
|
8783
|
-
payoutCollateralAmt
|
|
8784
|
-
);
|
|
8785
|
-
const redeemedIAssetAmt = iassetValueOfCollateral(
|
|
8786
|
-
payoutCollateralAmt - reimbursementCollateral,
|
|
8787
8827
|
price
|
|
8788
8828
|
);
|
|
8789
8829
|
const resultVal = (0, import_lucid49.addAssets)(
|
|
@@ -9225,22 +9265,22 @@ var import_lucid53 = require("@lucid-evolution/lucid");
|
|
|
9225
9265
|
|
|
9226
9266
|
// src/contracts/rob-leverage/helpers.ts
|
|
9227
9267
|
var import_fp_ts19 = require("fp-ts");
|
|
9228
|
-
var
|
|
9268
|
+
var import_decimal2 = require("decimal.js");
|
|
9229
9269
|
var MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
|
|
9230
9270
|
function approximateLeverageRedemptions(baseCollateral, targetLeverage, redemptionReimbursementRatio, debtMintingFeeRatio) {
|
|
9231
|
-
const debtMintingFeeRatioDecimal = (0,
|
|
9271
|
+
const debtMintingFeeRatioDecimal = (0, import_decimal2.Decimal)(debtMintingFeeRatio.numerator).div(
|
|
9232
9272
|
debtMintingFeeRatio.denominator
|
|
9233
9273
|
);
|
|
9234
|
-
const redemptionReimbursementRatioDecimal = (0,
|
|
9274
|
+
const redemptionReimbursementRatioDecimal = (0, import_decimal2.Decimal)(
|
|
9235
9275
|
redemptionReimbursementRatio.numerator
|
|
9236
9276
|
).div(redemptionReimbursementRatio.denominator);
|
|
9237
9277
|
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
9238
9278
|
redemptionReimbursementRatioDecimal
|
|
9239
9279
|
);
|
|
9240
|
-
const bExFees = (0,
|
|
9241
|
-
const b = bExFees.div((0,
|
|
9280
|
+
const bExFees = (0, import_decimal2.Decimal)(baseCollateral).mul(targetLeverage).minus(baseCollateral).floor();
|
|
9281
|
+
const b = bExFees.div((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
9242
9282
|
const collateralRatio = {
|
|
9243
|
-
numerator: fromDecimal((0,
|
|
9283
|
+
numerator: fromDecimal((0, import_decimal2.Decimal)(baseCollateral).add(bExFees)),
|
|
9244
9284
|
denominator: fromDecimal(b)
|
|
9245
9285
|
};
|
|
9246
9286
|
return {
|
|
@@ -9250,12 +9290,6 @@ function approximateLeverageRedemptions(baseCollateral, targetLeverage, redempti
|
|
|
9250
9290
|
};
|
|
9251
9291
|
}
|
|
9252
9292
|
function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement, redemptionReimbursementRatio, iassetPrice, redemptionLrps) {
|
|
9253
|
-
const priceDecimal = (0, import_decimal.Decimal)(iassetPrice.numerator).div(
|
|
9254
|
-
iassetPrice.denominator
|
|
9255
|
-
);
|
|
9256
|
-
const reimbRatio = (0, import_decimal.Decimal)(redemptionReimbursementRatio.numerator).div(
|
|
9257
|
-
redemptionReimbursementRatio.denominator
|
|
9258
|
-
);
|
|
9259
9293
|
const redemptionDetails = import_fp_ts19.function.pipe(
|
|
9260
9294
|
redemptionLrps,
|
|
9261
9295
|
import_fp_ts19.array.reduce(
|
|
@@ -9282,8 +9316,10 @@ function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursem
|
|
|
9282
9316
|
0n
|
|
9283
9317
|
);
|
|
9284
9318
|
const collateralToSpendInitial = acc.remainingCollateralToSpend - newRemainingCollateral;
|
|
9285
|
-
const finalPayoutIAssets =
|
|
9286
|
-
|
|
9319
|
+
const finalPayoutIAssets = calculateSpendAmtWhenRobBuyOrder(
|
|
9320
|
+
collateralToSpendInitial,
|
|
9321
|
+
redemptionReimbursementRatio,
|
|
9322
|
+
iassetPrice
|
|
9287
9323
|
);
|
|
9288
9324
|
const feeIAssetAmt = calculateFeeFromRatio(
|
|
9289
9325
|
redemptionReimbursementRatio,
|
|
@@ -9335,10 +9371,10 @@ function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursem
|
|
|
9335
9371
|
};
|
|
9336
9372
|
}
|
|
9337
9373
|
function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage, baseCollateral, iassetPrice, debtMintingFeePercentage, redemptionReimbursementPercentage, allLrps) {
|
|
9338
|
-
const debtMintingFeeRatioDecimal = (0,
|
|
9374
|
+
const debtMintingFeeRatioDecimal = (0, import_decimal2.Decimal)(
|
|
9339
9375
|
debtMintingFeePercentage.getOnChainInt
|
|
9340
9376
|
).div(OCD_DECIMAL_UNIT).div(100);
|
|
9341
|
-
const redemptionReimbursementRatioDecimal = (0,
|
|
9377
|
+
const redemptionReimbursementRatioDecimal = (0, import_decimal2.Decimal)(
|
|
9342
9378
|
redemptionReimbursementPercentage.getOnChainInt
|
|
9343
9379
|
).div(OCD_DECIMAL_UNIT).div(100);
|
|
9344
9380
|
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
@@ -9354,15 +9390,15 @@ function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage,
|
|
|
9354
9390
|
if (leverage <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
|
|
9355
9391
|
return void 0;
|
|
9356
9392
|
}
|
|
9357
|
-
const bExFees = (0,
|
|
9358
|
-
const b = bExFees.div((0,
|
|
9393
|
+
const bExFees = (0, import_decimal2.Decimal)(baseCollateral).mul(leverage).minus(baseCollateral).floor();
|
|
9394
|
+
const b = bExFees.div((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
9359
9395
|
const cappedB = bigintMin(
|
|
9360
9396
|
maxAvailableCollateralForRedemption,
|
|
9361
9397
|
fromDecimal(b)
|
|
9362
9398
|
);
|
|
9363
|
-
const cappedBExFees = (0,
|
|
9364
|
-
const collateralRatio = (0,
|
|
9365
|
-
(0,
|
|
9399
|
+
const cappedBExFees = (0, import_decimal2.Decimal)(cappedB).mul((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
9400
|
+
const collateralRatio = (0, import_decimal2.Decimal)(
|
|
9401
|
+
(0, import_decimal2.Decimal)(baseCollateral).add(cappedBExFees)
|
|
9366
9402
|
).div(cappedB);
|
|
9367
9403
|
return {
|
|
9368
9404
|
getOnChainInt: fromDecimal(
|
|
@@ -9371,16 +9407,16 @@ function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage,
|
|
|
9371
9407
|
};
|
|
9372
9408
|
}
|
|
9373
9409
|
function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collateralRatio, baseCollateral, iassetPrice, debtMintingFeeRatio, redemptionReimbursementRatio, allLrps) {
|
|
9374
|
-
const debtMintingFeeRatioDecimal = (0,
|
|
9410
|
+
const debtMintingFeeRatioDecimal = (0, import_decimal2.Decimal)(debtMintingFeeRatio.numerator).div(
|
|
9375
9411
|
debtMintingFeeRatio.denominator
|
|
9376
9412
|
);
|
|
9377
|
-
const redemptionReimbursementRatioDecimal = (0,
|
|
9413
|
+
const redemptionReimbursementRatioDecimal = (0, import_decimal2.Decimal)(
|
|
9378
9414
|
redemptionReimbursementRatio.numerator
|
|
9379
9415
|
).div(redemptionReimbursementRatio.denominator);
|
|
9380
9416
|
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
9381
9417
|
redemptionReimbursementRatioDecimal
|
|
9382
9418
|
);
|
|
9383
|
-
const collateralRatioDecimal = (0,
|
|
9419
|
+
const collateralRatioDecimal = (0, import_decimal2.Decimal)(collateralRatio.numerator).div(
|
|
9384
9420
|
collateralRatio.denominator
|
|
9385
9421
|
);
|
|
9386
9422
|
const maxAvailableCollateralForRedemption = calculateTotalCollateralForRedemption(
|
|
@@ -9393,20 +9429,20 @@ function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collatera
|
|
|
9393
9429
|
if (collateralRatioDecimal.toNumber() <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
|
|
9394
9430
|
return void 0;
|
|
9395
9431
|
}
|
|
9396
|
-
const theoreticalMaxLeverage = (0,
|
|
9432
|
+
const theoreticalMaxLeverage = (0, import_decimal2.Decimal)((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).div(collateralRatioDecimal.minus(1).add(totalFeeRatio)).add(1);
|
|
9397
9433
|
const bExFees = theoreticalMaxLeverage.mul(baseCollateral).minus(baseCollateral).floor();
|
|
9398
|
-
const b = bExFees.div((0,
|
|
9434
|
+
const b = bExFees.div((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
9399
9435
|
const cappedB = bigintMin(
|
|
9400
9436
|
maxAvailableCollateralForRedemption,
|
|
9401
9437
|
fromDecimal(b)
|
|
9402
9438
|
);
|
|
9403
|
-
const cappedBExFees = (0,
|
|
9404
|
-
return (0,
|
|
9439
|
+
const cappedBExFees = (0, import_decimal2.Decimal)(cappedB).mul((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
9440
|
+
return (0, import_decimal2.Decimal)(baseCollateral).add(cappedBExFees).div(baseCollateral).toNumber();
|
|
9405
9441
|
}
|
|
9406
9442
|
|
|
9407
9443
|
// src/contracts/rob-leverage/transactions.ts
|
|
9408
9444
|
var import_cardano_offchain_common24 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
9409
|
-
var
|
|
9445
|
+
var import_decimal3 = __toESM(require("decimal.js"));
|
|
9410
9446
|
async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, cdpCreatorOref, interestOracleOref, treasuryOref, sysParams, lucid, allRobs, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
|
|
9411
9447
|
const network = lucid.config().network;
|
|
9412
9448
|
const currentTime = BigInt((0, import_lucid53.slotToUnixTime)(network, currentSlot));
|
|
@@ -9517,9 +9553,9 @@ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, i
|
|
|
9517
9553
|
)
|
|
9518
9554
|
);
|
|
9519
9555
|
const mintedAmt = fromDecimal(
|
|
9520
|
-
(0,
|
|
9521
|
-
(0,
|
|
9522
|
-
(0,
|
|
9556
|
+
(0, import_decimal3.default)(redemptionDetails.totalIAssetPayout).div(
|
|
9557
|
+
(0, import_decimal3.default)(1).minus(
|
|
9558
|
+
(0, import_decimal3.default)(iassetDatum.debtMintingFeeRatio.numerator).div(
|
|
9523
9559
|
iassetDatum.debtMintingFeeRatio.denominator
|
|
9524
9560
|
)
|
|
9525
9561
|
)
|
|
@@ -11539,9 +11575,11 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
11539
11575
|
InterestCollectionParamsSchema,
|
|
11540
11576
|
InterestOracleDatumSchema,
|
|
11541
11577
|
InterestOracleParamsSchema,
|
|
11578
|
+
MAX_BUY_ROB_REDEMPTIONS_COUNT,
|
|
11542
11579
|
MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET,
|
|
11543
11580
|
MAX_E2S2S_ENTRIES_COUNT,
|
|
11544
11581
|
MAX_REDEMPTIONS_WITH_CDP_OPEN,
|
|
11582
|
+
MAX_SELL_ROB_REDEMPTIONS_COUNT,
|
|
11545
11583
|
MIN_ROB_COLLATERAL_AMT,
|
|
11546
11584
|
ONE_DAY,
|
|
11547
11585
|
ONE_HOUR,
|
|
@@ -11591,6 +11629,10 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
11591
11629
|
calculateIAssetRedemptionAmt,
|
|
11592
11630
|
calculateLeverageFromCollateralRatio,
|
|
11593
11631
|
calculateMinCollateralCappedIAssetRedemptionAmt,
|
|
11632
|
+
calculatePurchaseAmtWhenRobBuyOrder,
|
|
11633
|
+
calculatePurchaseAmtWhenRobSellOrder,
|
|
11634
|
+
calculateSpendAmtWhenRobBuyOrder,
|
|
11635
|
+
calculateSpendAmtWhenRobSellOrder,
|
|
11594
11636
|
calculateTotalCollateralForRedemption,
|
|
11595
11637
|
calculateUnitaryInterest,
|
|
11596
11638
|
calculateUnitaryInterestSinceOracleLastUpdated,
|
package/dist/index.mjs
CHANGED
|
@@ -8482,7 +8482,49 @@ import {
|
|
|
8482
8482
|
lovelacesAmt as lovelacesAmt3,
|
|
8483
8483
|
mkAssetsOf as mkAssetsOf9
|
|
8484
8484
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
8485
|
+
import Decimal from "decimal.js";
|
|
8485
8486
|
var MIN_ROB_COLLATERAL_AMT = 3000000n;
|
|
8487
|
+
var MAX_SELL_ROB_REDEMPTIONS_COUNT = 18;
|
|
8488
|
+
var MAX_BUY_ROB_REDEMPTIONS_COUNT = 20;
|
|
8489
|
+
function calculatePurchaseAmtWhenRobBuyOrder(sellIassetAmt, redemptionReimbursementRatio, price) {
|
|
8490
|
+
const reimbursementIAsset = calculateFeeFromRatio(
|
|
8491
|
+
redemptionReimbursementRatio,
|
|
8492
|
+
sellIassetAmt
|
|
8493
|
+
);
|
|
8494
|
+
const collateralForRedemption = rationalFloor(
|
|
8495
|
+
rationalMul(rationalFromInt(sellIassetAmt - reimbursementIAsset), price)
|
|
8496
|
+
);
|
|
8497
|
+
return collateralForRedemption;
|
|
8498
|
+
}
|
|
8499
|
+
function calculateSpendAmtWhenRobBuyOrder(purchaseCollateralAmt, redemptionReimbursementRatio, price) {
|
|
8500
|
+
const priceDecimal = Decimal(price.numerator).div(price.denominator);
|
|
8501
|
+
const reimbRatio = Decimal(redemptionReimbursementRatio.numerator).div(
|
|
8502
|
+
redemptionReimbursementRatio.denominator
|
|
8503
|
+
);
|
|
8504
|
+
return fromDecimal(
|
|
8505
|
+
Decimal(purchaseCollateralAmt).div(priceDecimal).floor().div(Decimal(1).minus(reimbRatio)).floor()
|
|
8506
|
+
);
|
|
8507
|
+
}
|
|
8508
|
+
function calculatePurchaseAmtWhenRobSellOrder(sellCollateralAmt, redemptionReimbursementRatio, price) {
|
|
8509
|
+
const reimbursementCollateral = calculateFeeFromRatio(
|
|
8510
|
+
redemptionReimbursementRatio,
|
|
8511
|
+
sellCollateralAmt
|
|
8512
|
+
);
|
|
8513
|
+
const redeemedIAssetAmt = iassetValueOfCollateral(
|
|
8514
|
+
sellCollateralAmt - reimbursementCollateral,
|
|
8515
|
+
price
|
|
8516
|
+
);
|
|
8517
|
+
return redeemedIAssetAmt;
|
|
8518
|
+
}
|
|
8519
|
+
function calculateSpendAmtWhenRobSellOrder(purchaseIassetAmt, redemptionReimbursementRatio, price) {
|
|
8520
|
+
const priceDecimal = Decimal(price.numerator).div(price.denominator);
|
|
8521
|
+
const reimbRatio = Decimal(redemptionReimbursementRatio.numerator).div(
|
|
8522
|
+
redemptionReimbursementRatio.denominator
|
|
8523
|
+
);
|
|
8524
|
+
return fromDecimal(
|
|
8525
|
+
Decimal(purchaseIassetAmt).mul(priceDecimal).floor().div(Decimal(1).minus(reimbRatio)).floor()
|
|
8526
|
+
);
|
|
8527
|
+
}
|
|
8486
8528
|
function robCollateralAmtToSpend(robAssets, robOrderType) {
|
|
8487
8529
|
return match18(robOrderType).returnType().with({ BuyIAssetOrder: P18.select() }, (content) => {
|
|
8488
8530
|
if (isSameAssetClass3(adaAssetClass5, content.collateralAsset)) {
|
|
@@ -8578,15 +8620,10 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8578
8620
|
throw new Error("Only same collateral asset");
|
|
8579
8621
|
}
|
|
8580
8622
|
const payoutIAssetAmt = payoutAmt;
|
|
8581
|
-
const
|
|
8623
|
+
const collateralForRedemption = calculatePurchaseAmtWhenRobBuyOrder(
|
|
8624
|
+
payoutIAssetAmt,
|
|
8582
8625
|
redemptionReimbursementRatio,
|
|
8583
|
-
|
|
8584
|
-
);
|
|
8585
|
-
const collateralForRedemption = rationalFloor(
|
|
8586
|
-
rationalMul(
|
|
8587
|
-
rationalFromInt(payoutIAssetAmt - reimburstmentIAsset),
|
|
8588
|
-
price
|
|
8589
|
-
)
|
|
8626
|
+
price
|
|
8590
8627
|
);
|
|
8591
8628
|
const resultVal = addAssets12(
|
|
8592
8629
|
robUtxo.assets,
|
|
@@ -8613,12 +8650,9 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8613
8650
|
})
|
|
8614
8651
|
);
|
|
8615
8652
|
const payoutCollateralAmt = payoutAmt;
|
|
8616
|
-
const
|
|
8653
|
+
const redeemedIAssetAmt = calculatePurchaseAmtWhenRobSellOrder(
|
|
8654
|
+
payoutCollateralAmt,
|
|
8617
8655
|
redemptionReimbursementRatio,
|
|
8618
|
-
payoutCollateralAmt
|
|
8619
|
-
);
|
|
8620
|
-
const redeemedIAssetAmt = iassetValueOfCollateral(
|
|
8621
|
-
payoutCollateralAmt - reimbursementCollateral,
|
|
8622
8656
|
price
|
|
8623
8657
|
);
|
|
8624
8658
|
const resultVal = addAssets12(
|
|
@@ -9084,22 +9118,22 @@ import {
|
|
|
9084
9118
|
|
|
9085
9119
|
// src/contracts/rob-leverage/helpers.ts
|
|
9086
9120
|
import { array as A11, function as F18 } from "fp-ts";
|
|
9087
|
-
import { Decimal } from "decimal.js";
|
|
9121
|
+
import { Decimal as Decimal2 } from "decimal.js";
|
|
9088
9122
|
var MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
|
|
9089
9123
|
function approximateLeverageRedemptions(baseCollateral, targetLeverage, redemptionReimbursementRatio, debtMintingFeeRatio) {
|
|
9090
|
-
const debtMintingFeeRatioDecimal =
|
|
9124
|
+
const debtMintingFeeRatioDecimal = Decimal2(debtMintingFeeRatio.numerator).div(
|
|
9091
9125
|
debtMintingFeeRatio.denominator
|
|
9092
9126
|
);
|
|
9093
|
-
const redemptionReimbursementRatioDecimal =
|
|
9127
|
+
const redemptionReimbursementRatioDecimal = Decimal2(
|
|
9094
9128
|
redemptionReimbursementRatio.numerator
|
|
9095
9129
|
).div(redemptionReimbursementRatio.denominator);
|
|
9096
9130
|
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
9097
9131
|
redemptionReimbursementRatioDecimal
|
|
9098
9132
|
);
|
|
9099
|
-
const bExFees =
|
|
9100
|
-
const b = bExFees.div(
|
|
9133
|
+
const bExFees = Decimal2(baseCollateral).mul(targetLeverage).minus(baseCollateral).floor();
|
|
9134
|
+
const b = bExFees.div(Decimal2(1).minus(totalFeeRatio)).floor();
|
|
9101
9135
|
const collateralRatio = {
|
|
9102
|
-
numerator: fromDecimal(
|
|
9136
|
+
numerator: fromDecimal(Decimal2(baseCollateral).add(bExFees)),
|
|
9103
9137
|
denominator: fromDecimal(b)
|
|
9104
9138
|
};
|
|
9105
9139
|
return {
|
|
@@ -9109,12 +9143,6 @@ function approximateLeverageRedemptions(baseCollateral, targetLeverage, redempti
|
|
|
9109
9143
|
};
|
|
9110
9144
|
}
|
|
9111
9145
|
function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement, redemptionReimbursementRatio, iassetPrice, redemptionLrps) {
|
|
9112
|
-
const priceDecimal = Decimal(iassetPrice.numerator).div(
|
|
9113
|
-
iassetPrice.denominator
|
|
9114
|
-
);
|
|
9115
|
-
const reimbRatio = Decimal(redemptionReimbursementRatio.numerator).div(
|
|
9116
|
-
redemptionReimbursementRatio.denominator
|
|
9117
|
-
);
|
|
9118
9146
|
const redemptionDetails = F18.pipe(
|
|
9119
9147
|
redemptionLrps,
|
|
9120
9148
|
A11.reduce(
|
|
@@ -9141,8 +9169,10 @@ function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursem
|
|
|
9141
9169
|
0n
|
|
9142
9170
|
);
|
|
9143
9171
|
const collateralToSpendInitial = acc.remainingCollateralToSpend - newRemainingCollateral;
|
|
9144
|
-
const finalPayoutIAssets =
|
|
9145
|
-
|
|
9172
|
+
const finalPayoutIAssets = calculateSpendAmtWhenRobBuyOrder(
|
|
9173
|
+
collateralToSpendInitial,
|
|
9174
|
+
redemptionReimbursementRatio,
|
|
9175
|
+
iassetPrice
|
|
9146
9176
|
);
|
|
9147
9177
|
const feeIAssetAmt = calculateFeeFromRatio(
|
|
9148
9178
|
redemptionReimbursementRatio,
|
|
@@ -9194,10 +9224,10 @@ function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursem
|
|
|
9194
9224
|
};
|
|
9195
9225
|
}
|
|
9196
9226
|
function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage, baseCollateral, iassetPrice, debtMintingFeePercentage, redemptionReimbursementPercentage, allLrps) {
|
|
9197
|
-
const debtMintingFeeRatioDecimal =
|
|
9227
|
+
const debtMintingFeeRatioDecimal = Decimal2(
|
|
9198
9228
|
debtMintingFeePercentage.getOnChainInt
|
|
9199
9229
|
).div(OCD_DECIMAL_UNIT).div(100);
|
|
9200
|
-
const redemptionReimbursementRatioDecimal =
|
|
9230
|
+
const redemptionReimbursementRatioDecimal = Decimal2(
|
|
9201
9231
|
redemptionReimbursementPercentage.getOnChainInt
|
|
9202
9232
|
).div(OCD_DECIMAL_UNIT).div(100);
|
|
9203
9233
|
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
@@ -9213,15 +9243,15 @@ function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage,
|
|
|
9213
9243
|
if (leverage <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
|
|
9214
9244
|
return void 0;
|
|
9215
9245
|
}
|
|
9216
|
-
const bExFees =
|
|
9217
|
-
const b = bExFees.div(
|
|
9246
|
+
const bExFees = Decimal2(baseCollateral).mul(leverage).minus(baseCollateral).floor();
|
|
9247
|
+
const b = bExFees.div(Decimal2(1).minus(totalFeeRatio)).floor();
|
|
9218
9248
|
const cappedB = bigintMin(
|
|
9219
9249
|
maxAvailableCollateralForRedemption,
|
|
9220
9250
|
fromDecimal(b)
|
|
9221
9251
|
);
|
|
9222
|
-
const cappedBExFees =
|
|
9223
|
-
const collateralRatio =
|
|
9224
|
-
|
|
9252
|
+
const cappedBExFees = Decimal2(cappedB).mul(Decimal2(1).minus(totalFeeRatio)).floor();
|
|
9253
|
+
const collateralRatio = Decimal2(
|
|
9254
|
+
Decimal2(baseCollateral).add(cappedBExFees)
|
|
9225
9255
|
).div(cappedB);
|
|
9226
9256
|
return {
|
|
9227
9257
|
getOnChainInt: fromDecimal(
|
|
@@ -9230,16 +9260,16 @@ function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage,
|
|
|
9230
9260
|
};
|
|
9231
9261
|
}
|
|
9232
9262
|
function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collateralRatio, baseCollateral, iassetPrice, debtMintingFeeRatio, redemptionReimbursementRatio, allLrps) {
|
|
9233
|
-
const debtMintingFeeRatioDecimal =
|
|
9263
|
+
const debtMintingFeeRatioDecimal = Decimal2(debtMintingFeeRatio.numerator).div(
|
|
9234
9264
|
debtMintingFeeRatio.denominator
|
|
9235
9265
|
);
|
|
9236
|
-
const redemptionReimbursementRatioDecimal =
|
|
9266
|
+
const redemptionReimbursementRatioDecimal = Decimal2(
|
|
9237
9267
|
redemptionReimbursementRatio.numerator
|
|
9238
9268
|
).div(redemptionReimbursementRatio.denominator);
|
|
9239
9269
|
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
9240
9270
|
redemptionReimbursementRatioDecimal
|
|
9241
9271
|
);
|
|
9242
|
-
const collateralRatioDecimal =
|
|
9272
|
+
const collateralRatioDecimal = Decimal2(collateralRatio.numerator).div(
|
|
9243
9273
|
collateralRatio.denominator
|
|
9244
9274
|
);
|
|
9245
9275
|
const maxAvailableCollateralForRedemption = calculateTotalCollateralForRedemption(
|
|
@@ -9252,20 +9282,20 @@ function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collatera
|
|
|
9252
9282
|
if (collateralRatioDecimal.toNumber() <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
|
|
9253
9283
|
return void 0;
|
|
9254
9284
|
}
|
|
9255
|
-
const theoreticalMaxLeverage =
|
|
9285
|
+
const theoreticalMaxLeverage = Decimal2(Decimal2(1).minus(totalFeeRatio)).div(collateralRatioDecimal.minus(1).add(totalFeeRatio)).add(1);
|
|
9256
9286
|
const bExFees = theoreticalMaxLeverage.mul(baseCollateral).minus(baseCollateral).floor();
|
|
9257
|
-
const b = bExFees.div(
|
|
9287
|
+
const b = bExFees.div(Decimal2(1).minus(totalFeeRatio)).floor();
|
|
9258
9288
|
const cappedB = bigintMin(
|
|
9259
9289
|
maxAvailableCollateralForRedemption,
|
|
9260
9290
|
fromDecimal(b)
|
|
9261
9291
|
);
|
|
9262
|
-
const cappedBExFees =
|
|
9263
|
-
return
|
|
9292
|
+
const cappedBExFees = Decimal2(cappedB).mul(Decimal2(1).minus(totalFeeRatio)).floor();
|
|
9293
|
+
return Decimal2(baseCollateral).add(cappedBExFees).div(baseCollateral).toNumber();
|
|
9264
9294
|
}
|
|
9265
9295
|
|
|
9266
9296
|
// src/contracts/rob-leverage/transactions.ts
|
|
9267
9297
|
import { mkAssetsOf as mkAssetsOf11 } from "@3rd-eye-labs/cardano-offchain-common";
|
|
9268
|
-
import
|
|
9298
|
+
import Decimal3 from "decimal.js";
|
|
9269
9299
|
async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, cdpCreatorOref, interestOracleOref, treasuryOref, sysParams, lucid, allRobs, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
|
|
9270
9300
|
const network = lucid.config().network;
|
|
9271
9301
|
const currentTime = BigInt(slotToUnixTime10(network, currentSlot));
|
|
@@ -9376,9 +9406,9 @@ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, i
|
|
|
9376
9406
|
)
|
|
9377
9407
|
);
|
|
9378
9408
|
const mintedAmt = fromDecimal(
|
|
9379
|
-
|
|
9380
|
-
|
|
9381
|
-
|
|
9409
|
+
Decimal3(redemptionDetails.totalIAssetPayout).div(
|
|
9410
|
+
Decimal3(1).minus(
|
|
9411
|
+
Decimal3(iassetDatum.debtMintingFeeRatio.numerator).div(
|
|
9382
9412
|
iassetDatum.debtMintingFeeRatio.denominator
|
|
9383
9413
|
)
|
|
9384
9414
|
)
|
|
@@ -11471,9 +11501,11 @@ export {
|
|
|
11471
11501
|
InterestCollectionParamsSchema,
|
|
11472
11502
|
InterestOracleDatumSchema,
|
|
11473
11503
|
InterestOracleParamsSchema,
|
|
11504
|
+
MAX_BUY_ROB_REDEMPTIONS_COUNT,
|
|
11474
11505
|
MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET,
|
|
11475
11506
|
MAX_E2S2S_ENTRIES_COUNT,
|
|
11476
11507
|
MAX_REDEMPTIONS_WITH_CDP_OPEN,
|
|
11508
|
+
MAX_SELL_ROB_REDEMPTIONS_COUNT,
|
|
11477
11509
|
MIN_ROB_COLLATERAL_AMT,
|
|
11478
11510
|
ONE_DAY,
|
|
11479
11511
|
ONE_HOUR,
|
|
@@ -11523,6 +11555,10 @@ export {
|
|
|
11523
11555
|
calculateIAssetRedemptionAmt,
|
|
11524
11556
|
calculateLeverageFromCollateralRatio,
|
|
11525
11557
|
calculateMinCollateralCappedIAssetRedemptionAmt,
|
|
11558
|
+
calculatePurchaseAmtWhenRobBuyOrder,
|
|
11559
|
+
calculatePurchaseAmtWhenRobSellOrder,
|
|
11560
|
+
calculateSpendAmtWhenRobBuyOrder,
|
|
11561
|
+
calculateSpendAmtWhenRobSellOrder,
|
|
11526
11562
|
calculateTotalCollateralForRedemption,
|
|
11527
11563
|
calculateUnitaryInterest,
|
|
11528
11564
|
calculateUnitaryInterestSinceOracleLastUpdated,
|
package/package.json
CHANGED
|
@@ -14,7 +14,12 @@ import {
|
|
|
14
14
|
serialiseRobRedeemer,
|
|
15
15
|
} from './types-new';
|
|
16
16
|
import { calculateFeeFromRatio } from '../../utils/indigo-helpers';
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
BigIntOrd,
|
|
19
|
+
fromDecimal,
|
|
20
|
+
sum,
|
|
21
|
+
zeroNegatives,
|
|
22
|
+
} from '../../utils/bigint-utils';
|
|
18
23
|
import {
|
|
19
24
|
readonlyArray as RA,
|
|
20
25
|
array as A,
|
|
@@ -43,9 +48,117 @@ import {
|
|
|
43
48
|
import { insertSorted, shuffle } from '../../utils/array-utils';
|
|
44
49
|
import { iassetValueOfCollateral } from '../cdp/helpers';
|
|
45
50
|
import { OracleIdx } from '../price-oracle/types-new';
|
|
51
|
+
import Decimal from 'decimal.js';
|
|
46
52
|
|
|
47
53
|
export const MIN_ROB_COLLATERAL_AMT = 3_000_000n;
|
|
48
54
|
|
|
55
|
+
/**
|
|
56
|
+
* The maximum of redemptions for a Tx that is doing only sell order redemptions.
|
|
57
|
+
* Based on the benchmarks.
|
|
58
|
+
*/
|
|
59
|
+
export const MAX_SELL_ROB_REDEMPTIONS_COUNT = 18;
|
|
60
|
+
/**
|
|
61
|
+
* The maximum of redemptions for a Tx that is doing only buy order redemptions.
|
|
62
|
+
* Based on the benchmarks.
|
|
63
|
+
*/
|
|
64
|
+
export const MAX_BUY_ROB_REDEMPTIONS_COUNT = 20;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Helper for ROB redemptions. A redeemer is selling iAssets against
|
|
68
|
+
* a buy order, i.e. buying a collateral asset.
|
|
69
|
+
* The return is the amount of collateral asset he buys.
|
|
70
|
+
*/
|
|
71
|
+
export function calculatePurchaseAmtWhenRobBuyOrder(
|
|
72
|
+
sellIassetAmt: bigint,
|
|
73
|
+
redemptionReimbursementRatio: Rational,
|
|
74
|
+
price: Rational,
|
|
75
|
+
): bigint {
|
|
76
|
+
const reimbursementIAsset = calculateFeeFromRatio(
|
|
77
|
+
redemptionReimbursementRatio,
|
|
78
|
+
sellIassetAmt,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const collateralForRedemption = rationalFloor(
|
|
82
|
+
rationalMul(rationalFromInt(sellIassetAmt - reimbursementIAsset), price),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return collateralForRedemption;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A redeemer is purchasing given collateral amount against buy order.
|
|
90
|
+
* Calculate what is the amount of iAsset the user sells/spends.
|
|
91
|
+
*/
|
|
92
|
+
export function calculateSpendAmtWhenRobBuyOrder(
|
|
93
|
+
purchaseCollateralAmt: bigint,
|
|
94
|
+
redemptionReimbursementRatio: Rational,
|
|
95
|
+
price: Rational,
|
|
96
|
+
): bigint {
|
|
97
|
+
const priceDecimal = Decimal(price.numerator).div(price.denominator);
|
|
98
|
+
const reimbRatio = Decimal(redemptionReimbursementRatio.numerator).div(
|
|
99
|
+
redemptionReimbursementRatio.denominator,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// TODO: make corrections here in case we can be ceiling this number instead.
|
|
103
|
+
// We want to be flooring here so that we don't go over the collateral to spend.
|
|
104
|
+
// Flooring multiple times is necessary here otherwise we could go over the collateral available.
|
|
105
|
+
// iassets = floor(collateral / price) / floor(1 - reimbursement fee)
|
|
106
|
+
return fromDecimal(
|
|
107
|
+
Decimal(purchaseCollateralAmt)
|
|
108
|
+
.div(priceDecimal)
|
|
109
|
+
.floor()
|
|
110
|
+
.div(Decimal(1).minus(reimbRatio))
|
|
111
|
+
.floor(),
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Helper for ROB redemptions. A redeemer is selling collateral against
|
|
117
|
+
* a sell order, i.e. buying iassets.
|
|
118
|
+
* The return is the amount of iassets he buys.
|
|
119
|
+
*/
|
|
120
|
+
export function calculatePurchaseAmtWhenRobSellOrder(
|
|
121
|
+
sellCollateralAmt: bigint,
|
|
122
|
+
redemptionReimbursementRatio: Rational,
|
|
123
|
+
price: Rational,
|
|
124
|
+
): bigint {
|
|
125
|
+
const reimbursementCollateral = calculateFeeFromRatio(
|
|
126
|
+
redemptionReimbursementRatio,
|
|
127
|
+
sellCollateralAmt,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const redeemedIAssetAmt = iassetValueOfCollateral(
|
|
131
|
+
sellCollateralAmt - reimbursementCollateral,
|
|
132
|
+
price,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
return redeemedIAssetAmt;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* A redeemer is purchasing given iasset amount against sell order.
|
|
140
|
+
* Calculate what is the amount of collateral the user sells/spends.
|
|
141
|
+
*/
|
|
142
|
+
export function calculateSpendAmtWhenRobSellOrder(
|
|
143
|
+
purchaseIassetAmt: bigint,
|
|
144
|
+
redemptionReimbursementRatio: Rational,
|
|
145
|
+
price: Rational,
|
|
146
|
+
): bigint {
|
|
147
|
+
const priceDecimal = Decimal(price.numerator).div(price.denominator);
|
|
148
|
+
const reimbRatio = Decimal(redemptionReimbursementRatio.numerator).div(
|
|
149
|
+
redemptionReimbursementRatio.denominator,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
// collateral = floor(iasset * price) / floor(1 - reimbursement fee)
|
|
153
|
+
return fromDecimal(
|
|
154
|
+
Decimal(purchaseIassetAmt)
|
|
155
|
+
.mul(priceDecimal)
|
|
156
|
+
.floor()
|
|
157
|
+
.div(Decimal(1).minus(reimbRatio))
|
|
158
|
+
.floor(),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
49
162
|
/**
|
|
50
163
|
* The amount of collateral asset available in the ROB when buy order. In case of ADA, take
|
|
51
164
|
* into account the min UTXO collateral.
|
|
@@ -181,6 +294,7 @@ export function robBuyOrderSummary(
|
|
|
181
294
|
} {
|
|
182
295
|
const redeemable = robCollateralAmtToSpend(robAssets, robOrderType);
|
|
183
296
|
|
|
297
|
+
// TODO: this is incorrect since it doesn't take into account the reimbursement ratio.
|
|
184
298
|
const payoutAmt = iassetValueOfCollateral(redeemable, oraclePrice);
|
|
185
299
|
|
|
186
300
|
return {
|
|
@@ -286,16 +400,10 @@ export function buildRedemptionsTx(
|
|
|
286
400
|
|
|
287
401
|
const payoutIAssetAmt = payoutAmt;
|
|
288
402
|
|
|
289
|
-
const
|
|
290
|
-
redemptionReimbursementRatio,
|
|
403
|
+
const collateralForRedemption = calculatePurchaseAmtWhenRobBuyOrder(
|
|
291
404
|
payoutIAssetAmt,
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const collateralForRedemption = rationalFloor(
|
|
295
|
-
rationalMul(
|
|
296
|
-
rationalFromInt(payoutIAssetAmt - reimburstmentIAsset),
|
|
297
|
-
price,
|
|
298
|
-
),
|
|
405
|
+
redemptionReimbursementRatio,
|
|
406
|
+
price,
|
|
299
407
|
);
|
|
300
408
|
|
|
301
409
|
const resultVal = addAssets(
|
|
@@ -327,13 +435,9 @@ export function buildRedemptionsTx(
|
|
|
327
435
|
|
|
328
436
|
const payoutCollateralAmt = payoutAmt;
|
|
329
437
|
|
|
330
|
-
const
|
|
331
|
-
redemptionReimbursementRatio,
|
|
438
|
+
const redeemedIAssetAmt = calculatePurchaseAmtWhenRobSellOrder(
|
|
332
439
|
payoutCollateralAmt,
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const redeemedIAssetAmt = iassetValueOfCollateral(
|
|
336
|
-
payoutCollateralAmt - reimbursementCollateral,
|
|
440
|
+
redemptionReimbursementRatio,
|
|
337
441
|
price,
|
|
338
442
|
);
|
|
339
443
|
|
|
@@ -57,6 +57,7 @@ import { bigintMax, bigintMin, fromDecimal } from '../../utils/bigint-utils';
|
|
|
57
57
|
import { array as A, function as F } from 'fp-ts';
|
|
58
58
|
import { Decimal } from 'decimal.js';
|
|
59
59
|
import {
|
|
60
|
+
calculateSpendAmtWhenRobBuyOrder,
|
|
60
61
|
calculateTotalCollateralForRedemption,
|
|
61
62
|
robCollateralAmtToSpend,
|
|
62
63
|
} from '../rob/helpers';
|
|
@@ -160,20 +161,12 @@ export function summarizeActualLeverageRedemptions(
|
|
|
160
161
|
*/
|
|
161
162
|
totalIAssetPayout: bigint;
|
|
162
163
|
} {
|
|
163
|
-
const priceDecimal = Decimal(iassetPrice.numerator).div(
|
|
164
|
-
iassetPrice.denominator,
|
|
165
|
-
);
|
|
166
|
-
|
|
167
164
|
type Accumulator = {
|
|
168
165
|
/// The remaining collateral to spend from ROBs
|
|
169
166
|
remainingCollateralToSpend: bigint;
|
|
170
167
|
redemptions: ROBRedemptionDetails[];
|
|
171
168
|
};
|
|
172
169
|
|
|
173
|
-
const reimbRatio = Decimal(redemptionReimbursementRatio.numerator).div(
|
|
174
|
-
redemptionReimbursementRatio.denominator,
|
|
175
|
-
);
|
|
176
|
-
|
|
177
170
|
const redemptionDetails = F.pipe(
|
|
178
171
|
redemptionLrps,
|
|
179
172
|
A.reduce<[UTxO, RobDatum], Accumulator>(
|
|
@@ -208,16 +201,10 @@ export function summarizeActualLeverageRedemptions(
|
|
|
208
201
|
const collateralToSpendInitial =
|
|
209
202
|
acc.remainingCollateralToSpend - newRemainingCollateral;
|
|
210
203
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const finalPayoutIAssets = fromDecimal(
|
|
216
|
-
Decimal(collateralToSpendInitial)
|
|
217
|
-
.div(priceDecimal)
|
|
218
|
-
.floor()
|
|
219
|
-
.div(Decimal(1).minus(reimbRatio))
|
|
220
|
-
.floor(),
|
|
204
|
+
const finalPayoutIAssets = calculateSpendAmtWhenRobBuyOrder(
|
|
205
|
+
collateralToSpendInitial,
|
|
206
|
+
redemptionReimbursementRatio,
|
|
207
|
+
iassetPrice,
|
|
221
208
|
);
|
|
222
209
|
|
|
223
210
|
const feeIAssetAmt = calculateFeeFromRatio(
|