@indigo-labs/indigo-sdk 0.2.23 → 0.2.25

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,15 @@ 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(
1506
+ sysParams.treasuryParams.treasuryUtxosStakeCredential
1507
+ ) : void 0;
1504
1508
  tx.readFrom([treasuryRefScriptUtxo]).collectFrom([treasuryUtxo], serialiseTreasuryRedeemer("CollectAda")).pay.ToContract(
1505
- treasuryUtxo.address,
1509
+ createScriptAddress(
1510
+ lucid.config().network,
1511
+ sysParams.validatorHashes.treasuryHash,
1512
+ stakeCredential
1513
+ ),
1506
1514
  { kind: "inline", value: import_lucid17.Data.void() },
1507
1515
  (0, import_lucid17.addAssets)(treasuryUtxo.assets, mkLovelacesOf(fee))
1508
1516
  );
@@ -4800,7 +4808,12 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
4800
4808
  };
4801
4809
  const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.stakingToken[1].unTokenName);
4802
4810
  const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName);
4803
- return lucid.newTx().collectFrom([stakingManagerOut.utxo], serialiseStakingRedeemer({ CreateStakingPosition: { creatorPkh: pkh.hash } })).readFrom([stakingRefScriptUtxo]).pay.ToContract(
4811
+ return lucid.newTx().collectFrom(
4812
+ [stakingManagerOut.utxo],
4813
+ serialiseStakingRedeemer({
4814
+ CreateStakingPosition: { creatorPkh: pkh.hash }
4815
+ })
4816
+ ).readFrom([stakingRefScriptUtxo]).pay.ToContract(
4804
4817
  stakingManagerOut.utxo.address,
4805
4818
  {
4806
4819
  kind: "inline",
@@ -4871,10 +4884,20 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
4871
4884
  kind: "inline",
4872
4885
  value: serialiseStakingDatum({
4873
4886
  ...stakingPositionOut.datum,
4874
- lockedAmount: newLockedAmount
4887
+ lockedAmount: newLockedAmount,
4888
+ positionSnapshot: stakingManagerOut.datum.managerSnapshot
4875
4889
  })
4876
4890
  },
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))
4891
+ (0, import_lucid35.addAssets)(
4892
+ stakingPositionOut.utxo.assets,
4893
+ mkAssetsOf(
4894
+ {
4895
+ currencySymbol: params.stakingParams.indyToken[0].unCurrencySymbol,
4896
+ tokenName: (0, import_lucid35.fromText)(params.stakingParams.indyToken[1].unTokenName)
4897
+ },
4898
+ amount
4899
+ )
4900
+ )
4878
4901
  ).addSignerKey((0, import_lucid35.toHex)(stakingPositionOut.datum.owner));
4879
4902
  }
