@dynamic-labs/waas-svm 5.9.4 → 5.10.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 +25 -0
- package/_virtual/_tslib.cjs +13 -0
- package/_virtual/_tslib.js +13 -1
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +10 -10
- package/src/connector/DynamicWaasSVMConnector.cjs +88 -42
- package/src/connector/DynamicWaasSVMConnector.d.ts +19 -9
- package/src/connector/DynamicWaasSVMConnector.js +89 -43
- package/src/signer/DynamicWaasSVMSigner.cjs +8 -2
- package/src/signer/DynamicWaasSVMSigner.d.ts +5 -5
- package/src/signer/DynamicWaasSVMSigner.js +8 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
|
|
2
|
+
## [5.10.0](https://github.com/dynamic-labs/dynamic-auth/compare/v5.9.6...v5.10.0) (2026-10-09)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add lockWallets/lockWallet to re-lock password-encrypted WaaS wallets ([#12461](https://github.com/dynamic-labs/dynamic-auth/issues/12461)) ([090f544](https://github.com/dynamic-labs/dynamic-auth/commit/090f544150f4359bbfd9c0ffb4c450868adb6759))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* **logger:** scope server error forwarding per instance ([#12477](https://github.com/dynamic-labs/dynamic-auth/issues/12477)) ([baa8c78](https://github.com/dynamic-labs/dynamic-auth/commit/baa8c780f4ef3cc35d62c363e03e74412ece91b9))
|
|
13
|
+
* **waas:** fall back when crypto.randomUUID is unavailable ([#12435](https://github.com/dynamic-labs/dynamic-auth/issues/12435)) ([5756f53](https://github.com/dynamic-labs/dynamic-auth/commit/5756f53423bd8316bce97e46ce38fc923fd5d574))
|
|
14
|
+
* **waas:** include every wallet in password update batches ([#12462](https://github.com/dynamic-labs/dynamic-auth/issues/12462)) ([80218f7](https://github.com/dynamic-labs/dynamic-auth/commit/80218f702dadfee9673cec4037889449bcd5ceb6))
|
|
15
|
+
|
|
16
|
+
### [5.9.6](https://github.com/dynamic-labs/dynamic-auth/compare/v5.9.5...v5.9.6) (2026-10-06)
|
|
17
|
+
|
|
18
|
+
### [5.9.5](https://github.com/dynamic-labs/dynamic-auth/compare/v5.9.4...v5.9.5) (2026-10-06)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* **ton:** move encodeComment to base TonWalletConnector ([#12459](https://github.com/dynamic-labs/dynamic-auth/issues/12459)) ([647df5b](https://github.com/dynamic-labs/dynamic-auth/commit/647df5bc3986d59d89dbe31bbd3ebe1c4605ec40))
|
|
24
|
+
* **waas-svm:** apply overrideBlockhash before sponsorship ([#12319](https://github.com/dynamic-labs/dynamic-auth/issues/12319)) ([074ce3c](https://github.com/dynamic-labs/dynamic-auth/commit/074ce3c4ecfa080b683c84120fa7643e8fe064d4)), closes [#10599](https://github.com/dynamic-labs/dynamic-auth/issues/10599) [#10599](https://github.com/dynamic-labs/dynamic-auth/issues/10599) [#10599](https://github.com/dynamic-labs/dynamic-auth/issues/10599) [#10599](https://github.com/dynamic-labs/dynamic-auth/issues/10599)
|
|
25
|
+
* **wallet-book:** use phantom.com for Phantom in-app-browser links ([#12456](https://github.com/dynamic-labs/dynamic-auth/issues/12456)) ([e762553](https://github.com/dynamic-labs/dynamic-auth/commit/e7625534f8beda3e649f121e637451e2188faef6))
|
|
26
|
+
|
|
2
27
|
### [5.9.4](https://github.com/dynamic-labs/dynamic-auth/compare/v5.9.3...v5.9.4) (2026-10-02)
|
|
3
28
|
|
|
4
29
|
### [5.9.3](https://github.com/dynamic-labs/dynamic-auth/compare/v5.9.2...v5.9.3) (2026-10-02)
|
package/_virtual/_tslib.cjs
CHANGED
|
@@ -18,6 +18,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
18
18
|
PERFORMANCE OF THIS SOFTWARE.
|
|
19
19
|
***************************************************************************** */
|
|
20
20
|
|
|
21
|
+
function __rest(s, e) {
|
|
22
|
+
var t = {};
|
|
23
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
24
|
+
t[p] = s[p];
|
|
25
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
26
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
27
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
28
|
+
t[p[i]] = s[p[i]];
|
|
29
|
+
}
|
|
30
|
+
return t;
|
|
31
|
+
}
|
|
32
|
+
|
|
21
33
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
22
34
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
35
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -34,3 +46,4 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
34
46
|
};
|
|
35
47
|
|
|
36
48
|
exports.__awaiter = __awaiter;
|
|
49
|
+
exports.__rest = __rest;
|
package/_virtual/_tslib.js
CHANGED
|
@@ -14,6 +14,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
15
|
***************************************************************************** */
|
|
16
16
|
|
|
17
|
+
function __rest(s, e) {
|
|
18
|
+
var t = {};
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
22
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
23
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
24
|
+
t[p[i]] = s[p[i]];
|
|
25
|
+
}
|
|
26
|
+
return t;
|
|
27
|
+
}
|
|
28
|
+
|
|
17
29
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
18
30
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
31
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -29,4 +41,4 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
29
41
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
42
|
};
|
|
31
43
|
|
|
32
|
-
export { __awaiter };
|
|
44
|
+
export { __awaiter, __rest };
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/waas-svm",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.10.0",
|
|
4
4
|
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@dynamic-labs/sdk-api-core": "0.70.0",
|
|
22
|
-
"@dynamic-labs/embedded-wallet-solana": "5.
|
|
22
|
+
"@dynamic-labs/embedded-wallet-solana": "5.10.0",
|
|
23
23
|
"@solana/web3.js": "1.98.1",
|
|
24
24
|
"eventemitter3": "5.0.1",
|
|
25
25
|
"bs58": "5.0.0",
|
|
26
|
-
"@dynamic-labs/assert-package-version": "5.
|
|
27
|
-
"@dynamic-labs/logger": "5.
|
|
28
|
-
"@dynamic-labs/rpc-providers": "5.
|
|
29
|
-
"@dynamic-labs/solana-core": "5.
|
|
30
|
-
"@dynamic-labs/types": "5.
|
|
31
|
-
"@dynamic-labs/utils": "5.
|
|
32
|
-
"@dynamic-labs/waas": "5.
|
|
33
|
-
"@dynamic-labs/wallet-connector-core": "5.
|
|
26
|
+
"@dynamic-labs/assert-package-version": "5.10.0",
|
|
27
|
+
"@dynamic-labs/logger": "5.10.0",
|
|
28
|
+
"@dynamic-labs/rpc-providers": "5.10.0",
|
|
29
|
+
"@dynamic-labs/solana-core": "5.10.0",
|
|
30
|
+
"@dynamic-labs/types": "5.10.0",
|
|
31
|
+
"@dynamic-labs/utils": "5.10.0",
|
|
32
|
+
"@dynamic-labs/waas": "5.10.0",
|
|
33
|
+
"@dynamic-labs/wallet-connector-core": "5.10.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {}
|
|
36
36
|
}
|
|
@@ -30,6 +30,7 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
|
|
|
30
30
|
this.overrideKey = 'dynamicwaas';
|
|
31
31
|
this.isEmbeddedWallet = true;
|
|
32
32
|
this.getSvmGasSponsorshipEnabled = () => false;
|
|
33
|
+
this.supportsSvmGasSponsorship = true;
|
|
33
34
|
this.logger = logger.logger;
|
|
34
35
|
this.walletUiUtils = props.walletUiUtils;
|
|
35
36
|
}
|
|
@@ -71,18 +72,52 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
|
|
|
71
72
|
}
|
|
72
73
|
return transaction.signatures.some((sig) => sig.signature && !sig.signature.every((byte) => byte === 0));
|
|
73
74
|
}
|
|
75
|
+
getFeePayerAddress(transaction) {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
if ('version' in transaction) {
|
|
78
|
+
return (_a = transaction.message.staticAccountKeys[0]) === null || _a === void 0 ? void 0 : _a.toBase58();
|
|
79
|
+
}
|
|
80
|
+
return (_b = transaction.feePayer) === null || _b === void 0 ? void 0 : _b.toBase58();
|
|
81
|
+
}
|
|
82
|
+
attemptSponsorship(environmentId, transaction, sponsorshipMode, attempt) {
|
|
83
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const sponsoredTransaction = yield this.instrumentAsync({
|
|
85
|
+
context: { attempt, maxAttempts: SPONSORSHIP_MAX_ATTEMPTS },
|
|
86
|
+
fn: () => _tslib.__awaiter(this, void 0, void 0, function* () { return embeddedWalletSolana.sponsorSolanaTransaction(environmentId, transaction); }),
|
|
87
|
+
operation: 'maybeSponsorTransaction',
|
|
88
|
+
resource: `sponsorSolanaTransaction-attempt-${attempt}`,
|
|
89
|
+
});
|
|
90
|
+
const feePayer = this.getFeePayerAddress(sponsoredTransaction);
|
|
91
|
+
if (sponsorshipMode === 'required' &&
|
|
92
|
+
(!feePayer || feePayer === this.activeAccountAddress)) {
|
|
93
|
+
throw new utils.DynamicError('Sponsored transaction is not sponsored', 'sponsorship_not_applied');
|
|
94
|
+
}
|
|
95
|
+
logger.logger.info('[maybeSponsorTransaction] Transaction sponsored successfully');
|
|
96
|
+
return sponsoredTransaction;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
asSponsorshipError(error) {
|
|
100
|
+
if (error instanceof utils.DynamicError) {
|
|
101
|
+
return error;
|
|
102
|
+
}
|
|
103
|
+
return new utils.DynamicError(SPONSORSHIP_FAILURE_MESSAGE, SPONSORSHIP_FAILURE_CODE);
|
|
104
|
+
}
|
|
74
105
|
/**
|
|
75
106
|
* Sponsor a transaction if gas sponsorship is enabled and the tx is unsigned.
|
|
76
107
|
* Retries transient failures; throws if sponsorship never succeeds so callers
|
|
77
108
|
* never sign and return a transaction that silently skipped sponsorship
|
|
78
109
|
* (e.g. a 0-SOL wallet still set as fee payer).
|
|
79
110
|
*/
|
|
80
|
-
maybeSponsorTransaction(
|
|
81
|
-
return _tslib.__awaiter(this,
|
|
82
|
-
if (
|
|
111
|
+
maybeSponsorTransaction(transaction_1) {
|
|
112
|
+
return _tslib.__awaiter(this, arguments, void 0, function* (transaction, sponsorshipMode = 'auto') {
|
|
113
|
+
if (sponsorshipMode === 'off' ||
|
|
114
|
+
(sponsorshipMode === 'auto' && !this.getSvmGasSponsorshipEnabled())) {
|
|
83
115
|
return transaction;
|
|
84
116
|
}
|
|
85
117
|
if (this.isTxAlreadySigned(transaction)) {
|
|
118
|
+
if (sponsorshipMode === 'required') {
|
|
119
|
+
throw new utils.DynamicError('Signed transactions cannot be sponsored', 'sponsorship_transaction_already_signed');
|
|
120
|
+
}
|
|
86
121
|
logger.logger.debug('[maybeSponsorTransaction] Skipping sponsorship - transaction already signed');
|
|
87
122
|
return transaction;
|
|
88
123
|
}
|
|
@@ -95,23 +130,13 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
|
|
|
95
130
|
const { environmentId } = this;
|
|
96
131
|
for (let attempt = 1; attempt <= SPONSORSHIP_MAX_ATTEMPTS; attempt++) {
|
|
97
132
|
try {
|
|
98
|
-
|
|
99
|
-
context: { attempt, maxAttempts: SPONSORSHIP_MAX_ATTEMPTS },
|
|
100
|
-
fn: () => _tslib.__awaiter(this, void 0, void 0, function* () { return embeddedWalletSolana.sponsorSolanaTransaction(environmentId, transaction); }),
|
|
101
|
-
operation: 'maybeSponsorTransaction',
|
|
102
|
-
resource: `sponsorSolanaTransaction-attempt-${attempt}`,
|
|
103
|
-
});
|
|
104
|
-
logger.logger.info('[maybeSponsorTransaction] Transaction sponsored successfully');
|
|
105
|
-
return sponsoredTransaction;
|
|
133
|
+
return yield this.attemptSponsorship(environmentId, transaction, sponsorshipMode, attempt);
|
|
106
134
|
}
|
|
107
135
|
catch (error) {
|
|
108
136
|
logger.logger.warn(`[maybeSponsorTransaction] Sponsorship attempt ${attempt}/${SPONSORSHIP_MAX_ATTEMPTS} failed`, { error });
|
|
109
137
|
if (attempt === SPONSORSHIP_MAX_ATTEMPTS ||
|
|
110
138
|
!this.isRetryableSponsorshipError(error)) {
|
|
111
|
-
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
throw new utils.DynamicError(SPONSORSHIP_FAILURE_MESSAGE, SPONSORSHIP_FAILURE_CODE);
|
|
139
|
+
throw this.asSponsorshipError(error);
|
|
115
140
|
}
|
|
116
141
|
yield utils.sleep(SPONSORSHIP_RETRY_INTERVAL_MS);
|
|
117
142
|
}
|
|
@@ -239,21 +264,27 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
|
|
|
239
264
|
});
|
|
240
265
|
}
|
|
241
266
|
internalSignTransaction(transaction_1) {
|
|
242
|
-
return _tslib.__awaiter(this, arguments, void 0, function* (transaction, { parentTraceId, startTime, overrideBlockhash, } = {}) {
|
|
267
|
+
return _tslib.__awaiter(this, arguments, void 0, function* (transaction, { parentTraceId, startTime, overrideBlockhash, sponsorshipMode, } = {}) {
|
|
243
268
|
var _a, _b, _c;
|
|
244
269
|
const traceId = parentTraceId || this.generateTraceId();
|
|
245
270
|
const effectiveStartTime = startTime || Date.now();
|
|
246
|
-
//
|
|
247
|
-
|
|
271
|
+
// Write the blockhash before sponsorship, never after: the sponsor signs the
|
|
272
|
+
// message it is handed, so a later rewrite invalidates its signature and the
|
|
273
|
+
// RPC rejects the transaction at preflight with SignatureFailure.
|
|
274
|
+
const txToSponsor = transaction;
|
|
248
275
|
if (overrideBlockhash) {
|
|
249
|
-
if (solanaCore.isVersionedTransaction(
|
|
250
|
-
|
|
276
|
+
if (solanaCore.isVersionedTransaction(txToSponsor)) {
|
|
277
|
+
txToSponsor.message.recentBlockhash = overrideBlockhash.blockhash;
|
|
251
278
|
}
|
|
252
279
|
else {
|
|
253
|
-
|
|
254
|
-
|
|
280
|
+
txToSponsor.recentBlockhash = overrideBlockhash.blockhash;
|
|
281
|
+
txToSponsor.lastValidBlockHeight =
|
|
282
|
+
overrideBlockhash.lastValidBlockHeight;
|
|
255
283
|
}
|
|
256
284
|
}
|
|
285
|
+
const txToSign = sponsorshipMode
|
|
286
|
+
? yield this.maybeSponsorTransaction(txToSponsor, sponsorshipMode)
|
|
287
|
+
: yield this.maybeSponsorTransaction(txToSponsor);
|
|
257
288
|
const walletClient = yield this.instrumentAsync({
|
|
258
289
|
context: { chainName: 'SVM', startTime: effectiveStartTime, traceId },
|
|
259
290
|
fn: () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.getWaasWalletClient(); }),
|
|
@@ -322,7 +353,7 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
|
|
|
322
353
|
return txToSign;
|
|
323
354
|
});
|
|
324
355
|
}
|
|
325
|
-
signTransaction(transaction) {
|
|
356
|
+
signTransaction(transaction, options) {
|
|
326
357
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
327
358
|
if (!this.activeAccountAddress) {
|
|
328
359
|
throw new Error('Active account address is required');
|
|
@@ -340,11 +371,11 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
|
|
|
340
371
|
from: this.activeAccountAddress,
|
|
341
372
|
multipleTransactions: [transaction],
|
|
342
373
|
onSubmit: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
343
|
-
return this.internalSignTransaction(transaction, {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
});
|
|
374
|
+
return this.internalSignTransaction(transaction, Object.assign(Object.assign({ parentTraceId: traceId }, ((options === null || options === void 0 ? void 0 : options.sponsorshipMode) && {
|
|
375
|
+
sponsorshipMode: options.sponsorshipMode,
|
|
376
|
+
})), { startTime }));
|
|
347
377
|
}),
|
|
378
|
+
sponsorshipMode: options === null || options === void 0 ? void 0 : options.sponsorshipMode,
|
|
348
379
|
});
|
|
349
380
|
const signedTransaction = yield this.walletUiUtils.signTransaction(this, uiTransaction);
|
|
350
381
|
this.instrument('[signTransaction] completed', {
|
|
@@ -356,20 +387,24 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
|
|
|
356
387
|
return signedTransaction;
|
|
357
388
|
});
|
|
358
389
|
}
|
|
359
|
-
internalSignAllTransactions(transactions) {
|
|
390
|
+
internalSignAllTransactions(transactions, options) {
|
|
360
391
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
361
392
|
if (!this.activeAccountAddress) {
|
|
362
393
|
throw new Error('Active account address is required');
|
|
363
394
|
}
|
|
364
395
|
const signedTransactions = [];
|
|
365
396
|
for (const transaction of transactions) {
|
|
366
|
-
const signedTx =
|
|
397
|
+
const signedTx = (options === null || options === void 0 ? void 0 : options.sponsorshipMode)
|
|
398
|
+
? yield this.internalSignTransaction(transaction, {
|
|
399
|
+
sponsorshipMode: options.sponsorshipMode,
|
|
400
|
+
})
|
|
401
|
+
: yield this.internalSignTransaction(transaction);
|
|
367
402
|
signedTransactions.push(signedTx);
|
|
368
403
|
}
|
|
369
404
|
return signedTransactions;
|
|
370
405
|
});
|
|
371
406
|
}
|
|
372
|
-
signAllTransactions(transactions) {
|
|
407
|
+
signAllTransactions(transactions, options) {
|
|
373
408
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
374
409
|
if (!this.activeAccountAddress) {
|
|
375
410
|
throw new Error('Active account address is required');
|
|
@@ -386,7 +421,12 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
|
|
|
386
421
|
connection: this.getWalletClient(),
|
|
387
422
|
from: this.activeAccountAddress,
|
|
388
423
|
multipleTransactions: transactions,
|
|
389
|
-
onSubmit: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
424
|
+
onSubmit: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
425
|
+
return options
|
|
426
|
+
? this.internalSignAllTransactions(transactions, options)
|
|
427
|
+
: this.internalSignAllTransactions(transactions);
|
|
428
|
+
}),
|
|
429
|
+
sponsorshipMode: options === null || options === void 0 ? void 0 : options.sponsorshipMode,
|
|
390
430
|
});
|
|
391
431
|
const signedTransactions = yield this.walletUiUtils.signTransaction(this, uiTransaction);
|
|
392
432
|
this.instrument('[signAllTransactions] completed', {
|
|
@@ -399,17 +439,17 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
|
|
|
399
439
|
});
|
|
400
440
|
}
|
|
401
441
|
internalSignAndSendTransaction(transaction_1, options_1) {
|
|
402
|
-
return _tslib.__awaiter(this, arguments, void 0, function* (transaction, options, { parentTraceId, startTime, } = {}) {
|
|
403
|
-
var _a;
|
|
442
|
+
return _tslib.__awaiter(this, arguments, void 0, function* (transaction, options, { parentTraceId, sponsorshipMode, startTime, } = {}) {
|
|
443
|
+
var _a, _b;
|
|
404
444
|
const traceId = parentTraceId || this.generateTraceId();
|
|
405
445
|
const effectiveStartTime = startTime || Date.now();
|
|
406
446
|
if (!this.activeAccountAddress) {
|
|
407
447
|
throw new Error('Active account address is required');
|
|
408
448
|
}
|
|
409
449
|
const connection = this.getWalletClient();
|
|
410
|
-
// Refresh the blockhash
|
|
411
|
-
//
|
|
412
|
-
//
|
|
450
|
+
// Refresh the blockhash so the tx gets a fresh validity window AND so
|
|
451
|
+
// confirmTransaction's expiration check operates on the same blockhash
|
|
452
|
+
// that's embedded in the tx. Applied before sponsorship.
|
|
413
453
|
// Use 'finalized' so the blockhash is recognized by every RPC node
|
|
414
454
|
// (a 'confirmed' blockhash may not yet have propagated to the simulating
|
|
415
455
|
// node, which surfaces as "Blockhash not found" at sendRawTransaction).
|
|
@@ -420,6 +460,7 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
|
|
|
420
460
|
return this.internalSignTransaction(transaction, {
|
|
421
461
|
overrideBlockhash: { blockhash, lastValidBlockHeight },
|
|
422
462
|
parentTraceId: traceId,
|
|
463
|
+
sponsorshipMode,
|
|
423
464
|
startTime: effectiveStartTime,
|
|
424
465
|
});
|
|
425
466
|
}),
|
|
@@ -447,12 +488,18 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
|
|
|
447
488
|
resource: 'sendRawTransaction',
|
|
448
489
|
});
|
|
449
490
|
const confirmationStartTime = Date.now();
|
|
491
|
+
// Confirm against the blockhash the broadcast tx actually carries, in case a
|
|
492
|
+
// sponsor ever substitutes its own. lastValidBlockHeight stays local, which
|
|
493
|
+
// only errs on the side of giving up early.
|
|
494
|
+
const broadcastBlockhash = isVersionedSolanaTransaction
|
|
495
|
+
? signedTransaction.message.recentBlockhash
|
|
496
|
+
: (_a = signedTransaction.recentBlockhash) !== null && _a !== void 0 ? _a : blockhash;
|
|
450
497
|
try {
|
|
451
498
|
const confirmationResult = yield connection.confirmTransaction({
|
|
452
|
-
blockhash,
|
|
499
|
+
blockhash: broadcastBlockhash,
|
|
453
500
|
lastValidBlockHeight,
|
|
454
501
|
signature,
|
|
455
|
-
}, (
|
|
502
|
+
}, (_b = options === null || options === void 0 ? void 0 : options.preflightCommitment) !== null && _b !== void 0 ? _b : 'confirmed');
|
|
456
503
|
const confirmationEndTime = Date.now();
|
|
457
504
|
const confirmationStepElapsed = confirmationEndTime - confirmationStartTime;
|
|
458
505
|
const confirmationTotalElapsed = confirmationEndTime - effectiveStartTime;
|
|
@@ -502,6 +549,7 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
|
|
|
502
549
|
}
|
|
503
550
|
const traceId = this.generateTraceId();
|
|
504
551
|
const startTime = Date.now();
|
|
552
|
+
const _a = options !== null && options !== void 0 ? options : {}, { sponsorshipMode } = _a, sendOptions = _tslib.__rest(_a, ["sponsorshipMode"]);
|
|
505
553
|
this.instrument('[signAndSendTransaction] start', {
|
|
506
554
|
key: 'signAndSendTransaction-start',
|
|
507
555
|
options,
|
|
@@ -514,11 +562,9 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
|
|
|
514
562
|
from: this.activeAccountAddress,
|
|
515
563
|
multipleTransactions: [transaction],
|
|
516
564
|
onSubmit: () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
517
|
-
return this.internalSignAndSendTransaction(transaction, options, {
|
|
518
|
-
parentTraceId: traceId,
|
|
519
|
-
startTime,
|
|
520
|
-
});
|
|
565
|
+
return this.internalSignAndSendTransaction(transaction, options ? sendOptions : undefined, Object.assign(Object.assign({ parentTraceId: traceId }, (sponsorshipMode && { sponsorshipMode })), { startTime }));
|
|
521
566
|
}),
|
|
567
|
+
sponsorshipMode,
|
|
522
568
|
});
|
|
523
569
|
const result = yield this.walletUiUtils.sendTransaction(this, uiTransaction);
|
|
524
570
|
this.instrument('[signAndSendTransaction] completed', {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connection, SendOptions, Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
2
2
|
import { MFAAction, TokenScope } from '@dynamic-labs/sdk-api-core';
|
|
3
|
-
import { ISolanaSigner, SolanaWalletConnector, SolanaWalletConnectorOpts } from '@dynamic-labs/solana-core';
|
|
3
|
+
import { GasSponsorshipMode, ISolanaSigner, SolanaSendOptions, SolanaTransactionOptions, SolanaWalletConnector, SolanaWalletConnectorOpts } from '@dynamic-labs/solana-core';
|
|
4
4
|
import { IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
|
|
5
5
|
import { ExportClientKeysharesParams, IDynamicWaasConnector, InternalWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
6
6
|
import { Logger } from '../../utils/logger';
|
|
@@ -160,10 +160,14 @@ declare const DynamicWaasSVMConnector_base: (abstract new (...args: any[]) => {
|
|
|
160
160
|
unlockWallet({ accountAddress, password, }: {
|
|
161
161
|
accountAddress: string;
|
|
162
162
|
password?: string | undefined;
|
|
163
|
-
}): Promise<import("@dynamic-labs-wallet/
|
|
163
|
+
}): Promise<import("@dynamic-labs-wallet/browser-wallet-client").GetWalletResponse>;
|
|
164
|
+
lockWallets(): Promise<void>;
|
|
165
|
+
lockWallet({ accountAddress }: {
|
|
166
|
+
accountAddress: string;
|
|
167
|
+
}): Promise<void>;
|
|
164
168
|
getWalletRecoveryState({ accountAddress, }: {
|
|
165
169
|
accountAddress: string;
|
|
166
|
-
}): Promise<import("@dynamic-labs-wallet/
|
|
170
|
+
}): Promise<import("@dynamic-labs-wallet/browser-wallet-client").WalletRecoveryState>;
|
|
167
171
|
createOfflineRecoveryShares({ accountAddress, password, cloudProviderAccessToken, mfaToken, }: {
|
|
168
172
|
accountAddress: string;
|
|
169
173
|
password?: string | undefined;
|
|
@@ -209,6 +213,7 @@ export declare class DynamicWaasSVMConnector extends DynamicWaasSVMConnector_bas
|
|
|
209
213
|
activeAccountAddress: string | undefined;
|
|
210
214
|
protected walletUiUtils: WalletUiUtils<InternalWalletConnector>;
|
|
211
215
|
private getSvmGasSponsorshipEnabled;
|
|
216
|
+
readonly supportsSvmGasSponsorship = true;
|
|
212
217
|
constructor(props: DynamicWaasSVMConnectorProps);
|
|
213
218
|
/**
|
|
214
219
|
* Set a getter that resolves the current SVM gas sponsorship state.
|
|
@@ -227,6 +232,9 @@ export declare class DynamicWaasSVMConnector extends DynamicWaasSVMConnector_bas
|
|
|
227
232
|
* Check if a transaction is already signed (has non-zero signatures).
|
|
228
233
|
*/
|
|
229
234
|
private isTxAlreadySigned;
|
|
235
|
+
private getFeePayerAddress;
|
|
236
|
+
private attemptSponsorship;
|
|
237
|
+
private asSponsorshipError;
|
|
230
238
|
/**
|
|
231
239
|
* Sponsor a transaction if gas sponsorship is enabled and the tx is unsigned.
|
|
232
240
|
* Retries transient failures; throws if sponsorship never succeeds so callers
|
|
@@ -247,22 +255,24 @@ export declare class DynamicWaasSVMConnector extends DynamicWaasSVMConnector_bas
|
|
|
247
255
|
startTime?: number;
|
|
248
256
|
}): Promise<string>;
|
|
249
257
|
signMessage(message: string): Promise<string>;
|
|
250
|
-
internalSignTransaction<T extends Transaction | VersionedTransaction>(transaction: T, { parentTraceId, startTime, overrideBlockhash, }?: {
|
|
258
|
+
internalSignTransaction<T extends Transaction | VersionedTransaction>(transaction: T, { parentTraceId, startTime, overrideBlockhash, sponsorshipMode, }?: {
|
|
251
259
|
parentTraceId?: string;
|
|
252
260
|
startTime?: number;
|
|
253
261
|
overrideBlockhash?: {
|
|
254
262
|
blockhash: string;
|
|
255
263
|
lastValidBlockHeight: number;
|
|
256
264
|
};
|
|
265
|
+
sponsorshipMode?: GasSponsorshipMode;
|
|
257
266
|
}): Promise<Transaction | VersionedTransaction>;
|
|
258
|
-
signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<Transaction | VersionedTransaction>;
|
|
259
|
-
internalSignAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<(Transaction | VersionedTransaction)[]>;
|
|
260
|
-
signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<(Transaction | VersionedTransaction)[]>;
|
|
261
|
-
internalSignAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions, { parentTraceId, startTime, }?: {
|
|
267
|
+
signTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SolanaTransactionOptions): Promise<Transaction | VersionedTransaction>;
|
|
268
|
+
internalSignAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[], options?: SolanaTransactionOptions): Promise<(Transaction | VersionedTransaction)[]>;
|
|
269
|
+
signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[], options?: SolanaTransactionOptions): Promise<(Transaction | VersionedTransaction)[]>;
|
|
270
|
+
internalSignAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions, { parentTraceId, sponsorshipMode, startTime, }?: {
|
|
262
271
|
parentTraceId?: string;
|
|
272
|
+
sponsorshipMode?: GasSponsorshipMode;
|
|
263
273
|
startTime?: number;
|
|
264
274
|
}): Promise<string>;
|
|
265
|
-
signAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?:
|
|
275
|
+
signAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SolanaSendOptions): Promise<string>;
|
|
266
276
|
getSigner(): Promise<ISolanaSigner>;
|
|
267
277
|
getWalletClientByAddress({ accountAddress, }: {
|
|
268
278
|
accountAddress: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
2
|
+
import { __awaiter, __rest } from '../../_virtual/_tslib.js';
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
4
|
import { sponsorSolanaTransaction } from '@dynamic-labs/embedded-wallet-solana';
|
|
5
5
|
import { MFAAction, TokenScope } from '@dynamic-labs/sdk-api-core';
|
|
@@ -26,6 +26,7 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
|
|
|
26
26
|
this.overrideKey = 'dynamicwaas';
|
|
27
27
|
this.isEmbeddedWallet = true;
|
|
28
28
|
this.getSvmGasSponsorshipEnabled = () => false;
|
|
29
|
+
this.supportsSvmGasSponsorship = true;
|
|
29
30
|
this.logger = logger;
|
|
30
31
|
this.walletUiUtils = props.walletUiUtils;
|
|
31
32
|
}
|
|
@@ -67,18 +68,52 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
|
|
|
67
68
|
}
|
|
68
69
|
return transaction.signatures.some((sig) => sig.signature && !sig.signature.every((byte) => byte === 0));
|
|
69
70
|
}
|
|
71
|
+
getFeePayerAddress(transaction) {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
if ('version' in transaction) {
|
|
74
|
+
return (_a = transaction.message.staticAccountKeys[0]) === null || _a === void 0 ? void 0 : _a.toBase58();
|
|
75
|
+
}
|
|
76
|
+
return (_b = transaction.feePayer) === null || _b === void 0 ? void 0 : _b.toBase58();
|
|
77
|
+
}
|
|
78
|
+
attemptSponsorship(environmentId, transaction, sponsorshipMode, attempt) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const sponsoredTransaction = yield this.instrumentAsync({
|
|
81
|
+
context: { attempt, maxAttempts: SPONSORSHIP_MAX_ATTEMPTS },
|
|
82
|
+
fn: () => __awaiter(this, void 0, void 0, function* () { return sponsorSolanaTransaction(environmentId, transaction); }),
|
|
83
|
+
operation: 'maybeSponsorTransaction',
|
|
84
|
+
resource: `sponsorSolanaTransaction-attempt-${attempt}`,
|
|
85
|
+
});
|
|
86
|
+
const feePayer = this.getFeePayerAddress(sponsoredTransaction);
|
|
87
|
+
if (sponsorshipMode === 'required' &&
|
|
88
|
+
(!feePayer || feePayer === this.activeAccountAddress)) {
|
|
89
|
+
throw new DynamicError('Sponsored transaction is not sponsored', 'sponsorship_not_applied');
|
|
90
|
+
}
|
|
91
|
+
logger.info('[maybeSponsorTransaction] Transaction sponsored successfully');
|
|
92
|
+
return sponsoredTransaction;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
asSponsorshipError(error) {
|
|
96
|
+
if (error instanceof DynamicError) {
|
|
97
|
+
return error;
|
|
98
|
+
}
|
|
99
|
+
return new DynamicError(SPONSORSHIP_FAILURE_MESSAGE, SPONSORSHIP_FAILURE_CODE);
|
|
100
|
+
}
|
|
70
101
|
/**
|
|
71
102
|
* Sponsor a transaction if gas sponsorship is enabled and the tx is unsigned.
|
|
72
103
|
* Retries transient failures; throws if sponsorship never succeeds so callers
|
|
73
104
|
* never sign and return a transaction that silently skipped sponsorship
|
|
74
105
|
* (e.g. a 0-SOL wallet still set as fee payer).
|
|
75
106
|
*/
|
|
76
|
-
maybeSponsorTransaction(
|
|
77
|
-
return __awaiter(this,
|
|
78
|
-
if (
|
|
107
|
+
maybeSponsorTransaction(transaction_1) {
|
|
108
|
+
return __awaiter(this, arguments, void 0, function* (transaction, sponsorshipMode = 'auto') {
|
|
109
|
+
if (sponsorshipMode === 'off' ||
|
|
110
|
+
(sponsorshipMode === 'auto' && !this.getSvmGasSponsorshipEnabled())) {
|
|
79
111
|
return transaction;
|
|
80
112
|
}
|
|
81
113
|
if (this.isTxAlreadySigned(transaction)) {
|
|
114
|
+
if (sponsorshipMode === 'required') {
|
|
115
|
+
throw new DynamicError('Signed transactions cannot be sponsored', 'sponsorship_transaction_already_signed');
|
|
116
|
+
}
|
|
82
117
|
logger.debug('[maybeSponsorTransaction] Skipping sponsorship - transaction already signed');
|
|
83
118
|
return transaction;
|
|
84
119
|
}
|
|
@@ -91,23 +126,13 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
|
|
|
91
126
|
const { environmentId } = this;
|
|
92
127
|
for (let attempt = 1; attempt <= SPONSORSHIP_MAX_ATTEMPTS; attempt++) {
|
|
93
128
|
try {
|
|
94
|
-
|
|
95
|
-
context: { attempt, maxAttempts: SPONSORSHIP_MAX_ATTEMPTS },
|
|
96
|
-
fn: () => __awaiter(this, void 0, void 0, function* () { return sponsorSolanaTransaction(environmentId, transaction); }),
|
|
97
|
-
operation: 'maybeSponsorTransaction',
|
|
98
|
-
resource: `sponsorSolanaTransaction-attempt-${attempt}`,
|
|
99
|
-
});
|
|
100
|
-
logger.info('[maybeSponsorTransaction] Transaction sponsored successfully');
|
|
101
|
-
return sponsoredTransaction;
|
|
129
|
+
return yield this.attemptSponsorship(environmentId, transaction, sponsorshipMode, attempt);
|
|
102
130
|
}
|
|
103
131
|
catch (error) {
|
|
104
132
|
logger.warn(`[maybeSponsorTransaction] Sponsorship attempt ${attempt}/${SPONSORSHIP_MAX_ATTEMPTS} failed`, { error });
|
|
105
133
|
if (attempt === SPONSORSHIP_MAX_ATTEMPTS ||
|
|
106
134
|
!this.isRetryableSponsorshipError(error)) {
|
|
107
|
-
|
|
108
|
-
throw error;
|
|
109
|
-
}
|
|
110
|
-
throw new DynamicError(SPONSORSHIP_FAILURE_MESSAGE, SPONSORSHIP_FAILURE_CODE);
|
|
135
|
+
throw this.asSponsorshipError(error);
|
|
111
136
|
}
|
|
112
137
|
yield sleep(SPONSORSHIP_RETRY_INTERVAL_MS);
|
|
113
138
|
}
|
|
@@ -235,21 +260,27 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
|
|
|
235
260
|
});
|
|
236
261
|
}
|
|
237
262
|
internalSignTransaction(transaction_1) {
|
|
238
|
-
return __awaiter(this, arguments, void 0, function* (transaction, { parentTraceId, startTime, overrideBlockhash, } = {}) {
|
|
263
|
+
return __awaiter(this, arguments, void 0, function* (transaction, { parentTraceId, startTime, overrideBlockhash, sponsorshipMode, } = {}) {
|
|
239
264
|
var _a, _b, _c;
|
|
240
265
|
const traceId = parentTraceId || this.generateTraceId();
|
|
241
266
|
const effectiveStartTime = startTime || Date.now();
|
|
242
|
-
//
|
|
243
|
-
|
|
267
|
+
// Write the blockhash before sponsorship, never after: the sponsor signs the
|
|
268
|
+
// message it is handed, so a later rewrite invalidates its signature and the
|
|
269
|
+
// RPC rejects the transaction at preflight with SignatureFailure.
|
|
270
|
+
const txToSponsor = transaction;
|
|
244
271
|
if (overrideBlockhash) {
|
|
245
|
-
if (isVersionedTransaction(
|
|
246
|
-
|
|
272
|
+
if (isVersionedTransaction(txToSponsor)) {
|
|
273
|
+
txToSponsor.message.recentBlockhash = overrideBlockhash.blockhash;
|
|
247
274
|
}
|
|
248
275
|
else {
|
|
249
|
-
|
|
250
|
-
|
|
276
|
+
txToSponsor.recentBlockhash = overrideBlockhash.blockhash;
|
|
277
|
+
txToSponsor.lastValidBlockHeight =
|
|
278
|
+
overrideBlockhash.lastValidBlockHeight;
|
|
251
279
|
}
|
|
252
280
|
}
|
|
281
|
+
const txToSign = sponsorshipMode
|
|
282
|
+
? yield this.maybeSponsorTransaction(txToSponsor, sponsorshipMode)
|
|
283
|
+
: yield this.maybeSponsorTransaction(txToSponsor);
|
|
253
284
|
const walletClient = yield this.instrumentAsync({
|
|
254
285
|
context: { chainName: 'SVM', startTime: effectiveStartTime, traceId },
|
|
255
286
|
fn: () => __awaiter(this, void 0, void 0, function* () { return this.getWaasWalletClient(); }),
|
|
@@ -318,7 +349,7 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
|
|
|
318
349
|
return txToSign;
|
|
319
350
|
});
|
|
320
351
|
}
|
|
321
|
-
signTransaction(transaction) {
|
|
352
|
+
signTransaction(transaction, options) {
|
|
322
353
|
return __awaiter(this, void 0, void 0, function* () {
|
|
323
354
|
if (!this.activeAccountAddress) {
|
|
324
355
|
throw new Error('Active account address is required');
|
|
@@ -336,11 +367,11 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
|
|
|
336
367
|
from: this.activeAccountAddress,
|
|
337
368
|
multipleTransactions: [transaction],
|
|
338
369
|
onSubmit: () => __awaiter(this, void 0, void 0, function* () {
|
|
339
|
-
return this.internalSignTransaction(transaction, {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
});
|
|
370
|
+
return this.internalSignTransaction(transaction, Object.assign(Object.assign({ parentTraceId: traceId }, ((options === null || options === void 0 ? void 0 : options.sponsorshipMode) && {
|
|
371
|
+
sponsorshipMode: options.sponsorshipMode,
|
|
372
|
+
})), { startTime }));
|
|
343
373
|
}),
|
|
374
|
+
sponsorshipMode: options === null || options === void 0 ? void 0 : options.sponsorshipMode,
|
|
344
375
|
});
|
|
345
376
|
const signedTransaction = yield this.walletUiUtils.signTransaction(this, uiTransaction);
|
|
346
377
|
this.instrument('[signTransaction] completed', {
|
|
@@ -352,20 +383,24 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
|
|
|
352
383
|
return signedTransaction;
|
|
353
384
|
});
|
|
354
385
|
}
|
|
355
|
-
internalSignAllTransactions(transactions) {
|
|
386
|
+
internalSignAllTransactions(transactions, options) {
|
|
356
387
|
return __awaiter(this, void 0, void 0, function* () {
|
|
357
388
|
if (!this.activeAccountAddress) {
|
|
358
389
|
throw new Error('Active account address is required');
|
|
359
390
|
}
|
|
360
391
|
const signedTransactions = [];
|
|
361
392
|
for (const transaction of transactions) {
|
|
362
|
-
const signedTx =
|
|
393
|
+
const signedTx = (options === null || options === void 0 ? void 0 : options.sponsorshipMode)
|
|
394
|
+
? yield this.internalSignTransaction(transaction, {
|
|
395
|
+
sponsorshipMode: options.sponsorshipMode,
|
|
396
|
+
})
|
|
397
|
+
: yield this.internalSignTransaction(transaction);
|
|
363
398
|
signedTransactions.push(signedTx);
|
|
364
399
|
}
|
|
365
400
|
return signedTransactions;
|
|
366
401
|
});
|
|
367
402
|
}
|
|
368
|
-
signAllTransactions(transactions) {
|
|
403
|
+
signAllTransactions(transactions, options) {
|
|
369
404
|
return __awaiter(this, void 0, void 0, function* () {
|
|
370
405
|
if (!this.activeAccountAddress) {
|
|
371
406
|
throw new Error('Active account address is required');
|
|
@@ -382,7 +417,12 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
|
|
|
382
417
|
connection: this.getWalletClient(),
|
|
383
418
|
from: this.activeAccountAddress,
|
|
384
419
|
multipleTransactions: transactions,
|
|
385
|
-
onSubmit: () => __awaiter(this, void 0, void 0, function* () {
|
|
420
|
+
onSubmit: () => __awaiter(this, void 0, void 0, function* () {
|
|
421
|
+
return options
|
|
422
|
+
? this.internalSignAllTransactions(transactions, options)
|
|
423
|
+
: this.internalSignAllTransactions(transactions);
|
|
424
|
+
}),
|
|
425
|
+
sponsorshipMode: options === null || options === void 0 ? void 0 : options.sponsorshipMode,
|
|
386
426
|
});
|
|
387
427
|
const signedTransactions = yield this.walletUiUtils.signTransaction(this, uiTransaction);
|
|
388
428
|
this.instrument('[signAllTransactions] completed', {
|
|
@@ -395,17 +435,17 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
|
|
|
395
435
|
});
|
|
396
436
|
}
|
|
397
437
|
internalSignAndSendTransaction(transaction_1, options_1) {
|
|
398
|
-
return __awaiter(this, arguments, void 0, function* (transaction, options, { parentTraceId, startTime, } = {}) {
|
|
399
|
-
var _a;
|
|
438
|
+
return __awaiter(this, arguments, void 0, function* (transaction, options, { parentTraceId, sponsorshipMode, startTime, } = {}) {
|
|
439
|
+
var _a, _b;
|
|
400
440
|
const traceId = parentTraceId || this.generateTraceId();
|
|
401
441
|
const effectiveStartTime = startTime || Date.now();
|
|
402
442
|
if (!this.activeAccountAddress) {
|
|
403
443
|
throw new Error('Active account address is required');
|
|
404
444
|
}
|
|
405
445
|
const connection = this.getWalletClient();
|
|
406
|
-
// Refresh the blockhash
|
|
407
|
-
//
|
|
408
|
-
//
|
|
446
|
+
// Refresh the blockhash so the tx gets a fresh validity window AND so
|
|
447
|
+
// confirmTransaction's expiration check operates on the same blockhash
|
|
448
|
+
// that's embedded in the tx. Applied before sponsorship.
|
|
409
449
|
// Use 'finalized' so the blockhash is recognized by every RPC node
|
|
410
450
|
// (a 'confirmed' blockhash may not yet have propagated to the simulating
|
|
411
451
|
// node, which surfaces as "Blockhash not found" at sendRawTransaction).
|
|
@@ -416,6 +456,7 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
|
|
|
416
456
|
return this.internalSignTransaction(transaction, {
|
|
417
457
|
overrideBlockhash: { blockhash, lastValidBlockHeight },
|
|
418
458
|
parentTraceId: traceId,
|
|
459
|
+
sponsorshipMode,
|
|
419
460
|
startTime: effectiveStartTime,
|
|
420
461
|
});
|
|
421
462
|
}),
|
|
@@ -443,12 +484,18 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
|
|
|
443
484
|
resource: 'sendRawTransaction',
|
|
444
485
|
});
|
|
445
486
|
const confirmationStartTime = Date.now();
|
|
487
|
+
// Confirm against the blockhash the broadcast tx actually carries, in case a
|
|
488
|
+
// sponsor ever substitutes its own. lastValidBlockHeight stays local, which
|
|
489
|
+
// only errs on the side of giving up early.
|
|
490
|
+
const broadcastBlockhash = isVersionedSolanaTransaction
|
|
491
|
+
? signedTransaction.message.recentBlockhash
|
|
492
|
+
: (_a = signedTransaction.recentBlockhash) !== null && _a !== void 0 ? _a : blockhash;
|
|
446
493
|
try {
|
|
447
494
|
const confirmationResult = yield connection.confirmTransaction({
|
|
448
|
-
blockhash,
|
|
495
|
+
blockhash: broadcastBlockhash,
|
|
449
496
|
lastValidBlockHeight,
|
|
450
497
|
signature,
|
|
451
|
-
}, (
|
|
498
|
+
}, (_b = options === null || options === void 0 ? void 0 : options.preflightCommitment) !== null && _b !== void 0 ? _b : 'confirmed');
|
|
452
499
|
const confirmationEndTime = Date.now();
|
|
453
500
|
const confirmationStepElapsed = confirmationEndTime - confirmationStartTime;
|
|
454
501
|
const confirmationTotalElapsed = confirmationEndTime - effectiveStartTime;
|
|
@@ -498,6 +545,7 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
|
|
|
498
545
|
}
|
|
499
546
|
const traceId = this.generateTraceId();
|
|
500
547
|
const startTime = Date.now();
|
|
548
|
+
const _a = options !== null && options !== void 0 ? options : {}, { sponsorshipMode } = _a, sendOptions = __rest(_a, ["sponsorshipMode"]);
|
|
501
549
|
this.instrument('[signAndSendTransaction] start', {
|
|
502
550
|
key: 'signAndSendTransaction-start',
|
|
503
551
|
options,
|
|
@@ -510,11 +558,9 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
|
|
|
510
558
|
from: this.activeAccountAddress,
|
|
511
559
|
multipleTransactions: [transaction],
|
|
512
560
|
onSubmit: () => __awaiter(this, void 0, void 0, function* () {
|
|
513
|
-
return this.internalSignAndSendTransaction(transaction, options, {
|
|
514
|
-
parentTraceId: traceId,
|
|
515
|
-
startTime,
|
|
516
|
-
});
|
|
561
|
+
return this.internalSignAndSendTransaction(transaction, options ? sendOptions : undefined, Object.assign(Object.assign({ parentTraceId: traceId }, (sponsorshipMode && { sponsorshipMode })), { startTime }));
|
|
517
562
|
}),
|
|
563
|
+
sponsorshipMode,
|
|
518
564
|
});
|
|
519
565
|
const result = yield this.walletUiUtils.sendTransaction(this, uiTransaction);
|
|
520
566
|
this.instrument('[signAndSendTransaction] completed', {
|
|
@@ -46,13 +46,19 @@ class DynamicWaasSVMSigner extends EventEmitter__default["default"] {
|
|
|
46
46
|
return { signature: signatureBytes };
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
signTransaction(transaction) {
|
|
49
|
+
signTransaction(transaction, options) {
|
|
50
50
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
if (options) {
|
|
52
|
+
return this.walletConnector.signTransaction(transaction, options);
|
|
53
|
+
}
|
|
51
54
|
return this.walletConnector.signTransaction(transaction);
|
|
52
55
|
});
|
|
53
56
|
}
|
|
54
|
-
signAllTransactions(transactions) {
|
|
57
|
+
signAllTransactions(transactions, options) {
|
|
55
58
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
if (options) {
|
|
60
|
+
return this.walletConnector.signAllTransactions(transactions, options);
|
|
61
|
+
}
|
|
56
62
|
return this.walletConnector.signAllTransactions(transactions);
|
|
57
63
|
});
|
|
58
64
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PublicKey,
|
|
1
|
+
import { PublicKey, Transaction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
|
|
2
2
|
import EventEmitter from 'eventemitter3';
|
|
3
|
-
import { SignedMessage, ISolanaSigner, ConnectionResult, ISolanaEvents } from '@dynamic-labs/solana-core';
|
|
3
|
+
import { SignedMessage, ISolanaSigner, ConnectionResult, ISolanaEvents, SolanaSendOptions, SolanaTransactionOptions } from '@dynamic-labs/solana-core';
|
|
4
4
|
import { DynamicWaasSVMConnector } from '../connector/DynamicWaasSVMConnector';
|
|
5
5
|
/**
|
|
6
6
|
* Signer implementation for DynamicWaasSVMConnector
|
|
@@ -23,9 +23,9 @@ export declare class DynamicWaasSVMSigner extends EventEmitter<ISolanaEvents> im
|
|
|
23
23
|
walletConnector: DynamicWaasSVMConnector;
|
|
24
24
|
});
|
|
25
25
|
signMessage(encodedMessage: Uint8Array): Promise<SignedMessage>;
|
|
26
|
-
signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
|
|
27
|
-
signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<T[]>;
|
|
28
|
-
signAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?:
|
|
26
|
+
signTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SolanaTransactionOptions): Promise<T>;
|
|
27
|
+
signAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[], options?: SolanaTransactionOptions): Promise<T[]>;
|
|
28
|
+
signAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SolanaSendOptions): Promise<{
|
|
29
29
|
signature: TransactionSignature;
|
|
30
30
|
}>;
|
|
31
31
|
connect(_args?: {
|
|
@@ -37,13 +37,19 @@ class DynamicWaasSVMSigner extends EventEmitter {
|
|
|
37
37
|
return { signature: signatureBytes };
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
signTransaction(transaction) {
|
|
40
|
+
signTransaction(transaction, options) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
if (options) {
|
|
43
|
+
return this.walletConnector.signTransaction(transaction, options);
|
|
44
|
+
}
|
|
42
45
|
return this.walletConnector.signTransaction(transaction);
|
|
43
46
|
});
|
|
44
47
|
}
|
|
45
|
-
signAllTransactions(transactions) {
|
|
48
|
+
signAllTransactions(transactions, options) {
|
|
46
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
if (options) {
|
|
51
|
+
return this.walletConnector.signAllTransactions(transactions, options);
|
|
52
|
+
}
|
|
47
53
|
return this.walletConnector.signAllTransactions(transactions);
|
|
48
54
|
});
|
|
49
55
|
}
|