@dynamic-labs-sdk/evm 1.0.0 → 1.2.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.
Files changed (111) hide show
  1. package/dist/{addEIP6963Extension-6WKcoc6j.cjs → addEIP6963Extension-BrxoI3fh.cjs} +3 -3
  2. package/dist/{addEIP6963Extension-6WKcoc6j.cjs.map → addEIP6963Extension-BrxoI3fh.cjs.map} +1 -1
  3. package/dist/{addEIP6963Extension-1jrwxkRl.esm.js → addEIP6963Extension-CTfW3lKP.esm.js} +3 -3
  4. package/dist/{addEIP6963Extension-1jrwxkRl.esm.js.map → addEIP6963Extension-CTfW3lKP.esm.js.map} +1 -1
  5. package/dist/{addEIP6963Extension-J6SledVr.native.esm.js → addEIP6963Extension-C_IKf5DD.native.esm.js} +1 -1
  6. package/dist/{addEIP6963Extension-J6SledVr.native.esm.js.map → addEIP6963Extension-C_IKf5DD.native.esm.js.map} +1 -1
  7. package/dist/{addWaasEvmExtension-BPKFUV3U.cjs → addWaasEvmExtension-CTYf_o8f.cjs} +5 -5
  8. package/dist/{addWaasEvmExtension-BPKFUV3U.cjs.map → addWaasEvmExtension-CTYf_o8f.cjs.map} +1 -1
  9. package/dist/{addWaasEvmExtension-CctMlyNt.esm.js → addWaasEvmExtension-DnfMMvBS.esm.js} +7 -7
  10. package/dist/addWaasEvmExtension-DnfMMvBS.esm.js.map +1 -0
  11. package/dist/{addWaasEvmExtension-U4DO_WKC.native.esm.js → addWaasEvmExtension-L8dUNmj8.native.esm.js} +8 -8
  12. package/dist/addWaasEvmExtension-L8dUNmj8.native.esm.js.map +1 -0
  13. package/dist/baseAccount.cjs +4 -4
  14. package/dist/baseAccount.esm.js +6 -6
  15. package/dist/baseAccount.esm.js.map +1 -1
  16. package/dist/baseAccount.native.esm.js +7 -7
  17. package/dist/baseAccount.native.esm.js.map +1 -1
  18. package/dist/{createWalletClientForWalletAccount-V4CfRjd4.native.esm.js → createWalletClientForWalletAccount-BotF25Kn.native.esm.js} +3 -3
  19. package/dist/createWalletClientForWalletAccount-BotF25Kn.native.esm.js.map +1 -0
  20. package/dist/{createWalletClientForWalletAccount-2HJ_yeO9.esm.js → createWalletClientForWalletAccount-CMD5kLVs.esm.js} +4 -4
  21. package/dist/createWalletClientForWalletAccount-CMD5kLVs.esm.js.map +1 -0
  22. package/dist/{createWalletClientForWalletAccount-BKMV0WzZ.cjs → createWalletClientForWalletAccount-DBAhi3L-.cjs} +3 -3
  23. package/dist/{createWalletClientForWalletAccount-BKMV0WzZ.cjs.map → createWalletClientForWalletAccount-DBAhi3L-.cjs.map} +1 -1
  24. package/dist/{createWalletProviderFromEIP1193Provider-CBbP9cb2.cjs → createWalletProviderFromEIP1193Provider-B_XDSRZ9.cjs} +4 -4
  25. package/dist/{createWalletProviderFromEIP1193Provider-CBbP9cb2.cjs.map → createWalletProviderFromEIP1193Provider-B_XDSRZ9.cjs.map} +1 -1
  26. package/dist/{createWalletProviderFromEIP1193Provider-DnPhiRmj.native.esm.js → createWalletProviderFromEIP1193Provider-CWWLWjod.native.esm.js} +4 -4
  27. package/dist/{createWalletProviderFromEIP1193Provider-DnPhiRmj.native.esm.js.map → createWalletProviderFromEIP1193Provider-CWWLWjod.native.esm.js.map} +1 -1
  28. package/dist/{createWalletProviderFromEIP1193Provider-BdZcBFWx.esm.js → createWalletProviderFromEIP1193Provider-ChSmbI-a.esm.js} +4 -4
  29. package/dist/{createWalletProviderFromEIP1193Provider-BdZcBFWx.esm.js.map → createWalletProviderFromEIP1193Provider-ChSmbI-a.esm.js.map} +1 -1
  30. package/dist/eip6963.cjs +4 -4
  31. package/dist/eip6963.esm.js +4 -4
  32. package/dist/eip6963.native.esm.js +2 -2
  33. package/dist/{evmTransferAmount-B__79nVn.native.esm.js → evmTransferAmount-BY0rW4dg.native.esm.js} +3 -3
  34. package/dist/{evmTransferAmount-B__79nVn.native.esm.js.map → evmTransferAmount-BY0rW4dg.native.esm.js.map} +1 -1
  35. package/dist/{evmTransferAmount-D1PZCZks.esm.js → evmTransferAmount-C4vCjuss.esm.js} +3 -3
  36. package/dist/{evmTransferAmount-D1PZCZks.esm.js.map → evmTransferAmount-C4vCjuss.esm.js.map} +1 -1
  37. package/dist/{evmTransferAmount-BA5VR2bh.cjs → evmTransferAmount-DJCA1p9e.cjs} +3 -3
  38. package/dist/{evmTransferAmount-BA5VR2bh.cjs.map → evmTransferAmount-DJCA1p9e.cjs.map} +1 -1
  39. package/dist/exports/index.d.ts +3 -0
  40. package/dist/exports/index.d.ts.map +1 -1
  41. package/dist/gasless/activate7702Delegation/activate7702Delegation.d.ts +29 -0
  42. package/dist/gasless/activate7702Delegation/activate7702Delegation.d.ts.map +1 -0
  43. package/dist/gasless/activate7702Delegation/index.d.ts +2 -0
  44. package/dist/gasless/activate7702Delegation/index.d.ts.map +1 -0
  45. package/dist/gasless/constants.d.ts +0 -2
  46. package/dist/gasless/constants.d.ts.map +1 -1
  47. package/dist/gasless/create7702DelegationRegistry/create7702DelegationRegistry.d.ts +22 -0
  48. package/dist/gasless/create7702DelegationRegistry/create7702DelegationRegistry.d.ts.map +1 -0
  49. package/dist/gasless/create7702DelegationRegistry/index.d.ts +3 -0
  50. package/dist/gasless/create7702DelegationRegistry/index.d.ts.map +1 -0
  51. package/dist/gasless/gasless.types.d.ts +6 -4
  52. package/dist/gasless/gasless.types.d.ts.map +1 -1
  53. package/dist/gasless/get7702DelegationRegistry/get7702DelegationRegistry.d.ts +7 -0
  54. package/dist/gasless/get7702DelegationRegistry/get7702DelegationRegistry.d.ts.map +1 -0
  55. package/dist/gasless/get7702DelegationRegistry/index.d.ts +2 -0
  56. package/dist/gasless/get7702DelegationRegistry/index.d.ts.map +1 -0
  57. package/dist/gasless/getAvailableEvmGaslessRelayer/getAvailableEvmGaslessRelayer.d.ts +28 -0
  58. package/dist/gasless/getAvailableEvmGaslessRelayer/getAvailableEvmGaslessRelayer.d.ts.map +1 -0
  59. package/dist/gasless/getAvailableEvmGaslessRelayer/index.d.ts +2 -0
  60. package/dist/gasless/getAvailableEvmGaslessRelayer/index.d.ts.map +1 -0
  61. package/dist/gasless/is7702DelegationActive/index.d.ts +2 -0
  62. package/dist/gasless/is7702DelegationActive/index.d.ts.map +1 -0
  63. package/dist/gasless/is7702DelegationActive/is7702DelegationActive.d.ts +18 -0
  64. package/dist/gasless/is7702DelegationActive/is7702DelegationActive.d.ts.map +1 -0
  65. package/dist/gasless/relaySponsoredTransaction/relaySponsoredTransaction.d.ts +3 -1
  66. package/dist/gasless/relaySponsoredTransaction/relaySponsoredTransaction.d.ts.map +1 -1
  67. package/dist/gasless/resolveAuthorization/index.d.ts +2 -0
  68. package/dist/gasless/resolveAuthorization/index.d.ts.map +1 -0
  69. package/dist/gasless/resolveAuthorization/resolveAuthorization.d.ts +20 -0
  70. package/dist/gasless/resolveAuthorization/resolveAuthorization.d.ts.map +1 -0
  71. package/dist/gasless/sendSponsoredTransaction/sendSponsoredTransaction.d.ts +6 -4
  72. package/dist/gasless/sendSponsoredTransaction/sendSponsoredTransaction.d.ts.map +1 -1
  73. package/dist/gasless/sign7702Authorization/index.d.ts +2 -0
  74. package/dist/gasless/sign7702Authorization/index.d.ts.map +1 -0
  75. package/dist/gasless/sign7702Authorization/sign7702Authorization.d.ts +23 -0
  76. package/dist/gasless/sign7702Authorization/sign7702Authorization.d.ts.map +1 -0
  77. package/dist/gasless/signSponsoredTransaction/signSponsoredTransaction.d.ts +12 -6
  78. package/dist/gasless/signSponsoredTransaction/signSponsoredTransaction.d.ts.map +1 -1
  79. package/dist/gasless/waitForSponsoredTransaction/waitForSponsoredTransaction.d.ts +2 -6
  80. package/dist/gasless/waitForSponsoredTransaction/waitForSponsoredTransaction.d.ts.map +1 -1
  81. package/dist/index.cjs +459 -277
  82. package/dist/index.cjs.map +1 -1
  83. package/dist/index.esm.js +435 -256
  84. package/dist/index.esm.js.map +1 -1
  85. package/dist/index.native.esm.js +435 -256
  86. package/dist/index.native.esm.js.map +1 -1
  87. package/dist/{package-BxZgKgaF.native.esm.js → package-AXj9tSuC.native.esm.js} +2 -2
  88. package/dist/package-AXj9tSuC.native.esm.js.map +1 -0
  89. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  90. package/dist/viem.cjs +1 -1
  91. package/dist/viem.esm.js +1 -1
  92. package/dist/viem.native.esm.js +2 -2
  93. package/dist/waas.cjs +3 -3
  94. package/dist/waas.esm.js +3 -3
  95. package/dist/waas.native.esm.js +4 -4
  96. package/dist/walletConnect/createWalletProviderFromEIP155Session/createWalletProviderFromEIP155Session.d.ts.map +1 -1
  97. package/dist/walletConnect.cjs +10 -4
  98. package/dist/walletConnect.cjs.map +1 -1
  99. package/dist/walletConnect.esm.js +15 -9
  100. package/dist/walletConnect.esm.js.map +1 -1
  101. package/dist/walletConnect.native.esm.js +16 -10
  102. package/dist/walletConnect.native.esm.js.map +1 -1
  103. package/dist/windowInjected.cjs +3 -3
  104. package/dist/windowInjected.esm.js +3 -3
  105. package/dist/windowInjected.native.esm.js +4 -4
  106. package/package.json +5 -5
  107. package/dist/addWaasEvmExtension-CctMlyNt.esm.js.map +0 -1
  108. package/dist/addWaasEvmExtension-U4DO_WKC.native.esm.js.map +0 -1
  109. package/dist/createWalletClientForWalletAccount-2HJ_yeO9.esm.js.map +0 -1
  110. package/dist/createWalletClientForWalletAccount-V4CfRjd4.native.esm.js.map +0 -1
  111. package/dist/package-BxZgKgaF.native.esm.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,44 +1,14 @@
