@dynamic-labs-sdk/evm 0.9.0 → 0.12.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-DmmAGx88.cjs.js → addEIP6963Extension-AEHuRGr9.cjs.js} +2 -2
- package/dist/{addEIP6963Extension-DmmAGx88.cjs.js.map → addEIP6963Extension-AEHuRGr9.cjs.js.map} +1 -1
- package/dist/{addEIP6963Extension-Fgvl12k3.esm.js → addEIP6963Extension-C3QBJ5eF.esm.js} +2 -2
- package/dist/{addEIP6963Extension-Fgvl12k3.esm.js.map → addEIP6963Extension-C3QBJ5eF.esm.js.map} +1 -1
- package/dist/createPublicClientFromNetworkData-DVfNmDlP.cjs.js +30 -0
- package/dist/createPublicClientFromNetworkData-DVfNmDlP.cjs.js.map +1 -0
- package/dist/createPublicClientFromNetworkData-FtTILn2t.esm.js +25 -0
- package/dist/createPublicClientFromNetworkData-FtTILn2t.esm.js.map +1 -0
- package/dist/{createWalletProviderFromEIP1193Provider-BjFdQbKT.cjs.js → createWalletProviderFromEIP1193Provider-DxS7zeOl.cjs.js} +2 -2
- package/dist/{createWalletProviderFromEIP1193Provider-BjFdQbKT.cjs.js.map → createWalletProviderFromEIP1193Provider-DxS7zeOl.cjs.js.map} +1 -1
- package/dist/{createWalletProviderFromEIP1193Provider-BlpJn4oS.esm.js → createWalletProviderFromEIP1193Provider-t5Nmo-Jr.esm.js} +2 -2
- package/dist/{createWalletProviderFromEIP1193Provider-BlpJn4oS.esm.js.map → createWalletProviderFromEIP1193Provider-t5Nmo-Jr.esm.js.map} +1 -1
- package/dist/eip6963.cjs.js +3 -3
- package/dist/eip6963.esm.js +3 -3
- package/dist/exports/index.d.ts +3 -0
- package/dist/exports/index.d.ts.map +1 -1
- package/dist/index.cjs.js +129 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +129 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/{package-CgwWn5CG.esm.js → package-BH3Pr-Kr.esm.js} +2 -2
- package/dist/package-BH3Pr-Kr.esm.js.map +1 -0
- package/dist/{package-D46S1BfS.cjs.js → package-CM0pp-B5.cjs.js} +2 -2
- package/dist/package-CM0pp-B5.cjs.js.map +1 -0
- package/dist/simulateEvmTransaction/index.d.ts +2 -0
- package/dist/simulateEvmTransaction/index.d.ts.map +1 -0
- package/dist/simulateEvmTransaction/simulateEvmTransaction.d.ts +27 -0
- package/dist/simulateEvmTransaction/simulateEvmTransaction.d.ts.map +1 -0
- package/dist/transactionSimulation.types.d.ts +57 -0
- package/dist/transactionSimulation.types.d.ts.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/utils/calculateEvmTransactionFee/calculateEvmTransactionFee.d.ts +23 -0
- package/dist/utils/calculateEvmTransactionFee/calculateEvmTransactionFee.d.ts.map +1 -0
- package/dist/utils/calculateEvmTransactionFee/index.d.ts +2 -0
- package/dist/utils/calculateEvmTransactionFee/index.d.ts.map +1 -0
- package/dist/viem.cjs.js +3 -22
- package/dist/viem.cjs.js.map +1 -1
- package/dist/viem.esm.js +3 -22
- package/dist/viem.esm.js.map +1 -1
- package/dist/waas.cjs.js +1 -1
- package/dist/waas.esm.js +1 -1
- package/dist/walletConnect.cjs.js +1 -1
- package/dist/walletConnect.esm.js +1 -1
- package/dist/windowInjected.cjs.js +2 -2
- package/dist/windowInjected.esm.js +2 -2
- package/package.json +5 -5
- package/dist/package-CgwWn5CG.esm.js.map +0 -1
- package/dist/package-D46S1BfS.cjs.js.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { n as version, t as name } from "./package-
|
|
1
|
+
import { n as version, t as name } from "./package-BH3Pr-Kr.esm.js";
|
|
2
2
|
import { n as RpcError } from "./registerEvmNetworkProviderBuilder-Cn6YtnaH.esm.js";
|
|
3
|
-
import "./createWalletProviderFromEIP1193Provider-
|
|
4
|
-
import { t as addEIP6963Extension } from "./addEIP6963Extension-
|
|
3
|
+
import "./createWalletProviderFromEIP1193Provider-t5Nmo-Jr.esm.js";
|
|
4
|
+
import { t as addEIP6963Extension } from "./addEIP6963Extension-C3QBJ5eF.esm.js";
|
|
5
5
|
import { t as addWaasEvmExtension } from "./addWaasEvmExtension-CL5LSmDe.esm.js";
|
|
6
|
+
import { t as createPublicClientFromNetworkData } from "./createPublicClientFromNetworkData-FtTILn2t.esm.js";
|
|
6
7
|
import { assertPackageVersion } from "@dynamic-labs-sdk/assert-package-version";
|
|
7
|
-
import { getDefaultClient } from "@dynamic-labs-sdk/client/core";
|
|
8
|
+
import { createApiClient, getCore, getDefaultClient } from "@dynamic-labs-sdk/client/core";
|
|
9
|
+
import { FeeEstimationFailedError, InvalidParamError, SimulationFailedError, getDefaultClient as getDefaultClient$1, getNetworksData } from "@dynamic-labs-sdk/client";
|
|
10
|
+
import { formatEther } from "viem";
|
|
8
11
|
|
|
9
12
|
//#region src/addEvmExtension/addEvmExtension.ts
|
|
10
13
|
/**
|
|
@@ -31,6 +34,62 @@ const addEvmExtension = (client = getDefaultClient()) => {
|
|
|
31
34
|
*/
|
|
32
35
|
const isEvmNetworkProvider = (networkProvider) => networkProvider.chain === "EVM";
|
|
33
36
|
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/utils/calculateEvmTransactionFee/calculateEvmTransactionFee.ts
|
|
39
|
+
/**
|
|
40
|
+
* Calculates the estimated fee for an EVM transaction.
|
|
41
|
+
*
|
|
42
|
+
* This function estimates gas usage and calculates the total transaction fee
|
|
43
|
+
* using either legacy gas pricing or EIP-1559 pricing. The fee is returned
|
|
44
|
+
* in both native units (wei) and human-readable format (ETH).
|
|
45
|
+
*
|
|
46
|
+
* @param params.transaction - The transaction to estimate fees for.
|
|
47
|
+
* @param params.networkData - Network configuration for RPC connection.
|
|
48
|
+
* @param params.nativeTokenPriceUsd - Optional USD price of the native token for fee conversion.
|
|
49
|
+
* @returns Fee data including gas estimates and human-readable amounts.
|
|
50
|
+
* @throws {FeeEstimationFailedError} If gas estimation or fee retrieval fails.
|
|
51
|
+
*/
|
|
52
|
+
const calculateEvmTransactionFee = async ({ transaction, networkData, nativeTokenPriceUsd }) => {
|
|
53
|
+
try {
|
|
54
|
+
const publicClient = createPublicClientFromNetworkData({ networkData });
|
|
55
|
+
const gasEstimate = await publicClient.estimateGas({
|
|
56
|
+
account: transaction.from,
|
|
57
|
+
data: transaction.data,
|
|
58
|
+
to: transaction.to,
|
|
59
|
+
value: transaction.value
|
|
60
|
+
});
|
|
61
|
+
let maxFeePerGas;
|
|
62
|
+
let maxPriorityFeePerGas;
|
|
63
|
+
let gasPrice;
|
|
64
|
+
let nativeAmount;
|
|
65
|
+
try {
|
|
66
|
+
const feeData = await publicClient.estimateFeesPerGas();
|
|
67
|
+
maxFeePerGas = feeData.maxFeePerGas;
|
|
68
|
+
maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
|
69
|
+
nativeAmount = gasEstimate * maxFeePerGas;
|
|
70
|
+
} catch {
|
|
71
|
+
gasPrice = await publicClient.getGasPrice();
|
|
72
|
+
nativeAmount = gasEstimate * gasPrice;
|
|
73
|
+
}
|
|
74
|
+
const humanReadableAmount = formatEther(nativeAmount);
|
|
75
|
+
const usdAmount = nativeTokenPriceUsd ? (Number(humanReadableAmount) * nativeTokenPriceUsd).toFixed(2) : void 0;
|
|
76
|
+
return {
|
|
77
|
+
gasEstimate,
|
|
78
|
+
gasPrice,
|
|
79
|
+
humanReadableAmount,
|
|
80
|
+
maxFeePerGas,
|
|
81
|
+
maxPriorityFeePerGas,
|
|
82
|
+
nativeAmount,
|
|
83
|
+
usdAmount
|
|
84
|
+
};
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw new FeeEstimationFailedError({
|
|
87
|
+
cause: error instanceof Error ? error : void 0,
|
|
88
|
+
message: "Failed to estimate EVM transaction fee"
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
34
93
|
//#endregion
|
|
35
94
|
//#region src/utils/isEvmWalletAccount/isEvmWalletAccount.ts
|
|
36
95
|
/**
|
|
@@ -41,10 +100,75 @@ const isEvmNetworkProvider = (networkProvider) => networkProvider.chain === "EVM
|
|
|
41
100
|
*/
|
|
42
101
|
const isEvmWalletAccount = (walletAccount) => walletAccount.chain === "EVM";
|
|
43
102
|
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/simulateEvmTransaction/simulateEvmTransaction.ts
|
|
105
|
+
/**
|
|
106
|
+
* Simulates an EVM transaction to preview its effects before execution.
|
|
107
|
+
*
|
|
108
|
+
* This function uses the Blockaid API to analyze the transaction and returns
|
|
109
|
+
* information about asset transfers, security validation, and optionally fee estimates.
|
|
110
|
+
* The simulation shows what will happen when the transaction is executed without
|
|
111
|
+
* actually sending it to the blockchain.
|
|
112
|
+
*
|
|
113
|
+
* @param params.walletAccount - The EVM wallet account that will sign the transaction.
|
|
114
|
+
* @param params.transaction - The transaction to simulate, including network ID.
|
|
115
|
+
* @param params.includeFees - Whether to calculate transaction fees (default: false).
|
|
116
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
117
|
+
* @returns Simulation result with asset diffs, security validation, and optional fee data.
|
|
118
|
+
* @throws {InvalidParamError} If wallet account is not an EVM account or network ID is not configured.
|
|
119
|
+
* @throws {SimulationFailedError} If the simulation API call fails.
|
|
120
|
+
* @throws {FeeEstimationFailedError} If includeFees is true and fee calculation fails.
|
|
121
|
+
*/
|
|
122
|
+
const simulateEvmTransaction = async ({ walletAccount, transaction, includeFees = false }, client = getDefaultClient$1()) => {
|
|
123
|
+
if (!isEvmWalletAccount(walletAccount)) throw new InvalidParamError("Wallet account must be an EVM wallet account");
|
|
124
|
+
const networkData = getNetworksData(client).find((data) => data.networkId === transaction.networkId && data.chain === "EVM");
|
|
125
|
+
if (!networkData) throw new InvalidParamError(`Network with ID ${transaction.networkId} is not configured in project settings`);
|
|
126
|
+
try {
|
|
127
|
+
const core = getCore(client);
|
|
128
|
+
const apiClient = createApiClient({}, client);
|
|
129
|
+
const simulateEVMTransactionRequest = {
|
|
130
|
+
chainId: transaction.networkId,
|
|
131
|
+
data: transaction.data || "0x",
|
|
132
|
+
from: transaction.from,
|
|
133
|
+
to: transaction.to
|
|
134
|
+
};
|
|
135
|
+
if (transaction.value !== void 0) simulateEVMTransactionRequest.value = transaction.value.toString();
|
|
136
|
+
const response = await apiClient.simulateEVMTransaction({
|
|
137
|
+
environmentId: core.environmentId,
|
|
138
|
+
simulateEVMTransactionRequest
|
|
139
|
+
});
|
|
140
|
+
let feeData;
|
|
141
|
+
if (includeFees) feeData = await calculateEvmTransactionFee({
|
|
142
|
+
nativeTokenPriceUsd: response.priceData?.nativeTokenUsdPrice,
|
|
143
|
+
networkData,
|
|
144
|
+
transaction
|
|
145
|
+
});
|
|
146
|
+
return {
|
|
147
|
+
counterparties: response.counterparties,
|
|
148
|
+
feeData,
|
|
149
|
+
inAssets: response.inAssets || [],
|
|
150
|
+
outAssets: response.outAssets || [],
|
|
151
|
+
priceData: response.priceData,
|
|
152
|
+
showTotalFiat: response.showTotalFiat,
|
|
153
|
+
validation: response.validation ? {
|
|
154
|
+
description: response.validation.description,
|
|
155
|
+
reason: response.validation.reason,
|
|
156
|
+
result: response.validation.result
|
|
157
|
+
} : void 0
|
|
158
|
+
};
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (error instanceof FeeEstimationFailedError) throw error;
|
|
161
|
+
throw new SimulationFailedError({
|
|
162
|
+
cause: error instanceof Error ? error : void 0,
|
|
163
|
+
message: "Failed to simulate EVM transaction"
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
44
168
|
//#endregion
|
|
45
169
|
//#region src/exports/index.ts
|
|
46
170
|
assertPackageVersion(name, version);
|
|
47
171
|
|
|
48
172
|
//#endregion
|
|
49
|
-
export { RpcError, addEvmExtension, isEvmNetworkProvider, isEvmWalletAccount };
|
|
173
|
+
export { RpcError, addEvmExtension, calculateEvmTransactionFee, isEvmNetworkProvider, isEvmWalletAccount, simulateEvmTransaction };
|
|
50
174
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","names":["packageName","packageVersion"],"sources":["../src/addEvmExtension/addEvmExtension.ts","../src/isEvmNetworkProvider/isEvmNetworkProvider.ts","../src/utils/isEvmWalletAccount/isEvmWalletAccount.ts","../src/exports/index.ts"],"sourcesContent":["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 */\nexport const addEvmExtension = (client = getDefaultClient()): void => {\n addEIP6963Extension(client);\n addWaasEvmExtension(client);\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 */\nexport const isEvmNetworkProvider = (\n networkProvider: NetworkProvider\n): networkProvider is EvmNetworkProvider => networkProvider.chain === 'EVM';\n","import type { WalletAccount } from '@dynamic-labs-sdk/client';\n\nimport type { EvmWalletAccount } from '../../EvmWalletAccount.types';\n\n/**\n * Type guard function to check if a wallet account is an EVM wallet account.\n *\n * @param walletAccount - The wallet account to check.\n * @returns True if the wallet account is an EVM wallet account, false otherwise.\n */\nexport const isEvmWalletAccount = (\n walletAccount: WalletAccount\n): walletAccount is EvmWalletAccount => walletAccount.chain === 'EVM';\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 { addEvmExtension } from '../addEvmExtension';\nexport { RpcError } from '../errors/RpcError';\nexport type { EvmNetworkProvider } from '../EvmNetworkProvider';\nexport type { EvmWalletAccount } from '../EvmWalletAccount.types';\nexport type { EvmWalletProvider } from '../EvmWalletProvider.types';\nexport { isEvmNetworkProvider } from '../isEvmNetworkProvider';\nexport { isEvmWalletAccount } from '../utils/isEvmWalletAccount';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAcA,MAAa,mBAAmB,SAAS,kBAAkB,KAAW;AACpE,qBAAoB,OAAO;AAC3B,qBAAoB,OAAO;;;;;;;;;;;ACN7B,MAAa,wBACX,oBAC0C,gBAAgB,UAAU;;;;;;;;;;ACFtE,MAAa,sBACX,kBACsC,cAAc,UAAU;;;;ACNhE,qBAAqBA,MAAaC,QAAe"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","names":["maxFeePerGas: bigint | undefined","maxPriorityFeePerGas: bigint | undefined","gasPrice: bigint | undefined","nativeAmount: bigint","getDefaultClient","feeData: EvmSimulationResult['feeData']","packageName","packageVersion"],"sources":["../src/addEvmExtension/addEvmExtension.ts","../src/isEvmNetworkProvider/isEvmNetworkProvider.ts","../src/utils/calculateEvmTransactionFee/calculateEvmTransactionFee.ts","../src/utils/isEvmWalletAccount/isEvmWalletAccount.ts","../src/simulateEvmTransaction/simulateEvmTransaction.ts","../src/exports/index.ts"],"sourcesContent":["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 */\nexport const addEvmExtension = (client = getDefaultClient()): void => {\n addEIP6963Extension(client);\n addWaasEvmExtension(client);\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 */\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 */\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 type { WalletAccount } from '@dynamic-labs-sdk/client';\n\nimport type { EvmWalletAccount } from '../../EvmWalletAccount.types';\n\n/**\n * Type guard function to check if a wallet account is an EVM wallet account.\n *\n * @param walletAccount - The wallet account to check.\n * @returns True if the wallet account is an EVM wallet account, false otherwise.\n */\nexport const isEvmWalletAccount = (\n walletAccount: WalletAccount\n): walletAccount is EvmWalletAccount => walletAccount.chain === 'EVM';\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 */\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 { addEvmExtension } from '../addEvmExtension';\nexport { RpcError } from '../errors/RpcError';\nexport type { EvmNetworkProvider } from '../EvmNetworkProvider';\nexport type { EvmWalletAccount } from '../EvmWalletAccount.types';\nexport type { EvmWalletProvider } from '../EvmWalletProvider.types';\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';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAcA,MAAa,mBAAmB,SAAS,kBAAkB,KAAW;AACpE,qBAAoB,OAAO;AAC3B,qBAAoB,OAAO;;;;;;;;;;;ACN7B,MAAa,wBACX,oBAC0C,gBAAgB,UAAU;;;;;;;;;;;;;;;;;ACiBtE,MAAa,6BAA6B,OAAO,EAC/C,aACA,aACA,0BACsE;AACtE,KAAI;EACF,MAAM,eAAe,kCAAkC,EAAE,aAAa,CAAC;EAGvE,MAAM,cAAc,MAAM,aAAa,YAAY;GACjD,SAAS,YAAY;GACrB,MAAM,YAAY;GAClB,IAAI,YAAY;GAChB,OAAO,YAAY;GACpB,CAAC;EAGF,IAAIA;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,sBAAsB,YAAY,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,IAAI,yBAAyB;GACjC,OAAO,iBAAiB,QAAQ,QAAQ;GACxC,SAAS;GACV,CAAC;;;;;;;;;;;;AC3EN,MAAa,sBACX,kBACsC,cAAc,UAAU;;;;;;;;;;;;;;;;;;;;;AC6BhE,MAAa,yBAAyB,OACpC,EACE,eACA,aACA,cAAc,SAEhB,SAASC,oBAAkB,KACM;AAEjC,KAAI,CAAC,mBAAmB,cAAc,CACpC,OAAM,IAAI,kBAAkB,+CAA+C;CAK7E,MAAM,cADe,gBAAgB,OAAO,CACX,MAC9B,SAAS,KAAK,cAAc,YAAY,aAAa,KAAK,UAAU,MACtE;AAED,KAAI,CAAC,YACH,OAAM,IAAI,kBACR,mBAAmB,YAAY,UAAU,wCAC1C;AAGH,KAAI;EAEF,MAAM,OAAO,QAAQ,OAAO;EAC5B,MAAM,YAAY,gBAAgB,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,iBAAiB,yBACnB,OAAM;AAGR,QAAM,IAAI,sBAAsB;GAC9B,OAAO,iBAAiB,QAAQ,QAAQ;GACxC,SAAS;GACV,CAAC;;;;;;ACxHN,qBAAqBC,MAAaC,QAAe"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region package.json
|
|
2
2
|
var name = "@dynamic-labs-sdk/evm";
|
|
3
|
-
var version = "0.
|
|
3
|
+
var version = "0.12.0";
|
|
4
4
|
|
|
5
5
|
//#endregion
|
|
6
6
|
export { version as n, name as t };
|
|
7
|
-
//# sourceMappingURL=package-
|
|
7
|
+
//# sourceMappingURL=package-BH3Pr-Kr.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-BH3Pr-Kr.esm.js","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
//#region package.json
|
|
3
3
|
var name = "@dynamic-labs-sdk/evm";
|
|
4
|
-
var version = "0.
|
|
4
|
+
var version = "0.12.0";
|
|
5
5
|
|
|
6
6
|
//#endregion
|
|
7
7
|
Object.defineProperty(exports, 'name', {
|
|
@@ -16,4 +16,4 @@ Object.defineProperty(exports, 'version', {
|
|
|
16
16
|
return version;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
-
//# sourceMappingURL=package-
|
|
19
|
+
//# sourceMappingURL=package-CM0pp-B5.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-CM0pp-B5.cjs.js","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/simulateEvmTransaction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { EvmWalletAccount } from '../EvmWalletAccount.types';
|
|
2
|
+
import type { EvmSimulationResult, EvmTransactionToSimulate } from '../transactionSimulation.types';
|
|
3
|
+
type SimulateEvmTransactionParams = {
|
|
4
|
+
includeFees?: boolean;
|
|
5
|
+
transaction: EvmTransactionToSimulate;
|
|
6
|
+
walletAccount: EvmWalletAccount;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Simulates an EVM transaction to preview its effects before execution.
|
|
10
|
+
*
|
|
11
|
+
* This function uses the Blockaid API to analyze the transaction and returns
|
|
12
|
+
* information about asset transfers, security validation, and optionally fee estimates.
|
|
13
|
+
* The simulation shows what will happen when the transaction is executed without
|
|
14
|
+
* actually sending it to the blockchain.
|
|
15
|
+
*
|
|
16
|
+
* @param params.walletAccount - The EVM wallet account that will sign the transaction.
|
|
17
|
+
* @param params.transaction - The transaction to simulate, including network ID.
|
|
18
|
+
* @param params.includeFees - Whether to calculate transaction fees (default: false).
|
|
19
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
20
|
+
* @returns Simulation result with asset diffs, security validation, and optional fee data.
|
|
21
|
+
* @throws {InvalidParamError} If wallet account is not an EVM account or network ID is not configured.
|
|
22
|
+
* @throws {SimulationFailedError} If the simulation API call fails.
|
|
23
|
+
* @throws {FeeEstimationFailedError} If includeFees is true and fee calculation fails.
|
|
24
|
+
*/
|
|
25
|
+
export declare const simulateEvmTransaction: ({ walletAccount, transaction, includeFees, }: SimulateEvmTransactionParams, client?: import("@dynamic-labs-sdk/client").DynamicClient) => Promise<EvmSimulationResult>;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=simulateEvmTransaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulateEvmTransaction.d.ts","sourceRoot":"","sources":["../../src/simulateEvmTransaction/simulateEvmTransaction.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,gCAAgC,CAAC;AAIxC,KAAK,4BAA4B,GAAG;IAClC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE,wBAAwB,CAAC;IACtC,aAAa,EAAE,gBAAgB,CAAC;CACjC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB,iDAK9B,4BAA4B,gEAE9B,OAAO,CAAC,mBAAmB,CAgF7B,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { SimulationResult, TransactionFeeData } from '@dynamic-labs-sdk/client';
|
|
2
|
+
import type { Hex } from 'viem';
|
|
3
|
+
/**
|
|
4
|
+
* EVM transaction data required for simulation.
|
|
5
|
+
*
|
|
6
|
+
* This represents a transaction to be simulated before execution.
|
|
7
|
+
*/
|
|
8
|
+
export type EvmTransactionToSimulate = {
|
|
9
|
+
/**
|
|
10
|
+
* Encoded function call data for contract interactions
|
|
11
|
+
*/
|
|
12
|
+
data?: Hex;
|
|
13
|
+
/**
|
|
14
|
+
* Address sending the transaction
|
|
15
|
+
*/
|
|
16
|
+
from: Hex;
|
|
17
|
+
/**
|
|
18
|
+
* Network identifier matching NetworkData.networkId (e.g., '1' for Ethereum, '137' for Polygon)
|
|
19
|
+
*/
|
|
20
|
+
networkId: string;
|
|
21
|
+
/**
|
|
22
|
+
* Address receiving the transaction
|
|
23
|
+
*/
|
|
24
|
+
to: Hex;
|
|
25
|
+
/**
|
|
26
|
+
* Amount of native token to send (in wei)
|
|
27
|
+
*/
|
|
28
|
+
value?: bigint;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* EVM-specific transaction fee data extending the base fee data with gas details.
|
|
32
|
+
*
|
|
33
|
+
* Includes both legacy and EIP-1559 gas pricing fields.
|
|
34
|
+
*/
|
|
35
|
+
export type EvmTransactionFeeData = TransactionFeeData & {
|
|
36
|
+
/**
|
|
37
|
+
* Estimated gas units required for the transaction
|
|
38
|
+
*/
|
|
39
|
+
gasEstimate: bigint;
|
|
40
|
+
/**
|
|
41
|
+
* Legacy gas price in wei per gas unit
|
|
42
|
+
*/
|
|
43
|
+
gasPrice?: bigint;
|
|
44
|
+
/**
|
|
45
|
+
* EIP-1559 maximum fee per gas unit in wei
|
|
46
|
+
*/
|
|
47
|
+
maxFeePerGas?: bigint;
|
|
48
|
+
/**
|
|
49
|
+
* EIP-1559 maximum priority fee (tip) per gas unit in wei
|
|
50
|
+
*/
|
|
51
|
+
maxPriorityFeePerGas?: bigint;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* EVM transaction simulation result with typed fee data.
|
|
55
|
+
*/
|
|
56
|
+
export type EvmSimulationResult = SimulationResult<EvmTransactionFeeData>;
|
|
57
|
+
//# sourceMappingURL=transactionSimulation.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactionSimulation.types.d.ts","sourceRoot":"","sources":["../src/transactionSimulation.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEhC;;;;GAIG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC;;OAEG;IACH,IAAI,CAAC,EAAE,GAAG,CAAC;IACX;;OAEG;IACH,IAAI,EAAE,GAAG,CAAC;IACV;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,EAAE,EAAE,GAAG,CAAC;IACR;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,kBAAkB,GAAG;IACvD;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,CAAC"}
|