@glamsystems/glam-sdk 0.1.27 → 0.1.29

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/index.cjs.js CHANGED
@@ -34,7 +34,7 @@ var borsh__namespace = /*#__PURE__*/_interopNamespaceDefault(borsh);
34
34
  var address = "GLAMbTqav9N9witRjswJ8enwp9vv5G8bsSJ2kPJ4rcyc";
35
35
  var metadata = {
36
36
  name: "glam_protocol",
37
- version: "0.4.29",
37
+ version: "0.4.33",
38
38
  spec: "0.1.0",
39
39
  description: "Glam Protocol"
40
40
  };
@@ -279,7 +279,7 @@ var instructions = [
279
279
  },
280
280
  {
281
281
  kind: "account",
282
- path: "token_program"
282
+ path: "claim_token_program"
283
283
  },
284
284
  {
285
285
  kind: "account",
@@ -336,7 +336,7 @@ var instructions = [
336
336
  },
337
337
  {
338
338
  kind: "account",
339
- path: "token_program"
339
+ path: "claim_token_program"
340
340
  },
341
341
  {
342
342
  kind: "account",
@@ -387,7 +387,11 @@ var instructions = [
387
387
  address: "11111111111111111111111111111111"
388
388
  },
389
389
  {
390
- name: "token_program"
390
+ name: "claim_token_program"
391
+ },
392
+ {
393
+ name: "associated_token_program",
394
+ address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
391
395
  }
392
396
  ],
393
397
  args: [
@@ -611,25 +615,344 @@ var instructions = [
611
615
  }
612
616
  },
613
617
  {
614
- name: "glam_mint",
615
- writable: true
616
- },
617
- {
618
- name: "escrow_mint_ata",
618
+ name: "glam_mint",
619
+ writable: true
620
+ },
621
+ {
622
+ name: "escrow_mint_ata",
623
+ writable: true,
624
+ pda: {
625
+ seeds: [
626
+ {
627
+ kind: "account",
628
+ path: "glam_escrow"
629
+ },
630
+ {
631
+ kind: "account",
632
+ path: "token_2022_program"
633
+ },
634
+ {
635
+ kind: "account",
636
+ path: "glam_mint"
637
+ }
638
+ ],
639
+ program: {
640
+ kind: "const",
641
+ value: [
642
+ 140,
643
+ 151,
644
+ 37,
645
+ 143,
646
+ 78,
647
+ 36,
648
+ 137,
649
+ 241,
650
+ 187,
651
+ 61,
652
+ 16,
653
+ 41,
654
+ 20,
655
+ 142,
656
+ 13,
657
+ 131,
658
+ 11,
659
+ 90,
660
+ 19,
661
+ 153,
662
+ 218,
663
+ 255,
664
+ 16,
665
+ 132,
666
+ 4,
667
+ 142,
668
+ 123,
669
+ 216,
670
+ 219,
671
+ 233,
672
+ 248,
673
+ 89
674
+ ]
675
+ }
676
+ }
677
+ },
678
+ {
679
+ name: "signer",
680
+ writable: true,
681
+ signer: true
682
+ },
683
+ {
684
+ name: "token_2022_program",
685
+ address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
686
+ }
687
+ ],
688
+ args: [
689
+ {
690
+ name: "mint_id",
691
+ type: "u8"
692
+ }
693
+ ]
694
+ },
695
+ {
696
+ name: "disburse_fees",
697
+ discriminator: [
698
+ 205,
699
+ 56,
700
+ 198,
701
+ 40,
702
+ 225,
703
+ 103,
704
+ 141,
705
+ 219
706
+ ],
707
+ accounts: [
708
+ {
709
+ name: "glam_state",
710
+ writable: true
711
+ },
712
+ {
713
+ name: "glam_vault",
714
+ pda: {
715
+ seeds: [
716
+ {
717
+ kind: "const",
718
+ value: [
719
+ 118,
720
+ 97,
721
+ 117,
722
+ 108,
723
+ 116
724
+ ]
725
+ },
726
+ {
727
+ kind: "account",
728
+ path: "glam_state"
729
+ }
730
+ ]
731
+ }
732
+ },
733
+ {
734
+ name: "glam_escrow",
735
+ pda: {
736
+ seeds: [
737
+ {
738
+ kind: "const",
739
+ value: [
740
+ 101,
741
+ 115,
742
+ 99,
743
+ 114,
744
+ 111,
745
+ 119
746
+ ]
747
+ },
748
+ {
749
+ kind: "account",
750
+ path: "glam_state"
751
+ }
752
+ ]
753
+ }
754
+ },
755
+ {
756
+ name: "glam_mint",
757
+ writable: true
758
+ },
759
+ {
760
+ name: "escrow_mint_ata",
761
+ writable: true,
762
+ pda: {
763
+ seeds: [
764
+ {
765
+ kind: "account",
766
+ path: "glam_escrow"
767
+ },
768
+ {
769
+ kind: "account",
770
+ path: "token_2022_program"
771
+ },
772
+ {
773
+ kind: "account",
774
+ path: "glam_mint"
775
+ }
776
+ ],
777
+ program: {
778
+ kind: "const",
779
+ value: [
780
+ 140,
781
+ 151,
782
+ 37,
783
+ 143,
784
+ 78,
785
+ 36,
786
+ 137,
787
+ 241,
788
+ 187,
789
+ 61,
790
+ 16,
791
+ 41,
792
+ 20,
793
+ 142,
794
+ 13,
795
+ 131,
796
+ 11,
797
+ 90,
798
+ 19,
799
+ 153,
800
+ 218,
801
+ 255,
802
+ 16,
803
+ 132,
804
+ 4,
805
+ 142,
806
+ 123,
807
+ 216,
808
+ 219,
809
+ 233,
810
+ 248,
811
+ 89
812
+ ]
813
+ }
814
+ }
815
+ },
816
+ {
817
+ name: "signer",
818
+ writable: true,
819
+ signer: true
820
+ },
821
+ {
822
+ name: "deposit_asset"
823
+ },
824
+ {
825
+ name: "vault_deposit_ata",
826
+ writable: true,
827
+ pda: {
828
+ seeds: [
829
+ {
830
+ kind: "account",
831
+ path: "glam_vault"
832
+ },
833
+ {
834
+ kind: "account",
835
+ path: "deposit_token_program"
836
+ },
837
+ {
838
+ kind: "account",
839
+ path: "deposit_asset"
840
+ }
841
+ ],
842
+ program: {
843
+ kind: "const",
844
+ value: [
845
+ 140,
846
+ 151,
847
+ 37,
848
+ 143,
849
+ 78,
850
+ 36,
851
+ 137,
852
+ 241,
853
+ 187,
854
+ 61,
855
+ 16,
856
+ 41,
857
+ 20,
858
+ 142,
859
+ 13,
860
+ 131,
861
+ 11,
862
+ 90,
863
+ 19,
864
+ 153,
865
+ 218,
866
+ 255,
867
+ 16,
868
+ 132,
869
+ 4,
870
+ 142,
871
+ 123,
872
+ 216,
873
+ 219,
874
+ 233,
875
+ 248,
876
+ 89
877
+ ]
878
+ }
879
+ }
880
+ },
881
+ {
882
+ name: "protocol_fee_authority_ata",
883
+ writable: true,
884
+ pda: {
885
+ seeds: [
886
+ {
887
+ kind: "account",
888
+ path: "glam_config.fee_authority",
889
+ account: "GlobalConfig"
890
+ },
891
+ {
892
+ kind: "account",
893
+ path: "deposit_token_program"
894
+ },
895
+ {
896
+ kind: "account",
897
+ path: "deposit_asset"
898
+ }
899
+ ],
900
+ program: {
901
+ kind: "const",
902
+ value: [
903
+ 140,
904
+ 151,
905
+ 37,
906
+ 143,
907
+ 78,
908
+ 36,
909
+ 137,
910
+ 241,
911
+ 187,
912
+ 61,
913
+ 16,
914
+ 41,
915
+ 20,
916
+ 142,
917
+ 13,
918
+ 131,
919
+ 11,
920
+ 90,
921
+ 19,
922
+ 153,
923
+ 218,
924
+ 255,
925
+ 16,
926
+ 132,
927
+ 4,
928
+ 142,
929
+ 123,
930
+ 216,
931
+ 219,
932
+ 233,
933
+ 248,
934
+ 89
935
+ ]
936
+ }
937
+ }
938
+ },
939
+ {
940
+ name: "manager_fee_authority_ata",
619
941
  writable: true,
620
942
  pda: {
621
943
  seeds: [
622
944
  {
623
945
  kind: "account",
624
- path: "glam_escrow"
946
+ path: "glam_state.owner",
947
+ account: "StateAccount"
625
948
  },
626
949
  {
627
950
  kind: "account",
628
- path: "token_2022_program"
951
+ path: "deposit_token_program"
629
952
  },
630
953
  {
631
954
  kind: "account",
632
- path: "glam_mint"
955
+ path: "deposit_asset"
633
956
  }
634
957
  ],
635
958
  program: {
@@ -672,9 +995,77 @@ var instructions = [
672
995
  }
673
996
  },
674
997
  {
675
- name: "signer",
676
- writable: true,
677
- signer: true
998
+ name: "glam_config",
999
+ pda: {
1000
+ seeds: [
1001
+ {
1002
+ kind: "const",
1003
+ value: [
1004
+ 103,
1005
+ 108,
1006
+ 111,
1007
+ 98,
1008
+ 97,
1009
+ 108,
1010
+ 95,
1011
+ 99,
1012
+ 111,
1013
+ 110,
1014
+ 102,
1015
+ 105,
1016
+ 103
1017
+ ]
1018
+ }
1019
+ ],
1020
+ program: {
1021
+ kind: "const",
1022
+ value: [
1023
+ 10,
1024
+ 11,
1025
+ 0,
1026
+ 83,
1027
+ 72,
1028
+ 16,
1029
+ 46,
1030
+ 144,
1031
+ 46,
1032
+ 42,
1033
+ 79,
1034
+ 22,
1035
+ 157,
1036
+ 123,
1037
+ 21,
1038
+ 242,
1039
+ 192,
1040
+ 146,
1041
+ 1,
1042
+ 78,
1043
+ 88,
1044
+ 59,
1045
+ 102,
1046
+ 9,
1047
+ 190,
1048
+ 226,
1049
+ 92,
1050
+ 189,
1051
+ 187,
1052
+ 232,
1053
+ 83,
1054
+ 220
1055
+ ]
1056
+ }
1057
+ }
1058
+ },
1059
+ {
1060
+ name: "system_program",
1061
+ address: "11111111111111111111111111111111"
1062
+ },
1063
+ {
1064
+ name: "associated_token_program",
1065
+ address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
1066
+ },
1067
+ {
1068
+ name: "deposit_token_program"
678
1069
  },
679
1070
  {
680
1071
  name: "token_2022_program",
@@ -982,6 +1373,99 @@ var instructions = [
982
1373
  }
983
1374
  ]
984
1375
  },
1376
+ {
1377
+ name: "drift_distributor_new_claim",
1378
+ discriminator: [
1379
+ 204,
1380
+ 159,
1381
+ 250,
1382
+ 46,
1383
+ 124,
1384
+ 193,
1385
+ 250,
1386
+ 10
1387
+ ],
1388
+ accounts: [
1389
+ {
1390
+ name: "glam_state"
1391
+ },
1392
+ {
1393
+ name: "glam_vault",
1394
+ writable: true,
1395
+ pda: {
1396
+ seeds: [
1397
+ {
1398
+ kind: "const",
1399
+ value: [
1400
+ 118,
1401
+ 97,
1402
+ 117,
1403
+ 108,
1404
+ 116
1405
+ ]
1406
+ },
1407
+ {
1408
+ kind: "account",
1409
+ path: "glam_state"
1410
+ }
1411
+ ]
1412
+ }
1413
+ },
1414
+ {
1415
+ name: "glam_signer",
1416
+ writable: true,
1417
+ signer: true
1418
+ },
1419
+ {
1420
+ name: "cpi_program",
1421
+ address: "E7HtfkEMhmn9uwL7EFNydcXBWy5WCYN1vFmKKjipEH1x"
1422
+ },
1423
+ {
1424
+ name: "distributor",
1425
+ writable: true
1426
+ },
1427
+ {
1428
+ name: "claim_status",
1429
+ writable: true
1430
+ },
1431
+ {
1432
+ name: "from",
1433
+ writable: true
1434
+ },
1435
+ {
1436
+ name: "to",
1437
+ writable: true
1438
+ },
1439
+ {
1440
+ name: "token_program"
1441
+ },
1442
+ {
1443
+ name: "system_program",
1444
+ address: "11111111111111111111111111111111"
1445
+ }
1446
+ ],
1447
+ args: [
1448
+ {
1449
+ name: "amount_unlocked",
1450
+ type: "u64"
1451
+ },
1452
+ {
1453
+ name: "amount_locked",
1454
+ type: "u64"
1455
+ },
1456
+ {
1457
+ name: "proof",
1458
+ type: {
1459
+ vec: {
1460
+ array: [
1461
+ "u8",
1462
+ 32
1463
+ ]
1464
+ }
1465
+ }
1466
+ }
1467
+ ]
1468
+ },
985
1469
  {
986
1470
  name: "drift_initialize_user",
987
1471
  discriminator: [
@@ -1537,22 +2021,84 @@ var instructions = [
1537
2021
  type: "u16"
1538
2022
  },
1539
2023
  {
1540
- name: "delegate",
1541
- type: "pubkey"
2024
+ name: "delegate",
2025
+ type: "pubkey"
2026
+ }
2027
+ ]
2028
+ },
2029
+ {
2030
+ name: "drift_update_user_margin_trading_enabled",
2031
+ discriminator: [
2032
+ 157,
2033
+ 175,
2034
+ 12,
2035
+ 19,
2036
+ 202,
2037
+ 114,
2038
+ 17,
2039
+ 36
2040
+ ],
2041
+ accounts: [
2042
+ {
2043
+ name: "glam_state"
2044
+ },
2045
+ {
2046
+ name: "glam_vault",
2047
+ pda: {
2048
+ seeds: [
2049
+ {
2050
+ kind: "const",
2051
+ value: [
2052
+ 118,
2053
+ 97,
2054
+ 117,
2055
+ 108,
2056
+ 116
2057
+ ]
2058
+ },
2059
+ {
2060
+ kind: "account",
2061
+ path: "glam_state"
2062
+ }
2063
+ ]
2064
+ }
2065
+ },
2066
+ {
2067
+ name: "glam_signer",
2068
+ writable: true,
2069
+ signer: true
2070
+ },
2071
+ {
2072
+ name: "cpi_program",
2073
+ address: "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH"
2074
+ },
2075
+ {
2076
+ name: "user",
2077
+ writable: true
2078
+ }
2079
+ ],
2080
+ args: [
2081
+ {
2082
+ name: "sub_account_id",
2083
+ type: "u16"
2084
+ },
2085
+ {
2086
+ name: "margin_trading_enabled",
2087
+ type: "bool"
1542
2088
  }
1543
2089
  ]
1544
2090
  },
1545
2091
  {
1546
- name: "drift_update_user_margin_trading_enabled",
2092
+ name: "drift_update_user_pool_id",
1547
2093
  discriminator: [
1548
- 157,
1549
- 175,
1550
- 12,
1551
- 19,
1552
- 202,
1553
- 114,
1554
- 17,
1555
- 36
2094
+ 44,
2095
+ 176,
2096
+ 143,
2097
+ 200,
2098
+ 153,
2099
+ 248,
2100
+ 221,
2101
+ 218
1556
2102
  ],
1557
2103
  accounts: [
1558
2104
  {
@@ -1599,8 +2145,8 @@ var instructions = [
1599
2145
  type: "u16"
1600
2146
  },
1601
2147
  {
1602
- name: "margin_trading_enabled",
1603
- type: "bool"
2148
+ name: "pool_id",
2149
+ type: "u8"
1604
2150
  }
1605
2151
  ]
1606
2152
  },
@@ -2505,41 +3051,8 @@ var instructions = [
2505
3051
  path: "glam_vault"
2506
3052
  },
2507
3053
  {
2508
- kind: "const",
2509
- value: [
2510
- 6,
2511
- 221,
2512
- 246,
2513
- 225,
2514
- 215,
2515
- 101,
2516
- 161,
2517
- 147,
2518
- 217,
2519
- 203,
2520
- 225,
2521
- 70,
2522
- 206,
2523
- 235,
2524
- 121,
2525
- 172,
2526
- 28,
2527
- 180,
2528
- 133,
2529
- 237,
2530
- 95,
2531
- 91,
2532
- 55,
2533
- 145,
2534
- 58,
2535
- 140,
2536
- 245,
2537
- 133,
2538
- 126,
2539
- 255,
2540
- 0,
2541
- 169
2542
- ]
3054
+ kind: "account",
3055
+ path: "deposit_token_program"
2543
3056
  },
2544
3057
  {
2545
3058
  kind: "account",
@@ -2595,41 +3108,8 @@ var instructions = [
2595
3108
  path: "glam_escrow"
2596
3109
  },
2597
3110
  {
2598
- kind: "const",
2599
- value: [
2600
- 6,
2601
- 221,
2602
- 246,
2603
- 225,
2604
- 215,
2605
- 101,
2606
- 161,
2607
- 147,
2608
- 217,
2609
- 203,
2610
- 225,
2611
- 70,
2612
- 206,
2613
- 235,
2614
- 121,
2615
- 172,
2616
- 28,
2617
- 180,
2618
- 133,
2619
- 237,
2620
- 95,
2621
- 91,
2622
- 55,
2623
- 145,
2624
- 58,
2625
- 140,
2626
- 245,
2627
- 133,
2628
- 126,
2629
- 255,
2630
- 0,
2631
- 169
2632
- ]
3111
+ kind: "account",
3112
+ path: "deposit_token_program"
2633
3113
  },
2634
3114
  {
2635
3115
  kind: "account",
@@ -2680,8 +3160,7 @@ var instructions = [
2680
3160
  address: "11111111111111111111111111111111"
2681
3161
  },
2682
3162
  {
2683
- name: "token_program",
2684
- address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
3163
+ name: "deposit_token_program"
2685
3164
  },
2686
3165
  {
2687
3166
  name: "token_2022_program",
@@ -6288,6 +6767,12 @@ var instructions = [
6288
6767
  },
6289
6768
  {
6290
6769
  name: "price_drift_users",
6770
+ docs: [
6771
+ "Extra accounts for pricing N drift users under the same user stats:",
6772
+ "- user_stats x 1",
6773
+ "- drift_user x N",
6774
+ "- markets and oracles used by all drift users (no specific order)"
6775
+ ],
6291
6776
  discriminator: [
6292
6777
  12,
6293
6778
  5,
@@ -6403,11 +6888,20 @@ var instructions = [
6403
6888
  name: "PriceDenom"
6404
6889
  }
6405
6890
  }
6891
+ },
6892
+ {
6893
+ name: "num_users",
6894
+ type: "u8"
6406
6895
  }
6407
6896
  ]
6408
6897
  },
6409
6898
  {
6410
6899
  name: "price_drift_vault_depositors",
6900
+ docs: [
6901
+ "Extra accounts for pricing N vault depositors:",
6902
+ "- (vault_depositor, drift_vault, drift_user) x N",
6903
+ "- markets and oracles used by all drift users (no specific order)"
6904
+ ],
6411
6905
  discriminator: [
6412
6906
  234,
6413
6907
  16,
@@ -6523,6 +7017,10 @@ var instructions = [
6523
7017
  name: "PriceDenom"
6524
7018
  }
6525
7019
  }
7020
+ },
7021
+ {
7022
+ name: "num_vault_depositors",
7023
+ type: "u8"
6526
7024
  }
6527
7025
  ]
6528
7026
  },
@@ -6668,6 +7166,11 @@ var instructions = [
6668
7166
  },
6669
7167
  {
6670
7168
  name: "price_kamino_vault_shares",
7169
+ docs: [
7170
+ "Extra accounts for pricing N kamino vault shares:",
7171
+ "- (kvault_share_ata, kvault_share_mint, kvault_state, kvault_deposit_token_oracle) x N",
7172
+ "- (lending_market, reserve) x M, M = number of unique markets used by all kvaults involved"
7173
+ ],
6671
7174
  discriminator: [
6672
7175
  112,
6673
7176
  92,
@@ -6803,6 +7306,10 @@ var instructions = [
6803
7306
  name: "PriceDenom"
6804
7307
  }
6805
7308
  }
7309
+ },
7310
+ {
7311
+ name: "num_vaults",
7312
+ type: "u8"
6806
7313
  }
6807
7314
  ]
6808
7315
  },
@@ -7047,16 +7554,22 @@ var instructions = [
7047
7554
  ]
7048
7555
  },
