@coinbase/agentkit 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +234 -0
- package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.d.ts +37 -0
- package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.js +91 -0
- package/dist/action-providers/cdp-v2/index.d.ts +2 -0
- package/dist/action-providers/cdp-v2/index.js +18 -0
- package/dist/action-providers/cdp-v2/schemas.d.ts +11 -0
- package/dist/action-providers/cdp-v2/schemas.js +13 -0
- package/dist/action-providers/compound/schemas.d.ts +8 -8
- package/dist/action-providers/index.d.ts +3 -0
- package/dist/action-providers/index.js +3 -0
- package/dist/action-providers/vaultsfyi/api/actions.d.ts +41 -0
- package/dist/action-providers/vaultsfyi/api/actions.js +28 -0
- package/dist/action-providers/vaultsfyi/api/types.d.ts +34 -0
- package/dist/action-providers/vaultsfyi/api/types.js +2 -0
- package/dist/action-providers/vaultsfyi/api/vaults.d.ts +38 -0
- package/dist/action-providers/vaultsfyi/api/vaults.js +39 -0
- package/dist/action-providers/vaultsfyi/constants.d.ts +12 -0
- package/dist/action-providers/vaultsfyi/constants.js +15 -0
- package/dist/action-providers/vaultsfyi/index.d.ts +7 -0
- package/dist/action-providers/vaultsfyi/index.js +23 -0
- package/dist/action-providers/vaultsfyi/schemas.d.ts +94 -0
- package/dist/action-providers/vaultsfyi/schemas.js +49 -0
- package/dist/action-providers/vaultsfyi/utils.d.ts +34 -0
- package/dist/action-providers/vaultsfyi/utils.js +69 -0
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.d.ts +98 -0
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.js +383 -0
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.test.d.ts +1 -0
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.test.js +438 -0
- package/dist/action-providers/zerodev/index.d.ts +1 -0
- package/dist/action-providers/zerodev/index.js +17 -0
- package/dist/action-providers/zerodev/schemas.d.ts +29 -0
- package/dist/action-providers/zerodev/schemas.js +21 -0
- package/dist/action-providers/zerodev/zeroDevWalletActionProvider.d.ts +32 -0
- package/dist/action-providers/zerodev/zeroDevWalletActionProvider.js +66 -0
- package/dist/action-providers/zerodev/zeroDevWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/zerodev/zeroDevWalletActionProvider.test.js +112 -0
- package/dist/network/svm.d.ts +1 -0
- package/dist/network/svm.js +6 -1
- package/dist/wallet-providers/cdpV2EvmWalletProvider.d.ts +105 -0
- package/dist/wallet-providers/cdpV2EvmWalletProvider.js +212 -0
- package/dist/wallet-providers/cdpV2EvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/cdpV2EvmWalletProvider.test.js +343 -0
- package/dist/wallet-providers/cdpV2Shared.d.ts +41 -0
- package/dist/wallet-providers/cdpV2Shared.js +2 -0
- package/dist/wallet-providers/cdpV2SolanaWalletProvider.d.ts +111 -0
- package/dist/wallet-providers/cdpV2SolanaWalletProvider.js +247 -0
- package/dist/wallet-providers/cdpV2SolanaWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/cdpV2SolanaWalletProvider.test.js +307 -0
- package/dist/wallet-providers/cdpV2WalletProvider.d.ts +35 -0
- package/dist/wallet-providers/cdpV2WalletProvider.js +42 -0
- package/dist/wallet-providers/cdpWalletProvider.js +1 -1
- package/dist/wallet-providers/cdpWalletProvider.test.js +1 -0
- package/dist/wallet-providers/evmWalletProvider.d.ts +7 -1
- package/dist/wallet-providers/evmWalletProvider.js +20 -0
- package/dist/wallet-providers/index.d.ts +5 -0
- package/dist/wallet-providers/index.js +5 -0
- package/dist/wallet-providers/walletProvider.test.js +22 -0
- package/dist/wallet-providers/zeroDevWalletProvider.d.ts +147 -0
- package/dist/wallet-providers/zeroDevWalletProvider.js +301 -0
- package/dist/wallet-providers/zeroDevWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/zeroDevWalletProvider.test.js +435 -0
- package/package.json +5 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.EvmWalletProvider = void 0;
|
|
6
|
+
const accounts_1 = require("viem/accounts");
|
|
6
7
|
const walletProvider_1 = require("./walletProvider");
|
|
7
8
|
/**
|
|
8
9
|
* EvmWalletProvider is the abstract base class for all EVM wallet providers.
|
|
@@ -10,5 +11,24 @@ const walletProvider_1 = require("./walletProvider");
|
|
|
10
11
|
* @abstract
|
|
11
12
|
*/
|
|
12
13
|
class EvmWalletProvider extends walletProvider_1.WalletProvider {
|
|
14
|
+
/**
|
|
15
|
+
* Convert the wallet provider to a Signer.
|
|
16
|
+
*
|
|
17
|
+
* @returns The signer.
|
|
18
|
+
*/
|
|
19
|
+
toSigner() {
|
|
20
|
+
return (0, accounts_1.toAccount)({
|
|
21
|
+
address: this.getAddress(),
|
|
22
|
+
signMessage: async ({ message }) => {
|
|
23
|
+
return this.signMessage(message);
|
|
24
|
+
},
|
|
25
|
+
signTransaction: async (transaction) => {
|
|
26
|
+
return this.signTransaction(transaction);
|
|
27
|
+
},
|
|
28
|
+
signTypedData: async (typedData) => {
|
|
29
|
+
return this.signTypedData(typedData);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
13
33
|
}
|
|
14
34
|
exports.EvmWalletProvider = EvmWalletProvider;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export * from "./walletProvider";
|
|
2
2
|
export * from "./evmWalletProvider";
|
|
3
3
|
export * from "./viemWalletProvider";
|
|
4
|
+
export * from "./cdpV2EvmWalletProvider";
|
|
5
|
+
export * from "./cdpV2SolanaWalletProvider";
|
|
6
|
+
export * from "./cdpV2WalletProvider";
|
|
7
|
+
export * from "./cdpV2Shared";
|
|
4
8
|
export * from "./cdpWalletProvider";
|
|
5
9
|
export * from "./svmWalletProvider";
|
|
6
10
|
export * from "./smartWalletProvider";
|
|
@@ -9,3 +13,4 @@ export * from "./privyWalletProvider";
|
|
|
9
13
|
export * from "./privyEvmWalletProvider";
|
|
10
14
|
export * from "./privySvmWalletProvider";
|
|
11
15
|
export * from "./privyEvmDelegatedEmbeddedWalletProvider";
|
|
16
|
+
export * from "./zeroDevWalletProvider";
|
|
@@ -17,6 +17,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./walletProvider"), exports);
|
|
18
18
|
__exportStar(require("./evmWalletProvider"), exports);
|
|
19
19
|
__exportStar(require("./viemWalletProvider"), exports);
|
|
20
|
+
__exportStar(require("./cdpV2EvmWalletProvider"), exports);
|
|
21
|
+
__exportStar(require("./cdpV2SolanaWalletProvider"), exports);
|
|
22
|
+
__exportStar(require("./cdpV2WalletProvider"), exports);
|
|
23
|
+
__exportStar(require("./cdpV2Shared"), exports);
|
|
20
24
|
__exportStar(require("./cdpWalletProvider"), exports);
|
|
21
25
|
__exportStar(require("./svmWalletProvider"), exports);
|
|
22
26
|
__exportStar(require("./smartWalletProvider"), exports);
|
|
@@ -25,3 +29,4 @@ __exportStar(require("./privyWalletProvider"), exports);
|
|
|
25
29
|
__exportStar(require("./privyEvmWalletProvider"), exports);
|
|
26
30
|
__exportStar(require("./privySvmWalletProvider"), exports);
|
|
27
31
|
__exportStar(require("./privyEvmDelegatedEmbeddedWalletProvider"), exports);
|
|
32
|
+
__exportStar(require("./zeroDevWalletProvider"), exports);
|
|
@@ -67,6 +67,19 @@ describe("WalletProvider", () => {
|
|
|
67
67
|
nativeTransfer(_to, _value) {
|
|
68
68
|
return Promise.resolve("0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef");
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Converts the wallet provider to a signer.
|
|
72
|
+
*
|
|
73
|
+
* @returns The signer object.
|
|
74
|
+
*/
|
|
75
|
+
toSigner() {
|
|
76
|
+
return {
|
|
77
|
+
address: this.getAddress(),
|
|
78
|
+
signMessage: async (_message) => "0xsigned",
|
|
79
|
+
signTransaction: async (_transaction) => "0xsigned",
|
|
80
|
+
signTypedData: async (_typedData) => "0xsigned",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
70
83
|
}
|
|
71
84
|
beforeEach(() => {
|
|
72
85
|
jest.clearAllMocks();
|
|
@@ -100,4 +113,13 @@ describe("WalletProvider", () => {
|
|
|
100
113
|
resolve(null);
|
|
101
114
|
}, 0));
|
|
102
115
|
});
|
|
116
|
+
it("should convert wallet provider to signer", () => {
|
|
117
|
+
const provider = new MockWalletProvider();
|
|
118
|
+
const signer = provider.toSigner();
|
|
119
|
+
expect(signer).toBeDefined();
|
|
120
|
+
expect(signer.address).toBe(MOCK_ADDRESS);
|
|
121
|
+
expect(signer.signMessage).toBeDefined();
|
|
122
|
+
expect(signer.signTransaction).toBeDefined();
|
|
123
|
+
expect(signer.signTypedData).toBeDefined();
|
|
124
|
+
});
|
|
103
125
|
});
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { KernelSmartAccountImplementation } from "@zerodev/sdk";
|
|
2
|
+
import { createIntentClient, type GetCABParameters, type GetCABResult } from "@zerodev/intent";
|
|
3
|
+
import { Abi, Address, ContractFunctionArgs, ContractFunctionName, ReadContractParameters, ReadContractReturnType, TransactionRequest, Hex, Hash, Account } from "viem";
|
|
4
|
+
import { SmartAccount } from "viem/account-abstraction";
|
|
5
|
+
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
6
|
+
import { type Network } from "../network";
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for the ZeroDev Wallet Provider.
|
|
9
|
+
*/
|
|
10
|
+
export interface ZeroDevWalletProviderConfig {
|
|
11
|
+
/**
|
|
12
|
+
* The underlying EVM wallet provider to use as a signer.
|
|
13
|
+
*/
|
|
14
|
+
signer: Account;
|
|
15
|
+
/**
|
|
16
|
+
* The ZeroDev project ID.
|
|
17
|
+
*/
|
|
18
|
+
projectId: string;
|
|
19
|
+
/**
|
|
20
|
+
* The EntryPoint version ("0.6" or "0.7").
|
|
21
|
+
* Defaults to "0.7".
|
|
22
|
+
*/
|
|
23
|
+
entryPointVersion?: "0.6" | "0.7";
|
|
24
|
+
/**
|
|
25
|
+
* The network ID of the wallet.
|
|
26
|
+
*/
|
|
27
|
+
networkId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The address of the wallet.
|
|
30
|
+
* If not provided, it will be computed from the signer.
|
|
31
|
+
*/
|
|
32
|
+
address?: Address;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A wallet provider that uses ZeroDev's account abstraction.
|
|
36
|
+
*/
|
|
37
|
+
export declare class ZeroDevWalletProvider extends EvmWalletProvider {
|
|
38
|
+
#private;
|
|
39
|
+
/**
|
|
40
|
+
* Constructs a new ZeroDevWalletProvider.
|
|
41
|
+
*
|
|
42
|
+
* @param config - The configuration options for the ZeroDevWalletProvider.
|
|
43
|
+
* @param kernelAccount - The kernel account.
|
|
44
|
+
* @param intentClient - The intent client.
|
|
45
|
+
*/
|
|
46
|
+
private constructor();
|
|
47
|
+
/**
|
|
48
|
+
* Configures a new ZeroDevWalletProvider with an existing wallet provider as the signer.
|
|
49
|
+
*
|
|
50
|
+
* @param config - The configuration options for the ZeroDevWalletProvider.
|
|
51
|
+
* @returns A Promise that resolves to a new ZeroDevWalletProvider instance.
|
|
52
|
+
*/
|
|
53
|
+
static configureWithWallet(config: ZeroDevWalletProviderConfig): Promise<ZeroDevWalletProvider>;
|
|
54
|
+
/**
|
|
55
|
+
* Signs a message using the Kernel account.
|
|
56
|
+
*
|
|
57
|
+
* @param message - The message to sign.
|
|
58
|
+
* @returns The signed message.
|
|
59
|
+
*/
|
|
60
|
+
signMessage(message: string | Uint8Array): Promise<Hex>;
|
|
61
|
+
/**
|
|
62
|
+
* Signs a typed data object using the Kernel account.
|
|
63
|
+
*
|
|
64
|
+
* @param typedData - The typed data object to sign.
|
|
65
|
+
* @returns The signed typed data object.
|
|
66
|
+
*/
|
|
67
|
+
signTypedData(typedData: any): Promise<Hex>;
|
|
68
|
+
/**
|
|
69
|
+
* Signs a transaction using the Kernel account.
|
|
70
|
+
*
|
|
71
|
+
* @param _transaction - The transaction to sign.
|
|
72
|
+
* @returns The signed transaction.
|
|
73
|
+
*/
|
|
74
|
+
signTransaction(_transaction: TransactionRequest): Promise<Hex>;
|
|
75
|
+
/**
|
|
76
|
+
* Sends a transaction using ZeroDev's Intent system.
|
|
77
|
+
*
|
|
78
|
+
* @param transaction - The transaction to send.
|
|
79
|
+
* @returns The hash of the transaction.
|
|
80
|
+
*/
|
|
81
|
+
sendTransaction(transaction: TransactionRequest): Promise<Hex>;
|
|
82
|
+
/**
|
|
83
|
+
* Waits for a transaction receipt.
|
|
84
|
+
*
|
|
85
|
+
* @param txHash - The hash of the transaction to wait for.
|
|
86
|
+
* @returns The transaction receipt.
|
|
87
|
+
*/
|
|
88
|
+
waitForTransactionReceipt(txHash: Hash): Promise<unknown>;
|
|
89
|
+
/**
|
|
90
|
+
* Reads a contract.
|
|
91
|
+
*
|
|
92
|
+
* @param params - The parameters to read the contract.
|
|
93
|
+
* @returns The response from the contract.
|
|
94
|
+
*/
|
|
95
|
+
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>>;
|
|
96
|
+
/**
|
|
97
|
+
* Gets the address of the wallet.
|
|
98
|
+
*
|
|
99
|
+
* @returns The address of the wallet.
|
|
100
|
+
*/
|
|
101
|
+
getAddress(): Address;
|
|
102
|
+
/**
|
|
103
|
+
* Gets the network of the wallet.
|
|
104
|
+
*
|
|
105
|
+
* @returns The network of the wallet.
|
|
106
|
+
*/
|
|
107
|
+
getNetwork(): Network;
|
|
108
|
+
/**
|
|
109
|
+
* Gets the name of the wallet provider.
|
|
110
|
+
*
|
|
111
|
+
* @returns The name of the wallet provider.
|
|
112
|
+
*/
|
|
113
|
+
getName(): string;
|
|
114
|
+
/**
|
|
115
|
+
* Gets the balance of the wallet.
|
|
116
|
+
*
|
|
117
|
+
* @returns The balance of the wallet in wei.
|
|
118
|
+
*/
|
|
119
|
+
getBalance(): Promise<bigint>;
|
|
120
|
+
/**
|
|
121
|
+
* Transfer the native asset of the network.
|
|
122
|
+
*
|
|
123
|
+
* @param to - The destination address.
|
|
124
|
+
* @param value - The amount to transfer in whole units (e.g. ETH).
|
|
125
|
+
* @returns The transaction hash.
|
|
126
|
+
*/
|
|
127
|
+
nativeTransfer(to: string, value: string): Promise<string>;
|
|
128
|
+
/**
|
|
129
|
+
* Gets the ZeroDev Kernel account.
|
|
130
|
+
*
|
|
131
|
+
* @returns The ZeroDev Kernel account.
|
|
132
|
+
*/
|
|
133
|
+
getKernelAccount(): SmartAccount<KernelSmartAccountImplementation>;
|
|
134
|
+
/**
|
|
135
|
+
* Gets the ZeroDev Intent client.
|
|
136
|
+
*
|
|
137
|
+
* @returns The ZeroDev Intent client.
|
|
138
|
+
*/
|
|
139
|
+
getIntentClient(): Awaited<ReturnType<typeof createIntentClient>>;
|
|
140
|
+
/**
|
|
141
|
+
* Gets chain abstracted balance.
|
|
142
|
+
*
|
|
143
|
+
* @param options - The options for the get CAB.
|
|
144
|
+
* @returns The chain abstracted balance.
|
|
145
|
+
*/
|
|
146
|
+
getCAB(options: GetCABParameters): Promise<GetCABResult>;
|
|
147
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _ZeroDevWalletProvider_signer, _ZeroDevWalletProvider_projectId, _ZeroDevWalletProvider_network, _ZeroDevWalletProvider_address, _ZeroDevWalletProvider_publicClient, _ZeroDevWalletProvider_kernelAccount, _ZeroDevWalletProvider_intentClient;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ZeroDevWalletProvider = void 0;
|
|
16
|
+
const sdk_1 = require("@zerodev/sdk");
|
|
17
|
+
const constants_1 = require("@zerodev/sdk/constants");
|
|
18
|
+
const ecdsa_validator_1 = require("@zerodev/ecdsa-validator");
|
|
19
|
+
const intent_1 = require("@zerodev/intent");
|
|
20
|
+
const viem_1 = require("viem");
|
|
21
|
+
const evmWalletProvider_1 = require("./evmWalletProvider");
|
|
22
|
+
const network_1 = require("../network");
|
|
23
|
+
/**
|
|
24
|
+
* A wallet provider that uses ZeroDev's account abstraction.
|
|
25
|
+
*/
|
|
26
|
+
class ZeroDevWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
27
|
+
/**
|
|
28
|
+
* Constructs a new ZeroDevWalletProvider.
|
|
29
|
+
*
|
|
30
|
+
* @param config - The configuration options for the ZeroDevWalletProvider.
|
|
31
|
+
* @param kernelAccount - The kernel account.
|
|
32
|
+
* @param intentClient - The intent client.
|
|
33
|
+
*/
|
|
34
|
+
constructor(config, kernelAccount, intentClient) {
|
|
35
|
+
super();
|
|
36
|
+
_ZeroDevWalletProvider_signer.set(this, void 0);
|
|
37
|
+
_ZeroDevWalletProvider_projectId.set(this, void 0);
|
|
38
|
+
_ZeroDevWalletProvider_network.set(this, void 0);
|
|
39
|
+
_ZeroDevWalletProvider_address.set(this, void 0);
|
|
40
|
+
_ZeroDevWalletProvider_publicClient.set(this, void 0);
|
|
41
|
+
_ZeroDevWalletProvider_kernelAccount.set(this, void 0);
|
|
42
|
+
_ZeroDevWalletProvider_intentClient.set(this, void 0);
|
|
43
|
+
__classPrivateFieldSet(this, _ZeroDevWalletProvider_signer, config.signer, "f");
|
|
44
|
+
__classPrivateFieldSet(this, _ZeroDevWalletProvider_projectId, config.projectId, "f");
|
|
45
|
+
__classPrivateFieldSet(this, _ZeroDevWalletProvider_network, {
|
|
46
|
+
protocolFamily: "evm",
|
|
47
|
+
networkId: config.networkId,
|
|
48
|
+
chainId: network_1.NETWORK_ID_TO_VIEM_CHAIN[config.networkId].id.toString(),
|
|
49
|
+
}, "f");
|
|
50
|
+
__classPrivateFieldSet(this, _ZeroDevWalletProvider_address, kernelAccount.address, "f");
|
|
51
|
+
__classPrivateFieldSet(this, _ZeroDevWalletProvider_kernelAccount, kernelAccount, "f");
|
|
52
|
+
__classPrivateFieldSet(this, _ZeroDevWalletProvider_intentClient, intentClient, "f");
|
|
53
|
+
// Create public client
|
|
54
|
+
__classPrivateFieldSet(this, _ZeroDevWalletProvider_publicClient, (0, viem_1.createPublicClient)({
|
|
55
|
+
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[__classPrivateFieldGet(this, _ZeroDevWalletProvider_network, "f").networkId],
|
|
56
|
+
transport: (0, viem_1.http)(),
|
|
57
|
+
}), "f");
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Configures a new ZeroDevWalletProvider with an existing wallet provider as the signer.
|
|
61
|
+
*
|
|
62
|
+
* @param config - The configuration options for the ZeroDevWalletProvider.
|
|
63
|
+
* @returns A Promise that resolves to a new ZeroDevWalletProvider instance.
|
|
64
|
+
*/
|
|
65
|
+
static async configureWithWallet(config) {
|
|
66
|
+
if (!config.signer) {
|
|
67
|
+
throw new Error("Signer is required");
|
|
68
|
+
}
|
|
69
|
+
if (!config.projectId) {
|
|
70
|
+
throw new Error("ZeroDev project ID is required");
|
|
71
|
+
}
|
|
72
|
+
const networkId = config.networkId || "base-sepolia";
|
|
73
|
+
const chain = network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId];
|
|
74
|
+
const bundlerRpc = `https://rpc.zerodev.app/api/v3/bundler/${config.projectId}`;
|
|
75
|
+
// Create public client
|
|
76
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
77
|
+
chain,
|
|
78
|
+
transport: (0, viem_1.http)(),
|
|
79
|
+
});
|
|
80
|
+
// Create ECDSA validator
|
|
81
|
+
const entryPoint = (0, constants_1.getEntryPoint)(config.entryPointVersion || "0.7");
|
|
82
|
+
const ecdsaValidator = await (0, ecdsa_validator_1.signerToEcdsaValidator)(publicClient, {
|
|
83
|
+
signer: config.signer,
|
|
84
|
+
entryPoint,
|
|
85
|
+
kernelVersion: constants_1.KERNEL_V3_2,
|
|
86
|
+
});
|
|
87
|
+
// Create kernel account with intent executor
|
|
88
|
+
const kernelAccount = await (0, sdk_1.createKernelAccount)(publicClient, {
|
|
89
|
+
plugins: {
|
|
90
|
+
sudo: ecdsaValidator,
|
|
91
|
+
},
|
|
92
|
+
entryPoint,
|
|
93
|
+
kernelVersion: constants_1.KERNEL_V3_2,
|
|
94
|
+
address: config.address,
|
|
95
|
+
initConfig: [(0, intent_1.installIntentExecutor)(intent_1.INTENT_V0_3)],
|
|
96
|
+
});
|
|
97
|
+
// Create intent client
|
|
98
|
+
const intentClient = await (0, intent_1.createIntentClient)({
|
|
99
|
+
account: kernelAccount,
|
|
100
|
+
chain,
|
|
101
|
+
bundlerTransport: (0, viem_1.http)(bundlerRpc),
|
|
102
|
+
version: intent_1.INTENT_V0_3,
|
|
103
|
+
});
|
|
104
|
+
return new ZeroDevWalletProvider(config, kernelAccount, intentClient);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Signs a message using the Kernel account.
|
|
108
|
+
*
|
|
109
|
+
* @param message - The message to sign.
|
|
110
|
+
* @returns The signed message.
|
|
111
|
+
*/
|
|
112
|
+
async signMessage(message) {
|
|
113
|
+
// Convert Uint8Array to string if needed
|
|
114
|
+
const messageStr = typeof message === "string" ? message : new TextDecoder().decode(message);
|
|
115
|
+
return __classPrivateFieldGet(this, _ZeroDevWalletProvider_kernelAccount, "f").signMessage({
|
|
116
|
+
message: messageStr,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Signs a typed data object using the Kernel account.
|
|
121
|
+
*
|
|
122
|
+
* @param typedData - The typed data object to sign.
|
|
123
|
+
* @returns The signed typed data object.
|
|
124
|
+
*/
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
|
+
async signTypedData(typedData) {
|
|
127
|
+
return __classPrivateFieldGet(this, _ZeroDevWalletProvider_kernelAccount, "f").signTypedData(typedData);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Signs a transaction using the Kernel account.
|
|
131
|
+
*
|
|
132
|
+
* @param _transaction - The transaction to sign.
|
|
133
|
+
* @returns The signed transaction.
|
|
134
|
+
*/
|
|
135
|
+
async signTransaction(_transaction) {
|
|
136
|
+
throw new Error("signTransaction is not supported for ZeroDev Wallet Provider");
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Sends a transaction using ZeroDev's Intent system.
|
|
140
|
+
*
|
|
141
|
+
* @param transaction - The transaction to send.
|
|
142
|
+
* @returns The hash of the transaction.
|
|
143
|
+
*/
|
|
144
|
+
async sendTransaction(transaction) {
|
|
145
|
+
// Get the chain ID from the network
|
|
146
|
+
const chainId = parseInt(__classPrivateFieldGet(this, _ZeroDevWalletProvider_network, "f").chainId);
|
|
147
|
+
// Determine if this is a native token transfer
|
|
148
|
+
const isNativeTransfer = transaction.value &&
|
|
149
|
+
BigInt(transaction.value) > 0 &&
|
|
150
|
+
(!transaction.data || transaction.data === "0x");
|
|
151
|
+
// For native token transfers, use ETH as the output token
|
|
152
|
+
if (isNativeTransfer) {
|
|
153
|
+
const intent = await __classPrivateFieldGet(this, _ZeroDevWalletProvider_intentClient, "f").sendUserIntent({
|
|
154
|
+
calls: [
|
|
155
|
+
{
|
|
156
|
+
to: transaction.to,
|
|
157
|
+
value: BigInt(transaction.value || 0),
|
|
158
|
+
data: transaction.data || "0x",
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
outputTokens: [
|
|
162
|
+
{
|
|
163
|
+
address: viem_1.zeroAddress,
|
|
164
|
+
chainId,
|
|
165
|
+
amount: BigInt(transaction.value || 0),
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
});
|
|
169
|
+
const receipt = await __classPrivateFieldGet(this, _ZeroDevWalletProvider_intentClient, "f").waitForUserIntentExecutionReceipt({
|
|
170
|
+
uiHash: intent.outputUiHash.uiHash,
|
|
171
|
+
});
|
|
172
|
+
return receipt?.receipt.transactionHash || "0x";
|
|
173
|
+
}
|
|
174
|
+
const intent = await __classPrivateFieldGet(this, _ZeroDevWalletProvider_intentClient, "f").sendUserIntent({
|
|
175
|
+
calls: [
|
|
176
|
+
{
|
|
177
|
+
to: transaction.to,
|
|
178
|
+
value: BigInt(transaction.value || 0),
|
|
179
|
+
data: transaction.data || "0x",
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
chainId: chainId,
|
|
183
|
+
});
|
|
184
|
+
const receipt = await __classPrivateFieldGet(this, _ZeroDevWalletProvider_intentClient, "f").waitForUserIntentExecutionReceipt({
|
|
185
|
+
uiHash: intent.outputUiHash.uiHash,
|
|
186
|
+
});
|
|
187
|
+
return receipt?.receipt.transactionHash || "0x";
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Waits for a transaction receipt.
|
|
191
|
+
*
|
|
192
|
+
* @param txHash - The hash of the transaction to wait for.
|
|
193
|
+
* @returns The transaction receipt.
|
|
194
|
+
*/
|
|
195
|
+
async waitForTransactionReceipt(txHash) {
|
|
196
|
+
return __classPrivateFieldGet(this, _ZeroDevWalletProvider_publicClient, "f").waitForTransactionReceipt({ hash: txHash });
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Reads a contract.
|
|
200
|
+
*
|
|
201
|
+
* @param params - The parameters to read the contract.
|
|
202
|
+
* @returns The response from the contract.
|
|
203
|
+
*/
|
|
204
|
+
async readContract(params) {
|
|
205
|
+
return __classPrivateFieldGet(this, _ZeroDevWalletProvider_publicClient, "f").readContract(params);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Gets the address of the wallet.
|
|
209
|
+
*
|
|
210
|
+
* @returns The address of the wallet.
|
|
211
|
+
*/
|
|
212
|
+
getAddress() {
|
|
213
|
+
return __classPrivateFieldGet(this, _ZeroDevWalletProvider_address, "f");
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Gets the network of the wallet.
|
|
217
|
+
*
|
|
218
|
+
* @returns The network of the wallet.
|
|
219
|
+
*/
|
|
220
|
+
getNetwork() {
|
|
221
|
+
return __classPrivateFieldGet(this, _ZeroDevWalletProvider_network, "f");
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Gets the name of the wallet provider.
|
|
225
|
+
*
|
|
226
|
+
* @returns The name of the wallet provider.
|
|
227
|
+
*/
|
|
228
|
+
getName() {
|
|
229
|
+
return "zerodev_wallet_provider";
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Gets the balance of the wallet.
|
|
233
|
+
*
|
|
234
|
+
* @returns The balance of the wallet in wei.
|
|
235
|
+
*/
|
|
236
|
+
async getBalance() {
|
|
237
|
+
return __classPrivateFieldGet(this, _ZeroDevWalletProvider_publicClient, "f").getBalance({
|
|
238
|
+
address: __classPrivateFieldGet(this, _ZeroDevWalletProvider_address, "f"),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Transfer the native asset of the network.
|
|
243
|
+
*
|
|
244
|
+
* @param to - The destination address.
|
|
245
|
+
* @param value - The amount to transfer in whole units (e.g. ETH).
|
|
246
|
+
* @returns The transaction hash.
|
|
247
|
+
*/
|
|
248
|
+
async nativeTransfer(to, value) {
|
|
249
|
+
// Convert value to wei (assuming value is in whole units)
|
|
250
|
+
const valueInWei = BigInt(parseFloat(value) * 10 ** 18);
|
|
251
|
+
// Get the chain ID from the network
|
|
252
|
+
const chainId = parseInt(__classPrivateFieldGet(this, _ZeroDevWalletProvider_network, "f").chainId || "1");
|
|
253
|
+
const intent = await __classPrivateFieldGet(this, _ZeroDevWalletProvider_intentClient, "f").sendUserIntent({
|
|
254
|
+
calls: [
|
|
255
|
+
{
|
|
256
|
+
to: to,
|
|
257
|
+
value: valueInWei,
|
|
258
|
+
data: "0x",
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
outputTokens: [
|
|
262
|
+
{
|
|
263
|
+
address: viem_1.zeroAddress,
|
|
264
|
+
chainId,
|
|
265
|
+
amount: valueInWei,
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
});
|
|
269
|
+
const receipt = await __classPrivateFieldGet(this, _ZeroDevWalletProvider_intentClient, "f").waitForUserIntentExecutionReceipt({
|
|
270
|
+
uiHash: intent.outputUiHash.uiHash,
|
|
271
|
+
});
|
|
272
|
+
return receipt?.receipt.transactionHash || "";
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Gets the ZeroDev Kernel account.
|
|
276
|
+
*
|
|
277
|
+
* @returns The ZeroDev Kernel account.
|
|
278
|
+
*/
|
|
279
|
+
getKernelAccount() {
|
|
280
|
+
return __classPrivateFieldGet(this, _ZeroDevWalletProvider_kernelAccount, "f");
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Gets the ZeroDev Intent client.
|
|
284
|
+
*
|
|
285
|
+
* @returns The ZeroDev Intent client.
|
|
286
|
+
*/
|
|
287
|
+
getIntentClient() {
|
|
288
|
+
return __classPrivateFieldGet(this, _ZeroDevWalletProvider_intentClient, "f");
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Gets chain abstracted balance.
|
|
292
|
+
*
|
|
293
|
+
* @param options - The options for the get CAB.
|
|
294
|
+
* @returns The chain abstracted balance.
|
|
295
|
+
*/
|
|
296
|
+
async getCAB(options) {
|
|
297
|
+
return __classPrivateFieldGet(this, _ZeroDevWalletProvider_intentClient, "f").getCAB(options);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
exports.ZeroDevWalletProvider = ZeroDevWalletProvider;
|
|
301
|
+
_ZeroDevWalletProvider_signer = new WeakMap(), _ZeroDevWalletProvider_projectId = new WeakMap(), _ZeroDevWalletProvider_network = new WeakMap(), _ZeroDevWalletProvider_address = new WeakMap(), _ZeroDevWalletProvider_publicClient = new WeakMap(), _ZeroDevWalletProvider_kernelAccount = new WeakMap(), _ZeroDevWalletProvider_intentClient = new WeakMap();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|