@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.js
CHANGED
|
@@ -208,6 +208,7 @@ __export(index_exports, {
|
|
|
208
208
|
randomLrpsSubsetSatisfyingTargetLovelaces: () => randomLrpsSubsetSatisfyingTargetLovelaces,
|
|
209
209
|
redeemCdp: () => redeemCdp,
|
|
210
210
|
redeemLrp: () => redeemLrp,
|
|
211
|
+
resolveUtxo: () => resolveUtxo,
|
|
211
212
|
rewardSnapshotPrecision: () => rewardSnapshotPrecision,
|
|
212
213
|
runCreateScriptRefTx: () => runCreateScriptRefTx,
|
|
213
214
|
runOneShotMintTx: () => runOneShotMintTx,
|
|
@@ -275,6 +276,33 @@ function fromSysParamsScriptCredential(cred) {
|
|
|
275
276
|
|
|
276
277
|
// src/utils/lucid-utils.ts
|
|
277
278
|
var import_lucid2 = require("@lucid-evolution/lucid");
|
|
279
|
+
|
|
280
|
+
// src/utils/utils.ts
|
|
281
|
+
var fs = __toESM(require("fs"));
|
|
282
|
+
var import_ts_pattern = require("ts-pattern");
|
|
283
|
+
function matchSingle(xs, mkErr) {
|
|
284
|
+
return (0, import_ts_pattern.match)(xs).with([import_ts_pattern.P.select()], (res) => res).otherwise(() => {
|
|
285
|
+
throw mkErr(xs);
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
function loadSystemParamsFromFile(file) {
|
|
289
|
+
return JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
290
|
+
}
|
|
291
|
+
function loadSystemParamsFromUrl(url) {
|
|
292
|
+
return fetch(url).then((res) => res.json()).then((data) => data);
|
|
293
|
+
}
|
|
294
|
+
var getRandomElement = (arr) => arr.length ? arr[Math.floor(Math.random() * arr.length)] : void 0;
|
|
295
|
+
|
|
296
|
+
// src/utils/lucid-utils.ts
|
|
297
|
+
async function resolveUtxo(input, lucid, errorMsg = "Expected a single UTXO") {
|
|
298
|
+
if ("address" in input) {
|
|
299
|
+
return input;
|
|
300
|
+
}
|
|
301
|
+
return matchSingle(
|
|
302
|
+
await lucid.utxosByOutRef([input]),
|
|
303
|
+
(_) => new Error(errorMsg)
|
|
304
|
+
);
|
|
305
|
+
}
|
|
278
306
|
function getInlineDatumOrThrow(utxo) {
|
|
279
307
|
if (utxo.datum != null) {
|
|
280
308
|
return utxo.datum;
|
|
@@ -313,22 +341,6 @@ function balance(utxos) {
|
|
|
313
341
|
return utxos.reduce((acc, utxo) => (0, import_lucid2.addAssets)(acc, utxo.assets), {});
|
|
314
342
|
}
|
|
315
343
|
|
|
316
|
-
// src/utils/utils.ts
|
|
317
|
-
var fs = __toESM(require("fs"));
|
|
318
|
-
var import_ts_pattern = require("ts-pattern");
|
|
319
|
-
function matchSingle(xs, mkErr) {
|
|
320
|
-
return (0, import_ts_pattern.match)(xs).with([import_ts_pattern.P.select()], (res) => res).otherwise(() => {
|
|
321
|
-
throw mkErr(xs);
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
function loadSystemParamsFromFile(file) {
|
|
325
|
-
return JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
326
|
-
}
|
|
327
|
-
function loadSystemParamsFromUrl(url) {
|
|
328
|
-
return fetch(url).then((res) => res.json()).then((data) => data);
|
|
329
|
-
}
|
|
330
|
-
var getRandomElement = (arr) => arr.length ? arr[Math.floor(Math.random() * arr.length)] : void 0;
|
|
331
|
-
|
|
332
344
|
// src/contracts/cdp/types.ts
|
|
333
345
|
var import_lucid6 = require("@lucid-evolution/lucid");
|
|
334
346
|
|
|
@@ -1440,10 +1452,11 @@ function serialiseCollectorRedeemer(redeemer) {
|
|
|
1440
1452
|
}
|
|
1441
1453
|
|
|
1442
1454
|
// src/contracts/collector/transactions.ts
|
|
1443
|
-
async function collectorFeeTx(fee, lucid, params, tx,
|
|
1444
|
-
const collectorUtxo =
|
|
1445
|
-
|
|
1446
|
-
|
|
1455
|
+
async function collectorFeeTx(fee, lucid, params, tx, collector) {
|
|
1456
|
+
const collectorUtxo = await resolveUtxo(
|
|
1457
|
+
collector,
|
|
1458
|
+
lucid,
|
|
1459
|
+
"Expected a single collector UTXO"
|
|
1447
1460
|
);
|
|
1448
1461
|
const collectorRefScriptUtxo = matchSingle(
|
|
1449
1462
|
await lucid.utxosByOutRef([
|
|
@@ -1493,11 +1506,12 @@ function serialiseTreasuryRedeemer(redeemer) {
|
|
|
1493
1506
|
}
|
|
1494
1507
|
|
|
1495
1508
|
// src/contracts/treasury/transactions.ts
|
|
1496
|
-
async function treasuryFeeTx(fee, lucid, sysParams, tx,
|
|
1509
|
+
async function treasuryFeeTx(fee, lucid, sysParams, tx, treasury) {
|
|
1497
1510
|
if (fee <= 0n) return;
|
|
1498
|
-
const treasuryUtxo =
|
|
1499
|
-
|
|
1500
|
-
|
|
1511
|
+
const treasuryUtxo = await resolveUtxo(
|
|
1512
|
+
treasury,
|
|
1513
|
+
lucid,
|
|
1514
|
+
"Expected a single treasury UTXO"
|
|
1501
1515
|
);
|
|
1502
1516
|
const treasuryRefScriptUtxo = matchSingle(
|
|
1503
1517
|
await lucid.utxosByOutRef([
|
|
@@ -1522,7 +1536,7 @@ async function treasuryFeeTx(fee, lucid, sysParams, tx, treasuryOref) {
|
|
|
1522
1536
|
}
|
|
1523
1537
|
|
|
1524
1538
|
// src/contracts/cdp/transactions.ts
|
|
1525
|
-
async function openCdp(collateralAmount, mintedAmount, sysParams,
|
|
1539
|
+
async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreator, iasset, priceOracle, interestOracle, collector, lucid, currentSlot) {
|
|
1526
1540
|
const network = lucid.config().network;
|
|
1527
1541
|
const currentTime = BigInt((0, import_lucid18.slotToUnixTime)(network, currentSlot));
|
|
1528
1542
|
const [pkh, skh] = await addrDetails(lucid);
|
|
@@ -1550,30 +1564,34 @@ async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref
|
|
|
1550
1564
|
]),
|
|
1551
1565
|
(_) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
1552
1566
|
);
|
|
1553
|
-
const iassetUtxo =
|
|
1554
|
-
|
|
1555
|
-
|
|
1567
|
+
const iassetUtxo = await resolveUtxo(
|
|
1568
|
+
iasset,
|
|
1569
|
+
lucid,
|
|
1570
|
+
"Expected a single iasset UTXO"
|
|
1556
1571
|
);
|
|
1557
1572
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
1558
1573
|
getInlineDatumOrThrow(iassetUtxo)
|
|
1559
1574
|
);
|
|
1560
|
-
const priceOracleUtxo =
|
|
1561
|
-
|
|
1562
|
-
|
|
1575
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
1576
|
+
priceOracle,
|
|
1577
|
+
lucid,
|
|
1578
|
+
"Expected a single price oracle UTXO"
|
|
1563
1579
|
);
|
|
1564
1580
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
1565
1581
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
1566
1582
|
);
|
|
1567
|
-
const interestOracleUtxo =
|
|
1568
|
-
|
|
1569
|
-
|
|
1583
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
1584
|
+
interestOracle,
|
|
1585
|
+
lucid,
|
|
1586
|
+
"Expected a single interest oracle UTXO"
|
|
1570
1587
|
);
|
|
1571
1588
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
1572
1589
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
1573
1590
|
);
|
|
1574
|
-
const cdpCreatorUtxo =
|
|
1575
|
-
|
|
1576
|
-
|
|
1591
|
+
const cdpCreatorUtxo = await resolveUtxo(
|
|
1592
|
+
cdpCreator,
|
|
1593
|
+
lucid,
|
|
1594
|
+
"Expected a single CDP creator UTXO"
|
|
1577
1595
|
);
|
|
1578
1596
|
(0, import_ts_pattern7.match)(iassetDatum.price).with({ Delisted: import_ts_pattern7.P.any }, () => {
|
|
1579
1597
|
throw new Error("Can't open CDP of delisted asset");
|
|
@@ -1640,11 +1658,11 @@ async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref
|
|
|
1640
1658
|
mintedAmount * priceOracleDatum.price.getOnChainInt / 1000000n
|
|
1641
1659
|
);
|
|
1642
1660
|
if (debtMintingFee > 0) {
|
|
1643
|
-
await collectorFeeTx(debtMintingFee, lucid, sysParams, tx,
|
|
1661
|
+
await collectorFeeTx(debtMintingFee, lucid, sysParams, tx, collector);
|
|
1644
1662
|
}
|
|
1645
1663
|
return tx;
|
|
1646
1664
|
}
|
|
1647
|
-
async function adjustCdp(collateralAmount, mintAmount,
|
|
1665
|
+
async function adjustCdp(collateralAmount, mintAmount, cdp, iasset, priceOracle, interestOracle, collector, gov, treasury, sysParams, lucid, currentSlot) {
|
|
1648
1666
|
const network = lucid.config().network;
|
|
1649
1667
|
const currentTime = BigInt((0, import_lucid18.slotToUnixTime)(network, currentSlot));
|
|
1650
1668
|
const cdpRefScriptUtxo = matchSingle(
|
|
@@ -1653,33 +1671,30 @@ async function adjustCdp(collateralAmount, mintAmount, cdpOref, iassetOref, pric
|
|
|
1653
1671
|
]),
|
|
1654
1672
|
(_) => new Error("Expected a single cdp Ref Script UTXO")
|
|
1655
1673
|
);
|
|
1656
|
-
const cdpUtxo =
|
|
1657
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
1658
|
-
(_) => new Error("Expected a single cdp UTXO")
|
|
1659
|
-
);
|
|
1674
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, "Expected a single cdp UTXO");
|
|
1660
1675
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
1661
|
-
const iassetUtxo =
|
|
1662
|
-
|
|
1663
|
-
|
|
1676
|
+
const iassetUtxo = await resolveUtxo(
|
|
1677
|
+
iasset,
|
|
1678
|
+
lucid,
|
|
1679
|
+
"Expected a single iasset UTXO"
|
|
1664
1680
|
);
|
|
1665
1681
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
1666
1682
|
getInlineDatumOrThrow(iassetUtxo)
|
|
1667
1683
|
);
|
|
1668
|
-
const govUtxo =
|
|
1669
|
-
await lucid.utxosByOutRef([govOref]),
|
|
1670
|
-
(_) => new Error("Expected a single gov UTXO")
|
|
1671
|
-
);
|
|
1684
|
+
const govUtxo = await resolveUtxo(gov, lucid, "Expected a single gov UTXO");
|
|
1672
1685
|
const govDatum = parseGovDatumOrThrow(getInlineDatumOrThrow(govUtxo));
|
|
1673
|
-
const priceOracleUtxo =
|
|
1674
|
-
|
|
1675
|
-
|
|
1686
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
1687
|
+
priceOracle,
|
|
1688
|
+
lucid,
|
|
1689
|
+
"Expected a single price oracle UTXO"
|
|
1676
1690
|
);
|
|
1677
1691
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
1678
1692
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
1679
1693
|
);
|
|
1680
|
-
const interestOracleUtxo =
|
|
1681
|
-
|
|
1682
|
-
|
|
1694
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
1695
|
+
interestOracle,
|
|
1696
|
+
lucid,
|
|
1697
|
+
"Expected a single interest oracle UTXO"
|
|
1683
1698
|
);
|
|
1684
1699
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
1685
1700
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
@@ -1767,13 +1782,7 @@ async function adjustCdp(collateralAmount, mintAmount, cdpOref, iassetOref, pric
|
|
|
1767
1782
|
);
|
|
1768
1783
|
const interestTreasuryAdaAmt = interestAdaAmt - interestCollectorAdaAmt;
|
|
1769
1784
|
if (interestTreasuryAdaAmt > 0) {
|
|
1770
|
-
await treasuryFeeTx(
|
|
1771
|
-
interestTreasuryAdaAmt,
|
|
1772
|
-
lucid,
|
|
1773
|
-
sysParams,
|
|
1774
|
-
tx,
|
|
1775
|
-
treasuryOref
|
|
1776
|
-
);
|
|
1785
|
+
await treasuryFeeTx(interestTreasuryAdaAmt, lucid, sysParams, tx, treasury);
|
|
1777
1786
|
}
|
|
1778
1787
|
let collectorFee = interestCollectorAdaAmt;
|
|
1779
1788
|
if (mintAmount > 0n) {
|
|
@@ -1789,75 +1798,75 @@ async function adjustCdp(collateralAmount, mintAmount, cdpOref, iassetOref, pric
|
|
|
1789
1798
|
);
|
|
1790
1799
|
}
|
|
1791
1800
|
if (collectorFee > 0n) {
|
|
1792
|
-
await collectorFeeTx(collectorFee, lucid, sysParams, tx,
|
|
1801
|
+
await collectorFeeTx(collectorFee, lucid, sysParams, tx, collector);
|
|
1793
1802
|
}
|
|
1794
1803
|
return tx;
|
|
1795
1804
|
}
|
|
1796
|
-
async function depositCdp(amount,
|
|
1805
|
+
async function depositCdp(amount, cdp, iasset, priceOracle, interestOracle, collector, gov, treasury, params, lucid, currentSlot) {
|
|
1797
1806
|
return adjustCdp(
|
|
1798
1807
|
amount,
|
|
1799
1808
|
0n,
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1809
|
+
cdp,
|
|
1810
|
+
iasset,
|
|
1811
|
+
priceOracle,
|
|
1812
|
+
interestOracle,
|
|
1813
|
+
collector,
|
|
1814
|
+
gov,
|
|
1815
|
+
treasury,
|
|
1807
1816
|
params,
|
|
1808
1817
|
lucid,
|
|
1809
1818
|
currentSlot
|
|
1810
1819
|
);
|
|
1811
1820
|
}
|
|
1812
|
-
async function withdrawCdp(amount,
|
|
1821
|
+
async function withdrawCdp(amount, cdp, iasset, priceOracle, interestOracle, collector, gov, treasury, params, lucid, currentSlot) {
|
|
1813
1822
|
return adjustCdp(
|
|
1814
1823
|
-amount,
|
|
1815
1824
|
0n,
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1825
|
+
cdp,
|
|
1826
|
+
iasset,
|
|
1827
|
+
priceOracle,
|
|
1828
|
+
interestOracle,
|
|
1829
|
+
collector,
|
|
1830
|
+
gov,
|
|
1831
|
+
treasury,
|
|
1823
1832
|
params,
|
|
1824
1833
|
lucid,
|
|
1825
1834
|
currentSlot
|
|
1826
1835
|
);
|
|
1827
1836
|
}
|
|
1828
|
-
async function mintCdp(amount,
|
|
1837
|
+
async function mintCdp(amount, cdp, iasset, priceOracle, interestOracle, collector, gov, treasury, params, lucid, currentSlot) {
|
|
1829
1838
|
return adjustCdp(
|
|
1830
1839
|
0n,
|
|
1831
1840
|
amount,
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1841
|
+
cdp,
|
|
1842
|
+
iasset,
|
|
1843
|
+
priceOracle,
|
|
1844
|
+
interestOracle,
|
|
1845
|
+
collector,
|
|
1846
|
+
gov,
|
|
1847
|
+
treasury,
|
|
1839
1848
|
params,
|
|
1840
1849
|
lucid,
|
|
1841
1850
|
currentSlot
|
|
1842
1851
|
);
|
|
1843
1852
|
}
|
|
1844
|
-
async function burnCdp(amount,
|
|
1853
|
+
async function burnCdp(amount, cdp, iasset, priceOracle, interestOracle, collector, gov, treasury, params, lucid, currentSlot) {
|
|
1845
1854
|
return adjustCdp(
|
|
1846
1855
|
0n,
|
|
1847
1856
|
-amount,
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1857
|
+
cdp,
|
|
1858
|
+
iasset,
|
|
1859
|
+
priceOracle,
|
|
1860
|
+
interestOracle,
|
|
1861
|
+
collector,
|
|
1862
|
+
gov,
|
|
1863
|
+
treasury,
|
|
1855
1864
|
params,
|
|
1856
1865
|
lucid,
|
|
1857
1866
|
currentSlot
|
|
1858
1867
|
);
|
|
1859
1868
|
}
|
|
1860
|
-
async function closeCdp(
|
|
1869
|
+
async function closeCdp(cdp, iasset, priceOracle, interestOracle, collector, gov, treasury, sysParams, lucid, currentSlot) {
|
|
1861
1870
|
const network = lucid.config().network;
|
|
1862
1871
|
const currentTime = BigInt((0, import_lucid18.slotToUnixTime)(network, currentSlot));
|
|
1863
1872
|
const cdpRefScriptUtxo = matchSingle(
|
|
@@ -1882,33 +1891,30 @@ async function closeCdp(cdpOref, iassetOref, priceOracleOref, interestOracleOref
|
|
|
1882
1891
|
]),
|
|
1883
1892
|
(_) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
1884
1893
|
);
|
|
1885
|
-
const cdpUtxo =
|
|
1886
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
1887
|
-
(_) => new Error("Expected a single cdp UTXO")
|
|
1888
|
-
);
|
|
1894
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, "Expected a single cdp UTXO");
|
|
1889
1895
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
1890
|
-
const iassetUtxo =
|
|
1891
|
-
|
|
1892
|
-
|
|
1896
|
+
const iassetUtxo = await resolveUtxo(
|
|
1897
|
+
iasset,
|
|
1898
|
+
lucid,
|
|
1899
|
+
"Expected a single iasset UTXO"
|
|
1893
1900
|
);
|
|
1894
1901
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
1895
1902
|
getInlineDatumOrThrow(iassetUtxo)
|
|
1896
1903
|
);
|
|
1897
|
-
const govUtxo =
|
|
1898
|
-
await lucid.utxosByOutRef([govOref]),
|
|
1899
|
-
(_) => new Error("Expected a single gov UTXO")
|
|
1900
|
-
);
|
|
1904
|
+
const govUtxo = await resolveUtxo(gov, lucid, "Expected a single gov UTXO");
|
|
1901
1905
|
const govDatum = parseGovDatumOrThrow(getInlineDatumOrThrow(govUtxo));
|
|
1902
|
-
const priceOracleUtxo =
|
|
1903
|
-
|
|
1904
|
-
|
|
1906
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
1907
|
+
priceOracle,
|
|
1908
|
+
lucid,
|
|
1909
|
+
"Expected a single price oracle UTXO"
|
|
1905
1910
|
);
|
|
1906
1911
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
1907
1912
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
1908
1913
|
);
|
|
1909
|
-
const interestOracleUtxo =
|
|
1910
|
-
|
|
1911
|
-
|
|
1914
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
1915
|
+
interestOracle,
|
|
1916
|
+
lucid,
|
|
1917
|
+
"Expected a single interest oracle UTXO"
|
|
1912
1918
|
);
|
|
1913
1919
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
1914
1920
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
@@ -1961,24 +1967,18 @@ async function closeCdp(cdpOref, iassetOref, priceOracleOref, interestOracleOref
|
|
|
1961
1967
|
);
|
|
1962
1968
|
const interestTreasuryAdaAmt = interestAdaAmt - interestCollectorAdaAmt;
|
|
1963
1969
|
if (interestTreasuryAdaAmt > 0) {
|
|
1964
|
-
await treasuryFeeTx(
|
|
1965
|
-
interestTreasuryAdaAmt,
|
|
1966
|
-
lucid,
|
|
1967
|
-
sysParams,
|
|
1968
|
-
tx,
|
|
1969
|
-
treasuryOref
|
|
1970
|
-
);
|
|
1970
|
+
await treasuryFeeTx(interestTreasuryAdaAmt, lucid, sysParams, tx, treasury);
|
|
1971
1971
|
}
|
|
1972
1972
|
const collectorFee = interestCollectorAdaAmt + calculateFeeFromPercentage(
|
|
1973
1973
|
govDatum.protocolParams.collateralFeePercentage,
|
|
1974
1974
|
lovelacesAmt(cdpUtxo.assets) - interestAdaAmt
|
|
1975
1975
|
);
|
|
1976
1976
|
if (collectorFee > 0n) {
|
|
1977
|
-
await collectorFeeTx(collectorFee, lucid, sysParams, tx,
|
|
1977
|
+
await collectorFeeTx(collectorFee, lucid, sysParams, tx, collector);
|
|
1978
1978
|
}
|
|
1979
1979
|
return tx;
|
|
1980
1980
|
}
|
|
1981
|
-
async function redeemCdp(attemptedRedemptionIAssetAmt,
|
|
1981
|
+
async function redeemCdp(attemptedRedemptionIAssetAmt, cdp, iasset, priceOracle, interestOracle, collector, treasury, sysParams, lucid, currentSlot) {
|
|
1982
1982
|
const network = lucid.config().network;
|
|
1983
1983
|
const currentTime = BigInt((0, import_lucid18.slotToUnixTime)(network, currentSlot));
|
|
1984
1984
|
const cdpRefScriptUtxo = matchSingle(
|
|
@@ -1995,28 +1995,28 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, pric
|
|
|
1995
1995
|
]),
|
|
1996
1996
|
(_) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
1997
1997
|
);
|
|
1998
|
-
const cdpUtxo =
|
|
1999
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
2000
|
-
(_) => new Error("Expected a single cdp UTXO")
|
|
2001
|
-
);
|
|
1998
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, "Expected a single cdp UTXO");
|
|
2002
1999
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
2003
|
-
const iassetUtxo =
|
|
2004
|
-
|
|
2005
|
-
|
|
2000
|
+
const iassetUtxo = await resolveUtxo(
|
|
2001
|
+
iasset,
|
|
2002
|
+
lucid,
|
|
2003
|
+
"Expected a single iasset UTXO"
|
|
2006
2004
|
);
|
|
2007
2005
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
2008
2006
|
getInlineDatumOrThrow(iassetUtxo)
|
|
2009
2007
|
);
|
|
2010
|
-
const priceOracleUtxo =
|
|
2011
|
-
|
|
2012
|
-
|
|
2008
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
2009
|
+
priceOracle,
|
|
2010
|
+
lucid,
|
|
2011
|
+
"Expected a single price oracle UTXO"
|
|
2013
2012
|
);
|
|
2014
2013
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
2015
2014
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
2016
2015
|
);
|
|
2017
|
-
const interestOracleUtxo =
|
|
2018
|
-
|
|
2019
|
-
|
|
2016
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
2017
|
+
interestOracle,
|
|
2018
|
+
lucid,
|
|
2019
|
+
"Expected a single interest oracle UTXO"
|
|
2020
2020
|
);
|
|
2021
2021
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
2022
2022
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
@@ -2120,18 +2120,12 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, pric
|
|
|
2120
2120
|
lucid,
|
|
2121
2121
|
sysParams,
|
|
2122
2122
|
tx,
|
|
2123
|
-
|
|
2124
|
-
);
|
|
2125
|
-
await treasuryFeeTx(
|
|
2126
|
-
interestTreasuryAdaAmt,
|
|
2127
|
-
lucid,
|
|
2128
|
-
sysParams,
|
|
2129
|
-
tx,
|
|
2130
|
-
treasuryOref
|
|
2123
|
+
collector
|
|
2131
2124
|
);
|
|
2125
|
+
await treasuryFeeTx(interestTreasuryAdaAmt, lucid, sysParams, tx, treasury);
|
|
2132
2126
|
return tx;
|
|
2133
2127
|
}
|
|
2134
|
-
async function freezeCdp(
|
|
2128
|
+
async function freezeCdp(cdp, iasset, priceOracle, interestOracle, sysParams, lucid, currentSlot) {
|
|
2135
2129
|
const network = lucid.config().network;
|
|
2136
2130
|
const currentTime = BigInt((0, import_lucid18.slotToUnixTime)(network, currentSlot));
|
|
2137
2131
|
const cdpRefScriptUtxo = matchSingle(
|
|
@@ -2140,28 +2134,28 @@ async function freezeCdp(cdpOref, iassetOref, priceOracleOref, interestOracleOre
|
|
|
2140
2134
|
]),
|
|
2141
2135
|
(_) => new Error("Expected a single cdp Ref Script UTXO")
|
|
2142
2136
|
);
|
|
2143
|
-
const cdpUtxo =
|
|
2144
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
2145
|
-
(_) => new Error("Expected a single cdp UTXO")
|
|
2146
|
-
);
|
|
2137
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, "Expected a single cdp UTXO");
|
|
2147
2138
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
2148
|
-
const iassetUtxo =
|
|
2149
|
-
|
|
2150
|
-
|
|
2139
|
+
const iassetUtxo = await resolveUtxo(
|
|
2140
|
+
iasset,
|
|
2141
|
+
lucid,
|
|
2142
|
+
"Expected a single iasset UTXO"
|
|
2151
2143
|
);
|
|
2152
2144
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
2153
2145
|
getInlineDatumOrThrow(iassetUtxo)
|
|
2154
2146
|
);
|
|
2155
|
-
const priceOracleUtxo =
|
|
2156
|
-
|
|
2157
|
-
|
|
2147
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
2148
|
+
priceOracle,
|
|
2149
|
+
lucid,
|
|
2150
|
+
"Expected a single price oracle UTXO"
|
|
2158
2151
|
);
|
|
2159
2152
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
2160
2153
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
2161
2154
|
);
|
|
2162
|
-
const interestOracleUtxo =
|
|
2163
|
-
|
|
2164
|
-
|
|
2155
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
2156
|
+
interestOracle,
|
|
2157
|
+
lucid,
|
|
2158
|
+
"Expected a single interest oracle UTXO"
|
|
2165
2159
|
);
|
|
2166
2160
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
2167
2161
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
@@ -2236,7 +2230,7 @@ async function freezeCdp(cdpOref, iassetOref, priceOracleOref, interestOracleOre
|
|
|
2236
2230
|
cdpUtxo.assets
|
|
2237
2231
|
);
|
|
2238
2232
|
}
|
|
2239
|
-
async function liquidateCdp(
|
|
2233
|
+
async function liquidateCdp(cdp, stabilityPool, collector, treasury, sysParams, lucid) {
|
|
2240
2234
|
const cdpRefScriptUtxo = matchSingle(
|
|
2241
2235
|
await lucid.utxosByOutRef([
|
|
2242
2236
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
@@ -2267,14 +2261,12 @@ async function liquidateCdp(cdpOref, stabilityPoolOref, collectorOref, treasuryO
|
|
|
2267
2261
|
]),
|
|
2268
2262
|
(_) => new Error("Expected a single cdp auth token policy Ref Script UTXO")
|
|
2269
2263
|
);
|
|
2270
|
-
const cdpUtxo =
|
|
2271
|
-
await lucid.utxosByOutRef([cdpOref]),
|
|
2272
|
-
(_) => new Error("Expected a single cdp UTXO")
|
|
2273
|
-
);
|
|
2264
|
+
const cdpUtxo = await resolveUtxo(cdp, lucid, "Expected a single cdp UTXO");
|
|
2274
2265
|
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(cdpUtxo));
|
|
2275
|
-
const spUtxo =
|
|
2276
|
-
|
|
2277
|
-
|
|
2266
|
+
const spUtxo = await resolveUtxo(
|
|
2267
|
+
stabilityPool,
|
|
2268
|
+
lucid,
|
|
2269
|
+
"Expected a single stability pool UTXO"
|
|
2278
2270
|
);
|
|
2279
2271
|
const spDatum = parseStabilityPoolDatum(getInlineDatumOrThrow(spUtxo));
|
|
2280
2272
|
const [lovelacesForTreasury, lovelacesForCollector] = (0, import_ts_pattern7.match)(cdpDatum.cdpFees).returnType().with({ FrozenCDPAccumulatedFees: import_ts_pattern7.P.select() }, (fees) => [
|
|
@@ -2344,14 +2336,8 @@ async function liquidateCdp(cdpOref, stabilityPoolOref, collectorOref, treasuryO
|
|
|
2344
2336
|
import_lucid18.Data.void()
|
|
2345
2337
|
);
|
|
2346
2338
|
}
|
|
2347
|
-
await collectorFeeTx(
|
|
2348
|
-
|
|
2349
|
-
lucid,
|
|
2350
|
-
sysParams,
|
|
2351
|
-
tx,
|
|
2352
|
-
collectorOref
|
|
2353
|
-
);
|
|
2354
|
-
await treasuryFeeTx(lovelacesForTreasury, lucid, sysParams, tx, treasuryOref);
|
|
2339
|
+
await collectorFeeTx(lovelacesForCollector, lucid, sysParams, tx, collector);
|
|
2340
|
+
await treasuryFeeTx(lovelacesForTreasury, lucid, sysParams, tx, treasury);
|
|
2355
2341
|
return tx;
|
|
2356
2342
|
}
|
|
2357
2343
|
async function mergeCdps(cdpsToMergeUtxos, sysParams, lucid) {
|
|
@@ -2858,20 +2844,17 @@ function updateStakingLockedAmount(stakingPosLockedAmt, currentTime) {
|
|
|
2858
2844
|
stakingPosLockedAmt.entries().filter(([_, { votingEnd }]) => votingEnd > currentTime)
|
|
2859
2845
|
);
|
|
2860
2846
|
}
|
|
2861
|
-
function findStakingManagerByOutRef(
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
);
|
|
2873
|
-
return result;
|
|
2874
|
-
});
|
|
2847
|
+
async function findStakingManagerByOutRef(stakingManager, lucid) {
|
|
2848
|
+
const utxo = await resolveUtxo(
|
|
2849
|
+
stakingManager,
|
|
2850
|
+
lucid,
|
|
2851
|
+
"Unable to locate Staking Manager by output reference."
|
|
2852
|
+
);
|
|
2853
|
+
if (!utxo.datum) {
|
|
2854
|
+
throw new Error("Staking Manager UTxO has no datum.");
|
|
2855
|
+
}
|
|
2856
|
+
const datum = parseStakingManagerDatum(utxo.datum);
|
|
2857
|
+
return { utxo, datum };
|
|
2875
2858
|
}
|
|
2876
2859
|
function findStakingManager(params, lucid) {
|
|
2877
2860
|
return lucid.utxosAtWithUnit(
|
|
@@ -2894,20 +2877,17 @@ function findStakingManager(params, lucid) {
|
|
|
2894
2877
|
return result;
|
|
2895
2878
|
});
|
|
2896
2879
|
}
|
|
2897
|
-
function findStakingPositionByOutRef(
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
);
|
|
2909
|
-
return result;
|
|
2910
|
-
});
|
|
2880
|
+
async function findStakingPositionByOutRef(stakingPosition, lucid) {
|
|
2881
|
+
const utxo = await resolveUtxo(
|
|
2882
|
+
stakingPosition,
|
|
2883
|
+
lucid,
|
|
2884
|
+
"Unable to locate Staking Position by output reference."
|
|
2885
|
+
);
|
|
2886
|
+
if (!utxo.datum) {
|
|
2887
|
+
throw new Error("Staking Position UTxO has no datum.");
|
|
2888
|
+
}
|
|
2889
|
+
const datum = parseStakingPositionOrThrow(utxo.datum);
|
|
2890
|
+
return { utxo, datum };
|
|
2911
2891
|
}
|
|
2912
2892
|
var rewardSnapshotPrecision = OCD_DECIMAL_UNIT * OCD_DECIMAL_UNIT;
|
|
2913
2893
|
function distributeReward(snapshotAda, adaReward, totalStake) {
|
|
@@ -3019,89 +2999,38 @@ var teamVestingSchedule = [
|
|
|
3019
2999
|
}
|
|
3020
3000
|
];
|
|
3021
3001
|
var spDistributionSchedule = {
|
|
3022
|
-
maxUnlockable:
|
|
3002
|
+
maxUnlockable: 2013760n * OCD_DECIMAL_UNIT,
|
|
3023
3003
|
schedule: [
|
|
3024
3004
|
{
|
|
3025
3005
|
vestedAtTime: 1669931100000n,
|
|
3026
3006
|
unlockAmt: 28768n * OCD_DECIMAL_UNIT
|
|
3027
|
-
},
|
|
3028
|
-
{
|
|
3029
|
-
vestedAtTime: 1701467100000n,
|
|
3030
|
-
unlockAmt: 33562n * OCD_DECIMAL_UNIT
|
|
3031
|
-
},
|
|
3032
|
-
{
|
|
3033
|
-
vestedAtTime: 1727387100000n,
|
|
3034
|
-
unlockAmt: 33561n * OCD_DECIMAL_UNIT
|
|
3035
|
-
},
|
|
3036
|
-
{
|
|
3037
|
-
vestedAtTime: 1733003100000n,
|
|
3038
|
-
unlockAmt: 38356n * OCD_DECIMAL_UNIT
|
|
3039
|
-
},
|
|
3040
|
-
{
|
|
3041
|
-
vestedAtTime: 1764539100000n,
|
|
3042
|
-
unlockAmt: 43150n * OCD_DECIMAL_UNIT
|
|
3043
|
-
},
|
|
3044
|
-
{
|
|
3045
|
-
vestedAtTime: 1796075100000n,
|
|
3046
|
-
unlockAmt: 47945n * OCD_DECIMAL_UNIT
|
|
3047
3007
|
}
|
|
3048
3008
|
]
|
|
3049
3009
|
};
|
|
3050
3010
|
var liqDistributionSchedule = {
|
|
3051
|
-
maxUnlockable:
|
|
3011
|
+
maxUnlockable: 316470n * OCD_DECIMAL_UNIT,
|
|
3052
3012
|
schedule: [
|
|
3053
3013
|
{
|
|
3054
3014
|
vestedAtTime: 1671659100000n,
|
|
3055
3015
|
unlockAmt: 4795n * OCD_DECIMAL_UNIT
|
|
3056
|
-
}
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
vestedAtTime: 1728683100000n,
|
|
3063
|
-
unlockAmt: 9589n * OCD_DECIMAL_UNIT
|
|
3064
|
-
},
|
|
3065
|
-
{
|
|
3066
|
-
vestedAtTime: 1734731100000n,
|
|
3067
|
-
unlockAmt: 14383n * OCD_DECIMAL_UNIT
|
|
3068
|
-
},
|
|
3069
|
-
{
|
|
3070
|
-
vestedAtTime: 1766267100000n,
|
|
3071
|
-
unlockAmt: 19178n * OCD_DECIMAL_UNIT
|
|
3072
|
-
},
|
|
3016
|
+
}
|
|
3017
|
+
]
|
|
3018
|
+
};
|
|
3019
|
+
var spLpDistributionSchedule = {
|
|
3020
|
+
maxUnlockable: 17016441n * OCD_DECIMAL_UNIT,
|
|
3021
|
+
schedule: [
|
|
3073
3022
|
{
|
|
3074
|
-
vestedAtTime:
|
|
3075
|
-
unlockAmt:
|
|
3023
|
+
vestedAtTime: 1700171100000n,
|
|
3024
|
+
unlockAmt: 33563n * OCD_DECIMAL_UNIT
|
|
3076
3025
|
}
|
|
3077
3026
|
]
|
|
3078
3027
|
};
|
|
3079
3028
|
var govDistributionSchedule = {
|
|
3080
|
-
maxUnlockable:
|
|
3029
|
+
maxUnlockable: 1381248n * OCD_DECIMAL_UNIT,
|
|
3081
3030
|
schedule: [
|
|
3082
3031
|
{
|
|
3083
3032
|
vestedAtTime: 1670363100000n,
|
|
3084
3033
|
unlockAmt: 2398n * OCD_DECIMAL_UNIT
|
|
3085
|
-
},
|
|
3086
|
-
{
|
|
3087
|
-
vestedAtTime: 1701899100000n,
|
|
3088
|
-
unlockAmt: 3596n * OCD_DECIMAL_UNIT
|
|
3089
|
-
},
|
|
3090
|
-
{
|
|
3091
|
-
vestedAtTime: 1733435100000n,
|
|
3092
|
-
unlockAmt: 4795n * OCD_DECIMAL_UNIT
|
|
3093
|
-
},
|
|
3094
|
-
{
|
|
3095
|
-
vestedAtTime: 1752443100000n,
|
|
3096
|
-
unlockAmt: 4794n * OCD_DECIMAL_UNIT
|
|
3097
|
-
},
|
|
3098
|
-
{
|
|
3099
|
-
vestedAtTime: 1764971100000n,
|
|
3100
|
-
unlockAmt: 5993n * OCD_DECIMAL_UNIT
|
|
3101
|
-
},
|
|
3102
|
-
{
|
|
3103
|
-
vestedAtTime: 1796507100000n,
|
|
3104
|
-
unlockAmt: 7191n * OCD_DECIMAL_UNIT
|
|
3105
3034
|
}
|
|
3106
3035
|
]
|
|
3107
3036
|
};
|
|
@@ -3134,7 +3063,7 @@ function calculateVestedPerEpoch(schedule, currentTime) {
|
|
|
3134
3063
|
return bigintMin(schedule.maxUnlockable, go(schedule.schedule));
|
|
3135
3064
|
}
|
|
3136
3065
|
function calculateTotalVestedRewards(currentTime) {
|
|
3137
|
-
return calculateVestedPerEpoch(spDistributionSchedule, currentTime) + calculateVestedPerEpoch(govDistributionSchedule, currentTime) + calculateVestedPerEpoch(liqDistributionSchedule, currentTime);
|
|
3066
|
+
return calculateVestedPerEpoch(spDistributionSchedule, currentTime) + calculateVestedPerEpoch(govDistributionSchedule, currentTime) + calculateVestedPerEpoch(liqDistributionSchedule, currentTime) + calculateVestedPerEpoch(spLpDistributionSchedule, currentTime);
|
|
3138
3067
|
}
|
|
3139
3068
|
|
|
3140
3069
|
// src/contracts/poll/helpers.ts
|
|
@@ -3156,7 +3085,7 @@ function q(initialIndyDist, pollStatus, currentTime, treasuryIndyWithdrawnAmt) {
|
|
|
3156
3085
|
)
|
|
3157
3086
|
}
|
|
3158
3087
|
).getOnChainInt;
|
|
3159
|
-
return { getOnChainInt: BigInt(q2) };
|
|
3088
|
+
return { getOnChainInt: BigInt(q2) / 1000n };
|
|
3160
3089
|
}
|
|
3161
3090
|
}
|
|
3162
3091
|
function pollPassQuorum(initialIndyDist, pollStatus, currentTime, minQuorum, treasuryIndyWithdrawnAmt) {
|
|
@@ -3332,7 +3261,7 @@ function serialiseVersionRecordDatum(d) {
|
|
|
3332
3261
|
}
|
|
3333
3262
|
|
|
3334
3263
|
// src/contracts/gov/transactions.ts
|
|
3335
|
-
async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lucid, currentSlot,
|
|
3264
|
+
async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lucid, currentSlot, gov, allIAssetOrefs) {
|
|
3336
3265
|
const network = lucid.config().network;
|
|
3337
3266
|
const currentTime = BigInt((0, import_lucid30.slotToUnixTime)(network, currentSlot));
|
|
3338
3267
|
const ownAddr = await lucid.wallet().address();
|
|
@@ -3353,10 +3282,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
3353
3282
|
]),
|
|
3354
3283
|
(_) => new Error("Expected a single poll auth token policy ref Script UTXO")
|
|
3355
3284
|
);
|
|
3356
|
-
const govUtxo =
|
|
3357
|
-
await lucid.utxosByOutRef([govOref]),
|
|
3358
|
-
(_) => new Error("Expected a single Gov UTXO")
|
|
3359
|
-
);
|
|
3285
|
+
const govUtxo = await resolveUtxo(gov, lucid, "Expected a single Gov UTXO");
|
|
3360
3286
|
const govDatum = parseGovDatumOrThrow(getInlineDatumOrThrow(govUtxo));
|
|
3361
3287
|
const votingEndTime = currentTime + govDatum.protocolParams.votingPeriod;
|
|
3362
3288
|
const expirationTime = votingEndTime + govDatum.protocolParams.expirationPeriod;
|
|
@@ -3450,18 +3376,19 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
3450
3376
|
newPollId
|
|
3451
3377
|
];
|
|
3452
3378
|
}
|
|
3453
|
-
async function createShardsChunks(chunkSize,
|
|
3379
|
+
async function createShardsChunks(chunkSize, pollManager, sysParams, currentSlot, lucid) {
|
|
3454
3380
|
const network = lucid.config().network;
|
|
3455
3381
|
const currentTime = BigInt((0, import_lucid30.slotToUnixTime)(network, currentSlot));
|
|
3456
3382
|
const ownAddr = await lucid.wallet().address();
|
|
3457
|
-
const pollManagerUtxo =
|
|
3458
|
-
|
|
3459
|
-
|
|
3383
|
+
const pollManagerUtxo = await resolveUtxo(
|
|
3384
|
+
pollManager,
|
|
3385
|
+
lucid,
|
|
3386
|
+
"Expected a single Poll manager UTXO"
|
|
3460
3387
|
);
|
|
3461
|
-
const
|
|
3388
|
+
const pollManagerDatum = parsePollManagerOrThrow(
|
|
3462
3389
|
getInlineDatumOrThrow(pollManagerUtxo)
|
|
3463
3390
|
);
|
|
3464
|
-
if (
|
|
3391
|
+
if (pollManagerDatum.createdShardsCount >= pollManagerDatum.totalShardsCount) {
|
|
3465
3392
|
throw new Error("All shards already created.");
|
|
3466
3393
|
}
|
|
3467
3394
|
const pollAuthTokenPolicyRefScriptUtxo = matchSingle(
|
|
@@ -3483,7 +3410,9 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
|
|
|
3483
3410
|
const shardsCount = BigInt(
|
|
3484
3411
|
Math.min(
|
|
3485
3412
|
Number(chunkSize),
|
|
3486
|
-
Number(
|
|
3413
|
+
Number(
|
|
3414
|
+
pollManagerDatum.totalShardsCount - pollManagerDatum.createdShardsCount
|
|
3415
|
+
)
|
|
3487
3416
|
)
|
|
3488
3417
|
);
|
|
3489
3418
|
const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
|
|
@@ -3499,8 +3428,8 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
|
|
|
3499
3428
|
value: serialisePollDatum({
|
|
3500
3429
|
PollManager: {
|
|
3501
3430
|
content: {
|
|
3502
|
-
...
|
|
3503
|
-
createdShardsCount:
|
|
3431
|
+
...pollManagerDatum,
|
|
3432
|
+
createdShardsCount: pollManagerDatum.createdShardsCount + shardsCount
|
|
3504
3433
|
}
|
|
3505
3434
|
}
|
|
3506
3435
|
})
|
|
@@ -3515,9 +3444,9 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
|
|
|
3515
3444
|
value: serialisePollDatum({
|
|
3516
3445
|
PollShard: {
|
|
3517
3446
|
content: {
|
|
3518
|
-
pollId:
|
|
3447
|
+
pollId: pollManagerDatum.pollId,
|
|
3519
3448
|
status: { yesVotes: 0n, noVotes: 0n },
|
|
3520
|
-
votingEndTime:
|
|
3449
|
+
votingEndTime: pollManagerDatum.votingEndTime,
|
|
3521
3450
|
managerAddress: addressFromBech32(pollManagerUtxo.address)
|
|
3522
3451
|
}
|
|
3523
3452
|
}
|
|
@@ -3545,7 +3474,7 @@ function voteHelper(stakingPosLockedAmt, pollShard, voteOption, currentTime, ind
|
|
|
3545
3474
|
];
|
|
3546
3475
|
return [new Map(newLockedAmt), newPollStatus];
|
|
3547
3476
|
}
|
|
3548
|
-
async function vote(voteOption,
|
|
3477
|
+
async function vote(voteOption, pollShard, stakingPosition, sysParams, lucid, currentSlot) {
|
|
3549
3478
|
const network = lucid.config().network;
|
|
3550
3479
|
const currentTime = BigInt((0, import_lucid30.slotToUnixTime)(network, currentSlot));
|
|
3551
3480
|
const ownAddr = await lucid.wallet().address();
|
|
@@ -3563,16 +3492,18 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
|
|
|
3563
3492
|
]),
|
|
3564
3493
|
(_) => new Error("Expected a single staking ref Script UTXO")
|
|
3565
3494
|
);
|
|
3566
|
-
const pollShardUtxo =
|
|
3567
|
-
|
|
3568
|
-
|
|
3495
|
+
const pollShardUtxo = await resolveUtxo(
|
|
3496
|
+
pollShard,
|
|
3497
|
+
lucid,
|
|
3498
|
+
"Expected a single Poll shard UTXO"
|
|
3569
3499
|
);
|
|
3570
3500
|
const pollShardDatum = parsePollShardOrThrow(
|
|
3571
3501
|
getInlineDatumOrThrow(pollShardUtxo)
|
|
3572
3502
|
);
|
|
3573
|
-
const stakingPosUtxo =
|
|
3574
|
-
|
|
3575
|
-
|
|
3503
|
+
const stakingPosUtxo = await resolveUtxo(
|
|
3504
|
+
stakingPosition,
|
|
3505
|
+
lucid,
|
|
3506
|
+
"Expected a single staking position UTXO"
|
|
3576
3507
|
);
|
|
3577
3508
|
const stakingPosDatum = parseStakingPositionOrThrow(
|
|
3578
3509
|
getInlineDatumOrThrow(stakingPosUtxo)
|
|
@@ -3592,7 +3523,12 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
|
|
|
3592
3523
|
BigInt(validityFrom),
|
|
3593
3524
|
indyStakedAmt
|
|
3594
3525
|
);
|
|
3595
|
-
return lucid.newTx().validFrom(validityFrom).validTo(
|
|
3526
|
+
return lucid.newTx().validFrom(validityFrom).validTo(
|
|
3527
|
+
Math.min(
|
|
3528
|
+
Number(pollShardDatum.votingEndTime) - ONE_SECOND,
|
|
3529
|
+
Number(currentTime) + Number(sysParams.govParams.gBiasTime) - ONE_SECOND
|
|
3530
|
+
)
|
|
3531
|
+
).readFrom([stakingRefScriptUtxo, pollShardRefScriptUtxo]).collectFrom([stakingPosUtxo], serialiseStakingRedeemer("Lock")).collectFrom(
|
|
3596
3532
|
[pollShardUtxo],
|
|
3597
3533
|
serialisePollShardRedeemer({ Vote: { content: voteOption } })
|
|
3598
3534
|
).pay.ToContract(
|
|
@@ -3621,7 +3557,7 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
|
|
|
3621
3557
|
stakingPosUtxo.assets
|
|
3622
3558
|
).addSigner(ownAddr);
|
|
3623
3559
|
}
|
|
3624
|
-
async function mergeShards(
|
|
3560
|
+
async function mergeShards(pollManager, shardsOutRefs, sysParams, lucid, currentSlot) {
|
|
3625
3561
|
const network = lucid.config().network;
|
|
3626
3562
|
const currentTime = BigInt((0, import_lucid30.slotToUnixTime)(network, currentSlot));
|
|
3627
3563
|
const ownAddr = await lucid.wallet().address();
|
|
@@ -3649,9 +3585,10 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
3649
3585
|
]),
|
|
3650
3586
|
(_) => new Error("Expected a single poll auth token policy ref Script UTXO")
|
|
3651
3587
|
);
|
|
3652
|
-
const pollManagerUtxo =
|
|
3653
|
-
|
|
3654
|
-
|
|
3588
|
+
const pollManagerUtxo = await resolveUtxo(
|
|
3589
|
+
pollManager,
|
|
3590
|
+
lucid,
|
|
3591
|
+
"Expected a single Poll manager UTXO"
|
|
3655
3592
|
);
|
|
3656
3593
|
const pollManagerDatum = parsePollManagerOrThrow(
|
|
3657
3594
|
getInlineDatumOrThrow(pollManagerUtxo)
|
|
@@ -3712,7 +3649,7 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
3712
3649
|
(0, import_lucid30.addAssets)(pollManagerUtxo.assets, shardsAggregatedAda)
|
|
3713
3650
|
).addSigner(ownAddr);
|
|
3714
3651
|
}
|
|
3715
|
-
async function endProposal(
|
|
3652
|
+
async function endProposal(pollManager, gov, sysParams, lucid, currentSlot) {
|
|
3716
3653
|
const network = lucid.config().network;
|
|
3717
3654
|
const currentTime = BigInt((0, import_lucid30.slotToUnixTime)(network, currentSlot));
|
|
3718
3655
|
const ownAddr = await lucid.wallet().address();
|
|
@@ -3748,28 +3685,26 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
|
|
|
3748
3685
|
]),
|
|
3749
3686
|
(_) => new Error("Expected a single upgrade auth token policy ref Script UTXO")
|
|
3750
3687
|
);
|
|
3751
|
-
const pollManagerUtxo =
|
|
3752
|
-
|
|
3753
|
-
|
|
3688
|
+
const pollManagerUtxo = await resolveUtxo(
|
|
3689
|
+
pollManager,
|
|
3690
|
+
lucid,
|
|
3691
|
+
"Expected a single Poll manager UTXO"
|
|
3754
3692
|
);
|
|
3755
|
-
const
|
|
3693
|
+
const pollManagerDatum = parsePollManagerOrThrow(
|
|
3756
3694
|
getInlineDatumOrThrow(pollManagerUtxo)
|
|
3757
3695
|
);
|
|
3758
|
-
const govUtxo =
|
|
3759
|
-
await lucid.utxosByOutRef([govOref]),
|
|
3760
|
-
(_) => new Error("Expected a single Gov UTXO")
|
|
3761
|
-
);
|
|
3696
|
+
const govUtxo = await resolveUtxo(gov, lucid, "Expected a single Gov UTXO");
|
|
3762
3697
|
const govDatum = parseGovDatumOrThrow(getInlineDatumOrThrow(govUtxo));
|
|
3763
3698
|
const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
|
|
3764
3699
|
const indyAsset = fromSystemParamsAsset(
|
|
3765
3700
|
sysParams.pollManagerParams.indyAsset
|
|
3766
3701
|
);
|
|
3767
|
-
const proposalExpired = currentTime >
|
|
3702
|
+
const proposalExpired = currentTime > pollManagerDatum.expirationTime;
|
|
3768
3703
|
const proposalPassed = !proposalExpired && pollPassQuorum(
|
|
3769
3704
|
sysParams.pollManagerParams.initialIndyDistribution,
|
|
3770
|
-
|
|
3705
|
+
pollManagerDatum.status,
|
|
3771
3706
|
currentTime,
|
|
3772
|
-
|
|
3707
|
+
pollManagerDatum.minimumQuorum,
|
|
3773
3708
|
govDatum.treasuryIndyWithdrawnAmt
|
|
3774
3709
|
);
|
|
3775
3710
|
const upgradeTokenVal = mkAssetsOf(
|
|
@@ -3806,12 +3741,12 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
|
|
|
3806
3741
|
{
|
|
3807
3742
|
kind: "inline",
|
|
3808
3743
|
value: serialiseExecuteDatum({
|
|
3809
|
-
id:
|
|
3810
|
-
content:
|
|
3744
|
+
id: pollManagerDatum.pollId,
|
|
3745
|
+
content: pollManagerDatum.content,
|
|
3811
3746
|
passedTime: currentTime,
|
|
3812
|
-
votingEndTime:
|
|
3813
|
-
protocolVersion:
|
|
3814
|
-
treasuryWithdrawal:
|
|
3747
|
+
votingEndTime: pollManagerDatum.votingEndTime,
|
|
3748
|
+
protocolVersion: pollManagerDatum.protocolVersion,
|
|
3749
|
+
treasuryWithdrawal: pollManagerDatum.treasuryWithdrawal
|
|
3815
3750
|
})
|
|
3816
3751
|
},
|
|
3817
3752
|
upgradeTokenVal
|
|
@@ -3828,14 +3763,11 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
|
|
|
3828
3763
|
}
|
|
3829
3764
|
return tx;
|
|
3830
3765
|
}
|
|
3831
|
-
async function executeProposal(
|
|
3766
|
+
async function executeProposal(execute, gov, treasuryWithdrawal, allIAssetOrefs, modifyIAsset, sysParams, lucid, currentSlot) {
|
|
3832
3767
|
const network = lucid.config().network;
|
|
3833
3768
|
const currentTime = BigInt((0, import_lucid30.slotToUnixTime)(network, currentSlot));
|
|
3834
3769
|
const ownAddr = await lucid.wallet().address();
|
|
3835
|
-
const govUtxo =
|
|
3836
|
-
await lucid.utxosByOutRef([govOref]),
|
|
3837
|
-
(_) => new Error("Expected a single gov UTXO")
|
|
3838
|
-
);
|
|
3770
|
+
const govUtxo = await resolveUtxo(gov, lucid, "Expected a single gov UTXO");
|
|
3839
3771
|
const govDatum = parseGovDatumOrThrow(getInlineDatumOrThrow(govUtxo));
|
|
3840
3772
|
const govRefScriptUtxo = matchSingle(
|
|
3841
3773
|
await lucid.utxosByOutRef([
|
|
@@ -3859,9 +3791,10 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3859
3791
|
]),
|
|
3860
3792
|
(_) => new Error("Expected a single upgrade auth token policy ref Script UTXO")
|
|
3861
3793
|
);
|
|
3862
|
-
const executeUtxo =
|
|
3863
|
-
|
|
3864
|
-
|
|
3794
|
+
const executeUtxo = await resolveUtxo(
|
|
3795
|
+
execute,
|
|
3796
|
+
lucid,
|
|
3797
|
+
"Expected a single execute UTXO"
|
|
3865
3798
|
);
|
|
3866
3799
|
const executeDatum = parseExecuteDatumOrThrow(
|
|
3867
3800
|
getInlineDatumOrThrow(executeUtxo)
|
|
@@ -3879,13 +3812,13 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3879
3812
|
import_fp_ts10.option.fromNullable(executeDatum.treasuryWithdrawal),
|
|
3880
3813
|
import_fp_ts10.option.match(
|
|
3881
3814
|
() => {
|
|
3882
|
-
if (
|
|
3815
|
+
if (treasuryWithdrawal) {
|
|
3883
3816
|
throw new Error("Cannot provide withdrawal oref when no withdrawal.");
|
|
3884
3817
|
}
|
|
3885
3818
|
return Promise.resolve();
|
|
3886
3819
|
},
|
|
3887
3820
|
async (withdrawal) => {
|
|
3888
|
-
if (!
|
|
3821
|
+
if (!treasuryWithdrawal) {
|
|
3889
3822
|
throw new Error("Have to provide withdrawal oref when withdrawal.");
|
|
3890
3823
|
}
|
|
3891
3824
|
const treasuryRefScriptUtxo = matchSingle(
|
|
@@ -3896,9 +3829,10 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
3896
3829
|
]),
|
|
3897
3830
|
(_) => new Error("Expected a single Treasury Ref Script UTXO")
|
|
3898
3831
|
);
|
|
3899
|
-
const treasuryWithdrawalUtxo =
|
|
3900
|
-
|
|
3901
|
-
|
|
3832
|
+
const treasuryWithdrawalUtxo = await resolveUtxo(
|
|
3833
|
+
treasuryWithdrawal,
|
|
3834
|
+
lucid,
|
|
3835
|
+
"Expected a single withdrawal UTXO"
|
|
3902
3836
|
);
|
|
3903
3837
|
const withdrawalVal = createValueFromWithdrawal(withdrawal);
|
|
3904
3838
|
const withdrawalChangeVal = (0, import_lucid30.addAssets)(
|
|
@@ -4061,12 +3995,13 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
4061
3995
|
]),
|
|
4062
3996
|
(_) => new Error("Expected a single CDP Ref Script UTXO")
|
|
4063
3997
|
);
|
|
4064
|
-
if (!
|
|
3998
|
+
if (!modifyIAsset) {
|
|
4065
3999
|
throw new Error("Have to provide iasset oref when modify asset.");
|
|
4066
4000
|
}
|
|
4067
|
-
const iassetUtxo =
|
|
4068
|
-
|
|
4069
|
-
|
|
4001
|
+
const iassetUtxo = await resolveUtxo(
|
|
4002
|
+
modifyIAsset,
|
|
4003
|
+
lucid,
|
|
4004
|
+
"Expected a single iasset UTXO"
|
|
4070
4005
|
);
|
|
4071
4006
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
4072
4007
|
getInlineDatumOrThrow(iassetUtxo)
|
|
@@ -4395,7 +4330,7 @@ async function closeSpAccount(accountUtxo, params, lucid) {
|
|
|
4395
4330
|
}
|
|
4396
4331
|
).addSignerKey((0, import_lucid34.toHex)(oldAccountDatum.owner));
|
|
4397
4332
|
}
|
|
4398
|
-
async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo, iAssetUtxo, newSnapshotUtxo, params, lucid,
|
|
4333
|
+
async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo, iAssetUtxo, newSnapshotUtxo, params, lucid, collector) {
|
|
4399
4334
|
const redeemer = {
|
|
4400
4335
|
ProcessRequest: {
|
|
4401
4336
|
txHash: { hash: (0, import_lucid34.fromHex)(accountUtxo.txHash) },
|
|
@@ -4578,13 +4513,7 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4578
4513
|
newPoolSum
|
|
4579
4514
|
);
|
|
4580
4515
|
if (rewardLovelacesFee > 0n) {
|
|
4581
|
-
await collectorFeeTx(
|
|
4582
|
-
rewardLovelacesFee,
|
|
4583
|
-
lucid,
|
|
4584
|
-
params,
|
|
4585
|
-
tx,
|
|
4586
|
-
collectorOref
|
|
4587
|
-
);
|
|
4516
|
+
await collectorFeeTx(rewardLovelacesFee, lucid, params, tx, collector);
|
|
4588
4517
|
}
|
|
4589
4518
|
tx.readFrom([govUtxo, iAssetUtxo, ...refInputs]);
|
|
4590
4519
|
tx.pay.ToContract(
|
|
@@ -4695,7 +4624,7 @@ async function processSpRequest(asset, stabilityPoolUtxo, accountUtxo, govUtxo,
|
|
|
4695
4624
|
params.scriptReferences.authTokenPolicies.accountTokenRef,
|
|
4696
4625
|
lucid
|
|
4697
4626
|
);
|
|
4698
|
-
await collectorFeeTx(rewardLovelacesFee, lucid, params, tx,
|
|
4627
|
+
await collectorFeeTx(rewardLovelacesFee, lucid, params, tx, collector);
|
|
4699
4628
|
tx.readFrom([govUtxo, iAssetUtxo, accountTokenRef, ...refInputs]);
|
|
4700
4629
|
tx.mintAssets(
|
|
4701
4630
|
{
|
|
@@ -4786,9 +4715,16 @@ async function annulRequest(accountUtxo, params, lucid) {
|
|
|
4786
4715
|
|
|
4787
4716
|
// src/contracts/staking/transactions.ts
|
|
4788
4717
|
var import_lucid35 = require("@lucid-evolution/lucid");
|
|
4789
|
-
async function openStakingPosition(amount, params, lucid,
|
|
4718
|
+
async function openStakingPosition(amount, params, lucid, stakingManager) {
|
|
4790
4719
|
const [pkh, _] = await addrDetails(lucid);
|
|
4791
|
-
const
|
|
4720
|
+
const stakingManagerUtxo = await resolveUtxo(
|
|
4721
|
+
stakingManager,
|
|
4722
|
+
lucid,
|
|
4723
|
+
"Expected a single staking manager UTXO"
|
|
4724
|
+
);
|
|
4725
|
+
const stakingManagerDatum = parseStakingManagerDatum(
|
|
4726
|
+
getInlineDatumOrThrow(stakingManagerUtxo)
|
|
4727
|
+
);
|
|
4792
4728
|
const stakingRefScriptUtxo = matchSingle(
|
|
4793
4729
|
await lucid.utxosByOutRef([
|
|
4794
4730
|
fromSystemParamsScriptRef(params.scriptReferences.stakingValidatorRef)
|
|
@@ -4804,39 +4740,39 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4804
4740
|
(_2) => new Error("Expected a single staking token policy Ref Script UTXO")
|
|
4805
4741
|
);
|
|
4806
4742
|
const newStakingManagerDatum = {
|
|
4807
|
-
totalStake:
|
|
4743
|
+
totalStake: stakingManagerDatum.totalStake + amount,
|
|
4808
4744
|
managerSnapshot: {
|
|
4809
|
-
snapshotAda:
|
|
4745
|
+
snapshotAda: stakingManagerDatum.managerSnapshot.snapshotAda
|
|
4810
4746
|
}
|
|
4811
4747
|
};
|
|
4812
4748
|
const stakingPositionDatum = {
|
|
4813
4749
|
owner: (0, import_lucid35.fromHex)(pkh.hash),
|
|
4814
4750
|
lockedAmount: /* @__PURE__ */ new Map([]),
|
|
4815
4751
|
positionSnapshot: {
|
|
4816
|
-
snapshotAda:
|
|
4752
|
+
snapshotAda: stakingManagerDatum.managerSnapshot.snapshotAda
|
|
4817
4753
|
}
|
|
4818
4754
|
};
|
|
4819
4755
|
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingToken[1].unTokenName);
|
|
4820
4756
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
4821
4757
|
return lucid.newTx().collectFrom(
|
|
4822
|
-
[
|
|
4758
|
+
[stakingManagerUtxo],
|
|
4823
4759
|
serialiseStakingRedeemer({
|
|
4824
4760
|
CreateStakingPosition: { creatorPkh: pkh.hash }
|
|
4825
4761
|
})
|
|
4826
4762
|
).readFrom([stakingRefScriptUtxo]).pay.ToContract(
|
|
4827
|
-
|
|
4763
|
+
stakingManagerUtxo.address,
|
|
4828
4764
|
{
|
|
4829
4765
|
kind: "inline",
|
|
4830
4766
|
value: serialiseStakingDatum(newStakingManagerDatum)
|
|
4831
4767
|
},
|
|
4832
|
-
|
|
4768
|
+
stakingManagerUtxo.assets
|
|
4833
4769
|
).readFrom([stakingTokenPolicyRefScriptUtxo]).mintAssets(
|
|
4834
4770
|
{
|
|
4835
4771
|
[stakingToken]: 1n
|
|
4836
4772
|
},
|
|
4837
4773
|
import_lucid35.Data.void()
|
|
4838
4774
|
).pay.ToContract(
|
|
4839
|
-
|
|
4775
|
+
stakingManagerUtxo.address,
|
|
4840
4776
|
{
|
|
4841
4777
|
kind: "inline",
|
|
4842
4778
|
value: serialiseStakingDatum(stakingPositionDatum)
|
|
@@ -4847,14 +4783,25 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4847
4783
|
}
|
|
4848
4784
|
).addSignerKey(pkh.hash);
|
|
4849
4785
|
}
|
|
4850
|
-
async function adjustStakingPosition(
|
|
4786
|
+
async function adjustStakingPosition(stakingPosition, amount, params, lucid, currentSlot, stakingManager) {
|
|
4851
4787
|
const network = lucid.config().network;
|
|
4852
4788
|
const currentTime = (0, import_lucid35.slotToUnixTime)(network, currentSlot) - 120 * ONE_SECOND;
|
|
4853
|
-
const
|
|
4854
|
-
|
|
4855
|
-
lucid
|
|
4789
|
+
const stakingPositionUtxo = await resolveUtxo(
|
|
4790
|
+
stakingPosition,
|
|
4791
|
+
lucid,
|
|
4792
|
+
"Expected a single staking position UTXO"
|
|
4793
|
+
);
|
|
4794
|
+
const stakingPositionDatum = parseStakingPositionOrThrow(
|
|
4795
|
+
getInlineDatumOrThrow(stakingPositionUtxo)
|
|
4796
|
+
);
|
|
4797
|
+
const stakingManagerUtxo = await resolveUtxo(
|
|
4798
|
+
stakingManager,
|
|
4799
|
+
lucid,
|
|
4800
|
+
"Expected a single staking manager UTXO"
|
|
4801
|
+
);
|
|
4802
|
+
const stakingManagerDatum = parseStakingManagerDatum(
|
|
4803
|
+
getInlineDatumOrThrow(stakingManagerUtxo)
|
|
4856
4804
|
);
|
|
4857
|
-
const stakingManagerOut = stakingManagerRef ? await findStakingManagerByOutRef(stakingManagerRef, lucid) : await findStakingManager(params, lucid);
|
|
4858
4805
|
const stakingRefScriptUtxo = matchSingle(
|
|
4859
4806
|
await lucid.utxosByOutRef([
|
|
4860
4807
|
fromSystemParamsScriptRef(params.scriptReferences.stakingValidatorRef)
|
|
@@ -4862,44 +4809,44 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4862
4809
|
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
4863
4810
|
);
|
|
4864
4811
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
4865
|
-
const existingIndyAmount =
|
|
4866
|
-
const currentSnapshotAda =
|
|
4867
|
-
const oldSnapshotAda =
|
|
4812
|
+
const existingIndyAmount = stakingPositionUtxo.assets[indyToken] ?? 0n;
|
|
4813
|
+
const currentSnapshotAda = stakingManagerDatum.managerSnapshot.snapshotAda;
|
|
4814
|
+
const oldSnapshotAda = stakingPositionDatum.positionSnapshot.snapshotAda;
|
|
4868
4815
|
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / rewardSnapshotPrecision;
|
|
4869
4816
|
const newLockedAmount = updateStakingLockedAmount(
|
|
4870
|
-
|
|
4817
|
+
stakingPositionDatum.lockedAmount,
|
|
4871
4818
|
BigInt(currentTime)
|
|
4872
4819
|
);
|
|
4873
4820
|
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo]).collectFrom(
|
|
4874
|
-
[
|
|
4821
|
+
[stakingPositionUtxo],
|
|
4875
4822
|
serialiseStakingRedeemer({
|
|
4876
4823
|
AdjustStakedAmount: { adjustAmount: amount }
|
|
4877
4824
|
})
|
|
4878
4825
|
).collectFrom(
|
|
4879
|
-
[
|
|
4826
|
+
[stakingManagerUtxo],
|
|
4880
4827
|
serialiseStakingRedeemer("UpdateTotalStake")
|
|
4881
4828
|
).pay.ToContract(
|
|
4882
|
-
|
|
4829
|
+
stakingManagerUtxo.address,
|
|
4883
4830
|
{
|
|
4884
4831
|
kind: "inline",
|
|
4885
4832
|
value: serialiseStakingDatum({
|
|
4886
|
-
...
|
|
4887
|
-
totalStake:
|
|
4833
|
+
...stakingManagerDatum,
|
|
4834
|
+
totalStake: stakingManagerDatum.totalStake + amount
|
|
4888
4835
|
})
|
|
4889
4836
|
},
|
|
4890
|
-
(0, import_lucid35.addAssets)(
|
|
4837
|
+
(0, import_lucid35.addAssets)(stakingManagerUtxo.assets, mkLovelacesOf(-adaReward))
|
|
4891
4838
|
).pay.ToContract(
|
|
4892
|
-
|
|
4839
|
+
stakingPositionUtxo.address,
|
|
4893
4840
|
{
|
|
4894
4841
|
kind: "inline",
|
|
4895
4842
|
value: serialiseStakingDatum({
|
|
4896
|
-
...
|
|
4843
|
+
...stakingPositionDatum,
|
|
4897
4844
|
lockedAmount: newLockedAmount,
|
|
4898
|
-
positionSnapshot:
|
|
4845
|
+
positionSnapshot: stakingManagerDatum.managerSnapshot
|
|
4899
4846
|
})
|
|
4900
4847
|
},
|
|
4901
4848
|
(0, import_lucid35.addAssets)(
|
|
4902
|
-
|
|
4849
|
+
stakingPositionUtxo.assets,
|
|
4903
4850
|
mkAssetsOf(
|
|
4904
4851
|
{
|
|
4905
4852
|
currencySymbol: params.stakingParams.indyToken[0].unCurrencySymbol,
|
|
@@ -4908,16 +4855,27 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4908
4855
|
amount
|
|
4909
4856
|
)
|
|
4910
4857
|
)
|
|
4911
|
-
).addSignerKey((0, import_lucid35.toHex)(
|
|
4858
|
+
).addSignerKey((0, import_lucid35.toHex)(stakingPositionDatum.owner));
|
|
4912
4859
|
}
|
|
4913
|
-
async function closeStakingPosition(
|
|
4860
|
+
async function closeStakingPosition(stakingPosition, params, lucid, currentSlot, stakingManager) {
|
|
4914
4861
|
const network = lucid.config().network;
|
|
4915
4862
|
const currentTime = (0, import_lucid35.slotToUnixTime)(network, currentSlot) - ONE_SECOND;
|
|
4916
|
-
const
|
|
4917
|
-
|
|
4918
|
-
lucid
|
|
4863
|
+
const stakingPositionUtxo = await resolveUtxo(
|
|
4864
|
+
stakingPosition,
|
|
4865
|
+
lucid,
|
|
4866
|
+
"Expected a single staking position UTXO"
|
|
4867
|
+
);
|
|
4868
|
+
const stakingPositionDatum = parseStakingPositionOrThrow(
|
|
4869
|
+
getInlineDatumOrThrow(stakingPositionUtxo)
|
|
4870
|
+
);
|
|
4871
|
+
const stakingManagerUtxo = await resolveUtxo(
|
|
4872
|
+
stakingManager,
|
|
4873
|
+
lucid,
|
|
4874
|
+
"Expected a single staking manager UTXO"
|
|
4875
|
+
);
|
|
4876
|
+
const stakingManagerDatum = parseStakingManagerDatum(
|
|
4877
|
+
getInlineDatumOrThrow(stakingManagerUtxo)
|
|
4919
4878
|
);
|
|
4920
|
-
const stakingManagerOut = stakingManagerRef ? await findStakingManagerByOutRef(stakingManagerRef, lucid) : await findStakingManager(params, lucid);
|
|
4921
4879
|
const stakingRefScriptUtxo = matchSingle(
|
|
4922
4880
|
await lucid.utxosByOutRef([
|
|
4923
4881
|
fromSystemParamsScriptRef(params.scriptReferences.stakingValidatorRef)
|
|
@@ -4934,33 +4892,37 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
4934
4892
|
);
|
|
4935
4893
|
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingToken[1].unTokenName);
|
|
4936
4894
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
4937
|
-
const existingIndyAmount =
|
|
4938
|
-
const currentSnapshotAda =
|
|
4939
|
-
const oldSnapshotAda =
|
|
4895
|
+
const existingIndyAmount = stakingPositionUtxo.assets[indyToken] ?? 0n;
|
|
4896
|
+
const currentSnapshotAda = stakingManagerDatum.managerSnapshot.snapshotAda;
|
|
4897
|
+
const oldSnapshotAda = stakingPositionDatum.positionSnapshot.snapshotAda;
|
|
4940
4898
|
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
|
|
4941
|
-
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([
|
|
4942
|
-
[
|
|
4899
|
+
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionUtxo], serialiseStakingRedeemer("Unstake")).collectFrom(
|
|
4900
|
+
[stakingManagerUtxo],
|
|
4943
4901
|
serialiseStakingRedeemer("UpdateTotalStake")
|
|
4944
4902
|
).pay.ToContract(
|
|
4945
|
-
|
|
4903
|
+
stakingManagerUtxo.address,
|
|
4946
4904
|
{
|
|
4947
4905
|
kind: "inline",
|
|
4948
4906
|
value: serialiseStakingDatum({
|
|
4949
|
-
...
|
|
4950
|
-
totalStake:
|
|
4907
|
+
...stakingManagerDatum,
|
|
4908
|
+
totalStake: stakingManagerDatum.totalStake - existingIndyAmount
|
|
4951
4909
|
})
|
|
4952
4910
|
},
|
|
4953
|
-
(0, import_lucid35.addAssets)(
|
|
4911
|
+
(0, import_lucid35.addAssets)(stakingManagerUtxo.assets, mkLovelacesOf(-adaReward))
|
|
4954
4912
|
).mintAssets(
|
|
4955
4913
|
{
|
|
4956
4914
|
[stakingToken]: -1n
|
|
4957
4915
|
},
|
|
4958
4916
|
import_lucid35.Data.void()
|
|
4959
|
-
).addSignerKey((0, import_lucid35.toHex)(
|
|
4917
|
+
).addSignerKey((0, import_lucid35.toHex)(stakingPositionDatum.owner));
|
|
4960
4918
|
}
|
|
4961
4919
|
var MIN_UTXO_AMOUNT = 2000000n;
|
|
4962
|
-
async function distributeAda(
|
|
4963
|
-
const
|
|
4920
|
+
async function distributeAda(stakingManager, collectorRefs, params, lucid) {
|
|
4921
|
+
const stakingManagerUtxo = await resolveUtxo(
|
|
4922
|
+
stakingManager,
|
|
4923
|
+
lucid,
|
|
4924
|
+
"Expected a single staking manager UTXO"
|
|
4925
|
+
);
|
|
4964
4926
|
const stakingManagerDatum = parseStakingManagerDatum(
|
|
4965
4927
|
getInlineDatumOrThrow(stakingManagerUtxo)
|
|
4966
4928
|
);
|
|
@@ -5118,16 +5080,16 @@ async function findInterestOracle(lucid, interestNft) {
|
|
|
5118
5080
|
}
|
|
5119
5081
|
|
|
5120
5082
|
// src/contracts/interest-oracle/transactions.ts
|
|
5121
|
-
async function startInterestOracle(initialUnitaryInterest, initialInterestRate, initialLastInterestUpdate, oracleParams, lucid, interestTokenName, withScriptRef = false,
|
|
5083
|
+
async function startInterestOracle(initialUnitaryInterest, initialInterestRate, initialLastInterestUpdate, oracleParams, lucid, interestTokenName, withScriptRef = false, refUtxo) {
|
|
5122
5084
|
const network = lucid.config().network;
|
|
5123
5085
|
const tokenName = interestTokenName ?? "INTEREST_ORACLE";
|
|
5124
|
-
if (!
|
|
5125
|
-
|
|
5086
|
+
if (!refUtxo) {
|
|
5087
|
+
refUtxo = (await lucid.wallet().getUtxos())[0];
|
|
5126
5088
|
}
|
|
5127
5089
|
const [tx, policyId] = await oneShotMintTx(lucid, {
|
|
5128
5090
|
referenceOutRef: {
|
|
5129
|
-
txHash:
|
|
5130
|
-
outputIdx: BigInt(
|
|
5091
|
+
txHash: refUtxo.txHash,
|
|
5092
|
+
outputIdx: BigInt(refUtxo.outputIndex)
|
|
5131
5093
|
},
|
|
5132
5094
|
mintAmounts: [
|
|
5133
5095
|
{
|
|
@@ -5691,21 +5653,18 @@ async function openLrp(assetTokenName, lovelacesAmt2, maxPrice, lucid, sysParams
|
|
|
5691
5653
|
{ lovelace: lovelacesAmt2 + MIN_LRP_COLLATERAL_AMT }
|
|
5692
5654
|
);
|
|
5693
5655
|
}
|
|
5694
|
-
async function cancelLrp(
|
|
5656
|
+
async function cancelLrp(lrp, sysParams, lucid) {
|
|
5695
5657
|
const lrpScriptRefUtxo = matchSingle(
|
|
5696
5658
|
await lucid.utxosByOutRef([
|
|
5697
5659
|
fromSystemParamsScriptRef(sysParams.scriptReferences.lrpValidatorRef)
|
|
5698
5660
|
]),
|
|
5699
5661
|
(_) => new Error("Expected a single LRP Ref Script UTXO")
|
|
5700
5662
|
);
|
|
5701
|
-
const lrpUtxo =
|
|
5702
|
-
await lucid.utxosByOutRef([lrpOutRef]),
|
|
5703
|
-
(_) => new Error("Expected a single LRP UTXO.")
|
|
5704
|
-
);
|
|
5663
|
+
const lrpUtxo = await resolveUtxo(lrp, lucid, "Expected a single LRP UTXO.");
|
|
5705
5664
|
const lrpDatum = parseLrpDatumOrThrow(getInlineDatumOrThrow(lrpUtxo));
|
|
5706
5665
|
return lucid.newTx().readFrom([lrpScriptRefUtxo]).collectFrom([lrpUtxo], serialiseLrpRedeemer("Cancel")).addSignerKey(lrpDatum.owner);
|
|
5707
5666
|
}
|
|
5708
|
-
async function redeemLrp(redemptionLrpsData,
|
|
5667
|
+
async function redeemLrp(redemptionLrpsData, priceOracle, iasset, lucid, sysParams) {
|
|
5709
5668
|
const network = lucid.config().network;
|
|
5710
5669
|
const lrpScriptRefUtxo = matchSingle(
|
|
5711
5670
|
await lucid.utxosByOutRef([
|
|
@@ -5713,13 +5672,15 @@ async function redeemLrp(redemptionLrpsData, priceOracleOutRef, iassetOutRef, lu
|
|
|
5713
5672
|
]),
|
|
5714
5673
|
(_) => new Error("Expected a single LRP Ref Script UTXO")
|
|
5715
5674
|
);
|
|
5716
|
-
const priceOracleUtxo =
|
|
5717
|
-
|
|
5718
|
-
|
|
5675
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
5676
|
+
priceOracle,
|
|
5677
|
+
lucid,
|
|
5678
|
+
"Expected a single price oracle UTXO"
|
|
5719
5679
|
);
|
|
5720
|
-
const iassetUtxo =
|
|
5721
|
-
|
|
5722
|
-
|
|
5680
|
+
const iassetUtxo = await resolveUtxo(
|
|
5681
|
+
iasset,
|
|
5682
|
+
lucid,
|
|
5683
|
+
"Expected a single IAsset UTXO"
|
|
5723
5684
|
);
|
|
5724
5685
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
5725
5686
|
getInlineDatumOrThrow(iassetUtxo)
|
|
@@ -5744,17 +5705,14 @@ async function redeemLrp(redemptionLrpsData, priceOracleOutRef, iassetOutRef, lu
|
|
|
5744
5705
|
)
|
|
5745
5706
|
).readFrom([lrpScriptRefUtxo]).readFrom([iassetUtxo, priceOracleUtxo]).compose(tx);
|
|
5746
5707
|
}
|
|
5747
|
-
async function adjustLrp(lucid,
|
|
5708
|
+
async function adjustLrp(lucid, lrp, lovelacesAdjustAmt, newMaxPrice, sysParams) {
|
|
5748
5709
|
const lrpScriptRefUtxo = matchSingle(
|
|
5749
5710
|
await lucid.utxosByOutRef([
|
|
5750
5711
|
fromSystemParamsScriptRef(sysParams.scriptReferences.lrpValidatorRef)
|
|
5751
5712
|
]),
|
|
5752
5713
|
(_) => new Error("Expected a single LRP Ref Script UTXO")
|
|
5753
5714
|
);
|
|
5754
|
-
const lrpUtxo =
|
|
5755
|
-
await lucid.utxosByOutRef([lrpOutRef]),
|
|
5756
|
-
(_) => new Error("Expected a single LRP UTXO.")
|
|
5757
|
-
);
|
|
5715
|
+
const lrpUtxo = await resolveUtxo(lrp, lucid, "Expected a single LRP UTXO.");
|
|
5758
5716
|
const lrpDatum = parseLrpDatumOrThrow(getInlineDatumOrThrow(lrpUtxo));
|
|
5759
5717
|
const rewardAssetClass = {
|
|
5760
5718
|
currencySymbol: sysParams.lrpParams.iassetPolicyId.unCurrencySymbol,
|
|
@@ -5791,8 +5749,8 @@ async function adjustLrp(lucid, lrpOutRef, lovelacesAdjustAmt, newMaxPrice, sysP
|
|
|
5791
5749
|
)
|
|
5792
5750
|
).addSignerKey(lrpDatum.owner);
|
|
5793
5751
|
}
|
|
5794
|
-
async function claimLrp(lucid,
|
|
5795
|
-
return adjustLrp(lucid,
|
|
5752
|
+
async function claimLrp(lucid, lrp, sysParams) {
|
|
5753
|
+
return adjustLrp(lucid, lrp, 0n, void 0, sysParams);
|
|
5796
5754
|
}
|
|
5797
5755
|
|
|
5798
5756
|
// src/contracts/lrp/scripts.ts
|
|
@@ -6019,7 +5977,7 @@ function calculateLeverageFromCollateralRatio(iasset, collateralRatioPercentage,
|
|
|
6019
5977
|
}
|
|
6020
5978
|
|
|
6021
5979
|
// src/contracts/leverage/transactions.ts
|
|
6022
|
-
async function leverageCdpWithLrp(leverage, baseCollateral,
|
|
5980
|
+
async function leverageCdpWithLrp(leverage, baseCollateral, priceOracle, iasset, cdpCreator, interestOracle, collector, sysParams, lucid, allLrps, currentSlot) {
|
|
6023
5981
|
const network = lucid.config().network;
|
|
6024
5982
|
const currentTime = BigInt((0, import_lucid51.slotToUnixTime)(network, currentSlot));
|
|
6025
5983
|
const [pkh, skh] = await addrDetails(lucid);
|
|
@@ -6053,27 +6011,31 @@ async function leverageCdpWithLrp(leverage, baseCollateral, priceOracleOutRef, i
|
|
|
6053
6011
|
]),
|
|
6054
6012
|
(_) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
6055
6013
|
);
|
|
6056
|
-
const cdpCreatorUtxo =
|
|
6057
|
-
|
|
6058
|
-
|
|
6014
|
+
const cdpCreatorUtxo = await resolveUtxo(
|
|
6015
|
+
cdpCreator,
|
|
6016
|
+
lucid,
|
|
6017
|
+
"Expected a single CDP creator UTXO"
|
|
6059
6018
|
);
|
|
6060
|
-
const interestOracleUtxo =
|
|
6061
|
-
|
|
6062
|
-
|
|
6019
|
+
const interestOracleUtxo = await resolveUtxo(
|
|
6020
|
+
interestOracle,
|
|
6021
|
+
lucid,
|
|
6022
|
+
"Expected a single interest oracle UTXO"
|
|
6063
6023
|
);
|
|
6064
6024
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
6065
6025
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
6066
6026
|
);
|
|
6067
|
-
const priceOracleUtxo =
|
|
6068
|
-
|
|
6069
|
-
|
|
6027
|
+
const priceOracleUtxo = await resolveUtxo(
|
|
6028
|
+
priceOracle,
|
|
6029
|
+
lucid,
|
|
6030
|
+
"Expected a single price oracle UTXO"
|
|
6070
6031
|
);
|
|
6071
6032
|
const priceOracleDatum = parsePriceOracleDatum(
|
|
6072
6033
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
6073
6034
|
);
|
|
6074
|
-
const iassetUtxo =
|
|
6075
|
-
|
|
6076
|
-
|
|
6035
|
+
const iassetUtxo = await resolveUtxo(
|
|
6036
|
+
iasset,
|
|
6037
|
+
lucid,
|
|
6038
|
+
"Expected a single IAsset UTXO"
|
|
6077
6039
|
);
|
|
6078
6040
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
6079
6041
|
getInlineDatumOrThrow(iassetUtxo)
|
|
@@ -6194,7 +6156,7 @@ async function leverageCdpWithLrp(leverage, baseCollateral, priceOracleOutRef, i
|
|
|
6194
6156
|
2n
|
|
6195
6157
|
);
|
|
6196
6158
|
if (debtMintingFee > 0) {
|
|
6197
|
-
await collectorFeeTx(debtMintingFee, lucid, sysParams, tx,
|
|
6159
|
+
await collectorFeeTx(debtMintingFee, lucid, sysParams, tx, collector);
|
|
6198
6160
|
}
|
|
6199
6161
|
return tx;
|
|
6200
6162
|
}
|
|
@@ -6378,6 +6340,7 @@ async function leverageCdpWithLrp(leverage, baseCollateral, priceOracleOutRef, i
|
|
|
6378
6340
|
randomLrpsSubsetSatisfyingTargetLovelaces,
|
|
6379
6341
|
redeemCdp,
|
|
6380
6342
|
redeemLrp,
|
|
6343
|
+
resolveUtxo,
|
|
6381
6344
|
rewardSnapshotPrecision,
|
|
6382
6345
|
runCreateScriptRefTx,
|
|
6383
6346
|
runOneShotMintTx,
|