4880
4903
  async function closeStakingPosition(stakingPositionRef, params, lucid, currentSlot, stakingManagerRef) {
@@ -4905,7 +4928,10 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
4905
4928
  const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
4906
4929
  const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
4907
4930
  const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
4908
- return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom([stakingManagerOut.utxo], serialiseStakingRedeemer("UpdateTotalStake")).pay.ToContract(
4931
+ return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom(
4932
+ [stakingManagerOut.utxo],
4933
+ serialiseStakingRedeemer("UpdateTotalStake")
4934
+ ).pay.ToContract(
4909
4935
  stakingManagerOut.utxo.address,
4910
4936
  {
4911
4937
  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,15 @@ 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(
1277
+ sysParams.treasuryParams.treasuryUtxosStakeCredential
1278
+ ) : void 0;
1275
1279
  tx.readFrom([treasuryRefScriptUtxo]).collectFrom([treasuryUtxo], serialiseTreasuryRedeemer("CollectAda")).pay.ToContract(
1276
- treasuryUtxo.address,
1280
+ createScriptAddress(
1281
+ lucid.config().network,
1282
+ sysParams.validatorHashes.treasuryHash,
1283
+ stakeCredential
1284
+ ),
1277
1285
  { kind: "inline", value: Data12.void() },
1278
1286
  addAssets2(treasuryUtxo.assets, mkLovelacesOf(fee))
1279
1287
  );
@@ -4612,7 +4620,12 @@ async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
4612
4620
  };
4613
4621
  const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + fromText6(params.stakingParams.stakingToken[1].unTokenName);
4614
4622
  const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText6(params.stakingParams.indyToken[1].unTokenName);
4615
- return lucid.newTx().collectFrom([stakingManagerOut.utxo], serialiseStakingRedeemer({ CreateStakingPosition: { creatorPkh: pkh.hash } })).readFrom([stakingRefScriptUtxo]).pay.ToContract(
4623
+ return lucid.newTx().collectFrom(
4624
+ [stakingManagerOut.utxo],
4625
+ serialiseStakingRedeemer({
4626
+ CreateStakingPosition: { creatorPkh: pkh.hash }
4627
+ })
4628
+ ).readFrom([stakingRefScriptUtxo]).pay.ToContract(
4616
4629
  stakingManagerOut.utxo.address,
4617
4630
  {
4618
4631
  kind: "inline",
@@ -4683,10 +4696,20 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
4683
4696
  kind: "inline",
4684
4697
  value: serialiseStakingDatum({
4685
4698
  ...stakingPositionOut.datum,
4686
- lockedAmount: newLockedAmount
4699
+ lockedAmount: newLockedAmount,
4700
+ positionSnapshot: stakingManagerOut.datum.managerSnapshot
4687
4701
  })
4688
4702
  },
4689
- addAssets6(stakingPositionOut.utxo.assets, mkAssetsOf({ currencySymbol: params.stakingParams.indyToken[0].unCurrencySymbol, tokenName: fromText6(params.stakingParams.indyToken[1].unTokenName) }, amount))
4703
+ addAssets6(
4704
+ stakingPositionOut.utxo.assets,
4705
+ mkAssetsOf(
4706
+ {
4707
+ currencySymbol: params.stakingParams.indyToken[0].unCurrencySymbol,
4708
+ tokenName: fromText6(params.stakingParams.indyToken[1].unTokenName)
4709
+ },
4710
+ amount
4711
+ )
4712
+ )
4690
4713
  ).addSignerKey(toHex2(stakingPositionOut.datum.owner));
4691
4714
  }
4692
4715
  async function closeStakingPosition(stakingPositionRef, params, lucid, currentSlot, stakingManagerRef) {
@@ -4717,7 +4740,10 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
4717
4740
  const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
4718
4741
  const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
4719
4742
  const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
4720
- return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom([stakingManagerOut.utxo], serialiseStakingRedeemer("UpdateTotalStake")).pay.ToContract(
4743
+ return lucid.newTx().validFrom(currentTime).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom(
4744
+ [stakingManagerOut.utxo],
4745
+ serialiseStakingRedeemer("UpdateTotalStake")
4746
+ ).pay.ToContract(
4721
4747
  stakingManagerOut.utxo.address,
4722
4748
  {
4723
4749
  kind: "inline",
@@ -4799,7 +4825,7 @@ import {
4799
4825
  // src/contracts/one-shot/transactions.ts
4800
4826
  import {
4801
4827
  addAssets as addAssets7,
4802
- Constr as Constr4,
4828
+ Constr as Constr3,
4803
4829
  Data as Data24,
4804
4830
  mintingPolicyToId,
4805
4831
  toUnit as toUnit2
@@ -4868,7 +4894,7 @@ async function oneShotMintTx(lucid, params) {
4868
4894
  [toUnit2(policyId, entry.tokenName)]: entry.amount
4869
4895
  })
4870
4896
  )(params.mintAmounts),
4871
- Data24.to(new Constr4(0, []))
4897
+ Data24.to(new Constr3(0, []))
4872
4898
  ).attach.MintingPolicy(oneShotPolicy),
4873
4899
  policyId
4874
4900
  ];
@@ -5049,7 +5075,7 @@ var mkVersionRegistryValidator = () => {
5049
5075
  // src/contracts/collector/scripts.ts
5050
5076
  import {
5051
5077
  applyParamsToScript as applyParamsToScript9,
5052
- Constr as Constr5,
5078
+ Constr as Constr4,
5053
5079
  fromText as fromText8
5054
5080
  } from "@lucid-evolution/lucid";
5055
5081
 
@@ -5065,16 +5091,16 @@ var mkCollectorValidatorFromSP = (params) => {
5065
5091
  return {
5066
5092
  type: "PlutusV2",
5067
5093
  script: applyParamsToScript9(_collectorValidator.cborHex, [
5068
- new Constr5(0, [
5069
- new Constr5(0, [
5094
+ new Constr4(0, [
5095
+ new Constr4(0, [
5070
5096
  params.stakingManagerNFT[0].unCurrencySymbol,
5071
5097
  fromText8(params.stakingManagerNFT[1].unTokenName)
5072
5098
  ]),
5073
- new Constr5(0, [
5099
+ new Constr4(0, [
5074
5100
  params.stakingToken[0].unCurrencySymbol,
5075
5101
  fromText8(params.stakingToken[1].unTokenName)
5076
5102
  ]),
5077
- new Constr5(0, [
5103
+ new Constr4(0, [
5078
5104
  params.versionRecordToken[0].unCurrencySymbol,
5079
5105
  fromText8(params.versionRecordToken[1].unTokenName)
5080
5106
  ])
@@ -5086,7 +5112,7 @@ var mkCollectorValidatorFromSP = (params) => {
5086
5112
  // src/contracts/treasury/scripts.ts
5087
5113
  import {
5088
5114
  applyParamsToScript as applyParamsToScript10,
5089
- Constr as Constr6,
5115
+ Constr as Constr5,
5090
5116
  fromText as fromText9
5091
5117
  } from "@lucid-evolution/lucid";
5092
5118
 
@@ -5102,22 +5128,22 @@ var mkTreasuryValidatorFromSP = (params) => {
5102
5128
  return {
5103
5129
  type: "PlutusV2",
5104
5130
  script: applyParamsToScript10(_treasuryValidator.cborHex, [
5105
- new Constr6(0, [
5106
- new Constr6(0, [
5131
+ new Constr5(0, [
5132
+ new Constr5(0, [
5107
5133
  params.upgradeToken[0].unCurrencySymbol,
5108
5134
  fromText9(params.upgradeToken[1].unTokenName)
5109
5135
  ]),
5110
- new Constr6(0, [
5136
+ new Constr5(0, [
5111
5137
  params.versionRecordToken[0].unCurrencySymbol,
5112
5138
  fromText9(params.versionRecordToken[1].unTokenName)
5113
5139
  ]),
5114
- params.treasuryUtxosStakeCredential ? new Constr6(0, [
5115
- new Constr6(0, [
5116
- new Constr6(1, [
5140
+ params.treasuryUtxosStakeCredential ? new Constr5(0, [
5141
+ new Constr5(0, [
5142
+ new Constr5(1, [
5117
5143
  params.treasuryUtxosStakeCredential.contents.contents
5118
5144
  ])
5119
5145
  ])
5120
- ]) : new Constr6(1, [])
5146
+ ]) : new Constr5(1, [])
5121
5147
  ])
5122
5148
  ])
5123
5149
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigo-labs/indigo-sdk",
3
- "version": "0.2.23",
3
+ "version": "0.2.25",
4
4
  "description": "Indigo SDK for interacting with Indigo endpoints via lucid-evolution",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -446,7 +446,9 @@ export async function vote(
446
446
  fromSystemParamsAsset(sysParams.govParams.indyAsset),
447
447
  );
448
448
 
449
- const validityFrom = Number(currentTime) - Math.min(120 * ONE_SECOND, Number(sysParams.govParams.gBiasTime));
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([stakingManagerOut.utxo], serialiseStakingRedeemer({CreateStakingPosition: { creatorPkh: pkh.hash }}))
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) - (120 * ONE_SECOND);
132
+ const currentTime = slotToUnixTime(network, currentSlot) - 120 * ONE_SECOND;
129
133
 
130
134
  const stakingPositionOut = await findStakingPositionByOutRef(
131
135
  stakingPositionRef,
@@ -191,9 +195,19 @@ export async function adjustStakingPosition(
191
195
  value: serialiseStakingDatum({
192
196
  ...stakingPositionOut.datum,
193
197
  lockedAmount: newLockedAmount,
198
+ positionSnapshot: stakingManagerOut.datum.managerSnapshot
194
199
  }),
195
200
  },
196
- addAssets(stakingPositionOut.utxo.assets, mkAssetsOf({ currencySymbol: params.stakingParams.indyToken[0].unCurrencySymbol, tokenName: fromText(params.stakingParams.indyToken[1].unTokenName) }, amount)),
201
+ addAssets(
202
+ stakingPositionOut.utxo.assets,
203
+ mkAssetsOf(
204
+ {
205
+ currencySymbol: params.stakingParams.indyToken[0].unCurrencySymbol,
206
+ tokenName: fromText(params.stakingParams.indyToken[1].unTokenName),
207
+ },
208
+ amount,
209
+ ),
210
+ ),
197
211
  )
198
212
  .addSignerKey(toHex(stakingPositionOut.datum.owner));
199
213
  }
@@ -251,7 +265,10 @@ export async function closeStakingPosition(
251
265
  .validFrom(currentTime)
252
266
  .readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo])
253
267
  .collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer('Unstake'))
254
- .collectFrom([stakingManagerOut.utxo], serialiseStakingRedeemer('UpdateTotalStake'))
268
+ .collectFrom(
269
+ [stakingManagerOut.utxo],
270
+ serialiseStakingRedeemer('UpdateTotalStake'),
271
+ )
255
272
  .pay.ToContract(
256
273
  stakingManagerOut.utxo.address,
257
274
  {
@@ -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,20 @@ 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
42
+ ? fromSysParamsScriptCredential(
43
+ sysParams.treasuryParams.treasuryUtxosStakeCredential,
44
+ )
45
+ : undefined;
46
+
37
47
  tx.readFrom([treasuryRefScriptUtxo])
38
48
  .collectFrom([treasuryUtxo], serialiseTreasuryRedeemer('CollectAda'))
39
49
  .pay.ToContract(
40
- treasuryUtxo.address,
50
+ createScriptAddress(
51
+ lucid.config().network!,
52
+ sysParams.validatorHashes.treasuryHash,
53
+ stakeCredential,
54
+ ),
41
55
  { kind: 'inline', value: Data.void() },
42
56
  addAssets(treasuryUtxo.assets, mkLovelacesOf(fee)),
43
57
  );
package/tests/gov.test.ts CHANGED
@@ -575,7 +575,13 @@ describe('Gov', () => {
575
575
 
576
576
  await runAndAwaitTx(
577
577
  context.lucid,
578
- adjustStakingPosition(stakingPosUtxo.utxo, 500_000_000n, sysParams, context.lucid, context.emulator.slot),
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