@indigo-labs/indigo-sdk 0.1.28 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/.github/workflows/ci.yml +8 -3
  2. package/dist/index.d.mts +1300 -671
  3. package/dist/index.d.ts +1300 -671
  4. package/dist/index.js +4663 -2220
  5. package/dist/index.mjs +4594 -2190
  6. package/eslint.config.mjs +7 -1
  7. package/package.json +9 -4
  8. package/src/contracts/cdp/helpers.ts +167 -0
  9. package/src/contracts/cdp/scripts.ts +33 -0
  10. package/src/contracts/cdp/transactions.ts +1310 -0
  11. package/src/contracts/cdp/types.ts +161 -0
  12. package/src/contracts/cdp-creator/scripts.ts +39 -0
  13. package/src/{types/indigo/cdp-creator.ts → contracts/cdp-creator/types.ts} +6 -4
  14. package/src/contracts/collector/scripts.ts +32 -0
  15. package/src/contracts/collector/transactions.ts +44 -0
  16. package/src/contracts/execute/scripts.ts +48 -0
  17. package/src/contracts/execute/types.ts +57 -0
  18. package/src/contracts/gov/helpers.ts +157 -0
  19. package/src/contracts/gov/scripts.ts +34 -0
  20. package/src/contracts/gov/transactions.ts +1224 -0
  21. package/src/contracts/gov/types-new.ts +115 -0
  22. package/src/contracts/gov/types.ts +89 -0
  23. package/src/{helpers/interest-oracle.ts → contracts/interest-oracle/helpers.ts} +37 -9
  24. package/src/contracts/interest-oracle/scripts.ts +18 -0
  25. package/src/contracts/interest-oracle/transactions.ts +149 -0
  26. package/src/{types/indigo/interest-oracle.ts → contracts/interest-oracle/types.ts} +1 -1
  27. package/src/contracts/lrp/scripts.ts +27 -0
  28. package/src/contracts/{lrp.ts → lrp/transactions.ts} +14 -14
  29. package/src/{types/indigo/lrp.ts → contracts/lrp/types.ts} +2 -2
  30. package/src/{scripts/one-shot-policy.ts → contracts/one-shot/scripts.ts} +1 -1
  31. package/src/contracts/{one-shot.ts → one-shot/transactions.ts} +3 -3
  32. package/src/contracts/poll/helpers.ts +55 -0
  33. package/src/contracts/poll/scripts.ts +72 -0
  34. package/src/contracts/poll/types-poll-manager.ts +38 -0
  35. package/src/contracts/poll/types-poll-shard.ts +38 -0
  36. package/src/contracts/poll/types-poll.ts +88 -0
  37. package/src/{scripts/price-oracle-validator.ts → contracts/price-oracle/scripts.ts} +1 -4
  38. package/src/contracts/price-oracle/transactions.ts +112 -0
  39. package/src/{types/indigo/price-oracle.ts → contracts/price-oracle/types.ts} +16 -4
  40. package/src/{helpers/stability-pool-helpers.ts → contracts/stability-pool/helpers.ts} +110 -6
  41. package/src/contracts/stability-pool/scripts.ts +46 -0
  42. package/src/contracts/stability-pool/transactions.ts +676 -0
  43. package/src/contracts/stability-pool/types-new.ts +208 -0
  44. package/src/contracts/stability-pool/types.ts +42 -0
  45. package/src/contracts/staking/helpers.ts +116 -0
  46. package/src/contracts/staking/scripts.ts +41 -0
  47. package/src/contracts/staking/transactions.ts +268 -0
  48. package/src/contracts/staking/types-new.ts +81 -0
  49. package/src/contracts/staking/types.ts +41 -0
  50. package/src/contracts/treasury/scripts.ts +37 -0
  51. package/src/contracts/treasury/transactions.ts +44 -0
  52. package/src/contracts/treasury/types.ts +55 -0
  53. package/src/contracts/version-registry/scripts.ts +29 -0
  54. package/src/contracts/version-registry/types-new.ts +19 -0
  55. package/src/{types/indigo/version-record.ts → contracts/version-registry/types.ts} +1 -1
  56. package/src/contracts/vesting/helpers.ts +267 -0
  57. package/src/index.ts +39 -33
  58. package/src/types/evolution-schema-options.ts +16 -0
  59. package/src/types/generic.ts +78 -60
  60. package/src/types/on-chain-decimal.ts +22 -0
  61. package/src/types/system-params.ts +22 -11
  62. package/src/utils/bigint-utils.ts +7 -0
  63. package/src/{helpers → utils}/helper-txs.ts +1 -0
  64. package/src/utils/time-helpers.ts +4 -0
  65. package/src/{helpers/helpers.ts → utils/utils.ts} +0 -10
  66. package/src/{helpers → utils}/value-helpers.ts +10 -0
  67. package/src/{scripts → validators}/cdp-creator-validator.ts +4 -50
  68. package/src/{scripts → validators}/cdp-validator.ts +3 -5
  69. package/src/{scripts → validators}/collector-validator.ts +2 -3
  70. package/src/{scripts/version-registry.ts → validators/execute-validator.ts} +3 -11
  71. package/src/{scripts/gov-validator.ts → validators/governance-validator.ts} +3 -40
  72. package/src/{scripts → validators}/interest-oracle-validator.ts +4 -20
  73. package/src/validators/lrp-validator.ts +7 -0
  74. package/src/validators/poll-manager-validator.ts +7 -0
  75. package/src/{scripts → validators}/poll-shard-validator.ts +3 -43
  76. package/src/{scripts → validators}/stability-pool-validator.ts +4 -57
  77. package/src/{scripts → validators}/staking-validator.ts +2 -3
  78. package/src/{scripts → validators}/treasury-validator.ts +2 -3
  79. package/src/{scripts → validators}/version-record-policy.ts +4 -23
  80. package/src/validators/version-registry-validator.ts +7 -0
  81. package/tests/cdp.test.ts +1565 -0
  82. package/tests/datums.test.ts +125 -108
  83. package/tests/endpoints/initialize.ts +240 -338
  84. package/tests/gov.test.ts +1874 -0
  85. package/tests/hash-checks.test.ts +26 -21
  86. package/tests/indigo-test-helpers.ts +1 -55
  87. package/tests/initialize.test.ts +10 -5
  88. package/tests/interest-calculations.test.ts +18 -18
  89. package/tests/interest-oracle.test.ts +20 -18
  90. package/tests/lrp.test.ts +191 -65
  91. package/tests/mock/assets-mock.ts +59 -0
  92. package/tests/queries/cdp-queries.ts +144 -0
  93. package/tests/queries/collector-queries.ts +26 -0
  94. package/tests/queries/execute-queries.ts +46 -0
  95. package/tests/queries/governance-queries.ts +19 -16
  96. package/tests/queries/iasset-queries.ts +46 -23
  97. package/tests/queries/interest-oracle-queries.ts +3 -6
  98. package/tests/queries/lrp-queries.ts +2 -2
  99. package/tests/queries/poll-queries.ts +97 -0
  100. package/tests/queries/price-oracle-queries.ts +5 -22
  101. package/tests/queries/stability-pool-queries.ts +10 -8
  102. package/tests/queries/staking-queries.ts +28 -19
  103. package/tests/queries/treasury-queries.ts +19 -0
  104. package/tests/stability-pool.test.ts +186 -71
  105. package/tests/staking.test.ts +30 -23
  106. package/tests/test-helpers.ts +11 -2
  107. package/tests/utils/asserts.ts +13 -0
  108. package/tests/utils/index.ts +50 -0
  109. package/tsconfig.json +3 -1
  110. package/vitest.config.ts +1 -1
  111. package/.github/workflows/test.yml +0 -44
  112. package/src/contracts/cdp.ts +0 -752
  113. package/src/contracts/collector.ts +0 -98
  114. package/src/contracts/gov.ts +0 -1
  115. package/src/contracts/interest-oracle.ts +0 -149
  116. package/src/contracts/stability-pool.ts +0 -690
  117. package/src/contracts/staking.ts +0 -348
  118. package/src/contracts/treasury.ts +0 -112
  119. package/src/helpers/asset-helpers.ts +0 -62
  120. package/src/helpers/staking-helpers.ts +0 -94
  121. package/src/helpers/time-helpers.ts +0 -4
  122. package/src/scripts/execute-validator.ts +0 -52
  123. package/src/scripts/lrp-validator.ts +0 -40
  124. package/src/scripts/poll-manager-validator.ts +0 -52
  125. package/src/types/indigo/cdp.ts +0 -88
  126. package/src/types/indigo/execute.ts +0 -21
  127. package/src/types/indigo/gov.ts +0 -51
  128. package/src/types/indigo/poll-manager.ts +0 -21
  129. package/src/types/indigo/poll-shard.ts +0 -16
  130. package/src/types/indigo/stability-pool.ts +0 -233
  131. package/src/types/indigo/staking.ts +0 -99
  132. /package/src/{types/one-shot.ts → contracts/one-shot/types.ts} +0 -0
  133. /package/src/{helpers/price-oracle-helpers.ts → contracts/price-oracle/helpers.ts} +0 -0
  134. /package/src/{helpers → utils}/indigo-helpers.ts +0 -0
  135. /package/src/{helpers → utils}/lucid-utils.ts +0 -0
