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