@indigo-labs/indigo-sdk 0.2.1 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/tests/cdp.test.ts CHANGED
@@ -28,7 +28,6 @@ import {
28
28
  freezeCdp,
29
29
  fromSystemParamsAsset,
30
30
  getInlineDatumOrThrow,
31
- IAssetOutput,
32
31
  InterestOracleDatum,
33
32
  liquidateCdp,
34
33
  matchSingle,
@@ -44,105 +43,29 @@ import {
44
43
  } from '../src';
45
44
  import {
46
45
  findAllActiveCdps,
46
+ findAllNecessaryOrefs,
47
47
  findCdp,
48
48
  findFrozenCDPs,
49
- findRandomCdpCreator,
50
49
  } from './queries/cdp-queries';
51
- import { findIAsset } from './queries/iasset-queries';
52
- import { findPriceOracle } from './queries/price-oracle-queries';
53
- import { match, P } from 'ts-pattern';
54
- import { findRandomCollector } from './queries/collector-queries';
55
- import { findGov } from './queries/governance-queries';
56
- import { findRandomTreasuryUtxo } from './queries/treasury-queries';
57
50
  import { getValueChangeAtAddressAfterAction } from './utils';
58
51
  import { cdpCollateralRatioPercentage } from '../src/contracts/cdp/helpers';
59
52
  import { OnChainDecimal } from '../src/types/on-chain-decimal';
60
- import { findInterestOracle } from './queries/interest-oracle-queries';
61
53
  import { feedPriceOracleTx } from '../src/contracts/price-oracle/transactions';
62
54
  import { iusdInitialAssetCfg } from './mock/assets-mock';
63
55
  import { assertValueInRange } from './utils/asserts';
64
- import {
65
- findStabilityPool,
66
- findStabilityPoolAccount,
67
- } from './queries/stability-pool-queries';
56
+ import { findStabilityPoolAccount } from './queries/stability-pool-queries';
68
57
 
69
58
  type MyContext = LucidContext<{
70
59
  admin: EmulatorAccount;
71
60
  user: EmulatorAccount;
72
61
  }>;
73
62
 
74
- async function findAllNecessaryOrefs(
75
- context: MyContext,
76
- sysParams: SystemParams,
77
- asset: string,
78
- ): Promise<{
79
- stabilityPoolUtxo: UTxO;
80
- iasset: IAssetOutput;
81
- cdpCreatorUtxo: UTxO;
82
- priceOracleUtxo: UTxO;
83
- interestOracleUtxo: UTxO;
84
- collectorUtxo: UTxO;
85
- govUtxo: UTxO;
86
- treasuryUtxo: UTxO;
87
- }> {
88
- const iasset = await findIAsset(
89
- context.lucid,
90
- sysParams.validatorHashes.cdpHash,
91
- fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
92
- asset,
93
- );
94
-
95
- const stabilityPool = await findStabilityPool(
96
- context.lucid,
97
- sysParams.validatorHashes.stabilityPoolHash,
98
- fromSystemParamsAsset(sysParams.stabilityPoolParams.stabilityPoolToken),
99
- asset,
100
- );
101
-
102
- return {
103
- stabilityPoolUtxo: stabilityPool,
104
- iasset,
105
- cdpCreatorUtxo: await findRandomCdpCreator(
106
- context.lucid,
107
- sysParams.validatorHashes.cdpCreatorHash,
108
- fromSystemParamsAsset(sysParams.cdpCreatorParams.cdpCreatorNft),
109
- ),
110
- priceOracleUtxo: await findPriceOracle(
111
- context.lucid,
112
- match(iasset.datum.price)
113
- .with({ Oracle: { content: P.select() } }, (oracleNft) => oracleNft)
114
- .otherwise(() => {
115
- throw new Error('Expected active oracle');
116
- }),
117
- ),
118
- interestOracleUtxo: await findInterestOracle(
119
- context.lucid,
120
- iasset.datum.interestOracleNft,
121
- ),
122
- collectorUtxo: await findRandomCollector(
123
- context.lucid,
124
- sysParams.validatorHashes.collectorHash,
125
- ),
126
- govUtxo: (
127
- await findGov(
128
- context.lucid,
129
- sysParams.validatorHashes.govHash,
130
- fromSystemParamsAsset(sysParams.govParams.govNFT),
131
- )
132
- ).utxo,
133
- treasuryUtxo: await findRandomTreasuryUtxo(
134
- context.lucid,
135
- sysParams.validatorHashes.treasuryHash,
136
- ),
137
- };
138
- }
139
-
140
63
  async function findPrice(
141
64
  context: MyContext,
142
65
  sysParams: SystemParams,
143
66
  asset: string,
144
67
  ): Promise<OnChainDecimal> {
145
- const orefs = await findAllNecessaryOrefs(context, sysParams, asset);
68
+ const orefs = await findAllNecessaryOrefs(context.lucid, sysParams, asset);
146
69
 
147
70
  const priceOracleUtxo = matchSingle(
148
71
  await context.lucid.utxosByOutRef([orefs.priceOracleUtxo]),
@@ -160,7 +83,7 @@ async function findInterestDatum(
160
83
  sysParams: SystemParams,
161
84
  asset: string,
162
85
  ): Promise<InterestOracleDatum> {
163
- const orefs = await findAllNecessaryOrefs(context, sysParams, asset);
86
+ const orefs = await findAllNecessaryOrefs(context.lucid, sysParams, asset);
164
87
 
165
88
  const interestOracleUtxo = matchSingle(
166
89
  await context.lucid.utxosByOutRef([orefs.interestOracleUtxo]),
@@ -209,7 +132,7 @@ describe('CDP', () => {
209
132
 
210
133
  const asset = 'iUSD';
211
134
 
212
- const orefs = await findAllNecessaryOrefs(context, sysParams, asset);
135
+ const orefs = await findAllNecessaryOrefs(context.lucid, sysParams, asset);
213
136
 
214
137
  await runAndAwaitTx(
215
138
  context.lucid,
@@ -241,7 +164,11 @@ describe('CDP', () => {
241
164
  const initialCollateral = 10_000_000n;
242
165
 
243
166
  {
244
- const orefs = await findAllNecessaryOrefs(context, sysParams, asset);
167
+ const orefs = await findAllNecessaryOrefs(
168
+ context.lucid,
169
+ sysParams,
170
+ asset,
171
+ );
245
172
 
246
173
  await runAndAwaitTx(
247
174
  context.lucid,
@@ -270,7 +197,11 @@ describe('CDP', () => {
270
197
  pkh.hash,
271
198
  skh,
272
199
  );
273
- const orefs = await findAllNecessaryOrefs(context, sysParams, asset);
200
+ const orefs = await findAllNecessaryOrefs(
201
+ context.lucid,
202
+ sysParams,
203
+ asset,
204
+ );
274
205
 
275
206
  const [_, treasuryValChange] = await getValueChangeAtAddressAfterAction(
276
207
  context.lucid,
@@ -328,7 +259,11 @@ describe('CDP', () => {
328
259
  const initialCollateral = 15_000_000n;
329
260
 
330
261
  {
331
- const orefs = await findAllNecessaryOrefs(context, sysParams, asset);
262
+ const orefs = await findAllNecessaryOrefs(
263
+ context.lucid,
264
+ sysParams,
265
+ asset,
266
+ );
332
267
 
333
268
  await runAndAwaitTx(
334
269
  context.lucid,
@@ -357,7 +292,11 @@ describe('CDP', () => {
357
292
  pkh.hash,
358
293
  skh,
359
294
  );
360
- const orefs = await findAllNecessaryOrefs(context, sysParams, asset);
295
+ const orefs = await findAllNecessaryOrefs(
296
+ context.lucid,
297
+ sysParams,
298
+ asset,
299
+ );
361
300
 
362
301
  const [_, treasuryValChange] = await getValueChangeAtAddressAfterAction(
363
302
  context.lucid,
@@ -415,7 +354,11 @@ describe('CDP', () => {
415
354
  const initialCollateral = 12_000_000n;
416
355
 
417
356
  {
418
- const orefs = await findAllNecessaryOrefs(context, sysParams, asset);
357
+ const orefs = await findAllNecessaryOrefs(
358
+ context.lucid,
359
+ sysParams,
360
+ asset,
361
+ );
419
362
 
420
363
  await runAndAwaitTx(
421
364
  context.lucid,
@@ -444,7 +387,11 @@ describe('CDP', () => {
444
387
  pkh.hash,
445
388
  skh,
446
389
  );
447
- const orefs = await findAllNecessaryOrefs(context, sysParams, asset);
390
+ const orefs = await findAllNecessaryOrefs(
391
+ context.lucid,
392
+ sysParams,
393
+ asset,
394
+ );
448
395
 
449
396
  const [_, treasuryValChange] = await getValueChangeAtAddressAfterAction(
450
397
  context.lucid,
@@ -502,7 +449,11 @@ describe('CDP', () => {
502
449
  const initialCollateral = 12_000_000n;
503
450
 
504
451
  {
505
- const orefs = await findAllNecessaryOrefs(context, sysParams, asset);
452
+ const orefs = await findAllNecessaryOrefs(
453
+ context.lucid,
454
+ sysParams,
455
+ asset,
456
+ );
506
457
 
507
458
  await runAndAwaitTx(
508
459
  context.lucid,
@@ -531,7 +482,11 @@ describe('CDP', () => {
531
482
  pkh.hash,
532
483
  skh,
533
484
  );
534
- const orefs = await findAllNecessaryOrefs(context, sysParams, asset);
485
+ const orefs = await findAllNecessaryOrefs(
486
+ context.lucid,
487
+ sysParams,
488
+ asset,
489
+ );
535
490
 
536
491
  const [_, treasuryValChange] = await getValueChangeAtAddressAfterAction(
537
492
  context.lucid,
@@ -586,7 +541,11 @@ describe('CDP', () => {
586
541
  const asset = 'iUSD';
587
542
 
588
543
  {
589
- const orefs = await findAllNecessaryOrefs(context, sysParams, asset);
544
+ const orefs = await findAllNecessaryOrefs(
545
+ context.lucid,
546
+ sysParams,
547
+ asset,
548
+ );
590
549
 
591
550
  await runAndAwaitTx(
592
551
  context.lucid,
@@ -616,7 +575,11 @@ describe('CDP', () => {
616
575
  skh,
617
576
  );
618
577
 
619
- const orefs = await findAllNecessaryOrefs(context, sysParams, asset);
578
+ const orefs = await findAllNecessaryOrefs(
579
+ context.lucid,
580
+ sysParams,
581
+ asset,
582
+ );
620
583
 
621
584
  await runAndAwaitTx(
622
585
  context.lucid,
@@ -647,7 +610,7 @@ describe('CDP', () => {
647
610
 
648
611
  {
649
612
  const orefs = await findAllNecessaryOrefs(
650
- context,
613
+ context.lucid,
651
614
  sysParams,
652
615
  iusdAssetInfo.iassetTokenNameAscii,
653
616
  );
@@ -674,7 +637,7 @@ describe('CDP', () => {
674
637
  context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
675
638
 
676
639
  const orefs = await findAllNecessaryOrefs(
677
- context,
640
+ context.lucid,
678
641
  sysParams,
679
642
  iusdAssetInfo.iassetTokenNameAscii,
680
643
  );
@@ -713,7 +676,7 @@ describe('CDP', () => {
713
676
  );
714
677
 
715
678
  const orefs = await findAllNecessaryOrefs(
716
- context,
679
+ context.lucid,
717
680
  sysParams,
718
681
  iusdAssetInfo.iassetTokenNameAscii,
719
682
  );
@@ -750,7 +713,7 @@ describe('CDP', () => {
750
713
  );
751
714
 
752
715
  const orefs = await findAllNecessaryOrefs(
753
- context,
716
+ context.lucid,
754
717
  sysParams,
755
718
  iusdAssetInfo.iassetTokenNameAscii,
756
719
  );
@@ -801,7 +764,7 @@ describe('CDP', () => {
801
764
 
802
765
  {
803
766
  const orefs = await findAllNecessaryOrefs(
804
- context,
767
+ context.lucid,
805
768
  sysParams,
806
769
  iusdAssetInfo.iassetTokenNameAscii,
807
770
  );
@@ -835,7 +798,7 @@ describe('CDP', () => {
835
798
  );
836
799
 
837
800
  const orefs = await findAllNecessaryOrefs(
838
- context,
801
+ context.lucid,
839
802
  sysParams,
840
803
  iusdAssetInfo.iassetTokenNameAscii,
841
804
  );
@@ -869,7 +832,7 @@ describe('CDP', () => {
869
832
  );
870
833
 
871
834
  const orefs = await findAllNecessaryOrefs(
872
- context,
835
+ context.lucid,
873
836
  sysParams,
874
837
  iusdAssetInfo.iassetTokenNameAscii,
875
838
  );
@@ -916,7 +879,7 @@ describe('CDP', () => {
916
879
 
917
880
  {
918
881
  const orefs = await findAllNecessaryOrefs(
919
- context,
882
+ context.lucid,
920
883
  sysParams,
921
884
  iusdAssetInfo.iassetTokenNameAscii,
922
885
  );
@@ -943,7 +906,7 @@ describe('CDP', () => {
943
906
 
944
907
  {
945
908
  const orefs = await findAllNecessaryOrefs(
946
- context,
909
+ context.lucid,
947
910
  sysParams,
948
911
  iusdAssetInfo.iassetTokenNameAscii,
949
912
  );
@@ -978,7 +941,7 @@ describe('CDP', () => {
978
941
  // Process the create account request
979
942
  {
980
943
  const orefs = await findAllNecessaryOrefs(
981
- context,
944
+ context.lucid,
982
945
  sysParams,
983
946
  iusdAssetInfo.iassetTokenNameAscii,
984
947
  );
@@ -1018,7 +981,7 @@ describe('CDP', () => {
1018
981
  );
1019
982
 
1020
983
  const orefs = await findAllNecessaryOrefs(
1021
- context,
984
+ context.lucid,
1022
985
  sysParams,
1023
986
  iusdAssetInfo.iassetTokenNameAscii,
1024
987
  );
@@ -1055,7 +1018,7 @@ describe('CDP', () => {
1055
1018
  );
1056
1019
 
1057
1020
  const orefs = await findAllNecessaryOrefs(
1058
- context,
1021
+ context.lucid,
1059
1022
  sysParams,
1060
1023
  iusdAssetInfo.iassetTokenNameAscii,
1061
1024
  );
@@ -1086,7 +1049,7 @@ describe('CDP', () => {
1086
1049
  );
1087
1050
 
1088
1051
  const orefs = await findAllNecessaryOrefs(
1089
- context,
1052
+ context.lucid,
1090
1053
  sysParams,
1091
1054
  iusdAssetInfo.iassetTokenNameAscii,
1092
1055
  );
@@ -1106,7 +1069,7 @@ describe('CDP', () => {
1106
1069
 
1107
1070
  {
1108
1071
  const orefs = await findAllNecessaryOrefs(
1109
- context,
1072
+ context.lucid,
1110
1073
  sysParams,
1111
1074
  iusdAssetInfo.iassetTokenNameAscii,
1112
1075
  );
@@ -1130,7 +1093,7 @@ describe('CDP', () => {
1130
1093
 
1131
1094
  {
1132
1095
  const orefs = await findAllNecessaryOrefs(
1133
- context,
1096
+ context.lucid,
1134
1097
  sysParams,
1135
1098
  iusdAssetInfo.iassetTokenNameAscii,
1136
1099
  );
@@ -1157,7 +1120,7 @@ describe('CDP', () => {
1157
1120
 
1158
1121
  {
1159
1122
  const orefs = await findAllNecessaryOrefs(
1160
- context,
1123
+ context.lucid,
1161
1124
  sysParams,
1162
1125
  iusdAssetInfo.iassetTokenNameAscii,
1163
1126
  );
@@ -1192,7 +1155,7 @@ describe('CDP', () => {
1192
1155
  // Process the create account request
1193
1156
  {
1194
1157
  const orefs = await findAllNecessaryOrefs(
1195
- context,
1158
+ context.lucid,
1196
1159
  sysParams,
1197
1160
  iusdAssetInfo.iassetTokenNameAscii,
1198
1161
  );
@@ -1232,7 +1195,7 @@ describe('CDP', () => {
1232
1195
  );
1233
1196
 
1234
1197
  const orefs = await findAllNecessaryOrefs(
1235
- context,
1198
+ context.lucid,
1236
1199
  sysParams,
1237
1200
  iusdAssetInfo.iassetTokenNameAscii,
1238
1201
  );
@@ -1269,7 +1232,7 @@ describe('CDP', () => {
1269
1232
  );
1270
1233
 
1271
1234
  const orefs = await findAllNecessaryOrefs(
1272
- context,
1235
+ context.lucid,
1273
1236
  sysParams,
1274
1237
  iusdAssetInfo.iassetTokenNameAscii,
1275
1238
  );
@@ -1300,7 +1263,7 @@ describe('CDP', () => {
1300
1263
  );
1301
1264
 
1302
1265
  const orefs = await findAllNecessaryOrefs(
1303
- context,
1266
+ context.lucid,
1304
1267
  sysParams,
1305
1268
  iusdAssetInfo.iassetTokenNameAscii,
1306
1269
  );
@@ -1320,7 +1283,7 @@ describe('CDP', () => {
1320
1283
 
1321
1284
  {
1322
1285
  const orefs = await findAllNecessaryOrefs(
1323
- context,
1286
+ context.lucid,
1324
1287
  sysParams,
1325
1288
  iusdAssetInfo.iassetTokenNameAscii,
1326
1289
  );
@@ -1344,7 +1307,7 @@ describe('CDP', () => {
1344
1307
 
1345
1308
  await repeat(3, async () => {
1346
1309
  const orefs = await findAllNecessaryOrefs(
1347
- context,
1310
+ context.lucid,
1348
1311
  sysParams,
1349
1312
  iusdAssetInfo.iassetTokenNameAscii,
1350
1313
  );
@@ -1368,7 +1331,7 @@ describe('CDP', () => {
1368
1331
 
1369
1332
  {
1370
1333
  const orefs = await findAllNecessaryOrefs(
1371
- context,
1334
+ context.lucid,
1372
1335
  sysParams,
1373
1336
  iusdAssetInfo.iassetTokenNameAscii,
1374
1337
  );
@@ -1399,7 +1362,7 @@ describe('CDP', () => {
1399
1362
 
1400
1363
  for (const cdp of activeCdps) {
1401
1364
  const orefs = await findAllNecessaryOrefs(
1402
- context,
1365
+ context.lucid,
1403
1366
  sysParams,
1404
1367
  iusdAssetInfo.iassetTokenNameAscii,
1405
1368
  );
@@ -1447,7 +1410,7 @@ describe('CDP', () => {
1447
1410
 
1448
1411
  {
1449
1412
  const orefs = await findAllNecessaryOrefs(
1450
- context,
1413
+ context.lucid,
1451
1414
  sysParams,
1452
1415
  iusdAssetInfo.iassetTokenNameAscii,
1453
1416
  );
@@ -1482,7 +1445,7 @@ describe('CDP', () => {
1482
1445
  // Process the create account request
1483
1446
  {
1484
1447
  const orefs = await findAllNecessaryOrefs(
1485
- context,
1448
+ context.lucid,
1486
1449
  sysParams,
1487
1450
  iusdAssetInfo.iassetTokenNameAscii,
1488
1451
  );
@@ -1528,7 +1491,7 @@ describe('CDP', () => {
1528
1491
  ).toBeTruthy();
1529
1492
 
1530
1493
  const orefs = await findAllNecessaryOrefs(
1531
- context,
1494
+ context.lucid,
1532
1495
  sysParams,
1533
1496
  iusdAssetInfo.iassetTokenNameAscii,
1534
1497
  );
@@ -1548,7 +1511,7 @@ describe('CDP', () => {
1548
1511
 
1549
1512
  {
1550
1513
  const orefs = await findAllNecessaryOrefs(
1551
- context,
1514
+ context.lucid,
1552
1515
  sysParams,
1553
1516
  iusdAssetInfo.iassetTokenNameAscii,
1554
1517
  );
@@ -285,7 +285,7 @@ async function initializeAsset(
285
285
  const interestOracleTokenName = asset.name + '_ORACLE';
286
286
  const [startInterestOracleTx, interestOracleNft] = await startInterestOracle(
287
287
  0n,
288
- asset.initerestOracle.initialInterestRate,
288
+ asset.interestOracle.initialInterestRate,
289
289
  0n,
290
290
  {
291
291
  owner: pkh.hash,