7049
7556
  {
7050
- name: "price_vault",
7557
+ name: "price_vault_tokens",
7558
+ docs: [
7559
+ "Price vault SOL balance and tokens it holds.",
7560
+ "",
7561
+ "Extra accounts for pricing N tokens:",
7562
+ "- (ata, mint, oracle) x N"
7563
+ ],
7051
7564
  discriminator: [
7052
- 47,
7053
- 213,
7054
- 36,
7055
- 17,
7565
+ 54,
7566
+ 42,
7567
+ 16,
7568
+ 199,
7569
+ 20,
7056
7570
  183,
7057
- 5,
7058
- 141,
7059
- 45
7571
+ 50,
7572
+ 137
7060
7573
  ],
7061
7574
  accounts: [
7062
7575
  {
@@ -7409,41 +7922,8 @@ var instructions = [
7409
7922
  path: "glam_escrow"
7410
7923
  },
7411
7924
  {
7412
- kind: "const",
7413
- value: [
7414
- 6,
7415
- 221,
7416
- 246,
7417
- 225,
7418
- 215,
7419
- 101,
7420
- 161,
7421
- 147,
7422
- 217,
7423
- 203,
7424
- 225,
7425
- 70,
7426
- 206,
7427
- 235,
7428
- 121,
7429
- 172,
7430
- 28,
7431
- 180,
7432
- 133,
7433
- 237,
7434
- 95,
7435
- 91,
7436
- 55,
7437
- 145,
7438
- 58,
7439
- 140,
7440
- 245,
7441
- 133,
7442
- 126,
7443
- 255,
7444
- 0,
7445
- 169
7446
- ]
7925
+ kind: "account",
7926
+ path: "deposit_token_program"
7447
7927
  },
7448
7928
  {
7449
7929
  kind: "account",
@@ -7499,41 +7979,8 @@ var instructions = [
7499
7979
  path: "signer"
7500
7980
  },
7501
7981
  {
7502
- kind: "const",
7503
- value: [
7504
- 6,
7505
- 221,
7506
- 246,
7507
- 225,
7508
- 215,
7509
- 101,
7510
- 161,
7511
- 147,
7512
- 217,
7513
- 203,
7514
- 225,
7515
- 70,
7516
- 206,
7517
- 235,
7518
- 121,
7519
- 172,
7520
- 28,
7521
- 180,
7522
- 133,
7523
- 237,
7524
- 95,
7525
- 91,
7526
- 55,
7527
- 145,
7528
- 58,
7529
- 140,
7530
- 245,
7531
- 133,
7532
- 126,
7533
- 255,
7534
- 0,
7535
- 169
7536
- ]
7982
+ kind: "account",
7983
+ path: "deposit_token_program"
7537
7984
  },
7538
7985
  {
7539
7986
  kind: "account",
@@ -7584,8 +8031,7 @@ var instructions = [
7584
8031
  address: "11111111111111111111111111111111"
7585
8032
  },
7586
8033
  {
7587
- name: "token_program",
7588
- address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
8034
+ name: "deposit_token_program"
7589
8035
  },
7590
8036
  {
7591
8037
  name: "associated_token_program",
@@ -9367,41 +9813,8 @@ var instructions = [
9367
9813
  path: "glam_vault"
9368
9814
  },
9369
9815
  {
9370
- kind: "const",
9371
- value: [
9372
- 6,
9373
- 221,
9374
- 246,
9375
- 225,
9376
- 215,
9377
- 101,
9378
- 161,
9379
- 147,
9380
- 217,
9381
- 203,
9382
- 225,
9383
- 70,
9384
- 206,
9385
- 235,
9386
- 121,
9387
- 172,
9388
- 28,
9389
- 180,
9390
- 133,
9391
- 237,
9392
- 95,
9393
- 91,
9394
- 55,
9395
- 145,
9396
- 58,
9397
- 140,
9398
- 245,
9399
- 133,
9400
- 126,
9401
- 255,
9402
- 0,
9403
- 169
9404
- ]
9816
+ kind: "account",
9817
+ path: "deposit_token_program"
9405
9818
  },
9406
9819
  {
9407
9820
  kind: "account",
@@ -9457,41 +9870,8 @@ var instructions = [
9457
9870
  path: "signer"
9458
9871
  },
9459
9872
  {
9460
- kind: "const",
9461
- value: [
9462
- 6,
9463
- 221,
9464
- 246,
9465
- 225,
9466
- 215,
9467
- 101,
9468
- 161,
9469
- 147,
9470
- 217,
9471
- 203,
9472
- 225,
9473
- 70,
9474
- 206,
9475
- 235,
9476
- 121,
9477
- 172,
9478
- 28,
9479
- 180,
9480
- 133,
9481
- 237,
9482
- 95,
9483
- 91,
9484
- 55,
9485
- 145,
9486
- 58,
9487
- 140,
9488
- 245,
9489
- 133,
9490
- 126,
9491
- 255,
9492
- 0,
9493
- 169
9494
- ]
9873
+ kind: "account",
9874
+ path: "deposit_token_program"
9495
9875
  },
9496
9876
  {
9497
9877
  kind: "account",
@@ -9547,8 +9927,7 @@ var instructions = [
9547
9927
  address: "11111111111111111111111111111111"
9548
9928
  },
9549
9929
  {
9550
- name: "token_program",
9551
- address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
9930
+ name: "deposit_token_program"
9552
9931
  },
9553
9932
  {
9554
9933
  name: "token_2022_program",
@@ -9890,79 +10269,331 @@ var instructions = [
9890
10269
  signer: true
9891
10270
  },
9892
10271
  {
9893
- name: "glam_mint",
9894
- writable: true
10272
+ name: "glam_mint",
10273
+ writable: true
10274
+ },
10275
+ {
10276
+ name: "token_2022_program",
10277
+ address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
10278
+ }
10279
+ ],
10280
+ args: [
10281
+ {
10282
+ name: "mint_id",
10283
+ type: "u8"
10284
+ }
10285
+ ]
10286
+ },
10287
+ {
10288
+ name: "update_state",
10289
+ discriminator: [
10290
+ 135,
10291
+ 112,
10292
+ 215,
10293
+ 75,
10294
+ 247,
10295
+ 185,
10296
+ 53,
10297
+ 176
10298
+ ],
10299
+ accounts: [
10300
+ {
10301
+ name: "glam_state",
10302
+ writable: true
10303
+ },
10304
+ {
10305
+ name: "glam_signer",
10306
+ writable: true,
10307
+ signer: true
10308
+ }
10309
+ ],
10310
+ args: [
10311
+ {
10312
+ name: "state",
10313
+ type: {
10314
+ defined: {
10315
+ name: "StateModel"
10316
+ }
10317
+ }
10318
+ }
10319
+ ]
10320
+ },
10321
+ {
10322
+ name: "update_state_apply_timelock",
10323
+ discriminator: [
10324
+ 66,
10325
+ 12,
10326
+ 138,
10327
+ 80,
10328
+ 133,
10329
+ 85,
10330
+ 46,
10331
+ 220
10332
+ ],
10333
+ accounts: [
10334
+ {
10335
+ name: "glam_state",
10336
+ writable: true
10337
+ },
10338
+ {
10339
+ name: "glam_signer",
10340
+ writable: true,
10341
+ signer: true
10342
+ }
10343
+ ],
10344
+ args: []
10345
+ },
10346
+ {
10347
+ name: "vote_authorize",
10348
+ discriminator: [
10349
+ 61,
10350
+ 48,
10351
+ 136,
10352
+ 95,
10353
+ 88,
10354
+ 65,
10355
+ 161,
10356
+ 215
10357
+ ],
10358
+ accounts: [
10359
+ {
10360
+ name: "glam_state"
10361
+ },
10362
+ {
10363
+ name: "glam_vault",
10364
+ writable: true,
10365
+ pda: {
10366
+ seeds: [
10367
+ {
10368
+ kind: "const",
10369
+ value: [
10370
+ 118,
10371
+ 97,
10372
+ 117,
10373
+ 108,
10374
+ 116
10375
+ ]
10376
+ },
10377
+ {
10378
+ kind: "account",
10379
+ path: "glam_state"
10380
+ }
10381
+ ]
10382
+ }
10383
+ },
10384
+ {
10385
+ name: "glam_signer",
10386
+ writable: true,
10387
+ signer: true
10388
+ },
10389
+ {
10390
+ name: "cpi_program",
10391
+ address: "Vote111111111111111111111111111111111111111"
10392
+ },
10393
+ {
10394
+ name: "vote",
10395
+ writable: true
10396
+ },
10397
+ {
10398
+ name: "clock",
10399
+ address: "SysvarC1ock11111111111111111111111111111111"
10400
+ }
10401
+ ],
10402
+ args: [
10403
+ {
10404
+ name: "new_authority",
10405
+ type: "pubkey"
10406
+ },
10407
+ {
10408
+ name: "vote_authorize",
10409
+ type: {
10410
+ defined: {
10411
+ name: "VoteAuthorizeEnum"
10412
+ }
10413
+ }
10414
+ }
10415
+ ]
10416
+ },
10417
+ {
10418
+ name: "vote_update_commission",
10419
+ discriminator: [
10420
+ 193,
10421
+ 83,
10422
+ 224,
10423
+ 17,
10424
+ 218,
10425
+ 144,
10426
+ 211,
10427
+ 60
10428
+ ],
10429
+ accounts: [
10430
+ {
10431
+ name: "glam_state"
10432
+ },
10433
+ {
10434
+ name: "glam_vault",
10435
+ writable: true,
10436
+ pda: {
10437
+ seeds: [
10438
+ {
10439
+ kind: "const",
10440
+ value: [
10441
+ 118,
10442
+ 97,
10443
+ 117,
10444
+ 108,
10445
+ 116
10446
+ ]
10447
+ },
10448
+ {
10449
+ kind: "account",
10450
+ path: "glam_state"
10451
+ }
10452
+ ]
10453
+ }
10454
+ },
10455
+ {
10456
+ name: "glam_signer",
10457
+ writable: true,
10458
+ signer: true
10459
+ },
10460
+ {
10461
+ name: "cpi_program",
10462
+ address: "Vote111111111111111111111111111111111111111"
9895
10463
  },
9896
10464
  {
9897
- name: "token_2022_program",
9898
- address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
10465
+ name: "vote",
10466
+ writable: true
9899
10467
  }
9900
10468
  ],
9901
10469
  args: [
9902
10470
  {
9903
- name: "mint_id",
10471
+ name: "new_commission",
9904
10472
  type: "u8"
9905
10473
  }
9906
10474
  ]
9907
10475
  },
9908
10476
  {
9909
- name: "update_state",
10477
+ name: "vote_update_validator_identity",
9910
10478
  discriminator: [
9911
- 135,
9912
- 112,
9913
- 215,
9914
- 75,
9915
- 247,
9916
- 185,
9917
- 53,
9918
- 176
10479
+ 164,
10480
+ 111,
10481
+ 105,
10482
+ 150,
10483
+ 248,
10484
+ 104,
10485
+ 150,
10486
+ 8
9919
10487
  ],
9920
10488
  accounts: [
9921
10489
  {
9922
- name: "glam_state",
9923
- writable: true
10490
+ name: "glam_state"
10491
+ },
10492
+ {
10493
+ name: "glam_vault",
10494
+ writable: true,
10495
+ pda: {
10496
+ seeds: [
10497
+ {
10498
+ kind: "const",
10499
+ value: [
10500
+ 118,
10501
+ 97,
10502
+ 117,
10503
+ 108,
10504
+ 116
10505
+ ]
10506
+ },
10507
+ {
10508
+ kind: "account",
10509
+ path: "glam_state"
10510
+ }
10511
+ ]
10512
+ }
9924
10513
  },
9925
10514
  {
9926
10515
  name: "glam_signer",
9927
10516
  writable: true,
9928
10517
  signer: true
9929
- }
9930
- ],
9931
- args: [
10518
+ },
9932
10519
  {
9933
- name: "state",
9934
- type: {
9935
- defined: {
9936
- name: "StateModel"
9937
- }
9938
- }
10520
+ name: "cpi_program",
10521
+ address: "Vote111111111111111111111111111111111111111"
10522
+ },
10523
+ {
10524
+ name: "vote",
10525
+ writable: true
10526
+ },
10527
+ {
10528
+ name: "identity",
10529
+ writable: true,
10530
+ signer: true
9939
10531
  }
9940
- ]
10532
+ ],
10533
+ args: []
9941
10534
  },
9942
10535
  {
9943
- name: "update_state_apply_timelock",
10536
+ name: "vote_withdraw",
9944
10537
  discriminator: [
9945
- 66,
9946
- 12,
9947
- 138,
9948
- 80,
9949
- 133,
9950
- 85,
9951
- 46,
9952
- 220
10538
+ 193,
10539
+ 3,
10540
+ 236,
10541
+ 192,
10542
+ 122,
10543
+ 146,
10544
+ 217,
10545
+ 149
9953
10546
  ],
9954
10547
  accounts: [
9955
10548
  {
9956
- name: "glam_state",
9957
- writable: true
10549
+ name: "glam_state"
10550
+ },
10551
+ {
10552
+ name: "glam_vault",
10553
+ writable: true,
10554
+ pda: {
10555
+ seeds: [
10556
+ {
10557
+ kind: "const",
10558
+ value: [
10559
+ 118,
10560
+ 97,
10561
+ 117,
10562
+ 108,
10563
+ 116
10564
+ ]
10565
+ },
10566
+ {
10567
+ kind: "account",
10568
+ path: "glam_state"
10569
+ }
10570
+ ]
10571
+ }
9958
10572
  },
9959
10573
  {
9960
10574
  name: "glam_signer",
9961
10575
  writable: true,
9962
10576
  signer: true
10577
+ },
10578
+ {
10579
+ name: "cpi_program",
10580
+ address: "Vote111111111111111111111111111111111111111"
10581
+ },
10582
+ {
10583
+ name: "vote",
10584
+ writable: true
10585
+ },
10586
+ {
10587
+ name: "recipient",
10588
+ writable: true
9963
10589
  }
9964
10590
  ],
9965
- args: []
10591
+ args: [
10592
+ {
10593
+ name: "lamports",
10594
+ type: "u64"
10595
+ }
10596
+ ]
9966
10597
  },
9967
10598
  {
9968
10599
  name: "withdraw",
@@ -10211,16 +10842,21 @@ var errors = [
10211
10842
  },
10212
10843
  {
10213
10844
  code: 48006,
10845
+ name: "CannotApplyChanges",
10846
+ msg: "Pending changes cannot be applied due to unfulfilled subscriptions or redemptions"
10847
+ },
10848
+ {
10849
+ code: 48007,
10214
10850
  name: "AssetNotBorrowable",
10215
10851
  msg: "Asset is not allowed to borrow"
10216
10852
  },
10217
10853
  {
10218
- code: 48007,
10854
+ code: 48008,
10219
10855
  name: "InvalidAccountOwner",
10220
10856
  msg: "Account owned by an invalid program"
10221
10857
  },
10222
10858
  {
10223
- code: 48008,
10859
+ code: 48009,
10224
10860
  name: "InvalidAuthority",
10225
10861
  msg: "Invalid authority"
10226
10862
  },
@@ -10928,7 +11564,7 @@ var types = [
10928
11564
  name: "MinRedemption"
10929
11565
  },
10930
11566
  {
10931
- name: "NotifyAndSettle"
11567
+ name: "RedemptionNotifyAndSettle"
10932
11568
  },
10933
11569
  {
10934
11570
  name: "Ledger"
@@ -10995,6 +11631,12 @@ var types = [
10995
11631
  },
10996
11632
  {
10997
11633
  name: "BorrowableAssets"
11634
+ },
11635
+ {
11636
+ name: "DriftVaultsAllowlist"
11637
+ },
11638
+ {
11639
+ name: "KaminoVaultsAllowlist"
10998
11640
  }
10999
11641
  ]
11000
11642
  }
@@ -11781,6 +12423,9 @@ var types = [
11781
12423
  },
11782
12424
  {
11783
12425
  name: "KaminoVaults"
12426
+ },
12427
+ {
12428
+ name: "Validator"
11784
12429
  }
11785
12430
  ]
11786
12431
  }
@@ -12366,9 +13011,9 @@ var types = [
12366
13011
  }
12367
13012
  },
12368
13013
  {
12369
- name: "immediate_or_cancel",
13014
+ name: "bit_flags",
12370
13015
  type: {
12371
- option: "bool"
13016
+ option: "u8"
12372
13017
  }
12373
13018
  },
12374
13019
  {
@@ -12663,8 +13308,8 @@ var types = [
12663
13308
  }
12664
13309
  },
12665
13310
  {
12666
- name: "immediate_or_cancel",
12667
- type: "bool"
13311
+ name: "bit_flags",
13312
+ type: "u8"
12668
13313
  },
12669
13314
  {
12670
13315
  name: "max_ts",
@@ -12822,7 +13467,7 @@ var types = [
12822
13467
  name: "Unstake"
12823
13468
  },
12824
13469
  {
12825
- name: "__DeprecatedLiquidUnstake"
13470
+ name: "DriftCancelOrders"
12826
13471
  },
12827
13472
  {
12828
13473
  name: "JupiterSwapAllowlisted"
@@ -12834,7 +13479,7 @@ var types = [
12834
13479
  name: "WSol"
12835
13480
  },
12836
13481
  {
12837
- name: "__DeprecatedWSolUnwrap"
13482
+ name: "DriftClaim"
12838
13483
  },
12839
13484
  {
12840
13485
  name: "MintMintTokens"
@@ -12913,6 +13558,21 @@ var types = [
12913
13558
  },
12914
13559
  {
12915
13560
  name: "KaminoVaultsWithdraw"
13561
+ },
13562
+ {
13563
+ name: "ValidatorAdmin"
13564
+ },
13565
+ {
13566
+ name: "ValidatorWithdraw"
13567
+ },
13568
+ {
13569
+ name: "ValidatorWithdrawToAny"
13570
+ },
13571
+ {
13572
+ name: "ValidatorWithdrawToIdentity"
13573
+ },
13574
+ {
13575
+ name: "Fulfill"
12916
13576
  }
12917
13577
  ]
12918
13578
  }
@@ -13651,6 +14311,22 @@ var types = [
13651
14311
  option: "u32"
13652
14312
  }
13653
14313
  },
14314
+ {
14315
+ name: "drift_vaults_allowlist",
14316
+ type: {
14317
+ option: {
14318
+ vec: "pubkey"
14319
+ }
14320
+ }
14321
+ },
14322
+ {
14323
+ name: "kamino_vaults_allowlist",
14324
+ type: {
14325
+ option: {
14326
+ vec: "pubkey"
14327
+ }
14328
+ }
14329
+ },
13654
14330
  {
13655
14331
  name: "metadata",
13656
14332
  type: {
@@ -13770,6 +14446,20 @@ var types = [
13770
14446
  ]
13771
14447
  }
13772
14448
  },
14449
+ {
14450
+ name: "VoteAuthorizeEnum",
14451
+ type: {
14452
+ kind: "enum",
14453
+ variants: [
14454
+ {
14455
+ name: "Voter"
14456
+ },
14457
+ {
14458
+ name: "Withdrawer"
14459
+ }
14460
+ ]
14461
+ }
14462
+ },
13773
14463
  {
13774
14464
  name: "WithdrawUnit",
13775
14465
  type: {
@@ -13856,6 +14546,7 @@ const STAKE_ACCOUNT_SIZE = 200;
13856
14546
  const METEORA_POSITION_SIZE = 8120;
13857
14547
  const KAMINO_OBTRIGATION_SIZE = 3344;
13858
14548
  const DRIFT_VAULT_DEPOSITOR_SIZE = 272;
14549
+ const JUPITER_API_DEFAULT = "https://lite-api.jup.ag";
13859
14550
  const JITO_TIP_DEFAULT = new web3_js.PublicKey("96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5");
13860
14551
  const KAMINO_SCOPE_PRICES = new web3_js.PublicKey("3NJYftD5sjVfxSnUdZ1wVML8f3aC6mp1CXCL6L7TnU8C");
13861
14552
  const MARINADE_NATIVE_STAKE_AUTHORITY = new web3_js.PublicKey("stWirqFCf2Uts1JBL1Jsd3r6VBWhgnpdPxCTe1MFjrq");
@@ -13885,6 +14576,7 @@ const KAMINO_LENDING_PROGRAM = new web3_js.PublicKey("KLend2g3cP87fffoy8q1mQqGKj
13885
14576
  const KAMINO_VAULTS_PROGRAM = new web3_js.PublicKey("KvauGMspG5k6rtzrqqn7WNn3oZdyKqLKwK2XWQ8FLjd");
13886
14577
  const KAMINO_FARM_PROGRAM = new web3_js.PublicKey("FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr");
13887
14578
  const MEMO_PROGRAM = new web3_js.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr");
14579
+ const ALT_PROGRAM_ID = new web3_js.PublicKey("AddressLookupTab1e1111111111111111111111111");
13888
14580
  /**
13889
14581
  * Stake pools
13890
14582
  */ const JITO_STAKE_POOL = new web3_js.PublicKey("Jito4APyf642JPZPx3hGc6WWJ8zPKtRbRs4P815Awbb");
@@ -13923,6 +14615,8 @@ class StateIdlModel {
13923
14615
  this.kaminoLendingMarkets = data.kaminoLendingMarkets ?? null;
13924
14616
  this.meteoraDlmmPools = data.meteoraDlmmPools ?? null;
13925
14617
  this.maxSwapSlippageBps = data.maxSwapSlippageBps ?? null;
14618
+ this.driftVaultsAllowlist = data.driftVaultsAllowlist ?? null;
14619
+ this.kaminoVaultsAllowlist = data.kaminoVaultsAllowlist ?? null;
13926
14620
  this.metadata = data.metadata ?? null;
13927
14621
  this.rawOpenfunds = data.rawOpenfunds ?? null;
13928
14622
  }
@@ -14274,6 +14968,14 @@ TimeUnit.Slot = {
14274
14968
  TimeUnit.Second = {
14275
14969
  second: {}
14276
14970
  };
14971
+ class VoteAuthorize {
14972
+ }
14973
+ VoteAuthorize.Voter = {
14974
+ voter: {}
14975
+ };
14976
+ VoteAuthorize.Withdrawer = {
14977
+ withdrawer: {}
14978
+ };
14277
14979
 
14278
14980
  var ClusterNetwork = /*#__PURE__*/ function(ClusterNetwork) {
14279
14981
  ClusterNetwork["Mainnet"] = "mainnet-beta";
@@ -14387,25 +15089,6 @@ const parseMeteoraPosition = async (connection, position)=>{
14387
15089
  binArrayUpper
14388
15090
  };
14389
15091
  };
14390
- async function fetchLookupTables(connection, authority, firstEntry) {
14391
- new web3_js.PublicKey("AddressLookupTab1e1111111111111111111111111");
14392
- // Fetch all accounts owned by the ALT program
14393
- // This is currently disabled due to RPC error "Request deprioritized due to number of accounts requested. Slow down requests or add filters to narrow down results"
14394
- // const accounts = await connection.getProgramAccounts(ALT_PROGRAM_ID, {
14395
- // filters: [
14396
- // { memcmp: { offset: 22, bytes: authority.toBase58() } },
14397
- // { memcmp: { offset: 56, bytes: firstEntry.toBase58() } }, // 1st entry in the table
14398
- // ],
14399
- // });
14400
- // return accounts.map(
14401
- // ({ pubkey, account }) =>
14402
- // new AddressLookupTableAccount({
14403
- // key: pubkey,
14404
- // state: AddressLookupTableAccount.deserialize(account.data),
14405
- // }),
14406
- // );
14407
- return [];
14408
- }
14409
15092
  /**
14410
15093
  * Parses program logs to extract error message
14411
15094
  */ function parseProgramLogs(logs) {
@@ -14422,8 +15105,8 @@ async function fetchLookupTables(connection, authority, firstEntry) {
14422
15105
  }
14423
15106
  return "Unknown error";
14424
15107
  }
14425
- const getSimulationComputeUnits = async (connection, instructions, payer, lookupTables)=>{
14426
- const testInstructions = [
15108
+ const getSimulationResult = async (connection, instructions, payer, lookupTables)=>{
15109
+ const testIxs = [
14427
15110
  // Set an arbitrarily high number in simulation
14428
15111
  // so we can be sure the transaction will succeed
14429
15112
  // and get the real compute units used
@@ -14432,19 +15115,30 @@ const getSimulationComputeUnits = async (connection, instructions, payer, lookup
14432
15115
  }),
14433
15116
  ...instructions
14434
15117
  ];
14435
- const testTransaction = new web3_js.VersionedTransaction(new web3_js.TransactionMessage({
14436
- instructions: testInstructions,
15118
+ const testTx = new web3_js.VersionedTransaction(new web3_js.TransactionMessage({
15119
+ instructions: testIxs,
14437
15120
  payerKey: payer,
14438
15121
  // RecentBlockhash can by any public key during simulation
14439
15122
  // since 'replaceRecentBlockhash' is set to 'true' below
14440
15123
  recentBlockhash: web3_js.PublicKey.default.toString()
14441
15124
  }).compileToV0Message(lookupTables));
14442
- const rpcResponse = await connection.simulateTransaction(testTransaction, {
14443
- replaceRecentBlockhash: true,
14444
- sigVerify: false
14445
- });
14446
- getErrorFromRPCResponse(rpcResponse);
14447
- return rpcResponse.value.unitsConsumed || undefined;
15125
+ const serializedTx = Buffer.from(testTx.serialize()).toString("base64");
15126
+ try {
15127
+ const rpcResponse = await connection.simulateTransaction(testTx, {
15128
+ replaceRecentBlockhash: true,
15129
+ sigVerify: false
15130
+ });
15131
+ getErrorFromRPCResponse(rpcResponse);
15132
+ return {
15133
+ unitsConsumed: rpcResponse.value.unitsConsumed,
15134
+ serializedTx
15135
+ };
15136
+ } catch (e) {
15137
+ return {
15138
+ error: e,
15139
+ serializedTx
15140
+ };
15141
+ }
14448
15142
  };
14449
15143
  const getErrorFromRPCResponse = (rpcResponse)=>{
14450
15144
  // Note: `confirmTransaction` does not throw an error if the confirmation does not succeed,
@@ -14504,6 +15198,15 @@ const STAKE_POOLS = sanctumLstList.LstList.filter((lst)=>!lst.name.includes("San
14504
15198
  poolState: new web3_js.PublicKey(poolState)
14505
15199
  };
14506
15200
  });
15201
+ STAKE_POOLS.push({
15202
+ name: "Phantom Staked SOL",
15203
+ symbol: "PSOL",
15204
+ mint: "pSo1f9nQXWgXibFtKf7NWYxb5enAM4qfP6UJSiXRQfL",
15205
+ decimals: 9,
15206
+ logoURI: "https://assets.phantom.app/assets/metadata/PSOL-512.png",
15207
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
15208
+ poolState: new web3_js.PublicKey("pSPcvR8GmG9aKDUbn9nbKYjkxt9hxMS7kF1qqKJaPqJ")
15209
+ });
14507
15210
  const STAKE_POOLS_MAP = new Map(STAKE_POOLS.map((p)=>[
14508
15211
  p.mint,
14509
15212
  p
@@ -14798,13 +15501,18 @@ function getAccountPolicyPda(tokenAccount) {
14798
15501
  ], TRANSFER_HOOK_PROGRAM)[0];
14799
15502
  }
14800
15503
 
14801
- const JUPITER_API_DEFAULT = "https://lite-api.jup.ag";
14802
15504
  const DEFAULT_PRIORITY_FEE = 10000; // microLamports
14803
15505
  const LOOKUP_TABLES = [
14804
15506
  new web3_js.PublicKey("284iwGtA9X9aLy3KsyV8uT2pXLARhYbiSi5SiM2g47M2"),
14805
15507
  new web3_js.PublicKey("D9cnvzswDikQDf53k4HpQ3KJ9y1Fv3HGGDFYMXnK5T6c"),
14806
15508
  new web3_js.PublicKey("EiWSskK5HXnBTptiS5DH6gpAJRVNQ3cAhTKBGaiaysAb")
14807
15509
  ];
15510
+ const STATES_LOOKUP_TABLES_MAP = new Map([
15511
+ [
15512
+ "3tfbxaHBDjczQo3eyNJGGG64ChZ9nG4V3Gywa4k59d5a",
15513
+ new web3_js.PublicKey("8HUXT9abWS2z3z92QyDzg51nMcc18LyWFvaEQZJMPixu")
15514
+ ]
15515
+ ]);
14808
15516
  const isBrowser = process.env.ANCHOR_BROWSER || typeof window !== "undefined" && !window.process?.hasOwnProperty("type");
14809
15517
  class BaseClient {
14810
15518
  get detectedCluster() {
@@ -14829,10 +15537,15 @@ class BaseClient {
14829
15537
  get isMainnet() {
14830
15538
  return this.cluster === ClusterNetwork.Mainnet;
14831
15539
  }
14832
- isPhantom() {
15540
+ isPhantomConnected() {
14833
15541
  if (!isBrowser) return false;
14834
- // TODO: remove when we can bypass from settings
14835
- return false;
15542
+ // Phantom automatically estimates fees
15543
+ // https://docs.phantom.app/developer-powertools/solana-priority-fees#how-phantom-applies-priority-fees-to-dapp-transactions
15544
+ // @ts-ignore
15545
+ const isPhantom = !!window?.phantom?.solana?.isPhantom;
15546
+ // @ts-ignore
15547
+ const isConnected = !!window?.phantom?.solana?.isConnected;
15548
+ return isPhantom && isConnected;
14836
15549
  }
14837
15550
  /**
14838
15551
  * Get metadata of an asset for pricing
@@ -14850,9 +15563,6 @@ class BaseClient {
14850
15563
  return assetMeta;
14851
15564
  }
14852
15565
  async getComputeBudgetIxs(vTx, computeUnitLimit, getPriorityFeeMicroLamports, maxFeeLamports, useMaxFee) {
14853
- if (this.isPhantom()) {
14854
- return [];
14855
- }
14856
15566
  // ComputeBudgetProgram.setComputeUnitLimit costs 150 CUs
14857
15567
  // Add 20% more CUs to account for variable execution
14858
15568
  computeUnitLimit += 150;
@@ -14884,6 +15594,59 @@ class BaseClient {
14884
15594
  })
14885
15595
  ];
14886
15596
  }
15597
+ /**
15598
+ * Fetches lookup tables for the current GLAM instance
15599
+ */ async findLookupTables() {
15600
+ const glamApi = process.env.NEXT_PUBLIC_GLAM_API || process.env.GLAM_API;
15601
+ if (glamApi) {
15602
+ const response = await fetch(`${glamApi}/v0/lut/glam/?state=${this.statePda}`);
15603
+ const data = await response.json();
15604
+ const { t: lookupTables } = data;
15605
+ const pubkeys = Object.keys(lookupTables);
15606
+ if (pubkeys.length > 0) {
15607
+ return await this.fetchAdressLookupTableAccounts(pubkeys);
15608
+ }
15609
+ }
15610
+ const tablePubkey = STATES_LOOKUP_TABLES_MAP.get(this.statePda.toBase58());
15611
+ if (tablePubkey) {
15612
+ return await this.fetchAdressLookupTableAccounts([
15613
+ tablePubkey
15614
+ ]);
15615
+ }
15616
+ // Fetch all accounts owned by the ALT program
15617
+ // This is very likely to hit the RPC error "Request deprioritized due to number of accounts requested. Slow down requests or add filters to narrow down results"
15618
+ const accounts = await this.provider.connection.getProgramAccounts(ALT_PROGRAM_ID, {
15619
+ filters: [
15620
+ {
15621
+ memcmp: {
15622
+ offset: 0,
15623
+ bytes: bytes.bs58.encode([
15624
+ 1,
15625
+ 0,
15626
+ 0,
15627
+ 0
15628
+ ])
15629
+ }
15630
+ },
15631
+ {
15632
+ memcmp: {
15633
+ offset: 56,
15634
+ bytes: this.statePda.toBase58()
15635
+ }
15636
+ },
15637
+ {
15638
+ memcmp: {
15639
+ offset: 88,
15640
+ bytes: this.vaultPda.toBase58()
15641
+ }
15642
+ }
15643
+ ]
15644
+ });
15645
+ return accounts.map(({ pubkey, account })=>new web3_js.AddressLookupTableAccount({
15646
+ key: pubkey,
15647
+ state: web3_js.AddressLookupTableAccount.deserialize(account.data)
15648
+ }));
15649
+ }
14887
15650
  async intoVersionedTransaction(tx, { lookupTables = [], signer, computeUnitLimit, getPriorityFeeMicroLamports, maxFeeLamports, useMaxFee = false, jitoTipLamports, simulate = false }) {
14888
15651
  signer = signer || this.getSigner();
14889
15652
  const instructions = tx.instructions;
@@ -14895,33 +15658,37 @@ class BaseClient {
14895
15658
  lamports: jitoTipLamports
14896
15659
  }));
14897
15660
  }
14898
- lookupTables.push(...await this.getAdressLookupTableAccounts(LOOKUP_TABLES));
14899
- const recentBlockhash = (await this.blockhashWithCache.get()).blockhash;
14900
- try {
14901
- computeUnitLimit = await getSimulationComputeUnits(this.provider.connection, instructions, signer, lookupTables);
14902
- } catch (e) {
14903
- // by default, a simulation error doesn't prevent the tx from being sent
14904
- // - when we run tests with failure cases, this RPC call fails with an incorrect error message so we should ignore it by default
14905
- // - gui: wallet apps usually do the simulation themselves, we should ignore the simulation error here by default
14906
- // - cli: we should set simulate=true
14907
- if (simulate) {
14908
- const vTx = new web3_js.VersionedTransaction(new web3_js.TransactionMessage({
14909
- instructions,
14910
- payerKey: signer,
14911
- recentBlockhash: web3_js.PublicKey.default.toString()
14912
- }).compileToV0Message(lookupTables));
14913
- console.log("Lookup tables:", lookupTables.map((lt)=>lt.key.toString()));
14914
- console.log("Tx (base64):", Buffer.from(vTx.serialize()).toString("base64"));
14915
- console.error("Simulation failed. If error message is too obscure, inspect and simulate the tx in explorer: https://explorer.solana.com/tx/inspector");
14916
- throw e;
14917
- }
15661
+ const lookupTableAccounts = [];
15662
+ if (lookupTables.every((t)=>t instanceof web3_js.AddressLookupTableAccount)) {
15663
+ const accounts = await this.fetchAdressLookupTableAccounts([
15664
+ ...LOOKUP_TABLES
15665
+ ]);
15666
+ lookupTableAccounts.push(...lookupTables, ...accounts);
15667
+ } else {
15668
+ const accounts = await this.fetchAdressLookupTableAccounts([
15669
+ ...lookupTables,
15670
+ ...LOOKUP_TABLES
15671
+ ]);
15672
+ lookupTableAccounts.push(...accounts);
15673
+ }
15674
+ const recentBlockhash = (await this.blockhashWithCache.get()).blockhash;
15675
+ const { unitsConsumed, error, serializedTx } = await getSimulationResult(this.provider.connection, instructions, signer, lookupTableAccounts);
15676
+ computeUnitLimit = unitsConsumed;
15677
+ // by default, a simulation error doesn't prevent the tx from being sent
15678
+ // - gui: wallet apps usually do the simulation themselves, we should ignore the simulation error here by default
15679
+ // - cli: we should set simulate=true
15680
+ if (error && simulate) {
15681
+ console.log("Tx (base64):", serializedTx);
15682
+ console.error("Simulation failed:", error.message);
15683
+ console.error("If error message is too obscure, inspect and simulate the tx in explorer: https://explorer.solana.com/tx/inspector");
15684
+ throw error;
14918
15685
  }
14919
15686
  if (computeUnitLimit) {
14920
15687
  const vTx = new web3_js.VersionedTransaction(new web3_js.TransactionMessage({
14921
15688
  payerKey: signer,
14922
15689
  recentBlockhash,
14923
15690
  instructions
14924
- }).compileToV0Message(lookupTables));
15691
+ }).compileToV0Message(lookupTableAccounts));
14925
15692
  const cuIxs = await this.getComputeBudgetIxs(vTx, computeUnitLimit, getPriorityFeeMicroLamports, maxFeeLamports, useMaxFee);
14926
15693
  instructions.unshift(...cuIxs);
14927
15694
  }
@@ -14929,7 +15696,7 @@ class BaseClient {
14929
15696
  payerKey: signer,
14930
15697
  recentBlockhash,
14931
15698
  instructions
14932
- }).compileToV0Message(lookupTables));
15699
+ }).compileToV0Message(lookupTableAccounts));
14933
15700
  }
14934
15701
  async sendAndConfirm(tx, additionalSigners = []) {
14935
15702
  const connection = this.provider.connection;
@@ -14977,13 +15744,21 @@ class BaseClient {
14977
15744
  }
14978
15745
  return txSig;
14979
15746
  }
14980
- async getAdressLookupTableAccounts(keys) {
14981
- if (!keys) {
15747
+ /**
15748
+ * Fetches multiple address lookup table accounts.
15749
+ *
15750
+ * @param pubkeys Array of lookup table public keys.
15751
+ * @returns
15752
+ */ async fetchAdressLookupTableAccounts(pubkeys) {
15753
+ if (!pubkeys) {
14982
15754
  throw new Error("addressLookupTableAddresses is undefined");
14983
15755
  }
14984
- const addressLookupTableAccountInfos = await this.provider.connection.getMultipleAccountsInfo(keys.map((key)=>new web3_js.PublicKey(key)));
15756
+ if (pubkeys.length === 0) {
15757
+ return [];
15758
+ }
15759
+ const addressLookupTableAccountInfos = await this.provider.connection.getMultipleAccountsInfo(pubkeys.map((key)=>new web3_js.PublicKey(key)));
14985
15760
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index)=>{
14986
- const tableAddress = keys[index];
15761
+ const tableAddress = pubkeys[index];
14987
15762
  if (accountInfo) {
14988
15763
  const tableAccount = new web3_js.AddressLookupTableAccount({
14989
15764
  key: new web3_js.PublicKey(tableAddress),
@@ -15086,7 +15861,7 @@ class BaseClient {
15086
15861
  try {
15087
15862
  const account = await splToken.getAccount(this.provider.connection, ata, "confirmed", tokenProgram);
15088
15863
  return {
15089
- amount: new anchor.BN(account.amount),
15864
+ amount: new anchor.BN(account.amount.toString()),
15090
15865
  uiAmount: Number(account.amount) / Math.pow(10, mint.decimals)
15091
15866
  };
15092
15867
  } catch (e) {
@@ -15099,6 +15874,21 @@ class BaseClient {
15099
15874
  throw e;
15100
15875
  }
15101
15876
  }
15877
+ async fetchMintsAndTokenPrograms(mintPubkeys) {
15878
+ const connection = this.provider.connection;
15879
+ const accountsInfo = await connection.getMultipleAccountsInfo(mintPubkeys, "confirmed");
15880
+ return accountsInfo.map((info, i)=>{
15881
+ if (!info) {
15882
+ throw new Error(`Mint ${mintPubkeys[i]} not found`);
15883
+ }
15884
+ const tokenProgram = info.owner;
15885
+ const mint = splToken.unpackMint(mintPubkeys[i], info, tokenProgram);
15886
+ return {
15887
+ mint,
15888
+ tokenProgram
15889
+ };
15890
+ });
15891
+ }
15102
15892
  async fetchMintAndTokenProgram(mintPubkey) {
15103
15893
  const connection = this.provider.connection;
15104
15894
  const info = await connection.getAccountInfo(mintPubkey, "confirmed");
@@ -15128,6 +15918,7 @@ class BaseClient {
15128
15918
  if (!this.statePda) {
15129
15919
  throw new Error("State PDA is not specified");
15130
15920
  }
15921
+ // @ts-ignore
15131
15922
  const state = await this.fetchStateAccount();
15132
15923
  if (state.params.length < 2) {
15133
15924
  throw new Error("Invalid mint index");
@@ -15283,7 +16074,6 @@ class BaseClient {
15283
16074
  if (config?.statePda) {
15284
16075
  this.statePda = config.statePda;
15285
16076
  }
15286
- this.jupiterApi = config?.jupiterApi || JUPITER_API_DEFAULT;
15287
16077
  this.blockhashWithCache = new BlockhashWithCache(this.provider, false);
15288
16078
  }
15289
16079
  }
@@ -16264,6 +17054,8 @@ function decodeUser(buffer) {
16264
17054
  };
16265
17055
  }
16266
17056
 
17057
+ const DRIFT_DISTRIBUTOR_PROGRAM = new web3_js.PublicKey("E7HtfkEMhmn9uwL7EFNydcXBWy5WCYN1vFmKKjipEH1x");
17058
+ const DRIFT = new web3_js.PublicKey("DriFtupJYLTosbwoN8koMbEYSx54aFAVLddWsbksjwg7");
16267
17059
  const DRIFT_SIGNER = new web3_js.PublicKey("JCNCMFXo5M5qwUPg2Utu1u6YWp3MbygxqBsBeXXJfrw");
16268
17060
  const DRIFT_MARGIN_PRECISION = 10000;
16269
17061
  class DriftClient {
@@ -16420,7 +17212,7 @@ class DriftClient {
16420
17212
  // If not, it means some market indexes are invalid and we throw an error
16421
17213
  const spotMarkets = marketIndexes.map((marketIndex)=>this.spotMarkets.get(marketIndex)).filter((m)=>m);
16422
17214
  const invalidIndexes = marketIndexes.filter((marketIndex)=>!this.spotMarkets.has(marketIndex));
16423
- if (invalidIndexes.length > 0) {
17215
+ if (invalidIndexes.length > 0 && process.env.NODE_ENV === "development") {
16424
17216
  console.warn(`The following spot markets could not be found: ${invalidIndexes.join(", ")}`);
16425
17217
  }
16426
17218
  return spotMarkets;
@@ -16470,7 +17262,7 @@ class DriftClient {
16470
17262
  }
16471
17263
  const data = await response.json();
16472
17264
  const { orderConstants, perp, spot } = data;
16473
- // Transform perp market from API to `PerpMarket` type
17265
+ // Transform market data from API to `PerpMarket`/`SpotMarket` objects
16474
17266
  const perpMarkets = perp.map((m)=>({
16475
17267
  name: m.symbol,
16476
17268
  marketIndex: m.marketIndex,
@@ -16478,10 +17270,6 @@ class DriftClient {
16478
17270
  oracle: new web3_js.PublicKey(m.oracle),
16479
17271
  oracleSource: OracleSource.fromString(m.oracleSource)
16480
17272
  }));
16481
- perpMarkets.forEach((m)=>{
16482
- this.perpMarkets.set(m.marketIndex, m);
16483
- });
16484
- // Transform spot market from API to `SpotMarket` type
16485
17273
  const spotMarkets = spot.map((m)=>({
16486
17274
  name: m.symbol,
16487
17275
  marketIndex: m.marketIndex,
@@ -16495,6 +17283,10 @@ class DriftClient {
16495
17283
  cumulativeDepositInterest: new anchor.BN(m.cumulativeDepositInterest),
16496
17284
  cumulativeBorrowInterest: new anchor.BN(m.cumulativeBorrowInterest)
16497
17285
  }));
17286
+ // Cache market objects
17287
+ perpMarkets.forEach((m)=>{
17288
+ this.perpMarkets.set(m.marketIndex, m);
17289
+ });
16498
17290
  spotMarkets.forEach((m)=>{
16499
17291
  this.spotMarkets.set(m.marketIndex, m);
16500
17292
  });
@@ -16507,7 +17299,8 @@ class DriftClient {
16507
17299
  return marketConfigs;
16508
17300
  }
16509
17301
  // If glam API is not available, fetch market configs from RPC
16510
- if (!this.marketConfigs) {
17302
+ // Force refetching if skipCache is true
17303
+ if (!this.marketConfigs || skipCache) {
16511
17304
  const perpMarkets = await this.fetchAndParsePerpMarkets(Array.from(Array(100).keys()), skipCache);
16512
17305
  const spotMarkets = await this.fetchAndParseSpotMarkets(Array.from(Array(100).keys()), skipCache);
16513
17306
  this.marketConfigs = {
@@ -16524,18 +17317,19 @@ class DriftClient {
16524
17317
  charsToName(chars) {
16525
17318
  return String.fromCharCode(...chars).replace(/\0/g, "").trim();
16526
17319
  }
16527
- async fetchDriftUser(subAccountId = 0, skipCache = false) {
16528
- const { user } = this.getDriftUserPdas(subAccountId);
16529
- const accountInfo = await this.base.provider.connection.getAccountInfo(user);
16530
- if (!accountInfo) {
16531
- return null;
16532
- }
16533
- const { delegate, name, spotPositions, marginMode, perpPositions, isMarginTradingEnabled, maxMarginRatio, orders } = decodeUser(accountInfo.data);
16534
- // Prefetch market configs
16535
- const marketConfigs = await this.fetchMarketConfigs(skipCache);
17320
+ async parseDriftUser(accountInfo, subAccountId) {
17321
+ const { delegate, name, spotPositions, marginMode, perpPositions, isMarginTradingEnabled, maxMarginRatio, orders, poolId } = decodeUser(accountInfo.data);
17322
+ // Fetch spot and perp markets used by this user
17323
+ const spotMarketIndexes = spotPositions.map((p)=>p.marketIndex);
17324
+ const perpMarketIndexes = perpPositions.map((p)=>p.marketIndex);
17325
+ await Promise.all([
17326
+ this.fetchAndParseSpotMarkets(spotMarketIndexes),
17327
+ this.fetchAndParsePerpMarkets(perpMarketIndexes)
17328
+ ]);
17329
+ // Extend spot positions with market info
16536
17330
  const spotPositionsExt = await Promise.all(spotPositions.map(async (p)=>{
16537
17331
  const { amount, uiAmount } = await this.calcSpotBalance(p.marketIndex, p.scaledBalance, p.balanceType);
16538
- const spotMarket = marketConfigs.spotMarkets.find((m)=>m.marketIndex === p.marketIndex);
17332
+ const spotMarket = this.spotMarkets.get(p.marketIndex);
16539
17333
  return {
16540
17334
  ...p,
16541
17335
  amount,
@@ -16554,9 +17348,39 @@ class DriftClient {
16554
17348
  marginMode,
16555
17349
  subAccountId,
16556
17350
  isMarginTradingEnabled,
16557
- maxMarginRatio
17351
+ maxMarginRatio,
17352
+ poolId
16558
17353
  };
16559
17354
  }
17355
+ async fetchDriftUser(subAccountId = 0, skipCache = false) {
17356
+ const { user } = this.getDriftUserPdas(subAccountId);
17357
+ const accountInfo = await this.base.provider.connection.getAccountInfo(user);
17358
+ if (!accountInfo) {
17359
+ return null;
17360
+ }
17361
+ // Prefetch market configs
17362
+ await this.fetchMarketConfigs(skipCache);
17363
+ return await this.parseDriftUser(accountInfo, subAccountId);
17364
+ }
17365
+ async fetchDriftUsers(skipCache = false) {
17366
+ const userPdas = Array.from(Array(8).keys()).map((subAccountId)=>{
17367
+ const { user } = this.getDriftUserPdas(subAccountId);
17368
+ return user;
17369
+ });
17370
+ const accountsInfo = await this.base.provider.connection.getMultipleAccountsInfo(userPdas);
17371
+ const subAccountsInfoAndIds = [];
17372
+ accountsInfo.forEach((a, i)=>{
17373
+ if (a) {
17374
+ subAccountsInfoAndIds.push([
17375
+ a,
17376
+ i
17377
+ ]);
17378
+ }
17379
+ });
17380
+ // Prefetch market configs
17381
+ await this.fetchMarketConfigs(skipCache);
17382
+ return await Promise.all(subAccountsInfoAndIds.map(([accountInfo, subAccountId])=>this.parseDriftUser(accountInfo, subAccountId)));
17383
+ }
16560
17384
  /**
16561
17385
  * @deprecated
16562
17386
  */ async fetchPolicyConfig(stateModel) {
@@ -16616,6 +17440,36 @@ class DriftClient {
16616
17440
  isSigner: false
16617
17441
  })));
16618
17442
  }
17443
+ getClaimStatus(claimant, distributor) {
17444
+ const [claimStatus] = web3_js.PublicKey.findProgramAddressSync([
17445
+ Buffer.from("ClaimStatus"),
17446
+ claimant.toBuffer(),
17447
+ distributor.toBuffer()
17448
+ ], DRIFT_DISTRIBUTOR_PROGRAM);
17449
+ return claimStatus;
17450
+ }
17451
+ async claim(distributor, amountUnlocked, amountLocked, proof, txOptions = {}) {
17452
+ const glamSigner = txOptions.signer || this.base.getSigner();
17453
+ const vault = this.base.vaultPda;
17454
+ const vaultAta = this.base.getVaultAta(DRIFT);
17455
+ const distributorAta = this.base.getAta(DRIFT, distributor);
17456
+ const preInstructions = [
17457
+ splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, vaultAta, vault, DRIFT)
17458
+ ];
17459
+ const tx = await this.base.program.methods.driftDistributorNewClaim(amountUnlocked, amountLocked, proof).accounts({
17460
+ glamState: this.base.statePda,
17461
+ glamSigner,
17462
+ distributor,
17463
+ claimStatus: this.getClaimStatus(vault, distributor),
17464
+ from: distributorAta,
17465
+ to: vaultAta,
17466
+ tokenProgram: splToken.TOKEN_PROGRAM_ID
17467
+ }).preInstructions(preInstructions).transaction();
17468
+ const vTx = await this.base.intoVersionedTransaction(tx, {
17469
+ ...txOptions
17470
+ });
17471
+ return await this.base.sendAndConfirm(vTx);
17472
+ }
16619
17473
  async initializeUserStatsIx(glamSigner) {
16620
17474
  const { userStats } = this.getDriftUserPdas();
16621
17475
  // @ts-ignore
@@ -16650,6 +17504,13 @@ class DriftClient {
16650
17504
  glamSigner
16651
17505
  }).remainingAccounts(remainingAccounts).instruction();
16652
17506
  }
17507
+ async updateUserPoolIdIx(subAccountId, poolId) {
17508
+ const { user } = this.getDriftUserPdas(subAccountId);
17509
+ return await this.base.program.methods.driftUpdateUserPoolId(subAccountId, poolId).accounts({
17510
+ glamState: this.base.statePda,
17511
+ user
17512
+ }).instruction();
17513
+ }
16653
17514
  async initializeTx(subAccountId = 0, txOptions = {}) {
16654
17515
  const glamSigner = txOptions.signer || this.base.getSigner();
16655
17516
  const tx = new web3_js.Transaction();
@@ -16720,13 +17581,23 @@ class DriftClient {
16720
17581
  async depositTx(amount, marketIndex = 1, subAccountId = 0, txOptions = {}) {
16721
17582
  const glamSigner = txOptions.signer || this.base.getSigner();
16722
17583
  const { user, userStats } = this.getDriftUserPdas(subAccountId);
16723
- const { mint, oracle, tokenProgram, marketPda, vault: driftVault } = await this.fetchAndParseSpotMarket(marketIndex);
17584
+ const { mint, oracle, tokenProgram, marketPda, vault: driftVault, name } = await this.fetchAndParseSpotMarket(marketIndex);
16724
17585
  console.log(`Spot market ${marketIndex} mint ${mint}, oracle: ${oracle}, marketPda: ${marketPda}, vault: ${driftVault}`);
16725
17586
  const preInstructions = [];
16726
17587
  const postInstructions = [];
16727
- // If drift user doesn't exist, prepend initializeUserStats and initializeUser instructions
17588
+ // If drift user doesn't exist, prepend initialization ixs
16728
17589
  if (!await this.fetchDriftUser(subAccountId)) {
16729
- preInstructions.push(await this.initializeUserStatsIx(glamSigner), await this.initializeUserIx(glamSigner, subAccountId));
17590
+ preInstructions.push(await this.initializeUserIx(glamSigner, subAccountId));
17591
+ // Only add ix to initialize user stats if subAccountId is 0
17592
+ if (subAccountId === 0) {
17593
+ preInstructions.push(await this.initializeUserStatsIx(glamSigner));
17594
+ }
17595
+ // If market name ends with "-N", it means we're depositing to an isolated pool
17596
+ const isolatedPoolMatch = name.match(/-(\d+)$/);
17597
+ if (isolatedPoolMatch) {
17598
+ const poolId = parseInt(isolatedPoolMatch[1]);
17599
+ preInstructions.push(await this.updateUserPoolIdIx(subAccountId, poolId));
17600
+ }
16730
17601
  }
16731
17602
  if (mint.equals(WSOL)) {
16732
17603
  const wrapSolIxs = await this.base.maybeWrapSol(amount, glamSigner);
@@ -17103,6 +17974,35 @@ class DriftVaultsClient {
17103
17974
  }
17104
17975
 
17105
17976
  const BASE = new web3_js.PublicKey("bJ1TRoFo2P6UHVwqdiipp6Qhp2HaaHpLowZ5LHet8Gm");
17977
+ const JUPITER_API = process.env.NEXT_PUBLIC_JUPITER_API || process.env.JUPITER_API || JUPITER_API_DEFAULT;
17978
+ async function fetchProgramLabels() {
17979
+ const res = await fetch(`${JUPITER_API}/swap/v1/program-id-to-label`);
17980
+ const data = await res.json();
17981
+ return data;
17982
+ }
17983
+ async function fetchTokenPrices(pubkeys) {
17984
+ const res = await fetch(`${JUPITER_API}/price/v3?ids=${pubkeys.join(",")}`);
17985
+ const data = await res.json();
17986
+ return Object.entries(data).map(([key, val])=>{
17987
+ return {
17988
+ mint: key,
17989
+ price: val.usdPrice
17990
+ };
17991
+ });
17992
+ }
17993
+ async function fetchTokensList() {
17994
+ const response = await fetch(`${JUPITER_API}/tokens/v2/tag?query=verified`);
17995
+ const data = await response.json();
17996
+ const tokenList = data?.map((t)=>({
17997
+ address: t.id,
17998
+ name: t.name,
17999
+ symbol: t.symbol,
18000
+ decimals: t.decimals,
18001
+ logoURI: t.icon,
18002
+ tags: t.tags
18003
+ }));
18004
+ return tokenList;
18005
+ }
17106
18006
  class JupiterSwapClient {
17107
18007
  /*
17108
18008
  * Client methods
@@ -17114,16 +18014,6 @@ class JupiterSwapClient {
17114
18014
  const tx = await this.setMaxSwapSlippageTx(slippageBps, txOptions);
17115
18015
  return await this.base.sendAndConfirm(tx);
17116
18016
  }
17117
- async fetchProgramLabels() {
17118
- const res = await fetch(`${this.base.jupiterApi}/swap/v1/program-id-to-label`);
17119
- const data = await res.json();
17120
- return data;
17121
- }
17122
- async fetchTokenPrices(pubkeys) {
17123
- const res = await fetch(`${this.base.jupiterApi}/price/v2?ids=${pubkeys.join(",")}`);
17124
- const data = await res.json();
17125
- return data;
17126
- }
17127
18017
  /*
17128
18018
  * API methods
17129
18019
  */ async swapTx(options, txOptions = {}) {
@@ -17165,13 +18055,12 @@ class JupiterSwapClient {
17165
18055
  swapInstruction = swapInstructions.swapInstruction;
17166
18056
  addressLookupTableAddresses = swapInstructions.addressLookupTableAddresses;
17167
18057
  }
17168
- const lookupTables = await this.base.getAdressLookupTableAccounts(addressLookupTableAddresses);
18058
+ const lookupTables = addressLookupTableAddresses.map((pubkey)=>new web3_js.PublicKey(pubkey));
17169
18059
  const swapIx = this.toTransactionInstruction(swapInstruction, glamVault.toBase58());
17170
- // TODO: Optimize by using batch RPC
17171
- const [inputTokenProgram, outputTokenProgram] = await Promise.all([
17172
- this.getTokenProgram(inputMint),
17173
- this.getTokenProgram(outputMint)
17174
- ]);
18060
+ const [inputTokenProgram, outputTokenProgram] = (await this.base.fetchMintsAndTokenPrograms([
18061
+ inputMint,
18062
+ outputMint
18063
+ ])).map((x)=>x.tokenProgram);
17175
18064
  const inputStakePool = STAKE_POOLS_MAP.get(inputMint.toBase58())?.poolState || null;
17176
18065
  const outputStakePool = STAKE_POOLS_MAP.get(outputMint.toBase58())?.poolState || null;
17177
18066
  const preInstructions = await this.getPreInstructions(glamSigner, inputMint, outputMint, amount, inputTokenProgram, outputTokenProgram);
@@ -17206,7 +18095,7 @@ class JupiterSwapClient {
17206
18095
  return tx.instructions[0];
17207
18096
  }
17208
18097
  async getQuoteResponse(quoteParams) {
17209
- const res = await fetch(`${this.base.jupiterApi}/swap/v1/quote?` + new URLSearchParams(Object.entries(quoteParams).map(([key, val])=>[
18098
+ const res = await fetch(`${JUPITER_API}/swap/v1/quote?` + new URLSearchParams(Object.entries(quoteParams).map(([key, val])=>[
17210
18099
  key,
17211
18100
  String(val)
17212
18101
  ])));
@@ -17217,7 +18106,7 @@ class JupiterSwapClient {
17217
18106
  return data;
17218
18107
  }
17219
18108
  async getSwapInstructions(quoteResponse, from) {
17220
- const res = await fetch(`${this.base.jupiterApi}/swap/v1/swap-instructions`, {
18109
+ const res = await fetch(`${JUPITER_API}/swap/v1/swap-instructions`, {
17221
18110
  method: "POST",
17222
18111
  headers: {
17223
18112
  Accept: "application/json",
@@ -18305,6 +19194,7 @@ class StateClient {
18305
19194
  async create(partialStateModel, singleTx = false, txOptions = {}) {
18306
19195
  const glamSigner = txOptions.signer || this.base.getSigner();
18307
19196
  let stateModel = this.enrichStateModel(partialStateModel);
19197
+ // @ts-ignore
18308
19198
  const statePda = getStatePda(stateModel, this.base.program.programId);
18309
19199
  this.base.statePda = statePda;
18310
19200
  console.log(`State PDA set to GlamClient: ${statePda}`);
@@ -18586,6 +19476,7 @@ class MintClient {
18586
19476
  });
18587
19477
  }
18588
19478
  async update(mintModel, txOptions = {}) {
19479
+ // @ts-ignore
18589
19480
  const tx = await this.base.program.methods.updateMint(0, new MintIdlModel(mintModel)).accounts({
18590
19481
  glamState: this.base.statePda,
18591
19482
  glamMint: this.base.mintPda
@@ -18866,7 +19757,6 @@ const KVaultStateLayout = borsh.struct([
18866
19757
  borsh.array(borsh.u128(), 242, "padding3")
18867
19758
  ]);
18868
19759
 
18869
- const LOOKUP_TABLE = new web3_js.PublicKey("284iwGtA9X9aLy3KsyV8uT2pXLARhYbiSi5SiM2g47M2");
18870
19760
  const DEFAULT_OBLIGATION_ARGS = {
18871
19761
  tag: 0,
18872
19762
  id: 0
@@ -19390,6 +20280,7 @@ class KaminoLendingClient {
19390
20280
  const vault = this.base.vaultPda;
19391
20281
  const userMetadata = this.getUserMetadataPda(vault);
19392
20282
  const lookupTable = new web3_js.PublicKey(0); // FIXME: create lookup table
20283
+ // @ts-ignore
19393
20284
  const tx = await this.base.program.methods.kaminoLendingInitUserMetadata(lookupTable).accounts({
19394
20285
  glamState: this.base.statePda,
19395
20286
  glamSigner,
@@ -19510,13 +20401,7 @@ class KaminoLendingClient {
19510
20401
  reserveFarmState: depositReserve.farmCollateral,
19511
20402
  farmsProgram: KAMINO_FARM_PROGRAM
19512
20403
  }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
19513
- const lookupTables = txOptions.lookupTables || await this.base.getAdressLookupTableAccounts([
19514
- LOOKUP_TABLE
19515
- ]);
19516
- const vTx = await this.base.intoVersionedTransaction(tx, {
19517
- ...txOptions,
19518
- lookupTables
19519
- });
20404
+ const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
19520
20405
  return vTx;
19521
20406
  }
19522
20407
  async withdrawTx(market, asset, amount, txOptions) {
@@ -19601,13 +20486,7 @@ class KaminoLendingClient {
19601
20486
  // - refreshObligationFarmsForReserve (if farm exists)
19602
20487
  const tx = new web3_js.Transaction();
19603
20488
  tx.add(...preInstructions, withdrawIx, ...postInstructions);
19604
- const lookupTables = txOptions.lookupTables || await this.base.getAdressLookupTableAccounts([
19605
- LOOKUP_TABLE
19606
- ]);
19607
- const vTx = await this.base.intoVersionedTransaction(tx, {
19608
- ...txOptions,
19609
- lookupTables
19610
- });
20489
+ const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
19611
20490
  return vTx;
19612
20491
  }
19613
20492
  async borrowTx(market, asset, amount, txOptions) {
@@ -19689,13 +20568,7 @@ class KaminoLendingClient {
19689
20568
  // - borrowObligationLiquidityV2
19690
20569
  const tx = new web3_js.Transaction();
19691
20570
  tx.add(...preInstructions, borrowIx);
19692
- const lookupTables = txOptions.lookupTables || await this.base.getAdressLookupTableAccounts([
19693
- LOOKUP_TABLE
19694
- ]);
19695
- const vTx = await this.base.intoVersionedTransaction(tx, {
19696
- ...txOptions,
19697
- lookupTables
19698
- });
20571
+ const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
19699
20572
  return vTx;
19700
20573
  }
19701
20574
  async repayTx(market, asset, amount, txOptions = {}) {
@@ -19762,13 +20635,7 @@ class KaminoLendingClient {
19762
20635
  // - repayObligationLiquidityV2
19763
20636
  const tx = new web3_js.Transaction();
19764
20637
  tx.add(...preInstructions, repayIx);
19765
- const lookupTables = txOptions.lookupTables || await this.base.getAdressLookupTableAccounts([
19766
- LOOKUP_TABLE
19767
- ]);
19768
- const vTx = await this.base.intoVersionedTransaction(tx, {
19769
- ...txOptions,
19770
- lookupTables
19771
- });
20638
+ const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
19772
20639
  return vTx;
19773
20640
  }
19774
20641
  constructor(base){
@@ -19890,13 +20757,7 @@ class KaminoFarmClient {
19890
20757
  tx.add(createAtaIx, harvestIx);
19891
20758
  }
19892
20759
  }
19893
- const lookupTables = txOptions.lookupTables || await this.base.getAdressLookupTableAccounts([
19894
- LOOKUP_TABLE
19895
- ]);
19896
- const vTx = await this.base.intoVersionedTransaction(tx, {
19897
- ...txOptions,
19898
- lookupTables
19899
- });
20760
+ const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
19900
20761
  return vTx;
19901
20762
  }
19902
20763
  constructor(base){
@@ -19914,11 +20775,11 @@ class KaminoFarmClient {
19914
20775
  }
19915
20776
  class KaminoVaultsClient {
19916
20777
  async deposit(vault, amount, txOptions = {}) {
19917
- const tx = await this.depositTx(vault, amount, txOptions);
20778
+ const tx = await this.depositTx(vault, new anchor.BN(amount), txOptions);
19918
20779
  return await this.base.sendAndConfirm(tx);
19919
20780
  }
19920
20781
  async withdraw(vault, amount, txOptions = {}) {
19921
- const tx = await this.withdrawTx(vault, amount, txOptions);
20782
+ const tx = await this.withdrawTx(vault, new anchor.BN(amount), txOptions);
19922
20783
  return await this.base.sendAndConfirm(tx);
19923
20784
  }
19924
20785
  async findAndParseKaminoVaults() {
@@ -19962,9 +20823,10 @@ class KaminoVaultsClient {
19962
20823
  this.shareMintToVaultPdaMap.set(vaultState.sharesMint.toBase58(), vault);
19963
20824
  return vaultState;
19964
20825
  }
19965
- async composeRemainingAccounts(allocationStrategies) {
19966
- // For each allocation get reserve and market pubkeys
19967
- const reserves = allocationStrategies.map((strategy)=>strategy.reserve);
20826
+ async composeRemainingAccounts(allocationStrategies, pricingMode = false) {
20827
+ // Iterate over allocation strategies and get reserve pubkeys, using a Set to avoid dupes
20828
+ const reservesSet = new Set(allocationStrategies.map((strategy)=>strategy.reserve.toBase58()));
20829
+ const reserves = Array.from(reservesSet).map((p)=>new web3_js.PublicKey(p));
19968
20830
  const parsedReserves = await this.kaminoLending.fetchAndParseReserves(reserves);
19969
20831
  const reserveMetas = reserves.map((pubkey)=>({
19970
20832
  pubkey,
@@ -19976,15 +20838,21 @@ class KaminoVaultsClient {
19976
20838
  isSigner: false,
19977
20839
  isWritable: false
19978
20840
  }));
20841
+ if (pricingMode) {
20842
+ // (market, reserve) must be paired
20843
+ return marketMetas.reduce((acc, marketMeta, i)=>{
20844
+ acc.push(marketMeta, reserveMetas[i]);
20845
+ return acc;
20846
+ }, []);
20847
+ }
19979
20848
  return [
19980
20849
  ...reserveMetas,
19981
20850
  ...marketMetas
19982
- ];
20851
+ ]; // Non pricing mode
19983
20852
  }
19984
20853
  async depositTx(vault, amount, txOptions = {}) {
19985
20854
  const glamSigner = txOptions.signer || this.base.getSigner();
19986
20855
  const vaultState = await this.fetchAndParseVaultState(vault);
19987
- const amountBN = new anchor.BN(amount * 10 ** vaultState.tokenMintDecimals.toNumber());
19988
20856
  const { tokenProgram: sharesTokenProgram } = await this.base.fetchMintAndTokenProgram(vaultState.sharesMint);
19989
20857
  const userTokenAta = this.base.getVaultAta(vaultState.tokenMint, vaultState.tokenProgram);
19990
20858
  const userSharesAta = this.base.getVaultAta(vaultState.sharesMint, sharesTokenProgram);
@@ -19994,7 +20862,7 @@ class KaminoVaultsClient {
19994
20862
  ];
19995
20863
  // Remaining accounts, skip empty allocation strategies
19996
20864
  const remainingAccounts = await this.composeRemainingAccounts(vaultState.vaultAllocationStrategy.filter(({ reserve })=>!reserve.equals(web3_js.PublicKey.default)));
19997
- const tx = await this.base.program.methods.kaminoVaultsDeposit(amountBN).accounts({
20865
+ const tx = await this.base.program.methods.kaminoVaultsDeposit(amount).accounts({
19998
20866
  glamState: this.base.statePda,
19999
20867
  glamSigner,
20000
20868
  vaultState: vault,
@@ -20019,7 +20887,6 @@ class KaminoVaultsClient {
20019
20887
  const userTokenAta = this.base.getVaultAta(vaultState.tokenMint, vaultState.tokenProgram);
20020
20888
  const { tokenProgram: sharesTokenProgram } = await this.base.fetchMintAndTokenProgram(vaultState.sharesMint);
20021
20889
  const userSharesAta = this.base.getVaultAta(vaultState.sharesMint, sharesTokenProgram);
20022
- const amountBN = new anchor.BN(amount * 10 ** vaultState.sharesMintDecimals.toNumber());
20023
20890
  const reserves = vaultState.vaultAllocationStrategy.filter(({ reserve })=>!reserve.equals(web3_js.PublicKey.default));
20024
20891
  // Withdraw from the first reserve when kvault does not have enough liquidity
20025
20892
  const idx = 0;
@@ -20029,7 +20896,7 @@ class KaminoVaultsClient {
20029
20896
  const preInstructions = [
20030
20897
  splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, userTokenAta, this.base.vaultPda, vaultState.tokenMint, vaultState.tokenProgram)
20031
20898
  ];
20032
- const tx = await this.base.program.methods.kaminoVaultsWithdraw(amountBN).accounts({
20899
+ const tx = await this.base.program.methods.kaminoVaultsWithdraw(amount).accounts({
20033
20900
  glamState: this.base.statePda,
20034
20901
  glamSigner,
20035
20902
  withdrawFromAvailableVaultState: vault,
@@ -20300,7 +21167,7 @@ class MeteoraDlmmClient {
20300
21167
  }
20301
21168
  }
20302
21169
 
20303
- class InvestorClient {
21170
+ class InvestClient {
20304
21171
  async subscribe(asset, amount, mintId = 0, queued = false, txOptions = {}) {
20305
21172
  const tx = await (queued ? this.queuedSubscribeTx(asset, amount, mintId, txOptions) : this.subscribeTx(asset, amount, mintId, txOptions));
20306
21173
  return await this.base.sendAndConfirm(tx);
@@ -20333,26 +21200,22 @@ class InvestorClient {
20333
21200
  const glamMint = this.base.mintPda;
20334
21201
  const mintTo = this.base.getMintAta(signer);
20335
21202
  // asset token to transfer to vault
20336
- const vault = this.base.vaultPda;
20337
- const vaultInput = this.base.getAta(asset, vault);
20338
- const signerInput = this.base.getAta(asset, signer);
21203
+ const signerAta = this.base.getAta(asset, signer);
20339
21204
  const wrapSolIxs = asset.equals(WSOL) ? [
20340
- splToken.createAssociatedTokenAccountIdempotentInstruction(signer, signerInput, signer, asset),
21205
+ splToken.createAssociatedTokenAccountIdempotentInstruction(signer, signerAta, signer, asset),
20341
21206
  web3_js.SystemProgram.transfer({
20342
21207
  fromPubkey: signer,
20343
- toPubkey: signerInput,
21208
+ toPubkey: signerAta,
20344
21209
  lamports: amount.toNumber()
20345
21210
  }),
20346
- splToken.createSyncNativeInstruction(signerInput)
21211
+ splToken.createSyncNativeInstruction(signerAta)
20347
21212
  ] : [];
20348
- let preInstructions = [
20349
- splToken.createAssociatedTokenAccountIdempotentInstruction(signer, vaultInput, vault, asset),
20350
- splToken.createAssociatedTokenAccountIdempotentInstruction(signer, mintTo, signer, glamMint, splToken.TOKEN_2022_PROGRAM_ID),
21213
+ const preInstructions = [
20351
21214
  ...wrapSolIxs,
20352
21215
  ...txOptions.preInstructions || []
20353
21216
  ];
20354
21217
  const postInstructions = asset.equals(WSOL) ? [
20355
- splToken.createCloseAccountInstruction(signerInput, signer, signer)
21218
+ splToken.createCloseAccountInstruction(signerAta, signer, signer)
20356
21219
  ] : [];
20357
21220
  // Check if lockup is enabled on the fund, if so, add signerPolicy
20358
21221
  let signerPolicy = null;
@@ -20366,7 +21229,8 @@ class InvestorClient {
20366
21229
  glamMint,
20367
21230
  signer,
20368
21231
  depositAsset: asset,
20369
- signerPolicy
21232
+ signerPolicy,
21233
+ depositTokenProgram: splToken.TOKEN_PROGRAM_ID
20370
21234
  }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
20371
21235
  return await this.base.intoVersionedTransaction(tx, txOptions);
20372
21236
  }
@@ -20376,8 +21240,6 @@ class InvestorClient {
20376
21240
  }
20377
21241
  const signer = txOptions.signer || this.base.getSigner();
20378
21242
  // asset token to transfer to escrow
20379
- const escrow = this.base.escrowPda;
20380
- const escrowAta = this.base.getAta(asset, escrow);
20381
21243
  const signerAta = this.base.getAta(asset, signer);
20382
21244
  const wrapSolIxs = asset.equals(WSOL) ? [
20383
21245
  splToken.createAssociatedTokenAccountIdempotentInstruction(signer, signerAta, signer, asset),
@@ -20388,19 +21250,18 @@ class InvestorClient {
20388
21250
  }),
20389
21251
  splToken.createSyncNativeInstruction(signerAta)
20390
21252
  ] : [];
20391
- let preInstructions = [
20392
- splToken.createAssociatedTokenAccountIdempotentInstruction(signer, escrowAta, escrow, asset),
21253
+ const preInstructions = [
20393
21254
  ...wrapSolIxs,
20394
21255
  ...txOptions.preInstructions || []
20395
21256
  ];
20396
21257
  const postInstructions = asset.equals(WSOL) ? [
20397
21258
  splToken.createCloseAccountInstruction(signerAta, signer, signer)
20398
21259
  ] : [];
20399
- // @ts-ignore
20400
21260
  const tx = await this.base.program.methods.queuedSubscribe(0, amount).accounts({
20401
21261
  glamState: this.base.statePda,
20402
21262
  signer,
20403
- depositAsset: asset
21263
+ depositAsset: asset,
21264
+ depositTokenProgram: splToken.TOKEN_PROGRAM_ID
20404
21265
  }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
20405
21266
  return await this.base.intoVersionedTransaction(tx, txOptions);
20406
21267
  }
@@ -20410,9 +21271,6 @@ class InvestorClient {
20410
21271
  }
20411
21272
  const signer = txOptions.signer || this.base.getSigner();
20412
21273
  const glamMint = this.base.mintPda;
20413
- const preInstructions = [
20414
- splToken.createAssociatedTokenAccountIdempotentInstruction(signer, this.base.getMintAta(signer), signer, glamMint, splToken.TOKEN_2022_PROGRAM_ID)
20415
- ];
20416
21274
  const remainingAccounts = [];
20417
21275
  if (await this.base.isLockupEnabled()) {
20418
21276
  const extraMetasAccount = this.base.extraMetasPda;
@@ -20430,7 +21288,7 @@ class InvestorClient {
20430
21288
  glamState: this.base.statePda,
20431
21289
  glamMint,
20432
21290
  signer
20433
- }).preInstructions(preInstructions).remainingAccounts(remainingAccounts.map((pubkey)=>({
21291
+ }).remainingAccounts(remainingAccounts.map((pubkey)=>({
20434
21292
  pubkey,
20435
21293
  isSigner: false,
20436
21294
  isWritable: false
@@ -20444,24 +21302,14 @@ class InvestorClient {
20444
21302
  const signer = txOptions.signer || this.base.getSigner();
20445
21303
  const stateModel = await this.base.fetchStateModel();
20446
21304
  const baseAsset = stateModel.baseAsset;
20447
- const vault = this.base.vaultPda;
20448
- const vaultAssetAta = this.base.getAta(baseAsset, vault);
20449
21305
  const glamMint = this.base.mintPda;
20450
- const escrow = this.base.escrowPda;
20451
- const escrowMintAta = this.base.getMintAta(escrow);
20452
- const escrowAssetAta = this.base.getAta(baseAsset, escrow);
20453
- let preInstructions = [
20454
- splToken.createAssociatedTokenAccountIdempotentInstruction(signer, escrowMintAta, escrow, glamMint, splToken.TOKEN_2022_PROGRAM_ID),
20455
- splToken.createAssociatedTokenAccountIdempotentInstruction(signer, escrowAssetAta, escrow, baseAsset),
20456
- splToken.createAssociatedTokenAccountIdempotentInstruction(signer, vaultAssetAta, vault, baseAsset),
20457
- ...txOptions.preInstructions || []
20458
- ];
20459
21306
  const tx = await this.base.program.methods.fulfill(mintId).accounts({
20460
21307
  glamState: this.base.statePda,
20461
21308
  glamMint,
20462
21309
  signer,
20463
- asset: baseAsset
20464
- }).preInstructions(preInstructions).transaction();
21310
+ asset: baseAsset,
21311
+ depositTokenProgram: splToken.TOKEN_PROGRAM_ID
21312
+ }).preInstructions(txOptions.preInstructions || []).transaction();
20465
21313
  return await this.base.intoVersionedTransaction(tx, txOptions);
20466
21314
  }
20467
21315
  async claimAssetTx(asset, mintId = 0, txOptions = {}) {
@@ -20469,7 +21317,6 @@ class InvestorClient {
20469
21317
  throw new Error("mintId must be 0");
20470
21318
  }
20471
21319
  const signer = txOptions.signer || this.base.getSigner();
20472
- this.base.mintPda;
20473
21320
  const signerAta = this.base.getAta(asset, signer);
20474
21321
  // Close wSOL ata so user gets SOL
20475
21322
  const postInstructions = asset.equals(WSOL) ? [
@@ -20479,7 +21326,7 @@ class InvestorClient {
20479
21326
  glamState: this.base.statePda,
20480
21327
  signer,
20481
21328
  tokenMint: asset,
20482
- tokenProgram: splToken.TOKEN_PROGRAM_ID
21329
+ claimTokenProgram: splToken.TOKEN_PROGRAM_ID
20483
21330
  }).preInstructions([
20484
21331
  splToken.createAssociatedTokenAccountIdempotentInstruction(signer, signerAta, signer, asset)
20485
21332
  ]).postInstructions(postInstructions).transaction();
@@ -20490,8 +21337,6 @@ class InvestorClient {
20490
21337
  throw new Error("mintId must be 0");
20491
21338
  }
20492
21339
  const signer = txOptions.signer || this.base.getSigner();
20493
- this.base.mintPda;
20494
- const signerAta = this.base.getAta(asset, signer, splToken.TOKEN_2022_PROGRAM_ID);
20495
21340
  const escrow = this.base.escrowPda;
20496
21341
  const remainingAccounts = [];
20497
21342
  if (await this.base.isLockupEnabled()) {
@@ -20509,10 +21354,8 @@ class InvestorClient {
20509
21354
  glamState: this.base.statePda,
20510
21355
  signer,
20511
21356
  tokenMint: asset,
20512
- tokenProgram: splToken.TOKEN_2022_PROGRAM_ID
20513
- }).preInstructions([
20514
- splToken.createAssociatedTokenAccountIdempotentInstruction(signer, signerAta, signer, asset, splToken.TOKEN_2022_PROGRAM_ID)
20515
- ]).remainingAccounts(remainingAccounts.map((pubkey)=>({
21357
+ claimTokenProgram: splToken.TOKEN_2022_PROGRAM_ID
21358
+ }).remainingAccounts(remainingAccounts.map((pubkey)=>({
20516
21359
  pubkey,
20517
21360
  isSigner: false,
20518
21361
  isWritable: false
@@ -20554,6 +21397,7 @@ class PriceClient {
20554
21397
  isSigner: false,
20555
21398
  isWritable: true
20556
21399
  }));
21400
+ // @ts-ignore
20557
21401
  const priceIx = await this.base.program.methods.priceKaminoObligations(priceDenom).accounts({
20558
21402
  glamState: this.base.statePda,
20559
21403
  solOracle: SOL_ORACLE,
@@ -20573,28 +21417,40 @@ class PriceClient {
20573
21417
  const shareAtas = [];
20574
21418
  const shareMints = [];
20575
21419
  const kvaultStates = [];
21420
+ const oracles = []; // oracle of kvault deposit token
20576
21421
  possibleShareAtaAccountsInfo.forEach((info, i)=>{
20577
21422
  if (info !== null) {
20578
21423
  shareAtas.push(possibleShareAtas[i]);
20579
21424
  shareMints.push(allKvaultMints[i]);
20580
21425
  kvaultStates.push(allKvaultStates[i]);
21426
+ const { tokenMint } = allKvaultStates[i];
21427
+ const assetMeta = ASSETS_MAINNET.get(tokenMint.toBase58());
21428
+ oracles.push(assetMeta?.oracle);
20581
21429
  }
20582
21430
  });
20583
21431
  const kvaultPdas = await this.kvaults.getVaultPdasByShareMints(shareMints);
20584
- const remainingAccounts = (await Promise.all(kvaultStates.map((kvault)=>{
20585
- return this.kvaults.composeRemainingAccounts(kvault.vaultAllocationStrategy.filter((alloc)=>!alloc.reserve.equals(web3_js.PublicKey.default)));
20586
- }))).flat();
20587
- [
20588
- ...kvaultPdas,
20589
- ...shareAtas
20590
- ].map((pubkey)=>{
20591
- remainingAccounts.unshift({
20592
- pubkey: pubkey,
20593
- isSigner: false,
20594
- isWritable: false
21432
+ const remainingAccounts = [];
21433
+ // first 3N remaining accounts are N tuples of (kvault_shares_ata, kvault_shares_mint, kvault_state)
21434
+ for(let i = 0; i < shareAtas.length; i++){
21435
+ [
21436
+ shareAtas[i],
21437
+ shareMints[i],
21438
+ kvaultPdas[i],
21439
+ oracles[i]
21440
+ ].map((pubkey)=>{
21441
+ remainingAccounts.push({
21442
+ pubkey,
21443
+ isSigner: false,
21444
+ isWritable: false
21445
+ });
20595
21446
  });
20596
- });
20597
- const priceIx = await this.base.program.methods.priceKaminoVaultShares(priceDenom).accounts({
21447
+ }
21448
+ // markets and reserves
21449
+ const marketsAndReserves = (await Promise.all(kvaultStates.map((kvault)=>{
21450
+ return this.kvaults.composeRemainingAccounts(kvault.vaultAllocationStrategy.filter((alloc)=>!alloc.reserve.equals(web3_js.PublicKey.default)), true);
21451
+ }))).flat();
21452
+ remainingAccounts.push(...marketsAndReserves);
21453
+ const priceIx = await this.base.program.methods.priceKaminoVaultShares(priceDenom, shareAtas.length).accounts({
20598
21454
  glamState: this.base.statePda,
20599
21455
  solOracle: SOL_ORACLE,
20600
21456
  pythOracle: null,
@@ -20605,33 +21461,62 @@ class PriceClient {
20605
21461
  return priceIx;
20606
21462
  }
20607
21463
  /**
20608
- * Returns an instruction that prices the all Drift users (aka sub-accounts) controlled by the GLAM vault.
20609
- * These Drift users must share the same user_stats that's also controlled by the GLAM vault.
21464
+ * Returns an instruction that prices all Drift users (aka sub-accounts) controlled by the GLAM vault.
20610
21465
  */ async priceDriftUsersIx(priceDenom) {
20611
- // FIXME: check more users than #0
20612
- const { user, userStats } = this.drift.getDriftUserPdas();
20613
- try {
20614
- const remainingAccounts = await this.drift.composeRemainingAccounts(0);
20615
- const priceDriftUsersIx = await this.base.program.methods.priceDriftUsers(priceDenom).accounts({
20616
- glamState: this.base.statePda,
20617
- solOracle: SOL_ORACLE
20618
- }).remainingAccounts([
20619
- {
20620
- pubkey: userStats,
20621
- isSigner: false,
20622
- isWritable: false
20623
- },
20624
- {
20625
- pubkey: user,
21466
+ // 1st remaining account is user_stats
21467
+ const { userStats } = this.drift.getDriftUserPdas();
21468
+ const remainingAccounts = [
21469
+ {
21470
+ pubkey: userStats,
21471
+ isSigner: false,
21472
+ isWritable: false
21473
+ }
21474
+ ];
21475
+ // Fetch first 8 sub accounts
21476
+ const userPdas = Array.from(Array(8).keys()).map((subAccountId)=>{
21477
+ const { user } = this.drift.getDriftUserPdas(subAccountId);
21478
+ return user;
21479
+ });
21480
+ const accountsInfo = await this.base.provider.connection.getMultipleAccountsInfo(userPdas);
21481
+ // Parse valid sub accounts
21482
+ const driftUsers = [];
21483
+ for(let i = 0; i < accountsInfo.length; i++){
21484
+ const accountInfo = accountsInfo[i];
21485
+ if (accountInfo) {
21486
+ const user = await this.drift.parseDriftUser(accountInfo, i);
21487
+ driftUsers.push(user);
21488
+ remainingAccounts.push({
21489
+ pubkey: userPdas[i],
20626
21490
  isSigner: false,
20627
21491
  isWritable: false
20628
- },
20629
- ...remainingAccounts
20630
- ]).instruction();
20631
- return priceDriftUsersIx;
20632
- } catch (error) {
20633
- return null;
21492
+ });
21493
+ }
20634
21494
  }
21495
+ // Build a set of markets and oracles that are used by all sub accounts
21496
+ const marketsAndOracles = new Set();
21497
+ const spotMarketIndexes = new Set(driftUsers.map((u)=>u.spotPositions.map((p)=>p.marketIndex)).flat());
21498
+ const perpMarketIndexes = new Set(driftUsers.map((u)=>u.perpPositions.map((p)=>p.marketIndex)).flat());
21499
+ const spotMarkets = await this.drift.fetchAndParseSpotMarkets(Array.from(spotMarketIndexes));
21500
+ const perpMarkets = await this.drift.fetchAndParsePerpMarkets(Array.from(perpMarketIndexes));
21501
+ spotMarkets.forEach((m)=>{
21502
+ marketsAndOracles.add(m.oracle.toBase58());
21503
+ marketsAndOracles.add(m.marketPda.toBase58());
21504
+ });
21505
+ perpMarkets.forEach((m)=>{
21506
+ marketsAndOracles.add(m.oracle.toBase58());
21507
+ marketsAndOracles.add(m.marketPda.toBase58());
21508
+ });
21509
+ // Add markets and oracles to remaining accounts
21510
+ Array.from(marketsAndOracles).map((pubkey)=>remainingAccounts.push({
21511
+ pubkey: new web3_js.PublicKey(pubkey),
21512
+ isSigner: false,
21513
+ isWritable: false
21514
+ }));
21515
+ const priceDriftUsersIx = await this.base.program.methods.priceDriftUsers(priceDenom, driftUsers.length).accounts({
21516
+ glamState: this.base.statePda,
21517
+ solOracle: SOL_ORACLE
21518
+ }).remainingAccounts(remainingAccounts).instruction();
21519
+ return priceDriftUsersIx;
20635
21520
  }
20636
21521
  /**
20637
21522
  * Returns an instruction that prices a drift vault depositor.
@@ -20648,23 +21533,36 @@ class PriceClient {
20648
21533
  // - oracles
20649
21534
  // - spot & perp markets
20650
21535
  // There might be overlaps between markets and oracles so we use a set to avoid duplicates
20651
- const remainingAccountsKeys = new Set();
21536
+ const remainingAccounts = [];
21537
+ const marketsAndOracles = new Set();
20652
21538
  for (const depositor of parsedVaultDepositors){
20653
- remainingAccountsKeys.add(depositor.address.toBase58());
20654
- remainingAccountsKeys.add(depositor.driftVault.toBase58());
20655
21539
  const { user: driftUser } = await this.dvaults.parseDriftVault(depositor.driftVault);
20656
- remainingAccountsKeys.add(driftUser.toBase58());
21540
+ remainingAccounts.push({
21541
+ pubkey: depositor.address,
21542
+ isSigner: false,
21543
+ isWritable: false
21544
+ });
21545
+ remainingAccounts.push({
21546
+ pubkey: depositor.driftVault,
21547
+ isSigner: false,
21548
+ isWritable: false
21549
+ });
21550
+ remainingAccounts.push({
21551
+ pubkey: driftUser,
21552
+ isSigner: false,
21553
+ isWritable: false
21554
+ });
20657
21555
  const markets_and_oracles = (await this.dvaults.composeRemainingAccounts(driftUser)).map((a)=>a.pubkey.toBase58());
20658
21556
  for (const k of markets_and_oracles){
20659
- remainingAccountsKeys.add(k);
21557
+ marketsAndOracles.add(k);
20660
21558
  }
20661
21559
  }
20662
- const remainingAccounts = Array.from(remainingAccountsKeys).map((k)=>({
21560
+ Array.from(marketsAndOracles).forEach((k)=>remainingAccounts.push({
20663
21561
  pubkey: new web3_js.PublicKey(k),
20664
21562
  isSigner: false,
20665
21563
  isWritable: false
20666
21564
  }));
20667
- const priceIx = await this.base.program.methods.priceDriftVaultDepositors(priceDenom).accounts({
21565
+ const priceIx = await this.base.program.methods.priceDriftVaultDepositors(priceDenom, parsedVaultDepositors.length).accounts({
20668
21566
  glamState: this.base.statePda,
20669
21567
  solOracle: SOL_ORACLE
20670
21568
  }).remainingAccounts(remainingAccounts).instruction();
@@ -20674,7 +21572,7 @@ class PriceClient {
20674
21572
  * Returns an instruction that prices vault balance and tokens the vault holds
20675
21573
  */ async priceVaultIx(priceDenom) {
20676
21574
  const remainingAccounts = await this.remainingAccountsForPricingVaultAssets(priceDenom == PriceDenom.ASSET);
20677
- const priceVaultIx = await this.base.program.methods.priceVault(priceDenom).accounts({
21575
+ const priceVaultIx = await this.base.program.methods.priceVaultTokens(priceDenom).accounts({
20678
21576
  glamState: this.base.statePda,
20679
21577
  solOracle: SOL_ORACLE
20680
21578
  }).remainingAccounts(remainingAccounts).instruction();
@@ -20729,19 +21627,24 @@ class PriceClient {
20729
21627
  priceVaultIx
20730
21628
  ];
20731
21629
  }
20732
- const priceStakesIx = await this.priceStakesIx(priceDenom);
20733
- const priceMeteoraIx = await this.priceMeteoraPositionsIx(priceDenom);
20734
- const priceKaminoIx = await this.priceKaminoObligationsIx(priceDenom);
20735
- const priceDriftUsersIx = await this.priceDriftUsersIx(priceDenom);
20736
- const priceDriftVaultDepositorsIx = await this.priceDriftVaultDepositorsIx(priceDenom);
20737
- return [
20738
- priceVaultIx,
20739
- priceStakesIx,
20740
- priceMeteoraIx,
20741
- priceKaminoIx,
20742
- priceDriftUsersIx,
20743
- priceDriftVaultDepositorsIx
20744
- ].filter((ix)=>ix !== null);
21630
+ const integrations = (stateModel.integrations || []).map((i)=>Object.keys(i)[0]);
21631
+ const integrationsToPricingFns = {
21632
+ drift: this.priceDriftUsersIx.bind(this),
21633
+ kaminoLending: this.priceKaminoObligationsIx.bind(this),
21634
+ nativeStaking: this.priceStakesIx.bind(this),
21635
+ meteoraDlmm: this.priceMeteoraPositionsIx.bind(this),
21636
+ driftVaults: this.priceDriftVaultDepositorsIx.bind(this),
21637
+ kaminoVaults: this.priceKaminoVaultSharesIx.bind(this)
21638
+ };
21639
+ const pricingFns = integrations.map((integration)=>integrationsToPricingFns[integration]).filter(Boolean);
21640
+ const pricingIxs = [
21641
+ priceVaultIx
21642
+ ];
21643
+ for (const fn of pricingFns){
21644
+ const ix = await fn(priceDenom);
21645
+ pricingIxs.push(ix);
21646
+ }
21647
+ return pricingIxs.filter(Boolean);
20745
21648
  }
20746
21649
  constructor(base, klend, kvaults, drift, dvaults){
20747
21650
  this.base = base;
@@ -20808,6 +21711,116 @@ class PriceClient {
20808
21711
  }
20809
21712
  }
20810
21713
 
21714
+ class ValidatorClient {
21715
+ /**
21716
+ * Authorize a new authority for the vote account.
21717
+ */ async voteAuthorize(vote, newAuthority, voteAuthorize, txOptions = {}) {
21718
+ const glamSigner = txOptions.signer || this.base.getSigner();
21719
+ // @ts-ignore
21720
+ const tx = await this.base.program.methods.voteAuthorize(newAuthority, voteAuthorize).accounts({
21721
+ glamState: this.base.statePda,
21722
+ glamSigner,
21723
+ vote
21724
+ }).transaction();
21725
+ return await this.base.sendAndConfirm(await this.base.intoVersionedTransaction(tx, txOptions));
21726
+ }
21727
+ /**
21728
+ * Update the validator identity for the vote account.
21729
+ */ async voteUpdateValidatorIdentity(vote, identity, txOptions = {}) {
21730
+ const glamSigner = txOptions.signer || this.base.getSigner();
21731
+ const tx = await this.base.program.methods.voteUpdateValidatorIdentity().accounts({
21732
+ glamState: this.base.statePda,
21733
+ glamSigner,
21734
+ vote,
21735
+ identity: identity.publicKey
21736
+ }).transaction();
21737
+ return await this.base.sendAndConfirm(await this.base.intoVersionedTransaction(tx, txOptions), [
21738
+ identity
21739
+ ]);
21740
+ }
21741
+ /**
21742
+ * Update the commission for the vote account.
21743
+ */ async voteUpdateCommission(vote, newCommission, txOptions = {}) {
21744
+ const glamSigner = txOptions.signer || this.base.getSigner();
21745
+ const tx = await this.base.program.methods.voteUpdateCommission(newCommission).accounts({
21746
+ glamState: this.base.statePda,
21747
+ glamSigner,
21748
+ vote
21749
+ }).transaction();
21750
+ return await this.base.sendAndConfirm(await this.base.intoVersionedTransaction(tx, txOptions));
21751
+ }
21752
+ /**
21753
+ * Withdraw lamports from the vote account to a recipient.
21754
+ */ async voteWithdraw(vote, recipient, lamports, txOptions = {}) {
21755
+ const glamSigner = txOptions.signer || this.base.getSigner();
21756
+ const tx = await this.base.program.methods.voteWithdraw(new anchor.BN(lamports)).accounts({
21757
+ glamState: this.base.statePda,
21758
+ glamSigner,
21759
+ vote,
21760
+ recipient
21761
+ }).transaction();
21762
+ return await this.base.sendAndConfirm(await this.base.intoVersionedTransaction(tx, txOptions));
21763
+ }
21764
+ constructor(base){
21765
+ this.base = base;
21766
+ }
21767
+ }
21768
+
21769
+ class FeesClient {
21770
+ async crystallizeFees(txOptions = {}) {
21771
+ const stateModel = await this.base.fetchStateModel();
21772
+ const { baseAsset } = stateModel;
21773
+ if (!baseAsset) {
21774
+ throw new Error("Base asset not found");
21775
+ }
21776
+ const priceVaultIxs = await this.price.priceVaultIxs(PriceDenom.fromAsset(baseAsset));
21777
+ const tx = await this.base.program.methods.crystallizeFees(0).accounts({
21778
+ glamState: this.base.statePda,
21779
+ glamMint: this.base.mintPda
21780
+ }).preInstructions(priceVaultIxs).transaction();
21781
+ const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
21782
+ return await this.base.sendAndConfirm(vTx);
21783
+ }
21784
+ async disburseFees(txOptions = {}) {
21785
+ const signer = txOptions.signer || this.base.getSigner();
21786
+ const stateModel = await this.base.fetchStateModel();
21787
+ const { baseAsset } = stateModel;
21788
+ if (!baseAsset) {
21789
+ throw new Error("Base asset not found");
21790
+ }
21791
+ // TODO: parse from glam config account
21792
+ const protocolFeeAuthority = new web3_js.PublicKey("gLJHKPrZLGBiBZ33hFgZh6YnsEhTVxuRT17UCqNp6ff");
21793
+ const managerFeeAuthority = stateModel?.owner?.pubkey;
21794
+ if (!managerFeeAuthority) {
21795
+ throw new Error("Manager fee authority not found");
21796
+ }
21797
+ const { tokenProgram } = await this.base.fetchMintAndTokenProgram(baseAsset);
21798
+ const protocolFeeAuthorityAta = this.base.getAta(baseAsset, protocolFeeAuthority, tokenProgram);
21799
+ const managerFeeAuthorityAta = this.base.getAta(baseAsset, managerFeeAuthority, tokenProgram);
21800
+ const priceVaultIxs = await this.price.priceVaultIxs(PriceDenom.fromAsset(baseAsset));
21801
+ const preInstructions = [
21802
+ splToken.createAssociatedTokenAccountIdempotentInstruction(signer, protocolFeeAuthorityAta, protocolFeeAuthority, baseAsset, tokenProgram),
21803
+ splToken.createAssociatedTokenAccountIdempotentInstruction(signer, managerFeeAuthorityAta, managerFeeAuthority, baseAsset, tokenProgram),
21804
+ ...priceVaultIxs
21805
+ ];
21806
+ const tx = await this.base.program.methods.disburseFees(0).accounts({
21807
+ glamState: this.base.statePda,
21808
+ glamMint: this.base.mintPda,
21809
+ // @ts-ignore
21810
+ protocolFeeAuthorityAta,
21811
+ managerFeeAuthorityAta,
21812
+ depositAsset: baseAsset,
21813
+ depositTokenProgram: tokenProgram
21814
+ }).preInstructions(preInstructions).transaction();
21815
+ const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
21816
+ return await this.base.sendAndConfirm(vTx);
21817
+ }
21818
+ constructor(base, price){
21819
+ this.base = base;
21820
+ this.price = price;
21821
+ }
21822
+ }
21823
+
20811
21824
  /**
20812
21825
  * Main entrypoint for the GLAM SDK
20813
21826
  *
@@ -20825,11 +21838,17 @@ class PriceClient {
20825
21838
  }
20826
21839
  return this._driftVaults;
20827
21840
  }
20828
- get investor() {
20829
- if (!this._investor) {
20830
- this._investor = new InvestorClient(this);
21841
+ get invest() {
21842
+ if (!this._invest) {
21843
+ this._invest = new InvestClient(this);
20831
21844
  }
20832
- return this._investor;
21845
+ return this._invest;
21846
+ }
21847
+ get fees() {
21848
+ if (!this._fees) {
21849
+ this._fees = new FeesClient(this, this.price);
21850
+ }
21851
+ return this._fees;
20833
21852
  }
20834
21853
  get jupiterSwap() {
20835
21854
  if (!this._jupiterSwap) {
@@ -20903,6 +21922,12 @@ class PriceClient {
20903
21922
  }
20904
21923
  return this._meteoraDlmm;
20905
21924
  }
21925
+ get validator() {
21926
+ if (!this._validator) {
21927
+ this._validator = new ValidatorClient(this);
21928
+ }
21929
+ return this._validator;
21930
+ }
20906
21931
  constructor(config){
20907
21932
  super(config);
20908
21933
  }
@@ -20979,6 +22004,7 @@ function getMarketOrderParams(params) {
20979
22004
  return Object.assign({}, DefaultOrderParams, optionalOrderParams, overridingParams);
20980
22005
  }
20981
22006
 
22007
+ exports.ALT_PROGRAM_ID = ALT_PROGRAM_ID;
20982
22008
  exports.ASSETS_MAINNET = ASSETS_MAINNET;
20983
22009
  exports.ASSETS_TESTS = ASSETS_TESTS;
20984
22010
  exports.AssetTier = AssetTier;
@@ -21082,11 +22108,14 @@ exports.TradeSide = TradeSide;
21082
22108
  exports.USDC = USDC;
21083
22109
  exports.USDC_ORACLE = USDC_ORACLE;
21084
22110
  exports.UserStatus = UserStatus;
22111
+ exports.VoteAuthorize = VoteAuthorize;
21085
22112
  exports.WSOL = WSOL;
21086
22113
  exports.ZERO = ZERO;
21087
22114
  exports.decodeUser = decodeUser;
21088
- exports.fetchLookupTables = fetchLookupTables;
21089
22115
  exports.fetchMeteoraPositions = fetchMeteoraPositions;
22116
+ exports.fetchProgramLabels = fetchProgramLabels;
22117
+ exports.fetchTokenPrices = fetchTokenPrices;
22118
+ exports.fetchTokensList = fetchTokensList;
21090
22119
  exports.findStakeAccounts = findStakeAccounts;
21091
22120
  exports.getAccountPolicyPda = getAccountPolicyPda;
21092
22121
  exports.getEscrowPda = getEscrowPda;
@@ -21099,7 +22128,7 @@ exports.getMintPda = getMintPda;
21099
22128
  exports.getOpenfundsPda = getOpenfundsPda;
21100
22129
  exports.getOrderParams = getOrderParams;
21101
22130
  exports.getPriorityFeeEstimate = getPriorityFeeEstimate;
21102
- exports.getSimulationComputeUnits = getSimulationComputeUnits;
22131
+ exports.getSimulationResult = getSimulationResult;
21103
22132
  exports.getStakeAccountsWithStates = getStakeAccountsWithStates;
21104
22133
  exports.getStatePda = getStatePda;
21105
22134
  exports.getTriggerLimitOrderParams = getTriggerLimitOrderParams;