@dynamic-labs/waas-evm 4.96.4 → 4.98.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/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +9 -8
- package/src/DynamicWaasEVMConnector.cjs +102 -0
- package/src/DynamicWaasEVMConnector.d.ts +20 -1
- package/src/DynamicWaasEVMConnector.js +103 -1
- package/src/gasless/toSponsoredTransactionCalls/toSponsoredTransactionCalls.cjs +39 -0
- package/src/gasless/toSponsoredTransactionCalls/toSponsoredTransactionCalls.d.ts +13 -0
- package/src/gasless/toSponsoredTransactionCalls/toSponsoredTransactionCalls.js +35 -0
- package/src/gasless/withBigintSafeSignTypedData/withBigintSafeSignTypedData.cjs +37 -0
- package/src/gasless/withBigintSafeSignTypedData/withBigintSafeSignTypedData.d.ts +7 -0
- package/src/gasless/withBigintSafeSignTypedData/withBigintSafeSignTypedData.js +33 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
|
|
2
|
+
## [4.98.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.97.0...v4.98.0) (2026-09-02)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* **waas-evm:** route embedded EVM sends through gas sponsorship when enabled (V4) ([#12307](https://github.com/dynamic-labs/dynamic-auth/issues/12307)) ([d8e6b94](https://github.com/dynamic-labs/dynamic-auth/commit/d8e6b94dc86e1d48b66a246bf8bf0b857e7e69c4))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* **sdk-react-core:** send a css overrides summary in sdkSettings telemetry (v4) ([#12330](https://github.com/dynamic-labs/dynamic-auth/issues/12330)) ([8547ee7](https://github.com/dynamic-labs/dynamic-auth/commit/8547ee7a7c3fef8de0ff384778f86542b809e7aa))
|
|
13
|
+
* **waas-svm:** apply overrideBlockhash before sponsorship [v4 backport] ([#12320](https://github.com/dynamic-labs/dynamic-auth/issues/12320)) ([0551f01](https://github.com/dynamic-labs/dynamic-auth/commit/0551f01953f5e623ac113b03e1b010d3dc58a81e)), 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)
|
|
14
|
+
|
|
15
|
+
## [4.97.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.96.4...v4.97.0) (2026-08-27)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* **screening:** connected-wallet transaction screening [v4 backport] (DYNT-1663) ([#12284](https://github.com/dynamic-labs/dynamic-auth/issues/12284)) ([294adba](https://github.com/dynamic-labs/dynamic-auth/commit/294adba7dba8f321f3b1e8413f73545701e51252)), closes [#12160](https://github.com/dynamic-labs/dynamic-auth/issues/12160) [#12167](https://github.com/dynamic-labs/dynamic-auth/issues/12167) [#12168](https://github.com/dynamic-labs/dynamic-auth/issues/12168) [#12169](https://github.com/dynamic-labs/dynamic-auth/issues/12169) [#12172](https://github.com/dynamic-labs/dynamic-auth/issues/12172)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* **screening:** wire connected-wallet screening into the Send Balance UI (DYNT-1663) ([#12289](https://github.com/dynamic-labs/dynamic-auth/issues/12289)) ([1587cd8](https://github.com/dynamic-labs/dynamic-auth/commit/1587cd833370e18fa383f942521500e4c1576390))
|
|
26
|
+
|
|
2
27
|
### [4.96.4](https://github.com/dynamic-labs/dynamic-auth/compare/v4.96.3...v4.96.4) (2026-08-26)
|
|
3
28
|
|
|
4
29
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/waas-evm",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.98.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",
|
|
@@ -18,15 +18,16 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@dynamic-labs/ethereum-gasless-core": "4.98.0",
|
|
21
22
|
"@dynamic-labs/sdk-api-core": "0.12.0",
|
|
22
23
|
"viem": "^2.45.3",
|
|
23
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
24
|
-
"@dynamic-labs/ethereum-core": "4.
|
|
25
|
-
"@dynamic-labs/logger": "4.
|
|
26
|
-
"@dynamic-labs/types": "4.
|
|
27
|
-
"@dynamic-labs/utils": "4.
|
|
28
|
-
"@dynamic-labs/waas": "4.
|
|
29
|
-
"@dynamic-labs/wallet-connector-core": "4.
|
|
24
|
+
"@dynamic-labs/assert-package-version": "4.98.0",
|
|
25
|
+
"@dynamic-labs/ethereum-core": "4.98.0",
|
|
26
|
+
"@dynamic-labs/logger": "4.98.0",
|
|
27
|
+
"@dynamic-labs/types": "4.98.0",
|
|
28
|
+
"@dynamic-labs/utils": "4.98.0",
|
|
29
|
+
"@dynamic-labs/waas": "4.98.0",
|
|
30
|
+
"@dynamic-labs/wallet-connector-core": "4.98.0"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {}
|
|
32
33
|
}
|
|
@@ -8,11 +8,14 @@ var viem = require('viem');
|
|
|
8
8
|
var accounts = require('viem/accounts');
|
|
9
9
|
var utils$1 = require('viem/utils');
|
|
10
10
|
var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
11
|
+
var ethereumGaslessCore = require('@dynamic-labs/ethereum-gasless-core');
|
|
11
12
|
var logger$1 = require('@dynamic-labs/logger');
|
|
12
13
|
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
13
14
|
var utils = require('@dynamic-labs/utils');
|
|
14
15
|
var waas = require('@dynamic-labs/waas');
|
|
15
16
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
17
|
+
var toSponsoredTransactionCalls = require('./gasless/toSponsoredTransactionCalls/toSponsoredTransactionCalls.cjs');
|
|
18
|
+
var withBigintSafeSignTypedData = require('./gasless/withBigintSafeSignTypedData/withBigintSafeSignTypedData.cjs');
|
|
16
19
|
|
|
17
20
|
const logger = new logger$1.Logger('DynamicWaasConnector');
|
|
18
21
|
class DynamicWaasEVMConnector extends waas.withDynamicWaas(ethereumCore.EthereumWalletConnector) {
|
|
@@ -43,6 +46,9 @@ class DynamicWaasEVMConnector extends waas.withDynamicWaas(ethereumCore.Ethereum
|
|
|
43
46
|
this.logger = logger;
|
|
44
47
|
this.overrideKey = 'dynamicwaas';
|
|
45
48
|
this.isEmbeddedWallet = true;
|
|
49
|
+
this.getEvmGasSponsorshipEnabled = () => false;
|
|
50
|
+
this.getSponsorshipSdkApi = undefined;
|
|
51
|
+
this.delegation7702Registry = ethereumGaslessCore.create7702DelegationRegistry();
|
|
46
52
|
/**
|
|
47
53
|
* Chain IDs that have dedicated connectors and should not be handled by this connector.
|
|
48
54
|
* Networks with these chain IDs are filtered from network lists and rejected during switching.
|
|
@@ -555,8 +561,94 @@ class DynamicWaasEVMConnector extends waas.withDynamicWaas(ethereumCore.Ethereum
|
|
|
555
561
|
});
|
|
556
562
|
});
|
|
557
563
|
}
|
|
564
|
+
/**
|
|
565
|
+
* Registers the project's EVM gas sponsorship configuration so the send flow
|
|
566
|
+
* can route transactions through the sponsored relay instead of paying fees
|
|
567
|
+
* from the wallet's native balance.
|
|
568
|
+
*/
|
|
569
|
+
setEvmGasSponsorshipConfig({ getEnabled, getSdkApi, }) {
|
|
570
|
+
this.getEvmGasSponsorshipEnabled = getEnabled;
|
|
571
|
+
this.getSponsorshipSdkApi = getSdkApi;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Sponsorship requires the project setting, an SDK API client and a relayer
|
|
575
|
+
* funded for the wallet's current chain. Anything missing means the send flow
|
|
576
|
+
* pays fees from the wallet's native balance.
|
|
577
|
+
*/
|
|
578
|
+
isGasSponsorshipAvailable() {
|
|
579
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
580
|
+
var _a;
|
|
581
|
+
const { environmentId } = this;
|
|
582
|
+
if (!this.getEvmGasSponsorshipEnabled() || !environmentId) {
|
|
583
|
+
return false;
|
|
584
|
+
}
|
|
585
|
+
const sdkApi = (_a = this.getSponsorshipSdkApi) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
586
|
+
if (!sdkApi) {
|
|
587
|
+
return false;
|
|
588
|
+
}
|
|
589
|
+
const evmNetwork = this.currentEvmNetwork();
|
|
590
|
+
if (!evmNetwork) {
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
593
|
+
try {
|
|
594
|
+
yield ethereumGaslessCore.getAvailableEvmGaslessRelayer({ chainId: Number(evmNetwork.chainId) }, { environmentId, sdkApi });
|
|
595
|
+
return true;
|
|
596
|
+
}
|
|
597
|
+
catch (_b) {
|
|
598
|
+
logger.debug('No EVM gasless relayer available for chain');
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
sendSponsoredUiTransaction(_a) {
|
|
604
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ accountAddress, sponsoredChainId, transaction, }) {
|
|
605
|
+
var _b, _c;
|
|
606
|
+
const sdkApi = (_b = this.getSponsorshipSdkApi) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
607
|
+
if (!sdkApi || !this.environmentId) {
|
|
608
|
+
throw new utils.DynamicError('Gas sponsorship is not configured', 'gas_sponsorship_not_configured');
|
|
609
|
+
}
|
|
610
|
+
const evmNetwork = this.currentEvmNetwork();
|
|
611
|
+
if (!evmNetwork) {
|
|
612
|
+
throw new utils.DynamicError('EVM network not found', 'evm_network_not_found');
|
|
613
|
+
}
|
|
614
|
+
if (Number(evmNetwork.chainId) !== sponsoredChainId) {
|
|
615
|
+
throw new utils.DynamicError('Gas sponsorship was not verified for the active chain', 'gas_sponsorship_chain_mismatch');
|
|
616
|
+
}
|
|
617
|
+
const publicClient = yield this.getPublicClient();
|
|
618
|
+
if (!publicClient) {
|
|
619
|
+
throw new utils.DynamicError('No public client available', 'no_public_client_available');
|
|
620
|
+
}
|
|
621
|
+
const accountSource = yield this.getViemAccountCustomSource({
|
|
622
|
+
accountAddress,
|
|
623
|
+
});
|
|
624
|
+
const sponsorshipWalletClient = viem.createWalletClient({
|
|
625
|
+
account: accounts.toAccount(withBigintSafeSignTypedData.withBigintSafeSignTypedData(accountSource)),
|
|
626
|
+
chain: ethereumCore.getOrMapViemChain(evmNetwork),
|
|
627
|
+
transport: viem.http(this.getRpcUrl(evmNetwork), this.providersConfig.httpTransportConfig),
|
|
628
|
+
});
|
|
629
|
+
const calls = toSponsoredTransactionCalls.toSponsoredTransactionCalls({
|
|
630
|
+
nonNativeAddress: transaction.nonNativeAddress,
|
|
631
|
+
nonNativeValue: transaction.nonNativeValue,
|
|
632
|
+
to: (_c = transaction.to) !== null && _c !== void 0 ? _c : undefined,
|
|
633
|
+
value: transaction.value,
|
|
634
|
+
});
|
|
635
|
+
const { transactionHash } = yield ethereumGaslessCore.sendSponsoredTransaction({
|
|
636
|
+
autoDelegate: true,
|
|
637
|
+
calls,
|
|
638
|
+
}, {
|
|
639
|
+
chainId: Number(evmNetwork.chainId),
|
|
640
|
+
delegationRegistry: this.delegation7702Registry,
|
|
641
|
+
environmentId: this.environmentId,
|
|
642
|
+
publicClient: publicClient,
|
|
643
|
+
sdkApi,
|
|
644
|
+
walletClient: sponsorshipWalletClient,
|
|
645
|
+
});
|
|
646
|
+
return transactionHash;
|
|
647
|
+
});
|
|
648
|
+
}
|
|
558
649
|
createUiTransaction(from) {
|
|
559
650
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
651
|
+
var _a;
|
|
560
652
|
yield this.validateActiveWallet(from);
|
|
561
653
|
const walletClient = this.getWalletClient();
|
|
562
654
|
const publicClient = yield this.getPublicClient();
|
|
@@ -566,9 +658,19 @@ class DynamicWaasEVMConnector extends waas.withDynamicWaas(ethereumCore.Ethereum
|
|
|
566
658
|
if (!publicClient || !walletClient) {
|
|
567
659
|
throw new utils.DynamicError('No public client available', 'no_public_client_available');
|
|
568
660
|
}
|
|
661
|
+
const isGasSponsored = yield this.isGasSponsorshipAvailable();
|
|
662
|
+
const sponsoredChainId = Number((_a = this.currentEvmNetwork()) === null || _a === void 0 ? void 0 : _a.chainId);
|
|
569
663
|
return new ethereumCore.ViemUiTransaction({
|
|
570
664
|
account: from,
|
|
665
|
+
isGasSponsored,
|
|
571
666
|
onSubmit: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
667
|
+
if (isGasSponsored) {
|
|
668
|
+
return this.sendSponsoredUiTransaction({
|
|
669
|
+
accountAddress: from,
|
|
670
|
+
sponsoredChainId,
|
|
671
|
+
transaction,
|
|
672
|
+
});
|
|
673
|
+
}
|
|
572
674
|
// Non native token
|
|
573
675
|
if (transaction.nonNativeAddress) {
|
|
574
676
|
return walletClient.writeContract({
|
|
@@ -2,7 +2,7 @@ import { Account, CustomSource, Hex, Transport, Chain as ViemChain, WalletClient
|
|
|
2
2
|
import { LocalAccount, SignAuthorizationParameters, SignAuthorizationReturnType } from 'viem/accounts';
|
|
3
3
|
import { EthereumWalletConnector, EthereumWalletConnectorOpts, SwitchNetworkOps } from '@dynamic-labs/ethereum-core';
|
|
4
4
|
import { Logger } from '@dynamic-labs/logger';
|
|
5
|
-
import { JwtVerifiedCredential, MFAAction, SignMessageContext, TokenScope } from '@dynamic-labs/sdk-api-core';
|
|
5
|
+
import { JwtVerifiedCredential, MFAAction, SDKApi, SignMessageContext, TokenScope } from '@dynamic-labs/sdk-api-core';
|
|
6
6
|
import { IUITransaction } from '@dynamic-labs/types';
|
|
7
7
|
import { WaasExportHandler } from '@dynamic-labs/waas';
|
|
8
8
|
import { IDynamicWaasConnector } from '@dynamic-labs/wallet-connector-core';
|
|
@@ -218,6 +218,9 @@ export declare class DynamicWaasEVMConnector extends DynamicWaasEVMConnector_bas
|
|
|
218
218
|
logger: Logger;
|
|
219
219
|
overrideKey: string;
|
|
220
220
|
isEmbeddedWallet: boolean;
|
|
221
|
+
private getEvmGasSponsorshipEnabled;
|
|
222
|
+
private getSponsorshipSdkApi;
|
|
223
|
+
private delegation7702Registry;
|
|
221
224
|
/**
|
|
222
225
|
* Chain IDs that have dedicated connectors and should not be handled by this connector.
|
|
223
226
|
* Networks with these chain IDs are filtered from network lists and rejected during switching.
|
|
@@ -305,6 +308,22 @@ export declare class DynamicWaasEVMConnector extends DynamicWaasEVMConnector_bas
|
|
|
305
308
|
existingPassword: string;
|
|
306
309
|
newPassword: string;
|
|
307
310
|
}): Promise<void>;
|
|
311
|
+
/**
|
|
312
|
+
* Registers the project's EVM gas sponsorship configuration so the send flow
|
|
313
|
+
* can route transactions through the sponsored relay instead of paying fees
|
|
314
|
+
* from the wallet's native balance.
|
|
315
|
+
*/
|
|
316
|
+
setEvmGasSponsorshipConfig({ getEnabled, getSdkApi, }: {
|
|
317
|
+
getEnabled: () => boolean;
|
|
318
|
+
getSdkApi: () => SDKApi;
|
|
319
|
+
}): void;
|
|
320
|
+
/**
|
|
321
|
+
* Sponsorship requires the project setting, an SDK API client and a relayer
|
|
322
|
+
* funded for the wallet's current chain. Anything missing means the send flow
|
|
323
|
+
* pays fees from the wallet's native balance.
|
|
324
|
+
*/
|
|
325
|
+
private isGasSponsorshipAvailable;
|
|
326
|
+
private sendSponsoredUiTransaction;
|
|
308
327
|
createUiTransaction(from: string): Promise<IUITransaction>;
|
|
309
328
|
getConnectedAccounts(): Promise<string[]>;
|
|
310
329
|
getAddress(): Promise<string>;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
-
import { http, serializeTransaction, erc20Abi, parseSignature } from 'viem';
|
|
3
|
+
import { http, serializeTransaction, createWalletClient, erc20Abi, parseSignature } from 'viem';
|
|
4
4
|
import { toAccount } from 'viem/accounts';
|
|
5
5
|
import { hashAuthorization } from 'viem/utils';
|
|
6
6
|
import { EthereumWalletConnector, createWalletClientWithUiConfirmation, getOrMapViemChain, ViemUiTransaction } from '@dynamic-labs/ethereum-core';
|
|
7
|
+
import { create7702DelegationRegistry, getAvailableEvmGaslessRelayer, sendSponsoredTransaction } from '@dynamic-labs/ethereum-gasless-core';
|
|
7
8
|
import { Logger } from '@dynamic-labs/logger';
|
|
8
9
|
import { MFAAction, TokenScope } from '@dynamic-labs/sdk-api-core';
|
|
9
10
|
import { DynamicError } from '@dynamic-labs/utils';
|
|
10
11
|
import { withDynamicWaas, WaasExportHandler } from '@dynamic-labs/waas';
|
|
11
12
|
import { isSameAddress } from '@dynamic-labs/wallet-connector-core';
|
|
13
|
+
import { toSponsoredTransactionCalls } from './gasless/toSponsoredTransactionCalls/toSponsoredTransactionCalls.js';
|
|
14
|
+
import { withBigintSafeSignTypedData } from './gasless/withBigintSafeSignTypedData/withBigintSafeSignTypedData.js';
|
|
12
15
|
|
|
13
16
|
const logger = new Logger('DynamicWaasConnector');
|
|
14
17
|
class DynamicWaasEVMConnector extends withDynamicWaas(EthereumWalletConnector) {
|
|
@@ -39,6 +42,9 @@ class DynamicWaasEVMConnector extends withDynamicWaas(EthereumWalletConnector) {
|
|
|
39
42
|
this.logger = logger;
|
|
40
43
|
this.overrideKey = 'dynamicwaas';
|
|
41
44
|
this.isEmbeddedWallet = true;
|
|
45
|
+
this.getEvmGasSponsorshipEnabled = () => false;
|
|
46
|
+
this.getSponsorshipSdkApi = undefined;
|
|
47
|
+
this.delegation7702Registry = create7702DelegationRegistry();
|
|
42
48
|
/**
|
|
43
49
|
* Chain IDs that have dedicated connectors and should not be handled by this connector.
|
|
44
50
|
* Networks with these chain IDs are filtered from network lists and rejected during switching.
|
|
@@ -551,8 +557,94 @@ class DynamicWaasEVMConnector extends withDynamicWaas(EthereumWalletConnector) {
|
|
|
551
557
|
});
|
|
552
558
|
});
|
|
553
559
|
}
|
|
560
|
+
/**
|
|
561
|
+
* Registers the project's EVM gas sponsorship configuration so the send flow
|
|
562
|
+
* can route transactions through the sponsored relay instead of paying fees
|
|
563
|
+
* from the wallet's native balance.
|
|
564
|
+
*/
|
|
565
|
+
setEvmGasSponsorshipConfig({ getEnabled, getSdkApi, }) {
|
|
566
|
+
this.getEvmGasSponsorshipEnabled = getEnabled;
|
|
567
|
+
this.getSponsorshipSdkApi = getSdkApi;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Sponsorship requires the project setting, an SDK API client and a relayer
|
|
571
|
+
* funded for the wallet's current chain. Anything missing means the send flow
|
|
572
|
+
* pays fees from the wallet's native balance.
|
|
573
|
+
*/
|
|
574
|
+
isGasSponsorshipAvailable() {
|
|
575
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
576
|
+
var _a;
|
|
577
|
+
const { environmentId } = this;
|
|
578
|
+
if (!this.getEvmGasSponsorshipEnabled() || !environmentId) {
|
|
579
|
+
return false;
|
|
580
|
+
}
|
|
581
|
+
const sdkApi = (_a = this.getSponsorshipSdkApi) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
582
|
+
if (!sdkApi) {
|
|
583
|
+
return false;
|
|
584
|
+
}
|
|
585
|
+
const evmNetwork = this.currentEvmNetwork();
|
|
586
|
+
if (!evmNetwork) {
|
|
587
|
+
return false;
|
|
588
|
+
}
|
|
589
|
+
try {
|
|
590
|
+
yield getAvailableEvmGaslessRelayer({ chainId: Number(evmNetwork.chainId) }, { environmentId, sdkApi });
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
catch (_b) {
|
|
594
|
+
logger.debug('No EVM gasless relayer available for chain');
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
sendSponsoredUiTransaction(_a) {
|
|
600
|
+
return __awaiter(this, arguments, void 0, function* ({ accountAddress, sponsoredChainId, transaction, }) {
|
|
601
|
+
var _b, _c;
|
|
602
|
+
const sdkApi = (_b = this.getSponsorshipSdkApi) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
603
|
+
if (!sdkApi || !this.environmentId) {
|
|
604
|
+
throw new DynamicError('Gas sponsorship is not configured', 'gas_sponsorship_not_configured');
|
|
605
|
+
}
|
|
606
|
+
const evmNetwork = this.currentEvmNetwork();
|
|
607
|
+
if (!evmNetwork) {
|
|
608
|
+
throw new DynamicError('EVM network not found', 'evm_network_not_found');
|
|
609
|
+
}
|
|
610
|
+
if (Number(evmNetwork.chainId) !== sponsoredChainId) {
|
|
611
|
+
throw new DynamicError('Gas sponsorship was not verified for the active chain', 'gas_sponsorship_chain_mismatch');
|
|
612
|
+
}
|
|
613
|
+
const publicClient = yield this.getPublicClient();
|
|
614
|
+
if (!publicClient) {
|
|
615
|
+
throw new DynamicError('No public client available', 'no_public_client_available');
|
|
616
|
+
}
|
|
617
|
+
const accountSource = yield this.getViemAccountCustomSource({
|
|
618
|
+
accountAddress,
|
|
619
|
+
});
|
|
620
|
+
const sponsorshipWalletClient = createWalletClient({
|
|
621
|
+
account: toAccount(withBigintSafeSignTypedData(accountSource)),
|
|
622
|
+
chain: getOrMapViemChain(evmNetwork),
|
|
623
|
+
transport: http(this.getRpcUrl(evmNetwork), this.providersConfig.httpTransportConfig),
|
|
624
|
+
});
|
|
625
|
+
const calls = toSponsoredTransactionCalls({
|
|
626
|
+
nonNativeAddress: transaction.nonNativeAddress,
|
|
627
|
+
nonNativeValue: transaction.nonNativeValue,
|
|
628
|
+
to: (_c = transaction.to) !== null && _c !== void 0 ? _c : undefined,
|
|
629
|
+
value: transaction.value,
|
|
630
|
+
});
|
|
631
|
+
const { transactionHash } = yield sendSponsoredTransaction({
|
|
632
|
+
autoDelegate: true,
|
|
633
|
+
calls,
|
|
634
|
+
}, {
|
|
635
|
+
chainId: Number(evmNetwork.chainId),
|
|
636
|
+
delegationRegistry: this.delegation7702Registry,
|
|
637
|
+
environmentId: this.environmentId,
|
|
638
|
+
publicClient: publicClient,
|
|
639
|
+
sdkApi,
|
|
640
|
+
walletClient: sponsorshipWalletClient,
|
|
641
|
+
});
|
|
642
|
+
return transactionHash;
|
|
643
|
+
});
|
|
644
|
+
}
|
|
554
645
|
createUiTransaction(from) {
|
|
555
646
|
return __awaiter(this, void 0, void 0, function* () {
|
|
647
|
+
var _a;
|
|
556
648
|
yield this.validateActiveWallet(from);
|
|
557
649
|
const walletClient = this.getWalletClient();
|
|
558
650
|
const publicClient = yield this.getPublicClient();
|
|
@@ -562,9 +654,19 @@ class DynamicWaasEVMConnector extends withDynamicWaas(EthereumWalletConnector) {
|
|
|
562
654
|
if (!publicClient || !walletClient) {
|
|
563
655
|
throw new DynamicError('No public client available', 'no_public_client_available');
|
|
564
656
|
}
|
|
657
|
+
const isGasSponsored = yield this.isGasSponsorshipAvailable();
|
|
658
|
+
const sponsoredChainId = Number((_a = this.currentEvmNetwork()) === null || _a === void 0 ? void 0 : _a.chainId);
|
|
565
659
|
return new ViemUiTransaction({
|
|
566
660
|
account: from,
|
|
661
|
+
isGasSponsored,
|
|
567
662
|
onSubmit: (transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
663
|
+
if (isGasSponsored) {
|
|
664
|
+
return this.sendSponsoredUiTransaction({
|
|
665
|
+
accountAddress: from,
|
|
666
|
+
sponsoredChainId,
|
|
667
|
+
transaction,
|
|
668
|
+
});
|
|
669
|
+
}
|
|
568
670
|
// Non native token
|
|
569
671
|
if (transaction.nonNativeAddress) {
|
|
570
672
|
return walletClient.writeContract({
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var viem = require('viem');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Maps a UI transaction to the batch of calls the sponsored-transaction
|
|
11
|
+
* delegate executes on behalf of the wallet.
|
|
12
|
+
*/
|
|
13
|
+
const toSponsoredTransactionCalls = ({ to, value, nonNativeAddress, nonNativeValue, }) => {
|
|
14
|
+
if (!to) {
|
|
15
|
+
throw new utils.DynamicError('Missing recipient, cannot sponsor transaction', 'sponsorship_missing_recipient');
|
|
16
|
+
}
|
|
17
|
+
if (nonNativeAddress) {
|
|
18
|
+
return [
|
|
19
|
+
{
|
|
20
|
+
data: viem.encodeFunctionData({
|
|
21
|
+
abi: viem.erc20Abi,
|
|
22
|
+
args: [to, nonNativeValue !== null && nonNativeValue !== void 0 ? nonNativeValue : BigInt(0)],
|
|
23
|
+
functionName: 'transfer',
|
|
24
|
+
}),
|
|
25
|
+
target: nonNativeAddress,
|
|
26
|
+
value: BigInt(0),
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
data: '0x',
|
|
33
|
+
target: to,
|
|
34
|
+
value: value !== null && value !== void 0 ? value : BigInt(0),
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.toSponsoredTransactionCalls = toSponsoredTransactionCalls;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SponsoredTransactionCall } from '@dynamic-labs/ethereum-gasless-core';
|
|
2
|
+
type ToSponsoredTransactionCallsParams = {
|
|
3
|
+
to: string | undefined;
|
|
4
|
+
value: bigint | undefined;
|
|
5
|
+
nonNativeAddress?: string;
|
|
6
|
+
nonNativeValue?: bigint;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Maps a UI transaction to the batch of calls the sponsored-transaction
|
|
10
|
+
* delegate executes on behalf of the wallet.
|
|
11
|
+
*/
|
|
12
|
+
export declare const toSponsoredTransactionCalls: ({ to, value, nonNativeAddress, nonNativeValue, }: ToSponsoredTransactionCallsParams) => SponsoredTransactionCall[];
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { encodeFunctionData, erc20Abi } from 'viem';
|
|
3
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Maps a UI transaction to the batch of calls the sponsored-transaction
|
|
7
|
+
* delegate executes on behalf of the wallet.
|
|
8
|
+
*/
|
|
9
|
+
const toSponsoredTransactionCalls = ({ to, value, nonNativeAddress, nonNativeValue, }) => {
|
|
10
|
+
if (!to) {
|
|
11
|
+
throw new DynamicError('Missing recipient, cannot sponsor transaction', 'sponsorship_missing_recipient');
|
|
12
|
+
}
|
|
13
|
+
if (nonNativeAddress) {
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
data: encodeFunctionData({
|
|
17
|
+
abi: erc20Abi,
|
|
18
|
+
args: [to, nonNativeValue !== null && nonNativeValue !== void 0 ? nonNativeValue : BigInt(0)],
|
|
19
|
+
functionName: 'transfer',
|
|
20
|
+
}),
|
|
21
|
+
target: nonNativeAddress,
|
|
22
|
+
value: BigInt(0),
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
data: '0x',
|
|
29
|
+
target: to,
|
|
30
|
+
value: value !== null && value !== void 0 ? value : BigInt(0),
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { toSponsoredTransactionCalls };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var utils = require('@dynamic-labs/utils');
|
|
7
|
+
|
|
8
|
+
const toJsonSafeValue = (value) => {
|
|
9
|
+
if (typeof value === 'bigint') {
|
|
10
|
+
return value.toString();
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
return value.map(toJsonSafeValue);
|
|
14
|
+
}
|
|
15
|
+
if (value !== null && typeof value === 'object') {
|
|
16
|
+
const entries = Object.entries(value).map(([key, nestedValue]) => [
|
|
17
|
+
key,
|
|
18
|
+
toJsonSafeValue(nestedValue),
|
|
19
|
+
]);
|
|
20
|
+
return Object.fromEntries(entries);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Wraps a viem custom source so typed-data payloads are stripped of bigints
|
|
26
|
+
* before signing. The WaaS signing transport serializes messages as JSON and
|
|
27
|
+
* rejects bigint values, which EIP-712 sponsored-transaction intents contain.
|
|
28
|
+
*/
|
|
29
|
+
const withBigintSafeSignTypedData = (source) => {
|
|
30
|
+
const { signTypedData } = source;
|
|
31
|
+
if (!signTypedData) {
|
|
32
|
+
throw new utils.DynamicError('Custom source does not support signTypedData', 'sign_typed_data_not_supported');
|
|
33
|
+
}
|
|
34
|
+
return Object.assign(Object.assign({}, source), { signTypedData: (typedData) => signTypedData(toJsonSafeValue(typedData)) });
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.withBigintSafeSignTypedData = withBigintSafeSignTypedData;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CustomSource } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a viem custom source so typed-data payloads are stripped of bigints
|
|
4
|
+
* before signing. The WaaS signing transport serializes messages as JSON and
|
|
5
|
+
* rejects bigint values, which EIP-712 sponsored-transaction intents contain.
|
|
6
|
+
*/
|
|
7
|
+
export declare const withBigintSafeSignTypedData: (source: CustomSource) => CustomSource;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
3
|
+
|
|
4
|
+
const toJsonSafeValue = (value) => {
|
|
5
|
+
if (typeof value === 'bigint') {
|
|
6
|
+
return value.toString();
|
|
7
|
+
}
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
return value.map(toJsonSafeValue);
|
|
10
|
+
}
|
|
11
|
+
if (value !== null && typeof value === 'object') {
|
|
12
|
+
const entries = Object.entries(value).map(([key, nestedValue]) => [
|
|
13
|
+
key,
|
|
14
|
+
toJsonSafeValue(nestedValue),
|
|
15
|
+
]);
|
|
16
|
+
return Object.fromEntries(entries);
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Wraps a viem custom source so typed-data payloads are stripped of bigints
|
|
22
|
+
* before signing. The WaaS signing transport serializes messages as JSON and
|
|
23
|
+
* rejects bigint values, which EIP-712 sponsored-transaction intents contain.
|
|
24
|
+
*/
|
|
25
|
+
const withBigintSafeSignTypedData = (source) => {
|
|
26
|
+
const { signTypedData } = source;
|
|
27
|
+
if (!signTypedData) {
|
|
28
|
+
throw new DynamicError('Custom source does not support signTypedData', 'sign_typed_data_not_supported');
|
|
29
|
+
}
|
|
30
|
+
return Object.assign(Object.assign({}, source), { signTypedData: (typedData) => signTypedData(toJsonSafeValue(typedData)) });
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { withBigintSafeSignTypedData };
|