@kamino-finance/klend-sdk 5.11.15 → 5.11.16

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.
@@ -16,6 +16,7 @@ import {
16
16
  Chain,
17
17
  DEFAULT_RECENT_SLOT_DURATION_MS,
18
18
  encodeTokenName,
19
+ getMedianSlotDurationInMsFromLastEpochs,
19
20
  initLookupTableIx,
20
21
  KaminoManager,
21
22
  KaminoMarket,
@@ -84,7 +85,12 @@ async function main() {
84
85
 
85
86
  const multisigPk = multisig ? new PublicKey(multisig) : PublicKey.default;
86
87
 
87
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
88
+ const kaminoManager = new KaminoManager(
89
+ env.connection,
90
+ DEFAULT_RECENT_SLOT_DURATION_MS,
91
+ env.kLendProgramId,
92
+ env.kVaultProgramId
93
+ );
88
94
 
89
95
  const { market: marketKp, ixns: createMarketIxns } = await kaminoManager.createMarketIxs({
90
96
  admin: mode === 'multisig' ? multisigPk : env.payer.publicKey,
@@ -118,7 +124,12 @@ async function main() {
118
124
  }
119
125
 
120
126
  const multisigPk = multisig ? new PublicKey(multisig) : PublicKey.default;
121
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
127
+ const kaminoManager = new KaminoManager(
128
+ env.connection,
129
+ DEFAULT_RECENT_SLOT_DURATION_MS,
130
+ env.kLendProgramId,
131
+ env.kVaultProgramId
132
+ );
122
133
 
123
134
  const reserveConfigFromFile = JSON.parse(fs.readFileSync(reserveConfigPath, 'utf8'));
124
135
 
@@ -184,7 +195,12 @@ async function main() {
184
195
  throw new Error('If using multisig mode, multisig is required');
185
196
  }
186
197
 
187
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
198
+ const kaminoManager = new KaminoManager(
199
+ env.connection,
200
+ DEFAULT_RECENT_SLOT_DURATION_MS,
201
+ env.kLendProgramId,
202
+ env.kVaultProgramId
203
+ );
188
204
 
189
205
  const reserveConfigFromFile = JSON.parse(fs.readFileSync(reserveConfigPath, 'utf8'));
190
206
 
@@ -247,7 +263,12 @@ async function main() {
247
263
  }
248
264
 
249
265
  const multisigPk = multisig ? new PublicKey(multisig) : PublicKey.default;
250
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
266
+ const kaminoManager = new KaminoManager(
267
+ env.connection,
268
+ DEFAULT_RECENT_SLOT_DURATION_MS,
269
+ env.kLendProgramId,
270
+ env.kVaultProgramId
271
+ );
251
272
 
252
273
  const tokenProgramID = await getAccountOwner(env.connection, tokenMint);
253
274
  const kaminoVaultConfig = new KaminoVaultConfig({
@@ -293,7 +314,12 @@ async function main() {
293
314
  throw new Error('If using multisig mode, multisig is required');
294
315
  }
295
316
 
296
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
317
+ const kaminoManager = new KaminoManager(
318
+ env.connection,
319
+ DEFAULT_RECENT_SLOT_DURATION_MS,
320
+ env.kLendProgramId,
321
+ env.kVaultProgramId
322
+ );
297
323
 
298
324
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
299
325
  const instructions = await kaminoManager.updateVaultConfigIxs(kaminoVault, new PendingVaultAdmin(), newAdmin);
@@ -329,7 +355,12 @@ async function main() {
329
355
  throw new Error('If using multisig mode, multisig is required');
330
356
  }
331
357
 
332
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
358
+ const kaminoManager = new KaminoManager(
359
+ env.connection,
360
+ DEFAULT_RECENT_SLOT_DURATION_MS,
361
+ env.kLendProgramId,
362
+ env.kVaultProgramId
363
+ );
333
364
 
334
365
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
335
366
  const instructions = await kaminoManager.updateVaultConfigIxs(kaminoVault, field, value);
@@ -364,7 +395,12 @@ async function main() {
364
395
  throw new Error('If using multisig mode, multisig is required');
365
396
  }
366
397
 
367
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
398
+ const kaminoManager = new KaminoManager(
399
+ env.connection,
400
+ DEFAULT_RECENT_SLOT_DURATION_MS,
401
+ env.kLendProgramId,
402
+ env.kVaultProgramId
403
+ );
368
404
 
369
405
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
370
406
  const instructions = await kaminoManager.updateVaultConfigIxs(kaminoVault, new ManagementFeeBps(), feeBps);
@@ -401,7 +437,12 @@ async function main() {
401
437
  throw new Error('If using multisig mode, multisig is required');
402
438
  }
403
439
 
404
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
440
+ const kaminoManager = new KaminoManager(
441
+ env.connection,
442
+ DEFAULT_RECENT_SLOT_DURATION_MS,
443
+ env.kLendProgramId,
444
+ env.kVaultProgramId
445
+ );
405
446
 
406
447
  const instructions = await kaminoManager.insertIntoLUTIxs(env.payer.publicKey, lutAddress, addressesArr);
407
448
 
@@ -435,7 +476,12 @@ async function main() {
435
476
  throw new Error('If using multisig mode, multisig is required');
436
477
  }
437
478
 
438
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
479
+ const kaminoManager = new KaminoManager(
480
+ env.connection,
481
+ DEFAULT_RECENT_SLOT_DURATION_MS,
482
+ env.kLendProgramId,
483
+ env.kVaultProgramId
484
+ );
439
485
 
440
486
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
441
487
  const syncLUTIxs = await kaminoManager.syncVaultLUTIxs(kaminoVault);
@@ -471,7 +517,12 @@ async function main() {
471
517
  throw new Error('If using multisig mode, multisig is required');
472
518
  }
473
519
 
474
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
520
+ const kaminoManager = new KaminoManager(
521
+ env.connection,
522
+ DEFAULT_RECENT_SLOT_DURATION_MS,
523
+ env.kLendProgramId,
524
+ env.kVaultProgramId
525
+ );
475
526
 
476
527
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
477
528
  const instructions = await kaminoManager.updateVaultConfigIxs(kaminoVault, new PerformanceFeeBps(), feeBps);
@@ -505,7 +556,12 @@ async function main() {
505
556
  throw new Error('If using multisig mode, multisig is required');
506
557
  }
507
558
 
508
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
559
+ const kaminoManager = new KaminoManager(
560
+ env.connection,
561
+ DEFAULT_RECENT_SLOT_DURATION_MS,
562
+ env.kLendProgramId,
563
+ env.kVaultProgramId
564
+ );
509
565
 
510
566
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
511
567
  const instructions = await kaminoManager.acceptVaultOwnershipIxs(kaminoVault);
@@ -540,7 +596,12 @@ async function main() {
540
596
  throw new Error('If using multisig mode, multisig is required');
541
597
  }
542
598
 
543
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
599
+ const kaminoManager = new KaminoManager(
600
+ env.connection,
601
+ DEFAULT_RECENT_SLOT_DURATION_MS,
602
+ env.kLendProgramId,
603
+ env.kVaultProgramId
604
+ );
544
605
 
545
606
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
546
607
  const instruction = await kaminoManager.giveUpPendingFeesIx(kaminoVault, new Decimal(maxAmountToGiveUp));
@@ -567,7 +628,12 @@ async function main() {
567
628
  throw new Error('If using multisig mode, multisig is required');
568
629
  }
569
630
 
570
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
631
+ const kaminoManager = new KaminoManager(
632
+ env.connection,
633
+ DEFAULT_RECENT_SLOT_DURATION_MS,
634
+ env.kLendProgramId,
635
+ env.kVaultProgramId
636
+ );
571
637
 
572
638
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
573
639
  const instructions = await kaminoManager.withdrawPendingFeesIxs(
@@ -595,10 +661,12 @@ async function main() {
595
661
 
596
662
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
597
663
 
598
- const stakeIxs = await new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId).stakeSharesIxs(
599
- env.payer.publicKey,
600
- kaminoVault
601
- );
664
+ const stakeIxs = await new KaminoManager(
665
+ env.connection,
666
+ DEFAULT_RECENT_SLOT_DURATION_MS,
667
+ env.kLendProgramId,
668
+ env.kVaultProgramId
669
+ ).stakeSharesIxs(env.payer.publicKey, kaminoVault);
602
670
 
603
671
  if (mode === 'multisig' && !multisig) {
604
672
  throw new Error('If using multisig mode, multisig is required');
@@ -631,7 +699,12 @@ async function main() {
631
699
  throw new Error('If using multisig mode, multisig is required');
632
700
  }
633
701
 
634
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
702
+ const kaminoManager = new KaminoManager(
703
+ env.connection,
704
+ DEFAULT_RECENT_SLOT_DURATION_MS,
705
+ env.kLendProgramId,
706
+ env.kVaultProgramId
707
+ );
635
708
  const reserveState = await Reserve.fetch(env.connection, reserveAddress, env.kLendProgramId);
636
709
  if (!reserveState) {
637
710
  throw new Error('Reserve not found');
@@ -682,7 +755,12 @@ async function main() {
682
755
  throw new Error('If using multisig mode, multisig is required');
683
756
  }
684
757
 
685
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
758
+ const kaminoManager = new KaminoManager(
759
+ env.connection,
760
+ DEFAULT_RECENT_SLOT_DURATION_MS,
761
+ env.kLendProgramId,
762
+ env.kVaultProgramId
763
+ );
686
764
 
687
765
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
688
766
  const depositInstructions = await kaminoManager.depositToVaultIxs(env.payer.publicKey, kaminoVault, amount);
@@ -711,7 +789,12 @@ async function main() {
711
789
  throw new Error('If using multisig mode, multisig is required');
712
790
  }
713
791
 
714
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
792
+ const kaminoManager = new KaminoManager(
793
+ env.connection,
794
+ DEFAULT_RECENT_SLOT_DURATION_MS,
795
+ env.kLendProgramId,
796
+ env.kVaultProgramId
797
+ );
715
798
 
716
799
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
717
800
  const withdrawIxs = await kaminoManager.withdrawFromVaultIxs(
@@ -751,7 +834,12 @@ async function main() {
751
834
  throw new Error('If using multisig mode, multisig is required');
752
835
  }
753
836
 
754
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
837
+ const kaminoManager = new KaminoManager(
838
+ env.connection,
839
+ DEFAULT_RECENT_SLOT_DURATION_MS,
840
+ env.kLendProgramId,
841
+ env.kVaultProgramId
842
+ );
755
843
 
756
844
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
757
845
  const instructions = await kaminoManager.investAllReservesIxs(env.payer.publicKey, kaminoVault);
@@ -783,7 +871,12 @@ async function main() {
783
871
  throw new Error('If using multisig mode, multisig is required');
784
872
  }
785
873
 
786
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
874
+ const kaminoManager = new KaminoManager(
875
+ env.connection,
876
+ DEFAULT_RECENT_SLOT_DURATION_MS,
877
+ env.kLendProgramId,
878
+ env.kVaultProgramId
879
+ );
787
880
 
788
881
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
789
882
  const reserveState = await Reserve.fetch(env.connection, new PublicKey(reserve), env.kLendProgramId);
@@ -828,8 +921,9 @@ async function main() {
828
921
  .requiredOption('--vault <string>', 'Vault address')
829
922
  .action(async ({ vault }) => {
830
923
  const env = initializeClient(false, false);
924
+ const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
831
925
 
832
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
926
+ const kaminoManager = new KaminoManager(env.connection, slotDuration, env.kLendProgramId, env.kVaultProgramId);
833
927
 
834
928
  const vaultAddress = new PublicKey(vault);
835
929
  const vaultState = await new KaminoVault(vaultAddress, undefined, env.kVaultProgramId).getState(env.connection);
@@ -850,8 +944,9 @@ async function main() {
850
944
  .requiredOption('--vault <string>', 'Vault address')
851
945
  .action(async ({ vault }) => {
852
946
  const env = initializeClient(false, false);
947
+ const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
853
948
 
854
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
949
+ const kaminoManager = new KaminoManager(env.connection, slotDuration, env.kLendProgramId, env.kVaultProgramId);
855
950
 
856
951
  const vaultAddress = new PublicKey(vault);
857
952
  const vaultState = await new KaminoVault(vaultAddress, undefined, env.kVaultProgramId).getState(env.connection);
@@ -869,8 +964,9 @@ async function main() {
869
964
  .requiredOption('--vault <string>', 'Vault address')
870
965
  .action(async ({ vault }) => {
871
966
  const env = initializeClient(false, false);
967
+ const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
872
968
 
873
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
969
+ const kaminoManager = new KaminoManager(env.connection, slotDuration, env.kLendProgramId, env.kVaultProgramId);
874
970
 
875
971
  const vaultAddress = new PublicKey(vault);
876
972
  const vaultState = await new KaminoVault(vaultAddress, undefined, env.kVaultProgramId).getState(env.connection);
@@ -888,8 +984,9 @@ async function main() {
888
984
  .requiredOption('--wallet <string>', 'User wailt address')
889
985
  .action(async ({ vault, wallet }) => {
890
986
  const env = initializeClient(false, false);
987
+ const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
891
988
 
892
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
989
+ const kaminoManager = new KaminoManager(env.connection, slotDuration, env.kLendProgramId, env.kVaultProgramId);
893
990
 
894
991
  const vaultAddress = new PublicKey(vault);
895
992
  const walletAddress = new PublicKey(wallet);
@@ -903,8 +1000,9 @@ async function main() {
903
1000
  .requiredOption('--wallet <string>', 'User wailt address')
904
1001
  .action(async ({ wallet }) => {
905
1002
  const env = initializeClient(false, false);
1003
+ const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
906
1004
 
907
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
1005
+ const kaminoManager = new KaminoManager(env.connection, slotDuration, env.kLendProgramId, env.kVaultProgramId);
908
1006
 
909
1007
  const walletAddress = new PublicKey(wallet);
910
1008
  const userShares = await kaminoManager.getUserSharesBalanceAllVaults(walletAddress);
@@ -918,8 +1016,9 @@ async function main() {
918
1016
  .requiredOption('--vault <string>', 'Vault address')
919
1017
  .action(async ({ vault }) => {
920
1018
  const env = initializeClient(false, false);
1019
+ const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
921
1020
 
922
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
1021
+ const kaminoManager = new KaminoManager(env.connection, slotDuration, env.kLendProgramId, env.kVaultProgramId);
923
1022
 
924
1023
  const vaultAddress = new PublicKey(vault);
925
1024
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
@@ -935,8 +1034,9 @@ async function main() {
935
1034
  .requiredOption('--vault <string>', 'Vault address')
936
1035
  .action(async ({ vault }) => {
937
1036
  const env = initializeClient(false, false);
1037
+ const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
938
1038
 
939
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
1039
+ const kaminoManager = new KaminoManager(env.connection, slotDuration, env.kLendProgramId, env.kVaultProgramId);
940
1040
 
941
1041
  const vaultAddress = new PublicKey(vault);
942
1042
  const kaminoVault = new KaminoVault(vaultAddress, undefined, env.kVaultProgramId);
@@ -961,7 +1061,12 @@ async function main() {
961
1061
 
962
1062
  commands.command('get-oracle-mappings').action(async () => {
963
1063
  const env = initializeClient(false, false);
964
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
1064
+ const kaminoManager = new KaminoManager(
1065
+ env.connection,
1066
+ DEFAULT_RECENT_SLOT_DURATION_MS,
1067
+ env.kLendProgramId,
1068
+ env.kVaultProgramId
1069
+ );
965
1070
 
966
1071
  console.log('Getting oracle mappings');
967
1072
  const oracleConfigs = await kaminoManager.getScopeOracleConfigs();
@@ -970,15 +1075,21 @@ async function main() {
970
1075
 
971
1076
  commands.command('get-all-vaults').action(async () => {
972
1077
  const env = initializeClient(false, false);
973
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
1078
+ const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
974
1079
 
1080
+ const kaminoManager = new KaminoManager(env.connection, slotDuration, env.kLendProgramId, env.kVaultProgramId);
975
1081
  const allVaults = await kaminoManager.getAllVaults();
976
1082
  console.log('all vaults', allVaults);
977
1083
  });
978
1084
 
979
1085
  commands.command('get-all-vaults-pks').action(async () => {
980
1086
  const env = initializeClient(false, false);
981
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
1087
+ const kaminoManager = new KaminoManager(
1088
+ env.connection,
1089
+ DEFAULT_RECENT_SLOT_DURATION_MS,
1090
+ env.kLendProgramId,
1091
+ env.kVaultProgramId
1092
+ );
982
1093
 
983
1094
  const allVaults = await kaminoManager.getAllVaults();
984
1095
  console.log(
@@ -994,8 +1105,9 @@ async function main() {
994
1105
  const env = initializeClient(false, false);
995
1106
 
996
1107
  const vaultAddress = new PublicKey(vault);
1108
+ const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
997
1109
 
998
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
1110
+ const kaminoManager = new KaminoManager(env.connection, slotDuration, env.kLendProgramId, env.kVaultProgramId);
999
1111
  const vaultState = await new KaminoVault(vaultAddress, undefined, env.kVaultProgramId).getState(env.connection);
1000
1112
 
1001
1113
  const simulatedHoldings = await kaminoManager.calculateSimulatedHoldingsWithInterest(vaultState);
@@ -1036,8 +1148,9 @@ async function main() {
1036
1148
  const env = initializeClient(false, false);
1037
1149
 
1038
1150
  const vaultAddress = new PublicKey(vault);
1151
+ const slotDuration = await getMedianSlotDurationInMsFromLastEpochs();
1039
1152
 
1040
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
1153
+ const kaminoManager = new KaminoManager(env.connection, slotDuration, env.kLendProgramId, env.kVaultProgramId);
1041
1154
  const vaultState = await new KaminoVault(vaultAddress, undefined, env.kVaultProgramId).getState(env.connection);
1042
1155
 
1043
1156
  const computedAllocation = await kaminoManager.getVaultComputedReservesAllocation(vaultState);
@@ -1117,7 +1230,12 @@ async function main() {
1117
1230
  throw new Error('If using multisig mode, multisig is required');
1118
1231
  }
1119
1232
 
1120
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
1233
+ const kaminoManager = new KaminoManager(
1234
+ env.connection,
1235
+ DEFAULT_RECENT_SLOT_DURATION_MS,
1236
+ env.kLendProgramId,
1237
+ env.kVaultProgramId
1238
+ );
1121
1239
 
1122
1240
  const newLendingMarket = LendingMarket.fromJSON(JSON.parse(fs.readFileSync(lendingMarketConfigPath, 'utf8')));
1123
1241
 
@@ -1157,7 +1275,12 @@ async function main() {
1157
1275
  throw new Error('If using multisig mode, multisig is required');
1158
1276
  }
1159
1277
 
1160
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
1278
+ const kaminoManager = new KaminoManager(
1279
+ env.connection,
1280
+ DEFAULT_RECENT_SLOT_DURATION_MS,
1281
+ env.kLendProgramId,
1282
+ env.kVaultProgramId
1283
+ );
1161
1284
 
1162
1285
  const ixn = kaminoManager.updateLendingMarketOwnerIxs(marketWithAddress);
1163
1286
 
@@ -1195,7 +1318,12 @@ async function main() {
1195
1318
  throw new Error('If using multisig mode, multisig is required');
1196
1319
  }
1197
1320
 
1198
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
1321
+ const kaminoManager = new KaminoManager(
1322
+ env.connection,
1323
+ DEFAULT_RECENT_SLOT_DURATION_MS,
1324
+ env.kLendProgramId,
1325
+ env.kVaultProgramId
1326
+ );
1199
1327
 
1200
1328
  const currentName = parseZeroPaddedUtf8(lendingMarketState.name);
1201
1329
  const newNameEncoded = encodeTokenName(newName);
@@ -1251,7 +1379,12 @@ async function main() {
1251
1379
  throw new Error('If using multisig mode, multisig is required');
1252
1380
  }
1253
1381
 
1254
- const kaminoManager = new KaminoManager(env.connection, env.kLendProgramId, env.kVaultProgramId);
1382
+ const kaminoManager = new KaminoManager(
1383
+ env.connection,
1384
+ DEFAULT_RECENT_SLOT_DURATION_MS,
1385
+ env.kLendProgramId,
1386
+ env.kVaultProgramId
1387
+ );
1255
1388
 
1256
1389
  const newReserveConfigFields: ReserveConfigFields = {
1257
1390
  ...reserveState.config,
package/src/utils/ata.ts CHANGED
@@ -1,11 +1,22 @@
1
1
  import {
2
2
  ASSOCIATED_TOKEN_PROGRAM_ID,
3
+ NATIVE_MINT,
3
4
  TOKEN_PROGRAM_ID,
5
+ createAssociatedTokenAccountInstruction,
4
6
  createAssociatedTokenAccountIdempotentInstruction as createAtaIx,
7
+ createCloseAccountInstruction,
8
+ getAssociatedTokenAddressSync,
5
9
  } from '@solana/spl-token';
6
- import { ComputeBudgetProgram, Connection, PublicKey, SystemProgram, TransactionInstruction } from '@solana/web3.js';
10
+ import {
11
+ AccountInfo,
12
+ ComputeBudgetProgram,
13
+ Connection,
14
+ PublicKey,
15
+ SystemProgram,
16
+ TransactionInstruction,
17
+ } from '@solana/web3.js';
7
18
  import Decimal from 'decimal.js';
8
- import { AnchorProvider } from '@coral-xyz/anchor';
19
+ import { collToLamportsDecimal, DECIMALS_SOL } from '@kamino-finance/kliquidity-sdk/dist';
9
20
 
10
21
  /**
11
22
  * Create an idempotent create ATA instruction
@@ -144,8 +155,8 @@ export function removeBudgetAndAtaIxns(ixns: TransactionInstruction[], mints: st
144
155
  });
145
156
  }
146
157
 
147
- export async function getTokenAccountBalance(provider: AnchorProvider, tokenAccount: PublicKey): Promise<number> {
148
- const tokenAccountBalance = await provider.connection.getTokenAccountBalance(tokenAccount);
158
+ export async function getTokenAccountBalance(connection: Connection, tokenAccount: PublicKey): Promise<number> {
159
+ const tokenAccountBalance = await connection.getTokenAccountBalance(tokenAccount);
149
160
 
150
161
  return Number(tokenAccountBalance.value.amount).valueOf();
151
162
  }
@@ -165,3 +176,90 @@ export async function getTokenAccountBalanceDecimal(
165
176
  const { value } = await connection.getTokenAccountBalance(ata);
166
177
  return new Decimal(value.uiAmountString!);
167
178
  }
179
+
180
+ export type CreateWsolAtaIxs = {
181
+ wsolAta: PublicKey;
182
+ createAtaIxs: TransactionInstruction[];
183
+ closeAtaIxs: TransactionInstruction[];
184
+ };
185
+
186
+ /**
187
+ * Creates a wSOL ata if missing and syncs the balance. If the ata exists and it has more or equal no wrapping happens
188
+ * @param connection - Solana RPC connection (read)
189
+ * @param amount min amount to have in the wSOL ata. If the ata exists and it has more or equal no wrapping happens
190
+ * @param owner - owner of the ata
191
+ * @returns wsolAta: the keypair of the ata, used to sign the initialization transaction; createAtaIxs: a list with ixs to initialize the ata and wrap SOL if needed; closeAtaIxs: a list with ixs to close the ata
192
+ */
193
+ export const createWsolAtaIfMissing = async (
194
+ connection: Connection,
195
+ amount: Decimal,
196
+ owner: PublicKey
197
+ ): Promise<CreateWsolAtaIxs> => {
198
+ const createIxns: TransactionInstruction[] = [];
199
+ const closeIxns: TransactionInstruction[] = [];
200
+
201
+ const wsolAta: PublicKey = getAssociatedTokenAddressSync(NATIVE_MINT, owner, true, TOKEN_PROGRAM_ID);
202
+
203
+ const solDeposit = amount;
204
+ const wsolAtaAccountInfo: AccountInfo<Buffer> | null = await connection.getAccountInfo(wsolAta);
205
+
206
+ // This checks if we need to create it
207
+ if (isWsolInfoInvalid(wsolAtaAccountInfo)) {
208
+ createIxns.push(createAssociatedTokenAccountInstruction(owner, wsolAta, owner, NATIVE_MINT, TOKEN_PROGRAM_ID));
209
+ }
210
+
211
+ let wsolExistingBalanceLamports = new Decimal(0);
212
+ try {
213
+ if (wsolAtaAccountInfo != null) {
214
+ const uiAmount = (await getTokenAccountBalanceDecimal(connection, NATIVE_MINT, owner)).toNumber();
215
+ wsolExistingBalanceLamports = collToLamportsDecimal(new Decimal(uiAmount), DECIMALS_SOL);
216
+ }
217
+ } catch (err) {
218
+ console.log('Err Token Balance', err);
219
+ }
220
+
221
+ if (solDeposit !== null && solDeposit.gt(wsolExistingBalanceLamports)) {
222
+ createIxns.push(
223
+ SystemProgram.transfer({
224
+ fromPubkey: owner,
225
+ toPubkey: wsolAta,
226
+ lamports: BigInt(solDeposit.sub(wsolExistingBalanceLamports).floor().toString()),
227
+ })
228
+ );
229
+ }
230
+
231
+ if (createIxns.length > 0) {
232
+ // Primitive way of wrapping SOL
233
+ createIxns.push(
234
+ new TransactionInstruction({
235
+ keys: [
236
+ {
237
+ pubkey: wsolAta,
238
+ isSigner: false,
239
+ isWritable: true,
240
+ },
241
+ ],
242
+ data: Buffer.from(new Uint8Array([17])),
243
+ programId: TOKEN_PROGRAM_ID,
244
+ })
245
+ );
246
+ }
247
+
248
+ closeIxns.push(createCloseAccountInstruction(wsolAta, owner, owner, [], TOKEN_PROGRAM_ID));
249
+
250
+ return {
251
+ wsolAta,
252
+ createAtaIxs: createIxns,
253
+ closeAtaIxs: closeIxns,
254
+ };
255
+ };
256
+
257
+ export const isWsolInfoInvalid = (wsolAtaAccountInfo: any): boolean => {
258
+ const res =
259
+ wsolAtaAccountInfo === null ||
260
+ (wsolAtaAccountInfo !== null &&
261
+ wsolAtaAccountInfo.data.length === 0 &&
262
+ wsolAtaAccountInfo.owner.eq(PublicKey.default));
263
+
264
+ return res;
265
+ };
@@ -92,3 +92,5 @@ export const SOL_PADDING_FOR_INTEREST = new BN('1000000');
92
92
  */
93
93
  export const MIN_INITIAL_DEPOSIT = 100_000;
94
94
  export const MIN_VAULT_INITIAL_DEPOSIT = 1_000_000_000;
95
+
96
+ export const VAULT_INITIAL_DEPOSIT = 1000;