@indigo-labs/indigo-sdk 0.3.9 → 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +293 -765
- package/dist/index.d.ts +293 -765
- package/dist/index.js +1033 -476
- package/dist/index.mjs +948 -388
- package/package.json +1 -1
- package/src/contracts/cdp/helpers.ts +12 -0
- package/src/contracts/gov/transactions.ts +4 -14
- package/src/contracts/iasset/helpers.ts +1 -0
- package/src/contracts/price-oracle/types-new.ts +1 -1
- package/src/contracts/rob/helpers.ts +274 -196
- package/src/contracts/rob/transactions.ts +11 -5
- package/src/contracts/rob-leverage/helpers.ts +379 -371
- package/src/contracts/rob-leverage/transactions.ts +176 -104
- package/src/index.ts +0 -2
- package/src/utils/utils.ts +0 -3
- package/tests/cdp/cdp-queries.ts +1 -1
- package/tests/endpoints/initialize.ts +14 -2
- package/tests/interest-collection/interest-collector-queries.ts +2 -1
- package/tests/queries/collector-queries.ts +2 -1
- package/tests/queries/poll-queries.ts +2 -1
- package/tests/queries/treasury-queries.ts +2 -1
- package/tests/rob/rob-leverage.test.ts +1646 -612
- package/tests/rob/rob.test.ts +35 -19
- package/tests/rob/transactions-mutated.ts +6 -4
package/dist/index.js
CHANGED
|
@@ -53,6 +53,7 @@ __export(index_exports, {
|
|
|
53
53
|
InterestOracleDatumSchema: () => InterestOracleDatumSchema,
|
|
54
54
|
InterestOracleParamsSchema: () => InterestOracleParamsSchema,
|
|
55
55
|
MAX_E2S2S_ENTRIES_COUNT: () => MAX_E2S2S_ENTRIES_COUNT,
|
|
56
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN: () => MAX_REDEMPTIONS_WITH_CDP_OPEN,
|
|
56
57
|
MIN_ROB_COLLATERAL_AMT: () => MIN_ROB_COLLATERAL_AMT,
|
|
57
58
|
ONE_DAY: () => ONE_DAY,
|
|
58
59
|
ONE_HOUR: () => ONE_HOUR,
|
|
@@ -87,6 +88,7 @@ __export(index_exports, {
|
|
|
87
88
|
adjustStakingPosition: () => adjustStakingPosition,
|
|
88
89
|
alwaysFailValidator: () => alwaysFailValidator,
|
|
89
90
|
annulRequest: () => annulRequest,
|
|
91
|
+
approximateLeverageRedemptions: () => approximateLeverageRedemptions,
|
|
90
92
|
attachOracle: () => attachOracle,
|
|
91
93
|
balance: () => balance,
|
|
92
94
|
batchCollectInterest: () => batchCollectInterest,
|
|
@@ -97,8 +99,11 @@ __export(index_exports, {
|
|
|
97
99
|
burnCdp: () => burnCdp,
|
|
98
100
|
calculateAccruedInterest: () => calculateAccruedInterest,
|
|
99
101
|
calculateAdaReward: () => calculateAdaReward,
|
|
102
|
+
calculateCollateralRatioFromLeverage: () => calculateCollateralRatioFromLeverage,
|
|
100
103
|
calculateIAssetRedemptionAmt: () => calculateIAssetRedemptionAmt,
|
|
104
|
+
calculateLeverageFromCollateralRatio: () => calculateLeverageFromCollateralRatio,
|
|
101
105
|
calculateMinCollateralCappedIAssetRedemptionAmt: () => calculateMinCollateralCappedIAssetRedemptionAmt,
|
|
106
|
+
calculateTotalCollateralForRedemption: () => calculateTotalCollateralForRedemption,
|
|
102
107
|
calculateUnitaryInterest: () => calculateUnitaryInterest,
|
|
103
108
|
calculateUnitaryInterestSinceOracleLastUpdated: () => calculateUnitaryInterestSinceOracleLastUpdated,
|
|
104
109
|
cancelRob: () => cancelRob,
|
|
@@ -164,9 +169,9 @@ __export(index_exports, {
|
|
|
164
169
|
getAssetClassComparisonStr: () => getAssetClassComparisonStr,
|
|
165
170
|
getInlineDatumOrThrow: () => getInlineDatumOrThrow,
|
|
166
171
|
getPythFeedConfig: () => getPythFeedConfig,
|
|
167
|
-
getRandomElement: () => getRandomElement,
|
|
168
172
|
getUpdatedAccountDeposit: () => getUpdatedAccountDeposit,
|
|
169
173
|
handleOracleForCollateralAsset: () => handleOracleForCollateralAsset,
|
|
174
|
+
iassetValueOfCollateral: () => iassetValueOfCollateral,
|
|
170
175
|
init: () => init,
|
|
171
176
|
initCDPCreator: () => initCDPCreator,
|
|
172
177
|
initCollector: () => initCollector,
|
|
@@ -180,8 +185,10 @@ __export(index_exports, {
|
|
|
180
185
|
initTreasury: () => initTreasury,
|
|
181
186
|
initializeAsset: () => initializeAsset,
|
|
182
187
|
insertSorted: () => insertSorted,
|
|
188
|
+
isBuyOrderFullyRedeemed: () => isBuyOrderFullyRedeemed,
|
|
183
189
|
isFullyRedeemed: () => isFullyRedeemed,
|
|
184
190
|
isSameEpochToScaleKey: () => isSameEpochToScaleKey,
|
|
191
|
+
leverageCdpWithRob: () => leverageCdpWithRob,
|
|
185
192
|
liquidateCdp: () => liquidateCdp,
|
|
186
193
|
liquidationHelper: () => liquidationHelper,
|
|
187
194
|
loadSystemParamsFromFile: () => loadSystemParamsFromFile,
|
|
@@ -245,10 +252,6 @@ __export(index_exports, {
|
|
|
245
252
|
parseIAssetDatumOrThrow: () => parseIAssetDatumOrThrow,
|
|
246
253
|
parseInterestCollectionDatum: () => parseInterestCollectionDatum,
|
|
247
254
|
parseInterestOracleDatum: () => parseInterestOracleDatum,
|
|
248
|
-
parsePollManager: () => parsePollManager,
|
|
249
|
-
parsePollManagerOrThrow: () => parsePollManagerOrThrow,
|
|
250
|
-
parsePollShard: () => parsePollShard,
|
|
251
|
-
parsePollShardOrThrow: () => parsePollShardOrThrow,
|
|
252
255
|
parsePriceOracleDatum: () => parsePriceOracleDatum,
|
|
253
256
|
parsePythStateDatum: () => parsePythStateDatum,
|
|
254
257
|
parseRobDatum: () => parseRobDatum,
|
|
@@ -269,8 +272,8 @@ __export(index_exports, {
|
|
|
269
272
|
parseStakingPosition: () => parseStakingPosition,
|
|
270
273
|
parseStakingPositionOrThrow: () => parseStakingPositionOrThrow,
|
|
271
274
|
partitionEpochToScaleToSums: () => partitionEpochToScaleToSums,
|
|
272
|
-
pollPassQuorum: () => pollPassQuorum,
|
|
273
275
|
processSpRequest: () => processSpRequest,
|
|
276
|
+
randomRobsSubsetSatisfyingTargetCollateral: () => randomRobsSubsetSatisfyingTargetCollateral,
|
|
274
277
|
rationalAdd: () => rationalAdd,
|
|
275
278
|
rationalCeil: () => rationalCeil,
|
|
276
279
|
rationalDiv: () => rationalDiv,
|
|
@@ -289,7 +292,10 @@ __export(index_exports, {
|
|
|
289
292
|
requestSpAccountClosure: () => requestSpAccountClosure,
|
|
290
293
|
requestSpAccountCreation: () => requestSpAccountCreation,
|
|
291
294
|
rewardSnapshotPrecision: () => rewardSnapshotPrecision,
|
|
292
|
-
|
|
295
|
+
robAmtToSpend: () => robAmtToSpend,
|
|
296
|
+
robBuyOrderSummary: () => robBuyOrderSummary,
|
|
297
|
+
robCollateralAmtToSpend: () => robCollateralAmtToSpend,
|
|
298
|
+
robIAssetAmtToSpend: () => robIAssetAmtToSpend,
|
|
293
299
|
runCreateScriptRefTx: () => runCreateScriptRefTx,
|
|
294
300
|
runOneShotMintTx: () => runOneShotMintTx,
|
|
295
301
|
scriptRef: () => scriptRef,
|
|
@@ -306,9 +312,6 @@ __export(index_exports, {
|
|
|
306
312
|
serialiseInterestCollectionDatum: () => serialiseInterestCollectionDatum,
|
|
307
313
|
serialiseInterestCollectionRedeemer: () => serialiseInterestCollectionRedeemer,
|
|
308
314
|
serialiseInterestOracleDatum: () => serialiseInterestOracleDatum,
|
|
309
|
-
serialisePollDatum: () => serialisePollDatum,
|
|
310
|
-
serialisePollManagerRedeemer: () => serialisePollManagerRedeemer,
|
|
311
|
-
serialisePollShardRedeemer: () => serialisePollShardRedeemer,
|
|
312
315
|
serialisePriceOracleDatum: () => serialisePriceOracleDatum,
|
|
313
316
|
serialisePriceOracleRedeemer: () => serialisePriceOracleRedeemer,
|
|
314
317
|
serialisePythFeedParams: () => serialisePythFeedParams,
|
|
@@ -337,6 +340,7 @@ __export(index_exports, {
|
|
|
337
340
|
startPriceOracleTx: () => startPriceOracleTx,
|
|
338
341
|
submitTx: () => submitTx,
|
|
339
342
|
sum: () => sum,
|
|
343
|
+
summarizeActualLeverageRedemptions: () => summarizeActualLeverageRedemptions,
|
|
340
344
|
toAssetClassFromLucid: () => toAssetClassFromLucid,
|
|
341
345
|
toDataDerivedPythPrice: () => toDataDerivedPythPrice,
|
|
342
346
|
toSystemParamsAsset: () => toSystemParamsAsset,
|
|
@@ -723,7 +727,6 @@ function loadSystemParamsFromFile(file) {
|
|
|
723
727
|
function loadSystemParamsFromUrl(url) {
|
|
724
728
|
return fetch(url).then((res) => res.json()).then((data) => data);
|
|
725
729
|
}
|
|
726
|
-
var getRandomElement = (arr) => arr.length ? arr[Math.floor(Math.random() * arr.length)] : void 0;
|
|
727
730
|
|
|
728
731
|
// src/utils/time-helpers.ts
|
|
729
732
|
var ONE_SECOND = 1e3;
|
|
@@ -800,6 +803,11 @@ function calculateFeeFromRatio(feeRatio, amount) {
|
|
|
800
803
|
|
|
801
804
|
// src/contracts/cdp/helpers.ts
|
|
802
805
|
var import_cardano_offchain_common = require("@3rd-eye-labs/cardano-offchain-common");
|
|
806
|
+
function iassetValueOfCollateral(collateralAmt, oraclePrice) {
|
|
807
|
+
return rationalFloor(
|
|
808
|
+
rationalDiv(rationalFromInt(collateralAmt), oraclePrice)
|
|
809
|
+
);
|
|
810
|
+
}
|
|
803
811
|
function cdpCollateralRatioPercentage(currentSlot, iassetPrice, cdpUtxo, cdpContent, interestOracleDatum, network) {
|
|
804
812
|
const currentTime = BigInt((0, import_lucid4.slotToUnixTime)(network, currentSlot));
|
|
805
813
|
return (0, import_ts_pattern5.match)(cdpContent.cdpFees).with({ ActiveCDPInterestTracking: import_ts_pattern5.P.select() }, (interest) => {
|
|
@@ -3909,6 +3917,7 @@ function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythS
|
|
|
3909
3917
|
}).with(
|
|
3910
3918
|
{ DeferredValidation: { feedValHash: import_ts_pattern12.P.select() } },
|
|
3911
3919
|
async (feedValHash) => {
|
|
3920
|
+
if (priceOracleOref) throw new Error("Cannot pass price oracle oref");
|
|
3912
3921
|
if (!pythMessage) throw new Error("Missing Pyth message");
|
|
3913
3922
|
if (!pythStateOref) throw new Error("Missing pyth state out ref");
|
|
3914
3923
|
const pythStateUtxo = matchSingle(
|
|
@@ -5371,185 +5380,25 @@ var mkPollShardValidatorFromSP = (params) => {
|
|
|
5371
5380
|
};
|
|
5372
5381
|
};
|
|
5373
5382
|
|
|
5374
|
-
// src/contracts/poll/types-poll-new.ts
|
|
5375
|
-
var import_evolution15 = require("@evolution-sdk/evolution");
|
|
5376
|
-
var import_cardano_offchain_common14 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
5377
|
-
var import_fp_ts13 = require("fp-ts");
|
|
5378
|
-
var import_ts_pattern15 = require("ts-pattern");
|
|
5379
|
-
var PollStatusSchema = import_evolution15.TSchema.Struct({
|
|
5380
|
-
yesVotes: import_evolution15.TSchema.Integer,
|
|
5381
|
-
noVotes: import_evolution15.TSchema.Integer
|
|
5382
|
-
});
|
|
5383
|
-
var PollManagerContentSchema = import_evolution15.TSchema.Struct({
|
|
5384
|
-
pollId: import_evolution15.TSchema.Integer,
|
|
5385
|
-
pollOwner: import_evolution15.TSchema.ByteArray,
|
|
5386
|
-
content: ProposalContentSchema,
|
|
5387
|
-
treasuryWithdrawal: import_evolution15.TSchema.NullOr(TreasuryWithdrawalSchema),
|
|
5388
|
-
status: PollStatusSchema,
|
|
5389
|
-
votingEndTime: import_evolution15.TSchema.Integer,
|
|
5390
|
-
createdShardsCount: import_evolution15.TSchema.Integer,
|
|
5391
|
-
talliedShardsCount: import_evolution15.TSchema.Integer,
|
|
5392
|
-
totalShardsCount: import_evolution15.TSchema.Integer,
|
|
5393
|
-
proposingEndTime: import_evolution15.TSchema.Integer,
|
|
5394
|
-
expirationTime: import_evolution15.TSchema.Integer,
|
|
5395
|
-
protocolVersion: import_evolution15.TSchema.Integer,
|
|
5396
|
-
minimumQuorum: import_evolution15.TSchema.Integer
|
|
5397
|
-
});
|
|
5398
|
-
var PollShardContentSchema = import_evolution15.TSchema.Struct({
|
|
5399
|
-
pollId: import_evolution15.TSchema.Integer,
|
|
5400
|
-
status: PollStatusSchema,
|
|
5401
|
-
votingEndTime: import_evolution15.TSchema.Integer,
|
|
5402
|
-
managerAddress: import_cardano_offchain_common14.AddressSchema
|
|
5403
|
-
});
|
|
5404
|
-
var PollDatumSchema = import_evolution15.TSchema.Union(
|
|
5405
|
-
import_evolution15.TSchema.Struct(
|
|
5406
|
-
{
|
|
5407
|
-
PollManager: PollManagerContentSchema
|
|
5408
|
-
},
|
|
5409
|
-
{ flatInUnion: true }
|
|
5410
|
-
),
|
|
5411
|
-
import_evolution15.TSchema.Struct({ PollShard: PollShardContentSchema }, { flatInUnion: true })
|
|
5412
|
-
);
|
|
5413
|
-
var VoteOptionSchema = import_evolution15.TSchema.Union(
|
|
5414
|
-
import_evolution15.TSchema.Literal("Yes", { flatInUnion: true }),
|
|
5415
|
-
import_evolution15.TSchema.Literal("No", { flatInUnion: true })
|
|
5416
|
-
);
|
|
5417
|
-
var PollShardRedeemerSchema = import_evolution15.TSchema.Union(
|
|
5418
|
-
import_evolution15.TSchema.Struct({ Vote: VoteOptionSchema }, { flatInUnion: true }),
|
|
5419
|
-
import_evolution15.TSchema.Struct(
|
|
5420
|
-
{
|
|
5421
|
-
MergeShards: import_evolution15.TSchema.Struct(
|
|
5422
|
-
{
|
|
5423
|
-
currentTime: import_evolution15.TSchema.Integer,
|
|
5424
|
-
pollManagerRef: import_cardano_offchain_common14.OutputReferenceSchema
|
|
5425
|
-
},
|
|
5426
|
-
{ flatFields: true }
|
|
5427
|
-
)
|
|
5428
|
-
},
|
|
5429
|
-
{ flatInUnion: true }
|
|
5430
|
-
)
|
|
5431
|
-
);
|
|
5432
|
-
var PollManagerRedeemerSchema = import_evolution15.TSchema.Union(
|
|
5433
|
-
import_evolution15.TSchema.Struct(
|
|
5434
|
-
{
|
|
5435
|
-
EndPoll: import_evolution15.TSchema.Struct(
|
|
5436
|
-
{ currentTime: import_evolution15.TSchema.Integer },
|
|
5437
|
-
{ flatFields: true }
|
|
5438
|
-
)
|
|
5439
|
-
},
|
|
5440
|
-
{ flatInUnion: true }
|
|
5441
|
-
),
|
|
5442
|
-
import_evolution15.TSchema.Struct(
|
|
5443
|
-
{
|
|
5444
|
-
CreateShards: import_evolution15.TSchema.Struct(
|
|
5445
|
-
{ currentTime: import_evolution15.TSchema.Integer },
|
|
5446
|
-
{ flatFields: true }
|
|
5447
|
-
)
|
|
5448
|
-
},
|
|
5449
|
-
{ flatInUnion: true }
|
|
5450
|
-
),
|
|
5451
|
-
import_evolution15.TSchema.Struct(
|
|
5452
|
-
{
|
|
5453
|
-
MergeShardsManager: import_evolution15.TSchema.Struct(
|
|
5454
|
-
{ currentTime: import_evolution15.TSchema.Integer },
|
|
5455
|
-
{ flatFields: true }
|
|
5456
|
-
)
|
|
5457
|
-
},
|
|
5458
|
-
{ flatInUnion: true }
|
|
5459
|
-
)
|
|
5460
|
-
);
|
|
5461
|
-
function serialisePollManagerRedeemer(r) {
|
|
5462
|
-
return import_evolution15.Data.withSchema(PollManagerRedeemerSchema).toCBORHex(r);
|
|
5463
|
-
}
|
|
5464
|
-
function serialisePollShardRedeemer(r) {
|
|
5465
|
-
return import_evolution15.Data.withSchema(PollShardRedeemerSchema).toCBORHex(r);
|
|
5466
|
-
}
|
|
5467
|
-
function parsePollManager(datum) {
|
|
5468
|
-
try {
|
|
5469
|
-
return (0, import_ts_pattern15.match)(
|
|
5470
|
-
import_evolution15.Data.withSchema(PollDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
5471
|
-
datum
|
|
5472
|
-
)
|
|
5473
|
-
).with({ PollManager: import_ts_pattern15.P.select() }, (res) => import_fp_ts13.option.some(res)).otherwise(() => import_fp_ts13.option.none);
|
|
5474
|
-
} catch (_) {
|
|
5475
|
-
return import_fp_ts13.option.none;
|
|
5476
|
-
}
|
|
5477
|
-
}
|
|
5478
|
-
function parsePollManagerOrThrow(datum) {
|
|
5479
|
-
return import_fp_ts13.function.pipe(
|
|
5480
|
-
parsePollManager(datum),
|
|
5481
|
-
import_fp_ts13.option.match(() => {
|
|
5482
|
-
throw new Error("Expected a poll manager datum.");
|
|
5483
|
-
}, import_fp_ts13.function.identity)
|
|
5484
|
-
);
|
|
5485
|
-
}
|
|
5486
|
-
function parsePollShard(datum) {
|
|
5487
|
-
try {
|
|
5488
|
-
return (0, import_ts_pattern15.match)(
|
|
5489
|
-
import_evolution15.Data.withSchema(PollDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
5490
|
-
datum
|
|
5491
|
-
)
|
|
5492
|
-
).with({ PollShard: import_ts_pattern15.P.select() }, (res) => import_fp_ts13.option.some(res)).otherwise(() => import_fp_ts13.option.none);
|
|
5493
|
-
} catch (_) {
|
|
5494
|
-
return import_fp_ts13.option.none;
|
|
5495
|
-
}
|
|
5496
|
-
}
|
|
5497
|
-
function parsePollShardOrThrow(datum) {
|
|
5498
|
-
return import_fp_ts13.function.pipe(
|
|
5499
|
-
parsePollShard(datum),
|
|
5500
|
-
import_fp_ts13.option.match(() => {
|
|
5501
|
-
throw new Error("Expected a poll shard datum.");
|
|
5502
|
-
}, import_fp_ts13.function.identity)
|
|
5503
|
-
);
|
|
5504
|
-
}
|
|
5505
|
-
function serialisePollDatum(d) {
|
|
5506
|
-
return import_evolution15.Data.withSchema(PollDatumSchema).toCBORHex(d);
|
|
5507
|
-
}
|
|
5508
|
-
|
|
5509
|
-
// src/contracts/poll/helpers.ts
|
|
5510
|
-
function q(pollStatus, e) {
|
|
5511
|
-
if (pollStatus.yesVotes + pollStatus.noVotes === 0n)
|
|
5512
|
-
return { getOnChainInt: 0n };
|
|
5513
|
-
else {
|
|
5514
|
-
const q2 = ocdDiv(
|
|
5515
|
-
{ getOnChainInt: pollStatus.yesVotes },
|
|
5516
|
-
{ getOnChainInt: BigInt(Math.floor(Math.sqrt(Number(e)))) }
|
|
5517
|
-
).getOnChainInt - ocdDiv(
|
|
5518
|
-
{ getOnChainInt: pollStatus.noVotes },
|
|
5519
|
-
{
|
|
5520
|
-
getOnChainInt: BigInt(
|
|
5521
|
-
Math.floor(
|
|
5522
|
-
Math.sqrt(Number(pollStatus.yesVotes + pollStatus.noVotes))
|
|
5523
|
-
)
|
|
5524
|
-
)
|
|
5525
|
-
}
|
|
5526
|
-
).getOnChainInt;
|
|
5527
|
-
return { getOnChainInt: BigInt(q2) };
|
|
5528
|
-
}
|
|
5529
|
-
}
|
|
5530
|
-
function pollPassQuorum(pollStatus, electorate, minQuorum) {
|
|
5531
|
-
return pollStatus.yesVotes + pollStatus.noVotes >= minQuorum && q(pollStatus, electorate).getOnChainInt > 50000n;
|
|
5532
|
-
}
|
|
5533
|
-
|
|
5534
5383
|
// src/contracts/collector/transactions.ts
|
|
5535
5384
|
var import_lucid22 = require("@lucid-evolution/lucid");
|
|
5536
5385
|
|
|
5537
5386
|
// src/contracts/collector/types-new.ts
|
|
5538
|
-
var
|
|
5539
|
-
var CollectorRedeemerSchema =
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5387
|
+
var import_evolution15 = require("@evolution-sdk/evolution");
|
|
5388
|
+
var CollectorRedeemerSchema = import_evolution15.TSchema.Union(
|
|
5389
|
+
import_evolution15.TSchema.Literal("Collect", { flatInUnion: true }),
|
|
5390
|
+
import_evolution15.TSchema.Literal("DistributeToStakers", { flatInUnion: true }),
|
|
5391
|
+
import_evolution15.TSchema.Literal("UpgradeVersion", { flatInUnion: true })
|
|
5543
5392
|
);
|
|
5544
5393
|
function serialiseCollectorRedeemer(r) {
|
|
5545
|
-
return
|
|
5394
|
+
return import_evolution15.Data.withSchema(
|
|
5546
5395
|
CollectorRedeemerSchema,
|
|
5547
5396
|
DEFAULT_SCHEMA_OPTIONS
|
|
5548
5397
|
).toCBORHex(r);
|
|
5549
5398
|
}
|
|
5550
5399
|
|
|
5551
5400
|
// src/contracts/collector/transactions.ts
|
|
5552
|
-
var
|
|
5401
|
+
var import_cardano_offchain_common14 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
5553
5402
|
async function collectorFeeTx(fee, lucid, params, tx, collectorOref) {
|
|
5554
5403
|
const collectorUtxo = matchSingle(
|
|
5555
5404
|
await lucid.utxosByOutRef([collectorOref]),
|
|
@@ -5564,7 +5413,7 @@ async function collectorFeeTx(fee, lucid, params, tx, collectorOref) {
|
|
|
5564
5413
|
tx.collectFrom([collectorUtxo], serialiseCollectorRedeemer("Collect")).pay.ToContract(
|
|
5565
5414
|
collectorUtxo.address,
|
|
5566
5415
|
{ kind: "inline", value: import_lucid22.Data.void() },
|
|
5567
|
-
(0, import_lucid22.addAssets)(collectorUtxo.assets, (0,
|
|
5416
|
+
(0, import_lucid22.addAssets)(collectorUtxo.assets, (0, import_cardano_offchain_common14.mkLovelacesOf)(fee))
|
|
5568
5417
|
).readFrom([collectorRefScriptUtxo]);
|
|
5569
5418
|
return collectorRefScriptUtxo;
|
|
5570
5419
|
}
|
|
@@ -5578,95 +5427,95 @@ var import_fp_ts15 = require("fp-ts");
|
|
|
5578
5427
|
var import_ts_pattern17 = require("ts-pattern");
|
|
5579
5428
|
|
|
5580
5429
|
// src/contracts/staking/types-new.ts
|
|
5581
|
-
var
|
|
5582
|
-
var
|
|
5583
|
-
var
|
|
5584
|
-
var StakingPosLockedAmtSchema =
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
voteAmt:
|
|
5589
|
-
votingEnd:
|
|
5430
|
+
var import_evolution16 = require("@evolution-sdk/evolution");
|
|
5431
|
+
var import_fp_ts13 = require("fp-ts");
|
|
5432
|
+
var import_ts_pattern15 = require("ts-pattern");
|
|
5433
|
+
var StakingPosLockedAmtSchema = import_evolution16.TSchema.Array(
|
|
5434
|
+
import_evolution16.TSchema.Tuple([
|
|
5435
|
+
import_evolution16.TSchema.Integer,
|
|
5436
|
+
import_evolution16.TSchema.Struct({
|
|
5437
|
+
voteAmt: import_evolution16.TSchema.Integer,
|
|
5438
|
+
votingEnd: import_evolution16.TSchema.Integer
|
|
5590
5439
|
})
|
|
5591
5440
|
])
|
|
5592
5441
|
);
|
|
5593
|
-
var RewardSnapshotSchema =
|
|
5594
|
-
snapshotAda:
|
|
5442
|
+
var RewardSnapshotSchema = import_evolution16.TSchema.Struct({
|
|
5443
|
+
snapshotAda: import_evolution16.TSchema.Integer
|
|
5595
5444
|
});
|
|
5596
|
-
var StakingPositionSchema =
|
|
5597
|
-
owner:
|
|
5445
|
+
var StakingPositionSchema = import_evolution16.TSchema.Struct({
|
|
5446
|
+
owner: import_evolution16.TSchema.ByteArray,
|
|
5598
5447
|
lockedAmount: StakingPosLockedAmtSchema,
|
|
5599
5448
|
positionSnapshot: RewardSnapshotSchema
|
|
5600
5449
|
});
|
|
5601
|
-
var StakingManagerSchema =
|
|
5602
|
-
totalStake:
|
|
5450
|
+
var StakingManagerSchema = import_evolution16.TSchema.Struct({
|
|
5451
|
+
totalStake: import_evolution16.TSchema.Integer,
|
|
5603
5452
|
managerSnapshot: RewardSnapshotSchema
|
|
5604
5453
|
});
|
|
5605
|
-
var StakingDatumSchema =
|
|
5454
|
+
var StakingDatumSchema = import_evolution16.TSchema.Union(
|
|
5606
5455
|
StakingManagerSchema,
|
|
5607
5456
|
StakingPositionSchema
|
|
5608
5457
|
);
|
|
5609
|
-
var StakingRedeemerSchema =
|
|
5610
|
-
|
|
5458
|
+
var StakingRedeemerSchema = import_evolution16.TSchema.Union(
|
|
5459
|
+
import_evolution16.TSchema.Struct(
|
|
5611
5460
|
{
|
|
5612
|
-
CreateStakingPosition:
|
|
5613
|
-
{ creatorPkh:
|
|
5461
|
+
CreateStakingPosition: import_evolution16.TSchema.Struct(
|
|
5462
|
+
{ creatorPkh: import_evolution16.TSchema.ByteArray },
|
|
5614
5463
|
{ flatFields: true }
|
|
5615
5464
|
)
|
|
5616
5465
|
},
|
|
5617
5466
|
{ flatInUnion: true }
|
|
5618
5467
|
),
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5468
|
+
import_evolution16.TSchema.Literal("UpdateTotalStake", { flatInUnion: true }),
|
|
5469
|
+
import_evolution16.TSchema.Literal("Distribute", { flatInUnion: true }),
|
|
5470
|
+
import_evolution16.TSchema.Struct(
|
|
5622
5471
|
{
|
|
5623
|
-
AdjustStakedAmount:
|
|
5624
|
-
{ adjustAmount:
|
|
5472
|
+
AdjustStakedAmount: import_evolution16.TSchema.Struct(
|
|
5473
|
+
{ adjustAmount: import_evolution16.TSchema.Integer },
|
|
5625
5474
|
{ flatFields: true }
|
|
5626
5475
|
)
|
|
5627
5476
|
},
|
|
5628
5477
|
{ flatInUnion: true }
|
|
5629
5478
|
),
|
|
5630
|
-
|
|
5631
|
-
|
|
5632
|
-
|
|
5479
|
+
import_evolution16.TSchema.Literal("Unstake", { flatInUnion: true }),
|
|
5480
|
+
import_evolution16.TSchema.Literal("Lock", { flatInUnion: true }),
|
|
5481
|
+
import_evolution16.TSchema.Literal("UpgradeVersion", { flatInUnion: true })
|
|
5633
5482
|
);
|
|
5634
5483
|
function serialiseStakingRedeemer(r) {
|
|
5635
|
-
return
|
|
5484
|
+
return import_evolution16.Data.withSchema(
|
|
5636
5485
|
StakingRedeemerSchema,
|
|
5637
5486
|
DEFAULT_SCHEMA_OPTIONS
|
|
5638
5487
|
).toCBORHex(r);
|
|
5639
5488
|
}
|
|
5640
5489
|
function parseStakingPosition(datum) {
|
|
5641
5490
|
try {
|
|
5642
|
-
return (0,
|
|
5643
|
-
|
|
5491
|
+
return (0, import_ts_pattern15.match)(
|
|
5492
|
+
import_evolution16.Data.withSchema(StakingDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
5644
5493
|
datum
|
|
5645
5494
|
)
|
|
5646
|
-
).with({ owner:
|
|
5495
|
+
).with({ owner: import_ts_pattern15.P.any }, (res) => import_fp_ts13.option.some(res)).otherwise(() => import_fp_ts13.option.none);
|
|
5647
5496
|
} catch (_) {
|
|
5648
|
-
return
|
|
5497
|
+
return import_fp_ts13.option.none;
|
|
5649
5498
|
}
|
|
5650
5499
|
}
|
|
5651
5500
|
function parseStakingPositionOrThrow(datum) {
|
|
5652
|
-
return
|
|
5501
|
+
return import_fp_ts13.function.pipe(
|
|
5653
5502
|
parseStakingPosition(datum),
|
|
5654
|
-
|
|
5503
|
+
import_fp_ts13.option.match(() => {
|
|
5655
5504
|
throw new Error("Expected a StakingPosition datum.");
|
|
5656
|
-
},
|
|
5505
|
+
}, import_fp_ts13.function.identity)
|
|
5657
5506
|
);
|
|
5658
5507
|
}
|
|
5659
5508
|
function parseStakingManagerDatum(datum) {
|
|
5660
|
-
return (0,
|
|
5661
|
-
|
|
5509
|
+
return (0, import_ts_pattern15.match)(
|
|
5510
|
+
import_evolution16.Data.withSchema(StakingDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
5662
5511
|
datum
|
|
5663
5512
|
)
|
|
5664
|
-
).with({ totalStake:
|
|
5513
|
+
).with({ totalStake: import_ts_pattern15.P.any }, (res) => res).otherwise(() => {
|
|
5665
5514
|
throw new Error("Expected a StakingPosition datum.");
|
|
5666
5515
|
});
|
|
5667
5516
|
}
|
|
5668
5517
|
function serialiseStakingDatum(d) {
|
|
5669
|
-
return
|
|
5518
|
+
return import_evolution16.Data.withSchema(StakingDatumSchema, DEFAULT_SCHEMA_OPTIONS).toCBORHex(
|
|
5670
5519
|
d
|
|
5671
5520
|
);
|
|
5672
5521
|
}
|
|
@@ -5781,22 +5630,182 @@ function calculateAdaReward(currentSnapshotAda, oldSnapshotAda, existingIndyAmou
|
|
|
5781
5630
|
return (currentSnapshotAda - oldSnapshotAda) * existingIndyAmount / rewardSnapshotPrecision;
|
|
5782
5631
|
}
|
|
5783
5632
|
|
|
5633
|
+
// src/contracts/poll/helpers.ts
|
|
5634
|
+
function q(pollStatus, e) {
|
|
5635
|
+
if (pollStatus.yesVotes + pollStatus.noVotes === 0n)
|
|
5636
|
+
return { getOnChainInt: 0n };
|
|
5637
|
+
else {
|
|
5638
|
+
const q2 = ocdDiv(
|
|
5639
|
+
{ getOnChainInt: pollStatus.yesVotes },
|
|
5640
|
+
{ getOnChainInt: BigInt(Math.floor(Math.sqrt(Number(e)))) }
|
|
5641
|
+
).getOnChainInt - ocdDiv(
|
|
5642
|
+
{ getOnChainInt: pollStatus.noVotes },
|
|
5643
|
+
{
|
|
5644
|
+
getOnChainInt: BigInt(
|
|
5645
|
+
Math.floor(
|
|
5646
|
+
Math.sqrt(Number(pollStatus.yesVotes + pollStatus.noVotes))
|
|
5647
|
+
)
|
|
5648
|
+
)
|
|
5649
|
+
}
|
|
5650
|
+
).getOnChainInt;
|
|
5651
|
+
return { getOnChainInt: BigInt(q2) };
|
|
5652
|
+
}
|
|
5653
|
+
}
|
|
5654
|
+
function pollPassQuorum(pollStatus, electorate, minQuorum) {
|
|
5655
|
+
return pollStatus.yesVotes + pollStatus.noVotes >= minQuorum && q(pollStatus, electorate).getOnChainInt > 50000n;
|
|
5656
|
+
}
|
|
5657
|
+
|
|
5784
5658
|
// src/contracts/version-registry/types-new.ts
|
|
5785
|
-
var
|
|
5786
|
-
var VersionRecordDatumSchema =
|
|
5787
|
-
upgradeId:
|
|
5659
|
+
var import_evolution17 = require("@evolution-sdk/evolution");
|
|
5660
|
+
var VersionRecordDatumSchema = import_evolution17.TSchema.Struct({
|
|
5661
|
+
upgradeId: import_evolution17.TSchema.Integer,
|
|
5788
5662
|
/// Underlying representation of the following mapping: ValidatorHash -> UpgradePath
|
|
5789
|
-
upgradePaths:
|
|
5790
|
-
|
|
5663
|
+
upgradePaths: import_evolution17.TSchema.Array(
|
|
5664
|
+
import_evolution17.TSchema.Tuple([import_evolution17.TSchema.ByteArray, import_evolution17.TSchema.ByteArray])
|
|
5791
5665
|
)
|
|
5792
5666
|
});
|
|
5793
5667
|
function serialiseVersionRecordDatum(d) {
|
|
5794
|
-
return
|
|
5668
|
+
return import_evolution17.Data.withSchema(
|
|
5795
5669
|
VersionRecordDatumSchema,
|
|
5796
5670
|
DEFAULT_SCHEMA_OPTIONS
|
|
5797
5671
|
).toCBORHex(d);
|
|
5798
5672
|
}
|
|
5799
5673
|
|
|
5674
|
+
// src/contracts/poll/types-poll-new.ts
|
|
5675
|
+
var import_evolution18 = require("@evolution-sdk/evolution");
|
|
5676
|
+
var import_cardano_offchain_common15 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
5677
|
+
var import_fp_ts14 = require("fp-ts");
|
|
5678
|
+
var import_ts_pattern16 = require("ts-pattern");
|
|
5679
|
+
var PollStatusSchema = import_evolution18.TSchema.Struct({
|
|
5680
|
+
yesVotes: import_evolution18.TSchema.Integer,
|
|
5681
|
+
noVotes: import_evolution18.TSchema.Integer
|
|
5682
|
+
});
|
|
5683
|
+
var PollManagerContentSchema = import_evolution18.TSchema.Struct({
|
|
5684
|
+
pollId: import_evolution18.TSchema.Integer,
|
|
5685
|
+
pollOwner: import_evolution18.TSchema.ByteArray,
|
|
5686
|
+
content: ProposalContentSchema,
|
|
5687
|
+
treasuryWithdrawal: import_evolution18.TSchema.NullOr(TreasuryWithdrawalSchema),
|
|
5688
|
+
status: PollStatusSchema,
|
|
5689
|
+
votingEndTime: import_evolution18.TSchema.Integer,
|
|
5690
|
+
createdShardsCount: import_evolution18.TSchema.Integer,
|
|
5691
|
+
talliedShardsCount: import_evolution18.TSchema.Integer,
|
|
5692
|
+
totalShardsCount: import_evolution18.TSchema.Integer,
|
|
5693
|
+
proposingEndTime: import_evolution18.TSchema.Integer,
|
|
5694
|
+
expirationTime: import_evolution18.TSchema.Integer,
|
|
5695
|
+
protocolVersion: import_evolution18.TSchema.Integer,
|
|
5696
|
+
minimumQuorum: import_evolution18.TSchema.Integer
|
|
5697
|
+
});
|
|
5698
|
+
var PollShardContentSchema = import_evolution18.TSchema.Struct({
|
|
5699
|
+
pollId: import_evolution18.TSchema.Integer,
|
|
5700
|
+
status: PollStatusSchema,
|
|
5701
|
+
votingEndTime: import_evolution18.TSchema.Integer,
|
|
5702
|
+
managerAddress: import_cardano_offchain_common15.AddressSchema
|
|
5703
|
+
});
|
|
5704
|
+
var PollDatumSchema = import_evolution18.TSchema.Union(
|
|
5705
|
+
import_evolution18.TSchema.Struct(
|
|
5706
|
+
{
|
|
5707
|
+
PollManager: PollManagerContentSchema
|
|
5708
|
+
},
|
|
5709
|
+
{ flatInUnion: true }
|
|
5710
|
+
),
|
|
5711
|
+
import_evolution18.TSchema.Struct({ PollShard: PollShardContentSchema }, { flatInUnion: true })
|
|
5712
|
+
);
|
|
5713
|
+
var VoteOptionSchema = import_evolution18.TSchema.Union(
|
|
5714
|
+
import_evolution18.TSchema.Literal("Yes", { flatInUnion: true }),
|
|
5715
|
+
import_evolution18.TSchema.Literal("No", { flatInUnion: true })
|
|
5716
|
+
);
|
|
5717
|
+
var PollShardRedeemerSchema = import_evolution18.TSchema.Union(
|
|
5718
|
+
import_evolution18.TSchema.Struct({ Vote: VoteOptionSchema }, { flatInUnion: true }),
|
|
5719
|
+
import_evolution18.TSchema.Struct(
|
|
5720
|
+
{
|
|
5721
|
+
MergeShards: import_evolution18.TSchema.Struct(
|
|
5722
|
+
{
|
|
5723
|
+
currentTime: import_evolution18.TSchema.Integer,
|
|
5724
|
+
pollManagerRef: import_cardano_offchain_common15.OutputReferenceSchema
|
|
5725
|
+
},
|
|
5726
|
+
{ flatFields: true }
|
|
5727
|
+
)
|
|
5728
|
+
},
|
|
5729
|
+
{ flatInUnion: true }
|
|
5730
|
+
)
|
|
5731
|
+
);
|
|
5732
|
+
var PollManagerRedeemerSchema = import_evolution18.TSchema.Union(
|
|
5733
|
+
import_evolution18.TSchema.Struct(
|
|
5734
|
+
{
|
|
5735
|
+
EndPoll: import_evolution18.TSchema.Struct(
|
|
5736
|
+
{ currentTime: import_evolution18.TSchema.Integer },
|
|
5737
|
+
{ flatFields: true }
|
|
5738
|
+
)
|
|
5739
|
+
},
|
|
5740
|
+
{ flatInUnion: true }
|
|
5741
|
+
),
|
|
5742
|
+
import_evolution18.TSchema.Struct(
|
|
5743
|
+
{
|
|
5744
|
+
CreateShards: import_evolution18.TSchema.Struct(
|
|
5745
|
+
{ currentTime: import_evolution18.TSchema.Integer },
|
|
5746
|
+
{ flatFields: true }
|
|
5747
|
+
)
|
|
5748
|
+
},
|
|
5749
|
+
{ flatInUnion: true }
|
|
5750
|
+
),
|
|
5751
|
+
import_evolution18.TSchema.Struct(
|
|
5752
|
+
{
|
|
5753
|
+
MergeShardsManager: import_evolution18.TSchema.Struct(
|
|
5754
|
+
{ currentTime: import_evolution18.TSchema.Integer },
|
|
5755
|
+
{ flatFields: true }
|
|
5756
|
+
)
|
|
5757
|
+
},
|
|
5758
|
+
{ flatInUnion: true }
|
|
5759
|
+
)
|
|
5760
|
+
);
|
|
5761
|
+
function serialisePollManagerRedeemer(r) {
|
|
5762
|
+
return import_evolution18.Data.withSchema(PollManagerRedeemerSchema).toCBORHex(r);
|
|
5763
|
+
}
|
|
5764
|
+
function serialisePollShardRedeemer(r) {
|
|
5765
|
+
return import_evolution18.Data.withSchema(PollShardRedeemerSchema).toCBORHex(r);
|
|
5766
|
+
}
|
|
5767
|
+
function parsePollManager(datum) {
|
|
5768
|
+
try {
|
|
5769
|
+
return (0, import_ts_pattern16.match)(
|
|
5770
|
+
import_evolution18.Data.withSchema(PollDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
5771
|
+
datum
|
|
5772
|
+
)
|
|
5773
|
+
).with({ PollManager: import_ts_pattern16.P.select() }, (res) => import_fp_ts14.option.some(res)).otherwise(() => import_fp_ts14.option.none);
|
|
5774
|
+
} catch (_) {
|
|
5775
|
+
return import_fp_ts14.option.none;
|
|
5776
|
+
}
|
|
5777
|
+
}
|
|
5778
|
+
function parsePollManagerOrThrow(datum) {
|
|
5779
|
+
return import_fp_ts14.function.pipe(
|
|
5780
|
+
parsePollManager(datum),
|
|
5781
|
+
import_fp_ts14.option.match(() => {
|
|
5782
|
+
throw new Error("Expected a poll manager datum.");
|
|
5783
|
+
}, import_fp_ts14.function.identity)
|
|
5784
|
+
);
|
|
5785
|
+
}
|
|
5786
|
+
function parsePollShard(datum) {
|
|
5787
|
+
try {
|
|
5788
|
+
return (0, import_ts_pattern16.match)(
|
|
5789
|
+
import_evolution18.Data.withSchema(PollDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
5790
|
+
datum
|
|
5791
|
+
)
|
|
5792
|
+
).with({ PollShard: import_ts_pattern16.P.select() }, (res) => import_fp_ts14.option.some(res)).otherwise(() => import_fp_ts14.option.none);
|
|
5793
|
+
} catch (_) {
|
|
5794
|
+
return import_fp_ts14.option.none;
|
|
5795
|
+
}
|
|
5796
|
+
}
|
|
5797
|
+
function parsePollShardOrThrow(datum) {
|
|
5798
|
+
return import_fp_ts14.function.pipe(
|
|
5799
|
+
parsePollShard(datum),
|
|
5800
|
+
import_fp_ts14.option.match(() => {
|
|
5801
|
+
throw new Error("Expected a poll shard datum.");
|
|
5802
|
+
}, import_fp_ts14.function.identity)
|
|
5803
|
+
);
|
|
5804
|
+
}
|
|
5805
|
+
function serialisePollDatum(d) {
|
|
5806
|
+
return import_evolution18.Data.withSchema(PollDatumSchema).toCBORHex(d);
|
|
5807
|
+
}
|
|
5808
|
+
|
|
5800
5809
|
// src/contracts/gov/transactions.ts
|
|
5801
5810
|
var import_cardano_offchain_common17 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
5802
5811
|
async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lucid, currentSlot, govOref, allIAssetOrefs) {
|
|
@@ -5914,9 +5923,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
5914
5923
|
)
|
|
5915
5924
|
)
|
|
5916
5925
|
)
|
|
5917
|
-
).validFrom(Number(currentTime) - ONE_SECOND).validTo(
|
|
5918
|
-
Number(currentTime) + Number(sysParams.govParams.gBiasTime) - ONE_SECOND
|
|
5919
|
-
).addSigner(ownAddr),
|
|
5926
|
+
).validFrom(Number(currentTime) - ONE_SECOND).validTo(Number(currentTime + sysParams.govParams.gBiasTime) - ONE_SECOND).addSigner(ownAddr),
|
|
5920
5927
|
newPollId
|
|
5921
5928
|
];
|
|
5922
5929
|
}
|
|
@@ -5958,7 +5965,7 @@ async function createShardsChunks(chunkSize, pollManagerOref, sysParams, current
|
|
|
5958
5965
|
);
|
|
5959
5966
|
const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
|
|
5960
5967
|
const tx = lucid.newTx().validFrom(Number(currentTime) - ONE_SECOND).validTo(
|
|
5961
|
-
Number(currentTime
|
|
5968
|
+
Number(currentTime + sysParams.pollManagerParams.pBiasTime) - ONE_SECOND
|
|
5962
5969
|
).mintAssets((0, import_cardano_offchain_common16.mkAssetsOf)(pollNft, shardsCount), import_lucid26.Data.void()).readFrom([pollAuthTokenPolicyRefScriptUtxo, pollManagerRefScriptUtxo]).collectFrom(
|
|
5963
5970
|
[pollManagerUtxo],
|
|
5964
5971
|
serialisePollManagerRedeemer({ CreateShards: { currentTime } })
|
|
@@ -6138,7 +6145,7 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
6138
6145
|
)(shardUtxos);
|
|
6139
6146
|
const pollNft = fromSystemParamsAsset(sysParams.govParams.pollToken);
|
|
6140
6147
|
return lucid.newTx().validFrom(Number(currentTime) - ONE_SECOND).validTo(
|
|
6141
|
-
Number(currentTime
|
|
6148
|
+
Number(currentTime + sysParams.pollManagerParams.pBiasTime) - ONE_SECOND
|
|
6142
6149
|
).readFrom([
|
|
6143
6150
|
pollShardRefScriptUtxo,
|
|
6144
6151
|
pollManagerRefScriptUtxo,
|
|
@@ -6925,9 +6932,7 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6925
6932
|
);
|
|
6926
6933
|
}).otherwise(() => {
|
|
6927
6934
|
});
|
|
6928
|
-
tx.readFrom([upgradeTokenPolicyRefScriptUtxo, executeRefScriptUtxo]).validFrom(Number(currentTime) - ONE_SECOND).validTo(
|
|
6929
|
-
Number(currentTime) + Number(sysParams.govParams.gBiasTime) - ONE_SECOND
|
|
6930
|
-
).collectFrom([executeUtxo], import_lucid26.Data.void()).mintAssets(
|
|
6935
|
+
tx.readFrom([upgradeTokenPolicyRefScriptUtxo, executeRefScriptUtxo]).validFrom(Number(currentTime) - ONE_SECOND).validTo(Number(currentTime + sysParams.govParams.gBiasTime) - ONE_SECOND).collectFrom([executeUtxo], import_lucid26.Data.void()).mintAssets(
|
|
6931
6936
|
(0, import_cardano_offchain_common16.mkAssetsOf)(fromSystemParamsAsset(sysParams.govParams.upgradeToken), -1n),
|
|
6932
6937
|
import_lucid26.Data.void()
|
|
6933
6938
|
).addSigner(ownAddr).setMinFee(922932n);
|
|
@@ -8448,7 +8453,7 @@ var import_fp_ts17 = require("fp-ts");
|
|
|
8448
8453
|
var import_ts_pattern19 = require("ts-pattern");
|
|
8449
8454
|
var import_cardano_offchain_common22 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
8450
8455
|
var MIN_ROB_COLLATERAL_AMT = 3000000n;
|
|
8451
|
-
function
|
|
8456
|
+
function robCollateralAmtToSpend(utxo, datum) {
|
|
8452
8457
|
return (0, import_ts_pattern19.match)(datum.orderType).returnType().with({ BuyIAssetOrder: import_ts_pattern19.P.select() }, (content) => {
|
|
8453
8458
|
if ((0, import_cardano_offchain_common22.isSameAssetClass)(import_cardano_offchain_common22.adaAssetClass, content.collateralAsset)) {
|
|
8454
8459
|
return zeroNegatives(
|
|
@@ -8457,24 +8462,61 @@ function robAmountToSpend(utxo, datum, sysParams) {
|
|
|
8457
8462
|
} else {
|
|
8458
8463
|
return (0, import_cardano_offchain_common22.assetClassValueOf)(utxo.assets, content.collateralAsset);
|
|
8459
8464
|
}
|
|
8460
|
-
}).
|
|
8465
|
+
}).otherwise(() => {
|
|
8466
|
+
throw new Error("Collateral to spend is relevant only for Buy orders.");
|
|
8467
|
+
});
|
|
8468
|
+
}
|
|
8469
|
+
function robIAssetAmtToSpend(utxo, datum, iassetCurrencySymbol) {
|
|
8470
|
+
return (0, import_ts_pattern19.match)(datum.orderType).returnType().with({ SellIAssetOrder: import_ts_pattern19.P.any }, (_) => {
|
|
8461
8471
|
return (0, import_cardano_offchain_common22.assetClassValueOf)(utxo.assets, {
|
|
8462
|
-
currencySymbol: (0, import_lucid49.fromHex)(
|
|
8463
|
-
sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol
|
|
8464
|
-
),
|
|
8472
|
+
currencySymbol: (0, import_lucid49.fromHex)(iassetCurrencySymbol.unCurrencySymbol),
|
|
8465
8473
|
tokenName: datum.iasset
|
|
8466
8474
|
});
|
|
8467
|
-
}).
|
|
8475
|
+
}).otherwise(() => {
|
|
8476
|
+
throw new Error("IAssets to spend is relevant only for Sell orders.");
|
|
8477
|
+
});
|
|
8478
|
+
}
|
|
8479
|
+
function robAmtToSpend(utxo, datum, iassetCurrencySymbol) {
|
|
8480
|
+
return (0, import_ts_pattern19.match)(datum.orderType).with({ BuyIAssetOrder: import_ts_pattern19.P.any }, () => robCollateralAmtToSpend(utxo, datum)).with(
|
|
8481
|
+
{ SellIAssetOrder: import_ts_pattern19.P.any },
|
|
8482
|
+
() => robIAssetAmtToSpend(utxo, datum, iassetCurrencySymbol)
|
|
8483
|
+
).exhaustive();
|
|
8468
8484
|
}
|
|
8469
|
-
function
|
|
8470
|
-
|
|
8485
|
+
function robBuyOrderSummary(utxo, datum, oraclePrice) {
|
|
8486
|
+
const redeemable = robCollateralAmtToSpend(utxo, datum);
|
|
8487
|
+
const payoutAmt = iassetValueOfCollateral(redeemable, oraclePrice);
|
|
8488
|
+
return {
|
|
8489
|
+
redeemableCollateral: redeemable,
|
|
8490
|
+
payoutIAsset: payoutAmt
|
|
8491
|
+
};
|
|
8492
|
+
}
|
|
8493
|
+
function isBuyOrderFullyRedeemed(utxo, datum, oraclePrice) {
|
|
8494
|
+
const summary = robBuyOrderSummary(utxo, datum, oraclePrice);
|
|
8495
|
+
return summary.redeemableCollateral <= 0n || summary.payoutIAsset <= 0n;
|
|
8496
|
+
}
|
|
8497
|
+
function isFullyRedeemed(utxo, datum, iassetCurrencySymbol) {
|
|
8498
|
+
return (0, import_ts_pattern19.match)(datum.orderType).returnType().with(
|
|
8499
|
+
{ BuyIAssetOrder: import_ts_pattern19.P.select() },
|
|
8500
|
+
(content) => isBuyOrderFullyRedeemed(utxo, datum, content.maxPrice)
|
|
8501
|
+
).with({ SellIAssetOrder: import_ts_pattern19.P.select() }, (content) => {
|
|
8502
|
+
const iassetToSpend = robIAssetAmtToSpend(
|
|
8503
|
+
utxo,
|
|
8504
|
+
datum,
|
|
8505
|
+
iassetCurrencySymbol
|
|
8506
|
+
);
|
|
8507
|
+
const payoutAmts = content.allowedCollateralAssets.map(
|
|
8508
|
+
(c) => rationalFloor(rationalMul(rationalFromInt(iassetToSpend), c[1]))
|
|
8509
|
+
);
|
|
8510
|
+
return iassetToSpend <= 0n || // When for every allowed collateral asset the payout would be 0
|
|
8511
|
+
payoutAmts.every((amt) => amt <= 0n);
|
|
8512
|
+
}).exhaustive();
|
|
8471
8513
|
}
|
|
8472
8514
|
function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redemptionReimbursementRatio, sysParams, tx, txOutputsBeforeCount, collateralAssetRefInputIdx, iassetRefInputIdx, oracleIdx) {
|
|
8473
8515
|
return import_fp_ts17.function.pipe(
|
|
8474
8516
|
redemptions,
|
|
8475
8517
|
import_fp_ts17.array.reduceWithIndex(
|
|
8476
8518
|
tx,
|
|
8477
|
-
(idx, acc, [robUtxo,
|
|
8519
|
+
(idx, acc, [robUtxo, payoutAmt]) => {
|
|
8478
8520
|
const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
|
|
8479
8521
|
if ((0, import_lucid49.toHex)(robDatum.iasset) !== (0, import_lucid49.toHex)(iasset)) {
|
|
8480
8522
|
throw new Error("Only same iAsset");
|
|
@@ -8485,7 +8527,7 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8485
8527
|
if (!(0, import_cardano_offchain_common22.isSameAssetClass)(content.collateralAsset, collateralAsset)) {
|
|
8486
8528
|
throw new Error("Only same collateral asset");
|
|
8487
8529
|
}
|
|
8488
|
-
const payoutIAssetAmt =
|
|
8530
|
+
const payoutIAssetAmt = payoutAmt;
|
|
8489
8531
|
const reimburstmentIAsset = calculateFeeFromRatio(
|
|
8490
8532
|
redemptionReimbursementRatio,
|
|
8491
8533
|
payoutIAssetAmt
|
|
@@ -8520,16 +8562,14 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8520
8562
|
throw new Error("Doesn't allow required collateral asset.");
|
|
8521
8563
|
})
|
|
8522
8564
|
);
|
|
8523
|
-
const payoutCollateralAmt =
|
|
8565
|
+
const payoutCollateralAmt = payoutAmt;
|
|
8524
8566
|
const reimbursementCollateral = calculateFeeFromRatio(
|
|
8525
8567
|
redemptionReimbursementRatio,
|
|
8526
8568
|
payoutCollateralAmt
|
|
8527
8569
|
);
|
|
8528
|
-
const redeemedIAssetAmt =
|
|
8529
|
-
|
|
8530
|
-
|
|
8531
|
-
price
|
|
8532
|
-
)
|
|
8570
|
+
const redeemedIAssetAmt = iassetValueOfCollateral(
|
|
8571
|
+
payoutCollateralAmt - reimbursementCollateral,
|
|
8572
|
+
price
|
|
8533
8573
|
);
|
|
8534
8574
|
const resultVal = (0, import_lucid49.addAssets)(
|
|
8535
8575
|
robUtxo.assets,
|
|
@@ -8547,7 +8587,9 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8547
8587
|
return [resultVal, BigInt(allowedAssetIdx)];
|
|
8548
8588
|
}).exhaustive();
|
|
8549
8589
|
if ((0, import_cardano_offchain_common22.lovelacesAmt)(robOutputVal) < MIN_ROB_COLLATERAL_AMT) {
|
|
8550
|
-
throw new Error(
|
|
8590
|
+
throw new Error(
|
|
8591
|
+
"Redeeming more than available or selected ROB was incorrectly initialised."
|
|
8592
|
+
);
|
|
8551
8593
|
}
|
|
8552
8594
|
return acc.collectFrom([robUtxo], {
|
|
8553
8595
|
kind: "self",
|
|
@@ -8558,7 +8600,7 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8558
8600
|
iassetRefInputIdx,
|
|
8559
8601
|
continuingOutputIdx: txOutputsBeforeCount + BigInt(idx),
|
|
8560
8602
|
sellOrderAllowedAssetsIdx,
|
|
8561
|
-
priceOracleIdx: oracleIdx
|
|
8603
|
+
priceOracleIdx: oracleIdx
|
|
8562
8604
|
}
|
|
8563
8605
|
})
|
|
8564
8606
|
}).pay.ToContract(
|
|
@@ -8579,6 +8621,85 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8579
8621
|
)
|
|
8580
8622
|
);
|
|
8581
8623
|
}
|
|
8624
|
+
function calculateTotalCollateralForRedemption(iasset, collateralAsset, iassetPrice, allRobs, maxRobsInTx) {
|
|
8625
|
+
return import_fp_ts17.function.pipe(
|
|
8626
|
+
allRobs,
|
|
8627
|
+
import_fp_ts17.array.filterMap(([utxo, datum]) => {
|
|
8628
|
+
const isCorrectOrder = (0, import_ts_pattern19.match)(datum.orderType).returnType().with(
|
|
8629
|
+
{ BuyIAssetOrder: import_ts_pattern19.P.select() },
|
|
8630
|
+
(content) => (0, import_cardano_offchain_common22.isSameAssetClass)(content.collateralAsset, collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice) && !isBuyOrderFullyRedeemed(utxo, datum, iassetPrice)
|
|
8631
|
+
).otherwise(() => false);
|
|
8632
|
+
if ((0, import_lucid49.toHex)(datum.iasset) !== (0, import_lucid49.toHex)(iasset) || !isCorrectOrder) {
|
|
8633
|
+
return import_fp_ts17.option.none;
|
|
8634
|
+
}
|
|
8635
|
+
const collateralToSpend = robCollateralAmtToSpend(utxo, datum);
|
|
8636
|
+
return import_fp_ts17.option.some(collateralToSpend);
|
|
8637
|
+
}),
|
|
8638
|
+
// From largest to smallest
|
|
8639
|
+
import_fp_ts17.array.sort(import_fp_ts17.ord.reverse(BigIntOrd)),
|
|
8640
|
+
// We can fit only this number of redemptions with CDP open into a single Tx.
|
|
8641
|
+
import_fp_ts17.array.takeLeft(maxRobsInTx),
|
|
8642
|
+
sum
|
|
8643
|
+
);
|
|
8644
|
+
}
|
|
8645
|
+
function randomRobsSubsetSatisfyingTargetCollateral(iasset, collateralAsset, targetCollateralToSpend, iassetPrice, allLrps, maxLrpsInTx, randomiseFn = shuffle) {
|
|
8646
|
+
if (targetCollateralToSpend <= 0n || iassetValueOfCollateral(targetCollateralToSpend, iassetPrice) <= 0n) {
|
|
8647
|
+
throw new Error("Must redeem and payout more than 0.");
|
|
8648
|
+
}
|
|
8649
|
+
const shuffled = randomiseFn(
|
|
8650
|
+
import_fp_ts17.function.pipe(
|
|
8651
|
+
allLrps,
|
|
8652
|
+
import_fp_ts17.array.filter(
|
|
8653
|
+
([utxo, datum]) => (0, import_lucid49.toHex)(datum.iasset) === (0, import_lucid49.toHex)(iasset) && (0, import_ts_pattern19.match)(datum.orderType).with(
|
|
8654
|
+
{ BuyIAssetOrder: import_ts_pattern19.P.select() },
|
|
8655
|
+
(content) => (0, import_cardano_offchain_common22.isSameAssetClass)(collateralAsset, content.collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice)
|
|
8656
|
+
).otherwise(() => false) && !isBuyOrderFullyRedeemed(utxo, datum, iassetPrice)
|
|
8657
|
+
)
|
|
8658
|
+
)
|
|
8659
|
+
);
|
|
8660
|
+
let result = [];
|
|
8661
|
+
let runningSum = 0n;
|
|
8662
|
+
for (let i = 0; i < shuffled.length; i++) {
|
|
8663
|
+
const element = shuffled[i];
|
|
8664
|
+
const lovelacesToSpend = robCollateralAmtToSpend(element[0], element[1]);
|
|
8665
|
+
const remainingToRedeem = targetCollateralToSpend - runningSum;
|
|
8666
|
+
const remainingToPayout = iassetValueOfCollateral(
|
|
8667
|
+
remainingToRedeem,
|
|
8668
|
+
iassetPrice
|
|
8669
|
+
);
|
|
8670
|
+
if (result.length > 0 && remainingToPayout <= 0n) {
|
|
8671
|
+
const last = result[result.length - 1];
|
|
8672
|
+
const lastSummary = robBuyOrderSummary(last[0], last[1], iassetPrice);
|
|
8673
|
+
if (lastSummary.redeemableCollateral < lovelacesToSpend) {
|
|
8674
|
+
result.pop();
|
|
8675
|
+
runningSum -= lastSummary.redeemableCollateral;
|
|
8676
|
+
} else {
|
|
8677
|
+
continue;
|
|
8678
|
+
}
|
|
8679
|
+
}
|
|
8680
|
+
result = insertSorted(
|
|
8681
|
+
result,
|
|
8682
|
+
element,
|
|
8683
|
+
import_fp_ts17.ord.contramap(
|
|
8684
|
+
([utxo, dat]) => robCollateralAmtToSpend(utxo, dat)
|
|
8685
|
+
// From highest to lowest
|
|
8686
|
+
)(import_fp_ts17.ord.reverse(BigIntOrd))
|
|
8687
|
+
);
|
|
8688
|
+
runningSum += lovelacesToSpend;
|
|
8689
|
+
if (result.length > maxLrpsInTx) {
|
|
8690
|
+
const popped = result.pop();
|
|
8691
|
+
runningSum -= robCollateralAmtToSpend(popped[0], popped[1]);
|
|
8692
|
+
}
|
|
8693
|
+
if (runningSum >= targetCollateralToSpend) {
|
|
8694
|
+
return result;
|
|
8695
|
+
}
|
|
8696
|
+
}
|
|
8697
|
+
const remainingToSpend = targetCollateralToSpend - runningSum;
|
|
8698
|
+
if (remainingToSpend > 0n && iassetValueOfCollateral(remainingToSpend, iassetPrice) > 0n) {
|
|
8699
|
+
throw new Error("Couldn't achieve target lovelaces");
|
|
8700
|
+
}
|
|
8701
|
+
return result;
|
|
8702
|
+
}
|
|
8582
8703
|
|
|
8583
8704
|
// src/contracts/rob/types.ts
|
|
8584
8705
|
var import_lucid50 = require("@lucid-evolution/lucid");
|
|
@@ -8718,7 +8839,7 @@ async function redeemRob(redemptionRobsData, priceOracleOutRef, iassetOutRef, co
|
|
|
8718
8839
|
0n,
|
|
8719
8840
|
refInputIdxs[2],
|
|
8720
8841
|
refInputIdxs[1],
|
|
8721
|
-
priceOracleOutRef !== void 0 ? refInputIdxs[3] :
|
|
8842
|
+
priceOracleOutRef !== void 0 ? { OracleRefInputIdx: refInputIdxs[3] } : "OracleVoid"
|
|
8722
8843
|
);
|
|
8723
8844
|
tx.readFrom(allRefInputs);
|
|
8724
8845
|
return tx;
|
|
@@ -8735,12 +8856,12 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
|
|
|
8735
8856
|
(_) => new Error("Expected a single ROB UTXO.")
|
|
8736
8857
|
);
|
|
8737
8858
|
const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
|
|
8738
|
-
if (adjustmentAmt === 0n && isFullyRedeemed(robUtxo, robDatum, sysParams)) {
|
|
8859
|
+
if (adjustmentAmt === 0n && isFullyRedeemed(robUtxo, robDatum, sysParams.cdpParams.cdpAssetSymbol)) {
|
|
8739
8860
|
throw new Error(
|
|
8740
8861
|
"When there's no more lovelaces to spend, use close instead of claim."
|
|
8741
8862
|
);
|
|
8742
8863
|
}
|
|
8743
|
-
if (adjustmentAmt < 0 &&
|
|
8864
|
+
if (adjustmentAmt < 0 && robAmtToSpend(robUtxo, robDatum, sysParams.cdpParams.cdpAssetSymbol) <= -adjustmentAmt) {
|
|
8744
8865
|
throw new Error(
|
|
8745
8866
|
"Can't adjust negatively by more than available. Also, for adjusting by exactly the amount deposited, a close action should be used instead."
|
|
8746
8867
|
);
|
|
@@ -8861,11 +8982,443 @@ var mkRobValidatorFromSP = (params) => {
|
|
|
8861
8982
|
};
|
|
8862
8983
|
};
|
|
8863
8984
|
|
|
8985
|
+
// src/contracts/rob-leverage/transactions.ts
|
|
8986
|
+
var import_lucid53 = require("@lucid-evolution/lucid");
|
|
8987
|
+
|
|
8988
|
+
// src/contracts/rob-leverage/helpers.ts
|
|
8989
|
+
var import_fp_ts19 = require("fp-ts");
|
|
8990
|
+
var import_decimal = require("decimal.js");
|
|
8991
|
+
var MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
|
|
8992
|
+
function approximateLeverageRedemptions(baseCollateral, targetLeverage, redemptionReimbursementRatio, debtMintingFeeRatio) {
|
|
8993
|
+
const debtMintingFeeRatioDecimal = (0, import_decimal.Decimal)(debtMintingFeeRatio.numerator).div(
|
|
8994
|
+
debtMintingFeeRatio.denominator
|
|
8995
|
+
);
|
|
8996
|
+
const redemptionReimbursementRatioDecimal = (0, import_decimal.Decimal)(
|
|
8997
|
+
redemptionReimbursementRatio.numerator
|
|
8998
|
+
).div(redemptionReimbursementRatio.denominator);
|
|
8999
|
+
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
9000
|
+
redemptionReimbursementRatioDecimal
|
|
9001
|
+
);
|
|
9002
|
+
const bExFees = (0, import_decimal.Decimal)(baseCollateral).mul(targetLeverage).minus(baseCollateral).floor();
|
|
9003
|
+
const b = bExFees.div((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
9004
|
+
const collateralRatio = {
|
|
9005
|
+
numerator: fromDecimal((0, import_decimal.Decimal)(baseCollateral).add(bExFees)),
|
|
9006
|
+
denominator: fromDecimal(b)
|
|
9007
|
+
};
|
|
9008
|
+
return {
|
|
9009
|
+
leverage: targetLeverage,
|
|
9010
|
+
collateralRatio,
|
|
9011
|
+
redeemedCollateral: fromDecimal(bExFees)
|
|
9012
|
+
};
|
|
9013
|
+
}
|
|
9014
|
+
function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement, redemptionReimbursementRatio, iassetPrice, redemptionLrps) {
|
|
9015
|
+
const priceDecimal = (0, import_decimal.Decimal)(iassetPrice.numerator).div(
|
|
9016
|
+
iassetPrice.denominator
|
|
9017
|
+
);
|
|
9018
|
+
const reimbRatio = (0, import_decimal.Decimal)(redemptionReimbursementRatio.numerator).div(
|
|
9019
|
+
redemptionReimbursementRatio.denominator
|
|
9020
|
+
);
|
|
9021
|
+
const redemptionDetails = import_fp_ts19.function.pipe(
|
|
9022
|
+
redemptionLrps,
|
|
9023
|
+
import_fp_ts19.array.reduce(
|
|
9024
|
+
{
|
|
9025
|
+
remainingCollateralToSpend: lovelacesForRedemptionWithReimbursement,
|
|
9026
|
+
redemptions: []
|
|
9027
|
+
},
|
|
9028
|
+
(acc, lrp) => {
|
|
9029
|
+
if (acc.remainingCollateralToSpend <= 0n || iassetValueOfCollateral(
|
|
9030
|
+
acc.remainingCollateralToSpend,
|
|
9031
|
+
iassetPrice
|
|
9032
|
+
) <= 0n) {
|
|
9033
|
+
return acc;
|
|
9034
|
+
}
|
|
9035
|
+
const collateralToSpend = robCollateralAmtToSpend(lrp[0], lrp[1]);
|
|
9036
|
+
if (collateralToSpend === 0n) {
|
|
9037
|
+
return acc;
|
|
9038
|
+
}
|
|
9039
|
+
const newRemainingCollateral = bigintMax(
|
|
9040
|
+
acc.remainingCollateralToSpend - collateralToSpend,
|
|
9041
|
+
0n
|
|
9042
|
+
);
|
|
9043
|
+
const collateralToSpendInitial = acc.remainingCollateralToSpend - newRemainingCollateral;
|
|
9044
|
+
const finalPayoutIAssets = fromDecimal(
|
|
9045
|
+
(0, import_decimal.Decimal)(collateralToSpendInitial).div(priceDecimal).floor().div((0, import_decimal.Decimal)(1).minus(reimbRatio)).floor()
|
|
9046
|
+
);
|
|
9047
|
+
const feeIAssetAmt = calculateFeeFromRatio(
|
|
9048
|
+
redemptionReimbursementRatio,
|
|
9049
|
+
finalPayoutIAssets
|
|
9050
|
+
);
|
|
9051
|
+
const finalCollateralToSpend = rationalFloor(
|
|
9052
|
+
rationalMul(
|
|
9053
|
+
rationalFromInt(finalPayoutIAssets - feeIAssetAmt),
|
|
9054
|
+
iassetPrice
|
|
9055
|
+
)
|
|
9056
|
+
);
|
|
9057
|
+
return {
|
|
9058
|
+
remainingCollateralToSpend: acc.remainingCollateralToSpend - finalCollateralToSpend,
|
|
9059
|
+
redemptions: [
|
|
9060
|
+
...acc.redemptions,
|
|
9061
|
+
{
|
|
9062
|
+
utxo: lrp[0],
|
|
9063
|
+
iassetsPayoutAmt: finalPayoutIAssets,
|
|
9064
|
+
redeemedCollateral: finalCollateralToSpend,
|
|
9065
|
+
reimbursementIAssetAmt: feeIAssetAmt
|
|
9066
|
+
}
|
|
9067
|
+
]
|
|
9068
|
+
};
|
|
9069
|
+
}
|
|
9070
|
+
)
|
|
9071
|
+
);
|
|
9072
|
+
const res = import_fp_ts19.function.pipe(
|
|
9073
|
+
redemptionDetails.redemptions,
|
|
9074
|
+
import_fp_ts19.array.reduce(
|
|
9075
|
+
{
|
|
9076
|
+
redeemedCollateral: 0n,
|
|
9077
|
+
payoutIAssets: 0n,
|
|
9078
|
+
reimbursementIAssets: 0n
|
|
9079
|
+
},
|
|
9080
|
+
(acc, details) => {
|
|
9081
|
+
return {
|
|
9082
|
+
redeemedCollateral: acc.redeemedCollateral + details.redeemedCollateral,
|
|
9083
|
+
reimbursementIAssets: acc.reimbursementIAssets + details.reimbursementIAssetAmt,
|
|
9084
|
+
payoutIAssets: acc.payoutIAssets + details.iassetsPayoutAmt
|
|
9085
|
+
};
|
|
9086
|
+
}
|
|
9087
|
+
)
|
|
9088
|
+
);
|
|
9089
|
+
return {
|
|
9090
|
+
redemptions: redemptionDetails.redemptions,
|
|
9091
|
+
totalRedeemedCollateral: res.redeemedCollateral,
|
|
9092
|
+
totalReimbursedIAsset: res.reimbursementIAssets,
|
|
9093
|
+
totalIAssetPayout: res.payoutIAssets
|
|
9094
|
+
};
|
|
9095
|
+
}
|
|
9096
|
+
function calculateCollateralRatioFromLeverage(iasset, collateralAsset, leverage, baseCollateral, iassetPrice, debtMintingFeePercentage, redemptionReimbursementPercentage, allLrps) {
|
|
9097
|
+
const debtMintingFeeRatioDecimal = (0, import_decimal.Decimal)(
|
|
9098
|
+
debtMintingFeePercentage.getOnChainInt
|
|
9099
|
+
).div(OCD_DECIMAL_UNIT).div(100);
|
|
9100
|
+
const redemptionReimbursementRatioDecimal = (0, import_decimal.Decimal)(
|
|
9101
|
+
redemptionReimbursementPercentage.getOnChainInt
|
|
9102
|
+
).div(OCD_DECIMAL_UNIT).div(100);
|
|
9103
|
+
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
9104
|
+
redemptionReimbursementRatioDecimal
|
|
9105
|
+
);
|
|
9106
|
+
const maxAvailableCollateralForRedemption = calculateTotalCollateralForRedemption(
|
|
9107
|
+
iasset,
|
|
9108
|
+
collateralAsset,
|
|
9109
|
+
iassetPrice,
|
|
9110
|
+
allLrps,
|
|
9111
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN
|
|
9112
|
+
);
|
|
9113
|
+
if (leverage <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
|
|
9114
|
+
return void 0;
|
|
9115
|
+
}
|
|
9116
|
+
const bExFees = (0, import_decimal.Decimal)(baseCollateral).mul(leverage).minus(baseCollateral).floor();
|
|
9117
|
+
const b = bExFees.div((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
9118
|
+
const cappedB = bigintMin(
|
|
9119
|
+
maxAvailableCollateralForRedemption,
|
|
9120
|
+
fromDecimal(b)
|
|
9121
|
+
);
|
|
9122
|
+
const cappedBExFees = (0, import_decimal.Decimal)(cappedB).mul((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
9123
|
+
const collateralRatio = (0, import_decimal.Decimal)(
|
|
9124
|
+
(0, import_decimal.Decimal)(baseCollateral).add(cappedBExFees)
|
|
9125
|
+
).div(cappedB);
|
|
9126
|
+
return {
|
|
9127
|
+
getOnChainInt: fromDecimal(
|
|
9128
|
+
collateralRatio.mul(100n * OCD_DECIMAL_UNIT).floor()
|
|
9129
|
+
)
|
|
9130
|
+
};
|
|
9131
|
+
}
|
|
9132
|
+
function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collateralRatio, baseCollateral, iassetPrice, debtMintingFeeRatio, redemptionReimbursementRatio, allLrps) {
|
|
9133
|
+
const debtMintingFeeRatioDecimal = (0, import_decimal.Decimal)(debtMintingFeeRatio.numerator).div(
|
|
9134
|
+
debtMintingFeeRatio.denominator
|
|
9135
|
+
);
|
|
9136
|
+
const redemptionReimbursementRatioDecimal = (0, import_decimal.Decimal)(
|
|
9137
|
+
redemptionReimbursementRatio.numerator
|
|
9138
|
+
).div(redemptionReimbursementRatio.denominator);
|
|
9139
|
+
const totalFeeRatio = debtMintingFeeRatioDecimal.add(
|
|
9140
|
+
redemptionReimbursementRatioDecimal
|
|
9141
|
+
);
|
|
9142
|
+
const collateralRatioDecimal = (0, import_decimal.Decimal)(collateralRatio.numerator).div(
|
|
9143
|
+
collateralRatio.denominator
|
|
9144
|
+
);
|
|
9145
|
+
const maxAvailableCollateralForRedemption = calculateTotalCollateralForRedemption(
|
|
9146
|
+
iasset,
|
|
9147
|
+
collateralAsset,
|
|
9148
|
+
iassetPrice,
|
|
9149
|
+
allLrps,
|
|
9150
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN
|
|
9151
|
+
);
|
|
9152
|
+
if (collateralRatioDecimal.toNumber() <= 1 || baseCollateral <= 0n || maxAvailableCollateralForRedemption <= 0n) {
|
|
9153
|
+
return void 0;
|
|
9154
|
+
}
|
|
9155
|
+
const theoreticalMaxLeverage = (0, import_decimal.Decimal)((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).div(collateralRatioDecimal.minus(1).add(totalFeeRatio)).add(1);
|
|
9156
|
+
const bExFees = theoreticalMaxLeverage.mul(baseCollateral).minus(baseCollateral).floor();
|
|
9157
|
+
const b = bExFees.div((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
9158
|
+
const cappedB = bigintMin(
|
|
9159
|
+
maxAvailableCollateralForRedemption,
|
|
9160
|
+
fromDecimal(b)
|
|
9161
|
+
);
|
|
9162
|
+
const cappedBExFees = (0, import_decimal.Decimal)(cappedB).mul((0, import_decimal.Decimal)(1).minus(totalFeeRatio)).floor();
|
|
9163
|
+
return (0, import_decimal.Decimal)(baseCollateral).add(cappedBExFees).div(baseCollateral).toNumber();
|
|
9164
|
+
}
|
|
9165
|
+
|
|
9166
|
+
// src/contracts/rob-leverage/transactions.ts
|
|
9167
|
+
var import_cardano_offchain_common24 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
9168
|
+
var import_decimal2 = __toESM(require("decimal.js"));
|
|
9169
|
+
async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, cdpCreatorOref, interestOracleOref, treasuryOref, sysParams, lucid, allRobs, currentSlot, pythMessage = void 0, pythStateOref = void 0) {
|
|
9170
|
+
const network = lucid.config().network;
|
|
9171
|
+
const currentTime = BigInt((0, import_lucid53.slotToUnixTime)(network, currentSlot));
|
|
9172
|
+
const [pkh, skh] = await addrDetails(lucid);
|
|
9173
|
+
const robScriptRefUtxo = matchSingle(
|
|
9174
|
+
await lucid.utxosByOutRef([
|
|
9175
|
+
fromSystemParamsScriptRef(sysParams.scriptReferences.robValidatorRef)
|
|
9176
|
+
]),
|
|
9177
|
+
(_2) => new Error("Expected a single ROB Ref Script UTXO")
|
|
9178
|
+
);
|
|
9179
|
+
const cdpCreatorRefScriptUtxo = matchSingle(
|
|
9180
|
+
await lucid.utxosByOutRef([
|
|
9181
|
+
fromSystemParamsScriptRef(
|
|
9182
|
+
sysParams.scriptReferences.cdpCreatorValidatorRef
|
|
9183
|
+
)
|
|
9184
|
+
]),
|
|
9185
|
+
(_2) => new Error("Expected a single cdp creator Ref Script UTXO")
|
|
9186
|
+
);
|
|
9187
|
+
const cdpAuthTokenPolicyRefScriptUtxo = matchSingle(
|
|
9188
|
+
await lucid.utxosByOutRef([
|
|
9189
|
+
fromSystemParamsScriptRef(
|
|
9190
|
+
sysParams.scriptReferences.authTokenPolicies.cdpAuthTokenRef
|
|
9191
|
+
)
|
|
9192
|
+
]),
|
|
9193
|
+
(_2) => new Error("Expected a single cdp auth token policy Ref Script UTXO")
|
|
9194
|
+
);
|
|
9195
|
+
const iAssetTokenPolicyRefScriptUtxo = matchSingle(
|
|
9196
|
+
await lucid.utxosByOutRef([
|
|
9197
|
+
fromSystemParamsScriptRef(
|
|
9198
|
+
sysParams.scriptReferences.iAssetTokenPolicyRef
|
|
9199
|
+
)
|
|
9200
|
+
]),
|
|
9201
|
+
(_2) => new Error("Expected a single iasset token policy Ref Script UTXO")
|
|
9202
|
+
);
|
|
9203
|
+
const cdpCreatorUtxo = matchSingle(
|
|
9204
|
+
await lucid.utxosByOutRef([cdpCreatorOref]),
|
|
9205
|
+
(_2) => new Error("Expected a single CDP creator UTXO")
|
|
9206
|
+
);
|
|
9207
|
+
const interestOracleUtxo = matchSingle(
|
|
9208
|
+
await lucid.utxosByOutRef([interestOracleOref]),
|
|
9209
|
+
(_2) => new Error("Expected a single interest oracle UTXO")
|
|
9210
|
+
);
|
|
9211
|
+
const interestOracleDatum = parseInterestOracleDatum(
|
|
9212
|
+
getInlineDatumOrThrow(interestOracleUtxo)
|
|
9213
|
+
);
|
|
9214
|
+
const iassetUtxo = matchSingle(
|
|
9215
|
+
await lucid.utxosByOutRef([iassetOutRef]),
|
|
9216
|
+
(_2) => new Error("Expected a single IAsset UTXO")
|
|
9217
|
+
);
|
|
9218
|
+
const iassetDatum = parseIAssetDatumOrThrow(
|
|
9219
|
+
getInlineDatumOrThrow(iassetUtxo)
|
|
9220
|
+
);
|
|
9221
|
+
const collateralAssetUtxo = matchSingle(
|
|
9222
|
+
await lucid.utxosByOutRef([collateralAssetOutRef]),
|
|
9223
|
+
(_2) => new Error("Expected a single collateral asset UTXO")
|
|
9224
|
+
);
|
|
9225
|
+
const collateralAssetDatum = parseCollateralAssetDatumOrThrow(
|
|
9226
|
+
getInlineDatumOrThrow(collateralAssetUtxo)
|
|
9227
|
+
);
|
|
9228
|
+
const [price, _] = await retrieveAdjustedPrice(
|
|
9229
|
+
iassetDatum.assetName,
|
|
9230
|
+
collateralAssetDatum.collateralAsset,
|
|
9231
|
+
collateralAssetDatum.priceInfo,
|
|
9232
|
+
collateralAssetDatum.extraDecimals,
|
|
9233
|
+
priceOracleOutRef,
|
|
9234
|
+
pythMessage,
|
|
9235
|
+
sysParams.pythConfig,
|
|
9236
|
+
lucid
|
|
9237
|
+
);
|
|
9238
|
+
const maxLeverage = calculateLeverageFromCollateralRatio(
|
|
9239
|
+
collateralAssetDatum.iasset,
|
|
9240
|
+
collateralAssetDatum.collateralAsset,
|
|
9241
|
+
collateralAssetDatum.maintenanceRatio,
|
|
9242
|
+
baseCollateral,
|
|
9243
|
+
price,
|
|
9244
|
+
iassetDatum.debtMintingFeeRatio,
|
|
9245
|
+
iassetDatum.redemptionReimbursementRatio,
|
|
9246
|
+
allRobs
|
|
9247
|
+
);
|
|
9248
|
+
if (!maxLeverage) {
|
|
9249
|
+
throw new Error("Can't calculate max leverage with those parameters.");
|
|
9250
|
+
}
|
|
9251
|
+
const leverageSummary = approximateLeverageRedemptions(
|
|
9252
|
+
baseCollateral,
|
|
9253
|
+
leverage,
|
|
9254
|
+
iassetDatum.redemptionProcessingFeeRatio,
|
|
9255
|
+
iassetDatum.debtMintingFeeRatio
|
|
9256
|
+
);
|
|
9257
|
+
if (maxLeverage < leverageSummary.leverage) {
|
|
9258
|
+
throw new Error("Can't use more leverage than max.");
|
|
9259
|
+
}
|
|
9260
|
+
if (rationalToFloat(leverageSummary.collateralRatio) < rationalToFloat(collateralAssetDatum.maintenanceRatio)) {
|
|
9261
|
+
throw new Error(
|
|
9262
|
+
"Can't have collateral ratio smaller than maintenance ratio"
|
|
9263
|
+
);
|
|
9264
|
+
}
|
|
9265
|
+
const redemptionDetails = summarizeActualLeverageRedemptions(
|
|
9266
|
+
leverageSummary.redeemedCollateral,
|
|
9267
|
+
iassetDatum.redemptionReimbursementRatio,
|
|
9268
|
+
price,
|
|
9269
|
+
randomRobsSubsetSatisfyingTargetCollateral(
|
|
9270
|
+
iassetDatum.assetName,
|
|
9271
|
+
collateralAssetDatum.collateralAsset,
|
|
9272
|
+
leverageSummary.redeemedCollateral,
|
|
9273
|
+
price,
|
|
9274
|
+
allRobs,
|
|
9275
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN
|
|
9276
|
+
)
|
|
9277
|
+
);
|
|
9278
|
+
const mintedAmt = fromDecimal(
|
|
9279
|
+
(0, import_decimal2.default)(redemptionDetails.totalIAssetPayout).div(
|
|
9280
|
+
(0, import_decimal2.default)(1).minus(
|
|
9281
|
+
(0, import_decimal2.default)(iassetDatum.debtMintingFeeRatio.numerator).div(
|
|
9282
|
+
iassetDatum.debtMintingFeeRatio.denominator
|
|
9283
|
+
)
|
|
9284
|
+
)
|
|
9285
|
+
).floor()
|
|
9286
|
+
);
|
|
9287
|
+
const debtMintingFee = calculateFeeFromRatio(
|
|
9288
|
+
iassetDatum.debtMintingFeeRatio,
|
|
9289
|
+
mintedAmt
|
|
9290
|
+
);
|
|
9291
|
+
const collateralAmt = redemptionDetails.totalRedeemedCollateral + baseCollateral;
|
|
9292
|
+
const cdpNftVal = (0, import_cardano_offchain_common24.mkAssetsOf)(
|
|
9293
|
+
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
9294
|
+
1n
|
|
9295
|
+
);
|
|
9296
|
+
const iassetClass = {
|
|
9297
|
+
currencySymbol: (0, import_lucid53.fromHex)(
|
|
9298
|
+
sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol
|
|
9299
|
+
),
|
|
9300
|
+
tokenName: iassetDatum.assetName
|
|
9301
|
+
};
|
|
9302
|
+
const iassetTokensVal = (0, import_cardano_offchain_common24.mkAssetsOf)(iassetClass, mintedAmt);
|
|
9303
|
+
const refScripts = [
|
|
9304
|
+
cdpCreatorRefScriptUtxo,
|
|
9305
|
+
cdpAuthTokenPolicyRefScriptUtxo,
|
|
9306
|
+
iAssetTokenPolicyRefScriptUtxo,
|
|
9307
|
+
robScriptRefUtxo
|
|
9308
|
+
];
|
|
9309
|
+
const tx = lucid.newTx().readFrom(refScripts).mintAssets(cdpNftVal, import_lucid53.Data.void()).mintAssets(iassetTokensVal, import_lucid53.Data.void()).pay.ToContract(
|
|
9310
|
+
createScriptAddress(network, sysParams.validatorHashes.cdpHash, skh),
|
|
9311
|
+
{
|
|
9312
|
+
kind: "inline",
|
|
9313
|
+
value: serialiseCdpDatum({
|
|
9314
|
+
cdpOwner: (0, import_lucid53.fromHex)(pkh.hash),
|
|
9315
|
+
iasset: iassetDatum.assetName,
|
|
9316
|
+
collateralAsset: collateralAssetDatum.collateralAsset,
|
|
9317
|
+
mintedAmt,
|
|
9318
|
+
cdpFees: {
|
|
9319
|
+
ActiveCDPInterestTracking: {
|
|
9320
|
+
lastSettled: currentTime,
|
|
9321
|
+
unitaryInterestSnapshot: calculateUnitaryInterestSinceOracleLastUpdated(
|
|
9322
|
+
currentTime,
|
|
9323
|
+
interestOracleDatum
|
|
9324
|
+
) + interestOracleDatum.unitaryInterest
|
|
9325
|
+
}
|
|
9326
|
+
}
|
|
9327
|
+
})
|
|
9328
|
+
},
|
|
9329
|
+
(0, import_lucid53.addAssets)(
|
|
9330
|
+
cdpNftVal,
|
|
9331
|
+
(0, import_cardano_offchain_common24.mkAssetsOf)(collateralAssetDatum.collateralAsset, collateralAmt)
|
|
9332
|
+
)
|
|
9333
|
+
).pay.ToContract(
|
|
9334
|
+
cdpCreatorUtxo.address,
|
|
9335
|
+
{
|
|
9336
|
+
kind: "inline",
|
|
9337
|
+
value: serialiseCDPCreatorDatum({
|
|
9338
|
+
creatorInputOref: {
|
|
9339
|
+
outputIndex: BigInt(cdpCreatorUtxo.outputIndex),
|
|
9340
|
+
txHash: (0, import_lucid53.fromHex)(cdpCreatorUtxo.txHash)
|
|
9341
|
+
}
|
|
9342
|
+
})
|
|
9343
|
+
},
|
|
9344
|
+
cdpCreatorUtxo.assets
|
|
9345
|
+
);
|
|
9346
|
+
const treasuryRefScriptUtxo = debtMintingFee > 0n ? await treasuryFeeTx(
|
|
9347
|
+
iassetClass,
|
|
9348
|
+
debtMintingFee,
|
|
9349
|
+
0n,
|
|
9350
|
+
lucid,
|
|
9351
|
+
sysParams,
|
|
9352
|
+
tx,
|
|
9353
|
+
cdpCreatorUtxo,
|
|
9354
|
+
treasuryOref
|
|
9355
|
+
) : void 0;
|
|
9356
|
+
const { interval, referenceInputs: refInputs } = await attachOracle(
|
|
9357
|
+
iassetDatum.assetName,
|
|
9358
|
+
collateralAssetDatum.collateralAsset,
|
|
9359
|
+
collateralAssetDatum.priceInfo,
|
|
9360
|
+
priceOracleOutRef,
|
|
9361
|
+
pythStateOref,
|
|
9362
|
+
pythMessage,
|
|
9363
|
+
sysParams.pythConfig,
|
|
9364
|
+
sysParams.cdpCreatorParams.biasTime,
|
|
9365
|
+
currentSlot,
|
|
9366
|
+
lucid,
|
|
9367
|
+
tx
|
|
9368
|
+
);
|
|
9369
|
+
const referenceInputs = [
|
|
9370
|
+
interestOracleUtxo,
|
|
9371
|
+
iassetUtxo,
|
|
9372
|
+
collateralAssetUtxo,
|
|
9373
|
+
...refInputs
|
|
9374
|
+
];
|
|
9375
|
+
const refInputsIndices = (0, import_lucid53.getInputIndices)(referenceInputs, [
|
|
9376
|
+
...referenceInputs,
|
|
9377
|
+
...refScripts,
|
|
9378
|
+
...treasuryRefScriptUtxo != null ? [treasuryRefScriptUtxo] : []
|
|
9379
|
+
]);
|
|
9380
|
+
const oracleIdx = priceOracleOutRef !== void 0 ? { OracleRefInputIdx: refInputsIndices[3] } : "OracleVoid";
|
|
9381
|
+
tx.validFrom(interval.validFrom).validTo(interval.validTo).readFrom(referenceInputs).collectFrom([cdpCreatorUtxo], {
|
|
9382
|
+
kind: "self",
|
|
9383
|
+
makeRedeemer: (inputIdx) => {
|
|
9384
|
+
return serialiseCDPCreatorRedeemer({
|
|
9385
|
+
CreateCDP: {
|
|
9386
|
+
cdpOwner: (0, import_lucid53.fromHex)(pkh.hash),
|
|
9387
|
+
minted: mintedAmt,
|
|
9388
|
+
collateralAmt,
|
|
9389
|
+
currentTime,
|
|
9390
|
+
creatorInputIdx: inputIdx,
|
|
9391
|
+
creatorOutputIdx: 1n,
|
|
9392
|
+
cdpOutputIdx: 0n,
|
|
9393
|
+
iassetRefInputIdx: refInputsIndices[1],
|
|
9394
|
+
collateralAssetRefInputIdx: refInputsIndices[2],
|
|
9395
|
+
interestOracleRefInputIdx: refInputsIndices[0],
|
|
9396
|
+
priceOracleIdx: oracleIdx
|
|
9397
|
+
}
|
|
9398
|
+
});
|
|
9399
|
+
}
|
|
9400
|
+
});
|
|
9401
|
+
buildRedemptionsTx(
|
|
9402
|
+
redemptionDetails.redemptions.map((r) => [r.utxo, r.iassetsPayoutAmt]),
|
|
9403
|
+
iassetDatum.assetName,
|
|
9404
|
+
collateralAssetDatum.collateralAsset,
|
|
9405
|
+
price,
|
|
9406
|
+
iassetDatum.redemptionReimbursementRatio,
|
|
9407
|
+
sysParams,
|
|
9408
|
+
tx,
|
|
9409
|
+
2n + (debtMintingFee > 0n ? 1n : 0n),
|
|
9410
|
+
refInputsIndices[2],
|
|
9411
|
+
refInputsIndices[1],
|
|
9412
|
+
oracleIdx
|
|
9413
|
+
);
|
|
9414
|
+
return tx;
|
|
9415
|
+
}
|
|
9416
|
+
|
|
8864
9417
|
// src/contracts/price-oracle/transactions.ts
|
|
8865
|
-
var
|
|
9418
|
+
var import_lucid55 = require("@lucid-evolution/lucid");
|
|
8866
9419
|
|
|
8867
9420
|
// src/contracts/price-oracle/scripts.ts
|
|
8868
|
-
var
|
|
9421
|
+
var import_lucid54 = require("@lucid-evolution/lucid");
|
|
8869
9422
|
|
|
8870
9423
|
// src/validators/price-oracle-validator.ts
|
|
8871
9424
|
var _priceOracleValidator = {
|
|
@@ -8878,18 +9431,18 @@ var _priceOracleValidator = {
|
|
|
8878
9431
|
function mkPriceOracleValidator(params) {
|
|
8879
9432
|
return {
|
|
8880
9433
|
type: "PlutusV3",
|
|
8881
|
-
script: (0,
|
|
9434
|
+
script: (0, import_lucid54.applyParamsToScript)(_priceOracleValidator.cborHex, [
|
|
8882
9435
|
castPriceOracleParams(params)
|
|
8883
9436
|
])
|
|
8884
9437
|
};
|
|
8885
9438
|
}
|
|
8886
9439
|
|
|
8887
9440
|
// src/contracts/price-oracle/transactions.ts
|
|
8888
|
-
var
|
|
9441
|
+
var import_cardano_offchain_common25 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
8889
9442
|
var Core2 = __toESM(require("@evolution-sdk/evolution"));
|
|
8890
9443
|
async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, currentSlot, refOutRef, auxiliaryData) {
|
|
8891
9444
|
const network = lucid.config().network;
|
|
8892
|
-
const now = BigInt((0,
|
|
9445
|
+
const now = BigInt((0, import_lucid55.slotToUnixTime)(network, currentSlot));
|
|
8893
9446
|
if (!refOutRef) {
|
|
8894
9447
|
refOutRef = (await lucid.wallet().getUtxos())[0];
|
|
8895
9448
|
}
|
|
@@ -8900,31 +9453,31 @@ async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, cu
|
|
|
8900
9453
|
},
|
|
8901
9454
|
mintAmounts: [
|
|
8902
9455
|
{
|
|
8903
|
-
tokenName: (0,
|
|
9456
|
+
tokenName: (0, import_lucid55.fromText)(assetName),
|
|
8904
9457
|
amount: 1n
|
|
8905
9458
|
}
|
|
8906
9459
|
]
|
|
8907
9460
|
});
|
|
8908
9461
|
const priceOracleNft = {
|
|
8909
|
-
currencySymbol: (0,
|
|
8910
|
-
tokenName: (0,
|
|
9462
|
+
currencySymbol: (0, import_lucid55.fromHex)(oracleNftPolicyId),
|
|
9463
|
+
tokenName: (0, import_lucid55.fromHex)((0, import_lucid55.fromText)(assetName))
|
|
8911
9464
|
};
|
|
8912
9465
|
const oracleValidator = mkPriceOracleValidator(oracleParams);
|
|
8913
9466
|
const oracleDatum = {
|
|
8914
9467
|
price: startPrice,
|
|
8915
9468
|
expirationTime: BigInt(now) + oracleParams.expirationPeriod,
|
|
8916
|
-
auxiliaryData: auxiliaryData ?? Core2.Data.fromCBORHex(
|
|
9469
|
+
auxiliaryData: auxiliaryData ?? Core2.Data.fromCBORHex(import_lucid55.Data.void())
|
|
8917
9470
|
};
|
|
8918
9471
|
tx.pay.ToContract(
|
|
8919
|
-
(0,
|
|
9472
|
+
(0, import_lucid55.validatorToAddress)(lucid.config().network, oracleValidator),
|
|
8920
9473
|
{ kind: "inline", value: serialisePriceOracleDatum(oracleDatum) },
|
|
8921
|
-
(0,
|
|
9474
|
+
(0, import_lucid55.addAssets)((0, import_cardano_offchain_common25.mkAssetsOf)(priceOracleNft, 1n))
|
|
8922
9475
|
);
|
|
8923
9476
|
return [tx, priceOracleNft];
|
|
8924
9477
|
}
|
|
8925
9478
|
async function feedPriceOracleTx(lucid, oracleOref, newPrice, oracleParams, currentSlot, auxiliaryData) {
|
|
8926
9479
|
const network = lucid.config().network;
|
|
8927
|
-
const currentTime = BigInt((0,
|
|
9480
|
+
const currentTime = BigInt((0, import_lucid55.slotToUnixTime)(network, currentSlot));
|
|
8928
9481
|
const priceOracleUtxo = matchSingle(
|
|
8929
9482
|
await lucid.utxosByOutRef([oracleOref]),
|
|
8930
9483
|
(_) => new Error("Expected a single price oracle UTXO")
|
|
@@ -8943,7 +9496,7 @@ async function feedPriceOracleTx(lucid, oracleOref, newPrice, oracleParams, curr
|
|
|
8943
9496
|
value: serialisePriceOracleDatum({
|
|
8944
9497
|
price: newPrice,
|
|
8945
9498
|
expirationTime: currentTime + oracleParams.expirationPeriod,
|
|
8946
|
-
auxiliaryData: auxiliaryData ?? Core2.Data.fromCBORHex(
|
|
9499
|
+
auxiliaryData: auxiliaryData ?? Core2.Data.fromCBORHex(import_lucid55.Data.void())
|
|
8947
9500
|
})
|
|
8948
9501
|
},
|
|
8949
9502
|
priceOracleUtxo.assets
|
|
@@ -8951,7 +9504,7 @@ async function feedPriceOracleTx(lucid, oracleOref, newPrice, oracleParams, curr
|
|
|
8951
9504
|
}
|
|
8952
9505
|
|
|
8953
9506
|
// src/utils/helper-txs.ts
|
|
8954
|
-
var
|
|
9507
|
+
var import_lucid56 = require("@lucid-evolution/lucid");
|
|
8955
9508
|
|
|
8956
9509
|
// src/scripts/always-fail-validator.ts
|
|
8957
9510
|
var alwaysFailValidator = {
|
|
@@ -8961,18 +9514,18 @@ var alwaysFailValidator = {
|
|
|
8961
9514
|
|
|
8962
9515
|
// src/utils/helper-txs.ts
|
|
8963
9516
|
async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
|
|
8964
|
-
const scriptAddr = (0,
|
|
9517
|
+
const scriptAddr = (0, import_lucid56.validatorToAddress)(network, alwaysFailValidator);
|
|
8965
9518
|
const txHash = await lucid.newTx().pay.ToAddressWithData(scriptAddr, void 0, {}, scriptRefValidator).complete().then((tx) => tx.sign.withWallet().complete()).then((tx) => tx.submit());
|
|
8966
9519
|
await lucid.awaitTx(txHash);
|
|
8967
9520
|
return { txHash, outputIndex: 0 };
|
|
8968
9521
|
}
|
|
8969
9522
|
|
|
8970
9523
|
// src/contracts/initialize/helpers.ts
|
|
8971
|
-
var
|
|
8972
|
-
var
|
|
9524
|
+
var import_lucid60 = require("@lucid-evolution/lucid");
|
|
9525
|
+
var import_cardano_offchain_common26 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
8973
9526
|
|
|
8974
9527
|
// src/scripts/auth-token-policy.ts
|
|
8975
|
-
var
|
|
9528
|
+
var import_lucid57 = require("@lucid-evolution/lucid");
|
|
8976
9529
|
var authPolicyData = {
|
|
8977
9530
|
type: "PlutusV2",
|
|
8978
9531
|
cborHex: "5904d95904d60100003232323232323232323232323232323232323232323232323232223232223232323253355335533357346042660166018a00200e03026464666ae68cdc419806980728019980b9999aa999ab9a3370e90030008990911118020029aba1302400215333573466e1d20040011321222230020053574260480042a666ae68c08c0044c848888c004014d5d098120010a999ab9a30220011321222230030053574260480040424c40024c4c016900100a80d98120009baa3500201d01813357389213d4d75737420636f6e73756d65204e4654206f7220746f6b656e2070726576696f75736c79206d696e746564207573696e67207468697320706f6c6963790001301415335738920103505435001613253335734604060460022646464646464646464646464646464646464646464642466666666666600202e02a02602201e01a01601200e00a0060046ae84d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d118118011aba1302200101f37546a002036a666ae68c078c0840084c8c848cc00400c008d5d09aba2302100335742604000403aa666ae68c074c080dd500180880e1baa00153335734603260380022646601e6ae84004d5d09aba2001301b00101837540044464646603a4466a0029000111a801112999ab9a3375e0040102660464466a0029000111a801112999ab9a3375e00401a20022600c0060022600c0060086a00402a6a0020264666aa6020026660144466aa601c02a46a002446601e00466aa602203046a0024466024004666a0026e012000700466e0000520000013355300e015235001223300f00233350012335530120192350012233013002300e0010012233300a0090020012335530120192350012233013002301000100133300500400200100e232333008200133008200175a6aa666ae68c05cc0680044c8c8c8c8c8c848cccc00401c01400c008d5d09aba2002357420026ae88008d5d08009aba2301a00235742603200202c44440066ea8d400404ccc06488cccd55cf800900891919809a999ab9a3019301c001132321233001003002357426ae88c070008d5d0980d80080c18021aba200337546ae84008054dd61a80091111111111100611199ab9a3375e00400201c010444666aa601602601e66aa601802646a002446601a0046010002666aa6016026446a00444a66a666aa602802e6601c4466601402e004002601002c46a002446601400400a00c200626602600800601c00266aa601802646a002446601a0046603844a66a002260180064426a00444a66a6601800401022444660040140082600c00600800446600244a66a004018200200a4244460060084446602c446666aae7c00480388c8cc040cc02cc01cc064004c018c060004c010d5d10019aba1002012375600242444600200820142014442466002006004601c4422444a66a00220044426600a004666aa600e01e00a008002601a442244a66a00200a44266012600800466aa600c01a00800220022006442446600200800660124422444a66a00226a00600e442666a00a0106008004666aa600e01400a0080024400444002240022a66ae71241035054310016370e90001b874800955cf2ab9d2323001001223300330020020011"
|
|
@@ -8980,15 +9533,15 @@ var authPolicyData = {
|
|
|
8980
9533
|
function mkAuthTokenPolicy(ac, tn) {
|
|
8981
9534
|
return {
|
|
8982
9535
|
type: authPolicyData.type,
|
|
8983
|
-
script: (0,
|
|
8984
|
-
new
|
|
9536
|
+
script: (0, import_lucid57.applyParamsToScript)(authPolicyData.cborHex, [
|
|
9537
|
+
new import_lucid57.Constr(0, [(0, import_lucid57.toHex)(ac.currencySymbol), (0, import_lucid57.toHex)(ac.tokenName)]),
|
|
8985
9538
|
tn
|
|
8986
9539
|
])
|
|
8987
9540
|
};
|
|
8988
9541
|
}
|
|
8989
9542
|
|
|
8990
9543
|
// src/contracts/iasset/scripts.ts
|
|
8991
|
-
var
|
|
9544
|
+
var import_lucid58 = require("@lucid-evolution/lucid");
|
|
8992
9545
|
|
|
8993
9546
|
// src/validators/iasset-validator.ts
|
|
8994
9547
|
var _iassetValidator = {
|
|
@@ -8998,8 +9551,8 @@ var _iassetValidator = {
|
|
|
8998
9551
|
};
|
|
8999
9552
|
|
|
9000
9553
|
// src/contracts/iasset/scripts.ts
|
|
9001
|
-
var
|
|
9002
|
-
var IAssetScriptParamsSchema =
|
|
9554
|
+
var import_lucid59 = require("@lucid-evolution/lucid");
|
|
9555
|
+
var IAssetScriptParamsSchema = import_lucid59.Data.Object({
|
|
9003
9556
|
upgradeToken: AssetClassSchema2,
|
|
9004
9557
|
versionRecordToken: AssetClassSchema2
|
|
9005
9558
|
});
|
|
@@ -9007,8 +9560,8 @@ var IAssetScriptParams = IAssetScriptParamsSchema;
|
|
|
9007
9560
|
var mkIAssetValidatorFromSP = (params) => {
|
|
9008
9561
|
return {
|
|
9009
9562
|
type: "PlutusV3",
|
|
9010
|
-
script: (0,
|
|
9011
|
-
|
|
9563
|
+
script: (0, import_lucid58.applyParamsToScript)(_iassetValidator.cborHex, [
|
|
9564
|
+
import_lucid59.Data.castTo(
|
|
9012
9565
|
{
|
|
9013
9566
|
upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
|
|
9014
9567
|
versionRecordToken: fromSystemParamsAssetLucid(
|
|
@@ -9025,7 +9578,7 @@ var mkIAssetValidatorFromSP = (params) => {
|
|
|
9025
9578
|
var import_ts_pattern21 = require("ts-pattern");
|
|
9026
9579
|
|
|
9027
9580
|
// tests/test-helpers.ts
|
|
9028
|
-
var
|
|
9581
|
+
var import_fp_ts20 = require("fp-ts");
|
|
9029
9582
|
async function runAndAwaitTxBuilder(lucid, transaction, extraSigners = []) {
|
|
9030
9583
|
const bTx = await transaction.complete();
|
|
9031
9584
|
const signatures = [await bTx.partialSign.withWallet()];
|
|
@@ -9086,22 +9639,22 @@ async function mintOneTimeToken(lucid, tokenName, amount) {
|
|
|
9086
9639
|
});
|
|
9087
9640
|
}
|
|
9088
9641
|
async function mintOneTimeAsset(lucid, tokenName, amount) {
|
|
9089
|
-
const policyId = await mintOneTimeToken(lucid, (0,
|
|
9642
|
+
const policyId = await mintOneTimeToken(lucid, (0, import_lucid60.fromText)(tokenName), amount);
|
|
9090
9643
|
return {
|
|
9091
|
-
currencySymbol: (0,
|
|
9092
|
-
tokenName: (0,
|
|
9644
|
+
currencySymbol: (0, import_lucid60.fromHex)(policyId),
|
|
9645
|
+
tokenName: (0, import_lucid60.fromHex)((0, import_lucid60.fromText)(tokenName))
|
|
9093
9646
|
};
|
|
9094
9647
|
}
|
|
9095
9648
|
function deriveAuthToken(parent, tokenName) {
|
|
9096
|
-
const policy = mkAuthTokenPolicy(parent, (0,
|
|
9649
|
+
const policy = mkAuthTokenPolicy(parent, (0, import_lucid60.fromText)(tokenName));
|
|
9097
9650
|
return {
|
|
9098
|
-
currencySymbol: (0,
|
|
9099
|
-
tokenName: (0,
|
|
9651
|
+
currencySymbol: (0, import_lucid60.fromHex)((0, import_lucid60.mintingPolicyToId)(policy)),
|
|
9652
|
+
tokenName: (0, import_lucid60.fromHex)((0, import_lucid60.fromText)(tokenName))
|
|
9100
9653
|
};
|
|
9101
9654
|
}
|
|
9102
9655
|
async function initScriptRef(lucid, validator) {
|
|
9103
9656
|
const tx = lucid.newTx().pay.ToContract(
|
|
9104
|
-
(0,
|
|
9657
|
+
(0, import_lucid60.credentialToAddress)(lucid.config().network, {
|
|
9105
9658
|
hash: alwaysFailValidatorHash,
|
|
9106
9659
|
type: "Script"
|
|
9107
9660
|
}),
|
|
@@ -9119,11 +9672,11 @@ async function initCollector(lucid, collectorParams, numCollectors) {
|
|
|
9119
9672
|
tx.pay.ToContract(
|
|
9120
9673
|
createScriptAddress(
|
|
9121
9674
|
lucid.config().network,
|
|
9122
|
-
(0,
|
|
9675
|
+
(0, import_lucid60.validatorToScriptHash)(mkCollectorValidatorFromSP(collectorParams))
|
|
9123
9676
|
),
|
|
9124
9677
|
{
|
|
9125
9678
|
kind: "inline",
|
|
9126
|
-
value:
|
|
9679
|
+
value: import_lucid60.Data.void()
|
|
9127
9680
|
}
|
|
9128
9681
|
);
|
|
9129
9682
|
}
|
|
@@ -9134,7 +9687,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
|
|
|
9134
9687
|
const interestCollectionAdminDatum = {
|
|
9135
9688
|
admin_permissions: {
|
|
9136
9689
|
Signature: {
|
|
9137
|
-
keyHash: (0,
|
|
9690
|
+
keyHash: (0, import_lucid60.fromHex)(pkh.hash)
|
|
9138
9691
|
}
|
|
9139
9692
|
}
|
|
9140
9693
|
};
|
|
@@ -9146,7 +9699,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
|
|
|
9146
9699
|
kind: "inline",
|
|
9147
9700
|
value: serialiseInterestCollectionDatum(interestCollectionAdminDatum)
|
|
9148
9701
|
},
|
|
9149
|
-
(0,
|
|
9702
|
+
(0, import_cardano_offchain_common26.mkAssetsOf)(multisigUtxoNft, 1n)
|
|
9150
9703
|
)
|
|
9151
9704
|
);
|
|
9152
9705
|
const interestCollectionUtxoDeploymentTx = lucid.newTx();
|
|
@@ -9154,7 +9707,7 @@ async function initInterestCollector(lucid, interestCollectionValHash, multisigU
|
|
|
9154
9707
|
interestCollectionUtxoDeploymentTx.pay.ToContract(
|
|
9155
9708
|
createScriptAddress(lucid.config().network, interestCollectionValHash),
|
|
9156
9709
|
void 0,
|
|
9157
|
-
(0,
|
|
9710
|
+
(0, import_cardano_offchain_common26.mkLovelacesOf)(interestCollectorUtxoLovelaces)
|
|
9158
9711
|
);
|
|
9159
9712
|
}
|
|
9160
9713
|
await submitTx(lucid, interestCollectionUtxoDeploymentTx);
|
|
@@ -9163,15 +9716,15 @@ async function initCDPCreator(lucid, cdpCreatorParams, numCdpCreators) {
|
|
|
9163
9716
|
const tx = lucid.newTx();
|
|
9164
9717
|
for (let i = 0; i < Number(numCdpCreators); i++) {
|
|
9165
9718
|
tx.pay.ToContract(
|
|
9166
|
-
(0,
|
|
9167
|
-
hash: (0,
|
|
9719
|
+
(0, import_lucid60.credentialToAddress)(lucid.config().network, {
|
|
9720
|
+
hash: (0, import_lucid60.validatorToScriptHash)(
|
|
9168
9721
|
mkCDPCreatorValidatorFromSP(cdpCreatorParams)
|
|
9169
9722
|
),
|
|
9170
9723
|
type: "Script"
|
|
9171
9724
|
}),
|
|
9172
|
-
{ kind: "inline", value:
|
|
9725
|
+
{ kind: "inline", value: import_lucid60.Data.void() },
|
|
9173
9726
|
{
|
|
9174
|
-
[cdpCreatorParams.cdpCreatorNft[0].unCurrencySymbol + (0,
|
|
9727
|
+
[cdpCreatorParams.cdpCreatorNft[0].unCurrencySymbol + (0, import_lucid60.fromText)(cdpCreatorParams.cdpCreatorNft[1].unTokenName)]: 1n
|
|
9175
9728
|
}
|
|
9176
9729
|
);
|
|
9177
9730
|
}
|
|
@@ -9180,21 +9733,21 @@ async function initCDPCreator(lucid, cdpCreatorParams, numCdpCreators) {
|
|
|
9180
9733
|
async function initTreasury(lucid, treasuryParams, daoAsset, indyAsset, treasuryIndyAmount, numTreasuryCollectors) {
|
|
9181
9734
|
const treasuryAddr = createScriptAddress(
|
|
9182
9735
|
lucid.config().network,
|
|
9183
|
-
(0,
|
|
9736
|
+
(0, import_lucid60.validatorToScriptHash)(mkTreasuryValidatorFromSP(treasuryParams)),
|
|
9184
9737
|
treasuryParams.treasuryUtxosStakeCredential != null ? fromSysParamsCredential(treasuryParams.treasuryUtxosStakeCredential) : void 0
|
|
9185
9738
|
);
|
|
9186
9739
|
const tx = lucid.newTx().pay.ToContract(
|
|
9187
9740
|
treasuryAddr,
|
|
9188
|
-
{ kind: "inline", value:
|
|
9189
|
-
(0,
|
|
9190
|
-
(0,
|
|
9191
|
-
(0,
|
|
9741
|
+
{ kind: "inline", value: import_lucid60.Data.void() },
|
|
9742
|
+
(0, import_lucid60.addAssets)(
|
|
9743
|
+
(0, import_cardano_offchain_common26.mkAssetsOf)(daoAsset, 1n),
|
|
9744
|
+
(0, import_cardano_offchain_common26.mkAssetsOf)(indyAsset, treasuryIndyAmount)
|
|
9192
9745
|
)
|
|
9193
9746
|
);
|
|
9194
9747
|
for (let i = 0; i < Number(numTreasuryCollectors); i++) {
|
|
9195
9748
|
tx.pay.ToContract(treasuryAddr, {
|
|
9196
9749
|
kind: "inline",
|
|
9197
|
-
value:
|
|
9750
|
+
value: import_lucid60.Data.void()
|
|
9198
9751
|
});
|
|
9199
9752
|
}
|
|
9200
9753
|
await submitTx(lucid, tx);
|
|
@@ -9203,7 +9756,7 @@ async function initStakingManager(lucid, stakingParams) {
|
|
|
9203
9756
|
const tx = lucid.newTx().pay.ToContract(
|
|
9204
9757
|
createScriptAddress(
|
|
9205
9758
|
lucid.config().network,
|
|
9206
|
-
(0,
|
|
9759
|
+
(0, import_lucid60.validatorToScriptHash)(mkStakingValidatorFromSP(stakingParams))
|
|
9207
9760
|
),
|
|
9208
9761
|
{
|
|
9209
9762
|
kind: "inline",
|
|
@@ -9213,7 +9766,7 @@ async function initStakingManager(lucid, stakingParams) {
|
|
|
9213
9766
|
})
|
|
9214
9767
|
},
|
|
9215
9768
|
{
|
|
9216
|
-
[stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0,
|
|
9769
|
+
[stakingParams.stakingManagerNFT[0].unCurrencySymbol + (0, import_lucid60.fromText)(stakingParams.stakingManagerNFT[1].unTokenName)]: 1n
|
|
9217
9770
|
}
|
|
9218
9771
|
);
|
|
9219
9772
|
await submitTx(lucid, tx);
|
|
@@ -9239,10 +9792,10 @@ async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, py
|
|
|
9239
9792
|
return Promise.resolve({
|
|
9240
9793
|
info: {
|
|
9241
9794
|
DeferredValidation: {
|
|
9242
|
-
feedValHash: (0,
|
|
9795
|
+
feedValHash: (0, import_lucid60.fromHex)(
|
|
9243
9796
|
getPythFeedConfig(
|
|
9244
9797
|
pythConfig,
|
|
9245
|
-
(0,
|
|
9798
|
+
(0, import_lucid60.fromHex)((0, import_lucid60.fromText)(iasset.name)),
|
|
9246
9799
|
collateralAsset.collateralAsset
|
|
9247
9800
|
).pythFeedValHash
|
|
9248
9801
|
)
|
|
@@ -9253,7 +9806,7 @@ async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, py
|
|
|
9253
9806
|
}).exhaustive();
|
|
9254
9807
|
}
|
|
9255
9808
|
async function initializeAsset(lucid, iassetParams, iassetToken, collateralAssetAuthToken, cdpAuthToken, cdpParams, stableswapValidatorHash, stabilityPoolParams, stabilityPoolToken, asset, pythConfig, currentSlot) {
|
|
9256
|
-
const iassetName = (0,
|
|
9809
|
+
const iassetName = (0, import_lucid60.fromHex)((0, import_lucid60.fromText)(asset.name));
|
|
9257
9810
|
const collateralAssetInfos = [];
|
|
9258
9811
|
for (const collateralAsset of asset.collateralAssets) {
|
|
9259
9812
|
const [pkh, _] = await addrDetails(lucid);
|
|
@@ -9293,7 +9846,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
9293
9846
|
const collateralAssetTx = lucid.newTx().pay.ToContract(
|
|
9294
9847
|
createScriptAddress(
|
|
9295
9848
|
lucid.config().network,
|
|
9296
|
-
(0,
|
|
9849
|
+
(0, import_lucid60.validatorToScriptHash)(mkIAssetValidatorFromSP(iassetParams))
|
|
9297
9850
|
),
|
|
9298
9851
|
{
|
|
9299
9852
|
kind: "inline",
|
|
@@ -9301,7 +9854,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
9301
9854
|
CollateralAssetContent: collateralAssetContent
|
|
9302
9855
|
})
|
|
9303
9856
|
},
|
|
9304
|
-
(0,
|
|
9857
|
+
(0, import_cardano_offchain_common26.mkAssetsOf)(collateralAssetAuthToken, 1n)
|
|
9305
9858
|
);
|
|
9306
9859
|
await submitTx(lucid, collateralAssetTx);
|
|
9307
9860
|
collateralAssetInfos.push({
|
|
@@ -9319,24 +9872,24 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
9319
9872
|
redemptionFeeRatio: stableswapPool.redemptionFeeRatio,
|
|
9320
9873
|
mintingEnabled: stableswapPool.mintingEnabled,
|
|
9321
9874
|
redemptionEnabled: stableswapPool.redemptionEnabled,
|
|
9322
|
-
feeManager: stableswapPool.feeManager ? (0,
|
|
9875
|
+
feeManager: stableswapPool.feeManager ? (0, import_lucid60.fromHex)(stableswapPool.feeManager) : null,
|
|
9323
9876
|
minMintOrderAmount: stableswapPool.minMintOrderAmount,
|
|
9324
9877
|
minRedemptionOrderAmount: stableswapPool.minRedemptionOrderAmount,
|
|
9325
9878
|
iasset: iassetName,
|
|
9326
|
-
stableswapValHash: (0,
|
|
9879
|
+
stableswapValHash: (0, import_lucid60.fromHex)(stableswapValidatorHash)
|
|
9327
9880
|
};
|
|
9328
9881
|
await submitTx(
|
|
9329
9882
|
lucid,
|
|
9330
9883
|
lucid.newTx().pay.ToContract(
|
|
9331
9884
|
createScriptAddress(
|
|
9332
9885
|
lucid.config().network,
|
|
9333
|
-
(0,
|
|
9886
|
+
(0, import_lucid60.validatorToScriptHash)(mkCdpValidatorFromSP(cdpParams))
|
|
9334
9887
|
),
|
|
9335
9888
|
{
|
|
9336
9889
|
kind: "inline",
|
|
9337
9890
|
value: serialiseStableswapPoolDatum(stableswapPoolDatum)
|
|
9338
9891
|
},
|
|
9339
|
-
(0,
|
|
9892
|
+
(0, import_cardano_offchain_common26.mkAssetsOf)(cdpAuthToken, 1n)
|
|
9340
9893
|
)
|
|
9341
9894
|
);
|
|
9342
9895
|
}
|
|
@@ -9349,28 +9902,28 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
9349
9902
|
redemptionReimbursementRatio: asset.redemptionReimbursementRatio,
|
|
9350
9903
|
redemptionProcessingFeeRatio: asset.redemptionProcessingFeeRatio,
|
|
9351
9904
|
firstIAsset: asset.firstAsset,
|
|
9352
|
-
nextIAsset: asset.nextAsset ? (0,
|
|
9905
|
+
nextIAsset: asset.nextAsset ? (0, import_lucid60.fromHex)((0, import_lucid60.fromText)(asset.nextAsset)) : null
|
|
9353
9906
|
};
|
|
9354
9907
|
const assetTx = lucid.newTx().pay.ToContract(
|
|
9355
9908
|
createScriptAddress(
|
|
9356
9909
|
lucid.config().network,
|
|
9357
|
-
(0,
|
|
9910
|
+
(0, import_lucid60.validatorToScriptHash)(mkIAssetValidatorFromSP(iassetParams))
|
|
9358
9911
|
),
|
|
9359
9912
|
{
|
|
9360
9913
|
kind: "inline",
|
|
9361
9914
|
value: serialiseIAssetDatum({ IAssetContent: iassetDatum })
|
|
9362
9915
|
},
|
|
9363
|
-
(0,
|
|
9916
|
+
(0, import_cardano_offchain_common26.mkAssetsOf)(iassetToken, 1n)
|
|
9364
9917
|
);
|
|
9365
9918
|
await submitTx(lucid, assetTx);
|
|
9366
9919
|
const stabilityPoolDatum = {
|
|
9367
|
-
iasset: (0,
|
|
9920
|
+
iasset: (0, import_lucid60.fromHex)((0, import_lucid60.fromText)(asset.name)),
|
|
9368
9921
|
state: initSpState,
|
|
9369
9922
|
assetStates: []
|
|
9370
9923
|
};
|
|
9371
9924
|
const spTx = lucid.newTx().pay.ToContract(
|
|
9372
|
-
(0,
|
|
9373
|
-
hash: (0,
|
|
9925
|
+
(0, import_lucid60.credentialToAddress)(lucid.config().network, {
|
|
9926
|
+
hash: (0, import_lucid60.validatorToScriptHash)(
|
|
9374
9927
|
mkStabilityPoolValidatorFromSP(stabilityPoolParams)
|
|
9375
9928
|
),
|
|
9376
9929
|
type: "Script"
|
|
@@ -9379,7 +9932,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
9379
9932
|
kind: "inline",
|
|
9380
9933
|
value: serialiseStabilityPoolDatum({ StabilityPool: stabilityPoolDatum })
|
|
9381
9934
|
},
|
|
9382
|
-
(0,
|
|
9935
|
+
(0, import_cardano_offchain_common26.mkAssetsOf)(stabilityPoolToken, 1n)
|
|
9383
9936
|
);
|
|
9384
9937
|
await submitTx(lucid, spTx);
|
|
9385
9938
|
return {
|
|
@@ -9396,39 +9949,39 @@ async function initGovernance(lucid, governanceParams, govToken, initialAssets,
|
|
|
9396
9949
|
iassetsCount: BigInt(initialAssets.length)
|
|
9397
9950
|
};
|
|
9398
9951
|
const tx = lucid.newTx().pay.ToContract(
|
|
9399
|
-
(0,
|
|
9400
|
-
hash: (0,
|
|
9952
|
+
(0, import_lucid60.credentialToAddress)(lucid.config().network, {
|
|
9953
|
+
hash: (0, import_lucid60.validatorToScriptHash)(mkGovValidatorFromSP(governanceParams)),
|
|
9401
9954
|
type: "Script"
|
|
9402
9955
|
}),
|
|
9403
9956
|
{ kind: "inline", value: serialiseGovDatum(datum) },
|
|
9404
|
-
(0,
|
|
9957
|
+
(0, import_cardano_offchain_common26.mkAssetsOf)(govToken, 1n)
|
|
9405
9958
|
);
|
|
9406
9959
|
await submitTx(lucid, tx);
|
|
9407
9960
|
}
|
|
9408
9961
|
async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
|
|
9409
|
-
const script = mkAuthTokenPolicy(asset, (0,
|
|
9410
|
-
const policyId = (0,
|
|
9962
|
+
const script = mkAuthTokenPolicy(asset, (0, import_lucid60.fromText)(tokenName));
|
|
9963
|
+
const policyId = (0, import_lucid60.mintingPolicyToId)(script);
|
|
9411
9964
|
const address = await lucid.wallet().address();
|
|
9412
|
-
const utxos = (await lucid.utxosAtWithUnit(address, (0,
|
|
9965
|
+
const utxos = (await lucid.utxosAtWithUnit(address, (0, import_cardano_offchain_common26.assetClassToUnit)(asset))).filter((utxo2) => (0, import_cardano_offchain_common26.assetClassValueOf)(utxo2.assets, asset) === 1n).sort((a, b) => Number((0, import_cardano_offchain_common26.lovelacesAmt)(b.assets) - (0, import_cardano_offchain_common26.lovelacesAmt)(a.assets)));
|
|
9413
9966
|
if (utxos.length === 0) {
|
|
9414
9967
|
throw new Error("No utxos found");
|
|
9415
9968
|
}
|
|
9416
9969
|
const utxo = utxos[0];
|
|
9417
9970
|
const tx = lucid.newTx().attach.MintingPolicy(script).collectFrom([utxo]).mintAssets(
|
|
9418
9971
|
{
|
|
9419
|
-
[policyId + (0,
|
|
9972
|
+
[policyId + (0, import_lucid60.fromText)(tokenName)]: amount
|
|
9420
9973
|
},
|
|
9421
|
-
|
|
9974
|
+
import_lucid60.Data.void()
|
|
9422
9975
|
);
|
|
9423
9976
|
await submitTx(lucid, tx);
|
|
9424
9977
|
}
|
|
9425
9978
|
|
|
9426
9979
|
// src/contracts/initialize/actions.ts
|
|
9427
|
-
var
|
|
9428
|
-
var
|
|
9980
|
+
var import_lucid65 = require("@lucid-evolution/lucid");
|
|
9981
|
+
var import_cardano_offchain_common28 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
9429
9982
|
|
|
9430
9983
|
// src/scripts/iasset-policy.ts
|
|
9431
|
-
var
|
|
9984
|
+
var import_lucid61 = require("@lucid-evolution/lucid");
|
|
9432
9985
|
var iassetPolicyData = {
|
|
9433
9986
|
type: "PlutusV2",
|
|
9434
9987
|
cborHex: "59047b590478010000323232323232323232323232323232323232323232323232323232323232330102223253353300453335734603e60426ea800c04c0794ccd5cd180f98108008991909198008018011aba13574460420046ae84c08000407804c54cd5ce248103505435001637540026602044464a66aa666ae68cdc419803199aa980d00e803919980810008079a98071a80080e9003998089192999ab9a30213023001132321233001003002357426ae88c08c008d5d098110008101baa00135500122222222222200c004480084ccd5cd19b8748008cc018ccd54c06807401c8ccc040800403cd4004801ccc044034d5400488888888888802801006004805c05c4cd5ce24910434450546f6b656e206d697373696e670001213253335734603e60420022646464646464646464646464646464646464646464642466666666666600202e02a02602201e01a01601200e00a0060046ae84d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d10011aba1001357440046ae84004d5d118108011aba1302000101e37546a002034464a666ae68c074c07c0044c8c848cc00400c008d5d09aba2301f00235742603c0020386ea800488800c88c8c8cc08088cd400520002235002225333573466ebc0080204cc09888cd400520002235002225333573466ebc00803440044c01800c0044c01800c010d4008064d400405ccc02488cd54c0440608d400488cc038008cd54c05006c8d400488cc044008ccd4004dc024000e008cdc0000a400000266aa602203046a002446601c004666a002466aa602a03846a0024466024004601a00200244666012010004002466aa602a03846a0024466024004601c00200266600800600400202244666ae68cdd7801000809006111199aa980780b80999aa980800b91a80091198068011804000999aa980780b911a80111299a999aa980c00d998071119980500d801000980400d11a8009119805001002803080189980b80200180900099aa980800b91a80091198068011980f91299a800898058019109a80111299a9980600100408911198010050020980300180200111980091299a80100808008049091118018021091118008021192999ab9a301430160011323232323232123333001007005003002357426ae88008d5d08009aba2002357420026ae88c058008d5d0980a8008099baa00133001200175a4446602c446666aae7c004803c8c8cc044cc020c01cc064004c018c060004c010d5d10019aba100201337560024424660020060044466026446666aae7c00480308cc034c014d5d080118019aba200201037580022014201444460066004002601a4422444a66a00220044426600a004666aa600e01e00a0080026018442244a66a00200a44266012600800466aa600c01a00800220022006442446600200800660104422444a66a00226a00600e442666a00a0106008004666aa600e01400a0080024400444002240022a66ae71241035054310016370e90002ab9e5573a4646002002446600660040040021"
|
|
@@ -9436,27 +9989,27 @@ var iassetPolicyData = {
|
|
|
9436
9989
|
function mkIAssetTokenPolicy(ac) {
|
|
9437
9990
|
return {
|
|
9438
9991
|
type: iassetPolicyData.type,
|
|
9439
|
-
script: (0,
|
|
9440
|
-
new
|
|
9992
|
+
script: (0, import_lucid61.applyParamsToScript)(iassetPolicyData.cborHex, [
|
|
9993
|
+
new import_lucid61.Constr(0, [(0, import_lucid61.toHex)(ac.currencySymbol), (0, import_lucid61.toHex)(ac.tokenName)])
|
|
9441
9994
|
])
|
|
9442
9995
|
};
|
|
9443
9996
|
}
|
|
9444
9997
|
|
|
9445
9998
|
// src/contracts/stableswap/scripts.ts
|
|
9446
|
-
var
|
|
9999
|
+
var import_lucid63 = require("@lucid-evolution/lucid");
|
|
9447
10000
|
|
|
9448
10001
|
// src/contracts/stableswap/types.ts
|
|
9449
|
-
var
|
|
9450
|
-
var StableswapParamsSchema =
|
|
9451
|
-
iassetSymbol:
|
|
10002
|
+
var import_lucid62 = require("@lucid-evolution/lucid");
|
|
10003
|
+
var StableswapParamsSchema = import_lucid62.Data.Object({
|
|
10004
|
+
iassetSymbol: import_lucid62.Data.Bytes(),
|
|
9452
10005
|
cdpToken: AssetClassSchema2,
|
|
9453
10006
|
versionRecordToken: AssetClassSchema2,
|
|
9454
|
-
cdpValHash:
|
|
9455
|
-
treasuryValHash:
|
|
10007
|
+
cdpValHash: import_lucid62.Data.Bytes(),
|
|
10008
|
+
treasuryValHash: import_lucid62.Data.Bytes()
|
|
9456
10009
|
});
|
|
9457
10010
|
var StableswapParams = StableswapParamsSchema;
|
|
9458
10011
|
function castStableswapParams(params) {
|
|
9459
|
-
return
|
|
10012
|
+
return import_lucid62.Data.castTo(params, StableswapParams);
|
|
9460
10013
|
}
|
|
9461
10014
|
|
|
9462
10015
|
// src/validators/stableswap-validator.ts
|
|
@@ -9470,7 +10023,7 @@ var _stableswapValidator = {
|
|
|
9470
10023
|
var mkStableswapValidator = (params) => {
|
|
9471
10024
|
return {
|
|
9472
10025
|
type: "PlutusV3",
|
|
9473
|
-
script: (0,
|
|
10026
|
+
script: (0, import_lucid63.applyParamsToScript)(_stableswapValidator.cborHex, [
|
|
9474
10027
|
castStableswapParams(params)
|
|
9475
10028
|
])
|
|
9476
10029
|
};
|
|
@@ -9478,7 +10031,7 @@ var mkStableswapValidator = (params) => {
|
|
|
9478
10031
|
var mkStableswapValidatorFromSP = (params) => {
|
|
9479
10032
|
return {
|
|
9480
10033
|
type: "PlutusV3",
|
|
9481
|
-
script: (0,
|
|
10034
|
+
script: (0, import_lucid63.applyParamsToScript)(_stableswapValidator.cborHex, [
|
|
9482
10035
|
castStableswapParams({
|
|
9483
10036
|
iassetSymbol: params.iassetSymbol.unCurrencySymbol,
|
|
9484
10037
|
cdpToken: fromSystemParamsAssetLucid(params.cdpToken),
|
|
@@ -9514,7 +10067,7 @@ var mkPythFeedValidator = (params) => {
|
|
|
9514
10067
|
var import_ts_pattern22 = require("ts-pattern");
|
|
9515
10068
|
|
|
9516
10069
|
// tests/pyth/endpoints.ts
|
|
9517
|
-
var
|
|
10070
|
+
var import_lucid64 = require("@lucid-evolution/lucid");
|
|
9518
10071
|
|
|
9519
10072
|
// src/validators/always-succeed-validator.ts
|
|
9520
10073
|
var _alwaysSucceedValidator = {
|
|
@@ -9530,29 +10083,29 @@ var alwaysSucceedValidator = {
|
|
|
9530
10083
|
};
|
|
9531
10084
|
|
|
9532
10085
|
// tests/pyth/endpoints.ts
|
|
9533
|
-
var
|
|
10086
|
+
var import_cardano_offchain_common27 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
9534
10087
|
var TEST_TRUSTED_SIGNER_PUB_KEY = "4a50d7c3d16b2be5c16ba996109a455a34cce08a81b3e15b86ef407e2f72e71f";
|
|
9535
10088
|
async function initPyth(lucid) {
|
|
9536
|
-
const pythStateName = (0,
|
|
10089
|
+
const pythStateName = (0, import_lucid64.fromText)("Pyth State");
|
|
9537
10090
|
const pythStatePolicyId = await mintOneTimeToken(lucid, pythStateName, 1n);
|
|
9538
10091
|
const pythStateAsset = {
|
|
9539
|
-
currencySymbol: (0,
|
|
9540
|
-
tokenName: (0,
|
|
10092
|
+
currencySymbol: (0, import_lucid64.fromHex)(pythStatePolicyId),
|
|
10093
|
+
tokenName: (0, import_lucid64.fromHex)(pythStateName)
|
|
9541
10094
|
};
|
|
9542
|
-
const alwaysSucceedsValidatorHash = (0,
|
|
10095
|
+
const alwaysSucceedsValidatorHash = (0, import_lucid64.validatorToScriptHash)(
|
|
9543
10096
|
alwaysSucceedValidator
|
|
9544
10097
|
);
|
|
9545
10098
|
const pythStateDatum = {
|
|
9546
10099
|
// The governance doesn't matter for the purpose of testing, so we can use any values
|
|
9547
10100
|
governance: {
|
|
9548
|
-
wormhole: (0,
|
|
10101
|
+
wormhole: (0, import_lucid64.fromHex)(""),
|
|
9549
10102
|
emitterChain: 0n,
|
|
9550
|
-
emitterAddress: (0,
|
|
10103
|
+
emitterAddress: (0, import_lucid64.fromHex)(""),
|
|
9551
10104
|
seenSequence: 0n
|
|
9552
10105
|
},
|
|
9553
10106
|
trustedSigners: /* @__PURE__ */ new Map([
|
|
9554
10107
|
[
|
|
9555
|
-
(0,
|
|
10108
|
+
(0, import_lucid64.fromHex)(TEST_TRUSTED_SIGNER_PUB_KEY),
|
|
9556
10109
|
{
|
|
9557
10110
|
lower_bound: {
|
|
9558
10111
|
bound_type: {
|
|
@@ -9572,25 +10125,25 @@ async function initPyth(lucid) {
|
|
|
9572
10125
|
deprecatedWithdrawScripts: /* @__PURE__ */ new Map(),
|
|
9573
10126
|
// For the purpose of testing, we use the always succeeds validator to validate the Pyth Messages.
|
|
9574
10127
|
// This means the message signature checking will always succeed for the purpose of emulation testing.
|
|
9575
|
-
withdraw_script: (0,
|
|
10128
|
+
withdraw_script: (0, import_lucid64.fromHex)(alwaysSucceedsValidatorHash)
|
|
9576
10129
|
};
|
|
9577
10130
|
await runAndAwaitTxBuilder(
|
|
9578
10131
|
lucid,
|
|
9579
10132
|
lucid.newTx().pay.ToContract(
|
|
9580
|
-
(0,
|
|
9581
|
-
hash: (0,
|
|
10133
|
+
(0, import_lucid64.credentialToAddress)(lucid.config().network, {
|
|
10134
|
+
hash: (0, import_lucid64.validatorToScriptHash)(alwaysSucceedValidator),
|
|
9582
10135
|
type: "Script"
|
|
9583
10136
|
}),
|
|
9584
10137
|
{ kind: "inline", value: serialisePythStateDatum(pythStateDatum) },
|
|
9585
|
-
(0,
|
|
10138
|
+
(0, import_cardano_offchain_common27.mkAssetsOf)(pythStateAsset, 1n),
|
|
9586
10139
|
alwaysSucceedValidator
|
|
9587
10140
|
)
|
|
9588
10141
|
);
|
|
9589
10142
|
await runAndAwaitTxBuilder(
|
|
9590
10143
|
lucid,
|
|
9591
10144
|
lucid.newTx().register.Stake(
|
|
9592
|
-
(0,
|
|
9593
|
-
hash: (0,
|
|
10145
|
+
(0, import_lucid64.credentialToRewardAddress)(lucid.config().network, {
|
|
10146
|
+
hash: (0, import_lucid64.validatorToScriptHash)(alwaysSucceedValidator),
|
|
9594
10147
|
type: "Script"
|
|
9595
10148
|
})
|
|
9596
10149
|
)
|
|
@@ -9614,7 +10167,7 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
|
|
|
9614
10167
|
const pythFeedValidator = mkPythFeedValidator(
|
|
9615
10168
|
fromSysParamsPythFeedParams(val.pythFeedParams)
|
|
9616
10169
|
);
|
|
9617
|
-
const pythFeedValHash = (0,
|
|
10170
|
+
const pythFeedValHash = (0, import_lucid65.validatorToScriptHash)(pythFeedValidator);
|
|
9618
10171
|
const pythFeedValScriptRef = await initScriptRef(
|
|
9619
10172
|
lucid,
|
|
9620
10173
|
pythFeedValidator
|
|
@@ -9622,13 +10175,13 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
|
|
|
9622
10175
|
await runAndAwaitTxBuilder(
|
|
9623
10176
|
lucid,
|
|
9624
10177
|
lucid.newTx().register.Stake(
|
|
9625
|
-
(0,
|
|
9626
|
-
hash: (0,
|
|
10178
|
+
(0, import_lucid65.credentialToRewardAddress)(lucid.config().network, {
|
|
10179
|
+
hash: (0, import_lucid65.validatorToScriptHash)(pythFeedValidator),
|
|
9627
10180
|
type: "Script"
|
|
9628
10181
|
})
|
|
9629
10182
|
)
|
|
9630
10183
|
);
|
|
9631
|
-
const key = `${asset.name}/${(0,
|
|
10184
|
+
const key = `${asset.name}/${(0, import_lucid65.toHex)(collateral.collateralAsset.currencySymbol)}.${(0, import_lucid65.toHex)(collateral.collateralAsset.tokenName)}`;
|
|
9632
10185
|
return {
|
|
9633
10186
|
[key]: {
|
|
9634
10187
|
params: val.pythFeedParams,
|
|
@@ -9680,16 +10233,16 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9680
10233
|
};
|
|
9681
10234
|
const versionRecordTokenPolicy = mkVersionRecordTokenPolicy({
|
|
9682
10235
|
upgradeToken: {
|
|
9683
|
-
currencySymbol: (0,
|
|
9684
|
-
tokenName: (0,
|
|
10236
|
+
currencySymbol: (0, import_lucid65.toHex)(upgradeToken.currencySymbol),
|
|
10237
|
+
tokenName: (0, import_lucid65.toHex)(upgradeToken.tokenName)
|
|
9685
10238
|
}
|
|
9686
10239
|
});
|
|
9687
10240
|
const versionRecordToken = {
|
|
9688
|
-
currencySymbol: (0,
|
|
9689
|
-
tokenName: (0,
|
|
10241
|
+
currencySymbol: (0, import_lucid65.fromHex)((0, import_lucid65.mintingPolicyToId)(versionRecordTokenPolicy)),
|
|
10242
|
+
tokenName: (0, import_lucid65.fromHex)((0, import_lucid65.fromText)(tn.versionRecord))
|
|
9690
10243
|
};
|
|
9691
10244
|
const versionRegistryValidator = mkVersionRegistryValidator();
|
|
9692
|
-
const versionRegistryValHash = (0,
|
|
10245
|
+
const versionRegistryValHash = (0, import_lucid65.validatorToScriptHash)(
|
|
9693
10246
|
versionRegistryValidator
|
|
9694
10247
|
);
|
|
9695
10248
|
const cdpCreatorAsset = await mintOneTimeAsset(
|
|
@@ -9710,7 +10263,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9710
10263
|
versionRecordToken: toSystemParamsAsset(versionRecordToken)
|
|
9711
10264
|
};
|
|
9712
10265
|
const collectorValidator = mkCollectorValidatorFromSP(collectorParams);
|
|
9713
|
-
const collectorValHash = (0,
|
|
10266
|
+
const collectorValHash = (0, import_lucid65.validatorToScriptHash)(collectorValidator);
|
|
9714
10267
|
const stakingParams = {
|
|
9715
10268
|
stakingManagerNFT: toSystemParamsAsset(stakingManagerAsset),
|
|
9716
10269
|
stakingToken: toSystemParamsAsset(stakingToken),
|
|
@@ -9719,7 +10272,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9719
10272
|
indyToken: toSystemParamsAsset(indyAsset),
|
|
9720
10273
|
collectorValHash
|
|
9721
10274
|
};
|
|
9722
|
-
const stakingValHash = (0,
|
|
10275
|
+
const stakingValHash = (0, import_lucid65.validatorToScriptHash)(
|
|
9723
10276
|
mkStakingValidatorFromSP(stakingParams)
|
|
9724
10277
|
);
|
|
9725
10278
|
await initStakingManager(lucid, stakingParams);
|
|
@@ -9728,9 +10281,9 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9728
10281
|
versionRecordToken: toSystemParamsAsset(versionRecordToken)
|
|
9729
10282
|
};
|
|
9730
10283
|
const iassetValidator = mkIAssetValidatorFromSP(iassetParams);
|
|
9731
|
-
const iassetValHash = (0,
|
|
10284
|
+
const iassetValHash = (0, import_lucid65.validatorToScriptHash)(iassetValidator);
|
|
9732
10285
|
const assetSymbolPolicy = mkIAssetTokenPolicy(cdpToken);
|
|
9733
|
-
const assetSymbol = (0,
|
|
10286
|
+
const assetSymbol = (0, import_lucid65.mintingPolicyToId)(assetSymbolPolicy);
|
|
9734
10287
|
const snapshotEpochToScaleToSumToken = deriveAuthToken(
|
|
9735
10288
|
stabilityPoolToken,
|
|
9736
10289
|
tn.snapshotEpochToScaleToSum
|
|
@@ -9753,14 +10306,14 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9753
10306
|
stakeCredential: spStakingCred
|
|
9754
10307
|
};
|
|
9755
10308
|
const stabilityPoolValidator = mkStabilityPoolValidatorFromSP(stabilityPoolParams);
|
|
9756
|
-
const stabilityPoolValHash = (0,
|
|
10309
|
+
const stabilityPoolValHash = (0, import_lucid65.validatorToScriptHash)(stabilityPoolValidator);
|
|
9757
10310
|
const treasuryParams = {
|
|
9758
10311
|
upgradeToken: toSystemParamsAsset(upgradeToken),
|
|
9759
10312
|
versionRecordToken: toSystemParamsAsset(versionRecordToken),
|
|
9760
10313
|
treasuryUtxosStakeCredential: treasuryStakingCred
|
|
9761
10314
|
};
|
|
9762
10315
|
const treasuryValidator = mkTreasuryValidatorFromSP(treasuryParams);
|
|
9763
|
-
const treasuryValHash = (0,
|
|
10316
|
+
const treasuryValHash = (0, import_lucid65.validatorToScriptHash)(treasuryValidator);
|
|
9764
10317
|
await initTreasury(
|
|
9765
10318
|
lucid,
|
|
9766
10319
|
treasuryParams,
|
|
@@ -9783,7 +10336,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9783
10336
|
const interestCollectionValidator = mkInterestCollectionValidatorFromSP(
|
|
9784
10337
|
interestCollectionParams
|
|
9785
10338
|
);
|
|
9786
|
-
const interestCollectionValHash = (0,
|
|
10339
|
+
const interestCollectionValHash = (0, import_lucid65.validatorToScriptHash)(
|
|
9787
10340
|
interestCollectionValidator
|
|
9788
10341
|
);
|
|
9789
10342
|
await initInterestCollector(
|
|
@@ -9812,10 +10365,10 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9812
10365
|
biasTime
|
|
9813
10366
|
};
|
|
9814
10367
|
const cdpRedeemValidator = mkCdpRedeemValidatorFromSP(cdpRedeemParams);
|
|
9815
|
-
const cdpRedeemValHash = (0,
|
|
9816
|
-
const cdpRedeemRewardAddr = (0,
|
|
10368
|
+
const cdpRedeemValHash = (0, import_lucid65.validatorToScriptHash)(cdpRedeemValidator);
|
|
10369
|
+
const cdpRedeemRewardAddr = (0, import_lucid65.credentialToRewardAddress)(
|
|
9817
10370
|
lucid.config().network,
|
|
9818
|
-
(0,
|
|
10371
|
+
(0, import_lucid65.scriptHashToCredential)(cdpRedeemValHash)
|
|
9819
10372
|
);
|
|
9820
10373
|
await submitTx(lucid, lucid.newTx().register.Stake(cdpRedeemRewardAddr));
|
|
9821
10374
|
const cdpParams = {
|
|
@@ -9834,7 +10387,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9834
10387
|
biasTime
|
|
9835
10388
|
};
|
|
9836
10389
|
const cdpValidator = mkCdpValidatorFromSP(cdpParams);
|
|
9837
|
-
const cdpValHash = (0,
|
|
10390
|
+
const cdpValHash = (0, import_lucid65.validatorToScriptHash)(cdpValidator);
|
|
9838
10391
|
const cdpCreatorParams = {
|
|
9839
10392
|
cdpCreatorNft: toSystemParamsAsset(cdpCreatorAsset),
|
|
9840
10393
|
cdpAssetCs: { unCurrencySymbol: assetSymbol },
|
|
@@ -9849,7 +10402,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9849
10402
|
biasTime: cdpParams.biasTime
|
|
9850
10403
|
};
|
|
9851
10404
|
const cdpCreatorValidator = mkCDPCreatorValidatorFromSP(cdpCreatorParams);
|
|
9852
|
-
const cdpCreatorValHash = (0,
|
|
10405
|
+
const cdpCreatorValHash = (0, import_lucid65.validatorToScriptHash)(cdpCreatorValidator);
|
|
9853
10406
|
const stableswapParams = {
|
|
9854
10407
|
iassetSymbol: { unCurrencySymbol: assetSymbol },
|
|
9855
10408
|
cdpToken: toSystemParamsAsset(cdpToken),
|
|
@@ -9858,7 +10411,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9858
10411
|
treasuryValHash
|
|
9859
10412
|
};
|
|
9860
10413
|
const stableswapValidator = mkStableswapValidatorFromSP(stableswapParams);
|
|
9861
|
-
const stableswapValHash = (0,
|
|
10414
|
+
const stableswapValHash = (0, import_lucid65.validatorToScriptHash)(stableswapValidator);
|
|
9862
10415
|
await initCollector(lucid, collectorParams, numCollectors);
|
|
9863
10416
|
const assetInfos = [];
|
|
9864
10417
|
if (initialAssets.length > 0) {
|
|
@@ -9885,9 +10438,9 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9885
10438
|
lucid,
|
|
9886
10439
|
lucid.newTx().pay.ToAddress(
|
|
9887
10440
|
await lucid.wallet().address(),
|
|
9888
|
-
(0,
|
|
9889
|
-
(0,
|
|
9890
|
-
(0,
|
|
10441
|
+
(0, import_lucid65.addAssets)(
|
|
10442
|
+
(0, import_cardano_offchain_common28.mkAssetsOf)(iassetToken, 1n),
|
|
10443
|
+
(0, import_cardano_offchain_common28.mkLovelacesOf)(BigInt(totalCollateralAssetsCount) * 5000000n)
|
|
9891
10444
|
)
|
|
9892
10445
|
)
|
|
9893
10446
|
);
|
|
@@ -9903,9 +10456,9 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9903
10456
|
lucid,
|
|
9904
10457
|
lucid.newTx().pay.ToAddress(
|
|
9905
10458
|
await lucid.wallet().address(),
|
|
9906
|
-
(0,
|
|
9907
|
-
(0,
|
|
9908
|
-
(0,
|
|
10459
|
+
(0, import_lucid65.addAssets)(
|
|
10460
|
+
(0, import_cardano_offchain_common28.mkAssetsOf)(cdpCreatorAsset, 1n),
|
|
10461
|
+
(0, import_cardano_offchain_common28.mkLovelacesOf)(BigInt(totalStablePoolsCount) * 5000000n)
|
|
9909
10462
|
)
|
|
9910
10463
|
)
|
|
9911
10464
|
);
|
|
@@ -9961,7 +10514,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9961
10514
|
treasuryValHash
|
|
9962
10515
|
};
|
|
9963
10516
|
const executeValidator = mkExecuteValidatorFromSP(executeParams);
|
|
9964
|
-
const executeValHash = (0,
|
|
10517
|
+
const executeValHash = (0, import_lucid65.validatorToScriptHash)(executeValidator);
|
|
9965
10518
|
const pollShardParams = {
|
|
9966
10519
|
pollToken: toSystemParamsAsset(pollToken),
|
|
9967
10520
|
stakingToken: toSystemParamsAsset(stakingToken),
|
|
@@ -9969,7 +10522,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9969
10522
|
stakingValHash
|
|
9970
10523
|
};
|
|
9971
10524
|
const pollShardValidator = mkPollShardValidatorFromSP(pollShardParams);
|
|
9972
|
-
const pollShardValHash = (0,
|
|
10525
|
+
const pollShardValHash = (0, import_lucid65.validatorToScriptHash)(pollShardValidator);
|
|
9973
10526
|
const pollManagerParams = {
|
|
9974
10527
|
govNFT: toSystemParamsAsset(govNftAsset),
|
|
9975
10528
|
pollToken: toSystemParamsAsset(pollToken),
|
|
@@ -9981,7 +10534,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9981
10534
|
treasuryValHash
|
|
9982
10535
|
};
|
|
9983
10536
|
const pollManagerValidator = mkPollManagerValidatorFromSP(pollManagerParams);
|
|
9984
|
-
const pollManagerValHash = (0,
|
|
10537
|
+
const pollManagerValHash = (0, import_lucid65.validatorToScriptHash)(pollManagerValidator);
|
|
9985
10538
|
const govParams = {
|
|
9986
10539
|
gBiasTime: gBiasTime ? BigInt(gBiasTime) : BigInt(biasTime),
|
|
9987
10540
|
govNFT: toSystemParamsAsset(govNftAsset),
|
|
@@ -9996,7 +10549,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
9996
10549
|
iassetSymbol: { unCurrencySymbol: assetSymbol }
|
|
9997
10550
|
};
|
|
9998
10551
|
const govValidator = mkGovValidatorFromSP(govParams);
|
|
9999
|
-
const govValHash = (0,
|
|
10552
|
+
const govValHash = (0, import_lucid65.validatorToScriptHash)(govValidator);
|
|
10000
10553
|
await initGovernance(
|
|
10001
10554
|
lucid,
|
|
10002
10555
|
govParams,
|
|
@@ -10012,36 +10565,36 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
10012
10565
|
versionRecordToken: cdpParams.versionRecordToken
|
|
10013
10566
|
};
|
|
10014
10567
|
const robValidator = mkRobValidatorFromSP(robParams);
|
|
10015
|
-
const robValHash = (0,
|
|
10016
|
-
const cdpTokenPolicy = mkAuthTokenPolicy(cdpCreatorAsset, (0,
|
|
10568
|
+
const robValHash = (0, import_lucid65.validatorToScriptHash)(robValidator);
|
|
10569
|
+
const cdpTokenPolicy = mkAuthTokenPolicy(cdpCreatorAsset, (0, import_lucid65.fromText)(tn.cdp));
|
|
10017
10570
|
const iassetTokenPolicy = mkAuthTokenPolicy(
|
|
10018
10571
|
upgradeToken,
|
|
10019
|
-
(0,
|
|
10572
|
+
(0, import_lucid65.fromText)(tn.iasset)
|
|
10020
10573
|
);
|
|
10021
10574
|
const accountTokenPolicy = mkAuthTokenPolicy(
|
|
10022
10575
|
stabilityPoolToken,
|
|
10023
|
-
(0,
|
|
10576
|
+
(0, import_lucid65.fromText)(tn.account)
|
|
10024
10577
|
);
|
|
10025
10578
|
const stabilityPoolTokenPolicy = mkAuthTokenPolicy(
|
|
10026
10579
|
upgradeToken,
|
|
10027
|
-
(0,
|
|
10580
|
+
(0, import_lucid65.fromText)(tn.stabilityPool)
|
|
10028
10581
|
);
|
|
10029
10582
|
const pollTokenPolicy = mkAuthTokenPolicy(
|
|
10030
10583
|
govNftAsset,
|
|
10031
|
-
(0,
|
|
10584
|
+
(0, import_lucid65.fromText)(tn.pollManager)
|
|
10032
10585
|
);
|
|
10033
10586
|
const stakingTokenPolicy = mkAuthTokenPolicy(
|
|
10034
10587
|
stakingManagerAsset,
|
|
10035
|
-
(0,
|
|
10588
|
+
(0, import_lucid65.fromText)(tn.staking)
|
|
10036
10589
|
);
|
|
10037
10590
|
const collateralAssetAuthTokenPolicy = mkAuthTokenPolicy(
|
|
10038
10591
|
iassetToken,
|
|
10039
|
-
(0,
|
|
10592
|
+
(0, import_lucid65.fromText)(tn.collateralAsset)
|
|
10040
10593
|
);
|
|
10041
|
-
const upgradeTokenPolicy = mkAuthTokenPolicy(pollToken, (0,
|
|
10594
|
+
const upgradeTokenPolicy = mkAuthTokenPolicy(pollToken, (0, import_lucid65.fromText)(tn.upgrade));
|
|
10042
10595
|
const snapshotEpochToScaleToSumTokenPolicy = mkAuthTokenPolicy(
|
|
10043
10596
|
stabilityPoolToken,
|
|
10044
|
-
(0,
|
|
10597
|
+
(0, import_lucid65.fromText)(tn.snapshotEpochToScaleToSum)
|
|
10045
10598
|
);
|
|
10046
10599
|
const sysParams = {
|
|
10047
10600
|
cdpParams,
|
|
@@ -10185,19 +10738,19 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
10185
10738
|
}
|
|
10186
10739
|
|
|
10187
10740
|
// src/contracts/stableswap/helpers.ts
|
|
10188
|
-
var
|
|
10741
|
+
var import_lucid66 = require("@lucid-evolution/lucid");
|
|
10189
10742
|
|
|
10190
10743
|
// src/contracts/stableswap/types-new.ts
|
|
10191
|
-
var
|
|
10744
|
+
var import_cardano_offchain_common29 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
10192
10745
|
var import_evolution20 = require("@evolution-sdk/evolution");
|
|
10193
|
-
var
|
|
10746
|
+
var import_fp_ts21 = require("fp-ts");
|
|
10194
10747
|
var import_effect3 = require("effect");
|
|
10195
10748
|
var OpaqueData4 = import_effect3.Schema.typeSchema(import_evolution20.Data.DataSchema);
|
|
10196
10749
|
var StableswapOrderDatumSchema = import_evolution20.TSchema.Struct({
|
|
10197
10750
|
iasset: import_evolution20.TSchema.ByteArray,
|
|
10198
|
-
collateralAsset:
|
|
10751
|
+
collateralAsset: import_cardano_offchain_common29.AssetClassSchema,
|
|
10199
10752
|
owner: import_evolution20.TSchema.ByteArray,
|
|
10200
|
-
destination:
|
|
10753
|
+
destination: import_cardano_offchain_common29.AddressSchema,
|
|
10201
10754
|
destinationInlineDatum: import_evolution20.TSchema.NullOr(OpaqueData4),
|
|
10202
10755
|
maxExecutionFee: import_evolution20.TSchema.Integer,
|
|
10203
10756
|
maxFeeRatio: RationalSchema
|
|
@@ -10222,7 +10775,7 @@ var StableswapOrderRedeemerSchema = import_evolution20.TSchema.Union(
|
|
|
10222
10775
|
);
|
|
10223
10776
|
var StableswapOutputDatumSchema = import_evolution20.TSchema.Tuple([
|
|
10224
10777
|
import_evolution20.TSchema.ByteArray,
|
|
10225
|
-
|
|
10778
|
+
import_cardano_offchain_common29.OutputReferenceSchema
|
|
10226
10779
|
]);
|
|
10227
10780
|
function serialiseStableswapOrderDatum(d) {
|
|
10228
10781
|
return import_evolution20.Data.withSchema(
|
|
@@ -10232,22 +10785,22 @@ function serialiseStableswapOrderDatum(d) {
|
|
|
10232
10785
|
}
|
|
10233
10786
|
function parseStableswapOrderDatum(datum) {
|
|
10234
10787
|
try {
|
|
10235
|
-
return
|
|
10788
|
+
return import_fp_ts21.option.some(
|
|
10236
10789
|
import_evolution20.Data.withSchema(
|
|
10237
10790
|
StableswapOrderDatumSchema,
|
|
10238
10791
|
DEFAULT_SCHEMA_OPTIONS
|
|
10239
10792
|
).fromCBORHex(datum)
|
|
10240
10793
|
);
|
|
10241
10794
|
} catch (_) {
|
|
10242
|
-
return
|
|
10795
|
+
return import_fp_ts21.option.none;
|
|
10243
10796
|
}
|
|
10244
10797
|
}
|
|
10245
10798
|
function parseStableswapOrderDatumOrThrow(datum) {
|
|
10246
|
-
return
|
|
10799
|
+
return import_fp_ts21.function.pipe(
|
|
10247
10800
|
parseStableswapOrderDatum(datum),
|
|
10248
|
-
|
|
10801
|
+
import_fp_ts21.option.match(() => {
|
|
10249
10802
|
throw new Error("Expected a Stableswap Order datum.");
|
|
10250
|
-
},
|
|
10803
|
+
}, import_fp_ts21.function.identity)
|
|
10251
10804
|
);
|
|
10252
10805
|
}
|
|
10253
10806
|
function serialiseStableswapOutputDatum(d) {
|
|
@@ -10264,22 +10817,22 @@ function serialiseStableswapOrderRedeemer(r) {
|
|
|
10264
10817
|
}
|
|
10265
10818
|
function parseStableswapOrderRedeemer(redeemerCborHex) {
|
|
10266
10819
|
try {
|
|
10267
|
-
return
|
|
10820
|
+
return import_fp_ts21.option.some(
|
|
10268
10821
|
import_evolution20.Data.withSchema(
|
|
10269
10822
|
StableswapOrderRedeemerSchema,
|
|
10270
10823
|
DEFAULT_SCHEMA_OPTIONS
|
|
10271
10824
|
).fromCBORHex(redeemerCborHex)
|
|
10272
10825
|
);
|
|
10273
10826
|
} catch (_) {
|
|
10274
|
-
return
|
|
10827
|
+
return import_fp_ts21.option.none;
|
|
10275
10828
|
}
|
|
10276
10829
|
}
|
|
10277
10830
|
function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
|
|
10278
|
-
return
|
|
10831
|
+
return import_fp_ts21.function.pipe(
|
|
10279
10832
|
parseStableswapOrderRedeemer(redeemerCborHex),
|
|
10280
|
-
|
|
10833
|
+
import_fp_ts21.option.match(() => {
|
|
10281
10834
|
throw new Error("Expected a Stableswap Order redeemer.");
|
|
10282
|
-
},
|
|
10835
|
+
}, import_fp_ts21.function.identity)
|
|
10283
10836
|
);
|
|
10284
10837
|
}
|
|
10285
10838
|
|
|
@@ -10289,9 +10842,9 @@ var BASE_MAX_EXECUTION_FEE = 1000000n;
|
|
|
10289
10842
|
function createDestinationDatum(datum, outRef) {
|
|
10290
10843
|
if (!datum) {
|
|
10291
10844
|
return serialiseStableswapOutputDatum([
|
|
10292
|
-
(0,
|
|
10845
|
+
(0, import_lucid66.fromHex)((0, import_lucid66.fromText)("IndigoStableswap")),
|
|
10293
10846
|
{
|
|
10294
|
-
txHash: (0,
|
|
10847
|
+
txHash: (0, import_lucid66.fromHex)(outRef.txHash),
|
|
10295
10848
|
outputIndex: BigInt(outRef.outputIndex)
|
|
10296
10849
|
}
|
|
10297
10850
|
]);
|
|
@@ -10300,28 +10853,28 @@ function createDestinationDatum(datum, outRef) {
|
|
|
10300
10853
|
}
|
|
10301
10854
|
|
|
10302
10855
|
// src/contracts/stableswap/transactions.ts
|
|
10303
|
-
var
|
|
10304
|
-
var
|
|
10305
|
-
var
|
|
10856
|
+
var import_lucid67 = require("@lucid-evolution/lucid");
|
|
10857
|
+
var import_cardano_offchain_common30 = require("@3rd-eye-labs/cardano-offchain-common");
|
|
10858
|
+
var import_fp_ts22 = require("fp-ts");
|
|
10306
10859
|
var import_Array3 = require("fp-ts/lib/Array");
|
|
10307
10860
|
async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
|
|
10308
10861
|
const myAddress = await lucid.wallet().address();
|
|
10309
|
-
const pkh = (0,
|
|
10862
|
+
const pkh = (0, import_lucid67.paymentCredentialOf)(myAddress);
|
|
10310
10863
|
const datum = {
|
|
10311
|
-
iasset: (0,
|
|
10864
|
+
iasset: (0, import_lucid67.fromHex)((0, import_lucid67.fromText)(iasset)),
|
|
10312
10865
|
collateralAsset,
|
|
10313
|
-
owner: (0,
|
|
10314
|
-
destination: (0,
|
|
10866
|
+
owner: (0, import_lucid67.fromHex)(pkh.hash),
|
|
10867
|
+
destination: (0, import_cardano_offchain_common30.addressFromBech32)(destinationAddress ?? myAddress),
|
|
10315
10868
|
destinationInlineDatum: destinationInlineDatum ?? null,
|
|
10316
10869
|
maxExecutionFee,
|
|
10317
10870
|
maxFeeRatio: maxFeeRatio ?? (minting ? poolDatum.mintingFeeRatio : poolDatum.redemptionFeeRatio)
|
|
10318
10871
|
};
|
|
10319
|
-
const assetsToSwap = minting ? (0,
|
|
10872
|
+
const assetsToSwap = minting ? (0, import_cardano_offchain_common30.mkAssetsOf)(collateralAsset, amount) : (0, import_cardano_offchain_common30.mkAssetsOf)(
|
|
10320
10873
|
{
|
|
10321
|
-
currencySymbol: (0,
|
|
10874
|
+
currencySymbol: (0, import_lucid67.fromHex)(
|
|
10322
10875
|
params.stableswapParams.iassetSymbol.unCurrencySymbol
|
|
10323
10876
|
),
|
|
10324
|
-
tokenName: (0,
|
|
10877
|
+
tokenName: (0, import_lucid67.fromHex)((0, import_lucid67.fromText)(iasset))
|
|
10325
10878
|
},
|
|
10326
10879
|
amount
|
|
10327
10880
|
);
|
|
@@ -10339,8 +10892,8 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
|
|
|
10339
10892
|
);
|
|
10340
10893
|
const roundedExpectedOutputLovelaces = (expectedOutputLovelaces / 1000000n + 1n) * 1000000n;
|
|
10341
10894
|
return lucid.newTx().pay.ToContract(
|
|
10342
|
-
(0,
|
|
10343
|
-
hash: (0,
|
|
10895
|
+
(0, import_lucid67.credentialToAddress)(lucid.config().network, {
|
|
10896
|
+
hash: (0, import_lucid67.validatorToScriptHash)(
|
|
10344
10897
|
mkStableswapValidatorFromSP(params.stableswapParams)
|
|
10345
10898
|
),
|
|
10346
10899
|
type: "Script"
|
|
@@ -10349,16 +10902,16 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
|
|
|
10349
10902
|
kind: "inline",
|
|
10350
10903
|
value: serialiseStableswapOrderDatum(datum)
|
|
10351
10904
|
},
|
|
10352
|
-
(0,
|
|
10905
|
+
(0, import_lucid67.addAssets)(
|
|
10353
10906
|
assetsToSwap,
|
|
10354
|
-
(0,
|
|
10907
|
+
(0, import_cardano_offchain_common30.mkLovelacesOf)(
|
|
10355
10908
|
roundedExpectedOutputLovelaces + maxExecutionFee + additionalLovelaces
|
|
10356
10909
|
)
|
|
10357
10910
|
)
|
|
10358
10911
|
);
|
|
10359
10912
|
}
|
|
10360
10913
|
async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
|
|
10361
|
-
const stableswapScriptRefUtxo = (0,
|
|
10914
|
+
const stableswapScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
|
|
10362
10915
|
await lucid.utxosByOutRef([
|
|
10363
10916
|
fromSystemParamsScriptRef(
|
|
10364
10917
|
sysParams.scriptReferences.stableswapValidatorRef
|
|
@@ -10366,20 +10919,20 @@ async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
|
|
|
10366
10919
|
]),
|
|
10367
10920
|
(_) => new Error("Expected a single Stableswap Ref Script UTXO")
|
|
10368
10921
|
);
|
|
10369
|
-
const stableswapOrderUtxo = (0,
|
|
10922
|
+
const stableswapOrderUtxo = (0, import_cardano_offchain_common30.matchSingle)(
|
|
10370
10923
|
await lucid.utxosByOutRef([stableswapOrderOref]),
|
|
10371
10924
|
(_) => new Error("Expected a single Stableswap Order UTXO.")
|
|
10372
10925
|
);
|
|
10373
10926
|
const stableswapOrderDatum = parseStableswapOrderDatumOrThrow(
|
|
10374
|
-
(0,
|
|
10927
|
+
(0, import_cardano_offchain_common30.getInlineDatumOrThrow)(stableswapOrderUtxo)
|
|
10375
10928
|
);
|
|
10376
10929
|
return lucid.newTx().readFrom([stableswapScriptRefUtxo]).collectFrom(
|
|
10377
10930
|
[stableswapOrderUtxo],
|
|
10378
10931
|
serialiseStableswapOrderRedeemer("CancelStableswapOrder")
|
|
10379
|
-
).addSignerKey((0,
|
|
10932
|
+
).addSignerKey((0, import_lucid67.toHex)(stableswapOrderDatum.owner));
|
|
10380
10933
|
}
|
|
10381
10934
|
async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPoolOref, treasuryOref, sysParams, lucid) {
|
|
10382
|
-
const stableswapScriptRefUtxo = (0,
|
|
10935
|
+
const stableswapScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
|
|
10383
10936
|
await lucid.utxosByOutRef([
|
|
10384
10937
|
fromSystemParamsScriptRef(
|
|
10385
10938
|
sysParams.scriptReferences.stableswapValidatorRef
|
|
@@ -10387,13 +10940,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
10387
10940
|
]),
|
|
10388
10941
|
(_) => new Error("Expected a single Stableswap Ref Script UTXO")
|
|
10389
10942
|
);
|
|
10390
|
-
const cdpScriptRefUtxo = (0,
|
|
10943
|
+
const cdpScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
|
|
10391
10944
|
await lucid.utxosByOutRef([
|
|
10392
10945
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
10393
10946
|
]),
|
|
10394
10947
|
(_) => new Error("Expected a single CDP Ref Script UTXO")
|
|
10395
10948
|
);
|
|
10396
|
-
const iAssetTokenPolicyRefScriptUtxo = (0,
|
|
10949
|
+
const iAssetTokenPolicyRefScriptUtxo = (0, import_cardano_offchain_common30.matchSingle)(
|
|
10397
10950
|
await lucid.utxosByOutRef([
|
|
10398
10951
|
fromSystemParamsScriptRef(
|
|
10399
10952
|
sysParams.scriptReferences.iAssetTokenPolicyRef
|
|
@@ -10405,7 +10958,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
10405
10958
|
throw new Error("At least one order must be provided.");
|
|
10406
10959
|
}
|
|
10407
10960
|
const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
|
|
10408
|
-
const sortedStableswapOrderUtxos = (0,
|
|
10961
|
+
const sortedStableswapOrderUtxos = (0, import_lucid67.sortUTxOs)(
|
|
10409
10962
|
stableswapOrderUtxos,
|
|
10410
10963
|
"Canonical"
|
|
10411
10964
|
);
|
|
@@ -10414,32 +10967,32 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
10414
10967
|
}
|
|
10415
10968
|
const mainOrderUtxo = sortedStableswapOrderUtxos[0];
|
|
10416
10969
|
const mainOrderDatum = parseStableswapOrderDatumOrThrow(
|
|
10417
|
-
(0,
|
|
10970
|
+
(0, import_cardano_offchain_common30.getInlineDatumOrThrow)(mainOrderUtxo)
|
|
10418
10971
|
);
|
|
10419
10972
|
const iassetAc = {
|
|
10420
|
-
currencySymbol: (0,
|
|
10973
|
+
currencySymbol: (0, import_lucid67.fromHex)(
|
|
10421
10974
|
sysParams.stableswapParams.iassetSymbol.unCurrencySymbol
|
|
10422
10975
|
),
|
|
10423
10976
|
tokenName: mainOrderDatum.iasset
|
|
10424
10977
|
};
|
|
10425
10978
|
const collateralAc = mainOrderDatum.collateralAsset;
|
|
10426
|
-
const stableswapPoolUtxo = (0,
|
|
10979
|
+
const stableswapPoolUtxo = (0, import_cardano_offchain_common30.matchSingle)(
|
|
10427
10980
|
await lucid.utxosByOutRef([stableswapPoolOref]),
|
|
10428
10981
|
(_) => new Error("Expected a single cdp UTXO")
|
|
10429
10982
|
);
|
|
10430
10983
|
const stableswapPoolDatum = parseStableswapPoolDatumOrThrow(
|
|
10431
|
-
(0,
|
|
10984
|
+
(0, import_cardano_offchain_common30.getInlineDatumOrThrow)(stableswapPoolUtxo)
|
|
10432
10985
|
);
|
|
10433
10986
|
const ordersInfo = sortedStableswapOrderUtxos.map(
|
|
10434
10987
|
(orderUtxo) => {
|
|
10435
10988
|
const orderDatum = parseStableswapOrderDatumOrThrow(
|
|
10436
|
-
(0,
|
|
10989
|
+
(0, import_cardano_offchain_common30.getInlineDatumOrThrow)(orderUtxo)
|
|
10437
10990
|
);
|
|
10438
|
-
if ((0,
|
|
10991
|
+
if ((0, import_lucid67.toHex)(orderDatum.iasset) != (0, import_lucid67.toHex)(mainOrderDatum.iasset) || (0, import_lucid67.toHex)(orderDatum.collateralAsset.currencySymbol) != (0, import_lucid67.toHex)(mainOrderDatum.collateralAsset.currencySymbol) || (0, import_lucid67.toHex)(orderDatum.collateralAsset.tokenName) != (0, import_lucid67.toHex)(mainOrderDatum.collateralAsset.tokenName)) {
|
|
10439
10992
|
throw new Error("Wrong batch of orders");
|
|
10440
10993
|
}
|
|
10441
|
-
const suppliedIasset = (0,
|
|
10442
|
-
const suppliedCollateralAsset = (0,
|
|
10994
|
+
const suppliedIasset = (0, import_cardano_offchain_common30.assetClassValueOf)(orderUtxo.assets, iassetAc);
|
|
10995
|
+
const suppliedCollateralAsset = (0, import_cardano_offchain_common30.assetClassValueOf)(
|
|
10443
10996
|
orderUtxo.assets,
|
|
10444
10997
|
collateralAc
|
|
10445
10998
|
);
|
|
@@ -10563,9 +11116,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
10563
11116
|
}
|
|
10564
11117
|
}
|
|
10565
11118
|
);
|
|
10566
|
-
const totalSwapInfo =
|
|
11119
|
+
const totalSwapInfo = import_fp_ts22.function.pipe(
|
|
10567
11120
|
ordersInfo,
|
|
10568
|
-
|
|
11121
|
+
import_fp_ts22.array.reduce(
|
|
10569
11122
|
{
|
|
10570
11123
|
suppliedCollateralAsset: 0n,
|
|
10571
11124
|
suppliedIasset: 0n,
|
|
@@ -10607,20 +11160,20 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
10607
11160
|
kind: "inline",
|
|
10608
11161
|
value: serialiseStableswapPoolDatum(stableswapPoolDatum)
|
|
10609
11162
|
},
|
|
10610
|
-
collateralAmtChangePool != 0n ? (0,
|
|
11163
|
+
collateralAmtChangePool != 0n ? (0, import_lucid67.addAssets)(
|
|
10611
11164
|
stableswapPoolUtxo.assets,
|
|
10612
|
-
(0,
|
|
11165
|
+
(0, import_cardano_offchain_common30.mkAssetsOf)(collateralAc, collateralAmtChangePool)
|
|
10613
11166
|
) : stableswapPoolUtxo.assets
|
|
10614
11167
|
).setMinFee(2055720n);
|
|
10615
11168
|
if (amountToMint !== 0n) {
|
|
10616
|
-
tx.mintAssets((0,
|
|
11169
|
+
tx.mintAssets((0, import_cardano_offchain_common30.mkAssetsOf)(iassetAc, amountToMint), import_lucid67.Data.void());
|
|
10617
11170
|
}
|
|
10618
|
-
|
|
11171
|
+
import_fp_ts22.function.pipe(
|
|
10619
11172
|
ordersInfo,
|
|
10620
|
-
|
|
11173
|
+
import_fp_ts22.array.reduce(tx, (acc, orderInfo) => {
|
|
10621
11174
|
return acc.collectFrom(
|
|
10622
11175
|
[orderInfo.utxo],
|
|
10623
|
-
(0,
|
|
11176
|
+
(0, import_cardano_offchain_common30.isSameOutRef)(orderInfo.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
|
|
10624
11177
|
kind: "selected",
|
|
10625
11178
|
makeRedeemer: (inputIndices) => {
|
|
10626
11179
|
return serialiseStableswapOrderRedeemer({
|
|
@@ -10633,7 +11186,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
10633
11186
|
inputs: [orderInfo.utxo, mainOrderUtxo]
|
|
10634
11187
|
}
|
|
10635
11188
|
).pay.ToAddressWithData(
|
|
10636
|
-
(0,
|
|
11189
|
+
(0, import_cardano_offchain_common30.addressToBech32)(orderInfo.datum.destination, lucid.config().network),
|
|
10637
11190
|
{
|
|
10638
11191
|
kind: "inline",
|
|
10639
11192
|
value: createDestinationDatum(
|
|
@@ -10641,13 +11194,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
10641
11194
|
orderInfo.utxo
|
|
10642
11195
|
)
|
|
10643
11196
|
},
|
|
10644
|
-
(0,
|
|
11197
|
+
(0, import_lucid67.addAssets)(
|
|
10645
11198
|
// Currently, we always take the max execution fee from the order utxo.
|
|
10646
11199
|
// This can be improved so that we take the actual execution fee.
|
|
10647
|
-
(0,
|
|
10648
|
-
(0,
|
|
11200
|
+
(0, import_cardano_offchain_common30.mkLovelacesOf)(
|
|
11201
|
+
(0, import_cardano_offchain_common30.lovelacesAmt)(orderInfo.utxo.assets) - orderInfo.datum.maxExecutionFee
|
|
10649
11202
|
),
|
|
10650
|
-
orderInfo.swapInfo.owedIasset > 0 ? (0,
|
|
11203
|
+
orderInfo.swapInfo.owedIasset > 0 ? (0, import_cardano_offchain_common30.mkAssetsOf)(iassetAc, orderInfo.swapInfo.owedIasset) : (0, import_cardano_offchain_common30.mkAssetsOf)(
|
|
10651
11204
|
collateralAc,
|
|
10652
11205
|
orderInfo.swapInfo.owedCollateralAsset
|
|
10653
11206
|
)
|
|
@@ -10670,7 +11223,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
10670
11223
|
return tx;
|
|
10671
11224
|
}
|
|
10672
11225
|
async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRef, newMintingFeeRatio, newRedemptionFeeRatio, sysParams, lucid) {
|
|
10673
|
-
const stableswapScriptRefUtxo = (0,
|
|
11226
|
+
const stableswapScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
|
|
10674
11227
|
await lucid.utxosByOutRef([
|
|
10675
11228
|
fromSystemParamsScriptRef(
|
|
10676
11229
|
sysParams.scriptReferences.stableswapValidatorRef
|
|
@@ -10678,22 +11231,22 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
10678
11231
|
]),
|
|
10679
11232
|
(_) => new Error("Expected a single Stableswap Ref Script UTXO")
|
|
10680
11233
|
);
|
|
10681
|
-
const cdpScriptRefUtxo = (0,
|
|
11234
|
+
const cdpScriptRefUtxo = (0, import_cardano_offchain_common30.matchSingle)(
|
|
10682
11235
|
await lucid.utxosByOutRef([
|
|
10683
11236
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
10684
11237
|
]),
|
|
10685
11238
|
(_) => new Error("Expected a single CDP Ref Script UTXO")
|
|
10686
11239
|
);
|
|
10687
|
-
const stableswapPool = (0,
|
|
11240
|
+
const stableswapPool = (0, import_cardano_offchain_common30.matchSingle)(
|
|
10688
11241
|
await lucid.utxosByOutRef([stableswapPoolOutRef]),
|
|
10689
11242
|
(_) => new Error("Expected a single Stableswap Pool UTXO.")
|
|
10690
11243
|
);
|
|
10691
|
-
const stableswapFeeUtxo = (0,
|
|
11244
|
+
const stableswapFeeUtxo = (0, import_cardano_offchain_common30.matchSingle)(
|
|
10692
11245
|
await lucid.utxosByOutRef([stableswapFeeOutRef]),
|
|
10693
11246
|
(_) => new Error("Expected a single Stableswap Fee UTXO.")
|
|
10694
11247
|
);
|
|
10695
11248
|
const stableswapPoolDatum = parseStableswapPoolDatumOrThrow(
|
|
10696
|
-
(0,
|
|
11249
|
+
(0, import_cardano_offchain_common30.getInlineDatumOrThrow)(stableswapPool)
|
|
10697
11250
|
);
|
|
10698
11251
|
const newStableswapPoolDatum = {
|
|
10699
11252
|
...stableswapPoolDatum,
|
|
@@ -10721,7 +11274,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
10721
11274
|
value: serialiseStableswapPoolDatum(newStableswapPoolDatum)
|
|
10722
11275
|
},
|
|
10723
11276
|
stableswapPool.assets
|
|
10724
|
-
).addSignerKey((0,
|
|
11277
|
+
).addSignerKey((0, import_lucid67.toHex)(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
|
|
10725
11278
|
}
|
|
10726
11279
|
// Annotate the CommonJS export names for ESM import in node:
|
|
10727
11280
|
0 && (module.exports = {
|
|
@@ -10748,6 +11301,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
10748
11301
|
InterestOracleDatumSchema,
|
|
10749
11302
|
InterestOracleParamsSchema,
|
|
10750
11303
|
MAX_E2S2S_ENTRIES_COUNT,
|
|
11304
|
+
MAX_REDEMPTIONS_WITH_CDP_OPEN,
|
|
10751
11305
|
MIN_ROB_COLLATERAL_AMT,
|
|
10752
11306
|
ONE_DAY,
|
|
10753
11307
|
ONE_HOUR,
|
|
@@ -10782,6 +11336,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
10782
11336
|
adjustStakingPosition,
|
|
10783
11337
|
alwaysFailValidator,
|
|
10784
11338
|
annulRequest,
|
|
11339
|
+
approximateLeverageRedemptions,
|
|
10785
11340
|
attachOracle,
|
|
10786
11341
|
balance,
|
|
10787
11342
|
batchCollectInterest,
|
|
@@ -10792,8 +11347,11 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
10792
11347
|
burnCdp,
|
|
10793
11348
|
calculateAccruedInterest,
|
|
10794
11349
|
calculateAdaReward,
|
|
11350
|
+
calculateCollateralRatioFromLeverage,
|
|
10795
11351
|
calculateIAssetRedemptionAmt,
|
|
11352
|
+
calculateLeverageFromCollateralRatio,
|
|
10796
11353
|
calculateMinCollateralCappedIAssetRedemptionAmt,
|
|
11354
|
+
calculateTotalCollateralForRedemption,
|
|
10797
11355
|
calculateUnitaryInterest,
|
|
10798
11356
|
calculateUnitaryInterestSinceOracleLastUpdated,
|
|
10799
11357
|
cancelRob,
|
|
@@ -10859,9 +11417,9 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
10859
11417
|
getAssetClassComparisonStr,
|
|
10860
11418
|
getInlineDatumOrThrow,
|
|
10861
11419
|
getPythFeedConfig,
|
|
10862
|
-
getRandomElement,
|
|
10863
11420
|
getUpdatedAccountDeposit,
|
|
10864
11421
|
handleOracleForCollateralAsset,
|
|
11422
|
+
iassetValueOfCollateral,
|
|
10865
11423
|
init,
|
|
10866
11424
|
initCDPCreator,
|
|
10867
11425
|
initCollector,
|
|
@@ -10875,8 +11433,10 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
10875
11433
|
initTreasury,
|
|
10876
11434
|
initializeAsset,
|
|
10877
11435
|
insertSorted,
|
|
11436
|
+
isBuyOrderFullyRedeemed,
|
|
10878
11437
|
isFullyRedeemed,
|
|
10879
11438
|
isSameEpochToScaleKey,
|
|
11439
|
+
leverageCdpWithRob,
|
|
10880
11440
|
liquidateCdp,
|
|
10881
11441
|
liquidationHelper,
|
|
10882
11442
|
loadSystemParamsFromFile,
|
|
@@ -10940,10 +11500,6 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
10940
11500
|
parseIAssetDatumOrThrow,
|
|
10941
11501
|
parseInterestCollectionDatum,
|
|
10942
11502
|
parseInterestOracleDatum,
|
|
10943
|
-
parsePollManager,
|
|
10944
|
-
parsePollManagerOrThrow,
|
|
10945
|
-
parsePollShard,
|
|
10946
|
-
parsePollShardOrThrow,
|
|
10947
11503
|
parsePriceOracleDatum,
|
|
10948
11504
|
parsePythStateDatum,
|
|
10949
11505
|
parseRobDatum,
|
|
@@ -10964,8 +11520,8 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
10964
11520
|
parseStakingPosition,
|
|
10965
11521
|
parseStakingPositionOrThrow,
|
|
10966
11522
|
partitionEpochToScaleToSums,
|
|
10967
|
-
pollPassQuorum,
|
|
10968
11523
|
processSpRequest,
|
|
11524
|
+
randomRobsSubsetSatisfyingTargetCollateral,
|
|
10969
11525
|
rationalAdd,
|
|
10970
11526
|
rationalCeil,
|
|
10971
11527
|
rationalDiv,
|
|
@@ -10984,7 +11540,10 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
10984
11540
|
requestSpAccountClosure,
|
|
10985
11541
|
requestSpAccountCreation,
|
|
10986
11542
|
rewardSnapshotPrecision,
|
|
10987
|
-
|
|
11543
|
+
robAmtToSpend,
|
|
11544
|
+
robBuyOrderSummary,
|
|
11545
|
+
robCollateralAmtToSpend,
|
|
11546
|
+
robIAssetAmtToSpend,
|
|
10988
11547
|
runCreateScriptRefTx,
|
|
10989
11548
|
runOneShotMintTx,
|
|
10990
11549
|
scriptRef,
|
|
@@ -11001,9 +11560,6 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
11001
11560
|
serialiseInterestCollectionDatum,
|
|
11002
11561
|
serialiseInterestCollectionRedeemer,
|
|
11003
11562
|
serialiseInterestOracleDatum,
|
|
11004
|
-
serialisePollDatum,
|
|
11005
|
-
serialisePollManagerRedeemer,
|
|
11006
|
-
serialisePollShardRedeemer,
|
|
11007
11563
|
serialisePriceOracleDatum,
|
|
11008
11564
|
serialisePriceOracleRedeemer,
|
|
11009
11565
|
serialisePythFeedParams,
|
|
@@ -11032,6 +11588,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
11032
11588
|
startPriceOracleTx,
|
|
11033
11589
|
submitTx,
|
|
11034
11590
|
sum,
|
|
11591
|
+
summarizeActualLeverageRedemptions,
|
|
11035
11592
|
toAssetClassFromLucid,
|
|
11036
11593
|
toDataDerivedPythPrice,
|
|
11037
11594
|
toSystemParamsAsset,
|