@coinbase/agentkit 0.0.0-nightly-20250328174338
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 +827 -0
- package/dist/action-providers/across/acrossActionProvider.d.ts +50 -0
- package/dist/action-providers/across/acrossActionProvider.js +333 -0
- package/dist/action-providers/across/acrossActionProvider.test.d.ts +1 -0
- package/dist/action-providers/across/acrossActionProvider.test.js +391 -0
- package/dist/action-providers/across/constants.d.ts +1 -0
- package/dist/action-providers/across/constants.js +2 -0
- package/dist/action-providers/across/index.d.ts +1 -0
- package/dist/action-providers/across/index.js +17 -0
- package/dist/action-providers/across/schemas.d.ts +36 -0
- package/dist/action-providers/across/schemas.js +46 -0
- package/dist/action-providers/across/utils.d.ts +7 -0
- package/dist/action-providers/across/utils.js +25 -0
- package/dist/action-providers/actionDecorator.d.ts +69 -0
- package/dist/action-providers/actionDecorator.js +96 -0
- package/dist/action-providers/actionProvider.d.ts +48 -0
- package/dist/action-providers/actionProvider.js +62 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.d.ts +55 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.js +173 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.test.d.ts +1 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.test.js +131 -0
- package/dist/action-providers/alchemy/index.d.ts +2 -0
- package/dist/action-providers/alchemy/index.js +18 -0
- package/dist/action-providers/alchemy/schemas.d.ts +41 -0
- package/dist/action-providers/alchemy/schemas.js +34 -0
- package/dist/action-providers/allora/alloraActionProvider.d.ts +44 -0
- package/dist/action-providers/allora/alloraActionProvider.js +195 -0
- package/dist/action-providers/allora/alloraActionProvider.test.d.ts +1 -0
- package/dist/action-providers/allora/alloraActionProvider.test.js +109 -0
- package/dist/action-providers/allora/index.d.ts +2 -0
- package/dist/action-providers/allora/index.js +18 -0
- package/dist/action-providers/allora/schemas.d.ts +28 -0
- package/dist/action-providers/allora/schemas.js +30 -0
- package/dist/action-providers/basename/basenameActionProvider.d.ts +30 -0
- package/dist/action-providers/basename/basenameActionProvider.js +109 -0
- package/dist/action-providers/basename/basenameActionProvider.test.d.ts +1 -0
- package/dist/action-providers/basename/basenameActionProvider.test.js +146 -0
- package/dist/action-providers/basename/constants.d.ts +52 -0
- package/dist/action-providers/basename/constants.js +81 -0
- package/dist/action-providers/basename/index.d.ts +2 -0
- package/dist/action-providers/basename/index.js +18 -0
- package/dist/action-providers/basename/schemas.d.ts +14 -0
- package/dist/action-providers/basename/schemas.js +14 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +43 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.js +128 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +146 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.d.ts +58 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.js +224 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpWalletActionProvider.test.js +267 -0
- package/dist/action-providers/cdp/constants.d.ts +31 -0
- package/dist/action-providers/cdp/constants.js +34 -0
- package/dist/action-providers/cdp/index.d.ts +3 -0
- package/dist/action-providers/cdp/index.js +19 -0
- package/dist/action-providers/cdp/schemas.d.ts +91 -0
- package/dist/action-providers/cdp/schemas.js +77 -0
- package/dist/action-providers/compound/compoundActionProvider.d.ts +67 -0
- package/dist/action-providers/compound/compoundActionProvider.js +365 -0
- package/dist/action-providers/compound/compoundActionProvider.test.d.ts +1 -0
- package/dist/action-providers/compound/compoundActionProvider.test.js +353 -0
- package/dist/action-providers/compound/constants.d.ts +180 -0
- package/dist/action-providers/compound/constants.js +129 -0
- package/dist/action-providers/compound/index.d.ts +1 -0
- package/dist/action-providers/compound/index.js +17 -0
- package/dist/action-providers/compound/schemas.d.ts +57 -0
- package/dist/action-providers/compound/schemas.js +58 -0
- package/dist/action-providers/compound/utils.d.ts +95 -0
- package/dist/action-providers/compound/utils.js +353 -0
- package/dist/action-providers/customActionProvider.d.ts +30 -0
- package/dist/action-providers/customActionProvider.js +66 -0
- package/dist/action-providers/defillama/constants.d.ts +8 -0
- package/dist/action-providers/defillama/constants.js +11 -0
- package/dist/action-providers/defillama/defillamaActionProvider.d.ts +54 -0
- package/dist/action-providers/defillama/defillamaActionProvider.js +180 -0
- package/dist/action-providers/defillama/defillamaActionProvider.test.d.ts +1 -0
- package/dist/action-providers/defillama/defillamaActionProvider.test.js +114 -0
- package/dist/action-providers/defillama/index.d.ts +1 -0
- package/dist/action-providers/defillama/index.js +17 -0
- package/dist/action-providers/defillama/schemas.d.ts +34 -0
- package/dist/action-providers/defillama/schemas.js +34 -0
- package/dist/action-providers/defillama/types.d.ts +73 -0
- package/dist/action-providers/defillama/types.js +2 -0
- package/dist/action-providers/defillama/utils.d.ts +10 -0
- package/dist/action-providers/defillama/utils.js +87 -0
- package/dist/action-providers/defillama/utils.test.d.ts +1 -0
- package/dist/action-providers/defillama/utils.test.js +124 -0
- package/dist/action-providers/erc20/constants.d.ts +137 -0
- package/dist/action-providers/erc20/constants.js +202 -0
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +38 -0
- package/dist/action-providers/erc20/erc20ActionProvider.js +142 -0
- package/dist/action-providers/erc20/erc20ActionProvider.test.d.ts +1 -0
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +131 -0
- package/dist/action-providers/erc20/index.d.ts +1 -0
- package/dist/action-providers/erc20/index.js +17 -0
- package/dist/action-providers/erc20/schemas.d.ts +27 -0
- package/dist/action-providers/erc20/schemas.js +26 -0
- package/dist/action-providers/erc721/constants.d.ts +232 -0
- package/dist/action-providers/erc721/constants.js +298 -0
- package/dist/action-providers/erc721/erc721ActionProvider.d.ts +46 -0
- package/dist/action-providers/erc721/erc721ActionProvider.js +164 -0
- package/dist/action-providers/erc721/erc721ActionProvider.test.d.ts +1 -0
- package/dist/action-providers/erc721/erc721ActionProvider.test.js +137 -0
- package/dist/action-providers/erc721/index.d.ts +1 -0
- package/dist/action-providers/erc721/index.js +17 -0
- package/dist/action-providers/erc721/schemas.d.ts +46 -0
- package/dist/action-providers/erc721/schemas.js +44 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.d.ts +57 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.js +142 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.test.js +151 -0
- package/dist/action-providers/farcaster/index.d.ts +2 -0
- package/dist/action-providers/farcaster/index.js +18 -0
- package/dist/action-providers/farcaster/schemas.d.ts +15 -0
- package/dist/action-providers/farcaster/schemas.js +20 -0
- package/dist/action-providers/index.d.ts +24 -0
- package/dist/action-providers/index.js +40 -0
- package/dist/action-providers/jupiter/index.d.ts +1 -0
- package/dist/action-providers/jupiter/index.js +17 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.d.ts +36 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.js +115 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.test.js +146 -0
- package/dist/action-providers/jupiter/schemas.d.ts +20 -0
- package/dist/action-providers/jupiter/schemas.js +20 -0
- package/dist/action-providers/messari/constants.d.ts +17 -0
- package/dist/action-providers/messari/constants.js +20 -0
- package/dist/action-providers/messari/index.d.ts +5 -0
- package/dist/action-providers/messari/index.js +21 -0
- package/dist/action-providers/messari/messariActionProvider.d.ts +42 -0
- package/dist/action-providers/messari/messariActionProvider.js +128 -0
- package/dist/action-providers/messari/messariActionProvider.test.d.ts +1 -0
- package/dist/action-providers/messari/messariActionProvider.test.js +152 -0
- package/dist/action-providers/messari/schemas.d.ts +11 -0
- package/dist/action-providers/messari/schemas.js +16 -0
- package/dist/action-providers/messari/types.d.ts +40 -0
- package/dist/action-providers/messari/types.js +2 -0
- package/dist/action-providers/messari/utils.d.ts +22 -0
- package/dist/action-providers/messari/utils.js +65 -0
- package/dist/action-providers/moonwell/constants.d.ts +78 -0
- package/dist/action-providers/moonwell/constants.js +111 -0
- package/dist/action-providers/moonwell/index.d.ts +1 -0
- package/dist/action-providers/moonwell/index.js +5 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.d.ts +39 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.js +249 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.test.d.ts +1 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.test.js +455 -0
- package/dist/action-providers/moonwell/schemas.d.ts +30 -0
- package/dist/action-providers/moonwell/schemas.js +39 -0
- package/dist/action-providers/morpho/constants.d.ts +16 -0
- package/dist/action-providers/morpho/constants.js +27 -0
- package/dist/action-providers/morpho/index.d.ts +2 -0
- package/dist/action-providers/morpho/index.js +18 -0
- package/dist/action-providers/morpho/morphoActionProvider.d.ts +39 -0
- package/dist/action-providers/morpho/morphoActionProvider.js +154 -0
- package/dist/action-providers/morpho/morphoActionProvider.test.d.ts +1 -0
- package/dist/action-providers/morpho/morphoActionProvider.test.js +128 -0
- package/dist/action-providers/morpho/schemas.d.ts +36 -0
- package/dist/action-providers/morpho/schemas.js +47 -0
- package/dist/action-providers/opensea/index.d.ts +1 -0
- package/dist/action-providers/opensea/index.js +17 -0
- package/dist/action-providers/opensea/openseaActionProvider.d.ts +59 -0
- package/dist/action-providers/opensea/openseaActionProvider.js +146 -0
- package/dist/action-providers/opensea/openseaActionProvider.test.d.ts +1 -0
- package/dist/action-providers/opensea/openseaActionProvider.test.js +201 -0
- package/dist/action-providers/opensea/schemas.d.ts +30 -0
- package/dist/action-providers/opensea/schemas.js +33 -0
- package/dist/action-providers/opensea/utils.d.ts +12 -0
- package/dist/action-providers/opensea/utils.js +47 -0
- package/dist/action-providers/pyth/index.d.ts +2 -0
- package/dist/action-providers/pyth/index.js +18 -0
- package/dist/action-providers/pyth/pythActionProvider.d.ts +33 -0
- package/dist/action-providers/pyth/pythActionProvider.js +121 -0
- package/dist/action-providers/pyth/pythActionProvider.test.d.ts +1 -0
- package/dist/action-providers/pyth/pythActionProvider.test.js +113 -0
- package/dist/action-providers/pyth/schemas.d.ts +21 -0
- package/dist/action-providers/pyth/schemas.js +20 -0
- package/dist/action-providers/spl/index.d.ts +1 -0
- package/dist/action-providers/spl/index.js +17 -0
- package/dist/action-providers/spl/schemas.d.ts +30 -0
- package/dist/action-providers/spl/schemas.js +26 -0
- package/dist/action-providers/spl/splActionProvider.d.ts +45 -0
- package/dist/action-providers/spl/splActionProvider.js +173 -0
- package/dist/action-providers/spl/splActionProvider.test.d.ts +1 -0
- package/dist/action-providers/spl/splActionProvider.test.js +300 -0
- package/dist/action-providers/twitter/index.d.ts +2 -0
- package/dist/action-providers/twitter/index.js +18 -0
- package/dist/action-providers/twitter/schemas.d.ts +38 -0
- package/dist/action-providers/twitter/schemas.js +44 -0
- package/dist/action-providers/twitter/twitterActionProvider.d.ts +82 -0
- package/dist/action-providers/twitter/twitterActionProvider.js +204 -0
- package/dist/action-providers/twitter/twitterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/twitter/twitterActionProvider.test.js +185 -0
- package/dist/action-providers/wallet/index.d.ts +1 -0
- package/dist/action-providers/wallet/index.js +17 -0
- package/dist/action-providers/wallet/schemas.d.ts +19 -0
- package/dist/action-providers/wallet/schemas.js +19 -0
- package/dist/action-providers/wallet/walletActionProvider.d.ts +44 -0
- package/dist/action-providers/wallet/walletActionProvider.js +140 -0
- package/dist/action-providers/wallet/walletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/wallet/walletActionProvider.test.js +194 -0
- package/dist/action-providers/weth/constants.d.ts +19 -0
- package/dist/action-providers/weth/constants.js +29 -0
- package/dist/action-providers/weth/index.d.ts +1 -0
- package/dist/action-providers/weth/index.js +17 -0
- package/dist/action-providers/weth/schemas.d.ts +8 -0
- package/dist/action-providers/weth/schemas.js +10 -0
- package/dist/action-providers/weth/wethActionProvider.d.ts +30 -0
- package/dist/action-providers/weth/wethActionProvider.js +89 -0
- package/dist/action-providers/weth/wethActionProvider.test.d.ts +1 -0
- package/dist/action-providers/weth/wethActionProvider.test.js +92 -0
- package/dist/action-providers/wow/constants.d.ts +15 -0
- package/dist/action-providers/wow/constants.js +844 -0
- package/dist/action-providers/wow/index.d.ts +2 -0
- package/dist/action-providers/wow/index.js +18 -0
- package/dist/action-providers/wow/schemas.d.ts +43 -0
- package/dist/action-providers/wow/schemas.js +47 -0
- package/dist/action-providers/wow/uniswap/constants.d.ts +3 -0
- package/dist/action-providers/wow/uniswap/constants.js +100 -0
- package/dist/action-providers/wow/uniswap/utils.d.ts +82 -0
- package/dist/action-providers/wow/uniswap/utils.js +226 -0
- package/dist/action-providers/wow/utils.d.ts +27 -0
- package/dist/action-providers/wow/utils.js +63 -0
- package/dist/action-providers/wow/wowActionProvider.d.ts +46 -0
- package/dist/action-providers/wow/wowActionProvider.js +223 -0
- package/dist/action-providers/wow/wowActionProvider.test.d.ts +1 -0
- package/dist/action-providers/wow/wowActionProvider.test.js +291 -0
- package/dist/agentkit.d.ts +44 -0
- package/dist/agentkit.js +68 -0
- package/dist/analytics/index.d.ts +1 -0
- package/dist/analytics/index.js +17 -0
- package/dist/analytics/sendAnalyticsEvent.d.ts +31 -0
- package/dist/analytics/sendAnalyticsEvent.js +52 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/network/index.d.ts +3 -0
- package/dist/network/index.js +19 -0
- package/dist/network/network.d.ts +20 -0
- package/dist/network/network.js +86 -0
- package/dist/network/svm.d.ts +15 -0
- package/dist/network/svm.js +38 -0
- package/dist/network/types.d.ts +17 -0
- package/dist/network/types.js +2 -0
- package/dist/utils.d.ts +22 -0
- package/dist/utils.js +57 -0
- package/dist/utils.test.d.ts +1 -0
- package/dist/utils.test.js +50 -0
- package/dist/wallet-providers/cdpWalletProvider.d.ts +246 -0
- package/dist/wallet-providers/cdpWalletProvider.js +421 -0
- package/dist/wallet-providers/cdpWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/cdpWalletProvider.test.js +701 -0
- package/dist/wallet-providers/evmWalletProvider.d.ts +51 -0
- package/dist/wallet-providers/evmWalletProvider.js +14 -0
- package/dist/wallet-providers/evmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/evmWalletProvider.test.js +56 -0
- package/dist/wallet-providers/index.d.ts +10 -0
- package/dist/wallet-providers/index.js +26 -0
- package/dist/wallet-providers/privyEvmWalletProvider.d.ts +55 -0
- package/dist/wallet-providers/privyEvmWalletProvider.js +140 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +331 -0
- package/dist/wallet-providers/privyShared.d.ts +40 -0
- package/dist/wallet-providers/privyShared.js +49 -0
- package/dist/wallet-providers/privySvmWalletProvider.d.ts +128 -0
- package/dist/wallet-providers/privySvmWalletProvider.js +212 -0
- package/dist/wallet-providers/privySvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privySvmWalletProvider.test.js +310 -0
- package/dist/wallet-providers/privyWalletProvider.d.ts +35 -0
- package/dist/wallet-providers/privyWalletProvider.js +39 -0
- package/dist/wallet-providers/privyWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyWalletProvider.test.js +124 -0
- package/dist/wallet-providers/smartWalletProvider.d.ts +177 -0
- package/dist/wallet-providers/smartWalletProvider.js +303 -0
- package/dist/wallet-providers/smartWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/smartWalletProvider.test.js +388 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +143 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.js +280 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +218 -0
- package/dist/wallet-providers/svmWalletProvider.d.ts +56 -0
- package/dist/wallet-providers/svmWalletProvider.js +13 -0
- package/dist/wallet-providers/svmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/svmWalletProvider.test.js +55 -0
- package/dist/wallet-providers/viemWalletProvider.d.ts +103 -0
- package/dist/wallet-providers/viemWalletProvider.js +206 -0
- package/dist/wallet-providers/viemWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/viemWalletProvider.test.js +338 -0
- package/dist/wallet-providers/walletProvider.d.ts +48 -0
- package/dist/wallet-providers/walletProvider.js +41 -0
- package/dist/wallet-providers/walletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/walletProvider.test.js +103 -0
- package/package.json +83 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { WalletClient as ViemWalletClient, TransactionRequest, ReadContractParameters, ReadContractReturnType, Abi, ContractFunctionName, ContractFunctionArgs } from "viem";
|
|
2
|
+
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
3
|
+
import { Network } from "../network";
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for gas multipliers.
|
|
6
|
+
*/
|
|
7
|
+
export interface ViemWalletProviderGasConfig {
|
|
8
|
+
/**
|
|
9
|
+
* An internal multiplier on gas limit estimation.
|
|
10
|
+
*/
|
|
11
|
+
gasLimitMultiplier?: number;
|
|
12
|
+
/**
|
|
13
|
+
* An internal multiplier on fee per gas estimation.
|
|
14
|
+
*/
|
|
15
|
+
feePerGasMultiplier?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A wallet provider that uses the Viem library.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ViemWalletProvider extends EvmWalletProvider {
|
|
21
|
+
#private;
|
|
22
|
+
/**
|
|
23
|
+
* Constructs a new ViemWalletProvider.
|
|
24
|
+
*
|
|
25
|
+
* @param walletClient - The wallet client.
|
|
26
|
+
* @param gasConfig - Configuration for gas multipliers.
|
|
27
|
+
*/
|
|
28
|
+
constructor(walletClient: ViemWalletClient, gasConfig?: ViemWalletProviderGasConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Signs a message.
|
|
31
|
+
*
|
|
32
|
+
* @param message - The message to sign.
|
|
33
|
+
* @returns The signed message.
|
|
34
|
+
*/
|
|
35
|
+
signMessage(message: string): Promise<`0x${string}`>;
|
|
36
|
+
/**
|
|
37
|
+
* Signs a typed data object.
|
|
38
|
+
*
|
|
39
|
+
* @param typedData - The typed data object to sign.
|
|
40
|
+
* @returns The signed typed data object.
|
|
41
|
+
*/
|
|
42
|
+
signTypedData(typedData: any): Promise<`0x${string}`>;
|
|
43
|
+
/**
|
|
44
|
+
* Signs a transaction.
|
|
45
|
+
*
|
|
46
|
+
* @param transaction - The transaction to sign.
|
|
47
|
+
* @returns The signed transaction.
|
|
48
|
+
*/
|
|
49
|
+
signTransaction(transaction: TransactionRequest): Promise<`0x${string}`>;
|
|
50
|
+
/**
|
|
51
|
+
* Sends a transaction.
|
|
52
|
+
*
|
|
53
|
+
* @param transaction - The transaction to send.
|
|
54
|
+
* @returns The hash of the transaction.
|
|
55
|
+
*/
|
|
56
|
+
sendTransaction(transaction: TransactionRequest): Promise<`0x${string}`>;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the address of the wallet.
|
|
59
|
+
*
|
|
60
|
+
* @returns The address of the wallet.
|
|
61
|
+
*/
|
|
62
|
+
getAddress(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the network of the wallet.
|
|
65
|
+
*
|
|
66
|
+
* @returns The network of the wallet.
|
|
67
|
+
*/
|
|
68
|
+
getNetwork(): Network;
|
|
69
|
+
/**
|
|
70
|
+
* Gets the name of the wallet provider.
|
|
71
|
+
*
|
|
72
|
+
* @returns The name of the wallet provider.
|
|
73
|
+
*/
|
|
74
|
+
getName(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Gets the balance of the wallet.
|
|
77
|
+
*
|
|
78
|
+
* @returns The balance of the wallet.
|
|
79
|
+
*/
|
|
80
|
+
getBalance(): Promise<bigint>;
|
|
81
|
+
/**
|
|
82
|
+
* Waits for a transaction receipt.
|
|
83
|
+
*
|
|
84
|
+
* @param txHash - The hash of the transaction to wait for.
|
|
85
|
+
* @returns The transaction receipt.
|
|
86
|
+
*/
|
|
87
|
+
waitForTransactionReceipt(txHash: `0x${string}`): Promise<any>;
|
|
88
|
+
/**
|
|
89
|
+
* Reads a contract.
|
|
90
|
+
*
|
|
91
|
+
* @param params - The parameters to read the contract.
|
|
92
|
+
* @returns The response from the contract.
|
|
93
|
+
*/
|
|
94
|
+
readContract<const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName<abi, "pure" | "view">, const args extends ContractFunctionArgs<abi, "pure" | "view", functionName>>(params: ReadContractParameters<abi, functionName, args>): Promise<ReadContractReturnType<abi, functionName, args>>;
|
|
95
|
+
/**
|
|
96
|
+
* Transfer the native asset of the network.
|
|
97
|
+
*
|
|
98
|
+
* @param to - The destination address.
|
|
99
|
+
* @param value - The amount to transfer in whole units (e.g. ETH)
|
|
100
|
+
* @returns The transaction hash.
|
|
101
|
+
*/
|
|
102
|
+
nativeTransfer(to: `0x${string}`, value: string): Promise<`0x${string}`>;
|
|
103
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TODO: Improve type safety
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
5
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
6
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
7
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
8
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
9
|
+
};
|
|
10
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
11
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
13
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
+
};
|
|
15
|
+
var _ViemWalletProvider_walletClient, _ViemWalletProvider_publicClient, _ViemWalletProvider_gasLimitMultiplier, _ViemWalletProvider_feePerGasMultiplier;
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ViemWalletProvider = void 0;
|
|
18
|
+
const viem_1 = require("viem");
|
|
19
|
+
const evmWalletProvider_1 = require("./evmWalletProvider");
|
|
20
|
+
const network_1 = require("../network/network");
|
|
21
|
+
const utils_1 = require("../utils");
|
|
22
|
+
/**
|
|
23
|
+
* A wallet provider that uses the Viem library.
|
|
24
|
+
*/
|
|
25
|
+
class ViemWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
26
|
+
/**
|
|
27
|
+
* Constructs a new ViemWalletProvider.
|
|
28
|
+
*
|
|
29
|
+
* @param walletClient - The wallet client.
|
|
30
|
+
* @param gasConfig - Configuration for gas multipliers.
|
|
31
|
+
*/
|
|
32
|
+
constructor(walletClient, gasConfig) {
|
|
33
|
+
super();
|
|
34
|
+
_ViemWalletProvider_walletClient.set(this, void 0);
|
|
35
|
+
_ViemWalletProvider_publicClient.set(this, void 0);
|
|
36
|
+
_ViemWalletProvider_gasLimitMultiplier.set(this, void 0);
|
|
37
|
+
_ViemWalletProvider_feePerGasMultiplier.set(this, void 0);
|
|
38
|
+
__classPrivateFieldSet(this, _ViemWalletProvider_walletClient, walletClient, "f");
|
|
39
|
+
__classPrivateFieldSet(this, _ViemWalletProvider_publicClient, (0, viem_1.createPublicClient)({
|
|
40
|
+
chain: walletClient.chain,
|
|
41
|
+
transport: (0, viem_1.http)(),
|
|
42
|
+
}), "f");
|
|
43
|
+
__classPrivateFieldSet(this, _ViemWalletProvider_gasLimitMultiplier, Math.max(gasConfig?.gasLimitMultiplier ?? 1.2, 1), "f");
|
|
44
|
+
__classPrivateFieldSet(this, _ViemWalletProvider_feePerGasMultiplier, Math.max(gasConfig?.feePerGasMultiplier ?? 1, 1), "f");
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Signs a message.
|
|
48
|
+
*
|
|
49
|
+
* @param message - The message to sign.
|
|
50
|
+
* @returns The signed message.
|
|
51
|
+
*/
|
|
52
|
+
async signMessage(message) {
|
|
53
|
+
const account = __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").account;
|
|
54
|
+
if (!account) {
|
|
55
|
+
throw new Error("Account not found");
|
|
56
|
+
}
|
|
57
|
+
return __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").signMessage({ account, message });
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Signs a typed data object.
|
|
61
|
+
*
|
|
62
|
+
* @param typedData - The typed data object to sign.
|
|
63
|
+
* @returns The signed typed data object.
|
|
64
|
+
*/
|
|
65
|
+
async signTypedData(typedData) {
|
|
66
|
+
return __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").signTypedData({
|
|
67
|
+
account: __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").account,
|
|
68
|
+
domain: typedData.domain,
|
|
69
|
+
types: typedData.types,
|
|
70
|
+
primaryType: typedData.primaryType,
|
|
71
|
+
message: typedData.message,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Signs a transaction.
|
|
76
|
+
*
|
|
77
|
+
* @param transaction - The transaction to sign.
|
|
78
|
+
* @returns The signed transaction.
|
|
79
|
+
*/
|
|
80
|
+
async signTransaction(transaction) {
|
|
81
|
+
const txParams = {
|
|
82
|
+
account: __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").account,
|
|
83
|
+
to: transaction.to,
|
|
84
|
+
value: transaction.value,
|
|
85
|
+
data: transaction.data,
|
|
86
|
+
chain: __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").chain,
|
|
87
|
+
};
|
|
88
|
+
return __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").signTransaction(txParams);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Sends a transaction.
|
|
92
|
+
*
|
|
93
|
+
* @param transaction - The transaction to send.
|
|
94
|
+
* @returns The hash of the transaction.
|
|
95
|
+
*/
|
|
96
|
+
async sendTransaction(transaction) {
|
|
97
|
+
const account = __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").account;
|
|
98
|
+
if (!account) {
|
|
99
|
+
throw new Error("Account not found");
|
|
100
|
+
}
|
|
101
|
+
const chain = __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").chain;
|
|
102
|
+
if (!chain) {
|
|
103
|
+
throw new Error("Chain not found");
|
|
104
|
+
}
|
|
105
|
+
const feeData = await __classPrivateFieldGet(this, _ViemWalletProvider_publicClient, "f").estimateFeesPerGas();
|
|
106
|
+
const maxFeePerGas = (0, utils_1.applyGasMultiplier)(feeData.maxFeePerGas, __classPrivateFieldGet(this, _ViemWalletProvider_feePerGasMultiplier, "f"));
|
|
107
|
+
const maxPriorityFeePerGas = (0, utils_1.applyGasMultiplier)(feeData.maxPriorityFeePerGas, __classPrivateFieldGet(this, _ViemWalletProvider_feePerGasMultiplier, "f"));
|
|
108
|
+
const gasLimit = await __classPrivateFieldGet(this, _ViemWalletProvider_publicClient, "f").estimateGas({
|
|
109
|
+
account,
|
|
110
|
+
to: transaction.to,
|
|
111
|
+
value: transaction.value,
|
|
112
|
+
data: transaction.data,
|
|
113
|
+
});
|
|
114
|
+
const gas = BigInt(Math.round(Number(gasLimit) * __classPrivateFieldGet(this, _ViemWalletProvider_gasLimitMultiplier, "f")));
|
|
115
|
+
const txParams = {
|
|
116
|
+
account: account,
|
|
117
|
+
chain: chain,
|
|
118
|
+
data: transaction.data,
|
|
119
|
+
to: transaction.to,
|
|
120
|
+
value: transaction.value,
|
|
121
|
+
gas,
|
|
122
|
+
maxFeePerGas,
|
|
123
|
+
maxPriorityFeePerGas,
|
|
124
|
+
};
|
|
125
|
+
return __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").sendTransaction(txParams);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Gets the address of the wallet.
|
|
129
|
+
*
|
|
130
|
+
* @returns The address of the wallet.
|
|
131
|
+
*/
|
|
132
|
+
getAddress() {
|
|
133
|
+
return __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").account?.address ?? "";
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Gets the network of the wallet.
|
|
137
|
+
*
|
|
138
|
+
* @returns The network of the wallet.
|
|
139
|
+
*/
|
|
140
|
+
getNetwork() {
|
|
141
|
+
return {
|
|
142
|
+
protocolFamily: "evm",
|
|
143
|
+
chainId: String(__classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").chain.id),
|
|
144
|
+
networkId: network_1.CHAIN_ID_TO_NETWORK_ID[__classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").chain.id],
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Gets the name of the wallet provider.
|
|
149
|
+
*
|
|
150
|
+
* @returns The name of the wallet provider.
|
|
151
|
+
*/
|
|
152
|
+
getName() {
|
|
153
|
+
return "viem_wallet_provider";
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Gets the balance of the wallet.
|
|
157
|
+
*
|
|
158
|
+
* @returns The balance of the wallet.
|
|
159
|
+
*/
|
|
160
|
+
async getBalance() {
|
|
161
|
+
const account = __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").account;
|
|
162
|
+
if (!account) {
|
|
163
|
+
throw new Error("Account not found");
|
|
164
|
+
}
|
|
165
|
+
return __classPrivateFieldGet(this, _ViemWalletProvider_publicClient, "f").getBalance({ address: account.address });
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Waits for a transaction receipt.
|
|
169
|
+
*
|
|
170
|
+
* @param txHash - The hash of the transaction to wait for.
|
|
171
|
+
* @returns The transaction receipt.
|
|
172
|
+
*/
|
|
173
|
+
async waitForTransactionReceipt(txHash) {
|
|
174
|
+
return await __classPrivateFieldGet(this, _ViemWalletProvider_publicClient, "f").waitForTransactionReceipt({ hash: txHash });
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Reads a contract.
|
|
178
|
+
*
|
|
179
|
+
* @param params - The parameters to read the contract.
|
|
180
|
+
* @returns The response from the contract.
|
|
181
|
+
*/
|
|
182
|
+
async readContract(params) {
|
|
183
|
+
return __classPrivateFieldGet(this, _ViemWalletProvider_publicClient, "f").readContract(params);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Transfer the native asset of the network.
|
|
187
|
+
*
|
|
188
|
+
* @param to - The destination address.
|
|
189
|
+
* @param value - The amount to transfer in whole units (e.g. ETH)
|
|
190
|
+
* @returns The transaction hash.
|
|
191
|
+
*/
|
|
192
|
+
async nativeTransfer(to, value) {
|
|
193
|
+
const atomicAmount = (0, viem_1.parseEther)(value);
|
|
194
|
+
const tx = await this.sendTransaction({
|
|
195
|
+
to: to,
|
|
196
|
+
value: atomicAmount,
|
|
197
|
+
});
|
|
198
|
+
const receipt = await this.waitForTransactionReceipt(tx);
|
|
199
|
+
if (!receipt) {
|
|
200
|
+
throw new Error("Transaction failed");
|
|
201
|
+
}
|
|
202
|
+
return receipt.transactionHash;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports.ViemWalletProvider = ViemWalletProvider;
|
|
206
|
+
_ViemWalletProvider_walletClient = new WeakMap(), _ViemWalletProvider_publicClient = new WeakMap(), _ViemWalletProvider_gasLimitMultiplier = new WeakMap(), _ViemWalletProvider_feePerGasMultiplier = new WeakMap();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const viemWalletProvider_1 = require("./viemWalletProvider");
|
|
37
|
+
const viem = __importStar(require("viem"));
|
|
38
|
+
global.fetch = jest.fn(() => Promise.resolve({
|
|
39
|
+
ok: true,
|
|
40
|
+
json: () => Promise.resolve({}),
|
|
41
|
+
}));
|
|
42
|
+
jest.mock("../analytics", () => ({
|
|
43
|
+
sendAnalyticsEvent: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
44
|
+
}));
|
|
45
|
+
// =========================================================
|
|
46
|
+
// consts
|
|
47
|
+
// =========================================================
|
|
48
|
+
const MOCK_CHAIN_ID = 84532;
|
|
49
|
+
const MOCK_ADDRESS = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e";
|
|
50
|
+
const MOCK_ADDRESS_TO = "0x1234567890123456789012345678901234567890";
|
|
51
|
+
const MOCK_TRANSACTION_HASH = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
52
|
+
const MOCK_SIGNATURE = "0x123456789abcdef";
|
|
53
|
+
const MOCK_BALANCE = 10000000000000000000n;
|
|
54
|
+
const MOCK_BLOCK_NUMBER = 12345n;
|
|
55
|
+
const MOCK_MESSAGE = "Hello, World!";
|
|
56
|
+
const MOCK_MAX_FEE_PER_GAS = BigInt(1000000000);
|
|
57
|
+
const MOCK_MAX_PRIORITY_FEE_PER_GAS = BigInt(100000000);
|
|
58
|
+
const MOCK_CHAIN = {
|
|
59
|
+
id: MOCK_CHAIN_ID,
|
|
60
|
+
name: "Base Sepolia",
|
|
61
|
+
nativeCurrency: { name: "ETH", symbol: "ETH", decimals: 18 },
|
|
62
|
+
rpcUrls: {
|
|
63
|
+
default: {
|
|
64
|
+
http: ["https://sepolia.base.org"],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
const MOCK_DATA = {
|
|
69
|
+
domain: {
|
|
70
|
+
name: "Example",
|
|
71
|
+
version: "1",
|
|
72
|
+
chainId: 1,
|
|
73
|
+
verifyingContract: "0x0000000000000000000000000000000000000000",
|
|
74
|
+
},
|
|
75
|
+
types: {
|
|
76
|
+
Person: [
|
|
77
|
+
{ name: "name", type: "string" },
|
|
78
|
+
{ name: "wallet", type: "address" },
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
primaryType: "Person",
|
|
82
|
+
message: {
|
|
83
|
+
name: "John Doe",
|
|
84
|
+
wallet: "0x0000000000000000000000000000000000000000",
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
// =========================================================
|
|
88
|
+
// mocks
|
|
89
|
+
// =========================================================
|
|
90
|
+
jest.mock("../network/network", () => ({
|
|
91
|
+
CHAIN_ID_TO_NETWORK_ID: {
|
|
92
|
+
1: "mainnet",
|
|
93
|
+
5: "goerli",
|
|
94
|
+
11155111: "sepolia",
|
|
95
|
+
},
|
|
96
|
+
}));
|
|
97
|
+
jest.mock("viem", () => {
|
|
98
|
+
return {
|
|
99
|
+
createPublicClient: jest.fn(),
|
|
100
|
+
createWalletClient: jest.fn(),
|
|
101
|
+
http: jest.fn(() => jest.fn()),
|
|
102
|
+
parseEther: jest.fn(() => BigInt(1000000000000000000)),
|
|
103
|
+
hexToString: jest.fn(),
|
|
104
|
+
fromHex: jest.fn(),
|
|
105
|
+
formatEther: jest.fn(),
|
|
106
|
+
privateKeyToAccount: jest.fn(),
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
jest.mock("viem/accounts", () => {
|
|
110
|
+
return {
|
|
111
|
+
privateKeyToAccount: jest.fn(),
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
describe("ViemWalletProvider", () => {
|
|
115
|
+
let provider;
|
|
116
|
+
let mockPublicClient;
|
|
117
|
+
let mockWalletClient;
|
|
118
|
+
beforeEach(() => {
|
|
119
|
+
jest.clearAllMocks();
|
|
120
|
+
const mockAccount = {
|
|
121
|
+
address: MOCK_ADDRESS,
|
|
122
|
+
};
|
|
123
|
+
mockPublicClient = {
|
|
124
|
+
chain: MOCK_CHAIN,
|
|
125
|
+
getBalance: jest.fn(),
|
|
126
|
+
getChainId: jest.fn(),
|
|
127
|
+
waitForTransactionReceipt: jest.fn(),
|
|
128
|
+
readContract: jest.fn(),
|
|
129
|
+
estimateFeesPerGas: jest.fn(),
|
|
130
|
+
estimateGas: jest.fn(),
|
|
131
|
+
};
|
|
132
|
+
mockPublicClient.getBalance.mockResolvedValue(MOCK_BALANCE);
|
|
133
|
+
mockPublicClient.getChainId.mockResolvedValue(MOCK_CHAIN_ID);
|
|
134
|
+
mockPublicClient.waitForTransactionReceipt.mockResolvedValue({
|
|
135
|
+
transactionHash: MOCK_TRANSACTION_HASH,
|
|
136
|
+
blockNumber: MOCK_BLOCK_NUMBER,
|
|
137
|
+
status: "success",
|
|
138
|
+
});
|
|
139
|
+
mockPublicClient.readContract.mockResolvedValue("mock_result");
|
|
140
|
+
mockPublicClient.estimateFeesPerGas.mockResolvedValue({
|
|
141
|
+
maxFeePerGas: MOCK_MAX_FEE_PER_GAS,
|
|
142
|
+
maxPriorityFeePerGas: MOCK_MAX_PRIORITY_FEE_PER_GAS,
|
|
143
|
+
});
|
|
144
|
+
mockPublicClient.estimateGas.mockResolvedValue(BigInt(21000));
|
|
145
|
+
mockWalletClient = {
|
|
146
|
+
chain: MOCK_CHAIN,
|
|
147
|
+
transport: {
|
|
148
|
+
name: "HTTP JSON-RPC",
|
|
149
|
+
request: jest.fn(),
|
|
150
|
+
value: { url: "https://ethereum.example.com" },
|
|
151
|
+
},
|
|
152
|
+
account: mockAccount,
|
|
153
|
+
signMessage: jest.fn(),
|
|
154
|
+
signTypedData: jest.fn(),
|
|
155
|
+
signTransaction: jest.fn(),
|
|
156
|
+
sendTransaction: jest.fn(),
|
|
157
|
+
};
|
|
158
|
+
mockWalletClient.signMessage.mockResolvedValue(MOCK_SIGNATURE);
|
|
159
|
+
mockWalletClient.signTypedData.mockResolvedValue(MOCK_SIGNATURE);
|
|
160
|
+
mockWalletClient.signTransaction.mockResolvedValue(MOCK_SIGNATURE);
|
|
161
|
+
mockWalletClient.sendTransaction.mockResolvedValue(MOCK_TRANSACTION_HASH);
|
|
162
|
+
viem.createPublicClient.mockReturnValue(mockPublicClient);
|
|
163
|
+
viem.createWalletClient.mockReturnValue(mockWalletClient);
|
|
164
|
+
viem.http.mockReturnValue(jest.fn());
|
|
165
|
+
provider = new viemWalletProvider_1.ViemWalletProvider(mockWalletClient);
|
|
166
|
+
});
|
|
167
|
+
describe("configuration and initialization", () => {
|
|
168
|
+
it("should create a provider with default gas multipliers", () => {
|
|
169
|
+
const provider = new viemWalletProvider_1.ViemWalletProvider(mockWalletClient);
|
|
170
|
+
expect(provider).toBeInstanceOf(viemWalletProvider_1.ViemWalletProvider);
|
|
171
|
+
expect(viem.createPublicClient).toHaveBeenCalledWith({
|
|
172
|
+
chain: MOCK_CHAIN,
|
|
173
|
+
transport: expect.any(Function),
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
it("should create a provider with custom gas multipliers", () => {
|
|
177
|
+
const gasConfig = {
|
|
178
|
+
gasLimitMultiplier: 1.5,
|
|
179
|
+
feePerGasMultiplier: 1.2,
|
|
180
|
+
};
|
|
181
|
+
const provider = new viemWalletProvider_1.ViemWalletProvider(mockWalletClient, gasConfig);
|
|
182
|
+
expect(provider).toBeInstanceOf(viemWalletProvider_1.ViemWalletProvider);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
describe("basic wallet methods", () => {
|
|
186
|
+
it("should get wallet address", () => {
|
|
187
|
+
const address = provider.getAddress();
|
|
188
|
+
expect(address).toBe(MOCK_ADDRESS);
|
|
189
|
+
});
|
|
190
|
+
it("should get network", () => {
|
|
191
|
+
const network = provider.getNetwork();
|
|
192
|
+
expect(network.chainId).toBe(String(MOCK_CHAIN_ID));
|
|
193
|
+
expect(network.protocolFamily).toBe("evm");
|
|
194
|
+
});
|
|
195
|
+
it("should get wallet name", () => {
|
|
196
|
+
const name = provider.getName();
|
|
197
|
+
expect(name).toBe("viem_wallet_provider");
|
|
198
|
+
});
|
|
199
|
+
it("should get balance", async () => {
|
|
200
|
+
const balance = await provider.getBalance();
|
|
201
|
+
expect(balance).toBe(MOCK_BALANCE);
|
|
202
|
+
expect(mockPublicClient.getBalance).toHaveBeenCalledWith({
|
|
203
|
+
address: MOCK_ADDRESS,
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
it("should handle connection errors during balance check", async () => {
|
|
207
|
+
mockPublicClient.getBalance.mockRejectedValueOnce(new Error("Network connection error"));
|
|
208
|
+
await expect(provider.getBalance()).rejects.toThrow("Network connection error");
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
describe("signing operations", () => {
|
|
212
|
+
it("should sign a message", async () => {
|
|
213
|
+
const signature = await provider.signMessage(MOCK_MESSAGE);
|
|
214
|
+
expect(mockWalletClient.signMessage).toHaveBeenCalledWith({
|
|
215
|
+
account: mockWalletClient.account,
|
|
216
|
+
message: MOCK_MESSAGE,
|
|
217
|
+
});
|
|
218
|
+
expect(signature).toBe(MOCK_SIGNATURE);
|
|
219
|
+
});
|
|
220
|
+
it("should sign typed data", async () => {
|
|
221
|
+
const signature = await provider.signTypedData(MOCK_DATA);
|
|
222
|
+
expect(mockWalletClient.signTypedData).toHaveBeenCalledWith({
|
|
223
|
+
account: mockWalletClient.account,
|
|
224
|
+
...MOCK_DATA,
|
|
225
|
+
});
|
|
226
|
+
expect(signature).toBe(MOCK_SIGNATURE);
|
|
227
|
+
});
|
|
228
|
+
it("should sign a transaction", async () => {
|
|
229
|
+
const transaction = {
|
|
230
|
+
to: MOCK_ADDRESS_TO,
|
|
231
|
+
value: BigInt(1000000000000000000),
|
|
232
|
+
};
|
|
233
|
+
await provider.signTransaction(transaction);
|
|
234
|
+
expect(mockWalletClient.signTransaction).toHaveBeenCalledWith({
|
|
235
|
+
account: mockWalletClient.account,
|
|
236
|
+
chain: mockWalletClient.chain,
|
|
237
|
+
to: transaction.to,
|
|
238
|
+
value: transaction.value,
|
|
239
|
+
data: transaction.data,
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
it("should handle signing errors", async () => {
|
|
243
|
+
mockWalletClient.signMessage.mockRejectedValueOnce(new Error("Signing failed"));
|
|
244
|
+
await expect(provider.signMessage("test message")).rejects.toThrow("Signing failed");
|
|
245
|
+
});
|
|
246
|
+
it("should handle typed data signing errors", async () => {
|
|
247
|
+
mockWalletClient.signTypedData.mockRejectedValueOnce(new Error("Signing failed"));
|
|
248
|
+
await expect(provider.signTypedData(MOCK_DATA)).rejects.toThrow("Signing failed");
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
describe("transaction operations", () => {
|
|
252
|
+
it("should send a transaction", async () => {
|
|
253
|
+
const transaction = {
|
|
254
|
+
to: MOCK_ADDRESS_TO,
|
|
255
|
+
value: BigInt(1000000000000000000),
|
|
256
|
+
};
|
|
257
|
+
const hash = await provider.sendTransaction(transaction);
|
|
258
|
+
expect(mockWalletClient.sendTransaction).toHaveBeenCalled();
|
|
259
|
+
expect(hash).toBe(MOCK_TRANSACTION_HASH);
|
|
260
|
+
});
|
|
261
|
+
it("should wait for a transaction receipt", async () => {
|
|
262
|
+
const receipt = await provider.waitForTransactionReceipt(MOCK_TRANSACTION_HASH);
|
|
263
|
+
expect(mockPublicClient.waitForTransactionReceipt).toHaveBeenCalledWith({
|
|
264
|
+
hash: MOCK_TRANSACTION_HASH,
|
|
265
|
+
});
|
|
266
|
+
expect(receipt).toEqual({
|
|
267
|
+
transactionHash: MOCK_TRANSACTION_HASH,
|
|
268
|
+
blockNumber: MOCK_BLOCK_NUMBER,
|
|
269
|
+
status: "success",
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
it("should handle transaction send errors", async () => {
|
|
273
|
+
mockWalletClient.sendTransaction.mockRejectedValueOnce(new Error("Transaction failed"));
|
|
274
|
+
const transaction = {
|
|
275
|
+
to: MOCK_ADDRESS_TO,
|
|
276
|
+
value: BigInt(1000000000000000000),
|
|
277
|
+
};
|
|
278
|
+
await expect(provider.sendTransaction(transaction)).rejects.toThrow("Transaction failed");
|
|
279
|
+
});
|
|
280
|
+
it("should handle transaction receipt wait errors", async () => {
|
|
281
|
+
mockPublicClient.waitForTransactionReceipt.mockRejectedValueOnce(new Error("Receipt retrieval failed"));
|
|
282
|
+
await expect(provider.waitForTransactionReceipt(MOCK_TRANSACTION_HASH)).rejects.toThrow("Receipt retrieval failed");
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
describe("native token operations", () => {
|
|
286
|
+
it("should transfer native tokens", async () => {
|
|
287
|
+
viem.parseEther.mockReturnValueOnce(BigInt(1000000000000000000));
|
|
288
|
+
const hash = await provider.nativeTransfer(MOCK_ADDRESS_TO, "1.0");
|
|
289
|
+
expect(viem.parseEther).toHaveBeenCalledWith("1.0");
|
|
290
|
+
expect(mockWalletClient.sendTransaction).toHaveBeenCalled();
|
|
291
|
+
expect(hash).toBe(MOCK_TRANSACTION_HASH);
|
|
292
|
+
});
|
|
293
|
+
it("should handle native transfer errors", async () => {
|
|
294
|
+
mockWalletClient.sendTransaction.mockRejectedValueOnce(new Error("Transaction failed"));
|
|
295
|
+
await expect(provider.nativeTransfer(MOCK_ADDRESS_TO, "1.0")).rejects.toThrow("Transaction failed");
|
|
296
|
+
});
|
|
297
|
+
it("should handle invalid address in native transfer", async () => {
|
|
298
|
+
const invalidAddress = "not_a_valid_address";
|
|
299
|
+
mockWalletClient.sendTransaction.mockImplementationOnce(() => {
|
|
300
|
+
throw new Error("Invalid address");
|
|
301
|
+
});
|
|
302
|
+
await expect(provider.nativeTransfer(invalidAddress, "1.0")).rejects.toThrow();
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
describe("contract interactions", () => {
|
|
306
|
+
it("should read contract data", async () => {
|
|
307
|
+
const contractParams = {
|
|
308
|
+
address: MOCK_ADDRESS_TO,
|
|
309
|
+
abi: [],
|
|
310
|
+
functionName: "balanceOf",
|
|
311
|
+
args: [MOCK_ADDRESS],
|
|
312
|
+
};
|
|
313
|
+
const result = await provider.readContract(contractParams);
|
|
314
|
+
expect(mockPublicClient.readContract).toHaveBeenCalledWith(contractParams);
|
|
315
|
+
expect(result).toBe("mock_result");
|
|
316
|
+
});
|
|
317
|
+
it("should handle contract read errors", async () => {
|
|
318
|
+
mockPublicClient.readContract.mockRejectedValueOnce(new Error("Contract read failed"));
|
|
319
|
+
const contractParams = {
|
|
320
|
+
address: MOCK_ADDRESS_TO,
|
|
321
|
+
abi: [],
|
|
322
|
+
functionName: "balanceOf",
|
|
323
|
+
args: [MOCK_ADDRESS],
|
|
324
|
+
};
|
|
325
|
+
await expect(provider.readContract(contractParams)).rejects.toThrow("Contract read failed");
|
|
326
|
+
});
|
|
327
|
+
it("should handle invalid ABI in contract read", async () => {
|
|
328
|
+
mockPublicClient.readContract.mockRejectedValueOnce(new TypeError("Invalid ABI format"));
|
|
329
|
+
const contractParams = {
|
|
330
|
+
address: MOCK_ADDRESS_TO,
|
|
331
|
+
abi: "invalid abi",
|
|
332
|
+
functionName: "balanceOf",
|
|
333
|
+
args: [MOCK_ADDRESS],
|
|
334
|
+
};
|
|
335
|
+
await expect(provider.readContract(contractParams)).rejects.toThrow("Invalid ABI format");
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
});
|