@indigo-labs/indigo-sdk 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +7 -0
- package/dist/index.d.mts +992 -905
- package/dist/index.d.ts +992 -905
- package/dist/index.js +2346 -2155
- package/dist/index.mjs +1925 -1750
- package/package.json +13 -21
- package/scripts/bench.sh +0 -0
- package/src/contracts/cdp/helpers.ts +7 -6
- package/src/contracts/cdp/transactions.ts +8 -29
- package/src/contracts/gov/transactions.ts +15 -17
- package/src/contracts/iasset/helpers.ts +2 -7
- package/src/contracts/initialize/actions.ts +0 -2
- package/src/contracts/initialize/helpers.ts +0 -4
- package/src/contracts/interest-collection/transactions.ts +2 -5
- package/src/contracts/interest-oracle/helpers.ts +4 -0
- package/src/contracts/interest-oracle/transactions.ts +1 -4
- package/src/contracts/price-oracle/helpers.ts +5 -11
- package/src/contracts/price-oracle/transactions.ts +2 -7
- package/src/contracts/rob/transactions.ts +0 -2
- package/src/contracts/rob-leverage/transactions.ts +1 -4
- package/{tests/queries/stability-pool-queries.ts → src/contracts/stability-pool/queries.ts} +22 -14
- package/src/contracts/stability-pool/transactions.ts +2 -8
- package/src/contracts/stableswap/helpers.ts +369 -1
- package/src/contracts/stableswap/transactions.ts +43 -191
- package/src/contracts/staking/transactions.ts +2 -7
- package/src/index.ts +4 -3
- package/tests/cdp/actions.ts +0 -11
- package/tests/cdp/cdp-helpers.ts +2 -2
- package/tests/cdp/cdp-queries.ts +8 -5
- package/tests/cdp/cdp.test.ts +409 -620
- package/tests/cdp/transactions-mutated.ts +30 -25
- package/tests/endpoints/initialize.ts +0 -2
- package/tests/gov/actions.ts +7 -32
- package/tests/gov/gov.test.ts +169 -401
- package/tests/indigo-test-helpers.ts +0 -1
- package/tests/initialize.test.ts +15 -20
- package/tests/interest-collection/interest-collection.test.ts +0 -4
- package/tests/interest-oracle.test.ts +1 -8
- package/tests/price-oracle/actions.ts +6 -8
- package/tests/price-oracle/price-oracle.test.ts +1 -13
- package/tests/price-oracle/transactions-mutated.ts +1 -4
- package/tests/pyth/pyth-feeds.test.ts +943 -0
- package/tests/pyth/pyth-indigo.test.ts +8 -12
- package/tests/pyth/pyth.test.ts +1 -2
- package/tests/rob/actions.ts +0 -2
- package/tests/rob/rob-leverage.test.ts +164 -220
- package/tests/rob/rob.test.ts +158 -263
- package/tests/rob/transactions-mutated.ts +7 -18
- package/tests/stability-pool/actions.ts +31 -22
- package/tests/stability-pool.test.ts +226 -319
- package/tests/stableswap/stableswap-actions.ts +0 -1
- package/tests/stableswap/stableswap.test.ts +226 -4
- package/tests/staking.test.ts +2 -13
- package/tests/treasury/treasury.test.ts +6 -30
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
fromHex as fromHex7,
|
|
7
7
|
getInputIndices as getInputIndices3,
|
|
8
8
|
scriptHashToCredential as scriptHashToCredential3,
|
|
9
|
-
slotToUnixTime as slotToUnixTime5,
|
|
10
9
|
toHex as toHex7
|
|
11
10
|
} from "@lucid-evolution/lucid";
|
|
12
11
|
|
|
@@ -431,16 +430,11 @@ function calculateAccruedInterest(now, unitaryInterestSnapshot, mintedAmount, in
|
|
|
431
430
|
}
|
|
432
431
|
|
|
433
432
|
// src/contracts/price-oracle/helpers.ts
|
|
434
|
-
|
|
435
|
-
slotToUnixTime
|
|
436
|
-
unixTimeToSlot
|
|
437
|
-
} from "@lucid-evolution/lucid";
|
|
438
|
-
function oracleExpirationAwareValidity(currentSlot, biasTime, oracleExpiration, network) {
|
|
439
|
-
const validateFrom = slotToUnixTime(network, currentSlot - 1);
|
|
433
|
+
function oracleExpirationAwareValidity(lucid, biasTime, oracleExpiration) {
|
|
434
|
+
const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
|
|
440
435
|
const defaultValidateTo = validateFrom + biasTime;
|
|
441
|
-
const cappedValidateTo = slotToUnixTime(
|
|
442
|
-
|
|
443
|
-
unixTimeToSlot(network, oracleExpiration) - 1
|
|
436
|
+
const cappedValidateTo = lucid.slotToUnixTime(
|
|
437
|
+
lucid.unixTimeToSlot(oracleExpiration) - 1
|
|
444
438
|
);
|
|
445
439
|
const isOracleActuallyExpired = cappedValidateTo <= validateFrom;
|
|
446
440
|
return {
|
|
@@ -453,7 +447,6 @@ function oracleExpirationAwareValidity(currentSlot, biasTime, oracleExpiration,
|
|
|
453
447
|
import { match as match13, P as P13 } from "ts-pattern";
|
|
454
448
|
|
|
455
449
|
// src/contracts/cdp/helpers.ts
|
|
456
|
-
import { slotToUnixTime as slotToUnixTime2 } from "@lucid-evolution/lucid";
|
|
457
450
|
import { match as match4, P as P4 } from "ts-pattern";
|
|
458
451
|
|
|
459
452
|
// src/utils/indigo-helpers.ts
|
|
@@ -471,11 +464,10 @@ function iassetValueOfCollateral(collateralAmt, oraclePrice) {
|
|
|
471
464
|
rationalDiv(rationalFromInt(collateralAmt), oraclePrice)
|
|
472
465
|
);
|
|
473
466
|
}
|
|
474
|
-
function cdpCollateralRatioPercentage(
|
|
475
|
-
const currentTime = BigInt(slotToUnixTime2(network, currentSlot));
|
|
467
|
+
function cdpCollateralRatioPercentage(now, iassetPrice, cdpUtxoAssets, cdpContent, interestOracleDatum) {
|
|
476
468
|
return match4(cdpContent.cdpFees).with({ ActiveCDPInterestTracking: P4.select() }, (interest) => {
|
|
477
469
|
const interestAmt = calculateAccruedInterest(
|
|
478
|
-
|
|
470
|
+
now,
|
|
479
471
|
interest.unitaryInterestSnapshot,
|
|
480
472
|
cdpContent.mintedAmt,
|
|
481
473
|
interest.lastSettled,
|
|
@@ -1606,7 +1598,6 @@ import {
|
|
|
1606
1598
|
toHex as toHex4,
|
|
1607
1599
|
addAssets as addAssets3,
|
|
1608
1600
|
fromHex as fromHex3,
|
|
1609
|
-
slotToUnixTime as slotToUnixTime3,
|
|
1610
1601
|
sortUTxOs,
|
|
1611
1602
|
getInputIndices as getInputIndices2
|
|
1612
1603
|
} from "@lucid-evolution/lucid";
|
|
@@ -2098,9 +2089,8 @@ function parseCollateralAssetDatumOrThrow(datum) {
|
|
|
2098
2089
|
}
|
|
2099
2090
|
|
|
2100
2091
|
// src/contracts/interest-collection/transactions.ts
|
|
2101
|
-
async function batchCollectInterest(collateralAssetOref, interestCollectorOutRef, interestOracleOutRef, cdpOutRefs, params, lucid
|
|
2102
|
-
const
|
|
2103
|
-
const currentTime = BigInt(slotToUnixTime3(network, currentSlot));
|
|
2092
|
+
async function batchCollectInterest(collateralAssetOref, interestCollectorOutRef, interestOracleOutRef, cdpOutRefs, params, lucid) {
|
|
2093
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
2104
2094
|
const interestCollectionRefScriptUtxo = matchSingle(
|
|
2105
2095
|
await lucid.utxosByOutRef([
|
|
2106
2096
|
fromSystemParamsScriptRef(
|
|
@@ -2196,7 +2186,7 @@ async function batchCollectInterest(collateralAssetOref, interestCollectorOutRef
|
|
|
2196
2186
|
referenceInputs,
|
|
2197
2187
|
false
|
|
2198
2188
|
);
|
|
2199
|
-
const validateFrom =
|
|
2189
|
+
const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
|
|
2200
2190
|
const validateTo = validateFrom + Number(params.cdpParams.biasTime);
|
|
2201
2191
|
const tx = lucid.newTx().validFrom(validateFrom).validTo(validateTo).readFrom(referenceInputs).collectFrom([interestCollectorUtxo], {
|
|
2202
2192
|
kind: "selected",
|
|
@@ -3246,7 +3236,6 @@ import {
|
|
|
3246
3236
|
Data as Data18,
|
|
3247
3237
|
fromHex as fromHex6,
|
|
3248
3238
|
scriptHashToCredential as scriptHashToCredential2,
|
|
3249
|
-
slotToUnixTime as slotToUnixTime4,
|
|
3250
3239
|
toHex as toHex6
|
|
3251
3240
|
} from "@lucid-evolution/lucid";
|
|
3252
3241
|
import { match as match11, P as P11 } from "ts-pattern";
|
|
@@ -3743,11 +3732,9 @@ function derivePythPrice(derivedPythPrice, messageHex) {
|
|
|
3743
3732
|
// src/contracts/iasset/helpers.ts
|
|
3744
3733
|
import * as Core from "@evolution-sdk/evolution";
|
|
3745
3734
|
var MAX_COLLATERAL_ASSETS_COUNT_PER_IASSET = 9;
|
|
3746
|
-
function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythStateOref, pythMessage, pythConfig, biasTime,
|
|
3735
|
+
function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythStateOref, pythMessage, pythConfig, biasTime, lucid, tx) {
|
|
3747
3736
|
return match11(priceInfo).returnType().with({ Delisted: P11.any }, () => {
|
|
3748
|
-
const currentTime = BigInt(
|
|
3749
|
-
slotToUnixTime4(lucid.config().network, currentSlot)
|
|
3750
|
-
);
|
|
3737
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
3751
3738
|
const validFrom = Number(currentTime - BigInt(biasTime / 2n));
|
|
3752
3739
|
const validTo = Number(currentTime + BigInt(biasTime / 2n));
|
|
3753
3740
|
return Promise.resolve({
|
|
@@ -3768,10 +3755,9 @@ function attachOracle(iasset, collateralAsset, priceInfo, priceOracleOref, pythS
|
|
|
3768
3755
|
);
|
|
3769
3756
|
return {
|
|
3770
3757
|
interval: oracleExpirationAwareValidity(
|
|
3771
|
-
|
|
3758
|
+
lucid,
|
|
3772
3759
|
Number(biasTime),
|
|
3773
|
-
Number(priceOracleDatum.expirationTime)
|
|
3774
|
-
lucid.config().network
|
|
3760
|
+
Number(priceOracleDatum.expirationTime)
|
|
3775
3761
|
),
|
|
3776
3762
|
referenceInputs: [priceOracleUtxo]
|
|
3777
3763
|
};
|
|
@@ -3875,9 +3861,9 @@ async function retrieveAdjustedPrice(iasset, collateralAsset, priceInfo, extraDe
|
|
|
3875
3861
|
}
|
|
3876
3862
|
|
|
3877
3863
|
// src/contracts/cdp/transactions.ts
|
|
3878
|
-
async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, lucid,
|
|
3864
|
+
async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, lucid, pythMessage = void 0, pythStateOref = void 0) {
|
|
3879
3865
|
const network = lucid.config().network;
|
|
3880
|
-
const currentTime = BigInt(
|
|
3866
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
3881
3867
|
const [pkh, skh] = await addrDetails(lucid);
|
|
3882
3868
|
const cdpCreatorRefScriptUtxo = matchSingle(
|
|
3883
3869
|
await lucid.utxosByOutRef([
|
|
@@ -3999,7 +3985,6 @@ async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref
|
|
|
3999
3985
|
pythMessage,
|
|
4000
3986
|
sysParams.pythConfig,
|
|
4001
3987
|
sysParams.cdpCreatorParams.biasTime,
|
|
4002
|
-
currentSlot,
|
|
4003
3988
|
lucid,
|
|
4004
3989
|
tx
|
|
4005
3990
|
);
|
|
@@ -4047,9 +4032,8 @@ async function openCdp(collateralAmount, mintedAmount, sysParams, cdpCreatorOref
|
|
|
4047
4032
|
});
|
|
4048
4033
|
return tx;
|
|
4049
4034
|
}
|
|
4050
|
-
async function adjustCdp(collateralAdjustment, debtAdjustment, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, interestCollectorOref, sysParams, lucid,
|
|
4051
|
-
const
|
|
4052
|
-
const currentTime = BigInt(slotToUnixTime5(network, currentSlot));
|
|
4035
|
+
async function adjustCdp(collateralAdjustment, debtAdjustment, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, interestCollectorOref, sysParams, lucid, pythMessage = void 0, pythStateOref = void 0) {
|
|
4036
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
4053
4037
|
const cdpRefScriptUtxo = matchSingle(
|
|
4054
4038
|
await lucid.utxosByOutRef([
|
|
4055
4039
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
@@ -4115,7 +4099,6 @@ async function adjustCdp(collateralAdjustment, debtAdjustment, cdpOref, iassetOr
|
|
|
4115
4099
|
pythMessage,
|
|
4116
4100
|
sysParams.pythConfig,
|
|
4117
4101
|
sysParams.cdpParams.biasTime,
|
|
4118
|
-
currentSlot,
|
|
4119
4102
|
lucid,
|
|
4120
4103
|
tx
|
|
4121
4104
|
);
|
|
@@ -4210,7 +4193,7 @@ async function adjustCdp(collateralAdjustment, debtAdjustment, cdpOref, iassetOr
|
|
|
4210
4193
|
tx.addSignerKey(toHex7(cdpDatum.cdpOwner));
|
|
4211
4194
|
return tx;
|
|
4212
4195
|
}
|
|
4213
|
-
async function depositCdp(amount, cdpOref, iassetOref, collateralAssetOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid
|
|
4196
|
+
async function depositCdp(amount, cdpOref, iassetOref, collateralAssetOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid) {
|
|
4214
4197
|
return adjustCdp(
|
|
4215
4198
|
amount,
|
|
4216
4199
|
0n,
|
|
@@ -4222,11 +4205,10 @@ async function depositCdp(amount, cdpOref, iassetOref, collateralAssetOref, inte
|
|
|
4222
4205
|
treasuryOref,
|
|
4223
4206
|
interestCollectorOref,
|
|
4224
4207
|
params,
|
|
4225
|
-
lucid
|
|
4226
|
-
currentSlot
|
|
4208
|
+
lucid
|
|
4227
4209
|
);
|
|
4228
4210
|
}
|
|
4229
|
-
async function withdrawCdp(amount, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid,
|
|
4211
|
+
async function withdrawCdp(amount, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid, pythMessage = void 0, pythStateOref = void 0) {
|
|
4230
4212
|
return adjustCdp(
|
|
4231
4213
|
-amount,
|
|
4232
4214
|
0n,
|
|
@@ -4239,12 +4221,11 @@ async function withdrawCdp(amount, cdpOref, iassetOref, collateralAssetOref, pri
|
|
|
4239
4221
|
interestCollectorOref,
|
|
4240
4222
|
params,
|
|
4241
4223
|
lucid,
|
|
4242
|
-
currentSlot,
|
|
4243
4224
|
pythMessage,
|
|
4244
4225
|
pythStateOref
|
|
4245
4226
|
);
|
|
4246
4227
|
}
|
|
4247
|
-
async function mintCdp(amount, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid,
|
|
4228
|
+
async function mintCdp(amount, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid, pythMessage = void 0, pythStateOref = void 0) {
|
|
4248
4229
|
return adjustCdp(
|
|
4249
4230
|
0n,
|
|
4250
4231
|
amount,
|
|
@@ -4257,12 +4238,11 @@ async function mintCdp(amount, cdpOref, iassetOref, collateralAssetOref, priceOr
|
|
|
4257
4238
|
interestCollectorOref,
|
|
4258
4239
|
params,
|
|
4259
4240
|
lucid,
|
|
4260
|
-
currentSlot,
|
|
4261
4241
|
pythMessage,
|
|
4262
4242
|
pythStateOref
|
|
4263
4243
|
);
|
|
4264
4244
|
}
|
|
4265
|
-
async function burnCdp(amount, cdpOref, iassetOref, collateralAssetOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid
|
|
4245
|
+
async function burnCdp(amount, cdpOref, iassetOref, collateralAssetOref, interestOracleOref, treasuryOref, interestCollectorOref, params, lucid) {
|
|
4266
4246
|
return adjustCdp(
|
|
4267
4247
|
0n,
|
|
4268
4248
|
-amount,
|
|
@@ -4274,13 +4254,11 @@ async function burnCdp(amount, cdpOref, iassetOref, collateralAssetOref, interes
|
|
|
4274
4254
|
treasuryOref,
|
|
4275
4255
|
interestCollectorOref,
|
|
4276
4256
|
params,
|
|
4277
|
-
lucid
|
|
4278
|
-
currentSlot
|
|
4257
|
+
lucid
|
|
4279
4258
|
);
|
|
4280
4259
|
}
|
|
4281
|
-
async function closeCdp(cdpOref, collateralAssetOref, interestOracleOref, interestCollectorOref, sysParams, lucid
|
|
4282
|
-
const
|
|
4283
|
-
const currentTime = BigInt(slotToUnixTime5(network, currentSlot));
|
|
4260
|
+
async function closeCdp(cdpOref, collateralAssetOref, interestOracleOref, interestCollectorOref, sysParams, lucid) {
|
|
4261
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
4284
4262
|
const cdpRefScriptUtxo = matchSingle(
|
|
4285
4263
|
await lucid.utxosByOutRef([
|
|
4286
4264
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
@@ -4322,7 +4300,7 @@ async function closeCdp(cdpOref, collateralAssetOref, interestOracleOref, intere
|
|
|
4322
4300
|
const interestOracleDatum = parseInterestOracleDatum(
|
|
4323
4301
|
getInlineDatumOrThrow(interestOracleUtxo)
|
|
4324
4302
|
);
|
|
4325
|
-
const validateFrom =
|
|
4303
|
+
const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
|
|
4326
4304
|
const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
|
|
4327
4305
|
const tx = lucid.newTx().readFrom([
|
|
4328
4306
|
cdpRefScriptUtxo,
|
|
@@ -4380,9 +4358,8 @@ async function closeCdp(cdpOref, collateralAssetOref, interestOracleOref, intere
|
|
|
4380
4358
|
}
|
|
4381
4359
|
return tx;
|
|
4382
4360
|
}
|
|
4383
|
-
async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, interestCollectorOref, treasuryOref, govOref, sysParams, lucid,
|
|
4384
|
-
const
|
|
4385
|
-
const currentTime = BigInt(slotToUnixTime5(network, currentSlot));
|
|
4361
|
+
async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, interestCollectorOref, treasuryOref, govOref, sysParams, lucid, pythMessage = void 0, _pythStateOref = void 0) {
|
|
4362
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
4386
4363
|
const cdpRefScriptUtxo = matchSingle(
|
|
4387
4364
|
await lucid.utxosByOutRef([
|
|
4388
4365
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
@@ -4512,15 +4489,14 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, coll
|
|
|
4512
4489
|
getInlineDatumOrThrow(priceOracleUtxo)
|
|
4513
4490
|
);
|
|
4514
4491
|
const txValidity = oracleExpirationAwareValidity(
|
|
4515
|
-
|
|
4492
|
+
lucid,
|
|
4516
4493
|
Number(sysParams.cdpCreatorParams.biasTime),
|
|
4517
|
-
Number(priceOracleDatum.expirationTime)
|
|
4518
|
-
network
|
|
4494
|
+
Number(priceOracleDatum.expirationTime)
|
|
4519
4495
|
);
|
|
4520
4496
|
referenceInputs.push(priceOracleUtxo);
|
|
4521
4497
|
tx.validFrom(txValidity.validFrom).validTo(txValidity.validTo);
|
|
4522
4498
|
} else {
|
|
4523
|
-
const validateFrom =
|
|
4499
|
+
const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
|
|
4524
4500
|
const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
|
|
4525
4501
|
tx.validFrom(validateFrom).validTo(validateTo);
|
|
4526
4502
|
}
|
|
@@ -4632,9 +4608,9 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, coll
|
|
|
4632
4608
|
);
|
|
4633
4609
|
return tx;
|
|
4634
4610
|
}
|
|
4635
|
-
async function freezeCdp(cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, sysParams, lucid,
|
|
4611
|
+
async function freezeCdp(cdpOref, iassetOref, collateralAssetOref, priceOracleOref, interestOracleOref, sysParams, lucid, pythMessage = void 0, pythStateOref = void 0) {
|
|
4636
4612
|
const network = lucid.config().network;
|
|
4637
|
-
const currentTime = BigInt(
|
|
4613
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
4638
4614
|
const cdpRefScriptUtxo = matchSingle(
|
|
4639
4615
|
await lucid.utxosByOutRef([
|
|
4640
4616
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
@@ -4717,7 +4693,6 @@ async function freezeCdp(cdpOref, iassetOref, collateralAssetOref, priceOracleOr
|
|
|
4717
4693
|
pythMessage,
|
|
4718
4694
|
sysParams.pythConfig,
|
|
4719
4695
|
sysParams.cdpParams.biasTime,
|
|
4720
|
-
currentSlot,
|
|
4721
4696
|
lucid,
|
|
4722
4697
|
tx
|
|
4723
4698
|
);
|
|
@@ -5317,7 +5292,6 @@ import {
|
|
|
5317
5292
|
fromHex as fromHex8,
|
|
5318
5293
|
fromText as fromText4,
|
|
5319
5294
|
paymentCredentialOf as paymentCredentialOf2,
|
|
5320
|
-
slotToUnixTime as slotToUnixTime6,
|
|
5321
5295
|
toHex as toHex8
|
|
5322
5296
|
} from "@lucid-evolution/lucid";
|
|
5323
5297
|
import {
|
|
@@ -5770,9 +5744,9 @@ import {
|
|
|
5770
5744
|
addressFromBech32,
|
|
5771
5745
|
addressToBech32
|
|
5772
5746
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
5773
|
-
async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lucid,
|
|
5747
|
+
async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lucid, govOref, allIAssetOrefs) {
|
|
5774
5748
|
const network = lucid.config().network;
|
|
5775
|
-
const currentTime = BigInt(
|
|
5749
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
5776
5750
|
const ownAddr = await lucid.wallet().address();
|
|
5777
5751
|
const pkh = paymentCredentialOf2(ownAddr);
|
|
5778
5752
|
const govRefScriptUtxo = matchSingle(
|
|
@@ -5891,9 +5865,9 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
5891
5865
|
newPollId
|
|
5892
5866
|
];
|
|
5893
5867
|
}
|
|
5894
|
-
async function createShardsChunks(chunkSize, pollManagerOref, sysParams,
|
|
5868
|
+
async function createShardsChunks(chunkSize, pollManagerOref, sysParams, lucid) {
|
|
5895
5869
|
const network = lucid.config().network;
|
|
5896
|
-
const currentTime = BigInt(
|
|
5870
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
5897
5871
|
const ownAddr = await lucid.wallet().address();
|
|
5898
5872
|
const pollManagerUtxo = matchSingle(
|
|
5899
5873
|
await lucid.utxosByOutRef([pollManagerOref]),
|
|
@@ -5982,9 +5956,9 @@ function voteHelper(stakingPosLockedAmt, pollShard, voteOption, currentTime, ind
|
|
|
5982
5956
|
];
|
|
5983
5957
|
return [newLockedAmt, newPollStatus];
|
|
5984
5958
|
}
|
|
5985
|
-
async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, lucid
|
|
5986
|
-
const
|
|
5987
|
-
const
|
|
5959
|
+
async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, lucid) {
|
|
5960
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
5961
|
+
const ownAddr = await lucid.wallet().address();
|
|
5988
5962
|
const pollShardRefScriptUtxo = matchSingle(
|
|
5989
5963
|
await lucid.utxosByOutRef([
|
|
5990
5964
|
fromSystemParamsScriptRef(
|
|
@@ -6029,7 +6003,10 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
|
|
|
6029
6003
|
indyStakedAmt
|
|
6030
6004
|
);
|
|
6031
6005
|
return lucid.newTx().validFrom(validityFrom).validTo(
|
|
6032
|
-
|
|
6006
|
+
Math.min(
|
|
6007
|
+
validityFrom + Number(sysParams.pollManagerParams.pBiasTime) - ONE_SECOND,
|
|
6008
|
+
Number(pollShardDatum.votingEndTime) - ONE_SECOND
|
|
6009
|
+
)
|
|
6033
6010
|
).readFrom([stakingRefScriptUtxo, pollShardRefScriptUtxo]).collectFrom([stakingPosUtxo], serialiseStakingRedeemer("Lock")).collectFrom(
|
|
6034
6011
|
[pollShardUtxo],
|
|
6035
6012
|
serialisePollShardRedeemer({ Vote: voteOption })
|
|
@@ -6055,11 +6032,10 @@ async function vote(voteOption, pollShardOref, stakingPositionOref, sysParams, l
|
|
|
6055
6032
|
})
|
|
6056
6033
|
},
|
|
6057
6034
|
stakingPosUtxo.assets
|
|
6058
|
-
).
|
|
6035
|
+
).addSigner(ownAddr);
|
|
6059
6036
|
}
|
|
6060
|
-
async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid
|
|
6061
|
-
const
|
|
6062
|
-
const currentTime = BigInt(slotToUnixTime6(network, currentSlot));
|
|
6037
|
+
async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid) {
|
|
6038
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
6063
6039
|
const ownAddr = await lucid.wallet().address();
|
|
6064
6040
|
const pollShardRefScriptUtxo = matchSingle(
|
|
6065
6041
|
await lucid.utxosByOutRef([
|
|
@@ -6146,9 +6122,9 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
6146
6122
|
addAssets8(pollManagerUtxo.assets, shardsAggregatedAda)
|
|
6147
6123
|
).addSigner(ownAddr);
|
|
6148
6124
|
}
|
|
6149
|
-
async function endProposal(pollManagerOref, govOref, sysParams, lucid
|
|
6125
|
+
async function endProposal(pollManagerOref, govOref, sysParams, lucid) {
|
|
6150
6126
|
const network = lucid.config().network;
|
|
6151
|
-
const currentTime = BigInt(
|
|
6127
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
6152
6128
|
const ownAddr = await lucid.wallet().address();
|
|
6153
6129
|
const pollManagerRefScriptUtxo = matchSingle(
|
|
6154
6130
|
await lucid.utxosByOutRef([
|
|
@@ -6260,9 +6236,9 @@ async function endProposal(pollManagerOref, govOref, sysParams, lucid, currentSl
|
|
|
6260
6236
|
}
|
|
6261
6237
|
return tx;
|
|
6262
6238
|
}
|
|
6263
|
-
async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, allIAssetOrefs, iAssetOref, allCollateralAssetsOrefsOfIAsset, collateralAssetOref, stableswapPoolOrCdpCreatorOref, sysParams, lucid
|
|
6239
|
+
async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, allIAssetOrefs, iAssetOref, allCollateralAssetsOrefsOfIAsset, collateralAssetOref, stableswapPoolOrCdpCreatorOref, sysParams, lucid) {
|
|
6264
6240
|
const network = lucid.config().network;
|
|
6265
|
-
const currentTime = BigInt(
|
|
6241
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
6266
6242
|
const ownAddr = await lucid.wallet().address();
|
|
6267
6243
|
const govUtxo = matchSingle(
|
|
6268
6244
|
await lucid.utxosByOutRef([govOref]),
|
|
@@ -6991,1567 +6967,1646 @@ var mkGovValidatorFromSP = (params) => {
|
|
|
6991
6967
|
};
|
|
6992
6968
|
};
|
|
6993
6969
|
|
|
6994
|
-
// src/contracts/
|
|
6970
|
+
// src/contracts/staking/transactions.ts
|
|
6995
6971
|
import {
|
|
6996
|
-
|
|
6972
|
+
addAssets as addAssets9,
|
|
6997
6973
|
Data as Data32,
|
|
6998
6974
|
fromHex as fromHex9,
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
slotToUnixTime as slotToUnixTime7,
|
|
7002
|
-
credentialToAddress as credentialToAddress3
|
|
6975
|
+
fromText as fromText5,
|
|
6976
|
+
toHex as toHex9
|
|
7003
6977
|
} from "@lucid-evolution/lucid";
|
|
7004
6978
|
import {
|
|
7005
|
-
adaAssetClass as adaAssetClass4,
|
|
7006
|
-
addressFromBech32 as addressFromBech322,
|
|
7007
|
-
addressToBech32 as addressToBech322,
|
|
7008
6979
|
assetClassValueOf as assetClassValueOf5,
|
|
7009
|
-
|
|
7010
|
-
lovelacesAmt as lovelacesAmt2,
|
|
7011
|
-
matchSingle as matchSingle3,
|
|
6980
|
+
getInlineDatumOrThrow as getInlineDatumOrThrow5,
|
|
7012
6981
|
mkAssetsOf as mkAssetsOf7,
|
|
7013
|
-
mkLovelacesOf as mkLovelacesOf4
|
|
7014
|
-
negateAssets as negateAssets4
|
|
6982
|
+
mkLovelacesOf as mkLovelacesOf4
|
|
7015
6983
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
const
|
|
7019
|
-
const
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
)
|
|
7024
|
-
|
|
6984
|
+
async function openStakingPosition(amount, params, lucid, stakingManagerRef) {
|
|
6985
|
+
const [pkh, _] = await addrDetails(lucid);
|
|
6986
|
+
const stakingManagerOut = stakingManagerRef ? await findStakingManagerByOutRef(stakingManagerRef, lucid) : await findStakingManager(params, lucid);
|
|
6987
|
+
const stakingRefScriptUtxo = matchSingle(
|
|
6988
|
+
await lucid.utxosByOutRef([
|
|
6989
|
+
fromSystemParamsScriptRef(params.scriptReferences.stakingValidatorRef)
|
|
6990
|
+
]),
|
|
6991
|
+
(_2) => new Error("Expected a single staking Ref Script UTXO")
|
|
6992
|
+
);
|
|
6993
|
+
const stakingTokenPolicyRefScriptUtxo = matchSingle(
|
|
6994
|
+
await lucid.utxosByOutRef([
|
|
6995
|
+
fromSystemParamsScriptRef(
|
|
6996
|
+
params.scriptReferences.authTokenPolicies.stakingTokenRef
|
|
6997
|
+
)
|
|
6998
|
+
]),
|
|
6999
|
+
(_2) => new Error("Expected a single staking token policy Ref Script UTXO")
|
|
7000
|
+
);
|
|
7001
|
+
const newStakingManagerDatum = {
|
|
7002
|
+
totalStake: stakingManagerOut.datum.totalStake + amount,
|
|
7003
|
+
managerSnapshot: {
|
|
7004
|
+
snapshotAda: stakingManagerOut.datum.managerSnapshot.snapshotAda
|
|
7005
|
+
}
|
|
7025
7006
|
};
|
|
7026
|
-
const
|
|
7007
|
+
const stakingPositionDatum = {
|
|
7027
7008
|
owner: fromHex9(pkh.hash),
|
|
7028
|
-
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
lastRequestProcessingTime: 0n
|
|
7009
|
+
lockedAmount: [],
|
|
7010
|
+
positionSnapshot: {
|
|
7011
|
+
snapshotAda: stakingManagerOut.datum.managerSnapshot.snapshotAda
|
|
7012
|
+
}
|
|
7033
7013
|
};
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
|
|
7037
|
-
|
|
7038
|
-
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
|
|
7042
|
-
|
|
7043
|
-
) : void 0
|
|
7044
|
-
),
|
|
7014
|
+
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + fromText5(params.stakingParams.stakingToken[1].unTokenName);
|
|
7015
|
+
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText5(params.stakingParams.indyToken[1].unTokenName);
|
|
7016
|
+
return lucid.newTx().collectFrom(
|
|
7017
|
+
[stakingManagerOut.utxo],
|
|
7018
|
+
serialiseStakingRedeemer({
|
|
7019
|
+
CreateStakingPosition: { creatorPkh: fromHex9(pkh.hash) }
|
|
7020
|
+
})
|
|
7021
|
+
).readFrom([stakingRefScriptUtxo]).pay.ToContract(
|
|
7022
|
+
stakingManagerOut.utxo.address,
|
|
7045
7023
|
{
|
|
7046
7024
|
kind: "inline",
|
|
7047
|
-
value:
|
|
7025
|
+
value: serialiseStakingDatum(newStakingManagerDatum)
|
|
7048
7026
|
},
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7027
|
+
stakingManagerOut.utxo.assets
|
|
7028
|
+
).readFrom([stakingTokenPolicyRefScriptUtxo]).mintAssets(
|
|
7029
|
+
{
|
|
7030
|
+
[stakingToken]: 1n
|
|
7031
|
+
},
|
|
7032
|
+
Data32.void()
|
|
7033
|
+
).pay.ToContract(
|
|
7034
|
+
stakingManagerOut.utxo.address,
|
|
7035
|
+
{
|
|
7036
|
+
kind: "inline",
|
|
7037
|
+
value: serialiseStakingDatum(stakingPositionDatum)
|
|
7038
|
+
},
|
|
7039
|
+
{
|
|
7040
|
+
[stakingToken]: 1n,
|
|
7041
|
+
[indyToken]: amount
|
|
7042
|
+
}
|
|
7058
7043
|
).addSignerKey(pkh.hash);
|
|
7059
7044
|
}
|
|
7060
|
-
async function
|
|
7061
|
-
const
|
|
7062
|
-
const
|
|
7045
|
+
async function adjustStakingPosition(stakingPositionRef, amount, params, lucid, stakingManagerRef) {
|
|
7046
|
+
const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
7047
|
+
const stakingPositionOut = await findStakingPositionByOutRef(
|
|
7048
|
+
stakingPositionRef,
|
|
7049
|
+
lucid
|
|
7050
|
+
);
|
|
7051
|
+
const stakingManagerOut = stakingManagerRef ? await findStakingManagerByOutRef(stakingManagerRef, lucid) : await findStakingManager(params, lucid);
|
|
7052
|
+
const stakingRefScriptUtxo = matchSingle(
|
|
7063
7053
|
await lucid.utxosByOutRef([
|
|
7064
|
-
fromSystemParamsScriptRef(
|
|
7065
|
-
sysParams.scriptReferences.stabilityPoolValidatorRef
|
|
7066
|
-
)
|
|
7054
|
+
fromSystemParamsScriptRef(params.scriptReferences.stakingValidatorRef)
|
|
7067
7055
|
]),
|
|
7068
|
-
(_) => new Error("Expected a single
|
|
7056
|
+
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
7069
7057
|
);
|
|
7070
|
-
const
|
|
7071
|
-
|
|
7058
|
+
const indyToken = fromSystemParamsAsset(params.stakingParams.indyToken);
|
|
7059
|
+
const adaReward = calculateAdaReward(
|
|
7060
|
+
stakingManagerOut.datum.managerSnapshot.snapshotAda,
|
|
7061
|
+
stakingPositionOut.datum.positionSnapshot.snapshotAda,
|
|
7062
|
+
assetClassValueOf5(stakingPositionOut.utxo.assets, indyToken)
|
|
7072
7063
|
);
|
|
7073
|
-
const
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
};
|
|
7082
|
-
return lucid.newTx().readFrom([stabilityPoolScriptRef]).collectFrom(
|
|
7083
|
-
[accountUtxo],
|
|
7084
|
-
serialiseStabilityPoolRedeemer({
|
|
7085
|
-
RequestAction: {
|
|
7086
|
-
Adjust: {
|
|
7087
|
-
amount,
|
|
7088
|
-
outputAddress: addressFromBech322(myAddress)
|
|
7089
|
-
}
|
|
7090
|
-
}
|
|
7064
|
+
const newLockedAmount = updateStakingLockedAmount(
|
|
7065
|
+
stakingPositionOut.datum.lockedAmount,
|
|
7066
|
+
BigInt(now)
|
|
7067
|
+
);
|
|
7068
|
+
return lucid.newTx().validFrom(Number(now)).readFrom([stakingRefScriptUtxo]).collectFrom(
|
|
7069
|
+
[stakingPositionOut.utxo],
|
|
7070
|
+
serialiseStakingRedeemer({
|
|
7071
|
+
AdjustStakedAmount: { adjustAmount: amount }
|
|
7091
7072
|
})
|
|
7073
|
+
).collectFrom(
|
|
7074
|
+
[stakingManagerOut.utxo],
|
|
7075
|
+
serialiseStakingRedeemer("UpdateTotalStake")
|
|
7092
7076
|
).pay.ToContract(
|
|
7093
|
-
|
|
7077
|
+
stakingManagerOut.utxo.address,
|
|
7094
7078
|
{
|
|
7095
7079
|
kind: "inline",
|
|
7096
|
-
value:
|
|
7097
|
-
|
|
7080
|
+
value: serialiseStakingDatum({
|
|
7081
|
+
...stakingManagerOut.datum,
|
|
7082
|
+
totalStake: stakingManagerOut.datum.totalStake + amount
|
|
7098
7083
|
})
|
|
7099
7084
|
},
|
|
7100
|
-
addAssets9(
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
1n
|
|
7110
|
-
),
|
|
7111
|
-
amount > 0n ? mkAssetsOf7(
|
|
7112
|
-
{
|
|
7113
|
-
currencySymbol: fromHex9(
|
|
7114
|
-
sysParams.stabilityPoolParams.assetSymbol.unCurrencySymbol
|
|
7115
|
-
),
|
|
7116
|
-
tokenName: oldAccountDatum.iasset
|
|
7085
|
+
addAssets9(stakingManagerOut.utxo.assets, mkLovelacesOf4(-adaReward))
|
|
7086
|
+
).pay.ToContract(
|
|
7087
|
+
stakingPositionOut.utxo.address,
|
|
7088
|
+
{
|
|
7089
|
+
kind: "inline",
|
|
7090
|
+
value: serialiseStakingDatum({
|
|
7091
|
+
...stakingPositionOut.datum,
|
|
7092
|
+
positionSnapshot: {
|
|
7093
|
+
snapshotAda: stakingManagerOut.datum.managerSnapshot.snapshotAda
|
|
7117
7094
|
},
|
|
7118
|
-
|
|
7119
|
-
)
|
|
7120
|
-
|
|
7121
|
-
|
|
7095
|
+
lockedAmount: newLockedAmount
|
|
7096
|
+
})
|
|
7097
|
+
},
|
|
7098
|
+
addAssets9(stakingPositionOut.utxo.assets, mkAssetsOf7(indyToken, amount))
|
|
7099
|
+
).addSignerKey(toHex9(stakingPositionOut.datum.owner));
|
|
7122
7100
|
}
|
|
7123
|
-
async function
|
|
7124
|
-
const
|
|
7125
|
-
const
|
|
7101
|
+
async function closeStakingPosition(stakingPositionRef, params, lucid, stakingManagerRef) {
|
|
7102
|
+
const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
7103
|
+
const stakingPositionOut = await findStakingPositionByOutRef(
|
|
7104
|
+
stakingPositionRef,
|
|
7105
|
+
lucid
|
|
7106
|
+
);
|
|
7107
|
+
const stakingManagerOut = stakingManagerRef ? await findStakingManagerByOutRef(stakingManagerRef, lucid) : await findStakingManager(params, lucid);
|
|
7108
|
+
const stakingRefScriptUtxo = matchSingle(
|
|
7109
|
+
await lucid.utxosByOutRef([
|
|
7110
|
+
fromSystemParamsScriptRef(params.scriptReferences.stakingValidatorRef)
|
|
7111
|
+
]),
|
|
7112
|
+
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
7113
|
+
);
|
|
7114
|
+
const stakingTokenPolicyRefScriptUtxo = matchSingle(
|
|
7126
7115
|
await lucid.utxosByOutRef([
|
|
7127
7116
|
fromSystemParamsScriptRef(
|
|
7128
|
-
|
|
7117
|
+
params.scriptReferences.authTokenPolicies.stakingTokenRef
|
|
7129
7118
|
)
|
|
7130
7119
|
]),
|
|
7131
|
-
(_) => new Error("Expected a single
|
|
7120
|
+
(_) => new Error("Expected a single staking token policy Ref Script UTXO")
|
|
7132
7121
|
);
|
|
7133
|
-
const
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
}
|
|
7138
|
-
};
|
|
7139
|
-
const oldAccountDatum = parseAccountDatumOrThrow(
|
|
7140
|
-
getInlineDatumOrThrow(accountUtxo)
|
|
7122
|
+
const indyToken = fromSystemParamsAsset(params.stakingParams.indyToken);
|
|
7123
|
+
const existingIndyAmount = assetClassValueOf5(
|
|
7124
|
+
stakingPositionOut.utxo.assets,
|
|
7125
|
+
indyToken
|
|
7141
7126
|
);
|
|
7142
|
-
const
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
|
|
7127
|
+
const adaReward = calculateAdaReward(
|
|
7128
|
+
stakingManagerOut.datum.managerSnapshot.snapshotAda,
|
|
7129
|
+
stakingPositionOut.datum.positionSnapshot.snapshotAda,
|
|
7130
|
+
assetClassValueOf5(stakingPositionOut.utxo.assets, indyToken)
|
|
7131
|
+
);
|
|
7132
|
+
return lucid.newTx().validFrom(Number(now)).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom(
|
|
7133
|
+
[stakingManagerOut.utxo],
|
|
7134
|
+
serialiseStakingRedeemer("UpdateTotalStake")
|
|
7149
7135
|
).pay.ToContract(
|
|
7150
|
-
|
|
7136
|
+
stakingManagerOut.utxo.address,
|
|
7151
7137
|
{
|
|
7152
7138
|
kind: "inline",
|
|
7153
|
-
value:
|
|
7139
|
+
value: serialiseStakingDatum({
|
|
7140
|
+
...stakingManagerOut.datum,
|
|
7141
|
+
totalStake: stakingManagerOut.datum.totalStake - existingIndyAmount
|
|
7142
|
+
})
|
|
7154
7143
|
},
|
|
7155
|
-
addAssets9(
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7159
|
-
|
|
7160
|
-
),
|
|
7161
|
-
mkAssetsOf7(
|
|
7162
|
-
fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
|
|
7163
|
-
1n
|
|
7164
|
-
)
|
|
7165
|
-
)
|
|
7166
|
-
).addSignerKey(toHex9(oldAccountDatum.owner));
|
|
7144
|
+
addAssets9(stakingManagerOut.utxo.assets, mkLovelacesOf4(-adaReward))
|
|
7145
|
+
).mintAssets(
|
|
7146
|
+
mkAssetsOf7(fromSystemParamsAsset(params.stakingParams.stakingToken), -1n),
|
|
7147
|
+
Data32.void()
|
|
7148
|
+
).addSignerKey(toHex9(stakingPositionOut.datum.owner));
|
|
7167
7149
|
}
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
const
|
|
7171
|
-
const
|
|
7150
|
+
var MIN_UTXO_AMOUNT = 2000000n;
|
|
7151
|
+
async function distributeAda(stakingManagerRef, collectorRefs, params, lucid) {
|
|
7152
|
+
const [stakingManagerUtxo] = await lucid.utxosByOutRef([stakingManagerRef]);
|
|
7153
|
+
const stakingManagerDatum = parseStakingManagerDatum(
|
|
7154
|
+
getInlineDatumOrThrow5(stakingManagerUtxo)
|
|
7155
|
+
);
|
|
7156
|
+
const collectorUtxos = (await lucid.utxosByOutRef(collectorRefs)).filter((utxo) => utxo.datum && utxo.datum === Data32.void()).filter((utxo) => utxo.assets["lovelace"] > MIN_UTXO_AMOUNT);
|
|
7157
|
+
if (collectorUtxos.length === 0) {
|
|
7158
|
+
throw new Error("No available collectors found");
|
|
7159
|
+
}
|
|
7160
|
+
const adaRewardCollected = collectorUtxos.reduce(
|
|
7161
|
+
(acc, utxo) => acc + utxo.assets["lovelace"] - MIN_UTXO_AMOUNT,
|
|
7162
|
+
0n
|
|
7163
|
+
);
|
|
7164
|
+
const newSnapshot = distributeReward(
|
|
7165
|
+
stakingManagerDatum.managerSnapshot.snapshotAda,
|
|
7166
|
+
adaRewardCollected,
|
|
7167
|
+
stakingManagerDatum.totalStake
|
|
7168
|
+
);
|
|
7169
|
+
const stakingRefScriptUtxo = matchSingle(
|
|
7172
7170
|
await lucid.utxosByOutRef([
|
|
7173
|
-
fromSystemParamsScriptRef(
|
|
7174
|
-
sysParams.scriptReferences.stabilityPoolValidatorRef
|
|
7175
|
-
)
|
|
7171
|
+
fromSystemParamsScriptRef(params.scriptReferences.stakingValidatorRef)
|
|
7176
7172
|
]),
|
|
7177
|
-
(_) => new Error("Expected a single
|
|
7173
|
+
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
7178
7174
|
);
|
|
7179
|
-
const
|
|
7180
|
-
|
|
7175
|
+
const collectorRefScriptUtxo = matchSingle(
|
|
7176
|
+
await lucid.utxosByOutRef([
|
|
7177
|
+
fromSystemParamsScriptRef(params.scriptReferences.collectorValidatorRef)
|
|
7178
|
+
]),
|
|
7179
|
+
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
7181
7180
|
);
|
|
7182
|
-
const
|
|
7183
|
-
|
|
7181
|
+
const tx = lucid.newTx().readFrom([stakingRefScriptUtxo, collectorRefScriptUtxo]).collectFrom([stakingManagerUtxo], serialiseStakingRedeemer("Distribute")).collectFrom(
|
|
7182
|
+
collectorUtxos,
|
|
7183
|
+
serialiseCollectorRedeemer("DistributeToStakers")
|
|
7184
|
+
).pay.ToContract(
|
|
7185
|
+
stakingManagerUtxo.address,
|
|
7186
|
+
{
|
|
7187
|
+
kind: "inline",
|
|
7188
|
+
value: serialiseStakingDatum({
|
|
7189
|
+
...stakingManagerDatum,
|
|
7190
|
+
managerSnapshot: { snapshotAda: newSnapshot }
|
|
7191
|
+
})
|
|
7192
|
+
},
|
|
7193
|
+
addAssets9(stakingManagerUtxo.assets, mkLovelacesOf4(adaRewardCollected))
|
|
7184
7194
|
);
|
|
7185
|
-
const
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
+
for (const collectorUtxo of collectorUtxos) {
|
|
7196
|
+
tx.pay.ToContract(
|
|
7197
|
+
collectorUtxo.address,
|
|
7198
|
+
{ kind: "inline", value: Data32.void() },
|
|
7199
|
+
mkLovelacesOf4(MIN_UTXO_AMOUNT)
|
|
7200
|
+
);
|
|
7201
|
+
}
|
|
7202
|
+
return tx;
|
|
7203
|
+
}
|
|
7204
|
+
|
|
7205
|
+
// src/contracts/staking/types.ts
|
|
7206
|
+
import { Data as Data33 } from "@lucid-evolution/lucid";
|
|
7207
|
+
var StakingParamsSchema = Data33.Object({
|
|
7208
|
+
stakingManagerNft: AssetClassSchema2,
|
|
7209
|
+
stakingToken: AssetClassSchema2,
|
|
7210
|
+
indyToken: AssetClassSchema2,
|
|
7211
|
+
pollToken: AssetClassSchema2,
|
|
7212
|
+
versionRecordToken: AssetClassSchema2,
|
|
7213
|
+
collectorValHash: Data33.Bytes()
|
|
7214
|
+
});
|
|
7215
|
+
var StakingParams = StakingParamsSchema;
|
|
7216
|
+
function castStakingParams(params) {
|
|
7217
|
+
return Data33.castTo(params, StakingParams);
|
|
7218
|
+
}
|
|
7219
|
+
|
|
7220
|
+
// src/contracts/interest-oracle/transactions.ts
|
|
7221
|
+
import {
|
|
7222
|
+
fromHex as fromHex10,
|
|
7223
|
+
fromText as fromText6,
|
|
7224
|
+
toUnit as toUnit2,
|
|
7225
|
+
validatorToAddress
|
|
7226
|
+
} from "@lucid-evolution/lucid";
|
|
7227
|
+
|
|
7228
|
+
// src/contracts/one-shot/transactions.ts
|
|
7229
|
+
import {
|
|
7230
|
+
addAssets as addAssets10,
|
|
7231
|
+
Data as Data35,
|
|
7232
|
+
mintingPolicyToId,
|
|
7233
|
+
toUnit
|
|
7234
|
+
} from "@lucid-evolution/lucid";
|
|
7235
|
+
|
|
7236
|
+
// src/contracts/one-shot/scripts.ts
|
|
7237
|
+
import { applyParamsToScript as applyParamsToScript7 } from "@lucid-evolution/lucid";
|
|
7238
|
+
|
|
7239
|
+
// src/contracts/one-shot/types.ts
|
|
7240
|
+
import { Data as Data34 } from "@lucid-evolution/lucid";
|
|
7241
|
+
var OneShotParamsSchema = Data34.Object({
|
|
7242
|
+
referenceOutRef: Data34.Object({
|
|
7243
|
+
txHash: Data34.Bytes(),
|
|
7244
|
+
outputIdx: Data34.Integer()
|
|
7245
|
+
}),
|
|
7246
|
+
mintAmounts: Data34.Array(
|
|
7247
|
+
Data34.Object({
|
|
7248
|
+
/// Use hex encoded string
|
|
7249
|
+
tokenName: Data34.Bytes(),
|
|
7250
|
+
amount: Data34.Integer()
|
|
7195
7251
|
})
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7252
|
+
)
|
|
7253
|
+
});
|
|
7254
|
+
var OneShotParams = OneShotParamsSchema;
|
|
7255
|
+
function castOneShotParams(params) {
|
|
7256
|
+
return Data34.castTo(params, OneShotParams);
|
|
7257
|
+
}
|
|
7258
|
+
|
|
7259
|
+
// src/validators/one-shot-policy.ts
|
|
7260
|
+
var _oneShotPolicy = {
|
|
7261
|
+
type: "PlutusScriptV3",
|
|
7262
|
+
description: "Generated by Aiken",
|
|
7263
|
+
cborHex: "590379590376010100229800aba4aba2aba1aba0aab9faab9eaab9dab9a4888888896600264653001300800198041804800cdc3a400130080024888966002600460106ea800e26644b30013004300a37546466446600400400244b30010018a60103d87a80008992cc004cdd7980918079baa001004899ba548000cc0440052f5c11330030033013002403460220028078dd6180798061baa004300e300b375402515980099912cc004006294226530013259800980418071baa00189bad300f301237566024601e6ea800629000201a30110019baf301130120019bab0024889660020031598009801002c4c02800e294100f44c96600266ebd300101400030110018acc004cdc38021bad301230153756602400313003374c602c00514a080822b3001300b0048980180345282020404060280028090653001001801c88cc048008cc048dd3000a5eb810011112cc00400a26600298103d87a80004bd6f7b63044c8cc896600266e452201000028acc004cdc7a4410000289980219ba548000cc054c04c00d2f5c00031330044c103d87a80000054045198008034006446600c0046602e00a00280310111bae301000130150033013002404514a114a114a08090dd59807180798079807980798059baa003374c646530010019bac3002300d37540294bd6f7b630200222259800801440063300100398098014c8cc8966002601600310048991919800800803112cc00400626602e66ec0dd48061ba60034bd6f7b63044c8cc896600266e4403c00a2b30013371e01e0051325980099baf4c101a000374c003100289980d99bb037520206e9800400901719198008009bab30190042259800800c4cc070cdd81ba900a375001297adef6c6089919912cc004cdc8806801456600266e3c03400a264b30013370e00266e05200000d880144cc080cdd81ba900e375066e0000403400901c1bad301d00389980f99bb0375201a6ea003001101b44cc07c00ccc01401400501b1bae301a001301f002301d001406d13301a337606ea403cdd3003002202c89980d00199802802800a02c375c602a0026034004603000280b0cc050cdd81ba9002375000297adef6c6040406eb8c04cc040dd50009bad30053010375400260240048019010118079808000c528c590094590091bae300c30093754006b300130023008375400915980098049baa0048a4d16402916401d16401c300800130033754013149a26cac8009"
|
|
7264
|
+
};
|
|
7265
|
+
|
|
7266
|
+
// src/contracts/one-shot/scripts.ts
|
|
7267
|
+
function mkOneShotPolicy(params) {
|
|
7268
|
+
return {
|
|
7269
|
+
type: "PlutusV3",
|
|
7270
|
+
script: applyParamsToScript7(_oneShotPolicy.cborHex, [
|
|
7271
|
+
castOneShotParams(params)
|
|
7272
|
+
])
|
|
7203
7273
|
};
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
const requestDepositAmt = assetClassValueOf5(
|
|
7214
|
-
accountUtxo.assets,
|
|
7215
|
-
iassetAssetClass
|
|
7216
|
-
);
|
|
7217
|
-
const poolAddr = credentialToAddress3(
|
|
7218
|
-
lucid.config().network,
|
|
7274
|
+
}
|
|
7275
|
+
|
|
7276
|
+
// src/contracts/one-shot/transactions.ts
|
|
7277
|
+
import { reduce } from "fp-ts/lib/Array";
|
|
7278
|
+
async function oneShotMintTx(lucid, params) {
|
|
7279
|
+
const oneShotPolicy = mkOneShotPolicy(params);
|
|
7280
|
+
const policyId = mintingPolicyToId(oneShotPolicy);
|
|
7281
|
+
const refUtxo = matchSingle(
|
|
7282
|
+
await lucid.utxosByOutRef([
|
|
7219
7283
|
{
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
},
|
|
7223
|
-
sysParams.stabilityPoolParams.stakeCredential != null ? fromSysParamsCredential(
|
|
7224
|
-
sysParams.stabilityPoolParams.stakeCredential
|
|
7225
|
-
) : void 0
|
|
7226
|
-
);
|
|
7227
|
-
const accountOutputAdaAmt = lovelacesAmt2(accountUtxo.assets) - BigInt(sysParams.stabilityPoolParams.accountCreateFeeLovelaces) - txFee;
|
|
7228
|
-
const accountTokenVal = mkAssetsOf7(
|
|
7229
|
-
fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
|
|
7230
|
-
1n
|
|
7231
|
-
);
|
|
7232
|
-
const accountOutputDatum = serialiseStabilityPoolDatum({
|
|
7233
|
-
Account: {
|
|
7234
|
-
owner: accountDatum.owner,
|
|
7235
|
-
iasset: stabilityPoolDatum.iasset,
|
|
7236
|
-
state: {
|
|
7237
|
-
...stabilityPoolDatum.state,
|
|
7238
|
-
depositVal: mkSPInteger(requestDepositAmt)
|
|
7239
|
-
},
|
|
7240
|
-
assetSums: stabilityPoolDatum.assetStates.map(([key, val]) => [
|
|
7241
|
-
key,
|
|
7242
|
-
val.currentSumVal
|
|
7243
|
-
]),
|
|
7244
|
-
request: null,
|
|
7245
|
-
lastRequestProcessingTime: currentTime
|
|
7284
|
+
txHash: params.referenceOutRef.txHash,
|
|
7285
|
+
outputIndex: Number(params.referenceOutRef.outputIdx)
|
|
7246
7286
|
}
|
|
7247
|
-
|
|
7248
|
-
|
|
7249
|
-
|
|
7250
|
-
poolAddr,
|
|
7251
|
-
accountTokenVal,
|
|
7252
|
-
{ InlineDatum: { datum: accountOutputDatum } }
|
|
7253
|
-
);
|
|
7254
|
-
if (accountOutputAdaAmt < accountOutMinUtxoLovelace) {
|
|
7255
|
-
throw new Error("Request doesn't have enough ADA to be processed.");
|
|
7287
|
+
]),
|
|
7288
|
+
(_) => {
|
|
7289
|
+
throw new Error("Cannot find the reference UTXO for one-shot.");
|
|
7256
7290
|
}
|
|
7257
|
-
|
|
7258
|
-
|
|
7259
|
-
|
|
7260
|
-
|
|
7261
|
-
|
|
7262
|
-
|
|
7263
|
-
|
|
7264
|
-
e2s2sIdxs: [],
|
|
7265
|
-
currentTime
|
|
7266
|
-
}
|
|
7267
|
-
})
|
|
7268
|
-
}).mintAssets(accountTokenVal, Data32.void()).pay.ToContract(
|
|
7269
|
-
poolAddr,
|
|
7270
|
-
{
|
|
7271
|
-
kind: "inline",
|
|
7272
|
-
value: serialiseStabilityPoolDatum({
|
|
7273
|
-
StabilityPool: liquidationHelper(
|
|
7274
|
-
{
|
|
7275
|
-
...stabilityPoolDatum,
|
|
7276
|
-
state: {
|
|
7277
|
-
...stabilityPoolDatum.state,
|
|
7278
|
-
depositVal: spAdd(
|
|
7279
|
-
stabilityPoolDatum.state.depositVal,
|
|
7280
|
-
mkSPInteger(requestDepositAmt)
|
|
7281
|
-
)
|
|
7282
|
-
}
|
|
7283
|
-
},
|
|
7284
|
-
adaAssetClass4,
|
|
7285
|
-
0n,
|
|
7286
|
-
BigInt(sysParams.stabilityPoolParams.accountCreateFeeLovelaces)
|
|
7287
|
-
)
|
|
7291
|
+
);
|
|
7292
|
+
return [
|
|
7293
|
+
lucid.newTx().collectFrom([refUtxo]).mintAssets(
|
|
7294
|
+
reduce(
|
|
7295
|
+
{},
|
|
7296
|
+
(acc, entry) => addAssets10(acc, {
|
|
7297
|
+
[toUnit(policyId, entry.tokenName)]: entry.amount
|
|
7288
7298
|
})
|
|
7289
|
-
|
|
7290
|
-
|
|
7291
|
-
|
|
7292
|
-
|
|
7293
|
-
|
|
7294
|
-
|
|
7295
|
-
|
|
7296
|
-
|
|
7297
|
-
|
|
7298
|
-
|
|
7299
|
-
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7304
|
-
|
|
7305
|
-
|
|
7306
|
-
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
7347
|
-
|
|
7348
|
-
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
|
|
7352
|
-
|
|
7353
|
-
|
|
7354
|
-
|
|
7355
|
-
makeRedeemer: (indices) => {
|
|
7356
|
-
return serialiseStabilityPoolRedeemer({
|
|
7357
|
-
ProcessRequestAccount: mkProcessRequestAccountRedeemerContent(
|
|
7358
|
-
indices[0],
|
|
7359
|
-
indices[1]
|
|
7360
|
-
)
|
|
7361
|
-
});
|
|
7362
|
-
}
|
|
7363
|
-
}).pay.ToContract(
|
|
7364
|
-
stabilityPoolUtxo.address,
|
|
7299
|
+
)(params.mintAmounts),
|
|
7300
|
+
Data35.void()
|
|
7301
|
+
).attach.MintingPolicy(oneShotPolicy),
|
|
7302
|
+
policyId
|
|
7303
|
+
];
|
|
7304
|
+
}
|
|
7305
|
+
async function runOneShotMintTx(lucid, params) {
|
|
7306
|
+
const [tx, policyId] = await oneShotMintTx(lucid, params);
|
|
7307
|
+
const txHash = await tx.complete().then((tx2) => tx2.sign.withWallet().complete()).then((tx2) => tx2.submit());
|
|
7308
|
+
await lucid.awaitTx(txHash);
|
|
7309
|
+
return policyId;
|
|
7310
|
+
}
|
|
7311
|
+
|
|
7312
|
+
// src/contracts/interest-oracle/scripts.ts
|
|
7313
|
+
import { applyParamsToScript as applyParamsToScript8 } from "@lucid-evolution/lucid";
|
|
7314
|
+
|
|
7315
|
+
// src/contracts/interest-oracle/types.ts
|
|
7316
|
+
import { Data as Data36 } from "@lucid-evolution/lucid";
|
|
7317
|
+
var InterestOracleParamsSchema = Data36.Object({
|
|
7318
|
+
/** Milliseconds */
|
|
7319
|
+
biasTime: Data36.Integer(),
|
|
7320
|
+
owner: Data36.Bytes()
|
|
7321
|
+
});
|
|
7322
|
+
var InterestOracleParams = InterestOracleParamsSchema;
|
|
7323
|
+
function castInterestOracleParams(params) {
|
|
7324
|
+
return Data36.castTo(params, InterestOracleParams);
|
|
7325
|
+
}
|
|
7326
|
+
|
|
7327
|
+
// src/validators/interest-oracle-validator.ts
|
|
7328
|
+
var _interestOracleValidator = {
|
|
7329
|
+
type: "PlutusScriptV3",
|
|
7330
|
+
description: "Generated by Aiken",
|
|
7331
|
+
cborHex: "5907e05907dd010100229800aba2aba1aba0aab9faab9eaab9dab9cab9a4888888896600264653001300900198049805000cdc3a400530090024888966002600460126ea800e2653001300e00198071807800cdc3a40009112cc004c004c034dd500444c8c8c966002602a00513259800980298089baa001899192cc004c06000a2b300130073013375401119800980b980a1baa008980a1baa00b9180c180c800c896600200310018a9980a0010800a02648888c966002660049201205458206973206e6f74207369676e6564206279206f7261636c65206f776e6572003232330010013758603c603e603e603e603e603e603e603e603e60366ea8048896600200314a115980099b8f375c603e00200714a31330020023020001406480e8dd71801980c9baa01f899912cc004cc011240115496e636f72726563742074782076616c6964697479003322980091192cc004c04c0062b30013013301f375400514c103d87a80008a6103d879800040751598009802000c5660026008603e6ea800a2980103d87a80008a6103d87b800040751332259800980d000c4c96600266e2000c0062980103d87980008acc004cdc4000801c530103d87b80008a6103d87a800040808100dd6981298111baa0048acc004c054006298103d87b80008a6103d8798000407c80f8dd6981198101baa003301f375400480e901d180f1baa002980118101810981098109810981098109810980e9baa014980118019980f98019980f98021980f9ba8337026eb4c01cc074dd500b9bad3020301d375404697ae03301f9800a51a60103d87a8000a60103d8798000406897ae03301f30033301f30043301f375066e00dd69803980e9baa017375a6040603a6ea808d2f5c06603f30014a34c103d87a8000a60103d8798000406897ae04bd702444b300132598009802800c528c566002603200314a314a080f101e180f9baa33003302330203754004604660406ea8006264b300130140018a518acc004c0640062946294101e203c301f375466006601460406ea8008c028c080dd5000c528203a118011980f192cc004c054c070dd5000c4c966002602c603a6ea8c020c078dd51810980f1baa00389802998101ba80014bd7044c014cc080dd419b80001480092f5c080d8dd69810180e9baa0018800a034301f301c3754603e60386ea8004cc078c966002602a60386ea8006264b30013016301d37546010603c6ea8c020c078dd5001c4c014cc080dd4000a5eb822600a660406ea0cdc0000a400297ae0406c6eb4c080c074dd5000c400501a180f980e1baa3006301c375400297ae0370e900244c9660026600a92012643757272656e742074696d652068617320746f206265203e3d206c6173745f736574746c656400337126eb4c004c070dd50041bad3006301c375402d15980099802a492b496e74657265737420726174652068617320746f20626520696e2072616e6765205b30252c20313030255d005980099b8948000dd6980f980e1baa301f301c375402d1337126eb4c07cc070dd5180f980e1baa0164820225ea294101944cc015240120496e746572657374206f7261636c65206f757470757420696e636f72726563740098009bac301f3020302000798019980f18011980f180f980e1baa301f301c37540086603c98103d87a80004bd7025eb8266e9520043301e30023301e375066e00dd6980f980e1baa008325980099b88375a6004603a6ea8024006266e0ccdc199b823370466e04004dd69801180e9baa009375a6040603a6ea8c01cc074dd5004a41010141ede959b7c03690405844fdf500a410112f5153301b4901015a001640686eb4c018c070dd500b1980f180f980e1baa0163301e3006301c375402c97ae04bd704dd59803180e1baa00448888c8c8cc004004018896600200314a1159800992cc004c0100062b30013375e601260486ea800401a2b300133229800992cc004c068c098dd5000c4dd6981398151bab302a302737540031480010241814800cdd58014dd798149815000c89660026040604e6ea930103d87a8000899b890010028acc004cdc480080144cdc480119b80001482026fb80a2941025204a4888966002007159800980100344cc00401120008a50409d1325980099baf4c1014000302a0018acc004cc008014dd6981598171bab302b001898019ba6302f0048a5040a115980099801002a4001130030078a5040a08140c0b400d02b0dd3002994c0040066eacc03cc094dd5001488cc0a4008cc0a4dd3000a5eb810011112cc00400a26600298103d87a80004bd6f7b63044c8cc896600266e452201000028acc004cdc7a441000028998021808198161815001a5eb80006266008980103d87a8000005409d198008034006446600c0046605c00a00280310271bae3027001302c003302a00240a113375e604e60506050605060486ea800530103d87a80008a50408514a0810a29410211813000c528c4cc008008c09c0050202048598009809980f9baa003891919baf302530223754604a60446ea8008004c090c084dd5002448c8cdd7981298111baa00200130243021375400880e914a080ca29410191180f98101810000c5282030374a90011ba548002294101619198008009bac301c0042259800800c5a264b30013375e603c60366ea80040422600a60366ea8006266006006603e00480c0c07400501b22c808a2c80a8dd6980b00098091baa0018b201e30140038b2024375a60260026026002601c6ea80222c805860146ea800e2c8038601200260086ea802629344d95900101"
|
|
7332
|
+
};
|
|
7333
|
+
|
|
7334
|
+
// src/contracts/interest-oracle/scripts.ts
|
|
7335
|
+
function mkInterestOracleValidator(params) {
|
|
7336
|
+
return {
|
|
7337
|
+
type: "PlutusV3",
|
|
7338
|
+
script: applyParamsToScript8(_interestOracleValidator.cborHex, [
|
|
7339
|
+
castInterestOracleParams(params)
|
|
7340
|
+
])
|
|
7341
|
+
};
|
|
7342
|
+
}
|
|
7343
|
+
|
|
7344
|
+
// tests/queries/interest-oracle-queries.ts
|
|
7345
|
+
import {
|
|
7346
|
+
assetClassToUnit as assetClassToUnit2
|
|
7347
|
+
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
7348
|
+
async function findInterestOracle(lucid, interestNft) {
|
|
7349
|
+
return lucid.utxoByUnit(assetClassToUnit2(interestNft));
|
|
7350
|
+
}
|
|
7351
|
+
|
|
7352
|
+
// src/contracts/interest-oracle/transactions.ts
|
|
7353
|
+
async function startInterestOracle(initialUnitaryInterest, initialInterestRate, initialLastInterestUpdate, oracleParams, lucid, interestTokenName, withScriptRef = false, refOutRef) {
|
|
7354
|
+
const network = lucid.config().network;
|
|
7355
|
+
const tokenName = interestTokenName ?? "INTEREST_ORACLE";
|
|
7356
|
+
if (!refOutRef) {
|
|
7357
|
+
refOutRef = (await lucid.wallet().getUtxos())[0];
|
|
7358
|
+
}
|
|
7359
|
+
const [tx, policyId] = await oneShotMintTx(lucid, {
|
|
7360
|
+
referenceOutRef: {
|
|
7361
|
+
txHash: refOutRef.txHash,
|
|
7362
|
+
outputIdx: BigInt(refOutRef.outputIndex)
|
|
7363
|
+
},
|
|
7364
|
+
mintAmounts: [
|
|
7365
7365
|
{
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
StabilityPool: {
|
|
7369
|
-
...stabilityPoolDatum,
|
|
7370
|
-
state: newPoolState
|
|
7371
|
-
}
|
|
7372
|
-
})
|
|
7373
|
-
},
|
|
7374
|
-
addAssets9(
|
|
7375
|
-
stabilityPoolUtxo.assets,
|
|
7376
|
-
negateAssets4(reward),
|
|
7377
|
-
mkAssetsOf7(iassetAssetClass, accountBalanceChange + withdrawalFeeAmt)
|
|
7378
|
-
)
|
|
7379
|
-
);
|
|
7380
|
-
const theoreticalOwnerOutputVal = addAssets9(
|
|
7381
|
-
reward,
|
|
7382
|
-
isDepositOrRewardWithdrawal ? {} : mkAssetsOf7(
|
|
7383
|
-
iassetAssetClass,
|
|
7384
|
-
-accountBalanceChange - withdrawalFeeAmt
|
|
7385
|
-
)
|
|
7386
|
-
);
|
|
7387
|
-
const ownerOutputDat = serialiseActionReturnDatum({
|
|
7388
|
-
IndigoStabilityPoolAccountAdjustment: {
|
|
7389
|
-
txHash: fromHex9(accountUtxo.txHash),
|
|
7390
|
-
outputIndex: BigInt(accountUtxo.outputIndex)
|
|
7366
|
+
tokenName: fromText6(tokenName),
|
|
7367
|
+
amount: 1n
|
|
7391
7368
|
}
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
);
|
|
7404
|
-
const accountOutputDat = serialiseStabilityPoolDatum({
|
|
7405
|
-
Account: {
|
|
7406
|
-
...updatedAccountContent,
|
|
7407
|
-
state: {
|
|
7408
|
-
...updatedAccountContent.state,
|
|
7409
|
-
depositVal: spAdd(
|
|
7410
|
-
updatedAccountContent.state.depositVal,
|
|
7411
|
-
mkSPInteger(accountBalanceChange)
|
|
7412
|
-
)
|
|
7369
|
+
]
|
|
7370
|
+
});
|
|
7371
|
+
const validator = mkInterestOracleValidator(oracleParams);
|
|
7372
|
+
tx.pay.ToContract(
|
|
7373
|
+
validatorToAddress(network, validator),
|
|
7374
|
+
{
|
|
7375
|
+
kind: "inline",
|
|
7376
|
+
value: serialiseInterestOracleDatum({
|
|
7377
|
+
unitaryInterest: initialUnitaryInterest,
|
|
7378
|
+
interestRate: {
|
|
7379
|
+
getOnChainInt: initialInterestRate
|
|
7413
7380
|
},
|
|
7414
|
-
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
1n
|
|
7421
|
-
);
|
|
7422
|
-
const accountOutMinUtxoLovelace = estimateUtxoMinLovelace3(
|
|
7423
|
-
lucid.config().protocolParameters,
|
|
7424
|
-
stabilityPoolUtxo.address,
|
|
7425
|
-
accountOutputValWithoutAda,
|
|
7426
|
-
{ InlineDatum: { datum: accountOutputDat } }
|
|
7427
|
-
);
|
|
7428
|
-
const accountOutputAdaAmt = lovelacesAmt2(accountUtxo.assets) - extraOwnerOutputLovelacesAmt - txFee;
|
|
7429
|
-
if (accountOutputAdaAmt < accountOutMinUtxoLovelace) {
|
|
7430
|
-
throw new Error("Account doesn't have enough ADA to be processed.");
|
|
7431
|
-
}
|
|
7432
|
-
tx.pay.ToContract(
|
|
7433
|
-
stabilityPoolUtxo.address,
|
|
7434
|
-
{
|
|
7435
|
-
kind: "inline",
|
|
7436
|
-
value: accountOutputDat
|
|
7437
|
-
},
|
|
7438
|
-
addAssets9(
|
|
7439
|
-
accountOutputValWithoutAda,
|
|
7440
|
-
mkLovelacesOf4(accountOutputAdaAmt)
|
|
7441
|
-
)
|
|
7442
|
-
).pay.ToAddressWithData(
|
|
7443
|
-
outputAddress,
|
|
7444
|
-
{
|
|
7445
|
-
kind: "inline",
|
|
7446
|
-
value: ownerOutputDat
|
|
7447
|
-
},
|
|
7448
|
-
actualOwnerOutputVal
|
|
7449
|
-
).setMinFee(txFee);
|
|
7450
|
-
}).with({ Close: P17.select() }, async (closeContent) => {
|
|
7451
|
-
if (txFee > closeContent.maxTxFee) {
|
|
7452
|
-
throw new Error("Account doesn't allow current transaction fee.");
|
|
7381
|
+
lastUpdated: initialLastInterestUpdate
|
|
7382
|
+
})
|
|
7383
|
+
},
|
|
7384
|
+
{
|
|
7385
|
+
lovelace: 2500000n,
|
|
7386
|
+
[toUnit2(policyId, fromText6(tokenName))]: 1n
|
|
7453
7387
|
}
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
|
|
7460
|
-
|
|
7461
|
-
);
|
|
7462
|
-
const iassetDatum = parseIAssetDatumOrThrow(
|
|
7463
|
-
getInlineDatumOrThrow(iAssetUtxo)
|
|
7464
|
-
);
|
|
7465
|
-
const outputAddress = addressToBech322(
|
|
7466
|
-
closeContent.outputAddress,
|
|
7467
|
-
lucid.config().network
|
|
7468
|
-
);
|
|
7469
|
-
const e2s2sIdxs = await findRelevantE2s2sIdxs(
|
|
7470
|
-
lucid,
|
|
7471
|
-
stabilityPoolDatum,
|
|
7472
|
-
accountDatum.state,
|
|
7473
|
-
allE2s2sSnapshotOrefs
|
|
7474
|
-
);
|
|
7475
|
-
const { updatedAccountContent, reward } = updateAccount(
|
|
7476
|
-
stabilityPoolDatum,
|
|
7477
|
-
accountDatum,
|
|
7478
|
-
e2s2sIdxs
|
|
7479
|
-
);
|
|
7480
|
-
const newPoolDepositExcludingFee = spZeroNegatives(
|
|
7481
|
-
spSub(
|
|
7482
|
-
stabilityPoolDatum.state.depositVal,
|
|
7483
|
-
updatedAccountContent.state.depositVal
|
|
7484
|
-
)
|
|
7485
|
-
);
|
|
7486
|
-
const withdrawnAmt = zeroNegatives(
|
|
7487
|
-
fromSPInteger(updatedAccountContent.state.depositVal)
|
|
7488
|
-
);
|
|
7489
|
-
const withdrawalFeeAmt = newPoolDepositExcludingFee.value === 0n ? 0n : calculateFeeFromRatio(
|
|
7490
|
-
iassetDatum.stabilityPoolWithdrawalFeeRatio,
|
|
7491
|
-
withdrawnAmt
|
|
7492
|
-
);
|
|
7493
|
-
const newPoolState = updatePoolStateWhenWithdrawalFee(withdrawalFeeAmt, {
|
|
7494
|
-
...stabilityPoolDatum.state,
|
|
7495
|
-
depositVal: newPoolDepositExcludingFee
|
|
7496
|
-
});
|
|
7497
|
-
const { e2s2sRefInputs, mkProcessRequestAccountRedeemerContent } = createProcessRequestAccountRedeemer(
|
|
7498
|
-
e2s2sIdxs,
|
|
7499
|
-
[...baseRefInputs, accountTokenScriptRef],
|
|
7500
|
-
currentTime
|
|
7388
|
+
);
|
|
7389
|
+
if (withScriptRef) {
|
|
7390
|
+
tx.pay.ToAddressWithData(
|
|
7391
|
+
validatorToAddress(network, validator),
|
|
7392
|
+
void 0,
|
|
7393
|
+
void 0,
|
|
7394
|
+
validator
|
|
7501
7395
|
);
|
|
7502
|
-
|
|
7503
|
-
|
|
7396
|
+
}
|
|
7397
|
+
return [
|
|
7398
|
+
tx,
|
|
7399
|
+
{
|
|
7400
|
+
currencySymbol: fromHex10(policyId),
|
|
7401
|
+
tokenName: fromHex10(fromText6(tokenName))
|
|
7504
7402
|
}
|
|
7505
|
-
|
|
7506
|
-
kind: "selected",
|
|
7507
|
-
inputs: [stabilityPoolUtxo, accountUtxo],
|
|
7508
|
-
makeRedeemer: (indices) => {
|
|
7509
|
-
return serialiseStabilityPoolRedeemer({
|
|
7510
|
-
ProcessRequestAccount: mkProcessRequestAccountRedeemerContent(
|
|
7511
|
-
indices[0],
|
|
7512
|
-
indices[1]
|
|
7513
|
-
)
|
|
7514
|
-
});
|
|
7515
|
-
}
|
|
7516
|
-
}).mintAssets(
|
|
7517
|
-
mkAssetsOf7(
|
|
7518
|
-
fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
|
|
7519
|
-
-1n
|
|
7520
|
-
),
|
|
7521
|
-
Data32.void()
|
|
7522
|
-
).pay.ToContract(
|
|
7523
|
-
stabilityPoolUtxo.address,
|
|
7524
|
-
{
|
|
7525
|
-
kind: "inline",
|
|
7526
|
-
value: serialiseStabilityPoolDatum({
|
|
7527
|
-
StabilityPool: {
|
|
7528
|
-
...stabilityPoolDatum,
|
|
7529
|
-
state: newPoolState
|
|
7530
|
-
}
|
|
7531
|
-
})
|
|
7532
|
-
},
|
|
7533
|
-
addAssets9(
|
|
7534
|
-
stabilityPoolUtxo.assets,
|
|
7535
|
-
negateAssets4(reward),
|
|
7536
|
-
mkAssetsOf7(iassetAssetClass, -withdrawnAmt + withdrawalFeeAmt)
|
|
7537
|
-
)
|
|
7538
|
-
).pay.ToAddressWithData(
|
|
7539
|
-
outputAddress,
|
|
7540
|
-
{
|
|
7541
|
-
kind: "inline",
|
|
7542
|
-
value: serialiseActionReturnDatum({
|
|
7543
|
-
IndigoStabilityPoolAccountClosure: {
|
|
7544
|
-
txHash: fromHex9(accountUtxo.txHash),
|
|
7545
|
-
outputIndex: BigInt(accountUtxo.outputIndex)
|
|
7546
|
-
}
|
|
7547
|
-
})
|
|
7548
|
-
},
|
|
7549
|
-
addAssets9(
|
|
7550
|
-
mkLovelacesOf4(lovelacesAmt2(accountUtxo.assets) - txFee),
|
|
7551
|
-
reward,
|
|
7552
|
-
mkAssetsOf7(iassetAssetClass, withdrawnAmt - withdrawalFeeAmt)
|
|
7553
|
-
)
|
|
7554
|
-
).setMinFee(txFee);
|
|
7555
|
-
}).exhaustive();
|
|
7556
|
-
return tx;
|
|
7557
|
-
}
|
|
7558
|
-
async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, currentSlot) {
|
|
7559
|
-
const draftTx = processSpRequestAuxiliary(
|
|
7560
|
-
stabilityPoolUtxo,
|
|
7561
|
-
accountUtxo,
|
|
7562
|
-
iAssetUtxo,
|
|
7563
|
-
allE2s2sSnapshotOrefs,
|
|
7564
|
-
sysParams,
|
|
7565
|
-
lucid,
|
|
7566
|
-
currentSlot,
|
|
7567
|
-
// Placeholder transation fee
|
|
7568
|
-
1n
|
|
7569
|
-
);
|
|
7570
|
-
const fee = (await (await draftTx).complete()).toTransaction().body().fee();
|
|
7571
|
-
return processSpRequestAuxiliary(
|
|
7572
|
-
stabilityPoolUtxo,
|
|
7573
|
-
accountUtxo,
|
|
7574
|
-
iAssetUtxo,
|
|
7575
|
-
allE2s2sSnapshotOrefs,
|
|
7576
|
-
sysParams,
|
|
7577
|
-
lucid,
|
|
7578
|
-
currentSlot,
|
|
7579
|
-
fee
|
|
7580
|
-
);
|
|
7403
|
+
];
|
|
7581
7404
|
}
|
|
7582
|
-
async function
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
)
|
|
7588
|
-
]),
|
|
7589
|
-
(_) => new Error("Expected a single stability pool Ref Script UTXO")
|
|
7590
|
-
);
|
|
7591
|
-
const snapshotE2s2sPolicyRefScriptUtxo = matchSingle3(
|
|
7592
|
-
await lucid.utxosByOutRef([
|
|
7593
|
-
fromSystemParamsScriptRef(
|
|
7594
|
-
sysParams.scriptReferences.authTokenPolicies.snapshotEpochToScaleToSumTokenRef
|
|
7595
|
-
)
|
|
7596
|
-
]),
|
|
7597
|
-
(_) => new Error("Expected a single snapshot e2s2s policy Ref Script UTXO")
|
|
7598
|
-
);
|
|
7599
|
-
const spUtxo = matchSingle3(
|
|
7600
|
-
await lucid.utxosByOutRef([stabilityPoolOref]),
|
|
7601
|
-
(_) => new Error("Expected a single stability pool UTXO")
|
|
7602
|
-
);
|
|
7603
|
-
const spDatum = parseStabilityPoolDatumOrThrow(getInlineDatumOrThrow(spUtxo));
|
|
7604
|
-
const [newSnapshotDatums, newAssetStates] = partitionEpochToScaleToSums(spDatum);
|
|
7605
|
-
if (newSnapshotDatums.length === 0) {
|
|
7606
|
-
throw new Error("There has to be a snapshot being created.");
|
|
7405
|
+
async function feedInterestOracle(params, newInterestRate, lucid, assetClass, utxo, scriptRef2) {
|
|
7406
|
+
if (!assetClass && !utxo)
|
|
7407
|
+
throw new Error("Either interest oracle nft or utxo must be provided");
|
|
7408
|
+
if (assetClass && !utxo) {
|
|
7409
|
+
utxo = await findInterestOracle(lucid, assetClass);
|
|
7607
7410
|
}
|
|
7608
|
-
const
|
|
7609
|
-
|
|
7411
|
+
const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
7412
|
+
const tx = lucid.newTx();
|
|
7413
|
+
const datum = parseInterestOracleDatum(getInlineDatumOrThrow(utxo));
|
|
7414
|
+
if (scriptRef2) {
|
|
7415
|
+
tx.readFrom([scriptRef2]);
|
|
7416
|
+
} else {
|
|
7417
|
+
tx.attach.Script(mkInterestOracleValidator(params));
|
|
7418
|
+
}
|
|
7419
|
+
tx.collectFrom(
|
|
7420
|
+
[utxo],
|
|
7421
|
+
serialiseFeedInterestOracleRedeemer({
|
|
7422
|
+
newInterestRate: {
|
|
7423
|
+
getOnChainInt: newInterestRate
|
|
7424
|
+
},
|
|
7425
|
+
currentTime: now
|
|
7426
|
+
})
|
|
7610
7427
|
);
|
|
7611
|
-
|
|
7612
|
-
|
|
7613
|
-
serialiseStabilityPoolRedeemer("RecordEpochToScaleToSum")
|
|
7614
|
-
).mintAssets(
|
|
7615
|
-
mkAssetsOf7(snapshotAc, BigInt(newSnapshotDatums.length)),
|
|
7616
|
-
Data32.void()
|
|
7617
|
-
).pay.ToContract(
|
|
7618
|
-
spUtxo.address,
|
|
7428
|
+
tx.pay.ToContract(
|
|
7429
|
+
utxo.address,
|
|
7619
7430
|
{
|
|
7620
7431
|
kind: "inline",
|
|
7621
|
-
value:
|
|
7622
|
-
|
|
7432
|
+
value: serialiseInterestOracleDatum({
|
|
7433
|
+
unitaryInterest: datum.unitaryInterest + calculateUnitaryInterestSinceOracleLastUpdated(now, datum),
|
|
7434
|
+
interestRate: {
|
|
7435
|
+
getOnChainInt: newInterestRate
|
|
7436
|
+
},
|
|
7437
|
+
lastUpdated: now
|
|
7623
7438
|
})
|
|
7624
7439
|
},
|
|
7625
|
-
|
|
7440
|
+
utxo.assets
|
|
7626
7441
|
);
|
|
7627
|
-
|
|
7628
|
-
|
|
7629
|
-
|
|
7630
|
-
{
|
|
7631
|
-
kind: "inline",
|
|
7632
|
-
value: serialiseStabilityPoolDatum({
|
|
7633
|
-
SnapshotEpochToScaleToSum: newDatum
|
|
7634
|
-
})
|
|
7635
|
-
},
|
|
7636
|
-
mkAssetsOf7(snapshotAc, 1n)
|
|
7637
|
-
);
|
|
7638
|
-
}
|
|
7442
|
+
tx.validFrom(Number(now) - ONE_SECOND);
|
|
7443
|
+
tx.validTo(Number(now + params.biasTime) - ONE_SECOND);
|
|
7444
|
+
tx.addSignerKey(params.owner);
|
|
7639
7445
|
return tx;
|
|
7640
7446
|
}
|
|
7641
|
-
|
|
7642
|
-
|
|
7643
|
-
|
|
7644
|
-
|
|
7645
|
-
|
|
7646
|
-
|
|
7647
|
-
|
|
7648
|
-
(
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
|
|
7655
|
-
tx.pay.ToContract(
|
|
7656
|
-
accountUtxo.address,
|
|
7657
|
-
{
|
|
7658
|
-
kind: "inline",
|
|
7659
|
-
value: serialiseStabilityPoolDatum({
|
|
7660
|
-
Account: {
|
|
7661
|
-
...oldAccountDatum,
|
|
7662
|
-
request: null
|
|
7663
|
-
}
|
|
7664
|
-
})
|
|
7665
|
-
},
|
|
7666
|
-
mkAssetsOf7(
|
|
7667
|
-
fromSystemParamsAsset(params.stabilityPoolParams.accountToken),
|
|
7668
|
-
1n
|
|
7669
|
-
)
|
|
7670
|
-
);
|
|
7447
|
+
|
|
7448
|
+
// src/contracts/interest-collection/helpers.ts
|
|
7449
|
+
import { toHex as toHex10 } from "@lucid-evolution/lucid";
|
|
7450
|
+
function signersAllOf(multisig) {
|
|
7451
|
+
if ("Signature" in multisig) {
|
|
7452
|
+
return [toHex10(multisig.Signature.keyHash)];
|
|
7453
|
+
} else {
|
|
7454
|
+
return multisig.AtLeast.authSignatories.map((signatory) => {
|
|
7455
|
+
try {
|
|
7456
|
+
return signersAllOf(fromDataMultisig(signatory));
|
|
7457
|
+
} catch {
|
|
7458
|
+
return [];
|
|
7459
|
+
}
|
|
7460
|
+
}).flat();
|
|
7671
7461
|
}
|
|
7672
|
-
return tx;
|
|
7673
7462
|
}
|
|
7674
7463
|
|
|
7675
|
-
// src/contracts/
|
|
7676
|
-
import {
|
|
7677
|
-
|
|
7678
|
-
|
|
7679
|
-
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
|
|
7464
|
+
// src/contracts/interest-collection/types.ts
|
|
7465
|
+
import { Data as Data37 } from "@lucid-evolution/lucid";
|
|
7466
|
+
var InterestCollectionParamsSchema = Data37.Object({
|
|
7467
|
+
versionRecordNft: AssetClassSchema2,
|
|
7468
|
+
multisigUtxoNft: AssetClassSchema2,
|
|
7469
|
+
cdpAuthTk: AssetClassSchema2,
|
|
7470
|
+
collateralAssetAuthTk: AssetClassSchema2,
|
|
7471
|
+
govAuthTk: AssetClassSchema2,
|
|
7472
|
+
cdpAssetSymbol: Data37.Bytes(),
|
|
7473
|
+
cdpBiasTime: Data37.Integer(),
|
|
7474
|
+
interestSettlementCooldown: Data37.Integer()
|
|
7475
|
+
});
|
|
7476
|
+
var InterestCollectionParams = InterestCollectionParamsSchema;
|
|
7477
|
+
function castInterestCollectionParams(params) {
|
|
7478
|
+
return Data37.castTo(params, InterestCollectionParams);
|
|
7479
|
+
}
|
|
7480
|
+
|
|
7481
|
+
// src/contracts/interest-collection/scripts.ts
|
|
7482
|
+
import { applyParamsToScript as applyParamsToScript9 } from "@lucid-evolution/lucid";
|
|
7483
|
+
|
|
7484
|
+
// src/validators/interest-collection-validator.ts
|
|
7485
|
+
var _interestCollectionValidator = {
|
|
7486
|
+
type: "PlutusScriptV3",
|
|
7487
|
+
description: "Generated by Aiken",
|
|
7488
|
+
cborHex: "59202059201d010100229800aba2aba1aba0aab9faab9eaab9dab9cab9a488888888cc896600264653001300b00198059806000cdc3a4005300b0024888966002600460166ea800e33001300c3754007370e90034dc3a4001370e90024c02cdd5002244444646644b300130060048acc004c050dd5006400a2c80aa2b3001300a0048991919194c004dd6980d800cdd6980d8024dd6980d801cdd6980d80124444b3001302000580545901d0c06c004c068004c064004c050dd50064566002600a009159800980a1baa00c8014590154566002600e009159800980a1baa00c801459015456600266e1d20080048acc004c050dd5006400a2c80aa2c8089011202240448088660024602c602e003259800980218091baa0018980b18099baa0018b20209180b180b980b980b980b800c888c8cc88cc0080080048966002003003899192cc004cdc8803000c56600266e3c01800626eb4c06800a00a80ba266008008603c00680b8dd7180c000980d800a0323232330010010062259800800c00e26464b30013372201000315980099b8f00800189bab301b002802a030899802002180f801a030375c6032002603800280d052f5bded8c029000488c8cc00400400c896600200314bd7044cc8966002600a00513301a00233004004001899802002000a02a3019001301a001405d3710900048c058c05cc05c00644646600200200644660060026004005301137540152259800800c40062a660240042002808a4602c602e602e602e602e602e602e602e602e602e003374a90012444444444444653001222323300d00423002301230243754002b300130143021375400312330053756602260466ea800400e24601930013756602260466ea80066eb8c098c08cdd5001cdd7180898119baa003403880fa4466016004466ebcc094c088dd5181298111baa3010302237540020052232330010010032259800800c5a264b30013375e604e60486ea80040122602460486ea800626600600660500048108c0980050242444b300130140088cc00488c966002602e0031323259800981580140122c8140dd6981480098129baa0038acc004c06c00626464b3001302b0028024590281bad302900130253754007159800980b000c566002604a6ea800e005164099164088811102218119baa002980518111baa028980818111baa028998009bac30253022375402e0229111192cc0040060451598009815800c4c9660020030248992cc004c0b400a2646644b3001301e00189919194c004dd69819000cc0cc0066eb4c0c800e6eb4c0c8009222259800981b801c4cc044c0d800c0262c81a06064002606200260586ea800e2b30013022001899192cc004c0c800a0091640bc6eb4c0c0004c0b0dd5001c566002603a00315980098161baa00380145902d4566002603e0031323322598009819800c4cc034c0c80040162c8180dd69818000981880098161baa0038acc004cdc3a401000315980098161baa00380145902d456600266e1d200a0018992cc004c0c4006264b30013020302d375400313232332259800981b001c0222c8198dd698198009bae30330023033001302e37540031640ac60600031640b860586ea800e2b30013370e9006000c56600260586ea800e0051640b515980099b874803800626464b3001303200280245902f1bad3030001302c375400715980099b874804000626464b3001303200280245902f1bad3030001302c375400715980099b87480480062b3001302c37540070028b205a8b205240a48149029205240a48149029205240a42b30013300f4901205370656e74205554784f2063616e6e6f7420686176652061646d696e204e4654009800998061bab3018302a375400a00d4a14a2813a26601e9212b43445020696e70757420646f6573206e6f74206861766520616e20616c6c6f7765642072656465656d6572003259800980e800c528c566002604200314a3159800980e000c528c56600266e1d200c0018a518a5040a0814102820503029375400314a08138c0a4dd50009919198008009bab300f302b37540404464b30013375e00860580031302d00189980180198188012054302f001300c3302b302c3029375400297ae0812a054302b00140a5300137586054604e6ea80720094c103d87a8000402102240a08140cc018dd6181498131baa01b3029302637546052604c6ea80051980092cc004c054c088dd5000c48c8cdd7981418129baa302830253754004002604e60486ea800a246466ebcc0a0c094dd5001000981398121baa0024081374a900048c098c09cc09cc09c0064464b30013017001899192cc004c0ac00a0091640a06eb8c0a4004c094dd5001c566002603600315980098129baa0038014590264590222044302337540053700900124444464b3001301e00e8cc004c0a0dd501048966002603860526ea800a264646644b30013032003802c5902f1bae302f001375c605e004605e00260546ea800a2c813a44b3001301c30293754005132323322598009819001c0162c8178dd698178009bad302f002302f001302a375400516409d223259800980e800c566002603a60546ea800a2980103d87a80008a6103d879800040a1159800980e000c566002603860546ea800a2980103d87a80008a6103d87b800040a113322598009811800c4c96600266e2000c0062980103d87980008acc004cdc4000801c530103d87b80008a6103d87a800040ac8158dd6981818169baa0048acc004c07c006298103d87b80008a6103d879800040a88150dd6981718159baa003302a3754004814102818149baa0029180319815992cc004c080c0a4dd5000c4c966002604260546ea8c064c0acdd5181718159baa00389807198169ba80014bd7044c038cc0b4dd41802800a5eb810281bad302d302a37540031001409c605860526ea8c0b0c0a4dd500099815992cc004c080c0a4dd5000c4c966002604260546ea8c064c0acdd5180c98159baa00389807198169ba80014bd7044c038cc0b4dd419b80001480052f5c08140dd6981698151baa0018800a04e302c30293754602e60526ea80052f5c1223302c337606ea4008dd4000a5eb7bdb182444b3001337129002000c66002007302f302f00299b800014800d003456600266e2520020018cc00400e605e005337000029000a0068acc004c0740062605c0051533029491146578706563745f61743a206e6f7420666f756e64001640a0814102848c0b0c0b4c0b4c0b4c0b4c0b4c0b4c0b400644444b30013300b0040058acc004cdd7980a98169baa0050038acc00660026eacc06cc0b4dd5002c00a0028032266ebcc024c0b4dd5002a60103d87a80008a5040a914a08152294102a48c0b0c0b4c0b4c0b4c0b4c0b4c0b400646058605a605a605a605a605a00291111111111194c004c0e00066eb4c0dc006600c00c9114c004dd6981d001cdd6981d181d801ccc004dd6181d181b9baa02c0029bad303a00f488896600266ebcc0f8c0ecdd5001015466002607c60766ea8c0f8c0ecdd51814981d9baa002981f1bac3023303b3754061330053758605260766ea80c001122259800998101bab302c303e37546058607c6ea8004c068c0f8dd502244c966002606a607c6ea8006264b30013044001899192cc004c0d0c104dd500144c8c8c8c8c8c8c8c8c8c8ca600260a0003375c60a0017375a60a001330500089828003cc14001a60a000b30500049bad3050003992cc004c1380062b30013371290021826800c5a26088609a002825a2c8278dd5182800124444444444b3001305b00b899817182d00a099912cc004c12c006264b3001305e001899818182e800801c5905b182c9baa0098acc004c13c006264b3001305e001899818982e800801c5905b182c9baa0098acc004c12800626464b3001305f00280245905c1bae305d0013059375401316415882b10560998170030998168028998168020998168018992cc004c128006264b3001305d001899818182e00080c45905a182c1baa00b8acc004c1380062b3001305837540170178b20b28b20aa415460ac6ea8028c158dd5003c590580c140004c13c004c138004c134004c130004c12c004c128004c124004c120004c11c004c108dd500145903f0992cc004cc090dd5981818211baa303030423754002605c60846ea800a264b300130353042375400313232323322598009826001c4c966002607660906ea800626464b3001304f00289919192cc004cc0cd2410f4261642074782076616c696469747900332259800992cc004c10800629462b300130470018a518a5041388270c13cdd519812982998281baa002305330503754003132598009821800c528c566002608e00314a314a0827104e18279baa33025303e30503754004607c60a06ea8006294104d1811180f98271baa0433022302b33050302b33050303133050375060066eb4c074c138dd502a25eb80cc142600294698103d87a8000a60103d8798000412c97ae033050302b33050303133050375066e00050dd6980e98271baa0544bd70198284c00528d300103d87a8000a60103d8798000412c97ae04bd704566002660669201274d757374206f6e6c79206d696e742074686520616363756d756c6174656420696e746572657374003375e6074609c6ea810cdd32cc004c100006297adef6c6089982819bb0301c304e37540a86e98cc084dd7182898271baa00e0014bd6f7b63020968acc004cc0cd241205370656e74205554784f2063616e6e6f7420686176652061646d696e204e4654009800998181bab303c304e37546078609c6ea8054c0f0c138dd502a528528a096899819a48146436f6e74696e75696e67206f7574707574206d7573742068617665206e6f20646174756d20616e6420686f6c642074686520616363756d756c6174656420696e7465726573740098008094c0c4cc140c0accc14004ccc141300103d87a80004bd7025eb8298107d87b9fd87980ff00cc004dd5981e18271baa303c304e375402b375c6038609c6ea81526eb8c144c138dd50072444b300130430048801c4c8c8cc0040040148966002003133056337606ea4014dd3001a5eb7bdb1822646644b30013372201000515980099b8f0080028992cc004cdd7a6101a000374c003100289982d19bb037520126e9800400905519198008009bab30580042259800800c4cc16ccdd81ba9009375001897adef6c6089919912cc004cdc8806001456600266e3c03000a264b30013370e00266e052000010880144cc17ccdd81ba900d375066e0000404000905a1bad305c00389982f19bb037520186ea003c01105944cc17800ccc0140140050591bae3059001305e002305c0014169133059337606ea4020dd300300220a889982c80199802802800a0a8375c60a800260b200460ae00282a8cc09000401104e2980103d87a8000407914a0825a294104b45282096375a60a06530010019bac3051304e375408737566064609c6ea810e660a098101000033050374e60a46eb0c0d8c138dd5021998284c005285300103d87a8000a60103d8798000412c97ae040044444b30010038800c4cc8966002609260a46ea8c158c14cdd5182b18299baa3041305337540051329800803c00a6eacc15cc160006653001375860b0003304b3054375460b060b2003375a60b000b30580024888966002660766eacc11cc164dd51823982c9baa0083041305937540bf15980099b8748038c160dd5000c4c96600260bc00313322598009827182d9baa0018992cc004c184006264b30013050305d37540031323232323298009833000cdd718330024c19800e6eb4c1980092222598009835802c4c8cc10c0044cc0fc00c4cc896600260b8003132323322598009839001c01a2c8378dd698378009bad306f002306f001306a375400f1598009830000c4c8c8cc896600260e40070068b20de375a60de0026eb4c1bc008c1bc004c1a8dd5003c5906720ce159800982d18339baa005899192cc0056600266e3c018dd7183698351baa02a899baf0053058306a375405514a0833a2b30013371066e00004dd6981d98351baa0700308992cc004c1500062b30019800983700b4c138cc1b4c1b8c1acdd5182c98359baa01a4bd704cdd2a4008660da6090660da6090660da008660da6ea401ccc1b4018cc1b4dd419b800050013306d30483306d3750062660da6ea007d2f5c097ae04bd7025eb826eacc164c1acdd5182c98359baa01aa60103d879800040ed13306d375066e00050004cc1b4dd3983780b19836cc00405698103d87a8000a60103d879800041a097ae08a99834a481333c65787065637465643e20457870656374206120636f727265637479207570646174656420636f6e74696e75696e6720434450001641a115330694912a3c65787065637465643e20546865726520697320736f6d65206163637275656420696e7465726573742e001641a064b3001337120026eb4c1b8c1acdd5014c56600266e20dd6982998359baa029031899b803370666e08cdc09bad306e306b375405200200a904040507b7a566df00d99b833370666e08cdc118101bad3053306b37540526eb4c1b8c1acdd5182c98359baa02900548202c227efa8052080897a8a99834a4810155001641a115980099b88002031899b833370666e08cdc118100011bad306e306b375460b260d66ea80a40152080b089fbea014820225ea2a660d292010156001641a08340dd698369837001454cc1a124012d3c65787065637465643e20497420697320746f6f20736f6f6e20746f20736574746c6520696e7465726573742e0016419d1533068491413c65787065637465643e20416c6c20434450732061726520666f72207468652073616d652069417373657420616e6420636f6c6c61746572616c2061737365742e0016419c6eb4c1b0004c1a0dd5002c5906518339baa005306a0098b20d01833000983280098320009831800982f1baa0018b20b630600018b20bc305c37540031641646eb4c174004c11cc108c168dd51824182d1baa0098b20b63059375400316415915980099baf305c3059375460b860b26ea8c11cc164dd500400f45660033001003a50a51415913305b3750004660b66e9c010cc16e600294698103d87a8000a60103d8798000415897ae08a9982ba4812845787065637420612073696e676c6520696e74657265737420636f6c6c6563746f7220696e7075740016415913305b3750004660b66e9c010cc16e60020074c103d87a8000a60103d8798000415897ae0415882b060b00088038c8cc0040040148966002003168994c004c15400660ac003305a00248896600266ebc00cc0f0cc16cc170c164dd500425eb822660b6004660b66e980052f5c113300600600141583058001415919800803400600900340188280c15000cc15400d05219b80375a609e60986ea80296600266e20dd6981a18261baa00a012899b833370666e08cdc118009bad3034304c37540146eb4c13cc130dd5181d18261baa00a482020283dbd2b36f806d2080b089fbea014820225ea2a66094921015a001641246e040462c8260dd6982680098249baa0018b208c304b0048b2092375a60920026eb4c12400cc124004c120004c10cdd5000c590401817981518211baa30303042375400315330404914c3c65787065637465643e205468652070726f7669646564207265662e20696e70757420696e64657820636f72726573706f6e647320746f2074686520696e746572657374206f7261636c652e001640fc660166eb0c0bcc104dd501b0049821800c59041181f9baa0018b2078302b3026303e37546058607c6ea80062a6607892014d3c65787065637465643e205468652070726f7669646564207265662e20696e70757420696e64657820636f72726573706f6e647320746f2074686520636f6c6c61746572616c2061737365742e001640ec8a9981ca49413c65787065637465643e205468652070726f766964656420696e70757420696e64657820636f72726573706f6e647320746f20746865206f776e20696e7075742e001640e0181b805a2646530012259800980f18159baa0028992cc004c0c400626600860600020051640b860586ea800a2c814a4605c605e605e605e605e605e605e605e605e0032232330010010032259800981018169baa0018991919800800802912cc00400629422b30013371e6eb8c0d000400e2946266004004606a00281710321bae3031302e3754003132337126eb4c0c8004c8cc004004dd61819981a001112cc0040062900044cc89660026600e00e0051300d0018800a060303400133002002303500140c8605c6ea800502b2444b3001301e013899912cc004c0cc006264646600e0022b3001330164901235265666572656e636564205554784f206d75737420686176652061646d696e204e465400330133756603e60626ea8c07cc0c4dd500100244cc0592412041646d696e206d756c7469736967206d7573742062652073617469736669656400330053034303137540026eb0c018c0c4dd50134528205c301d301830303754603c60606ea8004c0c80062c8180c06cc0b4dd5019998069bac301b302d37540446060605a6ea8c0c0c0b4dd5198061bac3030302d37540440391598009810009c6600244b30010018a40011300933002002303300140c1301b302d37540673019302d37540673300c37586060605a6ea80880712222323233223300b00113259800981d000c4c966002605a606c6ea8c04cc0dcdd5000c4cc88cc03c0044c9660026603e9211e5370656e74205554784f206d75737420686176652061646d696e204e4654003301c3756605060746ea80280322b30013301f490125466f756e646174696f6e206d756c7469736967206d75737420626520736174697366696564003300e303d303e303e303e303e303e303e303e303e303e303e303e303a3754605060746ea800cdd61807981d1baa02f8acc004cc07d2401234e65772061646d696e67206d756c74697369672063616e6e6f7420626520656d7074790030070018acc004cc07d241244e65772061646d696e206d756c7469736967206d75737420626520736174697366696564003300e0013758601e60746ea80be2b30013301f490121436f6e74696e75696e672076616c7565206d757374206265207468652073616d650098009bab3028303a37540093756605060746ea802a980103d87a8000404d13301f4901244f6c6420616e64206e657720646174756d73206d75737420626520646966666572656e7400980099baf006002a50a5140dd14a081ba29410374528206e8a5040dd14a081b8c0f0c0e4dd5000992cc004c0f0006264b3001302b303837540031323232323298009bad30410019bad30410059bad30410039bad30410024888966002608c00b13259800981a98211baa00189919191919191919191919194c004c1480066eb4c1480326eb4c14802e6eb4c14802a6eb4c1480266eb4c1480226eb4c14801e6eb4c14801a6eb4c1480166eb4c1480126eb4c1480092222222222259800982f00644cc0d4c1740384cc0c402c408a2c82d860a400260a200260a0002609e002609c002609a0026098002609600260940026092002609000260866ea80062c8200c1140222c821860820026080002607e002607c00260726ea80062c81b0c094c080c0e0dd51813181c1baa303b0018b207298009bac302530373754059008a60103d879800040606048603e606e6ea80062c81a0c0e40062c81b8cc07cdd6180e981a9baa02a301330183303730383035375400a97ae030010013020301b3033375400644b300130263033375400314a31323322598009810001456600266e24008c0180062646600200200444b30010018a518acc004cc01c01cc0f0006266004004607a00314a081b103a452820688a5040d06eb4c0e0004dd6181c181c800981a1baa00140c4600800889919912cc004c098c0bcdd5000c4cc8966002606c00313259800981298191baa00189919912cc004c0e800626603a6eb0c0e40048966002005132598009815981c1baa0018991925159800991980080098069bab3027303b375406044b30013371e6eb8c0fc00400e2946266004004608000281ca2934590371bae303c303937540031640d864660020026eb0c09cc0e4dd5003912cc004006298103d87a80008992cc006600266ebc00530103d87a8000a50a5140e11001899801801981f8012070325980099b8f375c607c002017130183303d303e303f0014bd7045300103d87a800040e06eb0c0f400503b44c8c8cc896600260800071300530400068b207a375c607a0026eb8c0f4008c0f4004dd6181d80120728b206e375a606e002607000260666ea80062c8180c07cc068c0c8dd5181018191baa30350018b2066375c606660606ea800660026eb0c078c0c0dd5012cc0ccc0c0dd501b530103d879800040451640b460020026062605c6ea8c0c4c0b8dd5198069bac3031302e375404603a44b30010018a5eb82266062605c6064002660040046066002818102a20541800800911192cc004c07800626464b3001303200280245902f1bae3030001302c37540071598009811000c4c8cc896600260660031330163758606400244b3001002803c66002013303400289800981a801201240c91640c06eb4c0c0004c0c4004c0b0dd5001c590292052302a37540048128888cc8a600264b3001301f302c37540031375a605a60606eacc0c0c0b4dd5000c5200040a8605e0033756005375e605e60600032259800981218169baa005899b890010028acc004cdc480080144cdc480119b80001482026fb80a294102b20564888966002007159800980100344cc00401120008a5040b51325980099baf4c0101400030300018acc004cc008014dd69818981a1bab3031001898019ba630350048a5040b915980099801002a4001130030078a5040b88170c0cc00d0310dd3001194c004006009223302f0023302f374c00297ae04004444b3001002899800a6103d87a80004bd6f7b63044c8cc896600266e452201000028acc004cdc7a441000028998021806998191818001a5eb80006266008980103d87a800000540b5198008034006446600c0046606800a002803102d1bae302d0013032003303000240b8407c22301698008014dd7181198101baa0019bae300e302037540028058602a602c00c602800a8b2012180580098031baa00b8a4d13656400c2a660049212f3c65787065637465643e2053696e676c652043445020696e70757420696e20746865207472616e73616374696f6e2e001615330024913f3c65787065637465643e2053696e676c6520696e74657265737420636f6c6c656374696f6e20696e70757420696e20746865207472616e73616374696f6e2e001601"
|
|
7489
|
+
};
|
|
7490
|
+
|
|
7491
|
+
// src/contracts/interest-collection/scripts.ts
|
|
7492
|
+
function mkInterestCollectionValidator(params) {
|
|
7493
|
+
return {
|
|
7494
|
+
type: "PlutusV3",
|
|
7495
|
+
script: applyParamsToScript9(_interestCollectionValidator.cborHex, [
|
|
7496
|
+
castInterestCollectionParams(params)
|
|
7497
|
+
])
|
|
7498
|
+
};
|
|
7499
|
+
}
|
|
7500
|
+
var mkInterestCollectionValidatorFromSP = (params) => {
|
|
7501
|
+
return {
|
|
7502
|
+
type: "PlutusV3",
|
|
7503
|
+
script: applyParamsToScript9(_interestCollectionValidator.cborHex, [
|
|
7504
|
+
castInterestCollectionParams({
|
|
7505
|
+
versionRecordNft: fromSystemParamsAssetLucid(params.versionRecordNft),
|
|
7506
|
+
multisigUtxoNft: fromSystemParamsAssetLucid(params.multisigUtxoNft),
|
|
7507
|
+
cdpAuthTk: fromSystemParamsAssetLucid(params.cdpAuthTk),
|
|
7508
|
+
collateralAssetAuthTk: fromSystemParamsAssetLucid(
|
|
7509
|
+
params.collateralAssetAuthTk
|
|
7510
|
+
),
|
|
7511
|
+
govAuthTk: fromSystemParamsAssetLucid(params.govAuthTk),
|
|
7512
|
+
cdpAssetSymbol: params.cdpAssetSymbol.unCurrencySymbol,
|
|
7513
|
+
cdpBiasTime: BigInt(params.cdpBiasTime),
|
|
7514
|
+
interestSettlementCooldown: BigInt(params.interestSettlementCooldown)
|
|
7515
|
+
})
|
|
7516
|
+
])
|
|
7517
|
+
};
|
|
7518
|
+
};
|
|
7519
|
+
|
|
7520
|
+
// src/contracts/interest-collection/queries.ts
|
|
7521
|
+
import { option as O14, function as F17 } from "fp-ts";
|
|
7684
7522
|
import {
|
|
7523
|
+
assetClassToUnit as assetClassToUnit3,
|
|
7685
7524
|
assetClassValueOf as assetClassValueOf6,
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
mkLovelacesOf as mkLovelacesOf5
|
|
7525
|
+
getRandomElement as getRandomElement2,
|
|
7526
|
+
matchSingle as matchSingle3
|
|
7689
7527
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
7690
|
-
async function
|
|
7691
|
-
|
|
7692
|
-
|
|
7693
|
-
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
]),
|
|
7697
|
-
(_2) => new Error("Expected a single staking Ref Script UTXO")
|
|
7528
|
+
async function findAllInterestCollectors(lucid, sysParams) {
|
|
7529
|
+
return lucid.utxosAt(
|
|
7530
|
+
createScriptAddress(
|
|
7531
|
+
lucid.config().network,
|
|
7532
|
+
sysParams.validatorHashes.interestCollectionHash
|
|
7533
|
+
)
|
|
7698
7534
|
);
|
|
7699
|
-
const stakingTokenPolicyRefScriptUtxo = matchSingle(
|
|
7700
|
-
await lucid.utxosByOutRef([
|
|
7701
|
-
fromSystemParamsScriptRef(
|
|
7702
|
-
params.scriptReferences.authTokenPolicies.stakingTokenRef
|
|
7703
|
-
)
|
|
7704
|
-
]),
|
|
7705
|
-
(_2) => new Error("Expected a single staking token policy Ref Script UTXO")
|
|
7706
|
-
);
|
|
7707
|
-
const newStakingManagerDatum = {
|
|
7708
|
-
totalStake: stakingManagerOut.datum.totalStake + amount,
|
|
7709
|
-
managerSnapshot: {
|
|
7710
|
-
snapshotAda: stakingManagerOut.datum.managerSnapshot.snapshotAda
|
|
7711
|
-
}
|
|
7712
|
-
};
|
|
7713
|
-
const stakingPositionDatum = {
|
|
7714
|
-
owner: fromHex10(pkh.hash),
|
|
7715
|
-
lockedAmount: [],
|
|
7716
|
-
positionSnapshot: {
|
|
7717
|
-
snapshotAda: stakingManagerOut.datum.managerSnapshot.snapshotAda
|
|
7718
|
-
}
|
|
7719
|
-
};
|
|
7720
|
-
const stakingToken = params.stakingParams.stakingToken[0].unCurrencySymbol + fromText6(params.stakingParams.stakingToken[1].unTokenName);
|
|
7721
|
-
const indyToken = params.stakingParams.indyToken[0].unCurrencySymbol + fromText6(params.stakingParams.indyToken[1].unTokenName);
|
|
7722
|
-
return lucid.newTx().collectFrom(
|
|
7723
|
-
[stakingManagerOut.utxo],
|
|
7724
|
-
serialiseStakingRedeemer({
|
|
7725
|
-
CreateStakingPosition: { creatorPkh: fromHex10(pkh.hash) }
|
|
7726
|
-
})
|
|
7727
|
-
).readFrom([stakingRefScriptUtxo]).pay.ToContract(
|
|
7728
|
-
stakingManagerOut.utxo.address,
|
|
7729
|
-
{
|
|
7730
|
-
kind: "inline",
|
|
7731
|
-
value: serialiseStakingDatum(newStakingManagerDatum)
|
|
7732
|
-
},
|
|
7733
|
-
stakingManagerOut.utxo.assets
|
|
7734
|
-
).readFrom([stakingTokenPolicyRefScriptUtxo]).mintAssets(
|
|
7735
|
-
{
|
|
7736
|
-
[stakingToken]: 1n
|
|
7737
|
-
},
|
|
7738
|
-
Data33.void()
|
|
7739
|
-
).pay.ToContract(
|
|
7740
|
-
stakingManagerOut.utxo.address,
|
|
7741
|
-
{
|
|
7742
|
-
kind: "inline",
|
|
7743
|
-
value: serialiseStakingDatum(stakingPositionDatum)
|
|
7744
|
-
},
|
|
7745
|
-
{
|
|
7746
|
-
[stakingToken]: 1n,
|
|
7747
|
-
[indyToken]: amount
|
|
7748
|
-
}
|
|
7749
|
-
).addSignerKey(pkh.hash);
|
|
7750
|
-
}
|
|
7751
|
-
async function adjustStakingPosition(stakingPositionRef, amount, params, lucid, currentSlot, stakingManagerRef) {
|
|
7752
|
-
const network = lucid.config().network;
|
|
7753
|
-
const now = BigInt(slotToUnixTime8(network, currentSlot));
|
|
7754
|
-
const stakingPositionOut = await findStakingPositionByOutRef(
|
|
7755
|
-
stakingPositionRef,
|
|
7756
|
-
lucid
|
|
7757
|
-
);
|
|
7758
|
-
const stakingManagerOut = stakingManagerRef ? await findStakingManagerByOutRef(stakingManagerRef, lucid) : await findStakingManager(params, lucid);
|
|
7759
|
-
const stakingRefScriptUtxo = matchSingle(
|
|
7760
|
-
await lucid.utxosByOutRef([
|
|
7761
|
-
fromSystemParamsScriptRef(params.scriptReferences.stakingValidatorRef)
|
|
7762
|
-
]),
|
|
7763
|
-
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
7764
|
-
);
|
|
7765
|
-
const indyToken = fromSystemParamsAsset(params.stakingParams.indyToken);
|
|
7766
|
-
const adaReward = calculateAdaReward(
|
|
7767
|
-
stakingManagerOut.datum.managerSnapshot.snapshotAda,
|
|
7768
|
-
stakingPositionOut.datum.positionSnapshot.snapshotAda,
|
|
7769
|
-
assetClassValueOf6(stakingPositionOut.utxo.assets, indyToken)
|
|
7770
|
-
);
|
|
7771
|
-
const newLockedAmount = updateStakingLockedAmount(
|
|
7772
|
-
stakingPositionOut.datum.lockedAmount,
|
|
7773
|
-
BigInt(now)
|
|
7774
|
-
);
|
|
7775
|
-
return lucid.newTx().validFrom(Number(now)).readFrom([stakingRefScriptUtxo]).collectFrom(
|
|
7776
|
-
[stakingPositionOut.utxo],
|
|
7777
|
-
serialiseStakingRedeemer({
|
|
7778
|
-
AdjustStakedAmount: { adjustAmount: amount }
|
|
7779
|
-
})
|
|
7780
|
-
).collectFrom(
|
|
7781
|
-
[stakingManagerOut.utxo],
|
|
7782
|
-
serialiseStakingRedeemer("UpdateTotalStake")
|
|
7783
|
-
).pay.ToContract(
|
|
7784
|
-
stakingManagerOut.utxo.address,
|
|
7785
|
-
{
|
|
7786
|
-
kind: "inline",
|
|
7787
|
-
value: serialiseStakingDatum({
|
|
7788
|
-
...stakingManagerOut.datum,
|
|
7789
|
-
totalStake: stakingManagerOut.datum.totalStake + amount
|
|
7790
|
-
})
|
|
7791
|
-
},
|
|
7792
|
-
addAssets10(stakingManagerOut.utxo.assets, mkLovelacesOf5(-adaReward))
|
|
7793
|
-
).pay.ToContract(
|
|
7794
|
-
stakingPositionOut.utxo.address,
|
|
7795
|
-
{
|
|
7796
|
-
kind: "inline",
|
|
7797
|
-
value: serialiseStakingDatum({
|
|
7798
|
-
...stakingPositionOut.datum,
|
|
7799
|
-
positionSnapshot: {
|
|
7800
|
-
snapshotAda: stakingManagerOut.datum.managerSnapshot.snapshotAda
|
|
7801
|
-
},
|
|
7802
|
-
lockedAmount: newLockedAmount
|
|
7803
|
-
})
|
|
7804
|
-
},
|
|
7805
|
-
addAssets10(stakingPositionOut.utxo.assets, mkAssetsOf8(indyToken, amount))
|
|
7806
|
-
).addSignerKey(toHex10(stakingPositionOut.datum.owner));
|
|
7807
7535
|
}
|
|
7808
|
-
async function
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
]),
|
|
7820
|
-
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
7821
|
-
);
|
|
7822
|
-
const stakingTokenPolicyRefScriptUtxo = matchSingle(
|
|
7823
|
-
await lucid.utxosByOutRef([
|
|
7824
|
-
fromSystemParamsScriptRef(
|
|
7825
|
-
params.scriptReferences.authTokenPolicies.stakingTokenRef
|
|
7536
|
+
async function findAdminInterestCollectors(lucid, sysParams) {
|
|
7537
|
+
return matchSingle3(
|
|
7538
|
+
await lucid.utxosAtWithUnit(
|
|
7539
|
+
createScriptAddress(
|
|
7540
|
+
lucid.config().network,
|
|
7541
|
+
sysParams.validatorHashes.interestCollectionHash
|
|
7542
|
+
),
|
|
7543
|
+
assetClassToUnit3(
|
|
7544
|
+
fromSystemParamsAsset(
|
|
7545
|
+
sysParams.interestCollectionParams.multisigUtxoNft
|
|
7546
|
+
)
|
|
7826
7547
|
)
|
|
7827
|
-
|
|
7828
|
-
(_) => new Error("Expected a single
|
|
7829
|
-
);
|
|
7830
|
-
const indyToken = fromSystemParamsAsset(params.stakingParams.indyToken);
|
|
7831
|
-
const existingIndyAmount = assetClassValueOf6(
|
|
7832
|
-
stakingPositionOut.utxo.assets,
|
|
7833
|
-
indyToken
|
|
7834
|
-
);
|
|
7835
|
-
const adaReward = calculateAdaReward(
|
|
7836
|
-
stakingManagerOut.datum.managerSnapshot.snapshotAda,
|
|
7837
|
-
stakingPositionOut.datum.positionSnapshot.snapshotAda,
|
|
7838
|
-
assetClassValueOf6(stakingPositionOut.utxo.assets, indyToken)
|
|
7548
|
+
),
|
|
7549
|
+
(_) => new Error("Expected a single admin interest collector UTXO")
|
|
7839
7550
|
);
|
|
7840
|
-
return lucid.newTx().validFrom(Number(now)).readFrom([stakingRefScriptUtxo, stakingTokenPolicyRefScriptUtxo]).collectFrom([stakingPositionOut.utxo], serialiseStakingRedeemer("Unstake")).collectFrom(
|
|
7841
|
-
[stakingManagerOut.utxo],
|
|
7842
|
-
serialiseStakingRedeemer("UpdateTotalStake")
|
|
7843
|
-
).pay.ToContract(
|
|
7844
|
-
stakingManagerOut.utxo.address,
|
|
7845
|
-
{
|
|
7846
|
-
kind: "inline",
|
|
7847
|
-
value: serialiseStakingDatum({
|
|
7848
|
-
...stakingManagerOut.datum,
|
|
7849
|
-
totalStake: stakingManagerOut.datum.totalStake - existingIndyAmount
|
|
7850
|
-
})
|
|
7851
|
-
},
|
|
7852
|
-
addAssets10(stakingManagerOut.utxo.assets, mkLovelacesOf5(-adaReward))
|
|
7853
|
-
).mintAssets(
|
|
7854
|
-
mkAssetsOf8(fromSystemParamsAsset(params.stakingParams.stakingToken), -1n),
|
|
7855
|
-
Data33.void()
|
|
7856
|
-
).addSignerKey(toHex10(stakingPositionOut.datum.owner));
|
|
7857
7551
|
}
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
throw new Error("No available collectors found");
|
|
7867
|
-
}
|
|
7868
|
-
const adaRewardCollected = collectorUtxos.reduce(
|
|
7869
|
-
(acc, utxo) => acc + utxo.assets["lovelace"] - MIN_UTXO_AMOUNT,
|
|
7870
|
-
0n
|
|
7871
|
-
);
|
|
7872
|
-
const newSnapshot = distributeReward(
|
|
7873
|
-
stakingManagerDatum.managerSnapshot.snapshotAda,
|
|
7874
|
-
adaRewardCollected,
|
|
7875
|
-
stakingManagerDatum.totalStake
|
|
7876
|
-
);
|
|
7877
|
-
const stakingRefScriptUtxo = matchSingle(
|
|
7878
|
-
await lucid.utxosByOutRef([
|
|
7879
|
-
fromSystemParamsScriptRef(params.scriptReferences.stakingValidatorRef)
|
|
7880
|
-
]),
|
|
7881
|
-
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
7882
|
-
);
|
|
7883
|
-
const collectorRefScriptUtxo = matchSingle(
|
|
7884
|
-
await lucid.utxosByOutRef([
|
|
7885
|
-
fromSystemParamsScriptRef(params.scriptReferences.collectorValidatorRef)
|
|
7886
|
-
]),
|
|
7887
|
-
(_) => new Error("Expected a single staking Ref Script UTXO")
|
|
7552
|
+
async function findRandomNonAdminInterestCollector(lucid, sysParams) {
|
|
7553
|
+
const allCollectors = (await findAllInterestCollectors(lucid, sysParams)).filter(
|
|
7554
|
+
(utxo) => !assetClassValueOf6(
|
|
7555
|
+
utxo.assets,
|
|
7556
|
+
fromSystemParamsAsset(
|
|
7557
|
+
sysParams.interestCollectionParams.multisigUtxoNft
|
|
7558
|
+
)
|
|
7559
|
+
)
|
|
7888
7560
|
);
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
{
|
|
7895
|
-
kind: "inline",
|
|
7896
|
-
value: serialiseStakingDatum({
|
|
7897
|
-
...stakingManagerDatum,
|
|
7898
|
-
managerSnapshot: { snapshotAda: newSnapshot }
|
|
7899
|
-
})
|
|
7900
|
-
},
|
|
7901
|
-
addAssets10(stakingManagerUtxo.assets, mkLovelacesOf5(adaRewardCollected))
|
|
7561
|
+
return F17.pipe(
|
|
7562
|
+
O14.fromNullable(getRandomElement2(allCollectors)),
|
|
7563
|
+
O14.match(() => {
|
|
7564
|
+
throw new Error("Expected some non-admin interest collector UTXOs.");
|
|
7565
|
+
}, F17.identity)
|
|
7902
7566
|
);
|
|
7903
|
-
for (const collectorUtxo of collectorUtxos) {
|
|
7904
|
-
tx.pay.ToContract(
|
|
7905
|
-
collectorUtxo.address,
|
|
7906
|
-
{ kind: "inline", value: Data33.void() },
|
|
7907
|
-
mkLovelacesOf5(MIN_UTXO_AMOUNT)
|
|
7908
|
-
);
|
|
7909
|
-
}
|
|
7910
|
-
return tx;
|
|
7911
7567
|
}
|
|
7912
7568
|
|
|
7913
|
-
// src/contracts/
|
|
7914
|
-
import { Data as
|
|
7915
|
-
var
|
|
7916
|
-
|
|
7917
|
-
stakingToken: AssetClassSchema2,
|
|
7918
|
-
indyToken: AssetClassSchema2,
|
|
7919
|
-
pollToken: AssetClassSchema2,
|
|
7920
|
-
versionRecordToken: AssetClassSchema2,
|
|
7921
|
-
collectorValHash: Data34.Bytes()
|
|
7569
|
+
// src/contracts/version-registry/types.ts
|
|
7570
|
+
import { Data as Data38 } from "@lucid-evolution/lucid";
|
|
7571
|
+
var VersionRecordTokenParamsSchema = Data38.Object({
|
|
7572
|
+
upgradeToken: AssetClassSchema2
|
|
7922
7573
|
});
|
|
7923
|
-
var
|
|
7924
|
-
function
|
|
7925
|
-
return
|
|
7574
|
+
var VersionRecordTokenParams = VersionRecordTokenParamsSchema;
|
|
7575
|
+
function castVersionRecordTokenParams(params) {
|
|
7576
|
+
return Data38.castTo(params, VersionRecordTokenParams);
|
|
7926
7577
|
}
|
|
7927
7578
|
|
|
7928
|
-
// src/contracts/
|
|
7929
|
-
import {
|
|
7930
|
-
fromHex as fromHex11,
|
|
7931
|
-
fromText as fromText7,
|
|
7932
|
-
slotToUnixTime as slotToUnixTime9,
|
|
7933
|
-
toUnit as toUnit2,
|
|
7934
|
-
validatorToAddress
|
|
7935
|
-
} from "@lucid-evolution/lucid";
|
|
7936
|
-
|
|
7937
|
-
// src/contracts/one-shot/transactions.ts
|
|
7579
|
+
// src/contracts/version-registry/scripts.ts
|
|
7938
7580
|
import {
|
|
7939
|
-
|
|
7940
|
-
Data as Data36,
|
|
7941
|
-
mintingPolicyToId,
|
|
7942
|
-
toUnit
|
|
7581
|
+
applyParamsToScript as applyParamsToScript10
|
|
7943
7582
|
} from "@lucid-evolution/lucid";
|
|
7944
7583
|
|
|
7945
|
-
// src/
|
|
7946
|
-
|
|
7947
|
-
|
|
7948
|
-
|
|
7949
|
-
|
|
7950
|
-
|
|
7951
|
-
referenceOutRef: Data35.Object({
|
|
7952
|
-
txHash: Data35.Bytes(),
|
|
7953
|
-
outputIdx: Data35.Integer()
|
|
7954
|
-
}),
|
|
7955
|
-
mintAmounts: Data35.Array(
|
|
7956
|
-
Data35.Object({
|
|
7957
|
-
/// Use hex encoded string
|
|
7958
|
-
tokenName: Data35.Bytes(),
|
|
7959
|
-
amount: Data35.Integer()
|
|
7960
|
-
})
|
|
7961
|
-
)
|
|
7962
|
-
});
|
|
7963
|
-
var OneShotParams = OneShotParamsSchema;
|
|
7964
|
-
function castOneShotParams(params) {
|
|
7965
|
-
return Data35.castTo(params, OneShotParams);
|
|
7966
|
-
}
|
|
7584
|
+
// src/validators/version-record-policy.ts
|
|
7585
|
+
var _versionRecordTokenPolicy = {
|
|
7586
|
+
type: "PlutusScriptV3",
|
|
7587
|
+
description: "Generated by Aiken",
|
|
7588
|
+
cborHex: "5901a159019e010100229800aba2aba1aba0aab9faab9eaab9dab9a488888896600264646644b30013370e900018031baa0018992cc004c032600246018601a003222323322330020020012259800800c00e26464b30013372200c00315980099b8f00600189bad3010002802a01c899802002180a001a01c375c601c00260220028078c8c8cc0040040188966002003003899192cc004cdc8804000c56600266e3c02000626eacc04400a00a807a266008008602a0068078dd718078009809000a02014bd6f7b6300a40013758601660106ea8c02c016601660106ea803922223232330010010042259800800c52f5c113322598009802980498089baa00289980980119802002000c4cc01001000500f18090009809800a0205980099b8748000c02cdd5260103d87980008919b8798009bab3005300d3754003375c6020601a6ea800a6eb8c014c034dd500120084800a2466e21200098009bab3005300d3754003375c6020601a6ea800a6eb8c014c034dd5001200840288a518b2012375c6014600e6ea80062c8028c020004c020c024004c020004c00cdd5004452689b2b200201"
|
|
7589
|
+
};
|
|
7967
7590
|
|
|
7968
|
-
// src/validators/
|
|
7969
|
-
var
|
|
7591
|
+
// src/validators/version-registry-validator.ts
|
|
7592
|
+
var _versionRegistryValidator = {
|
|
7970
7593
|
type: "PlutusScriptV3",
|
|
7971
7594
|
description: "Generated by Aiken",
|
|
7972
|
-
cborHex: "
|
|
7595
|
+
cborHex: "585e585c01010029800aba2aba1aab9eaab9dab9a4888896600264653001300600198031803800cc0180092225980099b8748008c01cdd500144c8cc892818050009805180580098041baa0028b200c180300098019baa0068a4d13656400401"
|
|
7973
7596
|
};
|
|
7974
7597
|
|
|
7975
|
-
// src/contracts/
|
|
7976
|
-
function
|
|
7598
|
+
// src/contracts/version-registry/scripts.ts
|
|
7599
|
+
function mkVersionRecordTokenPolicy(params) {
|
|
7977
7600
|
return {
|
|
7978
7601
|
type: "PlutusV3",
|
|
7979
|
-
script:
|
|
7980
|
-
|
|
7602
|
+
script: applyParamsToScript10(_versionRecordTokenPolicy.cborHex, [
|
|
7603
|
+
castVersionRecordTokenParams(params)
|
|
7981
7604
|
])
|
|
7982
7605
|
};
|
|
7983
7606
|
}
|
|
7607
|
+
var mkVersionRegistryValidator = () => {
|
|
7608
|
+
return {
|
|
7609
|
+
type: "PlutusV3",
|
|
7610
|
+
script: _versionRegistryValidator.cborHex
|
|
7611
|
+
};
|
|
7612
|
+
};
|
|
7984
7613
|
|
|
7985
|
-
// src/contracts/
|
|
7986
|
-
import {
|
|
7987
|
-
async function oneShotMintTx(lucid, params) {
|
|
7988
|
-
const oneShotPolicy = mkOneShotPolicy(params);
|
|
7989
|
-
const policyId = mintingPolicyToId(oneShotPolicy);
|
|
7990
|
-
const refUtxo = matchSingle(
|
|
7991
|
-
await lucid.utxosByOutRef([
|
|
7992
|
-
{
|
|
7993
|
-
txHash: params.referenceOutRef.txHash,
|
|
7994
|
-
outputIndex: Number(params.referenceOutRef.outputIdx)
|
|
7995
|
-
}
|
|
7996
|
-
]),
|
|
7997
|
-
(_) => {
|
|
7998
|
-
throw new Error("Cannot find the reference UTXO for one-shot.");
|
|
7999
|
-
}
|
|
8000
|
-
);
|
|
8001
|
-
return [
|
|
8002
|
-
lucid.newTx().collectFrom([refUtxo]).mintAssets(
|
|
8003
|
-
reduce(
|
|
8004
|
-
{},
|
|
8005
|
-
(acc, entry) => addAssets11(acc, {
|
|
8006
|
-
[toUnit(policyId, entry.tokenName)]: entry.amount
|
|
8007
|
-
})
|
|
8008
|
-
)(params.mintAmounts),
|
|
8009
|
-
Data36.void()
|
|
8010
|
-
).attach.MintingPolicy(oneShotPolicy),
|
|
8011
|
-
policyId
|
|
8012
|
-
];
|
|
8013
|
-
}
|
|
8014
|
-
async function runOneShotMintTx(lucid, params) {
|
|
8015
|
-
const [tx, policyId] = await oneShotMintTx(lucid, params);
|
|
8016
|
-
const txHash = await tx.complete().then((tx2) => tx2.sign.withWallet().complete()).then((tx2) => tx2.submit());
|
|
8017
|
-
await lucid.awaitTx(txHash);
|
|
8018
|
-
return policyId;
|
|
8019
|
-
}
|
|
8020
|
-
|
|
8021
|
-
// src/contracts/interest-oracle/scripts.ts
|
|
8022
|
-
import { applyParamsToScript as applyParamsToScript8 } from "@lucid-evolution/lucid";
|
|
8023
|
-
|
|
8024
|
-
// src/contracts/interest-oracle/types.ts
|
|
8025
|
-
import { Data as Data37 } from "@lucid-evolution/lucid";
|
|
8026
|
-
var InterestOracleParamsSchema = Data37.Object({
|
|
8027
|
-
/** Milliseconds */
|
|
8028
|
-
biasTime: Data37.Integer(),
|
|
8029
|
-
owner: Data37.Bytes()
|
|
8030
|
-
});
|
|
8031
|
-
var InterestOracleParams = InterestOracleParamsSchema;
|
|
8032
|
-
function castInterestOracleParams(params) {
|
|
8033
|
-
return Data37.castTo(params, InterestOracleParams);
|
|
8034
|
-
}
|
|
7614
|
+
// src/contracts/treasury/scripts.ts
|
|
7615
|
+
import { applyParamsToScript as applyParamsToScript11 } from "@lucid-evolution/lucid";
|
|
8035
7616
|
|
|
8036
|
-
// src/validators/
|
|
8037
|
-
var
|
|
7617
|
+
// src/validators/treasury-validator.ts
|
|
7618
|
+
var _treasuryValidator = {
|
|
8038
7619
|
type: "PlutusScriptV3",
|
|
8039
7620
|
description: "Generated by Aiken",
|
|
8040
|
-
cborHex: "5907e05907dd010100229800aba2aba1aba0aab9faab9eaab9dab9cab9a4888888896600264653001300900198049805000cdc3a400530090024888966002600460126ea800e2653001300e00198071807800cdc3a40009112cc004c004c034dd500444c8c8c966002602a00513259800980298089baa001899192cc004c06000a2b300130073013375401119800980b980a1baa008980a1baa00b9180c180c800c896600200310018a9980a0010800a02648888c966002660049201205458206973206e6f74207369676e6564206279206f7261636c65206f776e6572003232330010013758603c603e603e603e603e603e603e603e603e60366ea8048896600200314a115980099b8f375c603e00200714a31330020023020001406480e8dd71801980c9baa01f899912cc004cc011240115496e636f72726563742074782076616c6964697479003322980091192cc004c04c0062b30013013301f375400514c103d87a80008a6103d879800040751598009802000c5660026008603e6ea800a2980103d87a80008a6103d87b800040751332259800980d000c4c96600266e2000c0062980103d87980008acc004cdc4000801c530103d87b80008a6103d87a800040808100dd6981298111baa0048acc004c054006298103d87b80008a6103d8798000407c80f8dd6981198101baa003301f375400480e901d180f1baa002980118101810981098109810981098109810980e9baa014980118019980f98019980f98021980f9ba8337026eb4c01cc074dd500b9bad3020301d375404697ae03301f9800a51a60103d87a8000a60103d8798000406897ae03301f30033301f30043301f375066e00dd69803980e9baa017375a6040603a6ea808d2f5c06603f30014a34c103d87a8000a60103d8798000406897ae04bd702444b300132598009802800c528c566002603200314a314a080f101e180f9baa33003302330203754004604660406ea8006264b300130140018a518acc004c0640062946294101e203c301f375466006601460406ea8008c028c080dd5000c528203a118011980f192cc004c054c070dd5000c4c966002602c603a6ea8c020c078dd51810980f1baa00389802998101ba80014bd7044c014cc080dd419b80001480092f5c080d8dd69810180e9baa0018800a034301f301c3754603e60386ea8004cc078c966002602a60386ea8006264b30013016301d37546010603c6ea8c020c078dd5001c4c014cc080dd4000a5eb822600a660406ea0cdc0000a400297ae0406c6eb4c080c074dd5000c400501a180f980e1baa3006301c375400297ae0370e900244c9660026600a92012643757272656e742074696d652068617320746f206265203e3d206c6173745f736574746c656400337126eb4c004c070dd50041bad3006301c375402d15980099802a492b496e74657265737420726174652068617320746f20626520696e2072616e6765205b30252c20313030255d005980099b8948000dd6980f980e1baa301f301c375402d1337126eb4c07cc070dd5180f980e1baa0164820225ea294101944cc015240120496e746572657374206f7261636c65206f757470757420696e636f72726563740098009bac301f3020302000798019980f18011980f180f980e1baa301f301c37540086603c98103d87a80004bd7025eb8266e9520043301e30023301e375066e00dd6980f980e1baa008325980099b88375a6004603a6ea8024006266e0ccdc199b823370466e04004dd69801180e9baa009375a6040603a6ea8c01cc074dd5004a41010141ede959b7c03690405844fdf500a410112f5153301b4901015a001640686eb4c018c070dd500b1980f180f980e1baa0163301e3006301c375402c97ae04bd704dd59803180e1baa00448888c8c8cc004004018896600200314a1159800992cc004c0100062b30013375e601260486ea800401a2b300133229800992cc004c068c098dd5000c4dd6981398151bab302a302737540031480010241814800cdd58014dd798149815000c89660026040604e6ea930103d87a8000899b890010028acc004cdc480080144cdc480119b80001482026fb80a2941025204a4888966002007159800980100344cc00401120008a50409d1325980099baf4c1014000302a0018acc004cc008014dd6981598171bab302b001898019ba6302f0048a5040a115980099801002a4001130030078a5040a08140c0b400d02b0dd3002994c0040066eacc03cc094dd5001488cc0a4008cc0a4dd3000a5eb810011112cc00400a26600298103d87a80004bd6f7b63044c8cc896600266e452201000028acc004cdc7a441000028998021808198161815001a5eb80006266008980103d87a8000005409d198008034006446600c0046605c00a00280310271bae3027001302c003302a00240a113375e604e60506050605060486ea800530103d87a80008a50408514a0810a29410211813000c528c4cc008008c09c0050202048598009809980f9baa003891919baf302530223754604a60446ea8008004c090c084dd5002448c8cdd7981298111baa00200130243021375400880e914a080ca29410191180f98101810000c5282030374a90011ba548002294101619198008009bac301c0042259800800c5a264b30013375e603c60366ea80040422600a60366ea8006266006006603e00480c0c07400501b22c808a2c80a8dd6980b00098091baa0018b201e30140038b2024375a60260026026002601c6ea80222c805860146ea800e2c8038601200260086ea802629344d95900101"
|
|
7621
|
+
cborHex: "59225f59225c010100229800aba4aba2aba1aba0aab9faab9eaab9dab9cab9a488888888a60022a660049201293c65787065637465643e2045787065637473206f6e6c792073696e676c65206f776e206f757470757400168a998012493b3c65787065637465643e20416c6c20747265617375727920696e70757473206d75737420757365207468652072696768742072656465656d65722e00168a99801249303c65787065637465643e2048617320746f207265666572656e63652073696e676c65206578656375746520696e70757400168a99801249333c65787065637465643e20457870656374732073696e676c65206f757470757420746f207769746864726177616c206164647200168a998012492d3c65787065637465643e20457870656374732073696e676c6520696e7075742066726f6d20747265617375727900164888896600264653001300e00198071807800cdc3a4005300e00248889660026004601c6ea800e33001300f3754007370e90004dc3a4009370e90034dc3a401091111194c00488c9660026010003159800980c1baa00380145901945660026016003159800980c1baa0038014590194566002600e003159800980c1baa0038014590194566002600c003159800980c1baa0038014590194566002600a0031323232329800980f800cdd6980f801cdd6980f8012444b3001302300489980598110038acc004c03cc078dd5001c4c8c8cc8966002604e00700d8b2048375a60480026eb8c090008c090004c07cdd5001c5901c4590200c07c004c078004c074004c060dd5001c56600266e1d200a0018acc004c060dd5001c00a2c80ca2c80a9015202a405480a9015180b1baa002980c180c8034c0600192223300300d198009180e180e800c888c8cc88cc0080080048966002003003899192cc004cdc8803000c56600266e3c01800626eb4c08000a00a80ea266008008604800680e8dd7180f0009810800a03e3232330010010062259800800c00e26464b30013372201000315980099b8f00800189bab3021002802a03c8998020021812801a03c375c603e0026044002810052f5bded8c029000488c8cc00400400c896600200314bd7044cc8966002600a00513302000233004004001899802002000a036301f00130200014075371090004966002601060306ea80062603860326ea80062c80b246038603a603a00322323300100100322330030013002002980b9baa00d912cc004006200315330180021001405d2598009804980c1baa001891919baf301e301b3754603c60366ea8008004c074c068dd5001448c8cdd7980f180d9baa002001301d301a375400480b26e9520009180e180e980e980e800cdd7a6103d87a800091111919800800802912cc00400626604066ec0dd48029ba60044bd6f7b63044c8cc896600266e4402000a2b30013371e010005198008044dd59810801c01e46604866ec0dd48049ba60010028800a00c89981199bb037520106e9801c01101e44cc08c00ccc01401400501e1bae301e00130230023021001407d222232330010010052259800800c4cc080cdd81ba9005375000897adef6c6089919912cc004cdc8804001456600266e3c02000a330010089bad3021003803c8cc090cdd81ba9009375000200510014019133023337606ea4020dd4003802203c89981180199802802800a03c375c603c0026046004604200280fa244444b30013370e00866e052000003800c4c008cdc0002001a0349baf4c0101a0009111919800800802112cc004006200913298009bae301d0019bab301e00199801801981100120083020001407922232330010010042259800800c40122653001375c603a003375a603c0033300300330220024010604000280f244b3001300a30193754005132323322598009811001c0162c80f8dd6980f8009bad301f002301f001301a375400516405d2232598009805800c4c8c96600260420050048b203c375c603e00260366ea800e2b3001300e0018acc004c06cdd5001c00a2c80e22c80c1018180c9baa00291192cc004c02c00626464b3001302100280245901e1bae301f001301b37540071598009807000c4c8c96600260420050048b203c375c603e00260366ea800e2c80c1018180c9baa002911980e19bb037520046ea00052f5bded8c122232330010010042259800800c4012266006604000266004004604200280f26e9520024888888888888888888888888a600244646600200200644b30010018b44c96600266ebcc0e4c0d8dd500080244c078c0d8dd5000c4cc00c00cc0e8009033181c000a06c911191980d80211801180f181b1baa00159800981218199baa0018918144c004dd5980e981a9baa0019bae303830353754007375c603a606a6ea800d01c448c06a60026eacc074c0d4dd5000cdd7181c181a9baa0039bae301d3035375400680e10314888cc8a600264b30013027303637540031375a606e60746eacc0e8c0dcdd5000c5200040d060720033756005375e6072607400322598009815981b9baa005899b890010028acc004cdc480080144cdc480119b80001482026fb80a2941035206a4888966002007159800980100344cc00401120008a5040dd1325980099baf4c01014000303a0018acc004cc008014dd6981d981f1bab303b001898019ba6303f0048a5040e115980099801002a4001130030078a5040e081c0c0f400d03b0dd3001194c004006009223303900233039374c00297ae04004444b3001002899800a6103d87a80004bd6f7b63044c8cc896600266e452201000028acc004cdc7a44100002899802180c1981e181d001a5eb80006266008980103d87a800000540dd198008034006446600c0046607c00a00280310371bae3037001303c003303a00240e1223301900223375e606e60686ea8c0dcc0d0dd5180e181a1baa00100291194c0040060070024004444b30010028800c4ca6002009303b003cc00400a6eb8c0d80066eacc0dc0064444464b30013015374c00300289801800a07432329800800c01a00a80088896600200510018994c004012608a00798008014dd71820000cdd69820800c01501b200830430024104a02a8091004181c801206e911980c8011809000ca60020034bd70488a60020050019111981d1ba73303a375200c660746ea400ccc0e8dd400125eb8000500b201291192cc004c090006264b30013039001899805181c000801c59036181a1baa0038acc004c09c006264b30013039001899810981c000801c59036181a1baa0038acc004c08c00626464b3001303a0028024590371bae3038001303437540071640c4818903118191baa002911192cc004c09400626464b3001303b0028024590381bae3039001303537540071598009814000c4c8cc8966002607800313301a3758607600244b3001002803c66002013303d00289800981f001201240ed1640e46eb4c0e4004c0e8004c0d4dd5001c590322064303337540052232598009812000c4c9660026072003132598009813181a9baa00189919192cc004c0f400a26644b3001302b303a3754005132323259800982100144cc044c10400c4c966002605e003132598009822000c4c8c9660026064003132598009823800c4cc058c1180040262c8220c108dd50014566002606a003132323298009bad30480019bad30480039bad3048002488966002609800900e8b20921824000982380098211baa0028b207e40fc60806ea8004c10c0062c8208c0fcdd500145660026064003159800981f9baa002802c5904045903c2078303d37540031640fc6080002608000260766ea800a2c81c0c0f000c4cc06c00489660020050098992cc004c0b0c0ecdd5000c4c8c8ca60026eb4c1080066eb8c10800e6eb8c10800922259800982300244c020c1180262c82186084002608200260786ea80062c81c8c0f800903c45903a1bac303b001303b001303637540031640cc60700031640d860686ea800e2b300130270018acc004c0d0dd5001c00a2c81aa2c818903118191baa00291112cc004c094006200919800802400e6600e00400322222325980098099ba600180144c00c0050384c00401200f006a809a0284040819122222222222980091111191919800800803912cc00400629422b300132598009802000c56600266ebcc0a0c114dd5000803c56600330013756605a608a6ea800600d00540491302130223045375400314a0821229410424528208430470018a518998010011824000a08241146040009222225980099810002002c56600266ebcc090c104dd5002801c56600330013756605260826ea801600500140391301d301e3041375400b14a081f2294103e4528207c9801801ca60020034bd6f7b630488c8ca6002007375c6088005375c6088003375a6088608a0028030c110004c0fcdd5001201c48888c9660026062045132323259800800c0f22b300130480018992cc004c12400626464b3001303730463754003132323232323298009828000cdd698280024dd69828001cdd6982800124444b3001305500589919809182a80509980c0028acc004c108c144dd5002c4c8cc896600200304e8992cc004c16800a2b300133036491205769746864726177616c2076616c75652063616e6e6f7420626520656d70747900980098171ba6003a50a51414d1598009981b2481245472656173757279207769746864726177616c206f757470757420696e636f7272656374009800800cc098cc160c164c158dd500225eb8266e95200433058374e660b098011a5818496e6469676f54726561737572795769746864726177616c003305830593056375402297ae04bd70400e980103d87a800040651325980098179ba60018a518acc004c8cc004004c084008896600200314a115980099b88375a60b860ba60ba6eb0c17000520008a51899801001182e800a0ac416915330554901224e6f7420656e6f7567682066756e647320696e20747265617375727920696e707574001689981ba4811c5472656173757279206f757470757420697320696e636f72726563740098009bac303a3057375409330273305930353305901533059303a305737540bc97ae04bd70530107d87b9fd87980ff00800d300103d87a8000406c82a1054198109bab303e3056375402a646600200200844b30010018a5eb7bdb182264660b666ec0c160004dd319198008009bab305a0022259800800c52f5bded8c11323305e3376060b60026ea0cdc0a40006eb4c170004cc00c00cc180008c17800505c19801801982e801182d800a0b28a50414d14a0829a09e82b8c160005056180a1bac303b305337540026603a6eb0c0d8c14cdd502298119982a982b18299baa0014bd70182a98291baa0058b209e375a60a80151641483050001304f001304e001304d001304c0013047375400316411060546052608c6ea8c0b8c118dd50009824000c590464c004dd6182398221baa036982398221baa04ba60103d8798000404903c41148228cc03cdd6182318219baa035001304530423754608a60846ea8004cc040dd6182218209baa03302a8cc004dc0240052304530463046304630463046304630463046304600194c00400691100a4410040a5371090012444464b3001303902789919912cc00400608713259800982700144c966002607660946ea80062646464646465300130540019bad30540049bad30540039bad3054002488896600260b200b13233016305900a13301c005132598009823982b1baa006899192cc004ca6002003375860ba60b46ea81326eacc060c168dd5026528a002222259800801c400626644b30013052305e375460c460be6ea8c188c17cdd51823982f9baa0028994c00401e005375660c660c8003325980099baf30643061375460c860c26ea8c124c184dd500200dc566002003159800982a18301baa0018acc004c184dd5000c40160b883120b882f20b905c82e41710664401505e1831800a00e32330010010052259800800c5a265300130610019831000cc1980092225980099baf00330353306730683065375401097ae0899833801198339ba60014bd7044cc0180180050620c19000506246600200d001802400d00620b83060003306100341791598009981ca493d43616e6e6f742062652075736564207768656e207769746864726177616c2076616c7565206861732073696e676c65206173736574206f72206e6f6e650030150018acc004cc0e52412e43616e6e6f742062652075736564207769746820617373657473206e6f7420746f2062652077697468647261776e003370e6028006b3001303e30160028800c4c0600050564566002660729201374f6e65206f75747075742068617320746f2068617665207468652076616c7565206f662074726561737572795f7769746864726177616c0098009bac303c3059375409730293305b0124bd70530107d87b9fd87980ff008015300103d87a80004075133039490123416c6c207370656e742076616c75652068617320746f2062652070616964206261636b009800cc004dd6181e182c9baa04ba5eb7bdb18244b30013375e60bc60b66ea8c178c16cdd500100ac56600266ebcc0f8c16cdd500126107d87b9fd87980ff008998130009bab3043305b375400515330594912f3c65787065637465643e20416c6c206f776e206f757470757473206d757374206861766520766f696420646174756d001641611001416081520074c103d87a8000409914a082b22941056452820ac8a504158602600260306eb0c0fcc15cdd5182d182b9baa0068b20a898009bac3059305637540914bd6f7b6304896600266ebcc16cc160dd5182d982c1baa3040305837540040251330230013756608060b06ea8c100c160dd500144005055204e375a60b001516415830540013053001305200130510013050001304b3754003164120605c605a60946ea8c0c8c128dd5000c11104b1826000a09430253304900133049302a3047375409c97ae098009bac302f30473754073304a3047375409d4c0103d879800040546092608c6ea8c124c118dd51980a9bac30493046375407005f1323259800981b814c4c8ca600260506609800266098605a60946ea81452f5c1232330010010022259800800c52f5bded8c113233225980099b91489000028acc004cdc7a441000028800c401104d44cc14800ccc01401400504d1bae304d0013052002305000141393756606460946ea80092225980098289980c9bac3050304d375407e009132325980099817a495d416c6c20696e70757473206d7573742068617665206d6f7265207468616e2031206e6f6e2d414441206173736574206f722031206e6f6e2d41444120617373657420616e64206d6f7265207468616e20327820414441206275666665720032598009806000c528c566002608600313371090405b6e0298068024528209a41346014600800715980099817a492f416c6c207468652076616c7565206e6565647320746f2062652073656e74206261636b20746f207472656173757279009800800c00e98103d87a8000407113302f49012354686572652063616e2062652031206f75747075742077697468206f6e6c7920414441003371266e04c020008dd698294c004c010006660a2981010000330513032304f375408297ae09114c00400a0032223259800cc004c164006604c660b001897ae0a60107d87b9fd87980ff00acc004c11800e297adef6c6089982c19bb0375200e6e98cc0a001000d2f5bded8c0829a98103d879800040651330583750602a6eb4c164008cc160dd3982d000a5eb822a660a8921593c65787065637465643e2045616368206e6f6e204144412061737365742069732073657061726174656420696e746f20697473206f776e20636f6e74696e75696e67206f7574707574207769746820766f696420646174756d0016414c6eb0c160c164005028204c4800a294104c452820989800800d2f5bded8c1223301b0013756607060a06ea800901f1980b9bac3030304d375407e603a6609e00697ae08b209c182618249baa304c304937540026602e6eb0c12cc120dd501d018c566002606c05313233229800cc00400697adef6c60911980c0009bab3035304d3754606a609a6ea800901c4cc054dd6181718259baa03d301b3304d0024bd70488c8cc00400400c896600200314a315980098019829000c4cc008008c14c006294104c20a048896600200504a8992cc004c14c00e2b30013302f4912d416c6c206f776e20696e70757473206861766520746f20757365207468652072696768742072656465656d657200330020052323303c00113375e002980103d87c80003232330010013756602060a46ea811088c96600266ebc010c14c006260a80031330030033058002414460ac0026040660a460a660a06ea80052f5c115980099817a4812554686572652068617320746f206265206174206c656173742032206f776e20696e7075747300300b30080058acc004cc0bd2411c5472656173757279206f757470757420697320696e636f7272656374009800800cc07ccc1440192f5c14c107d87b9fd87980ff008025300103d87a8000404913302f490132416c6c20696e70757473206861766520746f20636f6e7461696e207468652073616d65206d657267696e6720617373657473003233003006232330010010032259800800c528c56600264607330013756607860a86ea8c0f0c150dd50024dd7182b800cdd7182b982c000a076375860ac00313300200230570018a50414082a0c060012294104c452820988a50413104b414060a20048278604e6609600266096605860926ea81412f5c06602a6eb0c130c124dd501d800982598241baa304b304837546602e6eb0c12cc120dd501d018c566002606a053132323298009bad304e00198271827800ccc068dd6182718259baa03d0349827001cdd698270012444446644b30013303249116546f6f206d616e7920617373657420636c61737365730033712601a004900245660026606492011c436f6c6c656374656420616d6f756e7420697320706f7369746976650059800981b801c4cdc4a400000f14a0827a26606492011c5472656173757279206f757470757420697320696e636f72726563740098009bac30353052375408930223305430303305430553052375460aa60a46ea8014cc150c0d4c148dd502ca5eb812f5c13374a90021982a18181982a18181982a01da5eb80cc1500192f5c097ae0801530103d87a8000405914a0827a294104f4c00660026eacc0e0c140dd5001cdd7182998281baa0029bae303830503754005001405548900a44100802a02a3233001001375860a860a26ea810c896600266ebcc154c148dd5182a8008034526899801001182b000a09e1827000982680098241baa03d89919912cc004c0f8c128dd5000c4cc896600260a200313259800981f18269baa00189919912cc004c1540062660666eb0c150004896600200513259800982218299baa0018991925159800991980080098069bab3059305a305a305a305a3056375409044b30013371e6eb8c16800400e294626600400460b600282a22934590521bae30573054375400316414464660020026eb0c0f0c150dd5003912cc0040062980103d87a80008992cc006600260640034a14a2829a2003133003003305a002414c64b30013371e6eb8c16400402e26068660b060b260b400297ae08a6103d87a8000414c6eb0c16000505644c8c8cc896600260b600713005305b0068b20b0375c60b00026eb8c160008c160004dd6182b00120a88b20a4375a60a400260a6002609c6ea80062c8258c0c4c0c0c134dd5181a98269baa30500018b209c375c609c60966ea800660026eb0c0ccc12cdd501ecc0ccc12cdd5029530103d879800040651641206002002609860926ea8c130c124dd51980c1bac304c3049375407606444b30010018a5eb822660986092609a00266004004609c0028259045208a4114600200244b30010018a40011300733002002304c001412482188c8cc0040040088966002003148002266453001375c6092005375660940052259800800c400e2646644601c6600a00a60a60086eb8c130004dd698268009827800a09a4888cc0040040086096002660040046098002824881f088c9660026066003132598009824000c4c966002606a60886ea800626464646464653001304e0019bae304e00698270024c13800e609c004911112cc004c15001a26604a60a601426604a00626604a00426604a00226604a00a01f164144304e001304d001304c001304b001304a00130453754003164108608e00316411460866ea800e2b300130360018992cc004c120006264b3001303530443754003132323232323298009827000cdd718270034c138012609c007304e0024888896600260a800d133025305300a13302500313302500213302500113302500500f8b20a21827000982680098260009825800982500098229baa0018b208430470018b208a304337540071598009819000c4c966002609000313259800981a98221baa00189919191919191919194c004dd69828800cdd71828804cdd69828803cc14401a60a200b30510049828801cc1440092222222259800982d004c4cc108c1640404cc0780144cc1080104cc0ac00c4cc0ac0084cc0ac0040562c82b860a200260a0002609e002609c002609a002609800260960026094002608a6ea80062c8210c11c0062c8228c10cdd5001c5660026062003132598009824000c4c966002606a60886ea800626464646464646464653001375a60a2003375c60a2013375a60a200f30510069828802cc14401260a200730510024888888896600260b4013133042305901013301e00513304200413302b00313302b00213302b0010158b20ae1828800982800098278009827000982680098260009825800982500098229baa0018b208430470018b208a304337540071598009818000c4c966002609000313259800981a98221baa00189919191919191919194c004dd71828800cdd71828804cc14401e60a200d305100598288024dd69828801cdd69828801244444444b3001305a009899821182c80809981580309981580289981580209981500180ac590570c144004c140004c13c004c138004c134004c130004c12c004c128004c114dd5000c590421823800c5904518219baa0038acc004cdc3a4014003132598009824000c4c966002606a60886ea8006264646464646464646464653001375c60a6003375c60a6017305300998298044c14c01e64b300130510018acc004cdc4a400860a000316898221828000a09c8b20a4375460a600d32598009828800c56600266e25200430500018b44c110c14000504e4590521baa305300598298024dd69829801cdd6982980124444444444b3001305e00b899823182e80a09981780409981780389981780309981700180cc5905b0c14c004c148004c144004c140004c13c004c138004c134004c130004c12c004c128004c114dd5000c590421823800c5904518219baa0038acc004cdc3a4018003132598009824000c4c966002606a60886ea80062646464646464646464646465300130540019bad305400c9bad305400b9bad305400a9bad30540099bad30540089bad30540079bad30540069bad30540059bad30540049bad30540024888888888896600260c0019133030305f00e13301e00b01b8b20ba182a000982980098290009828800982800098278009827000982680098260009825800982500098229baa0018b208430470018b208a3043375400715980099b8748038006264b300130480018992cc004c0d4c110dd5000c4c8cc8966002609800313302a3758609600244b3001002804c4c8cc896600260a200313259800981f18269baa001899192cc004c15000a2600e60a80111641446eb8c148004c138dd5000c5904b1828000c5904e1bae304e001304f0013758609a004825a2c8248dd69824800982500098229baa0018b208430470018b208a3043375400715980099b874804000626464b300130490028024590461bae30470013043375400716410082010402080410082010402080410060826ea800808966002600c602a6ea800a264646644b3001301e003802c5901b1bae301b001375c60360046036002602c6ea800a2c8099164030300e0013009375401f149a26cac80301"
|
|
8041
7622
|
};
|
|
8042
7623
|
|
|
8043
|
-
// src/contracts/
|
|
8044
|
-
|
|
7624
|
+
// src/contracts/treasury/types.ts
|
|
7625
|
+
import { Data as Data39 } from "@lucid-evolution/lucid";
|
|
7626
|
+
var TreasuryParamsSchema = Data39.Object({
|
|
7627
|
+
upgradeToken: AssetClassSchema2,
|
|
7628
|
+
versionRecordToken: AssetClassSchema2,
|
|
7629
|
+
treasuryUtxosStakeCredential: Data39.Nullable(StakeCredentialSchema)
|
|
7630
|
+
});
|
|
7631
|
+
var TreasuryParams = TreasuryParamsSchema;
|
|
7632
|
+
function castTreasuryParams(params) {
|
|
7633
|
+
return Data39.castTo(params, TreasuryParams);
|
|
7634
|
+
}
|
|
7635
|
+
|
|
7636
|
+
// src/contracts/treasury/scripts.ts
|
|
7637
|
+
var mkTreasuryValidatorFromSP = (params) => {
|
|
8045
7638
|
return {
|
|
8046
7639
|
type: "PlutusV3",
|
|
8047
|
-
script:
|
|
8048
|
-
|
|
7640
|
+
script: applyParamsToScript11(_treasuryValidator.cborHex, [
|
|
7641
|
+
castTreasuryParams({
|
|
7642
|
+
upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
|
|
7643
|
+
versionRecordToken: fromSystemParamsAssetLucid(
|
|
7644
|
+
params.versionRecordToken
|
|
7645
|
+
),
|
|
7646
|
+
treasuryUtxosStakeCredential: params.treasuryUtxosStakeCredential ? fromSysParamsStakeCredential(params.treasuryUtxosStakeCredential) : null
|
|
7647
|
+
})
|
|
8049
7648
|
])
|
|
8050
7649
|
};
|
|
8051
|
-
}
|
|
7650
|
+
};
|
|
8052
7651
|
|
|
8053
|
-
//
|
|
7652
|
+
// src/contracts/treasury/queries.ts
|
|
7653
|
+
import { option as O15, function as F18 } from "fp-ts";
|
|
8054
7654
|
import {
|
|
8055
|
-
assetClassToUnit as
|
|
7655
|
+
assetClassToUnit as assetClassToUnit4,
|
|
7656
|
+
assetClassValueOf as assetClassValueOf7,
|
|
7657
|
+
getRandomElement as getRandomElement3
|
|
8056
7658
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
8057
|
-
async function
|
|
8058
|
-
return lucid.
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
// src/contracts/interest-oracle/transactions.ts
|
|
8062
|
-
async function startInterestOracle(initialUnitaryInterest, initialInterestRate, initialLastInterestUpdate, oracleParams, lucid, interestTokenName, withScriptRef = false, refOutRef) {
|
|
8063
|
-
const network = lucid.config().network;
|
|
8064
|
-
const tokenName = interestTokenName ?? "INTEREST_ORACLE";
|
|
8065
|
-
if (!refOutRef) {
|
|
8066
|
-
refOutRef = (await lucid.wallet().getUtxos())[0];
|
|
8067
|
-
}
|
|
8068
|
-
const [tx, policyId] = await oneShotMintTx(lucid, {
|
|
8069
|
-
referenceOutRef: {
|
|
8070
|
-
txHash: refOutRef.txHash,
|
|
8071
|
-
outputIdx: BigInt(refOutRef.outputIndex)
|
|
8072
|
-
},
|
|
8073
|
-
mintAmounts: [
|
|
8074
|
-
{
|
|
8075
|
-
tokenName: fromText7(tokenName),
|
|
8076
|
-
amount: 1n
|
|
8077
|
-
}
|
|
8078
|
-
]
|
|
7659
|
+
async function findAllTreasuryUtxos(lucid, sysParams) {
|
|
7660
|
+
return lucid.utxosAt({
|
|
7661
|
+
type: "Script",
|
|
7662
|
+
hash: sysParams.validatorHashes.treasuryHash
|
|
8079
7663
|
});
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
getOnChainInt: initialInterestRate
|
|
8089
|
-
},
|
|
8090
|
-
lastUpdated: initialLastInterestUpdate
|
|
8091
|
-
})
|
|
8092
|
-
},
|
|
8093
|
-
{
|
|
8094
|
-
lovelace: 2500000n,
|
|
8095
|
-
[toUnit2(policyId, fromText7(tokenName))]: 1n
|
|
8096
|
-
}
|
|
7664
|
+
}
|
|
7665
|
+
async function findRandomTreasuryUtxo(lucid, sysParams) {
|
|
7666
|
+
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
7667
|
+
return F18.pipe(
|
|
7668
|
+
O15.fromNullable(getRandomElement3(treasuryUtxos)),
|
|
7669
|
+
O15.match(() => {
|
|
7670
|
+
throw new Error("Expected some treasury UTXOs.");
|
|
7671
|
+
}, F18.identity)
|
|
8097
7672
|
);
|
|
8098
|
-
if (withScriptRef) {
|
|
8099
|
-
tx.pay.ToAddressWithData(
|
|
8100
|
-
validatorToAddress(network, validator),
|
|
8101
|
-
void 0,
|
|
8102
|
-
void 0,
|
|
8103
|
-
validator
|
|
8104
|
-
);
|
|
8105
|
-
}
|
|
8106
|
-
return [
|
|
8107
|
-
tx,
|
|
8108
|
-
{
|
|
8109
|
-
currencySymbol: fromHex11(policyId),
|
|
8110
|
-
tokenName: fromHex11(fromText7(tokenName))
|
|
8111
|
-
}
|
|
8112
|
-
];
|
|
8113
7673
|
}
|
|
8114
|
-
async function
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
utxo = await findInterestOracle(lucid, assetClass);
|
|
8119
|
-
}
|
|
8120
|
-
const network = lucid.config().network;
|
|
8121
|
-
const now = BigInt(slotToUnixTime9(network, currentSlot));
|
|
8122
|
-
const tx = lucid.newTx();
|
|
8123
|
-
const datum = parseInterestOracleDatum(getInlineDatumOrThrow(utxo));
|
|
8124
|
-
if (scriptRef2) {
|
|
8125
|
-
tx.readFrom([scriptRef2]);
|
|
8126
|
-
} else {
|
|
8127
|
-
tx.attach.Script(mkInterestOracleValidator(params));
|
|
8128
|
-
}
|
|
8129
|
-
tx.collectFrom(
|
|
8130
|
-
[utxo],
|
|
8131
|
-
serialiseFeedInterestOracleRedeemer({
|
|
8132
|
-
newInterestRate: {
|
|
8133
|
-
getOnChainInt: newInterestRate
|
|
8134
|
-
},
|
|
8135
|
-
currentTime: now
|
|
8136
|
-
})
|
|
7674
|
+
async function findRandomTreasuryUtxoWithOnlyAda(lucid, sysParams) {
|
|
7675
|
+
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
7676
|
+
const adaOnlyTreasuryUtxos = treasuryUtxos.filter(
|
|
7677
|
+
(utxo) => Object.keys(utxo.assets).length == 1
|
|
8137
7678
|
);
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
{
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
unitaryInterest: datum.unitaryInterest + calculateUnitaryInterestSinceOracleLastUpdated(now, datum),
|
|
8144
|
-
interestRate: {
|
|
8145
|
-
getOnChainInt: newInterestRate
|
|
8146
|
-
},
|
|
8147
|
-
lastUpdated: now
|
|
8148
|
-
})
|
|
8149
|
-
},
|
|
8150
|
-
utxo.assets
|
|
7679
|
+
return F18.pipe(
|
|
7680
|
+
O15.fromNullable(getRandomElement3(adaOnlyTreasuryUtxos)),
|
|
7681
|
+
O15.match(() => {
|
|
7682
|
+
throw new Error("Expected some treasury UTXOs.");
|
|
7683
|
+
}, F18.identity)
|
|
8151
7684
|
);
|
|
8152
|
-
tx.validFrom(Number(now) - ONE_SECOND);
|
|
8153
|
-
tx.validTo(Number(now + params.biasTime) - ONE_SECOND);
|
|
8154
|
-
tx.addSignerKey(params.owner);
|
|
8155
|
-
return tx;
|
|
8156
7685
|
}
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
|
|
8163
|
-
|
|
8164
|
-
|
|
8165
|
-
|
|
8166
|
-
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
}
|
|
7686
|
+
async function findRandomTreasuryUtxoWithAsset(lucid, sysParams, asset, max_number_of_assets = 2n) {
|
|
7687
|
+
const treasuryUtxos = await lucid.utxosAtWithUnit(
|
|
7688
|
+
{ hash: sysParams.validatorHashes.treasuryHash, type: "Script" },
|
|
7689
|
+
assetClassToUnit4(asset)
|
|
7690
|
+
);
|
|
7691
|
+
const validTreasuryUtxos = treasuryUtxos.filter(
|
|
7692
|
+
(utxo) => Object.keys(utxo.assets).length <= max_number_of_assets
|
|
7693
|
+
);
|
|
7694
|
+
return F18.pipe(
|
|
7695
|
+
O15.fromNullable(getRandomElement3(validTreasuryUtxos)),
|
|
7696
|
+
O15.match(() => {
|
|
7697
|
+
throw new Error("Expected some treasury UTXOs.");
|
|
7698
|
+
}, F18.identity)
|
|
7699
|
+
);
|
|
8172
7700
|
}
|
|
8173
|
-
|
|
8174
|
-
|
|
8175
|
-
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8182
|
-
cdpAssetSymbol: Data38.Bytes(),
|
|
8183
|
-
cdpBiasTime: Data38.Integer(),
|
|
8184
|
-
interestSettlementCooldown: Data38.Integer()
|
|
8185
|
-
});
|
|
8186
|
-
var InterestCollectionParams = InterestCollectionParamsSchema;
|
|
8187
|
-
function castInterestCollectionParams(params) {
|
|
8188
|
-
return Data38.castTo(params, InterestCollectionParams);
|
|
7701
|
+
async function findAllTreasuryUtxosWithNonAdaAsset(lucid, sysParams, includeDaoToken = true) {
|
|
7702
|
+
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
7703
|
+
const treasuryUtxosWithNonAdaAsset = treasuryUtxos.filter(
|
|
7704
|
+
(utxo) => Object.keys(utxo.assets).length !== 1 && (includeDaoToken ? true : assetClassValueOf7(
|
|
7705
|
+
utxo.assets,
|
|
7706
|
+
fromSystemParamsAsset(sysParams.govParams.daoIdentityToken)
|
|
7707
|
+
) === 0n)
|
|
7708
|
+
);
|
|
7709
|
+
return treasuryUtxosWithNonAdaAsset;
|
|
8189
7710
|
}
|
|
8190
7711
|
|
|
8191
|
-
// src/contracts/
|
|
8192
|
-
import {
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
7712
|
+
// src/contracts/collector/scripts.ts
|
|
7713
|
+
import {
|
|
7714
|
+
applyParamsToScript as applyParamsToScript12,
|
|
7715
|
+
Constr as Constr2,
|
|
7716
|
+
fromText as fromText7
|
|
7717
|
+
} from "@lucid-evolution/lucid";
|
|
7718
|
+
|
|
7719
|
+
// src/validators/collector-validator.ts
|
|
7720
|
+
var _collectorValidator = {
|
|
8196
7721
|
type: "PlutusScriptV3",
|
|
8197
7722
|
description: "Generated by Aiken",
|
|
8198
|
-
cborHex: "59202059201d010100229800aba2aba1aba0aab9faab9eaab9dab9cab9a488888888cc896600264653001300b00198059806000cdc3a4005300b0024888966002600460166ea800e33001300c3754007370e90034dc3a4001370e90024c02cdd5002244444646644b300130060048acc004c050dd5006400a2c80aa2b3001300a0048991919194c004dd6980d800cdd6980d8024dd6980d801cdd6980d80124444b3001302000580545901d0c06c004c068004c064004c050dd50064566002600a009159800980a1baa00c8014590154566002600e009159800980a1baa00c801459015456600266e1d20080048acc004c050dd5006400a2c80aa2c8089011202240448088660024602c602e003259800980218091baa0018980b18099baa0018b20209180b180b980b980b980b800c888c8cc88cc0080080048966002003003899192cc004cdc8803000c56600266e3c01800626eb4c06800a00a80ba266008008603c00680b8dd7180c000980d800a0323232330010010062259800800c00e26464b30013372201000315980099b8f00800189bab301b002802a030899802002180f801a030375c6032002603800280d052f5bded8c029000488c8cc00400400c896600200314bd7044cc8966002600a00513301a00233004004001899802002000a02a3019001301a001405d3710900048c058c05cc05c00644646600200200644660060026004005301137540152259800800c40062a660240042002808a4602c602e602e602e602e602e602e602e602e602e003374a90012444444444444653001222323300d00423002301230243754002b300130143021375400312330053756602260466ea800400e24601930013756602260466ea80066eb8c098c08cdd5001cdd7180898119baa003403880fa4466016004466ebcc094c088dd5181298111baa3010302237540020052232330010010032259800800c5a264b30013375e604e60486ea80040122602460486ea800626600600660500048108c0980050242444b300130140088cc00488c966002602e0031323259800981580140122c8140dd6981480098129baa0038acc004c06c00626464b3001302b0028024590281bad302900130253754007159800980b000c566002604a6ea800e005164099164088811102218119baa002980518111baa028980818111baa028998009bac30253022375402e0229111192cc0040060451598009815800c4c9660020030248992cc004c0b400a2646644b3001301e00189919194c004dd69819000cc0cc0066eb4c0c800e6eb4c0c8009222259800981b801c4cc044c0d800c0262c81a06064002606200260586ea800e2b30013022001899192cc004c0c800a0091640bc6eb4c0c0004c0b0dd5001c566002603a00315980098161baa00380145902d4566002603e0031323322598009819800c4cc034c0c80040162c8180dd69818000981880098161baa0038acc004cdc3a401000315980098161baa00380145902d456600266e1d200a0018992cc004c0c4006264b30013020302d375400313232332259800981b001c0222c8198dd698198009bae30330023033001302e37540031640ac60600031640b860586ea800e2b30013370e9006000c56600260586ea800e0051640b515980099b874803800626464b3001303200280245902f1bad3030001302c375400715980099b874804000626464b3001303200280245902f1bad3030001302c375400715980099b87480480062b3001302c37540070028b205a8b205240a48149029205240a48149029205240a42b30013300f4901205370656e74205554784f2063616e6e6f7420686176652061646d696e204e4654009800998061bab3018302a375400a00d4a14a2813a26601e9212b43445020696e70757420646f6573206e6f74206861766520616e20616c6c6f7765642072656465656d6572003259800980e800c528c566002604200314a3159800980e000c528c56600266e1d200c0018a518a5040a0814102820503029375400314a08138c0a4dd50009919198008009bab300f302b37540404464b30013375e00860580031302d00189980180198188012054302f001300c3302b302c3029375400297ae0812a054302b00140a5300137586054604e6ea80720094c103d87a8000402102240a08140cc018dd6181498131baa01b3029302637546052604c6ea80051980092cc004c054c088dd5000c48c8cdd7981418129baa302830253754004002604e60486ea800a246466ebcc0a0c094dd5001000981398121baa0024081374a900048c098c09cc09cc09c0064464b30013017001899192cc004c0ac00a0091640a06eb8c0a4004c094dd5001c566002603600315980098129baa0038014590264590222044302337540053700900124444464b3001301e00e8cc004c0a0dd501048966002603860526ea800a264646644b30013032003802c5902f1bae302f001375c605e004605e00260546ea800a2c813a44b3001301c30293754005132323322598009819001c0162c8178dd698178009bad302f002302f001302a375400516409d223259800980e800c566002603a60546ea800a2980103d87a80008a6103d879800040a1159800980e000c566002603860546ea800a2980103d87a80008a6103d87b800040a113322598009811800c4c96600266e2000c0062980103d87980008acc004cdc4000801c530103d87b80008a6103d87a800040ac8158dd6981818169baa0048acc004c07c006298103d87b80008a6103d879800040a88150dd6981718159baa003302a3754004814102818149baa0029180319815992cc004c080c0a4dd5000c4c966002604260546ea8c064c0acdd5181718159baa00389807198169ba80014bd7044c038cc0b4dd41802800a5eb810281bad302d302a37540031001409c605860526ea8c0b0c0a4dd500099815992cc004c080c0a4dd5000c4c966002604260546ea8c064c0acdd5180c98159baa00389807198169ba80014bd7044c038cc0b4dd419b80001480052f5c08140dd6981698151baa0018800a04e302c30293754602e60526ea80052f5c1223302c337606ea4008dd4000a5eb7bdb182444b3001337129002000c66002007302f302f00299b800014800d003456600266e2520020018cc00400e605e005337000029000a0068acc004c0740062605c0051533029491146578706563745f61743a206e6f7420666f756e64001640a0814102848c0b0c0b4c0b4c0b4c0b4c0b4c0b4c0b400644444b30013300b0040058acc004cdd7980a98169baa0050038acc00660026eacc06cc0b4dd5002c00a0028032266ebcc024c0b4dd5002a60103d87a80008a5040a914a08152294102a48c0b0c0b4c0b4c0b4c0b4c0b4c0b400646058605a605a605a605a605a00291111111111194c004c0e00066eb4c0dc006600c00c9114c004dd6981d001cdd6981d181d801ccc004dd6181d181b9baa02c0029bad303a00f488896600266ebcc0f8c0ecdd5001015466002607c60766ea8c0f8c0ecdd51814981d9baa002981f1bac3023303b3754061330053758605260766ea80c001122259800998101bab302c303e37546058607c6ea8004c068c0f8dd502244c966002606a607c6ea8006264b30013044001899192cc004c0d0c104dd500144c8c8c8c8c8c8c8c8c8c8ca600260a0003375c60a0017375a60a001330500089828003cc14001a60a000b30500049bad3050003992cc004c1380062b30013371290021826800c5a26088609a002825a2c8278dd5182800124444444444b3001305b00b899817182d00a099912cc004c12c006264b3001305e001899818182e800801c5905b182c9baa0098acc004c13c006264b3001305e001899818982e800801c5905b182c9baa0098acc004c12800626464b3001305f00280245905c1bae305d0013059375401316415882b10560998170030998168028998168020998168018992cc004c128006264b3001305d001899818182e00080c45905a182c1baa00b8acc004c1380062b3001305837540170178b20b28b20aa415460ac6ea8028c158dd5003c590580c140004c13c004c138004c134004c130004c12c004c128004c124004c120004c11c004c108dd500145903f0992cc004cc090dd5981818211baa303030423754002605c60846ea800a264b300130353042375400313232323322598009826001c4c966002607660906ea800626464b3001304f00289919192cc004cc0cd2410f4261642074782076616c696469747900332259800992cc004c10800629462b300130470018a518a5041388270c13cdd519812982998281baa002305330503754003132598009821800c528c566002608e00314a314a0827104e18279baa33025303e30503754004607c60a06ea8006294104d1811180f98271baa0433022302b33050302b33050303133050375060066eb4c074c138dd502a25eb80cc142600294698103d87a8000a60103d8798000412c97ae033050302b33050303133050375066e00050dd6980e98271baa0544bd70198284c00528d300103d87a8000a60103d8798000412c97ae04bd704566002660669201274d757374206f6e6c79206d696e742074686520616363756d756c6174656420696e746572657374003375e6074609c6ea810cdd32cc004c100006297adef6c6089982819bb0301c304e37540a86e98cc084dd7182898271baa00e0014bd6f7b63020968acc004cc0cd241205370656e74205554784f2063616e6e6f7420686176652061646d696e204e4654009800998181bab303c304e37546078609c6ea8054c0f0c138dd502a528528a096899819a48146436f6e74696e75696e67206f7574707574206d7573742068617665206e6f20646174756d20616e6420686f6c642074686520616363756d756c6174656420696e7465726573740098008094c0c4cc140c0accc14004ccc141300103d87a80004bd7025eb8298107d87b9fd87980ff00cc004dd5981e18271baa303c304e375402b375c6038609c6ea81526eb8c144c138dd50072444b300130430048801c4c8c8cc0040040148966002003133056337606ea4014dd3001a5eb7bdb1822646644b30013372201000515980099b8f0080028992cc004cdd7a6101a000374c003100289982d19bb037520126e9800400905519198008009bab30580042259800800c4cc16ccdd81ba9009375001897adef6c6089919912cc004cdc8806001456600266e3c03000a264b30013370e00266e052000010880144cc17ccdd81ba900d375066e0000404000905a1bad305c00389982f19bb037520186ea003c01105944cc17800ccc0140140050591bae3059001305e002305c0014169133059337606ea4020dd300300220a889982c80199802802800a0a8375c60a800260b200460ae00282a8cc09000401104e2980103d87a8000407914a0825a294104b45282096375a60a06530010019bac3051304e375408737566064609c6ea810e660a098101000033050374e60a46eb0c0d8c138dd5021998284c005285300103d87a8000a60103d8798000412c97ae040044444b30010038800c4cc8966002609260a46ea8c158c14cdd5182b18299baa3041305337540051329800803c00a6eacc15cc160006653001375860b0003304b3054375460b060b2003375a60b000b30580024888966002660766eacc11cc164dd51823982c9baa0083041305937540bf15980099b8748038c160dd5000c4c96600260bc00313322598009827182d9baa0018992cc004c184006264b30013050305d37540031323232323298009833000cdd718330024c19800e6eb4c1980092222598009835802c4c8cc10c0044cc0fc00c4cc896600260b8003132323322598009839001c01a2c8378dd698378009bad306f002306f001306a375400f1598009830000c4c8c8cc896600260e40070068b20de375a60de0026eb4c1bc008c1bc004c1a8dd5003c5906720ce159800982d18339baa005899192cc0056600266e3c018dd7183698351baa02a899baf0053058306a375405514a0833a2b30013371066e00004dd6981d98351baa0700308992cc004c1500062b30019800983700b4c138cc1b4c1b8c1acdd5182c98359baa01a4bd704cdd2a4008660da6090660da6090660da008660da6ea401ccc1b4018cc1b4dd419b800050013306d30483306d3750062660da6ea007d2f5c097ae04bd7025eb826eacc164c1acdd5182c98359baa01aa60103d879800040ed13306d375066e00050004cc1b4dd3983780b19836cc00405698103d87a8000a60103d879800041a097ae08a99834a481333c65787065637465643e20457870656374206120636f727265637479207570646174656420636f6e74696e75696e6720434450001641a115330694912a3c65787065637465643e20546865726520697320736f6d65206163637275656420696e7465726573742e001641a064b3001337120026eb4c1b8c1acdd5014c56600266e20dd6982998359baa029031899b803370666e08cdc09bad306e306b375405200200a904040507b7a566df00d99b833370666e08cdc118101bad3053306b37540526eb4c1b8c1acdd5182c98359baa02900548202c227efa8052080897a8a99834a4810155001641a115980099b88002031899b833370666e08cdc118100011bad306e306b375460b260d66ea80a40152080b089fbea014820225ea2a660d292010156001641a08340dd698369837001454cc1a124012d3c65787065637465643e20497420697320746f6f20736f6f6e20746f20736574746c6520696e7465726573742e0016419d1533068491413c65787065637465643e20416c6c20434450732061726520666f72207468652073616d652069417373657420616e6420636f6c6c61746572616c2061737365742e0016419c6eb4c1b0004c1a0dd5002c5906518339baa005306a0098b20d01833000983280098320009831800982f1baa0018b20b630600018b20bc305c37540031641646eb4c174004c11cc108c168dd51824182d1baa0098b20b63059375400316415915980099baf305c3059375460b860b26ea8c11cc164dd500400f45660033001003a50a51415913305b3750004660b66e9c010cc16e600294698103d87a8000a60103d8798000415897ae08a9982ba4812845787065637420612073696e676c6520696e74657265737420636f6c6c6563746f7220696e7075740016415913305b3750004660b66e9c010cc16e60020074c103d87a8000a60103d8798000415897ae0415882b060b00088038c8cc0040040148966002003168994c004c15400660ac003305a00248896600266ebc00cc0f0cc16cc170c164dd500425eb822660b6004660b66e980052f5c113300600600141583058001415919800803400600900340188280c15000cc15400d05219b80375a609e60986ea80296600266e20dd6981a18261baa00a012899b833370666e08cdc118009bad3034304c37540146eb4c13cc130dd5181d18261baa00a482020283dbd2b36f806d2080b089fbea014820225ea2a66094921015a001641246e040462c8260dd6982680098249baa0018b208c304b0048b2092375a60920026eb4c12400cc124004c120004c10cdd5000c590401817981518211baa30303042375400315330404914c3c65787065637465643e205468652070726f7669646564207265662e20696e70757420696e64657820636f72726573706f6e647320746f2074686520696e746572657374206f7261636c652e001640fc660166eb0c0bcc104dd501b0049821800c59041181f9baa0018b2078302b3026303e37546058607c6ea80062a6607892014d3c65787065637465643e205468652070726f7669646564207265662e20696e70757420696e64657820636f72726573706f6e647320746f2074686520636f6c6c61746572616c2061737365742e001640ec8a9981ca49413c65787065637465643e205468652070726f766964656420696e70757420696e64657820636f72726573706f6e647320746f20746865206f776e20696e7075742e001640e0181b805a2646530012259800980f18159baa0028992cc004c0c400626600860600020051640b860586ea800a2c814a4605c605e605e605e605e605e605e605e605e0032232330010010032259800981018169baa0018991919800800802912cc00400629422b30013371e6eb8c0d000400e2946266004004606a00281710321bae3031302e3754003132337126eb4c0c8004c8cc004004dd61819981a001112cc0040062900044cc89660026600e00e0051300d0018800a060303400133002002303500140c8605c6ea800502b2444b3001301e013899912cc004c0cc006264646600e0022b3001330164901235265666572656e636564205554784f206d75737420686176652061646d696e204e465400330133756603e60626ea8c07cc0c4dd500100244cc0592412041646d696e206d756c7469736967206d7573742062652073617469736669656400330053034303137540026eb0c018c0c4dd50134528205c301d301830303754603c60606ea8004c0c80062c8180c06cc0b4dd5019998069bac301b302d37540446060605a6ea8c0c0c0b4dd5198061bac3030302d37540440391598009810009c6600244b30010018a40011300933002002303300140c1301b302d37540673019302d37540673300c37586060605a6ea80880712222323233223300b00113259800981d000c4c966002605a606c6ea8c04cc0dcdd5000c4cc88cc03c0044c9660026603e9211e5370656e74205554784f206d75737420686176652061646d696e204e4654003301c3756605060746ea80280322b30013301f490125466f756e646174696f6e206d756c7469736967206d75737420626520736174697366696564003300e303d303e303e303e303e303e303e303e303e303e303e303e303a3754605060746ea800cdd61807981d1baa02f8acc004cc07d2401234e65772061646d696e67206d756c74697369672063616e6e6f7420626520656d7074790030070018acc004cc07d241244e65772061646d696e206d756c7469736967206d75737420626520736174697366696564003300e0013758601e60746ea80be2b30013301f490121436f6e74696e75696e672076616c7565206d757374206265207468652073616d650098009bab3028303a37540093756605060746ea802a980103d87a8000404d13301f4901244f6c6420616e64206e657720646174756d73206d75737420626520646966666572656e7400980099baf006002a50a5140dd14a081ba29410374528206e8a5040dd14a081b8c0f0c0e4dd5000992cc004c0f0006264b3001302b303837540031323232323298009bad30410019bad30410059bad30410039bad30410024888966002608c00b13259800981a98211baa00189919191919191919191919194c004c1480066eb4c1480326eb4c14802e6eb4c14802a6eb4c1480266eb4c1480226eb4c14801e6eb4c14801a6eb4c1480166eb4c1480126eb4c1480092222222222259800982f00644cc0d4c1740384cc0c402c408a2c82d860a400260a200260a0002609e002609c002609a0026098002609600260940026092002609000260866ea80062c8200c1140222c821860820026080002607e002607c00260726ea80062c81b0c094c080c0e0dd51813181c1baa303b0018b207298009bac302530373754059008a60103d879800040606048603e606e6ea80062c81a0c0e40062c81b8cc07cdd6180e981a9baa02a301330183303730383035375400a97ae030010013020301b3033375400644b300130263033375400314a31323322598009810001456600266e24008c0180062646600200200444b30010018a518acc004cc01c01cc0f0006266004004607a00314a081b103a452820688a5040d06eb4c0e0004dd6181c181c800981a1baa00140c4600800889919912cc004c098c0bcdd5000c4cc8966002606c00313259800981298191baa00189919912cc004c0e800626603a6eb0c0e40048966002005132598009815981c1baa0018991925159800991980080098069bab3027303b375406044b30013371e6eb8c0fc00400e2946266004004608000281ca2934590371bae303c303937540031640d864660020026eb0c09cc0e4dd5003912cc004006298103d87a80008992cc006600266ebc00530103d87a8000a50a5140e11001899801801981f8012070325980099b8f375c607c002017130183303d303e303f0014bd7045300103d87a800040e06eb0c0f400503b44c8c8cc896600260800071300530400068b207a375c607a0026eb8c0f4008c0f4004dd6181d80120728b206e375a606e002607000260666ea80062c8180c07cc068c0c8dd5181018191baa30350018b2066375c606660606ea800660026eb0c078c0c0dd5012cc0ccc0c0dd501b530103d879800040451640b460020026062605c6ea8c0c4c0b8dd5198069bac3031302e375404603a44b30010018a5eb82266062605c6064002660040046066002818102a20541800800911192cc004c07800626464b3001303200280245902f1bae3030001302c37540071598009811000c4c8cc896600260660031330163758606400244b3001002803c66002013303400289800981a801201240c91640c06eb4c0c0004c0c4004c0b0dd5001c590292052302a37540048128888cc8a600264b3001301f302c37540031375a605a60606eacc0c0c0b4dd5000c5200040a8605e0033756005375e605e60600032259800981218169baa005899b890010028acc004cdc480080144cdc480119b80001482026fb80a294102b20564888966002007159800980100344cc00401120008a5040b51325980099baf4c0101400030300018acc004cc008014dd69818981a1bab3031001898019ba630350048a5040b915980099801002a4001130030078a5040b88170c0cc00d0310dd3001194c004006009223302f0023302f374c00297ae04004444b3001002899800a6103d87a80004bd6f7b63044c8cc896600266e452201000028acc004cdc7a441000028998021806998191818001a5eb80006266008980103d87a800000540b5198008034006446600c0046606800a002803102d1bae302d0013032003303000240b8407c22301698008014dd7181198101baa0019bae300e302037540028058602a602c00c602800a8b2012180580098031baa00b8a4d13656400c2a660049212f3c65787065637465643e2053696e676c652043445020696e70757420696e20746865207472616e73616374696f6e2e001615330024913f3c65787065637465643e2053696e676c6520696e74657265737420636f6c6c656374696f6e20696e70757420696e20746865207472616e73616374696f6e2e001601"
|
|
7723
|
+
cborHex: "590a2a590a27010100229800aba2aba1aba0aab9faab9eaab9dab9cab9a488888888cc896600264653001300b00198059806000cdc3a4005300b0024888966002600460166ea800e33001300c3754007370e90024dc3a4001300b375400891111919912cc004c0140122b3001301337540170028b20288acc004c0240122b3001301337540170028b20288acc004c0180122b3001301337540170028b20288b202040408080660024602a602c0032259800800c52f5c11330153012301600133002002301700140512301530163016001911919800800801912cc004006297ae0899912cc004c01400a2660320046600800800313300400400140506030002603200280b24446466446600400400244b3001001801c4c8c96600266e440180062b30013371e00c0031375a60320050054059133004004301d00340586eb8c05c004c068005018191919800800803112cc004006007132325980099b910080018acc004cdc7804000c4dd5980d001401501744cc010010c07800d0171bae3018001301b0014064297adef6c6014800260206ea802644b30010018800c54cc04400840050104dd2a400091111111194c0048c00800644602530010029bae301f301c3754003375c601660386ea8005007488c8cc00400400c8966002003168992cc004cdd79811180f9baa00100489807180f9baa001899801801981180120383021001407c9112cc004c03c01e2646464b300100180dc4c966002604a00513259800800c07a2b30013026001899805a49364d7573742070726f6475636520636f6c6c6563746f72206f7574707574207769746820696e63726561736564204144412076616c75650098009b914881009b8f4881009bac300f3022375402f3374a90011981218051981200219812260103d87a80004bd7025eb812222332232330010010052259800800c528456600264b300130040018acc004cdd7980c18159baa0014c107d87b9fd87980ff008acc004cc8a600264b30013020302d37540031375a605c60626eacc0c4c0b8dd5000c5200040ac60600033756005375e606060620032259800981298171baa4c0103d87a8000899b890010028acc004cdc480080144cdc480119b80001482026fb80a294102c20584888966002007159800980100344cc00401120008a5040b91325980099baf4c101400030310018acc004cc008014dd69819181a9bab3032001898019ba630360048a5040bd15980099801002a4001130030078a5040bc8178c0d000d0320dd3002994c0040066eacc06cc0b0dd5001488cc0c0008cc0c0dd3000a5eb810011112cc00400a26600298103d87a80004bd6f7b63044c8cc8966002601e005159800980700144cc010c064cc0ccc0c400d2f5c00031330044c0103d87a800000540b9198008034006446600c0046606a00a002803102e1bae302e0013033003303100240bd13375e605c605e605e605e60566ea800530103d87a80008a5040a114a0814229410281816800c528c4cc008008c0b800502720563259800a508800c4c8c8cc00400400c896600200313302c337609801014000374c00697adef6c6089919912cc004c02c00a2b3001300a0028992cc004cdd7a6101a000374c003100289981819bb04c01014000374c0020048158c8cc004004dd59817002112cc00400626606266ec130010140004c010101004bd6f7b63044c8cc89660026020005159800980780144c96600266e1c0052001880144cc0d4cdd8261014000375066e00005200200240c06eb4c0c800e26606866ec13010140004c0101010000440bd1330340033300500500140bc6eb8c0bc004c0d0008c0c800503044cc0bccdd82601014000374c00c008815226605e0066600a00a0028150dd7181500098178011816800a056330293376098010140004c010101004bd6f7b63020483756602a604c6ea8025660026030604a6ea8006246466ebcc0acc0a0dd5181598141baa002001302a3027375400512323375e605660506ea8008004c0a8c09cdd500120464079023204630073756602060426ea8c040c084dd5000c0710221811800a0423300b37586044603e6ea80508cdd7981198101baa302330203754601e60406ea8004008c084c078dd51810980f1baa0013300137586040603a6ea80480362b3001301300789919803a49334d757374207370656e64207374616b696e67206d616e61676572207769746820446973747269627574652072656465656d657200332259800800c00a2b3001302400189919912cc004c05400626464b300130290028024590261bae302700130233754007159800980c800c56600260466ea800e005164091159800980b000c56600260466ea800e00516409115980099b874801800626464b300130290028024590261bad30270013023375400715980099b87480200062b3001302337540070028b20488acc004cdc3a401400315980098119baa003801459024456600266e1d200c0018acc004c08cdd5001c00a2c81222c8101020204040808101020204013375e00298103d87b8000302037540026464660020026eacc094c098c098c098c098c098c098c098c098c098c088dd500b91192cc004cdd78021811800c4c09000626600600660500048108c098004cdd2a400466044604660406ea8c08c0052f5c100240848108528198051bac3021301e37540264660086eacc038c07cdd51807180f9baa0010023020301d37540471332259800980a980f1baa001899912cc004c094006264b30013014302137540031323322598009814800c4c8cc004004dd61814801112cc004006264b3001301a30273754003132324a2b3001323300100130103756605a605c605c605c605c60546ea807c896600266e3cdd71817000801c528c4cc008008c0bc00502845268b204c375c605660506ea80062c8128c8cc004004dd6180b98141baa0072259800800c5300103d87a80008992cc006600266ebc00530103d87a8000a50a51409d10018998018019817001204e325980099b8f375c605a002017130123302c302d302e0014bd7045300103d87a8000409c6eb0c0b000502a44c8c8cc8966002605e007133006006302f0058b2058375c60580026eb8c0b0008c0b0004dd61815000a0508b204c375a604c002604e00260446ea80062c80f8c966002602a60426ea80062604a60446ea80062c80f8c038c084dd5180818109baa30240018b2044375c6044603e6ea8004c8cc030dd6180798101baa01523002301030213754002b30013011301e375498103d879800089198029bab300f30203754002007123371090004c004dd5980798101baa0019bae302330203754007375c601e60406ea800d00b20388b2038300a301d37540466040603a6ea8c080c074dd5198009bac3020301d375402401a80d101a0c01c01c6028602a00a60260088b2012180580098031baa00b8a4d13656400c2a660049201353c65787065637465643e20436f6c6c6563746f7220696e7075742063616e6e6f742068617665206e6f6e2d41444120617373657473001615330024912c3c65787065637465643e204d757374207370656e642073696e676c6520636f6c6c6563746f7220696e707574001601"
|
|
8199
7724
|
};
|
|
8200
7725
|
|
|
8201
|
-
// src/contracts/
|
|
8202
|
-
|
|
7726
|
+
// src/contracts/collector/scripts.ts
|
|
7727
|
+
var mkCollectorValidatorFromSP = (params) => {
|
|
8203
7728
|
return {
|
|
8204
7729
|
type: "PlutusV3",
|
|
8205
|
-
script:
|
|
8206
|
-
|
|
7730
|
+
script: applyParamsToScript12(_collectorValidator.cborHex, [
|
|
7731
|
+
new Constr2(0, [
|
|
7732
|
+
new Constr2(0, [
|
|
7733
|
+
params.stakingManagerNFT[0].unCurrencySymbol,
|
|
7734
|
+
fromText7(params.stakingManagerNFT[1].unTokenName)
|
|
7735
|
+
]),
|
|
7736
|
+
new Constr2(0, [
|
|
7737
|
+
params.stakingToken[0].unCurrencySymbol,
|
|
7738
|
+
fromText7(params.stakingToken[1].unTokenName)
|
|
7739
|
+
]),
|
|
7740
|
+
new Constr2(0, [
|
|
7741
|
+
params.versionRecordToken[0].unCurrencySymbol,
|
|
7742
|
+
fromText7(params.versionRecordToken[1].unTokenName)
|
|
7743
|
+
])
|
|
7744
|
+
])
|
|
8207
7745
|
])
|
|
8208
7746
|
};
|
|
7747
|
+
};
|
|
7748
|
+
|
|
7749
|
+
// src/contracts/execute/types.ts
|
|
7750
|
+
import { Data as Data40 } from "@lucid-evolution/lucid";
|
|
7751
|
+
var ExecuteParamsSchema = Data40.Object({
|
|
7752
|
+
govNFT: AssetClassSchema2,
|
|
7753
|
+
upgradeToken: AssetClassSchema2,
|
|
7754
|
+
iAssetToken: AssetClassSchema2,
|
|
7755
|
+
collateralAssetToken: AssetClassSchema2,
|
|
7756
|
+
stabilityPoolToken: AssetClassSchema2,
|
|
7757
|
+
cdpCreatorToken: AssetClassSchema2,
|
|
7758
|
+
cdpToken: AssetClassSchema2,
|
|
7759
|
+
versionRecordToken: AssetClassSchema2,
|
|
7760
|
+
iassetValHash: Data40.Bytes(),
|
|
7761
|
+
cdpValHash: Data40.Bytes(),
|
|
7762
|
+
sPoolValHash: Data40.Bytes(),
|
|
7763
|
+
versionRegistryValHash: Data40.Bytes(),
|
|
7764
|
+
treasuryValHash: Data40.Bytes()
|
|
7765
|
+
});
|
|
7766
|
+
var ExecuteParams = ExecuteParamsSchema;
|
|
7767
|
+
function castExecuteParams(params) {
|
|
7768
|
+
return Data40.castTo(params, ExecuteParams);
|
|
8209
7769
|
}
|
|
8210
|
-
|
|
7770
|
+
|
|
7771
|
+
// src/contracts/execute/scripts.ts
|
|
7772
|
+
import {
|
|
7773
|
+
applyParamsToScript as applyParamsToScript13,
|
|
7774
|
+
applySingleCborEncoding
|
|
7775
|
+
} from "@lucid-evolution/lucid";
|
|
7776
|
+
|
|
7777
|
+
// src/validators/execute-validator.ts
|
|
7778
|
+
var _executeValidator = {
|
|
7779
|
+
type: "PlutusScriptV3",
|
|
7780
|
+
description: "Generated by Aiken",
|
|
7781
|
+
cborHex: "5931ec5931e9010100229800aba2aba1aba0aab9faab9eaab9dab9cab9a48888888a60022a66004921203c65787065637465643e20694173736574206e6f74207265666572656e63656400168a99801249283c65787065637465643e2053696e676c6520636f6c6c61746572616c20617373657420696e70757400168a998012491e3c65787065637465643e2053696e676c652069617373657420696e70757400168a99801249193c65787065637465643e204d697865642076657273696f6e7300168a99801249523c65787065637465643e205768656e2066756e64732066726f6d207472656173757279207265717565737465642069742068617320746f207370656e642061207574786f2066726f6d20747265617375727900168a99801249243c65787065637465643e204f6e6c792073696e676c65206578656375746520696e707574001648888896600264653001300f00198079808000cdc3a4005300f00248889660026004601e6ea800e2664530013015002980a980b001566002600260226ea801a2b30013012375400d149a2c809a2c8079222598009802180a1baa0028cc004c060c054dd50014c054dd500348c064c06800644646600200200644b30010018a5eb8226644b3001300500289980e80119802002000c4cc010010005018180e000980e800a03448888c8cc88cc89660020050158acc004c08800a26464b3001330013756601260406ea8018c024c080dd5013466002444646601800846004601c604a6ea800566002602460446ea8006246600a6eacc034c090dd5000801c48cdc42400130013756601a60486ea80066eb8c09cc090dd5001cdd7180698121baa003401881026e1d20049181218129812800c88c8cc00400400c88cc00c004c00800a4464b30013012001899192cc004c0a400a0091640986eb8c09c004c08cdd5001c566002602a00315980098119baa0038014590244590202040302137540049111119914c004c0a800a6002003259800980398139baa0018981598141baa0018b204a488a60026002601060546ea8c04cc0a8dd5001c8966002603660566ea800a26464646464646464646464653001303b0019bad303b00c9bad303b00b9bad303b00a9bad303b0099bad303b0089bad303b0079bad303b0069bad303b0059bad303b0049bad303b00248888888888966002608e01913301f304600e13301b00b0188b2088181d800981d000981c800981c000981b800981b000981a800981a00098198009819000981880098161baa0028b2052980e18149baa302d302e005488966002603860586ea800e264646464653001375a606a003375a606a00b375a606a007375a606a00491112cc004c0e80162660166072010330012303a303b303b303b303b303b303b303b0019181d181d981d981d800cdd2a40052259800800c40062a6606c004200281aa44b3001302730373754005132323322598009820001c0162c81e8dd6981e8009bad303d002303d001303837540051640d522598009813981b9baa0028991919912cc004c10000e00b1640f46eb8c0f4004dd7181e801181e800981c1baa0028b206a9b874801a6e1d20089b874802a6e1d200e9b87480326e2520044888888888888cc89660026601692125476f7620696e707574206d75737420757365207468652072696768742072656465656d6572005980080c44ca6002266ebc00530103d87b800098221baa00191192cc004c0dc00626464b3001304e00280245904b1bae304c00130483754007159800981d000c4c8c966002609c0050048b2096375c609800260906ea800e2c822904518231baa002488966002606e00513232323298009827800cdd698278024dd71827801a444b3001305300489919912cc004c10400a264b300130570018992cc004c10cc14cdd5000c4c8c8c8c8c8ca600260ba003375c60ba00d305d004982e801cc1740092222259800983180344cc094c1880284cc09400c4cc0940084cc0940044cc09401403a2c830060ba00260b800260b600260b400260b200260a86ea80062c8288c1580062c82a0c148dd5001c566002608800513259800982b800c4c966002608660a66ea800626464646464653001305d0019bae305d006982e8024c17400e60ba004911112cc004c18c01a26604a60c401426604a00626604a00426604a00226604a00a01d164180305d001305c001305b001305a00130590013054375400316414460ac00316415060a46ea800e2b300130310028992cc004c15c006264b3001304330533754003132323232323232323298009bad30600019bae30600099bad306000798300034c18001660c000930600039830001244444444b30013069009899815183400809981100289981500209981580189981580109981580080a4590660c180004c17c004c178004c174004c170004c16c004c168004c164004c150dd5000c59051182b000c5905418291baa0038acc004c05800a264b300130570018992cc004c10cc14cdd5000c4c8c8c8c8c8c8c8c8ca60026eb4c1800066eb8c1800266eb4c18001e60c000d306000598300024c18000e60c0004911111112cc004c1a402626605460d002026604400a2660540082660560062660560042660560020291641983060001305f001305e001305d001305c001305b001305a00130590013054375400316414460ac00316415060a46ea800e2b300130150028992cc004c15c006264b3001304330533754003132323232323232323298009bae30600019bae30600099830003cc18001a60c000b30600049bad30600039bad30600024888888896600260d201313302a306801013302b00613302b00513302b0041330410030148b20cc1830000982f800982f000982e800982e000982d800982d000982c800982a1baa0018b20a230560018b20a830523754007159800980a00144c96600260ae00313259800982198299baa001899191919191919191919194c004dd71831000cdd71831005cc18802660c40113062007992cc004c1800062b3001301f305f0018b44c148c17c00505d4590611baa3062006992cc004c1800062b3001301f305f0018b44c148c17c00505d4590611baa306200598310024dd69831001cdd6983100124444444444b3001306d00b899817183600a09981780409981780389981780309982280180c45906a0c188004c184004c180004c17c004c178004c174004c170004c16c004c168004c164004c150dd5000c59051182b000c5905418291baa0038acc004c04800a264b30013057001899814182b00080145905418291baa0038acc004c04c00a264b300130570018992cc004c10cc14cdd5000c4c8cc896600260b6003133034375860b400244b300100280444c8cc896600260c0003132598009826182e1baa001899192cc004c18c00a2600e60c60111641806eb8c184004c174dd5000c5905a182f800c5905d1bae305d001305e001375860b800482d22c82c0dd6982c000982c800982a1baa0018b20a230560018b20a83052375400715980099b874804000a26464b30013058002801c590551bae30560013052375400716413c827904f209e413c827904f209e413c609e6ea80044c966002608000313259800982b000c4c966002608460a46ea80062646464b3001305a002899912cc004c11cc15cdd500144c8c8c96600260be005133014305e003132598009825800c4c96600260c200313232598009827000c4c96600260c800313301930630010098b20c2305f37540051598009828800c4c8c8ca60026eb4c1940066eb4c19400e6eb4c194009222598009834802403a2c833060ca00260c800260be6ea800a2c82e105c182e9baa00130600018b20bc305c37540051598009827000c56600260b86ea800a00b16417516416482c8c168dd5000c5905c182e800982e800982c1baa0028b20aa30590031330330012259800801404e264b3001304830583754003132323298009bad305f0019bae305f0039bae305f00248896600260c60091300830630098b20c0182f800982f000982c9baa0018b20ac305b002416516415c6eb0c160004c160004c14cdd5000c59050182a800c5905318289baa0058acc004c10c0062b30013051375400b00c8b20a48b209c4138609e6ea8010c1480162c8280609e002609c002609a00260906ea80122b3001303a002899192cc004c13800a00b16412c6eb4c130004c120dd50024566002604e00515980098241baa004801c590494566002601800515980098241baa004801c59049459045208a4114822866004608e60886ea807409e294504144c96600266018921174d697865642070726f746f636f6c2076657273696f6e73003370e6eb4c08cc114dd500d9bad30013045375406115980099806249224d7573742065786563757465206166746572206566666563746976652064656c6179003259800981c18229baa001899b88337006eb4c090c118dd50189bad302430463754605e608c6ea8070dd6982498231baa0018a50410c6090608a6ea8c120c114dd5180798229baa0368acc004cc03124011143616e6e6f742062652065787069726564003259800981c18229baa001899b89375a6092608c6ea8004cdc01bad300f304637540626eb4c03cc118dd5181798231baa01c8a50410c6090608a6ea8c0b8c114dd5180798229baa0368cc0048c124c128c128c128c128c12800646092609460946094609460946094609460946094003375e980103d879800048896600264b3001303830483754600860926ea80d22b3001001820c4c966002609c005132332259800981e000c566002609a6ea800e005164139159800981f800c566002609a6ea800e0051641391598009816000c566002609a6ea800e0051641391598009808800c566002609a6ea800e0051641391598009808000c4c8c8c8ca600260a8003375a60a8007375a60a80049112cc004c16001226603260ae00e2b300130433053375400713232332259800982e001c0362c82c8dd6982c8009bae3059002305900130543754007164145164154305400130530013052001304d37540071598009807800c566002609a6ea800e005164139164128825104a2094412882504c010004c128dd500099804182698251baa0013756600860946ea80ee0848258c13000504a44cc0412414b5768656e206e6f207472656173757279207769746864726177616c207265717565737465642069742063616e2774207370656e6420616e79207574786f2066726f6d207472656173757279003375e6e9c005300101800041186605a6eb0c12cc120dd501c980819825182598261826182618261826182618261826182618261826182618241baa04e4bd704660026e952000911982619bb037520046ea00052f5bded8c1370090014dd2a4008911119912cc004cc88cc05d24012c54686520646174756d206f6620676f7665726e616e6365206d757374207570646174652070726f7065726c79003232598009820800c6600200900398039982a19191918069982b982c0019982b982c0011982b982c0009982b9ba8300b375a603c60aa6ea80acc164c164004c160004c15c004c148dd501425eb82600a60aa60a46ea816298103d87a800040191598009809000c6600200900398039982a1918059982a982b0009982a982b18299baa003305730570013052375405097ae09802982a98291baa058a60103d87a800040191598009809800c6600200900398039982a191918061982b182b8011982b182b8009982b1ba8300a375a606460a86ea80a8c160c160004c15c004c148dd501425eb82600a60aa60a46ea816298103d87a8000401919800813528528a09e413c827904f18281baa0013039305037540766eb0c144c148c148c138dd501f980b19828180319828182898271baa3051304e3754606e609c6ea809ccc14130103d87a80004bd7025eb82264b300133016490122546865207472616e73616374696f6e206d757374206d696e742070726f7065726c79003375e6016609e6ea8100dd34c0048c8cc004004008896600200314bd6f7b63044c8cc154cdd818290009ba63233001001375660a800444b30010018a5eb7bdb182264660b066ec0c154004dd419b8148000dd6982b00099801801982d001182c000a0ac3300300330570023055001414d304e37546070609e6ea80ea4446644b300130430038802c4c8c8cc00400401c8966002003133059337606ea4014dd3001a5eb7bdb1822646644b30013372201000515980099b8f0080028992cc004cdd7a60101a000374c003100289982e99bb037520126e9800400905819198008009bab305b0042259800800c4cc178cdd81ba9009375001697adef6c6089919912cc004cdc8806001456600266e3c03000a264b30013370e00266e05200000f880144cc188cdd81ba900d375066e0000403c00905d1bad305f00389983099bb037520186ea003801105c44cc18400ccc01401400505c1bae305c0013061002305f001417513305c337606ea4020dd300300220ae89982e00199802802800a0ae375c60ae00260b800460b400282c0cc02c00400d0511bae3055305237540046eb8c0ecc148dd50012444b300130410028cc00660026006600a607660a46ea8162601c60a46ea816290012002981818291baa058a4004800a2b300130310028cc004c00cc014c0ecc148dd502c4c06cc148dd502c520024005159800980a8014660026006600a607660a46ea8162600860a46ea8162900120028acc004c04c00a3300130033005303b305237540b1301c305237540b14800900144c00cc014c0ecc148dd502c209e413c827904f226602c921104661696c656420657865637574696f6e009800981c18279baa03a91829982a182a182a182a182a182a182a182a000c8c14cc150c150c150c150c150c150c150c150c150c15000644b300130403050375400513232323232323232329800982e800cdd7182e804cdd6982e8044c17401a60ba00b305d004982e801cc96600260b6003159800980d182d000c5a2609a60b400282c22c82e0dd5182e801244444444b30013066009899814183280789981400289981400209981400189981400109981f0040094590630c174004c170004c16c004c168004c164004c160004c15c004c158004c144dd500145904e4896600266e40008006298103d87980008acc004cdc7801000c530103d87a80008a6103d87b8000413882712222232598009822000c4ca6002601c660b0002660b0980103d87a80004bd704dd6182c982d182d182b1baa047982c982b1baa0074888c966002660429212153746162696c697479506f6f6c206f757470757420697320696e636f7272656374009800801cc088cc170c048cc170c088cc170c024c168dd503025eb80cc171300103d87a80004bd7025eb82601e660b86024660b86024660b860ba60b46ea8008cc171300118d8799fd8799f1b0de0b6b3a7640000ffd8799f00ff0000ff003305c4c10180004bd7025eb812f5c1300d3016305a37540c14c103d87a8000403915980098249bad3023305a37540611330214912370726f706f73656420694173736574206f757470757420697320696e636f727265637400330014a2980103d87a8000899810a48125496e636f72726563746c7920636f6e73756d6564207265666572656e636520696173736574003259800982f800c4c96600266ebc01cc17cc170dd5182f982e1baa3045305c3754003132598009826182e1baa0018992cc004c1880062646601a002264b3001304f0018acc004c148c17cdd5181518301baa0028acc004cc09d2412370726f706f73656420694173736574206f757470757420697320696e636f727265637400330074a26030660c460c660c06ea80092f5c113302749123636f6e73756d656420694173736574206f757470757420697320696e636f7272656374009800804cc0a0cc1880292f5c130153306230183306232323232323232301f33069306a00733069306a00633069306a00533069306a00433069306a00333069306a00233069306a001330699800a50a6103d87a8000a60103d8798000419060d660d600260d400260d200260d000260ce00260cc00260ca00260c06ea80092f5c097ae09809981f18301baa066a6103d87a8000405114a082ea294105d4566002607e003159800992cc004c140c180dd5000c4c068cc038dd7183218309baa009375c60c860c26ea8006294505e180818301baa0028acc004cc09d2412370726f706f73656420694173736574206f757470757420697320696e636f727265637400330074a0602060c06ea800a26604e92123636f6e73756d656420694173736574206f757470757420697320696e636f7272656374009800804cc0a0cc1880292f5c130153306230183306232323232323232301f33069306a00733069306a00633069306a00533069306a00433069306a00333069306a00233069306a00133069306a306b00133069301f33069306a3067375401e97ae04bd7018350009834800983400098338009833000983280098301baa0024bd7025eb826026607c60c06ea819a98103d87a8000405114a082ea294105d454cc1792411a537563682069617373657420616c7265616479206578697374730016417482e8c178dd5198061bae3062305f375400e6eb8c188c17cdd50009830800c5905f182e9baa0018b20b43033303a305c3754608a60b86ea80060aa82c8c1780062c82e260026eb0c174c168dd5025cc0e0c168dd50305300103d879800040e882ba2941057114c0040126046660ba00a97ae098081982e98099982e98099982e982f182d9baa0033305d4c10100003305d3044305b3754006660ba607260b66ea800ccc174c090c16cdd50019982e980b982d9baa0033305d3016305b3754006660bb3001002a6103d87a8000a60103d87980004160660ba00297ae04bd7025eb82601c607260b66ea818698103d87a8000403c301d330573005305537540b697ae08acc004c11c0062653001375860b260b460b400398009bac3059001981a182b1baa05ca6103d879800040d9301e330583006305637540b897ae0982c982b1baa007488896600260bc0071325980099baf003305e305b375460bc60b66ea8c110c16cdd5000c4c966002609660b66ea8006264b30013061001899198060008acc004cdc79bae3061305e37540026eb8c184c178dd5002c5660033001008981319830180b198300031983026103d87a80004bd7025eb826026660c0602c660c064646030660c460c6004660c460c6002660c4609260c06ea801ccc188c0f8c180dd500399831181498301baa00733062301c3060375400e660c4603660c06ea801cc190c190c190c190c190c190004c18c004c178dd5000a5eb812f5c13011303c305e37540c94c0103d87a8000404914a3153305c491253c65787065637465643e20694173736574206f757470757420697320696e636f72726563740016416d153305c4911e3c65787065637465643e204e6f742072656c6576616e74206961737365740016416c60c000316417860b86ea80062c82c8c0c8c0e4c16cdd51822182d9baa0018a9982ca49283c65787065637465643e204d6f64696679696e67206e6f6e2d7570677261646564204941737365740016416060ba00716416c3055375408d13259800981a80146600260b260ac6ea801e4464b3001304b30583754003133006375c608460b26ea800cdd71821182c9baa0028800a0ac33005375c60b660b06ea8008dd7182d982c1baa001980f1982c1803182b1baa05c4bd704c158dd5023a4445300130123305c0023305c4c103d87a80004bd704dd6182e982f182f000e60026eb0c174006607060b46ea818298103d879800040e89112cc0040060af132598009831001456600266ebc018c184c178dd51830982f1baa3047305e3754003132598009827182f1baa0018992cc004c1900062646601e0022b30013371e6eb8c190c184dd50009bae306430613754017159800cc00401a6052660c600e97ae0980b19831980c9983199180d198321832800998321ba83018375a609660c46ea8008c198c198004c184dd5000a5eb812f5c13014303f306137540cf4c103d87a80004055132324a2b30013051375a609660c46ea800a2b300198009bac3065306237540a7302b306237540d14c0103d8798000410915980099800a514c0103d87a80008a4d1533060491223c65787065637465643e2057726f6e6720636f6c6c61746572616c206f75747075740016417d1533060491243c65787065637465643e204e6f20636f6c6c61746572616c20617373657420696e7075740016418d13259800800c17a264b300130680028acc004cdd7806183398321baa306730643754609a60c86ea8006264b3001305730643754003132598009835000c4c8cc04800456600266e3cdd7183518339baa001375c60d460ce6ea80462b3001337106eb4c140c19cdd5003acc0056600266ebd6600260b260cc6ea8c084c19cdd5000c4c140c19cdd5000c4c96600260d800313259800982d98341baa0018992cc004c1b80062646602c0022b3001305d306a3754604a60d66ea8006260a860d66ea80062a660d2921253c65787065637465643e204e6f742074686520666972737420696e2074686520636861696e001641a060da0031641ac60d26ea80062c8330c0fcc118c1a0dd5182898341baa306b0018b20d298009bac3050306737540b13030306737540db4c0103d8798000411c8321300106d8799f4040ff008a51899baf30503067375402298106d8799f4040ff00419114804a2900820c88acc004c96600260ae003159800982d18339baa30223068375400515980099817a4812a70726f706f73656420636f6c6c61746572616c206173736574206f757470757420696e636f727265637400330074a26040660d460a260d06ea80092f5c113302f4912a636f6e73756d656420636f6c6c61746572616c206173736574206f757470757420696e636f7272656374009800806cc0c0cc1a80392f5c1301d3306a30303306a3232323232323232323029330733074009330733074008330733074007330733074006330733074005330733074004330733074003330733074002330733074001330739800a50a6103d87a8000a60103d879800041b860ea60ea00260e800260e600260e400260e200260e000260de00260dc00260da00260d06ea80092f5c097ae0980d981898341baa06ea6103d87a8000407114a0832a29410654566002608e003159800992cc004c160c1a0dd5000c4c088cc048c148c1a4dd5009983618349baa0018a514198602e60d06ea800a2b30013302f4912a70726f706f73656420636f6c6c61746572616c206173736574206f757470757420696e636f727265637400330074a0602e60d06ea800a26605e9212a636f6e73756d656420636f6c6c61746572616c206173736574206f757470757420696e636f7272656374009800806cc0c0cc1a80392f5c1301d3306a30303306a3232323232323232323029330733074009330733074008330733074007330733074006330733074005330733074004330733074003330733074002330733074001330733074307500133073302933073305a3071375403697ae04bd70183a000983980098390009838800983800098378009837000983680098341baa0024bd7025eb826036606260d06ea81ba98103d87a8000407114a0832a2941065454cc199241245375636820636f6c6c61746572616c20617373657420616c726561647920657869737473001641948328c198dd519808182818339baa011305030673754003149a2c83222a660ca921283c65787065637465643e204d617820636f6c6c61746572616c206173736574732072656163686564001641911533065491283c65787065637465643e204e6f742072656c6576616e7420636f6c6c61746572616c2061737365740016419060d200316419c60ca6ea80062c8310c0ecc108c190dd5182698321baa00182ea0c282fa0ca306600141913001375860ca60c46ea814e605660c46ea81a298103d8798000410882f88a6002011302b330650094bd704c060cc194c0accc194c06ccc194c198c18cdd500199832982618319baa00d3306530413063375401a660ca605860c66ea8034cc194c07cc18cdd500699832980f18319baa00d3306530153063375401a660ca605a60c66ea8034cc194c04cc18cdd500699832cc00400a98103d87a8000a60103d87980004180660ca00297ae04bd7025eb82602c605860c66ea81a698103d87a8000405d153305f4911e3c65787065637465643e2057726f6e6720696173736574206f757470757400164179153305f491173c65787065637465643e2057726f6e67206961737365740016417860c600316418460be6ea80062c82e0c0d4c0f0c178dd51823982f1baa00182ba0b682c20be3060001417845660026034005132980098079982c8009982ca6103d87a80004bd70660026eb0c168c15cdd50244c080c15cdd502ed300103d879800040dd305a305737540109112cc004c17800a264b30013375e00a60bc60b66ea8c178c16cdd51822182d9baa0018992cc004c138c16cdd5000c4c96600260c200313233009001159800acc004cdc79bae3061305e37540026eb8c184c178dd5002c4cdd79823982f1baa0013047305e375400b14a082da2b300198009bac303c305e375409f3026330600074bd704c04ccc180c098cc180c8c8c8c064cc18cc19000ccc18cc190008cc18cc190004cc18cc0a8c184dd500419831980e98309baa00833063301c30613754010660c6602660c26ea8020cc18cc0acc184dd500419831980898309baa008306530653065306530653065306500130640013063001305e375400297ae04bd704c044c09cc178dd5032530103d87a8000404914a3153305c4912c3c65787065637465643e20436f6c6c61746572616c206173736574206f757470757420696e636f72726563740016416d153305c491263c65787065637465643e20697272656c6576616e7420636f6c6c61746572616c2061737365740016416c60c000316417860b86ea80062c82c8c0c8c0e4c16cdd51822182d9baa00182a20b0305d0028b20b6180f1982c1803182b1baa05c4bd70456600260320051332259800982e000c4c966002609660b06ea80062b30013059375400313259800800c15a264b3001305f0028992cc004c12cc16cdd5000c4c96600260c20031323300c00115980099812a4810c57726f6e6720694173736574003371e6eb8c184c178dd50009bae3061305e3754011133025490117434450206f757470757420697320696e636f72726563740098009bac303c305e375409f3026330603016330603026330603018305e37540c897ae0330604c103d87a80004bd7025eb826026660c0604c660c0602c660c060c260bc6ea8020cc180c11cc178dd500419830181e182f1baa008330603027305e3754010660c0603460bc6ea8020cc1826002946980103d87a8000a60103d8798000416c660c130014a34c0103d87a8000a60103d8798000416c660c0603260bc6ea8020cc180c040c178dd5004198301814182f1baa00833060300e305e375401097ae04bd7025eb826022602060bc6ea8192980103d87a8000404914a082d8c1800062c82f0c170dd5000c590591819181c982d9baa3044305b3754003057417060ba00282da60026eb0c108c164dd50254c0dcc164dd502fd300103d879800040e51641691641586602c60b660b06ea8c16c004dd59809182c1baa0498b20b230593056375400f3001375860b260ac6ea811e602260ac6ea817298103d879800040d9159800980c00144cc896600260b80031325980099baf305c3059375460b860b26ea8c108c164dd500098109982d9809982c9baa05f4bd7044c96600266e1d20103059375400313259800982f800c4cc8966002609e60b86ea8006264b300130620018992cc004c138c178dd5000c4c8c8c8c8c8c8c8c8c8c8ca60026eb8c1b40066eb8c1b402e60da013306d0089836803cc96600260d600315980098151835000c5a260ba60d400283422c8360dd518368034c96600260d600315980098151835000c5a260ba60d400283422c8360dd51836802cc1b40126eb4c1b400e6eb4c1b4009222222222259800983c005c4cc0e4c1dc0504cc0e80204cc0e801c4cc0e80184cc14000c566002660769211643445020696e70757420697320696e636f7272656374005980099b8f375c60ee60e86ea8058dd7183b983a1baa01e899baf305d3074375402c60ba60e86ea807a294107144cc0ed24117434450206f757470757420697320696e636f72726563740098009bac3052307437540cb303c33076302c33076303c33076302e307437540f497ae0330764c103d87a80004bd7025eb826052660ec6078660ec64605a660ee60f0002660ee60f060f2002660ee60a660ea6ea807ccc1dcc0f8c1d4dd500f9983b9818983a9baa01f3307798009833983a1baa30303075375403f4c0103d87a8000a60103d879800041c8660ef3001306730743754604e60ea6ea807e980103d87a8000a60103d879800041c8660ee607e60ea6ea807ccc1dcc094c1d4dd500f9983b9817983a9baa01f3307730243075375403e97ae03074375402c97ae04bd704dd5982e983a1baa305d307437540394c0103d87a800040a114a0838a2c83a860da00260d800260d600260d400260d200260d000260ce00260cc00260ca00260c800260be6ea80062c82e0c1840062c82f8c174dd5000c5905a1bad305e00130323039305b3754608860b66ea800e2c82e0c168dd5000c590571980b982e182c9baa0013756602660b26ea812a2a660ae92011a3c65787065637465643e204d697865642076657273696f6e732e0016415860b600316416460b260ac6ea801e60026eb0c164c158dd5023cc020c158dd502e5300103d879800040d9159800980b80144c8cc07924012176657273696f6e5265636f7264206f757470757420697320696e636f72726563740098009bac303530573754091301f33059300f33059301f33059305a305b305b305b305b305b305b305b305b305b305b305b305737540ba97ae0330594c103d87a80004bd7025eb826018660b2601e660b260b460ae6ea8004cc164dd399198008009bac30413058375400444b30010018a5eb822660b66e9cc8cc170c174004cc170c174c168dd5182e982f000a5eb80dd6182e00099801001182e800a0b44bd7025eb826014604260ae6ea8176980103d87a8000402c60b260ac6ea801e2b300130160028a518a51414c829905320a6414c82988966002608c60ac6ea800a26464646464646464646465300130650019bae306500b9bad306500998328044c19401e60ca00d306500598328024dd69832801cc96600260c600315980098111831000c5a260aa60c400283022c8320dd5183280124444444444b3001307000b899818983780a0998148038998188030998190028998190020998190018992cc004c170006264b30013072001899819983880080c45906f18369baa00b8acc004c17c0062b3001306d37540170178b20dc8b20d441a860d66ea802a2c836860ca00260c800260c600260c400260c200260c000260be00260bc00260ba00260b800260ae6ea800a2c82a105220a43053375400a8a504130460a460a660a660a660a660a660a600314a0825888888c8c8cc00400401c896600200314a1159800992cc004c0100062b30013375e606660aa6ea800401e2b300133229800992cc004c11cc15cdd5000c4dd6982c182d9bab305b30583754003148001055182d000cdd58014dd7982d182d800c8966002609660b06ea8026266e2400400a2b30013371200200513371200466e0000520809bee028a50415882b1222259800801c566002600400d13300100448002294105844c96600266ebd3001014000305b0018acc004cc008014dd6982e182f9bab305c001898019ba630600048a50416515980099801002a4001130030078a50416482c8c17800d05c0dd3003194c0040066eacc0fcc158dd5001488cc168008cc168dd3000a5eb810011112cc00400a26600298103d87a80004bd6f7b63044c8cc896600266e452201000028acc004cdc7a4410000289980218099982e982d801a5eb80006266008980103d87a80000054161198008034006446600c004660be00a00280310581bae3058001305d003305b002416513375e603c60aa6ea800530103d87a80008a50414914a082922941052182b800c528c4cc008008c16000505120aa59800982018281baa004891919baf30563053375460ac60a66ea8008004c154c148dd5002c48c8cdd7982b18299baa00200130553052375400a8270966002942297adef6c6089982799bb03050304d37540026e98cc010dd7181b18269baa001480092f5bded8c0825114a0822914a082122941042452820842304830493049304930490018a504104446464660020020064464b30013375e008608e003130480018998018019826001208a304a001300c330460024bd7011192cc004c0d0006264b3001304a0018998061824800801c5904718229baa0038acc004c0dc006264b3001304a0018998059824800801c5904718229baa0038acc004c09000626464b3001304b0028024590481bae304900130453754007164108821104218219baa0024590370c0d4004c0d0004c0cc004c0c8004c0b4dd5001c5902a06644b300100180145660026056003133029302a001330299800a51a60103d87a8000a60103d8798000409097ae0801205040a026644b300100180145660026056003133029302a001330299800a50a6103d87a8000a60103d8798000409097ae0801205040a02a6604692130457870656374656420476f7620696e7075742065697468657220617320696e707574206f72207265662e20696e707574001698009bac300e3025375402d3028302537540574c0103d87980004015300100c981418129baa02ba60103d8798000401444464b30013018001899192cc004c0bc00a0091640b06eb8c0b4004c0a4dd5001c56600260360031323322598009818000c4cc024dd61817800912cc00400a00f19800804cc0c400a260026064004804902f45902d1bad302d001302e001302937540071640988130c09cdd500122a6603c921283c65787065637465643e20526571756972657320617574686564206578656375746520696e7075740016407444602730010029bae302430213754003375c601460426ea800500311119199119801001000912cc004006007132325980099b910060018acc004cdc7803000c4dd69813001401502344cc010010c0a800d0231bae30240013027001409464646600200200c44b3001001801c4c8c96600266e440200062b30013371e01000313756604e0050054091133004004302b00340906eb8c094004c0a00050260a5eb7bdb1805200080aa03e407c66002006603e60386ea8c07cc070dd50011bab301f30203020302030203020302030203020302000632330010010022259800800c5a264b30013375e6040603a6ea800402e2600c603a6ea8006266006006604200480d0c07c00501d1119802001119baf3020301d37546040603a6ea8c018c074dd50008011bac301c0034590120c040dd50019b87480022c8068601e00260146ea803e29344d95900701"
|
|
7782
|
+
};
|
|
7783
|
+
|
|
7784
|
+
// src/contracts/execute/scripts.ts
|
|
7785
|
+
var mkExecuteValidator = (params) => {
|
|
8211
7786
|
return {
|
|
8212
7787
|
type: "PlutusV3",
|
|
8213
|
-
script:
|
|
8214
|
-
|
|
8215
|
-
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
|
|
8226
|
-
|
|
7788
|
+
script: applySingleCborEncoding(
|
|
7789
|
+
applyParamsToScript13(_executeValidator.cborHex, [
|
|
7790
|
+
castExecuteParams(params)
|
|
7791
|
+
])
|
|
7792
|
+
)
|
|
7793
|
+
};
|
|
7794
|
+
};
|
|
7795
|
+
var mkExecuteValidatorFromSP = (params) => {
|
|
7796
|
+
return {
|
|
7797
|
+
type: "PlutusV3",
|
|
7798
|
+
script: applySingleCborEncoding(
|
|
7799
|
+
applyParamsToScript13(_executeValidator.cborHex, [
|
|
7800
|
+
castExecuteParams({
|
|
7801
|
+
govNFT: fromSystemParamsAssetLucid(params.govNFT),
|
|
7802
|
+
upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
|
|
7803
|
+
iAssetToken: fromSystemParamsAssetLucid(params.iAssetToken),
|
|
7804
|
+
collateralAssetToken: fromSystemParamsAssetLucid(
|
|
7805
|
+
params.collateralAssetToken
|
|
7806
|
+
),
|
|
7807
|
+
stabilityPoolToken: fromSystemParamsAssetLucid(
|
|
7808
|
+
params.stabilityPoolToken
|
|
7809
|
+
),
|
|
7810
|
+
cdpCreatorToken: fromSystemParamsAssetLucid(params.cdpCreatorToken),
|
|
7811
|
+
cdpToken: fromSystemParamsAssetLucid(params.cdpToken),
|
|
7812
|
+
versionRecordToken: fromSystemParamsAssetLucid(
|
|
7813
|
+
params.versionRecordToken
|
|
7814
|
+
),
|
|
7815
|
+
iassetValHash: params.iassetValHash,
|
|
7816
|
+
cdpValHash: params.cdpValHash,
|
|
7817
|
+
sPoolValHash: params.sPoolValHash,
|
|
7818
|
+
versionRegistryValHash: params.versionRegistryValHash,
|
|
7819
|
+
treasuryValHash: params.treasuryValHash
|
|
7820
|
+
})
|
|
7821
|
+
])
|
|
7822
|
+
)
|
|
8227
7823
|
};
|
|
8228
7824
|
};
|
|
8229
7825
|
|
|
8230
|
-
// src/contracts/
|
|
8231
|
-
import {
|
|
7826
|
+
// src/contracts/price-oracle/types.ts
|
|
7827
|
+
import { Data as Data41 } from "@lucid-evolution/lucid";
|
|
7828
|
+
var PriceOracleParamsSchema = Data41.Object({
|
|
7829
|
+
owner: Data41.Bytes(),
|
|
7830
|
+
/** Milliseconds */
|
|
7831
|
+
biasTime: Data41.Integer(),
|
|
7832
|
+
/** Milliseconds */
|
|
7833
|
+
expirationPeriod: Data41.Integer()
|
|
7834
|
+
});
|
|
7835
|
+
var PriceOracleParams = PriceOracleParamsSchema;
|
|
7836
|
+
function castPriceOracleParams(params) {
|
|
7837
|
+
return Data41.castTo(params, PriceOracleParams);
|
|
7838
|
+
}
|
|
7839
|
+
|
|
7840
|
+
// src/contracts/stability-pool/queries.ts
|
|
7841
|
+
import { toHex as toHex11 } from "@lucid-evolution/lucid";
|
|
8232
7842
|
import {
|
|
8233
|
-
assetClassToUnit as
|
|
8234
|
-
assetClassValueOf as assetClassValueOf7,
|
|
8235
|
-
getRandomElement as getRandomElement2,
|
|
7843
|
+
assetClassToUnit as assetClassToUnit5,
|
|
8236
7844
|
matchSingle as matchSingle4
|
|
8237
7845
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
8238
|
-
|
|
8239
|
-
|
|
8240
|
-
|
|
8241
|
-
|
|
8242
|
-
|
|
7846
|
+
import { option as O16, array as A10, function as F19 } from "fp-ts";
|
|
7847
|
+
async function findStabilityPool(lucid, sysParams, iassetName) {
|
|
7848
|
+
const spUtxos = await lucid.utxosAtWithUnit(
|
|
7849
|
+
{ hash: sysParams.validatorHashes.stabilityPoolHash, type: "Script" },
|
|
7850
|
+
assetClassToUnit5(
|
|
7851
|
+
fromSystemParamsAsset(sysParams.stabilityPoolParams.stabilityPoolToken)
|
|
7852
|
+
)
|
|
7853
|
+
);
|
|
7854
|
+
return matchSingle4(
|
|
7855
|
+
F19.pipe(
|
|
7856
|
+
spUtxos.map(
|
|
7857
|
+
(utxo) => F19.pipe(
|
|
7858
|
+
O16.fromNullable(utxo.datum),
|
|
7859
|
+
O16.flatMap(parseStabilityPoolDatum),
|
|
7860
|
+
O16.flatMap((datum) => {
|
|
7861
|
+
if (toHex11(datum.iasset) == toHex11(iassetName)) {
|
|
7862
|
+
return O16.some({ utxo, datum });
|
|
7863
|
+
} else {
|
|
7864
|
+
return O16.none;
|
|
7865
|
+
}
|
|
7866
|
+
})
|
|
7867
|
+
)
|
|
7868
|
+
),
|
|
7869
|
+
A10.compact
|
|
7870
|
+
),
|
|
7871
|
+
(res) => new Error(
|
|
7872
|
+
"Expected a single Stability Pool UTXO.: " + JSON.stringify(res)
|
|
8243
7873
|
)
|
|
8244
7874
|
);
|
|
8245
7875
|
}
|
|
8246
|
-
async function
|
|
7876
|
+
async function findStabilityPoolAccount(lucid, sysParams, owner, iassetName) {
|
|
7877
|
+
const spUtxos = await lucid.utxosAt({
|
|
7878
|
+
hash: sysParams.validatorHashes.stabilityPoolHash,
|
|
7879
|
+
type: "Script"
|
|
7880
|
+
});
|
|
8247
7881
|
return matchSingle4(
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
7882
|
+
F19.pipe(
|
|
7883
|
+
spUtxos.map(
|
|
7884
|
+
(utxo) => F19.pipe(
|
|
7885
|
+
O16.fromNullable(utxo.datum),
|
|
7886
|
+
O16.flatMap(parseAccountDatum),
|
|
7887
|
+
O16.flatMap((datum) => {
|
|
7888
|
+
if (toHex11(datum.iasset) == toHex11(iassetName) && toHex11(datum.owner) == owner) {
|
|
7889
|
+
return O16.some({ utxo, datum });
|
|
7890
|
+
} else {
|
|
7891
|
+
return O16.none;
|
|
7892
|
+
}
|
|
7893
|
+
})
|
|
7894
|
+
)
|
|
7895
|
+
),
|
|
7896
|
+
A10.compact
|
|
7897
|
+
),
|
|
7898
|
+
(res) => new Error("Expected a single Account UTXO.: " + JSON.stringify(res))
|
|
7899
|
+
);
|
|
7900
|
+
}
|
|
7901
|
+
async function findE2s2sSnapshots(lucid, sysParams, iassetName) {
|
|
7902
|
+
const spUtxos = await lucid.utxosAtWithUnit(
|
|
7903
|
+
mkStabilityPoolAddr(lucid, sysParams),
|
|
7904
|
+
assetClassToUnit5(
|
|
7905
|
+
fromSystemParamsAsset(
|
|
7906
|
+
sysParams.stabilityPoolParams.snapshotEpochToScaleToSumToken
|
|
7907
|
+
)
|
|
7908
|
+
)
|
|
7909
|
+
);
|
|
7910
|
+
return F19.pipe(
|
|
7911
|
+
spUtxos.map(
|
|
7912
|
+
(utxo) => F19.pipe(
|
|
7913
|
+
O16.fromNullable(utxo.datum),
|
|
7914
|
+
O16.flatMap(parseSnapshotEpochToScaleToSumDatum),
|
|
7915
|
+
O16.flatMap((datum) => {
|
|
7916
|
+
if (toHex11(datum.iasset) == toHex11(iassetName)) {
|
|
7917
|
+
return O16.some({ utxo, datum });
|
|
7918
|
+
} else {
|
|
7919
|
+
return O16.none;
|
|
7920
|
+
}
|
|
7921
|
+
})
|
|
7922
|
+
)
|
|
7923
|
+
),
|
|
7924
|
+
A10.compact
|
|
7925
|
+
);
|
|
7926
|
+
}
|
|
7927
|
+
|
|
7928
|
+
// src/contracts/stability-pool/transactions.ts
|
|
7929
|
+
import {
|
|
7930
|
+
fromText as fromText8,
|
|
7931
|
+
Data as Data42,
|
|
7932
|
+
fromHex as fromHex11,
|
|
7933
|
+
toHex as toHex12,
|
|
7934
|
+
addAssets as addAssets11,
|
|
7935
|
+
credentialToAddress as credentialToAddress3
|
|
7936
|
+
} from "@lucid-evolution/lucid";
|
|
7937
|
+
import {
|
|
7938
|
+
adaAssetClass as adaAssetClass4,
|
|
7939
|
+
addressFromBech32 as addressFromBech322,
|
|
7940
|
+
addressToBech32 as addressToBech322,
|
|
7941
|
+
assetClassValueOf as assetClassValueOf8,
|
|
7942
|
+
estimateUtxoMinLovelace as estimateUtxoMinLovelace3,
|
|
7943
|
+
lovelacesAmt as lovelacesAmt2,
|
|
7944
|
+
matchSingle as matchSingle5,
|
|
7945
|
+
mkAssetsOf as mkAssetsOf8,
|
|
7946
|
+
mkLovelacesOf as mkLovelacesOf5,
|
|
7947
|
+
negateAssets as negateAssets4
|
|
7948
|
+
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
7949
|
+
import { match as match17, P as P17 } from "ts-pattern";
|
|
7950
|
+
async function requestSpAccountCreation(assetAscii, amount, sysParams, lucid) {
|
|
7951
|
+
const [pkh, _skh] = await addrDetails(lucid);
|
|
7952
|
+
const iasset = fromHex11(fromText8(assetAscii));
|
|
7953
|
+
const iassetAssetClass = {
|
|
7954
|
+
currencySymbol: fromHex11(
|
|
7955
|
+
sysParams.stabilityPoolParams.assetSymbol.unCurrencySymbol
|
|
7956
|
+
),
|
|
7957
|
+
tokenName: iasset
|
|
7958
|
+
};
|
|
7959
|
+
const datum = {
|
|
7960
|
+
owner: fromHex11(pkh.hash),
|
|
7961
|
+
iasset,
|
|
7962
|
+
state: { ...initSpState, depositVal: mkSPInteger(amount) },
|
|
7963
|
+
assetSums: [],
|
|
7964
|
+
request: "Create",
|
|
7965
|
+
lastRequestProcessingTime: 0n
|
|
7966
|
+
};
|
|
7967
|
+
return lucid.newTx().pay.ToContract(
|
|
7968
|
+
credentialToAddress3(
|
|
7969
|
+
lucid.config().network,
|
|
7970
|
+
{
|
|
7971
|
+
hash: sysParams.validatorHashes.stabilityPoolHash,
|
|
7972
|
+
type: "Script"
|
|
7973
|
+
},
|
|
7974
|
+
sysParams.stabilityPoolParams.stakeCredential != null ? fromSysParamsCredential(
|
|
7975
|
+
sysParams.stabilityPoolParams.stakeCredential
|
|
7976
|
+
) : void 0
|
|
7977
|
+
),
|
|
7978
|
+
{
|
|
7979
|
+
kind: "inline",
|
|
7980
|
+
value: serialiseStabilityPoolDatum({ Account: datum })
|
|
7981
|
+
},
|
|
7982
|
+
addAssets11(
|
|
7983
|
+
mkAssetsOf8(iassetAssetClass, amount),
|
|
7984
|
+
mkLovelacesOf5(
|
|
7985
|
+
// TODO: Calculate a more accurate amount to just cover costs.
|
|
7986
|
+
// This should cover the account creation fee,
|
|
7987
|
+
// the minimum ADA for the account UTxO and the transaction fee.
|
|
7988
|
+
BigInt(sysParams.stabilityPoolParams.accountCreateFeeLovelaces) + 3000000n
|
|
7989
|
+
)
|
|
7990
|
+
)
|
|
7991
|
+
).addSignerKey(pkh.hash);
|
|
7992
|
+
}
|
|
7993
|
+
async function requestSpAccountAdjustment(amount, accountUtxo, sysParams, lucid) {
|
|
7994
|
+
const myAddress = await lucid.wallet().address();
|
|
7995
|
+
const stabilityPoolScriptRef = matchSingle5(
|
|
7996
|
+
await lucid.utxosByOutRef([
|
|
7997
|
+
fromSystemParamsScriptRef(
|
|
7998
|
+
sysParams.scriptReferences.stabilityPoolValidatorRef
|
|
7999
|
+
)
|
|
8000
|
+
]),
|
|
8001
|
+
(_) => new Error("Expected a single stability pool Ref Script UTXO")
|
|
8002
|
+
);
|
|
8003
|
+
const oldAccountDatum = parseAccountDatumOrThrow(
|
|
8004
|
+
getInlineDatumOrThrow(accountUtxo)
|
|
8005
|
+
);
|
|
8006
|
+
const newAccountDatum = {
|
|
8007
|
+
...oldAccountDatum,
|
|
8008
|
+
request: {
|
|
8009
|
+
Adjust: {
|
|
8010
|
+
amount,
|
|
8011
|
+
outputAddress: addressFromBech322(myAddress)
|
|
8012
|
+
}
|
|
8013
|
+
}
|
|
8014
|
+
};
|
|
8015
|
+
return lucid.newTx().readFrom([stabilityPoolScriptRef]).collectFrom(
|
|
8016
|
+
[accountUtxo],
|
|
8017
|
+
serialiseStabilityPoolRedeemer({
|
|
8018
|
+
RequestAction: {
|
|
8019
|
+
Adjust: {
|
|
8020
|
+
amount,
|
|
8021
|
+
outputAddress: addressFromBech322(myAddress)
|
|
8022
|
+
}
|
|
8023
|
+
}
|
|
8024
|
+
})
|
|
8025
|
+
).pay.ToContract(
|
|
8026
|
+
accountUtxo.address,
|
|
8027
|
+
{
|
|
8028
|
+
kind: "inline",
|
|
8029
|
+
value: serialiseStabilityPoolDatum({
|
|
8030
|
+
Account: newAccountDatum
|
|
8031
|
+
})
|
|
8032
|
+
},
|
|
8033
|
+
addAssets11(
|
|
8034
|
+
mkLovelacesOf5(
|
|
8035
|
+
// TODO: Calculate a more accurate amount to just cover costs.
|
|
8036
|
+
// This should cover the minimum ADA for 2 UTxOs (account and
|
|
8037
|
+
// rewards withdrawal) and the transaction fee.
|
|
8038
|
+
5000000n
|
|
8039
|
+
),
|
|
8040
|
+
mkAssetsOf8(
|
|
8041
|
+
fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
|
|
8042
|
+
1n
|
|
8043
|
+
),
|
|
8044
|
+
amount > 0n ? mkAssetsOf8(
|
|
8045
|
+
{
|
|
8046
|
+
currencySymbol: fromHex11(
|
|
8047
|
+
sysParams.stabilityPoolParams.assetSymbol.unCurrencySymbol
|
|
8048
|
+
),
|
|
8049
|
+
tokenName: oldAccountDatum.iasset
|
|
8050
|
+
},
|
|
8051
|
+
amount
|
|
8052
|
+
) : {}
|
|
8053
|
+
)
|
|
8054
|
+
).addSignerKey(toHex12(oldAccountDatum.owner));
|
|
8055
|
+
}
|
|
8056
|
+
async function requestSpAccountClosure(accountUtxo, sysParams, lucid, maxTxFee = BASE_MAX_TX_FEE) {
|
|
8057
|
+
const myAddress = await lucid.wallet().address();
|
|
8058
|
+
const stabilityPoolScriptRef = matchSingle5(
|
|
8059
|
+
await lucid.utxosByOutRef([
|
|
8060
|
+
fromSystemParamsScriptRef(
|
|
8061
|
+
sysParams.scriptReferences.stabilityPoolValidatorRef
|
|
8062
|
+
)
|
|
8063
|
+
]),
|
|
8064
|
+
(_) => new Error("Expected a single stability pool Ref Script UTXO")
|
|
8065
|
+
);
|
|
8066
|
+
const request = {
|
|
8067
|
+
Close: {
|
|
8068
|
+
outputAddress: addressFromBech322(myAddress),
|
|
8069
|
+
maxTxFee
|
|
8070
|
+
}
|
|
8071
|
+
};
|
|
8072
|
+
const oldAccountDatum = parseAccountDatumOrThrow(
|
|
8073
|
+
getInlineDatumOrThrow(accountUtxo)
|
|
8074
|
+
);
|
|
8075
|
+
const newAccountDatum = {
|
|
8076
|
+
...oldAccountDatum,
|
|
8077
|
+
request
|
|
8078
|
+
};
|
|
8079
|
+
return lucid.newTx().readFrom([stabilityPoolScriptRef]).collectFrom(
|
|
8080
|
+
[accountUtxo],
|
|
8081
|
+
serialiseStabilityPoolRedeemer({ RequestAction: request })
|
|
8082
|
+
).pay.ToContract(
|
|
8083
|
+
accountUtxo.address,
|
|
8084
|
+
{
|
|
8085
|
+
kind: "inline",
|
|
8086
|
+
value: serialiseStabilityPoolDatum({ Account: newAccountDatum })
|
|
8087
|
+
},
|
|
8088
|
+
addAssets11(
|
|
8089
|
+
mkLovelacesOf5(
|
|
8090
|
+
// TODO: Calculate a more accurate amount to just cover costs.
|
|
8091
|
+
// This should cover the minimum ADA for the rewards UTxO and the transaction fee.
|
|
8092
|
+
3000000n
|
|
8093
|
+
),
|
|
8094
|
+
mkAssetsOf8(
|
|
8095
|
+
fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
|
|
8096
|
+
1n
|
|
8097
|
+
)
|
|
8098
|
+
)
|
|
8099
|
+
).addSignerKey(toHex12(oldAccountDatum.owner));
|
|
8100
|
+
}
|
|
8101
|
+
async function processSpRequestAuxiliary(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid, txFee) {
|
|
8102
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
8103
|
+
const stabilityPoolScriptRef = matchSingle5(
|
|
8104
|
+
await lucid.utxosByOutRef([
|
|
8105
|
+
fromSystemParamsScriptRef(
|
|
8106
|
+
sysParams.scriptReferences.stabilityPoolValidatorRef
|
|
8107
|
+
)
|
|
8108
|
+
]),
|
|
8109
|
+
(_) => new Error("Expected a single stability pool Ref Script UTXO")
|
|
8110
|
+
);
|
|
8111
|
+
const accountDatum = parseAccountDatumOrThrow(
|
|
8112
|
+
getInlineDatumOrThrow(accountUtxo)
|
|
8113
|
+
);
|
|
8114
|
+
const stabilityPoolDatum = parseStabilityPoolDatumOrThrow(
|
|
8115
|
+
getInlineDatumOrThrow(stabilityPoolUtxo)
|
|
8116
|
+
);
|
|
8117
|
+
const baseRefInputs = [iAssetUtxo, stabilityPoolScriptRef];
|
|
8118
|
+
const validFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
|
|
8119
|
+
const tx = lucid.newTx().validFrom(validFrom).validTo(validFrom + sysParams.stabilityPoolParams.accountProcessingBiasMs).readFrom(baseRefInputs).collectFrom([stabilityPoolUtxo], {
|
|
8120
|
+
kind: "selected",
|
|
8121
|
+
inputs: [stabilityPoolUtxo, accountUtxo],
|
|
8122
|
+
makeRedeemer: (indices) => serialiseStabilityPoolRedeemer({
|
|
8123
|
+
ProcessRequestPool: {
|
|
8124
|
+
poolInputIdx: indices[0],
|
|
8125
|
+
accountInputIdx: indices[1]
|
|
8126
|
+
}
|
|
8127
|
+
})
|
|
8128
|
+
});
|
|
8129
|
+
if (!accountDatum.request) throw new Error("Account Request is null");
|
|
8130
|
+
const iassetAssetClass = {
|
|
8131
|
+
currencySymbol: fromHex11(
|
|
8132
|
+
sysParams.stabilityPoolParams.assetSymbol.unCurrencySymbol
|
|
8133
|
+
),
|
|
8134
|
+
tokenName: stabilityPoolDatum.iasset
|
|
8135
|
+
};
|
|
8136
|
+
await match17(accountDatum.request).with("Create", async (_) => {
|
|
8137
|
+
const accountTokenScriptRef = matchSingle5(
|
|
8138
|
+
await lucid.utxosByOutRef([
|
|
8139
|
+
fromSystemParamsScriptRef(
|
|
8140
|
+
sysParams.scriptReferences.authTokenPolicies.accountTokenRef
|
|
8141
|
+
)
|
|
8142
|
+
]),
|
|
8143
|
+
(_2) => new Error("Expected a single cdp auth token policy Ref Script UTXO")
|
|
8144
|
+
);
|
|
8145
|
+
const requestDepositAmt = assetClassValueOf8(
|
|
8146
|
+
accountUtxo.assets,
|
|
8147
|
+
iassetAssetClass
|
|
8148
|
+
);
|
|
8149
|
+
const poolAddr = credentialToAddress3(
|
|
8150
|
+
lucid.config().network,
|
|
8151
|
+
{
|
|
8152
|
+
hash: sysParams.validatorHashes.stabilityPoolHash,
|
|
8153
|
+
type: "Script"
|
|
8154
|
+
},
|
|
8155
|
+
sysParams.stabilityPoolParams.stakeCredential != null ? fromSysParamsCredential(
|
|
8156
|
+
sysParams.stabilityPoolParams.stakeCredential
|
|
8157
|
+
) : void 0
|
|
8158
|
+
);
|
|
8159
|
+
const accountOutputAdaAmt = lovelacesAmt2(accountUtxo.assets) - BigInt(sysParams.stabilityPoolParams.accountCreateFeeLovelaces) - txFee;
|
|
8160
|
+
const accountTokenVal = mkAssetsOf8(
|
|
8161
|
+
fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
|
|
8162
|
+
1n
|
|
8163
|
+
);
|
|
8164
|
+
const accountOutputDatum = serialiseStabilityPoolDatum({
|
|
8165
|
+
Account: {
|
|
8166
|
+
owner: accountDatum.owner,
|
|
8167
|
+
iasset: stabilityPoolDatum.iasset,
|
|
8168
|
+
state: {
|
|
8169
|
+
...stabilityPoolDatum.state,
|
|
8170
|
+
depositVal: mkSPInteger(requestDepositAmt)
|
|
8171
|
+
},
|
|
8172
|
+
assetSums: stabilityPoolDatum.assetStates.map(([key, val]) => [
|
|
8173
|
+
key,
|
|
8174
|
+
val.currentSumVal
|
|
8175
|
+
]),
|
|
8176
|
+
request: null,
|
|
8177
|
+
lastRequestProcessingTime: currentTime
|
|
8178
|
+
}
|
|
8179
|
+
});
|
|
8180
|
+
const accountOutMinUtxoLovelace = estimateUtxoMinLovelace3(
|
|
8181
|
+
lucid.config().protocolParameters,
|
|
8182
|
+
poolAddr,
|
|
8183
|
+
accountTokenVal,
|
|
8184
|
+
{ InlineDatum: { datum: accountOutputDatum } }
|
|
8185
|
+
);
|
|
8186
|
+
if (accountOutputAdaAmt < accountOutMinUtxoLovelace) {
|
|
8187
|
+
throw new Error("Request doesn't have enough ADA to be processed.");
|
|
8188
|
+
}
|
|
8189
|
+
tx.readFrom([accountTokenScriptRef]).collectFrom([accountUtxo], {
|
|
8190
|
+
kind: "selected",
|
|
8191
|
+
inputs: [stabilityPoolUtxo, accountUtxo],
|
|
8192
|
+
makeRedeemer: (indices) => serialiseStabilityPoolRedeemer({
|
|
8193
|
+
ProcessRequestAccount: {
|
|
8194
|
+
poolInputIdx: indices[0],
|
|
8195
|
+
accountInputIdx: indices[1],
|
|
8196
|
+
e2s2sIdxs: [],
|
|
8197
|
+
currentTime
|
|
8198
|
+
}
|
|
8199
|
+
})
|
|
8200
|
+
}).mintAssets(accountTokenVal, Data42.void()).pay.ToContract(
|
|
8201
|
+
poolAddr,
|
|
8202
|
+
{
|
|
8203
|
+
kind: "inline",
|
|
8204
|
+
value: serialiseStabilityPoolDatum({
|
|
8205
|
+
StabilityPool: liquidationHelper(
|
|
8206
|
+
{
|
|
8207
|
+
...stabilityPoolDatum,
|
|
8208
|
+
state: {
|
|
8209
|
+
...stabilityPoolDatum.state,
|
|
8210
|
+
depositVal: spAdd(
|
|
8211
|
+
stabilityPoolDatum.state.depositVal,
|
|
8212
|
+
mkSPInteger(requestDepositAmt)
|
|
8213
|
+
)
|
|
8214
|
+
}
|
|
8215
|
+
},
|
|
8216
|
+
adaAssetClass4,
|
|
8217
|
+
0n,
|
|
8218
|
+
BigInt(sysParams.stabilityPoolParams.accountCreateFeeLovelaces)
|
|
8219
|
+
)
|
|
8220
|
+
})
|
|
8221
|
+
},
|
|
8222
|
+
addAssets11(
|
|
8223
|
+
stabilityPoolUtxo.assets,
|
|
8224
|
+
mkAssetsOf8(iassetAssetClass, requestDepositAmt),
|
|
8225
|
+
mkLovelacesOf5(
|
|
8226
|
+
BigInt(sysParams.stabilityPoolParams.accountCreateFeeLovelaces)
|
|
8227
|
+
)
|
|
8228
|
+
)
|
|
8229
|
+
).pay.ToContract(
|
|
8230
|
+
poolAddr,
|
|
8231
|
+
{
|
|
8232
|
+
kind: "inline",
|
|
8233
|
+
value: accountOutputDatum
|
|
8234
|
+
},
|
|
8235
|
+
addAssets11(accountTokenVal, mkLovelacesOf5(accountOutputAdaAmt))
|
|
8236
|
+
).setMinFee(txFee);
|
|
8237
|
+
}).with({ Adjust: P17.select() }, async (adjustContent) => {
|
|
8238
|
+
const iassetDatum = parseIAssetDatumOrThrow(
|
|
8239
|
+
getInlineDatumOrThrow(iAssetUtxo)
|
|
8240
|
+
);
|
|
8241
|
+
const accountDepositChange = adjustContent.amount;
|
|
8242
|
+
const outputAddress = addressToBech322(
|
|
8243
|
+
adjustContent.outputAddress,
|
|
8244
|
+
lucid.config().network
|
|
8245
|
+
);
|
|
8246
|
+
const e2s2sIdxs = await findRelevantE2s2sIdxs(
|
|
8247
|
+
lucid,
|
|
8248
|
+
stabilityPoolDatum,
|
|
8249
|
+
accountDatum.state,
|
|
8250
|
+
allE2s2sSnapshotOrefs
|
|
8251
|
+
);
|
|
8252
|
+
const { updatedAccountContent, reward } = updateAccount(
|
|
8253
|
+
stabilityPoolDatum,
|
|
8254
|
+
accountDatum,
|
|
8255
|
+
e2s2sIdxs
|
|
8256
|
+
);
|
|
8257
|
+
const isDepositOrRewardWithdrawal = accountDepositChange >= 0;
|
|
8258
|
+
const accountBalanceChange = isDepositOrRewardWithdrawal ? accountDepositChange : bigintMax(
|
|
8259
|
+
accountDepositChange,
|
|
8260
|
+
-fromSPInteger(updatedAccountContent.state.depositVal)
|
|
8261
|
+
);
|
|
8262
|
+
const newPoolDepositExcludingFee = spZeroNegatives(
|
|
8263
|
+
spAdd(
|
|
8264
|
+
stabilityPoolDatum.state.depositVal,
|
|
8265
|
+
mkSPInteger(accountBalanceChange)
|
|
8266
|
+
)
|
|
8267
|
+
);
|
|
8268
|
+
const withdrawalFeeAmt = isDepositOrRewardWithdrawal || newPoolDepositExcludingFee.value === 0n ? 0n : calculateFeeFromRatio(
|
|
8269
|
+
iassetDatum.stabilityPoolWithdrawalFeeRatio,
|
|
8270
|
+
-accountBalanceChange
|
|
8271
|
+
);
|
|
8272
|
+
const newPoolState = updatePoolStateWhenWithdrawalFee(withdrawalFeeAmt, {
|
|
8273
|
+
...stabilityPoolDatum.state,
|
|
8274
|
+
depositVal: newPoolDepositExcludingFee
|
|
8275
|
+
});
|
|
8276
|
+
const { e2s2sRefInputs, mkProcessRequestAccountRedeemerContent } = createProcessRequestAccountRedeemer(
|
|
8277
|
+
e2s2sIdxs,
|
|
8278
|
+
baseRefInputs,
|
|
8279
|
+
currentTime
|
|
8280
|
+
);
|
|
8281
|
+
if (e2s2sRefInputs.length > 0) {
|
|
8282
|
+
tx.readFrom(e2s2sRefInputs);
|
|
8283
|
+
}
|
|
8284
|
+
tx.collectFrom([accountUtxo], {
|
|
8285
|
+
kind: "selected",
|
|
8286
|
+
inputs: [stabilityPoolUtxo, accountUtxo],
|
|
8287
|
+
makeRedeemer: (indices) => {
|
|
8288
|
+
return serialiseStabilityPoolRedeemer({
|
|
8289
|
+
ProcessRequestAccount: mkProcessRequestAccountRedeemerContent(
|
|
8290
|
+
indices[0],
|
|
8291
|
+
indices[1]
|
|
8292
|
+
)
|
|
8293
|
+
});
|
|
8294
|
+
}
|
|
8295
|
+
}).pay.ToContract(
|
|
8296
|
+
stabilityPoolUtxo.address,
|
|
8297
|
+
{
|
|
8298
|
+
kind: "inline",
|
|
8299
|
+
value: serialiseStabilityPoolDatum({
|
|
8300
|
+
StabilityPool: {
|
|
8301
|
+
...stabilityPoolDatum,
|
|
8302
|
+
state: newPoolState
|
|
8303
|
+
}
|
|
8304
|
+
})
|
|
8305
|
+
},
|
|
8306
|
+
addAssets11(
|
|
8307
|
+
stabilityPoolUtxo.assets,
|
|
8308
|
+
negateAssets4(reward),
|
|
8309
|
+
mkAssetsOf8(iassetAssetClass, accountBalanceChange + withdrawalFeeAmt)
|
|
8310
|
+
)
|
|
8311
|
+
);
|
|
8312
|
+
const theoreticalOwnerOutputVal = addAssets11(
|
|
8313
|
+
reward,
|
|
8314
|
+
isDepositOrRewardWithdrawal ? {} : mkAssetsOf8(
|
|
8315
|
+
iassetAssetClass,
|
|
8316
|
+
-accountBalanceChange - withdrawalFeeAmt
|
|
8317
|
+
)
|
|
8318
|
+
);
|
|
8319
|
+
const ownerOutputDat = serialiseActionReturnDatum({
|
|
8320
|
+
IndigoStabilityPoolAccountAdjustment: {
|
|
8321
|
+
txHash: fromHex11(accountUtxo.txHash),
|
|
8322
|
+
outputIndex: BigInt(accountUtxo.outputIndex)
|
|
8323
|
+
}
|
|
8324
|
+
});
|
|
8325
|
+
const ownerOutputMinUtxoLovelace = estimateUtxoMinLovelace3(
|
|
8326
|
+
lucid.config().protocolParameters,
|
|
8327
|
+
outputAddress,
|
|
8328
|
+
theoreticalOwnerOutputVal,
|
|
8329
|
+
{ InlineDatum: { datum: ownerOutputDat } }
|
|
8330
|
+
);
|
|
8331
|
+
const extraOwnerOutputLovelacesAmt = lovelacesAmt2(theoreticalOwnerOutputVal) >= ownerOutputMinUtxoLovelace ? 0n : ownerOutputMinUtxoLovelace - lovelacesAmt2(theoreticalOwnerOutputVal);
|
|
8332
|
+
const actualOwnerOutputVal = addAssets11(
|
|
8333
|
+
theoreticalOwnerOutputVal,
|
|
8334
|
+
mkLovelacesOf5(extraOwnerOutputLovelacesAmt)
|
|
8335
|
+
);
|
|
8336
|
+
const accountOutputDat = serialiseStabilityPoolDatum({
|
|
8337
|
+
Account: {
|
|
8338
|
+
...updatedAccountContent,
|
|
8339
|
+
state: {
|
|
8340
|
+
...updatedAccountContent.state,
|
|
8341
|
+
depositVal: spAdd(
|
|
8342
|
+
updatedAccountContent.state.depositVal,
|
|
8343
|
+
mkSPInteger(accountBalanceChange)
|
|
8344
|
+
)
|
|
8345
|
+
},
|
|
8346
|
+
request: null,
|
|
8347
|
+
lastRequestProcessingTime: currentTime
|
|
8348
|
+
}
|
|
8349
|
+
});
|
|
8350
|
+
const accountOutputValWithoutAda = mkAssetsOf8(
|
|
8351
|
+
fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
|
|
8352
|
+
1n
|
|
8353
|
+
);
|
|
8354
|
+
const accountOutMinUtxoLovelace = estimateUtxoMinLovelace3(
|
|
8355
|
+
lucid.config().protocolParameters,
|
|
8356
|
+
stabilityPoolUtxo.address,
|
|
8357
|
+
accountOutputValWithoutAda,
|
|
8358
|
+
{ InlineDatum: { datum: accountOutputDat } }
|
|
8359
|
+
);
|
|
8360
|
+
const accountOutputAdaAmt = lovelacesAmt2(accountUtxo.assets) - extraOwnerOutputLovelacesAmt - txFee;
|
|
8361
|
+
if (accountOutputAdaAmt < accountOutMinUtxoLovelace) {
|
|
8362
|
+
throw new Error("Account doesn't have enough ADA to be processed.");
|
|
8363
|
+
}
|
|
8364
|
+
tx.pay.ToContract(
|
|
8365
|
+
stabilityPoolUtxo.address,
|
|
8366
|
+
{
|
|
8367
|
+
kind: "inline",
|
|
8368
|
+
value: accountOutputDat
|
|
8369
|
+
},
|
|
8370
|
+
addAssets11(
|
|
8371
|
+
accountOutputValWithoutAda,
|
|
8372
|
+
mkLovelacesOf5(accountOutputAdaAmt)
|
|
8373
|
+
)
|
|
8374
|
+
).pay.ToAddressWithData(
|
|
8375
|
+
outputAddress,
|
|
8376
|
+
{
|
|
8377
|
+
kind: "inline",
|
|
8378
|
+
value: ownerOutputDat
|
|
8379
|
+
},
|
|
8380
|
+
actualOwnerOutputVal
|
|
8381
|
+
).setMinFee(txFee);
|
|
8382
|
+
}).with({ Close: P17.select() }, async (closeContent) => {
|
|
8383
|
+
if (txFee > closeContent.maxTxFee) {
|
|
8384
|
+
throw new Error("Account doesn't allow current transaction fee.");
|
|
8385
|
+
}
|
|
8386
|
+
const accountTokenScriptRef = matchSingle5(
|
|
8387
|
+
await lucid.utxosByOutRef([
|
|
8388
|
+
fromSystemParamsScriptRef(
|
|
8389
|
+
sysParams.scriptReferences.authTokenPolicies.accountTokenRef
|
|
8390
|
+
)
|
|
8391
|
+
]),
|
|
8392
|
+
(_) => new Error("Expected a single cdp auth token policy Ref Script UTXO")
|
|
8393
|
+
);
|
|
8394
|
+
const iassetDatum = parseIAssetDatumOrThrow(
|
|
8395
|
+
getInlineDatumOrThrow(iAssetUtxo)
|
|
8396
|
+
);
|
|
8397
|
+
const outputAddress = addressToBech322(
|
|
8398
|
+
closeContent.outputAddress,
|
|
8399
|
+
lucid.config().network
|
|
8400
|
+
);
|
|
8401
|
+
const e2s2sIdxs = await findRelevantE2s2sIdxs(
|
|
8402
|
+
lucid,
|
|
8403
|
+
stabilityPoolDatum,
|
|
8404
|
+
accountDatum.state,
|
|
8405
|
+
allE2s2sSnapshotOrefs
|
|
8406
|
+
);
|
|
8407
|
+
const { updatedAccountContent, reward } = updateAccount(
|
|
8408
|
+
stabilityPoolDatum,
|
|
8409
|
+
accountDatum,
|
|
8410
|
+
e2s2sIdxs
|
|
8411
|
+
);
|
|
8412
|
+
const newPoolDepositExcludingFee = spZeroNegatives(
|
|
8413
|
+
spSub(
|
|
8414
|
+
stabilityPoolDatum.state.depositVal,
|
|
8415
|
+
updatedAccountContent.state.depositVal
|
|
8416
|
+
)
|
|
8417
|
+
);
|
|
8418
|
+
const withdrawnAmt = zeroNegatives(
|
|
8419
|
+
fromSPInteger(updatedAccountContent.state.depositVal)
|
|
8420
|
+
);
|
|
8421
|
+
const withdrawalFeeAmt = newPoolDepositExcludingFee.value === 0n ? 0n : calculateFeeFromRatio(
|
|
8422
|
+
iassetDatum.stabilityPoolWithdrawalFeeRatio,
|
|
8423
|
+
withdrawnAmt
|
|
8424
|
+
);
|
|
8425
|
+
const newPoolState = updatePoolStateWhenWithdrawalFee(withdrawalFeeAmt, {
|
|
8426
|
+
...stabilityPoolDatum.state,
|
|
8427
|
+
depositVal: newPoolDepositExcludingFee
|
|
8428
|
+
});
|
|
8429
|
+
const { e2s2sRefInputs, mkProcessRequestAccountRedeemerContent } = createProcessRequestAccountRedeemer(
|
|
8430
|
+
e2s2sIdxs,
|
|
8431
|
+
[...baseRefInputs, accountTokenScriptRef],
|
|
8432
|
+
currentTime
|
|
8433
|
+
);
|
|
8434
|
+
if (e2s2sRefInputs.length > 0) {
|
|
8435
|
+
tx.readFrom(e2s2sRefInputs);
|
|
8436
|
+
}
|
|
8437
|
+
tx.readFrom([accountTokenScriptRef]).collectFrom([accountUtxo], {
|
|
8438
|
+
kind: "selected",
|
|
8439
|
+
inputs: [stabilityPoolUtxo, accountUtxo],
|
|
8440
|
+
makeRedeemer: (indices) => {
|
|
8441
|
+
return serialiseStabilityPoolRedeemer({
|
|
8442
|
+
ProcessRequestAccount: mkProcessRequestAccountRedeemerContent(
|
|
8443
|
+
indices[0],
|
|
8444
|
+
indices[1]
|
|
8445
|
+
)
|
|
8446
|
+
});
|
|
8447
|
+
}
|
|
8448
|
+
}).mintAssets(
|
|
8449
|
+
mkAssetsOf8(
|
|
8450
|
+
fromSystemParamsAsset(sysParams.stabilityPoolParams.accountToken),
|
|
8451
|
+
-1n
|
|
8252
8452
|
),
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
|
|
8256
|
-
|
|
8453
|
+
Data42.void()
|
|
8454
|
+
).pay.ToContract(
|
|
8455
|
+
stabilityPoolUtxo.address,
|
|
8456
|
+
{
|
|
8457
|
+
kind: "inline",
|
|
8458
|
+
value: serialiseStabilityPoolDatum({
|
|
8459
|
+
StabilityPool: {
|
|
8460
|
+
...stabilityPoolDatum,
|
|
8461
|
+
state: newPoolState
|
|
8462
|
+
}
|
|
8463
|
+
})
|
|
8464
|
+
},
|
|
8465
|
+
addAssets11(
|
|
8466
|
+
stabilityPoolUtxo.assets,
|
|
8467
|
+
negateAssets4(reward),
|
|
8468
|
+
mkAssetsOf8(iassetAssetClass, -withdrawnAmt + withdrawalFeeAmt)
|
|
8257
8469
|
)
|
|
8258
|
-
)
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
|
|
8264
|
-
|
|
8265
|
-
|
|
8266
|
-
|
|
8267
|
-
|
|
8470
|
+
).pay.ToAddressWithData(
|
|
8471
|
+
outputAddress,
|
|
8472
|
+
{
|
|
8473
|
+
kind: "inline",
|
|
8474
|
+
value: serialiseActionReturnDatum({
|
|
8475
|
+
IndigoStabilityPoolAccountClosure: {
|
|
8476
|
+
txHash: fromHex11(accountUtxo.txHash),
|
|
8477
|
+
outputIndex: BigInt(accountUtxo.outputIndex)
|
|
8478
|
+
}
|
|
8479
|
+
})
|
|
8480
|
+
},
|
|
8481
|
+
addAssets11(
|
|
8482
|
+
mkLovelacesOf5(lovelacesAmt2(accountUtxo.assets) - txFee),
|
|
8483
|
+
reward,
|
|
8484
|
+
mkAssetsOf8(iassetAssetClass, withdrawnAmt - withdrawalFeeAmt)
|
|
8268
8485
|
)
|
|
8269
|
-
)
|
|
8270
|
-
);
|
|
8271
|
-
return
|
|
8272
|
-
O14.fromNullable(getRandomElement2(allCollectors)),
|
|
8273
|
-
O14.match(() => {
|
|
8274
|
-
throw new Error("Expected some non-admin interest collector UTXOs.");
|
|
8275
|
-
}, F17.identity)
|
|
8276
|
-
);
|
|
8277
|
-
}
|
|
8278
|
-
|
|
8279
|
-
// src/contracts/version-registry/types.ts
|
|
8280
|
-
import { Data as Data39 } from "@lucid-evolution/lucid";
|
|
8281
|
-
var VersionRecordTokenParamsSchema = Data39.Object({
|
|
8282
|
-
upgradeToken: AssetClassSchema2
|
|
8283
|
-
});
|
|
8284
|
-
var VersionRecordTokenParams = VersionRecordTokenParamsSchema;
|
|
8285
|
-
function castVersionRecordTokenParams(params) {
|
|
8286
|
-
return Data39.castTo(params, VersionRecordTokenParams);
|
|
8287
|
-
}
|
|
8288
|
-
|
|
8289
|
-
// src/contracts/version-registry/scripts.ts
|
|
8290
|
-
import {
|
|
8291
|
-
applyParamsToScript as applyParamsToScript10
|
|
8292
|
-
} from "@lucid-evolution/lucid";
|
|
8293
|
-
|
|
8294
|
-
// src/validators/version-record-policy.ts
|
|
8295
|
-
var _versionRecordTokenPolicy = {
|
|
8296
|
-
type: "PlutusScriptV3",
|
|
8297
|
-
description: "Generated by Aiken",
|
|
8298
|
-
cborHex: "5901a159019e010100229800aba2aba1aba0aab9faab9eaab9dab9a488888896600264646644b30013370e900018031baa0018992cc004c032600246018601a003222323322330020020012259800800c00e26464b30013372200c00315980099b8f00600189bad3010002802a01c899802002180a001a01c375c601c00260220028078c8c8cc0040040188966002003003899192cc004cdc8804000c56600266e3c02000626eacc04400a00a807a266008008602a0068078dd718078009809000a02014bd6f7b6300a40013758601660106ea8c02c016601660106ea803922223232330010010042259800800c52f5c113322598009802980498089baa00289980980119802002000c4cc01001000500f18090009809800a0205980099b8748000c02cdd5260103d87980008919b8798009bab3005300d3754003375c6020601a6ea800a6eb8c014c034dd500120084800a2466e21200098009bab3005300d3754003375c6020601a6ea800a6eb8c014c034dd5001200840288a518b2012375c6014600e6ea80062c8028c020004c020c024004c020004c00cdd5004452689b2b200201"
|
|
8299
|
-
};
|
|
8300
|
-
|
|
8301
|
-
// src/validators/version-registry-validator.ts
|
|
8302
|
-
var _versionRegistryValidator = {
|
|
8303
|
-
type: "PlutusScriptV3",
|
|
8304
|
-
description: "Generated by Aiken",
|
|
8305
|
-
cborHex: "585e585c01010029800aba2aba1aab9eaab9dab9a4888896600264653001300600198031803800cc0180092225980099b8748008c01cdd500144c8cc892818050009805180580098041baa0028b200c180300098019baa0068a4d13656400401"
|
|
8306
|
-
};
|
|
8307
|
-
|
|
8308
|
-
// src/contracts/version-registry/scripts.ts
|
|
8309
|
-
function mkVersionRecordTokenPolicy(params) {
|
|
8310
|
-
return {
|
|
8311
|
-
type: "PlutusV3",
|
|
8312
|
-
script: applyParamsToScript10(_versionRecordTokenPolicy.cborHex, [
|
|
8313
|
-
castVersionRecordTokenParams(params)
|
|
8314
|
-
])
|
|
8315
|
-
};
|
|
8316
|
-
}
|
|
8317
|
-
var mkVersionRegistryValidator = () => {
|
|
8318
|
-
return {
|
|
8319
|
-
type: "PlutusV3",
|
|
8320
|
-
script: _versionRegistryValidator.cborHex
|
|
8321
|
-
};
|
|
8322
|
-
};
|
|
8323
|
-
|
|
8324
|
-
// src/contracts/treasury/scripts.ts
|
|
8325
|
-
import { applyParamsToScript as applyParamsToScript11 } from "@lucid-evolution/lucid";
|
|
8326
|
-
|
|
8327
|
-
// src/validators/treasury-validator.ts
|
|
8328
|
-
var _treasuryValidator = {
|
|
8329
|
-
type: "PlutusScriptV3",
|
|
8330
|
-
description: "Generated by Aiken",
|
|
8331
|
-
cborHex: "59225f59225c010100229800aba4aba2aba1aba0aab9faab9eaab9dab9cab9a488888888a60022a660049201293c65787065637465643e2045787065637473206f6e6c792073696e676c65206f776e206f757470757400168a998012493b3c65787065637465643e20416c6c20747265617375727920696e70757473206d75737420757365207468652072696768742072656465656d65722e00168a99801249303c65787065637465643e2048617320746f207265666572656e63652073696e676c65206578656375746520696e70757400168a99801249333c65787065637465643e20457870656374732073696e676c65206f757470757420746f207769746864726177616c206164647200168a998012492d3c65787065637465643e20457870656374732073696e676c6520696e7075742066726f6d20747265617375727900164888896600264653001300e00198071807800cdc3a4005300e00248889660026004601c6ea800e33001300f3754007370e90004dc3a4009370e90034dc3a401091111194c00488c9660026010003159800980c1baa00380145901945660026016003159800980c1baa0038014590194566002600e003159800980c1baa0038014590194566002600c003159800980c1baa0038014590194566002600a0031323232329800980f800cdd6980f801cdd6980f8012444b3001302300489980598110038acc004c03cc078dd5001c4c8c8cc8966002604e00700d8b2048375a60480026eb8c090008c090004c07cdd5001c5901c4590200c07c004c078004c074004c060dd5001c56600266e1d200a0018acc004c060dd5001c00a2c80ca2c80a9015202a405480a9015180b1baa002980c180c8034c0600192223300300d198009180e180e800c888c8cc88cc0080080048966002003003899192cc004cdc8803000c56600266e3c01800626eb4c08000a00a80ea266008008604800680e8dd7180f0009810800a03e3232330010010062259800800c00e26464b30013372201000315980099b8f00800189bab3021002802a03c8998020021812801a03c375c603e0026044002810052f5bded8c029000488c8cc00400400c896600200314bd7044cc8966002600a00513302000233004004001899802002000a036301f00130200014075371090004966002601060306ea80062603860326ea80062c80b246038603a603a00322323300100100322330030013002002980b9baa00d912cc004006200315330180021001405d2598009804980c1baa001891919baf301e301b3754603c60366ea8008004c074c068dd5001448c8cdd7980f180d9baa002001301d301a375400480b26e9520009180e180e980e980e800cdd7a6103d87a800091111919800800802912cc00400626604066ec0dd48029ba60044bd6f7b63044c8cc896600266e4402000a2b30013371e010005198008044dd59810801c01e46604866ec0dd48049ba60010028800a00c89981199bb037520106e9801c01101e44cc08c00ccc01401400501e1bae301e00130230023021001407d222232330010010052259800800c4cc080cdd81ba9005375000897adef6c6089919912cc004cdc8804001456600266e3c02000a330010089bad3021003803c8cc090cdd81ba9009375000200510014019133023337606ea4020dd4003802203c89981180199802802800a03c375c603c0026046004604200280fa244444b30013370e00866e052000003800c4c008cdc0002001a0349baf4c0101a0009111919800800802112cc004006200913298009bae301d0019bab301e00199801801981100120083020001407922232330010010042259800800c40122653001375c603a003375a603c0033300300330220024010604000280f244b3001300a30193754005132323322598009811001c0162c80f8dd6980f8009bad301f002301f001301a375400516405d2232598009805800c4c8c96600260420050048b203c375c603e00260366ea800e2b3001300e0018acc004c06cdd5001c00a2c80e22c80c1018180c9baa00291192cc004c02c00626464b3001302100280245901e1bae301f001301b37540071598009807000c4c8c96600260420050048b203c375c603e00260366ea800e2c80c1018180c9baa002911980e19bb037520046ea00052f5bded8c122232330010010042259800800c4012266006604000266004004604200280f26e9520024888888888888888888888888a600244646600200200644b30010018b44c96600266ebcc0e4c0d8dd500080244c078c0d8dd5000c4cc00c00cc0e8009033181c000a06c911191980d80211801180f181b1baa00159800981218199baa0018918144c004dd5980e981a9baa0019bae303830353754007375c603a606a6ea800d01c448c06a60026eacc074c0d4dd5000cdd7181c181a9baa0039bae301d3035375400680e10314888cc8a600264b30013027303637540031375a606e60746eacc0e8c0dcdd5000c5200040d060720033756005375e6072607400322598009815981b9baa005899b890010028acc004cdc480080144cdc480119b80001482026fb80a2941035206a4888966002007159800980100344cc00401120008a5040dd1325980099baf4c01014000303a0018acc004cc008014dd6981d981f1bab303b001898019ba6303f0048a5040e115980099801002a4001130030078a5040e081c0c0f400d03b0dd3001194c004006009223303900233039374c00297ae04004444b3001002899800a6103d87a80004bd6f7b63044c8cc896600266e452201000028acc004cdc7a44100002899802180c1981e181d001a5eb80006266008980103d87a800000540dd198008034006446600c0046607c00a00280310371bae3037001303c003303a00240e1223301900223375e606e60686ea8c0dcc0d0dd5180e181a1baa00100291194c0040060070024004444b30010028800c4ca6002009303b003cc00400a6eb8c0d80066eacc0dc0064444464b30013015374c00300289801800a07432329800800c01a00a80088896600200510018994c004012608a00798008014dd71820000cdd69820800c01501b200830430024104a02a8091004181c801206e911980c8011809000ca60020034bd70488a60020050019111981d1ba73303a375200c660746ea400ccc0e8dd400125eb8000500b201291192cc004c090006264b30013039001899805181c000801c59036181a1baa0038acc004c09c006264b30013039001899810981c000801c59036181a1baa0038acc004c08c00626464b3001303a0028024590371bae3038001303437540071640c4818903118191baa002911192cc004c09400626464b3001303b0028024590381bae3039001303537540071598009814000c4c8cc8966002607800313301a3758607600244b3001002803c66002013303d00289800981f001201240ed1640e46eb4c0e4004c0e8004c0d4dd5001c590322064303337540052232598009812000c4c9660026072003132598009813181a9baa00189919192cc004c0f400a26644b3001302b303a3754005132323259800982100144cc044c10400c4c966002605e003132598009822000c4c8c9660026064003132598009823800c4cc058c1180040262c8220c108dd50014566002606a003132323298009bad30480019bad30480039bad3048002488966002609800900e8b20921824000982380098211baa0028b207e40fc60806ea8004c10c0062c8208c0fcdd500145660026064003159800981f9baa002802c5904045903c2078303d37540031640fc6080002608000260766ea800a2c81c0c0f000c4cc06c00489660020050098992cc004c0b0c0ecdd5000c4c8c8ca60026eb4c1080066eb8c10800e6eb8c10800922259800982300244c020c1180262c82186084002608200260786ea80062c81c8c0f800903c45903a1bac303b001303b001303637540031640cc60700031640d860686ea800e2b300130270018acc004c0d0dd5001c00a2c81aa2c818903118191baa00291112cc004c094006200919800802400e6600e00400322222325980098099ba600180144c00c0050384c00401200f006a809a0284040819122222222222980091111191919800800803912cc00400629422b300132598009802000c56600266ebcc0a0c114dd5000803c56600330013756605a608a6ea800600d00540491302130223045375400314a0821229410424528208430470018a518998010011824000a08241146040009222225980099810002002c56600266ebcc090c104dd5002801c56600330013756605260826ea801600500140391301d301e3041375400b14a081f2294103e4528207c9801801ca60020034bd6f7b630488c8ca6002007375c6088005375c6088003375a6088608a0028030c110004c0fcdd5001201c48888c9660026062045132323259800800c0f22b300130480018992cc004c12400626464b3001303730463754003132323232323298009828000cdd698280024dd69828001cdd6982800124444b3001305500589919809182a80509980c0028acc004c108c144dd5002c4c8cc896600200304e8992cc004c16800a2b300133036491205769746864726177616c2076616c75652063616e6e6f7420626520656d70747900980098171ba6003a50a51414d1598009981b2481245472656173757279207769746864726177616c206f757470757420696e636f7272656374009800800cc098cc160c164c158dd500225eb8266e95200433058374e660b098011a5818496e6469676f54726561737572795769746864726177616c003305830593056375402297ae04bd70400e980103d87a800040651325980098179ba60018a518acc004c8cc004004c084008896600200314a115980099b88375a60b860ba60ba6eb0c17000520008a51899801001182e800a0ac416915330554901224e6f7420656e6f7567682066756e647320696e20747265617375727920696e707574001689981ba4811c5472656173757279206f757470757420697320696e636f72726563740098009bac303a3057375409330273305930353305901533059303a305737540bc97ae04bd70530107d87b9fd87980ff00800d300103d87a8000406c82a1054198109bab303e3056375402a646600200200844b30010018a5eb7bdb182264660b666ec0c160004dd319198008009bab305a0022259800800c52f5bded8c11323305e3376060b60026ea0cdc0a40006eb4c170004cc00c00cc180008c17800505c19801801982e801182d800a0b28a50414d14a0829a09e82b8c160005056180a1bac303b305337540026603a6eb0c0d8c14cdd502298119982a982b18299baa0014bd70182a98291baa0058b209e375a60a80151641483050001304f001304e001304d001304c0013047375400316411060546052608c6ea8c0b8c118dd50009824000c590464c004dd6182398221baa036982398221baa04ba60103d8798000404903c41148228cc03cdd6182318219baa035001304530423754608a60846ea8004cc040dd6182218209baa03302a8cc004dc0240052304530463046304630463046304630463046304600194c00400691100a4410040a5371090012444464b3001303902789919912cc00400608713259800982700144c966002607660946ea80062646464646465300130540019bad30540049bad30540039bad3054002488896600260b200b13233016305900a13301c005132598009823982b1baa006899192cc004ca6002003375860ba60b46ea81326eacc060c168dd5026528a002222259800801c400626644b30013052305e375460c460be6ea8c188c17cdd51823982f9baa0028994c00401e005375660c660c8003325980099baf30643061375460c860c26ea8c124c184dd500200dc566002003159800982a18301baa0018acc004c184dd5000c40160b883120b882f20b905c82e41710664401505e1831800a00e32330010010052259800800c5a265300130610019831000cc1980092225980099baf00330353306730683065375401097ae0899833801198339ba60014bd7044cc0180180050620c19000506246600200d001802400d00620b83060003306100341791598009981ca493d43616e6e6f742062652075736564207768656e207769746864726177616c2076616c7565206861732073696e676c65206173736574206f72206e6f6e650030150018acc004cc0e52412e43616e6e6f742062652075736564207769746820617373657473206e6f7420746f2062652077697468647261776e003370e6028006b3001303e30160028800c4c0600050564566002660729201374f6e65206f75747075742068617320746f2068617665207468652076616c7565206f662074726561737572795f7769746864726177616c0098009bac303c3059375409730293305b0124bd70530107d87b9fd87980ff008015300103d87a80004075133039490123416c6c207370656e742076616c75652068617320746f2062652070616964206261636b009800cc004dd6181e182c9baa04ba5eb7bdb18244b30013375e60bc60b66ea8c178c16cdd500100ac56600266ebcc0f8c16cdd500126107d87b9fd87980ff008998130009bab3043305b375400515330594912f3c65787065637465643e20416c6c206f776e206f757470757473206d757374206861766520766f696420646174756d001641611001416081520074c103d87a8000409914a082b22941056452820ac8a504158602600260306eb0c0fcc15cdd5182d182b9baa0068b20a898009bac3059305637540914bd6f7b6304896600266ebcc16cc160dd5182d982c1baa3040305837540040251330230013756608060b06ea8c100c160dd500144005055204e375a60b001516415830540013053001305200130510013050001304b3754003164120605c605a60946ea8c0c8c128dd5000c11104b1826000a09430253304900133049302a3047375409c97ae098009bac302f30473754073304a3047375409d4c0103d879800040546092608c6ea8c124c118dd51980a9bac30493046375407005f1323259800981b814c4c8ca600260506609800266098605a60946ea81452f5c1232330010010022259800800c52f5bded8c113233225980099b91489000028acc004cdc7a441000028800c401104d44cc14800ccc01401400504d1bae304d0013052002305000141393756606460946ea80092225980098289980c9bac3050304d375407e009132325980099817a495d416c6c20696e70757473206d7573742068617665206d6f7265207468616e2031206e6f6e2d414441206173736574206f722031206e6f6e2d41444120617373657420616e64206d6f7265207468616e20327820414441206275666665720032598009806000c528c566002608600313371090405b6e0298068024528209a41346014600800715980099817a492f416c6c207468652076616c7565206e6565647320746f2062652073656e74206261636b20746f207472656173757279009800800c00e98103d87a8000407113302f49012354686572652063616e2062652031206f75747075742077697468206f6e6c7920414441003371266e04c020008dd698294c004c010006660a2981010000330513032304f375408297ae09114c00400a0032223259800cc004c164006604c660b001897ae0a60107d87b9fd87980ff00acc004c11800e297adef6c6089982c19bb0375200e6e98cc0a001000d2f5bded8c0829a98103d879800040651330583750602a6eb4c164008cc160dd3982d000a5eb822a660a8921593c65787065637465643e2045616368206e6f6e204144412061737365742069732073657061726174656420696e746f20697473206f776e20636f6e74696e75696e67206f7574707574207769746820766f696420646174756d0016414c6eb0c160c164005028204c4800a294104c452820989800800d2f5bded8c1223301b0013756607060a06ea800901f1980b9bac3030304d375407e603a6609e00697ae08b209c182618249baa304c304937540026602e6eb0c12cc120dd501d018c566002606c05313233229800cc00400697adef6c60911980c0009bab3035304d3754606a609a6ea800901c4cc054dd6181718259baa03d301b3304d0024bd70488c8cc00400400c896600200314a315980098019829000c4cc008008c14c006294104c20a048896600200504a8992cc004c14c00e2b30013302f4912d416c6c206f776e20696e70757473206861766520746f20757365207468652072696768742072656465656d657200330020052323303c00113375e002980103d87c80003232330010013756602060a46ea811088c96600266ebc010c14c006260a80031330030033058002414460ac0026040660a460a660a06ea80052f5c115980099817a4812554686572652068617320746f206265206174206c656173742032206f776e20696e7075747300300b30080058acc004cc0bd2411c5472656173757279206f757470757420697320696e636f7272656374009800800cc07ccc1440192f5c14c107d87b9fd87980ff008025300103d87a8000404913302f490132416c6c20696e70757473206861766520746f20636f6e7461696e207468652073616d65206d657267696e6720617373657473003233003006232330010010032259800800c528c56600264607330013756607860a86ea8c0f0c150dd50024dd7182b800cdd7182b982c000a076375860ac00313300200230570018a50414082a0c060012294104c452820988a50413104b414060a20048278604e6609600266096605860926ea81412f5c06602a6eb0c130c124dd501d800982598241baa304b304837546602e6eb0c12cc120dd501d018c566002606a053132323298009bad304e00198271827800ccc068dd6182718259baa03d0349827001cdd698270012444446644b30013303249116546f6f206d616e7920617373657420636c61737365730033712601a004900245660026606492011c436f6c6c656374656420616d6f756e7420697320706f7369746976650059800981b801c4cdc4a400000f14a0827a26606492011c5472656173757279206f757470757420697320696e636f72726563740098009bac30353052375408930223305430303305430553052375460aa60a46ea8014cc150c0d4c148dd502ca5eb812f5c13374a90021982a18181982a18181982a01da5eb80cc1500192f5c097ae0801530103d87a8000405914a0827a294104f4c00660026eacc0e0c140dd5001cdd7182998281baa0029bae303830503754005001405548900a44100802a02a3233001001375860a860a26ea810c896600266ebcc154c148dd5182a8008034526899801001182b000a09e1827000982680098241baa03d89919912cc004c0f8c128dd5000c4cc896600260a200313259800981f18269baa00189919912cc004c1540062660666eb0c150004896600200513259800982218299baa0018991925159800991980080098069bab3059305a305a305a305a3056375409044b30013371e6eb8c16800400e294626600400460b600282a22934590521bae30573054375400316414464660020026eb0c0f0c150dd5003912cc0040062980103d87a80008992cc006600260640034a14a2829a2003133003003305a002414c64b30013371e6eb8c16400402e26068660b060b260b400297ae08a6103d87a8000414c6eb0c16000505644c8c8cc896600260b600713005305b0068b20b0375c60b00026eb8c160008c160004dd6182b00120a88b20a4375a60a400260a6002609c6ea80062c8258c0c4c0c0c134dd5181a98269baa30500018b209c375c609c60966ea800660026eb0c0ccc12cdd501ecc0ccc12cdd5029530103d879800040651641206002002609860926ea8c130c124dd51980c1bac304c3049375407606444b30010018a5eb822660986092609a00266004004609c0028259045208a4114600200244b30010018a40011300733002002304c001412482188c8cc0040040088966002003148002266453001375c6092005375660940052259800800c400e2646644601c6600a00a60a60086eb8c130004dd698268009827800a09a4888cc0040040086096002660040046098002824881f088c9660026066003132598009824000c4c966002606a60886ea800626464646464653001304e0019bae304e00698270024c13800e609c004911112cc004c15001a26604a60a601426604a00626604a00426604a00226604a00a01f164144304e001304d001304c001304b001304a00130453754003164108608e00316411460866ea800e2b300130360018992cc004c120006264b3001303530443754003132323232323298009827000cdd718270034c138012609c007304e0024888896600260a800d133025305300a13302500313302500213302500113302500500f8b20a21827000982680098260009825800982500098229baa0018b208430470018b208a304337540071598009819000c4c966002609000313259800981a98221baa00189919191919191919194c004dd69828800cdd71828804cdd69828803cc14401a60a200b30510049828801cc1440092222222259800982d004c4cc108c1640404cc0780144cc1080104cc0ac00c4cc0ac0084cc0ac0040562c82b860a200260a0002609e002609c002609a002609800260960026094002608a6ea80062c8210c11c0062c8228c10cdd5001c5660026062003132598009824000c4c966002606a60886ea800626464646464646464653001375a60a2003375c60a2013375a60a200f30510069828802cc14401260a200730510024888888896600260b4013133042305901013301e00513304200413302b00313302b00213302b0010158b20ae1828800982800098278009827000982680098260009825800982500098229baa0018b208430470018b208a304337540071598009818000c4c966002609000313259800981a98221baa00189919191919191919194c004dd71828800cdd71828804cc14401e60a200d305100598288024dd69828801cdd69828801244444444b3001305a009899821182c80809981580309981580289981580209981500180ac590570c144004c140004c13c004c138004c134004c130004c12c004c128004c114dd5000c590421823800c5904518219baa0038acc004cdc3a4014003132598009824000c4c966002606a60886ea8006264646464646464646464653001375c60a6003375c60a6017305300998298044c14c01e64b300130510018acc004cdc4a400860a000316898221828000a09c8b20a4375460a600d32598009828800c56600266e25200430500018b44c110c14000504e4590521baa305300598298024dd69829801cdd6982980124444444444b3001305e00b899823182e80a09981780409981780389981780309981700180cc5905b0c14c004c148004c144004c140004c13c004c138004c134004c130004c12c004c128004c114dd5000c590421823800c5904518219baa0038acc004cdc3a4018003132598009824000c4c966002606a60886ea80062646464646464646464646465300130540019bad305400c9bad305400b9bad305400a9bad30540099bad30540089bad30540079bad30540069bad30540059bad30540049bad30540024888888888896600260c0019133030305f00e13301e00b01b8b20ba182a000982980098290009828800982800098278009827000982680098260009825800982500098229baa0018b208430470018b208a3043375400715980099b8748038006264b300130480018992cc004c0d4c110dd5000c4c8cc8966002609800313302a3758609600244b3001002804c4c8cc896600260a200313259800981f18269baa001899192cc004c15000a2600e60a80111641446eb8c148004c138dd5000c5904b1828000c5904e1bae304e001304f0013758609a004825a2c8248dd69824800982500098229baa0018b208430470018b208a3043375400715980099b874804000626464b300130490028024590461bae30470013043375400716410082010402080410082010402080410060826ea800808966002600c602a6ea800a264646644b3001301e003802c5901b1bae301b001375c60360046036002602c6ea800a2c8099164030300e0013009375401f149a26cac80301"
|
|
8332
|
-
};
|
|
8333
|
-
|
|
8334
|
-
// src/contracts/treasury/types.ts
|
|
8335
|
-
import { Data as Data40 } from "@lucid-evolution/lucid";
|
|
8336
|
-
var TreasuryParamsSchema = Data40.Object({
|
|
8337
|
-
upgradeToken: AssetClassSchema2,
|
|
8338
|
-
versionRecordToken: AssetClassSchema2,
|
|
8339
|
-
treasuryUtxosStakeCredential: Data40.Nullable(StakeCredentialSchema)
|
|
8340
|
-
});
|
|
8341
|
-
var TreasuryParams = TreasuryParamsSchema;
|
|
8342
|
-
function castTreasuryParams(params) {
|
|
8343
|
-
return Data40.castTo(params, TreasuryParams);
|
|
8344
|
-
}
|
|
8345
|
-
|
|
8346
|
-
// src/contracts/treasury/scripts.ts
|
|
8347
|
-
var mkTreasuryValidatorFromSP = (params) => {
|
|
8348
|
-
return {
|
|
8349
|
-
type: "PlutusV3",
|
|
8350
|
-
script: applyParamsToScript11(_treasuryValidator.cborHex, [
|
|
8351
|
-
castTreasuryParams({
|
|
8352
|
-
upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
|
|
8353
|
-
versionRecordToken: fromSystemParamsAssetLucid(
|
|
8354
|
-
params.versionRecordToken
|
|
8355
|
-
),
|
|
8356
|
-
treasuryUtxosStakeCredential: params.treasuryUtxosStakeCredential ? fromSysParamsStakeCredential(params.treasuryUtxosStakeCredential) : null
|
|
8357
|
-
})
|
|
8358
|
-
])
|
|
8359
|
-
};
|
|
8360
|
-
};
|
|
8361
|
-
|
|
8362
|
-
// src/contracts/treasury/queries.ts
|
|
8363
|
-
import { option as O15, function as F18 } from "fp-ts";
|
|
8364
|
-
import {
|
|
8365
|
-
assetClassToUnit as assetClassToUnit4,
|
|
8366
|
-
assetClassValueOf as assetClassValueOf8,
|
|
8367
|
-
getRandomElement as getRandomElement3
|
|
8368
|
-
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
8369
|
-
async function findAllTreasuryUtxos(lucid, sysParams) {
|
|
8370
|
-
return lucid.utxosAt({
|
|
8371
|
-
type: "Script",
|
|
8372
|
-
hash: sysParams.validatorHashes.treasuryHash
|
|
8373
|
-
});
|
|
8374
|
-
}
|
|
8375
|
-
async function findRandomTreasuryUtxo(lucid, sysParams) {
|
|
8376
|
-
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
8377
|
-
return F18.pipe(
|
|
8378
|
-
O15.fromNullable(getRandomElement3(treasuryUtxos)),
|
|
8379
|
-
O15.match(() => {
|
|
8380
|
-
throw new Error("Expected some treasury UTXOs.");
|
|
8381
|
-
}, F18.identity)
|
|
8382
|
-
);
|
|
8383
|
-
}
|
|
8384
|
-
async function findRandomTreasuryUtxoWithOnlyAda(lucid, sysParams) {
|
|
8385
|
-
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
8386
|
-
const adaOnlyTreasuryUtxos = treasuryUtxos.filter(
|
|
8387
|
-
(utxo) => Object.keys(utxo.assets).length == 1
|
|
8388
|
-
);
|
|
8389
|
-
return F18.pipe(
|
|
8390
|
-
O15.fromNullable(getRandomElement3(adaOnlyTreasuryUtxos)),
|
|
8391
|
-
O15.match(() => {
|
|
8392
|
-
throw new Error("Expected some treasury UTXOs.");
|
|
8393
|
-
}, F18.identity)
|
|
8394
|
-
);
|
|
8486
|
+
).setMinFee(txFee);
|
|
8487
|
+
}).exhaustive();
|
|
8488
|
+
return tx;
|
|
8395
8489
|
}
|
|
8396
|
-
async function
|
|
8397
|
-
const
|
|
8398
|
-
|
|
8399
|
-
|
|
8400
|
-
|
|
8401
|
-
|
|
8402
|
-
|
|
8490
|
+
async function processSpRequest(stabilityPoolUtxo, accountUtxo, iAssetUtxo, allE2s2sSnapshotOrefs, sysParams, lucid) {
|
|
8491
|
+
const draftTx = processSpRequestAuxiliary(
|
|
8492
|
+
stabilityPoolUtxo,
|
|
8493
|
+
accountUtxo,
|
|
8494
|
+
iAssetUtxo,
|
|
8495
|
+
allE2s2sSnapshotOrefs,
|
|
8496
|
+
sysParams,
|
|
8497
|
+
lucid,
|
|
8498
|
+
// Placeholder transation fee
|
|
8499
|
+
1n
|
|
8403
8500
|
);
|
|
8404
|
-
|
|
8405
|
-
|
|
8406
|
-
|
|
8407
|
-
|
|
8408
|
-
|
|
8501
|
+
const fee = (await (await draftTx).complete()).toTransaction().body().fee();
|
|
8502
|
+
return processSpRequestAuxiliary(
|
|
8503
|
+
stabilityPoolUtxo,
|
|
8504
|
+
accountUtxo,
|
|
8505
|
+
iAssetUtxo,
|
|
8506
|
+
allE2s2sSnapshotOrefs,
|
|
8507
|
+
sysParams,
|
|
8508
|
+
lucid,
|
|
8509
|
+
fee
|
|
8409
8510
|
);
|
|
8410
8511
|
}
|
|
8411
|
-
async function
|
|
8412
|
-
const
|
|
8413
|
-
|
|
8414
|
-
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
)
|
|
8512
|
+
async function createE2s2sSnapshots(stabilityPoolOref, sysParams, lucid) {
|
|
8513
|
+
const stabilityPoolRefScriptUtxo = matchSingle5(
|
|
8514
|
+
await lucid.utxosByOutRef([
|
|
8515
|
+
fromSystemParamsScriptRef(
|
|
8516
|
+
sysParams.scriptReferences.stabilityPoolValidatorRef
|
|
8517
|
+
)
|
|
8518
|
+
]),
|
|
8519
|
+
(_) => new Error("Expected a single stability pool Ref Script UTXO")
|
|
8418
8520
|
);
|
|
8419
|
-
|
|
8420
|
-
|
|
8421
|
-
|
|
8422
|
-
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
|
|
8426
|
-
|
|
8427
|
-
|
|
8428
|
-
|
|
8429
|
-
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
|
|
8441
|
-
|
|
8442
|
-
|
|
8443
|
-
|
|
8444
|
-
|
|
8445
|
-
|
|
8446
|
-
|
|
8447
|
-
|
|
8448
|
-
|
|
8449
|
-
|
|
8450
|
-
|
|
8451
|
-
|
|
8452
|
-
|
|
8453
|
-
|
|
8454
|
-
|
|
8455
|
-
|
|
8456
|
-
|
|
8457
|
-
|
|
8458
|
-
|
|
8459
|
-
|
|
8460
|
-
|
|
8461
|
-
|
|
8462
|
-
|
|
8463
|
-
|
|
8464
|
-
|
|
8465
|
-
|
|
8466
|
-
|
|
8467
|
-
|
|
8468
|
-
cdpToken: AssetClassSchema2,
|
|
8469
|
-
versionRecordToken: AssetClassSchema2,
|
|
8470
|
-
iassetValHash: Data41.Bytes(),
|
|
8471
|
-
cdpValHash: Data41.Bytes(),
|
|
8472
|
-
sPoolValHash: Data41.Bytes(),
|
|
8473
|
-
versionRegistryValHash: Data41.Bytes(),
|
|
8474
|
-
treasuryValHash: Data41.Bytes()
|
|
8475
|
-
});
|
|
8476
|
-
var ExecuteParams = ExecuteParamsSchema;
|
|
8477
|
-
function castExecuteParams(params) {
|
|
8478
|
-
return Data41.castTo(params, ExecuteParams);
|
|
8521
|
+
const snapshotE2s2sPolicyRefScriptUtxo = matchSingle5(
|
|
8522
|
+
await lucid.utxosByOutRef([
|
|
8523
|
+
fromSystemParamsScriptRef(
|
|
8524
|
+
sysParams.scriptReferences.authTokenPolicies.snapshotEpochToScaleToSumTokenRef
|
|
8525
|
+
)
|
|
8526
|
+
]),
|
|
8527
|
+
(_) => new Error("Expected a single snapshot e2s2s policy Ref Script UTXO")
|
|
8528
|
+
);
|
|
8529
|
+
const spUtxo = matchSingle5(
|
|
8530
|
+
await lucid.utxosByOutRef([stabilityPoolOref]),
|
|
8531
|
+
(_) => new Error("Expected a single stability pool UTXO")
|
|
8532
|
+
);
|
|
8533
|
+
const spDatum = parseStabilityPoolDatumOrThrow(getInlineDatumOrThrow(spUtxo));
|
|
8534
|
+
const [newSnapshotDatums, newAssetStates] = partitionEpochToScaleToSums(spDatum);
|
|
8535
|
+
if (newSnapshotDatums.length === 0) {
|
|
8536
|
+
throw new Error("There has to be a snapshot being created.");
|
|
8537
|
+
}
|
|
8538
|
+
const snapshotAc = fromSystemParamsAsset(
|
|
8539
|
+
sysParams.stabilityPoolParams.snapshotEpochToScaleToSumToken
|
|
8540
|
+
);
|
|
8541
|
+
const tx = lucid.newTx().readFrom([stabilityPoolRefScriptUtxo, snapshotE2s2sPolicyRefScriptUtxo]).collectFrom(
|
|
8542
|
+
[spUtxo],
|
|
8543
|
+
serialiseStabilityPoolRedeemer("RecordEpochToScaleToSum")
|
|
8544
|
+
).mintAssets(
|
|
8545
|
+
mkAssetsOf8(snapshotAc, BigInt(newSnapshotDatums.length)),
|
|
8546
|
+
Data42.void()
|
|
8547
|
+
).pay.ToContract(
|
|
8548
|
+
spUtxo.address,
|
|
8549
|
+
{
|
|
8550
|
+
kind: "inline",
|
|
8551
|
+
value: serialiseStabilityPoolDatum({
|
|
8552
|
+
StabilityPool: { ...spDatum, assetStates: newAssetStates }
|
|
8553
|
+
})
|
|
8554
|
+
},
|
|
8555
|
+
spUtxo.assets
|
|
8556
|
+
);
|
|
8557
|
+
for (const newDatum of newSnapshotDatums) {
|
|
8558
|
+
tx.pay.ToContract(
|
|
8559
|
+
spUtxo.address,
|
|
8560
|
+
{
|
|
8561
|
+
kind: "inline",
|
|
8562
|
+
value: serialiseStabilityPoolDatum({
|
|
8563
|
+
SnapshotEpochToScaleToSum: newDatum
|
|
8564
|
+
})
|
|
8565
|
+
},
|
|
8566
|
+
mkAssetsOf8(snapshotAc, 1n)
|
|
8567
|
+
);
|
|
8568
|
+
}
|
|
8569
|
+
return tx;
|
|
8479
8570
|
}
|
|
8480
|
-
|
|
8481
|
-
|
|
8482
|
-
|
|
8483
|
-
|
|
8484
|
-
|
|
8485
|
-
|
|
8486
|
-
|
|
8487
|
-
|
|
8488
|
-
|
|
8489
|
-
|
|
8490
|
-
|
|
8491
|
-
cborHex: "5931ec5931e9010100229800aba2aba1aba0aab9faab9eaab9dab9cab9a48888888a60022a66004921203c65787065637465643e20694173736574206e6f74207265666572656e63656400168a99801249283c65787065637465643e2053696e676c6520636f6c6c61746572616c20617373657420696e70757400168a998012491e3c65787065637465643e2053696e676c652069617373657420696e70757400168a99801249193c65787065637465643e204d697865642076657273696f6e7300168a99801249523c65787065637465643e205768656e2066756e64732066726f6d207472656173757279207265717565737465642069742068617320746f207370656e642061207574786f2066726f6d20747265617375727900168a99801249243c65787065637465643e204f6e6c792073696e676c65206578656375746520696e707574001648888896600264653001300f00198079808000cdc3a4005300f00248889660026004601e6ea800e2664530013015002980a980b001566002600260226ea801a2b30013012375400d149a2c809a2c8079222598009802180a1baa0028cc004c060c054dd50014c054dd500348c064c06800644646600200200644b30010018a5eb8226644b3001300500289980e80119802002000c4cc010010005018180e000980e800a03448888c8cc88cc89660020050158acc004c08800a26464b3001330013756601260406ea8018c024c080dd5013466002444646601800846004601c604a6ea800566002602460446ea8006246600a6eacc034c090dd5000801c48cdc42400130013756601a60486ea80066eb8c09cc090dd5001cdd7180698121baa003401881026e1d20049181218129812800c88c8cc00400400c88cc00c004c00800a4464b30013012001899192cc004c0a400a0091640986eb8c09c004c08cdd5001c566002602a00315980098119baa0038014590244590202040302137540049111119914c004c0a800a6002003259800980398139baa0018981598141baa0018b204a488a60026002601060546ea8c04cc0a8dd5001c8966002603660566ea800a26464646464646464646464653001303b0019bad303b00c9bad303b00b9bad303b00a9bad303b0099bad303b0089bad303b0079bad303b0069bad303b0059bad303b0049bad303b00248888888888966002608e01913301f304600e13301b00b0188b2088181d800981d000981c800981c000981b800981b000981a800981a00098198009819000981880098161baa0028b2052980e18149baa302d302e005488966002603860586ea800e264646464653001375a606a003375a606a00b375a606a007375a606a00491112cc004c0e80162660166072010330012303a303b303b303b303b303b303b303b0019181d181d981d981d800cdd2a40052259800800c40062a6606c004200281aa44b3001302730373754005132323322598009820001c0162c81e8dd6981e8009bad303d002303d001303837540051640d522598009813981b9baa0028991919912cc004c10000e00b1640f46eb8c0f4004dd7181e801181e800981c1baa0028b206a9b874801a6e1d20089b874802a6e1d200e9b87480326e2520044888888888888cc89660026601692125476f7620696e707574206d75737420757365207468652072696768742072656465656d6572005980080c44ca6002266ebc00530103d87b800098221baa00191192cc004c0dc00626464b3001304e00280245904b1bae304c00130483754007159800981d000c4c8c966002609c0050048b2096375c609800260906ea800e2c822904518231baa002488966002606e00513232323298009827800cdd698278024dd71827801a444b3001305300489919912cc004c10400a264b300130570018992cc004c10cc14cdd5000c4c8c8c8c8c8ca600260ba003375c60ba00d305d004982e801cc1740092222259800983180344cc094c1880284cc09400c4cc0940084cc0940044cc09401403a2c830060ba00260b800260b600260b400260b200260a86ea80062c8288c1580062c82a0c148dd5001c566002608800513259800982b800c4c966002608660a66ea800626464646464653001305d0019bae305d006982e8024c17400e60ba004911112cc004c18c01a26604a60c401426604a00626604a00426604a00226604a00a01d164180305d001305c001305b001305a00130590013054375400316414460ac00316415060a46ea800e2b300130310028992cc004c15c006264b3001304330533754003132323232323232323298009bad30600019bae30600099bad306000798300034c18001660c000930600039830001244444444b30013069009899815183400809981100289981500209981580189981580109981580080a4590660c180004c17c004c178004c174004c170004c16c004c168004c164004c150dd5000c59051182b000c5905418291baa0038acc004c05800a264b300130570018992cc004c10cc14cdd5000c4c8c8c8c8c8c8c8c8ca60026eb4c1800066eb8c1800266eb4c18001e60c000d306000598300024c18000e60c0004911111112cc004c1a402626605460d002026604400a2660540082660560062660560042660560020291641983060001305f001305e001305d001305c001305b001305a00130590013054375400316414460ac00316415060a46ea800e2b300130150028992cc004c15c006264b3001304330533754003132323232323232323298009bae30600019bae30600099830003cc18001a60c000b30600049bad30600039bad30600024888888896600260d201313302a306801013302b00613302b00513302b0041330410030148b20cc1830000982f800982f000982e800982e000982d800982d000982c800982a1baa0018b20a230560018b20a830523754007159800980a00144c96600260ae00313259800982198299baa001899191919191919191919194c004dd71831000cdd71831005cc18802660c40113062007992cc004c1800062b3001301f305f0018b44c148c17c00505d4590611baa3062006992cc004c1800062b3001301f305f0018b44c148c17c00505d4590611baa306200598310024dd69831001cdd6983100124444444444b3001306d00b899817183600a09981780409981780389981780309982280180c45906a0c188004c184004c180004c17c004c178004c174004c170004c16c004c168004c164004c150dd5000c59051182b000c5905418291baa0038acc004c04800a264b30013057001899814182b00080145905418291baa0038acc004c04c00a264b300130570018992cc004c10cc14cdd5000c4c8cc896600260b6003133034375860b400244b300100280444c8cc896600260c0003132598009826182e1baa001899192cc004c18c00a2600e60c60111641806eb8c184004c174dd5000c5905a182f800c5905d1bae305d001305e001375860b800482d22c82c0dd6982c000982c800982a1baa0018b20a230560018b20a83052375400715980099b874804000a26464b30013058002801c590551bae30560013052375400716413c827904f209e413c827904f209e413c609e6ea80044c966002608000313259800982b000c4c966002608460a46ea80062646464b3001305a002899912cc004c11cc15cdd500144c8c8c96600260be005133014305e003132598009825800c4c96600260c200313232598009827000c4c96600260c800313301930630010098b20c2305f37540051598009828800c4c8c8ca60026eb4c1940066eb4c19400e6eb4c194009222598009834802403a2c833060ca00260c800260be6ea800a2c82e105c182e9baa00130600018b20bc305c37540051598009827000c56600260b86ea800a00b16417516416482c8c168dd5000c5905c182e800982e800982c1baa0028b20aa30590031330330012259800801404e264b3001304830583754003132323298009bad305f0019bae305f0039bae305f00248896600260c60091300830630098b20c0182f800982f000982c9baa0018b20ac305b002416516415c6eb0c160004c160004c14cdd5000c59050182a800c5905318289baa0058acc004c10c0062b30013051375400b00c8b20a48b209c4138609e6ea8010c1480162c8280609e002609c002609a00260906ea80122b3001303a002899192cc004c13800a00b16412c6eb4c130004c120dd50024566002604e00515980098241baa004801c590494566002601800515980098241baa004801c59049459045208a4114822866004608e60886ea807409e294504144c96600266018921174d697865642070726f746f636f6c2076657273696f6e73003370e6eb4c08cc114dd500d9bad30013045375406115980099806249224d7573742065786563757465206166746572206566666563746976652064656c6179003259800981c18229baa001899b88337006eb4c090c118dd50189bad302430463754605e608c6ea8070dd6982498231baa0018a50410c6090608a6ea8c120c114dd5180798229baa0368acc004cc03124011143616e6e6f742062652065787069726564003259800981c18229baa001899b89375a6092608c6ea8004cdc01bad300f304637540626eb4c03cc118dd5181798231baa01c8a50410c6090608a6ea8c0b8c114dd5180798229baa0368cc0048c124c128c128c128c128c12800646092609460946094609460946094609460946094003375e980103d879800048896600264b3001303830483754600860926ea80d22b3001001820c4c966002609c005132332259800981e000c566002609a6ea800e005164139159800981f800c566002609a6ea800e0051641391598009816000c566002609a6ea800e0051641391598009808800c566002609a6ea800e0051641391598009808000c4c8c8c8ca600260a8003375a60a8007375a60a80049112cc004c16001226603260ae00e2b300130433053375400713232332259800982e001c0362c82c8dd6982c8009bae3059002305900130543754007164145164154305400130530013052001304d37540071598009807800c566002609a6ea800e005164139164128825104a2094412882504c010004c128dd500099804182698251baa0013756600860946ea80ee0848258c13000504a44cc0412414b5768656e206e6f207472656173757279207769746864726177616c207265717565737465642069742063616e2774207370656e6420616e79207574786f2066726f6d207472656173757279003375e6e9c005300101800041186605a6eb0c12cc120dd501c980819825182598261826182618261826182618261826182618261826182618241baa04e4bd704660026e952000911982619bb037520046ea00052f5bded8c1370090014dd2a4008911119912cc004cc88cc05d24012c54686520646174756d206f6620676f7665726e616e6365206d757374207570646174652070726f7065726c79003232598009820800c6600200900398039982a19191918069982b982c0019982b982c0011982b982c0009982b9ba8300b375a603c60aa6ea80acc164c164004c160004c15c004c148dd501425eb82600a60aa60a46ea816298103d87a800040191598009809000c6600200900398039982a1918059982a982b0009982a982b18299baa003305730570013052375405097ae09802982a98291baa058a60103d87a800040191598009809800c6600200900398039982a191918061982b182b8011982b182b8009982b1ba8300a375a606460a86ea80a8c160c160004c15c004c148dd501425eb82600a60aa60a46ea816298103d87a8000401919800813528528a09e413c827904f18281baa0013039305037540766eb0c144c148c148c138dd501f980b19828180319828182898271baa3051304e3754606e609c6ea809ccc14130103d87a80004bd7025eb82264b300133016490122546865207472616e73616374696f6e206d757374206d696e742070726f7065726c79003375e6016609e6ea8100dd34c0048c8cc004004008896600200314bd6f7b63044c8cc154cdd818290009ba63233001001375660a800444b30010018a5eb7bdb182264660b066ec0c154004dd419b8148000dd6982b00099801801982d001182c000a0ac3300300330570023055001414d304e37546070609e6ea80ea4446644b300130430038802c4c8c8cc00400401c8966002003133059337606ea4014dd3001a5eb7bdb1822646644b30013372201000515980099b8f0080028992cc004cdd7a60101a000374c003100289982e99bb037520126e9800400905819198008009bab305b0042259800800c4cc178cdd81ba9009375001697adef6c6089919912cc004cdc8806001456600266e3c03000a264b30013370e00266e05200000f880144cc188cdd81ba900d375066e0000403c00905d1bad305f00389983099bb037520186ea003801105c44cc18400ccc01401400505c1bae305c0013061002305f001417513305c337606ea4020dd300300220ae89982e00199802802800a0ae375c60ae00260b800460b400282c0cc02c00400d0511bae3055305237540046eb8c0ecc148dd50012444b300130410028cc00660026006600a607660a46ea8162601c60a46ea816290012002981818291baa058a4004800a2b300130310028cc004c00cc014c0ecc148dd502c4c06cc148dd502c520024005159800980a8014660026006600a607660a46ea8162600860a46ea8162900120028acc004c04c00a3300130033005303b305237540b1301c305237540b14800900144c00cc014c0ecc148dd502c209e413c827904f226602c921104661696c656420657865637574696f6e009800981c18279baa03a91829982a182a182a182a182a182a182a182a000c8c14cc150c150c150c150c150c150c150c150c150c15000644b300130403050375400513232323232323232329800982e800cdd7182e804cdd6982e8044c17401a60ba00b305d004982e801cc96600260b6003159800980d182d000c5a2609a60b400282c22c82e0dd5182e801244444444b30013066009899814183280789981400289981400209981400189981400109981f0040094590630c174004c170004c16c004c168004c164004c160004c15c004c158004c144dd500145904e4896600266e40008006298103d87980008acc004cdc7801000c530103d87a80008a6103d87b8000413882712222232598009822000c4ca6002601c660b0002660b0980103d87a80004bd704dd6182c982d182d182b1baa047982c982b1baa0074888c966002660429212153746162696c697479506f6f6c206f757470757420697320696e636f7272656374009800801cc088cc170c048cc170c088cc170c024c168dd503025eb80cc171300103d87a80004bd7025eb82601e660b86024660b86024660b860ba60b46ea8008cc171300118d8799fd8799f1b0de0b6b3a7640000ffd8799f00ff0000ff003305c4c10180004bd7025eb812f5c1300d3016305a37540c14c103d87a8000403915980098249bad3023305a37540611330214912370726f706f73656420694173736574206f757470757420697320696e636f727265637400330014a2980103d87a8000899810a48125496e636f72726563746c7920636f6e73756d6564207265666572656e636520696173736574003259800982f800c4c96600266ebc01cc17cc170dd5182f982e1baa3045305c3754003132598009826182e1baa0018992cc004c1880062646601a002264b3001304f0018acc004c148c17cdd5181518301baa0028acc004cc09d2412370726f706f73656420694173736574206f757470757420697320696e636f727265637400330074a26030660c460c660c06ea80092f5c113302749123636f6e73756d656420694173736574206f757470757420697320696e636f7272656374009800804cc0a0cc1880292f5c130153306230183306232323232323232301f33069306a00733069306a00633069306a00533069306a00433069306a00333069306a00233069306a001330699800a50a6103d87a8000a60103d8798000419060d660d600260d400260d200260d000260ce00260cc00260ca00260c06ea80092f5c097ae09809981f18301baa066a6103d87a8000405114a082ea294105d4566002607e003159800992cc004c140c180dd5000c4c068cc038dd7183218309baa009375c60c860c26ea8006294505e180818301baa0028acc004cc09d2412370726f706f73656420694173736574206f757470757420697320696e636f727265637400330074a0602060c06ea800a26604e92123636f6e73756d656420694173736574206f757470757420697320696e636f7272656374009800804cc0a0cc1880292f5c130153306230183306232323232323232301f33069306a00733069306a00633069306a00533069306a00433069306a00333069306a00233069306a00133069306a306b00133069301f33069306a3067375401e97ae04bd7018350009834800983400098338009833000983280098301baa0024bd7025eb826026607c60c06ea819a98103d87a8000405114a082ea294105d454cc1792411a537563682069617373657420616c7265616479206578697374730016417482e8c178dd5198061bae3062305f375400e6eb8c188c17cdd50009830800c5905f182e9baa0018b20b43033303a305c3754608a60b86ea80060aa82c8c1780062c82e260026eb0c174c168dd5025cc0e0c168dd50305300103d879800040e882ba2941057114c0040126046660ba00a97ae098081982e98099982e98099982e982f182d9baa0033305d4c10100003305d3044305b3754006660ba607260b66ea800ccc174c090c16cdd50019982e980b982d9baa0033305d3016305b3754006660bb3001002a6103d87a8000a60103d87980004160660ba00297ae04bd7025eb82601c607260b66ea818698103d87a8000403c301d330573005305537540b697ae08acc004c11c0062653001375860b260b460b400398009bac3059001981a182b1baa05ca6103d879800040d9301e330583006305637540b897ae0982c982b1baa007488896600260bc0071325980099baf003305e305b375460bc60b66ea8c110c16cdd5000c4c966002609660b66ea8006264b30013061001899198060008acc004cdc79bae3061305e37540026eb8c184c178dd5002c5660033001008981319830180b198300031983026103d87a80004bd7025eb826026660c0602c660c064646030660c460c6004660c460c6002660c4609260c06ea801ccc188c0f8c180dd500399831181498301baa00733062301c3060375400e660c4603660c06ea801cc190c190c190c190c190c190004c18c004c178dd5000a5eb812f5c13011303c305e37540c94c0103d87a8000404914a3153305c491253c65787065637465643e20694173736574206f757470757420697320696e636f72726563740016416d153305c4911e3c65787065637465643e204e6f742072656c6576616e74206961737365740016416c60c000316417860b86ea80062c82c8c0c8c0e4c16cdd51822182d9baa0018a9982ca49283c65787065637465643e204d6f64696679696e67206e6f6e2d7570677261646564204941737365740016416060ba00716416c3055375408d13259800981a80146600260b260ac6ea801e4464b3001304b30583754003133006375c608460b26ea800cdd71821182c9baa0028800a0ac33005375c60b660b06ea8008dd7182d982c1baa001980f1982c1803182b1baa05c4bd704c158dd5023a4445300130123305c0023305c4c103d87a80004bd704dd6182e982f182f000e60026eb0c174006607060b46ea818298103d879800040e89112cc0040060af132598009831001456600266ebc018c184c178dd51830982f1baa3047305e3754003132598009827182f1baa0018992cc004c1900062646601e0022b30013371e6eb8c190c184dd50009bae306430613754017159800cc00401a6052660c600e97ae0980b19831980c9983199180d198321832800998321ba83018375a609660c46ea8008c198c198004c184dd5000a5eb812f5c13014303f306137540cf4c103d87a80004055132324a2b30013051375a609660c46ea800a2b300198009bac3065306237540a7302b306237540d14c0103d8798000410915980099800a514c0103d87a80008a4d1533060491223c65787065637465643e2057726f6e6720636f6c6c61746572616c206f75747075740016417d1533060491243c65787065637465643e204e6f20636f6c6c61746572616c20617373657420696e7075740016418d13259800800c17a264b300130680028acc004cdd7806183398321baa306730643754609a60c86ea8006264b3001305730643754003132598009835000c4c8cc04800456600266e3cdd7183518339baa001375c60d460ce6ea80462b3001337106eb4c140c19cdd5003acc0056600266ebd6600260b260cc6ea8c084c19cdd5000c4c140c19cdd5000c4c96600260d800313259800982d98341baa0018992cc004c1b80062646602c0022b3001305d306a3754604a60d66ea8006260a860d66ea80062a660d2921253c65787065637465643e204e6f742074686520666972737420696e2074686520636861696e001641a060da0031641ac60d26ea80062c8330c0fcc118c1a0dd5182898341baa306b0018b20d298009bac3050306737540b13030306737540db4c0103d8798000411c8321300106d8799f4040ff008a51899baf30503067375402298106d8799f4040ff00419114804a2900820c88acc004c96600260ae003159800982d18339baa30223068375400515980099817a4812a70726f706f73656420636f6c6c61746572616c206173736574206f757470757420696e636f727265637400330074a26040660d460a260d06ea80092f5c113302f4912a636f6e73756d656420636f6c6c61746572616c206173736574206f757470757420696e636f7272656374009800806cc0c0cc1a80392f5c1301d3306a30303306a3232323232323232323029330733074009330733074008330733074007330733074006330733074005330733074004330733074003330733074002330733074001330739800a50a6103d87a8000a60103d879800041b860ea60ea00260e800260e600260e400260e200260e000260de00260dc00260da00260d06ea80092f5c097ae0980d981898341baa06ea6103d87a8000407114a0832a29410654566002608e003159800992cc004c160c1a0dd5000c4c088cc048c148c1a4dd5009983618349baa0018a514198602e60d06ea800a2b30013302f4912a70726f706f73656420636f6c6c61746572616c206173736574206f757470757420696e636f727265637400330074a0602e60d06ea800a26605e9212a636f6e73756d656420636f6c6c61746572616c206173736574206f757470757420696e636f7272656374009800806cc0c0cc1a80392f5c1301d3306a30303306a3232323232323232323029330733074009330733074008330733074007330733074006330733074005330733074004330733074003330733074002330733074001330733074307500133073302933073305a3071375403697ae04bd70183a000983980098390009838800983800098378009837000983680098341baa0024bd7025eb826036606260d06ea81ba98103d87a8000407114a0832a2941065454cc199241245375636820636f6c6c61746572616c20617373657420616c726561647920657869737473001641948328c198dd519808182818339baa011305030673754003149a2c83222a660ca921283c65787065637465643e204d617820636f6c6c61746572616c206173736574732072656163686564001641911533065491283c65787065637465643e204e6f742072656c6576616e7420636f6c6c61746572616c2061737365740016419060d200316419c60ca6ea80062c8310c0ecc108c190dd5182698321baa00182ea0c282fa0ca306600141913001375860ca60c46ea814e605660c46ea81a298103d8798000410882f88a6002011302b330650094bd704c060cc194c0accc194c06ccc194c198c18cdd500199832982618319baa00d3306530413063375401a660ca605860c66ea8034cc194c07cc18cdd500699832980f18319baa00d3306530153063375401a660ca605a60c66ea8034cc194c04cc18cdd500699832cc00400a98103d87a8000a60103d87980004180660ca00297ae04bd7025eb82602c605860c66ea81a698103d87a8000405d153305f4911e3c65787065637465643e2057726f6e6720696173736574206f757470757400164179153305f491173c65787065637465643e2057726f6e67206961737365740016417860c600316418460be6ea80062c82e0c0d4c0f0c178dd51823982f1baa00182ba0b682c20be3060001417845660026034005132980098079982c8009982ca6103d87a80004bd70660026eb0c168c15cdd50244c080c15cdd502ed300103d879800040dd305a305737540109112cc004c17800a264b30013375e00a60bc60b66ea8c178c16cdd51822182d9baa0018992cc004c138c16cdd5000c4c96600260c200313233009001159800acc004cdc79bae3061305e37540026eb8c184c178dd5002c4cdd79823982f1baa0013047305e375400b14a082da2b300198009bac303c305e375409f3026330600074bd704c04ccc180c098cc180c8c8c8c064cc18cc19000ccc18cc190008cc18cc190004cc18cc0a8c184dd500419831980e98309baa00833063301c30613754010660c6602660c26ea8020cc18cc0acc184dd500419831980898309baa008306530653065306530653065306500130640013063001305e375400297ae04bd704c044c09cc178dd5032530103d87a8000404914a3153305c4912c3c65787065637465643e20436f6c6c61746572616c206173736574206f757470757420696e636f72726563740016416d153305c491263c65787065637465643e20697272656c6576616e7420636f6c6c61746572616c2061737365740016416c60c000316417860b86ea80062c82c8c0c8c0e4c16cdd51822182d9baa00182a20b0305d0028b20b6180f1982c1803182b1baa05c4bd70456600260320051332259800982e000c4c966002609660b06ea80062b30013059375400313259800800c15a264b3001305f0028992cc004c12cc16cdd5000c4c96600260c20031323300c00115980099812a4810c57726f6e6720694173736574003371e6eb8c184c178dd50009bae3061305e3754011133025490117434450206f757470757420697320696e636f72726563740098009bac303c305e375409f3026330603016330603026330603018305e37540c897ae0330604c103d87a80004bd7025eb826026660c0604c660c0602c660c060c260bc6ea8020cc180c11cc178dd500419830181e182f1baa008330603027305e3754010660c0603460bc6ea8020cc1826002946980103d87a8000a60103d8798000416c660c130014a34c0103d87a8000a60103d8798000416c660c0603260bc6ea8020cc180c040c178dd5004198301814182f1baa00833060300e305e375401097ae04bd7025eb826022602060bc6ea8192980103d87a8000404914a082d8c1800062c82f0c170dd5000c590591819181c982d9baa3044305b3754003057417060ba00282da60026eb0c108c164dd50254c0dcc164dd502fd300103d879800040e51641691641586602c60b660b06ea8c16c004dd59809182c1baa0498b20b230593056375400f3001375860b260ac6ea811e602260ac6ea817298103d879800040d9159800980c00144cc896600260b80031325980099baf305c3059375460b860b26ea8c108c164dd500098109982d9809982c9baa05f4bd7044c96600266e1d20103059375400313259800982f800c4cc8966002609e60b86ea8006264b300130620018992cc004c138c178dd5000c4c8c8c8c8c8c8c8c8c8c8ca60026eb8c1b40066eb8c1b402e60da013306d0089836803cc96600260d600315980098151835000c5a260ba60d400283422c8360dd518368034c96600260d600315980098151835000c5a260ba60d400283422c8360dd51836802cc1b40126eb4c1b400e6eb4c1b4009222222222259800983c005c4cc0e4c1dc0504cc0e80204cc0e801c4cc0e80184cc14000c566002660769211643445020696e70757420697320696e636f7272656374005980099b8f375c60ee60e86ea8058dd7183b983a1baa01e899baf305d3074375402c60ba60e86ea807a294107144cc0ed24117434450206f757470757420697320696e636f72726563740098009bac3052307437540cb303c33076302c33076303c33076302e307437540f497ae0330764c103d87a80004bd7025eb826052660ec6078660ec64605a660ee60f0002660ee60f060f2002660ee60a660ea6ea807ccc1dcc0f8c1d4dd500f9983b9818983a9baa01f3307798009833983a1baa30303075375403f4c0103d87a8000a60103d879800041c8660ef3001306730743754604e60ea6ea807e980103d87a8000a60103d879800041c8660ee607e60ea6ea807ccc1dcc094c1d4dd500f9983b9817983a9baa01f3307730243075375403e97ae03074375402c97ae04bd704dd5982e983a1baa305d307437540394c0103d87a800040a114a0838a2c83a860da00260d800260d600260d400260d200260d000260ce00260cc00260ca00260c800260be6ea80062c82e0c1840062c82f8c174dd5000c5905a1bad305e00130323039305b3754608860b66ea800e2c82e0c168dd5000c590571980b982e182c9baa0013756602660b26ea812a2a660ae92011a3c65787065637465643e204d697865642076657273696f6e732e0016415860b600316416460b260ac6ea801e60026eb0c164c158dd5023cc020c158dd502e5300103d879800040d9159800980b80144c8cc07924012176657273696f6e5265636f7264206f757470757420697320696e636f72726563740098009bac303530573754091301f33059300f33059301f33059305a305b305b305b305b305b305b305b305b305b305b305b305737540ba97ae0330594c103d87a80004bd7025eb826018660b2601e660b260b460ae6ea8004cc164dd399198008009bac30413058375400444b30010018a5eb822660b66e9cc8cc170c174004cc170c174c168dd5182e982f000a5eb80dd6182e00099801001182e800a0b44bd7025eb826014604260ae6ea8176980103d87a8000402c60b260ac6ea801e2b300130160028a518a51414c829905320a6414c82988966002608c60ac6ea800a26464646464646464646465300130650019bae306500b9bad306500998328044c19401e60ca00d306500598328024dd69832801cc96600260c600315980098111831000c5a260aa60c400283022c8320dd5183280124444444444b3001307000b899818983780a0998148038998188030998190028998190020998190018992cc004c170006264b30013072001899819983880080c45906f18369baa00b8acc004c17c0062b3001306d37540170178b20dc8b20d441a860d66ea802a2c836860ca00260c800260c600260c400260c200260c000260be00260bc00260ba00260b800260ae6ea800a2c82a105220a43053375400a8a504130460a460a660a660a660a660a660a600314a0825888888c8c8cc00400401c896600200314a1159800992cc004c0100062b30013375e606660aa6ea800401e2b300133229800992cc004c11cc15cdd5000c4dd6982c182d9bab305b30583754003148001055182d000cdd58014dd7982d182d800c8966002609660b06ea8026266e2400400a2b30013371200200513371200466e0000520809bee028a50415882b1222259800801c566002600400d13300100448002294105844c96600266ebd3001014000305b0018acc004cc008014dd6982e182f9bab305c001898019ba630600048a50416515980099801002a4001130030078a50416482c8c17800d05c0dd3003194c0040066eacc0fcc158dd5001488cc168008cc168dd3000a5eb810011112cc00400a26600298103d87a80004bd6f7b63044c8cc896600266e452201000028acc004cdc7a4410000289980218099982e982d801a5eb80006266008980103d87a80000054161198008034006446600c004660be00a00280310581bae3058001305d003305b002416513375e603c60aa6ea800530103d87a80008a50414914a082922941052182b800c528c4cc008008c16000505120aa59800982018281baa004891919baf30563053375460ac60a66ea8008004c154c148dd5002c48c8cdd7982b18299baa00200130553052375400a8270966002942297adef6c6089982799bb03050304d37540026e98cc010dd7181b18269baa001480092f5bded8c0825114a0822914a082122941042452820842304830493049304930490018a504104446464660020020064464b30013375e008608e003130480018998018019826001208a304a001300c330460024bd7011192cc004c0d0006264b3001304a0018998061824800801c5904718229baa0038acc004c0dc006264b3001304a0018998059824800801c5904718229baa0038acc004c09000626464b3001304b0028024590481bae304900130453754007164108821104218219baa0024590370c0d4004c0d0004c0cc004c0c8004c0b4dd5001c5902a06644b300100180145660026056003133029302a001330299800a51a60103d87a8000a60103d8798000409097ae0801205040a026644b300100180145660026056003133029302a001330299800a50a6103d87a8000a60103d8798000409097ae0801205040a02a6604692130457870656374656420476f7620696e7075742065697468657220617320696e707574206f72207265662e20696e707574001698009bac300e3025375402d3028302537540574c0103d87980004015300100c981418129baa02ba60103d8798000401444464b30013018001899192cc004c0bc00a0091640b06eb8c0b4004c0a4dd5001c56600260360031323322598009818000c4cc024dd61817800912cc00400a00f19800804cc0c400a260026064004804902f45902d1bad302d001302e001302937540071640988130c09cdd500122a6603c921283c65787065637465643e20526571756972657320617574686564206578656375746520696e7075740016407444602730010029bae302430213754003375c601460426ea800500311119199119801001000912cc004006007132325980099b910060018acc004cdc7803000c4dd69813001401502344cc010010c0a800d0231bae30240013027001409464646600200200c44b3001001801c4c8c96600266e440200062b30013371e01000313756604e0050054091133004004302b00340906eb8c094004c0a00050260a5eb7bdb1805200080aa03e407c66002006603e60386ea8c07cc070dd50011bab301f30203020302030203020302030203020302000632330010010022259800800c5a264b30013375e6040603a6ea800402e2600c603a6ea8006266006006604200480d0c07c00501d1119802001119baf3020301d37546040603a6ea8c018c074dd50008011bac301c0034590120c040dd50019b87480022c8068601e00260146ea803e29344d95900701"
|
|
8492
|
-
|
|
8493
|
-
|
|
8494
|
-
|
|
8495
|
-
|
|
8496
|
-
|
|
8497
|
-
|
|
8498
|
-
|
|
8499
|
-
|
|
8500
|
-
|
|
8501
|
-
|
|
8502
|
-
|
|
8503
|
-
};
|
|
8504
|
-
};
|
|
8505
|
-
var mkExecuteValidatorFromSP = (params) => {
|
|
8506
|
-
return {
|
|
8507
|
-
type: "PlutusV3",
|
|
8508
|
-
script: applySingleCborEncoding(
|
|
8509
|
-
applyParamsToScript13(_executeValidator.cborHex, [
|
|
8510
|
-
castExecuteParams({
|
|
8511
|
-
govNFT: fromSystemParamsAssetLucid(params.govNFT),
|
|
8512
|
-
upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
|
|
8513
|
-
iAssetToken: fromSystemParamsAssetLucid(params.iAssetToken),
|
|
8514
|
-
collateralAssetToken: fromSystemParamsAssetLucid(
|
|
8515
|
-
params.collateralAssetToken
|
|
8516
|
-
),
|
|
8517
|
-
stabilityPoolToken: fromSystemParamsAssetLucid(
|
|
8518
|
-
params.stabilityPoolToken
|
|
8519
|
-
),
|
|
8520
|
-
cdpCreatorToken: fromSystemParamsAssetLucid(params.cdpCreatorToken),
|
|
8521
|
-
cdpToken: fromSystemParamsAssetLucid(params.cdpToken),
|
|
8522
|
-
versionRecordToken: fromSystemParamsAssetLucid(
|
|
8523
|
-
params.versionRecordToken
|
|
8524
|
-
),
|
|
8525
|
-
iassetValHash: params.iassetValHash,
|
|
8526
|
-
cdpValHash: params.cdpValHash,
|
|
8527
|
-
sPoolValHash: params.sPoolValHash,
|
|
8528
|
-
versionRegistryValHash: params.versionRegistryValHash,
|
|
8529
|
-
treasuryValHash: params.treasuryValHash
|
|
8571
|
+
async function annulRequest(accountUtxo, params, lucid) {
|
|
8572
|
+
const stabilityPoolRefScriptUtxo = matchSingle5(
|
|
8573
|
+
await lucid.utxosByOutRef([
|
|
8574
|
+
fromSystemParamsScriptRef(
|
|
8575
|
+
params.scriptReferences.stabilityPoolValidatorRef
|
|
8576
|
+
)
|
|
8577
|
+
]),
|
|
8578
|
+
(_) => new Error("Expected a single stability pool Ref Script UTXO")
|
|
8579
|
+
);
|
|
8580
|
+
const oldAccountDatum = parseAccountDatumOrThrow(
|
|
8581
|
+
getInlineDatumOrThrow(accountUtxo)
|
|
8582
|
+
);
|
|
8583
|
+
const tx = lucid.newTx().readFrom([stabilityPoolRefScriptUtxo]).collectFrom([accountUtxo], serialiseStabilityPoolRedeemer("AnnulRequest")).addSignerKey(toHex12(oldAccountDatum.owner));
|
|
8584
|
+
if (oldAccountDatum.request !== "Create") {
|
|
8585
|
+
tx.pay.ToContract(
|
|
8586
|
+
accountUtxo.address,
|
|
8587
|
+
{
|
|
8588
|
+
kind: "inline",
|
|
8589
|
+
value: serialiseStabilityPoolDatum({
|
|
8590
|
+
Account: {
|
|
8591
|
+
...oldAccountDatum,
|
|
8592
|
+
request: null
|
|
8593
|
+
}
|
|
8530
8594
|
})
|
|
8531
|
-
|
|
8532
|
-
|
|
8533
|
-
|
|
8534
|
-
|
|
8535
|
-
|
|
8536
|
-
|
|
8537
|
-
|
|
8538
|
-
|
|
8539
|
-
owner: Data42.Bytes(),
|
|
8540
|
-
/** Milliseconds */
|
|
8541
|
-
biasTime: Data42.Integer(),
|
|
8542
|
-
/** Milliseconds */
|
|
8543
|
-
expirationPeriod: Data42.Integer()
|
|
8544
|
-
});
|
|
8545
|
-
var PriceOracleParams = PriceOracleParamsSchema;
|
|
8546
|
-
function castPriceOracleParams(params) {
|
|
8547
|
-
return Data42.castTo(params, PriceOracleParams);
|
|
8595
|
+
},
|
|
8596
|
+
mkAssetsOf8(
|
|
8597
|
+
fromSystemParamsAsset(params.stabilityPoolParams.accountToken),
|
|
8598
|
+
1n
|
|
8599
|
+
)
|
|
8600
|
+
);
|
|
8601
|
+
}
|
|
8602
|
+
return tx;
|
|
8548
8603
|
}
|
|
8549
8604
|
|
|
8550
8605
|
// src/contracts/rob/helpers.ts
|
|
8551
8606
|
import {
|
|
8552
8607
|
addAssets as addAssets12,
|
|
8553
8608
|
fromHex as fromHex12,
|
|
8554
|
-
toHex as
|
|
8609
|
+
toHex as toHex13
|
|
8555
8610
|
} from "@lucid-evolution/lucid";
|
|
8556
8611
|
|
|
8557
8612
|
// src/contracts/rob/types-new.ts
|
|
@@ -8560,7 +8615,7 @@ import {
|
|
|
8560
8615
|
AssetClassSchema as AssetClassSchema7,
|
|
8561
8616
|
OutputReferenceSchema as OutputReferenceSchema6
|
|
8562
8617
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
8563
|
-
import { option as
|
|
8618
|
+
import { option as O17, function as F20 } from "fp-ts";
|
|
8564
8619
|
var RobOrderTypeSchema = TSchema19.Union(
|
|
8565
8620
|
TSchema19.Struct(
|
|
8566
8621
|
{
|
|
@@ -8616,21 +8671,21 @@ var RobRedeemerSchema = TSchema19.Union(
|
|
|
8616
8671
|
);
|
|
8617
8672
|
function parseRobDatum(datum) {
|
|
8618
8673
|
try {
|
|
8619
|
-
return
|
|
8674
|
+
return O17.some(
|
|
8620
8675
|
Data43.withSchema(RobDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
8621
8676
|
datum
|
|
8622
8677
|
)
|
|
8623
8678
|
);
|
|
8624
8679
|
} catch (_) {
|
|
8625
|
-
return
|
|
8680
|
+
return O17.none;
|
|
8626
8681
|
}
|
|
8627
8682
|
}
|
|
8628
8683
|
function parseRobDatumOrThrow(datum) {
|
|
8629
|
-
return
|
|
8684
|
+
return F20.pipe(
|
|
8630
8685
|
parseRobDatum(datum),
|
|
8631
|
-
|
|
8686
|
+
O17.match(() => {
|
|
8632
8687
|
throw new Error("Expected an ROB datum.");
|
|
8633
|
-
},
|
|
8688
|
+
}, F20.identity)
|
|
8634
8689
|
);
|
|
8635
8690
|
}
|
|
8636
8691
|
function serialiseRobDatum(d) {
|
|
@@ -8643,30 +8698,30 @@ function serialiseRobRedeemer(r) {
|
|
|
8643
8698
|
}
|
|
8644
8699
|
function parseRobRedeemer(redeemerCborHex) {
|
|
8645
8700
|
try {
|
|
8646
|
-
return
|
|
8701
|
+
return O17.some(
|
|
8647
8702
|
Data43.withSchema(RobRedeemerSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
8648
8703
|
redeemerCborHex
|
|
8649
8704
|
)
|
|
8650
8705
|
);
|
|
8651
8706
|
} catch (_) {
|
|
8652
|
-
return
|
|
8707
|
+
return O17.none;
|
|
8653
8708
|
}
|
|
8654
8709
|
}
|
|
8655
8710
|
function parseRobRedeemerOrThrow(redeemerCborHex) {
|
|
8656
|
-
return
|
|
8711
|
+
return F20.pipe(
|
|
8657
8712
|
parseRobRedeemer(redeemerCborHex),
|
|
8658
|
-
|
|
8713
|
+
O17.match(() => {
|
|
8659
8714
|
throw new Error("Expected an ROB redeemer.");
|
|
8660
|
-
},
|
|
8715
|
+
}, F20.identity)
|
|
8661
8716
|
);
|
|
8662
8717
|
}
|
|
8663
8718
|
|
|
8664
8719
|
// src/contracts/rob/helpers.ts
|
|
8665
8720
|
import {
|
|
8666
8721
|
readonlyArray as RA3,
|
|
8667
|
-
array as
|
|
8668
|
-
function as
|
|
8669
|
-
option as
|
|
8722
|
+
array as A11,
|
|
8723
|
+
function as F21,
|
|
8724
|
+
option as O18,
|
|
8670
8725
|
ord as Ord4
|
|
8671
8726
|
} from "fp-ts";
|
|
8672
8727
|
import { match as match18, P as P18 } from "ts-pattern";
|
|
@@ -8799,13 +8854,13 @@ function isFullyRedeemed(robAssets, robOrderType, robIasset) {
|
|
|
8799
8854
|
}).exhaustive();
|
|
8800
8855
|
}
|
|
8801
8856
|
function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redemptionReimbursementRatio, sysParams, tx, txOutputsBeforeCount, collateralAssetRefInputIdx, iassetRefInputIdx, oracleIdx) {
|
|
8802
|
-
return
|
|
8857
|
+
return F21.pipe(
|
|
8803
8858
|
redemptions,
|
|
8804
|
-
|
|
8859
|
+
A11.reduceWithIndex(
|
|
8805
8860
|
tx,
|
|
8806
8861
|
(idx, acc, [robUtxo, payoutAmt]) => {
|
|
8807
8862
|
const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
|
|
8808
|
-
if (
|
|
8863
|
+
if (toHex13(robDatum.iasset) !== toHex13(iasset)) {
|
|
8809
8864
|
throw new Error("Only same iAsset");
|
|
8810
8865
|
}
|
|
8811
8866
|
const [robOutputVal, sellOrderAllowedAssetsIdx] = match18(
|
|
@@ -8835,12 +8890,12 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8835
8890
|
);
|
|
8836
8891
|
return [resultVal, 0n];
|
|
8837
8892
|
}).with({ SellIAssetOrder: P18.select() }, (content) => {
|
|
8838
|
-
const allowedAssetIdx =
|
|
8893
|
+
const allowedAssetIdx = F21.pipe(
|
|
8839
8894
|
content.allowedCollateralAssets,
|
|
8840
8895
|
RA3.findIndex(
|
|
8841
8896
|
([asset, _]) => isSameAssetClass3(asset, collateralAsset)
|
|
8842
8897
|
),
|
|
8843
|
-
|
|
8898
|
+
O18.getOrElse(() => {
|
|
8844
8899
|
throw new Error("Doesn't allow required collateral asset.");
|
|
8845
8900
|
})
|
|
8846
8901
|
);
|
|
@@ -8901,26 +8956,26 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8901
8956
|
);
|
|
8902
8957
|
}
|
|
8903
8958
|
function calculateTotalCollateralForRedemption(iasset, collateralAsset, iassetPrice, allRobs, maxRobsInTx) {
|
|
8904
|
-
return
|
|
8959
|
+
return F21.pipe(
|
|
8905
8960
|
allRobs,
|
|
8906
|
-
|
|
8961
|
+
A11.filterMap(([utxo, datum]) => {
|
|
8907
8962
|
const isCorrectOrder = match18(datum.orderType).returnType().with(
|
|
8908
8963
|
{ BuyIAssetOrder: P18.select() },
|
|
8909
8964
|
(content) => isSameAssetClass3(content.collateralAsset, collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice) && !isBuyOrderFullyRedeemed(utxo.assets, datum.orderType, iassetPrice)
|
|
8910
8965
|
).otherwise(() => false);
|
|
8911
|
-
if (
|
|
8912
|
-
return
|
|
8966
|
+
if (toHex13(datum.iasset) !== toHex13(iasset) || !isCorrectOrder) {
|
|
8967
|
+
return O18.none;
|
|
8913
8968
|
}
|
|
8914
8969
|
const collateralToSpend = robCollateralAmtToSpend(
|
|
8915
8970
|
utxo.assets,
|
|
8916
8971
|
datum.orderType
|
|
8917
8972
|
);
|
|
8918
|
-
return
|
|
8973
|
+
return O18.some(collateralToSpend);
|
|
8919
8974
|
}),
|
|
8920
8975
|
// From largest to smallest
|
|
8921
|
-
|
|
8976
|
+
A11.sort(Ord4.reverse(BigIntOrd)),
|
|
8922
8977
|
// We can fit only this number of redemptions with CDP open into a single Tx.
|
|
8923
|
-
|
|
8978
|
+
A11.takeLeft(maxRobsInTx),
|
|
8924
8979
|
sum
|
|
8925
8980
|
);
|
|
8926
8981
|
}
|
|
@@ -8929,10 +8984,10 @@ function randomRobsSubsetSatisfyingTargetCollateral(iasset, collateralAsset, tar
|
|
|
8929
8984
|
throw new Error("Must redeem and payout more than 0.");
|
|
8930
8985
|
}
|
|
8931
8986
|
const shuffled = randomiseFn(
|
|
8932
|
-
|
|
8987
|
+
F21.pipe(
|
|
8933
8988
|
allLrps,
|
|
8934
|
-
|
|
8935
|
-
([utxo, datum]) =>
|
|
8989
|
+
A11.filter(
|
|
8990
|
+
([utxo, datum]) => toHex13(datum.iasset) === toHex13(iasset) && match18(datum.orderType).with(
|
|
8936
8991
|
{ BuyIAssetOrder: P18.select() },
|
|
8937
8992
|
(content) => isSameAssetClass3(collateralAsset, content.collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice)
|
|
8938
8993
|
).otherwise(() => false) && !isBuyOrderFullyRedeemed(utxo.assets, datum.orderType, iassetPrice)
|
|
@@ -9011,15 +9066,15 @@ function castRobParams(params) {
|
|
|
9011
9066
|
import {
|
|
9012
9067
|
addAssets as addAssets13,
|
|
9013
9068
|
fromHex as fromHex13,
|
|
9014
|
-
toHex as
|
|
9069
|
+
toHex as toHex14,
|
|
9015
9070
|
fromText as fromText9,
|
|
9016
9071
|
getInputIndices as getInputIndices4
|
|
9017
9072
|
} from "@lucid-evolution/lucid";
|
|
9018
9073
|
import {
|
|
9019
9074
|
readonlyArray as RA4,
|
|
9020
|
-
array as
|
|
9021
|
-
function as
|
|
9022
|
-
option as
|
|
9075
|
+
array as A12,
|
|
9076
|
+
function as F22,
|
|
9077
|
+
option as O19
|
|
9023
9078
|
} from "fp-ts";
|
|
9024
9079
|
import { unzip, zip } from "fp-ts/lib/Array";
|
|
9025
9080
|
import {
|
|
@@ -9085,9 +9140,9 @@ async function cancelRob(robOutRef, sysParams, lucid) {
|
|
|
9085
9140
|
(_) => new Error("Expected a single ROB UTXO.")
|
|
9086
9141
|
);
|
|
9087
9142
|
const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
|
|
9088
|
-
return lucid.newTx().readFrom([robScriptRefUtxo]).collectFrom([robUtxo], serialiseRobRedeemer("Cancel")).addSignerKey(
|
|
9143
|
+
return lucid.newTx().readFrom([robScriptRefUtxo]).collectFrom([robUtxo], serialiseRobRedeemer("Cancel")).addSignerKey(toHex14(robDatum.owner));
|
|
9089
9144
|
}
|
|
9090
|
-
async function redeemRob(redemptionRobsData, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, lucid, sysParams,
|
|
9145
|
+
async function redeemRob(redemptionRobsData, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, lucid, sysParams, pythMessage = void 0, pythStateOutRef = void 0) {
|
|
9091
9146
|
const robScriptRefUtxo = matchSingle(
|
|
9092
9147
|
await lucid.utxosByOutRef([
|
|
9093
9148
|
fromSystemParamsScriptRef(sysParams.scriptReferences.robValidatorRef)
|
|
@@ -9131,7 +9186,6 @@ async function redeemRob(redemptionRobsData, priceOracleOutRef, iassetOutRef, co
|
|
|
9131
9186
|
pythMessage,
|
|
9132
9187
|
sysParams.pythConfig,
|
|
9133
9188
|
sysParams.cdpParams.biasTime,
|
|
9134
|
-
currentSlot,
|
|
9135
9189
|
lucid,
|
|
9136
9190
|
tx
|
|
9137
9191
|
);
|
|
@@ -9196,7 +9250,7 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
|
|
|
9196
9250
|
const reward = assetClassValueOf10(robUtxo.assets, iassetAc);
|
|
9197
9251
|
return [buyContent.collateralAsset, mkAssetsOf10(iassetAc, reward)];
|
|
9198
9252
|
}).with({ SellIAssetOrder: P19.select() }, (content) => {
|
|
9199
|
-
const reward =
|
|
9253
|
+
const reward = F22.pipe(
|
|
9200
9254
|
content.allowedCollateralAssets,
|
|
9201
9255
|
RA4.reduce(
|
|
9202
9256
|
{},
|
|
@@ -9236,12 +9290,12 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
|
|
|
9236
9290
|
return {
|
|
9237
9291
|
SellIAssetOrder: {
|
|
9238
9292
|
allowedCollateralAssets: content.allowedCollateralAssets.map(
|
|
9239
|
-
(entry) =>
|
|
9293
|
+
(entry) => F22.pipe(
|
|
9240
9294
|
newPrices,
|
|
9241
|
-
|
|
9295
|
+
A12.findFirst(
|
|
9242
9296
|
(newPrice) => isSameAssetClass4(newPrice[0], entry[0])
|
|
9243
9297
|
),
|
|
9244
|
-
|
|
9298
|
+
O19.match(
|
|
9245
9299
|
() => entry,
|
|
9246
9300
|
(newPrice) => [
|
|
9247
9301
|
entry[0],
|
|
@@ -9260,7 +9314,7 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
|
|
|
9260
9314
|
mkAssetsOf10(depositAsset, adjustmentAmt),
|
|
9261
9315
|
negateAssets5(rewardVal)
|
|
9262
9316
|
)
|
|
9263
|
-
).addSignerKey(
|
|
9317
|
+
).addSignerKey(toHex14(robDatum.owner));
|
|
9264
9318
|
}
|
|
9265
9319
|
async function claimRob(lucid, robOutRef, sysParams) {
|
|
9266
9320
|
return adjustRob(lucid, robOutRef, 0n, void 0, sysParams);
|
|
@@ -9305,14 +9359,13 @@ var mkRobValidatorFromSP = (params) => {
|
|
|
9305
9359
|
// src/contracts/rob-leverage/transactions.ts
|
|
9306
9360
|
import {
|
|
9307
9361
|
addAssets as addAssets14,
|
|
9308
|
-
slotToUnixTime as slotToUnixTime10,
|
|
9309
9362
|
Data as Data45,
|
|
9310
9363
|
fromHex as fromHex14,
|
|
9311
9364
|
getInputIndices as getInputIndices5
|
|
9312
9365
|
} from "@lucid-evolution/lucid";
|
|
9313
9366
|
|
|
9314
9367
|
// src/contracts/rob-leverage/helpers.ts
|
|
9315
|
-
import { array as
|
|
9368
|
+
import { array as A13, function as F23 } from "fp-ts";
|
|
9316
9369
|
import { Decimal as Decimal2 } from "decimal.js";
|
|
9317
9370
|
var MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
|
|
9318
9371
|
function approximateLeverageRedemptions(baseCollateral, targetLeverage, redemptionReimbursementRatio, debtMintingFeeRatio) {
|
|
@@ -9338,9 +9391,9 @@ function approximateLeverageRedemptions(baseCollateral, targetLeverage, redempti
|
|
|
9338
9391
|
};
|
|
9339
9392
|
}
|
|
9340
9393
|
function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement, redemptionReimbursementRatio, iassetPrice, redemptionLrps) {
|
|
9341
|
-
const redemptionDetails =
|
|
9394
|
+
const redemptionDetails = F23.pipe(
|
|
9342
9395
|
redemptionLrps,
|
|
9343
|
-
|
|
9396
|
+
A13.reduce(
|
|
9344
9397
|
{
|
|
9345
9398
|
remainingCollateralToSpend: lovelacesForRedemptionWithReimbursement,
|
|
9346
9399
|
redemptions: []
|
|
@@ -9394,9 +9447,9 @@ function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursem
|
|
|
9394
9447
|
}
|
|
9395
9448
|
)
|
|
9396
9449
|
);
|
|
9397
|
-
const res =
|
|
9450
|
+
const res = F23.pipe(
|
|
9398
9451
|
redemptionDetails.redemptions,
|
|
9399
|
-
|
|
9452
|
+
A13.reduce(
|
|
9400
9453
|
{
|
|
9401
9454
|
redeemedCollateral: 0n,
|
|
9402
9455
|
payoutIAssets: 0n,
|
|
@@ -9491,9 +9544,9 @@ function calculateLeverageFromCollateralRatio(iasset, collateralAsset, collatera
|
|
|
9491
9544
|
// src/contracts/rob-leverage/transactions.ts
|
|
9492
9545
|
import { mkAssetsOf as mkAssetsOf11 } from "@3rd-eye-labs/cardano-offchain-common";
|
|
9493
9546
|
import Decimal3 from "decimal.js";
|
|
9494
|
-
async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, cdpCreatorOref, interestOracleOref, treasuryOref, sysParams, lucid, allRobs,
|
|
9547
|
+
async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, iassetOutRef, collateralAssetOutRef, cdpCreatorOref, interestOracleOref, treasuryOref, sysParams, lucid, allRobs, pythMessage = void 0, pythStateOref = void 0) {
|
|
9495
9548
|
const network = lucid.config().network;
|
|
9496
|
-
const currentTime = BigInt(
|
|
9549
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
9497
9550
|
const [pkh, skh] = await addrDetails(lucid);
|
|
9498
9551
|
const robScriptRefUtxo = matchSingle(
|
|
9499
9552
|
await lucid.utxosByOutRef([
|
|
@@ -9687,7 +9740,6 @@ async function leverageCdpWithRob(leverage, baseCollateral, priceOracleOutRef, i
|
|
|
9687
9740
|
pythMessage,
|
|
9688
9741
|
sysParams.pythConfig,
|
|
9689
9742
|
sysParams.cdpCreatorParams.biasTime,
|
|
9690
|
-
currentSlot,
|
|
9691
9743
|
lucid,
|
|
9692
9744
|
tx
|
|
9693
9745
|
);
|
|
@@ -9745,7 +9797,6 @@ import {
|
|
|
9745
9797
|
Data as Data46,
|
|
9746
9798
|
fromHex as fromHex15,
|
|
9747
9799
|
fromText as fromText10,
|
|
9748
|
-
slotToUnixTime as slotToUnixTime11,
|
|
9749
9800
|
validatorToAddress as validatorToAddress2
|
|
9750
9801
|
} from "@lucid-evolution/lucid";
|
|
9751
9802
|
|
|
@@ -9774,9 +9825,8 @@ function mkPriceOracleValidator(params) {
|
|
|
9774
9825
|
// src/contracts/price-oracle/transactions.ts
|
|
9775
9826
|
import { mkAssetsOf as mkAssetsOf12 } from "@3rd-eye-labs/cardano-offchain-common";
|
|
9776
9827
|
import * as Core2 from "@evolution-sdk/evolution";
|
|
9777
|
-
async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams,
|
|
9778
|
-
const
|
|
9779
|
-
const now = BigInt(slotToUnixTime11(network, currentSlot));
|
|
9828
|
+
async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, refOutRef, auxiliaryData) {
|
|
9829
|
+
const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
9780
9830
|
if (!refOutRef) {
|
|
9781
9831
|
refOutRef = (await lucid.wallet().getUtxos())[0];
|
|
9782
9832
|
}
|
|
@@ -9809,9 +9859,8 @@ async function startPriceOracleTx(lucid, assetName, startPrice, oracleParams, cu
|
|
|
9809
9859
|
);
|
|
9810
9860
|
return [tx, priceOracleNft];
|
|
9811
9861
|
}
|
|
9812
|
-
async function feedPriceOracleTx(lucid, oracleOref, newPrice, oracleParams,
|
|
9813
|
-
const
|
|
9814
|
-
const currentTime = BigInt(slotToUnixTime11(network, currentSlot));
|
|
9862
|
+
async function feedPriceOracleTx(lucid, oracleOref, newPrice, oracleParams, auxiliaryData) {
|
|
9863
|
+
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
9815
9864
|
const priceOracleUtxo = matchSingle(
|
|
9816
9865
|
await lucid.utxosByOutRef([oracleOref]),
|
|
9817
9866
|
(_) => new Error("Expected a single price oracle UTXO")
|
|
@@ -9867,7 +9916,7 @@ import {
|
|
|
9867
9916
|
validatorToScriptHash as validatorToScriptHash3
|
|
9868
9917
|
} from "@lucid-evolution/lucid";
|
|
9869
9918
|
import {
|
|
9870
|
-
assetClassToUnit as
|
|
9919
|
+
assetClassToUnit as assetClassToUnit6,
|
|
9871
9920
|
assetClassValueOf as assetClassValueOf11,
|
|
9872
9921
|
lovelacesAmt as lovelacesAmt4,
|
|
9873
9922
|
mkAssetsOf as mkAssetsOf13,
|
|
@@ -9878,7 +9927,7 @@ import {
|
|
|
9878
9927
|
import {
|
|
9879
9928
|
applyParamsToScript as applyParamsToScript16,
|
|
9880
9929
|
Constr as Constr3,
|
|
9881
|
-
toHex as
|
|
9930
|
+
toHex as toHex15
|
|
9882
9931
|
} from "@lucid-evolution/lucid";
|
|
9883
9932
|
var authPolicyData = {
|
|
9884
9933
|
type: "PlutusV2",
|
|
@@ -9888,7 +9937,7 @@ function mkAuthTokenPolicy(ac, tn) {
|
|
|
9888
9937
|
return {
|
|
9889
9938
|
type: authPolicyData.type,
|
|
9890
9939
|
script: applyParamsToScript16(authPolicyData.cborHex, [
|
|
9891
|
-
new Constr3(0, [
|
|
9940
|
+
new Constr3(0, [toHex15(ac.currencySymbol), toHex15(ac.tokenName)]),
|
|
9892
9941
|
tn
|
|
9893
9942
|
])
|
|
9894
9943
|
};
|
|
@@ -9932,7 +9981,7 @@ var mkIAssetValidatorFromSP = (params) => {
|
|
|
9932
9981
|
import { match as match20 } from "ts-pattern";
|
|
9933
9982
|
|
|
9934
9983
|
// tests/test-helpers.ts
|
|
9935
|
-
import { array as
|
|
9984
|
+
import { array as A14, function as F24, option as O20 } from "fp-ts";
|
|
9936
9985
|
async function runAndAwaitTxBuilder(lucid, transaction, extraSigners = []) {
|
|
9937
9986
|
const bTx = await transaction.complete();
|
|
9938
9987
|
const signatures = [await bTx.partialSign.withWallet()];
|
|
@@ -10125,7 +10174,7 @@ async function initStakingManager(lucid, stakingParams) {
|
|
|
10125
10174
|
);
|
|
10126
10175
|
await submitTx(lucid, tx);
|
|
10127
10176
|
}
|
|
10128
|
-
async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, pythConfig
|
|
10177
|
+
async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, pythConfig) {
|
|
10129
10178
|
return match20(collateralAsset.priceOracle).returnType().with({ tag: "_indigo_oracle_nft" }, async (val) => {
|
|
10130
10179
|
const [pkh, _] = await addrDetails(lucid);
|
|
10131
10180
|
const priceOracleParams = {
|
|
@@ -10137,8 +10186,7 @@ async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, py
|
|
|
10137
10186
|
lucid,
|
|
10138
10187
|
val.tokenName,
|
|
10139
10188
|
val.startPrice,
|
|
10140
|
-
priceOracleParams
|
|
10141
|
-
currentSlot
|
|
10189
|
+
priceOracleParams
|
|
10142
10190
|
);
|
|
10143
10191
|
await runAndAwaitTxBuilder(lucid, priceOracleStartTx);
|
|
10144
10192
|
return { info: { OracleNft: priceOracleNft }, params: priceOracleParams };
|
|
@@ -10159,7 +10207,7 @@ async function handleOracleForCollateralAsset(lucid, iasset, collateralAsset, py
|
|
|
10159
10207
|
});
|
|
10160
10208
|
}).exhaustive();
|
|
10161
10209
|
}
|
|
10162
|
-
async function initializeAsset(lucid, iassetParams, iassetToken, collateralAssetAuthToken, cdpAuthToken, cdpParams, stableswapValidatorHash, stabilityPoolParams, stabilityPoolToken, asset, pythConfig
|
|
10210
|
+
async function initializeAsset(lucid, iassetParams, iassetToken, collateralAssetAuthToken, cdpAuthToken, cdpParams, stableswapValidatorHash, stabilityPoolParams, stabilityPoolToken, asset, pythConfig) {
|
|
10163
10211
|
const iassetName = fromHex16(fromText11(asset.name));
|
|
10164
10212
|
const collateralAssetInfos = [];
|
|
10165
10213
|
for (const collateralAsset of asset.collateralAssets) {
|
|
@@ -10181,8 +10229,7 @@ async function initializeAsset(lucid, iassetParams, iassetToken, collateralAsset
|
|
|
10181
10229
|
lucid,
|
|
10182
10230
|
asset,
|
|
10183
10231
|
collateralAsset,
|
|
10184
|
-
pythConfig
|
|
10185
|
-
currentSlot
|
|
10232
|
+
pythConfig
|
|
10186
10233
|
);
|
|
10187
10234
|
const collateralAssetContent = {
|
|
10188
10235
|
iasset: iassetName,
|
|
@@ -10316,7 +10363,7 @@ async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
|
|
|
10316
10363
|
const script = mkAuthTokenPolicy(asset, fromText11(tokenName));
|
|
10317
10364
|
const policyId = mintingPolicyToId2(script);
|
|
10318
10365
|
const address = await lucid.wallet().address();
|
|
10319
|
-
const utxos = (await lucid.utxosAtWithUnit(address,
|
|
10366
|
+
const utxos = (await lucid.utxosAtWithUnit(address, assetClassToUnit6(asset))).filter((utxo2) => assetClassValueOf11(utxo2.assets, asset) === 1n).sort((a, b) => Number(lovelacesAmt4(b.assets) - lovelacesAmt4(a.assets)));
|
|
10320
10367
|
if (utxos.length === 0) {
|
|
10321
10368
|
throw new Error("No utxos found");
|
|
10322
10369
|
}
|
|
@@ -10338,7 +10385,7 @@ import {
|
|
|
10338
10385
|
fromText as fromText13,
|
|
10339
10386
|
mintingPolicyToId as mintingPolicyToId3,
|
|
10340
10387
|
scriptHashToCredential as scriptHashToCredential4,
|
|
10341
|
-
toHex as
|
|
10388
|
+
toHex as toHex17,
|
|
10342
10389
|
validatorToScriptHash as validatorToScriptHash5
|
|
10343
10390
|
} from "@lucid-evolution/lucid";
|
|
10344
10391
|
import {
|
|
@@ -10350,7 +10397,7 @@ import {
|
|
|
10350
10397
|
import {
|
|
10351
10398
|
applyParamsToScript as applyParamsToScript18,
|
|
10352
10399
|
Constr as Constr4,
|
|
10353
|
-
toHex as
|
|
10400
|
+
toHex as toHex16
|
|
10354
10401
|
} from "@lucid-evolution/lucid";
|
|
10355
10402
|
var iassetPolicyData = {
|
|
10356
10403
|
type: "PlutusV2",
|
|
@@ -10360,7 +10407,7 @@ function mkIAssetTokenPolicy(ac) {
|
|
|
10360
10407
|
return {
|
|
10361
10408
|
type: iassetPolicyData.type,
|
|
10362
10409
|
script: applyParamsToScript18(iassetPolicyData.cborHex, [
|
|
10363
|
-
new Constr4(0, [
|
|
10410
|
+
new Constr4(0, [toHex16(ac.currencySymbol), toHex16(ac.tokenName)])
|
|
10364
10411
|
])
|
|
10365
10412
|
};
|
|
10366
10413
|
}
|
|
@@ -10566,7 +10613,7 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
|
|
|
10566
10613
|
throw error;
|
|
10567
10614
|
}
|
|
10568
10615
|
}
|
|
10569
|
-
const key = `${asset.name}/${
|
|
10616
|
+
const key = `${asset.name}/${toHex17(collateral.collateralAsset.currencySymbol)}.${toHex17(collateral.collateralAsset.tokenName)}`;
|
|
10570
10617
|
return {
|
|
10571
10618
|
[key]: {
|
|
10572
10619
|
params: val.pythFeedParams,
|
|
@@ -10583,7 +10630,7 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
|
|
|
10583
10630
|
pythFeeds: allPythFeeds
|
|
10584
10631
|
};
|
|
10585
10632
|
}
|
|
10586
|
-
async function init(lucid, defaultInitialAssets,
|
|
10633
|
+
async function init(lucid, defaultInitialAssets, mkPythBasedAssets = () => [], protocolParams, initOptions, spStakingCred = DEFAULT_STAKING_CRED, treasuryStakingCred = DEFAULT_STAKING_CRED) {
|
|
10587
10634
|
const startSlot = lucid.currentSlot();
|
|
10588
10635
|
const {
|
|
10589
10636
|
totalIndySupply,
|
|
@@ -10618,8 +10665,8 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
10618
10665
|
};
|
|
10619
10666
|
const versionRecordTokenPolicy = mkVersionRecordTokenPolicy({
|
|
10620
10667
|
upgradeToken: {
|
|
10621
|
-
currencySymbol:
|
|
10622
|
-
tokenName:
|
|
10668
|
+
currencySymbol: toHex17(upgradeToken.currencySymbol),
|
|
10669
|
+
tokenName: toHex17(upgradeToken.tokenName)
|
|
10623
10670
|
}
|
|
10624
10671
|
});
|
|
10625
10672
|
const versionRecordToken = {
|
|
@@ -10883,8 +10930,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
10883
10930
|
stabilityPoolParams,
|
|
10884
10931
|
stabilityPoolToken,
|
|
10885
10932
|
asset,
|
|
10886
|
-
pythConfig
|
|
10887
|
-
currentSlot
|
|
10933
|
+
pythConfig
|
|
10888
10934
|
);
|
|
10889
10935
|
assetInfos.push(assetInfo);
|
|
10890
10936
|
}
|
|
@@ -11133,39 +11179,39 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
11133
11179
|
}
|
|
11134
11180
|
|
|
11135
11181
|
// src/contracts/iasset/queries.ts
|
|
11136
|
-
import { toHex as
|
|
11182
|
+
import { toHex as toHex18 } from "@lucid-evolution/lucid";
|
|
11137
11183
|
import {
|
|
11138
|
-
assetClassToUnit as
|
|
11184
|
+
assetClassToUnit as assetClassToUnit7,
|
|
11139
11185
|
isSameAssetClass as isSameAssetClass5,
|
|
11140
|
-
matchSingle as
|
|
11186
|
+
matchSingle as matchSingle6
|
|
11141
11187
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
11142
|
-
import { option as
|
|
11188
|
+
import { option as O21, array as A15, function as F25 } from "fp-ts";
|
|
11143
11189
|
async function findIAsset(lucid, sysParams, iassetName) {
|
|
11144
11190
|
const iassetUtxos = await lucid.utxosAtWithUnit(
|
|
11145
11191
|
createScriptAddress(
|
|
11146
11192
|
lucid.config().network,
|
|
11147
11193
|
sysParams.validatorHashes.iassetHash
|
|
11148
11194
|
),
|
|
11149
|
-
|
|
11195
|
+
assetClassToUnit7(
|
|
11150
11196
|
fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken)
|
|
11151
11197
|
)
|
|
11152
11198
|
);
|
|
11153
|
-
return
|
|
11154
|
-
|
|
11199
|
+
return matchSingle6(
|
|
11200
|
+
F25.pipe(
|
|
11155
11201
|
iassetUtxos.map(
|
|
11156
|
-
(utxo) =>
|
|
11157
|
-
|
|
11158
|
-
|
|
11159
|
-
|
|
11160
|
-
if (
|
|
11161
|
-
return
|
|
11202
|
+
(utxo) => F25.pipe(
|
|
11203
|
+
O21.fromNullable(utxo.datum),
|
|
11204
|
+
O21.flatMap(parseIAssetDatum),
|
|
11205
|
+
O21.flatMap((datum) => {
|
|
11206
|
+
if (toHex18(datum.assetName) === toHex18(iassetName)) {
|
|
11207
|
+
return O21.some({ utxo, datum });
|
|
11162
11208
|
} else {
|
|
11163
|
-
return
|
|
11209
|
+
return O21.none;
|
|
11164
11210
|
}
|
|
11165
11211
|
})
|
|
11166
11212
|
)
|
|
11167
11213
|
),
|
|
11168
|
-
|
|
11214
|
+
A15.compact
|
|
11169
11215
|
),
|
|
11170
11216
|
(res) => new Error("Expected a single IAsset UTXO.: " + JSON.stringify(res))
|
|
11171
11217
|
);
|
|
@@ -11176,26 +11222,26 @@ async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset
|
|
|
11176
11222
|
lucid.config().network,
|
|
11177
11223
|
sysParams.validatorHashes.iassetHash
|
|
11178
11224
|
),
|
|
11179
|
-
|
|
11225
|
+
assetClassToUnit7(
|
|
11180
11226
|
fromSystemParamsAsset(sysParams.cdpParams.collateralAssetAuthToken)
|
|
11181
11227
|
)
|
|
11182
11228
|
);
|
|
11183
|
-
return
|
|
11184
|
-
|
|
11229
|
+
return matchSingle6(
|
|
11230
|
+
F25.pipe(
|
|
11185
11231
|
collateralAssetUtxos.map(
|
|
11186
|
-
(utxo) =>
|
|
11187
|
-
|
|
11188
|
-
|
|
11189
|
-
|
|
11190
|
-
if (isSameAssetClass5(datum.collateralAsset, collateralAsset) &&
|
|
11191
|
-
return
|
|
11232
|
+
(utxo) => F25.pipe(
|
|
11233
|
+
O21.fromNullable(utxo.datum),
|
|
11234
|
+
O21.flatMap(parseCollateralAssetDatum),
|
|
11235
|
+
O21.flatMap((datum) => {
|
|
11236
|
+
if (isSameAssetClass5(datum.collateralAsset, collateralAsset) && toHex18(iassetName) === toHex18(datum.iasset)) {
|
|
11237
|
+
return O21.some({ utxo, datum });
|
|
11192
11238
|
} else {
|
|
11193
|
-
return
|
|
11239
|
+
return O21.none;
|
|
11194
11240
|
}
|
|
11195
11241
|
})
|
|
11196
11242
|
)
|
|
11197
11243
|
),
|
|
11198
|
-
|
|
11244
|
+
A15.compact
|
|
11199
11245
|
),
|
|
11200
11246
|
(res) => new Error(
|
|
11201
11247
|
"Expected a single Collateral Asset UTXO.: " + JSON.stringify(res)
|
|
@@ -11205,6 +11251,7 @@ async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset
|
|
|
11205
11251
|
|
|
11206
11252
|
// src/contracts/stableswap/helpers.ts
|
|
11207
11253
|
import { fromHex as fromHex19, fromText as fromText14 } from "@lucid-evolution/lucid";
|
|
11254
|
+
import { array as A16, ord as Ord5, function as F27 } from "fp-ts";
|
|
11208
11255
|
|
|
11209
11256
|
// src/contracts/stableswap/types-new.ts
|
|
11210
11257
|
import {
|
|
@@ -11213,7 +11260,7 @@ import {
|
|
|
11213
11260
|
OutputReferenceSchema as OutputReferenceSchema7
|
|
11214
11261
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
11215
11262
|
import { TSchema as TSchema20, Data as Data51 } from "@evolution-sdk/evolution";
|
|
11216
|
-
import { option as
|
|
11263
|
+
import { option as O22, function as F26 } from "fp-ts";
|
|
11217
11264
|
import { Schema as Schema4 } from "effect";
|
|
11218
11265
|
var OpaqueData4 = Schema4.typeSchema(Data51.DataSchema);
|
|
11219
11266
|
var StableswapOrderDatumSchema = TSchema20.Struct({
|
|
@@ -11255,22 +11302,22 @@ function serialiseStableswapOrderDatum(d) {
|
|
|
11255
11302
|
}
|
|
11256
11303
|
function parseStableswapOrderDatum(datum) {
|
|
11257
11304
|
try {
|
|
11258
|
-
return
|
|
11305
|
+
return O22.some(
|
|
11259
11306
|
Data51.withSchema(
|
|
11260
11307
|
StableswapOrderDatumSchema,
|
|
11261
11308
|
DEFAULT_SCHEMA_OPTIONS
|
|
11262
11309
|
).fromCBORHex(datum)
|
|
11263
11310
|
);
|
|
11264
11311
|
} catch (_) {
|
|
11265
|
-
return
|
|
11312
|
+
return O22.none;
|
|
11266
11313
|
}
|
|
11267
11314
|
}
|
|
11268
11315
|
function parseStableswapOrderDatumOrThrow(datum) {
|
|
11269
|
-
return
|
|
11316
|
+
return F26.pipe(
|
|
11270
11317
|
parseStableswapOrderDatum(datum),
|
|
11271
|
-
|
|
11318
|
+
O22.match(() => {
|
|
11272
11319
|
throw new Error("Expected a Stableswap Order datum.");
|
|
11273
|
-
},
|
|
11320
|
+
}, F26.identity)
|
|
11274
11321
|
);
|
|
11275
11322
|
}
|
|
11276
11323
|
function serialiseStableswapOutputDatum(d) {
|
|
@@ -11287,28 +11334,32 @@ function serialiseStableswapOrderRedeemer(r) {
|
|
|
11287
11334
|
}
|
|
11288
11335
|
function parseStableswapOrderRedeemer(redeemerCborHex) {
|
|
11289
11336
|
try {
|
|
11290
|
-
return
|
|
11337
|
+
return O22.some(
|
|
11291
11338
|
Data51.withSchema(
|
|
11292
11339
|
StableswapOrderRedeemerSchema,
|
|
11293
11340
|
DEFAULT_SCHEMA_OPTIONS
|
|
11294
11341
|
).fromCBORHex(redeemerCborHex)
|
|
11295
11342
|
);
|
|
11296
11343
|
} catch (_) {
|
|
11297
|
-
return
|
|
11344
|
+
return O22.none;
|
|
11298
11345
|
}
|
|
11299
11346
|
}
|
|
11300
11347
|
function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
|
|
11301
|
-
return
|
|
11348
|
+
return F26.pipe(
|
|
11302
11349
|
parseStableswapOrderRedeemer(redeemerCborHex),
|
|
11303
|
-
|
|
11350
|
+
O22.match(() => {
|
|
11304
11351
|
throw new Error("Expected a Stableswap Order redeemer.");
|
|
11305
|
-
},
|
|
11352
|
+
}, F26.identity)
|
|
11306
11353
|
);
|
|
11307
11354
|
}
|
|
11308
11355
|
|
|
11309
11356
|
// src/contracts/stableswap/helpers.ts
|
|
11310
11357
|
import { Data as Data52 } from "@evolution-sdk/evolution";
|
|
11358
|
+
import { assetClassValueOf as assetClassValueOf12 } from "@3rd-eye-labs/cardano-offchain-common";
|
|
11311
11359
|
var BASE_MAX_EXECUTION_FEE = 1620000n;
|
|
11360
|
+
var defaultOrderProcessingConfig = {
|
|
11361
|
+
ignoreMaxExecutionFeeConstraint: false
|
|
11362
|
+
};
|
|
11312
11363
|
function createDestinationDatum(datum, outRef) {
|
|
11313
11364
|
if (!datum) {
|
|
11314
11365
|
return serialiseStableswapOutputDatum([
|
|
@@ -11321,6 +11372,229 @@ function createDestinationDatum(datum, outRef) {
|
|
|
11321
11372
|
}
|
|
11322
11373
|
return Data52.toCBORHex(datum);
|
|
11323
11374
|
}
|
|
11375
|
+
function psmOrderType(order, sysParams) {
|
|
11376
|
+
const iassetAc = {
|
|
11377
|
+
currencySymbol: fromHex19(
|
|
11378
|
+
sysParams.stableswapParams.iassetSymbol.unCurrencySymbol
|
|
11379
|
+
),
|
|
11380
|
+
tokenName: order.datum.iasset
|
|
11381
|
+
};
|
|
11382
|
+
const suppliedIasset = assetClassValueOf12(order.utxo.assets, iassetAc);
|
|
11383
|
+
const suppliedCollateralAsset = assetClassValueOf12(
|
|
11384
|
+
order.utxo.assets,
|
|
11385
|
+
order.datum.collateralAsset
|
|
11386
|
+
);
|
|
11387
|
+
if (suppliedIasset != 0n && suppliedCollateralAsset != 0n || suppliedIasset == 0n && suppliedCollateralAsset == 0n) {
|
|
11388
|
+
return {
|
|
11389
|
+
type: "ERROR",
|
|
11390
|
+
reason: "An order must supply either iAsset or collateral asset"
|
|
11391
|
+
};
|
|
11392
|
+
}
|
|
11393
|
+
const isMinting = suppliedCollateralAsset > 0n;
|
|
11394
|
+
return isMinting ? { type: "MINTING", suppliedCollateral: suppliedCollateralAsset } : { type: "REDEEMING", suppliedIassets: suppliedIasset };
|
|
11395
|
+
}
|
|
11396
|
+
function summariseOrder(order, psmPool, sysParams, orderProcessingConfig) {
|
|
11397
|
+
const orderType = psmOrderType(order, sysParams);
|
|
11398
|
+
if (orderType.type === "ERROR") {
|
|
11399
|
+
return { _tag: "ERROR", reason: orderType.reason };
|
|
11400
|
+
}
|
|
11401
|
+
const isOneToOne = psmPool.datum.collateralToIassetRatio.numerator === psmPool.datum.collateralToIassetRatio.denominator;
|
|
11402
|
+
if (!orderProcessingConfig.ignoreMaxExecutionFeeConstraint && order.datum.maxExecutionFee < BASE_MAX_EXECUTION_FEE) {
|
|
11403
|
+
return {
|
|
11404
|
+
_tag: "ERROR",
|
|
11405
|
+
reason: `Max execution fee is too low. Minimum: ${BASE_MAX_EXECUTION_FEE}`
|
|
11406
|
+
};
|
|
11407
|
+
}
|
|
11408
|
+
if (orderType.type === "MINTING") {
|
|
11409
|
+
const suppliedCollateralAsset = orderType.suppliedCollateral;
|
|
11410
|
+
if (rationalToFloat(order.datum.maxFeeRatio) < rationalToFloat(psmPool.datum.mintingFeeRatio)) {
|
|
11411
|
+
return { _tag: "ERROR", reason: "Max fee ratio not satisfied" };
|
|
11412
|
+
}
|
|
11413
|
+
if (isOneToOne) {
|
|
11414
|
+
const fee = calculateFeeFromRatio(
|
|
11415
|
+
psmPool.datum.mintingFeeRatio,
|
|
11416
|
+
suppliedCollateralAsset
|
|
11417
|
+
);
|
|
11418
|
+
return {
|
|
11419
|
+
_tag: "SUCCESS",
|
|
11420
|
+
result: {
|
|
11421
|
+
order,
|
|
11422
|
+
orderType: "MINTING",
|
|
11423
|
+
swapInfo: {
|
|
11424
|
+
suppliedCollateralAsset,
|
|
11425
|
+
suppliedIasset: 0n,
|
|
11426
|
+
owedCollateralAsset: 0n,
|
|
11427
|
+
owedIasset: suppliedCollateralAsset - fee,
|
|
11428
|
+
mintingFee: fee,
|
|
11429
|
+
redemptionFee: 0n
|
|
11430
|
+
}
|
|
11431
|
+
}
|
|
11432
|
+
};
|
|
11433
|
+
} else {
|
|
11434
|
+
const iAssetConversion = rationalFloor(
|
|
11435
|
+
rationalDiv(
|
|
11436
|
+
rationalFromInt(suppliedCollateralAsset),
|
|
11437
|
+
psmPool.datum.collateralToIassetRatio
|
|
11438
|
+
)
|
|
11439
|
+
);
|
|
11440
|
+
const attemptedNormalizedCollateral = rationalFloor(
|
|
11441
|
+
rationalMul(
|
|
11442
|
+
rationalFromInt(iAssetConversion),
|
|
11443
|
+
psmPool.datum.collateralToIassetRatio
|
|
11444
|
+
)
|
|
11445
|
+
);
|
|
11446
|
+
const normalizedCollateralSupplied = rationalFloor(
|
|
11447
|
+
rationalDiv(
|
|
11448
|
+
rationalFromInt(attemptedNormalizedCollateral),
|
|
11449
|
+
psmPool.datum.collateralToIassetRatio
|
|
11450
|
+
)
|
|
11451
|
+
) != iAssetConversion ? suppliedCollateralAsset : attemptedNormalizedCollateral;
|
|
11452
|
+
const fee = calculateFeeFromRatio(
|
|
11453
|
+
psmPool.datum.mintingFeeRatio,
|
|
11454
|
+
iAssetConversion
|
|
11455
|
+
);
|
|
11456
|
+
return {
|
|
11457
|
+
_tag: "SUCCESS",
|
|
11458
|
+
result: {
|
|
11459
|
+
order,
|
|
11460
|
+
orderType: "MINTING",
|
|
11461
|
+
swapInfo: {
|
|
11462
|
+
suppliedCollateralAsset: normalizedCollateralSupplied,
|
|
11463
|
+
suppliedIasset: 0n,
|
|
11464
|
+
owedIasset: iAssetConversion - fee,
|
|
11465
|
+
owedCollateralAsset: 0n,
|
|
11466
|
+
mintingFee: fee,
|
|
11467
|
+
redemptionFee: 0n
|
|
11468
|
+
}
|
|
11469
|
+
}
|
|
11470
|
+
};
|
|
11471
|
+
}
|
|
11472
|
+
} else {
|
|
11473
|
+
const suppliedIasset = orderType.suppliedIassets;
|
|
11474
|
+
if (rationalToFloat(order.datum.maxFeeRatio) < rationalToFloat(psmPool.datum.redemptionFeeRatio)) {
|
|
11475
|
+
return { _tag: "ERROR", reason: "Max fee ratio not satisfied" };
|
|
11476
|
+
}
|
|
11477
|
+
const fee = calculateFeeFromRatio(
|
|
11478
|
+
psmPool.datum.redemptionFeeRatio,
|
|
11479
|
+
suppliedIasset
|
|
11480
|
+
);
|
|
11481
|
+
const effectiveSuppliedIasset = suppliedIasset - fee;
|
|
11482
|
+
if (isOneToOne) {
|
|
11483
|
+
return {
|
|
11484
|
+
_tag: "SUCCESS",
|
|
11485
|
+
result: {
|
|
11486
|
+
order,
|
|
11487
|
+
orderType: "REDEEMING",
|
|
11488
|
+
swapInfo: {
|
|
11489
|
+
suppliedIasset: effectiveSuppliedIasset,
|
|
11490
|
+
suppliedCollateralAsset: 0n,
|
|
11491
|
+
owedCollateralAsset: effectiveSuppliedIasset,
|
|
11492
|
+
owedIasset: 0n,
|
|
11493
|
+
redemptionFee: fee,
|
|
11494
|
+
mintingFee: 0n
|
|
11495
|
+
}
|
|
11496
|
+
}
|
|
11497
|
+
};
|
|
11498
|
+
} else {
|
|
11499
|
+
const collateralConversion = rationalFloor(
|
|
11500
|
+
rationalMul(
|
|
11501
|
+
rationalFromInt(effectiveSuppliedIasset),
|
|
11502
|
+
psmPool.datum.collateralToIassetRatio
|
|
11503
|
+
)
|
|
11504
|
+
);
|
|
11505
|
+
const attemptedNormalizedEffectiveIasset = rationalFloor(
|
|
11506
|
+
rationalDiv(
|
|
11507
|
+
rationalFromInt(collateralConversion),
|
|
11508
|
+
psmPool.datum.collateralToIassetRatio
|
|
11509
|
+
)
|
|
11510
|
+
);
|
|
11511
|
+
const normalizedEffectiveIasset = rationalFloor(
|
|
11512
|
+
rationalMul(
|
|
11513
|
+
rationalFromInt(attemptedNormalizedEffectiveIasset),
|
|
11514
|
+
psmPool.datum.collateralToIassetRatio
|
|
11515
|
+
)
|
|
11516
|
+
) != collateralConversion ? effectiveSuppliedIasset : attemptedNormalizedEffectiveIasset;
|
|
11517
|
+
return {
|
|
11518
|
+
_tag: "SUCCESS",
|
|
11519
|
+
result: {
|
|
11520
|
+
order,
|
|
11521
|
+
orderType: "REDEEMING",
|
|
11522
|
+
swapInfo: {
|
|
11523
|
+
suppliedIasset: normalizedEffectiveIasset,
|
|
11524
|
+
suppliedCollateralAsset: 0n,
|
|
11525
|
+
owedCollateralAsset: rationalFloor(
|
|
11526
|
+
rationalMul(
|
|
11527
|
+
rationalFromInt(effectiveSuppliedIasset),
|
|
11528
|
+
psmPool.datum.collateralToIassetRatio
|
|
11529
|
+
)
|
|
11530
|
+
),
|
|
11531
|
+
owedIasset: 0n,
|
|
11532
|
+
redemptionFee: fee,
|
|
11533
|
+
mintingFee: 0n
|
|
11534
|
+
}
|
|
11535
|
+
}
|
|
11536
|
+
};
|
|
11537
|
+
}
|
|
11538
|
+
}
|
|
11539
|
+
}
|
|
11540
|
+
function pickValidSatisfiableOrders(orders, pool, sysParams, orderProcessingConfig) {
|
|
11541
|
+
const psmAvailableLiq = assetClassValueOf12(
|
|
11542
|
+
pool.utxo.assets,
|
|
11543
|
+
pool.datum.collateralAsset
|
|
11544
|
+
);
|
|
11545
|
+
const validOrders = orders.flatMap((order) => {
|
|
11546
|
+
try {
|
|
11547
|
+
const res = summariseOrder(order, pool, sysParams, orderProcessingConfig);
|
|
11548
|
+
return res._tag === "SUCCESS" ? [res.result] : [];
|
|
11549
|
+
} catch (_) {
|
|
11550
|
+
return [];
|
|
11551
|
+
}
|
|
11552
|
+
});
|
|
11553
|
+
const { left: mintingOrders, right: redeemingOrdersSortedDesc } = F27.pipe(
|
|
11554
|
+
validOrders,
|
|
11555
|
+
A16.partition((o) => o.orderType === "REDEEMING"),
|
|
11556
|
+
({ left, right }) => ({
|
|
11557
|
+
left,
|
|
11558
|
+
// Sort the redeeming orders descending.
|
|
11559
|
+
right: F27.pipe(
|
|
11560
|
+
right,
|
|
11561
|
+
A16.sort(
|
|
11562
|
+
Ord5.contramap(
|
|
11563
|
+
(o) => o.swapInfo.owedCollateralAsset
|
|
11564
|
+
)(Ord5.reverse(BigIntOrd))
|
|
11565
|
+
)
|
|
11566
|
+
)
|
|
11567
|
+
})
|
|
11568
|
+
);
|
|
11569
|
+
const totalCollateralDiff = F27.pipe(
|
|
11570
|
+
validOrders,
|
|
11571
|
+
A16.reduce(
|
|
11572
|
+
0n,
|
|
11573
|
+
(acc, order) => acc + order.swapInfo.suppliedCollateralAsset - order.swapInfo.owedCollateralAsset
|
|
11574
|
+
)
|
|
11575
|
+
);
|
|
11576
|
+
if (psmAvailableLiq + totalCollateralDiff >= 0n) {
|
|
11577
|
+
return validOrders.map((o) => o.order);
|
|
11578
|
+
}
|
|
11579
|
+
const collateralFromMinting = F27.pipe(
|
|
11580
|
+
mintingOrders,
|
|
11581
|
+
A16.reduce(0n, (acc, o) => acc + o.swapInfo.suppliedCollateralAsset)
|
|
11582
|
+
);
|
|
11583
|
+
const { selected } = F27.pipe(
|
|
11584
|
+
redeemingOrdersSortedDesc,
|
|
11585
|
+
A16.reduce(
|
|
11586
|
+
{
|
|
11587
|
+
intermediateCollateralAmt: psmAvailableLiq + collateralFromMinting,
|
|
11588
|
+
selected: []
|
|
11589
|
+
},
|
|
11590
|
+
({ intermediateCollateralAmt, selected: selected2 }, order) => intermediateCollateralAmt >= order.swapInfo.owedCollateralAsset ? {
|
|
11591
|
+
intermediateCollateralAmt: intermediateCollateralAmt - order.swapInfo.owedCollateralAsset,
|
|
11592
|
+
selected: [...selected2, order]
|
|
11593
|
+
} : { intermediateCollateralAmt, selected: selected2 }
|
|
11594
|
+
)
|
|
11595
|
+
);
|
|
11596
|
+
return [...mintingOrders, ...selected].map((o) => o.order);
|
|
11597
|
+
}
|
|
11324
11598
|
|
|
11325
11599
|
// src/contracts/stableswap/transactions.ts
|
|
11326
11600
|
import {
|
|
@@ -11331,20 +11605,20 @@ import {
|
|
|
11331
11605
|
fromText as fromText15,
|
|
11332
11606
|
paymentCredentialOf as paymentCredentialOf3,
|
|
11333
11607
|
sortUTxOs as sortUTxOs2,
|
|
11334
|
-
toHex as
|
|
11608
|
+
toHex as toHex19
|
|
11335
11609
|
} from "@lucid-evolution/lucid";
|
|
11336
11610
|
import {
|
|
11337
11611
|
addressFromBech32 as addressFromBech323,
|
|
11338
11612
|
addressToBech32 as addressToBech323,
|
|
11339
11613
|
getInlineDatumOrThrow as getInlineDatumOrThrow6,
|
|
11340
|
-
matchSingle as
|
|
11614
|
+
matchSingle as matchSingle7,
|
|
11341
11615
|
mkAssetsOf as mkAssetsOf16,
|
|
11342
11616
|
mkLovelacesOf as mkLovelacesOf9,
|
|
11343
11617
|
lovelacesAmt as lovelacesAmt5,
|
|
11344
11618
|
isSameOutRef as isSameOutRef2,
|
|
11345
|
-
assetClassValueOf as
|
|
11619
|
+
assetClassValueOf as assetClassValueOf13
|
|
11346
11620
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
11347
|
-
import { array as
|
|
11621
|
+
import { array as A17, function as F28 } from "fp-ts";
|
|
11348
11622
|
import { isEmpty } from "fp-ts/lib/Array";
|
|
11349
11623
|
async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
|
|
11350
11624
|
const myAddress = await lucid.wallet().address();
|
|
@@ -11398,7 +11672,7 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
|
|
|
11398
11672
|
);
|
|
11399
11673
|
}
|
|
11400
11674
|
async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
|
|
11401
|
-
const stableswapScriptRefUtxo =
|
|
11675
|
+
const stableswapScriptRefUtxo = matchSingle7(
|
|
11402
11676
|
await lucid.utxosByOutRef([
|
|
11403
11677
|
fromSystemParamsScriptRef(
|
|
11404
11678
|
sysParams.scriptReferences.stableswapValidatorRef
|
|
@@ -11406,7 +11680,7 @@ async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
|
|
|
11406
11680
|
]),
|
|
11407
11681
|
(_) => new Error("Expected a single Stableswap Ref Script UTXO")
|
|
11408
11682
|
);
|
|
11409
|
-
const stableswapOrderUtxo =
|
|
11683
|
+
const stableswapOrderUtxo = matchSingle7(
|
|
11410
11684
|
await lucid.utxosByOutRef([stableswapOrderOref]),
|
|
11411
11685
|
(_) => new Error("Expected a single Stableswap Order UTXO.")
|
|
11412
11686
|
);
|
|
@@ -11416,10 +11690,10 @@ async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
|
|
|
11416
11690
|
return lucid.newTx().readFrom([stableswapScriptRefUtxo]).collectFrom(
|
|
11417
11691
|
[stableswapOrderUtxo],
|
|
11418
11692
|
serialiseStableswapOrderRedeemer("CancelStableswapOrder")
|
|
11419
|
-
).addSignerKey(
|
|
11693
|
+
).addSignerKey(toHex19(stableswapOrderDatum.owner));
|
|
11420
11694
|
}
|
|
11421
|
-
async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPoolOref, treasuryOref, sysParams, lucid) {
|
|
11422
|
-
const stableswapScriptRefUtxo =
|
|
11695
|
+
async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPoolOref, treasuryOref, sysParams, lucid, orderProcessingConfig = defaultOrderProcessingConfig) {
|
|
11696
|
+
const stableswapScriptRefUtxo = matchSingle7(
|
|
11423
11697
|
await lucid.utxosByOutRef([
|
|
11424
11698
|
fromSystemParamsScriptRef(
|
|
11425
11699
|
sysParams.scriptReferences.stableswapValidatorRef
|
|
@@ -11427,13 +11701,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11427
11701
|
]),
|
|
11428
11702
|
(_) => new Error("Expected a single Stableswap Ref Script UTXO")
|
|
11429
11703
|
);
|
|
11430
|
-
const cdpScriptRefUtxo =
|
|
11704
|
+
const cdpScriptRefUtxo = matchSingle7(
|
|
11431
11705
|
await lucid.utxosByOutRef([
|
|
11432
11706
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
11433
11707
|
]),
|
|
11434
11708
|
(_) => new Error("Expected a single CDP Ref Script UTXO")
|
|
11435
11709
|
);
|
|
11436
|
-
const iAssetTokenPolicyRefScriptUtxo =
|
|
11710
|
+
const iAssetTokenPolicyRefScriptUtxo = matchSingle7(
|
|
11437
11711
|
await lucid.utxosByOutRef([
|
|
11438
11712
|
fromSystemParamsScriptRef(
|
|
11439
11713
|
sysParams.scriptReferences.iAssetTokenPolicyRef
|
|
@@ -11463,7 +11737,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11463
11737
|
tokenName: mainOrderDatum.iasset
|
|
11464
11738
|
};
|
|
11465
11739
|
const collateralAc = mainOrderDatum.collateralAsset;
|
|
11466
|
-
const stableswapPoolUtxo =
|
|
11740
|
+
const stableswapPoolUtxo = matchSingle7(
|
|
11467
11741
|
await lucid.utxosByOutRef([stableswapPoolOref]),
|
|
11468
11742
|
(_) => new Error("Expected a single cdp UTXO")
|
|
11469
11743
|
);
|
|
@@ -11475,137 +11749,24 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11475
11749
|
const orderDatum = parseStableswapOrderDatumOrThrow(
|
|
11476
11750
|
getInlineDatumOrThrow6(orderUtxo)
|
|
11477
11751
|
);
|
|
11478
|
-
if (
|
|
11752
|
+
if (toHex19(orderDatum.iasset) != toHex19(mainOrderDatum.iasset) || toHex19(orderDatum.collateralAsset.currencySymbol) != toHex19(mainOrderDatum.collateralAsset.currencySymbol) || toHex19(orderDatum.collateralAsset.tokenName) != toHex19(mainOrderDatum.collateralAsset.tokenName)) {
|
|
11479
11753
|
throw new Error("Wrong batch of orders");
|
|
11480
11754
|
}
|
|
11481
|
-
const
|
|
11482
|
-
|
|
11483
|
-
|
|
11484
|
-
|
|
11755
|
+
const res = summariseOrder(
|
|
11756
|
+
{ utxo: orderUtxo, datum: orderDatum },
|
|
11757
|
+
{ utxo: stableswapPoolUtxo, datum: stableswapPoolDatum },
|
|
11758
|
+
sysParams,
|
|
11759
|
+
orderProcessingConfig
|
|
11485
11760
|
);
|
|
11486
|
-
if (
|
|
11487
|
-
throw new Error(
|
|
11488
|
-
"An order must supply either iAsset or collateral asset"
|
|
11489
|
-
);
|
|
11490
|
-
}
|
|
11491
|
-
const isMinting = suppliedCollateralAsset > 0n;
|
|
11492
|
-
const isOneToOne = stableswapPoolDatum.collateralToIassetRatio.numerator === stableswapPoolDatum.collateralToIassetRatio.denominator;
|
|
11493
|
-
if (isMinting) {
|
|
11494
|
-
if (isOneToOne) {
|
|
11495
|
-
const fee2 = calculateFeeFromRatio(
|
|
11496
|
-
stableswapPoolDatum.mintingFeeRatio,
|
|
11497
|
-
suppliedCollateralAsset
|
|
11498
|
-
);
|
|
11499
|
-
return {
|
|
11500
|
-
utxo: orderUtxo,
|
|
11501
|
-
datum: orderDatum,
|
|
11502
|
-
swapInfo: {
|
|
11503
|
-
suppliedCollateralAsset,
|
|
11504
|
-
suppliedIasset: 0n,
|
|
11505
|
-
owedCollateralAsset: 0n,
|
|
11506
|
-
owedIasset: suppliedCollateralAsset - fee2,
|
|
11507
|
-
mintingFee: fee2,
|
|
11508
|
-
redemptionFee: 0n
|
|
11509
|
-
}
|
|
11510
|
-
};
|
|
11511
|
-
} else {
|
|
11512
|
-
const iAssetConversion = rationalFloor(
|
|
11513
|
-
rationalDiv(
|
|
11514
|
-
rationalFromInt(suppliedCollateralAsset),
|
|
11515
|
-
stableswapPoolDatum.collateralToIassetRatio
|
|
11516
|
-
)
|
|
11517
|
-
);
|
|
11518
|
-
const attemptedNormalizedCollateral = rationalFloor(
|
|
11519
|
-
rationalMul(
|
|
11520
|
-
rationalFromInt(iAssetConversion),
|
|
11521
|
-
stableswapPoolDatum.collateralToIassetRatio
|
|
11522
|
-
)
|
|
11523
|
-
);
|
|
11524
|
-
const normalizedCollateralSupplied = rationalFloor(
|
|
11525
|
-
rationalDiv(
|
|
11526
|
-
rationalFromInt(attemptedNormalizedCollateral),
|
|
11527
|
-
stableswapPoolDatum.collateralToIassetRatio
|
|
11528
|
-
)
|
|
11529
|
-
) != iAssetConversion ? suppliedCollateralAsset : attemptedNormalizedCollateral;
|
|
11530
|
-
const fee2 = calculateFeeFromRatio(
|
|
11531
|
-
stableswapPoolDatum.mintingFeeRatio,
|
|
11532
|
-
iAssetConversion
|
|
11533
|
-
);
|
|
11534
|
-
return {
|
|
11535
|
-
utxo: orderUtxo,
|
|
11536
|
-
datum: orderDatum,
|
|
11537
|
-
swapInfo: {
|
|
11538
|
-
suppliedCollateralAsset: normalizedCollateralSupplied,
|
|
11539
|
-
suppliedIasset: 0n,
|
|
11540
|
-
owedCollateralAsset: 0n,
|
|
11541
|
-
owedIasset: iAssetConversion - fee2,
|
|
11542
|
-
mintingFee: fee2,
|
|
11543
|
-
redemptionFee: 0n
|
|
11544
|
-
}
|
|
11545
|
-
};
|
|
11546
|
-
}
|
|
11547
|
-
} else {
|
|
11548
|
-
const fee2 = calculateFeeFromRatio(
|
|
11549
|
-
stableswapPoolDatum.redemptionFeeRatio,
|
|
11550
|
-
suppliedIasset
|
|
11551
|
-
);
|
|
11552
|
-
const effectiveSuppliedIasset = suppliedIasset - fee2;
|
|
11553
|
-
if (isOneToOne) {
|
|
11554
|
-
return {
|
|
11555
|
-
utxo: orderUtxo,
|
|
11556
|
-
datum: orderDatum,
|
|
11557
|
-
swapInfo: {
|
|
11558
|
-
suppliedCollateralAsset: 0n,
|
|
11559
|
-
suppliedIasset: effectiveSuppliedIasset,
|
|
11560
|
-
owedCollateralAsset: effectiveSuppliedIasset,
|
|
11561
|
-
owedIasset: 0n,
|
|
11562
|
-
mintingFee: 0n,
|
|
11563
|
-
redemptionFee: fee2
|
|
11564
|
-
}
|
|
11565
|
-
};
|
|
11566
|
-
} else {
|
|
11567
|
-
const collateralConversion = rationalFloor(
|
|
11568
|
-
rationalMul(
|
|
11569
|
-
rationalFromInt(effectiveSuppliedIasset),
|
|
11570
|
-
stableswapPoolDatum.collateralToIassetRatio
|
|
11571
|
-
)
|
|
11572
|
-
);
|
|
11573
|
-
const attemptedNormalizedEffectiveIasset = rationalFloor(
|
|
11574
|
-
rationalDiv(
|
|
11575
|
-
rationalFromInt(collateralConversion),
|
|
11576
|
-
stableswapPoolDatum.collateralToIassetRatio
|
|
11577
|
-
)
|
|
11578
|
-
);
|
|
11579
|
-
const normalizedEffectiveIasset = rationalFloor(
|
|
11580
|
-
rationalMul(
|
|
11581
|
-
rationalFromInt(attemptedNormalizedEffectiveIasset),
|
|
11582
|
-
stableswapPoolDatum.collateralToIassetRatio
|
|
11583
|
-
)
|
|
11584
|
-
) != collateralConversion ? effectiveSuppliedIasset : attemptedNormalizedEffectiveIasset;
|
|
11585
|
-
return {
|
|
11586
|
-
utxo: orderUtxo,
|
|
11587
|
-
datum: orderDatum,
|
|
11588
|
-
swapInfo: {
|
|
11589
|
-
suppliedCollateralAsset: 0n,
|
|
11590
|
-
suppliedIasset: normalizedEffectiveIasset,
|
|
11591
|
-
owedCollateralAsset: rationalFloor(
|
|
11592
|
-
rationalMul(
|
|
11593
|
-
rationalFromInt(effectiveSuppliedIasset),
|
|
11594
|
-
stableswapPoolDatum.collateralToIassetRatio
|
|
11595
|
-
)
|
|
11596
|
-
),
|
|
11597
|
-
owedIasset: 0n,
|
|
11598
|
-
mintingFee: 0n,
|
|
11599
|
-
redemptionFee: fee2
|
|
11600
|
-
}
|
|
11601
|
-
};
|
|
11602
|
-
}
|
|
11761
|
+
if (res._tag === "ERROR") {
|
|
11762
|
+
throw new Error(res.reason);
|
|
11603
11763
|
}
|
|
11764
|
+
return res.result;
|
|
11604
11765
|
}
|
|
11605
11766
|
);
|
|
11606
|
-
const totalSwapInfo =
|
|
11767
|
+
const totalSwapInfo = F28.pipe(
|
|
11607
11768
|
ordersInfo,
|
|
11608
|
-
|
|
11769
|
+
A17.reduce(
|
|
11609
11770
|
{
|
|
11610
11771
|
suppliedCollateralAsset: 0n,
|
|
11611
11772
|
suppliedIasset: 0n,
|
|
@@ -11627,6 +11788,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11627
11788
|
)
|
|
11628
11789
|
);
|
|
11629
11790
|
const collateralAmtChangePool = totalSwapInfo.suppliedCollateralAsset - totalSwapInfo.owedCollateralAsset;
|
|
11791
|
+
const newPsmPoolValue = addAssets18(
|
|
11792
|
+
stableswapPoolUtxo.assets,
|
|
11793
|
+
mkAssetsOf16(collateralAc, collateralAmtChangePool)
|
|
11794
|
+
);
|
|
11795
|
+
if (assetClassValueOf13(newPsmPoolValue, collateralAc) < 0n) {
|
|
11796
|
+
throw new Error("Cannot batch more than liquidity allows");
|
|
11797
|
+
}
|
|
11630
11798
|
const amountToMint = totalSwapInfo.owedIasset - totalSwapInfo.suppliedIasset + totalSwapInfo.mintingFee;
|
|
11631
11799
|
const fee = totalSwapInfo.mintingFee + totalSwapInfo.redemptionFee;
|
|
11632
11800
|
const tx = lucid.newTx().readFrom([
|
|
@@ -11647,20 +11815,17 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11647
11815
|
kind: "inline",
|
|
11648
11816
|
value: serialiseStableswapPoolDatum(stableswapPoolDatum)
|
|
11649
11817
|
},
|
|
11650
|
-
|
|
11651
|
-
stableswapPoolUtxo.assets,
|
|
11652
|
-
mkAssetsOf16(collateralAc, collateralAmtChangePool)
|
|
11653
|
-
) : stableswapPoolUtxo.assets
|
|
11818
|
+
newPsmPoolValue
|
|
11654
11819
|
).setMinFee(stableswapOrderOrefs.length > 1 ? 1498875n : 1030000n);
|
|
11655
11820
|
if (amountToMint !== 0n) {
|
|
11656
11821
|
tx.mintAssets(mkAssetsOf16(iassetAc, amountToMint), Data53.void());
|
|
11657
11822
|
}
|
|
11658
|
-
|
|
11823
|
+
F28.pipe(
|
|
11659
11824
|
ordersInfo,
|
|
11660
|
-
|
|
11825
|
+
A17.reduce(tx, (acc, orderInfo) => {
|
|
11661
11826
|
return acc.collectFrom(
|
|
11662
|
-
[orderInfo.utxo],
|
|
11663
|
-
isSameOutRef2(orderInfo.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
|
|
11827
|
+
[orderInfo.order.utxo],
|
|
11828
|
+
isSameOutRef2(orderInfo.order.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
|
|
11664
11829
|
kind: "selected",
|
|
11665
11830
|
makeRedeemer: (inputIndices) => {
|
|
11666
11831
|
return serialiseStableswapOrderRedeemer({
|
|
@@ -11670,24 +11835,27 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11670
11835
|
}
|
|
11671
11836
|
});
|
|
11672
11837
|
},
|
|
11673
|
-
inputs: [orderInfo.utxo, mainOrderUtxo]
|
|
11838
|
+
inputs: [orderInfo.order.utxo, mainOrderUtxo]
|
|
11674
11839
|
}
|
|
11675
11840
|
).pay.ToAddressWithData(
|
|
11676
|
-
addressToBech323(
|
|
11841
|
+
addressToBech323(
|
|
11842
|
+
orderInfo.order.datum.destination,
|
|
11843
|
+
lucid.config().network
|
|
11844
|
+
),
|
|
11677
11845
|
{
|
|
11678
11846
|
kind: "inline",
|
|
11679
11847
|
value: createDestinationDatum(
|
|
11680
|
-
orderInfo.datum.destinationInlineDatum ?? null,
|
|
11681
|
-
orderInfo.utxo
|
|
11848
|
+
orderInfo.order.datum.destinationInlineDatum ?? null,
|
|
11849
|
+
orderInfo.order.utxo
|
|
11682
11850
|
)
|
|
11683
11851
|
},
|
|
11684
11852
|
addAssets18(
|
|
11685
|
-
// Currently, we always take the max execution fee from the order utxo.
|
|
11853
|
+
// NOTICE: Currently, we always take the max execution fee from the order utxo.
|
|
11686
11854
|
// This can be improved so that we take the actual execution fee.
|
|
11687
11855
|
mkLovelacesOf9(
|
|
11688
|
-
lovelacesAmt5(orderInfo.utxo.assets) - orderInfo.datum.maxExecutionFee
|
|
11856
|
+
lovelacesAmt5(orderInfo.order.utxo.assets) - orderInfo.order.datum.maxExecutionFee
|
|
11689
11857
|
),
|
|
11690
|
-
orderInfo.
|
|
11858
|
+
orderInfo.orderType === "MINTING" ? mkAssetsOf16(iassetAc, orderInfo.swapInfo.owedIasset) : mkAssetsOf16(
|
|
11691
11859
|
collateralAc,
|
|
11692
11860
|
orderInfo.swapInfo.owedCollateralAsset
|
|
11693
11861
|
)
|
|
@@ -11710,7 +11878,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11710
11878
|
return tx;
|
|
11711
11879
|
}
|
|
11712
11880
|
async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRef, newMintingFeeRatio, newRedemptionFeeRatio, sysParams, lucid) {
|
|
11713
|
-
const stableswapScriptRefUtxo =
|
|
11881
|
+
const stableswapScriptRefUtxo = matchSingle7(
|
|
11714
11882
|
await lucid.utxosByOutRef([
|
|
11715
11883
|
fromSystemParamsScriptRef(
|
|
11716
11884
|
sysParams.scriptReferences.stableswapValidatorRef
|
|
@@ -11718,17 +11886,17 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
11718
11886
|
]),
|
|
11719
11887
|
(_) => new Error("Expected a single Stableswap Ref Script UTXO")
|
|
11720
11888
|
);
|
|
11721
|
-
const cdpScriptRefUtxo =
|
|
11889
|
+
const cdpScriptRefUtxo = matchSingle7(
|
|
11722
11890
|
await lucid.utxosByOutRef([
|
|
11723
11891
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
11724
11892
|
]),
|
|
11725
11893
|
(_) => new Error("Expected a single CDP Ref Script UTXO")
|
|
11726
11894
|
);
|
|
11727
|
-
const stableswapPool =
|
|
11895
|
+
const stableswapPool = matchSingle7(
|
|
11728
11896
|
await lucid.utxosByOutRef([stableswapPoolOutRef]),
|
|
11729
11897
|
(_) => new Error("Expected a single Stableswap Pool UTXO.")
|
|
11730
11898
|
);
|
|
11731
|
-
const stableswapFeeUtxo =
|
|
11899
|
+
const stableswapFeeUtxo = matchSingle7(
|
|
11732
11900
|
await lucid.utxosByOutRef([stableswapFeeOutRef]),
|
|
11733
11901
|
(_) => new Error("Expected a single Stableswap Fee UTXO.")
|
|
11734
11902
|
);
|
|
@@ -11761,7 +11929,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
11761
11929
|
value: serialiseStableswapPoolDatum(newStableswapPoolDatum)
|
|
11762
11930
|
},
|
|
11763
11931
|
stableswapPool.assets
|
|
11764
|
-
).addSignerKey(
|
|
11932
|
+
).addSignerKey(toHex19(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
|
|
11765
11933
|
}
|
|
11766
11934
|
export {
|
|
11767
11935
|
AccountContentSchema,
|
|
@@ -11881,6 +12049,7 @@ export {
|
|
|
11881
12049
|
createStableswapOrder,
|
|
11882
12050
|
decodePriceUpdate,
|
|
11883
12051
|
decodePythMessage,
|
|
12052
|
+
defaultOrderProcessingConfig,
|
|
11884
12053
|
depositCdp,
|
|
11885
12054
|
deriveAuthToken,
|
|
11886
12055
|
derivePythPrice,
|
|
@@ -11901,6 +12070,7 @@ export {
|
|
|
11901
12070
|
findAllTreasuryUtxos,
|
|
11902
12071
|
findAllTreasuryUtxosWithNonAdaAsset,
|
|
11903
12072
|
findCollateralAsset,
|
|
12073
|
+
findE2s2sSnapshots,
|
|
11904
12074
|
findIAsset,
|
|
11905
12075
|
findRandomCdpCreator,
|
|
11906
12076
|
findRandomNonAdminInterestCollector,
|
|
@@ -11908,6 +12078,8 @@ export {
|
|
|
11908
12078
|
findRandomTreasuryUtxoWithAsset,
|
|
11909
12079
|
findRandomTreasuryUtxoWithOnlyAda,
|
|
11910
12080
|
findRelevantE2s2sIdxs,
|
|
12081
|
+
findStabilityPool,
|
|
12082
|
+
findStabilityPoolAccount,
|
|
11911
12083
|
findStakingManager,
|
|
11912
12084
|
findStakingManagerByOutRef,
|
|
11913
12085
|
findStakingPositionByOutRef,
|
|
@@ -12041,7 +12213,9 @@ export {
|
|
|
12041
12213
|
parseStakingRedeemer,
|
|
12042
12214
|
parseStakingRedeemerOrThrow,
|
|
12043
12215
|
partitionEpochToScaleToSums,
|
|
12216
|
+
pickValidSatisfiableOrders,
|
|
12044
12217
|
processSpRequest,
|
|
12218
|
+
psmOrderType,
|
|
12045
12219
|
randomRobsSubsetSatisfyingTargetCollateral,
|
|
12046
12220
|
rationalAdd,
|
|
12047
12221
|
rationalCeil,
|
|
@@ -12115,6 +12289,7 @@ export {
|
|
|
12115
12289
|
startPriceOracleTx,
|
|
12116
12290
|
submitTx,
|
|
12117
12291
|
sum,
|
|
12292
|
+
summariseOrder,
|
|
12118
12293
|
summarizeActualLeverageRedemptions,
|
|
12119
12294
|
toAssetClassFromLucid,
|
|
12120
12295
|
toDataDerivedPythPrice,
|