@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/codecs.d.ts +10 -0
- package/dist/index.browser.cjs.js +253 -137
- package/dist/index.browser.cjs.js.map +1 -1
- package/dist/index.browser.esm.js +253 -137
- package/dist/index.browser.esm.js.map +1 -1
- package/dist/index.cjs.js +253 -137
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.esm.js +253 -137
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +287 -171
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/instructions.d.ts +28 -19
- package/package.json +1 -1
- package/src/codecs.ts +59 -6
- package/src/index.ts +32 -13
- package/src/instructions.ts +132 -61
package/dist/index.iife.js
CHANGED
|
@@ -19026,124 +19026,6 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
19026
19026
|
// for merges without a mismatch on credits observed
|
|
19027
19027
|
const MINIMUM_ACTIVE_STAKE = 1000000;
|
|
19028
19028
|
|
|
19029
|
-
/**
|
|
19030
|
-
* Populate a buffer of instruction data using an InstructionType
|
|
19031
|
-
* @internal
|
|
19032
|
-
*/
|
|
19033
|
-
function encodeData(type, fields) {
|
|
19034
|
-
const allocLength = type.layout.span;
|
|
19035
|
-
const data = node_buffer.Buffer.alloc(allocLength);
|
|
19036
|
-
const layoutFields = Object.assign({ instruction: type.index }, fields);
|
|
19037
|
-
type.layout.encode(layoutFields, data);
|
|
19038
|
-
return data;
|
|
19039
|
-
}
|
|
19040
|
-
/**
|
|
19041
|
-
* Decode instruction data buffer using an InstructionType
|
|
19042
|
-
* @internal
|
|
19043
|
-
*/
|
|
19044
|
-
function decodeData(type, buffer) {
|
|
19045
|
-
let data;
|
|
19046
|
-
try {
|
|
19047
|
-
data = type.layout.decode(buffer);
|
|
19048
|
-
}
|
|
19049
|
-
catch (err) {
|
|
19050
|
-
throw new Error(`invalid instruction; ${err}`);
|
|
19051
|
-
}
|
|
19052
|
-
if (data.instruction !== type.index) {
|
|
19053
|
-
throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
|
|
19054
|
-
}
|
|
19055
|
-
return data;
|
|
19056
|
-
}
|
|
19057
|
-
|
|
19058
|
-
function solToLamports(amount) {
|
|
19059
|
-
if (isNaN(amount)) {
|
|
19060
|
-
return Number(0);
|
|
19061
|
-
}
|
|
19062
|
-
return Number(amount * LAMPORTS_PER_SOL);
|
|
19063
|
-
}
|
|
19064
|
-
function lamportsToSol(lamports) {
|
|
19065
|
-
if (typeof lamports === 'number') {
|
|
19066
|
-
return Math.abs(lamports) / LAMPORTS_PER_SOL;
|
|
19067
|
-
}
|
|
19068
|
-
if (typeof lamports === 'bigint') {
|
|
19069
|
-
return Math.abs(Number(lamports)) / LAMPORTS_PER_SOL;
|
|
19070
|
-
}
|
|
19071
|
-
let signMultiplier = 1;
|
|
19072
|
-
if (lamports.isNeg()) {
|
|
19073
|
-
signMultiplier = -1;
|
|
19074
|
-
}
|
|
19075
|
-
const absLamports = lamports.abs();
|
|
19076
|
-
const lamportsString = absLamports.toString(10).padStart(10, '0');
|
|
19077
|
-
const splitIndex = lamportsString.length - 9;
|
|
19078
|
-
const solString = `${lamportsString.slice(0, splitIndex)}.${lamportsString.slice(splitIndex)}`;
|
|
19079
|
-
return signMultiplier * Number.parseFloat(solString);
|
|
19080
|
-
}
|
|
19081
|
-
|
|
19082
|
-
/**
|
|
19083
|
-
* Generates the wSOL transient program address for the stake pool
|
|
19084
|
-
*/
|
|
19085
|
-
function findWsolTransientProgramAddress(programId, userPubkey) {
|
|
19086
|
-
const [publicKey] = PublicKey.findProgramAddressSync([node_buffer.Buffer.from('transient_wsol'), userPubkey.toBuffer()], programId);
|
|
19087
|
-
return publicKey;
|
|
19088
|
-
}
|
|
19089
|
-
/**
|
|
19090
|
-
* Generates the withdraw authority program address for the stake pool
|
|
19091
|
-
*/
|
|
19092
|
-
async function findWithdrawAuthorityProgramAddress(programId, stakePoolAddress) {
|
|
19093
|
-
const [publicKey] = PublicKey.findProgramAddressSync([stakePoolAddress.toBuffer(), node_buffer.Buffer.from('withdraw')], programId);
|
|
19094
|
-
return publicKey;
|
|
19095
|
-
}
|
|
19096
|
-
/**
|
|
19097
|
-
* Generates the stake program address for a validator's vote account
|
|
19098
|
-
*/
|
|
19099
|
-
async function findStakeProgramAddress(programId, voteAccountAddress, stakePoolAddress, seed) {
|
|
19100
|
-
const [publicKey] = PublicKey.findProgramAddressSync([
|
|
19101
|
-
voteAccountAddress.toBuffer(),
|
|
19102
|
-
stakePoolAddress.toBuffer(),
|
|
19103
|
-
seed ? new BN(seed).toArrayLike(node_buffer.Buffer, 'le', 4) : node_buffer.Buffer.alloc(0),
|
|
19104
|
-
], programId);
|
|
19105
|
-
return publicKey;
|
|
19106
|
-
}
|
|
19107
|
-
/**
|
|
19108
|
-
* Generates the stake program address for a validator's vote account
|
|
19109
|
-
*/
|
|
19110
|
-
async function findTransientStakeProgramAddress(programId, voteAccountAddress, stakePoolAddress, seed) {
|
|
19111
|
-
const [publicKey] = PublicKey.findProgramAddressSync([
|
|
19112
|
-
TRANSIENT_STAKE_SEED_PREFIX,
|
|
19113
|
-
voteAccountAddress.toBuffer(),
|
|
19114
|
-
stakePoolAddress.toBuffer(),
|
|
19115
|
-
seed.toArrayLike(node_buffer.Buffer, 'le', 8),
|
|
19116
|
-
], programId);
|
|
19117
|
-
return publicKey;
|
|
19118
|
-
}
|
|
19119
|
-
/**
|
|
19120
|
-
* Generates the ephemeral program address for stake pool redelegation
|
|
19121
|
-
*/
|
|
19122
|
-
async function findEphemeralStakeProgramAddress(programId, stakePoolAddress, seed) {
|
|
19123
|
-
const [publicKey] = PublicKey.findProgramAddressSync([EPHEMERAL_STAKE_SEED_PREFIX, stakePoolAddress.toBuffer(), seed.toArrayLike(node_buffer.Buffer, 'le', 8)], programId);
|
|
19124
|
-
return publicKey;
|
|
19125
|
-
}
|
|
19126
|
-
/**
|
|
19127
|
-
* Generates the metadata program address for the stake pool
|
|
19128
|
-
*/
|
|
19129
|
-
function findMetadataAddress(stakePoolMintAddress) {
|
|
19130
|
-
const [publicKey] = PublicKey.findProgramAddressSync([node_buffer.Buffer.from('metadata'), METADATA_PROGRAM_ID.toBuffer(), stakePoolMintAddress.toBuffer()], METADATA_PROGRAM_ID);
|
|
19131
|
-
return publicKey;
|
|
19132
|
-
}
|
|
19133
|
-
/**
|
|
19134
|
-
* Generates the user stake account PDA for session-based withdrawals.
|
|
19135
|
-
* The PDA is derived from the user's wallet and a unique seed.
|
|
19136
|
-
*/
|
|
19137
|
-
function findUserStakeProgramAddress(programId, userWallet, seed) {
|
|
19138
|
-
const seedBN = typeof seed === 'number' ? new BN(seed) : seed;
|
|
19139
|
-
const [publicKey] = PublicKey.findProgramAddressSync([
|
|
19140
|
-
USER_STAKE_SEED_PREFIX,
|
|
19141
|
-
userWallet.toBuffer(),
|
|
19142
|
-
seedBN.toArrayLike(node_buffer.Buffer, 'le', 8),
|
|
19143
|
-
], programId);
|
|
19144
|
-
return publicKey;
|
|
19145
|
-
}
|
|
19146
|
-
|
|
19147
19029
|
var Layout = {};
|
|
19148
19030
|
|
|
19149
19031
|
/* The MIT License (MIT)
|
|
@@ -21758,14 +21640,18 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
21758
21640
|
|
|
21759
21641
|
var LayoutExports = /*@__PURE__*/ requireLayout();
|
|
21760
21642
|
|
|
21761
|
-
|
|
21643
|
+
/**
|
|
21644
|
+
* BN-based layout for data decoding using buffer-layout.
|
|
21645
|
+
* Used for decoding on-chain account data (StakePool, ValidatorList, etc.)
|
|
21646
|
+
*/
|
|
21647
|
+
class BNDataLayout extends LayoutExports.Layout {
|
|
21762
21648
|
constructor(span, signed, property) {
|
|
21763
21649
|
super(span, property);
|
|
21764
|
-
this.
|
|
21650
|
+
this.blobLayout = LayoutExports.blob(span);
|
|
21765
21651
|
this.signed = signed;
|
|
21766
21652
|
}
|
|
21767
21653
|
decode(b, offset = 0) {
|
|
21768
|
-
const num = new BN(this.
|
|
21654
|
+
const num = new BN(this.blobLayout.decode(b, offset), 10, 'le');
|
|
21769
21655
|
if (this.signed) {
|
|
21770
21656
|
return num.fromTwos(this.span * 8).clone();
|
|
21771
21657
|
}
|
|
@@ -21775,11 +21661,51 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
21775
21661
|
if (this.signed) {
|
|
21776
21662
|
src = src.toTwos(this.span * 8);
|
|
21777
21663
|
}
|
|
21778
|
-
return this.
|
|
21664
|
+
return this.blobLayout.encode(src.toArrayLike(Buffer, 'le', this.span), b, offset);
|
|
21779
21665
|
}
|
|
21780
21666
|
}
|
|
21667
|
+
/**
|
|
21668
|
+
* Creates a u64 layout for data decoding (account layouts).
|
|
21669
|
+
* Used in StakePoolLayout, ValidatorListLayout, etc.
|
|
21670
|
+
*/
|
|
21781
21671
|
function u64(property) {
|
|
21782
|
-
return new
|
|
21672
|
+
return new BNDataLayout(8, false, property);
|
|
21673
|
+
}
|
|
21674
|
+
/**
|
|
21675
|
+
* BN-based layout for 64-bit unsigned integers using @solana/buffer-layout.
|
|
21676
|
+
* Used for encoding instruction data with support for values > MAX_SAFE_INTEGER.
|
|
21677
|
+
*/
|
|
21678
|
+
class BNInstructionLayout extends LayoutExports$1.Layout {
|
|
21679
|
+
constructor(span, signed, property) {
|
|
21680
|
+
super(span, property);
|
|
21681
|
+
this.blobLayout = LayoutExports$1.blob(span);
|
|
21682
|
+
this.signed = signed;
|
|
21683
|
+
}
|
|
21684
|
+
decode(b, offset = 0) {
|
|
21685
|
+
const num = new BN(this.blobLayout.decode(b, offset), 10, 'le');
|
|
21686
|
+
if (this.signed) {
|
|
21687
|
+
return num.fromTwos(this.span * 8).clone();
|
|
21688
|
+
}
|
|
21689
|
+
return num;
|
|
21690
|
+
}
|
|
21691
|
+
encode(src, b, offset = 0) {
|
|
21692
|
+
if (this.signed) {
|
|
21693
|
+
src = src.toTwos(this.span * 8);
|
|
21694
|
+
}
|
|
21695
|
+
return this.blobLayout.encode(src.toArrayLike(Buffer, 'le', this.span), b, offset);
|
|
21696
|
+
}
|
|
21697
|
+
getSpan(_b, _offset) {
|
|
21698
|
+
return this.span;
|
|
21699
|
+
}
|
|
21700
|
+
}
|
|
21701
|
+
/**
|
|
21702
|
+
* Creates a u64 layout for instruction encoding.
|
|
21703
|
+
* Properly handles BN values larger than Number.MAX_SAFE_INTEGER.
|
|
21704
|
+
* Compatible with @solana/buffer-layout.struct().
|
|
21705
|
+
*/
|
|
21706
|
+
// eslint-disable-next-line ts/no-explicit-any
|
|
21707
|
+
function u64Instruction(property) {
|
|
21708
|
+
return new BNInstructionLayout(8, false, property);
|
|
21783
21709
|
}
|
|
21784
21710
|
class WrappedLayout extends LayoutExports.Layout {
|
|
21785
21711
|
constructor(layout, decoder, encoder, property) {
|
|
@@ -21847,6 +21773,124 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
21847
21773
|
return new WrappedLayout(layout, ({ values }) => values, values => ({ values }), property);
|
|
21848
21774
|
}
|
|
21849
21775
|
|
|
21776
|
+
/**
|
|
21777
|
+
* Populate a buffer of instruction data using an InstructionType
|
|
21778
|
+
* @internal
|
|
21779
|
+
*/
|
|
21780
|
+
function encodeData(type, fields) {
|
|
21781
|
+
const allocLength = type.layout.span;
|
|
21782
|
+
const data = node_buffer.Buffer.alloc(allocLength);
|
|
21783
|
+
const layoutFields = Object.assign({ instruction: type.index }, fields);
|
|
21784
|
+
type.layout.encode(layoutFields, data);
|
|
21785
|
+
return data;
|
|
21786
|
+
}
|
|
21787
|
+
/**
|
|
21788
|
+
* Decode instruction data buffer using an InstructionType
|
|
21789
|
+
* @internal
|
|
21790
|
+
*/
|
|
21791
|
+
function decodeData(type, buffer) {
|
|
21792
|
+
let data;
|
|
21793
|
+
try {
|
|
21794
|
+
data = type.layout.decode(buffer);
|
|
21795
|
+
}
|
|
21796
|
+
catch (err) {
|
|
21797
|
+
throw new Error(`invalid instruction; ${err}`);
|
|
21798
|
+
}
|
|
21799
|
+
if (data.instruction !== type.index) {
|
|
21800
|
+
throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
|
|
21801
|
+
}
|
|
21802
|
+
return data;
|
|
21803
|
+
}
|
|
21804
|
+
|
|
21805
|
+
function solToLamports(amount) {
|
|
21806
|
+
if (isNaN(amount)) {
|
|
21807
|
+
return Number(0);
|
|
21808
|
+
}
|
|
21809
|
+
return Number(amount * LAMPORTS_PER_SOL);
|
|
21810
|
+
}
|
|
21811
|
+
function lamportsToSol(lamports) {
|
|
21812
|
+
if (typeof lamports === 'number') {
|
|
21813
|
+
return Math.abs(lamports) / LAMPORTS_PER_SOL;
|
|
21814
|
+
}
|
|
21815
|
+
if (typeof lamports === 'bigint') {
|
|
21816
|
+
return Math.abs(Number(lamports)) / LAMPORTS_PER_SOL;
|
|
21817
|
+
}
|
|
21818
|
+
let signMultiplier = 1;
|
|
21819
|
+
if (lamports.isNeg()) {
|
|
21820
|
+
signMultiplier = -1;
|
|
21821
|
+
}
|
|
21822
|
+
const absLamports = lamports.abs();
|
|
21823
|
+
const lamportsString = absLamports.toString(10).padStart(10, '0');
|
|
21824
|
+
const splitIndex = lamportsString.length - 9;
|
|
21825
|
+
const solString = `${lamportsString.slice(0, splitIndex)}.${lamportsString.slice(splitIndex)}`;
|
|
21826
|
+
return signMultiplier * Number.parseFloat(solString);
|
|
21827
|
+
}
|
|
21828
|
+
|
|
21829
|
+
/**
|
|
21830
|
+
* Generates the wSOL transient program address for the stake pool
|
|
21831
|
+
*/
|
|
21832
|
+
function findWsolTransientProgramAddress(programId, userPubkey) {
|
|
21833
|
+
const [publicKey] = PublicKey.findProgramAddressSync([node_buffer.Buffer.from('transient_wsol'), userPubkey.toBuffer()], programId);
|
|
21834
|
+
return publicKey;
|
|
21835
|
+
}
|
|
21836
|
+
/**
|
|
21837
|
+
* Generates the withdraw authority program address for the stake pool
|
|
21838
|
+
*/
|
|
21839
|
+
async function findWithdrawAuthorityProgramAddress(programId, stakePoolAddress) {
|
|
21840
|
+
const [publicKey] = PublicKey.findProgramAddressSync([stakePoolAddress.toBuffer(), node_buffer.Buffer.from('withdraw')], programId);
|
|
21841
|
+
return publicKey;
|
|
21842
|
+
}
|
|
21843
|
+
/**
|
|
21844
|
+
* Generates the stake program address for a validator's vote account
|
|
21845
|
+
*/
|
|
21846
|
+
async function findStakeProgramAddress(programId, voteAccountAddress, stakePoolAddress, seed) {
|
|
21847
|
+
const [publicKey] = PublicKey.findProgramAddressSync([
|
|
21848
|
+
voteAccountAddress.toBuffer(),
|
|
21849
|
+
stakePoolAddress.toBuffer(),
|
|
21850
|
+
seed ? new BN(seed).toArrayLike(node_buffer.Buffer, 'le', 4) : node_buffer.Buffer.alloc(0),
|
|
21851
|
+
], programId);
|
|
21852
|
+
return publicKey;
|
|
21853
|
+
}
|
|
21854
|
+
/**
|
|
21855
|
+
* Generates the stake program address for a validator's vote account
|
|
21856
|
+
*/
|
|
21857
|
+
async function findTransientStakeProgramAddress(programId, voteAccountAddress, stakePoolAddress, seed) {
|
|
21858
|
+
const [publicKey] = PublicKey.findProgramAddressSync([
|
|
21859
|
+
TRANSIENT_STAKE_SEED_PREFIX,
|
|
21860
|
+
voteAccountAddress.toBuffer(),
|
|
21861
|
+
stakePoolAddress.toBuffer(),
|
|
21862
|
+
seed.toArrayLike(node_buffer.Buffer, 'le', 8),
|
|
21863
|
+
], programId);
|
|
21864
|
+
return publicKey;
|
|
21865
|
+
}
|
|
21866
|
+
/**
|
|
21867
|
+
* Generates the ephemeral program address for stake pool redelegation
|
|
21868
|
+
*/
|
|
21869
|
+
async function findEphemeralStakeProgramAddress(programId, stakePoolAddress, seed) {
|
|
21870
|
+
const [publicKey] = PublicKey.findProgramAddressSync([EPHEMERAL_STAKE_SEED_PREFIX, stakePoolAddress.toBuffer(), seed.toArrayLike(node_buffer.Buffer, 'le', 8)], programId);
|
|
21871
|
+
return publicKey;
|
|
21872
|
+
}
|
|
21873
|
+
/**
|
|
21874
|
+
* Generates the metadata program address for the stake pool
|
|
21875
|
+
*/
|
|
21876
|
+
function findMetadataAddress(stakePoolMintAddress) {
|
|
21877
|
+
const [publicKey] = PublicKey.findProgramAddressSync([node_buffer.Buffer.from('metadata'), METADATA_PROGRAM_ID.toBuffer(), stakePoolMintAddress.toBuffer()], METADATA_PROGRAM_ID);
|
|
21878
|
+
return publicKey;
|
|
21879
|
+
}
|
|
21880
|
+
/**
|
|
21881
|
+
* Generates the user stake account PDA for session-based withdrawals.
|
|
21882
|
+
* The PDA is derived from the user's wallet and a unique seed.
|
|
21883
|
+
*/
|
|
21884
|
+
function findUserStakeProgramAddress(programId, userWallet, seed) {
|
|
21885
|
+
const seedBN = typeof seed === 'number' ? new BN(seed) : seed;
|
|
21886
|
+
const [publicKey] = PublicKey.findProgramAddressSync([
|
|
21887
|
+
USER_STAKE_SEED_PREFIX,
|
|
21888
|
+
userWallet.toBuffer(),
|
|
21889
|
+
seedBN.toArrayLike(node_buffer.Buffer, 'le', 8),
|
|
21890
|
+
], programId);
|
|
21891
|
+
return publicKey;
|
|
21892
|
+
}
|
|
21893
|
+
|
|
21850
21894
|
const feeFields = [u64('denominator'), u64('numerator')];
|
|
21851
21895
|
var AccountType;
|
|
21852
21896
|
(function (AccountType) {
|
|
@@ -22189,11 +22233,50 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22189
22233
|
return result;
|
|
22190
22234
|
}
|
|
22191
22235
|
|
|
22236
|
+
/**
|
|
22237
|
+
* Converts various numeric types to BN for safe large number handling.
|
|
22238
|
+
* @internal
|
|
22239
|
+
*/
|
|
22240
|
+
function toBN(value) {
|
|
22241
|
+
if (BN.isBN(value)) {
|
|
22242
|
+
return value;
|
|
22243
|
+
}
|
|
22244
|
+
if (typeof value === 'bigint') {
|
|
22245
|
+
return new BN(value.toString());
|
|
22246
|
+
}
|
|
22247
|
+
if (typeof value === 'string') {
|
|
22248
|
+
// Validate string is a valid non-negative integer
|
|
22249
|
+
const trimmed = value.trim();
|
|
22250
|
+
if (!/^\d+$/.test(trimmed)) {
|
|
22251
|
+
throw new Error(`Invalid amount string: "${value}". Must be a non-negative integer.`);
|
|
22252
|
+
}
|
|
22253
|
+
return new BN(trimmed);
|
|
22254
|
+
}
|
|
22255
|
+
if (typeof value === 'number') {
|
|
22256
|
+
if (!Number.isFinite(value)) {
|
|
22257
|
+
throw new Error('Invalid amount: must be a finite number');
|
|
22258
|
+
}
|
|
22259
|
+
if (value < 0) {
|
|
22260
|
+
throw new Error('Invalid amount: must be non-negative');
|
|
22261
|
+
}
|
|
22262
|
+
if (!Number.isInteger(value)) {
|
|
22263
|
+
throw new Error('Invalid amount: must be an integer (lamports)');
|
|
22264
|
+
}
|
|
22265
|
+
// CRITICAL: Numbers > MAX_SAFE_INTEGER have already lost precision
|
|
22266
|
+
// We throw an error instead of silently corrupting data
|
|
22267
|
+
if (value > Number.MAX_SAFE_INTEGER) {
|
|
22268
|
+
throw new Error(`Amount ${value} exceeds Number.MAX_SAFE_INTEGER (9,007,199,254,740,991). ` +
|
|
22269
|
+
`Use BigInt or BN for large values to avoid precision loss.`);
|
|
22270
|
+
}
|
|
22271
|
+
return new BN(value);
|
|
22272
|
+
}
|
|
22273
|
+
throw new Error(`Invalid amount type: ${typeof value}`);
|
|
22274
|
+
}
|
|
22192
22275
|
// 'UpdateTokenMetadata' and 'CreateTokenMetadata' have dynamic layouts
|
|
22193
22276
|
const MOVE_STAKE_LAYOUT = LayoutExports$1.struct([
|
|
22194
22277
|
LayoutExports$1.u8('instruction'),
|
|
22195
|
-
|
|
22196
|
-
|
|
22278
|
+
u64Instruction('lamports'),
|
|
22279
|
+
u64Instruction('transientStakeSeed'),
|
|
22197
22280
|
]);
|
|
22198
22281
|
const UPDATE_VALIDATOR_LIST_BALANCE_LAYOUT = LayoutExports$1.struct([
|
|
22199
22282
|
LayoutExports$1.u8('instruction'),
|
|
@@ -22268,7 +22351,7 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22268
22351
|
index: 10,
|
|
22269
22352
|
layout: LayoutExports$1.struct([
|
|
22270
22353
|
LayoutExports$1.u8('instruction'),
|
|
22271
|
-
|
|
22354
|
+
u64Instruction('poolTokens'),
|
|
22272
22355
|
]),
|
|
22273
22356
|
},
|
|
22274
22357
|
/// Deposit SOL directly into the pool's reserve account. The output is a "pool" token
|
|
@@ -22277,7 +22360,7 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22277
22360
|
index: 14,
|
|
22278
22361
|
layout: LayoutExports$1.struct([
|
|
22279
22362
|
LayoutExports$1.u8('instruction'),
|
|
22280
|
-
|
|
22363
|
+
u64Instruction('lamports'),
|
|
22281
22364
|
]),
|
|
22282
22365
|
},
|
|
22283
22366
|
/// Withdraw SOL directly from the pool's reserve account. Fails if the
|
|
@@ -22286,25 +22369,25 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22286
22369
|
index: 16,
|
|
22287
22370
|
layout: LayoutExports$1.struct([
|
|
22288
22371
|
LayoutExports$1.u8('instruction'),
|
|
22289
|
-
|
|
22372
|
+
u64Instruction('poolTokens'),
|
|
22290
22373
|
]),
|
|
22291
22374
|
},
|
|
22292
22375
|
IncreaseAdditionalValidatorStake: {
|
|
22293
22376
|
index: 19,
|
|
22294
22377
|
layout: LayoutExports$1.struct([
|
|
22295
22378
|
LayoutExports$1.u8('instruction'),
|
|
22296
|
-
|
|
22297
|
-
|
|
22298
|
-
|
|
22379
|
+
u64Instruction('lamports'),
|
|
22380
|
+
u64Instruction('transientStakeSeed'),
|
|
22381
|
+
u64Instruction('ephemeralStakeSeed'),
|
|
22299
22382
|
]),
|
|
22300
22383
|
},
|
|
22301
22384
|
DecreaseAdditionalValidatorStake: {
|
|
22302
22385
|
index: 20,
|
|
22303
22386
|
layout: LayoutExports$1.struct([
|
|
22304
22387
|
LayoutExports$1.u8('instruction'),
|
|
22305
|
-
|
|
22306
|
-
|
|
22307
|
-
|
|
22388
|
+
u64Instruction('lamports'),
|
|
22389
|
+
u64Instruction('transientStakeSeed'),
|
|
22390
|
+
u64Instruction('ephemeralStakeSeed'),
|
|
22308
22391
|
]),
|
|
22309
22392
|
},
|
|
22310
22393
|
DecreaseValidatorStakeWithReserve: {
|
|
@@ -22319,62 +22402,62 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22319
22402
|
index: 23,
|
|
22320
22403
|
layout: LayoutExports$1.struct([
|
|
22321
22404
|
LayoutExports$1.u8('instruction'),
|
|
22322
|
-
|
|
22405
|
+
u64Instruction('lamports'),
|
|
22323
22406
|
]),
|
|
22324
22407
|
},
|
|
22325
22408
|
WithdrawStakeWithSlippage: {
|
|
22326
22409
|
index: 24,
|
|
22327
22410
|
layout: LayoutExports$1.struct([
|
|
22328
22411
|
LayoutExports$1.u8('instruction'),
|
|
22329
|
-
|
|
22330
|
-
|
|
22412
|
+
u64Instruction('poolTokensIn'),
|
|
22413
|
+
u64Instruction('minimumLamportsOut'),
|
|
22331
22414
|
]),
|
|
22332
22415
|
},
|
|
22333
22416
|
DepositSolWithSlippage: {
|
|
22334
22417
|
index: 25,
|
|
22335
22418
|
layout: LayoutExports$1.struct([
|
|
22336
22419
|
LayoutExports$1.u8('instruction'),
|
|
22337
|
-
|
|
22420
|
+
u64Instruction('lamports'),
|
|
22338
22421
|
]),
|
|
22339
22422
|
},
|
|
22340
22423
|
WithdrawSolWithSlippage: {
|
|
22341
22424
|
index: 26,
|
|
22342
22425
|
layout: LayoutExports$1.struct([
|
|
22343
22426
|
LayoutExports$1.u8('instruction'),
|
|
22344
|
-
|
|
22427
|
+
u64Instruction('lamports'),
|
|
22345
22428
|
]),
|
|
22346
22429
|
},
|
|
22347
22430
|
DepositWsolWithSession: {
|
|
22348
22431
|
index: 27,
|
|
22349
22432
|
layout: LayoutExports$1.struct([
|
|
22350
22433
|
LayoutExports$1.u8('instruction'),
|
|
22351
|
-
|
|
22352
|
-
|
|
22434
|
+
u64Instruction('lamportsIn'),
|
|
22435
|
+
u64Instruction('minimumPoolTokensOut'),
|
|
22353
22436
|
]),
|
|
22354
22437
|
},
|
|
22355
22438
|
WithdrawWsolWithSession: {
|
|
22356
22439
|
index: 28,
|
|
22357
22440
|
layout: LayoutExports$1.struct([
|
|
22358
22441
|
LayoutExports$1.u8('instruction'),
|
|
22359
|
-
|
|
22360
|
-
|
|
22442
|
+
u64Instruction('poolTokensIn'),
|
|
22443
|
+
u64Instruction('minimumLamportsOut'),
|
|
22361
22444
|
]),
|
|
22362
22445
|
},
|
|
22363
22446
|
WithdrawStakeWithSession: {
|
|
22364
22447
|
index: 29,
|
|
22365
22448
|
layout: LayoutExports$1.struct([
|
|
22366
22449
|
LayoutExports$1.u8('instruction'),
|
|
22367
|
-
|
|
22368
|
-
|
|
22369
|
-
|
|
22450
|
+
u64Instruction('poolTokensIn'),
|
|
22451
|
+
u64Instruction('minimumLamportsOut'),
|
|
22452
|
+
u64Instruction('userStakeSeed'),
|
|
22370
22453
|
]),
|
|
22371
22454
|
},
|
|
22372
22455
|
WithdrawFromStakeAccountWithSession: {
|
|
22373
22456
|
index: 30,
|
|
22374
22457
|
layout: LayoutExports$1.struct([
|
|
22375
22458
|
LayoutExports$1.u8('instruction'),
|
|
22376
|
-
|
|
22377
|
-
|
|
22459
|
+
u64Instruction('lamports'),
|
|
22460
|
+
u64Instruction('userStakeSeed'),
|
|
22378
22461
|
]),
|
|
22379
22462
|
},
|
|
22380
22463
|
});
|
|
@@ -22506,7 +22589,10 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22506
22589
|
static increaseValidatorStake(params) {
|
|
22507
22590
|
const { programId, stakePool, staker, withdrawAuthority, validatorList, reserveStake, transientStake, validatorStake, validatorVote, lamports, transientStakeSeed, } = params;
|
|
22508
22591
|
const type = STAKE_POOL_INSTRUCTION_LAYOUTS.IncreaseValidatorStake;
|
|
22509
|
-
const data = encodeData(type, {
|
|
22592
|
+
const data = encodeData(type, {
|
|
22593
|
+
lamports: toBN(lamports),
|
|
22594
|
+
transientStakeSeed: toBN(transientStakeSeed),
|
|
22595
|
+
});
|
|
22510
22596
|
const keys = [
|
|
22511
22597
|
{ pubkey: stakePool, isSigner: false, isWritable: false },
|
|
22512
22598
|
{ pubkey: staker, isSigner: true, isWritable: false },
|
|
@@ -22536,7 +22622,11 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22536
22622
|
static increaseAdditionalValidatorStake(params) {
|
|
22537
22623
|
const { programId, stakePool, staker, withdrawAuthority, validatorList, reserveStake, transientStake, validatorStake, validatorVote, lamports, transientStakeSeed, ephemeralStake, ephemeralStakeSeed, } = params;
|
|
22538
22624
|
const type = STAKE_POOL_INSTRUCTION_LAYOUTS.IncreaseAdditionalValidatorStake;
|
|
22539
|
-
const data = encodeData(type, {
|
|
22625
|
+
const data = encodeData(type, {
|
|
22626
|
+
lamports: toBN(lamports),
|
|
22627
|
+
transientStakeSeed: toBN(transientStakeSeed),
|
|
22628
|
+
ephemeralStakeSeed: toBN(ephemeralStakeSeed),
|
|
22629
|
+
});
|
|
22540
22630
|
const keys = [
|
|
22541
22631
|
{ pubkey: stakePool, isSigner: false, isWritable: false },
|
|
22542
22632
|
{ pubkey: staker, isSigner: true, isWritable: false },
|
|
@@ -22566,7 +22656,10 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22566
22656
|
static decreaseValidatorStake(params) {
|
|
22567
22657
|
const { programId, stakePool, staker, withdrawAuthority, validatorList, validatorStake, transientStake, lamports, transientStakeSeed, } = params;
|
|
22568
22658
|
const type = STAKE_POOL_INSTRUCTION_LAYOUTS.DecreaseValidatorStake;
|
|
22569
|
-
const data = encodeData(type, {
|
|
22659
|
+
const data = encodeData(type, {
|
|
22660
|
+
lamports: toBN(lamports),
|
|
22661
|
+
transientStakeSeed: toBN(transientStakeSeed),
|
|
22662
|
+
});
|
|
22570
22663
|
const keys = [
|
|
22571
22664
|
{ pubkey: stakePool, isSigner: false, isWritable: false },
|
|
22572
22665
|
{ pubkey: staker, isSigner: true, isWritable: false },
|
|
@@ -22592,7 +22685,10 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22592
22685
|
static decreaseValidatorStakeWithReserve(params) {
|
|
22593
22686
|
const { programId, stakePool, staker, withdrawAuthority, validatorList, reserveStake, validatorStake, transientStake, lamports, transientStakeSeed, } = params;
|
|
22594
22687
|
const type = STAKE_POOL_INSTRUCTION_LAYOUTS.DecreaseValidatorStakeWithReserve;
|
|
22595
|
-
const data = encodeData(type, {
|
|
22688
|
+
const data = encodeData(type, {
|
|
22689
|
+
lamports: toBN(lamports),
|
|
22690
|
+
transientStakeSeed: toBN(transientStakeSeed),
|
|
22691
|
+
});
|
|
22596
22692
|
const keys = [
|
|
22597
22693
|
{ pubkey: stakePool, isSigner: false, isWritable: false },
|
|
22598
22694
|
{ pubkey: staker, isSigner: true, isWritable: false },
|
|
@@ -22619,7 +22715,11 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22619
22715
|
static decreaseAdditionalValidatorStake(params) {
|
|
22620
22716
|
const { programId, stakePool, staker, withdrawAuthority, validatorList, reserveStake, validatorStake, transientStake, lamports, transientStakeSeed, ephemeralStakeSeed, ephemeralStake, } = params;
|
|
22621
22717
|
const type = STAKE_POOL_INSTRUCTION_LAYOUTS.DecreaseAdditionalValidatorStake;
|
|
22622
|
-
const data = encodeData(type, {
|
|
22718
|
+
const data = encodeData(type, {
|
|
22719
|
+
lamports: toBN(lamports),
|
|
22720
|
+
transientStakeSeed: toBN(transientStakeSeed),
|
|
22721
|
+
ephemeralStakeSeed: toBN(ephemeralStakeSeed),
|
|
22722
|
+
});
|
|
22623
22723
|
const keys = [
|
|
22624
22724
|
{ pubkey: stakePool, isSigner: false, isWritable: false },
|
|
22625
22725
|
{ pubkey: staker, isSigner: true, isWritable: false },
|
|
@@ -22676,7 +22776,7 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22676
22776
|
static depositSol(params) {
|
|
22677
22777
|
const { programId, stakePool, withdrawAuthority, depositAuthority, reserveStake, fundingAccount, destinationPoolAccount, managerFeeAccount, referralPoolAccount, poolMint, lamports, } = params;
|
|
22678
22778
|
const type = STAKE_POOL_INSTRUCTION_LAYOUTS.DepositSol;
|
|
22679
|
-
const data = encodeData(type, { lamports });
|
|
22779
|
+
const data = encodeData(type, { lamports: toBN(lamports) });
|
|
22680
22780
|
const keys = [
|
|
22681
22781
|
{ pubkey: stakePool, isSigner: false, isWritable: true },
|
|
22682
22782
|
{ pubkey: withdrawAuthority, isSigner: false, isWritable: false },
|
|
@@ -22709,8 +22809,8 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22709
22809
|
var _a;
|
|
22710
22810
|
const type = STAKE_POOL_INSTRUCTION_LAYOUTS.DepositWsolWithSession;
|
|
22711
22811
|
const data = encodeData(type, {
|
|
22712
|
-
lamportsIn: params.lamportsIn,
|
|
22713
|
-
minimumPoolTokensOut: params.minimumPoolTokensOut,
|
|
22812
|
+
lamportsIn: toBN(params.lamportsIn),
|
|
22813
|
+
minimumPoolTokensOut: toBN(params.minimumPoolTokensOut),
|
|
22714
22814
|
});
|
|
22715
22815
|
const keys = [
|
|
22716
22816
|
{ pubkey: params.stakePool, isSigner: false, isWritable: true },
|
|
@@ -22752,7 +22852,7 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22752
22852
|
static withdrawStake(params) {
|
|
22753
22853
|
const { programId, stakePool, validatorList, withdrawAuthority, validatorStake, destinationStake, destinationStakeAuthority, sourceTransferAuthority, sourcePoolAccount, managerFeeAccount, poolMint, poolTokens, } = params;
|
|
22754
22854
|
const type = STAKE_POOL_INSTRUCTION_LAYOUTS.WithdrawStake;
|
|
22755
|
-
const data = encodeData(type, { poolTokens });
|
|
22855
|
+
const data = encodeData(type, { poolTokens: toBN(poolTokens) });
|
|
22756
22856
|
const keys = [
|
|
22757
22857
|
{ pubkey: stakePool, isSigner: false, isWritable: true },
|
|
22758
22858
|
{ pubkey: validatorList, isSigner: false, isWritable: true },
|
|
@@ -22780,7 +22880,7 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22780
22880
|
static withdrawSol(params) {
|
|
22781
22881
|
const { programId, stakePool, withdrawAuthority, sourceTransferAuthority, sourcePoolAccount, reserveStake, destinationSystemAccount, managerFeeAccount, solWithdrawAuthority, poolMint, poolTokens, } = params;
|
|
22782
22882
|
const type = STAKE_POOL_INSTRUCTION_LAYOUTS.WithdrawSol;
|
|
22783
|
-
const data = encodeData(type, { poolTokens });
|
|
22883
|
+
const data = encodeData(type, { poolTokens: toBN(poolTokens) });
|
|
22784
22884
|
const keys = [
|
|
22785
22885
|
{ pubkey: stakePool, isSigner: false, isWritable: true },
|
|
22786
22886
|
{ pubkey: withdrawAuthority, isSigner: false, isWritable: false },
|
|
@@ -22815,8 +22915,8 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22815
22915
|
static withdrawWsolWithSession(params) {
|
|
22816
22916
|
const type = STAKE_POOL_INSTRUCTION_LAYOUTS.WithdrawWsolWithSession;
|
|
22817
22917
|
const data = encodeData(type, {
|
|
22818
|
-
poolTokensIn: params.poolTokensIn,
|
|
22819
|
-
minimumLamportsOut: params.minimumLamportsOut,
|
|
22918
|
+
poolTokensIn: toBN(params.poolTokensIn),
|
|
22919
|
+
minimumLamportsOut: toBN(params.minimumLamportsOut),
|
|
22820
22920
|
});
|
|
22821
22921
|
const keys = [
|
|
22822
22922
|
{ pubkey: params.stakePool, isSigner: false, isWritable: true },
|
|
@@ -22858,9 +22958,9 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22858
22958
|
static withdrawStakeWithSession(params) {
|
|
22859
22959
|
const type = STAKE_POOL_INSTRUCTION_LAYOUTS.WithdrawStakeWithSession;
|
|
22860
22960
|
const data = encodeData(type, {
|
|
22861
|
-
poolTokensIn: params.poolTokensIn,
|
|
22862
|
-
minimumLamportsOut: params.minimumLamportsOut,
|
|
22863
|
-
userStakeSeed: params.userStakeSeed,
|
|
22961
|
+
poolTokensIn: toBN(params.poolTokensIn),
|
|
22962
|
+
minimumLamportsOut: toBN(params.minimumLamportsOut),
|
|
22963
|
+
userStakeSeed: toBN(params.userStakeSeed),
|
|
22864
22964
|
});
|
|
22865
22965
|
const keys = [
|
|
22866
22966
|
{ pubkey: params.stakePool, isSigner: false, isWritable: true },
|
|
@@ -22895,8 +22995,8 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
22895
22995
|
static withdrawFromStakeAccountWithSession(params) {
|
|
22896
22996
|
const type = STAKE_POOL_INSTRUCTION_LAYOUTS.WithdrawFromStakeAccountWithSession;
|
|
22897
22997
|
const data = encodeData(type, {
|
|
22898
|
-
lamports: params.lamports,
|
|
22899
|
-
userStakeSeed: params.userStakeSeed,
|
|
22998
|
+
lamports: toBN(params.lamports),
|
|
22999
|
+
userStakeSeed: toBN(params.userStakeSeed),
|
|
22900
23000
|
});
|
|
22901
23001
|
const keys = [
|
|
22902
23002
|
{ pubkey: params.userStakeAccount, isSigner: false, isWritable: true },
|
|
@@ -23185,10 +23285,18 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
23185
23285
|
if (!skipBalanceCheck) {
|
|
23186
23286
|
const tokenAccountInfo = await connection.getTokenAccountBalance(wsolTokenAccount, 'confirmed');
|
|
23187
23287
|
const wsolBalance = tokenAccountInfo
|
|
23188
|
-
?
|
|
23189
|
-
: 0;
|
|
23190
|
-
|
|
23191
|
-
|
|
23288
|
+
? BigInt(tokenAccountInfo.value.amount)
|
|
23289
|
+
: BigInt(0);
|
|
23290
|
+
// Convert lamports to BigInt for comparison
|
|
23291
|
+
const lamportsBigInt = typeof lamports === 'bigint'
|
|
23292
|
+
? lamports
|
|
23293
|
+
: typeof lamports === 'string'
|
|
23294
|
+
? BigInt(lamports)
|
|
23295
|
+
: BN.isBN(lamports)
|
|
23296
|
+
? BigInt(lamports.toString())
|
|
23297
|
+
: BigInt(lamports);
|
|
23298
|
+
if (wsolBalance < lamportsBigInt) {
|
|
23299
|
+
throw new Error(`Not enough WSOL to deposit into pool. Maximum deposit amount is ${lamportsToSol(Number(wsolBalance))} WSOL.`);
|
|
23192
23300
|
}
|
|
23193
23301
|
}
|
|
23194
23302
|
const stakePoolAccount = await getStakePoolAccount(connection, stakePoolAddress);
|
|
@@ -23234,7 +23342,15 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
23234
23342
|
*/
|
|
23235
23343
|
async function depositSol(connection, stakePoolAddress, from, lamports, destinationTokenAccount, referrerTokenAccount, depositAuthority) {
|
|
23236
23344
|
const fromBalance = await connection.getBalance(from, 'confirmed');
|
|
23237
|
-
|
|
23345
|
+
// Convert lamports to BigInt for comparison
|
|
23346
|
+
const lamportsBigInt = typeof lamports === 'bigint'
|
|
23347
|
+
? lamports
|
|
23348
|
+
: typeof lamports === 'string'
|
|
23349
|
+
? BigInt(lamports)
|
|
23350
|
+
: BN.isBN(lamports)
|
|
23351
|
+
? BigInt(lamports.toString())
|
|
23352
|
+
: BigInt(lamports);
|
|
23353
|
+
if (BigInt(fromBalance) < lamportsBigInt) {
|
|
23238
23354
|
throw new Error(`Not enough SOL to deposit into pool. Maximum deposit amount is ${lamportsToSol(fromBalance)} SOL.`);
|
|
23239
23355
|
}
|
|
23240
23356
|
const stakePoolAccount = await getStakePoolAccount(connection, stakePoolAddress);
|
|
@@ -23248,7 +23364,7 @@ var solanaStakePool = (function (exports, node_buffer) {
|
|
|
23248
23364
|
instructions.push(SystemProgram.transfer({
|
|
23249
23365
|
fromPubkey: from,
|
|
23250
23366
|
toPubkey: userSolTransfer.publicKey,
|
|
23251
|
-
lamports,
|
|
23367
|
+
lamports: lamportsBigInt,
|
|
23252
23368
|
}));
|
|
23253
23369
|
// Create token account if not specified
|
|
23254
23370
|
if (!destinationTokenAccount) {
|