@dynamic-labs/solana-core 4.4.2-preview.0 → 4.4.2-preview.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/CHANGELOG.md +11 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +7 -7
- package/src/index.cjs +4 -0
- package/src/index.js +2 -0
- package/src/utils/createNonNativeTokenTransfer/createNonNativeTokenTransfer.cjs +38 -0
- package/src/utils/createNonNativeTokenTransfer/createNonNativeTokenTransfer.d.ts +11 -0
- package/src/utils/createNonNativeTokenTransfer/createNonNativeTokenTransfer.js +34 -0
- package/src/utils/createNonNativeTokenTransfer/index.d.ts +1 -0
- package/src/utils/createSolTransfer/createSolTransfer.cjs +25 -0
- package/src/utils/createSolTransfer/createSolTransfer.d.ts +7 -0
- package/src/utils/createSolTransfer/createSolTransfer.js +21 -0
- package/src/utils/createSolTransfer/index.d.ts +1 -0
- package/src/utils/index.d.ts +2 -0
- package/src/wallet/SolanaWallet.cjs +27 -15
- package/src/wallet/SolanaWallet.d.ts +5 -1
- package/src/wallet/SolanaWallet.js +28 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.4.2-preview.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.4.2...v4.4.2-preview.1) (2025-01-30)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add support for 7702 on ZeroDevConnector ([144e99a](https://github.com/dynamic-labs/dynamic-auth/commit/144e99a673abbe4c775ec2124375925e96f76071))
|
|
8
|
+
* implement experimental_signAuthorization method in TurnkeyEVMWalletConnector ([#7866](https://github.com/dynamic-labs/dynamic-auth/issues/7866)) ([9622d1e](https://github.com/dynamic-labs/dynamic-auth/commit/9622d1e0e42bb3401fffbdda7b735db1736717ce))
|
|
9
|
+
* implement experimental_signAuthorization method in TurnkeyEVMWalletConnector ([#7866](https://github.com/dynamic-labs/dynamic-auth/issues/7866)) ([7f367b8](https://github.com/dynamic-labs/dynamic-auth/commit/7f367b8bc9d6a0ece0268867bf9c7754d75d7949))
|
|
10
|
+
* implement experimental_signAuthorization method in TurnkeyEVMWalletConnector ([#7866](https://github.com/dynamic-labs/dynamic-auth/issues/7866)) ([2019c4c](https://github.com/dynamic-labs/dynamic-auth/commit/2019c4cb89e4a042dc1c896a71b803db572e1842))
|
|
11
|
+
* override kernel address and add auth to localstorage ([1074ebc](https://github.com/dynamic-labs/dynamic-auth/commit/1074ebc0f3eca26fb868fd7acc9e3ac7c1048007))
|
|
12
|
+
|
|
2
13
|
### [4.4.2-preview.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.4.1...v4.4.2-preview.0) (2025-01-28)
|
|
3
14
|
|
|
4
15
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/solana-core",
|
|
3
|
-
"version": "4.4.2-preview.
|
|
3
|
+
"version": "4.4.2-preview.1",
|
|
4
4
|
"description": "Core package for utilities and types for solana",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"@solana/spl-token": "0.4.6"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@dynamic-labs/assert-package-version": "4.4.2-preview.
|
|
27
|
-
"@dynamic-labs/rpc-providers": "4.4.2-preview.
|
|
28
|
-
"@dynamic-labs/types": "4.4.2-preview.
|
|
29
|
-
"@dynamic-labs/utils": "4.4.2-preview.
|
|
30
|
-
"@dynamic-labs/wallet-book": "4.4.2-preview.
|
|
31
|
-
"@dynamic-labs/wallet-connector-core": "4.4.2-preview.
|
|
26
|
+
"@dynamic-labs/assert-package-version": "4.4.2-preview.1",
|
|
27
|
+
"@dynamic-labs/rpc-providers": "4.4.2-preview.1",
|
|
28
|
+
"@dynamic-labs/types": "4.4.2-preview.1",
|
|
29
|
+
"@dynamic-labs/utils": "4.4.2-preview.1",
|
|
30
|
+
"@dynamic-labs/wallet-book": "4.4.2-preview.1",
|
|
31
|
+
"@dynamic-labs/wallet-connector-core": "4.4.2-preview.1",
|
|
32
32
|
"eventemitter3": "5.0.1"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/index.cjs
CHANGED
|
@@ -16,6 +16,8 @@ var encodeTransactionToBase64 = require('./utils/encodeTransactionToBase64/encod
|
|
|
16
16
|
var getGenesisHashLSKey = require('./utils/getGenesisHashLSKey/getGenesisHashLSKey.cjs');
|
|
17
17
|
var isTransactionSigned = require('./utils/isTransactionSigned/isTransactionSigned.cjs');
|
|
18
18
|
var getOverrideRpcUrlForNetwork = require('./utils/getOverrideRpcUrlForNetwork/getOverrideRpcUrlForNetwork.cjs');
|
|
19
|
+
var createNonNativeTokenTransfer = require('./utils/createNonNativeTokenTransfer/createNonNativeTokenTransfer.cjs');
|
|
20
|
+
var createSolTransfer = require('./utils/createSolTransfer/createSolTransfer.cjs');
|
|
19
21
|
var SolanaWallet = require('./wallet/SolanaWallet.cjs');
|
|
20
22
|
var isSolanaWallet = require('./wallet/isSolanaWallet/isSolanaWallet.cjs');
|
|
21
23
|
var isLedgerSolanaWallet = require('./wallet/isLedgerSolanaWallet/isLedgerSolanaWallet.cjs');
|
|
@@ -32,6 +34,8 @@ exports.encodeTransactionToBase64 = encodeTransactionToBase64.encodeTransactionT
|
|
|
32
34
|
exports.getGenesisHashLSKey = getGenesisHashLSKey.getGenesisHashLSKey;
|
|
33
35
|
exports.isTxAlreadySigned = isTransactionSigned.isTxAlreadySigned;
|
|
34
36
|
exports.getOverrideRpcUrlForNetwork = getOverrideRpcUrlForNetwork.getOverrideRpcUrlForNetwork;
|
|
37
|
+
exports.createNonNativeTokenTransfer = createNonNativeTokenTransfer.createNonNativeTokenTransfer;
|
|
38
|
+
exports.createSolTransfer = createSolTransfer.createSolTransfer;
|
|
35
39
|
exports.SolanaWallet = SolanaWallet.SolanaWallet;
|
|
36
40
|
exports.isSolanaWallet = isSolanaWallet.isSolanaWallet;
|
|
37
41
|
exports.isLedgerSolanaWallet = isLedgerSolanaWallet.isLedgerSolanaWallet;
|
package/src/index.js
CHANGED
|
@@ -12,6 +12,8 @@ export { encodeTransactionToBase64 } from './utils/encodeTransactionToBase64/enc
|
|
|
12
12
|
export { getGenesisHashLSKey } from './utils/getGenesisHashLSKey/getGenesisHashLSKey.js';
|
|
13
13
|
export { isTxAlreadySigned } from './utils/isTransactionSigned/isTransactionSigned.js';
|
|
14
14
|
export { getOverrideRpcUrlForNetwork } from './utils/getOverrideRpcUrlForNetwork/getOverrideRpcUrlForNetwork.js';
|
|
15
|
+
export { createNonNativeTokenTransfer } from './utils/createNonNativeTokenTransfer/createNonNativeTokenTransfer.js';
|
|
16
|
+
export { createSolTransfer } from './utils/createSolTransfer/createSolTransfer.js';
|
|
15
17
|
export { SolanaWallet } from './wallet/SolanaWallet.js';
|
|
16
18
|
export { isSolanaWallet } from './wallet/isSolanaWallet/isSolanaWallet.js';
|
|
17
19
|
export { isLedgerSolanaWallet } from './wallet/isLedgerSolanaWallet/isLedgerSolanaWallet.js';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var splToken = require('@solana/spl-token');
|
|
8
|
+
var web3_js = require('@solana/web3.js');
|
|
9
|
+
|
|
10
|
+
const createNonNativeTokenTransfer = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ connection, fromAddress, toAddress, tokenAddress, amount, decimals, blockhash, lastValidBlockHeight, }) {
|
|
11
|
+
var _b, _c;
|
|
12
|
+
const fromPublicKey = new web3_js.PublicKey(fromAddress);
|
|
13
|
+
const toPublicKey = new web3_js.PublicKey(toAddress);
|
|
14
|
+
const tokenPublicKey = new web3_js.PublicKey(tokenAddress);
|
|
15
|
+
const fromTokenAccount = (_c = (_b = (yield connection.getTokenAccountsByOwner(fromPublicKey, {
|
|
16
|
+
mint: tokenPublicKey,
|
|
17
|
+
}))) === null || _b === void 0 ? void 0 : _b.value[0]) === null || _c === void 0 ? void 0 : _c.pubkey;
|
|
18
|
+
if (!fromTokenAccount)
|
|
19
|
+
throw new Error('Source token account not found');
|
|
20
|
+
let toTokenAccountPubkey;
|
|
21
|
+
const instructions = [];
|
|
22
|
+
try {
|
|
23
|
+
toTokenAccountPubkey = yield splToken.getAssociatedTokenAddress(tokenPublicKey, toPublicKey);
|
|
24
|
+
yield connection.getTokenAccountBalance(toTokenAccountPubkey);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
toTokenAccountPubkey = yield splToken.getAssociatedTokenAddress(tokenPublicKey, toPublicKey);
|
|
28
|
+
instructions.push(splToken.createAssociatedTokenAccountInstruction(fromPublicKey, toTokenAccountPubkey, toPublicKey, tokenPublicKey));
|
|
29
|
+
}
|
|
30
|
+
instructions.push(splToken.createTransferInstruction(fromTokenAccount, toTokenAccountPubkey, fromPublicKey, BigInt(Number(amount) * Math.pow(10, (decimals || 0)))));
|
|
31
|
+
const transaction = new web3_js.Transaction().add(...instructions);
|
|
32
|
+
transaction.recentBlockhash = blockhash;
|
|
33
|
+
transaction.lastValidBlockHeight = lastValidBlockHeight;
|
|
34
|
+
transaction.feePayer = fromPublicKey;
|
|
35
|
+
return transaction;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
exports.createNonNativeTokenTransfer = createNonNativeTokenTransfer;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Connection, Transaction } from '@solana/web3.js';
|
|
2
|
+
export declare const createNonNativeTokenTransfer: ({ connection, fromAddress, toAddress, tokenAddress, amount, decimals, blockhash, lastValidBlockHeight, }: {
|
|
3
|
+
connection: Connection;
|
|
4
|
+
fromAddress: string;
|
|
5
|
+
toAddress: string;
|
|
6
|
+
tokenAddress: string;
|
|
7
|
+
amount: number;
|
|
8
|
+
blockhash: string;
|
|
9
|
+
lastValidBlockHeight: number;
|
|
10
|
+
decimals?: number;
|
|
11
|
+
}) => Promise<Transaction>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { getAssociatedTokenAddress, createAssociatedTokenAccountInstruction, createTransferInstruction } from '@solana/spl-token';
|
|
4
|
+
import { PublicKey, Transaction } from '@solana/web3.js';
|
|
5
|
+
|
|
6
|
+
const createNonNativeTokenTransfer = (_a) => __awaiter(void 0, [_a], void 0, function* ({ connection, fromAddress, toAddress, tokenAddress, amount, decimals, blockhash, lastValidBlockHeight, }) {
|
|
7
|
+
var _b, _c;
|
|
8
|
+
const fromPublicKey = new PublicKey(fromAddress);
|
|
9
|
+
const toPublicKey = new PublicKey(toAddress);
|
|
10
|
+
const tokenPublicKey = new PublicKey(tokenAddress);
|
|
11
|
+
const fromTokenAccount = (_c = (_b = (yield connection.getTokenAccountsByOwner(fromPublicKey, {
|
|
12
|
+
mint: tokenPublicKey,
|
|
13
|
+
}))) === null || _b === void 0 ? void 0 : _b.value[0]) === null || _c === void 0 ? void 0 : _c.pubkey;
|
|
14
|
+
if (!fromTokenAccount)
|
|
15
|
+
throw new Error('Source token account not found');
|
|
16
|
+
let toTokenAccountPubkey;
|
|
17
|
+
const instructions = [];
|
|
18
|
+
try {
|
|
19
|
+
toTokenAccountPubkey = yield getAssociatedTokenAddress(tokenPublicKey, toPublicKey);
|
|
20
|
+
yield connection.getTokenAccountBalance(toTokenAccountPubkey);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
toTokenAccountPubkey = yield getAssociatedTokenAddress(tokenPublicKey, toPublicKey);
|
|
24
|
+
instructions.push(createAssociatedTokenAccountInstruction(fromPublicKey, toTokenAccountPubkey, toPublicKey, tokenPublicKey));
|
|
25
|
+
}
|
|
26
|
+
instructions.push(createTransferInstruction(fromTokenAccount, toTokenAccountPubkey, fromPublicKey, BigInt(Number(amount) * Math.pow(10, (decimals || 0)))));
|
|
27
|
+
const transaction = new Transaction().add(...instructions);
|
|
28
|
+
transaction.recentBlockhash = blockhash;
|
|
29
|
+
transaction.lastValidBlockHeight = lastValidBlockHeight;
|
|
30
|
+
transaction.feePayer = fromPublicKey;
|
|
31
|
+
return transaction;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export { createNonNativeTokenTransfer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createNonNativeTokenTransfer } from './createNonNativeTokenTransfer';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var web3_js = require('@solana/web3.js');
|
|
8
|
+
var utils = require('@dynamic-labs/utils');
|
|
9
|
+
|
|
10
|
+
const createSolTransfer = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ fromAddress, toAddress, amount, blockhash, }) {
|
|
11
|
+
const message = new web3_js.TransactionMessage({
|
|
12
|
+
instructions: [
|
|
13
|
+
web3_js.SystemProgram.transfer({
|
|
14
|
+
fromPubkey: new web3_js.PublicKey(fromAddress),
|
|
15
|
+
lamports: utils.solToLamports(amount),
|
|
16
|
+
toPubkey: new web3_js.PublicKey(toAddress),
|
|
17
|
+
}),
|
|
18
|
+
],
|
|
19
|
+
payerKey: new web3_js.PublicKey(fromAddress),
|
|
20
|
+
recentBlockhash: blockhash,
|
|
21
|
+
}).compileToV0Message();
|
|
22
|
+
return new web3_js.VersionedTransaction(message);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
exports.createSolTransfer = createSolTransfer;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { VersionedTransaction } from '@solana/web3.js';
|
|
2
|
+
export declare const createSolTransfer: ({ fromAddress, toAddress, amount, blockhash, }: {
|
|
3
|
+
fromAddress: string;
|
|
4
|
+
toAddress: string;
|
|
5
|
+
amount: number;
|
|
6
|
+
blockhash: string;
|
|
7
|
+
}) => Promise<VersionedTransaction>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { TransactionMessage, SystemProgram, PublicKey, VersionedTransaction } from '@solana/web3.js';
|
|
4
|
+
import { solToLamports } from '@dynamic-labs/utils';
|
|
5
|
+
|
|
6
|
+
const createSolTransfer = (_a) => __awaiter(void 0, [_a], void 0, function* ({ fromAddress, toAddress, amount, blockhash, }) {
|
|
7
|
+
const message = new TransactionMessage({
|
|
8
|
+
instructions: [
|
|
9
|
+
SystemProgram.transfer({
|
|
10
|
+
fromPubkey: new PublicKey(fromAddress),
|
|
11
|
+
lamports: solToLamports(amount),
|
|
12
|
+
toPubkey: new PublicKey(toAddress),
|
|
13
|
+
}),
|
|
14
|
+
],
|
|
15
|
+
payerKey: new PublicKey(fromAddress),
|
|
16
|
+
recentBlockhash: blockhash,
|
|
17
|
+
}).compileToV0Message();
|
|
18
|
+
return new VersionedTransaction(message);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export { createSolTransfer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createSolTransfer } from './createSolTransfer';
|
package/src/utils/index.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ export { encodeTransactionToBase64, type EncodedTransaction, } from './encodeTra
|
|
|
5
5
|
export { getGenesisHashLSKey } from './getGenesisHashLSKey';
|
|
6
6
|
export { isTxAlreadySigned } from './isTransactionSigned';
|
|
7
7
|
export { getOverrideRpcUrlForNetwork } from './getOverrideRpcUrlForNetwork';
|
|
8
|
+
export { createNonNativeTokenTransfer } from './createNonNativeTokenTransfer';
|
|
9
|
+
export { createSolTransfer } from './createSolTransfer';
|
|
@@ -4,9 +4,12 @@
|
|
|
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');
|
|
8
7
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
8
|
var utils = require('@dynamic-labs/utils');
|
|
9
|
+
require('@solana/web3.js');
|
|
10
|
+
require('@solana/spl-token');
|
|
11
|
+
var createNonNativeTokenTransfer = require('../utils/createNonNativeTokenTransfer/createNonNativeTokenTransfer.cjs');
|
|
12
|
+
var createSolTransfer = require('../utils/createSolTransfer/createSolTransfer.cjs');
|
|
10
13
|
|
|
11
14
|
class SolanaWallet extends walletConnectorCore.Wallet {
|
|
12
15
|
/**
|
|
@@ -16,22 +19,31 @@ class SolanaWallet extends walletConnectorCore.Wallet {
|
|
|
16
19
|
* @returns The signature of the sent transaction.
|
|
17
20
|
*/
|
|
18
21
|
sendBalance(_a) {
|
|
19
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
|
|
22
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, }) {
|
|
23
|
+
let transaction;
|
|
20
24
|
const connection = yield this.getConnection();
|
|
21
25
|
const signer = yield this.getSigner();
|
|
22
|
-
const { blockhash } = yield connection.getLatestBlockhash('finalized');
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash('finalized');
|
|
27
|
+
if (token && token.address) {
|
|
28
|
+
transaction = yield createNonNativeTokenTransfer.createNonNativeTokenTransfer({
|
|
29
|
+
amount: Number(amount),
|
|
30
|
+
blockhash,
|
|
31
|
+
connection,
|
|
32
|
+
decimals: token.decimals,
|
|
33
|
+
fromAddress: this.address,
|
|
34
|
+
lastValidBlockHeight,
|
|
35
|
+
toAddress,
|
|
36
|
+
tokenAddress: token.address,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
transaction = yield createSolTransfer.createSolTransfer({
|
|
41
|
+
amount: Number(amount),
|
|
42
|
+
blockhash,
|
|
43
|
+
fromAddress: this.address,
|
|
44
|
+
toAddress,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
35
47
|
const { signature } = yield signer.signAndSendTransaction(transaction);
|
|
36
48
|
return signature;
|
|
37
49
|
});
|
|
@@ -9,9 +9,13 @@ export declare class SolanaWallet extends Wallet<SolanaWalletConnector> {
|
|
|
9
9
|
* @param toAddress - The address to send the balance to.
|
|
10
10
|
* @returns The signature of the sent transaction.
|
|
11
11
|
*/
|
|
12
|
-
sendBalance({ amount, toAddress, }: {
|
|
12
|
+
sendBalance({ amount, toAddress, token, }: {
|
|
13
13
|
amount: string;
|
|
14
14
|
toAddress: string;
|
|
15
|
+
token?: {
|
|
16
|
+
address: string;
|
|
17
|
+
decimals?: number;
|
|
18
|
+
};
|
|
15
19
|
}): Promise<string | undefined>;
|
|
16
20
|
/**
|
|
17
21
|
* Retrieves the RPC connection
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
-
import { TransactionMessage, SystemProgram, PublicKey, VersionedTransaction } from '@solana/web3.js';
|
|
4
3
|
import { Wallet, logger } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
-
import {
|
|
4
|
+
import { cloneObjectWithOverrides } from '@dynamic-labs/utils';
|
|
5
|
+
import '@solana/web3.js';
|
|
6
|
+
import '@solana/spl-token';
|
|
7
|
+
import { createNonNativeTokenTransfer } from '../utils/createNonNativeTokenTransfer/createNonNativeTokenTransfer.js';
|
|
8
|
+
import { createSolTransfer } from '../utils/createSolTransfer/createSolTransfer.js';
|
|
6
9
|
|
|
7
10
|
class SolanaWallet extends Wallet {
|
|
8
11
|
/**
|
|
@@ -12,22 +15,31 @@ class SolanaWallet extends Wallet {
|
|
|
12
15
|
* @returns The signature of the sent transaction.
|
|
13
16
|
*/
|
|
14
17
|
sendBalance(_a) {
|
|
15
|
-
return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
|
|
18
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, }) {
|
|
19
|
+
let transaction;
|
|
16
20
|
const connection = yield this.getConnection();
|
|
17
21
|
const signer = yield this.getSigner();
|
|
18
|
-
const { blockhash } = yield connection.getLatestBlockhash('finalized');
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash('finalized');
|
|
23
|
+
if (token && token.address) {
|
|
24
|
+
transaction = yield createNonNativeTokenTransfer({
|
|
25
|
+
amount: Number(amount),
|
|
26
|
+
blockhash,
|
|
27
|
+
connection,
|
|
28
|
+
decimals: token.decimals,
|
|
29
|
+
fromAddress: this.address,
|
|
30
|
+
lastValidBlockHeight,
|
|
31
|
+
toAddress,
|
|
32
|
+
tokenAddress: token.address,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
transaction = yield createSolTransfer({
|
|
37
|
+
amount: Number(amount),
|
|
38
|
+
blockhash,
|
|
39
|
+
fromAddress: this.address,
|
|
40
|
+
toAddress,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
31
43
|
const { signature } = yield signer.signAndSendTransaction(transaction);
|
|
32
44
|
return signature;
|
|
33
45
|
});
|