@glamsystems/glam-sdk 1.0.3-alpha.6 → 1.0.3

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
@@ -778,6 +778,535 @@ var instructions$8 = [
778
778
  }
779
779
  ]
780
780
  },
781
+ {
782
+ name: "stake_authorize",
783
+ discriminator: [
784
+ 127,
785
+ 247,
786
+ 88,
787
+ 164,
788
+ 201,
789
+ 0,
790
+ 79,
791
+ 7
792
+ ],
793
+ accounts: [
794
+ {
795
+ name: "glam_state",
796
+ writable: true
797
+ },
798
+ {
799
+ name: "glam_vault",
800
+ writable: true,
801
+ pda: {
802
+ seeds: [
803
+ {
804
+ kind: "const",
805
+ value: [
806
+ 118,
807
+ 97,
808
+ 117,
809
+ 108,
810
+ 116
811
+ ]
812
+ },
813
+ {
814
+ kind: "account",
815
+ path: "glam_state"
816
+ }
817
+ ]
818
+ }
819
+ },
820
+ {
821
+ name: "glam_signer",
822
+ writable: true,
823
+ signer: true
824
+ },
825
+ {
826
+ name: "cpi_program",
827
+ address: "Stake11111111111111111111111111111111111111"
828
+ },
829
+ {
830
+ name: "stake",
831
+ writable: true
832
+ },
833
+ {
834
+ name: "clock",
835
+ address: "SysvarC1ock11111111111111111111111111111111"
836
+ }
837
+ ],
838
+ args: [
839
+ {
840
+ name: "new_authority",
841
+ type: "pubkey"
842
+ },
843
+ {
844
+ name: "staker_or_withdrawer",
845
+ type: "u32"
846
+ }
847
+ ]
848
+ },
849
+ {
850
+ name: "stake_deactivate",
851
+ discriminator: [
852
+ 224,
853
+ 10,
854
+ 93,
855
+ 175,
856
+ 175,
857
+ 145,
858
+ 237,
859
+ 169
860
+ ],
861
+ accounts: [
862
+ {
863
+ name: "glam_state"
864
+ },
865
+ {
866
+ name: "glam_vault",
867
+ writable: true,
868
+ pda: {
869
+ seeds: [
870
+ {
871
+ kind: "const",
872
+ value: [
873
+ 118,
874
+ 97,
875
+ 117,
876
+ 108,
877
+ 116
878
+ ]
879
+ },
880
+ {
881
+ kind: "account",
882
+ path: "glam_state"
883
+ }
884
+ ]
885
+ }
886
+ },
887
+ {
888
+ name: "glam_signer",
889
+ writable: true,
890
+ signer: true
891
+ },
892
+ {
893
+ name: "cpi_program",
894
+ address: "Stake11111111111111111111111111111111111111"
895
+ },
896
+ {
897
+ name: "stake",
898
+ writable: true
899
+ },
900
+ {
901
+ name: "clock",
902
+ address: "SysvarC1ock11111111111111111111111111111111"
903
+ }
904
+ ],
905
+ args: []
906
+ },
907
+ {
908
+ name: "stake_delegate_stake",
909
+ discriminator: [
910
+ 202,
911
+ 40,
912
+ 152,
913
+ 239,
914
+ 175,
915
+ 251,
916
+ 66,
917
+ 228
918
+ ],
919
+ accounts: [
920
+ {
921
+ name: "glam_state",
922
+ writable: true
923
+ },
924
+ {
925
+ name: "glam_vault",
926
+ writable: true,
927
+ pda: {
928
+ seeds: [
929
+ {
930
+ kind: "const",
931
+ value: [
932
+ 118,
933
+ 97,
934
+ 117,
935
+ 108,
936
+ 116
937
+ ]
938
+ },
939
+ {
940
+ kind: "account",
941
+ path: "glam_state"
942
+ }
943
+ ]
944
+ }
945
+ },
946
+ {
947
+ name: "glam_signer",
948
+ writable: true,
949
+ signer: true
950
+ },
951
+ {
952
+ name: "cpi_program",
953
+ address: "Stake11111111111111111111111111111111111111"
954
+ },
955
+ {
956
+ name: "stake",
957
+ writable: true
958
+ },
959
+ {
960
+ name: "vote"
961
+ },
962
+ {
963
+ name: "clock",
964
+ address: "SysvarC1ock11111111111111111111111111111111"
965
+ },
966
+ {
967
+ name: "stake_history",
968
+ address: "SysvarStakeHistory1111111111111111111111111"
969
+ },
970
+ {
971
+ name: "stake_config"
972
+ }
973
+ ],
974
+ args: []
975
+ },
976
+ {
977
+ name: "stake_initialize",
978
+ discriminator: [
979
+ 68,
980
+ 66,
981
+ 118,
982
+ 79,
983
+ 15,
984
+ 144,
985
+ 190,
986
+ 190
987
+ ],
988
+ accounts: [
989
+ {
990
+ name: "glam_state",
991
+ writable: true
992
+ },
993
+ {
994
+ name: "glam_vault",
995
+ writable: true,
996
+ pda: {
997
+ seeds: [
998
+ {
999
+ kind: "const",
1000
+ value: [
1001
+ 118,
1002
+ 97,
1003
+ 117,
1004
+ 108,
1005
+ 116
1006
+ ]
1007
+ },
1008
+ {
1009
+ kind: "account",
1010
+ path: "glam_state"
1011
+ }
1012
+ ]
1013
+ }
1014
+ },
1015
+ {
1016
+ name: "glam_signer",
1017
+ writable: true,
1018
+ signer: true
1019
+ },
1020
+ {
1021
+ name: "cpi_program",
1022
+ address: "Stake11111111111111111111111111111111111111"
1023
+ },
1024
+ {
1025
+ name: "stake",
1026
+ writable: true
1027
+ },
1028
+ {
1029
+ name: "rent",
1030
+ address: "SysvarRent111111111111111111111111111111111"
1031
+ },
1032
+ {
1033
+ name: "system_program",
1034
+ address: "11111111111111111111111111111111"
1035
+ }
1036
+ ],
1037
+ args: []
1038
+ },
1039
+ {
1040
+ name: "stake_merge",
1041
+ discriminator: [
1042
+ 46,
1043
+ 181,
1044
+ 125,
1045
+ 12,
1046
+ 51,
1047
+ 179,
1048
+ 134,
1049
+ 176
1050
+ ],
1051
+ accounts: [
1052
+ {
1053
+ name: "glam_state",
1054
+ writable: true
1055
+ },
1056
+ {
1057
+ name: "glam_vault",
1058
+ writable: true,
1059
+ pda: {
1060
+ seeds: [
1061
+ {
1062
+ kind: "const",
1063
+ value: [
1064
+ 118,
1065
+ 97,
1066
+ 117,
1067
+ 108,
1068
+ 116
1069
+ ]
1070
+ },
1071
+ {
1072
+ kind: "account",
1073
+ path: "glam_state"
1074
+ }
1075
+ ]
1076
+ }
1077
+ },
1078
+ {
1079
+ name: "glam_signer",
1080
+ writable: true,
1081
+ signer: true
1082
+ },
1083
+ {
1084
+ name: "cpi_program",
1085
+ address: "Stake11111111111111111111111111111111111111"
1086
+ },
1087
+ {
1088
+ name: "destination_stake",
1089
+ writable: true
1090
+ },
1091
+ {
1092
+ name: "source_stake",
1093
+ writable: true
1094
+ },
1095
+ {
1096
+ name: "clock",
1097
+ address: "SysvarC1ock11111111111111111111111111111111"
1098
+ },
1099
+ {
1100
+ name: "stake_history",
1101
+ address: "SysvarStakeHistory1111111111111111111111111"
1102
+ }
1103
+ ],
1104
+ args: []
1105
+ },
1106
+ {
1107
+ name: "stake_move",
1108
+ discriminator: [
1109
+ 165,
1110
+ 157,
1111
+ 188,
1112
+ 245,
1113
+ 244,
1114
+ 234,
1115
+ 42,
1116
+ 186
1117
+ ],
1118
+ accounts: [
1119
+ {
1120
+ name: "glam_state",
1121
+ writable: true
1122
+ },
1123
+ {
1124
+ name: "glam_vault",
1125
+ writable: true,
1126
+ pda: {
1127
+ seeds: [
1128
+ {
1129
+ kind: "const",
1130
+ value: [
1131
+ 118,
1132
+ 97,
1133
+ 117,
1134
+ 108,
1135
+ 116
1136
+ ]
1137
+ },
1138
+ {
1139
+ kind: "account",
1140
+ path: "glam_state"
1141
+ }
1142
+ ]
1143
+ }
1144
+ },
1145
+ {
1146
+ name: "glam_signer",
1147
+ writable: true,
1148
+ signer: true
1149
+ },
1150
+ {
1151
+ name: "cpi_program",
1152
+ address: "Stake11111111111111111111111111111111111111"
1153
+ },
1154
+ {
1155
+ name: "source_stake",
1156
+ writable: true
1157
+ },
1158
+ {
1159
+ name: "destination_stake",
1160
+ writable: true
1161
+ }
1162
+ ],
1163
+ args: [
1164
+ {
1165
+ name: "move_stake",
1166
+ type: "bool"
1167
+ },
1168
+ {
1169
+ name: "lamports",
1170
+ type: "u64"
1171
+ }
1172
+ ]
1173
+ },
1174
+ {
1175
+ name: "stake_split",
1176
+ discriminator: [
1177
+ 63,
1178
+ 128,
1179
+ 169,
1180
+ 206,
1181
+ 158,
1182
+ 60,
1183
+ 135,
1184
+ 48
1185
+ ],
1186
+ accounts: [
1187
+ {
1188
+ name: "glam_state",
1189
+ writable: true
1190
+ },
1191
+ {
1192
+ name: "glam_vault",
1193
+ writable: true,
1194
+ pda: {
1195
+ seeds: [
1196
+ {
1197
+ kind: "const",
1198
+ value: [
1199
+ 118,
1200
+ 97,
1201
+ 117,
1202
+ 108,
1203
+ 116
1204
+ ]
1205
+ },
1206
+ {
1207
+ kind: "account",
1208
+ path: "glam_state"
1209
+ }
1210
+ ]
1211
+ }
1212
+ },
1213
+ {
1214
+ name: "glam_signer",
1215
+ writable: true,
1216
+ signer: true
1217
+ },
1218
+ {
1219
+ name: "cpi_program",
1220
+ address: "Stake11111111111111111111111111111111111111"
1221
+ },
1222
+ {
1223
+ name: "stake",
1224
+ writable: true
1225
+ },
1226
+ {
1227
+ name: "split_stake",
1228
+ writable: true
1229
+ }
1230
+ ],
1231
+ args: [
1232
+ {
1233
+ name: "lamports",
1234
+ type: "u64"
1235
+ }
1236
+ ]
1237
+ },
1238
+ {
1239
+ name: "stake_withdraw",
1240
+ discriminator: [
1241
+ 199,
1242
+ 13,
1243
+ 168,
1244
+ 20,
1245
+ 92,
1246
+ 151,
1247
+ 29,
1248
+ 56
1249
+ ],
1250
+ accounts: [
1251
+ {
1252
+ name: "glam_state",
1253
+ writable: true
1254
+ },
1255
+ {
1256
+ name: "glam_vault",
1257
+ writable: true,
1258
+ pda: {
1259
+ seeds: [
1260
+ {
1261
+ kind: "const",
1262
+ value: [
1263
+ 118,
1264
+ 97,
1265
+ 117,
1266
+ 108,
1267
+ 116
1268
+ ]
1269
+ },
1270
+ {
1271
+ kind: "account",
1272
+ path: "glam_state"
1273
+ }
1274
+ ]
1275
+ }
1276
+ },
1277
+ {
1278
+ name: "glam_signer",
1279
+ writable: true,
1280
+ signer: true
1281
+ },
1282
+ {
1283
+ name: "cpi_program",
1284
+ address: "Stake11111111111111111111111111111111111111"
1285
+ },
1286
+ {
1287
+ name: "stake",
1288
+ writable: true
1289
+ },
1290
+ {
1291
+ name: "clock",
1292
+ address: "SysvarC1ock11111111111111111111111111111111"
1293
+ },
1294
+ {
1295
+ name: "stake_history",
1296
+ address: "SysvarStakeHistory1111111111111111111111111"
1297
+ },
1298
+ {
1299
+ name: "system_program",
1300
+ address: "11111111111111111111111111111111"
1301
+ }
1302
+ ],
1303
+ args: [
1304
+ {
1305
+ name: "lamports",
1306
+ type: "u64"
1307
+ }
1308
+ ]
1309
+ },
781
1310
  {
782
1311
  name: "system_transfer",
783
1312
  discriminator: [
@@ -6076,6 +6605,229 @@ var instructions$6 = [
6076
6605
  }
6077
6606
  ]
6078
6607
  },
