@indigo-labs/indigo-sdk 0.5.16 → 0.6.1
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 +53 -32
- package/dist/index.d.ts +53 -32
- package/dist/index.js +314 -217
- package/dist/index.mjs +310 -213
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -279,6 +279,12 @@ function getPythFeedConfig(cfg, iasset, collateralAsset) {
|
|
|
279
279
|
throw new Error("No Pyth config known for such assets combination");
|
|
280
280
|
return res;
|
|
281
281
|
}
|
|
282
|
+
function toSystemParamsInput(outRef) {
|
|
283
|
+
return {
|
|
284
|
+
transactionId: outRef.txHash,
|
|
285
|
+
index: outRef.outputIndex
|
|
286
|
+
};
|
|
287
|
+
}
|
|
282
288
|
function toSystemParamsAsset(asset) {
|
|
283
289
|
return [
|
|
284
290
|
{ unCurrencySymbol: toHex(asset.currencySymbol) },
|
|
@@ -363,9 +369,26 @@ async function scriptRef(ref, lucid) {
|
|
|
363
369
|
if (utxos.length === 0) throw Error("Unable to locate script ref.");
|
|
364
370
|
return utxos[0];
|
|
365
371
|
}
|
|
366
|
-
|
|
367
|
-
|
|
372
|
+
var defaultSubmissionConfig = {
|
|
373
|
+
extraSigners: [],
|
|
374
|
+
useLocalOverride: true
|
|
375
|
+
};
|
|
376
|
+
async function runAndAwaitTxBuilder(lucid, transaction, submissionConfig) {
|
|
377
|
+
const config = {
|
|
378
|
+
...defaultSubmissionConfig,
|
|
379
|
+
...submissionConfig
|
|
380
|
+
};
|
|
381
|
+
const [newWalletUTxOs, _, bTx] = await transaction.chain();
|
|
382
|
+
const signatures = [await bTx.partialSign.withWallet()];
|
|
383
|
+
for (const signer of config.extraSigners) {
|
|
384
|
+
lucid.selectWallet.fromSeed(signer);
|
|
385
|
+
signatures.push(await lucid.fromTx(bTx.toCBOR()).partialSign.withWallet());
|
|
386
|
+
}
|
|
387
|
+
const signedTx = bTx.assemble(signatures);
|
|
388
|
+
const txHash = await signedTx.complete().then((tx) => tx.submit());
|
|
368
389
|
await lucid.awaitTx(txHash);
|
|
390
|
+
lucid.overrideUTxOs(newWalletUTxOs);
|
|
391
|
+
return txHash;
|
|
369
392
|
}
|
|
370
393
|
function balance(utxos) {
|
|
371
394
|
return utxos.reduce((acc, utxo) => addAssets(acc, utxo.assets), {});
|
|
@@ -442,8 +465,9 @@ function calculateAccruedInterest(now, unitaryInterestSnapshot, mintedAmount, in
|
|
|
442
465
|
|
|
443
466
|
// src/contracts/price-oracle/helpers.ts
|
|
444
467
|
function oracleExpirationAwareValidity(lucid, biasTime, oracleExpiration) {
|
|
445
|
-
const
|
|
446
|
-
const
|
|
468
|
+
const currentTime = lucid.slotToUnixTime(lucid.currentSlot());
|
|
469
|
+
const validateFrom = currentTime - Math.floor(biasTime / 2);
|
|
470
|
+
const defaultValidateTo = currentTime + Math.floor(biasTime / 2);
|
|
447
471
|
const cappedValidateTo = lucid.slotToUnixTime(
|
|
448
472
|
lucid.unixTimeToSlot(oracleExpiration) - 1
|
|
449
473
|
);
|
|
@@ -498,7 +522,15 @@ function computeEffectiveCdpState(now, cdpUtxoAssets, cdpContent, interestOracle
|
|
|
498
522
|
collateralAmt
|
|
499
523
|
};
|
|
500
524
|
}
|
|
501
|
-
|
|
525
|
+
var defaultLoanAdjustments = {
|
|
526
|
+
collateralAdjustment: 0n,
|
|
527
|
+
debtAdjustment: 0n
|
|
528
|
+
};
|
|
529
|
+
function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpContent, interestOracleDatum, loanAdjustments) {
|
|
530
|
+
const adjustments = {
|
|
531
|
+
...defaultLoanAdjustments,
|
|
532
|
+
...loanAdjustments
|
|
533
|
+
};
|
|
502
534
|
const cdpState = computeEffectiveCdpState(
|
|
503
535
|
now,
|
|
504
536
|
cdpUtxoAssets,
|
|
@@ -506,8 +538,11 @@ function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpConten
|
|
|
506
538
|
interestOracleDatum
|
|
507
539
|
);
|
|
508
540
|
const ratio = rationalDiv(
|
|
509
|
-
rationalFromInt(cdpState.collateralAmt),
|
|
510
|
-
rationalMul(
|
|
541
|
+
rationalFromInt(cdpState.collateralAmt + adjustments.collateralAdjustment),
|
|
542
|
+
rationalMul(
|
|
543
|
+
rationalFromInt(cdpState.mintedAmt + adjustments.debtAdjustment),
|
|
544
|
+
iassetPrice
|
|
545
|
+
)
|
|
511
546
|
);
|
|
512
547
|
return Number(ratio.numerator) * 100 / Number(ratio.denominator);
|
|
513
548
|
}
|
|
@@ -2210,8 +2245,12 @@ async function batchCollectInterest(collateralAssetOref, interestCollectorOutRef
|
|
|
2210
2245
|
referenceInputs,
|
|
2211
2246
|
false
|
|
2212
2247
|
);
|
|
2213
|
-
const validateFrom =
|
|
2214
|
-
|
|
2248
|
+
const validateFrom = Number(
|
|
2249
|
+
currentTime - BigInt(params.cdpParams.biasTime) / 2n
|
|
2250
|
+
);
|
|
2251
|
+
const validateTo = Number(
|
|
2252
|
+
currentTime + BigInt(params.cdpParams.biasTime) / 2n
|
|
2253
|
+
);
|
|
2215
2254
|
const tx = lucid.newTx().validFrom(validateFrom).validTo(validateTo).readFrom(referenceInputs).collectFrom([interestCollectorUtxo], {
|
|
2216
2255
|
kind: "selected",
|
|
2217
2256
|
makeRedeemer: (inputIndices) => {
|
|
@@ -3754,6 +3793,8 @@ function derivePythPrice(derivedPythPrice, messageHex) {
|
|
|
3754
3793
|
|
|
3755
3794
|
// src/contracts/iasset/helpers.ts
|
|
3756
3795
|
import * as Core from "@evolution-sdk/evolution";
|
|
3796
|
+
var MAX_PYTH_FEED_DELAY = 280 * 1e3;
|
|
3797
|
+
var PYTH_FEED_LEDGER_TIME_BUFFER = 20 * 1e3;
|
|
3757
3798
|
var MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET = 9;
|
|
3758
3799
|
function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythStateOref, pythMessage, pythConfig, biasTime, lucid, tx) {
|
|
3759
3800
|
return match11(priceInfo).returnType().with({ Delisted: P12.any }, () => {
|
|
@@ -3834,9 +3875,8 @@ function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythS
|
|
|
3834
3875
|
auxiliaryData: Core.Data.fromCBORHex(Data18.void())
|
|
3835
3876
|
})
|
|
3836
3877
|
);
|
|
3837
|
-
const
|
|
3838
|
-
const
|
|
3839
|
-
const validTo = Number(pythTimestamp + pythMaxDelay);
|
|
3878
|
+
const validFrom = Number(pythTimestamp - PYTH_FEED_LEDGER_TIME_BUFFER);
|
|
3879
|
+
const validTo = Number(pythTimestamp + MAX_PYTH_FEED_DELAY);
|
|
3840
3880
|
return {
|
|
3841
3881
|
interval: {
|
|
3842
3882
|
validFrom,
|
|
@@ -4323,8 +4363,12 @@ async function closeCdp(cdpOref, collateralAssetOref, interestOracleOref, intere
|
|
|
4323
4363
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
4324
4364
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
4325
4365
|
);
|
|
4326
|
-
const validateFrom =
|
|
4327
|
-
|
|
4366
|
+
const validateFrom = Number(
|
|
4367
|
+
currentTime - BigInt(sysParams.cdpParams.biasTime) / 2n
|
|
4368
|
+
);
|
|
4369
|
+
const validateTo = Number(
|
|
4370
|
+
currentTime + BigInt(sysParams.cdpParams.biasTime) / 2n
|
|
4371
|
+
);
|
|
4328
4372
|
const tx = lucid.newTx().readFrom([
|
|
4329
4373
|
cdpRefScriptUtxo,
|
|
4330
4374
|
iAssetTokenPolicyRefScriptUtxo,
|
|
@@ -4519,8 +4563,12 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, coll
|
|
|
4519
4563
|
referenceInputs.push(priceOracleUtxo);
|
|
4520
4564
|
tx.validFrom(txValidity.validFrom).validTo(txValidity.validTo);
|
|
4521
4565
|
} else {
|
|
4522
|
-
const validateFrom =
|
|
4523
|
-
|
|
4566
|
+
const validateFrom = Number(
|
|
4567
|
+
currentTime - BigInt(sysParams.cdpParams.biasTime) / 2n
|
|
4568
|
+
);
|
|
4569
|
+
const validateTo = Number(
|
|
4570
|
+
currentTime + BigInt(sysParams.cdpParams.biasTime) / 2n
|
|
4571
|
+
);
|
|
4524
4572
|
tx.validFrom(validateFrom).validTo(validateTo);
|
|
4525
4573
|
}
|
|
4526
4574
|
const partialRedemptionFee = F12.pipe(
|
|
@@ -7337,10 +7385,9 @@ async function oneShotMintTx(lucid, params) {
|
|
|
7337
7385
|
policyId
|
|
7338
7386
|
];
|
|
7339
7387
|
}
|
|
7340
|
-
async function runOneShotMintTx(lucid, params) {
|
|
7388
|
+
async function runOneShotMintTx(lucid, params, submissionConfig) {
|
|
7341
7389
|
const [tx, policyId] = await oneShotMintTx(lucid, params);
|
|
7342
|
-
|
|
7343
|
-
await lucid.awaitTx(txHash);
|
|
7390
|
+
await runAndAwaitTxBuilder(lucid, tx, submissionConfig);
|
|
7344
7391
|
return policyId;
|
|
7345
7392
|
}
|
|
7346
7393
|
|
|
@@ -8127,9 +8174,8 @@ async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee =
|
|
|
8127
8174
|
)
|
|
8128
8175
|
).addSignerKey(toHex12(oldAccountDatum.owner));
|
|
8129
8176
|
}
|
|
8130
|
-
async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, txFee
|
|
8131
|
-
const
|
|
8132
|
-
const currentTime = BigInt(lucid.slotToUnixTime(slot));
|
|
8177
|
+
async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, txFee) {
|
|
8178
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
8133
8179
|
const stabilityPoolScriptRef = matchSingle5(
|
|
8134
8180
|
await lucid.utxosByOutRef([
|
|
8135
8181
|
fromSystemParamsScriptRef(
|
|
@@ -8145,8 +8191,13 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
8145
8191
|
getInlineDatumOrThrow(stabilityPoolUtxo)
|
|
8146
8192
|
);
|
|
8147
8193
|
const baseRefInputs = [iAssetUtxo, stabilityPoolScriptRef];
|
|
8148
|
-
const
|
|
8149
|
-
|
|
8194
|
+
const validateFrom = Number(
|
|
8195
|
+
currentTime - BigInt(sysParams.stabilityPoolParams.accountProcessingBiasMs) / 2n
|
|
8196
|
+
);
|
|
8197
|
+
const validateTo = Number(
|
|
8198
|
+
currentTime + BigInt(sysParams.stabilityPoolParams.accountProcessingBiasMs) / 2n
|
|
8199
|
+
);
|
|
8200
|
+
const tx = lucid.newTx().validFrom(validateFrom).validTo(validateTo).readFrom(baseRefInputs).collectFrom([stabilityPoolUtxo], {
|
|
8150
8201
|
kind: "selected",
|
|
8151
8202
|
inputs: [stabilityPoolUtxo, accountUtxo],
|
|
8152
8203
|
makeRedeemer: (indices) => serialiseStabilityPoolRedeemer({
|
|
@@ -8517,7 +8568,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
8517
8568
|
}).exhaustive();
|
|
8518
8569
|
return tx;
|
|
8519
8570
|
}
|
|
8520
|
-
async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid
|
|
8571
|
+
async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid) {
|
|
8521
8572
|
const draftTx = processSpRequestAuxiliary(
|
|
8522
8573
|
stabilityPoolUtxo,
|
|
8523
8574
|
accountUtxo,
|
|
@@ -8526,8 +8577,7 @@ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE
|
|
|
8526
8577
|
sysParams,
|
|
8527
8578
|
lucid,
|
|
8528
8579
|
// Placeholder transation fee
|
|
8529
|
-
1n
|
|
8530
|
-
currentSlot
|
|
8580
|
+
1n
|
|
8531
8581
|
);
|
|
8532
8582
|
const fee = (await (await draftTx).complete()).toTransaction().body().fee();
|
|
8533
8583
|
return processSpRequestAuxiliary(
|
|
@@ -8537,8 +8587,7 @@ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE
|
|
|
8537
8587
|
allE2s2sSnapshotOrefs,
|
|
8538
8588
|
sysParams,
|
|
8539
8589
|
lucid,
|
|
8540
|
-
fee
|
|
8541
|
-
currentSlot
|
|
8590
|
+
fee
|
|
8542
8591
|
);
|
|
8543
8592
|
}
|
|
8544
8593
|
async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
|
|
@@ -9929,10 +9978,13 @@ var alwaysFailValidator = {
|
|
|
9929
9978
|
};
|
|
9930
9979
|
|
|
9931
9980
|
// src/utils/helper-txs.ts
|
|
9932
|
-
async function runCreateScriptRefTx(lucid, scriptRefValidator,
|
|
9933
|
-
const scriptAddr = validatorToAddress3(
|
|
9934
|
-
|
|
9935
|
-
|
|
9981
|
+
async function runCreateScriptRefTx(lucid, scriptRefValidator, submissionConfig) {
|
|
9982
|
+
const scriptAddr = validatorToAddress3(
|
|
9983
|
+
lucid.config().network,
|
|
9984
|
+
alwaysFailValidator
|
|
9985
|
+
);
|
|
9986
|
+
const tx = lucid.newTx().pay.ToAddressWithData(scriptAddr, void 0, {}, scriptRefValidator);
|
|
9987
|
+
const txHash = await runAndAwaitTxBuilder(lucid, tx, submissionConfig);
|
|
9936
9988
|
return { txHash, outputIndex: 0 };
|
|
9937
9989
|
}
|
|
9938
9990
|
|
|
@@ -10010,24 +10062,6 @@ var mkIAssetValidatorFromSP = (params) => {
|
|
|
10010
10062
|
|
|
10011
10063
|
// src/contracts/initialize/helpers.ts
|
|
10012
10064
|
import { match as match20 } from "ts-pattern";
|
|
10013
|
-
|
|
10014
|
-
// tests/test-helpers.ts
|
|
10015
|
-
import { array as A15, function as F24, option as O20 } from "fp-ts";
|
|
10016
|
-
async function runAndAwaitTxBuilder(lucid, transaction, extraSigners = []) {
|
|
10017
|
-
const bTx = await transaction.complete();
|
|
10018
|
-
const signatures = [await bTx.partialSign.withWallet()];
|
|
10019
|
-
for (const signer of extraSigners) {
|
|
10020
|
-
lucid.selectWallet.fromSeed(signer);
|
|
10021
|
-
signatures.push(await lucid.fromTx(bTx.toCBOR()).partialSign.withWallet());
|
|
10022
|
-
}
|
|
10023
|
-
const signedTx = bTx.assemble(signatures);
|
|
10024
|
-
const txHash = await signedTx.complete().then((tx) => tx.submit());
|
|
10025
|
-
await lucid.awaitTx(txHash);
|
|
10026
|
-
return txHash;
|
|
10027
|
-
}
|
|
10028
|
-
|
|
10029
|
-
// src/contracts/initialize/helpers.ts
|
|
10030
|
-
var alwaysFailValidatorHash = "ea84d625650d066e1645e3e81d9c70a73f9ed837bd96dc49850ae744";
|
|
10031
10065
|
var DEFAULT_INIT_OPTIONS = {
|
|
10032
10066
|
numCdpCreators: 2n,
|
|
10033
10067
|
numCollectors: 2n,
|
|
@@ -10062,18 +10096,27 @@ var INIT_TOKEN_NAMES = {
|
|
|
10062
10096
|
snapshotEpochToScaleToSum: "SNAPSHOT_EPOCH_TO_SCALE_TO_SUM",
|
|
10063
10097
|
account: "SP_ACCOUNT"
|
|
10064
10098
|
};
|
|
10065
|
-
async function mintOneTimeToken(lucid, tokenName, amount) {
|
|
10099
|
+
async function mintOneTimeToken(lucid, tokenName, amount, submissionConfig) {
|
|
10066
10100
|
const utxos = await lucid.wallet().getUtxos();
|
|
10067
|
-
return await runOneShotMintTx(
|
|
10068
|
-
|
|
10069
|
-
|
|
10070
|
-
|
|
10101
|
+
return await runOneShotMintTx(
|
|
10102
|
+
lucid,
|
|
10103
|
+
{
|
|
10104
|
+
referenceOutRef: {
|
|
10105
|
+
txHash: utxos[0].txHash,
|
|
10106
|
+
outputIdx: BigInt(utxos[0].outputIndex)
|
|
10107
|
+
},
|
|
10108
|
+
mintAmounts: [{ tokenName, amount }]
|
|
10071
10109
|
},
|
|
10072
|
-
|
|
10073
|
-
|
|
10110
|
+
submissionConfig
|
|
10111
|
+
);
|
|
10074
10112
|
}
|
|
10075
|
-
async function mintOneTimeAsset(lucid, tokenName, amount) {
|
|
10076
|
-
const policyId = await mintOneTimeToken(
|
|
10113
|
+
async function mintOneTimeAsset(lucid, tokenName, amount, submissionConfig) {
|
|
10114
|
+
const policyId = await mintOneTimeToken(
|
|
10115
|
+
lucid,
|
|
10116
|
+
fromText11(tokenName),
|
|
10117
|
+
amount,
|
|
10118
|
+
submissionConfig
|
|
10119
|
+
);
|
|
10077
10120
|
return {
|
|
10078
10121
|
currencySymbol: fromHex16(policyId),
|
|
10079
10122
|
tokenName: fromHex16(fromText11(tokenName))
|
|
@@ -10086,20 +10129,6 @@ function deriveAuthToken(parent, tokenName) {
|
|
|
10086
10129
|
tokenName: fromHex16(fromText11(tokenName))
|
|
10087
10130
|
};
|
|
10088
10131
|
}
|
|
10089
|
-
async function initScriptRef(lucid, validator) {
|
|
10090
|
-
const tx = lucid.newTx().pay.ToContract(
|
|
10091
|
-
credentialToAddress4(lucid.config().network, {
|
|
10092
|
-
hash: alwaysFailValidatorHash,
|
|
10093
|
-
type: "Script"
|
|
10094
|
-
}),
|
|
10095
|
-
void 0,
|
|
10096
|
-
void 0,
|
|
10097
|
-
validator
|
|
10098
|
-
);
|
|
10099
|
-
const txHash = await tx.complete().then((t) => t.sign.withWallet().complete()).then((t) => t.submit());
|
|
10100
|
-
await lucid.awaitTx(txHash);
|
|
10101
|
-
return { transactionId: txHash, index: 0 };
|
|
10102
|
-
}
|
|
10103
10132
|
async function initCollector(lucid, collectorParams, numCollectors) {
|
|
10104
10133
|
const tx = lucid.newTx();
|
|
10105
10134
|
for (let i = 0; i < Number(numCollectors); i++) {
|
|
@@ -10114,7 +10143,7 @@ async function initCollector(lucid, collectorParams, numCollectors) {
|
|
|
10114
10143
|
}
|
|
10115
10144
|
);
|
|
10116
10145
|
}
|
|
10117
|
-
await
|
|
10146
|
+
await runAndAwaitTxBuilder(lucid, tx);
|
|
10118
10147
|
}
|
|
10119
10148
|
async function initInterestCollector(lucid, interestCollectionValHash, multisigUtxoNft, numInterestCollectors, interestCollectorUtxoLovelaces) {
|
|
10120
10149
|
const [pkh, _] = await addrDetails(lucid);
|
|
@@ -10125,7 +10154,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
|
|
|
10125
10154
|
}
|
|
10126
10155
|
}
|
|
10127
10156
|
};
|
|
10128
|
-
await
|
|
10157
|
+
await runAndAwaitTxBuilder(
|
|
10129
10158
|
lucid,
|
|
10130
10159
|
lucid.newTx().pay.ToContract(
|
|
10131
10160
|
createScriptAddress(lucid.config().network, interestCollectionValHash),
|
|
@@ -10144,7 +10173,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
|
|
|
10144
10173
|
mkLovelacesOf7(interestCollectorUtxoLovelaces)
|
|
10145
10174
|
);
|
|
10146
10175
|
}
|
|
10147
|
-
await
|
|
10176
|
+
await runAndAwaitTxBuilder(lucid, interestCollectionUtxoDeploymentTx);
|
|
10148
10177
|
}
|
|
10149
10178
|
async function initCDPCreator(lucid, cdpCreatorParams, numCdpCreators) {
|
|
10150
10179
|
const tx = lucid.newTx();
|
|
@@ -10162,7 +10191,7 @@ async function initCDPCreator(lucid, cdpCreatorParams, numCdpCreators) {
|
|
|
10162
10191
|
}
|
|
10163
10192
|
);
|
|
10164
10193
|
}
|
|
10165
|
-
await
|
|
10194
|
+
await runAndAwaitTxBuilder(lucid, tx);
|
|
10166
10195
|
}
|
|
10167
10196
|
async function initTreasury(lucid, treasuryParams, daoAsset, indyAsset, treasuryIndyAmount, numTreasuryCollectors) {
|
|
10168
10197
|
const treasuryAddr = createScriptAddress(
|
|
@@ -10184,7 +10213,7 @@ async function initTreasury(lucid, treasuryParams, daoAsset, indyAsset, treasury
|
|
|
10184
10213
|
value: Data49.void()
|
|
10185
10214
|
});
|
|
10186
10215
|
}
|
|
10187
|
-
await
|
|
10216
|
+
await runAndAwaitTxBuilder(lucid, tx);
|
|
10188
10217
|
}
|
|
10189
10218
|
async function initStakingManager(lucid, stakingParams) {
|
|
10190
10219
|
const tx = lucid.newTx().pay.ToContract(
|
|
@@ -10203,7 +10232,7 @@ async function initStakingManager(lucid, stakingParams) {
|
|
|
10203
10232
|
[stakingParams.stakingManagerNFT[0].unCurrencySymbol + fromText11(stakingParams.stakingManagerNFT[1].unTokenName)]: 1n
|
|
10204
10233
|
}
|
|
10205
10234
|
);
|
|
10206
|
-
await
|
|
10235
|
+
await runAndAwaitTxBuilder(lucid, tx);
|
|
10207
10236
|
}
|
|
10208
10237
|
async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, pythConfig) {
|
|
10209
10238
|
return match20(collateralAsset.priceOracle).returnType().with({ tag: "_indigo_oracle_nft" }, async (val) => {
|
|
@@ -10255,7 +10284,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10255
10284
|
lucid,
|
|
10256
10285
|
collateralAsset.interestOracle.tokenName
|
|
10257
10286
|
);
|
|
10258
|
-
await
|
|
10287
|
+
await runAndAwaitTxBuilder(lucid, startInterestOracleTx);
|
|
10259
10288
|
const priceInfo = await handleOracleForCollateralAsset(
|
|
10260
10289
|
lucid,
|
|
10261
10290
|
asset,
|
|
@@ -10288,7 +10317,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10288
10317
|
},
|
|
10289
10318
|
mkAssetsOf13(collateralAssetAuthToken, 1n)
|
|
10290
10319
|
);
|
|
10291
|
-
await
|
|
10320
|
+
await runAndAwaitTxBuilder(lucid, collateralAssetTx);
|
|
10292
10321
|
collateralAssetInfos.push({
|
|
10293
10322
|
collateralAsset: collateralAsset.collateralAsset,
|
|
10294
10323
|
interestOracleNft,
|
|
@@ -10310,7 +10339,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10310
10339
|
iasset: iassetName,
|
|
10311
10340
|
stableswapValHash: fromHex16(stableswapValidatorHash)
|
|
10312
10341
|
};
|
|
10313
|
-
await
|
|
10342
|
+
await runAndAwaitTxBuilder(
|
|
10314
10343
|
lucid,
|
|
10315
10344
|
lucid.newTx().pay.ToContract(
|
|
10316
10345
|
createScriptAddress(
|
|
@@ -10347,7 +10376,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10347
10376
|
},
|
|
10348
10377
|
mkAssetsOf13(iassetToken, 1n)
|
|
10349
10378
|
);
|
|
10350
|
-
await
|
|
10379
|
+
await runAndAwaitTxBuilder(lucid, assetTx);
|
|
10351
10380
|
const stabilityPoolDatum = {
|
|
10352
10381
|
iasset: fromHex16(fromText11(asset.name)),
|
|
10353
10382
|
state: initSpState,
|
|
@@ -10366,7 +10395,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10366
10395
|
},
|
|
10367
10396
|
mkAssetsOf13(stabilityPoolToken, 1n)
|
|
10368
10397
|
);
|
|
10369
|
-
await
|
|
10398
|
+
await runAndAwaitTxBuilder(lucid, spTx);
|
|
10370
10399
|
return {
|
|
10371
10400
|
iassetTokenNameAscii: asset.name,
|
|
10372
10401
|
collateralAssets: collateralAssetInfos
|
|
@@ -10388,7 +10417,7 @@ async function initGovernance(lucid, governanceParams, govToken, initialAssets,
|
|
|
10388
10417
|
{ kind: "inline", value: serialiseGovDatum(datum) },
|
|
10389
10418
|
mkAssetsOf13(govToken, 1n)
|
|
10390
10419
|
);
|
|
10391
|
-
await
|
|
10420
|
+
await runAndAwaitTxBuilder(lucid, tx);
|
|
10392
10421
|
}
|
|
10393
10422
|
async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
|
|
10394
10423
|
const script = mkAuthTokenPolicy(asset, fromText11(tokenName));
|
|
@@ -10405,7 +10434,7 @@ async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
|
|
|
10405
10434
|
},
|
|
10406
10435
|
Data49.void()
|
|
10407
10436
|
);
|
|
10408
|
-
await
|
|
10437
|
+
await runAndAwaitTxBuilder(lucid, tx);
|
|
10409
10438
|
}
|
|
10410
10439
|
|
|
10411
10440
|
// src/contracts/initialize/actions.ts
|
|
@@ -10593,23 +10622,30 @@ async function initPyth(lucid) {
|
|
|
10593
10622
|
alwaysSucceedValidator
|
|
10594
10623
|
)
|
|
10595
10624
|
);
|
|
10596
|
-
|
|
10597
|
-
lucid.config().network,
|
|
10598
|
-
{ hash: validatorToScriptHash4(alwaysSucceedValidator), type: "Script" }
|
|
10599
|
-
);
|
|
10600
|
-
const { registered } = await lucid.rewardAccountAt(
|
|
10601
|
-
alwaysSucceedRewardAddress
|
|
10602
|
-
);
|
|
10603
|
-
if (!registered) {
|
|
10625
|
+
try {
|
|
10604
10626
|
await runAndAwaitTxBuilder(
|
|
10605
10627
|
lucid,
|
|
10606
|
-
lucid.newTx().register.Stake(
|
|
10628
|
+
lucid.newTx().register.Stake(
|
|
10629
|
+
credentialToRewardAddress3(lucid.config().network, {
|
|
10630
|
+
hash: validatorToScriptHash4(alwaysSucceedValidator),
|
|
10631
|
+
type: "Script"
|
|
10632
|
+
})
|
|
10633
|
+
)
|
|
10607
10634
|
);
|
|
10635
|
+
} catch (error) {
|
|
10636
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
10637
|
+
if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes("Trying to re-register some already known credentials.")) {
|
|
10638
|
+
throw error;
|
|
10639
|
+
}
|
|
10608
10640
|
}
|
|
10609
10641
|
return pythStateAsset;
|
|
10610
10642
|
}
|
|
10611
10643
|
|
|
10612
10644
|
// src/contracts/initialize/actions.ts
|
|
10645
|
+
function isAlreadyRegisteredError(error) {
|
|
10646
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
10647
|
+
return message.includes("StakeKeyRegisteredDELEG") || message.includes("Trying to re-register some already known credentials.");
|
|
10648
|
+
}
|
|
10613
10649
|
var DEFAULT_STAKING_CRED = {
|
|
10614
10650
|
tag: "StakingHash",
|
|
10615
10651
|
contents: {
|
|
@@ -10626,29 +10662,31 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
|
|
|
10626
10662
|
fromSysParamsPythFeedParams(val.pythFeedParams)
|
|
10627
10663
|
);
|
|
10628
10664
|
const pythFeedValHash = validatorToScriptHash5(pythFeedValidator);
|
|
10629
|
-
const pythFeedValScriptRef = await
|
|
10665
|
+
const pythFeedValScriptRef = await runCreateScriptRefTx(
|
|
10630
10666
|
lucid,
|
|
10631
10667
|
pythFeedValidator
|
|
10632
10668
|
);
|
|
10633
|
-
|
|
10634
|
-
lucid.config().network,
|
|
10635
|
-
{ hash: validatorToScriptHash5(pythFeedValidator), type: "Script" }
|
|
10636
|
-
);
|
|
10637
|
-
const { registered } = await lucid.rewardAccountAt(
|
|
10638
|
-
pythFeedRewardAddress
|
|
10639
|
-
);
|
|
10640
|
-
if (!registered) {
|
|
10669
|
+
try {
|
|
10641
10670
|
await runAndAwaitTxBuilder(
|
|
10642
10671
|
lucid,
|
|
10643
|
-
lucid.newTx().register.Stake(
|
|
10672
|
+
lucid.newTx().register.Stake(
|
|
10673
|
+
credentialToRewardAddress4(lucid.config().network, {
|
|
10674
|
+
hash: validatorToScriptHash5(pythFeedValidator),
|
|
10675
|
+
type: "Script"
|
|
10676
|
+
})
|
|
10677
|
+
)
|
|
10644
10678
|
);
|
|
10679
|
+
} catch (error) {
|
|
10680
|
+
if (!isAlreadyRegisteredError(error)) throw error;
|
|
10645
10681
|
}
|
|
10646
10682
|
const key = `${asset.name}/${toHex17(collateral.collateralAsset.currencySymbol)}.${toHex17(collateral.collateralAsset.tokenName)}`;
|
|
10647
10683
|
return {
|
|
10648
10684
|
[key]: {
|
|
10649
10685
|
params: val.pythFeedParams,
|
|
10650
10686
|
pythFeedValHash,
|
|
10651
|
-
pythFeedValScriptRef: {
|
|
10687
|
+
pythFeedValScriptRef: {
|
|
10688
|
+
input: toSystemParamsInput(pythFeedValScriptRef)
|
|
10689
|
+
}
|
|
10652
10690
|
}
|
|
10653
10691
|
};
|
|
10654
10692
|
}).otherwise(() => Promise.resolve({}));
|
|
@@ -10682,6 +10720,19 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10682
10720
|
const indyAsset = await mintOneTimeAsset(lucid, tn.indy, totalIndySupply);
|
|
10683
10721
|
const daoAsset = await mintOneTimeAsset(lucid, tn.dao, 1n);
|
|
10684
10722
|
const govNftAsset = await mintOneTimeAsset(lucid, tn.govNft, 1n);
|
|
10723
|
+
const cdpCreatorAsset = await mintOneTimeAsset(
|
|
10724
|
+
lucid,
|
|
10725
|
+
tn.cdpCreator,
|
|
10726
|
+
numCdpCreators
|
|
10727
|
+
);
|
|
10728
|
+
const cdpToken = deriveAuthToken(cdpCreatorAsset, tn.cdp);
|
|
10729
|
+
const stakingManagerAsset = await mintOneTimeAsset(
|
|
10730
|
+
lucid,
|
|
10731
|
+
tn.stakingManager,
|
|
10732
|
+
1n
|
|
10733
|
+
);
|
|
10734
|
+
const multisigUtxoNft = await mintOneTimeAsset(lucid, tn.multisigUtxo, 1n);
|
|
10735
|
+
const stakingToken = deriveAuthToken(stakingManagerAsset, tn.staking);
|
|
10685
10736
|
const pollToken = deriveAuthToken(govNftAsset, tn.pollManager);
|
|
10686
10737
|
const upgradeToken = deriveAuthToken(pollToken, tn.upgrade);
|
|
10687
10738
|
const iassetToken = deriveAuthToken(upgradeToken, tn.iasset);
|
|
@@ -10707,18 +10758,6 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10707
10758
|
const versionRegistryValHash = validatorToScriptHash5(
|
|
10708
10759
|
versionRegistryValidator
|
|
10709
10760
|
);
|
|
10710
|
-
const cdpCreatorAsset = await mintOneTimeAsset(
|
|
10711
|
-
lucid,
|
|
10712
|
-
tn.cdpCreator,
|
|
10713
|
-
numCdpCreators
|
|
10714
|
-
);
|
|
10715
|
-
const cdpToken = deriveAuthToken(cdpCreatorAsset, tn.cdp);
|
|
10716
|
-
const stakingManagerAsset = await mintOneTimeAsset(
|
|
10717
|
-
lucid,
|
|
10718
|
-
tn.stakingManager,
|
|
10719
|
-
1n
|
|
10720
|
-
);
|
|
10721
|
-
const stakingToken = deriveAuthToken(stakingManagerAsset, tn.staking);
|
|
10722
10761
|
const collectorParams = {
|
|
10723
10762
|
stakingManagerNFT: toSystemParamsAsset(stakingManagerAsset),
|
|
10724
10763
|
stakingToken: toSystemParamsAsset(stakingToken),
|
|
@@ -10784,7 +10823,6 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10784
10823
|
treasuryIndyAmount,
|
|
10785
10824
|
numTreasuryUtxos
|
|
10786
10825
|
);
|
|
10787
|
-
const multisigUtxoNft = await mintOneTimeAsset(lucid, tn.multisigUtxo, 1n);
|
|
10788
10826
|
const interestCollectionParams = {
|
|
10789
10827
|
versionRecordNft: toSystemParamsAsset(versionRecordToken),
|
|
10790
10828
|
multisigUtxoNft: toSystemParamsAsset(multisigUtxoNft),
|
|
@@ -10832,12 +10870,13 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10832
10870
|
lucid.config().network,
|
|
10833
10871
|
scriptHashToCredential4(cdpRedeemValHash)
|
|
10834
10872
|
);
|
|
10835
|
-
|
|
10836
|
-
if (!cdpRedeemRegistered) {
|
|
10873
|
+
try {
|
|
10837
10874
|
await runAndAwaitTxBuilder(
|
|
10838
10875
|
lucid,
|
|
10839
10876
|
lucid.newTx().register.Stake(cdpRedeemRewardAddr)
|
|
10840
10877
|
);
|
|
10878
|
+
} catch (error) {
|
|
10879
|
+
if (!isAlreadyRegisteredError(error)) throw error;
|
|
10841
10880
|
}
|
|
10842
10881
|
const cdpParams = {
|
|
10843
10882
|
cdpAuthToken: toSystemParamsAsset(cdpToken),
|
|
@@ -11087,97 +11126,155 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
11087
11126
|
},
|
|
11088
11127
|
scriptReferences: {
|
|
11089
11128
|
interestCollectionValidatorRef: {
|
|
11090
|
-
input:
|
|
11129
|
+
input: toSystemParamsInput(
|
|
11130
|
+
await runCreateScriptRefTx(lucid, interestCollectionValidator)
|
|
11131
|
+
)
|
|
11091
11132
|
},
|
|
11092
11133
|
robValidatorRef: {
|
|
11093
|
-
input:
|
|
11134
|
+
input: toSystemParamsInput(
|
|
11135
|
+
await runCreateScriptRefTx(lucid, robValidator)
|
|
11136
|
+
)
|
|
11094
11137
|
},
|
|
11095
11138
|
cdpCreatorValidatorRef: {
|
|
11096
|
-
input:
|
|
11139
|
+
input: toSystemParamsInput(
|
|
11140
|
+
await runCreateScriptRefTx(lucid, cdpCreatorValidator)
|
|
11141
|
+
)
|
|
11097
11142
|
},
|
|
11098
11143
|
cdpValidatorRef: {
|
|
11099
|
-
input:
|
|
11144
|
+
input: toSystemParamsInput(
|
|
11145
|
+
await runCreateScriptRefTx(lucid, cdpValidator)
|
|
11146
|
+
)
|
|
11100
11147
|
},
|
|
11101
11148
|
cdpRedeemValidatorRef: {
|
|
11102
|
-
input:
|
|
11149
|
+
input: toSystemParamsInput(
|
|
11150
|
+
await runCreateScriptRefTx(lucid, cdpRedeemValidator)
|
|
11151
|
+
)
|
|
11103
11152
|
},
|
|
11104
11153
|
collectorValidatorRef: {
|
|
11105
|
-
input:
|
|
11154
|
+
input: toSystemParamsInput(
|
|
11155
|
+
await runCreateScriptRefTx(lucid, collectorValidator)
|
|
11156
|
+
)
|
|
11106
11157
|
},
|
|
11107
11158
|
executeValidatorRef: {
|
|
11108
|
-
input:
|
|
11159
|
+
input: toSystemParamsInput(
|
|
11160
|
+
await runCreateScriptRefTx(lucid, executeValidator)
|
|
11161
|
+
)
|
|
11109
11162
|
},
|
|
11110
11163
|
pollShardValidatorRef: {
|
|
11111
|
-
input:
|
|
11164
|
+
input: toSystemParamsInput(
|
|
11165
|
+
await runCreateScriptRefTx(lucid, pollShardValidator)
|
|
11166
|
+
)
|
|
11112
11167
|
},
|
|
11113
11168
|
pollManagerValidatorRef: {
|
|
11114
|
-
input:
|
|
11169
|
+
input: toSystemParamsInput(
|
|
11170
|
+
await runCreateScriptRefTx(lucid, pollManagerValidator)
|
|
11171
|
+
)
|
|
11115
11172
|
},
|
|
11116
11173
|
iAssetTokenPolicyRef: {
|
|
11117
|
-
input:
|
|
11174
|
+
input: toSystemParamsInput(
|
|
11175
|
+
await runCreateScriptRefTx(lucid, assetSymbolPolicy)
|
|
11176
|
+
)
|
|
11118
11177
|
},
|
|
11119
11178
|
stakingValidatorRef: {
|
|
11120
|
-
input:
|
|
11121
|
-
|
|
11122
|
-
|
|
11179
|
+
input: toSystemParamsInput(
|
|
11180
|
+
await runCreateScriptRefTx(
|
|
11181
|
+
lucid,
|
|
11182
|
+
mkStakingValidatorFromSP(stakingParams)
|
|
11183
|
+
)
|
|
11123
11184
|
)
|
|
11124
11185
|
},
|
|
11125
11186
|
stabilityPoolValidatorRef: {
|
|
11126
|
-
input:
|
|
11187
|
+
input: toSystemParamsInput(
|
|
11188
|
+
await runCreateScriptRefTx(lucid, stabilityPoolValidator)
|
|
11189
|
+
)
|
|
11127
11190
|
},
|
|
11128
11191
|
stableswapValidatorRef: {
|
|
11129
|
-
input:
|
|
11192
|
+
input: toSystemParamsInput(
|
|
11193
|
+
await runCreateScriptRefTx(lucid, stableswapValidator)
|
|
11194
|
+
)
|
|
11130
11195
|
},
|
|
11131
11196
|
treasuryValidatorRef: {
|
|
11132
|
-
input:
|
|
11197
|
+
input: toSystemParamsInput(
|
|
11198
|
+
await runCreateScriptRefTx(lucid, treasuryValidator)
|
|
11199
|
+
)
|
|
11133
11200
|
},
|
|
11134
11201
|
governanceValidatorRef: {
|
|
11135
|
-
input:
|
|
11202
|
+
input: toSystemParamsInput(
|
|
11203
|
+
await runCreateScriptRefTx(lucid, govValidator)
|
|
11204
|
+
)
|
|
11136
11205
|
},
|
|
11137
11206
|
versionRegistryValidatorRef: {
|
|
11138
|
-
input:
|
|
11207
|
+
input: toSystemParamsInput(
|
|
11208
|
+
await runCreateScriptRefTx(lucid, versionRegistryValidator)
|
|
11209
|
+
)
|
|
11139
11210
|
},
|
|
11140
11211
|
iassetValidatorRef: {
|
|
11141
|
-
input:
|
|
11212
|
+
input: toSystemParamsInput(
|
|
11213
|
+
await runCreateScriptRefTx(lucid, iassetValidator)
|
|
11214
|
+
)
|
|
11142
11215
|
},
|
|
11143
11216
|
authTokenPolicies: {
|
|
11144
11217
|
cdpAuthTokenRef: {
|
|
11145
|
-
input:
|
|
11218
|
+
input: toSystemParamsInput(
|
|
11219
|
+
await runCreateScriptRefTx(lucid, cdpTokenPolicy)
|
|
11220
|
+
)
|
|
11146
11221
|
},
|
|
11147
11222
|
iAssetAuthTokenRef: {
|
|
11148
|
-
input:
|
|
11223
|
+
input: toSystemParamsInput(
|
|
11224
|
+
await runCreateScriptRefTx(lucid, iassetTokenPolicy)
|
|
11225
|
+
)
|
|
11149
11226
|
},
|
|
11150
11227
|
accountTokenRef: {
|
|
11151
|
-
input:
|
|
11228
|
+
input: toSystemParamsInput(
|
|
11229
|
+
await runCreateScriptRefTx(lucid, accountTokenPolicy)
|
|
11230
|
+
)
|
|
11152
11231
|
},
|
|
11153
11232
|
stabilityPoolAuthTokenRef: {
|
|
11154
|
-
input:
|
|
11233
|
+
input: toSystemParamsInput(
|
|
11234
|
+
await runCreateScriptRefTx(lucid, stabilityPoolTokenPolicy)
|
|
11235
|
+
)
|
|
11155
11236
|
},
|
|
11156
11237
|
pollManagerTokenRef: {
|
|
11157
|
-
input:
|
|
11238
|
+
input: toSystemParamsInput(
|
|
11239
|
+
await runCreateScriptRefTx(lucid, pollTokenPolicy)
|
|
11240
|
+
)
|
|
11158
11241
|
},
|
|
11159
11242
|
stakingTokenRef: {
|
|
11160
|
-
input:
|
|
11243
|
+
input: toSystemParamsInput(
|
|
11244
|
+
await runCreateScriptRefTx(lucid, stakingTokenPolicy)
|
|
11245
|
+
)
|
|
11161
11246
|
},
|
|
11162
11247
|
versionRecordTokenPolicyRef: {
|
|
11163
|
-
input:
|
|
11248
|
+
input: toSystemParamsInput(
|
|
11249
|
+
await runCreateScriptRefTx(lucid, versionRecordTokenPolicy)
|
|
11250
|
+
)
|
|
11164
11251
|
},
|
|
11165
11252
|
iAssetTokenRef: {
|
|
11166
|
-
input:
|
|
11253
|
+
input: toSystemParamsInput(
|
|
11254
|
+
await runCreateScriptRefTx(lucid, assetSymbolPolicy)
|
|
11255
|
+
)
|
|
11167
11256
|
},
|
|
11168
11257
|
collateralAssetTokenRef: {
|
|
11169
|
-
input:
|
|
11258
|
+
input: toSystemParamsInput(
|
|
11259
|
+
await runCreateScriptRefTx(lucid, collateralAssetAuthTokenPolicy)
|
|
11260
|
+
)
|
|
11170
11261
|
},
|
|
11171
11262
|
upgradeTokenRef: {
|
|
11172
|
-
input:
|
|
11263
|
+
input: toSystemParamsInput(
|
|
11264
|
+
await runCreateScriptRefTx(lucid, upgradeTokenPolicy)
|
|
11265
|
+
)
|
|
11173
11266
|
},
|
|
11174
11267
|
stabilityPoolTokenRef: {
|
|
11175
|
-
input:
|
|
11268
|
+
input: toSystemParamsInput(
|
|
11269
|
+
await runCreateScriptRefTx(lucid, stabilityPoolTokenPolicy)
|
|
11270
|
+
)
|
|
11176
11271
|
},
|
|
11177
11272
|
snapshotEpochToScaleToSumTokenRef: {
|
|
11178
|
-
input:
|
|
11179
|
-
|
|
11180
|
-
|
|
11273
|
+
input: toSystemParamsInput(
|
|
11274
|
+
await runCreateScriptRefTx(
|
|
11275
|
+
lucid,
|
|
11276
|
+
snapshotEpochToScaleToSumTokenPolicy
|
|
11277
|
+
)
|
|
11181
11278
|
)
|
|
11182
11279
|
}
|
|
11183
11280
|
}
|
|
@@ -11211,7 +11308,7 @@ import {
|
|
|
11211
11308
|
isSameAssetClass as isSameAssetClass5,
|
|
11212
11309
|
matchSingle as matchSingle6
|
|
11213
11310
|
} from "@indigo-labs/cardano-offchain-common";
|
|
11214
|
-
import { option as
|
|
11311
|
+
import { option as O20, array as A15, function as F24 } from "fp-ts";
|
|
11215
11312
|
async function findIAsset(lucid, sysParams, iassetName) {
|
|
11216
11313
|
const iassetUtxos = await lucid.utxosAtWithUnit(
|
|
11217
11314
|
createScriptAddress(
|
|
@@ -11223,21 +11320,21 @@ async function findIAsset(lucid, sysParams, iassetName) {
|
|
|
11223
11320
|
)
|
|
11224
11321
|
);
|
|
11225
11322
|
return matchSingle6(
|
|
11226
|
-
|
|
11323
|
+
F24.pipe(
|
|
11227
11324
|
iassetUtxos.map(
|
|
11228
|
-
(utxo) =>
|
|
11229
|
-
|
|
11230
|
-
|
|
11231
|
-
|
|
11325
|
+
(utxo) => F24.pipe(
|
|
11326
|
+
O20.fromNullable(utxo.datum),
|
|
11327
|
+
O20.flatMap(parseIAssetDatum),
|
|
11328
|
+
O20.flatMap((datum) => {
|
|
11232
11329
|
if (toHex18(datum.assetName) === toHex18(iassetName)) {
|
|
11233
|
-
return
|
|
11330
|
+
return O20.some({ utxo, datum });
|
|
11234
11331
|
} else {
|
|
11235
|
-
return
|
|
11332
|
+
return O20.none;
|
|
11236
11333
|
}
|
|
11237
11334
|
})
|
|
11238
11335
|
)
|
|
11239
11336
|
),
|
|
11240
|
-
|
|
11337
|
+
A15.compact
|
|
11241
11338
|
),
|
|
11242
11339
|
(res) => new Error("Expected a single IAsset UTXO.: " + JSON.stringify(res))
|
|
11243
11340
|
);
|
|
@@ -11253,21 +11350,21 @@ async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset
|
|
|
11253
11350
|
)
|
|
11254
11351
|
);
|
|
11255
11352
|
return matchSingle6(
|
|
11256
|
-
|
|
11353
|
+
F24.pipe(
|
|
11257
11354
|
collateralAssetUtxos.map(
|
|
11258
|
-
(utxo) =>
|
|
11259
|
-
|
|
11260
|
-
|
|
11261
|
-
|
|
11355
|
+
(utxo) => F24.pipe(
|
|
11356
|
+
O20.fromNullable(utxo.datum),
|
|
11357
|
+
O20.flatMap(parseCollateralAssetDatum),
|
|
11358
|
+
O20.flatMap((datum) => {
|
|
11262
11359
|
if (isSameAssetClass5(datum.collateralAsset, collateralAsset) && toHex18(iassetName) === toHex18(datum.iasset)) {
|
|
11263
|
-
return
|
|
11360
|
+
return O20.some({ utxo, datum });
|
|
11264
11361
|
} else {
|
|
11265
|
-
return
|
|
11362
|
+
return O20.none;
|
|
11266
11363
|
}
|
|
11267
11364
|
})
|
|
11268
11365
|
)
|
|
11269
11366
|
),
|
|
11270
|
-
|
|
11367
|
+
A15.compact
|
|
11271
11368
|
),
|
|
11272
11369
|
(res) => new Error(
|
|
11273
11370
|
"Expected a single Collateral Asset UTXO.: " + JSON.stringify(res)
|
|
@@ -11281,7 +11378,7 @@ import {
|
|
|
11281
11378
|
fromText as fromText14,
|
|
11282
11379
|
toHex as toHex19
|
|
11283
11380
|
} from "@lucid-evolution/lucid";
|
|
11284
|
-
import { array as
|
|
11381
|
+
import { array as A16, ord as Ord5, function as F26 } from "fp-ts";
|
|
11285
11382
|
|
|
11286
11383
|
// src/contracts/stableswap/types-new.ts
|
|
11287
11384
|
import {
|
|
@@ -11290,7 +11387,7 @@ import {
|
|
|
11290
11387
|
OutputReferenceSchema as OutputReferenceSchema7
|
|
11291
11388
|
} from "@indigo-labs/cardano-offchain-common";
|
|
11292
11389
|
import { TSchema as TSchema20, Data as Data51 } from "@evolution-sdk/evolution";
|
|
11293
|
-
import { option as
|
|
11390
|
+
import { option as O21, function as F25 } from "fp-ts";
|
|
11294
11391
|
import { Schema as Schema4 } from "effect";
|
|
11295
11392
|
var OpaqueData4 = Schema4.typeSchema(Data51.DataSchema);
|
|
11296
11393
|
var StableswapOrderDatumSchema = TSchema20.Struct({
|
|
@@ -11332,22 +11429,22 @@ function serialiseStableswapOrderDatum(d) {
|
|
|
11332
11429
|
}
|
|
11333
11430
|
function parseStableswapOrderDatum(datum) {
|
|
11334
11431
|
try {
|
|
11335
|
-
return
|
|
11432
|
+
return O21.some(
|
|
11336
11433
|
Data51.withSchema(
|
|
11337
11434
|
StableswapOrderDatumSchema,
|
|
11338
11435
|
DEFAULT_SCHEMA_OPTIONS
|
|
11339
11436
|
).fromCBORHex(datum)
|
|
11340
11437
|
);
|
|
11341
11438
|
} catch (_) {
|
|
11342
|
-
return
|
|
11439
|
+
return O21.none;
|
|
11343
11440
|
}
|
|
11344
11441
|
}
|
|
11345
11442
|
function parseStableswapOrderDatumOrThrow(datum) {
|
|
11346
|
-
return
|
|
11443
|
+
return F25.pipe(
|
|
11347
11444
|
parseStableswapOrderDatum(datum),
|
|
11348
|
-
|
|
11445
|
+
O21.match(() => {
|
|
11349
11446
|
throw new Error("Expected a Stableswap Order datum.");
|
|
11350
|
-
},
|
|
11447
|
+
}, F25.identity)
|
|
11351
11448
|
);
|
|
11352
11449
|
}
|
|
11353
11450
|
function serialiseStableswapOutputDatum(d) {
|
|
@@ -11364,22 +11461,22 @@ function serialiseStableswapOrderRedeemer(r) {
|
|
|
11364
11461
|
}
|
|
11365
11462
|
function parseStableswapOrderRedeemer(redeemerCborHex) {
|
|
11366
11463
|
try {
|
|
11367
|
-
return
|
|
11464
|
+
return O21.some(
|
|
11368
11465
|
Data51.withSchema(
|
|
11369
11466
|
StableswapOrderRedeemerSchema,
|
|
11370
11467
|
DEFAULT_SCHEMA_OPTIONS
|
|
11371
11468
|
).fromCBORHex(redeemerCborHex)
|
|
11372
11469
|
);
|
|
11373
11470
|
} catch (_) {
|
|
11374
|
-
return
|
|
11471
|
+
return O21.none;
|
|
11375
11472
|
}
|
|
11376
11473
|
}
|
|
11377
11474
|
function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
|
|
11378
|
-
return
|
|
11475
|
+
return F25.pipe(
|
|
11379
11476
|
parseStableswapOrderRedeemer(redeemerCborHex),
|
|
11380
|
-
|
|
11477
|
+
O21.match(() => {
|
|
11381
11478
|
throw new Error("Expected a Stableswap Order redeemer.");
|
|
11382
|
-
},
|
|
11479
|
+
}, F25.identity)
|
|
11383
11480
|
);
|
|
11384
11481
|
}
|
|
11385
11482
|
|
|
@@ -11639,15 +11736,15 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
|
|
|
11639
11736
|
return [];
|
|
11640
11737
|
}
|
|
11641
11738
|
});
|
|
11642
|
-
const { left: mintingOrders, right: redeemingOrdersSortedDesc } =
|
|
11739
|
+
const { left: mintingOrders, right: redeemingOrdersSortedDesc } = F26.pipe(
|
|
11643
11740
|
validOrders,
|
|
11644
|
-
|
|
11741
|
+
A16.partition((o) => o.orderType === "REDEEMING"),
|
|
11645
11742
|
({ left, right }) => ({
|
|
11646
11743
|
left,
|
|
11647
11744
|
// Sort the redeeming orders descending.
|
|
11648
|
-
right:
|
|
11745
|
+
right: F26.pipe(
|
|
11649
11746
|
right,
|
|
11650
|
-
|
|
11747
|
+
A16.sort(
|
|
11651
11748
|
Ord5.contramap(
|
|
11652
11749
|
(o) => o.swapInfo.owedCollateralAsset
|
|
11653
11750
|
)(Ord5.reverse(BigIntOrd))
|
|
@@ -11655,9 +11752,9 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
|
|
|
11655
11752
|
)
|
|
11656
11753
|
})
|
|
11657
11754
|
);
|
|
11658
|
-
const totalCollateralDiff =
|
|
11755
|
+
const totalCollateralDiff = F26.pipe(
|
|
11659
11756
|
validOrders,
|
|
11660
|
-
|
|
11757
|
+
A16.reduce(
|
|
11661
11758
|
0n,
|
|
11662
11759
|
(acc, order) => acc + order.swapInfo.suppliedCollateralAsset - order.swapInfo.owedCollateralAsset
|
|
11663
11760
|
)
|
|
@@ -11665,13 +11762,13 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
|
|
|
11665
11762
|
if (psmAvailableLiq + totalCollateralDiff >= 0n) {
|
|
11666
11763
|
return validOrders.map((o) => o.order);
|
|
11667
11764
|
}
|
|
11668
|
-
const collateralFromMinting =
|
|
11765
|
+
const collateralFromMinting = F26.pipe(
|
|
11669
11766
|
mintingOrders,
|
|
11670
|
-
|
|
11767
|
+
A16.reduce(0n, (acc, o) => acc + o.swapInfo.suppliedCollateralAsset)
|
|
11671
11768
|
);
|
|
11672
|
-
const { selected } =
|
|
11769
|
+
const { selected } = F26.pipe(
|
|
11673
11770
|
redeemingOrdersSortedDesc,
|
|
11674
|
-
|
|
11771
|
+
A16.reduce(
|
|
11675
11772
|
{
|
|
11676
11773
|
intermediateCollateralAmt: psmAvailableLiq + collateralFromMinting,
|
|
11677
11774
|
selected: []
|
|
@@ -11692,7 +11789,7 @@ import {
|
|
|
11692
11789
|
isSameAssetClass as isSameAssetClass6,
|
|
11693
11790
|
matchSingle as matchSingle7
|
|
11694
11791
|
} from "@indigo-labs/cardano-offchain-common";
|
|
11695
|
-
import { array as
|
|
11792
|
+
import { array as A17, function as F27, option as O22 } from "fp-ts";
|
|
11696
11793
|
async function findAllStableswapPools(lucid, sysParams) {
|
|
11697
11794
|
const cdpUtxos = await lucid.utxosAtWithUnit(
|
|
11698
11795
|
createScriptAddress(
|
|
@@ -11703,28 +11800,28 @@ async function findAllStableswapPools(lucid, sysParams) {
|
|
|
11703
11800
|
fromSystemParamsAsset(sysParams.stableswapParams.cdpToken)
|
|
11704
11801
|
)
|
|
11705
11802
|
);
|
|
11706
|
-
return
|
|
11803
|
+
return F27.pipe(
|
|
11707
11804
|
cdpUtxos.map(
|
|
11708
|
-
(utxo) =>
|
|
11709
|
-
|
|
11710
|
-
|
|
11711
|
-
|
|
11805
|
+
(utxo) => F27.pipe(
|
|
11806
|
+
O22.fromNullable(utxo.datum),
|
|
11807
|
+
O22.flatMap(parseStableswapPoolDatum),
|
|
11808
|
+
O22.map((datum) => ({ utxo, datum }))
|
|
11712
11809
|
)
|
|
11713
11810
|
),
|
|
11714
|
-
|
|
11811
|
+
A17.compact
|
|
11715
11812
|
);
|
|
11716
11813
|
}
|
|
11717
11814
|
async function findStableswapPool(lucid, sysParams, iassetName, collateralAsset) {
|
|
11718
11815
|
const stableswapPools = await findAllStableswapPools(lucid, sysParams);
|
|
11719
11816
|
return matchSingle7(
|
|
11720
|
-
|
|
11817
|
+
F27.pipe(
|
|
11721
11818
|
stableswapPools.map((pool) => {
|
|
11722
11819
|
if (toHex20(pool.datum.iasset) === iassetName && isSameAssetClass6(pool.datum.collateralAsset, collateralAsset)) {
|
|
11723
|
-
return
|
|
11820
|
+
return O22.some(pool);
|
|
11724
11821
|
}
|
|
11725
|
-
return
|
|
11822
|
+
return O22.none;
|
|
11726
11823
|
}),
|
|
11727
|
-
|
|
11824
|
+
A17.compact
|
|
11728
11825
|
),
|
|
11729
11826
|
(res) => new Error(
|
|
11730
11827
|
"Expected a single stableswap pool UTXO.: " + JSON.stringify(res)
|
|
@@ -11754,7 +11851,7 @@ import {
|
|
|
11754
11851
|
isSameOutRef as isSameOutRef2,
|
|
11755
11852
|
assetClassValueOf as assetClassValueOf13
|
|
11756
11853
|
} from "@indigo-labs/cardano-offchain-common";
|
|
11757
|
-
import { array as
|
|
11854
|
+
import { array as A18, function as F28 } from "fp-ts";
|
|
11758
11855
|
async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
|
|
11759
11856
|
const myAddress = await lucid.wallet().address();
|
|
11760
11857
|
const pkh = paymentCredentialOf3(myAddress);
|
|
@@ -11842,7 +11939,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11842
11939
|
]),
|
|
11843
11940
|
(_) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
11844
11941
|
);
|
|
11845
|
-
if (
|
|
11942
|
+
if (A18.isEmpty(stableswapOrderOrefs)) {
|
|
11846
11943
|
throw new Error("At least one order must be provided.");
|
|
11847
11944
|
}
|
|
11848
11945
|
const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
|
|
@@ -11889,9 +11986,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11889
11986
|
return res.result;
|
|
11890
11987
|
}
|
|
11891
11988
|
);
|
|
11892
|
-
const totalSwapInfo =
|
|
11989
|
+
const totalSwapInfo = F28.pipe(
|
|
11893
11990
|
ordersInfo,
|
|
11894
|
-
|
|
11991
|
+
A18.reduce(
|
|
11895
11992
|
{
|
|
11896
11993
|
suppliedCollateralAsset: 0n,
|
|
11897
11994
|
suppliedIasset: 0n,
|
|
@@ -11945,9 +12042,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11945
12042
|
if (amountToMint !== 0n) {
|
|
11946
12043
|
tx.mintAssets(mkAssetsOf16(iassetAc, amountToMint), Data53.void());
|
|
11947
12044
|
}
|
|
11948
|
-
|
|
12045
|
+
F28.pipe(
|
|
11949
12046
|
ordersInfo,
|
|
11950
|
-
|
|
12047
|
+
A18.reduce(tx, (acc, orderInfo) => {
|
|
11951
12048
|
return acc.collectFrom(
|
|
11952
12049
|
[orderInfo.order.utxo],
|
|
11953
12050
|
isSameOutRef2(orderInfo.order.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
|
|
@@ -12238,7 +12335,6 @@ export {
|
|
|
12238
12335
|
initGovernance,
|
|
12239
12336
|
initInterestCollector,
|
|
12240
12337
|
initPythConfig,
|
|
12241
|
-
initScriptRef,
|
|
12242
12338
|
initSpState,
|
|
12243
12339
|
initStakingManager,
|
|
12244
12340
|
initSumVal,
|
|
@@ -12375,6 +12471,7 @@ export {
|
|
|
12375
12471
|
robCollateralAmtToSpend,
|
|
12376
12472
|
robIAssetAmtToSpend,
|
|
12377
12473
|
robSellOrderFilledAssets,
|
|
12474
|
+
runAndAwaitTxBuilder,
|
|
12378
12475
|
runCreateScriptRefTx,
|
|
12379
12476
|
runOneShotMintTx,
|
|
12380
12477
|
scriptRef,
|
|
@@ -12420,13 +12517,13 @@ export {
|
|
|
12420
12517
|
spZeroNegatives,
|
|
12421
12518
|
startInterestOracle,
|
|
12422
12519
|
startPriceOracleTx,
|
|
12423
|
-
submitTx,
|
|
12424
12520
|
sum,
|
|
12425
12521
|
summariseOrder,
|
|
12426
12522
|
summarizeActualLeverageRedemptions,
|
|
12427
12523
|
toAssetClassFromLucid,
|
|
12428
12524
|
toDataDerivedPythPrice,
|
|
12429
12525
|
toSystemParamsAsset,
|
|
12526
|
+
toSystemParamsInput,
|
|
12430
12527
|
treasuryCollect,
|
|
12431
12528
|
treasuryFeeTx,
|
|
12432
12529
|
treasuryMerge,
|