@indigo-labs/indigo-sdk 0.2.33 → 0.2.35

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 CHANGED
@@ -2013,7 +2013,13 @@ declare const LRPRedeemerSchema: _lucid_evolution_lucid.TUnion<(_lucid_evolution
2013
2013
  type LRPRedeemer = Data.Static<typeof LRPRedeemerSchema>;
2014
2014
  declare function parseLrpDatum(datum: Datum): option.Option<LRPDatum>;
2015
2015
  declare function parseLrpDatumOrThrow(datum: Datum): LRPDatum;
2016
- declare function serialiseLrpDatum(datum: LRPDatum): Datum;
2016
+ type LRPSerialisationOptions = {
2017
+ _tag: 'noReplace';
2018
+ } | {
2019
+ _tag: 'adaptiveReplace';
2020
+ spentLrpDatum: string;
2021
+ };
2022
+ declare function serialiseLrpDatum(datum: LRPDatum, serialisationOptions?: LRPSerialisationOptions): Datum;
2017
2023
  declare function serialiseLrpRedeemer(redeemer: LRPRedeemer): Redeemer;
2018
2024
  declare function castLrpParams(params: LRPParams): Data;
2019
2025
  type LrpOutput = {
package/dist/index.d.ts CHANGED
@@ -2013,7 +2013,13 @@ declare const LRPRedeemerSchema: _lucid_evolution_lucid.TUnion<(_lucid_evolution
2013
2013
  type LRPRedeemer = Data.Static<typeof LRPRedeemerSchema>;
2014
2014
  declare function parseLrpDatum(datum: Datum): option.Option<LRPDatum>;
2015
2015
  declare function parseLrpDatumOrThrow(datum: Datum): LRPDatum;
2016
- declare function serialiseLrpDatum(datum: LRPDatum): Datum;
2016
+ type LRPSerialisationOptions = {
2017
+ _tag: 'noReplace';
2018
+ } | {
2019
+ _tag: 'adaptiveReplace';
2020
+ spentLrpDatum: string;
2021
+ };
2022
+ declare function serialiseLrpDatum(datum: LRPDatum, serialisationOptions?: LRPSerialisationOptions): Datum;
2017
2023
  declare function serialiseLrpRedeemer(redeemer: LRPRedeemer): Redeemer;
2018
2024
  declare function castLrpParams(params: LRPParams): Data;
2019
2025
  type LrpOutput = {
package/dist/index.js CHANGED
@@ -3592,7 +3592,12 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
3592
3592
  BigInt(validityFrom),
3593
3593
  indyStakedAmt
3594
3594
  );
3595
- return lucid.newTx().validFrom(validityFrom).validTo(Number(pollShardDatum.votingEndTime) - ONE_SECOND).readFrom([stakingRefScriptUtxo, pollShardRefScriptUtxo]).collectFrom([stakingPosUtxo], serialiseStakingRedeemer("Lock")).collectFrom(
3595
+ return lucid.newTx().validFrom(validityFrom).validTo(
3596
+ Math.min(
3597
+ Number(pollShardDatum.votingEndTime) - ONE_SECOND,
3598
+ Number(currentTime) + Number(sysParams.govParams.gBiasTime) - ONE_SECOND
3599
+ )
3600
+ ).readFrom([stakingRefScriptUtxo, pollShardRefScriptUtxo]).collectFrom([stakingPosUtxo], serialiseStakingRedeemer("Lock")).collectFrom(
3596
3601
  [pollShardUtxo],
3597
3602
  serialisePollShardRedeemer({ Vote: { content: voteOption } })
3598
3603
  ).pay.ToContract(
@@ -5374,6 +5379,7 @@ var import_lucid47 = require("@lucid-evolution/lucid");
5374
5379
  // src/contracts/lrp/types.ts
5375
5380
  var import_lucid46 = require("@lucid-evolution/lucid");
5376
5381
  var import_fp_ts11 = require("fp-ts");
5382
+ var import_ts_pattern12 = require("ts-pattern");
5377
5383
  var LRPParamsSchema = import_lucid46.Data.Object({
5378
5384
  versionRecordToken: AssetClassSchema,
5379
5385
  iassetNft: AssetClassSchema,
@@ -5423,19 +5429,36 @@ function parseLrpDatumOrThrow(datum) {
5423
5429
  }, import_fp_ts11.function.identity)
5424
5430
  );
5425
5431
  }
5426
- function serialiseLrpDatum(datum) {
5432
+ function serialiseLrpDatum(datum, serialisationOptions = { _tag: "noReplace" }) {
5427
5433
  const d = import_lucid46.Data.to(datum, LRPDatum);
5428
- const ocdSerialisedCanonical = import_lucid46.Data.to(
5429
- datum.maxPrice,
5430
- OnChainDecimal,
5431
- { canonical: true }
5432
- );
5433
- const ocdSerialisedNonCanonical = import_lucid46.Data.to(
5434
- datum.maxPrice,
5435
- OnChainDecimal,
5436
- { canonical: false }
5437
- );
5438
- return d.replace(ocdSerialisedNonCanonical, ocdSerialisedCanonical);
5434
+ return (0, import_ts_pattern12.match)(serialisationOptions).returnType().with({ _tag: "noReplace" }, () => d).with(
5435
+ { _tag: "adaptiveReplace", spentLrpDatum: import_ts_pattern12.P.select() },
5436
+ (spentLrpDatum) => {
5437
+ const isSpentDatumCanonical = spentLrpDatum.includes(
5438
+ import_lucid46.Data.to(
5439
+ parseLrpDatumOrThrow(spentLrpDatum).maxPrice,
5440
+ OnChainDecimal,
5441
+ {
5442
+ canonical: true
5443
+ }
5444
+ )
5445
+ );
5446
+ if (isSpentDatumCanonical) {
5447
+ const ocdSerialisedCanonical = import_lucid46.Data.to(
5448
+ datum.maxPrice,
5449
+ OnChainDecimal,
5450
+ { canonical: true }
5451
+ );
5452
+ const ocdSerialisedNonCanonical = import_lucid46.Data.to(
5453
+ datum.maxPrice,
5454
+ OnChainDecimal,
5455
+ { canonical: false }
5456
+ );
5457
+ return d.replace(ocdSerialisedNonCanonical, ocdSerialisedCanonical);
5458
+ }
5459
+ return d;
5460
+ }
5461
+ ).exhaustive();
5439
5462
  }
5440
5463
  function serialiseLrpRedeemer(redeemer) {
5441
5464
  return import_lucid46.Data.to(redeemer, LRPRedeemer);
@@ -5478,7 +5501,7 @@ function insertSorted(arr, item, ord) {
5478
5501
  }
5479
5502
 
5480
5503
  // src/contracts/lrp/helpers.ts
5481
- var import_ts_pattern12 = require("ts-pattern");
5504
+ var import_ts_pattern13 = require("ts-pattern");
5482
5505
  var MIN_LRP_COLLATERAL_AMT = 2000000n;
5483
5506
  function lrpRedeemableLovelacesInclReimb(lrp, lrpParams) {
5484
5507
  const datum = lrp[1];
@@ -5495,8 +5518,8 @@ function lrpRedeemableLovelacesInclReimb(lrp, lrpParams) {
5495
5518
  return res;
5496
5519
  }
5497
5520
  function buildRedemptionsTx(redemptions, price, redemptionReimbursementPercentage, sysParams, tx, txOutputsBeforeCount) {
5498
- const [[mainLrpUtxo, _], __] = (0, import_ts_pattern12.match)(redemptions).with(
5499
- [import_ts_pattern12.P._, ...import_ts_pattern12.P.array()],
5521
+ const [[mainLrpUtxo, _], __] = (0, import_ts_pattern13.match)(redemptions).with(
5522
+ [import_ts_pattern13.P._, ...import_ts_pattern13.P.array()],
5500
5523
  ([[firstLrp, _2], ...rest]) => [
5501
5524
  [firstLrp, _2],
5502
5525
  rest
@@ -5520,7 +5543,8 @@ function buildRedemptionsTx(redemptions, price, redemptionReimbursementPercentag
5520
5543
  redemptionReimbursementPercentage,
5521
5544
  lovelacesForRedemption
5522
5545
  );
5523
- const lrpDatum = parseLrpDatumOrThrow(getInlineDatumOrThrow(lrpUtxo));
5546
+ const lrpRawInlineDatum = getInlineDatumOrThrow(lrpUtxo);
5547
+ const lrpDatum = parseLrpDatumOrThrow(lrpRawInlineDatum);
5524
5548
  const resultVal = (0, import_lucid47.addAssets)(
5525
5549
  lrpUtxo.assets,
5526
5550
  mkLovelacesOf(-lovelacesForRedemption + reimburstmentLovelaces),
@@ -5555,10 +5579,13 @@ function buildRedemptionsTx(redemptions, price, redemptionReimbursementPercentag
5555
5579
  lrpUtxo.address,
5556
5580
  {
5557
5581
  kind: "inline",
5558
- value: serialiseLrpDatum({
5559
- ...lrpDatum,
5560
- lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
5561
- })
5582
+ value: serialiseLrpDatum(
5583
+ {
5584
+ ...lrpDatum,
5585
+ lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
5586
+ },
5587
+ { _tag: "adaptiveReplace", spentLrpDatum: lrpRawInlineDatum }
5588
+ )
5562
5589
  },
5563
5590
  resultVal
5564
5591
  );
package/dist/index.mjs CHANGED
@@ -3386,7 +3386,12 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
3386
3386
  BigInt(validityFrom),
3387
3387
  indyStakedAmt
3388
3388
  );
3389
- return lucid.newTx().validFrom(validityFrom).validTo(Number(pollShardDatum.votingEndTime) - ONE_SECOND).readFrom([stakingRefScriptUtxo, pollShardRefScriptUtxo]).collectFrom([stakingPosUtxo], serialiseStakingRedeemer("Lock")).collectFrom(
3389
+ return lucid.newTx().validFrom(validityFrom).validTo(
3390
+ Math.min(
3391
+ Number(pollShardDatum.votingEndTime) - ONE_SECOND,
3392
+ Number(currentTime) + Number(sysParams.govParams.gBiasTime) - ONE_SECOND
3393
+ )
3394
+ ).readFrom([stakingRefScriptUtxo, pollShardRefScriptUtxo]).collectFrom([stakingPosUtxo], serialiseStakingRedeemer("Lock")).collectFrom(
3390
3395
  [pollShardUtxo],
3391
3396
  serialisePollShardRedeemer({ Vote: { content: voteOption } })
3392
3397
  ).pay.ToContract(
@@ -5211,6 +5216,7 @@ import { addAssets as addAssets8 } from "@lucid-evolution/lucid";
5211
5216
  // src/contracts/lrp/types.ts
5212
5217
  import { Data as Data26 } from "@lucid-evolution/lucid";
5213
5218
  import { option as O8, function as F9 } from "fp-ts";
5219
+ import { match as match12, P as P11 } from "ts-pattern";
5214
5220
  var LRPParamsSchema = Data26.Object({
5215
5221
  versionRecordToken: AssetClassSchema,
5216
5222
  iassetNft: AssetClassSchema,
@@ -5260,19 +5266,36 @@ function parseLrpDatumOrThrow(datum) {
5260
5266
  }, F9.identity)
5261
5267
  );
5262
5268
  }
5263
- function serialiseLrpDatum(datum) {
5269
+ function serialiseLrpDatum(datum, serialisationOptions = { _tag: "noReplace" }) {
5264
5270
  const d = Data26.to(datum, LRPDatum);
5265
- const ocdSerialisedCanonical = Data26.to(
5266
- datum.maxPrice,
5267
- OnChainDecimal,
5268
- { canonical: true }
5269
- );
5270
- const ocdSerialisedNonCanonical = Data26.to(
5271
- datum.maxPrice,
5272
- OnChainDecimal,
5273
- { canonical: false }
5274
- );
5275
- return d.replace(ocdSerialisedNonCanonical, ocdSerialisedCanonical);
5271
+ return match12(serialisationOptions).returnType().with({ _tag: "noReplace" }, () => d).with(
5272
+ { _tag: "adaptiveReplace", spentLrpDatum: P11.select() },
5273
+ (spentLrpDatum) => {
5274
+ const isSpentDatumCanonical = spentLrpDatum.includes(
5275
+ Data26.to(
5276
+ parseLrpDatumOrThrow(spentLrpDatum).maxPrice,
5277
+ OnChainDecimal,
5278
+ {
5279
+ canonical: true
5280
+ }
5281
+ )
5282
+ );
5283
+ if (isSpentDatumCanonical) {
5284
+ const ocdSerialisedCanonical = Data26.to(
5285
+ datum.maxPrice,
5286
+ OnChainDecimal,
5287
+ { canonical: true }
5288
+ );
5289
+ const ocdSerialisedNonCanonical = Data26.to(
5290
+ datum.maxPrice,
5291
+ OnChainDecimal,
5292
+ { canonical: false }
5293
+ );
5294
+ return d.replace(ocdSerialisedNonCanonical, ocdSerialisedCanonical);
5295
+ }
5296
+ return d;
5297
+ }
5298
+ ).exhaustive();
5276
5299
  }
5277
5300
  function serialiseLrpRedeemer(redeemer) {
5278
5301
  return Data26.to(redeemer, LRPRedeemer);
@@ -5315,7 +5338,7 @@ function insertSorted(arr, item, ord) {
5315
5338
  }
5316
5339
 
5317
5340
  // src/contracts/lrp/helpers.ts
5318
- import { match as match12, P as P11 } from "ts-pattern";
5341
+ import { match as match13, P as P12 } from "ts-pattern";
5319
5342
  var MIN_LRP_COLLATERAL_AMT = 2000000n;
5320
5343
  function lrpRedeemableLovelacesInclReimb(lrp, lrpParams) {
5321
5344
  const datum = lrp[1];
@@ -5332,8 +5355,8 @@ function lrpRedeemableLovelacesInclReimb(lrp, lrpParams) {
5332
5355
  return res;
5333
5356
  }
5334
5357
  function buildRedemptionsTx(redemptions, price, redemptionReimbursementPercentage, sysParams, tx, txOutputsBeforeCount) {
5335
- const [[mainLrpUtxo, _], __] = match12(redemptions).with(
5336
- [P11._, ...P11.array()],
5358
+ const [[mainLrpUtxo, _], __] = match13(redemptions).with(
5359
+ [P12._, ...P12.array()],
5337
5360
  ([[firstLrp, _2], ...rest]) => [
5338
5361
  [firstLrp, _2],
5339
5362
  rest
@@ -5357,7 +5380,8 @@ function buildRedemptionsTx(redemptions, price, redemptionReimbursementPercentag
5357
5380
  redemptionReimbursementPercentage,
5358
5381
  lovelacesForRedemption
5359
5382
  );
5360
- const lrpDatum = parseLrpDatumOrThrow(getInlineDatumOrThrow(lrpUtxo));
5383
+ const lrpRawInlineDatum = getInlineDatumOrThrow(lrpUtxo);
5384
+ const lrpDatum = parseLrpDatumOrThrow(lrpRawInlineDatum);
5361
5385
  const resultVal = addAssets8(
5362
5386
  lrpUtxo.assets,
5363
5387
  mkLovelacesOf(-lovelacesForRedemption + reimburstmentLovelaces),
@@ -5392,10 +5416,13 @@ function buildRedemptionsTx(redemptions, price, redemptionReimbursementPercentag
5392
5416
  lrpUtxo.address,
5393
5417
  {
5394
5418
  kind: "inline",
5395
- value: serialiseLrpDatum({
5396
- ...lrpDatum,
5397
- lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
5398
- })
5419
+ value: serialiseLrpDatum(
5420
+ {
5421
+ ...lrpDatum,
5422
+ lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
5423
+ },
5424
+ { _tag: "adaptiveReplace", spentLrpDatum: lrpRawInlineDatum }
5425
+ )
5399
5426
  },
5400
5427
  resultVal
5401
5428
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigo-labs/indigo-sdk",
3
- "version": "0.2.33",
3
+ "version": "0.2.35",
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",
@@ -465,7 +465,14 @@ export async function vote(
465
465
  return lucid
466
466
  .newTx()
467
467
  .validFrom(validityFrom)
468
- .validTo(Number(pollShardDatum.votingEndTime) - ONE_SECOND)
468
+ .validTo(
469
+ Math.min(
470
+ Number(pollShardDatum.votingEndTime) - ONE_SECOND,
471
+ Number(currentTime) +
472
+ Number(sysParams.govParams.gBiasTime) -
473
+ ONE_SECOND,
474
+ ),
475
+ )
469
476
  .readFrom([stakingRefScriptUtxo, pollShardRefScriptUtxo])
470
477
  .collectFrom([stakingPosUtxo], serialiseStakingRedeemer('Lock'))
471
478
  .collectFrom(
@@ -93,7 +93,8 @@ export function buildRedemptionsTx(
93
93
  lovelacesForRedemption,
94
94
  );
95
95
 
96
- const lrpDatum = parseLrpDatumOrThrow(getInlineDatumOrThrow(lrpUtxo));
96
+ const lrpRawInlineDatum = getInlineDatumOrThrow(lrpUtxo);
97
+ const lrpDatum = parseLrpDatumOrThrow(lrpRawInlineDatum);
97
98
 
98
99
  const resultVal = addAssets(
99
100
  lrpUtxo.assets,
@@ -137,11 +138,14 @@ export function buildRedemptionsTx(
137
138
  lrpUtxo.address,
138
139
  {
139
140
  kind: 'inline',
140
- value: serialiseLrpDatum({
141
- ...lrpDatum,
142
- lovelacesToSpend:
143
- lrpDatum.lovelacesToSpend - lovelacesForRedemption,
144
- }),
141
+ value: serialiseLrpDatum(
142
+ {
143
+ ...lrpDatum,
144
+ lovelacesToSpend:
145
+ lrpDatum.lovelacesToSpend - lovelacesForRedemption,
146
+ },
147
+ { _tag: 'adaptiveReplace', spentLrpDatum: lrpRawInlineDatum },
148
+ ),
145
149
  },
146
150
  resultVal,
147
151
  );
@@ -5,6 +5,7 @@ import {
5
5
  OnChainDecimalSchema,
6
6
  } from '../../types/on-chain-decimal';
7
7
  import { option as O, function as F } from 'fp-ts';
8
+ import { match, P } from 'ts-pattern';
8
9
 
9
10
  export const LRPParamsSchema = Data.Object({
10
11
  versionRecordToken: AssetClassSchema,
@@ -63,27 +64,60 @@ export function parseLrpDatumOrThrow(datum: Datum): LRPDatum {
63
64
  );
64
65
  }
65
66
 
66
- export function serialiseLrpDatum(datum: LRPDatum): Datum {
67
+ type LRPSerialisationOptions =
68
+ // No replacing, just use non-canonical format.
69
+ | { _tag: 'noReplace' }
70
+ // Adaptive replace, when the spentDatum is canonical, do the replace,
71
+ // otherwise use the non canonical.
72
+ | { _tag: 'adaptiveReplace'; spentLrpDatum: string };
73
+
74
+ export function serialiseLrpDatum(
75
+ datum: LRPDatum,
76
+ // Overall, we don't want to do the replacing. We just use non-canonical format.
77
+ serialisationOptions: LRPSerialisationOptions = { _tag: 'noReplace' },
78
+ ): Datum {
67
79
  const d = Data.to<LRPDatum>(datum, LRPDatum);
68
80
 
69
- // If the lrp was created using a canonical on-chain decimal, we need to serialise it canonically.
70
- // This is due to some issue related to how Aiken compares objects.
71
- // See "Wrong continuing output" trace, specifically the spread of the previous datum ie. expecting the serialisation to be the same as it was created with
72
- // We however do not want to do this for any lrps that are being build canonical.
73
- const ocdSerialisedCanonical = Data.to<OnChainDecimal>(
74
- datum.maxPrice,
75
- OnChainDecimal,
76
- { canonical: true },
77
- );
78
- const ocdSerialisedNonCanonical = Data.to<OnChainDecimal>(
79
- datum.maxPrice,
80
- OnChainDecimal,
81
- { canonical: false },
82
- );
81
+ return match(serialisationOptions)
82
+ .returnType<Datum>()
83
+ .with({ _tag: 'noReplace' }, () => d)
84
+ .with(
85
+ { _tag: 'adaptiveReplace', spentLrpDatum: P.select() },
86
+ (spentLrpDatum) => {
87
+ const isSpentDatumCanonical = spentLrpDatum.includes(
88
+ Data.to<OnChainDecimal>(
89
+ parseLrpDatumOrThrow(spentLrpDatum).maxPrice,
90
+ OnChainDecimal,
91
+ {
92
+ canonical: true,
93
+ },
94
+ ),
95
+ );
96
+
97
+ // When spent datum was canonical, replace.
98
+ if (isSpentDatumCanonical) {
99
+ // If the lrp was created using a canonical on-chain decimal, we need to serialise it canonically.
100
+ // This is due to some issue related to how Aiken compares objects.
101
+ // See "Wrong continuing output" trace, specifically the spread of the previous datum ie. expecting the serialisation to be the same as it was created with
102
+ // We however do not want to do this for any lrps that are being build canonical.
103
+ const ocdSerialisedCanonical = Data.to<OnChainDecimal>(
104
+ datum.maxPrice,
105
+ OnChainDecimal,
106
+ { canonical: true },
107
+ );
108
+ const ocdSerialisedNonCanonical = Data.to<OnChainDecimal>(
109
+ datum.maxPrice,
110
+ OnChainDecimal,
111
+ { canonical: false },
112
+ );
83
113
 
84
- return d.replace(ocdSerialisedNonCanonical, ocdSerialisedCanonical);
114
+ return d.replace(ocdSerialisedNonCanonical, ocdSerialisedCanonical);
115
+ }
85
116
 
86
- // return d;
117
+ return d;
118
+ },
119
+ )
120
+ .exhaustive();
87
121
  }
88
122
 
89
123
  export function serialiseLrpRedeemer(redeemer: LRPRedeemer): Redeemer {
@@ -2,7 +2,6 @@ import { Core as EvoCore } from '@evolution-sdk/evolution';
2
2
  import { match, P } from 'ts-pattern';
3
3
  import { AddressSchema } from '@3rd-eye-labs/cardano-offchain-common';
4
4
  import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
5
- import { Data } from '@lucid-evolution/lucid';
6
5
 
7
6
  export const SPIntegerSchema = EvoCore.TSchema.Struct({
8
7
  value: EvoCore.TSchema.Integer,
@@ -2,7 +2,6 @@ import { Core as EvoCore } from '@evolution-sdk/evolution';
2
2
  import { option as O, function as F } from 'fp-ts';
3
3
  import { match, P } from 'ts-pattern';
4
4
  import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
5
- import { Data } from '@lucid-evolution/lucid';
6
5
 
7
6
  const StakingPosLockedAmtSchema = EvoCore.TSchema.Map(
8
7
  EvoCore.TSchema.Integer,