@dynamic-labs-sdk/evm 1.3.0 → 1.5.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-6q4uKJ2S.cjs → addEIP6963Extension-C-2D7v76.cjs} +3 -3
- package/dist/{addEIP6963Extension-6q4uKJ2S.cjs.map → addEIP6963Extension-C-2D7v76.cjs.map} +1 -1
- package/dist/{addEIP6963Extension-C_IKf5DD.native.esm.js → addEIP6963Extension-CrpzqtkA.native.esm.js} +1 -1
- package/dist/{addEIP6963Extension-C_IKf5DD.native.esm.js.map → addEIP6963Extension-CrpzqtkA.native.esm.js.map} +1 -1
- package/dist/{addEIP6963Extension-CSo4PZ83.esm.js → addEIP6963Extension-Dt582bCZ.esm.js} +3 -3
- package/dist/{addEIP6963Extension-CSo4PZ83.esm.js.map → addEIP6963Extension-Dt582bCZ.esm.js.map} +1 -1
- package/dist/{addWaasEvmExtension-L8dUNmj8.native.esm.js → addWaasEvmExtension-CrLafMzM.native.esm.js} +3 -3
- package/dist/{addWaasEvmExtension-L8dUNmj8.native.esm.js.map → addWaasEvmExtension-CrLafMzM.native.esm.js.map} +1 -1
- package/dist/{addWaasEvmExtension-DTmPsJ-R.esm.js → addWaasEvmExtension-CzyCQ7fp.esm.js} +3 -3
- package/dist/{addWaasEvmExtension-DTmPsJ-R.esm.js.map → addWaasEvmExtension-CzyCQ7fp.esm.js.map} +1 -1
- package/dist/{addWaasEvmExtension-FyQx6Qlo.cjs → addWaasEvmExtension-D8O6IjQG.cjs} +3 -3
- package/dist/{addWaasEvmExtension-FyQx6Qlo.cjs.map → addWaasEvmExtension-D8O6IjQG.cjs.map} +1 -1
- package/dist/baseAccount.cjs +3 -3
- package/dist/baseAccount.esm.js +3 -3
- package/dist/baseAccount.native.esm.js +4 -4
- package/dist/{createWalletClientForWalletAccount-CKBR4V6M.cjs → createWalletClientForWalletAccount-CTDnbreU.cjs} +8 -2
- package/dist/{createWalletClientForWalletAccount-CKBR4V6M.cjs.map → createWalletClientForWalletAccount-CTDnbreU.cjs.map} +1 -1
- package/dist/{createWalletClientForWalletAccount-BotF25Kn.native.esm.js → createWalletClientForWalletAccount-CuakQYYA.native.esm.js} +2 -2
- package/dist/{createWalletClientForWalletAccount-BotF25Kn.native.esm.js.map → createWalletClientForWalletAccount-CuakQYYA.native.esm.js.map} +1 -1
- package/dist/{createWalletClientForWalletAccount-DRs8Ja_I.esm.js → createWalletClientForWalletAccount-CzeWTBwv.esm.js} +3 -3
- package/dist/{createWalletClientForWalletAccount-DRs8Ja_I.esm.js.map → createWalletClientForWalletAccount-CzeWTBwv.esm.js.map} +1 -1
- package/dist/{createWalletProviderFromEIP1193Provider-CWWLWjod.native.esm.js → createWalletProviderFromEIP1193Provider-B8doAYSi.native.esm.js} +2 -2
- package/dist/{createWalletProviderFromEIP1193Provider-CWWLWjod.native.esm.js.map → createWalletProviderFromEIP1193Provider-B8doAYSi.native.esm.js.map} +1 -1
- package/dist/{createWalletProviderFromEIP1193Provider-p3Aa46Bi.esm.js → createWalletProviderFromEIP1193Provider-Di6l7mjB.esm.js} +2 -2
- package/dist/{createWalletProviderFromEIP1193Provider-p3Aa46Bi.esm.js.map → createWalletProviderFromEIP1193Provider-Di6l7mjB.esm.js.map} +1 -1
- package/dist/{createWalletProviderFromEIP1193Provider-D-6PlGdy.cjs → createWalletProviderFromEIP1193Provider-_EtpThZ6.cjs} +2 -2
- package/dist/{createWalletProviderFromEIP1193Provider-D-6PlGdy.cjs.map → createWalletProviderFromEIP1193Provider-_EtpThZ6.cjs.map} +1 -1
- package/dist/eip6963.cjs +4 -4
- package/dist/eip6963.esm.js +4 -4
- package/dist/eip6963.native.esm.js +2 -2
- package/dist/evmTransferAmount-3m9QeANI.esm.js +875 -0
- package/dist/evmTransferAmount-3m9QeANI.esm.js.map +1 -0
- package/dist/evmTransferAmount-BQDSXSva.native.esm.js +875 -0
- package/dist/evmTransferAmount-BQDSXSva.native.esm.js.map +1 -0
- package/dist/evmTransferAmount-Bb1YvuCX.cjs +964 -0
- package/dist/evmTransferAmount-Bb1YvuCX.cjs.map +1 -0
- package/dist/exports/metamask.d.ts +6 -0
- package/dist/exports/metamask.d.ts.map +1 -0
- package/dist/gasless/relaySponsoredTransaction/relaySponsoredTransaction.d.ts +6 -0
- package/dist/gasless/relaySponsoredTransaction/relaySponsoredTransaction.d.ts.map +1 -1
- package/dist/gasless/sendSponsoredTransaction/sendSponsoredTransaction.d.ts +6 -0
- package/dist/gasless/sendSponsoredTransaction/sendSponsoredTransaction.d.ts.map +1 -1
- package/dist/gasless/signSponsoredTransaction/signSponsoredTransaction.d.ts +11 -1
- package/dist/gasless/signSponsoredTransaction/signSponsoredTransaction.d.ts.map +1 -1
- package/dist/index.cjs +15 -531
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +7 -523
- package/dist/index.esm.js.map +1 -1
- package/dist/index.native.esm.js +7 -523
- package/dist/index.native.esm.js.map +1 -1
- package/dist/metamask/connectAndVerifyWithMetaMaskUriEvm/connectAndVerifyWithMetaMaskUriEvm.d.ts +17 -0
- package/dist/metamask/connectAndVerifyWithMetaMaskUriEvm/connectAndVerifyWithMetaMaskUriEvm.d.ts.map +1 -0
- package/dist/metamask/connectAndVerifyWithMetaMaskUriEvm/index.d.ts +2 -0
- package/dist/metamask/connectAndVerifyWithMetaMaskUriEvm/index.d.ts.map +1 -0
- package/dist/metamask/connectWithMetaMaskUriEvm/connectWithMetaMaskUriEvm.d.ts +17 -0
- package/dist/metamask/connectWithMetaMaskUriEvm/connectWithMetaMaskUriEvm.d.ts.map +1 -0
- package/dist/metamask/connectWithMetaMaskUriEvm/index.d.ts +3 -0
- package/dist/metamask/connectWithMetaMaskUriEvm/index.d.ts.map +1 -0
- package/dist/metamask/createMetaMaskEvmWalletProvider/createMetaMaskEvmWalletProvider.d.ts +7 -12
- package/dist/metamask/createMetaMaskEvmWalletProvider/createMetaMaskEvmWalletProvider.d.ts.map +1 -1
- package/dist/metamask/createMetaMaskEvmWalletProvider/index.d.ts +0 -1
- package/dist/metamask/createMetaMaskEvmWalletProvider/index.d.ts.map +1 -1
- package/dist/metamask/getMetaMaskEvmExtensionWalletProviderKey/getMetaMaskEvmExtensionWalletProviderKey.d.ts +10 -0
- package/dist/metamask/getMetaMaskEvmExtensionWalletProviderKey/getMetaMaskEvmExtensionWalletProviderKey.d.ts.map +1 -0
- package/dist/metamask/getMetaMaskEvmExtensionWalletProviderKey/index.d.ts +2 -0
- package/dist/metamask/getMetaMaskEvmExtensionWalletProviderKey/index.d.ts.map +1 -0
- package/dist/metamask/metamask.types.d.ts +8 -36
- package/dist/metamask/metamask.types.d.ts.map +1 -1
- package/dist/metamask/utils/createMetaMaskEvmController/createMetaMaskEvmController.d.ts +5 -27
- package/dist/metamask/utils/createMetaMaskEvmController/createMetaMaskEvmController.d.ts.map +1 -1
- package/dist/metamask.cjs +317 -0
- package/dist/metamask.cjs.map +1 -0
- package/dist/metamask.esm.js +309 -0
- package/dist/metamask.esm.js.map +1 -0
- package/dist/metamask.native.esm.js +310 -0
- package/dist/metamask.native.esm.js.map +1 -0
- package/dist/{package-DGj3wg-e.native.esm.js → package-CVMy4p36.native.esm.js} +2 -2
- package/dist/package-CVMy4p36.native.esm.js.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/utils/evmExecuteSponsoredSwapTransaction/evmExecuteSponsoredSwapTransaction.d.ts +31 -0
- package/dist/utils/evmExecuteSponsoredSwapTransaction/evmExecuteSponsoredSwapTransaction.d.ts.map +1 -0
- package/dist/utils/evmExecuteSponsoredSwapTransaction/index.d.ts +2 -0
- package/dist/utils/evmExecuteSponsoredSwapTransaction/index.d.ts.map +1 -0
- package/dist/utils/evmExecuteSwapTransaction/evmExecuteSwapTransaction.d.ts +10 -6
- package/dist/utils/evmExecuteSwapTransaction/evmExecuteSwapTransaction.d.ts.map +1 -1
- package/dist/viem.cjs +1 -1
- package/dist/viem.esm.js +1 -1
- package/dist/viem.native.esm.js +2 -2
- package/dist/waas.cjs +3 -3
- package/dist/waas.esm.js +3 -3
- package/dist/waas.native.esm.js +4 -4
- package/dist/walletConnect.cjs +2 -2
- package/dist/walletConnect.esm.js +2 -2
- package/dist/walletConnect.native.esm.js +3 -3
- package/dist/windowInjected.cjs +3 -3
- package/dist/windowInjected.esm.js +3 -3
- package/dist/windowInjected.native.esm.js +4 -4
- package/package.json +10 -4
- package/dist/evmTransferAmount-BJswh1ID.esm.js +0 -289
- package/dist/evmTransferAmount-BJswh1ID.esm.js.map +0 -1
- package/dist/evmTransferAmount-BY0rW4dg.native.esm.js +0 -289
- package/dist/evmTransferAmount-BY0rW4dg.native.esm.js.map +0 -1
- package/dist/evmTransferAmount-CkF4KIge.cjs +0 -324
- package/dist/evmTransferAmount-CkF4KIge.cjs.map +0 -1
- package/dist/metamask/utils/clearMetaMaskEvmSessionStorage/clearMetaMaskEvmSessionStorage.d.ts +0 -34
- package/dist/metamask/utils/clearMetaMaskEvmSessionStorage/clearMetaMaskEvmSessionStorage.d.ts.map +0 -1
- package/dist/metamask/utils/clearMetaMaskEvmSessionStorage/index.d.ts +0 -2
- package/dist/metamask/utils/clearMetaMaskEvmSessionStorage/index.d.ts.map +0 -1
- package/dist/metamask/utils/isConnectShapedResponse/index.d.ts +0 -3
- package/dist/metamask/utils/isConnectShapedResponse/index.d.ts.map +0 -1
- package/dist/metamask/utils/isConnectShapedResponse/isConnectShapedResponse.d.ts +0 -21
- package/dist/metamask/utils/isConnectShapedResponse/isConnectShapedResponse.d.ts.map +0 -1
- package/dist/package-DGj3wg-e.native.esm.js.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,515 +1,13 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
3
|
-
import "./createWalletProviderFromEIP1193Provider-
|
|
4
|
-
import { t as addEIP6963Extension } from "./addEIP6963Extension-
|
|
5
|
-
import { t as addWaasEvmExtension } from "./addWaasEvmExtension-
|
|
1
|
+
import { a as name, o as version, r as createPublicClientFromNetworkData } from "./createWalletClientForWalletAccount-CzeWTBwv.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-3m9QeANI.esm.js";
|
|
3
|
+
import "./createWalletProviderFromEIP1193Provider-Di6l7mjB.esm.js";
|
|
4
|
+
import { t as addEIP6963Extension } from "./addEIP6963Extension-Dt582bCZ.esm.js";
|
|
5
|
+
import { t as addWaasEvmExtension } from "./addWaasEvmExtension-CzyCQ7fp.esm.js";
|
|
6
6
|
import { assertPackageVersion } from "@dynamic-labs-sdk/assert-package-version";
|
|
7
|
-
import { BaseError, FeeEstimationFailedError, InvalidParamError, SimulationFailedError,
|
|
8
|
-
import {
|
|
7
|
+
import { BaseError, FeeEstimationFailedError, InvalidParamError, SimulationFailedError, getDefaultClient, getNetworksData } from "@dynamic-labs-sdk/client";
|
|
8
|
+
import { createApiClient, getCore, getDefaultClient as getDefaultClient$1 } from "@dynamic-labs-sdk/client/core";
|
|
9
9
|
import { formatEther } from "viem";
|
|
10
|
-
import { signAuthorization } from "viem/actions";
|
|
11
10
|
|
|
12
|
-
//#region src/errors/SponsorTransactionError/SponsorTransactionError.ts
|
|
13
|
-
var SponsorTransactionError = class extends BaseError {
|
|
14
|
-
constructor(cause, details) {
|
|
15
|
-
super({
|
|
16
|
-
cause: cause ?? null,
|
|
17
|
-
code: "sponsor_transaction_error",
|
|
18
|
-
details,
|
|
19
|
-
docsUrl: null,
|
|
20
|
-
name: "SponsorTransactionError",
|
|
21
|
-
shortMessage: "Failed to sponsor EVM transaction"
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/gasless/constants.ts
|
|
28
|
-
/** The Fireblocks Universal Gasless Delegate (UGD) contract address used for EIP-7702 delegation. */
|
|
29
|
-
const DELEGATION_CONTRACT_ADDRESS = "0x0000Fb7702036ff9f76044a501ac1aA74cbab16b";
|
|
30
|
-
/** Default sponsored transaction validity duration in seconds (10 minutes). */
|
|
31
|
-
const DEFAULT_VALID_FOR_SECONDS = 600;
|
|
32
|
-
/** EIP-7702 delegation code prefix used to identify delegated accounts. */
|
|
33
|
-
const DELEGATION_CODE_PREFIX = "0xef0100";
|
|
34
|
-
/** ERC-7579 batch call with opData and auth mode identifier. */
|
|
35
|
-
const BATCH_CALL_OPDATA_AUTH_MODE = "0x0100000000007821000100000000000000000000000000000000000000000000";
|
|
36
|
-
/** EIP-712 typed data types for UGD AuthorizedExecutions signing. */
|
|
37
|
-
const AUTHORIZED_EXECUTIONS_TYPES = {
|
|
38
|
-
AuthorizedExecutions: [
|
|
39
|
-
{
|
|
40
|
-
name: "calls",
|
|
41
|
-
type: "Execution[]"
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
name: "deadline",
|
|
45
|
-
type: "uint256"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: "mode",
|
|
49
|
-
type: "bytes32"
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name: "nonce",
|
|
53
|
-
type: "uint256"
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: "relayer",
|
|
57
|
-
type: "address"
|
|
58
|
-
}
|
|
59
|
-
],
|
|
60
|
-
Execution: [
|
|
61
|
-
{
|
|
62
|
-
name: "target",
|
|
63
|
-
type: "address"
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: "value",
|
|
67
|
-
type: "uint256"
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
name: "data",
|
|
71
|
-
type: "bytes"
|
|
72
|
-
}
|
|
73
|
-
]
|
|
74
|
-
};
|
|
75
|
-
/** Minimal ABI for the UGD contract's nonce validation function. */
|
|
76
|
-
const UGD_ABI = [{
|
|
77
|
-
inputs: [{
|
|
78
|
-
name: "nonce",
|
|
79
|
-
type: "uint256"
|
|
80
|
-
}],
|
|
81
|
-
name: "isNonceUsed",
|
|
82
|
-
outputs: [{
|
|
83
|
-
name: "",
|
|
84
|
-
type: "bool"
|
|
85
|
-
}],
|
|
86
|
-
stateMutability: "view",
|
|
87
|
-
type: "function"
|
|
88
|
-
}];
|
|
89
|
-
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/gasless/generateRandomNonce/generateRandomNonce.ts
|
|
92
|
-
/**
|
|
93
|
-
* Generates a cryptographically random 256-bit nonce.
|
|
94
|
-
*
|
|
95
|
-
* @returns A random bigint nonce.
|
|
96
|
-
* @not-instrumented
|
|
97
|
-
*/
|
|
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 getActiveNetworkData({ walletAccount }, client);
|
|
121
|
-
assertDefined(networkData, `No network data found for wallet account ${walletAccount.address}`);
|
|
122
|
-
const publicClient = 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 = getCore(client);
|
|
153
|
-
const apiClient = 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 = 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 = getDefaultClient$1()) => {
|
|
210
|
-
const { networkData } = await getActiveNetworkData({ walletAccount }, client);
|
|
211
|
-
assertDefined(networkData, `No network data found for wallet account ${walletAccount.address}`);
|
|
212
|
-
const chainId = 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 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 getActiveNetworkData({ walletAccount }, client);
|
|
243
|
-
assertDefined(networkData, `No network data found for wallet account ${walletAccount.address}`);
|
|
244
|
-
return 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 = getDefaultClient$1()) => {
|
|
264
|
-
return signAuthorization(await createWalletClientForWalletAccount({ walletAccount }, client), {
|
|
265
|
-
chainId: await resolveChainId({
|
|
266
|
-
chainId,
|
|
267
|
-
walletAccount
|
|
268
|
-
}, client),
|
|
269
|
-
contractAddress: DELEGATION_CONTRACT_ADDRESS
|
|
270
|
-
});
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
//#endregion
|
|
274
|
-
//#region src/gasless/resolveAuthorization/resolveAuthorization.ts
|
|
275
|
-
/**
|
|
276
|
-
* Resolves the EIP-7702 authorization for a sponsored transaction.
|
|
277
|
-
*
|
|
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.
|
|
281
|
-
*
|
|
282
|
-
* @not-instrumented
|
|
283
|
-
*/
|
|
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);
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
//#endregion
|
|
292
|
-
//#region src/gasless/toSerializedAuthorization/toSerializedAuthorization.ts
|
|
293
|
-
/**
|
|
294
|
-
* Converts a viem SignAuthorizationReturnType into a plain serializable object
|
|
295
|
-
* suitable for JSON transport to the sponsorship API.
|
|
296
|
-
*
|
|
297
|
-
* @not-instrumented
|
|
298
|
-
*/
|
|
299
|
-
const toSerializedAuthorization = (auth) => {
|
|
300
|
-
assertDefined(auth.yParity, "Signed authorization is missing yParity");
|
|
301
|
-
return {
|
|
302
|
-
address: auth.address,
|
|
303
|
-
chainId: auth.chainId,
|
|
304
|
-
nonce: auth.nonce,
|
|
305
|
-
r: auth.r,
|
|
306
|
-
s: auth.s,
|
|
307
|
-
yParity: auth.yParity
|
|
308
|
-
};
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
//#endregion
|
|
312
|
-
//#region src/gasless/signSponsoredTransaction/signSponsoredTransaction.ts
|
|
313
|
-
/**
|
|
314
|
-
* Signs a sponsored transaction by creating an EIP-712 intent signature.
|
|
315
|
-
*
|
|
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).
|
|
322
|
-
*
|
|
323
|
-
* @param params.walletAccount - The EVM wallet account to sign with.
|
|
324
|
-
* @param params.calls - The batch of calls to execute.
|
|
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.
|
|
327
|
-
* @param [params.validForSeconds] - How long the signed intent remains valid, in seconds. Defaults to 600 (10 minutes).
|
|
328
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
329
|
-
* @returns The signed sponsored transaction payload ready to be sent to the API.
|
|
330
|
-
* @not-instrumented
|
|
331
|
-
*/
|
|
332
|
-
const signSponsoredTransaction = async ({ walletAccount, calls, authorization, autoDelegate = true, validForSeconds = DEFAULT_VALID_FOR_SECONDS }, client = getDefaultClient$1()) => {
|
|
333
|
-
const { networkData } = await getActiveNetworkData({ walletAccount }, client);
|
|
334
|
-
assertDefined(networkData, `No network data found for wallet account ${walletAccount.address}`);
|
|
335
|
-
const resolvedAuthorization = await resolveAuthorization({
|
|
336
|
-
authorization,
|
|
337
|
-
autoDelegate,
|
|
338
|
-
walletAccount
|
|
339
|
-
}, client);
|
|
340
|
-
const nonce = await generateIntentNonce({ walletAccount }, client);
|
|
341
|
-
const deadline = BigInt(Math.floor(Date.now() / 1e3) + validForSeconds);
|
|
342
|
-
const chainId = mapNetworkDataToViemChain(networkData).id;
|
|
343
|
-
const { relayerAddress } = await getAvailableEvmGaslessRelayer({ chainId }, client);
|
|
344
|
-
const signature = await (await createWalletClientForWalletAccount({ walletAccount }, client)).signTypedData({
|
|
345
|
-
domain: {
|
|
346
|
-
chainId,
|
|
347
|
-
verifyingContract: DELEGATION_CONTRACT_ADDRESS
|
|
348
|
-
},
|
|
349
|
-
message: {
|
|
350
|
-
calls: calls.map((c) => ({
|
|
351
|
-
data: c.data,
|
|
352
|
-
target: c.target,
|
|
353
|
-
value: c.value
|
|
354
|
-
})),
|
|
355
|
-
deadline,
|
|
356
|
-
mode: BATCH_CALL_OPDATA_AUTH_MODE,
|
|
357
|
-
nonce,
|
|
358
|
-
relayer: relayerAddress
|
|
359
|
-
},
|
|
360
|
-
primaryType: "AuthorizedExecutions",
|
|
361
|
-
types: AUTHORIZED_EXECUTIONS_TYPES
|
|
362
|
-
});
|
|
363
|
-
return {
|
|
364
|
-
authorization: resolvedAuthorization ? toSerializedAuthorization(resolvedAuthorization) : void 0,
|
|
365
|
-
calls,
|
|
366
|
-
chainId,
|
|
367
|
-
deadline: deadline.toString(),
|
|
368
|
-
nonce: nonce.toString(),
|
|
369
|
-
relayer: relayerAddress,
|
|
370
|
-
signature,
|
|
371
|
-
walletAddress: walletAccount.address
|
|
372
|
-
};
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
//#endregion
|
|
376
|
-
//#region src/gasless/relaySponsoredTransaction/relaySponsoredTransaction.ts
|
|
377
|
-
const isSignedTransactionParams = (params) => "signedTransaction" in params;
|
|
378
|
-
/**
|
|
379
|
-
* Relays a sponsored EVM transaction to the Dynamic backend.
|
|
380
|
-
*
|
|
381
|
-
* Accepts either a pre-signed transaction or unsigned calls. When given
|
|
382
|
-
* unsigned calls, signs the transaction first via signSponsoredTransaction.
|
|
383
|
-
*
|
|
384
|
-
* The backend encodes the transaction, submits it to the relay provider,
|
|
385
|
-
* and returns a request ID for tracking. The relay may retry the on-chain
|
|
386
|
-
* submission, so the request ID (not a transaction hash) is the stable
|
|
387
|
-
* identifier for the sponsored transaction.
|
|
388
|
-
*
|
|
389
|
-
* @param params - Either { signedTransaction } or { walletAccount, calls, ... }.
|
|
390
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
391
|
-
* @returns An object containing the request ID for tracking the relayed transaction.
|
|
392
|
-
* @throws {SponsorTransactionError} If the API call fails or returns an unexpected response.
|
|
393
|
-
* @not-instrumented
|
|
394
|
-
*/
|
|
395
|
-
const relaySponsoredTransaction = async (params, client = getDefaultClient$1()) => {
|
|
396
|
-
const signedTransaction = isSignedTransactionParams(params) ? params.signedTransaction : await signSponsoredTransaction({
|
|
397
|
-
authorization: params.authorization,
|
|
398
|
-
autoDelegate: params.autoDelegate,
|
|
399
|
-
calls: params.calls,
|
|
400
|
-
validForSeconds: params.validForSeconds ?? DEFAULT_VALID_FOR_SECONDS,
|
|
401
|
-
walletAccount: params.walletAccount
|
|
402
|
-
}, client);
|
|
403
|
-
const core = getCore(client);
|
|
404
|
-
const apiClient = createApiClient({}, client);
|
|
405
|
-
let data;
|
|
406
|
-
try {
|
|
407
|
-
data = await apiClient.sponsorEVMTransaction({
|
|
408
|
-
environmentId: core.environmentId,
|
|
409
|
-
sponsorEVMTransactionRequest: {
|
|
410
|
-
authorization: signedTransaction.authorization,
|
|
411
|
-
calls: signedTransaction.calls.map((c) => ({
|
|
412
|
-
data: c.data,
|
|
413
|
-
target: c.target,
|
|
414
|
-
value: c.value.toString()
|
|
415
|
-
})),
|
|
416
|
-
chainId: signedTransaction.chainId,
|
|
417
|
-
deadline: signedTransaction.deadline,
|
|
418
|
-
nonce: signedTransaction.nonce,
|
|
419
|
-
relayer: signedTransaction.relayer,
|
|
420
|
-
signature: signedTransaction.signature,
|
|
421
|
-
walletAddress: signedTransaction.walletAddress
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
} catch (error) {
|
|
425
|
-
throw new SponsorTransactionError(error instanceof Error ? error : null);
|
|
426
|
-
}
|
|
427
|
-
if (!data.requestId) throw new SponsorTransactionError();
|
|
428
|
-
return { requestId: data.requestId };
|
|
429
|
-
};
|
|
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 = getDefaultClient$1()) => {
|
|
448
|
-
const core = getCore(client);
|
|
449
|
-
const apiClient = 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
|
-
|
|
466
|
-
//#endregion
|
|
467
|
-
//#region src/gasless/waitForSponsoredTransaction/waitForSponsoredTransaction.ts
|
|
468
|
-
const POLL_INTERVAL_MS = 2e3;
|
|
469
|
-
const MAX_POLLING_ATTEMPTS = 6e4 / POLL_INTERVAL_MS;
|
|
470
|
-
const TERMINAL_FAILURE_STATUSES = new Set(["failure"]);
|
|
471
|
-
/**
|
|
472
|
-
* Polls `getEVMSponsoredTransactionStatus` until the relay reports the
|
|
473
|
-
* transaction has been included on-chain, then returns the transaction hash.
|
|
474
|
-
*
|
|
475
|
-
* @param params.requestId - The request ID returned when the transaction was relayed.
|
|
476
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
477
|
-
* @returns An object containing the on-chain transaction hash.
|
|
478
|
-
* @throws {SponsorTransactionError} If the relay returns a terminal failure or polling times out.
|
|
479
|
-
* @not-instrumented
|
|
480
|
-
*/
|
|
481
|
-
const waitForSponsoredTransaction = async ({ requestId }, client = getDefaultClient()) => {
|
|
482
|
-
for (let attempt = 0; attempt < MAX_POLLING_ATTEMPTS; attempt++) {
|
|
483
|
-
const result = await getEVMSponsoredTransactionStatus({ requestId }, client);
|
|
484
|
-
if (TERMINAL_FAILURE_STATUSES.has(result.status)) throw new SponsorTransactionError(null, result.errorMessage);
|
|
485
|
-
if (result.transactionHash) return { transactionHash: result.transactionHash };
|
|
486
|
-
if (attempt < MAX_POLLING_ATTEMPTS - 1) await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
487
|
-
}
|
|
488
|
-
throw new SponsorTransactionError(null, `Timed out waiting for sponsored transaction ${requestId}`);
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
//#endregion
|
|
492
|
-
//#region src/gasless/sendSponsoredTransaction/sendSponsoredTransaction.ts
|
|
493
|
-
/**
|
|
494
|
-
* Sends a sponsored EVM transaction and waits for on-chain inclusion.
|
|
495
|
-
*
|
|
496
|
-
* Accepts either a pre-signed transaction or unsigned calls. When given
|
|
497
|
-
* unsigned calls, signs the transaction first via signSponsoredTransaction.
|
|
498
|
-
* Relays the transaction and resolves as soon as the relay reports the
|
|
499
|
-
* transaction has been included on-chain.
|
|
500
|
-
*
|
|
501
|
-
* @param params - Either { signedTransaction } or { walletAccount, calls, ... }.
|
|
502
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
503
|
-
* @returns An object containing the on-chain transaction hash.
|
|
504
|
-
* @throws {SponsorTransactionError} If the relay returns a terminal failure or polling times out.
|
|
505
|
-
* @not-instrumented
|
|
506
|
-
*/
|
|
507
|
-
const sendSponsoredTransaction = async (params, client = getDefaultClient()) => {
|
|
508
|
-
const { requestId } = await relaySponsoredTransaction(params, client);
|
|
509
|
-
return waitForSponsoredTransaction({ requestId }, client);
|
|
510
|
-
};
|
|
511
|
-
|
|
512
|
-
//#endregion
|
|
513
11
|
//#region src/gasless/activate7702Delegation/activate7702Delegation.ts
|
|
514
12
|
/**
|
|
515
13
|
* Activates EIP-7702 delegation for a wallet by sending a sponsored
|
|
@@ -563,20 +61,6 @@ var EvmGasSponsorshipNotEnabledError = class extends BaseError {
|
|
|
563
61
|
}
|
|
564
62
|
};
|
|
565
63
|
|
|
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 = getDefaultClient()) => {
|
|
576
|
-
assertDefined(client.projectSettings, "Project settings are not defined");
|
|
577
|
-
return client.projectSettings.sdk.embeddedWallets?.evmGasSponsorshipEnabled ?? false;
|
|
578
|
-
};
|
|
579
|
-
|
|
580
64
|
//#endregion
|
|
581
65
|
//#region src/isEvmNetworkProvider/isEvmNetworkProvider.ts
|
|
582
66
|
/**
|