@indigo-labs/indigo-sdk 0.1.15 → 0.1.17
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 +20 -11
- package/dist/index.mjs +22 -12
- package/package.json +1 -1
- package/src/contracts/lrp.ts +21 -11
- package/tests/lrp.test.ts +26 -2
package/dist/index.js
CHANGED
|
@@ -2901,6 +2901,22 @@ 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);
|
|
2906
|
+
console.log(
|
|
2907
|
+
lrpUtxo.address,
|
|
2908
|
+
{
|
|
2909
|
+
kind: "inline",
|
|
2910
|
+
value: serialiseLrpDatum({
|
|
2911
|
+
...lrpDatum,
|
|
2912
|
+
lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
|
|
2913
|
+
})
|
|
2914
|
+
},
|
|
2915
|
+
{
|
|
2916
|
+
lovelace: outputLovelacesAmt,
|
|
2917
|
+
[assetUnit]: redeemIAssetAmt + (lrpUtxo.assets[assetUnit] ?? 0n)
|
|
2918
|
+
}
|
|
2919
|
+
);
|
|
2904
2920
|
return acc.collectFrom(
|
|
2905
2921
|
[lrpUtxo],
|
|
2906
2922
|
serialiseLrpRedeemer(
|
|
@@ -2926,17 +2942,10 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
|
|
|
2926
2942
|
lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
|
|
2927
2943
|
})
|
|
2928
2944
|
},
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
{
|
|
2934
|
-
currencySymbol: lrpParams.iassetPolicyId,
|
|
2935
|
-
tokenName: mainLrpDatum.iasset
|
|
2936
|
-
},
|
|
2937
|
-
redeemIAssetAmt
|
|
2938
|
-
)
|
|
2939
|
-
)
|
|
2945
|
+
{
|
|
2946
|
+
lovelace: outputLovelacesAmt,
|
|
2947
|
+
[assetUnit]: redeemIAssetAmt + (lrpUtxo.assets[assetUnit] ?? 0n)
|
|
2948
|
+
}
|
|
2940
2949
|
);
|
|
2941
2950
|
}
|
|
2942
2951
|
)(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,22 @@ 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);
|
|
2815
|
+
console.log(
|
|
2816
|
+
lrpUtxo.address,
|
|
2817
|
+
{
|
|
2818
|
+
kind: "inline",
|
|
2819
|
+
value: serialiseLrpDatum({
|
|
2820
|
+
...lrpDatum,
|
|
2821
|
+
lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
|
|
2822
|
+
})
|
|
2823
|
+
},
|
|
2824
|
+
{
|
|
2825
|
+
lovelace: outputLovelacesAmt,
|
|
2826
|
+
[assetUnit]: redeemIAssetAmt + (lrpUtxo.assets[assetUnit] ?? 0n)
|
|
2827
|
+
}
|
|
2828
|
+
);
|
|
2812
2829
|
return acc.collectFrom(
|
|
2813
2830
|
[lrpUtxo],
|
|
2814
2831
|
serialiseLrpRedeemer(
|
|
@@ -2834,17 +2851,10 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
|
|
|
2834
2851
|
lovelacesToSpend: lrpDatum.lovelacesToSpend - lovelacesForRedemption
|
|
2835
2852
|
})
|
|
2836
2853
|
},
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
{
|
|
2842
|
-
currencySymbol: lrpParams.iassetPolicyId,
|
|
2843
|
-
tokenName: mainLrpDatum.iasset
|
|
2844
|
-
},
|
|
2845
|
-
redeemIAssetAmt
|
|
2846
|
-
)
|
|
2847
|
-
)
|
|
2854
|
+
{
|
|
2855
|
+
lovelace: outputLovelacesAmt,
|
|
2856
|
+
[assetUnit]: redeemIAssetAmt + (lrpUtxo.assets[assetUnit] ?? 0n)
|
|
2857
|
+
}
|
|
2848
2858
|
);
|
|
2849
2859
|
}
|
|
2850
2860
|
)(redemptionLrps);
|
package/package.json
CHANGED
package/src/contracts/lrp.ts
CHANGED
|
@@ -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,22 @@ 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);
|
|
164
|
+
|
|
165
|
+
console.log(lrpUtxo.address,
|
|
166
|
+
{
|
|
167
|
+
kind: 'inline',
|
|
168
|
+
value: serialiseLrpDatum({
|
|
169
|
+
...lrpDatum,
|
|
170
|
+
lovelacesToSpend:
|
|
171
|
+
lrpDatum.lovelacesToSpend - lovelacesForRedemption,
|
|
172
|
+
}),
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
lovelace: outputLovelacesAmt,
|
|
176
|
+
[assetUnit]: redeemIAssetAmt + (lrpUtxo.assets[assetUnit] ?? 0n),
|
|
177
|
+
});
|
|
161
178
|
|
|
162
179
|
return acc
|
|
163
180
|
.collectFrom(
|
|
@@ -190,17 +207,10 @@ export async function redeemLrp(
|
|
|
190
207
|
lrpDatum.lovelacesToSpend - lovelacesForRedemption,
|
|
191
208
|
}),
|
|
192
209
|
},
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
{
|
|
198
|
-
currencySymbol: lrpParams.iassetPolicyId,
|
|
199
|
-
tokenName: mainLrpDatum.iasset,
|
|
200
|
-
},
|
|
201
|
-
redeemIAssetAmt,
|
|
202
|
-
),
|
|
203
|
-
),
|
|
210
|
+
{
|
|
211
|
+
lovelace: outputLovelacesAmt,
|
|
212
|
+
[assetUnit]: redeemIAssetAmt + (lrpUtxo.assets[assetUnit] ?? 0n),
|
|
213
|
+
}
|
|
204
214
|
);
|
|
205
215
|
},
|
|
206
216
|
)(redemptionLrps);
|
package/tests/lrp.test.ts
CHANGED
|
@@ -495,7 +495,7 @@ describe('LRP', () => {
|
|
|
495
495
|
);
|
|
496
496
|
});
|
|
497
497
|
|
|
498
|
-
it('
|
|
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(
|
|
636
|
+
cancelLrp(closableLrp, lrpRefScriptOutRef, lucid),
|
|
613
637
|
);
|
|
614
638
|
});
|
|
615
639
|
|