@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
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const zeroDevWalletActionProvider_1 = require("./zeroDevWalletActionProvider");
|
|
4
|
+
const schemas_1 = require("./schemas");
|
|
5
|
+
describe("ZeroDev Wallet Action Provider Input Schemas", () => {
|
|
6
|
+
describe("Get CAB Schema", () => {
|
|
7
|
+
it("should successfully parse valid input with network type", () => {
|
|
8
|
+
const validInput = {
|
|
9
|
+
type: "networkType",
|
|
10
|
+
tokenTickers: ["ETH", "USDC"],
|
|
11
|
+
networkType: "mainnet",
|
|
12
|
+
};
|
|
13
|
+
const result = schemas_1.GetCABSchema.safeParse(validInput);
|
|
14
|
+
expect(result.success).toBe(true);
|
|
15
|
+
expect(result.data).toEqual(validInput);
|
|
16
|
+
});
|
|
17
|
+
it("should successfully parse valid input with network filter", () => {
|
|
18
|
+
const validInput = {
|
|
19
|
+
type: "networkFilter",
|
|
20
|
+
tokenTickers: ["ETH", "USDC"],
|
|
21
|
+
networks: [1, 8453], // ethereum and base network IDs
|
|
22
|
+
};
|
|
23
|
+
const result = schemas_1.GetCABSchema.safeParse(validInput);
|
|
24
|
+
expect(result.success).toBe(true);
|
|
25
|
+
expect(result.data).toEqual(validInput);
|
|
26
|
+
});
|
|
27
|
+
it("should successfully parse input with optional tokenTickers omitted", () => {
|
|
28
|
+
const validInput = {
|
|
29
|
+
type: "networkType",
|
|
30
|
+
networkType: "mainnet",
|
|
31
|
+
};
|
|
32
|
+
const result = schemas_1.GetCABSchema.safeParse(validInput);
|
|
33
|
+
expect(result.success).toBe(true);
|
|
34
|
+
expect(result.data).toEqual(validInput);
|
|
35
|
+
});
|
|
36
|
+
it("should fail parsing empty input", () => {
|
|
37
|
+
const emptyInput = {};
|
|
38
|
+
const result = schemas_1.GetCABSchema.safeParse(emptyInput);
|
|
39
|
+
expect(result.success).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe("ZeroDev Wallet Action Provider", () => {
|
|
44
|
+
let actionProvider;
|
|
45
|
+
let mockWallet;
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
// Reset all mocks before each test
|
|
48
|
+
jest.clearAllMocks();
|
|
49
|
+
actionProvider = new zeroDevWalletActionProvider_1.ZeroDevWalletActionProvider();
|
|
50
|
+
mockWallet = {
|
|
51
|
+
getCAB: jest.fn(),
|
|
52
|
+
getAddress: jest.fn().mockReturnValue("0xe6b2af36b3bb8d47206a129ff11d5a2de2a63c83"),
|
|
53
|
+
getNetwork: jest.fn().mockReturnValue({ networkId: "ethereum-mainnet" }),
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
describe("getCAB", () => {
|
|
57
|
+
const MOCK_BALANCES = {
|
|
58
|
+
balance: BigInt(1000000000000000000),
|
|
59
|
+
tokenAddress: "0x1234567890123456789012345678901234567890",
|
|
60
|
+
tokens: {
|
|
61
|
+
ETH: {
|
|
62
|
+
ethereum: "1.5",
|
|
63
|
+
base: "0.5",
|
|
64
|
+
},
|
|
65
|
+
USDC: {
|
|
66
|
+
ethereum: "1000",
|
|
67
|
+
base: "500",
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
beforeEach(() => {
|
|
72
|
+
mockWallet.getCAB.mockResolvedValue(MOCK_BALANCES);
|
|
73
|
+
});
|
|
74
|
+
it("should successfully get chain abstracted balances with network type", async () => {
|
|
75
|
+
const args = {
|
|
76
|
+
type: "networkType",
|
|
77
|
+
tokenTickers: ["ETH", "USDC"],
|
|
78
|
+
networkType: "mainnet",
|
|
79
|
+
};
|
|
80
|
+
const result = await actionProvider.getCAB(mockWallet, args);
|
|
81
|
+
expect(mockWallet.getCAB).toHaveBeenCalledWith(args);
|
|
82
|
+
expect(result).toEqual(MOCK_BALANCES);
|
|
83
|
+
});
|
|
84
|
+
it("should successfully get chain abstracted balances with network filter", async () => {
|
|
85
|
+
const args = {
|
|
86
|
+
type: "networkFilter",
|
|
87
|
+
tokenTickers: ["ETH", "USDC"],
|
|
88
|
+
networks: [1, 8453], // ethereum and base network IDs
|
|
89
|
+
};
|
|
90
|
+
const result = await actionProvider.getCAB(mockWallet, args);
|
|
91
|
+
expect(mockWallet.getCAB).toHaveBeenCalledWith(args);
|
|
92
|
+
expect(result).toEqual(MOCK_BALANCES);
|
|
93
|
+
});
|
|
94
|
+
it("should handle errors when getting balances", async () => {
|
|
95
|
+
const args = {
|
|
96
|
+
type: "networkType",
|
|
97
|
+
networkType: "mainnet",
|
|
98
|
+
};
|
|
99
|
+
const error = new Error("Failed to get balances");
|
|
100
|
+
mockWallet.getCAB.mockRejectedValue(error);
|
|
101
|
+
await expect(actionProvider.getCAB(mockWallet, args)).rejects.toThrow(error);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe("supportsNetwork", () => {
|
|
105
|
+
it("should return true when protocolFamily is evm", () => {
|
|
106
|
+
expect(actionProvider.supportsNetwork({ protocolFamily: "evm" })).toBe(true);
|
|
107
|
+
});
|
|
108
|
+
it("should return false when protocolFamily is not evm", () => {
|
|
109
|
+
expect(actionProvider.supportsNetwork({ protocolFamily: "solana" })).toBe(false);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
package/dist/network/svm.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export declare const SOLANA_MAINNET_NETWORK_ID = "solana-mainnet";
|
|
|
3
3
|
export declare const SOLANA_TESTNET_NETWORK_ID = "solana-testnet";
|
|
4
4
|
export declare const SOLANA_DEVNET_NETWORK_ID = "solana-devnet";
|
|
5
5
|
export type SOLANA_NETWORK_ID = typeof SOLANA_MAINNET_NETWORK_ID | typeof SOLANA_TESTNET_NETWORK_ID | typeof SOLANA_DEVNET_NETWORK_ID;
|
|
6
|
+
export declare const SOLANA_NETWORK_IDS: SOLANA_NETWORK_ID[];
|
|
6
7
|
export declare const SOLANA_PROTOCOL_FAMILY = "svm";
|
|
7
8
|
export declare const SOLANA_MAINNET_GENESIS_BLOCK_HASH = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
8
9
|
export declare const SOLANA_TESTNET_GENESIS_BLOCK_HASH = "4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY";
|
package/dist/network/svm.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SOLANA_CLUSTER_ID_BY_NETWORK_ID = exports.SOLANA_NETWORKS = exports.SOLANA_DEVNET_NETWORK = exports.SOLANA_TESTNET_NETWORK = exports.SOLANA_MAINNET_NETWORK = exports.SOLANA_DEVNET_GENESIS_BLOCK_HASH = exports.SOLANA_TESTNET_GENESIS_BLOCK_HASH = exports.SOLANA_MAINNET_GENESIS_BLOCK_HASH = exports.SOLANA_PROTOCOL_FAMILY = exports.SOLANA_DEVNET_NETWORK_ID = exports.SOLANA_TESTNET_NETWORK_ID = exports.SOLANA_MAINNET_NETWORK_ID = void 0;
|
|
3
|
+
exports.SOLANA_CLUSTER_ID_BY_NETWORK_ID = exports.SOLANA_NETWORKS = exports.SOLANA_DEVNET_NETWORK = exports.SOLANA_TESTNET_NETWORK = exports.SOLANA_MAINNET_NETWORK = exports.SOLANA_DEVNET_GENESIS_BLOCK_HASH = exports.SOLANA_TESTNET_GENESIS_BLOCK_HASH = exports.SOLANA_MAINNET_GENESIS_BLOCK_HASH = exports.SOLANA_PROTOCOL_FAMILY = exports.SOLANA_NETWORK_IDS = exports.SOLANA_DEVNET_NETWORK_ID = exports.SOLANA_TESTNET_NETWORK_ID = exports.SOLANA_MAINNET_NETWORK_ID = void 0;
|
|
4
4
|
// CDP Network IDs
|
|
5
5
|
exports.SOLANA_MAINNET_NETWORK_ID = "solana-mainnet";
|
|
6
6
|
exports.SOLANA_TESTNET_NETWORK_ID = "solana-testnet";
|
|
7
7
|
exports.SOLANA_DEVNET_NETWORK_ID = "solana-devnet";
|
|
8
|
+
exports.SOLANA_NETWORK_IDS = [
|
|
9
|
+
exports.SOLANA_MAINNET_NETWORK_ID,
|
|
10
|
+
exports.SOLANA_TESTNET_NETWORK_ID,
|
|
11
|
+
exports.SOLANA_DEVNET_NETWORK_ID,
|
|
12
|
+
];
|
|
8
13
|
// AgentKit Protocol Family
|
|
9
14
|
exports.SOLANA_PROTOCOL_FAMILY = "svm";
|
|
10
15
|
// Chain IDs - Genesis Block Hashes
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { CdpClient } from "@coinbase/cdp-sdk";
|
|
2
|
+
import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
|
|
3
|
+
import { Network } from "../network";
|
|
4
|
+
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
5
|
+
import { WalletProviderWithClient, CdpV2WalletProviderConfig } from "./cdpV2Shared";
|
|
6
|
+
/**
|
|
7
|
+
* A wallet provider that uses the Coinbase SDK.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CdpV2EvmWalletProvider extends EvmWalletProvider implements WalletProviderWithClient {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* Constructs a new CdpWalletProvider.
|
|
13
|
+
*
|
|
14
|
+
* @param config - The configuration options for the CdpWalletProvider.
|
|
15
|
+
*/
|
|
16
|
+
private constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Configures a new CdpWalletProvider with a wallet.
|
|
19
|
+
*
|
|
20
|
+
* @param config - Optional configuration parameters
|
|
21
|
+
* @returns A Promise that resolves to a new CdpWalletProvider instance
|
|
22
|
+
* @throws Error if required environment variables are missing or wallet initialization fails
|
|
23
|
+
*/
|
|
24
|
+
static configureWithWallet(config?: CdpV2WalletProviderConfig): Promise<CdpV2EvmWalletProvider>;
|
|
25
|
+
/**
|
|
26
|
+
* Signs a message.
|
|
27
|
+
*
|
|
28
|
+
* @param message - The message to sign.
|
|
29
|
+
* @returns The signed message.
|
|
30
|
+
*/
|
|
31
|
+
signMessage(message: string): Promise<Hex>;
|
|
32
|
+
/**
|
|
33
|
+
* Signs a typed data object.
|
|
34
|
+
*
|
|
35
|
+
* @param typedData - The typed data object to sign.
|
|
36
|
+
* @returns The signed typed data object.
|
|
37
|
+
*/
|
|
38
|
+
signTypedData(typedData: any): Promise<Hex>;
|
|
39
|
+
/**
|
|
40
|
+
* Signs a transaction.
|
|
41
|
+
*
|
|
42
|
+
* @param transaction - The transaction to sign.
|
|
43
|
+
* @returns The signed transaction.
|
|
44
|
+
*/
|
|
45
|
+
signTransaction(transaction: TransactionRequest): Promise<Hex>;
|
|
46
|
+
/**
|
|
47
|
+
* Sends a transaction.
|
|
48
|
+
*
|
|
49
|
+
* @param transaction - The transaction to send.
|
|
50
|
+
* @returns The hash of the transaction.
|
|
51
|
+
*/
|
|
52
|
+
sendTransaction(transaction: TransactionRequest): Promise<Hex>;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the address of the wallet.
|
|
55
|
+
*
|
|
56
|
+
* @returns The address of the wallet.
|
|
57
|
+
*/
|
|
58
|
+
getAddress(): string;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the network of the wallet.
|
|
61
|
+
*
|
|
62
|
+
* @returns The network of the wallet.
|
|
63
|
+
*/
|
|
64
|
+
getNetwork(): Network;
|
|
65
|
+
/**
|
|
66
|
+
* Gets the name of the wallet provider.
|
|
67
|
+
*
|
|
68
|
+
* @returns The name of the wallet provider.
|
|
69
|
+
*/
|
|
70
|
+
getName(): string;
|
|
71
|
+
/**
|
|
72
|
+
* Gets the CDP client.
|
|
73
|
+
*
|
|
74
|
+
* @returns The CDP client.
|
|
75
|
+
*/
|
|
76
|
+
getClient(): CdpClient;
|
|
77
|
+
/**
|
|
78
|
+
* Gets the balance of the wallet.
|
|
79
|
+
*
|
|
80
|
+
* @returns The balance of the wallet in wei
|
|
81
|
+
*/
|
|
82
|
+
getBalance(): Promise<bigint>;
|
|
83
|
+
/**
|
|
84
|
+
* Waits for a transaction receipt.
|
|
85
|
+
*
|
|
86
|
+
* @param txHash - The hash of the transaction to wait for.
|
|
87
|
+
* @returns The transaction receipt.
|
|
88
|
+
*/
|
|
89
|
+
waitForTransactionReceipt(txHash: Hex): Promise<any>;
|
|
90
|
+
/**
|
|
91
|
+
* Reads a contract.
|
|
92
|
+
*
|
|
93
|
+
* @param params - The parameters to read the contract.
|
|
94
|
+
* @returns The response from the contract.
|
|
95
|
+
*/
|
|
96
|
+
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>>;
|
|
97
|
+
/**
|
|
98
|
+
* Transfer the native asset of the network.
|
|
99
|
+
*
|
|
100
|
+
* @param to - The destination address.
|
|
101
|
+
* @param value - The amount to transfer in Wei.
|
|
102
|
+
* @returns The transaction hash.
|
|
103
|
+
*/
|
|
104
|
+
nativeTransfer(to: Address, value: string): Promise<Hex>;
|
|
105
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
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 _CdpV2EvmWalletProvider_instances, _CdpV2EvmWalletProvider_publicClient, _CdpV2EvmWalletProvider_serverAccount, _CdpV2EvmWalletProvider_cdp, _CdpV2EvmWalletProvider_network, _CdpV2EvmWalletProvider_getCdpSdkNetwork;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CdpV2EvmWalletProvider = void 0;
|
|
16
|
+
const cdp_sdk_1 = require("@coinbase/cdp-sdk");
|
|
17
|
+
const viem_1 = require("viem");
|
|
18
|
+
const network_1 = require("../network");
|
|
19
|
+
const evmWalletProvider_1 = require("./evmWalletProvider");
|
|
20
|
+
/**
|
|
21
|
+
* A wallet provider that uses the Coinbase SDK.
|
|
22
|
+
*/
|
|
23
|
+
class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
24
|
+
/**
|
|
25
|
+
* Constructs a new CdpWalletProvider.
|
|
26
|
+
*
|
|
27
|
+
* @param config - The configuration options for the CdpWalletProvider.
|
|
28
|
+
*/
|
|
29
|
+
constructor(config) {
|
|
30
|
+
super();
|
|
31
|
+
_CdpV2EvmWalletProvider_instances.add(this);
|
|
32
|
+
_CdpV2EvmWalletProvider_publicClient.set(this, void 0);
|
|
33
|
+
_CdpV2EvmWalletProvider_serverAccount.set(this, void 0);
|
|
34
|
+
_CdpV2EvmWalletProvider_cdp.set(this, void 0);
|
|
35
|
+
_CdpV2EvmWalletProvider_network.set(this, void 0);
|
|
36
|
+
__classPrivateFieldSet(this, _CdpV2EvmWalletProvider_serverAccount, config.serverAccount, "f");
|
|
37
|
+
__classPrivateFieldSet(this, _CdpV2EvmWalletProvider_cdp, config.cdp, "f");
|
|
38
|
+
__classPrivateFieldSet(this, _CdpV2EvmWalletProvider_publicClient, config.publicClient, "f");
|
|
39
|
+
__classPrivateFieldSet(this, _CdpV2EvmWalletProvider_network, config.network, "f");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Configures a new CdpWalletProvider with a wallet.
|
|
43
|
+
*
|
|
44
|
+
* @param config - Optional configuration parameters
|
|
45
|
+
* @returns A Promise that resolves to a new CdpWalletProvider instance
|
|
46
|
+
* @throws Error if required environment variables are missing or wallet initialization fails
|
|
47
|
+
*/
|
|
48
|
+
static async configureWithWallet(config = {}) {
|
|
49
|
+
const apiKeyId = config.apiKeyId || process.env.CDP_API_KEY_ID;
|
|
50
|
+
const apiKeySecret = config.apiKeySecret || process.env.CDP_API_KEY_SECRET;
|
|
51
|
+
const walletSecret = config.walletSecret || process.env.CDP_WALLET_SECRET;
|
|
52
|
+
const idempotencyKey = config.idempotencyKey || process.env.IDEMPOTENCY_KEY;
|
|
53
|
+
if (!apiKeyId || !apiKeySecret || !walletSecret) {
|
|
54
|
+
throw new Error("Missing required environment variables. CDP_API_KEY_ID, CDP_API_KEY_SECRET, CDP_WALLET_SECRET are required.");
|
|
55
|
+
}
|
|
56
|
+
const networkId = config.networkId || process.env.NETWORK_ID || "base-sepolia";
|
|
57
|
+
const network = {
|
|
58
|
+
protocolFamily: "evm",
|
|
59
|
+
chainId: network_1.NETWORK_ID_TO_CHAIN_ID[networkId],
|
|
60
|
+
networkId: networkId,
|
|
61
|
+
};
|
|
62
|
+
const cdpClient = new cdp_sdk_1.CdpClient({
|
|
63
|
+
apiKeyId,
|
|
64
|
+
apiKeySecret,
|
|
65
|
+
walletSecret,
|
|
66
|
+
});
|
|
67
|
+
const serverAccount = await (config.address
|
|
68
|
+
? cdpClient.evm.getAccount({ address: config.address })
|
|
69
|
+
: cdpClient.evm.createAccount({ idempotencyKey }));
|
|
70
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
71
|
+
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId],
|
|
72
|
+
transport: (0, viem_1.http)(),
|
|
73
|
+
});
|
|
74
|
+
return new CdpV2EvmWalletProvider({
|
|
75
|
+
publicClient,
|
|
76
|
+
cdp: cdpClient,
|
|
77
|
+
serverAccount,
|
|
78
|
+
network,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Signs a message.
|
|
83
|
+
*
|
|
84
|
+
* @param message - The message to sign.
|
|
85
|
+
* @returns The signed message.
|
|
86
|
+
*/
|
|
87
|
+
async signMessage(message) {
|
|
88
|
+
return __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_serverAccount, "f").signMessage({ message });
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Signs a typed data object.
|
|
92
|
+
*
|
|
93
|
+
* @param typedData - The typed data object to sign.
|
|
94
|
+
* @returns The signed typed data object.
|
|
95
|
+
*/
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
|
+
async signTypedData(typedData) {
|
|
98
|
+
return __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_serverAccount, "f").signTypedData(typedData);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Signs a transaction.
|
|
102
|
+
*
|
|
103
|
+
* @param transaction - The transaction to sign.
|
|
104
|
+
* @returns The signed transaction.
|
|
105
|
+
*/
|
|
106
|
+
async signTransaction(transaction) {
|
|
107
|
+
const serializedTx = (0, viem_1.serializeTransaction)(transaction);
|
|
108
|
+
const signedTx = await __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_cdp, "f").evm.signTransaction({
|
|
109
|
+
address: __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_serverAccount, "f").address,
|
|
110
|
+
transaction: serializedTx,
|
|
111
|
+
});
|
|
112
|
+
return signedTx.signature;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Sends a transaction.
|
|
116
|
+
*
|
|
117
|
+
* @param transaction - The transaction to send.
|
|
118
|
+
* @returns The hash of the transaction.
|
|
119
|
+
*/
|
|
120
|
+
async sendTransaction(transaction) {
|
|
121
|
+
const result = await __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_cdp, "f").evm.sendTransaction({
|
|
122
|
+
address: __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_serverAccount, "f").address,
|
|
123
|
+
transaction: (0, viem_1.serializeTransaction)(transaction),
|
|
124
|
+
network: __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_instances, "m", _CdpV2EvmWalletProvider_getCdpSdkNetwork).call(this),
|
|
125
|
+
});
|
|
126
|
+
return result.transactionHash;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Gets the address of the wallet.
|
|
130
|
+
*
|
|
131
|
+
* @returns The address of the wallet.
|
|
132
|
+
*/
|
|
133
|
+
getAddress() {
|
|
134
|
+
return __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_serverAccount, "f").address;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Gets the network of the wallet.
|
|
138
|
+
*
|
|
139
|
+
* @returns The network of the wallet.
|
|
140
|
+
*/
|
|
141
|
+
getNetwork() {
|
|
142
|
+
return __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_network, "f");
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Gets the name of the wallet provider.
|
|
146
|
+
*
|
|
147
|
+
* @returns The name of the wallet provider.
|
|
148
|
+
*/
|
|
149
|
+
getName() {
|
|
150
|
+
return "cdp_v2_wallet_provider";
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Gets the CDP client.
|
|
154
|
+
*
|
|
155
|
+
* @returns The CDP client.
|
|
156
|
+
*/
|
|
157
|
+
getClient() {
|
|
158
|
+
return __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_cdp, "f");
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Gets the balance of the wallet.
|
|
162
|
+
*
|
|
163
|
+
* @returns The balance of the wallet in wei
|
|
164
|
+
*/
|
|
165
|
+
async getBalance() {
|
|
166
|
+
return await __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_publicClient, "f").getBalance({ address: __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_serverAccount, "f").address });
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Waits for a transaction receipt.
|
|
170
|
+
*
|
|
171
|
+
* @param txHash - The hash of the transaction to wait for.
|
|
172
|
+
* @returns The transaction receipt.
|
|
173
|
+
*/
|
|
174
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
175
|
+
async waitForTransactionReceipt(txHash) {
|
|
176
|
+
return await __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_publicClient, "f").waitForTransactionReceipt({ hash: txHash });
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Reads a contract.
|
|
180
|
+
*
|
|
181
|
+
* @param params - The parameters to read the contract.
|
|
182
|
+
* @returns The response from the contract.
|
|
183
|
+
*/
|
|
184
|
+
async readContract(params) {
|
|
185
|
+
return __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_publicClient, "f").readContract(params);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Transfer the native asset of the network.
|
|
189
|
+
*
|
|
190
|
+
* @param to - The destination address.
|
|
191
|
+
* @param value - The amount to transfer in Wei.
|
|
192
|
+
* @returns The transaction hash.
|
|
193
|
+
*/
|
|
194
|
+
async nativeTransfer(to, value) {
|
|
195
|
+
return this.sendTransaction({
|
|
196
|
+
to: to,
|
|
197
|
+
value: BigInt(value),
|
|
198
|
+
data: "0x",
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.CdpV2EvmWalletProvider = CdpV2EvmWalletProvider;
|
|
203
|
+
_CdpV2EvmWalletProvider_publicClient = new WeakMap(), _CdpV2EvmWalletProvider_serverAccount = new WeakMap(), _CdpV2EvmWalletProvider_cdp = new WeakMap(), _CdpV2EvmWalletProvider_network = new WeakMap(), _CdpV2EvmWalletProvider_instances = new WeakSet(), _CdpV2EvmWalletProvider_getCdpSdkNetwork = function _CdpV2EvmWalletProvider_getCdpSdkNetwork() {
|
|
204
|
+
switch (__classPrivateFieldGet(this, _CdpV2EvmWalletProvider_network, "f").networkId) {
|
|
205
|
+
case "base-sepolia":
|
|
206
|
+
return "base-sepolia";
|
|
207
|
+
case "base-mainnet":
|
|
208
|
+
return "base";
|
|
209
|
+
default:
|
|
210
|
+
throw new Error(`Unsupported network: ${__classPrivateFieldGet(this, _CdpV2EvmWalletProvider_network, "f").networkId}`);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|