@solana/client 1.0.0 → 1.1.1
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/README.md +192 -38
- package/dist/index.browser.cjs +668 -64
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +666 -67
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +666 -67
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +668 -64
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +666 -67
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/actions.d.ts +22 -1
- package/dist/types/actions.d.ts.map +1 -1
- package/dist/types/client/actions.d.ts.map +1 -1
- package/dist/types/client/createClient.d.ts.map +1 -1
- package/dist/types/client/createClientHelpers.d.ts.map +1 -1
- package/dist/types/controllers/stakeController.d.ts +37 -0
- package/dist/types/controllers/stakeController.d.ts.map +1 -0
- package/dist/types/features/stake.d.ts +115 -0
- package/dist/types/features/stake.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +35 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/wallet/standard.d.ts.map +1 -1
- package/package.json +3 -1
package/dist/index.browser.mjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { createSolanaRpc, createSolanaRpcSubscriptions, address, getBase64EncodedWireTransaction, compileTransaction, partiallySignTransactionMessageWithSigners, appendTransactionMessageInstruction, setTransactionMessageLifetimeUsingBlockhash, isTransactionSendingSigner, getMessagePackerInstructionPlanFromInstructions, signature, AccountRole, pipe, createTransactionMessage, setTransactionMessageFeePayer, singleTransactionPlan, signAndSendTransactionMessageWithSigners, createTransactionPlanExecutor, signTransactionMessageWithSigners, isSolanaError, SOLANA_ERROR__TRANSACTION_ERROR__ALREADY_PROCESSED, createTransactionPlanner, setTransactionMessageFeePayerSigner, isTransactionPartialSigner, SOLANA_ERROR__INSTRUCTION_ERROR__COMPUTATIONAL_BUDGET_EXCEEDED, isInstructionForProgram, isInstructionWithData, SolanaError, SOLANA_ERROR__INSTRUCTION_ERROR__GENERIC_ERROR, airdropFactory, signatureBytes } from '@solana/kit';
|
|
1
|
+
import { createSolanaRpc, createSolanaRpcSubscriptions, address, getBase64EncodedWireTransaction, compileTransaction, partiallySignTransactionMessageWithSigners, appendTransactionMessageInstruction, setTransactionMessageLifetimeUsingBlockhash, isTransactionSendingSigner, getMessagePackerInstructionPlanFromInstructions, signature, AccountRole, pipe, createTransactionMessage, setTransactionMessageFeePayer, singleTransactionPlan, signAndSendTransactionMessageWithSigners, createTransactionPlanExecutor, signTransactionMessageWithSigners, isSolanaError, SOLANA_ERROR__TRANSACTION_ERROR__ALREADY_PROCESSED, generateKeyPairSigner, appendTransactionMessageInstructions, createTransactionPlanner, setTransactionMessageFeePayerSigner, isTransactionPartialSigner, SOLANA_ERROR__INSTRUCTION_ERROR__COMPUTATIONAL_BUDGET_EXCEEDED, isInstructionForProgram, isInstructionWithData, SolanaError, SOLANA_ERROR__INSTRUCTION_ERROR__GENERIC_ERROR, isSome, airdropFactory, signatureBytes } from '@solana/kit';
|
|
2
2
|
import { createBlockHeightExceedencePromiseFactory, createRecentSignatureConfirmationPromiseFactory, waitForRecentTransactionConfirmation } from '@solana/transaction-confirmation';
|
|
3
|
+
import { fetchAddressLookupTable, fetchAllAddressLookupTable } from '@solana-program/address-lookup-table';
|
|
4
|
+
import { getTransferSolInstruction, getCreateAccountInstruction, fetchNonce } from '@solana-program/system';
|
|
3
5
|
import { getBase58Decoder, getBase58Encoder } from '@solana/codecs-strings';
|
|
4
|
-
import { getTransferSolInstruction } from '@solana-program/system';
|
|
5
6
|
import { TOKEN_PROGRAM_ADDRESS, fetchMint, findAssociatedTokenPda, getCreateAssociatedTokenInstruction, getTransferCheckedInstruction } from '@solana-program/token';
|
|
7
|
+
import { getInitializeInstruction, getDelegateStakeInstruction, getDeactivateInstruction, getWithdrawInstruction } from '@solana-program/stake';
|
|
6
8
|
import { getSetComputeUnitLimitInstruction, getSetComputeUnitPriceInstruction, COMPUTE_BUDGET_PROGRAM_ADDRESS, ComputeBudgetInstruction } from '@solana-program/compute-budget';
|
|
7
9
|
import { createStore } from 'zustand/vanilla';
|
|
8
10
|
import { getWallets } from '@wallet-standard/app';
|
|
9
|
-
import { StandardConnect, StandardDisconnect } from '@wallet-standard/features';
|
|
11
|
+
import { StandardConnect, StandardEvents, StandardDisconnect } from '@wallet-standard/features';
|
|
10
12
|
import { getTransactionDecoder, getTransactionEncoder } from '@solana/transactions';
|
|
11
13
|
import { SolanaSignMessage, SolanaSignTransaction, SolanaSignAndSendTransaction } from '@solana/wallet-standard-features';
|
|
12
14
|
|
|
@@ -30,6 +32,18 @@ function fetchBalance(client, params) {
|
|
|
30
32
|
return client.actions.fetchBalance(params.address, params.commitment);
|
|
31
33
|
}
|
|
32
34
|
__name(fetchBalance, "fetchBalance");
|
|
35
|
+
function fetchLookupTable(client, params) {
|
|
36
|
+
return client.actions.fetchLookupTable(params.address, params.commitment);
|
|
37
|
+
}
|
|
38
|
+
__name(fetchLookupTable, "fetchLookupTable");
|
|
39
|
+
function fetchLookupTables(client, params) {
|
|
40
|
+
return client.actions.fetchLookupTables(params.addresses, params.commitment);
|
|
41
|
+
}
|
|
42
|
+
__name(fetchLookupTables, "fetchLookupTables");
|
|
43
|
+
function fetchNonceAccount(client, params) {
|
|
44
|
+
return client.actions.fetchNonceAccount(params.address, params.commitment);
|
|
45
|
+
}
|
|
46
|
+
__name(fetchNonceAccount, "fetchNonceAccount");
|
|
33
47
|
function requestAirdrop(client, params) {
|
|
34
48
|
return client.actions.requestAirdrop(params.address, params.lamports);
|
|
35
49
|
}
|
|
@@ -377,6 +391,7 @@ function updateState(store, update) {
|
|
|
377
391
|
__name(updateState, "updateState");
|
|
378
392
|
function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
379
393
|
const logger = inputLogger ?? createLogger();
|
|
394
|
+
let walletEventsCleanup;
|
|
380
395
|
function getCommitment(commitment) {
|
|
381
396
|
return commitment ?? store.getState().cluster.commitment;
|
|
382
397
|
}
|
|
@@ -449,6 +464,8 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
449
464
|
}
|
|
450
465
|
__name(setCluster2, "setCluster");
|
|
451
466
|
async function connectWallet2(connectorId, options = {}) {
|
|
467
|
+
walletEventsCleanup?.();
|
|
468
|
+
walletEventsCleanup = void 0;
|
|
452
469
|
const connector = connectors.get(connectorId);
|
|
453
470
|
if (!connector) {
|
|
454
471
|
throw new Error(`No wallet connector registered for id "${connectorId}".`);
|
|
@@ -456,7 +473,7 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
456
473
|
if (!connector.isSupported()) {
|
|
457
474
|
throw new Error(`Wallet connector "${connectorId}" is not supported in this environment.`);
|
|
458
475
|
}
|
|
459
|
-
const autoConnectPreference = options.autoConnect ??
|
|
476
|
+
const autoConnectPreference = options.autoConnect ?? false;
|
|
460
477
|
store.setState((state) => ({
|
|
461
478
|
...state,
|
|
462
479
|
lastUpdatedAt: now(),
|
|
@@ -469,6 +486,15 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
469
486
|
lastUpdatedAt: now(),
|
|
470
487
|
wallet: { autoConnect: autoConnectPreference, connectorId, session, status: "connected" }
|
|
471
488
|
}));
|
|
489
|
+
if (session.onAccountsChanged) {
|
|
490
|
+
walletEventsCleanup = session.onAccountsChanged((accounts) => {
|
|
491
|
+
if (accounts.length === 0) {
|
|
492
|
+
walletEventsCleanup?.();
|
|
493
|
+
walletEventsCleanup = void 0;
|
|
494
|
+
void disconnectWallet3();
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
}
|
|
472
498
|
logger({
|
|
473
499
|
data: { address: session.account.address.toString(), connectorId },
|
|
474
500
|
level: "info",
|
|
@@ -494,6 +520,8 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
494
520
|
if (wallet.status === "disconnected") {
|
|
495
521
|
return;
|
|
496
522
|
}
|
|
523
|
+
walletEventsCleanup?.();
|
|
524
|
+
walletEventsCleanup = void 0;
|
|
497
525
|
try {
|
|
498
526
|
if (wallet.status === "connected") {
|
|
499
527
|
await wallet.session.disconnect();
|
|
@@ -512,14 +540,14 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
512
540
|
}
|
|
513
541
|
}
|
|
514
542
|
__name(disconnectWallet3, "disconnectWallet");
|
|
515
|
-
async function fetchBalance2(
|
|
516
|
-
const key =
|
|
543
|
+
async function fetchBalance2(address5, commitment) {
|
|
544
|
+
const key = address5.toString();
|
|
517
545
|
store.setState((state) => ({
|
|
518
546
|
...state,
|
|
519
547
|
accounts: {
|
|
520
548
|
...state.accounts,
|
|
521
549
|
[key]: {
|
|
522
|
-
address:
|
|
550
|
+
address: address5,
|
|
523
551
|
data: state.accounts[key]?.data,
|
|
524
552
|
error: void 0,
|
|
525
553
|
fetching: true,
|
|
@@ -531,14 +559,14 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
531
559
|
lastUpdatedAt: now()
|
|
532
560
|
}));
|
|
533
561
|
try {
|
|
534
|
-
const response = await runtime.rpc.getBalance(
|
|
562
|
+
const response = await runtime.rpc.getBalance(address5, { commitment: getCommitment(commitment) }).send({ abortSignal: AbortSignal.timeout(1e4) });
|
|
535
563
|
const lamports2 = response.value;
|
|
536
564
|
store.setState((state) => ({
|
|
537
565
|
...state,
|
|
538
566
|
accounts: {
|
|
539
567
|
...state.accounts,
|
|
540
568
|
[key]: {
|
|
541
|
-
address:
|
|
569
|
+
address: address5,
|
|
542
570
|
data: state.accounts[key]?.data,
|
|
543
571
|
error: void 0,
|
|
544
572
|
fetching: false,
|
|
@@ -556,7 +584,7 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
556
584
|
accounts: {
|
|
557
585
|
...state.accounts,
|
|
558
586
|
[key]: {
|
|
559
|
-
address:
|
|
587
|
+
address: address5,
|
|
560
588
|
data: state.accounts[key]?.data,
|
|
561
589
|
error,
|
|
562
590
|
fetching: false,
|
|
@@ -576,14 +604,14 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
576
604
|
}
|
|
577
605
|
}
|
|
578
606
|
__name(fetchBalance2, "fetchBalance");
|
|
579
|
-
async function fetchAccount2(
|
|
580
|
-
const key =
|
|
607
|
+
async function fetchAccount2(address5, commitment) {
|
|
608
|
+
const key = address5.toString();
|
|
581
609
|
store.setState((state) => ({
|
|
582
610
|
...state,
|
|
583
611
|
accounts: {
|
|
584
612
|
...state.accounts,
|
|
585
613
|
[key]: {
|
|
586
|
-
address:
|
|
614
|
+
address: address5,
|
|
587
615
|
data: state.accounts[key]?.data,
|
|
588
616
|
error: void 0,
|
|
589
617
|
fetching: true,
|
|
@@ -595,7 +623,7 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
595
623
|
lastUpdatedAt: now()
|
|
596
624
|
}));
|
|
597
625
|
try {
|
|
598
|
-
const response = await runtime.rpc.getAccountInfo(
|
|
626
|
+
const response = await runtime.rpc.getAccountInfo(address5, { commitment: getCommitment(commitment), encoding: "base64" }).send({ abortSignal: AbortSignal.timeout(1e4) });
|
|
599
627
|
const value = response.value;
|
|
600
628
|
const lamports2 = value?.lamports ?? null;
|
|
601
629
|
store.setState((state) => ({
|
|
@@ -603,7 +631,7 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
603
631
|
accounts: {
|
|
604
632
|
...state.accounts,
|
|
605
633
|
[key]: {
|
|
606
|
-
address:
|
|
634
|
+
address: address5,
|
|
607
635
|
data: value,
|
|
608
636
|
error: void 0,
|
|
609
637
|
fetching: false,
|
|
@@ -621,7 +649,7 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
621
649
|
accounts: {
|
|
622
650
|
...state.accounts,
|
|
623
651
|
[key]: {
|
|
624
|
-
address:
|
|
652
|
+
address: address5,
|
|
625
653
|
data: state.accounts[key]?.data,
|
|
626
654
|
error,
|
|
627
655
|
fetching: false,
|
|
@@ -641,14 +669,49 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
641
669
|
}
|
|
642
670
|
}
|
|
643
671
|
__name(fetchAccount2, "fetchAccount");
|
|
672
|
+
async function fetchLookupTable2(addr, commitment) {
|
|
673
|
+
const account = await fetchAddressLookupTable(runtime.rpc, addr, {
|
|
674
|
+
commitment: getCommitment(commitment)
|
|
675
|
+
});
|
|
676
|
+
const { addresses, authority, deactivationSlot, lastExtendedSlot, lastExtendedSlotStartIndex } = account.data;
|
|
677
|
+
return {
|
|
678
|
+
addresses,
|
|
679
|
+
authority: isSome(authority) ? authority.value : void 0,
|
|
680
|
+
deactivationSlot,
|
|
681
|
+
lastExtendedSlot,
|
|
682
|
+
lastExtendedSlotStartIndex
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
__name(fetchLookupTable2, "fetchLookupTable");
|
|
686
|
+
async function fetchLookupTables2(addresses, commitment) {
|
|
687
|
+
if (addresses.length === 0) return [];
|
|
688
|
+
const accounts = await fetchAllAddressLookupTable(runtime.rpc, addresses, {
|
|
689
|
+
commitment: getCommitment(commitment)
|
|
690
|
+
});
|
|
691
|
+
return accounts.map(({ data }) => ({
|
|
692
|
+
addresses: data.addresses,
|
|
693
|
+
authority: isSome(data.authority) ? data.authority.value : void 0,
|
|
694
|
+
deactivationSlot: data.deactivationSlot,
|
|
695
|
+
lastExtendedSlot: data.lastExtendedSlot,
|
|
696
|
+
lastExtendedSlotStartIndex: data.lastExtendedSlotStartIndex
|
|
697
|
+
}));
|
|
698
|
+
}
|
|
699
|
+
__name(fetchLookupTables2, "fetchLookupTables");
|
|
700
|
+
async function fetchNonceAccount2(addr, commitment) {
|
|
701
|
+
const account = await fetchNonce(runtime.rpc, addr, {
|
|
702
|
+
commitment: getCommitment(commitment)
|
|
703
|
+
});
|
|
704
|
+
return { authority: account.data.authority, blockhash: account.data.blockhash };
|
|
705
|
+
}
|
|
706
|
+
__name(fetchNonceAccount2, "fetchNonceAccount");
|
|
644
707
|
async function sendTransaction2(transaction, commitment) {
|
|
645
708
|
const targetCommitment = getCommitment(commitment);
|
|
646
709
|
const abortController = new AbortController();
|
|
647
|
-
const
|
|
710
|
+
const signature5 = await runtime.rpc.sendTransaction(getBase64EncodedWireTransaction(transaction), {
|
|
648
711
|
encoding: "base64",
|
|
649
712
|
preflightCommitment: targetCommitment
|
|
650
713
|
}).send({ abortSignal: abortController.signal });
|
|
651
|
-
const key =
|
|
714
|
+
const key = signature5.toString();
|
|
652
715
|
store.setState((state) => ({
|
|
653
716
|
...state,
|
|
654
717
|
lastUpdatedAt: now(),
|
|
@@ -656,7 +719,7 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
656
719
|
...state.transactions,
|
|
657
720
|
[key]: {
|
|
658
721
|
lastUpdatedAt: now(),
|
|
659
|
-
signature:
|
|
722
|
+
signature: signature5,
|
|
660
723
|
status: "sending"
|
|
661
724
|
}
|
|
662
725
|
}
|
|
@@ -684,12 +747,12 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
684
747
|
...state.transactions,
|
|
685
748
|
[key]: {
|
|
686
749
|
lastUpdatedAt: now(),
|
|
687
|
-
signature:
|
|
750
|
+
signature: signature5,
|
|
688
751
|
status: "confirmed"
|
|
689
752
|
}
|
|
690
753
|
}
|
|
691
754
|
}));
|
|
692
|
-
return
|
|
755
|
+
return signature5;
|
|
693
756
|
} catch (error) {
|
|
694
757
|
store.setState((state) => ({
|
|
695
758
|
...state,
|
|
@@ -699,7 +762,7 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
699
762
|
[key]: {
|
|
700
763
|
error,
|
|
701
764
|
lastUpdatedAt: now(),
|
|
702
|
-
signature:
|
|
765
|
+
signature: signature5,
|
|
703
766
|
status: "failed"
|
|
704
767
|
}
|
|
705
768
|
}
|
|
@@ -713,26 +776,26 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
713
776
|
}
|
|
714
777
|
}
|
|
715
778
|
__name(sendTransaction2, "sendTransaction");
|
|
716
|
-
async function requestAirdrop2(
|
|
779
|
+
async function requestAirdrop2(address5, lamports2) {
|
|
717
780
|
try {
|
|
718
781
|
const factory = airdropFactory({
|
|
719
782
|
rpc: runtime.rpc,
|
|
720
783
|
rpcSubscriptions: runtime.rpcSubscriptions
|
|
721
784
|
});
|
|
722
|
-
const
|
|
785
|
+
const signature5 = await factory({
|
|
723
786
|
commitment: getCommitment("confirmed"),
|
|
724
787
|
lamports: lamports2,
|
|
725
|
-
recipientAddress:
|
|
788
|
+
recipientAddress: address5
|
|
726
789
|
});
|
|
727
790
|
logger({
|
|
728
|
-
data: { address:
|
|
791
|
+
data: { address: address5.toString(), lamports: lamports2.toString(), signature: signature5 },
|
|
729
792
|
level: "info",
|
|
730
793
|
message: "airdrop requested"
|
|
731
794
|
});
|
|
732
|
-
return
|
|
795
|
+
return signature5;
|
|
733
796
|
} catch (error) {
|
|
734
797
|
logger({
|
|
735
|
-
data: { address:
|
|
798
|
+
data: { address: address5.toString(), lamports: lamports2.toString(), ...formatError(error) },
|
|
736
799
|
level: "error",
|
|
737
800
|
message: "airdrop request failed"
|
|
738
801
|
});
|
|
@@ -745,6 +808,9 @@ function createActions({ connectors, logger: inputLogger, runtime, store }) {
|
|
|
745
808
|
disconnectWallet: disconnectWallet3,
|
|
746
809
|
fetchAccount: fetchAccount2,
|
|
747
810
|
fetchBalance: fetchBalance2,
|
|
811
|
+
fetchLookupTable: fetchLookupTable2,
|
|
812
|
+
fetchLookupTables: fetchLookupTables2,
|
|
813
|
+
fetchNonceAccount: fetchNonceAccount2,
|
|
748
814
|
requestAirdrop: requestAirdrop2,
|
|
749
815
|
sendTransaction: sendTransaction2,
|
|
750
816
|
setCluster: setCluster2
|
|
@@ -1133,11 +1199,11 @@ function isWalletSession(value) {
|
|
|
1133
1199
|
__name(isWalletSession, "isWalletSession");
|
|
1134
1200
|
function createWalletTransactionSigner(session, config = {}) {
|
|
1135
1201
|
const { commitment } = config;
|
|
1136
|
-
const
|
|
1202
|
+
const address5 = session.account.address;
|
|
1137
1203
|
if (session.signTransaction) {
|
|
1138
1204
|
const signTransaction = session.signTransaction.bind(session);
|
|
1139
1205
|
const modifyingSigner = Object.freeze({
|
|
1140
|
-
address:
|
|
1206
|
+
address: address5,
|
|
1141
1207
|
async modifyAndSignTransactions(transactions) {
|
|
1142
1208
|
const signedTransactions = [];
|
|
1143
1209
|
for (const transaction of transactions) {
|
|
@@ -1145,8 +1211,8 @@ function createWalletTransactionSigner(session, config = {}) {
|
|
|
1145
1211
|
const signed = await signTransaction(
|
|
1146
1212
|
castTransaction
|
|
1147
1213
|
);
|
|
1148
|
-
const
|
|
1149
|
-
if (!
|
|
1214
|
+
const signature5 = signed.signatures[address5];
|
|
1215
|
+
if (!signature5) {
|
|
1150
1216
|
throw new Error("Wallet did not populate the expected fee payer signature.");
|
|
1151
1217
|
}
|
|
1152
1218
|
const mergedTransaction = Object.freeze({
|
|
@@ -1165,11 +1231,11 @@ function createWalletTransactionSigner(session, config = {}) {
|
|
|
1165
1231
|
const signedTransactions = await this.modifyAndSignTransactions(transactions);
|
|
1166
1232
|
return Object.freeze(
|
|
1167
1233
|
signedTransactions.map((signedTransaction) => {
|
|
1168
|
-
const
|
|
1169
|
-
if (!
|
|
1234
|
+
const signature5 = signedTransaction.signatures[address5];
|
|
1235
|
+
if (!signature5) {
|
|
1170
1236
|
throw new Error("Expected signer to produce a signature for the provided address.");
|
|
1171
1237
|
}
|
|
1172
|
-
return Object.freeze({ [
|
|
1238
|
+
return Object.freeze({ [address5]: signature5 });
|
|
1173
1239
|
})
|
|
1174
1240
|
);
|
|
1175
1241
|
}
|
|
@@ -1183,7 +1249,7 @@ function createWalletTransactionSigner(session, config = {}) {
|
|
|
1183
1249
|
const base58Encoder = getBase58Encoder();
|
|
1184
1250
|
const sendTransaction2 = session.sendTransaction.bind(session);
|
|
1185
1251
|
const sendingSigner = Object.freeze({
|
|
1186
|
-
address:
|
|
1252
|
+
address: address5,
|
|
1187
1253
|
async signAndSendTransactions(transactions) {
|
|
1188
1254
|
const signatures = [];
|
|
1189
1255
|
for (const transaction of transactions) {
|
|
@@ -1522,6 +1588,310 @@ function createSplTokenHelper(runtime, config) {
|
|
|
1522
1588
|
};
|
|
1523
1589
|
}
|
|
1524
1590
|
__name(createSplTokenHelper, "createSplTokenHelper");
|
|
1591
|
+
var STAKE_PROGRAM_ID = "Stake11111111111111111111111111111111111111";
|
|
1592
|
+
var SYSVAR_CLOCK = "SysvarC1ock11111111111111111111111111111111";
|
|
1593
|
+
var SYSVAR_STAKE_HISTORY = "SysvarStakeHistory1111111111111111111111111";
|
|
1594
|
+
var UNUSED_STAKE_CONFIG_ACC = "StakeConfig11111111111111111111111111111111";
|
|
1595
|
+
var STAKE_STATE_LEN = 200;
|
|
1596
|
+
function ensureAddress3(value) {
|
|
1597
|
+
return typeof value === "string" ? address(value) : value;
|
|
1598
|
+
}
|
|
1599
|
+
__name(ensureAddress3, "ensureAddress");
|
|
1600
|
+
async function resolveLifetime3(runtime, commitment, fallback) {
|
|
1601
|
+
if (fallback) {
|
|
1602
|
+
return fallback;
|
|
1603
|
+
}
|
|
1604
|
+
const { value } = await runtime.rpc.getLatestBlockhash({ commitment }).send();
|
|
1605
|
+
return value;
|
|
1606
|
+
}
|
|
1607
|
+
__name(resolveLifetime3, "resolveLifetime");
|
|
1608
|
+
function resolveSigner3(authority, commitment) {
|
|
1609
|
+
if (isWalletSession(authority)) {
|
|
1610
|
+
const { signer, mode } = createWalletTransactionSigner(authority, { commitment });
|
|
1611
|
+
return { mode, signer };
|
|
1612
|
+
}
|
|
1613
|
+
return { mode: resolveSignerMode(authority), signer: authority };
|
|
1614
|
+
}
|
|
1615
|
+
__name(resolveSigner3, "resolveSigner");
|
|
1616
|
+
function toLamportAmount2(input) {
|
|
1617
|
+
return lamportsMath.fromLamports(input);
|
|
1618
|
+
}
|
|
1619
|
+
__name(toLamportAmount2, "toLamportAmount");
|
|
1620
|
+
function createStakeHelper(runtime) {
|
|
1621
|
+
async function prepareStake(config) {
|
|
1622
|
+
const commitment = config.commitment;
|
|
1623
|
+
const lifetime = await resolveLifetime3(runtime, commitment, config.lifetime);
|
|
1624
|
+
const { signer, mode } = resolveSigner3(config.authority, commitment);
|
|
1625
|
+
const validatorAddress = ensureAddress3(config.validatorId);
|
|
1626
|
+
const amount = toLamportAmount2(config.amount);
|
|
1627
|
+
const rentExempt = await runtime.rpc.getMinimumBalanceForRentExemption(BigInt(STAKE_STATE_LEN)).send();
|
|
1628
|
+
const totalLamports = rentExempt + amount;
|
|
1629
|
+
const stakeAccount = await generateKeyPairSigner();
|
|
1630
|
+
const createIx = getCreateAccountInstruction({
|
|
1631
|
+
payer: signer,
|
|
1632
|
+
newAccount: stakeAccount,
|
|
1633
|
+
lamports: totalLamports,
|
|
1634
|
+
space: BigInt(STAKE_STATE_LEN),
|
|
1635
|
+
programAddress: STAKE_PROGRAM_ID
|
|
1636
|
+
});
|
|
1637
|
+
const initializeIx = getInitializeInstruction({
|
|
1638
|
+
stake: stakeAccount.address,
|
|
1639
|
+
arg0: {
|
|
1640
|
+
staker: signer.address,
|
|
1641
|
+
withdrawer: signer.address
|
|
1642
|
+
},
|
|
1643
|
+
arg1: {
|
|
1644
|
+
unixTimestamp: 0n,
|
|
1645
|
+
epoch: 0n,
|
|
1646
|
+
custodian: signer.address
|
|
1647
|
+
}
|
|
1648
|
+
});
|
|
1649
|
+
const delegateIx = getDelegateStakeInstruction({
|
|
1650
|
+
stake: stakeAccount.address,
|
|
1651
|
+
vote: validatorAddress,
|
|
1652
|
+
stakeHistory: SYSVAR_STAKE_HISTORY,
|
|
1653
|
+
unused: UNUSED_STAKE_CONFIG_ACC,
|
|
1654
|
+
stakeAuthority: signer
|
|
1655
|
+
});
|
|
1656
|
+
const message = pipe(
|
|
1657
|
+
createTransactionMessage({ version: config.transactionVersion ?? 0 }),
|
|
1658
|
+
(m) => setTransactionMessageFeePayer(signer.address, m),
|
|
1659
|
+
(m) => setTransactionMessageLifetimeUsingBlockhash(lifetime, m),
|
|
1660
|
+
(m) => appendTransactionMessageInstructions([createIx, initializeIx, delegateIx], m)
|
|
1661
|
+
);
|
|
1662
|
+
return {
|
|
1663
|
+
commitment,
|
|
1664
|
+
lifetime,
|
|
1665
|
+
message,
|
|
1666
|
+
mode,
|
|
1667
|
+
signer,
|
|
1668
|
+
stakeAccount,
|
|
1669
|
+
plan: singleTransactionPlan(message)
|
|
1670
|
+
};
|
|
1671
|
+
}
|
|
1672
|
+
__name(prepareStake, "prepareStake");
|
|
1673
|
+
async function sendPreparedStake(prepared, options = {}) {
|
|
1674
|
+
if (prepared.mode === "send" && isTransactionSendingSigner(prepared.signer)) {
|
|
1675
|
+
const signatureBytes2 = await signAndSendTransactionMessageWithSigners(prepared.message, {
|
|
1676
|
+
abortSignal: options.abortSignal,
|
|
1677
|
+
minContextSlot: options.minContextSlot
|
|
1678
|
+
});
|
|
1679
|
+
const base58Decoder2 = getBase58Decoder();
|
|
1680
|
+
return signature(base58Decoder2.decode(signatureBytes2));
|
|
1681
|
+
}
|
|
1682
|
+
const commitment = options.commitment ?? prepared.commitment;
|
|
1683
|
+
const maxRetries = options.maxRetries === void 0 ? void 0 : typeof options.maxRetries === "bigint" ? options.maxRetries : BigInt(options.maxRetries);
|
|
1684
|
+
let latestSignature = null;
|
|
1685
|
+
const executor = createTransactionPlanExecutor({
|
|
1686
|
+
async executeTransactionMessage(message, config = {}) {
|
|
1687
|
+
const signed = await signTransactionMessageWithSigners(message, {
|
|
1688
|
+
abortSignal: config.abortSignal ?? options.abortSignal,
|
|
1689
|
+
minContextSlot: options.minContextSlot
|
|
1690
|
+
});
|
|
1691
|
+
const wire = getBase64EncodedWireTransaction(signed);
|
|
1692
|
+
const response = await runtime.rpc.sendTransaction(wire, {
|
|
1693
|
+
encoding: "base64",
|
|
1694
|
+
maxRetries,
|
|
1695
|
+
preflightCommitment: commitment,
|
|
1696
|
+
skipPreflight: options.skipPreflight
|
|
1697
|
+
}).send({ abortSignal: config.abortSignal ?? options.abortSignal });
|
|
1698
|
+
latestSignature = signature(response);
|
|
1699
|
+
return { transaction: signed };
|
|
1700
|
+
}
|
|
1701
|
+
});
|
|
1702
|
+
await executor(prepared.plan ?? singleTransactionPlan(prepared.message), { abortSignal: options.abortSignal });
|
|
1703
|
+
if (!latestSignature) {
|
|
1704
|
+
throw new Error("Failed to resolve transaction signature.");
|
|
1705
|
+
}
|
|
1706
|
+
return latestSignature;
|
|
1707
|
+
}
|
|
1708
|
+
__name(sendPreparedStake, "sendPreparedStake");
|
|
1709
|
+
async function sendStake(config, options) {
|
|
1710
|
+
const prepared = await prepareStake(config);
|
|
1711
|
+
return await sendPreparedStake(prepared, options);
|
|
1712
|
+
}
|
|
1713
|
+
__name(sendStake, "sendStake");
|
|
1714
|
+
async function prepareUnstake(config) {
|
|
1715
|
+
const commitment = config.commitment;
|
|
1716
|
+
const lifetime = await resolveLifetime3(runtime, commitment, config.lifetime);
|
|
1717
|
+
const { signer, mode } = resolveSigner3(config.authority, commitment);
|
|
1718
|
+
const stakeAccountAddress = ensureAddress3(config.stakeAccount);
|
|
1719
|
+
const deactivateIx = getDeactivateInstruction({
|
|
1720
|
+
stake: stakeAccountAddress,
|
|
1721
|
+
clockSysvar: SYSVAR_CLOCK,
|
|
1722
|
+
stakeAuthority: signer
|
|
1723
|
+
});
|
|
1724
|
+
const message = pipe(
|
|
1725
|
+
createTransactionMessage({ version: config.transactionVersion ?? 0 }),
|
|
1726
|
+
(m) => setTransactionMessageFeePayer(signer.address, m),
|
|
1727
|
+
(m) => setTransactionMessageLifetimeUsingBlockhash(lifetime, m),
|
|
1728
|
+
(m) => appendTransactionMessageInstructions([deactivateIx], m)
|
|
1729
|
+
);
|
|
1730
|
+
return {
|
|
1731
|
+
commitment,
|
|
1732
|
+
lifetime,
|
|
1733
|
+
message,
|
|
1734
|
+
mode,
|
|
1735
|
+
signer,
|
|
1736
|
+
plan: singleTransactionPlan(message)
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
__name(prepareUnstake, "prepareUnstake");
|
|
1740
|
+
async function sendPreparedUnstake(prepared, options = {}) {
|
|
1741
|
+
if (prepared.mode === "send" && isTransactionSendingSigner(prepared.signer)) {
|
|
1742
|
+
const signatureBytes2 = await signAndSendTransactionMessageWithSigners(prepared.message, {
|
|
1743
|
+
abortSignal: options.abortSignal,
|
|
1744
|
+
minContextSlot: options.minContextSlot
|
|
1745
|
+
});
|
|
1746
|
+
const base58Decoder2 = getBase58Decoder();
|
|
1747
|
+
return signature(base58Decoder2.decode(signatureBytes2));
|
|
1748
|
+
}
|
|
1749
|
+
const commitment = options.commitment ?? prepared.commitment;
|
|
1750
|
+
const maxRetries = options.maxRetries === void 0 ? void 0 : typeof options.maxRetries === "bigint" ? options.maxRetries : BigInt(options.maxRetries);
|
|
1751
|
+
let latestSignature = null;
|
|
1752
|
+
const executor = createTransactionPlanExecutor({
|
|
1753
|
+
async executeTransactionMessage(message, config = {}) {
|
|
1754
|
+
const signed = await signTransactionMessageWithSigners(message, {
|
|
1755
|
+
abortSignal: config.abortSignal ?? options.abortSignal,
|
|
1756
|
+
minContextSlot: options.minContextSlot
|
|
1757
|
+
});
|
|
1758
|
+
const wire = getBase64EncodedWireTransaction(signed);
|
|
1759
|
+
const response = await runtime.rpc.sendTransaction(wire, {
|
|
1760
|
+
encoding: "base64",
|
|
1761
|
+
maxRetries,
|
|
1762
|
+
preflightCommitment: commitment,
|
|
1763
|
+
skipPreflight: options.skipPreflight
|
|
1764
|
+
}).send({ abortSignal: config.abortSignal ?? options.abortSignal });
|
|
1765
|
+
latestSignature = signature(response);
|
|
1766
|
+
return { transaction: signed };
|
|
1767
|
+
}
|
|
1768
|
+
});
|
|
1769
|
+
await executor(prepared.plan);
|
|
1770
|
+
if (!latestSignature) {
|
|
1771
|
+
throw new Error("Failed to resolve transaction signature.");
|
|
1772
|
+
}
|
|
1773
|
+
return latestSignature;
|
|
1774
|
+
}
|
|
1775
|
+
__name(sendPreparedUnstake, "sendPreparedUnstake");
|
|
1776
|
+
async function sendUnstake(config, options) {
|
|
1777
|
+
const prepared = await prepareUnstake(config);
|
|
1778
|
+
return await sendPreparedUnstake(prepared, options);
|
|
1779
|
+
}
|
|
1780
|
+
__name(sendUnstake, "sendUnstake");
|
|
1781
|
+
async function prepareWithdraw(config) {
|
|
1782
|
+
const commitment = config.commitment;
|
|
1783
|
+
const lifetime = await resolveLifetime3(runtime, commitment, config.lifetime);
|
|
1784
|
+
const { signer, mode } = resolveSigner3(config.authority, commitment);
|
|
1785
|
+
const stakeAccountAddress = ensureAddress3(config.stakeAccount);
|
|
1786
|
+
const destinationAddress = ensureAddress3(config.destination);
|
|
1787
|
+
const amount = toLamportAmount2(config.amount);
|
|
1788
|
+
const withdrawIx = getWithdrawInstruction({
|
|
1789
|
+
stake: stakeAccountAddress,
|
|
1790
|
+
recipient: destinationAddress,
|
|
1791
|
+
clockSysvar: SYSVAR_CLOCK,
|
|
1792
|
+
stakeHistory: SYSVAR_STAKE_HISTORY,
|
|
1793
|
+
withdrawAuthority: signer,
|
|
1794
|
+
args: amount
|
|
1795
|
+
});
|
|
1796
|
+
const message = pipe(
|
|
1797
|
+
createTransactionMessage({ version: config.transactionVersion ?? 0 }),
|
|
1798
|
+
(m) => setTransactionMessageFeePayer(signer.address, m),
|
|
1799
|
+
(m) => setTransactionMessageLifetimeUsingBlockhash(lifetime, m),
|
|
1800
|
+
(m) => appendTransactionMessageInstructions([withdrawIx], m)
|
|
1801
|
+
);
|
|
1802
|
+
return {
|
|
1803
|
+
commitment,
|
|
1804
|
+
lifetime,
|
|
1805
|
+
message,
|
|
1806
|
+
mode,
|
|
1807
|
+
signer,
|
|
1808
|
+
plan: singleTransactionPlan(message)
|
|
1809
|
+
};
|
|
1810
|
+
}
|
|
1811
|
+
__name(prepareWithdraw, "prepareWithdraw");
|
|
1812
|
+
async function sendPreparedWithdraw(prepared, options = {}) {
|
|
1813
|
+
if (prepared.mode === "send" && isTransactionSendingSigner(prepared.signer)) {
|
|
1814
|
+
const signatureBytes2 = await signAndSendTransactionMessageWithSigners(prepared.message, {
|
|
1815
|
+
abortSignal: options.abortSignal,
|
|
1816
|
+
minContextSlot: options.minContextSlot
|
|
1817
|
+
});
|
|
1818
|
+
const base58Decoder2 = getBase58Decoder();
|
|
1819
|
+
return signature(base58Decoder2.decode(signatureBytes2));
|
|
1820
|
+
}
|
|
1821
|
+
const commitment = options.commitment ?? prepared.commitment;
|
|
1822
|
+
const maxRetries = options.maxRetries === void 0 ? void 0 : typeof options.maxRetries === "bigint" ? options.maxRetries : BigInt(options.maxRetries);
|
|
1823
|
+
let latestSignature = null;
|
|
1824
|
+
const executor = createTransactionPlanExecutor({
|
|
1825
|
+
async executeTransactionMessage(message, config = {}) {
|
|
1826
|
+
const signed = await signTransactionMessageWithSigners(message, {
|
|
1827
|
+
abortSignal: config.abortSignal ?? options.abortSignal,
|
|
1828
|
+
minContextSlot: options.minContextSlot
|
|
1829
|
+
});
|
|
1830
|
+
const wire = getBase64EncodedWireTransaction(signed);
|
|
1831
|
+
const response = await runtime.rpc.sendTransaction(wire, {
|
|
1832
|
+
encoding: "base64",
|
|
1833
|
+
maxRetries,
|
|
1834
|
+
preflightCommitment: commitment,
|
|
1835
|
+
skipPreflight: options.skipPreflight
|
|
1836
|
+
}).send({ abortSignal: config.abortSignal ?? options.abortSignal });
|
|
1837
|
+
latestSignature = signature(response);
|
|
1838
|
+
return { transaction: signed };
|
|
1839
|
+
}
|
|
1840
|
+
});
|
|
1841
|
+
await executor(prepared.plan);
|
|
1842
|
+
if (!latestSignature) {
|
|
1843
|
+
throw new Error("Failed to resolve transaction signature.");
|
|
1844
|
+
}
|
|
1845
|
+
return latestSignature;
|
|
1846
|
+
}
|
|
1847
|
+
__name(sendPreparedWithdraw, "sendPreparedWithdraw");
|
|
1848
|
+
async function sendWithdraw(config, options) {
|
|
1849
|
+
const prepared = await prepareWithdraw(config);
|
|
1850
|
+
return await sendPreparedWithdraw(prepared, options);
|
|
1851
|
+
}
|
|
1852
|
+
__name(sendWithdraw, "sendWithdraw");
|
|
1853
|
+
async function getStakeAccounts(wallet, validatorId) {
|
|
1854
|
+
const walletAddress = typeof wallet === "string" ? wallet : String(wallet);
|
|
1855
|
+
const accounts = await runtime.rpc.getProgramAccounts(STAKE_PROGRAM_ID, {
|
|
1856
|
+
encoding: "jsonParsed",
|
|
1857
|
+
filters: [
|
|
1858
|
+
{
|
|
1859
|
+
memcmp: {
|
|
1860
|
+
offset: 44n,
|
|
1861
|
+
bytes: walletAddress,
|
|
1862
|
+
encoding: "base58"
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
]
|
|
1866
|
+
}).send();
|
|
1867
|
+
if (!validatorId) {
|
|
1868
|
+
return accounts;
|
|
1869
|
+
}
|
|
1870
|
+
const validatorIdStr = typeof validatorId === "string" ? validatorId : String(validatorId);
|
|
1871
|
+
return accounts.filter((acc) => {
|
|
1872
|
+
const data = acc.account?.data;
|
|
1873
|
+
if (data && "parsed" in data) {
|
|
1874
|
+
const info = data.parsed?.info;
|
|
1875
|
+
return info?.stake?.delegation?.voter === validatorIdStr;
|
|
1876
|
+
}
|
|
1877
|
+
return false;
|
|
1878
|
+
});
|
|
1879
|
+
}
|
|
1880
|
+
__name(getStakeAccounts, "getStakeAccounts");
|
|
1881
|
+
return {
|
|
1882
|
+
getStakeAccounts,
|
|
1883
|
+
prepareStake,
|
|
1884
|
+
prepareUnstake,
|
|
1885
|
+
prepareWithdraw,
|
|
1886
|
+
sendPreparedStake,
|
|
1887
|
+
sendPreparedUnstake,
|
|
1888
|
+
sendPreparedWithdraw,
|
|
1889
|
+
sendStake,
|
|
1890
|
+
sendUnstake,
|
|
1891
|
+
sendWithdraw
|
|
1892
|
+
};
|
|
1893
|
+
}
|
|
1894
|
+
__name(createStakeHelper, "createStakeHelper");
|
|
1525
1895
|
function transactionToBase64(tx) {
|
|
1526
1896
|
if ("messageBytes" in tx) {
|
|
1527
1897
|
return getBase64EncodedWireTransaction(tx);
|
|
@@ -1674,11 +2044,11 @@ function resolveFeePayerAddress(feePayer, authoritySigner) {
|
|
|
1674
2044
|
return { address: feePayer.address, signer: feePayer };
|
|
1675
2045
|
}
|
|
1676
2046
|
if (feePayer) {
|
|
1677
|
-
const
|
|
1678
|
-
if (authoritySigner && authoritySigner.address ===
|
|
1679
|
-
return { address:
|
|
2047
|
+
const address5 = toAddress(feePayer);
|
|
2048
|
+
if (authoritySigner && authoritySigner.address === address5) {
|
|
2049
|
+
return { address: address5, signer: authoritySigner };
|
|
1680
2050
|
}
|
|
1681
|
-
return { address:
|
|
2051
|
+
return { address: address5 };
|
|
1682
2052
|
}
|
|
1683
2053
|
if (!authoritySigner) {
|
|
1684
2054
|
throw new Error("Unable to resolve authority signer for the fee payer.");
|
|
@@ -1930,6 +2300,21 @@ function wrapSplTokenHelper(helper, getFallback, baseCommitment) {
|
|
|
1930
2300
|
};
|
|
1931
2301
|
}
|
|
1932
2302
|
__name(wrapSplTokenHelper, "wrapSplTokenHelper");
|
|
2303
|
+
function wrapStakeHelper(helper, getFallback) {
|
|
2304
|
+
return {
|
|
2305
|
+
getStakeAccounts: helper.getStakeAccounts,
|
|
2306
|
+
prepareStake: /* @__PURE__ */ __name((config) => helper.prepareStake(withDefaultCommitment(config, getFallback)), "prepareStake"),
|
|
2307
|
+
prepareUnstake: /* @__PURE__ */ __name((config) => helper.prepareUnstake(withDefaultCommitment(config, getFallback)), "prepareUnstake"),
|
|
2308
|
+
prepareWithdraw: /* @__PURE__ */ __name((config) => helper.prepareWithdraw(withDefaultCommitment(config, getFallback)), "prepareWithdraw"),
|
|
2309
|
+
sendPreparedStake: helper.sendPreparedStake,
|
|
2310
|
+
sendPreparedUnstake: helper.sendPreparedUnstake,
|
|
2311
|
+
sendPreparedWithdraw: helper.sendPreparedWithdraw,
|
|
2312
|
+
sendStake: /* @__PURE__ */ __name((config, options) => helper.sendStake(withDefaultCommitment(config, getFallback), options), "sendStake"),
|
|
2313
|
+
sendUnstake: /* @__PURE__ */ __name((config, options) => helper.sendUnstake(withDefaultCommitment(config, getFallback), options), "sendUnstake"),
|
|
2314
|
+
sendWithdraw: /* @__PURE__ */ __name((config, options) => helper.sendWithdraw(withDefaultCommitment(config, getFallback), options), "sendWithdraw")
|
|
2315
|
+
};
|
|
2316
|
+
}
|
|
2317
|
+
__name(wrapStakeHelper, "wrapStakeHelper");
|
|
1933
2318
|
function normaliseConfigValue(value) {
|
|
1934
2319
|
if (value === null || value === void 0) {
|
|
1935
2320
|
return void 0;
|
|
@@ -1957,6 +2342,7 @@ function createClientHelpers(runtime, store) {
|
|
|
1957
2342
|
const getFallbackCommitment = /* @__PURE__ */ __name(() => store.getState().cluster.commitment, "getFallbackCommitment");
|
|
1958
2343
|
const splTokenCache = /* @__PURE__ */ new Map();
|
|
1959
2344
|
let solTransfer;
|
|
2345
|
+
let stake;
|
|
1960
2346
|
let transaction;
|
|
1961
2347
|
const getSolTransfer = /* @__PURE__ */ __name(() => {
|
|
1962
2348
|
if (!solTransfer) {
|
|
@@ -1964,6 +2350,12 @@ function createClientHelpers(runtime, store) {
|
|
|
1964
2350
|
}
|
|
1965
2351
|
return solTransfer;
|
|
1966
2352
|
}, "getSolTransfer");
|
|
2353
|
+
const getStake = /* @__PURE__ */ __name(() => {
|
|
2354
|
+
if (!stake) {
|
|
2355
|
+
stake = wrapStakeHelper(createStakeHelper(runtime), getFallbackCommitment);
|
|
2356
|
+
}
|
|
2357
|
+
return stake;
|
|
2358
|
+
}, "getStake");
|
|
1967
2359
|
const getTransaction = /* @__PURE__ */ __name(() => {
|
|
1968
2360
|
if (!transaction) {
|
|
1969
2361
|
transaction = createTransactionHelper(runtime, getFallbackCommitment);
|
|
@@ -1994,6 +2386,9 @@ function createClientHelpers(runtime, store) {
|
|
|
1994
2386
|
return getSolTransfer();
|
|
1995
2387
|
},
|
|
1996
2388
|
splToken: getSplTokenHelper,
|
|
2389
|
+
get stake() {
|
|
2390
|
+
return getStake();
|
|
2391
|
+
},
|
|
1997
2392
|
get transaction() {
|
|
1998
2393
|
return getTransaction();
|
|
1999
2394
|
},
|
|
@@ -2261,6 +2656,9 @@ function createClient(config) {
|
|
|
2261
2656
|
splToken: helpers.splToken,
|
|
2262
2657
|
SplToken: helpers.splToken,
|
|
2263
2658
|
SplHelper: helpers.splToken,
|
|
2659
|
+
get stake() {
|
|
2660
|
+
return helpers.stake;
|
|
2661
|
+
},
|
|
2264
2662
|
get transaction() {
|
|
2265
2663
|
return helpers.transaction;
|
|
2266
2664
|
},
|
|
@@ -2323,25 +2721,38 @@ function createWalletStandardConnector(wallet, options = {}) {
|
|
|
2323
2721
|
};
|
|
2324
2722
|
async function connect(connectionOptions = {}) {
|
|
2325
2723
|
const connectFeature = wallet.features[StandardConnect];
|
|
2724
|
+
const eventsFeature = wallet.features[StandardEvents];
|
|
2326
2725
|
const shouldConnectSilently = Boolean(connectionOptions.autoConnect);
|
|
2726
|
+
const allowInteractiveFallback = connectionOptions.allowInteractiveFallback ?? true;
|
|
2327
2727
|
let walletAccounts = wallet.accounts;
|
|
2328
2728
|
if (connectFeature) {
|
|
2329
|
-
const
|
|
2330
|
-
silent
|
|
2331
|
-
});
|
|
2332
|
-
|
|
2333
|
-
|
|
2729
|
+
const connectWithMode = /* @__PURE__ */ __name(async (silent) => connectFeature.connect({
|
|
2730
|
+
silent
|
|
2731
|
+
}), "connectWithMode");
|
|
2732
|
+
try {
|
|
2733
|
+
const { accounts } = await connectWithMode(shouldConnectSilently);
|
|
2734
|
+
if (accounts.length) {
|
|
2735
|
+
walletAccounts = accounts;
|
|
2736
|
+
}
|
|
2737
|
+
} catch (error) {
|
|
2738
|
+
if (!shouldConnectSilently || !allowInteractiveFallback) {
|
|
2739
|
+
throw error;
|
|
2740
|
+
}
|
|
2741
|
+
const { accounts } = await connectWithMode(false);
|
|
2742
|
+
if (accounts.length) {
|
|
2743
|
+
walletAccounts = accounts;
|
|
2744
|
+
}
|
|
2334
2745
|
}
|
|
2335
2746
|
}
|
|
2336
|
-
|
|
2337
|
-
|
|
2747
|
+
let currentAccount = getPrimaryAccount(walletAccounts);
|
|
2748
|
+
let sessionAccount = toSessionAccount(currentAccount);
|
|
2338
2749
|
const signMessageFeature = wallet.features[SolanaSignMessage];
|
|
2339
2750
|
const signTransactionFeature = wallet.features[SolanaSignTransaction];
|
|
2340
2751
|
const signAndSendFeature = wallet.features[SolanaSignAndSendTransaction];
|
|
2341
|
-
const resolvedChain = options.defaultChain ?? getChain(
|
|
2752
|
+
const resolvedChain = options.defaultChain ?? getChain(currentAccount);
|
|
2342
2753
|
const signMessage = signMessageFeature ? async (message) => {
|
|
2343
2754
|
const [output] = await signMessageFeature.signMessage({
|
|
2344
|
-
account:
|
|
2755
|
+
account: currentAccount,
|
|
2345
2756
|
message
|
|
2346
2757
|
});
|
|
2347
2758
|
return output.signature;
|
|
@@ -2349,11 +2760,11 @@ function createWalletStandardConnector(wallet, options = {}) {
|
|
|
2349
2760
|
const signTransaction = signTransactionFeature ? async (transaction) => {
|
|
2350
2761
|
const wireBytes = new Uint8Array(transactionEncoder.encode(transaction));
|
|
2351
2762
|
const request = resolvedChain ? {
|
|
2352
|
-
account:
|
|
2763
|
+
account: currentAccount,
|
|
2353
2764
|
chain: resolvedChain,
|
|
2354
2765
|
transaction: wireBytes
|
|
2355
2766
|
} : {
|
|
2356
|
-
account:
|
|
2767
|
+
account: currentAccount,
|
|
2357
2768
|
transaction: wireBytes
|
|
2358
2769
|
};
|
|
2359
2770
|
const [output] = await signTransactionFeature.signTransaction(request);
|
|
@@ -2361,9 +2772,9 @@ function createWalletStandardConnector(wallet, options = {}) {
|
|
|
2361
2772
|
} : void 0;
|
|
2362
2773
|
const sendTransaction2 = signAndSendFeature ? async (transaction, config) => {
|
|
2363
2774
|
const wireBytes = new Uint8Array(transactionEncoder.encode(transaction));
|
|
2364
|
-
const chain = options.defaultChain ?? getChain(
|
|
2775
|
+
const chain = options.defaultChain ?? getChain(currentAccount) ?? "solana:mainnet-beta";
|
|
2365
2776
|
const [output] = await signAndSendFeature.signAndSendTransaction({
|
|
2366
|
-
account:
|
|
2777
|
+
account: currentAccount,
|
|
2367
2778
|
chain,
|
|
2368
2779
|
options: {
|
|
2369
2780
|
commitment: mapCommitment(config?.commitment)
|
|
@@ -2373,13 +2784,35 @@ function createWalletStandardConnector(wallet, options = {}) {
|
|
|
2373
2784
|
return base58Decoder.decode(output.signature);
|
|
2374
2785
|
} : void 0;
|
|
2375
2786
|
async function disconnectSession() {
|
|
2787
|
+
changeUnsubscribe?.();
|
|
2376
2788
|
await disconnectWallet2(wallet);
|
|
2377
2789
|
}
|
|
2378
2790
|
__name(disconnectSession, "disconnectSession");
|
|
2791
|
+
let changeUnsubscribe;
|
|
2792
|
+
const onAccountsChanged = eventsFeature ? (listener) => {
|
|
2793
|
+
const off = eventsFeature.on("change", ({ accounts }) => {
|
|
2794
|
+
if (!accounts) return;
|
|
2795
|
+
if (!accounts.length) {
|
|
2796
|
+
listener([]);
|
|
2797
|
+
return;
|
|
2798
|
+
}
|
|
2799
|
+
currentAccount = accounts[0];
|
|
2800
|
+
sessionAccount = toSessionAccount(currentAccount);
|
|
2801
|
+
listener(accounts.map(toSessionAccount));
|
|
2802
|
+
});
|
|
2803
|
+
return off;
|
|
2804
|
+
} : void 0;
|
|
2379
2805
|
return {
|
|
2380
2806
|
account: sessionAccount,
|
|
2381
2807
|
connector: metadata,
|
|
2382
2808
|
disconnect: disconnectSession,
|
|
2809
|
+
onAccountsChanged: onAccountsChanged ? (listener) => {
|
|
2810
|
+
changeUnsubscribe = onAccountsChanged(listener);
|
|
2811
|
+
return () => {
|
|
2812
|
+
changeUnsubscribe?.();
|
|
2813
|
+
changeUnsubscribe = void 0;
|
|
2814
|
+
};
|
|
2815
|
+
} : void 0,
|
|
2383
2816
|
sendTransaction: sendTransaction2,
|
|
2384
2817
|
signMessage,
|
|
2385
2818
|
signTransaction
|
|
@@ -2594,9 +3027,9 @@ function createSolTransferController(config) {
|
|
|
2594
3027
|
const request = ensureAuthority(config2, authorityProvider);
|
|
2595
3028
|
setState(createAsyncState("loading"));
|
|
2596
3029
|
try {
|
|
2597
|
-
const
|
|
2598
|
-
setState(createAsyncState("success", { data:
|
|
2599
|
-
return
|
|
3030
|
+
const signature5 = await helper.sendTransfer(request, options);
|
|
3031
|
+
setState(createAsyncState("success", { data: signature5 }));
|
|
3032
|
+
return signature5;
|
|
2600
3033
|
} catch (error) {
|
|
2601
3034
|
setState(createAsyncState("error", { error }));
|
|
2602
3035
|
throw error;
|
|
@@ -2666,9 +3099,9 @@ function createSplTransferController(config) {
|
|
|
2666
3099
|
);
|
|
2667
3100
|
setState(createAsyncState("loading"));
|
|
2668
3101
|
try {
|
|
2669
|
-
const
|
|
2670
|
-
setState(createAsyncState("success", { data:
|
|
2671
|
-
return
|
|
3102
|
+
const signature5 = await helper.sendTransfer(resolvedConfig, options);
|
|
3103
|
+
setState(createAsyncState("success", { data: signature5 }));
|
|
3104
|
+
return signature5;
|
|
2672
3105
|
} catch (error) {
|
|
2673
3106
|
setState(createAsyncState("error", { error }));
|
|
2674
3107
|
throw error;
|
|
@@ -2696,6 +3129,172 @@ function createSplTransferController(config) {
|
|
|
2696
3129
|
}
|
|
2697
3130
|
__name(createSplTransferController, "createSplTransferController");
|
|
2698
3131
|
|
|
3132
|
+
// src/controllers/stakeController.ts
|
|
3133
|
+
function ensureAuthority2(input, resolveDefault) {
|
|
3134
|
+
const authority = input.authority ?? resolveDefault?.();
|
|
3135
|
+
if (!authority) {
|
|
3136
|
+
throw new Error("Connect a wallet or supply an `authority` before staking SOL.");
|
|
3137
|
+
}
|
|
3138
|
+
return {
|
|
3139
|
+
...input,
|
|
3140
|
+
authority
|
|
3141
|
+
};
|
|
3142
|
+
}
|
|
3143
|
+
__name(ensureAuthority2, "ensureAuthority");
|
|
3144
|
+
function ensureUnstakeAuthority(input, resolveDefault) {
|
|
3145
|
+
const authority = input.authority ?? resolveDefault?.();
|
|
3146
|
+
if (!authority) {
|
|
3147
|
+
throw new Error("Connect a wallet or supply an `authority` before unstaking SOL.");
|
|
3148
|
+
}
|
|
3149
|
+
return {
|
|
3150
|
+
...input,
|
|
3151
|
+
authority
|
|
3152
|
+
};
|
|
3153
|
+
}
|
|
3154
|
+
__name(ensureUnstakeAuthority, "ensureUnstakeAuthority");
|
|
3155
|
+
function ensureWithdrawAuthority(input, resolveDefault) {
|
|
3156
|
+
const authority = input.authority ?? resolveDefault?.();
|
|
3157
|
+
if (!authority) {
|
|
3158
|
+
throw new Error("Connect a wallet or supply an `authority` before withdrawing SOL.");
|
|
3159
|
+
}
|
|
3160
|
+
return {
|
|
3161
|
+
...input,
|
|
3162
|
+
authority
|
|
3163
|
+
};
|
|
3164
|
+
}
|
|
3165
|
+
__name(ensureWithdrawAuthority, "ensureWithdrawAuthority");
|
|
3166
|
+
function createStakeController(config) {
|
|
3167
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
3168
|
+
const unstakeListeners = /* @__PURE__ */ new Set();
|
|
3169
|
+
const withdrawListeners = /* @__PURE__ */ new Set();
|
|
3170
|
+
const helper = config.helper;
|
|
3171
|
+
const authorityProvider = config.authorityProvider;
|
|
3172
|
+
let state = createInitialAsyncState();
|
|
3173
|
+
let unstakeState = createInitialAsyncState();
|
|
3174
|
+
let withdrawState = createInitialAsyncState();
|
|
3175
|
+
function notify() {
|
|
3176
|
+
for (const listener of listeners) {
|
|
3177
|
+
listener();
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
__name(notify, "notify");
|
|
3181
|
+
function notifyUnstake() {
|
|
3182
|
+
for (const listener of unstakeListeners) {
|
|
3183
|
+
listener();
|
|
3184
|
+
}
|
|
3185
|
+
}
|
|
3186
|
+
__name(notifyUnstake, "notifyUnstake");
|
|
3187
|
+
function notifyWithdraw() {
|
|
3188
|
+
for (const listener of withdrawListeners) {
|
|
3189
|
+
listener();
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
__name(notifyWithdraw, "notifyWithdraw");
|
|
3193
|
+
function setState(next) {
|
|
3194
|
+
state = next;
|
|
3195
|
+
notify();
|
|
3196
|
+
}
|
|
3197
|
+
__name(setState, "setState");
|
|
3198
|
+
function setUnstakeState(next) {
|
|
3199
|
+
unstakeState = next;
|
|
3200
|
+
notifyUnstake();
|
|
3201
|
+
}
|
|
3202
|
+
__name(setUnstakeState, "setUnstakeState");
|
|
3203
|
+
function setWithdrawState(next) {
|
|
3204
|
+
withdrawState = next;
|
|
3205
|
+
notifyWithdraw();
|
|
3206
|
+
}
|
|
3207
|
+
__name(setWithdrawState, "setWithdrawState");
|
|
3208
|
+
async function stake(config2, options) {
|
|
3209
|
+
const request = ensureAuthority2(config2, authorityProvider);
|
|
3210
|
+
setState(createAsyncState("loading"));
|
|
3211
|
+
try {
|
|
3212
|
+
const signature5 = await helper.sendStake(request, options);
|
|
3213
|
+
setState(createAsyncState("success", { data: signature5 }));
|
|
3214
|
+
return signature5;
|
|
3215
|
+
} catch (error) {
|
|
3216
|
+
setState(createAsyncState("error", { error }));
|
|
3217
|
+
throw error;
|
|
3218
|
+
}
|
|
3219
|
+
}
|
|
3220
|
+
__name(stake, "stake");
|
|
3221
|
+
async function unstake(config2, options) {
|
|
3222
|
+
const request = ensureUnstakeAuthority(config2, authorityProvider);
|
|
3223
|
+
setUnstakeState(createAsyncState("loading"));
|
|
3224
|
+
try {
|
|
3225
|
+
const signature5 = await helper.sendUnstake(request, options);
|
|
3226
|
+
setUnstakeState(createAsyncState("success", { data: signature5 }));
|
|
3227
|
+
return signature5;
|
|
3228
|
+
} catch (error) {
|
|
3229
|
+
setUnstakeState(createAsyncState("error", { error }));
|
|
3230
|
+
throw error;
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
__name(unstake, "unstake");
|
|
3234
|
+
async function withdraw(config2, options) {
|
|
3235
|
+
const request = ensureWithdrawAuthority(config2, authorityProvider);
|
|
3236
|
+
setWithdrawState(createAsyncState("loading"));
|
|
3237
|
+
try {
|
|
3238
|
+
const signature5 = await helper.sendWithdraw(request, options);
|
|
3239
|
+
setWithdrawState(createAsyncState("success", { data: signature5 }));
|
|
3240
|
+
return signature5;
|
|
3241
|
+
} catch (error) {
|
|
3242
|
+
setWithdrawState(createAsyncState("error", { error }));
|
|
3243
|
+
throw error;
|
|
3244
|
+
}
|
|
3245
|
+
}
|
|
3246
|
+
__name(withdraw, "withdraw");
|
|
3247
|
+
function subscribe(listener) {
|
|
3248
|
+
listeners.add(listener);
|
|
3249
|
+
return () => {
|
|
3250
|
+
listeners.delete(listener);
|
|
3251
|
+
};
|
|
3252
|
+
}
|
|
3253
|
+
__name(subscribe, "subscribe");
|
|
3254
|
+
function subscribeUnstake(listener) {
|
|
3255
|
+
unstakeListeners.add(listener);
|
|
3256
|
+
return () => {
|
|
3257
|
+
unstakeListeners.delete(listener);
|
|
3258
|
+
};
|
|
3259
|
+
}
|
|
3260
|
+
__name(subscribeUnstake, "subscribeUnstake");
|
|
3261
|
+
function subscribeWithdraw(listener) {
|
|
3262
|
+
withdrawListeners.add(listener);
|
|
3263
|
+
return () => {
|
|
3264
|
+
withdrawListeners.delete(listener);
|
|
3265
|
+
};
|
|
3266
|
+
}
|
|
3267
|
+
__name(subscribeWithdraw, "subscribeWithdraw");
|
|
3268
|
+
function reset() {
|
|
3269
|
+
setState(createInitialAsyncState());
|
|
3270
|
+
}
|
|
3271
|
+
__name(reset, "reset");
|
|
3272
|
+
function resetUnstake() {
|
|
3273
|
+
setUnstakeState(createInitialAsyncState());
|
|
3274
|
+
}
|
|
3275
|
+
__name(resetUnstake, "resetUnstake");
|
|
3276
|
+
function resetWithdraw() {
|
|
3277
|
+
setWithdrawState(createInitialAsyncState());
|
|
3278
|
+
}
|
|
3279
|
+
__name(resetWithdraw, "resetWithdraw");
|
|
3280
|
+
return {
|
|
3281
|
+
getHelper: /* @__PURE__ */ __name(() => helper, "getHelper"),
|
|
3282
|
+
getState: /* @__PURE__ */ __name(() => state, "getState"),
|
|
3283
|
+
getUnstakeState: /* @__PURE__ */ __name(() => unstakeState, "getUnstakeState"),
|
|
3284
|
+
getWithdrawState: /* @__PURE__ */ __name(() => withdrawState, "getWithdrawState"),
|
|
3285
|
+
reset,
|
|
3286
|
+
resetUnstake,
|
|
3287
|
+
resetWithdraw,
|
|
3288
|
+
stake,
|
|
3289
|
+
unstake,
|
|
3290
|
+
withdraw,
|
|
3291
|
+
subscribe,
|
|
3292
|
+
subscribeUnstake,
|
|
3293
|
+
subscribeWithdraw
|
|
3294
|
+
};
|
|
3295
|
+
}
|
|
3296
|
+
__name(createStakeController, "createStakeController");
|
|
3297
|
+
|
|
2699
3298
|
// src/serialization/json.ts
|
|
2700
3299
|
function bigintToJson(value) {
|
|
2701
3300
|
return value.toString();
|
|
@@ -2770,7 +3369,7 @@ function insertReferenceKeys(references, transaction) {
|
|
|
2770
3369
|
const targetInstruction = transaction.instructions[index];
|
|
2771
3370
|
const accounts = [
|
|
2772
3371
|
...targetInstruction.accounts ?? [],
|
|
2773
|
-
...references.map((
|
|
3372
|
+
...references.map((address5) => ({ address: address5, role: AccountRole.READONLY }))
|
|
2774
3373
|
];
|
|
2775
3374
|
const updatedInstructions = [...transaction.instructions];
|
|
2776
3375
|
updatedInstructions.splice(index, 1, { ...targetInstruction, accounts });
|
|
@@ -2925,9 +3524,9 @@ function createTransactionPoolController(config) {
|
|
|
2925
3524
|
const target = resolvePrepared(overridePrepared);
|
|
2926
3525
|
sendStateStore.setSnapshot(createAsyncState("loading"));
|
|
2927
3526
|
try {
|
|
2928
|
-
const
|
|
2929
|
-
sendStateStore.setSnapshot(createAsyncState("success", { data:
|
|
2930
|
-
return
|
|
3527
|
+
const signature5 = await helper.send(target, rest);
|
|
3528
|
+
sendStateStore.setSnapshot(createAsyncState("success", { data: signature5 }));
|
|
3529
|
+
return signature5;
|
|
2931
3530
|
} catch (error) {
|
|
2932
3531
|
sendStateStore.setSnapshot(createAsyncState("error", { error }));
|
|
2933
3532
|
throw error;
|
|
@@ -2941,15 +3540,15 @@ function createTransactionPoolController(config) {
|
|
|
2941
3540
|
sendStateStore.setSnapshot(createAsyncState("loading"));
|
|
2942
3541
|
try {
|
|
2943
3542
|
const restWithLifetime = resolveLifetimeOptions(rest);
|
|
2944
|
-
const
|
|
3543
|
+
const signature5 = await helper.prepareAndSend(
|
|
2945
3544
|
{
|
|
2946
3545
|
...restWithLifetime,
|
|
2947
3546
|
instructions: nextInstructions
|
|
2948
3547
|
},
|
|
2949
3548
|
sendOptions
|
|
2950
3549
|
);
|
|
2951
|
-
sendStateStore.setSnapshot(createAsyncState("success", { data:
|
|
2952
|
-
return
|
|
3550
|
+
sendStateStore.setSnapshot(createAsyncState("success", { data: signature5 }));
|
|
3551
|
+
return signature5;
|
|
2953
3552
|
} catch (error) {
|
|
2954
3553
|
sendStateStore.setSnapshot(createAsyncState("error", { error }));
|
|
2955
3554
|
throw error;
|
|
@@ -3040,6 +3639,6 @@ function stableStringify(value) {
|
|
|
3040
3639
|
}
|
|
3041
3640
|
__name(stableStringify, "stableStringify");
|
|
3042
3641
|
|
|
3043
|
-
export { LAMPORTS_PER_SOL, SIGNATURE_STATUS_TIMEOUT_MS, applyRatio, applySerializableState, assertDecimals, assertNonNegative, autoDiscover, backpack, bigintFromJson, bigintToJson, checkedAdd, checkedDivide, checkedMultiply, checkedSubtract, confirmationMeetsCommitment, connectWallet, createAsyncState, createClient, createClientStore, createDefaultClient, createDefaultClientStore, createInitialAsyncState, createInitialClientState, createRatio, createSolTransferController, createSolTransferHelper, createSolanaRpcClient, createSplTokenHelper, createSplTransferController, createTokenAmount, createTransactionHelper, createTransactionPoolController, createTransactionRecipe, createWalletRegistry, createWalletStandardConnector, defaultWalletConnectors, deriveConfirmationStatus, deserializeSolanaState, disconnectWallet, fetchAccount, fetchBalance, getInitialSerializableState, getWalletStandardConnectors, injected, insertReferenceKey, insertReferenceKeys, lamports, lamportsFromJson, lamportsFromSol, lamportsMath, lamportsToJson, lamportsToSolString, normalizeSignature, phantom, pow10, prepareTransaction, requestAirdrop, resolveClientConfig, resolveCluster, sendTransaction, serializeSolanaState, setCluster, solflare, stableStringify, subscribeSolanaState, toAddress2 as toAddress, toAddressString, toBigint2 as toBigint, transactionToBase64, transactionToBase64WithSigners, watchWalletStandardConnectors };
|
|
3642
|
+
export { LAMPORTS_PER_SOL, SIGNATURE_STATUS_TIMEOUT_MS, applyRatio, applySerializableState, assertDecimals, assertNonNegative, autoDiscover, backpack, bigintFromJson, bigintToJson, checkedAdd, checkedDivide, checkedMultiply, checkedSubtract, confirmationMeetsCommitment, connectWallet, createAsyncState, createClient, createClientStore, createDefaultClient, createDefaultClientStore, createInitialAsyncState, createInitialClientState, createRatio, createSolTransferController, createSolTransferHelper, createSolanaRpcClient, createSplTokenHelper, createSplTransferController, createStakeController, createStakeHelper, createTokenAmount, createTransactionHelper, createTransactionPoolController, createTransactionRecipe, createWalletRegistry, createWalletStandardConnector, defaultWalletConnectors, deriveConfirmationStatus, deserializeSolanaState, disconnectWallet, fetchAccount, fetchBalance, fetchLookupTable, fetchLookupTables, fetchNonceAccount, getInitialSerializableState, getWalletStandardConnectors, injected, insertReferenceKey, insertReferenceKeys, lamports, lamportsFromJson, lamportsFromSol, lamportsMath, lamportsToJson, lamportsToSolString, normalizeSignature, phantom, pow10, prepareTransaction, requestAirdrop, resolveClientConfig, resolveCluster, sendTransaction, serializeSolanaState, setCluster, solflare, stableStringify, subscribeSolanaState, toAddress2 as toAddress, toAddressString, toBigint2 as toBigint, transactionToBase64, transactionToBase64WithSigners, watchWalletStandardConnectors };
|
|
3044
3643
|
//# sourceMappingURL=index.browser.mjs.map
|
|
3045
3644
|
//# sourceMappingURL=index.browser.mjs.map
|