@@ -1,39 +1,62 @@
1
- import {
2
- fromText,
3
- LucidEvolution,
4
- ScriptHash,
5
- UTxO,
6
- } from '@lucid-evolution/lucid';
7
- import { createScriptAddress } from '../../src/helpers/lucid-utils';
1
+ import { fromText, LucidEvolution, ScriptHash } from '@lucid-evolution/lucid';
2
+ import { createScriptAddress } from '../../src/utils/lucid-utils';
8
3
  import { AssetClass } from '../../src/types/generic';
9
- import { assetClassToUnit } from '../../src/helpers/value-helpers';
10
- import { matchSingle, parseIAssetDatum } from '../../src';
4
+ import { assetClassToUnit } from '../../src/utils/value-helpers';
5
+ import { IAssetOutput, matchSingle, parseIAssetDatum } from '../../src';
6
+ import { option as O, array as A, function as F } from 'fp-ts';
11
7
 
12
8
  export async function findIAsset(
13
9
  lucid: LucidEvolution,
14
10
  iassetScriptHash: ScriptHash,
15
11
  iassetNft: AssetClass,
12
+ // Ascii encoded
16
13
  iassetName: string,
17
- ): Promise<UTxO> {
14
+ ): Promise<IAssetOutput> {
18
15
  const iassetUtxos = await lucid.utxosAtWithUnit(
19
- createScriptAddress(lucid.config().network, iassetScriptHash),
16
+ createScriptAddress(lucid.config().network!, iassetScriptHash),
20
17
  assetClassToUnit(iassetNft),
21
18
  );
22
19
 
23
20
  return matchSingle(
24
- iassetUtxos.filter((utxo) => {
25
- if (utxo.datum != null) {
26
- try {
27
- const iassetDatum = parseIAssetDatum(utxo.datum);
28
-
29
- return iassetDatum.assetName == fromText(iassetName);
30
- } catch (_) {
31
- // when incompatible datum
32
- return false;
33
- }
34
- }
35
- }),
21
+ F.pipe(
22
+ iassetUtxos.map((utxo) =>
23
+ F.pipe(
24
+ O.fromNullable(utxo.datum),
25
+ O.flatMap(parseIAssetDatum),
26
+ O.flatMap((datum) => {
27
+ if (datum.assetName === fromText(iassetName)) {
28
+ return O.some({ utxo, datum: datum });
29
+ } else {
30
+ return O.none;
31
+ }
32
+ }),
33
+ ),
34
+ ),
35
+ A.compact,
36
+ ),
36
37
  (res) =>
37
38
  new Error('Expected a single IAsset UTXO.: ' + JSON.stringify(res)),
38
39
  );
39
40
  }
