@indigo-labs/indigo-sdk 0.3.8 → 0.3.10
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 +192 -32
- package/dist/index.d.ts +192 -32
- package/dist/index.js +819 -242
- package/dist/index.mjs +707 -135
- package/package.json +1 -1
- package/src/contracts/cdp/helpers.ts +12 -0
- package/src/contracts/gov/transactions.ts +4 -4
- package/src/contracts/iasset/helpers.ts +1 -0
- package/src/contracts/price-oracle/types-new.ts +1 -1
- package/src/contracts/rob/helpers.ts +274 -196
- package/src/contracts/rob/transactions.ts +11 -5
- package/src/contracts/rob-leverage/helpers.ts +379 -371
- package/src/contracts/rob-leverage/transactions.ts +176 -104
- package/src/utils/utils.ts +0 -3
- package/tests/cdp/cdp-queries.ts +1 -1
- package/tests/endpoints/initialize.ts +14 -2
- package/tests/interest-collection/interest-collector-queries.ts +2 -1
- package/tests/queries/collector-queries.ts +2 -1
- package/tests/queries/poll-queries.ts +2 -1
- package/tests/queries/treasury-queries.ts +2 -1
- package/tests/rob/rob-leverage.test.ts +1646 -612
- package/tests/rob/rob.test.ts +35 -19
- package/tests/rob/transactions-mutated.ts +6 -4
package/dist/index.mjs
CHANGED
|
@@ -387,7 +387,6 @@ function loadSystemParamsFromFile(file) {
|
|
|
387
387
|
function loadSystemParamsFromUrl(url) {
|
|
388
388
|
return fetch(url).then((res) => res.json()).then((data) => data);
|
|
389
389
|
}
|
|
390
|
-
var getRandomElement = (arr) => arr.length ? arr[Math.floor(Math.random() * arr.length)] : void 0;
|
|
391
390
|
|
|
392
391
|
// src/utils/time-helpers.ts
|
|
393
392
|
var ONE_SECOND = 1e3;
|
|
@@ -467,6 +466,11 @@ function calculateFeeFromRatio(feeRatio, amount) {
|
|
|
467
466
|
|
|
468
467
|
// src/contracts/cdp/helpers.ts
|
|
469
468
|
import { assetClassValueOf } from "@3rd-eye-labs/cardano-offchain-common";
|
|
469
|
+
function iassetValueOfCollateral(collateralAmt, oraclePrice) {
|
|
470
|
+
return rationalFloor(
|
|
471
|
+
rationalDiv(rationalFromInt(collateralAmt), oraclePrice)
|
|
472
|
+
);
|
|
473
|
+
}
|
|
470
474
|
function cdpCollateralRatioPercentage(currentSlot, iassetPrice, cdpUtxo, cdpContent, interestOracleDatum, network) {
|
|
471
475
|
const currentTime = BigInt(slotToUnixTime2(network, currentSlot));
|
|
472
476
|
return match4(cdpContent.cdpFees).with({ ActiveCDPInterestTracking: P4.select() }, (interest) => {
|
|
@@ -3653,6 +3657,7 @@ function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythS
|
|
|
3653
3657
|
}).with(
|
|
3654
3658
|
{ DeferredValidation: { feedValHash: P11.select() } },
|
|
3655
3659
|
async (feedValHash) => {
|
|
3660
|
+
if (priceOracleOref) throw new Error("Cannot pass price oracle oref");
|
|
3656
3661
|
if (!pythMessage) throw new Error("Missing Pyth message");
|
|
3657
3662
|
if (!pythStateOref) throw new Error("Missing pyth state out ref");
|
|
3658
3663
|
const pythStateUtxo = matchSingle(
|
|
@@ -5694,7 +5699,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
5694
5699
|
)
|
|
5695
5700
|
)
|
|
5696
5701
|
)
|
|
5697
|
-
).validFrom(Number(currentTime) - ONE_SECOND).validTo(Number(currentTime
|
|
5702
|
+
).validFrom(Number(currentTime) - ONE_SECOND).validTo(Number(currentTime + sysParams.govParams.gBiasTime) - ONE_SECOND).addSigner(ownAddr),
|
|
5698
5703
|
newPollId
|
|
5699
5704
|
];
|
|
5700
5705
|
}
|
|
@@ -5736,7 +5741,7 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
|
|
|
5736
5741
|
);
|
|
5737
5742
|
const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
|
|
5738
5743
|
const tx = lucid.newTx().validFrom(Number(currentTime) - ONE_SECOND).validTo(
|
|
5739
|
-
Number(currentTime
|
|
5744
|
+
Number(currentTime + sysParams.pollManagerParams.pBiasTime) - ONE_SECOND
|
|
5740
5745
|
).mintAssets(mkAssetsOf6(pollNft, shardsCount), Data30.void()).readFrom([pollAuthTokenPolicyRefScriptUtxo, pollManagerRefScriptUtxo]).collectFrom(
|
|
5741
5746
|
[pollManagerUtxo],
|
|
5742
5747
|
serialisePollManagerRedeemer({ CreateShards: { currentTime } })
|
|
@@ -5916,7 +5921,7 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
5916
5921
|
)(shardUtxos);
|
|
5917
5922
|
const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
|
|
5918
5923
|
return lucid.newTx().validFrom(Number(currentTime) - ONE_SECOND).validTo(
|
|
5919
|
-
Number(currentTime
|
|
5924
|
+
Number(currentTime + sysParams.pollManagerParams.pBiasTime) - ONE_SECOND
|
|
5920
5925
|
).readFrom([
|
|
5921
5926
|
pollShardRefScriptUtxo,
|
|
5922
5927
|
pollManagerRefScriptUtxo,
|
|
@@ -6703,7 +6708,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6703
6708
|
);
|
|
6704
6709
|
}).otherwise(() => {
|
|
6705
6710
|
});
|
|
6706
|
-
tx.readFrom([upgradeTokenPolicyRefScriptUtxo, executeRefScriptUtxo]).validFrom(Number(currentTime) - ONE_SECOND).validTo(Number(currentTime
|
|
6711
|
+
tx.readFrom([upgradeTokenPolicyRefScriptUtxo, executeRefScriptUtxo]).validFrom(Number(currentTime) - ONE_SECOND).validTo(Number(currentTime + sysParams.govParams.gBiasTime) - ONE_SECOND).collectFrom([executeUtxo], Data30.void()).mintAssets(
|
|
6707
6712
|
mkAssetsOf6(fromSystemParamsAsset(sysParams.govParams.upgradeToken), -1n),
|
|
6708
6713
|
Data30.void()
|
|
6709
6714
|
).addSigner(ownAddr).setMinFee(922932n);
|
|
@@ -8287,7 +8292,8 @@ import {
|
|
|
8287
8292
|
readonlyArray as RA3,
|
|
8288
8293
|
array as A9,
|
|
8289
8294
|
function as F16,
|
|
8290
|
-
option as O14
|
|
8295
|
+
option as O14,
|
|
8296
|
+
ord as Ord4
|
|
8291
8297
|
} from "fp-ts";
|
|
8292
8298
|
import { match as match18, P as P18 } from "ts-pattern";
|
|
8293
8299
|
import {
|
|
@@ -8298,7 +8304,7 @@ import {
|
|
|
8298
8304
|
mkAssetsOf as mkAssetsOf9
|
|
8299
8305
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
8300
8306
|
var MIN_ROB_COLLATERAL_AMT = 3000000n;
|
|
8301
|
-
function
|
|
8307
|
+
function robCollateralAmtToSpend(utxo, datum) {
|
|
8302
8308
|
return match18(datum.orderType).returnType().with({ BuyIAssetOrder: P18.select() }, (content) => {
|
|
8303
8309
|
if (isSameAssetClass3(adaAssetClass4, content.collateralAsset)) {
|
|
8304
8310
|
return zeroNegatives(
|
|
@@ -8307,24 +8313,61 @@ function robAmountToSpend(utxo, datum, sysParams) {
|
|
|
8307
8313
|
} else {
|
|
8308
8314
|
return assetClassValueOf7(utxo.assets, content.collateralAsset);
|
|
8309
8315
|
}
|
|
8310
|
-
}).
|
|
8316
|
+
}).otherwise(() => {
|
|
8317
|
+
throw new Error("Collateral to spend is relevant only for Buy orders.");
|
|
8318
|
+
});
|
|
8319
|
+
}
|
|
8320
|
+
function robIAssetAmtToSpend(utxo, datum, iassetCurrencySymbol) {
|
|
8321
|
+
return match18(datum.orderType).returnType().with({ SellIAssetOrder: P18.any }, (_) => {
|
|
8311
8322
|
return assetClassValueOf7(utxo.assets, {
|
|
8312
|
-
currencySymbol: fromHex12(
|
|
8313
|
-
sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol
|
|
8314
|
-
),
|
|
8323
|
+
currencySymbol: fromHex12(iassetCurrencySymbol.unCurrencySymbol),
|
|
8315
8324
|
tokenName: datum.iasset
|
|
8316
8325
|
});
|
|
8317
|
-
}).
|
|
8326
|
+
}).otherwise(() => {
|
|
8327
|
+
throw new Error("IAssets to spend is relevant only for Sell orders.");
|
|
8328
|
+
});
|
|
8329
|
+
}
|
|
8330
|
+
function robAmtToSpend(utxo, datum, iassetCurrencySymbol) {
|
|
8331
|
+
return match18(datum.orderType).with({ BuyIAssetOrder: P18.any }, () => robCollateralAmtToSpend(utxo, datum)).with(
|
|
8332
|
+
{ SellIAssetOrder: P18.any },
|
|
8333
|
+
() => robIAssetAmtToSpend(utxo, datum, iassetCurrencySymbol)
|
|
8334
|
+
).exhaustive();
|
|
8335
|
+
}
|
|
8336
|
+
function robBuyOrderSummary(utxo, datum, oraclePrice) {
|
|
8337
|
+
const redeemable = robCollateralAmtToSpend(utxo, datum);
|
|
8338
|
+
const payoutAmt = iassetValueOfCollateral(redeemable, oraclePrice);
|
|
8339
|
+
return {
|
|
8340
|
+
redeemableCollateral: redeemable,
|
|
8341
|
+
payoutIAsset: payoutAmt
|
|
8342
|
+
};
|
|
8318
8343
|
}
|
|
8319
|
-
function
|
|
8320
|
-
|
|
8344
|
+
function isBuyOrderFullyRedeemed(utxo, datum, oraclePrice) {
|
|
8345
|
+
const summary = robBuyOrderSummary(utxo, datum, oraclePrice);
|
|
8346
|
+
return summary.redeemableCollateral <= 0n || summary.payoutIAsset <= 0n;
|
|
8347
|
+
}
|
|
8348
|
+
function isFullyRedeemed(utxo, datum, iassetCurrencySymbol) {
|
|
8349
|
+
return match18(datum.orderType).returnType().with(
|
|
8350
|
+
{ BuyIAssetOrder: P18.select() },
|
|
8351
|
+
(content) => isBuyOrderFullyRedeemed(utxo, datum, content.maxPrice)
|
|
8352
|
+
).with({ SellIAssetOrder: P18.select() }, (content) => {
|
|
8353
|
+
const iassetToSpend = robIAssetAmtToSpend(
|
|
8354
|
+
utxo,
|
|
8355
|
+
datum,
|
|
8356
|
+
iassetCurrencySymbol
|
|
8357
|
+
);
|
|
8358
|
+
const payoutAmts = content.allowedCollateralAssets.map(
|
|
8359
|
+
(c) => rationalFloor(rationalMul(rationalFromInt(iassetToSpend), c[1]))
|
|
8360
|
+
);
|
|
8361
|
+
return iassetToSpend <= 0n || // When for every allowed collateral asset the payout would be 0
|
|
8362
|
+
payoutAmts.every((amt) => amt <= 0n);
|
|
8363
|
+
}).exhaustive();
|
|
8321
8364
|
}
|
|
8322
8365
|
function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redemptionReimbursementRatio, sysParams, tx, txOutputsBeforeCount, collateralAssetRefInputIdx, iassetRefInputIdx, oracleIdx) {
|
|
8323
8366
|
return F16.pipe(
|
|
8324
8367
|
redemptions,
|
|
8325
8368
|
A9.reduceWithIndex(
|
|
8326
8369
|
tx,
|
|
8327
|
-
(idx, acc, [robUtxo,
|
|
8370
|
+
(idx, acc, [robUtxo, payoutAmt]) => {
|
|
8328
8371
|
const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
|
|
8329
8372
|
if (toHex12(robDatum.iasset) !== toHex12(iasset)) {
|
|
8330
8373
|
throw new Error("Only same iAsset");
|
|
@@ -8335,7 +8378,7 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8335
8378
|
if (!isSameAssetClass3(content.collateralAsset, collateralAsset)) {
|
|
8336
8379
|
throw new Error("Only same collateral asset");
|
|
8337
8380
|
}
|
|
8338
|
-
const payoutIAssetAmt =
|
|
8381
|
+
const payoutIAssetAmt = payoutAmt;
|
|
8339
8382
|
const reimburstmentIAsset = calculateFeeFromRatio(
|
|
8340
8383
|
redemptionReimbursementRatio,
|
|
8341
8384
|
payoutIAssetAmt
|
|
@@ -8370,16 +8413,14 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8370
8413
|
throw new Error("Doesn't allow required collateral asset.");
|
|
8371
8414
|
})
|
|
8372
8415
|
);
|
|
8373
|
-
const payoutCollateralAmt =
|
|
8416
|
+
const payoutCollateralAmt = payoutAmt;
|
|
8374
8417
|
const reimbursementCollateral = calculateFeeFromRatio(
|
|
8375
8418
|
redemptionReimbursementRatio,
|
|
8376
8419
|
payoutCollateralAmt
|
|
8377
8420
|
);
|
|
8378
|
-
const redeemedIAssetAmt =
|
|
8379
|
-
|
|
8380
|
-
|
|
8381
|
-
price
|
|
8382
|
-
)
|
|
8421
|
+
const redeemedIAssetAmt = iassetValueOfCollateral(
|
|
8422
|
+
payoutCollateralAmt - reimbursementCollateral,
|
|
8423
|
+
price
|
|
8383
8424
|
);
|
|
8384
8425
|
const resultVal = addAssets12(
|
|
8385
8426
|
robUtxo.assets,
|
|
@@ -8397,7 +8438,9 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8397
8438
|
return [resultVal, BigInt(allowedAssetIdx)];
|
|
8398
8439
|
}).exhaustive();
|
|
8399
8440
|
if (lovelacesAmt3(robOutputVal) < MIN_ROB_COLLATERAL_AMT) {
|
|
8400
|
-
throw new Error(
|
|
8441
|
+
throw new Error(
|
|
8442
|
+
"Redeeming more than available or selected ROB was incorrectly initialised."
|
|
8443
|
+
);
|
|
8401
8444
|
}
|
|
8402
8445
|
return acc.collectFrom([robUtxo], {
|
|
8403
8446
|
kind: "self",
|
|
@@ -8408,7 +8451,7 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8408
8451
|
iassetRefInputIdx,
|
|
8409
8452
|
continuingOutputIdx: txOutputsBeforeCount + BigInt(idx),
|
|
8410
8453
|
sellOrderAllowedAssetsIdx,
|
|
8411
|
-
priceOracleIdx: oracleIdx
|
|
8454
|
+
priceOracleIdx: oracleIdx
|
|
8412
8455
|
}
|
|
8413
8456
|
})
|
|
8414
8457
|
}).pay.ToContract(
|
|
@@ -8429,6 +8472,85 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8429
8472
|
)
|
|
8430
8473
|
);
|
|
8431
8474
|
}
|
|
8475
|
+
function calculateTotalCollateralForRedemption(iasset, collateralAsset, iassetPrice, allRobs, maxRobsInTx) {
|
|
8476
|
+
return F16.pipe(
|
|
8477
|
+
allRobs,
|
|
8478
|
+
A9.filterMap(([utxo, datum]) => {
|
|
8479
|
+
const isCorrectOrder = match18(datum.orderType).returnType().with(
|
|
8480
|
+
{ BuyIAssetOrder: P18.select() },
|
|
8481
|
+
(content) => isSameAssetClass3(content.collateralAsset, collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice) && !isBuyOrderFullyRedeemed(utxo, datum, iassetPrice)
|
|
8482
|
+
).otherwise(() => false);
|
|
8483
|
+
if (toHex12(datum.iasset) !== toHex12(iasset) || !isCorrectOrder) {
|
|
8484
|
+
return O14.none;
|
|
8485
|
+
}
|
|
8486
|
+
const collateralToSpend = robCollateralAmtToSpend(utxo, datum);
|
|
8487
|
+
return O14.some(collateralToSpend);
|
|
8488
|
+
}),
|
|
8489
|
+
// From largest to smallest
|
|
8490
|
+
A9.sort(Ord4.reverse(BigIntOrd)),
|
|
8491
|
+
// We can fit only this number of redemptions with CDP open into a single Tx.
|
|
8492
|
+
A9.takeLeft(maxRobsInTx),
|
|
8493
|
+
sum
|
|
8494
|
+
);
|
|
8495
|
+
}
|
|
8496
|
+
function randomRobsSubsetSatisfyingTargetCollateral(iasset, collateralAsset, targetCollateralToSpend, iassetPrice, allLrps, maxLrpsInTx, randomiseFn = shuffle) {
|
|
8497
|
+
if (targetCollateralToSpend <= 0n || iassetValueOfCollateral(targetCollateralToSpend, iassetPrice) <= 0n) {
|
|
8498
|
+
throw new Error("Must redeem and payout more than 0.");
|
|
8499
|
+
}
|
|
8500
|
+
const shuffled = randomiseFn(
|
|
8501
|
+
F16.pipe(
|
|
8502
|
+
allLrps,
|
|
8503
|
+
A9.filter(
|
|
8504
|
+
([utxo, datum]) => toHex12(datum.iasset) === toHex12(iasset) && match18(datum.orderType).with(
|
|
8505
|
+
{ BuyIAssetOrder: P18.select() },
|
|
8506
|
+
(content) => isSameAssetClass3(collateralAsset, content.collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice)
|
|
8507
|
+
).otherwise(() => false) && !isBuyOrderFullyRedeemed(utxo, datum, iassetPrice)
|
|
8508
|
+
)
|
|
8509
|
+
)
|
|
8510
|
+
);
|
|
8511
|
+
let result = [];
|
|
8512
|
+
let runningSum = 0n;
|
|
8513
|
+
for (let i = 0; i < shuffled.length; i++) {
|
|
8514
|
+
const element = shuffled[i];
|
|
8515
|
+
const lovelacesToSpend = robCollateralAmtToSpend(element[0], element[1]);
|
|
8516
|
+
const remainingToRedeem = targetCollateralToSpend - runningSum;
|
|
8517
|
+
const remainingToPayout = iassetValueOfCollateral(
|
|
8518
|
+
remainingToRedeem,
|
|
8519
|
+
iassetPrice
|
|
8520
|
+
);
|
|
8521
|
+
if (result.length > 0 && remainingToPayout <= 0n) {
|
|
8522
|
+
const last = result[result.length - 1];
|
|
8523
|
+
const lastSummary = robBuyOrderSummary(last[0], last[1], iassetPrice);
|
|
8524
|
+
if (lastSummary.redeemableCollateral < lovelacesToSpend) {
|
|
8525
|
+
result.pop();
|
|
8526
|
+
runningSum -= lastSummary.redeemableCollateral;
|
|
8527
|
+
} else {
|
|
8528
|
+
continue;
|
|
8529
|
+
}
|
|
8530
|
+
}
|
|
8531
|
+
result = insertSorted(
|
|
8532
|
+
result,
|
|
8533
|
+
element,
|
|
8534
|
+
Ord4.contramap(
|
|
8535
|
+
([utxo, dat]) => robCollateralAmtToSpend(utxo, dat)
|
|
8536
|
+
// From highest to lowest
|
|
8537
|
+
)(Ord4.reverse(BigIntOrd))
|
|
8538
|
+
);
|
|
8539
|
+
runningSum += lovelacesToSpend;
|
|
8540
|
+
if (result.length > maxLrpsInTx) {
|
|
8541
|
+
const popped = result.pop();
|
|
8542
|
+
runningSum -= robCollateralAmtToSpend(popped[0], popped[1]);
|
|
8543
|
+
}
|
|
8544
|
+
if (runningSum >= targetCollateralToSpend) {
|
|
8545
|
+
return result;
|
|
8546
|
+
}
|
|
8547
|
+
}
|
|
8548
|
+
const remainingToSpend = targetCollateralToSpend - runningSum;
|
|
8549
|
+
if (remainingToSpend > 0n && iassetValueOfCollateral(remainingToSpend, iassetPrice) > 0n) {
|
|
8550
|
+
throw new Error("Couldn't achieve target lovelaces");
|
|
8551
|
+
}
|
|
8552
|
+
return result;
|
|
8553
|
+
}
|
|
8432
8554
|
|
|
8433
8555
|
// src/contracts/rob/types.ts
|
|
8434
8556
|
import { Data as Data44 } from "@lucid-evolution/lucid";
|
|
@@ -8586,7 +8708,7 @@ async function redeemRob(redemptionRobsData, priceOracleOutRef, iassetOutRef, co
|
|
|
8586
8708
|
0n,
|
|
8587
8709
|
refInputIdxs[2],
|
|
8588
8710
|
refInputIdxs[1],
|
|
8589
|
-
priceOracleOutRef !== void 0 ? refInputIdxs[3] :
|
|
8711
|
+
priceOracleOutRef !== void 0 ? { OracleRefInputIdx: refInputIdxs[3] } : "OracleVoid"
|
|
8590
8712
|
);
|
|
8591
8713
|
tx.readFrom(allRefInputs);
|
|
8592
8714
|
return tx;
|
|
@@ -8603,12 +8725,12 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
|
|
|
8603
8725
|
(_) => new Error("Expected a single ROB UTXO.")
|
|
8604
8726
|
);
|
|
8605
8727
|
const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
|
|
8606
|
-
if (adjustmentAmt === 0n && isFullyRedeemed(robUtxo, robDatum, sysParams)) {
|
|
8728
|
+
if (adjustmentAmt === 0n && isFullyRedeemed(robUtxo, robDatum, sysParams.cdpParams.cdpAssetSymbol)) {
|
|
8607
8729
|
throw new Error(
|
|
8608
8730
|
"When there's no more lovelaces to spend, use close instead of claim."
|
|
8609
8731
|
);
|
|
8610
8732
|
}
|
|
8611
|
-
if (adjustmentAmt < 0 &&
|
|
8733
|
+
if (adjustmentAmt < 0 && robAmtToSpend(robUtxo, robDatum, sysParams.cdpParams.cdpAssetSymbol) <= -adjustmentAmt) {
|
|
8612
8734
|
throw new Error(
|
|
8613
8735
|
"Can't adjust negatively by more than available. Also, for adjusting by exactly the amount deposited, a close action should be used instead."
|
|
8614
8736
|
);
|
|
@@ -8729,13 +8851,451 @@ var mkRobValidatorFromSP = (params) => {
|
|
|
8729
8851
|
};
|
|
8730
8852
|
};
|
|
8731
8853
|
|
|
8732
|
-
// src/contracts/
|
|
8854
|
+
// src/contracts/rob-leverage/transactions.ts
|
|
8733
8855
|
import {
|
|
8734
8856
|
addAssets as addAssets14,
|
|
8857
|
+
slotToUnixTime as slotToUnixTime10,
|
|
8735
8858
|
Data as Data45,
|
|
8736
8859
|
fromHex as fromHex14,
|
|
8860
|
+
getInputIndices as getInputIndices5
|
|
8861
|
+
} from "@lucid-evolution/lucid";
|
|
8862
|
+
|
|
8863
|
+
// src/contracts/rob-leverage/helpers.ts
|
|
8864
|
+
import { array as A11, function as F18 } from "fp-ts";
|
|
8865
|
+
import { Decimal } from "decimal.js";
|
|
8866
|
+
var MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
|
|
8867
|
+
function approximateLeverageRedemptions(baseCollateral, targetLeverage, redemptionReimbursementRatio, debtMintingFeeRatio) {
|
|
8868
|
+
const debtMintingFeeRatioDecimal = Decimal(debtMintingFeeRatio.numerator).div(
|
|
8869
|
+
debtMintingFeeRatio.denominator
|
|
8870
|
+
);
|
|
8871
|
+
const redemptionReimbursementRatioDecimal = Decimal(
|
|
8872
|
+
redemptionReimbursementRatio.numerator
|
|
8873
|
+
).div(redemptionReimbursementRatio.denominator);
|
|
8874
|
+
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
8875
|
+
redemptionReimbursementRatioDecimal
|
|
8876
|
+
);
|
|
8877
|
+
const bExFees = Decimal(baseCollateral).mul(targetLeverage).minus(baseCollateral).floor();
|
|
8878
|
+
const b = bExFees.div(Decimal(1).minus(totalFeeRatio)).floor();
|
|
8879
|
+
const collateralRatio = {
|
|
8880
|
+
numerator: fromDecimal(Decimal(baseCollateral).add(bExFees)),
|
|
8881
|
+
denominator: fromDecimal(b)
|
|
8882
|
+
};
|
|
8883
|
+
return {
|
|
8884
|
+
leverage: targetLeverage,
|
|
8885
|
+
collateralRatio,
|
|
8886
|
+
redeemedCollateral: fromDecimal(bExFees)
|
|
8887
|
+
};
|
|
8888
|
+
}
|
|
8889
|
+
function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement, redemptionReimbursementRatio, iassetPrice, redemptionLrps) {
|
|
8890
|
+
const priceDecimal = Decimal(iassetPrice.numerator).div(
|
|
8891
|
+
iassetPrice.denominator
|
|
8892
|
+
);
|
|
8893
|
+
const reimbRatio = Decimal(redemptionReimbursementRatio.numerator).div(
|
|
8894
|
+
redemptionReimbursementRatio.denominator
|
|
8895
|
+
);
|
|
8896
|
+
const redemptionDetails = F18.pipe(
|
|
8897
|
+
redemptionLrps,
|
|
8898
|
+
A11.reduce(
|
|
8899
|
+
{
|
|
8900
|
+
remainingCollateralToSpend: lovelacesForRedemptionWithReimbursement,
|
|
8901
|
+
redemptions: []
|
|
8902
|
+
},
|
|
8903
|
+
(acc, lrp) => {
|
|
8904
|
+
if (acc.remainingCollateralToSpend <= 0n || iassetValueOfCollateral(
|
|
8905
|
+
acc.remainingCollateralToSpend,
|
|
8906
|
+
iassetPrice
|
|
8907
|
+
) <= 0n) {
|
|
8908
|
+
return acc;
|
|
8909
|
+
}
|
|
8910
|
+
const collateralToSpend = robCollateralAmtToSpend(lrp[0], lrp[1]);
|
|
8911
|
+
if (collateralToSpend === 0n) {
|
|
8912
|
+
return acc;
|
|
8913
|
+
}
|
|
8914
|
+
const newRemainingCollateral = bigintMax(
|
|
8915
|
+
acc.remainingCollateralToSpend - collateralToSpend,
|
|
8916
|
+
0n
|
|
8917
|
+
);
|
|
8918
|
+
const collateralToSpendInitial = acc.remainingCollateralToSpend - newRemainingCollateral;
|
|
8919
|
+
const finalPayoutIAssets = fromDecimal(
|
|
8920
|
+
Decimal(collateralToSpendInitial).div(priceDecimal).floor().div(Decimal(1).minus(reimbRatio)).floor()
|
|
8921
|
+
);
|
|
8922
|
+
const feeIAssetAmt = calculateFeeFromRatio(
|
|
8923
|
+
redemptionReimbursementRatio,
|
|
8924
|
+
finalPayoutIAssets
|
|
8925
|
+
);
|
|
8926
|
+
const finalCollateralToSpend = rationalFloor(
|
|
8927
|
+
rationalMul(
|
|
8928
|
+
rationalFromInt(finalPayoutIAssets - feeIAssetAmt),
|
|
8929
|
+
iassetPrice
|
|
8930
|
+
)
|
|
8931
|
+
);
|
|
8932
|
+
return {
|
|
8933
|
+
remainingCollateralToSpend: acc.remainingCollateralToSpend - finalCollateralToSpend,
|
|
8934
|
+
redemptions: [
|
|
8935
|
+
...acc.redemptions,
|
|
8936
|
+
{
|
|
8937
|
+
utxo: lrp[0],
|
|
8938
|
+
iassetsPayoutAmt: finalPayoutIAssets,
|
|
8939
|
+
redeemedCollateral: finalCollateralToSpend,
|
|
8940
|
+
reimbursementIAssetAmt: feeIAssetAmt
|
|
8941
|
+
}
|
|
8942
|
+
]
|
|
8943
|
+
};
|
|
8944
|
+
}
|
|
8945
|
+
)
|
|
8946
|
+
);
|
|
8947
|
+
const res = F18.pipe(
|
|
8948
|
+
redemptionDetails.redemptions,
|
|
8949
|
+
A11.reduce(
|
|
8950
|
+
{
|
|
8951
|
+
redeemedCollateral: 0n,
|
|
8952
|
+
payoutIAssets: 0n,
|
|
8953
|
+
reimbursementIAssets: 0n
|
|
8954
|
+
},
|
|
8955
|
+
(acc, details) => {
|
|
8956
|
+
return {
|
|
8957
|
+
redeemedCollateral: acc.redeemedCollateral + details.redeemedCollateral,
|
|
8958
|
+
reimbursementIAssets: acc.reimbursementIAssets + details.reimbursementIAssetAmt,
|
|
8959
|
+
payoutIAssets: acc.payoutIAssets + details.iassetsPayoutAmt
|
|
8960
|
+
};
|
|
8961
|
+
}
|
|
8962
|
+
)
|
|
8963
|
+
);
|
|
8964
|
+
return {
|
|
8965
|
+
redemptions: redemptionDetails.redemptions,
|
|
8966
|
+
totalRedeemedCollateral: res.redeemedCollateral,
|
|
8967
|
+
totalReimbursedIAsset: res.reimbursementIAssets,
|
|
8968
|
+
totalIAssetPayout: res.payoutIAssets
|
|
8969
|
+
};
|
|
8970
|
+
}
|
|
8971
|
+
function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage, baseCollateral, iassetPrice, debtMintingFeePercentage, redemptionReimbursementPercentage, allLrps) {
|
|
8972
|
+
const debtMintingFeeRatioDecimal = Decimal(
|
|
8973
|
+
debtMintingFeePercentage.getOnChainInt
|
|
8974
|
+
).div(OCD_DECIMAL_UNIT).div(100);
|
|
8975
|
+
const redemptionReimbursementRatioDecimal = Decimal(
|
|
8976
|
+
redemptionReimbursementPercentage.getOnChainInt
|
|
8977
|
+
).div(OCD_DECIMAL_UNIT).div(100);
|
|
8978
|
+
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
8979
|
+
redemptionReimbursementRatioDecimal
|
|
8980
|
+
);
|
|
8981
|
+
const maxAvailableCollateralForRedemption = calculateTotalCollateralForRedemption(
|
|
8982
|
+
iasset,
|
|
8983
|
+
collateralAsset,
|
|
8984
|
+
iassetPrice,
|
|
8985
|
+
allLrps,
|
|
8986
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN
|
|
8987
|
+
);
|
|
8988
|
+
if (leverage <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
|
|
8989
|
+
return void 0;
|
|
8990
|
+
}
|
|
8991
|
+
const bExFees = Decimal(baseCollateral).mul(leverage).minus(baseCollateral).floor();
|
|
8992
|
+
const b = bExFees.div(Decimal(1).minus(totalFeeRatio)).floor();
|
|
8993
|
+
const cappedB = bigintMin(
|
|
8994
|
+
maxAvailableCollateralForRedemption,
|
|
8995
|
+
fromDecimal(b)
|
|
8996
|
+
);
|
|
8997
|
+
const cappedBExFees = Decimal(cappedB).mul(Decimal(1).minus(totalFeeRatio)).floor();
|
|
8998
|
+
const collateralRatio = Decimal(
|
|
8999
|
+
Decimal(baseCollateral).add(cappedBExFees)
|
|
9000
|
+
).div(cappedB);
|
|
9001
|
+
return {
|
|
9002
|
+
getOnChainInt: fromDecimal(
|
|
9003
|
+
collateralRatio.mul(100n * OCD_DECIMAL_UNIT).floor()
|
|
9004
|
+
)
|
|
9005
|
+
};
|
|
9006
|
+
}
|
|
9007
|
+
function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collateralRatio, baseCollateral, iassetPrice, debtMintingFeeRatio, redemptionReimbursementRatio, allLrps) {
|
|
9008
|
+
const debtMintingFeeRatioDecimal = Decimal(debtMintingFeeRatio.numerator).div(
|
|
9009
|
+
debtMintingFeeRatio.denominator
|
|
9010
|
+
);
|
|
9011
|
+
const redemptionReimbursementRatioDecimal = Decimal(
|
|
9012
|
+
redemptionReimbursementRatio.numerator
|
|
9013
|
+
).div(redemptionReimbursementRatio.denominator);
|
|
9014
|
+
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
9015
|
+
redemptionReimbursementRatioDecimal
|
|
9016
|
+
);
|
|
9017
|
+
const collateralRatioDecimal = Decimal(collateralRatio.numerator).div(
|
|
9018
|
+
collateralRatio.denominator
|
|
9019
|
+
);
|
|
9020
|
+
const maxAvailableCollateralForRedemption = calculateTotalCollateralForRedemption(
|
|
9021
|
+
iasset,
|
|
9022
|
+
collateralAsset,
|
|
9023
|
+
iassetPrice,
|
|
9024
|
+
allLrps,
|
|
9025
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN
|
|
9026
|
+
);
|
|
9027
|
+
if (collateralRatioDecimal.toNumber() <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
|
|
9028
|
+
return void 0;
|
|
9029
|
+
}
|
|
9030
|
+
const theoreticalMaxLeverage = Decimal(Decimal(1).minus(totalFeeRatio)).div(collateralRatioDecimal.minus(1).add(totalFeeRatio)).add(1);
|
|
9031
|
+
const bExFees = theoreticalMaxLeverage.mul(baseCollateral).minus(baseCollateral).floor();
|
|
9032
|
+
const b = bExFees.div(Decimal(1).minus(totalFeeRatio)).floor();
|
|
9033
|
+
const cappedB = bigintMin(
|
|
9034
|
+
maxAvailableCollateralForRedemption,
|
|
9035
|
+
fromDecimal(b)
|
|
9036
|
+
);
|
|
9037
|
+
const cappedBExFees = Decimal(cappedB).mul(Decimal(1).minus(totalFeeRatio)).floor();
|
|
9038
|
+
return Decimal(baseCollateral).add(cappedBExFees).div(baseCollateral).toNumber();
|
|
9039
|
+
}
|
|
9040
|
+
|
|
9041
|
+
// src/contracts/rob-leverage/transactions.ts
|
|
9042
|
+
import { mkAssetsOf as mkAssetsOf11 } from "@3rd-eye-labs/cardano-offchain-common";
|
|
9043
|
+
import Decimal2 from "decimal.js";
|
|
9044
|
+
async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, cdpCreatorOref, interestOracleOref, treasuryOref, sysParams, lucid, allRobs, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
|
|
9045
|
+
const network = lucid.config().network;
|
|
9046
|
+
const currentTime = BigInt(slotToUnixTime10(network, currentSlot));
|
|
9047
|
+
const [pkh, skh] = await addrDetails(lucid);
|
|
9048
|
+
const robScriptRefUtxo = matchSingle(
|
|
9049
|
+
await lucid.utxosByOutRef([
|
|
9050
|
+
fromSystemParamsScriptRef(sysParams.scriptReferences.robValidatorRef)
|
|
9051
|
+
]),
|
|
9052
|
+
(_2) => new Error("Expected a single ROB Ref Script UTXO")
|
|
9053
|
+
);
|
|
9054
|
+
const cdpCreatorRefScriptUtxo = matchSingle(
|
|
9055
|
+
await lucid.utxosByOutRef([
|
|
9056
|
+
fromSystemParamsScriptRef(
|
|
9057
|
+
sysParams.scriptReferences.cdpCreatorValidatorRef
|
|
9058
|
+
)
|
|
9059
|
+
]),
|
|
9060
|
+
(_2) => new Error("Expected a single cdp creator Ref Script UTXO")
|
|
9061
|
+
);
|
|
9062
|
+
const cdpAuthTokenPolicyRefScriptUtxo = matchSingle(
|
|
9063
|
+
await lucid.utxosByOutRef([
|
|
9064
|
+
fromSystemParamsScriptRef(
|
|
9065
|
+
sysParams.scriptReferences.authTokenPolicies.cdpAuthTokenRef
|
|
9066
|
+
)
|
|
9067
|
+
]),
|
|
9068
|
+
(_2) => new Error("Expected a single cdp auth token policy Ref Script UTXO")
|
|
9069
|
+
);
|
|
9070
|
+
const iAssetTokenPolicyRefScriptUtxo = matchSingle(
|
|
9071
|
+
await lucid.utxosByOutRef([
|
|
9072
|
+
fromSystemParamsScriptRef(
|
|
9073
|
+
sysParams.scriptReferences.iAssetTokenPolicyRef
|
|
9074
|
+
)
|
|
9075
|
+
]),
|
|
9076
|
+
(_2) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
9077
|
+
);
|
|
9078
|
+
const cdpCreatorUtxo = matchSingle(
|
|
9079
|
+
await lucid.utxosByOutRef([cdpCreatorOref]),
|
|
9080
|
+
(_2) => new Error("Expected a single CDP creator UTXO")
|
|
9081
|
+
);
|
|
9082
|
+
const interestOracleUtxo = matchSingle(
|
|
9083
|
+
await lucid.utxosByOutRef([interestOracleOref]),
|
|
9084
|
+
(_2) => new Error("Expected a single interest oracle UTXO")
|
|
9085
|
+
);
|
|
9086
|
+
const interestOracleDatum = parseInterestOracleDatum(
|
|
9087
|
+
getInlineDatumOrThrow(interestOracleUtxo)
|
|
9088
|
+
);
|
|
9089
|
+
const iassetUtxo = matchSingle(
|
|
9090
|
+
await lucid.utxosByOutRef([iassetOutRef]),
|
|
9091
|
+
(_2) => new Error("Expected a single IAsset UTXO")
|
|
9092
|
+
);
|
|
9093
|
+
const iassetDatum = parseIAssetDatumOrThrow(
|
|
9094
|
+
getInlineDatumOrThrow(iassetUtxo)
|
|
9095
|
+
);
|
|
9096
|
+
const collateralAssetUtxo = matchSingle(
|
|
9097
|
+
await lucid.utxosByOutRef([collateralAssetOutRef]),
|
|
9098
|
+
(_2) => new Error("Expected a single collateral asset UTXO")
|
|
9099
|
+
);
|
|
9100
|
+
const collateralAssetDatum = parseCollateralAssetDatumOrThrow(
|
|
9101
|
+
getInlineDatumOrThrow(collateralAssetUtxo)
|
|
9102
|
+
);
|
|
9103
|
+
const [price, _] = await retrieveAdjustedPrice(
|
|
9104
|
+
iassetDatum.assetName,
|
|
9105
|
+
collateralAssetDatum.collateralAsset,
|
|
9106
|
+
collateralAssetDatum.priceInfo,
|
|
9107
|
+
collateralAssetDatum.extraDecimals,
|
|
9108
|
+
priceOracleOutRef,
|
|
9109
|
+
pythMessage,
|
|
9110
|
+
sysParams.pythConfig,
|
|
9111
|
+
lucid
|
|
9112
|
+
);
|
|
9113
|
+
const maxLeverage = calculateLeverageFromCollateralRatio(
|
|
9114
|
+
collateralAssetDatum.iasset,
|
|
9115
|
+
collateralAssetDatum.collateralAsset,
|
|
9116
|
+
collateralAssetDatum.maintenanceRatio,
|
|
9117
|
+
baseCollateral,
|
|
9118
|
+
price,
|
|
9119
|
+
iassetDatum.debtMintingFeeRatio,
|
|
9120
|
+
iassetDatum.redemptionReimbursementRatio,
|
|
9121
|
+
allRobs
|
|
9122
|
+
);
|
|
9123
|
+
if (!maxLeverage) {
|
|
9124
|
+
throw new Error("Can't calculate max leverage with those parameters.");
|
|
9125
|
+
}
|
|
9126
|
+
const leverageSummary = approximateLeverageRedemptions(
|
|
9127
|
+
baseCollateral,
|
|
9128
|
+
leverage,
|
|
9129
|
+
iassetDatum.redemptionProcessingFeeRatio,
|
|
9130
|
+
iassetDatum.debtMintingFeeRatio
|
|
9131
|
+
);
|
|
9132
|
+
if (maxLeverage < leverageSummary.leverage) {
|
|
9133
|
+
throw new Error("Can't use more leverage than max.");
|
|
9134
|
+
}
|
|
9135
|
+
if (rationalToFloat(leverageSummary.collateralRatio) < rationalToFloat(collateralAssetDatum.maintenanceRatio)) {
|
|
9136
|
+
throw new Error(
|
|
9137
|
+
"Can't have collateral ratio smaller than maintenance ratio"
|
|
9138
|
+
);
|
|
9139
|
+
}
|
|
9140
|
+
const redemptionDetails = summarizeActualLeverageRedemptions(
|
|
9141
|
+
leverageSummary.redeemedCollateral,
|
|
9142
|
+
iassetDatum.redemptionReimbursementRatio,
|
|
9143
|
+
price,
|
|
9144
|
+
randomRobsSubsetSatisfyingTargetCollateral(
|
|
9145
|
+
iassetDatum.assetName,
|
|
9146
|
+
collateralAssetDatum.collateralAsset,
|
|
9147
|
+
leverageSummary.redeemedCollateral,
|
|
9148
|
+
price,
|
|
9149
|
+
allRobs,
|
|
9150
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN
|
|
9151
|
+
)
|
|
9152
|
+
);
|
|
9153
|
+
const mintedAmt = fromDecimal(
|
|
9154
|
+
Decimal2(redemptionDetails.totalIAssetPayout).div(
|
|
9155
|
+
Decimal2(1).minus(
|
|
9156
|
+
Decimal2(iassetDatum.debtMintingFeeRatio.numerator).div(
|
|
9157
|
+
iassetDatum.debtMintingFeeRatio.denominator
|
|
9158
|
+
)
|
|
9159
|
+
)
|
|
9160
|
+
).floor()
|
|
9161
|
+
);
|
|
9162
|
+
const debtMintingFee = calculateFeeFromRatio(
|
|
9163
|
+
iassetDatum.debtMintingFeeRatio,
|
|
9164
|
+
mintedAmt
|
|
9165
|
+
);
|
|
9166
|
+
const collateralAmt = redemptionDetails.totalRedeemedCollateral + baseCollateral;
|
|
9167
|
+
const cdpNftVal = mkAssetsOf11(
|
|
9168
|
+
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
9169
|
+
1n
|
|
9170
|
+
);
|
|
9171
|
+
const iassetClass = {
|
|
9172
|
+
currencySymbol: fromHex14(
|
|
9173
|
+
sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol
|
|
9174
|
+
),
|
|
9175
|
+
tokenName: iassetDatum.assetName
|
|
9176
|
+
};
|
|
9177
|
+
const iassetTokensVal = mkAssetsOf11(iassetClass, mintedAmt);
|
|
9178
|
+
const refScripts = [
|
|
9179
|
+
cdpCreatorRefScriptUtxo,
|
|
9180
|
+
cdpAuthTokenPolicyRefScriptUtxo,
|
|
9181
|
+
iAssetTokenPolicyRefScriptUtxo,
|
|
9182
|
+
robScriptRefUtxo
|
|
9183
|
+
];
|
|
9184
|
+
const tx = lucid.newTx().readFrom(refScripts).mintAssets(cdpNftVal, Data45.void()).mintAssets(iassetTokensVal, Data45.void()).pay.ToContract(
|
|
9185
|
+
createScriptAddress(network, sysParams.validatorHashes.cdpHash, skh),
|
|
9186
|
+
{
|
|
9187
|
+
kind: "inline",
|
|
9188
|
+
value: serialiseCdpDatum({
|
|
9189
|
+
cdpOwner: fromHex14(pkh.hash),
|
|
9190
|
+
iasset: iassetDatum.assetName,
|
|
9191
|
+
collateralAsset: collateralAssetDatum.collateralAsset,
|
|
9192
|
+
mintedAmt,
|
|
9193
|
+
cdpFees: {
|
|
9194
|
+
ActiveCDPInterestTracking: {
|
|
9195
|
+
lastSettled: currentTime,
|
|
9196
|
+
unitaryInterestSnapshot: calculateUnitaryInterestSinceOracleLastUpdated(
|
|
9197
|
+
currentTime,
|
|
9198
|
+
interestOracleDatum
|
|
9199
|
+
) + interestOracleDatum.unitaryInterest
|
|
9200
|
+
}
|
|
9201
|
+
}
|
|
9202
|
+
})
|
|
9203
|
+
},
|
|
9204
|
+
addAssets14(
|
|
9205
|
+
cdpNftVal,
|
|
9206
|
+
mkAssetsOf11(collateralAssetDatum.collateralAsset, collateralAmt)
|
|
9207
|
+
)
|
|
9208
|
+
).pay.ToContract(
|
|
9209
|
+
cdpCreatorUtxo.address,
|
|
9210
|
+
{
|
|
9211
|
+
kind: "inline",
|
|
9212
|
+
value: serialiseCDPCreatorDatum({
|
|
9213
|
+
creatorInputOref: {
|
|
9214
|
+
outputIndex: BigInt(cdpCreatorUtxo.outputIndex),
|
|
9215
|
+
txHash: fromHex14(cdpCreatorUtxo.txHash)
|
|
9216
|
+
}
|
|
9217
|
+
})
|
|
9218
|
+
},
|
|
9219
|
+
cdpCreatorUtxo.assets
|
|
9220
|
+
);
|
|
9221
|
+
const treasuryRefScriptUtxo = debtMintingFee > 0n ? await treasuryFeeTx(
|
|
9222
|
+
iassetClass,
|
|
9223
|
+
debtMintingFee,
|
|
9224
|
+
0n,
|
|
9225
|
+
lucid,
|
|
9226
|
+
sysParams,
|
|
9227
|
+
tx,
|
|
9228
|
+
cdpCreatorUtxo,
|
|
9229
|
+
treasuryOref
|
|
9230
|
+
) : void 0;
|
|
9231
|
+
const { interval, referenceInputs: refInputs } = await attachOracle(
|
|
9232
|
+
iassetDatum.assetName,
|
|
9233
|
+
collateralAssetDatum.collateralAsset,
|
|
9234
|
+
collateralAssetDatum.priceInfo,
|
|
9235
|
+
priceOracleOutRef,
|
|
9236
|
+
pythStateOref,
|
|
9237
|
+
pythMessage,
|
|
9238
|
+
sysParams.pythConfig,
|
|
9239
|
+
sysParams.cdpCreatorParams.biasTime,
|
|
9240
|
+
currentSlot,
|
|
9241
|
+
lucid,
|
|
9242
|
+
tx
|
|
9243
|
+
);
|
|
9244
|
+
const referenceInputs = [
|
|
9245
|
+
interestOracleUtxo,
|
|
9246
|
+
iassetUtxo,
|
|
9247
|
+
collateralAssetUtxo,
|
|
9248
|
+
...refInputs
|
|
9249
|
+
];
|
|
9250
|
+
const refInputsIndices = getInputIndices5(referenceInputs, [
|
|
9251
|
+
...referenceInputs,
|
|
9252
|
+
...refScripts,
|
|
9253
|
+
...treasuryRefScriptUtxo != null ? [treasuryRefScriptUtxo] : []
|
|
9254
|
+
]);
|
|
9255
|
+
const oracleIdx = priceOracleOutRef !== void 0 ? { OracleRefInputIdx: refInputsIndices[3] } : "OracleVoid";
|
|
9256
|
+
tx.validFrom(interval.validFrom).validTo(interval.validTo).readFrom(referenceInputs).collectFrom([cdpCreatorUtxo], {
|
|
9257
|
+
kind: "self",
|
|
9258
|
+
makeRedeemer: (inputIdx) => {
|
|
9259
|
+
return serialiseCDPCreatorRedeemer({
|
|
9260
|
+
CreateCDP: {
|
|
9261
|
+
cdpOwner: fromHex14(pkh.hash),
|
|
9262
|
+
minted: mintedAmt,
|
|
9263
|
+
collateralAmt,
|
|
9264
|
+
currentTime,
|
|
9265
|
+
creatorInputIdx: inputIdx,
|
|
9266
|
+
creatorOutputIdx: 1n,
|
|
9267
|
+
cdpOutputIdx: 0n,
|
|
9268
|
+
iassetRefInputIdx: refInputsIndices[1],
|
|
9269
|
+
collateralAssetRefInputIdx: refInputsIndices[2],
|
|
9270
|
+
interestOracleRefInputIdx: refInputsIndices[0],
|
|
9271
|
+
priceOracleIdx: oracleIdx
|
|
9272
|
+
}
|
|
9273
|
+
});
|
|
9274
|
+
}
|
|
9275
|
+
});
|
|
9276
|
+
buildRedemptionsTx(
|
|
9277
|
+
redemptionDetails.redemptions.map((r) => [r.utxo, r.iassetsPayoutAmt]),
|
|
9278
|
+
iassetDatum.assetName,
|
|
9279
|
+
collateralAssetDatum.collateralAsset,
|
|
9280
|
+
price,
|
|
9281
|
+
iassetDatum.redemptionReimbursementRatio,
|
|
9282
|
+
sysParams,
|
|
9283
|
+
tx,
|
|
9284
|
+
2n + (debtMintingFee > 0n ? 1n : 0n),
|
|
9285
|
+
refInputsIndices[2],
|
|
9286
|
+
refInputsIndices[1],
|
|
9287
|
+
oracleIdx
|
|
9288
|
+
);
|
|
9289
|
+
return tx;
|
|
9290
|
+
}
|
|
9291
|
+
|
|
9292
|
+
// src/contracts/price-oracle/transactions.ts
|
|
9293
|
+
import {
|
|
9294
|
+
addAssets as addAssets15,
|
|
9295
|
+
Data as Data46,
|
|
9296
|
+
fromHex as fromHex15,
|
|
8737
9297
|
fromText as fromText10,
|
|
8738
|
-
slotToUnixTime as
|
|
9298
|
+
slotToUnixTime as slotToUnixTime11,
|
|
8739
9299
|
validatorToAddress as validatorToAddress2
|
|
8740
9300
|
} from "@lucid-evolution/lucid";
|
|
8741
9301
|
|
|
@@ -8762,11 +9322,11 @@ function mkPriceOracleValidator(params) {
|
|
|
8762
9322
|
}
|
|
8763
9323
|
|
|
8764
9324
|
// src/contracts/price-oracle/transactions.ts
|
|
8765
|
-
import { mkAssetsOf as
|
|
9325
|
+
import { mkAssetsOf as mkAssetsOf12 } from "@3rd-eye-labs/cardano-offchain-common";
|
|
8766
9326
|
import * as Core2 from "@evolution-sdk/evolution";
|
|
8767
9327
|
async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, currentSlot, refOutRef, auxiliaryData) {
|
|
8768
9328
|
const network = lucid.config().network;
|
|
8769
|
-
const now = BigInt(
|
|
9329
|
+
const now = BigInt(slotToUnixTime11(network, currentSlot));
|
|
8770
9330
|
if (!refOutRef) {
|
|
8771
9331
|
refOutRef = (await lucid.wallet().getUtxos())[0];
|
|
8772
9332
|
}
|
|
@@ -8783,25 +9343,25 @@ async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, cu
|
|
|
8783
9343
|
]
|
|
8784
9344
|
});
|
|
8785
9345
|
const priceOracleNft = {
|
|
8786
|
-
currencySymbol:
|
|
8787
|
-
tokenName:
|
|
9346
|
+
currencySymbol: fromHex15(oracleNftPolicyId),
|
|
9347
|
+
tokenName: fromHex15(fromText10(assetName))
|
|
8788
9348
|
};
|
|
8789
9349
|
const oracleValidator = mkPriceOracleValidator(oracleParams);
|
|
8790
9350
|
const oracleDatum = {
|
|
8791
9351
|
price: startPrice,
|
|
8792
9352
|
expirationTime: BigInt(now) + oracleParams.expirationPeriod,
|
|
8793
|
-
auxiliaryData: auxiliaryData ?? Core2.Data.fromCBORHex(
|
|
9353
|
+
auxiliaryData: auxiliaryData ?? Core2.Data.fromCBORHex(Data46.void())
|
|
8794
9354
|
};
|
|
8795
9355
|
tx.pay.ToContract(
|
|
8796
9356
|
validatorToAddress2(lucid.config().network, oracleValidator),
|
|
8797
9357
|
{ kind: "inline", value: serialisePriceOracleDatum(oracleDatum) },
|
|
8798
|
-
|
|
9358
|
+
addAssets15(mkAssetsOf12(priceOracleNft, 1n))
|
|
8799
9359
|
);
|
|
8800
9360
|
return [tx, priceOracleNft];
|
|
8801
9361
|
}
|
|
8802
9362
|
async function feedPriceOracleTx(lucid, oracleOref, newPrice, oracleParams, currentSlot, auxiliaryData) {
|
|
8803
9363
|
const network = lucid.config().network;
|
|
8804
|
-
const currentTime = BigInt(
|
|
9364
|
+
const currentTime = BigInt(slotToUnixTime11(network, currentSlot));
|
|
8805
9365
|
const priceOracleUtxo = matchSingle(
|
|
8806
9366
|
await lucid.utxosByOutRef([oracleOref]),
|
|
8807
9367
|
(_) => new Error("Expected a single price oracle UTXO")
|
|
@@ -8820,7 +9380,7 @@ async function feedPriceOracleTx(lucid, oracleOref, newPrice, oracleParams, curr
|
|
|
8820
9380
|
value: serialisePriceOracleDatum({
|
|
8821
9381
|
price: newPrice,
|
|
8822
9382
|
expirationTime: currentTime + oracleParams.expirationPeriod,
|
|
8823
|
-
auxiliaryData: auxiliaryData ?? Core2.Data.fromCBORHex(
|
|
9383
|
+
auxiliaryData: auxiliaryData ?? Core2.Data.fromCBORHex(Data46.void())
|
|
8824
9384
|
})
|
|
8825
9385
|
},
|
|
8826
9386
|
priceOracleUtxo.assets
|
|
@@ -8848,10 +9408,10 @@ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
|
|
|
8848
9408
|
|
|
8849
9409
|
// src/contracts/initialize/helpers.ts
|
|
8850
9410
|
import {
|
|
8851
|
-
addAssets as
|
|
9411
|
+
addAssets as addAssets16,
|
|
8852
9412
|
credentialToAddress as credentialToAddress4,
|
|
8853
|
-
Data as
|
|
8854
|
-
fromHex as
|
|
9413
|
+
Data as Data49,
|
|
9414
|
+
fromHex as fromHex16,
|
|
8855
9415
|
fromText as fromText11,
|
|
8856
9416
|
mintingPolicyToId as mintingPolicyToId2,
|
|
8857
9417
|
validatorToScriptHash as validatorToScriptHash4
|
|
@@ -8860,7 +9420,7 @@ import {
|
|
|
8860
9420
|
assetClassToUnit as assetClassToUnit2,
|
|
8861
9421
|
assetClassValueOf as assetClassValueOf9,
|
|
8862
9422
|
lovelacesAmt as lovelacesAmt4,
|
|
8863
|
-
mkAssetsOf as
|
|
9423
|
+
mkAssetsOf as mkAssetsOf13,
|
|
8864
9424
|
mkLovelacesOf as mkLovelacesOf7
|
|
8865
9425
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
8866
9426
|
|
|
@@ -8895,8 +9455,8 @@ var _iassetValidator = {
|
|
|
8895
9455
|
};
|
|
8896
9456
|
|
|
8897
9457
|
// src/contracts/iasset/scripts.ts
|
|
8898
|
-
import { Data as
|
|
8899
|
-
var IAssetScriptParamsSchema =
|
|
9458
|
+
import { Data as Data48 } from "@lucid-evolution/lucid";
|
|
9459
|
+
var IAssetScriptParamsSchema = Data48.Object({
|
|
8900
9460
|
upgradeToken: AssetClassSchema2,
|
|
8901
9461
|
versionRecordToken: AssetClassSchema2
|
|
8902
9462
|
});
|
|
@@ -8905,7 +9465,7 @@ var mkIAssetValidatorFromSP = (params) => {
|
|
|
8905
9465
|
return {
|
|
8906
9466
|
type: "PlutusV3",
|
|
8907
9467
|
script: applyParamsToScript17(_iassetValidator.cborHex, [
|
|
8908
|
-
|
|
9468
|
+
Data48.castTo(
|
|
8909
9469
|
{
|
|
8910
9470
|
upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
|
|
8911
9471
|
versionRecordToken: fromSystemParamsAssetLucid(
|
|
@@ -8922,7 +9482,7 @@ var mkIAssetValidatorFromSP = (params) => {
|
|
|
8922
9482
|
import { match as match20 } from "ts-pattern";
|
|
8923
9483
|
|
|
8924
9484
|
// tests/test-helpers.ts
|
|
8925
|
-
import { array as
|
|
9485
|
+
import { array as A12, function as F19, option as O16 } from "fp-ts";
|
|
8926
9486
|
async function runAndAwaitTxBuilder(lucid, transaction, extraSigners = []) {
|
|
8927
9487
|
const bTx = await transaction.complete();
|
|
8928
9488
|
const signatures = [await bTx.partialSign.withWallet()];
|
|
@@ -8985,15 +9545,15 @@ async function mintOneTimeToken(lucid, tokenName, amount) {
|
|
|
8985
9545
|
async function mintOneTimeAsset(lucid, tokenName, amount) {
|
|
8986
9546
|
const policyId = await mintOneTimeToken(lucid, fromText11(tokenName), amount);
|
|
8987
9547
|
return {
|
|
8988
|
-
currencySymbol:
|
|
8989
|
-
tokenName:
|
|
9548
|
+
currencySymbol: fromHex16(policyId),
|
|
9549
|
+
tokenName: fromHex16(fromText11(tokenName))
|
|
8990
9550
|
};
|
|
8991
9551
|
}
|
|
8992
9552
|
function deriveAuthToken(parent, tokenName) {
|
|
8993
9553
|
const policy = mkAuthTokenPolicy(parent, fromText11(tokenName));
|
|
8994
9554
|
return {
|
|
8995
|
-
currencySymbol:
|
|
8996
|
-
tokenName:
|
|
9555
|
+
currencySymbol: fromHex16(mintingPolicyToId2(policy)),
|
|
9556
|
+
tokenName: fromHex16(fromText11(tokenName))
|
|
8997
9557
|
};
|
|
8998
9558
|
}
|
|
8999
9559
|
async function initScriptRef(lucid, validator) {
|
|
@@ -9020,7 +9580,7 @@ async function initCollector(lucid, collectorParams, numCollectors) {
|
|
|
9020
9580
|
),
|
|
9021
9581
|
{
|
|
9022
9582
|
kind: "inline",
|
|
9023
|
-
value:
|
|
9583
|
+
value: Data49.void()
|
|
9024
9584
|
}
|
|
9025
9585
|
);
|
|
9026
9586
|
}
|
|
@@ -9031,7 +9591,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
|
|
|
9031
9591
|
const interestCollectionAdminDatum = {
|
|
9032
9592
|
admin_permissions: {
|
|
9033
9593
|
Signature: {
|
|
9034
|
-
keyHash:
|
|
9594
|
+
keyHash: fromHex16(pkh.hash)
|
|
9035
9595
|
}
|
|
9036
9596
|
}
|
|
9037
9597
|
};
|
|
@@ -9043,7 +9603,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
|
|
|
9043
9603
|
kind: "inline",
|
|
9044
9604
|
value: serialiseInterestCollectionDatum(interestCollectionAdminDatum)
|
|
9045
9605
|
},
|
|
9046
|
-
|
|
9606
|
+
mkAssetsOf13(multisigUtxoNft, 1n)
|
|
9047
9607
|
)
|
|
9048
9608
|
);
|
|
9049
9609
|
const interestCollectionUtxoDeploymentTx = lucid.newTx();
|
|
@@ -9066,7 +9626,7 @@ async function initCDPCreator(lucid, cdpCreatorParams, numCdpCreators) {
|
|
|
9066
9626
|
),
|
|
9067
9627
|
type: "Script"
|
|
9068
9628
|
}),
|
|
9069
|
-
{ kind: "inline", value:
|
|
9629
|
+
{ kind: "inline", value: Data49.void() },
|
|
9070
9630
|
{
|
|
9071
9631
|
[cdpCreatorParams.cdpCreatorNft[0].unCurrencySymbol + fromText11(cdpCreatorParams.cdpCreatorNft[1].unTokenName)]: 1n
|
|
9072
9632
|
}
|
|
@@ -9082,16 +9642,16 @@ async function initTreasury(lucid, treasuryParams, daoAsset, indyAsset, treasury
|
|
|
9082
9642
|
);
|
|
9083
9643
|
const tx = lucid.newTx().pay.ToContract(
|
|
9084
9644
|
treasuryAddr,
|
|
9085
|
-
{ kind: "inline", value:
|
|
9086
|
-
|
|
9087
|
-
|
|
9088
|
-
|
|
9645
|
+
{ kind: "inline", value: Data49.void() },
|
|
9646
|
+
addAssets16(
|
|
9647
|
+
mkAssetsOf13(daoAsset, 1n),
|
|
9648
|
+
mkAssetsOf13(indyAsset, treasuryIndyAmount)
|
|
9089
9649
|
)
|
|
9090
9650
|
);
|
|
9091
9651
|
for (let i = 0; i < Number(numTreasuryCollectors); i++) {
|
|
9092
9652
|
tx.pay.ToContract(treasuryAddr, {
|
|
9093
9653
|
kind: "inline",
|
|
9094
|
-
value:
|
|
9654
|
+
value: Data49.void()
|
|
9095
9655
|
});
|
|
9096
9656
|
}
|
|
9097
9657
|
await submitTx(lucid, tx);
|
|
@@ -9136,10 +9696,10 @@ async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, py
|
|
|
9136
9696
|
return Promise.resolve({
|
|
9137
9697
|
info: {
|
|
9138
9698
|
DeferredValidation: {
|
|
9139
|
-
feedValHash:
|
|
9699
|
+
feedValHash: fromHex16(
|
|
9140
9700
|
getPythFeedConfig(
|
|
9141
9701
|
pythConfig,
|
|
9142
|
-
|
|
9702
|
+
fromHex16(fromText11(iasset.name)),
|
|
9143
9703
|
collateralAsset.collateralAsset
|
|
9144
9704
|
).pythFeedValHash
|
|
9145
9705
|
)
|
|
@@ -9150,7 +9710,7 @@ async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, py
|
|
|
9150
9710
|
}).exhaustive();
|
|
9151
9711
|
}
|
|
9152
9712
|
async function initializeAsset(lucid, iassetParams, iassetToken, collateralAssetAuthToken, cdpAuthToken, cdpParams, stableswapValidatorHash, stabilityPoolParams, stabilityPoolToken, asset, pythConfig, currentSlot) {
|
|
9153
|
-
const iassetName =
|
|
9713
|
+
const iassetName = fromHex16(fromText11(asset.name));
|
|
9154
9714
|
const collateralAssetInfos = [];
|
|
9155
9715
|
for (const collateralAsset of asset.collateralAssets) {
|
|
9156
9716
|
const [pkh, _] = await addrDetails(lucid);
|
|
@@ -9198,7 +9758,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
9198
9758
|
CollateralAssetContent: collateralAssetContent
|
|
9199
9759
|
})
|
|
9200
9760
|
},
|
|
9201
|
-
|
|
9761
|
+
mkAssetsOf13(collateralAssetAuthToken, 1n)
|
|
9202
9762
|
);
|
|
9203
9763
|
await submitTx(lucid, collateralAssetTx);
|
|
9204
9764
|
collateralAssetInfos.push({
|
|
@@ -9216,11 +9776,11 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
9216
9776
|
redemptionFeeRatio: stableswapPool.redemptionFeeRatio,
|
|
9217
9777
|
mintingEnabled: stableswapPool.mintingEnabled,
|
|
9218
9778
|
redemptionEnabled: stableswapPool.redemptionEnabled,
|
|
9219
|
-
feeManager: stableswapPool.feeManager ?
|
|
9779
|
+
feeManager: stableswapPool.feeManager ? fromHex16(stableswapPool.feeManager) : null,
|
|
9220
9780
|
minMintOrderAmount: stableswapPool.minMintOrderAmount,
|
|
9221
9781
|
minRedemptionOrderAmount: stableswapPool.minRedemptionOrderAmount,
|
|
9222
9782
|
iasset: iassetName,
|
|
9223
|
-
stableswapValHash:
|
|
9783
|
+
stableswapValHash: fromHex16(stableswapValidatorHash)
|
|
9224
9784
|
};
|
|
9225
9785
|
await submitTx(
|
|
9226
9786
|
lucid,
|
|
@@ -9233,7 +9793,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
9233
9793
|
kind: "inline",
|
|
9234
9794
|
value: serialiseStableswapPoolDatum(stableswapPoolDatum)
|
|
9235
9795
|
},
|
|
9236
|
-
|
|
9796
|
+
mkAssetsOf13(cdpAuthToken, 1n)
|
|
9237
9797
|
)
|
|
9238
9798
|
);
|
|
9239
9799
|
}
|
|
@@ -9246,7 +9806,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
9246
9806
|
redemptionReimbursementRatio: asset.redemptionReimbursementRatio,
|
|
9247
9807
|
redemptionProcessingFeeRatio: asset.redemptionProcessingFeeRatio,
|
|
9248
9808
|
firstIAsset: asset.firstAsset,
|
|
9249
|
-
nextIAsset: asset.nextAsset ?
|
|
9809
|
+
nextIAsset: asset.nextAsset ? fromHex16(fromText11(asset.nextAsset)) : null
|
|
9250
9810
|
};
|
|
9251
9811
|
const assetTx = lucid.newTx().pay.ToContract(
|
|
9252
9812
|
createScriptAddress(
|
|
@@ -9257,11 +9817,11 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
9257
9817
|
kind: "inline",
|
|
9258
9818
|
value: serialiseIAssetDatum({ IAssetContent: iassetDatum })
|
|
9259
9819
|
},
|
|
9260
|
-
|
|
9820
|
+
mkAssetsOf13(iassetToken, 1n)
|
|
9261
9821
|
);
|
|
9262
9822
|
await submitTx(lucid, assetTx);
|
|
9263
9823
|
const stabilityPoolDatum = {
|
|
9264
|
-
iasset:
|
|
9824
|
+
iasset: fromHex16(fromText11(asset.name)),
|
|
9265
9825
|
state: initSpState,
|
|
9266
9826
|
assetStates: []
|
|
9267
9827
|
};
|
|
@@ -9276,7 +9836,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
9276
9836
|
kind: "inline",
|
|
9277
9837
|
value: serialiseStabilityPoolDatum({ StabilityPool: stabilityPoolDatum })
|
|
9278
9838
|
},
|
|
9279
|
-
|
|
9839
|
+
mkAssetsOf13(stabilityPoolToken, 1n)
|
|
9280
9840
|
);
|
|
9281
9841
|
await submitTx(lucid, spTx);
|
|
9282
9842
|
return {
|
|
@@ -9298,7 +9858,7 @@ async function initGovernance(lucid, governanceParams, govToken, initialAssets,
|
|
|
9298
9858
|
type: "Script"
|
|
9299
9859
|
}),
|
|
9300
9860
|
{ kind: "inline", value: serialiseGovDatum(datum) },
|
|
9301
|
-
|
|
9861
|
+
mkAssetsOf13(govToken, 1n)
|
|
9302
9862
|
);
|
|
9303
9863
|
await submitTx(lucid, tx);
|
|
9304
9864
|
}
|
|
@@ -9315,16 +9875,16 @@ async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
|
|
|
9315
9875
|
{
|
|
9316
9876
|
[policyId + fromText11(tokenName)]: amount
|
|
9317
9877
|
},
|
|
9318
|
-
|
|
9878
|
+
Data49.void()
|
|
9319
9879
|
);
|
|
9320
9880
|
await submitTx(lucid, tx);
|
|
9321
9881
|
}
|
|
9322
9882
|
|
|
9323
9883
|
// src/contracts/initialize/actions.ts
|
|
9324
9884
|
import {
|
|
9325
|
-
addAssets as
|
|
9885
|
+
addAssets as addAssets17,
|
|
9326
9886
|
credentialToRewardAddress as credentialToRewardAddress4,
|
|
9327
|
-
fromHex as
|
|
9887
|
+
fromHex as fromHex18,
|
|
9328
9888
|
fromText as fromText13,
|
|
9329
9889
|
mintingPolicyToId as mintingPolicyToId3,
|
|
9330
9890
|
scriptHashToCredential as scriptHashToCredential4,
|
|
@@ -9332,7 +9892,7 @@ import {
|
|
|
9332
9892
|
validatorToScriptHash as validatorToScriptHash6
|
|
9333
9893
|
} from "@lucid-evolution/lucid";
|
|
9334
9894
|
import {
|
|
9335
|
-
mkAssetsOf as
|
|
9895
|
+
mkAssetsOf as mkAssetsOf15,
|
|
9336
9896
|
mkLovelacesOf as mkLovelacesOf8
|
|
9337
9897
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
9338
9898
|
|
|
@@ -9359,17 +9919,17 @@ function mkIAssetTokenPolicy(ac) {
|
|
|
9359
9919
|
import { applyParamsToScript as applyParamsToScript19 } from "@lucid-evolution/lucid";
|
|
9360
9920
|
|
|
9361
9921
|
// src/contracts/stableswap/types.ts
|
|
9362
|
-
import { Data as
|
|
9363
|
-
var StableswapParamsSchema =
|
|
9364
|
-
iassetSymbol:
|
|
9922
|
+
import { Data as Data50 } from "@lucid-evolution/lucid";
|
|
9923
|
+
var StableswapParamsSchema = Data50.Object({
|
|
9924
|
+
iassetSymbol: Data50.Bytes(),
|
|
9365
9925
|
cdpToken: AssetClassSchema2,
|
|
9366
9926
|
versionRecordToken: AssetClassSchema2,
|
|
9367
|
-
cdpValHash:
|
|
9368
|
-
treasuryValHash:
|
|
9927
|
+
cdpValHash: Data50.Bytes(),
|
|
9928
|
+
treasuryValHash: Data50.Bytes()
|
|
9369
9929
|
});
|
|
9370
9930
|
var StableswapParams = StableswapParamsSchema;
|
|
9371
9931
|
function castStableswapParams(params) {
|
|
9372
|
-
return
|
|
9932
|
+
return Data50.castTo(params, StableswapParams);
|
|
9373
9933
|
}
|
|
9374
9934
|
|
|
9375
9935
|
// src/validators/stableswap-validator.ts
|
|
@@ -9430,7 +9990,7 @@ import { match as match21 } from "ts-pattern";
|
|
|
9430
9990
|
import {
|
|
9431
9991
|
credentialToAddress as credentialToAddress5,
|
|
9432
9992
|
credentialToRewardAddress as credentialToRewardAddress3,
|
|
9433
|
-
fromHex as
|
|
9993
|
+
fromHex as fromHex17,
|
|
9434
9994
|
fromText as fromText12,
|
|
9435
9995
|
validatorToScriptHash as validatorToScriptHash5
|
|
9436
9996
|
} from "@lucid-evolution/lucid";
|
|
@@ -9449,14 +10009,14 @@ var alwaysSucceedValidator = {
|
|
|
9449
10009
|
};
|
|
9450
10010
|
|
|
9451
10011
|
// tests/pyth/endpoints.ts
|
|
9452
|
-
import { mkAssetsOf as
|
|
10012
|
+
import { mkAssetsOf as mkAssetsOf14 } from "@3rd-eye-labs/cardano-offchain-common";
|
|
9453
10013
|
var TEST_TRUSTED_SIGNER_PUB_KEY = "4a50d7c3d16b2be5c16ba996109a455a34cce08a81b3e15b86ef407e2f72e71f";
|
|
9454
10014
|
async function initPyth(lucid) {
|
|
9455
10015
|
const pythStateName = fromText12("Pyth State");
|
|
9456
10016
|
const pythStatePolicyId = await mintOneTimeToken(lucid, pythStateName, 1n);
|
|
9457
10017
|
const pythStateAsset = {
|
|
9458
|
-
currencySymbol:
|
|
9459
|
-
tokenName:
|
|
10018
|
+
currencySymbol: fromHex17(pythStatePolicyId),
|
|
10019
|
+
tokenName: fromHex17(pythStateName)
|
|
9460
10020
|
};
|
|
9461
10021
|
const alwaysSucceedsValidatorHash = validatorToScriptHash5(
|
|
9462
10022
|
alwaysSucceedValidator
|
|
@@ -9464,14 +10024,14 @@ async function initPyth(lucid) {
|
|
|
9464
10024
|
const pythStateDatum = {
|
|
9465
10025
|
// The governance doesn't matter for the purpose of testing, so we can use any values
|
|
9466
10026
|
governance: {
|
|
9467
|
-
wormhole:
|
|
10027
|
+
wormhole: fromHex17(""),
|
|
9468
10028
|
emitterChain: 0n,
|
|
9469
|
-
emitterAddress:
|
|
10029
|
+
emitterAddress: fromHex17(""),
|
|
9470
10030
|
seenSequence: 0n
|
|
9471
10031
|
},
|
|
9472
10032
|
trustedSigners: /* @__PURE__ */ new Map([
|
|
9473
10033
|
[
|
|
9474
|
-
|
|
10034
|
+
fromHex17(TEST_TRUSTED_SIGNER_PUB_KEY),
|
|
9475
10035
|
{
|
|
9476
10036
|
lower_bound: {
|
|
9477
10037
|
bound_type: {
|
|
@@ -9491,7 +10051,7 @@ async function initPyth(lucid) {
|
|
|
9491
10051
|
deprecatedWithdrawScripts: /* @__PURE__ */ new Map(),
|
|
9492
10052
|
// For the purpose of testing, we use the always succeeds validator to validate the Pyth Messages.
|
|
9493
10053
|
// This means the message signature checking will always succeed for the purpose of emulation testing.
|
|
9494
|
-
withdraw_script:
|
|
10054
|
+
withdraw_script: fromHex17(alwaysSucceedsValidatorHash)
|
|
9495
10055
|
};
|
|
9496
10056
|
await runAndAwaitTxBuilder(
|
|
9497
10057
|
lucid,
|
|
@@ -9501,7 +10061,7 @@ async function initPyth(lucid) {
|
|
|
9501
10061
|
type: "Script"
|
|
9502
10062
|
}),
|
|
9503
10063
|
{ kind: "inline", value: serialisePythStateDatum(pythStateDatum) },
|
|
9504
|
-
|
|
10064
|
+
mkAssetsOf14(pythStateAsset, 1n),
|
|
9505
10065
|
alwaysSucceedValidator
|
|
9506
10066
|
)
|
|
9507
10067
|
);
|
|
@@ -9604,8 +10164,8 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9604
10164
|
}
|
|
9605
10165
|
});
|
|
9606
10166
|
const versionRecordToken = {
|
|
9607
|
-
currencySymbol:
|
|
9608
|
-
tokenName:
|
|
10167
|
+
currencySymbol: fromHex18(mintingPolicyToId3(versionRecordTokenPolicy)),
|
|
10168
|
+
tokenName: fromHex18(fromText13(tn.versionRecord))
|
|
9609
10169
|
};
|
|
9610
10170
|
const versionRegistryValidator = mkVersionRegistryValidator();
|
|
9611
10171
|
const versionRegistryValHash = validatorToScriptHash6(
|
|
@@ -9804,8 +10364,8 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9804
10364
|
lucid,
|
|
9805
10365
|
lucid.newTx().pay.ToAddress(
|
|
9806
10366
|
await lucid.wallet().address(),
|
|
9807
|
-
|
|
9808
|
-
|
|
10367
|
+
addAssets17(
|
|
10368
|
+
mkAssetsOf15(iassetToken, 1n),
|
|
9809
10369
|
mkLovelacesOf8(BigInt(totalCollateralAssetsCount) * 5000000n)
|
|
9810
10370
|
)
|
|
9811
10371
|
)
|
|
@@ -9822,8 +10382,8 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9822
10382
|
lucid,
|
|
9823
10383
|
lucid.newTx().pay.ToAddress(
|
|
9824
10384
|
await lucid.wallet().address(),
|
|
9825
|
-
|
|
9826
|
-
|
|
10385
|
+
addAssets17(
|
|
10386
|
+
mkAssetsOf15(cdpCreatorAsset, 1n),
|
|
9827
10387
|
mkLovelacesOf8(BigInt(totalStablePoolsCount) * 5000000n)
|
|
9828
10388
|
)
|
|
9829
10389
|
)
|
|
@@ -10104,7 +10664,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
10104
10664
|
}
|
|
10105
10665
|
|
|
10106
10666
|
// src/contracts/stableswap/helpers.ts
|
|
10107
|
-
import { fromHex as
|
|
10667
|
+
import { fromHex as fromHex19, fromText as fromText14 } from "@lucid-evolution/lucid";
|
|
10108
10668
|
|
|
10109
10669
|
// src/contracts/stableswap/types-new.ts
|
|
10110
10670
|
import {
|
|
@@ -10112,10 +10672,10 @@ import {
|
|
|
10112
10672
|
AssetClassSchema as AssetClassSchema8,
|
|
10113
10673
|
OutputReferenceSchema as OutputReferenceSchema7
|
|
10114
10674
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
10115
|
-
import { TSchema as TSchema20, Data as
|
|
10116
|
-
import { option as O17, function as
|
|
10675
|
+
import { TSchema as TSchema20, Data as Data51 } from "@evolution-sdk/evolution";
|
|
10676
|
+
import { option as O17, function as F20 } from "fp-ts";
|
|
10117
10677
|
import { Schema as Schema4 } from "effect";
|
|
10118
|
-
var OpaqueData4 = Schema4.typeSchema(
|
|
10678
|
+
var OpaqueData4 = Schema4.typeSchema(Data51.DataSchema);
|
|
10119
10679
|
var StableswapOrderDatumSchema = TSchema20.Struct({
|
|
10120
10680
|
iasset: TSchema20.ByteArray,
|
|
10121
10681
|
collateralAsset: AssetClassSchema8,
|
|
@@ -10148,7 +10708,7 @@ var StableswapOutputDatumSchema = TSchema20.Tuple([
|
|
|
10148
10708
|
OutputReferenceSchema7
|
|
10149
10709
|
]);
|
|
10150
10710
|
function serialiseStableswapOrderDatum(d) {
|
|
10151
|
-
return
|
|
10711
|
+
return Data51.withSchema(
|
|
10152
10712
|
StableswapOrderDatumSchema,
|
|
10153
10713
|
DEFAULT_SCHEMA_OPTIONS
|
|
10154
10714
|
).toCBORHex(d);
|
|
@@ -10156,7 +10716,7 @@ function serialiseStableswapOrderDatum(d) {
|
|
|
10156
10716
|
function parseStableswapOrderDatum(datum) {
|
|
10157
10717
|
try {
|
|
10158
10718
|
return O17.some(
|
|
10159
|
-
|
|
10719
|
+
Data51.withSchema(
|
|
10160
10720
|
StableswapOrderDatumSchema,
|
|
10161
10721
|
DEFAULT_SCHEMA_OPTIONS
|
|
10162
10722
|
).fromCBORHex(datum)
|
|
@@ -10166,21 +10726,21 @@ function parseStableswapOrderDatum(datum) {
|
|
|
10166
10726
|
}
|
|
10167
10727
|
}
|
|
10168
10728
|
function parseStableswapOrderDatumOrThrow(datum) {
|
|
10169
|
-
return
|
|
10729
|
+
return F20.pipe(
|
|
10170
10730
|
parseStableswapOrderDatum(datum),
|
|
10171
10731
|
O17.match(() => {
|
|
10172
10732
|
throw new Error("Expected a Stableswap Order datum.");
|
|
10173
|
-
},
|
|
10733
|
+
}, F20.identity)
|
|
10174
10734
|
);
|
|
10175
10735
|
}
|
|
10176
10736
|
function serialiseStableswapOutputDatum(d) {
|
|
10177
|
-
return
|
|
10737
|
+
return Data51.withSchema(
|
|
10178
10738
|
StableswapOutputDatumSchema,
|
|
10179
10739
|
DEFAULT_SCHEMA_OPTIONS
|
|
10180
10740
|
).toCBORHex(d);
|
|
10181
10741
|
}
|
|
10182
10742
|
function serialiseStableswapOrderRedeemer(r) {
|
|
10183
|
-
return
|
|
10743
|
+
return Data51.withSchema(
|
|
10184
10744
|
StableswapOrderRedeemerSchema,
|
|
10185
10745
|
DEFAULT_SCHEMA_OPTIONS
|
|
10186
10746
|
).toCBORHex(r);
|
|
@@ -10188,7 +10748,7 @@ function serialiseStableswapOrderRedeemer(r) {
|
|
|
10188
10748
|
function parseStableswapOrderRedeemer(redeemerCborHex) {
|
|
10189
10749
|
try {
|
|
10190
10750
|
return O17.some(
|
|
10191
|
-
|
|
10751
|
+
Data51.withSchema(
|
|
10192
10752
|
StableswapOrderRedeemerSchema,
|
|
10193
10753
|
DEFAULT_SCHEMA_OPTIONS
|
|
10194
10754
|
).fromCBORHex(redeemerCborHex)
|
|
@@ -10198,36 +10758,36 @@ function parseStableswapOrderRedeemer(redeemerCborHex) {
|
|
|
10198
10758
|
}
|
|
10199
10759
|
}
|
|
10200
10760
|
function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
|
|
10201
|
-
return
|
|
10761
|
+
return F20.pipe(
|
|
10202
10762
|
parseStableswapOrderRedeemer(redeemerCborHex),
|
|
10203
10763
|
O17.match(() => {
|
|
10204
10764
|
throw new Error("Expected a Stableswap Order redeemer.");
|
|
10205
|
-
},
|
|
10765
|
+
}, F20.identity)
|
|
10206
10766
|
);
|
|
10207
10767
|
}
|
|
10208
10768
|
|
|
10209
10769
|
// src/contracts/stableswap/helpers.ts
|
|
10210
|
-
import { Data as
|
|
10770
|
+
import { Data as Data52 } from "@evolution-sdk/evolution";
|
|
10211
10771
|
var BASE_MAX_EXECUTION_FEE = 1000000n;
|
|
10212
10772
|
function createDestinationDatum(datum, outRef) {
|
|
10213
10773
|
if (!datum) {
|
|
10214
10774
|
return serialiseStableswapOutputDatum([
|
|
10215
|
-
|
|
10775
|
+
fromHex19(fromText14("IndigoStableswap")),
|
|
10216
10776
|
{
|
|
10217
|
-
txHash:
|
|
10777
|
+
txHash: fromHex19(outRef.txHash),
|
|
10218
10778
|
outputIndex: BigInt(outRef.outputIndex)
|
|
10219
10779
|
}
|
|
10220
10780
|
]);
|
|
10221
10781
|
}
|
|
10222
|
-
return
|
|
10782
|
+
return Data52.toCBORHex(datum);
|
|
10223
10783
|
}
|
|
10224
10784
|
|
|
10225
10785
|
// src/contracts/stableswap/transactions.ts
|
|
10226
10786
|
import {
|
|
10227
|
-
addAssets as
|
|
10787
|
+
addAssets as addAssets18,
|
|
10228
10788
|
credentialToAddress as credentialToAddress6,
|
|
10229
|
-
Data as
|
|
10230
|
-
fromHex as
|
|
10789
|
+
Data as Data53,
|
|
10790
|
+
fromHex as fromHex20,
|
|
10231
10791
|
fromText as fromText15,
|
|
10232
10792
|
paymentCredentialOf as paymentCredentialOf3,
|
|
10233
10793
|
sortUTxOs as sortUTxOs2,
|
|
@@ -10239,32 +10799,32 @@ import {
|
|
|
10239
10799
|
addressToBech32 as addressToBech323,
|
|
10240
10800
|
getInlineDatumOrThrow as getInlineDatumOrThrow6,
|
|
10241
10801
|
matchSingle as matchSingle4,
|
|
10242
|
-
mkAssetsOf as
|
|
10802
|
+
mkAssetsOf as mkAssetsOf16,
|
|
10243
10803
|
mkLovelacesOf as mkLovelacesOf9,
|
|
10244
10804
|
lovelacesAmt as lovelacesAmt5,
|
|
10245
10805
|
isSameOutRef as isSameOutRef2,
|
|
10246
10806
|
assetClassValueOf as assetClassValueOf10
|
|
10247
10807
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
10248
|
-
import { array as
|
|
10808
|
+
import { array as A13, function as F21 } from "fp-ts";
|
|
10249
10809
|
import { isEmpty } from "fp-ts/lib/Array";
|
|
10250
10810
|
async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
|
|
10251
10811
|
const myAddress = await lucid.wallet().address();
|
|
10252
10812
|
const pkh = paymentCredentialOf3(myAddress);
|
|
10253
10813
|
const datum = {
|
|
10254
|
-
iasset:
|
|
10814
|
+
iasset: fromHex20(fromText15(iasset)),
|
|
10255
10815
|
collateralAsset,
|
|
10256
|
-
owner:
|
|
10816
|
+
owner: fromHex20(pkh.hash),
|
|
10257
10817
|
destination: addressFromBech323(destinationAddress ?? myAddress),
|
|
10258
10818
|
destinationInlineDatum: destinationInlineDatum ?? null,
|
|
10259
10819
|
maxExecutionFee,
|
|
10260
10820
|
maxFeeRatio: maxFeeRatio ?? (minting ? poolDatum.mintingFeeRatio : poolDatum.redemptionFeeRatio)
|
|
10261
10821
|
};
|
|
10262
|
-
const assetsToSwap = minting ?
|
|
10822
|
+
const assetsToSwap = minting ? mkAssetsOf16(collateralAsset, amount) : mkAssetsOf16(
|
|
10263
10823
|
{
|
|
10264
|
-
currencySymbol:
|
|
10824
|
+
currencySymbol: fromHex20(
|
|
10265
10825
|
params.stableswapParams.iassetSymbol.unCurrencySymbol
|
|
10266
10826
|
),
|
|
10267
|
-
tokenName:
|
|
10827
|
+
tokenName: fromHex20(fromText15(iasset))
|
|
10268
10828
|
},
|
|
10269
10829
|
amount
|
|
10270
10830
|
);
|
|
@@ -10292,7 +10852,7 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
|
|
|
10292
10852
|
kind: "inline",
|
|
10293
10853
|
value: serialiseStableswapOrderDatum(datum)
|
|
10294
10854
|
},
|
|
10295
|
-
|
|
10855
|
+
addAssets18(
|
|
10296
10856
|
assetsToSwap,
|
|
10297
10857
|
mkLovelacesOf9(
|
|
10298
10858
|
roundedExpectedOutputLovelaces + maxExecutionFee + additionalLovelaces
|
|
@@ -10360,7 +10920,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
10360
10920
|
getInlineDatumOrThrow6(mainOrderUtxo)
|
|
10361
10921
|
);
|
|
10362
10922
|
const iassetAc = {
|
|
10363
|
-
currencySymbol:
|
|
10923
|
+
currencySymbol: fromHex20(
|
|
10364
10924
|
sysParams.stableswapParams.iassetSymbol.unCurrencySymbol
|
|
10365
10925
|
),
|
|
10366
10926
|
tokenName: mainOrderDatum.iasset
|
|
@@ -10506,9 +11066,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
10506
11066
|
}
|
|
10507
11067
|
}
|
|
10508
11068
|
);
|
|
10509
|
-
const totalSwapInfo =
|
|
11069
|
+
const totalSwapInfo = F21.pipe(
|
|
10510
11070
|
ordersInfo,
|
|
10511
|
-
|
|
11071
|
+
A13.reduce(
|
|
10512
11072
|
{
|
|
10513
11073
|
suppliedCollateralAsset: 0n,
|
|
10514
11074
|
suppliedIasset: 0n,
|
|
@@ -10550,17 +11110,17 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
10550
11110
|
kind: "inline",
|
|
10551
11111
|
value: serialiseStableswapPoolDatum(stableswapPoolDatum)
|
|
10552
11112
|
},
|
|
10553
|
-
collateralAmtChangePool != 0n ?
|
|
11113
|
+
collateralAmtChangePool != 0n ? addAssets18(
|
|
10554
11114
|
stableswapPoolUtxo.assets,
|
|
10555
|
-
|
|
11115
|
+
mkAssetsOf16(collateralAc, collateralAmtChangePool)
|
|
10556
11116
|
) : stableswapPoolUtxo.assets
|
|
10557
11117
|
).setMinFee(2055720n);
|
|
10558
11118
|
if (amountToMint !== 0n) {
|
|
10559
|
-
tx.mintAssets(
|
|
11119
|
+
tx.mintAssets(mkAssetsOf16(iassetAc, amountToMint), Data53.void());
|
|
10560
11120
|
}
|
|
10561
|
-
|
|
11121
|
+
F21.pipe(
|
|
10562
11122
|
ordersInfo,
|
|
10563
|
-
|
|
11123
|
+
A13.reduce(tx, (acc, orderInfo) => {
|
|
10564
11124
|
return acc.collectFrom(
|
|
10565
11125
|
[orderInfo.utxo],
|
|
10566
11126
|
isSameOutRef2(orderInfo.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
|
|
@@ -10584,13 +11144,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
10584
11144
|
orderInfo.utxo
|
|
10585
11145
|
)
|
|
10586
11146
|
},
|
|
10587
|
-
|
|
11147
|
+
addAssets18(
|
|
10588
11148
|
// Currently, we always take the max execution fee from the order utxo.
|
|
10589
11149
|
// This can be improved so that we take the actual execution fee.
|
|
10590
11150
|
mkLovelacesOf9(
|
|
10591
11151
|
lovelacesAmt5(orderInfo.utxo.assets) - orderInfo.datum.maxExecutionFee
|
|
10592
11152
|
),
|
|
10593
|
-
orderInfo.swapInfo.owedIasset > 0 ?
|
|
11153
|
+
orderInfo.swapInfo.owedIasset > 0 ? mkAssetsOf16(iassetAc, orderInfo.swapInfo.owedIasset) : mkAssetsOf16(
|
|
10594
11154
|
collateralAc,
|
|
10595
11155
|
orderInfo.swapInfo.owedCollateralAsset
|
|
10596
11156
|
)
|
|
@@ -10690,6 +11250,7 @@ export {
|
|
|
10690
11250
|
InterestOracleDatumSchema,
|
|
10691
11251
|
InterestOracleParamsSchema,
|
|
10692
11252
|
MAX_E2S2S_ENTRIES_COUNT,
|
|
11253
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN,
|
|
10693
11254
|
MIN_ROB_COLLATERAL_AMT,
|
|
10694
11255
|
ONE_DAY,
|
|
10695
11256
|
ONE_HOUR,
|
|
@@ -10724,6 +11285,7 @@ export {
|
|
|
10724
11285
|
adjustStakingPosition,
|
|
10725
11286
|
alwaysFailValidator,
|
|
10726
11287
|
annulRequest,
|
|
11288
|
+
approximateLeverageRedemptions,
|
|
10727
11289
|
attachOracle,
|
|
10728
11290
|
balance,
|
|
10729
11291
|
batchCollectInterest,
|
|
@@ -10734,8 +11296,11 @@ export {
|
|
|
10734
11296
|
burnCdp,
|
|
10735
11297
|
calculateAccruedInterest,
|
|
10736
11298
|
calculateAdaReward,
|
|
11299
|
+
calculateCollateralRatioFromLeverage,
|
|
10737
11300
|
calculateIAssetRedemptionAmt,
|
|
11301
|
+
calculateLeverageFromCollateralRatio,
|
|
10738
11302
|
calculateMinCollateralCappedIAssetRedemptionAmt,
|
|
11303
|
+
calculateTotalCollateralForRedemption,
|
|
10739
11304
|
calculateUnitaryInterest,
|
|
10740
11305
|
calculateUnitaryInterestSinceOracleLastUpdated,
|
|
10741
11306
|
cancelRob,
|
|
@@ -10801,9 +11366,9 @@ export {
|
|
|
10801
11366
|
getAssetClassComparisonStr,
|
|
10802
11367
|
getInlineDatumOrThrow,
|
|
10803
11368
|
getPythFeedConfig,
|
|
10804
|
-
getRandomElement,
|
|
10805
11369
|
getUpdatedAccountDeposit,
|
|
10806
11370
|
handleOracleForCollateralAsset,
|
|
11371
|
+
iassetValueOfCollateral,
|
|
10807
11372
|
init,
|
|
10808
11373
|
initCDPCreator,
|
|
10809
11374
|
initCollector,
|
|
@@ -10817,8 +11382,10 @@ export {
|
|
|
10817
11382
|
initTreasury,
|
|
10818
11383
|
initializeAsset,
|
|
10819
11384
|
insertSorted,
|
|
11385
|
+
isBuyOrderFullyRedeemed,
|
|
10820
11386
|
isFullyRedeemed,
|
|
10821
11387
|
isSameEpochToScaleKey,
|
|
11388
|
+
leverageCdpWithRob,
|
|
10822
11389
|
liquidateCdp,
|
|
10823
11390
|
liquidationHelper,
|
|
10824
11391
|
loadSystemParamsFromFile,
|
|
@@ -10903,6 +11470,7 @@ export {
|
|
|
10903
11470
|
parseStakingPositionOrThrow,
|
|
10904
11471
|
partitionEpochToScaleToSums,
|
|
10905
11472
|
processSpRequest,
|
|
11473
|
+
randomRobsSubsetSatisfyingTargetCollateral,
|
|
10906
11474
|
rationalAdd,
|
|
10907
11475
|
rationalCeil,
|
|
10908
11476
|
rationalDiv,
|
|
@@ -10921,7 +11489,10 @@ export {
|
|
|
10921
11489
|
requestSpAccountClosure,
|
|
10922
11490
|
requestSpAccountCreation,
|
|
10923
11491
|
rewardSnapshotPrecision,
|
|
10924
|
-
|
|
11492
|
+
robAmtToSpend,
|
|
11493
|
+
robBuyOrderSummary,
|
|
11494
|
+
robCollateralAmtToSpend,
|
|
11495
|
+
robIAssetAmtToSpend,
|
|
10925
11496
|
runCreateScriptRefTx,
|
|
10926
11497
|
runOneShotMintTx,
|
|
10927
11498
|
scriptRef,
|
|
@@ -10966,6 +11537,7 @@ export {
|
|
|
10966
11537
|
startPriceOracleTx,
|
|
10967
11538
|
submitTx,
|
|
10968
11539
|
sum,
|
|
11540
|
+
summarizeActualLeverageRedemptions,
|
|
10969
11541
|
toAssetClassFromLucid,
|
|
10970
11542
|
toDataDerivedPythPrice,
|
|
10971
11543
|
toSystemParamsAsset,
|