@indigo-labs/indigo-sdk 0.2.2 → 0.2.4
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 +163 -17
- package/dist/index.d.ts +163 -17
- package/dist/index.js +1122 -475
- package/dist/index.mjs +950 -314
- package/package.json +1 -1
- package/src/contracts/collector/transactions.ts +3 -3
- package/src/contracts/collector/types.ts +16 -0
- package/src/contracts/leverage/helpers.ts +424 -0
- package/src/contracts/leverage/transactions.ts +274 -0
- package/src/contracts/lrp/helpers.ts +290 -0
- package/src/contracts/lrp/transactions.ts +42 -104
- package/src/contracts/lrp/types.ts +19 -3
- package/src/contracts/staking/helpers.ts +11 -0
- package/src/contracts/staking/transactions.ts +94 -4
- package/src/index.ts +5 -2
- package/src/types/on-chain-decimal.ts +4 -0
- package/src/utils/array-utils.ts +39 -0
- package/src/utils/bigint-utils.ts +16 -0
- package/tests/array-utils.test.ts +92 -0
- package/tests/cdp.test.ts +83 -120
- package/tests/endpoints/initialize.ts +1 -1
- package/tests/lrp-leverage.test.ts +1495 -0
- package/tests/lrp.test.ts +436 -658
- package/tests/mock/assets-mock.ts +2 -2
- package/tests/queries/cdp-queries.ts +76 -0
- package/tests/queries/lrp-queries.ts +41 -4
- package/tests/staking.test.ts +71 -16
- package/tests/indigo-test-helpers.ts +0 -61
package/dist/index.js
CHANGED
|
@@ -56,6 +56,8 @@ __export(index_exports, {
|
|
|
56
56
|
LRPDatumSchema: () => LRPDatumSchema,
|
|
57
57
|
LRPParamsSchema: () => LRPParamsSchema,
|
|
58
58
|
LRPRedeemerSchema: () => LRPRedeemerSchema,
|
|
59
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN: () => MAX_REDEMPTIONS_WITH_CDP_OPEN,
|
|
60
|
+
MIN_LRP_COLLATERAL_AMT: () => MIN_LRP_COLLATERAL_AMT,
|
|
59
61
|
ONE_DAY: () => ONE_DAY,
|
|
60
62
|
ONE_HOUR: () => ONE_HOUR,
|
|
61
63
|
ONE_SECOND: () => ONE_SECOND,
|
|
@@ -86,12 +88,17 @@ __export(index_exports, {
|
|
|
86
88
|
adjustSpAccount: () => adjustSpAccount,
|
|
87
89
|
adjustStakingPosition: () => adjustStakingPosition,
|
|
88
90
|
adjustmentHelper: () => adjustmentHelper,
|
|
91
|
+
approximateLeverageRedemptions: () => approximateLeverageRedemptions,
|
|
89
92
|
assetClassToUnit: () => assetClassToUnit,
|
|
90
93
|
assetClassValueOf: () => assetClassValueOf,
|
|
91
94
|
balance: () => balance,
|
|
95
|
+
buildRedemptionsTx: () => buildRedemptionsTx,
|
|
92
96
|
burnCdp: () => burnCdp,
|
|
97
|
+
calculateCollateralRatioFromLeverage: () => calculateCollateralRatioFromLeverage,
|
|
93
98
|
calculateIAssetRedemptionAmt: () => calculateIAssetRedemptionAmt,
|
|
99
|
+
calculateLeverageFromCollateralRatio: () => calculateLeverageFromCollateralRatio,
|
|
94
100
|
calculateMinCollateralCappedIAssetRedemptionAmt: () => calculateMinCollateralCappedIAssetRedemptionAmt,
|
|
101
|
+
calculateTotalAdaForRedemption: () => calculateTotalAdaForRedemption,
|
|
95
102
|
cancelLrp: () => cancelLrp,
|
|
96
103
|
castCDPCreatorParams: () => castCDPCreatorParams,
|
|
97
104
|
castCdpParams: () => castCdpParams,
|
|
@@ -116,6 +123,7 @@ __export(index_exports, {
|
|
|
116
123
|
createShardsChunks: () => createShardsChunks,
|
|
117
124
|
createSpAccount: () => createSpAccount,
|
|
118
125
|
depositCdp: () => depositCdp,
|
|
126
|
+
distributeAda: () => distributeAda,
|
|
119
127
|
endProposal: () => endProposal,
|
|
120
128
|
executeProposal: () => executeProposal,
|
|
121
129
|
feedInterestOracle: () => feedInterestOracle,
|
|
@@ -131,12 +139,15 @@ __export(index_exports, {
|
|
|
131
139
|
getSumFromEpochToScaleToSum: () => getSumFromEpochToScaleToSum,
|
|
132
140
|
initEpochToScaleToSumMap: () => initEpochToScaleToSumMap,
|
|
133
141
|
initSpSnapshot: () => initSpSnapshot,
|
|
142
|
+
insertSorted: () => insertSorted,
|
|
134
143
|
isAssetsZero: () => isAssetsZero,
|
|
144
|
+
leverageCdpWithLrp: () => leverageCdpWithLrp,
|
|
135
145
|
liquidateCdp: () => liquidateCdp,
|
|
136
146
|
liquidationHelper: () => liquidationHelper,
|
|
137
147
|
loadSystemParamsFromFile: () => loadSystemParamsFromFile,
|
|
138
148
|
loadSystemParamsFromUrl: () => loadSystemParamsFromUrl,
|
|
139
149
|
lovelacesAmt: () => lovelacesAmt,
|
|
150
|
+
lrpRedeemableLovelacesInclReimb: () => lrpRedeemableLovelacesInclReimb,
|
|
140
151
|
matchSingle: () => matchSingle,
|
|
141
152
|
mergeCdps: () => mergeCdps,
|
|
142
153
|
mergeShards: () => mergeShards,
|
|
@@ -176,6 +187,7 @@ __export(index_exports, {
|
|
|
176
187
|
parseIAssetDatumOrThrow: () => parseIAssetDatumOrThrow,
|
|
177
188
|
parseInterestOracleDatum: () => parseInterestOracleDatum,
|
|
178
189
|
parseLrpDatum: () => parseLrpDatum,
|
|
190
|
+
parseLrpDatumOrThrow: () => parseLrpDatumOrThrow,
|
|
179
191
|
parsePriceOracleDatum: () => parsePriceOracleDatum,
|
|
180
192
|
parseSnapshotEpochToScaleToSumDatum: () => parseSnapshotEpochToScaleToSumDatum,
|
|
181
193
|
parseStabilityPoolDatum: () => parseStabilityPoolDatum,
|
|
@@ -183,6 +195,7 @@ __export(index_exports, {
|
|
|
183
195
|
parseStakingPosition: () => parseStakingPosition,
|
|
184
196
|
parseStakingPositionOrThrow: () => parseStakingPositionOrThrow,
|
|
185
197
|
processSpRequest: () => processSpRequest,
|
|
198
|
+
randomLrpsSubsetSatisfyingTargetLovelaces: () => randomLrpsSubsetSatisfyingTargetLovelaces,
|
|
186
199
|
redeemCdp: () => redeemCdp,
|
|
187
200
|
redeemLrp: () => redeemLrp,
|
|
188
201
|
runCreateScriptRefTx: () => runCreateScriptRefTx,
|
|
@@ -209,11 +222,13 @@ __export(index_exports, {
|
|
|
209
222
|
serialiseStakingDatum: () => serialiseStakingDatum,
|
|
210
223
|
serialiseStakingRedeemer: () => serialiseStakingRedeemer,
|
|
211
224
|
setSumInEpochToScaleToSum: () => setSumInEpochToScaleToSum,
|
|
225
|
+
shuffle: () => shuffle,
|
|
212
226
|
spAdd: () => spAdd,
|
|
213
227
|
spDiv: () => spDiv,
|
|
214
228
|
spMul: () => spMul,
|
|
215
229
|
spSub: () => spSub,
|
|
216
230
|
startInterestOracle: () => startInterestOracle,
|
|
231
|
+
summarizeActualLeverageRedemptions: () => summarizeActualLeverageRedemptions,
|
|
217
232
|
toSystemParamsAsset: () => toSystemParamsAsset,
|
|
218
233
|
treasuryFeeTx: () => treasuryFeeTx,
|
|
219
234
|
updatePoolSnapshotWithdrawalFee: () => updatePoolSnapshotWithdrawalFee,
|
|
@@ -223,7 +238,7 @@ __export(index_exports, {
|
|
|
223
238
|
module.exports = __toCommonJS(index_exports);
|
|
224
239
|
|
|
225
240
|
// src/contracts/cdp/transactions.ts
|
|
226
|
-
var
|
|
241
|
+
var import_lucid18 = require("@lucid-evolution/lucid");
|
|
227
242
|
|
|
228
243
|
// src/types/system-params.ts
|
|
229
244
|
var import_lucid = require("@lucid-evolution/lucid");
|
|
@@ -1012,12 +1027,23 @@ function calculateMinCollateralCappedIAssetRedemptionAmt(collateralAmt, mintedAm
|
|
|
1012
1027
|
}
|
|
1013
1028
|
|
|
1014
1029
|
// src/utils/bigint-utils.ts
|
|
1030
|
+
var import_fp_ts3 = require("fp-ts");
|
|
1015
1031
|
function bigintMax(a, b) {
|
|
1016
1032
|
return a > b ? a : b;
|
|
1017
1033
|
}
|
|
1018
1034
|
function bigintMin(a, b) {
|
|
1019
1035
|
return a < b ? a : b;
|
|
1020
1036
|
}
|
|
1037
|
+
function sum(arr) {
|
|
1038
|
+
return import_fp_ts3.array.reduce(0n, (acc, val) => acc + val)(arr);
|
|
1039
|
+
}
|
|
1040
|
+
function fromDecimal(val) {
|
|
1041
|
+
return BigInt(val.toString());
|
|
1042
|
+
}
|
|
1043
|
+
var BigIntOrd = {
|
|
1044
|
+
equals: (x, y) => x === y,
|
|
1045
|
+
compare: (first, second) => first < second ? -1 : first > second ? 1 : 0
|
|
1046
|
+
};
|
|
1021
1047
|
|
|
1022
1048
|
// src/contracts/stability-pool/types-new.ts
|
|
1023
1049
|
var import_evolution2 = require("@evolution-sdk/evolution");
|
|
@@ -1193,14 +1219,14 @@ function getSumFromEpochToScaleToSum(e2s2s, epoch, scale) {
|
|
|
1193
1219
|
}
|
|
1194
1220
|
return void 0;
|
|
1195
1221
|
}
|
|
1196
|
-
function setSumInEpochToScaleToSum(e2s2s, epoch, scale,
|
|
1222
|
+
function setSumInEpochToScaleToSum(e2s2s, epoch, scale, sum2) {
|
|
1197
1223
|
const map = /* @__PURE__ */ new Map();
|
|
1198
1224
|
for (const [key, value] of e2s2s.entries()) {
|
|
1199
1225
|
if (!(key.epoch === epoch && key.scale === scale)) {
|
|
1200
1226
|
map.set(key, value);
|
|
1201
1227
|
}
|
|
1202
1228
|
}
|
|
1203
|
-
map.set({ epoch, scale },
|
|
1229
|
+
map.set({ epoch, scale }, sum2);
|
|
1204
1230
|
return map;
|
|
1205
1231
|
}
|
|
1206
1232
|
function getAccountReward(account, e2s2s) {
|
|
@@ -1374,10 +1400,24 @@ function liquidationHelper(spContent, iassetBurnAmt, reward) {
|
|
|
1374
1400
|
}
|
|
1375
1401
|
|
|
1376
1402
|
// src/contracts/cdp/transactions.ts
|
|
1377
|
-
var
|
|
1403
|
+
var import_fp_ts4 = require("fp-ts");
|
|
1378
1404
|
|
|
1379
1405
|
// src/contracts/collector/transactions.ts
|
|
1406
|
+
var import_lucid15 = require("@lucid-evolution/lucid");
|
|
1407
|
+
|
|
1408
|
+
// src/contracts/collector/types.ts
|
|
1380
1409
|
var import_lucid14 = require("@lucid-evolution/lucid");
|
|
1410
|
+
var CollectorRedeemerSchema = import_lucid14.Data.Enum([
|
|
1411
|
+
import_lucid14.Data.Literal("Collect"),
|
|
1412
|
+
import_lucid14.Data.Literal("DistributeToStakers"),
|
|
1413
|
+
import_lucid14.Data.Literal("UpgradeVersion")
|
|
1414
|
+
]);
|
|
1415
|
+
var CollectorRedeemer = CollectorRedeemerSchema;
|
|
1416
|
+
function serialiseCollectorRedeemer(redeemer) {
|
|
1417
|
+
return import_lucid14.Data.to(redeemer, CollectorRedeemer);
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
// src/contracts/collector/transactions.ts
|
|
1381
1421
|
async function collectorFeeTx(fee, lucid, params, tx, collectorOref) {
|
|
1382
1422
|
const collectorUtxo = matchSingle(
|
|
1383
1423
|
await lucid.utxosByOutRef([collectorOref]),
|
|
@@ -1389,9 +1429,9 @@ async function collectorFeeTx(fee, lucid, params, tx, collectorOref) {
|
|
|
1389
1429
|
]),
|
|
1390
1430
|
(_) => new Error("Expected a single collector Ref Script UTXO")
|
|
1391
1431
|
);
|
|
1392
|
-
tx.collectFrom([collectorUtxo],
|
|
1432
|
+
tx.collectFrom([collectorUtxo], serialiseCollectorRedeemer("Collect")).pay.ToContract(
|
|
1393
1433
|
collectorUtxo.address,
|
|
1394
|
-
{ kind: "inline", value:
|
|
1434
|
+
{ kind: "inline", value: import_lucid15.Data.void() },
|
|
1395
1435
|
{
|
|
1396
1436
|
...collectorUtxo.assets,
|
|
1397
1437
|
lovelace: collectorUtxo.assets.lovelace + fee
|
|
@@ -1400,34 +1440,34 @@ async function collectorFeeTx(fee, lucid, params, tx, collectorOref) {
|
|
|
1400
1440
|
}
|
|
1401
1441
|
|
|
1402
1442
|
// src/contracts/treasury/transactions.ts
|
|
1403
|
-
var
|
|
1443
|
+
var import_lucid17 = require("@lucid-evolution/lucid");
|
|
1404
1444
|
|
|
1405
1445
|
// src/contracts/treasury/types.ts
|
|
1406
|
-
var
|
|
1407
|
-
var TreasuryParamsSchema =
|
|
1446
|
+
var import_lucid16 = require("@lucid-evolution/lucid");
|
|
1447
|
+
var TreasuryParamsSchema = import_lucid16.Data.Object({
|
|
1408
1448
|
upgradeToken: AssetClassSchema,
|
|
1409
1449
|
versionRecordToken: AssetClassSchema,
|
|
1410
|
-
treasuryUtxosStakeCredential:
|
|
1450
|
+
treasuryUtxosStakeCredential: import_lucid16.Data.Nullable(StakeCredentialSchema)
|
|
1411
1451
|
});
|
|
1412
|
-
var TreasuryRedeemerSchema =
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1452
|
+
var TreasuryRedeemerSchema = import_lucid16.Data.Enum([
|
|
1453
|
+
import_lucid16.Data.Literal("Withdraw"),
|
|
1454
|
+
import_lucid16.Data.Literal("PrepareWithdraw"),
|
|
1455
|
+
import_lucid16.Data.Literal("Split"),
|
|
1456
|
+
import_lucid16.Data.Literal("Merge"),
|
|
1457
|
+
import_lucid16.Data.Literal("CollectAda"),
|
|
1458
|
+
import_lucid16.Data.Literal("UpgradeVersion")
|
|
1419
1459
|
]);
|
|
1420
1460
|
var TreasuryRedeemer = TreasuryRedeemerSchema;
|
|
1421
|
-
var WithdrawalOutputDatumSchema =
|
|
1422
|
-
|
|
1461
|
+
var WithdrawalOutputDatumSchema = import_lucid16.Data.Tuple([
|
|
1462
|
+
import_lucid16.Data.Bytes(),
|
|
1423
1463
|
OutputReferenceSchema
|
|
1424
1464
|
]);
|
|
1425
1465
|
var WithdrawalOutputDatum = WithdrawalOutputDatumSchema;
|
|
1426
1466
|
function serialiseWithdrawalOutputDatum(d) {
|
|
1427
|
-
return
|
|
1467
|
+
return import_lucid16.Data.to(d, WithdrawalOutputDatum);
|
|
1428
1468
|
}
|
|
1429
1469
|
function serialiseTreasuryRedeemer(redeemer) {
|
|
1430
|
-
return
|
|
1470
|
+
return import_lucid16.Data.to(redeemer, TreasuryRedeemer);
|
|
1431
1471
|
}
|
|
1432
1472
|
|
|
1433
1473
|
// src/contracts/treasury/transactions.ts
|
|
@@ -1446,15 +1486,15 @@ async function treasuryFeeTx(fee, lucid, sysParams, tx, treasuryOref) {
|
|
|
1446
1486
|
);
|
|
1447
1487
|
tx.readFrom([treasuryRefScriptUtxo]).collectFrom([treasuryUtxo], serialiseTreasuryRedeemer("CollectAda")).pay.ToContract(
|
|
1448
1488
|
treasuryUtxo.address,
|
|
1449
|
-
{ kind: "inline", value:
|
|
1450
|
-
(0,
|
|
1489
|
+
{ kind: "inline", value: import_lucid17.Data.void() },
|
|
1490
|
+
(0, import_lucid17.addAssets)(treasuryUtxo.assets, mkLovelacesOf(fee))
|
|
1451
1491
|
);
|
|
1452
1492
|
}
|
|
1453
1493
|
|
|
1454
1494
|
// src/contracts/cdp/transactions.ts
|
|
1455
1495
|
async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref, iassetOref, priceOracleOref, interestOracleOref, collectorOref, lucid, currentSlot) {
|
|
1456
1496
|
const network = lucid.config().network;
|
|
1457
|
-
const currentTime = BigInt((0,
|
|
1497
|
+
const currentTime = BigInt((0, import_lucid18.slotToUnixTime)(network, currentSlot));
|
|
1458
1498
|
const [pkh, skh] = await addrDetails(lucid);
|
|
1459
1499
|
const cdpCreatorRefScriptUtxo = matchSingle(
|
|
1460
1500
|
await lucid.utxosByOutRef([
|
|
@@ -1530,7 +1570,7 @@ async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref
|
|
|
1530
1570
|
cdpCreatorRefScriptUtxo,
|
|
1531
1571
|
cdpAuthTokenPolicyRefScriptUtxo,
|
|
1532
1572
|
iAssetTokenPolicyRefScriptUtxo
|
|
1533
|
-
]).mintAssets(cdpNftVal,
|
|
1573
|
+
]).mintAssets(cdpNftVal, import_lucid18.Data.void()).mintAssets(iassetTokensVal, import_lucid18.Data.void()).collectFrom(
|
|
1534
1574
|
[cdpCreatorUtxo],
|
|
1535
1575
|
serialiseCDPCreatorRedeemer({
|
|
1536
1576
|
CreateCDP: {
|
|
@@ -1559,10 +1599,10 @@ async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref
|
|
|
1559
1599
|
}
|
|
1560
1600
|
})
|
|
1561
1601
|
},
|
|
1562
|
-
(0,
|
|
1602
|
+
(0, import_lucid18.addAssets)(cdpNftVal, mkLovelacesOf(collateralAmount))
|
|
1563
1603
|
).pay.ToContract(
|
|
1564
1604
|
cdpCreatorUtxo.address,
|
|
1565
|
-
{ kind: "inline", value:
|
|
1605
|
+
{ kind: "inline", value: import_lucid18.Data.void() },
|
|
1566
1606
|
cdpCreatorUtxo.assets
|
|
1567
1607
|
).readFrom([priceOracleUtxo, interestOracleUtxo, iassetUtxo]).addSignerKey(pkh.hash);
|
|
1568
1608
|
const debtMintingFee = calculateFeeFromPercentage(
|
|
@@ -1576,7 +1616,7 @@ async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref
|
|
|
1576
1616
|
}
|
|
1577
1617
|
async function adjustCdp(collateralAmount, mintAmount, cdpOref, iassetOref, priceOracleOref, interestOracleOref, collectorOref, govOref, treasuryOref, sysParams, lucid, currentSlot) {
|
|
1578
1618
|
const network = lucid.config().network;
|
|
1579
|
-
const currentTime = BigInt((0,
|
|
1619
|
+
const currentTime = BigInt((0, import_lucid18.slotToUnixTime)(network, currentSlot));
|
|
1580
1620
|
const cdpRefScriptUtxo = matchSingle(
|
|
1581
1621
|
await lucid.utxosByOutRef([
|
|
1582
1622
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
@@ -1651,7 +1691,7 @@ async function adjustCdp(collateralAmount, mintAmount, cdpOref, iassetOref, pric
|
|
|
1651
1691
|
}
|
|
1652
1692
|
})
|
|
1653
1693
|
},
|
|
1654
|
-
(0,
|
|
1694
|
+
(0, import_lucid18.addAssets)(cdpUtxo.assets, mkLovelacesOf(collateralAmount))
|
|
1655
1695
|
);
|
|
1656
1696
|
if (!cdpDatum.cdpOwner) {
|
|
1657
1697
|
throw new Error("Expected active CDP");
|
|
@@ -1675,7 +1715,7 @@ async function adjustCdp(collateralAmount, mintAmount, cdpOref, iassetOref, pric
|
|
|
1675
1715
|
);
|
|
1676
1716
|
tx.readFrom([iAssetTokenPolicyRefScriptUtxo]).mintAssets(
|
|
1677
1717
|
iassetTokensVal,
|
|
1678
|
-
|
|
1718
|
+
import_lucid18.Data.void()
|
|
1679
1719
|
);
|
|
1680
1720
|
}
|
|
1681
1721
|
const interestAdaAmt = (0, import_ts_pattern7.match)(cdpDatum.cdpFees).with({ FrozenCDPAccumulatedFees: import_ts_pattern7.P.any }, () => {
|
|
@@ -1788,7 +1828,7 @@ async function burnCdp(amount, cdpOref, iassetOref, priceOracleOref, interestOra
|
|
|
1788
1828
|
}
|
|
1789
1829
|
async function closeCdp(cdpOref, iassetOref, priceOracleOref, interestOracleOref, collectorOref, govOref, treasuryOref, sysParams, lucid, currentSlot) {
|
|
1790
1830
|
const network = lucid.config().network;
|
|
1791
|
-
const currentTime = BigInt((0,
|
|
1831
|
+
const currentTime = BigInt((0, import_lucid18.slotToUnixTime)(network, currentSlot));
|
|
1792
1832
|
const cdpRefScriptUtxo = matchSingle(
|
|
1793
1833
|
await lucid.utxosByOutRef([
|
|
1794
1834
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
@@ -1860,10 +1900,10 @@ async function closeCdp(cdpOref, iassetOref, priceOracleOref, interestOracleOref
|
|
|
1860
1900
|
},
|
|
1861
1901
|
-cdpDatum.mintedAmt
|
|
1862
1902
|
),
|
|
1863
|
-
|
|
1903
|
+
import_lucid18.Data.void()
|
|
1864
1904
|
).mintAssets(
|
|
1865
1905
|
mkAssetsOf(fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken), -1n),
|
|
1866
|
-
|
|
1906
|
+
import_lucid18.Data.void()
|
|
1867
1907
|
).collectFrom(
|
|
1868
1908
|
[cdpUtxo],
|
|
1869
1909
|
serialiseCdpRedeemer({ CloseCdp: { currentTime } })
|
|
@@ -1909,7 +1949,7 @@ async function closeCdp(cdpOref, iassetOref, priceOracleOref, interestOracleOref
|
|
|
1909
1949
|
}
|
|
1910
1950
|
async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, priceOracleOref, interestOracleOref, collectorOref, treasuryOref, sysParams, lucid, currentSlot) {
|
|
1911
1951
|
const network = lucid.config().network;
|
|
1912
|
-
const currentTime = BigInt((0,
|
|
1952
|
+
const currentTime = BigInt((0, import_lucid18.slotToUnixTime)(network, currentSlot));
|
|
1913
1953
|
const cdpRefScriptUtxo = matchSingle(
|
|
1914
1954
|
await lucid.utxosByOutRef([
|
|
1915
1955
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
@@ -2018,7 +2058,7 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, pric
|
|
|
2018
2058
|
},
|
|
2019
2059
|
-redemptionIAssetAmt
|
|
2020
2060
|
),
|
|
2021
|
-
|
|
2061
|
+
import_lucid18.Data.void()
|
|
2022
2062
|
).pay.ToContract(
|
|
2023
2063
|
cdpUtxo.address,
|
|
2024
2064
|
{
|
|
@@ -2037,7 +2077,7 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, pric
|
|
|
2037
2077
|
}
|
|
2038
2078
|
})
|
|
2039
2079
|
},
|
|
2040
|
-
(0,
|
|
2080
|
+
(0, import_lucid18.addAssets)(
|
|
2041
2081
|
cdpUtxo.assets,
|
|
2042
2082
|
mkLovelacesOf(-redemptionLovelacesAmt),
|
|
2043
2083
|
mkLovelacesOf(reimburstmentFee),
|
|
@@ -2062,7 +2102,7 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, pric
|
|
|
2062
2102
|
}
|
|
2063
2103
|
async function freezeCdp(cdpOref, iassetOref, priceOracleOref, interestOracleOref, sysParams, lucid, currentSlot) {
|
|
2064
2104
|
const network = lucid.config().network;
|
|
2065
|
-
const currentTime = BigInt((0,
|
|
2105
|
+
const currentTime = BigInt((0, import_lucid18.slotToUnixTime)(network, currentSlot));
|
|
2066
2106
|
const cdpRefScriptUtxo = matchSingle(
|
|
2067
2107
|
await lucid.utxosByOutRef([
|
|
2068
2108
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
@@ -2228,7 +2268,7 @@ async function liquidateCdp(cdpOref, stabilityPoolOref, collectorOref, treasuryO
|
|
|
2228
2268
|
stabilityPoolRefScriptUtxo,
|
|
2229
2269
|
iAssetTokenPolicyRefScriptUtxo,
|
|
2230
2270
|
cdpAuthTokenPolicyRefScriptUtxo
|
|
2231
|
-
]).collectFrom([spUtxo], serialiseStabilityPoolRedeemer("LiquidateCDP")).collectFrom([cdpUtxo], serialiseCdpRedeemer("Liquidate")).mintAssets(mkAssetsOf(iassetsAc, -iassetBurnAmt),
|
|
2271
|
+
]).collectFrom([spUtxo], serialiseStabilityPoolRedeemer("LiquidateCDP")).collectFrom([cdpUtxo], serialiseCdpRedeemer("Liquidate")).mintAssets(mkAssetsOf(iassetsAc, -iassetBurnAmt), import_lucid18.Data.void()).pay.ToContract(
|
|
2232
2272
|
spUtxo.address,
|
|
2233
2273
|
{
|
|
2234
2274
|
kind: "inline",
|
|
@@ -2240,7 +2280,7 @@ async function liquidateCdp(cdpOref, stabilityPoolOref, collectorOref, treasuryO
|
|
|
2240
2280
|
).newSpContent
|
|
2241
2281
|
})
|
|
2242
2282
|
},
|
|
2243
|
-
(0,
|
|
2283
|
+
(0, import_lucid18.addAssets)(
|
|
2244
2284
|
spUtxo.assets,
|
|
2245
2285
|
mkLovelacesOf(collateralAbsorbed),
|
|
2246
2286
|
mkAssetsOf(iassetsAc, -iassetBurnAmt)
|
|
@@ -2262,7 +2302,7 @@ async function liquidateCdp(cdpOref, stabilityPoolOref, collectorOref, treasuryO
|
|
|
2262
2302
|
}
|
|
2263
2303
|
})
|
|
2264
2304
|
},
|
|
2265
|
-
(0,
|
|
2305
|
+
(0, import_lucid18.addAssets)(
|
|
2266
2306
|
mkAssetsOf(cdpNftAc, assetClassValueOf(cdpUtxo.assets, cdpNftAc)),
|
|
2267
2307
|
mkLovelacesOf(collateralAvailable - collateralAbsorbed)
|
|
2268
2308
|
)
|
|
@@ -2270,7 +2310,7 @@ async function liquidateCdp(cdpOref, stabilityPoolOref, collectorOref, treasuryO
|
|
|
2270
2310
|
} else {
|
|
2271
2311
|
tx.mintAssets(
|
|
2272
2312
|
mkAssetsOf(cdpNftAc, -assetClassValueOf(cdpUtxo.assets, cdpNftAc)),
|
|
2273
|
-
|
|
2313
|
+
import_lucid18.Data.void()
|
|
2274
2314
|
);
|
|
2275
2315
|
}
|
|
2276
2316
|
await collectorFeeTx(
|
|
@@ -2297,17 +2337,17 @@ async function mergeCdps(cdpsToMergeUtxos, sysParams, lucid) {
|
|
|
2297
2337
|
if (cdpUtxos.length !== cdpsToMergeUtxos.length) {
|
|
2298
2338
|
throw new Error("Expected certain number of CDPs");
|
|
2299
2339
|
}
|
|
2300
|
-
const aggregatedVal =
|
|
2340
|
+
const aggregatedVal = import_fp_ts4.function.pipe(
|
|
2301
2341
|
cdpUtxos,
|
|
2302
|
-
|
|
2342
|
+
import_fp_ts4.array.reduce({}, (acc, utxo) => (0, import_lucid18.addAssets)(acc, utxo.assets))
|
|
2303
2343
|
);
|
|
2304
|
-
const aggregatedMintedAmt =
|
|
2344
|
+
const aggregatedMintedAmt = import_fp_ts4.function.pipe(
|
|
2305
2345
|
cdpDatums,
|
|
2306
|
-
|
|
2346
|
+
import_fp_ts4.array.reduce(0n, (acc, cdpDat) => acc + cdpDat.mintedAmt)
|
|
2307
2347
|
);
|
|
2308
|
-
const { aggregatedFeeTreasury, aggregatedFeeIndyStakers } =
|
|
2348
|
+
const { aggregatedFeeTreasury, aggregatedFeeIndyStakers } = import_fp_ts4.function.pipe(
|
|
2309
2349
|
cdpDatums,
|
|
2310
|
-
|
|
2350
|
+
import_fp_ts4.array.reduce(
|
|
2311
2351
|
{ aggregatedFeeIndyStakers: 0n, aggregatedFeeTreasury: 0n },
|
|
2312
2352
|
(acc, cdpDat) => (0, import_ts_pattern7.match)(cdpDat.cdpFees).returnType().with({ FrozenCDPAccumulatedFees: import_ts_pattern7.P.select() }, (fees) => ({
|
|
2313
2353
|
aggregatedFeeIndyStakers: acc.aggregatedFeeIndyStakers + fees.lovelacesIndyStakers,
|
|
@@ -2316,7 +2356,7 @@ async function mergeCdps(cdpsToMergeUtxos, sysParams, lucid) {
|
|
|
2316
2356
|
)
|
|
2317
2357
|
);
|
|
2318
2358
|
const [[mainMergeUtxo, mainCdpDatum], otherMergeUtxos] = (0, import_ts_pattern7.match)(
|
|
2319
|
-
|
|
2359
|
+
import_fp_ts4.array.zip(cdpUtxos, cdpDatums)
|
|
2320
2360
|
).returnType().with([import_ts_pattern7.P._, ...import_ts_pattern7.P.array()], ([main, ...other]) => [
|
|
2321
2361
|
main,
|
|
2322
2362
|
other.map((a) => a[0])
|
|
@@ -2354,7 +2394,7 @@ async function mergeCdps(cdpsToMergeUtxos, sysParams, lucid) {
|
|
|
2354
2394
|
}
|
|
2355
2395
|
|
|
2356
2396
|
// src/contracts/cdp/scripts.ts
|
|
2357
|
-
var
|
|
2397
|
+
var import_lucid19 = require("@lucid-evolution/lucid");
|
|
2358
2398
|
|
|
2359
2399
|
// src/validators/cdp-validator.ts
|
|
2360
2400
|
var _cdpValidator = {
|
|
@@ -2367,7 +2407,7 @@ var _cdpValidator = {
|
|
|
2367
2407
|
var mkCdpValidatorFromSP = (params) => {
|
|
2368
2408
|
return {
|
|
2369
2409
|
type: "PlutusV2",
|
|
2370
|
-
script: (0,
|
|
2410
|
+
script: (0, import_lucid19.applyParamsToScript)(_cdpValidator.cborHex, [
|
|
2371
2411
|
castCdpParams({
|
|
2372
2412
|
cdp_auth_token: fromSystemParamsAsset(params.cdpAuthToken),
|
|
2373
2413
|
cdp_asset_symbol: params.cdpAssetSymbol.unCurrencySymbol,
|
|
@@ -2392,7 +2432,7 @@ var mkCdpValidatorFromSP = (params) => {
|
|
|
2392
2432
|
};
|
|
2393
2433
|
|
|
2394
2434
|
// src/contracts/cdp-creator/scripts.ts
|
|
2395
|
-
var
|
|
2435
|
+
var import_lucid20 = require("@lucid-evolution/lucid");
|
|
2396
2436
|
|
|
2397
2437
|
// src/validators/cdp-creator-validator.ts
|
|
2398
2438
|
var _cdpCreatorValidator = {
|
|
@@ -2405,7 +2445,7 @@ var _cdpCreatorValidator = {
|
|
|
2405
2445
|
var mkCDPCreatorValidator = (params) => {
|
|
2406
2446
|
return {
|
|
2407
2447
|
type: "PlutusV2",
|
|
2408
|
-
script: (0,
|
|
2448
|
+
script: (0, import_lucid20.applyParamsToScript)(_cdpCreatorValidator.cborHex, [
|
|
2409
2449
|
castCDPCreatorParams(params)
|
|
2410
2450
|
])
|
|
2411
2451
|
};
|
|
@@ -2413,7 +2453,7 @@ var mkCDPCreatorValidator = (params) => {
|
|
|
2413
2453
|
var mkCDPCreatorValidatorFromSP = (params) => {
|
|
2414
2454
|
return {
|
|
2415
2455
|
type: "PlutusV2",
|
|
2416
|
-
script: (0,
|
|
2456
|
+
script: (0, import_lucid20.applyParamsToScript)(_cdpCreatorValidator.cborHex, [
|
|
2417
2457
|
castCDPCreatorParams({
|
|
2418
2458
|
cdpCreatorNft: fromSystemParamsAsset(params.cdpCreatorNft),
|
|
2419
2459
|
cdpAssetCs: params.cdpAssetCs.unCurrencySymbol,
|
|
@@ -2430,64 +2470,64 @@ var mkCDPCreatorValidatorFromSP = (params) => {
|
|
|
2430
2470
|
};
|
|
2431
2471
|
|
|
2432
2472
|
// src/contracts/poll/scripts.ts
|
|
2433
|
-
var
|
|
2473
|
+
var import_lucid23 = require("@lucid-evolution/lucid");
|
|
2434
2474
|
|
|
2435
2475
|
// src/contracts/poll/types-poll-manager.ts
|
|
2436
|
-
var
|
|
2437
|
-
var PollManagerParamsSchema =
|
|
2476
|
+
var import_lucid21 = require("@lucid-evolution/lucid");
|
|
2477
|
+
var PollManagerParamsSchema = import_lucid21.Data.Object({
|
|
2438
2478
|
govNFT: AssetClassSchema,
|
|
2439
2479
|
pollToken: AssetClassSchema,
|
|
2440
2480
|
upgradeToken: AssetClassSchema,
|
|
2441
2481
|
indyAsset: AssetClassSchema,
|
|
2442
|
-
govExecuteValHash:
|
|
2443
|
-
pBiasTime:
|
|
2444
|
-
shardValHash:
|
|
2445
|
-
treasuryValHash:
|
|
2446
|
-
initialIndyDistribution:
|
|
2482
|
+
govExecuteValHash: import_lucid21.Data.Bytes(),
|
|
2483
|
+
pBiasTime: import_lucid21.Data.Integer(),
|
|
2484
|
+
shardValHash: import_lucid21.Data.Bytes(),
|
|
2485
|
+
treasuryValHash: import_lucid21.Data.Bytes(),
|
|
2486
|
+
initialIndyDistribution: import_lucid21.Data.Integer()
|
|
2447
2487
|
});
|
|
2448
2488
|
var PollManagerParams = PollManagerParamsSchema;
|
|
2449
|
-
var PollManagerRedeemerSchema =
|
|
2450
|
-
|
|
2451
|
-
EndPoll:
|
|
2489
|
+
var PollManagerRedeemerSchema = import_lucid21.Data.Enum([
|
|
2490
|
+
import_lucid21.Data.Object({
|
|
2491
|
+
EndPoll: import_lucid21.Data.Object({ currentTime: import_lucid21.Data.Integer() })
|
|
2452
2492
|
}),
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
MergeShardsManager:
|
|
2493
|
+
import_lucid21.Data.Object({ CreateShards: import_lucid21.Data.Object({ currentTime: import_lucid21.Data.Integer() }) }),
|
|
2494
|
+
import_lucid21.Data.Object({
|
|
2495
|
+
MergeShardsManager: import_lucid21.Data.Object({ currentTime: import_lucid21.Data.Integer() })
|
|
2456
2496
|
})
|
|
2457
2497
|
]);
|
|
2458
2498
|
var PollManagerRedeemer = PollManagerRedeemerSchema;
|
|
2459
2499
|
function serialisePollManagerRedeemer(r) {
|
|
2460
|
-
return
|
|
2500
|
+
return import_lucid21.Data.to(r, PollManagerRedeemer);
|
|
2461
2501
|
}
|
|
2462
2502
|
function castPollManagerParams(params) {
|
|
2463
|
-
return
|
|
2503
|
+
return import_lucid21.Data.castTo(params, PollManagerParams);
|
|
2464
2504
|
}
|
|
2465
2505
|
|
|
2466
2506
|
// src/contracts/poll/types-poll-shard.ts
|
|
2467
|
-
var
|
|
2468
|
-
var PollShardParamsSchema =
|
|
2507
|
+
var import_lucid22 = require("@lucid-evolution/lucid");
|
|
2508
|
+
var PollShardParamsSchema = import_lucid22.Data.Object({
|
|
2469
2509
|
pollToken: AssetClassSchema,
|
|
2470
2510
|
stakingToken: AssetClassSchema,
|
|
2471
2511
|
indyAsset: AssetClassSchema,
|
|
2472
|
-
stakingValHash:
|
|
2512
|
+
stakingValHash: import_lucid22.Data.Bytes()
|
|
2473
2513
|
});
|
|
2474
2514
|
var PollShardParams = PollShardParamsSchema;
|
|
2475
|
-
var VoteOptionSchema =
|
|
2476
|
-
var PollShardRedeemerSchema =
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
MergeShards:
|
|
2480
|
-
currentTime:
|
|
2515
|
+
var VoteOptionSchema = import_lucid22.Data.Enum([import_lucid22.Data.Literal("Yes"), import_lucid22.Data.Literal("No")]);
|
|
2516
|
+
var PollShardRedeemerSchema = import_lucid22.Data.Enum([
|
|
2517
|
+
import_lucid22.Data.Object({ Vote: import_lucid22.Data.Object({ content: VoteOptionSchema }) }),
|
|
2518
|
+
import_lucid22.Data.Object({
|
|
2519
|
+
MergeShards: import_lucid22.Data.Object({
|
|
2520
|
+
currentTime: import_lucid22.Data.Integer(),
|
|
2481
2521
|
pollManagerRef: OutputReferenceSchema
|
|
2482
2522
|
})
|
|
2483
2523
|
})
|
|
2484
2524
|
]);
|
|
2485
2525
|
var PollShardRedeemer = PollShardRedeemerSchema;
|
|
2486
2526
|
function serialisePollShardRedeemer(redeemer) {
|
|
2487
|
-
return
|
|
2527
|
+
return import_lucid22.Data.to(redeemer, PollShardRedeemer);
|
|
2488
2528
|
}
|
|
2489
2529
|
function castPollShardParams(params) {
|
|
2490
|
-
return
|
|
2530
|
+
return import_lucid22.Data.castTo(params, PollShardParams);
|
|
2491
2531
|
}
|
|
2492
2532
|
|
|
2493
2533
|
// src/validators/poll-manager-validator.ts
|
|
@@ -2508,7 +2548,7 @@ var _pollShardValidator = {
|
|
|
2508
2548
|
var mkPollManagerValidator = (params) => {
|
|
2509
2549
|
return {
|
|
2510
2550
|
type: "PlutusV2",
|
|
2511
|
-
script: (0,
|
|
2551
|
+
script: (0, import_lucid23.applyParamsToScript)(_pollManagerValidator.cborHex, [
|
|
2512
2552
|
castPollManagerParams(params)
|
|
2513
2553
|
])
|
|
2514
2554
|
};
|
|
@@ -2516,7 +2556,7 @@ var mkPollManagerValidator = (params) => {
|
|
|
2516
2556
|
var mkPollManagerValidatorFromSP = (params) => {
|
|
2517
2557
|
return {
|
|
2518
2558
|
type: "PlutusV2",
|
|
2519
|
-
script: (0,
|
|
2559
|
+
script: (0, import_lucid23.applyParamsToScript)(_pollManagerValidator.cborHex, [
|
|
2520
2560
|
castPollManagerParams({
|
|
2521
2561
|
govNFT: fromSystemParamsAsset(params.govNFT),
|
|
2522
2562
|
pollToken: fromSystemParamsAsset(params.pollToken),
|
|
@@ -2534,7 +2574,7 @@ var mkPollManagerValidatorFromSP = (params) => {
|
|
|
2534
2574
|
var mkPollShardValidator = (params) => {
|
|
2535
2575
|
return {
|
|
2536
2576
|
type: "PlutusV2",
|
|
2537
|
-
script: (0,
|
|
2577
|
+
script: (0, import_lucid23.applyParamsToScript)(_pollShardValidator.cborHex, [
|
|
2538
2578
|
castPollShardParams(params)
|
|
2539
2579
|
])
|
|
2540
2580
|
};
|
|
@@ -2542,7 +2582,7 @@ var mkPollShardValidator = (params) => {
|
|
|
2542
2582
|
var mkPollShardValidatorFromSP = (params) => {
|
|
2543
2583
|
return {
|
|
2544
2584
|
type: "PlutusV2",
|
|
2545
|
-
script: (0,
|
|
2585
|
+
script: (0, import_lucid23.applyParamsToScript)(_pollShardValidator.cborHex, [
|
|
2546
2586
|
castPollShardParams({
|
|
2547
2587
|
pollToken: fromSystemParamsAsset(params.pollToken),
|
|
2548
2588
|
stakingToken: fromSystemParamsAsset(params.stakingToken),
|
|
@@ -2554,123 +2594,123 @@ var mkPollShardValidatorFromSP = (params) => {
|
|
|
2554
2594
|
};
|
|
2555
2595
|
|
|
2556
2596
|
// src/contracts/gov/transactions.ts
|
|
2557
|
-
var
|
|
2597
|
+
var import_lucid30 = require("@lucid-evolution/lucid");
|
|
2558
2598
|
|
|
2559
2599
|
// src/contracts/poll/types-poll.ts
|
|
2560
|
-
var
|
|
2561
|
-
var
|
|
2600
|
+
var import_lucid24 = require("@lucid-evolution/lucid");
|
|
2601
|
+
var import_fp_ts5 = require("fp-ts");
|
|
2562
2602
|
var import_ts_pattern8 = require("ts-pattern");
|
|
2563
|
-
var PollStatusSchema =
|
|
2564
|
-
yesVotes:
|
|
2565
|
-
noVotes:
|
|
2603
|
+
var PollStatusSchema = import_lucid24.Data.Object({
|
|
2604
|
+
yesVotes: import_lucid24.Data.Integer(),
|
|
2605
|
+
noVotes: import_lucid24.Data.Integer()
|
|
2566
2606
|
});
|
|
2567
|
-
var PollManagerContentSchema =
|
|
2568
|
-
pollId:
|
|
2569
|
-
pollOwner:
|
|
2607
|
+
var PollManagerContentSchema = import_lucid24.Data.Object({
|
|
2608
|
+
pollId: import_lucid24.Data.Integer(),
|
|
2609
|
+
pollOwner: import_lucid24.Data.Bytes(),
|
|
2570
2610
|
content: ProposalContentSchema,
|
|
2571
|
-
treasuryWithdrawal:
|
|
2611
|
+
treasuryWithdrawal: import_lucid24.Data.Nullable(TreasuryWithdrawalSchema),
|
|
2572
2612
|
status: PollStatusSchema,
|
|
2573
|
-
votingEndTime:
|
|
2574
|
-
createdShardsCount:
|
|
2575
|
-
talliedShardsCount:
|
|
2576
|
-
totalShardsCount:
|
|
2577
|
-
proposingEndTime:
|
|
2578
|
-
expirationTime:
|
|
2579
|
-
protocolVersion:
|
|
2580
|
-
minimumQuorum:
|
|
2613
|
+
votingEndTime: import_lucid24.Data.Integer(),
|
|
2614
|
+
createdShardsCount: import_lucid24.Data.Integer(),
|
|
2615
|
+
talliedShardsCount: import_lucid24.Data.Integer(),
|
|
2616
|
+
totalShardsCount: import_lucid24.Data.Integer(),
|
|
2617
|
+
proposingEndTime: import_lucid24.Data.Integer(),
|
|
2618
|
+
expirationTime: import_lucid24.Data.Integer(),
|
|
2619
|
+
protocolVersion: import_lucid24.Data.Integer(),
|
|
2620
|
+
minimumQuorum: import_lucid24.Data.Integer()
|
|
2581
2621
|
});
|
|
2582
|
-
var PollShardContentSchema =
|
|
2583
|
-
pollId:
|
|
2622
|
+
var PollShardContentSchema = import_lucid24.Data.Object({
|
|
2623
|
+
pollId: import_lucid24.Data.Integer(),
|
|
2584
2624
|
status: PollStatusSchema,
|
|
2585
|
-
votingEndTime:
|
|
2625
|
+
votingEndTime: import_lucid24.Data.Integer(),
|
|
2586
2626
|
managerAddress: AddressSchema
|
|
2587
2627
|
});
|
|
2588
|
-
var PollDatumSchema =
|
|
2589
|
-
|
|
2590
|
-
PollManager:
|
|
2628
|
+
var PollDatumSchema = import_lucid24.Data.Enum([
|
|
2629
|
+
import_lucid24.Data.Object({
|
|
2630
|
+
PollManager: import_lucid24.Data.Object({ content: PollManagerContentSchema })
|
|
2591
2631
|
}),
|
|
2592
|
-
|
|
2632
|
+
import_lucid24.Data.Object({ PollShard: import_lucid24.Data.Object({ content: PollShardContentSchema }) })
|
|
2593
2633
|
]);
|
|
2594
2634
|
var PollDatum = PollDatumSchema;
|
|
2595
2635
|
function parsePollManager(datum) {
|
|
2596
2636
|
try {
|
|
2597
|
-
return (0, import_ts_pattern8.match)(
|
|
2637
|
+
return (0, import_ts_pattern8.match)(import_lucid24.Data.from(datum, PollDatum)).with({ PollManager: import_ts_pattern8.P.select() }, (res) => import_fp_ts5.option.some(res.content)).otherwise(() => import_fp_ts5.option.none);
|
|
2598
2638
|
} catch (_) {
|
|
2599
|
-
return
|
|
2639
|
+
return import_fp_ts5.option.none;
|
|
2600
2640
|
}
|
|
2601
2641
|
}
|
|
2602
2642
|
function parsePollManagerOrThrow(datum) {
|
|
2603
|
-
return
|
|
2643
|
+
return import_fp_ts5.function.pipe(
|
|
2604
2644
|
parsePollManager(datum),
|
|
2605
|
-
|
|
2645
|
+
import_fp_ts5.option.match(() => {
|
|
2606
2646
|
throw new Error("Expected a Poll manager datum.");
|
|
2607
|
-
},
|
|
2647
|
+
}, import_fp_ts5.function.identity)
|
|
2608
2648
|
);
|
|
2609
2649
|
}
|
|
2610
2650
|
function parsePollShard(datum) {
|
|
2611
2651
|
try {
|
|
2612
|
-
return (0, import_ts_pattern8.match)(
|
|
2652
|
+
return (0, import_ts_pattern8.match)(import_lucid24.Data.from(datum, PollDatum)).with({ PollShard: import_ts_pattern8.P.select() }, (res) => import_fp_ts5.option.some(res.content)).otherwise(() => import_fp_ts5.option.none);
|
|
2613
2653
|
} catch (_) {
|
|
2614
|
-
return
|
|
2654
|
+
return import_fp_ts5.option.none;
|
|
2615
2655
|
}
|
|
2616
2656
|
}
|
|
2617
2657
|
function parsePollShardOrThrow(datum) {
|
|
2618
|
-
return
|
|
2658
|
+
return import_fp_ts5.function.pipe(
|
|
2619
2659
|
parsePollShard(datum),
|
|
2620
|
-
|
|
2660
|
+
import_fp_ts5.option.match(() => {
|
|
2621
2661
|
throw new Error("Expected a Poll shard datum.");
|
|
2622
|
-
},
|
|
2662
|
+
}, import_fp_ts5.function.identity)
|
|
2623
2663
|
);
|
|
2624
2664
|
}
|
|
2625
2665
|
function serialisePollDatum(datum) {
|
|
2626
|
-
return
|
|
2666
|
+
return import_lucid24.Data.to(datum, PollDatum);
|
|
2627
2667
|
}
|
|
2628
2668
|
|
|
2629
2669
|
// src/contracts/gov/transactions.ts
|
|
2630
|
-
var
|
|
2670
|
+
var import_lucid31 = require("@lucid-evolution/lucid");
|
|
2631
2671
|
var import_function2 = require("fp-ts/lib/function");
|
|
2632
|
-
var
|
|
2672
|
+
var import_fp_ts10 = require("fp-ts");
|
|
2633
2673
|
var import_ts_pattern11 = require("ts-pattern");
|
|
2634
2674
|
|
|
2635
2675
|
// src/contracts/staking/types.ts
|
|
2636
|
-
var
|
|
2637
|
-
var StakingParamsSchema =
|
|
2676
|
+
var import_lucid25 = require("@lucid-evolution/lucid");
|
|
2677
|
+
var StakingParamsSchema = import_lucid25.Data.Object({
|
|
2638
2678
|
stakingManagerNft: AssetClassSchema,
|
|
2639
2679
|
stakingToken: AssetClassSchema,
|
|
2640
2680
|
indyToken: AssetClassSchema,
|
|
2641
2681
|
pollToken: AssetClassSchema,
|
|
2642
2682
|
versionRecordToken: AssetClassSchema,
|
|
2643
|
-
collectorValHash:
|
|
2683
|
+
collectorValHash: import_lucid25.Data.Bytes()
|
|
2644
2684
|
});
|
|
2645
2685
|
var StakingParams = StakingParamsSchema;
|
|
2646
|
-
var StakingRedeemerSchema =
|
|
2647
|
-
|
|
2648
|
-
CreateStakingPosition:
|
|
2649
|
-
creatorPkh:
|
|
2686
|
+
var StakingRedeemerSchema = import_lucid25.Data.Enum([
|
|
2687
|
+
import_lucid25.Data.Object({
|
|
2688
|
+
CreateStakingPosition: import_lucid25.Data.Object({
|
|
2689
|
+
creatorPkh: import_lucid25.Data.Bytes()
|
|
2650
2690
|
})
|
|
2651
2691
|
}),
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
AdjustStakedAmount:
|
|
2656
|
-
adjustAmount:
|
|
2692
|
+
import_lucid25.Data.Literal("UpdateTotalStake"),
|
|
2693
|
+
import_lucid25.Data.Literal("Distribute"),
|
|
2694
|
+
import_lucid25.Data.Object({
|
|
2695
|
+
AdjustStakedAmount: import_lucid25.Data.Object({
|
|
2696
|
+
adjustAmount: import_lucid25.Data.Integer()
|
|
2657
2697
|
})
|
|
2658
2698
|
}),
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2699
|
+
import_lucid25.Data.Literal("Unstake"),
|
|
2700
|
+
import_lucid25.Data.Literal("Lock"),
|
|
2701
|
+
import_lucid25.Data.Literal("UpgradeVersion")
|
|
2662
2702
|
]);
|
|
2663
2703
|
var StakingRedeemer = StakingRedeemerSchema;
|
|
2664
2704
|
function serialiseStakingRedeemer(redeemer) {
|
|
2665
|
-
return
|
|
2705
|
+
return import_lucid25.Data.to(redeemer, StakingRedeemer);
|
|
2666
2706
|
}
|
|
2667
2707
|
function castStakingParams(params) {
|
|
2668
|
-
return
|
|
2708
|
+
return import_lucid25.Data.castTo(params, StakingParams);
|
|
2669
2709
|
}
|
|
2670
2710
|
|
|
2671
2711
|
// src/contracts/staking/types-new.ts
|
|
2672
2712
|
var import_evolution3 = require("@evolution-sdk/evolution");
|
|
2673
|
-
var
|
|
2713
|
+
var import_fp_ts6 = require("fp-ts");
|
|
2674
2714
|
var import_ts_pattern9 = require("ts-pattern");
|
|
2675
2715
|
var StakingPosLockedAmtSchema = import_evolution3.Core.TSchema.Map(
|
|
2676
2716
|
import_evolution3.Core.TSchema.Integer,
|
|
@@ -2702,17 +2742,17 @@ function parseStakingPosition(datum) {
|
|
|
2702
2742
|
StakingDatumSchema,
|
|
2703
2743
|
DEFAULT_SCHEMA_OPTIONS
|
|
2704
2744
|
).fromCBORHex(datum)
|
|
2705
|
-
).with({ owner: import_ts_pattern9.P.any }, (res) =>
|
|
2745
|
+
).with({ owner: import_ts_pattern9.P.any }, (res) => import_fp_ts6.option.some(res)).otherwise(() => import_fp_ts6.option.none);
|
|
2706
2746
|
} catch (_) {
|
|
2707
|
-
return
|
|
2747
|
+
return import_fp_ts6.option.none;
|
|
2708
2748
|
}
|
|
2709
2749
|
}
|
|
2710
2750
|
function parseStakingPositionOrThrow(datum) {
|
|
2711
|
-
return
|
|
2751
|
+
return import_fp_ts6.function.pipe(
|
|
2712
2752
|
parseStakingPosition(datum),
|
|
2713
|
-
|
|
2753
|
+
import_fp_ts6.option.match(() => {
|
|
2714
2754
|
throw new Error("Expected a StakingPosition datum.");
|
|
2715
|
-
},
|
|
2755
|
+
}, import_fp_ts6.function.identity)
|
|
2716
2756
|
);
|
|
2717
2757
|
}
|
|
2718
2758
|
function parseStakingManagerDatum(datum) {
|
|
@@ -2733,10 +2773,10 @@ function serialiseStakingDatum(d) {
|
|
|
2733
2773
|
}
|
|
2734
2774
|
|
|
2735
2775
|
// src/contracts/staking/helpers.ts
|
|
2736
|
-
var
|
|
2776
|
+
var import_lucid27 = require("@lucid-evolution/lucid");
|
|
2737
2777
|
|
|
2738
2778
|
// src/contracts/staking/scripts.ts
|
|
2739
|
-
var
|
|
2779
|
+
var import_lucid26 = require("@lucid-evolution/lucid");
|
|
2740
2780
|
|
|
2741
2781
|
// src/validators/staking-validator.ts
|
|
2742
2782
|
var _stakingValidator = {
|
|
@@ -2749,27 +2789,27 @@ var _stakingValidator = {
|
|
|
2749
2789
|
var mkStakingValidatorFromSP = (params) => {
|
|
2750
2790
|
return {
|
|
2751
2791
|
type: "PlutusV2",
|
|
2752
|
-
script: (0,
|
|
2753
|
-
new
|
|
2754
|
-
new
|
|
2792
|
+
script: (0, import_lucid26.applyParamsToScript)(_stakingValidator.cborHex, [
|
|
2793
|
+
new import_lucid26.Constr(0, [
|
|
2794
|
+
new import_lucid26.Constr(0, [
|
|
2755
2795
|
params.stakingManagerNFT[0].unCurrencySymbol,
|
|
2756
|
-
(0,
|
|
2796
|
+
(0, import_lucid26.fromText)(params.stakingManagerNFT[1].unTokenName)
|
|
2757
2797
|
]),
|
|
2758
|
-
new
|
|
2798
|
+
new import_lucid26.Constr(0, [
|
|
2759
2799
|
params.stakingToken[0].unCurrencySymbol,
|
|
2760
|
-
(0,
|
|
2800
|
+
(0, import_lucid26.fromText)(params.stakingToken[1].unTokenName)
|
|
2761
2801
|
]),
|
|
2762
|
-
new
|
|
2802
|
+
new import_lucid26.Constr(0, [
|
|
2763
2803
|
params.indyToken[0].unCurrencySymbol,
|
|
2764
|
-
(0,
|
|
2804
|
+
(0, import_lucid26.fromText)(params.indyToken[1].unTokenName)
|
|
2765
2805
|
]),
|
|
2766
|
-
new
|
|
2806
|
+
new import_lucid26.Constr(0, [
|
|
2767
2807
|
params.pollToken[0].unCurrencySymbol,
|
|
2768
|
-
(0,
|
|
2808
|
+
(0, import_lucid26.fromText)(params.pollToken[1].unTokenName)
|
|
2769
2809
|
]),
|
|
2770
|
-
new
|
|
2810
|
+
new import_lucid26.Constr(0, [
|
|
2771
2811
|
params.versionRecordToken[0].unCurrencySymbol,
|
|
2772
|
-
(0,
|
|
2812
|
+
(0, import_lucid26.fromText)(params.versionRecordToken[1].unTokenName)
|
|
2773
2813
|
]),
|
|
2774
2814
|
params.collectorValHash
|
|
2775
2815
|
])
|
|
@@ -2802,9 +2842,9 @@ function findStakingManager(params, lucid) {
|
|
|
2802
2842
|
return lucid.utxosAtWithUnit(
|
|
2803
2843
|
createScriptAddress(
|
|
2804
2844
|
lucid.config().network,
|
|
2805
|
-
(0,
|
|
2845
|
+
(0, import_lucid27.validatorToScriptHash)(mkStakingValidatorFromSP(params.stakingParams))
|
|
2806
2846
|
),
|
|
2807
|
-
params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0,
|
|
2847
|
+
params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0, import_lucid27.fromText)(params.stakingParams.stakingManagerNFT[1].unTokenName)
|
|
2808
2848
|
).then(
|
|
2809
2849
|
(utxos) => utxos.map((utxo) => {
|
|
2810
2850
|
if (!utxo.datum) return void 0;
|
|
@@ -2834,10 +2874,14 @@ function findStakingPositionByOutRef(stakingPositionRef, lucid) {
|
|
|
2834
2874
|
return result;
|
|
2835
2875
|
});
|
|
2836
2876
|
}
|
|
2877
|
+
var rewardSnapshotPrecision = OCD_DECIMAL_UNIT * OCD_DECIMAL_UNIT;
|
|
2878
|
+
function distributeReward(snapshotAda, adaReward, totalStake) {
|
|
2879
|
+
return snapshotAda + adaReward * rewardSnapshotPrecision / totalStake;
|
|
2880
|
+
}
|
|
2837
2881
|
|
|
2838
2882
|
// src/contracts/vesting/helpers.ts
|
|
2839
2883
|
var import_ts_pattern10 = require("ts-pattern");
|
|
2840
|
-
var
|
|
2884
|
+
var import_fp_ts7 = require("fp-ts");
|
|
2841
2885
|
var teamVestingSchedule = [
|
|
2842
2886
|
{
|
|
2843
2887
|
vestedAtTime: 1669067100000n,
|
|
@@ -3024,7 +3068,7 @@ var govDistributionSchedule = {
|
|
|
3024
3068
|
]
|
|
3025
3069
|
};
|
|
3026
3070
|
function calculateTotalVestedTeam(currentTime) {
|
|
3027
|
-
return
|
|
3071
|
+
return import_fp_ts7.array.reduce(0n, (acc, schedule) => {
|
|
3028
3072
|
if (currentTime >= schedule.vestedAtTime) {
|
|
3029
3073
|
return acc + schedule.unlockAmt;
|
|
3030
3074
|
} else {
|
|
@@ -3082,64 +3126,64 @@ function pollPassQuorum(initialIndyDist, pollStatus, currentTime, minQuorum, tre
|
|
|
3082
3126
|
}
|
|
3083
3127
|
|
|
3084
3128
|
// src/contracts/execute/types.ts
|
|
3085
|
-
var
|
|
3086
|
-
var
|
|
3087
|
-
var ExecuteParamsSchema =
|
|
3129
|
+
var import_lucid28 = require("@lucid-evolution/lucid");
|
|
3130
|
+
var import_fp_ts8 = require("fp-ts");
|
|
3131
|
+
var ExecuteParamsSchema = import_lucid28.Data.Object({
|
|
3088
3132
|
govNFT: AssetClassSchema,
|
|
3089
3133
|
upgradeToken: AssetClassSchema,
|
|
3090
3134
|
iAssetToken: AssetClassSchema,
|
|
3091
3135
|
stabilityPoolToken: AssetClassSchema,
|
|
3092
3136
|
versionRecordToken: AssetClassSchema,
|
|
3093
|
-
cdpValHash:
|
|
3094
|
-
sPoolValHash:
|
|
3095
|
-
versionRegistryValHash:
|
|
3096
|
-
treasuryValHash:
|
|
3137
|
+
cdpValHash: import_lucid28.Data.Bytes(),
|
|
3138
|
+
sPoolValHash: import_lucid28.Data.Bytes(),
|
|
3139
|
+
versionRegistryValHash: import_lucid28.Data.Bytes(),
|
|
3140
|
+
treasuryValHash: import_lucid28.Data.Bytes(),
|
|
3097
3141
|
indyAsset: AssetClassSchema
|
|
3098
3142
|
});
|
|
3099
3143
|
var ExecuteParams = ExecuteParamsSchema;
|
|
3100
|
-
var ExecuteDatumSchema =
|
|
3101
|
-
id:
|
|
3144
|
+
var ExecuteDatumSchema = import_lucid28.Data.Object({
|
|
3145
|
+
id: import_lucid28.Data.Integer(),
|
|
3102
3146
|
content: ProposalContentSchema,
|
|
3103
|
-
passedTime:
|
|
3104
|
-
votingEndTime:
|
|
3105
|
-
protocolVersion:
|
|
3147
|
+
passedTime: import_lucid28.Data.Integer(),
|
|
3148
|
+
votingEndTime: import_lucid28.Data.Integer(),
|
|
3149
|
+
protocolVersion: import_lucid28.Data.Integer(),
|
|
3106
3150
|
/// Value proposed to be withdrawn from the treasury as part of the proposal.
|
|
3107
|
-
treasuryWithdrawal:
|
|
3151
|
+
treasuryWithdrawal: import_lucid28.Data.Nullable(TreasuryWithdrawalSchema)
|
|
3108
3152
|
});
|
|
3109
3153
|
var ExecuteDatum = ExecuteDatumSchema;
|
|
3110
3154
|
function serialiseExecuteDatum(d) {
|
|
3111
|
-
return
|
|
3155
|
+
return import_lucid28.Data.to(d, ExecuteDatum);
|
|
3112
3156
|
}
|
|
3113
3157
|
function parseExecuteDatum(d) {
|
|
3114
3158
|
try {
|
|
3115
|
-
return
|
|
3159
|
+
return import_fp_ts8.option.some(import_lucid28.Data.from(d, ExecuteDatum));
|
|
3116
3160
|
} catch (_) {
|
|
3117
|
-
return
|
|
3161
|
+
return import_fp_ts8.option.none;
|
|
3118
3162
|
}
|
|
3119
3163
|
}
|
|
3120
3164
|
function parseExecuteDatumOrThrow(d) {
|
|
3121
|
-
return
|
|
3165
|
+
return import_fp_ts8.function.pipe(
|
|
3122
3166
|
parseExecuteDatum(d),
|
|
3123
|
-
|
|
3167
|
+
import_fp_ts8.option.match(() => {
|
|
3124
3168
|
throw new Error("Expected an Execute datum.");
|
|
3125
|
-
},
|
|
3169
|
+
}, import_fp_ts8.function.identity)
|
|
3126
3170
|
);
|
|
3127
3171
|
}
|
|
3128
3172
|
function castExecuteParams(params) {
|
|
3129
|
-
return
|
|
3173
|
+
return import_lucid28.Data.castTo(params, ExecuteParams);
|
|
3130
3174
|
}
|
|
3131
3175
|
|
|
3132
3176
|
// src/contracts/gov/helpers.ts
|
|
3133
3177
|
var import_function = require("fp-ts/lib/function");
|
|
3134
|
-
var
|
|
3135
|
-
var
|
|
3178
|
+
var import_fp_ts9 = require("fp-ts");
|
|
3179
|
+
var import_lucid29 = require("@lucid-evolution/lucid");
|
|
3136
3180
|
function proposalDeposit(baseDeposit, activeProposals) {
|
|
3137
3181
|
return baseDeposit * 2n ** activeProposals;
|
|
3138
3182
|
}
|
|
3139
3183
|
function createValueFromWithdrawal(w) {
|
|
3140
|
-
return
|
|
3184
|
+
return import_fp_ts9.array.reduce(
|
|
3141
3185
|
{},
|
|
3142
|
-
(acc, [cs, tk, amt]) => (0,
|
|
3186
|
+
(acc, [cs, tk, amt]) => (0, import_lucid29.addAssets)(acc, mkAssetsOf({ currencySymbol: cs, tokenName: tk }, amt))
|
|
3143
3187
|
)(w.value);
|
|
3144
3188
|
}
|
|
3145
3189
|
async function findRelativeIAssetForInsertion(newIAssetTokenName, allIAssetOrefs, lucid) {
|
|
@@ -3156,22 +3200,22 @@ async function findRelativeIAssetForInsertion(newIAssetTokenName, allIAssetOrefs
|
|
|
3156
3200
|
return (0, import_function.pipe)(
|
|
3157
3201
|
// Sort the asset names
|
|
3158
3202
|
iassetUtxos,
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3203
|
+
import_fp_ts9.array.sort(
|
|
3204
|
+
import_fp_ts9.ord.contramap((x) => (0, import_lucid29.toText)(x.datum.assetName))(
|
|
3205
|
+
import_fp_ts9.string.Ord
|
|
3162
3206
|
)
|
|
3163
3207
|
),
|
|
3164
3208
|
// split head and tail
|
|
3165
|
-
|
|
3166
|
-
() =>
|
|
3167
|
-
(head, rest) =>
|
|
3209
|
+
import_fp_ts9.array.foldLeft(
|
|
3210
|
+
() => import_fp_ts9.option.none,
|
|
3211
|
+
(head, rest) => import_fp_ts9.option.some([head, rest])
|
|
3168
3212
|
),
|
|
3169
3213
|
// find the preceding iasset for the new token name
|
|
3170
|
-
|
|
3171
|
-
([firstIAsset, rest]) =>
|
|
3172
|
-
|
|
3214
|
+
import_fp_ts9.option.flatMap(
|
|
3215
|
+
([firstIAsset, rest]) => import_fp_ts9.option.some(
|
|
3216
|
+
import_fp_ts9.array.reduce(
|
|
3173
3217
|
firstIAsset,
|
|
3174
|
-
(acc, iasset) => (0,
|
|
3218
|
+
(acc, iasset) => (0, import_lucid29.toText)(iasset.datum.assetName) < newIAssetTokenName ? iasset : acc
|
|
3175
3219
|
)(rest)
|
|
3176
3220
|
)
|
|
3177
3221
|
)
|
|
@@ -3194,22 +3238,22 @@ function iassetCreationDatumHelper(proposeAssetContent, referencedIAsset) {
|
|
|
3194
3238
|
firstIAsset: true,
|
|
3195
3239
|
nextIAsset: null
|
|
3196
3240
|
};
|
|
3197
|
-
return
|
|
3241
|
+
return import_fp_ts9.function.pipe(
|
|
3198
3242
|
referencedIAsset,
|
|
3199
|
-
|
|
3243
|
+
import_fp_ts9.option.match(
|
|
3200
3244
|
() => ({
|
|
3201
3245
|
newIAsset: newContent,
|
|
3202
|
-
newReferencedIAsset:
|
|
3246
|
+
newReferencedIAsset: import_fp_ts9.option.none
|
|
3203
3247
|
}),
|
|
3204
3248
|
(referencedIA) => {
|
|
3205
|
-
if ((0,
|
|
3249
|
+
if ((0, import_lucid29.toText)(proposeAssetContent.asset) < (0, import_lucid29.toText)(referencedIA.assetName)) {
|
|
3206
3250
|
return {
|
|
3207
3251
|
newIAsset: {
|
|
3208
3252
|
...newContent,
|
|
3209
3253
|
firstIAsset: true,
|
|
3210
3254
|
nextIAsset: referencedIA.assetName
|
|
3211
3255
|
},
|
|
3212
|
-
newReferencedIAsset:
|
|
3256
|
+
newReferencedIAsset: import_fp_ts9.option.some({
|
|
3213
3257
|
...referencedIA,
|
|
3214
3258
|
firstIAsset: false
|
|
3215
3259
|
})
|
|
@@ -3221,7 +3265,7 @@ function iassetCreationDatumHelper(proposeAssetContent, referencedIAsset) {
|
|
|
3221
3265
|
firstIAsset: false,
|
|
3222
3266
|
nextIAsset: referencedIA.nextIAsset
|
|
3223
3267
|
},
|
|
3224
|
-
newReferencedIAsset:
|
|
3268
|
+
newReferencedIAsset: import_fp_ts9.option.some({
|
|
3225
3269
|
...referencedIA,
|
|
3226
3270
|
nextIAsset: proposeAssetContent.asset
|
|
3227
3271
|
})
|
|
@@ -3252,9 +3296,9 @@ function serialiseVersionRecordDatum(d) {
|
|
|
3252
3296
|
// src/contracts/gov/transactions.ts
|
|
3253
3297
|
async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lucid, currentSlot, govOref, allIAssetOrefs) {
|
|
3254
3298
|
const network = lucid.config().network;
|
|
3255
|
-
const currentTime = BigInt((0,
|
|
3299
|
+
const currentTime = BigInt((0, import_lucid30.slotToUnixTime)(network, currentSlot));
|
|
3256
3300
|
const ownAddr = await lucid.wallet().address();
|
|
3257
|
-
const pkh = (0,
|
|
3301
|
+
const pkh = (0, import_lucid30.paymentCredentialOf)(ownAddr);
|
|
3258
3302
|
const govRefScriptUtxo = matchSingle(
|
|
3259
3303
|
await lucid.utxosByOutRef([
|
|
3260
3304
|
fromSystemParamsScriptRef(
|
|
@@ -3287,13 +3331,13 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
3287
3331
|
const tx = lucid.newTx();
|
|
3288
3332
|
await (0, import_ts_pattern11.match)(proposalContent).with({ ProposeAsset: { asset: import_ts_pattern11.P.select() } }, async (newAsset) => {
|
|
3289
3333
|
const relativeIAsset = await findRelativeIAssetForInsertion(
|
|
3290
|
-
(0,
|
|
3334
|
+
(0, import_lucid30.toText)(newAsset),
|
|
3291
3335
|
allIAssetOrefs,
|
|
3292
3336
|
lucid
|
|
3293
3337
|
);
|
|
3294
3338
|
(0, import_function2.pipe)(
|
|
3295
3339
|
relativeIAsset,
|
|
3296
|
-
|
|
3340
|
+
import_fp_ts10.option.match(
|
|
3297
3341
|
() => {
|
|
3298
3342
|
if (govDatum.iassetsCount !== 0n) {
|
|
3299
3343
|
throw new Error(
|
|
@@ -3309,7 +3353,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
3309
3353
|
}).otherwise(() => {
|
|
3310
3354
|
});
|
|
3311
3355
|
return [
|
|
3312
|
-
tx.mintAssets(pollNftValue,
|
|
3356
|
+
tx.mintAssets(pollNftValue, import_lucid31.Data.void()).readFrom([govRefScriptUtxo, pollAuthTokenPolicyRefScriptUtxo]).collectFrom(
|
|
3313
3357
|
[govUtxo],
|
|
3314
3358
|
serialiseGovRedeemer({
|
|
3315
3359
|
CreatePoll: {
|
|
@@ -3354,7 +3398,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
3354
3398
|
}
|
|
3355
3399
|
})
|
|
3356
3400
|
},
|
|
3357
|
-
(0,
|
|
3401
|
+
(0, import_lucid30.addAssets)(
|
|
3358
3402
|
pollNftValue,
|
|
3359
3403
|
mkAssetsOf(
|
|
3360
3404
|
fromSystemParamsAsset(sysParams.govParams.indyAsset),
|
|
@@ -3370,7 +3414,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
3370
3414
|
}
|
|
3371
3415
|
async function createShardsChunks(chunkSize, pollManagerOref, sysParams, currentSlot, lucid) {
|
|
3372
3416
|
const network = lucid.config().network;
|
|
3373
|
-
const currentTime = BigInt((0,
|
|
3417
|
+
const currentTime = BigInt((0, import_lucid30.slotToUnixTime)(network, currentSlot));
|
|
3374
3418
|
const ownAddr = await lucid.wallet().address();
|
|
3375
3419
|
const pollManagerUtxo = matchSingle(
|
|
3376
3420
|
await lucid.utxosByOutRef([pollManagerOref]),
|
|
@@ -3407,7 +3451,7 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
|
|
|
3407
3451
|
const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
|
|
3408
3452
|
const tx = lucid.newTx().validFrom(Number(currentTime) - ONE_SECOND).validTo(
|
|
3409
3453
|
Number(currentTime + sysParams.pollManagerParams.pBiasTime) - ONE_SECOND
|
|
3410
|
-
).mintAssets(mkAssetsOf(pollNft, shardsCount),
|
|
3454
|
+
).mintAssets(mkAssetsOf(pollNft, shardsCount), import_lucid31.Data.void()).readFrom([pollAuthTokenPolicyRefScriptUtxo, pollManagerRefScriptUtxo]).collectFrom(
|
|
3411
3455
|
[pollManagerUtxo],
|
|
3412
3456
|
serialisePollManagerRedeemer({ CreateShards: { currentTime } })
|
|
3413
3457
|
).pay.ToContract(
|
|
@@ -3465,7 +3509,7 @@ function voteHelper(stakingPosLockedAmt, pollShard, voteOption, currentTime, ind
|
|
|
3465
3509
|
}
|
|
3466
3510
|
async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, lucid, currentSlot) {
|
|
3467
3511
|
const network = lucid.config().network;
|
|
3468
|
-
const currentTime = BigInt((0,
|
|
3512
|
+
const currentTime = BigInt((0, import_lucid30.slotToUnixTime)(network, currentSlot));
|
|
3469
3513
|
const ownAddr = await lucid.wallet().address();
|
|
3470
3514
|
const pollShardRefScriptUtxo = matchSingle(
|
|
3471
3515
|
await lucid.utxosByOutRef([
|
|
@@ -3541,7 +3585,7 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
|
|
|
3541
3585
|
}
|
|
3542
3586
|
async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, currentSlot) {
|
|
3543
3587
|
const network = lucid.config().network;
|
|
3544
|
-
const currentTime = BigInt((0,
|
|
3588
|
+
const currentTime = BigInt((0, import_lucid30.slotToUnixTime)(network, currentSlot));
|
|
3545
3589
|
const ownAddr = await lucid.wallet().address();
|
|
3546
3590
|
const pollShardRefScriptUtxo = matchSingle(
|
|
3547
3591
|
await lucid.utxosByOutRef([
|
|
@@ -3575,10 +3619,10 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
3575
3619
|
getInlineDatumOrThrow(pollManagerUtxo)
|
|
3576
3620
|
);
|
|
3577
3621
|
const shardUtxos = await lucid.utxosByOutRef(shardsOutRefs);
|
|
3578
|
-
const aggregatedStatus =
|
|
3622
|
+
const aggregatedStatus = import_fp_ts10.function.pipe(
|
|
3579
3623
|
shardUtxos,
|
|
3580
|
-
|
|
3581
|
-
|
|
3624
|
+
import_fp_ts10.array.map((utxo) => parsePollShardOrThrow(getInlineDatumOrThrow(utxo))),
|
|
3625
|
+
import_fp_ts10.array.reduce(
|
|
3582
3626
|
pollManagerDatum.status,
|
|
3583
3627
|
(acc, shard) => ({
|
|
3584
3628
|
yesVotes: acc.yesVotes + shard.status.yesVotes,
|
|
@@ -3586,9 +3630,9 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
3586
3630
|
})
|
|
3587
3631
|
)
|
|
3588
3632
|
);
|
|
3589
|
-
const shardsAggregatedAda =
|
|
3633
|
+
const shardsAggregatedAda = import_fp_ts10.array.reduce(
|
|
3590
3634
|
{},
|
|
3591
|
-
(acc, utxo) => (0,
|
|
3635
|
+
(acc, utxo) => (0, import_lucid30.addAssets)(acc, mkLovelacesOf(lovelacesAmt(utxo.assets)))
|
|
3592
3636
|
)(shardUtxos);
|
|
3593
3637
|
const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
|
|
3594
3638
|
return lucid.newTx().validFrom(Number(currentTime) - ONE_SECOND).validTo(
|
|
@@ -3597,7 +3641,7 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
3597
3641
|
pollShardRefScriptUtxo,
|
|
3598
3642
|
pollManagerRefScriptUtxo,
|
|
3599
3643
|
pollAuthTokenPolicyRefScriptUtxo
|
|
3600
|
-
]).mintAssets(mkAssetsOf(pollNft, -BigInt(shardsOutRefs.length)),
|
|
3644
|
+
]).mintAssets(mkAssetsOf(pollNft, -BigInt(shardsOutRefs.length)), import_lucid31.Data.void()).collectFrom(
|
|
3601
3645
|
[pollManagerUtxo],
|
|
3602
3646
|
serialisePollManagerRedeemer({
|
|
3603
3647
|
MergeShardsManager: { currentTime }
|
|
@@ -3627,12 +3671,12 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
3627
3671
|
}
|
|
3628
3672
|
})
|
|
3629
3673
|
},
|
|
3630
|
-
(0,
|
|
3674
|
+
(0, import_lucid30.addAssets)(pollManagerUtxo.assets, shardsAggregatedAda)
|
|
3631
3675
|
).addSigner(ownAddr);
|
|
3632
3676
|
}
|
|
3633
3677
|
async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSlot) {
|
|
3634
3678
|
const network = lucid.config().network;
|
|
3635
|
-
const currentTime = BigInt((0,
|
|
3679
|
+
const currentTime = BigInt((0, import_lucid30.slotToUnixTime)(network, currentSlot));
|
|
3636
3680
|
const ownAddr = await lucid.wallet().address();
|
|
3637
3681
|
const pollManagerRefScriptUtxo = matchSingle(
|
|
3638
3682
|
await lucid.utxosByOutRef([
|
|
@@ -3707,7 +3751,7 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
|
|
|
3707
3751
|
).collectFrom(
|
|
3708
3752
|
[govUtxo],
|
|
3709
3753
|
serialiseGovRedeemer({ WitnessEndPoll: { currentTime } })
|
|
3710
|
-
).mintAssets(mkAssetsOf(pollNft, -1n),
|
|
3754
|
+
).mintAssets(mkAssetsOf(pollNft, -1n), import_lucid31.Data.void()).pay.ToContract(
|
|
3711
3755
|
govUtxo.address,
|
|
3712
3756
|
{
|
|
3713
3757
|
kind: "inline",
|
|
@@ -3733,11 +3777,11 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
|
|
|
3733
3777
|
})
|
|
3734
3778
|
},
|
|
3735
3779
|
upgradeTokenVal
|
|
3736
|
-
).mintAssets(upgradeTokenVal,
|
|
3780
|
+
).mintAssets(upgradeTokenVal, import_lucid31.Data.void());
|
|
3737
3781
|
} else {
|
|
3738
3782
|
tx.pay.ToContract(
|
|
3739
3783
|
createScriptAddress(network, sysParams.validatorHashes.treasuryHash),
|
|
3740
|
-
{ kind: "inline", value:
|
|
3784
|
+
{ kind: "inline", value: import_lucid31.Data.void() },
|
|
3741
3785
|
mkAssetsOf(
|
|
3742
3786
|
indyAsset,
|
|
3743
3787
|
assetClassValueOf(pollManagerUtxo.assets, indyAsset)
|
|
@@ -3748,7 +3792,7 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
|
|
|
3748
3792
|
}
|
|
3749
3793
|
async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, allIAssetOrefs, modifyIAssetOref, sysParams, lucid, currentSlot) {
|
|
3750
3794
|
const network = lucid.config().network;
|
|
3751
|
-
const currentTime = BigInt((0,
|
|
3795
|
+
const currentTime = BigInt((0, import_lucid30.slotToUnixTime)(network, currentSlot));
|
|
3752
3796
|
const ownAddr = await lucid.wallet().address();
|
|
3753
3797
|
const govUtxo = matchSingle(
|
|
3754
3798
|
await lucid.utxosByOutRef([govOref]),
|
|
@@ -3794,8 +3838,8 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3794
3838
|
);
|
|
3795
3839
|
const tx = lucid.newTx();
|
|
3796
3840
|
await (0, import_function2.pipe)(
|
|
3797
|
-
|
|
3798
|
-
|
|
3841
|
+
import_fp_ts10.option.fromNullable(executeDatum.treasuryWithdrawal),
|
|
3842
|
+
import_fp_ts10.option.match(
|
|
3799
3843
|
() => {
|
|
3800
3844
|
if (treasuryWithdrawalOref) {
|
|
3801
3845
|
throw new Error("Cannot provide withdrawal oref when no withdrawal.");
|
|
@@ -3819,7 +3863,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3819
3863
|
(_) => new Error("Expected a single withdrawal UTXO")
|
|
3820
3864
|
);
|
|
3821
3865
|
const withdrawalVal = createValueFromWithdrawal(withdrawal);
|
|
3822
|
-
const withdrawalChangeVal = (0,
|
|
3866
|
+
const withdrawalChangeVal = (0, import_lucid30.addAssets)(
|
|
3823
3867
|
treasuryWithdrawalUtxo.assets,
|
|
3824
3868
|
negateAssets(withdrawalVal)
|
|
3825
3869
|
);
|
|
@@ -3832,7 +3876,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3832
3876
|
sysParams.treasuryParams.treasuryUtxosStakeCredential
|
|
3833
3877
|
) : void 0
|
|
3834
3878
|
),
|
|
3835
|
-
{ kind: "inline", value:
|
|
3879
|
+
{ kind: "inline", value: import_lucid31.Data.void() },
|
|
3836
3880
|
withdrawalChangeVal
|
|
3837
3881
|
);
|
|
3838
3882
|
}
|
|
@@ -3844,7 +3888,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3844
3888
|
{
|
|
3845
3889
|
kind: "inline",
|
|
3846
3890
|
value: serialiseWithdrawalOutputDatum([
|
|
3847
|
-
(0,
|
|
3891
|
+
(0, import_lucid30.fromText)("IndigoTreasuryWithdrawal"),
|
|
3848
3892
|
{
|
|
3849
3893
|
txHash: { hash: executeUtxo.txHash },
|
|
3850
3894
|
outputIndex: BigInt(executeUtxo.outputIndex)
|
|
@@ -3885,15 +3929,15 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3885
3929
|
throw new Error("Have to provide all iasset orefs when propose asset.");
|
|
3886
3930
|
}
|
|
3887
3931
|
const iassetToReference = await findRelativeIAssetForInsertion(
|
|
3888
|
-
(0,
|
|
3932
|
+
(0, import_lucid30.toText)(proposeContent.asset),
|
|
3889
3933
|
allIAssetOrefs,
|
|
3890
3934
|
lucid
|
|
3891
3935
|
);
|
|
3892
3936
|
const { newIAsset, newReferencedIAsset } = iassetCreationDatumHelper(
|
|
3893
3937
|
proposeContent,
|
|
3894
|
-
|
|
3938
|
+
import_fp_ts10.function.pipe(
|
|
3895
3939
|
iassetToReference,
|
|
3896
|
-
|
|
3940
|
+
import_fp_ts10.option.map((i) => i.datum)
|
|
3897
3941
|
)
|
|
3898
3942
|
);
|
|
3899
3943
|
const iassetAuthVal = mkAssetsOf(
|
|
@@ -3909,7 +3953,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3909
3953
|
cdpRefScriptUtxo,
|
|
3910
3954
|
iassetTokenPolicyRefScriptUtxo,
|
|
3911
3955
|
stabilityPoolTokenPolicyRefScriptUtxo
|
|
3912
|
-
]).mintAssets(spAuthVal,
|
|
3956
|
+
]).mintAssets(spAuthVal, import_lucid31.Data.void()).mintAssets(iassetAuthVal, import_lucid31.Data.void()).collectFrom([govUtxo], serialiseGovRedeemer("UpgradeGov")).pay.ToContract(
|
|
3913
3957
|
govUtxo.address,
|
|
3914
3958
|
{
|
|
3915
3959
|
kind: "inline",
|
|
@@ -3934,7 +3978,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3934
3978
|
value: serialiseStabilityPoolDatum(
|
|
3935
3979
|
{
|
|
3936
3980
|
StabilityPool: {
|
|
3937
|
-
asset: (0,
|
|
3981
|
+
asset: (0, import_lucid30.fromHex)(proposeContent.asset),
|
|
3938
3982
|
poolSnapshot: initSpSnapshot,
|
|
3939
3983
|
epochToScaleToSum: initEpochToScaleToSumMap()
|
|
3940
3984
|
}
|
|
@@ -3944,14 +3988,14 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3944
3988
|
},
|
|
3945
3989
|
spAuthVal
|
|
3946
3990
|
);
|
|
3947
|
-
|
|
3991
|
+
import_fp_ts10.function.pipe(
|
|
3948
3992
|
iassetToReference,
|
|
3949
|
-
|
|
3993
|
+
import_fp_ts10.option.match(
|
|
3950
3994
|
() => {
|
|
3951
3995
|
},
|
|
3952
|
-
(i) =>
|
|
3996
|
+
(i) => import_fp_ts10.function.pipe(
|
|
3953
3997
|
newReferencedIAsset,
|
|
3954
|
-
|
|
3998
|
+
import_fp_ts10.option.match(
|
|
3955
3999
|
() => {
|
|
3956
4000
|
throw new Error("Expected some referenced iasset.");
|
|
3957
4001
|
},
|
|
@@ -4075,7 +4119,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
4075
4119
|
fromSystemParamsAsset(sysParams.executeParams.versionRecordToken),
|
|
4076
4120
|
1n
|
|
4077
4121
|
);
|
|
4078
|
-
tx.readFrom([govRefScriptUtxo, versionRecordTokenPolicyRefScriptUtxo]).mintAssets(versionRecordNftVal,
|
|
4122
|
+
tx.readFrom([govRefScriptUtxo, versionRecordTokenPolicyRefScriptUtxo]).mintAssets(versionRecordNftVal, import_lucid31.Data.void()).pay.ToContract(
|
|
4079
4123
|
createScriptAddress(
|
|
4080
4124
|
network,
|
|
4081
4125
|
sysParams.validatorHashes.versionRegistryHash
|
|
@@ -4103,52 +4147,52 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
4103
4147
|
govUtxo.assets
|
|
4104
4148
|
);
|
|
4105
4149
|
}).exhaustive();
|
|
4106
|
-
tx.readFrom([upgradeTokenPolicyRefScriptUtxo, executeRefScriptUtxo]).validFrom(Number(currentTime) - ONE_SECOND).validTo(Number(currentTime + sysParams.govParams.gBiasTime) - ONE_SECOND).collectFrom([executeUtxo],
|
|
4150
|
+
tx.readFrom([upgradeTokenPolicyRefScriptUtxo, executeRefScriptUtxo]).validFrom(Number(currentTime) - ONE_SECOND).validTo(Number(currentTime + sysParams.govParams.gBiasTime) - ONE_SECOND).collectFrom([executeUtxo], import_lucid31.Data.void()).mintAssets(
|
|
4107
4151
|
mkAssetsOf(fromSystemParamsAsset(sysParams.govParams.upgradeToken), -1n),
|
|
4108
|
-
|
|
4152
|
+
import_lucid31.Data.void()
|
|
4109
4153
|
).addSigner(ownAddr);
|
|
4110
4154
|
return tx;
|
|
4111
4155
|
}
|
|
4112
4156
|
|
|
4113
4157
|
// src/contracts/stability-pool/transactions.ts
|
|
4114
|
-
var
|
|
4158
|
+
var import_lucid34 = require("@lucid-evolution/lucid");
|
|
4115
4159
|
|
|
4116
4160
|
// src/contracts/stability-pool/types.ts
|
|
4117
|
-
var
|
|
4118
|
-
var ActionReturnDatumSchema =
|
|
4119
|
-
|
|
4120
|
-
IndigoStabilityPoolAccountAdjustment:
|
|
4161
|
+
var import_lucid32 = require("@lucid-evolution/lucid");
|
|
4162
|
+
var ActionReturnDatumSchema = import_lucid32.Data.Enum([
|
|
4163
|
+
import_lucid32.Data.Object({
|
|
4164
|
+
IndigoStabilityPoolAccountAdjustment: import_lucid32.Data.Object({
|
|
4121
4165
|
spent_account: OutputReferenceSchema
|
|
4122
4166
|
})
|
|
4123
4167
|
}),
|
|
4124
|
-
|
|
4125
|
-
IndigoStabilityPoolAccountClosure:
|
|
4168
|
+
import_lucid32.Data.Object({
|
|
4169
|
+
IndigoStabilityPoolAccountClosure: import_lucid32.Data.Object({
|
|
4126
4170
|
closed_account: OutputReferenceSchema
|
|
4127
4171
|
})
|
|
4128
4172
|
})
|
|
4129
4173
|
]);
|
|
4130
4174
|
var ActionReturnDatum = ActionReturnDatumSchema;
|
|
4131
|
-
var StabilityPoolParamsSchema =
|
|
4132
|
-
assetSymbol:
|
|
4175
|
+
var StabilityPoolParamsSchema = import_lucid32.Data.Object({
|
|
4176
|
+
assetSymbol: import_lucid32.Data.Bytes(),
|
|
4133
4177
|
stabilityPoolToken: AssetClassSchema,
|
|
4134
4178
|
snapshotEpochToScaleToSumToken: AssetClassSchema,
|
|
4135
4179
|
accountToken: AssetClassSchema,
|
|
4136
4180
|
cdpToken: AssetClassSchema,
|
|
4137
4181
|
iAssetAuthToken: AssetClassSchema,
|
|
4138
4182
|
versionRecordToken: AssetClassSchema,
|
|
4139
|
-
collectorValHash:
|
|
4183
|
+
collectorValHash: import_lucid32.Data.Bytes(),
|
|
4140
4184
|
govNFT: AssetClassSchema,
|
|
4141
|
-
accountCreateFeeLovelaces:
|
|
4142
|
-
accountAdjustmentFeeLovelaces:
|
|
4143
|
-
requestCollateralLovelaces:
|
|
4185
|
+
accountCreateFeeLovelaces: import_lucid32.Data.Integer(),
|
|
4186
|
+
accountAdjustmentFeeLovelaces: import_lucid32.Data.Integer(),
|
|
4187
|
+
requestCollateralLovelaces: import_lucid32.Data.Integer()
|
|
4144
4188
|
});
|
|
4145
4189
|
var StabilityPoolParams = StabilityPoolParamsSchema;
|
|
4146
4190
|
function castStabilityPoolParams(params) {
|
|
4147
|
-
return
|
|
4191
|
+
return import_lucid32.Data.castTo(params, StabilityPoolParams);
|
|
4148
4192
|
}
|
|
4149
4193
|
|
|
4150
4194
|
// src/contracts/stability-pool/scripts.ts
|
|
4151
|
-
var
|
|
4195
|
+
var import_lucid33 = require("@lucid-evolution/lucid");
|
|
4152
4196
|
|
|
4153
4197
|
// src/validators/stability-pool-validator.ts
|
|
4154
4198
|
var _stabilityPoolValidator = {
|
|
@@ -4161,7 +4205,7 @@ var _stabilityPoolValidator = {
|
|
|
4161
4205
|
var mkStabilityPoolValidatorFromSP = (params) => {
|
|
4162
4206
|
return {
|
|
4163
4207
|
type: "PlutusV2",
|
|
4164
|
-
script: (0,
|
|
4208
|
+
script: (0, import_lucid33.applyParamsToScript)(_stabilityPoolValidator.cborHex, [
|
|
4165
4209
|
castStabilityPoolParams({
|
|
4166
4210
|
assetSymbol: params.assetSymbol.unCurrencySymbol,
|
|
4167
4211
|
stabilityPoolToken: fromSystemParamsAsset(params.stabilityPoolToken),
|
|
@@ -4192,8 +4236,8 @@ async function createSpAccount(asset, amount, params, lucid) {
|
|
|
4192
4236
|
params.stabilityPoolParams.accountCreateFeeLovelaces + params.stabilityPoolParams.requestCollateralLovelaces
|
|
4193
4237
|
);
|
|
4194
4238
|
const datum = {
|
|
4195
|
-
owner: (0,
|
|
4196
|
-
asset: (0,
|
|
4239
|
+
owner: (0, import_lucid34.fromHex)(pkh.hash),
|
|
4240
|
+
asset: (0, import_lucid34.fromHex)((0, import_lucid34.fromText)(asset)),
|
|
4197
4241
|
accountSnapshot: {
|
|
4198
4242
|
productVal: { value: 0n },
|
|
4199
4243
|
depositVal: { value: 0n },
|
|
@@ -4204,8 +4248,8 @@ async function createSpAccount(asset, amount, params, lucid) {
|
|
|
4204
4248
|
request: "Create"
|
|
4205
4249
|
};
|
|
4206
4250
|
return lucid.newTx().pay.ToContract(
|
|
4207
|
-
(0,
|
|
4208
|
-
hash: (0,
|
|
4251
|
+
(0, import_lucid34.credentialToAddress)(lucid.config().network, {
|
|
4252
|
+
hash: (0, import_lucid34.validatorToScriptHash)(
|
|
4209
4253
|
mkStabilityPoolValidatorFromSP(params.stabilityPoolParams)
|
|
4210
4254
|
),
|
|
4211
4255
|
type: "Script"
|
|
@@ -4216,7 +4260,7 @@ async function createSpAccount(asset, amount, params, lucid) {
|
|
|
4216
4260
|
},
|
|
4217
4261
|
{
|
|
4218
4262
|
lovelace: minLovelaces,
|
|
4219
|
-
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
4263
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid34.fromText)(asset)]: amount
|
|
4220
4264
|
}
|
|
4221
4265
|
).addSignerKey(pkh.hash);
|
|
4222
4266
|
}
|
|
@@ -4242,10 +4286,10 @@ async function adjustSpAccount(asset, amount, accountUtxo, params, lucid) {
|
|
|
4242
4286
|
lovelace: BigInt(
|
|
4243
4287
|
params.stabilityPoolParams.requestCollateralLovelaces + params.stabilityPoolParams.accountAdjustmentFeeLovelaces
|
|
4244
4288
|
),
|
|
4245
|
-
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0,
|
|
4289
|
+
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid34.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
|
|
4246
4290
|
};
|
|
4247
4291
|
if (amount > 0n) {
|
|
4248
|
-
value[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
4292
|
+
value[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid34.fromText)(asset)] = amount;
|
|
4249
4293
|
}
|
|
4250
4294
|
return lucid.newTx().readFrom([stabilityPoolScriptRef]).collectFrom(
|
|
4251
4295
|
[accountUtxo],
|
|
@@ -4258,8 +4302,8 @@ async function adjustSpAccount(asset, amount, accountUtxo, params, lucid) {
|
|
|
4258
4302
|
}
|
|
4259
4303
|
})
|
|
4260
4304
|
).pay.ToContract(
|
|
4261
|
-
(0,
|
|
4262
|
-
hash: (0,
|
|
4305
|
+
(0, import_lucid34.credentialToAddress)(lucid.config().network, {
|
|
4306
|
+
hash: (0, import_lucid34.validatorToScriptHash)(
|
|
4263
4307
|
mkStabilityPoolValidatorFromSP(params.stabilityPoolParams)
|
|
4264
4308
|
),
|
|
4265
4309
|
type: "Script"
|
|
@@ -4271,7 +4315,7 @@ async function adjustSpAccount(asset, amount, accountUtxo, params, lucid) {
|
|
|
4271
4315
|
})
|
|
4272
4316
|
},
|
|
4273
4317
|
value
|
|
4274
|
-
).addSignerKey((0,
|
|
4318
|
+
).addSignerKey((0, import_lucid34.toHex)(oldAccountDatum.owner));
|
|
4275
4319
|
}
|
|
4276
4320
|
async function closeSpAccount(accountUtxo, params, lucid) {
|
|
4277
4321
|
const myAddress = await lucid.wallet().address();
|
|
@@ -4295,8 +4339,8 @@ async function closeSpAccount(accountUtxo, params, lucid) {
|
|
|
4295
4339
|
[accountUtxo],
|
|
4296
4340
|
serialiseStabilityPoolRedeemer({ RequestAction: request })
|
|
4297
4341
|
).pay.ToContract(
|
|
4298
|
-
(0,
|
|
4299
|
-
hash: (0,
|
|
4342
|
+
(0, import_lucid34.credentialToAddress)(lucid.config().network, {
|
|
4343
|
+
hash: (0, import_lucid34.validatorToScriptHash)(
|
|
4300
4344
|
mkStabilityPoolValidatorFromSP(params.stabilityPoolParams)
|
|
4301
4345
|
),
|
|
4302
4346
|
type: "Script"
|
|
@@ -4309,14 +4353,14 @@ async function closeSpAccount(accountUtxo, params, lucid) {
|
|
|
4309
4353
|
lovelace: BigInt(
|
|
4310
4354
|
params.stabilityPoolParams.requestCollateralLovelaces + params.stabilityPoolParams.accountAdjustmentFeeLovelaces
|
|
4311
4355
|
),
|
|
4312
|
-
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0,
|
|
4356
|
+
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid34.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
|
|
4313
4357
|
}
|
|
4314
|
-
).addSignerKey((0,
|
|
4358
|
+
).addSignerKey((0, import_lucid34.toHex)(oldAccountDatum.owner));
|
|
4315
4359
|
}
|
|
4316
4360
|
async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo, iAssetUtxo, newSnapshotUtxo, params, lucid, collectorOref) {
|
|
4317
4361
|
const redeemer = {
|
|
4318
4362
|
ProcessRequest: {
|
|
4319
|
-
txHash: { hash: (0,
|
|
4363
|
+
txHash: { hash: (0, import_lucid34.fromHex)(accountUtxo.txHash) },
|
|
4320
4364
|
outputIndex: BigInt(accountUtxo.outputIndex)
|
|
4321
4365
|
}
|
|
4322
4366
|
};
|
|
@@ -4336,7 +4380,7 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4336
4380
|
lucid
|
|
4337
4381
|
);
|
|
4338
4382
|
tx.readFrom([accountTokenScriptRef]);
|
|
4339
|
-
const iassetUnit = params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
4383
|
+
const iassetUnit = params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid34.fromText)(asset);
|
|
4340
4384
|
const reqAmount = accountUtxo.assets[iassetUnit] ?? 0n;
|
|
4341
4385
|
const newAccountSnapshot = {
|
|
4342
4386
|
...stabilityPoolDatum.poolSnapshot,
|
|
@@ -4377,14 +4421,14 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4377
4421
|
const stabilityPoolAssetToken = stabilityPoolUtxo.assets[iassetUnit] ?? 0n;
|
|
4378
4422
|
const poolOutputValue = {
|
|
4379
4423
|
lovelace: stabilityPoolUtxo.assets.lovelace + BigInt(params.stabilityPoolParams.accountCreateFeeLovelaces),
|
|
4380
|
-
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + (0,
|
|
4381
|
-
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
4424
|
+
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + (0, import_lucid34.fromText)(params.stabilityPoolParams.stabilityPoolToken[1].unTokenName)]: 1n,
|
|
4425
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid34.fromText)(asset)]: stabilityPoolAssetToken + reqAmount
|
|
4382
4426
|
};
|
|
4383
4427
|
tx.mintAssets(
|
|
4384
4428
|
{
|
|
4385
|
-
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0,
|
|
4429
|
+
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid34.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
|
|
4386
4430
|
},
|
|
4387
|
-
|
|
4431
|
+
import_lucid34.Data.to(new import_lucid34.Constr(0, []))
|
|
4388
4432
|
);
|
|
4389
4433
|
tx.pay.ToContract(
|
|
4390
4434
|
stabilityPoolUtxo.address,
|
|
@@ -4414,7 +4458,7 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4414
4458
|
},
|
|
4415
4459
|
{
|
|
4416
4460
|
lovelace: accountUtxo.assets.lovelace - BigInt(params.stabilityPoolParams.accountCreateFeeLovelaces),
|
|
4417
|
-
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0,
|
|
4461
|
+
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid34.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
|
|
4418
4462
|
}
|
|
4419
4463
|
);
|
|
4420
4464
|
} else if ("Adjust" in accountDatum.request) {
|
|
@@ -4519,8 +4563,8 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4519
4563
|
},
|
|
4520
4564
|
{
|
|
4521
4565
|
lovelace: stabilityPoolUtxo.assets.lovelace + BigInt(params.stabilityPoolParams.accountAdjustmentFeeLovelaces) - reward,
|
|
4522
|
-
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + (0,
|
|
4523
|
-
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
4566
|
+
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + (0, import_lucid34.fromText)(params.stabilityPoolParams.stabilityPoolToken[1].unTokenName)]: 1n,
|
|
4567
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid34.fromText)(asset)]: stabilityPoolUtxo.assets[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid34.fromText)(asset)] + balanceChange + withdrawalFee
|
|
4524
4568
|
}
|
|
4525
4569
|
);
|
|
4526
4570
|
tx.pay.ToContract(
|
|
@@ -4537,7 +4581,7 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4537
4581
|
},
|
|
4538
4582
|
{
|
|
4539
4583
|
lovelace: accountUtxo.assets.lovelace - BigInt(params.stabilityPoolParams.accountAdjustmentFeeLovelaces) - 2000000n,
|
|
4540
|
-
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0,
|
|
4584
|
+
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid34.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
|
|
4541
4585
|
}
|
|
4542
4586
|
);
|
|
4543
4587
|
if (myAddress !== outputAddress) {
|
|
@@ -4545,7 +4589,7 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4545
4589
|
outputAddress,
|
|
4546
4590
|
{
|
|
4547
4591
|
kind: "inline",
|
|
4548
|
-
value:
|
|
4592
|
+
value: import_lucid34.Data.to(
|
|
4549
4593
|
{
|
|
4550
4594
|
IndigoStabilityPoolAccountAdjustment: {
|
|
4551
4595
|
spent_account: {
|
|
@@ -4560,7 +4604,7 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4560
4604
|
{
|
|
4561
4605
|
lovelace: reward - rewardLovelacesFee + 2000000n,
|
|
4562
4606
|
...!isDepositOrRewardWithdrawal ? {
|
|
4563
|
-
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
4607
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid34.fromText)(asset)]: -balanceChange - withdrawalFee
|
|
4564
4608
|
} : {}
|
|
4565
4609
|
}
|
|
4566
4610
|
);
|
|
@@ -4617,11 +4661,11 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4617
4661
|
tx.readFrom([govUtxo, iAssetUtxo, accountTokenRef, ...refInputs]);
|
|
4618
4662
|
tx.mintAssets(
|
|
4619
4663
|
{
|
|
4620
|
-
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0,
|
|
4664
|
+
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid34.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: -1n
|
|
4621
4665
|
},
|
|
4622
|
-
|
|
4666
|
+
import_lucid34.Data.to(new import_lucid34.Constr(0, []))
|
|
4623
4667
|
);
|
|
4624
|
-
const assetOutputAmountForSP = stabilityPoolUtxo.assets[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
4668
|
+
const assetOutputAmountForSP = stabilityPoolUtxo.assets[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid34.fromText)(asset)] - fromSPInteger(withdrawnAmt) - withdrawalFeeAmount;
|
|
4625
4669
|
tx.pay.ToContract(
|
|
4626
4670
|
stabilityPoolUtxo.address,
|
|
4627
4671
|
{
|
|
@@ -4635,9 +4679,9 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4635
4679
|
},
|
|
4636
4680
|
{
|
|
4637
4681
|
lovelace: stabilityPoolUtxo.assets.lovelace - reward,
|
|
4638
|
-
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + (0,
|
|
4682
|
+
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + (0, import_lucid34.fromText)(params.stabilityPoolParams.stabilityPoolToken[1].unTokenName)]: 1n,
|
|
4639
4683
|
...assetOutputAmountForSP > 0n ? {
|
|
4640
|
-
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
4684
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid34.fromText)(asset)]: assetOutputAmountForSP
|
|
4641
4685
|
} : {}
|
|
4642
4686
|
}
|
|
4643
4687
|
);
|
|
@@ -4646,7 +4690,7 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4646
4690
|
outputAddress,
|
|
4647
4691
|
{
|
|
4648
4692
|
kind: "inline",
|
|
4649
|
-
value:
|
|
4693
|
+
value: import_lucid34.Data.to(
|
|
4650
4694
|
{
|
|
4651
4695
|
IndigoStabilityPoolAccountClosure: {
|
|
4652
4696
|
closed_account: {
|
|
@@ -4660,7 +4704,7 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4660
4704
|
},
|
|
4661
4705
|
{
|
|
4662
4706
|
lovelace: accountUtxo.assets.lovelace + reward - rewardLovelacesFee,
|
|
4663
|
-
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
4707
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid34.fromText)(asset)]: fromSPInteger(withdrawnAmt) - withdrawalFeeAmount
|
|
4664
4708
|
}
|
|
4665
4709
|
);
|
|
4666
4710
|
}
|
|
@@ -4669,7 +4713,7 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4669
4713
|
}
|
|
4670
4714
|
|
|
4671
4715
|
// src/contracts/staking/transactions.ts
|
|
4672
|
-
var
|
|
4716
|
+
var import_lucid35 = require("@lucid-evolution/lucid");
|
|
4673
4717
|
async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
4674
4718
|
const [pkh, _] = await addrDetails(lucid);
|
|
4675
4719
|
const stakingManagerOut = stakingManagerRef ? await findStakingManagerByOutRef(stakingManagerRef, lucid) : await findStakingManager(params, lucid);
|
|
@@ -4694,15 +4738,15 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4694
4738
|
}
|
|
4695
4739
|
};
|
|
4696
4740
|
const stakingPositionDatum = {
|
|
4697
|
-
owner: (0,
|
|
4741
|
+
owner: (0, import_lucid35.fromHex)(pkh.hash),
|
|
4698
4742
|
lockedAmount: /* @__PURE__ */ new Map([]),
|
|
4699
4743
|
positionSnapshot: {
|
|
4700
4744
|
snapshotAda: stakingManagerOut.datum.managerSnapshot.snapshotAda
|
|
4701
4745
|
}
|
|
4702
4746
|
};
|
|
4703
|
-
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0,
|
|
4704
|
-
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0,
|
|
4705
|
-
return lucid.newTx().collectFrom([stakingManagerOut.utxo],
|
|
4747
|
+
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingToken[1].unTokenName);
|
|
4748
|
+
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
4749
|
+
return lucid.newTx().collectFrom([stakingManagerOut.utxo], import_lucid35.Data.to(new import_lucid35.Constr(0, [pkh.hash]))).readFrom([stakingRefScriptUtxo]).pay.ToContract(
|
|
4706
4750
|
stakingManagerOut.utxo.address,
|
|
4707
4751
|
{
|
|
4708
4752
|
kind: "inline",
|
|
@@ -4713,7 +4757,7 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4713
4757
|
{
|
|
4714
4758
|
[stakingToken]: 1n
|
|
4715
4759
|
},
|
|
4716
|
-
|
|
4760
|
+
import_lucid35.Data.void()
|
|
4717
4761
|
).pay.ToContract(
|
|
4718
4762
|
stakingManagerOut.utxo.address,
|
|
4719
4763
|
{
|
|
@@ -4739,18 +4783,26 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4739
4783
|
]),
|
|
4740
4784
|
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
4741
4785
|
);
|
|
4742
|
-
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0,
|
|
4743
|
-
const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0,
|
|
4744
|
-
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0,
|
|
4786
|
+
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingToken[1].unTokenName);
|
|
4787
|
+
const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingManagerNFT[1].unTokenName);
|
|
4788
|
+
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
4745
4789
|
const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
|
|
4746
4790
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
4747
4791
|
const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
|
|
4748
|
-
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount /
|
|
4792
|
+
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / rewardSnapshotPrecision;
|
|
4749
4793
|
const newLockedAmount = updateStakingLockedAmount(
|
|
4750
4794
|
stakingPositionOut.datum.lockedAmount,
|
|
4751
4795
|
BigInt(now)
|
|
4752
4796
|
);
|
|
4753
|
-
return lucid.newTx().validFrom(Date.now()).readFrom([stakingRefScriptUtxo]).collectFrom(
|
|
4797
|
+
return lucid.newTx().validFrom(Date.now()).readFrom([stakingRefScriptUtxo]).collectFrom(
|
|
4798
|
+
[stakingPositionOut.utxo],
|
|
4799
|
+
serialiseStakingRedeemer({
|
|
4800
|
+
AdjustStakedAmount: { adjustAmount: amount }
|
|
4801
|
+
})
|
|
4802
|
+
).collectFrom(
|
|
4803
|
+
[stakingManagerOut.utxo],
|
|
4804
|
+
serialiseStakingRedeemer("UpdateTotalStake")
|
|
4805
|
+
).pay.ToContract(
|
|
4754
4806
|
stakingManagerOut.utxo.address,
|
|
4755
4807
|
{
|
|
4756
4808
|
kind: "inline",
|
|
@@ -4776,7 +4828,7 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4776
4828
|
[stakingToken]: 1n,
|
|
4777
4829
|
[indyToken]: stakingPositionOut.utxo.assets[indyToken] + amount
|
|
4778
4830
|
}
|
|
4779
|
-
).addSignerKey((0,
|
|
4831
|
+
).addSignerKey((0, import_lucid35.toHex)(stakingPositionOut.datum.owner));
|
|
4780
4832
|
}
|
|
4781
4833
|
async function closeStakingPosition(stakingPositionRef, params, lucid, stakingManagerRef) {
|
|
4782
4834
|
const stakingPositionOut = await findStakingPositionByOutRef(
|
|
@@ -4798,14 +4850,14 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, stakingMa
|
|
|
4798
4850
|
]),
|
|
4799
4851
|
(_) => new Error("Expected a single staking token policy Ref Script UTXO")
|
|
4800
4852
|
);
|
|
4801
|
-
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0,
|
|
4802
|
-
const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0,
|
|
4803
|
-
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0,
|
|
4853
|
+
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingToken[1].unTokenName);
|
|
4854
|
+
const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingManagerNFT[1].unTokenName);
|
|
4855
|
+
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
4804
4856
|
const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
|
|
4805
4857
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
4806
4858
|
const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
|
|
4807
4859
|
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
|
|
4808
|
-
return lucid.newTx().validFrom(Date.now()).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo],
|
|
4860
|
+
return lucid.newTx().validFrom(Date.now()).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], import_lucid35.Data.to(new import_lucid35.Constr(4, []))).collectFrom([stakingManagerOut.utxo], import_lucid35.Data.to(new import_lucid35.Constr(1, []))).pay.ToContract(
|
|
4809
4861
|
stakingManagerOut.utxo.address,
|
|
4810
4862
|
{
|
|
4811
4863
|
kind: "inline",
|
|
@@ -4822,37 +4874,91 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, stakingMa
|
|
|
4822
4874
|
{
|
|
4823
4875
|
[stakingToken]: -1n
|
|
4824
4876
|
},
|
|
4825
|
-
|
|
4826
|
-
).addSignerKey((0,
|
|
4877
|
+
import_lucid35.Data.void()
|
|
4878
|
+
).addSignerKey((0, import_lucid35.toHex)(stakingPositionOut.datum.owner));
|
|
4879
|
+
}
|
|
4880
|
+
var MIN_UTXO_AMOUNT = 2000000n;
|
|
4881
|
+
async function distributeAda(stakingManagerRef, collectorRefs, params, lucid) {
|
|
4882
|
+
const [stakingManagerUtxo] = await lucid.utxosByOutRef([stakingManagerRef]);
|
|
4883
|
+
const stakingManagerDatum = parseStakingManagerDatum(
|
|
4884
|
+
getInlineDatumOrThrow(stakingManagerUtxo)
|
|
4885
|
+
);
|
|
4886
|
+
const collectorUtxos = (await lucid.utxosByOutRef(collectorRefs)).filter((utxo) => utxo.datum && utxo.datum === import_lucid35.Data.void()).filter((utxo) => utxo.assets.lovelace > MIN_UTXO_AMOUNT);
|
|
4887
|
+
if (collectorUtxos.length === 0) {
|
|
4888
|
+
throw new Error("No available collectors found");
|
|
4889
|
+
}
|
|
4890
|
+
const adaRewardCollected = collectorUtxos.reduce(
|
|
4891
|
+
(acc, utxo) => acc + utxo.assets.lovelace - MIN_UTXO_AMOUNT,
|
|
4892
|
+
0n
|
|
4893
|
+
);
|
|
4894
|
+
const newSnapshot = distributeReward(
|
|
4895
|
+
stakingManagerDatum.managerSnapshot.snapshotAda,
|
|
4896
|
+
adaRewardCollected,
|
|
4897
|
+
stakingManagerDatum.totalStake
|
|
4898
|
+
);
|
|
4899
|
+
const stakingRefScriptUtxo = matchSingle(
|
|
4900
|
+
await lucid.utxosByOutRef([
|
|
4901
|
+
fromSystemParamsScriptRef(params.scriptReferences.stakingValidatorRef)
|
|
4902
|
+
]),
|
|
4903
|
+
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
4904
|
+
);
|
|
4905
|
+
const collectorRefScriptUtxo = matchSingle(
|
|
4906
|
+
await lucid.utxosByOutRef([
|
|
4907
|
+
fromSystemParamsScriptRef(params.scriptReferences.collectorValidatorRef)
|
|
4908
|
+
]),
|
|
4909
|
+
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
4910
|
+
);
|
|
4911
|
+
const tx = lucid.newTx().readFrom([stakingRefScriptUtxo, collectorRefScriptUtxo]).collectFrom([stakingManagerUtxo], serialiseStakingRedeemer("Distribute")).collectFrom(
|
|
4912
|
+
collectorUtxos,
|
|
4913
|
+
serialiseCollectorRedeemer("DistributeToStakers")
|
|
4914
|
+
).pay.ToContract(
|
|
4915
|
+
stakingManagerUtxo.address,
|
|
4916
|
+
{
|
|
4917
|
+
kind: "inline",
|
|
4918
|
+
value: serialiseStakingDatum({
|
|
4919
|
+
...stakingManagerDatum,
|
|
4920
|
+
managerSnapshot: { snapshotAda: newSnapshot }
|
|
4921
|
+
})
|
|
4922
|
+
},
|
|
4923
|
+
(0, import_lucid35.addAssets)(stakingManagerUtxo.assets, mkLovelacesOf(adaRewardCollected))
|
|
4924
|
+
);
|
|
4925
|
+
for (const collectorUtxo of collectorUtxos) {
|
|
4926
|
+
tx.pay.ToContract(
|
|
4927
|
+
collectorUtxo.address,
|
|
4928
|
+
{ kind: "inline", value: import_lucid35.Data.void() },
|
|
4929
|
+
mkLovelacesOf(MIN_UTXO_AMOUNT)
|
|
4930
|
+
);
|
|
4931
|
+
}
|
|
4932
|
+
return tx;
|
|
4827
4933
|
}
|
|
4828
4934
|
|
|
4829
4935
|
// src/contracts/interest-oracle/transactions.ts
|
|
4830
|
-
var
|
|
4936
|
+
var import_lucid40 = require("@lucid-evolution/lucid");
|
|
4831
4937
|
|
|
4832
4938
|
// src/contracts/one-shot/transactions.ts
|
|
4833
|
-
var
|
|
4939
|
+
var import_lucid38 = require("@lucid-evolution/lucid");
|
|
4834
4940
|
|
|
4835
4941
|
// src/contracts/one-shot/scripts.ts
|
|
4836
|
-
var
|
|
4942
|
+
var import_lucid37 = require("@lucid-evolution/lucid");
|
|
4837
4943
|
|
|
4838
4944
|
// src/contracts/one-shot/types.ts
|
|
4839
|
-
var
|
|
4840
|
-
var OneShotParamsSchema =
|
|
4841
|
-
referenceOutRef:
|
|
4842
|
-
txHash:
|
|
4843
|
-
outputIdx:
|
|
4945
|
+
var import_lucid36 = require("@lucid-evolution/lucid");
|
|
4946
|
+
var OneShotParamsSchema = import_lucid36.Data.Object({
|
|
4947
|
+
referenceOutRef: import_lucid36.Data.Object({
|
|
4948
|
+
txHash: import_lucid36.Data.Bytes(),
|
|
4949
|
+
outputIdx: import_lucid36.Data.Integer()
|
|
4844
4950
|
}),
|
|
4845
|
-
mintAmounts:
|
|
4846
|
-
|
|
4951
|
+
mintAmounts: import_lucid36.Data.Array(
|
|
4952
|
+
import_lucid36.Data.Object({
|
|
4847
4953
|
/// Use hex encoded string
|
|
4848
|
-
tokenName:
|
|
4849
|
-
amount:
|
|
4954
|
+
tokenName: import_lucid36.Data.Bytes(),
|
|
4955
|
+
amount: import_lucid36.Data.Integer()
|
|
4850
4956
|
})
|
|
4851
4957
|
)
|
|
4852
4958
|
});
|
|
4853
4959
|
var OneShotParams = OneShotParamsSchema;
|
|
4854
4960
|
function castOneShotParams(params) {
|
|
4855
|
-
return
|
|
4961
|
+
return import_lucid36.Data.castTo(params, OneShotParams);
|
|
4856
4962
|
}
|
|
4857
4963
|
|
|
4858
4964
|
// src/contracts/one-shot/scripts.ts
|
|
@@ -4863,7 +4969,7 @@ var oneShotPolicyData = {
|
|
|
4863
4969
|
function mkOneShotPolicy(params) {
|
|
4864
4970
|
return {
|
|
4865
4971
|
type: oneShotPolicyData.type,
|
|
4866
|
-
script: (0,
|
|
4972
|
+
script: (0, import_lucid37.applyParamsToScript)(oneShotPolicyData.cborHex, [
|
|
4867
4973
|
castOneShotParams(params)
|
|
4868
4974
|
])
|
|
4869
4975
|
};
|
|
@@ -4873,7 +4979,7 @@ function mkOneShotPolicy(params) {
|
|
|
4873
4979
|
var import_Array = require("fp-ts/lib/Array");
|
|
4874
4980
|
async function oneShotMintTx(lucid, params) {
|
|
4875
4981
|
const oneShotPolicy = mkOneShotPolicy(params);
|
|
4876
|
-
const policyId = (0,
|
|
4982
|
+
const policyId = (0, import_lucid38.mintingPolicyToId)(oneShotPolicy);
|
|
4877
4983
|
const refUtxo = matchSingle(
|
|
4878
4984
|
await lucid.utxosByOutRef([
|
|
4879
4985
|
{
|
|
@@ -4889,11 +4995,11 @@ async function oneShotMintTx(lucid, params) {
|
|
|
4889
4995
|
lucid.newTx().collectFrom([refUtxo]).mintAssets(
|
|
4890
4996
|
(0, import_Array.reduce)(
|
|
4891
4997
|
{},
|
|
4892
|
-
(acc, entry) => (0,
|
|
4893
|
-
[(0,
|
|
4998
|
+
(acc, entry) => (0, import_lucid38.addAssets)(acc, {
|
|
4999
|
+
[(0, import_lucid38.toUnit)(policyId, entry.tokenName)]: entry.amount
|
|
4894
5000
|
})
|
|
4895
5001
|
)(params.mintAmounts),
|
|
4896
|
-
|
|
5002
|
+
import_lucid38.Data.to(new import_lucid38.Constr(0, []))
|
|
4897
5003
|
).attach.MintingPolicy(oneShotPolicy),
|
|
4898
5004
|
policyId
|
|
4899
5005
|
];
|
|
@@ -4906,7 +5012,7 @@ async function runOneShotMintTx(lucid, params) {
|
|
|
4906
5012
|
}
|
|
4907
5013
|
|
|
4908
5014
|
// src/contracts/interest-oracle/scripts.ts
|
|
4909
|
-
var
|
|
5015
|
+
var import_lucid39 = require("@lucid-evolution/lucid");
|
|
4910
5016
|
|
|
4911
5017
|
// src/validators/interest-oracle-validator.ts
|
|
4912
5018
|
var _interestOracleValidator = {
|
|
@@ -4919,7 +5025,7 @@ var _interestOracleValidator = {
|
|
|
4919
5025
|
function mkInterestOracleValidator(params) {
|
|
4920
5026
|
return {
|
|
4921
5027
|
type: "PlutusV2",
|
|
4922
|
-
script: (0,
|
|
5028
|
+
script: (0, import_lucid39.applyParamsToScript)(_interestOracleValidator.cborHex, [
|
|
4923
5029
|
castInterestOracleParams(params)
|
|
4924
5030
|
])
|
|
4925
5031
|
};
|
|
@@ -4944,14 +5050,14 @@ async function startInterestOracle(initialUnitaryInterest, initialInterestRate,
|
|
|
4944
5050
|
},
|
|
4945
5051
|
mintAmounts: [
|
|
4946
5052
|
{
|
|
4947
|
-
tokenName: (0,
|
|
5053
|
+
tokenName: (0, import_lucid40.fromText)(tokenName),
|
|
4948
5054
|
amount: 1n
|
|
4949
5055
|
}
|
|
4950
5056
|
]
|
|
4951
5057
|
});
|
|
4952
5058
|
const validator = mkInterestOracleValidator(oracleParams);
|
|
4953
5059
|
tx.pay.ToContract(
|
|
4954
|
-
(0,
|
|
5060
|
+
(0, import_lucid40.validatorToAddress)(network, validator),
|
|
4955
5061
|
{
|
|
4956
5062
|
kind: "inline",
|
|
4957
5063
|
value: serialiseInterestOracleDatum({
|
|
@@ -4964,12 +5070,12 @@ async function startInterestOracle(initialUnitaryInterest, initialInterestRate,
|
|
|
4964
5070
|
},
|
|
4965
5071
|
{
|
|
4966
5072
|
lovelace: 2500000n,
|
|
4967
|
-
[(0,
|
|
5073
|
+
[(0, import_lucid40.toUnit)(policyId, (0, import_lucid40.fromText)(tokenName))]: 1n
|
|
4968
5074
|
}
|
|
4969
5075
|
);
|
|
4970
5076
|
if (withScriptRef) {
|
|
4971
5077
|
tx.pay.ToAddressWithData(
|
|
4972
|
-
(0,
|
|
5078
|
+
(0, import_lucid40.validatorToAddress)(network, validator),
|
|
4973
5079
|
void 0,
|
|
4974
5080
|
void 0,
|
|
4975
5081
|
validator
|
|
@@ -4979,7 +5085,7 @@ async function startInterestOracle(initialUnitaryInterest, initialInterestRate,
|
|
|
4979
5085
|
tx,
|
|
4980
5086
|
{
|
|
4981
5087
|
currencySymbol: policyId,
|
|
4982
|
-
tokenName: (0,
|
|
5088
|
+
tokenName: (0, import_lucid40.fromText)(tokenName)
|
|
4983
5089
|
}
|
|
4984
5090
|
];
|
|
4985
5091
|
}
|
|
@@ -5027,17 +5133,17 @@ async function feedInterestOracle(params, newInterestRate, lucid, assetClass, ut
|
|
|
5027
5133
|
}
|
|
5028
5134
|
|
|
5029
5135
|
// src/contracts/version-registry/types.ts
|
|
5030
|
-
var
|
|
5031
|
-
var VersionRecordTokenParamsSchema =
|
|
5136
|
+
var import_lucid41 = require("@lucid-evolution/lucid");
|
|
5137
|
+
var VersionRecordTokenParamsSchema = import_lucid41.Data.Object({
|
|
5032
5138
|
upgradeToken: AssetClassSchema
|
|
5033
5139
|
});
|
|
5034
5140
|
var VersionRecordTokenParams = VersionRecordTokenParamsSchema;
|
|
5035
5141
|
function castVersionRecordTokenParams(params) {
|
|
5036
|
-
return
|
|
5142
|
+
return import_lucid41.Data.castTo(params, VersionRecordTokenParams);
|
|
5037
5143
|
}
|
|
5038
5144
|
|
|
5039
5145
|
// src/contracts/version-registry/scripts.ts
|
|
5040
|
-
var
|
|
5146
|
+
var import_lucid42 = require("@lucid-evolution/lucid");
|
|
5041
5147
|
|
|
5042
5148
|
// src/validators/version-record-policy.ts
|
|
5043
5149
|
var _versionRecordTokenPolicy = {
|
|
@@ -5057,7 +5163,7 @@ var _versionRegistryValidator = {
|
|
|
5057
5163
|
function mkVersionRecordTokenPolicy(params) {
|
|
5058
5164
|
return {
|
|
5059
5165
|
type: "PlutusV2",
|
|
5060
|
-
script: (0,
|
|
5166
|
+
script: (0, import_lucid42.applyParamsToScript)(_versionRecordTokenPolicy.cborHex, [
|
|
5061
5167
|
castVersionRecordTokenParams(params)
|
|
5062
5168
|
])
|
|
5063
5169
|
};
|
|
@@ -5070,7 +5176,7 @@ var mkVersionRegistryValidator = () => {
|
|
|
5070
5176
|
};
|
|
5071
5177
|
|
|
5072
5178
|
// src/contracts/collector/scripts.ts
|
|
5073
|
-
var
|
|
5179
|
+
var import_lucid43 = require("@lucid-evolution/lucid");
|
|
5074
5180
|
|
|
5075
5181
|
// src/validators/collector-validator.ts
|
|
5076
5182
|
var _collectorValidator = {
|
|
@@ -5083,19 +5189,19 @@ var _collectorValidator = {
|
|
|
5083
5189
|
var mkCollectorValidatorFromSP = (params) => {
|
|
5084
5190
|
return {
|
|
5085
5191
|
type: "PlutusV2",
|
|
5086
|
-
script: (0,
|
|
5087
|
-
new
|
|
5088
|
-
new
|
|
5192
|
+
script: (0, import_lucid43.applyParamsToScript)(_collectorValidator.cborHex, [
|
|
5193
|
+
new import_lucid43.Constr(0, [
|
|
5194
|
+
new import_lucid43.Constr(0, [
|
|
5089
5195
|
params.stakingManagerNFT[0].unCurrencySymbol,
|
|
5090
|
-
(0,
|
|
5196
|
+
(0, import_lucid43.fromText)(params.stakingManagerNFT[1].unTokenName)
|
|
5091
5197
|
]),
|
|
5092
|
-
new
|
|
5198
|
+
new import_lucid43.Constr(0, [
|
|
5093
5199
|
params.stakingToken[0].unCurrencySymbol,
|
|
5094
|
-
(0,
|
|
5200
|
+
(0, import_lucid43.fromText)(params.stakingToken[1].unTokenName)
|
|
5095
5201
|
]),
|
|
5096
|
-
new
|
|
5202
|
+
new import_lucid43.Constr(0, [
|
|
5097
5203
|
params.versionRecordToken[0].unCurrencySymbol,
|
|
5098
|
-
(0,
|
|
5204
|
+
(0, import_lucid43.fromText)(params.versionRecordToken[1].unTokenName)
|
|
5099
5205
|
])
|
|
5100
5206
|
])
|
|
5101
5207
|
])
|
|
@@ -5103,7 +5209,7 @@ var mkCollectorValidatorFromSP = (params) => {
|
|
|
5103
5209
|
};
|
|
5104
5210
|
|
|
5105
5211
|
// src/contracts/treasury/scripts.ts
|
|
5106
|
-
var
|
|
5212
|
+
var import_lucid44 = require("@lucid-evolution/lucid");
|
|
5107
5213
|
|
|
5108
5214
|
// src/validators/treasury-validator.ts
|
|
5109
5215
|
var _treasuryValidator = {
|
|
@@ -5116,30 +5222,30 @@ var _treasuryValidator = {
|
|
|
5116
5222
|
var mkTreasuryValidatorFromSP = (params) => {
|
|
5117
5223
|
return {
|
|
5118
5224
|
type: "PlutusV2",
|
|
5119
|
-
script: (0,
|
|
5120
|
-
new
|
|
5121
|
-
new
|
|
5225
|
+
script: (0, import_lucid44.applyParamsToScript)(_treasuryValidator.cborHex, [
|
|
5226
|
+
new import_lucid44.Constr(0, [
|
|
5227
|
+
new import_lucid44.Constr(0, [
|
|
5122
5228
|
params.upgradeToken[0].unCurrencySymbol,
|
|
5123
|
-
(0,
|
|
5229
|
+
(0, import_lucid44.fromText)(params.upgradeToken[1].unTokenName)
|
|
5124
5230
|
]),
|
|
5125
|
-
new
|
|
5231
|
+
new import_lucid44.Constr(0, [
|
|
5126
5232
|
params.versionRecordToken[0].unCurrencySymbol,
|
|
5127
|
-
(0,
|
|
5233
|
+
(0, import_lucid44.fromText)(params.versionRecordToken[1].unTokenName)
|
|
5128
5234
|
]),
|
|
5129
|
-
params.treasuryUtxosStakeCredential ? new
|
|
5130
|
-
new
|
|
5131
|
-
new
|
|
5235
|
+
params.treasuryUtxosStakeCredential ? new import_lucid44.Constr(0, [
|
|
5236
|
+
new import_lucid44.Constr(0, [
|
|
5237
|
+
new import_lucid44.Constr(1, [
|
|
5132
5238
|
params.treasuryUtxosStakeCredential.contents.contents
|
|
5133
5239
|
])
|
|
5134
5240
|
])
|
|
5135
|
-
]) : new
|
|
5241
|
+
]) : new import_lucid44.Constr(1, [])
|
|
5136
5242
|
])
|
|
5137
5243
|
])
|
|
5138
5244
|
};
|
|
5139
5245
|
};
|
|
5140
5246
|
|
|
5141
5247
|
// src/contracts/execute/scripts.ts
|
|
5142
|
-
var
|
|
5248
|
+
var import_lucid45 = require("@lucid-evolution/lucid");
|
|
5143
5249
|
|
|
5144
5250
|
// src/validators/execute-validator.ts
|
|
5145
5251
|
var _executeValidator = {
|
|
@@ -5152,8 +5258,8 @@ var _executeValidator = {
|
|
|
5152
5258
|
var mkExecuteValidator = (params) => {
|
|
5153
5259
|
return {
|
|
5154
5260
|
type: "PlutusV2",
|
|
5155
|
-
script: (0,
|
|
5156
|
-
(0,
|
|
5261
|
+
script: (0, import_lucid45.applySingleCborEncoding)(
|
|
5262
|
+
(0, import_lucid45.applyParamsToScript)(_executeValidator.cborHex, [
|
|
5157
5263
|
castExecuteParams(params)
|
|
5158
5264
|
])
|
|
5159
5265
|
)
|
|
@@ -5162,8 +5268,8 @@ var mkExecuteValidator = (params) => {
|
|
|
5162
5268
|
var mkExecuteValidatorFromSP = (params) => {
|
|
5163
5269
|
return {
|
|
5164
5270
|
type: "PlutusV2",
|
|
5165
|
-
script: (0,
|
|
5166
|
-
(0,
|
|
5271
|
+
script: (0, import_lucid45.applySingleCborEncoding)(
|
|
5272
|
+
(0, import_lucid45.applyParamsToScript)(_executeValidator.cborHex, [
|
|
5167
5273
|
castExecuteParams({
|
|
5168
5274
|
govNFT: fromSystemParamsAsset(params.govNFT),
|
|
5169
5275
|
upgradeToken: fromSystemParamsAsset(params.upgradeToken),
|
|
@@ -5181,62 +5287,276 @@ var mkExecuteValidatorFromSP = (params) => {
|
|
|
5181
5287
|
};
|
|
5182
5288
|
};
|
|
5183
5289
|
|
|
5290
|
+
// src/contracts/lrp/helpers.ts
|
|
5291
|
+
var import_lucid47 = require("@lucid-evolution/lucid");
|
|
5292
|
+
|
|
5184
5293
|
// src/contracts/lrp/types.ts
|
|
5185
|
-
var
|
|
5186
|
-
var
|
|
5294
|
+
var import_lucid46 = require("@lucid-evolution/lucid");
|
|
5295
|
+
var import_fp_ts11 = require("fp-ts");
|
|
5296
|
+
var LRPParamsSchema = import_lucid46.Data.Object({
|
|
5187
5297
|
versionRecordToken: AssetClassSchema,
|
|
5188
5298
|
iassetNft: AssetClassSchema,
|
|
5189
|
-
iassetPolicyId:
|
|
5190
|
-
minRedemptionLovelacesAmt:
|
|
5299
|
+
iassetPolicyId: import_lucid46.Data.Bytes(),
|
|
5300
|
+
minRedemptionLovelacesAmt: import_lucid46.Data.Integer()
|
|
5191
5301
|
});
|
|
5192
5302
|
var LRPParams = LRPParamsSchema;
|
|
5193
|
-
var LRPDatumSchema =
|
|
5194
|
-
owner:
|
|
5195
|
-
iasset:
|
|
5303
|
+
var LRPDatumSchema = import_lucid46.Data.Object({
|
|
5304
|
+
owner: import_lucid46.Data.Bytes(),
|
|
5305
|
+
iasset: import_lucid46.Data.Bytes(),
|
|
5196
5306
|
maxPrice: OnChainDecimalSchema,
|
|
5197
5307
|
/**
|
|
5198
5308
|
* The amount of lovelaces that is available to be spent.
|
|
5199
5309
|
* This doesn't correspond to the lovelaces in UTXO's value,
|
|
5200
5310
|
* since that can contain fees, too.
|
|
5201
5311
|
*/
|
|
5202
|
-
lovelacesToSpend:
|
|
5312
|
+
lovelacesToSpend: import_lucid46.Data.Integer()
|
|
5203
5313
|
});
|
|
5204
5314
|
var LRPDatum = LRPDatumSchema;
|
|
5205
|
-
var LRPRedeemerSchema =
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
RedeemAuxiliary:
|
|
5209
|
-
continuingOutputIdx:
|
|
5315
|
+
var LRPRedeemerSchema = import_lucid46.Data.Enum([
|
|
5316
|
+
import_lucid46.Data.Object({ Redeem: import_lucid46.Data.Object({ continuingOutputIdx: import_lucid46.Data.Integer() }) }),
|
|
5317
|
+
import_lucid46.Data.Object({
|
|
5318
|
+
RedeemAuxiliary: import_lucid46.Data.Object({
|
|
5319
|
+
continuingOutputIdx: import_lucid46.Data.Integer(),
|
|
5210
5320
|
mainRedeemOutRef: OutputReferenceSchema,
|
|
5211
|
-
asset:
|
|
5321
|
+
asset: import_lucid46.Data.Bytes(),
|
|
5212
5322
|
assetPrice: OnChainDecimalSchema,
|
|
5213
5323
|
redemptionReimbursementPercentage: OnChainDecimalSchema
|
|
5214
5324
|
})
|
|
5215
5325
|
}),
|
|
5216
|
-
|
|
5217
|
-
|
|
5326
|
+
import_lucid46.Data.Literal("Cancel"),
|
|
5327
|
+
import_lucid46.Data.Literal("UpgradeVersion")
|
|
5218
5328
|
]);
|
|
5219
5329
|
var LRPRedeemer = LRPRedeemerSchema;
|
|
5220
5330
|
function parseLrpDatum(datum) {
|
|
5221
|
-
|
|
5331
|
+
try {
|
|
5332
|
+
return import_fp_ts11.option.some(import_lucid46.Data.from(datum, LRPDatum));
|
|
5333
|
+
} catch (_) {
|
|
5334
|
+
return import_fp_ts11.option.none;
|
|
5335
|
+
}
|
|
5336
|
+
}
|
|
5337
|
+
function parseLrpDatumOrThrow(datum) {
|
|
5338
|
+
return import_fp_ts11.function.pipe(
|
|
5339
|
+
parseLrpDatum(datum),
|
|
5340
|
+
import_fp_ts11.option.match(() => {
|
|
5341
|
+
throw new Error("Expected an LRP datum.");
|
|
5342
|
+
}, import_fp_ts11.function.identity)
|
|
5343
|
+
);
|
|
5222
5344
|
}
|
|
5223
5345
|
function serialiseLrpDatum(datum) {
|
|
5224
|
-
return
|
|
5346
|
+
return import_lucid46.Data.to(datum, LRPDatum);
|
|
5225
5347
|
}
|
|
5226
5348
|
function serialiseLrpRedeemer(redeemer) {
|
|
5227
|
-
return
|
|
5349
|
+
return import_lucid46.Data.to(redeemer, LRPRedeemer);
|
|
5228
5350
|
}
|
|
5229
5351
|
function castLrpParams(params) {
|
|
5230
|
-
return
|
|
5352
|
+
return import_lucid46.Data.castTo(params, LRPParams);
|
|
5231
5353
|
}
|
|
5232
5354
|
|
|
5233
|
-
// src/contracts/lrp/
|
|
5234
|
-
var
|
|
5355
|
+
// src/contracts/lrp/helpers.ts
|
|
5356
|
+
var import_fp_ts13 = require("fp-ts");
|
|
5357
|
+
|
|
5358
|
+
// src/utils/array-utils.ts
|
|
5359
|
+
var import_fp_ts12 = require("fp-ts");
|
|
5360
|
+
function shuffle(arr) {
|
|
5361
|
+
const source = [...arr];
|
|
5362
|
+
for (let i = source.length - 1; i > 0; i--) {
|
|
5363
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
5364
|
+
[source[i], source[j]] = [source[j], source[i]];
|
|
5365
|
+
}
|
|
5366
|
+
return source;
|
|
5367
|
+
}
|
|
5368
|
+
function insertSorted(arr, item, ord) {
|
|
5369
|
+
if (arr.length === 0) {
|
|
5370
|
+
return [item];
|
|
5371
|
+
}
|
|
5372
|
+
const arrOrd = ord.compare(arr[0], arr[arr.length - 1]);
|
|
5373
|
+
if (arrOrd === 0) {
|
|
5374
|
+
if (ord.compare(arr[0], item) === -1) {
|
|
5375
|
+
return [...arr, item];
|
|
5376
|
+
} else {
|
|
5377
|
+
return [item, ...arr];
|
|
5378
|
+
}
|
|
5379
|
+
}
|
|
5380
|
+
for (let i = 0; i < arr.length; i++) {
|
|
5381
|
+
if (ord.compare(arr[i], item) !== arrOrd) {
|
|
5382
|
+
return [...import_fp_ts12.array.takeLeft(i)(arr), item, ...import_fp_ts12.array.takeRight(arr.length - i)(arr)];
|
|
5383
|
+
}
|
|
5384
|
+
}
|
|
5385
|
+
return [...arr, item];
|
|
5386
|
+
}
|
|
5387
|
+
|
|
5388
|
+
// src/contracts/lrp/helpers.ts
|
|
5235
5389
|
var import_ts_pattern12 = require("ts-pattern");
|
|
5390
|
+
var MIN_LRP_COLLATERAL_AMT = 2000000n;
|
|
5391
|
+
function lrpRedeemableLovelacesInclReimb(lrp, lrpParams) {
|
|
5392
|
+
const datum = lrp[1];
|
|
5393
|
+
const utxo = lrp[0];
|
|
5394
|
+
let res = 0n;
|
|
5395
|
+
if (datum.lovelacesToSpend > lovelacesAmt(utxo.assets)) {
|
|
5396
|
+
res = bigintMax(lovelacesAmt(utxo.assets) - MIN_LRP_COLLATERAL_AMT, 0n);
|
|
5397
|
+
} else {
|
|
5398
|
+
res = datum.lovelacesToSpend;
|
|
5399
|
+
}
|
|
5400
|
+
if (res < lrpParams.minRedemptionLovelacesAmt) {
|
|
5401
|
+
return 0n;
|
|
5402
|
+
}
|
|
5403
|
+
return res;
|
|
5404
|
+
}
|
|
5405
|
+
function buildRedemptionsTx(redemptions, price, redemptionReimbursementPercentage, sysParams, tx, txOutputsBeforeCount) {
|
|
5406
|
+
const [[mainLrpUtxo, _], __] = (0, import_ts_pattern12.match)(redemptions).with(
|
|
5407
|
+
[import_ts_pattern12.P._, ...import_ts_pattern12.P.array()],
|
|
5408
|
+
([[firstLrp, _2], ...rest]) => [
|
|
5409
|
+
[firstLrp, _2],
|
|
5410
|
+
rest
|
|
5411
|
+
]
|
|
5412
|
+
).otherwise(() => {
|
|
5413
|
+
throw new Error("Expects at least 1 UTXO to redeem.");
|
|
5414
|
+
});
|
|
5415
|
+
const mainLrpDatum = parseLrpDatumOrThrow(getInlineDatumOrThrow(mainLrpUtxo));
|
|
5416
|
+
return import_fp_ts13.function.pipe(
|
|
5417
|
+
redemptions,
|
|
5418
|
+
import_fp_ts13.array.reduceWithIndex(
|
|
5419
|
+
tx,
|
|
5420
|
+
(idx, acc, [lrpUtxo, redeemIAssetAmt]) => {
|
|
5421
|
+
const lovelacesForRedemption = ocdMul(
|
|
5422
|
+
{
|
|
5423
|
+
getOnChainInt: redeemIAssetAmt
|
|
5424
|
+
},
|
|
5425
|
+
price
|
|
5426
|
+
).getOnChainInt;
|
|
5427
|
+
const reimburstmentLovelaces = calculateFeeFromPercentage(
|
|
5428
|
+
redemptionReimbursementPercentage,
|
|
5429
|
+
lovelacesForRedemption
|
|
5430
|
+
);
|
|
5431
|
+
const lrpDatum = parseLrpDatumOrThrow(getInlineDatumOrThrow(lrpUtxo));
|
|
5432
|
+
const resultVal = (0, import_lucid47.addAssets)(
|
|
5433
|
+
lrpUtxo.assets,
|
|
5434
|
+
mkLovelacesOf(-lovelacesForRedemption + reimburstmentLovelaces),
|
|
5435
|
+
mkAssetsOf(
|
|
5436
|
+
{
|
|
5437
|
+
currencySymbol: sysParams.lrpParams.iassetPolicyId.unCurrencySymbol,
|
|
5438
|
+
tokenName: mainLrpDatum.iasset
|
|
5439
|
+
},
|
|
5440
|
+
redeemIAssetAmt
|
|
5441
|
+
)
|
|
5442
|
+
);
|
|
5443
|
+
if (lovelacesAmt(resultVal) < MIN_LRP_COLLATERAL_AMT) {
|
|
5444
|
+
throw new Error("LRP was incorrectly initialised.");
|
|
5445
|
+
}
|
|
5446
|
+
return acc.collectFrom(
|
|
5447
|
+
[lrpUtxo],
|
|
5448
|
+
serialiseLrpRedeemer(
|
|
5449
|
+
idx === 0 ? { Redeem: { continuingOutputIdx: txOutputsBeforeCount + 0n } } : {
|
|
5450
|
+
RedeemAuxiliary: {
|
|
5451
|
+
continuingOutputIdx: txOutputsBeforeCount + BigInt(idx),
|
|
5452
|
+
mainRedeemOutRef: {
|
|
5453
|
+
txHash: { hash: mainLrpUtxo.txHash },
|
|
5454
|
+
outputIndex: BigInt(mainLrpUtxo.outputIndex)
|
|
5455
|
+
},
|
|
5456
|
+
asset: mainLrpDatum.iasset,
|
|
5457
|
+
assetPrice: price,
|
|
5458
|
+
redemptionReimbursementPercentage
|
|
5459
|
+
}
|
|
5460
|
+
}
|
|
5461
|
+
)
|
|
5462
|
+
).pay.ToContract(
|
|
5463
|
+
lrpUtxo.address,
|
|
5464
|
+
{
|
|
5465
|
+
kind: "inline",
|
|
5466
|
+
value: serialiseLrpDatum({
|
|
5467
|
+
...lrpDatum,
|
|
5468
|
+
lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
|
|
5469
|
+
})
|
|
5470
|
+
},
|
|
5471
|
+
resultVal
|
|
5472
|
+
);
|
|
5473
|
+
}
|
|
5474
|
+
)
|
|
5475
|
+
);
|
|
5476
|
+
}
|
|
5477
|
+
function calculateTotalAdaForRedemption(iasset, iassetPrice, lrpParams, allLrps, maxLrpsInTx) {
|
|
5478
|
+
return import_fp_ts13.function.pipe(
|
|
5479
|
+
allLrps,
|
|
5480
|
+
import_fp_ts13.array.filterMap(([utxo, datum]) => {
|
|
5481
|
+
if (datum.iasset !== iasset || datum.maxPrice.getOnChainInt < iassetPrice.getOnChainInt) {
|
|
5482
|
+
return import_fp_ts13.option.none;
|
|
5483
|
+
}
|
|
5484
|
+
const lovelacesToSpend = lrpRedeemableLovelacesInclReimb(
|
|
5485
|
+
[utxo, datum],
|
|
5486
|
+
lrpParams
|
|
5487
|
+
);
|
|
5488
|
+
if (lovelacesToSpend === 0n) {
|
|
5489
|
+
return import_fp_ts13.option.none;
|
|
5490
|
+
}
|
|
5491
|
+
return import_fp_ts13.option.some(lovelacesToSpend);
|
|
5492
|
+
}),
|
|
5493
|
+
// From largest to smallest
|
|
5494
|
+
import_fp_ts13.array.sort(import_fp_ts13.ord.reverse(BigIntOrd)),
|
|
5495
|
+
// We can fit only this number of redemptions with CDP open into a single Tx.
|
|
5496
|
+
import_fp_ts13.array.takeLeft(maxLrpsInTx),
|
|
5497
|
+
sum
|
|
5498
|
+
);
|
|
5499
|
+
}
|
|
5500
|
+
function randomLrpsSubsetSatisfyingTargetLovelaces(iasset, targetLovelacesToSpend, iassetPrice, allLrps, lrpParams, maxLrpsInTx, randomiseFn = shuffle) {
|
|
5501
|
+
if (targetLovelacesToSpend < lrpParams.minRedemptionLovelacesAmt) {
|
|
5502
|
+
throw new Error("Can't redeem less than the minimum.");
|
|
5503
|
+
}
|
|
5504
|
+
const shuffled = randomiseFn(
|
|
5505
|
+
import_fp_ts13.function.pipe(
|
|
5506
|
+
allLrps,
|
|
5507
|
+
import_fp_ts13.array.filter(
|
|
5508
|
+
([_, datum]) => datum.iasset === iasset && datum.maxPrice.getOnChainInt >= iassetPrice.getOnChainInt
|
|
5509
|
+
)
|
|
5510
|
+
)
|
|
5511
|
+
);
|
|
5512
|
+
let result = [];
|
|
5513
|
+
let runningSum = 0n;
|
|
5514
|
+
for (let i = 0; i < shuffled.length; i++) {
|
|
5515
|
+
const element = shuffled[i];
|
|
5516
|
+
const lovelacesToSpend = lrpRedeemableLovelacesInclReimb(
|
|
5517
|
+
element,
|
|
5518
|
+
lrpParams
|
|
5519
|
+
);
|
|
5520
|
+
if (lovelacesToSpend < lrpParams.minRedemptionLovelacesAmt) {
|
|
5521
|
+
continue;
|
|
5522
|
+
}
|
|
5523
|
+
if (result.length > 0 && targetLovelacesToSpend - runningSum < lrpParams.minRedemptionLovelacesAmt) {
|
|
5524
|
+
const last = result[result.length - 1];
|
|
5525
|
+
if (lrpRedeemableLovelacesInclReimb(last, lrpParams) < lovelacesToSpend) {
|
|
5526
|
+
const popped = result.pop();
|
|
5527
|
+
runningSum -= lrpRedeemableLovelacesInclReimb(popped, lrpParams);
|
|
5528
|
+
} else {
|
|
5529
|
+
continue;
|
|
5530
|
+
}
|
|
5531
|
+
}
|
|
5532
|
+
result = insertSorted(
|
|
5533
|
+
result,
|
|
5534
|
+
element,
|
|
5535
|
+
import_fp_ts13.ord.contramap(
|
|
5536
|
+
([_, dat]) => dat.lovelacesToSpend
|
|
5537
|
+
// From highest to lowest
|
|
5538
|
+
)(import_fp_ts13.ord.reverse(BigIntOrd))
|
|
5539
|
+
);
|
|
5540
|
+
runningSum += lovelacesToSpend;
|
|
5541
|
+
if (result.length > maxLrpsInTx) {
|
|
5542
|
+
const popped = result.pop();
|
|
5543
|
+
runningSum -= lrpRedeemableLovelacesInclReimb(popped, lrpParams);
|
|
5544
|
+
}
|
|
5545
|
+
if (runningSum >= targetLovelacesToSpend) {
|
|
5546
|
+
return result;
|
|
5547
|
+
}
|
|
5548
|
+
}
|
|
5549
|
+
if (targetLovelacesToSpend - runningSum >= lrpParams.minRedemptionLovelacesAmt) {
|
|
5550
|
+
throw new Error("Couldn't achieve target lovelaces");
|
|
5551
|
+
}
|
|
5552
|
+
return result;
|
|
5553
|
+
}
|
|
5554
|
+
|
|
5555
|
+
// src/contracts/lrp/transactions.ts
|
|
5556
|
+
var import_lucid48 = require("@lucid-evolution/lucid");
|
|
5236
5557
|
var import_Array2 = require("fp-ts/lib/Array");
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
async function openLrp(assetTokenName, lovelacesAmt2, maxPrice, lucid, lrpScriptHash, network, lrpStakeCredential) {
|
|
5558
|
+
async function openLrp(assetTokenName, lovelacesAmt2, maxPrice, lucid, sysParams, lrpStakeCredential) {
|
|
5559
|
+
const network = lucid.config().network;
|
|
5240
5560
|
const [ownPkh, _] = await addrDetails(lucid);
|
|
5241
5561
|
const newDatum = {
|
|
5242
5562
|
owner: ownPkh.hash,
|
|
@@ -5245,38 +5565,47 @@ async function openLrp(assetTokenName, lovelacesAmt2, maxPrice, lucid, lrpScript
|
|
|
5245
5565
|
lovelacesToSpend: lovelacesAmt2
|
|
5246
5566
|
};
|
|
5247
5567
|
return lucid.newTx().pay.ToContract(
|
|
5248
|
-
createScriptAddress(
|
|
5568
|
+
createScriptAddress(
|
|
5569
|
+
network,
|
|
5570
|
+
sysParams.validatorHashes.lrpHash,
|
|
5571
|
+
lrpStakeCredential
|
|
5572
|
+
),
|
|
5249
5573
|
{
|
|
5250
5574
|
kind: "inline",
|
|
5251
5575
|
value: serialiseLrpDatum(newDatum)
|
|
5252
5576
|
},
|
|
5253
|
-
{ lovelace: lovelacesAmt2 +
|
|
5577
|
+
{ lovelace: lovelacesAmt2 + MIN_LRP_COLLATERAL_AMT }
|
|
5254
5578
|
);
|
|
5255
5579
|
}
|
|
5256
|
-
async function cancelLrp(lrpOutRef,
|
|
5580
|
+
async function cancelLrp(lrpOutRef, sysParams, lucid) {
|
|
5257
5581
|
const lrpScriptRefUtxo = matchSingle(
|
|
5258
|
-
await lucid.utxosByOutRef([
|
|
5582
|
+
await lucid.utxosByOutRef([
|
|
5583
|
+
fromSystemParamsScriptRef(sysParams.scriptReferences.lrpValidatorRef)
|
|
5584
|
+
]),
|
|
5259
5585
|
(_) => new Error("Expected a single LRP Ref Script UTXO")
|
|
5260
5586
|
);
|
|
5261
5587
|
const lrpUtxo = matchSingle(
|
|
5262
5588
|
await lucid.utxosByOutRef([lrpOutRef]),
|
|
5263
5589
|
(_) => new Error("Expected a single LRP UTXO.")
|
|
5264
5590
|
);
|
|
5265
|
-
const lrpDatum =
|
|
5591
|
+
const lrpDatum = parseLrpDatumOrThrow(getInlineDatumOrThrow(lrpUtxo));
|
|
5266
5592
|
return lucid.newTx().readFrom([lrpScriptRefUtxo]).collectFrom([lrpUtxo], serialiseLrpRedeemer("Cancel")).addSignerKey(lrpDatum.owner);
|
|
5267
5593
|
}
|
|
5268
|
-
async function redeemLrp(redemptionLrpsData,
|
|
5594
|
+
async function redeemLrp(redemptionLrpsData, priceOracleOutRef, iassetOutRef, lucid, sysParams) {
|
|
5595
|
+
const network = lucid.config().network;
|
|
5269
5596
|
const lrpScriptRefUtxo = matchSingle(
|
|
5270
|
-
await lucid.utxosByOutRef([
|
|
5271
|
-
|
|
5597
|
+
await lucid.utxosByOutRef([
|
|
5598
|
+
fromSystemParamsScriptRef(sysParams.scriptReferences.lrpValidatorRef)
|
|
5599
|
+
]),
|
|
5600
|
+
(_) => new Error("Expected a single LRP Ref Script UTXO")
|
|
5272
5601
|
);
|
|
5273
5602
|
const priceOracleUtxo = matchSingle(
|
|
5274
5603
|
await lucid.utxosByOutRef([priceOracleOutRef]),
|
|
5275
|
-
(
|
|
5604
|
+
(_) => new Error("Expected a single price oracle UTXO")
|
|
5276
5605
|
);
|
|
5277
5606
|
const iassetUtxo = matchSingle(
|
|
5278
5607
|
await lucid.utxosByOutRef([iassetOutRef]),
|
|
5279
|
-
(
|
|
5608
|
+
(_) => new Error("Expected a single IAsset UTXO")
|
|
5280
5609
|
);
|
|
5281
5610
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
5282
5611
|
getInlineDatumOrThrow(iassetUtxo)
|
|
@@ -5286,88 +5615,35 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
|
|
|
5286
5615
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
5287
5616
|
);
|
|
5288
5617
|
const redemptionLrps = await lucid.utxosByOutRef(lrpsToRedeemOutRefs).then((val) => (0, import_Array2.zip)(val, lrpRedemptionIAssetAmt));
|
|
5289
|
-
const
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
]
|
|
5295
|
-
).otherwise(() => {
|
|
5296
|
-
throw new Error("Expects at least 1 UTXO to redeem.");
|
|
5297
|
-
});
|
|
5298
|
-
const mainLrpDatum = parseLrpDatum(getInlineDatumOrThrow(mainLrpUtxo));
|
|
5299
|
-
const tx = (0, import_Array3.reduceWithIndex)(
|
|
5618
|
+
const tx = buildRedemptionsTx(
|
|
5619
|
+
redemptionLrps,
|
|
5620
|
+
priceOracleDatum.price,
|
|
5621
|
+
iassetDatum.redemptionReimbursementPercentage,
|
|
5622
|
+
sysParams,
|
|
5300
5623
|
lucid.newTx(),
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
{
|
|
5304
|
-
getOnChainInt: redeemIAssetAmt
|
|
5305
|
-
},
|
|
5306
|
-
priceOracleDatum.price
|
|
5307
|
-
).getOnChainInt;
|
|
5308
|
-
const reimburstmentLovelaces = calculateFeeFromPercentage(
|
|
5309
|
-
iassetDatum.redemptionReimbursementPercentage,
|
|
5310
|
-
lovelacesForRedemption
|
|
5311
|
-
);
|
|
5312
|
-
const lrpDatum = parseLrpDatum(getInlineDatumOrThrow(lrpUtxo));
|
|
5313
|
-
return acc.collectFrom(
|
|
5314
|
-
[lrpUtxo],
|
|
5315
|
-
serialiseLrpRedeemer(
|
|
5316
|
-
idx === 0 ? { Redeem: { continuingOutputIdx: 0n } } : {
|
|
5317
|
-
RedeemAuxiliary: {
|
|
5318
|
-
continuingOutputIdx: BigInt(idx),
|
|
5319
|
-
mainRedeemOutRef: {
|
|
5320
|
-
txHash: { hash: mainLrpUtxo.txHash },
|
|
5321
|
-
outputIndex: BigInt(mainLrpUtxo.outputIndex)
|
|
5322
|
-
},
|
|
5323
|
-
asset: mainLrpDatum.iasset,
|
|
5324
|
-
assetPrice: priceOracleDatum.price,
|
|
5325
|
-
redemptionReimbursementPercentage: iassetDatum.redemptionReimbursementPercentage
|
|
5326
|
-
}
|
|
5327
|
-
}
|
|
5328
|
-
)
|
|
5329
|
-
).pay.ToContract(
|
|
5330
|
-
lrpUtxo.address,
|
|
5331
|
-
{
|
|
5332
|
-
kind: "inline",
|
|
5333
|
-
value: serialiseLrpDatum({
|
|
5334
|
-
...lrpDatum,
|
|
5335
|
-
lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
|
|
5336
|
-
})
|
|
5337
|
-
},
|
|
5338
|
-
(0, import_lucid46.addAssets)(
|
|
5339
|
-
lrpUtxo.assets,
|
|
5340
|
-
mkLovelacesOf(-lovelacesForRedemption + reimburstmentLovelaces),
|
|
5341
|
-
mkAssetsOf(
|
|
5342
|
-
{
|
|
5343
|
-
currencySymbol: lrpParams.iassetPolicyId,
|
|
5344
|
-
tokenName: mainLrpDatum.iasset
|
|
5345
|
-
},
|
|
5346
|
-
redeemIAssetAmt
|
|
5347
|
-
)
|
|
5348
|
-
)
|
|
5349
|
-
);
|
|
5350
|
-
}
|
|
5351
|
-
)(redemptionLrps);
|
|
5624
|
+
0n
|
|
5625
|
+
);
|
|
5352
5626
|
return lucid.newTx().validTo(
|
|
5353
|
-
(0,
|
|
5627
|
+
(0, import_lucid48.slotToUnixTime)(
|
|
5354
5628
|
network,
|
|
5355
|
-
(0,
|
|
5629
|
+
(0, import_lucid48.unixTimeToSlot)(network, Number(priceOracleDatum.expiration)) - 1
|
|
5356
5630
|
)
|
|
5357
5631
|
).readFrom([lrpScriptRefUtxo]).readFrom([iassetUtxo, priceOracleUtxo]).compose(tx);
|
|
5358
5632
|
}
|
|
5359
|
-
async function adjustLrp(lucid, lrpOutRef, lovelacesAdjustAmt,
|
|
5633
|
+
async function adjustLrp(lucid, lrpOutRef, lovelacesAdjustAmt, sysParams) {
|
|
5360
5634
|
const lrpScriptRefUtxo = matchSingle(
|
|
5361
|
-
await lucid.utxosByOutRef([
|
|
5635
|
+
await lucid.utxosByOutRef([
|
|
5636
|
+
fromSystemParamsScriptRef(sysParams.scriptReferences.lrpValidatorRef)
|
|
5637
|
+
]),
|
|
5362
5638
|
(_) => new Error("Expected a single LRP Ref Script UTXO")
|
|
5363
5639
|
);
|
|
5364
5640
|
const lrpUtxo = matchSingle(
|
|
5365
5641
|
await lucid.utxosByOutRef([lrpOutRef]),
|
|
5366
5642
|
(_) => new Error("Expected a single LRP UTXO.")
|
|
5367
5643
|
);
|
|
5368
|
-
const lrpDatum =
|
|
5644
|
+
const lrpDatum = parseLrpDatumOrThrow(getInlineDatumOrThrow(lrpUtxo));
|
|
5369
5645
|
const rewardAssetClass = {
|
|
5370
|
-
currencySymbol: lrpParams.iassetPolicyId,
|
|
5646
|
+
currencySymbol: sysParams.lrpParams.iassetPolicyId.unCurrencySymbol,
|
|
5371
5647
|
tokenName: lrpDatum.iasset
|
|
5372
5648
|
};
|
|
5373
5649
|
const rewardAssetsAmt = assetClassValueOf(lrpUtxo.assets, rewardAssetClass);
|
|
@@ -5390,19 +5666,19 @@ async function adjustLrp(lucid, lrpOutRef, lovelacesAdjustAmt, lrpRefScriptOutRe
|
|
|
5390
5666
|
lovelacesToSpend: lrpDatum.lovelacesToSpend + lovelacesAdjustAmt
|
|
5391
5667
|
})
|
|
5392
5668
|
},
|
|
5393
|
-
(0,
|
|
5669
|
+
(0, import_lucid48.addAssets)(
|
|
5394
5670
|
lrpUtxo.assets,
|
|
5395
5671
|
mkAssetsOf(rewardAssetClass, -rewardAssetsAmt),
|
|
5396
5672
|
mkLovelacesOf(lovelacesAdjustAmt)
|
|
5397
5673
|
)
|
|
5398
5674
|
).addSignerKey(lrpDatum.owner);
|
|
5399
5675
|
}
|
|
5400
|
-
async function claimLrp(lucid, lrpOutRef,
|
|
5401
|
-
return adjustLrp(lucid, lrpOutRef, 0n,
|
|
5676
|
+
async function claimLrp(lucid, lrpOutRef, sysParams) {
|
|
5677
|
+
return adjustLrp(lucid, lrpOutRef, 0n, sysParams);
|
|
5402
5678
|
}
|
|
5403
5679
|
|
|
5404
5680
|
// src/contracts/lrp/scripts.ts
|
|
5405
|
-
var
|
|
5681
|
+
var import_lucid49 = require("@lucid-evolution/lucid");
|
|
5406
5682
|
|
|
5407
5683
|
// src/validators/lrp-validator.ts
|
|
5408
5684
|
var _lrpValidator = {
|
|
@@ -5415,13 +5691,13 @@ var _lrpValidator = {
|
|
|
5415
5691
|
var mkLrpValidator = (params) => {
|
|
5416
5692
|
return {
|
|
5417
5693
|
type: "PlutusV2",
|
|
5418
|
-
script: (0,
|
|
5694
|
+
script: (0, import_lucid49.applyParamsToScript)(_lrpValidator.cborHex, [castLrpParams(params)])
|
|
5419
5695
|
};
|
|
5420
5696
|
};
|
|
5421
5697
|
var mkLrpValidatorFromSP = (params) => {
|
|
5422
5698
|
return {
|
|
5423
5699
|
type: "PlutusV2",
|
|
5424
|
-
script: (0,
|
|
5700
|
+
script: (0, import_lucid49.applyParamsToScript)(_lrpValidator.cborHex, [
|
|
5425
5701
|
castLrpParams({
|
|
5426
5702
|
versionRecordToken: fromSystemParamsAsset(params.versionRecordToken),
|
|
5427
5703
|
iassetNft: fromSystemParamsAsset(params.iassetNft),
|
|
@@ -5433,7 +5709,7 @@ var mkLrpValidatorFromSP = (params) => {
|
|
|
5433
5709
|
};
|
|
5434
5710
|
|
|
5435
5711
|
// src/utils/helper-txs.ts
|
|
5436
|
-
var
|
|
5712
|
+
var import_lucid50 = require("@lucid-evolution/lucid");
|
|
5437
5713
|
|
|
5438
5714
|
// src/scripts/always-fail-validator.ts
|
|
5439
5715
|
var alwaysFailValidator = {
|
|
@@ -5443,11 +5719,367 @@ var alwaysFailValidator = {
|
|
|
5443
5719
|
|
|
5444
5720
|
// src/utils/helper-txs.ts
|
|
5445
5721
|
async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
|
|
5446
|
-
const scriptAddr = (0,
|
|
5722
|
+
const scriptAddr = (0, import_lucid50.validatorToAddress)(network, alwaysFailValidator);
|
|
5447
5723
|
const txHash = await lucid.newTx().pay.ToAddressWithData(scriptAddr, void 0, {}, scriptRefValidator).complete().then((tx) => tx.sign.withWallet().complete()).then((tx) => tx.submit());
|
|
5448
5724
|
await lucid.awaitTx(txHash);
|
|
5449
5725
|
return { txHash, outputIndex: 0 };
|
|
5450
5726
|
}
|
|
5727
|
+
|
|
5728
|
+
// src/contracts/leverage/transactions.ts
|
|
5729
|
+
var import_lucid51 = require("@lucid-evolution/lucid");
|
|
5730
|
+
|
|
5731
|
+
// src/contracts/leverage/helpers.ts
|
|
5732
|
+
var import_fp_ts14 = require("fp-ts");
|
|
5733
|
+
var import_decimal2 = require("decimal.js");
|
|
5734
|
+
var MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
|
|
5735
|
+
function approximateLeverageRedemptions(baseCollateral, targetLeverage, redemptionReimbursementPercentage, debtMintingFeePercentage) {
|
|
5736
|
+
const debtMintingFeeRatioDecimal = (0, import_decimal2.Decimal)(
|
|
5737
|
+
debtMintingFeePercentage.getOnChainInt
|
|
5738
|
+
).div(OCD_DECIMAL_UNIT).div(100);
|
|
5739
|
+
const redemptionReimbursementRatioDecimal = (0, import_decimal2.Decimal)(
|
|
5740
|
+
redemptionReimbursementPercentage.getOnChainInt
|
|
5741
|
+
).div(OCD_DECIMAL_UNIT).div(100);
|
|
5742
|
+
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
5743
|
+
redemptionReimbursementRatioDecimal
|
|
5744
|
+
);
|
|
5745
|
+
const bExFees = (0, import_decimal2.Decimal)(baseCollateral).mul(targetLeverage).minus(baseCollateral).floor();
|
|
5746
|
+
const b = bExFees.div((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
5747
|
+
const collateralRatio = {
|
|
5748
|
+
getOnChainInt: fromDecimal(
|
|
5749
|
+
(0, import_decimal2.Decimal)((0, import_decimal2.Decimal)(baseCollateral).add(bExFees)).div(b).mul(100n * OCD_DECIMAL_UNIT).floor()
|
|
5750
|
+
)
|
|
5751
|
+
};
|
|
5752
|
+
return {
|
|
5753
|
+
leverage: targetLeverage,
|
|
5754
|
+
collateralRatio,
|
|
5755
|
+
lovelacesForRedemptionWithReimbursement: fromDecimal(b)
|
|
5756
|
+
};
|
|
5757
|
+
}
|
|
5758
|
+
function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement, redemptionReimbursementPercentage, iassetPrice, lrpParams, redemptionLrps) {
|
|
5759
|
+
const priceDecimal = (0, import_decimal2.Decimal)(iassetPrice.getOnChainInt).div(OCD_DECIMAL_UNIT);
|
|
5760
|
+
const redemptionDetails = import_fp_ts14.function.pipe(
|
|
5761
|
+
redemptionLrps,
|
|
5762
|
+
import_fp_ts14.array.reduce(
|
|
5763
|
+
{
|
|
5764
|
+
remainingRedemptionLovelacesInclReim: lovelacesForRedemptionWithReimbursement,
|
|
5765
|
+
redemptions: []
|
|
5766
|
+
},
|
|
5767
|
+
(acc, lrp) => {
|
|
5768
|
+
if (acc.remainingRedemptionLovelacesInclReim < lrpParams.minRedemptionLovelacesAmt) {
|
|
5769
|
+
return acc;
|
|
5770
|
+
}
|
|
5771
|
+
const lovelacesToSpend = lrpRedeemableLovelacesInclReimb(
|
|
5772
|
+
lrp,
|
|
5773
|
+
lrpParams
|
|
5774
|
+
);
|
|
5775
|
+
if (lovelacesToSpend === 0n) {
|
|
5776
|
+
return acc;
|
|
5777
|
+
}
|
|
5778
|
+
const newRemainingLovelaces = bigintMax(
|
|
5779
|
+
acc.remainingRedemptionLovelacesInclReim - lovelacesToSpend,
|
|
5780
|
+
0n
|
|
5781
|
+
);
|
|
5782
|
+
const redemptionLovelacesInitial = acc.remainingRedemptionLovelacesInclReim - newRemainingLovelaces;
|
|
5783
|
+
const finalRedemptionIAssets = fromDecimal(
|
|
5784
|
+
(0, import_decimal2.Decimal)(redemptionLovelacesInitial).div(priceDecimal).floor()
|
|
5785
|
+
);
|
|
5786
|
+
const finalRedemptionLovelaces = ocdMul(
|
|
5787
|
+
{
|
|
5788
|
+
getOnChainInt: finalRedemptionIAssets
|
|
5789
|
+
},
|
|
5790
|
+
iassetPrice
|
|
5791
|
+
).getOnChainInt;
|
|
5792
|
+
const reimbursementLovelaces = calculateFeeFromPercentage(
|
|
5793
|
+
redemptionReimbursementPercentage,
|
|
5794
|
+
finalRedemptionLovelaces
|
|
5795
|
+
);
|
|
5796
|
+
return {
|
|
5797
|
+
remainingRedemptionLovelacesInclReim: acc.remainingRedemptionLovelacesInclReim - finalRedemptionLovelaces,
|
|
5798
|
+
redemptions: [
|
|
5799
|
+
...acc.redemptions,
|
|
5800
|
+
{
|
|
5801
|
+
utxo: lrp[0],
|
|
5802
|
+
iassetsForRedemptionAmt: finalRedemptionIAssets,
|
|
5803
|
+
redemptionLovelacesAmtInclReimbursement: finalRedemptionLovelaces,
|
|
5804
|
+
reimbursementLovelacesAmt: reimbursementLovelaces
|
|
5805
|
+
}
|
|
5806
|
+
]
|
|
5807
|
+
};
|
|
5808
|
+
}
|
|
5809
|
+
)
|
|
5810
|
+
);
|
|
5811
|
+
const res = import_fp_ts14.function.pipe(
|
|
5812
|
+
redemptionDetails.redemptions,
|
|
5813
|
+
import_fp_ts14.array.reduce(
|
|
5814
|
+
{
|
|
5815
|
+
redeemedLovelaces: 0n,
|
|
5816
|
+
redemptionIAssets: 0n,
|
|
5817
|
+
reimbursementLovelaces: 0n
|
|
5818
|
+
},
|
|
5819
|
+
(acc, details) => {
|
|
5820
|
+
return {
|
|
5821
|
+
redeemedLovelaces: acc.redeemedLovelaces + details.redemptionLovelacesAmtInclReimbursement - details.reimbursementLovelacesAmt,
|
|
5822
|
+
reimbursementLovelaces: acc.reimbursementLovelaces + details.reimbursementLovelacesAmt,
|
|
5823
|
+
redemptionIAssets: acc.redemptionIAssets + details.iassetsForRedemptionAmt
|
|
5824
|
+
};
|
|
5825
|
+
}
|
|
5826
|
+
)
|
|
5827
|
+
);
|
|
5828
|
+
return {
|
|
5829
|
+
redemptions: redemptionDetails.redemptions,
|
|
5830
|
+
totalRedeemedLovelaces: res.redeemedLovelaces,
|
|
5831
|
+
totalReimbursementLovelaces: res.reimbursementLovelaces,
|
|
5832
|
+
totalRedemptionIAssets: res.redemptionIAssets
|
|
5833
|
+
};
|
|
5834
|
+
}
|
|
5835
|
+
function calculateCollateralRatioFromLeverage(iasset, leverage, baseCollateral, iassetPrice, debtMintingFeePercentage, redemptionReimbursementPercentage, lrpParams, allLrps) {
|
|
5836
|
+
const debtMintingFeeRatioDecimal = (0, import_decimal2.Decimal)(
|
|
5837
|
+
debtMintingFeePercentage.getOnChainInt
|
|
5838
|
+
).div(OCD_DECIMAL_UNIT).div(100);
|
|
5839
|
+
const redemptionReimbursementRatioDecimal = (0, import_decimal2.Decimal)(
|
|
5840
|
+
redemptionReimbursementPercentage.getOnChainInt
|
|
5841
|
+
).div(OCD_DECIMAL_UNIT).div(100);
|
|
5842
|
+
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
5843
|
+
redemptionReimbursementRatioDecimal
|
|
5844
|
+
);
|
|
5845
|
+
const maxAvailableAdaForRedemptionInclReimb = calculateTotalAdaForRedemption(
|
|
5846
|
+
iasset,
|
|
5847
|
+
iassetPrice,
|
|
5848
|
+
lrpParams,
|
|
5849
|
+
allLrps,
|
|
5850
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN
|
|
5851
|
+
);
|
|
5852
|
+
if (leverage <= 1 || baseCollateral <= 0n || maxAvailableAdaForRedemptionInclReimb <= 0n) {
|
|
5853
|
+
return void 0;
|
|
5854
|
+
}
|
|
5855
|
+
const bExFees = (0, import_decimal2.Decimal)(baseCollateral).mul(leverage).minus(baseCollateral).floor();
|
|
5856
|
+
const b = bExFees.div((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
5857
|
+
const cappedB = bigintMin(
|
|
5858
|
+
maxAvailableAdaForRedemptionInclReimb,
|
|
5859
|
+
fromDecimal(b)
|
|
5860
|
+
);
|
|
5861
|
+
const cappedBExFees = (0, import_decimal2.Decimal)(cappedB).mul((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
5862
|
+
const collateralRatio = (0, import_decimal2.Decimal)(
|
|
5863
|
+
(0, import_decimal2.Decimal)(baseCollateral).add(cappedBExFees)
|
|
5864
|
+
).div(cappedB);
|
|
5865
|
+
return {
|
|
5866
|
+
getOnChainInt: fromDecimal(
|
|
5867
|
+
collateralRatio.mul(100n * OCD_DECIMAL_UNIT).floor()
|
|
5868
|
+
)
|
|
5869
|
+
};
|
|
5870
|
+
}
|
|
5871
|
+
function calculateLeverageFromCollateralRatio(iasset, collateralRatioPercentage, baseCollateral, iassetPrice, debtMintingFeePercentage, redemptionReimbursementPercentage, lrpParams, allLrps) {
|
|
5872
|
+
const debtMintingFeeRatioDecimal = (0, import_decimal2.Decimal)(
|
|
5873
|
+
debtMintingFeePercentage.getOnChainInt
|
|
5874
|
+
).div(OCD_DECIMAL_UNIT).div(100);
|
|
5875
|
+
const redemptionReimbursementRatioDecimal = (0, import_decimal2.Decimal)(
|
|
5876
|
+
redemptionReimbursementPercentage.getOnChainInt
|
|
5877
|
+
).div(OCD_DECIMAL_UNIT).div(100);
|
|
5878
|
+
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
5879
|
+
redemptionReimbursementRatioDecimal
|
|
5880
|
+
);
|
|
5881
|
+
const collateralRatio = (0, import_decimal2.Decimal)(collateralRatioPercentage.getOnChainInt).div(OCD_DECIMAL_UNIT).div(100);
|
|
5882
|
+
const maxAvailableAdaForRedemptionInclReimb = calculateTotalAdaForRedemption(
|
|
5883
|
+
iasset,
|
|
5884
|
+
iassetPrice,
|
|
5885
|
+
lrpParams,
|
|
5886
|
+
allLrps,
|
|
5887
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN
|
|
5888
|
+
);
|
|
5889
|
+
if (collateralRatio.toNumber() <= 1 || baseCollateral <= 0n || maxAvailableAdaForRedemptionInclReimb <= 0n) {
|
|
5890
|
+
return void 0;
|
|
5891
|
+
}
|
|
5892
|
+
const theoreticalMaxLeverage = (0, import_decimal2.Decimal)((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).div(collateralRatio.minus(1).add(totalFeeRatio)).add(1);
|
|
5893
|
+
const bExFees = theoreticalMaxLeverage.mul(baseCollateral).minus(baseCollateral).floor();
|
|
5894
|
+
const b = bExFees.div((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
5895
|
+
const cappedB = bigintMin(
|
|
5896
|
+
maxAvailableAdaForRedemptionInclReimb,
|
|
5897
|
+
fromDecimal(b)
|
|
5898
|
+
);
|
|
5899
|
+
const cappedBExFees = (0, import_decimal2.Decimal)(cappedB).mul((0, import_decimal2.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
5900
|
+
return (0, import_decimal2.Decimal)(baseCollateral).add(cappedBExFees).div(baseCollateral).toNumber();
|
|
5901
|
+
}
|
|
5902
|
+
|
|
5903
|
+
// src/contracts/leverage/transactions.ts
|
|
5904
|
+
async function leverageCdpWithLrp(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, cdpCreatorOref, interestOracleOref, collectorOref, sysParams, lucid, allLrps, currentSlot) {
|
|
5905
|
+
const network = lucid.config().network;
|
|
5906
|
+
const currentTime = BigInt((0, import_lucid51.slotToUnixTime)(network, currentSlot));
|
|
5907
|
+
const [pkh, skh] = await addrDetails(lucid);
|
|
5908
|
+
const lrpScriptRefUtxo = matchSingle(
|
|
5909
|
+
await lucid.utxosByOutRef([
|
|
5910
|
+
fromSystemParamsScriptRef(sysParams.scriptReferences.lrpValidatorRef)
|
|
5911
|
+
]),
|
|
5912
|
+
(_) => new Error("Expected a single LRP Ref Script UTXO")
|
|
5913
|
+
);
|
|
5914
|
+
const cdpCreatorRefScriptUtxo = matchSingle(
|
|
5915
|
+
await lucid.utxosByOutRef([
|
|
5916
|
+
fromSystemParamsScriptRef(
|
|
5917
|
+
sysParams.scriptReferences.cdpCreatorValidatorRef
|
|
5918
|
+
)
|
|
5919
|
+
]),
|
|
5920
|
+
(_) => new Error("Expected a single cdp creator Ref Script UTXO")
|
|
5921
|
+
);
|
|
5922
|
+
const cdpAuthTokenPolicyRefScriptUtxo = matchSingle(
|
|
5923
|
+
await lucid.utxosByOutRef([
|
|
5924
|
+
fromSystemParamsScriptRef(
|
|
5925
|
+
sysParams.scriptReferences.authTokenPolicies.cdpAuthTokenRef
|
|
5926
|
+
)
|
|
5927
|
+
]),
|
|
5928
|
+
(_) => new Error("Expected a single cdp auth token policy Ref Script UTXO")
|
|
5929
|
+
);
|
|
5930
|
+
const iAssetTokenPolicyRefScriptUtxo = matchSingle(
|
|
5931
|
+
await lucid.utxosByOutRef([
|
|
5932
|
+
fromSystemParamsScriptRef(
|
|
5933
|
+
sysParams.scriptReferences.iAssetTokenPolicyRef
|
|
5934
|
+
)
|
|
5935
|
+
]),
|
|
5936
|
+
(_) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
5937
|
+
);
|
|
5938
|
+
const cdpCreatorUtxo = matchSingle(
|
|
5939
|
+
await lucid.utxosByOutRef([cdpCreatorOref]),
|
|
5940
|
+
(_) => new Error("Expected a single CDP creator UTXO")
|
|
5941
|
+
);
|
|
5942
|
+
const interestOracleUtxo = matchSingle(
|
|
5943
|
+
await lucid.utxosByOutRef([interestOracleOref]),
|
|
5944
|
+
(_) => new Error("Expected a single interest oracle UTXO")
|
|
5945
|
+
);
|
|
5946
|
+
const interestOracleDatum = parseInterestOracleDatum(
|
|
5947
|
+
getInlineDatumOrThrow(interestOracleUtxo)
|
|
5948
|
+
);
|
|
5949
|
+
const priceOracleUtxo = matchSingle(
|
|
5950
|
+
await lucid.utxosByOutRef([priceOracleOutRef]),
|
|
5951
|
+
(_) => new Error("Expected a single price oracle UTXO")
|
|
5952
|
+
);
|
|
5953
|
+
const priceOracleDatum = parsePriceOracleDatum(
|
|
5954
|
+
getInlineDatumOrThrow(priceOracleUtxo)
|
|
5955
|
+
);
|
|
5956
|
+
const iassetUtxo = matchSingle(
|
|
5957
|
+
await lucid.utxosByOutRef([iassetOutRef]),
|
|
5958
|
+
(_) => new Error("Expected a single IAsset UTXO")
|
|
5959
|
+
);
|
|
5960
|
+
const iassetDatum = parseIAssetDatumOrThrow(
|
|
5961
|
+
getInlineDatumOrThrow(iassetUtxo)
|
|
5962
|
+
);
|
|
5963
|
+
const maxLeverage = calculateLeverageFromCollateralRatio(
|
|
5964
|
+
iassetDatum.assetName,
|
|
5965
|
+
iassetDatum.maintenanceRatio,
|
|
5966
|
+
baseCollateral,
|
|
5967
|
+
priceOracleDatum.price,
|
|
5968
|
+
iassetDatum.debtMintingFeePercentage,
|
|
5969
|
+
iassetDatum.redemptionReimbursementPercentage,
|
|
5970
|
+
sysParams.lrpParams,
|
|
5971
|
+
allLrps
|
|
5972
|
+
);
|
|
5973
|
+
if (!maxLeverage) {
|
|
5974
|
+
throw new Error("Can't calculate max leverage with those parameters.");
|
|
5975
|
+
}
|
|
5976
|
+
const leverageSummary = approximateLeverageRedemptions(
|
|
5977
|
+
baseCollateral,
|
|
5978
|
+
leverage,
|
|
5979
|
+
iassetDatum.redemptionReimbursementPercentage,
|
|
5980
|
+
iassetDatum.debtMintingFeePercentage
|
|
5981
|
+
);
|
|
5982
|
+
if (maxLeverage < leverageSummary.leverage) {
|
|
5983
|
+
throw new Error("Can't use more leverage than max.");
|
|
5984
|
+
}
|
|
5985
|
+
if (leverageSummary.collateralRatio.getOnChainInt < iassetDatum.maintenanceRatio.getOnChainInt) {
|
|
5986
|
+
throw new Error(
|
|
5987
|
+
"Can't have collateral ratio smaller than maintenance ratio"
|
|
5988
|
+
);
|
|
5989
|
+
}
|
|
5990
|
+
const redemptionDetails = summarizeActualLeverageRedemptions(
|
|
5991
|
+
leverageSummary.lovelacesForRedemptionWithReimbursement,
|
|
5992
|
+
iassetDatum.redemptionReimbursementPercentage,
|
|
5993
|
+
priceOracleDatum.price,
|
|
5994
|
+
sysParams.lrpParams,
|
|
5995
|
+
randomLrpsSubsetSatisfyingTargetLovelaces(
|
|
5996
|
+
iassetDatum.assetName,
|
|
5997
|
+
leverageSummary.lovelacesForRedemptionWithReimbursement,
|
|
5998
|
+
priceOracleDatum.price,
|
|
5999
|
+
allLrps,
|
|
6000
|
+
sysParams.lrpParams,
|
|
6001
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN
|
|
6002
|
+
)
|
|
6003
|
+
);
|
|
6004
|
+
const mintedAmt = redemptionDetails.totalRedemptionIAssets;
|
|
6005
|
+
const debtMintingFee = calculateFeeFromPercentage(
|
|
6006
|
+
iassetDatum.debtMintingFeePercentage,
|
|
6007
|
+
ocdMul({ getOnChainInt: mintedAmt }, priceOracleDatum.price).getOnChainInt
|
|
6008
|
+
);
|
|
6009
|
+
const collateralAmt = redemptionDetails.totalRedeemedLovelaces + baseCollateral - debtMintingFee;
|
|
6010
|
+
const cdpNftVal = mkAssetsOf(
|
|
6011
|
+
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
6012
|
+
1n
|
|
6013
|
+
);
|
|
6014
|
+
const iassetTokensVal = mkAssetsOf(
|
|
6015
|
+
{
|
|
6016
|
+
currencySymbol: sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol,
|
|
6017
|
+
tokenName: iassetDatum.assetName
|
|
6018
|
+
},
|
|
6019
|
+
mintedAmt
|
|
6020
|
+
);
|
|
6021
|
+
const txValidity = oracleExpirationAwareValidity(
|
|
6022
|
+
currentSlot,
|
|
6023
|
+
Number(sysParams.cdpCreatorParams.biasTime),
|
|
6024
|
+
Number(priceOracleDatum.expiration),
|
|
6025
|
+
network
|
|
6026
|
+
);
|
|
6027
|
+
const tx = lucid.newTx().validFrom(txValidity.validFrom).validTo(txValidity.validTo).readFrom([priceOracleUtxo, interestOracleUtxo, iassetUtxo]).readFrom([
|
|
6028
|
+
cdpCreatorRefScriptUtxo,
|
|
6029
|
+
cdpAuthTokenPolicyRefScriptUtxo,
|
|
6030
|
+
iAssetTokenPolicyRefScriptUtxo,
|
|
6031
|
+
lrpScriptRefUtxo
|
|
6032
|
+
]).mintAssets(cdpNftVal, import_lucid51.Data.void()).mintAssets(iassetTokensVal, import_lucid51.Data.void()).collectFrom(
|
|
6033
|
+
[cdpCreatorUtxo],
|
|
6034
|
+
serialiseCDPCreatorRedeemer({
|
|
6035
|
+
CreateCDP: {
|
|
6036
|
+
cdpOwner: pkh.hash,
|
|
6037
|
+
minted: mintedAmt,
|
|
6038
|
+
collateral: collateralAmt,
|
|
6039
|
+
currentTime
|
|
6040
|
+
}
|
|
6041
|
+
})
|
|
6042
|
+
).pay.ToContract(
|
|
6043
|
+
createScriptAddress(network, sysParams.validatorHashes.cdpHash, skh),
|
|
6044
|
+
{
|
|
6045
|
+
kind: "inline",
|
|
6046
|
+
value: serialiseCdpDatum({
|
|
6047
|
+
cdpOwner: pkh.hash,
|
|
6048
|
+
iasset: iassetDatum.assetName,
|
|
6049
|
+
mintedAmt,
|
|
6050
|
+
cdpFees: {
|
|
6051
|
+
ActiveCDPInterestTracking: {
|
|
6052
|
+
lastSettled: currentTime,
|
|
6053
|
+
unitaryInterestSnapshot: calculateUnitaryInterestSinceOracleLastUpdated(
|
|
6054
|
+
currentTime,
|
|
6055
|
+
interestOracleDatum
|
|
6056
|
+
) + interestOracleDatum.unitaryInterest
|
|
6057
|
+
}
|
|
6058
|
+
}
|
|
6059
|
+
})
|
|
6060
|
+
},
|
|
6061
|
+
(0, import_lucid51.addAssets)(cdpNftVal, mkLovelacesOf(collateralAmt))
|
|
6062
|
+
).pay.ToContract(
|
|
6063
|
+
cdpCreatorUtxo.address,
|
|
6064
|
+
{ kind: "inline", value: import_lucid51.Data.void() },
|
|
6065
|
+
cdpCreatorUtxo.assets
|
|
6066
|
+
).addSignerKey(pkh.hash);
|
|
6067
|
+
buildRedemptionsTx(
|
|
6068
|
+
redemptionDetails.redemptions.map((r) => [
|
|
6069
|
+
r.utxo,
|
|
6070
|
+
r.iassetsForRedemptionAmt
|
|
6071
|
+
]),
|
|
6072
|
+
priceOracleDatum.price,
|
|
6073
|
+
iassetDatum.redemptionReimbursementPercentage,
|
|
6074
|
+
sysParams,
|
|
6075
|
+
tx,
|
|
6076
|
+
2n
|
|
6077
|
+
);
|
|
6078
|
+
if (debtMintingFee > 0) {
|
|
6079
|
+
await collectorFeeTx(debtMintingFee, lucid, sysParams, tx, collectorOref);
|
|
6080
|
+
}
|
|
6081
|
+
return tx;
|
|
6082
|
+
}
|
|
5451
6083
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5452
6084
|
0 && (module.exports = {
|
|
5453
6085
|
AccountContentSchema,
|
|
@@ -5476,6 +6108,8 @@ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
|
|
|
5476
6108
|
LRPDatumSchema,
|
|
5477
6109
|
LRPParamsSchema,
|
|
5478
6110
|
LRPRedeemerSchema,
|
|
6111
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN,
|
|
6112
|
+
MIN_LRP_COLLATERAL_AMT,
|
|
5479
6113
|
ONE_DAY,
|
|
5480
6114
|
ONE_HOUR,
|
|
5481
6115
|
ONE_SECOND,
|
|
@@ -5506,12 +6140,17 @@ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
|
|
|
5506
6140
|
adjustSpAccount,
|
|
5507
6141
|
adjustStakingPosition,
|
|
5508
6142
|
adjustmentHelper,
|
|
6143
|
+
approximateLeverageRedemptions,
|
|
5509
6144
|
assetClassToUnit,
|
|
5510
6145
|
assetClassValueOf,
|
|
5511
6146
|
balance,
|
|
6147
|
+
buildRedemptionsTx,
|
|
5512
6148
|
burnCdp,
|
|
6149
|
+
calculateCollateralRatioFromLeverage,
|
|
5513
6150
|
calculateIAssetRedemptionAmt,
|
|
6151
|
+
calculateLeverageFromCollateralRatio,
|
|
5514
6152
|
calculateMinCollateralCappedIAssetRedemptionAmt,
|
|
6153
|
+
calculateTotalAdaForRedemption,
|
|
5515
6154
|
cancelLrp,
|
|
5516
6155
|
castCDPCreatorParams,
|
|
5517
6156
|
castCdpParams,
|
|
@@ -5536,6 +6175,7 @@ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
|
|
|
5536
6175
|
createShardsChunks,
|
|
5537
6176
|
createSpAccount,
|
|
5538
6177
|
depositCdp,
|
|
6178
|
+
distributeAda,
|
|
5539
6179
|
endProposal,
|
|
5540
6180
|
executeProposal,
|
|
5541
6181
|
feedInterestOracle,
|
|
@@ -5551,12 +6191,15 @@ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
|
|
|
5551
6191
|
getSumFromEpochToScaleToSum,
|
|
5552
6192
|
initEpochToScaleToSumMap,
|
|
5553
6193
|
initSpSnapshot,
|
|
6194
|
+
insertSorted,
|
|
5554
6195
|
isAssetsZero,
|
|
6196
|
+
leverageCdpWithLrp,
|
|
5555
6197
|
liquidateCdp,
|
|
5556
6198
|
liquidationHelper,
|
|
5557
6199
|
loadSystemParamsFromFile,
|
|
5558
6200
|
loadSystemParamsFromUrl,
|
|
5559
6201
|
lovelacesAmt,
|
|
6202
|
+
lrpRedeemableLovelacesInclReimb,
|
|
5560
6203
|
matchSingle,
|
|
5561
6204
|
mergeCdps,
|
|
5562
6205
|
mergeShards,
|
|
@@ -5596,6 +6239,7 @@ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
|
|
|
5596
6239
|
parseIAssetDatumOrThrow,
|
|
5597
6240
|
parseInterestOracleDatum,
|
|
5598
6241
|
parseLrpDatum,
|
|
6242
|
+
parseLrpDatumOrThrow,
|
|
5599
6243
|
parsePriceOracleDatum,
|
|
5600
6244
|
parseSnapshotEpochToScaleToSumDatum,
|
|
5601
6245
|
parseStabilityPoolDatum,
|
|
@@ -5603,6 +6247,7 @@ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
|
|
|
5603
6247
|
parseStakingPosition,
|
|
5604
6248
|
parseStakingPositionOrThrow,
|
|
5605
6249
|
processSpRequest,
|
|
6250
|
+
randomLrpsSubsetSatisfyingTargetLovelaces,
|
|
5606
6251
|
redeemCdp,
|
|
5607
6252
|
redeemLrp,
|
|
5608
6253
|
runCreateScriptRefTx,
|
|
@@ -5629,11 +6274,13 @@ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
|
|
|
5629
6274
|
serialiseStakingDatum,
|
|
5630
6275
|
serialiseStakingRedeemer,
|
|
5631
6276
|
setSumInEpochToScaleToSum,
|
|
6277
|
+
shuffle,
|
|
5632
6278
|
spAdd,
|
|
5633
6279
|
spDiv,
|
|
5634
6280
|
spMul,
|
|
5635
6281
|
spSub,
|
|
5636
6282
|
startInterestOracle,
|
|
6283
|
+
summarizeActualLeverageRedemptions,
|
|
5637
6284
|
toSystemParamsAsset,
|
|
5638
6285
|
treasuryFeeTx,
|
|
5639
6286
|
updatePoolSnapshotWithdrawalFee,
|