41
+
42
+ export async function findAllIAssets(
43
+ lucid: LucidEvolution,
44
+ iassetScriptHash: ScriptHash,
45
+ iassetNft: AssetClass,
46
+ ): Promise<IAssetOutput[]> {
47
+ const iassetUtxos = await lucid.utxosAtWithUnit(
48
+ createScriptAddress(lucid.config().network!, iassetScriptHash),
49
+ assetClassToUnit(iassetNft),
50
+ );
51
+
52
+ return F.pipe(
53
+ iassetUtxos.map((utxo) =>
54
+ F.pipe(
55
+ O.fromNullable(utxo.datum),
56
+ O.flatMap(parseIAssetDatum),
57
+ O.map((datum) => ({ utxo, datum: datum })),
58
+ ),
59
+ ),
60
+ A.compact,
61
+ );
62
+ }
@@ -1,13 +1,10 @@
1
1
  import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
2
2
  import { AssetClass } from '../../src/types/generic';
3
- import { assetClassToUnit } from '../../src/helpers/value-helpers';
4
- import { InterestOracleDatum, parseInterestOracleDatum } from '../../src';
3
+ import { assetClassToUnit } from '../../src/utils/value-helpers';
5
4
 
6
5
  export async function findInterestOracle(
7
6
  lucid: LucidEvolution,
8
7
  interestNft: AssetClass,
9
- ): Promise<[UTxO, InterestOracleDatum]> {
10
- const interestUtxo = await lucid.utxoByUnit(assetClassToUnit(interestNft));
11
- if (!interestUtxo.datum) throw new Error('No interest oracle utxo found');
12
- return [interestUtxo, parseInterestOracleDatum(interestUtxo.datum)];
8
+ ): Promise<UTxO> {
9
+ return lucid.utxoByUnit(assetClassToUnit(interestNft));
13
10
  }
