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