6608
+ {
6609
+ name: "price_stake_accounts",
6610
+ discriminator: [
6611
+ 119,
6612
+ 137,
6613
+ 9,
6614
+ 15,
6615
+ 196,
6616
+ 73,
6617
+ 30,
6618
+ 27
6619
+ ],
6620
+ accounts: [
6621
+ {
6622
+ name: "glam_state",
6623
+ writable: true
6624
+ },
6625
+ {
6626
+ name: "glam_vault",
6627
+ pda: {
6628
+ seeds: [
6629
+ {
6630
+ kind: "const",
6631
+ value: [
6632
+ 118,
6633
+ 97,
6634
+ 117,
6635
+ 108,
6636
+ 116
6637
+ ]
6638
+ },
6639
+ {
6640
+ kind: "account",
6641
+ path: "glam_state"
6642
+ }
6643
+ ],
6644
+ program: {
6645
+ kind: "const",
6646
+ value: [
6647
+ 227,
6648
+ 199,
6649
+ 235,
6650
+ 230,
6651
+ 176,
6652
+ 132,
6653
+ 243,
6654
+ 117,
6655
+ 43,
6656
+ 131,
6657
+ 173,
6658
+ 18,
6659
+ 78,
6660
+ 255,
6661
+ 26,
6662
+ 50,
6663
+ 209,
6664
+ 135,
6665
+ 86,
6666
+ 219,
6667
+ 140,
6668
+ 126,
6669
+ 61,
6670
+ 255,
6671
+ 0,
6672
+ 218,
6673
+ 252,
6674
+ 224,
6675
+ 172,
6676
+ 8,
6677
+ 223,
6678
+ 207
6679
+ ]
6680
+ }
6681
+ }
6682
+ },
6683
+ {
6684
+ name: "signer",
6685
+ writable: true,
6686
+ signer: true
6687
+ },
6688
+ {
6689
+ name: "sol_usd_oracle"
6690
+ },
6691
+ {
6692
+ name: "base_asset_oracle"
6693
+ },
6694
+ {
6695
+ name: "integration_authority",
6696
+ pda: {
6697
+ seeds: [
6698
+ {
6699
+ kind: "const",
6700
+ value: [
6701
+ 105,
6702
+ 110,
6703
+ 116,
6704
+ 101,
6705
+ 103,
6706
+ 114,
6707
+ 97,
6708
+ 116,
6709
+ 105,
6710
+ 111,
6711
+ 110,
6712
+ 45,
6713
+ 97,
6714
+ 117,
6715
+ 116,
6716
+ 104,
6717
+ 111,
6718
+ 114,
6719
+ 105,
6720
+ 116,
6721
+ 121
6722
+ ]
6723
+ }
6724
+ ]
6725
+ }
6726
+ },
6727
+ {
6728
+ name: "glam_config",
6729
+ pda: {
6730
+ seeds: [
6731
+ {
6732
+ kind: "const",
6733
+ value: [
6734
+ 103,
6735
+ 108,
6736
+ 111,
6737
+ 98,
6738
+ 97,
6739
+ 108,
6740
+ 45,
6741
+ 99,
6742
+ 111,
6743
+ 110,
6744
+ 102,
6745
+ 105,
6746
+ 103
6747
+ ]
6748
+ }
6749
+ ],
6750
+ program: {
6751
+ kind: "const",
6752
+ value: [
6753
+ 10,
6754
+ 11,
6755
+ 0,
6756
+ 83,
6757
+ 72,
6758
+ 16,
6759
+ 46,
6760
+ 144,
6761
+ 46,
6762
+ 42,
6763
+ 79,
6764
+ 22,
6765
+ 157,
6766
+ 123,
6767
+ 21,
6768
+ 242,
6769
+ 192,
6770
+ 146,
6771
+ 1,
6772
+ 78,
6773
+ 88,
6774
+ 59,
6775
+ 102,
6776
+ 9,
6777
+ 190,
6778
+ 226,
6779
+ 92,
6780
+ 189,
6781
+ 187,
6782
+ 232,
6783
+ 83,
6784
+ 220
6785
+ ]
6786
+ }
6787
+ }
6788
+ },
6789
+ {
6790
+ name: "glam_protocol",
6791
+ address: "GLAMpaME8wdTEzxtiYEAa5yD8fZbxZiz2hNtV58RZiEz"
6792
+ },
6793
+ {
6794
+ name: "event_authority",
6795
+ optional: true,
6796
+ pda: {
6797
+ seeds: [
6798
+ {
6799
+ kind: "const",
6800
+ value: [
6801
+ 95,
6802
+ 95,
6803
+ 101,
6804
+ 118,
6805
+ 101,
6806
+ 110,
6807
+ 116,
6808
+ 95,
6809
+ 97,
6810
+ 117,
6811
+ 116,
6812
+ 104,
6813
+ 111,
6814
+ 114,
6815
+ 105,
6816
+ 116,
6817
+ 121
6818
+ ]
6819
+ }
6820
+ ]
6821
+ }
6822
+ },
6823
+ {
6824
+ name: "event_program",
6825
+ optional: true,
6826
+ address: "GM1NtvvnSXUptTrMCqbogAdZJydZSNv98DoU5AZVLmGh"
6827
+ }
6828
+ ],
6829
+ args: []
6830
+ },
6079
6831
  {
6080
6832
  name: "price_vault_tokens",
6081
6833
  docs: [
@@ -19200,6 +19952,10 @@ var instructions$1 = [
19200
19952
  name: "glam_protocol_program",
19201
19953
  address: "GLAMpaME8wdTEzxtiYEAa5yD8fZbxZiz2hNtV58RZiEz"
19202
19954
  },
19955
+ {
19956
+ name: "system_program",
19957
+ address: "11111111111111111111111111111111"
19958
+ },
19203
19959
  {
19204
19960
  name: "stake_pool",
19205
19961
  writable: true
@@ -19219,18 +19975,10 @@ var instructions$1 = [
19219
19975
  name: "fee_account",
19220
19976
  writable: true
19221
19977
  },
19222
- {
19223
- name: "referrer_pool_tokens_account",
19224
- writable: true
19225
- },
19226
19978
  {
19227
19979
  name: "pool_mint",
19228
19980
  writable: true
19229
19981
  },
19230
- {
19231
- name: "system_program",
19232
- address: "11111111111111111111111111111111"
19233
- },
19234
19982
  {
19235
19983
  name: "token_program"
19236
19984
  }
@@ -19342,6 +20090,9 @@ var instructions$1 = [
19342
20090
  name: "validator_list",
19343
20091
  writable: true
19344
20092
  },
20093
+ {
20094
+ name: "stake_pool_deposit_authority"
20095
+ },
19345
20096
  {
19346
20097
  name: "stake_pool_withdraw_authority"
19347
20098
  },
@@ -19365,10 +20116,6 @@ var instructions$1 = [
19365
20116
  name: "fee_account",
19366
20117
  writable: true
19367
20118
  },
19368
- {
19369
- name: "referrer_pool_tokens_account",
19370
- writable: true
19371
- },
19372
20119
  {
19373
20120
  name: "pool_mint",
19374
20121
  writable: true
@@ -20655,29 +21402,14 @@ var constants$1 = [
20655
21402
  value: "2"
20656
21403
  },
20657
21404
  {
20658
- name: "PROTO_STAKE_POOL",
21405
+ name: "PROTO_SANCTUM_MULTI",
20659
21406
  type: "u16",
20660
- value: "1"
20661
- },
20662
- {
20663
- name: "SANCTUM_PERM_DEPOSIT_SOL",
20664
- type: "u64",
20665
- value: "1"
20666
- },
20667
- {
20668
- name: "SANCTUM_PERM_DEPOSIT_STAKE",
20669
- type: "u64",
20670
- value: "2"
20671
- },
20672
- {
20673
- name: "SANCTUM_PERM_WITHDRAW_SOL",
20674
- type: "u64",
20675
21407
  value: "4"
20676
21408
  },
20677
21409
  {
20678
- name: "SANCTUM_PERM_WITHDRAW_STAKE",
20679
- type: "u64",
20680
- value: "8"
21410
+ name: "PROTO_STAKE_POOL",
21411
+ type: "u16",
21412
+ value: "1"
20681
21413
  },
20682
21414
  {
20683
21415
  name: "STAKE_POOL_PERM_DEPOSIT_SOL",
@@ -22318,7 +23050,6 @@ const KAMINO_RESERVE_SIZE = 8624;
22318
23050
  const DRIFT_VAULT_DEPOSITOR_SIZE = 272;
22319
23051
  const JUPITER_API_DEFAULT = "https://lite-api.jup.ag";
22320
23052
  const JITO_TIP_DEFAULT = new web3_js.PublicKey("96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5");
22321
- const KAMINO_SCOPE_PRICES = new web3_js.PublicKey("3NJYftD5sjVfxSnUdZ1wVML8f3aC6mp1CXCL6L7TnU8C");
22322
23053
  const MARINADE_NATIVE_STAKE_AUTHORITY = new web3_js.PublicKey("stWirqFCf2Uts1JBL1Jsd3r6VBWhgnpdPxCTe1MFjrq");
22323
23054
  /**
22324
23055
  * Token mints. If no devnet version is defined, assume mainnet and devnet addresses are the same.
@@ -22336,7 +23067,6 @@ const JUP = new web3_js.PublicKey("JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN")
22336
23067
  */ const MARINADE_PROGRAM_ID = new web3_js.PublicKey("MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD");
22337
23068
  const DRIFT_PROGRAM_ID = new web3_js.PublicKey("dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH");
22338
23069
  const DRIFT_VAULTS_PROGRAM_ID = new web3_js.PublicKey("vAuLTsyrvSfZRuRB3XgvkPwNGgYSs9YRYymVebLKoxR");
22339
- const DRIFT_DISTRIBUTOR_PROGRAM = new web3_js.PublicKey("E7HtfkEMhmn9uwL7EFNydcXBWy5WCYN1vFmKKjipEH1x");
22340
23070
  const JUPITER_PROGRAM_ID = new web3_js.PublicKey("JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4");
22341
23071
  const SANCTUM_STAKE_POOL_PROGRAM_ID = new web3_js.PublicKey("SP12tWFxD9oJsVWNavTTBZvMbA6gkAmxtVgxdqvyvhY");
22342
23072
  const GOVERNANCE_PROGRAM_ID = new web3_js.PublicKey("GovaE4iu227srtG2s3tZzB4RmWBzw8sTwrCLZz7kN7rY");
@@ -22351,10 +23081,6 @@ const MEMO_PROGRAM = new web3_js.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgD
22351
23081
  const ALT_PROGRAM_ID = new web3_js.PublicKey("AddressLookupTab1e1111111111111111111111111");
22352
23082
  const TOKEN_MESSENGER_MINTER_V2 = new web3_js.PublicKey("CCTPV2vPZJS2u2BBsUoscuikbYjnpFmbFsvVuJdgUMQe");
22353
23083
  const MESSAGE_TRANSMITTER_V2 = new web3_js.PublicKey("CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC");
22354
- /**
22355
- * Stake pools
22356
- */ const JITO_STAKE_POOL = new web3_js.PublicKey("Jito4APyf642JPZPx3hGc6WWJ8zPKtRbRs4P815Awbb");
22357
- const JUPSOL_STAKE_POOL = new web3_js.PublicKey("8VpRhuxa7sUUepdY3kQiTmX9rS5vx4WgaXiAnXq4KCtr");
22358
23084
  /**
22359
23085
  * Referrers
22360
23086
  */ const GLAM_REFERRER = new web3_js.PublicKey("GLAMrG37ZqioqvzBNQGCfCUueDz3tsr7MwMFyRk9PS89");
@@ -24649,7 +25375,7 @@ function decodeUser(buffer) {
24649
25375
  };
24650
25376
  }
24651
25377
 
24652
- const FractionDecimal$1 = Decimal.clone({
25378
+ const FractionDecimal = Decimal.clone({
24653
25379
  precision: 40
24654
25380
  });
24655
25381
  /**
@@ -24657,7 +25383,7 @@ const FractionDecimal$1 = Decimal.clone({
24657
25383
  * https://github.com/Kamino-Finance/klend-sdk/blob/2fbc31a5b165aca3e2ca2e3d0e6162848743192d/src/classes/fraction.ts#L26
24658
25384
  */ class Fraction {
24659
25385
  toDecimal() {
24660
- return new FractionDecimal$1(this.valueSf.toString()).div(Fraction.MULTIPLIER);
25386
+ return new FractionDecimal(this.valueSf.toString()).div(Fraction.MULTIPLIER);
24661
25387
  }
24662
25388
  getValue() {
24663
25389
  return this.valueSf;
@@ -24687,7 +25413,7 @@ const FractionDecimal$1 = Decimal.clone({
24687
25413
  Fraction.MAX_SIZE_F = 128;
24688
25414
  Fraction.MAX_SIZE_BF = 256;
24689
25415
  Fraction.FRACTIONS = 60;
24690
- Fraction.MULTIPLIER = new FractionDecimal$1(2).pow(Fraction.FRACTIONS);
25416
+ Fraction.MULTIPLIER = new FractionDecimal(2).pow(Fraction.FRACTIONS);
24691
25417
  Fraction.MAX_F_BN = new anchor.BN(2).pow(new anchor.BN(Fraction.MAX_SIZE_F)).sub(new anchor.BN(1));
24692
25418
  Fraction.MAX_BF_BN = new anchor.BN(2).pow(new anchor.BN(Fraction.MAX_SIZE_BF)).sub(new anchor.BN(1));
24693
25419
  Fraction.MIN_BN = new anchor.BN(0);
@@ -25458,8 +26184,10 @@ class BaseClient {
25458
26184
  }
25459
26185
  }
25460
26186
  class BaseTxBuilder {
25461
- build(ix, txOptions = {}) {
25462
- const tx = new web3_js.Transaction().add(...txOptions.preInstructions || [], ix, ...txOptions.postInstructions || []);
26187
+ /**
26188
+ * Build a transaction with the given instructions. Pre and post instructions in txOptions are preserved.
26189
+ */ build(ixs, txOptions = {}) {
26190
+ const tx = new web3_js.Transaction().add(...txOptions.preInstructions || [], ...ixs, ...txOptions.postInstructions || []);
25463
26191
  return tx;
25464
26192
  }
25465
26193
  constructor(base){
@@ -25551,97 +26279,448 @@ class DriftSpotMarket extends Decodable {
25551
26279
  get nameStr() {
25552
26280
  return charsToName(this.name);
25553
26281
  }
25554
- }
25555
- DriftSpotMarket._layout = borsh.struct([
25556
- borsh.array(borsh.u8(), 8, "discriminator"),
25557
- borsh.publicKey("marketPda"),
25558
- borsh.publicKey("oracle"),
25559
- borsh.publicKey("mint"),
25560
- borsh.publicKey("vault"),
25561
- borsh.array(borsh.u8(), 32, "name"),
25562
- // Padding for bytes between name and cumulativeDepositInterest
25563
- borsh.array(borsh.u8(), 464 - 168, "padding1"),
25564
- borsh.u128("cumulativeDepositInterest"),
25565
- borsh.u128("cumulativeBorrowInterest"),
25566
- // Padding for bytes between cumulativeBorrowInterest and decimals
25567
- borsh.array(borsh.u8(), 680 - 496, "padding2"),
25568
- borsh.u32("decimals"),
25569
- borsh.u16("marketIndex"),
25570
- borsh.u8("padding3"),
25571
- borsh.u8("oracleSource"),
25572
- borsh.array(borsh.u8(), 46, "padding4"),
25573
- borsh.u8("tokenProgram"),
25574
- borsh.u8("poolId"),
25575
- borsh.array(borsh.u8(), 40, "padding5")
25576
- ]);
25577
- class DriftPerpMarket extends Decodable {
25578
- get nameStr() {
25579
- return charsToName(this.name);
26282
+ }
26283
+ DriftSpotMarket._layout = borsh.struct([
26284
+ borsh.array(borsh.u8(), 8, "discriminator"),
26285
+ borsh.publicKey("marketPda"),
26286
+ borsh.publicKey("oracle"),
26287
+ borsh.publicKey("mint"),
26288
+ borsh.publicKey("vault"),
26289
+ borsh.array(borsh.u8(), 32, "name"),
26290
+ // Padding for bytes between name and cumulativeDepositInterest
26291
+ borsh.array(borsh.u8(), 464 - 168, "padding1"),
26292
+ borsh.u128("cumulativeDepositInterest"),
26293
+ borsh.u128("cumulativeBorrowInterest"),
26294
+ // Padding for bytes between cumulativeBorrowInterest and decimals
26295
+ borsh.array(borsh.u8(), 680 - 496, "padding2"),
26296
+ borsh.u32("decimals"),
26297
+ borsh.u16("marketIndex"),
26298
+ borsh.u8("padding3"),
26299
+ borsh.u8("oracleSource"),
26300
+ borsh.array(borsh.u8(), 46, "padding4"),
26301
+ borsh.u8("tokenProgram"),
26302
+ borsh.u8("poolId"),
26303
+ borsh.array(borsh.u8(), 40, "padding5")
26304
+ ]);
26305
+ class DriftPerpMarket extends Decodable {
26306
+ get nameStr() {
26307
+ return charsToName(this.name);
26308
+ }
26309
+ }
26310
+ DriftPerpMarket._layout = borsh.struct([
26311
+ borsh.array(borsh.u8(), 8, "discriminator"),
26312
+ borsh.publicKey("marketPda"),
26313
+ borsh.publicKey("oracle"),
26314
+ borsh.array(borsh.u8(), 854, "padding1"),
26315
+ borsh.u8("oracleSource"),
26316
+ borsh.array(borsh.u8(), 73, "padding2"),
26317
+ borsh.array(borsh.u8(), 32, "name"),
26318
+ borsh.array(borsh.u8(), 128, "padding3"),
26319
+ borsh.u16("marketIndex")
26320
+ ]);
26321
+
26322
+ const DRIFT_SIGNER = new web3_js.PublicKey("JCNCMFXo5M5qwUPg2Utu1u6YWp3MbygxqBsBeXXJfrw");
26323
+ const DRIFT_MARGIN_PRECISION = 10000;
26324
+ let TxBuilder$6 = class TxBuilder extends BaseTxBuilder {
26325
+ async initializeUserStatsIx(glamSigner) {
26326
+ const { userStats } = this.drift.getDriftUserPdas();
26327
+ return await this.base.extDriftProgram.methods.initializeUserStats().accounts({
26328
+ glamState: this.base.statePda,
26329
+ glamSigner,
26330
+ state: this.drift.driftStatePda,
26331
+ userStats
26332
+ }).instruction();
26333
+ }
26334
+ async initializeUserIx(glamSigner, subAccountId) {
26335
+ const name = `GLAM *.+ ${subAccountId}`.split("").map((char)=>char.charCodeAt(0)).concat(Array(24).fill(0));
26336
+ const { user, userStats } = this.drift.getDriftUserPdas(subAccountId);
26337
+ const { user: referrer, userStats: referrerStats } = this.drift.getGlamReferrerPdas();
26338
+ const remainingAccounts = [
26339
+ {
26340
+ pubkey: referrer,
26341
+ isWritable: true,
26342
+ isSigner: false
26343
+ },
26344
+ {
26345
+ pubkey: referrerStats,
26346
+ isWritable: true,
26347
+ isSigner: false
26348
+ }
26349
+ ];
26350
+ return await this.base.extDriftProgram.methods.initializeUser(subAccountId, name).accounts({
26351
+ glamState: this.base.statePda,
26352
+ user,
26353
+ userStats,
26354
+ state: this.drift.driftStatePda,
26355
+ glamSigner
26356
+ }).remainingAccounts(remainingAccounts).instruction();
26357
+ }
26358
+ async updateUserPoolIdIx(subAccountId, poolId) {
26359
+ const { user } = this.drift.getDriftUserPdas(subAccountId);
26360
+ return await this.base.extDriftProgram.methods.updateUserPoolId(subAccountId, poolId).accounts({
26361
+ glamState: this.base.statePda,
26362
+ user
26363
+ }).instruction();
26364
+ }
26365
+ async initializeIxs(subAccountId, glamSigner) {
26366
+ const ixs = [];
26367
+ // Create userStats account if it doesn't exist
26368
+ const { userStats } = this.drift.getDriftUserPdas();
26369
+ const userStatsInfo = await this.base.provider.connection.getAccountInfo(userStats);
26370
+ if (!userStatsInfo) {
26371
+ ixs.push(await this.initializeUserStatsIx(glamSigner));
26372
+ }
26373
+ // Initialize user (aka sub-account)
26374
+ ixs.push(await this.initializeUserIx(glamSigner, subAccountId));
26375
+ return ixs;
26376
+ }
26377
+ async initializeTx(subAccountId, txOptions = {}) {
26378
+ const glamSigner = txOptions.signer || this.base.signer;
26379
+ const ixs = await this.initializeIxs(subAccountId, glamSigner);
26380
+ const tx = this.build(ixs, txOptions);
26381
+ return await this.base.intoVersionedTransaction(tx, txOptions);
26382
+ }
26383
+ async depositIxs(amount, marketIndex, subAccountId, glamSigner) {
26384
+ const { user, userStats } = this.drift.getDriftUserPdas(subAccountId);
26385
+ const { mint, oracle, tokenProgram, marketPda, vault: driftVault, name } = await this.drift.fetchAndParseSpotMarket(marketIndex);
26386
+ console.log(`Spot market ${marketIndex} mint ${mint}, oracle: ${oracle}, marketPda: ${marketPda}, vault: ${driftVault}`);
26387
+ const preInstructions = [];
26388
+ const postInstructions = [];
26389
+ // If drift user doesn't exist, prepend initialization ixs
26390
+ if (!await this.drift.fetchDriftUser(subAccountId)) {
26391
+ // Only add ix to initialize user stats if subAccountId is 0
26392
+ if (subAccountId === 0) {
26393
+ preInstructions.push(await this.initializeUserStatsIx(glamSigner));
26394
+ }
26395
+ preInstructions.push(await this.initializeUserIx(glamSigner, subAccountId));
26396
+ // If market name ends with "-N", it means we're depositing to an isolated pool
26397
+ const isolatedPoolMatch = name.match(/-(\d+)$/);
26398
+ if (isolatedPoolMatch) {
26399
+ const poolId = parseInt(isolatedPoolMatch[1]);
26400
+ preInstructions.push(await this.updateUserPoolIdIx(subAccountId, poolId));
26401
+ }
26402
+ }
26403
+ if (mint.equals(WSOL)) {
26404
+ const wrapSolIxs = await this.vault.maybeWrapSol(amount, glamSigner);
26405
+ preInstructions.push(...wrapSolIxs);
26406
+ // If we need to wrap SOL, it means the wSOL balance will be drained,
26407
+ // and we close the wSOL token account for convenience
26408
+ const tokenAccount = this.base.getVaultAta(WSOL);
26409
+ const closeTokenAccountIx = await this.base.extSplProgram.methods.tokenCloseAccount().accounts({
26410
+ glamState: this.base.statePda,
26411
+ glamSigner,
26412
+ tokenAccount,
26413
+ cpiProgram: splToken.TOKEN_PROGRAM_ID
26414
+ }).instruction();
26415
+ postInstructions.push(closeTokenAccountIx);
26416
+ }
26417
+ const remainingAccounts = [
26418
+ {
26419
+ pubkey: new web3_js.PublicKey(oracle),
26420
+ isSigner: false,
26421
+ isWritable: false
26422
+ },
26423
+ {
26424
+ pubkey: new web3_js.PublicKey(marketPda),
26425
+ isSigner: false,
26426
+ isWritable: true
26427
+ }
26428
+ ];
26429
+ if (tokenProgram.equals(splToken.TOKEN_2022_PROGRAM_ID)) {
26430
+ remainingAccounts.push({
26431
+ pubkey: mint,
26432
+ isSigner: false,
26433
+ isWritable: false
26434
+ });
26435
+ }
26436
+ const ix = await this.base.extDriftProgram.methods.deposit(marketIndex, amount, false).accounts({
26437
+ glamState: this.base.statePda,
26438
+ glamSigner,
26439
+ state: this.drift.driftStatePda,
26440
+ user,
26441
+ userStats,
26442
+ spotMarketVault: driftVault,
26443
+ userTokenAccount: this.base.getVaultAta(mint, tokenProgram),
26444
+ tokenProgram
26445
+ }).remainingAccounts(remainingAccounts).instruction();
26446
+ return [
26447
+ ...preInstructions,
26448
+ ix,
26449
+ ...postInstructions
26450
+ ];
26451
+ }
26452
+ async depositTx(amount, marketIndex, subAccountId, txOptions = {}) {
26453
+ const glamSigner = txOptions.signer || this.base.signer;
26454
+ const ixs = await this.depositIxs(amount, marketIndex, subAccountId, glamSigner);
26455
+ const tx = this.build(ixs, txOptions);
26456
+ return await this.base.intoVersionedTransaction(tx, txOptions);
26457
+ }
26458
+ async withdrawIxs(amount, marketIndex, subAccountId, glamSigner) {
26459
+ const { user, userStats } = this.drift.getDriftUserPdas(subAccountId);
26460
+ const { mint, tokenProgram, vault: driftVault } = await this.drift.fetchAndParseSpotMarket(marketIndex);
26461
+ const glamVault = this.base.vaultPda;
26462
+ const glamVaultAta = this.base.getVaultAta(mint, tokenProgram);
26463
+ const remainingAccounts = await this.drift.composeRemainingAccounts(subAccountId, MarketType.SPOT, marketIndex);
26464
+ if (tokenProgram.equals(splToken.TOKEN_2022_PROGRAM_ID)) {
26465
+ remainingAccounts.push({
26466
+ pubkey: mint,
26467
+ isSigner: false,
26468
+ isWritable: false
26469
+ });
26470
+ }
26471
+ // Create vault ata in case it doesn't exist
26472
+ const preIx = splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, glamVaultAta, glamVault, mint, tokenProgram);
26473
+ const ix = await this.base.extDriftProgram.methods.withdraw(marketIndex, amount, false).accounts({
26474
+ glamState: this.base.statePda,
26475
+ glamSigner,
26476
+ state: this.drift.driftStatePda,
26477
+ user,
26478
+ userStats,
26479
+ spotMarketVault: driftVault,
26480
+ userTokenAccount: glamVaultAta,
26481
+ driftSigner: DRIFT_SIGNER,
26482
+ tokenProgram
26483
+ }).remainingAccounts(remainingAccounts).instruction();
26484
+ return [
26485
+ preIx,
26486
+ ix
26487
+ ];
26488
+ }
26489
+ async withdrawTx(amount, marketIndex, subAccountId, txOptions = {}) {
26490
+ const glamSigner = txOptions.signer || this.base.signer;
26491
+ const ixs = await this.withdrawIxs(amount, marketIndex, subAccountId, glamSigner);
26492
+ const tx = this.build(ixs, txOptions);
26493
+ return await this.base.intoVersionedTransaction(tx, txOptions);
26494
+ }
26495
+ async updateUserCustomMarginRatioIx(maxLeverage, subAccountId, glamSigner) {
26496
+ const { user } = this.drift.getDriftUserPdas(subAccountId);
26497
+ // https://github.com/drift-labs/protocol-v2/blob/babed162b08b1fe34e49a81c5aa3e4ec0a88ecdf/programs/drift/src/math/constants.rs#L183-L184
26498
+ // 0 means No Limit
26499
+ const marginRatio = maxLeverage === 0 ? 0 : DRIFT_MARGIN_PRECISION / maxLeverage;
26500
+ return await this.base.extDriftProgram.methods.updateUserCustomMarginRatio(subAccountId, marginRatio).accounts({
26501
+ glamState: this.base.statePda,
26502
+ glamSigner,
26503
+ user
26504
+ }).instruction();
26505
+ }
26506
+ async updateUserCustomMarginRatioTx(maxLeverage, subAccountId = 0, txOptions = {}) {
26507
+ const glamSigner = txOptions.signer || this.base.signer;
26508
+ const ix = await this.updateUserCustomMarginRatioIx(maxLeverage, subAccountId, glamSigner);
26509
+ const tx = this.build([
26510
+ ix
26511
+ ], txOptions);
26512
+ return await this.base.intoVersionedTransaction(tx, txOptions);
26513
+ }
26514
+ async updateUserMarginTradingEnabledIx(marginTradingEnabled, subAccountId, glamSigner) {
26515
+ const { user } = this.drift.getDriftUserPdas(subAccountId);
26516
+ return await this.base.extDriftProgram.methods.updateUserMarginTradingEnabled(subAccountId, marginTradingEnabled).accounts({
26517
+ glamState: this.base.statePda,
26518
+ glamSigner,
26519
+ user
26520
+ }).instruction();
26521
+ }
26522
+ async updateUserMarginTradingEnabledTx(marginTradingEnabled, subAccountId = 0, txOptions = {}) {
26523
+ const glamSigner = txOptions.signer || this.base.signer;
26524
+ const ix = await this.updateUserMarginTradingEnabledIx(marginTradingEnabled, subAccountId, glamSigner);
26525
+ const tx = this.build([
26526
+ ix
26527
+ ], txOptions);
26528
+ return await this.base.intoVersionedTransaction(tx, txOptions);
26529
+ }
26530
+ async updateUserDelegateIx(delegate, subAccountId, glamSigner) {
26531
+ const { user } = this.drift.getDriftUserPdas(subAccountId);
26532
+ return await this.base.extDriftProgram.methods.updateUserDelegate(subAccountId, new web3_js.PublicKey(delegate)).accounts({
26533
+ glamState: this.base.statePda,
26534
+ glamSigner,
26535
+ user
26536
+ }).instruction();
26537
+ }
26538
+ async updateUserDelegateTx(delegate, subAccountId = 0, txOptions = {}) {
26539
+ const glamSigner = txOptions.signer || this.base.signer;
26540
+ const ix = await this.updateUserDelegateIx(delegate, subAccountId, glamSigner);
26541
+ const tx = this.build([
26542
+ ix
26543
+ ], txOptions);
26544
+ return await this.base.intoVersionedTransaction(tx, txOptions);
26545
+ }
26546
+ async deleteUserIx(subAccountId, glamSigner) {
26547
+ const { user, userStats } = this.drift.getDriftUserPdas(subAccountId);
26548
+ return await this.base.extDriftProgram.methods.deleteUser().accounts({
26549
+ glamState: this.base.statePda,
26550
+ state: this.drift.driftStatePda,
26551
+ user,
26552
+ userStats,
26553
+ glamSigner
26554
+ }).instruction();
26555
+ }
26556
+ async deleteUserTx(subAccountId, txOptions = {}) {
26557
+ const glamSigner = txOptions.signer || this.base.signer;
26558
+ const ix = await this.deleteUserIx(subAccountId, glamSigner);
26559
+ const tx = this.build([
26560
+ ix
26561
+ ], txOptions);
26562
+ return await this.base.intoVersionedTransaction(tx, txOptions);
26563
+ }
26564
+ async placeOrderIx(orderParams, subAccountId, glamSigner) {
26565
+ const { marketIndex, marketType } = orderParams;
26566
+ const { user: referrer, userStats: referrerStats } = this.drift.getGlamReferrerPdas();
26567
+ const remainingAccounts = (await this.drift.composeRemainingAccounts(subAccountId, marketType, marketIndex)).concat([
26568
+ {
26569
+ pubkey: referrer,
26570
+ isWritable: true,
26571
+ isSigner: false
26572
+ },
26573
+ {
26574
+ pubkey: referrerStats,
26575
+ isWritable: true,
26576
+ isSigner: false
26577
+ }
26578
+ ]);
26579
+ const { user } = this.drift.getDriftUserPdas(subAccountId);
26580
+ return await this.base.extDriftProgram.methods.placeOrders([
26581
+ orderParams
26582
+ ]).accounts({
26583
+ glamState: this.base.statePda,
26584
+ glamSigner,
26585
+ user,
26586
+ state: this.drift.driftStatePda
26587
+ }).remainingAccounts(remainingAccounts).instruction();
26588
+ }
26589
+ async placeOrderTx(orderParams, subAccountId, txOptions = {}) {
26590
+ const glamSigner = txOptions.signer || this.base.signer;
26591
+ const ix = await this.placeOrderIx(orderParams, subAccountId, glamSigner);
26592
+ const tx = this.build([
26593
+ ix
26594
+ ], txOptions);
26595
+ return await this.base.intoVersionedTransaction(tx, txOptions);
25580
26596
  }
25581
- }
25582
- DriftPerpMarket._layout = borsh.struct([
25583
- borsh.array(borsh.u8(), 8, "discriminator"),
25584
- borsh.publicKey("marketPda"),
25585
- borsh.publicKey("oracle"),
25586
- borsh.array(borsh.u8(), 854, "padding1"),
25587
- borsh.u8("oracleSource"),
25588
- borsh.array(borsh.u8(), 73, "padding2"),
25589
- borsh.array(borsh.u8(), 32, "name"),
25590
- borsh.array(borsh.u8(), 128, "padding3"),
25591
- borsh.u16("marketIndex")
25592
- ]);
25593
-
25594
- const DRIFT_SIGNER = new web3_js.PublicKey("JCNCMFXo5M5qwUPg2Utu1u6YWp3MbygxqBsBeXXJfrw");
25595
- const DRIFT_MARGIN_PRECISION = 10000;
26597
+ async modifyOrderIx(modifyOrderParams, orderId, marketIndex, marketType, subAccountId, glamSigner) {
26598
+ const remainingAccounts = await this.drift.composeRemainingAccounts(subAccountId, marketType, marketIndex);
26599
+ const { user } = this.drift.getDriftUserPdas(subAccountId);
26600
+ return await this.base.extDriftProgram.methods.modifyOrder(orderId, modifyOrderParams).accounts({
26601
+ glamState: this.base.statePda,
26602
+ glamSigner,
26603
+ user,
26604
+ state: this.drift.driftStatePda
26605
+ }).remainingAccounts(remainingAccounts).instruction();
26606
+ }
26607
+ async modifyOrderTx(modifyOrderParams, orderId, marketIndex, marketType, subAccountId, txOptions = {}) {
26608
+ const glamSigner = txOptions.signer || this.base.signer;
26609
+ const ix = await this.modifyOrderIx(modifyOrderParams, orderId, marketIndex, marketType, subAccountId, glamSigner);
26610
+ const tx = this.build([
26611
+ ix
26612
+ ], txOptions);
26613
+ return await this.base.intoVersionedTransaction(tx, txOptions);
26614
+ }
26615
+ async cancelOrdersIx(marketType, marketIndex, direction, subAccountId, glamSigner) {
26616
+ const remainingAccounts = await this.drift.composeRemainingAccounts(subAccountId, marketType, marketIndex);
26617
+ const { user } = this.drift.getDriftUserPdas(subAccountId);
26618
+ return await this.base.extDriftProgram.methods.cancelOrders(marketType, marketIndex, direction).accounts({
26619
+ glamState: this.base.statePda,
26620
+ glamSigner,
26621
+ user,
26622
+ state: this.drift.driftStatePda
26623
+ }).remainingAccounts(remainingAccounts).instruction();
26624
+ }
26625
+ async cancelOrdersTx(marketType, marketIndex, direction, subAccountId = 0, txOptions = {}) {
26626
+ const glamSigner = txOptions.signer || this.base.signer;
26627
+ const ix = await this.cancelOrdersIx(marketType, marketIndex, direction, subAccountId, glamSigner);
26628
+ const tx = this.build([
26629
+ ix
26630
+ ], txOptions);
26631
+ return await this.base.intoVersionedTransaction(tx, txOptions);
26632
+ }
26633
+ async cancelOrdersByIdsIx(orderIds, subAccountId, glamSigner) {
26634
+ const remainingAccounts = await this.drift.composeRemainingAccounts(subAccountId);
26635
+ const { user } = this.drift.getDriftUserPdas(subAccountId);
26636
+ return await this.base.extDriftProgram.methods.cancelOrdersByIds(orderIds).accounts({
26637
+ glamState: this.base.statePda,
26638
+ glamSigner,
26639
+ user,
26640
+ state: this.drift.driftStatePda
26641
+ }).remainingAccounts(remainingAccounts).instruction();
26642
+ }
26643
+ async cancelOrdersByIdsTx(orderIds, subAccountId = 0, txOptions = {}) {
26644
+ const glamSigner = txOptions.signer || this.base.signer;
26645
+ const ix = await this.cancelOrdersByIdsIx(orderIds, subAccountId, glamSigner);
26646
+ const tx = this.build([
26647
+ ix
26648
+ ], txOptions);
26649
+ return await this.base.intoVersionedTransaction(tx, txOptions);
26650
+ }
26651
+ async settlePnlIx(marketIndex, subAccountId, glamSigner) {
26652
+ const { vault: driftVault } = await this.drift.fetchAndParseSpotMarket(0);
26653
+ const remainingAccounts = await this.drift.composeRemainingAccounts(subAccountId, MarketType.PERP, marketIndex);
26654
+ const { user } = this.drift.getDriftUserPdas(subAccountId);
26655
+ return await this.base.extDriftProgram.methods.settlePnl(marketIndex).accounts({
26656
+ glamState: this.base.statePda,
26657
+ glamSigner,
26658
+ user,
26659
+ state: this.drift.driftStatePda,
26660
+ spotMarketVault: driftVault
26661
+ }).remainingAccounts(remainingAccounts).instruction();
26662
+ }
26663
+ async settlePnlTx(marketIndex, subAccountId = 0, txOptions = {}) {
26664
+ const glamSigner = txOptions.signer || this.base.signer;
26665
+ const ix = await this.settlePnlIx(marketIndex, subAccountId, glamSigner);
26666
+ const tx = this.build([
26667
+ ix
26668
+ ], txOptions);
26669
+ return await this.base.intoVersionedTransaction(tx, txOptions);
26670
+ }
26671
+ constructor(base, vault, drift){
26672
+ super(base), this.base = base, this.vault = vault, this.drift = drift;
26673
+ }
26674
+ };
25596
26675
  class DriftClient {
25597
26676
  /*
25598
26677
  * Client methods
25599
26678
  */ async initialize(subAccountId = 0, txOptions = {}) {
25600
- const tx = await this.initializeTx(subAccountId, txOptions);
26679
+ const tx = await this.txBuilder.initializeTx(subAccountId, txOptions);
25601
26680
  return await this.base.sendAndConfirm(tx);
25602
26681
  }
25603
26682
  async updateUserCustomMarginRatio(maxLeverage, subAccountId = 0) {
25604
- const tx = await this.updateUserCustomMarginRatioTx(maxLeverage, subAccountId);
26683
+ const tx = await this.txBuilder.updateUserCustomMarginRatioTx(maxLeverage, subAccountId);
25605
26684
  return await this.base.sendAndConfirm(tx);
25606
26685
  }
25607
26686
  async updateUserMarginTradingEnabled(marginTradingEnabled, subAccountId = 0, txOptions = {}) {
25608
- const tx = await this.updateUserMarginTradingEnabledTx(marginTradingEnabled, subAccountId, txOptions);
26687
+ const tx = await this.txBuilder.updateUserMarginTradingEnabledTx(marginTradingEnabled, subAccountId, txOptions);
25609
26688
  return await this.base.sendAndConfirm(tx);
25610
26689
  }
25611
26690
  async updateUserDelegate(delegate, subAccountId = 0) {
25612
- const tx = await this.updateUserDelegateTx(new web3_js.PublicKey(delegate), subAccountId);
26691
+ const tx = await this.txBuilder.updateUserDelegateTx(new web3_js.PublicKey(delegate), subAccountId);
25613
26692
  return await this.base.sendAndConfirm(tx);
25614
26693
  }
25615
26694
  async deleteUser(subAccountId = 0, txOptions = {}) {
25616
- const tx = await this.deleteUserTx(subAccountId, txOptions);
26695
+ const tx = await this.txBuilder.deleteUserTx(subAccountId, txOptions);
25617
26696
  return await this.base.sendAndConfirm(tx);
25618
26697
  }
25619
26698
  async deposit(amount, marketIndex = 1, subAccountId = 0, txOptions = {}) {
25620
- const tx = await this.depositTx(amount, marketIndex, subAccountId, txOptions);
26699
+ const tx = await this.txBuilder.depositTx(amount, marketIndex, subAccountId, txOptions);
25621
26700
  return await this.base.sendAndConfirm(tx);
25622
26701
  }
25623
26702
  async withdraw(amount, marketIndex = 1, subAccountId = 0, txOptions = {}) {
25624
- const tx = await this.withdrawTx(amount, marketIndex, subAccountId, txOptions);
26703
+ const tx = await this.txBuilder.withdrawTx(amount, marketIndex, subAccountId, txOptions);
25625
26704
  return await this.base.sendAndConfirm(tx);
25626
26705
  }
25627
26706
  async placeOrder(orderParams, subAccountId = 0, txOptions = {}) {
25628
- const tx = await this.placeOrderTx(orderParams, subAccountId, txOptions);
26707
+ const tx = await this.txBuilder.placeOrderTx(orderParams, subAccountId, txOptions);
25629
26708
  return await this.base.sendAndConfirm(tx);
25630
26709
  }
25631
26710
  async modifyOrder(modifyOrderParams, orderId, marketIndex, marketType, subAccountId = 0, txOptions = {}) {
25632
- const tx = await this.modifyOrderTx(modifyOrderParams, orderId, marketIndex, marketType, subAccountId, txOptions);
26711
+ const tx = await this.txBuilder.modifyOrderTx(modifyOrderParams, orderId, marketIndex, marketType, subAccountId, txOptions);
25633
26712
  return await this.base.sendAndConfirm(tx);
25634
26713
  }
25635
26714
  async cancelOrders(marketType, marketIndex, direction, subAccountId = 0, txOptions = {}) {
25636
- const tx = await this.cancelOrdersTx(marketType, marketIndex, direction, subAccountId, txOptions);
26715
+ const tx = await this.txBuilder.cancelOrdersTx(marketType, marketIndex, direction, subAccountId, txOptions);
25637
26716
  return await this.base.sendAndConfirm(tx);
25638
26717
  }
25639
26718
  async cancelOrdersByIds(orderIds, subAccountId = 0, txOptions = {}) {
25640
- const tx = await this.cancelOrdersByIdsTx(orderIds, subAccountId, txOptions);
26719
+ const tx = await this.txBuilder.cancelOrdersByIdsTx(orderIds, subAccountId, txOptions);
25641
26720
  return await this.base.sendAndConfirm(tx);
25642
26721
  }
25643
26722
  async settlePnl(marketIndex, subAccountId = 0, txOptions = {}) {
25644
- const tx = await this.settlePnlTx(marketIndex, subAccountId, txOptions);
26723
+ const tx = await this.txBuilder.settlePnlTx(marketIndex, subAccountId, txOptions);
25645
26724
  return await this.base.sendAndConfirm(tx);
25646
26725
  }
25647
26726
  getGlamReferrerPdas() {
@@ -25923,350 +27002,26 @@ class DriftClient {
25923
27002
  spotMarketIndexes.push(0);
25924
27003
  }
25925
27004
  }
25926
- const spotMarkets = await this.fetchAndParseSpotMarkets(spotMarketIndexes);
25927
- const perpMarkets = await this.fetchAndParsePerpMarkets(perpMarketIndexes);
25928
- if (process.env.NODE_ENV === "development") {
25929
- console.log("[composeRemainingAccounts] perpMarkets:", perpMarkets);
25930
- }
25931
- const oracles = spotMarkets.map((m)=>m.oracle).concat(perpMarkets.map((m)=>m.oracle));
25932
- const markets = spotMarkets.map((m)=>m.marketPda).concat(perpMarkets.map((m)=>m.marketPda));
25933
- if (process.env.NODE_ENV === "development") {
25934
- console.log("[composeRemainingAccounts] markets:", markets.map((m)=>m.toBase58()));
25935
- console.log("[composeRemainingAccounts] oracles:", oracles.map((o)=>o.toBase58()));
25936
- }
25937
- return oracles.map((o)=>({
25938
- pubkey: new web3_js.PublicKey(o),
25939
- isWritable: false,
25940
- isSigner: false
25941
- })).concat(markets.map((m)=>({
25942
- pubkey: new web3_js.PublicKey(m),
25943
- isWritable: true,
25944
- isSigner: false
25945
- })));
25946
- }
25947
- getClaimStatus(claimant, distributor) {
25948
- const [claimStatus] = web3_js.PublicKey.findProgramAddressSync([
25949
- Buffer.from("ClaimStatus"),
25950
- claimant.toBuffer(),
25951
- distributor.toBuffer()
25952
- ], DRIFT_DISTRIBUTOR_PROGRAM);
25953
- return claimStatus;
25954
- }
25955
- // public async claim(
25956
- // distributor: PublicKey,
25957
- // amountUnlocked: BN,
25958
- // amountLocked: BN,
25959
- // proof: number[][],
25960
- // txOptions: TxOptions = {},
25961
- // ) {
25962
- // const glamSigner = txOptions.signer || this.base.signer;
25963
- // const vault = this.base.vaultPda;
25964
- // const vaultAta = this.base.getVaultAta(DRIFT);
25965
- // const distributorAta = this.base.getAta(DRIFT, distributor);
25966
- // const preInstructions = [
25967
- // createAssociatedTokenAccountIdempotentInstruction(
25968
- // glamSigner,
25969
- // vaultAta,
25970
- // vault,
25971
- // DRIFT,
25972
- // ),
25973
- // ];
25974
- // const tx = await this.base.extDriftProgram.methods
25975
- // .distributorNewClaim(amountUnlocked, amountLocked, proof)
25976
- // .accounts({
25977
- // glamState: this.base.statePda,
25978
- // glamSigner,
25979
- // distributor,
25980
- // claimStatus: this.getClaimStatus(vault, distributor),
25981
- // from: distributorAta,
25982
- // to: vaultAta,
25983
- // tokenProgram: TOKEN_PROGRAM_ID,
25984
- // })
25985
- // .preInstructions(preInstructions)
25986
- // .transaction();
25987
- // const vTx = await this.base.intoVersionedTransaction(tx, { ...txOptions });
25988
- // return await this.base.sendAndConfirm(vTx);
25989
- // }
25990
- async initializeUserStatsIx(glamSigner) {
25991
- const { userStats } = this.getDriftUserPdas();
25992
- return await this.base.extDriftProgram.methods.initializeUserStats().accounts({
25993
- glamState: this.base.statePda,
25994
- glamSigner,
25995
- state: this.driftStatePda,
25996
- userStats
25997
- }).instruction();
25998
- }
25999
- async initializeUserIx(glamSigner, subAccountId) {
26000
- const name = `GLAM *.+ ${subAccountId}`.split("").map((char)=>char.charCodeAt(0)).concat(Array(24).fill(0));
26001
- const { user, userStats } = this.getDriftUserPdas(subAccountId);
26002
- const { user: referrer, userStats: referrerStats } = this.getGlamReferrerPdas();
26003
- const remainingAccounts = [
26004
- {
26005
- pubkey: referrer,
26006
- isWritable: true,
26007
- isSigner: false
26008
- },
26009
- {
26010
- pubkey: referrerStats,
26011
- isWritable: true,
26012
- isSigner: false
26013
- }
26014
- ];
26015
- return await this.base.extDriftProgram.methods.initializeUser(subAccountId, name).accounts({
26016
- glamState: this.base.statePda,
26017
- user,
26018
- userStats,
26019
- state: this.driftStatePda,
26020
- glamSigner
26021
- }).remainingAccounts(remainingAccounts).instruction();
26022
- }
26023
- async updateUserPoolIdIx(subAccountId, poolId) {
26024
- const { user } = this.getDriftUserPdas(subAccountId);
26025
- return await this.base.extDriftProgram.methods.updateUserPoolId(subAccountId, poolId).accounts({
26026
- glamState: this.base.statePda,
26027
- user
26028
- }).instruction();
26029
- }
26030
- async initializeTx(subAccountId = 0, txOptions = {}) {
26031
- const glamSigner = txOptions.signer || this.base.signer;
26032
- const tx = new web3_js.Transaction();
26033
- // Create userStats account if it doesn't exist
26034
- const { userStats } = this.getDriftUserPdas();
26035
- const userStatsInfo = await this.base.provider.connection.getAccountInfo(userStats);
26036
- if (!userStatsInfo) {
26037
- tx.add(await this.initializeUserStatsIx(glamSigner));
26038
- }
26039
- // Initialize user (aka sub-account)
26040
- tx.add(await this.initializeUserIx(glamSigner, subAccountId));
26041
- return await this.base.intoVersionedTransaction(tx, txOptions);
26042
- }
26043
- async updateUserCustomMarginRatioIx(maxLeverage, subAccountId = 0, txOptions = {}) {
26044
- const glamSigner = txOptions.signer || this.base.signer;
26045
- const { user } = this.getDriftUserPdas(subAccountId);
26046
- // https://github.com/drift-labs/protocol-v2/blob/babed162b08b1fe34e49a81c5aa3e4ec0a88ecdf/programs/drift/src/math/constants.rs#L183-L184
26047
- // 0 means No Limit
26048
- const marginRatio = maxLeverage === 0 ? 0 : DRIFT_MARGIN_PRECISION / maxLeverage;
26049
- return await this.base.extDriftProgram.methods.updateUserCustomMarginRatio(subAccountId, marginRatio).accounts({
26050
- glamState: this.base.statePda,
26051
- glamSigner,
26052
- user
26053
- }).instruction();
26054
- }
26055
- async updateUserCustomMarginRatioTx(maxLeverage, subAccountId = 0, txOptions = {}) {
26056
- const tx = new web3_js.Transaction().add(await this.updateUserCustomMarginRatioIx(maxLeverage, subAccountId, txOptions));
26057
- return await this.base.intoVersionedTransaction(tx, txOptions);
26058
- }
26059
- async updateUserMarginTradingEnabledIx(marginTradingEnabled, subAccountId = 0, txOptions = {}) {
26060
- const glamSigner = txOptions.signer || this.base.signer;
26061
- const { user } = this.getDriftUserPdas(subAccountId);
26062
- return await this.base.extDriftProgram.methods.updateUserMarginTradingEnabled(subAccountId, marginTradingEnabled).accounts({
26063
- glamState: this.base.statePda,
26064
- glamSigner,
26065
- user
26066
- }).instruction();
26067
- }
26068
- async updateUserMarginTradingEnabledTx(marginTradingEnabled, subAccountId = 0, txOptions = {}) {
26069
- const tx = new web3_js.Transaction().add(...txOptions.preInstructions || [], await this.updateUserMarginTradingEnabledIx(marginTradingEnabled, subAccountId, txOptions));
26070
- return await this.base.intoVersionedTransaction(tx, txOptions);
26071
- }
26072
- async updateUserDelegateIx(delegate, subAccountId = 0, txOptions = {}) {
26073
- const glamSigner = txOptions.signer || this.base.signer;
26074
- const { user } = this.getDriftUserPdas(subAccountId);
26075
- return await this.base.extDriftProgram.methods.updateUserDelegate(subAccountId, new web3_js.PublicKey(delegate)).accounts({
26076
- glamState: this.base.statePda,
26077
- glamSigner,
26078
- user
26079
- }).instruction();
26080
- }
26081
- async updateUserDelegateTx(delegate, subAccountId = 0, txOptions = {}) {
26082
- const tx = new web3_js.Transaction().add(await this.updateUserDelegateIx(delegate, subAccountId, txOptions));
26083
- return await this.base.intoVersionedTransaction(tx, txOptions);
26084
- }
26085
- async deleteUserTx(subAccountId = 0, txOptions = {}) {
26086
- const glamSigner = txOptions.signer || this.base.signer;
26087
- const { user, userStats } = this.getDriftUserPdas(subAccountId);
26088
- const tx = await this.base.extDriftProgram.methods.deleteUser().accounts({
26089
- glamState: this.base.statePda,
26090
- state: this.driftStatePda,
26091
- user,
26092
- userStats,
26093
- glamSigner
26094
- }).transaction();
26095
- return await this.base.intoVersionedTransaction(tx, txOptions);
26096
- }
26097
- async depositTx(amount, marketIndex = 1, subAccountId = 0, txOptions = {}) {
26098
- const glamSigner = txOptions.signer || this.base.signer;
26099
- const { user, userStats } = this.getDriftUserPdas(subAccountId);
26100
- const { mint, oracle, tokenProgram, marketPda, vault: driftVault, name } = await this.fetchAndParseSpotMarket(marketIndex);
26101
- console.log(`Spot market ${marketIndex} mint ${mint}, oracle: ${oracle}, marketPda: ${marketPda}, vault: ${driftVault}`);
26102
- const preInstructions = [];
26103
- const postInstructions = [];
26104
- // If drift user doesn't exist, prepend initialization ixs
26105
- if (!await this.fetchDriftUser(subAccountId)) {
26106
- // Only add ix to initialize user stats if subAccountId is 0
26107
- if (subAccountId === 0) {
26108
- preInstructions.push(await this.initializeUserStatsIx(glamSigner));
26109
- }
26110
- preInstructions.push(await this.initializeUserIx(glamSigner, subAccountId));
26111
- // If market name ends with "-N", it means we're depositing to an isolated pool
26112
- const isolatedPoolMatch = name.match(/-(\d+)$/);
26113
- if (isolatedPoolMatch) {
26114
- const poolId = parseInt(isolatedPoolMatch[1]);
26115
- preInstructions.push(await this.updateUserPoolIdIx(subAccountId, poolId));
26116
- }
26117
- }
26118
- if (mint.equals(WSOL)) {
26119
- const wrapSolIxs = await this.vault.maybeWrapSol(amount, glamSigner);
26120
- preInstructions.push(...wrapSolIxs);
26121
- // If we need to wrap SOL, it means the wSOL balance will be drained,
26122
- // and we close the wSOL token account for convenience
26123
- const tokenAccount = this.base.getVaultAta(WSOL);
26124
- const closeTokenAccountIx = await this.base.extSplProgram.methods.tokenCloseAccount().accounts({
26125
- glamState: this.base.statePda,
26126
- glamSigner,
26127
- tokenAccount,
26128
- cpiProgram: splToken.TOKEN_PROGRAM_ID
26129
- }).instruction();
26130
- postInstructions.push(closeTokenAccountIx);
26131
- }
26132
- const remainingAccounts = [
26133
- {
26134
- pubkey: new web3_js.PublicKey(oracle),
26135
- isSigner: false,
26136
- isWritable: false
26137
- },
26138
- {
26139
- pubkey: new web3_js.PublicKey(marketPda),
26140
- isSigner: false,
26141
- isWritable: true
26142
- }
26143
- ];
26144
- if (tokenProgram.equals(splToken.TOKEN_2022_PROGRAM_ID)) {
26145
- remainingAccounts.push({
26146
- pubkey: mint,
26147
- isSigner: false,
26148
- isWritable: false
26149
- });
26150
- }
26151
- const tx = await this.base.extDriftProgram.methods.deposit(marketIndex, amount, false).accounts({
26152
- glamState: this.base.statePda,
26153
- glamSigner,
26154
- state: this.driftStatePda,
26155
- user,
26156
- userStats,
26157
- spotMarketVault: driftVault,
26158
- userTokenAccount: this.base.getVaultAta(mint, tokenProgram),
26159
- tokenProgram
26160
- }).remainingAccounts(remainingAccounts).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
26161
- return await this.base.intoVersionedTransaction(tx, txOptions);
26162
- }
26163
- async withdrawTx(amount, marketIndex = 1, subAccountId = 0, txOptions = {}) {
26164
- const glamSigner = txOptions.signer || this.base.signer;
26165
- const { user, userStats } = this.getDriftUserPdas(subAccountId);
26166
- const { mint, tokenProgram, vault: driftVault } = await this.fetchAndParseSpotMarket(marketIndex);
26167
- const glamVault = this.base.vaultPda;
26168
- const glamVaultAta = this.base.getVaultAta(mint, tokenProgram);
26169
- const remainingAccounts = await this.composeRemainingAccounts(subAccountId, MarketType.SPOT, marketIndex);
26170
- if (tokenProgram.equals(splToken.TOKEN_2022_PROGRAM_ID)) {
26171
- remainingAccounts.push({
26172
- pubkey: mint,
26173
- isSigner: false,
26174
- isWritable: false
26175
- });
27005
+ const spotMarkets = await this.fetchAndParseSpotMarkets(spotMarketIndexes);
27006
+ const perpMarkets = await this.fetchAndParsePerpMarkets(perpMarketIndexes);
27007
+ if (process.env.NODE_ENV === "development") {
27008
+ console.log("[composeRemainingAccounts] perpMarkets:", perpMarkets);
26176
27009
  }
26177
- // Create vault ata in case it doesn't exist
26178
- const preInstructions = [
26179
- splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, glamVaultAta, glamVault, mint, tokenProgram)
26180
- ];
26181
- const tx = await this.base.extDriftProgram.methods.withdraw(marketIndex, amount, false).accounts({
26182
- glamState: this.base.statePda,
26183
- glamSigner,
26184
- state: this.driftStatePda,
26185
- user,
26186
- userStats,
26187
- spotMarketVault: driftVault,
26188
- userTokenAccount: glamVaultAta,
26189
- driftSigner: DRIFT_SIGNER,
26190
- tokenProgram
26191
- }).remainingAccounts(remainingAccounts).preInstructions(preInstructions).transaction();
26192
- return await this.base.intoVersionedTransaction(tx, txOptions);
26193
- }
26194
- async placeOrderTx(orderParams, subAccountId = 0, txOptions = {}) {
26195
- const { marketIndex, marketType } = orderParams;
26196
- const { user: referrer, userStats: referrerStats } = this.getGlamReferrerPdas();
26197
- const remainingAccounts = (await this.composeRemainingAccounts(subAccountId, marketType, marketIndex)).concat([
26198
- {
26199
- pubkey: referrer,
26200
- isWritable: true,
27010
+ const oracles = spotMarkets.map((m)=>m.oracle).concat(perpMarkets.map((m)=>m.oracle));
27011
+ const markets = spotMarkets.map((m)=>m.marketPda).concat(perpMarkets.map((m)=>m.marketPda));
27012
+ if (process.env.NODE_ENV === "development") {
27013
+ console.log("[composeRemainingAccounts] markets:", markets.map((m)=>m.toBase58()));
27014
+ console.log("[composeRemainingAccounts] oracles:", oracles.map((o)=>o.toBase58()));
27015
+ }
27016
+ return oracles.map((o)=>({
27017
+ pubkey: new web3_js.PublicKey(o),
27018
+ isWritable: false,
26201
27019
  isSigner: false
26202
- },
26203
- {
26204
- pubkey: referrerStats,
27020
+ })).concat(markets.map((m)=>({
27021
+ pubkey: new web3_js.PublicKey(m),
26205
27022
  isWritable: true,
26206
27023
  isSigner: false
26207
- }
26208
- ]);
26209
- const glamSigner = txOptions.signer || this.base.signer;
26210
- const { user } = this.getDriftUserPdas(subAccountId);
26211
- const tx = await this.base.extDriftProgram.methods.placeOrders([
26212
- orderParams
26213
- ]).accounts({
26214
- glamState: this.base.statePda,
26215
- glamSigner,
26216
- user,
26217
- state: this.driftStatePda
26218
- }).remainingAccounts(remainingAccounts).transaction();
26219
- return await this.base.intoVersionedTransaction(tx, txOptions);
26220
- }
26221
- async modifyOrderTx(modifyOrderParams, orderId, marketIndex, marketType, subAccountId = 0, txOptions = {}) {
26222
- const remainingAccounts = await this.composeRemainingAccounts(subAccountId, marketType, marketIndex);
26223
- const signer = txOptions.signer || this.base.signer;
26224
- const { user } = this.getDriftUserPdas(subAccountId);
26225
- const tx = await this.base.extDriftProgram.methods.modifyOrder(orderId, modifyOrderParams).accounts({
26226
- glamState: this.base.statePda,
26227
- glamSigner: signer,
26228
- user,
26229
- state: this.driftStatePda
26230
- }).remainingAccounts(remainingAccounts).transaction();
26231
- return await this.base.intoVersionedTransaction(tx, txOptions);
26232
- }
26233
- async cancelOrdersTx(marketType, marketIndex, direction, subAccountId = 0, txOptions = {}) {
26234
- const glamSigner = txOptions.signer || this.base.signer;
26235
- const { user } = this.getDriftUserPdas(subAccountId);
26236
- const remainingAccounts = await this.composeRemainingAccounts(subAccountId, marketType, marketIndex);
26237
- const tx = await this.base.extDriftProgram.methods.cancelOrders(marketType, marketIndex, direction).accounts({
26238
- glamState: this.base.statePda,
26239
- glamSigner,
26240
- user,
26241
- state: this.driftStatePda
26242
- }).remainingAccounts(remainingAccounts).transaction();
26243
- return await this.base.intoVersionedTransaction(tx, txOptions);
26244
- }
26245
- async cancelOrdersByIdsTx(orderIds, subAccountId = 0, txOptions = {}) {
26246
- const glamSigner = txOptions.signer || this.base.signer;
26247
- const { user } = this.getDriftUserPdas(subAccountId);
26248
- const remainingAccounts = await this.composeRemainingAccounts(subAccountId);
26249
- const tx = await this.base.extDriftProgram.methods.cancelOrdersByIds(orderIds).accounts({
26250
- glamState: this.base.statePda,
26251
- glamSigner,
26252
- user,
26253
- state: this.driftStatePda
26254
- }).remainingAccounts(remainingAccounts).transaction();
26255
- return await this.base.intoVersionedTransaction(tx, txOptions);
26256
- }
26257
- async settlePnlTx(marketIndex, subAccountId = 0, txOptions = {}) {
26258
- const glamSigner = txOptions.signer || this.base.signer;
26259
- const { user } = this.getDriftUserPdas(subAccountId);
26260
- const { vault: driftVault } = await this.fetchAndParseSpotMarket(0);
26261
- const remainingAccounts = await this.composeRemainingAccounts(subAccountId, MarketType.PERP, marketIndex);
26262
- const tx = await this.base.extDriftProgram.methods.settlePnl(marketIndex).accounts({
26263
- glamState: this.base.statePda,
26264
- glamSigner,
26265
- user,
26266
- state: this.driftStatePda,
26267
- spotMarketVault: driftVault
26268
- }).remainingAccounts(remainingAccounts).transaction();
26269
- return await this.base.intoVersionedTransaction(tx, txOptions);
27024
+ })));
26270
27025
  }
26271
27026
  constructor(base, vault){
26272
27027
  this.base = base;
@@ -26290,6 +27045,7 @@ class DriftClient {
26290
27045
  authority.toBuffer()
26291
27046
  ], DRIFT_PROGRAM_ID)[0];
26292
27047
  this.marketTypeEquals = (a, b)=>a && Object.keys(a)[0] === Object.keys(b)[0];
27048
+ this.txBuilder = new TxBuilder$6(base, vault, this);
26293
27049
  }
26294
27050
  }
26295
27051
  class DriftVaultsClient {
@@ -27012,7 +27768,7 @@ async function getSwapInstructions(quoteResponse, from) {
27012
27768
  });
27013
27769
  return await res.json();
27014
27770
  }
27015
- let TxBuilder$4 = class TxBuilder {
27771
+ let TxBuilder$5 = class TxBuilder {
27016
27772
  async swap(options, txOptions = {}) {
27017
27773
  const glamSigner = txOptions.signer || this.base.signer;
27018
27774
  const glamVault = this.base.vaultPda;
@@ -27114,7 +27870,7 @@ class JupiterSwapClient {
27114
27870
  constructor(base, vault){
27115
27871
  this.base = base;
27116
27872
  this.vault = vault;
27117
- this.txBuilder = new TxBuilder$4(base, vault);
27873
+ this.txBuilder = new TxBuilder$5(base, vault);
27118
27874
  }
27119
27875
  }
27120
27876
 
@@ -27599,7 +28355,7 @@ class VaultClient {
27599
28355
  }
27600
28356
  }
27601
28357
 
27602
- let TxBuilder$3 = class TxBuilder extends BaseTxBuilder {
28358
+ let TxBuilder$4 = class TxBuilder extends BaseTxBuilder {
27603
28359
  async initialize(params, txOptions = {}) {
27604
28360
  const glamSigner = txOptions.signer || this.base.signer;
27605
28361
  // stateInitKey = hash state name and get first 8 bytes
@@ -27630,7 +28386,9 @@ let TxBuilder$3 = class TxBuilder extends BaseTxBuilder {
27630
28386
  }
27631
28387
  async update(params, txOptions) {
27632
28388
  const ix = await this.updateIx(params, txOptions.signer);
27633
- const tx = this.build(ix, txOptions);
28389
+ const tx = this.build([
28390
+ ix
28391
+ ], txOptions);
27634
28392
  return await this.base.intoVersionedTransaction(tx, txOptions);
27635
28393
  }
27636
28394
  async updateIx(params, signer) {
@@ -27702,7 +28460,7 @@ class StateClient {
27702
28460
  }
27703
28461
  constructor(base){
27704
28462
  this.base = base;
27705
- this.txBuilder = new TxBuilder$3(base);
28463
+ this.txBuilder = new TxBuilder$4(base);
27706
28464
  }
27707
28465
  }
27708
28466
 
@@ -27926,164 +28684,67 @@ Obligation._layout = borsh.struct([
27926
28684
  borsh.u8("stale"),
27927
28685
  borsh.u8("priceStatus"),
27928
28686
  borsh.array(borsh.u8(), 6, "placeholder")
27929
- ], "lastUpdate"),
27930
- borsh.publicKey("lendingMarket"),
27931
- borsh.publicKey("owner"),
27932
- borsh.array(borsh.struct([
27933
- borsh.publicKey("depositReserve"),
27934
- borsh.u64("depositedAmount"),
27935
- borsh.u128("marketValueSf"),
27936
- borsh.u64("borrowedAmountAgainstThisCollateralInElevationGroup"),
27937
- borsh.array(borsh.u64(), 9, "padding")
27938
- ]), 8, "deposits"),
27939
- borsh.u64("lowestReserveDepositLiquidationLtv"),
27940
- borsh.u128("depositedValueSf"),
27941
- borsh.array(borsh.struct([
27942
- borsh.publicKey("borrowReserve"),
27943
- borsh.struct([
27944
- borsh.array(borsh.u64(), 4, "value"),
27945
- borsh.array(borsh.u64(), 2, "padding")
27946
- ], "cumulativeBorrowRateBsf"),
27947
- borsh.u64("padding"),
27948
- borsh.u128("borrowedAmountSf"),
27949
- borsh.u128("marketValueSf"),
27950
- borsh.u128("borrowFactorAdjustedMarketValueSf"),
27951
- borsh.u64("borrowedAmountOutsideElevationGroups"),
27952
- borsh.array(borsh.u64(), 7, "padding2")
27953
- ]), 5, "borrows"),
27954
- borsh.u128("borrowFactorAdjustedDebtValueSf"),
27955
- borsh.u128("borrowedAssetsMarketValueSf"),
27956
- borsh.u128("allowedBorrowValueSf"),
27957
- borsh.u128("unhealthyBorrowValueSf"),
27958
- borsh.array(borsh.u8(), 8, "depositsAssetTiers"),
27959
- borsh.array(borsh.u8(), 5, "borrowsAssetTiers"),
27960
- borsh.u8("elevationGroup"),
27961
- borsh.u8("numOfObsoleteDepositReserves"),
27962
- borsh.u8("hasDebt"),
27963
- borsh.publicKey("referrer"),
27964
- borsh.u8("borrowingDisabled"),
27965
- borsh.u8("autodeleverageTargetLtvPct"),
27966
- borsh.u8("lowestReserveDepositMaxLtvPct"),
27967
- borsh.u8("numOfObsoleteBorrowReserves"),
27968
- borsh.array(borsh.u8(), 4, "reserved"),
27969
- borsh.u64("highestBorrowFactorPct"),
27970
- borsh.u64("autodeleverageMarginCallStartedTimestamp"),
27971
- borsh.array(borsh.struct([
27972
- borsh.u128("conditionThresholdSf"),
27973
- borsh.u128("opportunityParameterSf"),
27974
- borsh.u16("minExecutionBonusBps"),
27975
- borsh.u16("maxExecutionBonusBps"),
27976
- borsh.u8("conditionType"),
27977
- borsh.u8("opportunityType"),
27978
- borsh.array(borsh.u8(), 2, "padding1"),
27979
- borsh.array(borsh.u64(), 8, "padding2")
27980
- ]), 2, "orders"),
27981
- borsh.array(borsh.u64(), 93, "padding3")
27982
- ]);
27983
-
27984
- const FractionDecimal = Decimal.clone({
27985
- precision: 40
27986
- });
27987
- new FractionDecimal(2).pow(60);
27988
- const DEFAULT_OBLIGATION_ARGS = {
27989
- tag: 0,
27990
- id: 0
27991
- };
27992
- const EVENT_AUTHORITY = new web3_js.PublicKey("24tHwQyJJ9akVXxnvkekGfAoeUJXXS7mE6kQNioNySsK");
27993
- class KaminoLendingClient {
27994
- /**
27995
- * Initializes Kamino user metadata
27996
- *
27997
- * @param market Lending market
27998
- * @param referrer Referrer user metadata
27999
- * @param txOptions
28000
- * @returns
28001
- */ async initUserMetadata(txOptions = {}) {
28002
- const tx = await this.initUserMetadataTx(txOptions);
28003
- return await this.base.sendAndConfirm(tx);
28004
- }
28005
- /**
28006
- * Deposits asset to the lending market.
28007
- *
28008
- * @param market Lending market
28009
- * @param asset Asset mint
28010
- * @param amount Amount to deposit
28011
- * @param txOptions
28012
- * @returns
28013
- */ async deposit(market, asset, amount, txOptions = {}) {
28014
- const tx = await this.depositTx(new web3_js.PublicKey(market), new web3_js.PublicKey(asset), new anchor.BN(amount), txOptions);
28015
- return await this.base.sendAndConfirm(tx);
28016
- }
28017
- /**
28018
- * Withdraws asset from the lending market.
28019
- *
28020
- * @param market Lending market
28021
- * @param asset Asset mint
28022
- * @param amount Amount to deposit
28023
- * @param txOptions
28024
- * @returns
28025
- */ async withdraw(market, asset, amount, txOptions = {}) {
28026
- const tx = await this.withdrawTx(new web3_js.PublicKey(market), new web3_js.PublicKey(asset), new anchor.BN(amount), txOptions);
28027
- return await this.base.sendAndConfirm(tx);
28028
- }
28029
- /**
28030
- * Borrows asset from the lending market.
28031
- *
28032
- * @param market Lending market
28033
- * @param asset Asset mint
28034
- * @param amount Amount to borrow
28035
- * @param txOptions
28036
- * @returns
28037
- */ async borrow(market, asset, amount, txOptions = {}) {
28038
- const tx = await this.borrowTx(new web3_js.PublicKey(market), new web3_js.PublicKey(asset), new anchor.BN(amount), txOptions);
28039
- return await this.base.sendAndConfirm(tx);
28040
- }
28041
- /**
28042
- * Repays asset to the lending market.
28043
- *
28044
- * @param market
28045
- * @param asset
28046
- * @param amount
28047
- * @param txOptions
28048
- * @returns
28049
- */ async repay(market, asset, amount, txOptions = {}) {
28050
- const tx = await this.repayTx(new web3_js.PublicKey(market), new web3_js.PublicKey(asset), new anchor.BN(amount), txOptions);
28051
- return await this.base.sendAndConfirm(tx);
28052
- }
28053
- getUserMetadataPda(owner) {
28054
- const [userMetadataPda] = web3_js.PublicKey.findProgramAddressSync([
28055
- Buffer.from("user_meta"),
28056
- owner.toBuffer()
28057
- ], KAMINO_LENDING_PROGRAM);
28058
- return userMetadataPda;
28059
- }
28060
- getObligationPda(owner, market, args = DEFAULT_OBLIGATION_ARGS) {
28061
- const seed = [
28062
- Buffer.from([
28063
- args.tag
28064
- ]),
28065
- Buffer.from([
28066
- args.id
28067
- ]),
28068
- owner.toBuffer(),
28069
- market.toBuffer(),
28070
- web3_js.PublicKey.default.toBuffer(),
28071
- web3_js.PublicKey.default.toBuffer()
28072
- ];
28073
- const [obligation, _] = web3_js.PublicKey.findProgramAddressSync(seed, KAMINO_LENDING_PROGRAM);
28074
- return obligation;
28075
- }
28076
- // seeds = [BASE_SEED_USER_STATE, farm_state.key().as_ref(), delegatee.key().as_ref()],
28077
- // for a delegated farm, the delegatee is the obligation, the owner (of farm user state) is the vault PDA
28078
- // for an un-delegated farm, the delegatee and the owner are the same (vault PDA)
28079
- getFarmUserState(farmUser, farm) {
28080
- const [obligationFarm] = web3_js.PublicKey.findProgramAddressSync([
28081
- Buffer.from("user"),
28082
- farm.toBuffer(),
28083
- farmUser.toBuffer()
28084
- ], KAMINO_FARM_PROGRAM);
28085
- return obligationFarm;
28086
- }
28687
+ ], "lastUpdate"),
28688
+ borsh.publicKey("lendingMarket"),
28689
+ borsh.publicKey("owner"),
28690
+ borsh.array(borsh.struct([
28691
+ borsh.publicKey("depositReserve"),
28692
+ borsh.u64("depositedAmount"),
28693
+ borsh.u128("marketValueSf"),
28694
+ borsh.u64("borrowedAmountAgainstThisCollateralInElevationGroup"),
28695
+ borsh.array(borsh.u64(), 9, "padding")
28696
+ ]), 8, "deposits"),
28697
+ borsh.u64("lowestReserveDepositLiquidationLtv"),
28698
+ borsh.u128("depositedValueSf"),
28699
+ borsh.array(borsh.struct([
28700
+ borsh.publicKey("borrowReserve"),
28701
+ borsh.struct([
28702
+ borsh.array(borsh.u64(), 4, "value"),
28703
+ borsh.array(borsh.u64(), 2, "padding")
28704
+ ], "cumulativeBorrowRateBsf"),
28705
+ borsh.u64("padding"),
28706
+ borsh.u128("borrowedAmountSf"),
28707
+ borsh.u128("marketValueSf"),
28708
+ borsh.u128("borrowFactorAdjustedMarketValueSf"),
28709
+ borsh.u64("borrowedAmountOutsideElevationGroups"),
28710
+ borsh.array(borsh.u64(), 7, "padding2")
28711
+ ]), 5, "borrows"),
28712
+ borsh.u128("borrowFactorAdjustedDebtValueSf"),
28713
+ borsh.u128("borrowedAssetsMarketValueSf"),
28714
+ borsh.u128("allowedBorrowValueSf"),
28715
+ borsh.u128("unhealthyBorrowValueSf"),
28716
+ borsh.array(borsh.u8(), 8, "depositsAssetTiers"),
28717
+ borsh.array(borsh.u8(), 5, "borrowsAssetTiers"),
28718
+ borsh.u8("elevationGroup"),
28719
+ borsh.u8("numOfObsoleteDepositReserves"),
28720
+ borsh.u8("hasDebt"),
28721
+ borsh.publicKey("referrer"),
28722
+ borsh.u8("borrowingDisabled"),
28723
+ borsh.u8("autodeleverageTargetLtvPct"),
28724
+ borsh.u8("lowestReserveDepositMaxLtvPct"),
28725
+ borsh.u8("numOfObsoleteBorrowReserves"),
28726
+ borsh.array(borsh.u8(), 4, "reserved"),
28727
+ borsh.u64("highestBorrowFactorPct"),
28728
+ borsh.u64("autodeleverageMarginCallStartedTimestamp"),
28729
+ borsh.array(borsh.struct([
28730
+ borsh.u128("conditionThresholdSf"),
28731
+ borsh.u128("opportunityParameterSf"),
28732
+ borsh.u16("minExecutionBonusBps"),
28733
+ borsh.u16("maxExecutionBonusBps"),
28734
+ borsh.u8("conditionType"),
28735
+ borsh.u8("opportunityType"),
28736
+ borsh.array(borsh.u8(), 2, "padding1"),
28737
+ borsh.array(borsh.u64(), 8, "padding2")
28738
+ ]), 2, "orders"),
28739
+ borsh.array(borsh.u64(), 93, "padding3")
28740
+ ]);
28741
+
28742
+ const DEFAULT_OBLIGATION_ARGS = {
28743
+ tag: 0,
28744
+ id: 0
28745
+ };
28746
+ const EVENT_AUTHORITY = new web3_js.PublicKey("24tHwQyJJ9akVXxnvkekGfAoeUJXXS7mE6kQNioNySsK");
28747
+ let TxBuilder$3 = class TxBuilder extends BaseTxBuilder {
28087
28748
  refreshObligationIx(accounts, programId = KAMINO_LENDING_PROGRAM) {
28088
28749
  const keys = [
28089
28750
  {
@@ -28320,14 +28981,14 @@ class KaminoLendingClient {
28320
28981
  return [
28321
28982
  farmCollateral
28322
28983
  ].filter((farm)=>!!farm).map((farm)=>{
28323
- const obligationFarmUserState = this.getFarmUserState(obligation, farm);
28984
+ const obligationFarmUserState = this.klend.getFarmUserState(obligation, farm);
28324
28985
  return this.refreshObligationFarmsForReserveIx({
28325
28986
  mode: 0
28326
28987
  }, {
28327
28988
  crank: this.base.signer,
28328
28989
  baseAccounts: {
28329
28990
  obligation,
28330
- lendingMarketAuthority: this.getMarketAuthority(lendingMarket),
28991
+ lendingMarketAuthority: this.klend.getMarketAuthority(lendingMarket),
28331
28992
  reserve: parsedReserve.address,
28332
28993
  reserveFarmState: farm,
28333
28994
  obligationFarmUserState,
@@ -28346,215 +29007,37 @@ class KaminoLendingClient {
28346
29007
  return [
28347
29008
  farmDebt
28348
29009
  ].filter((farm)=>!!farm).map((farm)=>{
28349
- const obligationFarmUserState = this.getFarmUserState(obligation, farm);
28350
- return this.refreshObligationFarmsForReserveIx({
28351
- mode: 1
28352
- }, {
28353
- crank: this.base.signer,
28354
- baseAccounts: {
28355
- obligation,
28356
- lendingMarketAuthority: this.getMarketAuthority(lendingMarket),
28357
- reserve: parsedReserve.address,
28358
- reserveFarmState: farm,
28359
- obligationFarmUserState,
28360
- lendingMarket
28361
- },
28362
- farmsProgram: KAMINO_FARM_PROGRAM,
28363
- rent: web3_js.SYSVAR_RENT_PUBKEY,
28364
- systemProgram: web3_js.SystemProgram.programId
28365
- });
28366
- });
28367
- }).flat();
28368
- }
28369
- getMarketAuthority(market) {
28370
- const [authority, _] = web3_js.PublicKey.findProgramAddressSync([
28371
- Buffer.from("lma"),
28372
- market.toBuffer()
28373
- ], KAMINO_LENDING_PROGRAM);
28374
- return authority;
28375
- }
28376
- reservePdas(market, mint) {
28377
- const [liquiditySupplyVault] = web3_js.PublicKey.findProgramAddressSync([
28378
- Buffer.from("reserve_liq_supply"),
28379
- market.toBuffer(),
28380
- mint.toBuffer()
28381
- ], KAMINO_LENDING_PROGRAM);
28382
- const [collateralMint] = web3_js.PublicKey.findProgramAddressSync([
28383
- Buffer.from("reserve_coll_mint"),
28384
- market.toBuffer(),
28385
- mint.toBuffer()
28386
- ], KAMINO_LENDING_PROGRAM);
28387
- const [collateralSupplyVault] = web3_js.PublicKey.findProgramAddressSync([
28388
- Buffer.from("reserve_coll_supply"),
28389
- market.toBuffer(),
28390
- mint.toBuffer()
28391
- ], KAMINO_LENDING_PROGRAM);
28392
- const [feeVault] = web3_js.PublicKey.findProgramAddressSync([
28393
- Buffer.from("fee_receiver"),
28394
- market.toBuffer(),
28395
- mint.toBuffer()
28396
- ], KAMINO_LENDING_PROGRAM);
28397
- return {
28398
- liquiditySupplyVault,
28399
- collateralMint,
28400
- collateralSupplyVault,
28401
- feeVault
28402
- };
28403
- }
28404
- parseObligation(obligation, data) {
28405
- const { lendingMarket, deposits: _deposits, borrows: _borrows } = Obligation.decode(obligation, data);
28406
- // Map decoded deposits to the expected format, filtering out empty deposits
28407
- const deposits = _deposits.filter(({ depositReserve })=>!depositReserve.equals(web3_js.PublicKey.default)).map(({ depositReserve, depositedAmount, marketValueSf })=>{
28408
- return {
28409
- reserve: depositReserve,
28410
- depositedAmount,
28411
- marketValueSf
28412
- };
28413
- });
28414
- // Map decoded borrows to the expected format, filtering out empty borrows
28415
- const borrows = _borrows.filter(({ borrowReserve })=>!borrowReserve.equals(web3_js.PublicKey.default)).map(({ borrowReserve, borrowedAmountSf, marketValueSf, cumulativeBorrowRateBsf })=>{
28416
- return {
28417
- reserve: borrowReserve,
28418
- borrowedAmountSf,
28419
- marketValueSf,
28420
- cumulativeBorrowRateBsf
28421
- };
28422
- });
28423
- return {
28424
- address: obligation,
28425
- lendingMarket,
28426
- deposits,
28427
- borrows
28428
- };
28429
- }
28430
- /**
28431
- * Fetches and parses an obligation account
28432
- */ async fetchAndParseObligation(obligation) {
28433
- const cached = this.obligations.get(obligation);
28434
- if (cached) {
28435
- return cached;
28436
- }
28437
- const obligationAccount = await this.base.provider.connection.getAccountInfo(obligation);
28438
- if (!obligationAccount) {
28439
- throw new Error("Obligation account not found");
28440
- }
28441
- const parsedObligation = this.parseObligation(obligation, obligationAccount.data);
28442
- this.obligations.set(obligation, parsedObligation);
28443
- return parsedObligation;
28444
- }
28445
- parseReserve(pubkey, data) {
28446
- const { lendingMarket, farmCollateral, farmDebt, liquidity: { mintPubkey, mintDecimals }, config: { tokenInfo: { scopeConfiguration: { priceFeed } } }, collateralExchangeRate, cumulativeBorrowRate } = Reserve.decode(pubkey, data);
28447
- return {
28448
- address: pubkey,
28449
- market: lendingMarket,
28450
- farmCollateral: farmCollateral.equals(web3_js.PublicKey.default) ? null : farmCollateral,
28451
- farmDebt: farmDebt.equals(web3_js.PublicKey.default) ? null : farmDebt,
28452
- liquidityMint: mintPubkey,
28453
- liquidityMintDecimals: mintDecimals.toNumber(),
28454
- scopePriceFeed: priceFeed,
28455
- ...this.reservePdas(lendingMarket, mintPubkey),
28456
- collateralExchangeRate,
28457
- cumulativeBorrowRate
28458
- };
28459
- }
28460
- async fetchAndParseReserves(reserves) {
28461
- const requestReservesSet = new PkSet(reserves);
28462
- const cachedReservesSet = new PkSet(Array.from(this.reserves.pkKeys()));
28463
- // If all requested reserves are cached, return data from cache
28464
- if (cachedReservesSet.includes(requestReservesSet)) {
28465
- return Array.from(this.reserves.values()).filter(({ address })=>requestReservesSet.has(address));
28466
- }
28467
- // Only fetch reserves that are not cached
28468
- const reservesToFetch = Array.from(requestReservesSet).filter((r)=>!cachedReservesSet.has(r));
28469
- if (process.env.NODE_ENV !== "production") {
28470
- console.log("Fetching reserves:", reservesToFetch.map((r)=>r.toBase58()));
28471
- }
28472
- const reserveAccounts = await this.base.provider.connection.getMultipleAccountsInfo(reservesToFetch);
28473
- if (reserveAccounts.some((a)=>!a)) {
28474
- throw new Error("Not all reserves can be found");
28475
- }
28476
- reserveAccounts.forEach((account, i)=>{
28477
- const parsedReserve = this.parseReserve(reservesToFetch[i], account.data);
28478
- this.reserves.set(reservesToFetch[i], parsedReserve);
28479
- });
28480
- // Return requested reserves
28481
- return Array.from(this.reserves.values()).filter(({ address })=>requestReservesSet.has(address));
28482
- }
28483
- /**
28484
- * Finds and parses a reserve account for a given market and asset
28485
- *
28486
- * @param market The lending market public key
28487
- * @param asset The asset public key
28488
- * @returns The parsed reserve account
28489
- */ async findAndParseReserve(market, asset) {
28490
- const accounts = await this.base.provider.connection.getProgramAccounts(KAMINO_LENDING_PROGRAM, {
28491
- filters: [
28492
- {
28493
- dataSize: KAMINO_RESERVE_SIZE
28494
- },
28495
- {
28496
- memcmp: {
28497
- offset: 32,
28498
- bytes: market.toBase58()
28499
- }
28500
- },
28501
- {
28502
- memcmp: {
28503
- offset: 128,
28504
- bytes: asset.toBase58()
28505
- }
28506
- }
28507
- ]
28508
- });
28509
- if (accounts.length === 0) {
28510
- throw new Error("Reserve not found");
28511
- }
28512
- const parsedReserve = this.parseReserve(accounts[0].pubkey, accounts[0].account.data);
28513
- this.reserves.set(accounts[0].pubkey, parsedReserve);
28514
- return parsedReserve;
28515
- }
28516
- /**
28517
- * Finds and parses Kamino obligations for a given owner and market (optional)
28518
- */ async findAndParseObligations(owner, market) {
28519
- const accounts = await this.base.provider.connection.getProgramAccounts(KAMINO_LENDING_PROGRAM, {
28520
- filters: [
28521
- {
28522
- dataSize: KAMINO_OBTRIGATION_SIZE
28523
- },
28524
- {
28525
- memcmp: {
28526
- offset: 64,
28527
- bytes: owner.toBase58()
28528
- }
28529
- },
28530
- ...market ? [
28531
- {
28532
- memcmp: {
28533
- offset: 32,
28534
- bytes: market.toBase58()
28535
- }
28536
- }
28537
- ] : []
28538
- ]
28539
- });
28540
- // Parse obligations and cache them
28541
- return accounts.map((a)=>{
28542
- const parsedObligation = this.parseObligation(a.pubkey, a.account.data);
28543
- this.obligations.set(a.pubkey, parsedObligation);
28544
- return parsedObligation;
28545
- });
29010
+ const obligationFarmUserState = this.klend.getFarmUserState(obligation, farm);
29011
+ return this.refreshObligationFarmsForReserveIx({
29012
+ mode: 1
29013
+ }, {
29014
+ crank: this.base.signer,
29015
+ baseAccounts: {
29016
+ obligation,
29017
+ lendingMarketAuthority: this.klend.getMarketAuthority(lendingMarket),
29018
+ reserve: parsedReserve.address,
29019
+ reserveFarmState: farm,
29020
+ obligationFarmUserState,
29021
+ lendingMarket
29022
+ },
29023
+ farmsProgram: KAMINO_FARM_PROGRAM,
29024
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
29025
+ systemProgram: web3_js.SystemProgram.programId
29026
+ });
29027
+ });
29028
+ }).flat();
28546
29029
  }
28547
29030
  /**
28548
29031
  * Returns two instructions that refresh reserves in batch and refresh obligation
28549
29032
  */ async refreshReservesAndObligationIxs(obligation, targetReserve) {
28550
29033
  // Get a set of reserves to refresh
28551
- const { deposits, borrows, lendingMarket } = await this.fetchAndParseObligation(obligation);
29034
+ const { deposits, borrows, lendingMarket } = await this.klend.fetchAndParseObligation(obligation);
28552
29035
  const reservesInUse = deposits.map(({ reserve })=>reserve).concat(borrows.map(({ reserve })=>reserve));
28553
29036
  // Refresh all reserves, including those in use and target reserve
28554
29037
  const reservesSet = new PkSet();
28555
29038
  reservesInUse.forEach((reserve)=>reservesSet.add(reserve));
28556
29039
  reservesSet.add(targetReserve.address);
28557
- const parsedReserves = await this.fetchAndParseReserves(Array.from(reservesSet));
29040
+ const parsedReserves = await this.klend.fetchAndParseReserves(Array.from(reservesSet));
28558
29041
  const refreshReservesIx = this.refreshReservesBatchIx(parsedReserves, false);
28559
29042
  // Refresh obligation with reserves in use (exclude target reserve)
28560
29043
  const refreshObligationIx = this.refreshObligationIx({
@@ -28579,13 +29062,13 @@ class KaminoLendingClient {
28579
29062
  initIx: null
28580
29063
  };
28581
29064
  }
28582
- const farmUser = this.getFarmUserState(obligation, farmState);
29065
+ const farmUser = this.klend.getFarmUserState(obligation, farmState);
28583
29066
  const farmUserAccount = await this.base.provider.connection.getAccountInfo(farmUser);
28584
29067
  const initIx = farmUserAccount ? null : await this.base.extKaminoProgram.methods.lendingInitObligationFarmsForReserve(mode).accounts({
28585
29068
  glamState: this.base.statePda,
28586
29069
  glamSigner: signer || this.base.signer,
28587
29070
  obligation,
28588
- lendingMarketAuthority: this.getMarketAuthority(market),
29071
+ lendingMarketAuthority: this.klend.getMarketAuthority(market),
28589
29072
  reserve: address,
28590
29073
  reserveFarmState: farmState,
28591
29074
  obligationFarm: farmUser,
@@ -28600,7 +29083,7 @@ class KaminoLendingClient {
28600
29083
  async initUserMetadataTx(txOptions = {}) {
28601
29084
  const glamSigner = txOptions.signer || this.base.signer;
28602
29085
  const vault = this.base.vaultPda;
28603
- const userMetadata = this.getUserMetadataPda(vault);
29086
+ const userMetadata = this.klend.getUserMetadataPda(vault);
28604
29087
  const lookupTable = new web3_js.PublicKey(0); // FIXME: create lookup table
28605
29088
  const tx = await this.base.extKaminoProgram.methods.lendingInitUserMetadata(lookupTable).accounts({
28606
29089
  glamState: this.base.statePda,
@@ -28608,16 +29091,14 @@ class KaminoLendingClient {
28608
29091
  userMetadata,
28609
29092
  referrerUserMetadata: null
28610
29093
  }).transaction();
28611
- const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
28612
- return vTx;
29094
+ return await this.base.intoVersionedTransaction(tx, txOptions);
28613
29095
  }
28614
- async depositTx(market, asset, amount, txOptions) {
28615
- const glamSigner = txOptions.signer || this.base.signer;
29096
+ async depositIxs(market, asset, amount, glamSigner) {
28616
29097
  const vault = this.base.vaultPda;
28617
- const userMetadata = this.getUserMetadataPda(vault);
28618
- const obligation = this.getObligationPda(vault, market);
28619
- const preInstructions = txOptions.preInstructions || [];
28620
- const postInstructions = txOptions.postInstructions || [];
29098
+ const userMetadata = this.klend.getUserMetadataPda(vault);
29099
+ const obligation = this.klend.getObligationPda(vault, market);
29100
+ const preInstructions = [];
29101
+ const postInstructions = [];
28621
29102
  const [userMetadataAccount, obligationAccount] = await this.base.provider.connection.getMultipleAccountsInfo([
28622
29103
  userMetadata,
28623
29104
  obligation
@@ -28643,7 +29124,7 @@ class KaminoLendingClient {
28643
29124
  ownerUserMetadata: userMetadata
28644
29125
  }).instruction());
28645
29126
  }
28646
- const depositReserve = await this.findAndParseReserve(market, asset);
29127
+ const depositReserve = await this.klend.findAndParseReserve(market, asset);
28647
29128
  const { farmUser: obligationFarmUser, initIx } = await this.initObligationFarmUserForReserveIx(obligation, depositReserve, 0, glamSigner);
28648
29129
  if (initIx) {
28649
29130
  preInstructions.push(initIx);
@@ -28690,12 +29171,12 @@ class KaminoLendingClient {
28690
29171
  // postInstructions.push(closeIx);
28691
29172
  // }
28692
29173
  }
28693
- const tx = await this.base.extKaminoProgram.methods.lendingDepositReserveLiquidityAndObligationCollateralV2(amount).accounts({
29174
+ const ix = await this.base.extKaminoProgram.methods.lendingDepositReserveLiquidityAndObligationCollateralV2(amount).accounts({
28694
29175
  glamState: this.base.statePda,
28695
29176
  glamSigner,
28696
29177
  obligation,
28697
29178
  lendingMarket: market,
28698
- lendingMarketAuthority: this.getMarketAuthority(market),
29179
+ lendingMarketAuthority: this.klend.getMarketAuthority(market),
28699
29180
  reserve: depositReserve.address,
28700
29181
  reserveLiquidityMint: asset,
28701
29182
  reserveLiquiditySupply: depositReserve.liquiditySupplyVault,
@@ -28709,17 +29190,25 @@ class KaminoLendingClient {
28709
29190
  obligationFarmUserState: obligationFarmUser,
28710
29191
  reserveFarmState: depositReserve.farmCollateral,
28711
29192
  farmsProgram: KAMINO_FARM_PROGRAM
28712
- }).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
28713
- const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
28714
- return vTx;
29193
+ }).instruction();
29194
+ return [
29195
+ ...preInstructions,
29196
+ ix,
29197
+ ...postInstructions
29198
+ ];
28715
29199
  }
28716
- async withdrawTx(market, asset, amount, txOptions) {
29200
+ async depositTx(market, asset, amount, txOptions = {}) {
28717
29201
  const glamSigner = txOptions.signer || this.base.signer;
29202
+ const ixs = await this.depositIxs(market, asset, amount, glamSigner);
29203
+ const tx = this.build(ixs, txOptions);
29204
+ return await this.base.intoVersionedTransaction(tx, txOptions);
29205
+ }
29206
+ async withdrawIxs(market, asset, amount, glamSigner) {
28718
29207
  const vault = this.base.vaultPda;
28719
- const obligation = this.getObligationPda(vault, market);
29208
+ const obligation = this.klend.getObligationPda(vault, market);
28720
29209
  const preInstructions = [];
28721
29210
  const postInstructions = [];
28722
- const withdrawReserve = await this.findAndParseReserve(market, asset);
29211
+ const withdrawReserve = await this.klend.findAndParseReserve(market, asset);
28723
29212
  const { farmUser: obligationFarmUser, initIx } = await this.initObligationFarmUserForReserveIx(obligation, withdrawReserve, 0, glamSigner);
28724
29213
  if (initIx) {
28725
29214
  preInstructions.push(initIx);
@@ -28746,7 +29235,7 @@ class KaminoLendingClient {
28746
29235
  glamSigner,
28747
29236
  obligation,
28748
29237
  lendingMarket: market,
28749
- lendingMarketAuthority: this.getMarketAuthority(market),
29238
+ lendingMarketAuthority: this.klend.getMarketAuthority(market),
28750
29239
  withdrawReserve: withdrawReserve.address,
28751
29240
  reserveLiquidityMint: asset,
28752
29241
  reserveSourceCollateral: withdrawReserve.collateralSupplyVault,
@@ -28773,106 +29262,392 @@ class KaminoLendingClient {
28773
29262
  // - refreshObligationFarmsForReserve (if farm exists)
28774
29263
  // - withdrawIx
28775
29264
  // - refreshObligationFarmsForReserve (if farm exists)
28776
- const tx = new web3_js.Transaction();
28777
- tx.add(...preInstructions, withdrawIx, ...postInstructions);
28778
- const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
28779
- return vTx;
29265
+ return [
29266
+ ...preInstructions,
29267
+ withdrawIx,
29268
+ ...postInstructions
29269
+ ];
29270
+ }
29271
+ async withdrawTx(market, asset, amount, txOptions = {}) {
29272
+ const glamSigner = txOptions.signer || this.base.signer;
29273
+ const ixs = await this.withdrawIxs(market, asset, amount, glamSigner);
29274
+ const tx = this.build(ixs, txOptions);
29275
+ return await this.base.intoVersionedTransaction(tx, txOptions);
29276
+ }
29277
+ async borrowIxs(market, asset, amount, glamSigner) {
29278
+ const vault = this.base.vaultPda;
29279
+ const obligation = this.klend.getObligationPda(vault, market);
29280
+ const preInstructions = [];
29281
+ const postInstructions = [];
29282
+ const borrowReserve = await this.klend.findAndParseReserve(market, asset);
29283
+ const { farmUser: obligationFarmUser, initIx } = await this.initObligationFarmUserForReserveIx(obligation, borrowReserve, 1, glamSigner);
29284
+ if (initIx) {
29285
+ preInstructions.push(initIx);
29286
+ }
29287
+ const ixs = await this.refreshReservesAndObligationIxs(obligation, borrowReserve);
29288
+ preInstructions.push(...ixs);
29289
+ if (borrowReserve.farmDebt) {
29290
+ const ixs = this.refreshObligationDebtFarmsForReservesIxs(obligation, market, [
29291
+ borrowReserve
29292
+ ]);
29293
+ preInstructions.push(...ixs);
29294
+ postInstructions.push(...ixs); // farms must be refreshed after borrow
29295
+ }
29296
+ // Create asset ATA in case it doesn't exist. Add it to the beginning of preInstructions
29297
+ const { tokenProgram } = await fetchMintAndTokenProgram(this.base.provider.connection, asset);
29298
+ const userDestinationLiquidity = this.base.getVaultAta(asset, tokenProgram);
29299
+ const createAtaIx = splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, userDestinationLiquidity, vault, asset, tokenProgram);
29300
+ preInstructions.unshift(createAtaIx);
29301
+ const borrowIx = await this.base.extKaminoProgram.methods.lendingBorrowObligationLiquidityV2(amount).accounts({
29302
+ glamState: this.base.statePda,
29303
+ glamSigner,
29304
+ obligation,
29305
+ lendingMarket: market,
29306
+ lendingMarketAuthority: this.klend.getMarketAuthority(market),
29307
+ borrowReserve: borrowReserve.address,
29308
+ borrowReserveLiquidityMint: asset,
29309
+ reserveSourceLiquidity: borrowReserve.liquiditySupplyVault,
29310
+ borrowReserveLiquidityFeeReceiver: borrowReserve.feeVault,
29311
+ userDestinationLiquidity,
29312
+ referrerTokenState: null,
29313
+ instructionSysvarAccount: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
29314
+ tokenProgram,
29315
+ obligationFarmUserState: obligationFarmUser,
29316
+ reserveFarmState: borrowReserve.farmDebt,
29317
+ farmsProgram: KAMINO_FARM_PROGRAM
29318
+ }).instruction();
29319
+ return [
29320
+ ...preInstructions,
29321
+ borrowIx
29322
+ ];
29323
+ }
29324
+ async borrowTx(market, asset, amount, txOptions = {}) {
29325
+ const glamSigner = txOptions.signer || this.base.signer;
29326
+ const ixs = await this.borrowIxs(market, asset, amount, glamSigner);
29327
+ const tx = this.build(ixs, txOptions);
29328
+ return await this.base.intoVersionedTransaction(tx, txOptions);
29329
+ }
29330
+ async repayIxs(market, asset, amount, glamSigner) {
29331
+ const vault = this.base.vaultPda;
29332
+ const obligation = this.klend.getObligationPda(vault, market);
29333
+ const preInstructions = [];
29334
+ const repayReserve = await this.klend.findAndParseReserve(market, asset);
29335
+ const { farmUser: obligationFarmUser, initIx } = await this.initObligationFarmUserForReserveIx(obligation, repayReserve, 1, glamSigner);
29336
+ if (initIx) {
29337
+ preInstructions.push(initIx);
29338
+ }
29339
+ const ixs = await this.refreshReservesAndObligationIxs(obligation, repayReserve);
29340
+ preInstructions.push(...ixs);
29341
+ const { tokenProgram } = await fetchMintAndTokenProgram(this.base.provider.connection, asset);
29342
+ const repayIx = await this.base.extKaminoProgram.methods.lendingRepayObligationLiquidityV2(amount).accounts({
29343
+ glamState: this.base.statePda,
29344
+ glamSigner,
29345
+ obligation,
29346
+ lendingMarket: market,
29347
+ lendingMarketAuthority: this.klend.getMarketAuthority(market),
29348
+ repayReserve: repayReserve.address,
29349
+ reserveLiquidityMint: asset,
29350
+ reserveDestinationLiquidity: repayReserve.liquiditySupplyVault,
29351
+ userSourceLiquidity: this.base.getVaultAta(asset, tokenProgram),
29352
+ instructionSysvarAccount: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
29353
+ tokenProgram,
29354
+ obligationFarmUserState: obligationFarmUser,
29355
+ reserveFarmState: repayReserve.farmDebt,
29356
+ farmsProgram: KAMINO_FARM_PROGRAM
29357
+ }).instruction();
29358
+ return [
29359
+ ...preInstructions,
29360
+ repayIx
29361
+ ];
29362
+ }
29363
+ async repayTx(market, asset, amount, txOptions = {}) {
29364
+ const glamSigner = txOptions.signer || this.base.signer;
29365
+ const ixs = await this.repayIxs(market, asset, amount, glamSigner);
29366
+ const tx = this.build(ixs, txOptions);
29367
+ return await this.base.intoVersionedTransaction(tx, txOptions);
29368
+ }
29369
+ constructor(base, vault, klend){
29370
+ super(base), this.base = base, this.vault = vault, this.klend = klend;
29371
+ }
29372
+ };
29373
+ class KaminoLendingClient {
29374
+ /**
29375
+ * Initializes Kamino user metadata
29376
+ *
29377
+ * @param market Lending market
29378
+ * @param referrer Referrer user metadata
29379
+ * @param txOptions
29380
+ * @returns
29381
+ */ async initUserMetadata(txOptions = {}) {
29382
+ const tx = await this.txBuilder.initUserMetadataTx(txOptions);
29383
+ return await this.base.sendAndConfirm(tx);
29384
+ }
29385
+ /**
29386
+ * Deposits asset to the lending market.
29387
+ *
29388
+ * @param market Lending market
29389
+ * @param asset Asset mint
29390
+ * @param amount Amount to deposit
29391
+ * @param txOptions
29392
+ * @returns
29393
+ */ async deposit(market, asset, amount, txOptions = {}) {
29394
+ const tx = await this.txBuilder.depositTx(new web3_js.PublicKey(market), new web3_js.PublicKey(asset), new anchor.BN(amount), txOptions);
29395
+ return await this.base.sendAndConfirm(tx);
29396
+ }
29397
+ /**
29398
+ * Withdraws asset from the lending market.
29399
+ *
29400
+ * @param market Lending market
29401
+ * @param asset Asset mint
29402
+ * @param amount Amount to deposit
29403
+ * @param txOptions
29404
+ * @returns
29405
+ */ async withdraw(market, asset, amount, txOptions = {}) {
29406
+ const tx = await this.txBuilder.withdrawTx(new web3_js.PublicKey(market), new web3_js.PublicKey(asset), new anchor.BN(amount), txOptions);
29407
+ return await this.base.sendAndConfirm(tx);
29408
+ }
29409
+ /**
29410
+ * Borrows asset from the lending market.
29411
+ *
29412
+ * @param market Lending market
29413
+ * @param asset Asset mint
29414
+ * @param amount Amount to borrow
29415
+ * @param txOptions
29416
+ * @returns
29417
+ */ async borrow(market, asset, amount, txOptions = {}) {
29418
+ const tx = await this.txBuilder.borrowTx(new web3_js.PublicKey(market), new web3_js.PublicKey(asset), new anchor.BN(amount), txOptions);
29419
+ return await this.base.sendAndConfirm(tx);
29420
+ }
29421
+ /**
29422
+ * Repays asset to the lending market.
29423
+ *
29424
+ * @param market
29425
+ * @param asset
29426
+ * @param amount
29427
+ * @param txOptions
29428
+ * @returns
29429
+ */ async repay(market, asset, amount, txOptions = {}) {
29430
+ const tx = await this.txBuilder.repayTx(new web3_js.PublicKey(market), new web3_js.PublicKey(asset), new anchor.BN(amount), txOptions);
29431
+ return await this.base.sendAndConfirm(tx);
29432
+ }
29433
+ getUserMetadataPda(owner) {
29434
+ const [userMetadataPda] = web3_js.PublicKey.findProgramAddressSync([
29435
+ Buffer.from("user_meta"),
29436
+ owner.toBuffer()
29437
+ ], KAMINO_LENDING_PROGRAM);
29438
+ return userMetadataPda;
29439
+ }
29440
+ getObligationPda(owner, market, args = DEFAULT_OBLIGATION_ARGS) {
29441
+ const seed = [
29442
+ Buffer.from([
29443
+ args.tag
29444
+ ]),
29445
+ Buffer.from([
29446
+ args.id
29447
+ ]),
29448
+ owner.toBuffer(),
29449
+ market.toBuffer(),
29450
+ web3_js.PublicKey.default.toBuffer(),
29451
+ web3_js.PublicKey.default.toBuffer()
29452
+ ];
29453
+ const [obligation, _] = web3_js.PublicKey.findProgramAddressSync(seed, KAMINO_LENDING_PROGRAM);
29454
+ return obligation;
29455
+ }
29456
+ // seeds = [BASE_SEED_USER_STATE, farm_state.key().as_ref(), delegatee.key().as_ref()],
29457
+ // for a delegated farm, the delegatee is the obligation, the owner (of farm user state) is the vault PDA
29458
+ // for an un-delegated farm, the delegatee and the owner are the same (vault PDA)
29459
+ getFarmUserState(farmUser, farm) {
29460
+ const [obligationFarm] = web3_js.PublicKey.findProgramAddressSync([
29461
+ Buffer.from("user"),
29462
+ farm.toBuffer(),
29463
+ farmUser.toBuffer()
29464
+ ], KAMINO_FARM_PROGRAM);
29465
+ return obligationFarm;
29466
+ }
29467
+ getMarketAuthority(market) {
29468
+ const [authority, _] = web3_js.PublicKey.findProgramAddressSync([
29469
+ Buffer.from("lma"),
29470
+ market.toBuffer()
29471
+ ], KAMINO_LENDING_PROGRAM);
29472
+ return authority;
29473
+ }
29474
+ reservePdas(market, mint) {
29475
+ const [liquiditySupplyVault] = web3_js.PublicKey.findProgramAddressSync([
29476
+ Buffer.from("reserve_liq_supply"),
29477
+ market.toBuffer(),
29478
+ mint.toBuffer()
29479
+ ], KAMINO_LENDING_PROGRAM);
29480
+ const [collateralMint] = web3_js.PublicKey.findProgramAddressSync([
29481
+ Buffer.from("reserve_coll_mint"),
29482
+ market.toBuffer(),
29483
+ mint.toBuffer()
29484
+ ], KAMINO_LENDING_PROGRAM);
29485
+ const [collateralSupplyVault] = web3_js.PublicKey.findProgramAddressSync([
29486
+ Buffer.from("reserve_coll_supply"),
29487
+ market.toBuffer(),
29488
+ mint.toBuffer()
29489
+ ], KAMINO_LENDING_PROGRAM);
29490
+ const [feeVault] = web3_js.PublicKey.findProgramAddressSync([
29491
+ Buffer.from("fee_receiver"),
29492
+ market.toBuffer(),
29493
+ mint.toBuffer()
29494
+ ], KAMINO_LENDING_PROGRAM);
29495
+ return {
29496
+ liquiditySupplyVault,
29497
+ collateralMint,
29498
+ collateralSupplyVault,
29499
+ feeVault
29500
+ };
29501
+ }
29502
+ parseObligation(obligation, data) {
29503
+ const { lendingMarket, deposits: _deposits, borrows: _borrows } = Obligation.decode(obligation, data);
29504
+ // Map decoded deposits to the expected format, filtering out empty deposits
29505
+ const deposits = _deposits.filter(({ depositReserve })=>!depositReserve.equals(web3_js.PublicKey.default)).map(({ depositReserve, depositedAmount, marketValueSf })=>{
29506
+ return {
29507
+ reserve: depositReserve,
29508
+ depositedAmount,
29509
+ marketValueSf
29510
+ };
29511
+ });
29512
+ // Map decoded borrows to the expected format, filtering out empty borrows
29513
+ const borrows = _borrows.filter(({ borrowReserve })=>!borrowReserve.equals(web3_js.PublicKey.default)).map(({ borrowReserve, borrowedAmountSf, marketValueSf, cumulativeBorrowRateBsf })=>{
29514
+ return {
29515
+ reserve: borrowReserve,
29516
+ borrowedAmountSf,
29517
+ marketValueSf,
29518
+ cumulativeBorrowRateBsf
29519
+ };
29520
+ });
29521
+ return {
29522
+ address: obligation,
29523
+ lendingMarket,
29524
+ deposits,
29525
+ borrows
29526
+ };
28780
29527
  }
28781
- async borrowTx(market, asset, amount, txOptions) {
28782
- const glamSigner = txOptions.signer || this.base.signer;
28783
- const vault = this.base.vaultPda;
28784
- const obligation = this.getObligationPda(vault, market);
28785
- const preInstructions = [];
28786
- const postInstructions = [];
28787
- const borrowReserve = await this.findAndParseReserve(market, asset);
28788
- const { farmUser: obligationFarmUser, initIx } = await this.initObligationFarmUserForReserveIx(obligation, borrowReserve, 1, glamSigner);
28789
- if (initIx) {
28790
- preInstructions.push(initIx);
29528
+ /**
29529
+ * Fetches and parses an obligation account
29530
+ */ async fetchAndParseObligation(obligation) {
29531
+ const cached = this.obligations.get(obligation);
29532
+ if (cached) {
29533
+ return cached;
28791
29534
  }
28792
- const ixs = await this.refreshReservesAndObligationIxs(obligation, borrowReserve);
28793
- preInstructions.push(...ixs);
28794
- if (borrowReserve.farmDebt) {
28795
- const ixs = this.refreshObligationDebtFarmsForReservesIxs(obligation, market, [
28796
- borrowReserve
28797
- ]);
28798
- preInstructions.push(...ixs);
28799
- postInstructions.push(...ixs); // farms must be refreshed after borrow
29535
+ const obligationAccount = await this.base.provider.connection.getAccountInfo(obligation);
29536
+ if (!obligationAccount) {
29537
+ throw new Error("Obligation account not found");
28800
29538
  }
28801
- // Create asset ATA in case it doesn't exist. Add it to the beginning of preInstructions
28802
- const { tokenProgram } = await fetchMintAndTokenProgram(this.base.provider.connection, asset);
28803
- const userDestinationLiquidity = this.base.getVaultAta(asset, tokenProgram);
28804
- const createAtaIx = splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, userDestinationLiquidity, vault, asset, tokenProgram);
28805
- preInstructions.unshift(createAtaIx);
28806
- const borrowIx = await this.base.extKaminoProgram.methods.lendingBorrowObligationLiquidityV2(amount).accounts({
28807
- glamState: this.base.statePda,
28808
- glamSigner,
28809
- obligation,
28810
- lendingMarket: market,
28811
- lendingMarketAuthority: this.getMarketAuthority(market),
28812
- borrowReserve: borrowReserve.address,
28813
- borrowReserveLiquidityMint: asset,
28814
- reserveSourceLiquidity: borrowReserve.liquiditySupplyVault,
28815
- borrowReserveLiquidityFeeReceiver: borrowReserve.feeVault,
28816
- userDestinationLiquidity,
28817
- referrerTokenState: null,
28818
- instructionSysvarAccount: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
28819
- tokenProgram,
28820
- obligationFarmUserState: obligationFarmUser,
28821
- reserveFarmState: borrowReserve.farmDebt,
28822
- farmsProgram: KAMINO_FARM_PROGRAM
28823
- }).instruction();
28824
- // The final instructions in the tx:
28825
- // - refreshReserve * N
28826
- // - refreshObligation
28827
- // - borrowObligationLiquidityV2
28828
- const tx = new web3_js.Transaction();
28829
- tx.add(...preInstructions, borrowIx);
28830
- const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
28831
- return vTx;
29539
+ const parsedObligation = this.parseObligation(obligation, obligationAccount.data);
29540
+ this.obligations.set(obligation, parsedObligation);
29541
+ return parsedObligation;
28832
29542
  }
28833
- async repayTx(market, asset, amount, txOptions = {}) {
28834
- const glamSigner = txOptions.signer || this.base.signer;
28835
- const vault = this.base.vaultPda;
28836
- const obligation = this.getObligationPda(vault, market);
28837
- const preInstructions = [];
28838
- const repayReserve = await this.findAndParseReserve(market, asset);
28839
- const { farmUser: obligationFarmUser, initIx } = await this.initObligationFarmUserForReserveIx(obligation, repayReserve, 1, glamSigner);
28840
- if (initIx) {
28841
- preInstructions.push(initIx);
29543
+ parseReserve(pubkey, data) {
29544
+ const { lendingMarket, farmCollateral, farmDebt, liquidity: { mintPubkey, mintDecimals }, config: { tokenInfo: { scopeConfiguration: { priceFeed } } }, collateralExchangeRate, cumulativeBorrowRate } = Reserve.decode(pubkey, data);
29545
+ return {
29546
+ address: pubkey,
29547
+ market: lendingMarket,
29548
+ farmCollateral: farmCollateral.equals(web3_js.PublicKey.default) ? null : farmCollateral,
29549
+ farmDebt: farmDebt.equals(web3_js.PublicKey.default) ? null : farmDebt,
29550
+ liquidityMint: mintPubkey,
29551
+ liquidityMintDecimals: mintDecimals.toNumber(),
29552
+ scopePriceFeed: priceFeed,
29553
+ ...this.reservePdas(lendingMarket, mintPubkey),
29554
+ collateralExchangeRate,
29555
+ cumulativeBorrowRate
29556
+ };
29557
+ }
29558
+ async fetchAndParseReserves(reserves) {
29559
+ const requestReservesSet = new PkSet(reserves);
29560
+ const cachedReservesSet = new PkSet(Array.from(this.reserves.pkKeys()));
29561
+ // If all requested reserves are cached, return data from cache
29562
+ if (cachedReservesSet.includes(requestReservesSet)) {
29563
+ return Array.from(this.reserves.values()).filter(({ address })=>requestReservesSet.has(address));
28842
29564
  }
28843
- const ixs = await this.refreshReservesAndObligationIxs(obligation, repayReserve);
28844
- preInstructions.push(...ixs);
28845
- const { tokenProgram } = await fetchMintAndTokenProgram(this.base.provider.connection, asset);
28846
- const repayIx = await this.base.extKaminoProgram.methods.lendingRepayObligationLiquidityV2(amount).accounts({
28847
- glamState: this.base.statePda,
28848
- glamSigner,
28849
- obligation,
28850
- lendingMarket: market,
28851
- lendingMarketAuthority: this.getMarketAuthority(market),
28852
- repayReserve: repayReserve.address,
28853
- reserveLiquidityMint: asset,
28854
- reserveDestinationLiquidity: repayReserve.liquiditySupplyVault,
28855
- userSourceLiquidity: this.base.getVaultAta(asset, tokenProgram),
28856
- instructionSysvarAccount: web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
28857
- tokenProgram,
28858
- obligationFarmUserState: obligationFarmUser,
28859
- reserveFarmState: repayReserve.farmDebt,
28860
- farmsProgram: KAMINO_FARM_PROGRAM
28861
- }).instruction();
28862
- // The final instructions in the tx:
28863
- // - refreshReserve * N
28864
- // - refreshObligation
28865
- // - repayObligationLiquidityV2
28866
- const tx = new web3_js.Transaction();
28867
- tx.add(...preInstructions, repayIx);
28868
- const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
28869
- return vTx;
29565
+ // Only fetch reserves that are not cached
29566
+ const reservesToFetch = Array.from(requestReservesSet).filter((r)=>!cachedReservesSet.has(r));
29567
+ if (process.env.NODE_ENV !== "production") {
29568
+ console.log("Fetching reserves:", reservesToFetch.map((r)=>r.toBase58()));
29569
+ }
29570
+ const reserveAccounts = await this.base.provider.connection.getMultipleAccountsInfo(reservesToFetch);
29571
+ if (reserveAccounts.some((a)=>!a)) {
29572
+ throw new Error("Not all reserves can be found");
29573
+ }
29574
+ reserveAccounts.forEach((account, i)=>{
29575
+ const parsedReserve = this.parseReserve(reservesToFetch[i], account.data);
29576
+ this.reserves.set(reservesToFetch[i], parsedReserve);
29577
+ });
29578
+ // Return requested reserves
29579
+ return Array.from(this.reserves.values()).filter(({ address })=>requestReservesSet.has(address));
29580
+ }
29581
+ /**
29582
+ * Finds and parses a reserve account for a given market and asset
29583
+ *
29584
+ * @param market The lending market public key
29585
+ * @param asset The asset public key
29586
+ * @returns The parsed reserve account
29587
+ */ async findAndParseReserve(market, asset) {
29588
+ const accounts = await this.base.provider.connection.getProgramAccounts(KAMINO_LENDING_PROGRAM, {
29589
+ filters: [
29590
+ {
29591
+ dataSize: KAMINO_RESERVE_SIZE
29592
+ },
29593
+ {
29594
+ memcmp: {
29595
+ offset: 32,
29596
+ bytes: market.toBase58()
29597
+ }
29598
+ },
29599
+ {
29600
+ memcmp: {
29601
+ offset: 128,
29602
+ bytes: asset.toBase58()
29603
+ }
29604
+ }
29605
+ ]
29606
+ });
29607
+ if (accounts.length === 0) {
29608
+ throw new Error("Reserve not found");
29609
+ }
29610
+ const parsedReserve = this.parseReserve(accounts[0].pubkey, accounts[0].account.data);
29611
+ this.reserves.set(accounts[0].pubkey, parsedReserve);
29612
+ return parsedReserve;
29613
+ }
29614
+ /**
29615
+ * Finds and parses Kamino obligations for a given owner and market (optional)
29616
+ */ async findAndParseObligations(owner, market) {
29617
+ const accounts = await this.base.provider.connection.getProgramAccounts(KAMINO_LENDING_PROGRAM, {
29618
+ filters: [
29619
+ {
29620
+ dataSize: KAMINO_OBTRIGATION_SIZE
29621
+ },
29622
+ {
29623
+ memcmp: {
29624
+ offset: 64,
29625
+ bytes: owner.toBase58()
29626
+ }
29627
+ },
29628
+ ...market ? [
29629
+ {
29630
+ memcmp: {
29631
+ offset: 32,
29632
+ bytes: market.toBase58()
29633
+ }
29634
+ }
29635
+ ] : []
29636
+ ]
29637
+ });
29638
+ // Parse obligations and cache them
29639
+ return accounts.map((a)=>{
29640
+ const parsedObligation = this.parseObligation(a.pubkey, a.account.data);
29641
+ this.obligations.set(a.pubkey, parsedObligation);
29642
+ return parsedObligation;
29643
+ });
28870
29644
  }
28871
29645
  constructor(base, vault){
28872
29646
  this.base = base;
28873
29647
  this.vault = vault;
28874
29648
  this.reserves = new PkMap();
28875
29649
  this.obligations = new PkMap();
29650
+ this.txBuilder = new TxBuilder$3(base, vault, this);
28876
29651
  }
28877
29652
  }
28878
29653
  class KaminoFarmClient {
@@ -29844,10 +30619,10 @@ class PriceClient {
29844
30619
  });
29845
30620
  // Refresh reserves in batch
29846
30621
  const parsedReserves = await this.klend.fetchAndParseReserves(Array.from(reservesSet));
29847
- ixs.push(this.klend.refreshReservesBatchIx(parsedReserves, false));
30622
+ ixs.push(this.klend.txBuilder.refreshReservesBatchIx(parsedReserves, false));
29848
30623
  // Refresh obligations
29849
30624
  parsedObligations.forEach(({ address: obligation, lendingMarket })=>{
29850
- ixs.push(this.klend.refreshObligationIx({
30625
+ ixs.push(this.klend.txBuilder.refreshObligationIx({
29851
30626
  obligation,
29852
30627
  lendingMarket,
29853
30628
  reserves: Array.from(obligationReservesMap.get(obligation) || [])
@@ -29930,7 +30705,7 @@ class PriceClient {
29930
30705
  }
29931
30706
  }
29932
30707
  const parsedReserves = await this.klend.fetchAndParseReserves(reserves);
29933
- const refreshReservesIx = this.klend.refreshReservesBatchIx(parsedReserves, false);
30708
+ const refreshReservesIx = this.klend.txBuilder.refreshReservesBatchIx(parsedReserves, false);
29934
30709
  const preInstructions = [
29935
30710
  refreshReservesIx
29936
30711
  ];
@@ -30057,33 +30832,23 @@ class PriceClient {
30057
30832
  /**
30058
30833
  * Returns an instruction that prices stake accounts.
30059
30834
  * If there are no stake accounts, returns null.
30060
- */ /*
30061
- async priceStakeAccountsIx(): Promise<TransactionInstruction | null> {
30062
- const stakes = await findStakeAccounts(
30063
- this.base.provider.connection,
30064
- this.base.vaultPda,
30065
- );
30066
- if (stakes.length === 0) {
30067
- return null;
30835
+ */ async priceStakeAccountsIx() {
30836
+ const stakes = await findStakeAccounts(this.base.connection, this.base.vaultPda);
30837
+ if (stakes.length === 0) {
30838
+ return null;
30839
+ }
30840
+ const priceStakesIx = await this.base.mintProgram.methods.priceStakeAccounts().accounts({
30841
+ glamState: this.base.statePda,
30842
+ solUsdOracle: SOL_ORACLE,
30843
+ baseAssetOracle: await this.getbaseAssetOracle()
30844
+ }).remainingAccounts(stakes.map((pubkey)=>({
30845
+ pubkey,
30846
+ isSigner: false,
30847
+ isWritable: false
30848
+ }))).instruction();
30849
+ return priceStakesIx;
30068
30850
  }
30069
- const priceStakesIx = await this.base.mintProgram.methods
30070
- .priceStakeAccounts()
30071
- .accounts({
30072
- glamState: this.base.statePda,
30073
- solUsdOracle: SOL_ORACLE,
30074
- baseAssetOracle: await this.getbaseAssetOracle(),
30075
- })
30076
- .remainingAccounts(
30077
- stakes.map((pubkey) => ({
30078
- pubkey,
30079
- isSigner: false,
30080
- isWritable: false,
30081
- })),
30082
- )
30083
- .instruction();
30084
- return priceStakesIx;
30085
- }
30086
- */ /**
30851
+ /**
30087
30852
  * Returns an instruction that prices Meteora positions.
30088
30853
  * If there are no Meteora positions, returns null.
30089
30854
  */ /*
@@ -30144,6 +30909,14 @@ class PriceClient {
30144
30909
  if (ixs) pricingIxs.push(...ixs);
30145
30910
  }
30146
30911
  }
30912
+ const nativeIntegrationAcl = integrationAcls.find((acl)=>acl.integrationProgram.equals(this.base.protocolProgram.programId));
30913
+ if (nativeIntegrationAcl) {
30914
+ // stake program
30915
+ if (nativeIntegrationAcl.protocolsBitmask & 0b10) {
30916
+ const ix = await this.priceStakeAccountsIx();
30917
+ if (ix) pricingIxs.push(ix);
30918
+ }
30919
+ }
30147
30920
  return pricingIxs.filter(Boolean);
30148
30921
  }
30149
30922
  async validateAumIx() {
@@ -30647,7 +31420,9 @@ let TxBuilder$2 = class TxBuilder extends BaseTxBuilder {
30647
31420
  }
30648
31421
  async closeMint(txOptions = {}) {
30649
31422
  const ix = await this.closeMintIx(txOptions.signer);
30650
- const tx = this.build(ix, txOptions);
31423
+ const tx = this.build([
31424
+ ix
31425
+ ], txOptions);
30651
31426
  return await this.base.intoVersionedTransaction(tx, txOptions);
30652
31427
  }
30653
31428
  };
@@ -30788,7 +31563,9 @@ class MintClient {
30788
31563
  let TxBuilder$1 = class TxBuilder extends BaseTxBuilder {
30789
31564
  async emergencyAccessUpdate(args, txOptions = {}) {
30790
31565
  const ix = await this.emergencyAccessUpdateIx(args, txOptions.signer);
30791
- const tx = this.build(ix, txOptions);
31566
+ const tx = this.build([
31567
+ ix
31568
+ ], txOptions);
30792
31569
  return await this.base.intoVersionedTransaction(tx, txOptions);
30793
31570
  }
30794
31571
  async emergencyAccessUpdateIx(args, signer) {
@@ -30999,13 +31776,9 @@ class StakingClient {
30999
31776
  txSig
31000
31777
  };
31001
31778
  }
31002
- async redelegate(existingStake, vote, txOptions = {}) {
31003
- const { newStake, tx } = await this.redelegateStakeTx(existingStake, vote, txOptions);
31004
- const txSig = await this.base.sendAndConfirm(tx);
31005
- return {
31006
- newStake,
31007
- txSig
31008
- };
31779
+ async move(sourceStake, destinationStake, amount, txOptions = {}) {
31780
+ const tx = await this.moveStakeTx(sourceStake, destinationStake, amount, txOptions);
31781
+ return await this.base.sendAndConfirm(tx);
31009
31782
  }
31010
31783
  /*
31011
31784
  * Utils
@@ -31140,7 +31913,6 @@ class StakingClient {
31140
31913
  stakePoolWithdrawAuthority: withdrawAuthority,
31141
31914
  reserveStake,
31142
31915
  feeAccount,
31143
- referrerPoolTokensAccount: poolTokensTo,
31144
31916
  poolTokensTo,
31145
31917
  poolMint,
31146
31918
  tokenProgram
@@ -31151,7 +31923,7 @@ class StakingClient {
31151
31923
  }
31152
31924
  async stakePoolDepositStakeTx(stakePool, stakeAccount, txOptions = {}) {
31153
31925
  const glamSigner = txOptions.signer || this.base.signer;
31154
- const { programId: stakePoolProgram, poolMint, withdrawAuthority, feeAccount, validatorList, tokenProgramId: tokenProgram, reserveStake } = await this.getStakePoolAccountData(stakePool);
31926
+ const { programId: stakePoolProgram, poolMint, depositAuthority, withdrawAuthority, feeAccount, validatorList, tokenProgramId: tokenProgram, reserveStake } = await this.getStakePoolAccountData(stakePool);
31155
31927
  const glamVault = this.base.vaultPda;
31156
31928
  const poolTokensTo = this.base.getVaultAta(poolMint, tokenProgram);
31157
31929
  // All stake accounts owned by the stake pool withdraw authority
@@ -31171,6 +31943,7 @@ class StakingClient {
31171
31943
  glamState: this.base.statePda,
31172
31944
  cpiProgram: stakePoolProgram,
31173
31945
  stakePool,
31946
+ stakePoolDepositAuthority: depositAuthority,
31174
31947
  stakePoolWithdrawAuthority: withdrawAuthority,
31175
31948
  validatorList,
31176
31949
  validatorStakeAccount,
@@ -31179,7 +31952,6 @@ class StakingClient {
31179
31952
  poolTokensTo,
31180
31953
  poolMint,
31181
31954
  feeAccount,
31182
- referrerPoolTokensAccount: poolTokensTo,
31183
31955
  tokenProgram
31184
31956
  }).preInstructions([
31185
31957
  splToken.createAssociatedTokenAccountIdempotentInstruction(glamSigner, poolTokensTo, glamVault, poolMint, tokenProgram)
@@ -31196,8 +31968,7 @@ class StakingClient {
31196
31968
  const validatorStakeAccount = validatorStakeCandidates.length === 0 ? reserveStake : validatorStakeCandidates[0].address;
31197
31969
  const [stakeAccount, createStakeAccountIx] = await this.createStakeAccount(glamSigner);
31198
31970
  const postInstructions = deactivate ? [
31199
- await this.base.protocolProgram.methods// @ts-ignore
31200
- .stakeDeactivate().accounts({
31971
+ await this.base.protocolProgram.methods.stakeDeactivate().accounts({
31201
31972
  glamSigner,
31202
31973
  glamState: this.base.statePda,
31203
31974
  stake: stakeAccount
@@ -31224,8 +31995,7 @@ class StakingClient {
31224
31995
  async initializeAndDelegateStakeTx(vote, amount, txOptions = {}) {
31225
31996
  const glamSigner = txOptions.signer || this.base.signer;
31226
31997
  const [stakeAccount, createStakeAccountIx] = await this.createStakeAccount(glamSigner);
31227
- const initStakeIx = await this.base.protocolProgram.methods// @ts-ignore
31228
- .stakeInitialize().accounts({
31998
+ const initStakeIx = await this.base.protocolProgram.methods.stakeInitialize().accounts({
31229
31999
  glamState: this.base.statePda,
31230
32000
  glamSigner,
31231
32001
  stake: stakeAccount
@@ -31235,8 +32005,7 @@ class StakingClient {
31235
32005
  glamSigner,
31236
32006
  to: stakeAccount
31237
32007
  }).instruction();
31238
- const tx = await this.base.protocolProgram.methods// @ts-ignore
31239
- .stakeDelegateStake().accounts({
32008
+ const tx = await this.base.protocolProgram.methods.stakeDelegateStake().accounts({
31240
32009
  glamState: this.base.statePda,
31241
32010
  glamSigner,
31242
32011
  stake: stakeAccount,
@@ -31254,8 +32023,7 @@ class StakingClient {
31254
32023
  throw new Error("At least one stake account is required");
31255
32024
  }
31256
32025
  const glamSigner = txOptions.signer || this.base.signer;
31257
- const tx = await this.base.protocolProgram.methods// @ts-ignore
31258
- .stakeDeactivate().accounts({
32026
+ const tx = await this.base.protocolProgram.methods.stakeDeactivate().accounts({
31259
32027
  glamState: this.base.statePda,
31260
32028
  glamSigner,
31261
32029
  stake: stakeAccounts[0]
@@ -31276,8 +32044,7 @@ class StakingClient {
31276
32044
  lamports = accontInfo ? new anchor.BN(accontInfo.lamports) : new anchor.BN(0);
31277
32045
  }
31278
32046
  const glamSigner = txOptions.signer || this.base.signer;
31279
- const tx = await this.base.protocolProgram.methods// @ts-ignore
31280
- .stakeWithdraw(lamports).accounts({
32047
+ const tx = await this.base.protocolProgram.methods.stakeWithdraw(lamports).accounts({
31281
32048
  glamSigner,
31282
32049
  glamState: this.base.statePda,
31283
32050
  stake: stakeAccounts[0]
@@ -31290,8 +32057,7 @@ class StakingClient {
31290
32057
  }
31291
32058
  async mergeStakeTx(destinationStake, sourceStake, txOptions = {}) {
31292
32059
  const glamSigner = txOptions.signer || this.base.signer;
31293
- const tx = await this.base.protocolProgram.methods// @ts-ignore
31294
- .stakeMerge().accounts({
32060
+ const tx = await this.base.protocolProgram.methods.stakeMerge().accounts({
31295
32061
  glamSigner,
31296
32062
  glamState: this.base.statePda,
31297
32063
  destinationStake,
@@ -31302,8 +32068,7 @@ class StakingClient {
31302
32068
  async splitStakeTx(existingStake, lamports, txOptions = {}) {
31303
32069
  const glamSigner = txOptions.signer || this.base.signer;
31304
32070
  const [newStake, createStakeAccountIx] = await this.createStakeAccount(glamSigner);
31305
- const tx = await this.base.protocolProgram.methods// @ts-ignore
31306
- .stakeSplit(lamports).accounts({
32071
+ const tx = await this.base.protocolProgram.methods.stakeSplit(lamports).accounts({
31307
32072
  glamSigner,
31308
32073
  glamState: this.base.statePda,
31309
32074
  stake: existingStake,
@@ -31317,25 +32082,15 @@ class StakingClient {
31317
32082
  newStake
31318
32083
  };
31319
32084
  }
31320
- async redelegateStakeTx(existingStake, vote, txOptions = {}) {
32085
+ async moveStakeTx(sourceStake, destinationStake, amount, txOptions = {}) {
31321
32086
  const glamSigner = txOptions.signer || this.base.signer;
31322
- const [newStake, createStakeAccountIx] = await this.createStakeAccount(glamSigner);
31323
- const tx = await this.base.protocolProgram.methods// @ts-ignore
31324
- .stakeRedelegate().accounts({
32087
+ const tx = await this.base.protocolProgram.methods.stakeMove(true, amount).accounts({
31325
32088
  glamSigner,
31326
32089
  glamState: this.base.statePda,
31327
- vote,
31328
- stake: existingStake,
31329
- newStake,
31330
- stakeConfig: web3_js.STAKE_CONFIG_ID
31331
- }).preInstructions([
31332
- createStakeAccountIx
31333
- ]).transaction();
31334
- const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
31335
- return {
31336
- tx: vTx,
31337
- newStake
31338
- };
32090
+ sourceStake,
32091
+ destinationStake
32092
+ }).transaction();
32093
+ return await this.base.intoVersionedTransaction(tx, txOptions);
31339
32094
  }
31340
32095
  constructor(base, marinade){
31341
32096
  this.base = base;
@@ -32025,7 +32780,6 @@ exports.CctpPolicy = CctpPolicy;
32025
32780
  exports.ContractTier = ContractTier;
32026
32781
  exports.ContractType = ContractType;
32027
32782
  exports.CreatedModel = CreatedModel;
32028
- exports.DRIFT_DISTRIBUTOR_PROGRAM = DRIFT_DISTRIBUTOR_PROGRAM;
32029
32783
  exports.DRIFT_POOL_MAPPING = DRIFT_POOL_MAPPING;
32030
32784
  exports.DRIFT_PROGRAM_ID = DRIFT_PROGRAM_ID;
32031
32785
  exports.DRIFT_VAULTS_PROGRAM_ID = DRIFT_VAULTS_PROGRAM_ID;
@@ -32054,12 +32808,10 @@ exports.GlamProtocolIdlJson = GlamProtocolIdlJson;
32054
32808
  exports.InsuranceFundOperation = InsuranceFundOperation;
32055
32809
  exports.IntegrationAcl = IntegrationAcl;
32056
32810
  exports.IntegrationPermissions = IntegrationPermissions;
32057
- exports.JITO_STAKE_POOL = JITO_STAKE_POOL;
32058
32811
  exports.JITO_TIP_DEFAULT = JITO_TIP_DEFAULT;
32059
32812
  exports.JUP = JUP;
32060
32813
  exports.JUPITER_API_DEFAULT = JUPITER_API_DEFAULT;
32061
32814
  exports.JUPITER_PROGRAM_ID = JUPITER_PROGRAM_ID;
32062
- exports.JUPSOL_STAKE_POOL = JUPSOL_STAKE_POOL;
32063
32815
  exports.JUP_VOTE_PROGRAM = JUP_VOTE_PROGRAM;
32064
32816
  exports.JupiterSwapClient = JupiterSwapClient;
32065
32817
  exports.JupiterSwapPolicy = JupiterSwapPolicy;
@@ -32067,7 +32819,6 @@ exports.KAMINO_FARM_PROGRAM = KAMINO_FARM_PROGRAM;
32067
32819
  exports.KAMINO_LENDING_PROGRAM = KAMINO_LENDING_PROGRAM;
32068
32820
  exports.KAMINO_OBTRIGATION_SIZE = KAMINO_OBTRIGATION_SIZE;
32069
32821
  exports.KAMINO_RESERVE_SIZE = KAMINO_RESERVE_SIZE;
32070
- exports.KAMINO_SCOPE_PRICES = KAMINO_SCOPE_PRICES;
32071
32822
  exports.KAMINO_VAULTS_PROGRAM = KAMINO_VAULTS_PROGRAM;
32072
32823
  exports.KaminoLendingPolicy = KaminoLendingPolicy;
32073
32824
  exports.KaminoVaultsPolicy = KaminoVaultsPolicy;