@@ -5,8 +5,8 @@ import {
5
5
  ScriptHash,
6
6
  UTxO,
7
7
  } from '@lucid-evolution/lucid';
8
- import { createScriptAddress } from '../../src/helpers/lucid-utils';
9
- import { parseLrpDatum } from '../../src/types/indigo/lrp';
8
+ import { createScriptAddress } from '../../src/utils/lucid-utils';
9
+ import { parseLrpDatum } from '../../src/contracts/lrp/types';
10
10
 
11
11
  /**
12
12
  * Beware, this shouldn't be used in production since it queries all the UTXOs
@@ -0,0 +1,97 @@
1
+ import { LucidEvolution, ScriptHash, UTxO } from '@lucid-evolution/lucid';
2
+ import {
3
+ parsePollManager,
4
+ parsePollShard,
5
+ PollManagerContent,
6
+ PollShardContent,
7
+ } from '../../src/contracts/poll/types-poll';
8
+ import {
9
+ AssetClass,
10
+ matchSingle,
11
+ createScriptAddress,
12
+ getRandomElement,
13
+ } from '../../src';
14
+ import { assetClassToUnit } from '../../src/utils/value-helpers';
15
+ import { option as O, array as A, function as F } from 'fp-ts';
16
+
17
+ export async function findPollManager(
18
+ lucid: LucidEvolution,
19
+ pollManagerScriptHash: ScriptHash,
20
+ pollManagerNft: AssetClass,
21
+ pollId: bigint,
22
+ ): Promise<{ utxo: UTxO; datum: PollManagerContent }> {
23
+ const pollManagerUtxos = await lucid.utxosAtWithUnit(
24
+ createScriptAddress(lucid.config().network!, pollManagerScriptHash),
25
+ assetClassToUnit(pollManagerNft),
26
+ );
27
+
28
+ return matchSingle(
29
+ F.pipe(
30
+ pollManagerUtxos.map((utxo) =>
31
+ F.pipe(
32
+ O.fromNullable(utxo.datum),
33
+ O.flatMap(parsePollManager),
34
+ O.flatMap((datum) => {
35
+ if (datum.pollId === pollId) {
36
+ return O.some({ utxo, datum: datum });
37
+ } else {
38
+ return O.none;
39
+ }
40
+ }),
41
+ ),
42
+ ),
43
+ A.compact,
44
+ ),
45
+ (res) => new Error('Expected a single Gov UTXO.: ' + JSON.stringify(res)),
46
+ );
47
+ }
48
+
49
+ export async function findAllPollShards(
50
+ lucid: LucidEvolution,
51
+ pollShardScriptHash: string,
52
+ pollShardNft: AssetClass,
53
+ pollId: bigint,
54
+ ): Promise<{ utxo: UTxO; datum: PollShardContent }[]> {
55
+ const pollShardUtxos = await lucid.utxosAtWithUnit(
56
+ createScriptAddress(lucid.config().network!, pollShardScriptHash),
57
+ assetClassToUnit(pollShardNft),
58
+ );
59
+
60
+ return F.pipe(
61
+ pollShardUtxos.map((utxo) =>
62
+ F.pipe(
63
+ O.fromNullable(utxo.datum),
64
+ O.flatMap(parsePollShard),
65
+ O.flatMap((datum) => {
66
+ if (datum.pollId === pollId) {
67
+ return O.some({ utxo, datum: datum });
68
+ } else {
69
+ return O.none;
70
+ }
71
+ }),
72
+ ),
73
+ ),
74
+ A.compact,
75
+ );
76
+ }
77
+
78
+ export async function findRandomPollShard(
79
+ lucid: LucidEvolution,
80
+ pollShardScriptHash: string,
81
+ pollShardNft: AssetClass,
82
+ pollId: bigint,
83
+ ): Promise<{ utxo: UTxO; datum: PollShardContent }> {
84
+ const pollShardOuts = await findAllPollShards(
85
+ lucid,
86
+ pollShardScriptHash,
87
+ pollShardNft,
88
+ pollId,
89
+ );
90
+
91
+ return F.pipe(
92
+ O.fromNullable(getRandomElement(pollShardOuts)),
93
+ O.match(() => {
94
+ throw new Error('Expected some poll shard UTXOs.');
95
+ }, F.identity),
96
+ );
97
+ }
@@ -1,27 +1,10 @@
1
- import {
2
- LucidEvolution,
3
- Network,
4
- OutRef,
5
- ScriptHash,
6
- toUnit,
7
- } from '@lucid-evolution/lucid';
8
- import { createScriptAddress, matchSingle, OracleAssetNft } from '../../src';
1
+ import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
2
+ import { OracleAssetNft } from '../../src';
3
+ import { assetClassToUnit } from '../../src/utils/value-helpers';
9
4
 
10
5
  export async function findPriceOracle(
11
6
  lucid: LucidEvolution,
12
- network: Network,
13
- oracleScriptHash: ScriptHash,
14
7
  oracleNft: OracleAssetNft,
15
- ): Promise<OutRef> {
16
- return matchSingle(
17
- await lucid.utxosAtWithUnit(
18
- createScriptAddress(network, oracleScriptHash),
19
- toUnit(
20
- oracleNft.oracleNft.asset.currencySymbol,
21
- oracleNft.oracleNft.asset.tokenName,
22
- ),
23
- ),
24
- (res) =>
25
- new Error('Expected a single Oracle UTXO.: ' + JSON.stringify(res)),
26
- );
8
+ ): Promise<UTxO> {
9
+ return lucid.utxoByUnit(assetClassToUnit(oracleNft.oracleNft));
27
10
  }
@@ -2,16 +2,17 @@ import {
2
2
  fromText,
3
3
  LucidEvolution,
4
4
  ScriptHash,
5
+ toHex,
5
6
  UTxO,
6
7
  } from '@lucid-evolution/lucid';
7
- import { createScriptAddress } from '../../src/helpers/lucid-utils';
8
+ import { createScriptAddress } from '../../src/utils/lucid-utils';
8
9
  import { AssetClass } from '../../src/types/generic';
9
- import { assetClassToUnit } from '../../src/helpers/value-helpers';
10
+ import { assetClassToUnit } from '../../src/utils/value-helpers';
11
+ import { matchSingle } from '../../src';
10
12
  import {
11
- matchSingle,
12
13
  parseAccountDatum,
13
14
  parseStabilityPoolDatum,
14
- } from '../../src';
15
+ } from '../../src/contracts/stability-pool/types-new';
15
16
 
16
17
  export async function findStabilityPool(
17
18
  lucid: LucidEvolution,
@@ -20,7 +21,7 @@ export async function findStabilityPool(
20
21
  asset: string,
21
22
  ): Promise<UTxO> {
22
23
  const stakingUtxos = await lucid.utxosAtWithUnit(
23
- createScriptAddress(lucid.config().network, stabilityPoolHash),
24
+ createScriptAddress(lucid.config().network!, stabilityPoolHash),
24
25
  assetClassToUnit(stabilityPoolToken),
25
26
  );
26
27
 
@@ -30,7 +31,7 @@ export async function findStabilityPool(
30
31
  try {
31
32
  const stabilityPoolDatum = parseStabilityPoolDatum(utxo.datum);
32
33
 
33
- return stabilityPoolDatum.asset == fromText(asset);
34
+ return toHex(stabilityPoolDatum.asset) == fromText(asset);
34
35
  } catch (_) {
35
36
  // when incompatible datum
36
37
  return false;
@@ -51,7 +52,7 @@ export async function findStabilityPoolAccount(
51
52
  asset: string,
52
53
  ): Promise<UTxO> {
53
54
  const accountUtxos = await lucid.utxosAt(
54
- createScriptAddress(lucid.config().network, stabilityPoolHash),
55
+ createScriptAddress(lucid.config().network!, stabilityPoolHash),
55
56
  );
56
57
 
57
58
  return matchSingle(
@@ -61,7 +62,8 @@ export async function findStabilityPoolAccount(
61
62
  const accountDatum = parseAccountDatum(utxo.datum);
62
63
 
63
64
  return (
64
- accountDatum.asset == fromText(asset) && accountDatum.owner == owner
65
+ toHex(accountDatum.asset) == fromText(asset) &&
66
+ toHex(accountDatum.owner) == owner
65
67
  );
66
68
  } catch (_) {
67
69
  // when incompatible datum
@@ -1,40 +1,49 @@
1
1
  import {
2
2
  LucidEvolution,
3
- Network,
4
- OutRef,
5
3
  ScriptHash,
4
+ toHex,
5
+ UTxO,
6
6
  } from '@lucid-evolution/lucid';
7
- import { createScriptAddress } from '../../src/helpers/lucid-utils';
7
+ import { createScriptAddress } from '../../src/utils/lucid-utils';
8
8
  import { AssetClass } from '../../src/types/generic';
9
- import { assetClassToUnit } from '../../src/helpers/value-helpers';
9
+ import { assetClassToUnit } from '../../src/utils/value-helpers';
10
10
  import { matchSingle } from '../../src';
11
- import { parseStakingPositionDatum } from '../../src/types/indigo/staking';
11
+ import { option as O, array as A, function as F } from 'fp-ts';
12
+ import {
13
+ parseStakingPosition,
14
+ StakingPosition,
15
+ } from '../../src/contracts/staking/types-new';
12
16
 
13
17
  export async function findStakingPosition(
14
18
  lucid: LucidEvolution,
15
- network: Network,
16
19
  stakingScriptHash: ScriptHash,
17
20
  stakingPositionNft: AssetClass,
18
21
  owner: string,
19
- ): Promise<OutRef> {
22
+ ): Promise<{ utxo: UTxO; datum: StakingPosition }> {
23
+ const network = lucid.config().network!;
24
+
20
25
  const stakingUtxos = await lucid.utxosAtWithUnit(
21
26
  createScriptAddress(network, stakingScriptHash),
22
27
  assetClassToUnit(stakingPositionNft),
23
28
  );
24
29
 
25
30
  return matchSingle(
26
- stakingUtxos.filter((utxo) => {
27
- if (utxo.datum != null) {
28
- try {
29
- const stakingDatum = parseStakingPositionDatum(utxo.datum);
30
-
31
- return stakingDatum.owner == owner;
32
- } catch (_) {
33
- // when incompatible datum
34
- return false;
35
- }
36
- }
37
- }),
31
+ F.pipe(
32
+ stakingUtxos.map((utxo) =>
33
+ F.pipe(
34
+ O.fromNullable(utxo.datum),
35
+ O.flatMap(parseStakingPosition),
36
+ O.flatMap((datum) => {
37
+ if (toHex(datum.owner) === owner) {
38
+ return O.some({ utxo, datum: datum });
39
+ } else {
40
+ return O.none;
41
+ }
42
+ }),
43
+ ),
44
+ ),
45
+ A.compact,
46
+ ),
38
47
  (res) =>
39
48
  new Error(
40
49
  'Expected a single Staking Position UTXO.: ' + JSON.stringify(res),
@@ -0,0 +1,19 @@
1
+ import { LucidEvolution, ScriptHash, UTxO } from '@lucid-evolution/lucid';
2
+ import { createScriptAddress, getRandomElement } from '../../src';
3
+ import { option as O, function as F } from 'fp-ts';
4
+
5
+ export async function findRandomTreasuryUtxo(
6
+ lucid: LucidEvolution,
7
+ treasuryScriptHash: ScriptHash,
8
+ ): Promise<UTxO> {
9
+ const treasuryUtxos = await lucid.utxosAt(
10
+ createScriptAddress(lucid.config().network!, treasuryScriptHash),
11
+ );
12
+
13
+ return F.pipe(
14
+ O.fromNullable(getRandomElement(treasuryUtxos)),
15
+ O.match(() => {
16
+ throw new Error('Expected some treasury UTXOs.');
17
+ }, F.identity),
18
+ );
19
+ }