@indigo-labs/indigo-sdk 0.3.28 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +7 -0
- package/.github/workflows/ci.yml +0 -1
- package/README.md +16 -0
- package/dist/index.d.mts +33 -3
- package/dist/index.d.ts +33 -3
- package/dist/index.js +610 -364
- package/dist/index.mjs +445 -196
- package/package.json +14 -22
- package/scripts/bench.sh +0 -0
- package/src/contracts/cdp-creator/queries.ts +30 -0
- package/src/contracts/iasset/queries.ts +102 -0
- package/src/contracts/initialize/actions.ts +38 -15
- package/{tests/interest-collection/interest-collector-queries.ts → src/contracts/interest-collection/queries.ts} +28 -12
- package/src/contracts/pyth-feed/helpers.ts +24 -0
- package/{tests/treasury/treasury-queries.ts → src/contracts/treasury/queries.ts} +15 -24
- package/src/index.ts +6 -1
- package/tests/cdp/actions.ts +1 -1
- package/tests/cdp/cdp-queries.ts +3 -23
- package/tests/cdp/transactions-mutated.ts +3 -4
- package/tests/gov/gov.test.ts +18 -18
- package/tests/interest-collection/interest-collection.test.ts +17 -62
- package/tests/queries/iasset-queries.ts +1 -84
- package/tests/rob/rob.test.ts +52 -52
- package/tests/stableswap/stableswap.test.ts +1 -1
- package/tests/treasury/actions.ts +1 -1
- package/tests/treasury/treasury.test.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1598,7 +1598,7 @@ function partitionEpochToScaleToSums(spContent) {
|
|
|
1598
1598
|
}
|
|
1599
1599
|
|
|
1600
1600
|
// src/contracts/cdp/transactions.ts
|
|
1601
|
-
import { array as
|
|
1601
|
+
import { array as A8, function as F12, option as O9 } from "fp-ts";
|
|
1602
1602
|
|
|
1603
1603
|
// src/contracts/interest-collection/transactions.ts
|
|
1604
1604
|
import {
|
|
@@ -3688,6 +3688,19 @@ async function encodeSignedPythMessage(update, secretKey) {
|
|
|
3688
3688
|
|
|
3689
3689
|
// src/contracts/pyth-feed/helpers.ts
|
|
3690
3690
|
import { fromHex as fromHex5 } from "@lucid-evolution/lucid";
|
|
3691
|
+
import { array as A7, function as F11 } from "fp-ts";
|
|
3692
|
+
function collectPriceFeedIds(derivedPythPrice) {
|
|
3693
|
+
const ids = match10(derivedPythPrice).with({ Value: P10.select() }, (value) => [
|
|
3694
|
+
BigInt(value.configuration.priceFeedId)
|
|
3695
|
+
]).with(
|
|
3696
|
+
{ Inverse: P10.select() },
|
|
3697
|
+
(inverse) => collectPriceFeedIds(fromDataDerivedPythPrice(inverse.value))
|
|
3698
|
+
).with({ Divide: P10.select() }, (divide) => [
|
|
3699
|
+
...collectPriceFeedIds(fromDataDerivedPythPrice(divide.x)),
|
|
3700
|
+
...collectPriceFeedIds(fromDataDerivedPythPrice(divide.y))
|
|
3701
|
+
]).exhaustive();
|
|
3702
|
+
return F11.pipe(ids, A7.uniq(BigIntOrd), A7.sort(BigIntOrd));
|
|
3703
|
+
}
|
|
3691
3704
|
function derivePythPrice(derivedPythPrice, messageHex) {
|
|
3692
3705
|
const decodedMessage = decodePythMessage(fromHex5(messageHex));
|
|
3693
3706
|
const pricePayload = decodePriceUpdate(decodedMessage.payload);
|
|
@@ -4511,7 +4524,7 @@ async function redeemCdp(attemptedRedemptionIAssetAmt, cdpOref, iassetOref, coll
|
|
|
4511
4524
|
const validateTo = validateFrom + Number(sysParams.cdpCreatorParams.biasTime);
|
|
4512
4525
|
tx.validFrom(validateFrom).validTo(validateTo);
|
|
4513
4526
|
}
|
|
4514
|
-
const partialRedemptionFee =
|
|
4527
|
+
const partialRedemptionFee = F12.pipe(
|
|
4515
4528
|
govDatum.protocolParams.cdpRedemptionRequiredSignature,
|
|
4516
4529
|
O9.fromNullable,
|
|
4517
4530
|
O9.match(
|
|
@@ -4907,17 +4920,17 @@ async function mergeCdps(cdpsToMergeUtxos, sysParams, lucid) {
|
|
|
4907
4920
|
if (cdpUtxos.length !== cdpsToMergeUtxos.length) {
|
|
4908
4921
|
throw new Error("Expected certain number of CDPs");
|
|
4909
4922
|
}
|
|
4910
|
-
const aggregatedVal =
|
|
4923
|
+
const aggregatedVal = F12.pipe(
|
|
4911
4924
|
cdpUtxos,
|
|
4912
|
-
|
|
4925
|
+
A8.reduce({}, (acc, utxo) => addAssets6(acc, utxo.assets))
|
|
4913
4926
|
);
|
|
4914
|
-
const aggregatedMintedAmt =
|
|
4927
|
+
const aggregatedMintedAmt = F12.pipe(
|
|
4915
4928
|
cdpDatums,
|
|
4916
|
-
|
|
4929
|
+
A8.reduce(0n, (acc, cdpDat) => acc + cdpDat.mintedAmt)
|
|
4917
4930
|
);
|
|
4918
|
-
const { aggregatedInterest, aggregatedCollateralTreasury } =
|
|
4931
|
+
const { aggregatedInterest, aggregatedCollateralTreasury } = F12.pipe(
|
|
4919
4932
|
cdpDatums,
|
|
4920
|
-
|
|
4933
|
+
A8.reduce(
|
|
4921
4934
|
{ aggregatedCollateralTreasury: 0n, aggregatedInterest: 0n },
|
|
4922
4935
|
(acc, cdpDat) => match13(cdpDat.cdpFees).returnType().with({ FrozenCDPAccumulatedFees: P13.select() }, (fees) => ({
|
|
4923
4936
|
aggregatedCollateralTreasury: acc.aggregatedCollateralTreasury + fees.collateralTreasury,
|
|
@@ -4926,7 +4939,7 @@ async function mergeCdps(cdpsToMergeUtxos, sysParams, lucid) {
|
|
|
4926
4939
|
)
|
|
4927
4940
|
);
|
|
4928
4941
|
const [[mainMergeUtxo, mainCdpDatum], otherMergeUtxos] = match13(
|
|
4929
|
-
|
|
4942
|
+
A8.zip(cdpUtxos, cdpDatums)
|
|
4930
4943
|
).returnType().with([P13._, ...P13.array()], ([main, ...other]) => [
|
|
4931
4944
|
main,
|
|
4932
4945
|
other.map((a) => a[0])
|
|
@@ -5138,6 +5151,30 @@ var mkCDPCreatorValidatorFromSP = (params) => {
|
|
|
5138
5151
|
};
|
|
5139
5152
|
};
|
|
5140
5153
|
|
|
5154
|
+
// src/contracts/cdp-creator/queries.ts
|
|
5155
|
+
import {
|
|
5156
|
+
assetClassToUnit,
|
|
5157
|
+
getRandomElement
|
|
5158
|
+
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
5159
|
+
import { option as O10, function as F13 } from "fp-ts";
|
|
5160
|
+
async function findRandomCdpCreator(lucid, sysParams) {
|
|
5161
|
+
const cdpCreatorUtxos = await lucid.utxosAtWithUnit(
|
|
5162
|
+
createScriptAddress(
|
|
5163
|
+
lucid.config().network,
|
|
5164
|
+
sysParams.validatorHashes.cdpCreatorHash
|
|
5165
|
+
),
|
|
5166
|
+
assetClassToUnit(
|
|
5167
|
+
fromSystemParamsAsset(sysParams.cdpCreatorParams.cdpCreatorNft)
|
|
5168
|
+
)
|
|
5169
|
+
);
|
|
5170
|
+
return F13.pipe(
|
|
5171
|
+
O10.fromNullable(getRandomElement(cdpCreatorUtxos)),
|
|
5172
|
+
O10.match(() => {
|
|
5173
|
+
throw new Error("Expected some cdp creator UTXOs.");
|
|
5174
|
+
}, F13.identity)
|
|
5175
|
+
);
|
|
5176
|
+
}
|
|
5177
|
+
|
|
5141
5178
|
// src/contracts/poll/scripts.ts
|
|
5142
5179
|
import { applyParamsToScript as applyParamsToScript4 } from "@lucid-evolution/lucid";
|
|
5143
5180
|
|
|
@@ -5295,12 +5332,12 @@ import {
|
|
|
5295
5332
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
5296
5333
|
import { Data as Data30 } from "@lucid-evolution/lucid";
|
|
5297
5334
|
import { pipe as pipe2 } from "fp-ts/lib/function";
|
|
5298
|
-
import { array as
|
|
5335
|
+
import { array as A9, option as O13, function as F16 } from "fp-ts";
|
|
5299
5336
|
import { match as match16, P as P16 } from "ts-pattern";
|
|
5300
5337
|
|
|
5301
5338
|
// src/contracts/staking/types-new.ts
|
|
5302
5339
|
import { TSchema as TSchema16, Data as Data27 } from "@evolution-sdk/evolution";
|
|
5303
|
-
import { option as
|
|
5340
|
+
import { option as O11, function as F14 } from "fp-ts";
|
|
5304
5341
|
import { match as match14, P as P14 } from "ts-pattern";
|
|
5305
5342
|
var StakingPosLockedAmtSchema = TSchema16.Array(
|
|
5306
5343
|
TSchema16.Tuple([
|
|
@@ -5360,22 +5397,22 @@ function serialiseStakingRedeemer(r) {
|
|
|
5360
5397
|
}
|
|
5361
5398
|
function parseStakingRedeemer(datum) {
|
|
5362
5399
|
try {
|
|
5363
|
-
return
|
|
5400
|
+
return O11.some(
|
|
5364
5401
|
Data27.withSchema(
|
|
5365
5402
|
StakingRedeemerSchema,
|
|
5366
5403
|
DEFAULT_SCHEMA_OPTIONS
|
|
5367
5404
|
).fromCBORHex(datum)
|
|
5368
5405
|
);
|
|
5369
5406
|
} catch (_) {
|
|
5370
|
-
return
|
|
5407
|
+
return O11.none;
|
|
5371
5408
|
}
|
|
5372
5409
|
}
|
|
5373
5410
|
function parseStakingRedeemerOrThrow(datum) {
|
|
5374
|
-
return
|
|
5411
|
+
return F14.pipe(
|
|
5375
5412
|
parseStakingRedeemer(datum),
|
|
5376
|
-
|
|
5413
|
+
O11.match(() => {
|
|
5377
5414
|
throw new Error("Expected a StakingRedeemer datum.");
|
|
5378
|
-
},
|
|
5415
|
+
}, F14.identity)
|
|
5379
5416
|
);
|
|
5380
5417
|
}
|
|
5381
5418
|
function parseStakingPosition(datum) {
|
|
@@ -5384,17 +5421,17 @@ function parseStakingPosition(datum) {
|
|
|
5384
5421
|
Data27.withSchema(StakingDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
5385
5422
|
datum
|
|
5386
5423
|
)
|
|
5387
|
-
).with({ owner: P14.any }, (res) =>
|
|
5424
|
+
).with({ owner: P14.any }, (res) => O11.some(res)).otherwise(() => O11.none);
|
|
5388
5425
|
} catch (_) {
|
|
5389
|
-
return
|
|
5426
|
+
return O11.none;
|
|
5390
5427
|
}
|
|
5391
5428
|
}
|
|
5392
5429
|
function parseStakingPositionOrThrow(datum) {
|
|
5393
|
-
return
|
|
5430
|
+
return F14.pipe(
|
|
5394
5431
|
parseStakingPosition(datum),
|
|
5395
|
-
|
|
5432
|
+
O11.match(() => {
|
|
5396
5433
|
throw new Error("Expected a StakingPosition datum.");
|
|
5397
|
-
},
|
|
5434
|
+
}, F14.identity)
|
|
5398
5435
|
);
|
|
5399
5436
|
}
|
|
5400
5437
|
function parseStakingManagerDatum(datum) {
|
|
@@ -5576,7 +5613,7 @@ import {
|
|
|
5576
5613
|
AddressSchema as AddressSchema3,
|
|
5577
5614
|
OutputReferenceSchema as OutputReferenceSchema5
|
|
5578
5615
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
5579
|
-
import { option as
|
|
5616
|
+
import { option as O12, function as F15 } from "fp-ts";
|
|
5580
5617
|
import { match as match15, P as P15 } from "ts-pattern";
|
|
5581
5618
|
var PollStatusSchema = TSchema18.Struct({
|
|
5582
5619
|
yesVotes: TSchema18.Integer,
|
|
@@ -5668,22 +5705,22 @@ function serialisePollShardRedeemer(r) {
|
|
|
5668
5705
|
}
|
|
5669
5706
|
function parsePollShardRedeemer(datum) {
|
|
5670
5707
|
try {
|
|
5671
|
-
return
|
|
5708
|
+
return O12.some(
|
|
5672
5709
|
Data29.withSchema(
|
|
5673
5710
|
PollShardRedeemerSchema,
|
|
5674
5711
|
DEFAULT_SCHEMA_OPTIONS
|
|
5675
5712
|
).fromCBORHex(datum)
|
|
5676
5713
|
);
|
|
5677
5714
|
} catch (_) {
|
|
5678
|
-
return
|
|
5715
|
+
return O12.none;
|
|
5679
5716
|
}
|
|
5680
5717
|
}
|
|
5681
5718
|
function parsePollShardRedeemerOrThrow(datum) {
|
|
5682
|
-
return
|
|
5719
|
+
return F15.pipe(
|
|
5683
5720
|
parsePollShardRedeemer(datum),
|
|
5684
|
-
|
|
5721
|
+
O12.match(() => {
|
|
5685
5722
|
throw new Error("Expected a poll shard redeemer.");
|
|
5686
|
-
},
|
|
5723
|
+
}, F15.identity)
|
|
5687
5724
|
);
|
|
5688
5725
|
}
|
|
5689
5726
|
function parsePollManager(datum) {
|
|
@@ -5692,17 +5729,17 @@ function parsePollManager(datum) {
|
|
|
5692
5729
|
Data29.withSchema(PollDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
5693
5730
|
datum
|
|
5694
5731
|
)
|
|
5695
|
-
).with({ PollManager: P15.select() }, (res) =>
|
|
5732
|
+
).with({ PollManager: P15.select() }, (res) => O12.some(res)).otherwise(() => O12.none);
|
|
5696
5733
|
} catch (_) {
|
|
5697
|
-
return
|
|
5734
|
+
return O12.none;
|
|
5698
5735
|
}
|
|
5699
5736
|
}
|
|
5700
5737
|
function parsePollManagerOrThrow(datum) {
|
|
5701
|
-
return
|
|
5738
|
+
return F15.pipe(
|
|
5702
5739
|
parsePollManager(datum),
|
|
5703
|
-
|
|
5740
|
+
O12.match(() => {
|
|
5704
5741
|
throw new Error("Expected a poll manager datum.");
|
|
5705
|
-
},
|
|
5742
|
+
}, F15.identity)
|
|
5706
5743
|
);
|
|
5707
5744
|
}
|
|
5708
5745
|
function parsePollShard(datum) {
|
|
@@ -5711,17 +5748,17 @@ function parsePollShard(datum) {
|
|
|
5711
5748
|
Data29.withSchema(PollDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
5712
5749
|
datum
|
|
5713
5750
|
)
|
|
5714
|
-
).with({ PollShard: P15.select() }, (res) =>
|
|
5751
|
+
).with({ PollShard: P15.select() }, (res) => O12.some(res)).otherwise(() => O12.none);
|
|
5715
5752
|
} catch (_) {
|
|
5716
|
-
return
|
|
5753
|
+
return O12.none;
|
|
5717
5754
|
}
|
|
5718
5755
|
}
|
|
5719
5756
|
function parsePollShardOrThrow(datum) {
|
|
5720
|
-
return
|
|
5757
|
+
return F15.pipe(
|
|
5721
5758
|
parsePollShard(datum),
|
|
5722
|
-
|
|
5759
|
+
O12.match(() => {
|
|
5723
5760
|
throw new Error("Expected a poll shard datum.");
|
|
5724
|
-
},
|
|
5761
|
+
}, F15.identity)
|
|
5725
5762
|
);
|
|
5726
5763
|
}
|
|
5727
5764
|
function serialisePollDatum(d) {
|
|
@@ -5779,7 +5816,7 @@ async function createProposal(proposalContent, treasuryWithdrawal, sysParams, lu
|
|
|
5779
5816
|
);
|
|
5780
5817
|
pipe2(
|
|
5781
5818
|
relativeIAsset,
|
|
5782
|
-
|
|
5819
|
+
O13.match(
|
|
5783
5820
|
() => {
|
|
5784
5821
|
if (govDatum.iassetsCount !== 0n) {
|
|
5785
5822
|
throw new Error(
|
|
@@ -6055,10 +6092,10 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
6055
6092
|
getInlineDatumOrThrow(pollManagerUtxo)
|
|
6056
6093
|
);
|
|
6057
6094
|
const shardUtxos = await lucid.utxosByOutRef(shardsOutRefs);
|
|
6058
|
-
const aggregatedStatus =
|
|
6095
|
+
const aggregatedStatus = F16.pipe(
|
|
6059
6096
|
shardUtxos,
|
|
6060
|
-
|
|
6061
|
-
|
|
6097
|
+
A9.map((utxo) => parsePollShardOrThrow(getInlineDatumOrThrow(utxo))),
|
|
6098
|
+
A9.reduce(
|
|
6062
6099
|
pollManagerDatum.status,
|
|
6063
6100
|
(acc, shard) => ({
|
|
6064
6101
|
yesVotes: acc.yesVotes + shard.status.yesVotes,
|
|
@@ -6066,7 +6103,7 @@ async function mergeShards(pollManagerOref, shardsOutRefs, sysParams, lucid, cur
|
|
|
6066
6103
|
})
|
|
6067
6104
|
)
|
|
6068
6105
|
);
|
|
6069
|
-
const shardsAggregatedAda =
|
|
6106
|
+
const shardsAggregatedAda = A9.reduce(
|
|
6070
6107
|
{},
|
|
6071
6108
|
(acc, utxo) => addAssets8(acc, mkLovelacesOf3(lovelacesAmt(utxo.assets)))
|
|
6072
6109
|
)(shardUtxos);
|
|
@@ -6262,8 +6299,8 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6262
6299
|
);
|
|
6263
6300
|
const tx = lucid.newTx();
|
|
6264
6301
|
await pipe2(
|
|
6265
|
-
|
|
6266
|
-
|
|
6302
|
+
O13.fromNullable(executeDatum.treasuryWithdrawal),
|
|
6303
|
+
O13.match(
|
|
6267
6304
|
() => {
|
|
6268
6305
|
if (treasuryWithdrawalOref) {
|
|
6269
6306
|
throw new Error("Cannot provide withdrawal oref when no withdrawal.");
|
|
@@ -6361,9 +6398,9 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6361
6398
|
);
|
|
6362
6399
|
const { newIAsset, newReferencedIAsset } = iassetCreationDatumHelper(
|
|
6363
6400
|
proposeContent,
|
|
6364
|
-
|
|
6401
|
+
F16.pipe(
|
|
6365
6402
|
iassetToReference,
|
|
6366
|
-
|
|
6403
|
+
O13.map((i) => i.datum)
|
|
6367
6404
|
)
|
|
6368
6405
|
);
|
|
6369
6406
|
const iassetAuthVal = mkAssetsOf6(
|
|
@@ -6416,14 +6453,14 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6416
6453
|
},
|
|
6417
6454
|
spAuthVal
|
|
6418
6455
|
);
|
|
6419
|
-
|
|
6456
|
+
F16.pipe(
|
|
6420
6457
|
iassetToReference,
|
|
6421
|
-
|
|
6458
|
+
O13.match(
|
|
6422
6459
|
() => {
|
|
6423
6460
|
},
|
|
6424
|
-
(i) =>
|
|
6461
|
+
(i) => F16.pipe(
|
|
6425
6462
|
newReferencedIAsset,
|
|
6426
|
-
|
|
6463
|
+
O13.match(
|
|
6427
6464
|
() => {
|
|
6428
6465
|
throw new Error("Expected some referenced iasset.");
|
|
6429
6466
|
},
|
|
@@ -6541,9 +6578,9 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6541
6578
|
);
|
|
6542
6579
|
const { newCollateralAsset, newReferencedCollateralAsset } = collateralAssetCreationDatumHelper(
|
|
6543
6580
|
addCollateralContent,
|
|
6544
|
-
|
|
6581
|
+
F16.pipe(
|
|
6545
6582
|
collateralAssetToReference,
|
|
6546
|
-
|
|
6583
|
+
O13.map((i) => i.datum)
|
|
6547
6584
|
)
|
|
6548
6585
|
);
|
|
6549
6586
|
const collateralAssetAuthVal = mkAssetsOf6(
|
|
@@ -6588,15 +6625,15 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6588
6625
|
},
|
|
6589
6626
|
collateralAssetAuthVal
|
|
6590
6627
|
);
|
|
6591
|
-
|
|
6628
|
+
F16.pipe(
|
|
6592
6629
|
collateralAssetToReference,
|
|
6593
|
-
|
|
6630
|
+
O13.match(
|
|
6594
6631
|
() => {
|
|
6595
6632
|
},
|
|
6596
6633
|
(i) => {
|
|
6597
|
-
|
|
6634
|
+
F16.pipe(
|
|
6598
6635
|
newReferencedCollateralAsset,
|
|
6599
|
-
|
|
6636
|
+
O13.match(
|
|
6600
6637
|
() => {
|
|
6601
6638
|
throw new Error("Expected some referenced collateral asset");
|
|
6602
6639
|
},
|
|
@@ -6629,14 +6666,14 @@ async function executeProposal(executeOref, govOref, treasuryWithdrawalOref, all
|
|
|
6629
6666
|
)
|
|
6630
6667
|
);
|
|
6631
6668
|
if (!isSameAssetClass2(newCollateralAsset.collateralAsset, adaAssetClass3)) {
|
|
6632
|
-
|
|
6669
|
+
F16.pipe(
|
|
6633
6670
|
newReferencedCollateralAsset,
|
|
6634
|
-
|
|
6671
|
+
O13.match(
|
|
6635
6672
|
() => {
|
|
6636
6673
|
},
|
|
6637
|
-
(referencedAsset) => referencedAsset.firstCollateralAsset ? {} :
|
|
6674
|
+
(referencedAsset) => referencedAsset.firstCollateralAsset ? {} : F16.pipe(
|
|
6638
6675
|
firstCollateralAsset,
|
|
6639
|
-
|
|
6676
|
+
O13.match(
|
|
6640
6677
|
() => {
|
|
6641
6678
|
},
|
|
6642
6679
|
(firstAsset) => {
|
|
@@ -8014,10 +8051,10 @@ function mkInterestOracleValidator(params) {
|
|
|
8014
8051
|
|
|
8015
8052
|
// tests/queries/interest-oracle-queries.ts
|
|
8016
8053
|
import {
|
|
8017
|
-
assetClassToUnit
|
|
8054
|
+
assetClassToUnit as assetClassToUnit2
|
|
8018
8055
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
8019
8056
|
async function findInterestOracle(lucid, interestNft) {
|
|
8020
|
-
return lucid.utxoByUnit(
|
|
8057
|
+
return lucid.utxoByUnit(assetClassToUnit2(interestNft));
|
|
8021
8058
|
}
|
|
8022
8059
|
|
|
8023
8060
|
// src/contracts/interest-oracle/transactions.ts
|
|
@@ -8189,6 +8226,55 @@ var mkInterestCollectionValidatorFromSP = (params) => {
|
|
|
8189
8226
|
};
|
|
8190
8227
|
};
|
|
8191
8228
|
|
|
8229
|
+
// src/contracts/interest-collection/queries.ts
|
|
8230
|
+
import { option as O14, function as F17 } from "fp-ts";
|
|
8231
|
+
import {
|
|
8232
|
+
assetClassToUnit as assetClassToUnit3,
|
|
8233
|
+
assetClassValueOf as assetClassValueOf7,
|
|
8234
|
+
getRandomElement as getRandomElement2,
|
|
8235
|
+
matchSingle as matchSingle4
|
|
8236
|
+
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
8237
|
+
async function findAllInterestCollectors(lucid, sysParams) {
|
|
8238
|
+
return lucid.utxosAt(
|
|
8239
|
+
createScriptAddress(
|
|
8240
|
+
lucid.config().network,
|
|
8241
|
+
sysParams.validatorHashes.interestCollectionHash
|
|
8242
|
+
)
|
|
8243
|
+
);
|
|
8244
|
+
}
|
|
8245
|
+
async function findAdminInterestCollectors(lucid, sysParams) {
|
|
8246
|
+
return matchSingle4(
|
|
8247
|
+
await lucid.utxosAtWithUnit(
|
|
8248
|
+
createScriptAddress(
|
|
8249
|
+
lucid.config().network,
|
|
8250
|
+
sysParams.validatorHashes.interestCollectionHash
|
|
8251
|
+
),
|
|
8252
|
+
assetClassToUnit3(
|
|
8253
|
+
fromSystemParamsAsset(
|
|
8254
|
+
sysParams.interestCollectionParams.multisigUtxoNft
|
|
8255
|
+
)
|
|
8256
|
+
)
|
|
8257
|
+
),
|
|
8258
|
+
(_) => new Error("Expected a single admin interest collector UTXO")
|
|
8259
|
+
);
|
|
8260
|
+
}
|
|
8261
|
+
async function findRandomNonAdminInterestCollector(lucid, sysParams) {
|
|
8262
|
+
const allCollectors = (await findAllInterestCollectors(lucid, sysParams)).filter(
|
|
8263
|
+
(utxo) => !assetClassValueOf7(
|
|
8264
|
+
utxo.assets,
|
|
8265
|
+
fromSystemParamsAsset(
|
|
8266
|
+
sysParams.interestCollectionParams.multisigUtxoNft
|
|
8267
|
+
)
|
|
8268
|
+
)
|
|
8269
|
+
);
|
|
8270
|
+
return F17.pipe(
|
|
8271
|
+
O14.fromNullable(getRandomElement2(allCollectors)),
|
|
8272
|
+
O14.match(() => {
|
|
8273
|
+
throw new Error("Expected some non-admin interest collector UTXOs.");
|
|
8274
|
+
}, F17.identity)
|
|
8275
|
+
);
|
|
8276
|
+
}
|
|
8277
|
+
|
|
8192
8278
|
// src/contracts/version-registry/types.ts
|
|
8193
8279
|
import { Data as Data39 } from "@lucid-evolution/lucid";
|
|
8194
8280
|
var VersionRecordTokenParamsSchema = Data39.Object({
|
|
@@ -8234,45 +8320,8 @@ var mkVersionRegistryValidator = () => {
|
|
|
8234
8320
|
};
|
|
8235
8321
|
};
|
|
8236
8322
|
|
|
8237
|
-
// src/contracts/collector/scripts.ts
|
|
8238
|
-
import {
|
|
8239
|
-
applyParamsToScript as applyParamsToScript11,
|
|
8240
|
-
Constr as Constr2,
|
|
8241
|
-
fromText as fromText8
|
|
8242
|
-
} from "@lucid-evolution/lucid";
|
|
8243
|
-
|
|
8244
|
-
// src/validators/collector-validator.ts
|
|
8245
|
-
var _collectorValidator = {
|
|
8246
|
-
type: "PlutusScriptV3",
|
|
8247
|
-
description: "Generated by Aiken",
|
|
8248
|
-
cborHex: "590a2a590a27010100229800aba2aba1aba0aab9faab9eaab9dab9cab9a488888888cc896600264653001300b00198059806000cdc3a4005300b0024888966002600460166ea800e33001300c3754007370e90024dc3a4001300b375400891111919912cc004c0140122b3001301337540170028b20288acc004c0240122b3001301337540170028b20288acc004c0180122b3001301337540170028b20288b202040408080660024602a602c0032259800800c52f5c11330153012301600133002002301700140512301530163016001911919800800801912cc004006297ae0899912cc004c01400a2660320046600800800313300400400140506030002603200280b24446466446600400400244b3001001801c4c8c96600266e440180062b30013371e00c0031375a60320050054059133004004301d00340586eb8c05c004c068005018191919800800803112cc004006007132325980099b910080018acc004cdc7804000c4dd5980d001401501744cc010010c07800d0171bae3018001301b0014064297adef6c6014800260206ea802644b30010018800c54cc04400840050104dd2a400091111111194c0048c00800644602530010029bae301f301c3754003375c601660386ea8005007488c8cc00400400c8966002003168992cc004cdd79811180f9baa00100489807180f9baa001899801801981180120383021001407c9112cc004c03c01e2646464b300100180dc4c966002604a00513259800800c07a2b30013026001899805a49364d7573742070726f6475636520636f6c6c6563746f72206f7574707574207769746820696e63726561736564204144412076616c75650098009b914881009b8f4881009bac300f3022375402f3374a90011981218051981200219812260103d87a80004bd7025eb812222332232330010010052259800800c528456600264b300130040018acc004cdd7980c18159baa0014c107d87b9fd87980ff008acc004cc8a600264b30013020302d37540031375a605c60626eacc0c4c0b8dd5000c5200040ac60600033756005375e606060620032259800981298171baa4c0103d87a8000899b890010028acc004cdc480080144cdc480119b80001482026fb80a294102c20584888966002007159800980100344cc00401120008a5040b91325980099baf4c101400030310018acc004cc008014dd69819181a9bab3032001898019ba630360048a5040bd15980099801002a4001130030078a5040bc8178c0d000d0320dd3002994c0040066eacc06cc0b0dd5001488cc0c0008cc0c0dd3000a5eb810011112cc00400a26600298103d87a80004bd6f7b63044c8cc8966002601e005159800980700144cc010c064cc0ccc0c400d2f5c00031330044c0103d87a800000540b9198008034006446600c0046606a00a002803102e1bae302e0013033003303100240bd13375e605c605e605e605e60566ea800530103d87a80008a5040a114a0814229410281816800c528c4cc008008c0b800502720563259800a508800c4c8c8cc00400400c896600200313302c337609801014000374c00697adef6c6089919912cc004c02c00a2b3001300a0028992cc004cdd7a6101a000374c003100289981819bb04c01014000374c0020048158c8cc004004dd59817002112cc00400626606266ec130010140004c010101004bd6f7b63044c8cc89660026020005159800980780144c96600266e1c0052001880144cc0d4cdd8261014000375066e00005200200240c06eb4c0c800e26606866ec13010140004c0101010000440bd1330340033300500500140bc6eb8c0bc004c0d0008c0c800503044cc0bccdd82601014000374c00c008815226605e0066600a00a0028150dd7181500098178011816800a056330293376098010140004c010101004bd6f7b63020483756602a604c6ea8025660026030604a6ea8006246466ebcc0acc0a0dd5181598141baa002001302a3027375400512323375e605660506ea8008004c0a8c09cdd500120464079023204630073756602060426ea8c040c084dd5000c0710221811800a0423300b37586044603e6ea80508cdd7981198101baa302330203754601e60406ea8004008c084c078dd51810980f1baa0013300137586040603a6ea80480362b3001301300789919803a49334d757374207370656e64207374616b696e67206d616e61676572207769746820446973747269627574652072656465656d657200332259800800c00a2b3001302400189919912cc004c05400626464b300130290028024590261bae302700130233754007159800980c800c56600260466ea800e005164091159800980b000c56600260466ea800e00516409115980099b874801800626464b300130290028024590261bad30270013023375400715980099b87480200062b3001302337540070028b20488acc004cdc3a401400315980098119baa003801459024456600266e1d200c0018acc004c08cdd5001c00a2c81222c8101020204040808101020204013375e00298103d87b8000302037540026464660020026eacc094c098c098c098c098c098c098c098c098c098c088dd500b91192cc004cdd78021811800c4c09000626600600660500048108c098004cdd2a400466044604660406ea8c08c0052f5c100240848108528198051bac3021301e37540264660086eacc038c07cdd51807180f9baa0010023020301d37540471332259800980a980f1baa001899912cc004c094006264b30013014302137540031323322598009814800c4c8cc004004dd61814801112cc004006264b3001301a30273754003132324a2b3001323300100130103756605a605c605c605c605c60546ea807c896600266e3cdd71817000801c528c4cc008008c0bc00502845268b204c375c605660506ea80062c8128c8cc004004dd6180b98141baa0072259800800c5300103d87a80008992cc006600266ebc00530103d87a8000a50a51409d10018998018019817001204e325980099b8f375c605a002017130123302c302d302e0014bd7045300103d87a8000409c6eb0c0b000502a44c8c8cc8966002605e007133006006302f0058b2058375c60580026eb8c0b0008c0b0004dd61815000a0508b204c375a604c002604e00260446ea80062c80f8c966002602a60426ea80062604a60446ea80062c80f8c038c084dd5180818109baa30240018b2044375c6044603e6ea8004c8cc030dd6180798101baa01523002301030213754002b30013011301e375498103d879800089198029bab300f30203754002007123371090004c004dd5980798101baa0019bae302330203754007375c601e60406ea800d00b20388b2038300a301d37540466040603a6ea8c080c074dd5198009bac3020301d375402401a80d101a0c01c01c6028602a00a60260088b2012180580098031baa00b8a4d13656400c2a660049201353c65787065637465643e20436f6c6c6563746f7220696e7075742063616e6e6f742068617665206e6f6e2d41444120617373657473001615330024912c3c65787065637465643e204d757374207370656e642073696e676c6520636f6c6c6563746f7220696e707574001601"
|
|
8249
|
-
};
|
|
8250
|
-
|
|
8251
|
-
// src/contracts/collector/scripts.ts
|
|
8252
|
-
var mkCollectorValidatorFromSP = (params) => {
|
|
8253
|
-
return {
|
|
8254
|
-
type: "PlutusV3",
|
|
8255
|
-
script: applyParamsToScript11(_collectorValidator.cborHex, [
|
|
8256
|
-
new Constr2(0, [
|
|
8257
|
-
new Constr2(0, [
|
|
8258
|
-
params.stakingManagerNFT[0].unCurrencySymbol,
|
|
8259
|
-
fromText8(params.stakingManagerNFT[1].unTokenName)
|
|
8260
|
-
]),
|
|
8261
|
-
new Constr2(0, [
|
|
8262
|
-
params.stakingToken[0].unCurrencySymbol,
|
|
8263
|
-
fromText8(params.stakingToken[1].unTokenName)
|
|
8264
|
-
]),
|
|
8265
|
-
new Constr2(0, [
|
|
8266
|
-
params.versionRecordToken[0].unCurrencySymbol,
|
|
8267
|
-
fromText8(params.versionRecordToken[1].unTokenName)
|
|
8268
|
-
])
|
|
8269
|
-
])
|
|
8270
|
-
])
|
|
8271
|
-
};
|
|
8272
|
-
};
|
|
8273
|
-
|
|
8274
8323
|
// src/contracts/treasury/scripts.ts
|
|
8275
|
-
import { applyParamsToScript as
|
|
8324
|
+
import { applyParamsToScript as applyParamsToScript11 } from "@lucid-evolution/lucid";
|
|
8276
8325
|
|
|
8277
8326
|
// src/validators/treasury-validator.ts
|
|
8278
8327
|
var _treasuryValidator = {
|
|
@@ -8297,7 +8346,7 @@ function castTreasuryParams(params) {
|
|
|
8297
8346
|
var mkTreasuryValidatorFromSP = (params) => {
|
|
8298
8347
|
return {
|
|
8299
8348
|
type: "PlutusV3",
|
|
8300
|
-
script:
|
|
8349
|
+
script: applyParamsToScript11(_treasuryValidator.cborHex, [
|
|
8301
8350
|
castTreasuryParams({
|
|
8302
8351
|
upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
|
|
8303
8352
|
versionRecordToken: fromSystemParamsAssetLucid(
|
|
@@ -8309,6 +8358,103 @@ var mkTreasuryValidatorFromSP = (params) => {
|
|
|
8309
8358
|
};
|
|
8310
8359
|
};
|
|
8311
8360
|
|
|
8361
|
+
// src/contracts/treasury/queries.ts
|
|
8362
|
+
import { option as O15, function as F18 } from "fp-ts";
|
|
8363
|
+
import {
|
|
8364
|
+
assetClassToUnit as assetClassToUnit4,
|
|
8365
|
+
assetClassValueOf as assetClassValueOf8,
|
|
8366
|
+
getRandomElement as getRandomElement3
|
|
8367
|
+
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
8368
|
+
async function findAllTreasuryUtxos(lucid, sysParams) {
|
|
8369
|
+
return lucid.utxosAt({
|
|
8370
|
+
type: "Script",
|
|
8371
|
+
hash: sysParams.validatorHashes.treasuryHash
|
|
8372
|
+
});
|
|
8373
|
+
}
|
|
8374
|
+
async function findRandomTreasuryUtxo(lucid, sysParams) {
|
|
8375
|
+
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
8376
|
+
return F18.pipe(
|
|
8377
|
+
O15.fromNullable(getRandomElement3(treasuryUtxos)),
|
|
8378
|
+
O15.match(() => {
|
|
8379
|
+
throw new Error("Expected some treasury UTXOs.");
|
|
8380
|
+
}, F18.identity)
|
|
8381
|
+
);
|
|
8382
|
+
}
|
|
8383
|
+
async function findRandomTreasuryUtxoWithOnlyAda(lucid, sysParams) {
|
|
8384
|
+
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
8385
|
+
const adaOnlyTreasuryUtxos = treasuryUtxos.filter(
|
|
8386
|
+
(utxo) => Object.keys(utxo.assets).length == 1
|
|
8387
|
+
);
|
|
8388
|
+
return F18.pipe(
|
|
8389
|
+
O15.fromNullable(getRandomElement3(adaOnlyTreasuryUtxos)),
|
|
8390
|
+
O15.match(() => {
|
|
8391
|
+
throw new Error("Expected some treasury UTXOs.");
|
|
8392
|
+
}, F18.identity)
|
|
8393
|
+
);
|
|
8394
|
+
}
|
|
8395
|
+
async function findRandomTreasuryUtxoWithAsset(lucid, sysParams, asset, max_number_of_assets = 2n) {
|
|
8396
|
+
const treasuryUtxos = await lucid.utxosAtWithUnit(
|
|
8397
|
+
{ hash: sysParams.validatorHashes.treasuryHash, type: "Script" },
|
|
8398
|
+
assetClassToUnit4(asset)
|
|
8399
|
+
);
|
|
8400
|
+
const validTreasuryUtxos = treasuryUtxos.filter(
|
|
8401
|
+
(utxo) => Object.keys(utxo.assets).length <= max_number_of_assets
|
|
8402
|
+
);
|
|
8403
|
+
return F18.pipe(
|
|
8404
|
+
O15.fromNullable(getRandomElement3(validTreasuryUtxos)),
|
|
8405
|
+
O15.match(() => {
|
|
8406
|
+
throw new Error("Expected some treasury UTXOs.");
|
|
8407
|
+
}, F18.identity)
|
|
8408
|
+
);
|
|
8409
|
+
}
|
|
8410
|
+
async function findAllTreasuryUtxosWithNonAdaAsset(lucid, sysParams, includeDaoToken = true) {
|
|
8411
|
+
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
8412
|
+
const treasuryUtxosWithNonAdaAsset = treasuryUtxos.filter(
|
|
8413
|
+
(utxo) => Object.keys(utxo.assets).length !== 1 && (includeDaoToken ? true : assetClassValueOf8(
|
|
8414
|
+
utxo.assets,
|
|
8415
|
+
fromSystemParamsAsset(sysParams.govParams.daoIdentityToken)
|
|
8416
|
+
) === 0n)
|
|
8417
|
+
);
|
|
8418
|
+
return treasuryUtxosWithNonAdaAsset;
|
|
8419
|
+
}
|
|
8420
|
+
|
|
8421
|
+
// src/contracts/collector/scripts.ts
|
|
8422
|
+
import {
|
|
8423
|
+
applyParamsToScript as applyParamsToScript12,
|
|
8424
|
+
Constr as Constr2,
|
|
8425
|
+
fromText as fromText8
|
|
8426
|
+
} from "@lucid-evolution/lucid";
|
|
8427
|
+
|
|
8428
|
+
// src/validators/collector-validator.ts
|
|
8429
|
+
var _collectorValidator = {
|
|
8430
|
+
type: "PlutusScriptV3",
|
|
8431
|
+
description: "Generated by Aiken",
|
|
8432
|
+
cborHex: "590a2a590a27010100229800aba2aba1aba0aab9faab9eaab9dab9cab9a488888888cc896600264653001300b00198059806000cdc3a4005300b0024888966002600460166ea800e33001300c3754007370e90024dc3a4001300b375400891111919912cc004c0140122b3001301337540170028b20288acc004c0240122b3001301337540170028b20288acc004c0180122b3001301337540170028b20288b202040408080660024602a602c0032259800800c52f5c11330153012301600133002002301700140512301530163016001911919800800801912cc004006297ae0899912cc004c01400a2660320046600800800313300400400140506030002603200280b24446466446600400400244b3001001801c4c8c96600266e440180062b30013371e00c0031375a60320050054059133004004301d00340586eb8c05c004c068005018191919800800803112cc004006007132325980099b910080018acc004cdc7804000c4dd5980d001401501744cc010010c07800d0171bae3018001301b0014064297adef6c6014800260206ea802644b30010018800c54cc04400840050104dd2a400091111111194c0048c00800644602530010029bae301f301c3754003375c601660386ea8005007488c8cc00400400c8966002003168992cc004cdd79811180f9baa00100489807180f9baa001899801801981180120383021001407c9112cc004c03c01e2646464b300100180dc4c966002604a00513259800800c07a2b30013026001899805a49364d7573742070726f6475636520636f6c6c6563746f72206f7574707574207769746820696e63726561736564204144412076616c75650098009b914881009b8f4881009bac300f3022375402f3374a90011981218051981200219812260103d87a80004bd7025eb812222332232330010010052259800800c528456600264b300130040018acc004cdd7980c18159baa0014c107d87b9fd87980ff008acc004cc8a600264b30013020302d37540031375a605c60626eacc0c4c0b8dd5000c5200040ac60600033756005375e606060620032259800981298171baa4c0103d87a8000899b890010028acc004cdc480080144cdc480119b80001482026fb80a294102c20584888966002007159800980100344cc00401120008a5040b91325980099baf4c101400030310018acc004cc008014dd69819181a9bab3032001898019ba630360048a5040bd15980099801002a4001130030078a5040bc8178c0d000d0320dd3002994c0040066eacc06cc0b0dd5001488cc0c0008cc0c0dd3000a5eb810011112cc00400a26600298103d87a80004bd6f7b63044c8cc8966002601e005159800980700144cc010c064cc0ccc0c400d2f5c00031330044c0103d87a800000540b9198008034006446600c0046606a00a002803102e1bae302e0013033003303100240bd13375e605c605e605e605e60566ea800530103d87a80008a5040a114a0814229410281816800c528c4cc008008c0b800502720563259800a508800c4c8c8cc00400400c896600200313302c337609801014000374c00697adef6c6089919912cc004c02c00a2b3001300a0028992cc004cdd7a6101a000374c003100289981819bb04c01014000374c0020048158c8cc004004dd59817002112cc00400626606266ec130010140004c010101004bd6f7b63044c8cc89660026020005159800980780144c96600266e1c0052001880144cc0d4cdd8261014000375066e00005200200240c06eb4c0c800e26606866ec13010140004c0101010000440bd1330340033300500500140bc6eb8c0bc004c0d0008c0c800503044cc0bccdd82601014000374c00c008815226605e0066600a00a0028150dd7181500098178011816800a056330293376098010140004c010101004bd6f7b63020483756602a604c6ea8025660026030604a6ea8006246466ebcc0acc0a0dd5181598141baa002001302a3027375400512323375e605660506ea8008004c0a8c09cdd500120464079023204630073756602060426ea8c040c084dd5000c0710221811800a0423300b37586044603e6ea80508cdd7981198101baa302330203754601e60406ea8004008c084c078dd51810980f1baa0013300137586040603a6ea80480362b3001301300789919803a49334d757374207370656e64207374616b696e67206d616e61676572207769746820446973747269627574652072656465656d657200332259800800c00a2b3001302400189919912cc004c05400626464b300130290028024590261bae302700130233754007159800980c800c56600260466ea800e005164091159800980b000c56600260466ea800e00516409115980099b874801800626464b300130290028024590261bad30270013023375400715980099b87480200062b3001302337540070028b20488acc004cdc3a401400315980098119baa003801459024456600266e1d200c0018acc004c08cdd5001c00a2c81222c8101020204040808101020204013375e00298103d87b8000302037540026464660020026eacc094c098c098c098c098c098c098c098c098c098c088dd500b91192cc004cdd78021811800c4c09000626600600660500048108c098004cdd2a400466044604660406ea8c08c0052f5c100240848108528198051bac3021301e37540264660086eacc038c07cdd51807180f9baa0010023020301d37540471332259800980a980f1baa001899912cc004c094006264b30013014302137540031323322598009814800c4c8cc004004dd61814801112cc004006264b3001301a30273754003132324a2b3001323300100130103756605a605c605c605c605c60546ea807c896600266e3cdd71817000801c528c4cc008008c0bc00502845268b204c375c605660506ea80062c8128c8cc004004dd6180b98141baa0072259800800c5300103d87a80008992cc006600266ebc00530103d87a8000a50a51409d10018998018019817001204e325980099b8f375c605a002017130123302c302d302e0014bd7045300103d87a8000409c6eb0c0b000502a44c8c8cc8966002605e007133006006302f0058b2058375c60580026eb8c0b0008c0b0004dd61815000a0508b204c375a604c002604e00260446ea80062c80f8c966002602a60426ea80062604a60446ea80062c80f8c038c084dd5180818109baa30240018b2044375c6044603e6ea8004c8cc030dd6180798101baa01523002301030213754002b30013011301e375498103d879800089198029bab300f30203754002007123371090004c004dd5980798101baa0019bae302330203754007375c601e60406ea800d00b20388b2038300a301d37540466040603a6ea8c080c074dd5198009bac3020301d375402401a80d101a0c01c01c6028602a00a60260088b2012180580098031baa00b8a4d13656400c2a660049201353c65787065637465643e20436f6c6c6563746f7220696e7075742063616e6e6f742068617665206e6f6e2d41444120617373657473001615330024912c3c65787065637465643e204d757374207370656e642073696e676c6520636f6c6c6563746f7220696e707574001601"
|
|
8433
|
+
};
|
|
8434
|
+
|
|
8435
|
+
// src/contracts/collector/scripts.ts
|
|
8436
|
+
var mkCollectorValidatorFromSP = (params) => {
|
|
8437
|
+
return {
|
|
8438
|
+
type: "PlutusV3",
|
|
8439
|
+
script: applyParamsToScript12(_collectorValidator.cborHex, [
|
|
8440
|
+
new Constr2(0, [
|
|
8441
|
+
new Constr2(0, [
|
|
8442
|
+
params.stakingManagerNFT[0].unCurrencySymbol,
|
|
8443
|
+
fromText8(params.stakingManagerNFT[1].unTokenName)
|
|
8444
|
+
]),
|
|
8445
|
+
new Constr2(0, [
|
|
8446
|
+
params.stakingToken[0].unCurrencySymbol,
|
|
8447
|
+
fromText8(params.stakingToken[1].unTokenName)
|
|
8448
|
+
]),
|
|
8449
|
+
new Constr2(0, [
|
|
8450
|
+
params.versionRecordToken[0].unCurrencySymbol,
|
|
8451
|
+
fromText8(params.versionRecordToken[1].unTokenName)
|
|
8452
|
+
])
|
|
8453
|
+
])
|
|
8454
|
+
])
|
|
8455
|
+
};
|
|
8456
|
+
};
|
|
8457
|
+
|
|
8312
8458
|
// src/contracts/execute/types.ts
|
|
8313
8459
|
import { Data as Data41 } from "@lucid-evolution/lucid";
|
|
8314
8460
|
var ExecuteParamsSchema = Data41.Object({
|
|
@@ -8413,7 +8559,7 @@ import {
|
|
|
8413
8559
|
AssetClassSchema as AssetClassSchema7,
|
|
8414
8560
|
OutputReferenceSchema as OutputReferenceSchema6
|
|
8415
8561
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
8416
|
-
import { option as
|
|
8562
|
+
import { option as O16, function as F19 } from "fp-ts";
|
|
8417
8563
|
var RobOrderTypeSchema = TSchema19.Union(
|
|
8418
8564
|
TSchema19.Struct(
|
|
8419
8565
|
{
|
|
@@ -8469,21 +8615,21 @@ var RobRedeemerSchema = TSchema19.Union(
|
|
|
8469
8615
|
);
|
|
8470
8616
|
function parseRobDatum(datum) {
|
|
8471
8617
|
try {
|
|
8472
|
-
return
|
|
8618
|
+
return O16.some(
|
|
8473
8619
|
Data43.withSchema(RobDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
8474
8620
|
datum
|
|
8475
8621
|
)
|
|
8476
8622
|
);
|
|
8477
8623
|
} catch (_) {
|
|
8478
|
-
return
|
|
8624
|
+
return O16.none;
|
|
8479
8625
|
}
|
|
8480
8626
|
}
|
|
8481
8627
|
function parseRobDatumOrThrow(datum) {
|
|
8482
|
-
return
|
|
8628
|
+
return F19.pipe(
|
|
8483
8629
|
parseRobDatum(datum),
|
|
8484
|
-
|
|
8630
|
+
O16.match(() => {
|
|
8485
8631
|
throw new Error("Expected an ROB datum.");
|
|
8486
|
-
},
|
|
8632
|
+
}, F19.identity)
|
|
8487
8633
|
);
|
|
8488
8634
|
}
|
|
8489
8635
|
function serialiseRobDatum(d) {
|
|
@@ -8496,36 +8642,36 @@ function serialiseRobRedeemer(r) {
|
|
|
8496
8642
|
}
|
|
8497
8643
|
function parseRobRedeemer(redeemerCborHex) {
|
|
8498
8644
|
try {
|
|
8499
|
-
return
|
|
8645
|
+
return O16.some(
|
|
8500
8646
|
Data43.withSchema(RobRedeemerSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
8501
8647
|
redeemerCborHex
|
|
8502
8648
|
)
|
|
8503
8649
|
);
|
|
8504
8650
|
} catch (_) {
|
|
8505
|
-
return
|
|
8651
|
+
return O16.none;
|
|
8506
8652
|
}
|
|
8507
8653
|
}
|
|
8508
8654
|
function parseRobRedeemerOrThrow(redeemerCborHex) {
|
|
8509
|
-
return
|
|
8655
|
+
return F19.pipe(
|
|
8510
8656
|
parseRobRedeemer(redeemerCborHex),
|
|
8511
|
-
|
|
8657
|
+
O16.match(() => {
|
|
8512
8658
|
throw new Error("Expected an ROB redeemer.");
|
|
8513
|
-
},
|
|
8659
|
+
}, F19.identity)
|
|
8514
8660
|
);
|
|
8515
8661
|
}
|
|
8516
8662
|
|
|
8517
8663
|
// src/contracts/rob/helpers.ts
|
|
8518
8664
|
import {
|
|
8519
8665
|
readonlyArray as RA3,
|
|
8520
|
-
array as
|
|
8521
|
-
function as
|
|
8522
|
-
option as
|
|
8666
|
+
array as A10,
|
|
8667
|
+
function as F20,
|
|
8668
|
+
option as O17,
|
|
8523
8669
|
ord as Ord4
|
|
8524
8670
|
} from "fp-ts";
|
|
8525
8671
|
import { match as match18, P as P18 } from "ts-pattern";
|
|
8526
8672
|
import {
|
|
8527
8673
|
adaAssetClass as adaAssetClass5,
|
|
8528
|
-
assetClassValueOf as
|
|
8674
|
+
assetClassValueOf as assetClassValueOf9,
|
|
8529
8675
|
isSameAssetClass as isSameAssetClass3,
|
|
8530
8676
|
lovelacesAmt as lovelacesAmt3,
|
|
8531
8677
|
mkAssetsOf as mkAssetsOf9
|
|
@@ -8578,7 +8724,7 @@ function robCollateralAmtToSpend(robAssets, robOrderType) {
|
|
|
8578
8724
|
if (isSameAssetClass3(adaAssetClass5, content.collateralAsset)) {
|
|
8579
8725
|
return zeroNegatives(lovelacesAmt3(robAssets) - MIN_ROB_COLLATERAL_AMT);
|
|
8580
8726
|
} else {
|
|
8581
|
-
return
|
|
8727
|
+
return assetClassValueOf9(robAssets, content.collateralAsset);
|
|
8582
8728
|
}
|
|
8583
8729
|
}).otherwise(() => {
|
|
8584
8730
|
throw new Error("Collateral to spend is relevant only for Buy orders.");
|
|
@@ -8586,7 +8732,7 @@ function robCollateralAmtToSpend(robAssets, robOrderType) {
|
|
|
8586
8732
|
}
|
|
8587
8733
|
function robIAssetAmtToSpend(robAssets, robOrderType, robIasset) {
|
|
8588
8734
|
return match18(robOrderType).returnType().with({ SellIAssetOrder: P18.any }, (_) => {
|
|
8589
|
-
return
|
|
8735
|
+
return assetClassValueOf9(robAssets, robIasset);
|
|
8590
8736
|
}).otherwise(() => {
|
|
8591
8737
|
throw new Error("IAssets to spend is relevant only for Sell orders.");
|
|
8592
8738
|
});
|
|
@@ -8604,7 +8750,7 @@ function robBuyOrderFilledAssets(robAssets, robOrderType, robIasset) {
|
|
|
8604
8750
|
return match18(robOrderType).returnType().with({ BuyIAssetOrder: P18.any }, () => {
|
|
8605
8751
|
return {
|
|
8606
8752
|
asset: robIasset,
|
|
8607
|
-
filledAmt:
|
|
8753
|
+
filledAmt: assetClassValueOf9(robAssets, robIasset)
|
|
8608
8754
|
};
|
|
8609
8755
|
}).otherwise(() => {
|
|
8610
8756
|
throw new Error("Expected only buy order.");
|
|
@@ -8615,7 +8761,7 @@ function robSellOrderFilledAssets(robAssets, robOrderType) {
|
|
|
8615
8761
|
return content.allowedCollateralAssets.map(([asset, _]) => {
|
|
8616
8762
|
return {
|
|
8617
8763
|
asset,
|
|
8618
|
-
filledAmt:
|
|
8764
|
+
filledAmt: assetClassValueOf9(robAssets, asset) - (isSameAssetClass3(asset, adaAssetClass5) ? MIN_ROB_COLLATERAL_AMT : 0n)
|
|
8619
8765
|
};
|
|
8620
8766
|
});
|
|
8621
8767
|
}).otherwise(() => {
|
|
@@ -8652,9 +8798,9 @@ function isFullyRedeemed(robAssets, robOrderType, robIasset) {
|
|
|
8652
8798
|
}).exhaustive();
|
|
8653
8799
|
}
|
|
8654
8800
|
function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redemptionReimbursementRatio, sysParams, tx, txOutputsBeforeCount, collateralAssetRefInputIdx, iassetRefInputIdx, oracleIdx) {
|
|
8655
|
-
return
|
|
8801
|
+
return F20.pipe(
|
|
8656
8802
|
redemptions,
|
|
8657
|
-
|
|
8803
|
+
A10.reduceWithIndex(
|
|
8658
8804
|
tx,
|
|
8659
8805
|
(idx, acc, [robUtxo, payoutAmt]) => {
|
|
8660
8806
|
const robDatum = parseRobDatumOrThrow(getInlineDatumOrThrow(robUtxo));
|
|
@@ -8688,12 +8834,12 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8688
8834
|
);
|
|
8689
8835
|
return [resultVal, 0n];
|
|
8690
8836
|
}).with({ SellIAssetOrder: P18.select() }, (content) => {
|
|
8691
|
-
const allowedAssetIdx =
|
|
8837
|
+
const allowedAssetIdx = F20.pipe(
|
|
8692
8838
|
content.allowedCollateralAssets,
|
|
8693
8839
|
RA3.findIndex(
|
|
8694
8840
|
([asset, _]) => isSameAssetClass3(asset, collateralAsset)
|
|
8695
8841
|
),
|
|
8696
|
-
|
|
8842
|
+
O17.getOrElse(() => {
|
|
8697
8843
|
throw new Error("Doesn't allow required collateral asset.");
|
|
8698
8844
|
})
|
|
8699
8845
|
);
|
|
@@ -8754,26 +8900,26 @@ function buildRedemptionsTx(redemptions, iasset, collateralAsset, price, redempt
|
|
|
8754
8900
|
);
|
|
8755
8901
|
}
|
|
8756
8902
|
function calculateTotalCollateralForRedemption(iasset, collateralAsset, iassetPrice, allRobs, maxRobsInTx) {
|
|
8757
|
-
return
|
|
8903
|
+
return F20.pipe(
|
|
8758
8904
|
allRobs,
|
|
8759
|
-
|
|
8905
|
+
A10.filterMap(([utxo, datum]) => {
|
|
8760
8906
|
const isCorrectOrder = match18(datum.orderType).returnType().with(
|
|
8761
8907
|
{ BuyIAssetOrder: P18.select() },
|
|
8762
8908
|
(content) => isSameAssetClass3(content.collateralAsset, collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice) && !isBuyOrderFullyRedeemed(utxo.assets, datum.orderType, iassetPrice)
|
|
8763
8909
|
).otherwise(() => false);
|
|
8764
8910
|
if (toHex12(datum.iasset) !== toHex12(iasset) || !isCorrectOrder) {
|
|
8765
|
-
return
|
|
8911
|
+
return O17.none;
|
|
8766
8912
|
}
|
|
8767
8913
|
const collateralToSpend = robCollateralAmtToSpend(
|
|
8768
8914
|
utxo.assets,
|
|
8769
8915
|
datum.orderType
|
|
8770
8916
|
);
|
|
8771
|
-
return
|
|
8917
|
+
return O17.some(collateralToSpend);
|
|
8772
8918
|
}),
|
|
8773
8919
|
// From largest to smallest
|
|
8774
|
-
|
|
8920
|
+
A10.sort(Ord4.reverse(BigIntOrd)),
|
|
8775
8921
|
// We can fit only this number of redemptions with CDP open into a single Tx.
|
|
8776
|
-
|
|
8922
|
+
A10.takeLeft(maxRobsInTx),
|
|
8777
8923
|
sum
|
|
8778
8924
|
);
|
|
8779
8925
|
}
|
|
@@ -8782,9 +8928,9 @@ function randomRobsSubsetSatisfyingTargetCollateral(iasset, collateralAsset, tar
|
|
|
8782
8928
|
throw new Error("Must redeem and payout more than 0.");
|
|
8783
8929
|
}
|
|
8784
8930
|
const shuffled = randomiseFn(
|
|
8785
|
-
|
|
8931
|
+
F20.pipe(
|
|
8786
8932
|
allLrps,
|
|
8787
|
-
|
|
8933
|
+
A10.filter(
|
|
8788
8934
|
([utxo, datum]) => toHex12(datum.iasset) === toHex12(iasset) && match18(datum.orderType).with(
|
|
8789
8935
|
{ BuyIAssetOrder: P18.select() },
|
|
8790
8936
|
(content) => isSameAssetClass3(collateralAsset, content.collateralAsset) && rationalToFloat(content.maxPrice) >= rationalToFloat(iassetPrice)
|
|
@@ -8870,14 +9016,14 @@ import {
|
|
|
8870
9016
|
} from "@lucid-evolution/lucid";
|
|
8871
9017
|
import {
|
|
8872
9018
|
readonlyArray as RA4,
|
|
8873
|
-
array as
|
|
8874
|
-
function as
|
|
8875
|
-
option as
|
|
9019
|
+
array as A11,
|
|
9020
|
+
function as F21,
|
|
9021
|
+
option as O18
|
|
8876
9022
|
} from "fp-ts";
|
|
8877
9023
|
import { unzip, zip } from "fp-ts/lib/Array";
|
|
8878
9024
|
import {
|
|
8879
9025
|
adaAssetClass as adaAssetClass6,
|
|
8880
|
-
assetClassValueOf as
|
|
9026
|
+
assetClassValueOf as assetClassValueOf10,
|
|
8881
9027
|
isSameAssetClass as isSameAssetClass4,
|
|
8882
9028
|
mkAssetsOf as mkAssetsOf10,
|
|
8883
9029
|
mkLovelacesOf as mkLovelacesOf6,
|
|
@@ -9046,15 +9192,15 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
|
|
|
9046
9192
|
tokenName: robDatum.iasset
|
|
9047
9193
|
};
|
|
9048
9194
|
const [depositAsset, rewardVal] = match19(robDatum.orderType).returnType().with({ BuyIAssetOrder: P19.select() }, (buyContent) => {
|
|
9049
|
-
const reward =
|
|
9195
|
+
const reward = assetClassValueOf10(robUtxo.assets, iassetAc);
|
|
9050
9196
|
return [buyContent.collateralAsset, mkAssetsOf10(iassetAc, reward)];
|
|
9051
9197
|
}).with({ SellIAssetOrder: P19.select() }, (content) => {
|
|
9052
|
-
const reward =
|
|
9198
|
+
const reward = F21.pipe(
|
|
9053
9199
|
content.allowedCollateralAssets,
|
|
9054
9200
|
RA4.reduce(
|
|
9055
9201
|
{},
|
|
9056
9202
|
(acc, [asset, _]) => {
|
|
9057
|
-
const amt =
|
|
9203
|
+
const amt = assetClassValueOf10(robUtxo.assets, asset) - // in case of ADA, the min has to stay.
|
|
9058
9204
|
(isSameAssetClass4(asset, adaAssetClass6) ? MIN_ROB_COLLATERAL_AMT : 0n);
|
|
9059
9205
|
return addAssets13(acc, mkAssetsOf10(asset, amt));
|
|
9060
9206
|
}
|
|
@@ -9089,12 +9235,12 @@ async function adjustRob(lucid, robOutRef, adjustmentAmt, newLimitPrice, sysPara
|
|
|
9089
9235
|
return {
|
|
9090
9236
|
SellIAssetOrder: {
|
|
9091
9237
|
allowedCollateralAssets: content.allowedCollateralAssets.map(
|
|
9092
|
-
(entry) =>
|
|
9238
|
+
(entry) => F21.pipe(
|
|
9093
9239
|
newPrices,
|
|
9094
|
-
|
|
9240
|
+
A11.findFirst(
|
|
9095
9241
|
(newPrice) => isSameAssetClass4(newPrice[0], entry[0])
|
|
9096
9242
|
),
|
|
9097
|
-
|
|
9243
|
+
O18.match(
|
|
9098
9244
|
() => entry,
|
|
9099
9245
|
(newPrice) => [
|
|
9100
9246
|
entry[0],
|
|
@@ -9165,7 +9311,7 @@ import {
|
|
|
9165
9311
|
} from "@lucid-evolution/lucid";
|
|
9166
9312
|
|
|
9167
9313
|
// src/contracts/rob-leverage/helpers.ts
|
|
9168
|
-
import { array as
|
|
9314
|
+
import { array as A12, function as F22 } from "fp-ts";
|
|
9169
9315
|
import { Decimal as Decimal2 } from "decimal.js";
|
|
9170
9316
|
var MAX_REDEMPTIONS_WITH_CDP_OPEN = 4;
|
|
9171
9317
|
function approximateLeverageRedemptions(baseCollateral, targetLeverage, redemptionReimbursementRatio, debtMintingFeeRatio) {
|
|
@@ -9191,9 +9337,9 @@ function approximateLeverageRedemptions(baseCollateral, targetLeverage, redempti
|
|
|
9191
9337
|
};
|
|
9192
9338
|
}
|
|
9193
9339
|
function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursement, redemptionReimbursementRatio, iassetPrice, redemptionLrps) {
|
|
9194
|
-
const redemptionDetails =
|
|
9340
|
+
const redemptionDetails = F22.pipe(
|
|
9195
9341
|
redemptionLrps,
|
|
9196
|
-
|
|
9342
|
+
A12.reduce(
|
|
9197
9343
|
{
|
|
9198
9344
|
remainingCollateralToSpend: lovelacesForRedemptionWithReimbursement,
|
|
9199
9345
|
redemptions: []
|
|
@@ -9247,9 +9393,9 @@ function summarizeActualLeverageRedemptions(lovelacesForRedemptionWithReimbursem
|
|
|
9247
9393
|
}
|
|
9248
9394
|
)
|
|
9249
9395
|
);
|
|
9250
|
-
const res =
|
|
9396
|
+
const res = F22.pipe(
|
|
9251
9397
|
redemptionDetails.redemptions,
|
|
9252
|
-
|
|
9398
|
+
A12.reduce(
|
|
9253
9399
|
{
|
|
9254
9400
|
redeemedCollateral: 0n,
|
|
9255
9401
|
payoutIAssets: 0n,
|
|
@@ -9720,8 +9866,8 @@ import {
|
|
|
9720
9866
|
validatorToScriptHash as validatorToScriptHash3
|
|
9721
9867
|
} from "@lucid-evolution/lucid";
|
|
9722
9868
|
import {
|
|
9723
|
-
assetClassToUnit as
|
|
9724
|
-
assetClassValueOf as
|
|
9869
|
+
assetClassToUnit as assetClassToUnit5,
|
|
9870
|
+
assetClassValueOf as assetClassValueOf11,
|
|
9725
9871
|
lovelacesAmt as lovelacesAmt4,
|
|
9726
9872
|
mkAssetsOf as mkAssetsOf13,
|
|
9727
9873
|
mkLovelacesOf as mkLovelacesOf7
|
|
@@ -9785,7 +9931,7 @@ var mkIAssetValidatorFromSP = (params) => {
|
|
|
9785
9931
|
import { match as match20 } from "ts-pattern";
|
|
9786
9932
|
|
|
9787
9933
|
// tests/test-helpers.ts
|
|
9788
|
-
import { array as
|
|
9934
|
+
import { array as A13, function as F23, option as O19 } from "fp-ts";
|
|
9789
9935
|
async function runAndAwaitTxBuilder(lucid, transaction, extraSigners = []) {
|
|
9790
9936
|
const bTx = await transaction.complete();
|
|
9791
9937
|
const signatures = [await bTx.partialSign.withWallet()];
|
|
@@ -10169,7 +10315,7 @@ async function mintAuthTokenDirect(lucid, asset, tokenName, amount) {
|
|
|
10169
10315
|
const script = mkAuthTokenPolicy(asset, fromText11(tokenName));
|
|
10170
10316
|
const policyId = mintingPolicyToId2(script);
|
|
10171
10317
|
const address = await lucid.wallet().address();
|
|
10172
|
-
const utxos = (await lucid.utxosAtWithUnit(address,
|
|
10318
|
+
const utxos = (await lucid.utxosAtWithUnit(address, assetClassToUnit5(asset))).filter((utxo2) => assetClassValueOf11(utxo2.assets, asset) === 1n).sort((a, b) => Number(lovelacesAmt4(b.assets) - lovelacesAmt4(a.assets)));
|
|
10173
10319
|
if (utxos.length === 0) {
|
|
10174
10320
|
throw new Error("No utxos found");
|
|
10175
10321
|
}
|
|
@@ -10401,15 +10547,24 @@ async function initPythConfig(lucid, initialAssets, pythStateAsset) {
|
|
|
10401
10547
|
lucid,
|
|
10402
10548
|
pythFeedValidator
|
|
10403
10549
|
);
|
|
10404
|
-
|
|
10405
|
-
|
|
10406
|
-
|
|
10407
|
-
|
|
10408
|
-
|
|
10409
|
-
|
|
10410
|
-
|
|
10411
|
-
|
|
10412
|
-
|
|
10550
|
+
try {
|
|
10551
|
+
await runAndAwaitTxBuilder(
|
|
10552
|
+
lucid,
|
|
10553
|
+
lucid.newTx().register.Stake(
|
|
10554
|
+
credentialToRewardAddress4(lucid.config().network, {
|
|
10555
|
+
hash: validatorToScriptHash5(pythFeedValidator),
|
|
10556
|
+
type: "Script"
|
|
10557
|
+
})
|
|
10558
|
+
)
|
|
10559
|
+
);
|
|
10560
|
+
} catch (error) {
|
|
10561
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
10562
|
+
if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes(
|
|
10563
|
+
"Trying to re-register some already known credentials."
|
|
10564
|
+
)) {
|
|
10565
|
+
throw error;
|
|
10566
|
+
}
|
|
10567
|
+
}
|
|
10413
10568
|
const key = `${asset.name}/${toHex16(collateral.collateralAsset.currencySymbol)}.${toHex16(collateral.collateralAsset.tokenName)}`;
|
|
10414
10569
|
return {
|
|
10415
10570
|
[key]: {
|
|
@@ -10599,7 +10754,17 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
10599
10754
|
lucid.config().network,
|
|
10600
10755
|
scriptHashToCredential4(cdpRedeemValHash)
|
|
10601
10756
|
);
|
|
10602
|
-
|
|
10757
|
+
try {
|
|
10758
|
+
await runAndAwaitTxBuilder(
|
|
10759
|
+
lucid,
|
|
10760
|
+
lucid.newTx().register.Stake(cdpRedeemRewardAddr)
|
|
10761
|
+
);
|
|
10762
|
+
} catch (error) {
|
|
10763
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
10764
|
+
if (!message.includes("StakeKeyRegisteredDELEG") && !message.includes("Trying to re-register some already known credentials.")) {
|
|
10765
|
+
throw error;
|
|
10766
|
+
}
|
|
10767
|
+
}
|
|
10603
10768
|
const cdpParams = {
|
|
10604
10769
|
cdpAuthToken: toSystemParamsAsset(cdpToken),
|
|
10605
10770
|
cdpAssetSymbol: { unCurrencySymbol: assetSymbol },
|
|
@@ -10783,7 +10948,7 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
10783
10948
|
lucid,
|
|
10784
10949
|
govParams,
|
|
10785
10950
|
govNftAsset,
|
|
10786
|
-
|
|
10951
|
+
initialAssets,
|
|
10787
10952
|
protocolParams
|
|
10788
10953
|
);
|
|
10789
10954
|
const robParams = {
|
|
@@ -10966,6 +11131,77 @@ async function init(lucid, defaultInitialAssets, currentSlot, mkPythBasedAssets
|
|
|
10966
11131
|
return [sysParams, assetInfos];
|
|
10967
11132
|
}
|
|
10968
11133
|
|
|
11134
|
+
// src/contracts/iasset/queries.ts
|
|
11135
|
+
import { toHex as toHex17 } from "@lucid-evolution/lucid";
|
|
11136
|
+
import {
|
|
11137
|
+
assetClassToUnit as assetClassToUnit6,
|
|
11138
|
+
isSameAssetClass as isSameAssetClass5,
|
|
11139
|
+
matchSingle as matchSingle5
|
|
11140
|
+
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
11141
|
+
import { option as O20, array as A14, function as F24 } from "fp-ts";
|
|
11142
|
+
async function findIAsset(lucid, sysParams, iassetName) {
|
|
11143
|
+
const iassetUtxos = await lucid.utxosAtWithUnit(
|
|
11144
|
+
createScriptAddress(
|
|
11145
|
+
lucid.config().network,
|
|
11146
|
+
sysParams.validatorHashes.iassetHash
|
|
11147
|
+
),
|
|
11148
|
+
assetClassToUnit6(
|
|
11149
|
+
fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken)
|
|
11150
|
+
)
|
|
11151
|
+
);
|
|
11152
|
+
return matchSingle5(
|
|
11153
|
+
F24.pipe(
|
|
11154
|
+
iassetUtxos.map(
|
|
11155
|
+
(utxo) => F24.pipe(
|
|
11156
|
+
O20.fromNullable(utxo.datum),
|
|
11157
|
+
O20.flatMap(parseIAssetDatum),
|
|
11158
|
+
O20.flatMap((datum) => {
|
|
11159
|
+
if (toHex17(datum.assetName) === toHex17(iassetName)) {
|
|
11160
|
+
return O20.some({ utxo, datum });
|
|
11161
|
+
} else {
|
|
11162
|
+
return O20.none;
|
|
11163
|
+
}
|
|
11164
|
+
})
|
|
11165
|
+
)
|
|
11166
|
+
),
|
|
11167
|
+
A14.compact
|
|
11168
|
+
),
|
|
11169
|
+
(res) => new Error("Expected a single IAsset UTXO.: " + JSON.stringify(res))
|
|
11170
|
+
);
|
|
11171
|
+
}
|
|
11172
|
+
async function findCollateralAsset(lucid, sysParams, iassetName, collateralAsset) {
|
|
11173
|
+
const collateralAssetUtxos = await lucid.utxosAtWithUnit(
|
|
11174
|
+
createScriptAddress(
|
|
11175
|
+
lucid.config().network,
|
|
11176
|
+
sysParams.validatorHashes.iassetHash
|
|
11177
|
+
),
|
|
11178
|
+
assetClassToUnit6(
|
|
11179
|
+
fromSystemParamsAsset(sysParams.cdpParams.collateralAssetAuthToken)
|
|
11180
|
+
)
|
|
11181
|
+
);
|
|
11182
|
+
return matchSingle5(
|
|
11183
|
+
F24.pipe(
|
|
11184
|
+
collateralAssetUtxos.map(
|
|
11185
|
+
(utxo) => F24.pipe(
|
|
11186
|
+
O20.fromNullable(utxo.datum),
|
|
11187
|
+
O20.flatMap(parseCollateralAssetDatum),
|
|
11188
|
+
O20.flatMap((datum) => {
|
|
11189
|
+
if (isSameAssetClass5(datum.collateralAsset, collateralAsset) && toHex17(iassetName) === toHex17(datum.iasset)) {
|
|
11190
|
+
return O20.some({ utxo, datum });
|
|
11191
|
+
} else {
|
|
11192
|
+
return O20.none;
|
|
11193
|
+
}
|
|
11194
|
+
})
|
|
11195
|
+
)
|
|
11196
|
+
),
|
|
11197
|
+
A14.compact
|
|
11198
|
+
),
|
|
11199
|
+
(res) => new Error(
|
|
11200
|
+
"Expected a single Collateral Asset UTXO.: " + JSON.stringify(res)
|
|
11201
|
+
)
|
|
11202
|
+
);
|
|
11203
|
+
}
|
|
11204
|
+
|
|
10969
11205
|
// src/contracts/stableswap/helpers.ts
|
|
10970
11206
|
import { fromHex as fromHex19, fromText as fromText14 } from "@lucid-evolution/lucid";
|
|
10971
11207
|
|
|
@@ -10976,7 +11212,7 @@ import {
|
|
|
10976
11212
|
OutputReferenceSchema as OutputReferenceSchema7
|
|
10977
11213
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
10978
11214
|
import { TSchema as TSchema20, Data as Data51 } from "@evolution-sdk/evolution";
|
|
10979
|
-
import { option as
|
|
11215
|
+
import { option as O21, function as F25 } from "fp-ts";
|
|
10980
11216
|
import { Schema as Schema4 } from "effect";
|
|
10981
11217
|
var OpaqueData4 = Schema4.typeSchema(Data51.DataSchema);
|
|
10982
11218
|
var StableswapOrderDatumSchema = TSchema20.Struct({
|
|
@@ -11018,22 +11254,22 @@ function serialiseStableswapOrderDatum(d) {
|
|
|
11018
11254
|
}
|
|
11019
11255
|
function parseStableswapOrderDatum(datum) {
|
|
11020
11256
|
try {
|
|
11021
|
-
return
|
|
11257
|
+
return O21.some(
|
|
11022
11258
|
Data51.withSchema(
|
|
11023
11259
|
StableswapOrderDatumSchema,
|
|
11024
11260
|
DEFAULT_SCHEMA_OPTIONS
|
|
11025
11261
|
).fromCBORHex(datum)
|
|
11026
11262
|
);
|
|
11027
11263
|
} catch (_) {
|
|
11028
|
-
return
|
|
11264
|
+
return O21.none;
|
|
11029
11265
|
}
|
|
11030
11266
|
}
|
|
11031
11267
|
function parseStableswapOrderDatumOrThrow(datum) {
|
|
11032
|
-
return
|
|
11268
|
+
return F25.pipe(
|
|
11033
11269
|
parseStableswapOrderDatum(datum),
|
|
11034
|
-
|
|
11270
|
+
O21.match(() => {
|
|
11035
11271
|
throw new Error("Expected a Stableswap Order datum.");
|
|
11036
|
-
},
|
|
11272
|
+
}, F25.identity)
|
|
11037
11273
|
);
|
|
11038
11274
|
}
|
|
11039
11275
|
function serialiseStableswapOutputDatum(d) {
|
|
@@ -11050,22 +11286,22 @@ function serialiseStableswapOrderRedeemer(r) {
|
|
|
11050
11286
|
}
|
|
11051
11287
|
function parseStableswapOrderRedeemer(redeemerCborHex) {
|
|
11052
11288
|
try {
|
|
11053
|
-
return
|
|
11289
|
+
return O21.some(
|
|
11054
11290
|
Data51.withSchema(
|
|
11055
11291
|
StableswapOrderRedeemerSchema,
|
|
11056
11292
|
DEFAULT_SCHEMA_OPTIONS
|
|
11057
11293
|
).fromCBORHex(redeemerCborHex)
|
|
11058
11294
|
);
|
|
11059
11295
|
} catch (_) {
|
|
11060
|
-
return
|
|
11296
|
+
return O21.none;
|
|
11061
11297
|
}
|
|
11062
11298
|
}
|
|
11063
11299
|
function parseStableswapOrderRedeemerOrThrow(redeemerCborHex) {
|
|
11064
|
-
return
|
|
11300
|
+
return F25.pipe(
|
|
11065
11301
|
parseStableswapOrderRedeemer(redeemerCborHex),
|
|
11066
|
-
|
|
11302
|
+
O21.match(() => {
|
|
11067
11303
|
throw new Error("Expected a Stableswap Order redeemer.");
|
|
11068
|
-
},
|
|
11304
|
+
}, F25.identity)
|
|
11069
11305
|
);
|
|
11070
11306
|
}
|
|
11071
11307
|
|
|
@@ -11094,20 +11330,20 @@ import {
|
|
|
11094
11330
|
fromText as fromText15,
|
|
11095
11331
|
paymentCredentialOf as paymentCredentialOf3,
|
|
11096
11332
|
sortUTxOs as sortUTxOs2,
|
|
11097
|
-
toHex as
|
|
11333
|
+
toHex as toHex18
|
|
11098
11334
|
} from "@lucid-evolution/lucid";
|
|
11099
11335
|
import {
|
|
11100
11336
|
addressFromBech32 as addressFromBech323,
|
|
11101
11337
|
addressToBech32 as addressToBech323,
|
|
11102
11338
|
getInlineDatumOrThrow as getInlineDatumOrThrow6,
|
|
11103
|
-
matchSingle as
|
|
11339
|
+
matchSingle as matchSingle6,
|
|
11104
11340
|
mkAssetsOf as mkAssetsOf16,
|
|
11105
11341
|
mkLovelacesOf as mkLovelacesOf9,
|
|
11106
11342
|
lovelacesAmt as lovelacesAmt5,
|
|
11107
11343
|
isSameOutRef as isSameOutRef2,
|
|
11108
|
-
assetClassValueOf as
|
|
11344
|
+
assetClassValueOf as assetClassValueOf12
|
|
11109
11345
|
} from "@3rd-eye-labs/cardano-offchain-common";
|
|
11110
|
-
import { array as
|
|
11346
|
+
import { array as A15, function as F26 } from "fp-ts";
|
|
11111
11347
|
import { isEmpty } from "fp-ts/lib/Array";
|
|
11112
11348
|
async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
|
|
11113
11349
|
const myAddress = await lucid.wallet().address();
|
|
@@ -11161,7 +11397,7 @@ async function createStableswapOrder(iasset, collateralAsset, amount, minting, p
|
|
|
11161
11397
|
);
|
|
11162
11398
|
}
|
|
11163
11399
|
async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
|
|
11164
|
-
const stableswapScriptRefUtxo =
|
|
11400
|
+
const stableswapScriptRefUtxo = matchSingle6(
|
|
11165
11401
|
await lucid.utxosByOutRef([
|
|
11166
11402
|
fromSystemParamsScriptRef(
|
|
11167
11403
|
sysParams.scriptReferences.stableswapValidatorRef
|
|
@@ -11169,7 +11405,7 @@ async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
|
|
|
11169
11405
|
]),
|
|
11170
11406
|
(_) => new Error("Expected a single Stableswap Ref Script UTXO")
|
|
11171
11407
|
);
|
|
11172
|
-
const stableswapOrderUtxo =
|
|
11408
|
+
const stableswapOrderUtxo = matchSingle6(
|
|
11173
11409
|
await lucid.utxosByOutRef([stableswapOrderOref]),
|
|
11174
11410
|
(_) => new Error("Expected a single Stableswap Order UTXO.")
|
|
11175
11411
|
);
|
|
@@ -11179,10 +11415,10 @@ async function cancelStableswapOrder(stableswapOrderOref, sysParams, lucid) {
|
|
|
11179
11415
|
return lucid.newTx().readFrom([stableswapScriptRefUtxo]).collectFrom(
|
|
11180
11416
|
[stableswapOrderUtxo],
|
|
11181
11417
|
serialiseStableswapOrderRedeemer("CancelStableswapOrder")
|
|
11182
|
-
).addSignerKey(
|
|
11418
|
+
).addSignerKey(toHex18(stableswapOrderDatum.owner));
|
|
11183
11419
|
}
|
|
11184
11420
|
async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPoolOref, treasuryOref, sysParams, lucid) {
|
|
11185
|
-
const stableswapScriptRefUtxo =
|
|
11421
|
+
const stableswapScriptRefUtxo = matchSingle6(
|
|
11186
11422
|
await lucid.utxosByOutRef([
|
|
11187
11423
|
fromSystemParamsScriptRef(
|
|
11188
11424
|
sysParams.scriptReferences.stableswapValidatorRef
|
|
@@ -11190,13 +11426,13 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11190
11426
|
]),
|
|
11191
11427
|
(_) => new Error("Expected a single Stableswap Ref Script UTXO")
|
|
11192
11428
|
);
|
|
11193
|
-
const cdpScriptRefUtxo =
|
|
11429
|
+
const cdpScriptRefUtxo = matchSingle6(
|
|
11194
11430
|
await lucid.utxosByOutRef([
|
|
11195
11431
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
11196
11432
|
]),
|
|
11197
11433
|
(_) => new Error("Expected a single CDP Ref Script UTXO")
|
|
11198
11434
|
);
|
|
11199
|
-
const iAssetTokenPolicyRefScriptUtxo =
|
|
11435
|
+
const iAssetTokenPolicyRefScriptUtxo = matchSingle6(
|
|
11200
11436
|
await lucid.utxosByOutRef([
|
|
11201
11437
|
fromSystemParamsScriptRef(
|
|
11202
11438
|
sysParams.scriptReferences.iAssetTokenPolicyRef
|
|
@@ -11226,7 +11462,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11226
11462
|
tokenName: mainOrderDatum.iasset
|
|
11227
11463
|
};
|
|
11228
11464
|
const collateralAc = mainOrderDatum.collateralAsset;
|
|
11229
|
-
const stableswapPoolUtxo =
|
|
11465
|
+
const stableswapPoolUtxo = matchSingle6(
|
|
11230
11466
|
await lucid.utxosByOutRef([stableswapPoolOref]),
|
|
11231
11467
|
(_) => new Error("Expected a single cdp UTXO")
|
|
11232
11468
|
);
|
|
@@ -11238,11 +11474,11 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11238
11474
|
const orderDatum = parseStableswapOrderDatumOrThrow(
|
|
11239
11475
|
getInlineDatumOrThrow6(orderUtxo)
|
|
11240
11476
|
);
|
|
11241
|
-
if (
|
|
11477
|
+
if (toHex18(orderDatum.iasset) != toHex18(mainOrderDatum.iasset) || toHex18(orderDatum.collateralAsset.currencySymbol) != toHex18(mainOrderDatum.collateralAsset.currencySymbol) || toHex18(orderDatum.collateralAsset.tokenName) != toHex18(mainOrderDatum.collateralAsset.tokenName)) {
|
|
11242
11478
|
throw new Error("Wrong batch of orders");
|
|
11243
11479
|
}
|
|
11244
|
-
const suppliedIasset =
|
|
11245
|
-
const suppliedCollateralAsset =
|
|
11480
|
+
const suppliedIasset = assetClassValueOf12(orderUtxo.assets, iassetAc);
|
|
11481
|
+
const suppliedCollateralAsset = assetClassValueOf12(
|
|
11246
11482
|
orderUtxo.assets,
|
|
11247
11483
|
collateralAc
|
|
11248
11484
|
);
|
|
@@ -11366,9 +11602,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11366
11602
|
}
|
|
11367
11603
|
}
|
|
11368
11604
|
);
|
|
11369
|
-
const totalSwapInfo =
|
|
11605
|
+
const totalSwapInfo = F26.pipe(
|
|
11370
11606
|
ordersInfo,
|
|
11371
|
-
|
|
11607
|
+
A15.reduce(
|
|
11372
11608
|
{
|
|
11373
11609
|
suppliedCollateralAsset: 0n,
|
|
11374
11610
|
suppliedIasset: 0n,
|
|
@@ -11418,9 +11654,9 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11418
11654
|
if (amountToMint !== 0n) {
|
|
11419
11655
|
tx.mintAssets(mkAssetsOf16(iassetAc, amountToMint), Data53.void());
|
|
11420
11656
|
}
|
|
11421
|
-
|
|
11657
|
+
F26.pipe(
|
|
11422
11658
|
ordersInfo,
|
|
11423
|
-
|
|
11659
|
+
A15.reduce(tx, (acc, orderInfo) => {
|
|
11424
11660
|
return acc.collectFrom(
|
|
11425
11661
|
[orderInfo.utxo],
|
|
11426
11662
|
isSameOutRef2(orderInfo.utxo, mainOrderUtxo) ? serialiseStableswapOrderRedeemer("BatchProcessStableswapOrders") : {
|
|
@@ -11473,7 +11709,7 @@ async function batchProcessStableswapOrders(stableswapOrderOrefs, stableswapPool
|
|
|
11473
11709
|
return tx;
|
|
11474
11710
|
}
|
|
11475
11711
|
async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRef, newMintingFeeRatio, newRedemptionFeeRatio, sysParams, lucid) {
|
|
11476
|
-
const stableswapScriptRefUtxo =
|
|
11712
|
+
const stableswapScriptRefUtxo = matchSingle6(
|
|
11477
11713
|
await lucid.utxosByOutRef([
|
|
11478
11714
|
fromSystemParamsScriptRef(
|
|
11479
11715
|
sysParams.scriptReferences.stableswapValidatorRef
|
|
@@ -11481,17 +11717,17 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
11481
11717
|
]),
|
|
11482
11718
|
(_) => new Error("Expected a single Stableswap Ref Script UTXO")
|
|
11483
11719
|
);
|
|
11484
|
-
const cdpScriptRefUtxo =
|
|
11720
|
+
const cdpScriptRefUtxo = matchSingle6(
|
|
11485
11721
|
await lucid.utxosByOutRef([
|
|
11486
11722
|
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef)
|
|
11487
11723
|
]),
|
|
11488
11724
|
(_) => new Error("Expected a single CDP Ref Script UTXO")
|
|
11489
11725
|
);
|
|
11490
|
-
const stableswapPool =
|
|
11726
|
+
const stableswapPool = matchSingle6(
|
|
11491
11727
|
await lucid.utxosByOutRef([stableswapPoolOutRef]),
|
|
11492
11728
|
(_) => new Error("Expected a single Stableswap Pool UTXO.")
|
|
11493
11729
|
);
|
|
11494
|
-
const stableswapFeeUtxo =
|
|
11730
|
+
const stableswapFeeUtxo = matchSingle6(
|
|
11495
11731
|
await lucid.utxosByOutRef([stableswapFeeOutRef]),
|
|
11496
11732
|
(_) => new Error("Expected a single Stableswap Fee UTXO.")
|
|
11497
11733
|
);
|
|
@@ -11524,7 +11760,7 @@ async function updateStableswapPoolFees(stableswapPoolOutRef, stableswapFeeOutRe
|
|
|
11524
11760
|
value: serialiseStableswapPoolDatum(newStableswapPoolDatum)
|
|
11525
11761
|
},
|
|
11526
11762
|
stableswapPool.assets
|
|
11527
|
-
).addSignerKey(
|
|
11763
|
+
).addSignerKey(toHex18(stableswapPoolDatum.feeManager)).setMinFee(1038402n);
|
|
11528
11764
|
}
|
|
11529
11765
|
export {
|
|
11530
11766
|
AccountContentSchema,
|
|
@@ -11633,6 +11869,7 @@ export {
|
|
|
11633
11869
|
closeCdp,
|
|
11634
11870
|
closeStakingPosition,
|
|
11635
11871
|
collectInterestTx,
|
|
11872
|
+
collectPriceFeedIds,
|
|
11636
11873
|
collectorFeeTx,
|
|
11637
11874
|
createDestinationDatum,
|
|
11638
11875
|
createE2s2sSnapshots,
|
|
@@ -11645,6 +11882,7 @@ export {
|
|
|
11645
11882
|
decodePythMessage,
|
|
11646
11883
|
depositCdp,
|
|
11647
11884
|
deriveAuthToken,
|
|
11885
|
+
derivePythPrice,
|
|
11648
11886
|
distributeAda,
|
|
11649
11887
|
distributeInterest,
|
|
11650
11888
|
distributeReward,
|
|
@@ -11657,6 +11895,17 @@ export {
|
|
|
11657
11895
|
executeProposal,
|
|
11658
11896
|
feedInterestOracle,
|
|
11659
11897
|
feedPriceOracleTx,
|
|
11898
|
+
findAdminInterestCollectors,
|
|
11899
|
+
findAllInterestCollectors,
|
|
11900
|
+
findAllTreasuryUtxos,
|
|
11901
|
+
findAllTreasuryUtxosWithNonAdaAsset,
|
|
11902
|
+
findCollateralAsset,
|
|
11903
|
+
findIAsset,
|
|
11904
|
+
findRandomCdpCreator,
|
|
11905
|
+
findRandomNonAdminInterestCollector,
|
|
11906
|
+
findRandomTreasuryUtxo,
|
|
11907
|
+
findRandomTreasuryUtxoWithAsset,
|
|
11908
|
+
findRandomTreasuryUtxoWithOnlyAda,
|
|
11660
11909
|
findRelevantE2s2sIdxs,
|
|
11661
11910
|
findStakingManager,
|
|
11662
11911
|
findStakingManagerByOutRef,
|