@indigo-labs/indigo-sdk 0.5.4 → 0.5.6

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 (208) hide show
  1. package/dist/index.d.mts +11 -1
  2. package/dist/index.d.ts +11 -1
  3. package/dist/index.js +17 -0
  4. package/dist/index.mjs +15 -0
  5. package/package.json +11 -1
  6. package/.claude/settings.local.json +0 -7
  7. package/.github/workflows/ci.yml +0 -66
  8. package/.husky/pre-commit +0 -1
  9. package/.nvmrc +0 -1
  10. package/.prettierignore +0 -1
  11. package/.prettierrc +0 -6
  12. package/eslint.config.mjs +0 -42
  13. package/scripts/bench.sh +0 -62
  14. package/scripts/run-repeat.sh +0 -22
  15. package/src/contracts/cdp/helpers.ts +0 -173
  16. package/src/contracts/cdp/scripts.ts +0 -70
  17. package/src/contracts/cdp/transactions.ts +0 -1584
  18. package/src/contracts/cdp/types-new.ts +0 -277
  19. package/src/contracts/cdp/types.ts +0 -43
  20. package/src/contracts/cdp-creator/queries.ts +0 -30
  21. package/src/contracts/cdp-creator/scripts.ts +0 -45
  22. package/src/contracts/cdp-creator/types-new.ts +0 -50
  23. package/src/contracts/cdp-creator/types.ts +0 -24
  24. package/src/contracts/collector/scripts.ts +0 -32
  25. package/src/contracts/collector/transactions.ts +0 -50
  26. package/src/contracts/collector/types-new.ts +0 -17
  27. package/src/contracts/execute/scripts.ts +0 -57
  28. package/src/contracts/execute/types-new.ts +0 -44
  29. package/src/contracts/execute/types.ts +0 -24
  30. package/src/contracts/gov/helpers.ts +0 -351
  31. package/src/contracts/gov/scripts.ts +0 -41
  32. package/src/contracts/gov/transactions.ts +0 -1607
  33. package/src/contracts/gov/types-new.ts +0 -268
  34. package/src/contracts/gov/types.ts +0 -22
  35. package/src/contracts/iasset/helpers.ts +0 -170
  36. package/src/contracts/iasset/queries.ts +0 -102
  37. package/src/contracts/iasset/scripts.ts +0 -38
  38. package/src/contracts/iasset/types.ts +0 -154
  39. package/src/contracts/initialize/actions.ts +0 -789
  40. package/src/contracts/initialize/helpers.ts +0 -616
  41. package/src/contracts/initialize/types.ts +0 -116
  42. package/src/contracts/interest-collection/helpers.ts +0 -19
  43. package/src/contracts/interest-collection/queries.ts +0 -66
  44. package/src/contracts/interest-collection/scripts.ts +0 -44
  45. package/src/contracts/interest-collection/transactions.ts +0 -433
  46. package/src/contracts/interest-collection/types-new.ts +0 -50
  47. package/src/contracts/interest-collection/types.ts +0 -26
  48. package/src/contracts/interest-oracle/helpers.ts +0 -61
  49. package/src/contracts/interest-oracle/scripts.ts +0 -18
  50. package/src/contracts/interest-oracle/transactions.ts +0 -151
  51. package/src/contracts/interest-oracle/types-new.ts +0 -32
  52. package/src/contracts/interest-oracle/types.ts +0 -16
  53. package/src/contracts/one-shot/scripts.ts +0 -12
  54. package/src/contracts/one-shot/transactions.ts +0 -66
  55. package/src/contracts/one-shot/types.ts +0 -22
  56. package/src/contracts/poll/helpers.ts +0 -37
  57. package/src/contracts/poll/scripts.ts +0 -71
  58. package/src/contracts/poll/types-poll-manager.ts +0 -20
  59. package/src/contracts/poll/types-poll-new.ts +0 -196
  60. package/src/contracts/poll/types-poll-shard.ts +0 -16
  61. package/src/contracts/price-oracle/helpers.ts +0 -30
  62. package/src/contracts/price-oracle/scripts.ts +0 -18
  63. package/src/contracts/price-oracle/transactions.ts +0 -115
  64. package/src/contracts/price-oracle/types-new.ts +0 -50
  65. package/src/contracts/price-oracle/types.ts +0 -16
  66. package/src/contracts/pyth-feed/helpers.ts +0 -82
  67. package/src/contracts/pyth-feed/scripts.ts +0 -15
  68. package/src/contracts/pyth-feed/types.ts +0 -181
  69. package/src/contracts/rob/helpers.ts +0 -666
  70. package/src/contracts/rob/scripts.ts +0 -35
  71. package/src/contracts/rob/transactions.ts +0 -423
  72. package/src/contracts/rob/types-new.ts +0 -128
  73. package/src/contracts/rob/types.ts +0 -16
  74. package/src/contracts/rob-leverage/helpers.ts +0 -422
  75. package/src/contracts/rob-leverage/transactions.ts +0 -368
  76. package/src/contracts/stability-pool/helpers.ts +0 -798
  77. package/src/contracts/stability-pool/queries.ts +0 -132
  78. package/src/contracts/stability-pool/scripts.ts +0 -51
  79. package/src/contracts/stability-pool/transactions.ts +0 -921
  80. package/src/contracts/stability-pool/types-new.ts +0 -385
  81. package/src/contracts/stability-pool/types.ts +0 -25
  82. package/src/contracts/stableswap/helpers.ts +0 -507
  83. package/src/contracts/stableswap/scripts.ts +0 -37
  84. package/src/contracts/stableswap/transactions.ts +0 -475
  85. package/src/contracts/stableswap/types-new.ts +0 -131
  86. package/src/contracts/stableswap/types.ts +0 -17
  87. package/src/contracts/staking/helpers.ts +0 -136
  88. package/src/contracts/staking/scripts.ts +0 -41
  89. package/src/contracts/staking/transactions.ts +0 -349
  90. package/src/contracts/staking/types-new.ts +0 -137
  91. package/src/contracts/staking/types.ts +0 -17
  92. package/src/contracts/treasury/helpers.ts +0 -21
  93. package/src/contracts/treasury/queries.ts +0 -100
  94. package/src/contracts/treasury/scripts.ts +0 -27
  95. package/src/contracts/treasury/transactions.ts +0 -334
  96. package/src/contracts/treasury/types-new.ts +0 -69
  97. package/src/contracts/treasury/types.ts +0 -14
  98. package/src/contracts/version-registry/scripts.ts +0 -29
  99. package/src/contracts/version-registry/types-new.ts +0 -18
  100. package/src/contracts/version-registry/types.ts +0 -17
  101. package/src/index.ts +0 -93
  102. package/src/scripts/always-fail-validator.ts +0 -7
  103. package/src/scripts/auth-token-policy.ts +0 -24
  104. package/src/scripts/iasset-policy.ts +0 -23
  105. package/src/types/evolution-schema-options.ts +0 -16
  106. package/src/types/generic.ts +0 -52
  107. package/src/types/multisig.ts +0 -48
  108. package/src/types/on-chain-decimal.ts +0 -57
  109. package/src/types/rational.ts +0 -61
  110. package/src/types/system-params.ts +0 -463
  111. package/src/utils/array-utils.ts +0 -108
  112. package/src/utils/bigint-utils.ts +0 -35
  113. package/src/utils/helper-txs.ts +0 -31
  114. package/src/utils/indigo-helpers.ts +0 -17
  115. package/src/utils/lucid-utils.ts +0 -125
  116. package/src/utils/oracle-helpers.ts +0 -62
  117. package/src/utils/pyth/decode.ts +0 -223
  118. package/src/utils/pyth/encode.ts +0 -262
  119. package/src/utils/pyth/index.ts +0 -14
  120. package/src/utils/pyth/types.ts +0 -87
  121. package/src/utils/time-helpers.ts +0 -4
  122. package/src/utils/utils.ts +0 -25
  123. package/src/validators/always-succeed-validator.ts +0 -6
  124. package/src/validators/cdp-creator-validator.ts +0 -7
  125. package/src/validators/cdp-redeem-validator.ts +0 -7
  126. package/src/validators/cdp-validator.ts +0 -7
  127. package/src/validators/collector-validator.ts +0 -7
  128. package/src/validators/execute-validator.ts +0 -7
  129. package/src/validators/governance-validator.ts +0 -7
  130. package/src/validators/iasset-validator.ts +0 -7
  131. package/src/validators/interest-collection-validator.ts +0 -7
  132. package/src/validators/interest-oracle-validator.ts +0 -7
  133. package/src/validators/one-shot-policy.ts +0 -7
  134. package/src/validators/poll-manager-validator.ts +0 -7
  135. package/src/validators/poll-shard-validator.ts +0 -7
  136. package/src/validators/price-oracle-validator.ts +0 -7
  137. package/src/validators/pyth-feed-validator.ts +0 -7
  138. package/src/validators/rob-validator.ts +0 -7
  139. package/src/validators/stability-pool-validator.ts +0 -7
  140. package/src/validators/stableswap-validator.ts +0 -7
  141. package/src/validators/staking-validator.ts +0 -7
  142. package/src/validators/treasury-validator.ts +0 -7
  143. package/src/validators/version-record-policy.ts +0 -7
  144. package/src/validators/version-registry-validator.ts +0 -7
  145. package/tests/always-succeed/script.ts +0 -7
  146. package/tests/array-utils.test.ts +0 -92
  147. package/tests/bigint-utils.test.ts +0 -41
  148. package/tests/cdp/actions.ts +0 -680
  149. package/tests/cdp/cdp-helpers.ts +0 -55
  150. package/tests/cdp/cdp-queries.ts +0 -423
  151. package/tests/cdp/cdp.test.ts +0 -6730
  152. package/tests/cdp/transactions-mutated.ts +0 -1733
  153. package/tests/data/system-params.json +0 -1155
  154. package/tests/datums.test.ts +0 -302
  155. package/tests/endpoints/initialize.ts +0 -78
  156. package/tests/endpoints/interest-collector.ts +0 -37
  157. package/tests/endpoints/treasury.ts +0 -70
  158. package/tests/gov/actions.ts +0 -381
  159. package/tests/gov/gov.test.ts +0 -5147
  160. package/tests/gov/governance-queries.ts +0 -37
  161. package/tests/hash-checks.test.ts +0 -112
  162. package/tests/indigo-test-helpers.ts +0 -99
  163. package/tests/initialize.test.ts +0 -79
  164. package/tests/interest-calculations.test.ts +0 -120
  165. package/tests/interest-collection/interest-collection.test.ts +0 -843
  166. package/tests/interest-collection/transactions-mutated.ts +0 -260
  167. package/tests/interest-oracle.test.ts +0 -93
  168. package/tests/mock/assets-mock.ts +0 -243
  169. package/tests/mock/protocol-params-mock.ts +0 -21
  170. package/tests/price-oracle/actions.ts +0 -161
  171. package/tests/price-oracle/price-oracle-queries.ts +0 -12
  172. package/tests/price-oracle/price-oracle.test.ts +0 -228
  173. package/tests/price-oracle/transactions-mutated.ts +0 -59
  174. package/tests/pyth/endpoints.ts +0 -96
  175. package/tests/pyth/helpers.ts +0 -37
  176. package/tests/pyth/pyth-encoding.test.ts +0 -376
  177. package/tests/pyth/pyth-feeds.test.ts +0 -943
  178. package/tests/pyth/pyth-indigo.test.ts +0 -505
  179. package/tests/pyth/pyth.test.ts +0 -299
  180. package/tests/queries/collector-queries.ts +0 -27
  181. package/tests/queries/execute-queries.ts +0 -47
  182. package/tests/queries/iasset-queries.ts +0 -149
  183. package/tests/queries/interest-oracle-queries.ts +0 -12
  184. package/tests/queries/poll-queries.ts +0 -97
  185. package/tests/queries/staking-queries.ts +0 -54
  186. package/tests/rob/actions.ts +0 -56
  187. package/tests/rob/rob-leverage.test.ts +0 -2555
  188. package/tests/rob/rob-queries.ts +0 -95
  189. package/tests/rob/rob.test.ts +0 -3677
  190. package/tests/rob/transactions-mutated.ts +0 -844
  191. package/tests/script-size.test.ts +0 -240
  192. package/tests/setup.ts +0 -135
  193. package/tests/stability-pool/actions.ts +0 -229
  194. package/tests/stability-pool.test.ts +0 -6491
  195. package/tests/stableswap/stableswap-actions.ts +0 -83
  196. package/tests/stableswap/stableswap-queries.ts +0 -98
  197. package/tests/stableswap/stableswap.test.ts +0 -4471
  198. package/tests/stableswap/transactions-mutated.ts +0 -348
  199. package/tests/staking.test.ts +0 -172
  200. package/tests/test-helpers.ts +0 -94
  201. package/tests/treasury/actions.ts +0 -67
  202. package/tests/treasury/treasury.test.ts +0 -320
  203. package/tests/utils/asserts.ts +0 -87
  204. package/tests/utils/benchmark-utils.ts +0 -130
  205. package/tests/utils/index.ts +0 -168
  206. package/tsconfig.build.json +0 -4
  207. package/tsconfig.json +0 -27
  208. package/vitest.config.ts +0 -11
