@indigo-labs/indigo-sdk 0.1.15 → 0.1.16

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
@@ -2901,6 +2901,8 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
2901
2901
  lovelacesForRedemption
2902
2902
  );
2903
2903
  const lrpDatum = parseLrpDatum(getInlineDatumOrThrow(lrpUtxo));
2904
+ const outputLovelacesAmt = lrpUtxo.assets.lovelace - lovelacesForRedemption + reimburstmentLovelaces;
2905
+ const assetUnit = (0, import_lucid34.toUnit)(lrpParams.iassetPolicyId, mainLrpDatum.iasset);
2904
2906
  return acc.collectFrom(
2905
2907
  [lrpUtxo],
2906
2908
  serialiseLrpRedeemer(
@@ -2926,17 +2928,10 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
2926
2928
  lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
2927
2929
  })
2928
2930
  },
2929
- (0, import_lucid34.addAssets)(
2930
- lrpUtxo.assets,
2931
- mkLovelacesOf(-(lovelacesForRedemption - reimburstmentLovelaces)),
2932
- mkAssetsOf(
2933
- {
2934
- currencySymbol: lrpParams.iassetPolicyId,
2935
- tokenName: mainLrpDatum.iasset
2936
- },
2937
- redeemIAssetAmt
2938
- )
2939
- )
2931
+ {
2932
+ lovelace: outputLovelacesAmt,
2933
+ [assetUnit]: redeemIAssetAmt + (lrpUtxo.assets[assetUnit] ?? 0n)
2934
+ }
2940
2935
  );
2941
2936
  }
2942
2937
  )(redemptionLrps);
package/dist/index.mjs CHANGED
@@ -2731,7 +2731,8 @@ function castLrpParams(params) {
2731
2731
  import {
2732
2732
  addAssets as addAssets3,
2733
2733
  unixTimeToSlot as unixTimeToSlot2,
2734
- slotToUnixTime as slotToUnixTime3
2734
+ slotToUnixTime as slotToUnixTime3,
2735
+ toUnit as toUnit4
2735
2736
  } from "@lucid-evolution/lucid";
2736
2737
  import { match as match5, P as P5 } from "ts-pattern";
2737
2738
  import { unzip, zip } from "fp-ts/lib/Array";
@@ -2809,6 +2810,8 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
2809
2810
  lovelacesForRedemption
2810
2811
  );
2811
2812
  const lrpDatum = parseLrpDatum(getInlineDatumOrThrow(lrpUtxo));
2813
+ const outputLovelacesAmt = lrpUtxo.assets.lovelace - lovelacesForRedemption + reimburstmentLovelaces;
2814
+ const assetUnit = toUnit4(lrpParams.iassetPolicyId, mainLrpDatum.iasset);
2812
2815
  return acc.collectFrom(
2813
2816
  [lrpUtxo],
2814
2817
  serialiseLrpRedeemer(
@@ -2834,17 +2837,10 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
2834
2837
  lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
2835
2838
  })
2836
2839
  },
2837
- addAssets3(
2838
- lrpUtxo.assets,
2839
- mkLovelacesOf(-(lovelacesForRedemption - reimburstmentLovelaces)),
2840
- mkAssetsOf(
2841
- {
2842
- currencySymbol: lrpParams.iassetPolicyId,
2843
- tokenName: mainLrpDatum.iasset
2844
- },
2845
- redeemIAssetAmt
2846
- )
2847
- )
2840
+ {
2841
+ lovelace: outputLovelacesAmt,
2842
+ [assetUnit]: redeemIAssetAmt + (lrpUtxo.assets[assetUnit] ?? 0n)
2843
+ }
2848
2844
  );
2849
2845
  }
2850
2846
  )(redemptionLrps);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigo-labs/indigo-sdk",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
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",
@@ -9,6 +9,7 @@ import {
9
9
  addAssets,
10
10
  unixTimeToSlot,
11
11
  slotToUnixTime,
12
+ toUnit,
12
13
  } from '@lucid-evolution/lucid';
13
14
  import {
14
15
  addrDetails,
@@ -158,6 +159,8 @@ export async function redeemLrp(
158
159
  );
159
160
 
160
161
  const lrpDatum = parseLrpDatum(getInlineDatumOrThrow(lrpUtxo));
162
+ const outputLovelacesAmt = lrpUtxo.assets.lovelace - lovelacesForRedemption + reimburstmentLovelaces;
163
+ const assetUnit = toUnit(lrpParams.iassetPolicyId, mainLrpDatum.iasset);
161
164
 
162
165
  return acc
163
166
  .collectFrom(
@@ -190,17 +193,10 @@ export async function redeemLrp(
190
193
  lrpDatum.lovelacesToSpend - lovelacesForRedemption,
191
194
  }),
192
195
  },
193
- addAssets(
194
- lrpUtxo.assets,
195
- mkLovelacesOf(-(lovelacesForRedemption - reimburstmentLovelaces)),
196
- mkAssetsOf(
197
- {
198
- currencySymbol: lrpParams.iassetPolicyId,
199
- tokenName: mainLrpDatum.iasset,
200
- },
201
- redeemIAssetAmt,
202
- ),
203
- ),
196
+ {
197
+ lovelace: outputLovelacesAmt,
198
+ [assetUnit]: redeemIAssetAmt + (lrpUtxo.assets[assetUnit] ?? 0n),
199
+ }
204
200
  );
205
201
  },
206
202
  )(redemptionLrps);
package/tests/lrp.test.ts CHANGED
@@ -495,7 +495,7 @@ describe('LRP', () => {
495
495
  );
496
496
  });
497
497
 
498
- it('single redemption and cancel', async () => {
498
+ it('redeem, redeem again and cancel', async () => {
499
499
  const network: Network = 'Custom';
500
500
  const account1 = generateEmulatorAccount({
501
501
  lovelace: 80_000_000_000n, // 80,000 ADA
@@ -601,15 +601,39 @@ describe('LRP', () => {
601
601
 
602
602
  const redeemedLrp = await findSingleOwnLrp();
603
603
 
604
+ await runAndAwaitTx(
605
+ lucid,
606
+ redeemLrp(
607
+ [[redeemedLrp, redemptionIAssetAmt]],
608
+ lrpRefScriptOutRef,
609
+ await findPriceOracle(
610
+ lucid,
611
+ network,
612
+ testCtx.oracleValHash,
613
+ testCtx.oracleNft,
614
+ ),
615
+ await findIAsset(
616
+ lucid,
617
+ testCtx.iassetValHash,
618
+ testCtx.iassetNft,
619
+ toText(iassetTokenName),
620
+ ),
621
+ lucid,
622
+ lrpParams,
623
+ network,
624
+ ),
625
+ );
626
+
604
627
  strictEqual(
605
628
  assetClassValueOf(redeemedLrp.assets, redemptionAsset),
606
629
  redemptionIAssetAmt,
607
630
  'LRP has wrong number of iassets after redemption',
608
631
  );
632
+ const closableLrp = await findSingleOwnLrp();
609
633
 
610
634
  await runAndAwaitTx(
611
635
  lucid,
612
- cancelLrp(redeemedLrp, lrpRefScriptOutRef, lucid),
636
+ cancelLrp(closableLrp, lrpRefScriptOutRef, lucid),
613
637
  );
614
638
  });
615
639