@indigo-labs/indigo-sdk 0.1.21 → 0.1.22

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 +3 -8
  2. package/.github/workflows/test.yml +44 -0
  3. package/dist/index.d.mts +670 -1291
  4. package/dist/index.d.ts +670 -1291
  5. package/dist/index.js +2235 -4669
  6. package/dist/index.mjs +2216 -4618
  7. package/eslint.config.mjs +1 -7
  8. package/package.json +4 -9
  9. package/src/contracts/cdp.ts +746 -0
  10. package/src/contracts/collector.ts +98 -0
  11. package/src/contracts/gov.ts +1 -0
  12. package/src/contracts/interest-oracle.ts +149 -0
  13. package/src/contracts/{lrp/transactions.ts → lrp.ts} +14 -14
  14. package/src/contracts/{one-shot/transactions.ts → one-shot.ts} +3 -3
  15. package/src/contracts/stability-pool.ts +690 -0
  16. package/src/contracts/staking.ts +348 -0
  17. package/src/contracts/treasury.ts +112 -0
  18. package/src/helpers/asset-helpers.ts +57 -0
  19. package/src/{utils → helpers}/helper-txs.ts +0 -1
  20. package/src/{utils/utils.ts → helpers/helpers.ts} +10 -0
  21. package/src/{contracts/interest-oracle/helpers.ts → helpers/interest-oracle.ts} +9 -37
  22. package/src/{contracts/stability-pool/helpers.ts → helpers/stability-pool-helpers.ts} +6 -110
  23. package/src/helpers/staking-helpers.ts +94 -0
  24. package/src/helpers/time-helpers.ts +4 -0
  25. package/src/{utils → helpers}/value-helpers.ts +0 -10
  26. package/src/index.ts +33 -38
  27. package/src/{validators → scripts}/cdp-creator-validator.ts +50 -4
  28. package/src/{validators → scripts}/cdp-validator.ts +5 -3
  29. package/src/{validators → scripts}/collector-validator.ts +3 -2
  30. package/src/scripts/execute-validator.ts +52 -0
  31. package/src/{validators/governance-validator.ts → scripts/gov-validator.ts} +40 -3
  32. package/src/{validators → scripts}/interest-oracle-validator.ts +20 -4
  33. package/src/scripts/lrp-validator.ts +40 -0
  34. package/src/{contracts/one-shot/scripts.ts → scripts/one-shot-policy.ts} +1 -1
  35. package/src/scripts/poll-manager-validator.ts +52 -0
  36. package/src/{validators → scripts}/poll-shard-validator.ts +43 -3
  37. package/src/{contracts/price-oracle/scripts.ts → scripts/price-oracle-validator.ts} +4 -1
  38. package/src/{validators → scripts}/stability-pool-validator.ts +57 -4
  39. package/src/{validators → scripts}/staking-validator.ts +3 -2
  40. package/src/{validators → scripts}/treasury-validator.ts +3 -2
  41. package/src/{validators → scripts}/version-record-policy.ts +23 -4
  42. package/src/{validators/execute-validator.ts → scripts/version-registry.ts} +11 -3
  43. package/src/types/generic.ts +60 -78
  44. package/src/{contracts/cdp-creator/types.ts → types/indigo/cdp-creator.ts} +4 -6
  45. package/src/types/indigo/cdp.ts +88 -0
  46. package/src/types/indigo/execute.ts +21 -0
  47. package/src/types/indigo/gov.ts +51 -0
  48. package/src/{contracts/interest-oracle/types.ts → types/indigo/interest-oracle.ts} +1 -1
  49. package/src/{contracts/lrp/types.ts → types/indigo/lrp.ts} +2 -2
  50. package/src/types/indigo/poll-manager.ts +21 -0
  51. package/src/types/indigo/poll-shard.ts +16 -0
  52. package/src/{contracts/price-oracle/types.ts → types/indigo/price-oracle.ts} +4 -16
  53. package/src/types/indigo/stability-pool.ts +233 -0
  54. package/src/types/indigo/staking.ts +99 -0
  55. package/src/{contracts/version-registry/types.ts → types/indigo/version-record.ts} +1 -1
  56. package/src/types/on-chain-decimal.ts +0 -22
  57. package/src/types/system-params.ts +11 -22
  58. package/tests/datums.test.ts +108 -125
  59. package/tests/endpoints/initialize.ts +338 -240
  60. package/tests/hash-checks.test.ts +21 -26
  61. package/tests/indigo-test-helpers.ts +55 -1
  62. package/tests/initialize.test.ts +5 -10
  63. package/tests/interest-calculations.test.ts +18 -18
  64. package/tests/interest-oracle.test.ts +18 -20
  65. package/tests/lrp.test.ts +65 -191
  66. package/tests/queries/governance-queries.ts +16 -19
  67. package/tests/queries/iasset-queries.ts +23 -46
  68. package/tests/queries/interest-oracle-queries.ts +6 -3
  69. package/tests/queries/lrp-queries.ts +2 -2
  70. package/tests/queries/price-oracle-queries.ts +22 -5
  71. package/tests/queries/stability-pool-queries.ts +8 -10
  72. package/tests/queries/staking-queries.ts +19 -28
  73. package/tests/stability-pool.test.ts +71 -186
  74. package/tests/staking.test.ts +23 -30
  75. package/tests/test-helpers.ts +2 -11
  76. package/tsconfig.json +1 -3
  77. package/vitest.config.ts +1 -1
  78. package/src/contracts/cdp/helpers.ts +0 -167
  79. package/src/contracts/cdp/scripts.ts +0 -33
  80. package/src/contracts/cdp/transactions.ts +0 -1310
  81. package/src/contracts/cdp/types.ts +0 -161
  82. package/src/contracts/cdp-creator/scripts.ts +0 -39
  83. package/src/contracts/collector/scripts.ts +0 -32
  84. package/src/contracts/collector/transactions.ts +0 -44
  85. package/src/contracts/execute/scripts.ts +0 -48
  86. package/src/contracts/execute/types.ts +0 -57
  87. package/src/contracts/gov/helpers.ts +0 -157
  88. package/src/contracts/gov/scripts.ts +0 -34
  89. package/src/contracts/gov/transactions.ts +0 -1224
  90. package/src/contracts/gov/types-new.ts +0 -115
  91. package/src/contracts/gov/types.ts +0 -89
  92. package/src/contracts/interest-oracle/scripts.ts +0 -18
  93. package/src/contracts/interest-oracle/transactions.ts +0 -149
  94. package/src/contracts/lrp/scripts.ts +0 -27
  95. package/src/contracts/poll/helpers.ts +0 -55
  96. package/src/contracts/poll/scripts.ts +0 -72
  97. package/src/contracts/poll/types-poll-manager.ts +0 -38
  98. package/src/contracts/poll/types-poll-shard.ts +0 -38
  99. package/src/contracts/poll/types-poll.ts +0 -88
  100. package/src/contracts/price-oracle/transactions.ts +0 -112
  101. package/src/contracts/stability-pool/scripts.ts +0 -46
  102. package/src/contracts/stability-pool/transactions.ts +0 -660
  103. package/src/contracts/stability-pool/types-new.ts +0 -208
  104. package/src/contracts/stability-pool/types.ts +0 -42
  105. package/src/contracts/staking/helpers.ts +0 -116
  106. package/src/contracts/staking/scripts.ts +0 -41
  107. package/src/contracts/staking/transactions.ts +0 -268
  108. package/src/contracts/staking/types-new.ts +0 -81
  109. package/src/contracts/staking/types.ts +0 -41
  110. package/src/contracts/treasury/scripts.ts +0 -37
  111. package/src/contracts/treasury/transactions.ts +0 -44
  112. package/src/contracts/treasury/types.ts +0 -55
  113. package/src/contracts/version-registry/scripts.ts +0 -29
  114. package/src/contracts/version-registry/types-new.ts +0 -19
  115. package/src/contracts/vesting/helpers.ts +0 -267
  116. package/src/types/evolution-schema-options.ts +0 -16
  117. package/src/utils/bigint-utils.ts +0 -7
  118. package/src/utils/time-helpers.ts +0 -4
  119. package/src/validators/lrp-validator.ts +0 -7
  120. package/src/validators/poll-manager-validator.ts +0 -7
  121. package/src/validators/version-registry-validator.ts +0 -7
  122. package/tests/cdp.test.ts +0 -1565
  123. package/tests/gov.test.ts +0 -1874
  124. package/tests/mock/assets-mock.ts +0 -59
  125. package/tests/queries/cdp-queries.ts +0 -144
  126. package/tests/queries/collector-queries.ts +0 -26
  127. package/tests/queries/execute-queries.ts +0 -46
  128. package/tests/queries/poll-queries.ts +0 -97
  129. package/tests/queries/treasury-queries.ts +0 -19
  130. package/tests/utils/asserts.ts +0 -13
  131. package/tests/utils/index.ts +0 -50
  132. /package/src/{utils → helpers}/indigo-helpers.ts +0 -0
  133. /package/src/{utils → helpers}/lucid-utils.ts +0 -0
  134. /package/src/{contracts/price-oracle/helpers.ts → helpers/price-oracle-helpers.ts} +0 -0
  135. /package/src/{contracts/one-shot/types.ts → types/one-shot.ts} +0 -0
