@coinbase/agentkit 0.1.2 → 0.2.1
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 +388 -5
- package/dist/action-providers/erc20/schemas.d.ts +2 -2
- package/dist/action-providers/index.d.ts +8 -7
- package/dist/action-providers/index.js +8 -7
- package/dist/action-providers/morpho/schemas.d.ts +4 -4
- 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 +160 -0
- package/dist/action-providers/spl/splActionProvider.test.d.ts +1 -0
- package/dist/action-providers/spl/splActionProvider.test.js +263 -0
- package/dist/action-providers/wallet/walletActionProvider.d.ts +1 -1
- package/dist/action-providers/wallet/walletActionProvider.js +31 -18
- package/dist/action-providers/wallet/walletActionProvider.test.js +101 -23
- package/dist/network/index.d.ts +2 -1
- package/dist/network/index.js +2 -1
- package/dist/network/network.d.ts +7 -0
- package/dist/network/network.js +46 -1
- package/dist/network/svm.d.ts +15 -0
- package/dist/network/svm.js +38 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +14 -0
- package/dist/wallet-providers/cdpWalletProvider.d.ts +13 -0
- package/dist/wallet-providers/cdpWalletProvider.js +14 -7
- package/dist/wallet-providers/index.d.ts +5 -0
- package/dist/wallet-providers/index.js +5 -0
- package/dist/wallet-providers/privyEvmWalletProvider.d.ts +55 -0
- package/dist/wallet-providers/privyEvmWalletProvider.js +140 -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/privyWalletProvider.d.ts +35 -0
- package/dist/wallet-providers/privyWalletProvider.js +39 -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 +24 -0
- package/dist/wallet-providers/svmWalletProvider.d.ts +56 -0
- package/dist/wallet-providers/svmWalletProvider.js +13 -0
- package/dist/wallet-providers/viemWalletProvider.d.ts +15 -1
- package/dist/wallet-providers/viemWalletProvider.js +22 -3
- package/dist/wallet-providers/walletProvider.d.ts +1 -1
- package/package.json +4 -1
|
@@ -4,41 +4,82 @@ const walletActionProvider_1 = require("./walletActionProvider");
|
|
|
4
4
|
const schemas_1 = require("./schemas");
|
|
5
5
|
describe("Wallet Action Provider", () => {
|
|
6
6
|
const MOCK_ADDRESS = "0xe6b2af36b3bb8d47206a129ff11d5a2de2a63c83";
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const MOCK_ETH_BALANCE = 1000000000000000000n;
|
|
8
|
+
const MOCK_SOL_BALANCE = 1000000000n;
|
|
9
|
+
const MOCK_EVM_NETWORK = {
|
|
9
10
|
protocolFamily: "evm",
|
|
10
11
|
networkId: "base-sepolia",
|
|
11
12
|
chainId: "123",
|
|
12
13
|
};
|
|
14
|
+
const MOCK_SOLANA_NETWORK = {
|
|
15
|
+
protocolFamily: "svm",
|
|
16
|
+
networkId: "mainnet",
|
|
17
|
+
};
|
|
18
|
+
const MOCK_UNKNOWN_NETWORK = {
|
|
19
|
+
protocolFamily: "unknown",
|
|
20
|
+
networkId: "testnet",
|
|
21
|
+
};
|
|
13
22
|
const MOCK_PROVIDER_NAME = "TestWallet";
|
|
14
23
|
const MOCK_TRANSACTION_HASH = "0xghijkl987654321";
|
|
24
|
+
const MOCK_SIGNATURE = "mock-signature";
|
|
15
25
|
let mockWallet;
|
|
16
26
|
const actionProvider = (0, walletActionProvider_1.walletActionProvider)();
|
|
17
27
|
beforeEach(() => {
|
|
18
28
|
mockWallet = {
|
|
19
29
|
getAddress: jest.fn().mockReturnValue(MOCK_ADDRESS),
|
|
20
|
-
getNetwork: jest.fn().mockReturnValue(
|
|
21
|
-
getBalance: jest.fn().mockResolvedValue(
|
|
30
|
+
getNetwork: jest.fn().mockReturnValue(MOCK_EVM_NETWORK),
|
|
31
|
+
getBalance: jest.fn().mockResolvedValue(MOCK_ETH_BALANCE),
|
|
22
32
|
getName: jest.fn().mockReturnValue(MOCK_PROVIDER_NAME),
|
|
23
33
|
nativeTransfer: jest.fn().mockResolvedValue(MOCK_TRANSACTION_HASH),
|
|
24
34
|
};
|
|
25
35
|
});
|
|
26
36
|
describe("getWalletDetails", () => {
|
|
27
|
-
it("should
|
|
37
|
+
it("should show WEI balance for EVM networks", async () => {
|
|
38
|
+
mockWallet.getNetwork.mockReturnValue(MOCK_EVM_NETWORK);
|
|
39
|
+
mockWallet.getBalance.mockResolvedValue(MOCK_ETH_BALANCE);
|
|
40
|
+
const response = await actionProvider.getWalletDetails(mockWallet, {});
|
|
41
|
+
const expectedResponse = [
|
|
42
|
+
"Wallet Details:",
|
|
43
|
+
`- Provider: ${MOCK_PROVIDER_NAME}`,
|
|
44
|
+
`- Address: ${MOCK_ADDRESS}`,
|
|
45
|
+
"- Network:",
|
|
46
|
+
` * Protocol Family: ${MOCK_EVM_NETWORK.protocolFamily}`,
|
|
47
|
+
` * Network ID: ${MOCK_EVM_NETWORK.networkId}`,
|
|
48
|
+
` * Chain ID: ${MOCK_EVM_NETWORK.chainId}`,
|
|
49
|
+
`- Native Balance: ${MOCK_ETH_BALANCE.toString()} WEI`,
|
|
50
|
+
].join("\n");
|
|
51
|
+
expect(response).toBe(expectedResponse);
|
|
52
|
+
});
|
|
53
|
+
it("should show LAMPORTS balance for Solana networks", async () => {
|
|
54
|
+
mockWallet.getNetwork.mockReturnValue(MOCK_SOLANA_NETWORK);
|
|
55
|
+
mockWallet.getBalance.mockResolvedValue(MOCK_SOL_BALANCE);
|
|
56
|
+
const response = await actionProvider.getWalletDetails(mockWallet, {});
|
|
57
|
+
const expectedResponse = [
|
|
58
|
+
"Wallet Details:",
|
|
59
|
+
`- Provider: ${MOCK_PROVIDER_NAME}`,
|
|
60
|
+
`- Address: ${MOCK_ADDRESS}`,
|
|
61
|
+
"- Network:",
|
|
62
|
+
` * Protocol Family: ${MOCK_SOLANA_NETWORK.protocolFamily}`,
|
|
63
|
+
` * Network ID: ${MOCK_SOLANA_NETWORK.networkId}`,
|
|
64
|
+
` * Chain ID: N/A`,
|
|
65
|
+
`- Native Balance: ${MOCK_SOL_BALANCE.toString()} LAMPORTS`,
|
|
66
|
+
].join("\n");
|
|
67
|
+
expect(response).toBe(expectedResponse);
|
|
68
|
+
});
|
|
69
|
+
it("should handle unknown protocol families", async () => {
|
|
70
|
+
mockWallet.getNetwork.mockReturnValue(MOCK_UNKNOWN_NETWORK);
|
|
71
|
+
mockWallet.getBalance.mockResolvedValue(MOCK_ETH_BALANCE);
|
|
28
72
|
const response = await actionProvider.getWalletDetails(mockWallet, {});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* Chain ID: ${MOCK_NETWORK.chainId}
|
|
40
|
-
- ETH Balance: 1.000000 ETH
|
|
41
|
-
- Native Balance: ${MOCK_BALANCE.toString()} WEI`;
|
|
73
|
+
const expectedResponse = [
|
|
74
|
+
"Wallet Details:",
|
|
75
|
+
`- Provider: ${MOCK_PROVIDER_NAME}`,
|
|
76
|
+
`- Address: ${MOCK_ADDRESS}`,
|
|
77
|
+
"- Network:",
|
|
78
|
+
` * Protocol Family: ${MOCK_UNKNOWN_NETWORK.protocolFamily}`,
|
|
79
|
+
` * Network ID: ${MOCK_UNKNOWN_NETWORK.networkId}`,
|
|
80
|
+
` * Chain ID: N/A`,
|
|
81
|
+
`- Native Balance: ${MOCK_ETH_BALANCE.toString()} `,
|
|
82
|
+
].join("\n");
|
|
42
83
|
expect(response).toBe(expectedResponse);
|
|
43
84
|
});
|
|
44
85
|
it("should handle missing network IDs gracefully", async () => {
|
|
@@ -48,6 +89,7 @@ describe("Wallet Action Provider", () => {
|
|
|
48
89
|
const response = await actionProvider.getWalletDetails(mockWallet, {});
|
|
49
90
|
expect(response).toContain("Network ID: N/A");
|
|
50
91
|
expect(response).toContain("Chain ID: N/A");
|
|
92
|
+
expect(response).toContain(`Native Balance: ${MOCK_ETH_BALANCE.toString()} WEI`);
|
|
51
93
|
});
|
|
52
94
|
it("should handle errors when getting wallet details", async () => {
|
|
53
95
|
const error = new Error("Failed to get wallet details");
|
|
@@ -57,7 +99,7 @@ describe("Wallet Action Provider", () => {
|
|
|
57
99
|
});
|
|
58
100
|
});
|
|
59
101
|
describe("Native Transfer", () => {
|
|
60
|
-
const MOCK_AMOUNT = "1.5"; // 1.5 ETH
|
|
102
|
+
const MOCK_AMOUNT = "1.5"; // 1.5 ETH/SOL
|
|
61
103
|
const MOCK_DESTINATION = "0x321";
|
|
62
104
|
it("should successfully parse valid input", () => {
|
|
63
105
|
const validInput = {
|
|
@@ -75,16 +117,52 @@ describe("Wallet Action Provider", () => {
|
|
|
75
117
|
const result = schemas_1.NativeTransferSchema.safeParse(emptyInput);
|
|
76
118
|
expect(result.success).toBe(false);
|
|
77
119
|
});
|
|
78
|
-
it("should successfully transfer
|
|
120
|
+
it("should successfully transfer ETH", async () => {
|
|
121
|
+
mockWallet.getNetwork.mockReturnValue(MOCK_EVM_NETWORK);
|
|
122
|
+
mockWallet.nativeTransfer.mockResolvedValue(MOCK_TRANSACTION_HASH);
|
|
79
123
|
const args = {
|
|
80
124
|
to: MOCK_DESTINATION,
|
|
81
125
|
value: MOCK_AMOUNT,
|
|
82
126
|
};
|
|
83
127
|
const response = await actionProvider.nativeTransfer(mockWallet, args);
|
|
84
128
|
expect(mockWallet.nativeTransfer).toHaveBeenCalledWith(MOCK_DESTINATION, MOCK_AMOUNT);
|
|
85
|
-
expect(response).toBe(`Transferred ${MOCK_AMOUNT} ETH to ${MOCK_DESTINATION}
|
|
129
|
+
expect(response).toBe(`Transferred ${MOCK_AMOUNT} ETH to ${MOCK_DESTINATION}\nTransaction hash: ${MOCK_TRANSACTION_HASH}`);
|
|
130
|
+
});
|
|
131
|
+
it("should successfully transfer SOL", async () => {
|
|
132
|
+
mockWallet.getNetwork.mockReturnValue(MOCK_SOLANA_NETWORK);
|
|
133
|
+
mockWallet.nativeTransfer.mockResolvedValue(MOCK_SIGNATURE);
|
|
134
|
+
const args = {
|
|
135
|
+
to: MOCK_DESTINATION,
|
|
136
|
+
value: MOCK_AMOUNT,
|
|
137
|
+
};
|
|
138
|
+
const response = await actionProvider.nativeTransfer(mockWallet, args);
|
|
139
|
+
expect(mockWallet.nativeTransfer).toHaveBeenCalledWith(MOCK_DESTINATION, MOCK_AMOUNT);
|
|
140
|
+
expect(response).toBe(`Transferred ${MOCK_AMOUNT} SOL to ${MOCK_DESTINATION}\nSignature: ${MOCK_SIGNATURE}`);
|
|
141
|
+
});
|
|
142
|
+
it("should handle ETH transfer errors", async () => {
|
|
143
|
+
mockWallet.getNetwork.mockReturnValue(MOCK_EVM_NETWORK);
|
|
144
|
+
const args = {
|
|
145
|
+
to: MOCK_DESTINATION,
|
|
146
|
+
value: MOCK_AMOUNT,
|
|
147
|
+
};
|
|
148
|
+
const error = new Error("Failed to execute transfer");
|
|
149
|
+
mockWallet.nativeTransfer.mockRejectedValue(error);
|
|
150
|
+
const response = await actionProvider.nativeTransfer(mockWallet, args);
|
|
151
|
+
expect(response).toBe(`Error during transaction: ${error}`);
|
|
152
|
+
});
|
|
153
|
+
it("should handle SOL transfer errors", async () => {
|
|
154
|
+
mockWallet.getNetwork.mockReturnValue(MOCK_SOLANA_NETWORK);
|
|
155
|
+
const args = {
|
|
156
|
+
to: MOCK_DESTINATION,
|
|
157
|
+
value: MOCK_AMOUNT,
|
|
158
|
+
};
|
|
159
|
+
const error = new Error("Failed to execute transfer");
|
|
160
|
+
mockWallet.nativeTransfer.mockRejectedValue(error);
|
|
161
|
+
const response = await actionProvider.nativeTransfer(mockWallet, args);
|
|
162
|
+
expect(response).toBe(`Error during transfer: ${error}`);
|
|
86
163
|
});
|
|
87
|
-
it("should handle transfer errors", async () => {
|
|
164
|
+
it("should handle unknown protocol family transfer errors", async () => {
|
|
165
|
+
mockWallet.getNetwork.mockReturnValue(MOCK_UNKNOWN_NETWORK);
|
|
88
166
|
const args = {
|
|
89
167
|
to: MOCK_DESTINATION,
|
|
90
168
|
value: MOCK_AMOUNT,
|
|
@@ -92,7 +170,7 @@ describe("Wallet Action Provider", () => {
|
|
|
92
170
|
const error = new Error("Failed to execute transfer");
|
|
93
171
|
mockWallet.nativeTransfer.mockRejectedValue(error);
|
|
94
172
|
const response = await actionProvider.nativeTransfer(mockWallet, args);
|
|
95
|
-
expect(response).toBe(`Error
|
|
173
|
+
expect(response).toBe(`Error during transfer: ${error}`);
|
|
96
174
|
});
|
|
97
175
|
});
|
|
98
176
|
describe("supportsNetwork", () => {
|
package/dist/network/index.d.ts
CHANGED
package/dist/network/index.js
CHANGED
|
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./types"), exports);
|
|
18
17
|
__exportStar(require("./network"), exports);
|
|
18
|
+
__exportStar(require("./svm"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
@@ -11,3 +11,10 @@ export declare const NETWORK_ID_TO_CHAIN_ID: Record<string, string>;
|
|
|
11
11
|
* Maps Coinbase network IDs to Viem chain objects
|
|
12
12
|
*/
|
|
13
13
|
export declare const NETWORK_ID_TO_VIEM_CHAIN: Record<string, Chain>;
|
|
14
|
+
/**
|
|
15
|
+
* Get a chain from the viem chains object
|
|
16
|
+
*
|
|
17
|
+
* @param id - The chain ID
|
|
18
|
+
* @returns The chain
|
|
19
|
+
*/
|
|
20
|
+
export declare const getChain: (id: string) => Chain;
|
package/dist/network/network.js
CHANGED
|
@@ -1,7 +1,41 @@
|
|
|
1
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
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NETWORK_ID_TO_VIEM_CHAIN = exports.NETWORK_ID_TO_CHAIN_ID = exports.CHAIN_ID_TO_NETWORK_ID = void 0;
|
|
36
|
+
exports.getChain = exports.NETWORK_ID_TO_VIEM_CHAIN = exports.NETWORK_ID_TO_CHAIN_ID = exports.CHAIN_ID_TO_NETWORK_ID = void 0;
|
|
4
37
|
const chains_1 = require("viem/chains");
|
|
38
|
+
const chains = __importStar(require("viem/chains"));
|
|
5
39
|
/**
|
|
6
40
|
* Maps EVM chain IDs to Coinbase network IDs
|
|
7
41
|
*/
|
|
@@ -39,3 +73,14 @@ exports.NETWORK_ID_TO_VIEM_CHAIN = {
|
|
|
39
73
|
"optimism-mainnet": chains_1.optimism,
|
|
40
74
|
"optimism-sepolia": chains_1.optimismSepolia,
|
|
41
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* Get a chain from the viem chains object
|
|
78
|
+
*
|
|
79
|
+
* @param id - The chain ID
|
|
80
|
+
* @returns The chain
|
|
81
|
+
*/
|
|
82
|
+
const getChain = (id) => {
|
|
83
|
+
const chainList = Object.values(chains);
|
|
84
|
+
return chainList.find(chain => chain.id === parseInt(id));
|
|
85
|
+
};
|
|
86
|
+
exports.getChain = getChain;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Network } from "./types";
|
|
2
|
+
export declare const SOLANA_MAINNET_NETWORK_ID = "solana-mainnet";
|
|
3
|
+
export declare const SOLANA_TESTNET_NETWORK_ID = "solana-testnet";
|
|
4
|
+
export declare const SOLANA_DEVNET_NETWORK_ID = "solana-devnet";
|
|
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_PROTOCOL_FAMILY = "svm";
|
|
7
|
+
export declare const SOLANA_MAINNET_GENESIS_BLOCK_HASH = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
8
|
+
export declare const SOLANA_TESTNET_GENESIS_BLOCK_HASH = "4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY";
|
|
9
|
+
export declare const SOLANA_DEVNET_GENESIS_BLOCK_HASH = "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG";
|
|
10
|
+
export type SOLANA_CLUSTER = typeof SOLANA_MAINNET_GENESIS_BLOCK_HASH | typeof SOLANA_TESTNET_GENESIS_BLOCK_HASH | typeof SOLANA_DEVNET_GENESIS_BLOCK_HASH;
|
|
11
|
+
export declare const SOLANA_MAINNET_NETWORK: Network;
|
|
12
|
+
export declare const SOLANA_TESTNET_NETWORK: Network;
|
|
13
|
+
export declare const SOLANA_DEVNET_NETWORK: Network;
|
|
14
|
+
export declare const SOLANA_NETWORKS: Record<SOLANA_CLUSTER, Network>;
|
|
15
|
+
export declare const SOLANA_CLUSTER_ID_BY_NETWORK_ID: Record<SOLANA_NETWORK_ID, string>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
4
|
+
// CDP Network IDs
|
|
5
|
+
exports.SOLANA_MAINNET_NETWORK_ID = "solana-mainnet";
|
|
6
|
+
exports.SOLANA_TESTNET_NETWORK_ID = "solana-testnet";
|
|
7
|
+
exports.SOLANA_DEVNET_NETWORK_ID = "solana-devnet";
|
|
8
|
+
// AgentKit Protocol Family
|
|
9
|
+
exports.SOLANA_PROTOCOL_FAMILY = "svm";
|
|
10
|
+
// Chain IDs - Genesis Block Hashes
|
|
11
|
+
exports.SOLANA_MAINNET_GENESIS_BLOCK_HASH = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
|
|
12
|
+
exports.SOLANA_TESTNET_GENESIS_BLOCK_HASH = "4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY";
|
|
13
|
+
exports.SOLANA_DEVNET_GENESIS_BLOCK_HASH = "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG";
|
|
14
|
+
exports.SOLANA_MAINNET_NETWORK = {
|
|
15
|
+
protocolFamily: exports.SOLANA_PROTOCOL_FAMILY,
|
|
16
|
+
chainId: exports.SOLANA_MAINNET_GENESIS_BLOCK_HASH,
|
|
17
|
+
networkId: exports.SOLANA_MAINNET_NETWORK_ID,
|
|
18
|
+
};
|
|
19
|
+
exports.SOLANA_TESTNET_NETWORK = {
|
|
20
|
+
protocolFamily: exports.SOLANA_PROTOCOL_FAMILY,
|
|
21
|
+
chainId: exports.SOLANA_TESTNET_GENESIS_BLOCK_HASH,
|
|
22
|
+
networkId: exports.SOLANA_TESTNET_NETWORK_ID,
|
|
23
|
+
};
|
|
24
|
+
exports.SOLANA_DEVNET_NETWORK = {
|
|
25
|
+
protocolFamily: exports.SOLANA_PROTOCOL_FAMILY,
|
|
26
|
+
chainId: exports.SOLANA_DEVNET_GENESIS_BLOCK_HASH,
|
|
27
|
+
networkId: exports.SOLANA_DEVNET_NETWORK_ID,
|
|
28
|
+
};
|
|
29
|
+
exports.SOLANA_NETWORKS = {
|
|
30
|
+
[exports.SOLANA_MAINNET_GENESIS_BLOCK_HASH]: exports.SOLANA_MAINNET_NETWORK,
|
|
31
|
+
[exports.SOLANA_TESTNET_GENESIS_BLOCK_HASH]: exports.SOLANA_TESTNET_NETWORK,
|
|
32
|
+
[exports.SOLANA_DEVNET_GENESIS_BLOCK_HASH]: exports.SOLANA_DEVNET_NETWORK,
|
|
33
|
+
};
|
|
34
|
+
exports.SOLANA_CLUSTER_ID_BY_NETWORK_ID = {
|
|
35
|
+
[exports.SOLANA_MAINNET_NETWORK_ID]: "mainnet-beta",
|
|
36
|
+
[exports.SOLANA_TESTNET_NETWORK_ID]: "testnet",
|
|
37
|
+
[exports.SOLANA_DEVNET_NETWORK_ID]: "devnet",
|
|
38
|
+
};
|
package/dist/utils.d.ts
CHANGED
|
@@ -9,3 +9,14 @@ import { EvmWalletProvider } from "./wallet-providers";
|
|
|
9
9
|
* @returns A success message or error message
|
|
10
10
|
*/
|
|
11
11
|
export declare function approve(wallet: EvmWalletProvider, tokenAddress: string, spenderAddress: string, amount: bigint): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Scales a gas estimate by a given multiplier.
|
|
14
|
+
*
|
|
15
|
+
* This function converts the gas estimate to a number, applies the multiplier,
|
|
16
|
+
* rounds the result to the nearest integer, and returns it as a bigint.
|
|
17
|
+
*
|
|
18
|
+
* @param gas - The original gas estimate (bigint).
|
|
19
|
+
* @param multiplier - The factor by which to scale the estimate.
|
|
20
|
+
* @returns The adjusted gas estimate as a bigint.
|
|
21
|
+
*/
|
|
22
|
+
export declare function applyGasMultiplier(gas: bigint, multiplier: number): bigint;
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.approve = approve;
|
|
4
|
+
exports.applyGasMultiplier = applyGasMultiplier;
|
|
4
5
|
const viem_1 = require("viem");
|
|
5
6
|
const ERC20_ABI = [
|
|
6
7
|
{
|
|
@@ -41,3 +42,16 @@ async function approve(wallet, tokenAddress, spenderAddress, amount) {
|
|
|
41
42
|
return `Error approving tokens: ${error}`;
|
|
42
43
|
}
|
|
43
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Scales a gas estimate by a given multiplier.
|
|
47
|
+
*
|
|
48
|
+
* This function converts the gas estimate to a number, applies the multiplier,
|
|
49
|
+
* rounds the result to the nearest integer, and returns it as a bigint.
|
|
50
|
+
*
|
|
51
|
+
* @param gas - The original gas estimate (bigint).
|
|
52
|
+
* @param multiplier - The factor by which to scale the estimate.
|
|
53
|
+
* @returns The adjusted gas estimate as a bigint.
|
|
54
|
+
*/
|
|
55
|
+
function applyGasMultiplier(gas, multiplier) {
|
|
56
|
+
return BigInt(Math.round(Number(gas) * multiplier));
|
|
57
|
+
}
|
|
@@ -35,6 +35,19 @@ export interface CdpWalletProviderConfig extends CdpProviderConfig {
|
|
|
35
35
|
* The network ID of the wallet.
|
|
36
36
|
*/
|
|
37
37
|
networkId?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Configuration for gas multipliers.
|
|
40
|
+
*/
|
|
41
|
+
gas?: {
|
|
42
|
+
/**
|
|
43
|
+
* An internal multiplier on gas limit estimation.
|
|
44
|
+
*/
|
|
45
|
+
gasLimitMultiplier?: number;
|
|
46
|
+
/**
|
|
47
|
+
* An internal multiplier on fee per gas estimation.
|
|
48
|
+
*/
|
|
49
|
+
feePerGasMultiplier?: number;
|
|
50
|
+
};
|
|
38
51
|
}
|
|
39
52
|
/**
|
|
40
53
|
* Configuration options for the CDP Agentkit with a Wallet.
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
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
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _CdpWalletProvider_cdpWallet, _CdpWalletProvider_address, _CdpWalletProvider_network, _CdpWalletProvider_publicClient;
|
|
13
|
+
var _CdpWalletProvider_cdpWallet, _CdpWalletProvider_address, _CdpWalletProvider_network, _CdpWalletProvider_publicClient, _CdpWalletProvider_gasLimitMultiplier, _CdpWalletProvider_feePerGasMultiplier;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.CdpWalletProvider = void 0;
|
|
16
16
|
const package_json_1 = require("../../package.json");
|
|
@@ -19,6 +19,7 @@ const viem_1 = require("viem");
|
|
|
19
19
|
const evmWalletProvider_1 = require("./evmWalletProvider");
|
|
20
20
|
const coinbase_sdk_1 = require("@coinbase/coinbase-sdk");
|
|
21
21
|
const network_1 = require("../network/network");
|
|
22
|
+
const utils_1 = require("../utils");
|
|
22
23
|
/**
|
|
23
24
|
* A wallet provider that uses the Coinbase SDK.
|
|
24
25
|
*/
|
|
@@ -34,6 +35,8 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
34
35
|
_CdpWalletProvider_address.set(this, void 0);
|
|
35
36
|
_CdpWalletProvider_network.set(this, void 0);
|
|
36
37
|
_CdpWalletProvider_publicClient.set(this, void 0);
|
|
38
|
+
_CdpWalletProvider_gasLimitMultiplier.set(this, void 0);
|
|
39
|
+
_CdpWalletProvider_feePerGasMultiplier.set(this, void 0);
|
|
37
40
|
__classPrivateFieldSet(this, _CdpWalletProvider_cdpWallet, config.wallet, "f");
|
|
38
41
|
__classPrivateFieldSet(this, _CdpWalletProvider_address, config.address, "f");
|
|
39
42
|
__classPrivateFieldSet(this, _CdpWalletProvider_network, config.network, "f");
|
|
@@ -41,6 +44,8 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
41
44
|
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[config.network.networkId],
|
|
42
45
|
transport: (0, viem_1.http)(),
|
|
43
46
|
}), "f");
|
|
47
|
+
__classPrivateFieldSet(this, _CdpWalletProvider_gasLimitMultiplier, Math.max(config.gas?.gasLimitMultiplier ?? 1.2, 1), "f");
|
|
48
|
+
__classPrivateFieldSet(this, _CdpWalletProvider_feePerGasMultiplier, Math.max(config.gas?.feePerGasMultiplier ?? 1, 1), "f");
|
|
44
49
|
}
|
|
45
50
|
/**
|
|
46
51
|
* Configures a new CdpWalletProvider with a wallet.
|
|
@@ -92,6 +97,7 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
92
97
|
wallet,
|
|
93
98
|
address,
|
|
94
99
|
network,
|
|
100
|
+
gas: config.gas,
|
|
95
101
|
});
|
|
96
102
|
return cdpWalletProvider;
|
|
97
103
|
}
|
|
@@ -183,22 +189,23 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
183
189
|
address: __classPrivateFieldGet(this, _CdpWalletProvider_address, "f"),
|
|
184
190
|
});
|
|
185
191
|
const feeData = await __classPrivateFieldGet(this, _CdpWalletProvider_publicClient, "f").estimateFeesPerGas();
|
|
186
|
-
const
|
|
192
|
+
const maxFeePerGas = (0, utils_1.applyGasMultiplier)(feeData.maxFeePerGas, __classPrivateFieldGet(this, _CdpWalletProvider_feePerGasMultiplier, "f"));
|
|
193
|
+
const maxPriorityFeePerGas = (0, utils_1.applyGasMultiplier)(feeData.maxPriorityFeePerGas, __classPrivateFieldGet(this, _CdpWalletProvider_feePerGasMultiplier, "f"));
|
|
194
|
+
const gasLimit = await __classPrivateFieldGet(this, _CdpWalletProvider_publicClient, "f").estimateGas({
|
|
187
195
|
account: __classPrivateFieldGet(this, _CdpWalletProvider_address, "f"),
|
|
188
196
|
to,
|
|
189
197
|
value,
|
|
190
198
|
data,
|
|
191
|
-
maxFeePerGas: feeData.maxFeePerGas,
|
|
192
|
-
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
|
|
193
199
|
});
|
|
200
|
+
const gas = BigInt(Math.round(Number(gasLimit) * __classPrivateFieldGet(this, _CdpWalletProvider_gasLimitMultiplier, "f")));
|
|
194
201
|
const chainId = parseInt(__classPrivateFieldGet(this, _CdpWalletProvider_network, "f").chainId, 10);
|
|
195
202
|
return {
|
|
196
203
|
to,
|
|
197
204
|
value,
|
|
198
205
|
data,
|
|
199
206
|
nonce,
|
|
200
|
-
maxFeePerGas
|
|
201
|
-
maxPriorityFeePerGas
|
|
207
|
+
maxFeePerGas,
|
|
208
|
+
maxPriorityFeePerGas,
|
|
202
209
|
gas,
|
|
203
210
|
chainId,
|
|
204
211
|
type: "eip1559",
|
|
@@ -375,4 +382,4 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
375
382
|
}
|
|
376
383
|
}
|
|
377
384
|
exports.CdpWalletProvider = CdpWalletProvider;
|
|
378
|
-
_CdpWalletProvider_cdpWallet = new WeakMap(), _CdpWalletProvider_address = new WeakMap(), _CdpWalletProvider_network = new WeakMap(), _CdpWalletProvider_publicClient = new WeakMap();
|
|
385
|
+
_CdpWalletProvider_cdpWallet = new WeakMap(), _CdpWalletProvider_address = new WeakMap(), _CdpWalletProvider_network = new WeakMap(), _CdpWalletProvider_publicClient = new WeakMap(), _CdpWalletProvider_gasLimitMultiplier = new WeakMap(), _CdpWalletProvider_feePerGasMultiplier = new WeakMap();
|
|
@@ -2,3 +2,8 @@ export * from "./walletProvider";
|
|
|
2
2
|
export * from "./evmWalletProvider";
|
|
3
3
|
export * from "./viemWalletProvider";
|
|
4
4
|
export * from "./cdpWalletProvider";
|
|
5
|
+
export * from "./svmWalletProvider";
|
|
6
|
+
export * from "./solanaKeypairWalletProvider";
|
|
7
|
+
export * from "./privyWalletProvider";
|
|
8
|
+
export * from "./privyEvmWalletProvider";
|
|
9
|
+
export * from "./privySvmWalletProvider";
|
|
@@ -18,3 +18,8 @@ __exportStar(require("./walletProvider"), exports);
|
|
|
18
18
|
__exportStar(require("./evmWalletProvider"), exports);
|
|
19
19
|
__exportStar(require("./viemWalletProvider"), exports);
|
|
20
20
|
__exportStar(require("./cdpWalletProvider"), exports);
|
|
21
|
+
__exportStar(require("./svmWalletProvider"), exports);
|
|
22
|
+
__exportStar(require("./solanaKeypairWalletProvider"), exports);
|
|
23
|
+
__exportStar(require("./privyWalletProvider"), exports);
|
|
24
|
+
__exportStar(require("./privyEvmWalletProvider"), exports);
|
|
25
|
+
__exportStar(require("./privySvmWalletProvider"), exports);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ViemWalletProvider } from "./viemWalletProvider";
|
|
2
|
+
import { PrivyWalletConfig, PrivyWalletExport } from "./privyShared";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for the Privy wallet provider.
|
|
5
|
+
*
|
|
6
|
+
* @interface
|
|
7
|
+
*/
|
|
8
|
+
export interface PrivyEvmWalletConfig extends PrivyWalletConfig {
|
|
9
|
+
/** Optional chain ID to connect to */
|
|
10
|
+
chainId?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A wallet provider that uses Privy's server wallet API.
|
|
14
|
+
* This provider extends the ViemWalletProvider to provide Privy-specific wallet functionality
|
|
15
|
+
* while maintaining compatibility with the base wallet provider interface.
|
|
16
|
+
*/
|
|
17
|
+
export declare class PrivyEvmWalletProvider extends ViemWalletProvider {
|
|
18
|
+
#private;
|
|
19
|
+
/**
|
|
20
|
+
* Private constructor to enforce use of factory method.
|
|
21
|
+
*
|
|
22
|
+
* @param walletClient - The Viem wallet client instance
|
|
23
|
+
* @param config - The configuration options for the Privy wallet
|
|
24
|
+
*/
|
|
25
|
+
private constructor();
|
|
26
|
+
/**
|
|
27
|
+
* Creates and configures a new PrivyWalletProvider instance.
|
|
28
|
+
*
|
|
29
|
+
* @param config - The configuration options for the Privy wallet
|
|
30
|
+
* @returns A configured PrivyWalletProvider instance
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const provider = await PrivyWalletProvider.configureWithWallet({
|
|
35
|
+
* appId: "your-app-id",
|
|
36
|
+
* appSecret: "your-app-secret",
|
|
37
|
+
* walletId: "wallet-id",
|
|
38
|
+
* chainId: "84532"
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
static configureWithWallet(config: PrivyEvmWalletConfig): Promise<PrivyEvmWalletProvider>;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the name of the wallet provider.
|
|
45
|
+
*
|
|
46
|
+
* @returns The string identifier for this wallet provider
|
|
47
|
+
*/
|
|
48
|
+
getName(): string;
|
|
49
|
+
/**
|
|
50
|
+
* Exports the wallet data.
|
|
51
|
+
*
|
|
52
|
+
* @returns The wallet data
|
|
53
|
+
*/
|
|
54
|
+
exportWallet(): PrivyWalletExport;
|
|
55
|
+
}
|