@lucid-evolution/provider 0.1.44 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +780 -656
- package/dist/index.d.cts +10 -53
- package/dist/index.d.ts +10 -53
- package/dist/index.js +773 -650
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
1
|
// src/core.ts
|
|
8
2
|
import * as CML from "@anastasia-labs/cardano-multiplatform-lib-nodejs";
|
|
9
3
|
|
|
10
|
-
// src/blockfrost
|
|
4
|
+
// src/blockfrost.ts
|
|
11
5
|
import { fromHex, sleep } from "@lucid-evolution/core-utils";
|
|
12
6
|
import { applyDoubleCborEncoding } from "@lucid-evolution/utils";
|
|
13
7
|
|
|
14
8
|
// package.json
|
|
15
9
|
var package_default = {
|
|
16
10
|
name: "@lucid-evolution/provider",
|
|
17
|
-
version: "0.1.
|
|
11
|
+
version: "0.1.46",
|
|
18
12
|
description: "",
|
|
19
13
|
main: "./dist/index.js",
|
|
20
14
|
types: "./dist/index.d.ts",
|
|
@@ -62,8 +56,48 @@ var package_default = {
|
|
|
62
56
|
}
|
|
63
57
|
};
|
|
64
58
|
|
|
65
|
-
// src/
|
|
59
|
+
// src/internal/blockfrost.ts
|
|
66
60
|
import { pipe, Record } from "effect";
|
|
61
|
+
var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
|
|
62
|
+
{
|
|
63
|
+
txId: utxo.txHash,
|
|
64
|
+
index: utxo.outputIndex
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
address: utxo.address,
|
|
68
|
+
value: {
|
|
69
|
+
coins: Number(utxo.assets["lovelace"]),
|
|
70
|
+
assets: fromAssets(utxo.assets)
|
|
71
|
+
},
|
|
72
|
+
datumHash: utxo.datumHash,
|
|
73
|
+
datum: utxo.datum,
|
|
74
|
+
script: toTxOutScript(utxo.scriptRef)
|
|
75
|
+
}
|
|
76
|
+
]);
|
|
77
|
+
var toTxOutScript = (scriptRef) => {
|
|
78
|
+
if (scriptRef) {
|
|
79
|
+
switch (scriptRef.type) {
|
|
80
|
+
case "PlutusV1":
|
|
81
|
+
return { "plutus:v1": scriptRef.script };
|
|
82
|
+
case "PlutusV2":
|
|
83
|
+
return { "plutus:v2": scriptRef.script };
|
|
84
|
+
case "PlutusV3":
|
|
85
|
+
return { "plutus:v3": scriptRef.script };
|
|
86
|
+
default:
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
var fromAssets = (assets) => pipe(
|
|
92
|
+
Record.remove(assets, "lovelace"),
|
|
93
|
+
Record.mapEntries((amount, unit) => [
|
|
94
|
+
unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
|
|
95
|
+
Number(amount)
|
|
96
|
+
]),
|
|
97
|
+
(r) => Record.isEmptyRecord(r) ? void 0 : r
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// src/blockfrost.ts
|
|
67
101
|
var Blockfrost = class {
|
|
68
102
|
url;
|
|
69
103
|
projectId;
|
|
@@ -289,6 +323,11 @@ var Blockfrost = class {
|
|
|
289
323
|
type: "PlutusV2",
|
|
290
324
|
script: applyDoubleCborEncoding(script)
|
|
291
325
|
};
|
|
326
|
+
case "plutusV3":
|
|
327
|
+
return {
|
|
328
|
+
type: "PlutusV3",
|
|
329
|
+
script: applyDoubleCborEncoding(script)
|
|
330
|
+
};
|
|
292
331
|
}
|
|
293
332
|
})() : void 0
|
|
294
333
|
};
|
|
@@ -336,42 +375,6 @@ var Blockfrost = class {
|
|
|
336
375
|
return evalRedeemers;
|
|
337
376
|
}
|
|
338
377
|
};
|
|
339
|
-
function datumJsonToCbor(json) {
|
|
340
|
-
const convert = (json2) => {
|
|
341
|
-
if (!isNaN(json2.int)) {
|
|
342
|
-
return CML.PlutusData.new_integer(
|
|
343
|
-
CML.BigInteger.from_str(json2.int.toString())
|
|
344
|
-
);
|
|
345
|
-
} else if (json2.bytes || !isNaN(Number(json2.bytes))) {
|
|
346
|
-
return CML.PlutusData.new_bytes(fromHex(json2.bytes));
|
|
347
|
-
} else if (json2.map) {
|
|
348
|
-
const m = CML.PlutusMap.new();
|
|
349
|
-
json2.map.forEach(({ k, v }) => {
|
|
350
|
-
m.set(convert(k), convert(v));
|
|
351
|
-
});
|
|
352
|
-
return CML.PlutusData.new_map(m);
|
|
353
|
-
} else if (json2.list) {
|
|
354
|
-
const l = CML.PlutusDataList.new();
|
|
355
|
-
json2.list.forEach((v) => {
|
|
356
|
-
l.add(convert(v));
|
|
357
|
-
});
|
|
358
|
-
return CML.PlutusData.new_list(l);
|
|
359
|
-
} else if (!isNaN(json2.constructor)) {
|
|
360
|
-
const l = CML.PlutusDataList.new();
|
|
361
|
-
json2.fields.forEach((v) => {
|
|
362
|
-
l.add(convert(v));
|
|
363
|
-
});
|
|
364
|
-
return CML.PlutusData.new_constr_plutus_data(
|
|
365
|
-
CML.ConstrPlutusData.new(
|
|
366
|
-
CML.BigInteger.from_str(json2.constructor.toString()).as_u64(),
|
|
367
|
-
l
|
|
368
|
-
)
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
throw new Error("Unsupported type");
|
|
372
|
-
};
|
|
373
|
-
return convert(json).to_cbor_hex();
|
|
374
|
-
}
|
|
375
378
|
var handleRateLimit = async (count) => {
|
|
376
379
|
if (count % 100 === 0) {
|
|
377
380
|
await sleep(5e3);
|
|
@@ -380,38 +383,21 @@ var handleRateLimit = async (count) => {
|
|
|
380
383
|
}
|
|
381
384
|
};
|
|
382
385
|
var lucid = package_default.version;
|
|
383
|
-
var toAditionalUTXOs = (utxos) => (utxos || []).map((utxo) => [
|
|
384
|
-
{
|
|
385
|
-
txId: utxo.txHash,
|
|
386
|
-
index: utxo.outputIndex
|
|
387
|
-
},
|
|
388
|
-
{
|
|
389
|
-
address: utxo.address,
|
|
390
|
-
value: {
|
|
391
|
-
coins: Number(utxo.assets["lovelace"]),
|
|
392
|
-
assets: fromAssets(utxo.assets)
|
|
393
|
-
},
|
|
394
|
-
datumHash: utxo.datumHash,
|
|
395
|
-
datum: utxo.datum,
|
|
396
|
-
script: utxo.scriptRef ? utxo.scriptRef.type === "PlutusV1" ? { "plutus:v1": utxo.scriptRef.script } : { "plutus:v2": utxo.scriptRef.script } : void 0
|
|
397
|
-
}
|
|
398
|
-
]);
|
|
399
|
-
var fromAssets = (assets) => pipe(
|
|
400
|
-
Record.remove(assets, "lovelace"),
|
|
401
|
-
Record.mapEntries((amount, unit) => [
|
|
402
|
-
unit.length === 56 ? unit.slice(0, 56) : unit.slice(0, 56) + "." + unit.slice(56),
|
|
403
|
-
Number(amount)
|
|
404
|
-
]),
|
|
405
|
-
(r) => Record.isEmptyRecord(r) ? void 0 : r
|
|
406
|
-
);
|
|
407
386
|
|
|
408
|
-
// src/kupmios
|
|
409
|
-
import { applyDoubleCborEncoding as applyDoubleCborEncoding2, fromUnit } from "@lucid-evolution/utils";
|
|
410
|
-
import * as
|
|
387
|
+
// src/kupmios.ts
|
|
388
|
+
import { applyDoubleCborEncoding as applyDoubleCborEncoding2, fromUnit as fromUnit2 } from "@lucid-evolution/utils";
|
|
389
|
+
import * as S3 from "@effect/schema/Schema";
|
|
411
390
|
import { Effect, pipe as pipe2, Array as _Array, Schedule, Data } from "effect";
|
|
391
|
+
import {
|
|
392
|
+
HttpClient,
|
|
393
|
+
HttpClientRequest,
|
|
394
|
+
HttpClientResponse
|
|
395
|
+
} from "@effect/platform";
|
|
396
|
+
import { ArrayFormatter } from "@effect/schema";
|
|
412
397
|
|
|
413
|
-
// src/
|
|
398
|
+
// src/internal/ogmios.ts
|
|
414
399
|
import * as S from "@effect/schema/Schema";
|
|
400
|
+
import { fromUnit } from "@lucid-evolution/utils";
|
|
415
401
|
var JSONRPCSchema = (schema) => S.extend(
|
|
416
402
|
S.Struct({
|
|
417
403
|
jsonrpc: S.String,
|
|
@@ -429,6 +415,51 @@ var TupleNumberFromString = S.compose(
|
|
|
429
415
|
);
|
|
430
416
|
var ProtocolParametersSchema = S.Struct({
|
|
431
417
|
minFeeCoefficient: S.Number,
|
|
418
|
+
minFeeReferenceScripts: S.Struct({
|
|
419
|
+
base: S.Number,
|
|
420
|
+
range: S.Number,
|
|
421
|
+
multiplier: S.Number
|
|
422
|
+
}),
|
|
423
|
+
maxReferenceScriptsSize: S.Struct({
|
|
424
|
+
bytes: S.Number
|
|
425
|
+
}),
|
|
426
|
+
stakePoolVotingThresholds: S.Struct({
|
|
427
|
+
noConfidence: TupleNumberFromString,
|
|
428
|
+
constitutionalCommittee: S.Struct({
|
|
429
|
+
default: TupleNumberFromString,
|
|
430
|
+
stateOfNoConfidence: TupleNumberFromString
|
|
431
|
+
}),
|
|
432
|
+
hardForkInitiation: TupleNumberFromString,
|
|
433
|
+
protocolParametersUpdate: S.Struct({
|
|
434
|
+
security: TupleNumberFromString
|
|
435
|
+
})
|
|
436
|
+
}),
|
|
437
|
+
delegateRepresentativeVotingThresholds: S.Struct({
|
|
438
|
+
noConfidence: TupleNumberFromString,
|
|
439
|
+
constitutionalCommittee: S.Struct({
|
|
440
|
+
default: TupleNumberFromString,
|
|
441
|
+
stateOfNoConfidence: TupleNumberFromString
|
|
442
|
+
}),
|
|
443
|
+
constitution: TupleNumberFromString,
|
|
444
|
+
hardForkInitiation: TupleNumberFromString,
|
|
445
|
+
protocolParametersUpdate: S.Struct({
|
|
446
|
+
network: TupleNumberFromString,
|
|
447
|
+
economic: TupleNumberFromString,
|
|
448
|
+
technical: TupleNumberFromString,
|
|
449
|
+
governance: TupleNumberFromString
|
|
450
|
+
}),
|
|
451
|
+
treasuryWithdrawals: TupleNumberFromString
|
|
452
|
+
}),
|
|
453
|
+
constitutionalCommitteeMinSize: S.Number,
|
|
454
|
+
constitutionalCommitteeMaxTermLength: S.Number,
|
|
455
|
+
governanceActionLifetime: S.Number,
|
|
456
|
+
governanceActionDeposit: S.Struct({
|
|
457
|
+
ada: LovelaceAsset
|
|
458
|
+
}),
|
|
459
|
+
delegateRepresentativeDeposit: S.Struct({
|
|
460
|
+
ada: LovelaceAsset
|
|
461
|
+
}),
|
|
462
|
+
delegateRepresentativeMaxIdleTime: S.Number,
|
|
432
463
|
minFeeConstant: S.Struct({ ada: LovelaceAsset }),
|
|
433
464
|
maxBlockBodySize: S.Struct({ bytes: S.Number }),
|
|
434
465
|
maxBlockHeaderSize: S.Struct({ bytes: S.Number }),
|
|
@@ -445,7 +476,8 @@ var ProtocolParametersSchema = S.Struct({
|
|
|
445
476
|
minUtxoDepositCoefficient: S.Number,
|
|
446
477
|
plutusCostModels: S.Struct({
|
|
447
478
|
"plutus:v1": S.Array(S.Number),
|
|
448
|
-
"plutus:v2": S.Array(S.Number)
|
|
479
|
+
"plutus:v2": S.Array(S.Number),
|
|
480
|
+
"plutus:v3": S.Array(S.Number)
|
|
449
481
|
}),
|
|
450
482
|
scriptExecutionPrices: S.Struct({
|
|
451
483
|
memory: TupleNumberFromString,
|
|
@@ -461,62 +493,118 @@ var ProtocolParametersSchema = S.Struct({
|
|
|
461
493
|
maxCollateralInputs: S.Number,
|
|
462
494
|
version: S.Struct({ major: S.Number, minor: S.Number })
|
|
463
495
|
});
|
|
464
|
-
var
|
|
465
|
-
|
|
466
|
-
|
|
496
|
+
var Delegation = S.NullOr(
|
|
497
|
+
S.Record(
|
|
498
|
+
S.String,
|
|
499
|
+
S.Struct({
|
|
500
|
+
delegate: S.Struct({ id: S.String }),
|
|
501
|
+
rewards: S.Struct({ ada: S.Struct({ lovelace: S.Number }) }),
|
|
502
|
+
deposit: S.Struct({ ada: S.Struct({ lovelace: S.Number }) })
|
|
503
|
+
})
|
|
504
|
+
)
|
|
505
|
+
);
|
|
506
|
+
var RedeemerSchema = S.Struct({
|
|
507
|
+
validator: S.Struct({
|
|
508
|
+
purpose: S.String,
|
|
509
|
+
index: S.Int
|
|
510
|
+
}),
|
|
511
|
+
budget: S.Struct({
|
|
512
|
+
memory: S.Int,
|
|
513
|
+
cpu: S.Int
|
|
514
|
+
})
|
|
467
515
|
});
|
|
468
|
-
var
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
516
|
+
var toOgmiosUTxOs = (utxos) => {
|
|
517
|
+
const toOgmiosScript = (scriptRef) => {
|
|
518
|
+
if (scriptRef) {
|
|
519
|
+
switch (scriptRef.type) {
|
|
520
|
+
case "PlutusV1":
|
|
521
|
+
return { language: "plutus:v1", cbor: scriptRef.script };
|
|
522
|
+
case "PlutusV2":
|
|
523
|
+
return { language: "plutus:v2", cbor: scriptRef.script };
|
|
524
|
+
case "PlutusV3":
|
|
525
|
+
return { language: "plutus:v3", cbor: scriptRef.script };
|
|
526
|
+
default:
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
const toOgmiosAssets = (assets) => {
|
|
532
|
+
const newAssets = {};
|
|
533
|
+
Object.entries(assets).map(([unit, amount]) => {
|
|
534
|
+
if (unit == "lovelace") return;
|
|
535
|
+
const { policyId, assetName } = fromUnit(unit);
|
|
536
|
+
newAssets[policyId][assetName ? assetName : ""] = Number(amount);
|
|
537
|
+
});
|
|
538
|
+
return newAssets;
|
|
539
|
+
};
|
|
540
|
+
return (utxos || []).map(
|
|
541
|
+
(utxo) => ({
|
|
542
|
+
transaction: {
|
|
543
|
+
id: utxo.txHash
|
|
544
|
+
},
|
|
545
|
+
index: utxo.outputIndex,
|
|
546
|
+
address: utxo.address,
|
|
547
|
+
value: {
|
|
548
|
+
ada: { lovelace: Number(utxo.assets["lovelace"]) },
|
|
549
|
+
...toOgmiosAssets(utxo.assets)
|
|
550
|
+
},
|
|
551
|
+
datumHash: utxo.datumHash,
|
|
552
|
+
datum: utxo.datum,
|
|
553
|
+
script: toOgmiosScript(utxo.scriptRef)
|
|
554
|
+
})
|
|
555
|
+
);
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
// src/internal/kupo.ts
|
|
559
|
+
import * as S2 from "@effect/schema/Schema";
|
|
560
|
+
var ValueSchema = S2.Struct({
|
|
561
|
+
coins: S2.Number,
|
|
562
|
+
assets: S2.Record(S2.String, S2.Number)
|
|
563
|
+
});
|
|
564
|
+
var UTxOSchema = S2.Struct({
|
|
565
|
+
transaction_index: S2.Number,
|
|
566
|
+
transaction_id: S2.String,
|
|
567
|
+
output_index: S2.Number,
|
|
568
|
+
address: S2.String,
|
|
569
|
+
value: ValueSchema,
|
|
570
|
+
datum_hash: S2.NullOr(S2.String),
|
|
571
|
+
datum_type: S2.optional(S2.Literal("hash", "inline")),
|
|
572
|
+
script_hash: S2.NullOr(S2.String),
|
|
573
|
+
created_at: S2.Struct({
|
|
574
|
+
slot_no: S2.Number,
|
|
575
|
+
header_hash: S2.String
|
|
480
576
|
}),
|
|
481
|
-
spent_at:
|
|
482
|
-
|
|
483
|
-
slot_no:
|
|
484
|
-
header_hash:
|
|
577
|
+
spent_at: S2.NullOr(
|
|
578
|
+
S2.Struct({
|
|
579
|
+
slot_no: S2.Number,
|
|
580
|
+
header_hash: S2.String
|
|
485
581
|
})
|
|
486
582
|
)
|
|
487
583
|
});
|
|
488
|
-
var
|
|
489
|
-
|
|
490
|
-
language:
|
|
491
|
-
script:
|
|
584
|
+
var ScriptSchema = S2.NullOr(
|
|
585
|
+
S2.Struct({
|
|
586
|
+
language: S2.Literal("native", "plutus:v1", "plutus:v2", "plutus:v3"),
|
|
587
|
+
script: S2.String
|
|
492
588
|
})
|
|
493
589
|
);
|
|
494
|
-
var
|
|
495
|
-
var
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
delegate:
|
|
500
|
-
rewards:
|
|
501
|
-
deposit:
|
|
590
|
+
var DatumSchema = S2.NullOr(S2.Struct({ datum: S2.String }));
|
|
591
|
+
var DelegationSchema = S2.NullOr(
|
|
592
|
+
S2.Record(
|
|
593
|
+
S2.String,
|
|
594
|
+
S2.Struct({
|
|
595
|
+
delegate: S2.Struct({ id: S2.String }),
|
|
596
|
+
rewards: S2.Struct({ ada: S2.Struct({ lovelace: S2.Number }) }),
|
|
597
|
+
deposit: S2.Struct({ ada: S2.Struct({ lovelace: S2.Number }) })
|
|
502
598
|
})
|
|
503
599
|
)
|
|
504
600
|
);
|
|
505
601
|
|
|
506
|
-
// src/kupmios
|
|
507
|
-
import {
|
|
508
|
-
HttpClient,
|
|
509
|
-
HttpClientRequest,
|
|
510
|
-
HttpClientResponse
|
|
511
|
-
} from "@effect/platform";
|
|
602
|
+
// src/kupmios.ts
|
|
512
603
|
var KupmiosError = class extends Data.TaggedError("KupmiosError") {
|
|
513
604
|
get message() {
|
|
514
|
-
return `${this.cause}`;
|
|
605
|
+
return `${JSON.stringify(this.cause)}`;
|
|
515
606
|
}
|
|
516
607
|
};
|
|
517
|
-
var kupmiosError = (cause) => new KupmiosError({
|
|
518
|
-
cause: JSON.stringify(cause)
|
|
519
|
-
});
|
|
520
608
|
var Kupmios = class {
|
|
521
609
|
kupoUrl;
|
|
522
610
|
ogmiosUrl;
|
|
@@ -535,15 +623,13 @@ var Kupmios = class {
|
|
|
535
623
|
params: {},
|
|
536
624
|
id: null
|
|
537
625
|
};
|
|
538
|
-
const schema = JSONRPCSchema(
|
|
539
|
-
ProtocolParametersSchema
|
|
540
|
-
);
|
|
626
|
+
const schema = JSONRPCSchema(ProtocolParametersSchema);
|
|
541
627
|
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
542
628
|
Effect.flatMap(
|
|
543
|
-
(response) => "error" in response ?
|
|
629
|
+
(response) => "error" in response ? Effect.fail(response) : Effect.succeed(response.result)
|
|
544
630
|
),
|
|
545
631
|
Effect.timeout(1e4),
|
|
546
|
-
Effect.catchAll(
|
|
632
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
547
633
|
);
|
|
548
634
|
const result = await Effect.runPromise(program);
|
|
549
635
|
return toProtocolParameters(result);
|
|
@@ -552,11 +638,11 @@ var Kupmios = class {
|
|
|
552
638
|
const isAddress = typeof addressOrCredential === "string";
|
|
553
639
|
const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
|
|
554
640
|
const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent`;
|
|
555
|
-
const schema =
|
|
641
|
+
const schema = S3.Array(UTxOSchema);
|
|
556
642
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
557
643
|
Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
558
644
|
Effect.timeout(1e4),
|
|
559
|
-
Effect.catchAll(
|
|
645
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
560
646
|
);
|
|
561
647
|
const utxos = await Effect.runPromise(program);
|
|
562
648
|
return utxos;
|
|
@@ -564,25 +650,25 @@ var Kupmios = class {
|
|
|
564
650
|
async getUtxosWithUnit(addressOrCredential, unit) {
|
|
565
651
|
const isAddress = typeof addressOrCredential === "string";
|
|
566
652
|
const queryPredicate = isAddress ? addressOrCredential : addressOrCredential.hash;
|
|
567
|
-
const { policyId, assetName } =
|
|
653
|
+
const { policyId, assetName } = fromUnit2(unit);
|
|
568
654
|
const pattern = `${this.kupoUrl}/matches/${queryPredicate}${isAddress ? "" : "/*"}?unspent&policy_id=${policyId}${assetName ? `&asset_name=${assetName}` : ""}`;
|
|
569
|
-
const schema =
|
|
655
|
+
const schema = S3.Array(UTxOSchema);
|
|
570
656
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
571
657
|
Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
572
658
|
Effect.timeout(1e4),
|
|
573
|
-
Effect.catchAll(
|
|
659
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
574
660
|
);
|
|
575
661
|
const utxos = await Effect.runPromise(program);
|
|
576
662
|
return utxos;
|
|
577
663
|
}
|
|
578
664
|
async getUtxoByUnit(unit) {
|
|
579
|
-
const { policyId, assetName } =
|
|
665
|
+
const { policyId, assetName } = fromUnit2(unit);
|
|
580
666
|
const pattern = `${this.kupoUrl}/matches/${policyId}.${assetName ? `${assetName}` : "*"}?unspent`;
|
|
581
|
-
const schema =
|
|
667
|
+
const schema = S3.Array(UTxOSchema);
|
|
582
668
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
583
669
|
Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
584
670
|
Effect.timeout(1e4),
|
|
585
|
-
Effect.catchAll(
|
|
671
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
586
672
|
);
|
|
587
673
|
const utxos = await Effect.runPromise(program);
|
|
588
674
|
if (utxos.length > 1) {
|
|
@@ -595,13 +681,13 @@ var Kupmios = class {
|
|
|
595
681
|
...new Set(outRefs.map((outRef) => outRef.txHash))
|
|
596
682
|
];
|
|
597
683
|
const mkPattern = (txHash) => `${this.kupoUrl}/matches/*@${txHash}?unspent`;
|
|
598
|
-
const schema =
|
|
684
|
+
const schema = S3.Array(UTxOSchema);
|
|
599
685
|
const program = Effect.forEach(
|
|
600
686
|
queryHashes,
|
|
601
687
|
(txHash) => fetchKupoParse(mkPattern(txHash), schema).pipe(
|
|
602
688
|
Effect.flatMap((u) => kupmiosUtxosToUtxos(this.kupoUrl, u)),
|
|
603
689
|
Effect.timeout(1e4),
|
|
604
|
-
Effect.catchAll(
|
|
690
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
605
691
|
)
|
|
606
692
|
);
|
|
607
693
|
const utxos = await Effect.runPromise(program);
|
|
@@ -618,13 +704,13 @@ var Kupmios = class {
|
|
|
618
704
|
params: { keys: [rewardAddress] },
|
|
619
705
|
id: null
|
|
620
706
|
};
|
|
621
|
-
const schema = JSONRPCSchema(
|
|
707
|
+
const schema = JSONRPCSchema(Delegation);
|
|
622
708
|
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
623
709
|
Effect.flatMap(
|
|
624
|
-
(response) => "error" in response ?
|
|
710
|
+
(response) => "error" in response ? Effect.fail(response) : Effect.succeed(response.result)
|
|
625
711
|
),
|
|
626
712
|
Effect.timeout(1e4),
|
|
627
|
-
Effect.catchAll(
|
|
713
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
628
714
|
);
|
|
629
715
|
const result = await Effect.runPromise(program);
|
|
630
716
|
const delegation = result ? Object.values(result)[0] : null;
|
|
@@ -635,18 +721,18 @@ var Kupmios = class {
|
|
|
635
721
|
}
|
|
636
722
|
async getDatum(datumHash) {
|
|
637
723
|
const pattern = `${this.kupoUrl}/datums/${datumHash}`;
|
|
638
|
-
const schema =
|
|
724
|
+
const schema = DatumSchema;
|
|
639
725
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
640
726
|
Effect.timeout(1e4),
|
|
641
727
|
Effect.flatMap(Effect.fromNullable),
|
|
642
|
-
Effect.catchAll(
|
|
728
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
643
729
|
);
|
|
644
730
|
const result = await Effect.runPromise(program);
|
|
645
731
|
return result.datum;
|
|
646
732
|
}
|
|
647
733
|
async awaitTx(txHash, checkInterval = 2e4) {
|
|
648
|
-
const pattern = `${this.kupoUrl}/matches/*@${txHash}
|
|
649
|
-
const schema =
|
|
734
|
+
const pattern = `${this.kupoUrl}/matches/*@${txHash}`;
|
|
735
|
+
const schema = S3.Array(UTxOSchema).annotations({
|
|
650
736
|
identifier: "Array<KupmiosSchema.KupoUTxO>"
|
|
651
737
|
});
|
|
652
738
|
const program = fetchKupoParse(pattern, schema).pipe(
|
|
@@ -655,7 +741,7 @@ var Kupmios = class {
|
|
|
655
741
|
until: (result) => result.length > 0
|
|
656
742
|
}),
|
|
657
743
|
Effect.timeout(16e4),
|
|
658
|
-
Effect.catchAll(
|
|
744
|
+
Effect.catchAll((cause) => new KupmiosError({ cause })),
|
|
659
745
|
Effect.as(true)
|
|
660
746
|
);
|
|
661
747
|
return await Effect.runPromise(program);
|
|
@@ -670,70 +756,39 @@ var Kupmios = class {
|
|
|
670
756
|
id: null
|
|
671
757
|
};
|
|
672
758
|
const schema = JSONRPCSchema(
|
|
673
|
-
|
|
674
|
-
transaction:
|
|
675
|
-
id:
|
|
759
|
+
S3.Struct({
|
|
760
|
+
transaction: S3.Struct({
|
|
761
|
+
id: S3.String
|
|
676
762
|
})
|
|
677
763
|
})
|
|
678
764
|
);
|
|
679
765
|
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
680
766
|
Effect.flatMap(
|
|
681
|
-
(response) => "error" in response ? Effect.fail(response
|
|
767
|
+
(response) => "error" in response ? Effect.fail(response) : Effect.succeed(response)
|
|
682
768
|
),
|
|
683
769
|
Effect.timeout(1e4),
|
|
684
|
-
Effect.catchAll(
|
|
770
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
685
771
|
);
|
|
686
772
|
const { result } = await Effect.runPromise(program);
|
|
687
773
|
return result.transaction.id;
|
|
688
774
|
}
|
|
689
775
|
async evaluateTx(tx, additionalUTxOs) {
|
|
690
|
-
const utxos = (additionalUTxOs || []).map((utxo) => {
|
|
691
|
-
const script = utxo.scriptRef ? {
|
|
692
|
-
language: utxo.scriptRef.type,
|
|
693
|
-
cbor: utxo.scriptRef.script
|
|
694
|
-
} : void 0;
|
|
695
|
-
return [
|
|
696
|
-
{
|
|
697
|
-
transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
|
|
698
|
-
},
|
|
699
|
-
{
|
|
700
|
-
address: utxo.address,
|
|
701
|
-
value: {
|
|
702
|
-
coins: utxo.assets.lovelace,
|
|
703
|
-
assets: utxo.assets.restAssets
|
|
704
|
-
},
|
|
705
|
-
datumHash: utxo.datumHash,
|
|
706
|
-
datum: utxo.datum,
|
|
707
|
-
script
|
|
708
|
-
}
|
|
709
|
-
];
|
|
710
|
-
});
|
|
711
776
|
const data = {
|
|
712
777
|
jsonrpc: "2.0",
|
|
713
778
|
method: "evaluateTransaction",
|
|
714
|
-
params: {
|
|
779
|
+
params: {
|
|
780
|
+
transaction: { cbor: tx },
|
|
781
|
+
additionalUtxo: toOgmiosUTxOs(additionalUTxOs)
|
|
782
|
+
},
|
|
715
783
|
id: null
|
|
716
784
|
};
|
|
717
|
-
const schema = JSONRPCSchema(
|
|
718
|
-
S2.Array(
|
|
719
|
-
S2.Struct({
|
|
720
|
-
validator: S2.Struct({
|
|
721
|
-
purpose: S2.String,
|
|
722
|
-
index: S2.Int
|
|
723
|
-
}),
|
|
724
|
-
budget: S2.Struct({
|
|
725
|
-
memory: S2.Int,
|
|
726
|
-
cpu: S2.Int
|
|
727
|
-
})
|
|
728
|
-
})
|
|
729
|
-
)
|
|
730
|
-
);
|
|
785
|
+
const schema = JSONRPCSchema(S3.Array(RedeemerSchema));
|
|
731
786
|
const program = fetchOgmiosParse(this.ogmiosUrl, data, schema).pipe(
|
|
732
787
|
Effect.flatMap(
|
|
733
|
-
(response) => "error" in response ?
|
|
788
|
+
(response) => "error" in response ? Effect.fail(response) : Effect.succeed(response.result)
|
|
734
789
|
),
|
|
735
790
|
Effect.timeout(1e4),
|
|
736
|
-
Effect.catchAll(
|
|
791
|
+
Effect.catchAll((cause) => new KupmiosError({ cause }))
|
|
737
792
|
);
|
|
738
793
|
const result = await Effect.runPromise(program);
|
|
739
794
|
const evalRedeemers = result.map((item) => ({
|
|
@@ -750,7 +805,7 @@ var Kupmios = class {
|
|
|
750
805
|
var getDatumEffect = (kupoUrl, datum_type, datum_hash) => Effect.gen(function* () {
|
|
751
806
|
if (datum_type === "inline" && datum_hash) {
|
|
752
807
|
const pattern = `${kupoUrl}/datums/${datum_hash}`;
|
|
753
|
-
const schema =
|
|
808
|
+
const schema = DatumSchema;
|
|
754
809
|
return yield* fetchKupoParse(pattern, schema).pipe(
|
|
755
810
|
Effect.flatMap(Effect.fromNullable),
|
|
756
811
|
Effect.map((result) => result.datum),
|
|
@@ -761,7 +816,7 @@ var getDatumEffect = (kupoUrl, datum_type, datum_hash) => Effect.gen(function* (
|
|
|
761
816
|
var getScriptEffect = (kupoUrl, script_hash) => Effect.gen(function* () {
|
|
762
817
|
if (script_hash) {
|
|
763
818
|
const pattern = `${kupoUrl}/scripts/${script_hash}`;
|
|
764
|
-
const schema =
|
|
819
|
+
const schema = ScriptSchema;
|
|
765
820
|
return yield* pipe2(
|
|
766
821
|
fetchKupoParse(pattern, schema),
|
|
767
822
|
Effect.flatMap(Effect.fromNullable),
|
|
@@ -780,6 +835,11 @@ var getScriptEffect = (kupoUrl, script_hash) => Effect.gen(function* () {
|
|
|
780
835
|
type: "PlutusV2",
|
|
781
836
|
script: applyDoubleCborEncoding2(script)
|
|
782
837
|
};
|
|
838
|
+
case "plutus:v3":
|
|
839
|
+
return {
|
|
840
|
+
type: "PlutusV3",
|
|
841
|
+
script: applyDoubleCborEncoding2(script)
|
|
842
|
+
};
|
|
783
843
|
}
|
|
784
844
|
})
|
|
785
845
|
);
|
|
@@ -824,6 +884,12 @@ var toProtocolParameters = (result) => {
|
|
|
824
884
|
index.toString(),
|
|
825
885
|
value
|
|
826
886
|
])
|
|
887
|
+
),
|
|
888
|
+
PlutusV3: Object.fromEntries(
|
|
889
|
+
result.plutusCostModels["plutus:v3"].map((value, index) => [
|
|
890
|
+
index.toString(),
|
|
891
|
+
value
|
|
892
|
+
])
|
|
827
893
|
)
|
|
828
894
|
}
|
|
829
895
|
};
|
|
@@ -833,20 +899,22 @@ var fetchOgmiosParse = (url, data, schema) => pipe2(
|
|
|
833
899
|
HttpClientRequest.jsonBody(data),
|
|
834
900
|
Effect.flatMap(HttpClient.fetch),
|
|
835
901
|
HttpClientResponse.json,
|
|
836
|
-
Effect.flatMap(
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
902
|
+
Effect.flatMap(S3.decodeUnknown(schema, { onExcessProperty: "error" })),
|
|
903
|
+
Effect.catchTag(
|
|
904
|
+
"ParseError",
|
|
905
|
+
(e) => Effect.fail(ArrayFormatter.formatErrorSync(e))
|
|
906
|
+
)
|
|
840
907
|
// Effect.scoped
|
|
841
908
|
);
|
|
842
909
|
var fetchKupoParse = (url, schema) => pipe2(
|
|
843
910
|
HttpClientRequest.get(url),
|
|
844
911
|
HttpClient.fetchOk,
|
|
845
912
|
HttpClientResponse.json,
|
|
846
|
-
Effect.flatMap(
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
913
|
+
Effect.flatMap(S3.decodeUnknown(schema, { onExcessProperty: "error" })),
|
|
914
|
+
Effect.catchTag(
|
|
915
|
+
"ParseError",
|
|
916
|
+
(e) => Effect.fail(ArrayFormatter.formatErrorSync(e))
|
|
917
|
+
)
|
|
850
918
|
// Effect.scoped
|
|
851
919
|
);
|
|
852
920
|
var kupmiosUtxosToUtxos = (kupoURL, utxos) => Effect.forEach(
|
|
@@ -1223,12 +1291,27 @@ It does not exist or was already spent.`
|
|
|
1223
1291
|
3: "Reward"
|
|
1224
1292
|
};
|
|
1225
1293
|
const collected = [];
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1294
|
+
const redeemers2 = witnesses.redeemers();
|
|
1295
|
+
const arrLegacyRedeemer = redeemers2?.as_arr_legacy_redeemer();
|
|
1296
|
+
if (arrLegacyRedeemer) {
|
|
1297
|
+
for (let i = 0; i < (arrLegacyRedeemer.len() || 0); i++) {
|
|
1298
|
+
const redeemer = arrLegacyRedeemer.get(i);
|
|
1299
|
+
collected.push({
|
|
1300
|
+
tag: tagMap[redeemer.tag()],
|
|
1301
|
+
index: Number(redeemer.index())
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
const mapRedeemerKeyToRedeemerVal = redeemers2?.as_map_redeemer_key_to_redeemer_val();
|
|
1306
|
+
if (mapRedeemerKeyToRedeemerVal) {
|
|
1307
|
+
const keys = mapRedeemerKeyToRedeemerVal.keys();
|
|
1308
|
+
for (let i = 0; i < (keys.len() || 0); i++) {
|
|
1309
|
+
const key = keys.get(i);
|
|
1310
|
+
collected.push({
|
|
1311
|
+
tag: tagMap[key.tag()],
|
|
1312
|
+
index: Number(key.index())
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1232
1315
|
}
|
|
1233
1316
|
return collected;
|
|
1234
1317
|
})();
|
|
@@ -1610,7 +1693,7 @@ var Maestro = class {
|
|
|
1610
1693
|
this.turboSubmit = turboSubmit;
|
|
1611
1694
|
}
|
|
1612
1695
|
async getProtocolParameters() {
|
|
1613
|
-
const timestampedResult = await fetch(`${this.url}/protocol-
|
|
1696
|
+
const timestampedResult = await fetch(`${this.url}/protocol-parameters`, {
|
|
1614
1697
|
headers: this.commonHeaders()
|
|
1615
1698
|
}).then((res) => res.json());
|
|
1616
1699
|
const result = timestampedResult.data;
|
|
@@ -1618,37 +1701,39 @@ var Maestro = class {
|
|
|
1618
1701
|
const forwardSlashIndex = str.indexOf("/");
|
|
1619
1702
|
return parseInt(str.slice(0, forwardSlashIndex)) / parseInt(str.slice(forwardSlashIndex + 1));
|
|
1620
1703
|
};
|
|
1621
|
-
const renameKeysAndSort = (obj, newKeys) => {
|
|
1622
|
-
const entries = Object.keys(obj).sort().map((key) => {
|
|
1623
|
-
const newKey = newKeys[key] || key;
|
|
1624
|
-
return {
|
|
1625
|
-
[newKey]: Object.fromEntries(
|
|
1626
|
-
Object.entries(obj[key]).sort(
|
|
1627
|
-
([k, _v], [k2, _v2]) => k.localeCompare(k2)
|
|
1628
|
-
)
|
|
1629
|
-
)
|
|
1630
|
-
};
|
|
1631
|
-
});
|
|
1632
|
-
return Object.assign({}, ...entries);
|
|
1633
|
-
};
|
|
1634
1704
|
return {
|
|
1635
1705
|
minFeeA: parseInt(result.min_fee_coefficient),
|
|
1636
|
-
minFeeB: parseInt(result.min_fee_constant),
|
|
1637
|
-
maxTxSize: parseInt(result.
|
|
1638
|
-
maxValSize: parseInt(result.max_value_size),
|
|
1639
|
-
keyDeposit: BigInt(result.
|
|
1640
|
-
poolDeposit: BigInt(result.
|
|
1641
|
-
priceMem: decimalFromRationalString(
|
|
1642
|
-
|
|
1706
|
+
minFeeB: parseInt(result.min_fee_constant.ada.lovelace),
|
|
1707
|
+
maxTxSize: parseInt(result.max_transaction_size.bytes),
|
|
1708
|
+
maxValSize: parseInt(result.max_value_size.bytes),
|
|
1709
|
+
keyDeposit: BigInt(result.stake_credential_deposit.ada.lovelace),
|
|
1710
|
+
poolDeposit: BigInt(result.stake_pool_deposit.ada.lovelace),
|
|
1711
|
+
priceMem: decimalFromRationalString(
|
|
1712
|
+
result.script_execution_prices.memory
|
|
1713
|
+
),
|
|
1714
|
+
priceStep: decimalFromRationalString(result.script_execution_prices.cpu),
|
|
1643
1715
|
maxTxExMem: BigInt(result.max_execution_units_per_transaction.memory),
|
|
1644
|
-
maxTxExSteps: BigInt(result.max_execution_units_per_transaction.
|
|
1645
|
-
coinsPerUtxoByte: BigInt(result.
|
|
1716
|
+
maxTxExSteps: BigInt(result.max_execution_units_per_transaction.cpu),
|
|
1717
|
+
coinsPerUtxoByte: BigInt(result.min_utxo_deposit_coefficient),
|
|
1646
1718
|
collateralPercentage: parseInt(result.collateral_percentage),
|
|
1647
1719
|
maxCollateralInputs: parseInt(result.max_collateral_inputs),
|
|
1648
|
-
costModels:
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1720
|
+
costModels: {
|
|
1721
|
+
PlutusV1: Object.fromEntries(
|
|
1722
|
+
result.plutus_cost_models.plutus_v1.map(
|
|
1723
|
+
(value, index) => [index.toString(), value]
|
|
1724
|
+
)
|
|
1725
|
+
),
|
|
1726
|
+
PlutusV2: Object.fromEntries(
|
|
1727
|
+
result.plutus_cost_models.plutus_v2.map(
|
|
1728
|
+
(value, index) => [index.toString(), value]
|
|
1729
|
+
)
|
|
1730
|
+
),
|
|
1731
|
+
PlutusV3: Object.fromEntries(
|
|
1732
|
+
result.plutus_cost_models.plutus_v2.map(
|
|
1733
|
+
(value, index) => [index.toString(), value]
|
|
1734
|
+
)
|
|
1735
|
+
)
|
|
1736
|
+
}
|
|
1652
1737
|
};
|
|
1653
1738
|
}
|
|
1654
1739
|
async getUtxosInternal(addressOrCredential, unit) {
|
|
@@ -1831,10 +1916,7 @@ var Maestro = class {
|
|
|
1831
1916
|
address: result.address,
|
|
1832
1917
|
datumHash: result.datum ? result.datum.type == "inline" ? void 0 : result.datum.hash : void 0,
|
|
1833
1918
|
datum: result.datum?.bytes,
|
|
1834
|
-
scriptRef: result.reference_script
|
|
1835
|
-
type: result.reference_script.type == "plutusv1" ? "PlutusV1" : "PlutusV2",
|
|
1836
|
-
script: applyDoubleCborEncoding3(result.reference_script.bytes)
|
|
1837
|
-
} : void 0
|
|
1919
|
+
scriptRef: toScriptRef(result.reference_script)
|
|
1838
1920
|
};
|
|
1839
1921
|
}
|
|
1840
1922
|
async getAllPagesData(getResponse, qry, paramsGiven, errorMsg) {
|
|
@@ -1859,13 +1941,13 @@ var Maestro = class {
|
|
|
1859
1941
|
}
|
|
1860
1942
|
async evaluateTx(tx, additionalUTxOs) {
|
|
1861
1943
|
const additionalMaestroUTxOs = (additionalUTxOs || []).map((utxo) => ({
|
|
1862
|
-
index: utxo.outputIndex,
|
|
1863
1944
|
tx_hash: utxo.txHash,
|
|
1864
|
-
|
|
1945
|
+
index: utxo.outputIndex,
|
|
1946
|
+
txout_cbor: utxoToCore(utxo).output().to_cbor_hex()
|
|
1865
1947
|
}));
|
|
1866
1948
|
const payload = {
|
|
1867
1949
|
cbor: tx,
|
|
1868
|
-
additionalMaestroUTxOs
|
|
1950
|
+
additional_utxos: additionalMaestroUTxOs
|
|
1869
1951
|
};
|
|
1870
1952
|
const res = await fetch(`${this.url}/transactions/evaluate`, {
|
|
1871
1953
|
method: "POST",
|
|
@@ -1885,277 +1967,391 @@ var Maestro = class {
|
|
|
1885
1967
|
return result;
|
|
1886
1968
|
}
|
|
1887
1969
|
};
|
|
1970
|
+
var toScriptRef = (reference_script) => {
|
|
1971
|
+
if (reference_script && reference_script.bytes) {
|
|
1972
|
+
switch (reference_script.type) {
|
|
1973
|
+
case "plutusv1":
|
|
1974
|
+
return {
|
|
1975
|
+
type: "PlutusV1",
|
|
1976
|
+
script: applyDoubleCborEncoding3(reference_script.bytes)
|
|
1977
|
+
};
|
|
1978
|
+
case "plutusv2":
|
|
1979
|
+
return {
|
|
1980
|
+
type: "PlutusV2",
|
|
1981
|
+
script: applyDoubleCborEncoding3(reference_script.bytes)
|
|
1982
|
+
};
|
|
1983
|
+
case "plutusv3":
|
|
1984
|
+
return {
|
|
1985
|
+
type: "PlutusV3",
|
|
1986
|
+
script: applyDoubleCborEncoding3(reference_script.bytes)
|
|
1987
|
+
};
|
|
1988
|
+
default:
|
|
1989
|
+
return void 0;
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
};
|
|
1888
1993
|
var lucid2 = package_default.version;
|
|
1889
1994
|
|
|
1890
|
-
// src/koios
|
|
1891
|
-
import * as
|
|
1995
|
+
// src/koios.ts
|
|
1996
|
+
import * as S5 from "@effect/schema/Schema";
|
|
1892
1997
|
import { fromHex as fromHex4 } from "@lucid-evolution/core-utils";
|
|
1893
|
-
import {
|
|
1998
|
+
import { fromUnit as fromUnit3 } from "@lucid-evolution/utils";
|
|
1894
1999
|
|
|
1895
|
-
// src/koios
|
|
1896
|
-
import
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
2000
|
+
// src/internal/koios.ts
|
|
2001
|
+
import {
|
|
2002
|
+
HttpClient as HttpClient2,
|
|
2003
|
+
HttpClientRequest as HttpClientRequest2,
|
|
2004
|
+
HttpClientResponse as HttpClientResponse2
|
|
2005
|
+
} from "@effect/platform";
|
|
2006
|
+
import * as S4 from "@effect/schema/Schema";
|
|
2007
|
+
import { Effect as Effect2, pipe as pipe3 } from "effect";
|
|
2008
|
+
import { applyDoubleCborEncoding as applyDoubleCborEncoding4 } from "@lucid-evolution/utils";
|
|
2009
|
+
var ProtocolParametersSchema2 = S4.Struct({
|
|
2010
|
+
pvt_motion_no_confidence: S4.Number,
|
|
2011
|
+
pvt_committee_normal: S4.Number,
|
|
2012
|
+
pvt_committee_no_confidence: S4.Number,
|
|
2013
|
+
pvt_hard_fork_initiation: S4.Number,
|
|
2014
|
+
pvtpp_security_group: S4.Number,
|
|
2015
|
+
dvt_motion_no_confidence: S4.Number,
|
|
2016
|
+
dvt_committee_normal: S4.Number,
|
|
2017
|
+
dvt_committee_no_confidence: S4.Number,
|
|
2018
|
+
dvt_update_to_constitution: S4.Number,
|
|
2019
|
+
dvt_hard_fork_initiation: S4.Number,
|
|
2020
|
+
dvt_p_p_network_group: S4.Number,
|
|
2021
|
+
dvt_p_p_economic_group: S4.Number,
|
|
2022
|
+
dvt_p_p_technical_group: S4.Number,
|
|
2023
|
+
dvt_p_p_gov_group: S4.Number,
|
|
2024
|
+
dvt_treasury_withdrawal: S4.Number,
|
|
2025
|
+
committee_min_size: S4.Number,
|
|
2026
|
+
committee_max_term_length: S4.Number,
|
|
2027
|
+
gov_action_lifetime: S4.Number,
|
|
2028
|
+
gov_action_deposit: S4.NumberFromString,
|
|
2029
|
+
drep_deposit: S4.NumberFromString,
|
|
2030
|
+
drep_activity: S4.Number,
|
|
2031
|
+
min_fee_ref_script_cost_per_byte: S4.Number,
|
|
2032
|
+
epoch_no: S4.Number,
|
|
2033
|
+
min_fee_a: S4.Number,
|
|
2034
|
+
min_fee_b: S4.Number,
|
|
2035
|
+
max_block_size: S4.Number,
|
|
2036
|
+
max_tx_size: S4.Number,
|
|
2037
|
+
max_bh_size: S4.Number,
|
|
2038
|
+
key_deposit: S4.BigInt,
|
|
2039
|
+
pool_deposit: S4.BigInt,
|
|
2040
|
+
max_epoch: S4.Number,
|
|
2041
|
+
optimal_pool_count: S4.Number,
|
|
2042
|
+
influence: S4.Number,
|
|
2043
|
+
monetary_expand_rate: S4.Number,
|
|
2044
|
+
treasury_growth_rate: S4.Number,
|
|
2045
|
+
decentralisation: S4.Number,
|
|
2046
|
+
extra_entropy: S4.NullOr(S4.String),
|
|
2047
|
+
protocol_major: S4.Number,
|
|
2048
|
+
protocol_minor: S4.Number,
|
|
2049
|
+
min_utxo_value: S4.String,
|
|
2050
|
+
min_pool_cost: S4.String,
|
|
2051
|
+
nonce: S4.String,
|
|
2052
|
+
block_hash: S4.NullOr(S4.String),
|
|
2053
|
+
cost_models: S4.Struct({
|
|
2054
|
+
PlutusV1: S4.Array(S4.Number),
|
|
2055
|
+
PlutusV2: S4.Array(S4.Number),
|
|
2056
|
+
PlutusV3: S4.Array(S4.Number)
|
|
1922
2057
|
}),
|
|
1923
|
-
price_mem:
|
|
1924
|
-
price_step:
|
|
1925
|
-
max_tx_ex_mem:
|
|
1926
|
-
max_tx_ex_steps:
|
|
1927
|
-
max_block_ex_mem:
|
|
1928
|
-
max_block_ex_steps:
|
|
1929
|
-
max_val_size:
|
|
1930
|
-
collateral_percent:
|
|
1931
|
-
max_collateral_inputs:
|
|
1932
|
-
coins_per_utxo_size:
|
|
2058
|
+
price_mem: S4.Number,
|
|
2059
|
+
price_step: S4.Number,
|
|
2060
|
+
max_tx_ex_mem: S4.BigIntFromNumber,
|
|
2061
|
+
max_tx_ex_steps: S4.BigIntFromNumber,
|
|
2062
|
+
max_block_ex_mem: S4.Number,
|
|
2063
|
+
max_block_ex_steps: S4.Number,
|
|
2064
|
+
max_val_size: S4.Number,
|
|
2065
|
+
collateral_percent: S4.Number,
|
|
2066
|
+
max_collateral_inputs: S4.Number,
|
|
2067
|
+
coins_per_utxo_size: S4.BigInt
|
|
1933
2068
|
});
|
|
1934
|
-
var
|
|
1935
|
-
policy_id:
|
|
1936
|
-
asset_name:
|
|
1937
|
-
fingerprint:
|
|
1938
|
-
decimals:
|
|
1939
|
-
quantity:
|
|
2069
|
+
var AssetSchema = S4.Struct({
|
|
2070
|
+
policy_id: S4.String,
|
|
2071
|
+
asset_name: S4.NullOr(S4.String),
|
|
2072
|
+
fingerprint: S4.String,
|
|
2073
|
+
decimals: S4.Number,
|
|
2074
|
+
quantity: S4.String
|
|
1940
2075
|
});
|
|
1941
|
-
var
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
),
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
value: S3.NullOr(S3.Object)
|
|
2076
|
+
var ReferenceScriptSchema = S4.Struct({
|
|
2077
|
+
hash: S4.NullOr(S4.String),
|
|
2078
|
+
size: S4.NullOr(S4.Number),
|
|
2079
|
+
type: S4.NullOr(S4.String),
|
|
2080
|
+
bytes: S4.NullOr(S4.String),
|
|
2081
|
+
value: S4.NullOr(S4.Object)
|
|
2082
|
+
});
|
|
2083
|
+
var UTxOSchema2 = S4.Struct({
|
|
2084
|
+
tx_hash: S4.String,
|
|
2085
|
+
tx_index: S4.Number,
|
|
2086
|
+
block_time: S4.Number,
|
|
2087
|
+
block_height: S4.NullOr(S4.Number),
|
|
2088
|
+
value: S4.String,
|
|
2089
|
+
datum_hash: S4.NullOr(S4.String),
|
|
2090
|
+
inline_datum: S4.NullOr(
|
|
2091
|
+
S4.Struct({
|
|
2092
|
+
bytes: S4.String,
|
|
2093
|
+
value: S4.Object
|
|
1960
2094
|
})
|
|
1961
2095
|
),
|
|
1962
|
-
|
|
2096
|
+
reference_script: S4.NullOr(ReferenceScriptSchema),
|
|
2097
|
+
asset_list: S4.NullOr(S4.Array(AssetSchema))
|
|
1963
2098
|
});
|
|
1964
|
-
var
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
address:
|
|
1968
|
-
balance:
|
|
1969
|
-
stake_address:
|
|
1970
|
-
script_address:
|
|
1971
|
-
utxo_set:
|
|
2099
|
+
var AddressInfoSchema = S4.Array(
|
|
2100
|
+
S4.NullishOr(
|
|
2101
|
+
S4.Struct({
|
|
2102
|
+
address: S4.String,
|
|
2103
|
+
balance: S4.String,
|
|
2104
|
+
stake_address: S4.NullOr(S4.String),
|
|
2105
|
+
script_address: S4.Boolean,
|
|
2106
|
+
utxo_set: S4.Array(UTxOSchema2)
|
|
1972
2107
|
})
|
|
1973
2108
|
)
|
|
1974
2109
|
);
|
|
1975
|
-
var
|
|
1976
|
-
payment_addr:
|
|
1977
|
-
bech32:
|
|
1978
|
-
cred:
|
|
2110
|
+
var InputOutputSchema = S4.Struct({
|
|
2111
|
+
payment_addr: S4.Struct({
|
|
2112
|
+
bech32: S4.String,
|
|
2113
|
+
cred: S4.String
|
|
1979
2114
|
}),
|
|
1980
|
-
stake_addr:
|
|
1981
|
-
tx_hash:
|
|
1982
|
-
tx_index:
|
|
1983
|
-
value:
|
|
1984
|
-
datum_hash:
|
|
1985
|
-
inline_datum:
|
|
1986
|
-
|
|
1987
|
-
bytes:
|
|
1988
|
-
value:
|
|
1989
|
-
})
|
|
1990
|
-
),
|
|
1991
|
-
reference_script: S3.NullOr(
|
|
1992
|
-
S3.Struct({
|
|
1993
|
-
hash: S3.String,
|
|
1994
|
-
size: S3.Number,
|
|
1995
|
-
type: S3.String,
|
|
1996
|
-
bytes: S3.String,
|
|
1997
|
-
value: S3.NullOr(S3.Object)
|
|
2115
|
+
stake_addr: S4.NullOr(S4.String),
|
|
2116
|
+
tx_hash: S4.String,
|
|
2117
|
+
tx_index: S4.Number,
|
|
2118
|
+
value: S4.String,
|
|
2119
|
+
datum_hash: S4.NullOr(S4.String),
|
|
2120
|
+
inline_datum: S4.NullOr(
|
|
2121
|
+
S4.Struct({
|
|
2122
|
+
bytes: S4.String,
|
|
2123
|
+
value: S4.Object
|
|
1998
2124
|
})
|
|
1999
2125
|
),
|
|
2000
|
-
|
|
2126
|
+
reference_script: S4.NullOr(ReferenceScriptSchema),
|
|
2127
|
+
asset_list: S4.Array(AssetSchema)
|
|
2001
2128
|
});
|
|
2002
|
-
var
|
|
2003
|
-
tx_hash:
|
|
2004
|
-
block_hash:
|
|
2005
|
-
block_height:
|
|
2006
|
-
epoch_no:
|
|
2007
|
-
epoch_slot:
|
|
2008
|
-
absolute_slot:
|
|
2009
|
-
tx_timestamp:
|
|
2010
|
-
tx_block_index:
|
|
2011
|
-
tx_size:
|
|
2012
|
-
total_output:
|
|
2013
|
-
fee:
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2129
|
+
var TxInfoSchema = S4.Struct({
|
|
2130
|
+
tx_hash: S4.String,
|
|
2131
|
+
block_hash: S4.String,
|
|
2132
|
+
block_height: S4.Number,
|
|
2133
|
+
epoch_no: S4.Number,
|
|
2134
|
+
epoch_slot: S4.Number,
|
|
2135
|
+
absolute_slot: S4.Number,
|
|
2136
|
+
tx_timestamp: S4.Number,
|
|
2137
|
+
tx_block_index: S4.Number,
|
|
2138
|
+
tx_size: S4.Number,
|
|
2139
|
+
total_output: S4.String,
|
|
2140
|
+
fee: S4.String,
|
|
2141
|
+
treasury_donation: S4.String,
|
|
2142
|
+
deposit: S4.String,
|
|
2143
|
+
invalid_before: S4.NullOr(S4.String),
|
|
2144
|
+
invalid_after: S4.NullOr(S4.String),
|
|
2145
|
+
collateral_inputs: S4.NullOr(S4.Array(InputOutputSchema)),
|
|
2146
|
+
collateral_output: S4.NullOr(InputOutputSchema),
|
|
2147
|
+
reference_inputs: S4.NullOr(S4.Array(InputOutputSchema)),
|
|
2148
|
+
inputs: S4.Array(InputOutputSchema),
|
|
2149
|
+
outputs: S4.Array(InputOutputSchema),
|
|
2150
|
+
withdrawals: S4.NullOr(
|
|
2151
|
+
S4.Array(
|
|
2152
|
+
S4.Struct({
|
|
2153
|
+
amount: S4.String,
|
|
2154
|
+
stake_addr: S4.String
|
|
2027
2155
|
})
|
|
2028
2156
|
)
|
|
2029
2157
|
),
|
|
2030
|
-
assets_minted:
|
|
2031
|
-
metadata:
|
|
2032
|
-
certificates:
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
index:
|
|
2036
|
-
type:
|
|
2037
|
-
info:
|
|
2158
|
+
assets_minted: S4.NullOr(S4.Array(AssetSchema)),
|
|
2159
|
+
metadata: S4.NullOr(S4.Object),
|
|
2160
|
+
certificates: S4.NullOr(
|
|
2161
|
+
S4.Array(
|
|
2162
|
+
S4.Struct({
|
|
2163
|
+
index: S4.Number,
|
|
2164
|
+
type: S4.String,
|
|
2165
|
+
info: S4.NullOr(S4.Object)
|
|
2038
2166
|
})
|
|
2039
2167
|
)
|
|
2040
2168
|
),
|
|
2041
|
-
native_scripts:
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
script_hash:
|
|
2045
|
-
script_json:
|
|
2169
|
+
native_scripts: S4.NullOr(
|
|
2170
|
+
S4.Array(
|
|
2171
|
+
S4.Struct({
|
|
2172
|
+
script_hash: S4.String,
|
|
2173
|
+
script_json: S4.Object
|
|
2046
2174
|
})
|
|
2047
2175
|
)
|
|
2048
2176
|
),
|
|
2049
|
-
plutus_contracts:
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
address:
|
|
2053
|
-
spends_input:
|
|
2054
|
-
|
|
2055
|
-
tx_hash:
|
|
2056
|
-
tx_index:
|
|
2177
|
+
plutus_contracts: S4.NullOr(
|
|
2178
|
+
S4.Array(
|
|
2179
|
+
S4.Struct({
|
|
2180
|
+
address: S4.String,
|
|
2181
|
+
spends_input: S4.NullOr(
|
|
2182
|
+
S4.Struct({
|
|
2183
|
+
tx_hash: S4.String,
|
|
2184
|
+
tx_index: S4.Number
|
|
2057
2185
|
})
|
|
2058
2186
|
),
|
|
2059
|
-
script_hash:
|
|
2060
|
-
bytecode:
|
|
2061
|
-
size:
|
|
2062
|
-
valid_contract:
|
|
2063
|
-
input:
|
|
2064
|
-
redeemer:
|
|
2065
|
-
purpose:
|
|
2066
|
-
fee:
|
|
2067
|
-
unit:
|
|
2068
|
-
steps:
|
|
2069
|
-
mem:
|
|
2187
|
+
script_hash: S4.String,
|
|
2188
|
+
bytecode: S4.String,
|
|
2189
|
+
size: S4.Number,
|
|
2190
|
+
valid_contract: S4.Boolean,
|
|
2191
|
+
input: S4.Struct({
|
|
2192
|
+
redeemer: S4.Struct({
|
|
2193
|
+
purpose: S4.Literal("spend", "mint", "cert", "reward"),
|
|
2194
|
+
fee: S4.String,
|
|
2195
|
+
unit: S4.Struct({
|
|
2196
|
+
steps: S4.String,
|
|
2197
|
+
mem: S4.String
|
|
2070
2198
|
}),
|
|
2071
|
-
datum:
|
|
2072
|
-
hash:
|
|
2073
|
-
value:
|
|
2199
|
+
datum: S4.Struct({
|
|
2200
|
+
hash: S4.NullOr(S4.String),
|
|
2201
|
+
value: S4.NullOr(S4.Object)
|
|
2074
2202
|
})
|
|
2075
2203
|
}),
|
|
2076
|
-
datum:
|
|
2077
|
-
hash:
|
|
2078
|
-
value:
|
|
2204
|
+
datum: S4.Struct({
|
|
2205
|
+
hash: S4.NullOr(S4.String),
|
|
2206
|
+
value: S4.NullOr(S4.Object)
|
|
2079
2207
|
})
|
|
2080
2208
|
})
|
|
2081
2209
|
})
|
|
2082
2210
|
)
|
|
2083
|
-
)
|
|
2211
|
+
),
|
|
2212
|
+
//TODO: add S.Struct
|
|
2213
|
+
// https://preprod.koios.rest/#post-/tx_info
|
|
2214
|
+
voting_procedures: S4.Array(S4.Object),
|
|
2215
|
+
//TODO: add S.Struct
|
|
2216
|
+
// https://preprod.koios.rest/#post-/tx_info
|
|
2217
|
+
proposal_procedures: S4.Object
|
|
2084
2218
|
});
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
// src/fetch.ts
|
|
2091
|
-
var fetch_exports = {};
|
|
2092
|
-
__export(fetch_exports, {
|
|
2093
|
-
FetchError: () => FetchError,
|
|
2094
|
-
JsonError: () => JsonError,
|
|
2095
|
-
ResponseError: () => ResponseError,
|
|
2096
|
-
fetchEffect: () => fetchEffect
|
|
2219
|
+
var TxHashSchema = S4.String;
|
|
2220
|
+
var AssetAddressSchema = S4.Struct({
|
|
2221
|
+
payment_address: S4.String,
|
|
2222
|
+
stake_address: S4.NullOr(S4.String),
|
|
2223
|
+
quantity: S4.String
|
|
2097
2224
|
});
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2225
|
+
var AccountInfoSchema = S4.Struct({
|
|
2226
|
+
delegated_pool: S4.NullOr(S4.String),
|
|
2227
|
+
rewards_available: S4.NumberFromString
|
|
2228
|
+
});
|
|
2229
|
+
var DatumInfo = S4.Struct({
|
|
2230
|
+
bytes: S4.String
|
|
2231
|
+
});
|
|
2232
|
+
var postWithSchemaValidation = (url, data, schema) => pipe3(
|
|
2233
|
+
HttpClientRequest2.post(url),
|
|
2234
|
+
HttpClientRequest2.jsonBody(data),
|
|
2235
|
+
Effect2.flatMap(HttpClient2.fetchOk),
|
|
2236
|
+
HttpClientResponse2.json,
|
|
2237
|
+
Effect2.flatMap(S4.decodeUnknown(schema))
|
|
2238
|
+
// Effect.scoped
|
|
2239
|
+
);
|
|
2240
|
+
var getWithSchemaValidation = (url, schema) => pipe3(
|
|
2241
|
+
HttpClientRequest2.get(url),
|
|
2242
|
+
HttpClient2.fetchOk,
|
|
2243
|
+
HttpClientResponse2.json,
|
|
2244
|
+
Effect2.flatMap(S4.decodeUnknown(schema))
|
|
2245
|
+
);
|
|
2246
|
+
var toUTxO = (koiosUTxO, address) => ({
|
|
2247
|
+
txHash: koiosUTxO.tx_hash,
|
|
2248
|
+
outputIndex: koiosUTxO.tx_index,
|
|
2249
|
+
assets: (() => {
|
|
2250
|
+
const a = {};
|
|
2251
|
+
if (koiosUTxO.asset_list) {
|
|
2252
|
+
koiosUTxO.asset_list.forEach((am) => {
|
|
2253
|
+
a[am.policy_id + am.asset_name] = BigInt(am.quantity);
|
|
2254
|
+
});
|
|
2255
|
+
}
|
|
2256
|
+
a["lovelace"] = BigInt(koiosUTxO.value);
|
|
2257
|
+
return a;
|
|
2258
|
+
})(),
|
|
2259
|
+
address,
|
|
2260
|
+
datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash || void 0,
|
|
2261
|
+
datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
|
|
2262
|
+
scriptRef: toScriptRef2(koiosUTxO.reference_script)
|
|
2263
|
+
});
|
|
2264
|
+
var toScriptRef2 = (reference_script) => {
|
|
2265
|
+
if (reference_script && reference_script.bytes && reference_script.type) {
|
|
2266
|
+
switch (reference_script.type) {
|
|
2267
|
+
case "plutusV1":
|
|
2268
|
+
return {
|
|
2269
|
+
type: "PlutusV1",
|
|
2270
|
+
script: applyDoubleCborEncoding4(reference_script.bytes)
|
|
2271
|
+
};
|
|
2272
|
+
case "plutusV2":
|
|
2273
|
+
return {
|
|
2274
|
+
type: "PlutusV2",
|
|
2275
|
+
script: applyDoubleCborEncoding4(reference_script.bytes)
|
|
2276
|
+
};
|
|
2277
|
+
case "plutusV3":
|
|
2278
|
+
return {
|
|
2279
|
+
type: "PlutusV3",
|
|
2280
|
+
script: applyDoubleCborEncoding4(reference_script.bytes)
|
|
2281
|
+
};
|
|
2282
|
+
default:
|
|
2283
|
+
return void 0;
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2102
2286
|
};
|
|
2103
|
-
var
|
|
2287
|
+
var getUtxosEffect = (baseUrl, addressOrCredential) => {
|
|
2288
|
+
const url = `${baseUrl}/address_info`;
|
|
2289
|
+
const body = {
|
|
2290
|
+
_addresses: [addressOrCredential]
|
|
2291
|
+
};
|
|
2292
|
+
const schema = AddressInfoSchema;
|
|
2293
|
+
const result = pipe3(
|
|
2294
|
+
Effect2.if(typeof addressOrCredential === "string", {
|
|
2295
|
+
onFalse: () => Effect2.fail("Credential Type is not supported in Koios yet."),
|
|
2296
|
+
onTrue: () => postWithSchemaValidation(url, body, schema)
|
|
2297
|
+
}),
|
|
2298
|
+
Effect2.map(
|
|
2299
|
+
([result2]) => result2 ? result2.utxo_set.map((koiosUtxo) => toUTxO(koiosUtxo, result2.address)) : []
|
|
2300
|
+
)
|
|
2301
|
+
);
|
|
2302
|
+
return result;
|
|
2104
2303
|
};
|
|
2105
|
-
var fetchEffect = (input, requestInit) => pipe3(
|
|
2106
|
-
Effect2.tryPromise({
|
|
2107
|
-
try: () => fetch(input, requestInit),
|
|
2108
|
-
catch: (error) => new FetchError({
|
|
2109
|
-
message: `${String(error)}. Please ensure the server is operational or check the validity of the input:${input}.`
|
|
2110
|
-
})
|
|
2111
|
-
}),
|
|
2112
|
-
Effect2.flatMap(
|
|
2113
|
-
(response) => !response.ok ? new ResponseError({
|
|
2114
|
-
message: `${response.status} ${response.statusText}`
|
|
2115
|
-
}) : Effect2.succeed(response)
|
|
2116
|
-
),
|
|
2117
|
-
Effect2.flatMap(
|
|
2118
|
-
(response) => Effect2.tryPromise({
|
|
2119
|
-
try: () => response.json(),
|
|
2120
|
-
catch: (error) => new JsonError({ message: String(error) })
|
|
2121
|
-
})
|
|
2122
|
-
)
|
|
2123
|
-
);
|
|
2124
2304
|
|
|
2125
|
-
// src/koios
|
|
2305
|
+
// src/koios.ts
|
|
2306
|
+
import { Data as Data2, Effect as Effect3, pipe as pipe4, Schedule as Schedule2 } from "effect";
|
|
2307
|
+
var KoiosError = class extends Data2.TaggedError("KoiosError") {
|
|
2308
|
+
get message() {
|
|
2309
|
+
return `${this.cause}`;
|
|
2310
|
+
}
|
|
2311
|
+
};
|
|
2126
2312
|
var Koios = class {
|
|
2127
2313
|
baseUrl;
|
|
2128
2314
|
constructor(baseUrl) {
|
|
2129
2315
|
this.baseUrl = baseUrl;
|
|
2130
2316
|
}
|
|
2131
2317
|
async getProtocolParameters() {
|
|
2132
|
-
const
|
|
2133
|
-
|
|
2318
|
+
const url = `${this.baseUrl}/epoch_params?limit=1`;
|
|
2319
|
+
const schema = S5.Array(ProtocolParametersSchema2);
|
|
2320
|
+
const [result] = await pipe4(
|
|
2321
|
+
getWithSchemaValidation(url, schema),
|
|
2322
|
+
Effect3.timeout(1e4),
|
|
2323
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2324
|
+
Effect3.runPromise
|
|
2134
2325
|
);
|
|
2135
|
-
const param = S4.decodeUnknownSync(ProtocolParametersSchema2)(result[0]);
|
|
2136
2326
|
return {
|
|
2137
|
-
minFeeA:
|
|
2138
|
-
minFeeB:
|
|
2139
|
-
maxTxSize:
|
|
2140
|
-
maxValSize:
|
|
2141
|
-
keyDeposit:
|
|
2142
|
-
poolDeposit:
|
|
2143
|
-
priceMem:
|
|
2144
|
-
priceStep:
|
|
2145
|
-
maxTxExMem:
|
|
2146
|
-
maxTxExSteps:
|
|
2147
|
-
coinsPerUtxoByte:
|
|
2148
|
-
collateralPercentage:
|
|
2149
|
-
maxCollateralInputs:
|
|
2327
|
+
minFeeA: result.min_fee_a,
|
|
2328
|
+
minFeeB: result.min_fee_b,
|
|
2329
|
+
maxTxSize: result.max_tx_size,
|
|
2330
|
+
maxValSize: result.max_val_size,
|
|
2331
|
+
keyDeposit: result.key_deposit,
|
|
2332
|
+
poolDeposit: result.pool_deposit,
|
|
2333
|
+
priceMem: result.price_mem,
|
|
2334
|
+
priceStep: result.price_step,
|
|
2335
|
+
maxTxExMem: result.max_tx_ex_mem,
|
|
2336
|
+
maxTxExSteps: result.max_tx_ex_steps,
|
|
2337
|
+
coinsPerUtxoByte: result.coins_per_utxo_size,
|
|
2338
|
+
collateralPercentage: result.collateral_percent,
|
|
2339
|
+
maxCollateralInputs: result.max_collateral_inputs,
|
|
2150
2340
|
costModels: {
|
|
2151
2341
|
PlutusV1: Object.fromEntries(
|
|
2152
|
-
|
|
2342
|
+
result.cost_models.PlutusV1.map((value, index) => [
|
|
2153
2343
|
index.toString(),
|
|
2154
2344
|
value
|
|
2155
2345
|
])
|
|
2156
2346
|
),
|
|
2157
2347
|
PlutusV2: Object.fromEntries(
|
|
2158
|
-
|
|
2348
|
+
result.cost_models.PlutusV2.map((value, index) => [
|
|
2349
|
+
index.toString(),
|
|
2350
|
+
value
|
|
2351
|
+
])
|
|
2352
|
+
),
|
|
2353
|
+
PlutusV3: Object.fromEntries(
|
|
2354
|
+
result.cost_models.PlutusV3.map((value, index) => [
|
|
2159
2355
|
index.toString(),
|
|
2160
2356
|
value
|
|
2161
2357
|
])
|
|
@@ -2164,101 +2360,94 @@ var Koios = class {
|
|
|
2164
2360
|
};
|
|
2165
2361
|
}
|
|
2166
2362
|
async getUtxos(addressOrCredential) {
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
}
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
"Content-Type": "application/json"
|
|
2175
|
-
},
|
|
2176
|
-
method: "POST",
|
|
2177
|
-
body: JSON.stringify(body)
|
|
2178
|
-
}).then((res) => res.json());
|
|
2179
|
-
const parsedResult = S4.decodeUnknownSync(KoiosAddressInfoSchema)(
|
|
2180
|
-
result
|
|
2181
|
-
)[0];
|
|
2182
|
-
return parsedResult ? parsedResult.utxo_set.map(
|
|
2183
|
-
(koiosUTXO) => toUTxO(koiosUTXO, parsedResult.address)
|
|
2184
|
-
) : [];
|
|
2185
|
-
} else {
|
|
2186
|
-
throw Error("getUtxos by Credential Type is not supported in Koios yet.");
|
|
2187
|
-
}
|
|
2363
|
+
const result = await pipe4(
|
|
2364
|
+
getUtxosEffect(this.baseUrl, addressOrCredential),
|
|
2365
|
+
Effect3.timeout(1e4),
|
|
2366
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2367
|
+
Effect3.runPromise
|
|
2368
|
+
);
|
|
2369
|
+
return result;
|
|
2188
2370
|
}
|
|
2189
2371
|
async getUtxosWithUnit(addressOrCredential, unit) {
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2372
|
+
const result = await pipe4(
|
|
2373
|
+
getUtxosEffect(this.baseUrl, addressOrCredential),
|
|
2374
|
+
Effect3.map(
|
|
2375
|
+
(utxos) => utxos.filter((utxo) => {
|
|
2194
2376
|
const keys = Object.keys(utxo.assets);
|
|
2195
2377
|
return keys.length > 0 && keys.includes(unit);
|
|
2196
|
-
})
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
}
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
);
|
|
2204
|
-
}
|
|
2378
|
+
})
|
|
2379
|
+
),
|
|
2380
|
+
Effect3.timeout(1e4),
|
|
2381
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2382
|
+
Effect3.runPromise
|
|
2383
|
+
);
|
|
2384
|
+
return result;
|
|
2205
2385
|
}
|
|
2206
2386
|
async getUtxoByUnit(unit) {
|
|
2207
|
-
let { policyId, assetName } =
|
|
2208
|
-
|
|
2209
|
-
const
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2387
|
+
let { policyId, assetName } = fromUnit3(unit);
|
|
2388
|
+
const url = `${this.baseUrl}/asset_addresses?_asset_policy=${policyId}&_asset_name=${assetName}`;
|
|
2389
|
+
const result = await pipe4(
|
|
2390
|
+
getWithSchemaValidation(url, S5.Array(AssetAddressSchema)),
|
|
2391
|
+
Effect3.flatMap(
|
|
2392
|
+
(adresses) => adresses.length === 0 ? Effect3.fail("Unit not found") : Effect3.succeed(adresses)
|
|
2393
|
+
),
|
|
2394
|
+
Effect3.flatMap(
|
|
2395
|
+
(adresses) => adresses.length > 1 ? Effect3.fail("Unit needs to be an NFT or only held by one address.") : Effect3.succeed(adresses[0])
|
|
2396
|
+
),
|
|
2397
|
+
Effect3.flatMap(
|
|
2398
|
+
(address) => getUtxosEffect(this.baseUrl, address.payment_address)
|
|
2399
|
+
),
|
|
2400
|
+
Effect3.map(
|
|
2401
|
+
(utxos) => utxos.filter((utxo) => {
|
|
2402
|
+
const keys = Object.keys(utxo.assets);
|
|
2403
|
+
return keys.length > 0 && keys.includes(unit);
|
|
2404
|
+
})
|
|
2405
|
+
),
|
|
2406
|
+
Effect3.flatMap(
|
|
2407
|
+
(utxos) => utxos.length > 1 ? Effect3.fail("Unit needs to be an NFT or only held by one address.") : Effect3.succeed(utxos[0])
|
|
2408
|
+
),
|
|
2409
|
+
Effect3.timeout(1e4),
|
|
2410
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2411
|
+
Effect3.runPromise
|
|
2412
|
+
);
|
|
2413
|
+
return result;
|
|
2228
2414
|
}
|
|
2229
2415
|
async getUtxosByOutRef(outRefs) {
|
|
2230
|
-
const
|
|
2416
|
+
const url = `${this.baseUrl}/tx_info`;
|
|
2231
2417
|
const body = {
|
|
2232
|
-
_tx_hashes: [...new Set(outRefs.map((outRef) => outRef.txHash))]
|
|
2418
|
+
_tx_hashes: [...new Set(outRefs.map((outRef) => outRef.txHash))],
|
|
2419
|
+
_assets: true,
|
|
2420
|
+
_scripts: true
|
|
2233
2421
|
};
|
|
2234
|
-
const
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
},
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
result
|
|
2244
|
-
)[0];
|
|
2245
|
-
if (parsedResult) {
|
|
2246
|
-
return parsedResult.outputs.map(
|
|
2422
|
+
const schema = S5.Array(TxInfoSchema);
|
|
2423
|
+
const [result] = await pipe4(
|
|
2424
|
+
postWithSchemaValidation(url, body, schema),
|
|
2425
|
+
Effect3.timeout(1e4),
|
|
2426
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2427
|
+
Effect3.runPromise
|
|
2428
|
+
);
|
|
2429
|
+
if (result) {
|
|
2430
|
+
const utxos = result.outputs.map(
|
|
2247
2431
|
(koiosInputOutput) => toUTxO(
|
|
2248
2432
|
{
|
|
2249
2433
|
tx_hash: koiosInputOutput.tx_hash,
|
|
2250
2434
|
tx_index: koiosInputOutput.tx_index,
|
|
2251
|
-
|
|
2435
|
+
block_time: 0,
|
|
2436
|
+
block_height: result.block_height,
|
|
2252
2437
|
value: koiosInputOutput.value,
|
|
2253
2438
|
datum_hash: koiosInputOutput.datum_hash,
|
|
2254
2439
|
inline_datum: koiosInputOutput.inline_datum,
|
|
2255
2440
|
reference_script: koiosInputOutput.reference_script,
|
|
2256
|
-
|
|
2257
|
-
asset_list: typeof koiosInputOutput.asset_list === "string" ? [] : koiosInputOutput.asset_list
|
|
2441
|
+
asset_list: koiosInputOutput.asset_list
|
|
2258
2442
|
},
|
|
2259
2443
|
koiosInputOutput.payment_addr.bech32
|
|
2260
2444
|
)
|
|
2261
2445
|
);
|
|
2446
|
+
return utxos.filter(
|
|
2447
|
+
(utxo) => outRefs.some(
|
|
2448
|
+
(outRef) => utxo.txHash === outRef.txHash && utxo.outputIndex === outRef.outputIndex
|
|
2449
|
+
)
|
|
2450
|
+
);
|
|
2262
2451
|
} else {
|
|
2263
2452
|
return [];
|
|
2264
2453
|
}
|
|
@@ -2267,135 +2456,94 @@ var Koios = class {
|
|
|
2267
2456
|
const body = {
|
|
2268
2457
|
_stake_addresses: [rewardAddress]
|
|
2269
2458
|
};
|
|
2270
|
-
const
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2459
|
+
const url = `${this.baseUrl}/account_info`;
|
|
2460
|
+
const result = await pipe4(
|
|
2461
|
+
postWithSchemaValidation(
|
|
2462
|
+
url,
|
|
2463
|
+
body,
|
|
2464
|
+
S5.Array(AccountInfoSchema)
|
|
2465
|
+
),
|
|
2466
|
+
Effect3.flatMap(
|
|
2467
|
+
(result2) => result2.length === 0 ? Effect3.fail("No Delegation Found by Reward Address") : Effect3.succeed(result2[0])
|
|
2468
|
+
),
|
|
2469
|
+
Effect3.timeout(1e4),
|
|
2470
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2471
|
+
Effect3.runPromise
|
|
2472
|
+
);
|
|
2473
|
+
return {
|
|
2474
|
+
poolId: result.delegated_pool || null,
|
|
2475
|
+
rewards: BigInt(result.rewards_available)
|
|
2476
|
+
};
|
|
2286
2477
|
}
|
|
2287
2478
|
async getDatum(datumHash) {
|
|
2479
|
+
const url = `${this.baseUrl}/datum_info`;
|
|
2288
2480
|
const body = {
|
|
2289
2481
|
_datum_hashes: [datumHash]
|
|
2290
2482
|
};
|
|
2291
|
-
const
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
"
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
} else {
|
|
2302
|
-
throw new Error("No Datum Found by Datum Hash");
|
|
2303
|
-
}
|
|
2483
|
+
const result = await pipe4(
|
|
2484
|
+
postWithSchemaValidation(url, body, S5.Array(DatumInfo)),
|
|
2485
|
+
Effect3.flatMap(
|
|
2486
|
+
(result2) => result2.length === 0 ? Effect3.fail("No Datum Found by Datum Hash") : Effect3.succeed(result2[0])
|
|
2487
|
+
),
|
|
2488
|
+
Effect3.timeout(1e4),
|
|
2489
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2490
|
+
Effect3.runPromise
|
|
2491
|
+
);
|
|
2492
|
+
return result.bytes;
|
|
2304
2493
|
}
|
|
2305
2494
|
async awaitTx(txHash, checkInterval = 2e4) {
|
|
2495
|
+
const url = `${this.baseUrl}/tx_info`;
|
|
2306
2496
|
const body = {
|
|
2307
2497
|
_tx_hashes: [txHash]
|
|
2308
2498
|
};
|
|
2309
|
-
const
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
"Content-Type": "application/json"
|
|
2313
|
-
},
|
|
2314
|
-
method: "POST",
|
|
2315
|
-
body: JSON.stringify(body)
|
|
2316
|
-
};
|
|
2317
|
-
const program = pipe4(
|
|
2318
|
-
fetchEffect(`${this.baseUrl}/tx_info`, request),
|
|
2319
|
-
Effect3.flatMap(
|
|
2320
|
-
(json) => S4.decodeUnknown(S4.Array(KoiosTxInfoSchema))(json)
|
|
2321
|
-
),
|
|
2322
|
-
Effect3.catchTag(
|
|
2323
|
-
"ParseError",
|
|
2324
|
-
(e) => Effect3.fail(ArrayFormatter.formatErrorSync(e))
|
|
2325
|
-
),
|
|
2499
|
+
const schema = S5.Array(TxInfoSchema);
|
|
2500
|
+
const result = await pipe4(
|
|
2501
|
+
postWithSchemaValidation(url, body, schema),
|
|
2326
2502
|
Effect3.repeat({
|
|
2327
2503
|
schedule: Schedule2.exponential(checkInterval),
|
|
2328
|
-
until: (
|
|
2504
|
+
until: (result2) => result2.length > 0
|
|
2329
2505
|
}),
|
|
2330
2506
|
Effect3.timeout(16e4),
|
|
2331
2507
|
Effect3.orDie,
|
|
2332
|
-
Effect3.as(true)
|
|
2508
|
+
Effect3.as(true),
|
|
2509
|
+
Effect3.runPromise
|
|
2333
2510
|
);
|
|
2334
|
-
return
|
|
2511
|
+
return result;
|
|
2335
2512
|
}
|
|
2336
2513
|
async submitTx(tx) {
|
|
2337
|
-
const
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
const isTxHash = S4.is(TxHashSchema);
|
|
2347
|
-
if (!isTxHash(result)) {
|
|
2348
|
-
throw new Error(JSON.stringify(result));
|
|
2349
|
-
}
|
|
2514
|
+
const url = `${this.baseUrl}/submittx`;
|
|
2515
|
+
const body = fromHex4(tx);
|
|
2516
|
+
const schema = TxHashSchema;
|
|
2517
|
+
const result = await pipe4(
|
|
2518
|
+
postWithSchemaValidation(url, body, schema),
|
|
2519
|
+
Effect3.timeout(1e4),
|
|
2520
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2521
|
+
Effect3.runPromise
|
|
2522
|
+
);
|
|
2350
2523
|
return result;
|
|
2351
2524
|
}
|
|
2352
2525
|
async evaluateTx(tx, additionalUTxOs) {
|
|
2353
|
-
const
|
|
2354
|
-
|
|
2355
|
-
language: utxo.scriptRef.type,
|
|
2356
|
-
cbor: utxo.scriptRef.script
|
|
2357
|
-
} : void 0;
|
|
2358
|
-
return [
|
|
2359
|
-
{
|
|
2360
|
-
transaction: { id: utxo.txHash, output: { index: utxo.outputIndex } }
|
|
2361
|
-
},
|
|
2362
|
-
{
|
|
2363
|
-
address: utxo.address,
|
|
2364
|
-
value: {
|
|
2365
|
-
coins: utxo.assets.lovelace,
|
|
2366
|
-
assets: utxo.assets.restAssets
|
|
2367
|
-
},
|
|
2368
|
-
datumHash: utxo.datumHash,
|
|
2369
|
-
datum: utxo.datum,
|
|
2370
|
-
script
|
|
2371
|
-
}
|
|
2372
|
-
];
|
|
2373
|
-
});
|
|
2374
|
-
const data = {
|
|
2526
|
+
const url = `${this.baseUrl}/ogmios`;
|
|
2527
|
+
const body = {
|
|
2375
2528
|
jsonrpc: "2.0",
|
|
2376
2529
|
method: "evaluateTransaction",
|
|
2377
|
-
params: {
|
|
2530
|
+
params: {
|
|
2531
|
+
transaction: { cbor: tx },
|
|
2532
|
+
additionalUtxo: toOgmiosUTxOs(additionalUTxOs)
|
|
2533
|
+
},
|
|
2378
2534
|
id: null
|
|
2379
2535
|
};
|
|
2380
|
-
const
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
if (!response.ok) {
|
|
2392
|
-
const errorBody = await response.text();
|
|
2393
|
-
throw new Error(
|
|
2394
|
-
`Request failed with status ${response.status}: ${errorBody}`
|
|
2395
|
-
);
|
|
2396
|
-
}
|
|
2397
|
-
const result = await response.json();
|
|
2398
|
-
const evalRedeemers = result.result.map((item) => ({
|
|
2536
|
+
const schema = JSONRPCSchema(S5.Array(RedeemerSchema));
|
|
2537
|
+
const result = await pipe4(
|
|
2538
|
+
postWithSchemaValidation(url, body, schema),
|
|
2539
|
+
Effect3.flatMap(
|
|
2540
|
+
(response) => "error" in response ? Effect3.fail(response) : Effect3.succeed(response.result)
|
|
2541
|
+
),
|
|
2542
|
+
Effect3.timeout(1e4),
|
|
2543
|
+
Effect3.catchAllCause((cause) => new KoiosError({ cause })),
|
|
2544
|
+
Effect3.runPromise
|
|
2545
|
+
);
|
|
2546
|
+
const evalRedeemers = result.map((item) => ({
|
|
2399
2547
|
ex_units: {
|
|
2400
2548
|
mem: item.budget.memory,
|
|
2401
2549
|
steps: item.budget.cpu
|
|
@@ -2406,38 +2554,13 @@ var Koios = class {
|
|
|
2406
2554
|
return evalRedeemers;
|
|
2407
2555
|
}
|
|
2408
2556
|
};
|
|
2409
|
-
var toUTxO = (koiosUTxO, address) => ({
|
|
2410
|
-
txHash: koiosUTxO.tx_hash,
|
|
2411
|
-
outputIndex: koiosUTxO.tx_index,
|
|
2412
|
-
assets: (() => {
|
|
2413
|
-
const a = {};
|
|
2414
|
-
if (koiosUTxO.asset_list) {
|
|
2415
|
-
koiosUTxO.asset_list.forEach((am) => {
|
|
2416
|
-
a[am.policy_id + am.asset_name] = BigInt(am.quantity);
|
|
2417
|
-
});
|
|
2418
|
-
}
|
|
2419
|
-
a["lovelace"] = BigInt(koiosUTxO.value);
|
|
2420
|
-
return a;
|
|
2421
|
-
})(),
|
|
2422
|
-
address,
|
|
2423
|
-
datumHash: koiosUTxO.inline_datum ? void 0 : koiosUTxO.datum_hash,
|
|
2424
|
-
datum: koiosUTxO.inline_datum ? koiosUTxO.inline_datum.bytes : void 0,
|
|
2425
|
-
scriptRef: koiosUTxO.reference_script ? koiosUTxO.reference_script.type == "plutusV1" ? {
|
|
2426
|
-
type: "PlutusV1",
|
|
2427
|
-
script: applyDoubleCborEncoding4(koiosUTxO.reference_script.bytes)
|
|
2428
|
-
} : {
|
|
2429
|
-
type: "PlutusV2",
|
|
2430
|
-
script: applyDoubleCborEncoding4(koiosUTxO.reference_script.bytes)
|
|
2431
|
-
} : void 0
|
|
2432
|
-
});
|
|
2433
2557
|
export {
|
|
2434
2558
|
Blockfrost,
|
|
2435
2559
|
Emulator,
|
|
2436
|
-
fetch_exports as FetchProvider,
|
|
2437
2560
|
Koios,
|
|
2561
|
+
KoiosError,
|
|
2438
2562
|
Kupmios,
|
|
2439
2563
|
KupmiosError,
|
|
2440
2564
|
Maestro,
|
|
2441
|
-
datumJsonToCbor,
|
|
2442
2565
|
generateEmulatorAccount
|
|
2443
2566
|
};
|