@dynamic-labs-sdk/evm 1.17.1 → 1.19.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/dist/{addEIP6963Extension-Nz8vTj11.esm.js → addEIP6963Extension-BjucaEgu.esm.js} +3 -3
- package/dist/{addEIP6963Extension-Nz8vTj11.esm.js.map → addEIP6963Extension-BjucaEgu.esm.js.map} +1 -1
- package/dist/{addEIP6963Extension-5tjpOHPi.cjs → addEIP6963Extension-ButCTeIE.cjs} +3 -3
- package/dist/{addEIP6963Extension-5tjpOHPi.cjs.map → addEIP6963Extension-ButCTeIE.cjs.map} +1 -1
- package/dist/addEvmExtension/addEvmExtension.d.ts +10 -1
- package/dist/addEvmExtension/addEvmExtension.d.ts.map +1 -1
- package/dist/{addWaasEvmExtension-CexieTAz.cjs → addWaasEvmExtension-CIBwjebr.cjs} +3 -3
- package/dist/{addWaasEvmExtension-CexieTAz.cjs.map → addWaasEvmExtension-CIBwjebr.cjs.map} +1 -1
- package/dist/{addWaasEvmExtension-JRgUEac2.esm.js → addWaasEvmExtension-D47UG4zQ.esm.js} +3 -3
- package/dist/{addWaasEvmExtension-JRgUEac2.esm.js.map → addWaasEvmExtension-D47UG4zQ.esm.js.map} +1 -1
- package/dist/{addWaasEvmExtension-CJD8D1Sf.native.esm.js → addWaasEvmExtension-V3vwSfx0.native.esm.js} +2 -2
- package/dist/{addWaasEvmExtension-CJD8D1Sf.native.esm.js.map → addWaasEvmExtension-V3vwSfx0.native.esm.js.map} +1 -1
- package/dist/baseAccount.cjs +4 -4
- package/dist/baseAccount.esm.js +4 -4
- package/dist/baseAccount.native.esm.js +3 -3
- package/dist/{createWalletClientForWalletAccount-CRcI7k6-.esm.js → createWalletClientForWalletAccount-CSV76RdP.esm.js} +2 -2
- package/dist/{createWalletClientForWalletAccount-CRcI7k6-.esm.js.map → createWalletClientForWalletAccount-CSV76RdP.esm.js.map} +1 -1
- package/dist/{createWalletClientForWalletAccount-Cb2uMZxJ.cjs → createWalletClientForWalletAccount-DZ1SUxot.cjs} +2 -2
- package/dist/{createWalletClientForWalletAccount-Cb2uMZxJ.cjs.map → createWalletClientForWalletAccount-DZ1SUxot.cjs.map} +1 -1
- package/dist/{createWalletProviderFromEIP1193Provider-DIplPkf4.cjs → createWalletProviderFromEIP1193Provider-BfIxWk-1.cjs} +2 -2
- package/dist/{createWalletProviderFromEIP1193Provider-DIplPkf4.cjs.map → createWalletProviderFromEIP1193Provider-BfIxWk-1.cjs.map} +1 -1
- package/dist/{createWalletProviderFromEIP1193Provider-D4aKomjq.native.esm.js → createWalletProviderFromEIP1193Provider-BoNh5_kO.native.esm.js} +2 -2
- package/dist/{createWalletProviderFromEIP1193Provider-D4aKomjq.native.esm.js.map → createWalletProviderFromEIP1193Provider-BoNh5_kO.native.esm.js.map} +1 -1
- package/dist/{createWalletProviderFromEIP1193Provider-BQ0d8crZ.esm.js → createWalletProviderFromEIP1193Provider-Dhruqg0P.esm.js} +2 -2
- package/dist/{createWalletProviderFromEIP1193Provider-BQ0d8crZ.esm.js.map → createWalletProviderFromEIP1193Provider-Dhruqg0P.esm.js.map} +1 -1
- package/dist/eip6963.cjs +5 -5
- package/dist/eip6963.esm.js +5 -5
- package/dist/eip6963.native.esm.js +1 -1
- package/dist/{evmTransferAmount-B2lXHyW3.native.esm.js → evmTransferAmount-D9Sygfbl.native.esm.js} +87 -2
- package/dist/evmTransferAmount-D9Sygfbl.native.esm.js.map +1 -0
- package/dist/{evmTransferAmount-C1msMTNe.cjs → evmTransferAmount-bPkkINFr.cjs} +89 -4
- package/dist/evmTransferAmount-bPkkINFr.cjs.map +1 -0
- package/dist/{evmTransferAmount-ebnRuHex.esm.js → evmTransferAmount-zNYlT8-b.esm.js} +89 -4
- package/dist/evmTransferAmount-zNYlT8-b.esm.js.map +1 -0
- package/dist/gasless/activate7702Delegation/activate7702Delegation.d.ts +9 -0
- package/dist/gasless/activate7702Delegation/activate7702Delegation.d.ts.map +1 -1
- package/dist/gasless/getEVMSponsoredTransactionStatus/getEVMSponsoredTransactionStatus.d.ts +10 -0
- package/dist/gasless/getEVMSponsoredTransactionStatus/getEVMSponsoredTransactionStatus.d.ts.map +1 -1
- package/dist/gasless/is7702DelegationActive/is7702DelegationActive.d.ts +11 -1
- package/dist/gasless/is7702DelegationActive/is7702DelegationActive.d.ts.map +1 -1
- package/dist/gasless/isEvmGasSponsorshipEnabled/isEvmGasSponsorshipEnabled.d.ts +9 -0
- package/dist/gasless/isEvmGasSponsorshipEnabled/isEvmGasSponsorshipEnabled.d.ts.map +1 -1
- package/dist/gasless/relaySponsoredTransaction/relaySponsoredTransaction.d.ts +11 -0
- package/dist/gasless/relaySponsoredTransaction/relaySponsoredTransaction.d.ts.map +1 -1
- package/dist/gasless/sendSponsoredTransaction/sendSponsoredTransaction.d.ts +10 -0
- package/dist/gasless/sendSponsoredTransaction/sendSponsoredTransaction.d.ts.map +1 -1
- package/dist/gasless/sign7702Authorization/sign7702Authorization.d.ts +8 -0
- package/dist/gasless/sign7702Authorization/sign7702Authorization.d.ts.map +1 -1
- package/dist/gasless/signSponsoredTransaction/signSponsoredTransaction.d.ts +11 -0
- package/dist/gasless/signSponsoredTransaction/signSponsoredTransaction.d.ts.map +1 -1
- package/dist/gasless/waitForSponsoredTransaction/waitForSponsoredTransaction.d.ts +8 -0
- package/dist/gasless/waitForSponsoredTransaction/waitForSponsoredTransaction.d.ts.map +1 -1
- package/dist/index.cjs +55 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +55 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.native.esm.js +52 -3
- package/dist/index.native.esm.js.map +1 -1
- package/dist/isEvmNetworkProvider/isEvmNetworkProvider.d.ts +10 -1
- package/dist/isEvmNetworkProvider/isEvmNetworkProvider.d.ts.map +1 -1
- package/dist/{mapNetworkDataToViemChain-6r3qQgSG.esm.js → mapNetworkDataToViemChain-DXy4yka7.esm.js} +2 -2
- package/dist/{mapNetworkDataToViemChain-6r3qQgSG.esm.js.map → mapNetworkDataToViemChain-DXy4yka7.esm.js.map} +1 -1
- package/dist/{mapNetworkDataToViemChain-DHni6ErD.cjs → mapNetworkDataToViemChain-y9sq6Oak.cjs} +2 -2
- package/dist/{mapNetworkDataToViemChain-DHni6ErD.cjs.map → mapNetworkDataToViemChain-y9sq6Oak.cjs.map} +1 -1
- package/dist/metamask.cjs +4 -4
- package/dist/metamask.esm.js +4 -4
- package/dist/metamask.native.esm.js +3 -3
- package/dist/{package-Dt8Q4Vtr.native.esm.js → package-YT_Fw3US.native.esm.js} +2 -2
- package/dist/package-YT_Fw3US.native.esm.js.map +1 -0
- package/dist/simulateEvmTransaction/simulateEvmTransaction.d.ts +12 -1
- package/dist/simulateEvmTransaction/simulateEvmTransaction.d.ts.map +1 -1
- package/dist/tempo.cjs +1 -1
- package/dist/tempo.esm.js +1 -1
- package/dist/tempo.native.esm.js +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/utils/calculateEvmTransactionFee/calculateEvmTransactionFee.d.ts +12 -1
- package/dist/utils/calculateEvmTransactionFee/calculateEvmTransactionFee.d.ts.map +1 -1
- package/dist/utils/isEvmWalletAccount/isEvmWalletAccount.d.ts +9 -1
- package/dist/utils/isEvmWalletAccount/isEvmWalletAccount.d.ts.map +1 -1
- package/dist/viem.cjs +2 -2
- package/dist/viem.esm.js +2 -2
- package/dist/viem.native.esm.js +1 -1
- package/dist/waas.cjs +4 -4
- package/dist/waas.esm.js +4 -4
- package/dist/waas.native.esm.js +3 -3
- package/dist/walletConnect.cjs +3 -3
- package/dist/walletConnect.esm.js +3 -3
- package/dist/walletConnect.native.esm.js +2 -2
- package/dist/windowInjected.cjs +4 -4
- package/dist/windowInjected.esm.js +4 -4
- package/dist/windowInjected.native.esm.js +3 -3
- package/package.json +6 -6
- package/dist/evmTransferAmount-B2lXHyW3.native.esm.js.map +0 -1
- package/dist/evmTransferAmount-C1msMTNe.cjs.map +0 -1
- package/dist/evmTransferAmount-ebnRuHex.esm.js.map +0 -1
- package/dist/package-Dt8Q4Vtr.native.esm.js.map +0 -1
|
@@ -7,10 +7,18 @@ type WaitForSponsoredTransactionParams = {
|
|
|
7
7
|
* Polls `getEVMSponsoredTransactionStatus` until the relay reports the
|
|
8
8
|
* transaction has been included on-chain, then returns the transaction hash.
|
|
9
9
|
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const { requestId } = await relaySponsoredTransaction({ signedTransaction });
|
|
13
|
+
* const { transactionHash } = await waitForSponsoredTransaction({ requestId });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
10
16
|
* @param params.requestId - The request ID returned when the transaction was relayed.
|
|
11
17
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
12
18
|
* @returns An object containing the on-chain transaction hash.
|
|
13
19
|
* @throws {SponsorTransactionError} If the relay returns a terminal failure or polling times out.
|
|
20
|
+
* @see relaySponsoredTransaction
|
|
21
|
+
* @see getEVMSponsoredTransactionStatus
|
|
14
22
|
* @notInstrumented
|
|
15
23
|
*/
|
|
16
24
|
export declare const waitForSponsoredTransaction: ({ requestId }: WaitForSponsoredTransactionParams, client?: import("@dynamic-labs-sdk/client").DynamicClient) => Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForSponsoredTransaction.d.ts","sourceRoot":"","sources":["../../../src/gasless/waitForSponsoredTransaction/waitForSponsoredTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAchC,KAAK,iCAAiC,GAAG;IACvC,2FAA2F;IAC3F,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"waitForSponsoredTransaction.d.ts","sourceRoot":"","sources":["../../../src/gasless/waitForSponsoredTransaction/waitForSponsoredTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAchC,KAAK,iCAAiC,GAAG;IACvC,2FAA2F;IAC3F,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,2BAA2B,kBACvB,iCAAiC,gEAE/C,OAAO,CAAC;IAAE,eAAe,EAAE,GAAG,CAAA;CAAE,CA0BlC,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const require_mapNetworkDataToViemChain = require('./mapNetworkDataToViemChain-
|
|
2
|
-
const require_evmTransferAmount = require('./evmTransferAmount-
|
|
3
|
-
const require_createWalletClientForWalletAccount = require('./createWalletClientForWalletAccount-
|
|
4
|
-
require('./createWalletProviderFromEIP1193Provider-
|
|
5
|
-
const require_addEIP6963Extension = require('./addEIP6963Extension-
|
|
6
|
-
const require_addWaasEvmExtension = require('./addWaasEvmExtension-
|
|
1
|
+
const require_mapNetworkDataToViemChain = require('./mapNetworkDataToViemChain-y9sq6Oak.cjs');
|
|
2
|
+
const require_evmTransferAmount = require('./evmTransferAmount-bPkkINFr.cjs');
|
|
3
|
+
const require_createWalletClientForWalletAccount = require('./createWalletClientForWalletAccount-DZ1SUxot.cjs');
|
|
4
|
+
require('./createWalletProviderFromEIP1193Provider-BfIxWk-1.cjs');
|
|
5
|
+
const require_addEIP6963Extension = require('./addEIP6963Extension-ButCTeIE.cjs');
|
|
6
|
+
const require_addWaasEvmExtension = require('./addWaasEvmExtension-CIBwjebr.cjs');
|
|
7
7
|
let _dynamic_labs_sdk_assert_package_version = require("@dynamic-labs-sdk/assert-package-version");
|
|
8
8
|
let _dynamic_labs_sdk_client = require("@dynamic-labs-sdk/client");
|
|
9
9
|
let _dynamic_labs_sdk_client_core = require("@dynamic-labs-sdk/client/core");
|
|
@@ -18,11 +18,20 @@ let viem = require("viem");
|
|
|
18
18
|
* subsequent sponsored transactions no longer need to include the
|
|
19
19
|
* authorization.
|
|
20
20
|
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const { transactionHash } = await activate7702Delegation({
|
|
24
|
+
* walletAccount: evmAccount,
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
21
28
|
* @param params.walletAccount - The EVM wallet account to activate delegation for.
|
|
22
29
|
* @param [params.authorization] - Pre-signed authorization. If omitted, signs one automatically.
|
|
23
30
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
24
31
|
* @returns An object containing the on-chain transaction hash.
|
|
25
32
|
* @throws {SponsorTransactionError} If the relay returns a terminal failure or polling times out.
|
|
33
|
+
* @see is7702DelegationActive
|
|
34
|
+
* @see sign7702Authorization
|
|
26
35
|
* @notInstrumented
|
|
27
36
|
*/
|
|
28
37
|
const activate7702Delegation = async ({ walletAccount, authorization }, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => require_evmTransferAmount.sendSponsoredTransaction({
|
|
@@ -40,7 +49,16 @@ const activate7702Delegation = async ({ walletAccount, authorization }, client =
|
|
|
40
49
|
* and the Dynamic WaaS EVM extension, enabling support for all EVM wallet types
|
|
41
50
|
* including standard wallets and embedded wallets managed by Dynamic's infrastructure.
|
|
42
51
|
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const client = createDynamicClient({ environmentId: 'env-123' });
|
|
55
|
+
* addEvmExtension(client);
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
43
58
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
59
|
+
* @returns void
|
|
60
|
+
* @see isEvmWalletAccount
|
|
61
|
+
* @see isEvmNetworkProvider
|
|
44
62
|
* @notInstrumented
|
|
45
63
|
*/
|
|
46
64
|
const addEvmExtension = (client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
|
|
@@ -67,8 +85,17 @@ var EvmGasSponsorshipNotEnabledError = class extends _dynamic_labs_sdk_client.Ba
|
|
|
67
85
|
/**
|
|
68
86
|
* Type guard function to check if a network provider is an EVM network provider.
|
|
69
87
|
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* if (isEvmNetworkProvider(networkProvider)) {
|
|
91
|
+
* const publicClient = networkProvider.getPublicClient();
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
70
95
|
* @param networkProvider - The network provider to check.
|
|
71
96
|
* @returns True if the network provider is an EVM network provider, false otherwise.
|
|
97
|
+
* @see isEvmWalletAccount
|
|
98
|
+
* @see addEvmExtension
|
|
72
99
|
* @notInstrumented
|
|
73
100
|
*/
|
|
74
101
|
const isEvmNetworkProvider = (networkProvider) => networkProvider.chain === "EVM";
|
|
@@ -82,11 +109,22 @@ const isEvmNetworkProvider = (networkProvider) => networkProvider.chain === "EVM
|
|
|
82
109
|
* using either legacy gas pricing or EIP-1559 pricing. The fee is returned
|
|
83
110
|
* in both native units (wei) and human-readable format (ETH).
|
|
84
111
|
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const feeData = await calculateEvmTransactionFee({
|
|
115
|
+
* transaction: { from: '0x...', to: '0x...', value: 1000000000000000000n, networkId: '1' },
|
|
116
|
+
* networkData,
|
|
117
|
+
* nativeTokenPriceUsd: 3500,
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
85
121
|
* @param params.transaction - The transaction to estimate fees for.
|
|
86
122
|
* @param params.networkData - Network configuration for RPC connection.
|
|
87
123
|
* @param params.nativeTokenPriceUsd - Optional USD price of the native token for fee conversion.
|
|
88
124
|
* @returns Fee data including gas estimates and human-readable amounts.
|
|
89
125
|
* @throws {FeeEstimationFailedError} If gas estimation or fee retrieval fails.
|
|
126
|
+
* @see simulateEvmTransaction
|
|
127
|
+
* @see isEvmWalletAccount
|
|
90
128
|
* @notInstrumented
|
|
91
129
|
*/
|
|
92
130
|
const calculateEvmTransactionFee = async ({ transaction, networkData, nativeTokenPriceUsd }) => {
|
|
@@ -140,6 +178,15 @@ const calculateEvmTransactionFee = async ({ transaction, networkData, nativeToke
|
|
|
140
178
|
* The simulation shows what will happen when the transaction is executed without
|
|
141
179
|
* actually sending it to the blockchain.
|
|
142
180
|
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* const result = await simulateEvmTransaction({
|
|
184
|
+
* walletAccount: evmAccount,
|
|
185
|
+
* transaction: { from: '0x...', to: '0x...', value: 1000000000000000000n, networkId: '1' },
|
|
186
|
+
* includeFees: true,
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
143
190
|
* @param params.walletAccount - The EVM wallet account that will sign the transaction.
|
|
144
191
|
* @param params.transaction - The transaction to simulate, including network ID.
|
|
145
192
|
* @param params.includeFees - Whether to calculate transaction fees (default: false).
|
|
@@ -148,6 +195,8 @@ const calculateEvmTransactionFee = async ({ transaction, networkData, nativeToke
|
|
|
148
195
|
* @throws {InvalidParamError} If wallet account is not an EVM account or network ID is not configured.
|
|
149
196
|
* @throws {SimulationFailedError} If the simulation API call fails.
|
|
150
197
|
* @throws {FeeEstimationFailedError} If includeFees is true and fee calculation fails.
|
|
198
|
+
* @see calculateEvmTransactionFee
|
|
199
|
+
* @see isEvmWalletAccount
|
|
151
200
|
* @notInstrumented
|
|
152
201
|
*/
|
|
153
202
|
const simulateEvmTransaction = async ({ walletAccount, transaction, includeFees = false }, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["sendSponsoredTransaction","BaseError","createPublicClientFromNetworkData","maxFeePerGas: bigint | undefined","maxPriorityFeePerGas: bigint | undefined","gasPrice: bigint | undefined","nativeAmount: bigint","FeeEstimationFailedError","isEvmWalletAccount","InvalidParamError","feeData: EvmSimulationResult['feeData']","FeeEstimationFailedError","SimulationFailedError","packageName","packageVersion"],"sources":["../src/gasless/activate7702Delegation/activate7702Delegation.ts","../src/addEvmExtension/addEvmExtension.ts","../src/errors/EvmGasSponsorshipNotEnabledError/EvmGasSponsorshipNotEnabledError.ts","../src/isEvmNetworkProvider/isEvmNetworkProvider.ts","../src/utils/calculateEvmTransactionFee/calculateEvmTransactionFee.ts","../src/simulateEvmTransaction/simulateEvmTransaction.ts","../src/exports/index.ts"],"sourcesContent":["import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport type { Hex } from 'viem';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\n\nimport type { EvmWalletAccount } from '../../EvmWalletAccount.types';\nimport { sendSponsoredTransaction } from '../sendSponsoredTransaction';\n\ntype Activate7702DelegationParams = {\n /** Pre-signed EIP-7702 authorization. If not provided, one will be signed automatically. */\n authorization?: SignAuthorizationReturnType;\n /** The EVM wallet account to activate delegation for. */\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Activates EIP-7702 delegation for a wallet by sending a sponsored\n * transaction that only contains the 7702 authorization.\n *\n * After activation, the wallet's delegation is persisted on-chain and\n * subsequent sponsored transactions no longer need to include the\n * authorization.\n *\n * @param params.walletAccount - The EVM wallet account to activate delegation for.\n * @param [params.authorization] - Pre-signed authorization. If omitted, signs one automatically.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns An object containing the on-chain transaction hash.\n * @throws {SponsorTransactionError} If the relay returns a terminal failure or polling times out.\n * @notInstrumented\n */\nexport const activate7702Delegation = async (\n { walletAccount, authorization }: Activate7702DelegationParams,\n client = getDefaultClient()\n): Promise<{ transactionHash: Hex }> =>\n sendSponsoredTransaction(\n { authorization, calls: [], walletAccount },\n client\n );\n","import { getDefaultClient } from '@dynamic-labs-sdk/client/core';\n\nimport { addEIP6963Extension } from '../eip6963/addEIP6963Extension';\nimport { addWaasEvmExtension } from '../waas/addWaasEvmExtension';\n\n/**\n * Adds the EVM extension to the Dynamic client.\n *\n * This is a convenience function that adds both the EIP-6963 extension\n * and the Dynamic WaaS EVM extension, enabling support for all EVM wallet types\n * including standard wallets and embedded wallets managed by Dynamic's infrastructure.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @notInstrumented\n */\nexport const addEvmExtension = (client = getDefaultClient()): void => {\n addEIP6963Extension(client);\n addWaasEvmExtension(client);\n};\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class EvmGasSponsorshipNotEnabledError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'evm_gas_sponsorship_not_enabled_error',\n docsUrl: null,\n name: 'EvmGasSponsorshipNotEnabledError',\n shortMessage: 'EVM gas sponsorship is not enabled for this project',\n });\n }\n}\n","import type { NetworkProvider } from '@dynamic-labs-sdk/client';\n\nimport type { EvmNetworkProvider } from '../EvmNetworkProvider';\n\n/**\n * Type guard function to check if a network provider is an EVM network provider.\n *\n * @param networkProvider - The network provider to check.\n * @returns True if the network provider is an EVM network provider, false otherwise.\n * @notInstrumented\n */\nexport const isEvmNetworkProvider = (\n networkProvider: NetworkProvider\n): networkProvider is EvmNetworkProvider => networkProvider.chain === 'EVM';\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { FeeEstimationFailedError } from '@dynamic-labs-sdk/client';\nimport { formatEther } from 'viem';\n\nimport type {\n EvmTransactionFeeData,\n EvmTransactionToSimulate,\n} from '../../transactionSimulation.types';\nimport { createPublicClientFromNetworkData } from '../../viem/createPublicClientFromNetworkData';\n\ntype CalculateEvmTransactionFeeParams = {\n nativeTokenPriceUsd?: number;\n networkData: NetworkData;\n transaction: EvmTransactionToSimulate;\n};\n\n/**\n * Calculates the estimated fee for an EVM transaction.\n *\n * This function estimates gas usage and calculates the total transaction fee\n * using either legacy gas pricing or EIP-1559 pricing. The fee is returned\n * in both native units (wei) and human-readable format (ETH).\n *\n * @param params.transaction - The transaction to estimate fees for.\n * @param params.networkData - Network configuration for RPC connection.\n * @param params.nativeTokenPriceUsd - Optional USD price of the native token for fee conversion.\n * @returns Fee data including gas estimates and human-readable amounts.\n * @throws {FeeEstimationFailedError} If gas estimation or fee retrieval fails.\n * @notInstrumented\n */\nexport const calculateEvmTransactionFee = async ({\n transaction,\n networkData,\n nativeTokenPriceUsd,\n}: CalculateEvmTransactionFeeParams): Promise<EvmTransactionFeeData> => {\n try {\n const publicClient = createPublicClientFromNetworkData({ networkData });\n\n // Estimate gas for the transaction\n const gasEstimate = await publicClient.estimateGas({\n account: transaction.from,\n data: transaction.data,\n to: transaction.to,\n value: transaction.value,\n });\n\n // Try to get EIP-1559 fees first, fallback to legacy gas price\n let maxFeePerGas: bigint | undefined;\n let maxPriorityFeePerGas: bigint | undefined;\n let gasPrice: bigint | undefined;\n let nativeAmount: bigint;\n\n try {\n const feeData = await publicClient.estimateFeesPerGas();\n maxFeePerGas = feeData.maxFeePerGas;\n maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;\n\n // Calculate fee using EIP-1559 pricing\n nativeAmount = gasEstimate * maxFeePerGas;\n } catch {\n // Fallback to legacy gas pricing\n gasPrice = await publicClient.getGasPrice();\n nativeAmount = gasEstimate * gasPrice;\n }\n\n // Format to human-readable ETH\n const humanReadableAmount = formatEther(nativeAmount);\n\n // Calculate USD amount if price data available\n const usdAmount = nativeTokenPriceUsd\n ? (Number(humanReadableAmount) * nativeTokenPriceUsd).toFixed(2)\n : undefined;\n\n return {\n gasEstimate,\n gasPrice,\n humanReadableAmount,\n maxFeePerGas,\n maxPriorityFeePerGas,\n nativeAmount,\n usdAmount,\n };\n } catch (error) {\n throw new FeeEstimationFailedError({\n cause: error instanceof Error ? error : undefined,\n message: 'Failed to estimate EVM transaction fee',\n });\n }\n};\n","import {\n FeeEstimationFailedError,\n InvalidParamError,\n SimulationFailedError,\n getDefaultClient,\n getNetworksData,\n} from '@dynamic-labs-sdk/client';\nimport { createApiClient, getCore } from '@dynamic-labs-sdk/client/core';\nimport type { SimulateEVMTransactionRequest } from '@dynamic-labs/sdk-api-core';\n\nimport type { EvmWalletAccount } from '../EvmWalletAccount.types';\nimport type {\n EvmSimulationResult,\n EvmTransactionToSimulate,\n} from '../transactionSimulation.types';\nimport { calculateEvmTransactionFee } from '../utils/calculateEvmTransactionFee';\nimport { isEvmWalletAccount } from '../utils/isEvmWalletAccount';\n\ntype SimulateEvmTransactionParams = {\n includeFees?: boolean;\n transaction: EvmTransactionToSimulate;\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Simulates an EVM transaction to preview its effects before execution.\n *\n * This function uses the Blockaid API to analyze the transaction and returns\n * information about asset transfers, security validation, and optionally fee estimates.\n * The simulation shows what will happen when the transaction is executed without\n * actually sending it to the blockchain.\n *\n * @param params.walletAccount - The EVM wallet account that will sign the transaction.\n * @param params.transaction - The transaction to simulate, including network ID.\n * @param params.includeFees - Whether to calculate transaction fees (default: false).\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns Simulation result with asset diffs, security validation, and optional fee data.\n * @throws {InvalidParamError} If wallet account is not an EVM account or network ID is not configured.\n * @throws {SimulationFailedError} If the simulation API call fails.\n * @throws {FeeEstimationFailedError} If includeFees is true and fee calculation fails.\n * @notInstrumented\n */\nexport const simulateEvmTransaction = async (\n {\n walletAccount,\n transaction,\n includeFees = false,\n }: SimulateEvmTransactionParams,\n client = getDefaultClient()\n): Promise<EvmSimulationResult> => {\n // Validate wallet account type\n if (!isEvmWalletAccount(walletAccount)) {\n throw new InvalidParamError('Wallet account must be an EVM wallet account');\n }\n\n // Get network data for the specified network\n const networksData = getNetworksData(client);\n const networkData = networksData.find(\n (data) => data.networkId === transaction.networkId && data.chain === 'EVM'\n );\n\n if (!networkData) {\n throw new InvalidParamError(\n `Network with ID ${transaction.networkId} is not configured in project settings`\n );\n }\n\n try {\n // Create API client and call simulation endpoint\n const core = getCore(client);\n const apiClient = createApiClient({}, client);\n\n const simulateEVMTransactionRequest = {\n chainId: transaction.networkId,\n data: transaction.data || '0x',\n from: transaction.from,\n to: transaction.to,\n } as SimulateEVMTransactionRequest;\n\n if (transaction.value !== undefined) {\n simulateEVMTransactionRequest.value = transaction.value.toString();\n }\n\n const response = await apiClient.simulateEVMTransaction({\n environmentId: core.environmentId,\n simulateEVMTransactionRequest,\n });\n\n // Calculate fees if requested\n let feeData: EvmSimulationResult['feeData'];\n\n if (includeFees) {\n feeData = await calculateEvmTransactionFee({\n nativeTokenPriceUsd: response.priceData?.nativeTokenUsdPrice,\n networkData,\n transaction,\n });\n }\n\n // Map API response to simulation result\n return {\n counterparties: response.counterparties,\n feeData,\n inAssets: response.inAssets || [],\n outAssets: response.outAssets || [],\n priceData: response.priceData,\n showTotalFiat: response.showTotalFiat,\n validation: response.validation\n ? {\n description: response.validation.description,\n reason: response.validation.reason,\n result: response.validation.result as\n | 'benign'\n | 'warning'\n | 'malicious',\n }\n : undefined,\n };\n } catch (error) {\n // Re-throw FeeEstimationFailedError as-is\n if (error instanceof FeeEstimationFailedError) {\n throw error;\n }\n\n throw new SimulationFailedError({\n cause: error instanceof Error ? error : undefined,\n message: 'Failed to simulate EVM transaction',\n });\n }\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\nassertPackageVersion(packageName, packageVersion);\n\nexport { activate7702Delegation } from '../gasless/activate7702Delegation';\nexport { addEvmExtension } from '../addEvmExtension';\nexport { EvmGasSponsorshipNotEnabledError } from '../errors/EvmGasSponsorshipNotEnabledError';\nexport { RpcError } from '../errors/RpcError';\nexport { SponsorTransactionError } from '../errors/SponsorTransactionError';\nexport type { EvmNetworkProvider } from '../EvmNetworkProvider';\nexport type { EvmWalletAccount } from '../EvmWalletAccount.types';\nexport type { EvmWalletProvider } from '../EvmWalletProvider.types';\nexport type {\n SerializedAuthorization,\n SignedSponsoredTransaction,\n SponsoredTransactionCall,\n SponsoredTransactionStatus,\n SponsoredTransactionStatusResult,\n} from '../gasless/gasless.types';\nexport { getEVMSponsoredTransactionStatus } from '../gasless/getEVMSponsoredTransactionStatus';\nexport { is7702DelegationActive } from '../gasless/is7702DelegationActive';\nexport { isEvmGasSponsorshipEnabled } from '../gasless/isEvmGasSponsorshipEnabled';\nexport { isEvmNetworkProvider } from '../isEvmNetworkProvider';\nexport { simulateEvmTransaction } from '../simulateEvmTransaction';\nexport type {\n EvmSimulationResult,\n EvmTransactionFeeData,\n EvmTransactionToSimulate,\n} from '../transactionSimulation.types';\nexport { calculateEvmTransactionFee } from '../utils/calculateEvmTransactionFee';\nexport { isEvmWalletAccount } from '../utils/isEvmWalletAccount';\nexport { relaySponsoredTransaction } from '../gasless/relaySponsoredTransaction';\nexport { sendSponsoredTransaction } from '../gasless/sendSponsoredTransaction';\nexport { sign7702Authorization } from '../gasless/sign7702Authorization';\nexport { signSponsoredTransaction } from '../gasless/signSponsoredTransaction';\nexport { waitForSponsoredTransaction } from '../gasless/waitForSponsoredTransaction';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,yBAAyB,OACpC,EAAE,eAAe,iBACjB,yDAA2B,KAE3BA,mDACE;CAAE;CAAe,OAAO,EAAE;CAAE;CAAe,EAC3C,OACD;;;;;;;;;;;;;;ACrBH,MAAa,mBAAmB,8DAA2B,KAAW;AACpE,iDAAoB,OAAO;AAC3B,iDAAoB,OAAO;;;;;ACf7B,IAAa,mCAAb,cAAsDC,mCAAU;CAC9D,cAAc;AACZ,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cAAc;GACf,CAAC;;;;;;;;;;;;;ACCN,MAAa,wBACX,oBAC0C,gBAAgB,UAAU;;;;;;;;;;;;;;;;;;ACiBtE,MAAa,6BAA6B,OAAO,EAC/C,aACA,aACA,0BACsE;AACtE,KAAI;EACF,MAAM,eAAeC,6EAAkC,EAAE,aAAa,CAAC;EAGvE,MAAM,cAAc,MAAM,aAAa,YAAY;GACjD,SAAS,YAAY;GACrB,MAAM,YAAY;GAClB,IAAI,YAAY;GAChB,OAAO,YAAY;GACpB,CAAC;EAGF,IAAIC;EACJ,IAAIC;EACJ,IAAIC;EACJ,IAAIC;AAEJ,MAAI;GACF,MAAM,UAAU,MAAM,aAAa,oBAAoB;AACvD,kBAAe,QAAQ;AACvB,0BAAuB,QAAQ;AAG/B,kBAAe,cAAc;UACvB;AAEN,cAAW,MAAM,aAAa,aAAa;AAC3C,kBAAe,cAAc;;EAI/B,MAAM,4CAAkC,aAAa;EAGrD,MAAM,YAAY,uBACb,OAAO,oBAAoB,GAAG,qBAAqB,QAAQ,EAAE,GAC9D;AAEJ,SAAO;GACL;GACA;GACA;GACA;GACA;GACA;GACA;GACD;UACM,OAAO;AACd,QAAM,IAAIC,kDAAyB;GACjC,OAAO,iBAAiB,QAAQ,QAAQ;GACxC,SAAS;GACV,CAAC;;;;;;;;;;;;;;;;;;;;;;;;AC5CN,MAAa,yBAAyB,OACpC,EACE,eACA,aACA,cAAc,SAEhB,yDAA2B,KACM;AAEjC,KAAI,CAACC,6CAAmB,cAAc,CACpC,OAAM,IAAIC,2CAAkB,+CAA+C;CAK7E,MAAM,4DAD+B,OAAO,CACX,MAC9B,SAAS,KAAK,cAAc,YAAY,aAAa,KAAK,UAAU,MACtE;AAED,KAAI,CAAC,YACH,OAAM,IAAIA,2CACR,mBAAmB,YAAY,UAAU,wCAC1C;AAGH,KAAI;EAEF,MAAM,kDAAe,OAAO;EAC5B,MAAM,+DAA4B,EAAE,EAAE,OAAO;EAE7C,MAAM,gCAAgC;GACpC,SAAS,YAAY;GACrB,MAAM,YAAY,QAAQ;GAC1B,MAAM,YAAY;GAClB,IAAI,YAAY;GACjB;AAED,MAAI,YAAY,UAAU,OACxB,+BAA8B,QAAQ,YAAY,MAAM,UAAU;EAGpE,MAAM,WAAW,MAAM,UAAU,uBAAuB;GACtD,eAAe,KAAK;GACpB;GACD,CAAC;EAGF,IAAIC;AAEJ,MAAI,YACF,WAAU,MAAM,2BAA2B;GACzC,qBAAqB,SAAS,WAAW;GACzC;GACA;GACD,CAAC;AAIJ,SAAO;GACL,gBAAgB,SAAS;GACzB;GACA,UAAU,SAAS,YAAY,EAAE;GACjC,WAAW,SAAS,aAAa,EAAE;GACnC,WAAW,SAAS;GACpB,eAAe,SAAS;GACxB,YAAY,SAAS,aACjB;IACE,aAAa,SAAS,WAAW;IACjC,QAAQ,SAAS,WAAW;IAC5B,QAAQ,SAAS,WAAW;IAI7B,GACD;GACL;UACM,OAAO;AAEd,MAAI,iBAAiBC,kDACnB,OAAM;AAGR,QAAM,IAAIC,+CAAsB;GAC9B,OAAO,iBAAiB,QAAQ,QAAQ;GACxC,SAAS;GACV,CAAC;;;;;;mECzHeC,wCAAaC,0CAAe"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["sendSponsoredTransaction","BaseError","createPublicClientFromNetworkData","maxFeePerGas: bigint | undefined","maxPriorityFeePerGas: bigint | undefined","gasPrice: bigint | undefined","nativeAmount: bigint","FeeEstimationFailedError","isEvmWalletAccount","InvalidParamError","feeData: EvmSimulationResult['feeData']","FeeEstimationFailedError","SimulationFailedError","packageName","packageVersion"],"sources":["../src/gasless/activate7702Delegation/activate7702Delegation.ts","../src/addEvmExtension/addEvmExtension.ts","../src/errors/EvmGasSponsorshipNotEnabledError/EvmGasSponsorshipNotEnabledError.ts","../src/isEvmNetworkProvider/isEvmNetworkProvider.ts","../src/utils/calculateEvmTransactionFee/calculateEvmTransactionFee.ts","../src/simulateEvmTransaction/simulateEvmTransaction.ts","../src/exports/index.ts"],"sourcesContent":["import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport type { Hex } from 'viem';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\n\nimport type { EvmWalletAccount } from '../../EvmWalletAccount.types';\nimport { sendSponsoredTransaction } from '../sendSponsoredTransaction';\n\ntype Activate7702DelegationParams = {\n /** Pre-signed EIP-7702 authorization. If not provided, one will be signed automatically. */\n authorization?: SignAuthorizationReturnType;\n /** The EVM wallet account to activate delegation for. */\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Activates EIP-7702 delegation for a wallet by sending a sponsored\n * transaction that only contains the 7702 authorization.\n *\n * After activation, the wallet's delegation is persisted on-chain and\n * subsequent sponsored transactions no longer need to include the\n * authorization.\n *\n * @example\n * ```ts\n * const { transactionHash } = await activate7702Delegation({\n * walletAccount: evmAccount,\n * });\n * ```\n *\n * @param params.walletAccount - The EVM wallet account to activate delegation for.\n * @param [params.authorization] - Pre-signed authorization. If omitted, signs one automatically.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns An object containing the on-chain transaction hash.\n * @throws {SponsorTransactionError} If the relay returns a terminal failure or polling times out.\n * @see is7702DelegationActive\n * @see sign7702Authorization\n * @notInstrumented\n */\nexport const activate7702Delegation = async (\n { walletAccount, authorization }: Activate7702DelegationParams,\n client = getDefaultClient()\n): Promise<{ transactionHash: Hex }> =>\n sendSponsoredTransaction(\n { authorization, calls: [], walletAccount },\n client\n );\n","import { getDefaultClient } from '@dynamic-labs-sdk/client/core';\n\nimport { addEIP6963Extension } from '../eip6963/addEIP6963Extension';\nimport { addWaasEvmExtension } from '../waas/addWaasEvmExtension';\n\n/**\n * Adds the EVM extension to the Dynamic client.\n *\n * This is a convenience function that adds both the EIP-6963 extension\n * and the Dynamic WaaS EVM extension, enabling support for all EVM wallet types\n * including standard wallets and embedded wallets managed by Dynamic's infrastructure.\n *\n * @example\n * ```ts\n * const client = createDynamicClient({ environmentId: 'env-123' });\n * addEvmExtension(client);\n * ```\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns void\n * @see isEvmWalletAccount\n * @see isEvmNetworkProvider\n * @notInstrumented\n */\nexport const addEvmExtension = (client = getDefaultClient()): void => {\n addEIP6963Extension(client);\n addWaasEvmExtension(client);\n};\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class EvmGasSponsorshipNotEnabledError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'evm_gas_sponsorship_not_enabled_error',\n docsUrl: null,\n name: 'EvmGasSponsorshipNotEnabledError',\n shortMessage: 'EVM gas sponsorship is not enabled for this project',\n });\n }\n}\n","import type { NetworkProvider } from '@dynamic-labs-sdk/client';\n\nimport type { EvmNetworkProvider } from '../EvmNetworkProvider';\n\n/**\n * Type guard function to check if a network provider is an EVM network provider.\n *\n * @example\n * ```ts\n * if (isEvmNetworkProvider(networkProvider)) {\n * const publicClient = networkProvider.getPublicClient();\n * }\n * ```\n *\n * @param networkProvider - The network provider to check.\n * @returns True if the network provider is an EVM network provider, false otherwise.\n * @see isEvmWalletAccount\n * @see addEvmExtension\n * @notInstrumented\n */\nexport const isEvmNetworkProvider = (\n networkProvider: NetworkProvider\n): networkProvider is EvmNetworkProvider => networkProvider.chain === 'EVM';\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { FeeEstimationFailedError } from '@dynamic-labs-sdk/client';\nimport { formatEther } from 'viem';\n\nimport type {\n EvmTransactionFeeData,\n EvmTransactionToSimulate,\n} from '../../transactionSimulation.types';\nimport { createPublicClientFromNetworkData } from '../../viem/createPublicClientFromNetworkData';\n\ntype CalculateEvmTransactionFeeParams = {\n nativeTokenPriceUsd?: number;\n networkData: NetworkData;\n transaction: EvmTransactionToSimulate;\n};\n\n/**\n * Calculates the estimated fee for an EVM transaction.\n *\n * This function estimates gas usage and calculates the total transaction fee\n * using either legacy gas pricing or EIP-1559 pricing. The fee is returned\n * in both native units (wei) and human-readable format (ETH).\n *\n * @example\n * ```ts\n * const feeData = await calculateEvmTransactionFee({\n * transaction: { from: '0x...', to: '0x...', value: 1000000000000000000n, networkId: '1' },\n * networkData,\n * nativeTokenPriceUsd: 3500,\n * });\n * ```\n *\n * @param params.transaction - The transaction to estimate fees for.\n * @param params.networkData - Network configuration for RPC connection.\n * @param params.nativeTokenPriceUsd - Optional USD price of the native token for fee conversion.\n * @returns Fee data including gas estimates and human-readable amounts.\n * @throws {FeeEstimationFailedError} If gas estimation or fee retrieval fails.\n * @see simulateEvmTransaction\n * @see isEvmWalletAccount\n * @notInstrumented\n */\nexport const calculateEvmTransactionFee = async ({\n transaction,\n networkData,\n nativeTokenPriceUsd,\n}: CalculateEvmTransactionFeeParams): Promise<EvmTransactionFeeData> => {\n try {\n const publicClient = createPublicClientFromNetworkData({ networkData });\n\n // Estimate gas for the transaction\n const gasEstimate = await publicClient.estimateGas({\n account: transaction.from,\n data: transaction.data,\n to: transaction.to,\n value: transaction.value,\n });\n\n // Try to get EIP-1559 fees first, fallback to legacy gas price\n let maxFeePerGas: bigint | undefined;\n let maxPriorityFeePerGas: bigint | undefined;\n let gasPrice: bigint | undefined;\n let nativeAmount: bigint;\n\n try {\n const feeData = await publicClient.estimateFeesPerGas();\n maxFeePerGas = feeData.maxFeePerGas;\n maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;\n\n // Calculate fee using EIP-1559 pricing\n nativeAmount = gasEstimate * maxFeePerGas;\n } catch {\n // Fallback to legacy gas pricing\n gasPrice = await publicClient.getGasPrice();\n nativeAmount = gasEstimate * gasPrice;\n }\n\n // Format to human-readable ETH\n const humanReadableAmount = formatEther(nativeAmount);\n\n // Calculate USD amount if price data available\n const usdAmount = nativeTokenPriceUsd\n ? (Number(humanReadableAmount) * nativeTokenPriceUsd).toFixed(2)\n : undefined;\n\n return {\n gasEstimate,\n gasPrice,\n humanReadableAmount,\n maxFeePerGas,\n maxPriorityFeePerGas,\n nativeAmount,\n usdAmount,\n };\n } catch (error) {\n throw new FeeEstimationFailedError({\n cause: error instanceof Error ? error : undefined,\n message: 'Failed to estimate EVM transaction fee',\n });\n }\n};\n","import {\n FeeEstimationFailedError,\n InvalidParamError,\n SimulationFailedError,\n getDefaultClient,\n getNetworksData,\n} from '@dynamic-labs-sdk/client';\nimport { createApiClient, getCore } from '@dynamic-labs-sdk/client/core';\nimport type { SimulateEVMTransactionRequest } from '@dynamic-labs/sdk-api-core';\n\nimport type { EvmWalletAccount } from '../EvmWalletAccount.types';\nimport type {\n EvmSimulationResult,\n EvmTransactionToSimulate,\n} from '../transactionSimulation.types';\nimport { calculateEvmTransactionFee } from '../utils/calculateEvmTransactionFee';\nimport { isEvmWalletAccount } from '../utils/isEvmWalletAccount';\n\ntype SimulateEvmTransactionParams = {\n includeFees?: boolean;\n transaction: EvmTransactionToSimulate;\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Simulates an EVM transaction to preview its effects before execution.\n *\n * This function uses the Blockaid API to analyze the transaction and returns\n * information about asset transfers, security validation, and optionally fee estimates.\n * The simulation shows what will happen when the transaction is executed without\n * actually sending it to the blockchain.\n *\n * @example\n * ```ts\n * const result = await simulateEvmTransaction({\n * walletAccount: evmAccount,\n * transaction: { from: '0x...', to: '0x...', value: 1000000000000000000n, networkId: '1' },\n * includeFees: true,\n * });\n * ```\n *\n * @param params.walletAccount - The EVM wallet account that will sign the transaction.\n * @param params.transaction - The transaction to simulate, including network ID.\n * @param params.includeFees - Whether to calculate transaction fees (default: false).\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns Simulation result with asset diffs, security validation, and optional fee data.\n * @throws {InvalidParamError} If wallet account is not an EVM account or network ID is not configured.\n * @throws {SimulationFailedError} If the simulation API call fails.\n * @throws {FeeEstimationFailedError} If includeFees is true and fee calculation fails.\n * @see calculateEvmTransactionFee\n * @see isEvmWalletAccount\n * @notInstrumented\n */\nexport const simulateEvmTransaction = async (\n {\n walletAccount,\n transaction,\n includeFees = false,\n }: SimulateEvmTransactionParams,\n client = getDefaultClient()\n): Promise<EvmSimulationResult> => {\n // Validate wallet account type\n if (!isEvmWalletAccount(walletAccount)) {\n throw new InvalidParamError('Wallet account must be an EVM wallet account');\n }\n\n // Get network data for the specified network\n const networksData = getNetworksData(client);\n const networkData = networksData.find(\n (data) => data.networkId === transaction.networkId && data.chain === 'EVM'\n );\n\n if (!networkData) {\n throw new InvalidParamError(\n `Network with ID ${transaction.networkId} is not configured in project settings`\n );\n }\n\n try {\n // Create API client and call simulation endpoint\n const core = getCore(client);\n const apiClient = createApiClient({}, client);\n\n const simulateEVMTransactionRequest = {\n chainId: transaction.networkId,\n data: transaction.data || '0x',\n from: transaction.from,\n to: transaction.to,\n } as SimulateEVMTransactionRequest;\n\n if (transaction.value !== undefined) {\n simulateEVMTransactionRequest.value = transaction.value.toString();\n }\n\n const response = await apiClient.simulateEVMTransaction({\n environmentId: core.environmentId,\n simulateEVMTransactionRequest,\n });\n\n // Calculate fees if requested\n let feeData: EvmSimulationResult['feeData'];\n\n if (includeFees) {\n feeData = await calculateEvmTransactionFee({\n nativeTokenPriceUsd: response.priceData?.nativeTokenUsdPrice,\n networkData,\n transaction,\n });\n }\n\n // Map API response to simulation result\n return {\n counterparties: response.counterparties,\n feeData,\n inAssets: response.inAssets || [],\n outAssets: response.outAssets || [],\n priceData: response.priceData,\n showTotalFiat: response.showTotalFiat,\n validation: response.validation\n ? {\n description: response.validation.description,\n reason: response.validation.reason,\n result: response.validation.result as\n | 'benign'\n | 'warning'\n | 'malicious',\n }\n : undefined,\n };\n } catch (error) {\n // Re-throw FeeEstimationFailedError as-is\n if (error instanceof FeeEstimationFailedError) {\n throw error;\n }\n\n throw new SimulationFailedError({\n cause: error instanceof Error ? error : undefined,\n message: 'Failed to simulate EVM transaction',\n });\n }\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\nassertPackageVersion(packageName, packageVersion);\n\nexport { activate7702Delegation } from '../gasless/activate7702Delegation';\nexport { addEvmExtension } from '../addEvmExtension';\nexport { EvmGasSponsorshipNotEnabledError } from '../errors/EvmGasSponsorshipNotEnabledError';\nexport { RpcError } from '../errors/RpcError';\nexport { SponsorTransactionError } from '../errors/SponsorTransactionError';\nexport type { EvmNetworkProvider } from '../EvmNetworkProvider';\nexport type { EvmWalletAccount } from '../EvmWalletAccount.types';\nexport type { EvmWalletProvider } from '../EvmWalletProvider.types';\nexport type {\n SerializedAuthorization,\n SignedSponsoredTransaction,\n SponsoredTransactionCall,\n SponsoredTransactionStatus,\n SponsoredTransactionStatusResult,\n} from '../gasless/gasless.types';\nexport { getEVMSponsoredTransactionStatus } from '../gasless/getEVMSponsoredTransactionStatus';\nexport { is7702DelegationActive } from '../gasless/is7702DelegationActive';\nexport { isEvmGasSponsorshipEnabled } from '../gasless/isEvmGasSponsorshipEnabled';\nexport { isEvmNetworkProvider } from '../isEvmNetworkProvider';\nexport { simulateEvmTransaction } from '../simulateEvmTransaction';\nexport type {\n EvmSimulationResult,\n EvmTransactionFeeData,\n EvmTransactionToSimulate,\n} from '../transactionSimulation.types';\nexport { calculateEvmTransactionFee } from '../utils/calculateEvmTransactionFee';\nexport { isEvmWalletAccount } from '../utils/isEvmWalletAccount';\nexport { relaySponsoredTransaction } from '../gasless/relaySponsoredTransaction';\nexport { sendSponsoredTransaction } from '../gasless/sendSponsoredTransaction';\nexport { sign7702Authorization } from '../gasless/sign7702Authorization';\nexport { signSponsoredTransaction } from '../gasless/signSponsoredTransaction';\nexport { waitForSponsoredTransaction } from '../gasless/waitForSponsoredTransaction';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,yBAAyB,OACpC,EAAE,eAAe,iBACjB,yDAA2B,KAE3BA,mDACE;CAAE;CAAe,OAAO,EAAE;CAAE;CAAe,EAC3C,OACD;;;;;;;;;;;;;;;;;;;;;;;ACrBH,MAAa,mBAAmB,8DAA2B,KAAW;AACpE,iDAAoB,OAAO;AAC3B,iDAAoB,OAAO;;;;;ACxB7B,IAAa,mCAAb,cAAsDC,mCAAU;CAC9D,cAAc;AACZ,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cAAc;GACf,CAAC;;;;;;;;;;;;;;;;;;;;;;ACUN,MAAa,wBACX,oBAC0C,gBAAgB,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACmBtE,MAAa,6BAA6B,OAAO,EAC/C,aACA,aACA,0BACsE;AACtE,KAAI;EACF,MAAM,eAAeC,6EAAkC,EAAE,aAAa,CAAC;EAGvE,MAAM,cAAc,MAAM,aAAa,YAAY;GACjD,SAAS,YAAY;GACrB,MAAM,YAAY;GAClB,IAAI,YAAY;GAChB,OAAO,YAAY;GACpB,CAAC;EAGF,IAAIC;EACJ,IAAIC;EACJ,IAAIC;EACJ,IAAIC;AAEJ,MAAI;GACF,MAAM,UAAU,MAAM,aAAa,oBAAoB;AACvD,kBAAe,QAAQ;AACvB,0BAAuB,QAAQ;AAG/B,kBAAe,cAAc;UACvB;AAEN,cAAW,MAAM,aAAa,aAAa;AAC3C,kBAAe,cAAc;;EAI/B,MAAM,4CAAkC,aAAa;EAGrD,MAAM,YAAY,uBACb,OAAO,oBAAoB,GAAG,qBAAqB,QAAQ,EAAE,GAC9D;AAEJ,SAAO;GACL;GACA;GACA;GACA;GACA;GACA;GACA;GACD;UACM,OAAO;AACd,QAAM,IAAIC,kDAAyB;GACjC,OAAO,iBAAiB,QAAQ,QAAQ;GACxC,SAAS;GACV,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC5CN,MAAa,yBAAyB,OACpC,EACE,eACA,aACA,cAAc,SAEhB,yDAA2B,KACM;AAEjC,KAAI,CAACC,6CAAmB,cAAc,CACpC,OAAM,IAAIC,2CAAkB,+CAA+C;CAK7E,MAAM,4DAD+B,OAAO,CACX,MAC9B,SAAS,KAAK,cAAc,YAAY,aAAa,KAAK,UAAU,MACtE;AAED,KAAI,CAAC,YACH,OAAM,IAAIA,2CACR,mBAAmB,YAAY,UAAU,wCAC1C;AAGH,KAAI;EAEF,MAAM,kDAAe,OAAO;EAC5B,MAAM,+DAA4B,EAAE,EAAE,OAAO;EAE7C,MAAM,gCAAgC;GACpC,SAAS,YAAY;GACrB,MAAM,YAAY,QAAQ;GAC1B,MAAM,YAAY;GAClB,IAAI,YAAY;GACjB;AAED,MAAI,YAAY,UAAU,OACxB,+BAA8B,QAAQ,YAAY,MAAM,UAAU;EAGpE,MAAM,WAAW,MAAM,UAAU,uBAAuB;GACtD,eAAe,KAAK;GACpB;GACD,CAAC;EAGF,IAAIC;AAEJ,MAAI,YACF,WAAU,MAAM,2BAA2B;GACzC,qBAAqB,SAAS,WAAW;GACzC;GACA;GACD,CAAC;AAIJ,SAAO;GACL,gBAAgB,SAAS;GACzB;GACA,UAAU,SAAS,YAAY,EAAE;GACjC,WAAW,SAAS,aAAa,EAAE;GACnC,WAAW,SAAS;GACpB,eAAe,SAAS;GACxB,YAAY,SAAS,aACjB;IACE,aAAa,SAAS,WAAW;IACjC,QAAQ,SAAS,WAAW;IAC5B,QAAQ,SAAS,WAAW;IAI7B,GACD;GACL;UACM,OAAO;AAEd,MAAI,iBAAiBC,kDACnB,OAAM;AAGR,QAAM,IAAIC,+CAAsB;GAC9B,OAAO,iBAAiB,QAAQ,QAAQ;GACxC,SAAS;GACV,CAAC;;;;;;mECpIeC,wCAAaC,0CAAe"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { n as name, r as version } from "./mapNetworkDataToViemChain-
|
|
2
|
-
import { a as isEvmWalletAccount, c as sendSponsoredTransaction, d as relaySponsoredTransaction, f as signSponsoredTransaction, h as SponsorTransactionError, l as waitForSponsoredTransaction, m as is7702DelegationActive, p as sign7702Authorization, r as isEvmGasSponsorshipEnabled, s as RpcError, u as getEVMSponsoredTransactionStatus } from "./evmTransferAmount-
|
|
3
|
-
import { r as createPublicClientFromNetworkData } from "./createWalletClientForWalletAccount-
|
|
4
|
-
import "./createWalletProviderFromEIP1193Provider-
|
|
5
|
-
import { t as addEIP6963Extension } from "./addEIP6963Extension-
|
|
6
|
-
import { t as addWaasEvmExtension } from "./addWaasEvmExtension-
|
|
1
|
+
import { n as name, r as version } from "./mapNetworkDataToViemChain-DXy4yka7.esm.js";
|
|
2
|
+
import { a as isEvmWalletAccount, c as sendSponsoredTransaction, d as relaySponsoredTransaction, f as signSponsoredTransaction, h as SponsorTransactionError, l as waitForSponsoredTransaction, m as is7702DelegationActive, p as sign7702Authorization, r as isEvmGasSponsorshipEnabled, s as RpcError, u as getEVMSponsoredTransactionStatus } from "./evmTransferAmount-zNYlT8-b.esm.js";
|
|
3
|
+
import { r as createPublicClientFromNetworkData } from "./createWalletClientForWalletAccount-CSV76RdP.esm.js";
|
|
4
|
+
import "./createWalletProviderFromEIP1193Provider-Dhruqg0P.esm.js";
|
|
5
|
+
import { t as addEIP6963Extension } from "./addEIP6963Extension-BjucaEgu.esm.js";
|
|
6
|
+
import { t as addWaasEvmExtension } from "./addWaasEvmExtension-D47UG4zQ.esm.js";
|
|
7
7
|
import { assertPackageVersion } from "@dynamic-labs-sdk/assert-package-version";
|
|
8
8
|
import { BaseError, FeeEstimationFailedError, InvalidParamError, SimulationFailedError, getDefaultClient, getNetworksData } from "@dynamic-labs-sdk/client";
|
|
9
9
|
import { createApiClient, getCore, getDefaultClient as getDefaultClient$1 } from "@dynamic-labs-sdk/client/core";
|
|
@@ -18,11 +18,20 @@ import { formatEther } from "viem";
|
|
|
18
18
|
* subsequent sponsored transactions no longer need to include the
|
|
19
19
|
* authorization.
|
|
20
20
|
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const { transactionHash } = await activate7702Delegation({
|
|
24
|
+
* walletAccount: evmAccount,
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
21
28
|
* @param params.walletAccount - The EVM wallet account to activate delegation for.
|
|
22
29
|
* @param [params.authorization] - Pre-signed authorization. If omitted, signs one automatically.
|
|
23
30
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
24
31
|
* @returns An object containing the on-chain transaction hash.
|
|
25
32
|
* @throws {SponsorTransactionError} If the relay returns a terminal failure or polling times out.
|
|
33
|
+
* @see is7702DelegationActive
|
|
34
|
+
* @see sign7702Authorization
|
|
26
35
|
* @notInstrumented
|
|
27
36
|
*/
|
|
28
37
|
const activate7702Delegation = async ({ walletAccount, authorization }, client = getDefaultClient()) => sendSponsoredTransaction({
|
|
@@ -40,7 +49,16 @@ const activate7702Delegation = async ({ walletAccount, authorization }, client =
|
|
|
40
49
|
* and the Dynamic WaaS EVM extension, enabling support for all EVM wallet types
|
|
41
50
|
* including standard wallets and embedded wallets managed by Dynamic's infrastructure.
|
|
42
51
|
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const client = createDynamicClient({ environmentId: 'env-123' });
|
|
55
|
+
* addEvmExtension(client);
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
43
58
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
59
|
+
* @returns void
|
|
60
|
+
* @see isEvmWalletAccount
|
|
61
|
+
* @see isEvmNetworkProvider
|
|
44
62
|
* @notInstrumented
|
|
45
63
|
*/
|
|
46
64
|
const addEvmExtension = (client = getDefaultClient$1()) => {
|
|
@@ -67,8 +85,17 @@ var EvmGasSponsorshipNotEnabledError = class extends BaseError {
|
|
|
67
85
|
/**
|
|
68
86
|
* Type guard function to check if a network provider is an EVM network provider.
|
|
69
87
|
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* if (isEvmNetworkProvider(networkProvider)) {
|
|
91
|
+
* const publicClient = networkProvider.getPublicClient();
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
70
95
|
* @param networkProvider - The network provider to check.
|
|
71
96
|
* @returns True if the network provider is an EVM network provider, false otherwise.
|
|
97
|
+
* @see isEvmWalletAccount
|
|
98
|
+
* @see addEvmExtension
|
|
72
99
|
* @notInstrumented
|
|
73
100
|
*/
|
|
74
101
|
const isEvmNetworkProvider = (networkProvider) => networkProvider.chain === "EVM";
|
|
@@ -82,11 +109,22 @@ const isEvmNetworkProvider = (networkProvider) => networkProvider.chain === "EVM
|
|
|
82
109
|
* using either legacy gas pricing or EIP-1559 pricing. The fee is returned
|
|
83
110
|
* in both native units (wei) and human-readable format (ETH).
|
|
84
111
|
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const feeData = await calculateEvmTransactionFee({
|
|
115
|
+
* transaction: { from: '0x...', to: '0x...', value: 1000000000000000000n, networkId: '1' },
|
|
116
|
+
* networkData,
|
|
117
|
+
* nativeTokenPriceUsd: 3500,
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
85
121
|
* @param params.transaction - The transaction to estimate fees for.
|
|
86
122
|
* @param params.networkData - Network configuration for RPC connection.
|
|
87
123
|
* @param params.nativeTokenPriceUsd - Optional USD price of the native token for fee conversion.
|
|
88
124
|
* @returns Fee data including gas estimates and human-readable amounts.
|
|
89
125
|
* @throws {FeeEstimationFailedError} If gas estimation or fee retrieval fails.
|
|
126
|
+
* @see simulateEvmTransaction
|
|
127
|
+
* @see isEvmWalletAccount
|
|
90
128
|
* @notInstrumented
|
|
91
129
|
*/
|
|
92
130
|
const calculateEvmTransactionFee = async ({ transaction, networkData, nativeTokenPriceUsd }) => {
|
|
@@ -140,6 +178,15 @@ const calculateEvmTransactionFee = async ({ transaction, networkData, nativeToke
|
|
|
140
178
|
* The simulation shows what will happen when the transaction is executed without
|
|
141
179
|
* actually sending it to the blockchain.
|
|
142
180
|
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* const result = await simulateEvmTransaction({
|
|
184
|
+
* walletAccount: evmAccount,
|
|
185
|
+
* transaction: { from: '0x...', to: '0x...', value: 1000000000000000000n, networkId: '1' },
|
|
186
|
+
* includeFees: true,
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
143
190
|
* @param params.walletAccount - The EVM wallet account that will sign the transaction.
|
|
144
191
|
* @param params.transaction - The transaction to simulate, including network ID.
|
|
145
192
|
* @param params.includeFees - Whether to calculate transaction fees (default: false).
|
|
@@ -148,6 +195,8 @@ const calculateEvmTransactionFee = async ({ transaction, networkData, nativeToke
|
|
|
148
195
|
* @throws {InvalidParamError} If wallet account is not an EVM account or network ID is not configured.
|
|
149
196
|
* @throws {SimulationFailedError} If the simulation API call fails.
|
|
150
197
|
* @throws {FeeEstimationFailedError} If includeFees is true and fee calculation fails.
|
|
198
|
+
* @see calculateEvmTransactionFee
|
|
199
|
+
* @see isEvmWalletAccount
|
|
151
200
|
* @notInstrumented
|
|
152
201
|
*/
|
|
153
202
|
const simulateEvmTransaction = async ({ walletAccount, transaction, includeFees = false }, client = getDefaultClient()) => {
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","names":["getDefaultClient","maxFeePerGas: bigint | undefined","maxPriorityFeePerGas: bigint | undefined","gasPrice: bigint | undefined","nativeAmount: bigint","feeData: EvmSimulationResult['feeData']","packageName","packageVersion"],"sources":["../src/gasless/activate7702Delegation/activate7702Delegation.ts","../src/addEvmExtension/addEvmExtension.ts","../src/errors/EvmGasSponsorshipNotEnabledError/EvmGasSponsorshipNotEnabledError.ts","../src/isEvmNetworkProvider/isEvmNetworkProvider.ts","../src/utils/calculateEvmTransactionFee/calculateEvmTransactionFee.ts","../src/simulateEvmTransaction/simulateEvmTransaction.ts","../src/exports/index.ts"],"sourcesContent":["import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport type { Hex } from 'viem';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\n\nimport type { EvmWalletAccount } from '../../EvmWalletAccount.types';\nimport { sendSponsoredTransaction } from '../sendSponsoredTransaction';\n\ntype Activate7702DelegationParams = {\n /** Pre-signed EIP-7702 authorization. If not provided, one will be signed automatically. */\n authorization?: SignAuthorizationReturnType;\n /** The EVM wallet account to activate delegation for. */\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Activates EIP-7702 delegation for a wallet by sending a sponsored\n * transaction that only contains the 7702 authorization.\n *\n * After activation, the wallet's delegation is persisted on-chain and\n * subsequent sponsored transactions no longer need to include the\n * authorization.\n *\n * @param params.walletAccount - The EVM wallet account to activate delegation for.\n * @param [params.authorization] - Pre-signed authorization. If omitted, signs one automatically.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns An object containing the on-chain transaction hash.\n * @throws {SponsorTransactionError} If the relay returns a terminal failure or polling times out.\n * @notInstrumented\n */\nexport const activate7702Delegation = async (\n { walletAccount, authorization }: Activate7702DelegationParams,\n client = getDefaultClient()\n): Promise<{ transactionHash: Hex }> =>\n sendSponsoredTransaction(\n { authorization, calls: [], walletAccount },\n client\n );\n","import { getDefaultClient } from '@dynamic-labs-sdk/client/core';\n\nimport { addEIP6963Extension } from '../eip6963/addEIP6963Extension';\nimport { addWaasEvmExtension } from '../waas/addWaasEvmExtension';\n\n/**\n * Adds the EVM extension to the Dynamic client.\n *\n * This is a convenience function that adds both the EIP-6963 extension\n * and the Dynamic WaaS EVM extension, enabling support for all EVM wallet types\n * including standard wallets and embedded wallets managed by Dynamic's infrastructure.\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @notInstrumented\n */\nexport const addEvmExtension = (client = getDefaultClient()): void => {\n addEIP6963Extension(client);\n addWaasEvmExtension(client);\n};\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class EvmGasSponsorshipNotEnabledError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'evm_gas_sponsorship_not_enabled_error',\n docsUrl: null,\n name: 'EvmGasSponsorshipNotEnabledError',\n shortMessage: 'EVM gas sponsorship is not enabled for this project',\n });\n }\n}\n","import type { NetworkProvider } from '@dynamic-labs-sdk/client';\n\nimport type { EvmNetworkProvider } from '../EvmNetworkProvider';\n\n/**\n * Type guard function to check if a network provider is an EVM network provider.\n *\n * @param networkProvider - The network provider to check.\n * @returns True if the network provider is an EVM network provider, false otherwise.\n * @notInstrumented\n */\nexport const isEvmNetworkProvider = (\n networkProvider: NetworkProvider\n): networkProvider is EvmNetworkProvider => networkProvider.chain === 'EVM';\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { FeeEstimationFailedError } from '@dynamic-labs-sdk/client';\nimport { formatEther } from 'viem';\n\nimport type {\n EvmTransactionFeeData,\n EvmTransactionToSimulate,\n} from '../../transactionSimulation.types';\nimport { createPublicClientFromNetworkData } from '../../viem/createPublicClientFromNetworkData';\n\ntype CalculateEvmTransactionFeeParams = {\n nativeTokenPriceUsd?: number;\n networkData: NetworkData;\n transaction: EvmTransactionToSimulate;\n};\n\n/**\n * Calculates the estimated fee for an EVM transaction.\n *\n * This function estimates gas usage and calculates the total transaction fee\n * using either legacy gas pricing or EIP-1559 pricing. The fee is returned\n * in both native units (wei) and human-readable format (ETH).\n *\n * @param params.transaction - The transaction to estimate fees for.\n * @param params.networkData - Network configuration for RPC connection.\n * @param params.nativeTokenPriceUsd - Optional USD price of the native token for fee conversion.\n * @returns Fee data including gas estimates and human-readable amounts.\n * @throws {FeeEstimationFailedError} If gas estimation or fee retrieval fails.\n * @notInstrumented\n */\nexport const calculateEvmTransactionFee = async ({\n transaction,\n networkData,\n nativeTokenPriceUsd,\n}: CalculateEvmTransactionFeeParams): Promise<EvmTransactionFeeData> => {\n try {\n const publicClient = createPublicClientFromNetworkData({ networkData });\n\n // Estimate gas for the transaction\n const gasEstimate = await publicClient.estimateGas({\n account: transaction.from,\n data: transaction.data,\n to: transaction.to,\n value: transaction.value,\n });\n\n // Try to get EIP-1559 fees first, fallback to legacy gas price\n let maxFeePerGas: bigint | undefined;\n let maxPriorityFeePerGas: bigint | undefined;\n let gasPrice: bigint | undefined;\n let nativeAmount: bigint;\n\n try {\n const feeData = await publicClient.estimateFeesPerGas();\n maxFeePerGas = feeData.maxFeePerGas;\n maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;\n\n // Calculate fee using EIP-1559 pricing\n nativeAmount = gasEstimate * maxFeePerGas;\n } catch {\n // Fallback to legacy gas pricing\n gasPrice = await publicClient.getGasPrice();\n nativeAmount = gasEstimate * gasPrice;\n }\n\n // Format to human-readable ETH\n const humanReadableAmount = formatEther(nativeAmount);\n\n // Calculate USD amount if price data available\n const usdAmount = nativeTokenPriceUsd\n ? (Number(humanReadableAmount) * nativeTokenPriceUsd).toFixed(2)\n : undefined;\n\n return {\n gasEstimate,\n gasPrice,\n humanReadableAmount,\n maxFeePerGas,\n maxPriorityFeePerGas,\n nativeAmount,\n usdAmount,\n };\n } catch (error) {\n throw new FeeEstimationFailedError({\n cause: error instanceof Error ? error : undefined,\n message: 'Failed to estimate EVM transaction fee',\n });\n }\n};\n","import {\n FeeEstimationFailedError,\n InvalidParamError,\n SimulationFailedError,\n getDefaultClient,\n getNetworksData,\n} from '@dynamic-labs-sdk/client';\nimport { createApiClient, getCore } from '@dynamic-labs-sdk/client/core';\nimport type { SimulateEVMTransactionRequest } from '@dynamic-labs/sdk-api-core';\n\nimport type { EvmWalletAccount } from '../EvmWalletAccount.types';\nimport type {\n EvmSimulationResult,\n EvmTransactionToSimulate,\n} from '../transactionSimulation.types';\nimport { calculateEvmTransactionFee } from '../utils/calculateEvmTransactionFee';\nimport { isEvmWalletAccount } from '../utils/isEvmWalletAccount';\n\ntype SimulateEvmTransactionParams = {\n includeFees?: boolean;\n transaction: EvmTransactionToSimulate;\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Simulates an EVM transaction to preview its effects before execution.\n *\n * This function uses the Blockaid API to analyze the transaction and returns\n * information about asset transfers, security validation, and optionally fee estimates.\n * The simulation shows what will happen when the transaction is executed without\n * actually sending it to the blockchain.\n *\n * @param params.walletAccount - The EVM wallet account that will sign the transaction.\n * @param params.transaction - The transaction to simulate, including network ID.\n * @param params.includeFees - Whether to calculate transaction fees (default: false).\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns Simulation result with asset diffs, security validation, and optional fee data.\n * @throws {InvalidParamError} If wallet account is not an EVM account or network ID is not configured.\n * @throws {SimulationFailedError} If the simulation API call fails.\n * @throws {FeeEstimationFailedError} If includeFees is true and fee calculation fails.\n * @notInstrumented\n */\nexport const simulateEvmTransaction = async (\n {\n walletAccount,\n transaction,\n includeFees = false,\n }: SimulateEvmTransactionParams,\n client = getDefaultClient()\n): Promise<EvmSimulationResult> => {\n // Validate wallet account type\n if (!isEvmWalletAccount(walletAccount)) {\n throw new InvalidParamError('Wallet account must be an EVM wallet account');\n }\n\n // Get network data for the specified network\n const networksData = getNetworksData(client);\n const networkData = networksData.find(\n (data) => data.networkId === transaction.networkId && data.chain === 'EVM'\n );\n\n if (!networkData) {\n throw new InvalidParamError(\n `Network with ID ${transaction.networkId} is not configured in project settings`\n );\n }\n\n try {\n // Create API client and call simulation endpoint\n const core = getCore(client);\n const apiClient = createApiClient({}, client);\n\n const simulateEVMTransactionRequest = {\n chainId: transaction.networkId,\n data: transaction.data || '0x',\n from: transaction.from,\n to: transaction.to,\n } as SimulateEVMTransactionRequest;\n\n if (transaction.value !== undefined) {\n simulateEVMTransactionRequest.value = transaction.value.toString();\n }\n\n const response = await apiClient.simulateEVMTransaction({\n environmentId: core.environmentId,\n simulateEVMTransactionRequest,\n });\n\n // Calculate fees if requested\n let feeData: EvmSimulationResult['feeData'];\n\n if (includeFees) {\n feeData = await calculateEvmTransactionFee({\n nativeTokenPriceUsd: response.priceData?.nativeTokenUsdPrice,\n networkData,\n transaction,\n });\n }\n\n // Map API response to simulation result\n return {\n counterparties: response.counterparties,\n feeData,\n inAssets: response.inAssets || [],\n outAssets: response.outAssets || [],\n priceData: response.priceData,\n showTotalFiat: response.showTotalFiat,\n validation: response.validation\n ? {\n description: response.validation.description,\n reason: response.validation.reason,\n result: response.validation.result as\n | 'benign'\n | 'warning'\n | 'malicious',\n }\n : undefined,\n };\n } catch (error) {\n // Re-throw FeeEstimationFailedError as-is\n if (error instanceof FeeEstimationFailedError) {\n throw error;\n }\n\n throw new SimulationFailedError({\n cause: error instanceof Error ? error : undefined,\n message: 'Failed to simulate EVM transaction',\n });\n }\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\nassertPackageVersion(packageName, packageVersion);\n\nexport { activate7702Delegation } from '../gasless/activate7702Delegation';\nexport { addEvmExtension } from '../addEvmExtension';\nexport { EvmGasSponsorshipNotEnabledError } from '../errors/EvmGasSponsorshipNotEnabledError';\nexport { RpcError } from '../errors/RpcError';\nexport { SponsorTransactionError } from '../errors/SponsorTransactionError';\nexport type { EvmNetworkProvider } from '../EvmNetworkProvider';\nexport type { EvmWalletAccount } from '../EvmWalletAccount.types';\nexport type { EvmWalletProvider } from '../EvmWalletProvider.types';\nexport type {\n SerializedAuthorization,\n SignedSponsoredTransaction,\n SponsoredTransactionCall,\n SponsoredTransactionStatus,\n SponsoredTransactionStatusResult,\n} from '../gasless/gasless.types';\nexport { getEVMSponsoredTransactionStatus } from '../gasless/getEVMSponsoredTransactionStatus';\nexport { is7702DelegationActive } from '../gasless/is7702DelegationActive';\nexport { isEvmGasSponsorshipEnabled } from '../gasless/isEvmGasSponsorshipEnabled';\nexport { isEvmNetworkProvider } from '../isEvmNetworkProvider';\nexport { simulateEvmTransaction } from '../simulateEvmTransaction';\nexport type {\n EvmSimulationResult,\n EvmTransactionFeeData,\n EvmTransactionToSimulate,\n} from '../transactionSimulation.types';\nexport { calculateEvmTransactionFee } from '../utils/calculateEvmTransactionFee';\nexport { isEvmWalletAccount } from '../utils/isEvmWalletAccount';\nexport { relaySponsoredTransaction } from '../gasless/relaySponsoredTransaction';\nexport { sendSponsoredTransaction } from '../gasless/sendSponsoredTransaction';\nexport { sign7702Authorization } from '../gasless/sign7702Authorization';\nexport { signSponsoredTransaction } from '../gasless/signSponsoredTransaction';\nexport { waitForSponsoredTransaction } from '../gasless/waitForSponsoredTransaction';\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","names":["getDefaultClient","maxFeePerGas: bigint | undefined","maxPriorityFeePerGas: bigint | undefined","gasPrice: bigint | undefined","nativeAmount: bigint","feeData: EvmSimulationResult['feeData']","packageName","packageVersion"],"sources":["../src/gasless/activate7702Delegation/activate7702Delegation.ts","../src/addEvmExtension/addEvmExtension.ts","../src/errors/EvmGasSponsorshipNotEnabledError/EvmGasSponsorshipNotEnabledError.ts","../src/isEvmNetworkProvider/isEvmNetworkProvider.ts","../src/utils/calculateEvmTransactionFee/calculateEvmTransactionFee.ts","../src/simulateEvmTransaction/simulateEvmTransaction.ts","../src/exports/index.ts"],"sourcesContent":["import { getDefaultClient } from '@dynamic-labs-sdk/client';\nimport type { Hex } from 'viem';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\n\nimport type { EvmWalletAccount } from '../../EvmWalletAccount.types';\nimport { sendSponsoredTransaction } from '../sendSponsoredTransaction';\n\ntype Activate7702DelegationParams = {\n /** Pre-signed EIP-7702 authorization. If not provided, one will be signed automatically. */\n authorization?: SignAuthorizationReturnType;\n /** The EVM wallet account to activate delegation for. */\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Activates EIP-7702 delegation for a wallet by sending a sponsored\n * transaction that only contains the 7702 authorization.\n *\n * After activation, the wallet's delegation is persisted on-chain and\n * subsequent sponsored transactions no longer need to include the\n * authorization.\n *\n * @example\n * ```ts\n * const { transactionHash } = await activate7702Delegation({\n * walletAccount: evmAccount,\n * });\n * ```\n *\n * @param params.walletAccount - The EVM wallet account to activate delegation for.\n * @param [params.authorization] - Pre-signed authorization. If omitted, signs one automatically.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns An object containing the on-chain transaction hash.\n * @throws {SponsorTransactionError} If the relay returns a terminal failure or polling times out.\n * @see is7702DelegationActive\n * @see sign7702Authorization\n * @notInstrumented\n */\nexport const activate7702Delegation = async (\n { walletAccount, authorization }: Activate7702DelegationParams,\n client = getDefaultClient()\n): Promise<{ transactionHash: Hex }> =>\n sendSponsoredTransaction(\n { authorization, calls: [], walletAccount },\n client\n );\n","import { getDefaultClient } from '@dynamic-labs-sdk/client/core';\n\nimport { addEIP6963Extension } from '../eip6963/addEIP6963Extension';\nimport { addWaasEvmExtension } from '../waas/addWaasEvmExtension';\n\n/**\n * Adds the EVM extension to the Dynamic client.\n *\n * This is a convenience function that adds both the EIP-6963 extension\n * and the Dynamic WaaS EVM extension, enabling support for all EVM wallet types\n * including standard wallets and embedded wallets managed by Dynamic's infrastructure.\n *\n * @example\n * ```ts\n * const client = createDynamicClient({ environmentId: 'env-123' });\n * addEvmExtension(client);\n * ```\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns void\n * @see isEvmWalletAccount\n * @see isEvmNetworkProvider\n * @notInstrumented\n */\nexport const addEvmExtension = (client = getDefaultClient()): void => {\n addEIP6963Extension(client);\n addWaasEvmExtension(client);\n};\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class EvmGasSponsorshipNotEnabledError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'evm_gas_sponsorship_not_enabled_error',\n docsUrl: null,\n name: 'EvmGasSponsorshipNotEnabledError',\n shortMessage: 'EVM gas sponsorship is not enabled for this project',\n });\n }\n}\n","import type { NetworkProvider } from '@dynamic-labs-sdk/client';\n\nimport type { EvmNetworkProvider } from '../EvmNetworkProvider';\n\n/**\n * Type guard function to check if a network provider is an EVM network provider.\n *\n * @example\n * ```ts\n * if (isEvmNetworkProvider(networkProvider)) {\n * const publicClient = networkProvider.getPublicClient();\n * }\n * ```\n *\n * @param networkProvider - The network provider to check.\n * @returns True if the network provider is an EVM network provider, false otherwise.\n * @see isEvmWalletAccount\n * @see addEvmExtension\n * @notInstrumented\n */\nexport const isEvmNetworkProvider = (\n networkProvider: NetworkProvider\n): networkProvider is EvmNetworkProvider => networkProvider.chain === 'EVM';\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { FeeEstimationFailedError } from '@dynamic-labs-sdk/client';\nimport { formatEther } from 'viem';\n\nimport type {\n EvmTransactionFeeData,\n EvmTransactionToSimulate,\n} from '../../transactionSimulation.types';\nimport { createPublicClientFromNetworkData } from '../../viem/createPublicClientFromNetworkData';\n\ntype CalculateEvmTransactionFeeParams = {\n nativeTokenPriceUsd?: number;\n networkData: NetworkData;\n transaction: EvmTransactionToSimulate;\n};\n\n/**\n * Calculates the estimated fee for an EVM transaction.\n *\n * This function estimates gas usage and calculates the total transaction fee\n * using either legacy gas pricing or EIP-1559 pricing. The fee is returned\n * in both native units (wei) and human-readable format (ETH).\n *\n * @example\n * ```ts\n * const feeData = await calculateEvmTransactionFee({\n * transaction: { from: '0x...', to: '0x...', value: 1000000000000000000n, networkId: '1' },\n * networkData,\n * nativeTokenPriceUsd: 3500,\n * });\n * ```\n *\n * @param params.transaction - The transaction to estimate fees for.\n * @param params.networkData - Network configuration for RPC connection.\n * @param params.nativeTokenPriceUsd - Optional USD price of the native token for fee conversion.\n * @returns Fee data including gas estimates and human-readable amounts.\n * @throws {FeeEstimationFailedError} If gas estimation or fee retrieval fails.\n * @see simulateEvmTransaction\n * @see isEvmWalletAccount\n * @notInstrumented\n */\nexport const calculateEvmTransactionFee = async ({\n transaction,\n networkData,\n nativeTokenPriceUsd,\n}: CalculateEvmTransactionFeeParams): Promise<EvmTransactionFeeData> => {\n try {\n const publicClient = createPublicClientFromNetworkData({ networkData });\n\n // Estimate gas for the transaction\n const gasEstimate = await publicClient.estimateGas({\n account: transaction.from,\n data: transaction.data,\n to: transaction.to,\n value: transaction.value,\n });\n\n // Try to get EIP-1559 fees first, fallback to legacy gas price\n let maxFeePerGas: bigint | undefined;\n let maxPriorityFeePerGas: bigint | undefined;\n let gasPrice: bigint | undefined;\n let nativeAmount: bigint;\n\n try {\n const feeData = await publicClient.estimateFeesPerGas();\n maxFeePerGas = feeData.maxFeePerGas;\n maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;\n\n // Calculate fee using EIP-1559 pricing\n nativeAmount = gasEstimate * maxFeePerGas;\n } catch {\n // Fallback to legacy gas pricing\n gasPrice = await publicClient.getGasPrice();\n nativeAmount = gasEstimate * gasPrice;\n }\n\n // Format to human-readable ETH\n const humanReadableAmount = formatEther(nativeAmount);\n\n // Calculate USD amount if price data available\n const usdAmount = nativeTokenPriceUsd\n ? (Number(humanReadableAmount) * nativeTokenPriceUsd).toFixed(2)\n : undefined;\n\n return {\n gasEstimate,\n gasPrice,\n humanReadableAmount,\n maxFeePerGas,\n maxPriorityFeePerGas,\n nativeAmount,\n usdAmount,\n };\n } catch (error) {\n throw new FeeEstimationFailedError({\n cause: error instanceof Error ? error : undefined,\n message: 'Failed to estimate EVM transaction fee',\n });\n }\n};\n","import {\n FeeEstimationFailedError,\n InvalidParamError,\n SimulationFailedError,\n getDefaultClient,\n getNetworksData,\n} from '@dynamic-labs-sdk/client';\nimport { createApiClient, getCore } from '@dynamic-labs-sdk/client/core';\nimport type { SimulateEVMTransactionRequest } from '@dynamic-labs/sdk-api-core';\n\nimport type { EvmWalletAccount } from '../EvmWalletAccount.types';\nimport type {\n EvmSimulationResult,\n EvmTransactionToSimulate,\n} from '../transactionSimulation.types';\nimport { calculateEvmTransactionFee } from '../utils/calculateEvmTransactionFee';\nimport { isEvmWalletAccount } from '../utils/isEvmWalletAccount';\n\ntype SimulateEvmTransactionParams = {\n includeFees?: boolean;\n transaction: EvmTransactionToSimulate;\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Simulates an EVM transaction to preview its effects before execution.\n *\n * This function uses the Blockaid API to analyze the transaction and returns\n * information about asset transfers, security validation, and optionally fee estimates.\n * The simulation shows what will happen when the transaction is executed without\n * actually sending it to the blockchain.\n *\n * @example\n * ```ts\n * const result = await simulateEvmTransaction({\n * walletAccount: evmAccount,\n * transaction: { from: '0x...', to: '0x...', value: 1000000000000000000n, networkId: '1' },\n * includeFees: true,\n * });\n * ```\n *\n * @param params.walletAccount - The EVM wallet account that will sign the transaction.\n * @param params.transaction - The transaction to simulate, including network ID.\n * @param params.includeFees - Whether to calculate transaction fees (default: false).\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns Simulation result with asset diffs, security validation, and optional fee data.\n * @throws {InvalidParamError} If wallet account is not an EVM account or network ID is not configured.\n * @throws {SimulationFailedError} If the simulation API call fails.\n * @throws {FeeEstimationFailedError} If includeFees is true and fee calculation fails.\n * @see calculateEvmTransactionFee\n * @see isEvmWalletAccount\n * @notInstrumented\n */\nexport const simulateEvmTransaction = async (\n {\n walletAccount,\n transaction,\n includeFees = false,\n }: SimulateEvmTransactionParams,\n client = getDefaultClient()\n): Promise<EvmSimulationResult> => {\n // Validate wallet account type\n if (!isEvmWalletAccount(walletAccount)) {\n throw new InvalidParamError('Wallet account must be an EVM wallet account');\n }\n\n // Get network data for the specified network\n const networksData = getNetworksData(client);\n const networkData = networksData.find(\n (data) => data.networkId === transaction.networkId && data.chain === 'EVM'\n );\n\n if (!networkData) {\n throw new InvalidParamError(\n `Network with ID ${transaction.networkId} is not configured in project settings`\n );\n }\n\n try {\n // Create API client and call simulation endpoint\n const core = getCore(client);\n const apiClient = createApiClient({}, client);\n\n const simulateEVMTransactionRequest = {\n chainId: transaction.networkId,\n data: transaction.data || '0x',\n from: transaction.from,\n to: transaction.to,\n } as SimulateEVMTransactionRequest;\n\n if (transaction.value !== undefined) {\n simulateEVMTransactionRequest.value = transaction.value.toString();\n }\n\n const response = await apiClient.simulateEVMTransaction({\n environmentId: core.environmentId,\n simulateEVMTransactionRequest,\n });\n\n // Calculate fees if requested\n let feeData: EvmSimulationResult['feeData'];\n\n if (includeFees) {\n feeData = await calculateEvmTransactionFee({\n nativeTokenPriceUsd: response.priceData?.nativeTokenUsdPrice,\n networkData,\n transaction,\n });\n }\n\n // Map API response to simulation result\n return {\n counterparties: response.counterparties,\n feeData,\n inAssets: response.inAssets || [],\n outAssets: response.outAssets || [],\n priceData: response.priceData,\n showTotalFiat: response.showTotalFiat,\n validation: response.validation\n ? {\n description: response.validation.description,\n reason: response.validation.reason,\n result: response.validation.result as\n | 'benign'\n | 'warning'\n | 'malicious',\n }\n : undefined,\n };\n } catch (error) {\n // Re-throw FeeEstimationFailedError as-is\n if (error instanceof FeeEstimationFailedError) {\n throw error;\n }\n\n throw new SimulationFailedError({\n cause: error instanceof Error ? error : undefined,\n message: 'Failed to simulate EVM transaction',\n });\n }\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\nassertPackageVersion(packageName, packageVersion);\n\nexport { activate7702Delegation } from '../gasless/activate7702Delegation';\nexport { addEvmExtension } from '../addEvmExtension';\nexport { EvmGasSponsorshipNotEnabledError } from '../errors/EvmGasSponsorshipNotEnabledError';\nexport { RpcError } from '../errors/RpcError';\nexport { SponsorTransactionError } from '../errors/SponsorTransactionError';\nexport type { EvmNetworkProvider } from '../EvmNetworkProvider';\nexport type { EvmWalletAccount } from '../EvmWalletAccount.types';\nexport type { EvmWalletProvider } from '../EvmWalletProvider.types';\nexport type {\n SerializedAuthorization,\n SignedSponsoredTransaction,\n SponsoredTransactionCall,\n SponsoredTransactionStatus,\n SponsoredTransactionStatusResult,\n} from '../gasless/gasless.types';\nexport { getEVMSponsoredTransactionStatus } from '../gasless/getEVMSponsoredTransactionStatus';\nexport { is7702DelegationActive } from '../gasless/is7702DelegationActive';\nexport { isEvmGasSponsorshipEnabled } from '../gasless/isEvmGasSponsorshipEnabled';\nexport { isEvmNetworkProvider } from '../isEvmNetworkProvider';\nexport { simulateEvmTransaction } from '../simulateEvmTransaction';\nexport type {\n EvmSimulationResult,\n EvmTransactionFeeData,\n EvmTransactionToSimulate,\n} from '../transactionSimulation.types';\nexport { calculateEvmTransactionFee } from '../utils/calculateEvmTransactionFee';\nexport { isEvmWalletAccount } from '../utils/isEvmWalletAccount';\nexport { relaySponsoredTransaction } from '../gasless/relaySponsoredTransaction';\nexport { sendSponsoredTransaction } from '../gasless/sendSponsoredTransaction';\nexport { sign7702Authorization } from '../gasless/sign7702Authorization';\nexport { signSponsoredTransaction } from '../gasless/signSponsoredTransaction';\nexport { waitForSponsoredTransaction } from '../gasless/waitForSponsoredTransaction';\n"],"mappings":"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"}
|
package/dist/index.native.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { n as version, t as name } from "./package-
|
|
2
|
-
import { a as isEvmWalletAccount, c as sendSponsoredTransaction, d as relaySponsoredTransaction, f as signSponsoredTransaction, h as SponsorTransactionError, l as waitForSponsoredTransaction, m as is7702DelegationActive, p as sign7702Authorization, r as isEvmGasSponsorshipEnabled, s as RpcError, u as getEVMSponsoredTransactionStatus } from "./evmTransferAmount-
|
|
1
|
+
import { n as version, t as name } from "./package-YT_Fw3US.native.esm.js";
|
|
2
|
+
import { a as isEvmWalletAccount, c as sendSponsoredTransaction, d as relaySponsoredTransaction, f as signSponsoredTransaction, h as SponsorTransactionError, l as waitForSponsoredTransaction, m as is7702DelegationActive, p as sign7702Authorization, r as isEvmGasSponsorshipEnabled, s as RpcError, u as getEVMSponsoredTransactionStatus } from "./evmTransferAmount-D9Sygfbl.native.esm.js";
|
|
3
3
|
import { r as createPublicClientFromNetworkData } from "./createWalletClientForWalletAccount-CsfxMvvD.native.esm.js";
|
|
4
4
|
import { t as addEIP6963Extension } from "./addEIP6963Extension-h10IapXB.native.esm.js";
|
|
5
|
-
import { t as addWaasEvmExtension } from "./addWaasEvmExtension-
|
|
5
|
+
import { t as addWaasEvmExtension } from "./addWaasEvmExtension-V3vwSfx0.native.esm.js";
|
|
6
6
|
import { assertPackageVersion } from "@dynamic-labs-sdk/assert-package-version";
|
|
7
7
|
import { BaseError, FeeEstimationFailedError, InvalidParamError, SimulationFailedError, getDefaultClient, getNetworksData } from "@dynamic-labs-sdk/client";
|
|
8
8
|
import { createApiClient, getCore, getDefaultClient as getDefaultClient$1 } from "@dynamic-labs-sdk/client/core";
|
|
@@ -17,11 +17,20 @@ import { formatEther } from "viem";
|
|
|
17
17
|
* subsequent sponsored transactions no longer need to include the
|
|
18
18
|
* authorization.
|
|
19
19
|
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const { transactionHash } = await activate7702Delegation({
|
|
23
|
+
* walletAccount: evmAccount,
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
20
27
|
* @param params.walletAccount - The EVM wallet account to activate delegation for.
|
|
21
28
|
* @param [params.authorization] - Pre-signed authorization. If omitted, signs one automatically.
|
|
22
29
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
23
30
|
* @returns An object containing the on-chain transaction hash.
|
|
24
31
|
* @throws {SponsorTransactionError} If the relay returns a terminal failure or polling times out.
|
|
32
|
+
* @see is7702DelegationActive
|
|
33
|
+
* @see sign7702Authorization
|
|
25
34
|
* @notInstrumented
|
|
26
35
|
*/
|
|
27
36
|
const activate7702Delegation = async ({ walletAccount, authorization }, client = getDefaultClient()) => sendSponsoredTransaction({
|
|
@@ -39,7 +48,16 @@ const activate7702Delegation = async ({ walletAccount, authorization }, client =
|
|
|
39
48
|
* and the Dynamic WaaS EVM extension, enabling support for all EVM wallet types
|
|
40
49
|
* including standard wallets and embedded wallets managed by Dynamic's infrastructure.
|
|
41
50
|
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const client = createDynamicClient({ environmentId: 'env-123' });
|
|
54
|
+
* addEvmExtension(client);
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
42
57
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
58
|
+
* @returns void
|
|
59
|
+
* @see isEvmWalletAccount
|
|
60
|
+
* @see isEvmNetworkProvider
|
|
43
61
|
* @notInstrumented
|
|
44
62
|
*/
|
|
45
63
|
const addEvmExtension = (client = getDefaultClient$1()) => {
|
|
@@ -66,8 +84,17 @@ var EvmGasSponsorshipNotEnabledError = class extends BaseError {
|
|
|
66
84
|
/**
|
|
67
85
|
* Type guard function to check if a network provider is an EVM network provider.
|
|
68
86
|
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* if (isEvmNetworkProvider(networkProvider)) {
|
|
90
|
+
* const publicClient = networkProvider.getPublicClient();
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
69
94
|
* @param networkProvider - The network provider to check.
|
|
70
95
|
* @returns True if the network provider is an EVM network provider, false otherwise.
|
|
96
|
+
* @see isEvmWalletAccount
|
|
97
|
+
* @see addEvmExtension
|
|
71
98
|
* @notInstrumented
|
|
72
99
|
*/
|
|
73
100
|
const isEvmNetworkProvider = (networkProvider) => networkProvider.chain === "EVM";
|
|
@@ -81,11 +108,22 @@ const isEvmNetworkProvider = (networkProvider) => networkProvider.chain === "EVM
|
|
|
81
108
|
* using either legacy gas pricing or EIP-1559 pricing. The fee is returned
|
|
82
109
|
* in both native units (wei) and human-readable format (ETH).
|
|
83
110
|
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const feeData = await calculateEvmTransactionFee({
|
|
114
|
+
* transaction: { from: '0x...', to: '0x...', value: 1000000000000000000n, networkId: '1' },
|
|
115
|
+
* networkData,
|
|
116
|
+
* nativeTokenPriceUsd: 3500,
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
84
120
|
* @param params.transaction - The transaction to estimate fees for.
|
|
85
121
|
* @param params.networkData - Network configuration for RPC connection.
|
|
86
122
|
* @param params.nativeTokenPriceUsd - Optional USD price of the native token for fee conversion.
|
|
87
123
|
* @returns Fee data including gas estimates and human-readable amounts.
|
|
88
124
|
* @throws {FeeEstimationFailedError} If gas estimation or fee retrieval fails.
|
|
125
|
+
* @see simulateEvmTransaction
|
|
126
|
+
* @see isEvmWalletAccount
|
|
89
127
|
* @notInstrumented
|
|
90
128
|
*/
|
|
91
129
|
const calculateEvmTransactionFee = async ({ transaction, networkData, nativeTokenPriceUsd }) => {
|
|
@@ -139,6 +177,15 @@ const calculateEvmTransactionFee = async ({ transaction, networkData, nativeToke
|
|
|
139
177
|
* The simulation shows what will happen when the transaction is executed without
|
|
140
178
|
* actually sending it to the blockchain.
|
|
141
179
|
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* const result = await simulateEvmTransaction({
|
|
183
|
+
* walletAccount: evmAccount,
|
|
184
|
+
* transaction: { from: '0x...', to: '0x...', value: 1000000000000000000n, networkId: '1' },
|
|
185
|
+
* includeFees: true,
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
142
189
|
* @param params.walletAccount - The EVM wallet account that will sign the transaction.
|
|
143
190
|
* @param params.transaction - The transaction to simulate, including network ID.
|
|
144
191
|
* @param params.includeFees - Whether to calculate transaction fees (default: false).
|
|
@@ -147,6 +194,8 @@ const calculateEvmTransactionFee = async ({ transaction, networkData, nativeToke
|
|
|
147
194
|
* @throws {InvalidParamError} If wallet account is not an EVM account or network ID is not configured.
|
|
148
195
|
* @throws {SimulationFailedError} If the simulation API call fails.
|
|
149
196
|
* @throws {FeeEstimationFailedError} If includeFees is true and fee calculation fails.
|
|
197
|
+
* @see calculateEvmTransactionFee
|
|
198
|
+
* @see isEvmWalletAccount
|
|
150
199
|
* @notInstrumented
|
|
151
200
|
*/
|
|
152
201
|
const simulateEvmTransaction = async ({ walletAccount, transaction, includeFees = false }, client = getDefaultClient()) => {
|