@indigo-labs/indigo-sdk 0.5.15 → 0.6.0
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 +52 -31
- package/dist/index.d.ts +52 -31
- package/dist/index.js +271 -195
- package/dist/index.mjs +267 -191
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -211,7 +211,6 @@ __export(index_exports, {
|
|
|
211
211
|
initGovernance: () => initGovernance,
|
|
212
212
|
initInterestCollector: () => initInterestCollector,
|
|
213
213
|
initPythConfig: () => initPythConfig,
|
|
214
|
-
initScriptRef: () => initScriptRef,
|
|
215
214
|
initSpState: () => initSpState,
|
|
216
215
|
initStakingManager: () => initStakingManager,
|
|
217
216
|
initSumVal: () => initSumVal,
|
|
@@ -348,6 +347,7 @@ __export(index_exports, {
|
|
|
348
347
|
robCollateralAmtToSpend: () => robCollateralAmtToSpend,
|
|
349
348
|
robIAssetAmtToSpend: () => robIAssetAmtToSpend,
|
|
350
349
|
robSellOrderFilledAssets: () => robSellOrderFilledAssets,
|
|
350
|
+
runAndAwaitTxBuilder: () => runAndAwaitTxBuilder,
|
|
351
351
|
runCreateScriptRefTx: () => runCreateScriptRefTx,
|
|
352
352
|
runOneShotMintTx: () => runOneShotMintTx,
|
|
353
353
|
scriptRef: () => scriptRef,
|
|
@@ -393,13 +393,13 @@ __export(index_exports, {
|
|
|
393
393
|
spZeroNegatives: () => spZeroNegatives,
|
|
394
394
|
startInterestOracle: () => startInterestOracle,
|
|
395
395
|
startPriceOracleTx: () => startPriceOracleTx,
|
|
396
|
-
submitTx: () => submitTx,
|
|
397
396
|
sum: () => sum,
|
|
398
397
|
summariseOrder: () => summariseOrder,
|
|
399
398
|
summarizeActualLeverageRedemptions: () => summarizeActualLeverageRedemptions,
|
|
400
399
|
toAssetClassFromLucid: () => toAssetClassFromLucid,
|
|
401
400
|
toDataDerivedPythPrice: () => toDataDerivedPythPrice,
|
|
402
401
|
toSystemParamsAsset: () => toSystemParamsAsset,
|
|
402
|
+
toSystemParamsInput: () => toSystemParamsInput,
|
|
403
403
|
treasuryCollect: () => treasuryCollect,
|
|
404
404
|
treasuryFeeTx: () => treasuryFeeTx,
|
|
405
405
|
treasuryMerge: () => treasuryMerge,
|
|
@@ -682,6 +682,12 @@ function getPythFeedConfig(cfg, iasset, collateralAsset) {
|
|
|
682
682
|
throw new Error("No Pyth config known for such assets combination");
|
|
683
683
|
return res;
|
|
684
684
|
}
|
|
685
|
+
function toSystemParamsInput(outRef) {
|
|
686
|
+
return {
|
|
687
|
+
transactionId: outRef.txHash,
|
|
688
|
+
index: outRef.outputIndex
|
|
689
|
+
};
|
|
690
|
+
}
|
|
685
691
|
function toSystemParamsAsset(asset) {
|
|
686
692
|
return [
|
|
687
693
|
{ unCurrencySymbol: (0, import_lucid.toHex)(asset.currencySymbol) },
|
|
@@ -758,9 +764,26 @@ async function scriptRef(ref, lucid) {
|
|
|
758
764
|
if (utxos.length === 0) throw Error("Unable to locate script ref.");
|
|
759
765
|
return utxos[0];
|
|
760
766
|
}
|
|
761
|
-
|
|
762
|
-
|
|
767
|
+
var defaultSubmissionConfig = {
|
|
768
|
+
extraSigners: [],
|
|
769
|
+
useLocalOverride: true
|
|
770
|
+
};
|
|
771
|
+
async function runAndAwaitTxBuilder(lucid, transaction, submissionConfig) {
|
|
772
|
+
const config = {
|
|
773
|
+
...defaultSubmissionConfig,
|
|
774
|
+
...submissionConfig
|
|
775
|
+
};
|
|
776
|
+
const [newWalletUTxOs, _, bTx] = await transaction.chain();
|
|
777
|
+
const signatures = [await bTx.partialSign.withWallet()];
|
|
778
|
+
for (const signer of config.extraSigners) {
|
|
779
|
+
lucid.selectWallet.fromSeed(signer);
|
|
780
|
+
signatures.push(await lucid.fromTx(bTx.toCBOR()).partialSign.withWallet());
|
|
781
|
+
}
|
|
782
|
+
const signedTx = bTx.assemble(signatures);
|
|
783
|
+
const txHash = await signedTx.complete().then((tx) => tx.submit());
|
|
763
784
|
await lucid.awaitTx(txHash);
|
|
785
|
+
lucid.overrideUTxOs(newWalletUTxOs);
|
|
786
|
+
return txHash;
|
|
764
787
|
}
|
|
765
788
|
function balance(utxos) {
|
|
766
789
|
return utxos.reduce((acc, utxo) => (0, import_lucid2.addAssets)(acc, utxo.assets), {});
|
|
@@ -893,7 +916,15 @@ function computeEffectiveCdpState(now, cdpUtxoAssets, cdpContent, interestOracle
|
|
|
893
916
|
collateralAmt
|
|
894
917
|
};
|
|
895
918
|
}
|
|
896
|
-
|
|
919
|
+
var defaultLoanAdjustments = {
|
|
920
|
+
collateralAdjustment: 0n,
|
|
921
|
+
debtAdjustment: 0n
|
|
922
|
+
};
|
|
923
|
+
function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpContent, interestOracleDatum, loanAdjustments) {
|
|
924
|
+
const adjustments = {
|
|
925
|
+
...defaultLoanAdjustments,
|
|
926
|
+
...loanAdjustments
|
|
927
|
+
};
|
|
897
928
|
const cdpState = computeEffectiveCdpState(
|
|
898
929
|
now,
|
|
899
930
|
cdpUtxoAssets,
|
|
@@ -901,8 +932,11 @@ function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpConten
|
|
|
901
932
|
interestOracleDatum
|
|
902
933
|
);
|
|
903
934
|
const ratio = rationalDiv(
|
|
904
|
-
rationalFromInt(cdpState.collateralAmt),
|
|
905
|
-
rationalMul(
|
|
935
|
+
rationalFromInt(cdpState.collateralAmt + adjustments.collateralAdjustment),
|
|
936
|
+
rationalMul(
|
|
937
|
+
rationalFromInt(cdpState.mintedAmt + adjustments.debtAdjustment),
|
|
938
|
+
iassetPrice
|
|
939
|
+
)
|
|
906
940
|
);
|
|
907
941
|
return Number(ratio.numerator) * 100 / Number(ratio.denominator);
|
|
908
942
|
}
|
|
@@ -7595,10 +7629,9 @@ async function oneShotMintTx(lucid, params) {
|
|
|
7595
7629
|
policyId
|
|
7596
7630
|
];
|
|
7597
7631
|
}
|
|
7598
|
-
async function runOneShotMintTx(lucid, params) {
|
|
7632
|
+
async function runOneShotMintTx(lucid, params, submissionConfig) {
|
|
7599
7633
|
const [tx, policyId] = await oneShotMintTx(lucid, params);
|
|
7600
|
-
|
|
7601
|
-
await lucid.awaitTx(txHash);
|
|
7634
|
+
await runAndAwaitTxBuilder(lucid, tx, submissionConfig);
|
|
7602
7635
|
return policyId;
|
|
7603
7636
|
}
|
|
7604
7637
|
|
|
@@ -10094,10 +10127,13 @@ var alwaysFailValidator = {
|
|
|
10094
10127
|
};
|
|
10095
10128
|
|
|
10096
10129
|
// src/utils/helper-txs.ts
|
|
10097
|
-
async function runCreateScriptRefTx(lucid, scriptRefValidator,
|
|
10098
|
-
const scriptAddr = (0, import_lucid55.validatorToAddress)(
|
|
10099
|
-
|
|
10100
|
-
|
|
10130
|
+
async function runCreateScriptRefTx(lucid, scriptRefValidator, submissionConfig) {
|
|
10131
|
+
const scriptAddr = (0, import_lucid55.validatorToAddress)(
|
|
10132
|
+
lucid.config().network,
|
|
10133
|
+
alwaysFailValidator
|
|
10134
|
+
);
|
|
10135
|
+
const tx = lucid.newTx().pay.ToAddressWithData(scriptAddr, void 0, {}, scriptRefValidator);
|
|
10136
|
+
const txHash = await runAndAwaitTxBuilder(lucid, tx, submissionConfig);
|
|
10101
10137
|
return { txHash, outputIndex: 0 };
|
|
10102
10138
|
}
|
|
10103
10139
|
|
|
@@ -10157,24 +10193,6 @@ var mkIAssetValidatorFromSP = (params) => {
|
|
|
10157
10193
|
|
|
10158
10194
|
// src/contracts/initialize/helpers.ts
|
|
10159
10195
|
var import_ts_pattern21 = require("ts-pattern");
|
|
10160
|
-
|
|
10161
|
-
// tests/test-helpers.ts
|
|
10162
|
-
var import_fp_ts26 = require("fp-ts");
|
|
10163
|
-
async function runAndAwaitTxBuilder(lucid, transaction, extraSigners = []) {
|
|
10164
|
-
const bTx = await transaction.complete();
|
|
10165
|
-
const signatures = [await bTx.partialSign.withWallet()];
|
|
10166
|
-
for (const signer of extraSigners) {
|
|
10167
|
-
lucid.selectWallet.fromSeed(signer);
|
|
10168
|
-
signatures.push(await lucid.fromTx(bTx.toCBOR()).partialSign.withWallet());
|
|
10169
|
-
}
|
|
10170
|
-
const signedTx = bTx.assemble(signatures);
|
|
10171
|
-
const txHash = await signedTx.complete().then((tx) => tx.submit());
|
|
10172
|
-
await lucid.awaitTx(txHash);
|
|
10173
|
-
return txHash;
|
|
10174
|
-
}
|
|
10175
|
-
|
|
10176
|
-
// src/contracts/initialize/helpers.ts
|
|
10177
|
-
var alwaysFailValidatorHash = "ea84d625650d066e1645e3e81d9c70a73f9ed837bd96dc49850ae744";
|
|
10178
10196
|
var DEFAULT_INIT_OPTIONS = {
|
|
10179
10197
|
numCdpCreators: 2n,
|
|
10180
10198
|
numCollectors: 2n,
|
|
@@ -10209,18 +10227,27 @@ var INIT_TOKEN_NAMES = {
|
|
|
10209
10227
|
snapshotEpochToScaleToSum: "SNAPSHOT_EPOCH_TO_SCALE_TO_SUM",
|
|
10210
10228
|
account: "SP_ACCOUNT"
|
|
10211
10229
|
};
|
|
10212
|
-
async function mintOneTimeToken(lucid, tokenName, amount) {
|
|
10230
|
+
async function mintOneTimeToken(lucid, tokenName, amount, submissionConfig) {
|
|
10213
10231
|
const utxos = await lucid.wallet().getUtxos();
|
|
10214
|
-
return await runOneShotMintTx(
|
|
10215
|
-
|
|
10216
|
-
|
|
10217
|
-
|
|
10232
|
+
return await runOneShotMintTx(
|
|
10233
|
+
lucid,
|
|
10234
|
+
{
|
|
10235
|
+
referenceOutRef: {
|
|
10236
|
+
txHash: utxos[0].txHash,
|
|
10237
|
+
outputIdx: BigInt(utxos[0].outputIndex)
|
|
10238
|
+
},
|
|
10239
|
+
mintAmounts: [{ tokenName, amount }]
|
|
10218
10240
|
},
|
|
10219
|
-
|
|
10220
|
-
|
|
10241
|
+
submissionConfig
|
|
10242
|
+
);
|
|
10221
10243
|
}
|
|
10222
|
-
async function mintOneTimeAsset(lucid, tokenName, amount) {
|
|
10223
|
-
const policyId = await mintOneTimeToken(
|
|
10244
|
+
async function mintOneTimeAsset(lucid, tokenName, amount, submissionConfig) {
|
|
10245
|
+
const policyId = await mintOneTimeToken(
|
|
10246
|
+
lucid,
|
|
10247
|
+
(0, import_lucid59.fromText)(tokenName),
|
|
10248
|
+
amount,
|
|
10249
|
+
submissionConfig
|
|
10250
|
+
);
|
|
10224
10251
|
return {
|
|
10225
10252
|
currencySymbol: (0, import_lucid59.fromHex)(policyId),
|
|
10226
10253
|
tokenName: (0, import_lucid59.fromHex)((0, import_lucid59.fromText)(tokenName))
|
|
@@ -10233,20 +10260,6 @@ function deriveAuthToken(parent, tokenName) {
|
|
|
10233
10260
|
tokenName: (0, import_lucid59.fromHex)((0, import_lucid59.fromText)(tokenName))
|
|
10234
10261
|
};
|
|
10235
10262
|
}
|
|
10236
|
-
async function initScriptRef(lucid, validator) {
|
|
10237
|
-
const tx = lucid.newTx().pay.ToContract(
|
|
10238
|
-
(0, import_lucid59.credentialToAddress)(lucid.config().network, {
|
|
10239
|
-
hash: alwaysFailValidatorHash,
|
|
10240
|
-
type: "Script"
|
|
10241
|
-
}),
|
|
10242
|
-
void 0,
|
|
10243
|
-
void 0,
|
|
10244
|
-
validator
|
|
10245
|
-
);
|
|
10246
|
-
const txHash = await tx.complete().then((t) => t.sign.withWallet().complete()).then((t) => t.submit());
|
|
10247
|
-
await lucid.awaitTx(txHash);
|
|
10248
|
-
return { transactionId: txHash, index: 0 };
|
|
10249
|
-
}
|
|
10250
10263
|
async function initCollector(lucid, collectorParams, numCollectors) {
|
|
10251
10264
|
const tx = lucid.newTx();
|
|
10252
10265
|
for (let i = 0; i < Number(numCollectors); i++) {
|
|
@@ -10261,7 +10274,7 @@ async function initCollector(lucid, collectorParams, numCollectors) {
|
|
|
10261
10274
|
}
|
|
10262
10275
|
);
|
|
10263
10276
|
}
|
|
10264
|
-
await
|
|
10277
|
+
await runAndAwaitTxBuilder(lucid, tx);
|
|
10265
10278
|
}
|
|
10266
10279
|
async function initInterestCollector(lucid, interestCollectionValHash, multisigUtxoNft, numInterestCollectors, interestCollectorUtxoLovelaces) {
|
|
10267
10280
|
const [pkh, _] = await addrDetails(lucid);
|
|
@@ -10272,7 +10285,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
|
|
|
10272
10285
|
}
|
|
10273
10286
|
}
|
|
10274
10287
|
};
|
|
10275
|
-
await
|
|
10288
|
+
await runAndAwaitTxBuilder(
|
|
10276
10289
|
lucid,
|
|
10277
10290
|
lucid.newTx().pay.ToContract(
|
|
10278
10291
|
createScriptAddress(lucid.config().network, interestCollectionValHash),
|
|
@@ -10291,7 +10304,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
|
|
|
10291
10304
|
(0, import_cardano_offchain_common30.mkLovelacesOf)(interestCollectorUtxoLovelaces)
|
|
10292
10305
|
);
|
|
10293
10306
|
}
|
|
10294
|
-
await
|
|
10307
|
+
await runAndAwaitTxBuilder(lucid, interestCollectionUtxoDeploymentTx);
|
|
10295
10308
|
}
|
|
10296
10309
|
async function initCDPCreator(lucid, cdpCreatorParams, numCdpCreators) {
|
|
10297
10310
|
const tx = lucid.newTx();
|
|
@@ -10309,7 +10322,7 @@ async function initCDPCreator(lucid, cdpCreatorParams, numCdpCreators) {
|
|
|
10309
10322
|
}
|
|
10310
10323
|
);
|
|
10311
10324
|
}
|
|
10312
|
-
await
|
|
10325
|
+
await runAndAwaitTxBuilder(lucid, tx);
|
|
10313
10326
|
}
|
|
10314
10327
|
async function initTreasury(lucid, treasuryParams, daoAsset, indyAsset, treasuryIndyAmount, numTreasuryCollectors) {
|
|
10315
10328
|
const treasuryAddr = createScriptAddress(
|
|
@@ -10331,7 +10344,7 @@ async function initTreasury(lucid, treasuryParams, daoAsset, indyAsset, treasury
|
|
|
10331
10344
|
value: import_lucid59.Data.void()
|
|
10332
10345
|
});
|
|
10333
10346
|
}
|
|
10334
|
-
await
|
|
10347
|
+
await runAndAwaitTxBuilder(lucid, tx);
|
|
10335
10348
|
}
|
|
10336
10349
|
async function initStakingManager(lucid, stakingParams) {
|
|
10337
10350
|
const tx = lucid.newTx().pay.ToContract(
|
|
@@ -10350,7 +10363,7 @@ async function initStakingManager(lucid, stakingParams) {
|
|
|
10350
10363
|
[stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0, import_lucid59.fromText)(stakingParams.stakingManagerNFT[1].unTokenName)]: 1n
|
|
10351
10364
|
}
|
|
10352
10365
|
);
|
|
10353
|
-
await
|
|
10366
|
+
await runAndAwaitTxBuilder(lucid, tx);
|
|
10354
10367
|
}
|
|
10355
10368
|
async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, pythConfig) {
|
|
10356
10369
|
return (0, import_ts_pattern21.match)(collateralAsset.priceOracle).returnType().with({ tag: "_indigo_oracle_nft" }, async (val) => {
|
|
@@ -10402,7 +10415,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10402
10415
|
lucid,
|
|
10403
10416
|
collateralAsset.interestOracle.tokenName
|
|
10404
10417
|
);
|
|
10405
|
-
await
|
|
10418
|
+
await runAndAwaitTxBuilder(lucid, startInterestOracleTx);
|
|
10406
10419
|
const priceInfo = await handleOracleForCollateralAsset(
|
|
10407
10420
|
lucid,
|
|
10408
10421
|
asset,
|
|
@@ -10435,7 +10448,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10435
10448
|
},
|
|
10436
10449
|
(0, import_cardano_offchain_common30.mkAssetsOf)(collateralAssetAuthToken, 1n)
|
|
10437
10450
|
);
|
|
10438
|
-
await
|
|
10451
|
+
await runAndAwaitTxBuilder(lucid, collateralAssetTx);
|
|
10439
10452
|
collateralAssetInfos.push({
|
|
10440
10453
|
collateralAsset: collateralAsset.collateralAsset,
|
|
10441
10454
|
interestOracleNft,
|
|
@@ -10457,7 +10470,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10457
10470
|
iasset: iassetName,
|
|
10458
10471
|
stableswapValHash: (0, import_lucid59.fromHex)(stableswapValidatorHash)
|
|
10459
10472
|
};
|
|
10460
|
-
await
|
|
10473
|
+
await runAndAwaitTxBuilder(
|
|
10461
10474
|
lucid,
|
|
10462
10475
|
lucid.newTx().pay.ToContract(
|
|
10463
10476
|
createScriptAddress(
|
|
@@ -10494,7 +10507,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10494
10507
|
},
|
|
10495
10508
|
(0, import_cardano_offchain_common30.mkAssetsOf)(iassetToken, 1n)
|
|
10496
10509
|
);
|
|
10497
|
-
await
|
|
10510
|
+
await runAndAwaitTxBuilder(lucid, assetTx);
|
|
10498
10511
|
const stabilityPoolDatum = {
|
|
10499
10512
|
iasset: (0, import_lucid59.fromHex)((0, import_lucid59.fromText)(asset.name)),
|
|
10500
10513
|
state: initSpState,
|
|
@@ -10513,7 +10526,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10513
10526
|
},
|
|
10514
10527
|
(0, import_cardano_offchain_common30.mkAssetsOf)(stabilityPoolToken, 1n)
|
|
10515
10528
|
);
|
|
10516
|
-
await
|
|
10529
|
+
await runAndAwaitTxBuilder(lucid, spTx);
|
|
10517
10530
|
return {
|
|
10518
10531
|
iassetTokenNameAscii: asset.name,
|
|
10519
10532
|
collateralAssets: collateralAssetInfos
|
|
@@ -10535,7 +10548,7 @@ async function initGovernance(lucid, governanceParams, govToken, initialAssets,
|
|
|
10535
10548
|
{ kind: "inline", value: serialiseGovDatum(datum) },
|
|
10536
10549
|
(0, import_cardano_offchain_common30.mkAssetsOf)(govToken, 1n)
|
|
10537
10550
|
);
|
|
10538
|
-
await
|
|
10551
|
+
await runAndAwaitTxBuilder(lucid, tx);
|
|
10539
10552
|
}
|
|
10540
10553
|
async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
|
|
10541
10554
|
const script = mkAuthTokenPolicy(asset, (0, import_lucid59.fromText)(tokenName));
|
|
@@ -10552,7 +10565,7 @@ async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
|
|
|
10552
10565
|
},
|
|
10553
10566
|
import_lucid59.Data.void()
|
|
10554
10567
|
);
|
|
10555
|
-
await
|
|
10568
|
+
await runAndAwaitTxBuilder(lucid, tx);
|
|
10556
10569
|
}
|
|
10557
10570
|
|
|
10558
10571
|
// src/contracts/initialize/actions.ts
|
|
@@ -10718,19 +10731,30 @@ async function initPyth(lucid) {
|
|
|
10718
10731
|
alwaysSucceedValidator
|
|
10719
10732
|
)
|
|
10720
10733
|
);
|
|
10721
|
-
|
|
10722
|
-
|
|
10723
|
-
|
|
10724
|
-
|
|
10725
|
-
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
|
|
10729
|
-
|
|
10734
|
+
try {
|
|
10735
|
+
await runAndAwaitTxBuilder(
|
|
10736
|
+
lucid,
|
|
10737
|
+
lucid.newTx().register.Stake(
|
|
10738
|
+
(0, import_lucid63.credentialToRewardAddress)(lucid.config().network, {
|
|
10739
|
+
hash: (0, import_lucid63.validatorToScriptHash)(alwaysSucceedValidator),
|
|
10740
|
+
type: "Script"
|
|
10741
|
+
})
|
|
10742
|
+
)
|
|
10743
|
+
);
|
|
10744
|
+
} catch (error) {
|
|
10745
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
10746
|
+
if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes("Trying to re-register some already known credentials.")) {
|
|
10747
|
+
throw error;
|
|
10748
|
+
}
|
|
10749
|
+
}
|
|
10730
10750
|
return pythStateAsset;
|
|
10731
10751
|
}
|
|
10732
10752
|
|
|
10733
10753
|
// src/contracts/initialize/actions.ts
|
|
10754
|
+
function isAlreadyRegisteredError(error) {
|
|
10755
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
10756
|
+
return message.includes("StakeKeyRegisteredDELEG") || message.includes("Trying to re-register some already known credentials.");
|
|
10757
|
+
}
|
|
10734
10758
|
var DEFAULT_STAKING_CRED = {
|
|
10735
10759
|
tag: "StakingHash",
|
|
10736
10760
|
contents: {
|
|
@@ -10747,7 +10771,7 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
|
|
|
10747
10771
|
fromSysParamsPythFeedParams(val.pythFeedParams)
|
|
10748
10772
|
);
|
|
10749
10773
|
const pythFeedValHash = (0, import_lucid64.validatorToScriptHash)(pythFeedValidator);
|
|
10750
|
-
const pythFeedValScriptRef = await
|
|
10774
|
+
const pythFeedValScriptRef = await runCreateScriptRefTx(
|
|
10751
10775
|
lucid,
|
|
10752
10776
|
pythFeedValidator
|
|
10753
10777
|
);
|
|
@@ -10762,19 +10786,16 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
|
|
|
10762
10786
|
)
|
|
10763
10787
|
);
|
|
10764
10788
|
} catch (error) {
|
|
10765
|
-
|
|
10766
|
-
if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes(
|
|
10767
|
-
"Trying to re-register some already known credentials."
|
|
10768
|
-
)) {
|
|
10769
|
-
throw error;
|
|
10770
|
-
}
|
|
10789
|
+
if (!isAlreadyRegisteredError(error)) throw error;
|
|
10771
10790
|
}
|
|
10772
10791
|
const key = `${asset.name}/${(0, import_lucid64.toHex)(collateral.collateralAsset.currencySymbol)}.${(0, import_lucid64.toHex)(collateral.collateralAsset.tokenName)}`;
|
|
10773
10792
|
return {
|
|
10774
10793
|
[key]: {
|
|
10775
10794
|
params: val.pythFeedParams,
|
|
10776
10795
|
pythFeedValHash,
|
|
10777
|
-
pythFeedValScriptRef: {
|
|
10796
|
+
pythFeedValScriptRef: {
|
|
10797
|
+
input: toSystemParamsInput(pythFeedValScriptRef)
|
|
10798
|
+
}
|
|
10778
10799
|
}
|
|
10779
10800
|
};
|
|
10780
10801
|
}).otherwise(() => Promise.resolve({}));
|
|
@@ -10808,6 +10829,19 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10808
10829
|
const indyAsset = await mintOneTimeAsset(lucid, tn.indy, totalIndySupply);
|
|
10809
10830
|
const daoAsset = await mintOneTimeAsset(lucid, tn.dao, 1n);
|
|
10810
10831
|
const govNftAsset = await mintOneTimeAsset(lucid, tn.govNft, 1n);
|
|
10832
|
+
const cdpCreatorAsset = await mintOneTimeAsset(
|
|
10833
|
+
lucid,
|
|
10834
|
+
tn.cdpCreator,
|
|
10835
|
+
numCdpCreators
|
|
10836
|
+
);
|
|
10837
|
+
const cdpToken = deriveAuthToken(cdpCreatorAsset, tn.cdp);
|
|
10838
|
+
const stakingManagerAsset = await mintOneTimeAsset(
|
|
10839
|
+
lucid,
|
|
10840
|
+
tn.stakingManager,
|
|
10841
|
+
1n
|
|
10842
|
+
);
|
|
10843
|
+
const multisigUtxoNft = await mintOneTimeAsset(lucid, tn.multisigUtxo, 1n);
|
|
10844
|
+
const stakingToken = deriveAuthToken(stakingManagerAsset, tn.staking);
|
|
10811
10845
|
const pollToken = deriveAuthToken(govNftAsset, tn.pollManager);
|
|
10812
10846
|
const upgradeToken = deriveAuthToken(pollToken, tn.upgrade);
|
|
10813
10847
|
const iassetToken = deriveAuthToken(upgradeToken, tn.iasset);
|
|
@@ -10833,18 +10867,6 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10833
10867
|
const versionRegistryValHash = (0, import_lucid64.validatorToScriptHash)(
|
|
10834
10868
|
versionRegistryValidator
|
|
10835
10869
|
);
|
|
10836
|
-
const cdpCreatorAsset = await mintOneTimeAsset(
|
|
10837
|
-
lucid,
|
|
10838
|
-
tn.cdpCreator,
|
|
10839
|
-
numCdpCreators
|
|
10840
|
-
);
|
|
10841
|
-
const cdpToken = deriveAuthToken(cdpCreatorAsset, tn.cdp);
|
|
10842
|
-
const stakingManagerAsset = await mintOneTimeAsset(
|
|
10843
|
-
lucid,
|
|
10844
|
-
tn.stakingManager,
|
|
10845
|
-
1n
|
|
10846
|
-
);
|
|
10847
|
-
const stakingToken = deriveAuthToken(stakingManagerAsset, tn.staking);
|
|
10848
10870
|
const collectorParams = {
|
|
10849
10871
|
stakingManagerNFT: toSystemParamsAsset(stakingManagerAsset),
|
|
10850
10872
|
stakingToken: toSystemParamsAsset(stakingToken),
|
|
@@ -10910,7 +10932,6 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10910
10932
|
treasuryIndyAmount,
|
|
10911
10933
|
numTreasuryUtxos
|
|
10912
10934
|
);
|
|
10913
|
-
const multisigUtxoNft = await mintOneTimeAsset(lucid, tn.multisigUtxo, 1n);
|
|
10914
10935
|
const interestCollectionParams = {
|
|
10915
10936
|
versionRecordNft: toSystemParamsAsset(versionRecordToken),
|
|
10916
10937
|
multisigUtxoNft: toSystemParamsAsset(multisigUtxoNft),
|
|
@@ -10964,10 +10985,7 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10964
10985
|
lucid.newTx().register.Stake(cdpRedeemRewardAddr)
|
|
10965
10986
|
);
|
|
10966
10987
|
} catch (error) {
|
|
10967
|
-
|
|
10968
|
-
if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes("Trying to re-register some already known credentials.")) {
|
|
10969
|
-
throw error;
|
|
10970
|
-
}
|
|
10988
|
+
if (!isAlreadyRegisteredError(error)) throw error;
|
|
10971
10989
|
}
|
|
10972
10990
|
const cdpParams = {
|
|
10973
10991
|
cdpAuthToken: toSystemParamsAsset(cdpToken),
|
|
@@ -11217,97 +11235,155 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
11217
11235
|
},
|
|
11218
11236
|
scriptReferences: {
|
|
11219
11237
|
interestCollectionValidatorRef: {
|
|
11220
|
-
input:
|
|
11238
|
+
input: toSystemParamsInput(
|
|
11239
|
+
await runCreateScriptRefTx(lucid, interestCollectionValidator)
|
|
11240
|
+
)
|
|
11221
11241
|
},
|
|
11222
11242
|
robValidatorRef: {
|
|
11223
|
-
input:
|
|
11243
|
+
input: toSystemParamsInput(
|
|
11244
|
+
await runCreateScriptRefTx(lucid, robValidator)
|
|
11245
|
+
)
|
|
11224
11246
|
},
|
|
11225
11247
|
cdpCreatorValidatorRef: {
|
|
11226
|
-
input:
|
|
11248
|
+
input: toSystemParamsInput(
|
|
11249
|
+
await runCreateScriptRefTx(lucid, cdpCreatorValidator)
|
|
11250
|
+
)
|
|
11227
11251
|
},
|
|
11228
11252
|
cdpValidatorRef: {
|
|
11229
|
-
input:
|
|
11253
|
+
input: toSystemParamsInput(
|
|
11254
|
+
await runCreateScriptRefTx(lucid, cdpValidator)
|
|
11255
|
+
)
|
|
11230
11256
|
},
|
|
11231
11257
|
cdpRedeemValidatorRef: {
|
|
11232
|
-
input:
|
|
11258
|
+
input: toSystemParamsInput(
|
|
11259
|
+
await runCreateScriptRefTx(lucid, cdpRedeemValidator)
|
|
11260
|
+
)
|
|
11233
11261
|
},
|
|
11234
11262
|
collectorValidatorRef: {
|
|
11235
|
-
input:
|
|
11263
|
+
input: toSystemParamsInput(
|
|
11264
|
+
await runCreateScriptRefTx(lucid, collectorValidator)
|
|
11265
|
+
)
|
|
11236
11266
|
},
|
|
11237
11267
|
executeValidatorRef: {
|
|
11238
|
-
input:
|
|
11268
|
+
input: toSystemParamsInput(
|
|
11269
|
+
await runCreateScriptRefTx(lucid, executeValidator)
|
|
11270
|
+
)
|
|
11239
11271
|
},
|
|
11240
11272
|
pollShardValidatorRef: {
|
|
11241
|
-
input:
|
|
11273
|
+
input: toSystemParamsInput(
|
|
11274
|
+
await runCreateScriptRefTx(lucid, pollShardValidator)
|
|
11275
|
+
)
|
|
11242
11276
|
},
|
|
11243
11277
|
pollManagerValidatorRef: {
|
|
11244
|
-
input:
|
|
11278
|
+
input: toSystemParamsInput(
|
|
11279
|
+
await runCreateScriptRefTx(lucid, pollManagerValidator)
|
|
11280
|
+
)
|
|
11245
11281
|
},
|
|
11246
11282
|
iAssetTokenPolicyRef: {
|
|
11247
|
-
input:
|
|
11283
|
+
input: toSystemParamsInput(
|
|
11284
|
+
await runCreateScriptRefTx(lucid, assetSymbolPolicy)
|
|
11285
|
+
)
|
|
11248
11286
|
},
|
|
11249
11287
|
stakingValidatorRef: {
|
|
11250
|
-
input:
|
|
11251
|
-
|
|
11252
|
-
|
|
11288
|
+
input: toSystemParamsInput(
|
|
11289
|
+
await runCreateScriptRefTx(
|
|
11290
|
+
lucid,
|
|
11291
|
+
mkStakingValidatorFromSP(stakingParams)
|
|
11292
|
+
)
|
|
11253
11293
|
)
|
|
11254
11294
|
},
|
|
11255
11295
|
stabilityPoolValidatorRef: {
|
|
11256
|
-
input:
|
|
11296
|
+
input: toSystemParamsInput(
|
|
11297
|
+
await runCreateScriptRefTx(lucid, stabilityPoolValidator)
|
|
11298
|
+
)
|
|
11257
11299
|
},
|
|
11258
11300
|
stableswapValidatorRef: {
|
|
11259
|
-
input:
|
|
11301
|
+
input: toSystemParamsInput(
|
|
11302
|
+
await runCreateScriptRefTx(lucid, stableswapValidator)
|
|
11303
|
+
)
|
|
11260
11304
|
},
|
|
11261
11305
|
treasuryValidatorRef: {
|
|
11262
|
-
input:
|
|
11306
|
+
input: toSystemParamsInput(
|
|
11307
|
+
await runCreateScriptRefTx(lucid, treasuryValidator)
|
|
11308
|
+
)
|
|
11263
11309
|
},
|
|
11264
11310
|
governanceValidatorRef: {
|
|
11265
|
-
input:
|
|
11311
|
+
input: toSystemParamsInput(
|
|
11312
|
+
await runCreateScriptRefTx(lucid, govValidator)
|
|
11313
|
+
)
|
|
11266
11314
|
},
|
|
11267
11315
|
versionRegistryValidatorRef: {
|
|
11268
|
-
input:
|
|
11316
|
+
input: toSystemParamsInput(
|
|
11317
|
+
await runCreateScriptRefTx(lucid, versionRegistryValidator)
|
|
11318
|
+
)
|
|
11269
11319
|
},
|
|
11270
11320
|
iassetValidatorRef: {
|
|
11271
|
-
input:
|
|
11321
|
+
input: toSystemParamsInput(
|
|
11322
|
+
await runCreateScriptRefTx(lucid, iassetValidator)
|
|
11323
|
+
)
|
|
11272
11324
|
},
|
|
11273
11325
|
authTokenPolicies: {
|
|
11274
11326
|
cdpAuthTokenRef: {
|
|
11275
|
-
input:
|
|
11327
|
+
input: toSystemParamsInput(
|
|
11328
|
+
await runCreateScriptRefTx(lucid, cdpTokenPolicy)
|
|
11329
|
+
)
|
|
11276
11330
|
},
|
|
11277
11331
|
iAssetAuthTokenRef: {
|
|
11278
|
-
input:
|
|
11332
|
+
input: toSystemParamsInput(
|
|
11333
|
+
await runCreateScriptRefTx(lucid, iassetTokenPolicy)
|
|
11334
|
+
)
|
|
11279
11335
|
},
|
|
11280
11336
|
accountTokenRef: {
|
|
11281
|
-
input:
|
|
11337
|
+
input: toSystemParamsInput(
|
|
11338
|
+
await runCreateScriptRefTx(lucid, accountTokenPolicy)
|
|
11339
|
+
)
|
|
11282
11340
|
},
|
|
11283
11341
|
stabilityPoolAuthTokenRef: {
|
|
11284
|
-
input:
|
|
11342
|
+
input: toSystemParamsInput(
|
|
11343
|
+
await runCreateScriptRefTx(lucid, stabilityPoolTokenPolicy)
|
|
11344
|
+
)
|
|
11285
11345
|
},
|
|
11286
11346
|
pollManagerTokenRef: {
|
|
11287
|
-
input:
|
|
11347
|
+
input: toSystemParamsInput(
|
|
11348
|
+
await runCreateScriptRefTx(lucid, pollTokenPolicy)
|
|
11349
|
+
)
|
|
11288
11350
|
},
|
|
11289
11351
|
stakingTokenRef: {
|
|
11290
|
-
input:
|
|
11352
|
+
input: toSystemParamsInput(
|
|
11353
|
+
await runCreateScriptRefTx(lucid, stakingTokenPolicy)
|
|
11354
|
+
)
|
|
11291
11355
|
},
|
|
11292
11356
|
versionRecordTokenPolicyRef: {
|
|
11293
|
-
input:
|
|
11357
|
+
input: toSystemParamsInput(
|
|
11358
|
+
await runCreateScriptRefTx(lucid, versionRecordTokenPolicy)
|
|
11359
|
+
)
|
|
11294
11360
|
},
|
|
11295
11361
|
iAssetTokenRef: {
|
|
11296
|
-
input:
|
|
11362
|
+
input: toSystemParamsInput(
|
|
11363
|
+
await runCreateScriptRefTx(lucid, assetSymbolPolicy)
|
|
11364
|
+
)
|
|
11297
11365
|
},
|
|
11298
11366
|
collateralAssetTokenRef: {
|
|
11299
|
-
input:
|
|
11367
|
+
input: toSystemParamsInput(
|
|
11368
|
+
await runCreateScriptRefTx(lucid, collateralAssetAuthTokenPolicy)
|
|
11369
|
+
)
|
|
11300
11370
|
},
|
|
11301
11371
|
upgradeTokenRef: {
|
|
11302
|
-
input:
|
|
11372
|
+
input: toSystemParamsInput(
|
|
11373
|
+
await runCreateScriptRefTx(lucid, upgradeTokenPolicy)
|
|
11374
|
+
)
|
|
11303
11375
|
},
|
|
11304
11376
|
stabilityPoolTokenRef: {
|
|
11305
|
-
input:
|
|
11377
|
+
input: toSystemParamsInput(
|
|
11378
|
+
await runCreateScriptRefTx(lucid, stabilityPoolTokenPolicy)
|
|
11379
|
+
)
|
|
11306
11380
|
},
|
|
11307
11381
|
snapshotEpochToScaleToSumTokenRef: {
|
|
11308
|
-
input:
|
|
11309
|
-
|
|
11310
|
-
|
|
11382
|
+
input: toSystemParamsInput(
|
|
11383
|
+
await runCreateScriptRefTx(
|
|
11384
|
+
lucid,
|
|
11385
|
+
snapshotEpochToScaleToSumTokenPolicy
|
|
11386
|
+
)
|
|
11311
11387
|
)
|
|
11312
11388
|
}
|
|
11313
11389
|
}
|
|
@@ -11337,7 +11413,7 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
11337
11413
|
// src/contracts/iasset/queries.ts
|
|
11338
11414
|
var import_lucid65 = require("@lucid-evolution/lucid");
|
|
11339
11415
|
var import_cardano_offchain_common33 = require("@indigo-labs/cardano-offchain-common");
|
|
11340
|
-
var
|
|
11416
|
+
var import_fp_ts26 = require("fp-ts");
|
|
11341
11417
|
async function findIAsset(lucid, sysParams, iassetName) {
|
|
11342
11418
|
const iassetUtxos = await lucid.utxosAtWithUnit(
|
|
11343
11419
|
createScriptAddress(
|
|
@@ -11349,21 +11425,21 @@ async function findIAsset(lucid, sysParams, iassetName) {
|
|
|
11349
11425
|
)
|
|
11350
11426
|
);
|
|
11351
11427
|
return (0, import_cardano_offchain_common33.matchSingle)(
|
|
11352
|
-
|
|
11428
|
+
import_fp_ts26.function.pipe(
|
|
11353
11429
|
iassetUtxos.map(
|
|
11354
|
-
(utxo) =>
|
|
11355
|
-
|
|
11356
|
-
|
|
11357
|
-
|
|
11430
|
+
(utxo) => import_fp_ts26.function.pipe(
|
|
11431
|
+
import_fp_ts26.option.fromNullable(utxo.datum),
|
|
11432
|
+
import_fp_ts26.option.flatMap(parseIAssetDatum),
|
|
11433
|
+
import_fp_ts26.option.flatMap((datum) => {
|
|
11358
11434
|
if ((0, import_lucid65.toHex)(datum.assetName) === (0, import_lucid65.toHex)(iassetName)) {
|
|
11359
|
-
return
|
|
11435
|
+
return import_fp_ts26.option.some({ utxo, datum });
|
|
11360
11436
|
} else {
|
|
11361
|
-
return
|
|
11437
|
+
return import_fp_ts26.option.none;
|
|
11362
11438
|
}
|
|
11363
11439
|
})
|
|
11364
11440
|
)
|
|
11365
11441
|
),
|
|
11366
|
-
|
|
11442
|
+
import_fp_ts26.array.compact
|
|
11367
11443
|
),
|
|
11368
11444
|
(res) => new Error("Expected a single IAsset UTXO.: " + JSON.stringify(res))
|
|
11369
11445
|
);
|
|
@@ -11379,21 +11455,21 @@ async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset
|
|
|
11379
11455
|
)
|
|
11380
11456
|
);
|
|
11381
11457
|
return (0, import_cardano_offchain_common33.matchSingle)(
|
|
11382
|
-
|
|
11458
|
+
import_fp_ts26.function.pipe(
|
|
11383
11459
|
collateralAssetUtxos.map(
|
|
11384
|
-
(utxo) =>
|
|
11385
|
-
|
|
11386
|
-
|
|
11387
|
-
|
|
11460
|
+
(utxo) => import_fp_ts26.function.pipe(
|
|
11461
|
+
import_fp_ts26.option.fromNullable(utxo.datum),
|
|
11462
|
+
import_fp_ts26.option.flatMap(parseCollateralAssetDatum),
|
|
11463
|
+
import_fp_ts26.option.flatMap((datum) => {
|
|
11388
11464
|
if ((0, import_cardano_offchain_common33.isSameAssetClass)(datum.collateralAsset, collateralAsset) && (0, import_lucid65.toHex)(iassetName) === (0, import_lucid65.toHex)(datum.iasset)) {
|
|
11389
|
-
return
|
|
11465
|
+
return import_fp_ts26.option.some({ utxo, datum });
|
|
11390
11466
|
} else {
|
|
11391
|
-
return
|
|
11467
|
+
return import_fp_ts26.option.none;
|
|
11392
11468
|
}
|
|
11393
11469
|
})
|
|
11394
11470
|
)
|
|
11395
11471
|
),
|
|
11396
|
-
|
|
11472
|
+
import_fp_ts26.array.compact
|
|
11397
11473
|
),
|
|
11398
11474
|
(res) => new Error(
|
|
11399
11475
|
"Expected a single Collateral Asset UTXO.: " + JSON.stringify(res)
|
|
@@ -11403,12 +11479,12 @@ async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset
|
|
|
11403
11479
|
|
|
11404
11480
|
// src/contracts/stableswap/helpers.ts
|
|
11405
11481
|
var import_lucid66 = require("@lucid-evolution/lucid");
|
|
11406
|
-
var
|
|
11482
|
+
var import_fp_ts28 = require("fp-ts");
|
|
11407
11483
|
|
|
11408
11484
|
// src/contracts/stableswap/types-new.ts
|
|
11409
11485
|
var import_cardano_offchain_common34 = require("@indigo-labs/cardano-offchain-common");
|
|
11410
11486
|
var import_evolution20 = require("@evolution-sdk/evolution");
|
|
11411
|
-
var
|
|
11487
|
+
var import_fp_ts27 = require("fp-ts");
|
|
11412
11488
|
var import_effect3 = require("effect");
|
|
11413
11489
|
var OpaqueData4 = import_effect3.Schema.typeSchema(import_evolution20.Data.DataSchema);
|
|
11414
11490
|
var StableswapOrderDatumSchema = import_evolution20.TSchema.Struct({
|
|
@@ -11450,22 +11526,22 @@ function serialiseStableswapOrderDatum(d) {
|
|
|
11450
11526
|
}
|
|
11451
11527
|
function parseStableswapOrderDatum(datum) {
|
|
11452
11528
|
try {
|
|
11453
|
-
return
|
|
11529
|
+
return import_fp_ts27.option.some(
|
|
11454
11530
|
import_evolution20.Data.withSchema(
|
|
11455
11531
|
StableswapOrderDatumSchema,
|
|
11456
11532
|
DEFAULT_SCHEMA_OPTIONS
|
|
11457
11533
|
).fromCBORHex(datum)
|
|
11458
11534
|
);
|
|
11459
11535
|
} catch (_) {
|
|
11460
|
-
return
|
|
11536
|
+
return import_fp_ts27.option.none;
|
|
11461
11537
|
}
|
|
11462
11538
|
}
|
|
11463
11539
|
function parseStableswapOrderDatumOrThrow(datum) {
|
|
11464
|
-
return
|
|
11540
|
+
return import_fp_ts27.function.pipe(
|
|
11465
11541
|
parseStableswapOrderDatum(datum),
|
|
11466
|
-
|
|
11542
|
+
import_fp_ts27.option.match(() => {
|
|
11467
11543
|
throw new Error("Expected a Stableswap Order datum.");
|
|
11468
|
-
},
|
|
11544
|
+
}, import_fp_ts27.function.identity)
|
|
11469
11545
|
);
|
|
11470
11546
|
}
|
|
11471
11547
|
function serialiseStableswapOutputDatum(d) {
|
|
@@ -11482,22 +11558,22 @@ function serialiseStableswapOrderRedeemer(r) {
|
|
|
11482
11558
|
}
|
|
11483
11559
|
function parseStableswapOrderRedeemer(redeemerCborHex) {
|
|
11484
11560
|
try {
|
|
11485
|
-
return
|
|
11561
|
+
return import_fp_ts27.option.some(
|
|
11486
11562
|
import_evolution20.Data.withSchema(
|
|
11487
11563
|
StableswapOrderRedeemerSchema,
|
|
11488
11564
|
DEFAULT_SCHEMA_OPTIONS
|
|
11489
11565
|
).fromCBORHex(redeemerCborHex)
|
|
11490
11566
|
);
|
|
11491
11567
|
} catch (_) {
|
|
11492
|
-
return
|
|
11568
|
+
return import_fp_ts27.option.none;
|
|
11493
11569
|
}
|
|
11494
11570
|
}
|
|
11495
11571
|
function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
|
|
11496
|
-
return
|
|
11572
|
+
return import_fp_ts27.function.pipe(
|
|
11497
11573
|
parseStableswapOrderRedeemer(redeemerCborHex),
|
|
11498
|
-
|
|
11574
|
+
import_fp_ts27.option.match(() => {
|
|
11499
11575
|
throw new Error("Expected a Stableswap Order redeemer.");
|
|
11500
|
-
},
|
|
11576
|
+
}, import_fp_ts27.function.identity)
|
|
11501
11577
|
);
|
|
11502
11578
|
}
|
|
11503
11579
|
|
|
@@ -11753,25 +11829,25 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
|
|
|
11753
11829
|
return [];
|
|
11754
11830
|
}
|
|
11755
11831
|
});
|
|
11756
|
-
const { left: mintingOrders, right: redeemingOrdersSortedDesc } =
|
|
11832
|
+
const { left: mintingOrders, right: redeemingOrdersSortedDesc } = import_fp_ts28.function.pipe(
|
|
11757
11833
|
validOrders,
|
|
11758
|
-
|
|
11834
|
+
import_fp_ts28.array.partition((o) => o.orderType === "REDEEMING"),
|
|
11759
11835
|
({ left, right }) => ({
|
|
11760
11836
|
left,
|
|
11761
11837
|
// Sort the redeeming orders descending.
|
|
11762
|
-
right:
|
|
11838
|
+
right: import_fp_ts28.function.pipe(
|
|
11763
11839
|
right,
|
|
11764
|
-
|
|
11765
|
-
|
|
11840
|
+
import_fp_ts28.array.sort(
|
|
11841
|
+
import_fp_ts28.ord.contramap(
|
|
11766
11842
|
(o) => o.swapInfo.owedCollateralAsset
|
|
11767
|
-
)(
|
|
11843
|
+
)(import_fp_ts28.ord.reverse(BigIntOrd))
|
|
11768
11844
|
)
|
|
11769
11845
|
)
|
|
11770
11846
|
})
|
|
11771
11847
|
);
|
|
11772
|
-
const totalCollateralDiff =
|
|
11848
|
+
const totalCollateralDiff = import_fp_ts28.function.pipe(
|
|
11773
11849
|
validOrders,
|
|
11774
|
-
|
|
11850
|
+
import_fp_ts28.array.reduce(
|
|
11775
11851
|
0n,
|
|
11776
11852
|
(acc, order) => acc + order.swapInfo.suppliedCollateralAsset - order.swapInfo.owedCollateralAsset
|
|
11777
11853
|
)
|
|
@@ -11779,13 +11855,13 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
|
|
|
11779
11855
|
if (psmAvailableLiq + totalCollateralDiff >= 0n) {
|
|
11780
11856
|
return validOrders.map((o) => o.order);
|
|
11781
11857
|
}
|
|
11782
|
-
const collateralFromMinting =
|
|
11858
|
+
const collateralFromMinting = import_fp_ts28.function.pipe(
|
|
11783
11859
|
mintingOrders,
|
|
11784
|
-
|
|
11860
|
+
import_fp_ts28.array.reduce(0n, (acc, o) => acc + o.swapInfo.suppliedCollateralAsset)
|
|
11785
11861
|
);
|
|
11786
|
-
const { selected } =
|
|
11862
|
+
const { selected } = import_fp_ts28.function.pipe(
|
|
11787
11863
|
redeemingOrdersSortedDesc,
|
|
11788
|
-
|
|
11864
|
+
import_fp_ts28.array.reduce(
|
|
11789
11865
|
{
|
|
11790
11866
|
intermediateCollateralAmt: psmAvailableLiq + collateralFromMinting,
|
|
11791
11867
|
selected: []
|
|
@@ -11802,7 +11878,7 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
|
|
|
11802
11878
|
// src/contracts/stableswap/queries.ts
|
|
11803
11879
|
var import_lucid67 = require("@lucid-evolution/lucid");
|
|
11804
11880
|
var import_cardano_offchain_common36 = require("@indigo-labs/cardano-offchain-common");
|
|
11805
|
-
var
|
|
11881
|
+
var import_fp_ts29 = require("fp-ts");
|
|
11806
11882
|
async function findAllStableswapPools(lucid, sysParams) {
|
|
11807
11883
|
const cdpUtxos = await lucid.utxosAtWithUnit(
|
|
11808
11884
|
createScriptAddress(
|
|
@@ -11813,28 +11889,28 @@ async function findAllStableswapPools(lucid, sysParams) {
|
|
|
11813
11889
|
fromSystemParamsAsset(sysParams.stableswapParams.cdpToken)
|
|
11814
11890
|
)
|
|
11815
11891
|
);
|
|
11816
|
-
return
|
|
11892
|
+
return import_fp_ts29.function.pipe(
|
|
11817
11893
|
cdpUtxos.map(
|
|
11818
|
-
(utxo) =>
|
|
11819
|
-
|
|
11820
|
-
|
|
11821
|
-
|
|
11894
|
+
(utxo) => import_fp_ts29.function.pipe(
|
|
11895
|
+
import_fp_ts29.option.fromNullable(utxo.datum),
|
|
11896
|
+
import_fp_ts29.option.flatMap(parseStableswapPoolDatum),
|
|
11897
|
+
import_fp_ts29.option.map((datum) => ({ utxo, datum }))
|
|
11822
11898
|
)
|
|
11823
11899
|
),
|
|
11824
|
-
|
|
11900
|
+
import_fp_ts29.array.compact
|
|
11825
11901
|
);
|
|
11826
11902
|
}
|
|
11827
11903
|
async function findStableswapPool(lucid, sysParams, iassetName, collateralAsset) {
|
|
11828
11904
|
const stableswapPools = await findAllStableswapPools(lucid, sysParams);
|
|
11829
11905
|
return (0, import_cardano_offchain_common36.matchSingle)(
|
|
11830
|
-
|
|
11906
|
+
import_fp_ts29.function.pipe(
|
|
11831
11907
|
stableswapPools.map((pool) => {
|
|
11832
11908
|
if ((0, import_lucid67.toHex)(pool.datum.iasset) === iassetName && (0, import_cardano_offchain_common36.isSameAssetClass)(pool.datum.collateralAsset, collateralAsset)) {
|
|
11833
|
-
return
|
|
11909
|
+
return import_fp_ts29.option.some(pool);
|
|
11834
11910
|
}
|
|
11835
|
-
return
|
|
11911
|
+
return import_fp_ts29.option.none;
|
|
11836
11912
|
}),
|
|
11837
|
-
|
|
11913
|
+
import_fp_ts29.array.compact
|
|
11838
11914
|
),
|
|
11839
11915
|
(res) => new Error(
|
|
11840
11916
|
"Expected a single stableswap pool UTXO.: " + JSON.stringify(res)
|
|
@@ -11845,7 +11921,7 @@ async function findStableswapPool(lucid, sysParams, iassetName, collateralAsset)
|
|
|
11845
11921
|
// src/contracts/stableswap/transactions.ts
|
|
11846
11922
|
var import_lucid68 = require("@lucid-evolution/lucid");
|
|
11847
11923
|
var import_cardano_offchain_common37 = require("@indigo-labs/cardano-offchain-common");
|
|
11848
|
-
var
|
|
11924
|
+
var import_fp_ts30 = require("fp-ts");
|
|
11849
11925
|
async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
|
|
11850
11926
|
const myAddress = await lucid.wallet().address();
|
|
11851
11927
|
const pkh = (0, import_lucid68.paymentCredentialOf)(myAddress);
|
|
@@ -11933,7 +12009,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11933
12009
|
]),
|
|
11934
12010
|
(_) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
11935
12011
|
);
|
|
11936
|
-
if (
|
|
12012
|
+
if (import_fp_ts30.array.isEmpty(stableswapOrderOrefs)) {
|
|
11937
12013
|
throw new Error("At least one order must be provided.");
|
|
11938
12014
|
}
|
|
11939
12015
|
const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
|
|
@@ -11980,9 +12056,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11980
12056
|
return res.result;
|
|
11981
12057
|
}
|
|
11982
12058
|
);
|
|
11983
|
-
const totalSwapInfo =
|
|
12059
|
+
const totalSwapInfo = import_fp_ts30.function.pipe(
|
|
11984
12060
|
ordersInfo,
|
|
11985
|
-
|
|
12061
|
+
import_fp_ts30.array.reduce(
|
|
11986
12062
|
{
|
|
11987
12063
|
suppliedCollateralAsset: 0n,
|
|
11988
12064
|
suppliedIasset: 0n,
|
|
@@ -12036,9 +12112,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
12036
12112
|
if (amountToMint !== 0n) {
|
|
12037
12113
|
tx.mintAssets((0, import_cardano_offchain_common37.mkAssetsOf)(iassetAc, amountToMint), import_lucid68.Data.void());
|
|
12038
12114
|
}
|
|
12039
|
-
|
|
12115
|
+
import_fp_ts30.function.pipe(
|
|
12040
12116
|
ordersInfo,
|
|
12041
|
-
|
|
12117
|
+
import_fp_ts30.array.reduce(tx, (acc, orderInfo) => {
|
|
12042
12118
|
return acc.collectFrom(
|
|
12043
12119
|
[orderInfo.order.utxo],
|
|
12044
12120
|
(0, import_cardano_offchain_common37.isSameOutRef)(orderInfo.order.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
|
|
@@ -12330,7 +12406,6 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
12330
12406
|
initGovernance,
|
|
12331
12407
|
initInterestCollector,
|
|
12332
12408
|
initPythConfig,
|
|
12333
|
-
initScriptRef,
|
|
12334
12409
|
initSpState,
|
|
12335
12410
|
initStakingManager,
|
|
12336
12411
|
initSumVal,
|
|
@@ -12467,6 +12542,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
12467
12542
|
robCollateralAmtToSpend,
|
|
12468
12543
|
robIAssetAmtToSpend,
|
|
12469
12544
|
robSellOrderFilledAssets,
|
|
12545
|
+
runAndAwaitTxBuilder,
|
|
12470
12546
|
runCreateScriptRefTx,
|
|
12471
12547
|
runOneShotMintTx,
|
|
12472
12548
|
scriptRef,
|
|
@@ -12512,13 +12588,13 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
12512
12588
|
spZeroNegatives,
|
|
12513
12589
|
startInterestOracle,
|
|
12514
12590
|
startPriceOracleTx,
|
|
12515
|
-
submitTx,
|
|
12516
12591
|
sum,
|
|
12517
12592
|
summariseOrder,
|
|
12518
12593
|
summarizeActualLeverageRedemptions,
|
|
12519
12594
|
toAssetClassFromLucid,
|
|
12520
12595
|
toDataDerivedPythPrice,
|
|
12521
12596
|
toSystemParamsAsset,
|
|
12597
|
+
toSystemParamsInput,
|
|
12522
12598
|
treasuryCollect,
|
|
12523
12599
|
treasuryFeeTx,
|
|
12524
12600
|
treasuryMerge,
|