@@ -1,39 +1,20 @@
1
1
  import { beforeEach, test, afterEach } from 'vitest';
2
2
  import { LucidContext, runAndAwaitTx } from './test-helpers';
3
- import { EmulatorAccount, fromText, Lucid } from '@lucid-evolution/lucid';
3
+ import { fromText, Lucid } from '@lucid-evolution/lucid';
4
4
  import { Emulator } from '@lucid-evolution/lucid';
5
5
  import { generateEmulatorAccount } from '@lucid-evolution/lucid';
6
6
  import { init } from './endpoints/initialize';
7
- import {
8
- addrDetails,
9
- adjustSpAccount,
10
- closeSpAccount,
11
- createSpAccount,
12
- fromSystemParamsAsset,
13
- openCdp,
14
- processSpRequest,
15
- } from '../src';
7
+ import { addrDetails, CDPContract, StabilityPoolContract } from '../src';
16
8
  import {
17
9
  findStabilityPool,
18
10
  findStabilityPoolAccount,
19
11
  } from './queries/stability-pool-queries';
20
12
  import { findIAsset } from './queries/iasset-queries';
21
13
  import { findGov } from './queries/governance-queries';
22
- import { findRandomCdpCreator } from './queries/cdp-queries';
23
- import { findPriceOracle } from './queries/price-oracle-queries';
24
- import { match, P } from 'ts-pattern';
25
- import { findInterestOracle } from './queries/interest-oracle-queries';
26
- import { findRandomCollector } from './queries/collector-queries';
27
- import { iusdInitialAssetCfg } from './mock/assets-mock';
28
14
 
