@indigo-labs/indigo-sdk 0.2.32 → 0.2.34

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
@@ -322,6 +322,7 @@ declare const OnChainDecimalSchema: _lucid_evolution_lucid.TObject<{
322
322
  getOnChainInt: _lucid_evolution_lucid.TUnsafe<bigint>;
323
323
  }>;
324
324
  type OnChainDecimal = Data.Static<typeof OnChainDecimalSchema>;
325
+ declare const OnChainDecimal: OnChainDecimal;
325
326
 
326
327
  declare const CdpParamsSchema: _lucid_evolution_lucid.TObject<{
327
328
  cdp_auth_token: _lucid_evolution_lucid.TObject<{
@@ -2012,7 +2013,13 @@ declare const LRPRedeemerSchema: _lucid_evolution_lucid.TUnion<(_lucid_evolution
2012
2013
  type LRPRedeemer = Data.Static<typeof LRPRedeemerSchema>;
2013
2014
  declare function parseLrpDatum(datum: Datum): option.Option<LRPDatum>;
2014
2015
  declare function parseLrpDatumOrThrow(datum: Datum): LRPDatum;
2015
- 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;
2016
2023
  declare function serialiseLrpRedeemer(redeemer: LRPRedeemer): Redeemer;
2017
2024
  declare function castLrpParams(params: LRPParams): Data;
2018
2025
  type LrpOutput = {
package/dist/index.d.ts CHANGED
@@ -322,6 +322,7 @@ declare const OnChainDecimalSchema: _lucid_evolution_lucid.TObject<{
322
322
  getOnChainInt: _lucid_evolution_lucid.TUnsafe<bigint>;
323
323
  }>;
324
324
  type OnChainDecimal = Data.Static<typeof OnChainDecimalSchema>;
325
+ declare const OnChainDecimal: OnChainDecimal;
325
326
 
326
327
  declare const CdpParamsSchema: _lucid_evolution_lucid.TObject<{
327
328
  cdp_auth_token: _lucid_evolution_lucid.TObject<{
@@ -2012,7 +2013,13 @@ declare const LRPRedeemerSchema: _lucid_evolution_lucid.TUnion<(_lucid_evolution
2012
2013
  type LRPRedeemer = Data.Static<typeof LRPRedeemerSchema>;
2013
2014
  declare function parseLrpDatum(datum: Datum): option.Option<LRPDatum>;
2014
2015
  declare function parseLrpDatumOrThrow(datum: Datum): LRPDatum;
2015
- 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;
2016
2023
  declare function serialiseLrpRedeemer(redeemer: LRPRedeemer): Redeemer;
2017
2024
  declare function castLrpParams(params: LRPParams): Data;
2018
2025
  type LrpOutput = {
package/dist/index.js CHANGED
@@ -414,6 +414,7 @@ var OCD_DECIMAL_UNIT = 1000000n;
414
414
  var OnChainDecimalSchema = import_lucid4.Data.Object({
415
415
  getOnChainInt: import_lucid4.Data.Integer()
416
416
  });
417
+ var OnChainDecimal = OnChainDecimalSchema;
417
418
  function ocdCeil(a) {
418
419
  const whole = a.getOnChainInt / OCD_DECIMAL_UNIT;
419
420
  return a.getOnChainInt > whole * OCD_DECIMAL_UNIT ? whole + 1n : whole;
@@ -5373,6 +5374,7 @@ var import_lucid47 = require("@lucid-evolution/lucid");
5373
5374
  // src/contracts/lrp/types.ts
5374
5375
  var import_lucid46 = require("@lucid-evolution/lucid");
5375
5376
  var import_fp_ts11 = require("fp-ts");
5377
+ var import_ts_pattern12 = require("ts-pattern");
5376
5378
  var LRPParamsSchema = import_lucid46.Data.Object({
5377
5379
  versionRecordToken: AssetClassSchema,
5378
5380
  iassetNft: AssetClassSchema,
@@ -5422,11 +5424,39 @@ function parseLrpDatumOrThrow(datum) {
5422
5424
  }, import_fp_ts11.function.identity)
5423
5425
  );
5424
5426
  }
5425
- function serialiseLrpDatum(datum) {
5426
- return import_lucid46.Data.to(datum, LRPDatum);
5427
+ function serialiseLrpDatum(datum, serialisationOptions = { _tag: "noReplace" }) {
5428
+ const d = import_lucid46.Data.to(datum, LRPDatum);
5429
+ return (0, import_ts_pattern12.match)(serialisationOptions).returnType().with({ _tag: "noReplace" }, () => d).with(
5430
+ { _tag: "adaptiveReplace", spentLrpDatum: import_ts_pattern12.P.select() },
5431
+ (spentLrpDatum) => {
5432
+ const isSpentDatumCanonical = spentLrpDatum.includes(
5433
+ import_lucid46.Data.to(
5434
+ parseLrpDatumOrThrow(spentLrpDatum).maxPrice,
5435
+ OnChainDecimal,
5436
+ {
5437
+ canonical: true
5438
+ }
5439
+ )
5440
+ );
5441
+ if (isSpentDatumCanonical) {
5442
+ const ocdSerialisedCanonical = import_lucid46.Data.to(
5443
+ datum.maxPrice,
5444
+ OnChainDecimal,
5445
+ { canonical: true }
5446
+ );
5447
+ const ocdSerialisedNonCanonical = import_lucid46.Data.to(
5448
+ datum.maxPrice,
5449
+ OnChainDecimal,
5450
+ { canonical: false }
5451
+ );
5452
+ return d.replace(ocdSerialisedNonCanonical, ocdSerialisedCanonical);
5453
+ }
5454
+ return d;
5455
+ }
5456
+ ).exhaustive();
5427
5457
  }
5428
5458
  function serialiseLrpRedeemer(redeemer) {
5429
- return import_lucid46.Data.to(redeemer, LRPRedeemer, { canonical: false });
5459
+ return import_lucid46.Data.to(redeemer, LRPRedeemer);
5430
5460
  }
5431
5461
  function castLrpParams(params) {
5432
5462
  return import_lucid46.Data.castTo(params, LRPParams);
@@ -5466,7 +5496,7 @@ function insertSorted(arr, item, ord) {
5466
5496
  }
5467
5497
 
5468
5498
  // src/contracts/lrp/helpers.ts
5469
- var import_ts_pattern12 = require("ts-pattern");
5499
+ var import_ts_pattern13 = require("ts-pattern");
5470
5500
  var MIN_LRP_COLLATERAL_AMT = 2000000n;
5471
5501
  function lrpRedeemableLovelacesInclReimb(lrp, lrpParams) {
5472
5502
  const datum = lrp[1];
@@ -5483,8 +5513,8 @@ function lrpRedeemableLovelacesInclReimb(lrp, lrpParams) {
5483
5513
  return res;
5484
5514
  }
5485
5515
  function buildRedemptionsTx(redemptions, price, redemptionReimbursementPercentage, sysParams, tx, txOutputsBeforeCount) {
5486
- const [[mainLrpUtxo, _], __] = (0, import_ts_pattern12.match)(redemptions).with(
5487
- [import_ts_pattern12.P._, ...import_ts_pattern12.P.array()],
5516
+ const [[mainLrpUtxo, _], __] = (0, import_ts_pattern13.match)(redemptions).with(
5517
+ [import_ts_pattern13.P._, ...import_ts_pattern13.P.array()],
5488
5518
  ([[firstLrp, _2], ...rest]) => [
5489
5519
  [firstLrp, _2],
5490
5520
  rest
@@ -5508,7 +5538,8 @@ function buildRedemptionsTx(redemptions, price, redemptionReimbursementPercentag
5508
5538
  redemptionReimbursementPercentage,
5509
5539
  lovelacesForRedemption
5510
5540
  );
5511
- const lrpDatum = parseLrpDatumOrThrow(getInlineDatumOrThrow(lrpUtxo));
5541
+ const lrpRawInlineDatum = getInlineDatumOrThrow(lrpUtxo);
5542
+ const lrpDatum = parseLrpDatumOrThrow(lrpRawInlineDatum);
5512
5543
  const resultVal = (0, import_lucid47.addAssets)(
5513
5544
  lrpUtxo.assets,
5514
5545
  mkLovelacesOf(-lovelacesForRedemption + reimburstmentLovelaces),
@@ -5543,10 +5574,13 @@ function buildRedemptionsTx(redemptions, price, redemptionReimbursementPercentag
5543
5574
  lrpUtxo.address,
5544
5575
  {
5545
5576
  kind: "inline",
5546
- value: serialiseLrpDatum({
5547
- ...lrpDatum,
5548
- lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
5549
- })
5577
+ value: serialiseLrpDatum(
5578
+ {
5579
+ ...lrpDatum,
5580
+ lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
5581
+ },
5582
+ { _tag: "adaptiveReplace", spentLrpDatum: lrpRawInlineDatum }
5583
+ )
5550
5584
  },
5551
5585
  resultVal
5552
5586
  );
package/dist/index.mjs CHANGED
@@ -177,6 +177,7 @@ var OCD_DECIMAL_UNIT = 1000000n;
177
177
  var OnChainDecimalSchema = Data2.Object({
178
178
  getOnChainInt: Data2.Integer()
179
179
  });
180
+ var OnChainDecimal = OnChainDecimalSchema;
180
181
  function ocdCeil(a) {
181
182
  const whole = a.getOnChainInt / OCD_DECIMAL_UNIT;
182
183
  return a.getOnChainInt > whole * OCD_DECIMAL_UNIT ? whole + 1n : whole;
@@ -5210,6 +5211,7 @@ import { addAssets as addAssets8 } from "@lucid-evolution/lucid";
5210
5211
  // src/contracts/lrp/types.ts
5211
5212
  import { Data as Data26 } from "@lucid-evolution/lucid";
5212
5213
  import { option as O8, function as F9 } from "fp-ts";
5214
+ import { match as match12, P as P11 } from "ts-pattern";
5213
5215
  var LRPParamsSchema = Data26.Object({
5214
5216
  versionRecordToken: AssetClassSchema,
5215
5217
  iassetNft: AssetClassSchema,
@@ -5259,11 +5261,39 @@ function parseLrpDatumOrThrow(datum) {
5259
5261
  }, F9.identity)
5260
5262
  );
5261
5263
  }
5262
- function serialiseLrpDatum(datum) {
5263
- return Data26.to(datum, LRPDatum);
5264
+ function serialiseLrpDatum(datum, serialisationOptions = { _tag: "noReplace" }) {
5265
+ const d = Data26.to(datum, LRPDatum);
5266
+ return match12(serialisationOptions).returnType().with({ _tag: "noReplace" }, () => d).with(
5267
+ { _tag: "adaptiveReplace", spentLrpDatum: P11.select() },
5268
+ (spentLrpDatum) => {
5269
+ const isSpentDatumCanonical = spentLrpDatum.includes(
5270
+ Data26.to(
5271
+ parseLrpDatumOrThrow(spentLrpDatum).maxPrice,
5272
+ OnChainDecimal,
5273
+ {
5274
+ canonical: true
5275
+ }
5276
+ )
5277
+ );
5278
+ if (isSpentDatumCanonical) {
5279
+ const ocdSerialisedCanonical = Data26.to(
5280
+ datum.maxPrice,
5281
+ OnChainDecimal,
5282
+ { canonical: true }
5283
+ );
5284
+ const ocdSerialisedNonCanonical = Data26.to(
5285
+ datum.maxPrice,
5286
+ OnChainDecimal,
5287
+ { canonical: false }
5288
+ );
5289
+ return d.replace(ocdSerialisedNonCanonical, ocdSerialisedCanonical);
5290
+ }
5291
+ return d;
5292
+ }
5293
+ ).exhaustive();
5264
5294
  }
5265
5295
  function serialiseLrpRedeemer(redeemer) {
5266
- return Data26.to(redeemer, LRPRedeemer, { canonical: false });
5296
+ return Data26.to(redeemer, LRPRedeemer);
5267
5297
  }
5268
5298
  function castLrpParams(params) {
5269
5299
  return Data26.castTo(params, LRPParams);
@@ -5303,7 +5333,7 @@ function insertSorted(arr, item, ord) {
5303
5333
  }
5304
5334
 
5305
5335
  // src/contracts/lrp/helpers.ts
5306
- import { match as match12, P as P11 } from "ts-pattern";
5336
+ import { match as match13, P as P12 } from "ts-pattern";
5307
5337
  var MIN_LRP_COLLATERAL_AMT = 2000000n;
5308
5338
  function lrpRedeemableLovelacesInclReimb(lrp, lrpParams) {
5309
5339
  const datum = lrp[1];
@@ -5320,8 +5350,8 @@ function lrpRedeemableLovelacesInclReimb(lrp, lrpParams) {
5320
5350
  return res;
5321
5351
  }
5322
5352
  function buildRedemptionsTx(redemptions, price, redemptionReimbursementPercentage, sysParams, tx, txOutputsBeforeCount) {
5323
- const [[mainLrpUtxo, _], __] = match12(redemptions).with(
5324
- [P11._, ...P11.array()],
5353
+ const [[mainLrpUtxo, _], __] = match13(redemptions).with(
5354
+ [P12._, ...P12.array()],
5325
5355
  ([[firstLrp, _2], ...rest]) => [
5326
5356
  [firstLrp, _2],
5327
5357
  rest
@@ -5345,7 +5375,8 @@ function buildRedemptionsTx(redemptions, price, redemptionReimbursementPercentag
5345
5375
  redemptionReimbursementPercentage,
5346
5376
  lovelacesForRedemption
5347
5377
  );
5348
- const lrpDatum = parseLrpDatumOrThrow(getInlineDatumOrThrow(lrpUtxo));
5378
+ const lrpRawInlineDatum = getInlineDatumOrThrow(lrpUtxo);
5379
+ const lrpDatum = parseLrpDatumOrThrow(lrpRawInlineDatum);
5349
5380
  const resultVal = addAssets8(
5350
5381
  lrpUtxo.assets,
5351
5382
  mkLovelacesOf(-lovelacesForRedemption + reimburstmentLovelaces),
@@ -5380,10 +5411,13 @@ function buildRedemptionsTx(redemptions, price, redemptionReimbursementPercentag
5380
5411
  lrpUtxo.address,
5381
5412
  {
5382
5413
  kind: "inline",
5383
- value: serialiseLrpDatum({
5384
- ...lrpDatum,
5385
- lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
5386
- })
5414
+ value: serialiseLrpDatum(
5415
+ {
5416
+ ...lrpDatum,
5417
+ lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
5418
+ },
5419
+ { _tag: "adaptiveReplace", spentLrpDatum: lrpRawInlineDatum }
5420
+ )
5387
5421
  },
5388
5422
  resultVal
5389
5423
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigo-labs/indigo-sdk",
3
- "version": "0.2.32",
3
+ "version": "0.2.34",
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",
@@ -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
  );
@@ -1,7 +1,11 @@
1
1
  import { Data, Datum, Redeemer, UTxO } from '@lucid-evolution/lucid';
2
2
  import { AssetClassSchema, OutputReferenceSchema } from '../../types/generic';
3
- import { OnChainDecimalSchema } from '../../types/on-chain-decimal';
3
+ import {
4
+ OnChainDecimal,
5
+ OnChainDecimalSchema,
6
+ } from '../../types/on-chain-decimal';
4
7
  import { option as O, function as F } from 'fp-ts';
8
+ import { match, P } from 'ts-pattern';
5
9
 
6
10
  export const LRPParamsSchema = Data.Object({
7
11
  versionRecordToken: AssetClassSchema,
@@ -60,12 +64,64 @@ export function parseLrpDatumOrThrow(datum: Datum): LRPDatum {
60
64
  );
61
65
  }
62
66
 
63
- export function serialiseLrpDatum(datum: LRPDatum): Datum {
64
- return Data.to<LRPDatum>(datum, LRPDatum);
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 {
79
+ const d = Data.to<LRPDatum>(datum, LRPDatum);
80
+
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
+ );
113
+
114
+ return d.replace(ocdSerialisedNonCanonical, ocdSerialisedCanonical);
115
+ }
116
+
117
+ return d;
118
+ },
119
+ )
120
+ .exhaustive();
65
121
  }
66
122
 
67
123
  export function serialiseLrpRedeemer(redeemer: LRPRedeemer): Redeemer {
68
- return Data.to<LRPRedeemer>(redeemer, LRPRedeemer, { canonical: false });
124
+ return Data.to<LRPRedeemer>(redeemer, LRPRedeemer);
69
125
  }
70
126
 
71
127
  export function castLrpParams(params: LRPParams): Data {
@@ -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,
@@ -6,6 +6,7 @@ export const OnChainDecimalSchema = Data.Object({
6
6
  getOnChainInt: Data.Integer(),
7
7
  });
8
8
  export type OnChainDecimal = Data.Static<typeof OnChainDecimalSchema>;
9
+ export const OnChainDecimal = OnChainDecimalSchema as unknown as OnChainDecimal;
9
10
 
10
11
  export function ocdCeil(a: OnChainDecimal): bigint {
11
12
  const whole = a.getOnChainInt / OCD_DECIMAL_UNIT;