@indigo-labs/indigo-sdk 0.2.1 → 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 +245 -17
- package/dist/index.d.ts +245 -17
- package/dist/index.js +1144 -479
- package/dist/index.mjs +970 -319
- package/package.json +1 -1
- package/src/contracts/collector/transactions.ts +3 -3
- package/src/contracts/collector/types.ts +16 -0
- package/src/contracts/leverage/helpers.ts +424 -0
- package/src/contracts/leverage/transactions.ts +274 -0
- package/src/contracts/lrp/helpers.ts +290 -0
- package/src/contracts/lrp/transactions.ts +42 -104
- package/src/contracts/lrp/types.ts +19 -3
- package/src/contracts/stability-pool/transactions.ts +0 -4
- package/src/contracts/staking/helpers.ts +11 -0
- package/src/contracts/staking/transactions.ts +94 -4
- package/src/index.ts +7 -2
- package/src/types/on-chain-decimal.ts +4 -0
- package/src/utils/array-utils.ts +39 -0
- package/src/utils/bigint-utils.ts +16 -0
- package/tests/array-utils.test.ts +92 -0
- package/tests/cdp.test.ts +83 -120
- package/tests/endpoints/initialize.ts +1 -1
- package/tests/lrp-leverage.test.ts +1495 -0
- package/tests/lrp.test.ts +436 -658
- package/tests/mock/assets-mock.ts +2 -2
- package/tests/queries/cdp-queries.ts +76 -0
- package/tests/queries/lrp-queries.ts +41 -4
- package/tests/staking.test.ts +71 -16
- package/tests/indigo-test-helpers.ts +0 -61
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,89 @@ 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>;
|
|
1508
|
+
|
|
1509
|
+
declare const StakingParamsSchema: _lucid_evolution_lucid.TObject<{
|
|
1510
|
+
stakingManagerNft: _lucid_evolution_lucid.TObject<{
|
|
1511
|
+
currencySymbol: _lucid_evolution_lucid.TUnsafe<string>;
|
|
1512
|
+
tokenName: _lucid_evolution_lucid.TUnsafe<string>;
|
|
1513
|
+
}>;
|
|
1514
|
+
stakingToken: _lucid_evolution_lucid.TObject<{
|
|
1515
|
+
currencySymbol: _lucid_evolution_lucid.TUnsafe<string>;
|
|
1516
|
+
tokenName: _lucid_evolution_lucid.TUnsafe<string>;
|
|
1517
|
+
}>;
|
|
1518
|
+
indyToken: _lucid_evolution_lucid.TObject<{
|
|
1519
|
+
currencySymbol: _lucid_evolution_lucid.TUnsafe<string>;
|
|
1520
|
+
tokenName: _lucid_evolution_lucid.TUnsafe<string>;
|
|
1521
|
+
}>;
|
|
1522
|
+
pollToken: _lucid_evolution_lucid.TObject<{
|
|
1523
|
+
currencySymbol: _lucid_evolution_lucid.TUnsafe<string>;
|
|
1524
|
+
tokenName: _lucid_evolution_lucid.TUnsafe<string>;
|
|
1525
|
+
}>;
|
|
1526
|
+
versionRecordToken: _lucid_evolution_lucid.TObject<{
|
|
1527
|
+
currencySymbol: _lucid_evolution_lucid.TUnsafe<string>;
|
|
1528
|
+
tokenName: _lucid_evolution_lucid.TUnsafe<string>;
|
|
1529
|
+
}>;
|
|
1530
|
+
collectorValHash: _lucid_evolution_lucid.TUnsafe<string>;
|
|
1531
|
+
}>;
|
|
1532
|
+
type StakingParams = Data.Static<typeof StakingParamsSchema>;
|
|
1533
|
+
declare const StakingParams: StakingParams;
|
|
1534
|
+
declare const StakingRedeemerSchema: _lucid_evolution_lucid.TUnion<(_lucid_evolution_lucid.TLiteral<"UpgradeVersion"> | _lucid_evolution_lucid.TObject<{
|
|
1535
|
+
CreateStakingPosition: _lucid_evolution_lucid.TObject<{
|
|
1536
|
+
creatorPkh: _lucid_evolution_lucid.TUnsafe<string>;
|
|
1537
|
+
}>;
|
|
1538
|
+
}> | _lucid_evolution_lucid.TLiteral<"UpdateTotalStake"> | _lucid_evolution_lucid.TLiteral<"Distribute"> | _lucid_evolution_lucid.TObject<{
|
|
1539
|
+
AdjustStakedAmount: _lucid_evolution_lucid.TObject<{
|
|
1540
|
+
adjustAmount: _lucid_evolution_lucid.TUnsafe<bigint>;
|
|
1541
|
+
}>;
|
|
1542
|
+
}> | _lucid_evolution_lucid.TLiteral<"Unstake"> | _lucid_evolution_lucid.TLiteral<"Lock">)[]>;
|
|
1543
|
+
type StakingRedeemer = Data.Static<typeof StakingRedeemerSchema>;
|
|
1544
|
+
declare function serialiseStakingRedeemer(redeemer: StakingRedeemer): Redeemer;
|
|
1545
|
+
declare function castStakingParams(params: StakingParams): Data;
|
|
1546
|
+
|
|
1547
|
+
declare const StakingPosLockedAmtSchema: Core.TSchema.Map<Core.TSchema.Integer, Core.TSchema.Struct<{
|
|
1548
|
+
voteAmt: Core.TSchema.Integer;
|
|
1549
|
+
votingEnd: Core.TSchema.Integer;
|
|
1550
|
+
}>>;
|
|
1551
|
+
type StakingPosLockedAmt = typeof StakingPosLockedAmtSchema.Type;
|
|
1552
|
+
declare const StakingPositionSchema: Core.TSchema.Struct<{
|
|
1553
|
+
owner: Core.TSchema.ByteArray;
|
|
1554
|
+
lockedAmount: Core.TSchema.Map<Core.TSchema.Integer, Core.TSchema.Struct<{
|
|
1555
|
+
voteAmt: Core.TSchema.Integer;
|
|
1556
|
+
votingEnd: Core.TSchema.Integer;
|
|
1557
|
+
}>>;
|
|
1558
|
+
positionSnapshot: Core.TSchema.Struct<{
|
|
1559
|
+
snapshotAda: Core.TSchema.Integer;
|
|
1560
|
+
}>;
|
|
1561
|
+
}>;
|
|
1562
|
+
type StakingPosition = typeof StakingPositionSchema.Type;
|
|
1563
|
+
declare const StakingManagerSchema: Core.TSchema.Struct<{
|
|
1564
|
+
totalStake: Core.TSchema.Integer;
|
|
1565
|
+
managerSnapshot: Core.TSchema.Struct<{
|
|
1566
|
+
snapshotAda: Core.TSchema.Integer;
|
|
1567
|
+
}>;
|
|
1568
|
+
}>;
|
|
1569
|
+
type StakingManager = typeof StakingManagerSchema.Type;
|
|
1570
|
+
declare const StakingDatumSchema: Core.TSchema.Union<[Core.TSchema.Struct<{
|
|
1571
|
+
totalStake: Core.TSchema.Integer;
|
|
1572
|
+
managerSnapshot: Core.TSchema.Struct<{
|
|
1573
|
+
snapshotAda: Core.TSchema.Integer;
|
|
1574
|
+
}>;
|
|
1575
|
+
}>, Core.TSchema.Struct<{
|
|
1576
|
+
owner: Core.TSchema.ByteArray;
|
|
1577
|
+
lockedAmount: Core.TSchema.Map<Core.TSchema.Integer, Core.TSchema.Struct<{
|
|
1578
|
+
voteAmt: Core.TSchema.Integer;
|
|
1579
|
+
votingEnd: Core.TSchema.Integer;
|
|
1580
|
+
}>>;
|
|
1581
|
+
positionSnapshot: Core.TSchema.Struct<{
|
|
1582
|
+
snapshotAda: Core.TSchema.Integer;
|
|
1583
|
+
}>;
|
|
1584
|
+
}>]>;
|
|
1585
|
+
type StakingDatum = typeof StakingDatumSchema.Type;
|
|
1586
|
+
declare function parseStakingPosition(datum: string): option.Option<StakingPosition>;
|
|
1587
|
+
declare function parseStakingPositionOrThrow(datum: string): StakingPosition;
|
|
1588
|
+
declare function parseStakingManagerDatum(datum: string): StakingManager;
|
|
1589
|
+
declare function serialiseStakingDatum(d: StakingDatum): string;
|
|
1507
1590
|
|
|
1508
1591
|
declare function startInterestOracle(initialUnitaryInterest: bigint, initialInterestRate: bigint, initialLastInterestUpdate: bigint, oracleParams: InterestOracleParams, lucid: LucidEvolution, interestTokenName?: string, withScriptRef?: boolean, refOutRef?: OutRef): Promise<[TxBuilder, AssetClass]>;
|
|
1509
1592
|
declare function feedInterestOracle(params: InterestOracleParams, newInterestRate: bigint, lucid: LucidEvolution, assetClass?: AssetClass, utxo?: UTxO, scriptRef?: UTxO): Promise<TxBuilder>;
|
|
@@ -1525,15 +1608,6 @@ declare const mkVersionRegistryValidator: () => SpendingValidator;
|
|
|
1525
1608
|
|
|
1526
1609
|
declare function treasuryFeeTx(fee: bigint, lucid: LucidEvolution, sysParams: SystemParams, tx: TxBuilder, treasuryOref: OutRef): Promise<void>;
|
|
1527
1610
|
|
|
1528
|
-
/**
|
|
1529
|
-
* Accept only a single item in the array and return it.
|
|
1530
|
-
* When not exclusively a single item, throw an error.
|
|
1531
|
-
*/
|
|
1532
|
-
declare function matchSingle<T>(xs: T[], mkErr: (xs: T[]) => Error): T;
|
|
1533
|
-
declare function loadSystemParamsFromFile(file: string): SystemParams;
|
|
1534
|
-
declare function loadSystemParamsFromUrl(url: string): Promise<SystemParams>;
|
|
1535
|
-
declare const getRandomElement: <T>(arr: T[]) => T | undefined;
|
|
1536
|
-
|
|
1537
1611
|
/**
|
|
1538
1612
|
* Returns the inline datum.
|
|
1539
1613
|
* Throws when the UTXO doesn't have an inline datum
|
|
@@ -1908,16 +1982,53 @@ declare const LRPRedeemerSchema: _lucid_evolution_lucid.TUnion<(_lucid_evolution
|
|
|
1908
1982
|
}>;
|
|
1909
1983
|
}> | _lucid_evolution_lucid.TLiteral<"Cancel">)[]>;
|
|
1910
1984
|
type LRPRedeemer = Data.Static<typeof LRPRedeemerSchema>;
|
|
1911
|
-
declare function parseLrpDatum(datum: Datum): LRPDatum
|
|
1985
|
+
declare function parseLrpDatum(datum: Datum): option.Option<LRPDatum>;
|
|
1986
|
+
declare function parseLrpDatumOrThrow(datum: Datum): LRPDatum;
|
|
1912
1987
|
declare function serialiseLrpDatum(datum: LRPDatum): Datum;
|
|
1913
1988
|
declare function serialiseLrpRedeemer(redeemer: LRPRedeemer): Redeemer;
|
|
1914
1989
|
declare function castLrpParams(params: LRPParams): Data;
|
|
1990
|
+
type LrpOutput = {
|
|
1991
|
+
datum: LRPDatum;
|
|
1992
|
+
utxo: UTxO;
|
|
1993
|
+
};
|
|
1915
1994
|
|
|
1916
|
-
declare
|
|
1917
|
-
|
|
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>;
|
|
1918
2029
|
declare function redeemLrp(
|
|
1919
2030
|
/** The tuple represents the LRP outref and the amount of iAssets to redeem against it. */
|
|
1920
|
-
redemptionLrpsData: [OutRef, bigint][],
|
|
2031
|
+
redemptionLrpsData: [OutRef, bigint][], priceOracleOutRef: OutRef, iassetOutRef: OutRef, lucid: LucidEvolution, sysParams: SystemParams): Promise<TxBuilder>;
|
|
1921
2032
|
/**
|
|
1922
2033
|
* Create Tx adjusting the LRP and claiming the received iAssets
|
|
1923
2034
|
*/
|
|
@@ -1926,11 +2037,11 @@ declare function adjustLrp(lucid: LucidEvolution, lrpOutRef: OutRef,
|
|
|
1926
2037
|
* A positive amount increases the lovelaces in the LRP,
|
|
1927
2038
|
* and a negative amount takes lovelaces from the LRP.
|
|
1928
2039
|
*/
|
|
1929
|
-
lovelacesAdjustAmt: bigint,
|
|
2040
|
+
lovelacesAdjustAmt: bigint, sysParams: SystemParams): Promise<TxBuilder>;
|
|
1930
2041
|
/**
|
|
1931
2042
|
* Create Tx claiming the received iAssets.
|
|
1932
2043
|
*/
|
|
1933
|
-
declare function claimLrp(lucid: LucidEvolution, lrpOutRef: OutRef,
|
|
2044
|
+
declare function claimLrp(lucid: LucidEvolution, lrpOutRef: OutRef, sysParams: SystemParams): Promise<TxBuilder>;
|
|
1934
2045
|
|
|
1935
2046
|
declare const mkLrpValidator: (params: LRPParams) => SpendingValidator;
|
|
1936
2047
|
declare const mkLrpValidatorFromSP: (params: LrpParamsSP) => SpendingValidator;
|
|
@@ -1956,6 +2067,21 @@ type OneShotParams = Data.Static<typeof OneShotParamsSchema>;
|
|
|
1956
2067
|
declare function oneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<[TxBuilder, PolicyId]>;
|
|
1957
2068
|
declare function runOneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<PolicyId>;
|
|
1958
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
|
+
|
|
1959
2085
|
declare function mkLovelacesOf(amount: bigint): Assets;
|
|
1960
2086
|
declare function lovelacesAmt(assets: Assets): bigint;
|
|
1961
2087
|
declare function assetClassToUnit(ac: AssetClass): Unit;
|
|
@@ -1964,4 +2090,106 @@ declare function assetClassValueOf(assets: Assets, assetClass: AssetClass): bigi
|
|
|
1964
2090
|
declare function negateAssets(assets: Assets): Assets;
|
|
1965
2091
|
declare function isAssetsZero(assets: Assets): boolean;
|
|
1966
2092
|
|
|
1967
|
-
|
|
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 };
|