@indigo-labs/indigo-sdk 0.4.3 → 0.5.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 (54) hide show
  1. package/.claude/settings.local.json +7 -0
  2. package/dist/index.d.mts +992 -905
  3. package/dist/index.d.ts +992 -905
  4. package/dist/index.js +2346 -2155
  5. package/dist/index.mjs +1925 -1750
  6. package/package.json +13 -21
  7. package/scripts/bench.sh +0 -0
  8. package/src/contracts/cdp/helpers.ts +7 -6
  9. package/src/contracts/cdp/transactions.ts +8 -29
  10. package/src/contracts/gov/transactions.ts +15 -17
  11. package/src/contracts/iasset/helpers.ts +2 -7
  12. package/src/contracts/initialize/actions.ts +0 -2
  13. package/src/contracts/initialize/helpers.ts +0 -4
  14. package/src/contracts/interest-collection/transactions.ts +2 -5
  15. package/src/contracts/interest-oracle/helpers.ts +4 -0
  16. package/src/contracts/interest-oracle/transactions.ts +1 -4
  17. package/src/contracts/price-oracle/helpers.ts +5 -11
  18. package/src/contracts/price-oracle/transactions.ts +2 -7
  19. package/src/contracts/rob/transactions.ts +0 -2
  20. package/src/contracts/rob-leverage/transactions.ts +1 -4
  21. package/{tests/queries/stability-pool-queries.ts → src/contracts/stability-pool/queries.ts} +22 -14
  22. package/src/contracts/stability-pool/transactions.ts +2 -8
  23. package/src/contracts/stableswap/helpers.ts +369 -1
  24. package/src/contracts/stableswap/transactions.ts +43 -191
  25. package/src/contracts/staking/transactions.ts +2 -7
  26. package/src/index.ts +4 -3
  27. package/tests/cdp/actions.ts +0 -11
  28. package/tests/cdp/cdp-helpers.ts +2 -2
  29. package/tests/cdp/cdp-queries.ts +8 -5
  30. package/tests/cdp/cdp.test.ts +409 -620
  31. package/tests/cdp/transactions-mutated.ts +30 -25
  32. package/tests/endpoints/initialize.ts +0 -2
  33. package/tests/gov/actions.ts +7 -32
  34. package/tests/gov/gov.test.ts +169 -401
  35. package/tests/indigo-test-helpers.ts +0 -1
  36. package/tests/initialize.test.ts +15 -20
  37. package/tests/interest-collection/interest-collection.test.ts +0 -4
  38. package/tests/interest-oracle.test.ts +1 -8
  39. package/tests/price-oracle/actions.ts +6 -8
  40. package/tests/price-oracle/price-oracle.test.ts +1 -13
  41. package/tests/price-oracle/transactions-mutated.ts +1 -4
  42. package/tests/pyth/pyth-feeds.test.ts +943 -0
  43. package/tests/pyth/pyth-indigo.test.ts +8 -12
  44. package/tests/pyth/pyth.test.ts +1 -2
  45. package/tests/rob/actions.ts +0 -2
  46. package/tests/rob/rob-leverage.test.ts +164 -220
  47. package/tests/rob/rob.test.ts +158 -263
  48. package/tests/rob/transactions-mutated.ts +7 -18
  49. package/tests/stability-pool/actions.ts +31 -22
  50. package/tests/stability-pool.test.ts +226 -319
  51. package/tests/stableswap/stableswap-actions.ts +0 -1
  52. package/tests/stableswap/stableswap.test.ts +226 -4
  53. package/tests/staking.test.ts +2 -13
  54. package/tests/treasury/treasury.test.ts +6 -30
