@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.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
- async function submitTx(lucid, tx) {
367
- const txHash = await tx.complete().then((t) => t.sign.withWallet().complete()).then((t) => t.submit());
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), {});
@@ -498,7 +521,15 @@ function computeEffectiveCdpState(now, cdpUtxoAssets, cdpContent, interestOracle
498
521
  collateralAmt
499
522
  };
500
523
  }
501
- function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpContent, interestOracleDatum) {
524
+ var defaultLoanAdjustments = {
525
+ collateralAdjustment: 0n,
526
+ debtAdjustment: 0n
527
+ };
528
+ function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpContent, interestOracleDatum, loanAdjustments) {
529
+ const adjustments = {
530
+ ...defaultLoanAdjustments,
531
+ ...loanAdjustments
532
+ };
502
533
  const cdpState = computeEffectiveCdpState(
503
534
  now,
504
535
  cdpUtxoAssets,
@@ -506,8 +537,11 @@ function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpConten
506
537
  interestOracleDatum
507
538
  );
508
539
  const ratio = rationalDiv(
509
- rationalFromInt(cdpState.collateralAmt),
510
- rationalMul(rationalFromInt(cdpState.mintedAmt), iassetPrice)
540
+ rationalFromInt(cdpState.collateralAmt + adjustments.collateralAdjustment),
541
+ rationalMul(
542
+ rationalFromInt(cdpState.mintedAmt + adjustments.debtAdjustment),
543
+ iassetPrice
544
+ )
511
545
  );
512
546
  return Number(ratio.numerator) * 100 / Number(ratio.denominator);
513
547
  }
@@ -7337,10 +7371,9 @@ async function oneShotMintTx(lucid, params) {
7337
7371
  policyId
7338
7372
  ];
7339
7373
  }
