@indigo-labs/indigo-sdk 0.2.23 → 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
CHANGED
|
@@ -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",
|
|
@@ -4874,7 +4881,16 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4874
4881
|
lockedAmount: newLockedAmount
|
|
4875
4882
|
})
|
|
4876
4883
|
},
|
|
4877
|
-
(0, import_lucid35.addAssets)(
|
|
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
|
+
)
|
|
4878
4894
|
).addSignerKey((0, import_lucid35.toHex)(stakingPositionOut.datum.owner));
|
|
4879
4895
|
}
|
|
4880
4896
|
async function closeStakingPosition(stakingPositionRef, params, lucid, currentSlot, stakingManagerRef) {
|
|
@@ -4905,7 +4921,10 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
4905
4921
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
4906
4922
|
const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
|
|
4907
4923
|
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
|
|
4908
|
-
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom(
|
|
4924
|
+
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom(
|
|
4925
|
+
[stakingManagerOut.utxo],
|
|
4926
|
+
serialiseStakingRedeemer("UpdateTotalStake")
|
|
4927
|
+
).pay.ToContract(
|
|
4909
4928
|
stakingManagerOut.utxo.address,
|
|
4910
4929
|
{
|
|
4911
4930
|
kind: "inline",
|
package/dist/index.mjs
CHANGED
|
@@ -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
|
);
|
|
@@ -4612,7 +4614,12 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
|
4612
4614
|
};
|
|
4613
4615
|
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + fromText6(params.stakingParams.stakingToken[1].unTokenName);
|
|
4614
4616
|
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText6(params.stakingParams.indyToken[1].unTokenName);
|
|
4615
|
-
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(
|
|
4616
4623
|
stakingManagerOut.utxo.address,
|
|
4617
4624
|
{
|
|
4618
4625
|
kind: "inline",
|
|
@@ -4686,7 +4693,16 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
4686
4693
|
lockedAmount: newLockedAmount
|
|
4687
4694
|
})
|
|
4688
4695
|
},
|
|
4689
|
-
addAssets6(
|
|
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
|
+
)
|
|
4690
4706
|
).addSignerKey(toHex2(stakingPositionOut.datum.owner));
|
|
4691
4707
|
}
|
|
4692
4708
|
async function closeStakingPosition(stakingPositionRef, params, lucid, currentSlot, stakingManagerRef) {
|
|
@@ -4717,7 +4733,10 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
4717
4733
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
4718
4734
|
const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
|
|
4719
4735
|
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
|
|
4720
|
-
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom(
|
|
4736
|
+
return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom(
|
|
4737
|
+
[stakingManagerOut.utxo],
|
|
4738
|
+
serialiseStakingRedeemer("UpdateTotalStake")
|
|
4739
|
+
).pay.ToContract(
|
|
4721
4740
|
stakingManagerOut.utxo.address,
|
|
4722
4741
|
{
|
|
4723
4742
|
kind: "inline",
|
|
@@ -4799,7 +4818,7 @@ import {
|
|
|
4799
4818
|
// src/contracts/one-shot/transactions.ts
|
|
4800
4819
|
import {
|
|
4801
4820
|
addAssets as addAssets7,
|
|
4802
|
-
Constr as
|
|
4821
|
+
Constr as Constr3,
|
|
4803
4822
|
Data as Data24,
|
|
4804
4823
|
mintingPolicyToId,
|
|
4805
4824
|
toUnit as toUnit2
|
|
@@ -4868,7 +4887,7 @@ async function oneShotMintTx(lucid, params) {
|
|
|
4868
4887
|
[toUnit2(policyId, entry.tokenName)]: entry.amount
|
|
4869
4888
|
})
|
|
4870
4889
|
)(params.mintAmounts),
|
|
4871
|
-
Data24.to(new
|
|
4890
|
+
Data24.to(new Constr3(0, []))
|
|
4872
4891
|
).attach.MintingPolicy(oneShotPolicy),
|
|
4873
4892
|
policyId
|
|
4874
4893
|
];
|
|
@@ -5049,7 +5068,7 @@ var mkVersionRegistryValidator = () => {
|
|
|
5049
5068
|
// src/contracts/collector/scripts.ts
|
|
5050
5069
|
import {
|
|
5051
5070
|
applyParamsToScript as applyParamsToScript9,
|
|
5052
|
-
Constr as
|
|
5071
|
+
Constr as Constr4,
|
|
5053
5072
|
fromText as fromText8
|
|
5054
5073
|
} from "@lucid-evolution/lucid";
|
|
5055
5074
|
|
|
@@ -5065,16 +5084,16 @@ var mkCollectorValidatorFromSP = (params) => {
|
|
|
5065
5084
|
return {
|
|
5066
5085
|
type: "PlutusV2",
|
|
5067
5086
|
script: applyParamsToScript9(_collectorValidator.cborHex, [
|
|
5068
|
-
new
|
|
5069
|
-
new
|
|
5087
|
+
new Constr4(0, [
|
|
5088
|
+
new Constr4(0, [
|
|
5070
5089
|
params.stakingManagerNFT[0].unCurrencySymbol,
|
|
5071
5090
|
fromText8(params.stakingManagerNFT[1].unTokenName)
|
|
5072
5091
|
]),
|
|
5073
|
-
new
|
|
5092
|
+
new Constr4(0, [
|
|
5074
5093
|
params.stakingToken[0].unCurrencySymbol,
|
|
5075
5094
|
fromText8(params.stakingToken[1].unTokenName)
|
|
5076
5095
|
]),
|
|
5077
|
-
new
|
|
5096
|
+
new Constr4(0, [
|
|
5078
5097
|
params.versionRecordToken[0].unCurrencySymbol,
|
|
5079
5098
|
fromText8(params.versionRecordToken[1].unTokenName)
|
|
5080
5099
|
])
|
|
@@ -5086,7 +5105,7 @@ var mkCollectorValidatorFromSP = (params) => {
|
|
|
5086
5105
|
// src/contracts/treasury/scripts.ts
|
|
5087
5106
|
import {
|
|
5088
5107
|
applyParamsToScript as applyParamsToScript10,
|
|
5089
|
-
Constr as
|
|
5108
|
+
Constr as Constr5,
|
|
5090
5109
|
fromText as fromText9
|
|
5091
5110
|
} from "@lucid-evolution/lucid";
|
|
5092
5111
|
|
|
@@ -5102,22 +5121,22 @@ var mkTreasuryValidatorFromSP = (params) => {
|
|
|
5102
5121
|
return {
|
|
5103
5122
|
type: "PlutusV2",
|
|
5104
5123
|
script: applyParamsToScript10(_treasuryValidator.cborHex, [
|
|
5105
|
-
new
|
|
5106
|
-
new
|
|
5124
|
+
new Constr5(0, [
|
|
5125
|
+
new Constr5(0, [
|
|
5107
5126
|
params.upgradeToken[0].unCurrencySymbol,
|
|
5108
5127
|
fromText9(params.upgradeToken[1].unTokenName)
|
|
5109
5128
|
]),
|
|
5110
|
-
new
|
|
5129
|
+
new Constr5(0, [
|
|
5111
5130
|
params.versionRecordToken[0].unCurrencySymbol,
|
|
5112
5131
|
fromText9(params.versionRecordToken[1].unTokenName)
|
|
5113
5132
|
]),
|
|
5114
|
-
params.treasuryUtxosStakeCredential ? new
|
|
5115
|
-
new
|
|
5116
|
-
new
|
|
5133
|
+
params.treasuryUtxosStakeCredential ? new Constr5(0, [
|
|
5134
|
+
new Constr5(0, [
|
|
5135
|
+
new Constr5(1, [
|
|
5117
5136
|
params.treasuryUtxosStakeCredential.contents.contents
|
|
5118
5137
|
])
|
|
5119
5138
|
])
|
|
5120
|
-
]) : new
|
|
5139
|
+
]) : new Constr5(1, [])
|
|
5121
5140
|
])
|
|
5122
5141
|
])
|
|
5123
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.');
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
addAssets,
|
|
3
|
-
Constr,
|
|
4
3
|
Data,
|
|
5
4
|
fromHex,
|
|
6
5
|
fromText,
|
|
@@ -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) -
|
|
132
|
+
const currentTime = slotToUnixTime(network, currentSlot) - 120 * ONE_SECOND;
|
|
129
133
|
|
|
130
134
|
const stakingPositionOut = await findStakingPositionByOutRef(
|
|
131
135
|
stakingPositionRef,
|
|
@@ -193,7 +197,16 @@ export async function adjustStakingPosition(
|
|
|
193
197
|
lockedAmount: newLockedAmount,
|
|
194
198
|
}),
|
|
195
199
|
},
|
|
196
|
-
addAssets(
|
|
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
|
+
),
|
|
197
210
|
)
|
|
198
211
|
.addSignerKey(toHex(stakingPositionOut.datum.owner));
|
|
199
212
|
}
|
|
@@ -251,7 +264,10 @@ export async function closeStakingPosition(
|
|
|
251
264
|
.validFrom(currentTime)
|
|
252
265
|
.readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo])
|
|
253
266
|
.collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer('Unstake'))
|
|
254
|
-
.collectFrom(
|
|
267
|
+
.collectFrom(
|
|
268
|
+
[stakingManagerOut.utxo],
|
|
269
|
+
serialiseStakingRedeemer('UpdateTotalStake'),
|
|
270
|
+
)
|
|
255
271
|
.pay.ToContract(
|
|
256
272
|
stakingManagerOut.utxo.address,
|
|
257
273
|
{
|
|
@@ -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
|
);
|
package/tests/gov.test.ts
CHANGED
|
@@ -575,7 +575,13 @@ describe('Gov', () => {
|
|
|
575
575
|
|
|
576
576
|
await runAndAwaitTx(
|
|
577
577
|
context.lucid,
|
|
578
|
-
adjustStakingPosition(
|
|
578
|
+
adjustStakingPosition(
|
|
579
|
+
stakingPosUtxo.utxo,
|
|
580
|
+
500_000_000n,
|
|
581
|
+
sysParams,
|
|
582
|
+
context.lucid,
|
|
583
|
+
context.emulator.slot,
|
|
584
|
+
),
|
|
579
585
|
);
|
|
580
586
|
});
|
|
581
587
|
|