@dynamic-labs/embedded-wallet-solana 3.2.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/package.cjs +5 -5
- package/package.js +5 -5
- package/package.json +12 -11
- package/src/index.cjs +3 -1
- package/src/index.js +4 -0
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaSigner.cjs +2 -4
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaSigner.d.ts +1 -1
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaSigner.js +2 -4
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.cjs +39 -16
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.d.ts +1 -0
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.js +39 -16
- package/src/lib/utils/transactionDecoder/transactionDecoder.cjs +23 -9
- package/src/lib/utils/transactionDecoder/transactionDecoder.js +23 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
|
|
2
|
+
## [3.4.0](https://github.com/dynamic-labs/DynamicAuth/compare/v3.3.0...v3.4.0) (2024-10-16)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add support for add Oyl Wallet ([#7140](https://github.com/dynamic-labs/DynamicAuth/issues/7140)) ([f683f10](https://github.com/dynamic-labs/DynamicAuth/commit/f683f108098a2effac0f3b78c35bf2be73c1263c))
|
|
8
|
+
* add support for xverse account change event ([#7131](https://github.com/dynamic-labs/DynamicAuth/issues/7131)) ([bc34105](https://github.com/dynamic-labs/DynamicAuth/commit/bc341059903dc4d494f8d3ab127fa1adbec69c3a))
|
|
9
|
+
* embedded wallet signAllTransaction headless functionality for solana ([#7134](https://github.com/dynamic-labs/DynamicAuth/issues/7134)) ([15fa689](https://github.com/dynamic-labs/DynamicAuth/commit/15fa689f1f3bd591f10b19875d53f7cc3ffe1ebd))
|
|
10
|
+
* support ability to define additional oauth scopes ([#7113](https://github.com/dynamic-labs/DynamicAuth/issues/7113)) ([75c7f90](https://github.com/dynamic-labs/DynamicAuth/commit/75c7f9091b936153597b081d261e15cd1186623a))
|
|
11
|
+
|
|
12
|
+
## [3.3.0](https://github.com/dynamic-labs/DynamicAuth/compare/v3.2.0...v3.3.0) (2024-10-08)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* Account Abstraction Multi-Chain ([#7088](https://github.com/dynamic-labs/DynamicAuth/issues/7088)) ([c5de504](https://github.com/dynamic-labs/DynamicAuth/commit/c5de50414299473b8ec18094693377d8c064e4fa))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* solana embedded sponsored transactions ([#7066](https://github.com/dynamic-labs/DynamicAuth/issues/7066)) ([086b4ec](https://github.com/dynamic-labs/DynamicAuth/commit/086b4ecbbad56a4684f655fb977a1d5d7d3bca3a))
|
|
23
|
+
|
|
2
24
|
## [3.2.0](https://github.com/dynamic-labs/DynamicAuth/compare/v3.1.4...v3.2.0) (2024-10-02)
|
|
3
25
|
|
|
4
26
|
|
package/package.cjs
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var version = "3.
|
|
6
|
+
var version = "3.4.0";
|
|
7
7
|
var dependencies = {
|
|
8
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
9
|
-
"@dynamic-labs/utils": "3.
|
|
10
|
-
"@dynamic-labs/logger": "3.
|
|
11
|
-
"@dynamic-labs/types": "3.
|
|
8
|
+
"@dynamic-labs/sdk-api-core": "0.0.545",
|
|
9
|
+
"@dynamic-labs/utils": "3.4.0",
|
|
10
|
+
"@dynamic-labs/logger": "3.4.0",
|
|
11
|
+
"@dynamic-labs/types": "3.4.0",
|
|
12
12
|
eventemitter3: "5.0.1",
|
|
13
13
|
"@solana/spl-token": "0.4.6",
|
|
14
14
|
"@solana/web3.js": "1.92.1",
|
package/package.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
var version = "3.
|
|
2
|
+
var version = "3.4.0";
|
|
3
3
|
var dependencies = {
|
|
4
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
5
|
-
"@dynamic-labs/utils": "3.
|
|
6
|
-
"@dynamic-labs/logger": "3.
|
|
7
|
-
"@dynamic-labs/types": "3.
|
|
4
|
+
"@dynamic-labs/sdk-api-core": "0.0.545",
|
|
5
|
+
"@dynamic-labs/utils": "3.4.0",
|
|
6
|
+
"@dynamic-labs/logger": "3.4.0",
|
|
7
|
+
"@dynamic-labs/types": "3.4.0",
|
|
8
8
|
eventemitter3: "5.0.1",
|
|
9
9
|
"@solana/spl-token": "0.4.6",
|
|
10
10
|
"@solana/web3.js": "1.92.1",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/embedded-wallet-solana",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"./package.json": "./package.json"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
30
|
-
"@dynamic-labs/utils": "3.
|
|
31
|
-
"@dynamic-labs/logger": "3.
|
|
32
|
-
"@dynamic-labs/types": "3.
|
|
29
|
+
"@dynamic-labs/sdk-api-core": "0.0.545",
|
|
30
|
+
"@dynamic-labs/utils": "3.4.0",
|
|
31
|
+
"@dynamic-labs/logger": "3.4.0",
|
|
32
|
+
"@dynamic-labs/types": "3.4.0",
|
|
33
33
|
"eventemitter3": "5.0.1",
|
|
34
34
|
"@solana/spl-token": "0.4.6",
|
|
35
35
|
"@solana/web3.js": "1.92.1",
|
|
@@ -37,12 +37,13 @@
|
|
|
37
37
|
"@turnkey/iframe-stamper": "2.0.0",
|
|
38
38
|
"@turnkey/solana": "0.3.9",
|
|
39
39
|
"@turnkey/webauthn-stamper": "0.5.0",
|
|
40
|
-
"@dynamic-labs/
|
|
41
|
-
"@dynamic-labs/
|
|
42
|
-
"@dynamic-labs/
|
|
43
|
-
"@dynamic-labs/
|
|
44
|
-
"@dynamic-labs/wallet-
|
|
45
|
-
"@dynamic-labs/
|
|
40
|
+
"@dynamic-labs/assert-package-version": "3.4.0",
|
|
41
|
+
"@dynamic-labs/embedded-wallet": "3.4.0",
|
|
42
|
+
"@dynamic-labs/rpc-providers": "3.4.0",
|
|
43
|
+
"@dynamic-labs/solana-core": "3.4.0",
|
|
44
|
+
"@dynamic-labs/wallet-book": "3.4.0",
|
|
45
|
+
"@dynamic-labs/wallet-connector-core": "3.4.0",
|
|
46
|
+
"@dynamic-labs/webauthn": "3.4.0",
|
|
46
47
|
"react-dom": "18.2.0",
|
|
47
48
|
"viem": "2.9.25"
|
|
48
49
|
},
|
package/src/index.cjs
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
+
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
7
|
+
var _package = require('../package.cjs');
|
|
6
8
|
var TurnkeySolanaWalletConnectors = require('./TurnkeySolanaWalletConnectors.cjs');
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
assertPackageVersion.assertPackageVersion('@dynamic-labs/embedded-wallet-solana', _package.version);
|
|
9
11
|
|
|
10
12
|
exports.TurnkeySolanaWalletConnectors = TurnkeySolanaWalletConnectors.TurnkeySolanaWalletConnectors;
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
|
+
import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
|
|
3
|
+
import { version } from '../package.js';
|
|
2
4
|
export { TurnkeySolanaWalletConnectors } from './TurnkeySolanaWalletConnectors.js';
|
|
5
|
+
|
|
6
|
+
assertPackageVersion('@dynamic-labs/embedded-wallet-solana', version);
|
|
@@ -27,11 +27,9 @@ class TurnkeySolanaSigner {
|
|
|
27
27
|
return this.walletConnector.signTransaction(transaction);
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
-
signAllTransactions(
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
32
|
-
_transactions) {
|
|
30
|
+
signAllTransactions(transactions) {
|
|
33
31
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
|
|
32
|
+
return this.walletConnector.signAllTransactions(transactions);
|
|
35
33
|
});
|
|
36
34
|
}
|
|
37
35
|
signAndSendTransaction(transaction, options) {
|
|
@@ -32,7 +32,7 @@ export declare class TurnkeySolanaSigner implements IEmbeddedWalletSolanaSigner
|
|
|
32
32
|
});
|
|
33
33
|
signMessage(encodedMessage: Uint8Array): Promise<SignedMessage>;
|
|
34
34
|
signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
|
|
35
|
-
signAllTransactions<T extends Transaction | VersionedTransaction>(
|
|
35
|
+
signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<T[]>;
|
|
36
36
|
signAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions): Promise<{
|
|
37
37
|
signature: TransactionSignature;
|
|
38
38
|
}>;
|
|
@@ -23,11 +23,9 @@ class TurnkeySolanaSigner {
|
|
|
23
23
|
return this.walletConnector.signTransaction(transaction);
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
signAllTransactions(
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
28
|
-
_transactions) {
|
|
26
|
+
signAllTransactions(transactions) {
|
|
29
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
|
|
28
|
+
return this.walletConnector.signAllTransactions(transactions);
|
|
31
29
|
});
|
|
32
30
|
}
|
|
33
31
|
signAndSendTransaction(transaction, options) {
|
|
@@ -288,27 +288,42 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
288
288
|
return transaction;
|
|
289
289
|
});
|
|
290
290
|
}
|
|
291
|
+
signAllTransactions(transactions) {
|
|
292
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
293
|
+
yield this.createOrRestoreSession();
|
|
294
|
+
let account = yield this.getTurnkeyAccount();
|
|
295
|
+
const address = this.turnkeyAddress;
|
|
296
|
+
if (!account || !address) {
|
|
297
|
+
throw new Error('No turnkey account');
|
|
298
|
+
}
|
|
299
|
+
try {
|
|
300
|
+
const signedTransactions = yield account.signAllTransactions(transactions, address);
|
|
301
|
+
return signedTransactions;
|
|
302
|
+
}
|
|
303
|
+
catch (err) {
|
|
304
|
+
if (embeddedWallet.TURNKEY_SDK_SESSION_KEY_RETRYABLE_ERRORS.some((errorMsg) => err.message.includes(errorMsg))) {
|
|
305
|
+
yield this.removeSessionKeys();
|
|
306
|
+
yield this.createOrRestoreSession({
|
|
307
|
+
ignoreRestore: true,
|
|
308
|
+
});
|
|
309
|
+
account = (yield this.getTurnkeyAccount());
|
|
310
|
+
const signedTransactions = yield account.signAllTransactions(transactions, address);
|
|
311
|
+
return signedTransactions;
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
embeddedWallet.logger.error('[TK] failed to perform SignAllTransactions activity', err);
|
|
315
|
+
throw err;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}
|
|
291
320
|
internalSignAndSendTransaction(transaction, options) {
|
|
292
321
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
293
|
-
var _a;
|
|
294
322
|
if (!this.turnkeyAddress)
|
|
295
323
|
throw new utils.DynamicError('Solana wallet not found');
|
|
296
324
|
const currentConnection = this.getConnection('confirmed');
|
|
297
|
-
const blockhash = yield currentConnection.getLatestBlockhash();
|
|
298
|
-
if ('version' in transaction) {
|
|
299
|
-
transaction.message.recentBlockhash =
|
|
300
|
-
blockhash.blockhash;
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
transaction.recentBlockhash = blockhash.blockhash;
|
|
304
|
-
transaction.feePayer =
|
|
305
|
-
(_a = transaction.feePayer) !== null && _a !== void 0 ? _a : new web3_js.PublicKey(this.turnkeyAddress);
|
|
306
|
-
}
|
|
307
325
|
const signedTransaction = yield this.signTransaction(transaction);
|
|
308
|
-
const signature = yield currentConnection.sendRawTransaction(
|
|
309
|
-
requireAllSignatures: false,
|
|
310
|
-
verifySignatures: false,
|
|
311
|
-
})), options);
|
|
326
|
+
const signature = yield currentConnection.sendRawTransaction(signedTransaction.serialize(), options);
|
|
312
327
|
// listen for tx confirmation until 60 seconds, which is ~150 blocks expiration
|
|
313
328
|
return new Promise((resolve, reject) => {
|
|
314
329
|
const timeout = setTimeout(() => {
|
|
@@ -332,8 +347,16 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
332
347
|
if (!this.turnkeyAddress)
|
|
333
348
|
throw new utils.DynamicError('Solana wallet not found');
|
|
334
349
|
let optimizedTransaction = transaction;
|
|
350
|
+
let alreadySigned = false;
|
|
351
|
+
if ('version' in transaction) {
|
|
352
|
+
alreadySigned = transaction.signatures.some((sig) => !sig.every((byte) => byte === 0));
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
alreadySigned = transaction.signatures.some((sig) => sig.signature);
|
|
356
|
+
}
|
|
335
357
|
try {
|
|
336
|
-
|
|
358
|
+
// we cannot optimize partially signed transactions as once a tx is modified the signatures are no longer valid
|
|
359
|
+
if ((yield this.getNetwork()) === 'mainnet' && !alreadySigned) {
|
|
337
360
|
optimizedTransaction = (yield api.optimizeSolanaTransaction(this.getEnvId(), transaction, (_a = this.turnkeyAddress) !== null && _a !== void 0 ? _a : ''));
|
|
338
361
|
}
|
|
339
362
|
}
|
|
@@ -48,6 +48,7 @@ export declare class TurnkeySolanaWalletConnector extends TurnkeyWalletConnector
|
|
|
48
48
|
getEnvId: () => any;
|
|
49
49
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
50
50
|
signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
|
|
51
|
+
signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<T[]>;
|
|
51
52
|
internalSignAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions): Promise<string>;
|
|
52
53
|
signAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions): Promise<string>;
|
|
53
54
|
sendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, connection: Connection, options?: SendTransactionOptions): Promise<string>;
|
|
@@ -284,27 +284,42 @@ class TurnkeySolanaWalletConnector extends TurnkeyWalletConnectorBase {
|
|
|
284
284
|
return transaction;
|
|
285
285
|
});
|
|
286
286
|
}
|
|
287
|
+
signAllTransactions(transactions) {
|
|
288
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
289
|
+
yield this.createOrRestoreSession();
|
|
290
|
+
let account = yield this.getTurnkeyAccount();
|
|
291
|
+
const address = this.turnkeyAddress;
|
|
292
|
+
if (!account || !address) {
|
|
293
|
+
throw new Error('No turnkey account');
|
|
294
|
+
}
|
|
295
|
+
try {
|
|
296
|
+
const signedTransactions = yield account.signAllTransactions(transactions, address);
|
|
297
|
+
return signedTransactions;
|
|
298
|
+
}
|
|
299
|
+
catch (err) {
|
|
300
|
+
if (TURNKEY_SDK_SESSION_KEY_RETRYABLE_ERRORS.some((errorMsg) => err.message.includes(errorMsg))) {
|
|
301
|
+
yield this.removeSessionKeys();
|
|
302
|
+
yield this.createOrRestoreSession({
|
|
303
|
+
ignoreRestore: true,
|
|
304
|
+
});
|
|
305
|
+
account = (yield this.getTurnkeyAccount());
|
|
306
|
+
const signedTransactions = yield account.signAllTransactions(transactions, address);
|
|
307
|
+
return signedTransactions;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
logger.error('[TK] failed to perform SignAllTransactions activity', err);
|
|
311
|
+
throw err;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
}
|
|
287
316
|
internalSignAndSendTransaction(transaction, options) {
|
|
288
317
|
return __awaiter(this, void 0, void 0, function* () {
|
|
289
|
-
var _a;
|
|
290
318
|
if (!this.turnkeyAddress)
|
|
291
319
|
throw new DynamicError('Solana wallet not found');
|
|
292
320
|
const currentConnection = this.getConnection('confirmed');
|
|
293
|
-
const blockhash = yield currentConnection.getLatestBlockhash();
|
|
294
|
-
if ('version' in transaction) {
|
|
295
|
-
transaction.message.recentBlockhash =
|
|
296
|
-
blockhash.blockhash;
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
transaction.recentBlockhash = blockhash.blockhash;
|
|
300
|
-
transaction.feePayer =
|
|
301
|
-
(_a = transaction.feePayer) !== null && _a !== void 0 ? _a : new PublicKey(this.turnkeyAddress);
|
|
302
|
-
}
|
|
303
321
|
const signedTransaction = yield this.signTransaction(transaction);
|
|
304
|
-
const signature = yield currentConnection.sendRawTransaction(
|
|
305
|
-
requireAllSignatures: false,
|
|
306
|
-
verifySignatures: false,
|
|
307
|
-
})), options);
|
|
322
|
+
const signature = yield currentConnection.sendRawTransaction(signedTransaction.serialize(), options);
|
|
308
323
|
// listen for tx confirmation until 60 seconds, which is ~150 blocks expiration
|
|
309
324
|
return new Promise((resolve, reject) => {
|
|
310
325
|
const timeout = setTimeout(() => {
|
|
@@ -328,8 +343,16 @@ class TurnkeySolanaWalletConnector extends TurnkeyWalletConnectorBase {
|
|
|
328
343
|
if (!this.turnkeyAddress)
|
|
329
344
|
throw new DynamicError('Solana wallet not found');
|
|
330
345
|
let optimizedTransaction = transaction;
|
|
346
|
+
let alreadySigned = false;
|
|
347
|
+
if ('version' in transaction) {
|
|
348
|
+
alreadySigned = transaction.signatures.some((sig) => !sig.every((byte) => byte === 0));
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
alreadySigned = transaction.signatures.some((sig) => sig.signature);
|
|
352
|
+
}
|
|
331
353
|
try {
|
|
332
|
-
|
|
354
|
+
// we cannot optimize partially signed transactions as once a tx is modified the signatures are no longer valid
|
|
355
|
+
if ((yield this.getNetwork()) === 'mainnet' && !alreadySigned) {
|
|
333
356
|
optimizedTransaction = (yield optimizeSolanaTransaction(this.getEnvId(), transaction, (_a = this.turnkeyAddress) !== null && _a !== void 0 ? _a : ''));
|
|
334
357
|
}
|
|
335
358
|
}
|
|
@@ -10,16 +10,27 @@ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
|
10
10
|
var utils = require('@dynamic-labs/utils');
|
|
11
11
|
|
|
12
12
|
const getTotalSolanaSpend = (transaction, connection, thisAddress) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
-
var _a, _b, _c, _d, _e, _f;
|
|
13
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
14
14
|
let simulation;
|
|
15
|
+
let feePayer;
|
|
15
16
|
if ('version' in transaction) {
|
|
17
|
+
[feePayer] = transaction.message.staticAccountKeys;
|
|
16
18
|
simulation = yield connection.simulateTransaction(transaction, {
|
|
17
|
-
accounts: {
|
|
19
|
+
accounts: {
|
|
20
|
+
addresses: feePayer.toBase58() && feePayer.toBase58() !== thisAddress
|
|
21
|
+
? [feePayer.toBase58(), thisAddress]
|
|
22
|
+
: [thisAddress],
|
|
23
|
+
encoding: 'base64',
|
|
24
|
+
},
|
|
18
25
|
replaceRecentBlockhash: true,
|
|
19
26
|
});
|
|
20
27
|
}
|
|
21
28
|
else {
|
|
22
|
-
|
|
29
|
+
feePayer =
|
|
30
|
+
transaction.feePayer || transaction.instructions[0].keys[0].pubkey;
|
|
31
|
+
simulation = yield connection.simulateTransaction(transaction, undefined, feePayer.toBase58() && feePayer.toBase58() !== thisAddress
|
|
32
|
+
? [feePayer, new web3_js.PublicKey(thisAddress)]
|
|
33
|
+
: [new web3_js.PublicKey(thisAddress)]);
|
|
23
34
|
}
|
|
24
35
|
const previousBalance = yield connection.getBalance(new web3_js.PublicKey(thisAddress));
|
|
25
36
|
if (!((_c = (_b = (_a = simulation === null || simulation === void 0 ? void 0 : simulation.value) === null || _a === void 0 ? void 0 : _a.accounts) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.lamports)) {
|
|
@@ -43,11 +54,14 @@ const getTotalSolanaSpend = (transaction, connection, thisAddress) => _tslib.__a
|
|
|
43
54
|
}
|
|
44
55
|
return undefined;
|
|
45
56
|
}
|
|
46
|
-
|
|
57
|
+
// the last account will be the embedded wallet,
|
|
58
|
+
// if there are two addresses the first will be gas-sponsoring so we dont want to calculate sol for that
|
|
59
|
+
const totalSolTransfer = previousBalance -
|
|
60
|
+
((_g = (_f = (_e = (_d = simulation === null || simulation === void 0 ? void 0 : simulation.value) === null || _d === void 0 ? void 0 : _d.accounts) === null || _e === void 0 ? void 0 : _e[1]) === null || _f === void 0 ? void 0 : _f.lamports) !== null && _g !== void 0 ? _g : (_k = (_j = (_h = simulation === null || simulation === void 0 ? void 0 : simulation.value) === null || _h === void 0 ? void 0 : _h.accounts) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.lamports);
|
|
47
61
|
return BigInt(totalSolTransfer);
|
|
48
62
|
});
|
|
49
63
|
const decodeTransaction = (transaction, connection, thisAddress) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
-
var
|
|
64
|
+
var _l;
|
|
51
65
|
if (!transaction) {
|
|
52
66
|
throw new utils.DynamicError('Transaction is required');
|
|
53
67
|
}
|
|
@@ -72,7 +86,7 @@ const decodeTransaction = (transaction, connection, thisAddress) => _tslib.__awa
|
|
|
72
86
|
}
|
|
73
87
|
}
|
|
74
88
|
else if (!transaction.instructions) {
|
|
75
|
-
decodedInstructions = (
|
|
89
|
+
decodedInstructions = (_l = web3_js.Transaction.from(Buffer.from(transaction.serialize()))) === null || _l === void 0 ? void 0 : _l.instructions;
|
|
76
90
|
}
|
|
77
91
|
else {
|
|
78
92
|
decodedInstructions = transaction.instructions;
|
|
@@ -100,7 +114,7 @@ const decodeTransaction = (transaction, connection, thisAddress) => _tslib.__awa
|
|
|
100
114
|
}
|
|
101
115
|
// SPL transfers
|
|
102
116
|
let splTransfers = yield Promise.all(decodedInstructions.map((instruction) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
-
var
|
|
117
|
+
var _m, _o, _p, _q, _r, _s, _t;
|
|
104
118
|
if (instruction.programId.equals(splToken.TOKEN_PROGRAM_ID)) {
|
|
105
119
|
const decodedTokenInstruction = splToken.decodeTransferInstructionUnchecked(instruction);
|
|
106
120
|
const { source, destination } = decodedTokenInstruction.keys;
|
|
@@ -114,9 +128,9 @@ const decodeTransaction = (transaction, connection, thisAddress) => _tslib.__awa
|
|
|
114
128
|
}
|
|
115
129
|
// Pure SPL transfers, get the address from the destination token account to display to user
|
|
116
130
|
const destinationAccountInfo = yield connection.getParsedAccountInfo(destination.pubkey);
|
|
117
|
-
const isTokenAccount = ((
|
|
131
|
+
const isTokenAccount = ((_p = (_o = (_m = destinationAccountInfo.value) === null || _m === void 0 ? void 0 : _m.data) === null || _o === void 0 ? void 0 : _o.parsed) === null || _p === void 0 ? void 0 : _p.type) === 'account';
|
|
118
132
|
const destinationOwner = isTokenAccount
|
|
119
|
-
? (
|
|
133
|
+
? (_t = (_s = (_r = (_q = destinationAccountInfo.value) === null || _q === void 0 ? void 0 : _q.data) === null || _r === void 0 ? void 0 : _r.parsed) === null || _s === void 0 ? void 0 : _s.info) === null || _t === void 0 ? void 0 : _t.owner
|
|
120
134
|
: null;
|
|
121
135
|
const toAddress = destinationOwner
|
|
122
136
|
? destinationOwner
|
|
@@ -6,16 +6,27 @@ import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
|
6
6
|
import { DynamicError } from '@dynamic-labs/utils';
|
|
7
7
|
|
|
8
8
|
const getTotalSolanaSpend = (transaction, connection, thisAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f;
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
10
10
|
let simulation;
|
|
11
|
+
let feePayer;
|
|
11
12
|
if ('version' in transaction) {
|
|
13
|
+
[feePayer] = transaction.message.staticAccountKeys;
|
|
12
14
|
simulation = yield connection.simulateTransaction(transaction, {
|
|
13
|
-
accounts: {
|
|
15
|
+
accounts: {
|
|
16
|
+
addresses: feePayer.toBase58() && feePayer.toBase58() !== thisAddress
|
|
17
|
+
? [feePayer.toBase58(), thisAddress]
|
|
18
|
+
: [thisAddress],
|
|
19
|
+
encoding: 'base64',
|
|
20
|
+
},
|
|
14
21
|
replaceRecentBlockhash: true,
|
|
15
22
|
});
|
|
16
23
|
}
|
|
17
24
|
else {
|
|
18
|
-
|
|
25
|
+
feePayer =
|
|
26
|
+
transaction.feePayer || transaction.instructions[0].keys[0].pubkey;
|
|
27
|
+
simulation = yield connection.simulateTransaction(transaction, undefined, feePayer.toBase58() && feePayer.toBase58() !== thisAddress
|
|
28
|
+
? [feePayer, new PublicKey(thisAddress)]
|
|
29
|
+
: [new PublicKey(thisAddress)]);
|
|
19
30
|
}
|
|
20
31
|
const previousBalance = yield connection.getBalance(new PublicKey(thisAddress));
|
|
21
32
|
if (!((_c = (_b = (_a = simulation === null || simulation === void 0 ? void 0 : simulation.value) === null || _a === void 0 ? void 0 : _a.accounts) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.lamports)) {
|
|
@@ -39,11 +50,14 @@ const getTotalSolanaSpend = (transaction, connection, thisAddress) => __awaiter(
|
|
|
39
50
|
}
|
|
40
51
|
return undefined;
|
|
41
52
|
}
|
|
42
|
-
|
|
53
|
+
// the last account will be the embedded wallet,
|
|
54
|
+
// if there are two addresses the first will be gas-sponsoring so we dont want to calculate sol for that
|
|
55
|
+
const totalSolTransfer = previousBalance -
|
|
56
|
+
((_g = (_f = (_e = (_d = simulation === null || simulation === void 0 ? void 0 : simulation.value) === null || _d === void 0 ? void 0 : _d.accounts) === null || _e === void 0 ? void 0 : _e[1]) === null || _f === void 0 ? void 0 : _f.lamports) !== null && _g !== void 0 ? _g : (_k = (_j = (_h = simulation === null || simulation === void 0 ? void 0 : simulation.value) === null || _h === void 0 ? void 0 : _h.accounts) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.lamports);
|
|
43
57
|
return BigInt(totalSolTransfer);
|
|
44
58
|
});
|
|
45
59
|
const decodeTransaction = (transaction, connection, thisAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
-
var
|
|
60
|
+
var _l;
|
|
47
61
|
if (!transaction) {
|
|
48
62
|
throw new DynamicError('Transaction is required');
|
|
49
63
|
}
|
|
@@ -68,7 +82,7 @@ const decodeTransaction = (transaction, connection, thisAddress) => __awaiter(vo
|
|
|
68
82
|
}
|
|
69
83
|
}
|
|
70
84
|
else if (!transaction.instructions) {
|
|
71
|
-
decodedInstructions = (
|
|
85
|
+
decodedInstructions = (_l = Transaction.from(Buffer.from(transaction.serialize()))) === null || _l === void 0 ? void 0 : _l.instructions;
|
|
72
86
|
}
|
|
73
87
|
else {
|
|
74
88
|
decodedInstructions = transaction.instructions;
|
|
@@ -96,7 +110,7 @@ const decodeTransaction = (transaction, connection, thisAddress) => __awaiter(vo
|
|
|
96
110
|
}
|
|
97
111
|
// SPL transfers
|
|
98
112
|
let splTransfers = yield Promise.all(decodedInstructions.map((instruction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
-
var
|
|
113
|
+
var _m, _o, _p, _q, _r, _s, _t;
|
|
100
114
|
if (instruction.programId.equals(TOKEN_PROGRAM_ID)) {
|
|
101
115
|
const decodedTokenInstruction = decodeTransferInstructionUnchecked(instruction);
|
|
102
116
|
const { source, destination } = decodedTokenInstruction.keys;
|
|
@@ -110,9 +124,9 @@ const decodeTransaction = (transaction, connection, thisAddress) => __awaiter(vo
|
|
|
110
124
|
}
|
|
111
125
|
// Pure SPL transfers, get the address from the destination token account to display to user
|
|
112
126
|
const destinationAccountInfo = yield connection.getParsedAccountInfo(destination.pubkey);
|
|
113
|
-
const isTokenAccount = ((
|
|
127
|
+
const isTokenAccount = ((_p = (_o = (_m = destinationAccountInfo.value) === null || _m === void 0 ? void 0 : _m.data) === null || _o === void 0 ? void 0 : _o.parsed) === null || _p === void 0 ? void 0 : _p.type) === 'account';
|
|
114
128
|
const destinationOwner = isTokenAccount
|
|
115
|
-
? (
|
|
129
|
+
? (_t = (_s = (_r = (_q = destinationAccountInfo.value) === null || _q === void 0 ? void 0 : _q.data) === null || _r === void 0 ? void 0 : _r.parsed) === null || _s === void 0 ? void 0 : _s.info) === null || _t === void 0 ? void 0 : _t.owner
|
|
116
130
|
: null;
|
|
117
131
|
const toAddress = destinationOwner
|
|
118
132
|
? destinationOwner
|