@@ -44,7 +44,6 @@ export async function runCreateStableswapPool(
44
44
  null,
45
45
  context.systemParams,
46
46
  context.lucid,
47
- context.emulator.slot,
48
47
  (
49
48
  await findGov(
50
49
  context.lucid,
@@ -1,4 +1,4 @@
1
- import { assert, beforeEach, test } from 'vitest';
1
+ import { assert, beforeEach, expect, test } from 'vitest';
2
2
  import {
3
3
  IndigoTestContext,
4
4
  repeat,
@@ -41,6 +41,7 @@ import {
41
41
  } from './stableswap-queries';
42
42
  import { feedPriceOracleTx } from '../../src/contracts/price-oracle/transactions';
43
43
  import {
44
+ adaAssetClass,
44
45
  addressFromBech32,
45
46
  assetClassValueOf,
46
47
  lovelacesAmt,
@@ -53,7 +54,10 @@ import { array as A } from 'fp-ts';
53
54
  import { runOpenCdp } from '../cdp/actions';
54
55
  import { Data } from '@evolution-sdk/evolution';
55
56
  import { serialiseStableswapOrderDatum } from '../../src/contracts/stableswap/types-new';
56
- import { BASE_MAX_EXECUTION_FEE } from '../../src/contracts/stableswap/helpers';
57
+ import {
58
+ BASE_MAX_EXECUTION_FEE,
59
+ pickValidSatisfiableOrders,
60
+ } from '../../src/contracts/stableswap/helpers';
57
61
  import { StableswapPoolContent } from '../../src/contracts/cdp/types-new';
58
62
  import { mutatedBatchProcessStableswapOrders } from './transactions-mutated';
59
63
  import { expectScriptFailure } from '../utils/asserts';
@@ -63,6 +67,7 @@ import {
63
67
  } from '../../src/contracts/treasury/queries';
64
68
  import { createUtxoAtTreasury } from '../endpoints/treasury';
65
69
  import { rationalFromInt, rationalZero } from '../../src/types/rational';
70
+ import { refreshPriceOracle } from '../price-oracle/actions';
66
71
 
67
72
  beforeEach<IndigoTestContext>(async (context: IndigoTestContext) => {
68
73
  await createIndigoTestContext(context);
@@ -391,6 +396,225 @@ test<IndigoTestContext>('Stableswap - Batch a single order to mint with no minti
391
396
  );
392
397
  });
393
398
 
399
+ test<IndigoTestContext>('Stableswap - pickValidSatisfiableOrders', async (context: IndigoTestContext) => {
400
+ context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
401
+
402
+ await runCreateStableswapPool(
403
+ context.assetConfigs[0].iassetTokenNameAscii,
404
+ EXAMPLE_TOKEN_1,
405
+ context,
406
+ rationalFromInt(1n),
407
+ { numerator: 5n, denominator: 1000n },
408
+ { numerator: 5n, denominator: 1000n },
409
+ );
410
+
411
+ const stableswapPool = await findStableswapPool(
412
+ context.lucid,
413
+ context.systemParams.validatorHashes.cdpHash,
414
+ fromSystemParamsAsset(context.systemParams.stableswapParams.cdpToken),
415
+ fromText(context.assetConfigs[0].iassetTokenNameAscii),
416
+ EXAMPLE_TOKEN_1,
417
+ );
418
+
419
+ await refreshPriceOracle(
420
+ context,
421
+ context.systemParams,
422
+ context.assetConfigs[0],
423
+ adaAssetClass,
424
+ );
425
+
426
+ context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
427
+
428
+ // Add some iAssets to wallet
429
+ await runAndAwaitTx(
430
+ context.lucid,
431
+ runOpenCdp(
432
+ context,
433
+ context.systemParams,
434
+ context.assetConfigs[0].iassetTokenNameAscii,
435
+ adaAssetClass,
436
+ 100_000_000n,
437
+ 50_000_000n,
438
+ ),
439
+ );
440
+
441
+ // mint order
442
+ await runAndAwaitTx(
443
+ context.lucid,
444
+ createStableswapOrder(
445
+ context.assetConfigs[0].iassetTokenNameAscii,
446
+ EXAMPLE_TOKEN_1,
447
+ 10_000_000n,
448
+ true,
449
+ stableswapPool.datum,
450
+ context.systemParams,
451
+ context.lucid,
452
+ ),
453
+ );
454
+
455
+ // mint order, can't process because max exec fee is low
456
+ const mintOrderMaxExecFeeTx = await runAndAwaitTx(
457
+ context.lucid,
458
+ createStableswapOrder(
459
+ context.assetConfigs[0].iassetTokenNameAscii,
460
+ EXAMPLE_TOKEN_1,
461
+ 3_000_000n,
462
+ true,
463
+ stableswapPool.datum,
464
+ context.systemParams,
465
+ context.lucid,
466
+ await context.lucid.wallet().address(),
467
+ undefined,
468
+ 1n,
469
+ ),
470
+ );
471
+
472
+ // mint order, this one shouldn't be processed because of maxFeeRatio
473
+ const mintOrderMaxFeeTx = await runAndAwaitTx(
474
+ context.lucid,
475
+ createStableswapOrder(
476
+ context.assetConfigs[0].iassetTokenNameAscii,
477
+ EXAMPLE_TOKEN_1,
478
+ 10_000_000n,
479
+ true,
480
+ stableswapPool.datum,
481
+ context.systemParams,
482
+ context.lucid,
483
+ await context.lucid.wallet().address(),
484
+ undefined,
485
+ BASE_MAX_EXECUTION_FEE,
486
+ 0n,
487
+ rationalZero,
488
+ ),
489
+ );
490
+
491
+ // Redemption order, this can't be processed because of lack of liquidity
492
+ const redeemOrderTx0 = await runAndAwaitTx(
493
+ context.lucid,
494
+ createStableswapOrder(
495
+ context.assetConfigs[0].iassetTokenNameAscii,
496
+ EXAMPLE_TOKEN_1,
497
+ 20_000_000n,
498
+ false,
499
+ stableswapPool.datum,
500
+ context.systemParams,
501
+ context.lucid,
502
+ ),
503
+ );
504
+
505
+ // Redemption order
506
+ await runAndAwaitTx(
507
+ context.lucid,
508
+ createStableswapOrder(
509
+ context.assetConfigs[0].iassetTokenNameAscii,
510
+ EXAMPLE_TOKEN_1,
511
+ 5_000_000n,
512
+ false,
513
+ stableswapPool.datum,
514
+ context.systemParams,
515
+ context.lucid,
516
+ ),
517
+ );
518
+
519
+ // Redemption order, can't be satisfied because of maxFeeRatio
520
+ const redeemOrderMaxFeeTx = await runAndAwaitTx(
521
+ context.lucid,
522
+ createStableswapOrder(
523
+ context.assetConfigs[0].iassetTokenNameAscii,
524
+ EXAMPLE_TOKEN_1,
525
+ 1_000_000n,
526
+ false,
527
+ stableswapPool.datum,
528
+ context.systemParams,
529
+ context.lucid,
530
+ await context.lucid.wallet().address(),
531
+ undefined,
532
+ BASE_MAX_EXECUTION_FEE,
533
+ 0n,
534
+ rationalZero,
535
+ ),
536
+ );
537
+
538
+ // redemption order, can't process because max exec fee is low
539
+ const redemptionOrderMaxExecFeeTx = await runAndAwaitTx(
540
+ context.lucid,
541
+ createStableswapOrder(
542
+ context.assetConfigs[0].iassetTokenNameAscii,
543
+ EXAMPLE_TOKEN_1,
544
+ 1_000_000n,
545
+ false,
546
+ stableswapPool.datum,
547
+ context.systemParams,
548
+ context.lucid,
549
+ await context.lucid.wallet().address(),
550
+ undefined,
551
+ 1n,
552
+ ),
553
+ );
554
+
555
+ const stableswapOrders = await findStableswapOrders(
556
+ context.lucid,
557
+ context.systemParams.validatorHashes.stableswapHash,
558
+ fromText(context.assetConfigs[0].iassetTokenNameAscii),
559
+ EXAMPLE_TOKEN_1,
560
+ );
561
+
562
+ await createUtxoAtTreasury(
563
+ mkLovelacesOf(2_000_000n),
564
+ context.systemParams,
565
+ context,
566
+ );
567
+
568
+ const treasuryUtxo = await findRandomTreasuryUtxoWithOnlyAda(
569
+ context.lucid,
570
+ context.systemParams,
571
+ );
572
+
573
+ const satisfiableOrders = pickValidSatisfiableOrders(
574
+ stableswapOrders,
575
+ stableswapPool,
576
+ context.systemParams,
577
+ { ignoreMaxExecutionFeeConstraint: false },
578
+ );
579
+
580
+ expect(satisfiableOrders.length, 'Only 2 orders are satisfiable').toEqual(2);
581
+
582
+ await runAndAwaitTx(
583
+ context.lucid,
584
+ batchProcessStableswapOrders(
585
+ satisfiableOrders.map((o) => o.utxo),
586
+ stableswapPool.utxo,
587
+ treasuryUtxo,
588
+ context.systemParams,
589
+ context.lucid,
590
+ ),
591
+ );
592
+
593
+ ///////////////////////////////////
594
+ // Checks after last transaction //
595
+ ///////////////////////////////////
596
+
597
+ const remainingOrders = await findStableswapOrders(
598
+ context.lucid,
599
+ context.systemParams.validatorHashes.stableswapHash,
600
+ fromText(context.assetConfigs[0].iassetTokenNameAscii),
601
+ EXAMPLE_TOKEN_1,
602
+ );
603
+
604
+ expect(
605
+ remainingOrders.map((o) => o.utxo.txHash),
606
+ 'Expected different orders to not be processed',
607
+ ).toEqual(
608
+ expect.arrayContaining([
609
+ redeemOrderMaxFeeTx,
610
+ redeemOrderTx0,
611
+ mintOrderMaxFeeTx,
612
+ mintOrderMaxExecFeeTx,
613
+ redemptionOrderMaxExecFeeTx,
614
+ ]),
615
+ );
616
+ });
617
+
394
618
  test<IndigoTestContext>('Stableswap - Batch a single order to mint with collateral asset in the pool', async (context: IndigoTestContext) => {
395
619
  context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
396
620
 
@@ -989,7 +1213,6 @@ test<IndigoTestContext>('Stableswap - Batch a single order to redeem emptying th
989
1213
  priceOracleUtxo!,
990
1214
  rationalFromInt(1n),
991
1215
  context.assetConfigs[0].collateralAssets[0].oracleParams!,
992
- context.emulator.slot,
993
1216
  ),
994
1217
  );
995
1218
 
@@ -3549,7 +3772,6 @@ test<IndigoTestContext>('Stableswap - Batch an order to mint with an order to re
3549
3772
  priceOracleUtxo!,
3550
3773
  rationalFromInt(1n),
3551
3774
  context.assetConfigs[0].collateralAssets[0].oracleParams!,
3552
- context.emulator.slot,
3553
3775
  ),
3554
3776
  );
3555
3777
 
@@ -67,7 +67,6 @@ test<IndigoTestContext>('Staking - Adjust Position', async ({
67
67
  1_000_000n,
68
68
  systemParams,
69
69
  lucid,
70
- emulator.slot,
71
70
  ),
72
71
  lucid,
73
72
  emulator,
@@ -106,12 +105,7 @@ test.todo<IndigoTestContext>(
106
105
 
107
106
  await benchmarkAndAwaitTx(
108
107
  'Staking - Close Position',
109
- await closeStakingPosition(
110
- myStakingPosition.utxo,
111
- systemParams,
112
- lucid,
113
- emulator.slot,
114
- ),
108
+ await closeStakingPosition(myStakingPosition.utxo, systemParams, lucid),
115
109
  lucid,
116
110
  emulator,
117
111
  );
@@ -170,12 +164,7 @@ test<IndigoTestContext>('Staking - Distribute ADA to Stakers', async ({
170
164
  () =>
171
165
  runAndAwaitTx(
172
166
  lucid,
173
- closeStakingPosition(
174
- myStakingPosition.utxo,
175
- systemParams,
176
- lucid,
177
- emulator.slot,
178
- ),
167
+ closeStakingPosition(myStakingPosition.utxo, systemParams, lucid),
179
168
  ),
180
169
  );
181
170
 
@@ -161,11 +161,7 @@ describe('Treasury', () => {
161
161
  });
162
162
 
163
163
  test<MyContext>('Merge (3 lovelace UTxOs)', async (context: MyContext) => {
164
- const [sysParams, __] = await init(
165
- context.lucid,
166
- [iusdInitialAssetCfg()],
167
- context.emulator.slot,
168
- );
164
+ const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg()]);
169
165
 
170
166
  context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
171
167
 
@@ -182,11 +178,7 @@ describe('Treasury', () => {
182
178
  });
183
179
 
184
180
  test<MyContext>('Merge (3 INDY UTxOs)', async (context: MyContext) => {
185
- const [sysParams, __] = await init(
186
- context.lucid,
187
- [iusdInitialAssetCfg()],
188
- context.emulator.slot,
189
- );
181
+ const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg()]);
190
182
 
191
183
  context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
192
184
 
@@ -212,11 +204,7 @@ describe('Treasury', () => {
212
204
  });
213
205
 
214
206
  test<MyContext>('Merge (fail, 1 lovelace, 2 INDY UTxOs)', async (context: MyContext) => {
215
- const [sysParams, __] = await init(
216
- context.lucid,
217
- [iusdInitialAssetCfg()],
218
- context.emulator.slot,
219
- );
207
+ const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg()]);
220
208
 
221
209
  context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
222
210
 
@@ -237,11 +225,7 @@ describe('Treasury', () => {
237
225
  });
238
226
 
239
227
  test<MyContext>('Split (12 assets)', async (context: MyContext) => {
240
- const [sysParams, __] = await init(
241
- context.lucid,
242
- [iusdInitialAssetCfg()],
243
- context.emulator.slot,
244
- );
228
+ const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg()]);
245
229
 
246
230
  context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
247
231
 
@@ -271,11 +255,7 @@ describe('Treasury', () => {
271
255
  });
272
256
 
273
257
  test<MyContext>('Split (fail, lovelace only)', async (context: MyContext) => {
274
- const [sysParams, __] = await init(
275
- context.lucid,
276
- [iusdInitialAssetCfg()],
277
- context.emulator.slot,
278
- );
258
+ const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg()]);
279
259
 
280
260
  context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
281
261
 
@@ -286,11 +266,7 @@ describe('Treasury', () => {
286
266
  });
287
267
 
288
268
  test<MyContext>('Collect non-positive amount or negative extra lovelaces fails', async (context: MyContext) => {
289
- const [sysParams, __] = await init(
290
- context.lucid,
291
- [iusdInitialAssetCfg()],
292
- context.emulator.slot,
293
- );
269
+ const [sysParams, __] = await init(context.lucid, [iusdInitialAssetCfg()]);
294
270
 
295
271
  context.lucid.selectWallet.fromSeed(context.users.user.seedPhrase);
296
272