7340
- async function runOneShotMintTx(lucid, params) {
7374
+ async function runOneShotMintTx(lucid, params, submissionConfig) {
7341
7375
  const [tx, policyId] = await oneShotMintTx(lucid, params);
7342
- const txHash = await tx.complete().then((tx2) => tx2.sign.withWallet().complete()).then((tx2) => tx2.submit());
7343
- await lucid.awaitTx(txHash);
7376
+ await runAndAwaitTxBuilder(lucid, tx, submissionConfig);
7344
7377
  return policyId;
7345
7378
  }
7346
7379
 
@@ -9929,10 +9962,13 @@ var alwaysFailValidator = {
9929
9962
  };
9930
9963
 
9931
9964
  // src/utils/helper-txs.ts
9932
- async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
9933
- const scriptAddr = validatorToAddress3(network, alwaysFailValidator);
9934
- const txHash = await lucid.newTx().pay.ToAddressWithData(scriptAddr, void 0, {}, scriptRefValidator).complete().then((tx) => tx.sign.withWallet().complete()).then((tx) => tx.submit());
9935
- await lucid.awaitTx(txHash);
9965
+ async function runCreateScriptRefTx(lucid, scriptRefValidator, submissionConfig) {
9966
+ const scriptAddr = validatorToAddress3(
9967
+ lucid.config().network,
9968
+ alwaysFailValidator
9969
+ );
9970
+ const tx = lucid.newTx().pay.ToAddressWithData(scriptAddr, void 0, {}, scriptRefValidator);
9971
+ const txHash = await runAndAwaitTxBuilder(lucid, tx, submissionConfig);
9936
9972
  return { txHash, outputIndex: 0 };
9937
9973
  }
9938
9974
 
@@ -10010,24 +10046,6 @@ var mkIAssetValidatorFromSP = (params) => {
10010
10046
 
10011
10047
  // src/contracts/initialize/helpers.ts
10012
10048
  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
10049
  var DEFAULT_INIT_OPTIONS = {
10032
10050
  numCdpCreators: 2n,
10033
10051
  numCollectors: 2n,
@@ -10062,18 +10080,27 @@ var INIT_TOKEN_NAMES = {
10062
10080
  snapshotEpochToScaleToSum: "SNAPSHOT_EPOCH_TO_SCALE_TO_SUM",
10063
10081
  account: "SP_ACCOUNT"
10064
10082
  };
10065
- async function mintOneTimeToken(lucid, tokenName, amount) {
10083
+ async function mintOneTimeToken(lucid, tokenName, amount, submissionConfig) {
10066
10084
  const utxos = await lucid.wallet().getUtxos();
10067
- return await runOneShotMintTx(lucid, {
10068
- referenceOutRef: {
10069
- txHash: utxos[0].txHash,
10070
- outputIdx: BigInt(utxos[0].outputIndex)
10085
+ return await runOneShotMintTx(
10086
+ lucid,
10087
+ {
10088
+ referenceOutRef: {
10089
+ txHash: utxos[0].txHash,
10090
+ outputIdx: BigInt(utxos[0].outputIndex)
10091
+ },
10092
+ mintAmounts: [{ tokenName, amount }]
10071
10093
  },
10072
- mintAmounts: [{ tokenName, amount }]
10073
- });
10094
+ submissionConfig
10095
+ );
10074
10096
  }
10075
- async function mintOneTimeAsset(lucid, tokenName, amount) {
10076
- const policyId = await mintOneTimeToken(lucid, fromText11(tokenName), amount);
10097
+ async function mintOneTimeAsset(lucid, tokenName, amount, submissionConfig) {
10098
+ const policyId = await mintOneTimeToken(
10099
+ lucid,
10100
+ fromText11(tokenName),
10101
+ amount,
10102
+ submissionConfig
10103
+ );
10077
10104
  return {
10078
10105
  currencySymbol: fromHex16(policyId),
10079
10106
  tokenName: fromHex16(fromText11(tokenName))
@@ -10086,20 +10113,6 @@ function deriveAuthToken(parent, tokenName) {
10086
10113
  tokenName: fromHex16(fromText11(tokenName))
10087
10114
  };
10088
10115
  }
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
10116
  async function initCollector(lucid, collectorParams, numCollectors) {
10104
10117
  const tx = lucid.newTx();
10105
10118
  for (let i = 0; i < Number(numCollectors); i++) {
@@ -10114,7 +10127,7 @@ async function initCollector(lucid, collectorParams, numCollectors) {
10114
10127
  }
10115
10128
  );
10116
10129
  }
10117
- await submitTx(lucid, tx);
10130
+ await runAndAwaitTxBuilder(lucid, tx);
10118
10131
  }
10119
10132
  async function initInterestCollector(lucid, interestCollectionValHash, multisigUtxoNft, numInterestCollectors, interestCollectorUtxoLovelaces) {
10120
10133
  const [pkh, _] = await addrDetails(lucid);
@@ -10125,7 +10138,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
10125
10138
  }
10126
10139
  }
10127
10140
  };
10128
- await submitTx(
10141
+ await runAndAwaitTxBuilder(
10129
10142
  lucid,
10130
10143
  lucid.newTx().pay.ToContract(
10131
10144
  createScriptAddress(lucid.config().network, interestCollectionValHash),
@@ -10144,7 +10157,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
10144
10157
  mkLovelacesOf7(interestCollectorUtxoLovelaces)
10145
10158
  );
10146
10159
  }
10147
- await submitTx(lucid, interestCollectionUtxoDeploymentTx);
10160
+ await runAndAwaitTxBuilder(lucid, interestCollectionUtxoDeploymentTx);
10148
10161
  }
10149
10162
  async function initCDPCreator(lucid, cdpCreatorParams, numCdpCreators) {
10150
10163
  const tx = lucid.newTx();
@@ -10162,7 +10175,7 @@ async function initCDPCreator(lucid, cdpCreatorParams, numCdpCreators) {
10162
10175
  }
10163
10176
  );
10164
10177
  }
10165
- await submitTx(lucid, tx);
10178
+ await runAndAwaitTxBuilder(lucid, tx);
10166
10179
  }
10167
10180
  async function initTreasury(lucid, treasuryParams, daoAsset, indyAsset, treasuryIndyAmount, numTreasuryCollectors) {
10168
10181
  const treasuryAddr = createScriptAddress(
@@ -10184,7 +10197,7 @@ async function initTreasury(lucid, treasuryParams, daoAsset, indyAsset, treasury
10184
10197
  value: Data49.void()
10185
10198
  });
10186
10199
  }
10187
- await submitTx(lucid, tx);
10200
+ await runAndAwaitTxBuilder(lucid, tx);
10188
10201
  }
10189
10202
  async function initStakingManager(lucid, stakingParams) {
10190
10203
  const tx = lucid.newTx().pay.ToContract(
@@ -10203,7 +10216,7 @@ async function initStakingManager(lucid, stakingParams) {
10203
10216
  [stakingParams.stakingManagerNFT[0].unCurrencySymbol + fromText11(stakingParams.stakingManagerNFT[1].unTokenName)]: 1n
10204
10217
  }
10205
10218
  );
10206
- await submitTx(lucid, tx);
10219
+ await runAndAwaitTxBuilder(lucid, tx);
10207
10220
  }
10208
10221
  async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, pythConfig) {
10209
10222
  return match20(collateralAsset.priceOracle).returnType().with({ tag: "_indigo_oracle_nft" }, async (val) => {
@@ -10255,7 +10268,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10255
10268
  lucid,
10256
10269
  collateralAsset.interestOracle.tokenName
10257
10270
  );
10258
- await submitTx(lucid, startInterestOracleTx);
10271
+ await runAndAwaitTxBuilder(lucid, startInterestOracleTx);
10259
10272
  const priceInfo = await handleOracleForCollateralAsset(
10260
10273
  lucid,
10261
10274
  asset,
@@ -10288,7 +10301,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10288
10301
  },
10289
10302
  mkAssetsOf13(collateralAssetAuthToken, 1n)
10290
10303
  );
10291
- await submitTx(lucid, collateralAssetTx);
10304
+ await runAndAwaitTxBuilder(lucid, collateralAssetTx);
10292
10305
  collateralAssetInfos.push({
10293
10306
  collateralAsset: collateralAsset.collateralAsset,
10294
10307
  interestOracleNft,
@@ -10310,7 +10323,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10310
10323
  iasset: iassetName,
10311
10324
  stableswapValHash: fromHex16(stableswapValidatorHash)
10312
10325
  };
10313
- await submitTx(
10326
+ await runAndAwaitTxBuilder(
10314
10327
  lucid,
10315
10328
  lucid.newTx().pay.ToContract(
10316
10329
  createScriptAddress(
@@ -10347,7 +10360,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10347
10360
  },
10348
10361
  mkAssetsOf13(iassetToken, 1n)
10349
10362
  );
10350
- await submitTx(lucid, assetTx);
10363
+ await runAndAwaitTxBuilder(lucid, assetTx);
10351
10364
  const stabilityPoolDatum = {
10352
10365
  iasset: fromHex16(fromText11(asset.name)),
10353
10366
  state: initSpState,
@@ -10366,7 +10379,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
10366
10379
  },
10367
10380
  mkAssetsOf13(stabilityPoolToken, 1n)
10368
10381
  );
10369
- await submitTx(lucid, spTx);
10382
+ await runAndAwaitTxBuilder(lucid, spTx);
10370
10383
  return {
10371
10384
  iassetTokenNameAscii: asset.name,
10372
10385
  collateralAssets: collateralAssetInfos
@@ -10388,7 +10401,7 @@ async function initGovernance(lucid, governanceParams, govToken, initialAssets,
10388
10401
  { kind: "inline", value: serialiseGovDatum(datum) },
10389
10402
  mkAssetsOf13(govToken, 1n)
10390
10403
  );
10391
- await submitTx(lucid, tx);
10404
+ await runAndAwaitTxBuilder(lucid, tx);
10392
10405
  }
10393
10406
  async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
10394
10407
  const script = mkAuthTokenPolicy(asset, fromText11(tokenName));
@@ -10405,7 +10418,7 @@ async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
10405
10418
  },
10406
10419
  Data49.void()
10407
10420
  );
10408
- await submitTx(lucid, tx);
10421
+ await runAndAwaitTxBuilder(lucid, tx);
10409
10422
  }
