@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.mjs
CHANGED
|
@@ -279,6 +279,12 @@ function getPythFeedConfig(cfg, iasset, collateralAsset) {
|
|
|
279
279
|
throw new Error("No Pyth config known for such assets combination");
|
|
280
280
|
return res;
|
|
281
281
|
}
|
|
282
|
+
function toSystemParamsInput(outRef) {
|
|
283
|
+
return {
|
|
284
|
+
transactionId: outRef.txHash,
|
|
285
|
+
index: outRef.outputIndex
|
|
286
|
+
};
|
|
287
|
+
}
|
|
282
288
|
function toSystemParamsAsset(asset) {
|
|
283
289
|
return [
|
|
284
290
|
{ unCurrencySymbol: toHex(asset.currencySymbol) },
|
|
@@ -363,9 +369,26 @@ async function scriptRef(ref, lucid) {
|
|
|
363
369
|
if (utxos.length === 0) throw Error("Unable to locate script ref.");
|
|
364
370
|
return utxos[0];
|
|
365
371
|
}
|
|
366
|
-
|
|
367
|
-
|
|
372
|
+
var defaultSubmissionConfig = {
|
|
373
|
+
extraSigners: [],
|
|
374
|
+
useLocalOverride: true
|
|
375
|
+
};
|
|
376
|
+
async function runAndAwaitTxBuilder(lucid, transaction, submissionConfig) {
|
|
377
|
+
const config = {
|
|
378
|
+
...defaultSubmissionConfig,
|
|
379
|
+
...submissionConfig
|
|
380
|
+
};
|
|
381
|
+
const [newWalletUTxOs, _, bTx] = await transaction.chain();
|
|
382
|
+
const signatures = [await bTx.partialSign.withWallet()];
|
|
383
|
+
for (const signer of config.extraSigners) {
|
|
384
|
+
lucid.selectWallet.fromSeed(signer);
|
|
385
|
+
signatures.push(await lucid.fromTx(bTx.toCBOR()).partialSign.withWallet());
|
|
386
|
+
}
|
|
387
|
+
const signedTx = bTx.assemble(signatures);
|
|
388
|
+
const txHash = await signedTx.complete().then((tx) => tx.submit());
|
|
368
389
|
await lucid.awaitTx(txHash);
|
|
390
|
+
lucid.overrideUTxOs(newWalletUTxOs);
|
|
391
|
+
return txHash;
|
|
369
392
|
}
|
|
370
393
|
function balance(utxos) {
|
|
371
394
|
return utxos.reduce((acc, utxo) => addAssets(acc, utxo.assets), {});
|
|
@@ -498,7 +521,15 @@ function computeEffectiveCdpState(now, cdpUtxoAssets, cdpContent, interestOracle
|
|
|
498
521
|
collateralAmt
|
|
499
522
|
};
|
|
500
523
|
}
|
|
501
|
-
|
|
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(
|
|
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
|
-
|
|
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,
|
|
9933
|
-
const scriptAddr = validatorToAddress3(
|
|
9934
|
-
|
|
9935
|
-
|
|
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(
|
|
10068
|
-
|
|
10069
|
-
|
|
10070
|
-
|
|
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
|
-
|
|
10073
|
-
|
|
10094
|
+
submissionConfig
|
|
10095
|
+
);
|
|
10074
10096
|
}
|
|
10075
|
-
async function mintOneTimeAsset(lucid, tokenName, amount) {
|
|
10076
|
-
const policyId = await mintOneTimeToken(
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
10421
|
+
await runAndAwaitTxBuilder(lucid, tx);
|
|
10409
10422
|
}
|
|
10410
10423
|
|
|
10411
10424
|
// src/contracts/initialize/actions.ts
|
|
@@ -10593,23 +10606,30 @@ async function initPyth(lucid) {
|
|
|
10593
10606
|
alwaysSucceedValidator
|
|
10594
10607
|
)
|
|
10595
10608
|
);
|
|
10596
|
-
|
|
10597
|
-
lucid.config().network,
|
|
10598
|
-
{ hash: validatorToScriptHash4(alwaysSucceedValidator), type: "Script" }
|
|
10599
|
-
);
|
|
10600
|
-
const { registered } = await lucid.rewardAccountAt(
|
|
10601
|
-
alwaysSucceedRewardAddress
|
|
10602
|
-
);
|
|
10603
|
-
if (!registered) {
|
|
10609
|
+
try {
|
|
10604
10610
|
await runAndAwaitTxBuilder(
|
|
10605
10611
|
lucid,
|
|
10606
|
-
lucid.newTx().register.Stake(
|
|
10612
|
+
lucid.newTx().register.Stake(
|
|
10613
|
+
credentialToRewardAddress3(lucid.config().network, {
|
|
10614
|
+
hash: validatorToScriptHash4(alwaysSucceedValidator),
|
|
10615
|
+
type: "Script"
|
|
10616
|
+
})
|
|
10617
|
+
)
|
|
10607
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
|
+
}
|
|
10608
10624
|
}
|
|
10609
10625
|
return pythStateAsset;
|
|
10610
10626
|
}
|
|
10611
10627
|
|
|
10612
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
|
+
}
|
|
10613
10633
|
var DEFAULT_STAKING_CRED = {
|
|
10614
10634
|
tag: "StakingHash",
|
|
10615
10635
|
contents: {
|
|
@@ -10626,29 +10646,31 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
|
|
|
10626
10646
|
fromSysParamsPythFeedParams(val.pythFeedParams)
|
|
10627
10647
|
);
|
|
10628
10648
|
const pythFeedValHash = validatorToScriptHash5(pythFeedValidator);
|
|
10629
|
-
const pythFeedValScriptRef = await
|
|
10649
|
+
const pythFeedValScriptRef = await runCreateScriptRefTx(
|
|
10630
10650
|
lucid,
|
|
10631
10651
|
pythFeedValidator
|
|
10632
10652
|
);
|
|
10633
|
-
|
|
10634
|
-
lucid.config().network,
|
|
10635
|
-
{ hash: validatorToScriptHash5(pythFeedValidator), type: "Script" }
|
|
10636
|
-
);
|
|
10637
|
-
const { registered } = await lucid.rewardAccountAt(
|
|
10638
|
-
pythFeedRewardAddress
|
|
10639
|
-
);
|
|
10640
|
-
if (!registered) {
|
|
10653
|
+
try {
|
|
10641
10654
|
await runAndAwaitTxBuilder(
|
|
10642
10655
|
lucid,
|
|
10643
|
-
lucid.newTx().register.Stake(
|
|
10656
|
+
lucid.newTx().register.Stake(
|
|
10657
|
+
credentialToRewardAddress4(lucid.config().network, {
|
|
10658
|
+
hash: validatorToScriptHash5(pythFeedValidator),
|
|
10659
|
+
type: "Script"
|
|
10660
|
+
})
|
|
10661
|
+
)
|
|
10644
10662
|
);
|
|
10663
|
+
} catch (error) {
|
|
10664
|
+
if (!isAlreadyRegisteredError(error)) throw error;
|
|
10645
10665
|
}
|
|
10646
10666
|
const key = `${asset.name}/${toHex17(collateral.collateralAsset.currencySymbol)}.${toHex17(collateral.collateralAsset.tokenName)}`;
|
|
10647
10667
|
return {
|
|
10648
10668
|
[key]: {
|
|
10649
10669
|
params: val.pythFeedParams,
|
|
10650
10670
|
pythFeedValHash,
|
|
10651
|
-
pythFeedValScriptRef: {
|
|
10671
|
+
pythFeedValScriptRef: {
|
|
10672
|
+
input: toSystemParamsInput(pythFeedValScriptRef)
|
|
10673
|
+
}
|
|
10652
10674
|
}
|
|
10653
10675
|
};
|
|
10654
10676
|
}).otherwise(() => Promise.resolve({}));
|
|
@@ -10682,6 +10704,19 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10682
10704
|
const indyAsset = await mintOneTimeAsset(lucid, tn.indy, totalIndySupply);
|
|
10683
10705
|
const daoAsset = await mintOneTimeAsset(lucid, tn.dao, 1n);
|
|
10684
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);
|
|
10685
10720
|
const pollToken = deriveAuthToken(govNftAsset, tn.pollManager);
|
|
10686
10721
|
const upgradeToken = deriveAuthToken(pollToken, tn.upgrade);
|
|
10687
10722
|
const iassetToken = deriveAuthToken(upgradeToken, tn.iasset);
|
|
@@ -10707,18 +10742,6 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10707
10742
|
const versionRegistryValHash = validatorToScriptHash5(
|
|
10708
10743
|
versionRegistryValidator
|
|
10709
10744
|
);
|
|
10710
|
-
const cdpCreatorAsset = await mintOneTimeAsset(
|
|
10711
|
-
lucid,
|
|
10712
|
-
tn.cdpCreator,
|
|
10713
|
-
numCdpCreators
|
|
10714
|
-
);
|
|
10715
|
-
const cdpToken = deriveAuthToken(cdpCreatorAsset, tn.cdp);
|
|
10716
|
-
const stakingManagerAsset = await mintOneTimeAsset(
|
|
10717
|
-
lucid,
|
|
10718
|
-
tn.stakingManager,
|
|
10719
|
-
1n
|
|
10720
|
-
);
|
|
10721
|
-
const stakingToken = deriveAuthToken(stakingManagerAsset, tn.staking);
|
|
10722
10745
|
const collectorParams = {
|
|
10723
10746
|
stakingManagerNFT: toSystemParamsAsset(stakingManagerAsset),
|
|
10724
10747
|
stakingToken: toSystemParamsAsset(stakingToken),
|
|
@@ -10784,7 +10807,6 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10784
10807
|
treasuryIndyAmount,
|
|
10785
10808
|
numTreasuryUtxos
|
|
10786
10809
|
);
|
|
10787
|
-
const multisigUtxoNft = await mintOneTimeAsset(lucid, tn.multisigUtxo, 1n);
|
|
10788
10810
|
const interestCollectionParams = {
|
|
10789
10811
|
versionRecordNft: toSystemParamsAsset(versionRecordToken),
|
|
10790
10812
|
multisigUtxoNft: toSystemParamsAsset(multisigUtxoNft),
|
|
@@ -10832,12 +10854,13 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
10832
10854
|
lucid.config().network,
|
|
10833
10855
|
scriptHashToCredential4(cdpRedeemValHash)
|
|
10834
10856
|
);
|
|
10835
|
-
|
|
10836
|
-
if (!cdpRedeemRegistered) {
|
|
10857
|
+
try {
|
|
10837
10858
|
await runAndAwaitTxBuilder(
|
|
10838
10859
|
lucid,
|
|
10839
10860
|
lucid.newTx().register.Stake(cdpRedeemRewardAddr)
|
|
10840
10861
|
);
|
|
10862
|
+
} catch (error) {
|
|
10863
|
+
if (!isAlreadyRegisteredError(error)) throw error;
|
|
10841
10864
|
}
|
|
10842
10865
|
const cdpParams = {
|
|
10843
10866
|
cdpAuthToken: toSystemParamsAsset(cdpToken),
|
|
@@ -11087,97 +11110,155 @@ async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], p
|
|
|
11087
11110
|
},
|
|
11088
11111
|
scriptReferences: {
|
|
11089
11112
|
interestCollectionValidatorRef: {
|
|
11090
|
-
input:
|
|
11113
|
+
input: toSystemParamsInput(
|
|
11114
|
+
await runCreateScriptRefTx(lucid, interestCollectionValidator)
|
|
11115
|
+
)
|
|
11091
11116
|
},
|
|
11092
11117
|
robValidatorRef: {
|
|
11093
|
-
input:
|
|
11118
|
+
input: toSystemParamsInput(
|
|
11119
|
+
await runCreateScriptRefTx(lucid, robValidator)
|
|
11120
|
+
)
|
|
11094
11121
|
},
|
|
11095
11122
|
cdpCreatorValidatorRef: {
|
|
11096
|
-
input:
|
|
11123
|
+
input: toSystemParamsInput(
|
|
11124
|
+
await runCreateScriptRefTx(lucid, cdpCreatorValidator)
|
|
11125
|
+
)
|
|
11097
11126
|
},
|
|
11098
11127
|
cdpValidatorRef: {
|
|
11099
|
-
input:
|
|
11128
|
+
input: toSystemParamsInput(
|
|
11129
|
+
await runCreateScriptRefTx(lucid, cdpValidator)
|
|
11130
|
+
)
|
|
11100
11131
|
},
|
|
11101
11132
|
cdpRedeemValidatorRef: {
|
|
11102
|
-
input:
|
|
11133
|
+
input: toSystemParamsInput(
|
|
11134
|
+
await runCreateScriptRefTx(lucid, cdpRedeemValidator)
|
|
11135
|
+
)
|
|
11103
11136
|
},
|
|
11104
11137
|
collectorValidatorRef: {
|
|
11105
|
-
input:
|
|
11138
|
+
input: toSystemParamsInput(
|
|
11139
|
+
await runCreateScriptRefTx(lucid, collectorValidator)
|
|
11140
|
+
)
|
|
11106
11141
|
},
|
|
11107
11142
|
executeValidatorRef: {
|
|
11108
|
-
input:
|
|
11143
|
+
input: toSystemParamsInput(
|
|
11144
|
+
await runCreateScriptRefTx(lucid, executeValidator)
|
|
11145
|
+
)
|
|
11109
11146
|
},
|
|
11110
11147
|
pollShardValidatorRef: {
|
|
11111
|
-
input:
|
|
11148
|
+
input: toSystemParamsInput(
|
|
11149
|
+
await runCreateScriptRefTx(lucid, pollShardValidator)
|
|
11150
|
+
)
|
|
11112
11151
|
},
|
|
11113
11152
|
pollManagerValidatorRef: {
|
|
11114
|
-
input:
|
|
11153
|
+
input: toSystemParamsInput(
|
|
11154
|
+
await runCreateScriptRefTx(lucid, pollManagerValidator)
|
|
11155
|
+
)
|
|
11115
11156
|
},
|
|
11116
11157
|
iAssetTokenPolicyRef: {
|
|
11117
|
-
input:
|
|
11158
|
+
input: toSystemParamsInput(
|
|
11159
|
+
await runCreateScriptRefTx(lucid, assetSymbolPolicy)
|
|
11160
|
+
)
|
|
11118
11161
|
},
|
|
11119
11162
|
stakingValidatorRef: {
|
|
11120
|
-
input:
|
|
11121
|
-
|
|
11122
|
-
|
|
11163
|
+
input: toSystemParamsInput(
|
|
11164
|
+
await runCreateScriptRefTx(
|
|
11165
|
+
lucid,
|
|
11166
|
+
mkStakingValidatorFromSP(stakingParams)
|
|
11167
|
+
)
|
|
11123
11168
|
)
|
|
11124
11169
|
},
|
|
11125
11170
|
stabilityPoolValidatorRef: {
|
|
11126
|
-
input:
|
|
11171
|
+
input: toSystemParamsInput(
|
|
11172
|
+
await runCreateScriptRefTx(lucid, stabilityPoolValidator)
|
|
11173
|
+
)
|
|
11127
11174
|
},
|
|
11128
11175
|
stableswapValidatorRef: {
|
|
11129
|
-
input:
|
|
11176
|
+
input: toSystemParamsInput(
|
|
11177
|
+
await runCreateScriptRefTx(lucid, stableswapValidator)
|
|
11178
|
+
)
|
|
11130
11179
|
},
|
|
11131
11180
|
treasuryValidatorRef: {
|
|
11132
|
-
input:
|
|
11181
|
+
input: toSystemParamsInput(
|
|
11182
|
+
await runCreateScriptRefTx(lucid, treasuryValidator)
|
|
11183
|
+
)
|
|
11133
11184
|
},
|
|
11134
11185
|
governanceValidatorRef: {
|
|
11135
|
-
input:
|
|
11186
|
+
input: toSystemParamsInput(
|
|
11187
|
+
await runCreateScriptRefTx(lucid, govValidator)
|
|
11188
|
+
)
|
|
11136
11189
|
},
|
|
11137
11190
|
versionRegistryValidatorRef: {
|
|
11138
|
-
input:
|
|
11191
|
+
input: toSystemParamsInput(
|
|
11192
|
+
await runCreateScriptRefTx(lucid, versionRegistryValidator)
|
|
11193
|
+
)
|
|
11139
11194
|
},
|
|
11140
11195
|
iassetValidatorRef: {
|
|
11141
|
-
input:
|
|
11196
|
+
input: toSystemParamsInput(
|
|
11197
|
+
await runCreateScriptRefTx(lucid, iassetValidator)
|
|
11198
|
+
)
|
|
11142
11199
|
},
|
|
11143
11200
|
authTokenPolicies: {
|
|
11144
11201
|
cdpAuthTokenRef: {
|
|
11145
|
-
input:
|
|
11202
|
+
input: toSystemParamsInput(
|
|
11203
|
+
await runCreateScriptRefTx(lucid, cdpTokenPolicy)
|
|
11204
|
+
)
|
|
11146
11205
|
},
|
|
11147
11206
|
iAssetAuthTokenRef: {
|
|
11148
|
-
input:
|
|
11207
|
+
input: toSystemParamsInput(
|
|
11208
|
+
await runCreateScriptRefTx(lucid, iassetTokenPolicy)
|
|
11209
|
+
)
|
|
11149
11210
|
},
|
|
11150
11211
|
accountTokenRef: {
|
|
11151
|
-
input:
|
|
11212
|
+
input: toSystemParamsInput(
|
|
11213
|
+
await runCreateScriptRefTx(lucid, accountTokenPolicy)
|
|
11214
|
+
)
|
|
11152
11215
|
},
|
|
11153
11216
|
stabilityPoolAuthTokenRef: {
|
|
11154
|
-
input:
|
|
11217
|
+
input: toSystemParamsInput(
|
|
11218
|
+
await runCreateScriptRefTx(lucid, stabilityPoolTokenPolicy)
|
|
11219
|
+
)
|
|
11155
11220
|
},
|
|
11156
11221
|
pollManagerTokenRef: {
|
|
11157
|
-
input:
|
|
11222
|
+
input: toSystemParamsInput(
|
|
11223
|
+
await runCreateScriptRefTx(lucid, pollTokenPolicy)
|
|
11224
|
+
)
|
|
11158
11225
|
},
|
|
11159
11226
|
stakingTokenRef: {
|
|
11160
|
-
input:
|
|
11227
|
+
input: toSystemParamsInput(
|
|
11228
|
+
await runCreateScriptRefTx(lucid, stakingTokenPolicy)
|
|
11229
|
+
)
|
|
11161
11230
|
},
|
|
11162
11231
|
versionRecordTokenPolicyRef: {
|
|
11163
|
-
input:
|
|
11232
|
+
input: toSystemParamsInput(
|
|
11233
|
+
await runCreateScriptRefTx(lucid, versionRecordTokenPolicy)
|
|
11234
|
+
)
|
|
11164
11235
|
},
|
|
11165
11236
|
iAssetTokenRef: {
|
|
11166
|
-
input:
|
|
11237
|
+
input: toSystemParamsInput(
|
|
11238
|
+
await runCreateScriptRefTx(lucid, assetSymbolPolicy)
|
|
11239
|
+
)
|
|
11167
11240
|
},
|
|
11168
11241
|
collateralAssetTokenRef: {
|
|
11169
|
-
input:
|
|
11242
|
+
input: toSystemParamsInput(
|
|
11243
|
+
await runCreateScriptRefTx(lucid, collateralAssetAuthTokenPolicy)
|
|
11244
|
+
)
|
|
11170
11245
|
},
|
|
11171
11246
|
upgradeTokenRef: {
|
|
11172
|
-
input:
|
|
11247
|
+
input: toSystemParamsInput(
|
|
11248
|
+
await runCreateScriptRefTx(lucid, upgradeTokenPolicy)
|
|
11249
|
+
)
|
|
11173
11250
|
},
|
|
11174
11251
|
stabilityPoolTokenRef: {
|
|
11175
|
-
input:
|
|
11252
|
+
input: toSystemParamsInput(
|
|
11253
|
+
await runCreateScriptRefTx(lucid, stabilityPoolTokenPolicy)
|
|
11254
|
+
)
|
|
11176
11255
|
},
|
|
11177
11256
|
snapshotEpochToScaleToSumTokenRef: {
|
|
11178
|
-
input:
|
|
11179
|
-
|
|
11180
|
-
|
|
11257
|
+
input: toSystemParamsInput(
|
|
11258
|
+
await runCreateScriptRefTx(
|
|
11259
|
+
lucid,
|
|
11260
|
+
snapshotEpochToScaleToSumTokenPolicy
|
|
11261
|
+
)
|
|
11181
11262
|
)
|
|
11182
11263
|
}
|
|
11183
11264
|
}
|
|
@@ -11211,7 +11292,7 @@ import {
|
|
|
11211
11292
|
isSameAssetClass as isSameAssetClass5,
|
|
11212
11293
|
matchSingle as matchSingle6
|
|
11213
11294
|
} from "@indigo-labs/cardano-offchain-common";
|
|
11214
|
-
import { option as
|
|
11295
|
+
import { option as O20, array as A15, function as F24 } from "fp-ts";
|
|
11215
11296
|
async function findIAsset(lucid, sysParams, iassetName) {
|
|
11216
11297
|
const iassetUtxos = await lucid.utxosAtWithUnit(
|
|
11217
11298
|
createScriptAddress(
|
|
@@ -11223,21 +11304,21 @@ async function findIAsset(lucid, sysParams, iassetName) {
|
|
|
11223
11304
|
)
|
|
11224
11305
|
);
|
|
11225
11306
|
return matchSingle6(
|
|
11226
|
-
|
|
11307
|
+
F24.pipe(
|
|
11227
11308
|
iassetUtxos.map(
|
|
11228
|
-
(utxo) =>
|
|
11229
|
-
|
|
11230
|
-
|
|
11231
|
-
|
|
11309
|
+
(utxo) => F24.pipe(
|
|
11310
|
+
O20.fromNullable(utxo.datum),
|
|
11311
|
+
O20.flatMap(parseIAssetDatum),
|
|
11312
|
+
O20.flatMap((datum) => {
|
|
11232
11313
|
if (toHex18(datum.assetName) === toHex18(iassetName)) {
|
|
11233
|
-
return
|
|
11314
|
+
return O20.some({ utxo, datum });
|
|
11234
11315
|
} else {
|
|
11235
|
-
return
|
|
11316
|
+
return O20.none;
|
|
11236
11317
|
}
|
|
11237
11318
|
})
|
|
11238
11319
|
)
|
|
11239
11320
|
),
|
|
11240
|
-
|
|
11321
|
+
A15.compact
|
|
11241
11322
|
),
|
|
11242
11323
|
(res) => new Error("Expected a single IAsset UTXO.: " + JSON.stringify(res))
|
|
11243
11324
|
);
|
|
@@ -11253,21 +11334,21 @@ async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset
|
|
|
11253
11334
|
)
|
|
11254
11335
|
);
|
|
11255
11336
|
return matchSingle6(
|
|
11256
|
-
|
|
11337
|
+
F24.pipe(
|
|
11257
11338
|
collateralAssetUtxos.map(
|
|
11258
|
-
(utxo) =>
|
|
11259
|
-
|
|
11260
|
-
|
|
11261
|
-
|
|
11339
|
+
(utxo) => F24.pipe(
|
|
11340
|
+
O20.fromNullable(utxo.datum),
|
|
11341
|
+
O20.flatMap(parseCollateralAssetDatum),
|
|
11342
|
+
O20.flatMap((datum) => {
|
|
11262
11343
|
if (isSameAssetClass5(datum.collateralAsset, collateralAsset) && toHex18(iassetName) === toHex18(datum.iasset)) {
|
|
11263
|
-
return
|
|
11344
|
+
return O20.some({ utxo, datum });
|
|
11264
11345
|
} else {
|
|
11265
|
-
return
|
|
11346
|
+
return O20.none;
|
|
11266
11347
|
}
|
|
11267
11348
|
})
|
|
11268
11349
|
)
|
|
11269
11350
|
),
|
|
11270
|
-
|
|
11351
|
+
A15.compact
|
|
11271
11352
|
),
|
|
11272
11353
|
(res) => new Error(
|
|
11273
11354
|
"Expected a single Collateral Asset UTXO.: " + JSON.stringify(res)
|
|
@@ -11281,7 +11362,7 @@ import {
|
|
|
11281
11362
|
fromText as fromText14,
|
|
11282
11363
|
toHex as toHex19
|
|
11283
11364
|
} from "@lucid-evolution/lucid";
|
|
11284
|
-
import { array as
|
|
11365
|
+
import { array as A16, ord as Ord5, function as F26 } from "fp-ts";
|
|
11285
11366
|
|
|
11286
11367
|
// src/contracts/stableswap/types-new.ts
|
|
11287
11368
|
import {
|
|
@@ -11290,7 +11371,7 @@ import {
|
|
|
11290
11371
|
OutputReferenceSchema as OutputReferenceSchema7
|
|
11291
11372
|
} from "@indigo-labs/cardano-offchain-common";
|
|
11292
11373
|
import { TSchema as TSchema20, Data as Data51 } from "@evolution-sdk/evolution";
|
|
11293
|
-
import { option as
|
|
11374
|
+
import { option as O21, function as F25 } from "fp-ts";
|
|
11294
11375
|
import { Schema as Schema4 } from "effect";
|
|
11295
11376
|
var OpaqueData4 = Schema4.typeSchema(Data51.DataSchema);
|
|
11296
11377
|
var StableswapOrderDatumSchema = TSchema20.Struct({
|
|
@@ -11332,22 +11413,22 @@ function serialiseStableswapOrderDatum(d) {
|
|
|
11332
11413
|
}
|
|
11333
11414
|
function parseStableswapOrderDatum(datum) {
|
|
11334
11415
|
try {
|
|
11335
|
-
return
|
|
11416
|
+
return O21.some(
|
|
11336
11417
|
Data51.withSchema(
|
|
11337
11418
|
StableswapOrderDatumSchema,
|
|
11338
11419
|
DEFAULT_SCHEMA_OPTIONS
|
|
11339
11420
|
).fromCBORHex(datum)
|
|
11340
11421
|
);
|
|
11341
11422
|
} catch (_) {
|
|
11342
|
-
return
|
|
11423
|
+
return O21.none;
|
|
11343
11424
|
}
|
|
11344
11425
|
}
|
|
11345
11426
|
function parseStableswapOrderDatumOrThrow(datum) {
|
|
11346
|
-
return
|
|
11427
|
+
return F25.pipe(
|
|
11347
11428
|
parseStableswapOrderDatum(datum),
|
|
11348
|
-
|
|
11429
|
+
O21.match(() => {
|
|
11349
11430
|
throw new Error("Expected a Stableswap Order datum.");
|
|
11350
|
-
},
|
|
11431
|
+
}, F25.identity)
|
|
11351
11432
|
);
|
|
11352
11433
|
}
|
|
11353
11434
|
function serialiseStableswapOutputDatum(d) {
|
|
@@ -11364,22 +11445,22 @@ function serialiseStableswapOrderRedeemer(r) {
|
|
|
11364
11445
|
}
|
|
11365
11446
|
function parseStableswapOrderRedeemer(redeemerCborHex) {
|
|
11366
11447
|
try {
|
|
11367
|
-
return
|
|
11448
|
+
return O21.some(
|
|
11368
11449
|
Data51.withSchema(
|
|
11369
11450
|
StableswapOrderRedeemerSchema,
|
|
11370
11451
|
DEFAULT_SCHEMA_OPTIONS
|
|
11371
11452
|
).fromCBORHex(redeemerCborHex)
|
|
11372
11453
|
);
|
|
11373
11454
|
} catch (_) {
|
|
11374
|
-
return
|
|
11455
|
+
return O21.none;
|
|
11375
11456
|
}
|
|
11376
11457
|
}
|
|
11377
11458
|
function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
|
|
11378
|
-
return
|
|
11459
|
+
return F25.pipe(
|
|
11379
11460
|
parseStableswapOrderRedeemer(redeemerCborHex),
|
|
11380
|
-
|
|
11461
|
+
O21.match(() => {
|
|
11381
11462
|
throw new Error("Expected a Stableswap Order redeemer.");
|
|
11382
|
-
},
|
|
11463
|
+
}, F25.identity)
|
|
11383
11464
|
);
|
|
11384
11465
|
}
|
|
11385
11466
|
|
|
@@ -11639,15 +11720,15 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
|
|
|
11639
11720
|
return [];
|
|
11640
11721
|
}
|
|
11641
11722
|
});
|
|
11642
|
-
const { left: mintingOrders, right: redeemingOrdersSortedDesc } =
|
|
11723
|
+
const { left: mintingOrders, right: redeemingOrdersSortedDesc } = F26.pipe(
|
|
11643
11724
|
validOrders,
|
|
11644
|
-
|
|
11725
|
+
A16.partition((o) => o.orderType === "REDEEMING"),
|
|
11645
11726
|
({ left, right }) => ({
|
|
11646
11727
|
left,
|
|
11647
11728
|
// Sort the redeeming orders descending.
|
|
11648
|
-
right:
|
|
11729
|
+
right: F26.pipe(
|
|
11649
11730
|
right,
|
|
11650
|
-
|
|
11731
|
+
A16.sort(
|
|
11651
11732
|
Ord5.contramap(
|
|
11652
11733
|
(o) => o.swapInfo.owedCollateralAsset
|
|
11653
11734
|
)(Ord5.reverse(BigIntOrd))
|
|
@@ -11655,9 +11736,9 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
|
|
|
11655
11736
|
)
|
|
11656
11737
|
})
|
|
11657
11738
|
);
|
|
11658
|
-
const totalCollateralDiff =
|
|
11739
|
+
const totalCollateralDiff = F26.pipe(
|
|
11659
11740
|
validOrders,
|
|
11660
|
-
|
|
11741
|
+
A16.reduce(
|
|
11661
11742
|
0n,
|
|
11662
11743
|
(acc, order) => acc + order.swapInfo.suppliedCollateralAsset - order.swapInfo.owedCollateralAsset
|
|
11663
11744
|
)
|
|
@@ -11665,13 +11746,13 @@ function pickValidSatisfiableOrders(lucid, orders, pool, sysParams, psmProcessin
|
|
|
11665
11746
|
if (psmAvailableLiq + totalCollateralDiff >= 0n) {
|
|
11666
11747
|
return validOrders.map((o) => o.order);
|
|
11667
11748
|
}
|
|
11668
|
-
const collateralFromMinting =
|
|
11749
|
+
const collateralFromMinting = F26.pipe(
|
|
11669
11750
|
mintingOrders,
|
|
11670
|
-
|
|
11751
|
+
A16.reduce(0n, (acc, o) => acc + o.swapInfo.suppliedCollateralAsset)
|
|
11671
11752
|
);
|
|
11672
|
-
const { selected } =
|
|
11753
|
+
const { selected } = F26.pipe(
|
|
11673
11754
|
redeemingOrdersSortedDesc,
|
|
11674
|
-
|
|
11755
|
+
A16.reduce(
|
|
11675
11756
|
{
|
|
11676
11757
|
intermediateCollateralAmt: psmAvailableLiq + collateralFromMinting,
|
|
11677
11758
|
selected: []
|
|
@@ -11692,7 +11773,7 @@ import {
|
|
|
11692
11773
|
isSameAssetClass as isSameAssetClass6,
|
|
11693
11774
|
matchSingle as matchSingle7
|
|
11694
11775
|
} from "@indigo-labs/cardano-offchain-common";
|
|
11695
|
-
import { array as
|
|
11776
|
+
import { array as A17, function as F27, option as O22 } from "fp-ts";
|
|
11696
11777
|
async function findAllStableswapPools(lucid, sysParams) {
|
|
11697
11778
|
const cdpUtxos = await lucid.utxosAtWithUnit(
|
|
11698
11779
|
createScriptAddress(
|
|
@@ -11703,28 +11784,28 @@ async function findAllStableswapPools(lucid, sysParams) {
|
|
|
11703
11784
|
fromSystemParamsAsset(sysParams.stableswapParams.cdpToken)
|
|
11704
11785
|
)
|
|
11705
11786
|
);
|
|
11706
|
-
return
|
|
11787
|
+
return F27.pipe(
|
|
11707
11788
|
cdpUtxos.map(
|
|
11708
|
-
(utxo) =>
|
|
11709
|
-
|
|
11710
|
-
|
|
11711
|
-
|
|
11789
|
+
(utxo) => F27.pipe(
|
|
11790
|
+
O22.fromNullable(utxo.datum),
|
|
11791
|
+
O22.flatMap(parseStableswapPoolDatum),
|
|
11792
|
+
O22.map((datum) => ({ utxo, datum }))
|
|
11712
11793
|
)
|
|
11713
11794
|
),
|
|
11714
|
-
|
|
11795
|
+
A17.compact
|
|
11715
11796
|
);
|
|
11716
11797
|
}
|
|
11717
11798
|
async function findStableswapPool(lucid, sysParams, iassetName, collateralAsset) {
|
|
11718
11799
|
const stableswapPools = await findAllStableswapPools(lucid, sysParams);
|
|
11719
11800
|
return matchSingle7(
|
|
11720
|
-
|
|
11801
|
+
F27.pipe(
|
|
11721
11802
|
stableswapPools.map((pool) => {
|
|
11722
11803
|
if (toHex20(pool.datum.iasset) === iassetName && isSameAssetClass6(pool.datum.collateralAsset, collateralAsset)) {
|
|
11723
|
-
return
|
|
11804
|
+
return O22.some(pool);
|
|
11724
11805
|
}
|
|
11725
|
-
return
|
|
11806
|
+
return O22.none;
|
|
11726
11807
|
}),
|
|
11727
|
-
|
|
11808
|
+
A17.compact
|
|
11728
11809
|
),
|
|
11729
11810
|
(res) => new Error(
|
|
11730
11811
|
"Expected a single stableswap pool UTXO.: " + JSON.stringify(res)
|
|
@@ -11754,7 +11835,7 @@ import {
|
|
|
11754
11835
|
isSameOutRef as isSameOutRef2,
|
|
11755
11836
|
assetClassValueOf as assetClassValueOf13
|
|
11756
11837
|
} from "@indigo-labs/cardano-offchain-common";
|
|
11757
|
-
import { array as
|
|
11838
|
+
import { array as A18, function as F28 } from "fp-ts";
|
|
11758
11839
|
async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
|
|
11759
11840
|
const myAddress = await lucid.wallet().address();
|
|
11760
11841
|
const pkh = paymentCredentialOf3(myAddress);
|
|
@@ -11842,7 +11923,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11842
11923
|
]),
|
|
11843
11924
|
(_) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
11844
11925
|
);
|
|
11845
|
-
if (
|
|
11926
|
+
if (A18.isEmpty(stableswapOrderOrefs)) {
|
|
11846
11927
|
throw new Error("At least one order must be provided.");
|
|
11847
11928
|
}
|
|
11848
11929
|
const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
|
|
@@ -11889,9 +11970,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11889
11970
|
return res.result;
|
|
11890
11971
|
}
|
|
11891
11972
|
);
|
|
11892
|
-
const totalSwapInfo =
|
|
11973
|
+
const totalSwapInfo = F28.pipe(
|
|
11893
11974
|
ordersInfo,
|
|
11894
|
-
|
|
11975
|
+
A18.reduce(
|
|
11895
11976
|
{
|
|
11896
11977
|
suppliedCollateralAsset: 0n,
|
|
11897
11978
|
suppliedIasset: 0n,
|
|
@@ -11945,9 +12026,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11945
12026
|
if (amountToMint !== 0n) {
|
|
11946
12027
|
tx.mintAssets(mkAssetsOf16(iassetAc, amountToMint), Data53.void());
|
|
11947
12028
|
}
|
|
11948
|
-
|
|
12029
|
+
F28.pipe(
|
|
11949
12030
|
ordersInfo,
|
|
11950
|
-
|
|
12031
|
+
A18.reduce(tx, (acc, orderInfo) => {
|
|
11951
12032
|
return acc.collectFrom(
|
|
11952
12033
|
[orderInfo.order.utxo],
|
|
11953
12034
|
isSameOutRef2(orderInfo.order.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
|
|
@@ -12238,7 +12319,6 @@ export {
|
|
|
12238
12319
|
initGovernance,
|
|
12239
12320
|
initInterestCollector,
|
|
12240
12321
|
initPythConfig,
|
|
12241
|
-
initScriptRef,
|
|
12242
12322
|
initSpState,
|
|
12243
12323
|
initStakingManager,
|
|
12244
12324
|
initSumVal,
|
|
@@ -12375,6 +12455,7 @@ export {
|
|
|
12375
12455
|
robCollateralAmtToSpend,
|
|
12376
12456
|
robIAssetAmtToSpend,
|
|
12377
12457
|
robSellOrderFilledAssets,
|
|
12458
|
+
runAndAwaitTxBuilder,
|
|
12378
12459
|
runCreateScriptRefTx,
|
|
12379
12460
|
runOneShotMintTx,
|
|
12380
12461
|
scriptRef,
|
|
@@ -12420,13 +12501,13 @@ export {
|
|
|
12420
12501
|
spZeroNegatives,
|
|
12421
12502
|
startInterestOracle,
|
|
12422
12503
|
startPriceOracleTx,
|
|
12423
|
-
submitTx,
|
|
12424
12504
|
sum,
|
|
12425
12505
|
summariseOrder,
|
|
12426
12506
|
summarizeActualLeverageRedemptions,
|
|
12427
12507
|
toAssetClassFromLucid,
|
|
12428
12508
|
toDataDerivedPythPrice,
|
|
12429
12509
|
toSystemParamsAsset,
|
|
12510
|
+
toSystemParamsInput,
|
|
12430
12511
|
treasuryCollect,
|
|
12431
12512
|
treasuryFeeTx,
|
|
12432
12513
|
treasuryMerge,
|