@indigo-labs/indigo-sdk 0.4.0 → 0.4.1
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/.claude/settings.local.json +7 -0
- package/.github/workflows/ci.yml +0 -1
- package/README.md +16 -0
- package/dist/index.d.mts +33 -3
- package/dist/index.d.ts +33 -3
- package/dist/index.js +587 -355
- package/dist/index.mjs +422 -187
- package/package.json +12 -20
- package/scripts/bench.sh +0 -0
- package/src/contracts/cdp-creator/queries.ts +30 -0
- package/src/contracts/iasset/queries.ts +102 -0
- package/src/contracts/initialize/actions.ts +12 -5
- package/{tests/interest-collection/interest-collector-queries.ts → src/contracts/interest-collection/queries.ts} +28 -12
- package/src/contracts/pyth-feed/helpers.ts +24 -0
- package/{tests/treasury/treasury-queries.ts → src/contracts/treasury/queries.ts} +15 -24
- package/src/index.ts +6 -1
- package/tests/cdp/actions.ts +1 -1
- package/tests/cdp/cdp-queries.ts +3 -23
- package/tests/cdp/transactions-mutated.ts +3 -4
- package/tests/gov/gov.test.ts +18 -18
- package/tests/interest-collection/interest-collection.test.ts +17 -62
- package/tests/queries/iasset-queries.ts +1 -84
- package/tests/rob/rob.test.ts +52 -52
- package/tests/stableswap/stableswap.test.ts +1 -1
- package/tests/treasury/actions.ts +1 -1
- package/tests/treasury/treasury.test.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -136,6 +136,7 @@ __export(index_exports, {
|
|
|
136
136
|
closeCdp: () => closeCdp,
|
|
137
137
|
closeStakingPosition: () => closeStakingPosition,
|
|
138
138
|
collectInterestTx: () => collectInterestTx,
|
|
139
|
+
collectPriceFeedIds: () => collectPriceFeedIds,
|
|
139
140
|
collectorFeeTx: () => collectorFeeTx,
|
|
140
141
|
createDestinationDatum: () => createDestinationDatum,
|
|
141
142
|
createE2s2sSnapshots: () => createE2s2sSnapshots,
|
|
@@ -148,6 +149,7 @@ __export(index_exports, {
|
|
|
148
149
|
decodePythMessage: () => decodePythMessage,
|
|
149
150
|
depositCdp: () => depositCdp,
|
|
150
151
|
deriveAuthToken: () => deriveAuthToken,
|
|
152
|
+
derivePythPrice: () => derivePythPrice,
|
|
151
153
|
distributeAda: () => distributeAda,
|
|
152
154
|
distributeInterest: () => distributeInterest,
|
|
153
155
|
distributeReward: () => distributeReward,
|
|
@@ -160,6 +162,17 @@ __export(index_exports, {
|
|
|
160
162
|
executeProposal: () => executeProposal,
|
|
161
163
|
feedInterestOracle: () => feedInterestOracle,
|
|
162
164
|
feedPriceOracleTx: () => feedPriceOracleTx,
|
|
165
|
+
findAdminInterestCollectors: () => findAdminInterestCollectors,
|
|
166
|
+
findAllInterestCollectors: () => findAllInterestCollectors,
|
|
167
|
+
findAllTreasuryUtxos: () => findAllTreasuryUtxos,
|
|
168
|
+
findAllTreasuryUtxosWithNonAdaAsset: () => findAllTreasuryUtxosWithNonAdaAsset,
|
|
169
|
+
findCollateralAsset: () => findCollateralAsset,
|
|
170
|
+
findIAsset: () => findIAsset,
|
|
171
|
+
findRandomCdpCreator: () => findRandomCdpCreator,
|
|
172
|
+
findRandomNonAdminInterestCollector: () => findRandomNonAdminInterestCollector,
|
|
173
|
+
findRandomTreasuryUtxo: () => findRandomTreasuryUtxo,
|
|
174
|
+
findRandomTreasuryUtxoWithAsset: () => findRandomTreasuryUtxoWithAsset,
|
|
175
|
+
findRandomTreasuryUtxoWithOnlyAda: () => findRandomTreasuryUtxoWithOnlyAda,
|
|
163
176
|
findRelevantE2s2sIdxs: () => findRelevantE2s2sIdxs,
|
|
164
177
|
findStakingManager: () => findStakingManager,
|
|
165
178
|
findStakingManagerByOutRef: () => findStakingManagerByOutRef,
|
|
@@ -1938,7 +1951,7 @@ function partitionEpochToScaleToSums(spContent) {
|
|
|
1938
1951
|
}
|
|
1939
1952
|
|
|
1940
1953
|
// src/contracts/cdp/transactions.ts
|
|
1941
|
-
var
|
|
1954
|
+
var import_fp_ts13 = require("fp-ts");
|
|
1942
1955
|
|
|
1943
1956
|
// src/contracts/interest-collection/transactions.ts
|
|
1944
1957
|
var import_lucid9 = require("@lucid-evolution/lucid");
|
|
@@ -3975,6 +3988,19 @@ async function encodeSignedPythMessage(update, secretKey) {
|
|
|
3975
3988
|
|
|
3976
3989
|
// src/contracts/pyth-feed/helpers.ts
|
|
3977
3990
|
var import_lucid12 = require("@lucid-evolution/lucid");
|
|
3991
|
+
var import_fp_ts12 = require("fp-ts");
|
|
3992
|
+
function collectPriceFeedIds(derivedPythPrice) {
|
|
3993
|
+
const ids = (0, import_ts_pattern11.match)(derivedPythPrice).with({ Value: import_ts_pattern11.P.select() }, (value) => [
|
|
3994
|
+
BigInt(value.configuration.priceFeedId)
|
|
3995
|
+
]).with(
|
|
3996
|
+
{ Inverse: import_ts_pattern11.P.select() },
|
|
3997
|
+
(inverse) => collectPriceFeedIds(fromDataDerivedPythPrice(inverse.value))
|
|
3998
|
+
).with({ Divide: import_ts_pattern11.P.select() }, (divide) => [
|
|
3999
|
+
...collectPriceFeedIds(fromDataDerivedPythPrice(divide.x)),
|
|
4000
|
+
...collectPriceFeedIds(fromDataDerivedPythPrice(divide.y))
|
|
4001
|
+
]).exhaustive();
|
|
4002
|
+
return import_fp_ts12.function.pipe(ids, import_fp_ts12.array.uniq(BigIntOrd), import_fp_ts12.array.sort(BigIntOrd));
|
|
4003
|
+
}
|
|
3978
4004
|
function derivePythPrice(derivedPythPrice, messageHex) {
|
|
3979
4005
|
const decodedMessage = decodePythMessage((0, import_lucid12.fromHex)(messageHex));
|
|
3980
4006
|
const pricePayload = decodePriceUpdate(decodedMessage.payload);
|
|
@@ -4795,10 +4821,10 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, coll
|
|
|
4795
4821
|
const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
|
|
4796
4822
|
tx.validFrom(validateFrom).validTo(validateTo);
|
|
4797
4823
|
}
|
|
4798
|
-
const partialRedemptionFee =
|
|
4824
|
+
const partialRedemptionFee = import_fp_ts13.function.pipe(
|
|
4799
4825
|
govDatum.protocolParams.cdpRedemptionRequiredSignature,
|
|
4800
|
-
|
|
4801
|
-
|
|
4826
|
+
import_fp_ts13.option.fromNullable,
|
|
4827
|
+
import_fp_ts13.option.match(
|
|
4802
4828
|
// When public redemptions
|
|
4803
4829
|
() => {
|
|
4804
4830
|
return isPartial ? BigInt(sysParams.cdpRedeemParams.partialRedemptionExtraFeeLovelace) : 0n;
|
|
@@ -5191,17 +5217,17 @@ async function mergeCdps(cdpsToMergeUtxos, sysParams, lucid) {
|
|
|
5191
5217
|
if (cdpUtxos.length !== cdpsToMergeUtxos.length) {
|
|
5192
5218
|
throw new Error("Expected certain number of CDPs");
|
|
5193
5219
|
}
|
|
5194
|
-
const aggregatedVal =
|
|
5220
|
+
const aggregatedVal = import_fp_ts13.function.pipe(
|
|
5195
5221
|
cdpUtxos,
|
|
5196
|
-
|
|
5222
|
+
import_fp_ts13.array.reduce({}, (acc, utxo) => (0, import_lucid14.addAssets)(acc, utxo.assets))
|
|
5197
5223
|
);
|
|
5198
|
-
const aggregatedMintedAmt =
|
|
5224
|
+
const aggregatedMintedAmt = import_fp_ts13.function.pipe(
|
|
5199
5225
|
cdpDatums,
|
|
5200
|
-
|
|
5226
|
+
import_fp_ts13.array.reduce(0n, (acc, cdpDat) => acc + cdpDat.mintedAmt)
|
|
5201
5227
|
);
|
|
5202
|
-
const { aggregatedInterest, aggregatedCollateralTreasury } =
|
|
5228
|
+
const { aggregatedInterest, aggregatedCollateralTreasury } = import_fp_ts13.function.pipe(
|
|
5203
5229
|
cdpDatums,
|
|
5204
|
-
|
|
5230
|
+
import_fp_ts13.array.reduce(
|
|
5205
5231
|
{ aggregatedCollateralTreasury: 0n, aggregatedInterest: 0n },
|
|
5206
5232
|
(acc, cdpDat) => (0, import_ts_pattern14.match)(cdpDat.cdpFees).returnType().with({ FrozenCDPAccumulatedFees: import_ts_pattern14.P.select() }, (fees) => ({
|
|
5207
5233
|
aggregatedCollateralTreasury: acc.aggregatedCollateralTreasury + fees.collateralTreasury,
|
|
@@ -5210,7 +5236,7 @@ async function mergeCdps(cdpsToMergeUtxos, sysParams, lucid) {
|
|
|
5210
5236
|
)
|
|
5211
5237
|
);
|
|
5212
5238
|
const [[mainMergeUtxo, mainCdpDatum], otherMergeUtxos] = (0, import_ts_pattern14.match)(
|
|
5213
|
-
|
|
5239
|
+
import_fp_ts13.array.zip(cdpUtxos, cdpDatums)
|
|
5214
5240
|
).returnType().with([import_ts_pattern14.P._, ...import_ts_pattern14.P.array()], ([main, ...other]) => [
|
|
5215
5241
|
main,
|
|
5216
5242
|
other.map((a) => a[0])
|
|
@@ -5420,6 +5446,27 @@ var mkCDPCreatorValidatorFromSP = (params) => {
|
|
|
5420
5446
|
};
|
|
5421
5447
|
};
|
|
5422
5448
|
|
|
5449
|
+
// src/contracts/cdp-creator/queries.ts
|
|
5450
|
+
var import_cardano_offchain_common14 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
5451
|
+
var import_fp_ts14 = require("fp-ts");
|
|
5452
|
+
async function findRandomCdpCreator(lucid, sysParams) {
|
|
5453
|
+
const cdpCreatorUtxos = await lucid.utxosAtWithUnit(
|
|
5454
|
+
createScriptAddress(
|
|
5455
|
+
lucid.config().network,
|
|
5456
|
+
sysParams.validatorHashes.cdpCreatorHash
|
|
5457
|
+
),
|
|
5458
|
+
(0, import_cardano_offchain_common14.assetClassToUnit)(
|
|
5459
|
+
fromSystemParamsAsset(sysParams.cdpCreatorParams.cdpCreatorNft)
|
|
5460
|
+
)
|
|
5461
|
+
);
|
|
5462
|
+
return import_fp_ts14.function.pipe(
|
|
5463
|
+
import_fp_ts14.option.fromNullable((0, import_cardano_offchain_common14.getRandomElement)(cdpCreatorUtxos)),
|
|
5464
|
+
import_fp_ts14.option.match(() => {
|
|
5465
|
+
throw new Error("Expected some cdp creator UTXOs.");
|
|
5466
|
+
}, import_fp_ts14.function.identity)
|
|
5467
|
+
);
|
|
5468
|
+
}
|
|
5469
|
+
|
|
5423
5470
|
// src/contracts/poll/scripts.ts
|
|
5424
5471
|
var import_lucid21 = require("@lucid-evolution/lucid");
|
|
5425
5472
|
|
|
@@ -5533,7 +5580,7 @@ function serialiseCollectorRedeemer(r) {
|
|
|
5533
5580
|
}
|
|
5534
5581
|
|
|
5535
5582
|
// src/contracts/collector/transactions.ts
|
|
5536
|
-
var
|
|
5583
|
+
var import_cardano_offchain_common15 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
5537
5584
|
async function collectorFeeTx(fee, lucid, params, tx, collectorOref) {
|
|
5538
5585
|
const collectorUtxo = matchSingle(
|
|
5539
5586
|
await lucid.utxosByOutRef([collectorOref]),
|
|
@@ -5548,22 +5595,22 @@ async function collectorFeeTx(fee, lucid, params, tx, collectorOref) {
|
|
|
5548
5595
|
tx.collectFrom([collectorUtxo], serialiseCollectorRedeemer("Collect")).pay.ToContract(
|
|
5549
5596
|
collectorUtxo.address,
|
|
5550
5597
|
{ kind: "inline", value: import_lucid22.Data.void() },
|
|
5551
|
-
(0, import_lucid22.addAssets)(collectorUtxo.assets, (0,
|
|
5598
|
+
(0, import_lucid22.addAssets)(collectorUtxo.assets, (0, import_cardano_offchain_common15.mkLovelacesOf)(fee))
|
|
5552
5599
|
).readFrom([collectorRefScriptUtxo]);
|
|
5553
5600
|
return collectorRefScriptUtxo;
|
|
5554
5601
|
}
|
|
5555
5602
|
|
|
5556
5603
|
// src/contracts/gov/transactions.ts
|
|
5557
5604
|
var import_lucid25 = require("@lucid-evolution/lucid");
|
|
5558
|
-
var
|
|
5605
|
+
var import_cardano_offchain_common17 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
5559
5606
|
var import_lucid26 = require("@lucid-evolution/lucid");
|
|
5560
5607
|
var import_function2 = require("fp-ts/lib/function");
|
|
5561
|
-
var
|
|
5608
|
+
var import_fp_ts17 = require("fp-ts");
|
|
5562
5609
|
var import_ts_pattern17 = require("ts-pattern");
|
|
5563
5610
|
|
|
5564
5611
|
// src/contracts/staking/types-new.ts
|
|
5565
5612
|
var import_evolution16 = require("@evolution-sdk/evolution");
|
|
5566
|
-
var
|
|
5613
|
+
var import_fp_ts15 = require("fp-ts");
|
|
5567
5614
|
var import_ts_pattern15 = require("ts-pattern");
|
|
5568
5615
|
var StakingPosLockedAmtSchema = import_evolution16.TSchema.Array(
|
|
5569
5616
|
import_evolution16.TSchema.Tuple([
|
|
@@ -5623,22 +5670,22 @@ function serialiseStakingRedeemer(r) {
|
|
|
5623
5670
|
}
|
|
5624
5671
|
function parseStakingRedeemer(datum) {
|
|
5625
5672
|
try {
|
|
5626
|
-
return
|
|
5673
|
+
return import_fp_ts15.option.some(
|
|
5627
5674
|
import_evolution16.Data.withSchema(
|
|
5628
5675
|
StakingRedeemerSchema,
|
|
5629
5676
|
DEFAULT_SCHEMA_OPTIONS
|
|
5630
5677
|
).fromCBORHex(datum)
|
|
5631
5678
|
);
|
|
5632
5679
|
} catch (_) {
|
|
5633
|
-
return
|
|
5680
|
+
return import_fp_ts15.option.none;
|
|
5634
5681
|
}
|
|
5635
5682
|
}
|
|
5636
5683
|
function parseStakingRedeemerOrThrow(datum) {
|
|
5637
|
-
return
|
|
5684
|
+
return import_fp_ts15.function.pipe(
|
|
5638
5685
|
parseStakingRedeemer(datum),
|
|
5639
|
-
|
|
5686
|
+
import_fp_ts15.option.match(() => {
|
|
5640
5687
|
throw new Error("Expected a StakingRedeemer datum.");
|
|
5641
|
-
},
|
|
5688
|
+
}, import_fp_ts15.function.identity)
|
|
5642
5689
|
);
|
|
5643
5690
|
}
|
|
5644
5691
|
function parseStakingPosition(datum) {
|
|
@@ -5647,17 +5694,17 @@ function parseStakingPosition(datum) {
|
|
|
5647
5694
|
import_evolution16.Data.withSchema(StakingDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
5648
5695
|
datum
|
|
5649
5696
|
)
|
|
5650
|
-
).with({ owner: import_ts_pattern15.P.any }, (res) =>
|
|
5697
|
+
).with({ owner: import_ts_pattern15.P.any }, (res) => import_fp_ts15.option.some(res)).otherwise(() => import_fp_ts15.option.none);
|
|
5651
5698
|
} catch (_) {
|
|
5652
|
-
return
|
|
5699
|
+
return import_fp_ts15.option.none;
|
|
5653
5700
|
}
|
|
5654
5701
|
}
|
|
5655
5702
|
function parseStakingPositionOrThrow(datum) {
|
|
5656
|
-
return
|
|
5703
|
+
return import_fp_ts15.function.pipe(
|
|
5657
5704
|
parseStakingPosition(datum),
|
|
5658
|
-
|
|
5705
|
+
import_fp_ts15.option.match(() => {
|
|
5659
5706
|
throw new Error("Expected a StakingPosition datum.");
|
|
5660
|
-
},
|
|
5707
|
+
}, import_fp_ts15.function.identity)
|
|
5661
5708
|
);
|
|
5662
5709
|
}
|
|
5663
5710
|
function parseStakingManagerDatum(datum) {
|
|
@@ -5828,8 +5875,8 @@ function serialiseVersionRecordDatum(d) {
|
|
|
5828
5875
|
|
|
5829
5876
|
// src/contracts/poll/types-poll-new.ts
|
|
5830
5877
|
var import_evolution18 = require("@evolution-sdk/evolution");
|
|
5831
|
-
var
|
|
5832
|
-
var
|
|
5878
|
+
var import_cardano_offchain_common16 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
5879
|
+
var import_fp_ts16 = require("fp-ts");
|
|
5833
5880
|
var import_ts_pattern16 = require("ts-pattern");
|
|
5834
5881
|
var PollStatusSchema = import_evolution18.TSchema.Struct({
|
|
5835
5882
|
yesVotes: import_evolution18.TSchema.Integer,
|
|
@@ -5854,7 +5901,7 @@ var PollShardContentSchema = import_evolution18.TSchema.Struct({
|
|
|
5854
5901
|
pollId: import_evolution18.TSchema.Integer,
|
|
5855
5902
|
status: PollStatusSchema,
|
|
5856
5903
|
votingEndTime: import_evolution18.TSchema.Integer,
|
|
5857
|
-
managerAddress:
|
|
5904
|
+
managerAddress: import_cardano_offchain_common16.AddressSchema
|
|
5858
5905
|
});
|
|
5859
5906
|
var PollDatumSchema = import_evolution18.TSchema.Union(
|
|
5860
5907
|
import_evolution18.TSchema.Struct(
|
|
@@ -5876,7 +5923,7 @@ var PollShardRedeemerSchema = import_evolution18.TSchema.Union(
|
|
|
5876
5923
|
MergeShards: import_evolution18.TSchema.Struct(
|
|
5877
5924
|
{
|
|
5878
5925
|
currentTime: import_evolution18.TSchema.Integer,
|
|
5879
|
-
pollManagerRef:
|
|
5926
|
+
pollManagerRef: import_cardano_offchain_common16.OutputReferenceSchema
|
|
5880
5927
|
},
|
|
5881
5928
|
{ flatFields: true }
|
|
5882
5929
|
)
|
|
@@ -5921,22 +5968,22 @@ function serialisePollShardRedeemer(r) {
|
|
|
5921
5968
|
}
|
|
5922
5969
|
function parsePollShardRedeemer(datum) {
|
|
5923
5970
|
try {
|
|
5924
|
-
return
|
|
5971
|
+
return import_fp_ts16.option.some(
|
|
5925
5972
|
import_evolution18.Data.withSchema(
|
|
5926
5973
|
PollShardRedeemerSchema,
|
|
5927
5974
|
DEFAULT_SCHEMA_OPTIONS
|
|
5928
5975
|
).fromCBORHex(datum)
|
|
5929
5976
|
);
|
|
5930
5977
|
} catch (_) {
|
|
5931
|
-
return
|
|
5978
|
+
return import_fp_ts16.option.none;
|
|
5932
5979
|
}
|
|
5933
5980
|
}
|
|
5934
5981
|
function parsePollShardRedeemerOrThrow(datum) {
|
|
5935
|
-
return
|
|
5982
|
+
return import_fp_ts16.function.pipe(
|
|
5936
5983
|
parsePollShardRedeemer(datum),
|
|
5937
|
-
|
|
5984
|
+
import_fp_ts16.option.match(() => {
|
|
5938
5985
|
throw new Error("Expected a poll shard redeemer.");
|
|
5939
|
-
},
|
|
5986
|
+
}, import_fp_ts16.function.identity)
|
|
5940
5987
|
);
|
|
5941
5988
|
}
|
|
5942
5989
|
function parsePollManager(datum) {
|
|
@@ -5945,17 +5992,17 @@ function parsePollManager(datum) {
|
|
|
5945
5992
|
import_evolution18.Data.withSchema(PollDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
5946
5993
|
datum
|
|
5947
5994
|
)
|
|
5948
|
-
).with({ PollManager: import_ts_pattern16.P.select() }, (res) =>
|
|
5995
|
+
).with({ PollManager: import_ts_pattern16.P.select() }, (res) => import_fp_ts16.option.some(res)).otherwise(() => import_fp_ts16.option.none);
|
|
5949
5996
|
} catch (_) {
|
|
5950
|
-
return
|
|
5997
|
+
return import_fp_ts16.option.none;
|
|
5951
5998
|
}
|
|
5952
5999
|
}
|
|
5953
6000
|
function parsePollManagerOrThrow(datum) {
|
|
5954
|
-
return
|
|
6001
|
+
return import_fp_ts16.function.pipe(
|
|
5955
6002
|
parsePollManager(datum),
|
|
5956
|
-
|
|
6003
|
+
import_fp_ts16.option.match(() => {
|
|
5957
6004
|
throw new Error("Expected a poll manager datum.");
|
|
5958
|
-
},
|
|
6005
|
+
}, import_fp_ts16.function.identity)
|
|
5959
6006
|
);
|
|
5960
6007
|
}
|
|
5961
6008
|
function parsePollShard(datum) {
|
|
@@ -5964,17 +6011,17 @@ function parsePollShard(datum) {
|
|
|
5964
6011
|
import_evolution18.Data.withSchema(PollDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
5965
6012
|
datum
|
|
5966
6013
|
)
|
|
5967
|
-
).with({ PollShard: import_ts_pattern16.P.select() }, (res) =>
|
|
6014
|
+
).with({ PollShard: import_ts_pattern16.P.select() }, (res) => import_fp_ts16.option.some(res)).otherwise(() => import_fp_ts16.option.none);
|
|
5968
6015
|
} catch (_) {
|
|
5969
|
-
return
|
|
6016
|
+
return import_fp_ts16.option.none;
|
|
5970
6017
|
}
|
|
5971
6018
|
}
|
|
5972
6019
|
function parsePollShardOrThrow(datum) {
|
|
5973
|
-
return
|
|
6020
|
+
return import_fp_ts16.function.pipe(
|
|
5974
6021
|
parsePollShard(datum),
|
|
5975
|
-
|
|
6022
|
+
import_fp_ts16.option.match(() => {
|
|
5976
6023
|
throw new Error("Expected a poll shard datum.");
|
|
5977
|
-
},
|
|
6024
|
+
}, import_fp_ts16.function.identity)
|
|
5978
6025
|
);
|
|
5979
6026
|
}
|
|
5980
6027
|
function serialisePollDatum(d) {
|
|
@@ -5982,7 +6029,7 @@ function serialisePollDatum(d) {
|
|
|
5982
6029
|
}
|
|
5983
6030
|
|
|
5984
6031
|
// src/contracts/gov/transactions.ts
|
|
5985
|
-
var
|
|
6032
|
+
var import_cardano_offchain_common18 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
5986
6033
|
async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lucid, currentSlot, govOref, allIAssetOrefs) {
|
|
5987
6034
|
const network = lucid.config().network;
|
|
5988
6035
|
const currentTime = BigInt((0, import_lucid25.slotToUnixTime)(network, currentSlot));
|
|
@@ -6012,7 +6059,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
6012
6059
|
const votingEndTime = currentTime + govDatum.protocolParams.votingPeriod;
|
|
6013
6060
|
const expirationTime = votingEndTime + govDatum.protocolParams.expirationPeriod;
|
|
6014
6061
|
const proposingEndTime = currentTime + govDatum.protocolParams.proposingPeriod;
|
|
6015
|
-
const pollNftValue = (0,
|
|
6062
|
+
const pollNftValue = (0, import_cardano_offchain_common17.mkAssetsOf)(
|
|
6016
6063
|
fromSystemParamsAsset(sysParams.govParams.pollToken),
|
|
6017
6064
|
1n
|
|
6018
6065
|
);
|
|
@@ -6029,7 +6076,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
6029
6076
|
);
|
|
6030
6077
|
(0, import_function2.pipe)(
|
|
6031
6078
|
relativeIAsset,
|
|
6032
|
-
|
|
6079
|
+
import_fp_ts17.option.match(
|
|
6033
6080
|
() => {
|
|
6034
6081
|
if (govDatum.iassetsCount !== 0n) {
|
|
6035
6082
|
throw new Error(
|
|
@@ -6090,7 +6137,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
6090
6137
|
},
|
|
6091
6138
|
(0, import_lucid25.addAssets)(
|
|
6092
6139
|
pollNftValue,
|
|
6093
|
-
(0,
|
|
6140
|
+
(0, import_cardano_offchain_common17.mkAssetsOf)(
|
|
6094
6141
|
fromSystemParamsAsset(sysParams.govParams.indyAsset),
|
|
6095
6142
|
proposalDeposit(
|
|
6096
6143
|
govDatum.protocolParams.proposalDeposit,
|
|
@@ -6143,7 +6190,7 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
|
|
|
6143
6190
|
const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
|
|
6144
6191
|
const tx = lucid.newTx().validFrom(Number(currentTime) - ONE_SECOND).validTo(
|
|
6145
6192
|
Number(currentTime) + Number(sysParams.pollManagerParams.pBiasTime) - ONE_SECOND
|
|
6146
|
-
).mintAssets((0,
|
|
6193
|
+
).mintAssets((0, import_cardano_offchain_common17.mkAssetsOf)(pollNft, shardsCount), import_lucid26.Data.void()).readFrom([pollAuthTokenPolicyRefScriptUtxo, pollManagerRefScriptUtxo]).collectFrom(
|
|
6147
6194
|
[pollManagerUtxo],
|
|
6148
6195
|
serialisePollManagerRedeemer({ CreateShards: { currentTime } })
|
|
6149
6196
|
).pay.ToContract(
|
|
@@ -6169,11 +6216,11 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
|
|
|
6169
6216
|
pollId: pollManager.pollId,
|
|
6170
6217
|
status: { yesVotes: 0n, noVotes: 0n },
|
|
6171
6218
|
votingEndTime: pollManager.votingEndTime,
|
|
6172
|
-
managerAddress: (0,
|
|
6219
|
+
managerAddress: (0, import_cardano_offchain_common18.addressFromBech32)(pollManagerUtxo.address)
|
|
6173
6220
|
}
|
|
6174
6221
|
})
|
|
6175
6222
|
},
|
|
6176
|
-
(0,
|
|
6223
|
+
(0, import_cardano_offchain_common17.mkAssetsOf)(pollNft, 1n)
|
|
6177
6224
|
);
|
|
6178
6225
|
}
|
|
6179
6226
|
return tx;
|
|
@@ -6227,7 +6274,7 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
|
|
|
6227
6274
|
const stakingPosDatum = parseStakingPositionOrThrow(
|
|
6228
6275
|
getInlineDatumOrThrow(stakingPosUtxo)
|
|
6229
6276
|
);
|
|
6230
|
-
const indyStakedAmt = (0,
|
|
6277
|
+
const indyStakedAmt = (0, import_cardano_offchain_common17.assetClassValueOf)(
|
|
6231
6278
|
stakingPosUtxo.assets,
|
|
6232
6279
|
fromSystemParamsAsset(sysParams.govParams.indyAsset)
|
|
6233
6280
|
);
|
|
@@ -6305,10 +6352,10 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
6305
6352
|
getInlineDatumOrThrow(pollManagerUtxo)
|
|
6306
6353
|
);
|
|
6307
6354
|
const shardUtxos = await lucid.utxosByOutRef(shardsOutRefs);
|
|
6308
|
-
const aggregatedStatus =
|
|
6355
|
+
const aggregatedStatus = import_fp_ts17.function.pipe(
|
|
6309
6356
|
shardUtxos,
|
|
6310
|
-
|
|
6311
|
-
|
|
6357
|
+
import_fp_ts17.array.map((utxo) => parsePollShardOrThrow(getInlineDatumOrThrow(utxo))),
|
|
6358
|
+
import_fp_ts17.array.reduce(
|
|
6312
6359
|
pollManagerDatum.status,
|
|
6313
6360
|
(acc, shard) => ({
|
|
6314
6361
|
yesVotes: acc.yesVotes + shard.status.yesVotes,
|
|
@@ -6316,9 +6363,9 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
6316
6363
|
})
|
|
6317
6364
|
)
|
|
6318
6365
|
);
|
|
6319
|
-
const shardsAggregatedAda =
|
|
6366
|
+
const shardsAggregatedAda = import_fp_ts17.array.reduce(
|
|
6320
6367
|
{},
|
|
6321
|
-
(acc, utxo) => (0, import_lucid25.addAssets)(acc, (0,
|
|
6368
|
+
(acc, utxo) => (0, import_lucid25.addAssets)(acc, (0, import_cardano_offchain_common17.mkLovelacesOf)((0, import_cardano_offchain_common17.lovelacesAmt)(utxo.assets)))
|
|
6322
6369
|
)(shardUtxos);
|
|
6323
6370
|
const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
|
|
6324
6371
|
return lucid.newTx().validFrom(Number(currentTime) - ONE_SECOND).validTo(
|
|
@@ -6327,7 +6374,7 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
6327
6374
|
pollShardRefScriptUtxo,
|
|
6328
6375
|
pollManagerRefScriptUtxo,
|
|
6329
6376
|
pollAuthTokenPolicyRefScriptUtxo
|
|
6330
|
-
]).mintAssets((0,
|
|
6377
|
+
]).mintAssets((0, import_cardano_offchain_common17.mkAssetsOf)(pollNft, -BigInt(shardsOutRefs.length)), import_lucid26.Data.void()).collectFrom(
|
|
6331
6378
|
[pollManagerUtxo],
|
|
6332
6379
|
serialisePollManagerRedeemer({
|
|
6333
6380
|
MergeShardsManager: { currentTime }
|
|
@@ -6416,7 +6463,7 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
|
|
|
6416
6463
|
govDatum.protocolParams.electorate,
|
|
6417
6464
|
pollManager.minimumQuorum
|
|
6418
6465
|
);
|
|
6419
|
-
const upgradeTokenVal = (0,
|
|
6466
|
+
const upgradeTokenVal = (0, import_cardano_offchain_common17.mkAssetsOf)(
|
|
6420
6467
|
fromSystemParamsAsset(sysParams.govParams.upgradeToken),
|
|
6421
6468
|
1n
|
|
6422
6469
|
);
|
|
@@ -6433,7 +6480,7 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
|
|
|
6433
6480
|
).collectFrom(
|
|
6434
6481
|
[govUtxo],
|
|
6435
6482
|
serialiseGovRedeemer({ WitnessEndPoll: { currentTime } })
|
|
6436
|
-
).mintAssets((0,
|
|
6483
|
+
).mintAssets((0, import_cardano_offchain_common17.mkAssetsOf)(pollNft, -1n), import_lucid26.Data.void()).pay.ToContract(
|
|
6437
6484
|
govUtxo.address,
|
|
6438
6485
|
{
|
|
6439
6486
|
kind: "inline",
|
|
@@ -6464,9 +6511,9 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
|
|
|
6464
6511
|
tx.pay.ToContract(
|
|
6465
6512
|
createScriptAddress(network, sysParams.validatorHashes.treasuryHash),
|
|
6466
6513
|
{ kind: "inline", value: import_lucid26.Data.void() },
|
|
6467
|
-
(0,
|
|
6514
|
+
(0, import_cardano_offchain_common17.mkAssetsOf)(
|
|
6468
6515
|
indyAsset,
|
|
6469
|
-
(0,
|
|
6516
|
+
(0, import_cardano_offchain_common17.assetClassValueOf)(pollManagerUtxo.assets, indyAsset)
|
|
6470
6517
|
)
|
|
6471
6518
|
);
|
|
6472
6519
|
}
|
|
@@ -6512,8 +6559,8 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6512
6559
|
);
|
|
6513
6560
|
const tx = lucid.newTx();
|
|
6514
6561
|
await (0, import_function2.pipe)(
|
|
6515
|
-
|
|
6516
|
-
|
|
6562
|
+
import_fp_ts17.option.fromNullable(executeDatum.treasuryWithdrawal),
|
|
6563
|
+
import_fp_ts17.option.match(
|
|
6517
6564
|
() => {
|
|
6518
6565
|
if (treasuryWithdrawalOref) {
|
|
6519
6566
|
throw new Error("Cannot provide withdrawal oref when no withdrawal.");
|
|
@@ -6539,9 +6586,9 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6539
6586
|
const withdrawalVal = createValueFromWithdrawal(withdrawal);
|
|
6540
6587
|
const withdrawalChangeVal = (0, import_lucid25.addAssets)(
|
|
6541
6588
|
treasuryWithdrawalUtxo.assets,
|
|
6542
|
-
(0,
|
|
6589
|
+
(0, import_cardano_offchain_common17.negateAssets)(withdrawalVal)
|
|
6543
6590
|
);
|
|
6544
|
-
if (!(0,
|
|
6591
|
+
if (!(0, import_cardano_offchain_common17.isAssetsZero)(withdrawalChangeVal)) {
|
|
6545
6592
|
tx.pay.ToContract(
|
|
6546
6593
|
createScriptAddress(
|
|
6547
6594
|
network,
|
|
@@ -6558,7 +6605,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6558
6605
|
[treasuryWithdrawalUtxo],
|
|
6559
6606
|
serialiseTreasuryRedeemer("Withdraw")
|
|
6560
6607
|
).pay.ToAddressWithData(
|
|
6561
|
-
(0,
|
|
6608
|
+
(0, import_cardano_offchain_common18.addressToBech32)(withdrawal.destination, lucid.config().network),
|
|
6562
6609
|
{
|
|
6563
6610
|
kind: "inline",
|
|
6564
6611
|
value: serialiseWithdrawalOutputDatum([
|
|
@@ -6611,16 +6658,16 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6611
6658
|
);
|
|
6612
6659
|
const { newIAsset, newReferencedIAsset } = iassetCreationDatumHelper(
|
|
6613
6660
|
proposeContent,
|
|
6614
|
-
|
|
6661
|
+
import_fp_ts17.function.pipe(
|
|
6615
6662
|
iassetToReference,
|
|
6616
|
-
|
|
6663
|
+
import_fp_ts17.option.map((i) => i.datum)
|
|
6617
6664
|
)
|
|
6618
6665
|
);
|
|
6619
|
-
const iassetAuthVal = (0,
|
|
6666
|
+
const iassetAuthVal = (0, import_cardano_offchain_common17.mkAssetsOf)(
|
|
6620
6667
|
fromSystemParamsAsset(sysParams.executeParams.iAssetToken),
|
|
6621
6668
|
1n
|
|
6622
6669
|
);
|
|
6623
|
-
const spAuthVal = (0,
|
|
6670
|
+
const spAuthVal = (0, import_cardano_offchain_common17.mkAssetsOf)(
|
|
6624
6671
|
fromSystemParamsAsset(sysParams.executeParams.stabilityPoolToken),
|
|
6625
6672
|
1n
|
|
6626
6673
|
);
|
|
@@ -6666,14 +6713,14 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6666
6713
|
},
|
|
6667
6714
|
spAuthVal
|
|
6668
6715
|
);
|
|
6669
|
-
|
|
6716
|
+
import_fp_ts17.function.pipe(
|
|
6670
6717
|
iassetToReference,
|
|
6671
|
-
|
|
6718
|
+
import_fp_ts17.option.match(
|
|
6672
6719
|
() => {
|
|
6673
6720
|
},
|
|
6674
|
-
(i) =>
|
|
6721
|
+
(i) => import_fp_ts17.function.pipe(
|
|
6675
6722
|
newReferencedIAsset,
|
|
6676
|
-
|
|
6723
|
+
import_fp_ts17.option.match(
|
|
6677
6724
|
() => {
|
|
6678
6725
|
throw new Error("Expected some referenced iasset.");
|
|
6679
6726
|
},
|
|
@@ -6791,12 +6838,12 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6791
6838
|
);
|
|
6792
6839
|
const { newCollateralAsset, newReferencedCollateralAsset } = collateralAssetCreationDatumHelper(
|
|
6793
6840
|
addCollateralContent,
|
|
6794
|
-
|
|
6841
|
+
import_fp_ts17.function.pipe(
|
|
6795
6842
|
collateralAssetToReference,
|
|
6796
|
-
|
|
6843
|
+
import_fp_ts17.option.map((i) => i.datum)
|
|
6797
6844
|
)
|
|
6798
6845
|
);
|
|
6799
|
-
const collateralAssetAuthVal = (0,
|
|
6846
|
+
const collateralAssetAuthVal = (0, import_cardano_offchain_common17.mkAssetsOf)(
|
|
6800
6847
|
fromSystemParamsAsset(sysParams.executeParams.collateralAssetToken),
|
|
6801
6848
|
1n
|
|
6802
6849
|
);
|
|
@@ -6838,15 +6885,15 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6838
6885
|
},
|
|
6839
6886
|
collateralAssetAuthVal
|
|
6840
6887
|
);
|
|
6841
|
-
|
|
6888
|
+
import_fp_ts17.function.pipe(
|
|
6842
6889
|
collateralAssetToReference,
|
|
6843
|
-
|
|
6890
|
+
import_fp_ts17.option.match(
|
|
6844
6891
|
() => {
|
|
6845
6892
|
},
|
|
6846
6893
|
(i) => {
|
|
6847
|
-
|
|
6894
|
+
import_fp_ts17.function.pipe(
|
|
6848
6895
|
newReferencedCollateralAsset,
|
|
6849
|
-
|
|
6896
|
+
import_fp_ts17.option.match(
|
|
6850
6897
|
() => {
|
|
6851
6898
|
throw new Error("Expected some referenced collateral asset");
|
|
6852
6899
|
},
|
|
@@ -6878,15 +6925,15 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6878
6925
|
}
|
|
6879
6926
|
)
|
|
6880
6927
|
);
|
|
6881
|
-
if (!(0,
|
|
6882
|
-
|
|
6928
|
+
if (!(0, import_cardano_offchain_common17.isSameAssetClass)(newCollateralAsset.collateralAsset, import_cardano_offchain_common17.adaAssetClass)) {
|
|
6929
|
+
import_fp_ts17.function.pipe(
|
|
6883
6930
|
newReferencedCollateralAsset,
|
|
6884
|
-
|
|
6931
|
+
import_fp_ts17.option.match(
|
|
6885
6932
|
() => {
|
|
6886
6933
|
},
|
|
6887
|
-
(referencedAsset) => referencedAsset.firstCollateralAsset ? {} :
|
|
6934
|
+
(referencedAsset) => referencedAsset.firstCollateralAsset ? {} : import_fp_ts17.function.pipe(
|
|
6888
6935
|
firstCollateralAsset,
|
|
6889
|
-
|
|
6936
|
+
import_fp_ts17.option.match(
|
|
6890
6937
|
() => {
|
|
6891
6938
|
},
|
|
6892
6939
|
(firstAsset) => {
|
|
@@ -6920,7 +6967,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6920
6967
|
const collateralAssetDatum = parseCollateralAssetDatumOrThrow(
|
|
6921
6968
|
getInlineDatumOrThrow(collateralAssetUtxo)
|
|
6922
6969
|
);
|
|
6923
|
-
if (!(0,
|
|
6970
|
+
if (!(0, import_cardano_offchain_common17.isSameAssetClass)(
|
|
6924
6971
|
collateralAssetDatum.collateralAsset,
|
|
6925
6972
|
updateCollateralContent.collateralAsset
|
|
6926
6973
|
) || (0, import_lucid25.toHex)(collateralAssetDatum.iasset) !== (0, import_lucid25.toHex)(updateCollateralContent.correspondingIAsset)) {
|
|
@@ -6981,7 +7028,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6981
7028
|
await lucid.utxosByOutRef([iAssetOref]),
|
|
6982
7029
|
(_) => new Error("Expected a single iasset UTXO")
|
|
6983
7030
|
);
|
|
6984
|
-
const cdpAuthVal = (0,
|
|
7031
|
+
const cdpAuthVal = (0, import_cardano_offchain_common17.mkAssetsOf)(
|
|
6985
7032
|
fromSystemParamsAsset(sysParams.executeParams.cdpToken),
|
|
6986
7033
|
1n
|
|
6987
7034
|
);
|
|
@@ -7099,7 +7146,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
7099
7146
|
"Expected a single version record token policy ref Script UTXO"
|
|
7100
7147
|
)
|
|
7101
7148
|
);
|
|
7102
|
-
const versionRecordNftVal = (0,
|
|
7149
|
+
const versionRecordNftVal = (0, import_cardano_offchain_common17.mkAssetsOf)(
|
|
7103
7150
|
fromSystemParamsAsset(sysParams.executeParams.versionRecordToken),
|
|
7104
7151
|
1n
|
|
7105
7152
|
);
|
|
@@ -7135,7 +7182,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
7135
7182
|
tx.readFrom([upgradeTokenPolicyRefScriptUtxo, executeRefScriptUtxo]).validFrom(Number(currentTime) - ONE_SECOND).validTo(
|
|
7136
7183
|
Number(currentTime) + Number(sysParams.govParams.gBiasTime) - ONE_SECOND
|
|
7137
7184
|
).collectFrom([executeUtxo], import_lucid26.Data.void()).mintAssets(
|
|
7138
|
-
(0,
|
|
7185
|
+
(0, import_cardano_offchain_common17.mkAssetsOf)(fromSystemParamsAsset(sysParams.govParams.upgradeToken), -1n),
|
|
7139
7186
|
import_lucid26.Data.void()
|
|
7140
7187
|
).addSigner(ownAddr).setMinFee(922932n);
|
|
7141
7188
|
return tx;
|
|
@@ -7205,7 +7252,7 @@ var mkGovValidatorFromSP = (params) => {
|
|
|
7205
7252
|
|
|
7206
7253
|
// src/contracts/stability-pool/transactions.ts
|
|
7207
7254
|
var import_lucid29 = require("@lucid-evolution/lucid");
|
|
7208
|
-
var
|
|
7255
|
+
var import_cardano_offchain_common19 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
7209
7256
|
var import_ts_pattern18 = require("ts-pattern");
|
|
7210
7257
|
async function requestSpAccountCreation(assetAscii, amount, sysParams, lucid) {
|
|
7211
7258
|
const [pkh, _skh] = await addrDetails(lucid);
|
|
@@ -7240,8 +7287,8 @@ async function requestSpAccountCreation(assetAscii, amount, sysParams, lucid) {
|
|
|
7240
7287
|
value: serialiseStabilityPoolDatum({ Account: datum })
|
|
7241
7288
|
},
|
|
7242
7289
|
(0, import_lucid29.addAssets)(
|
|
7243
|
-
(0,
|
|
7244
|
-
(0,
|
|
7290
|
+
(0, import_cardano_offchain_common19.mkAssetsOf)(iassetAssetClass, amount),
|
|
7291
|
+
(0, import_cardano_offchain_common19.mkLovelacesOf)(
|
|
7245
7292
|
// TODO: Calculate a more accurate amount to just cover costs.
|
|
7246
7293
|
// This should cover the account creation fee,
|
|
7247
7294
|
// the minimum ADA for the account UTxO and the transaction fee.
|
|
@@ -7252,7 +7299,7 @@ async function requestSpAccountCreation(assetAscii, amount, sysParams, lucid) {
|
|
|
7252
7299
|
}
|
|
7253
7300
|
async function requestSpAccountAdjustment(amount, accountUtxo, sysParams, lucid) {
|
|
7254
7301
|
const myAddress = await lucid.wallet().address();
|
|
7255
|
-
const stabilityPoolScriptRef = (0,
|
|
7302
|
+
const stabilityPoolScriptRef = (0, import_cardano_offchain_common19.matchSingle)(
|
|
7256
7303
|
await lucid.utxosByOutRef([
|
|
7257
7304
|
fromSystemParamsScriptRef(
|
|
7258
7305
|
sysParams.scriptReferences.stabilityPoolValidatorRef
|
|
@@ -7268,7 +7315,7 @@ async function requestSpAccountAdjustment(amount, accountUtxo, sysParams, lucid)
|
|
|
7268
7315
|
request: {
|
|
7269
7316
|
Adjust: {
|
|
7270
7317
|
amount,
|
|
7271
|
-
outputAddress: (0,
|
|
7318
|
+
outputAddress: (0, import_cardano_offchain_common19.addressFromBech32)(myAddress)
|
|
7272
7319
|
}
|
|
7273
7320
|
}
|
|
7274
7321
|
};
|
|
@@ -7278,7 +7325,7 @@ async function requestSpAccountAdjustment(amount, accountUtxo, sysParams, lucid)
|
|
|
7278
7325
|
RequestAction: {
|
|
7279
7326
|
Adjust: {
|
|
7280
7327
|
amount,
|
|
7281
|
-
outputAddress: (0,
|
|
7328
|
+
outputAddress: (0, import_cardano_offchain_common19.addressFromBech32)(myAddress)
|
|
7282
7329
|
}
|
|
7283
7330
|
}
|
|
7284
7331
|
})
|
|
@@ -7291,17 +7338,17 @@ async function requestSpAccountAdjustment(amount, accountUtxo, sysParams, lucid)
|
|
|
7291
7338
|
})
|
|
7292
7339
|
},
|
|
7293
7340
|
(0, import_lucid29.addAssets)(
|
|
7294
|
-
(0,
|
|
7341
|
+
(0, import_cardano_offchain_common19.mkLovelacesOf)(
|
|
7295
7342
|
// TODO: Calculate a more accurate amount to just cover costs.
|
|
7296
7343
|
// This should cover the minimum ADA for 2 UTxOs (account and
|
|
7297
7344
|
// rewards withdrawal) and the transaction fee.
|
|
7298
7345
|
5000000n
|
|
7299
7346
|
),
|
|
7300
|
-
(0,
|
|
7347
|
+
(0, import_cardano_offchain_common19.mkAssetsOf)(
|
|
7301
7348
|
fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
|
|
7302
7349
|
1n
|
|
7303
7350
|
),
|
|
7304
|
-
amount > 0n ? (0,
|
|
7351
|
+
amount > 0n ? (0, import_cardano_offchain_common19.mkAssetsOf)(
|
|
7305
7352
|
{
|
|
7306
7353
|
currencySymbol: (0, import_lucid29.fromHex)(
|
|
7307
7354
|
sysParams.stabilityPoolParams.assetSymbol.unCurrencySymbol
|
|
@@ -7315,7 +7362,7 @@ async function requestSpAccountAdjustment(amount, accountUtxo, sysParams, lucid)
|
|
|
7315
7362
|
}
|
|
7316
7363
|
async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee = BASE_MAX_TX_FEE) {
|
|
7317
7364
|
const myAddress = await lucid.wallet().address();
|
|
7318
|
-
const stabilityPoolScriptRef = (0,
|
|
7365
|
+
const stabilityPoolScriptRef = (0, import_cardano_offchain_common19.matchSingle)(
|
|
7319
7366
|
await lucid.utxosByOutRef([
|
|
7320
7367
|
fromSystemParamsScriptRef(
|
|
7321
7368
|
sysParams.scriptReferences.stabilityPoolValidatorRef
|
|
@@ -7325,7 +7372,7 @@ async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee =
|
|
|
7325
7372
|
);
|
|
7326
7373
|
const request = {
|
|
7327
7374
|
Close: {
|
|
7328
|
-
outputAddress: (0,
|
|
7375
|
+
outputAddress: (0, import_cardano_offchain_common19.addressFromBech32)(myAddress),
|
|
7329
7376
|
maxTxFee
|
|
7330
7377
|
}
|
|
7331
7378
|
};
|
|
@@ -7346,12 +7393,12 @@ async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee =
|
|
|
7346
7393
|
value: serialiseStabilityPoolDatum({ Account: newAccountDatum })
|
|
7347
7394
|
},
|
|
7348
7395
|
(0, import_lucid29.addAssets)(
|
|
7349
|
-
(0,
|
|
7396
|
+
(0, import_cardano_offchain_common19.mkLovelacesOf)(
|
|
7350
7397
|
// TODO: Calculate a more accurate amount to just cover costs.
|
|
7351
7398
|
// This should cover the minimum ADA for the rewards UTxO and the transaction fee.
|
|
7352
7399
|
3000000n
|
|
7353
7400
|
),
|
|
7354
|
-
(0,
|
|
7401
|
+
(0, import_cardano_offchain_common19.mkAssetsOf)(
|
|
7355
7402
|
fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
|
|
7356
7403
|
1n
|
|
7357
7404
|
)
|
|
@@ -7361,7 +7408,7 @@ async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee =
|
|
|
7361
7408
|
async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, currentSlot, txFee) {
|
|
7362
7409
|
const network = lucid.config().network;
|
|
7363
7410
|
const currentTime = BigInt((0, import_lucid29.slotToUnixTime)(network, currentSlot));
|
|
7364
|
-
const stabilityPoolScriptRef = (0,
|
|
7411
|
+
const stabilityPoolScriptRef = (0, import_cardano_offchain_common19.matchSingle)(
|
|
7365
7412
|
await lucid.utxosByOutRef([
|
|
7366
7413
|
fromSystemParamsScriptRef(
|
|
7367
7414
|
sysParams.scriptReferences.stabilityPoolValidatorRef
|
|
@@ -7395,7 +7442,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7395
7442
|
tokenName: stabilityPoolDatum.iasset
|
|
7396
7443
|
};
|
|
7397
7444
|
await (0, import_ts_pattern18.match)(accountDatum.request).with("Create", async (_) => {
|
|
7398
|
-
const accountTokenScriptRef = (0,
|
|
7445
|
+
const accountTokenScriptRef = (0, import_cardano_offchain_common19.matchSingle)(
|
|
7399
7446
|
await lucid.utxosByOutRef([
|
|
7400
7447
|
fromSystemParamsScriptRef(
|
|
7401
7448
|
sysParams.scriptReferences.authTokenPolicies.accountTokenRef
|
|
@@ -7403,7 +7450,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7403
7450
|
]),
|
|
7404
7451
|
(_2) => new Error("Expected a single cdp auth token policy Ref Script UTXO")
|
|
7405
7452
|
);
|
|
7406
|
-
const requestDepositAmt = (0,
|
|
7453
|
+
const requestDepositAmt = (0, import_cardano_offchain_common19.assetClassValueOf)(
|
|
7407
7454
|
accountUtxo.assets,
|
|
7408
7455
|
iassetAssetClass
|
|
7409
7456
|
);
|
|
@@ -7417,8 +7464,8 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7417
7464
|
sysParams.stabilityPoolParams.stakeCredential
|
|
7418
7465
|
) : void 0
|
|
7419
7466
|
);
|
|
7420
|
-
const accountOutputAdaAmt = (0,
|
|
7421
|
-
const accountTokenVal = (0,
|
|
7467
|
+
const accountOutputAdaAmt = (0, import_cardano_offchain_common19.lovelacesAmt)(accountUtxo.assets) - BigInt(sysParams.stabilityPoolParams.accountCreateFeeLovelaces) - txFee;
|
|
7468
|
+
const accountTokenVal = (0, import_cardano_offchain_common19.mkAssetsOf)(
|
|
7422
7469
|
fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
|
|
7423
7470
|
1n
|
|
7424
7471
|
);
|
|
@@ -7438,7 +7485,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7438
7485
|
lastRequestProcessingTime: currentTime
|
|
7439
7486
|
}
|
|
7440
7487
|
});
|
|
7441
|
-
const accountOutMinUtxoLovelace = (0,
|
|
7488
|
+
const accountOutMinUtxoLovelace = (0, import_cardano_offchain_common19.estimateUtxoMinLovelace)(
|
|
7442
7489
|
lucid.config().protocolParameters,
|
|
7443
7490
|
poolAddr,
|
|
7444
7491
|
accountTokenVal,
|
|
@@ -7474,7 +7521,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7474
7521
|
)
|
|
7475
7522
|
}
|
|
7476
7523
|
},
|
|
7477
|
-
|
|
7524
|
+
import_cardano_offchain_common19.adaAssetClass,
|
|
7478
7525
|
0n,
|
|
7479
7526
|
BigInt(sysParams.stabilityPoolParams.accountCreateFeeLovelaces)
|
|
7480
7527
|
)
|
|
@@ -7482,8 +7529,8 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7482
7529
|
},
|
|
7483
7530
|
(0, import_lucid29.addAssets)(
|
|
7484
7531
|
stabilityPoolUtxo.assets,
|
|
7485
|
-
(0,
|
|
7486
|
-
(0,
|
|
7532
|
+
(0, import_cardano_offchain_common19.mkAssetsOf)(iassetAssetClass, requestDepositAmt),
|
|
7533
|
+
(0, import_cardano_offchain_common19.mkLovelacesOf)(
|
|
7487
7534
|
BigInt(sysParams.stabilityPoolParams.accountCreateFeeLovelaces)
|
|
7488
7535
|
)
|
|
7489
7536
|
)
|
|
@@ -7493,14 +7540,14 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7493
7540
|
kind: "inline",
|
|
7494
7541
|
value: accountOutputDatum
|
|
7495
7542
|
},
|
|
7496
|
-
(0, import_lucid29.addAssets)(accountTokenVal, (0,
|
|
7543
|
+
(0, import_lucid29.addAssets)(accountTokenVal, (0, import_cardano_offchain_common19.mkLovelacesOf)(accountOutputAdaAmt))
|
|
7497
7544
|
).setMinFee(txFee);
|
|
7498
7545
|
}).with({ Adjust: import_ts_pattern18.P.select() }, async (adjustContent) => {
|
|
7499
7546
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
7500
7547
|
getInlineDatumOrThrow(iAssetUtxo)
|
|
7501
7548
|
);
|
|
7502
7549
|
const accountDepositChange = adjustContent.amount;
|
|
7503
|
-
const outputAddress = (0,
|
|
7550
|
+
const outputAddress = (0, import_cardano_offchain_common19.addressToBech32)(
|
|
7504
7551
|
adjustContent.outputAddress,
|
|
7505
7552
|
lucid.config().network
|
|
7506
7553
|
);
|
|
@@ -7566,13 +7613,13 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7566
7613
|
},
|
|
7567
7614
|
(0, import_lucid29.addAssets)(
|
|
7568
7615
|
stabilityPoolUtxo.assets,
|
|
7569
|
-
(0,
|
|
7570
|
-
(0,
|
|
7616
|
+
(0, import_cardano_offchain_common19.negateAssets)(reward),
|
|
7617
|
+
(0, import_cardano_offchain_common19.mkAssetsOf)(iassetAssetClass, accountBalanceChange + withdrawalFeeAmt)
|
|
7571
7618
|
)
|
|
7572
7619
|
);
|
|
7573
7620
|
const theoreticalOwnerOutputVal = (0, import_lucid29.addAssets)(
|
|
7574
7621
|
reward,
|
|
7575
|
-
isDepositOrRewardWithdrawal ? {} : (0,
|
|
7622
|
+
isDepositOrRewardWithdrawal ? {} : (0, import_cardano_offchain_common19.mkAssetsOf)(
|
|
7576
7623
|
iassetAssetClass,
|
|
7577
7624
|
-accountBalanceChange - withdrawalFeeAmt
|
|
7578
7625
|
)
|
|
@@ -7583,16 +7630,16 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7583
7630
|
outputIndex: BigInt(accountUtxo.outputIndex)
|
|
7584
7631
|
}
|
|
7585
7632
|
});
|
|
7586
|
-
const ownerOutputMinUtxoLovelace = (0,
|
|
7633
|
+
const ownerOutputMinUtxoLovelace = (0, import_cardano_offchain_common19.estimateUtxoMinLovelace)(
|
|
7587
7634
|
lucid.config().protocolParameters,
|
|
7588
7635
|
outputAddress,
|
|
7589
7636
|
theoreticalOwnerOutputVal,
|
|
7590
7637
|
{ InlineDatum: { datum: ownerOutputDat } }
|
|
7591
7638
|
);
|
|
7592
|
-
const extraOwnerOutputLovelacesAmt = (0,
|
|
7639
|
+
const extraOwnerOutputLovelacesAmt = (0, import_cardano_offchain_common19.lovelacesAmt)(theoreticalOwnerOutputVal) >= ownerOutputMinUtxoLovelace ? 0n : ownerOutputMinUtxoLovelace - (0, import_cardano_offchain_common19.lovelacesAmt)(theoreticalOwnerOutputVal);
|
|
7593
7640
|
const actualOwnerOutputVal = (0, import_lucid29.addAssets)(
|
|
7594
7641
|
theoreticalOwnerOutputVal,
|
|
7595
|
-
(0,
|
|
7642
|
+
(0, import_cardano_offchain_common19.mkLovelacesOf)(extraOwnerOutputLovelacesAmt)
|
|
7596
7643
|
);
|
|
7597
7644
|
const accountOutputDat = serialiseStabilityPoolDatum({
|
|
7598
7645
|
Account: {
|
|
@@ -7608,17 +7655,17 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7608
7655
|
lastRequestProcessingTime: currentTime
|
|
7609
7656
|
}
|
|
7610
7657
|
});
|
|
7611
|
-
const accountOutputValWithoutAda = (0,
|
|
7658
|
+
const accountOutputValWithoutAda = (0, import_cardano_offchain_common19.mkAssetsOf)(
|
|
7612
7659
|
fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
|
|
7613
7660
|
1n
|
|
7614
7661
|
);
|
|
7615
|
-
const accountOutMinUtxoLovelace = (0,
|
|
7662
|
+
const accountOutMinUtxoLovelace = (0, import_cardano_offchain_common19.estimateUtxoMinLovelace)(
|
|
7616
7663
|
lucid.config().protocolParameters,
|
|
7617
7664
|
stabilityPoolUtxo.address,
|
|
7618
7665
|
accountOutputValWithoutAda,
|
|
7619
7666
|
{ InlineDatum: { datum: accountOutputDat } }
|
|
7620
7667
|
);
|
|
7621
|
-
const accountOutputAdaAmt = (0,
|
|
7668
|
+
const accountOutputAdaAmt = (0, import_cardano_offchain_common19.lovelacesAmt)(accountUtxo.assets) - extraOwnerOutputLovelacesAmt - txFee;
|
|
7622
7669
|
if (accountOutputAdaAmt < accountOutMinUtxoLovelace) {
|
|
7623
7670
|
throw new Error("Account doesn't have enough ADA to be processed.");
|
|
7624
7671
|
}
|
|
@@ -7630,7 +7677,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7630
7677
|
},
|
|
7631
7678
|
(0, import_lucid29.addAssets)(
|
|
7632
7679
|
accountOutputValWithoutAda,
|
|
7633
|
-
(0,
|
|
7680
|
+
(0, import_cardano_offchain_common19.mkLovelacesOf)(accountOutputAdaAmt)
|
|
7634
7681
|
)
|
|
7635
7682
|
).pay.ToAddressWithData(
|
|
7636
7683
|
outputAddress,
|
|
@@ -7644,7 +7691,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7644
7691
|
if (txFee > closeContent.maxTxFee) {
|
|
7645
7692
|
throw new Error("Account doesn't allow current transaction fee.");
|
|
7646
7693
|
}
|
|
7647
|
-
const accountTokenScriptRef = (0,
|
|
7694
|
+
const accountTokenScriptRef = (0, import_cardano_offchain_common19.matchSingle)(
|
|
7648
7695
|
await lucid.utxosByOutRef([
|
|
7649
7696
|
fromSystemParamsScriptRef(
|
|
7650
7697
|
sysParams.scriptReferences.authTokenPolicies.accountTokenRef
|
|
@@ -7655,7 +7702,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7655
7702
|
const iassetDatum = parseIAssetDatumOrThrow(
|
|
7656
7703
|
getInlineDatumOrThrow(iAssetUtxo)
|
|
7657
7704
|
);
|
|
7658
|
-
const outputAddress = (0,
|
|
7705
|
+
const outputAddress = (0, import_cardano_offchain_common19.addressToBech32)(
|
|
7659
7706
|
closeContent.outputAddress,
|
|
7660
7707
|
lucid.config().network
|
|
7661
7708
|
);
|
|
@@ -7707,7 +7754,7 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7707
7754
|
});
|
|
7708
7755
|
}
|
|
7709
7756
|
}).mintAssets(
|
|
7710
|
-
(0,
|
|
7757
|
+
(0, import_cardano_offchain_common19.mkAssetsOf)(
|
|
7711
7758
|
fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
|
|
7712
7759
|
-1n
|
|
7713
7760
|
),
|
|
@@ -7725,8 +7772,8 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7725
7772
|
},
|
|
7726
7773
|
(0, import_lucid29.addAssets)(
|
|
7727
7774
|
stabilityPoolUtxo.assets,
|
|
7728
|
-
(0,
|
|
7729
|
-
(0,
|
|
7775
|
+
(0, import_cardano_offchain_common19.negateAssets)(reward),
|
|
7776
|
+
(0, import_cardano_offchain_common19.mkAssetsOf)(iassetAssetClass, -withdrawnAmt + withdrawalFeeAmt)
|
|
7730
7777
|
)
|
|
7731
7778
|
).pay.ToAddressWithData(
|
|
7732
7779
|
outputAddress,
|
|
@@ -7740,9 +7787,9 @@ async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetU
|
|
|
7740
7787
|
})
|
|
7741
7788
|
},
|
|
7742
7789
|
(0, import_lucid29.addAssets)(
|
|
7743
|
-
(0,
|
|
7790
|
+
(0, import_cardano_offchain_common19.mkLovelacesOf)((0, import_cardano_offchain_common19.lovelacesAmt)(accountUtxo.assets) - txFee),
|
|
7744
7791
|
reward,
|
|
7745
|
-
(0,
|
|
7792
|
+
(0, import_cardano_offchain_common19.mkAssetsOf)(iassetAssetClass, withdrawnAmt - withdrawalFeeAmt)
|
|
7746
7793
|
)
|
|
7747
7794
|
).setMinFee(txFee);
|
|
7748
7795
|
}).exhaustive();
|
|
@@ -7773,7 +7820,7 @@ async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE
|
|
|
7773
7820
|
);
|
|
7774
7821
|
}
|
|
7775
7822
|
async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
|
|
7776
|
-
const stabilityPoolRefScriptUtxo = (0,
|
|
7823
|
+
const stabilityPoolRefScriptUtxo = (0, import_cardano_offchain_common19.matchSingle)(
|
|
7777
7824
|
await lucid.utxosByOutRef([
|
|
7778
7825
|
fromSystemParamsScriptRef(
|
|
7779
7826
|
sysParams.scriptReferences.stabilityPoolValidatorRef
|
|
@@ -7781,7 +7828,7 @@ async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
|
|
|
7781
7828
|
]),
|
|
7782
7829
|
(_) => new Error("Expected a single stability pool Ref Script UTXO")
|
|
7783
7830
|
);
|
|
7784
|
-
const snapshotE2s2sPolicyRefScriptUtxo = (0,
|
|
7831
|
+
const snapshotE2s2sPolicyRefScriptUtxo = (0, import_cardano_offchain_common19.matchSingle)(
|
|
7785
7832
|
await lucid.utxosByOutRef([
|
|
7786
7833
|
fromSystemParamsScriptRef(
|
|
7787
7834
|
sysParams.scriptReferences.authTokenPolicies.snapshotEpochToScaleToSumTokenRef
|
|
@@ -7789,7 +7836,7 @@ async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
|
|
|
7789
7836
|
]),
|
|
7790
7837
|
(_) => new Error("Expected a single snapshot e2s2s policy Ref Script UTXO")
|
|
7791
7838
|
);
|
|
7792
|
-
const spUtxo = (0,
|
|
7839
|
+
const spUtxo = (0, import_cardano_offchain_common19.matchSingle)(
|
|
7793
7840
|
await lucid.utxosByOutRef([stabilityPoolOref]),
|
|
7794
7841
|
(_) => new Error("Expected a single stability pool UTXO")
|
|
7795
7842
|
);
|
|
@@ -7805,7 +7852,7 @@ async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
|
|
|
7805
7852
|
[spUtxo],
|
|
7806
7853
|
serialiseStabilityPoolRedeemer("RecordEpochToScaleToSum")
|
|
7807
7854
|
).mintAssets(
|
|
7808
|
-
(0,
|
|
7855
|
+
(0, import_cardano_offchain_common19.mkAssetsOf)(snapshotAc, BigInt(newSnapshotDatums.length)),
|
|
7809
7856
|
import_lucid29.Data.void()
|
|
7810
7857
|
).pay.ToContract(
|
|
7811
7858
|
spUtxo.address,
|
|
@@ -7826,13 +7873,13 @@ async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
|
|
|
7826
7873
|
SnapshotEpochToScaleToSum: newDatum
|
|
7827
7874
|
})
|
|
7828
7875
|
},
|
|
7829
|
-
(0,
|
|
7876
|
+
(0, import_cardano_offchain_common19.mkAssetsOf)(snapshotAc, 1n)
|
|
7830
7877
|
);
|
|
7831
7878
|
}
|
|
7832
7879
|
return tx;
|
|
7833
7880
|
}
|
|
7834
7881
|
async function annulRequest(accountUtxo, params, lucid) {
|
|
7835
|
-
const stabilityPoolRefScriptUtxo = (0,
|
|
7882
|
+
const stabilityPoolRefScriptUtxo = (0, import_cardano_offchain_common19.matchSingle)(
|
|
7836
7883
|
await lucid.utxosByOutRef([
|
|
7837
7884
|
fromSystemParamsScriptRef(
|
|
7838
7885
|
params.scriptReferences.stabilityPoolValidatorRef
|
|
@@ -7856,7 +7903,7 @@ async function annulRequest(accountUtxo, params, lucid) {
|
|
|
7856
7903
|
}
|
|
7857
7904
|
})
|
|
7858
7905
|
},
|
|
7859
|
-
(0,
|
|
7906
|
+
(0, import_cardano_offchain_common19.mkAssetsOf)(
|
|
7860
7907
|
fromSystemParamsAsset(params.stabilityPoolParams.accountToken),
|
|
7861
7908
|
1n
|
|
7862
7909
|
)
|
|
@@ -7867,7 +7914,7 @@ async function annulRequest(accountUtxo, params, lucid) {
|
|
|
7867
7914
|
|
|
7868
7915
|
// src/contracts/staking/transactions.ts
|
|
7869
7916
|
var import_lucid30 = require("@lucid-evolution/lucid");
|
|
7870
|
-
var
|
|
7917
|
+
var import_cardano_offchain_common20 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
7871
7918
|
async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
7872
7919
|
const [pkh, _] = await addrDetails(lucid);
|
|
7873
7920
|
const stakingManagerOut = stakingManagerRef ? await findStakingManagerByOutRef(stakingManagerRef, lucid) : await findStakingManager(params, lucid);
|
|
@@ -7947,7 +7994,7 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
7947
7994
|
const adaReward = calculateAdaReward(
|
|
7948
7995
|
stakingManagerOut.datum.managerSnapshot.snapshotAda,
|
|
7949
7996
|
stakingPositionOut.datum.positionSnapshot.snapshotAda,
|
|
7950
|
-
(0,
|
|
7997
|
+
(0, import_cardano_offchain_common20.assetClassValueOf)(stakingPositionOut.utxo.assets, indyToken)
|
|
7951
7998
|
);
|
|
7952
7999
|
const newLockedAmount = updateStakingLockedAmount(
|
|
7953
8000
|
stakingPositionOut.datum.lockedAmount,
|
|
@@ -7970,7 +8017,7 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
7970
8017
|
totalStake: stakingManagerOut.datum.totalStake + amount
|
|
7971
8018
|
})
|
|
7972
8019
|
},
|
|
7973
|
-
(0, import_lucid30.addAssets)(stakingManagerOut.utxo.assets, (0,
|
|
8020
|
+
(0, import_lucid30.addAssets)(stakingManagerOut.utxo.assets, (0, import_cardano_offchain_common20.mkLovelacesOf)(-adaReward))
|
|
7974
8021
|
).pay.ToContract(
|
|
7975
8022
|
stakingPositionOut.utxo.address,
|
|
7976
8023
|
{
|
|
@@ -7983,7 +8030,7 @@ async function adjustStakingPosition(stakingPositionRef, amount, params, lucid,
|
|
|
7983
8030
|
lockedAmount: newLockedAmount
|
|
7984
8031
|
})
|
|
7985
8032
|
},
|
|
7986
|
-
(0, import_lucid30.addAssets)(stakingPositionOut.utxo.assets, (0,
|
|
8033
|
+
(0, import_lucid30.addAssets)(stakingPositionOut.utxo.assets, (0, import_cardano_offchain_common20.mkAssetsOf)(indyToken, amount))
|
|
7987
8034
|
).addSignerKey((0, import_lucid30.toHex)(stakingPositionOut.datum.owner));
|
|
7988
8035
|
}
|
|
7989
8036
|
async function closeStakingPosition(stakingPositionRef, params, lucid, currentSlot, stakingManagerRef) {
|
|
@@ -8009,14 +8056,14 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
8009
8056
|
(_) => new Error("Expected a single staking token policy Ref Script UTXO")
|
|
8010
8057
|
);
|
|
8011
8058
|
const indyToken = fromSystemParamsAsset(params.stakingParams.indyToken);
|
|
8012
|
-
const existingIndyAmount = (0,
|
|
8059
|
+
const existingIndyAmount = (0, import_cardano_offchain_common20.assetClassValueOf)(
|
|
8013
8060
|
stakingPositionOut.utxo.assets,
|
|
8014
8061
|
indyToken
|
|
8015
8062
|
);
|
|
8016
8063
|
const adaReward = calculateAdaReward(
|
|
8017
8064
|
stakingManagerOut.datum.managerSnapshot.snapshotAda,
|
|
8018
8065
|
stakingPositionOut.datum.positionSnapshot.snapshotAda,
|
|
8019
|
-
(0,
|
|
8066
|
+
(0, import_cardano_offchain_common20.assetClassValueOf)(stakingPositionOut.utxo.assets, indyToken)
|
|
8020
8067
|
);
|
|
8021
8068
|
return lucid.newTx().validFrom(Number(now)).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom(
|
|
8022
8069
|
[stakingManagerOut.utxo],
|
|
@@ -8030,9 +8077,9 @@ async function closeStakingPosition(stakingPositionRef, params, lucid, currentSl
|
|
|
8030
8077
|
totalStake: stakingManagerOut.datum.totalStake - existingIndyAmount
|
|
8031
8078
|
})
|
|
8032
8079
|
},
|
|
8033
|
-
(0, import_lucid30.addAssets)(stakingManagerOut.utxo.assets, (0,
|
|
8080
|
+
(0, import_lucid30.addAssets)(stakingManagerOut.utxo.assets, (0, import_cardano_offchain_common20.mkLovelacesOf)(-adaReward))
|
|
8034
8081
|
).mintAssets(
|
|
8035
|
-
(0,
|
|
8082
|
+
(0, import_cardano_offchain_common20.mkAssetsOf)(fromSystemParamsAsset(params.stakingParams.stakingToken), -1n),
|
|
8036
8083
|
import_lucid30.Data.void()
|
|
8037
8084
|
).addSignerKey((0, import_lucid30.toHex)(stakingPositionOut.datum.owner));
|
|
8038
8085
|
}
|
|
@@ -8040,7 +8087,7 @@ var MIN_UTXO_AMOUNT = 2000000n;
|
|
|
8040
8087
|
async function distributeAda(stakingManagerRef, collectorRefs, params, lucid) {
|
|
8041
8088
|
const [stakingManagerUtxo] = await lucid.utxosByOutRef([stakingManagerRef]);
|
|
8042
8089
|
const stakingManagerDatum = parseStakingManagerDatum(
|
|
8043
|
-
(0,
|
|
8090
|
+
(0, import_cardano_offchain_common20.getInlineDatumOrThrow)(stakingManagerUtxo)
|
|
8044
8091
|
);
|
|
8045
8092
|
const collectorUtxos = (await lucid.utxosByOutRef(collectorRefs)).filter((utxo) => utxo.datum && utxo.datum === import_lucid30.Data.void()).filter((utxo) => utxo.assets["lovelace"] > MIN_UTXO_AMOUNT);
|
|
8046
8093
|
if (collectorUtxos.length === 0) {
|
|
@@ -8079,13 +8126,13 @@ async function distributeAda(stakingManagerRef, collectorRefs, params, lucid) {
|
|
|
8079
8126
|
managerSnapshot: { snapshotAda: newSnapshot }
|
|
8080
8127
|
})
|
|
8081
8128
|
},
|
|
8082
|
-
(0, import_lucid30.addAssets)(stakingManagerUtxo.assets, (0,
|
|
8129
|
+
(0, import_lucid30.addAssets)(stakingManagerUtxo.assets, (0, import_cardano_offchain_common20.mkLovelacesOf)(adaRewardCollected))
|
|
8083
8130
|
);
|
|
8084
8131
|
for (const collectorUtxo of collectorUtxos) {
|
|
8085
8132
|
tx.pay.ToContract(
|
|
8086
8133
|
collectorUtxo.address,
|
|
8087
8134
|
{ kind: "inline", value: import_lucid30.Data.void() },
|
|
8088
|
-
(0,
|
|
8135
|
+
(0, import_cardano_offchain_common20.mkLovelacesOf)(MIN_UTXO_AMOUNT)
|
|
8089
8136
|
);
|
|
8090
8137
|
}
|
|
8091
8138
|
return tx;
|
|
@@ -8221,9 +8268,9 @@ function mkInterestOracleValidator(params) {
|
|
|
8221
8268
|
}
|
|
8222
8269
|
|
|
8223
8270
|
// tests/queries/interest-oracle-queries.ts
|
|
8224
|
-
var
|
|
8271
|
+
var import_cardano_offchain_common21 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
8225
8272
|
async function findInterestOracle(lucid, interestNft) {
|
|
8226
|
-
return lucid.utxoByUnit((0,
|
|
8273
|
+
return lucid.utxoByUnit((0, import_cardano_offchain_common21.assetClassToUnit)(interestNft));
|
|
8227
8274
|
}
|
|
8228
8275
|
|
|
8229
8276
|
// src/contracts/interest-oracle/transactions.ts
|
|
@@ -8395,6 +8442,50 @@ var mkInterestCollectionValidatorFromSP = (params) => {
|
|
|
8395
8442
|
};
|
|
8396
8443
|
};
|
|
8397
8444
|
|
|
8445
|
+
// src/contracts/interest-collection/queries.ts
|
|
8446
|
+
var import_fp_ts18 = require("fp-ts");
|
|
8447
|
+
var import_cardano_offchain_common22 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
8448
|
+
async function findAllInterestCollectors(lucid, sysParams) {
|
|
8449
|
+
return lucid.utxosAt(
|
|
8450
|
+
createScriptAddress(
|
|
8451
|
+
lucid.config().network,
|
|
8452
|
+
sysParams.validatorHashes.interestCollectionHash
|
|
8453
|
+
)
|
|
8454
|
+
);
|
|
8455
|
+
}
|
|
8456
|
+
async function findAdminInterestCollectors(lucid, sysParams) {
|
|
8457
|
+
return (0, import_cardano_offchain_common22.matchSingle)(
|
|
8458
|
+
await lucid.utxosAtWithUnit(
|
|
8459
|
+
createScriptAddress(
|
|
8460
|
+
lucid.config().network,
|
|
8461
|
+
sysParams.validatorHashes.interestCollectionHash
|
|
8462
|
+
),
|
|
8463
|
+
(0, import_cardano_offchain_common22.assetClassToUnit)(
|
|
8464
|
+
fromSystemParamsAsset(
|
|
8465
|
+
sysParams.interestCollectionParams.multisigUtxoNft
|
|
8466
|
+
)
|
|
8467
|
+
)
|
|
8468
|
+
),
|
|
8469
|
+
(_) => new Error("Expected a single admin interest collector UTXO")
|
|
8470
|
+
);
|
|
8471
|
+
}
|
|
8472
|
+
async function findRandomNonAdminInterestCollector(lucid, sysParams) {
|
|
8473
|
+
const allCollectors = (await findAllInterestCollectors(lucid, sysParams)).filter(
|
|
8474
|
+
(utxo) => !(0, import_cardano_offchain_common22.assetClassValueOf)(
|
|
8475
|
+
utxo.assets,
|
|
8476
|
+
fromSystemParamsAsset(
|
|
8477
|
+
sysParams.interestCollectionParams.multisigUtxoNft
|
|
8478
|
+
)
|
|
8479
|
+
)
|
|
8480
|
+
);
|
|
8481
|
+
return import_fp_ts18.function.pipe(
|
|
8482
|
+
import_fp_ts18.option.fromNullable((0, import_cardano_offchain_common22.getRandomElement)(allCollectors)),
|
|
8483
|
+
import_fp_ts18.option.match(() => {
|
|
8484
|
+
throw new Error("Expected some non-admin interest collector UTXOs.");
|
|
8485
|
+
}, import_fp_ts18.function.identity)
|
|
8486
|
+
);
|
|
8487
|
+
}
|
|
8488
|
+
|
|
8398
8489
|
// src/contracts/version-registry/types.ts
|
|
8399
8490
|
var import_lucid41 = require("@lucid-evolution/lucid");
|
|
8400
8491
|
var VersionRecordTokenParamsSchema = import_lucid41.Data.Object({
|
|
@@ -8438,41 +8529,8 @@ var mkVersionRegistryValidator = () => {
|
|
|
8438
8529
|
};
|
|
8439
8530
|
};
|
|
8440
8531
|
|
|
8441
|
-
// src/contracts/collector/scripts.ts
|
|
8442
|
-
var import_lucid43 = require("@lucid-evolution/lucid");
|
|
8443
|
-
|
|
8444
|
-
// src/validators/collector-validator.ts
|
|
8445
|
-
var _collectorValidator = {
|
|
8446
|
-
type: "PlutusScriptV3",
|
|
8447
|
-
description: "Generated by Aiken",
|
|
8448
|
-
cborHex: "590a2a590a27010100229800aba2aba1aba0aab9faab9eaab9dab9cab9a488888888cc896600264653001300b00198059806000cdc3a4005300b0024888966002600460166ea800e33001300c3754007370e90024dc3a4001300b375400891111919912cc004c0140122b3001301337540170028b20288acc004c0240122b3001301337540170028b20288acc004c0180122b3001301337540170028b20288b202040408080660024602a602c0032259800800c52f5c11330153012301600133002002301700140512301530163016001911919800800801912cc004006297ae0899912cc004c01400a2660320046600800800313300400400140506030002603200280b24446466446600400400244b3001001801c4c8c96600266e440180062b30013371e00c0031375a60320050054059133004004301d00340586eb8c05c004c068005018191919800800803112cc004006007132325980099b910080018acc004cdc7804000c4dd5980d001401501744cc010010c07800d0171bae3018001301b0014064297adef6c6014800260206ea802644b30010018800c54cc04400840050104dd2a400091111111194c0048c00800644602530010029bae301f301c3754003375c601660386ea8005007488c8cc00400400c8966002003168992cc004cdd79811180f9baa00100489807180f9baa001899801801981180120383021001407c9112cc004c03c01e2646464b300100180dc4c966002604a00513259800800c07a2b30013026001899805a49364d7573742070726f6475636520636f6c6c6563746f72206f7574707574207769746820696e63726561736564204144412076616c75650098009b914881009b8f4881009bac300f3022375402f3374a90011981218051981200219812260103d87a80004bd7025eb812222332232330010010052259800800c528456600264b300130040018acc004cdd7980c18159baa0014c107d87b9fd87980ff008acc004cc8a600264b30013020302d37540031375a605c60626eacc0c4c0b8dd5000c5200040ac60600033756005375e606060620032259800981298171baa4c0103d87a8000899b890010028acc004cdc480080144cdc480119b80001482026fb80a294102c20584888966002007159800980100344cc00401120008a5040b91325980099baf4c101400030310018acc004cc008014dd69819181a9bab3032001898019ba630360048a5040bd15980099801002a4001130030078a5040bc8178c0d000d0320dd3002994c0040066eacc06cc0b0dd5001488cc0c0008cc0c0dd3000a5eb810011112cc00400a26600298103d87a80004bd6f7b63044c8cc8966002601e005159800980700144cc010c064cc0ccc0c400d2f5c00031330044c0103d87a800000540b9198008034006446600c0046606a00a002803102e1bae302e0013033003303100240bd13375e605c605e605e605e60566ea800530103d87a80008a5040a114a0814229410281816800c528c4cc008008c0b800502720563259800a508800c4c8c8cc00400400c896600200313302c337609801014000374c00697adef6c6089919912cc004c02c00a2b3001300a0028992cc004cdd7a6101a000374c003100289981819bb04c01014000374c0020048158c8cc004004dd59817002112cc00400626606266ec130010140004c010101004bd6f7b63044c8cc89660026020005159800980780144c96600266e1c0052001880144cc0d4cdd8261014000375066e00005200200240c06eb4c0c800e26606866ec13010140004c0101010000440bd1330340033300500500140bc6eb8c0bc004c0d0008c0c800503044cc0bccdd82601014000374c00c008815226605e0066600a00a0028150dd7181500098178011816800a056330293376098010140004c010101004bd6f7b63020483756602a604c6ea8025660026030604a6ea8006246466ebcc0acc0a0dd5181598141baa002001302a3027375400512323375e605660506ea8008004c0a8c09cdd500120464079023204630073756602060426ea8c040c084dd5000c0710221811800a0423300b37586044603e6ea80508cdd7981198101baa302330203754601e60406ea8004008c084c078dd51810980f1baa0013300137586040603a6ea80480362b3001301300789919803a49334d757374207370656e64207374616b696e67206d616e61676572207769746820446973747269627574652072656465656d657200332259800800c00a2b3001302400189919912cc004c05400626464b300130290028024590261bae302700130233754007159800980c800c56600260466ea800e005164091159800980b000c56600260466ea800e00516409115980099b874801800626464b300130290028024590261bad30270013023375400715980099b87480200062b3001302337540070028b20488acc004cdc3a401400315980098119baa003801459024456600266e1d200c0018acc004c08cdd5001c00a2c81222c8101020204040808101020204013375e00298103d87b8000302037540026464660020026eacc094c098c098c098c098c098c098c098c098c098c088dd500b91192cc004cdd78021811800c4c09000626600600660500048108c098004cdd2a400466044604660406ea8c08c0052f5c100240848108528198051bac3021301e37540264660086eacc038c07cdd51807180f9baa0010023020301d37540471332259800980a980f1baa001899912cc004c094006264b30013014302137540031323322598009814800c4c8cc004004dd61814801112cc004006264b3001301a30273754003132324a2b3001323300100130103756605a605c605c605c605c60546ea807c896600266e3cdd71817000801c528c4cc008008c0bc00502845268b204c375c605660506ea80062c8128c8cc004004dd6180b98141baa0072259800800c5300103d87a80008992cc006600266ebc00530103d87a8000a50a51409d10018998018019817001204e325980099b8f375c605a002017130123302c302d302e0014bd7045300103d87a8000409c6eb0c0b000502a44c8c8cc8966002605e007133006006302f0058b2058375c60580026eb8c0b0008c0b0004dd61815000a0508b204c375a604c002604e00260446ea80062c80f8c966002602a60426ea80062604a60446ea80062c80f8c038c084dd5180818109baa30240018b2044375c6044603e6ea8004c8cc030dd6180798101baa01523002301030213754002b30013011301e375498103d879800089198029bab300f30203754002007123371090004c004dd5980798101baa0019bae302330203754007375c601e60406ea800d00b20388b2038300a301d37540466040603a6ea8c080c074dd5198009bac3020301d375402401a80d101a0c01c01c6028602a00a60260088b2012180580098031baa00b8a4d13656400c2a660049201353c65787065637465643e20436f6c6c6563746f7220696e7075742063616e6e6f742068617665206e6f6e2d41444120617373657473001615330024912c3c65787065637465643e204d757374207370656e642073696e676c6520636f6c6c6563746f7220696e707574001601"
|
|
8449
|
-
};
|
|
8450
|
-
|
|
8451
|
-
// src/contracts/collector/scripts.ts
|
|
8452
|
-
var mkCollectorValidatorFromSP = (params) => {
|
|
8453
|
-
return {
|
|
8454
|
-
type: "PlutusV3",
|
|
8455
|
-
script: (0, import_lucid43.applyParamsToScript)(_collectorValidator.cborHex, [
|
|
8456
|
-
new import_lucid43.Constr(0, [
|
|
8457
|
-
new import_lucid43.Constr(0, [
|
|
8458
|
-
params.stakingManagerNFT[0].unCurrencySymbol,
|
|
8459
|
-
(0, import_lucid43.fromText)(params.stakingManagerNFT[1].unTokenName)
|
|
8460
|
-
]),
|
|
8461
|
-
new import_lucid43.Constr(0, [
|
|
8462
|
-
params.stakingToken[0].unCurrencySymbol,
|
|
8463
|
-
(0, import_lucid43.fromText)(params.stakingToken[1].unTokenName)
|
|
8464
|
-
]),
|
|
8465
|
-
new import_lucid43.Constr(0, [
|
|
8466
|
-
params.versionRecordToken[0].unCurrencySymbol,
|
|
8467
|
-
(0, import_lucid43.fromText)(params.versionRecordToken[1].unTokenName)
|
|
8468
|
-
])
|
|
8469
|
-
])
|
|
8470
|
-
])
|
|
8471
|
-
};
|
|
8472
|
-
};
|
|
8473
|
-
|
|
8474
8532
|
// src/contracts/treasury/scripts.ts
|
|
8475
|
-
var
|
|
8533
|
+
var import_lucid44 = require("@lucid-evolution/lucid");
|
|
8476
8534
|
|
|
8477
8535
|
// src/validators/treasury-validator.ts
|
|
8478
8536
|
var _treasuryValidator = {
|
|
@@ -8482,22 +8540,22 @@ var _treasuryValidator = {
|
|
|
8482
8540
|
};
|
|
8483
8541
|
|
|
8484
8542
|
// src/contracts/treasury/types.ts
|
|
8485
|
-
var
|
|
8486
|
-
var TreasuryParamsSchema =
|
|
8543
|
+
var import_lucid43 = require("@lucid-evolution/lucid");
|
|
8544
|
+
var TreasuryParamsSchema = import_lucid43.Data.Object({
|
|
8487
8545
|
upgradeToken: AssetClassSchema2,
|
|
8488
8546
|
versionRecordToken: AssetClassSchema2,
|
|
8489
|
-
treasuryUtxosStakeCredential:
|
|
8547
|
+
treasuryUtxosStakeCredential: import_lucid43.Data.Nullable(StakeCredentialSchema)
|
|
8490
8548
|
});
|
|
8491
8549
|
var TreasuryParams = TreasuryParamsSchema;
|
|
8492
8550
|
function castTreasuryParams(params) {
|
|
8493
|
-
return
|
|
8551
|
+
return import_lucid43.Data.castTo(params, TreasuryParams);
|
|
8494
8552
|
}
|
|
8495
8553
|
|
|
8496
8554
|
// src/contracts/treasury/scripts.ts
|
|
8497
8555
|
var mkTreasuryValidatorFromSP = (params) => {
|
|
8498
8556
|
return {
|
|
8499
8557
|
type: "PlutusV3",
|
|
8500
|
-
script: (0,
|
|
8558
|
+
script: (0, import_lucid44.applyParamsToScript)(_treasuryValidator.cborHex, [
|
|
8501
8559
|
castTreasuryParams({
|
|
8502
8560
|
upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
|
|
8503
8561
|
versionRecordToken: fromSystemParamsAssetLucid(
|
|
@@ -8509,6 +8567,95 @@ var mkTreasuryValidatorFromSP = (params) => {
|
|
|
8509
8567
|
};
|
|
8510
8568
|
};
|
|
8511
8569
|
|
|
8570
|
+
// src/contracts/treasury/queries.ts
|
|
8571
|
+
var import_fp_ts19 = require("fp-ts");
|
|
8572
|
+
var import_cardano_offchain_common23 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
8573
|
+
async function findAllTreasuryUtxos(lucid, sysParams) {
|
|
8574
|
+
return lucid.utxosAt({
|
|
8575
|
+
type: "Script",
|
|
8576
|
+
hash: sysParams.validatorHashes.treasuryHash
|
|
8577
|
+
});
|
|
8578
|
+
}
|
|
8579
|
+
async function findRandomTreasuryUtxo(lucid, sysParams) {
|
|
8580
|
+
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
8581
|
+
return import_fp_ts19.function.pipe(
|
|
8582
|
+
import_fp_ts19.option.fromNullable((0, import_cardano_offchain_common23.getRandomElement)(treasuryUtxos)),
|
|
8583
|
+
import_fp_ts19.option.match(() => {
|
|
8584
|
+
throw new Error("Expected some treasury UTXOs.");
|
|
8585
|
+
}, import_fp_ts19.function.identity)
|
|
8586
|
+
);
|
|
8587
|
+
}
|
|
8588
|
+
async function findRandomTreasuryUtxoWithOnlyAda(lucid, sysParams) {
|
|
8589
|
+
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
8590
|
+
const adaOnlyTreasuryUtxos = treasuryUtxos.filter(
|
|
8591
|
+
(utxo) => Object.keys(utxo.assets).length == 1
|
|
8592
|
+
);
|
|
8593
|
+
return import_fp_ts19.function.pipe(
|
|
8594
|
+
import_fp_ts19.option.fromNullable((0, import_cardano_offchain_common23.getRandomElement)(adaOnlyTreasuryUtxos)),
|
|
8595
|
+
import_fp_ts19.option.match(() => {
|
|
8596
|
+
throw new Error("Expected some treasury UTXOs.");
|
|
8597
|
+
}, import_fp_ts19.function.identity)
|
|
8598
|
+
);
|
|
8599
|
+
}
|
|
8600
|
+
async function findRandomTreasuryUtxoWithAsset(lucid, sysParams, asset, max_number_of_assets = 2n) {
|
|
8601
|
+
const treasuryUtxos = await lucid.utxosAtWithUnit(
|
|
8602
|
+
{ hash: sysParams.validatorHashes.treasuryHash, type: "Script" },
|
|
8603
|
+
(0, import_cardano_offchain_common23.assetClassToUnit)(asset)
|
|
8604
|
+
);
|
|
8605
|
+
const validTreasuryUtxos = treasuryUtxos.filter(
|
|
8606
|
+
(utxo) => Object.keys(utxo.assets).length <= max_number_of_assets
|
|
8607
|
+
);
|
|
8608
|
+
return import_fp_ts19.function.pipe(
|
|
8609
|
+
import_fp_ts19.option.fromNullable((0, import_cardano_offchain_common23.getRandomElement)(validTreasuryUtxos)),
|
|
8610
|
+
import_fp_ts19.option.match(() => {
|
|
8611
|
+
throw new Error("Expected some treasury UTXOs.");
|
|
8612
|
+
}, import_fp_ts19.function.identity)
|
|
8613
|
+
);
|
|
8614
|
+
}
|
|
8615
|
+
async function findAllTreasuryUtxosWithNonAdaAsset(lucid, sysParams, includeDaoToken = true) {
|
|
8616
|
+
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
8617
|
+
const treasuryUtxosWithNonAdaAsset = treasuryUtxos.filter(
|
|
8618
|
+
(utxo) => Object.keys(utxo.assets).length !== 1 && (includeDaoToken ? true : (0, import_cardano_offchain_common23.assetClassValueOf)(
|
|
8619
|
+
utxo.assets,
|
|
8620
|
+
fromSystemParamsAsset(sysParams.govParams.daoIdentityToken)
|
|
8621
|
+
) === 0n)
|
|
8622
|
+
);
|
|
8623
|
+
return treasuryUtxosWithNonAdaAsset;
|
|
8624
|
+
}
|
|
8625
|
+
|
|
8626
|
+
// src/contracts/collector/scripts.ts
|
|
8627
|
+
var import_lucid45 = require("@lucid-evolution/lucid");
|
|
8628
|
+
|
|
8629
|
+
// src/validators/collector-validator.ts
|
|
8630
|
+
var _collectorValidator = {
|
|
8631
|
+
type: "PlutusScriptV3",
|
|
8632
|
+
description: "Generated by Aiken",
|
|
8633
|
+
cborHex: "590a2a590a27010100229800aba2aba1aba0aab9faab9eaab9dab9cab9a488888888cc896600264653001300b00198059806000cdc3a4005300b0024888966002600460166ea800e33001300c3754007370e90024dc3a4001300b375400891111919912cc004c0140122b3001301337540170028b20288acc004c0240122b3001301337540170028b20288acc004c0180122b3001301337540170028b20288b202040408080660024602a602c0032259800800c52f5c11330153012301600133002002301700140512301530163016001911919800800801912cc004006297ae0899912cc004c01400a2660320046600800800313300400400140506030002603200280b24446466446600400400244b3001001801c4c8c96600266e440180062b30013371e00c0031375a60320050054059133004004301d00340586eb8c05c004c068005018191919800800803112cc004006007132325980099b910080018acc004cdc7804000c4dd5980d001401501744cc010010c07800d0171bae3018001301b0014064297adef6c6014800260206ea802644b30010018800c54cc04400840050104dd2a400091111111194c0048c00800644602530010029bae301f301c3754003375c601660386ea8005007488c8cc00400400c8966002003168992cc004cdd79811180f9baa00100489807180f9baa001899801801981180120383021001407c9112cc004c03c01e2646464b300100180dc4c966002604a00513259800800c07a2b30013026001899805a49364d7573742070726f6475636520636f6c6c6563746f72206f7574707574207769746820696e63726561736564204144412076616c75650098009b914881009b8f4881009bac300f3022375402f3374a90011981218051981200219812260103d87a80004bd7025eb812222332232330010010052259800800c528456600264b300130040018acc004cdd7980c18159baa0014c107d87b9fd87980ff008acc004cc8a600264b30013020302d37540031375a605c60626eacc0c4c0b8dd5000c5200040ac60600033756005375e606060620032259800981298171baa4c0103d87a8000899b890010028acc004cdc480080144cdc480119b80001482026fb80a294102c20584888966002007159800980100344cc00401120008a5040b91325980099baf4c101400030310018acc004cc008014dd69819181a9bab3032001898019ba630360048a5040bd15980099801002a4001130030078a5040bc8178c0d000d0320dd3002994c0040066eacc06cc0b0dd5001488cc0c0008cc0c0dd3000a5eb810011112cc00400a26600298103d87a80004bd6f7b63044c8cc8966002601e005159800980700144cc010c064cc0ccc0c400d2f5c00031330044c0103d87a800000540b9198008034006446600c0046606a00a002803102e1bae302e0013033003303100240bd13375e605c605e605e605e60566ea800530103d87a80008a5040a114a0814229410281816800c528c4cc008008c0b800502720563259800a508800c4c8c8cc00400400c896600200313302c337609801014000374c00697adef6c6089919912cc004c02c00a2b3001300a0028992cc004cdd7a6101a000374c003100289981819bb04c01014000374c0020048158c8cc004004dd59817002112cc00400626606266ec130010140004c010101004bd6f7b63044c8cc89660026020005159800980780144c96600266e1c0052001880144cc0d4cdd8261014000375066e00005200200240c06eb4c0c800e26606866ec13010140004c0101010000440bd1330340033300500500140bc6eb8c0bc004c0d0008c0c800503044cc0bccdd82601014000374c00c008815226605e0066600a00a0028150dd7181500098178011816800a056330293376098010140004c010101004bd6f7b63020483756602a604c6ea8025660026030604a6ea8006246466ebcc0acc0a0dd5181598141baa002001302a3027375400512323375e605660506ea8008004c0a8c09cdd500120464079023204630073756602060426ea8c040c084dd5000c0710221811800a0423300b37586044603e6ea80508cdd7981198101baa302330203754601e60406ea8004008c084c078dd51810980f1baa0013300137586040603a6ea80480362b3001301300789919803a49334d757374207370656e64207374616b696e67206d616e61676572207769746820446973747269627574652072656465656d657200332259800800c00a2b3001302400189919912cc004c05400626464b300130290028024590261bae302700130233754007159800980c800c56600260466ea800e005164091159800980b000c56600260466ea800e00516409115980099b874801800626464b300130290028024590261bad30270013023375400715980099b87480200062b3001302337540070028b20488acc004cdc3a401400315980098119baa003801459024456600266e1d200c0018acc004c08cdd5001c00a2c81222c8101020204040808101020204013375e00298103d87b8000302037540026464660020026eacc094c098c098c098c098c098c098c098c098c098c088dd500b91192cc004cdd78021811800c4c09000626600600660500048108c098004cdd2a400466044604660406ea8c08c0052f5c100240848108528198051bac3021301e37540264660086eacc038c07cdd51807180f9baa0010023020301d37540471332259800980a980f1baa001899912cc004c094006264b30013014302137540031323322598009814800c4c8cc004004dd61814801112cc004006264b3001301a30273754003132324a2b3001323300100130103756605a605c605c605c605c60546ea807c896600266e3cdd71817000801c528c4cc008008c0bc00502845268b204c375c605660506ea80062c8128c8cc004004dd6180b98141baa0072259800800c5300103d87a80008992cc006600266ebc00530103d87a8000a50a51409d10018998018019817001204e325980099b8f375c605a002017130123302c302d302e0014bd7045300103d87a8000409c6eb0c0b000502a44c8c8cc8966002605e007133006006302f0058b2058375c60580026eb8c0b0008c0b0004dd61815000a0508b204c375a604c002604e00260446ea80062c80f8c966002602a60426ea80062604a60446ea80062c80f8c038c084dd5180818109baa30240018b2044375c6044603e6ea8004c8cc030dd6180798101baa01523002301030213754002b30013011301e375498103d879800089198029bab300f30203754002007123371090004c004dd5980798101baa0019bae302330203754007375c601e60406ea800d00b20388b2038300a301d37540466040603a6ea8c080c074dd5198009bac3020301d375402401a80d101a0c01c01c6028602a00a60260088b2012180580098031baa00b8a4d13656400c2a660049201353c65787065637465643e20436f6c6c6563746f7220696e7075742063616e6e6f742068617665206e6f6e2d41444120617373657473001615330024912c3c65787065637465643e204d757374207370656e642073696e676c6520636f6c6c6563746f7220696e707574001601"
|
|
8634
|
+
};
|
|
8635
|
+
|
|
8636
|
+
// src/contracts/collector/scripts.ts
|
|
8637
|
+
var mkCollectorValidatorFromSP = (params) => {
|
|
8638
|
+
return {
|
|
8639
|
+
type: "PlutusV3",
|
|
8640
|
+
script: (0, import_lucid45.applyParamsToScript)(_collectorValidator.cborHex, [
|
|
8641
|
+
new import_lucid45.Constr(0, [
|
|
8642
|
+
new import_lucid45.Constr(0, [
|
|
8643
|
+
params.stakingManagerNFT[0].unCurrencySymbol,
|
|
8644
|
+
(0, import_lucid45.fromText)(params.stakingManagerNFT[1].unTokenName)
|
|
8645
|
+
]),
|
|
8646
|
+
new import_lucid45.Constr(0, [
|
|
8647
|
+
params.stakingToken[0].unCurrencySymbol,
|
|
8648
|
+
(0, import_lucid45.fromText)(params.stakingToken[1].unTokenName)
|
|
8649
|
+
]),
|
|
8650
|
+
new import_lucid45.Constr(0, [
|
|
8651
|
+
params.versionRecordToken[0].unCurrencySymbol,
|
|
8652
|
+
(0, import_lucid45.fromText)(params.versionRecordToken[1].unTokenName)
|
|
8653
|
+
])
|
|
8654
|
+
])
|
|
8655
|
+
])
|
|
8656
|
+
};
|
|
8657
|
+
};
|
|
8658
|
+
|
|
8512
8659
|
// src/contracts/execute/types.ts
|
|
8513
8660
|
var import_lucid46 = require("@lucid-evolution/lucid");
|
|
8514
8661
|
var ExecuteParamsSchema = import_lucid46.Data.Object({
|
|
@@ -8602,14 +8749,14 @@ var import_lucid49 = require("@lucid-evolution/lucid");
|
|
|
8602
8749
|
|
|
8603
8750
|
// src/contracts/rob/types-new.ts
|
|
8604
8751
|
var import_evolution19 = require("@evolution-sdk/evolution");
|
|
8605
|
-
var
|
|
8606
|
-
var
|
|
8752
|
+
var import_cardano_offchain_common24 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
8753
|
+
var import_fp_ts20 = require("fp-ts");
|
|
8607
8754
|
var RobOrderTypeSchema = import_evolution19.TSchema.Union(
|
|
8608
8755
|
import_evolution19.TSchema.Struct(
|
|
8609
8756
|
{
|
|
8610
8757
|
BuyIAssetOrder: import_evolution19.TSchema.Struct(
|
|
8611
8758
|
{
|
|
8612
|
-
collateralAsset:
|
|
8759
|
+
collateralAsset: import_cardano_offchain_common24.AssetClassSchema,
|
|
8613
8760
|
maxPrice: RationalSchema
|
|
8614
8761
|
},
|
|
8615
8762
|
{ flatFields: true }
|
|
@@ -8622,7 +8769,7 @@ var RobOrderTypeSchema = import_evolution19.TSchema.Union(
|
|
|
8622
8769
|
SellIAssetOrder: import_evolution19.TSchema.Struct(
|
|
8623
8770
|
{
|
|
8624
8771
|
allowedCollateralAssets: import_evolution19.TSchema.Array(
|
|
8625
|
-
import_evolution19.TSchema.Tuple([
|
|
8772
|
+
import_evolution19.TSchema.Tuple([import_cardano_offchain_common24.AssetClassSchema, RationalSchema])
|
|
8626
8773
|
)
|
|
8627
8774
|
},
|
|
8628
8775
|
{ flatFields: true }
|
|
@@ -8635,7 +8782,7 @@ var RobDatumSchema = import_evolution19.TSchema.Struct({
|
|
|
8635
8782
|
owner: import_evolution19.TSchema.ByteArray,
|
|
8636
8783
|
iasset: import_evolution19.TSchema.ByteArray,
|
|
8637
8784
|
orderType: RobOrderTypeSchema,
|
|
8638
|
-
robRefInput:
|
|
8785
|
+
robRefInput: import_cardano_offchain_common24.OutputReferenceSchema
|
|
8639
8786
|
});
|
|
8640
8787
|
var RobRedeemerSchema = import_evolution19.TSchema.Union(
|
|
8641
8788
|
import_evolution19.TSchema.Struct(
|
|
@@ -8659,21 +8806,21 @@ var RobRedeemerSchema = import_evolution19.TSchema.Union(
|
|
|
8659
8806
|
);
|
|
8660
8807
|
function parseRobDatum(datum) {
|
|
8661
8808
|
try {
|
|
8662
|
-
return
|
|
8809
|
+
return import_fp_ts20.option.some(
|
|
8663
8810
|
import_evolution19.Data.withSchema(RobDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
8664
8811
|
datum
|
|
8665
8812
|
)
|
|
8666
8813
|
);
|
|
8667
8814
|
} catch (_) {
|
|
8668
|
-
return
|
|
8815
|
+
return import_fp_ts20.option.none;
|
|
8669
8816
|
}
|
|
8670
8817
|
}
|
|
8671
8818
|
function parseRobDatumOrThrow(datum) {
|
|
8672
|
-
return
|
|
8819
|
+
return import_fp_ts20.function.pipe(
|
|
8673
8820
|
parseRobDatum(datum),
|
|
8674
|
-
|
|
8821
|
+
import_fp_ts20.option.match(() => {
|
|
8675
8822
|
throw new Error("Expected an ROB datum.");
|
|
8676
|
-
},
|
|
8823
|
+
}, import_fp_ts20.function.identity)
|
|
8677
8824
|
);
|
|
8678
8825
|
}
|
|
8679
8826
|
function serialiseRobDatum(d) {
|
|
@@ -8686,28 +8833,28 @@ function serialiseRobRedeemer(r) {
|
|
|
8686
8833
|
}
|
|
8687
8834
|
function parseRobRedeemer(redeemerCborHex) {
|
|
8688
8835
|
try {
|
|
8689
|
-
return
|
|
8836
|
+
return import_fp_ts20.option.some(
|
|
8690
8837
|
import_evolution19.Data.withSchema(RobRedeemerSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
8691
8838
|
redeemerCborHex
|
|
8692
8839
|
)
|
|
8693
8840
|
);
|
|
8694
8841
|
} catch (_) {
|
|
8695
|
-
return
|
|
8842
|
+
return import_fp_ts20.option.none;
|
|
8696
8843
|
}
|
|
8697
8844
|
}
|
|
8698
8845
|
function parseRobRedeemerOrThrow(redeemerCborHex) {
|
|
8699
|
-
return
|
|
8846
|
+
return import_fp_ts20.function.pipe(
|
|
8700
8847
|
parseRobRedeemer(redeemerCborHex),
|
|
8701
|
-
|
|
8848
|
+
import_fp_ts20.option.match(() => {
|
|
8702
8849
|
throw new Error("Expected an ROB redeemer.");
|
|
8703
|
-
},
|
|
8850
|
+
}, import_fp_ts20.function.identity)
|
|
8704
8851
|
);
|
|
8705
8852
|
}
|
|
8706
8853
|
|
|
8707
8854
|
// src/contracts/rob/helpers.ts
|
|
8708
|
-
var
|
|
8855
|
+
var import_fp_ts21 = require("fp-ts");
|
|
8709
8856
|
var import_ts_pattern19 = require("ts-pattern");
|
|
8710
|
-
var
|
|
8857
|
+
var import_cardano_offchain_common25 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
8711
8858
|
var import_decimal = __toESM(require("decimal.js"));
|
|
8712
8859
|
var MIN_ROB_COLLATERAL_AMT = 3000000n;
|
|
8713
8860
|
var MAX_SELL_ROB_REDEMPTIONS_COUNT = 18;
|
|
@@ -8753,10 +8900,10 @@ function calculateSpendAmtWhenRobSellOrder(purchaseIassetAmt, redemptionReimburs
|
|
|
8753
8900
|
}
|
|
8754
8901
|
function robCollateralAmtToSpend(robAssets, robOrderType) {
|
|
8755
8902
|
return (0, import_ts_pattern19.match)(robOrderType).returnType().with({ BuyIAssetOrder: import_ts_pattern19.P.select() }, (content) => {
|
|
8756
|
-
if ((0,
|
|
8757
|
-
return zeroNegatives((0,
|
|
8903
|
+
if ((0, import_cardano_offchain_common25.isSameAssetClass)(import_cardano_offchain_common25.adaAssetClass, content.collateralAsset)) {
|
|
8904
|
+
return zeroNegatives((0, import_cardano_offchain_common25.lovelacesAmt)(robAssets) - MIN_ROB_COLLATERAL_AMT);
|
|
8758
8905
|
} else {
|
|
8759
|
-
return (0,
|
|
8906
|
+
return (0, import_cardano_offchain_common25.assetClassValueOf)(robAssets, content.collateralAsset);
|
|
8760
8907
|
}
|
|
8761
8908
|
}).otherwise(() => {
|
|
8762
8909
|
throw new Error("Collateral to spend is relevant only for Buy orders.");
|
|
@@ -8764,7 +8911,7 @@ function robCollateralAmtToSpend(robAssets, robOrderType) {
|
|
|
8764
8911
|
}
|
|
8765
8912
|
function robIAssetAmtToSpend(robAssets, robOrderType, robIasset) {
|
|
8766
8913
|
return (0, import_ts_pattern19.match)(robOrderType).returnType().with({ SellIAssetOrder: import_ts_pattern19.P.any }, (_) => {
|
|
8767
|
-
return (0,
|
|
8914
|
+
return (0, import_cardano_offchain_common25.assetClassValueOf)(robAssets, robIasset);
|
|
8768
8915
|
}).otherwise(() => {
|
|
8769
8916
|
throw new Error("IAssets to spend is relevant only for Sell orders.");
|
|
8770
8917
|
});
|
|
@@ -8782,7 +8929,7 @@ function robBuyOrderFilledAssets(robAssets, robOrderType, robIasset) {
|
|
|
8782
8929
|
return (0, import_ts_pattern19.match)(robOrderType).returnType().with({ BuyIAssetOrder: import_ts_pattern19.P.any }, () => {
|
|
8783
8930
|
return {
|
|
8784
8931
|
asset: robIasset,
|
|
8785
|
-
filledAmt: (0,
|
|
8932
|
+
filledAmt: (0, import_cardano_offchain_common25.assetClassValueOf)(robAssets, robIasset)
|
|
8786
8933
|
};
|
|
8787
8934
|
}).otherwise(() => {
|
|
8788
8935
|
throw new Error("Expected only buy order.");
|
|
@@ -8793,7 +8940,7 @@ function robSellOrderFilledAssets(robAssets, robOrderType) {
|
|
|
8793
8940
|
return content.allowedCollateralAssets.map(([asset, _]) => {
|
|
8794
8941
|
return {
|
|
8795
8942
|
asset,
|
|
8796
|
-
filledAmt: (0,
|
|
8943
|
+
filledAmt: (0, import_cardano_offchain_common25.assetClassValueOf)(robAssets, asset) - ((0, import_cardano_offchain_common25.isSameAssetClass)(asset, import_cardano_offchain_common25.adaAssetClass) ? MIN_ROB_COLLATERAL_AMT : 0n)
|
|
8797
8944
|
};
|
|
8798
8945
|
});
|
|
8799
8946
|
}).otherwise(() => {
|
|
@@ -8830,9 +8977,9 @@ function isFullyRedeemed(robAssets, robOrderType, robIasset) {
|
|
|
8830
8977
|
}).exhaustive();
|
|
8831
8978
|
}
|
|
8832
8979
|
function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redemptionReimbursementRatio, sysParams, tx, txOutputsBeforeCount, collateralAssetRefInputIdx, iassetRefInputIdx, oracleIdx) {
|
|
8833
|
-
return
|
|
8980
|
+
return import_fp_ts21.function.pipe(
|
|
8834
8981
|
redemptions,
|
|
8835
|
-
|
|
8982
|
+
import_fp_ts21.array.reduceWithIndex(
|
|
8836
8983
|
tx,
|
|
8837
8984
|
(idx, acc, [robUtxo, payoutAmt]) => {
|
|
8838
8985
|
const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
|
|
@@ -8842,7 +8989,7 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8842
8989
|
const [robOutputVal, sellOrderAllowedAssetsIdx] = (0, import_ts_pattern19.match)(
|
|
8843
8990
|
robDatum.orderType
|
|
8844
8991
|
).returnType().with({ BuyIAssetOrder: import_ts_pattern19.P.select() }, (content) => {
|
|
8845
|
-
if (!(0,
|
|
8992
|
+
if (!(0, import_cardano_offchain_common25.isSameAssetClass)(content.collateralAsset, collateralAsset)) {
|
|
8846
8993
|
throw new Error("Only same collateral asset");
|
|
8847
8994
|
}
|
|
8848
8995
|
const payoutIAssetAmt = payoutAmt;
|
|
@@ -8853,8 +9000,8 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8853
9000
|
);
|
|
8854
9001
|
const resultVal = (0, import_lucid49.addAssets)(
|
|
8855
9002
|
robUtxo.assets,
|
|
8856
|
-
(0,
|
|
8857
|
-
(0,
|
|
9003
|
+
(0, import_cardano_offchain_common25.mkAssetsOf)(collateralAsset, -collateralForRedemption),
|
|
9004
|
+
(0, import_cardano_offchain_common25.mkAssetsOf)(
|
|
8858
9005
|
{
|
|
8859
9006
|
currencySymbol: (0, import_lucid49.fromHex)(
|
|
8860
9007
|
sysParams.robParams.iassetPolicyId.unCurrencySymbol
|
|
@@ -8866,12 +9013,12 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8866
9013
|
);
|
|
8867
9014
|
return [resultVal, 0n];
|
|
8868
9015
|
}).with({ SellIAssetOrder: import_ts_pattern19.P.select() }, (content) => {
|
|
8869
|
-
const allowedAssetIdx =
|
|
9016
|
+
const allowedAssetIdx = import_fp_ts21.function.pipe(
|
|
8870
9017
|
content.allowedCollateralAssets,
|
|
8871
|
-
|
|
8872
|
-
([asset, _]) => (0,
|
|
9018
|
+
import_fp_ts21.readonlyArray.findIndex(
|
|
9019
|
+
([asset, _]) => (0, import_cardano_offchain_common25.isSameAssetClass)(asset, collateralAsset)
|
|
8873
9020
|
),
|
|
8874
|
-
|
|
9021
|
+
import_fp_ts21.option.getOrElse(() => {
|
|
8875
9022
|
throw new Error("Doesn't allow required collateral asset.");
|
|
8876
9023
|
})
|
|
8877
9024
|
);
|
|
@@ -8883,8 +9030,8 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8883
9030
|
);
|
|
8884
9031
|
const resultVal = (0, import_lucid49.addAssets)(
|
|
8885
9032
|
robUtxo.assets,
|
|
8886
|
-
(0,
|
|
8887
|
-
(0,
|
|
9033
|
+
(0, import_cardano_offchain_common25.mkAssetsOf)(collateralAsset, payoutCollateralAmt),
|
|
9034
|
+
(0, import_cardano_offchain_common25.mkAssetsOf)(
|
|
8888
9035
|
{
|
|
8889
9036
|
currencySymbol: (0, import_lucid49.fromHex)(
|
|
8890
9037
|
sysParams.robParams.iassetPolicyId.unCurrencySymbol
|
|
@@ -8896,7 +9043,7 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8896
9043
|
);
|
|
8897
9044
|
return [resultVal, BigInt(allowedAssetIdx)];
|
|
8898
9045
|
}).exhaustive();
|
|
8899
|
-
if ((0,
|
|
9046
|
+
if ((0, import_cardano_offchain_common25.lovelacesAmt)(robOutputVal) < MIN_ROB_COLLATERAL_AMT) {
|
|
8900
9047
|
throw new Error(
|
|
8901
9048
|
"Redeeming more than available or selected ROB was incorrectly initialised."
|
|
8902
9049
|
);
|
|
@@ -8932,26 +9079,26 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8932
9079
|
);
|
|
8933
9080
|
}
|
|
8934
9081
|
function calculateTotalCollateralForRedemption(iasset, collateralAsset, iassetPrice, allRobs, maxRobsInTx) {
|
|
8935
|
-
return
|
|
9082
|
+
return import_fp_ts21.function.pipe(
|
|
8936
9083
|
allRobs,
|
|
8937
|
-
|
|
9084
|
+
import_fp_ts21.array.filterMap(([utxo, datum]) => {
|
|
8938
9085
|
const isCorrectOrder = (0, import_ts_pattern19.match)(datum.orderType).returnType().with(
|
|
8939
9086
|
{ BuyIAssetOrder: import_ts_pattern19.P.select() },
|
|
8940
|
-
(content) => (0,
|
|
9087
|
+
(content) => (0, import_cardano_offchain_common25.isSameAssetClass)(content.collateralAsset, collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice) && !isBuyOrderFullyRedeemed(utxo.assets, datum.orderType, iassetPrice)
|
|
8941
9088
|
).otherwise(() => false);
|
|
8942
9089
|
if ((0, import_lucid49.toHex)(datum.iasset) !== (0, import_lucid49.toHex)(iasset) || !isCorrectOrder) {
|
|
8943
|
-
return
|
|
9090
|
+
return import_fp_ts21.option.none;
|
|
8944
9091
|
}
|
|
8945
9092
|
const collateralToSpend = robCollateralAmtToSpend(
|
|
8946
9093
|
utxo.assets,
|
|
8947
9094
|
datum.orderType
|
|
8948
9095
|
);
|
|
8949
|
-
return
|
|
9096
|
+
return import_fp_ts21.option.some(collateralToSpend);
|
|
8950
9097
|
}),
|
|
8951
9098
|
// From largest to smallest
|
|
8952
|
-
|
|
9099
|
+
import_fp_ts21.array.sort(import_fp_ts21.ord.reverse(BigIntOrd)),
|
|
8953
9100
|
// We can fit only this number of redemptions with CDP open into a single Tx.
|
|
8954
|
-
|
|
9101
|
+
import_fp_ts21.array.takeLeft(maxRobsInTx),
|
|
8955
9102
|
sum
|
|
8956
9103
|
);
|
|
8957
9104
|
}
|
|
@@ -8960,12 +9107,12 @@ function randomRobsSubsetSatisfyingTargetCollateral(iasset, collateralAsset, tar
|
|
|
8960
9107
|
throw new Error("Must redeem and payout more than 0.");
|
|
8961
9108
|
}
|
|
8962
9109
|
const shuffled = randomiseFn(
|
|
8963
|
-
|
|
9110
|
+
import_fp_ts21.function.pipe(
|
|
8964
9111
|
allLrps,
|
|
8965
|
-
|
|
9112
|
+
import_fp_ts21.array.filter(
|
|
8966
9113
|
([utxo, datum]) => (0, import_lucid49.toHex)(datum.iasset) === (0, import_lucid49.toHex)(iasset) && (0, import_ts_pattern19.match)(datum.orderType).with(
|
|
8967
9114
|
{ BuyIAssetOrder: import_ts_pattern19.P.select() },
|
|
8968
|
-
(content) => (0,
|
|
9115
|
+
(content) => (0, import_cardano_offchain_common25.isSameAssetClass)(collateralAsset, content.collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice)
|
|
8969
9116
|
).otherwise(() => false) && !isBuyOrderFullyRedeemed(utxo.assets, datum.orderType, iassetPrice)
|
|
8970
9117
|
)
|
|
8971
9118
|
)
|
|
@@ -9000,10 +9147,10 @@ function randomRobsSubsetSatisfyingTargetCollateral(iasset, collateralAsset, tar
|
|
|
9000
9147
|
result = insertSorted(
|
|
9001
9148
|
result,
|
|
9002
9149
|
element,
|
|
9003
|
-
|
|
9150
|
+
import_fp_ts21.ord.contramap(
|
|
9004
9151
|
([utxo, dat]) => robCollateralAmtToSpend(utxo.assets, dat.orderType)
|
|
9005
9152
|
// From highest to lowest
|
|
9006
|
-
)(
|
|
9153
|
+
)(import_fp_ts21.ord.reverse(BigIntOrd))
|
|
9007
9154
|
);
|
|
9008
9155
|
runningSum += lovelacesToSpend;
|
|
9009
9156
|
if (result.length > maxLrpsInTx) {
|
|
@@ -9040,9 +9187,9 @@ function castRobParams(params) {
|
|
|
9040
9187
|
|
|
9041
9188
|
// src/contracts/rob/transactions.ts
|
|
9042
9189
|
var import_lucid51 = require("@lucid-evolution/lucid");
|
|
9043
|
-
var
|
|
9190
|
+
var import_fp_ts22 = require("fp-ts");
|
|
9044
9191
|
var import_Array2 = require("fp-ts/lib/Array");
|
|
9045
|
-
var
|
|
9192
|
+
var import_cardano_offchain_common26 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
9046
9193
|
var import_ts_pattern20 = require("ts-pattern");
|
|
9047
9194
|
async function openRob(assetTokenNameAscii, depositAmt, orderType, lucid, sysParams, robStakeCredential) {
|
|
9048
9195
|
const network = lucid.config().network;
|
|
@@ -9060,10 +9207,10 @@ async function openRob(assetTokenNameAscii, depositAmt, orderType, lucid, sysPar
|
|
|
9060
9207
|
};
|
|
9061
9208
|
const depositVal = (0, import_ts_pattern20.match)(orderType).with(
|
|
9062
9209
|
{ BuyIAssetOrder: import_ts_pattern20.P.select() },
|
|
9063
|
-
(buyContent) => (0,
|
|
9210
|
+
(buyContent) => (0, import_cardano_offchain_common26.mkAssetsOf)(buyContent.collateralAsset, depositAmt)
|
|
9064
9211
|
).with(
|
|
9065
9212
|
{ SellIAssetOrder: import_ts_pattern20.P.any },
|
|
9066
|
-
(_2) => (0,
|
|
9213
|
+
(_2) => (0, import_cardano_offchain_common26.mkAssetsOf)(
|
|
9067
9214
|
{
|
|
9068
9215
|
currencySymbol: (0, import_lucid51.fromHex)(
|
|
9069
9216
|
sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol
|
|
@@ -9083,7 +9230,7 @@ async function openRob(assetTokenNameAscii, depositAmt, orderType, lucid, sysPar
|
|
|
9083
9230
|
kind: "inline",
|
|
9084
9231
|
value: serialiseRobDatum(newDatum)
|
|
9085
9232
|
},
|
|
9086
|
-
(0, import_lucid51.addAssets)(depositVal, (0,
|
|
9233
|
+
(0, import_lucid51.addAssets)(depositVal, (0, import_cardano_offchain_common26.mkLovelacesOf)(MIN_ROB_COLLATERAL_AMT))
|
|
9087
9234
|
);
|
|
9088
9235
|
}
|
|
9089
9236
|
async function cancelRob(robOutRef, sysParams, lucid) {
|
|
@@ -9206,17 +9353,17 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
|
|
|
9206
9353
|
tokenName: robDatum.iasset
|
|
9207
9354
|
};
|
|
9208
9355
|
const [depositAsset, rewardVal] = (0, import_ts_pattern20.match)(robDatum.orderType).returnType().with({ BuyIAssetOrder: import_ts_pattern20.P.select() }, (buyContent) => {
|
|
9209
|
-
const reward = (0,
|
|
9210
|
-
return [buyContent.collateralAsset, (0,
|
|
9356
|
+
const reward = (0, import_cardano_offchain_common26.assetClassValueOf)(robUtxo.assets, iassetAc);
|
|
9357
|
+
return [buyContent.collateralAsset, (0, import_cardano_offchain_common26.mkAssetsOf)(iassetAc, reward)];
|
|
9211
9358
|
}).with({ SellIAssetOrder: import_ts_pattern20.P.select() }, (content) => {
|
|
9212
|
-
const reward =
|
|
9359
|
+
const reward = import_fp_ts22.function.pipe(
|
|
9213
9360
|
content.allowedCollateralAssets,
|
|
9214
|
-
|
|
9361
|
+
import_fp_ts22.readonlyArray.reduce(
|
|
9215
9362
|
{},
|
|
9216
9363
|
(acc, [asset, _]) => {
|
|
9217
|
-
const amt = (0,
|
|
9218
|
-
((0,
|
|
9219
|
-
return (0, import_lucid51.addAssets)(acc, (0,
|
|
9364
|
+
const amt = (0, import_cardano_offchain_common26.assetClassValueOf)(robUtxo.assets, asset) - // in case of ADA, the min has to stay.
|
|
9365
|
+
((0, import_cardano_offchain_common26.isSameAssetClass)(asset, import_cardano_offchain_common26.adaAssetClass) ? MIN_ROB_COLLATERAL_AMT : 0n);
|
|
9366
|
+
return (0, import_lucid51.addAssets)(acc, (0, import_cardano_offchain_common26.mkAssetsOf)(asset, amt));
|
|
9220
9367
|
}
|
|
9221
9368
|
)
|
|
9222
9369
|
);
|
|
@@ -9249,12 +9396,12 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
|
|
|
9249
9396
|
return {
|
|
9250
9397
|
SellIAssetOrder: {
|
|
9251
9398
|
allowedCollateralAssets: content.allowedCollateralAssets.map(
|
|
9252
|
-
(entry) =>
|
|
9399
|
+
(entry) => import_fp_ts22.function.pipe(
|
|
9253
9400
|
newPrices,
|
|
9254
|
-
|
|
9255
|
-
(newPrice) => (0,
|
|
9401
|
+
import_fp_ts22.array.findFirst(
|
|
9402
|
+
(newPrice) => (0, import_cardano_offchain_common26.isSameAssetClass)(newPrice[0], entry[0])
|
|
9256
9403
|
),
|
|
9257
|
-
|
|
9404
|
+
import_fp_ts22.option.match(
|
|
9258
9405
|
() => entry,
|
|
9259
9406
|
(newPrice) => [
|
|
9260
9407
|
entry[0],
|
|
@@ -9270,8 +9417,8 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
|
|
|
9270
9417
|
},
|
|
9271
9418
|
(0, import_lucid51.addAssets)(
|
|
9272
9419
|
robUtxo.assets,
|
|
9273
|
-
(0,
|
|
9274
|
-
(0,
|
|
9420
|
+
(0, import_cardano_offchain_common26.mkAssetsOf)(depositAsset, adjustmentAmt),
|
|
9421
|
+
(0, import_cardano_offchain_common26.negateAssets)(rewardVal)
|
|
9275
9422
|
)
|
|
9276
9423
|
).addSignerKey((0, import_lucid51.toHex)(robDatum.owner));
|
|
9277
9424
|
}
|
|
@@ -9319,7 +9466,7 @@ var mkRobValidatorFromSP = (params) => {
|
|
|
9319
9466
|
var import_lucid53 = require("@lucid-evolution/lucid");
|
|
9320
9467
|
|
|
9321
9468
|
// src/contracts/rob-leverage/helpers.ts
|
|
9322
|
-
var
|
|
9469
|
+
var import_fp_ts23 = require("fp-ts");
|
|
9323
9470
|
var import_decimal2 = require("decimal.js");
|
|
9324
9471
|
var MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
|
|
9325
9472
|
function approximateLeverageRedemptions(baseCollateral, targetLeverage, redemptionReimbursementRatio, debtMintingFeeRatio) {
|
|
@@ -9345,9 +9492,9 @@ function approximateLeverageRedemptions(baseCollateral, targetLeverage, redempti
|
|
|
9345
9492
|
};
|
|
9346
9493
|
}
|
|
9347
9494
|
function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement, redemptionReimbursementRatio, iassetPrice, redemptionLrps) {
|
|
9348
|
-
const redemptionDetails =
|
|
9495
|
+
const redemptionDetails = import_fp_ts23.function.pipe(
|
|
9349
9496
|
redemptionLrps,
|
|
9350
|
-
|
|
9497
|
+
import_fp_ts23.array.reduce(
|
|
9351
9498
|
{
|
|
9352
9499
|
remainingCollateralToSpend: lovelacesForRedemptionWithReimbursement,
|
|
9353
9500
|
redemptions: []
|
|
@@ -9401,9 +9548,9 @@ function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursem
|
|
|
9401
9548
|
}
|
|
9402
9549
|
)
|
|
9403
9550
|
);
|
|
9404
|
-
const res =
|
|
9551
|
+
const res = import_fp_ts23.function.pipe(
|
|
9405
9552
|
redemptionDetails.redemptions,
|
|
9406
|
-
|
|
9553
|
+
import_fp_ts23.array.reduce(
|
|
9407
9554
|
{
|
|
9408
9555
|
redeemedCollateral: 0n,
|
|
9409
9556
|
payoutIAssets: 0n,
|
|
@@ -9496,7 +9643,7 @@ function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collatera
|
|
|
9496
9643
|
}
|
|
9497
9644
|
|
|
9498
9645
|
// src/contracts/rob-leverage/transactions.ts
|
|
9499
|
-
var
|
|
9646
|
+
var import_cardano_offchain_common27 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
9500
9647
|
var import_decimal3 = __toESM(require("decimal.js"));
|
|
9501
9648
|
async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, cdpCreatorOref, interestOracleOref, treasuryOref, sysParams, lucid, allRobs, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
|
|
9502
9649
|
const network = lucid.config().network;
|
|
@@ -9621,7 +9768,7 @@ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, i
|
|
|
9621
9768
|
mintedAmt
|
|
9622
9769
|
);
|
|
9623
9770
|
const collateralAmt = redemptionDetails.totalRedeemedCollateral + baseCollateral;
|
|
9624
|
-
const cdpNftVal = (0,
|
|
9771
|
+
const cdpNftVal = (0, import_cardano_offchain_common27.mkAssetsOf)(
|
|
9625
9772
|
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
9626
9773
|
1n
|
|
9627
9774
|
);
|
|
@@ -9631,7 +9778,7 @@ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, i
|
|
|
9631
9778
|
),
|
|
9632
9779
|
tokenName: iassetDatum.assetName
|
|
9633
9780
|
};
|
|
9634
|
-
const iassetTokensVal = (0,
|
|
9781
|
+
const iassetTokensVal = (0, import_cardano_offchain_common27.mkAssetsOf)(iassetClass, mintedAmt);
|
|
9635
9782
|
const refScripts = [
|
|
9636
9783
|
cdpCreatorRefScriptUtxo,
|
|
9637
9784
|
cdpAuthTokenPolicyRefScriptUtxo,
|
|
@@ -9660,7 +9807,7 @@ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, i
|
|
|
9660
9807
|
},
|
|
9661
9808
|
(0, import_lucid53.addAssets)(
|
|
9662
9809
|
cdpNftVal,
|
|
9663
|
-
(0,
|
|
9810
|
+
(0, import_cardano_offchain_common27.mkAssetsOf)(collateralAssetDatum.collateralAsset, collateralAmt)
|
|
9664
9811
|
)
|
|
9665
9812
|
).pay.ToContract(
|
|
9666
9813
|
cdpCreatorUtxo.address,
|
|
@@ -9770,7 +9917,7 @@ function mkPriceOracleValidator(params) {
|
|
|
9770
9917
|
}
|
|
9771
9918
|
|
|
9772
9919
|
// src/contracts/price-oracle/transactions.ts
|
|
9773
|
-
var
|
|
9920
|
+
var import_cardano_offchain_common28 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
9774
9921
|
var Core2 = __toESM(require("@evolution-sdk/evolution"));
|
|
9775
9922
|
async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, currentSlot, refOutRef, auxiliaryData) {
|
|
9776
9923
|
const network = lucid.config().network;
|
|
@@ -9803,7 +9950,7 @@ async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, cu
|
|
|
9803
9950
|
tx.pay.ToContract(
|
|
9804
9951
|
(0, import_lucid55.validatorToAddress)(lucid.config().network, oracleValidator),
|
|
9805
9952
|
{ kind: "inline", value: serialisePriceOracleDatum(oracleDatum) },
|
|
9806
|
-
(0, import_lucid55.addAssets)((0,
|
|
9953
|
+
(0, import_lucid55.addAssets)((0, import_cardano_offchain_common28.mkAssetsOf)(priceOracleNft, 1n))
|
|
9807
9954
|
);
|
|
9808
9955
|
return [tx, priceOracleNft];
|
|
9809
9956
|
}
|
|
@@ -9854,7 +10001,7 @@ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
|
|
|
9854
10001
|
|
|
9855
10002
|
// src/contracts/initialize/helpers.ts
|
|
9856
10003
|
var import_lucid60 = require("@lucid-evolution/lucid");
|
|
9857
|
-
var
|
|
10004
|
+
var import_cardano_offchain_common29 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
9858
10005
|
|
|
9859
10006
|
// src/scripts/auth-token-policy.ts
|
|
9860
10007
|
var import_lucid57 = require("@lucid-evolution/lucid");
|
|
@@ -9910,7 +10057,7 @@ var mkIAssetValidatorFromSP = (params) => {
|
|
|
9910
10057
|
var import_ts_pattern21 = require("ts-pattern");
|
|
9911
10058
|
|
|
9912
10059
|
// tests/test-helpers.ts
|
|
9913
|
-
var
|
|
10060
|
+
var import_fp_ts24 = require("fp-ts");
|
|
9914
10061
|
async function runAndAwaitTxBuilder(lucid, transaction, extraSigners = []) {
|
|
9915
10062
|
const bTx = await transaction.complete();
|
|
9916
10063
|
const signatures = [await bTx.partialSign.withWallet()];
|
|
@@ -10031,7 +10178,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
|
|
|
10031
10178
|
kind: "inline",
|
|
10032
10179
|
value: serialiseInterestCollectionDatum(interestCollectionAdminDatum)
|
|
10033
10180
|
},
|
|
10034
|
-
(0,
|
|
10181
|
+
(0, import_cardano_offchain_common29.mkAssetsOf)(multisigUtxoNft, 1n)
|
|
10035
10182
|
)
|
|
10036
10183
|
);
|
|
10037
10184
|
const interestCollectionUtxoDeploymentTx = lucid.newTx();
|
|
@@ -10039,7 +10186,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
|
|
|
10039
10186
|
interestCollectionUtxoDeploymentTx.pay.ToContract(
|
|
10040
10187
|
createScriptAddress(lucid.config().network, interestCollectionValHash),
|
|
10041
10188
|
void 0,
|
|
10042
|
-
(0,
|
|
10189
|
+
(0, import_cardano_offchain_common29.mkLovelacesOf)(interestCollectorUtxoLovelaces)
|
|
10043
10190
|
);
|
|
10044
10191
|
}
|
|
10045
10192
|
await submitTx(lucid, interestCollectionUtxoDeploymentTx);
|
|
@@ -10072,8 +10219,8 @@ async function initTreasury(lucid, treasuryParams, daoAsset, indyAsset, treasury
|
|
|
10072
10219
|
treasuryAddr,
|
|
10073
10220
|
{ kind: "inline", value: import_lucid60.Data.void() },
|
|
10074
10221
|
(0, import_lucid60.addAssets)(
|
|
10075
|
-
(0,
|
|
10076
|
-
(0,
|
|
10222
|
+
(0, import_cardano_offchain_common29.mkAssetsOf)(daoAsset, 1n),
|
|
10223
|
+
(0, import_cardano_offchain_common29.mkAssetsOf)(indyAsset, treasuryIndyAmount)
|
|
10077
10224
|
)
|
|
10078
10225
|
);
|
|
10079
10226
|
for (let i = 0; i < Number(numTreasuryCollectors); i++) {
|
|
@@ -10186,7 +10333,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10186
10333
|
CollateralAssetContent: collateralAssetContent
|
|
10187
10334
|
})
|
|
10188
10335
|
},
|
|
10189
|
-
(0,
|
|
10336
|
+
(0, import_cardano_offchain_common29.mkAssetsOf)(collateralAssetAuthToken, 1n)
|
|
10190
10337
|
);
|
|
10191
10338
|
await submitTx(lucid, collateralAssetTx);
|
|
10192
10339
|
collateralAssetInfos.push({
|
|
@@ -10221,7 +10368,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10221
10368
|
kind: "inline",
|
|
10222
10369
|
value: serialiseStableswapPoolDatum(stableswapPoolDatum)
|
|
10223
10370
|
},
|
|
10224
|
-
(0,
|
|
10371
|
+
(0, import_cardano_offchain_common29.mkAssetsOf)(cdpAuthToken, 1n)
|
|
10225
10372
|
)
|
|
10226
10373
|
);
|
|
10227
10374
|
}
|
|
@@ -10245,7 +10392,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10245
10392
|
kind: "inline",
|
|
10246
10393
|
value: serialiseIAssetDatum({ IAssetContent: iassetDatum })
|
|
10247
10394
|
},
|
|
10248
|
-
(0,
|
|
10395
|
+
(0, import_cardano_offchain_common29.mkAssetsOf)(iassetToken, 1n)
|
|
10249
10396
|
);
|
|
10250
10397
|
await submitTx(lucid, assetTx);
|
|
10251
10398
|
const stabilityPoolDatum = {
|
|
@@ -10264,7 +10411,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10264
10411
|
kind: "inline",
|
|
10265
10412
|
value: serialiseStabilityPoolDatum({ StabilityPool: stabilityPoolDatum })
|
|
10266
10413
|
},
|
|
10267
|
-
(0,
|
|
10414
|
+
(0, import_cardano_offchain_common29.mkAssetsOf)(stabilityPoolToken, 1n)
|
|
10268
10415
|
);
|
|
10269
10416
|
await submitTx(lucid, spTx);
|
|
10270
10417
|
return {
|
|
@@ -10286,7 +10433,7 @@ async function initGovernance(lucid, governanceParams, govToken, initialAssets,
|
|
|
10286
10433
|
type: "Script"
|
|
10287
10434
|
}),
|
|
10288
10435
|
{ kind: "inline", value: serialiseGovDatum(datum) },
|
|
10289
|
-
(0,
|
|
10436
|
+
(0, import_cardano_offchain_common29.mkAssetsOf)(govToken, 1n)
|
|
10290
10437
|
);
|
|
10291
10438
|
await submitTx(lucid, tx);
|
|
10292
10439
|
}
|
|
@@ -10294,7 +10441,7 @@ async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
|
|
|
10294
10441
|
const script = mkAuthTokenPolicy(asset, (0, import_lucid60.fromText)(tokenName));
|
|
10295
10442
|
const policyId = (0, import_lucid60.mintingPolicyToId)(script);
|
|
10296
10443
|
const address = await lucid.wallet().address();
|
|
10297
|
-
const utxos = (await lucid.utxosAtWithUnit(address, (0,
|
|
10444
|
+
const utxos = (await lucid.utxosAtWithUnit(address, (0, import_cardano_offchain_common29.assetClassToUnit)(asset))).filter((utxo2) => (0, import_cardano_offchain_common29.assetClassValueOf)(utxo2.assets, asset) === 1n).sort((a, b) => Number((0, import_cardano_offchain_common29.lovelacesAmt)(b.assets) - (0, import_cardano_offchain_common29.lovelacesAmt)(a.assets)));
|
|
10298
10445
|
if (utxos.length === 0) {
|
|
10299
10446
|
throw new Error("No utxos found");
|
|
10300
10447
|
}
|
|
@@ -10310,7 +10457,7 @@ async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
|
|
|
10310
10457
|
|
|
10311
10458
|
// src/contracts/initialize/actions.ts
|
|
10312
10459
|
var import_lucid65 = require("@lucid-evolution/lucid");
|
|
10313
|
-
var
|
|
10460
|
+
var import_cardano_offchain_common31 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
10314
10461
|
|
|
10315
10462
|
// src/scripts/iasset-policy.ts
|
|
10316
10463
|
var import_lucid61 = require("@lucid-evolution/lucid");
|
|
@@ -10415,7 +10562,7 @@ var alwaysSucceedValidator = {
|
|
|
10415
10562
|
};
|
|
10416
10563
|
|
|
10417
10564
|
// tests/pyth/endpoints.ts
|
|
10418
|
-
var
|
|
10565
|
+
var import_cardano_offchain_common30 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
10419
10566
|
var TEST_TRUSTED_SIGNER_PUB_KEY = "4a50d7c3d16b2be5c16ba996109a455a34cce08a81b3e15b86ef407e2f72e71f";
|
|
10420
10567
|
async function initPyth(lucid) {
|
|
10421
10568
|
const pythStateName = (0, import_lucid64.fromText)("Pyth State");
|
|
@@ -10467,7 +10614,7 @@ async function initPyth(lucid) {
|
|
|
10467
10614
|
type: "Script"
|
|
10468
10615
|
}),
|
|
10469
10616
|
{ kind: "inline", value: serialisePythStateDatum(pythStateDatum) },
|
|
10470
|
-
(0,
|
|
10617
|
+
(0, import_cardano_offchain_common30.mkAssetsOf)(pythStateAsset, 1n),
|
|
10471
10618
|
alwaysSucceedValidator
|
|
10472
10619
|
)
|
|
10473
10620
|
);
|
|
@@ -10516,7 +10663,9 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
|
|
|
10516
10663
|
);
|
|
10517
10664
|
} catch (error) {
|
|
10518
10665
|
const message = error instanceof Error ? error.message : String(error);
|
|
10519
|
-
if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes(
|
|
10666
|
+
if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes(
|
|
10667
|
+
"Trying to re-register some already known credentials."
|
|
10668
|
+
)) {
|
|
10520
10669
|
throw error;
|
|
10521
10670
|
}
|
|
10522
10671
|
}
|
|
@@ -10710,7 +10859,10 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
10710
10859
|
(0, import_lucid65.scriptHashToCredential)(cdpRedeemValHash)
|
|
10711
10860
|
);
|
|
10712
10861
|
try {
|
|
10713
|
-
await runAndAwaitTxBuilder(
|
|
10862
|
+
await runAndAwaitTxBuilder(
|
|
10863
|
+
lucid,
|
|
10864
|
+
lucid.newTx().register.Stake(cdpRedeemRewardAddr)
|
|
10865
|
+
);
|
|
10714
10866
|
} catch (error) {
|
|
10715
10867
|
const message = error instanceof Error ? error.message : String(error);
|
|
10716
10868
|
if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes("Trying to re-register some already known credentials.")) {
|
|
@@ -10785,8 +10937,8 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
10785
10937
|
lucid.newTx().pay.ToAddress(
|
|
10786
10938
|
await lucid.wallet().address(),
|
|
10787
10939
|
(0, import_lucid65.addAssets)(
|
|
10788
|
-
(0,
|
|
10789
|
-
(0,
|
|
10940
|
+
(0, import_cardano_offchain_common31.mkAssetsOf)(iassetToken, 1n),
|
|
10941
|
+
(0, import_cardano_offchain_common31.mkLovelacesOf)(BigInt(totalCollateralAssetsCount) * 5000000n)
|
|
10790
10942
|
)
|
|
10791
10943
|
)
|
|
10792
10944
|
);
|
|
@@ -10803,8 +10955,8 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
10803
10955
|
lucid.newTx().pay.ToAddress(
|
|
10804
10956
|
await lucid.wallet().address(),
|
|
10805
10957
|
(0, import_lucid65.addAssets)(
|
|
10806
|
-
(0,
|
|
10807
|
-
(0,
|
|
10958
|
+
(0, import_cardano_offchain_common31.mkAssetsOf)(cdpCreatorAsset, 1n),
|
|
10959
|
+
(0, import_cardano_offchain_common31.mkLovelacesOf)(BigInt(totalStablePoolsCount) * 5000000n)
|
|
10808
10960
|
)
|
|
10809
10961
|
)
|
|
10810
10962
|
);
|
|
@@ -11083,20 +11235,87 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
11083
11235
|
return [sysParams, assetInfos];
|
|
11084
11236
|
}
|
|
11085
11237
|
|
|
11086
|
-
// src/contracts/
|
|
11238
|
+
// src/contracts/iasset/queries.ts
|
|
11087
11239
|
var import_lucid66 = require("@lucid-evolution/lucid");
|
|
11240
|
+
var import_cardano_offchain_common32 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
11241
|
+
var import_fp_ts25 = require("fp-ts");
|
|
11242
|
+
async function findIAsset(lucid, sysParams, iassetName) {
|
|
11243
|
+
const iassetUtxos = await lucid.utxosAtWithUnit(
|
|
11244
|
+
createScriptAddress(
|
|
11245
|
+
lucid.config().network,
|
|
11246
|
+
sysParams.validatorHashes.iassetHash
|
|
11247
|
+
),
|
|
11248
|
+
(0, import_cardano_offchain_common32.assetClassToUnit)(
|
|
11249
|
+
fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken)
|
|
11250
|
+
)
|
|
11251
|
+
);
|
|
11252
|
+
return (0, import_cardano_offchain_common32.matchSingle)(
|
|
11253
|
+
import_fp_ts25.function.pipe(
|
|
11254
|
+
iassetUtxos.map(
|
|
11255
|
+
(utxo) => import_fp_ts25.function.pipe(
|
|
11256
|
+
import_fp_ts25.option.fromNullable(utxo.datum),
|
|
11257
|
+
import_fp_ts25.option.flatMap(parseIAssetDatum),
|
|
11258
|
+
import_fp_ts25.option.flatMap((datum) => {
|
|
11259
|
+
if ((0, import_lucid66.toHex)(datum.assetName) === (0, import_lucid66.toHex)(iassetName)) {
|
|
11260
|
+
return import_fp_ts25.option.some({ utxo, datum });
|
|
11261
|
+
} else {
|
|
11262
|
+
return import_fp_ts25.option.none;
|
|
11263
|
+
}
|
|
11264
|
+
})
|
|
11265
|
+
)
|
|
11266
|
+
),
|
|
11267
|
+
import_fp_ts25.array.compact
|
|
11268
|
+
),
|
|
11269
|
+
(res) => new Error("Expected a single IAsset UTXO.: " + JSON.stringify(res))
|
|
11270
|
+
);
|
|
11271
|
+
}
|
|
11272
|
+
async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset) {
|
|
11273
|
+
const collateralAssetUtxos = await lucid.utxosAtWithUnit(
|
|
11274
|
+
createScriptAddress(
|
|
11275
|
+
lucid.config().network,
|
|
11276
|
+
sysParams.validatorHashes.iassetHash
|
|
11277
|
+
),
|
|
11278
|
+
(0, import_cardano_offchain_common32.assetClassToUnit)(
|
|
11279
|
+
fromSystemParamsAsset(sysParams.cdpParams.collateralAssetAuthToken)
|
|
11280
|
+
)
|
|
11281
|
+
);
|
|
11282
|
+
return (0, import_cardano_offchain_common32.matchSingle)(
|
|
11283
|
+
import_fp_ts25.function.pipe(
|
|
11284
|
+
collateralAssetUtxos.map(
|
|
11285
|
+
(utxo) => import_fp_ts25.function.pipe(
|
|
11286
|
+
import_fp_ts25.option.fromNullable(utxo.datum),
|
|
11287
|
+
import_fp_ts25.option.flatMap(parseCollateralAssetDatum),
|
|
11288
|
+
import_fp_ts25.option.flatMap((datum) => {
|
|
11289
|
+
if ((0, import_cardano_offchain_common32.isSameAssetClass)(datum.collateralAsset, collateralAsset) && (0, import_lucid66.toHex)(iassetName) === (0, import_lucid66.toHex)(datum.iasset)) {
|
|
11290
|
+
return import_fp_ts25.option.some({ utxo, datum });
|
|
11291
|
+
} else {
|
|
11292
|
+
return import_fp_ts25.option.none;
|
|
11293
|
+
}
|
|
11294
|
+
})
|
|
11295
|
+
)
|
|
11296
|
+
),
|
|
11297
|
+
import_fp_ts25.array.compact
|
|
11298
|
+
),
|
|
11299
|
+
(res) => new Error(
|
|
11300
|
+
"Expected a single Collateral Asset UTXO.: " + JSON.stringify(res)
|
|
11301
|
+
)
|
|
11302
|
+
);
|
|
11303
|
+
}
|
|
11304
|
+
|
|
11305
|
+
// src/contracts/stableswap/helpers.ts
|
|
11306
|
+
var import_lucid67 = require("@lucid-evolution/lucid");
|
|
11088
11307
|
|
|
11089
11308
|
// src/contracts/stableswap/types-new.ts
|
|
11090
|
-
var
|
|
11309
|
+
var import_cardano_offchain_common33 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
11091
11310
|
var import_evolution20 = require("@evolution-sdk/evolution");
|
|
11092
|
-
var
|
|
11311
|
+
var import_fp_ts26 = require("fp-ts");
|
|
11093
11312
|
var import_effect3 = require("effect");
|
|
11094
11313
|
var OpaqueData4 = import_effect3.Schema.typeSchema(import_evolution20.Data.DataSchema);
|
|
11095
11314
|
var StableswapOrderDatumSchema = import_evolution20.TSchema.Struct({
|
|
11096
11315
|
iasset: import_evolution20.TSchema.ByteArray,
|
|
11097
|
-
collateralAsset:
|
|
11316
|
+
collateralAsset: import_cardano_offchain_common33.AssetClassSchema,
|
|
11098
11317
|
owner: import_evolution20.TSchema.ByteArray,
|
|
11099
|
-
destination:
|
|
11318
|
+
destination: import_cardano_offchain_common33.AddressSchema,
|
|
11100
11319
|
destinationInlineDatum: import_evolution20.TSchema.NullOr(OpaqueData4),
|
|
11101
11320
|
maxExecutionFee: import_evolution20.TSchema.Integer,
|
|
11102
11321
|
maxFeeRatio: RationalSchema
|
|
@@ -11121,7 +11340,7 @@ var StableswapOrderRedeemerSchema = import_evolution20.TSchema.Union(
|
|
|
11121
11340
|
);
|
|
11122
11341
|
var StableswapOutputDatumSchema = import_evolution20.TSchema.Tuple([
|
|
11123
11342
|
import_evolution20.TSchema.ByteArray,
|
|
11124
|
-
|
|
11343
|
+
import_cardano_offchain_common33.OutputReferenceSchema
|
|
11125
11344
|
]);
|
|
11126
11345
|
function serialiseStableswapOrderDatum(d) {
|
|
11127
11346
|
return import_evolution20.Data.withSchema(
|
|
@@ -11131,22 +11350,22 @@ function serialiseStableswapOrderDatum(d) {
|
|
|
11131
11350
|
}
|
|
11132
11351
|
function parseStableswapOrderDatum(datum) {
|
|
11133
11352
|
try {
|
|
11134
|
-
return
|
|
11353
|
+
return import_fp_ts26.option.some(
|
|
11135
11354
|
import_evolution20.Data.withSchema(
|
|
11136
11355
|
StableswapOrderDatumSchema,
|
|
11137
11356
|
DEFAULT_SCHEMA_OPTIONS
|
|
11138
11357
|
).fromCBORHex(datum)
|
|
11139
11358
|
);
|
|
11140
11359
|
} catch (_) {
|
|
11141
|
-
return
|
|
11360
|
+
return import_fp_ts26.option.none;
|
|
11142
11361
|
}
|
|
11143
11362
|
}
|
|
11144
11363
|
function parseStableswapOrderDatumOrThrow(datum) {
|
|
11145
|
-
return
|
|
11364
|
+
return import_fp_ts26.function.pipe(
|
|
11146
11365
|
parseStableswapOrderDatum(datum),
|
|
11147
|
-
|
|
11366
|
+
import_fp_ts26.option.match(() => {
|
|
11148
11367
|
throw new Error("Expected a Stableswap Order datum.");
|
|
11149
|
-
},
|
|
11368
|
+
}, import_fp_ts26.function.identity)
|
|
11150
11369
|
);
|
|
11151
11370
|
}
|
|
11152
11371
|
function serialiseStableswapOutputDatum(d) {
|
|
@@ -11163,22 +11382,22 @@ function serialiseStableswapOrderRedeemer(r) {
|
|
|
11163
11382
|
}
|
|
11164
11383
|
function parseStableswapOrderRedeemer(redeemerCborHex) {
|
|
11165
11384
|
try {
|
|
11166
|
-
return
|
|
11385
|
+
return import_fp_ts26.option.some(
|
|
11167
11386
|
import_evolution20.Data.withSchema(
|
|
11168
11387
|
StableswapOrderRedeemerSchema,
|
|
11169
11388
|
DEFAULT_SCHEMA_OPTIONS
|
|
11170
11389
|
).fromCBORHex(redeemerCborHex)
|
|
11171
11390
|
);
|
|
11172
11391
|
} catch (_) {
|
|
11173
|
-
return
|
|
11392
|
+
return import_fp_ts26.option.none;
|
|
11174
11393
|
}
|
|
11175
11394
|
}
|
|
11176
11395
|
function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
|
|
11177
|
-
return
|
|
11396
|
+
return import_fp_ts26.function.pipe(
|
|
11178
11397
|
parseStableswapOrderRedeemer(redeemerCborHex),
|
|
11179
|
-
|
|
11398
|
+
import_fp_ts26.option.match(() => {
|
|
11180
11399
|
throw new Error("Expected a Stableswap Order redeemer.");
|
|
11181
|
-
},
|
|
11400
|
+
}, import_fp_ts26.function.identity)
|
|
11182
11401
|
);
|
|
11183
11402
|
}
|
|
11184
11403
|
|
|
@@ -11188,9 +11407,9 @@ var BASE_MAX_EXECUTION_FEE = 1620000n;
|
|
|
11188
11407
|
function createDestinationDatum(datum, outRef) {
|
|
11189
11408
|
if (!datum) {
|
|
11190
11409
|
return serialiseStableswapOutputDatum([
|
|
11191
|
-
(0,
|
|
11410
|
+
(0, import_lucid67.fromHex)((0, import_lucid67.fromText)("IndigoStableswap")),
|
|
11192
11411
|
{
|
|
11193
|
-
txHash: (0,
|
|
11412
|
+
txHash: (0, import_lucid67.fromHex)(outRef.txHash),
|
|
11194
11413
|
outputIndex: BigInt(outRef.outputIndex)
|
|
11195
11414
|
}
|
|
11196
11415
|
]);
|
|
@@ -11199,28 +11418,28 @@ function createDestinationDatum(datum, outRef) {
|
|
|
11199
11418
|
}
|
|
11200
11419
|
|
|
11201
11420
|
// src/contracts/stableswap/transactions.ts
|
|
11202
|
-
var
|
|
11203
|
-
var
|
|
11204
|
-
var
|
|
11421
|
+
var import_lucid68 = require("@lucid-evolution/lucid");
|
|
11422
|
+
var import_cardano_offchain_common34 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
11423
|
+
var import_fp_ts27 = require("fp-ts");
|
|
11205
11424
|
var import_Array3 = require("fp-ts/lib/Array");
|
|
11206
11425
|
async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
|
|
11207
11426
|
const myAddress = await lucid.wallet().address();
|
|
11208
|
-
const pkh = (0,
|
|
11427
|
+
const pkh = (0, import_lucid68.paymentCredentialOf)(myAddress);
|
|
11209
11428
|
const datum = {
|
|
11210
|
-
iasset: (0,
|
|
11429
|
+
iasset: (0, import_lucid68.fromHex)((0, import_lucid68.fromText)(iasset)),
|
|
11211
11430
|
collateralAsset,
|
|
11212
|
-
owner: (0,
|
|
11213
|
-
destination: (0,
|
|
11431
|
+
owner: (0, import_lucid68.fromHex)(pkh.hash),
|
|
11432
|
+
destination: (0, import_cardano_offchain_common34.addressFromBech32)(destinationAddress ?? myAddress),
|
|
11214
11433
|
destinationInlineDatum: destinationInlineDatum ?? null,
|
|
11215
11434
|
maxExecutionFee,
|
|
11216
11435
|
maxFeeRatio: maxFeeRatio ?? (minting ? poolDatum.mintingFeeRatio : poolDatum.redemptionFeeRatio)
|
|
11217
11436
|
};
|
|
11218
|
-
const assetsToSwap = minting ? (0,
|
|
11437
|
+
const assetsToSwap = minting ? (0, import_cardano_offchain_common34.mkAssetsOf)(collateralAsset, amount) : (0, import_cardano_offchain_common34.mkAssetsOf)(
|
|
11219
11438
|
{
|
|
11220
|
-
currencySymbol: (0,
|
|
11439
|
+
currencySymbol: (0, import_lucid68.fromHex)(
|
|
11221
11440
|
params.stableswapParams.iassetSymbol.unCurrencySymbol
|
|
11222
11441
|
),
|
|
11223
|
-
tokenName: (0,
|
|
11442
|
+
tokenName: (0, import_lucid68.fromHex)((0, import_lucid68.fromText)(iasset))
|
|
11224
11443
|
},
|
|
11225
11444
|
amount
|
|
11226
11445
|
);
|
|
@@ -11238,7 +11457,7 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
|
|
|
11238
11457
|
);
|
|
11239
11458
|
const roundedExpectedOutputLovelaces = (expectedOutputLovelaces / 1000000n + 1n) * 1000000n;
|
|
11240
11459
|
return lucid.newTx().pay.ToContract(
|
|
11241
|
-
(0,
|
|
11460
|
+
(0, import_lucid68.credentialToAddress)(lucid.config().network, {
|
|
11242
11461
|
hash: params.validatorHashes.stableswapHash,
|
|
11243
11462
|
type: "Script"
|
|
11244
11463
|
}),
|
|
@@ -11246,16 +11465,16 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
|
|
|
11246
11465
|
kind: "inline",
|
|
11247
11466
|
value: serialiseStableswapOrderDatum(datum)
|
|
11248
11467
|
},
|
|
11249
|
-
(0,
|
|
11468
|
+
(0, import_lucid68.addAssets)(
|
|
11250
11469
|
assetsToSwap,
|
|
11251
|
-
(0,
|
|
11470
|
+
(0, import_cardano_offchain_common34.mkLovelacesOf)(
|
|
11252
11471
|
roundedExpectedOutputLovelaces + maxExecutionFee + additionalLovelaces
|
|
11253
11472
|
)
|
|
11254
11473
|
)
|
|
11255
11474
|
);
|
|
11256
11475
|
}
|
|
11257
11476
|
async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
|
|
11258
|
-
const stableswapScriptRefUtxo = (0,
|
|
11477
|
+
const stableswapScriptRefUtxo = (0, import_cardano_offchain_common34.matchSingle)(
|
|
11259
11478
|
await lucid.utxosByOutRef([
|
|
11260
11479
|
fromSystemParamsScriptRef(
|
|
11261
11480
|
sysParams.scriptReferences.stableswapValidatorRef
|
|
@@ -11263,20 +11482,20 @@ async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
|
|
|
11263
11482
|
]),
|
|
11264
11483
|
(_) => new Error("Expected a single Stableswap Ref Script UTXO")
|
|
11265
11484
|
);
|
|
11266
|
-
const stableswapOrderUtxo = (0,
|
|
11485
|
+
const stableswapOrderUtxo = (0, import_cardano_offchain_common34.matchSingle)(
|
|
11267
11486
|
await lucid.utxosByOutRef([stableswapOrderOref]),
|
|
11268
11487
|
(_) => new Error("Expected a single Stableswap Order UTXO.")
|
|
11269
11488
|
);
|
|
11270
11489
|
const stableswapOrderDatum = parseStableswapOrderDatumOrThrow(
|
|
11271
|
-
(0,
|
|
11490
|
+
(0, import_cardano_offchain_common34.getInlineDatumOrThrow)(stableswapOrderUtxo)
|
|
11272
11491
|
);
|
|
11273
11492
|
return lucid.newTx().readFrom([stableswapScriptRefUtxo]).collectFrom(
|
|
11274
11493
|
[stableswapOrderUtxo],
|
|
11275
11494
|
serialiseStableswapOrderRedeemer("CancelStableswapOrder")
|
|
11276
|
-
).addSignerKey((0,
|
|
11495
|
+
).addSignerKey((0, import_lucid68.toHex)(stableswapOrderDatum.owner));
|
|
11277
11496
|
}
|
|
11278
11497
|
async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPoolOref, treasuryOref, sysParams, lucid) {
|
|
11279
|
-
const stableswapScriptRefUtxo = (0,
|
|
11498
|
+
const stableswapScriptRefUtxo = (0, import_cardano_offchain_common34.matchSingle)(
|
|
11280
11499
|
await lucid.utxosByOutRef([
|
|
11281
11500
|
fromSystemParamsScriptRef(
|
|
11282
11501
|
sysParams.scriptReferences.stableswapValidatorRef
|
|
@@ -11284,13 +11503,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11284
11503
|
]),
|
|
11285
11504
|
(_) => new Error("Expected a single Stableswap Ref Script UTXO")
|
|
11286
11505
|
);
|
|
11287
|
-
const cdpScriptRefUtxo = (0,
|
|
11506
|
+
const cdpScriptRefUtxo = (0, import_cardano_offchain_common34.matchSingle)(
|
|
11288
11507
|
await lucid.utxosByOutRef([
|
|
11289
11508
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
11290
11509
|
]),
|
|
11291
11510
|
(_) => new Error("Expected a single CDP Ref Script UTXO")
|
|
11292
11511
|
);
|
|
11293
|
-
const iAssetTokenPolicyRefScriptUtxo = (0,
|
|
11512
|
+
const iAssetTokenPolicyRefScriptUtxo = (0, import_cardano_offchain_common34.matchSingle)(
|
|
11294
11513
|
await lucid.utxosByOutRef([
|
|
11295
11514
|
fromSystemParamsScriptRef(
|
|
11296
11515
|
sysParams.scriptReferences.iAssetTokenPolicyRef
|
|
@@ -11302,7 +11521,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11302
11521
|
throw new Error("At least one order must be provided.");
|
|
11303
11522
|
}
|
|
11304
11523
|
const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
|
|
11305
|
-
const sortedStableswapOrderUtxos = (0,
|
|
11524
|
+
const sortedStableswapOrderUtxos = (0, import_lucid68.sortUTxOs)(
|
|
11306
11525
|
stableswapOrderUtxos,
|
|
11307
11526
|
"Canonical"
|
|
11308
11527
|
);
|
|
@@ -11311,32 +11530,32 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11311
11530
|
}
|
|
11312
11531
|
const mainOrderUtxo = sortedStableswapOrderUtxos[0];
|
|
11313
11532
|
const mainOrderDatum = parseStableswapOrderDatumOrThrow(
|
|
11314
|
-
(0,
|
|
11533
|
+
(0, import_cardano_offchain_common34.getInlineDatumOrThrow)(mainOrderUtxo)
|
|
11315
11534
|
);
|
|
11316
11535
|
const iassetAc = {
|
|
11317
|
-
currencySymbol: (0,
|
|
11536
|
+
currencySymbol: (0, import_lucid68.fromHex)(
|
|
11318
11537
|
sysParams.stableswapParams.iassetSymbol.unCurrencySymbol
|
|
11319
11538
|
),
|
|
11320
11539
|
tokenName: mainOrderDatum.iasset
|
|
11321
11540
|
};
|
|
11322
11541
|
const collateralAc = mainOrderDatum.collateralAsset;
|
|
11323
|
-
const stableswapPoolUtxo = (0,
|
|
11542
|
+
const stableswapPoolUtxo = (0, import_cardano_offchain_common34.matchSingle)(
|
|
11324
11543
|
await lucid.utxosByOutRef([stableswapPoolOref]),
|
|
11325
11544
|
(_) => new Error("Expected a single cdp UTXO")
|
|
11326
11545
|
);
|
|
11327
11546
|
const stableswapPoolDatum = parseStableswapPoolDatumOrThrow(
|
|
11328
|
-
(0,
|
|
11547
|
+
(0, import_cardano_offchain_common34.getInlineDatumOrThrow)(stableswapPoolUtxo)
|
|
11329
11548
|
);
|
|
11330
11549
|
const ordersInfo = sortedStableswapOrderUtxos.map(
|
|
11331
11550
|
(orderUtxo) => {
|
|
11332
11551
|
const orderDatum = parseStableswapOrderDatumOrThrow(
|
|
11333
|
-
(0,
|
|
11552
|
+
(0, import_cardano_offchain_common34.getInlineDatumOrThrow)(orderUtxo)
|
|
11334
11553
|
);
|
|
11335
|
-
if ((0,
|
|
11554
|
+
if ((0, import_lucid68.toHex)(orderDatum.iasset) != (0, import_lucid68.toHex)(mainOrderDatum.iasset) || (0, import_lucid68.toHex)(orderDatum.collateralAsset.currencySymbol) != (0, import_lucid68.toHex)(mainOrderDatum.collateralAsset.currencySymbol) || (0, import_lucid68.toHex)(orderDatum.collateralAsset.tokenName) != (0, import_lucid68.toHex)(mainOrderDatum.collateralAsset.tokenName)) {
|
|
11336
11555
|
throw new Error("Wrong batch of orders");
|
|
11337
11556
|
}
|
|
11338
|
-
const suppliedIasset = (0,
|
|
11339
|
-
const suppliedCollateralAsset = (0,
|
|
11557
|
+
const suppliedIasset = (0, import_cardano_offchain_common34.assetClassValueOf)(orderUtxo.assets, iassetAc);
|
|
11558
|
+
const suppliedCollateralAsset = (0, import_cardano_offchain_common34.assetClassValueOf)(
|
|
11340
11559
|
orderUtxo.assets,
|
|
11341
11560
|
collateralAc
|
|
11342
11561
|
);
|
|
@@ -11460,9 +11679,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11460
11679
|
}
|
|
11461
11680
|
}
|
|
11462
11681
|
);
|
|
11463
|
-
const totalSwapInfo =
|
|
11682
|
+
const totalSwapInfo = import_fp_ts27.function.pipe(
|
|
11464
11683
|
ordersInfo,
|
|
11465
|
-
|
|
11684
|
+
import_fp_ts27.array.reduce(
|
|
11466
11685
|
{
|
|
11467
11686
|
suppliedCollateralAsset: 0n,
|
|
11468
11687
|
suppliedIasset: 0n,
|
|
@@ -11504,20 +11723,20 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11504
11723
|
kind: "inline",
|
|
11505
11724
|
value: serialiseStableswapPoolDatum(stableswapPoolDatum)
|
|
11506
11725
|
},
|
|
11507
|
-
collateralAmtChangePool != 0n ? (0,
|
|
11726
|
+
collateralAmtChangePool != 0n ? (0, import_lucid68.addAssets)(
|
|
11508
11727
|
stableswapPoolUtxo.assets,
|
|
11509
|
-
(0,
|
|
11728
|
+
(0, import_cardano_offchain_common34.mkAssetsOf)(collateralAc, collateralAmtChangePool)
|
|
11510
11729
|
) : stableswapPoolUtxo.assets
|
|
11511
11730
|
).setMinFee(stableswapOrderOrefs.length > 1 ? 1498875n : 1030000n);
|
|
11512
11731
|
if (amountToMint !== 0n) {
|
|
11513
|
-
tx.mintAssets((0,
|
|
11732
|
+
tx.mintAssets((0, import_cardano_offchain_common34.mkAssetsOf)(iassetAc, amountToMint), import_lucid68.Data.void());
|
|
11514
11733
|
}
|
|
11515
|
-
|
|
11734
|
+
import_fp_ts27.function.pipe(
|
|
11516
11735
|
ordersInfo,
|
|
11517
|
-
|
|
11736
|
+
import_fp_ts27.array.reduce(tx, (acc, orderInfo) => {
|
|
11518
11737
|
return acc.collectFrom(
|
|
11519
11738
|
[orderInfo.utxo],
|
|
11520
|
-
(0,
|
|
11739
|
+
(0, import_cardano_offchain_common34.isSameOutRef)(orderInfo.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
|
|
11521
11740
|
kind: "selected",
|
|
11522
11741
|
makeRedeemer: (inputIndices) => {
|
|
11523
11742
|
return serialiseStableswapOrderRedeemer({
|
|
@@ -11530,7 +11749,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11530
11749
|
inputs: [orderInfo.utxo, mainOrderUtxo]
|
|
11531
11750
|
}
|
|
11532
11751
|
).pay.ToAddressWithData(
|
|
11533
|
-
(0,
|
|
11752
|
+
(0, import_cardano_offchain_common34.addressToBech32)(orderInfo.datum.destination, lucid.config().network),
|
|
11534
11753
|
{
|
|
11535
11754
|
kind: "inline",
|
|
11536
11755
|
value: createDestinationDatum(
|
|
@@ -11538,13 +11757,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11538
11757
|
orderInfo.utxo
|
|
11539
11758
|
)
|
|
11540
11759
|
},
|
|
11541
|
-
(0,
|
|
11760
|
+
(0, import_lucid68.addAssets)(
|
|
11542
11761
|
// Currently, we always take the max execution fee from the order utxo.
|
|
11543
11762
|
// This can be improved so that we take the actual execution fee.
|
|
11544
|
-
(0,
|
|
11545
|
-
(0,
|
|
11763
|
+
(0, import_cardano_offchain_common34.mkLovelacesOf)(
|
|
11764
|
+
(0, import_cardano_offchain_common34.lovelacesAmt)(orderInfo.utxo.assets) - orderInfo.datum.maxExecutionFee
|
|
11546
11765
|
),
|
|
11547
|
-
orderInfo.swapInfo.owedIasset > 0 ? (0,
|
|
11766
|
+
orderInfo.swapInfo.owedIasset > 0 ? (0, import_cardano_offchain_common34.mkAssetsOf)(iassetAc, orderInfo.swapInfo.owedIasset) : (0, import_cardano_offchain_common34.mkAssetsOf)(
|
|
11548
11767
|
collateralAc,
|
|
11549
11768
|
orderInfo.swapInfo.owedCollateralAsset
|
|
11550
11769
|
)
|
|
@@ -11567,7 +11786,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11567
11786
|
return tx;
|
|
11568
11787
|
}
|
|
11569
11788
|
async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRef, newMintingFeeRatio, newRedemptionFeeRatio, sysParams, lucid) {
|
|
11570
|
-
const stableswapScriptRefUtxo = (0,
|
|
11789
|
+
const stableswapScriptRefUtxo = (0, import_cardano_offchain_common34.matchSingle)(
|
|
11571
11790
|
await lucid.utxosByOutRef([
|
|
11572
11791
|
fromSystemParamsScriptRef(
|
|
11573
11792
|
sysParams.scriptReferences.stableswapValidatorRef
|
|
@@ -11575,22 +11794,22 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
11575
11794
|
]),
|
|
11576
11795
|
(_) => new Error("Expected a single Stableswap Ref Script UTXO")
|
|
11577
11796
|
);
|
|
11578
|
-
const cdpScriptRefUtxo = (0,
|
|
11797
|
+
const cdpScriptRefUtxo = (0, import_cardano_offchain_common34.matchSingle)(
|
|
11579
11798
|
await lucid.utxosByOutRef([
|
|
11580
11799
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
11581
11800
|
]),
|
|
11582
11801
|
(_) => new Error("Expected a single CDP Ref Script UTXO")
|
|
11583
11802
|
);
|
|
11584
|
-
const stableswapPool = (0,
|
|
11803
|
+
const stableswapPool = (0, import_cardano_offchain_common34.matchSingle)(
|
|
11585
11804
|
await lucid.utxosByOutRef([stableswapPoolOutRef]),
|
|
11586
11805
|
(_) => new Error("Expected a single Stableswap Pool UTXO.")
|
|
11587
11806
|
);
|
|
11588
|
-
const stableswapFeeUtxo = (0,
|
|
11807
|
+
const stableswapFeeUtxo = (0, import_cardano_offchain_common34.matchSingle)(
|
|
11589
11808
|
await lucid.utxosByOutRef([stableswapFeeOutRef]),
|
|
11590
11809
|
(_) => new Error("Expected a single Stableswap Fee UTXO.")
|
|
11591
11810
|
);
|
|
11592
11811
|
const stableswapPoolDatum = parseStableswapPoolDatumOrThrow(
|
|
11593
|
-
(0,
|
|
11812
|
+
(0, import_cardano_offchain_common34.getInlineDatumOrThrow)(stableswapPool)
|
|
11594
11813
|
);
|
|
11595
11814
|
const newStableswapPoolDatum = {
|
|
11596
11815
|
...stableswapPoolDatum,
|
|
@@ -11618,7 +11837,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
11618
11837
|
value: serialiseStableswapPoolDatum(newStableswapPoolDatum)
|
|
11619
11838
|
},
|
|
11620
11839
|
stableswapPool.assets
|
|
11621
|
-
).addSignerKey((0,
|
|
11840
|
+
).addSignerKey((0, import_lucid68.toHex)(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
|
|
11622
11841
|
}
|
|
11623
11842
|
// Annotate the CommonJS export names for ESM import in node:
|
|
11624
11843
|
0 && (module.exports = {
|
|
@@ -11728,6 +11947,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
11728
11947
|
closeCdp,
|
|
11729
11948
|
closeStakingPosition,
|
|
11730
11949
|
collectInterestTx,
|
|
11950
|
+
collectPriceFeedIds,
|
|
11731
11951
|
collectorFeeTx,
|
|
11732
11952
|
createDestinationDatum,
|
|
11733
11953
|
createE2s2sSnapshots,
|
|
@@ -11740,6 +11960,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
11740
11960
|
decodePythMessage,
|
|
11741
11961
|
depositCdp,
|
|
11742
11962
|
deriveAuthToken,
|
|
11963
|
+
derivePythPrice,
|
|
11743
11964
|
distributeAda,
|
|
11744
11965
|
distributeInterest,
|
|
11745
11966
|
distributeReward,
|
|
@@ -11752,6 +11973,17 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
11752
11973
|
executeProposal,
|
|
11753
11974
|
feedInterestOracle,
|
|
11754
11975
|
feedPriceOracleTx,
|
|
11976
|
+
findAdminInterestCollectors,
|
|
11977
|
+
findAllInterestCollectors,
|
|
11978
|
+
findAllTreasuryUtxos,
|
|
11979
|
+
findAllTreasuryUtxosWithNonAdaAsset,
|
|
11980
|
+
findCollateralAsset,
|
|
11981
|
+
findIAsset,
|
|
11982
|
+
findRandomCdpCreator,
|
|
11983
|
+
findRandomNonAdminInterestCollector,
|
|
11984
|
+
findRandomTreasuryUtxo,
|
|
11985
|
+
findRandomTreasuryUtxoWithAsset,
|
|
11986
|
+
findRandomTreasuryUtxoWithOnlyAda,
|
|
11755
11987
|
findRelevantE2s2sIdxs,
|
|
11756
11988
|
findStakingManager,
|
|
11757
11989
|
findStakingManagerByOutRef,
|