10410
10423
 
10411
10424
  // src/contracts/initialize/actions.ts
@@ -10593,19 +10606,30 @@ async function initPyth(lucid) {
10593
10606
  alwaysSucceedValidator
10594
10607
  )
10595
10608
  );
10596
- await runAndAwaitTxBuilder(
10597
- lucid,
10598
- lucid.newTx().register.Stake(
10599
- credentialToRewardAddress3(lucid.config().network, {
10600
- hash: validatorToScriptHash4(alwaysSucceedValidator),
10601
- type: "Script"
10602
- })
10603
- )
10604
- );
10609
+ try {
10610
+ await runAndAwaitTxBuilder(
10611
+ lucid,
10612
+ lucid.newTx().register.Stake(
10613
+ credentialToRewardAddress3(lucid.config().network, {
10614
+ hash: validatorToScriptHash4(alwaysSucceedValidator),
10615
+ type: "Script"
10616
+ })
10617
+ )
10618
+ );
10619
+ } catch (error) {
10620
+ const message = error instanceof Error ? error.message : String(error);
10621
+ if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes("Trying to re-register some already known credentials.")) {
10622
+ throw error;
10623
+ }
10624
+ }
10605
10625
  return pythStateAsset;
10606
10626
  }
10607
10627
 
10608
10628
  // src/contracts/initialize/actions.ts
10629
+ function isAlreadyRegisteredError(error) {
10630
+ const message = error instanceof Error ? error.message : String(error);
10631
+ return message.includes("StakeKeyRegisteredDELEG") || message.includes("Trying to re-register some already known credentials.");
10632
+ }
10609
10633
  var DEFAULT_STAKING_CRED = {
10610
10634
  tag: "StakingHash",
10611
10635
  contents: {
@@ -10622,7 +10646,7 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
10622
10646
  fromSysParamsPythFeedParams(val.pythFeedParams)
10623
10647
  );
10624
10648
  const pythFeedValHash = validatorToScriptHash5(pythFeedValidator);
10625
- const pythFeedValScriptRef = await initScriptRef(
10649
+ const pythFeedValScriptRef = await runCreateScriptRefTx(
10626
10650
  lucid,
10627
10651
  pythFeedValidator
10628
10652
  );
@@ -10637,19 +10661,16 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
10637
10661
  )
10638
10662
  );
10639
10663
  } catch (error) {
10640
- const message = error instanceof Error ? error.message : String(error);
10641
- if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes(
10642
- "Trying to re-register some already known credentials."
10643
- )) {
10644
- throw error;
10645
- }
10664
+ if (!isAlreadyRegisteredError(error)) throw error;
10646
10665
  }
10647
10666
  const key = `${asset.name}/${toHex17(collateral.collateralAsset.currencySymbol)}.${toHex17(collateral.collateralAsset.tokenName)}`;
10648
10667
  return {
10649
10668
  [key]: {
10650
10669
  params: val.pythFeedParams,
10651
10670
  pythFeedValHash,
10652
- pythFeedValScriptRef: { input: pythFeedValScriptRef }
10671
+ pythFeedValScriptRef: {
10672
+ input: toSystemParamsInput(pythFeedValScriptRef)
10673
+ }
10653
10674
  }
10654
10675
  };
10655
10676
  }).otherwise(() => Promise.resolve({}));
@@ -10683,6 +10704,19 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
10683
10704
  const indyAsset = await mintOneTimeAsset(lucid, tn.indy, totalIndySupply);
10684
10705
  const daoAsset = await mintOneTimeAsset(lucid, tn.dao, 1n);
10685
10706
  const govNftAsset = await mintOneTimeAsset(lucid, tn.govNft, 1n);
