@indigo-labs/indigo-sdk 0.1.8 → 0.1.9
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 +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +326 -315
- package/dist/index.mjs +78 -64
- package/package.json +1 -2
- package/src/contracts/cdp.ts +54 -47
- package/src/contracts/lrp.ts +9 -16
- package/tests/lrp.test.ts +0 -8
- package/tests/stability-pool.test.ts +26 -3
package/dist/index.js
CHANGED
|
@@ -157,7 +157,7 @@ __export(index_exports, {
|
|
|
157
157
|
module.exports = __toCommonJS(index_exports);
|
|
158
158
|
|
|
159
159
|
// src/contracts/cdp.ts
|
|
160
|
-
var
|
|
160
|
+
var import_lucid13 = require("@lucid-evolution/lucid");
|
|
161
161
|
|
|
162
162
|
// src/helpers/asset-helpers.ts
|
|
163
163
|
var import_lucid5 = require("@lucid-evolution/lucid");
|
|
@@ -728,9 +728,27 @@ function calculateAccruedInterest(now, unitaryInterestSnapshot, mintedAmount, in
|
|
|
728
728
|
}
|
|
729
729
|
}
|
|
730
730
|
|
|
731
|
+
// src/helpers/price-oracle-helpers.ts
|
|
732
|
+
var import_lucid12 = require("@lucid-evolution/lucid");
|
|
733
|
+
function oracleExpirationAwareValidity(currentSlot, biasTime, oracleExpiration, network) {
|
|
734
|
+
const validateFrom = (0, import_lucid12.slotToUnixTime)(network, currentSlot - 1);
|
|
735
|
+
const defaultValidateTo = validateFrom + biasTime;
|
|
736
|
+
const cappedValidateTo = (0, import_lucid12.slotToUnixTime)(
|
|
737
|
+
network,
|
|
738
|
+
(0, import_lucid12.unixTimeToSlot)(network, oracleExpiration) - 1
|
|
739
|
+
);
|
|
740
|
+
const isOracleActuallyExpired = cappedValidateTo <= validateFrom;
|
|
741
|
+
return {
|
|
742
|
+
validFrom: validateFrom,
|
|
743
|
+
validTo: isOracleActuallyExpired ? defaultValidateTo : Math.min(defaultValidateTo, cappedValidateTo)
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
|
|
731
747
|
// src/contracts/cdp.ts
|
|
732
748
|
var CDPContract = class _CDPContract {
|
|
733
|
-
static async openPosition(asset, collateralAmount, mintedAmount, params, lucid, assetRef, priceOracleRef, interestOracleRef, cdpCreatorRef, collectorRef
|
|
749
|
+
static async openPosition(asset, collateralAmount, mintedAmount, params, lucid, currentSlot, assetRef, priceOracleRef, interestOracleRef, cdpCreatorRef, collectorRef) {
|
|
750
|
+
const network = lucid.config().network;
|
|
751
|
+
const currentTime = BigInt((0, import_lucid13.slotToUnixTime)(network, currentSlot));
|
|
734
752
|
const [pkh, skh] = await addrDetails(lucid);
|
|
735
753
|
const assetOut = await (assetRef ? IAssetHelpers.findIAssetByRef(assetRef, lucid) : IAssetHelpers.findIAssetByName(asset, params, lucid));
|
|
736
754
|
if (!assetOut || !assetOut.datum) throw new Error("Unable to find IAsset");
|
|
@@ -756,11 +774,11 @@ var CDPContract = class _CDPContract {
|
|
|
756
774
|
);
|
|
757
775
|
const cdpCreatorOut = getRandomElement(
|
|
758
776
|
cdpCreatorRef ? await lucid.utxosByOutRef([cdpCreatorRef]) : await lucid.utxosAtWithUnit(
|
|
759
|
-
(0,
|
|
777
|
+
(0, import_lucid13.credentialToAddress)(network, {
|
|
760
778
|
type: "Script",
|
|
761
779
|
hash: params.validatorHashes.cdpCreatorHash
|
|
762
780
|
}),
|
|
763
|
-
params.cdpCreatorParams.cdpCreatorNft[0].unCurrencySymbol + (0,
|
|
781
|
+
params.cdpCreatorParams.cdpCreatorNft[0].unCurrencySymbol + (0, import_lucid13.fromText)(params.cdpCreatorParams.cdpCreatorNft[1].unTokenName)
|
|
764
782
|
)
|
|
765
783
|
);
|
|
766
784
|
const cdpCreatorRedeemer = castCDPCreatorRedeemer({
|
|
@@ -768,7 +786,7 @@ var CDPContract = class _CDPContract {
|
|
|
768
786
|
cdpOwner: pkh.hash,
|
|
769
787
|
minted: mintedAmount,
|
|
770
788
|
collateral: collateralAmount,
|
|
771
|
-
currentTime
|
|
789
|
+
currentTime
|
|
772
790
|
}
|
|
773
791
|
});
|
|
774
792
|
const cdpCreatorScriptRefUtxo = await scriptRef(
|
|
@@ -776,27 +794,27 @@ var CDPContract = class _CDPContract {
|
|
|
776
794
|
lucid
|
|
777
795
|
);
|
|
778
796
|
const cdpAddress = _CDPContract.address(params.cdpParams, lucid, skh);
|
|
779
|
-
const cdpToken = params.cdpParams.cdpAuthToken[0].unCurrencySymbol + (0,
|
|
797
|
+
const cdpToken = params.cdpParams.cdpAuthToken[0].unCurrencySymbol + (0, import_lucid13.fromText)(params.cdpParams.cdpAuthToken[1].unTokenName);
|
|
780
798
|
const cdpValue = {
|
|
781
799
|
lovelace: collateralAmount
|
|
782
800
|
};
|
|
783
801
|
cdpValue[cdpToken] = 1n;
|
|
784
802
|
const newSnapshot = calculateUnitaryInterestSinceOracleLastUpdated(
|
|
785
|
-
|
|
803
|
+
currentTime,
|
|
786
804
|
interestOracleDatum
|
|
787
805
|
) + interestOracleDatum.unitaryInterest;
|
|
788
806
|
const cdpDatum = {
|
|
789
807
|
cdpOwner: pkh.hash,
|
|
790
|
-
iasset: (0,
|
|
808
|
+
iasset: (0, import_lucid13.fromText)(asset),
|
|
791
809
|
mintedAmt: mintedAmount,
|
|
792
810
|
cdpFees: {
|
|
793
811
|
ActiveCDPInterestTracking: {
|
|
794
|
-
lastSettled:
|
|
812
|
+
lastSettled: currentTime,
|
|
795
813
|
unitaryInterestSnapshot: newSnapshot
|
|
796
814
|
}
|
|
797
815
|
}
|
|
798
816
|
};
|
|
799
|
-
const assetToken = params.cdpParams.cdpAssetSymbol.unCurrencySymbol + (0,
|
|
817
|
+
const assetToken = params.cdpParams.cdpAssetSymbol.unCurrencySymbol + (0, import_lucid13.fromText)(asset);
|
|
800
818
|
const cdpTokenMintValue = {};
|
|
801
819
|
cdpTokenMintValue[cdpToken] = 1n;
|
|
802
820
|
const iassetTokenMintValue = {};
|
|
@@ -813,11 +831,13 @@ var CDPContract = class _CDPContract {
|
|
|
813
831
|
BigInt(assetOut.datum.debtMintingFeePercentage.getOnChainInt),
|
|
814
832
|
mintedAmount * oracleDatum.price.getOnChainInt / 1000000n
|
|
815
833
|
);
|
|
816
|
-
const
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
834
|
+
const txValidity = oracleExpirationAwareValidity(
|
|
835
|
+
currentSlot,
|
|
836
|
+
Number(params.cdpCreatorParams.biasTime),
|
|
837
|
+
Number(oracleDatum.expiration),
|
|
838
|
+
network
|
|
839
|
+
);
|
|
840
|
+
const tx = lucid.newTx().collectFrom([cdpCreatorOut], import_lucid13.Data.to(cdpCreatorRedeemer)).readFrom([cdpCreatorScriptRefUtxo]).pay.ToContract(
|
|
821
841
|
cdpAddress,
|
|
822
842
|
{ kind: "inline", value: serialiseCDPDatum(cdpDatum) },
|
|
823
843
|
cdpValue
|
|
@@ -825,7 +845,7 @@ var CDPContract = class _CDPContract {
|
|
|
825
845
|
cdpCreatorOut.address,
|
|
826
846
|
{ kind: "inline", value: cdpCreatorOut.datum },
|
|
827
847
|
cdpCreatorOut.assets
|
|
828
|
-
).readFrom([oracleOut, interestOracleOut, assetOut.utxo]).mintAssets(cdpTokenMintValue,
|
|
848
|
+
).readFrom([oracleOut, interestOracleOut, assetOut.utxo]).mintAssets(cdpTokenMintValue, import_lucid13.Data.to(new import_lucid13.Constr(0, []))).readFrom([cdpAuthTokenScriptRefUtxo]).mintAssets(iassetTokenMintValue, import_lucid13.Data.to(new import_lucid13.Constr(0, []))).readFrom([iAssetTokenScriptRefUtxo]).addSignerKey(pkh.hash).validFrom(txValidity.validFrom).validTo(txValidity.validTo);
|
|
829
849
|
if (debtMintingFee > 0) {
|
|
830
850
|
await CollectorContract.feeTx(
|
|
831
851
|
debtMintingFee,
|
|
@@ -837,13 +857,14 @@ var CDPContract = class _CDPContract {
|
|
|
837
857
|
}
|
|
838
858
|
return tx;
|
|
839
859
|
}
|
|
840
|
-
static async deposit(cdpRef, amount, params, lucid, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
|
|
860
|
+
static async deposit(cdpRef, amount, params, lucid, currentSlot, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
|
|
841
861
|
return _CDPContract.adjust(
|
|
842
862
|
cdpRef,
|
|
843
863
|
amount,
|
|
844
864
|
0n,
|
|
845
865
|
params,
|
|
846
866
|
lucid,
|
|
867
|
+
currentSlot,
|
|
847
868
|
assetRef,
|
|
848
869
|
priceOracleRef,
|
|
849
870
|
interestOracleRef,
|
|
@@ -852,13 +873,14 @@ var CDPContract = class _CDPContract {
|
|
|
852
873
|
treasuryRef
|
|
853
874
|
);
|
|
854
875
|
}
|
|
855
|
-
static async withdraw(cdpRef, amount, params, lucid, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
|
|
876
|
+
static async withdraw(cdpRef, amount, params, lucid, currentSlot, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
|
|
856
877
|
return _CDPContract.adjust(
|
|
857
878
|
cdpRef,
|
|
858
879
|
-amount,
|
|
859
880
|
0n,
|
|
860
881
|
params,
|
|
861
882
|
lucid,
|
|
883
|
+
currentSlot,
|
|
862
884
|
assetRef,
|
|
863
885
|
priceOracleRef,
|
|
864
886
|
interestOracleRef,
|
|
@@ -867,13 +889,14 @@ var CDPContract = class _CDPContract {
|
|
|
867
889
|
treasuryRef
|
|
868
890
|
);
|
|
869
891
|
}
|
|
870
|
-
static async mint(cdpRef, amount, params, lucid, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
|
|
892
|
+
static async mint(cdpRef, amount, params, lucid, currentSlot, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
|
|
871
893
|
return _CDPContract.adjust(
|
|
872
894
|
cdpRef,
|
|
873
895
|
0n,
|
|
874
896
|
amount,
|
|
875
897
|
params,
|
|
876
898
|
lucid,
|
|
899
|
+
currentSlot,
|
|
877
900
|
assetRef,
|
|
878
901
|
priceOracleRef,
|
|
879
902
|
interestOracleRef,
|
|
@@ -882,13 +905,14 @@ var CDPContract = class _CDPContract {
|
|
|
882
905
|
treasuryRef
|
|
883
906
|
);
|
|
884
907
|
}
|
|
885
|
-
static async burn(cdpRef, amount, params, lucid, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
|
|
908
|
+
static async burn(cdpRef, amount, params, lucid, currentSlot, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
|
|
886
909
|
return _CDPContract.adjust(
|
|
887
910
|
cdpRef,
|
|
888
911
|
0n,
|
|
889
912
|
-amount,
|
|
890
913
|
params,
|
|
891
914
|
lucid,
|
|
915
|
+
currentSlot,
|
|
892
916
|
assetRef,
|
|
893
917
|
priceOracleRef,
|
|
894
918
|
interestOracleRef,
|
|
@@ -897,15 +921,16 @@ var CDPContract = class _CDPContract {
|
|
|
897
921
|
treasuryRef
|
|
898
922
|
);
|
|
899
923
|
}
|
|
900
|
-
static async adjust(cdpRef, collateralAmount, mintAmount, params, lucid, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
|
|
924
|
+
static async adjust(cdpRef, collateralAmount, mintAmount, params, lucid, currentSlot, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
|
|
925
|
+
const network = lucid.config().network;
|
|
901
926
|
const [pkh, _] = await addrDetails(lucid);
|
|
902
|
-
const
|
|
927
|
+
const currentTime = BigInt((0, import_lucid13.slotToUnixTime)(network, currentSlot));
|
|
903
928
|
const cdp = (await lucid.utxosByOutRef([cdpRef]))[0];
|
|
904
929
|
if (!cdp.datum) throw new Error("Unable to find CDP Datum");
|
|
905
930
|
const cdpDatum = parseCDPDatum(cdp.datum);
|
|
906
931
|
const iAsset = await (assetRef ? IAssetHelpers.findIAssetByRef(assetRef, lucid) : IAssetHelpers.findIAssetByName(cdpDatum.iasset, params, lucid));
|
|
907
932
|
const gov = govRef ? (await lucid.utxosByOutRef([govRef]))[0] : await lucid.utxoByUnit(
|
|
908
|
-
params.govParams.govNFT[0].unCurrencySymbol + (0,
|
|
933
|
+
params.govParams.govNFT[0].unCurrencySymbol + (0, import_lucid13.fromText)(params.govParams.govNFT[1].unTokenName)
|
|
909
934
|
);
|
|
910
935
|
if (!gov.datum) throw new Error("Unable to find Gov Datum");
|
|
911
936
|
const govData = parseGovDatum(gov.datum);
|
|
@@ -917,7 +942,7 @@ var CDPContract = class _CDPContract {
|
|
|
917
942
|
cdpAssets["lovelace"] = cdp.assets["lovelace"] + collateralAmount;
|
|
918
943
|
const interestOracleAsset = iAsset.datum.interestOracleNft;
|
|
919
944
|
const interestOracleOut = interestOracleRef ? (await lucid.utxosByOutRef([interestOracleRef]))[0] : await lucid.utxoByUnit(
|
|
920
|
-
interestOracleAsset.currencySymbol + (0,
|
|
945
|
+
interestOracleAsset.currencySymbol + (0, import_lucid13.fromText)(interestOracleAsset.tokenName)
|
|
921
946
|
);
|
|
922
947
|
if (!interestOracleOut.datum)
|
|
923
948
|
return Promise.reject(new Error("Interest Oracle datum not found"));
|
|
@@ -926,14 +951,14 @@ var CDPContract = class _CDPContract {
|
|
|
926
951
|
);
|
|
927
952
|
const tx = lucid.newTx().collectFrom(
|
|
928
953
|
[cdp],
|
|
929
|
-
|
|
954
|
+
import_lucid13.Data.to(new import_lucid13.Constr(0, [currentTime, mintAmount, collateralAmount]))
|
|
930
955
|
).readFrom([iAsset.utxo, gov, cdpScriptRefUtxo]).addSignerKey(pkh.hash);
|
|
931
956
|
if (!cdp.datum) throw new Error("Unable to find CDP Datum");
|
|
932
957
|
const cdpD = parseCDPDatum(cdp.datum);
|
|
933
958
|
if (!("ActiveCDPInterestTracking" in cdpD.cdpFees))
|
|
934
959
|
throw new Error("Invalid CDP Fees");
|
|
935
960
|
const newSnapshot = calculateUnitaryInterestSinceOracleLastUpdated(
|
|
936
|
-
|
|
961
|
+
currentTime,
|
|
937
962
|
interestOracleDatum
|
|
938
963
|
) + interestOracleDatum.unitaryInterest;
|
|
939
964
|
const cdpD_ = {
|
|
@@ -941,7 +966,7 @@ var CDPContract = class _CDPContract {
|
|
|
941
966
|
mintedAmt: cdpD.mintedAmt + mintAmount,
|
|
942
967
|
cdpFees: {
|
|
943
968
|
ActiveCDPInterestTracking: {
|
|
944
|
-
lastSettled:
|
|
969
|
+
lastSettled: currentTime,
|
|
945
970
|
unitaryInterestSnapshot: newSnapshot
|
|
946
971
|
}
|
|
947
972
|
}
|
|
@@ -957,17 +982,19 @@ var CDPContract = class _CDPContract {
|
|
|
957
982
|
const oracleAsset = iAsset.datum.price;
|
|
958
983
|
if (!("Oracle" in oracleAsset)) throw new Error("Invalid oracle asset");
|
|
959
984
|
const oracleRefInput = priceOracleRef ? (await lucid.utxosByOutRef([priceOracleRef]))[0] : await lucid.utxoByUnit(
|
|
960
|
-
oracleAsset.Oracle.oracleNft.asset.currencySymbol + (0,
|
|
985
|
+
oracleAsset.Oracle.oracleNft.asset.currencySymbol + (0, import_lucid13.fromText)(oracleAsset.Oracle.oracleNft.asset.tokenName)
|
|
961
986
|
);
|
|
962
987
|
if (!oracleRefInput.datum)
|
|
963
988
|
return Promise.reject(new Error("Invalid oracle input"));
|
|
964
989
|
const od = parsePriceOracleDatum(oracleRefInput.datum);
|
|
965
990
|
if (!od) return Promise.reject(new Error("Invalid oracle input"));
|
|
966
|
-
const
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
991
|
+
const txValidity = oracleExpirationAwareValidity(
|
|
992
|
+
currentSlot,
|
|
993
|
+
Number(params.cdpCreatorParams.biasTime),
|
|
994
|
+
Number(od.expiration),
|
|
995
|
+
network
|
|
996
|
+
);
|
|
997
|
+
tx.readFrom([oracleRefInput]).validFrom(txValidity.validFrom).validTo(txValidity.validTo);
|
|
971
998
|
let fee = 0n;
|
|
972
999
|
if (collateralAmount < 0) {
|
|
973
1000
|
fee += calculateFeeFromPercentage(
|
|
@@ -982,7 +1009,7 @@ var CDPContract = class _CDPContract {
|
|
|
982
1009
|
);
|
|
983
1010
|
}
|
|
984
1011
|
const interestPaymentAsset = calculateAccruedInterest(
|
|
985
|
-
|
|
1012
|
+
currentTime,
|
|
986
1013
|
cdpD.cdpFees.ActiveCDPInterestTracking.unitaryInterestSnapshot,
|
|
987
1014
|
cdpD.mintedAmt,
|
|
988
1015
|
cdpD.cdpFees.ActiveCDPInterestTracking.lastSettled,
|
|
@@ -1015,7 +1042,7 @@ var CDPContract = class _CDPContract {
|
|
|
1015
1042
|
mintValue[iassetToken] = mintAmount;
|
|
1016
1043
|
tx.readFrom([iAssetTokenScriptRefUtxo]).mintAssets(
|
|
1017
1044
|
mintValue,
|
|
1018
|
-
|
|
1045
|
+
import_lucid13.Data.to(new import_lucid13.Constr(0, []))
|
|
1019
1046
|
);
|
|
1020
1047
|
}
|
|
1021
1048
|
if (fee > 0n) {
|
|
@@ -1023,15 +1050,16 @@ var CDPContract = class _CDPContract {
|
|
|
1023
1050
|
}
|
|
1024
1051
|
return tx;
|
|
1025
1052
|
}
|
|
1026
|
-
static async close(cdpRef, params, lucid, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
|
|
1053
|
+
static async close(cdpRef, params, lucid, currentSlot, assetRef, priceOracleRef, interestOracleRef, collectorRef, govRef, treasuryRef) {
|
|
1054
|
+
const network = lucid.config().network;
|
|
1027
1055
|
const [pkh, _] = await addrDetails(lucid);
|
|
1028
|
-
const
|
|
1056
|
+
const currentTime = BigInt((0, import_lucid13.slotToUnixTime)(network, currentSlot));
|
|
1029
1057
|
const cdp = (await lucid.utxosByOutRef([cdpRef]))[0];
|
|
1030
1058
|
if (!cdp.datum) throw new Error("Unable to find CDP Datum");
|
|
1031
1059
|
const cdpDatum = parseCDPDatum(cdp.datum);
|
|
1032
1060
|
const iAsset = await (assetRef ? IAssetHelpers.findIAssetByRef(assetRef, lucid) : IAssetHelpers.findIAssetByName(cdpDatum.iasset, params, lucid));
|
|
1033
1061
|
const gov = govRef ? (await lucid.utxosByOutRef([govRef]))[0] : await lucid.utxoByUnit(
|
|
1034
|
-
params.govParams.govNFT[0].unCurrencySymbol + (0,
|
|
1062
|
+
params.govParams.govNFT[0].unCurrencySymbol + (0, import_lucid13.fromText)(params.govParams.govNFT[1].unTokenName)
|
|
1035
1063
|
);
|
|
1036
1064
|
if (!gov.datum) throw new Error("Unable to find Gov Datum");
|
|
1037
1065
|
const cdpScriptRefUtxo = await _CDPContract.scriptRef(
|
|
@@ -1040,14 +1068,14 @@ var CDPContract = class _CDPContract {
|
|
|
1040
1068
|
);
|
|
1041
1069
|
const interestOracleAsset = iAsset.datum.interestOracleNft;
|
|
1042
1070
|
const interestOracleOut = interestOracleRef ? (await lucid.utxosByOutRef([interestOracleRef]))[0] : await lucid.utxoByUnit(
|
|
1043
|
-
interestOracleAsset.currencySymbol + (0,
|
|
1071
|
+
interestOracleAsset.currencySymbol + (0, import_lucid13.fromText)(interestOracleAsset.tokenName)
|
|
1044
1072
|
);
|
|
1045
1073
|
if (!interestOracleOut.datum)
|
|
1046
1074
|
return Promise.reject(new Error("Interest Oracle datum not found"));
|
|
1047
1075
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
1048
1076
|
interestOracleOut.datum
|
|
1049
1077
|
);
|
|
1050
|
-
const tx = lucid.newTx().collectFrom([cdp],
|
|
1078
|
+
const tx = lucid.newTx().collectFrom([cdp], import_lucid13.Data.to(new import_lucid13.Constr(1, [currentTime]))).readFrom([iAsset.utxo, gov, cdpScriptRefUtxo]).addSignerKey(pkh.hash);
|
|
1051
1079
|
if (!cdp.datum) throw new Error("Unable to find CDP Datum");
|
|
1052
1080
|
const cdpD = parseCDPDatum(cdp.datum);
|
|
1053
1081
|
if (!("ActiveCDPInterestTracking" in cdpD.cdpFees))
|
|
@@ -1056,19 +1084,21 @@ var CDPContract = class _CDPContract {
|
|
|
1056
1084
|
throw new Error("iAsset is delisted");
|
|
1057
1085
|
const oracleAsset = iAsset.datum.price.Oracle.oracleNft.asset;
|
|
1058
1086
|
const oracleRefInput = priceOracleRef ? (await lucid.utxosByOutRef([priceOracleRef]))[0] : await lucid.utxoByUnit(
|
|
1059
|
-
oracleAsset.currencySymbol + (0,
|
|
1087
|
+
oracleAsset.currencySymbol + (0, import_lucid13.fromText)(oracleAsset.tokenName)
|
|
1060
1088
|
);
|
|
1061
1089
|
if (!oracleRefInput.datum)
|
|
1062
1090
|
return Promise.reject(new Error("Invalid oracle input"));
|
|
1063
1091
|
const od = parsePriceOracleDatum(oracleRefInput.datum);
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1092
|
+
const txValidity = oracleExpirationAwareValidity(
|
|
1093
|
+
currentSlot,
|
|
1094
|
+
Number(params.cdpCreatorParams.biasTime),
|
|
1095
|
+
Number(od.expiration),
|
|
1096
|
+
network
|
|
1097
|
+
);
|
|
1098
|
+
tx.readFrom([oracleRefInput]).validFrom(txValidity.validFrom).validTo(txValidity.validTo);
|
|
1069
1099
|
let fee = 0n;
|
|
1070
1100
|
const interestPaymentAsset = calculateAccruedInterest(
|
|
1071
|
-
|
|
1101
|
+
currentTime,
|
|
1072
1102
|
cdpD.cdpFees.ActiveCDPInterestTracking.unitaryInterestSnapshot,
|
|
1073
1103
|
cdpD.mintedAmt,
|
|
1074
1104
|
cdpD.cdpFees.ActiveCDPInterestTracking.lastSettled,
|
|
@@ -1099,12 +1129,12 @@ var CDPContract = class _CDPContract {
|
|
|
1099
1129
|
const assetBurnValue = {};
|
|
1100
1130
|
assetBurnValue[iassetToken] = -BigInt(cdpD.mintedAmt);
|
|
1101
1131
|
const cdpTokenBurnValue = {};
|
|
1102
|
-
cdpTokenBurnValue[params.cdpParams.cdpAuthToken[0].unCurrencySymbol + (0,
|
|
1132
|
+
cdpTokenBurnValue[params.cdpParams.cdpAuthToken[0].unCurrencySymbol + (0, import_lucid13.fromText)(params.cdpParams.cdpAuthToken[1].unTokenName)] = -1n;
|
|
1103
1133
|
const cdpAuthTokenScriptRefUtxo = await _CDPContract.cdpAuthTokenRef(
|
|
1104
1134
|
params.scriptReferences,
|
|
1105
1135
|
lucid
|
|
1106
1136
|
);
|
|
1107
|
-
tx.readFrom([iAssetTokenScriptRefUtxo]).mintAssets(assetBurnValue,
|
|
1137
|
+
tx.readFrom([iAssetTokenScriptRefUtxo]).mintAssets(assetBurnValue, import_lucid13.Data.to(new import_lucid13.Constr(0, []))).readFrom([cdpAuthTokenScriptRefUtxo]).mintAssets(cdpTokenBurnValue, import_lucid13.Data.to(new import_lucid13.Constr(0, [])));
|
|
1108
1138
|
if (fee > 0n) {
|
|
1109
1139
|
await CollectorContract.feeTx(fee, lucid, params, tx, collectorRef);
|
|
1110
1140
|
}
|
|
@@ -1113,34 +1143,34 @@ var CDPContract = class _CDPContract {
|
|
|
1113
1143
|
static validator(params) {
|
|
1114
1144
|
return {
|
|
1115
1145
|
type: _cdpValidator.type,
|
|
1116
|
-
script: (0,
|
|
1117
|
-
new
|
|
1118
|
-
new
|
|
1146
|
+
script: (0, import_lucid13.applyParamsToScript)(_cdpValidator.cborHex, [
|
|
1147
|
+
new import_lucid13.Constr(0, [
|
|
1148
|
+
new import_lucid13.Constr(0, [
|
|
1119
1149
|
params.cdpAuthToken[0].unCurrencySymbol,
|
|
1120
|
-
(0,
|
|
1150
|
+
(0, import_lucid13.fromText)(params.cdpAuthToken[1].unTokenName)
|
|
1121
1151
|
]),
|
|
1122
1152
|
params.cdpAssetSymbol.unCurrencySymbol,
|
|
1123
|
-
new
|
|
1153
|
+
new import_lucid13.Constr(0, [
|
|
1124
1154
|
params.iAssetAuthToken[0].unCurrencySymbol,
|
|
1125
|
-
(0,
|
|
1155
|
+
(0, import_lucid13.fromText)(params.iAssetAuthToken[1].unTokenName)
|
|
1126
1156
|
]),
|
|
1127
|
-
new
|
|
1157
|
+
new import_lucid13.Constr(0, [
|
|
1128
1158
|
params.stabilityPoolAuthToken[0].unCurrencySymbol,
|
|
1129
|
-
(0,
|
|
1159
|
+
(0, import_lucid13.fromText)(params.stabilityPoolAuthToken[1].unTokenName)
|
|
1130
1160
|
]),
|
|
1131
|
-
new
|
|
1161
|
+
new import_lucid13.Constr(0, [
|
|
1132
1162
|
params.versionRecordToken[0].unCurrencySymbol,
|
|
1133
|
-
(0,
|
|
1163
|
+
(0, import_lucid13.fromText)(params.versionRecordToken[1].unTokenName)
|
|
1134
1164
|
]),
|
|
1135
|
-
new
|
|
1165
|
+
new import_lucid13.Constr(0, [
|
|
1136
1166
|
params.upgradeToken[0].unCurrencySymbol,
|
|
1137
|
-
(0,
|
|
1167
|
+
(0, import_lucid13.fromText)(params.upgradeToken[1].unTokenName)
|
|
1138
1168
|
]),
|
|
1139
1169
|
params.collectorValHash,
|
|
1140
1170
|
params.spValHash,
|
|
1141
|
-
new
|
|
1171
|
+
new import_lucid13.Constr(0, [
|
|
1142
1172
|
params.govNFT[0].unCurrencySymbol,
|
|
1143
|
-
(0,
|
|
1173
|
+
(0, import_lucid13.fromText)(params.govNFT[1].unTokenName)
|
|
1144
1174
|
]),
|
|
1145
1175
|
BigInt(params.minCollateralInLovelace),
|
|
1146
1176
|
BigInt(params.partialRedemptionExtraFeeLovelace),
|
|
@@ -1151,14 +1181,14 @@ var CDPContract = class _CDPContract {
|
|
|
1151
1181
|
};
|
|
1152
1182
|
}
|
|
1153
1183
|
static validatorHash(params) {
|
|
1154
|
-
return (0,
|
|
1184
|
+
return (0, import_lucid13.validatorToScriptHash)(_CDPContract.validator(params));
|
|
1155
1185
|
}
|
|
1156
1186
|
static address(cdpParams, lucid, skh) {
|
|
1157
1187
|
const network = lucid.config().network;
|
|
1158
1188
|
if (!network) {
|
|
1159
1189
|
throw new Error("Network configuration is undefined");
|
|
1160
1190
|
}
|
|
1161
|
-
return (0,
|
|
1191
|
+
return (0, import_lucid13.validatorToAddress)(network, _CDPContract.validator(cdpParams), skh);
|
|
1162
1192
|
}
|
|
1163
1193
|
static scriptRef(params, lucid) {
|
|
1164
1194
|
return scriptRef(params.cdpValidatorRef, lucid);
|
|
@@ -1179,111 +1209,111 @@ var GovContract = class {
|
|
|
1179
1209
|
};
|
|
1180
1210
|
|
|
1181
1211
|
// src/contracts/stability-pool.ts
|
|
1182
|
-
var
|
|
1212
|
+
var import_lucid17 = require("@lucid-evolution/lucid");
|
|
1183
1213
|
|
|
1184
1214
|
// src/types/indigo/stability-pool.ts
|
|
1185
|
-
var
|
|
1215
|
+
var import_lucid14 = require("@lucid-evolution/lucid");
|
|
1186
1216
|
var import_ts_pattern3 = require("ts-pattern");
|
|
1187
|
-
var SPIntegerSchema =
|
|
1188
|
-
value:
|
|
1217
|
+
var SPIntegerSchema = import_lucid14.Data.Object({
|
|
1218
|
+
value: import_lucid14.Data.Integer()
|
|
1189
1219
|
});
|
|
1190
1220
|
var SPInteger = SPIntegerSchema;
|
|
1191
|
-
var StabilityPoolSnapshotSchema =
|
|
1221
|
+
var StabilityPoolSnapshotSchema = import_lucid14.Data.Object({
|
|
1192
1222
|
productVal: SPIntegerSchema,
|
|
1193
1223
|
depositVal: SPIntegerSchema,
|
|
1194
1224
|
sumVal: SPIntegerSchema,
|
|
1195
|
-
epoch:
|
|
1196
|
-
scale:
|
|
1225
|
+
epoch: import_lucid14.Data.Integer(),
|
|
1226
|
+
scale: import_lucid14.Data.Integer()
|
|
1197
1227
|
});
|
|
1198
1228
|
var StabilityPoolSnapshot = StabilityPoolSnapshotSchema;
|
|
1199
|
-
var EpochToScaleToSumSchema =
|
|
1200
|
-
|
|
1229
|
+
var EpochToScaleToSumSchema = import_lucid14.Data.Map(
|
|
1230
|
+
import_lucid14.Data.Object({ epoch: import_lucid14.Data.Integer(), scale: import_lucid14.Data.Integer() }),
|
|
1201
1231
|
SPIntegerSchema,
|
|
1202
1232
|
{ minItems: 0 }
|
|
1203
1233
|
);
|
|
1204
1234
|
var EpochToScaleToSum = EpochToScaleToSumSchema;
|
|
1205
|
-
var StabilityPoolContentSchema =
|
|
1206
|
-
asset:
|
|
1235
|
+
var StabilityPoolContentSchema = import_lucid14.Data.Object({
|
|
1236
|
+
asset: import_lucid14.Data.Bytes(),
|
|
1207
1237
|
snapshot: StabilityPoolSnapshotSchema,
|
|
1208
1238
|
epochToScaleToSum: EpochToScaleToSumSchema
|
|
1209
1239
|
});
|
|
1210
1240
|
var StabilityPoolContent = StabilityPoolContentSchema;
|
|
1211
|
-
var AccountActionSchema =
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
Adjust:
|
|
1215
|
-
amount:
|
|
1241
|
+
var AccountActionSchema = import_lucid14.Data.Enum([
|
|
1242
|
+
import_lucid14.Data.Literal("Create"),
|
|
1243
|
+
import_lucid14.Data.Object({
|
|
1244
|
+
Adjust: import_lucid14.Data.Object({
|
|
1245
|
+
amount: import_lucid14.Data.Integer(),
|
|
1216
1246
|
outputAddress: AddressSchema
|
|
1217
1247
|
})
|
|
1218
1248
|
}),
|
|
1219
|
-
|
|
1249
|
+
import_lucid14.Data.Object({ Close: import_lucid14.Data.Object({ outputAddress: AddressSchema }) })
|
|
1220
1250
|
]);
|
|
1221
1251
|
var AccountAction = AccountActionSchema;
|
|
1222
|
-
var AccountContentSchema =
|
|
1223
|
-
owner:
|
|
1224
|
-
asset:
|
|
1252
|
+
var AccountContentSchema = import_lucid14.Data.Object({
|
|
1253
|
+
owner: import_lucid14.Data.Bytes(),
|
|
1254
|
+
asset: import_lucid14.Data.Bytes(),
|
|
1225
1255
|
snapshot: StabilityPoolSnapshotSchema,
|
|
1226
|
-
request:
|
|
1256
|
+
request: import_lucid14.Data.Nullable(AccountActionSchema)
|
|
1227
1257
|
});
|
|
1228
1258
|
var AccountContent = AccountContentSchema;
|
|
1229
|
-
var SnapshotEpochToScaleToSumContentSchema =
|
|
1230
|
-
asset:
|
|
1259
|
+
var SnapshotEpochToScaleToSumContentSchema = import_lucid14.Data.Object({
|
|
1260
|
+
asset: import_lucid14.Data.Bytes(),
|
|
1231
1261
|
snapshot: EpochToScaleToSumSchema
|
|
1232
1262
|
});
|
|
1233
1263
|
var SnapshotEpochToScaleToSumContent = SnapshotEpochToScaleToSumContentSchema;
|
|
1234
|
-
var StabilityPoolDatumSchema =
|
|
1235
|
-
|
|
1236
|
-
StabilityPool:
|
|
1264
|
+
var StabilityPoolDatumSchema = import_lucid14.Data.Enum([
|
|
1265
|
+
import_lucid14.Data.Object({
|
|
1266
|
+
StabilityPool: import_lucid14.Data.Object({ content: StabilityPoolContentSchema })
|
|
1237
1267
|
}),
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
SnapshotEpochToScaleToSum:
|
|
1268
|
+
import_lucid14.Data.Object({ Account: import_lucid14.Data.Object({ content: AccountContentSchema }) }),
|
|
1269
|
+
import_lucid14.Data.Object({
|
|
1270
|
+
SnapshotEpochToScaleToSum: import_lucid14.Data.Object({
|
|
1241
1271
|
content: SnapshotEpochToScaleToSumContentSchema
|
|
1242
1272
|
})
|
|
1243
1273
|
})
|
|
1244
1274
|
]);
|
|
1245
1275
|
var StabilityPoolDatum = StabilityPoolDatumSchema;
|
|
1246
|
-
var ActionReturnDatumSchema =
|
|
1247
|
-
|
|
1248
|
-
IndigoStabilityPoolAccountAdjustment:
|
|
1276
|
+
var ActionReturnDatumSchema = import_lucid14.Data.Enum([
|
|
1277
|
+
import_lucid14.Data.Object({
|
|
1278
|
+
IndigoStabilityPoolAccountAdjustment: import_lucid14.Data.Object({
|
|
1249
1279
|
spent_account: OutputReferenceSchema
|
|
1250
1280
|
})
|
|
1251
1281
|
}),
|
|
1252
|
-
|
|
1253
|
-
IndigoStabilityPoolAccountClosure:
|
|
1282
|
+
import_lucid14.Data.Object({
|
|
1283
|
+
IndigoStabilityPoolAccountClosure: import_lucid14.Data.Object({
|
|
1254
1284
|
closed_account: OutputReferenceSchema
|
|
1255
1285
|
})
|
|
1256
1286
|
})
|
|
1257
1287
|
]);
|
|
1258
1288
|
var ActionReturnDatum = ActionReturnDatumSchema;
|
|
1259
|
-
var StabilityPoolRedeemerSchema =
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
ProcessRequest:
|
|
1289
|
+
var StabilityPoolRedeemerSchema = import_lucid14.Data.Enum([
|
|
1290
|
+
import_lucid14.Data.Object({ RequestAction: import_lucid14.Data.Object({ action: AccountActionSchema }) }),
|
|
1291
|
+
import_lucid14.Data.Object({
|
|
1292
|
+
ProcessRequest: import_lucid14.Data.Object({ requestRef: OutputReferenceSchema })
|
|
1263
1293
|
}),
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1294
|
+
import_lucid14.Data.Object({ AnnulRequest: import_lucid14.Data.Object({}) }),
|
|
1295
|
+
import_lucid14.Data.Object({ LiquidateCDP: import_lucid14.Data.Object({}) }),
|
|
1296
|
+
import_lucid14.Data.Object({ RecordEpochToScaleToSum: import_lucid14.Data.Object({}) }),
|
|
1297
|
+
import_lucid14.Data.Object({ UpgradeVersion: import_lucid14.Data.Object({}) })
|
|
1268
1298
|
]);
|
|
1269
1299
|
var StabilityPoolRedeemer = StabilityPoolRedeemerSchema;
|
|
1270
1300
|
function parseStabilityPoolDatum(datum) {
|
|
1271
|
-
return (0, import_ts_pattern3.match)(
|
|
1301
|
+
return (0, import_ts_pattern3.match)(import_lucid14.Data.from(datum, StabilityPoolDatum)).with({ StabilityPool: { content: import_ts_pattern3.P.select() } }, (res) => res).otherwise(() => {
|
|
1272
1302
|
throw new Error("Expected a Stability Pool datum.");
|
|
1273
1303
|
});
|
|
1274
1304
|
}
|
|
1275
1305
|
function parseAccountDatum(datum) {
|
|
1276
|
-
return (0, import_ts_pattern3.match)(
|
|
1306
|
+
return (0, import_ts_pattern3.match)(import_lucid14.Data.from(datum, StabilityPoolDatum)).with({ Account: { content: import_ts_pattern3.P.select() } }, (res) => res).otherwise(() => {
|
|
1277
1307
|
throw new Error("Expected a StakingPosition datum.");
|
|
1278
1308
|
});
|
|
1279
1309
|
}
|
|
1280
1310
|
function parseSnapshotEpochToScaleToSumDatum(datum) {
|
|
1281
|
-
return (0, import_ts_pattern3.match)(
|
|
1311
|
+
return (0, import_ts_pattern3.match)(import_lucid14.Data.from(datum, StabilityPoolDatum)).with({ SnapshotEpochToScaleToSum: { content: import_ts_pattern3.P.select() } }, (res) => res).otherwise(() => {
|
|
1282
1312
|
throw new Error("Expected a SnapshotEpochToScaleToSum datum.");
|
|
1283
1313
|
});
|
|
1284
1314
|
}
|
|
1285
1315
|
function serialiseStabilityPoolDatum(d) {
|
|
1286
|
-
let cbor =
|
|
1316
|
+
let cbor = import_lucid14.Data.to(d, StabilityPoolDatum);
|
|
1287
1317
|
if ("StabilityPool" in d) {
|
|
1288
1318
|
if (cbor.includes("bf")) {
|
|
1289
1319
|
if (d.StabilityPool.content.epochToScaleToSum.size > 0) {
|
|
@@ -1298,25 +1328,25 @@ function serialiseStabilityPoolDatum(d) {
|
|
|
1298
1328
|
return cbor;
|
|
1299
1329
|
}
|
|
1300
1330
|
function serialiseStabilityPoolRedeemer(params) {
|
|
1301
|
-
return
|
|
1331
|
+
return import_lucid14.Data.to(params, StabilityPoolRedeemer);
|
|
1302
1332
|
}
|
|
1303
|
-
var StabilityPoolParamsSchema =
|
|
1304
|
-
assetSymbol:
|
|
1333
|
+
var StabilityPoolParamsSchema = import_lucid14.Data.Object({
|
|
1334
|
+
assetSymbol: import_lucid14.Data.Bytes(),
|
|
1305
1335
|
stabilityPoolToken: AssetClassSchema,
|
|
1306
1336
|
snapshotEpochToScaleToSumToken: AssetClassSchema,
|
|
1307
1337
|
accountToken: AssetClassSchema,
|
|
1308
1338
|
cdpToken: AssetClassSchema,
|
|
1309
1339
|
iAssetAuthToken: AssetClassSchema,
|
|
1310
1340
|
versionRecordToken: AssetClassSchema,
|
|
1311
|
-
collectorValHash:
|
|
1341
|
+
collectorValHash: import_lucid14.Data.Bytes(),
|
|
1312
1342
|
govNFT: AssetClassSchema,
|
|
1313
|
-
accountCreateFeeLovelaces:
|
|
1314
|
-
accountAdjustmentFeeLovelaces:
|
|
1315
|
-
requestCollateralLovelaces:
|
|
1343
|
+
accountCreateFeeLovelaces: import_lucid14.Data.Integer(),
|
|
1344
|
+
accountAdjustmentFeeLovelaces: import_lucid14.Data.Integer(),
|
|
1345
|
+
requestCollateralLovelaces: import_lucid14.Data.Integer()
|
|
1316
1346
|
});
|
|
1317
1347
|
var StabilityPoolParams = StabilityPoolParamsSchema;
|
|
1318
1348
|
function castStabilityPoolParams(params) {
|
|
1319
|
-
return
|
|
1349
|
+
return import_lucid14.Data.castTo(params, StabilityPoolParams);
|
|
1320
1350
|
}
|
|
1321
1351
|
var spPrecision = 1000000000000000000n;
|
|
1322
1352
|
function mkSPInteger(value) {
|
|
@@ -1339,20 +1369,20 @@ function spDiv(a, b) {
|
|
|
1339
1369
|
}
|
|
1340
1370
|
|
|
1341
1371
|
// src/scripts/stability-pool-validator.ts
|
|
1342
|
-
var
|
|
1372
|
+
var import_lucid16 = require("@lucid-evolution/lucid");
|
|
1343
1373
|
|
|
1344
1374
|
// src/types/system-params.ts
|
|
1345
|
-
var
|
|
1375
|
+
var import_lucid15 = require("@lucid-evolution/lucid");
|
|
1346
1376
|
function toSystemParamsAsset(asset) {
|
|
1347
1377
|
return [
|
|
1348
1378
|
{ unCurrencySymbol: asset.currencySymbol },
|
|
1349
|
-
{ unTokenName: (0,
|
|
1379
|
+
{ unTokenName: (0, import_lucid15.toText)(asset.tokenName) }
|
|
1350
1380
|
];
|
|
1351
1381
|
}
|
|
1352
1382
|
function fromSystemParamsAsset(asset) {
|
|
1353
1383
|
return {
|
|
1354
1384
|
currencySymbol: asset[0].unCurrencySymbol,
|
|
1355
|
-
tokenName: (0,
|
|
1385
|
+
tokenName: (0, import_lucid15.fromText)(asset[1].unTokenName)
|
|
1356
1386
|
};
|
|
1357
1387
|
}
|
|
1358
1388
|
|
|
@@ -1365,7 +1395,7 @@ var stabilityPoolValidator = {
|
|
|
1365
1395
|
var mkStabilityPoolValidatorFromSP = (params) => {
|
|
1366
1396
|
return {
|
|
1367
1397
|
type: stabilityPoolValidator.type,
|
|
1368
|
-
script: (0,
|
|
1398
|
+
script: (0, import_lucid16.applyParamsToScript)(stabilityPoolValidator.cborHex, [
|
|
1369
1399
|
castStabilityPoolParams({
|
|
1370
1400
|
assetSymbol: params.assetSymbol.unCurrencySymbol,
|
|
1371
1401
|
stabilityPoolToken: fromSystemParamsAsset(params.stabilityPoolToken),
|
|
@@ -1537,7 +1567,7 @@ var StabilityPoolContract = class {
|
|
|
1537
1567
|
Account: {
|
|
1538
1568
|
content: {
|
|
1539
1569
|
owner: pkh.hash,
|
|
1540
|
-
asset: (0,
|
|
1570
|
+
asset: (0, import_lucid17.fromText)(asset),
|
|
1541
1571
|
snapshot: {
|
|
1542
1572
|
productVal: { value: 0n },
|
|
1543
1573
|
depositVal: { value: 0n },
|
|
@@ -1550,8 +1580,8 @@ var StabilityPoolContract = class {
|
|
|
1550
1580
|
}
|
|
1551
1581
|
};
|
|
1552
1582
|
return lucid.newTx().pay.ToContract(
|
|
1553
|
-
(0,
|
|
1554
|
-
hash: (0,
|
|
1583
|
+
(0, import_lucid17.credentialToAddress)(lucid.config().network, {
|
|
1584
|
+
hash: (0, import_lucid17.validatorToScriptHash)(
|
|
1555
1585
|
mkStabilityPoolValidatorFromSP(params.stabilityPoolParams)
|
|
1556
1586
|
),
|
|
1557
1587
|
type: "Script"
|
|
@@ -1559,7 +1589,7 @@ var StabilityPoolContract = class {
|
|
|
1559
1589
|
{ kind: "inline", value: serialiseStabilityPoolDatum(datum) },
|
|
1560
1590
|
{
|
|
1561
1591
|
lovelace: minLovelaces,
|
|
1562
|
-
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
1592
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid17.fromText)(asset)]: amount
|
|
1563
1593
|
}
|
|
1564
1594
|
).addSignerKey(pkh.hash);
|
|
1565
1595
|
}
|
|
@@ -1589,8 +1619,8 @@ var StabilityPoolContract = class {
|
|
|
1589
1619
|
}
|
|
1590
1620
|
};
|
|
1591
1621
|
return lucid.newTx().readFrom([stabilityPoolScriptRef]).collectFrom([accountUtxo], serialiseStabilityPoolRedeemer(redeemer)).pay.ToContract(
|
|
1592
|
-
(0,
|
|
1593
|
-
hash: (0,
|
|
1622
|
+
(0, import_lucid17.credentialToAddress)(lucid.config().network, {
|
|
1623
|
+
hash: (0, import_lucid17.validatorToScriptHash)(
|
|
1594
1624
|
mkStabilityPoolValidatorFromSP(params.stabilityPoolParams)
|
|
1595
1625
|
),
|
|
1596
1626
|
type: "Script"
|
|
@@ -1607,8 +1637,8 @@ var StabilityPoolContract = class {
|
|
|
1607
1637
|
lovelace: BigInt(
|
|
1608
1638
|
params.stabilityPoolParams.requestCollateralLovelaces + params.stabilityPoolParams.accountAdjustmentFeeLovelaces
|
|
1609
1639
|
),
|
|
1610
|
-
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0,
|
|
1611
|
-
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
1640
|
+
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid17.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n,
|
|
1641
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid17.fromText)(asset)]: amount
|
|
1612
1642
|
}
|
|
1613
1643
|
).addSignerKey(pkh.hash);
|
|
1614
1644
|
}
|
|
@@ -1637,8 +1667,8 @@ var StabilityPoolContract = class {
|
|
|
1637
1667
|
}
|
|
1638
1668
|
};
|
|
1639
1669
|
return lucid.newTx().readFrom([stabilityPoolScriptRef]).collectFrom([accountUtxo], serialiseStabilityPoolRedeemer(redeemer)).pay.ToContract(
|
|
1640
|
-
(0,
|
|
1641
|
-
hash: (0,
|
|
1670
|
+
(0, import_lucid17.credentialToAddress)(lucid.config().network, {
|
|
1671
|
+
hash: (0, import_lucid17.validatorToScriptHash)(
|
|
1642
1672
|
mkStabilityPoolValidatorFromSP(params.stabilityPoolParams)
|
|
1643
1673
|
),
|
|
1644
1674
|
type: "Script"
|
|
@@ -1655,7 +1685,7 @@ var StabilityPoolContract = class {
|
|
|
1655
1685
|
lovelace: BigInt(
|
|
1656
1686
|
params.stabilityPoolParams.requestCollateralLovelaces + params.stabilityPoolParams.accountAdjustmentFeeLovelaces
|
|
1657
1687
|
),
|
|
1658
|
-
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0,
|
|
1688
|
+
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid17.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
|
|
1659
1689
|
}
|
|
1660
1690
|
).addSignerKey(pkh.hash);
|
|
1661
1691
|
}
|
|
@@ -1685,7 +1715,7 @@ var StabilityPoolContract = class {
|
|
|
1685
1715
|
lucid
|
|
1686
1716
|
);
|
|
1687
1717
|
tx.readFrom([accountTokenScriptRef]);
|
|
1688
|
-
const iassetUnit = params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
1718
|
+
const iassetUnit = params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid17.fromText)(asset);
|
|
1689
1719
|
const reqAmount = accountUtxo.assets[iassetUnit] ?? 0n;
|
|
1690
1720
|
const newAccountSnapshot = {
|
|
1691
1721
|
...stabilityPoolDatum.snapshot,
|
|
@@ -1727,14 +1757,14 @@ var StabilityPoolContract = class {
|
|
|
1727
1757
|
const stabilityPoolAssetToken = stabilityPoolUtxo.assets[iassetUnit] ?? 0n;
|
|
1728
1758
|
const poolOutputValue = {
|
|
1729
1759
|
lovelace: stabilityPoolUtxo.assets.lovelace + BigInt(params.stabilityPoolParams.accountCreateFeeLovelaces),
|
|
1730
|
-
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + (0,
|
|
1731
|
-
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
1760
|
+
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + (0, import_lucid17.fromText)(params.stabilityPoolParams.stabilityPoolToken[1].unTokenName)]: 1n,
|
|
1761
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid17.fromText)(asset)]: stabilityPoolAssetToken + reqAmount
|
|
1732
1762
|
};
|
|
1733
1763
|
tx.mintAssets(
|
|
1734
1764
|
{
|
|
1735
|
-
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0,
|
|
1765
|
+
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid17.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
|
|
1736
1766
|
},
|
|
1737
|
-
|
|
1767
|
+
import_lucid17.Data.to(new import_lucid17.Constr(0, []))
|
|
1738
1768
|
);
|
|
1739
1769
|
tx.pay.ToContract(
|
|
1740
1770
|
stabilityPoolUtxo.address,
|
|
@@ -1768,7 +1798,7 @@ var StabilityPoolContract = class {
|
|
|
1768
1798
|
},
|
|
1769
1799
|
{
|
|
1770
1800
|
lovelace: accountUtxo.assets.lovelace - BigInt(params.stabilityPoolParams.accountCreateFeeLovelaces),
|
|
1771
|
-
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0,
|
|
1801
|
+
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid17.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
|
|
1772
1802
|
}
|
|
1773
1803
|
);
|
|
1774
1804
|
} else if ("Adjust" in accountDatum.request) {
|
|
@@ -1863,10 +1893,10 @@ var StabilityPoolContract = class {
|
|
|
1863
1893
|
},
|
|
1864
1894
|
{
|
|
1865
1895
|
lovelace: stabilityPoolUtxo.assets.lovelace + BigInt(params.stabilityPoolParams.accountAdjustmentFeeLovelaces) - reward,
|
|
1866
|
-
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + (0,
|
|
1896
|
+
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + (0, import_lucid17.fromText)(
|
|
1867
1897
|
params.stabilityPoolParams.stabilityPoolToken[1].unTokenName
|
|
1868
1898
|
)]: 1n,
|
|
1869
|
-
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
1899
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid17.fromText)(asset)]: stabilityPoolUtxo.assets[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid17.fromText)(asset)] + balanceChange + withdrawalFee
|
|
1870
1900
|
}
|
|
1871
1901
|
);
|
|
1872
1902
|
tx.pay.ToContract(
|
|
@@ -1885,7 +1915,7 @@ var StabilityPoolContract = class {
|
|
|
1885
1915
|
},
|
|
1886
1916
|
{
|
|
1887
1917
|
lovelace: accountUtxo.assets.lovelace - BigInt(params.stabilityPoolParams.accountAdjustmentFeeLovelaces) - 2000000n,
|
|
1888
|
-
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0,
|
|
1918
|
+
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid17.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: 1n
|
|
1889
1919
|
}
|
|
1890
1920
|
);
|
|
1891
1921
|
if (myAddress !== outputAddress) {
|
|
@@ -1893,7 +1923,7 @@ var StabilityPoolContract = class {
|
|
|
1893
1923
|
outputAddress,
|
|
1894
1924
|
{
|
|
1895
1925
|
kind: "inline",
|
|
1896
|
-
value:
|
|
1926
|
+
value: import_lucid17.Data.to(
|
|
1897
1927
|
{
|
|
1898
1928
|
IndigoStabilityPoolAccountAdjustment: {
|
|
1899
1929
|
spent_account: {
|
|
@@ -1908,7 +1938,7 @@ var StabilityPoolContract = class {
|
|
|
1908
1938
|
{
|
|
1909
1939
|
lovelace: reward - rewardLovelacesFee + 2000000n,
|
|
1910
1940
|
...amount < 0n ? {
|
|
1911
|
-
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
1941
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid17.fromText)(asset)]: -(amount - withdrawalFee)
|
|
1912
1942
|
} : {}
|
|
1913
1943
|
}
|
|
1914
1944
|
);
|
|
@@ -1961,11 +1991,11 @@ var StabilityPoolContract = class {
|
|
|
1961
1991
|
tx.readFrom([govUtxo, iAssetUtxo, accountTokenRef, ...refInputs]);
|
|
1962
1992
|
tx.mintAssets(
|
|
1963
1993
|
{
|
|
1964
|
-
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0,
|
|
1994
|
+
[params.stabilityPoolParams.accountToken[0].unCurrencySymbol + (0, import_lucid17.fromText)(params.stabilityPoolParams.accountToken[1].unTokenName)]: -1n
|
|
1965
1995
|
},
|
|
1966
|
-
|
|
1996
|
+
import_lucid17.Data.to(new import_lucid17.Constr(0, []))
|
|
1967
1997
|
);
|
|
1968
|
-
const assetOutputAmountForSP = stabilityPoolUtxo.assets[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
1998
|
+
const assetOutputAmountForSP = stabilityPoolUtxo.assets[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid17.fromText)(asset)] - fromSPInteger(withdrawnAmt) - withdrawalFeeAmount;
|
|
1969
1999
|
tx.pay.ToContract(
|
|
1970
2000
|
stabilityPoolUtxo.address,
|
|
1971
2001
|
{
|
|
@@ -1981,11 +2011,11 @@ var StabilityPoolContract = class {
|
|
|
1981
2011
|
},
|
|
1982
2012
|
{
|
|
1983
2013
|
lovelace: stabilityPoolUtxo.assets.lovelace - reward,
|
|
1984
|
-
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + (0,
|
|
2014
|
+
[params.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol + (0, import_lucid17.fromText)(
|
|
1985
2015
|
params.stabilityPoolParams.stabilityPoolToken[1].unTokenName
|
|
1986
2016
|
)]: 1n,
|
|
1987
2017
|
...assetOutputAmountForSP > 0n ? {
|
|
1988
|
-
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
2018
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid17.fromText)(asset)]: assetOutputAmountForSP
|
|
1989
2019
|
} : {}
|
|
1990
2020
|
}
|
|
1991
2021
|
);
|
|
@@ -1994,7 +2024,7 @@ var StabilityPoolContract = class {
|
|
|
1994
2024
|
outputAddress,
|
|
1995
2025
|
{
|
|
1996
2026
|
kind: "inline",
|
|
1997
|
-
value:
|
|
2027
|
+
value: import_lucid17.Data.to(
|
|
1998
2028
|
{
|
|
1999
2029
|
IndigoStabilityPoolAccountClosure: {
|
|
2000
2030
|
closed_account: {
|
|
@@ -2008,7 +2038,7 @@ var StabilityPoolContract = class {
|
|
|
2008
2038
|
},
|
|
2009
2039
|
{
|
|
2010
2040
|
lovelace: accountUtxo.assets.lovelace + reward - rewardLovelacesFee,
|
|
2011
|
-
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0,
|
|
2041
|
+
[params.stabilityPoolParams.assetSymbol.unCurrencySymbol + (0, import_lucid17.fromText)(asset)]: fromSPInteger(withdrawnAmt) - withdrawalFeeAmount
|
|
2012
2042
|
}
|
|
2013
2043
|
);
|
|
2014
2044
|
}
|
|
@@ -2018,7 +2048,7 @@ var StabilityPoolContract = class {
|
|
|
2018
2048
|
};
|
|
2019
2049
|
|
|
2020
2050
|
// src/contracts/staking.ts
|
|
2021
|
-
var
|
|
2051
|
+
var import_lucid20 = require("@lucid-evolution/lucid");
|
|
2022
2052
|
|
|
2023
2053
|
// src/scripts/staking-validator.ts
|
|
2024
2054
|
var _stakingValidator = {
|
|
@@ -2028,73 +2058,73 @@ var _stakingValidator = {
|
|
|
2028
2058
|
};
|
|
2029
2059
|
|
|
2030
2060
|
// src/types/indigo/staking.ts
|
|
2031
|
-
var
|
|
2061
|
+
var import_lucid18 = require("@lucid-evolution/lucid");
|
|
2032
2062
|
var import_ts_pattern4 = require("ts-pattern");
|
|
2033
|
-
var StakingParamsSchema =
|
|
2063
|
+
var StakingParamsSchema = import_lucid18.Data.Object({
|
|
2034
2064
|
stakingManagerNft: AssetClassSchema,
|
|
2035
2065
|
stakingToken: AssetClassSchema,
|
|
2036
2066
|
indyToken: AssetClassSchema,
|
|
2037
2067
|
pollToken: AssetClassSchema,
|
|
2038
2068
|
versionRecordToken: AssetClassSchema,
|
|
2039
|
-
collectorValHash:
|
|
2069
|
+
collectorValHash: import_lucid18.Data.Bytes()
|
|
2040
2070
|
});
|
|
2041
|
-
var StakingRedeemerSchema =
|
|
2042
|
-
|
|
2043
|
-
CreateStakingPosition:
|
|
2044
|
-
creatorPkh:
|
|
2071
|
+
var StakingRedeemerSchema = import_lucid18.Data.Enum([
|
|
2072
|
+
import_lucid18.Data.Object({
|
|
2073
|
+
CreateStakingPosition: import_lucid18.Data.Object({
|
|
2074
|
+
creatorPkh: import_lucid18.Data.Bytes()
|
|
2045
2075
|
})
|
|
2046
2076
|
}),
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
AdjustStakedAmount:
|
|
2051
|
-
adjustAmount:
|
|
2077
|
+
import_lucid18.Data.Literal("UpdateTotalStake"),
|
|
2078
|
+
import_lucid18.Data.Literal("Distribute"),
|
|
2079
|
+
import_lucid18.Data.Object({
|
|
2080
|
+
AdjustStakedAmount: import_lucid18.Data.Object({
|
|
2081
|
+
adjustAmount: import_lucid18.Data.Integer()
|
|
2052
2082
|
})
|
|
2053
2083
|
}),
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2084
|
+
import_lucid18.Data.Literal("Unstake"),
|
|
2085
|
+
import_lucid18.Data.Literal("Lock"),
|
|
2086
|
+
import_lucid18.Data.Literal("UpgradeVersion")
|
|
2057
2087
|
]);
|
|
2058
|
-
var RewardSnapshotSchema =
|
|
2059
|
-
var StakingManagerContentSchema =
|
|
2060
|
-
totalStake:
|
|
2088
|
+
var RewardSnapshotSchema = import_lucid18.Data.Object({ snapshotAda: import_lucid18.Data.Integer() });
|
|
2089
|
+
var StakingManagerContentSchema = import_lucid18.Data.Object({
|
|
2090
|
+
totalStake: import_lucid18.Data.Integer(),
|
|
2061
2091
|
managerSnapshot: RewardSnapshotSchema
|
|
2062
2092
|
});
|
|
2063
|
-
var StakingPositionContentSchema =
|
|
2064
|
-
owner:
|
|
2065
|
-
lockedAmount:
|
|
2066
|
-
|
|
2067
|
-
|
|
2093
|
+
var StakingPositionContentSchema = import_lucid18.Data.Object({
|
|
2094
|
+
owner: import_lucid18.Data.Bytes(),
|
|
2095
|
+
lockedAmount: import_lucid18.Data.Map(
|
|
2096
|
+
import_lucid18.Data.Integer(),
|
|
2097
|
+
import_lucid18.Data.Tuple([import_lucid18.Data.Integer(), import_lucid18.Data.Integer()], {
|
|
2068
2098
|
hasConstr: true
|
|
2069
2099
|
})
|
|
2070
2100
|
),
|
|
2071
2101
|
positionSnapshot: RewardSnapshotSchema
|
|
2072
2102
|
});
|
|
2073
|
-
var StakingDatumSchema =
|
|
2074
|
-
|
|
2075
|
-
StakingManager:
|
|
2103
|
+
var StakingDatumSchema = import_lucid18.Data.Enum([
|
|
2104
|
+
import_lucid18.Data.Object({
|
|
2105
|
+
StakingManager: import_lucid18.Data.Object({ content: StakingManagerContentSchema })
|
|
2076
2106
|
}),
|
|
2077
|
-
|
|
2078
|
-
StakingPosition:
|
|
2107
|
+
import_lucid18.Data.Object({
|
|
2108
|
+
StakingPosition: import_lucid18.Data.Object({ content: StakingPositionContentSchema })
|
|
2079
2109
|
})
|
|
2080
2110
|
]);
|
|
2081
2111
|
var StakingDatum = StakingDatumSchema;
|
|
2082
2112
|
function parseStakingPositionDatum(datum) {
|
|
2083
|
-
return (0, import_ts_pattern4.match)(
|
|
2113
|
+
return (0, import_ts_pattern4.match)(import_lucid18.Data.from(datum, StakingDatum)).with({ StakingPosition: { content: import_ts_pattern4.P.select() } }, (res) => res).otherwise(() => {
|
|
2084
2114
|
throw new Error("Expected a StakingPosition datum.");
|
|
2085
2115
|
});
|
|
2086
2116
|
}
|
|
2087
2117
|
function parseStakingManagerDatum(datum) {
|
|
2088
|
-
return (0, import_ts_pattern4.match)(
|
|
2118
|
+
return (0, import_ts_pattern4.match)(import_lucid18.Data.from(datum, StakingDatum)).with({ StakingManager: { content: import_ts_pattern4.P.select() } }, (res) => res).otherwise(() => {
|
|
2089
2119
|
throw new Error("Expected a StakingPosition datum.");
|
|
2090
2120
|
});
|
|
2091
2121
|
}
|
|
2092
2122
|
function serialiseStakingDatum(d) {
|
|
2093
|
-
return
|
|
2123
|
+
return import_lucid18.Data.to(d, StakingDatum);
|
|
2094
2124
|
}
|
|
2095
2125
|
|
|
2096
2126
|
// src/helpers/staking-helpers.ts
|
|
2097
|
-
var
|
|
2127
|
+
var import_lucid19 = require("@lucid-evolution/lucid");
|
|
2098
2128
|
var StakingHelpers = class {
|
|
2099
2129
|
static async findStakingManagerByOutRef(stakingManagerRef, lucid) {
|
|
2100
2130
|
return lucid.utxosByOutRef([stakingManagerRef]).then(
|
|
@@ -2114,7 +2144,7 @@ var StakingHelpers = class {
|
|
|
2114
2144
|
static async findStakingManager(params, lucid) {
|
|
2115
2145
|
return lucid.utxosAtWithUnit(
|
|
2116
2146
|
StakingContract.address(params.stakingParams, lucid),
|
|
2117
|
-
params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0,
|
|
2147
|
+
params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0, import_lucid19.fromText)(params.stakingParams.stakingManagerNFT[1].unTokenName)
|
|
2118
2148
|
).then(
|
|
2119
2149
|
(utxos) => utxos.map((utxo) => {
|
|
2120
2150
|
if (!utxo.datum) return void 0;
|
|
@@ -2175,9 +2205,9 @@ var StakingContract = class _StakingContract {
|
|
|
2175
2205
|
snapshotAda: stakingManagerOut.datum.managerSnapshot.snapshotAda
|
|
2176
2206
|
}
|
|
2177
2207
|
};
|
|
2178
|
-
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0,
|
|
2179
|
-
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0,
|
|
2180
|
-
return lucid.newTx().collectFrom([stakingManagerOut.utxo],
|
|
2208
|
+
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0, import_lucid20.fromText)(params.stakingParams.stakingToken[1].unTokenName);
|
|
2209
|
+
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid20.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
2210
|
+
return lucid.newTx().collectFrom([stakingManagerOut.utxo], import_lucid20.Data.to(new import_lucid20.Constr(0, [pkh.hash]))).readFrom([stakingScriptRef]).pay.ToContract(
|
|
2181
2211
|
stakingManagerOut.utxo.address,
|
|
2182
2212
|
{
|
|
2183
2213
|
kind: "inline",
|
|
@@ -2190,7 +2220,7 @@ var StakingContract = class _StakingContract {
|
|
|
2190
2220
|
{
|
|
2191
2221
|
[stakingToken]: 1n
|
|
2192
2222
|
},
|
|
2193
|
-
|
|
2223
|
+
import_lucid20.Data.void()
|
|
2194
2224
|
).pay.ToContract(
|
|
2195
2225
|
_StakingContract.address(params.stakingParams, lucid),
|
|
2196
2226
|
{
|
|
@@ -2220,9 +2250,9 @@ var StakingContract = class _StakingContract {
|
|
|
2220
2250
|
params.scriptReferences,
|
|
2221
2251
|
lucid
|
|
2222
2252
|
);
|
|
2223
|
-
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0,
|
|
2224
|
-
const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0,
|
|
2225
|
-
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0,
|
|
2253
|
+
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0, import_lucid20.fromText)(params.stakingParams.stakingToken[1].unTokenName);
|
|
2254
|
+
const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0, import_lucid20.fromText)(params.stakingParams.stakingManagerNFT[1].unTokenName);
|
|
2255
|
+
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid20.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
2226
2256
|
const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
|
|
2227
2257
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
2228
2258
|
const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
|
|
@@ -2233,7 +2263,7 @@ var StakingContract = class _StakingContract {
|
|
|
2233
2263
|
newLockedAmount.set(key, [value[0], value[1]]);
|
|
2234
2264
|
}
|
|
2235
2265
|
}
|
|
2236
|
-
return lucid.newTx().validFrom(Date.now()).readFrom([stakingScriptRef]).collectFrom([stakingPositionOut.utxo],
|
|
2266
|
+
return lucid.newTx().validFrom(Date.now()).readFrom([stakingScriptRef]).collectFrom([stakingPositionOut.utxo], import_lucid20.Data.to(new import_lucid20.Constr(3, [amount]))).collectFrom([stakingManagerOut.utxo], import_lucid20.Data.to(new import_lucid20.Constr(1, []))).pay.ToContract(
|
|
2237
2267
|
stakingManagerOut.utxo.address,
|
|
2238
2268
|
{
|
|
2239
2269
|
kind: "inline",
|
|
@@ -2287,14 +2317,14 @@ var StakingContract = class _StakingContract {
|
|
|
2287
2317
|
params.scriptReferences,
|
|
2288
2318
|
lucid
|
|
2289
2319
|
);
|
|
2290
|
-
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0,
|
|
2291
|
-
const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0,
|
|
2292
|
-
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0,
|
|
2320
|
+
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + (0, import_lucid20.fromText)(params.stakingParams.stakingToken[1].unTokenName);
|
|
2321
|
+
const stakingManagerToken = params.stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0, import_lucid20.fromText)(params.stakingParams.stakingManagerNFT[1].unTokenName);
|
|
2322
|
+
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + (0, import_lucid20.fromText)(params.stakingParams.indyToken[1].unTokenName);
|
|
2293
2323
|
const existingIndyAmount = stakingPositionOut.utxo.assets[indyToken] ?? 0n;
|
|
2294
2324
|
const currentSnapshotAda = stakingManagerOut.datum.managerSnapshot.snapshotAda;
|
|
2295
2325
|
const oldSnapshotAda = stakingPositionOut.datum.positionSnapshot.snapshotAda;
|
|
2296
2326
|
const adaReward = (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / (1000000n * 1000000n);
|
|
2297
|
-
return lucid.newTx().validFrom(Date.now()).readFrom([stakingScriptRef]).readFrom([stakingTokenScriptRefUtxo]).collectFrom([stakingPositionOut.utxo],
|
|
2327
|
+
return lucid.newTx().validFrom(Date.now()).readFrom([stakingScriptRef]).readFrom([stakingTokenScriptRefUtxo]).collectFrom([stakingPositionOut.utxo], import_lucid20.Data.to(new import_lucid20.Constr(4, []))).collectFrom([stakingManagerOut.utxo], import_lucid20.Data.to(new import_lucid20.Constr(1, []))).pay.ToContract(
|
|
2298
2328
|
stakingManagerOut.utxo.address,
|
|
2299
2329
|
{
|
|
2300
2330
|
kind: "inline",
|
|
@@ -2315,34 +2345,34 @@ var StakingContract = class _StakingContract {
|
|
|
2315
2345
|
{
|
|
2316
2346
|
[stakingToken]: -1n
|
|
2317
2347
|
},
|
|
2318
|
-
|
|
2348
|
+
import_lucid20.Data.void()
|
|
2319
2349
|
).addSignerKey(pkh.hash);
|
|
2320
2350
|
}
|
|
2321
2351
|
// Staking Validator
|
|
2322
2352
|
static validator(params) {
|
|
2323
2353
|
return {
|
|
2324
2354
|
type: "PlutusV2",
|
|
2325
|
-
script: (0,
|
|
2326
|
-
new
|
|
2327
|
-
new
|
|
2355
|
+
script: (0, import_lucid20.applyParamsToScript)(_stakingValidator.cborHex, [
|
|
2356
|
+
new import_lucid20.Constr(0, [
|
|
2357
|
+
new import_lucid20.Constr(0, [
|
|
2328
2358
|
params.stakingManagerNFT[0].unCurrencySymbol,
|
|
2329
|
-
(0,
|
|
2359
|
+
(0, import_lucid20.fromText)(params.stakingManagerNFT[1].unTokenName)
|
|
2330
2360
|
]),
|
|
2331
|
-
new
|
|
2361
|
+
new import_lucid20.Constr(0, [
|
|
2332
2362
|
params.stakingToken[0].unCurrencySymbol,
|
|
2333
|
-
(0,
|
|
2363
|
+
(0, import_lucid20.fromText)(params.stakingToken[1].unTokenName)
|
|
2334
2364
|
]),
|
|
2335
|
-
new
|
|
2365
|
+
new import_lucid20.Constr(0, [
|
|
2336
2366
|
params.indyToken[0].unCurrencySymbol,
|
|
2337
|
-
(0,
|
|
2367
|
+
(0, import_lucid20.fromText)(params.indyToken[1].unTokenName)
|
|
2338
2368
|
]),
|
|
2339
|
-
new
|
|
2369
|
+
new import_lucid20.Constr(0, [
|
|
2340
2370
|
params.pollToken[0].unCurrencySymbol,
|
|
2341
|
-
(0,
|
|
2371
|
+
(0, import_lucid20.fromText)(params.pollToken[1].unTokenName)
|
|
2342
2372
|
]),
|
|
2343
|
-
new
|
|
2373
|
+
new import_lucid20.Constr(0, [
|
|
2344
2374
|
params.versionRecordToken[0].unCurrencySymbol,
|
|
2345
|
-
(0,
|
|
2375
|
+
(0, import_lucid20.fromText)(params.versionRecordToken[1].unTokenName)
|
|
2346
2376
|
]),
|
|
2347
2377
|
params.collectorValHash
|
|
2348
2378
|
])
|
|
@@ -2350,14 +2380,14 @@ var StakingContract = class _StakingContract {
|
|
|
2350
2380
|
};
|
|
2351
2381
|
}
|
|
2352
2382
|
static validatorHash(params) {
|
|
2353
|
-
return (0,
|
|
2383
|
+
return (0, import_lucid20.validatorToScriptHash)(_StakingContract.validator(params));
|
|
2354
2384
|
}
|
|
2355
2385
|
static address(params, lucid) {
|
|
2356
2386
|
const network = lucid.config().network;
|
|
2357
2387
|
if (!network) {
|
|
2358
2388
|
throw new Error("Network configuration is undefined");
|
|
2359
2389
|
}
|
|
2360
|
-
return (0,
|
|
2390
|
+
return (0, import_lucid20.validatorToAddress)(network, _StakingContract.validator(params));
|
|
2361
2391
|
}
|
|
2362
2392
|
static async scriptRef(params, lucid) {
|
|
2363
2393
|
return scriptRef(params.stakingValidatorRef, lucid);
|
|
@@ -2368,32 +2398,32 @@ var StakingContract = class _StakingContract {
|
|
|
2368
2398
|
};
|
|
2369
2399
|
|
|
2370
2400
|
// src/contracts/interest-oracle.ts
|
|
2371
|
-
var
|
|
2401
|
+
var import_lucid26 = require("@lucid-evolution/lucid");
|
|
2372
2402
|
|
|
2373
2403
|
// src/contracts/one-shot.ts
|
|
2374
|
-
var
|
|
2404
|
+
var import_lucid23 = require("@lucid-evolution/lucid");
|
|
2375
2405
|
|
|
2376
2406
|
// src/scripts/one-shot-policy.ts
|
|
2377
|
-
var
|
|
2407
|
+
var import_lucid22 = require("@lucid-evolution/lucid");
|
|
2378
2408
|
|
|
2379
2409
|
// src/types/one-shot.ts
|
|
2380
|
-
var
|
|
2381
|
-
var OneShotParamsSchema =
|
|
2382
|
-
referenceOutRef:
|
|
2383
|
-
txHash:
|
|
2384
|
-
outputIdx:
|
|
2410
|
+
var import_lucid21 = require("@lucid-evolution/lucid");
|
|
2411
|
+
var OneShotParamsSchema = import_lucid21.Data.Object({
|
|
2412
|
+
referenceOutRef: import_lucid21.Data.Object({
|
|
2413
|
+
txHash: import_lucid21.Data.Bytes(),
|
|
2414
|
+
outputIdx: import_lucid21.Data.Integer()
|
|
2385
2415
|
}),
|
|
2386
|
-
mintAmounts:
|
|
2387
|
-
|
|
2416
|
+
mintAmounts: import_lucid21.Data.Array(
|
|
2417
|
+
import_lucid21.Data.Object({
|
|
2388
2418
|
/// Use hex encoded string
|
|
2389
|
-
tokenName:
|
|
2390
|
-
amount:
|
|
2419
|
+
tokenName: import_lucid21.Data.Bytes(),
|
|
2420
|
+
amount: import_lucid21.Data.Integer()
|
|
2391
2421
|
})
|
|
2392
2422
|
)
|
|
2393
2423
|
});
|
|
2394
2424
|
var OneShotParams = OneShotParamsSchema;
|
|
2395
2425
|
function castOneShotParams(params) {
|
|
2396
|
-
return
|
|
2426
|
+
return import_lucid21.Data.castTo(params, OneShotParams);
|
|
2397
2427
|
}
|
|
2398
2428
|
|
|
2399
2429
|
// src/scripts/one-shot-policy.ts
|
|
@@ -2404,7 +2434,7 @@ var oneShotPolicyData = {
|
|
|
2404
2434
|
function mkOneShotPolicy(params) {
|
|
2405
2435
|
return {
|
|
2406
2436
|
type: oneShotPolicyData.type,
|
|
2407
|
-
script: (0,
|
|
2437
|
+
script: (0, import_lucid22.applyParamsToScript)(oneShotPolicyData.cborHex, [
|
|
2408
2438
|
castOneShotParams(params)
|
|
2409
2439
|
])
|
|
2410
2440
|
};
|
|
@@ -2414,7 +2444,7 @@ function mkOneShotPolicy(params) {
|
|
|
2414
2444
|
var import_Array = require("fp-ts/lib/Array");
|
|
2415
2445
|
async function oneShotMintTx(lucid, params) {
|
|
2416
2446
|
const oneShotPolicy = mkOneShotPolicy(params);
|
|
2417
|
-
const policyId = (0,
|
|
2447
|
+
const policyId = (0, import_lucid23.mintingPolicyToId)(oneShotPolicy);
|
|
2418
2448
|
const refUtxo = matchSingle(
|
|
2419
2449
|
await lucid.utxosByOutRef([
|
|
2420
2450
|
{
|
|
@@ -2430,11 +2460,11 @@ async function oneShotMintTx(lucid, params) {
|
|
|
2430
2460
|
lucid.newTx().collectFrom([refUtxo]).mintAssets(
|
|
2431
2461
|
(0, import_Array.reduce)(
|
|
2432
2462
|
{},
|
|
2433
|
-
(acc, entry) => (0,
|
|
2434
|
-
[(0,
|
|
2463
|
+
(acc, entry) => (0, import_lucid23.addAssets)(acc, {
|
|
2464
|
+
[(0, import_lucid23.toUnit)(policyId, entry.tokenName)]: entry.amount
|
|
2435
2465
|
})
|
|
2436
2466
|
)(params.mintAmounts),
|
|
2437
|
-
|
|
2467
|
+
import_lucid23.Data.to(new import_lucid23.Constr(0, []))
|
|
2438
2468
|
).attach.MintingPolicy(oneShotPolicy),
|
|
2439
2469
|
policyId
|
|
2440
2470
|
];
|
|
@@ -2447,7 +2477,7 @@ async function runOneShotMintTx(lucid, params) {
|
|
|
2447
2477
|
}
|
|
2448
2478
|
|
|
2449
2479
|
// src/scripts/interest-oracle-validator.ts
|
|
2450
|
-
var
|
|
2480
|
+
var import_lucid24 = require("@lucid-evolution/lucid");
|
|
2451
2481
|
var interestOracleValidator = {
|
|
2452
2482
|
type: "PlutusV2",
|
|
2453
2483
|
cborHex: "590a3f590a3c0100003232323232323232223232322322533300932323253323300d3001300f375400426464646464a666024601e60286ea80044c8c8c8c94ccc058cc005241205458206973206e6f74207369676e6564206279206f7261636c65206f776e6572003232330010013758603c603e603e603e603e603e603e603e603e60366ea8038894ccc074004528099299980d19b8f375c604000400829444cc00c00c004c080004dd71801980c9baa01515332330173300249115496e636f72726563742074782076616c6964697479003232323232533301c32533301d300500114a22a66603a60220022944528180f1baa33003300d301f3754004601a603e6ea80044c94ccc074c0680045288a99980e98088008a5114a0603c6ea8cc00cc024c07cdd50011804980f9baa00114a06008601666040601666040600a660406ea0cdc09bad3008301e375402a6eb4c030c078dd500d25eb80cc080ccc06d28a60103d87a80004c0103d87980004bd70198101805998101802998101ba8337006eb4c020c078dd500a9bad300c301e375403497ae03302033301b4a298103d87a80004c0103d87980004bd7025eb80c00cc080c084c084c084c084c084c084c084c074dd50081119299980e180c8008a99980e180c980f1baa00214c103d87a800014c103d87980001533301c30040011533301c3004301e3754004298103d87a800014c103d87b800013232533301e3012001132533301f33710006002298103d87980001533301f337100020062980103d87b800014c103d87a8000375a604860426ea801054ccc078c06c004530103d87b800014c103d8798000301f37540066eb4c088c07cdd5001980e9baa002370e9002118041980e99299980c9806980d9baa001132533301a32533301f301e0011533301b300f301d00114a22a6660366030603a00229405858dd51803980e9baa300b301d3754006260086603e6ea00052f5c0260086603e6ea0cdc0000a400497ae0375a603e60386ea80044004c024c06cdd51804980d9baa0013301d325333019300d301b3754002264a66603464a66603e603c0022a666036601e603a002294454ccc06cc060c0740045280b0b1baa3007301d3754600e603a6ea800c4c010cc07cdd4000a5eb804c010cc07cdd419b80001480052f5c06eb4c07cc070dd500088009804980d9baa3005301b375400297ae01325333018330034912643757272656e742074696d652068617320746f206265203e3d206c6173745f736574746c656400337126eb4c004c06cdd500b1bad3005301b37540242a66466032660089212b496e74657265737420726174652068617320746f20626520696e2072616e6765205b30252c20313030255d0053330193001375a601460386ea8c028c070dd5009899b89375a601460386ea8c028c070dd500999b82480092080897a14a026600892120496e746572657374206f7261636c65206f757470757420696e636f72726563740033332222323300100132323300100101222533302500114bd7009919299981198028010998140011980200200089980200200098148011813800a99980f180d98101baa00413223375e602260466ea8c044c08cdd5000801181218109baa00413223375e602260466ea8004008c090c084dd50021129998118008a5013253330203253330213375e601460486ea80040184c94ccc0980045288a99981318148008991919299981299b8f375c605600691100153330253371e00291010015333025302230273754980103d87a800015333025300d00213371200490404df7010a501300d00214a02940dd7181518158011bad3029302a302a001375860500022940c8cc004004c8ccc004004dd5980818131baa003323300100100822533302900114bd6f7b6300991981599bb037526eb8c0a0004dd319198008009bab302a00222533302c00114bd6f7b6300991981719bb037526eb8c0ac004dd419b8148000dd69816000998018019818001181700099801801981680118158009112999814801080089919980200218168019991191980080080291299981700089981799bb037520086e9800d2f5bded8c0264646464a66605c66ebccc05402000930103d8798000133033337606ea4020dd30038028a99981719b8f008002132533302f302c3031375400226606866ec0dd4804981a98191baa001004100432533302f533303300114a229405300103d87a80001301f33034374c00297ae0323330010010080022225333035002100113233300400430390033322323300100100522533303a00113303b337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0e8cdd799810804001260103d879800013303f337606ea4020dd40038028a99981d19b8f008002132533303b3038303d375400226608066ec0dd48049820981f1baa001004100432533303b303800114c103d87a80001302b33040375000297ae03370000e00226607e66ec0dd48011ba800133006006003375a60780066eb8c0e8008c0f8008c0f0004dd7181a0009bad30350013037002133033337606ea4008dd3000998030030019bab3030003375c605c004606400460600026eb8c0a0004dd5981480098158011129998138008a5eb804c8ccc888c8cc00400400c894ccc0b4004400c4c8cc0bcdd3998179ba90063302f37526eb8c0b0004cc0bcdd41bad302d0014bd7019801801981880118178009bae30260013756604e00266006006605600460520022940c098008528899801801800981300091299980d99b9000200114c103d87980001533301b3371e0040022980103d87a800014c103d87b800030033301e30093301e0053301e4c0103d87a80004bd7025eb80cdd2a40086603c60126603c6ea0cdc01bad300a301c375402e64a66603466e20dd69801980e9baa01800113370666e0ccdc119b82337020026eb4c00cc074dd500c1bad300b301d3754600e603a6ea8061208080a0f6f4acdbe01b48202c227efa8052080897a153301b491254d75737420686f6c643a206e6f77203e206c61737420696e746572657374207570646174650016375a600c60386ea804ccc078c028c070dd50099980f1803180e1baa0134bd7025eb80dd59803180e1baa3006301c375400e6e25200014a029408c078c07cc07c004dd2a4004294052811299980b99980b800a504a22a6603000420022002600a602e6ea8c014c05cdd51800980b9baa0022301a301b0013018301537540022c6644646600200200644a666032002298103d87a80001323253330173375e601060346ea80080144c01ccc0700092f5c0266008008002603a00460360026eb0c05c010c05cc050dd50031ba5480008c058004dd6180a180a980a80098081baa003370e90010b18089809001180800098061baa00114984d9594ccc01cc010c024dd50008991919192999807980900109924c600e0062c6eb4c040004c040008c038004c028dd50008b2999802980118039baa0031323232323232533300f3012002132498c01c00c58dd698080009808001180700098070011bad300c001300837540062c4a66600a6004600e6ea80044c8c94ccc02cc03800852616375a601800260106ea800458dc3a4000ae695ce2ab9d5573caae7d5d02ba157441"
|
|
@@ -2455,19 +2485,19 @@ var interestOracleValidator = {
|
|
|
2455
2485
|
function mkInterestOracleValidator(params) {
|
|
2456
2486
|
return {
|
|
2457
2487
|
type: interestOracleValidator.type,
|
|
2458
|
-
script: (0,
|
|
2488
|
+
script: (0, import_lucid24.applyParamsToScript)(interestOracleValidator.cborHex, [
|
|
2459
2489
|
castInterestOracleParams(params)
|
|
2460
2490
|
])
|
|
2461
2491
|
};
|
|
2462
2492
|
}
|
|
2463
2493
|
|
|
2464
2494
|
// src/helpers/value-helpers.ts
|
|
2465
|
-
var
|
|
2495
|
+
var import_lucid25 = require("@lucid-evolution/lucid");
|
|
2466
2496
|
function mkLovelacesOf(amount) {
|
|
2467
2497
|
return { lovelace: amount };
|
|
2468
2498
|
}
|
|
2469
2499
|
function assetClassToUnit(ac) {
|
|
2470
|
-
return (0,
|
|
2500
|
+
return (0, import_lucid25.toUnit)(ac.currencySymbol, ac.tokenName);
|
|
2471
2501
|
}
|
|
2472
2502
|
function mkAssetsOf(assetClass, amount) {
|
|
2473
2503
|
return {
|
|
@@ -2499,14 +2529,14 @@ var InterestOracleContract = class {
|
|
|
2499
2529
|
},
|
|
2500
2530
|
mintAmounts: [
|
|
2501
2531
|
{
|
|
2502
|
-
tokenName: (0,
|
|
2532
|
+
tokenName: (0, import_lucid26.fromText)(tokenName),
|
|
2503
2533
|
amount: 1n
|
|
2504
2534
|
}
|
|
2505
2535
|
]
|
|
2506
2536
|
});
|
|
2507
2537
|
const validator = mkInterestOracleValidator(oracleParams);
|
|
2508
2538
|
tx.pay.ToContract(
|
|
2509
|
-
(0,
|
|
2539
|
+
(0, import_lucid26.validatorToAddress)(lucid.config().network, validator),
|
|
2510
2540
|
{
|
|
2511
2541
|
kind: "inline",
|
|
2512
2542
|
value: serialiseInterestOracleDatum({
|
|
@@ -2519,12 +2549,12 @@ var InterestOracleContract = class {
|
|
|
2519
2549
|
},
|
|
2520
2550
|
{
|
|
2521
2551
|
lovelace: 2500000n,
|
|
2522
|
-
[(0,
|
|
2552
|
+
[(0, import_lucid26.toUnit)(policyId, (0, import_lucid26.fromText)(tokenName))]: 1n
|
|
2523
2553
|
}
|
|
2524
2554
|
);
|
|
2525
2555
|
if (withScriptRef) {
|
|
2526
2556
|
tx.pay.ToAddressWithData(
|
|
2527
|
-
(0,
|
|
2557
|
+
(0, import_lucid26.validatorToAddress)(lucid.config().network, validator),
|
|
2528
2558
|
void 0,
|
|
2529
2559
|
void 0,
|
|
2530
2560
|
validator
|
|
@@ -2534,7 +2564,7 @@ var InterestOracleContract = class {
|
|
|
2534
2564
|
tx,
|
|
2535
2565
|
{
|
|
2536
2566
|
currencySymbol: policyId,
|
|
2537
|
-
tokenName: (0,
|
|
2567
|
+
tokenName: (0, import_lucid26.fromText)(tokenName)
|
|
2538
2568
|
}
|
|
2539
2569
|
];
|
|
2540
2570
|
}
|
|
@@ -2584,7 +2614,7 @@ var InterestOracleContract = class {
|
|
|
2584
2614
|
};
|
|
2585
2615
|
|
|
2586
2616
|
// src/scripts/cdp-creator-validator.ts
|
|
2587
|
-
var
|
|
2617
|
+
var import_lucid27 = require("@lucid-evolution/lucid");
|
|
2588
2618
|
var cdpCreatorValidator = {
|
|
2589
2619
|
type: "PlutusV2",
|
|
2590
2620
|
description: "",
|
|
@@ -2593,7 +2623,7 @@ var cdpCreatorValidator = {
|
|
|
2593
2623
|
var mkCDPCreatorValidator = (params) => {
|
|
2594
2624
|
return {
|
|
2595
2625
|
type: cdpCreatorValidator.type,
|
|
2596
|
-
script: (0,
|
|
2626
|
+
script: (0, import_lucid27.applyParamsToScript)(cdpCreatorValidator.cborHex, [
|
|
2597
2627
|
castCDPCreatorParams(params)
|
|
2598
2628
|
])
|
|
2599
2629
|
};
|
|
@@ -2601,7 +2631,7 @@ var mkCDPCreatorValidator = (params) => {
|
|
|
2601
2631
|
var mkCDPCreatorValidatorFromSP = (params) => {
|
|
2602
2632
|
return {
|
|
2603
2633
|
type: cdpCreatorValidator.type,
|
|
2604
|
-
script: (0,
|
|
2634
|
+
script: (0, import_lucid27.applyParamsToScript)(cdpCreatorValidator.cborHex, [
|
|
2605
2635
|
castCDPCreatorParams({
|
|
2606
2636
|
cdpCreatorNft: fromSystemParamsAsset(params.cdpCreatorNft),
|
|
2607
2637
|
cdpAssetCs: params.cdpAssetCs.unCurrencySymbol,
|
|
@@ -2618,19 +2648,19 @@ var mkCDPCreatorValidatorFromSP = (params) => {
|
|
|
2618
2648
|
};
|
|
2619
2649
|
|
|
2620
2650
|
// src/scripts/poll-shard-validator.ts
|
|
2621
|
-
var
|
|
2651
|
+
var import_lucid29 = require("@lucid-evolution/lucid");
|
|
2622
2652
|
|
|
2623
2653
|
// src/types/indigo/poll-shard.ts
|
|
2624
|
-
var
|
|
2625
|
-
var PollShardParamsSchema =
|
|
2654
|
+
var import_lucid28 = require("@lucid-evolution/lucid");
|
|
2655
|
+
var PollShardParamsSchema = import_lucid28.Data.Object({
|
|
2626
2656
|
pollToken: AssetClassSchema,
|
|
2627
2657
|
stakingToken: AssetClassSchema,
|
|
2628
2658
|
indyAsset: AssetClassSchema,
|
|
2629
|
-
stakingValHash:
|
|
2659
|
+
stakingValHash: import_lucid28.Data.Bytes()
|
|
2630
2660
|
});
|
|
2631
2661
|
var PollShardParams = PollShardParamsSchema;
|
|
2632
2662
|
function castPollShardParams(params) {
|
|
2633
|
-
return
|
|
2663
|
+
return import_lucid28.Data.castTo(params, PollShardParams);
|
|
2634
2664
|
}
|
|
2635
2665
|
|
|
2636
2666
|
// src/scripts/poll-shard-validator.ts
|
|
@@ -2642,7 +2672,7 @@ var pollShardValidatorData = {
|
|
|
2642
2672
|
var mkPollShardValidator = (params) => {
|
|
2643
2673
|
return {
|
|
2644
2674
|
type: pollShardValidatorData.type,
|
|
2645
|
-
script: (0,
|
|
2675
|
+
script: (0, import_lucid29.applyParamsToScript)(pollShardValidatorData.cborHex, [
|
|
2646
2676
|
castPollShardParams(params)
|
|
2647
2677
|
])
|
|
2648
2678
|
};
|
|
@@ -2650,7 +2680,7 @@ var mkPollShardValidator = (params) => {
|
|
|
2650
2680
|
var mkPollShardValidatorFromSP = (params) => {
|
|
2651
2681
|
return {
|
|
2652
2682
|
type: pollShardValidatorData.type,
|
|
2653
|
-
script: (0,
|
|
2683
|
+
script: (0, import_lucid29.applyParamsToScript)(pollShardValidatorData.cborHex, [
|
|
2654
2684
|
castPollShardParams({
|
|
2655
2685
|
pollToken: fromSystemParamsAsset(params.pollToken),
|
|
2656
2686
|
stakingToken: fromSystemParamsAsset(params.stakingToken),
|
|
@@ -2662,24 +2692,24 @@ var mkPollShardValidatorFromSP = (params) => {
|
|
|
2662
2692
|
};
|
|
2663
2693
|
|
|
2664
2694
|
// src/scripts/poll-manager-validator.ts
|
|
2665
|
-
var
|
|
2695
|
+
var import_lucid31 = require("@lucid-evolution/lucid");
|
|
2666
2696
|
|
|
2667
2697
|
// src/types/indigo/poll-manager.ts
|
|
2668
|
-
var
|
|
2669
|
-
var PollManagerParamsSchema =
|
|
2698
|
+
var import_lucid30 = require("@lucid-evolution/lucid");
|
|
2699
|
+
var PollManagerParamsSchema = import_lucid30.Data.Object({
|
|
2670
2700
|
govNFT: AssetClassSchema,
|
|
2671
2701
|
pollToken: AssetClassSchema,
|
|
2672
2702
|
upgradeToken: AssetClassSchema,
|
|
2673
2703
|
indyAsset: AssetClassSchema,
|
|
2674
|
-
govExecuteValHash:
|
|
2675
|
-
pBiasTime:
|
|
2676
|
-
shardValHash:
|
|
2677
|
-
treasuryValHash:
|
|
2678
|
-
initialIndyDistribution:
|
|
2704
|
+
govExecuteValHash: import_lucid30.Data.Bytes(),
|
|
2705
|
+
pBiasTime: import_lucid30.Data.Integer(),
|
|
2706
|
+
shardValHash: import_lucid30.Data.Bytes(),
|
|
2707
|
+
treasuryValHash: import_lucid30.Data.Bytes(),
|
|
2708
|
+
initialIndyDistribution: import_lucid30.Data.Integer()
|
|
2679
2709
|
});
|
|
2680
2710
|
var PollManagerParams = PollManagerParamsSchema;
|
|
2681
2711
|
function castPollManagerParams(params) {
|
|
2682
|
-
return
|
|
2712
|
+
return import_lucid30.Data.castTo(params, PollManagerParams);
|
|
2683
2713
|
}
|
|
2684
2714
|
|
|
2685
2715
|
// src/scripts/poll-manager-validator.ts
|
|
@@ -2691,7 +2721,7 @@ var pollManagerValidatorData = {
|
|
|
2691
2721
|
var mkPollManagerValidator = (params) => {
|
|
2692
2722
|
return {
|
|
2693
2723
|
type: pollManagerValidatorData.type,
|
|
2694
|
-
script: (0,
|
|
2724
|
+
script: (0, import_lucid31.applyParamsToScript)(pollManagerValidatorData.cborHex, [
|
|
2695
2725
|
castPollManagerParams(params)
|
|
2696
2726
|
])
|
|
2697
2727
|
};
|
|
@@ -2699,7 +2729,7 @@ var mkPollManagerValidator = (params) => {
|
|
|
2699
2729
|
var mkPollManagerValidatorFromSP = (params) => {
|
|
2700
2730
|
return {
|
|
2701
2731
|
type: pollManagerValidatorData.type,
|
|
2702
|
-
script: (0,
|
|
2732
|
+
script: (0, import_lucid31.applyParamsToScript)(pollManagerValidatorData.cborHex, [
|
|
2703
2733
|
castPollManagerParams({
|
|
2704
2734
|
govNFT: fromSystemParamsAsset(params.govNFT),
|
|
2705
2735
|
pollToken: fromSystemParamsAsset(params.pollToken),
|
|
@@ -2716,71 +2746,71 @@ var mkPollManagerValidatorFromSP = (params) => {
|
|
|
2716
2746
|
};
|
|
2717
2747
|
|
|
2718
2748
|
// src/types/indigo/execute.ts
|
|
2719
|
-
var
|
|
2720
|
-
var ExecuteParamsSchema =
|
|
2749
|
+
var import_lucid32 = require("@lucid-evolution/lucid");
|
|
2750
|
+
var ExecuteParamsSchema = import_lucid32.Data.Object({
|
|
2721
2751
|
govNFT: AssetClassSchema,
|
|
2722
2752
|
upgradeToken: AssetClassSchema,
|
|
2723
2753
|
iAssetToken: AssetClassSchema,
|
|
2724
2754
|
stabilityPoolToken: AssetClassSchema,
|
|
2725
2755
|
versionRecordToken: AssetClassSchema,
|
|
2726
|
-
cdpValHash:
|
|
2727
|
-
sPoolValHash:
|
|
2728
|
-
versionRegistryValHash:
|
|
2729
|
-
treasuryValHash:
|
|
2756
|
+
cdpValHash: import_lucid32.Data.Bytes(),
|
|
2757
|
+
sPoolValHash: import_lucid32.Data.Bytes(),
|
|
2758
|
+
versionRegistryValHash: import_lucid32.Data.Bytes(),
|
|
2759
|
+
treasuryValHash: import_lucid32.Data.Bytes(),
|
|
2730
2760
|
indyAsset: AssetClassSchema
|
|
2731
2761
|
});
|
|
2732
2762
|
var ExecuteParams = ExecuteParamsSchema;
|
|
2733
2763
|
function castExecuteParams(params) {
|
|
2734
|
-
return
|
|
2764
|
+
return import_lucid32.Data.castTo(params, ExecuteParams);
|
|
2735
2765
|
}
|
|
2736
2766
|
|
|
2737
2767
|
// src/types/indigo/lrp.ts
|
|
2738
|
-
var
|
|
2739
|
-
var LRPParamsSchema =
|
|
2768
|
+
var import_lucid33 = require("@lucid-evolution/lucid");
|
|
2769
|
+
var LRPParamsSchema = import_lucid33.Data.Object({
|
|
2740
2770
|
versionRecordToken: AssetClassSchema,
|
|
2741
2771
|
iassetNft: AssetClassSchema,
|
|
2742
|
-
iassetPolicyId:
|
|
2743
|
-
minRedemptionLovelacesAmt:
|
|
2772
|
+
iassetPolicyId: import_lucid33.Data.Bytes(),
|
|
2773
|
+
minRedemptionLovelacesAmt: import_lucid33.Data.Integer()
|
|
2744
2774
|
});
|
|
2745
2775
|
var LRPParams = LRPParamsSchema;
|
|
2746
|
-
var LRPDatumSchema =
|
|
2747
|
-
owner:
|
|
2748
|
-
iasset:
|
|
2776
|
+
var LRPDatumSchema = import_lucid33.Data.Object({
|
|
2777
|
+
owner: import_lucid33.Data.Bytes(),
|
|
2778
|
+
iasset: import_lucid33.Data.Bytes(),
|
|
2749
2779
|
maxPrice: OnChainDecimalSchema,
|
|
2750
2780
|
/**
|
|
2751
2781
|
* The amount of lovelaces that is available to be spent.
|
|
2752
2782
|
* This doesn't correspond to the lovelaces in UTXO's value,
|
|
2753
2783
|
* since that can contain fees, too.
|
|
2754
2784
|
*/
|
|
2755
|
-
lovelacesToSpend:
|
|
2785
|
+
lovelacesToSpend: import_lucid33.Data.Integer()
|
|
2756
2786
|
});
|
|
2757
2787
|
var LRPDatum = LRPDatumSchema;
|
|
2758
|
-
var LRPRedeemerSchema =
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
RedeemAuxiliary:
|
|
2762
|
-
continuingOutputIdx:
|
|
2788
|
+
var LRPRedeemerSchema = import_lucid33.Data.Enum([
|
|
2789
|
+
import_lucid33.Data.Object({ Redeem: import_lucid33.Data.Object({ continuingOutputIdx: import_lucid33.Data.Integer() }) }),
|
|
2790
|
+
import_lucid33.Data.Object({
|
|
2791
|
+
RedeemAuxiliary: import_lucid33.Data.Object({
|
|
2792
|
+
continuingOutputIdx: import_lucid33.Data.Integer(),
|
|
2763
2793
|
mainRedeemOutRef: OutputReferenceSchema,
|
|
2764
|
-
asset:
|
|
2794
|
+
asset: import_lucid33.Data.Bytes(),
|
|
2765
2795
|
assetPrice: OnChainDecimalSchema,
|
|
2766
2796
|
redemptionReimbursementPercentage: OnChainDecimalSchema
|
|
2767
2797
|
})
|
|
2768
2798
|
}),
|
|
2769
|
-
|
|
2770
|
-
|
|
2799
|
+
import_lucid33.Data.Literal("Cancel"),
|
|
2800
|
+
import_lucid33.Data.Literal("UpgradeVersion")
|
|
2771
2801
|
]);
|
|
2772
2802
|
var LRPRedeemer = LRPRedeemerSchema;
|
|
2773
2803
|
function parseLrpDatum(datum) {
|
|
2774
|
-
return
|
|
2804
|
+
return import_lucid33.Data.from(datum, LRPDatum);
|
|
2775
2805
|
}
|
|
2776
2806
|
function serialiseLrpDatum(datum) {
|
|
2777
|
-
return
|
|
2807
|
+
return import_lucid33.Data.to(datum, LRPDatum);
|
|
2778
2808
|
}
|
|
2779
2809
|
function serialiseLrpRedeemer(redeemer) {
|
|
2780
|
-
return
|
|
2810
|
+
return import_lucid33.Data.to(redeemer, LRPRedeemer);
|
|
2781
2811
|
}
|
|
2782
2812
|
function castLrpParams(params) {
|
|
2783
|
-
return
|
|
2813
|
+
return import_lucid33.Data.castTo(params, LRPParams);
|
|
2784
2814
|
}
|
|
2785
2815
|
|
|
2786
2816
|
// src/contracts/lrp.ts
|
|
@@ -2788,24 +2818,6 @@ var import_lucid34 = require("@lucid-evolution/lucid");
|
|
|
2788
2818
|
var import_ts_pattern5 = require("ts-pattern");
|
|
2789
2819
|
var import_Array2 = require("fp-ts/lib/Array");
|
|
2790
2820
|
var import_Array3 = require("fp-ts/lib/Array");
|
|
2791
|
-
|
|
2792
|
-
// src/helpers/price-oracle-helpers.ts
|
|
2793
|
-
var import_lucid33 = require("@lucid-evolution/lucid");
|
|
2794
|
-
function oracleExpirationAwareValidity(currentSlot, biasTime, oracleExpiration, network) {
|
|
2795
|
-
const validateFrom = (0, import_lucid33.slotToUnixTime)(network, currentSlot - 1);
|
|
2796
|
-
const defaultValidateTo = validateFrom + biasTime;
|
|
2797
|
-
const cappedValidateTo = (0, import_lucid33.slotToUnixTime)(
|
|
2798
|
-
network,
|
|
2799
|
-
(0, import_lucid33.unixTimeToSlot)(network, oracleExpiration) - 1
|
|
2800
|
-
);
|
|
2801
|
-
const isOracleActuallyExpired = cappedValidateTo <= validateFrom;
|
|
2802
|
-
return {
|
|
2803
|
-
validFrom: validateFrom,
|
|
2804
|
-
validTo: isOracleActuallyExpired ? defaultValidateTo : Math.min(defaultValidateTo, cappedValidateTo)
|
|
2805
|
-
};
|
|
2806
|
-
}
|
|
2807
|
-
|
|
2808
|
-
// src/contracts/lrp.ts
|
|
2809
2821
|
var MIN_UTXO_COLLATERAL_AMT = 2000000n;
|
|
2810
2822
|
async function openLrp(assetTokenName, lovelacesAmt, maxPrice, lucid, lrpScriptHash, network, lrpStakeCredential) {
|
|
2811
2823
|
const [ownPkh, _] = await addrDetails(lucid);
|
|
@@ -2836,7 +2848,7 @@ async function cancelLrp(lrpOutRef, lrpRefScriptOutRef, lucid) {
|
|
|
2836
2848
|
);
|
|
2837
2849
|
return lucid.newTx().readFrom([lrpScriptRefUtxo]).collectFrom([lrpUtxo], serialiseLrpRedeemer("Cancel")).addSigner(ownAddr);
|
|
2838
2850
|
}
|
|
2839
|
-
async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutRef, iassetOutRef, lucid, lrpParams,
|
|
2851
|
+
async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutRef, iassetOutRef, lucid, lrpParams, network) {
|
|
2840
2852
|
const lrpScriptRefUtxo = matchSingle(
|
|
2841
2853
|
await lucid.utxosByOutRef([lrpRefScriptOutRef]),
|
|
2842
2854
|
(_2) => new Error("Expected a single LRP Ref Script UTXO")
|
|
@@ -2918,13 +2930,12 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
|
|
|
2918
2930
|
);
|
|
2919
2931
|
}
|
|
2920
2932
|
)(redemptionLrps);
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
);
|
|
2927
|
-
return lucid.newTx().validFrom(txValidity.validFrom).validTo(txValidity.validTo).readFrom([lrpScriptRefUtxo]).readFrom([iassetUtxo, priceOracleUtxo]).compose(tx);
|
|
2933
|
+
return lucid.newTx().validTo(
|
|
2934
|
+
(0, import_lucid34.slotToUnixTime)(
|
|
2935
|
+
network,
|
|
2936
|
+
(0, import_lucid34.unixTimeToSlot)(network, Number(priceOracleDatum.expiration)) - 1
|
|
2937
|
+
)
|
|
2938
|
+
).readFrom([lrpScriptRefUtxo]).readFrom([iassetUtxo, priceOracleUtxo]).compose(tx);
|
|
2928
2939
|
}
|
|
2929
2940
|
async function adjustLrp(lucid, lrpOutRef, lovelacesAdjustAmt, lrpRefScriptOutRef, lrpParams) {
|
|
2930
2941
|
const ownAddr = await lucid.wallet().address();
|