@@ -1,299 +0,0 @@
1
- import {
2
- credentialToRewardAddress,
3
- Data,
4
- Emulator,
5
- EmulatorAccount,
6
- fromHex,
7
- generateEmulatorAccount,
8
- Lucid,
9
- scriptHashToCredential,
10
- toHex,
11
- validatorToScriptHash,
12
- } from '@lucid-evolution/lucid';
13
- import { beforeEach, describe, expect, test } from 'vitest';
14
- import { LucidContext, runAndAwaitTxBuilder } from '../test-helpers';
15
- import {
16
- initPyth,
17
- TEST_TRUSTED_SIGNER_PRIV_KEY,
18
- TEST_TRUSTED_SIGNER_PUB_KEY,
19
- } from './endpoints';
20
- import {
21
- PythFeedParams,
22
- PythStateDatum,
23
- serialisePythFeedRedeemer,
24
- serialisePythStateDatum,
25
- serialisePythUpdatesRedeemer,
26
- toDataDerivedPythPrice,
27
- } from '../../src/contracts/pyth-feed/types';
28
- import { assetClassToUnit } from '@3rd-eye-labs/cardano-offchain-common';
29
- import { mkPythFeedValidator } from '../../src/contracts/pyth-feed/scripts';
30
- import { alwaysSucceedValidator } from '../always-succeed/script';
31
- import {
32
- encodePriceUpdate,
33
- encodePythMessage,
34
- type PriceUpdate,
35
- type PythMessageParts,
36
- } from '../../src/utils/pyth';
37
- import { MAINNET_PROTOCOL_PARAMETERS } from '../indigo-test-helpers';
38
- import { createPythMessage } from './helpers';
39
- import { ParsedFeedPayload } from '@pythnetwork/pyth-lazer-sdk';
40
- import { derivePythPrice } from '../../src/contracts/pyth-feed/helpers';
41
- import * as Core from '@evolution-sdk/evolution';
42
-
43
- type MyContext = LucidContext<{
44
- admin: EmulatorAccount;
45
- }>;
46
-
47
- describe('Pyth > Initialization', () => {
48
- beforeEach<MyContext>(async (context: MyContext) => {
49
- context.users = {
50
- admin: generateEmulatorAccount({
51
- lovelace: BigInt(100_000_000_000_000),
52
- }),
53
- };
54
-
55
- context.emulator = new Emulator(
56
- [context.users.admin],
57
- MAINNET_PROTOCOL_PARAMETERS,
58
- );
59
-
60
- context.lucid = await Lucid(context.emulator, 'Custom');
61
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
62
- });
63
-
64
- test('initPyth initializes the Pyth State NFT', async (context: MyContext) => {
65
- const pythStateAsset = await initPyth(context.lucid);
66
-
67
- expect(pythStateAsset).toBeDefined();
68
- });
69
-
70
- test('Properly serializes a Pyth State datum', (_context: MyContext) => {
71
- const pythStateDatum: PythStateDatum = {
72
- governance: {
73
- wormhole: fromHex(''),
74
- emitterChain: 0n,
75
- emitterAddress: fromHex(''),
76
- seenSequence: 0n,
77
- },
78
- trustedSigners: new Map([
79
- [
80
- fromHex(
81
- '4a50d7c3d16b2be5c16ba996109a455a34cce08a81b3e15b86ef407e2f72e71f',
82
- ),
83
- {
84
- lower_bound: {
85
- bound_type: {
86
- _tag: 'NegativeInfinity',
87
- },
88
- is_inclusive: true,
89
- },
90
- upper_bound: {
91
- bound_type: {
92
- _tag: 'Finite',
93
- finite: 1n,
94
- },
95
- is_inclusive: true,
96
- },
97
- },
98
- ],
99
- ]),
100
- deprecatedWithdrawScripts: new Map(),
101
- withdraw_script: fromHex(
102
- '7688145a4fa7aa18c16ef0daafeec18091ab99ea4268cfe2d863c79fda131938',
103
- ),
104
- };
105
-
106
- const serialisedPythStateDatum = serialisePythStateDatum(pythStateDatum);
107
- expect(serialisedPythStateDatum).toBe(
108
- 'd8799fd8799f40004000ffa158204a50d7c3d16b2be5c16ba996109a455a34cce08a81b3e15b86ef407e2f72e71fd8799fd8799fd87980d87a80ffd8799fd87a9f01ffd87a80ffffa058207688145a4fa7aa18c16ef0daafeec18091ab99ea4268cfe2d863c79fda131938ff',
109
- );
110
- });
111
-
112
- test('Pyth Feed validator can confirm a Pyth Message', async (context: MyContext) => {
113
- const pythStateAsset = await initPyth(context.lucid);
114
-
115
- const noble = await import('@noble/ed25519');
116
- const priceFeedId = 1;
117
- const price = 1000n;
118
- const exponent = -8;
119
-
120
- const params: PythFeedParams = {
121
- pythStatePolicyId: pythStateAsset.currencySymbol,
122
- config: {
123
- Value: { configuration: { priceFeedId: BigInt(priceFeedId) } },
124
- },
125
- };
126
-
127
- const pfvValidator = mkPythFeedValidator(params);
128
- const pfvValHash = validatorToScriptHash(pfvValidator);
129
-
130
- // Register the stake key for pyth feed validator.
131
- await runAndAwaitTxBuilder(
132
- context.lucid,
133
- context.lucid.newTx().register.Stake(
134
- credentialToRewardAddress(context.lucid.config().network!, {
135
- hash: pfvValHash,
136
- type: 'Script',
137
- }),
138
- ),
139
- );
140
-
141
- const currentTime = BigInt(
142
- context.lucid.slotToUnixTime(context.lucid.currentSlot()),
143
- );
144
-
145
- // This is to test the transaction validity when using a timestamp different than the
146
- // slot boundary (which is the usual and general case).
147
- const timestamp = currentTime - 10n;
148
-
149
- const update: PriceUpdate = {
150
- timestampUs: (timestamp * 1_000n).toString(),
151
- channelId: 0,
152
- priceFeeds: [
153
- {
154
- priceFeedId,
155
- price: price.toString(),
156
- exponent,
157
- },
158
- ],
159
- };
160
- const payload = encodePriceUpdate(update);
161
- const signature = await noble.signAsync(
162
- payload,
163
- fromHex(TEST_TRUSTED_SIGNER_PRIV_KEY),
164
- );
165
- const parts: PythMessageParts = {
166
- signature,
167
- publicKey: fromHex(TEST_TRUSTED_SIGNER_PUB_KEY),
168
- payload,
169
- };
170
- const message = encodePythMessage(parts);
171
-
172
- const pythStateUtxo = await context.lucid.utxoByUnit(
173
- assetClassToUnit(pythStateAsset),
174
- );
175
-
176
- await runAndAwaitTxBuilder(
177
- context.lucid,
178
- context.lucid
179
- .newTx()
180
- .readFrom([pythStateUtxo])
181
- .attach.Script(pfvValidator)
182
- .validFrom(Number(timestamp))
183
- .validTo(Number(timestamp) + 60 * 1000)
184
- .withdraw(
185
- credentialToRewardAddress(
186
- context.lucid.config().network!,
187
- scriptHashToCredential(pfvValHash),
188
- ),
189
- 0n,
190
- serialisePythFeedRedeemer({
191
- price: {
192
- numerator: 1_000n,
193
- denominator: 100_000_000n,
194
- },
195
- auxiliaryData: Core.Data.fromCBORHex(Data.void()),
196
- }),
197
- )
198
- .withdraw(
199
- credentialToRewardAddress(
200
- context.lucid.config().network!,
201
- scriptHashToCredential(
202
- validatorToScriptHash(alwaysSucceedValidator),
203
- ),
204
- ),
205
- 0n,
206
- serialisePythUpdatesRedeemer([message]),
207
- ),
208
- );
209
- });
210
- });
211
-
212
- describe('Pyth > Helper functions', () => {
213
- test('derivePythPrice works', async () => {
214
- const feed1: ParsedFeedPayload = {
215
- priceFeedId: 1,
216
- price: '1000',
217
- exponent: -8,
218
- };
219
- const feed2: ParsedFeedPayload = {
220
- priceFeedId: 2,
221
- price: '99',
222
- exponent: 0,
223
- };
224
- const feed3: ParsedFeedPayload = {
225
- priceFeedId: 3,
226
- price: '45',
227
- exponent: 0,
228
- };
229
- const message = await createPythMessage(
230
- [feed1, feed2, feed3],
231
- BigInt(Date.now()),
232
- );
233
-
234
- // Single direct value
235
- // 1000 * 10^-8 = 0.00001
236
- {
237
- const price = derivePythPrice(
238
- {
239
- Value: {
240
- configuration: { priceFeedId: 1n },
241
- },
242
- },
243
- toHex(message),
244
- );
245
-
246
- expect(price.numerator).toBe(1_000n);
247
- expect(price.denominator).toBe(100_000_000n);
248
- }
249
-
250
- // Single inverse value: 1 / (1000 * 10^-8) = 1 / 0.00001 = 100000
251
- {
252
- const price = derivePythPrice(
253
- {
254
- Inverse: {
255
- value: toDataDerivedPythPrice({
256
- Value: {
257
- configuration: {
258
- priceFeedId: 1n,
259
- },
260
- },
261
- }),
262
- },
263
- },
264
- toHex(message),
265
- );
266
-
267
- expect(price.numerator).toBe(100_000_000n);
268
- expect(price.denominator).toBe(1_000n);
269
- }
270
-
271
- // Single divide value: 99 / 45 = 2.2
272
- {
273
- const price = derivePythPrice(
274
- {
275
- Divide: {
276
- x: toDataDerivedPythPrice({
277
- Value: {
278
- configuration: {
279
- priceFeedId: 2n,
280
- },
281
- },
282
- }),
283
- y: toDataDerivedPythPrice({
284
- Value: {
285
- configuration: {
286
- priceFeedId: 3n,
287
- },
288
- },
289
- }),
290
- },
291
- },
292
- toHex(message),
293
- );
294
-
295
- expect(price.numerator).toBe(99n);
296
- expect(price.denominator).toBe(45n);
297
- }
298
- });
299
- });
@@ -1,27 +0,0 @@
1
- import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
2
- import { createScriptAddress } from '../../src';
3
- import { option as O, function as F } from 'fp-ts';
4
- import { getRandomElement } from '@3rd-eye-labs/cardano-offchain-common';
5
-
6
- export async function findAllCollectors(
7
- lucid: LucidEvolution,
8
- collectorScriptHash: string,
9
- ): Promise<UTxO[]> {
10
- return lucid.utxosAt(
11
- createScriptAddress(lucid.config().network!, collectorScriptHash),
12
- );
13
- }
14
-
15
- export async function findRandomCollector(
16
- lucid: LucidEvolution,
17
- collectorScriptHash: string,
18
- ): Promise<UTxO> {
19
- const allCollectors = await findAllCollectors(lucid, collectorScriptHash);
20
-
21
- return F.pipe(
22
- O.fromNullable(getRandomElement(allCollectors)),
23
- O.match(() => {
24
- throw new Error('Expected some poll shard UTXOs.');
25
- }, F.identity),
26
- );
27
- }
@@ -1,47 +0,0 @@
1
- import { LucidEvolution, ScriptHash, UTxO } from '@lucid-evolution/lucid';
2
- import { createScriptAddress, matchSingle } from '../../src';
3
- import { option as O, array as A, function as F } from 'fp-ts';
4
- import {
5
- AssetClass,
6
- assetClassToUnit,
7
- } from '@3rd-eye-labs/cardano-offchain-common';
8
- import {
9
- ExecuteDatum,
10
- parseExecuteDatum,
11
- } from '../../src/contracts/execute/types-new';
12
-
13
- export async function findExecute(
14
- lucid: LucidEvolution,
15
- executeHash: ScriptHash,
16
- executeNft: AssetClass,
17
- upgradeId: bigint,
18
- ): Promise<{
19
- utxo: UTxO;
20
- datum: ExecuteDatum;
21
- }> {
22
- const executeUtxos = await lucid.utxosAtWithUnit(
23
- createScriptAddress(lucid.config().network!, executeHash),
24
- assetClassToUnit(executeNft),
25
- );
26
-
27
- return matchSingle(
28
- F.pipe(
29
- executeUtxos.map((utxo) =>
30
- F.pipe(
31
- O.fromNullable(utxo.datum),
32
- O.flatMap(parseExecuteDatum),
33
- O.flatMap((datum) => {
34
- if (datum.id === upgradeId) {
35
- return O.some({ utxo, datum: datum });
36
- } else {
37
- return O.none;
38
- }
39
- }),
40
- ),
41
- ),
42
- A.compact,
43
- ),
44
- (res) =>
45
- new Error('Expected a single Execute UTXO.: ' + JSON.stringify(res)),
46
- );
47
- }
@@ -1,149 +0,0 @@
1
- import {
2
- fromText,
3
- LucidEvolution,
4
- ScriptHash,
5
- toHex,
6
- toText,
7
- } from '@lucid-evolution/lucid';
8
- import { createScriptAddress } from '../../src/utils/lucid-utils';
9
- import { matchSingle, SystemParams } from '../../src';
10
- import { option as O, array as A, function as F } from 'fp-ts';
11
- import {
12
- AssetClass,
13
- assetClassToUnit,
14
- isSameAssetClass,
15
- } from '@3rd-eye-labs/cardano-offchain-common';
16
- import {
17
- CollateralAssetOutput,
18
- IAssetOutput,
19
- parseCollateralAssetDatum,
20
- parseIAssetDatum,
21
- } from '../../src/contracts/iasset/types';
22
-
23
- // TODO: replace with the new variant defined below
24
- export async function findIAsset(
25
- lucid: LucidEvolution,
26
- iassetScriptHash: ScriptHash,
27
- iassetNft: AssetClass,
28
- // Ascii encoded
29
- iassetName: string,
30
- ): Promise<IAssetOutput> {
31
- const iassetUtxos = await lucid.utxosAtWithUnit(
32
- createScriptAddress(lucid.config().network!, iassetScriptHash),
33
- assetClassToUnit(iassetNft),
34
- );
35
-
36
- return matchSingle(
37
- F.pipe(
38
- iassetUtxos.map((utxo) =>
39
- F.pipe(
40
- O.fromNullable(utxo.datum),
41
- O.flatMap(parseIAssetDatum),
42
- O.flatMap((datum) => {
43
- if (toHex(datum.assetName) === fromText(iassetName)) {
44
- return O.some({ utxo, datum: datum });
45
- } else {
46
- return O.none;
47
- }
48
- }),
49
- ),
50
- ),
51
- A.compact,
52
- ),
53
- (res) =>
54
- new Error('Expected a single IAsset UTXO.: ' + JSON.stringify(res)),
55
- );
56
- }
57
-
58
- export async function findAllIAssets(
59
- lucid: LucidEvolution,
60
- iassetScriptHash: ScriptHash,
61
- iassetNft: AssetClass,
62
- ): Promise<IAssetOutput[]> {
63
- const iassetUtxos = await lucid.utxosAtWithUnit(
64
- createScriptAddress(lucid.config().network!, iassetScriptHash),
65
- assetClassToUnit(iassetNft),
66
- );
67
-
68
- return F.pipe(
69
- iassetUtxos.map((utxo) =>
70
- F.pipe(
71
- O.fromNullable(utxo.datum),
72
- O.flatMap(parseIAssetDatum),
73
- O.map((datum) => ({ utxo, datum: datum })),
74
- ),
75
- ),
76
- A.compact,
77
- );
78
- }
79
-
80
- // TODO: replace by the new variant defined below
81
- export async function findCollateralAsset(
82
- lucid: LucidEvolution,
83
- sysParams: SystemParams,
84
- collateralAssetNft: AssetClass,
85
- // Ascii encoded
86
- iassetName: string,
87
- collateralAsset: AssetClass,
88
- ): Promise<CollateralAssetOutput> {
89
- const collateralAssetUtxos = await lucid.utxosAtWithUnit(
90
- createScriptAddress(
91
- lucid.config().network!,
92
- sysParams.validatorHashes.iassetHash,
93
- ),
94
- assetClassToUnit(collateralAssetNft),
95
- );
96
-
97
- return matchSingle(
98
- F.pipe(
99
- collateralAssetUtxos.map((utxo) =>
100
- F.pipe(
101
- O.fromNullable(utxo.datum),
102
- O.flatMap(parseCollateralAssetDatum),
103
- O.flatMap((datum) => {
104
- if (
105
- isSameAssetClass(datum.collateralAsset, collateralAsset) &&
106
- fromText(iassetName) === toHex(datum.iasset)
107
- ) {
108
- return O.some({ utxo, datum: datum });
109
- } else {
110
- return O.none;
111
- }
112
- }),
113
- ),
114
- ),
115
- A.compact,
116
- ),
117
- (res) =>
118
- new Error(
119
- 'Expected a single Collateral Asset UTXO.: ' + JSON.stringify(res),
120
- ),
121
- );
122
- }
123
-
124
- export async function findAllCollateralAssetsOfIAsset(
125
- lucid: LucidEvolution,
126
- iassetScriptHash: ScriptHash,
127
- collateralAssetNft: AssetClass,
128
- iasset: Uint8Array<ArrayBufferLike>,
129
- ): Promise<CollateralAssetOutput[]> {
130
- const collateralUtxos = await lucid.utxosAtWithUnit(
131
- createScriptAddress(lucid.config().network!, iassetScriptHash),
132
- assetClassToUnit(collateralAssetNft),
133
- );
134
-
135
- return F.pipe(
136
- collateralUtxos.map((utxo) =>
137
- F.pipe(
138
- O.fromNullable(utxo.datum),
139
- O.flatMap(parseCollateralAssetDatum),
140
- O.filter(
141
- (collateralAsset) =>
142
- toText(toHex(collateralAsset.iasset)) === toText(toHex(iasset)),
143
- ),
144
- O.map((datum) => ({ utxo, datum: datum })),
145
- ),
146
- ),
147
- A.compact,
148
- );
149
- }
@@ -1,12 +0,0 @@
1
- import {
2
- AssetClass,
3
- assetClassToUnit,
4
- } from '@3rd-eye-labs/cardano-offchain-common';
5
- import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
6
-
7
- export async function findInterestOracle(
8
- lucid: LucidEvolution,
9
- interestNft: AssetClass,
10
- ): Promise<UTxO> {
11
- return lucid.utxoByUnit(assetClassToUnit(interestNft));
12
- }
@@ -1,97 +0,0 @@
1
- import { LucidEvolution, ScriptHash, UTxO } from '@lucid-evolution/lucid';
2
-
3
- import { matchSingle, createScriptAddress } from '../../src';
4
- import { option as O, array as A, function as F } from 'fp-ts';
5
- import {
6
- AssetClass,
7
- assetClassToUnit,
8
- getRandomElement,
9
- } from '@3rd-eye-labs/cardano-offchain-common';
10
- import {
11
- parsePollManager,
12
- parsePollShard,
13
- PollManagerContent,
14
- PollShardContent,
15
- } from '../../src/contracts/poll/types-poll-new';
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,54 +0,0 @@
1
- import {
2
- LucidEvolution,
3
- ScriptHash,
4
- toHex,
5
- UTxO,
6
- } from '@lucid-evolution/lucid';
7
- import { createScriptAddress } from '../../src/utils/lucid-utils';
8
- import { matchSingle } from '../../src';
9
- import { option as O, array as A, function as F } from 'fp-ts';
10
- import {
11
- parseStakingPosition,
12
- StakingPosition,
13
- } from '../../src/contracts/staking/types-new';
14
- import {
15
- AssetClass,
16
- assetClassToUnit,
17
- } from '@3rd-eye-labs/cardano-offchain-common';
18
-
19
- export async function findStakingPosition(
20
- lucid: LucidEvolution,
21
- stakingScriptHash: ScriptHash,
22
- stakingPositionNft: AssetClass,
23
- owner: string,
24
- ): Promise<{ utxo: UTxO; datum: StakingPosition }> {
25
- const network = lucid.config().network!;
26
-
27
- const stakingUtxos = await lucid.utxosAtWithUnit(
28
- createScriptAddress(network, stakingScriptHash),
29
- assetClassToUnit(stakingPositionNft),
30
- );
31
-
32
- return matchSingle(
33
- F.pipe(
34
- stakingUtxos.map((utxo) =>
35
- F.pipe(
36
- O.fromNullable(utxo.datum),
37
- O.flatMap(parseStakingPosition),
38
- O.flatMap((datum) => {
39
- if (toHex(datum.owner) === owner) {
40
- return O.some({ utxo, datum: datum });
41
- } else {
42
- return O.none;
43
- }
44
- }),
45
- ),
46
- ),
47
- A.compact,
48
- ),
49
- (res) =>
50
- new Error(
51
- 'Expected a single Staking Position UTXO.: ' + JSON.stringify(res),
52
- ),
53
- );
54
- }