10707
+ const cdpCreatorAsset = await mintOneTimeAsset(
10708
+ lucid,
10709
+ tn.cdpCreator,
10710
+ numCdpCreators
10711
+ );
10712
+ const cdpToken = deriveAuthToken(cdpCreatorAsset, tn.cdp);
10713
+ const stakingManagerAsset = await mintOneTimeAsset(
10714
+ lucid,
10715
+ tn.stakingManager,
10716
+ 1n
10717
+ );
10718
+ const multisigUtxoNft = await mintOneTimeAsset(lucid, tn.multisigUtxo, 1n);
10719
+ const stakingToken = deriveAuthToken(stakingManagerAsset, tn.staking);
10686
10720
  const pollToken = deriveAuthToken(govNftAsset, tn.pollManager);
10687
10721
  const upgradeToken = deriveAuthToken(pollToken, tn.upgrade);
10688
10722
  const iassetToken = deriveAuthToken(upgradeToken, tn.iasset);
@@ -10708,18 +10742,6 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
10708
10742
  const versionRegistryValHash = validatorToScriptHash5(
10709
10743
  versionRegistryValidator
10710
10744
  );
10711
- const cdpCreatorAsset = await mintOneTimeAsset(
10712
- lucid,
10713
- tn.cdpCreator,
10714
- numCdpCreators
10715
- );
10716
- const cdpToken = deriveAuthToken(cdpCreatorAsset, tn.cdp);
10717
- const stakingManagerAsset = await mintOneTimeAsset(
10718
- lucid,
10719
- tn.stakingManager,
10720
- 1n
10721
- );
10722
- const stakingToken = deriveAuthToken(stakingManagerAsset, tn.staking);
10723
10745
  const collectorParams = {
10724
10746
  stakingManagerNFT: toSystemParamsAsset(stakingManagerAsset),
10725
10747
  stakingToken: toSystemParamsAsset(stakingToken),
@@ -10785,7 +10807,6 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
10785
10807
  treasuryIndyAmount,
10786
10808
  numTreasuryUtxos
10787
10809
  );
10788
- const multisigUtxoNft = await mintOneTimeAsset(lucid, tn.multisigUtxo, 1n);
10789
10810
  const interestCollectionParams = {
10790
10811
  versionRecordNft: toSystemParamsAsset(versionRecordToken),
10791
10812
  multisigUtxoNft: toSystemParamsAsset(multisigUtxoNft),
@@ -10839,10 +10860,7 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
10839
10860
  lucid.newTx().register.Stake(cdpRedeemRewardAddr)
10840
10861
  );
10841
10862
  } catch (error) {
10842
- const message = error instanceof Error ? error.message : String(error);
10843
- if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes("Trying to re-register some already known credentials.")) {
10844
- throw error;
10845
- }
10863
+ if (!isAlreadyRegisteredError(error)) throw error;
10846
10864
  }
10847
10865
  const cdpParams = {
10848
10866
  cdpAuthToken: toSystemParamsAsset(cdpToken),
@@ -11092,97 +11110,155 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
11092
11110
  },
