@coinbase/agentkit 0.10.0 → 0.10.2
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/README.md +195 -23
- package/dist/action-providers/across/acrossActionProvider.js +3 -3
- package/dist/action-providers/across/schemas.d.ts +1 -1
- package/dist/action-providers/baseAccount/baseAccountActionProvider.d.ts +46 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.js +404 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.test.d.ts +1 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.test.js +325 -0
- package/dist/action-providers/baseAccount/index.d.ts +2 -0
- package/dist/action-providers/baseAccount/index.js +18 -0
- package/dist/action-providers/baseAccount/schemas.d.ts +43 -0
- package/dist/action-providers/baseAccount/schemas.js +62 -0
- package/dist/action-providers/baseAccount/types.d.ts +17 -0
- package/dist/action-providers/baseAccount/types.js +2 -0
- package/dist/action-providers/baseAccount/utils.d.ts +14 -0
- package/dist/action-providers/baseAccount/utils.js +57 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +3 -12
- package/dist/action-providers/cdp/cdpApiActionProvider.js +2 -81
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +0 -125
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +18 -3
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +224 -23
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +280 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +17 -2
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +224 -18
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +267 -1
- package/dist/action-providers/cdp/schemas.d.ts +12 -12
- package/dist/action-providers/cdp/schemas.js +17 -5
- package/dist/action-providers/cdp/swapUtils.d.ts +23 -0
- package/dist/action-providers/cdp/swapUtils.js +106 -0
- package/dist/action-providers/clanker/clankerActionProvider.d.ts +43 -0
- package/dist/action-providers/clanker/clankerActionProvider.js +130 -0
- package/dist/action-providers/clanker/clankerActionProvider.test.d.ts +4 -0
- package/dist/action-providers/clanker/clankerActionProvider.test.js +119 -0
- package/dist/action-providers/clanker/index.d.ts +2 -0
- package/dist/action-providers/clanker/index.js +18 -0
- package/dist/action-providers/clanker/schemas.d.ts +56 -0
- package/dist/action-providers/clanker/schemas.js +47 -0
- package/dist/action-providers/clanker/utils.d.ts +9 -0
- package/dist/action-providers/clanker/utils.js +23 -0
- package/dist/action-providers/compound/constants.d.ts +1 -1
- package/dist/action-providers/compound/constants.js +2 -2
- package/dist/action-providers/erc20/constants.d.ts +35 -135
- package/dist/action-providers/erc20/constants.js +37 -189
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +9 -1
- package/dist/action-providers/erc20/erc20ActionProvider.js +87 -35
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +115 -52
- package/dist/action-providers/erc20/schemas.d.ts +25 -12
- package/dist/action-providers/erc20/schemas.js +34 -6
- package/dist/action-providers/erc20/utils.d.ts +19 -0
- package/dist/action-providers/erc20/utils.js +54 -0
- package/dist/action-providers/flaunch/client_utils.d.ts +25 -0
- package/dist/action-providers/flaunch/client_utils.js +62 -0
- package/dist/action-providers/flaunch/constants.d.ts +42 -21
- package/dist/action-providers/flaunch/constants.js +113 -38
- package/dist/action-providers/flaunch/flaunchActionProvider.d.ts +4 -43
- package/dist/action-providers/flaunch/flaunchActionProvider.js +133 -209
- package/dist/action-providers/flaunch/flaunchActionProvider.test.js +113 -13
- package/dist/action-providers/flaunch/metadata_utils.d.ts +12 -0
- package/dist/action-providers/flaunch/metadata_utils.js +216 -0
- package/dist/action-providers/flaunch/schemas.d.ts +39 -3
- package/dist/action-providers/flaunch/schemas.js +62 -10
- package/dist/action-providers/flaunch/{utils.d.ts → swap_utils.d.ts} +17 -19
- package/dist/action-providers/flaunch/{utils.js → swap_utils.js} +137 -172
- package/dist/action-providers/index.d.ts +4 -0
- package/dist/action-providers/index.js +4 -0
- package/dist/action-providers/jupiter/schemas.d.ts +1 -1
- package/dist/action-providers/moonwell/schemas.d.ts +2 -2
- package/dist/action-providers/morpho/morphoActionProvider.js +5 -5
- package/dist/action-providers/morpho/schemas.d.ts +2 -2
- package/dist/action-providers/pyth/pythActionProvider.d.ts +2 -2
- package/dist/action-providers/pyth/pythActionProvider.js +83 -26
- package/dist/action-providers/pyth/pythActionProvider.test.js +179 -23
- package/dist/action-providers/pyth/schemas.d.ts +6 -0
- package/dist/action-providers/pyth/schemas.js +9 -1
- package/dist/action-providers/superfluid/constants.d.ts +814 -0
- package/dist/action-providers/superfluid/constants.js +2826 -0
- package/dist/action-providers/superfluid/graphQueries/endpoints.d.ts +2 -0
- package/dist/action-providers/superfluid/graphQueries/endpoints.js +5 -0
- package/dist/action-providers/superfluid/graphQueries/queries.d.ts +1 -0
- package/dist/action-providers/superfluid/graphQueries/queries.js +35 -0
- package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.d.ts +8 -0
- package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.js +24 -0
- package/dist/action-providers/superfluid/graphQueries/types.d.ts +27 -0
- package/dist/action-providers/superfluid/graphQueries/types.js +2 -0
- package/dist/action-providers/superfluid/index.d.ts +7 -0
- package/dist/action-providers/superfluid/index.js +23 -0
- package/dist/action-providers/superfluid/schemas.d.ts +86 -0
- package/dist/action-providers/superfluid/schemas.js +103 -0
- package/dist/action-providers/superfluid/superfluidActionProvider.d.ts +20 -0
- package/dist/action-providers/superfluid/superfluidActionProvider.js +36 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.d.ts +46 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.js +143 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.js +92 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.d.ts +27 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.js +71 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.js +57 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.d.ts +56 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.js +191 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.js +80 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.d.ts +30 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.js +109 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.js +75 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.d.ts +32 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.js +101 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.js +85 -0
- package/dist/action-providers/superfluid/utils/parseLogs.d.ts +19 -0
- package/dist/action-providers/superfluid/utils/parseLogs.js +81 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +4 -16
- package/dist/action-providers/truemarkets/truemarketsActionProvider.js +20 -41
- package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +11 -33
- package/dist/action-providers/wallet/walletActionProvider.js +24 -10
- package/dist/action-providers/wallet/walletActionProvider.test.js +6 -2
- package/dist/action-providers/x402/schemas.d.ts +7 -0
- package/dist/action-providers/x402/schemas.js +11 -1
- package/dist/action-providers/x402/utils.d.ts +55 -0
- package/dist/action-providers/x402/utils.js +160 -0
- package/dist/action-providers/x402/x402ActionProvider.d.ts +9 -9
- package/dist/action-providers/x402/x402ActionProvider.js +158 -39
- package/dist/action-providers/x402/x402ActionProvider.test.js +116 -10
- package/dist/action-providers/zeroX/index.d.ts +1 -0
- package/dist/action-providers/zeroX/index.js +17 -0
- package/dist/action-providers/zeroX/schemas.d.ts +51 -0
- package/dist/action-providers/zeroX/schemas.js +82 -0
- package/dist/action-providers/zeroX/utils.d.ts +23 -0
- package/dist/action-providers/zeroX/utils.js +106 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.d.ts +57 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.js +407 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.test.d.ts +1 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.test.js +445 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.js +43 -13
- package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +27 -2
- package/dist/wallet-providers/cdpEvmWalletProvider.js +54 -36
- package/dist/wallet-providers/cdpEvmWalletProvider.test.js +7 -0
- package/dist/wallet-providers/cdpShared.d.ts +5 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +29 -3
- package/dist/wallet-providers/cdpSmartWalletProvider.js +66 -25
- package/dist/wallet-providers/cdpSmartWalletProvider.test.js +6 -10
- package/dist/wallet-providers/cdpSolanaWalletProvider.d.ts +1 -1
- package/dist/wallet-providers/cdpSolanaWalletProvider.js +7 -7
- package/dist/wallet-providers/cdpSolanaWalletProvider.test.js +15 -12
- package/dist/wallet-providers/evmWalletProvider.d.ts +13 -2
- package/dist/wallet-providers/evmWalletProvider.js +4 -0
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +18 -2
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +23 -2
- package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +19 -2
- package/dist/wallet-providers/legacyCdpWalletProvider.js +27 -2
- package/dist/wallet-providers/legacyCdpWalletProvider.test.js +6 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +17 -2
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +39 -3
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +1 -1
- package/dist/wallet-providers/privyEvmWalletProvider.d.ts +2 -0
- package/dist/wallet-providers/privyEvmWalletProvider.js +2 -1
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +12 -1
- package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +1 -1
- package/dist/wallet-providers/solanaKeypairWalletProvider.js +3 -4
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +4 -2
- package/dist/wallet-providers/viemWalletProvider.d.ts +20 -3
- package/dist/wallet-providers/viemWalletProvider.js +33 -4
- package/dist/wallet-providers/viemWalletProvider.test.js +27 -6
- package/dist/wallet-providers/walletProvider.d.ts +1 -1
- package/dist/wallet-providers/zeroDevWalletProvider.d.ts +17 -2
- package/dist/wallet-providers/zeroDevWalletProvider.js +26 -5
- package/dist/wallet-providers/zeroDevWalletProvider.test.js +12 -2
- package/package.json +8 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SendUserOperationOptions, Signer } from "@coinbase/coinbase-sdk";
|
|
2
|
-
import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
|
|
2
|
+
import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest, PublicClient as ViemPublicClient } from "viem";
|
|
3
3
|
import { Network } from "../network";
|
|
4
4
|
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
5
5
|
export interface ConfigureLegacyCdpSmartWalletOptions {
|
|
@@ -9,6 +9,7 @@ export interface ConfigureLegacyCdpSmartWalletOptions {
|
|
|
9
9
|
smartWalletAddress?: Hex;
|
|
10
10
|
paymasterUrl?: string;
|
|
11
11
|
signer: Signer;
|
|
12
|
+
rpcUrl?: string;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* A wallet provider that uses Smart Wallets from the Coinbase SDK.
|
|
@@ -46,6 +47,15 @@ export declare class LegacyCdpSmartWalletProvider extends EvmWalletProvider {
|
|
|
46
47
|
* ```
|
|
47
48
|
*/
|
|
48
49
|
static configureWithWallet(config: ConfigureLegacyCdpSmartWalletOptions): Promise<LegacyCdpSmartWalletProvider>;
|
|
50
|
+
/**
|
|
51
|
+
* Stub for hash signing
|
|
52
|
+
*
|
|
53
|
+
* @throws as signing hashes is not implemented for SmartWallets.
|
|
54
|
+
*
|
|
55
|
+
* @param _ - The hash to sign.
|
|
56
|
+
* @returns The signed hash.
|
|
57
|
+
*/
|
|
58
|
+
sign(_: `0x${string}`): Promise<Hex>;
|
|
49
59
|
/**
|
|
50
60
|
* Stub for message signing
|
|
51
61
|
*
|
|
@@ -146,6 +156,12 @@ export declare class LegacyCdpSmartWalletProvider extends EvmWalletProvider {
|
|
|
146
156
|
* @returns The name of the wallet provider.
|
|
147
157
|
*/
|
|
148
158
|
getName(): string;
|
|
159
|
+
/**
|
|
160
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
161
|
+
*
|
|
162
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
163
|
+
*/
|
|
164
|
+
getPublicClient(): ViemPublicClient;
|
|
149
165
|
/**
|
|
150
166
|
* Gets the balance of the wallet.
|
|
151
167
|
*
|
|
@@ -170,7 +186,7 @@ export declare class LegacyCdpSmartWalletProvider extends EvmWalletProvider {
|
|
|
170
186
|
* Transfer the native asset of the network.
|
|
171
187
|
*
|
|
172
188
|
* @param to - The destination address.
|
|
173
|
-
* @param value - The amount to transfer in Wei.
|
|
189
|
+
* @param value - The amount to transfer in atomic units (Wei).
|
|
174
190
|
* @returns The transaction hash.
|
|
175
191
|
*/
|
|
176
192
|
nativeTransfer(to: Address, value: string): Promise<Hex>;
|
|
@@ -34,9 +34,10 @@ class LegacyCdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider
|
|
|
34
34
|
_LegacyCdpSmartWalletProvider_publicClient.set(this, void 0);
|
|
35
35
|
__classPrivateFieldSet(this, _LegacyCdpSmartWalletProvider_network, config.network, "f");
|
|
36
36
|
__classPrivateFieldSet(this, _LegacyCdpSmartWalletProvider_smartWallet, config.smartWallet, "f");
|
|
37
|
+
const rpcUrl = config.rpcUrl || process.env.RPC_URL;
|
|
37
38
|
__classPrivateFieldSet(this, _LegacyCdpSmartWalletProvider_publicClient, (0, viem_1.createPublicClient)({
|
|
38
39
|
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[config.network.networkId],
|
|
39
|
-
transport: (0, viem_1.http)(),
|
|
40
|
+
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
40
41
|
}), "f");
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
@@ -106,9 +107,21 @@ class LegacyCdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider
|
|
|
106
107
|
smartWallet: networkScopedSmartWallet,
|
|
107
108
|
network,
|
|
108
109
|
chainId: network.chainId,
|
|
110
|
+
rpcUrl: config.rpcUrl,
|
|
109
111
|
});
|
|
110
112
|
return legacyCdpSmartWalletProvider;
|
|
111
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Stub for hash signing
|
|
116
|
+
*
|
|
117
|
+
* @throws as signing hashes is not implemented for SmartWallets.
|
|
118
|
+
*
|
|
119
|
+
* @param _ - The hash to sign.
|
|
120
|
+
* @returns The signed hash.
|
|
121
|
+
*/
|
|
122
|
+
async sign(_) {
|
|
123
|
+
throw new Error("Not implemented");
|
|
124
|
+
}
|
|
112
125
|
/**
|
|
113
126
|
* Stub for message signing
|
|
114
127
|
*
|
|
@@ -242,6 +255,14 @@ class LegacyCdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider
|
|
|
242
255
|
getName() {
|
|
243
256
|
return "legacy_cdp_smart_wallet_provider";
|
|
244
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
260
|
+
*
|
|
261
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
262
|
+
*/
|
|
263
|
+
getPublicClient() {
|
|
264
|
+
return __classPrivateFieldGet(this, _LegacyCdpSmartWalletProvider_publicClient, "f");
|
|
265
|
+
}
|
|
245
266
|
/**
|
|
246
267
|
* Gets the balance of the wallet.
|
|
247
268
|
*
|
|
@@ -278,7 +299,7 @@ class LegacyCdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider
|
|
|
278
299
|
* Transfer the native asset of the network.
|
|
279
300
|
*
|
|
280
301
|
* @param to - The destination address.
|
|
281
|
-
* @param value - The amount to transfer in Wei.
|
|
302
|
+
* @param value - The amount to transfer in atomic units (Wei).
|
|
282
303
|
* @returns The transaction hash.
|
|
283
304
|
*/
|
|
284
305
|
async nativeTransfer(to, value) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReadContractParameters, ReadContractReturnType, TransactionRequest, TransactionSerializable, Abi, ContractFunctionName, ContractFunctionArgs, Address, Hex } from "viem";
|
|
1
|
+
import { ReadContractParameters, ReadContractReturnType, TransactionRequest, TransactionSerializable, PublicClient, Abi, ContractFunctionName, ContractFunctionArgs, Address, Hex } from "viem";
|
|
2
2
|
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
3
3
|
import { Network } from "../network";
|
|
4
4
|
import { Coinbase, CreateERC20Options, CreateTradeOptions, SmartContract, Trade, Wallet, WalletData } from "@coinbase/coinbase-sdk";
|
|
@@ -50,6 +50,10 @@ export interface LegacyCdpWalletProviderConfig extends LegacyCdpProviderConfig {
|
|
|
50
50
|
*/
|
|
51
51
|
feePerGasMultiplier?: number;
|
|
52
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* Optional RPC URL for Viem public client.
|
|
55
|
+
*/
|
|
56
|
+
rpcUrl?: string;
|
|
53
57
|
}
|
|
54
58
|
/**
|
|
55
59
|
* Configuration options for the CDP Agentkit with a Wallet.
|
|
@@ -85,6 +89,13 @@ export declare class LegacyCdpWalletProvider extends EvmWalletProvider {
|
|
|
85
89
|
* @throws Error if required environment variables are missing or wallet initialization fails
|
|
86
90
|
*/
|
|
87
91
|
static configureWithWallet(config?: ConfigureLegacyCdpAgentkitWithWalletOptions): Promise<LegacyCdpWalletProvider>;
|
|
92
|
+
/**
|
|
93
|
+
* Signs a raw hash.
|
|
94
|
+
*
|
|
95
|
+
* @param hash - The hash to sign.
|
|
96
|
+
* @returns The signed hash.
|
|
97
|
+
*/
|
|
98
|
+
sign(hash: `0x${string}`): Promise<`0x${string}`>;
|
|
88
99
|
/**
|
|
89
100
|
* Signs a message.
|
|
90
101
|
*
|
|
@@ -148,6 +159,12 @@ export declare class LegacyCdpWalletProvider extends EvmWalletProvider {
|
|
|
148
159
|
* @returns The name of the wallet provider.
|
|
149
160
|
*/
|
|
150
161
|
getName(): string;
|
|
162
|
+
/**
|
|
163
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
164
|
+
*
|
|
165
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
166
|
+
*/
|
|
167
|
+
getPublicClient(): PublicClient;
|
|
151
168
|
/**
|
|
152
169
|
* Gets the balance of the wallet.
|
|
153
170
|
*
|
|
@@ -221,7 +238,7 @@ export declare class LegacyCdpWalletProvider extends EvmWalletProvider {
|
|
|
221
238
|
* Transfer the native asset of the network.
|
|
222
239
|
*
|
|
223
240
|
* @param to - The destination address.
|
|
224
|
-
* @param value - The amount to transfer in Wei.
|
|
241
|
+
* @param value - The amount to transfer in atomic units (Wei).
|
|
225
242
|
* @returns The transaction hash.
|
|
226
243
|
*/
|
|
227
244
|
nativeTransfer(to: `0x${string}`, value: string): Promise<`0x${string}`>;
|
|
@@ -43,9 +43,10 @@ class LegacyCdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
43
43
|
__classPrivateFieldSet(this, _LegacyCdpWalletProvider_cdpWallet, config.wallet, "f");
|
|
44
44
|
__classPrivateFieldSet(this, _LegacyCdpWalletProvider_address, config.address, "f");
|
|
45
45
|
__classPrivateFieldSet(this, _LegacyCdpWalletProvider_network, config.network, "f");
|
|
46
|
+
const rpcUrl = config.rpcUrl || process.env.RPC_URL;
|
|
46
47
|
__classPrivateFieldSet(this, _LegacyCdpWalletProvider_publicClient, (0, viem_1.createPublicClient)({
|
|
47
48
|
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[config.network.networkId],
|
|
48
|
-
transport: (0, viem_1.http)(),
|
|
49
|
+
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
49
50
|
}), "f");
|
|
50
51
|
__classPrivateFieldSet(this, _LegacyCdpWalletProvider_gasLimitMultiplier, Math.max(config.gas?.gasLimitMultiplier ?? 1.2, 1), "f");
|
|
51
52
|
__classPrivateFieldSet(this, _LegacyCdpWalletProvider_feePerGasMultiplier, Math.max(config.gas?.feePerGasMultiplier ?? 1, 1), "f");
|
|
@@ -105,6 +106,22 @@ class LegacyCdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
105
106
|
});
|
|
106
107
|
return cdpWalletProvider;
|
|
107
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Signs a raw hash.
|
|
111
|
+
*
|
|
112
|
+
* @param hash - The hash to sign.
|
|
113
|
+
* @returns The signed hash.
|
|
114
|
+
*/
|
|
115
|
+
async sign(hash) {
|
|
116
|
+
if (!__classPrivateFieldGet(this, _LegacyCdpWalletProvider_cdpWallet, "f")) {
|
|
117
|
+
throw new Error("Wallet not initialized");
|
|
118
|
+
}
|
|
119
|
+
const payload = await __classPrivateFieldGet(this, _LegacyCdpWalletProvider_cdpWallet, "f").createPayloadSignature(hash);
|
|
120
|
+
if (payload.getStatus() === "pending" && payload?.wait) {
|
|
121
|
+
await payload.wait(); // needed for Server-Signers
|
|
122
|
+
}
|
|
123
|
+
return payload.getSignature();
|
|
124
|
+
}
|
|
108
125
|
/**
|
|
109
126
|
* Signs a message.
|
|
110
127
|
*
|
|
@@ -268,6 +285,14 @@ class LegacyCdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
268
285
|
getName() {
|
|
269
286
|
return "legacy_cdp_wallet_provider";
|
|
270
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
290
|
+
*
|
|
291
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
292
|
+
*/
|
|
293
|
+
getPublicClient() {
|
|
294
|
+
return __classPrivateFieldGet(this, _LegacyCdpWalletProvider_publicClient, "f");
|
|
295
|
+
}
|
|
271
296
|
/**
|
|
272
297
|
* Gets the balance of the wallet.
|
|
273
298
|
*
|
|
@@ -363,7 +388,7 @@ class LegacyCdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
363
388
|
* Transfer the native asset of the network.
|
|
364
389
|
*
|
|
365
390
|
* @param to - The destination address.
|
|
366
|
-
* @param value - The amount to transfer in Wei.
|
|
391
|
+
* @param value - The amount to transfer in atomic units (Wei).
|
|
367
392
|
* @returns The transaction hash.
|
|
368
393
|
*/
|
|
369
394
|
async nativeTransfer(to, value) {
|
|
@@ -268,6 +268,12 @@ describe("LegacyCdpWalletProvider", () => {
|
|
|
268
268
|
// signing operation tests
|
|
269
269
|
// =========================================================
|
|
270
270
|
describe("signing operations", () => {
|
|
271
|
+
it("should sign a hash", async () => {
|
|
272
|
+
const testHash = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
273
|
+
const signature = await provider.sign(testHash);
|
|
274
|
+
expect(mockWalletObj.createPayloadSignature).toHaveBeenCalledWith(testHash);
|
|
275
|
+
expect(signature).toBe(MOCK_SIGNATURE);
|
|
276
|
+
});
|
|
271
277
|
it("should sign messages", async () => {
|
|
272
278
|
const signature = await provider.signMessage("Hello, world!");
|
|
273
279
|
expect(mockWalletObj.createPayloadSignature).toHaveBeenCalled();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Abi, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionReceipt, TransactionRequest } from "viem";
|
|
1
|
+
import { Abi, ContractFunctionArgs, ContractFunctionName, Hex, PublicClient, ReadContractParameters, ReadContractReturnType, TransactionReceipt, TransactionRequest } from "viem";
|
|
2
2
|
import { Network } from "../network";
|
|
3
3
|
import { PrivyWalletConfig, PrivyWalletExport } from "./privyShared";
|
|
4
4
|
import { WalletProvider } from "./walletProvider";
|
|
@@ -14,6 +14,8 @@ export interface PrivyEvmDelegatedEmbeddedWalletConfig extends PrivyWalletConfig
|
|
|
14
14
|
chainId?: string;
|
|
15
15
|
/** The wallet type to use */
|
|
16
16
|
walletType: "embedded";
|
|
17
|
+
/** Optional RPC URL for Viem public client */
|
|
18
|
+
rpcUrl?: string;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* A wallet provider that uses Privy's embedded wallets with delegation.
|
|
@@ -64,12 +66,25 @@ export declare class PrivyEvmDelegatedEmbeddedWalletProvider extends WalletProvi
|
|
|
64
66
|
* @returns The name of the wallet provider.
|
|
65
67
|
*/
|
|
66
68
|
getName(): string;
|
|
69
|
+
/**
|
|
70
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
71
|
+
*
|
|
72
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
73
|
+
*/
|
|
74
|
+
getPublicClient(): PublicClient;
|
|
67
75
|
/**
|
|
68
76
|
* Gets the balance of the wallet.
|
|
69
77
|
*
|
|
70
78
|
* @returns The balance of the wallet in wei
|
|
71
79
|
*/
|
|
72
80
|
getBalance(): Promise<bigint>;
|
|
81
|
+
/**
|
|
82
|
+
* Signs a raw hash.
|
|
83
|
+
*
|
|
84
|
+
* @param hash - The hash to sign.
|
|
85
|
+
* @returns The signed hash.
|
|
86
|
+
*/
|
|
87
|
+
sign(hash: `0x${string}`): Promise<Hex>;
|
|
73
88
|
/**
|
|
74
89
|
* Signs a message.
|
|
75
90
|
*
|
|
@@ -132,7 +147,7 @@ export declare class PrivyEvmDelegatedEmbeddedWalletProvider extends WalletProvi
|
|
|
132
147
|
* Transfer the native asset of the network.
|
|
133
148
|
*
|
|
134
149
|
* @param to - The destination address.
|
|
135
|
-
* @param value - The amount to transfer in Wei.
|
|
150
|
+
* @param value - The amount to transfer in atomic units (Wei).
|
|
136
151
|
* @returns The transaction hash.
|
|
137
152
|
*/
|
|
138
153
|
nativeTransfer(to: string, value: string): Promise<Hex>;
|
|
@@ -59,9 +59,10 @@ class PrivyEvmDelegatedEmbeddedWalletProvider extends walletProvider_1.WalletPro
|
|
|
59
59
|
if (!chain) {
|
|
60
60
|
throw new Error(`Chain with ID ${chainId} not found`);
|
|
61
61
|
}
|
|
62
|
+
const rpcUrl = config.rpcUrl || process.env.RPC_URL;
|
|
62
63
|
__classPrivateFieldSet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_publicClient, (0, viem_1.createPublicClient)({
|
|
63
64
|
chain,
|
|
64
|
-
transport: (0, viem_1.http)(),
|
|
65
|
+
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
65
66
|
}), "f");
|
|
66
67
|
}
|
|
67
68
|
/**
|
|
@@ -142,6 +143,14 @@ class PrivyEvmDelegatedEmbeddedWalletProvider extends walletProvider_1.WalletPro
|
|
|
142
143
|
getName() {
|
|
143
144
|
return "privy_evm_embedded_wallet_provider";
|
|
144
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
148
|
+
*
|
|
149
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
150
|
+
*/
|
|
151
|
+
getPublicClient() {
|
|
152
|
+
return __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_publicClient, "f");
|
|
153
|
+
}
|
|
145
154
|
/**
|
|
146
155
|
* Gets the balance of the wallet.
|
|
147
156
|
*
|
|
@@ -161,6 +170,33 @@ class PrivyEvmDelegatedEmbeddedWalletProvider extends walletProvider_1.WalletPro
|
|
|
161
170
|
throw new Error("Error getting balance");
|
|
162
171
|
}
|
|
163
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Signs a raw hash.
|
|
175
|
+
*
|
|
176
|
+
* @param hash - The hash to sign.
|
|
177
|
+
* @returns The signed hash.
|
|
178
|
+
*/
|
|
179
|
+
async sign(hash) {
|
|
180
|
+
const body = {
|
|
181
|
+
address: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, "f"),
|
|
182
|
+
chain_type: "ethereum",
|
|
183
|
+
method: "personal_sign",
|
|
184
|
+
params: {
|
|
185
|
+
message: hash,
|
|
186
|
+
encoding: "hex",
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
try {
|
|
190
|
+
const response = await this.executePrivyRequest(body);
|
|
191
|
+
return response.data?.signature;
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
if (error instanceof Error) {
|
|
195
|
+
throw new Error(`Hash signing failed: ${error.message}`);
|
|
196
|
+
}
|
|
197
|
+
throw new Error("Hash signing failed");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
164
200
|
/**
|
|
165
201
|
* Signs a message.
|
|
166
202
|
*
|
|
@@ -306,11 +342,11 @@ class PrivyEvmDelegatedEmbeddedWalletProvider extends walletProvider_1.WalletPro
|
|
|
306
342
|
* Transfer the native asset of the network.
|
|
307
343
|
*
|
|
308
344
|
* @param to - The destination address.
|
|
309
|
-
* @param value - The amount to transfer in Wei.
|
|
345
|
+
* @param value - The amount to transfer in atomic units (Wei).
|
|
310
346
|
* @returns The transaction hash.
|
|
311
347
|
*/
|
|
312
348
|
async nativeTransfer(to, value) {
|
|
313
|
-
const valueInWei = (
|
|
349
|
+
const valueInWei = BigInt(value);
|
|
314
350
|
const valueHex = `0x${valueInWei.toString(16)}`;
|
|
315
351
|
const body = {
|
|
316
352
|
address: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, "f"),
|
|
@@ -211,7 +211,7 @@ describe("PrivyEvmDelegatedEmbeddedWalletProvider", () => {
|
|
|
211
211
|
});
|
|
212
212
|
});
|
|
213
213
|
it("should transfer native tokens", async () => {
|
|
214
|
-
const result = await provider.nativeTransfer("0x1234567890123456789012345678901234567890", "
|
|
214
|
+
const result = await provider.nativeTransfer("0x1234567890123456789012345678901234567890", "1000000000000000000");
|
|
215
215
|
expect(result).toBe(MOCK_TRANSACTION_HASH);
|
|
216
216
|
});
|
|
217
217
|
it("should export wallet data", () => {
|
|
@@ -8,6 +8,8 @@ import { PrivyWalletConfig, PrivyWalletExport } from "./privyShared";
|
|
|
8
8
|
export interface PrivyEvmWalletConfig extends PrivyWalletConfig {
|
|
9
9
|
/** Optional chain ID to connect to */
|
|
10
10
|
chainId?: string;
|
|
11
|
+
/** Optional RPC URL override for Viem wallet/public clients */
|
|
12
|
+
rpcUrl?: string;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
15
|
* A wallet provider that uses Privy's server wallet API.
|
|
@@ -107,10 +107,11 @@ class PrivyEvmWalletProvider extends viemWalletProvider_1.ViemWalletProvider {
|
|
|
107
107
|
if (!chain) {
|
|
108
108
|
throw new Error(`Chain with ID ${chainId} not found`);
|
|
109
109
|
}
|
|
110
|
+
const rpcUrl = config.rpcUrl || process.env.RPC_URL;
|
|
110
111
|
const walletClient = (0, viem_2.createWalletClient)({
|
|
111
112
|
account,
|
|
112
113
|
chain,
|
|
113
|
-
transport: (0, viem_2.http)(),
|
|
114
|
+
transport: rpcUrl ? (0, viem_2.http)(rpcUrl) : (0, viem_2.http)(),
|
|
114
115
|
});
|
|
115
116
|
return new PrivyEvmWalletProvider(walletClient, { ...config, walletId });
|
|
116
117
|
}
|
|
@@ -14,6 +14,10 @@ const MOCK_TRANSACTION_HASH = "0xef01";
|
|
|
14
14
|
const MOCK_SIGNATURE_HASH_1 = "0x1234";
|
|
15
15
|
const MOCK_SIGNATURE_HASH_2 = "0x5678";
|
|
16
16
|
const MOCK_SIGNATURE_HASH_3 = "0xabcd";
|
|
17
|
+
const MOCK_HASH_SIGNATURE = "0xhash";
|
|
18
|
+
jest.mock("../analytics", () => ({
|
|
19
|
+
sendAnalyticsEvent: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
20
|
+
}));
|
|
17
21
|
jest.mock("@privy-io/server-auth", () => ({
|
|
18
22
|
PrivyClient: jest.fn().mockImplementation(() => ({
|
|
19
23
|
appId: "mock-app-id",
|
|
@@ -65,6 +69,7 @@ jest.mock("@privy-io/server-auth/viem", () => ({
|
|
|
65
69
|
createViemAccount: jest.fn().mockResolvedValue({
|
|
66
70
|
address: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
|
|
67
71
|
type: "local",
|
|
72
|
+
sign: jest.fn().mockResolvedValue("0xhash"),
|
|
68
73
|
signMessage: jest.fn().mockResolvedValue("0x1234"),
|
|
69
74
|
signTypedData: jest.fn().mockResolvedValue("0x5678"),
|
|
70
75
|
signTransaction: jest.fn().mockResolvedValue("0xabcd"),
|
|
@@ -120,6 +125,7 @@ jest.mock("viem", () => {
|
|
|
120
125
|
createWalletClient: jest.fn().mockReturnValue({
|
|
121
126
|
account: {
|
|
122
127
|
address: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
|
|
128
|
+
sign: jest.fn().mockResolvedValue("0xhash"),
|
|
123
129
|
},
|
|
124
130
|
chain: {
|
|
125
131
|
id: 1,
|
|
@@ -214,6 +220,11 @@ describe("PrivyEvmWalletProvider", () => {
|
|
|
214
220
|
it("should get the provider name", () => {
|
|
215
221
|
expect(provider.getName()).toBe("privy_evm_wallet_provider");
|
|
216
222
|
});
|
|
223
|
+
it("should sign a hash", async () => {
|
|
224
|
+
const testHash = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
225
|
+
const result = await provider.sign(testHash);
|
|
226
|
+
expect(result).toBe(MOCK_HASH_SIGNATURE);
|
|
227
|
+
});
|
|
217
228
|
it("should sign a message", async () => {
|
|
218
229
|
const result = await provider.signMessage("Hello, world!");
|
|
219
230
|
expect(result).toBe(MOCK_SIGNATURE_HASH_1);
|
|
@@ -272,7 +283,7 @@ describe("PrivyEvmWalletProvider", () => {
|
|
|
272
283
|
expect(result).toBe("mock_result");
|
|
273
284
|
});
|
|
274
285
|
it("should transfer native tokens", async () => {
|
|
275
|
-
const result = await provider.nativeTransfer("0x1234567890123456789012345678901234567890", "
|
|
286
|
+
const result = await provider.nativeTransfer("0x1234567890123456789012345678901234567890", "1000000000000000000");
|
|
276
287
|
expect(result).toBe(MOCK_TRANSACTION_HASH);
|
|
277
288
|
});
|
|
278
289
|
it("should export wallet data", () => {
|
|
@@ -129,7 +129,7 @@ export declare class SolanaKeypairWalletProvider extends SvmWalletProvider {
|
|
|
129
129
|
* Transfer SOL from the wallet to another address
|
|
130
130
|
*
|
|
131
131
|
* @param to - The base58 encoded address to transfer the SOL to
|
|
132
|
-
* @param value - The amount
|
|
132
|
+
* @param value - The amount to transfer in atomic units (Lamports)
|
|
133
133
|
* @returns The signature
|
|
134
134
|
*/
|
|
135
135
|
nativeTransfer(to: string, value: string): Promise<string>;
|
|
@@ -231,16 +231,15 @@ class SolanaKeypairWalletProvider extends svmWalletProvider_1.SvmWalletProvider
|
|
|
231
231
|
* Transfer SOL from the wallet to another address
|
|
232
232
|
*
|
|
233
233
|
* @param to - The base58 encoded address to transfer the SOL to
|
|
234
|
-
* @param value - The amount
|
|
234
|
+
* @param value - The amount to transfer in atomic units (Lamports)
|
|
235
235
|
* @returns The signature
|
|
236
236
|
*/
|
|
237
237
|
async nativeTransfer(to, value) {
|
|
238
238
|
const initialBalance = await this.getBalance();
|
|
239
|
-
const
|
|
240
|
-
const lamports = BigInt(Math.floor(solAmount * web3_js_1.LAMPORTS_PER_SOL));
|
|
239
|
+
const lamports = BigInt(value);
|
|
241
240
|
// Check if we have enough balance (including estimated fees)
|
|
242
241
|
if (initialBalance < lamports + BigInt(5000)) {
|
|
243
|
-
throw new Error(`Insufficient balance. Have ${Number(initialBalance)
|
|
242
|
+
throw new Error(`Insufficient balance. Have ${Number(initialBalance)} lamports, need ${Number(lamports) + 5000} lamports (including fees)`);
|
|
244
243
|
}
|
|
245
244
|
const toPubkey = new web3_js_1.PublicKey(to);
|
|
246
245
|
const instructions = [
|
|
@@ -183,14 +183,16 @@ describe("SolanaKeypairWalletProvider", () => {
|
|
|
183
183
|
});
|
|
184
184
|
it("should transfer native tokens", async () => {
|
|
185
185
|
const destination = "EQJqzeeVEnm8rKWQJ5SMTtQBD4xEgixwgzNWKkpeFRZ9";
|
|
186
|
-
const signature = await wallet.nativeTransfer(destination, "0.1
|
|
186
|
+
const signature = await wallet.nativeTransfer(destination, "100000000"); // 0.1 SOL in lamports
|
|
187
187
|
expect(signature).toBe("signature123");
|
|
188
188
|
});
|
|
189
189
|
it("should handle insufficient balance when transferring", async () => {
|
|
190
190
|
const connection = wallet.getConnection();
|
|
191
191
|
connection.getBalance.mockResolvedValueOnce(100);
|
|
192
192
|
const destination = "EQJqzeeVEnm8rKWQJ5SMTtQBD4xEgixwgzNWKkpeFRZ9";
|
|
193
|
-
await expect(wallet.nativeTransfer(destination, "
|
|
193
|
+
await expect(wallet.nativeTransfer(destination, "1000000000")).rejects.toThrow(
|
|
194
|
+
// 1 SOL in lamports
|
|
195
|
+
"Insufficient balance");
|
|
194
196
|
});
|
|
195
197
|
it("should handle transaction failure when sending", async () => {
|
|
196
198
|
const connection = wallet.getConnection();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalletClient as ViemWalletClient, TransactionRequest, ReadContractParameters, ReadContractReturnType, Abi, ContractFunctionName, ContractFunctionArgs } from "viem";
|
|
1
|
+
import { WalletClient as ViemWalletClient, TransactionRequest, PublicClient as ViemPublicClient, ReadContractParameters, ReadContractReturnType, Abi, ContractFunctionName, ContractFunctionArgs } from "viem";
|
|
2
2
|
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
3
3
|
import { Network } from "../network";
|
|
4
4
|
/**
|
|
@@ -13,6 +13,10 @@ export interface ViemWalletProviderGasConfig {
|
|
|
13
13
|
* An internal multiplier on fee per gas estimation.
|
|
14
14
|
*/
|
|
15
15
|
feePerGasMultiplier?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Optional RPC URL override for Viem public client.
|
|
18
|
+
*/
|
|
19
|
+
rpcUrl?: string;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
22
|
* A wallet provider that uses the Viem library.
|
|
@@ -26,13 +30,20 @@ export declare class ViemWalletProvider extends EvmWalletProvider {
|
|
|
26
30
|
* @param gasConfig - Configuration for gas multipliers.
|
|
27
31
|
*/
|
|
28
32
|
constructor(walletClient: ViemWalletClient, gasConfig?: ViemWalletProviderGasConfig);
|
|
33
|
+
/**
|
|
34
|
+
* Signs a raw hash.
|
|
35
|
+
*
|
|
36
|
+
* @param hash - The hash to sign.
|
|
37
|
+
* @returns The signed hash.
|
|
38
|
+
*/
|
|
39
|
+
sign(hash: `0x${string}`): Promise<`0x${string}`>;
|
|
29
40
|
/**
|
|
30
41
|
* Signs a message.
|
|
31
42
|
*
|
|
32
43
|
* @param message - The message to sign.
|
|
33
44
|
* @returns The signed message.
|
|
34
45
|
*/
|
|
35
|
-
signMessage(message: string): Promise<`0x${string}`>;
|
|
46
|
+
signMessage(message: string | Uint8Array): Promise<`0x${string}`>;
|
|
36
47
|
/**
|
|
37
48
|
* Signs a typed data object.
|
|
38
49
|
*
|
|
@@ -72,6 +83,12 @@ export declare class ViemWalletProvider extends EvmWalletProvider {
|
|
|
72
83
|
* @returns The name of the wallet provider.
|
|
73
84
|
*/
|
|
74
85
|
getName(): string;
|
|
86
|
+
/**
|
|
87
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
88
|
+
*
|
|
89
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
90
|
+
*/
|
|
91
|
+
getPublicClient(): ViemPublicClient;
|
|
75
92
|
/**
|
|
76
93
|
* Gets the balance of the wallet.
|
|
77
94
|
*
|
|
@@ -96,7 +113,7 @@ export declare class ViemWalletProvider extends EvmWalletProvider {
|
|
|
96
113
|
* Transfer the native asset of the network.
|
|
97
114
|
*
|
|
98
115
|
* @param to - The destination address.
|
|
99
|
-
* @param value - The amount to transfer in
|
|
116
|
+
* @param value - The amount to transfer in atomic units (Wei)
|
|
100
117
|
* @returns The transaction hash.
|
|
101
118
|
*/
|
|
102
119
|
nativeTransfer(to: `0x${string}`, value: string): Promise<`0x${string}`>;
|
|
@@ -36,13 +36,30 @@ class ViemWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
36
36
|
_ViemWalletProvider_gasLimitMultiplier.set(this, void 0);
|
|
37
37
|
_ViemWalletProvider_feePerGasMultiplier.set(this, void 0);
|
|
38
38
|
__classPrivateFieldSet(this, _ViemWalletProvider_walletClient, walletClient, "f");
|
|
39
|
+
const rpcUrl = gasConfig?.rpcUrl || process.env.RPC_URL;
|
|
39
40
|
__classPrivateFieldSet(this, _ViemWalletProvider_publicClient, (0, viem_1.createPublicClient)({
|
|
40
41
|
chain: walletClient.chain,
|
|
41
|
-
transport: (0, viem_1.http)(),
|
|
42
|
+
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
42
43
|
}), "f");
|
|
43
44
|
__classPrivateFieldSet(this, _ViemWalletProvider_gasLimitMultiplier, Math.max(gasConfig?.gasLimitMultiplier ?? 1.2, 1), "f");
|
|
44
45
|
__classPrivateFieldSet(this, _ViemWalletProvider_feePerGasMultiplier, Math.max(gasConfig?.feePerGasMultiplier ?? 1, 1), "f");
|
|
45
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Signs a raw hash.
|
|
49
|
+
*
|
|
50
|
+
* @param hash - The hash to sign.
|
|
51
|
+
* @returns The signed hash.
|
|
52
|
+
*/
|
|
53
|
+
async sign(hash) {
|
|
54
|
+
const account = __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").account;
|
|
55
|
+
if (!account) {
|
|
56
|
+
throw new Error("Account not found");
|
|
57
|
+
}
|
|
58
|
+
if (!account.sign) {
|
|
59
|
+
throw new Error("Account does not support raw hash signing");
|
|
60
|
+
}
|
|
61
|
+
return account.sign({ hash });
|
|
62
|
+
}
|
|
46
63
|
/**
|
|
47
64
|
* Signs a message.
|
|
48
65
|
*
|
|
@@ -54,7 +71,11 @@ class ViemWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
54
71
|
if (!account) {
|
|
55
72
|
throw new Error("Account not found");
|
|
56
73
|
}
|
|
57
|
-
|
|
74
|
+
const _message = typeof message === "string" ? ((0, viem_1.isHex)(message) ? message : (0, viem_1.toHex)(message)) : message;
|
|
75
|
+
return __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").signMessage({
|
|
76
|
+
account,
|
|
77
|
+
message: { raw: _message },
|
|
78
|
+
});
|
|
58
79
|
}
|
|
59
80
|
/**
|
|
60
81
|
* Signs a typed data object.
|
|
@@ -152,6 +173,14 @@ class ViemWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
152
173
|
getName() {
|
|
153
174
|
return "viem_wallet_provider";
|
|
154
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Gets the Viem PublicClient used for read-only operations.
|
|
178
|
+
*
|
|
179
|
+
* @returns The Viem PublicClient instance used for read-only operations.
|
|
180
|
+
*/
|
|
181
|
+
getPublicClient() {
|
|
182
|
+
return __classPrivateFieldGet(this, _ViemWalletProvider_publicClient, "f");
|
|
183
|
+
}
|
|
155
184
|
/**
|
|
156
185
|
* Gets the balance of the wallet.
|
|
157
186
|
*
|
|
@@ -186,11 +215,11 @@ class ViemWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
186
215
|
* Transfer the native asset of the network.
|
|
187
216
|
*
|
|
188
217
|
* @param to - The destination address.
|
|
189
|
-
* @param value - The amount to transfer in
|
|
218
|
+
* @param value - The amount to transfer in atomic units (Wei)
|
|
190
219
|
* @returns The transaction hash.
|
|
191
220
|
*/
|
|
192
221
|
async nativeTransfer(to, value) {
|
|
193
|
-
const atomicAmount = (
|
|
222
|
+
const atomicAmount = BigInt(value);
|
|
194
223
|
const tx = await this.sendTransaction({
|
|
195
224
|
to: to,
|
|
196
225
|
value: atomicAmount,
|