@ignitionfi/fogo-stake-pool 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AccountInfo, Connection, PublicKey, Signer, TransactionInstruction } from '@solana/web3.js';
2
2
  import BN from 'bn.js';
3
+ import { AmountInput } from './instructions';
3
4
  import { StakeAccount, StakePool, ValidatorList } from './layouts';
4
5
  import { ValidatorAccount } from './utils';
5
6
  export { DEVNET_STAKE_POOL_PROGRAM_ID, STAKE_POOL_PROGRAM_ID, } from './constants';
@@ -57,7 +58,7 @@ export declare function depositStake(connection: Connection, stakePoolAddress: P
57
58
  /**
58
59
  * Creates instructions required to deposit sol to stake pool.
59
60
  */
60
- export declare function depositWsolWithSession(connection: Connection, stakePoolAddress: PublicKey, signerOrSession: PublicKey, userPubkey: PublicKey, lamports: number, minimumPoolTokensOut?: number, destinationTokenAccount?: PublicKey, referrerTokenAccount?: PublicKey, depositAuthority?: PublicKey, payer?: PublicKey,
61
+ export declare function depositWsolWithSession(connection: Connection, stakePoolAddress: PublicKey, signerOrSession: PublicKey, userPubkey: PublicKey, lamports: AmountInput, minimumPoolTokensOut?: AmountInput, destinationTokenAccount?: PublicKey, referrerTokenAccount?: PublicKey, depositAuthority?: PublicKey, payer?: PublicKey,
61
62
  /**
62
63
  * Skip WSOL balance validation. Set to true when adding wrap instructions
63
64
  * in the same transaction that will fund the WSOL account before deposit.
@@ -69,7 +70,7 @@ skipBalanceCheck?: boolean): Promise<{
69
70
  /**
70
71
  * Creates instructions required to deposit sol to stake pool.
71
72
  */
72
- export declare function depositSol(connection: Connection, stakePoolAddress: PublicKey, from: PublicKey, lamports: number, destinationTokenAccount?: PublicKey, referrerTokenAccount?: PublicKey, depositAuthority?: PublicKey): Promise<{
73
+ export declare function depositSol(connection: Connection, stakePoolAddress: PublicKey, from: PublicKey, lamports: AmountInput, destinationTokenAccount?: PublicKey, referrerTokenAccount?: PublicKey, depositAuthority?: PublicKey): Promise<{
73
74
  instructions: TransactionInstruction[];
74
75
  signers: Signer[];
75
76
  }>;
@@ -173,13 +174,13 @@ export declare function removeValidatorFromPool(connection: Connection, stakePoo
173
174
  /**
174
175
  * Creates instructions required to increase validator stake.
175
176
  */
176
- export declare function increaseValidatorStake(connection: Connection, stakePoolAddress: PublicKey, validatorVote: PublicKey, lamports: number, ephemeralStakeSeed?: number): Promise<{
177
+ export declare function increaseValidatorStake(connection: Connection, stakePoolAddress: PublicKey, validatorVote: PublicKey, lamports: AmountInput, ephemeralStakeSeed?: number): Promise<{
177
178
  instructions: TransactionInstruction[];
178
179
  }>;
179
180
  /**
180
181
  * Creates instructions required to decrease validator stake.
181
182
  */
182
- export declare function decreaseValidatorStake(connection: Connection, stakePoolAddress: PublicKey, validatorVote: PublicKey, lamports: number, ephemeralStakeSeed?: number): Promise<{
183
+ export declare function decreaseValidatorStake(connection: Connection, stakePoolAddress: PublicKey, validatorVote: PublicKey, lamports: AmountInput, ephemeralStakeSeed?: number): Promise<{
183
184
  instructions: TransactionInstruction[];
184
185
  }>;
185
186
  /**
package/dist/index.esm.js CHANGED
@@ -438,6 +438,139 @@ const USER_STAKE_SEED_PREFIX = Buffer$1.from('user_stake');
438
438
  // for merges without a mismatch on credits observed
439
439
  const MINIMUM_ACTIVE_STAKE = 1000000;
440
440
 
441
+ /**
442
+ * BN-based layout for data decoding using buffer-layout.
443
+ * Used for decoding on-chain account data (StakePool, ValidatorList, etc.)
444
+ */
445
+ class BNDataLayout extends Layout {
446
+ constructor(span, signed, property) {
447
+ super(span, property);
448
+ this.blobLayout = blob(span);
449
+ this.signed = signed;
450
+ }
451
+ decode(b, offset = 0) {
452
+ const num = new BN(this.blobLayout.decode(b, offset), 10, 'le');
453
+ if (this.signed) {
454
+ return num.fromTwos(this.span * 8).clone();
455
+ }
456
+ return num;
457
+ }
458
+ encode(src, b, offset = 0) {
459
+ if (this.signed) {
460
+ src = src.toTwos(this.span * 8);
461
+ }
462
+ return this.blobLayout.encode(src.toArrayLike(Buffer, 'le', this.span), b, offset);
463
+ }
464
+ }
465
+ /**
466
+ * Creates a u64 layout for data decoding (account layouts).
467
+ * Used in StakePoolLayout, ValidatorListLayout, etc.
468
+ */
469
+ function u64(property) {
470
+ return new BNDataLayout(8, false, property);
471
+ }
472
+ /**
473
+ * BN-based layout for 64-bit unsigned integers using @solana/buffer-layout.
474
+ * Used for encoding instruction data with support for values > MAX_SAFE_INTEGER.
475
+ */
476
+ class BNInstructionLayout extends BufferLayout.Layout {
477
+ constructor(span, signed, property) {
478
+ super(span, property);
479
+ this.blobLayout = BufferLayout.blob(span);
480
+ this.signed = signed;
481
+ }
482
+ decode(b, offset = 0) {
483
+ const num = new BN(this.blobLayout.decode(b, offset), 10, 'le');
484
+ if (this.signed) {
485
+ return num.fromTwos(this.span * 8).clone();
486
+ }
487
+ return num;
488
+ }
489
+ encode(src, b, offset = 0) {
490
+ if (this.signed) {
491
+ src = src.toTwos(this.span * 8);
492
+ }
493
+ return this.blobLayout.encode(src.toArrayLike(Buffer, 'le', this.span), b, offset);
494
+ }
495
+ getSpan(_b, _offset) {
496
+ return this.span;
497
+ }
498
+ }
499
+ /**
500
+ * Creates a u64 layout for instruction encoding.
501
+ * Properly handles BN values larger than Number.MAX_SAFE_INTEGER.
502
+ * Compatible with @solana/buffer-layout.struct().
503
+ */
504
+ // eslint-disable-next-line ts/no-explicit-any
505
+ function u64Instruction(property) {
506
+ return new BNInstructionLayout(8, false, property);
507
+ }
508
+ class WrappedLayout extends Layout {
509
+ constructor(layout, decoder, encoder, property) {
510
+ super(layout.span, property);
511
+ this.layout = layout;
512
+ this.decoder = decoder;
513
+ this.encoder = encoder;
514
+ }
515
+ decode(b, offset) {
516
+ return this.decoder(this.layout.decode(b, offset));
517
+ }
518
+ encode(src, b, offset) {
519
+ return this.layout.encode(this.encoder(src), b, offset);
520
+ }
521
+ getSpan(b, offset) {
522
+ return this.layout.getSpan(b, offset);
523
+ }
524
+ }
525
+ function publicKey(property) {
526
+ return new WrappedLayout(blob(32), (b) => new PublicKey(b), (key) => key.toBuffer(), property);
527
+ }
528
+ class OptionLayout extends Layout {
529
+ constructor(layout, property) {
530
+ super(-1, property);
531
+ this.layout = layout;
532
+ this.discriminator = u8();
533
+ }
534
+ encode(src, b, offset = 0) {
535
+ if (src === null || src === undefined) {
536
+ return this.discriminator.encode(0, b, offset);
537
+ }
538
+ this.discriminator.encode(1, b, offset);
539
+ return this.layout.encode(src, b, offset + 1) + 1;
540
+ }
541
+ decode(b, offset = 0) {
542
+ const discriminator = this.discriminator.decode(b, offset);
543
+ if (discriminator === 0) {
544
+ return null;
545
+ }
546
+ else if (discriminator === 1) {
547
+ return this.layout.decode(b, offset + 1);
548
+ }
549
+ throw new Error(`Invalid option ${this.property}`);
550
+ }
551
+ getSpan(b, offset = 0) {
552
+ const discriminator = this.discriminator.decode(b, offset);
553
+ if (discriminator === 0) {
554
+ return 1;
555
+ }
556
+ else if (discriminator === 1) {
557
+ return this.layout.getSpan(b, offset + 1) + 1;
558
+ }
559
+ throw new Error(`Invalid option ${this.property}`);
560
+ }
561
+ }
562
+ function option(layout, property) {
563
+ return new OptionLayout(layout, property);
564
+ }
565
+ function vec(elementLayout, property) {
566
+ const length = u32('length');
567
+ const layout = struct([
568
+ length,
569
+ seq(elementLayout, offset(length, -length.span), 'values'),
570
+ ]);
571
+ return new WrappedLayout(layout, ({ values }) => values, values => ({ values }), property);
572
+ }
573
+
441
574
  /**
442
575
  * Populate a buffer of instruction data using an InstructionType
443
576
  * @internal
@@ -556,95 +689,6 @@ function findUserStakeProgramAddress(programId, userWallet, seed) {
556
689
  return publicKey;
557
690
  }
558
691
 
559
- class BNLayout extends Layout {
560
- constructor(span, signed, property) {
561
- super(span, property);
562
- this.blob = blob(span);
563
- this.signed = signed;
564
- }
565
- decode(b, offset = 0) {
566
- const num = new BN(this.blob.decode(b, offset), 10, 'le');
567
- if (this.signed) {
568
- return num.fromTwos(this.span * 8).clone();
569
- }
570
- return num;
571
- }
572
- encode(src, b, offset = 0) {
573
- if (this.signed) {
574
- src = src.toTwos(this.span * 8);
575
- }
576
- return this.blob.encode(src.toArrayLike(Buffer, 'le', this.span), b, offset);
577
- }
578
- }
579
- function u64(property) {
580
- return new BNLayout(8, false, property);
581
- }
582
- class WrappedLayout extends Layout {
583
- constructor(layout, decoder, encoder, property) {
584
- super(layout.span, property);
585
- this.layout = layout;
586
- this.decoder = decoder;
587
- this.encoder = encoder;
588
- }
589
- decode(b, offset) {
590
- return this.decoder(this.layout.decode(b, offset));
591
- }
592
- encode(src, b, offset) {
593
- return this.layout.encode(this.encoder(src), b, offset);
594
- }
595
- getSpan(b, offset) {
596
- return this.layout.getSpan(b, offset);
597
- }
598
- }
599
- function publicKey(property) {
600
- return new WrappedLayout(blob(32), (b) => new PublicKey(b), (key) => key.toBuffer(), property);
601
- }
602
- class OptionLayout extends Layout {
603
- constructor(layout, property) {
604
- super(-1, property);
605
- this.layout = layout;
606
- this.discriminator = u8();
607
- }
608
- encode(src, b, offset = 0) {
609
- if (src === null || src === undefined) {
610
- return this.discriminator.encode(0, b, offset);
611
- }
612
- this.discriminator.encode(1, b, offset);
613
- return this.layout.encode(src, b, offset + 1) + 1;
614
- }
615
- decode(b, offset = 0) {
616
- const discriminator = this.discriminator.decode(b, offset);
617
- if (discriminator === 0) {
618
- return null;
619
- }
620
- else if (discriminator === 1) {
621
- return this.layout.decode(b, offset + 1);
622
- }
623
- throw new Error(`Invalid option ${this.property}`);
624
- }
625
- getSpan(b, offset = 0) {
626
- const discriminator = this.discriminator.decode(b, offset);
627
- if (discriminator === 0) {
628
- return 1;
629
- }
630
- else if (discriminator === 1) {
631
- return this.layout.getSpan(b, offset + 1) + 1;
632
- }
633
- throw new Error(`Invalid option ${this.property}`);
634
- }
635
- }
636
- function option(layout, property) {
637
- return new OptionLayout(layout, property);
638
- }
639
- function vec(elementLayout, property) {
640
- const length = u32('length');
641
- const layout = struct([
642
- length,
643
- seq(elementLayout, offset(length, -length.span), 'values'),
644
- ]);
645
- return new WrappedLayout(layout, ({ values }) => values, values => ({ values }), property);
646
- }
647
-
648
692
  const feeFields = [u64('denominator'), u64('numerator')];
649
693
  var AccountType;
650
694
  (function (AccountType) {
@@ -987,11 +1031,50 @@ function arrayChunk(array, size) {
987
1031
  return result;
988
1032
  }
989
1033
 
1034
+ /**
1035
+ * Converts various numeric types to BN for safe large number handling.
1036
+ * @internal
1037
+ */
1038
+ function toBN(value) {
1039
+ if (BN.isBN(value)) {
1040
+ return value;
1041
+ }
1042
+ if (typeof value === 'bigint') {
1043
+ return new BN(value.toString());
1044
+ }
1045
+ if (typeof value === 'string') {
1046
+ // Validate string is a valid non-negative integer
1047
+ const trimmed = value.trim();
1048
+ if (!/^\d+$/.test(trimmed)) {
1049
+ throw new Error(`Invalid amount string: "${value}". Must be a non-negative integer.`);
1050
+ }
1051
+ return new BN(trimmed);
1052
+ }
1053
+ if (typeof value === 'number') {
1054
+ if (!Number.isFinite(value)) {
1055
+ throw new Error('Invalid amount: must be a finite number');
1056
+ }
1057
+ if (value < 0) {
1058
+ throw new Error('Invalid amount: must be non-negative');
1059
+ }
1060
+ if (!Number.isInteger(value)) {
1061
+ throw new Error('Invalid amount: must be an integer (lamports)');
1062
+ }
1063
+ // CRITICAL: Numbers > MAX_SAFE_INTEGER have already lost precision
1064
+ // We throw an error instead of silently corrupting data
1065
+ if (value > Number.MAX_SAFE_INTEGER) {
1066
+ throw new Error(`Amount ${value} exceeds Number.MAX_SAFE_INTEGER (9,007,199,254,740,991). ` +
1067
+ `Use BigInt or BN for large values to avoid precision loss.`);
1068
+ }
1069
+ return new BN(value);
1070
+ }
1071
+ throw new Error(`Invalid amount type: ${typeof value}`);
1072
+ }
990
1073
  // 'UpdateTokenMetadata' and 'CreateTokenMetadata' have dynamic layouts
991
1074
  const MOVE_STAKE_LAYOUT = BufferLayout.struct([
992
1075
  BufferLayout.u8('instruction'),
993
- BufferLayout.ns64('lamports'),
994
- BufferLayout.ns64('transientStakeSeed'),
1076
+ u64Instruction('lamports'),
1077
+ u64Instruction('transientStakeSeed'),
995
1078
  ]);
996
1079
  const UPDATE_VALIDATOR_LIST_BALANCE_LAYOUT = BufferLayout.struct([
997
1080
  BufferLayout.u8('instruction'),
@@ -1066,7 +1149,7 @@ const STAKE_POOL_INSTRUCTION_LAYOUTS = Object.freeze({
1066
1149
  index: 10,
1067
1150
  layout: BufferLayout.struct([
1068
1151
  BufferLayout.u8('instruction'),
1069
- BufferLayout.ns64('poolTokens'),
1152
+ u64Instruction('poolTokens'),
1070
1153
  ]),
1071
1154
  },
1072
1155
  /// Deposit SOL directly into the pool's reserve account. The output is a "pool" token
@@ -1075,7 +1158,7 @@ const STAKE_POOL_INSTRUCTION_LAYOUTS = Object.freeze({
1075
1158
  index: 14,
1076
1159
  layout: BufferLayout.struct([
1077
1160
  BufferLayout.u8('instruction'),
1078
- BufferLayout.ns64('lamports'),
1161
+ u64Instruction('lamports'),
1079
1162
  ]),
1080
1163
  },
1081
1164
  /// Withdraw SOL directly from the pool's reserve account. Fails if the
@@ -1084,25 +1167,25 @@ const STAKE_POOL_INSTRUCTION_LAYOUTS = Object.freeze({
1084
1167
  index: 16,
1085
1168
  layout: BufferLayout.struct([
1086
1169
  BufferLayout.u8('instruction'),
1087
- BufferLayout.ns64('poolTokens'),
1170
+ u64Instruction('poolTokens'),
1088
1171
  ]),
1089
1172
  },
1090
1173
  IncreaseAdditionalValidatorStake: {
1091
1174
  index: 19,
1092
1175
  layout: BufferLayout.struct([
1093
1176
  BufferLayout.u8('instruction'),
1094
- BufferLayout.ns64('lamports'),
1095
- BufferLayout.ns64('transientStakeSeed'),
1096
- BufferLayout.ns64('ephemeralStakeSeed'),
1177
+ u64Instruction('lamports'),
1178
+ u64Instruction('transientStakeSeed'),
1179
+ u64Instruction('ephemeralStakeSeed'),
1097
1180
  ]),
1098
1181
  },
1099
1182
  DecreaseAdditionalValidatorStake: {
1100
1183
  index: 20,
1101
1184
  layout: BufferLayout.struct([
1102
1185
  BufferLayout.u8('instruction'),
1103
- BufferLayout.ns64('lamports'),
1104
- BufferLayout.ns64('transientStakeSeed'),
1105
- BufferLayout.ns64('ephemeralStakeSeed'),
1186
+ u64Instruction('lamports'),
1187
+ u64Instruction('transientStakeSeed'),
1188
+ u64Instruction('ephemeralStakeSeed'),
1106
1189
  ]),
1107
1190
  },
1108
1191
  DecreaseValidatorStakeWithReserve: {
@@ -1117,62 +1200,62 @@ const STAKE_POOL_INSTRUCTION_LAYOUTS = Object.freeze({
1117
1200
  index: 23,
1118
1201
  layout: BufferLayout.struct([
1119
1202
  BufferLayout.u8('instruction'),
1120
- BufferLayout.ns64('lamports'),
1203
+ u64Instruction('lamports'),
1121
1204
  ]),
1122
1205
  },
1123
1206
  WithdrawStakeWithSlippage: {
1124
1207
  index: 24,
1125
1208
  layout: BufferLayout.struct([
1126
1209
  BufferLayout.u8('instruction'),
1127
- BufferLayout.ns64('poolTokensIn'),
1128
- BufferLayout.ns64('minimumLamportsOut'),
1210
+ u64Instruction('poolTokensIn'),
1211
+ u64Instruction('minimumLamportsOut'),
1129
1212
  ]),
1130
1213
  },
1131
1214
  DepositSolWithSlippage: {
1132
1215
  index: 25,
1133
1216
  layout: BufferLayout.struct([
1134
1217
  BufferLayout.u8('instruction'),
1135
- BufferLayout.ns64('lamports'),
1218
+ u64Instruction('lamports'),
1136
1219
  ]),
1137
1220
  },
1138
1221
  WithdrawSolWithSlippage: {
1139
1222
  index: 26,
1140
1223
  layout: BufferLayout.struct([
1141
1224
  BufferLayout.u8('instruction'),
1142
- BufferLayout.ns64('lamports'),
1225
+ u64Instruction('lamports'),
1143
1226
  ]),
1144
1227
  },
1145
1228
  DepositWsolWithSession: {
1146
1229
  index: 27,
1147
1230
  layout: BufferLayout.struct([
1148
1231
  BufferLayout.u8('instruction'),
1149
- BufferLayout.ns64('lamportsIn'),
1150
- BufferLayout.ns64('minimumPoolTokensOut'),
1232
+ u64Instruction('lamportsIn'),
1233
+ u64Instruction('minimumPoolTokensOut'),
1151
1234
  ]),
1152
1235
  },
1153
1236
  WithdrawWsolWithSession: {
1154
1237
  index: 28,
1155
1238
  layout: BufferLayout.struct([
1156
1239
  BufferLayout.u8('instruction'),
1157
- BufferLayout.ns64('poolTokensIn'),
1158
- BufferLayout.ns64('minimumLamportsOut'),
1240
+ u64Instruction('poolTokensIn'),
1241
+ u64Instruction('minimumLamportsOut'),
1159
1242
  ]),
1160
1243
  },
1161
1244
  WithdrawStakeWithSession: {
1162
1245
  index: 29,
1163
1246
  layout: BufferLayout.struct([
1164
1247
  BufferLayout.u8('instruction'),
1165
- BufferLayout.ns64('poolTokensIn'),
1166
- BufferLayout.ns64('minimumLamportsOut'),
1167
- BufferLayout.ns64('userStakeSeed'),
1248
+ u64Instruction('poolTokensIn'),
1249
+ u64Instruction('minimumLamportsOut'),
1250
+ u64Instruction('userStakeSeed'),
1168
1251
  ]),
1169
1252
  },
1170
1253
  WithdrawFromStakeAccountWithSession: {
1171
1254
  index: 30,
1172
1255
  layout: BufferLayout.struct([
1173
1256
  BufferLayout.u8('instruction'),
1174
- BufferLayout.ns64('lamports'),
1175
- BufferLayout.ns64('userStakeSeed'),
1257
+ u64Instruction('lamports'),
1258
+ u64Instruction('userStakeSeed'),
1176
1259
  ]),
1177
1260
  },
1178
1261
  });
@@ -1304,7 +1387,10 @@ class StakePoolInstruction {
1304
1387
  static increaseValidatorStake(params) {
1305
1388
  const { programId, stakePool, staker, withdrawAuthority, validatorList, reserveStake, transientStake, validatorStake, validatorVote, lamports, transientStakeSeed, } = params;
1306
1389
  const type = STAKE_POOL_INSTRUCTION_LAYOUTS.IncreaseValidatorStake;
1307
- const data = encodeData(type, { lamports, transientStakeSeed });
1390
+ const data = encodeData(type, {
1391
+ lamports: toBN(lamports),
1392
+ transientStakeSeed: toBN(transientStakeSeed),
1393
+ });
1308
1394
  const keys = [
1309
1395
  { pubkey: stakePool, isSigner: false, isWritable: false },
1310
1396
  { pubkey: staker, isSigner: true, isWritable: false },
@@ -1334,7 +1420,11 @@ class StakePoolInstruction {
1334
1420
  static increaseAdditionalValidatorStake(params) {
1335
1421
  const { programId, stakePool, staker, withdrawAuthority, validatorList, reserveStake, transientStake, validatorStake, validatorVote, lamports, transientStakeSeed, ephemeralStake, ephemeralStakeSeed, } = params;
1336
1422
  const type = STAKE_POOL_INSTRUCTION_LAYOUTS.IncreaseAdditionalValidatorStake;
1337
- const data = encodeData(type, { lamports, transientStakeSeed, ephemeralStakeSeed });
1423
+ const data = encodeData(type, {
1424
+ lamports: toBN(lamports),
1425
+ transientStakeSeed: toBN(transientStakeSeed),
1426
+ ephemeralStakeSeed: toBN(ephemeralStakeSeed),
1427
+ });
1338
1428
  const keys = [
1339
1429
  { pubkey: stakePool, isSigner: false, isWritable: false },
1340
1430
  { pubkey: staker, isSigner: true, isWritable: false },
@@ -1364,7 +1454,10 @@ class StakePoolInstruction {
1364
1454
  static decreaseValidatorStake(params) {
1365
1455
  const { programId, stakePool, staker, withdrawAuthority, validatorList, validatorStake, transientStake, lamports, transientStakeSeed, } = params;
1366
1456
  const type = STAKE_POOL_INSTRUCTION_LAYOUTS.DecreaseValidatorStake;
1367
- const data = encodeData(type, { lamports, transientStakeSeed });
1457
+ const data = encodeData(type, {
1458
+ lamports: toBN(lamports),
1459
+ transientStakeSeed: toBN(transientStakeSeed),
1460
+ });
1368
1461
  const keys = [
1369
1462
  { pubkey: stakePool, isSigner: false, isWritable: false },
1370
1463
  { pubkey: staker, isSigner: true, isWritable: false },
@@ -1390,7 +1483,10 @@ class StakePoolInstruction {
1390
1483
  static decreaseValidatorStakeWithReserve(params) {
1391
1484
  const { programId, stakePool, staker, withdrawAuthority, validatorList, reserveStake, validatorStake, transientStake, lamports, transientStakeSeed, } = params;
1392
1485
  const type = STAKE_POOL_INSTRUCTION_LAYOUTS.DecreaseValidatorStakeWithReserve;
1393
- const data = encodeData(type, { lamports, transientStakeSeed });
1486
+ const data = encodeData(type, {
1487
+ lamports: toBN(lamports),
1488
+ transientStakeSeed: toBN(transientStakeSeed),
1489
+ });
1394
1490
  const keys = [
1395
1491
  { pubkey: stakePool, isSigner: false, isWritable: false },
1396
1492
  { pubkey: staker, isSigner: true, isWritable: false },
@@ -1417,7 +1513,11 @@ class StakePoolInstruction {
1417
1513
  static decreaseAdditionalValidatorStake(params) {
1418
1514
  const { programId, stakePool, staker, withdrawAuthority, validatorList, reserveStake, validatorStake, transientStake, lamports, transientStakeSeed, ephemeralStakeSeed, ephemeralStake, } = params;
1419
1515
  const type = STAKE_POOL_INSTRUCTION_LAYOUTS.DecreaseAdditionalValidatorStake;
1420
- const data = encodeData(type, { lamports, transientStakeSeed, ephemeralStakeSeed });
1516
+ const data = encodeData(type, {
1517
+ lamports: toBN(lamports),
1518
+ transientStakeSeed: toBN(transientStakeSeed),
1519
+ ephemeralStakeSeed: toBN(ephemeralStakeSeed),
1520
+ });
1421
1521
  const keys = [
1422
1522
  { pubkey: stakePool, isSigner: false, isWritable: false },
1423
1523
  { pubkey: staker, isSigner: true, isWritable: false },
@@ -1474,7 +1574,7 @@ class StakePoolInstruction {
1474
1574
  static depositSol(params) {
1475
1575
  const { programId, stakePool, withdrawAuthority, depositAuthority, reserveStake, fundingAccount, destinationPoolAccount, managerFeeAccount, referralPoolAccount, poolMint, lamports, } = params;
1476
1576
  const type = STAKE_POOL_INSTRUCTION_LAYOUTS.DepositSol;
1477
- const data = encodeData(type, { lamports });
1577
+ const data = encodeData(type, { lamports: toBN(lamports) });
1478
1578
  const keys = [
1479
1579
  { pubkey: stakePool, isSigner: false, isWritable: true },
1480
1580
  { pubkey: withdrawAuthority, isSigner: false, isWritable: false },
@@ -1507,8 +1607,8 @@ class StakePoolInstruction {
1507
1607
  var _a;
1508
1608
  const type = STAKE_POOL_INSTRUCTION_LAYOUTS.DepositWsolWithSession;
1509
1609
  const data = encodeData(type, {
1510
- lamportsIn: params.lamportsIn,
1511
- minimumPoolTokensOut: params.minimumPoolTokensOut,
1610
+ lamportsIn: toBN(params.lamportsIn),
1611
+ minimumPoolTokensOut: toBN(params.minimumPoolTokensOut),
1512
1612
  });
1513
1613
  const keys = [
1514
1614
  { pubkey: params.stakePool, isSigner: false, isWritable: true },
@@ -1550,7 +1650,7 @@ class StakePoolInstruction {
1550
1650
  static withdrawStake(params) {
1551
1651
  const { programId, stakePool, validatorList, withdrawAuthority, validatorStake, destinationStake, destinationStakeAuthority, sourceTransferAuthority, sourcePoolAccount, managerFeeAccount, poolMint, poolTokens, } = params;
1552
1652
  const type = STAKE_POOL_INSTRUCTION_LAYOUTS.WithdrawStake;
1553
- const data = encodeData(type, { poolTokens });
1653
+ const data = encodeData(type, { poolTokens: toBN(poolTokens) });
1554
1654
  const keys = [
1555
1655
  { pubkey: stakePool, isSigner: false, isWritable: true },
1556
1656
  { pubkey: validatorList, isSigner: false, isWritable: true },
@@ -1578,7 +1678,7 @@ class StakePoolInstruction {
1578
1678
  static withdrawSol(params) {
1579
1679
  const { programId, stakePool, withdrawAuthority, sourceTransferAuthority, sourcePoolAccount, reserveStake, destinationSystemAccount, managerFeeAccount, solWithdrawAuthority, poolMint, poolTokens, } = params;
1580
1680
  const type = STAKE_POOL_INSTRUCTION_LAYOUTS.WithdrawSol;
1581
- const data = encodeData(type, { poolTokens });
1681
+ const data = encodeData(type, { poolTokens: toBN(poolTokens) });
1582
1682
  const keys = [
1583
1683
  { pubkey: stakePool, isSigner: false, isWritable: true },
1584
1684
  { pubkey: withdrawAuthority, isSigner: false, isWritable: false },
@@ -1613,8 +1713,8 @@ class StakePoolInstruction {
1613
1713
  static withdrawWsolWithSession(params) {
1614
1714
  const type = STAKE_POOL_INSTRUCTION_LAYOUTS.WithdrawWsolWithSession;
1615
1715
  const data = encodeData(type, {
1616
- poolTokensIn: params.poolTokensIn,
1617
- minimumLamportsOut: params.minimumLamportsOut,
1716
+ poolTokensIn: toBN(params.poolTokensIn),
1717
+ minimumLamportsOut: toBN(params.minimumLamportsOut),
1618
1718
  });
1619
1719
  const keys = [
1620
1720
  { pubkey: params.stakePool, isSigner: false, isWritable: true },
@@ -1656,9 +1756,9 @@ class StakePoolInstruction {
1656
1756
  static withdrawStakeWithSession(params) {
1657
1757
  const type = STAKE_POOL_INSTRUCTION_LAYOUTS.WithdrawStakeWithSession;
1658
1758
  const data = encodeData(type, {
1659
- poolTokensIn: params.poolTokensIn,
1660
- minimumLamportsOut: params.minimumLamportsOut,
1661
- userStakeSeed: params.userStakeSeed,
1759
+ poolTokensIn: toBN(params.poolTokensIn),
1760
+ minimumLamportsOut: toBN(params.minimumLamportsOut),
1761
+ userStakeSeed: toBN(params.userStakeSeed),
1662
1762
  });
1663
1763
  const keys = [
1664
1764
  { pubkey: params.stakePool, isSigner: false, isWritable: true },
@@ -1693,8 +1793,8 @@ class StakePoolInstruction {
1693
1793
  static withdrawFromStakeAccountWithSession(params) {
1694
1794
  const type = STAKE_POOL_INSTRUCTION_LAYOUTS.WithdrawFromStakeAccountWithSession;
1695
1795
  const data = encodeData(type, {
1696
- lamports: params.lamports,
1697
- userStakeSeed: params.userStakeSeed,
1796
+ lamports: toBN(params.lamports),
1797
+ userStakeSeed: toBN(params.userStakeSeed),
1698
1798
  });
1699
1799
  const keys = [
1700
1800
  { pubkey: params.userStakeAccount, isSigner: false, isWritable: true },
@@ -1983,10 +2083,18 @@ skipBalanceCheck = false) {
1983
2083
  if (!skipBalanceCheck) {
1984
2084
  const tokenAccountInfo = await connection.getTokenAccountBalance(wsolTokenAccount, 'confirmed');
1985
2085
  const wsolBalance = tokenAccountInfo
1986
- ? parseInt(tokenAccountInfo.value.amount)
1987
- : 0;
1988
- if (wsolBalance < lamports) {
1989
- throw new Error(`Not enough WSOL to deposit into pool. Maximum deposit amount is ${lamportsToSol(wsolBalance)} WSOL.`);
2086
+ ? BigInt(tokenAccountInfo.value.amount)
2087
+ : BigInt(0);
2088
+ // Convert lamports to BigInt for comparison
2089
+ const lamportsBigInt = typeof lamports === 'bigint'
2090
+ ? lamports
2091
+ : typeof lamports === 'string'
2092
+ ? BigInt(lamports)
2093
+ : BN.isBN(lamports)
2094
+ ? BigInt(lamports.toString())
2095
+ : BigInt(lamports);
2096
+ if (wsolBalance < lamportsBigInt) {
2097
+ throw new Error(`Not enough WSOL to deposit into pool. Maximum deposit amount is ${lamportsToSol(Number(wsolBalance))} WSOL.`);
1990
2098
  }
1991
2099
  }
1992
2100
  const stakePoolAccount = await getStakePoolAccount(connection, stakePoolAddress);
@@ -2032,7 +2140,15 @@ skipBalanceCheck = false) {
2032
2140
  */
2033
2141
  async function depositSol(connection, stakePoolAddress, from, lamports, destinationTokenAccount, referrerTokenAccount, depositAuthority) {
2034
2142
  const fromBalance = await connection.getBalance(from, 'confirmed');
2035
- if (fromBalance < lamports) {
2143
+ // Convert lamports to BigInt for comparison
2144
+ const lamportsBigInt = typeof lamports === 'bigint'
2145
+ ? lamports
2146
+ : typeof lamports === 'string'
2147
+ ? BigInt(lamports)
2148
+ : BN.isBN(lamports)
2149
+ ? BigInt(lamports.toString())
2150
+ : BigInt(lamports);
2151
+ if (BigInt(fromBalance) < lamportsBigInt) {
2036
2152
  throw new Error(`Not enough SOL to deposit into pool. Maximum deposit amount is ${lamportsToSol(fromBalance)} SOL.`);
2037
2153
  }
2038
2154
  const stakePoolAccount = await getStakePoolAccount(connection, stakePoolAddress);
@@ -2046,7 +2162,7 @@ async function depositSol(connection, stakePoolAddress, from, lamports, destinat
2046
2162
  instructions.push(SystemProgram.transfer({
2047
2163
  fromPubkey: from,
2048
2164
  toPubkey: userSolTransfer.publicKey,
2049
- lamports,
2165
+ lamports: lamportsBigInt,
2050
2166
  }));
2051
2167
  // Create token account if not specified
2052
2168
  if (!destinationTokenAccount) {