1
- const require_createWalletClientForWalletAccount = require('./createWalletClientForWalletAccount-BKMV0WzZ.cjs');
2
- const require_evmTransferAmount = require('./evmTransferAmount-BA5VR2bh.cjs');
3
- require('./createWalletProviderFromEIP1193Provider-CBbP9cb2.cjs');
4
- const require_addEIP6963Extension = require('./addEIP6963Extension-6WKcoc6j.cjs');
5
- const require_addWaasEvmExtension = require('./addWaasEvmExtension-BPKFUV3U.cjs');
1
+ const require_createWalletClientForWalletAccount = require('./createWalletClientForWalletAccount-DBAhi3L-.cjs');
2
+ const require_evmTransferAmount = require('./evmTransferAmount-DJCA1p9e.cjs');
3
+ require('./createWalletProviderFromEIP1193Provider-B_XDSRZ9.cjs');
4
+ const require_addEIP6963Extension = require('./addEIP6963Extension-BrxoI3fh.cjs');
5
+ const require_addWaasEvmExtension = require('./addWaasEvmExtension-CTYf_o8f.cjs');
6
6
  let _dynamic_labs_sdk_assert_package_version = require("@dynamic-labs-sdk/assert-package-version");
7
- let _dynamic_labs_sdk_client_core = require("@dynamic-labs-sdk/client/core");
8
7
  let _dynamic_labs_sdk_client = require("@dynamic-labs-sdk/client");
8
+ let _dynamic_labs_sdk_client_core = require("@dynamic-labs-sdk/client/core");
9
9
  let viem = require("viem");
10
+ let viem_actions = require("viem/actions");
10
11
 
11
- //#region src/addEvmExtension/addEvmExtension.ts
12
- /**
13
- * Adds the EVM extension to the Dynamic client.
14
- *
15
- * This is a convenience function that adds both the EIP-6963 extension
16
- * and the Dynamic WaaS EVM extension, enabling support for all EVM wallet types
17
- * including standard wallets and embedded wallets managed by Dynamic's infrastructure.
18
- *
19
- * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
20
- * @not-instrumented
21
- */
22
- const addEvmExtension = (client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
23
- require_addEIP6963Extension.addEIP6963Extension(client);
24
- require_addWaasEvmExtension.addWaasEvmExtension(client);
25
- };
26
-
27
- //#endregion
28
- //#region src/errors/EvmGasSponsorshipNotEnabledError/EvmGasSponsorshipNotEnabledError.ts
29
- var EvmGasSponsorshipNotEnabledError = class extends _dynamic_labs_sdk_client.BaseError {
30
- constructor() {
31
- super({
32
- cause: null,
33
- code: "evm_gas_sponsorship_not_enabled_error",
34
- docsUrl: null,
35
- name: "EvmGasSponsorshipNotEnabledError",
36
- shortMessage: "EVM gas sponsorship is not enabled for this project"
37
- });
38
- }
39
- };
40
-
41
- //#endregion
42
12
  //#region src/errors/SponsorTransactionError/SponsorTransactionError.ts
