@indigo-labs/indigo-sdk 0.2.21 → 0.2.23
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 +8 -20
- package/dist/index.mjs +8 -21
- package/package.json +1 -1
- package/src/contracts/gov/transactions.ts +1 -1
- package/src/contracts/price-oracle/helpers.ts +1 -1
- package/src/contracts/staking/transactions.ts +8 -26
- package/tests/endpoints/initialize.ts +2 -2
- package/tests/gov.test.ts +49 -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,
|
|
@@ -3563,7 +3563,7 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
|
|
|
3563
3563
|
stakingPosUtxo.assets,
|
|
3564
3564
|
fromSystemParamsAsset(sysParams.govParams.indyAsset)
|
|
3565
3565
|
);
|
|
3566
|
-
const validityFrom = Number(currentTime) - ONE_SECOND;
|
|
3566
|
+
const validityFrom = Number(currentTime) - Math.min(120 * ONE_SECOND, Number(sysParams.govParams.gBiasTime));
|
|
3567
3567
|
if (stakingPosDatum.lockedAmount.has(pollShardDatum.pollId)) {
|
|
3568
3568
|
throw new Error("Already voted for that proposal.");
|
|
3569
3569
|
}
|
|
@@ -4800,7 +4800,7 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4800
4800
|
};
|
|
4801
4801
|
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingToken[1].unTokenName);
|
|
4802
4802
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
4803
|
-
return lucid.newTx().collectFrom([stakingManagerOut.utxo],
|
|
4803
|
+
return lucid.newTx().collectFrom([stakingManagerOut.utxo], serialiseStakingRedeemer({ CreateStakingPosition: { creatorPkh: pkh.hash } })).readFrom([stakingRefScriptUtxo]).pay.ToContract(
|
|
4804
4804
|
stakingManagerOut.utxo.address,
|
|
4805
4805
|
{
|
|
4806
4806
|
kind: "inline",
|
|
@@ -4826,7 +4826,7 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4826
4826
|
}
|
|
4827
4827
|
async function adjustStakingPosition(stakingPositionRef, amount, params, lucid, currentSlot, stakingManagerRef) {
|
|
4828
4828
|
const network = lucid.config().network;
|
|
4829
|
-
const currentTime = (0, import_lucid35.slotToUnixTime)(network, currentSlot) - ONE_SECOND;
|
|
4829
|
+
const currentTime = (0, import_lucid35.slotToUnixTime)(network, currentSlot) - 120 * ONE_SECOND;
|
|
4830
4830
|
const stakingPositionOut = await findStakingPositionByOutRef(
|
|
4831
4831
|
stakingPositionRef,
|
|
4832
4832
|
lucid
|
|
@@ -4838,8 +4838,6 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4838
4838
|
]),
|
|
4839
4839
|
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
4840
4840
|
);
|
|
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
4841
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
4844
4842
|
const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
|
|
4845
4843
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
@@ -4866,10 +4864,7 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4866
4864
|
totalStake: stakingManagerOut.datum.totalStake + amount
|
|
4867
4865
|
})
|
|
4868
4866
|
},
|
|
4869
|
-
|
|
4870
|
-
lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
|
|
4871
|
-
[stakingManagerToken]: 1n
|
|
4872
|
-
}
|
|
4867
|
+
(0, import_lucid35.addAssets)(stakingManagerOut.utxo.assets, mkLovelacesOf(-adaReward))
|
|
4873
4868
|
).pay.ToContract(
|
|
4874
4869
|
stakingPositionOut.utxo.address,
|
|
4875
4870
|
{
|
|
@@ -4879,10 +4874,7 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4879
4874
|
lockedAmount: newLockedAmount
|
|
4880
4875
|
})
|
|
4881
4876
|
},
|
|
4882
|
-
{
|
|
4883
|
-
[stakingToken]: 1n,
|
|
4884
|
-
[indyToken]: stakingPositionOut.utxo.assets[indyToken] + amount
|
|
4885
|
-
}
|
|
4877
|
+
(0, import_lucid35.addAssets)(stakingPositionOut.utxo.assets, mkAssetsOf({ currencySymbol: params.stakingParams.indyToken[0].unCurrencySymbol, tokenName: (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName) }, amount))
|
|
4886
4878
|
).addSignerKey((0, import_lucid35.toHex)(stakingPositionOut.datum.owner));
|
|
4887
4879
|
}
|
|
4888
4880
|
async function closeStakingPosition(stakingPositionRef, params, lucid, currentSlot, stakingManagerRef) {
|
|
@@ -4908,13 +4900,12 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
4908
4900
|
(_) => new Error("Expected a single staking token policy Ref Script UTXO")
|
|
4909
4901
|
);
|
|
4910
4902
|
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
4903
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
4913
4904
|
const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
|
|
4914
4905
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
4915
4906
|
const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
|
|
4916
4907
|
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
|
|
4917
|
-
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo],
|
|
4908
|
+
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom([stakingManagerOut.utxo], serialiseStakingRedeemer("UpdateTotalStake")).pay.ToContract(
|
|
4918
4909
|
stakingManagerOut.utxo.address,
|
|
4919
4910
|
{
|
|
4920
4911
|
kind: "inline",
|
|
@@ -4923,10 +4914,7 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
4923
4914
|
totalStake: stakingManagerOut.datum.totalStake - existingIndyAmount
|
|
4924
4915
|
})
|
|
4925
4916
|
},
|
|
4926
|
-
|
|
4927
|
-
lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
|
|
4928
|
-
[stakingManagerToken]: 1n
|
|
4929
|
-
}
|
|
4917
|
+
(0, import_lucid35.addAssets)(stakingManagerOut.utxo.assets, mkLovelacesOf(-adaReward))
|
|
4930
4918
|
).mintAssets(
|
|
4931
4919
|
{
|
|
4932
4920
|
[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,
|
|
@@ -3357,7 +3357,7 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
|
|
|
3357
3357
|
stakingPosUtxo.assets,
|
|
3358
3358
|
fromSystemParamsAsset(sysParams.govParams.indyAsset)
|
|
3359
3359
|
);
|
|
3360
|
-
const validityFrom = Number(currentTime) - ONE_SECOND;
|
|
3360
|
+
const validityFrom = Number(currentTime) - Math.min(120 * ONE_SECOND, Number(sysParams.govParams.gBiasTime));
|
|
3361
3361
|
if (stakingPosDatum.lockedAmount.has(pollShardDatum.pollId)) {
|
|
3362
3362
|
throw new Error("Already voted for that proposal.");
|
|
3363
3363
|
}
|
|
@@ -4574,7 +4574,6 @@ async function annulRequest(accountUtxo, params, lucid) {
|
|
|
4574
4574
|
// src/contracts/staking/transactions.ts
|
|
4575
4575
|
import {
|
|
4576
4576
|
addAssets as addAssets6,
|
|
4577
|
-
Constr as Constr3,
|
|
4578
4577
|
Data as Data22,
|
|
4579
4578
|
fromHex as fromHex3,
|
|
4580
4579
|
fromText as fromText6,
|
|
@@ -4613,7 +4612,7 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4613
4612
|
};
|
|
4614
4613
|
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + fromText6(params.stakingParams.stakingToken[1].unTokenName);
|
|
4615
4614
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText6(params.stakingParams.indyToken[1].unTokenName);
|
|
4616
|
-
return lucid.newTx().collectFrom([stakingManagerOut.utxo],
|
|
4615
|
+
return lucid.newTx().collectFrom([stakingManagerOut.utxo], serialiseStakingRedeemer({ CreateStakingPosition: { creatorPkh: pkh.hash } })).readFrom([stakingRefScriptUtxo]).pay.ToContract(
|
|
4617
4616
|
stakingManagerOut.utxo.address,
|
|
4618
4617
|
{
|
|
4619
4618
|
kind: "inline",
|
|
@@ -4639,7 +4638,7 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4639
4638
|
}
|
|
4640
4639
|
async function adjustStakingPosition(stakingPositionRef, amount, params, lucid, currentSlot, stakingManagerRef) {
|
|
4641
4640
|
const network = lucid.config().network;
|
|
4642
|
-
const currentTime = slotToUnixTime5(network, currentSlot) - ONE_SECOND;
|
|
4641
|
+
const currentTime = slotToUnixTime5(network, currentSlot) - 120 * ONE_SECOND;
|
|
4643
4642
|
const stakingPositionOut = await findStakingPositionByOutRef(
|
|
4644
4643
|
stakingPositionRef,
|
|
4645
4644
|
lucid
|
|
@@ -4651,8 +4650,6 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4651
4650
|
]),
|
|
4652
4651
|
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
4653
4652
|
);
|
|
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
4653
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText6(params.stakingParams.indyToken[1].unTokenName);
|
|
4657
4654
|
const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
|
|
4658
4655
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
@@ -4679,10 +4676,7 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4679
4676
|
totalStake: stakingManagerOut.datum.totalStake + amount
|
|
4680
4677
|
})
|
|
4681
4678
|
},
|
|
4682
|
-
|
|
4683
|
-
lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
|
|
4684
|
-
[stakingManagerToken]: 1n
|
|
4685
|
-
}
|
|
4679
|
+
addAssets6(stakingManagerOut.utxo.assets, mkLovelacesOf(-adaReward))
|
|
4686
4680
|
).pay.ToContract(
|
|
4687
4681
|
stakingPositionOut.utxo.address,
|
|
4688
4682
|
{
|
|
@@ -4692,10 +4686,7 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4692
4686
|
lockedAmount: newLockedAmount
|
|
4693
4687
|
})
|
|
4694
4688
|
},
|
|
4695
|
-
{
|
|
4696
|
-
[stakingToken]: 1n,
|
|
4697
|
-
[indyToken]: stakingPositionOut.utxo.assets[indyToken] + amount
|
|
4698
|
-
}
|
|
4689
|
+
addAssets6(stakingPositionOut.utxo.assets, mkAssetsOf({ currencySymbol: params.stakingParams.indyToken[0].unCurrencySymbol, tokenName: fromText6(params.stakingParams.indyToken[1].unTokenName) }, amount))
|
|
4699
4690
|
).addSignerKey(toHex2(stakingPositionOut.datum.owner));
|
|
4700
4691
|
}
|
|
4701
4692
|
async function closeStakingPosition(stakingPositionRef, params, lucid, currentSlot, stakingManagerRef) {
|
|
@@ -4721,13 +4712,12 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
4721
4712
|
(_) => new Error("Expected a single staking token policy Ref Script UTXO")
|
|
4722
4713
|
);
|
|
4723
4714
|
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
4715
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText6(params.stakingParams.indyToken[1].unTokenName);
|
|
4726
4716
|
const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
|
|
4727
4717
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
4728
4718
|
const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
|
|
4729
4719
|
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
|
|
4730
|
-
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo],
|
|
4720
|
+
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom([stakingManagerOut.utxo], serialiseStakingRedeemer("UpdateTotalStake")).pay.ToContract(
|
|
4731
4721
|
stakingManagerOut.utxo.address,
|
|
4732
4722
|
{
|
|
4733
4723
|
kind: "inline",
|
|
@@ -4736,10 +4726,7 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
4736
4726
|
totalStake: stakingManagerOut.datum.totalStake - existingIndyAmount
|
|
4737
4727
|
})
|
|
4738
4728
|
},
|
|
4739
|
-
|
|
4740
|
-
lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
|
|
4741
|
-
[stakingManagerToken]: 1n
|
|
4742
|
-
}
|
|
4729
|
+
addAssets6(stakingManagerOut.utxo.assets, mkLovelacesOf(-adaReward))
|
|
4743
4730
|
).mintAssets(
|
|
4744
4731
|
{
|
|
4745
4732
|
[stakingToken]: -1n
|
package/package.json
CHANGED
|
@@ -446,7 +446,7 @@ export async function vote(
|
|
|
446
446
|
fromSystemParamsAsset(sysParams.govParams.indyAsset),
|
|
447
447
|
);
|
|
448
448
|
|
|
449
|
-
const validityFrom = Number(currentTime) - ONE_SECOND;
|
|
449
|
+
const validityFrom = Number(currentTime) - Math.min(120 * ONE_SECOND, Number(sysParams.govParams.gBiasTime));
|
|
450
450
|
|
|
451
451
|
if (stakingPosDatum.lockedAmount.has(pollShardDatum.pollId)) {
|
|
452
452
|
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.
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
import { matchSingle } from '../../utils/utils';
|
|
33
33
|
import { serialiseStakingRedeemer } from './types';
|
|
34
34
|
import { serialiseCollectorRedeemer } from '../collector/types';
|
|
35
|
-
import { mkLovelacesOf } from '../../utils/value-helpers';
|
|
35
|
+
import { mkAssetsOf, mkLovelacesOf } from '../../utils/value-helpers';
|
|
36
36
|
import { ONE_SECOND } from '../../utils/time-helpers';
|
|
37
37
|
|
|
38
38
|
export async function openStakingPosition(
|
|
@@ -85,7 +85,7 @@ export async function openStakingPosition(
|
|
|
85
85
|
fromText(params.stakingParams.indyToken[1].unTokenName);
|
|
86
86
|
return lucid
|
|
87
87
|
.newTx()
|
|
88
|
-
.collectFrom([stakingManagerOut.utxo],
|
|
88
|
+
.collectFrom([stakingManagerOut.utxo], serialiseStakingRedeemer({CreateStakingPosition: { creatorPkh: pkh.hash }}))
|
|
89
89
|
.readFrom([stakingRefScriptUtxo])
|
|
90
90
|
.pay.ToContract(
|
|
91
91
|
stakingManagerOut.utxo.address,
|
|
@@ -125,7 +125,7 @@ export async function adjustStakingPosition(
|
|
|
125
125
|
stakingManagerRef?: OutRef,
|
|
126
126
|
): Promise<TxBuilder> {
|
|
127
127
|
const network = lucid.config().network!;
|
|
128
|
-
const currentTime = slotToUnixTime(network, currentSlot) - ONE_SECOND;
|
|
128
|
+
const currentTime = slotToUnixTime(network, currentSlot) - (120 * ONE_SECOND);
|
|
129
129
|
|
|
130
130
|
const stakingPositionOut = await findStakingPositionByOutRef(
|
|
131
131
|
stakingPositionRef,
|
|
@@ -142,12 +142,6 @@ export async function adjustStakingPosition(
|
|
|
142
142
|
(_) => new Error('Expected a single staking Ref Script UTXO'),
|
|
143
143
|
);
|
|
144
144
|
|
|
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
145
|
const indyToken =
|
|
152
146
|
params.stakingParams.indyToken[0].unCurrencySymbol +
|
|
153
147
|
fromText(params.stakingParams.indyToken[1].unTokenName);
|
|
@@ -188,10 +182,7 @@ export async function adjustStakingPosition(
|
|
|
188
182
|
totalStake: stakingManagerOut.datum.totalStake + amount,
|
|
189
183
|
}),
|
|
190
184
|
},
|
|
191
|
-
|
|
192
|
-
lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
|
|
193
|
-
[stakingManagerToken]: 1n,
|
|
194
|
-
},
|
|
185
|
+
addAssets(stakingManagerOut.utxo.assets, mkLovelacesOf(-adaReward)),
|
|
195
186
|
)
|
|
196
187
|
.pay.ToContract(
|
|
197
188
|
stakingPositionOut.utxo.address,
|
|
@@ -202,10 +193,7 @@ export async function adjustStakingPosition(
|
|
|
202
193
|
lockedAmount: newLockedAmount,
|
|
203
194
|
}),
|
|
204
195
|
},
|
|
205
|
-
{
|
|
206
|
-
[stakingToken]: 1n,
|
|
207
|
-
[indyToken]: stakingPositionOut.utxo.assets[indyToken] + amount,
|
|
208
|
-
},
|
|
196
|
+
addAssets(stakingPositionOut.utxo.assets, mkAssetsOf({ currencySymbol: params.stakingParams.indyToken[0].unCurrencySymbol, tokenName: fromText(params.stakingParams.indyToken[1].unTokenName) }, amount)),
|
|
209
197
|
)
|
|
210
198
|
.addSignerKey(toHex(stakingPositionOut.datum.owner));
|
|
211
199
|
}
|
|
@@ -246,9 +234,6 @@ export async function closeStakingPosition(
|
|
|
246
234
|
const stakingToken =
|
|
247
235
|
params.stakingParams.stakingToken[0].unCurrencySymbol +
|
|
248
236
|
fromText(params.stakingParams.stakingToken[1].unTokenName);
|
|
249
|
-
const stakingManagerToken =
|
|
250
|
-
params.stakingParams.stakingManagerNFT[0].unCurrencySymbol +
|
|
251
|
-
fromText(params.stakingParams.stakingManagerNFT[1].unTokenName);
|
|
252
237
|
const indyToken =
|
|
253
238
|
params.stakingParams.indyToken[0].unCurrencySymbol +
|
|
254
239
|
fromText(params.stakingParams.indyToken[1].unTokenName);
|
|
@@ -265,8 +250,8 @@ export async function closeStakingPosition(
|
|
|
265
250
|
.newTx()
|
|
266
251
|
.validFrom(currentTime)
|
|
267
252
|
.readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo])
|
|
268
|
-
.collectFrom([stakingPositionOut.utxo],
|
|
269
|
-
.collectFrom([stakingManagerOut.utxo],
|
|
253
|
+
.collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer('Unstake'))
|
|
254
|
+
.collectFrom([stakingManagerOut.utxo], serialiseStakingRedeemer('UpdateTotalStake'))
|
|
270
255
|
.pay.ToContract(
|
|
271
256
|
stakingManagerOut.utxo.address,
|
|
272
257
|
{
|
|
@@ -276,10 +261,7 @@ export async function closeStakingPosition(
|
|
|
276
261
|
totalStake: stakingManagerOut.datum.totalStake - existingIndyAmount,
|
|
277
262
|
}),
|
|
278
263
|
},
|
|
279
|
-
|
|
280
|
-
lovelace: stakingManagerOut.utxo.assets.lovelace - adaReward,
|
|
281
|
-
[stakingManagerToken]: 1n,
|
|
282
|
-
},
|
|
264
|
+
addAssets(stakingManagerOut.utxo.assets, mkLovelacesOf(-adaReward)),
|
|
283
265
|
)
|
|
284
266
|
.mintAssets(
|
|
285
267
|
{
|
|
@@ -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,54 @@ 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(stakingPosUtxo.utxo, 500_000_000n, sysParams, context.lucid, context.emulator.slot),
|
|
579
|
+
);
|
|
580
|
+
});
|
|
581
|
+
|
|
533
582
|
test<MyContext>('Vote on 2 proposals sequentially (lower pollID first)', async (context: MyContext) => {
|
|
534
583
|
context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
|
|
535
584
|
|