@dynamic-labs/solana-core 4.0.0-alpha.8 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +1,27 @@
1
- import { Connection } from '@solana/web3.js';
2
- import { Chain, IHardwareWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
1
+ import { Connection, ConnectionConfig } from '@solana/web3.js';
2
+ import { Chain, IHardwareWalletConnector, WalletConnectorBase, WalletMetadata } from '@dynamic-labs/wallet-connector-core';
3
3
  import { GenericNetwork } from '@dynamic-labs/types';
4
4
  import { WalletBookSchema } from '@dynamic-labs/wallet-book';
5
5
  import { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';
6
6
  import { IChainRpcProviders } from '../rpc';
7
7
  import { SolanaWallet } from '../wallet';
8
8
  import { ISolana } from '../types';
9
- export type SolWalletConnectorOpts = {
9
+ export type SolanaWalletConnectorOpts = {
10
10
  chainRpcProviders: IChainRpcProviders;
11
11
  solNetworks: GenericNetwork[];
12
12
  walletBook: WalletBookSchema;
13
+ metadata?: WalletMetadata;
14
+ connectionConfig?: ConnectionConfig;
13
15
  };
14
- export declare abstract class SolWalletConnector extends WalletConnectorBase<typeof SolanaWallet> implements IHardwareWalletConnector {
16
+ export declare abstract class SolanaWalletConnector extends WalletConnectorBase<typeof SolanaWallet> implements IHardwareWalletConnector {
15
17
  isHardwareWalletEnabled: boolean;
16
18
  verifiedCredentials: JwtVerifiedCredential[];
17
19
  solNetworks: GenericNetwork[];
18
20
  ChainWallet: typeof SolanaWallet;
19
21
  supportedChains: Chain[];
20
22
  connectedChain: Chain;
21
- constructor(opts: SolWalletConnectorOpts);
23
+ protected connectionConfig: ConnectionConfig | undefined;
24
+ constructor(opts: SolanaWalletConnectorOpts);
22
25
  getNetwork(): Promise<string>;
23
26
  endSession(): Promise<void>;
24
27
  getWalletClient(): Connection;
@@ -3,13 +3,12 @@ import { __awaiter } from '../../_virtual/_tslib.js';
3
3
  import { PublicKey, Connection, Transaction, TransactionInstruction } from '@solana/web3.js';
4
4
  import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
5
5
  import { DynamicError, isLedgerAddressViaVerifiedCredentials, NotSupportedError } from '@dynamic-labs/utils';
6
- import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
7
6
  import { SolanaWallet } from '../wallet/SolanaWallet.js';
8
7
  import { extractNonce } from '../utils/extractNonce/extractNonce.js';
9
8
  import { getGenesisHashLSKey } from '../utils/getGenesisHashLSKey/getGenesisHashLSKey.js';
10
9
 
11
10
  const MEMO_PROGRAM_ID = new PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr');
12
- class SolWalletConnector extends WalletConnectorBase {
11
+ class SolanaWalletConnector extends WalletConnectorBase {
13
12
  constructor(opts) {
14
13
  var _a;
15
14
  super(opts);
@@ -20,7 +19,8 @@ class SolWalletConnector extends WalletConnectorBase {
20
19
  this.connectedChain = 'SOL';
21
20
  this.solNetworks = opts.solNetworks;
22
21
  this.chainRpcProviders = opts.chainRpcProviders;
23
- (_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerSolanaProviders();
22
+ this.connectionConfig = opts.connectionConfig;
23
+ (_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerSolanaProviders(this.connectionConfig);
24
24
  }
25
25
  getNetwork() {
26
26
  return __awaiter(this, void 0, void 0, function* () {
@@ -51,13 +51,13 @@ class SolWalletConnector extends WalletConnectorBase {
51
51
  });
52
52
  }
53
53
  getWalletClient() {
54
- var _a;
54
+ var _a, _b;
55
55
  const [network] = this.solNetworks;
56
56
  if (!network) {
57
57
  throw new DynamicError('No enabled networks');
58
58
  }
59
59
  const rpcUrl = ((_a = network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) || network.rpcUrls[0];
60
- return new Connection(rpcUrl, 'confirmed');
60
+ return new Connection(rpcUrl, (_b = this.connectionConfig) !== null && _b !== void 0 ? _b : 'confirmed');
61
61
  }
62
62
  getPublicClient() {
63
63
  return __awaiter(this, void 0, void 0, function* () {
@@ -88,10 +88,8 @@ class SolWalletConnector extends WalletConnectorBase {
88
88
  return lamports / 1000000000;
89
89
  }
90
90
  canConnectWithHardwareWallet() {
91
- const wallet = findWalletBookWallet(this.walletBook, this.key);
92
- if (!wallet || !wallet.hardwareWallets)
93
- return false;
94
- return wallet.hardwareWallets.includes('ledger');
91
+ var _a;
92
+ return Boolean((_a = this.metadata.supportedHardwareWallets) === null || _a === void 0 ? void 0 : _a.includes('ledger'));
95
93
  }
96
94
  signMessage(messageToSign) {
97
95
  const _super = Object.create(null, {
@@ -168,4 +166,4 @@ class SolWalletConnector extends WalletConnectorBase {
168
166
  }
169
167
  }
170
168
 
171
- export { SolWalletConnector };
169
+ export { SolanaWalletConnector };
@@ -1 +1 @@
1
- export * from './SolWalletConnector';
1
+ export * from './SolanaWalletConnector';
package/src/index.cjs CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var assertPackageVersion = require('@dynamic-labs/assert-package-version');
7
7
  var _package = require('../package.cjs');
8
- var SolWalletConnector = require('./connector/SolWalletConnector.cjs');
8
+ var SolanaWalletConnector = require('./connector/SolanaWalletConnector.cjs');
9
9
  require('./rpc/RpcProviderSolana/RpcProviderSolana.cjs');
10
10
  var rpcProviders = require('@dynamic-labs/rpc-providers');
11
11
  var solanaProvidersSelector = require('./rpc/solanaProvidersSelector/solanaProvidersSelector.cjs');
@@ -14,6 +14,7 @@ var decodeTransactionFromBase64 = require('./utils/decodeTransactionFromBase64/d
14
14
  var isVersionedTransaction = require('./utils/isVersionedTransaction/isVersionedTransaction.cjs');
15
15
  var encodeTransactionToBase64 = require('./utils/encodeTransactionToBase64/encodeTransactionToBase64.cjs');
16
16
  var getGenesisHashLSKey = require('./utils/getGenesisHashLSKey/getGenesisHashLSKey.cjs');
17
+ var isTransactionSigned = require('./utils/isTransactionSigned/isTransactionSigned.cjs');
17
18
  var SolanaWallet = require('./wallet/SolanaWallet.cjs');
18
19
  var isSolanaWallet = require('./wallet/isSolanaWallet/isSolanaWallet.cjs');
19
20
  var isLedgerSolanaWallet = require('./wallet/isLedgerSolanaWallet/isLedgerSolanaWallet.cjs');
@@ -21,13 +22,14 @@ var constants = require('./constants.cjs');
21
22
 
22
23
  assertPackageVersion.assertPackageVersion('@dynamic-labs/solana-core', _package.version);
23
24
 
24
- exports.SolWalletConnector = SolWalletConnector.SolWalletConnector;
25
+ exports.SolanaWalletConnector = SolanaWalletConnector.SolanaWalletConnector;
25
26
  exports.solanaProvidersSelector = solanaProvidersSelector.solanaProvidersSelector;
26
27
  exports.SolanaUiTransaction = SolanaUiTransaction.SolanaUiTransaction;
27
28
  exports.decodeTransactionFromBase64 = decodeTransactionFromBase64.decodeTransactionFromBase64;
28
29
  exports.isVersionedTransaction = isVersionedTransaction.isVersionedTransaction;
29
30
  exports.encodeTransactionToBase64 = encodeTransactionToBase64.encodeTransactionToBase64;
30
31
  exports.getGenesisHashLSKey = getGenesisHashLSKey.getGenesisHashLSKey;
32
+ exports.isTxAlreadySigned = isTransactionSigned.isTxAlreadySigned;
31
33
  exports.SolanaWallet = SolanaWallet.SolanaWallet;
32
34
  exports.isSolanaWallet = isSolanaWallet.isSolanaWallet;
33
35
  exports.isLedgerSolanaWallet = isLedgerSolanaWallet.isLedgerSolanaWallet;
package/src/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use client'
2
2
  import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
3
3
  import { version } from '../package.js';
4
- export { SolWalletConnector } from './connector/SolWalletConnector.js';
4
+ export { SolanaWalletConnector } from './connector/SolanaWalletConnector.js';
5
5
  import './rpc/RpcProviderSolana/RpcProviderSolana.js';
6
6
  export * from '@dynamic-labs/rpc-providers';
7
7
  export { solanaProvidersSelector } from './rpc/solanaProvidersSelector/solanaProvidersSelector.js';
@@ -10,6 +10,7 @@ export { decodeTransactionFromBase64 } from './utils/decodeTransactionFromBase64
10
10
  export { isVersionedTransaction } from './utils/isVersionedTransaction/isVersionedTransaction.js';
11
11
  export { encodeTransactionToBase64 } from './utils/encodeTransactionToBase64/encodeTransactionToBase64.js';
12
12
  export { getGenesisHashLSKey } from './utils/getGenesisHashLSKey/getGenesisHashLSKey.js';
13
+ export { isTxAlreadySigned } from './utils/isTransactionSigned/isTransactionSigned.js';
13
14
  export { SolanaWallet } from './wallet/SolanaWallet.js';
14
15
  export { isSolanaWallet } from './wallet/isSolanaWallet/isSolanaWallet.js';
15
16
  export { isLedgerSolanaWallet } from './wallet/isLedgerSolanaWallet/isLedgerSolanaWallet.js';
@@ -9,14 +9,14 @@ rpcProviders.ChainRpcProviders.getSolanaProviderByChainId = (rpcProviders, chain
9
9
  const provider = (_a = rpcProviders['solana']) === null || _a === void 0 ? void 0 : _a.find((rpcProvider) => rpcProvider.chainId === chainId);
10
10
  return provider;
11
11
  };
12
- rpcProviders.ChainRpcProviders.registerSolanaProviders = () => {
12
+ rpcProviders.ChainRpcProviders.registerSolanaProviders = (connectionConfig) => {
13
13
  rpcProviders.ChainRpcProviders.registerChainProviders(rpcProviders.ProviderChain.SOLANA, (config) => {
14
14
  const rpcProviders = {};
15
15
  if (config === null || config === void 0 ? void 0 : config.solana) {
16
16
  rpcProviders.solana = config.solana.map((network) => {
17
17
  var _a;
18
18
  const rpcUrl = ((_a = network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) || network.rpcUrls[0];
19
- const provider = new web3_js.Connection(rpcUrl);
19
+ const provider = new web3_js.Connection(rpcUrl, connectionConfig);
20
20
  return {
21
21
  chainId: network.chainId.toString(),
22
22
  chainName: network.name,
@@ -1,4 +1,4 @@
1
- import { Connection } from '@solana/web3.js';
1
+ import { Connection, ConnectionConfig } from '@solana/web3.js';
2
2
  import { RpcProviders } from '@dynamic-labs/rpc-providers';
3
3
  type ISolanaRpcProvider = {
4
4
  chainId: string;
@@ -12,7 +12,7 @@ declare module '@dynamic-labs/rpc-providers' {
12
12
  }
13
13
  interface IChainRpcProviders {
14
14
  getSolanaProviderByChainId(rpcProviders: RpcProviders, chainId: string): SolanaRpcProvider | undefined;
15
- registerSolanaProviders(): void;
15
+ registerSolanaProviders(connectionConfig?: ConnectionConfig): void;
16
16
  }
17
17
  }
18
18
  export {};
@@ -7,14 +7,14 @@ ChainRpcProviders.getSolanaProviderByChainId = (rpcProviders, chainId) => {
7
7
  const provider = (_a = rpcProviders['solana']) === null || _a === void 0 ? void 0 : _a.find((rpcProvider) => rpcProvider.chainId === chainId);
8
8
  return provider;
9
9
  };
10
- ChainRpcProviders.registerSolanaProviders = () => {
10
+ ChainRpcProviders.registerSolanaProviders = (connectionConfig) => {
11
11
  ChainRpcProviders.registerChainProviders(ProviderChain.SOLANA, (config) => {
12
12
  const rpcProviders = {};
13
13
  if (config === null || config === void 0 ? void 0 : config.solana) {
14
14
  rpcProviders.solana = config.solana.map((network) => {
15
15
  var _a;
16
16
  const rpcUrl = ((_a = network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) || network.rpcUrls[0];
17
- const provider = new Connection(rpcUrl);
17
+ const provider = new Connection(rpcUrl, connectionConfig);
18
18
  return {
19
19
  chainId: network.chainId.toString(),
20
20
  chainName: network.name,
@@ -10,16 +10,69 @@ var utils = require('@dynamic-labs/utils');
10
10
 
11
11
  const LAMPORTS_PER_SOL = 1000000000;
12
12
  class SolanaUiTransaction {
13
- constructor({ onSubmit, from, connection, originalTransaction, }) {
13
+ constructor({ onSubmit, from, connection, multipleTransactions, }) {
14
14
  this.chain = 'SOL';
15
15
  this.data = undefined;
16
16
  this.fee = { gas: undefined };
17
- this.feeDeducted = false;
18
17
  this.formatNonNativeToken = (value, decimals) => (Number(value) / Number(Math.pow(10, decimals))).toString();
19
18
  this.from = from;
20
19
  this.onSubmit = onSubmit;
21
20
  this.connection = connection;
22
- this.originalTransaction = originalTransaction;
21
+ this.multipleTransactions = multipleTransactions;
22
+ }
23
+ fetchFee() {
24
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
25
+ if (this.fee.gas)
26
+ return;
27
+ let transactions = this.multipleTransactions;
28
+ // for send balance flow, create the transaction and then estimate it
29
+ if (!transactions) {
30
+ const tx = yield this.createTransactionSafe();
31
+ if (!tx)
32
+ return;
33
+ transactions = tx instanceof Array ? tx : [tx];
34
+ }
35
+ const compiledMessages = yield Promise.all(transactions.map((tx) => _tslib.__awaiter(this, void 0, void 0, function* () {
36
+ if ('version' in tx) {
37
+ return tx.message;
38
+ }
39
+ return tx.compileMessage();
40
+ })));
41
+ if (compiledMessages.some((msg) => !msg)) {
42
+ throw new Error('Invalid transaction');
43
+ }
44
+ const getFeeWithRetry = (message) => _tslib.__awaiter(this, void 0, void 0, function* () {
45
+ let res = yield this.connection.getFeeForMessage(message, 'confirmed');
46
+ let retryCount = 0;
47
+ while (res.value === null && retryCount < 5) {
48
+ res = yield this.connection.getFeeForMessage(message, 'confirmed');
49
+ retryCount++;
50
+ }
51
+ return res.value ? BigInt(res.value) : BigInt(0);
52
+ });
53
+ const fees = yield Promise.all(compiledMessages.map((message) => getFeeWithRetry(message)));
54
+ this.fee.gas = fees.reduce((acc, fee) => acc + fee, BigInt(0));
55
+ if (this.fee.gas === BigInt(0)) {
56
+ this.fee.gas = undefined;
57
+ }
58
+ });
59
+ }
60
+ // if one of the transactions is not sponsored,
61
+ // then the simulation will have a solana transfer in it if it was successful
62
+ isGasSponsored() {
63
+ var _a;
64
+ if (!((_a = this.multipleTransactions) === null || _a === void 0 ? void 0 : _a.length))
65
+ return false;
66
+ return this.multipleTransactions.every((tx) => {
67
+ var _a;
68
+ if ('version' in tx) {
69
+ return this.from !== tx.message.staticAccountKeys[0].toBase58();
70
+ }
71
+ if ('feePayer' in tx) {
72
+ return this.from !== ((_a = tx.feePayer) === null || _a === void 0 ? void 0 : _a.toBase58());
73
+ }
74
+ return false;
75
+ });
23
76
  }
24
77
  parse(input) {
25
78
  const floatValue = parseFloat(input);
@@ -40,7 +93,11 @@ class SolanaUiTransaction {
40
93
  }
41
94
  submit() {
42
95
  return _tslib.__awaiter(this, void 0, void 0, function* () {
43
- const sendTransaction = yield this.createTransaction();
96
+ if (this.multipleTransactions) {
97
+ return this.onSubmit();
98
+ }
99
+ // send balance modal transactions
100
+ const sendTransaction = (yield this.createTransaction());
44
101
  return this.onSubmit(sendTransaction);
45
102
  });
46
103
  }
@@ -57,37 +114,6 @@ class SolanaUiTransaction {
57
114
  }
58
115
  return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address);
59
116
  }
60
- fetchFee() {
61
- return _tslib.__awaiter(this, void 0, void 0, function* () {
62
- if (this.fee.gas)
63
- return;
64
- const transaction = yield this.createTransactionSafe();
65
- if (!transaction) {
66
- return;
67
- }
68
- let compiledMessage;
69
- if ('version' in transaction) {
70
- compiledMessage = transaction.message;
71
- }
72
- else {
73
- compiledMessage = transaction.compileMessage();
74
- }
75
- if (!compiledMessage) {
76
- throw new Error('Invalid transaction');
77
- }
78
- let res = yield this.connection.getFeeForMessage(compiledMessage);
79
- let retryCount = 0;
80
- while (res.value === null && retryCount < 5) {
81
- res = yield this.connection.getFeeForMessage(compiledMessage);
82
- retryCount++;
83
- }
84
- this.fee.gas = res.value ? BigInt(res.value) : undefined;
85
- if (!this.feeDeducted && this.fee.gas && this.value) {
86
- this.value = this.value - this.fee.gas;
87
- this.feeDeducted = true;
88
- }
89
- });
90
- }
91
117
  createTransaction() {
92
118
  return _tslib.__awaiter(this, void 0, void 0, function* () {
93
119
  var _a;
@@ -95,8 +121,8 @@ class SolanaUiTransaction {
95
121
  if (!to) {
96
122
  throw new Error('Destination is required');
97
123
  }
98
- if (this.originalTransaction) {
99
- return this.originalTransaction;
124
+ if (this.multipleTransactions) {
125
+ return this.multipleTransactions;
100
126
  }
101
127
  const sendTransaction = new web3_js.Transaction();
102
128
  const fromPubkey = new web3_js.PublicKey(this.from);
@@ -4,11 +4,10 @@ export declare const LAMPORTS_PER_SOL = 1000000000;
4
4
  type SolanaUiTransactionProps = {
5
5
  from: string;
6
6
  connection: Connection;
7
- onSubmit: (transaction: Transaction | VersionedTransaction) => Promise<string>;
8
- originalTransaction?: Transaction | VersionedTransaction;
7
+ onSubmit: (transaction?: Transaction | VersionedTransaction) => Promise<any>;
8
+ multipleTransactions?: (Transaction | VersionedTransaction)[];
9
9
  };
10
10
  export declare class SolanaUiTransaction implements IUITransaction {
11
- notEnoughFundsError: boolean | undefined;
12
11
  to: string | undefined;
13
12
  from: string;
14
13
  value: bigint | undefined;
@@ -18,22 +17,23 @@ export declare class SolanaUiTransaction implements IUITransaction {
18
17
  fee: {
19
18
  gas: bigint | undefined;
20
19
  };
21
- originalTransaction: Transaction | VersionedTransaction | undefined;
22
- feeDeducted: boolean;
20
+ multipleTransactions?: (Transaction | VersionedTransaction)[];
23
21
  nonNativeAddress?: string;
24
22
  nonNativeDecimal?: number;
25
23
  nonNativeValue?: bigint;
26
24
  private onSubmit;
27
25
  private connection;
28
- constructor({ onSubmit, from, connection, originalTransaction, }: SolanaUiTransactionProps);
26
+ constructor({ onSubmit, from, connection, multipleTransactions, }: SolanaUiTransactionProps);
27
+ nativePrice?: number | undefined;
28
+ fetchFee(): Promise<void>;
29
+ isGasSponsored(): boolean;
29
30
  parse(input: string): bigint;
30
31
  parseNonNativeToken(input: string, decimals: number): bigint;
31
32
  formatNonNativeToken: (value: bigint, decimals: number) => string;
32
33
  format(value: bigint, { precision }?: IUITransactionFormatOptions): string;
33
- submit(): Promise<string>;
34
+ submit(): Promise<any>;
34
35
  getBalance(): Promise<bigint>;
35
36
  validateAddressFormat(address: string): boolean;
36
- fetchFee(): Promise<void>;
37
37
  private createTransaction;
38
38
  private createTransactionSafe;
39
39
  }
@@ -6,16 +6,69 @@ import { formatNumberText } from '@dynamic-labs/utils';
6
6
 
7
7
  const LAMPORTS_PER_SOL = 1000000000;
8
8
  class SolanaUiTransaction {
9
- constructor({ onSubmit, from, connection, originalTransaction, }) {
9
+ constructor({ onSubmit, from, connection, multipleTransactions, }) {
10
10
  this.chain = 'SOL';
11
11
  this.data = undefined;
12
12
  this.fee = { gas: undefined };
13
- this.feeDeducted = false;
14
13
  this.formatNonNativeToken = (value, decimals) => (Number(value) / Number(Math.pow(10, decimals))).toString();
15
14
  this.from = from;
16
15
  this.onSubmit = onSubmit;
17
16
  this.connection = connection;
18
- this.originalTransaction = originalTransaction;
17
+ this.multipleTransactions = multipleTransactions;
18
+ }
19
+ fetchFee() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ if (this.fee.gas)
22
+ return;
23
+ let transactions = this.multipleTransactions;
24
+ // for send balance flow, create the transaction and then estimate it
25
+ if (!transactions) {
26
+ const tx = yield this.createTransactionSafe();
27
+ if (!tx)
28
+ return;
29
+ transactions = tx instanceof Array ? tx : [tx];
30
+ }
31
+ const compiledMessages = yield Promise.all(transactions.map((tx) => __awaiter(this, void 0, void 0, function* () {
32
+ if ('version' in tx) {
33
+ return tx.message;
34
+ }
35
+ return tx.compileMessage();
36
+ })));
37
+ if (compiledMessages.some((msg) => !msg)) {
38
+ throw new Error('Invalid transaction');
39
+ }
40
+ const getFeeWithRetry = (message) => __awaiter(this, void 0, void 0, function* () {
41
+ let res = yield this.connection.getFeeForMessage(message, 'confirmed');
42
+ let retryCount = 0;
43
+ while (res.value === null && retryCount < 5) {
44
+ res = yield this.connection.getFeeForMessage(message, 'confirmed');
45
+ retryCount++;
46
+ }
47
+ return res.value ? BigInt(res.value) : BigInt(0);
48
+ });
49
+ const fees = yield Promise.all(compiledMessages.map((message) => getFeeWithRetry(message)));
50
+ this.fee.gas = fees.reduce((acc, fee) => acc + fee, BigInt(0));
51
+ if (this.fee.gas === BigInt(0)) {
52
+ this.fee.gas = undefined;
53
+ }
54
+ });
55
+ }
56
+ // if one of the transactions is not sponsored,
57
+ // then the simulation will have a solana transfer in it if it was successful
58
+ isGasSponsored() {
59
+ var _a;
60
+ if (!((_a = this.multipleTransactions) === null || _a === void 0 ? void 0 : _a.length))
61
+ return false;
62
+ return this.multipleTransactions.every((tx) => {
63
+ var _a;
64
+ if ('version' in tx) {
65
+ return this.from !== tx.message.staticAccountKeys[0].toBase58();
66
+ }
67
+ if ('feePayer' in tx) {
68
+ return this.from !== ((_a = tx.feePayer) === null || _a === void 0 ? void 0 : _a.toBase58());
69
+ }
70
+ return false;
71
+ });
19
72
  }
20
73
  parse(input) {
21
74
  const floatValue = parseFloat(input);
@@ -36,7 +89,11 @@ class SolanaUiTransaction {
36
89
  }
37
90
  submit() {
38
91
  return __awaiter(this, void 0, void 0, function* () {
39
- const sendTransaction = yield this.createTransaction();
92
+ if (this.multipleTransactions) {
93
+ return this.onSubmit();
94
+ }
95
+ // send balance modal transactions
96
+ const sendTransaction = (yield this.createTransaction());
40
97
  return this.onSubmit(sendTransaction);
41
98
  });
42
99
  }
@@ -53,37 +110,6 @@ class SolanaUiTransaction {
53
110
  }
54
111
  return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address);
55
112
  }
56
- fetchFee() {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- if (this.fee.gas)
59
- return;
60
- const transaction = yield this.createTransactionSafe();
61
- if (!transaction) {
62
- return;
63
- }
64
- let compiledMessage;
65
- if ('version' in transaction) {
66
- compiledMessage = transaction.message;
67
- }
68
- else {
69
- compiledMessage = transaction.compileMessage();
70
- }
71
- if (!compiledMessage) {
72
- throw new Error('Invalid transaction');
73
- }
74
- let res = yield this.connection.getFeeForMessage(compiledMessage);
75
- let retryCount = 0;
76
- while (res.value === null && retryCount < 5) {
77
- res = yield this.connection.getFeeForMessage(compiledMessage);
78
- retryCount++;
79
- }
80
- this.fee.gas = res.value ? BigInt(res.value) : undefined;
81
- if (!this.feeDeducted && this.fee.gas && this.value) {
82
- this.value = this.value - this.fee.gas;
83
- this.feeDeducted = true;
84
- }
85
- });
86
- }
87
113
  createTransaction() {
88
114
  return __awaiter(this, void 0, void 0, function* () {
89
115
  var _a;
@@ -91,8 +117,8 @@ class SolanaUiTransaction {
91
117
  if (!to) {
92
118
  throw new Error('Destination is required');
93
119
  }
94
- if (this.originalTransaction) {
95
- return this.originalTransaction;
120
+ if (this.multipleTransactions) {
121
+ return this.multipleTransactions;
96
122
  }
97
123
  const sendTransaction = new Transaction();
98
124
  const fromPubkey = new PublicKey(this.from);
@@ -3,3 +3,4 @@ export { decodeTransactionFromBase64 } from './decodeTransactionFromBase64';
3
3
  export { isVersionedTransaction } from './isVersionedTransaction';
4
4
  export { encodeTransactionToBase64, type EncodedTransaction, } from './encodeTransactionToBase64';
5
5
  export { getGenesisHashLSKey } from './getGenesisHashLSKey';
6
+ export { isTxAlreadySigned } from './isTransactionSigned';
@@ -0,0 +1 @@
1
+ export * from './isTransactionSigned';
@@ -0,0 +1,17 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const isTxAlreadySigned = (transaction) => {
7
+ let alreadySigned = false;
8
+ if ('version' in transaction) {
9
+ alreadySigned = transaction.signatures.some((sig) => !sig.every((byte) => byte === 0));
10
+ }
11
+ else {
12
+ alreadySigned = transaction.signatures.some((sig) => sig.signature);
13
+ }
14
+ return alreadySigned;
15
+ };
16
+
17
+ exports.isTxAlreadySigned = isTxAlreadySigned;
@@ -0,0 +1,2 @@
1
+ import { Transaction, VersionedTransaction } from '@solana/web3.js';
2
+ export declare const isTxAlreadySigned: (transaction: Transaction | VersionedTransaction) => boolean;
@@ -0,0 +1,13 @@
1
+ 'use client'
2
+ const isTxAlreadySigned = (transaction) => {
3
+ let alreadySigned = false;
4
+ if ('version' in transaction) {
5
+ alreadySigned = transaction.signatures.some((sig) => !sig.every((byte) => byte === 0));
6
+ }
7
+ else {
8
+ alreadySigned = transaction.signatures.some((sig) => sig.signature);
9
+ }
10
+ return alreadySigned;
11
+ };
12
+
13
+ export { isTxAlreadySigned };
@@ -4,10 +4,38 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../_virtual/_tslib.cjs');
7
+ var web3_js = require('@solana/web3.js');
7
8
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
9
  var utils = require('@dynamic-labs/utils');
9
10
 
10
11
  class SolanaWallet extends walletConnectorCore.Wallet {
12
+ /**
13
+ * Sends the native balance of the wallet to the given address.
14
+ * @param amount - The amount of balance to send (in SOL).
15
+ * @param toAddress - The address to send the balance to.
16
+ * @returns The signature of the sent transaction.
17
+ */
18
+ sendBalance(_a) {
19
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
20
+ const connection = yield this.getConnection();
21
+ const signer = yield this.getSigner();
22
+ const { blockhash } = yield connection.getLatestBlockhash('finalized');
23
+ const message = new web3_js.TransactionMessage({
24
+ instructions: [
25
+ web3_js.SystemProgram.transfer({
26
+ fromPubkey: new web3_js.PublicKey(this.address),
27
+ lamports: utils.solToLamports(Number(amount)),
28
+ toPubkey: new web3_js.PublicKey(toAddress),
29
+ }),
30
+ ],
31
+ payerKey: new web3_js.PublicKey(this.address),
32
+ recentBlockhash: blockhash,
33
+ }).compileToV0Message();
34
+ const transaction = new web3_js.VersionedTransaction(message);
35
+ const { signature } = yield signer.signAndSendTransaction(transaction);
36
+ return signature;
37
+ });
38
+ }
11
39
  /**
12
40
  * Retrieves the RPC connection
13
41
  * @returns A promise that resolves to the RPC connection
@@ -1,8 +1,18 @@
1
1
  import { Connection } from '@solana/web3.js';
2
2
  import { Wallet } from '@dynamic-labs/wallet-connector-core';
3
- import { SolWalletConnector } from '../connector';
3
+ import { SolanaWalletConnector } from '../connector';
4
4
  import { ISolana } from '../types';
5
- export declare class SolanaWallet extends Wallet<SolWalletConnector> {
5
+ export declare class SolanaWallet extends Wallet<SolanaWalletConnector> {
6
+ /**
7
+ * Sends the native balance of the wallet to the given address.
8
+ * @param amount - The amount of balance to send (in SOL).
9
+ * @param toAddress - The address to send the balance to.
10
+ * @returns The signature of the sent transaction.
11
+ */
12
+ sendBalance({ amount, toAddress, }: {
13
+ amount: string;
14
+ toAddress: string;
15
+ }): Promise<string | undefined>;
6
16
  /**
7
17
  * Retrieves the RPC connection
8
18
  * @returns A promise that resolves to the RPC connection
@@ -1,9 +1,37 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { TransactionMessage, SystemProgram, PublicKey, VersionedTransaction } from '@solana/web3.js';
3
4
  import { Wallet, logger } from '@dynamic-labs/wallet-connector-core';
4
- import { cloneObjectWithOverrides } from '@dynamic-labs/utils';
5
+ import { solToLamports, cloneObjectWithOverrides } from '@dynamic-labs/utils';
5
6
 
6
7
  class SolanaWallet extends Wallet {
8
+ /**
9
+ * Sends the native balance of the wallet to the given address.
10
+ * @param amount - The amount of balance to send (in SOL).
11
+ * @param toAddress - The address to send the balance to.
12
+ * @returns The signature of the sent transaction.
13
+ */
14
+ sendBalance(_a) {
15
+ return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
16
+ const connection = yield this.getConnection();
17
+ const signer = yield this.getSigner();
18
+ const { blockhash } = yield connection.getLatestBlockhash('finalized');
19
+ const message = new TransactionMessage({
20
+ instructions: [
21
+ SystemProgram.transfer({
22
+ fromPubkey: new PublicKey(this.address),
23
+ lamports: solToLamports(Number(amount)),
24
+ toPubkey: new PublicKey(toAddress),
25
+ }),
26
+ ],
27
+ payerKey: new PublicKey(this.address),
28
+ recentBlockhash: blockhash,
29
+ }).compileToV0Message();
30
+ const transaction = new VersionedTransaction(message);
31
+ const { signature } = yield signer.signAndSendTransaction(transaction);
32
+ return signature;
33
+ });
34
+ }
7
35
  /**
8
36
  * Retrieves the RPC connection
9
37
  * @returns A promise that resolves to the RPC connection