@indigo-labs/indigo-sdk 0.2.34 → 0.2.36
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 +60 -43
- package/dist/index.d.ts +60 -43
- package/dist/index.js +384 -421
- package/dist/index.mjs +385 -428
- package/package.json +1 -1
- package/src/contracts/cdp/transactions.ts +175 -201
- package/src/contracts/collector/transactions.ts +7 -11
- package/src/contracts/gov/transactions.ts +80 -68
- package/src/contracts/interest-oracle/transactions.ts +6 -6
- package/src/contracts/leverage/transactions.ts +24 -19
- package/src/contracts/lrp/transactions.ts +18 -20
- package/src/contracts/poll/helpers.ts +1 -1
- package/src/contracts/price-oracle/transactions.ts +6 -5
- package/src/contracts/stability-pool/transactions.ts +4 -10
- package/src/contracts/staking/helpers.ts +30 -47
- package/src/contracts/staking/transactions.ts +89 -58
- package/src/contracts/treasury/transactions.ts +10 -6
- package/src/contracts/vesting/helpers.ts +20 -69
- package/src/utils/lucid-utils.ts +33 -0
- package/tests/gov.test.ts +98 -16
- package/tests/staking.test.ts +24 -5
package/dist/index.mjs
CHANGED
|
@@ -34,6 +34,33 @@ import {
|
|
|
34
34
|
scriptHashToCredential,
|
|
35
35
|
stakeCredentialOf
|
|
36
36
|
} from "@lucid-evolution/lucid";
|
|
37
|
+
|
|
38
|
+
// src/utils/utils.ts
|
|
39
|
+
import * as fs from "fs";
|
|
40
|
+
import { match, P } from "ts-pattern";
|
|
41
|
+
function matchSingle(xs, mkErr) {
|
|
42
|
+
return match(xs).with([P.select()], (res) => res).otherwise(() => {
|
|
43
|
+
throw mkErr(xs);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function loadSystemParamsFromFile(file) {
|
|
47
|
+
return JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
48
|
+
}
|
|
49
|
+
function loadSystemParamsFromUrl(url) {
|
|
50
|
+
return fetch(url).then((res) => res.json()).then((data) => data);
|
|
51
|
+
}
|
|
52
|
+
var getRandomElement = (arr) => arr.length ? arr[Math.floor(Math.random() * arr.length)] : void 0;
|
|
53
|
+
|
|
54
|
+
// src/utils/lucid-utils.ts
|
|
55
|
+
async function resolveUtxo(input, lucid, errorMsg = "Expected a single UTXO") {
|
|
56
|
+
if ("address" in input) {
|
|
57
|
+
return input;
|
|
58
|
+
}
|
|
59
|
+
return matchSingle(
|
|
60
|
+
await lucid.utxosByOutRef([input]),
|
|
61
|
+
(_) => new Error(errorMsg)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
37
64
|
function getInlineDatumOrThrow(utxo) {
|
|
38
65
|
if (utxo.datum != null) {
|
|
39
66
|
return utxo.datum;
|
|
@@ -72,22 +99,6 @@ function balance(utxos) {
|
|
|
72
99
|
return utxos.reduce((acc, utxo) => addAssets(acc, utxo.assets), {});
|
|
73
100
|
}
|
|
74
101
|
|
|
75
|
-
// src/utils/utils.ts
|
|
76
|
-
import * as fs from "fs";
|
|
77
|
-
import { match, P } from "ts-pattern";
|
|
78
|
-
function matchSingle(xs, mkErr) {
|
|
79
|
-
return match(xs).with([P.select()], (res) => res).otherwise(() => {
|
|
80
|
-
throw mkErr(xs);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
function loadSystemParamsFromFile(file) {
|
|
84
|
-
return JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
85
|
-
}
|
|
86
|
-
function loadSystemParamsFromUrl(url) {
|
|
87
|
-
return fetch(url).then((res) => res.json()).then((data) => data);
|
|
88
|
-
}
|
|
89
|
-
var getRandomElement = (arr) => arr.length ? arr[Math.floor(Math.random() * arr.length)] : void 0;
|
|
90
|
-
|
|
91
102
|
// src/contracts/cdp/types.ts
|
|
92
103
|
import { Data as Data4 } from "@lucid-evolution/lucid";
|
|
93
104
|
|
|
@@ -1191,9 +1202,7 @@ function liquidationHelper(spContent, iassetBurnAmt, reward) {
|
|
|
1191
1202
|
import { array as A2, function as F3 } from "fp-ts";
|
|
1192
1203
|
|
|
1193
1204
|
// src/contracts/collector/transactions.ts
|
|
1194
|
-
import {
|
|
1195
|
-
Data as Data10
|
|
1196
|
-
} from "@lucid-evolution/lucid";
|
|
1205
|
+
import { Data as Data10 } from "@lucid-evolution/lucid";
|
|
1197
1206
|
|
|
1198
1207
|
// src/contracts/collector/types.ts
|
|
1199
1208
|
import { Data as Data9 } from "@lucid-evolution/lucid";
|
|
@@ -1208,10 +1217,11 @@ function serialiseCollectorRedeemer(redeemer) {
|
|
|
1208
1217
|
}
|
|
1209
1218
|
|
|
1210
1219
|
// src/contracts/collector/transactions.ts
|
|
1211
|
-
async function collectorFeeTx(fee, lucid, params, tx,
|
|
1212
|
-
const collectorUtxo =
|
|
1213
|
-
|
|
1214
|
-
|
|
1220
|
+
async function collectorFeeTx(fee, lucid, params, tx, collector) {
|
|
1221
|
+
const collectorUtxo = await resolveUtxo(
|
|
1222
|
+
collector,
|
|
1223
|
+
lucid,
|
|
1224
|
+
"Expected a single collector UTXO"
|
|
1215
1225
|
);
|
|
1216
1226
|
const collectorRefScriptUtxo = matchSingle(
|
|
1217
1227
|
await lucid.utxosByOutRef([
|
|
@@ -1264,11 +1274,12 @@ function serialiseTreasuryRedeemer(redeemer) {
|
|
|
1264
1274
|
}
|
|
1265
1275
|
|
|
1266
1276
|
// src/contracts/treasury/transactions.ts
|
|
1267
|
-
async function treasuryFeeTx(fee, lucid, sysParams, tx,
|
|
1277
|
+
async function treasuryFeeTx(fee, lucid, sysParams, tx, treasury) {
|
|
1268
1278
|
if (fee <= 0n) return;
|
|
1269
|
-
const treasuryUtxo =
|
|
1270
|
-
|
|
1271
|
-
|
|
1279
|
+
const treasuryUtxo = await resolveUtxo(
|
|
1280
|
+
treasury,
|
|
1281
|
+
lucid,
|
|
1282
|
+
"Expected a single treasury UTXO"
|
|
1272
1283
|
);
|
|
1273
1284
|
const treasuryRefScriptUtxo = matchSingle(
|
|
1274
1285
|
await lucid.utxosByOutRef([
|
|
@@ -1293,7 +1304,7 @@ async function treasuryFeeTx(fee, lucid, sysParams, tx, treasuryOref) {
|
|
|
1293
1304
|
}
|
|
1294
1305
|
|
|
1295
1306
|
// src/contracts/cdp/transactions.ts
|
|
1296
|
-
async function openCdp(collateralAmount, mintedAmount, sysParams,
|
|
1307
|
+
async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreator, iasset, priceOracle, interestOracle, collector, lucid, currentSlot) {
|
|
1297
1308
|
const network = lucid.config().network;
|
|
1298
1309
|
const currentTime = BigInt(slotToUnixTime3(network, currentSlot));
|
|
1299
1310
|
const [pkh, skh] = await addrDetails(lucid);
|
|
@@ -1321,30 +1332,34 @@ async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref
|
|
|
1321
1332
|
]),
|
|
1322
1333
|
(_) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
1323
1334
|
);
|
|
1324
|
-
const iassetUtxo =
|
|
1325
|
-
|
|
1326
|
-
|
|
1335
|
+
const iassetUtxo = await resolveUtxo(
|
|
1336
|
+
iasset,
|
|
1337
|
+
lucid,
|
|
1338
|
+
"Expected a single iasset UTXO"
|
|
1327
1339
|
);
|
|
1328
1340
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
1329
1341
|
getInlineDatumOrThrow(iassetUtxo)
|
|
1330
1342
|
);
|
|
1331
|
-
const priceOracleUtxo =
|
|
1332
|
-
|
|
1333
|
-
|
|
1343
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
1344
|
+
priceOracle,
|
|
1345
|
+
lucid,
|
|
1346
|
+
"Expected a single price oracle UTXO"
|
|
1334
1347
|
);
|
|
1335
1348
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
1336
1349
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
1337
1350
|
);
|
|
1338
|
-
const interestOracleUtxo =
|
|
1339
|
-
|
|
1340
|
-
|
|
1351
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
1352
|
+
interestOracle,
|
|
1353
|
+
lucid,
|
|
1354
|
+
"Expected a single interest oracle UTXO"
|
|
1341
1355
|
);
|
|
1342
1356
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
1343
1357
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
1344
1358
|
);
|
|
1345
|
-
const cdpCreatorUtxo =
|
|
1346
|
-
|
|
1347
|
-
|
|
1359
|
+
const cdpCreatorUtxo = await resolveUtxo(
|
|
1360
|
+
cdpCreator,
|
|
1361
|
+
lucid,
|
|
1362
|
+
"Expected a single CDP creator UTXO"
|
|
1348
1363
|
);
|
|
1349
1364
|
match7(iassetDatum.price).with({ Delisted: P6.any }, () => {
|
|
1350
1365
|
throw new Error("Can't open CDP of delisted asset");
|
|
@@ -1411,11 +1426,11 @@ async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref
|
|
|
1411
1426
|
mintedAmount * priceOracleDatum.price.getOnChainInt / 1000000n
|
|
1412
1427
|
);
|
|
1413
1428
|
if (debtMintingFee > 0) {
|
|
1414
|
-
await collectorFeeTx(debtMintingFee, lucid, sysParams, tx,
|
|
1429
|
+
await collectorFeeTx(debtMintingFee, lucid, sysParams, tx, collector);
|
|
1415
1430
|
}
|
|
1416
1431
|
return tx;
|
|
1417
1432
|
}
|
|
1418
|
-
async function adjustCdp(collateralAmount, mintAmount,
|
|
1433
|
+
async function adjustCdp(collateralAmount, mintAmount, cdp, iasset, priceOracle, interestOracle, collector, gov, treasury, sysParams, lucid, currentSlot) {
|
|
1419
1434
|
const network = lucid.config().network;
|
|
1420
1435
|
const currentTime = BigInt(slotToUnixTime3(network, currentSlot));
|
|
1421
1436
|
const cdpRefScriptUtxo = matchSingle(
|
|
@@ -1424,33 +1439,30 @@ async function adjustCdp(collateralAmount, mintAmount, cdpOref, iassetOref, pric
|
|
|
1424
1439
|
]),
|
|
1425
1440
|
(_) => new Error("Expected a single cdp Ref Script UTXO")
|
|
1426
1441
|
);
|
|
1427
|
-
const cdpUtxo =
|
|
1428
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
1429
|
-
(_) => new Error("Expected a single cdp UTXO")
|
|
1430
|
-
);
|
|
1442
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, "Expected a single cdp UTXO");
|
|
1431
1443
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
1432
|
-
const iassetUtxo =
|
|
1433
|
-
|
|
1434
|
-
|
|
1444
|
+
const iassetUtxo = await resolveUtxo(
|
|
1445
|
+
iasset,
|
|
1446
|
+
lucid,
|
|
1447
|
+
"Expected a single iasset UTXO"
|
|
1435
1448
|
);
|
|
1436
1449
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
1437
1450
|
getInlineDatumOrThrow(iassetUtxo)
|
|
1438
1451
|
);
|
|
1439
|
-
const govUtxo =
|
|
1440
|
-
await lucid.utxosByOutRef([govOref]),
|
|
1441
|
-
(_) => new Error("Expected a single gov UTXO")
|
|
1442
|
-
);
|
|
1452
|
+
const govUtxo = await resolveUtxo(gov, lucid, "Expected a single gov UTXO");
|
|
1443
1453
|
const govDatum = parseGovDatumOrThrow(getInlineDatumOrThrow(govUtxo));
|
|
1444
|
-
const priceOracleUtxo =
|
|
1445
|
-
|
|
1446
|
-
|
|
1454
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
1455
|
+
priceOracle,
|
|
1456
|
+
lucid,
|
|
1457
|
+
"Expected a single price oracle UTXO"
|
|
1447
1458
|
);
|
|
1448
1459
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
1449
1460
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
1450
1461
|
);
|
|
1451
|
-
const interestOracleUtxo =
|
|
1452
|
-
|
|
1453
|
-
|
|
1462
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
1463
|
+
interestOracle,
|
|
1464
|
+
lucid,
|
|
1465
|
+
"Expected a single interest oracle UTXO"
|
|
1454
1466
|
);
|
|
1455
1467
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
1456
1468
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
@@ -1538,13 +1550,7 @@ async function adjustCdp(collateralAmount, mintAmount, cdpOref, iassetOref, pric
|
|
|
1538
1550
|
);
|
|
1539
1551
|
const interestTreasuryAdaAmt = interestAdaAmt - interestCollectorAdaAmt;
|
|
1540
1552
|
if (interestTreasuryAdaAmt > 0) {
|
|
1541
|
-
await treasuryFeeTx(
|
|
1542
|
-
interestTreasuryAdaAmt,
|
|
1543
|
-
lucid,
|
|
1544
|
-
sysParams,
|
|
1545
|
-
tx,
|
|
1546
|
-
treasuryOref
|
|
1547
|
-
);
|
|
1553
|
+
await treasuryFeeTx(interestTreasuryAdaAmt, lucid, sysParams, tx, treasury);
|
|
1548
1554
|
}
|
|
1549
1555
|
let collectorFee = interestCollectorAdaAmt;
|
|
1550
1556
|
if (mintAmount > 0n) {
|
|
@@ -1560,75 +1566,75 @@ async function adjustCdp(collateralAmount, mintAmount, cdpOref, iassetOref, pric
|
|
|
1560
1566
|
);
|
|
1561
1567
|
}
|
|
1562
1568
|
if (collectorFee > 0n) {
|
|
1563
|
-
await collectorFeeTx(collectorFee, lucid, sysParams, tx,
|
|
1569
|
+
await collectorFeeTx(collectorFee, lucid, sysParams, tx, collector);
|
|
1564
1570
|
}
|
|
1565
1571
|
return tx;
|
|
1566
1572
|
}
|
|
1567
|
-
async function depositCdp(amount,
|
|
1573
|
+
async function depositCdp(amount, cdp, iasset, priceOracle, interestOracle, collector, gov, treasury, params, lucid, currentSlot) {
|
|
1568
1574
|
return adjustCdp(
|
|
1569
1575
|
amount,
|
|
1570
1576
|
0n,
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1577
|
+
cdp,
|
|
1578
|
+
iasset,
|
|
1579
|
+
priceOracle,
|
|
1580
|
+
interestOracle,
|
|
1581
|
+
collector,
|
|
1582
|
+
gov,
|
|
1583
|
+
treasury,
|
|
1578
1584
|
params,
|
|
1579
1585
|
lucid,
|
|
1580
1586
|
currentSlot
|
|
1581
1587
|
);
|
|
1582
1588
|
}
|
|
1583
|
-
async function withdrawCdp(amount,
|
|
1589
|
+
async function withdrawCdp(amount, cdp, iasset, priceOracle, interestOracle, collector, gov, treasury, params, lucid, currentSlot) {
|
|
1584
1590
|
return adjustCdp(
|
|
1585
1591
|
-amount,
|
|
1586
1592
|
0n,
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1593
|
+
cdp,
|
|
1594
|
+
iasset,
|
|
1595
|
+
priceOracle,
|
|
1596
|
+
interestOracle,
|
|
1597
|
+
collector,
|
|
1598
|
+
gov,
|
|
1599
|
+
treasury,
|
|
1594
1600
|
params,
|
|
1595
1601
|
lucid,
|
|
1596
1602
|
currentSlot
|
|
1597
1603
|
);
|
|
1598
1604
|
}
|
|
1599
|
-
async function mintCdp(amount,
|
|
1605
|
+
async function mintCdp(amount, cdp, iasset, priceOracle, interestOracle, collector, gov, treasury, params, lucid, currentSlot) {
|
|
1600
1606
|
return adjustCdp(
|
|
1601
1607
|
0n,
|
|
1602
1608
|
amount,
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1609
|
+
cdp,
|
|
1610
|
+
iasset,
|
|
1611
|
+
priceOracle,
|
|
1612
|
+
interestOracle,
|
|
1613
|
+
collector,
|
|
1614
|
+
gov,
|
|
1615
|
+
treasury,
|
|
1610
1616
|
params,
|
|
1611
1617
|
lucid,
|
|
1612
1618
|
currentSlot
|
|
1613
1619
|
);
|
|
1614
1620
|
}
|
|
1615
|
-
async function burnCdp(amount,
|
|
1621
|
+
async function burnCdp(amount, cdp, iasset, priceOracle, interestOracle, collector, gov, treasury, params, lucid, currentSlot) {
|
|
1616
1622
|
return adjustCdp(
|
|
1617
1623
|
0n,
|
|
1618
1624
|
-amount,
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1625
|
+
cdp,
|
|
1626
|
+
iasset,
|
|
1627
|
+
priceOracle,
|
|
1628
|
+
interestOracle,
|
|
1629
|
+
collector,
|
|
1630
|
+
gov,
|
|
1631
|
+
treasury,
|
|
1626
1632
|
params,
|
|
1627
1633
|
lucid,
|
|
1628
1634
|
currentSlot
|
|
1629
1635
|
);
|
|
1630
1636
|
}
|
|
1631
|
-
async function closeCdp(
|
|
1637
|
+
async function closeCdp(cdp, iasset, priceOracle, interestOracle, collector, gov, treasury, sysParams, lucid, currentSlot) {
|
|
1632
1638
|
const network = lucid.config().network;
|
|
1633
1639
|
const currentTime = BigInt(slotToUnixTime3(network, currentSlot));
|
|
1634
1640
|
const cdpRefScriptUtxo = matchSingle(
|
|
@@ -1653,33 +1659,30 @@ async function closeCdp(cdpOref, iassetOref, priceOracleOref, interestOracleOref
|
|
|
1653
1659
|
]),
|
|
1654
1660
|
(_) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
1655
1661
|
);
|
|
1656
|
-
const cdpUtxo =
|
|
1657
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
1658
|
-
(_) => new Error("Expected a single cdp UTXO")
|
|
1659
|
-
);
|
|
1662
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, "Expected a single cdp UTXO");
|
|
1660
1663
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
1661
|
-
const iassetUtxo =
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
+
const iassetUtxo = await resolveUtxo(
|
|
1665
|
+
iasset,
|
|
1666
|
+
lucid,
|
|
1667
|
+
"Expected a single iasset UTXO"
|
|
1664
1668
|
);
|
|
1665
1669
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
1666
1670
|
getInlineDatumOrThrow(iassetUtxo)
|
|
1667
1671
|
);
|
|
1668
|
-
const govUtxo =
|
|
1669
|
-
await lucid.utxosByOutRef([govOref]),
|
|
1670
|
-
(_) => new Error("Expected a single gov UTXO")
|
|
1671
|
-
);
|
|
1672
|
+
const govUtxo = await resolveUtxo(gov, lucid, "Expected a single gov UTXO");
|
|
1672
1673
|
const govDatum = parseGovDatumOrThrow(getInlineDatumOrThrow(govUtxo));
|
|
1673
|
-
const priceOracleUtxo =
|
|
1674
|
-
|
|
1675
|
-
|
|
1674
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
1675
|
+
priceOracle,
|
|
1676
|
+
lucid,
|
|
1677
|
+
"Expected a single price oracle UTXO"
|
|
1676
1678
|
);
|
|
1677
1679
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
1678
1680
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
1679
1681
|
);
|
|
1680
|
-
const interestOracleUtxo =
|
|
1681
|
-
|
|
1682
|
-
|
|
1682
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
1683
|
+
interestOracle,
|
|
1684
|
+
lucid,
|
|
1685
|
+
"Expected a single interest oracle UTXO"
|
|
1683
1686
|
);
|
|
1684
1687
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
1685
1688
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
@@ -1732,24 +1735,18 @@ async function closeCdp(cdpOref, iassetOref, priceOracleOref, interestOracleOref
|
|
|
1732
1735
|
);
|
|
1733
1736
|
const interestTreasuryAdaAmt = interestAdaAmt - interestCollectorAdaAmt;
|
|
1734
1737
|
if (interestTreasuryAdaAmt > 0) {
|
|
1735
|
-
await treasuryFeeTx(
|
|
1736
|
-
interestTreasuryAdaAmt,
|
|
1737
|
-
lucid,
|
|
1738
|
-
sysParams,
|
|
1739
|
-
tx,
|
|
1740
|
-
treasuryOref
|
|
1741
|
-
);
|
|
1738
|
+
await treasuryFeeTx(interestTreasuryAdaAmt, lucid, sysParams, tx, treasury);
|
|
1742
1739
|
}
|
|
1743
1740
|
const collectorFee = interestCollectorAdaAmt + calculateFeeFromPercentage(
|
|
1744
1741
|
govDatum.protocolParams.collateralFeePercentage,
|
|
1745
1742
|
lovelacesAmt(cdpUtxo.assets) - interestAdaAmt
|
|
1746
1743
|
);
|
|
1747
1744
|
if (collectorFee > 0n) {
|
|
1748
|
-
await collectorFeeTx(collectorFee, lucid, sysParams, tx,
|
|
1745
|
+
await collectorFeeTx(collectorFee, lucid, sysParams, tx, collector);
|
|
1749
1746
|
}
|
|
1750
1747
|
return tx;
|
|
1751
1748
|
}
|
|
1752
|
-
async function redeemCdp(attemptedRedemptionIAssetAmt,
|
|
1749
|
+
async function redeemCdp(attemptedRedemptionIAssetAmt, cdp, iasset, priceOracle, interestOracle, collector, treasury, sysParams, lucid, currentSlot) {
|
|
1753
1750
|
const network = lucid.config().network;
|
|
1754
1751
|
const currentTime = BigInt(slotToUnixTime3(network, currentSlot));
|
|
1755
1752
|
const cdpRefScriptUtxo = matchSingle(
|
|
@@ -1766,28 +1763,28 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, pric
|
|
|
1766
1763
|
]),
|
|
1767
1764
|
(_) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
1768
1765
|
);
|
|
1769
|
-
const cdpUtxo =
|
|
1770
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
1771
|
-
(_) => new Error("Expected a single cdp UTXO")
|
|
1772
|
-
);
|
|
1766
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, "Expected a single cdp UTXO");
|
|
1773
1767
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
1774
|
-
const iassetUtxo =
|
|
1775
|
-
|
|
1776
|
-
|
|
1768
|
+
const iassetUtxo = await resolveUtxo(
|
|
1769
|
+
iasset,
|
|
1770
|
+
lucid,
|
|
1771
|
+
"Expected a single iasset UTXO"
|
|
1777
1772
|
);
|
|
1778
1773
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
1779
1774
|
getInlineDatumOrThrow(iassetUtxo)
|
|
1780
1775
|
);
|
|
1781
|
-
const priceOracleUtxo =
|
|
1782
|
-
|
|
1783
|
-
|
|
1776
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
1777
|
+
priceOracle,
|
|
1778
|
+
lucid,
|
|
1779
|
+
"Expected a single price oracle UTXO"
|
|
1784
1780
|
);
|
|
1785
1781
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
1786
1782
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
1787
1783
|
);
|
|
1788
|
-
const interestOracleUtxo =
|
|
1789
|
-
|
|
1790
|
-
|
|
1784
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
1785
|
+
interestOracle,
|
|
1786
|
+
lucid,
|
|
1787
|
+
"Expected a single interest oracle UTXO"
|
|
1791
1788
|
);
|
|
1792
1789
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
1793
1790
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
@@ -1891,18 +1888,12 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, pric
|
|
|
1891
1888
|
lucid,
|
|
1892
1889
|
sysParams,
|
|
1893
1890
|
tx,
|
|
1894
|
-
|
|
1895
|
-
);
|
|
1896
|
-
await treasuryFeeTx(
|
|
1897
|
-
interestTreasuryAdaAmt,
|
|
1898
|
-
lucid,
|
|
1899
|
-
sysParams,
|
|
1900
|
-
tx,
|
|
1901
|
-
treasuryOref
|
|
1891
|
+
collector
|
|
1902
1892
|
);
|
|
1893
|
+
await treasuryFeeTx(interestTreasuryAdaAmt, lucid, sysParams, tx, treasury);
|
|
1903
1894
|
return tx;
|
|
1904
1895
|
}
|
|
1905
|
-
async function freezeCdp(
|
|
1896
|
+
async function freezeCdp(cdp, iasset, priceOracle, interestOracle, sysParams, lucid, currentSlot) {
|
|
1906
1897
|
const network = lucid.config().network;
|
|
1907
1898
|
const currentTime = BigInt(slotToUnixTime3(network, currentSlot));
|
|
1908
1899
|
const cdpRefScriptUtxo = matchSingle(
|
|
@@ -1911,28 +1902,28 @@ async function freezeCdp(cdpOref, iassetOref, priceOracleOref, interestOracleOre
|
|
|
1911
1902
|
]),
|
|
1912
1903
|
(_) => new Error("Expected a single cdp Ref Script UTXO")
|
|
1913
1904
|
);
|
|
1914
|
-
const cdpUtxo =
|
|
1915
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
1916
|
-
(_) => new Error("Expected a single cdp UTXO")
|
|
1917
|
-
);
|
|
1905
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, "Expected a single cdp UTXO");
|
|
1918
1906
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
1919
|
-
const iassetUtxo =
|
|
1920
|
-
|
|
1921
|
-
|
|
1907
|
+
const iassetUtxo = await resolveUtxo(
|
|
1908
|
+
iasset,
|
|
1909
|
+
lucid,
|
|
1910
|
+
"Expected a single iasset UTXO"
|
|
1922
1911
|
);
|
|
1923
1912
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
1924
1913
|
getInlineDatumOrThrow(iassetUtxo)
|
|
1925
1914
|
);
|
|
1926
|
-
const priceOracleUtxo =
|
|
1927
|
-
|
|
1928
|
-
|
|
1915
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
1916
|
+
priceOracle,
|
|
1917
|
+
lucid,
|
|
1918
|
+
"Expected a single price oracle UTXO"
|
|
1929
1919
|
);
|
|
1930
1920
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
1931
1921
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
1932
1922
|
);
|
|
1933
|
-
const interestOracleUtxo =
|
|
1934
|
-
|
|
1935
|
-
|
|
1923
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
1924
|
+
interestOracle,
|
|
1925
|
+
lucid,
|
|
1926
|
+
"Expected a single interest oracle UTXO"
|
|
1936
1927
|
);
|
|
1937
1928
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
1938
1929
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
@@ -2007,7 +1998,7 @@ async function freezeCdp(cdpOref, iassetOref, priceOracleOref, interestOracleOre
|
|
|
2007
1998
|
cdpUtxo.assets
|
|
2008
1999
|
);
|
|
2009
2000
|
}
|
|
2010
|
-
async function liquidateCdp(
|
|
2001
|
+
async function liquidateCdp(cdp, stabilityPool, collector, treasury, sysParams, lucid) {
|
|
2011
2002
|
const cdpRefScriptUtxo = matchSingle(
|
|
2012
2003
|
await lucid.utxosByOutRef([
|
|
2013
2004
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
@@ -2038,14 +2029,12 @@ async function liquidateCdp(cdpOref, stabilityPoolOref, collectorOref, treasuryO
|
|
|
2038
2029
|
]),
|
|
2039
2030
|
(_) => new Error("Expected a single cdp auth token policy Ref Script UTXO")
|
|
2040
2031
|
);
|
|
2041
|
-
const cdpUtxo =
|
|
2042
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
2043
|
-
(_) => new Error("Expected a single cdp UTXO")
|
|
2044
|
-
);
|
|
2032
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, "Expected a single cdp UTXO");
|
|
2045
2033
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
2046
|
-
const spUtxo =
|
|
2047
|
-
|
|
2048
|
-
|
|
2034
|
+
const spUtxo = await resolveUtxo(
|
|
2035
|
+
stabilityPool,
|
|
2036
|
+
lucid,
|
|
2037
|
+
"Expected a single stability pool UTXO"
|
|
2049
2038
|
);
|
|
2050
2039
|
const spDatum = parseStabilityPoolDatum(getInlineDatumOrThrow(spUtxo));
|
|
2051
2040
|
const [lovelacesForTreasury, lovelacesForCollector] = match7(cdpDatum.cdpFees).returnType().with({ FrozenCDPAccumulatedFees: P6.select() }, (fees) => [
|
|
@@ -2115,14 +2104,8 @@ async function liquidateCdp(cdpOref, stabilityPoolOref, collectorOref, treasuryO
|
|
|
2115
2104
|
Data13.void()
|
|
2116
2105
|
);
|
|
2117
2106
|
}
|
|
2118
|
-
await collectorFeeTx(
|
|
2119
|
-
|
|
2120
|
-
lucid,
|
|
2121
|
-
sysParams,
|
|
2122
|
-
tx,
|
|
2123
|
-
collectorOref
|
|
2124
|
-
);
|
|
2125
|
-
await treasuryFeeTx(lovelacesForTreasury, lucid, sysParams, tx, treasuryOref);
|
|
2107
|
+
await collectorFeeTx(lovelacesForCollector, lucid, sysParams, tx, collector);
|
|
2108
|
+
await treasuryFeeTx(lovelacesForTreasury, lucid, sysParams, tx, treasury);
|
|
2126
2109
|
return tx;
|
|
2127
2110
|
}
|
|
2128
2111
|
async function mergeCdps(cdpsToMergeUtxos, sysParams, lucid) {
|
|
@@ -2586,10 +2569,7 @@ function serialiseStakingDatum(d) {
|
|
|
2586
2569
|
}
|
|
2587
2570
|
|
|
2588
2571
|
// src/contracts/staking/helpers.ts
|
|
2589
|
-
import {
|
|
2590
|
-
fromText as fromText3,
|
|
2591
|
-
validatorToScriptHash
|
|
2592
|
-
} from "@lucid-evolution/lucid";
|
|
2572
|
+
import { fromText as fromText3, validatorToScriptHash } from "@lucid-evolution/lucid";
|
|
2593
2573
|
|
|
2594
2574
|
// src/contracts/staking/scripts.ts
|
|
2595
2575
|
import {
|
|
@@ -2643,20 +2623,17 @@ function updateStakingLockedAmount(stakingPosLockedAmt, currentTime) {
|
|
|
2643
2623
|
stakingPosLockedAmt.entries().filter(([_, { votingEnd }]) => votingEnd > currentTime)
|
|
2644
2624
|
);
|
|
2645
2625
|
}
|
|
2646
|
-
function findStakingManagerByOutRef(
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
);
|
|
2658
|
-
return result;
|
|
2659
|
-
});
|
|
2626
|
+
async function findStakingManagerByOutRef(stakingManager, lucid) {
|
|
2627
|
+
const utxo = await resolveUtxo(
|
|
2628
|
+
stakingManager,
|
|
2629
|
+
lucid,
|
|
2630
|
+
"Unable to locate Staking Manager by output reference."
|
|
2631
|
+
);
|
|
2632
|
+
if (!utxo.datum) {
|
|
2633
|
+
throw new Error("Staking Manager UTxO has no datum.");
|
|
2634
|
+
}
|
|
2635
|
+
const datum = parseStakingManagerDatum(utxo.datum);
|
|
2636
|
+
return { utxo, datum };
|
|
2660
2637
|
}
|
|
2661
2638
|
function findStakingManager(params, lucid) {
|
|
2662
2639
|
return lucid.utxosAtWithUnit(
|
|
@@ -2679,20 +2656,17 @@ function findStakingManager(params, lucid) {
|
|
|
2679
2656
|
return result;
|
|
2680
2657
|
});
|
|
2681
2658
|
}
|
|
2682
|
-
function findStakingPositionByOutRef(
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
);
|
|
2694
|
-
return result;
|
|
2695
|
-
});
|
|
2659
|
+
async function findStakingPositionByOutRef(stakingPosition, lucid) {
|
|
2660
|
+
const utxo = await resolveUtxo(
|
|
2661
|
+
stakingPosition,
|
|
2662
|
+
lucid,
|
|
2663
|
+
"Unable to locate Staking Position by output reference."
|
|
2664
|
+
);
|
|
2665
|
+
if (!utxo.datum) {
|
|
2666
|
+
throw new Error("Staking Position UTxO has no datum.");
|
|
2667
|
+
}
|
|
2668
|
+
const datum = parseStakingPositionOrThrow(utxo.datum);
|
|
2669
|
+
return { utxo, datum };
|
|
2696
2670
|
}
|
|
2697
2671
|
var rewardSnapshotPrecision = OCD_DECIMAL_UNIT * OCD_DECIMAL_UNIT;
|
|
2698
2672
|
function distributeReward(snapshotAda, adaReward, totalStake) {
|
|
@@ -2804,89 +2778,38 @@ var teamVestingSchedule = [
|
|
|
2804
2778
|
}
|
|
2805
2779
|
];
|
|
2806
2780
|
var spDistributionSchedule = {
|
|
2807
|
-
maxUnlockable:
|
|
2781
|
+
maxUnlockable: 2013760n * OCD_DECIMAL_UNIT,
|
|
2808
2782
|
schedule: [
|
|
2809
2783
|
{
|
|
2810
2784
|
vestedAtTime: 1669931100000n,
|
|
2811
2785
|
unlockAmt: 28768n * OCD_DECIMAL_UNIT
|
|
2812
|
-
},
|
|
2813
|
-
{
|
|
2814
|
-
vestedAtTime: 1701467100000n,
|
|
2815
|
-
unlockAmt: 33562n * OCD_DECIMAL_UNIT
|
|
2816
|
-
},
|
|
2817
|
-
{
|
|
2818
|
-
vestedAtTime: 1727387100000n,
|
|
2819
|
-
unlockAmt: 33561n * OCD_DECIMAL_UNIT
|
|
2820
|
-
},
|
|
2821
|
-
{
|
|
2822
|
-
vestedAtTime: 1733003100000n,
|
|
2823
|
-
unlockAmt: 38356n * OCD_DECIMAL_UNIT
|
|
2824
|
-
},
|
|
2825
|
-
{
|
|
2826
|
-
vestedAtTime: 1764539100000n,
|
|
2827
|
-
unlockAmt: 43150n * OCD_DECIMAL_UNIT
|
|
2828
|
-
},
|
|
2829
|
-
{
|
|
2830
|
-
vestedAtTime: 1796075100000n,
|
|
2831
|
-
unlockAmt: 47945n * OCD_DECIMAL_UNIT
|
|
2832
2786
|
}
|
|
2833
2787
|
]
|
|
2834
2788
|
};
|
|
2835
2789
|
var liqDistributionSchedule = {
|
|
2836
|
-
maxUnlockable:
|
|
2790
|
+
maxUnlockable: 316470n * OCD_DECIMAL_UNIT,
|
|
2837
2791
|
schedule: [
|
|
2838
2792
|
{
|
|
2839
2793
|
vestedAtTime: 1671659100000n,
|
|
2840
2794
|
unlockAmt: 4795n * OCD_DECIMAL_UNIT
|
|
2841
|
-
}
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
vestedAtTime: 1728683100000n,
|
|
2848
|
-
unlockAmt: 9589n * OCD_DECIMAL_UNIT
|
|
2849
|
-
},
|
|
2850
|
-
{
|
|
2851
|
-
vestedAtTime: 1734731100000n,
|
|
2852
|
-
unlockAmt: 14383n * OCD_DECIMAL_UNIT
|
|
2853
|
-
},
|
|
2854
|
-
{
|
|
2855
|
-
vestedAtTime: 1766267100000n,
|
|
2856
|
-
unlockAmt: 19178n * OCD_DECIMAL_UNIT
|
|
2857
|
-
},
|
|
2795
|
+
}
|
|
2796
|
+
]
|
|
2797
|
+
};
|
|
2798
|
+
var spLpDistributionSchedule = {
|
|
2799
|
+
maxUnlockable: 17016441n * OCD_DECIMAL_UNIT,
|
|
2800
|
+
schedule: [
|
|
2858
2801
|
{
|
|
2859
|
-
vestedAtTime:
|
|
2860
|
-
unlockAmt:
|
|
2802
|
+
vestedAtTime: 1700171100000n,
|
|
2803
|
+
unlockAmt: 33563n * OCD_DECIMAL_UNIT
|
|
2861
2804
|
}
|
|
2862
2805
|
]
|
|
2863
2806
|
};
|
|
2864
2807
|
var govDistributionSchedule = {
|
|
2865
|
-
maxUnlockable:
|
|
2808
|
+
maxUnlockable: 1381248n * OCD_DECIMAL_UNIT,
|
|
2866
2809
|
schedule: [
|
|
2867
2810
|
{
|
|
2868
2811
|
vestedAtTime: 1670363100000n,
|
|
2869
2812
|
unlockAmt: 2398n * OCD_DECIMAL_UNIT
|
|
2870
|
-
},
|
|
2871
|
-
{
|
|
2872
|
-
vestedAtTime: 1701899100000n,
|
|
2873
|
-
unlockAmt: 3596n * OCD_DECIMAL_UNIT
|
|
2874
|
-
},
|
|
2875
|
-
{
|
|
2876
|
-
vestedAtTime: 1733435100000n,
|
|
2877
|
-
unlockAmt: 4795n * OCD_DECIMAL_UNIT
|
|
2878
|
-
},
|
|
2879
|
-
{
|
|
2880
|
-
vestedAtTime: 1752443100000n,
|
|
2881
|
-
unlockAmt: 4794n * OCD_DECIMAL_UNIT
|
|
2882
|
-
},
|
|
2883
|
-
{
|
|
2884
|
-
vestedAtTime: 1764971100000n,
|
|
2885
|
-
unlockAmt: 5993n * OCD_DECIMAL_UNIT
|
|
2886
|
-
},
|
|
2887
|
-
{
|
|
2888
|
-
vestedAtTime: 1796507100000n,
|
|
2889
|
-
unlockAmt: 7191n * OCD_DECIMAL_UNIT
|
|
2890
2813
|
}
|
|
2891
2814
|
]
|
|
2892
2815
|
};
|
|
@@ -2919,7 +2842,7 @@ function calculateVestedPerEpoch(schedule, currentTime) {
|
|
|
2919
2842
|
return bigintMin(schedule.maxUnlockable, go(schedule.schedule));
|
|
2920
2843
|
}
|
|
2921
2844
|
function calculateTotalVestedRewards(currentTime) {
|
|
2922
|
-
return calculateVestedPerEpoch(spDistributionSchedule, currentTime) + calculateVestedPerEpoch(govDistributionSchedule, currentTime) + calculateVestedPerEpoch(liqDistributionSchedule, currentTime);
|
|
2845
|
+
return calculateVestedPerEpoch(spDistributionSchedule, currentTime) + calculateVestedPerEpoch(govDistributionSchedule, currentTime) + calculateVestedPerEpoch(liqDistributionSchedule, currentTime) + calculateVestedPerEpoch(spLpDistributionSchedule, currentTime);
|
|
2923
2846
|
}
|
|
2924
2847
|
|
|
2925
2848
|
// src/contracts/poll/helpers.ts
|
|
@@ -2941,7 +2864,7 @@ function q(initialIndyDist, pollStatus, currentTime, treasuryIndyWithdrawnAmt) {
|
|
|
2941
2864
|
)
|
|
2942
2865
|
}
|
|
2943
2866
|
).getOnChainInt;
|
|
2944
|
-
return { getOnChainInt: BigInt(q2) };
|
|
2867
|
+
return { getOnChainInt: BigInt(q2) / 1000n };
|
|
2945
2868
|
}
|
|
2946
2869
|
}
|
|
2947
2870
|
function pollPassQuorum(initialIndyDist, pollStatus, currentTime, minQuorum, treasuryIndyWithdrawnAmt) {
|
|
@@ -3126,7 +3049,7 @@ function serialiseVersionRecordDatum(d) {
|
|
|
3126
3049
|
}
|
|
3127
3050
|
|
|
3128
3051
|
// src/contracts/gov/transactions.ts
|
|
3129
|
-
async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lucid, currentSlot,
|
|
3052
|
+
async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lucid, currentSlot, gov, allIAssetOrefs) {
|
|
3130
3053
|
const network = lucid.config().network;
|
|
3131
3054
|
const currentTime = BigInt(slotToUnixTime4(network, currentSlot));
|
|
3132
3055
|
const ownAddr = await lucid.wallet().address();
|
|
@@ -3147,10 +3070,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
3147
3070
|
]),
|
|
3148
3071
|
(_) => new Error("Expected a single poll auth token policy ref Script UTXO")
|
|
3149
3072
|
);
|
|
3150
|
-
const govUtxo =
|
|
3151
|
-
await lucid.utxosByOutRef([govOref]),
|
|
3152
|
-
(_) => new Error("Expected a single Gov UTXO")
|
|
3153
|
-
);
|
|
3073
|
+
const govUtxo = await resolveUtxo(gov, lucid, "Expected a single Gov UTXO");
|
|
3154
3074
|
const govDatum = parseGovDatumOrThrow(getInlineDatumOrThrow(govUtxo));
|
|
3155
3075
|
const votingEndTime = currentTime + govDatum.protocolParams.votingPeriod;
|
|
3156
3076
|
const expirationTime = votingEndTime + govDatum.protocolParams.expirationPeriod;
|
|
@@ -3244,18 +3164,19 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
3244
3164
|
newPollId
|
|
3245
3165
|
];
|
|
3246
3166
|
}
|
|
3247
|
-
async function createShardsChunks(chunkSize,
|
|
3167
|
+
async function createShardsChunks(chunkSize, pollManager, sysParams, currentSlot, lucid) {
|
|
3248
3168
|
const network = lucid.config().network;
|
|
3249
3169
|
const currentTime = BigInt(slotToUnixTime4(network, currentSlot));
|
|
3250
3170
|
const ownAddr = await lucid.wallet().address();
|
|
3251
|
-
const pollManagerUtxo =
|
|
3252
|
-
|
|
3253
|
-
|
|
3171
|
+
const pollManagerUtxo = await resolveUtxo(
|
|
3172
|
+
pollManager,
|
|
3173
|
+
lucid,
|
|
3174
|
+
"Expected a single Poll manager UTXO"
|
|
3254
3175
|
);
|
|
3255
|
-
const
|
|
3176
|
+
const pollManagerDatum = parsePollManagerOrThrow(
|
|
3256
3177
|
getInlineDatumOrThrow(pollManagerUtxo)
|
|
3257
3178
|
);
|
|
3258
|
-
if (
|
|
3179
|
+
if (pollManagerDatum.createdShardsCount >= pollManagerDatum.totalShardsCount) {
|
|
3259
3180
|
throw new Error("All shards already created.");
|
|
3260
3181
|
}
|
|
3261
3182
|
const pollAuthTokenPolicyRefScriptUtxo = matchSingle(
|
|
@@ -3277,7 +3198,9 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
|
|
|
3277
3198
|
const shardsCount = BigInt(
|
|
3278
3199
|
Math.min(
|
|
3279
3200
|
Number(chunkSize),
|
|
3280
|
-
Number(
|
|
3201
|
+
Number(
|
|
3202
|
+
pollManagerDatum.totalShardsCount - pollManagerDatum.createdShardsCount
|
|
3203
|
+
)
|
|
3281
3204
|
)
|
|
3282
3205
|
);
|
|
3283
3206
|
const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
|
|
@@ -3293,8 +3216,8 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
|
|
|
3293
3216
|
value: serialisePollDatum({
|
|
3294
3217
|
PollManager: {
|
|
3295
3218
|
content: {
|
|
3296
|
-
...
|
|
3297
|
-
createdShardsCount:
|
|
3219
|
+
...pollManagerDatum,
|
|
3220
|
+
createdShardsCount: pollManagerDatum.createdShardsCount + shardsCount
|
|
3298
3221
|
}
|
|
3299
3222
|
}
|
|
3300
3223
|
})
|
|
@@ -3309,9 +3232,9 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
|
|
|
3309
3232
|
value: serialisePollDatum({
|
|
3310
3233
|
PollShard: {
|
|
3311
3234
|
content: {
|
|
3312
|
-
pollId:
|
|
3235
|
+
pollId: pollManagerDatum.pollId,
|
|
3313
3236
|
status: { yesVotes: 0n, noVotes: 0n },
|
|
3314
|
-
votingEndTime:
|
|
3237
|
+
votingEndTime: pollManagerDatum.votingEndTime,
|
|
3315
3238
|
managerAddress: addressFromBech32(pollManagerUtxo.address)
|
|
3316
3239
|
}
|
|
3317
3240
|
}
|
|
@@ -3339,7 +3262,7 @@ function voteHelper(stakingPosLockedAmt, pollShard, voteOption, currentTime, ind
|
|
|
3339
3262
|
];
|
|
3340
3263
|
return [new Map(newLockedAmt), newPollStatus];
|
|
3341
3264
|
}
|
|
3342
|
-
async function vote(voteOption,
|
|
3265
|
+
async function vote(voteOption, pollShard, stakingPosition, sysParams, lucid, currentSlot) {
|
|
3343
3266
|
const network = lucid.config().network;
|
|
3344
3267
|
const currentTime = BigInt(slotToUnixTime4(network, currentSlot));
|
|
3345
3268
|
const ownAddr = await lucid.wallet().address();
|
|
@@ -3357,16 +3280,18 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
|
|
|
3357
3280
|
]),
|
|
3358
3281
|
(_) => new Error("Expected a single staking ref Script UTXO")
|
|
3359
3282
|
);
|
|
3360
|
-
const pollShardUtxo =
|
|
3361
|
-
|
|
3362
|
-
|
|
3283
|
+
const pollShardUtxo = await resolveUtxo(
|
|
3284
|
+
pollShard,
|
|
3285
|
+
lucid,
|
|
3286
|
+
"Expected a single Poll shard UTXO"
|
|
3363
3287
|
);
|
|
3364
3288
|
const pollShardDatum = parsePollShardOrThrow(
|
|
3365
3289
|
getInlineDatumOrThrow(pollShardUtxo)
|
|
3366
3290
|
);
|
|
3367
|
-
const stakingPosUtxo =
|
|
3368
|
-
|
|
3369
|
-
|
|
3291
|
+
const stakingPosUtxo = await resolveUtxo(
|
|
3292
|
+
stakingPosition,
|
|
3293
|
+
lucid,
|
|
3294
|
+
"Expected a single staking position UTXO"
|
|
3370
3295
|
);
|
|
3371
3296
|
const stakingPosDatum = parseStakingPositionOrThrow(
|
|
3372
3297
|
getInlineDatumOrThrow(stakingPosUtxo)
|
|
@@ -3386,7 +3311,12 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
|
|
|
3386
3311
|
BigInt(validityFrom),
|
|
3387
3312
|
indyStakedAmt
|
|
3388
3313
|
);
|
|
3389
|
-
return lucid.newTx().validFrom(validityFrom).validTo(
|
|
3314
|
+
return lucid.newTx().validFrom(validityFrom).validTo(
|
|
3315
|
+
Math.min(
|
|
3316
|
+
Number(pollShardDatum.votingEndTime) - ONE_SECOND,
|
|
3317
|
+
Number(currentTime) + Number(sysParams.govParams.gBiasTime) - ONE_SECOND
|
|
3318
|
+
)
|
|
3319
|
+
).readFrom([stakingRefScriptUtxo, pollShardRefScriptUtxo]).collectFrom([stakingPosUtxo], serialiseStakingRedeemer("Lock")).collectFrom(
|
|
3390
3320
|
[pollShardUtxo],
|
|
3391
3321
|
serialisePollShardRedeemer({ Vote: { content: voteOption } })
|
|
3392
3322
|
).pay.ToContract(
|
|
@@ -3415,7 +3345,7 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
|
|
|
3415
3345
|
stakingPosUtxo.assets
|
|
3416
3346
|
).addSigner(ownAddr);
|
|
3417
3347
|
}
|
|
3418
|
-
async function mergeShards(
|
|
3348
|
+
async function mergeShards(pollManager, shardsOutRefs, sysParams, lucid, currentSlot) {
|
|
3419
3349
|
const network = lucid.config().network;
|
|
3420
3350
|
const currentTime = BigInt(slotToUnixTime4(network, currentSlot));
|
|
3421
3351
|
const ownAddr = await lucid.wallet().address();
|
|
@@ -3443,9 +3373,10 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
3443
3373
|
]),
|
|
3444
3374
|
(_) => new Error("Expected a single poll auth token policy ref Script UTXO")
|
|
3445
3375
|
);
|
|
3446
|
-
const pollManagerUtxo =
|
|
3447
|
-
|
|
3448
|
-
|
|
3376
|
+
const pollManagerUtxo = await resolveUtxo(
|
|
3377
|
+
pollManager,
|
|
3378
|
+
lucid,
|
|
3379
|
+
"Expected a single Poll manager UTXO"
|
|
3449
3380
|
);
|
|
3450
3381
|
const pollManagerDatum = parsePollManagerOrThrow(
|
|
3451
3382
|
getInlineDatumOrThrow(pollManagerUtxo)
|
|
@@ -3506,7 +3437,7 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
3506
3437
|
addAssets5(pollManagerUtxo.assets, shardsAggregatedAda)
|
|
3507
3438
|
).addSigner(ownAddr);
|
|
3508
3439
|
}
|
|
3509
|
-
async function endProposal(
|
|
3440
|
+
async function endProposal(pollManager, gov, sysParams, lucid, currentSlot) {
|
|
3510
3441
|
const network = lucid.config().network;
|
|
3511
3442
|
const currentTime = BigInt(slotToUnixTime4(network, currentSlot));
|
|
3512
3443
|
const ownAddr = await lucid.wallet().address();
|
|
@@ -3542,28 +3473,26 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
|
|
|
3542
3473
|
]),
|
|
3543
3474
|
(_) => new Error("Expected a single upgrade auth token policy ref Script UTXO")
|
|
3544
3475
|
);
|
|
3545
|
-
const pollManagerUtxo =
|
|
3546
|
-
|
|
3547
|
-
|
|
3476
|
+
const pollManagerUtxo = await resolveUtxo(
|
|
3477
|
+
pollManager,
|
|
3478
|
+
lucid,
|
|
3479
|
+
"Expected a single Poll manager UTXO"
|
|
3548
3480
|
);
|
|
3549
|
-
const
|
|
3481
|
+
const pollManagerDatum = parsePollManagerOrThrow(
|
|
3550
3482
|
getInlineDatumOrThrow(pollManagerUtxo)
|
|
3551
3483
|
);
|
|
3552
|
-
const govUtxo =
|
|
3553
|
-
await lucid.utxosByOutRef([govOref]),
|
|
3554
|
-
(_) => new Error("Expected a single Gov UTXO")
|
|
3555
|
-
);
|
|
3484
|
+
const govUtxo = await resolveUtxo(gov, lucid, "Expected a single Gov UTXO");
|
|
3556
3485
|
const govDatum = parseGovDatumOrThrow(getInlineDatumOrThrow(govUtxo));
|
|
3557
3486
|
const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
|
|
3558
3487
|
const indyAsset = fromSystemParamsAsset(
|
|
3559
3488
|
sysParams.pollManagerParams.indyAsset
|
|
3560
3489
|
);
|
|
3561
|
-
const proposalExpired = currentTime >
|
|
3490
|
+
const proposalExpired = currentTime > pollManagerDatum.expirationTime;
|
|
3562
3491
|
const proposalPassed = !proposalExpired && pollPassQuorum(
|
|
3563
3492
|
sysParams.pollManagerParams.initialIndyDistribution,
|
|
3564
|
-
|
|
3493
|
+
pollManagerDatum.status,
|
|
3565
3494
|
currentTime,
|
|
3566
|
-
|
|
3495
|
+
pollManagerDatum.minimumQuorum,
|
|
3567
3496
|
govDatum.treasuryIndyWithdrawnAmt
|
|
3568
3497
|
);
|
|
3569
3498
|
const upgradeTokenVal = mkAssetsOf(
|
|
@@ -3600,12 +3529,12 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
|
|
|
3600
3529
|
{
|
|
3601
3530
|
kind: "inline",
|
|
3602
3531
|
value: serialiseExecuteDatum({
|
|
3603
|
-
id:
|
|
3604
|
-
content:
|
|
3532
|
+
id: pollManagerDatum.pollId,
|
|
3533
|
+
content: pollManagerDatum.content,
|
|
3605
3534
|
passedTime: currentTime,
|
|
3606
|
-
votingEndTime:
|
|
3607
|
-
protocolVersion:
|
|
3608
|
-
treasuryWithdrawal:
|
|
3535
|
+
votingEndTime: pollManagerDatum.votingEndTime,
|
|
3536
|
+
protocolVersion: pollManagerDatum.protocolVersion,
|
|
3537
|
+
treasuryWithdrawal: pollManagerDatum.treasuryWithdrawal
|
|
3609
3538
|
})
|
|
3610
3539
|
},
|
|
3611
3540
|
upgradeTokenVal
|
|
@@ -3622,14 +3551,11 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
|
|
|
3622
3551
|
}
|
|
3623
3552
|
return tx;
|
|
3624
3553
|
}
|
|
3625
|
-
async function executeProposal(
|
|
3554
|
+
async function executeProposal(execute, gov, treasuryWithdrawal, allIAssetOrefs, modifyIAsset, sysParams, lucid, currentSlot) {
|
|
3626
3555
|
const network = lucid.config().network;
|
|
3627
3556
|
const currentTime = BigInt(slotToUnixTime4(network, currentSlot));
|
|
3628
3557
|
const ownAddr = await lucid.wallet().address();
|
|
3629
|
-
const govUtxo =
|
|
3630
|
-
await lucid.utxosByOutRef([govOref]),
|
|
3631
|
-
(_) => new Error("Expected a single gov UTXO")
|
|
3632
|
-
);
|
|
3558
|
+
const govUtxo = await resolveUtxo(gov, lucid, "Expected a single gov UTXO");
|
|
3633
3559
|
const govDatum = parseGovDatumOrThrow(getInlineDatumOrThrow(govUtxo));
|
|
3634
3560
|
const govRefScriptUtxo = matchSingle(
|
|
3635
3561
|
await lucid.utxosByOutRef([
|
|
@@ -3653,9 +3579,10 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3653
3579
|
]),
|
|
3654
3580
|
(_) => new Error("Expected a single upgrade auth token policy ref Script UTXO")
|
|
3655
3581
|
);
|
|
3656
|
-
const executeUtxo =
|
|
3657
|
-
|
|
3658
|
-
|
|
3582
|
+
const executeUtxo = await resolveUtxo(
|
|
3583
|
+
execute,
|
|
3584
|
+
lucid,
|
|
3585
|
+
"Expected a single execute UTXO"
|
|
3659
3586
|
);
|
|
3660
3587
|
const executeDatum = parseExecuteDatumOrThrow(
|
|
3661
3588
|
getInlineDatumOrThrow(executeUtxo)
|
|
@@ -3673,13 +3600,13 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3673
3600
|
O7.fromNullable(executeDatum.treasuryWithdrawal),
|
|
3674
3601
|
O7.match(
|
|
3675
3602
|
() => {
|
|
3676
|
-
if (
|
|
3603
|
+
if (treasuryWithdrawal) {
|
|
3677
3604
|
throw new Error("Cannot provide withdrawal oref when no withdrawal.");
|
|
3678
3605
|
}
|
|
3679
3606
|
return Promise.resolve();
|
|
3680
3607
|
},
|
|
3681
3608
|
async (withdrawal) => {
|
|
3682
|
-
if (!
|
|
3609
|
+
if (!treasuryWithdrawal) {
|
|
3683
3610
|
throw new Error("Have to provide withdrawal oref when withdrawal.");
|
|
3684
3611
|
}
|
|
3685
3612
|
const treasuryRefScriptUtxo = matchSingle(
|
|
@@ -3690,9 +3617,10 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3690
3617
|
]),
|
|
3691
3618
|
(_) => new Error("Expected a single Treasury Ref Script UTXO")
|
|
3692
3619
|
);
|
|
3693
|
-
const treasuryWithdrawalUtxo =
|
|
3694
|
-
|
|
3695
|
-
|
|
3620
|
+
const treasuryWithdrawalUtxo = await resolveUtxo(
|
|
3621
|
+
treasuryWithdrawal,
|
|
3622
|
+
lucid,
|
|
3623
|
+
"Expected a single withdrawal UTXO"
|
|
3696
3624
|
);
|
|
3697
3625
|
const withdrawalVal = createValueFromWithdrawal(withdrawal);
|
|
3698
3626
|
const withdrawalChangeVal = addAssets5(
|
|
@@ -3855,12 +3783,13 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3855
3783
|
]),
|
|
3856
3784
|
(_) => new Error("Expected a single CDP Ref Script UTXO")
|
|
3857
3785
|
);
|
|
3858
|
-
if (!
|
|
3786
|
+
if (!modifyIAsset) {
|
|
3859
3787
|
throw new Error("Have to provide iasset oref when modify asset.");
|
|
3860
3788
|
}
|
|
3861
|
-
const iassetUtxo =
|
|
3862
|
-
|
|
3863
|
-
|
|
3789
|
+
const iassetUtxo = await resolveUtxo(
|
|
3790
|
+
modifyIAsset,
|
|
3791
|
+
lucid,
|
|
3792
|
+
"Expected a single iasset UTXO"
|
|
3864
3793
|
);
|
|
3865
3794
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
3866
3795
|
getInlineDatumOrThrow(iassetUtxo)
|
|
@@ -4200,7 +4129,7 @@ async function closeSpAccount(accountUtxo, params, lucid) {
|
|
|
4200
4129
|
}
|
|
4201
4130
|
).addSignerKey(toHex(oldAccountDatum.owner));
|
|
4202
4131
|
}
|
|
4203
|
-
async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo, iAssetUtxo, newSnapshotUtxo, params, lucid,
|
|
4132
|
+
async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo, iAssetUtxo, newSnapshotUtxo, params, lucid, collector) {
|
|
4204
4133
|
const redeemer = {
|
|
4205
4134
|
ProcessRequest: {
|
|
4206
4135
|
txHash: { hash: fromHex2(accountUtxo.txHash) },
|
|
@@ -4383,13 +4312,7 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4383
4312
|
newPoolSum
|
|
4384
4313
|
);
|
|
4385
4314
|
if (rewardLovelacesFee > 0n) {
|
|
4386
|
-
await collectorFeeTx(
|
|
4387
|
-
rewardLovelacesFee,
|
|
4388
|
-
lucid,
|
|
4389
|
-
params,
|
|
4390
|
-
tx,
|
|
4391
|
-
collectorOref
|
|
4392
|
-
);
|
|
4315
|
+
await collectorFeeTx(rewardLovelacesFee, lucid, params, tx, collector);
|
|
4393
4316
|
}
|
|
4394
4317
|
tx.readFrom([govUtxo, iAssetUtxo, ...refInputs]);
|
|
4395
4318
|
tx.pay.ToContract(
|
|
@@ -4500,7 +4423,7 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4500
4423
|
params.scriptReferences.authTokenPolicies.accountTokenRef,
|
|
4501
4424
|
lucid
|
|
4502
4425
|
);
|
|
4503
|
-
await collectorFeeTx(rewardLovelacesFee, lucid, params, tx,
|
|
4426
|
+
await collectorFeeTx(rewardLovelacesFee, lucid, params, tx, collector);
|
|
4504
4427
|
tx.readFrom([govUtxo, iAssetUtxo, accountTokenRef, ...refInputs]);
|
|
4505
4428
|
tx.mintAssets(
|
|
4506
4429
|
{
|
|
@@ -4598,9 +4521,16 @@ import {
|
|
|
4598
4521
|
slotToUnixTime as slotToUnixTime5,
|
|
4599
4522
|
toHex as toHex2
|
|
4600
4523
|
} from "@lucid-evolution/lucid";
|
|
4601
|
-
async function openStakingPosition(amount, params, lucid,
|
|
4524
|
+
async function openStakingPosition(amount, params, lucid, stakingManager) {
|
|
4602
4525
|
const [pkh, _] = await addrDetails(lucid);
|
|
4603
|
-
const
|
|
4526
|
+
const stakingManagerUtxo = await resolveUtxo(
|
|
4527
|
+
stakingManager,
|
|
4528
|
+
lucid,
|
|
4529
|
+
"Expected a single staking manager UTXO"
|
|
4530
|
+
);
|
|
4531
|
+
const stakingManagerDatum = parseStakingManagerDatum(
|
|
4532
|
+
getInlineDatumOrThrow(stakingManagerUtxo)
|
|
4533
|
+
);
|
|
4604
4534
|
const stakingRefScriptUtxo = matchSingle(
|
|
4605
4535
|
await lucid.utxosByOutRef([
|
|
4606
4536
|
fromSystemParamsScriptRef(params.scriptReferences.stakingValidatorRef)
|
|
@@ -4616,39 +4546,39 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4616
4546
|
(_2) => new Error("Expected a single staking token policy Ref Script UTXO")
|
|
4617
4547
|
);
|
|
4618
4548
|
const newStakingManagerDatum = {
|
|
4619
|
-
totalStake:
|
|
4549
|
+
totalStake: stakingManagerDatum.totalStake + amount,
|
|
4620
4550
|
managerSnapshot: {
|
|
4621
|
-
snapshotAda:
|
|
4551
|
+
snapshotAda: stakingManagerDatum.managerSnapshot.snapshotAda
|
|
4622
4552
|
}
|
|
4623
4553
|
};
|
|
4624
4554
|
const stakingPositionDatum = {
|
|
4625
4555
|
owner: fromHex3(pkh.hash),
|
|
4626
4556
|
lockedAmount: /* @__PURE__ */ new Map([]),
|
|
4627
4557
|
positionSnapshot: {
|
|
4628
|
-
snapshotAda:
|
|
4558
|
+
snapshotAda: stakingManagerDatum.managerSnapshot.snapshotAda
|
|
4629
4559
|
}
|
|
4630
4560
|
};
|
|
4631
4561
|
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + fromText6(params.stakingParams.stakingToken[1].unTokenName);
|
|
4632
4562
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText6(params.stakingParams.indyToken[1].unTokenName);
|
|
4633
4563
|
return lucid.newTx().collectFrom(
|
|
4634
|
-
[
|
|
4564
|
+
[stakingManagerUtxo],
|
|
4635
4565
|
serialiseStakingRedeemer({
|
|
4636
4566
|
CreateStakingPosition: { creatorPkh: pkh.hash }
|
|
4637
4567
|
})
|
|
4638
4568
|
).readFrom([stakingRefScriptUtxo]).pay.ToContract(
|
|
4639
|
-
|
|
4569
|
+
stakingManagerUtxo.address,
|
|
4640
4570
|
{
|
|
4641
4571
|
kind: "inline",
|
|
4642
4572
|
value: serialiseStakingDatum(newStakingManagerDatum)
|
|
4643
4573
|
},
|
|
4644
|
-
|
|
4574
|
+
stakingManagerUtxo.assets
|
|
4645
4575
|
).readFrom([stakingTokenPolicyRefScriptUtxo]).mintAssets(
|
|
4646
4576
|
{
|
|
4647
4577
|
[stakingToken]: 1n
|
|
4648
4578
|
},
|
|
4649
4579
|
Data22.void()
|
|
4650
4580
|
).pay.ToContract(
|
|
4651
|
-
|
|
4581
|
+
stakingManagerUtxo.address,
|
|
4652
4582
|
{
|
|
4653
4583
|
kind: "inline",
|
|
4654
4584
|
value: serialiseStakingDatum(stakingPositionDatum)
|
|
@@ -4659,14 +4589,25 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4659
4589
|
}
|
|
4660
4590
|
).addSignerKey(pkh.hash);
|
|
4661
4591
|
}
|
|
4662
|
-
async function adjustStakingPosition(
|
|
4592
|
+
async function adjustStakingPosition(stakingPosition, amount, params, lucid, currentSlot, stakingManager) {
|
|
4663
4593
|
const network = lucid.config().network;
|
|
4664
4594
|
const currentTime = slotToUnixTime5(network, currentSlot) - 120 * ONE_SECOND;
|
|
4665
|
-
const
|
|
4666
|
-
|
|
4667
|
-
lucid
|
|
4595
|
+
const stakingPositionUtxo = await resolveUtxo(
|
|
4596
|
+
stakingPosition,
|
|
4597
|
+
lucid,
|
|
4598
|
+
"Expected a single staking position UTXO"
|
|
4599
|
+
);
|
|
4600
|
+
const stakingPositionDatum = parseStakingPositionOrThrow(
|
|
4601
|
+
getInlineDatumOrThrow(stakingPositionUtxo)
|
|
4602
|
+
);
|
|
4603
|
+
const stakingManagerUtxo = await resolveUtxo(
|
|
4604
|
+
stakingManager,
|
|
4605
|
+
lucid,
|
|
4606
|
+
"Expected a single staking manager UTXO"
|
|
4607
|
+
);
|
|
4608
|
+
const stakingManagerDatum = parseStakingManagerDatum(
|
|
4609
|
+
getInlineDatumOrThrow(stakingManagerUtxo)
|
|
4668
4610
|
);
|
|
4669
|
-
const stakingManagerOut = stakingManagerRef ? await findStakingManagerByOutRef(stakingManagerRef, lucid) : await findStakingManager(params, lucid);
|
|
4670
4611
|
const stakingRefScriptUtxo = matchSingle(
|
|
4671
4612
|
await lucid.utxosByOutRef([
|
|
4672
4613
|
fromSystemParamsScriptRef(params.scriptReferences.stakingValidatorRef)
|
|
@@ -4674,44 +4615,44 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4674
4615
|
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
4675
4616
|
);
|
|
4676
4617
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText6(params.stakingParams.indyToken[1].unTokenName);
|
|
4677
|
-
const existingIndyAmount =
|
|
4678
|
-
const currentSnapshotAda =
|
|
4679
|
-
const oldSnapshotAda =
|
|
4618
|
+
const existingIndyAmount = stakingPositionUtxo.assets[indyToken] ?? 0n;
|
|
4619
|
+
const currentSnapshotAda = stakingManagerDatum.managerSnapshot.snapshotAda;
|
|
4620
|
+
const oldSnapshotAda = stakingPositionDatum.positionSnapshot.snapshotAda;
|
|
4680
4621
|
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / rewardSnapshotPrecision;
|
|
4681
4622
|
const newLockedAmount = updateStakingLockedAmount(
|
|
4682
|
-
|
|
4623
|
+
stakingPositionDatum.lockedAmount,
|
|
4683
4624
|
BigInt(currentTime)
|
|
4684
4625
|
);
|
|
4685
4626
|
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo]).collectFrom(
|
|
4686
|
-
[
|
|
4627
|
+
[stakingPositionUtxo],
|
|
4687
4628
|
serialiseStakingRedeemer({
|
|
4688
4629
|
AdjustStakedAmount: { adjustAmount: amount }
|
|
4689
4630
|
})
|
|
4690
4631
|
).collectFrom(
|
|
4691
|
-
[
|
|
4632
|
+
[stakingManagerUtxo],
|
|
4692
4633
|
serialiseStakingRedeemer("UpdateTotalStake")
|
|
4693
4634
|
).pay.ToContract(
|
|
4694
|
-
|
|
4635
|
+
stakingManagerUtxo.address,
|
|
4695
4636
|
{
|
|
4696
4637
|
kind: "inline",
|
|
4697
4638
|
value: serialiseStakingDatum({
|
|
4698
|
-
...
|
|
4699
|
-
totalStake:
|
|
4639
|
+
...stakingManagerDatum,
|
|
4640
|
+
totalStake: stakingManagerDatum.totalStake + amount
|
|
4700
4641
|
})
|
|
4701
4642
|
},
|
|
4702
|
-
addAssets6(
|
|
4643
|
+
addAssets6(stakingManagerUtxo.assets, mkLovelacesOf(-adaReward))
|
|
4703
4644
|
).pay.ToContract(
|
|
4704
|
-
|
|
4645
|
+
stakingPositionUtxo.address,
|
|
4705
4646
|
{
|
|
4706
4647
|
kind: "inline",
|
|
4707
4648
|
value: serialiseStakingDatum({
|
|
4708
|
-
...
|
|
4649
|
+
...stakingPositionDatum,
|
|
4709
4650
|
lockedAmount: newLockedAmount,
|
|
4710
|
-
positionSnapshot:
|
|
4651
|
+
positionSnapshot: stakingManagerDatum.managerSnapshot
|
|
4711
4652
|
})
|
|
4712
4653
|
},
|
|
4713
4654
|
addAssets6(
|
|
4714
|
-
|
|
4655
|
+
stakingPositionUtxo.assets,
|
|
4715
4656
|
mkAssetsOf(
|
|
4716
4657
|
{
|
|
4717
4658
|
currencySymbol: params.stakingParams.indyToken[0].unCurrencySymbol,
|
|
@@ -4720,16 +4661,27 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4720
4661
|
amount
|
|
4721
4662
|
)
|
|
4722
4663
|
)
|
|
4723
|
-
).addSignerKey(toHex2(
|
|
4664
|
+
).addSignerKey(toHex2(stakingPositionDatum.owner));
|
|
4724
4665
|
}
|
|
4725
|
-
async function closeStakingPosition(
|
|
4666
|
+
async function closeStakingPosition(stakingPosition, params, lucid, currentSlot, stakingManager) {
|
|
4726
4667
|
const network = lucid.config().network;
|
|
4727
4668
|
const currentTime = slotToUnixTime5(network, currentSlot) - ONE_SECOND;
|
|
4728
|
-
const
|
|
4729
|
-
|
|
4730
|
-
lucid
|
|
4669
|
+
const stakingPositionUtxo = await resolveUtxo(
|
|
4670
|
+
stakingPosition,
|
|
4671
|
+
lucid,
|
|
4672
|
+
"Expected a single staking position UTXO"
|
|
4673
|
+
);
|
|
4674
|
+
const stakingPositionDatum = parseStakingPositionOrThrow(
|
|
4675
|
+
getInlineDatumOrThrow(stakingPositionUtxo)
|
|
4676
|
+
);
|
|
4677
|
+
const stakingManagerUtxo = await resolveUtxo(
|
|
4678
|
+
stakingManager,
|
|
4679
|
+
lucid,
|
|
4680
|
+
"Expected a single staking manager UTXO"
|
|
4681
|
+
);
|
|
4682
|
+
const stakingManagerDatum = parseStakingManagerDatum(
|
|
4683
|
+
getInlineDatumOrThrow(stakingManagerUtxo)
|
|
4731
4684
|
);
|
|
4732
|
-
const stakingManagerOut = stakingManagerRef ? await findStakingManagerByOutRef(stakingManagerRef, lucid) : await findStakingManager(params, lucid);
|
|
4733
4685
|
const stakingRefScriptUtxo = matchSingle(
|
|
4734
4686
|
await lucid.utxosByOutRef([
|
|
4735
4687
|
fromSystemParamsScriptRef(params.scriptReferences.stakingValidatorRef)
|
|
@@ -4746,33 +4698,37 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
4746
4698
|
);
|
|
4747
4699
|
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + fromText6(params.stakingParams.stakingToken[1].unTokenName);
|
|
4748
4700
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText6(params.stakingParams.indyToken[1].unTokenName);
|
|
4749
|
-
const existingIndyAmount =
|
|
4750
|
-
const currentSnapshotAda =
|
|
4751
|
-
const oldSnapshotAda =
|
|
4701
|
+
const existingIndyAmount = stakingPositionUtxo.assets[indyToken] ?? 0n;
|
|
4702
|
+
const currentSnapshotAda = stakingManagerDatum.managerSnapshot.snapshotAda;
|
|
4703
|
+
const oldSnapshotAda = stakingPositionDatum.positionSnapshot.snapshotAda;
|
|
4752
4704
|
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
|
|
4753
|
-
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([
|
|
4754
|
-
[
|
|
4705
|
+
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionUtxo], serialiseStakingRedeemer("Unstake")).collectFrom(
|
|
4706
|
+
[stakingManagerUtxo],
|
|
4755
4707
|
serialiseStakingRedeemer("UpdateTotalStake")
|
|
4756
4708
|
).pay.ToContract(
|
|
4757
|
-
|
|
4709
|
+
stakingManagerUtxo.address,
|
|
4758
4710
|
{
|
|
4759
4711
|
kind: "inline",
|
|
4760
4712
|
value: serialiseStakingDatum({
|
|
4761
|
-
...
|
|
4762
|
-
totalStake:
|
|
4713
|
+
...stakingManagerDatum,
|
|
4714
|
+
totalStake: stakingManagerDatum.totalStake - existingIndyAmount
|
|
4763
4715
|
})
|
|
4764
4716
|
},
|
|
4765
|
-
addAssets6(
|
|
4717
|
+
addAssets6(stakingManagerUtxo.assets, mkLovelacesOf(-adaReward))
|
|
4766
4718
|
).mintAssets(
|
|
4767
4719
|
{
|
|
4768
4720
|
[stakingToken]: -1n
|
|
4769
4721
|
},
|
|
4770
4722
|
Data22.void()
|
|
4771
|
-
).addSignerKey(toHex2(
|
|
4723
|
+
).addSignerKey(toHex2(stakingPositionDatum.owner));
|
|
4772
4724
|
}
|
|
4773
4725
|
var MIN_UTXO_AMOUNT = 2000000n;
|
|
4774
|
-
async function distributeAda(
|
|
4775
|
-
const
|
|
4726
|
+
async function distributeAda(stakingManager, collectorRefs, params, lucid) {
|
|
4727
|
+
const stakingManagerUtxo = await resolveUtxo(
|
|
4728
|
+
stakingManager,
|
|
4729
|
+
lucid,
|
|
4730
|
+
"Expected a single staking manager UTXO"
|
|
4731
|
+
);
|
|
4776
4732
|
const stakingManagerDatum = parseStakingManagerDatum(
|
|
4777
4733
|
getInlineDatumOrThrow(stakingManagerUtxo)
|
|
4778
4734
|
);
|
|
@@ -4942,16 +4898,16 @@ async function findInterestOracle(lucid, interestNft) {
|
|
|
4942
4898
|
}
|
|
4943
4899
|
|
|
4944
4900
|
// src/contracts/interest-oracle/transactions.ts
|
|
4945
|
-
async function startInterestOracle(initialUnitaryInterest, initialInterestRate, initialLastInterestUpdate, oracleParams, lucid, interestTokenName, withScriptRef = false,
|
|
4901
|
+
async function startInterestOracle(initialUnitaryInterest, initialInterestRate, initialLastInterestUpdate, oracleParams, lucid, interestTokenName, withScriptRef = false, refUtxo) {
|
|
4946
4902
|
const network = lucid.config().network;
|
|
4947
4903
|
const tokenName = interestTokenName ?? "INTEREST_ORACLE";
|
|
4948
|
-
if (!
|
|
4949
|
-
|
|
4904
|
+
if (!refUtxo) {
|
|
4905
|
+
refUtxo = (await lucid.wallet().getUtxos())[0];
|
|
4950
4906
|
}
|
|
4951
4907
|
const [tx, policyId] = await oneShotMintTx(lucid, {
|
|
4952
4908
|
referenceOutRef: {
|
|
4953
|
-
txHash:
|
|
4954
|
-
outputIdx: BigInt(
|
|
4909
|
+
txHash: refUtxo.txHash,
|
|
4910
|
+
outputIdx: BigInt(refUtxo.outputIndex)
|
|
4955
4911
|
},
|
|
4956
4912
|
mintAmounts: [
|
|
4957
4913
|
{
|
|
@@ -5532,21 +5488,18 @@ async function openLrp(assetTokenName, lovelacesAmt2, maxPrice, lucid, sysParams
|
|
|
5532
5488
|
{ lovelace: lovelacesAmt2 + MIN_LRP_COLLATERAL_AMT }
|
|
5533
5489
|
);
|
|
5534
5490
|
}
|
|
5535
|
-
async function cancelLrp(
|
|
5491
|
+
async function cancelLrp(lrp, sysParams, lucid) {
|
|
5536
5492
|
const lrpScriptRefUtxo = matchSingle(
|
|
5537
5493
|
await lucid.utxosByOutRef([
|
|
5538
5494
|
fromSystemParamsScriptRef(sysParams.scriptReferences.lrpValidatorRef)
|
|
5539
5495
|
]),
|
|
5540
5496
|
(_) => new Error("Expected a single LRP Ref Script UTXO")
|
|
5541
5497
|
);
|
|
5542
|
-
const lrpUtxo =
|
|
5543
|
-
await lucid.utxosByOutRef([lrpOutRef]),
|
|
5544
|
-
(_) => new Error("Expected a single LRP UTXO.")
|
|
5545
|
-
);
|
|
5498
|
+
const lrpUtxo = await resolveUtxo(lrp, lucid, "Expected a single LRP UTXO.");
|
|
5546
5499
|
const lrpDatum = parseLrpDatumOrThrow(getInlineDatumOrThrow(lrpUtxo));
|
|
5547
5500
|
return lucid.newTx().readFrom([lrpScriptRefUtxo]).collectFrom([lrpUtxo], serialiseLrpRedeemer("Cancel")).addSignerKey(lrpDatum.owner);
|
|
5548
5501
|
}
|
|
5549
|
-
async function redeemLrp(redemptionLrpsData,
|
|
5502
|
+
async function redeemLrp(redemptionLrpsData, priceOracle, iasset, lucid, sysParams) {
|
|
5550
5503
|
const network = lucid.config().network;
|
|
5551
5504
|
const lrpScriptRefUtxo = matchSingle(
|
|
5552
5505
|
await lucid.utxosByOutRef([
|
|
@@ -5554,13 +5507,15 @@ async function redeemLrp(redemptionLrpsData, priceOracleOutRef, iassetOutRef, lu
|
|
|
5554
5507
|
]),
|
|
5555
5508
|
(_) => new Error("Expected a single LRP Ref Script UTXO")
|
|
5556
5509
|
);
|
|
5557
|
-
const priceOracleUtxo =
|
|
5558
|
-
|
|
5559
|
-
|
|
5510
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
5511
|
+
priceOracle,
|
|
5512
|
+
lucid,
|
|
5513
|
+
"Expected a single price oracle UTXO"
|
|
5560
5514
|
);
|
|
5561
|
-
const iassetUtxo =
|
|
5562
|
-
|
|
5563
|
-
|
|
5515
|
+
const iassetUtxo = await resolveUtxo(
|
|
5516
|
+
iasset,
|
|
5517
|
+
lucid,
|
|
5518
|
+
"Expected a single IAsset UTXO"
|
|
5564
5519
|
);
|
|
5565
5520
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
5566
5521
|
getInlineDatumOrThrow(iassetUtxo)
|
|
@@ -5585,17 +5540,14 @@ async function redeemLrp(redemptionLrpsData, priceOracleOutRef, iassetOutRef, lu
|
|
|
5585
5540
|
)
|
|
5586
5541
|
).readFrom([lrpScriptRefUtxo]).readFrom([iassetUtxo, priceOracleUtxo]).compose(tx);
|
|
5587
5542
|
}
|
|
5588
|
-
async function adjustLrp(lucid,
|
|
5543
|
+
async function adjustLrp(lucid, lrp, lovelacesAdjustAmt, newMaxPrice, sysParams) {
|
|
5589
5544
|
const lrpScriptRefUtxo = matchSingle(
|
|
5590
5545
|
await lucid.utxosByOutRef([
|
|
5591
5546
|
fromSystemParamsScriptRef(sysParams.scriptReferences.lrpValidatorRef)
|
|
5592
5547
|
]),
|
|
5593
5548
|
(_) => new Error("Expected a single LRP Ref Script UTXO")
|
|
5594
5549
|
);
|
|
5595
|
-
const lrpUtxo =
|
|
5596
|
-
await lucid.utxosByOutRef([lrpOutRef]),
|
|
5597
|
-
(_) => new Error("Expected a single LRP UTXO.")
|
|
5598
|
-
);
|
|
5550
|
+
const lrpUtxo = await resolveUtxo(lrp, lucid, "Expected a single LRP UTXO.");
|
|
5599
5551
|
const lrpDatum = parseLrpDatumOrThrow(getInlineDatumOrThrow(lrpUtxo));
|
|
5600
5552
|
const rewardAssetClass = {
|
|
5601
5553
|
currencySymbol: sysParams.lrpParams.iassetPolicyId.unCurrencySymbol,
|
|
@@ -5632,8 +5584,8 @@ async function adjustLrp(lucid, lrpOutRef, lovelacesAdjustAmt, newMaxPrice, sysP
|
|
|
5632
5584
|
)
|
|
5633
5585
|
).addSignerKey(lrpDatum.owner);
|
|
5634
5586
|
}
|
|
5635
|
-
async function claimLrp(lucid,
|
|
5636
|
-
return adjustLrp(lucid,
|
|
5587
|
+
async function claimLrp(lucid, lrp, sysParams) {
|
|
5588
|
+
return adjustLrp(lucid, lrp, 0n, void 0, sysParams);
|
|
5637
5589
|
}
|
|
5638
5590
|
|
|
5639
5591
|
// src/contracts/lrp/scripts.ts
|
|
@@ -5866,7 +5818,7 @@ function calculateLeverageFromCollateralRatio(iasset, collateralRatioPercentage,
|
|
|
5866
5818
|
}
|
|
5867
5819
|
|
|
5868
5820
|
// src/contracts/leverage/transactions.ts
|
|
5869
|
-
async function leverageCdpWithLrp(leverage, baseCollateral,
|
|
5821
|
+
async function leverageCdpWithLrp(leverage, baseCollateral, priceOracle, iasset, cdpCreator, interestOracle, collector, sysParams, lucid, allLrps, currentSlot) {
|
|
5870
5822
|
const network = lucid.config().network;
|
|
5871
5823
|
const currentTime = BigInt(slotToUnixTime7(network, currentSlot));
|
|
5872
5824
|
const [pkh, skh] = await addrDetails(lucid);
|
|
@@ -5900,27 +5852,31 @@ async function leverageCdpWithLrp(leverage, baseCollateral, priceOracleOutRef, i
|
|
|
5900
5852
|
]),
|
|
5901
5853
|
(_) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
5902
5854
|
);
|
|
5903
|
-
const cdpCreatorUtxo =
|
|
5904
|
-
|
|
5905
|
-
|
|
5855
|
+
const cdpCreatorUtxo = await resolveUtxo(
|
|
5856
|
+
cdpCreator,
|
|
5857
|
+
lucid,
|
|
5858
|
+
"Expected a single CDP creator UTXO"
|
|
5906
5859
|
);
|
|
5907
|
-
const interestOracleUtxo =
|
|
5908
|
-
|
|
5909
|
-
|
|
5860
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
5861
|
+
interestOracle,
|
|
5862
|
+
lucid,
|
|
5863
|
+
"Expected a single interest oracle UTXO"
|
|
5910
5864
|
);
|
|
5911
5865
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
5912
5866
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
5913
5867
|
);
|
|
5914
|
-
const priceOracleUtxo =
|
|
5915
|
-
|
|
5916
|
-
|
|
5868
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
5869
|
+
priceOracle,
|
|
5870
|
+
lucid,
|
|
5871
|
+
"Expected a single price oracle UTXO"
|
|
5917
5872
|
);
|
|
5918
5873
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
5919
5874
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
5920
5875
|
);
|
|
5921
|
-
const iassetUtxo =
|
|
5922
|
-
|
|
5923
|
-
|
|
5876
|
+
const iassetUtxo = await resolveUtxo(
|
|
5877
|
+
iasset,
|
|
5878
|
+
lucid,
|
|
5879
|
+
"Expected a single IAsset UTXO"
|
|
5924
5880
|
);
|
|
5925
5881
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
5926
5882
|
getInlineDatumOrThrow(iassetUtxo)
|
|
@@ -6041,7 +5997,7 @@ async function leverageCdpWithLrp(leverage, baseCollateral, priceOracleOutRef, i
|
|
|
6041
5997
|
2n
|
|
6042
5998
|
);
|
|
6043
5999
|
if (debtMintingFee > 0) {
|
|
6044
|
-
await collectorFeeTx(debtMintingFee, lucid, sysParams, tx,
|
|
6000
|
+
await collectorFeeTx(debtMintingFee, lucid, sysParams, tx, collector);
|
|
6045
6001
|
}
|
|
6046
6002
|
return tx;
|
|
6047
6003
|
}
|
|
@@ -6224,6 +6180,7 @@ export {
|
|
|
6224
6180
|
randomLrpsSubsetSatisfyingTargetLovelaces,
|
|
6225
6181
|
redeemCdp,
|
|
6226
6182
|
redeemLrp,
|
|
6183
|
+
resolveUtxo,
|
|
6227
6184
|
rewardSnapshotPrecision,
|
|
6228
6185
|
runCreateScriptRefTx,
|
|
6229
6186
|
runOneShotMintTx,
|