@indigo-labs/indigo-sdk 0.4.3 → 0.4.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.
@@ -0,0 +1,943 @@
1
+ import {
2
+ fromHex,
3
+ SpendingValidator,
4
+ validatorToScriptHash,
5
+ } from '@lucid-evolution/lucid';
6
+ import {
7
+ AssetClassSP,
8
+ fromSysParamsPythFeedParams,
9
+ mkPythFeedValidator,
10
+ PythFeedParamsSP,
11
+ toDataDerivedPythPrice,
12
+ } from '../../src';
13
+ import { expect, test } from 'vitest';
14
+
15
+ /******************************
16
+ ** Pyth configs for iAssets **
17
+ ******************************/
18
+
19
+ const pythStateAssetClass: AssetClassSP = [
20
+ {
21
+ unCurrencySymbol:
22
+ 'c935c937d0deda8975142c7b77aeef8f8cd48791e89a8ca7a0edc154',
23
+ },
24
+ {
25
+ unTokenName: 'Pyth State',
26
+ },
27
+ ];
28
+
29
+ /** Config: 1 / ADA/USD => USD/ADA */
30
+ test('iusd pyth feed', () => {
31
+ const IUSD_PYTH_FEED_PARAMS: PythFeedParamsSP = {
32
+ config: {
33
+ tag: 'inverse',
34
+ val: {
35
+ tag: 'value',
36
+ val: {
37
+ priceFeedId: 16,
38
+ },
39
+ },
40
+ },
41
+ pythStatePolicyId: pythStateAssetClass[0],
42
+ };
43
+
44
+ const iusdPythFeedValidator: SpendingValidator = mkPythFeedValidator(
45
+ fromSysParamsPythFeedParams(IUSD_PYTH_FEED_PARAMS),
46
+ );
47
+
48
+ const iusdPythFeedValidatorHash = validatorToScriptHash(
49
+ iusdPythFeedValidator,
50
+ );
51
+
52
+ expect(iusdPythFeedValidatorHash).toEqual(
53
+ // Rebuild the params without conversion functions as well.
54
+ validatorToScriptHash(
55
+ mkPythFeedValidator({
56
+ config: {
57
+ Inverse: {
58
+ value: toDataDerivedPythPrice({
59
+ Value: { configuration: { priceFeedId: 16n } },
60
+ }),
61
+ },
62
+ },
63
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
64
+ }),
65
+ ),
66
+ );
67
+
68
+ expect(iusdPythFeedValidatorHash).toEqual(
69
+ '4cb907af98c1ed5ee9f251691a0ec909f2a26b583ed271f2a88a55cb',
70
+ );
71
+ });
72
+
73
+ /** Config: BTC/USD / ADA/USD => BTC/ADA */
74
+ test('ibtc pyth feed', () => {
75
+ const IBTC_PYTH_FEED_PARAMS: PythFeedParamsSP = {
76
+ config: {
77
+ tag: 'divide',
78
+ val: [
79
+ {
80
+ tag: 'value',
81
+ val: {
82
+ priceFeedId: 1,
83
+ },
84
+ },
85
+ {
86
+ tag: 'value',
87
+ val: {
88
+ priceFeedId: 16,
89
+ },
90
+ },
91
+ ],
92
+ },
93
+ pythStatePolicyId: pythStateAssetClass[0],
94
+ };
95
+
96
+ const ibtcPythFeedValidator: SpendingValidator = mkPythFeedValidator(
97
+ fromSysParamsPythFeedParams(IBTC_PYTH_FEED_PARAMS),
98
+ );
99
+
100
+ const ibtcPythFeedValidatorHash = validatorToScriptHash(
101
+ ibtcPythFeedValidator,
102
+ );
103
+
104
+ expect(ibtcPythFeedValidatorHash).toEqual(
105
+ // Rebuild the params without conversion functions as well.
106
+ validatorToScriptHash(
107
+ mkPythFeedValidator({
108
+ config: {
109
+ Divide: {
110
+ x: toDataDerivedPythPrice({
111
+ Value: { configuration: { priceFeedId: 1n } },
112
+ }),
113
+ y: toDataDerivedPythPrice({
114
+ Value: { configuration: { priceFeedId: 16n } },
115
+ }),
116
+ },
117
+ },
118
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
119
+ }),
120
+ ),
121
+ );
122
+
123
+ expect(ibtcPythFeedValidatorHash).toEqual(
124
+ '77f65e4d14ed8106e8a97814bdb0e7688f652fe41c71295a42f11a26',
125
+ );
126
+ });
127
+
128
+ /** Config: ETH/USD / ADA/USD => ETH/ADA */
129
+ test('ieth pyth feed', () => {
130
+ const IETH_PYTH_FEED_PARAMS: PythFeedParamsSP = {
131
+ config: {
132
+ tag: 'divide',
133
+ val: [
134
+ {
135
+ tag: 'value',
136
+ val: {
137
+ priceFeedId: 2,
138
+ },
139
+ },
140
+ {
141
+ tag: 'value',
142
+ val: {
143
+ priceFeedId: 16,
144
+ },
145
+ },
146
+ ],
147
+ },
148
+ pythStatePolicyId: pythStateAssetClass[0],
149
+ };
150
+
151
+ const iethPythFeedValidator: SpendingValidator = mkPythFeedValidator(
152
+ fromSysParamsPythFeedParams(IETH_PYTH_FEED_PARAMS),
153
+ );
154
+
155
+ const iethPythFeedValidatorHash = validatorToScriptHash(
156
+ iethPythFeedValidator,
157
+ );
158
+
159
+ expect(iethPythFeedValidatorHash).toEqual(
160
+ // Rebuild the params without conversion functions as well.
161
+ validatorToScriptHash(
162
+ mkPythFeedValidator({
163
+ config: {
164
+ Divide: {
165
+ x: toDataDerivedPythPrice({
166
+ Value: { configuration: { priceFeedId: 2n } },
167
+ }),
168
+ y: toDataDerivedPythPrice({
169
+ Value: { configuration: { priceFeedId: 16n } },
170
+ }),
171
+ },
172
+ },
173
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
174
+ }),
175
+ ),
176
+ );
177
+
178
+ expect(iethPythFeedValidatorHash).toEqual(
179
+ '893828eeaa8bf4322559da69b69f0f36795d430f5942e2472cef8a88',
180
+ );
181
+ });
182
+
183
+ /** Config: SOL/USD / ADA/USD => SOL/ADA */
184
+ test('isol pyth feed', () => {
185
+ const ISOL_PYTH_FEED_PARAMS: PythFeedParamsSP = {
186
+ config: {
187
+ tag: 'divide',
188
+ val: [
189
+ {
190
+ tag: 'value',
191
+ val: {
192
+ priceFeedId: 6,
193
+ },
194
+ },
195
+ {
196
+ tag: 'value',
197
+ val: {
198
+ priceFeedId: 16,
199
+ },
200
+ },
201
+ ],
202
+ },
203
+ pythStatePolicyId: pythStateAssetClass[0],
204
+ };
205
+
206
+ const isolPythFeedValidator: SpendingValidator = mkPythFeedValidator(
207
+ fromSysParamsPythFeedParams(ISOL_PYTH_FEED_PARAMS),
208
+ );
209
+
210
+ const isolPythFeedValidatorHash = validatorToScriptHash(
211
+ isolPythFeedValidator,
212
+ );
213
+
214
+ expect(isolPythFeedValidatorHash).toEqual(
215
+ // Rebuild the params without conversion functions as well.
216
+ validatorToScriptHash(
217
+ mkPythFeedValidator({
218
+ config: {
219
+ Divide: {
220
+ x: toDataDerivedPythPrice({
221
+ Value: { configuration: { priceFeedId: 6n } },
222
+ }),
223
+ y: toDataDerivedPythPrice({
224
+ Value: { configuration: { priceFeedId: 16n } },
225
+ }),
226
+ },
227
+ },
228
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
229
+ }),
230
+ ),
231
+ );
232
+
233
+ expect(isolPythFeedValidatorHash).toEqual(
234
+ '9a899983b90e2c2cfbc985cd34812a1ba393e169d7f7d277085ab14a',
235
+ );
236
+ });
237
+
238
+ /** Config: EUR/USD / ADA/USD => EUR/ADA */
239
+ test('ieur pyth feed', () => {
240
+ const IEUR_PYTH_FEED_PARAMS: PythFeedParamsSP = {
241
+ config: {
242
+ tag: 'divide',
243
+ val: [
244
+ {
245
+ tag: 'value',
246
+ val: {
247
+ priceFeedId: 327,
248
+ },
249
+ },
250
+ {
251
+ tag: 'value',
252
+ val: {
253
+ priceFeedId: 16,
254
+ },
255
+ },
256
+ ],
257
+ },
258
+ pythStatePolicyId: pythStateAssetClass[0],
259
+ };
260
+
261
+ const ieurPythFeedValidator: SpendingValidator = mkPythFeedValidator(
262
+ fromSysParamsPythFeedParams(IEUR_PYTH_FEED_PARAMS),
263
+ );
264
+
265
+ const ieurPythFeedValidatorHash = validatorToScriptHash(
266
+ ieurPythFeedValidator,
267
+ );
268
+
269
+ expect(ieurPythFeedValidatorHash).toEqual(
270
+ // Rebuild the params without conversion functions as well.
271
+ validatorToScriptHash(
272
+ mkPythFeedValidator({
273
+ config: {
274
+ Divide: {
275
+ x: toDataDerivedPythPrice({
276
+ Value: { configuration: { priceFeedId: 327n } },
277
+ }),
278
+ y: toDataDerivedPythPrice({
279
+ Value: { configuration: { priceFeedId: 16n } },
280
+ }),
281
+ },
282
+ },
283
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
284
+ }),
285
+ ),
286
+ );
287
+
288
+ expect(ieurPythFeedValidatorHash).toEqual(
289
+ '9da7071e0abb11aa4e1b669ae60592d3dbcaade6e9724c45b1a654eb',
290
+ );
291
+ });
292
+
293
+ /** Config: (1 / USD/JPY) / ADA/USD => JPY/ADA */
294
+ test('ijpy pyth feed', () => {
295
+ const IJPY_PYTH_FEED_PARAMS: PythFeedParamsSP = {
296
+ config: {
297
+ tag: 'divide',
298
+ val: [
299
+ {
300
+ tag: 'inverse',
301
+ val: {
302
+ tag: 'value',
303
+ val: {
304
+ priceFeedId: 340,
305
+ },
306
+ },
307
+ },
308
+ {
309
+ tag: 'value',
310
+ val: {
311
+ priceFeedId: 16,
312
+ },
313
+ },
314
+ ],
315
+ },
316
+ pythStatePolicyId: pythStateAssetClass[0],
317
+ };
318
+
319
+ const ijpyPythFeedValidator: SpendingValidator = mkPythFeedValidator(
320
+ fromSysParamsPythFeedParams(IJPY_PYTH_FEED_PARAMS),
321
+ );
322
+
323
+ const ijpyPythFeedValidatorHash = validatorToScriptHash(
324
+ ijpyPythFeedValidator,
325
+ );
326
+
327
+ expect(ijpyPythFeedValidatorHash).toEqual(
328
+ // Rebuild the params without conversion functions as well.
329
+ validatorToScriptHash(
330
+ mkPythFeedValidator({
331
+ config: {
332
+ Divide: {
333
+ x: toDataDerivedPythPrice({
334
+ Inverse: {
335
+ value: toDataDerivedPythPrice({
336
+ Value: { configuration: { priceFeedId: 340n } },
337
+ }),
338
+ },
339
+ }),
340
+ y: toDataDerivedPythPrice({
341
+ Value: { configuration: { priceFeedId: 16n } },
342
+ }),
343
+ },
344
+ },
345
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
346
+ }),
347
+ ),
348
+ );
349
+
350
+ expect(ijpyPythFeedValidatorHash).toEqual(
351
+ '0db1238594da8cb18260454e115dd63bd9789aad487ff1d80f59799a',
352
+ );
353
+ });
354
+
355
+ /** Config: 1 / NIGHT/USD => USD/NIGHT */
356
+ test('iusd night pyth feed', () => {
357
+ const IUSD_NIGHT_PYTH_FEED_PARAMS: PythFeedParamsSP = {
358
+ config: {
359
+ tag: 'inverse',
360
+ val: {
361
+ tag: 'value',
362
+ val: {
363
+ priceFeedId: 2970,
364
+ },
365
+ },
366
+ },
367
+ pythStatePolicyId: pythStateAssetClass[0],
368
+ };
369
+
370
+ const iusdNightPythFeedValidator: SpendingValidator = mkPythFeedValidator(
371
+ fromSysParamsPythFeedParams(IUSD_NIGHT_PYTH_FEED_PARAMS),
372
+ );
373
+
374
+ const iusdNightPythFeedValidatorHash = validatorToScriptHash(
375
+ iusdNightPythFeedValidator,
376
+ );
377
+
378
+ expect(iusdNightPythFeedValidatorHash).toEqual(
379
+ // Rebuild the params without conversion functions as well.
380
+ validatorToScriptHash(
381
+ mkPythFeedValidator({
382
+ config: {
383
+ Inverse: {
384
+ value: toDataDerivedPythPrice({
385
+ Value: { configuration: { priceFeedId: 2970n } },
386
+ }),
387
+ },
388
+ },
389
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
390
+ }),
391
+ ),
392
+ );
393
+
394
+ expect(iusdNightPythFeedValidatorHash).toEqual(
395
+ '1d4c0f85dcbcc230f1550f30574206c5b9bddff47b7b135edb12de69',
396
+ );
397
+ });
398
+
399
+ /** Config: (EUR / USD) / (NIGHT/USD) => EUR/NIGHT */
400
+ test('ieur night pyth feed', () => {
401
+ const IEUR_NIGHT_PYTH_FEED_PARAMS: PythFeedParamsSP = {
402
+ config: {
403
+ tag: 'divide',
404
+ val: [
405
+ {
406
+ tag: 'value',
407
+ val: {
408
+ priceFeedId: 327,
409
+ },
410
+ },
411
+ {
412
+ tag: 'value',
413
+ val: {
414
+ priceFeedId: 2970,
415
+ },
416
+ },
417
+ ],
418
+ },
419
+ pythStatePolicyId: pythStateAssetClass[0],
420
+ };
421
+
422
+ const ieurNightPythFeedValidator: SpendingValidator = mkPythFeedValidator(
423
+ fromSysParamsPythFeedParams(IEUR_NIGHT_PYTH_FEED_PARAMS),
424
+ );
425
+
426
+ const ieurNightPythFeedValidatorHash = validatorToScriptHash(
427
+ ieurNightPythFeedValidator,
428
+ );
429
+
430
+ expect(ieurNightPythFeedValidatorHash).toEqual(
431
+ // Rebuild the params without conversion functions as well.
432
+ validatorToScriptHash(
433
+ mkPythFeedValidator({
434
+ config: {
435
+ Divide: {
436
+ x: toDataDerivedPythPrice({
437
+ Value: { configuration: { priceFeedId: 327n } },
438
+ }),
439
+ y: toDataDerivedPythPrice({
440
+ Value: { configuration: { priceFeedId: 2970n } },
441
+ }),
442
+ },
443
+ },
444
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
445
+ }),
446
+ ),
447
+ );
448
+
449
+ expect(ieurNightPythFeedValidatorHash).toEqual(
450
+ '2104dd1545835d7b13f2dd482bcc3943cf42ec15fa968411d4632149',
451
+ );
452
+ });
453
+
454
+ /** Config: (1 / USD/JPY) / (NIGHT/USD) => JPY/NIGHT */
455
+ test('ijpy night pyth feed', () => {
456
+ const IJPY_NIGHT_PYTH_FEED_PARAMS: PythFeedParamsSP = {
457
+ config: {
458
+ tag: 'divide',
459
+ val: [
460
+ {
461
+ tag: 'inverse',
462
+ val: {
463
+ tag: 'value',
464
+ val: {
465
+ priceFeedId: 340,
466
+ },
467
+ },
468
+ },
469
+ {
470
+ tag: 'value',
471
+ val: {
472
+ priceFeedId: 2970,
473
+ },
474
+ },
475
+ ],
476
+ },
477
+ pythStatePolicyId: pythStateAssetClass[0],
478
+ };
479
+
480
+ const ijpyNightPythFeedValidator: SpendingValidator = mkPythFeedValidator(
481
+ fromSysParamsPythFeedParams(IJPY_NIGHT_PYTH_FEED_PARAMS),
482
+ );
483
+
484
+ const ijpyNightPythFeedValidatorHash = validatorToScriptHash(
485
+ ijpyNightPythFeedValidator,
486
+ );
487
+
488
+ expect(ijpyNightPythFeedValidatorHash).toEqual(
489
+ // Rebuild the params without conversion functions as well.
490
+ validatorToScriptHash(
491
+ mkPythFeedValidator({
492
+ config: {
493
+ Divide: {
494
+ x: toDataDerivedPythPrice({
495
+ Inverse: {
496
+ value: toDataDerivedPythPrice({
497
+ Value: { configuration: { priceFeedId: 340n } },
498
+ }),
499
+ },
500
+ }),
501
+ y: toDataDerivedPythPrice({
502
+ Value: { configuration: { priceFeedId: 2970n } },
503
+ }),
504
+ },
505
+ },
506
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
507
+ }),
508
+ ),
509
+ );
510
+
511
+ expect(ijpyNightPythFeedValidatorHash).toEqual(
512
+ '00bc4b3a8710593c2e25c6e151fbdff3ec79106e828a48e16f9422f8',
513
+ );
514
+ });
515
+
516
+ /** Config: (EUR / USD) / (USDCx/USD) => EUR/USDCx */
517
+ test('ieur usdcx pyth feed', () => {
518
+ const IEUR_USDCX_PYTH_FEED_PARAMS: PythFeedParamsSP = {
519
+ config: {
520
+ tag: 'divide',
521
+ val: [
522
+ {
523
+ tag: 'value',
524
+ val: {
525
+ priceFeedId: 327,
526
+ },
527
+ },
528
+ {
529
+ tag: 'value',
530
+ val: {
531
+ priceFeedId: 7,
532
+ },
533
+ },
534
+ ],
535
+ },
536
+ pythStatePolicyId: pythStateAssetClass[0],
537
+ };
538
+
539
+ const ieurUSDCxPythFeedValidator: SpendingValidator = mkPythFeedValidator(
540
+ fromSysParamsPythFeedParams(IEUR_USDCX_PYTH_FEED_PARAMS),
541
+ );
542
+
543
+ const ieurUSDCxPythFeedValidatorHash = validatorToScriptHash(
544
+ ieurUSDCxPythFeedValidator,
545
+ );
546
+
547
+ expect(ieurUSDCxPythFeedValidatorHash).toEqual(
548
+ // Rebuild the params without conversion functions as well.
549
+ validatorToScriptHash(
550
+ mkPythFeedValidator({
551
+ config: {
552
+ Divide: {
553
+ x: toDataDerivedPythPrice({
554
+ Value: { configuration: { priceFeedId: 327n } },
555
+ }),
556
+ y: toDataDerivedPythPrice({
557
+ Value: { configuration: { priceFeedId: 7n } },
558
+ }),
559
+ },
560
+ },
561
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
562
+ }),
563
+ ),
564
+ );
565
+
566
+ expect(ieurUSDCxPythFeedValidatorHash).toEqual(
567
+ '0b1d64e558d1c38e420c2348e8674c99cf9a4552ebc4e18c1f20a20b',
568
+ );
569
+ });
570
+
571
+ /** Config: (1 / USD/JPY) / (USDCx/USD) => JPY/USDCx */
572
+ test('ijpy usdcx pyth feed', () => {
573
+ const IJPY_USDCX_PYTH_FEED_PARAMS: PythFeedParamsSP = {
574
+ config: {
575
+ tag: 'divide',
576
+ val: [
577
+ {
578
+ tag: 'inverse',
579
+ val: {
580
+ tag: 'value',
581
+ val: {
582
+ priceFeedId: 340,
583
+ },
584
+ },
585
+ },
586
+ {
587
+ tag: 'value',
588
+ val: {
589
+ priceFeedId: 7,
590
+ },
591
+ },
592
+ ],
593
+ },
594
+ pythStatePolicyId: pythStateAssetClass[0],
595
+ };
596
+
597
+ const ijpyUSDCxPythFeedValidator: SpendingValidator = mkPythFeedValidator(
598
+ fromSysParamsPythFeedParams(IJPY_USDCX_PYTH_FEED_PARAMS),
599
+ );
600
+
601
+ const ijpyUSDCxPythFeedValidatorHash = validatorToScriptHash(
602
+ ijpyUSDCxPythFeedValidator,
603
+ );
604
+
605
+ expect(ijpyUSDCxPythFeedValidatorHash).toEqual(
606
+ // Rebuild the params without conversion functions as well.
607
+ validatorToScriptHash(
608
+ mkPythFeedValidator({
609
+ config: {
610
+ Divide: {
611
+ x: toDataDerivedPythPrice({
612
+ Inverse: {
613
+ value: toDataDerivedPythPrice({
614
+ Value: { configuration: { priceFeedId: 340n } },
615
+ }),
616
+ },
617
+ }),
618
+ y: toDataDerivedPythPrice({
619
+ Value: { configuration: { priceFeedId: 7n } },
620
+ }),
621
+ },
622
+ },
623
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
624
+ }),
625
+ ),
626
+ );
627
+
628
+ expect(ijpyUSDCxPythFeedValidatorHash).toEqual(
629
+ 'f2c4e1f46052f4f1de0088a9c70889b3bef48bd6015fd4c0adb3195c',
630
+ );
631
+ });
632
+
633
+ /** Config: (BTC / USD) / (NIGHT/USD) => BTC/NIGHT */
634
+ test('ibtc night pyth feed', () => {
635
+ const IBTC_NIGHT_PYTH_FEED_PARAMS: PythFeedParamsSP = {
636
+ config: {
637
+ tag: 'divide',
638
+ val: [
639
+ {
640
+ tag: 'value',
641
+ val: {
642
+ priceFeedId: 1,
643
+ },
644
+ },
645
+ {
646
+ tag: 'value',
647
+ val: {
648
+ priceFeedId: 2970,
649
+ },
650
+ },
651
+ ],
652
+ },
653
+ pythStatePolicyId: pythStateAssetClass[0],
654
+ };
655
+
656
+ const ibtcNightPythFeedValidator: SpendingValidator = mkPythFeedValidator(
657
+ fromSysParamsPythFeedParams(IBTC_NIGHT_PYTH_FEED_PARAMS),
658
+ );
659
+
660
+ const ibtcNightPythFeedValidatorHash = validatorToScriptHash(
661
+ ibtcNightPythFeedValidator,
662
+ );
663
+
664
+ expect(ibtcNightPythFeedValidatorHash).toEqual(
665
+ // Rebuild the params without conversion functions as well.
666
+ validatorToScriptHash(
667
+ mkPythFeedValidator({
668
+ config: {
669
+ Divide: {
670
+ x: toDataDerivedPythPrice({
671
+ Value: { configuration: { priceFeedId: 1n } },
672
+ }),
673
+ y: toDataDerivedPythPrice({
674
+ Value: { configuration: { priceFeedId: 2970n } },
675
+ }),
676
+ },
677
+ },
678
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
679
+ }),
680
+ ),
681
+ );
682
+
683
+ expect(ibtcNightPythFeedValidatorHash).toEqual(
684
+ '176c55745286f4a139bf69719514fb4769be572f0b009b31ae482a3d',
685
+ );
686
+ });
687
+
688
+ /** Config: (ETH / USD) / (NIGHT/USD) => BTC/NIGHT */
689
+ test('ieth night pyth feed', () => {
690
+ const IETH_NIGHT_PYTH_FEED_PARAMS: PythFeedParamsSP = {
691
+ config: {
692
+ tag: 'divide',
693
+ val: [
694
+ {
695
+ tag: 'value',
696
+ val: {
697
+ priceFeedId: 2,
698
+ },
699
+ },
700
+ {
701
+ tag: 'value',
702
+ val: {
703
+ priceFeedId: 2970,
704
+ },
705
+ },
706
+ ],
707
+ },
708
+ pythStatePolicyId: pythStateAssetClass[0],
709
+ };
710
+
711
+ const iethNightPythFeedValidator: SpendingValidator = mkPythFeedValidator(
712
+ fromSysParamsPythFeedParams(IETH_NIGHT_PYTH_FEED_PARAMS),
713
+ );
714
+
715
+ const iethNightPythFeedValidatorHash = validatorToScriptHash(
716
+ iethNightPythFeedValidator,
717
+ );
718
+
719
+ expect(iethNightPythFeedValidatorHash).toEqual(
720
+ // Rebuild the params without conversion functions as well.
721
+ validatorToScriptHash(
722
+ mkPythFeedValidator({
723
+ config: {
724
+ Divide: {
725
+ x: toDataDerivedPythPrice({
726
+ Value: { configuration: { priceFeedId: 2n } },
727
+ }),
728
+ y: toDataDerivedPythPrice({
729
+ Value: { configuration: { priceFeedId: 2970n } },
730
+ }),
731
+ },
732
+ },
733
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
734
+ }),
735
+ ),
736
+ );
737
+
738
+ expect(iethNightPythFeedValidatorHash).toEqual(
739
+ '9fd83fdd93a6945790498fe47fdeff28a8beda1f611784edcd1fee98',
740
+ );
741
+ });
742
+
743
+ /** Config: (BTC / USD) / (USDCx/USD) => BTC/USDCx */
744
+ test('ibtc usdcx pyth feed', () => {
745
+ const IBTC_USDCX_PYTH_FEED_PARAMS: PythFeedParamsSP = {
746
+ config: {
747
+ tag: 'divide',
748
+ val: [
749
+ {
750
+ tag: 'value',
751
+ val: {
752
+ priceFeedId: 1,
753
+ },
754
+ },
755
+ {
756
+ tag: 'value',
757
+ val: {
758
+ priceFeedId: 7,
759
+ },
760
+ },
761
+ ],
762
+ },
763
+ pythStatePolicyId: pythStateAssetClass[0],
764
+ };
765
+
766
+ const ibtcUSDCxPythFeedValidator: SpendingValidator = mkPythFeedValidator(
767
+ fromSysParamsPythFeedParams(IBTC_USDCX_PYTH_FEED_PARAMS),
768
+ );
769
+
770
+ const ibtcUSDCxPythFeedValidatorHash = validatorToScriptHash(
771
+ ibtcUSDCxPythFeedValidator,
772
+ );
773
+
774
+ expect(ibtcUSDCxPythFeedValidatorHash).toEqual(
775
+ // Rebuild the params without conversion functions as well.
776
+ validatorToScriptHash(
777
+ mkPythFeedValidator({
778
+ config: {
779
+ Divide: {
780
+ x: toDataDerivedPythPrice({
781
+ Value: { configuration: { priceFeedId: 1n } },
782
+ }),
783
+ y: toDataDerivedPythPrice({
784
+ Value: { configuration: { priceFeedId: 7n } },
785
+ }),
786
+ },
787
+ },
788
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
789
+ }),
790
+ ),
791
+ );
792
+
793
+ expect(ibtcUSDCxPythFeedValidatorHash).toEqual(
794
+ 'df5a33036a62f20fa23f07d50a8da0b56714ae6c69f7389b82318fef',
795
+ );
796
+ });
797
+
798
+ /** Config: (ETH / USD) / (USDCx/USD) => BTC/USDCx */
799
+ test('ieth usdcx pyth feed', () => {
800
+ const IETH_USDCX_PYTH_FEED_PARAMS: PythFeedParamsSP = {
801
+ config: {
802
+ tag: 'divide',
803
+ val: [
804
+ {
805
+ tag: 'value',
806
+ val: {
807
+ priceFeedId: 2,
808
+ },
809
+ },
810
+ {
811
+ tag: 'value',
812
+ val: {
813
+ priceFeedId: 7,
814
+ },
815
+ },
816
+ ],
817
+ },
818
+ pythStatePolicyId: pythStateAssetClass[0],
819
+ };
820
+
821
+ const iethUSDCxPythFeedValidator: SpendingValidator = mkPythFeedValidator(
822
+ fromSysParamsPythFeedParams(IETH_USDCX_PYTH_FEED_PARAMS),
823
+ );
824
+
825
+ const iethUSDCxPythFeedValidatorHash = validatorToScriptHash(
826
+ iethUSDCxPythFeedValidator,
827
+ );
828
+
829
+ expect(iethUSDCxPythFeedValidatorHash).toEqual(
830
+ // Rebuild the params without conversion functions as well.
831
+ validatorToScriptHash(
832
+ mkPythFeedValidator({
833
+ config: {
834
+ Divide: {
835
+ x: toDataDerivedPythPrice({
836
+ Value: { configuration: { priceFeedId: 2n } },
837
+ }),
838
+ y: toDataDerivedPythPrice({
839
+ Value: { configuration: { priceFeedId: 7n } },
840
+ }),
841
+ },
842
+ },
843
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
844
+ }),
845
+ ),
846
+ );
847
+
848
+ expect(iethUSDCxPythFeedValidatorHash).toEqual(
849
+ 'f83f5e86412ad360e1f6f248503b11fa92edf4aaa4a6799f1f067317',
850
+ );
851
+ });
852
+
853
+ /** Config: (ADA / USD) / (USD/NIGHT) => ADA/NIGHT */
854
+ test('iada night pyth feed', () => {
855
+ const IADA_NIGHT_PYTH_FEED_PARAMS: PythFeedParamsSP = {
856
+ config: {
857
+ tag: 'divide',
858
+ val: [
859
+ {
860
+ tag: 'value',
861
+ val: {
862
+ priceFeedId: 16,
863
+ },
864
+ },
865
+ {
866
+ tag: 'value',
867
+ val: {
868
+ priceFeedId: 2970,
869
+ },
870
+ },
871
+ ],
872
+ },
873
+ pythStatePolicyId: pythStateAssetClass[0],
874
+ };
875
+
876
+ const iadaNightPythFeedValidator: SpendingValidator = mkPythFeedValidator(
877
+ fromSysParamsPythFeedParams(IADA_NIGHT_PYTH_FEED_PARAMS),
878
+ );
879
+
880
+ const iadaNightPythFeedValidatorHash = validatorToScriptHash(
881
+ iadaNightPythFeedValidator,
882
+ );
883
+
884
+ expect(iadaNightPythFeedValidatorHash).toEqual(
885
+ // Rebuild the params without conversion functions as well.
886
+ validatorToScriptHash(
887
+ mkPythFeedValidator({
888
+ config: {
889
+ Divide: {
890
+ x: toDataDerivedPythPrice({
891
+ Value: { configuration: { priceFeedId: 16n } },
892
+ }),
893
+ y: toDataDerivedPythPrice({
894
+ Value: { configuration: { priceFeedId: 2970n } },
895
+ }),
896
+ },
897
+ },
898
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
899
+ }),
900
+ ),
901
+ );
902
+
903
+ expect(iadaNightPythFeedValidatorHash).toEqual(
904
+ 'c16544a7009549cf26bde1cead12859b1933186da3c2717cd30074b9',
905
+ );
906
+ });
907
+
908
+ /** Config: ADA / USD */
909
+ test('iada usdcx pyth feed', () => {
910
+ const IADA_USDCX_PYTH_FEED_PARAMS: PythFeedParamsSP = {
911
+ config: {
912
+ tag: 'value',
913
+ val: {
914
+ priceFeedId: 16,
915
+ },
916
+ },
917
+ pythStatePolicyId: pythStateAssetClass[0],
918
+ };
919
+
920
+ const iadaUSDCxPythFeedValidator: SpendingValidator = mkPythFeedValidator(
921
+ fromSysParamsPythFeedParams(IADA_USDCX_PYTH_FEED_PARAMS),
922
+ );
923
+
924
+ const iadaUSDCxPythFeedValidatorHash = validatorToScriptHash(
925
+ iadaUSDCxPythFeedValidator,
926
+ );
927
+
928
+ expect(iadaUSDCxPythFeedValidatorHash).toEqual(
929
+ // Rebuild the params without conversion functions as well.
930
+ validatorToScriptHash(
931
+ mkPythFeedValidator({
932
+ config: {
933
+ Value: { configuration: { priceFeedId: 16n } },
934
+ },
935
+ pythStatePolicyId: fromHex(pythStateAssetClass[0].unCurrencySymbol),
936
+ }),
937
+ ),
938
+ );
939
+
940
+ expect(iadaUSDCxPythFeedValidatorHash).toEqual(
941
+ '075b0ce5d592d51262e6d3e1c8a88e94c86470f95dc7b8e7a9139782',
942
+ );
943
+ });