43
13
  var SponsorTransactionError = class extends _dynamic_labs_sdk_client.BaseError {
44
14
  constructor(cause, details) {
@@ -53,197 +23,14 @@ var SponsorTransactionError = class extends _dynamic_labs_sdk_client.BaseError {
53
23
  }
54
24
  };
55
25
 
56
- //#endregion
57
- //#region src/gasless/getEVMSponsoredTransactionStatus/getEVMSponsoredTransactionStatus.ts
58
- /**
59
- * Fetches the current relay state for a sponsored EVM transaction.
60
- *
61
- * Returns the lifecycle status, the on-chain transaction hash (when the relay
62
- * has broadcast it), and any terminal-failure error message. Use this as the
63
- * building block for custom polling flows; for the common "wait until done"
64
- * case prefer `waitForSponsoredTransaction`.
65
- *
66
- * @param params.requestId - The request ID returned when the transaction was relayed.
67
- * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
68
- * @returns The current status, optional transaction hash, and optional error message.
69
- * @throws {SponsorTransactionError} If the API call fails.
70
- * @not-instrumented
71
- */
72
- const getEVMSponsoredTransactionStatus = async ({ requestId }, client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
73
- const core = (0, _dynamic_labs_sdk_client_core.getCore)(client);
74
- const apiClient = (0, _dynamic_labs_sdk_client_core.createApiClient)({}, client);
75
- let data;
76
- try {
77
- data = await apiClient.getEVMSponsoredTransactionStatus({
78
- environmentId: core.environmentId,
79
- requestId
80
- });
81
- } catch (error) {
82
- throw new SponsorTransactionError(error instanceof Error ? error : null);
83
- }
84
- return {
85
- errorMessage: data.errorMessage,
86
- status: data.status,
87
- transactionHash: data.transactionHash
88
- };
89
- };
90
-
91
- //#endregion
92
- //#region src/gasless/isEvmGasSponsorshipEnabled/isEvmGasSponsorshipEnabled.ts
93
- /**
94
- * Checks if EVM gas sponsorship is enabled for the current project.
95
- *
96
- * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
97
- * @returns True if EVM gas sponsorship is enabled, false otherwise.
98
- * @not-instrumented
99
- */
100
- const isEvmGasSponsorshipEnabled = (client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => {
101
- (0, _dynamic_labs_sdk_client_core.assertDefined)(client.projectSettings, "Project settings are not defined");
102
- return client.projectSettings.sdk.embeddedWallets?.evmGasSponsorshipEnabled ?? false;
103
- };
104
-
105
- //#endregion
106
- //#region src/isEvmNetworkProvider/isEvmNetworkProvider.ts
107
- /**
108
- * Type guard function to check if a network provider is an EVM network provider.
109
- *
110
- * @param networkProvider - The network provider to check.
111
- * @returns True if the network provider is an EVM network provider, false otherwise.
112
- * @not-instrumented
113
- */
114
- const isEvmNetworkProvider = (networkProvider) => networkProvider.chain === "EVM";
115
-
116
- //#endregion
117
- //#region src/utils/calculateEvmTransactionFee/calculateEvmTransactionFee.ts
118
- /**
119
- * Calculates the estimated fee for an EVM transaction.
120
- *
121
- * This function estimates gas usage and calculates the total transaction fee
122
- * using either legacy gas pricing or EIP-1559 pricing. The fee is returned
123
- * in both native units (wei) and human-readable format (ETH).
124
- *
125
- * @param params.transaction - The transaction to estimate fees for.
126
- * @param params.networkData - Network configuration for RPC connection.
127
- * @param params.nativeTokenPriceUsd - Optional USD price of the native token for fee conversion.
128
- * @returns Fee data including gas estimates and human-readable amounts.
129
- * @throws {FeeEstimationFailedError} If gas estimation or fee retrieval fails.
130
- * @not-instrumented
131
- */
132
- const calculateEvmTransactionFee = async ({ transaction, networkData, nativeTokenPriceUsd }) => {
133
- try {
134
- const publicClient = require_createWalletClientForWalletAccount.createPublicClientFromNetworkData({ networkData });
135
- const gasEstimate = await publicClient.estimateGas({
136
- account: transaction.from,
137
- data: transaction.data,
138
- to: transaction.to,
139
- value: transaction.value
140
- });
141
- let maxFeePerGas;
142
- let maxPriorityFeePerGas;
143
- let gasPrice;
144
- let nativeAmount;
145
- try {
146
- const feeData = await publicClient.estimateFeesPerGas();
147
- maxFeePerGas = feeData.maxFeePerGas;
148
- maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
149
- nativeAmount = gasEstimate * maxFeePerGas;
150
- } catch {
151
- gasPrice = await publicClient.getGasPrice();
152
- nativeAmount = gasEstimate * gasPrice;
153
- }
154
- const humanReadableAmount = (0, viem.formatEther)(nativeAmount);
155
- const usdAmount = nativeTokenPriceUsd ? (Number(humanReadableAmount) * nativeTokenPriceUsd).toFixed(2) : void 0;
156
- return {
157
- gasEstimate,
158
- gasPrice,
159
- humanReadableAmount,
160
- maxFeePerGas,
161
- maxPriorityFeePerGas,
162
- nativeAmount,
163
- usdAmount
164
- };
165
- } catch (error) {
166
- throw new _dynamic_labs_sdk_client.FeeEstimationFailedError({
167
- cause: error instanceof Error ? error : void 0,
168
- message: "Failed to estimate EVM transaction fee"
169
- });
170
- }
171
- };
172
-
173
- //#endregion
174
- //#region src/simulateEvmTransaction/simulateEvmTransaction.ts
175
- /**
176
- * Simulates an EVM transaction to preview its effects before execution.
177
- *
178
- * This function uses the Blockaid API to analyze the transaction and returns
179
- * information about asset transfers, security validation, and optionally fee estimates.
180
- * The simulation shows what will happen when the transaction is executed without
181
- * actually sending it to the blockchain.
182
- *
183
- * @param params.walletAccount - The EVM wallet account that will sign the transaction.
184
- * @param params.transaction - The transaction to simulate, including network ID.
185
- * @param params.includeFees - Whether to calculate transaction fees (default: false).
186
- * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
187
- * @returns Simulation result with asset diffs, security validation, and optional fee data.
188
- * @throws {InvalidParamError} If wallet account is not an EVM account or network ID is not configured.
189
- * @throws {SimulationFailedError} If the simulation API call fails.
190
- * @throws {FeeEstimationFailedError} If includeFees is true and fee calculation fails.
191
- * @not-instrumented
192
- */
193
- const simulateEvmTransaction = async ({ walletAccount, transaction, includeFees = false }, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => {
194
- if (!require_evmTransferAmount.isEvmWalletAccount(walletAccount)) throw new _dynamic_labs_sdk_client.InvalidParamError("Wallet account must be an EVM wallet account");
195
- const networkData = (0, _dynamic_labs_sdk_client.getNetworksData)(client).find((data) => data.networkId === transaction.networkId && data.chain === "EVM");
196
- if (!networkData) throw new _dynamic_labs_sdk_client.InvalidParamError(`Network with ID ${transaction.networkId} is not configured in project settings`);
197
- try {
198
- const core = (0, _dynamic_labs_sdk_client_core.getCore)(client);
199
- const apiClient = (0, _dynamic_labs_sdk_client_core.createApiClient)({}, client);
200
- const simulateEVMTransactionRequest = {
201
- chainId: transaction.networkId,
202
- data: transaction.data || "0x",
203
- from: transaction.from,
204
- to: transaction.to
205
- };
206
- if (transaction.value !== void 0) simulateEVMTransactionRequest.value = transaction.value.toString();
207
- const response = await apiClient.simulateEVMTransaction({
208
- environmentId: core.environmentId,
209
- simulateEVMTransactionRequest
210
- });
211
- let feeData;
212
- if (includeFees) feeData = await calculateEvmTransactionFee({
213
- nativeTokenPriceUsd: response.priceData?.nativeTokenUsdPrice,
214
- networkData,
215
- transaction
216
- });
217
- return {
218
- counterparties: response.counterparties,
219
- feeData,
220
- inAssets: response.inAssets || [],
221
- outAssets: response.outAssets || [],
222
- priceData: response.priceData,
223
- showTotalFiat: response.showTotalFiat,
224
- validation: response.validation ? {
225
- description: response.validation.description,
226
- reason: response.validation.reason,
227
- result: response.validation.result
228
- } : void 0
229
- };
230
- } catch (error) {
231
- if (error instanceof _dynamic_labs_sdk_client.FeeEstimationFailedError) throw error;
232
- throw new _dynamic_labs_sdk_client.SimulationFailedError({
233
- cause: error instanceof Error ? error : void 0,
234
- message: "Failed to simulate EVM transaction"
235
- });
236
- }
237
- };
238
-
239
26
  //#endregion
240
27
  //#region src/gasless/constants.ts
241
28
  /** The Fireblocks Universal Gasless Delegate (UGD) contract address used for EIP-7702 delegation. */
242
29
  const DELEGATION_CONTRACT_ADDRESS = "0x0000Fb7702036ff9f76044a501ac1aA74cbab16b";
243
- /** The ERC-7821 Forwarder contract address that relays calls to the delegated wallet. */
244
- const RELAYER_CONTRACT_ADDRESS = "0x0fb50CBAd1B82005628bc8aF0f7A6D81Bf74cDCe";
245
30
  /** Default sponsored transaction validity duration in seconds (10 minutes). */
246
31
  const DEFAULT_VALID_FOR_SECONDS = 600;
32
+ /** EIP-7702 delegation code prefix used to identify delegated accounts. */
33
+ const DELEGATION_CODE_PREFIX = "0xef0100";
247
34
  /** ERC-7579 batch call with opData and auth mode identifier. */
248
35
  const BATCH_CALL_OPDATA_AUTH_MODE = "0x0100000000007821000100000000000000000000000000000000000000000000";
249
36
  /** EIP-712 typed data types for UGD AuthorizedExecutions signing. */
@@ -308,40 +95,197 @@ const UGD_ABI = [{
308
95
  * @returns A random bigint nonce.
309
96
  * @not-instrumented
310
97
  */
311
- const generateRandomNonce = () => {
312
- const bytes = new Uint8Array(32);
313
- crypto.getRandomValues(bytes);
314
- return bytes.reduce((acc, byte) => acc << 8n | BigInt(byte), 0n);
98
+ const generateRandomNonce = () => {
99
+ const bytes = new Uint8Array(32);
100
+ crypto.getRandomValues(bytes);
101
+ return bytes.reduce((acc, byte) => acc << 8n | BigInt(byte), 0n);
102
+ };
103
+
104
+ //#endregion
105
+ //#region src/gasless/generateIntentNonce/generateIntentNonce.ts
106
+ /**
107
+ * Generates a random bitmap nonce for UGD AuthorizedExecutions signing.
108
+ *
109
+ * Uses crypto.getRandomValues() for 256-bit randomness. Validates against
110
+ * the on-chain isNonceUsed check as a safety measure, although collision
111
+ * is essentially impossible with 256-bit random values.
112
+ *
113
+ * @param params.walletAccount - The wallet account whose delegation contract is checked.
114
+ * @param [client] - The Dynamic client instance.
115
+ * @returns A unique bigint nonce for the EIP-712 intent.
116
+ * @not-instrumented
117
+ */
118
+ const generateIntentNonce = async ({ walletAccount }, client) => {
119
+ const nonce = generateRandomNonce();
120
+ const { networkData } = await (0, _dynamic_labs_sdk_client.getActiveNetworkData)({ walletAccount }, client);
121
+ (0, _dynamic_labs_sdk_client_core.assertDefined)(networkData, `No network data found for wallet account ${walletAccount.address}`);
122
+ const publicClient = require_createWalletClientForWalletAccount.createPublicClientFromNetworkData({ networkData });
123
+ try {
124
+ if (await publicClient.readContract({
125
+ abi: UGD_ABI,
126
+ address: walletAccount.address,
127
+ args: [nonce],
128
+ functionName: "isNonceUsed"
129
+ })) return generateRandomNonce();
130
+ } catch {}
131
+ return nonce;
132
+ };
133
+
134
+ //#endregion
135
+ //#region src/gasless/getAvailableEvmGaslessRelayer/getAvailableEvmGaslessRelayer.ts
136
+ /**
137
+ * Fetches the relayer address to embed in the EIP-712 sponsored-transaction
138
+ * intent for the given chain.
139
+ *
140
+ * The returned address is owned by the project's relay backend and is the
141
+ * eventual `from` of the on-chain broadcast. It must be set as the `relayer`
142
+ * field of the EIP-712 intent before signing — the on-chain delegate validates
143
+ * the signature against this address.
144
+ *
145
+ * @param params.chainId - The EVM chain ID the sponsored transaction targets.
146
+ * @param client - The Dynamic client instance.
147
+ * @returns The relayer address to embed in the EIP-712 intent.
148
+ * @throws {SponsorTransactionError} If the API call fails or returns no relayer address.
149
+ * @not-instrumented
150
+ */
151
+ const getAvailableEvmGaslessRelayer = async ({ chainId }, client) => {
152
+ const core = (0, _dynamic_labs_sdk_client_core.getCore)(client);
153
+ const apiClient = (0, _dynamic_labs_sdk_client_core.createApiClient)({}, client);
154
+ let data;
155
+ try {
156
+ data = await apiClient.getAvailableEVMGaslessRelayer({
157
+ chainId,
158
+ environmentId: core.environmentId
159
+ });
160
+ } catch (error) {
161
+ throw new SponsorTransactionError(error instanceof Error ? error : null);
162
+ }
163
+ if (!data.relayerAddress) throw new SponsorTransactionError();
164
+ return { relayerAddress: data.relayerAddress };
165
+ };
166
+
167
+ //#endregion
168
+ //#region src/gasless/create7702DelegationRegistry/create7702DelegationRegistry.ts
169
+ /**
170
+ * Creates an in-memory registry that tracks which wallet+chain combinations
171
+ * have active EIP-7702 delegation. Only active delegations are cached —
172
+ * a missing entry means the status is unknown and should be checked via RPC.
173
+ *
174
+ * @not-instrumented
175
+ */
176
+ const create7702DelegationRegistry = () => {
177
+ const delegated = /* @__PURE__ */ new Map();
178
+ const buildKey = ({ chainId, walletAddress }) => `${walletAddress.toLowerCase()}:${chainId}`;
179
+ return {
180
+ isDelegated: (params) => delegated.has(buildKey(params)),
181
+ markDelegated: (params) => {
182
+ delegated.set(buildKey(params), true);
183
+ }
184
+ };
185
+ };
186
+
187
+ //#endregion
188
+ //#region src/gasless/get7702DelegationRegistry/get7702DelegationRegistry.ts
189
+ /**
190
+ * Returns the per-client EIP-7702 delegation registry, creating it on first access.
191
+ *
192
+ * @not-instrumented
193
+ */
194
+ const get7702DelegationRegistry = (0, _dynamic_labs_sdk_client_core.createRuntimeServiceAccessKey)("evm-7702-delegation-registry", () => create7702DelegationRegistry());
195
+
196
+ //#endregion
197
+ //#region src/gasless/is7702DelegationActive/is7702DelegationActive.ts
198
+ /**
199
+ * Checks whether EIP-7702 delegation to the Dynamic gasless contract is active
200
+ * for the given wallet account on its current network.
201
+ *
202
+ * Results are cached per wallet+chain in an in-memory registry
203
+ *
204
+ * @param params.walletAccount - The EVM wallet account to check delegation status for.
205
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
206
+ * @returns True if the wallet has an active delegation to the gasless contract.
207
+ * @not-instrumented
208
+ */
209
+ const is7702DelegationActive = async ({ walletAccount }, client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
210
+ const { networkData } = await (0, _dynamic_labs_sdk_client.getActiveNetworkData)({ walletAccount }, client);
211
+ (0, _dynamic_labs_sdk_client_core.assertDefined)(networkData, `No network data found for wallet account ${walletAccount.address}`);
212
+ const chainId = require_createWalletClientForWalletAccount.mapNetworkDataToViemChain(networkData).id;
213
+ const registry = get7702DelegationRegistry(client);
214
+ if (registry.isDelegated({
215
+ chainId,
216
+ walletAddress: walletAccount.address
217
+ })) return true;
218
+ const bytecode = await require_createWalletClientForWalletAccount.createPublicClientFromNetworkData({ networkData }).getCode({ address: walletAccount.address });
219
+ if (!bytecode) return false;
220
+ const expectedPrefix = DELEGATION_CODE_PREFIX + DELEGATION_CONTRACT_ADDRESS.slice(2).toLowerCase();
221
+ const isActive = bytecode.toLowerCase().startsWith(expectedPrefix);
222
+ if (isActive) registry.markDelegated({
223
+ chainId,
224
+ walletAddress: walletAccount.address
225
+ });
226
+ return isActive;
227
+ };
228
+
229
+ //#endregion
230
+ //#region src/gasless/resolveChainId/resolveChainId.ts
231
+ /**
232
+ * Resolves a chain ID from either an explicit override or the wallet's active network.
233
+ *
234
+ * @param params.chainId - Explicit chain ID override.
235
+ * @param params.walletAccount - The wallet account to resolve the chain from.
236
+ * @param client - The Dynamic client instance.
237
+ * @returns The resolved chain ID.
238
+ * @not-instrumented
239
+ */
240
+ const resolveChainId = async ({ chainId, walletAccount }, client) => {
241
+ if (chainId !== void 0) return chainId;
242
+ const { networkData } = await (0, _dynamic_labs_sdk_client.getActiveNetworkData)({ walletAccount }, client);
243
+ (0, _dynamic_labs_sdk_client_core.assertDefined)(networkData, `No network data found for wallet account ${walletAccount.address}`);
244
+ return require_createWalletClientForWalletAccount.mapNetworkDataToViemChain(networkData).id;
245
+ };
246
+
247
+ //#endregion
248
+ //#region src/gasless/sign7702Authorization/sign7702Authorization.ts
249
+ /**
250
+ * Signs an EIP-7702 authorization to delegate the wallet to the Dynamic
251
+ * gasless delegation contract.
252
+ *
253
+ * The signed authorization can be included in a sponsored transaction to
254
+ * activate the delegation on-chain. If no chainId is provided, the wallet's
255
+ * active network chain ID is used.
256
+ *
257
+ * @param params.walletAccount - The EVM wallet account to sign the authorization for.
258
+ * @param [params.chainId] - Override chain ID. Defaults to the wallet's active network.
259
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
260
+ * @returns The signed EIP-7702 authorization.
261
+ * @not-instrumented
262
+ */
263
+ const sign7702Authorization = async ({ walletAccount, chainId }, client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
264
+ return (0, viem_actions.signAuthorization)(await require_createWalletClientForWalletAccount.createWalletClientForWalletAccount({ walletAccount }, client), {
265
+ chainId: await resolveChainId({
266
+ chainId,
267
+ walletAccount
268
+ }, client),
269
+ contractAddress: DELEGATION_CONTRACT_ADDRESS
270
+ });
315
271
  };
316
272
 
317
273
  //#endregion
318
- //#region src/gasless/generateIntentNonce/generateIntentNonce.ts
274
+ //#region src/gasless/resolveAuthorization/resolveAuthorization.ts
319
275
  /**
320
- * Generates a random bitmap nonce for UGD AuthorizedExecutions signing.
276
+ * Resolves the EIP-7702 authorization for a sponsored transaction.
321
277
  *
322
- * Uses crypto.getRandomValues() for 256-bit randomness. Validates against
323
- * the on-chain isNonceUsed check as a safety measure, although collision
324
- * is essentially impossible with 256-bit random values.
278
+ * Returns the provided authorization if given, auto-signs one if needed
279
+ * and autoDelegate is true, or returns undefined if the wallet is already
280
+ * delegated or autoDelegate is false.
325
281
  *
326
- * @param params.walletAccount - The wallet account whose delegation contract is checked.
327
- * @param [client] - The Dynamic client instance.
328
- * @returns A unique bigint nonce for the EIP-712 intent.
329
282
  * @not-instrumented
330
283
  */
331
- const generateIntentNonce = async ({ walletAccount }, client) => {
332
- const nonce = generateRandomNonce();
333
- const { networkData } = await (0, _dynamic_labs_sdk_client.getActiveNetworkData)({ walletAccount }, client);
334
- (0, _dynamic_labs_sdk_client_core.assertDefined)(networkData, `No network data found for wallet account ${walletAccount.address}`);
335
- const publicClient = require_createWalletClientForWalletAccount.createPublicClientFromNetworkData({ networkData });
336
- try {
337
- if (await publicClient.readContract({
338
- abi: UGD_ABI,
339
- address: walletAccount.address,
340
- args: [nonce],
341
- functionName: "isNonceUsed"
342
- })) return generateRandomNonce();
343
- } catch {}
344
- return nonce;
284
+ const resolveAuthorization = async ({ authorization, autoDelegate, walletAccount }, client) => {
285
+ if (authorization) return authorization;
286
+ if (!autoDelegate) return;
287
+ if (await is7702DelegationActive({ walletAccount }, client)) return;
288
+ return sign7702Authorization({ walletAccount }, client);
345
289
  };
346
290
 
347
291
  //#endregion
@@ -369,24 +313,34 @@ const toSerializedAuthorization = (auth) => {
369
313
  /**
370
314
  * Signs a sponsored transaction by creating an EIP-712 intent signature.
371
315
  *
372
- * If an authorization is provided, it is serialized and included in the
373
- * payload. Otherwise the intent is signed without any authorization
374
- * (caller manages delegation separately).
316
+ * This function handles the complete signing flow:
317
+ * - If an authorization is provided, it is included in the payload.
318
+ * - If autoDelegate is true (default) and no authorization is provided,
319
+ * checks whether delegation is active and signs a 7702 authorization if needed.
320
+ * - If autoDelegate is false and no authorization is provided, the intent
321
+ * is signed without any authorization (user manages delegation separately).
375
322
  *
376
323
  * @param params.walletAccount - The EVM wallet account to sign with.
377
324
  * @param params.calls - The batch of calls to execute.
378
- * @param [params.authorization] - Pre-signed EIP-7702 authorization to include.
325
+ * @param [params.authorization] - Pre-signed EIP-7702 authorization. Takes priority over autoDelegate.
326
+ * @param [params.autoDelegate] - Whether to auto-sign 7702 if not delegated. Defaults to true.
379
327
  * @param [params.validForSeconds] - How long the signed intent remains valid, in seconds. Defaults to 600 (10 minutes).
380
328
  * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
381
329
  * @returns The signed sponsored transaction payload ready to be sent to the API.
382
330
  * @not-instrumented
383
331
  */
384
- const signSponsoredTransaction = async ({ walletAccount, calls, authorization, validForSeconds = DEFAULT_VALID_FOR_SECONDS }, client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
332
+ const signSponsoredTransaction = async ({ walletAccount, calls, authorization, autoDelegate = true, validForSeconds = DEFAULT_VALID_FOR_SECONDS }, client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
385
333
  const { networkData } = await (0, _dynamic_labs_sdk_client.getActiveNetworkData)({ walletAccount }, client);
386
334
  (0, _dynamic_labs_sdk_client_core.assertDefined)(networkData, `No network data found for wallet account ${walletAccount.address}`);
335
+ const resolvedAuthorization = await resolveAuthorization({
336
+ authorization,
337
+ autoDelegate,
338
+ walletAccount
339
+ }, client);
387
340
  const nonce = await generateIntentNonce({ walletAccount }, client);
388
341
  const deadline = BigInt(Math.floor(Date.now() / 1e3) + validForSeconds);
389
342
  const chainId = require_createWalletClientForWalletAccount.mapNetworkDataToViemChain(networkData).id;
343
+ const { relayerAddress } = await getAvailableEvmGaslessRelayer({ chainId }, client);
390
344
  const signature = await (await require_createWalletClientForWalletAccount.createWalletClientForWalletAccount({ walletAccount }, client)).signTypedData({
391
345
  domain: {
392
346
  chainId,
@@ -401,18 +355,18 @@ const signSponsoredTransaction = async ({ walletAccount, calls, authorization, v
401
355
  deadline,
402
356
  mode: BATCH_CALL_OPDATA_AUTH_MODE,
403
357
  nonce,
404
- relayer: RELAYER_CONTRACT_ADDRESS
358
+ relayer: relayerAddress
405
359
  },
406
360
  primaryType: "AuthorizedExecutions",
407
361
  types: AUTHORIZED_EXECUTIONS_TYPES
408
362
  });
409
363
  return {
410
- authorization: authorization ? toSerializedAuthorization(authorization) : void 0,
364
+ authorization: resolvedAuthorization ? toSerializedAuthorization(resolvedAuthorization) : void 0,
411
365
  calls,
412
366
  chainId,
413
367
  deadline: deadline.toString(),
414
368
  nonce: nonce.toString(),
415
- relayer: RELAYER_CONTRACT_ADDRESS,
369
+ relayer: relayerAddress,
416
370
  signature,
417
371
  walletAddress: walletAccount.address
418
372
  };
@@ -441,6 +395,7 @@ const isSignedTransactionParams = (params) => "signedTransaction" in params;
441
395
  const relaySponsoredTransaction = async (params, client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
442
396
  const signedTransaction = isSignedTransactionParams(params) ? params.signedTransaction : await signSponsoredTransaction({
443
397
  authorization: params.authorization,
398
+ autoDelegate: params.autoDelegate,
444
399
  calls: params.calls,
445
400
  validForSeconds: params.validForSeconds ?? DEFAULT_VALID_FOR_SECONDS,
446
401
  walletAccount: params.walletAccount
@@ -473,17 +428,49 @@ const relaySponsoredTransaction = async (params, client = (0, _dynamic_labs_sdk_
473
428
  return { requestId: data.requestId };
474
429
  };
475
430
 
431
+ //#endregion
432
+ //#region src/gasless/getEVMSponsoredTransactionStatus/getEVMSponsoredTransactionStatus.ts
433
+ /**
434
+ * Fetches the current relay state for a sponsored EVM transaction.
435
+ *
436
+ * Returns the lifecycle status, the on-chain transaction hash (when the relay
437
+ * has broadcast it), and any terminal-failure error message. Use this as the
438
+ * building block for custom polling flows; for the common "wait until done"
439
+ * case prefer `waitForSponsoredTransaction`.
440
+ *
441
+ * @param params.requestId - The request ID returned when the transaction was relayed.
442
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
443
+ * @returns The current status, optional transaction hash, and optional error message.
444
+ * @throws {SponsorTransactionError} If the API call fails.
445
+ * @not-instrumented
446
+ */
447
+ const getEVMSponsoredTransactionStatus = async ({ requestId }, client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
448
+ const core = (0, _dynamic_labs_sdk_client_core.getCore)(client);
449
+ const apiClient = (0, _dynamic_labs_sdk_client_core.createApiClient)({}, client);
450
+ let data;
451
+ try {
452
+ data = await apiClient.getEVMSponsoredTransactionStatus({
453
+ environmentId: core.environmentId,
454
+ requestId
455
+ });
456
+ } catch (error) {
457
+ throw new SponsorTransactionError(error instanceof Error ? error : null);
458
+ }
459
+ return {
460
+ errorMessage: data.errorMessage,
461
+ status: data.status,
462
+ transactionHash: data.transactionHash
463
+ };
464
+ };
465
+
476
466
  //#endregion
477
467
  //#region src/gasless/waitForSponsoredTransaction/waitForSponsoredTransaction.ts
478
468
  const POLL_INTERVAL_MS = 2e3;
479
469
  const MAX_POLLING_ATTEMPTS = 6e4 / POLL_INTERVAL_MS;
470
+ const TERMINAL_FAILURE_STATUSES = new Set(["failure"]);
480
471
  /**
481
- * Polls `getEVMSponsoredTransactionStatus` until the relay reaches a terminal
482
- * state and returns the on-chain transaction hash.
483
- *
484
- * Resolves on `CONFIRMED`. Throws `SponsorTransactionError` on terminal
485
- * failure statuses (`FAILED`, `CANCELED`, `EXPIRED`, `REJECTED`) or after a
486
- * 60s timeout.
472
+ * Polls `getEVMSponsoredTransactionStatus` until the relay reports the
473
+ * transaction has been included on-chain, then returns the transaction hash.
487
474
  *
488
475
  * @param params.requestId - The request ID returned when the transaction was relayed.
489
476
  * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
@@ -494,18 +481,8 @@ const MAX_POLLING_ATTEMPTS = 6e4 / POLL_INTERVAL_MS;
494
481
  const waitForSponsoredTransaction = async ({ requestId }, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => {
495
482
  for (let attempt = 0; attempt < MAX_POLLING_ATTEMPTS; attempt++) {
496
483
  const result = await getEVMSponsoredTransactionStatus({ requestId }, client);
497
- switch (result.status) {
498
- case "CONFIRMED":
499
- if (!result.transactionHash) throw new SponsorTransactionError();
500
- return { transactionHash: result.transactionHash };
501
- case "CANCELED":
502
- case "EXPIRED":
503
- case "FAILED":
504
- case "REJECTED": throw new SponsorTransactionError(null, result.errorMessage);
505
- case "PENDING":
506
- case "SENT":
507
- case "SUBMITTED": break;
508
- }
484
+ if (TERMINAL_FAILURE_STATUSES.has(result.status)) throw new SponsorTransactionError(null, result.errorMessage);
485
+ if (result.transactionHash) return { transactionHash: result.transactionHash };
509
486
  if (attempt < MAX_POLLING_ATTEMPTS - 1) await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
510
487
  }
511
488
  throw new SponsorTransactionError(null, `Timed out waiting for sponsored transaction ${requestId}`);
@@ -514,12 +491,12 @@ const waitForSponsoredTransaction = async ({ requestId }, client = (0, _dynamic_
514
491
  //#endregion
515
492
  //#region src/gasless/sendSponsoredTransaction/sendSponsoredTransaction.ts
516
493
  /**
517
- * Sends a sponsored EVM transaction and waits for the on-chain transaction hash.
494
+ * Sends a sponsored EVM transaction and waits for on-chain inclusion.
518
495
  *
519
496
  * Accepts either a pre-signed transaction or unsigned calls. When given
520
497
  * unsigned calls, signs the transaction first via signSponsoredTransaction.
521
- * Relays the transaction and polls until the relay reports a CONFIRMED
522
- * status, then returns the resulting transaction hash.
498
+ * Relays the transaction and resolves as soon as the relay reports the
499
+ * transaction has been included on-chain.
523
500
  *
524
501
  * @param params - Either { signedTransaction } or { walletAccount, calls, ... }.
525
502
  * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
@@ -532,6 +509,208 @@ const sendSponsoredTransaction = async (params, client = (0, _dynamic_labs_sdk_c
532
509
  return waitForSponsoredTransaction({ requestId }, client);
533
510
  };
534
511
 
512
+ //#endregion
513
+ //#region src/gasless/activate7702Delegation/activate7702Delegation.ts
514
+ /**
515
+ * Activates EIP-7702 delegation for a wallet by sending a sponsored
516
+ * transaction that only contains the 7702 authorization.
517
+ *
518
+ * After activation, the wallet's delegation is persisted on-chain and
519
+ * subsequent sponsored transactions no longer need to include the
520
+ * authorization.
521
+ *
522
+ * @param params.walletAccount - The EVM wallet account to activate delegation for.
523
+ * @param [params.authorization] - Pre-signed authorization. If omitted, signs one automatically.
524
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
525
+ * @returns An object containing the on-chain transaction hash.
526
+ * @throws {SponsorTransactionError} If the relay returns a terminal failure or polling times out.
527
+ * @not-instrumented
528
+ */
529
+ const activate7702Delegation = async ({ walletAccount, authorization }, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => sendSponsoredTransaction({
530
+ authorization,
531
+ calls: [],
532
+ walletAccount
533
+ }, client);
534
+
535
+ //#endregion
536
+ //#region src/addEvmExtension/addEvmExtension.ts
537
+ /**
538
+ * Adds the EVM extension to the Dynamic client.
539
+ *
540
+ * This is a convenience function that adds both the EIP-6963 extension
541
+ * and the Dynamic WaaS EVM extension, enabling support for all EVM wallet types
542
+ * including standard wallets and embedded wallets managed by Dynamic's infrastructure.
543
+ *
544
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
545
+ * @not-instrumented
546
+ */
547
+ const addEvmExtension = (client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
548
+ require_addEIP6963Extension.addEIP6963Extension(client);
549
+ require_addWaasEvmExtension.addWaasEvmExtension(client);
550
+ };
551
+
552
+ //#endregion
553
+ //#region src/errors/EvmGasSponsorshipNotEnabledError/EvmGasSponsorshipNotEnabledError.ts
554
+ var EvmGasSponsorshipNotEnabledError = class extends _dynamic_labs_sdk_client.BaseError {
555
+ constructor() {
556
+ super({
557
+ cause: null,
558
+ code: "evm_gas_sponsorship_not_enabled_error",
559
+ docsUrl: null,
560
+ name: "EvmGasSponsorshipNotEnabledError",
561
+ shortMessage: "EVM gas sponsorship is not enabled for this project"
562
+ });
563
+ }
564
+ };
565
+
566
+ //#endregion
567
+ //#region src/gasless/isEvmGasSponsorshipEnabled/isEvmGasSponsorshipEnabled.ts
568
+ /**
569
+ * Checks if EVM gas sponsorship is enabled for the current project.
570
+ *
571
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
572
+ * @returns True if EVM gas sponsorship is enabled, false otherwise.
573
+ * @not-instrumented
574
+ */
575
+ const isEvmGasSponsorshipEnabled = (client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => {
576
+ (0, _dynamic_labs_sdk_client_core.assertDefined)(client.projectSettings, "Project settings are not defined");
577
+ return client.projectSettings.sdk.embeddedWallets?.evmGasSponsorshipEnabled ?? false;
578
+ };
579
+
580
+ //#endregion
581
+ //#region src/isEvmNetworkProvider/isEvmNetworkProvider.ts
582
+ /**
583
+ * Type guard function to check if a network provider is an EVM network provider.
584
+ *
585
+ * @param networkProvider - The network provider to check.
586
+ * @returns True if the network provider is an EVM network provider, false otherwise.
587
+ * @not-instrumented
588
+ */
589
+ const isEvmNetworkProvider = (networkProvider) => networkProvider.chain === "EVM";
590
+
591
+ //#endregion
592
+ //#region src/utils/calculateEvmTransactionFee/calculateEvmTransactionFee.ts
593
+ /**
594
+ * Calculates the estimated fee for an EVM transaction.
595
+ *
596
+ * This function estimates gas usage and calculates the total transaction fee
597
+ * using either legacy gas pricing or EIP-1559 pricing. The fee is returned
598
+ * in both native units (wei) and human-readable format (ETH).
599
+ *
600
+ * @param params.transaction - The transaction to estimate fees for.
601
+ * @param params.networkData - Network configuration for RPC connection.
602
+ * @param params.nativeTokenPriceUsd - Optional USD price of the native token for fee conversion.
603
+ * @returns Fee data including gas estimates and human-readable amounts.
604
+ * @throws {FeeEstimationFailedError} If gas estimation or fee retrieval fails.
605
+ * @not-instrumented
606
+ */
607
+ const calculateEvmTransactionFee = async ({ transaction, networkData, nativeTokenPriceUsd }) => {
608
+ try {
609
+ const publicClient = require_createWalletClientForWalletAccount.createPublicClientFromNetworkData({ networkData });
610
+ const gasEstimate = await publicClient.estimateGas({
611
+ account: transaction.from,
612
+ data: transaction.data,
613
+ to: transaction.to,
614
+ value: transaction.value
615
+ });
616
+ let maxFeePerGas;
617
+ let maxPriorityFeePerGas;
618
+ let gasPrice;
619
+ let nativeAmount;
620
+ try {
621
+ const feeData = await publicClient.estimateFeesPerGas();
622
+ maxFeePerGas = feeData.maxFeePerGas;
623
+ maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
624
+ nativeAmount = gasEstimate * maxFeePerGas;
625
+ } catch {
626
+ gasPrice = await publicClient.getGasPrice();
627
+ nativeAmount = gasEstimate * gasPrice;
628
+ }
629
+ const humanReadableAmount = (0, viem.formatEther)(nativeAmount);
630
+ const usdAmount = nativeTokenPriceUsd ? (Number(humanReadableAmount) * nativeTokenPriceUsd).toFixed(2) : void 0;
631
+ return {
632
+ gasEstimate,
633
+ gasPrice,
634
+ humanReadableAmount,
635
+ maxFeePerGas,
636
+ maxPriorityFeePerGas,
637
+ nativeAmount,
638
+ usdAmount
639
+ };
640
+ } catch (error) {
641
+ throw new _dynamic_labs_sdk_client.FeeEstimationFailedError({
642
+ cause: error instanceof Error ? error : void 0,
643
+ message: "Failed to estimate EVM transaction fee"
644
+ });
645
+ }
646
+ };
647
+
648
+ //#endregion
649
+ //#region src/simulateEvmTransaction/simulateEvmTransaction.ts
650
+ /**
651
+ * Simulates an EVM transaction to preview its effects before execution.
652
+ *
653
+ * This function uses the Blockaid API to analyze the transaction and returns
654
+ * information about asset transfers, security validation, and optionally fee estimates.
655
+ * The simulation shows what will happen when the transaction is executed without
656
+ * actually sending it to the blockchain.
657
+ *
658
+ * @param params.walletAccount - The EVM wallet account that will sign the transaction.
659
+ * @param params.transaction - The transaction to simulate, including network ID.
660
+ * @param params.includeFees - Whether to calculate transaction fees (default: false).
661
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
662
+ * @returns Simulation result with asset diffs, security validation, and optional fee data.
663
+ * @throws {InvalidParamError} If wallet account is not an EVM account or network ID is not configured.
664
+ * @throws {SimulationFailedError} If the simulation API call fails.
665
+ * @throws {FeeEstimationFailedError} If includeFees is true and fee calculation fails.
666
+ * @not-instrumented
667
+ */
668
+ const simulateEvmTransaction = async ({ walletAccount, transaction, includeFees = false }, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => {
669
+ if (!require_evmTransferAmount.isEvmWalletAccount(walletAccount)) throw new _dynamic_labs_sdk_client.InvalidParamError("Wallet account must be an EVM wallet account");
670
+ const networkData = (0, _dynamic_labs_sdk_client.getNetworksData)(client).find((data) => data.networkId === transaction.networkId && data.chain === "EVM");
671
+ if (!networkData) throw new _dynamic_labs_sdk_client.InvalidParamError(`Network with ID ${transaction.networkId} is not configured in project settings`);
672
+ try {
673
+ const core = (0, _dynamic_labs_sdk_client_core.getCore)(client);
674
+ const apiClient = (0, _dynamic_labs_sdk_client_core.createApiClient)({}, client);
675
+ const simulateEVMTransactionRequest = {
676
+ chainId: transaction.networkId,
677
+ data: transaction.data || "0x",
678
+ from: transaction.from,
679
+ to: transaction.to
680
+ };
681
+ if (transaction.value !== void 0) simulateEVMTransactionRequest.value = transaction.value.toString();
682
+ const response = await apiClient.simulateEVMTransaction({
683
+ environmentId: core.environmentId,
684
+ simulateEVMTransactionRequest
685
+ });
686
+ let feeData;
687
+ if (includeFees) feeData = await calculateEvmTransactionFee({
688
+ nativeTokenPriceUsd: response.priceData?.nativeTokenUsdPrice,
689
+ networkData,
690
+ transaction
691
+ });
692
+ return {
693
+ counterparties: response.counterparties,
694
+ feeData,
695
+ inAssets: response.inAssets || [],
696
+ outAssets: response.outAssets || [],
697
+ priceData: response.priceData,
698
+ showTotalFiat: response.showTotalFiat,
699
+ validation: response.validation ? {
700
+ description: response.validation.description,
701
+ reason: response.validation.reason,
702
+ result: response.validation.result
703
+ } : void 0
704
+ };
705
+ } catch (error) {
706
+ if (error instanceof _dynamic_labs_sdk_client.FeeEstimationFailedError) throw error;
707
+ throw new _dynamic_labs_sdk_client.SimulationFailedError({
708
+ cause: error instanceof Error ? error : void 0,
709
+ message: "Failed to simulate EVM transaction"
710
+ });
711
+ }
712
+ };
713
+
535
714
  //#endregion
536
715
  //#region src/exports/index.ts
537
716
  (0, _dynamic_labs_sdk_assert_package_version.assertPackageVersion)(require_createWalletClientForWalletAccount.name, require_createWalletClientForWalletAccount.version);
@@ -540,14 +719,17 @@ const sendSponsoredTransaction = async (params, client = (0, _dynamic_labs_sdk_c
540
719
  exports.EvmGasSponsorshipNotEnabledError = EvmGasSponsorshipNotEnabledError;
541
720
  exports.RpcError = require_evmTransferAmount.RpcError;
542
721
  exports.SponsorTransactionError = SponsorTransactionError;
722
+ exports.activate7702Delegation = activate7702Delegation;
543
723
  exports.addEvmExtension = addEvmExtension;
544
724
  exports.calculateEvmTransactionFee = calculateEvmTransactionFee;
545
725
  exports.getEVMSponsoredTransactionStatus = getEVMSponsoredTransactionStatus;
726
+ exports.is7702DelegationActive = is7702DelegationActive;
546
727
  exports.isEvmGasSponsorshipEnabled = isEvmGasSponsorshipEnabled;
547
728
  exports.isEvmNetworkProvider = isEvmNetworkProvider;
548
729
  exports.isEvmWalletAccount = require_evmTransferAmount.isEvmWalletAccount;
549
730
  exports.relaySponsoredTransaction = relaySponsoredTransaction;
550
731
  exports.sendSponsoredTransaction = sendSponsoredTransaction;
732
+ exports.sign7702Authorization = sign7702Authorization;
551
733
  exports.signSponsoredTransaction = signSponsoredTransaction;
552
734
  exports.simulateEvmTransaction = simulateEvmTransaction;
553
735
  exports.waitForSponsoredTransaction = waitForSponsoredTransaction;