29
15
  let originalDateNow: () => number;
30
16
 
31
- type MyContext = LucidContext<{
32
- admin: EmulatorAccount;
33
- user: EmulatorAccount;
34
- }>;
35
-
36
- beforeEach<MyContext>(async (context: MyContext) => {
17
+ beforeEach<LucidContext>(async (context: LucidContext) => {
37
18
  context.users = {
38
19
  admin: generateEmulatorAccount({
39
20
  lovelace: BigInt(100_000_000_000_000),
@@ -55,48 +36,23 @@ afterEach(() => {
55
36
  Date.now = originalDateNow;
56
37
  });
57
38
 
58
- test<MyContext>('Stability Pool - Create Account', async ({
39
+ test<LucidContext>('Stability Pool - Create Account', async ({
59
40
  lucid,
60
41
  users,
61
42
  emulator,
62
- }: MyContext) => {
43
+ }: LucidContext) => {
63
44
  lucid.selectWallet.fromSeed(users.admin.seedPhrase);
64
- const [systemParams, [iusdInfo]] = await init(lucid, [iusdInitialAssetCfg]);
45
+ const systemParams = await init(lucid);
65
46
  lucid.selectWallet.fromSeed(users.user.seedPhrase);
66
47
  const [pkh, _] = await addrDetails(lucid);
67
48
 
68
- const iasset = await findIAsset(
69
- lucid,
70
- systemParams.validatorHashes.cdpHash,
71
- fromSystemParamsAsset(systemParams.cdpParams.iAssetAuthToken),
72
- iusdInfo.iassetTokenNameAscii,
73
- );
74
-
75
49
  await runAndAwaitTx(
76
50
  lucid,
77
- openCdp(
51
+ CDPContract.openPosition(
52
+ 'iUSD',
78
53
  1_000_000_000n,
79
54
  20n,
80
55
  systemParams,
81
- await findRandomCdpCreator(
82
- lucid,
83
- systemParams.validatorHashes.cdpCreatorHash,
84
- fromSystemParamsAsset(systemParams.cdpCreatorParams.cdpCreatorNft),
85
- ),
86
- iasset.utxo,
87
- await findPriceOracle(
88
- lucid,
89
- match(iasset.datum.price)
90
- .with({ Oracle: { content: P.select() } }, (oracleNft) => oracleNft)
91
- .otherwise(() => {
92
- throw new Error('Expected active oracle');
93
- }),
94
- ),
95
- await findInterestOracle(lucid, iasset.datum.interestOracleNft),
96
- await findRandomCollector(
97
- lucid,
98
- systemParams.validatorHashes.collectorHash,
99
- ),
100
56
  lucid,
101
57
  emulator.slot,
102
58
  ),
@@ -104,7 +60,7 @@ test<MyContext>('Stability Pool - Create Account', async ({
104
60
 
105
61
  await runAndAwaitTx(
106
62
  lucid,
107
- createSpAccount(iusdInfo.iassetTokenNameAscii, 10n, systemParams, lucid),
63
+ StabilityPoolContract.createAccount('iUSD', 10n, systemParams, lucid),
108
64
  );
109
65
 
110
66
  const stabilityPoolUtxo = await findStabilityPool(
@@ -117,14 +73,14 @@ test<MyContext>('Stability Pool - Create Account', async ({
117
73
  systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
118
74
  ),
119
75
  },
120
- iusdInfo.iassetTokenNameAscii,
76
+ 'iUSD',
121
77
  );
122
78
 
123
79
  const accountUtxo = await findStabilityPoolAccount(
124
80
  lucid,
125
81
  systemParams.validatorHashes.stabilityPoolHash,
126
82
  pkh.hash,
127
- iusdInfo.iassetTokenNameAscii,
83
+ 'iUSD',
128
84
  );
129
85
 
130
86
  const assetUtxo = await findIAsset(
@@ -137,7 +93,7 @@ test<MyContext>('Stability Pool - Create Account', async ({
137
93
  systemParams.cdpParams.iAssetAuthToken[1].unTokenName,
138
94
  ),
139
95
  },
140
- iusdInfo.iassetTokenNameAscii,
96
+ 'iUSD',
141
97
  );
142
98
 
143
99
  const govUtxo = await findGov(lucid, systemParams.validatorHashes.govHash, {
@@ -149,65 +105,36 @@ test<MyContext>('Stability Pool - Create Account', async ({
149
105
 
150
106
  await runAndAwaitTx(
151
107
  lucid,
152
- processSpRequest(
153
- iusdInfo.iassetTokenNameAscii,
108
+ StabilityPoolContract.processRequest(
109
+ 'iUSD',
154
110
  stabilityPoolUtxo,
155
111
  accountUtxo,
156
- govUtxo.utxo,
157
- assetUtxo.utxo,
112
+ govUtxo,
113
+ assetUtxo,
158
114
  undefined,
159
115
  systemParams,
160
116
  lucid,
161
- await findRandomCollector(
162
- lucid,
163
- systemParams.validatorHashes.collectorHash,
164
- ),
165
117
  ),
166
118
  );
167
119
  });
168
120
 
169
- test<MyContext>('Stability Pool - Adjust Account', async ({
121
+ test<LucidContext>('Stability Pool - Adjust Account', async ({
170
122
  lucid,
171
123
  users,
172
124
  emulator,
173
- }: MyContext) => {
125
+ }: LucidContext) => {
174
126
  lucid.selectWallet.fromSeed(users.admin.seedPhrase);
175
- const [systemParams, [iusdInfo]] = await init(lucid, [iusdInitialAssetCfg]);
127
+ const systemParams = await init(lucid);
176
128
  lucid.selectWallet.fromSeed(users.user.seedPhrase);
177
129
  const [pkh, _] = await addrDetails(lucid);
178
130
 
179
- const iasset = await findIAsset(
180
- lucid,
181
- systemParams.validatorHashes.cdpHash,
182
- fromSystemParamsAsset(systemParams.cdpParams.iAssetAuthToken),
183
- iusdInfo.iassetTokenNameAscii,
184
- );
185
-
186
131
  await runAndAwaitTx(
187
132
  lucid,
188
- openCdp(
133
+ CDPContract.openPosition(
134
+ 'iUSD',
189
135
  1_000_000_000n,
190
136
  20n,
191
137
  systemParams,
192
- await findRandomCdpCreator(
193
- lucid,
194
- systemParams.validatorHashes.cdpCreatorHash,
195
- fromSystemParamsAsset(systemParams.cdpCreatorParams.cdpCreatorNft),
196
- ),
197
- iasset.utxo,
198
- await findPriceOracle(
199
- lucid,
200
- match(iasset.datum.price)
201
- .with({ Oracle: { content: P.select() } }, (oracleNft) => oracleNft)
202
- .otherwise(() => {
203
- throw new Error('Expected active oracle');
204
- }),
205
- ),
206
- await findInterestOracle(lucid, iasset.datum.interestOracleNft),
207
- await findRandomCollector(
208
- lucid,
209
- systemParams.validatorHashes.collectorHash,
210
- ),
211
138
  lucid,
212
139
  emulator.slot,
213
140
  ),
@@ -215,7 +142,7 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
215
142
 
216
143
  await runAndAwaitTx(
217
144
  lucid,
218
- createSpAccount(iusdInfo.iassetTokenNameAscii, 10n, systemParams, lucid),
145
+ StabilityPoolContract.createAccount('iUSD', 10n, systemParams, lucid),
219
146
  );
220
147
 
221
148
  lucid.selectWallet.fromSeed(users.admin.seedPhrase);
@@ -230,14 +157,14 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
230
157
  systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
231
158
  ),
232
159
  },
233
- iusdInfo.iassetTokenNameAscii,
160
+ 'iUSD',
234
161
  );
235
162
 
236
163
  let accountUtxo = await findStabilityPoolAccount(
237
164
  lucid,
238
165
  systemParams.validatorHashes.stabilityPoolHash,
239
166
  pkh.hash,
240
- iusdInfo.iassetTokenNameAscii,
167
+ 'iUSD',
241
168
  );
242
169
 
243
170
  const assetUtxo = await findIAsset(
@@ -250,7 +177,7 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
250
177
  systemParams.cdpParams.iAssetAuthToken[1].unTokenName,
251
178
  ),
252
179
  },
253
- iusdInfo.iassetTokenNameAscii,
180
+ 'iUSD',
254
181
  );
255
182
 
256
183
  const govUtxo = await findGov(lucid, systemParams.validatorHashes.govHash, {
@@ -260,19 +187,15 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
260
187
 
261
188
  await runAndAwaitTx(
262
189
  lucid,
263
- processSpRequest(
264
- iusdInfo.iassetTokenNameAscii,
190
+ StabilityPoolContract.processRequest(
191
+ 'iUSD',
265
192
  stabilityPoolUtxo,
266
193
  accountUtxo,
267
- govUtxo.utxo,
268
- assetUtxo.utxo,
194
+ govUtxo,
195
+ assetUtxo,
269
196
  undefined,
270
197
  systemParams,
271
198
  lucid,
272
- await findRandomCollector(
273
- lucid,
274
- systemParams.validatorHashes.collectorHash,
275
- ),
276
199
  ),
277
200
  );
278
201
 
@@ -288,20 +211,20 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
288
211
  systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
289
212
  ),
290
213
  },
291
- iusdInfo.iassetTokenNameAscii,
214
+ 'iUSD',
292
215
  );
293
216
 
294
217
  accountUtxo = await findStabilityPoolAccount(
295
218
  lucid,
296
219
  systemParams.validatorHashes.stabilityPoolHash,
297
220
  pkh.hash,
298
- iusdInfo.iassetTokenNameAscii,
221
+ 'iUSD',
299
222
  );
300
223
 
301
224
  await runAndAwaitTx(
302
225
  lucid,
303
- adjustSpAccount(
304
- iusdInfo.iassetTokenNameAscii,
226
+ StabilityPoolContract.adjustAccount(
227
+ 'iUSD',
305
228
  10n,
306
229
  accountUtxo,
307
230
  systemParams,
@@ -314,24 +237,20 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
314
237
  lucid,
315
238
  systemParams.validatorHashes.stabilityPoolHash,
316
239
  pkh.hash,
317
- iusdInfo.iassetTokenNameAscii,
240
+ 'iUSD',
318
241
  );
319
242
 
320
243
  await runAndAwaitTx(
321
244
  lucid,
322
- processSpRequest(
323
- iusdInfo.iassetTokenNameAscii,
245
+ StabilityPoolContract.processRequest(
246
+ 'iUSD',
324
247
  stabilityPoolUtxo,
325
248
  accountUtxo,
326
- govUtxo.utxo,
327
- assetUtxo.utxo,
249
+ govUtxo,
250
+ assetUtxo,
328
251
  undefined,
329
252
  systemParams,
330
253
  lucid,
331
- await findRandomCollector(
332
- lucid,
333
- systemParams.validatorHashes.collectorHash,
334
- ),
335
254
  ),
336
255
  );
337
256
 
@@ -348,20 +267,20 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
348
267
  systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
349
268
  ),
350
269
  },
351
- iusdInfo.iassetTokenNameAscii,
270
+ 'iUSD',
352
271
  );
353
272
 
354
273
  accountUtxo = await findStabilityPoolAccount(
355
274
  lucid,
356
275
  systemParams.validatorHashes.stabilityPoolHash,
357
276
  pkh.hash,
358
- iusdInfo.iassetTokenNameAscii,
277
+ 'iUSD',
359
278
  );
360
279
 
361
280
  await runAndAwaitTx(
362
281
  lucid,
363
- adjustSpAccount(
364
- iusdInfo.iassetTokenNameAscii,
282
+ StabilityPoolContract.adjustAccount(
283
+ 'iUSD',
365
284
  -10n,
366
285
  accountUtxo,
367
286
  systemParams,
@@ -374,70 +293,41 @@ test<MyContext>('Stability Pool - Adjust Account', async ({
374
293
  lucid,
375
294
  systemParams.validatorHashes.stabilityPoolHash,
376
295
  pkh.hash,
377
- iusdInfo.iassetTokenNameAscii,
296
+ 'iUSD',
378
297
  );
379
298
 
380
299
  await runAndAwaitTx(
381
300
  lucid,
382
- processSpRequest(
383
- iusdInfo.iassetTokenNameAscii,
301
+ StabilityPoolContract.processRequest(
302
+ 'iUSD',
384
303
  stabilityPoolUtxo,
385
304
  accountUtxo,
386
- govUtxo.utxo,
387
- assetUtxo.utxo,
305
+ govUtxo,
306
+ assetUtxo,
388
307
  undefined,
389
308
  systemParams,
390
309
  lucid,
391
- await findRandomCollector(
392
- lucid,
393
- systemParams.validatorHashes.collectorHash,
394
- ),
395
310
  ),
396
311
  );
397
312
  });
398
313
 
399
- test<MyContext>('Stability Pool - Close Account', async ({
314
+ test<LucidContext>('Stability Pool - Close Account', async ({
400
315
  lucid,
401
316
  users,
402
317
  emulator,
403
- }: MyContext) => {
318
+ }: LucidContext) => {
404
319
  lucid.selectWallet.fromSeed(users.admin.seedPhrase);
405
- const [systemParams, [iusdInfo]] = await init(lucid, [iusdInitialAssetCfg]);
320
+ const systemParams = await init(lucid, emulator.now());
406
321
  lucid.selectWallet.fromSeed(users.user.seedPhrase);
407
322
  const [pkh, _] = await addrDetails(lucid);
408
323
 
409
- const iasset = await findIAsset(
410
- lucid,
411
- systemParams.validatorHashes.cdpHash,
412
- fromSystemParamsAsset(systemParams.cdpParams.iAssetAuthToken),
413
- iusdInfo.iassetTokenNameAscii,
414
- );
415
-
416
324
  await runAndAwaitTx(
417
325
  lucid,
418
- openCdp(
326
+ CDPContract.openPosition(
327
+ 'iUSD',
419
328
  1_000_000_000n,
420
329
  20n,
421
330
  systemParams,
422
- await findRandomCdpCreator(
423
- lucid,
424
- systemParams.validatorHashes.cdpCreatorHash,
425
- fromSystemParamsAsset(systemParams.cdpCreatorParams.cdpCreatorNft),
426
- ),
427
- iasset.utxo,
428
- await findPriceOracle(
429
- lucid,
430
- match(iasset.datum.price)
431
- .with({ Oracle: { content: P.select() } }, (oracleNft) => oracleNft)
432
- .otherwise(() => {
433
- throw new Error('Expected active oracle');
434
- }),
435
- ),
436
- await findInterestOracle(lucid, iasset.datum.interestOracleNft),
437
- await findRandomCollector(
438
- lucid,
439
- systemParams.validatorHashes.collectorHash,
440
- ),
441
331
  lucid,
442
332
  emulator.slot,
443
333
  ),
@@ -445,7 +335,7 @@ test<MyContext>('Stability Pool - Close Account', async ({
445
335
 
446
336
  await runAndAwaitTx(
447
337
  lucid,
448
- createSpAccount(iusdInfo.iassetTokenNameAscii, 10n, systemParams, lucid),
338
+ StabilityPoolContract.createAccount('iUSD', 10n, systemParams, lucid),
449
339
  );
450
340
 
451
341
  lucid.selectWallet.fromSeed(users.admin.seedPhrase);
@@ -460,14 +350,14 @@ test<MyContext>('Stability Pool - Close Account', async ({
460
350
  systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
461
351
  ),
462
352
  },
463
- iusdInfo.iassetTokenNameAscii,
353
+ 'iUSD',
464
354
  );
465
355
 
466
356
  let accountUtxo = await findStabilityPoolAccount(
467
357
  lucid,
468
358
  systemParams.validatorHashes.stabilityPoolHash,
469
359
  pkh.hash,
470
- iusdInfo.iassetTokenNameAscii,
360
+ 'iUSD',
471
361
  );
472
362
 
473
363
  const assetUtxo = await findIAsset(
@@ -480,7 +370,7 @@ test<MyContext>('Stability Pool - Close Account', async ({
480
370
  systemParams.cdpParams.iAssetAuthToken[1].unTokenName,
481
371
  ),
482
372
  },
483
- iusdInfo.iassetTokenNameAscii,
373
+ 'iUSD',
484
374
  );
485
375
 
486
376
  const govUtxo = await findGov(lucid, systemParams.validatorHashes.govHash, {
@@ -490,19 +380,15 @@ test<MyContext>('Stability Pool - Close Account', async ({
490
380
 
491
381
  await runAndAwaitTx(
492
382
  lucid,
493
- processSpRequest(
494
- iusdInfo.iassetTokenNameAscii,
383
+ StabilityPoolContract.processRequest(
384
+ 'iUSD',
495
385
  stabilityPoolUtxo,
496
386
  accountUtxo,
497
- govUtxo.utxo,
498
- assetUtxo.utxo,
387
+ govUtxo,
388
+ assetUtxo,
499
389
  undefined,
500
390
  systemParams,
501
391
  lucid,
502
- await findRandomCollector(
503
- lucid,
504
- systemParams.validatorHashes.collectorHash,
505
- ),
506
392
  ),
507
393
  );
508
394
 
@@ -518,41 +404,40 @@ test<MyContext>('Stability Pool - Close Account', async ({
518
404
  systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
519
405
  ),
520
406
  },
521
- iusdInfo.iassetTokenNameAscii,
407
+ 'iUSD',
522
408
  );
523
409
 
524
410
  accountUtxo = await findStabilityPoolAccount(
525
411
  lucid,
526
412
  systemParams.validatorHashes.stabilityPoolHash,
527
413
  pkh.hash,
528
- iusdInfo.iassetTokenNameAscii,
414
+ 'iUSD',
529
415
  );
530
416
 
531
- await runAndAwaitTx(lucid, closeSpAccount(accountUtxo, systemParams, lucid));
417
+ await runAndAwaitTx(
418
+ lucid,
419
+ StabilityPoolContract.closeAccount(accountUtxo, systemParams, lucid),
420
+ );
532
421
  lucid.selectWallet.fromSeed(users.admin.seedPhrase);
533
422
 
534
423
  accountUtxo = await findStabilityPoolAccount(
535
424
  lucid,
536
425
  systemParams.validatorHashes.stabilityPoolHash,
537
426
  pkh.hash,
538
- iusdInfo.iassetTokenNameAscii,
427
+ 'iUSD',
539
428
  );
540
429
 
541
430
  await runAndAwaitTx(
542
431
  lucid,
543
- processSpRequest(
544
- iusdInfo.iassetTokenNameAscii,
432
+ StabilityPoolContract.processRequest(
433
+ 'iUSD',
545
434
  stabilityPoolUtxo,
546
435
  accountUtxo,
547
- govUtxo.utxo,
548
- assetUtxo.utxo,
436
+ govUtxo,
437
+ assetUtxo,
549
438
  undefined,
550
439
  systemParams,
551
440
  lucid,
552
- await findRandomCollector(
553
- lucid,
554
- systemParams.validatorHashes.collectorHash,
555
- ),
556
441
  ),
557
442
  );
558
443
  });
@@ -1,23 +1,14 @@
1
1
  import { beforeEach, test } from 'vitest';
2
2
  import { LucidContext, runAndAwaitTx } from './test-helpers';
3
- import { EmulatorAccount, fromText, Lucid } from '@lucid-evolution/lucid';
3
+ import { fromText, Lucid } from '@lucid-evolution/lucid';
4
4
  import { Emulator } from '@lucid-evolution/lucid';
5
5
  import { generateEmulatorAccount } from '@lucid-evolution/lucid';
6
+ import { StakingContract } from '../src/contracts/staking';
6
7
  import { init } from './endpoints/initialize';
7
- import { addrDetails } from '../src/utils/lucid-utils';
8
+ import { addrDetails } from '../src/helpers/lucid-utils';
8
9
  import { findStakingPosition } from './queries/staking-queries';
9
- import { iusdInitialAssetCfg } from './mock/assets-mock';
10
- import {
11
- adjustStakingPosition,
12
- closeStakingPosition,
13
- openStakingPosition,
14
- } from '../src/contracts/staking/transactions';
15
10
 
16
- type MyContext = LucidContext<{
17
- admin: EmulatorAccount;
18
- }>;
19
-
20
- beforeEach<MyContext>(async (context: MyContext) => {
11
+ beforeEach<LucidContext>(async (context: LucidContext) => {
21
12
  context.users = {
22
13
  admin: generateEmulatorAccount({
23
14
  lovelace: BigInt(100_000_000_000_000),
@@ -29,34 +20,35 @@ beforeEach<MyContext>(async (context: MyContext) => {
29
20
  context.lucid = await Lucid(context.emulator, 'Custom');
30
21
  });
31
22
 
32
- test<MyContext>('Staking - Create Position', async ({
23
+ test<LucidContext>('Staking - Create Position', async ({
33
24
  lucid,
34
25
  users,
35
- }: MyContext) => {
26
+ }: LucidContext) => {
36
27
  lucid.selectWallet.fromSeed(users.admin.seedPhrase);
37
- const [systemParams, _] = await init(lucid, [iusdInitialAssetCfg]);
28
+ const systemParams = await init(lucid);
38
29
 
39
30
  await runAndAwaitTx(
40
31
  lucid,
41
- openStakingPosition(1_000_000n, systemParams, lucid),
32
+ StakingContract.openPosition(1_000_000n, systemParams, lucid),
42
33
  );
43
34
  });
44
35
 
45
- test<MyContext>('Staking - Adjust Position', async ({
36
+ test<LucidContext>('Staking - Adjust Position', async ({
46
37
  lucid,
47
38
  users,
48
- }: MyContext) => {
39
+ }: LucidContext) => {
49
40
  lucid.selectWallet.fromSeed(users.admin.seedPhrase);
50
- const [systemParams, _] = await init(lucid, [iusdInitialAssetCfg]);
41
+ const systemParams = await init(lucid);
51
42
 
52
43
  await runAndAwaitTx(
53
44
  lucid,
54
- openStakingPosition(1_000_000n, systemParams, lucid),
45
+ StakingContract.openPosition(1_000_000n, systemParams, lucid),
55
46
  );
56
47
 
57
- const [pkh, __] = await addrDetails(lucid);
48
+ const [pkh, _] = await addrDetails(lucid);
58
49
  const myStakingPosition = await findStakingPosition(
59
50
  lucid,
51
+ lucid.config().network,
60
52
  systemParams.validatorHashes.stakingHash,
61
53
  {
62
54
  currencySymbol:
@@ -70,8 +62,8 @@ test<MyContext>('Staking - Adjust Position', async ({
70
62
 
71
63
  await runAndAwaitTx(
72
64
  lucid,
73
- adjustStakingPosition(
74
- myStakingPosition.utxo,
65
+ StakingContract.adjustPosition(
66
+ myStakingPosition,
75
67
  1_000_000n,
76
68
  systemParams,
77
69
  lucid,
@@ -79,21 +71,22 @@ test<MyContext>('Staking - Adjust Position', async ({
79
71
  );
80
72
  });
81
73
 
82
- test<MyContext>('Staking - Close Position', async ({
74
+ test<LucidContext>('Staking - Close Position', async ({
83
75
  lucid,
84
76
  users,
85
- }: MyContext) => {
77
+ }: LucidContext) => {
86
78
  lucid.selectWallet.fromSeed(users.admin.seedPhrase);
87
- const [systemParams, _] = await init(lucid, [iusdInitialAssetCfg]);
79
+ const systemParams = await init(lucid);
88
80
 
89
81
  await runAndAwaitTx(
90
82
  lucid,
91
- openStakingPosition(1_000_000n, systemParams, lucid),
83
+ StakingContract.openPosition(1_000_000n, systemParams, lucid),
92
84
  );
93
85
 
94
- const [pkh, __] = await addrDetails(lucid);
86
+ const [pkh, _] = await addrDetails(lucid);
95
87
  const myStakingPosition = await findStakingPosition(
96
88
  lucid,
89
+ lucid.config().network,
97
90
  systemParams.validatorHashes.stakingHash,
98
91
  {
99
92
  currencySymbol:
@@ -107,6 +100,6 @@ test<MyContext>('Staking - Close Position', async ({
107
100
 
108
101
  await runAndAwaitTx(
109
102
  lucid,
110
- closeStakingPosition(myStakingPosition.utxo, systemParams, lucid),
103
+ StakingContract.closePosition(myStakingPosition, systemParams, lucid),
111
104
  );
112
105
  });
@@ -5,9 +5,9 @@ import {
5
5
  TxBuilder,
6
6
  } from '@lucid-evolution/lucid';
7
7
 
8
- export type LucidContext<T extends Record<string, EmulatorAccount>> = {
8
+ export type LucidContext = {
9
9
  lucid: LucidEvolution;
10
- users: T;
10
+ users: { [key: string]: EmulatorAccount };
11
11
  emulator: Emulator;
12
12
  };
13
13
 
@@ -36,12 +36,3 @@ export async function runAndAwaitTxBuilder(
36
36
  await lucid.awaitTx(txHash);
37
37
  return txHash;
38
38
  }
39
-
40
- export async function repeat(
41
- times: number,
42
- action: () => Promise<void>,
43
- ): Promise<void> {
44
- for (let i = 0; i < times; i++) {
45
- await action();
46
- }
47
- }
package/tsconfig.json CHANGED
@@ -5,9 +5,7 @@
5
5
  "module": "nodenext",
6
6
  "target": "ESNext",
7
7
  "moduleResolution": "nodenext",
8
- "allowUnreachableCode": true,
9
- "strict": true,
10
- "skipLibCheck": true
8
+ "allowUnreachableCode": true
11
9
  },
12
10
  "ts-node": {
13
11
  "compilerOptions": {
package/vitest.config.ts CHANGED
@@ -2,7 +2,7 @@ import { defineConfig } from 'vitest/config';
2
2
 
3
3
  export default defineConfig({
4
4
  test: {
5
- testTimeout: 120000, // 3 minutes
5
+ testTimeout: 120000, // 2 minutes
6
6
  reporters: 'verbose',
7
7
  include: ['./tests/**/*.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
8
8
  },