@indigo-labs/indigo-sdk 0.2.2 → 0.2.4

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
@@ -1,6 +1,6 @@
1
1
  import * as _lucid_evolution_lucid from '@lucid-evolution/lucid';
2
2
  import { Data, Network, OutRef, Credential, LucidEvolution, TxBuilder, Redeemer, Datum, UTxO, SpendingValidator, MintingPolicy, ScriptHash, Address, Assets, PolicyId, Unit } from '@lucid-evolution/lucid';
3
- import { option } from 'fp-ts';
3
+ import { option, ord } from 'fp-ts';
4
4
  import { Core } from '@evolution-sdk/evolution';
5
5
 
6
6
  declare const AssetClassSchema: _lucid_evolution_lucid.TObject<{
@@ -1504,6 +1504,7 @@ declare function spDiv(a: SPInteger, b: SPInteger): SPInteger;
1504
1504
  declare function openStakingPosition(amount: bigint, params: SystemParams, lucid: LucidEvolution, stakingManagerRef?: OutRef): Promise<TxBuilder>;
1505
1505
  declare function adjustStakingPosition(stakingPositionRef: OutRef, amount: bigint, params: SystemParams, lucid: LucidEvolution, stakingManagerRef?: OutRef): Promise<TxBuilder>;
1506
1506
  declare function closeStakingPosition(stakingPositionRef: OutRef, params: SystemParams, lucid: LucidEvolution, stakingManagerRef?: OutRef): Promise<TxBuilder>;
1507
+ declare function distributeAda(stakingManagerRef: OutRef, collectorRefs: OutRef[], params: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
1507
1508
 
1508
1509
  declare const StakingParamsSchema: _lucid_evolution_lucid.TObject<{
1509
1510
  stakingManagerNft: _lucid_evolution_lucid.TObject<{
@@ -1607,15 +1608,6 @@ declare const mkVersionRegistryValidator: () => SpendingValidator;
1607
1608
 
1608
1609
  declare function treasuryFeeTx(fee: bigint, lucid: LucidEvolution, sysParams: SystemParams, tx: TxBuilder, treasuryOref: OutRef): Promise<void>;
1609
1610
 
1610
- /**
1611
- * Accept only a single item in the array and return it.
1612
- * When not exclusively a single item, throw an error.
1613
- */
1614
- declare function matchSingle<T>(xs: T[], mkErr: (xs: T[]) => Error): T;
1615
- declare function loadSystemParamsFromFile(file: string): SystemParams;
1616
- declare function loadSystemParamsFromUrl(url: string): Promise<SystemParams>;
1617
- declare const getRandomElement: <T>(arr: T[]) => T | undefined;
1618
-
1619
1611
  /**
1620
1612
  * Returns the inline datum.
1621
1613
  * Throws when the UTXO doesn't have an inline datum
@@ -1990,16 +1982,53 @@ declare const LRPRedeemerSchema: _lucid_evolution_lucid.TUnion<(_lucid_evolution
1990
1982
  }>;
1991
1983
  }> | _lucid_evolution_lucid.TLiteral<"Cancel">)[]>;
1992
1984
  type LRPRedeemer = Data.Static<typeof LRPRedeemerSchema>;
1993
- declare function parseLrpDatum(datum: Datum): LRPDatum;
1985
+ declare function parseLrpDatum(datum: Datum): option.Option<LRPDatum>;
1986
+ declare function parseLrpDatumOrThrow(datum: Datum): LRPDatum;
1994
1987
  declare function serialiseLrpDatum(datum: LRPDatum): Datum;
1995
1988
  declare function serialiseLrpRedeemer(redeemer: LRPRedeemer): Redeemer;
1996
1989
  declare function castLrpParams(params: LRPParams): Data;
1990
+ type LrpOutput = {
1991
+ datum: LRPDatum;
1992
+ utxo: UTxO;
1993
+ };
1997
1994
 
1998
- declare function openLrp(assetTokenName: string, lovelacesAmt: bigint, maxPrice: OnChainDecimal, lucid: LucidEvolution, lrpScriptHash: ScriptHash, network: Network, lrpStakeCredential?: Credential): Promise<TxBuilder>;
1999
- declare function cancelLrp(lrpOutRef: OutRef, lrpRefScriptOutRef: OutRef, lucid: LucidEvolution): Promise<TxBuilder>;
1995
+ declare const MIN_LRP_COLLATERAL_AMT = 2000000n;
1996
+ /**
1997
+ * Calculate the actually redeemable lovelaces taking into account:
1998
+ * - LRP datum
1999
+ * - UTXO's value
2000
+ * - min redemption
2001
+ *
2002
+ * This helps to handle incorrectly initialised LRPs, too.
2003
+ */
2004
+ declare function lrpRedeemableLovelacesInclReimb(lrp: [UTxO, LRPDatum], lrpParams: LrpParamsSP): bigint;
2005
+ declare function buildRedemptionsTx(
2006
+ /** The tuple represents the LRP UTXO and the amount of iAssets to redeem against it. */
2007
+ redemptions: [UTxO, bigint][], price: OnChainDecimal, redemptionReimbursementPercentage: OnChainDecimal, sysParams: SystemParams, tx: TxBuilder,
2008
+ /**
2009
+ * The number of Tx outputs before these.
2010
+ */
2011
+ txOutputsBeforeCount: bigint): TxBuilder;
2012
+ /**
2013
+ * Given all available LRP UTXOs, calculate total available ADA that can be redeemed (including reimbursement fee).
2014
+ * Taking into account ncorrectly initialised LRPs (without base collateral).
2015
+ */
2016
+ declare function calculateTotalAdaForRedemption(iasset: string, iassetPrice: OnChainDecimal, lrpParams: LrpParamsSP, allLrps: [UTxO, LRPDatum][],
2017
+ /**
2018
+ * How many LRPs can be redeemed in a single Tx.
2019
+ */
2020
+ maxLrpsInTx: number): bigint;
2021
+ declare function randomLrpsSubsetSatisfyingTargetLovelaces(iasset: string, targetLovelacesToSpend: bigint, iassetPrice: OnChainDecimal, allLrps: [UTxO, LRPDatum][], lrpParams: LrpParamsSP,
2022
+ /**
2023
+ * How many LRPs can be redeemed in a single Tx.
2024
+ */
2025
+ maxLrpsInTx: number, randomiseFn?: (arr: [UTxO, LRPDatum][]) => [UTxO, LRPDatum][]): [UTxO, LRPDatum][];
2026
+
2027
+ declare function openLrp(assetTokenName: string, lovelacesAmt: bigint, maxPrice: OnChainDecimal, lucid: LucidEvolution, sysParams: SystemParams, lrpStakeCredential?: Credential): Promise<TxBuilder>;
2028
+ declare function cancelLrp(lrpOutRef: OutRef, sysParams: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
2000
2029
  declare function redeemLrp(
2001
2030
  /** The tuple represents the LRP outref and the amount of iAssets to redeem against it. */
2002
- redemptionLrpsData: [OutRef, bigint][], lrpRefScriptOutRef: OutRef, priceOracleOutRef: OutRef, iassetOutRef: OutRef, lucid: LucidEvolution, lrpParams: LRPParams, network: Network): Promise<TxBuilder>;
2031
+ redemptionLrpsData: [OutRef, bigint][], priceOracleOutRef: OutRef, iassetOutRef: OutRef, lucid: LucidEvolution, sysParams: SystemParams): Promise<TxBuilder>;
2003
2032
  /**
2004
2033
  * Create Tx adjusting the LRP and claiming the received iAssets
2005
2034
  */
@@ -2008,11 +2037,11 @@ declare function adjustLrp(lucid: LucidEvolution, lrpOutRef: OutRef,
2008
2037
  * A positive amount increases the lovelaces in the LRP,
2009
2038
  * and a negative amount takes lovelaces from the LRP.
2010
2039
  */
2011
- lovelacesAdjustAmt: bigint, lrpRefScriptOutRef: OutRef, lrpParams: LRPParams): Promise<TxBuilder>;
2040
+ lovelacesAdjustAmt: bigint, sysParams: SystemParams): Promise<TxBuilder>;
2012
2041
  /**
2013
2042
  * Create Tx claiming the received iAssets.
2014
2043
  */
2015
- declare function claimLrp(lucid: LucidEvolution, lrpOutRef: OutRef, lrpRefScriptOutRef: OutRef, lrpParams: LRPParams): Promise<TxBuilder>;
2044
+ declare function claimLrp(lucid: LucidEvolution, lrpOutRef: OutRef, sysParams: SystemParams): Promise<TxBuilder>;
2016
2045
 
2017
2046
  declare const mkLrpValidator: (params: LRPParams) => SpendingValidator;
2018
2047
  declare const mkLrpValidatorFromSP: (params: LrpParamsSP) => SpendingValidator;
@@ -2038,6 +2067,21 @@ type OneShotParams = Data.Static<typeof OneShotParamsSchema>;
2038
2067
  declare function oneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<[TxBuilder, PolicyId]>;
2039
2068
  declare function runOneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<PolicyId>;
2040
2069
 
2070
+ /**
2071
+ * Accept only a single item in the array and return it.
2072
+ * When not exclusively a single item, throw an error.
2073
+ */
2074
+ declare function matchSingle<T>(xs: T[], mkErr: (xs: T[]) => Error): T;
2075
+ declare function loadSystemParamsFromFile(file: string): SystemParams;
2076
+ declare function loadSystemParamsFromUrl(url: string): Promise<SystemParams>;
2077
+ declare const getRandomElement: <T>(arr: T[]) => T | undefined;
2078
+
2079
+ declare function shuffle<T>(arr: T[]): T[];
2080
+ /**
2081
+ * The parameter `arr` should be sorted for correct results.
2082
+ */
2083
+ declare function insertSorted<T>(arr: T[], item: T, ord: ord.Ord<T>): T[];
2084
+
2041
2085
  declare function mkLovelacesOf(amount: bigint): Assets;
2042
2086
  declare function lovelacesAmt(assets: Assets): bigint;
2043
2087
  declare function assetClassToUnit(ac: AssetClass): Unit;
@@ -2046,4 +2090,106 @@ declare function assetClassValueOf(assets: Assets, assetClass: AssetClass): bigi
2046
2090
  declare function negateAssets(assets: Assets): Assets;
2047
2091
  declare function isAssetsZero(assets: Assets): boolean;
2048
2092
 
2049
- export { type AccountAction, type AccountContent, AccountContentSchema, ActionReturnDatum, ActionReturnDatumSchema, type AddressCredential, type AddressCredentialOrDatum, AddressD, type AddressSP, AddressSchema, type Amount, type AssetClass, type AssetClassSP, AssetClassSchema, type AuthTokenPolicies, type CDPContent, CDPContentSchema, CDPCreatorParams, type CDPCreatorParamsSP, CDPCreatorRedeemer, type CDPDatum, CDPDatumSchema, type CDPFees, CDPFeesSchema, type CDPRedeemer, type CdpParams, type CdpParamsSP, type CollectorParamsSP, CredentialD, CredentialSchema, type CurrencySymbol, type DistributionParams, type EpochToScaleToSum, EpochToScaleToSumSchema, ExecuteDatum, ExecuteParams, type ExecuteParamsSP, type FeedInterestOracleRedeemer, FeedInterestOracleRedeemerSchema, type GovDatum, GovParams, type GovParamsSP, GovRedeemer, type IAssetContent, IAssetContentSchema, type IAssetOutput, IAssetPriceInfoSchema, type Input, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type LRPDatum, LRPDatumSchema, type LRPParams, LRPParamsSchema, type LRPRedeemer, LRPRedeemerSchema, type LrpParamsSP, ONE_DAY, ONE_HOUR, ONE_SECOND, ONE_YEAR, type OracleAssetNft, OracleAssetNftSchema, type Output, type OutputReference, OutputReferenceSchema, PollManagerParams, type PollManagerParamsSP, PollManagerRedeemer, PollShardParams, type PollShardParamsSP, PollShardRedeemer, type PriceOracleDatum, PriceOracleDatumSchema, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PubKeyHash, 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 StabilityPoolSnapshot, StakeCredentialSchema, type StakingManager, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingRedeemer, type StartTime, type SystemParams, type TokenName, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, addressFromBech32, addressToBech32, adjust, adjustLrp, adjustSpAccount, adjustStakingPosition, adjustmentHelper, assetClassToUnit, assetClassValueOf, balance, burnCdp, calculateIAssetRedemptionAmt, calculateMinCollateralCappedIAssetRedemptionAmt, cancelLrp, castCDPCreatorParams, castCdpParams, castExecuteParams, castGovParams, castInterestOracleParams, castLrpParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimLrp, closeCdp, closeSpAccount, closeStakingPosition, collectorFeeTx, createProposal, createScriptAddress, createShardsChunks, createSpAccount, depositCdp, endProposal, executeProposal, feedInterestOracle, freezeCdp, fromSPInteger, fromSysParamsScriptCredential, fromSystemParamsAsset, fromSystemParamsScriptRef, getAccountFund, getAccountReward, getInlineDatumOrThrow, getRandomElement, getSumFromEpochToScaleToSum, initEpochToScaleToSumMap, initSpSnapshot, isAssetsZero, liquidateCdp, liquidationHelper, loadSystemParamsFromFile, loadSystemParamsFromUrl, lovelacesAmt, matchSingle, mergeCdps, mergeShards, mintCdp, mkAssetsOf, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkCdpValidatorFromSP, mkCollectorValidatorFromSP, mkExecuteValidator, mkExecuteValidatorFromSP, mkInterestOracleValidator, mkLovelacesOf, mkLrpValidator, mkLrpValidatorFromSP, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkSPInteger, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, negateAssets, oneShotMintTx, openCdp, openLrp, openStakingPosition, parseAccountDatum, parseCdpDatum, parseCdpDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestOracleDatum, parseLrpDatum, parsePriceOracleDatum, parseSnapshotEpochToScaleToSumDatum, parseStabilityPoolDatum, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, processSpRequest, redeemCdp, redeemLrp, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseCDPCreatorDatum, serialiseCDPCreatorRedeemer, serialiseCdpDatum, serialiseCdpRedeemer, serialiseExecuteDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseGovRedeemer, serialiseIAssetDatum, serialiseInterestOracleDatum, serialiseLrpDatum, serialiseLrpRedeemer, serialisePollManagerRedeemer, serialisePollShardRedeemer, serialisePriceOracleDatum, serialisePriceOracleRedeemer, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, serialiseStakingDatum, serialiseStakingRedeemer, setSumInEpochToScaleToSum, spAdd, spDiv, spMul, spSub, startInterestOracle, toSystemParamsAsset, treasuryFeeTx, updatePoolSnapshotWithdrawalFee, vote, withdrawCdp };
2093
+ declare function leverageCdpWithLrp(leverage: number, baseCollateral: bigint, priceOracleOutRef: OutRef, iassetOutRef: OutRef, cdpCreatorOref: OutRef, interestOracleOref: OutRef, collectorOref: OutRef, sysParams: SystemParams, lucid: LucidEvolution, allLrps: [UTxO, LRPDatum][], currentSlot: number): Promise<TxBuilder>;
2094
+
2095
+ /**
2096
+ * The following is the math related to the leverage calculations.
2097
+ *
2098
+ * Leverage is the multiplier you apply to the base deposit and you get the amount of final collateral
2099
+ * the CDP should have. Additionally, the minted amount is used to pay for fees. The leverage a user picks, is
2100
+ * already taking into account the fees, i.e. the fees are paid from the borrowed assets.
2101
+ *
2102
+ * There's a direct relationship between collateral ratio and leverage multiplier. Each leverage multiplier
2103
+ * results in a single collateral ratio and vice versa. Maximum potential leverage is the leverage that
2104
+ * results in collateral ratio being the maintenance collateral ratio of the corresponding iAsset.
2105
+ *
2106
+ * `d` = base deposit
2107
+ * `b` = total borrowed value (including the fees)
2108
+ * `L` = leverage
2109
+ * `f_m` = debt minting fee
2110
+ * `f_r` = reimbursement fee
2111
+ * `c` = collateral ratio
2112
+ *
2113
+ * The following is a detailed derivation of the math:
2114
+ *
2115
+ * 1. Since the redemption fee is proportional to the borrowed amount,
2116
+ * we can express the ADA we get from the order book as `b'=b*(1-f_r)`,
2117
+ * since some of the borrowed amount goes back to the order book.
2118
+ *
2119
+ * 2. Since all the minted iAsset are used to get borrowed ADA,
2120
+ * the value of the minted asset will be `b`.
2121
+ *
2122
+ * 3. The minting fee is a percentage of the value of the minted iAsset.
2123
+ * Therefore the available ADA to add as collateral is `b''=b' - b*f_m = b*(1 - f_r - f_m)`.
2124
+ *
2125
+ * 4. The collateral ratio can now be expressed as `c = (d + b * (1 - f_r - f_m)) / b`.
2126
+ *
2127
+ * 5. Working out the expression, we can express `b` in terms of everything else: `b = d / (c - 1 + f_r + f_m)`.
2128
+ *
2129
+ * 6. The minted amount will be `b / asset_price`.
2130
+ *
2131
+ * 7. Collateral amount of the CDP is `d + b * (1 - f_r - f_m)`
2132
+ *
2133
+ * 8. Leverage calculation: `L = (d + b * (1 - f_r - f_m)) / d`.
2134
+ *
2135
+ * Plugging in the `b` formula we get: `L = (d + (d / (c - 1 + f_r + f_m)) * (1 - f_r - f_m)) / d`.
2136
+ *
2137
+ * Simplified, yields the following:
2138
+ * `L = 1 + ((1 - f_r - f_m) / (c - 1 + f_r + f_m))`
2139
+ *
2140
+ * 9. `b'' = b * (1 - f_r - f_m)`
2141
+ * Solved for `b` yields the following:
2142
+ * `b = b'' / (1 - f_r - f_m)`
2143
+ *
2144
+ * 10. Having leverage and base deposit, we can find `b''`:
2145
+ * `b’’ = d(L - 1)`
2146
+ */
2147
+
2148
+ /**
2149
+ * How many LRP redemptions can we fit into a TX with CDP open.
2150
+ */
2151
+ declare const MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
2152
+ type LRPRedemptionDetails = {
2153
+ utxo: UTxO;
2154
+ /**
2155
+ * This is including the reimbursement fee.
2156
+ **/
2157
+ redemptionLovelacesAmtInclReimbursement: bigint;
2158
+ iassetsForRedemptionAmt: bigint;
2159
+ reimbursementLovelacesAmt: bigint;
2160
+ };
2161
+ type ApproximateLeverageRedemptionsResult = {
2162
+ leverage: number;
2163
+ collateralRatio: OnChainDecimal;
2164
+ lovelacesForRedemptionWithReimbursement: bigint;
2165
+ };
2166
+ /**
2167
+ * We assume exact precision. However, actual redemptions include rounding and
2168
+ * the rounding behaviour changes based on the number of redemptions.
2169
+ * This may slightly tweak the numbers and the result can be different.
2170
+ *
2171
+ * The math is described at the top of this code file.
2172
+ */
2173
+ declare function approximateLeverageRedemptions(baseCollateral: bigint, targetLeverage: number, redemptionReimbursementPercentage: OnChainDecimal, debtMintingFeePercentage: OnChainDecimal): ApproximateLeverageRedemptionsResult;
2174
+ declare function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement: bigint, redemptionReimbursementPercentage: OnChainDecimal, iassetPrice: OnChainDecimal, lrpParams: LrpParamsSP, redemptionLrps: [UTxO, LRPDatum][]): {
2175
+ redemptions: LRPRedemptionDetails[];
2176
+ /**
2177
+ * The actual amount received from redemptions (i.e. without the reimbursement fee).
2178
+ */
2179
+ totalRedeemedLovelaces: bigint;
2180
+ /**
2181
+ * Total lovelaces amt that has been reimbursted
2182
+ */
2183
+ totalReimbursementLovelaces: bigint;
2184
+ totalRedemptionIAssets: bigint;
2185
+ };
2186
+ /**
2187
+ * The math is described at the top of this code file.
2188
+ */
2189
+ declare function calculateCollateralRatioFromLeverage(iasset: string, leverage: number, baseCollateral: bigint, iassetPrice: OnChainDecimal, debtMintingFeePercentage: OnChainDecimal, redemptionReimbursementPercentage: OnChainDecimal, lrpParams: LrpParamsSP, allLrps: [UTxO, LRPDatum][]): OnChainDecimal | undefined;
2190
+ /**
2191
+ * The math is described at the top of this code file.
2192
+ */
2193
+ declare function calculateLeverageFromCollateralRatio(iasset: string, collateralRatioPercentage: OnChainDecimal, baseCollateral: bigint, iassetPrice: OnChainDecimal, debtMintingFeePercentage: OnChainDecimal, redemptionReimbursementPercentage: OnChainDecimal, lrpParams: LrpParamsSP, allLrps: [UTxO, LRPDatum][]): number | undefined;
2194
+
2195
+ export { type AccountAction, type AccountContent, AccountContentSchema, ActionReturnDatum, ActionReturnDatumSchema, type AddressCredential, type AddressCredentialOrDatum, AddressD, type AddressSP, AddressSchema, type Amount, type AssetClass, type AssetClassSP, AssetClassSchema, type AuthTokenPolicies, type CDPContent, CDPContentSchema, CDPCreatorParams, type CDPCreatorParamsSP, CDPCreatorRedeemer, type CDPDatum, CDPDatumSchema, type CDPFees, CDPFeesSchema, type CDPRedeemer, type CdpParams, type CdpParamsSP, type CollectorParamsSP, CredentialD, CredentialSchema, type CurrencySymbol, type DistributionParams, type EpochToScaleToSum, EpochToScaleToSumSchema, ExecuteDatum, ExecuteParams, type ExecuteParamsSP, type FeedInterestOracleRedeemer, FeedInterestOracleRedeemerSchema, type GovDatum, GovParams, type GovParamsSP, GovRedeemer, type IAssetContent, IAssetContentSchema, type IAssetOutput, IAssetPriceInfoSchema, type Input, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type LRPDatum, LRPDatumSchema, type LRPParams, LRPParamsSchema, type LRPRedeemer, LRPRedeemerSchema, type LrpOutput, type LrpParamsSP, MAX_REDEMPTIONS_WITH_CDP_OPEN, MIN_LRP_COLLATERAL_AMT, ONE_DAY, ONE_HOUR, ONE_SECOND, ONE_YEAR, type OracleAssetNft, OracleAssetNftSchema, type Output, type OutputReference, OutputReferenceSchema, PollManagerParams, type PollManagerParamsSP, PollManagerRedeemer, PollShardParams, type PollShardParamsSP, PollShardRedeemer, type PriceOracleDatum, PriceOracleDatumSchema, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PubKeyHash, 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 StabilityPoolSnapshot, StakeCredentialSchema, type StakingManager, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingRedeemer, type StartTime, type SystemParams, type TokenName, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, addressFromBech32, addressToBech32, adjust, adjustLrp, adjustSpAccount, adjustStakingPosition, adjustmentHelper, approximateLeverageRedemptions, assetClassToUnit, assetClassValueOf, balance, buildRedemptionsTx, burnCdp, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculateTotalAdaForRedemption, cancelLrp, castCDPCreatorParams, castCdpParams, castExecuteParams, castGovParams, castInterestOracleParams, castLrpParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimLrp, closeCdp, closeSpAccount, closeStakingPosition, collectorFeeTx, createProposal, createScriptAddress, createShardsChunks, createSpAccount, depositCdp, distributeAda, endProposal, executeProposal, feedInterestOracle, freezeCdp, fromSPInteger, fromSysParamsScriptCredential, fromSystemParamsAsset, fromSystemParamsScriptRef, getAccountFund, getAccountReward, getInlineDatumOrThrow, getRandomElement, getSumFromEpochToScaleToSum, initEpochToScaleToSumMap, initSpSnapshot, insertSorted, isAssetsZero, leverageCdpWithLrp, liquidateCdp, liquidationHelper, loadSystemParamsFromFile, loadSystemParamsFromUrl, lovelacesAmt, lrpRedeemableLovelacesInclReimb, matchSingle, mergeCdps, mergeShards, mintCdp, mkAssetsOf, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkCdpValidatorFromSP, mkCollectorValidatorFromSP, mkExecuteValidator, mkExecuteValidatorFromSP, mkInterestOracleValidator, mkLovelacesOf, mkLrpValidator, mkLrpValidatorFromSP, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkSPInteger, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, negateAssets, oneShotMintTx, openCdp, openLrp, openStakingPosition, parseAccountDatum, parseCdpDatum, parseCdpDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestOracleDatum, parseLrpDatum, parseLrpDatumOrThrow, parsePriceOracleDatum, parseSnapshotEpochToScaleToSumDatum, parseStabilityPoolDatum, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, processSpRequest, randomLrpsSubsetSatisfyingTargetLovelaces, redeemCdp, redeemLrp, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseCDPCreatorDatum, serialiseCDPCreatorRedeemer, serialiseCdpDatum, serialiseCdpRedeemer, serialiseExecuteDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseGovRedeemer, serialiseIAssetDatum, serialiseInterestOracleDatum, serialiseLrpDatum, serialiseLrpRedeemer, serialisePollManagerRedeemer, serialisePollShardRedeemer, serialisePriceOracleDatum, serialisePriceOracleRedeemer, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, serialiseStakingDatum, serialiseStakingRedeemer, setSumInEpochToScaleToSum, shuffle, spAdd, spDiv, spMul, spSub, startInterestOracle, summarizeActualLeverageRedemptions, toSystemParamsAsset, treasuryFeeTx, updatePoolSnapshotWithdrawalFee, vote, withdrawCdp };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _lucid_evolution_lucid from '@lucid-evolution/lucid';
2
2
  import { Data, Network, OutRef, Credential, LucidEvolution, TxBuilder, Redeemer, Datum, UTxO, SpendingValidator, MintingPolicy, ScriptHash, Address, Assets, PolicyId, Unit } from '@lucid-evolution/lucid';
3
- import { option } from 'fp-ts';
3
+ import { option, ord } from 'fp-ts';
4
4
  import { Core } from '@evolution-sdk/evolution';
5
5
 
6
6
  declare const AssetClassSchema: _lucid_evolution_lucid.TObject<{
@@ -1504,6 +1504,7 @@ declare function spDiv(a: SPInteger, b: SPInteger): SPInteger;
1504
1504
  declare function openStakingPosition(amount: bigint, params: SystemParams, lucid: LucidEvolution, stakingManagerRef?: OutRef): Promise<TxBuilder>;
1505
1505
  declare function adjustStakingPosition(stakingPositionRef: OutRef, amount: bigint, params: SystemParams, lucid: LucidEvolution, stakingManagerRef?: OutRef): Promise<TxBuilder>;
1506
1506
  declare function closeStakingPosition(stakingPositionRef: OutRef, params: SystemParams, lucid: LucidEvolution, stakingManagerRef?: OutRef): Promise<TxBuilder>;
1507
+ declare function distributeAda(stakingManagerRef: OutRef, collectorRefs: OutRef[], params: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
1507
1508
 
1508
1509
  declare const StakingParamsSchema: _lucid_evolution_lucid.TObject<{
1509
1510
  stakingManagerNft: _lucid_evolution_lucid.TObject<{
@@ -1607,15 +1608,6 @@ declare const mkVersionRegistryValidator: () => SpendingValidator;
1607
1608
 
1608
1609
  declare function treasuryFeeTx(fee: bigint, lucid: LucidEvolution, sysParams: SystemParams, tx: TxBuilder, treasuryOref: OutRef): Promise<void>;
1609
1610
 
1610
- /**
1611
- * Accept only a single item in the array and return it.
1612
- * When not exclusively a single item, throw an error.
1613
- */
1614
- declare function matchSingle<T>(xs: T[], mkErr: (xs: T[]) => Error): T;
1615
- declare function loadSystemParamsFromFile(file: string): SystemParams;
1616
- declare function loadSystemParamsFromUrl(url: string): Promise<SystemParams>;
1617
- declare const getRandomElement: <T>(arr: T[]) => T | undefined;
1618
-
1619
1611
  /**
1620
1612
  * Returns the inline datum.
1621
1613
  * Throws when the UTXO doesn't have an inline datum
@@ -1990,16 +1982,53 @@ declare const LRPRedeemerSchema: _lucid_evolution_lucid.TUnion<(_lucid_evolution
1990
1982
  }>;
1991
1983
  }> | _lucid_evolution_lucid.TLiteral<"Cancel">)[]>;
1992
1984
  type LRPRedeemer = Data.Static<typeof LRPRedeemerSchema>;
1993
- declare function parseLrpDatum(datum: Datum): LRPDatum;
1985
+ declare function parseLrpDatum(datum: Datum): option.Option<LRPDatum>;
1986
+ declare function parseLrpDatumOrThrow(datum: Datum): LRPDatum;
1994
1987
  declare function serialiseLrpDatum(datum: LRPDatum): Datum;
1995
1988
  declare function serialiseLrpRedeemer(redeemer: LRPRedeemer): Redeemer;
1996
1989
  declare function castLrpParams(params: LRPParams): Data;
1990
+ type LrpOutput = {
1991
+ datum: LRPDatum;
1992
+ utxo: UTxO;
1993
+ };
1997
1994
 
1998
- declare function openLrp(assetTokenName: string, lovelacesAmt: bigint, maxPrice: OnChainDecimal, lucid: LucidEvolution, lrpScriptHash: ScriptHash, network: Network, lrpStakeCredential?: Credential): Promise<TxBuilder>;
1999
- declare function cancelLrp(lrpOutRef: OutRef, lrpRefScriptOutRef: OutRef, lucid: LucidEvolution): Promise<TxBuilder>;
1995
+ declare const MIN_LRP_COLLATERAL_AMT = 2000000n;
1996
+ /**
1997
+ * Calculate the actually redeemable lovelaces taking into account:
1998
+ * - LRP datum
1999
+ * - UTXO's value
2000
+ * - min redemption
2001
+ *
2002
+ * This helps to handle incorrectly initialised LRPs, too.
2003
+ */
2004
+ declare function lrpRedeemableLovelacesInclReimb(lrp: [UTxO, LRPDatum], lrpParams: LrpParamsSP): bigint;
2005
+ declare function buildRedemptionsTx(
2006
+ /** The tuple represents the LRP UTXO and the amount of iAssets to redeem against it. */
2007
+ redemptions: [UTxO, bigint][], price: OnChainDecimal, redemptionReimbursementPercentage: OnChainDecimal, sysParams: SystemParams, tx: TxBuilder,
2008
+ /**
2009
+ * The number of Tx outputs before these.
2010
+ */
2011
+ txOutputsBeforeCount: bigint): TxBuilder;
2012
+ /**
2013
+ * Given all available LRP UTXOs, calculate total available ADA that can be redeemed (including reimbursement fee).
2014
+ * Taking into account ncorrectly initialised LRPs (without base collateral).
2015
+ */
2016
+ declare function calculateTotalAdaForRedemption(iasset: string, iassetPrice: OnChainDecimal, lrpParams: LrpParamsSP, allLrps: [UTxO, LRPDatum][],
2017
+ /**
2018
+ * How many LRPs can be redeemed in a single Tx.
2019
+ */
2020
+ maxLrpsInTx: number): bigint;
2021
+ declare function randomLrpsSubsetSatisfyingTargetLovelaces(iasset: string, targetLovelacesToSpend: bigint, iassetPrice: OnChainDecimal, allLrps: [UTxO, LRPDatum][], lrpParams: LrpParamsSP,
2022
+ /**
2023
+ * How many LRPs can be redeemed in a single Tx.
2024
+ */
2025
+ maxLrpsInTx: number, randomiseFn?: (arr: [UTxO, LRPDatum][]) => [UTxO, LRPDatum][]): [UTxO, LRPDatum][];
2026
+
2027
+ declare function openLrp(assetTokenName: string, lovelacesAmt: bigint, maxPrice: OnChainDecimal, lucid: LucidEvolution, sysParams: SystemParams, lrpStakeCredential?: Credential): Promise<TxBuilder>;
2028
+ declare function cancelLrp(lrpOutRef: OutRef, sysParams: SystemParams, lucid: LucidEvolution): Promise<TxBuilder>;
2000
2029
  declare function redeemLrp(
2001
2030
  /** The tuple represents the LRP outref and the amount of iAssets to redeem against it. */
2002
- redemptionLrpsData: [OutRef, bigint][], lrpRefScriptOutRef: OutRef, priceOracleOutRef: OutRef, iassetOutRef: OutRef, lucid: LucidEvolution, lrpParams: LRPParams, network: Network): Promise<TxBuilder>;
2031
+ redemptionLrpsData: [OutRef, bigint][], priceOracleOutRef: OutRef, iassetOutRef: OutRef, lucid: LucidEvolution, sysParams: SystemParams): Promise<TxBuilder>;
2003
2032
  /**
2004
2033
  * Create Tx adjusting the LRP and claiming the received iAssets
2005
2034
  */
@@ -2008,11 +2037,11 @@ declare function adjustLrp(lucid: LucidEvolution, lrpOutRef: OutRef,
2008
2037
  * A positive amount increases the lovelaces in the LRP,
2009
2038
  * and a negative amount takes lovelaces from the LRP.
2010
2039
  */
2011
- lovelacesAdjustAmt: bigint, lrpRefScriptOutRef: OutRef, lrpParams: LRPParams): Promise<TxBuilder>;
2040
+ lovelacesAdjustAmt: bigint, sysParams: SystemParams): Promise<TxBuilder>;
2012
2041
  /**
2013
2042
  * Create Tx claiming the received iAssets.
2014
2043
  */
2015
- declare function claimLrp(lucid: LucidEvolution, lrpOutRef: OutRef, lrpRefScriptOutRef: OutRef, lrpParams: LRPParams): Promise<TxBuilder>;
2044
+ declare function claimLrp(lucid: LucidEvolution, lrpOutRef: OutRef, sysParams: SystemParams): Promise<TxBuilder>;
2016
2045
 
2017
2046
  declare const mkLrpValidator: (params: LRPParams) => SpendingValidator;
2018
2047
  declare const mkLrpValidatorFromSP: (params: LrpParamsSP) => SpendingValidator;
@@ -2038,6 +2067,21 @@ type OneShotParams = Data.Static<typeof OneShotParamsSchema>;
2038
2067
  declare function oneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<[TxBuilder, PolicyId]>;
2039
2068
  declare function runOneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<PolicyId>;
2040
2069
 
2070
+ /**
2071
+ * Accept only a single item in the array and return it.
2072
+ * When not exclusively a single item, throw an error.
2073
+ */
2074
+ declare function matchSingle<T>(xs: T[], mkErr: (xs: T[]) => Error): T;
2075
+ declare function loadSystemParamsFromFile(file: string): SystemParams;
2076
+ declare function loadSystemParamsFromUrl(url: string): Promise<SystemParams>;
2077
+ declare const getRandomElement: <T>(arr: T[]) => T | undefined;
2078
+
2079
+ declare function shuffle<T>(arr: T[]): T[];
2080
+ /**
2081
+ * The parameter `arr` should be sorted for correct results.
2082
+ */
2083
+ declare function insertSorted<T>(arr: T[], item: T, ord: ord.Ord<T>): T[];
2084
+
2041
2085
  declare function mkLovelacesOf(amount: bigint): Assets;
2042
2086
  declare function lovelacesAmt(assets: Assets): bigint;
2043
2087
  declare function assetClassToUnit(ac: AssetClass): Unit;
@@ -2046,4 +2090,106 @@ declare function assetClassValueOf(assets: Assets, assetClass: AssetClass): bigi
2046
2090
  declare function negateAssets(assets: Assets): Assets;
2047
2091
  declare function isAssetsZero(assets: Assets): boolean;
2048
2092
 
2049
- export { type AccountAction, type AccountContent, AccountContentSchema, ActionReturnDatum, ActionReturnDatumSchema, type AddressCredential, type AddressCredentialOrDatum, AddressD, type AddressSP, AddressSchema, type Amount, type AssetClass, type AssetClassSP, AssetClassSchema, type AuthTokenPolicies, type CDPContent, CDPContentSchema, CDPCreatorParams, type CDPCreatorParamsSP, CDPCreatorRedeemer, type CDPDatum, CDPDatumSchema, type CDPFees, CDPFeesSchema, type CDPRedeemer, type CdpParams, type CdpParamsSP, type CollectorParamsSP, CredentialD, CredentialSchema, type CurrencySymbol, type DistributionParams, type EpochToScaleToSum, EpochToScaleToSumSchema, ExecuteDatum, ExecuteParams, type ExecuteParamsSP, type FeedInterestOracleRedeemer, FeedInterestOracleRedeemerSchema, type GovDatum, GovParams, type GovParamsSP, GovRedeemer, type IAssetContent, IAssetContentSchema, type IAssetOutput, IAssetPriceInfoSchema, type Input, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type LRPDatum, LRPDatumSchema, type LRPParams, LRPParamsSchema, type LRPRedeemer, LRPRedeemerSchema, type LrpParamsSP, ONE_DAY, ONE_HOUR, ONE_SECOND, ONE_YEAR, type OracleAssetNft, OracleAssetNftSchema, type Output, type OutputReference, OutputReferenceSchema, PollManagerParams, type PollManagerParamsSP, PollManagerRedeemer, PollShardParams, type PollShardParamsSP, PollShardRedeemer, type PriceOracleDatum, PriceOracleDatumSchema, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PubKeyHash, 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 StabilityPoolSnapshot, StakeCredentialSchema, type StakingManager, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingRedeemer, type StartTime, type SystemParams, type TokenName, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, addressFromBech32, addressToBech32, adjust, adjustLrp, adjustSpAccount, adjustStakingPosition, adjustmentHelper, assetClassToUnit, assetClassValueOf, balance, burnCdp, calculateIAssetRedemptionAmt, calculateMinCollateralCappedIAssetRedemptionAmt, cancelLrp, castCDPCreatorParams, castCdpParams, castExecuteParams, castGovParams, castInterestOracleParams, castLrpParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimLrp, closeCdp, closeSpAccount, closeStakingPosition, collectorFeeTx, createProposal, createScriptAddress, createShardsChunks, createSpAccount, depositCdp, endProposal, executeProposal, feedInterestOracle, freezeCdp, fromSPInteger, fromSysParamsScriptCredential, fromSystemParamsAsset, fromSystemParamsScriptRef, getAccountFund, getAccountReward, getInlineDatumOrThrow, getRandomElement, getSumFromEpochToScaleToSum, initEpochToScaleToSumMap, initSpSnapshot, isAssetsZero, liquidateCdp, liquidationHelper, loadSystemParamsFromFile, loadSystemParamsFromUrl, lovelacesAmt, matchSingle, mergeCdps, mergeShards, mintCdp, mkAssetsOf, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkCdpValidatorFromSP, mkCollectorValidatorFromSP, mkExecuteValidator, mkExecuteValidatorFromSP, mkInterestOracleValidator, mkLovelacesOf, mkLrpValidator, mkLrpValidatorFromSP, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkSPInteger, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, negateAssets, oneShotMintTx, openCdp, openLrp, openStakingPosition, parseAccountDatum, parseCdpDatum, parseCdpDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestOracleDatum, parseLrpDatum, parsePriceOracleDatum, parseSnapshotEpochToScaleToSumDatum, parseStabilityPoolDatum, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, processSpRequest, redeemCdp, redeemLrp, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseCDPCreatorDatum, serialiseCDPCreatorRedeemer, serialiseCdpDatum, serialiseCdpRedeemer, serialiseExecuteDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseGovRedeemer, serialiseIAssetDatum, serialiseInterestOracleDatum, serialiseLrpDatum, serialiseLrpRedeemer, serialisePollManagerRedeemer, serialisePollShardRedeemer, serialisePriceOracleDatum, serialisePriceOracleRedeemer, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, serialiseStakingDatum, serialiseStakingRedeemer, setSumInEpochToScaleToSum, spAdd, spDiv, spMul, spSub, startInterestOracle, toSystemParamsAsset, treasuryFeeTx, updatePoolSnapshotWithdrawalFee, vote, withdrawCdp };
2093
+ declare function leverageCdpWithLrp(leverage: number, baseCollateral: bigint, priceOracleOutRef: OutRef, iassetOutRef: OutRef, cdpCreatorOref: OutRef, interestOracleOref: OutRef, collectorOref: OutRef, sysParams: SystemParams, lucid: LucidEvolution, allLrps: [UTxO, LRPDatum][], currentSlot: number): Promise<TxBuilder>;
2094
+
2095
+ /**
2096
+ * The following is the math related to the leverage calculations.
2097
+ *
2098
+ * Leverage is the multiplier you apply to the base deposit and you get the amount of final collateral
2099
+ * the CDP should have. Additionally, the minted amount is used to pay for fees. The leverage a user picks, is
2100
+ * already taking into account the fees, i.e. the fees are paid from the borrowed assets.
2101
+ *
2102
+ * There's a direct relationship between collateral ratio and leverage multiplier. Each leverage multiplier
2103
+ * results in a single collateral ratio and vice versa. Maximum potential leverage is the leverage that
2104
+ * results in collateral ratio being the maintenance collateral ratio of the corresponding iAsset.
2105
+ *
2106
+ * `d` = base deposit
2107
+ * `b` = total borrowed value (including the fees)
2108
+ * `L` = leverage
2109
+ * `f_m` = debt minting fee
2110
+ * `f_r` = reimbursement fee
2111
+ * `c` = collateral ratio
2112
+ *
2113
+ * The following is a detailed derivation of the math:
2114
+ *
2115
+ * 1. Since the redemption fee is proportional to the borrowed amount,
2116
+ * we can express the ADA we get from the order book as `b'=b*(1-f_r)`,
2117
+ * since some of the borrowed amount goes back to the order book.
2118
+ *
2119
+ * 2. Since all the minted iAsset are used to get borrowed ADA,
2120
+ * the value of the minted asset will be `b`.
2121
+ *
2122
+ * 3. The minting fee is a percentage of the value of the minted iAsset.
2123
+ * Therefore the available ADA to add as collateral is `b''=b' - b*f_m = b*(1 - f_r - f_m)`.
2124
+ *
2125
+ * 4. The collateral ratio can now be expressed as `c = (d + b * (1 - f_r - f_m)) / b`.
2126
+ *
2127
+ * 5. Working out the expression, we can express `b` in terms of everything else: `b = d / (c - 1 + f_r + f_m)`.
2128
+ *
2129
+ * 6. The minted amount will be `b / asset_price`.
2130
+ *
2131
+ * 7. Collateral amount of the CDP is `d + b * (1 - f_r - f_m)`
2132
+ *
2133
+ * 8. Leverage calculation: `L = (d + b * (1 - f_r - f_m)) / d`.
2134
+ *
2135
+ * Plugging in the `b` formula we get: `L = (d + (d / (c - 1 + f_r + f_m)) * (1 - f_r - f_m)) / d`.
2136
+ *
2137
+ * Simplified, yields the following:
2138
+ * `L = 1 + ((1 - f_r - f_m) / (c - 1 + f_r + f_m))`
2139
+ *
2140
+ * 9. `b'' = b * (1 - f_r - f_m)`
2141
+ * Solved for `b` yields the following:
2142
+ * `b = b'' / (1 - f_r - f_m)`
2143
+ *
2144
+ * 10. Having leverage and base deposit, we can find `b''`:
2145
+ * `b’’ = d(L - 1)`
2146
+ */
2147
+
2148
+ /**
2149
+ * How many LRP redemptions can we fit into a TX with CDP open.
2150
+ */
2151
+ declare const MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
2152
+ type LRPRedemptionDetails = {
2153
+ utxo: UTxO;
2154
+ /**
2155
+ * This is including the reimbursement fee.
2156
+ **/
2157
+ redemptionLovelacesAmtInclReimbursement: bigint;
2158
+ iassetsForRedemptionAmt: bigint;
2159
+ reimbursementLovelacesAmt: bigint;
2160
+ };
2161
+ type ApproximateLeverageRedemptionsResult = {
2162
+ leverage: number;
2163
+ collateralRatio: OnChainDecimal;
2164
+ lovelacesForRedemptionWithReimbursement: bigint;
2165
+ };
2166
+ /**
2167
+ * We assume exact precision. However, actual redemptions include rounding and
2168
+ * the rounding behaviour changes based on the number of redemptions.
2169
+ * This may slightly tweak the numbers and the result can be different.
2170
+ *
2171
+ * The math is described at the top of this code file.
2172
+ */
2173
+ declare function approximateLeverageRedemptions(baseCollateral: bigint, targetLeverage: number, redemptionReimbursementPercentage: OnChainDecimal, debtMintingFeePercentage: OnChainDecimal): ApproximateLeverageRedemptionsResult;
2174
+ declare function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement: bigint, redemptionReimbursementPercentage: OnChainDecimal, iassetPrice: OnChainDecimal, lrpParams: LrpParamsSP, redemptionLrps: [UTxO, LRPDatum][]): {
2175
+ redemptions: LRPRedemptionDetails[];
2176
+ /**
2177
+ * The actual amount received from redemptions (i.e. without the reimbursement fee).
2178
+ */
2179
+ totalRedeemedLovelaces: bigint;
2180
+ /**
2181
+ * Total lovelaces amt that has been reimbursted
2182
+ */
2183
+ totalReimbursementLovelaces: bigint;
2184
+ totalRedemptionIAssets: bigint;
2185
+ };
2186
+ /**
2187
+ * The math is described at the top of this code file.
2188
+ */
2189
+ declare function calculateCollateralRatioFromLeverage(iasset: string, leverage: number, baseCollateral: bigint, iassetPrice: OnChainDecimal, debtMintingFeePercentage: OnChainDecimal, redemptionReimbursementPercentage: OnChainDecimal, lrpParams: LrpParamsSP, allLrps: [UTxO, LRPDatum][]): OnChainDecimal | undefined;
2190
+ /**
2191
+ * The math is described at the top of this code file.
2192
+ */
2193
+ declare function calculateLeverageFromCollateralRatio(iasset: string, collateralRatioPercentage: OnChainDecimal, baseCollateral: bigint, iassetPrice: OnChainDecimal, debtMintingFeePercentage: OnChainDecimal, redemptionReimbursementPercentage: OnChainDecimal, lrpParams: LrpParamsSP, allLrps: [UTxO, LRPDatum][]): number | undefined;
2194
+
2195
+ export { type AccountAction, type AccountContent, AccountContentSchema, ActionReturnDatum, ActionReturnDatumSchema, type AddressCredential, type AddressCredentialOrDatum, AddressD, type AddressSP, AddressSchema, type Amount, type AssetClass, type AssetClassSP, AssetClassSchema, type AuthTokenPolicies, type CDPContent, CDPContentSchema, CDPCreatorParams, type CDPCreatorParamsSP, CDPCreatorRedeemer, type CDPDatum, CDPDatumSchema, type CDPFees, CDPFeesSchema, type CDPRedeemer, type CdpParams, type CdpParamsSP, type CollectorParamsSP, CredentialD, CredentialSchema, type CurrencySymbol, type DistributionParams, type EpochToScaleToSum, EpochToScaleToSumSchema, ExecuteDatum, ExecuteParams, type ExecuteParamsSP, type FeedInterestOracleRedeemer, FeedInterestOracleRedeemerSchema, type GovDatum, GovParams, type GovParamsSP, GovRedeemer, type IAssetContent, IAssetContentSchema, type IAssetOutput, IAssetPriceInfoSchema, type Input, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type LRPDatum, LRPDatumSchema, type LRPParams, LRPParamsSchema, type LRPRedeemer, LRPRedeemerSchema, type LrpOutput, type LrpParamsSP, MAX_REDEMPTIONS_WITH_CDP_OPEN, MIN_LRP_COLLATERAL_AMT, ONE_DAY, ONE_HOUR, ONE_SECOND, ONE_YEAR, type OracleAssetNft, OracleAssetNftSchema, type Output, type OutputReference, OutputReferenceSchema, PollManagerParams, type PollManagerParamsSP, PollManagerRedeemer, PollShardParams, type PollShardParamsSP, PollShardRedeemer, type PriceOracleDatum, PriceOracleDatumSchema, type PriceOracleParams, PriceOracleParamsSchema, type PriceOracleRedeemer, type PubKeyHash, 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 StabilityPoolSnapshot, StakeCredentialSchema, type StakingManager, type StakingParamsSP, type StakingPosLockedAmt, type StakingPosition, type StakingRedeemer, type StartTime, type SystemParams, type TokenName, type TreasuryParamsSP, type TreasuryWithdrawal, type TreasuryWithdrawalItem, TreasuryWithdrawalSchema, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, VersionRecordTokenParams, type VoteOption, addrDetails, addressFromBech32, addressToBech32, adjust, adjustLrp, adjustSpAccount, adjustStakingPosition, adjustmentHelper, approximateLeverageRedemptions, assetClassToUnit, assetClassValueOf, balance, buildRedemptionsTx, burnCdp, calculateCollateralRatioFromLeverage, calculateIAssetRedemptionAmt, calculateLeverageFromCollateralRatio, calculateMinCollateralCappedIAssetRedemptionAmt, calculateTotalAdaForRedemption, cancelLrp, castCDPCreatorParams, castCdpParams, castExecuteParams, castGovParams, castInterestOracleParams, castLrpParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castStabilityPoolParams, castStakingParams, castVersionRecordTokenParams, cdpCollateralRatioPercentage, claimLrp, closeCdp, closeSpAccount, closeStakingPosition, collectorFeeTx, createProposal, createScriptAddress, createShardsChunks, createSpAccount, depositCdp, distributeAda, endProposal, executeProposal, feedInterestOracle, freezeCdp, fromSPInteger, fromSysParamsScriptCredential, fromSystemParamsAsset, fromSystemParamsScriptRef, getAccountFund, getAccountReward, getInlineDatumOrThrow, getRandomElement, getSumFromEpochToScaleToSum, initEpochToScaleToSumMap, initSpSnapshot, insertSorted, isAssetsZero, leverageCdpWithLrp, liquidateCdp, liquidationHelper, loadSystemParamsFromFile, loadSystemParamsFromUrl, lovelacesAmt, lrpRedeemableLovelacesInclReimb, matchSingle, mergeCdps, mergeShards, mintCdp, mkAssetsOf, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkCdpValidatorFromSP, mkCollectorValidatorFromSP, mkExecuteValidator, mkExecuteValidatorFromSP, mkInterestOracleValidator, mkLovelacesOf, mkLrpValidator, mkLrpValidatorFromSP, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkSPInteger, mkTreasuryValidatorFromSP, mkVersionRecordTokenPolicy, mkVersionRegistryValidator, negateAssets, oneShotMintTx, openCdp, openLrp, openStakingPosition, parseAccountDatum, parseCdpDatum, parseCdpDatumOrThrow, parseExecuteDatum, parseExecuteDatumOrThrow, parseGovDatum, parseGovDatumOrThrow, parseIAssetDatum, parseIAssetDatumOrThrow, parseInterestOracleDatum, parseLrpDatum, parseLrpDatumOrThrow, parsePriceOracleDatum, parseSnapshotEpochToScaleToSumDatum, parseStabilityPoolDatum, parseStakingManagerDatum, parseStakingPosition, parseStakingPositionOrThrow, processSpRequest, randomLrpsSubsetSatisfyingTargetLovelaces, redeemCdp, redeemLrp, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseCDPCreatorDatum, serialiseCDPCreatorRedeemer, serialiseCdpDatum, serialiseCdpRedeemer, serialiseExecuteDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseGovRedeemer, serialiseIAssetDatum, serialiseInterestOracleDatum, serialiseLrpDatum, serialiseLrpRedeemer, serialisePollManagerRedeemer, serialisePollShardRedeemer, serialisePriceOracleDatum, serialisePriceOracleRedeemer, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, serialiseStakingDatum, serialiseStakingRedeemer, setSumInEpochToScaleToSum, shuffle, spAdd, spDiv, spMul, spSub, startInterestOracle, summarizeActualLeverageRedemptions, toSystemParamsAsset, treasuryFeeTx, updatePoolSnapshotWithdrawalFee, vote, withdrawCdp };