11093
11111
  scriptReferences: {
11094
11112
  interestCollectionValidatorRef: {
11095
- input: await initScriptRef(lucid, interestCollectionValidator)
11113
+ input: toSystemParamsInput(
11114
+ await runCreateScriptRefTx(lucid, interestCollectionValidator)
11115
+ )
11096
11116
  },
11097
11117
  robValidatorRef: {
11098
- input: await initScriptRef(lucid, robValidator)
11118
+ input: toSystemParamsInput(
11119
+ await runCreateScriptRefTx(lucid, robValidator)
11120
+ )
11099
11121
  },
11100
11122
  cdpCreatorValidatorRef: {
11101
- input: await initScriptRef(lucid, cdpCreatorValidator)
11123
+ input: toSystemParamsInput(
11124
+ await runCreateScriptRefTx(lucid, cdpCreatorValidator)
11125
+ )
11102
11126
  },
11103
11127
  cdpValidatorRef: {
11104
- input: await initScriptRef(lucid, cdpValidator)
11128
+ input: toSystemParamsInput(
11129
+ await runCreateScriptRefTx(lucid, cdpValidator)
11130
+ )
11105
11131
  },
11106
11132
  cdpRedeemValidatorRef: {
11107
- input: await initScriptRef(lucid, cdpRedeemValidator)
11133
+ input: toSystemParamsInput(
11134
+ await runCreateScriptRefTx(lucid, cdpRedeemValidator)
11135
+ )
11108
11136
  },
11109
11137
  collectorValidatorRef: {
11110
- input: await initScriptRef(lucid, collectorValidator)
11138
+ input: toSystemParamsInput(
11139
+ await runCreateScriptRefTx(lucid, collectorValidator)
11140
+ )
11111
11141
  },
11112
11142
  executeValidatorRef: {
11113
- input: await initScriptRef(lucid, executeValidator)
11143
+ input: toSystemParamsInput(
11144
+ await runCreateScriptRefTx(lucid, executeValidator)
11145
+ )
11114
11146
  },
11115
11147
  pollShardValidatorRef: {
11116
- input: await initScriptRef(lucid, pollShardValidator)
11148
+ input: toSystemParamsInput(
11149
+ await runCreateScriptRefTx(lucid, pollShardValidator)
11150
+ )
11117
11151
  },
11118
11152
  pollManagerValidatorRef: {
11119
- input: await initScriptRef(lucid, pollManagerValidator)
11153
+ input: toSystemParamsInput(
11154
+ await runCreateScriptRefTx(lucid, pollManagerValidator)
11155
+ )
11120
11156
  },
11121
11157
  iAssetTokenPolicyRef: {
11122
- input: await initScriptRef(lucid, assetSymbolPolicy)
11158
+ input: toSystemParamsInput(
11159
+ await runCreateScriptRefTx(lucid, assetSymbolPolicy)
11160
+ )
11123
11161
  },
11124
11162
  stakingValidatorRef: {
11125
- input: await initScriptRef(
11126
- lucid,
11127
- mkStakingValidatorFromSP(stakingParams)
11163
+ input: toSystemParamsInput(
11164
+ await runCreateScriptRefTx(
11165
+ lucid,
11166
+ mkStakingValidatorFromSP(stakingParams)
11167
+ )
11128
11168
  )
11129
11169
  },
11130
11170
  stabilityPoolValidatorRef: {
11131
- input: await initScriptRef(lucid, stabilityPoolValidator)
11171
+ input: toSystemParamsInput(
11172
+ await runCreateScriptRefTx(lucid, stabilityPoolValidator)
11173
+ )
11132
11174
  },
11133
11175
  stableswapValidatorRef: {
11134
- input: await initScriptRef(lucid, stableswapValidator)
11176
+ input: toSystemParamsInput(
11177
+ await runCreateScriptRefTx(lucid, stableswapValidator)
11178
+ )
11135
11179
  },
11136
11180
  treasuryValidatorRef: {
11137
- input: await initScriptRef(lucid, treasuryValidator)
11181
+ input: toSystemParamsInput(
11182
+ await runCreateScriptRefTx(lucid, treasuryValidator)
11183
+ )
11138
11184
  },
11139
11185
  governanceValidatorRef: {
11140
- input: await initScriptRef(lucid, govValidator)
11186
+ input: toSystemParamsInput(
11187
+ await runCreateScriptRefTx(lucid, govValidator)
11188
+ )
11141
11189
  },
11142
11190
  versionRegistryValidatorRef: {
11143
- input: await initScriptRef(lucid, versionRegistryValidator)
11191
+ input: toSystemParamsInput(
11192
+ await runCreateScriptRefTx(lucid, versionRegistryValidator)
11193
+ )
11144
11194
  },
11145
11195
  iassetValidatorRef: {
11146
- input: await initScriptRef(lucid, iassetValidator)
11196
+ input: toSystemParamsInput(
11197
+ await runCreateScriptRefTx(lucid, iassetValidator)
11198
+ )
11147
11199
  },
11148
11200
  authTokenPolicies: {
11149
11201
  cdpAuthTokenRef: {
11150
- input: await initScriptRef(lucid, cdpTokenPolicy)
11202
+ input: toSystemParamsInput(
11203
+ await runCreateScriptRefTx(lucid, cdpTokenPolicy)
11204
+ )
11151
11205
  },
11152
11206
  iAssetAuthTokenRef: {
11153
- input: await initScriptRef(lucid, iassetTokenPolicy)
11207
+ input: toSystemParamsInput(
11208
+ await runCreateScriptRefTx(lucid, iassetTokenPolicy)
11209
+ )
11154
11210
  },
11155
11211
  accountTokenRef: {
11156
- input: await initScriptRef(lucid, accountTokenPolicy)
11212
+ input: toSystemParamsInput(
11213
+ await runCreateScriptRefTx(lucid, accountTokenPolicy)
11214
+ )
11157
11215
  },
11158
11216
  stabilityPoolAuthTokenRef: {
11159
- input: await initScriptRef(lucid, stabilityPoolTokenPolicy)
11217
+ input: toSystemParamsInput(
11218
+ await runCreateScriptRefTx(lucid, stabilityPoolTokenPolicy)
11219
+ )
11160
11220
  },
11161
11221
  pollManagerTokenRef: {
11162
- input: await initScriptRef(lucid, pollTokenPolicy)
11222
+ input: toSystemParamsInput(
11223
+ await runCreateScriptRefTx(lucid, pollTokenPolicy)
11224
+ )
11163
11225
  },
11164
11226
  stakingTokenRef: {
11165
- input: await initScriptRef(lucid, stakingTokenPolicy)
11227
+ input: toSystemParamsInput(
11228
+ await runCreateScriptRefTx(lucid, stakingTokenPolicy)
11229
+ )
11166
11230
  },
11167
11231
  versionRecordTokenPolicyRef: {
11168
- input: await initScriptRef(lucid, versionRecordTokenPolicy)
11232
+ input: toSystemParamsInput(
11233
+ await runCreateScriptRefTx(lucid, versionRecordTokenPolicy)
11234
+ )
11169
11235
  },
11170
11236
  iAssetTokenRef: {
11171
- input: await initScriptRef(lucid, assetSymbolPolicy)
11237
+ input: toSystemParamsInput(
11238
+ await runCreateScriptRefTx(lucid, assetSymbolPolicy)
11239
+ )
11172
11240
  },
11173
11241
  collateralAssetTokenRef: {
11174
- input: await initScriptRef(lucid, collateralAssetAuthTokenPolicy)
11242
+ input: toSystemParamsInput(
11243
+ await runCreateScriptRefTx(lucid, collateralAssetAuthTokenPolicy)
11244
+ )
11175
11245
  },
11176
11246
  upgradeTokenRef: {
11177
- input: await initScriptRef(lucid, upgradeTokenPolicy)
11247
+ input: toSystemParamsInput(
11248
+ await runCreateScriptRefTx(lucid, upgradeTokenPolicy)
11249
+ )
11178
11250
  },
11179
11251
  stabilityPoolTokenRef: {
11180
- input: await initScriptRef(lucid, stabilityPoolTokenPolicy)
11252
+ input: toSystemParamsInput(
11253
+ await runCreateScriptRefTx(lucid, stabilityPoolTokenPolicy)
11254
+ )
11181
11255
  },
11182
11256
  snapshotEpochToScaleToSumTokenRef: {
11183
- input: await initScriptRef(
11184
- lucid,
11185
- snapshotEpochToScaleToSumTokenPolicy
11257
+ input: toSystemParamsInput(
11258
+ await runCreateScriptRefTx(
11259
+ lucid,
11260
+ snapshotEpochToScaleToSumTokenPolicy
11261
+ )
11186
11262
  )
11187
11263
  }
11188
11264
  }
@@ -11216,7 +11292,7 @@ import {
11216
11292
  isSameAssetClass as isSameAssetClass5,
11217
11293
  matchSingle as matchSingle6
11218
11294
  } from "@indigo-labs/cardano-offchain-common";
11219
- import { option as O21, array as A16, function as F25 } from "fp-ts";
11295
+ import { option as O20, array as A15, function as F24 } from "fp-ts";
11220
11296
  async function findIAsset(lucid, sysParams, iassetName) {
11221
11297
  const iassetUtxos = await lucid.utxosAtWithUnit(
11222
11298
  createScriptAddress(
@@ -11228,21 +11304,21 @@ async function findIAsset(lucid, sysParams, iassetName) {
11228
11304
  )
11229
11305
  );
11230
11306
  return matchSingle6(
11231
- F25.pipe(
11307
+ F24.pipe(
11232
11308
  iassetUtxos.map(
11233
- (utxo) => F25.pipe(
11234
- O21.fromNullable(utxo.datum),
11235
- O21.flatMap(parseIAssetDatum),
11236
- O21.flatMap((datum) => {
11309
+ (utxo) => F24.pipe(
11310
+ O20.fromNullable(utxo.datum),
11311
+ O20.flatMap(parseIAssetDatum),
11312
+ O20.flatMap((datum) => {
11237
11313
  if (toHex18(datum.assetName) === toHex18(iassetName)) {
11238
- return O21.some({ utxo, datum });
11314
+ return O20.some({ utxo, datum });
11239
11315
  } else {
11240
- return O21.none;
11316
+ return O20.none;
11241
11317
  }
11242
11318
  })
11243
11319
  )
11244
11320
  ),
11245
- A16.compact
11321
+ A15.compact
11246
11322
  ),
11247
11323
  (res) => new Error("Expected a single IAsset UTXO.: " + JSON.stringify(res))
11248
11324
  );
@@ -11258,21 +11334,21 @@ async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset
11258
11334
  )
11259
11335
  );
11260
11336
  return matchSingle6(
11261
- F25.pipe(
11337
+ F24.pipe(
11262
11338
  collateralAssetUtxos.map(
11263
- (utxo) => F25.pipe(
11264
- O21.fromNullable(utxo.datum),
11265
- O21.flatMap(parseCollateralAssetDatum),
11266
- O21.flatMap((datum) => {
11339
+ (utxo) => F24.pipe(
11340
+ O20.fromNullable(utxo.datum),
11341
+ O20.flatMap(parseCollateralAssetDatum),
11342
+ O20.flatMap((datum) => {
11267
11343
  if (isSameAssetClass5(datum.collateralAsset, collateralAsset) && toHex18(iassetName) === toHex18(datum.iasset)) {
11268
- return O21.some({ utxo, datum });
11344
+ return O20.some({ utxo, datum });
11269
11345
  } else {
11270
- return O21.none;
11346
+ return O20.none;
11271
11347
  }
11272
11348
  })
11273
11349
  )
11274
11350
  ),
11275
- A16.compact
11351
+ A15.compact
11276
11352
  ),
11277
11353
  (res) => new Error(
11278
11354
  "Expected a single Collateral Asset UTXO.: " + JSON.stringify(res)
@@ -11286,7 +11362,7 @@ import {
11286
11362
  fromText as fromText14,
11287
11363
  toHex as toHex19
11288
11364
  } from "@lucid-evolution/lucid";
11289
- import { array as A17, ord as Ord5, function as F27 } from "fp-ts";
11365
+ import { array as A16, ord as Ord5, function as F26 } from "fp-ts";
11290
11366
 
11291
11367
  // src/contracts/stableswap/types-new.ts
11292
11368
  import {
@@ -11295,7 +11371,7 @@ import {
11295
11371
  OutputReferenceSchema as OutputReferenceSchema7
11296
11372
  } from "@indigo-labs/cardano-offchain-common";
11297
11373
  import { TSchema as TSchema20, Data as Data51 } from "@evolution-sdk/evolution";
11298
- import { option as O22, function as F26 } from "fp-ts";
11374
+ import { option as O21, function as F25 } from "fp-ts";
11299
11375
  import { Schema as Schema4 } from "effect";
11300
11376
  var OpaqueData4 = Schema4.typeSchema(Data51.DataSchema);
11301
11377
  var StableswapOrderDatumSchema = TSchema20.Struct({
@@ -11337,22 +11413,22 @@ function serialiseStableswapOrderDatum(d) {
11337
11413
  }
11338
11414
  function parseStableswapOrderDatum(datum) {
11339
11415
  try {
11340
- return O22.some(
11416
+ return O21.some(
11341
11417
  Data51.withSchema(
11342
11418
  StableswapOrderDatumSchema,
11343
11419
  DEFAULT_SCHEMA_OPTIONS
11344
11420
  ).fromCBORHex(datum)
11345
11421
  );
11346
11422
  } catch (_) {
11347
- return O22.none;
11423
+ return O21.none;
11348
11424
  }
11349
11425
  }
11350
11426
  function parseStableswapOrderDatumOrThrow(datum) {
11351
- return F26.pipe(
11427
+ return F25.pipe(
11352
11428
  parseStableswapOrderDatum(datum),
11353
- O22.match(() => {
11429
+ O21.match(() => {
11354
11430
  throw new Error("Expected a Stableswap Order datum.");
11355
- }, F26.identity)
11431
+ }, F25.identity)
11356
11432
  );
11357
11433
  }
11358
11434
  function serialiseStableswapOutputDatum(d) {
@@ -11369,22 +11445,22 @@ function serialiseStableswapOrderRedeemer(r) {
11369
11445
  }
11370
11446
  function parseStableswapOrderRedeemer(redeemerCborHex) {
11371
11447
  try {
11372
- return O22.some(
11448
+ return O21.some(
11373
11449
  Data51.withSchema(
11374
11450
  StableswapOrderRedeemerSchema,
11375
11451
  DEFAULT_SCHEMA_OPTIONS
11376
11452
  ).fromCBORHex(redeemerCborHex)
11377
11453
  );
11378
11454
  } catch (_) {
11379
- return O22.none;
11455
+ return O21.none;
11380
11456
  }
11381
11457
  }
11382
11458
  function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
11383
- return F26.pipe(
11459
+ return F25.pipe(
11384
11460
  parseStableswapOrderRedeemer(redeemerCborHex),
11385
- O22.match(() => {
11461
+ O21.match(() => {
11386
11462
  throw new Error("Expected a Stableswap Order redeemer.");
11387
- }, F26.identity)
11463
+ }, F25.identity)
11388
11464
  );
11389
11465
  }
11390
11466
 
@@ -11644,15 +11720,15 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
11644
11720
  return [];
11645
11721
  }
11646
11722
  });
11647
- const { left: mintingOrders, right: redeemingOrdersSortedDesc } = F27.pipe(
11723
+ const { left: mintingOrders, right: redeemingOrdersSortedDesc } = F26.pipe(
11648
11724
  validOrders,
11649
- A17.partition((o) => o.orderType === "REDEEMING"),
11725
+ A16.partition((o) => o.orderType === "REDEEMING"),
11650
11726
  ({ left, right }) => ({
11651
11727
  left,
11652
11728
  // Sort the redeeming orders descending.
11653
- right: F27.pipe(
11729
+ right: F26.pipe(
11654
11730
  right,
11655
- A17.sort(
11731
+ A16.sort(
11656
11732
  Ord5.contramap(
11657
11733
  (o) => o.swapInfo.owedCollateralAsset
11658
11734
  )(Ord5.reverse(BigIntOrd))
@@ -11660,9 +11736,9 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
11660
11736
  )
11661
11737
  })
11662
11738
  );
11663
- const totalCollateralDiff = F27.pipe(
11739
+ const totalCollateralDiff = F26.pipe(
11664
11740
  validOrders,
11665
- A17.reduce(
11741
+ A16.reduce(
11666
11742
  0n,
11667
11743
  (acc, order) => acc + order.swapInfo.suppliedCollateralAsset - order.swapInfo.owedCollateralAsset
11668
11744
  )
@@ -11670,13 +11746,13 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
11670
11746
  if (psmAvailableLiq + totalCollateralDiff >= 0n) {
11671
11747
  return validOrders.map((o) => o.order);
11672
11748
  }
11673
- const collateralFromMinting = F27.pipe(
11749
+ const collateralFromMinting = F26.pipe(
11674
11750
  mintingOrders,
11675
- A17.reduce(0n, (acc, o) => acc + o.swapInfo.suppliedCollateralAsset)
11751
+ A16.reduce(0n, (acc, o) => acc + o.swapInfo.suppliedCollateralAsset)
11676
11752
  );
11677
- const { selected } = F27.pipe(
11753
+ const { selected } = F26.pipe(
11678
11754
  redeemingOrdersSortedDesc,
11679
- A17.reduce(
11755
+ A16.reduce(
11680
11756
  {
11681
11757
  intermediateCollateralAmt: psmAvailableLiq + collateralFromMinting,
11682
11758
  selected: []
@@ -11697,7 +11773,7 @@ import {
11697
11773
  isSameAssetClass as isSameAssetClass6,
11698
11774
  matchSingle as matchSingle7
11699
11775
  } from "@indigo-labs/cardano-offchain-common";
11700
- import { array as A18, function as F28, option as O23 } from "fp-ts";
11776
+ import { array as A17, function as F27, option as O22 } from "fp-ts";
11701
11777
  async function findAllStableswapPools(lucid, sysParams) {
11702
11778
  const cdpUtxos = await lucid.utxosAtWithUnit(
11703
11779
  createScriptAddress(
@@ -11708,28 +11784,28 @@ async function findAllStableswapPools(lucid, sysParams) {
11708
11784
  fromSystemParamsAsset(sysParams.stableswapParams.cdpToken)
11709
11785
  )
11710
11786
  );
11711
- return F28.pipe(
11787
+ return F27.pipe(
11712
11788
  cdpUtxos.map(
11713
- (utxo) => F28.pipe(
11714
- O23.fromNullable(utxo.datum),
11715
- O23.flatMap(parseStableswapPoolDatum),
11716
- O23.map((datum) => ({ utxo, datum }))
11789
+ (utxo) => F27.pipe(
11790
+ O22.fromNullable(utxo.datum),
11791
+ O22.flatMap(parseStableswapPoolDatum),
11792
+ O22.map((datum) => ({ utxo, datum }))
11717
11793
  )
11718
11794
  ),
11719
- A18.compact
11795
+ A17.compact
11720
11796
  );
11721
11797
  }
11722
11798
  async function findStableswapPool(lucid, sysParams, iassetName, collateralAsset) {
11723
11799
  const stableswapPools = await findAllStableswapPools(lucid, sysParams);
11724
11800
  return matchSingle7(
11725
- F28.pipe(
11801
+ F27.pipe(
11726
11802
  stableswapPools.map((pool) => {
11727
11803
  if (toHex20(pool.datum.iasset) === iassetName && isSameAssetClass6(pool.datum.collateralAsset, collateralAsset)) {
11728
- return O23.some(pool);
11804
+ return O22.some(pool);
11729
11805
  }
11730
- return O23.none;
11806
+ return O22.none;
11731
11807
  }),
11732
- A18.compact
11808
+ A17.compact
11733
11809
  ),
11734
11810
  (res) => new Error(
11735
11811
  "Expected a single stableswap pool UTXO.: " + JSON.stringify(res)
@@ -11759,7 +11835,7 @@ import {
11759
11835
  isSameOutRef as isSameOutRef2,
11760
11836
  assetClassValueOf as assetClassValueOf13
11761
11837
  } from "@indigo-labs/cardano-offchain-common";
11762
- import { array as A19, function as F29 } from "fp-ts";
11838
+ import { array as A18, function as F28 } from "fp-ts";
11763
11839
  async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
11764
11840
  const myAddress = await lucid.wallet().address();
11765
11841
  const pkh = paymentCredentialOf3(myAddress);
@@ -11847,7 +11923,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11847
11923
  ]),
11848
11924
  (_) => new Error("Expected a single iasset token policy Ref Script UTXO")
11849
11925
  );
11850
- if (A19.isEmpty(stableswapOrderOrefs)) {
11926
+ if (A18.isEmpty(stableswapOrderOrefs)) {
11851
11927
  throw new Error("At least one order must be provided.");
11852
11928
  }
11853
11929
  const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
@@ -11894,9 +11970,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11894
11970
  return res.result;
11895
11971
  }
11896
11972
  );
11897
- const totalSwapInfo = F29.pipe(
11973
+ const totalSwapInfo = F28.pipe(
11898
11974
  ordersInfo,
11899
- A19.reduce(
11975
+ A18.reduce(
11900
11976
  {
11901
11977
  suppliedCollateralAsset: 0n,
11902
11978
  suppliedIasset: 0n,
@@ -11950,9 +12026,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
11950
12026
  if (amountToMint !== 0n) {
11951
12027
  tx.mintAssets(mkAssetsOf16(iassetAc, amountToMint), Data53.void());
11952
12028
  }
11953
- F29.pipe(
12029
+ F28.pipe(
11954
12030
  ordersInfo,
11955
- A19.reduce(tx, (acc, orderInfo) => {
12031
+ A18.reduce(tx, (acc, orderInfo) => {
11956
12032
  return acc.collectFrom(
11957
12033
  [orderInfo.order.utxo],
11958
12034
  isSameOutRef2(orderInfo.order.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
@@ -12243,7 +12319,6 @@ export {
12243
12319
  initGovernance,
12244
12320
  initInterestCollector,
12245
12321
  initPythConfig,
12246
- initScriptRef,
12247
12322
  initSpState,
12248
12323
  initStakingManager,
12249
12324
  initSumVal,
@@ -12380,6 +12455,7 @@ export {
12380
12455
  robCollateralAmtToSpend,
12381
12456
  robIAssetAmtToSpend,
12382
12457
  robSellOrderFilledAssets,
12458
+ runAndAwaitTxBuilder,
12383
12459
  runCreateScriptRefTx,
12384
12460
  runOneShotMintTx,
12385
12461
  scriptRef,
@@ -12425,13 +12501,13 @@ export {
12425
12501
  spZeroNegatives,
12426
12502
  startInterestOracle,
12427
12503
  startPriceOracleTx,
12428
- submitTx,
12429
12504
  sum,
12430
12505
  summariseOrder,
12431
12506
  summarizeActualLeverageRedemptions,
12432
12507
  toAssetClassFromLucid,
12433
12508
  toDataDerivedPythPrice,
12434
12509
  toSystemParamsAsset,
12510
+ toSystemParamsInput,
12435
12511
  treasuryCollect,
12436
12512
  treasuryFeeTx,
12437
12513
  treasuryMerge,