@indigo-labs/indigo-sdk 0.5.16 → 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 +277 -196
- package/dist/index.mjs +273 -192
- 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,23 +10731,30 @@ async function initPyth(lucid) {
|
|
|
10718
10731
|
alwaysSucceedValidator
|
|
10719
10732
|
)
|
|
10720
10733
|
);
|
|
10721
|
-
|
|
10722
|
-
lucid.config().network,
|
|
10723
|
-
{ hash: (0, import_lucid63.validatorToScriptHash)(alwaysSucceedValidator), type: "Script" }
|
|
10724
|
-
);
|
|
10725
|
-
const { registered } = await lucid.rewardAccountAt(
|
|
10726
|
-
alwaysSucceedRewardAddress
|
|
10727
|
-
);
|
|
10728
|
-
if (!registered) {
|
|
10734
|
+
try {
|
|
10729
10735
|
await runAndAwaitTxBuilder(
|
|
10730
10736
|
lucid,
|
|
10731
|
-
lucid.newTx().register.Stake(
|
|
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
|
+
)
|
|
10732
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
|
+
}
|
|
10733
10749
|
}
|
|
10734
10750
|
return pythStateAsset;
|
|
10735
10751
|
}
|
|
10736
10752
|
|
|
10737
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
|
+
}
|
|
10738
10758
|
var DEFAULT_STAKING_CRED = {
|
|
10739
10759
|
tag: "StakingHash",
|
|
10740
10760
|
contents: {
|
|
@@ -10751,29 +10771,31 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
|
|
|
10751
10771
|
fromSysParamsPythFeedParams(val.pythFeedParams)
|
|
10752
10772
|
);
|
|
10753
10773
|
const pythFeedValHash = (0, import_lucid64.validatorToScriptHash)(pythFeedValidator);
|
|
10754
|
-
const pythFeedValScriptRef = await
|
|
10774
|
+
const pythFeedValScriptRef = await runCreateScriptRefTx(
|
|
10755
10775
|
lucid,
|
|
10756
10776
|
pythFeedValidator
|
|
10757
10777
|
);
|
|
10758
|
-
|
|
10759
|
-
lucid.config().network,
|
|
10760
|
-
{ hash: (0, import_lucid64.validatorToScriptHash)(pythFeedValidator), type: "Script" }
|
|
10761
|
-
);
|
|
10762
|
-
const { registered } = await lucid.rewardAccountAt(
|
|
10763
|
-
pythFeedRewardAddress
|
|
10764
|
-
);
|
|
10765
|
-
if (!registered) {
|
|
10778
|
+
try {
|
|
10766
10779
|
await runAndAwaitTxBuilder(
|
|
10767
10780
|
lucid,
|
|
10768
|
-
lucid.newTx().register.Stake(
|
|
10781
|
+
lucid.newTx().register.Stake(
|
|
10782
|
+
(0, import_lucid64.credentialToRewardAddress)(lucid.config().network, {
|
|
10783
|
+
hash: (0, import_lucid64.validatorToScriptHash)(pythFeedValidator),
|
|
10784
|
+
type: "Script"
|
|
10785
|
+
})
|
|
10786
|
+
)
|
|
10769
10787
|
);
|
|
10788
|
+
} catch (error) {
|
|
10789
|
+
if (!isAlreadyRegisteredError(error)) throw error;
|
|
10770
10790
|
}
|
|
10771
10791
|
const key = `${asset.name}/${(0, import_lucid64.toHex)(collateral.collateralAsset.currencySymbol)}.${(0, import_lucid64.toHex)(collateral.collateralAsset.tokenName)}`;
|
|
10772
10792
|
return {
|
|
10773
10793
|
[key]: {
|
|
10774
10794
|
params: val.pythFeedParams,
|
|
10775
10795
|
pythFeedValHash,
|
|
10776
|
-
pythFeedValScriptRef: {
|
|
10796
|
+
pythFeedValScriptRef: {
|
|
10797
|
+
input: toSystemParamsInput(pythFeedValScriptRef)
|
|
10798
|
+
}
|
|
10777
10799
|
}
|
|
10778
10800
|
};
|
|
10779
10801
|
}).otherwise(() => Promise.resolve({}));
|
|
@@ -10807,6 +10829,19 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10807
10829
|
const indyAsset = await mintOneTimeAsset(lucid, tn.indy, totalIndySupply);
|
|
10808
10830
|
const daoAsset = await mintOneTimeAsset(lucid, tn.dao, 1n);
|
|
10809
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);
|
|
10810
10845
|
const pollToken = deriveAuthToken(govNftAsset, tn.pollManager);
|
|
10811
10846
|
const upgradeToken = deriveAuthToken(pollToken, tn.upgrade);
|
|
10812
10847
|
const iassetToken = deriveAuthToken(upgradeToken, tn.iasset);
|
|
@@ -10832,18 +10867,6 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10832
10867
|
const versionRegistryValHash = (0, import_lucid64.validatorToScriptHash)(
|
|
10833
10868
|
versionRegistryValidator
|
|
10834
10869
|
);
|
|
10835
|
-
const cdpCreatorAsset = await mintOneTimeAsset(
|
|
10836
|
-
lucid,
|
|
10837
|
-
tn.cdpCreator,
|
|
10838
|
-
numCdpCreators
|
|
10839
|
-
);
|
|
10840
|
-
const cdpToken = deriveAuthToken(cdpCreatorAsset, tn.cdp);
|
|
10841
|
-
const stakingManagerAsset = await mintOneTimeAsset(
|
|
10842
|
-
lucid,
|
|
10843
|
-
tn.stakingManager,
|
|
10844
|
-
1n
|
|
10845
|
-
);
|
|
10846
|
-
const stakingToken = deriveAuthToken(stakingManagerAsset, tn.staking);
|
|
10847
10870
|
const collectorParams = {
|
|
10848
10871
|
stakingManagerNFT: toSystemParamsAsset(stakingManagerAsset),
|
|
10849
10872
|
stakingToken: toSystemParamsAsset(stakingToken),
|
|
@@ -10909,7 +10932,6 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10909
10932
|
treasuryIndyAmount,
|
|
10910
10933
|
numTreasuryUtxos
|
|
10911
10934
|
);
|
|
10912
|
-
const multisigUtxoNft = await mintOneTimeAsset(lucid, tn.multisigUtxo, 1n);
|
|
10913
10935
|
const interestCollectionParams = {
|
|
10914
10936
|
versionRecordNft: toSystemParamsAsset(versionRecordToken),
|
|
10915
10937
|
multisigUtxoNft: toSystemParamsAsset(multisigUtxoNft),
|
|
@@ -10957,12 +10979,13 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10957
10979
|
lucid.config().network,
|
|
10958
10980
|
(0, import_lucid64.scriptHashToCredential)(cdpRedeemValHash)
|
|
10959
10981
|
);
|
|
10960
|
-
|
|
10961
|
-
if (!cdpRedeemRegistered) {
|
|
10982
|
+
try {
|
|
10962
10983
|
await runAndAwaitTxBuilder(
|
|
10963
10984
|
lucid,
|
|
10964
10985
|
lucid.newTx().register.Stake(cdpRedeemRewardAddr)
|
|
10965
10986
|
);
|
|
10987
|
+
} catch (error) {
|
|
10988
|
+
if (!isAlreadyRegisteredError(error)) throw error;
|
|
10966
10989
|
}
|
|
10967
10990
|
const cdpParams = {
|
|
10968
10991
|
cdpAuthToken: toSystemParamsAsset(cdpToken),
|
|
@@ -11212,97 +11235,155 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
11212
11235
|
},
|
|
11213
11236
|
scriptReferences: {
|
|
11214
11237
|
interestCollectionValidatorRef: {
|
|
11215
|
-
input:
|
|
11238
|
+
input: toSystemParamsInput(
|
|
11239
|
+
await runCreateScriptRefTx(lucid, interestCollectionValidator)
|
|
11240
|
+
)
|
|
11216
11241
|
},
|
|
11217
11242
|
robValidatorRef: {
|
|
11218
|
-
input:
|
|
11243
|
+
input: toSystemParamsInput(
|
|
11244
|
+
await runCreateScriptRefTx(lucid, robValidator)
|
|
11245
|
+
)
|
|
11219
11246
|
},
|
|
11220
11247
|
cdpCreatorValidatorRef: {
|
|
11221
|
-
input:
|
|
11248
|
+
input: toSystemParamsInput(
|
|
11249
|
+
await runCreateScriptRefTx(lucid, cdpCreatorValidator)
|
|
11250
|
+
)
|
|
11222
11251
|
},
|
|
11223
11252
|
cdpValidatorRef: {
|
|
11224
|
-
input:
|
|
11253
|
+
input: toSystemParamsInput(
|
|
11254
|
+
await runCreateScriptRefTx(lucid, cdpValidator)
|
|
11255
|
+
)
|
|
11225
11256
|
},
|
|
11226
11257
|
cdpRedeemValidatorRef: {
|
|
11227
|
-
input:
|
|
11258
|
+
input: toSystemParamsInput(
|
|
11259
|
+
await runCreateScriptRefTx(lucid, cdpRedeemValidator)
|
|
11260
|
+
)
|
|
11228
11261
|
},
|
|
11229
11262
|
collectorValidatorRef: {
|
|
11230
|
-
input:
|
|
11263
|
+
input: toSystemParamsInput(
|
|
11264
|
+
await runCreateScriptRefTx(lucid, collectorValidator)
|
|
11265
|
+
)
|
|
11231
11266
|
},
|
|
11232
11267
|
executeValidatorRef: {
|
|
11233
|
-
input:
|
|
11268
|
+
input: toSystemParamsInput(
|
|
11269
|
+
await runCreateScriptRefTx(lucid, executeValidator)
|
|
11270
|
+
)
|
|
11234
11271
|
},
|
|
11235
11272
|
pollShardValidatorRef: {
|
|
11236
|
-
input:
|
|
11273
|
+
input: toSystemParamsInput(
|
|
11274
|
+
await runCreateScriptRefTx(lucid, pollShardValidator)
|
|
11275
|
+
)
|
|
11237
11276
|
},
|
|
11238
11277
|
pollManagerValidatorRef: {
|
|
11239
|
-
input:
|
|
11278
|
+
input: toSystemParamsInput(
|
|
11279
|
+
await runCreateScriptRefTx(lucid, pollManagerValidator)
|
|
11280
|
+
)
|
|
11240
11281
|
},
|
|
11241
11282
|
iAssetTokenPolicyRef: {
|
|
11242
|
-
input:
|
|
11283
|
+
input: toSystemParamsInput(
|
|
11284
|
+
await runCreateScriptRefTx(lucid, assetSymbolPolicy)
|
|
11285
|
+
)
|
|
11243
11286
|
},
|
|
11244
11287
|
stakingValidatorRef: {
|
|
11245
|
-
input:
|
|
11246
|
-
|
|
11247
|
-
|
|
11288
|
+
input: toSystemParamsInput(
|
|
11289
|
+
await runCreateScriptRefTx(
|
|
11290
|
+
lucid,
|
|
11291
|
+
mkStakingValidatorFromSP(stakingParams)
|
|
11292
|
+
)
|
|
11248
11293
|
)
|
|
11249
11294
|
},
|
|
11250
11295
|
stabilityPoolValidatorRef: {
|
|
11251
|
-
input:
|
|
11296
|
+
input: toSystemParamsInput(
|
|
11297
|
+
await runCreateScriptRefTx(lucid, stabilityPoolValidator)
|
|
11298
|
+
)
|
|
11252
11299
|
},
|
|
11253
11300
|
stableswapValidatorRef: {
|
|
11254
|
-
input:
|
|
11301
|
+
input: toSystemParamsInput(
|
|
11302
|
+
await runCreateScriptRefTx(lucid, stableswapValidator)
|
|
11303
|
+
)
|
|
11255
11304
|
},
|
|
11256
11305
|
treasuryValidatorRef: {
|
|
11257
|
-
input:
|
|
11306
|
+
input: toSystemParamsInput(
|
|
11307
|
+
await runCreateScriptRefTx(lucid, treasuryValidator)
|
|
11308
|
+
)
|
|
11258
11309
|
},
|
|
11259
11310
|
governanceValidatorRef: {
|
|
11260
|
-
input:
|
|
11311
|
+
input: toSystemParamsInput(
|
|
11312
|
+
await runCreateScriptRefTx(lucid, govValidator)
|
|
11313
|
+
)
|
|
11261
11314
|
},
|
|
11262
11315
|
versionRegistryValidatorRef: {
|
|
11263
|
-
input:
|
|
11316
|
+
input: toSystemParamsInput(
|
|
11317
|
+
await runCreateScriptRefTx(lucid, versionRegistryValidator)
|
|
11318
|
+
)
|
|
11264
11319
|
},
|
|
11265
11320
|
iassetValidatorRef: {
|
|
11266
|
-
input:
|
|
11321
|
+
input: toSystemParamsInput(
|
|
11322
|
+
await runCreateScriptRefTx(lucid, iassetValidator)
|
|
11323
|
+
)
|
|
11267
11324
|
},
|
|
11268
11325
|
authTokenPolicies: {
|
|
11269
11326
|
cdpAuthTokenRef: {
|
|
11270
|
-
input:
|
|
11327
|
+
input: toSystemParamsInput(
|
|
11328
|
+
await runCreateScriptRefTx(lucid, cdpTokenPolicy)
|
|
11329
|
+
)
|
|
11271
11330
|
},
|
|
11272
11331
|
iAssetAuthTokenRef: {
|
|
11273
|
-
input:
|
|
11332
|
+
input: toSystemParamsInput(
|
|
11333
|
+
await runCreateScriptRefTx(lucid, iassetTokenPolicy)
|
|
11334
|
+
)
|
|
11274
11335
|
},
|
|
11275
11336
|
accountTokenRef: {
|
|
11276
|
-
input:
|
|
11337
|
+
input: toSystemParamsInput(
|
|
11338
|
+
await runCreateScriptRefTx(lucid, accountTokenPolicy)
|
|
11339
|
+
)
|
|
11277
11340
|
},
|
|
11278
11341
|
stabilityPoolAuthTokenRef: {
|
|
11279
|
-
input:
|
|
11342
|
+
input: toSystemParamsInput(
|
|
11343
|
+
await runCreateScriptRefTx(lucid, stabilityPoolTokenPolicy)
|
|
11344
|
+
)
|
|
11280
11345
|
},
|
|
11281
11346
|
pollManagerTokenRef: {
|
|
11282
|
-
input:
|
|
11347
|
+
input: toSystemParamsInput(
|
|
11348
|
+
await runCreateScriptRefTx(lucid, pollTokenPolicy)
|
|
11349
|
+
)
|
|
11283
11350
|
},
|
|
11284
11351
|
stakingTokenRef: {
|
|
11285
|
-
input:
|
|
11352
|
+
input: toSystemParamsInput(
|
|
11353
|
+
await runCreateScriptRefTx(lucid, stakingTokenPolicy)
|
|
11354
|
+
)
|
|
11286
11355
|
},
|
|
11287
11356
|
versionRecordTokenPolicyRef: {
|
|
11288
|
-
input:
|
|
11357
|
+
input: toSystemParamsInput(
|
|
11358
|
+
await runCreateScriptRefTx(lucid, versionRecordTokenPolicy)
|
|
11359
|
+
)
|
|
11289
11360
|
},
|
|
11290
11361
|
iAssetTokenRef: {
|
|
11291
|
-
input:
|
|
11362
|
+
input: toSystemParamsInput(
|
|
11363
|
+
await runCreateScriptRefTx(lucid, assetSymbolPolicy)
|
|
11364
|
+
)
|
|
11292
11365
|
},
|
|
11293
11366
|
collateralAssetTokenRef: {
|
|
11294
|
-
input:
|
|
11367
|
+
input: toSystemParamsInput(
|
|
11368
|
+
await runCreateScriptRefTx(lucid, collateralAssetAuthTokenPolicy)
|
|
11369
|
+
)
|
|
11295
11370
|
},
|
|
11296
11371
|
upgradeTokenRef: {
|
|
11297
|
-
input:
|
|
11372
|
+
input: toSystemParamsInput(
|
|
11373
|
+
await runCreateScriptRefTx(lucid, upgradeTokenPolicy)
|
|
11374
|
+
)
|
|
11298
11375
|
},
|
|
11299
11376
|
stabilityPoolTokenRef: {
|
|
11300
|
-
input:
|
|
11377
|
+
input: toSystemParamsInput(
|
|
11378
|
+
await runCreateScriptRefTx(lucid, stabilityPoolTokenPolicy)
|
|
11379
|
+
)
|
|
11301
11380
|
},
|
|
11302
11381
|
snapshotEpochToScaleToSumTokenRef: {
|
|
11303
|
-
input:
|
|
11304
|
-
|
|
11305
|
-
|
|
11382
|
+
input: toSystemParamsInput(
|
|
11383
|
+
await runCreateScriptRefTx(
|
|
11384
|
+
lucid,
|
|
11385
|
+
snapshotEpochToScaleToSumTokenPolicy
|
|
11386
|
+
)
|
|
11306
11387
|
)
|
|
11307
11388
|
}
|
|
11308
11389
|
}
|
|
@@ -11332,7 +11413,7 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
11332
11413
|
// src/contracts/iasset/queries.ts
|
|
11333
11414
|
var import_lucid65 = require("@lucid-evolution/lucid");
|
|
11334
11415
|
var import_cardano_offchain_common33 = require("@indigo-labs/cardano-offchain-common");
|
|
11335
|
-
var
|
|
11416
|
+
var import_fp_ts26 = require("fp-ts");
|
|
11336
11417
|
async function findIAsset(lucid, sysParams, iassetName) {
|
|
11337
11418
|
const iassetUtxos = await lucid.utxosAtWithUnit(
|
|
11338
11419
|
createScriptAddress(
|
|
@@ -11344,21 +11425,21 @@ async function findIAsset(lucid, sysParams, iassetName) {
|
|
|
11344
11425
|
)
|
|
11345
11426
|
);
|
|
11346
11427
|
return (0, import_cardano_offchain_common33.matchSingle)(
|
|
11347
|
-
|
|
11428
|
+
import_fp_ts26.function.pipe(
|
|
11348
11429
|
iassetUtxos.map(
|
|
11349
|
-
(utxo) =>
|
|
11350
|
-
|
|
11351
|
-
|
|
11352
|
-
|
|
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) => {
|
|
11353
11434
|
if ((0, import_lucid65.toHex)(datum.assetName) === (0, import_lucid65.toHex)(iassetName)) {
|
|
11354
|
-
return
|
|
11435
|
+
return import_fp_ts26.option.some({ utxo, datum });
|
|
11355
11436
|
} else {
|
|
11356
|
-
return
|
|
11437
|
+
return import_fp_ts26.option.none;
|
|
11357
11438
|
}
|
|
11358
11439
|
})
|
|
11359
11440
|
)
|
|
11360
11441
|
),
|
|
11361
|
-
|
|
11442
|
+
import_fp_ts26.array.compact
|
|
11362
11443
|
),
|
|
11363
11444
|
(res) => new Error("Expected a single IAsset UTXO.: " + JSON.stringify(res))
|
|
11364
11445
|
);
|
|
@@ -11374,21 +11455,21 @@ async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset
|
|
|
11374
11455
|
)
|
|
11375
11456
|
);
|
|
11376
11457
|
return (0, import_cardano_offchain_common33.matchSingle)(
|
|
11377
|
-
|
|
11458
|
+
import_fp_ts26.function.pipe(
|
|
11378
11459
|
collateralAssetUtxos.map(
|
|
11379
|
-
(utxo) =>
|
|
11380
|
-
|
|
11381
|
-
|
|
11382
|
-
|
|
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) => {
|
|
11383
11464
|
if ((0, import_cardano_offchain_common33.isSameAssetClass)(datum.collateralAsset, collateralAsset) && (0, import_lucid65.toHex)(iassetName) === (0, import_lucid65.toHex)(datum.iasset)) {
|
|
11384
|
-
return
|
|
11465
|
+
return import_fp_ts26.option.some({ utxo, datum });
|
|
11385
11466
|
} else {
|
|
11386
|
-
return
|
|
11467
|
+
return import_fp_ts26.option.none;
|
|
11387
11468
|
}
|
|
11388
11469
|
})
|
|
11389
11470
|
)
|
|
11390
11471
|
),
|
|
11391
|
-
|
|
11472
|
+
import_fp_ts26.array.compact
|
|
11392
11473
|
),
|
|
11393
11474
|
(res) => new Error(
|
|
11394
11475
|
"Expected a single Collateral Asset UTXO.: " + JSON.stringify(res)
|
|
@@ -11398,12 +11479,12 @@ async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset
|
|
|
11398
11479
|
|
|
11399
11480
|
// src/contracts/stableswap/helpers.ts
|
|
11400
11481
|
var import_lucid66 = require("@lucid-evolution/lucid");
|
|
11401
|
-
var
|
|
11482
|
+
var import_fp_ts28 = require("fp-ts");
|
|
11402
11483
|
|
|
11403
11484
|
// src/contracts/stableswap/types-new.ts
|
|
11404
11485
|
var import_cardano_offchain_common34 = require("@indigo-labs/cardano-offchain-common");
|
|
11405
11486
|
var import_evolution20 = require("@evolution-sdk/evolution");
|
|
11406
|
-
var
|
|
11487
|
+
var import_fp_ts27 = require("fp-ts");
|
|
11407
11488
|
var import_effect3 = require("effect");
|
|
11408
11489
|
var OpaqueData4 = import_effect3.Schema.typeSchema(import_evolution20.Data.DataSchema);
|
|
11409
11490
|
var StableswapOrderDatumSchema = import_evolution20.TSchema.Struct({
|
|
@@ -11445,22 +11526,22 @@ function serialiseStableswapOrderDatum(d) {
|
|
|
11445
11526
|
}
|
|
11446
11527
|
function parseStableswapOrderDatum(datum) {
|
|
11447
11528
|
try {
|
|
11448
|
-
return
|
|
11529
|
+
return import_fp_ts27.option.some(
|
|
11449
11530
|
import_evolution20.Data.withSchema(
|
|
11450
11531
|
StableswapOrderDatumSchema,
|
|
11451
11532
|
DEFAULT_SCHEMA_OPTIONS
|
|
11452
11533
|
).fromCBORHex(datum)
|
|
11453
11534
|
);
|
|
11454
11535
|
} catch (_) {
|
|
11455
|
-
return
|
|
11536
|
+
return import_fp_ts27.option.none;
|
|
11456
11537
|
}
|
|
11457
11538
|
}
|
|
11458
11539
|
function parseStableswapOrderDatumOrThrow(datum) {
|
|
11459
|
-
return
|
|
11540
|
+
return import_fp_ts27.function.pipe(
|
|
11460
11541
|
parseStableswapOrderDatum(datum),
|
|
11461
|
-
|
|
11542
|
+
import_fp_ts27.option.match(() => {
|
|
11462
11543
|
throw new Error("Expected a Stableswap Order datum.");
|
|
11463
|
-
},
|
|
11544
|
+
}, import_fp_ts27.function.identity)
|
|
11464
11545
|
);
|
|
11465
11546
|
}
|
|
11466
11547
|
function serialiseStableswapOutputDatum(d) {
|
|
@@ -11477,22 +11558,22 @@ function serialiseStableswapOrderRedeemer(r) {
|
|
|
11477
11558
|
}
|
|
11478
11559
|
function parseStableswapOrderRedeemer(redeemerCborHex) {
|
|
11479
11560
|
try {
|
|
11480
|
-
return
|
|
11561
|
+
return import_fp_ts27.option.some(
|
|
11481
11562
|
import_evolution20.Data.withSchema(
|
|
11482
11563
|
StableswapOrderRedeemerSchema,
|
|
11483
11564
|
DEFAULT_SCHEMA_OPTIONS
|
|
11484
11565
|
).fromCBORHex(redeemerCborHex)
|
|
11485
11566
|
);
|
|
11486
11567
|
} catch (_) {
|
|
11487
|
-
return
|
|
11568
|
+
return import_fp_ts27.option.none;
|
|
11488
11569
|
}
|
|
11489
11570
|
}
|
|
11490
11571
|
function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
|
|
11491
|
-
return
|
|
11572
|
+
return import_fp_ts27.function.pipe(
|
|
11492
11573
|
parseStableswapOrderRedeemer(redeemerCborHex),
|
|
11493
|
-
|
|
11574
|
+
import_fp_ts27.option.match(() => {
|
|
11494
11575
|
throw new Error("Expected a Stableswap Order redeemer.");
|
|
11495
|
-
},
|
|
11576
|
+
}, import_fp_ts27.function.identity)
|
|
11496
11577
|
);
|
|
11497
11578
|
}
|
|
11498
11579
|
|
|
@@ -11748,25 +11829,25 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
|
|
|
11748
11829
|
return [];
|
|
11749
11830
|
}
|
|
11750
11831
|
});
|
|
11751
|
-
const { left: mintingOrders, right: redeemingOrdersSortedDesc } =
|
|
11832
|
+
const { left: mintingOrders, right: redeemingOrdersSortedDesc } = import_fp_ts28.function.pipe(
|
|
11752
11833
|
validOrders,
|
|
11753
|
-
|
|
11834
|
+
import_fp_ts28.array.partition((o) => o.orderType === "REDEEMING"),
|
|
11754
11835
|
({ left, right }) => ({
|
|
11755
11836
|
left,
|
|
11756
11837
|
// Sort the redeeming orders descending.
|
|
11757
|
-
right:
|
|
11838
|
+
right: import_fp_ts28.function.pipe(
|
|
11758
11839
|
right,
|
|
11759
|
-
|
|
11760
|
-
|
|
11840
|
+
import_fp_ts28.array.sort(
|
|
11841
|
+
import_fp_ts28.ord.contramap(
|
|
11761
11842
|
(o) => o.swapInfo.owedCollateralAsset
|
|
11762
|
-
)(
|
|
11843
|
+
)(import_fp_ts28.ord.reverse(BigIntOrd))
|
|
11763
11844
|
)
|
|
11764
11845
|
)
|
|
11765
11846
|
})
|
|
11766
11847
|
);
|
|
11767
|
-
const totalCollateralDiff =
|
|
11848
|
+
const totalCollateralDiff = import_fp_ts28.function.pipe(
|
|
11768
11849
|
validOrders,
|
|
11769
|
-
|
|
11850
|
+
import_fp_ts28.array.reduce(
|
|
11770
11851
|
0n,
|
|
11771
11852
|
(acc, order) => acc + order.swapInfo.suppliedCollateralAsset - order.swapInfo.owedCollateralAsset
|
|
11772
11853
|
)
|
|
@@ -11774,13 +11855,13 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
|
|
|
11774
11855
|
if (psmAvailableLiq + totalCollateralDiff >= 0n) {
|
|
11775
11856
|
return validOrders.map((o) => o.order);
|
|
11776
11857
|
}
|
|
11777
|
-
const collateralFromMinting =
|
|
11858
|
+
const collateralFromMinting = import_fp_ts28.function.pipe(
|
|
11778
11859
|
mintingOrders,
|
|
11779
|
-
|
|
11860
|
+
import_fp_ts28.array.reduce(0n, (acc, o) => acc + o.swapInfo.suppliedCollateralAsset)
|
|
11780
11861
|
);
|
|
11781
|
-
const { selected } =
|
|
11862
|
+
const { selected } = import_fp_ts28.function.pipe(
|
|
11782
11863
|
redeemingOrdersSortedDesc,
|
|
11783
|
-
|
|
11864
|
+
import_fp_ts28.array.reduce(
|
|
11784
11865
|
{
|
|
11785
11866
|
intermediateCollateralAmt: psmAvailableLiq + collateralFromMinting,
|
|
11786
11867
|
selected: []
|
|
@@ -11797,7 +11878,7 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
|
|
|
11797
11878
|
// src/contracts/stableswap/queries.ts
|
|
11798
11879
|
var import_lucid67 = require("@lucid-evolution/lucid");
|
|
11799
11880
|
var import_cardano_offchain_common36 = require("@indigo-labs/cardano-offchain-common");
|
|
11800
|
-
var
|
|
11881
|
+
var import_fp_ts29 = require("fp-ts");
|
|
11801
11882
|
async function findAllStableswapPools(lucid, sysParams) {
|
|
11802
11883
|
const cdpUtxos = await lucid.utxosAtWithUnit(
|
|
11803
11884
|
createScriptAddress(
|
|
@@ -11808,28 +11889,28 @@ async function findAllStableswapPools(lucid, sysParams) {
|
|
|
11808
11889
|
fromSystemParamsAsset(sysParams.stableswapParams.cdpToken)
|
|
11809
11890
|
)
|
|
11810
11891
|
);
|
|
11811
|
-
return
|
|
11892
|
+
return import_fp_ts29.function.pipe(
|
|
11812
11893
|
cdpUtxos.map(
|
|
11813
|
-
(utxo) =>
|
|
11814
|
-
|
|
11815
|
-
|
|
11816
|
-
|
|
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 }))
|
|
11817
11898
|
)
|
|
11818
11899
|
),
|
|
11819
|
-
|
|
11900
|
+
import_fp_ts29.array.compact
|
|
11820
11901
|
);
|
|
11821
11902
|
}
|
|
11822
11903
|
async function findStableswapPool(lucid, sysParams, iassetName, collateralAsset) {
|
|
11823
11904
|
const stableswapPools = await findAllStableswapPools(lucid, sysParams);
|
|
11824
11905
|
return (0, import_cardano_offchain_common36.matchSingle)(
|
|
11825
|
-
|
|
11906
|
+
import_fp_ts29.function.pipe(
|
|
11826
11907
|
stableswapPools.map((pool) => {
|
|
11827
11908
|
if ((0, import_lucid67.toHex)(pool.datum.iasset) === iassetName && (0, import_cardano_offchain_common36.isSameAssetClass)(pool.datum.collateralAsset, collateralAsset)) {
|
|
11828
|
-
return
|
|
11909
|
+
return import_fp_ts29.option.some(pool);
|
|
11829
11910
|
}
|
|
11830
|
-
return
|
|
11911
|
+
return import_fp_ts29.option.none;
|
|
11831
11912
|
}),
|
|
11832
|
-
|
|
11913
|
+
import_fp_ts29.array.compact
|
|
11833
11914
|
),
|
|
11834
11915
|
(res) => new Error(
|
|
11835
11916
|
"Expected a single stableswap pool UTXO.: " + JSON.stringify(res)
|
|
@@ -11840,7 +11921,7 @@ async function findStableswapPool(lucid, sysParams, iassetName, collateralAsset)
|
|
|
11840
11921
|
// src/contracts/stableswap/transactions.ts
|
|
11841
11922
|
var import_lucid68 = require("@lucid-evolution/lucid");
|
|
11842
11923
|
var import_cardano_offchain_common37 = require("@indigo-labs/cardano-offchain-common");
|
|
11843
|
-
var
|
|
11924
|
+
var import_fp_ts30 = require("fp-ts");
|
|
11844
11925
|
async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
|
|
11845
11926
|
const myAddress = await lucid.wallet().address();
|
|
11846
11927
|
const pkh = (0, import_lucid68.paymentCredentialOf)(myAddress);
|
|
@@ -11928,7 +12009,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11928
12009
|
]),
|
|
11929
12010
|
(_) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
11930
12011
|
);
|
|
11931
|
-
if (
|
|
12012
|
+
if (import_fp_ts30.array.isEmpty(stableswapOrderOrefs)) {
|
|
11932
12013
|
throw new Error("At least one order must be provided.");
|
|
11933
12014
|
}
|
|
11934
12015
|
const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
|
|
@@ -11975,9 +12056,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11975
12056
|
return res.result;
|
|
11976
12057
|
}
|
|
11977
12058
|
);
|
|
11978
|
-
const totalSwapInfo =
|
|
12059
|
+
const totalSwapInfo = import_fp_ts30.function.pipe(
|
|
11979
12060
|
ordersInfo,
|
|
11980
|
-
|
|
12061
|
+
import_fp_ts30.array.reduce(
|
|
11981
12062
|
{
|
|
11982
12063
|
suppliedCollateralAsset: 0n,
|
|
11983
12064
|
suppliedIasset: 0n,
|
|
@@ -12031,9 +12112,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
12031
12112
|
if (amountToMint !== 0n) {
|
|
12032
12113
|
tx.mintAssets((0, import_cardano_offchain_common37.mkAssetsOf)(iassetAc, amountToMint), import_lucid68.Data.void());
|
|
12033
12114
|
}
|
|
12034
|
-
|
|
12115
|
+
import_fp_ts30.function.pipe(
|
|
12035
12116
|
ordersInfo,
|
|
12036
|
-
|
|
12117
|
+
import_fp_ts30.array.reduce(tx, (acc, orderInfo) => {
|
|
12037
12118
|
return acc.collectFrom(
|
|
12038
12119
|
[orderInfo.order.utxo],
|
|
12039
12120
|
(0, import_cardano_offchain_common37.isSameOutRef)(orderInfo.order.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
|
|
@@ -12325,7 +12406,6 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
12325
12406
|
initGovernance,
|
|
12326
12407
|
initInterestCollector,
|
|
12327
12408
|
initPythConfig,
|
|
12328
|
-
initScriptRef,
|
|
12329
12409
|
initSpState,
|
|
12330
12410
|
initStakingManager,
|
|
12331
12411
|
initSumVal,
|
|
@@ -12462,6 +12542,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
12462
12542
|
robCollateralAmtToSpend,
|
|
12463
12543
|
robIAssetAmtToSpend,
|
|
12464
12544
|
robSellOrderFilledAssets,
|
|
12545
|
+
runAndAwaitTxBuilder,
|
|
12465
12546
|
runCreateScriptRefTx,
|
|
12466
12547
|
runOneShotMintTx,
|
|
12467
12548
|
scriptRef,
|
|
@@ -12507,13 +12588,13 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
12507
12588
|
spZeroNegatives,
|
|
12508
12589
|
startInterestOracle,
|
|
12509
12590
|
startPriceOracleTx,
|
|
12510
|
-
submitTx,
|
|
12511
12591
|
sum,
|
|
12512
12592
|
summariseOrder,
|
|
12513
12593
|
summarizeActualLeverageRedemptions,
|
|
12514
12594
|
toAssetClassFromLucid,
|
|
12515
12595
|
toDataDerivedPythPrice,
|
|
12516
12596
|
toSystemParamsAsset,
|
|
12597
|
+
toSystemParamsInput,
|
|
12517
12598
|
treasuryCollect,
|
|
12518
12599
|
treasuryFeeTx,
|
|
12519
12600
|
treasuryMerge,
|