@indigo-labs/indigo-sdk 0.2.22 → 0.2.24
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.js +27 -20
- package/dist/index.mjs +42 -36
- package/package.json +1 -1
- package/src/contracts/gov/transactions.ts +3 -1
- package/src/contracts/price-oracle/helpers.ts +1 -1
- package/src/contracts/staking/transactions.ts +25 -27
- package/src/contracts/treasury/transactions.ts +7 -1
- package/tests/endpoints/initialize.ts +2 -2
- package/tests/gov.test.ts +55 -0
package/dist/index.js
CHANGED
|
@@ -862,7 +862,7 @@ function computeInterestLovelacesFor100PercentCR(collateral, mintedAmt, price) {
|
|
|
862
862
|
// src/contracts/price-oracle/helpers.ts
|
|
863
863
|
var import_lucid10 = require("@lucid-evolution/lucid");
|
|
864
864
|
function oracleExpirationAwareValidity(currentSlot, biasTime, oracleExpiration, network) {
|
|
865
|
-
const validateFrom = (0, import_lucid10.slotToUnixTime)(network, currentSlot - 1) - Math.min(120 * ONE_SECOND, biasTime);
|
|
865
|
+
const validateFrom = (0, import_lucid10.slotToUnixTime)(network, currentSlot - 1) - Math.min(120 * ONE_SECOND, biasTime - ONE_SECOND);
|
|
866
866
|
const defaultValidateTo = validateFrom + biasTime;
|
|
867
867
|
const cappedValidateTo = (0, import_lucid10.slotToUnixTime)(
|
|
868
868
|
network,
|
|
@@ -1489,6 +1489,7 @@ function serialiseTreasuryRedeemer(redeemer) {
|
|
|
1489
1489
|
|
|
1490
1490
|
// src/contracts/treasury/transactions.ts
|
|
1491
1491
|
async function treasuryFeeTx(fee, lucid, sysParams, tx, treasuryOref) {
|
|
1492
|
+
if (fee <= 0n) return;
|
|
1492
1493
|
const treasuryUtxo = matchSingle(
|
|
1493
1494
|
await lucid.utxosByOutRef([treasuryOref]),
|
|
1494
1495
|
(_) => new Error("Expected a single treasury UTXO")
|
|
@@ -1501,8 +1502,9 @@ async function treasuryFeeTx(fee, lucid, sysParams, tx, treasuryOref) {
|
|
|
1501
1502
|
]),
|
|
1502
1503
|
(_) => new Error("Expected a single treasury Ref Script UTXO")
|
|
1503
1504
|
);
|
|
1505
|
+
const stakeCredential = sysParams.treasuryParams.treasuryUtxosStakeCredential ? fromSysParamsScriptCredential(sysParams.treasuryParams.treasuryUtxosStakeCredential) : void 0;
|
|
1504
1506
|
tx.readFrom([treasuryRefScriptUtxo]).collectFrom([treasuryUtxo], serialiseTreasuryRedeemer("CollectAda")).pay.ToContract(
|
|
1505
|
-
|
|
1507
|
+
createScriptAddress(lucid.config().network, sysParams.validatorHashes.treasuryHash, stakeCredential),
|
|
1506
1508
|
{ kind: "inline", value: import_lucid17.Data.void() },
|
|
1507
1509
|
(0, import_lucid17.addAssets)(treasuryUtxo.assets, mkLovelacesOf(fee))
|
|
1508
1510
|
);
|
|
@@ -4800,7 +4802,12 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4800
4802
|
};
|
|
4801
4803
|
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingToken[1].unTokenName);
|
|
4802
4804
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
4803
|
-
return lucid.newTx().collectFrom(
|
|
4805
|
+
return lucid.newTx().collectFrom(
|
|
4806
|
+
[stakingManagerOut.utxo],
|
|
4807
|
+
serialiseStakingRedeemer({
|
|
4808
|
+
CreateStakingPosition: { creatorPkh: pkh.hash }
|
|
4809
|
+
})
|
|
4810
|
+
).readFrom([stakingRefScriptUtxo]).pay.ToContract(
|
|
4804
4811
|
stakingManagerOut.utxo.address,
|
|
4805
4812
|
{
|
|
4806
4813
|
kind: "inline",
|
|
@@ -4826,7 +4833,7 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4826
4833
|
}
|
|
4827
4834
|
async function adjustStakingPosition(stakingPositionRef, amount, params, lucid, currentSlot, stakingManagerRef) {
|
|
4828
4835
|
const network = lucid.config().network;
|
|
4829
|
-
const currentTime = (0, import_lucid35.slotToUnixTime)(network, currentSlot) - ONE_SECOND;
|
|
4836
|
+
const currentTime = (0, import_lucid35.slotToUnixTime)(network, currentSlot) - 120 * ONE_SECOND;
|
|
4830
4837
|
const stakingPositionOut = await findStakingPositionByOutRef(
|
|
4831
4838
|
stakingPositionRef,
|
|
4832
4839
|
lucid
|
|
@@ -4838,8 +4845,6 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4838
4845
|
]),
|
|
4839
4846
|
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
4840
4847
|
);
|
|
4841
|
-
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingToken[1].unTokenName);
|
|
4842
|
-
const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingManagerNFT[1].unTokenName);
|
|
4843
4848
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
4844
4849
|
const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
|
|
4845
4850
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
@@ -4866,10 +4871,7 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4866
4871
|
totalStake: stakingManagerOut.datum.totalStake + amount
|
|
4867
4872
|
})
|
|
4868
4873
|
},
|
|
4869
|
-
|
|
4870
|
-
lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
|
|
4871
|
-
[stakingManagerToken]: 1n
|
|
4872
|
-
}
|
|
4874
|
+
(0, import_lucid35.addAssets)(stakingManagerOut.utxo.assets, mkLovelacesOf(-adaReward))
|
|
4873
4875
|
).pay.ToContract(
|
|
4874
4876
|
stakingPositionOut.utxo.address,
|
|
4875
4877
|
{
|
|
@@ -4879,10 +4881,16 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4879
4881
|
lockedAmount: newLockedAmount
|
|
4880
4882
|
})
|
|
4881
4883
|
},
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4884
|
+
(0, import_lucid35.addAssets)(
|
|
4885
|
+
stakingPositionOut.utxo.assets,
|
|
4886
|
+
mkAssetsOf(
|
|
4887
|
+
{
|
|
4888
|
+
currencySymbol: params.stakingParams.indyToken[0].unCurrencySymbol,
|
|
4889
|
+
tokenName: (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName)
|
|
4890
|
+
},
|
|
4891
|
+
amount
|
|
4892
|
+
)
|
|
4893
|
+
)
|
|
4886
4894
|
).addSignerKey((0, import_lucid35.toHex)(stakingPositionOut.datum.owner));
|
|
4887
4895
|
}
|
|
4888
4896
|
async function closeStakingPosition(stakingPositionRef, params, lucid, currentSlot, stakingManagerRef) {
|
|
@@ -4908,13 +4916,15 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
4908
4916
|
(_) => new Error("Expected a single staking token policy Ref Script UTXO")
|
|
4909
4917
|
);
|
|
4910
4918
|
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingToken[1].unTokenName);
|
|
4911
|
-
const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingManagerNFT[1].unTokenName);
|
|
4912
4919
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
4913
4920
|
const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
|
|
4914
4921
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
4915
4922
|
const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
|
|
4916
4923
|
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
|
|
4917
|
-
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo],
|
|
4924
|
+
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom(
|
|
4925
|
+
[stakingManagerOut.utxo],
|
|
4926
|
+
serialiseStakingRedeemer("UpdateTotalStake")
|
|
4927
|
+
).pay.ToContract(
|
|
4918
4928
|
stakingManagerOut.utxo.address,
|
|
4919
4929
|
{
|
|
4920
4930
|
kind: "inline",
|
|
@@ -4923,10 +4933,7 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
4923
4933
|
totalStake: stakingManagerOut.datum.totalStake - existingIndyAmount
|
|
4924
4934
|
})
|
|
4925
4935
|
},
|
|
4926
|
-
|
|
4927
|
-
lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
|
|
4928
|
-
[stakingManagerToken]: 1n
|
|
4929
|
-
}
|
|
4936
|
+
(0, import_lucid35.addAssets)(stakingManagerOut.utxo.assets, mkLovelacesOf(-adaReward))
|
|
4930
4937
|
).mintAssets(
|
|
4931
4938
|
{
|
|
4932
4939
|
[stakingToken]: -1n
|
package/dist/index.mjs
CHANGED
|
@@ -628,7 +628,7 @@ import {
|
|
|
628
628
|
unixTimeToSlot
|
|
629
629
|
} from "@lucid-evolution/lucid";
|
|
630
630
|
function oracleExpirationAwareValidity(currentSlot, biasTime, oracleExpiration, network) {
|
|
631
|
-
const validateFrom = slotToUnixTime(network, currentSlot - 1) - Math.min(120 * ONE_SECOND, biasTime);
|
|
631
|
+
const validateFrom = slotToUnixTime(network, currentSlot - 1) - Math.min(120 * ONE_SECOND, biasTime - ONE_SECOND);
|
|
632
632
|
const defaultValidateTo = validateFrom + biasTime;
|
|
633
633
|
const cappedValidateTo = slotToUnixTime(
|
|
634
634
|
network,
|
|
@@ -1260,6 +1260,7 @@ function serialiseTreasuryRedeemer(redeemer) {
|
|
|
1260
1260
|
|
|
1261
1261
|
// src/contracts/treasury/transactions.ts
|
|
1262
1262
|
async function treasuryFeeTx(fee, lucid, sysParams, tx, treasuryOref) {
|
|
1263
|
+
if (fee <= 0n) return;
|
|
1263
1264
|
const treasuryUtxo = matchSingle(
|
|
1264
1265
|
await lucid.utxosByOutRef([treasuryOref]),
|
|
1265
1266
|
(_) => new Error("Expected a single treasury UTXO")
|
|
@@ -1272,8 +1273,9 @@ async function treasuryFeeTx(fee, lucid, sysParams, tx, treasuryOref) {
|
|
|
1272
1273
|
]),
|
|
1273
1274
|
(_) => new Error("Expected a single treasury Ref Script UTXO")
|
|
1274
1275
|
);
|
|
1276
|
+
const stakeCredential = sysParams.treasuryParams.treasuryUtxosStakeCredential ? fromSysParamsScriptCredential(sysParams.treasuryParams.treasuryUtxosStakeCredential) : void 0;
|
|
1275
1277
|
tx.readFrom([treasuryRefScriptUtxo]).collectFrom([treasuryUtxo], serialiseTreasuryRedeemer("CollectAda")).pay.ToContract(
|
|
1276
|
-
|
|
1278
|
+
createScriptAddress(lucid.config().network, sysParams.validatorHashes.treasuryHash, stakeCredential),
|
|
1277
1279
|
{ kind: "inline", value: Data12.void() },
|
|
1278
1280
|
addAssets2(treasuryUtxo.assets, mkLovelacesOf(fee))
|
|
1279
1281
|
);
|
|
@@ -4574,7 +4576,6 @@ async function annulRequest(accountUtxo, params, lucid) {
|
|
|
4574
4576
|
// src/contracts/staking/transactions.ts
|
|
4575
4577
|
import {
|
|
4576
4578
|
addAssets as addAssets6,
|
|
4577
|
-
Constr as Constr3,
|
|
4578
4579
|
Data as Data22,
|
|
4579
4580
|
fromHex as fromHex3,
|
|
4580
4581
|
fromText as fromText6,
|
|
@@ -4613,7 +4614,12 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4613
4614
|
};
|
|
4614
4615
|
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + fromText6(params.stakingParams.stakingToken[1].unTokenName);
|
|
4615
4616
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText6(params.stakingParams.indyToken[1].unTokenName);
|
|
4616
|
-
return lucid.newTx().collectFrom(
|
|
4617
|
+
return lucid.newTx().collectFrom(
|
|
4618
|
+
[stakingManagerOut.utxo],
|
|
4619
|
+
serialiseStakingRedeemer({
|
|
4620
|
+
CreateStakingPosition: { creatorPkh: pkh.hash }
|
|
4621
|
+
})
|
|
4622
|
+
).readFrom([stakingRefScriptUtxo]).pay.ToContract(
|
|
4617
4623
|
stakingManagerOut.utxo.address,
|
|
4618
4624
|
{
|
|
4619
4625
|
kind: "inline",
|
|
@@ -4639,7 +4645,7 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4639
4645
|
}
|
|
4640
4646
|
async function adjustStakingPosition(stakingPositionRef, amount, params, lucid, currentSlot, stakingManagerRef) {
|
|
4641
4647
|
const network = lucid.config().network;
|
|
4642
|
-
const currentTime = slotToUnixTime5(network, currentSlot) - ONE_SECOND;
|
|
4648
|
+
const currentTime = slotToUnixTime5(network, currentSlot) - 120 * ONE_SECOND;
|
|
4643
4649
|
const stakingPositionOut = await findStakingPositionByOutRef(
|
|
4644
4650
|
stakingPositionRef,
|
|
4645
4651
|
lucid
|
|
@@ -4651,8 +4657,6 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4651
4657
|
]),
|
|
4652
4658
|
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
4653
4659
|
);
|
|
4654
|
-
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + fromText6(params.stakingParams.stakingToken[1].unTokenName);
|
|
4655
|
-
const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + fromText6(params.stakingParams.stakingManagerNFT[1].unTokenName);
|
|
4656
4660
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText6(params.stakingParams.indyToken[1].unTokenName);
|
|
4657
4661
|
const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
|
|
4658
4662
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
@@ -4679,10 +4683,7 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4679
4683
|
totalStake: stakingManagerOut.datum.totalStake + amount
|
|
4680
4684
|
})
|
|
4681
4685
|
},
|
|
4682
|
-
|
|
4683
|
-
lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
|
|
4684
|
-
[stakingManagerToken]: 1n
|
|
4685
|
-
}
|
|
4686
|
+
addAssets6(stakingManagerOut.utxo.assets, mkLovelacesOf(-adaReward))
|
|
4686
4687
|
).pay.ToContract(
|
|
4687
4688
|
stakingPositionOut.utxo.address,
|
|
4688
4689
|
{
|
|
@@ -4692,10 +4693,16 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4692
4693
|
lockedAmount: newLockedAmount
|
|
4693
4694
|
})
|
|
4694
4695
|
},
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4696
|
+
addAssets6(
|
|
4697
|
+
stakingPositionOut.utxo.assets,
|
|
4698
|
+
mkAssetsOf(
|
|
4699
|
+
{
|
|
4700
|
+
currencySymbol: params.stakingParams.indyToken[0].unCurrencySymbol,
|
|
4701
|
+
tokenName: fromText6(params.stakingParams.indyToken[1].unTokenName)
|
|
4702
|
+
},
|
|
4703
|
+
amount
|
|
4704
|
+
)
|
|
4705
|
+
)
|
|
4699
4706
|
).addSignerKey(toHex2(stakingPositionOut.datum.owner));
|
|
4700
4707
|
}
|
|
4701
4708
|
async function closeStakingPosition(stakingPositionRef, params, lucid, currentSlot, stakingManagerRef) {
|
|
@@ -4721,13 +4728,15 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
4721
4728
|
(_) => new Error("Expected a single staking token policy Ref Script UTXO")
|
|
4722
4729
|
);
|
|
4723
4730
|
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + fromText6(params.stakingParams.stakingToken[1].unTokenName);
|
|
4724
|
-
const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + fromText6(params.stakingParams.stakingManagerNFT[1].unTokenName);
|
|
4725
4731
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText6(params.stakingParams.indyToken[1].unTokenName);
|
|
4726
4732
|
const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
|
|
4727
4733
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
4728
4734
|
const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
|
|
4729
4735
|
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
|
|
4730
|
-
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo],
|
|
4736
|
+
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom(
|
|
4737
|
+
[stakingManagerOut.utxo],
|
|
4738
|
+
serialiseStakingRedeemer("UpdateTotalStake")
|
|
4739
|
+
).pay.ToContract(
|
|
4731
4740
|
stakingManagerOut.utxo.address,
|
|
4732
4741
|
{
|
|
4733
4742
|
kind: "inline",
|
|
@@ -4736,10 +4745,7 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
4736
4745
|
totalStake: stakingManagerOut.datum.totalStake - existingIndyAmount
|
|
4737
4746
|
})
|
|
4738
4747
|
},
|
|
4739
|
-
|
|
4740
|
-
lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
|
|
4741
|
-
[stakingManagerToken]: 1n
|
|
4742
|
-
}
|
|
4748
|
+
addAssets6(stakingManagerOut.utxo.assets, mkLovelacesOf(-adaReward))
|
|
4743
4749
|
).mintAssets(
|
|
4744
4750
|
{
|
|
4745
4751
|
[stakingToken]: -1n
|
|
@@ -4812,7 +4818,7 @@ import {
|
|
|
4812
4818
|
// src/contracts/one-shot/transactions.ts
|
|
4813
4819
|
import {
|
|
4814
4820
|
addAssets as addAssets7,
|
|
4815
|
-
Constr as
|
|
4821
|
+
Constr as Constr3,
|
|
4816
4822
|
Data as Data24,
|
|
4817
4823
|
mintingPolicyToId,
|
|
4818
4824
|
toUnit as toUnit2
|
|
@@ -4881,7 +4887,7 @@ async function oneShotMintTx(lucid, params) {
|
|
|
4881
4887
|
[toUnit2(policyId, entry.tokenName)]: entry.amount
|
|
4882
4888
|
})
|
|
4883
4889
|
)(params.mintAmounts),
|
|
4884
|
-
Data24.to(new
|
|
4890
|
+
Data24.to(new Constr3(0, []))
|
|
4885
4891
|
).attach.MintingPolicy(oneShotPolicy),
|
|
4886
4892
|
policyId
|
|
4887
4893
|
];
|
|
@@ -5062,7 +5068,7 @@ var mkVersionRegistryValidator = () => {
|
|
|
5062
5068
|
// src/contracts/collector/scripts.ts
|
|
5063
5069
|
import {
|
|
5064
5070
|
applyParamsToScript as applyParamsToScript9,
|
|
5065
|
-
Constr as
|
|
5071
|
+
Constr as Constr4,
|
|
5066
5072
|
fromText as fromText8
|
|
5067
5073
|
} from "@lucid-evolution/lucid";
|
|
5068
5074
|
|
|
@@ -5078,16 +5084,16 @@ var mkCollectorValidatorFromSP = (params) => {
|
|
|
5078
5084
|
return {
|
|
5079
5085
|
type: "PlutusV2",
|
|
5080
5086
|
script: applyParamsToScript9(_collectorValidator.cborHex, [
|
|
5081
|
-
new
|
|
5082
|
-
new
|
|
5087
|
+
new Constr4(0, [
|
|
5088
|
+
new Constr4(0, [
|
|
5083
5089
|
params.stakingManagerNFT[0].unCurrencySymbol,
|
|
5084
5090
|
fromText8(params.stakingManagerNFT[1].unTokenName)
|
|
5085
5091
|
]),
|
|
5086
|
-
new
|
|
5092
|
+
new Constr4(0, [
|
|
5087
5093
|
params.stakingToken[0].unCurrencySymbol,
|
|
5088
5094
|
fromText8(params.stakingToken[1].unTokenName)
|
|
5089
5095
|
]),
|
|
5090
|
-
new
|
|
5096
|
+
new Constr4(0, [
|
|
5091
5097
|
params.versionRecordToken[0].unCurrencySymbol,
|
|
5092
5098
|
fromText8(params.versionRecordToken[1].unTokenName)
|
|
5093
5099
|
])
|
|
@@ -5099,7 +5105,7 @@ var mkCollectorValidatorFromSP = (params) => {
|
|
|
5099
5105
|
// src/contracts/treasury/scripts.ts
|
|
5100
5106
|
import {
|
|
5101
5107
|
applyParamsToScript as applyParamsToScript10,
|
|
5102
|
-
Constr as
|
|
5108
|
+
Constr as Constr5,
|
|
5103
5109
|
fromText as fromText9
|
|
5104
5110
|
} from "@lucid-evolution/lucid";
|
|
5105
5111
|
|
|
@@ -5115,22 +5121,22 @@ var mkTreasuryValidatorFromSP = (params) => {
|
|
|
5115
5121
|
return {
|
|
5116
5122
|
type: "PlutusV2",
|
|
5117
5123
|
script: applyParamsToScript10(_treasuryValidator.cborHex, [
|
|
5118
|
-
new
|
|
5119
|
-
new
|
|
5124
|
+
new Constr5(0, [
|
|
5125
|
+
new Constr5(0, [
|
|
5120
5126
|
params.upgradeToken[0].unCurrencySymbol,
|
|
5121
5127
|
fromText9(params.upgradeToken[1].unTokenName)
|
|
5122
5128
|
]),
|
|
5123
|
-
new
|
|
5129
|
+
new Constr5(0, [
|
|
5124
5130
|
params.versionRecordToken[0].unCurrencySymbol,
|
|
5125
5131
|
fromText9(params.versionRecordToken[1].unTokenName)
|
|
5126
5132
|
]),
|
|
5127
|
-
params.treasuryUtxosStakeCredential ? new
|
|
5128
|
-
new
|
|
5129
|
-
new
|
|
5133
|
+
params.treasuryUtxosStakeCredential ? new Constr5(0, [
|
|
5134
|
+
new Constr5(0, [
|
|
5135
|
+
new Constr5(1, [
|
|
5130
5136
|
params.treasuryUtxosStakeCredential.contents.contents
|
|
5131
5137
|
])
|
|
5132
5138
|
])
|
|
5133
|
-
]) : new
|
|
5139
|
+
]) : new Constr5(1, [])
|
|
5134
5140
|
])
|
|
5135
5141
|
])
|
|
5136
5142
|
};
|
package/package.json
CHANGED
|
@@ -446,7 +446,9 @@ export async function vote(
|
|
|
446
446
|
fromSystemParamsAsset(sysParams.govParams.indyAsset),
|
|
447
447
|
);
|
|
448
448
|
|
|
449
|
-
const validityFrom =
|
|
449
|
+
const validityFrom =
|
|
450
|
+
Number(currentTime) -
|
|
451
|
+
Math.min(120 * ONE_SECOND, Number(sysParams.govParams.gBiasTime));
|
|
450
452
|
|
|
451
453
|
if (stakingPosDatum.lockedAmount.has(pollShardDatum.pollId)) {
|
|
452
454
|
throw new Error('Already voted for that proposal.');
|
|
@@ -20,7 +20,7 @@ export function oracleExpirationAwareValidity(
|
|
|
20
20
|
} {
|
|
21
21
|
const validateFrom =
|
|
22
22
|
slotToUnixTime(network, currentSlot - 1) -
|
|
23
|
-
Math.min(120 * ONE_SECOND, biasTime);
|
|
23
|
+
Math.min(120 * ONE_SECOND, biasTime - ONE_SECOND);
|
|
24
24
|
const defaultValidateTo = validateFrom + biasTime;
|
|
25
25
|
/// Take the oracle expiration time - 1 slot which is the last acceptable non-expired valid_to time
|
|
26
26
|
/// for the current oracle.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
addAssets,
|
|
3
|
-
Constr,
|
|
4
3
|
Data,
|
|
5
4
|
fromHex,
|
|
6
5
|
fromText,
|
|
@@ -32,7 +31,7 @@ import {
|
|
|
32
31
|
import { matchSingle } from '../../utils/utils';
|
|
33
32
|
import { serialiseStakingRedeemer } from './types';
|
|
34
33
|
import { serialiseCollectorRedeemer } from '../collector/types';
|
|
35
|
-
import { mkLovelacesOf } from '../../utils/value-helpers';
|
|
34
|
+
import { mkAssetsOf, mkLovelacesOf } from '../../utils/value-helpers';
|
|
36
35
|
import { ONE_SECOND } from '../../utils/time-helpers';
|
|
37
36
|
|
|
38
37
|
export async function openStakingPosition(
|
|
@@ -85,7 +84,12 @@ export async function openStakingPosition(
|
|
|
85
84
|
fromText(params.stakingParams.indyToken[1].unTokenName);
|
|
86
85
|
return lucid
|
|
87
86
|
.newTx()
|
|
88
|
-
.collectFrom(
|
|
87
|
+
.collectFrom(
|
|
88
|
+
[stakingManagerOut.utxo],
|
|
89
|
+
serialiseStakingRedeemer({
|
|
90
|
+
CreateStakingPosition: { creatorPkh: pkh.hash },
|
|
91
|
+
}),
|
|
92
|
+
)
|
|
89
93
|
.readFrom([stakingRefScriptUtxo])
|
|
90
94
|
.pay.ToContract(
|
|
91
95
|
stakingManagerOut.utxo.address,
|
|
@@ -125,7 +129,7 @@ export async function adjustStakingPosition(
|
|
|
125
129
|
stakingManagerRef?: OutRef,
|
|
126
130
|
): Promise<TxBuilder> {
|
|
127
131
|
const network = lucid.config().network!;
|
|
128
|
-
const currentTime = slotToUnixTime(network, currentSlot) - ONE_SECOND;
|
|
132
|
+
const currentTime = slotToUnixTime(network, currentSlot) - 120 * ONE_SECOND;
|
|
129
133
|
|
|
130
134
|
const stakingPositionOut = await findStakingPositionByOutRef(
|
|
131
135
|
stakingPositionRef,
|
|
@@ -142,12 +146,6 @@ export async function adjustStakingPosition(
|
|
|
142
146
|
(_) => new Error('Expected a single staking Ref Script UTXO'),
|
|
143
147
|
);
|
|
144
148
|
|
|
145
|
-
const stakingToken =
|
|
146
|
-
params.stakingParams.stakingToken[0].unCurrencySymbol +
|
|
147
|
-
fromText(params.stakingParams.stakingToken[1].unTokenName);
|
|
148
|
-
const stakingManagerToken =
|
|
149
|
-
params.stakingParams.stakingManagerNFT[0].unCurrencySymbol +
|
|
150
|
-
fromText(params.stakingParams.stakingManagerNFT[1].unTokenName);
|
|
151
149
|
const indyToken =
|
|
152
150
|
params.stakingParams.indyToken[0].unCurrencySymbol +
|
|
153
151
|
fromText(params.stakingParams.indyToken[1].unTokenName);
|
|
@@ -188,10 +186,7 @@ export async function adjustStakingPosition(
|
|
|
188
186
|
totalStake: stakingManagerOut.datum.totalStake + amount,
|
|
189
187
|
}),
|
|
190
188
|
},
|
|
191
|
-
|
|
192
|
-
lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
|
|
193
|
-
[stakingManagerToken]: 1n,
|
|
194
|
-
},
|
|
189
|
+
addAssets(stakingManagerOut.utxo.assets, mkLovelacesOf(-adaReward)),
|
|
195
190
|
)
|
|
196
191
|
.pay.ToContract(
|
|
197
192
|
stakingPositionOut.utxo.address,
|
|
@@ -202,10 +197,16 @@ export async function adjustStakingPosition(
|
|
|
202
197
|
lockedAmount: newLockedAmount,
|
|
203
198
|
}),
|
|
204
199
|
},
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
200
|
+
addAssets(
|
|
201
|
+
stakingPositionOut.utxo.assets,
|
|
202
|
+
mkAssetsOf(
|
|
203
|
+
{
|
|
204
|
+
currencySymbol: params.stakingParams.indyToken[0].unCurrencySymbol,
|
|
205
|
+
tokenName: fromText(params.stakingParams.indyToken[1].unTokenName),
|
|
206
|
+
},
|
|
207
|
+
amount,
|
|
208
|
+
),
|
|
209
|
+
),
|
|
209
210
|
)
|
|
210
211
|
.addSignerKey(toHex(stakingPositionOut.datum.owner));
|
|
211
212
|
}
|
|
@@ -246,9 +247,6 @@ export async function closeStakingPosition(
|
|
|
246
247
|
const stakingToken =
|
|
247
248
|
params.stakingParams.stakingToken[0].unCurrencySymbol +
|
|
248
249
|
fromText(params.stakingParams.stakingToken[1].unTokenName);
|
|
249
|
-
const stakingManagerToken =
|
|
250
|
-
params.stakingParams.stakingManagerNFT[0].unCurrencySymbol +
|
|
251
|
-
fromText(params.stakingParams.stakingManagerNFT[1].unTokenName);
|
|
252
250
|
const indyToken =
|
|
253
251
|
params.stakingParams.indyToken[0].unCurrencySymbol +
|
|
254
252
|
fromText(params.stakingParams.indyToken[1].unTokenName);
|
|
@@ -265,8 +263,11 @@ export async function closeStakingPosition(
|
|
|
265
263
|
.newTx()
|
|
266
264
|
.validFrom(currentTime)
|
|
267
265
|
.readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo])
|
|
268
|
-
.collectFrom([stakingPositionOut.utxo],
|
|
269
|
-
.collectFrom(
|
|
266
|
+
.collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer('Unstake'))
|
|
267
|
+
.collectFrom(
|
|
268
|
+
[stakingManagerOut.utxo],
|
|
269
|
+
serialiseStakingRedeemer('UpdateTotalStake'),
|
|
270
|
+
)
|
|
270
271
|
.pay.ToContract(
|
|
271
272
|
stakingManagerOut.utxo.address,
|
|
272
273
|
{
|
|
@@ -276,10 +277,7 @@ export async function closeStakingPosition(
|
|
|
276
277
|
totalStake: stakingManagerOut.datum.totalStake - existingIndyAmount,
|
|
277
278
|
}),
|
|
278
279
|
},
|
|
279
|
-
|
|
280
|
-
lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
|
|
281
|
-
[stakingManagerToken]: 1n,
|
|
282
|
-
},
|
|
280
|
+
addAssets(stakingManagerOut.utxo.assets, mkLovelacesOf(-adaReward)),
|
|
283
281
|
)
|
|
284
282
|
.mintAssets(
|
|
285
283
|
{
|
|
@@ -6,12 +6,14 @@ import {
|
|
|
6
6
|
TxBuilder,
|
|
7
7
|
} from '@lucid-evolution/lucid';
|
|
8
8
|
import {
|
|
9
|
+
fromSysParamsScriptCredential,
|
|
9
10
|
fromSystemParamsScriptRef,
|
|
10
11
|
SystemParams,
|
|
11
12
|
} from '../../types/system-params';
|
|
12
13
|
import { matchSingle } from '../../utils/utils';
|
|
13
14
|
import { mkLovelacesOf } from '../../utils/value-helpers';
|
|
14
15
|
import { serialiseTreasuryRedeemer } from './types';
|
|
16
|
+
import { createScriptAddress } from '../../utils/lucid-utils';
|
|
15
17
|
|
|
16
18
|
export async function treasuryFeeTx(
|
|
17
19
|
fee: bigint,
|
|
@@ -20,6 +22,8 @@ export async function treasuryFeeTx(
|
|
|
20
22
|
tx: TxBuilder,
|
|
21
23
|
treasuryOref: OutRef,
|
|
22
24
|
): Promise<void> {
|
|
25
|
+
if (fee <= 0n) return;
|
|
26
|
+
|
|
23
27
|
const treasuryUtxo = matchSingle(
|
|
24
28
|
await lucid.utxosByOutRef([treasuryOref]),
|
|
25
29
|
(_) => new Error('Expected a single treasury UTXO'),
|
|
@@ -34,10 +38,12 @@ export async function treasuryFeeTx(
|
|
|
34
38
|
(_) => new Error('Expected a single treasury Ref Script UTXO'),
|
|
35
39
|
);
|
|
36
40
|
|
|
41
|
+
const stakeCredential = sysParams.treasuryParams.treasuryUtxosStakeCredential ? fromSysParamsScriptCredential(sysParams.treasuryParams.treasuryUtxosStakeCredential) : undefined;
|
|
42
|
+
|
|
37
43
|
tx.readFrom([treasuryRefScriptUtxo])
|
|
38
44
|
.collectFrom([treasuryUtxo], serialiseTreasuryRedeemer('CollectAda'))
|
|
39
45
|
.pay.ToContract(
|
|
40
|
-
|
|
46
|
+
createScriptAddress(lucid.config().network!, sysParams.validatorHashes.treasuryHash, stakeCredential),
|
|
41
47
|
{ kind: 'inline', value: Data.void() },
|
|
42
48
|
addAssets(treasuryUtxo.assets, mkLovelacesOf(fee)),
|
|
43
49
|
);
|
|
@@ -666,7 +666,7 @@ export async function init(
|
|
|
666
666
|
govNFT: toSystemParamsAsset(govNftAsset),
|
|
667
667
|
minCollateralInLovelace: 10_000_000,
|
|
668
668
|
partialRedemptionExtraFeeLovelace: 10_000_000,
|
|
669
|
-
biasTime:
|
|
669
|
+
biasTime: 180_000,
|
|
670
670
|
treasuryValHash: treasuryValHash,
|
|
671
671
|
};
|
|
672
672
|
const cdpValHash = validatorToScriptHash(mkCdpValidatorFromSP(cdpParams));
|
|
@@ -680,7 +680,7 @@ export async function init(
|
|
|
680
680
|
cdpScriptHash: cdpValHash,
|
|
681
681
|
collectorValHash: collectorValHash,
|
|
682
682
|
minCollateralInLovelace: 10_000_000,
|
|
683
|
-
biasTime:
|
|
683
|
+
biasTime: 180_000n,
|
|
684
684
|
};
|
|
685
685
|
const cdpCreatorValidator = mkCDPCreatorValidatorFromSP(cdpCreatorParams);
|
|
686
686
|
const cdpCreatorValHash = validatorToScriptHash(cdpCreatorValidator);
|
package/tests/gov.test.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { findGov } from './queries/governance-queries';
|
|
|
21
21
|
import {
|
|
22
22
|
addrDetails,
|
|
23
23
|
addressFromBech32,
|
|
24
|
+
adjustStakingPosition,
|
|
24
25
|
createProposal,
|
|
25
26
|
createScriptAddress,
|
|
26
27
|
createShardsChunks,
|
|
@@ -530,6 +531,60 @@ describe('Gov', () => {
|
|
|
530
531
|
await runVote(pollId, 'Yes', sysParams, context);
|
|
531
532
|
});
|
|
532
533
|
|
|
534
|
+
test<MyContext>('Vote on proposal, then deposit more INDY', async (context: MyContext) => {
|
|
535
|
+
context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
|
|
536
|
+
|
|
537
|
+
const [sysParams, _] = await init(context.lucid, [iusdInitialAssetCfg]);
|
|
538
|
+
|
|
539
|
+
const govUtxo = await findGov(
|
|
540
|
+
context.lucid,
|
|
541
|
+
sysParams.validatorHashes.govHash,
|
|
542
|
+
fromSystemParamsAsset(sysParams.govParams.govNFT),
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
const [tx, pollId] = await createProposal(
|
|
546
|
+
{ TextProposal: { bytes: fromText('smth') } },
|
|
547
|
+
null,
|
|
548
|
+
sysParams,
|
|
549
|
+
context.lucid,
|
|
550
|
+
context.emulator.slot,
|
|
551
|
+
govUtxo.utxo,
|
|
552
|
+
[],
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
await runAndAwaitTxBuilder(context.lucid, tx);
|
|
556
|
+
|
|
557
|
+
await runCreateAllShards(pollId, sysParams, context);
|
|
558
|
+
|
|
559
|
+
await runAndAwaitTx(
|
|
560
|
+
context.lucid,
|
|
561
|
+
openStakingPosition(1_000_000n, sysParams, context.lucid),
|
|
562
|
+
);
|
|
563
|
+
|
|
564
|
+
await runVote(pollId, 'Yes', sysParams, context);
|
|
565
|
+
|
|
566
|
+
const [pkh, _skh] = await addrDetails(context.lucid);
|
|
567
|
+
const stakingPosUtxo = await findStakingPosition(
|
|
568
|
+
context.lucid,
|
|
569
|
+
sysParams.validatorHashes.stakingHash,
|
|
570
|
+
fromSystemParamsAsset(sysParams.stakingParams.stakingToken),
|
|
571
|
+
pkh.hash,
|
|
572
|
+
);
|
|
573
|
+
|
|
574
|
+
context.emulator.awaitSlot(60);
|
|
575
|
+
|
|
576
|
+
await runAndAwaitTx(
|
|
577
|
+
context.lucid,
|
|
578
|
+
adjustStakingPosition(
|
|
579
|
+
stakingPosUtxo.utxo,
|
|
580
|
+
500_000_000n,
|
|
581
|
+
sysParams,
|
|
582
|
+
context.lucid,
|
|
583
|
+
context.emulator.slot,
|
|
584
|
+
),
|
|
585
|
+
);
|
|
586
|
+
});
|
|
587
|
+
|
|
533
588
|
test<MyContext>('Vote on 2 proposals sequentially (lower pollID first)', async (context: MyContext) => {
|
|
534
589
|
context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
|
|
535
590
|
|