@dynamic-labs-sdk/zerodev 0.1.2 → 0.2.3
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/KernelClient.types.d.ts.map +1 -0
- package/{src → dist}/addZerodevExtension/addZerodevExtension.d.ts +1 -1
- package/dist/addZerodevExtension/addZerodevExtension.d.ts.map +1 -0
- package/dist/addZerodevExtension/index.d.ts.map +1 -0
- package/dist/canSponsorTransaction/canSponsorTransaction.d.ts.map +1 -0
- package/dist/canSponsorTransaction/index.d.ts.map +1 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/core.cjs.js +17 -0
- package/dist/core.cjs.js.map +1 -0
- package/dist/core.esm.js +9 -0
- package/dist/core.esm.js.map +1 -0
- package/{src → dist}/createKernelClientForWalletAccount/createKernelClientForWalletAccount.d.ts +1 -1
- package/dist/createKernelClientForWalletAccount/createKernelClientForWalletAccount.d.ts.map +1 -0
- package/dist/createKernelClientForWalletAccount/index.d.ts.map +1 -0
- package/dist/estimateTransactionGas/estimateTransactionGas.d.ts.map +1 -0
- package/dist/estimateTransactionGas/index.d.ts.map +1 -0
- package/dist/exports/core.d.ts.map +1 -0
- package/dist/exports/index.d.ts.map +1 -0
- package/{src → dist}/getSignerForSmartWalletAccount/getSignerForSmartWalletAccount.d.ts +1 -1
- package/dist/getSignerForSmartWalletAccount/getSignerForSmartWalletAccount.d.ts.map +1 -0
- package/dist/getSignerForSmartWalletAccount/index.d.ts.map +1 -0
- package/dist/getZerodevRpc-BWc2Ad-o.esm.js +177 -0
- package/dist/getZerodevRpc-BWc2Ad-o.esm.js.map +1 -0
- package/dist/getZerodevRpc-BuzdzM8R.cjs.js +254 -0
- package/dist/getZerodevRpc-BuzdzM8R.cjs.js.map +1 -0
- package/dist/index.cjs.js +258 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.js +253 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/isGasSponsorshipError/index.d.ts.map +1 -0
- package/dist/isGasSponsorshipError/isGasSponsorshipError.d.ts.map +1 -0
- package/dist/isZerodevWalletAccount/index.d.ts.map +1 -0
- package/dist/isZerodevWalletAccount/isZerodevWalletAccount.d.ts.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/dist/utils/calculateGasForUserOperation/calculateGasForUserOperation.d.ts.map +1 -0
- package/dist/utils/calculateGasForUserOperation/index.d.ts.map +1 -0
- package/dist/utils/createKernelAccount/createKernelAccount.d.ts.map +1 -0
- package/dist/utils/createKernelAccount/index.d.ts.map +1 -0
- package/dist/utils/createZerodevWalletProvider/createZerodevWalletProvider.d.ts.map +1 -0
- package/dist/utils/createZerodevWalletProvider/index.d.ts.map +1 -0
- package/dist/utils/getAllUserZerodevAddresses/getAllUserZerodevAddresses.d.ts.map +1 -0
- package/dist/utils/getAllUserZerodevAddresses/index.d.ts.map +1 -0
- package/dist/utils/getEcdsaValidator/getEcdsaValidator.d.ts.map +1 -0
- package/dist/utils/getEcdsaValidator/index.d.ts.map +1 -0
- package/dist/utils/getEntryPoint/getEntryPoint.d.ts.map +1 -0
- package/dist/utils/getEntryPoint/index.d.ts.map +1 -0
- package/dist/utils/getKernelVersion/getKernelVersion.d.ts.map +1 -0
- package/dist/utils/getKernelVersion/index.d.ts.map +1 -0
- package/dist/utils/getPaymasterConfig/getPaymasterConfig.d.ts.map +1 -0
- package/dist/utils/getPaymasterConfig/index.d.ts.map +1 -0
- package/{src → dist}/utils/getZerodevChainProviderForNetworkId/getZerodevChainProviderForNetworkId.d.ts +1 -1
- package/dist/utils/getZerodevChainProviderForNetworkId/getZerodevChainProviderForNetworkId.d.ts.map +1 -0
- package/dist/utils/getZerodevChainProviderForNetworkId/index.d.ts.map +1 -0
- package/{src → dist}/utils/getZerodevProviderFromSettings/getZerodevProviderFromSettings.d.ts +1 -1
- package/dist/utils/getZerodevProviderFromSettings/getZerodevProviderFromSettings.d.ts.map +1 -0
- package/dist/utils/getZerodevProviderFromSettings/index.d.ts.map +1 -0
- package/{src → dist}/utils/getZerodevRpc/getZerodevRpc.d.ts +1 -1
- package/dist/utils/getZerodevRpc/getZerodevRpc.d.ts.map +1 -0
- package/dist/utils/getZerodevRpc/index.d.ts.map +1 -0
- package/dist/utils/prepareUserOperationWithKernelClient/index.d.ts.map +1 -0
- package/dist/utils/prepareUserOperationWithKernelClient/prepareUserOperationWithKernelClient.d.ts.map +1 -0
- package/dist/utils/shouldSignWithEoa/index.d.ts.map +1 -0
- package/dist/utils/shouldSignWithEoa/shouldSignWithEoa.d.ts.map +1 -0
- package/dist/utils/shouldUseEIP7702/index.d.ts.map +1 -0
- package/{src → dist}/utils/shouldUseEIP7702/shouldUseEIP7702.d.ts +1 -1
- package/dist/utils/shouldUseEIP7702/shouldUseEIP7702.d.ts.map +1 -0
- package/dist/utils/signMessage/index.d.ts.map +1 -0
- package/dist/utils/signMessage/signMessage.d.ts.map +1 -0
- package/package.json +29 -15
- package/CHANGELOG.md +0 -606
- package/core.cjs.d.ts +0 -1
- package/core.cjs.js +0 -25
- package/core.esm.d.ts +0 -1
- package/core.esm.js +0 -14
- package/getZerodevRpc.cjs.js +0 -222
- package/getZerodevRpc.esm.js +0 -208
- package/index.cjs.d.ts +0 -1
- package/index.cjs.js +0 -311
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -305
- package/src/KernelClient.types.d.ts.map +0 -1
- package/src/addZerodevExtension/addZerodevExtension.d.ts.map +0 -1
- package/src/addZerodevExtension/index.d.ts.map +0 -1
- package/src/canSponsorTransaction/canSponsorTransaction.d.ts.map +0 -1
- package/src/canSponsorTransaction/index.d.ts.map +0 -1
- package/src/constants.d.ts.map +0 -1
- package/src/createKernelClientForWalletAccount/createKernelClientForWalletAccount.d.ts.map +0 -1
- package/src/createKernelClientForWalletAccount/index.d.ts.map +0 -1
- package/src/estimateTransactionGas/estimateTransactionGas.d.ts.map +0 -1
- package/src/estimateTransactionGas/index.d.ts.map +0 -1
- package/src/exports/core.d.ts.map +0 -1
- package/src/exports/index.d.ts.map +0 -1
- package/src/getSignerForSmartWalletAccount/getSignerForSmartWalletAccount.d.ts.map +0 -1
- package/src/getSignerForSmartWalletAccount/index.d.ts.map +0 -1
- package/src/isGasSponsorshipError/index.d.ts.map +0 -1
- package/src/isGasSponsorshipError/isGasSponsorshipError.d.ts.map +0 -1
- package/src/isZerodevWalletAccount/index.d.ts.map +0 -1
- package/src/isZerodevWalletAccount/isZerodevWalletAccount.d.ts.map +0 -1
- package/src/utils/calculateGasForUserOperation/calculateGasForUserOperation.d.ts.map +0 -1
- package/src/utils/calculateGasForUserOperation/index.d.ts.map +0 -1
- package/src/utils/createKernelAccount/createKernelAccount.d.ts.map +0 -1
- package/src/utils/createKernelAccount/index.d.ts.map +0 -1
- package/src/utils/createZerodevWalletProvider/createZerodevWalletProvider.d.ts.map +0 -1
- package/src/utils/createZerodevWalletProvider/index.d.ts.map +0 -1
- package/src/utils/getAllUserZerodevAddresses/getAllUserZerodevAddresses.d.ts.map +0 -1
- package/src/utils/getAllUserZerodevAddresses/index.d.ts.map +0 -1
- package/src/utils/getEcdsaValidator/getEcdsaValidator.d.ts.map +0 -1
- package/src/utils/getEcdsaValidator/index.d.ts.map +0 -1
- package/src/utils/getEntryPoint/getEntryPoint.d.ts.map +0 -1
- package/src/utils/getEntryPoint/index.d.ts.map +0 -1
- package/src/utils/getKernelVersion/getKernelVersion.d.ts.map +0 -1
- package/src/utils/getKernelVersion/index.d.ts.map +0 -1
- package/src/utils/getPaymasterConfig/getPaymasterConfig.d.ts.map +0 -1
- package/src/utils/getPaymasterConfig/index.d.ts.map +0 -1
- package/src/utils/getZerodevChainProviderForNetworkId/getZerodevChainProviderForNetworkId.d.ts.map +0 -1
- package/src/utils/getZerodevChainProviderForNetworkId/index.d.ts.map +0 -1
- package/src/utils/getZerodevProviderFromSettings/getZerodevProviderFromSettings.d.ts.map +0 -1
- package/src/utils/getZerodevProviderFromSettings/index.d.ts.map +0 -1
- package/src/utils/getZerodevRpc/getZerodevRpc.d.ts.map +0 -1
- package/src/utils/getZerodevRpc/index.d.ts.map +0 -1
- package/src/utils/prepareUserOperationWithKernelClient/index.d.ts.map +0 -1
- package/src/utils/prepareUserOperationWithKernelClient/prepareUserOperationWithKernelClient.d.ts.map +0 -1
- package/src/utils/shouldSignWithEoa/index.d.ts.map +0 -1
- package/src/utils/shouldSignWithEoa/shouldSignWithEoa.d.ts.map +0 -1
- package/src/utils/shouldUseEIP7702/index.d.ts.map +0 -1
- package/src/utils/shouldUseEIP7702/shouldUseEIP7702.d.ts.map +0 -1
- package/src/utils/signMessage/index.d.ts.map +0 -1
- package/src/utils/signMessage/signMessage.d.ts.map +0 -1
- /package/{src → dist}/KernelClient.types.d.ts +0 -0
- /package/{src → dist}/addZerodevExtension/index.d.ts +0 -0
- /package/{src → dist}/canSponsorTransaction/canSponsorTransaction.d.ts +0 -0
- /package/{src → dist}/canSponsorTransaction/index.d.ts +0 -0
- /package/{src → dist}/constants.d.ts +0 -0
- /package/{src → dist}/createKernelClientForWalletAccount/index.d.ts +0 -0
- /package/{src → dist}/estimateTransactionGas/estimateTransactionGas.d.ts +0 -0
- /package/{src → dist}/estimateTransactionGas/index.d.ts +0 -0
- /package/{src → dist}/exports/core.d.ts +0 -0
- /package/{src → dist}/exports/index.d.ts +0 -0
- /package/{src → dist}/getSignerForSmartWalletAccount/index.d.ts +0 -0
- /package/{src → dist}/isGasSponsorshipError/index.d.ts +0 -0
- /package/{src → dist}/isGasSponsorshipError/isGasSponsorshipError.d.ts +0 -0
- /package/{src → dist}/isZerodevWalletAccount/index.d.ts +0 -0
- /package/{src → dist}/isZerodevWalletAccount/isZerodevWalletAccount.d.ts +0 -0
- /package/{src → dist}/utils/calculateGasForUserOperation/calculateGasForUserOperation.d.ts +0 -0
- /package/{src → dist}/utils/calculateGasForUserOperation/index.d.ts +0 -0
- /package/{src → dist}/utils/createKernelAccount/createKernelAccount.d.ts +0 -0
- /package/{src → dist}/utils/createKernelAccount/index.d.ts +0 -0
- /package/{src → dist}/utils/createZerodevWalletProvider/createZerodevWalletProvider.d.ts +0 -0
- /package/{src → dist}/utils/createZerodevWalletProvider/index.d.ts +0 -0
- /package/{src → dist}/utils/getAllUserZerodevAddresses/getAllUserZerodevAddresses.d.ts +0 -0
- /package/{src → dist}/utils/getAllUserZerodevAddresses/index.d.ts +0 -0
- /package/{src → dist}/utils/getEcdsaValidator/getEcdsaValidator.d.ts +0 -0
- /package/{src → dist}/utils/getEcdsaValidator/index.d.ts +0 -0
- /package/{src → dist}/utils/getEntryPoint/getEntryPoint.d.ts +0 -0
- /package/{src → dist}/utils/getEntryPoint/index.d.ts +0 -0
- /package/{src → dist}/utils/getKernelVersion/getKernelVersion.d.ts +0 -0
- /package/{src → dist}/utils/getKernelVersion/index.d.ts +0 -0
- /package/{src → dist}/utils/getPaymasterConfig/getPaymasterConfig.d.ts +0 -0
- /package/{src → dist}/utils/getPaymasterConfig/index.d.ts +0 -0
- /package/{src → dist}/utils/getZerodevChainProviderForNetworkId/index.d.ts +0 -0
- /package/{src → dist}/utils/getZerodevProviderFromSettings/index.d.ts +0 -0
- /package/{src → dist}/utils/getZerodevRpc/index.d.ts +0 -0
- /package/{src → dist}/utils/prepareUserOperationWithKernelClient/index.d.ts +0 -0
- /package/{src → dist}/utils/prepareUserOperationWithKernelClient/prepareUserOperationWithKernelClient.d.ts +0 -0
- /package/{src → dist}/utils/shouldSignWithEoa/index.d.ts +0 -0
- /package/{src → dist}/utils/shouldSignWithEoa/shouldSignWithEoa.d.ts +0 -0
- /package/{src → dist}/utils/shouldUseEIP7702/index.d.ts +0 -0
- /package/{src → dist}/utils/signMessage/index.d.ts +0 -0
- /package/{src → dist}/utils/signMessage/signMessage.d.ts +0 -0
package/index.cjs.js
DELETED
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var assertPackageVersion = require('@dynamic-labs-sdk/assert-package-version');
|
|
4
|
-
var getZerodevRpc = require('./getZerodevRpc.cjs.js');
|
|
5
|
-
var core = require('@dynamic-labs-sdk/client/core');
|
|
6
|
-
var client = require('@dynamic-labs-sdk/client');
|
|
7
|
-
var evm = require('@dynamic-labs-sdk/evm');
|
|
8
|
-
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
9
|
-
var viem = require('@dynamic-labs-sdk/evm/viem');
|
|
10
|
-
var sdk = require('@zerodev/sdk');
|
|
11
|
-
var viem$1 = require('viem');
|
|
12
|
-
require('@zerodev/ecdsa-validator');
|
|
13
|
-
require('@zerodev/multi-chain-ecdsa-validator');
|
|
14
|
-
|
|
15
|
-
const getAllUserZerodevAddresses = (client)=>{
|
|
16
|
-
var _client_user;
|
|
17
|
-
var _client_user_verifiedCredentials_filter;
|
|
18
|
-
const zerodevWalletCredentials = (_client_user_verifiedCredentials_filter = (_client_user = client.user) == null ? void 0 : _client_user.verifiedCredentials.filter((credential)=>{
|
|
19
|
-
var _credential_walletName;
|
|
20
|
-
return credential.walletProvider === sdkApiCore.WalletProviderEnum.SmartContractWallet && ((_credential_walletName = credential.walletName) == null ? void 0 : _credential_walletName.toLowerCase().startsWith(getZerodevRpc.ZERODEV_METADATA.normalizedWalletName)) && credential.address && credential.chain && core.getChainFromVerifiedCredentialChain(credential.chain) === 'EVM';
|
|
21
|
-
})) != null ? _client_user_verifiedCredentials_filter : [];
|
|
22
|
-
const zerodevAddresses = zerodevWalletCredentials.map(// casting because we're already filtering out credentials without an address
|
|
23
|
-
(credential)=>credential.address);
|
|
24
|
-
return zerodevAddresses;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
function _extends() {
|
|
28
|
-
_extends = Object.assign || function assign(target) {
|
|
29
|
-
for(var i = 1; i < arguments.length; i++){
|
|
30
|
-
var source = arguments[i];
|
|
31
|
-
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
32
|
-
}
|
|
33
|
-
return target;
|
|
34
|
-
};
|
|
35
|
-
return _extends.apply(this, arguments);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Creates a KernelClient instance for a given smart wallet account.
|
|
40
|
-
*
|
|
41
|
-
* @param params.smartWalletAccount - The smart wallet account to create the KernelClient for.
|
|
42
|
-
* @param [params.bundlerProvider] - A custom bundler provider to use
|
|
43
|
-
* @param [params.bundlerRpc] - A custom bundler RPC to use
|
|
44
|
-
* @param [params.networkId] - The network ID to use for the KernelClient.
|
|
45
|
-
* If not provided, the network ID will be fetched from the active network data.
|
|
46
|
-
* @param [params.paymasterRpc] - A custom paymaster RPC to use
|
|
47
|
-
* @param [params.gasTokenAddress] - The address of a custom ERC20 token to use as a gas token
|
|
48
|
-
* @param [params.withSponsorship] - Whether to use sponsorship for the KernelClient or not (default is true).
|
|
49
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
50
|
-
* @returns A promise that resolves to a KernelClient instance.
|
|
51
|
-
*/ const createKernelClientForWalletAccount = async ({ smartWalletAccount, withSponsorship = true, bundlerProvider, networkId, bundlerRpc: bundlerRpcOverride, paymasterRpc: paymasterRpcOverride, gasTokenAddress }, client$1 = core.getDefaultClient())=>{
|
|
52
|
-
let networkData;
|
|
53
|
-
if (networkId) {
|
|
54
|
-
networkData = core.getNetworkDataForNetworkId({
|
|
55
|
-
chain: 'EVM',
|
|
56
|
-
networkId
|
|
57
|
-
}, client$1);
|
|
58
|
-
core.assertDefined(networkData, `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`);
|
|
59
|
-
} else {
|
|
60
|
-
const activeNetworkData = await client.getActiveNetworkData({
|
|
61
|
-
walletAccount: smartWalletAccount
|
|
62
|
-
}, client$1);
|
|
63
|
-
networkData = activeNetworkData.networkData;
|
|
64
|
-
core.assertDefined(networkData, `No active network data found for this wallet account.`);
|
|
65
|
-
}
|
|
66
|
-
const viemChain = viem.mapNetworkDataToViemChain(networkData);
|
|
67
|
-
const bundlerRpc = bundlerRpcOverride != null ? bundlerRpcOverride : getZerodevRpc.getZerodevRpc({
|
|
68
|
-
bundlerProvider,
|
|
69
|
-
networkId: networkData.networkId,
|
|
70
|
-
rpcType: 'bundler'
|
|
71
|
-
}, client$1);
|
|
72
|
-
const bundlerTransport = viem$1.http(bundlerRpc);
|
|
73
|
-
const publicClient = viem$1.createPublicClient({
|
|
74
|
-
chain: viemChain,
|
|
75
|
-
transport: bundlerTransport
|
|
76
|
-
});
|
|
77
|
-
const account = await getZerodevRpc.createKernelAccount({
|
|
78
|
-
publicClient,
|
|
79
|
-
smartWalletAccount
|
|
80
|
-
}, client$1);
|
|
81
|
-
const paymasterRpc = paymasterRpcOverride != null ? paymasterRpcOverride : getZerodevRpc.getZerodevRpc({
|
|
82
|
-
bundlerProvider,
|
|
83
|
-
networkId: networkData.networkId,
|
|
84
|
-
rpcType: 'paymaster'
|
|
85
|
-
}, client$1);
|
|
86
|
-
const paymasterConfig = withSponsorship ? getZerodevRpc.getPaymasterConfig({
|
|
87
|
-
chain: viemChain,
|
|
88
|
-
gasTokenAddress,
|
|
89
|
-
paymasterRpc
|
|
90
|
-
}) : {};
|
|
91
|
-
return sdk.createKernelAccountClient(_extends({
|
|
92
|
-
account,
|
|
93
|
-
bundlerTransport,
|
|
94
|
-
chain: viemChain,
|
|
95
|
-
client: publicClient,
|
|
96
|
-
userOperation: {
|
|
97
|
-
estimateFeesPerGas: async ({ bundlerClient })=>sdk.getUserOperationGasPrice(bundlerClient)
|
|
98
|
-
}
|
|
99
|
-
}, paymasterConfig));
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const shouldSignWithEoa = async ({ kernelClient, smartWalletAccount }, client)=>{
|
|
103
|
-
const useEIP7702 = getZerodevRpc.shouldUseEIP7702({
|
|
104
|
-
smartWalletAccount
|
|
105
|
-
}, client);
|
|
106
|
-
if (!useEIP7702) {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
const isDeployed = await kernelClient.account.isDeployed();
|
|
110
|
-
return !isDeployed;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const signMessage = async ({ walletAccount, message }, client$1)=>{
|
|
114
|
-
const kernelClient = await createKernelClientForWalletAccount({
|
|
115
|
-
smartWalletAccount: walletAccount
|
|
116
|
-
}, client$1);
|
|
117
|
-
const shouldUseEoa = await shouldSignWithEoa({
|
|
118
|
-
kernelClient,
|
|
119
|
-
smartWalletAccount: walletAccount
|
|
120
|
-
}, client$1);
|
|
121
|
-
if (shouldUseEoa) {
|
|
122
|
-
const eoaWalletAccount = client.getOwnerWalletAccountForSmartWalletAccount({
|
|
123
|
-
smartWalletAccount: walletAccount
|
|
124
|
-
}, client$1);
|
|
125
|
-
core.assertDefined(eoaWalletAccount, 'Eoa wallet account not found');
|
|
126
|
-
const { signature } = await client.signMessage({
|
|
127
|
-
message,
|
|
128
|
-
walletAccount: eoaWalletAccount
|
|
129
|
-
});
|
|
130
|
-
return {
|
|
131
|
-
signature
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
const signature = await kernelClient.signMessage({
|
|
135
|
-
message
|
|
136
|
-
});
|
|
137
|
-
return {
|
|
138
|
-
signature
|
|
139
|
-
};
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const createZerodevWalletProvider = (client$1)=>{
|
|
143
|
-
const chain = 'EVM';
|
|
144
|
-
const walletProviderType = sdkApiCore.WalletProviderEnum.SmartContractWallet;
|
|
145
|
-
const key = core.formatWalletProviderKey({
|
|
146
|
-
chain,
|
|
147
|
-
displayName: getZerodevRpc.ZERODEV_METADATA.displayName,
|
|
148
|
-
walletProviderType
|
|
149
|
-
});
|
|
150
|
-
const getActiveNetworkId = async ()=>core.getActiveNetworkIdFromLastKnownRegistry({
|
|
151
|
-
client: client$1,
|
|
152
|
-
walletProviderKey: key
|
|
153
|
-
});
|
|
154
|
-
const getConnectedAddresses = async ()=>{
|
|
155
|
-
const zerodevAddresses = getAllUserZerodevAddresses(client$1);
|
|
156
|
-
return {
|
|
157
|
-
addresses: zerodevAddresses
|
|
158
|
-
};
|
|
159
|
-
};
|
|
160
|
-
const signMessage$1 = async ({ walletAccount, message })=>{
|
|
161
|
-
core.assertDefined(walletAccount, 'Wallet account is required');
|
|
162
|
-
if (!evm.isEvmWalletAccount(walletAccount)) {
|
|
163
|
-
throw new client.InvalidParamError(`walletAccount is not an EVM wallet account`);
|
|
164
|
-
}
|
|
165
|
-
return signMessage({
|
|
166
|
-
message,
|
|
167
|
-
walletAccount
|
|
168
|
-
}, client$1);
|
|
169
|
-
};
|
|
170
|
-
const switchActiveNetwork = async ({ networkId })=>{
|
|
171
|
-
const isNetworkEnabled = getZerodevRpc.getZerodevChainProviderForNetworkId({
|
|
172
|
-
networkId
|
|
173
|
-
}, client$1);
|
|
174
|
-
if (!isNetworkEnabled) {
|
|
175
|
-
throw new client.UnrecognizedNetworkError({
|
|
176
|
-
networkId,
|
|
177
|
-
originalError: null,
|
|
178
|
-
walletProviderKey: key
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
return core.switchActiveNetworkInLastKnownRegistry({
|
|
182
|
-
client: client$1,
|
|
183
|
-
networkId,
|
|
184
|
-
walletProviderKey: key
|
|
185
|
-
});
|
|
186
|
-
};
|
|
187
|
-
return {
|
|
188
|
-
chain,
|
|
189
|
-
getActiveNetworkId,
|
|
190
|
-
getConnectedAddresses,
|
|
191
|
-
groupKey: core.formatWalletProviderGroupKey(getZerodevRpc.ZERODEV_METADATA.displayName),
|
|
192
|
-
key,
|
|
193
|
-
metadata: {
|
|
194
|
-
displayName: getZerodevRpc.ZERODEV_METADATA.displayName,
|
|
195
|
-
icon: getZerodevRpc.ZERODEV_METADATA.icon
|
|
196
|
-
},
|
|
197
|
-
signMessage: signMessage$1,
|
|
198
|
-
switchActiveNetwork,
|
|
199
|
-
walletProviderType
|
|
200
|
-
};
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const ZERODEV_EXTENSION_KEY = 'zerodev';
|
|
204
|
-
/**
|
|
205
|
-
* Adds the ZeroDev extension to the Dynamic client.
|
|
206
|
-
*
|
|
207
|
-
* This extension enables Account Abstraction integration with ZeroDev
|
|
208
|
-
*
|
|
209
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
210
|
-
*/ const addZerodevExtension = (client = core.getDefaultClient())=>{
|
|
211
|
-
if (core.hasExtension({
|
|
212
|
-
extensionKey: ZERODEV_EXTENSION_KEY
|
|
213
|
-
}, client)) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
core.registerExtension({
|
|
217
|
-
extensionKey: ZERODEV_EXTENSION_KEY
|
|
218
|
-
}, client);
|
|
219
|
-
const walletProviderRegistry = core.getWalletProviderRegistry(client);
|
|
220
|
-
const walletProvider = createZerodevWalletProvider(client);
|
|
221
|
-
walletProviderRegistry.register({
|
|
222
|
-
priority: core.WalletProviderPriority.WALLET_SDK,
|
|
223
|
-
walletProvider
|
|
224
|
-
});
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
const prepareUserOperationWithKernelClient = async ({ kernelClient, transaction })=>{
|
|
228
|
-
var _transaction_data;
|
|
229
|
-
const callData = await kernelClient.account.encodeCalls([
|
|
230
|
-
{
|
|
231
|
-
data: (_transaction_data = transaction.data) != null ? _transaction_data : '0x',
|
|
232
|
-
to: transaction.to,
|
|
233
|
-
value: transaction.value
|
|
234
|
-
}
|
|
235
|
-
]);
|
|
236
|
-
return kernelClient.prepareUserOperation({
|
|
237
|
-
callData
|
|
238
|
-
});
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Checks if a transaction can be sponsored
|
|
243
|
-
* @param params.transaction - The transaction to check if it can be sponsored
|
|
244
|
-
* @param params.kernelClient - The kernel client to use to check if the transaction can be sponsored. If no provided, a walletAccount is required to create a kernel client with sponsorship.
|
|
245
|
-
* @param params.walletAccount - The wallet account that will be used to send the transaction, Only required if no kernel client is provided
|
|
246
|
-
* @returns True if the transaction can be sponsored, false otherwise
|
|
247
|
-
*/ const canSponsorTransaction = async ({ walletAccount, transaction, kernelClient })=>{
|
|
248
|
-
let kernelClientToUse = kernelClient;
|
|
249
|
-
if (!kernelClientToUse) {
|
|
250
|
-
core.assertDefined(walletAccount, 'Please provide either a wallet account or a kernel client in the parameters');
|
|
251
|
-
kernelClientToUse = await createKernelClientForWalletAccount({
|
|
252
|
-
smartWalletAccount: walletAccount
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
try {
|
|
256
|
-
const sponsorResult = await prepareUserOperationWithKernelClient({
|
|
257
|
-
kernelClient: kernelClientToUse,
|
|
258
|
-
transaction
|
|
259
|
-
});
|
|
260
|
-
const hasPaymaster = sponsorResult.paymasterAndData !== '0x';
|
|
261
|
-
return hasPaymaster;
|
|
262
|
-
} catch (e) {
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
const calculateGasForUserOperation = ({ userOperationData })=>{
|
|
268
|
-
// Sum all gas units
|
|
269
|
-
const totalGasUnits = userOperationData.callGasLimit + userOperationData.verificationGasLimit + userOperationData.preVerificationGas;
|
|
270
|
-
// Multiply by maxFeePerGas to get the total gas cost in wei
|
|
271
|
-
const gasCost = totalGasUnits * userOperationData.maxFeePerGas;
|
|
272
|
-
return gasCost;
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Estimates the total gas for a transaction
|
|
277
|
-
* @param params.transaction - The transaction to estimate the gas for
|
|
278
|
-
* @param params.walletAccount - The wallet account that will be used to send the transaction
|
|
279
|
-
* @returns The gas for the transaction in wei
|
|
280
|
-
*/ const estimateTransactionGas = async ({ walletAccount, transaction })=>{
|
|
281
|
-
try {
|
|
282
|
-
const kernelClientWithoutSponsorship = await createKernelClientForWalletAccount({
|
|
283
|
-
smartWalletAccount: walletAccount,
|
|
284
|
-
withSponsorship: false
|
|
285
|
-
});
|
|
286
|
-
const unsponsoredUserOperation = await prepareUserOperationWithKernelClient({
|
|
287
|
-
kernelClient: kernelClientWithoutSponsorship,
|
|
288
|
-
transaction
|
|
289
|
-
});
|
|
290
|
-
return calculateGasForUserOperation({
|
|
291
|
-
userOperationData: unsponsoredUserOperation
|
|
292
|
-
});
|
|
293
|
-
} catch (e) {
|
|
294
|
-
return null;
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
const isGasSponsorshipError = (err)=>{
|
|
299
|
-
var _errorWithMessage_message;
|
|
300
|
-
const errorWithMessage = err;
|
|
301
|
-
return (errorWithMessage == null ? void 0 : (_errorWithMessage_message = errorWithMessage.message) == null ? void 0 : _errorWithMessage_message.includes('userOp did not match any gas sponsoring policies')) || false;
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
assertPackageVersion.assertPackageVersion(getZerodevRpc.name, getZerodevRpc.version);
|
|
305
|
-
|
|
306
|
-
exports.getSignerForSmartWalletAccount = getZerodevRpc.getSignerForSmartWalletAccount;
|
|
307
|
-
exports.addZerodevExtension = addZerodevExtension;
|
|
308
|
-
exports.canSponsorTransaction = canSponsorTransaction;
|
|
309
|
-
exports.createKernelClientForWalletAccount = createKernelClientForWalletAccount;
|
|
310
|
-
exports.estimateTransactionGas = estimateTransactionGas;
|
|
311
|
-
exports.isGasSponsorshipError = isGasSponsorshipError;
|
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/exports/index";
|
package/index.esm.js
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';
|
|
2
|
-
import { Z as ZERODEV_METADATA, g as getZerodevRpc, c as createKernelAccount, a as getPaymasterConfig, s as shouldUseEIP7702, b as getZerodevChainProviderForNetworkId, n as name, v as version } from './getZerodevRpc.esm.js';
|
|
3
|
-
export { d as getSignerForSmartWalletAccount } from './getZerodevRpc.esm.js';
|
|
4
|
-
import { getChainFromVerifiedCredentialChain, getDefaultClient, getNetworkDataForNetworkId, assertDefined, formatWalletProviderKey, formatWalletProviderGroupKey, getActiveNetworkIdFromLastKnownRegistry, switchActiveNetworkInLastKnownRegistry, hasExtension, registerExtension, getWalletProviderRegistry, WalletProviderPriority } from '@dynamic-labs-sdk/client/core';
|
|
5
|
-
import { getActiveNetworkData, getOwnerWalletAccountForSmartWalletAccount, signMessage as signMessage$1, UnrecognizedNetworkError, InvalidParamError } from '@dynamic-labs-sdk/client';
|
|
6
|
-
import { isEvmWalletAccount } from '@dynamic-labs-sdk/evm';
|
|
7
|
-
import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
8
|
-
import { mapNetworkDataToViemChain } from '@dynamic-labs-sdk/evm/viem';
|
|
9
|
-
import { createKernelAccountClient, getUserOperationGasPrice } from '@zerodev/sdk';
|
|
10
|
-
import { http, createPublicClient } from 'viem';
|
|
11
|
-
import '@zerodev/ecdsa-validator';
|
|
12
|
-
import '@zerodev/multi-chain-ecdsa-validator';
|
|
13
|
-
|
|
14
|
-
const getAllUserZerodevAddresses = (client)=>{
|
|
15
|
-
var _client_user;
|
|
16
|
-
var _client_user_verifiedCredentials_filter;
|
|
17
|
-
const zerodevWalletCredentials = (_client_user_verifiedCredentials_filter = (_client_user = client.user) == null ? void 0 : _client_user.verifiedCredentials.filter((credential)=>{
|
|
18
|
-
var _credential_walletName;
|
|
19
|
-
return credential.walletProvider === WalletProviderEnum.SmartContractWallet && ((_credential_walletName = credential.walletName) == null ? void 0 : _credential_walletName.toLowerCase().startsWith(ZERODEV_METADATA.normalizedWalletName)) && credential.address && credential.chain && getChainFromVerifiedCredentialChain(credential.chain) === 'EVM';
|
|
20
|
-
})) != null ? _client_user_verifiedCredentials_filter : [];
|
|
21
|
-
const zerodevAddresses = zerodevWalletCredentials.map(// casting because we're already filtering out credentials without an address
|
|
22
|
-
(credential)=>credential.address);
|
|
23
|
-
return zerodevAddresses;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function _extends() {
|
|
27
|
-
_extends = Object.assign || function assign(target) {
|
|
28
|
-
for(var i = 1; i < arguments.length; i++){
|
|
29
|
-
var source = arguments[i];
|
|
30
|
-
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
31
|
-
}
|
|
32
|
-
return target;
|
|
33
|
-
};
|
|
34
|
-
return _extends.apply(this, arguments);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Creates a KernelClient instance for a given smart wallet account.
|
|
39
|
-
*
|
|
40
|
-
* @param params.smartWalletAccount - The smart wallet account to create the KernelClient for.
|
|
41
|
-
* @param [params.bundlerProvider] - A custom bundler provider to use
|
|
42
|
-
* @param [params.bundlerRpc] - A custom bundler RPC to use
|
|
43
|
-
* @param [params.networkId] - The network ID to use for the KernelClient.
|
|
44
|
-
* If not provided, the network ID will be fetched from the active network data.
|
|
45
|
-
* @param [params.paymasterRpc] - A custom paymaster RPC to use
|
|
46
|
-
* @param [params.gasTokenAddress] - The address of a custom ERC20 token to use as a gas token
|
|
47
|
-
* @param [params.withSponsorship] - Whether to use sponsorship for the KernelClient or not (default is true).
|
|
48
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
49
|
-
* @returns A promise that resolves to a KernelClient instance.
|
|
50
|
-
*/ const createKernelClientForWalletAccount = async ({ smartWalletAccount, withSponsorship = true, bundlerProvider, networkId, bundlerRpc: bundlerRpcOverride, paymasterRpc: paymasterRpcOverride, gasTokenAddress }, client = getDefaultClient())=>{
|
|
51
|
-
let networkData;
|
|
52
|
-
if (networkId) {
|
|
53
|
-
networkData = getNetworkDataForNetworkId({
|
|
54
|
-
chain: 'EVM',
|
|
55
|
-
networkId
|
|
56
|
-
}, client);
|
|
57
|
-
assertDefined(networkData, `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`);
|
|
58
|
-
} else {
|
|
59
|
-
const activeNetworkData = await getActiveNetworkData({
|
|
60
|
-
walletAccount: smartWalletAccount
|
|
61
|
-
}, client);
|
|
62
|
-
networkData = activeNetworkData.networkData;
|
|
63
|
-
assertDefined(networkData, `No active network data found for this wallet account.`);
|
|
64
|
-
}
|
|
65
|
-
const viemChain = mapNetworkDataToViemChain(networkData);
|
|
66
|
-
const bundlerRpc = bundlerRpcOverride != null ? bundlerRpcOverride : getZerodevRpc({
|
|
67
|
-
bundlerProvider,
|
|
68
|
-
networkId: networkData.networkId,
|
|
69
|
-
rpcType: 'bundler'
|
|
70
|
-
}, client);
|
|
71
|
-
const bundlerTransport = http(bundlerRpc);
|
|
72
|
-
const publicClient = createPublicClient({
|
|
73
|
-
chain: viemChain,
|
|
74
|
-
transport: bundlerTransport
|
|
75
|
-
});
|
|
76
|
-
const account = await createKernelAccount({
|
|
77
|
-
publicClient,
|
|
78
|
-
smartWalletAccount
|
|
79
|
-
}, client);
|
|
80
|
-
const paymasterRpc = paymasterRpcOverride != null ? paymasterRpcOverride : getZerodevRpc({
|
|
81
|
-
bundlerProvider,
|
|
82
|
-
networkId: networkData.networkId,
|
|
83
|
-
rpcType: 'paymaster'
|
|
84
|
-
}, client);
|
|
85
|
-
const paymasterConfig = withSponsorship ? getPaymasterConfig({
|
|
86
|
-
chain: viemChain,
|
|
87
|
-
gasTokenAddress,
|
|
88
|
-
paymasterRpc
|
|
89
|
-
}) : {};
|
|
90
|
-
return createKernelAccountClient(_extends({
|
|
91
|
-
account,
|
|
92
|
-
bundlerTransport,
|
|
93
|
-
chain: viemChain,
|
|
94
|
-
client: publicClient,
|
|
95
|
-
userOperation: {
|
|
96
|
-
estimateFeesPerGas: async ({ bundlerClient })=>getUserOperationGasPrice(bundlerClient)
|
|
97
|
-
}
|
|
98
|
-
}, paymasterConfig));
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const shouldSignWithEoa = async ({ kernelClient, smartWalletAccount }, client)=>{
|
|
102
|
-
const useEIP7702 = shouldUseEIP7702({
|
|
103
|
-
smartWalletAccount
|
|
104
|
-
}, client);
|
|
105
|
-
if (!useEIP7702) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
const isDeployed = await kernelClient.account.isDeployed();
|
|
109
|
-
return !isDeployed;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const signMessage = async ({ walletAccount, message }, client)=>{
|
|
113
|
-
const kernelClient = await createKernelClientForWalletAccount({
|
|
114
|
-
smartWalletAccount: walletAccount
|
|
115
|
-
}, client);
|
|
116
|
-
const shouldUseEoa = await shouldSignWithEoa({
|
|
117
|
-
kernelClient,
|
|
118
|
-
smartWalletAccount: walletAccount
|
|
119
|
-
}, client);
|
|
120
|
-
if (shouldUseEoa) {
|
|
121
|
-
const eoaWalletAccount = getOwnerWalletAccountForSmartWalletAccount({
|
|
122
|
-
smartWalletAccount: walletAccount
|
|
123
|
-
}, client);
|
|
124
|
-
assertDefined(eoaWalletAccount, 'Eoa wallet account not found');
|
|
125
|
-
const { signature } = await signMessage$1({
|
|
126
|
-
message,
|
|
127
|
-
walletAccount: eoaWalletAccount
|
|
128
|
-
});
|
|
129
|
-
return {
|
|
130
|
-
signature
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
const signature = await kernelClient.signMessage({
|
|
134
|
-
message
|
|
135
|
-
});
|
|
136
|
-
return {
|
|
137
|
-
signature
|
|
138
|
-
};
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const createZerodevWalletProvider = (client)=>{
|
|
142
|
-
const chain = 'EVM';
|
|
143
|
-
const walletProviderType = WalletProviderEnum.SmartContractWallet;
|
|
144
|
-
const key = formatWalletProviderKey({
|
|
145
|
-
chain,
|
|
146
|
-
displayName: ZERODEV_METADATA.displayName,
|
|
147
|
-
walletProviderType
|
|
148
|
-
});
|
|
149
|
-
const getActiveNetworkId = async ()=>getActiveNetworkIdFromLastKnownRegistry({
|
|
150
|
-
client,
|
|
151
|
-
walletProviderKey: key
|
|
152
|
-
});
|
|
153
|
-
const getConnectedAddresses = async ()=>{
|
|
154
|
-
const zerodevAddresses = getAllUserZerodevAddresses(client);
|
|
155
|
-
return {
|
|
156
|
-
addresses: zerodevAddresses
|
|
157
|
-
};
|
|
158
|
-
};
|
|
159
|
-
const signMessage$1 = async ({ walletAccount, message })=>{
|
|
160
|
-
assertDefined(walletAccount, 'Wallet account is required');
|
|
161
|
-
if (!isEvmWalletAccount(walletAccount)) {
|
|
162
|
-
throw new InvalidParamError(`walletAccount is not an EVM wallet account`);
|
|
163
|
-
}
|
|
164
|
-
return signMessage({
|
|
165
|
-
message,
|
|
166
|
-
walletAccount
|
|
167
|
-
}, client);
|
|
168
|
-
};
|
|
169
|
-
const switchActiveNetwork = async ({ networkId })=>{
|
|
170
|
-
const isNetworkEnabled = getZerodevChainProviderForNetworkId({
|
|
171
|
-
networkId
|
|
172
|
-
}, client);
|
|
173
|
-
if (!isNetworkEnabled) {
|
|
174
|
-
throw new UnrecognizedNetworkError({
|
|
175
|
-
networkId,
|
|
176
|
-
originalError: null,
|
|
177
|
-
walletProviderKey: key
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
return switchActiveNetworkInLastKnownRegistry({
|
|
181
|
-
client,
|
|
182
|
-
networkId,
|
|
183
|
-
walletProviderKey: key
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
return {
|
|
187
|
-
chain,
|
|
188
|
-
getActiveNetworkId,
|
|
189
|
-
getConnectedAddresses,
|
|
190
|
-
groupKey: formatWalletProviderGroupKey(ZERODEV_METADATA.displayName),
|
|
191
|
-
key,
|
|
192
|
-
metadata: {
|
|
193
|
-
displayName: ZERODEV_METADATA.displayName,
|
|
194
|
-
icon: ZERODEV_METADATA.icon
|
|
195
|
-
},
|
|
196
|
-
signMessage: signMessage$1,
|
|
197
|
-
switchActiveNetwork,
|
|
198
|
-
walletProviderType
|
|
199
|
-
};
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
const ZERODEV_EXTENSION_KEY = 'zerodev';
|
|
203
|
-
/**
|
|
204
|
-
* Adds the ZeroDev extension to the Dynamic client.
|
|
205
|
-
*
|
|
206
|
-
* This extension enables Account Abstraction integration with ZeroDev
|
|
207
|
-
*
|
|
208
|
-
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
209
|
-
*/ const addZerodevExtension = (client = getDefaultClient())=>{
|
|
210
|
-
if (hasExtension({
|
|
211
|
-
extensionKey: ZERODEV_EXTENSION_KEY
|
|
212
|
-
}, client)) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
registerExtension({
|
|
216
|
-
extensionKey: ZERODEV_EXTENSION_KEY
|
|
217
|
-
}, client);
|
|
218
|
-
const walletProviderRegistry = getWalletProviderRegistry(client);
|
|
219
|
-
const walletProvider = createZerodevWalletProvider(client);
|
|
220
|
-
walletProviderRegistry.register({
|
|
221
|
-
priority: WalletProviderPriority.WALLET_SDK,
|
|
222
|
-
walletProvider
|
|
223
|
-
});
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
const prepareUserOperationWithKernelClient = async ({ kernelClient, transaction })=>{
|
|
227
|
-
var _transaction_data;
|
|
228
|
-
const callData = await kernelClient.account.encodeCalls([
|
|
229
|
-
{
|
|
230
|
-
data: (_transaction_data = transaction.data) != null ? _transaction_data : '0x',
|
|
231
|
-
to: transaction.to,
|
|
232
|
-
value: transaction.value
|
|
233
|
-
}
|
|
234
|
-
]);
|
|
235
|
-
return kernelClient.prepareUserOperation({
|
|
236
|
-
callData
|
|
237
|
-
});
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Checks if a transaction can be sponsored
|
|
242
|
-
* @param params.transaction - The transaction to check if it can be sponsored
|
|
243
|
-
* @param params.kernelClient - The kernel client to use to check if the transaction can be sponsored. If no provided, a walletAccount is required to create a kernel client with sponsorship.
|
|
244
|
-
* @param params.walletAccount - The wallet account that will be used to send the transaction, Only required if no kernel client is provided
|
|
245
|
-
* @returns True if the transaction can be sponsored, false otherwise
|
|
246
|
-
*/ const canSponsorTransaction = async ({ walletAccount, transaction, kernelClient })=>{
|
|
247
|
-
let kernelClientToUse = kernelClient;
|
|
248
|
-
if (!kernelClientToUse) {
|
|
249
|
-
assertDefined(walletAccount, 'Please provide either a wallet account or a kernel client in the parameters');
|
|
250
|
-
kernelClientToUse = await createKernelClientForWalletAccount({
|
|
251
|
-
smartWalletAccount: walletAccount
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
try {
|
|
255
|
-
const sponsorResult = await prepareUserOperationWithKernelClient({
|
|
256
|
-
kernelClient: kernelClientToUse,
|
|
257
|
-
transaction
|
|
258
|
-
});
|
|
259
|
-
const hasPaymaster = sponsorResult.paymasterAndData !== '0x';
|
|
260
|
-
return hasPaymaster;
|
|
261
|
-
} catch (e) {
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
const calculateGasForUserOperation = ({ userOperationData })=>{
|
|
267
|
-
// Sum all gas units
|
|
268
|
-
const totalGasUnits = userOperationData.callGasLimit + userOperationData.verificationGasLimit + userOperationData.preVerificationGas;
|
|
269
|
-
// Multiply by maxFeePerGas to get the total gas cost in wei
|
|
270
|
-
const gasCost = totalGasUnits * userOperationData.maxFeePerGas;
|
|
271
|
-
return gasCost;
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Estimates the total gas for a transaction
|
|
276
|
-
* @param params.transaction - The transaction to estimate the gas for
|
|
277
|
-
* @param params.walletAccount - The wallet account that will be used to send the transaction
|
|
278
|
-
* @returns The gas for the transaction in wei
|
|
279
|
-
*/ const estimateTransactionGas = async ({ walletAccount, transaction })=>{
|
|
280
|
-
try {
|
|
281
|
-
const kernelClientWithoutSponsorship = await createKernelClientForWalletAccount({
|
|
282
|
-
smartWalletAccount: walletAccount,
|
|
283
|
-
withSponsorship: false
|
|
284
|
-
});
|
|
285
|
-
const unsponsoredUserOperation = await prepareUserOperationWithKernelClient({
|
|
286
|
-
kernelClient: kernelClientWithoutSponsorship,
|
|
287
|
-
transaction
|
|
288
|
-
});
|
|
289
|
-
return calculateGasForUserOperation({
|
|
290
|
-
userOperationData: unsponsoredUserOperation
|
|
291
|
-
});
|
|
292
|
-
} catch (e) {
|
|
293
|
-
return null;
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
const isGasSponsorshipError = (err)=>{
|
|
298
|
-
var _errorWithMessage_message;
|
|
299
|
-
const errorWithMessage = err;
|
|
300
|
-
return (errorWithMessage == null ? void 0 : (_errorWithMessage_message = errorWithMessage.message) == null ? void 0 : _errorWithMessage_message.includes('userOp did not match any gas sponsoring policies')) || false;
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
assertPackageVersion(name, version);
|
|
304
|
-
|
|
305
|
-
export { addZerodevExtension, canSponsorTransaction, createKernelClientForWalletAccount, estimateTransactionGas, isGasSponsorshipError };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KernelClient.types.d.ts","sourceRoot":"","sources":["../../../../packages/zerodev/src/KernelClient.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,MAAM,MAAM,YAAY,GAAG,mBAAmB,CAC5C,SAAS,EACT,KAAK,EACL,YAAY,EACZ,MAAM,EACN,SAAS,CACV,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addZerodevExtension.d.ts","sourceRoot":"","sources":["../../../../../packages/zerodev/src/addZerodevExtension/addZerodevExtension.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,qBAAqB,YAAY,CAAC;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,wBAe/B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/zerodev/src/addZerodevExtension/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"canSponsorTransaction.d.ts","sourceRoot":"","sources":["../../../../../packages/zerodev/src/canSponsorTransaction/canSponsorTransaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAGhC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAG1D,KAAK,+BAA+B,GAAG;IACrC,WAAW,EAAE;QACX,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,EAAE,EAAE,GAAG,CAAC;QACR,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAEF,KAAK,qCAAqC,GAAG,+BAA+B,GAAG;IAC7E,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,aAAa,EAAE,gBAAgB,CAAC;CACjC,CAAC;AAEF,KAAK,qCAAqC,GAAG,+BAA+B,GAAG;IAC7E,YAAY,EAAE,YAAY,CAAC;IAC3B,aAAa,CAAC,EAAE,KAAK,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GACnC,qCAAqC,GACrC,qCAAqC,CAAC;AAE1C;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,kDAI/B,2BAA2B,KAAG,OAAO,CAAC,OAAO,CA0B/C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/zerodev/src/canSponsorTransaction/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,KAAK,2BAA2B,GACjC,MAAM,yBAAyB,CAAC"}
|
package/src/constants.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../packages/zerodev/src/constants.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,eAAO,MAAM,gBAAgB;;;;CAI5B,CAAC;AAEF,eAAO,MAAM,oBAAoB,mCAAmC,CAAC;AAErE,eAAO,MAAM,kBAAkB;;;;;;CAMrB,CAAC;AAEX,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAC1C,iBAAiB,EACjB,mBAAmB,CAKX,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createKernelClientForWalletAccount.d.ts","sourceRoot":"","sources":["../../../../../packages/zerodev/src/createKernelClientForWalletAccount/createKernelClientForWalletAccount.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAKzE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAGhC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAK1D,KAAK,wCAAwC,GAAG;IAC9C,eAAe,CAAC,EAAE,sBAAsB,CAAC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,GAAG,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,gBAAgB,CAAC;IACrC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,kCAAkC,8JAS1C,wCAAwC,mBAE1C,OAAO,CAAC,YAAY,CAqFtB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/zerodev/src/createKernelClientForWalletAccount/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"estimateTransactionGas.d.ts","sourceRoot":"","sources":["../../../../../packages/zerodev/src/estimateTransactionGas/estimateTransactionGas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAMhC,MAAM,MAAM,4BAA4B,GAAG;IACzC,WAAW,EAAE;QACX,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,EAAE,EAAE,GAAG,CAAC;QACR,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,aAAa,EAAE,gBAAgB,CAAC;CACjC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,oCAGhC,4BAA4B,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAqBtD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/zerodev/src/estimateTransactionGas/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,KAAK,4BAA4B,GAClC,MAAM,0BAA0B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../../packages/zerodev/src/exports/core.ts"],"names":[],"mappings":"AAMA;;;;;;GAMG;AAEH,sCAAsC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,sCAAsC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,sCAAsC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,sCAAsC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,sCAAsC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,sCAAsC;AACtC,OAAO,EAAE,mCAAmC,EAAE,MAAM,8CAA8C,CAAC;AACnG,sCAAsC;AACtC,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AACzF,sCAAsC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,sCAAsC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/zerodev/src/exports/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,kCAAkC,EAAE,MAAM,uCAAuC,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,8BAA8B,EAAE,MAAM,mCAAmC,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSignerForSmartWalletAccount.d.ts","sourceRoot":"","sources":["../../../../../packages/zerodev/src/getSignerForSmartWalletAccount/getSignerForSmartWalletAccount.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,gBAAgB,EAEtB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEpE,KAAK,oCAAoC,GAAG;IAC1C,kBAAkB,EAAE,gBAAgB,CAAC;CACtC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,8BAA8B,2BACjB,oCAAoC,mBAE3D,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,CAgBjD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/zerodev/src/getSignerForSmartWalletAccount/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC"}
|